// src/engine/opencode/config-scaffold.ts — SPEC-966: Generate OpenCode config files
import { mkdirSync, writeFileSync, existsSync } from 'fs';
import { join } from 'path';
import { assertEnglishOnlyArtifactText } from '../spec-language/english-only.js';
const PLANU_OPENCODE_RULES = `# Planu Rules for OpenCode

## SDD Workflow

- Always create a spec before implementing features
- Use \`planu_create_spec\` to generate structured acceptance criteria
- Run \`planu_validate\` before marking specs as done
- Track actuals with \`planu_record_actual\` for estimation calibration

## Plan Mode Integration

- When entering plan mode, call \`planu_facilitate\` to align on approach
- When exiting plan mode, run \`planu_check_readiness\` before building
- Auto-transition: plan → build when readiness score >= 70

## TypeScript Quality Gates

- Run \`planu_type_safety_gate\` before marking specs done
- Zero \`any\` types in new code (waivers allowed per file)
- Zero unjustified \`@ts-ignore\` comments
`;
const PLANU_OPENCODE_SKILLS = `# Planu Skill — SDD on OpenCode

## Trigger

User mentions "create spec", "plan feature", "design implementation", or "SDD".

## Steps

1. Run \`planu_facilitate\` to understand the request
2. If broad, break down into multiple specs
3. Create specs with \`planu_create_spec\`
4. Set status to \`review\` when ready
5. After approval, implement with spec as checklist
6. Validate with \`planu_validate\` before marking done

## Output

Always return spec IDs and next steps.
`;
const PLANU_AGENTS_MD_BLOCK = `## Planu SDD Integration

Planu provides spec-driven development tools for OpenCode workspaces.

### Key Tools

- \`planu_list_specs\` — Show all specs in the project
- \`planu_create_spec\` — Create a new spec from description
- \`planu_validate\` — Check implementation against spec
- \`planu_type_safety_gate\` — Block done on TypeScript anti-patterns
- \`planu_spec_obesity_healer\` — Clean bloated legacy specs

### Workflow

1. **Plan**: Use \`planu_facilitate\` to explore and plan
2. **Spec**: Create specs with clear acceptance criteria
3. **Build**: Implement against the spec checklist
4. **Validate**: Run \`planu_validate\` before marking done
5. **Ship**: Update status and record actuals

### Coach Rules

- Use native interactive UI (not AskUserQuestion references)
- Respect OpenCode plan mode lifecycle
- Fallback to Planu-managed flow when plan mode unavailable
`;
export function scaffoldOpenCodeConfig(projectPath) {
    const files = [];
    // .opencode/rules/planu-workflow.md
    const rulesDir = join(projectPath, '.opencode', 'rules');
    mkdirSync(rulesDir, { recursive: true });
    const rulesPath = join(rulesDir, 'planu-workflow.md');
    assertEnglishOnlyArtifactText(PLANU_OPENCODE_RULES, 'rule');
    writeFileSync(rulesPath, PLANU_OPENCODE_RULES, 'utf-8');
    files.push(rulesPath);
    // .opencode/skills/planu-sdd.md
    const skillsDir = join(projectPath, '.opencode', 'skills');
    mkdirSync(skillsDir, { recursive: true });
    const skillsPath = join(skillsDir, 'planu-sdd.md');
    assertEnglishOnlyArtifactText(PLANU_OPENCODE_SKILLS, 'skill');
    writeFileSync(skillsPath, PLANU_OPENCODE_SKILLS, 'utf-8');
    files.push(skillsPath);
    // AGENTS.md append (or create)
    const agentsMdPath = join(projectPath, 'AGENTS.md');
    assertEnglishOnlyArtifactText(PLANU_AGENTS_MD_BLOCK, 'agent');
    if (existsSync(agentsMdPath)) {
        writeFileSync(agentsMdPath, '\n' + PLANU_AGENTS_MD_BLOCK + '\n', { flag: 'a' });
        files.push(agentsMdPath + ' (appended)');
    }
    else {
        writeFileSync(agentsMdPath, PLANU_AGENTS_MD_BLOCK, 'utf-8');
        files.push(agentsMdPath);
    }
    return { files };
}
//# sourceMappingURL=config-scaffold.js.map