sdd-forge 0.1.0-alpha.23 → 0.1.0-alpha.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,24 +1,24 @@
1
- # <!-- {{data: project.name("")}} -->sdd-forge<!-- {{/data}} -->
1
+ # {{data: project.name("")}}sdd-forge{{/data}}
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/sdd-forge.svg)](https://www.npmjs.com/package/sdd-forge)
4
4
 
5
- > **Alpha:** This tool is currently in alpha. APIs, command structures, and configuration formats may change without notice. Not recommended for production use.
5
+ > **Alpha:** This tool is currently in alpha. The API, command structure, and configuration format may change without notice. Please avoid using it in production environments.
6
6
 
7
7
  **A CLI tool that automatically generates and maintains project documentation using source code analysis + AI.**
8
8
 
9
9
  Statically analyzes your codebase and combines templates with AI to auto-generate `docs/`.
10
- Spec-Driven Development (SDD) workflows further automate documentation updates when adding features or making changes.
10
+ The Spec-Driven Development (SDD) workflow also automates documentation updates when adding features or making changes.
11
11
 
12
12
  ## Features
13
13
 
14
- - **Zero dependencies** — Runs on Node.js 18+ only. No npm packages required
15
- - **Automatic source analysis** — Statically analyzes controllers, models, routes, and config files to extract structural data
16
- - **AI document generation** — AI automatically expands `{{text}}` directives in templates
17
- - **Template inheritance** — Customizable via 4-layer inheritance: base → arch → preset → project-local
18
- - **SDD workflow** — Manage the spec → gate → implement → forge → review cycle with commands
19
- - **Multi-language support** — Auto-generate documentation in multiple languages via translate / generate modes
20
- - **AI agent integration** — Supports Claude Code (skills) and Codex CLI
21
- - **Multi-preset** — Supports Node.js CLI / CakePHP2 / Laravel / Symfony
14
+ - **Zero dependencies** — Runs on Node.js 18+ only. No npm package dependencies.
15
+ - **Automatic source code analysis** — Statically analyzes controllers, models, routes, and config files to extract structural data.
16
+ - **AI document generation** — AI automatically expands `{{text}}` directives in templates.
17
+ - **Template inheritance** — Four-layer inheritance (base → arch → preset → project-local) for flexible customization.
18
+ - **SDD workflow** — Manage the development cycle of spec → gate → implementation → forge → review with simple commands.
19
+ - **Multilingual support** — Automatically generate documentation in multiple languages via translate / generate modes.
20
+ - **AI agent integration** — Compatible with Claude Code (skills) and Codex CLI.
21
+ - **Multi-preset** — Supports Node.js CLI / CakePHP2 / Laravel / Symfony.
22
22
 
23
23
  ## Quick Start
24
24
 
@@ -26,28 +26,28 @@ Spec-Driven Development (SDD) workflows further automate documentation updates w
26
26
 
27
27
  <pre>
28
28
  # npm
29
- npm install -g <!-- {{data: project.name("")}} -->sdd-forge<!-- {{/data}} -->
29
+ npm install -g {{data: project.name("")}}sdd-forge{{/data}}
30
30
 
31
31
  # yarn
32
- yarn global add <!-- {{data: project.name("")}} -->sdd-forge<!-- {{/data}} -->
32
+ yarn global add {{data: project.name("")}}sdd-forge{{/data}}
33
33
 
34
34
  # pnpm
35
- pnpm add -g <!-- {{data: project.name("")}} -->sdd-forge<!-- {{/data}} -->
35
+ pnpm add -g {{data: project.name("")}}sdd-forge{{/data}}
36
36
  </pre>
37
37
 
38
38
  ### Setup & Document Generation
39
39
 
40
40
  <pre>
41
41
  # 1. Register your project (interactive wizard)
42
- <!-- {{data: project.name("")}} -->sdd-forge<!-- {{/data}} --> setup
42
+ {{data: project.name("")}}sdd-forge{{/data}} setup
43
43
 
44
44
  # 2. Generate all documentation at once (scan → init → data → text → readme → agents → translate)
45
- <!-- {{data: project.name("")}} -->sdd-forge<!-- {{/data}} --> build
45
+ {{data: project.name("")}}sdd-forge{{/data}} build
46
46
  </pre>
47
47
 
48
- This alone generates `docs/` and `README.md`.
48
+ This is all it takes to generate `docs/` and `README.md`.
49
49
 
50
- ## Commands
50
+ ## Command Reference
51
51
 
52
52
  ### Document Generation
53
53
 
@@ -57,12 +57,12 @@ This alone generates `docs/` and `README.md`.
57
57
  | `build` | Run the full document generation pipeline |
58
58
  | `scan` | Analyze source code → `analysis.json` |
59
59
  | `init` | Initialize `docs/` from templates |
60
- | `data` | Resolve `{{data}}` directives with analysis data |
60
+ | `data` | Resolve `{{data}}` directives with analyzed data |
61
61
  | `text` | Resolve `{{text}}` directives with AI |
62
62
  | `readme` | Auto-generate `README.md` from `docs/` |
63
63
  | `forge` | Iteratively improve documentation with AI |
64
64
  | `review` | Check documentation quality |
65
- | `translate` | Multi-language translation (default language → other languages) |
65
+ | `translate` | Multilingual translation (default language → others) |
66
66
  | `upgrade` | Update preset templates to the latest version |
67
67
 
68
68
  ### SDD Workflow
@@ -70,7 +70,7 @@ This alone generates `docs/` and `README.md`.
70
70
  | Command | Description |
71
71
  |---|---|
72
72
  | `spec` | Create a spec document + feature branch |
73
- | `gate` | Pre-implementation check for spec |
73
+ | `gate` | Pre-implementation check for the spec |
74
74
  | `flow` | Automatically run the SDD workflow |
75
75
  | `changelog` | Generate change history from specs/ |
76
76
  | `agents` | Update AGENTS.md |
@@ -85,12 +85,12 @@ This alone generates `docs/` and `README.md`.
85
85
 
86
86
  ## SDD Workflow
87
87
 
88
- The feature addition / change flow:
88
+ The flow for adding features or making changes:
89
89
 
90
90
  ```
91
91
  spec Create a spec (feature branch + spec.md)
92
92
 
93
- gate Spec gate check (PASS when no open issues)
93
+ gate Spec gate check (PASS when no unresolved items)
94
94
 
95
95
  implement Write code after gate PASS
96
96
 
@@ -112,7 +112,7 @@ Run the SDD workflow with skills:
112
112
 
113
113
  #### Codex CLI
114
114
 
115
- Run the workflow from prompts:
115
+ Run the workflow from a prompt:
116
116
 
117
117
  ```
118
118
  $sdd-flow-start — Start spec creation → gate → implementation
@@ -149,9 +149,9 @@ You can add project-specific templates and data sources:
149
149
  <!-- {{data: docs.chapters("Chapter|Overview")}} -->
150
150
  | Chapter | Overview |
151
151
  | --- | --- |
152
- | [01. System Overview](https://github.com/SpreadWorks/sdd-forge/blob/main/docs/01_overview.md) | |
153
- | [02. CLI Command Reference](https://github.com/SpreadWorks/sdd-forge/blob/main/docs/02_cli_commands.md) | |
154
- | [03. Configuration and Customization](https://github.com/SpreadWorks/sdd-forge/blob/main/docs/03_configuration.md) | |
152
+ | [01. System Overview](https://github.com/SpreadWorks/sdd-forge/blob/main/docs/01_overview.md) | This chapter provides a high-level view of `sdd-forge`, a Node.js CLI tool that automates documentation generation th… |
153
+ | [02. CLI Command Reference](https://github.com/SpreadWorks/sdd-forge/blob/main/docs/02_cli_commands.md) | This chapter documents all 17 subcommands available in `sdd-forge`, organized across three dispatcher layers (`docs.j… |
154
+ | [03. Configuration and Customization](https://github.com/SpreadWorks/sdd-forge/blob/main/docs/03_configuration.md) | This chapter covers the configuration files and customization options available in sdd-forge, including project setti… |
155
155
  | [04. Internal Design](https://github.com/SpreadWorks/sdd-forge/blob/main/docs/04_internal_design.md) | |
156
156
  <!-- {{/data}} -->
157
157
 
@@ -4,20 +4,87 @@
4
4
 
5
5
  <!-- {{text: Write a 1-2 sentence overview of this chapter. Include the project's architecture and whether it integrates with external systems.}} -->
6
6
 
7
+ This chapter provides a high-level view of `sdd-forge`, a Node.js CLI tool that automates documentation generation through source code analysis and drives feature development via a Spec-Driven Development (SDD) workflow. The tool integrates with externally configured AI agents (such as Claude CLI) to produce and refine project documentation, while relying solely on Node.js built-in modules for all other operations.
8
+
7
9
  ## Content
8
10
 
9
11
  ### Architecture Diagram
10
12
 
11
13
  <!-- {{text: Generate a mermaid flowchart showing the project architecture. Include data flows between major components. Output only the mermaid code block.}} -->
12
14
 
15
+ ```mermaid
16
+ flowchart TD
17
+ User([User / CI]) -->|CLI invocation| Entry[sdd-forge.js\nEntry Point]
18
+
19
+ Entry -->|docs subcommands| DocsDispatcher[docs.js\nDispatcher]
20
+ Entry -->|spec / gate| SpecDispatcher[spec.js\nDispatcher]
21
+ Entry -->|flow| Flow[flow.js\nSDD Flow Runner]
22
+ Entry -->|presets| Presets[presets-cmd.js]
23
+ Entry -->|help| Help[help.js]
24
+
25
+ DocsDispatcher --> Scan[scan\nSource Analysis]
26
+ DocsDispatcher --> Data[data\nDirective Resolver]
27
+ DocsDispatcher --> Text[text\nAI Text Fill]
28
+ DocsDispatcher --> Forge[forge\nDocs Refinement]
29
+ DocsDispatcher --> Review[review\nQuality Check]
30
+ DocsDispatcher --> Readme[readme\nREADME Generator]
31
+
32
+ SpecDispatcher --> SpecInit[spec init\nSpec Creation]
33
+ SpecDispatcher --> Gate[gate\nGate Check]
34
+
35
+ Scan -->|analysis.json\nsummary.json| OutputDir[.sdd-forge/output/]
36
+ Data -->|reads| OutputDir
37
+ Text -->|reads| OutputDir
38
+ Forge -->|reads| OutputDir
39
+
40
+ Text -->|prompt| AgentLib[lib/agent.js\nAI Agent Caller]
41
+ Forge -->|prompt| AgentLib
42
+ Review -->|prompt| AgentLib
43
+ AgentLib -->|configured command| ExternalAI([External AI Agent\ne.g. Claude CLI])
44
+
45
+ OutputDir -->|resolved directives| DocsDir[docs/\nGenerated Documentation]
46
+ ```
47
+
13
48
  ### Component Responsibilities
14
49
 
15
50
  <!-- {{text: Describe the major components with their location, responsibilities, and I/O in table format.}} -->
16
51
 
52
+ | Component | Location | Responsibility | Input | Output |
53
+ |---|---|---|---|---|
54
+ | CLI Entry Point | `src/sdd-forge.js` | Parses top-level subcommand and resolves project context via environment variables | CLI arguments, `.sdd-forge/projects.json` | Routes to dispatcher with `SDD_SOURCE_ROOT` / `SDD_WORK_ROOT` set |
55
+ | Docs Dispatcher | `src/docs.js` | Routes docs-related subcommands (`build`, `scan`, `data`, `text`, `forge`, `review`, etc.) | Subcommand string | Delegates to `src/docs/commands/*.js` |
56
+ | Spec Dispatcher | `src/spec.js` | Routes spec-related subcommands (`spec`, `gate`) | Subcommand string | Delegates to `src/specs/commands/*.js` |
57
+ | Scanner | `src/docs/lib/scanner.js` | Traverses source files and extracts structural information (PHP, JS, YAML) | Source root path, scan config | `.sdd-forge/output/analysis.json`, `summary.json` |
58
+ | Directive Parser | `src/docs/lib/directive-parser.js` | Parses `{{data}}`, `{{text}}`, `@block`, and `@extends` directives in Markdown templates | Markdown template files | Parsed directive AST |
59
+ | Data Resolver | `src/docs/lib/resolver-factory.js` | Resolves `{{data}}` directives by binding analysis data to named data sources | Parsed directives, `analysis.json` | Rendered Markdown sections |
60
+ | AI Agent Caller | `src/lib/agent.js` | Executes configured external AI agent commands synchronously or asynchronously | Prompt string, agent config | AI-generated text streamed or returned as string |
61
+ | Config Manager | `src/lib/config.js` | Loads and validates `.sdd-forge/config.json`; manages context and path resolution | `.sdd-forge/` directory | Typed config object, resolved paths |
62
+ | Flow State Manager | `src/lib/flow-state.js` | Persists and retrieves SDD workflow state (current spec, branch, worktree info) | Work root path, state object | `.sdd-forge/current-spec` JSON file |
63
+ | Preset System | `src/lib/presets.js` | Auto-discovers `preset.json` files under `src/presets/` and registers available project types | `src/presets/` directory tree | `PRESETS` constant used across all consumers |
64
+ | SDD Flow Runner | `src/flow.js` | Orchestrates the full SDD cycle (spec → gate → implement → forge → review) automatically | `--request` argument, flow state | Sequential command execution with user interaction |
65
+
17
66
  ### External Integrations
18
67
 
19
68
  <!-- {{text: If there are external system integrations, describe their purpose and connection method in table format.}} -->
20
69
 
70
+ | System | Purpose | Connection Method | Configuration |
71
+ |---|---|---|---|
72
+ | AI Agent (e.g. Claude CLI) | Generates and refines documentation text, performs quality review, and evaluates spec gate checks | Spawned as a child process via `child_process.execFileSync` (sync) or `spawn` (async) | Defined in `.sdd-forge/config.json` under `providers` and `defaultAgent`; supports `command`, `args`, `timeoutMs`, and `systemPromptFlag` |
73
+ | Git | Branch creation, worktree isolation, and repository root resolution for SDD workflows | Invoked via `child_process` shell commands (`git rev-parse`, `git worktree`, etc.) | Resolved automatically from the working directory; worktree support detected via `.git` file presence |
74
+
75
+ `sdd-forge` has no network-based external dependencies. All integrations are process-level and operate entirely within the local development environment.
76
+
21
77
  ### Environment Differences
22
78
 
23
79
  <!-- {{text: Describe the configuration differences across environments (local/staging/production).}} -->
80
+
81
+ `sdd-forge` is a local developer CLI tool and does not have traditional deployment environments (staging, production). Configuration is driven entirely by `.sdd-forge/config.json` in each project's working directory.
82
+
83
+ | Aspect | Local Development | CI / Automated Pipeline |
84
+ |---|---|---|
85
+ | Agent invocation | Interactive; supports streaming output callbacks for live feedback | Non-interactive; `callAgentAsync()` with `stdin: "ignore"` to prevent hangs |
86
+ | `CLAUDECODE` env var | May be set if running inside Claude Code | Must be unset before spawning AI agent subprocess (handled automatically by `agent.js`) |
87
+ | Project context | Resolved via `.sdd-forge/projects.json` `default` entry or `--project` flag | Set explicitly via `SDD_SOURCE_ROOT` and `SDD_WORK_ROOT` environment variables |
88
+ | AI agent timeout | Defaults: 120 s / 180 s / 300 s depending on command | Same defaults apply; increase via `config.limits.designTimeoutMs` if needed |
89
+ | Concurrency | Default 5 parallel file processes; tunable via `config.limits.concurrency` | Same; reduce if CPU-constrained in CI runners |
90
+ | Output language | Controlled by `config.output.default` and `config.lang` | Same; no environment-specific overrides exist |
@@ -4,20 +4,267 @@
4
4
 
5
5
  <!-- {{text: Write a 1–2 sentence overview of this chapter. Cover the total number of commands, whether global options exist, and the subcommand structure.}} -->
6
6
 
7
+ This chapter documents all 17 subcommands available in `sdd-forge`, organized across three dispatcher layers (`docs.js`, `spec.js`, and direct commands). Each subcommand is accessible via `sdd-forge <subcommand>`, with a small set of global options applying across the CLI.
8
+
7
9
  ## Contents
8
10
 
9
11
  ### Command List
10
12
 
11
- <!-- {{text: List all commands in a table, including command name, description, and main options. Commands can be identified from the modules list in the analysis data. Include both commands routed through dispatchers (docs.js, spec.js) and directly executed commands (flow, presets). Note that build is a composite command (scan → init → data → text → readme → agents → translate pipeline). Be sure to include translate (multi-language translation), upgrade (template update), and default (default project configuration).}} -->
13
+ <!-- {{text: List all commands in a table format. Include command name, description, and main options. Commands can be identified from the modules list in the analysis data. Include both commands routed through dispatchers (docs.js, spec.js) and directly executed commands (flow, presets). Note that build is a composite command (scan → init → data → text → readme → agents → translate pipeline). Be sure to include translate (multilingual translation), upgrade (template update), and default (default project configuration).}} -->
14
+
15
+ | Command | Description | Key Options |
16
+ |---|---|---|
17
+ | `build` | Run the full documentation pipeline: `scan → init → data → text → readme → agents → translate` | `--project` |
18
+ | `scan` | Analyze source code and output `analysis.json` and `summary.json` | `--project` |
19
+ | `init` | Initialize `docs/` from preset templates | `--project`, `--preset` |
20
+ | `data` | Resolve `{{data}}` directives using analysis results | `--project` |
21
+ | `text` | Resolve `{{text}}` directives using AI agents | `--project`, `--agent`, `--file` |
22
+ | `readme` | Auto-generate `README.md` from docs content | `--project` |
23
+ | `forge` | Iteratively improve docs with AI | `--prompt`, `--spec`, `--project` |
24
+ | `review` | Run a quality check on generated docs | `--project` |
25
+ | `changelog` | Generate `change_log.md` from accumulated specs | `--project` |
26
+ | `agents` | Update `AGENTS.md` (SDD template + PROJECT section) | `--sdd`, `--project`, `--dry-run` |
27
+ | `translate` | Translate docs into additional output languages | `--lang`, `--force`, `--dry-run` |
28
+ | `upgrade` | Update SDD-managed doc templates to the latest version | `--project` |
29
+ | `setup` | Register a project and generate `.sdd-forge/config.json` | — |
30
+ | `default` | Set or display the default project | — |
31
+ | `spec` | Initialize a new spec file and feature branch | `--title`, `--no-branch` |
32
+ | `gate` | Run a gate check against a spec file | `--spec`, `--phase` |
33
+ | `flow` | Automatically execute the full SDD flow for a given request | `--request` |
34
+ | `presets` | List or inspect available project type presets | — |
35
+ | `help` | Display available subcommands and usage information | — |
12
36
 
13
37
  ### Global Options
14
38
 
15
- <!-- {{text: Describe the global options common to all commands in a table. Include --project, --help/-h, and --version/-v/-V. Also note that setup, default, help, and presets skip project context resolution.}} -->
39
+ <!-- {{text: List global options common to all commands in a table format. Include --project, --help/-h, and --version/-v/-V. Also note that setup, default, help, and presets skip project context resolution.}} -->
40
+
41
+ | Option | Alias | Description |
42
+ |---|---|---|
43
+ | `--project <name>` | — | Specify the target project by name, as registered in `.sdd-forge/projects.json`. Overrides the `default` project setting. |
44
+ | `--help` | `-h` | Display usage information for the CLI or a specific subcommand. |
45
+ | `--version` | `-v`, `-V` | Print the installed `sdd-forge` version (read from `package.json`). |
46
+
47
+ > **Note:** The `setup`, `default`, `help`, and `presets` subcommands skip project context resolution entirely. They do not require a registered project and will not read `.sdd-forge/config.json` or set `SDD_SOURCE_ROOT` / `SDD_WORK_ROOT`.
16
48
 
17
49
  ### Command Details
18
50
 
19
51
  <!-- {{text: Describe the usage, options, and examples for each command in detail. Create a #### subsection for each command. For the build pipeline, list all steps: scan → init → data → text → readme → agents → translate. The translate command has --lang, --force, and --dry-run options.}} -->
20
52
 
53
+ #### build
54
+
55
+ Runs the complete documentation generation pipeline in a single step. The pipeline executes the following stages in order: `scan → init → data → text → readme → agents → translate`. This is the standard entry point for first-time setup or full regeneration of project docs.
56
+
57
+ ```bash
58
+ sdd-forge build
59
+ sdd-forge build --project myproject
60
+ ```
61
+
62
+ #### scan
63
+
64
+ Analyzes the project source code according to the configured preset (e.g., `cli/node-cli`, `webapp/cakephp2`) and writes results to `.sdd-forge/output/analysis.json` and `.sdd-forge/output/summary.json`. The `summary.json` is a lightweight version intended for AI consumption.
65
+
66
+ ```bash
67
+ sdd-forge scan
68
+ ```
69
+
70
+ #### init
71
+
72
+ Initializes the `docs/` directory structure by copying preset templates. Templates are resolved from `src/presets/{preset}/templates/{lang}/`. Existing files are not overwritten unless explicitly forced.
73
+
74
+ ```bash
75
+ sdd-forge init
76
+ ```
77
+
78
+ #### data
79
+
80
+ Resolves all `{{data: ...}}` directives found in `docs/` files, replacing them with structured data extracted from `analysis.json`. Directives outside template boundaries are left untouched.
81
+
82
+ ```bash
83
+ sdd-forge data
84
+ ```
85
+
86
+ #### text
87
+
88
+ Resolves `{{text: ...}}` directives in `docs/` files using the configured AI agent. Processes files concurrently up to the `limits.concurrency` setting. Optionally targets a single file.
89
+
90
+ | Option | Description |
91
+ |---|---|
92
+ | `--file <path>` | Process only the specified docs file |
93
+ | `--agent <name>` | Override the AI agent to use |
94
+
95
+ ```bash
96
+ sdd-forge text
97
+ sdd-forge text --file docs/02_cli_commands.md
98
+ ```
99
+
100
+ #### readme
101
+
102
+ Auto-generates `README.md` in the project root using the content of `docs/` as source material. The output is driven by the AI agent defined in the project config.
103
+
104
+ ```bash
105
+ sdd-forge readme
106
+ ```
107
+
108
+ #### forge
109
+
110
+ Iteratively improves one or more docs files using AI, guided by a prompt describing recent changes. When `--spec` is provided, the spec file is included as additional context for the AI.
111
+
112
+ | Option | Description |
113
+ |---|---|
114
+ | `--prompt <text>` | Description of changes to reflect in docs (required) |
115
+ | `--spec <path>` | Path to the spec file for additional context |
116
+
117
+ ```bash
118
+ sdd-forge forge --prompt "Added translate command with --lang option"
119
+ sdd-forge forge --prompt "Refactored scanner" --spec specs/010-refactor/spec.md
120
+ ```
121
+
122
+ #### review
123
+
124
+ Runs a quality check over the generated docs using AI, validating completeness, accuracy, and consistency with the source code. Outputs a PASS or FAIL result with actionable feedback.
125
+
126
+ ```bash
127
+ sdd-forge review
128
+ ```
129
+
130
+ #### changelog
131
+
132
+ Generates `change_log.md` by aggregating all spec files under `specs/`. Each spec contributes a changelog entry describing the feature or fix it represents.
133
+
134
+ ```bash
135
+ sdd-forge changelog
136
+ ```
137
+
138
+ #### agents
139
+
140
+ Updates `AGENTS.md` with the latest SDD instruction template and a newly generated PROJECT section derived from `analysis.json` / `summary.json`. The command supports partial updates via flags.
141
+
142
+ | Option | Description |
143
+ |---|---|
144
+ | `--sdd` | Update only the `<!-- SDD:START/END -->` section |
145
+ | `--project` | Update only the `<!-- PROJECT:START/END -->` section |
146
+ | `--dry-run` | Preview output without writing to disk |
147
+
148
+ ```bash
149
+ sdd-forge agents
150
+ sdd-forge agents --sdd
151
+ sdd-forge agents --dry-run
152
+ ```
153
+
154
+ #### translate
155
+
156
+ Translates the generated docs into one or more additional output languages, as specified by `output.languages` in the project config. Uses `output.mode` (`translate` or `generate`) to determine the translation strategy.
157
+
158
+ | Option | Description |
159
+ |---|---|
160
+ | `--lang <code>` | Target language code to translate into (e.g., `en`, `ja`) |
161
+ | `--force` | Overwrite existing translated files |
162
+ | `--dry-run` | Preview without writing to disk |
163
+
164
+ ```bash
165
+ sdd-forge translate --lang en
166
+ sdd-forge translate --lang en --force
167
+ ```
168
+
169
+ #### upgrade
170
+
171
+ Updates the SDD-managed sections of `docs/` templates to match the latest version bundled with the installed `sdd-forge` package. Content outside directive boundaries is preserved.
172
+
173
+ ```bash
174
+ sdd-forge upgrade
175
+ ```
176
+
177
+ #### setup
178
+
179
+ Registers a new project with `sdd-forge` and generates the initial `.sdd-forge/config.json`. Guides the user through selecting a project type preset and configuring output language settings. Also creates `AGENTS.md` and a `CLAUDE.md` symlink.
180
+
181
+ ```bash
182
+ sdd-forge setup
183
+ ```
184
+
185
+ #### default
186
+
187
+ Sets or displays the default project for the current tool installation. The default project is stored in `.sdd-forge/projects.json` and used when `--project` is not specified.
188
+
189
+ ```bash
190
+ sdd-forge default
191
+ sdd-forge default myproject
192
+ ```
193
+
194
+ #### spec
195
+
196
+ Creates a new spec file under `specs/NNN-<slug>/spec.md` and optionally creates a feature branch. Used at the start of the SDD workflow for any new feature or fix.
197
+
198
+ | Option | Description |
199
+ |---|---|
200
+ | `--title <name>` | Title of the spec / feature (required) |
201
+ | `--no-branch` | Skip branch creation (e.g., when already inside a worktree) |
202
+
203
+ ```bash
204
+ sdd-forge spec --title "Add translate command"
205
+ sdd-forge spec --title "Fix scanner" --no-branch
206
+ ```
207
+
208
+ #### gate
209
+
210
+ Validates a spec file against defined acceptance criteria before (`--phase pre`) or after (`--phase post`) implementation. Reports each check item as PASS or FAIL.
211
+
212
+ | Option | Description |
213
+ |---|---|
214
+ | `--spec <path>` | Path to the spec file to validate (required) |
215
+ | `--phase <pre\|post>` | Gate phase; defaults to `pre` |
216
+
217
+ ```bash
218
+ sdd-forge gate --spec specs/010-translate/spec.md
219
+ sdd-forge gate --spec specs/010-translate/spec.md --phase post
220
+ ```
221
+
222
+ #### flow
223
+
224
+ Automatically executes the full SDD flow — spec creation, gate check, and implementation scaffolding — for a given natural-language request. Intended for AI agent environments where manual step-by-step execution is not practical.
225
+
226
+ | Option | Description |
227
+ |---|---|
228
+ | `--request <text>` | Natural-language description of the feature or fix |
229
+
230
+ ```bash
231
+ sdd-forge flow --request "Add support for multilingual output"
232
+ ```
233
+
234
+ #### presets
235
+
236
+ Lists all available project type presets bundled with `sdd-forge`, including architecture-layer presets (`webapp`, `cli`, `library`) and framework-specific presets (`cakephp2`, `laravel`, `symfony`, `node-cli`).
237
+
238
+ ```bash
239
+ sdd-forge presets
240
+ ```
241
+
242
+ #### help
243
+
244
+ Displays a summary of all available subcommands and their descriptions. Equivalent to running `sdd-forge` with no arguments.
245
+
246
+ ```bash
247
+ sdd-forge help
248
+ sdd-forge -h
249
+ ```
250
+
21
251
  ### Exit Codes and Output
22
252
 
23
- <!-- {{text: Describe exit code definitions (0=success, 1=general error, etc.) and the rules for stdout/stderr usage in a table. Include the point that gate and review PASS/FAIL results are printed to stdout.}} -->
253
+ <!-- {{text: Describe exit code definitions (0=success, 1=general error, etc.) and the rules for stdout/stderr usage in a table format. Include the fact that gate and review PASS/FAIL results are printed to stdout.}} -->
254
+
255
+ **Exit Codes**
256
+
257
+ | Code | Meaning |
258
+ |---|---|
259
+ | `0` | Command completed successfully |
260
+ | `1` | General error (misconfiguration, missing required argument, unexpected failure) |
261
+ | `2` | Validation failure — used by `gate` when one or more checks FAIL, and by `review` when the quality check does not PASS |
262
+
263
+ **stdout / stderr Rules**
264
+
265
+ | Stream | Content |
266
+ |---|---|
267
+ | `stdout` | Primary command output: generated text, rendered tables, `gate` PASS/FAIL check results, `review` PASS/FAIL results, `--dry-run` previews |
268
+ | `stderr` | Diagnostic messages: progress indicators, warnings, error details, AI agent invocation logs |
269
+
270
+ > `gate` and `review` always print their PASS/FAIL verdict and per-item results to `stdout`, making them suitable for use in CI pipelines where stdout is captured and evaluated by automated tooling.
@@ -2,22 +2,132 @@
2
2
 
3
3
  ## Description
4
4
 
5
- <!-- {{text: Describe the overview of this chapter in 12 sentences. Cover the types of configuration files, the range of configurable options, and customization points.}} -->
5
+ <!-- {{text: Describe the overview of this chapter in 1-2 sentences. Cover the types of configuration files, the range of configurable options, and customization points.}} -->
6
+
7
+ This chapter covers the configuration files and customization options available in sdd-forge, including project settings, AI provider definitions, document style controls, and multi-project management. Understanding these options allows you to tailor the tool's behavior to your team's workflow, language preferences, and existing AI infrastructure.
6
8
 
7
9
  ## Contents
8
10
 
9
11
  ### Configuration Files
10
12
 
11
- <!-- {{text: List the configuration files loaded by this tool in a table, including the location and role of each. Main files: .sdd-forge/config.json (project settings), .sdd-forge/context.json (project context), .sdd-forge/projects.json (multi-project management), .sdd-forge/current-spec (SDD flow state), .sdd-forge/output/analysis.json (analysis results), .sdd-forge/output/summary.json (lightweight version for AI).}} -->
13
+ <!-- {{text: List all configuration files loaded by this tool in a table, including their locations and roles. Main files: .sdd-forge/config.json (project settings), .sdd-forge/context.json (project context), .sdd-forge/projects.json (multi-project management), .sdd-forge/current-spec (SDD flow state), .sdd-forge/output/analysis.json (analysis results), .sdd-forge/output/summary.json (lightweight version for AI).}} -->
14
+
15
+ All configuration and generated state files are stored under the `.sdd-forge/` directory at the working root of your project. The table below lists each file, its location, and its purpose.
16
+
17
+ | File | Location | Role |
18
+ |---|---|---|
19
+ | `config.json` | `.sdd-forge/config.json` | Primary project configuration. Defines output languages, project type, AI providers, document style, and workflow settings. Required before most commands can run. |
20
+ | `context.json` | `.sdd-forge/context.json` | Free-form project context string passed to AI agents as supplementary background information. Takes priority over `textFill.projectContext` in `config.json`. |
21
+ | `projects.json` | `.sdd-forge/projects.json` | Multi-project registry. Created by `sdd-forge setup`. Maps project names to their source and working root paths. |
22
+ | `current-spec` | `.sdd-forge/current-spec` | JSON file tracking the active SDD flow state, including the spec path, base branch, and feature branch. Deleted at flow completion. |
23
+ | `analysis.json` | `.sdd-forge/output/analysis.json` | Full source code analysis result produced by `sdd-forge scan`. Stored in compact JSON (no indentation). |
24
+ | `summary.json` | `.sdd-forge/output/summary.json` | Lightweight version of `analysis.json` optimized for AI input. Used in preference to `analysis.json` by commands such as `forge`, `agents`, and `init`. |
12
25
 
13
26
  ### Configuration Reference
14
27
 
15
- <!-- {{text: Describe all fields in .sdd-forge/config.json in a table format. Include field name, whether required, type, default value, and description. Main fields: output.languages (list of output languages), output.default (default language), output.mode (translate/generate), lang (CLI operating language), type (project type), documentStyle (purpose/tone/customInstruction), textFill (projectContext/preamblePatterns), defaultAgent, providers (AI agent definitions), flow.merge (squash/ff-only/merge), limits (concurrency/designTimeoutMs).}} -->
28
+ <!-- {{text: Describe all fields in .sdd-forge/config.json in a table format. Include field name, whether required, type, default value, and description. Main fields: output.languages (output language list), output.default (default language), output.mode (translate/generate), lang (CLI operating language), type (project type), documentStyle (purpose/tone/customInstruction), textFill (projectContext/preamblePatterns), defaultAgent, providers (AI agent definitions), flow.merge (squash/ff-only/merge), limits (concurrency/designTimeoutMs).}} -->
29
+
30
+ The following table describes every supported field in `.sdd-forge/config.json`. Fields marked **Required** must be present for the tool to operate correctly.
31
+
32
+ | Field | Required | Type | Default | Description |
33
+ |---|---|---|---|---|
34
+ | `output.languages` | ✅ | `string[]` | — | List of output languages for generated documentation (e.g., `["ja"]`, `["en", "ja"]`). |
35
+ | `output.default` | ✅ | `string` | — | The primary language used when generating documentation (e.g., `"ja"`). |
36
+ | `output.mode` | — | `"translate"` \| `"generate"` | `"translate"` | How non-default languages are produced. `translate` derives them from the default-language output; `generate` produces them independently. |
37
+ | `lang` | ✅ | `string` | — | Operating language for the CLI, AGENTS.md, skill prompts, and spec files (e.g., `"ja"`, `"en"`). |
38
+ | `type` | ✅ | `string` | — | Project type identifier that selects the matching preset (e.g., `"webapp/cakephp2"`, `"cli/node-cli"`). |
39
+ | `uiLang` | — | `"en"` \| `"ja"` | — | Language used for CLI interface messages. |
40
+ | `documentStyle.purpose` | — | `string` | — | Describes the intended audience and purpose of the generated documentation. |
41
+ | `documentStyle.tone` | — | `"polite"` \| `"formal"` \| `"casual"` | — | Controls the writing style applied by the AI when generating documentation text. |
42
+ | `documentStyle.customInstruction` | — | `string` | — | Additional free-form instructions passed to the AI agent during text generation. |
43
+ | `textFill.projectContext` | — | `string` | — | A brief description of the project used as supplementary context for AI generation. Overridden by `context.json` if present. |
44
+ | `textFill.preamblePatterns` | — | `object[]` | — | Patterns used to strip unwanted preamble text from LLM output before it is written to documentation files. |
45
+ | `defaultAgent` | — | `string` | — | The key name of the AI provider defined in `providers` to use when no explicit `--agent` flag is given. |
46
+ | `providers` | — | `object` | — | A map of named AI agent definitions. Each entry specifies `command`, `args`, optional `timeoutMs`, and `systemPromptFlag`. |
47
+ | `flow.merge` | — | `"squash"` \| `"ff-only"` \| `"merge"` | `"squash"` | Git merge strategy applied when closing an SDD flow and merging the feature branch back to the base branch. |
48
+ | `limits.concurrency` | — | `number` | `5` | Number of files processed in parallel during documentation generation. |
49
+ | `limits.designTimeoutMs` | — | `number` | — | Maximum time in milliseconds allowed for a single AI agent call before it is considered timed out. |
16
50
 
17
51
  ### Customization Points
18
52
 
19
- <!-- {{text: Describe the items users can customize. (1) AI provider settings (providers field, command/args/timeoutMs/systemPromptFlag) with configuration examples, (2) document style (purpose/tone/customInstruction), (3) preset selection (type field), (4) merge strategy (flow.merge), (5) concurrency level (limits.concurrency). Include JSON configuration examples for each item.}} -->
53
+ <!-- {{text: Explain the items users can customize. (1) AI provider settings (providers field, command/args/timeoutMs/systemPromptFlag) with configuration examples, (2) document style (purpose/tone/customInstruction), (3) preset selection (type field), (4) merge strategy (flow.merge), (5) concurrency (limits.concurrency). Include a JSON configuration example for each item.}} -->
54
+
55
+ **1. AI Provider Settings**
56
+
57
+ The `providers` field lets you register one or more AI agents and control how sdd-forge invokes them. Each provider entry specifies the executable command, the argument list (use `{{PROMPT}}` as a placeholder for the prompt — if omitted it is appended automatically), an optional timeout, and how the system prompt is passed.
58
+
59
+ ```json
60
+ {
61
+ "defaultAgent": "claude",
62
+ "providers": {
63
+ "claude": {
64
+ "command": "claude",
65
+ "args": ["--model", "claude-opus-4-5", "-p", "{{PROMPT}}"],
66
+ "timeoutMs": 180000,
67
+ "systemPromptFlag": "--system-prompt"
68
+ }
69
+ }
70
+ }
71
+ ```
72
+
73
+ **2. Document Style**
74
+
75
+ The `documentStyle` block shapes the tone and focus of every AI-generated text section. Set `purpose` to describe who will read the documentation, `tone` to control formality, and `customInstruction` to pass any project-specific writing rules directly to the AI.
76
+
77
+ ```json
78
+ {
79
+ "documentStyle": {
80
+ "purpose": "Internal reference for backend engineers onboarding to the project",
81
+ "tone": "formal",
82
+ "customInstruction": "Always use active voice and avoid passive constructions."
83
+ }
84
+ }
85
+ ```
86
+
87
+ **3. Preset Selection**
88
+
89
+ The `type` field selects the preset that determines which source files are scanned and which documentation template structure is applied. Choose the value that best matches your project's architecture.
90
+
91
+ ```json
92
+ {
93
+ "type": "cli/node-cli"
94
+ }
95
+ ```
96
+
97
+ Available preset keys include `webapp/cakephp2`, `webapp/laravel`, `webapp/symfony`, and `cli/node-cli`. Use `sdd-forge presets` to list all available options.
98
+
99
+ **4. Merge Strategy**
100
+
101
+ The `flow.merge` field controls how feature branches are integrated into the base branch at the end of an SDD workflow. `squash` (the default) combines all commits into one clean commit; `ff-only` requires a linear history; `merge` creates a standard merge commit.
102
+
103
+ ```json
104
+ {
105
+ "flow": {
106
+ "merge": "squash"
107
+ }
108
+ }
109
+ ```
110
+
111
+ **5. Concurrency**
112
+
113
+ The `limits.concurrency` field sets the number of source files processed in parallel during documentation generation. Increase this value on machines with sufficient resources to speed up large codebases, or decrease it to reduce memory pressure.
114
+
115
+ ```json
116
+ {
117
+ "limits": {
118
+ "concurrency": 10
119
+ }
120
+ }
121
+ ```
20
122
 
21
123
  ### Environment Variables
22
124
 
23
- <!-- {{text: List the environment variables referenced by the tool and their purposes in a table. SDD_SOURCE_ROOT (source code root), SDD_WORK_ROOT (work root, location where .sdd-forge/ is placed), CLAUDECODE (internal variable deleted to prevent Claude CLI from hanging).}} -->
125
+ <!-- {{text: List the environment variables referenced by the tool and their purposes in a table. SDD_SOURCE_ROOT (source code root), SDD_WORK_ROOT (working root, location of .sdd-forge/), CLAUDECODE (internal variable removed to prevent Claude CLI hangs).}} -->
126
+
127
+ The following environment variables influence the behavior of sdd-forge at runtime. They are typically set automatically by the tool itself during command execution, but can also be specified manually when integrating sdd-forge into scripts or CI pipelines.
128
+
129
+ | Variable | Direction | Description |
130
+ |---|---|---|
131
+ | `SDD_SOURCE_ROOT` | Input | Absolute path to the root of the source code being analyzed. When set, overrides the path resolved from `projects.json` or the current working directory. |
132
+ | `SDD_WORK_ROOT` | Input | Absolute path to the working root — the directory that contains `.sdd-forge/`. When set, all config, output, and state files are read from and written to this location. |
133
+ | `CLAUDECODE` | Internal | An environment variable that sdd-forge actively **removes** before spawning AI agent processes. This prevents the Claude CLI from entering an interactive mode and hanging when standard input is closed. |
@@ -2,26 +2,199 @@
2
2
 
3
3
  ## Overview
4
4
 
5
- <!-- {{text: Describe the purpose of this chapter in 1–2 sentences. Cover the project structure, module dependency direction, and key processing flows.}} -->
5
+ <!-- {{text: Describe the purpose of this chapter in 1–2 sentences. Cover the project structure, direction of module dependencies, and key processing flows.}} -->
6
+
7
+ This chapter describes the internal architecture of sdd-forge, covering the directory layout, module responsibilities, and dependency relationships. It also documents the key processing flows that run when core commands such as `build` and `forge` are executed.
6
8
 
7
9
  ## Contents
8
10
 
9
11
  ### Project Structure
10
12
 
11
- <!-- {{text: Describe the directory structure of this project in a tree-format code block. Include role comments for major directories and files. Cover the dispatchers directly under src/ (sdd-forge.js, docs.js, spec.js, flow.js), docs/commands/ (subcommand implementations), docs/lib/ (document generation library), lib/ (shared utilities), presets/ (preset definitions), and templates/ (bundled templates).}} -->
13
+ <!-- {{text: Describe the directory structure of this project in a tree-format code block. Include role comments for major directories and files. Cover the top-level dispatchers under src/ (sdd-forge.js, docs.js, spec.js, flow.js), docs/commands/ (subcommand implementations), docs/lib/ (document generation libraries), lib/ (shared utilities), presets/ (preset definitions), and templates/ (bundled templates).}} -->
14
+
15
+ ```
16
+ sdd-forge/
17
+ ├── package.json ← Package manifest; bin entry points to src/sdd-forge.js
18
+ ├── src/
19
+ │ ├── sdd-forge.js ← Top-level CLI entry point; routes to docs.js / spec.js / flow.js
20
+ │ ├── docs.js ← Dispatcher for all docs-related subcommands
21
+ │ ├── spec.js ← Dispatcher for spec and gate subcommands
22
+ │ ├── flow.js ← SDD flow automation (DIRECT_COMMAND, no sub-routing)
23
+ │ ├── presets-cmd.js ← Dispatcher for the presets subcommand
24
+ │ ├── help.js ← Renders the command reference to stdout
25
+ │ ├── docs/
26
+ │ │ ├── commands/ ← One file per docs subcommand (scan, init, data, text,
27
+ │ │ │ readme, forge, review, agents, changelog, setup, …)
28
+ │ │ ├── data/ ← DataSource implementations (project.js, docs.js,
29
+ │ │ │ agents.js, lang.js)
30
+ │ │ └── lib/ ← Document-generation library (scanner, directive-parser,
31
+ │ │ template-merger, renderers, forge-prompts, text-prompts,
32
+ │ │ data-source, data-source-loader, resolver-factory, …)
33
+ │ ├── specs/
34
+ │ │ └── commands/ ← Spec subcommand implementations (init, gate)
35
+ │ ├── lib/ ← Shared utilities (agent, cli, config, flow-state,
36
+ │ │ presets, i18n, process, projects, types)
37
+ │ ├── presets/ ← Preset definitions; each subdirectory holds preset.json
38
+ │ │ ├── base/ ← Base preset + doc templates (ja/en)
39
+ │ │ ├── webapp/, cli/, library/ ← Architecture-layer presets
40
+ │ │ ├── cakephp2/, laravel/, symfony/ ← Framework-specific presets
41
+ │ │ ├── node-cli/ ← Node.js CLI preset
42
+ │ │ └── lib/ ← Shared preset utilities (composer-utils.js)
43
+ │ └── templates/ ← Bundled project templates (config.example.json,
44
+ │ review-checklist.md, SDD skill scripts)
45
+ ├── docs/ ← sdd-forge's own design documentation (published to npm)
46
+ ├── tests/ ← Test files (*.test.js, Node.js built-in test runner)
47
+ └── specs/ ← Accumulated SDD spec files (020+ entries)
48
+ ```
12
49
 
13
50
  ### Module Overview
14
51
 
15
52
  <!-- {{text: List the major modules in a table format. Include module name, file path, and responsibility. Cover the dispatcher layer (sdd-forge.js, docs.js, spec.js), command layer (docs/commands/*.js, specs/commands/*.js), library layer (lib/agent.js, lib/cli.js, lib/config.js, lib/flow-state.js, lib/presets.js, lib/i18n.js), and document generation layer (docs/lib/scanner.js, directive-parser.js, template-merger.js, forge-prompts.js, text-prompts.js, review-parser.js, data-source.js, resolver-factory.js).}} -->
16
53
 
54
+ | Module | File Path | Responsibility |
55
+ |---|---|---|
56
+ | **CLI Entry Point** | `src/sdd-forge.js` | Parses the top-level subcommand, resolves project context via env vars, and routes to the appropriate dispatcher |
57
+ | **Docs Dispatcher** | `src/docs.js` | Routes docs-related subcommands (`build`, `scan`, `init`, `data`, `text`, `readme`, `forge`, `review`, `changelog`, `agents`, `setup`, …) to their command files |
58
+ | **Spec Dispatcher** | `src/spec.js` | Routes `spec` and `gate` subcommands to their command files |
59
+ | **Flow Command** | `src/flow.js` | Executes the end-to-end SDD workflow automation as a single DIRECT_COMMAND |
60
+ | **Scan Command** | `src/docs/commands/scan.js` | Invokes the scanner on the source tree and writes `analysis.json` / `summary.json` |
61
+ | **Data Command** | `src/docs/commands/data.js` | Resolves `{{data}}` directives in doc templates using DataSource implementations |
62
+ | **Text Command** | `src/docs/commands/text.js` | Resolves `{{text}}` directives by invoking the configured AI agent |
63
+ | **Forge Command** | `src/docs/commands/forge.js` | Iteratively improves docs by generating and applying AI-suggested edits |
64
+ | **Review Command** | `src/docs/commands/review.js` | Runs the AI-powered doc quality check and parses pass/fail results |
65
+ | **Spec Init Command** | `src/specs/commands/init.js` | Creates a new spec directory and `spec.md` scaffold, optionally creating a feature branch |
66
+ | **Gate Command** | `src/specs/commands/gate.js` | Validates a spec against pre- or post-implementation checklists |
67
+ | **Agent Utilities** | `src/lib/agent.js` | Wraps synchronous and asynchronous AI agent invocations; handles prompt injection and timeout management |
68
+ | **CLI Utilities** | `src/lib/cli.js` | Provides `parseArgs()`, `repoRoot()`, `sourceRoot()`, `isInsideWorktree()`, and the `PKG_DIR` constant |
69
+ | **Config Utilities** | `src/lib/config.js` | Loads and validates `.sdd-forge/config.json`; manages context, output, and data directory paths |
70
+ | **Flow State** | `src/lib/flow-state.js` | Persists and retrieves the current SDD workflow state in `.sdd-forge/current-spec` |
71
+ | **Presets Registry** | `src/lib/presets.js` | Auto-discovers `preset.json` files under `src/presets/` and exports the `PRESETS` constant |
72
+ | **i18n** | `src/lib/i18n.js` | Loads locale strings for CLI messages and template labels |
73
+ | **Scanner** | `src/docs/lib/scanner.js` | Traverses the source tree and extracts structural information from PHP, JS, and YAML files |
74
+ | **Directive Parser** | `src/docs/lib/directive-parser.js` | Parses `{{data}}`, `{{text}}`, `@block`, and `@extends` directives from Markdown templates |
75
+ | **Template Merger** | `src/docs/lib/template-merger.js` | Resolves `@extends` / `@block` template inheritance chains |
76
+ | **Forge Prompts** | `src/docs/lib/forge-prompts.js` | Builds AI prompts for the `forge` and `agents` commands; exports `summaryToText()` |
77
+ | **Text Prompts** | `src/docs/lib/text-prompts.js` | Builds per-directive AI prompts for the `text` command |
78
+ | **Review Parser** | `src/docs/lib/review-parser.js` | Parses structured pass/fail results from AI review output |
79
+ | **DataSource Base** | `src/docs/lib/data-source.js` | Abstract base class for all `{{data}}` resolver implementations |
80
+ | **Resolver Factory** | `src/docs/lib/resolver-factory.js` | Creates the appropriate DataSource resolver for a given directive via `createResolver()` |
81
+
17
82
  ### Module Dependencies
18
83
 
19
- <!-- {{text: Generate a mermaid graph showing inter-module dependencies. Reflect the three-layer dispatch structure and show the dependency direction from dispatcher → command → library. Output only the mermaid code block.}} -->
84
+ <!-- {{text: Generate a mermaid graph showing the dependencies between modules. Reflect the three-layer dispatch structure and show the dependency direction from dispatcher → command → library. Output only the mermaid code block.}} -->
85
+
86
+ ```mermaid
87
+ graph TD
88
+ CLI["sdd-forge.js<br/>(Entry Point)"]
89
+
90
+ CLI --> DOCS["docs.js<br/>(Docs Dispatcher)"]
91
+ CLI --> SPEC["spec.js<br/>(Spec Dispatcher)"]
92
+ CLI --> FLOW["flow.js<br/>(Flow Command)"]
93
+
94
+ DOCS --> SCAN["docs/commands/scan.js"]
95
+ DOCS --> INIT_D["docs/commands/init.js"]
96
+ DOCS --> DATA["docs/commands/data.js"]
97
+ DOCS --> TEXT["docs/commands/text.js"]
98
+ DOCS --> FORGE["docs/commands/forge.js"]
99
+ DOCS --> REVIEW["docs/commands/review.js"]
100
+ DOCS --> AGENTS["docs/commands/agents.js"]
101
+ DOCS --> README["docs/commands/readme.js"]
102
+
103
+ SPEC --> SPEC_INIT["specs/commands/init.js"]
104
+ SPEC --> GATE["specs/commands/gate.js"]
105
+
106
+ SCAN --> SCANNER["docs/lib/scanner.js"]
107
+ DATA --> DIR_PARSER["docs/lib/directive-parser.js"]
108
+ DATA --> RESOLVER["docs/lib/resolver-factory.js"]
109
+ DATA --> DS["docs/lib/data-source.js"]
110
+ TEXT --> DIR_PARSER
111
+ TEXT --> TEXT_PROMPTS["docs/lib/text-prompts.js"]
112
+ FORGE --> FORGE_PROMPTS["docs/lib/forge-prompts.js"]
113
+ REVIEW --> REVIEW_PARSER["docs/lib/review-parser.js"]
114
+ INIT_D --> TMPL_MERGER["docs/lib/template-merger.js"]
115
+
116
+ SCAN --> CONFIG["lib/config.js"]
117
+ DATA --> CONFIG
118
+ TEXT --> CONFIG
119
+ FORGE --> CONFIG
120
+ REVIEW --> CONFIG
121
+ FORGE --> AGENT["lib/agent.js"]
122
+ TEXT --> AGENT
123
+ REVIEW --> AGENT
124
+ AGENTS --> AGENT
125
+
126
+ SPEC_INIT --> CLI_LIB["lib/cli.js"]
127
+ GATE --> CLI_LIB
128
+ SCAN --> CLI_LIB
129
+ FLOW --> CONFIG
130
+ FLOW --> CLI_LIB
131
+ FLOW --> FLOW_STATE["lib/flow-state.js"]
132
+
133
+ RESOLVER --> DS
134
+ FORGE_PROMPTS --> SCANNER
135
+ CLI --> CONFIG
136
+ ```
20
137
 
21
138
  ### Key Processing Flows
22
139
 
23
- <!-- {{text: Explain the data and control flow between modules when a representative command (build or forge) is executed, using numbered steps. Include the sequence: entry point → dispatch → config loading → analysis data preparation → AI invocation → file writing.}} -->
140
+ <!-- {{text: Explain the inter-module data and control flow when a representative command (build or forge) is executed, using numbered steps. Include the flow from entry point → dispatch → config loading → analysis data preparation → AI invocation → file writing.}} -->
141
+
142
+ **`sdd-forge build` flow**
143
+
144
+ 1. **Entry** — `sdd-forge.js` receives the `build` subcommand, resolves the project context (via `--project` flag or `.sdd-forge/projects.json`), and sets `SDD_SOURCE_ROOT` / `SDD_WORK_ROOT` environment variables.
145
+ 2. **Dispatch** — `docs.js` maps `build` to the ordered pipeline: `scan → init → data → text → readme`.
146
+ 3. **Config loading** — Each command calls `loadConfig()` in `lib/config.js` to read `.sdd-forge/config.json` and obtain output language settings, project type, and agent configuration.
147
+ 4. **Source scan** — `docs/commands/scan.js` invokes `scanner.js` to traverse the source tree. The result is serialised to `.sdd-forge/output/analysis.json` and a lightweight `.sdd-forge/output/summary.json`.
148
+ 5. **Template initialisation** — `docs/commands/init.js` applies `template-merger.js` to resolve `@extends` / `@block` inheritance and write the initial Markdown template files into `docs/`.
149
+ 6. **Data resolution** — `docs/commands/data.js` uses `directive-parser.js` to locate `{{data}}` directives, then calls `resolver-factory.js` to instantiate the matching DataSource. Each DataSource reads from `analysis.json` or `summary.json` and writes rendered Markdown back into the doc file.
150
+ 7. **AI text generation** — `docs/commands/text.js` locates `{{text}}` directives, builds prompts via `text-prompts.js`, and calls `callAgentAsync()` in `lib/agent.js` to stream responses from the configured AI agent. Results are written inline into the doc files.
151
+ 8. **README generation** — `docs/commands/readme.js` assembles the project README from the now-populated doc files and writes `README.md`.
152
+
153
+ **`sdd-forge forge` flow**
154
+
155
+ 1. **Entry & dispatch** — `sdd-forge.js` → `docs.js` → `docs/commands/forge.js`.
156
+ 2. **Config & data loading** — `loadConfig()` provides agent settings; `summaryToText()` in `forge-prompts.js` converts `summary.json` into a compact textual representation for the AI prompt.
157
+ 3. **Prompt construction** — `forge-prompts.js` combines the summary text, the current doc content, and the `--prompt` argument into a structured improvement request.
158
+ 4. **AI invocation** — `callAgentAsync()` in `lib/agent.js` spawns the AI agent process with `stdin: "ignore"` to avoid EOF hangs, streaming output back via callback.
159
+ 5. **File writing** — The agent's output is parsed and written back to the target doc files, preserving content outside `{{data}}` / `{{text}}` directive blocks.
160
+ 6. **Review** — The caller is expected to subsequently run `sdd-forge review`, which uses `review-parser.js` to evaluate the updated docs and report pass/fail status.
24
161
 
25
162
  ### Extension Points
26
163
 
27
- <!-- {{text: Explain what needs to change and the extension patterns when adding new commands or features. Cover each of the following: (1) adding a new docs subcommand, (2) adding a new spec subcommand, (3) adding a new preset, (4) adding a new DataSource ({{data}} resolver), and (5) adding a new AI prompt.}} -->
164
+ <!-- {{text: Explain where changes are needed and the extension patterns when adding new commands or features. Provide steps for each of the following: (1) adding a new docs subcommand, (2) adding a new spec subcommand, (3) adding a new preset, (4) adding a new DataSource ({{data}} resolver), and (5) adding a new AI prompt.}} -->
165
+
166
+ **(1) Adding a new docs subcommand**
167
+
168
+ 1. Create `src/docs/commands/<name>.js` and export (or call at the bottom) a `main()` function.
169
+ 2. Open `src/docs.js` and add a `case '<name>':` branch that imports and invokes the new command file.
170
+ 3. Update `src/help.js` to include the new subcommand in the printed reference.
171
+ 4. Add a corresponding test file under `tests/docs/commands/`.
172
+
173
+ **(2) Adding a new spec subcommand**
174
+
175
+ 1. Create `src/specs/commands/<name>.js` with a `main()` function.
176
+ 2. Open `src/spec.js` and add a routing entry for the new subcommand name.
177
+ 3. Update `src/help.js` with a description of the new subcommand.
178
+ 4. Add tests under `tests/specs/commands/`.
179
+
180
+ **(3) Adding a new preset**
181
+
182
+ 1. Create a directory under `src/presets/<key>/` containing a `preset.json` that declares `type`, `arch`, `isArch`, and `chapters`.
183
+ 2. If the preset requires custom scan logic, add a DataSource file under `src/docs/data/` or directly within the preset directory.
184
+ 3. Place Markdown templates in `src/presets/<key>/templates/{ja,en}/` following the naming convention used by existing presets.
185
+ 4. The `PRESETS` constant in `src/lib/presets.js` is built by auto-discovery, so no manual registration is required.
186
+ 5. Add an alias to `src/lib/types.js` → `TYPE_ALIASES` if a short-form name is needed.
187
+
188
+ **(4) Adding a new DataSource (`{{data}}` resolver)**
189
+
190
+ 1. Create a new class in `src/docs/data/` (or inside the relevant preset directory) that extends `DataSource` from `src/docs/lib/data-source.js` and implements the `resolve()` method.
191
+ 2. Register the new resolver key in `src/docs/lib/resolver-factory.js` inside `createResolver()` so that directive-parser matches `{{data: <key>(...)}}` to your class.
192
+ 3. Ensure the resolver reads from `.sdd-forge/output/summary.json` (falling back to `analysis.json`) rather than operating directly on source files.
193
+ 4. Add unit tests under `tests/docs/` covering the resolver's output format.
194
+
195
+ **(5) Adding a new AI prompt**
196
+
197
+ 1. Determine whether the prompt belongs to the iterative improvement flow (`forge-prompts.js`) or the per-directive generation flow (`text-prompts.js`) and open the corresponding file in `src/docs/lib/`.
198
+ 2. Add a new exported function that accepts the relevant context (summary text, doc content, user-supplied hint) and returns a fully-formed prompt string.
199
+ 3. Import and call the new function from the command file that will use it (`forge.js`, `text.js`, or `agents.js`).
200
+ 4. If the prompt uses a system prompt, confirm whether `systemPromptFlag` in the agent config is `"--system-prompt"` or `"--system-prompt-file"` (the latter writes a temporary file) — see `lib/agent.js` for details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdd-forge",
3
- "version": "0.1.0-alpha.23",
3
+ "version": "0.1.0-alpha.24",
4
4
  "description": "Spec-Driven Development tooling for automated documentation generation",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,7 +12,7 @@ import path from "path";
12
12
  import { runIfDirect } from "../../lib/entrypoint.js";
13
13
  import { repoRoot, parseArgs } from "../../lib/cli.js";
14
14
  import { loadLang, sddOutputDir, resolveProjectContext } from "../../lib/config.js";
15
- import { callAgent, loadAgentConfig, MID_AGENT_TIMEOUT_MS } from "../../lib/agent.js";
15
+ import { callAgent, loadAgentConfig, LONG_AGENT_TIMEOUT_MS } from "../../lib/agent.js";
16
16
  import { createI18n } from "../../lib/i18n.js";
17
17
  import { createResolver } from "../lib/resolver-factory.js";
18
18
  import { createLogger } from "../../lib/progress.js";
@@ -179,7 +179,7 @@ async function main(ctx) {
179
179
  const prompt = buildRefinePrompt(projectContent, summary, config, srcRoot, sddContent);
180
180
 
181
181
  try {
182
- const result = callAgent(agent, prompt, MID_AGENT_TIMEOUT_MS, undefined, { systemPrompt });
182
+ const result = callAgent(agent, prompt, LONG_AGENT_TIMEOUT_MS, undefined, { systemPrompt });
183
183
 
184
184
  let refined = result.trim();
185
185