phasegate 0.152.8 → 0.153.0

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/CHANGELOG.md CHANGED
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.153.0] - 2026-05-13
11
+
12
+ ### Added
13
+
14
+ - **WI-175 — agent setup completeness and confidence** — adds `setup:agent` completeness summaries, `config:plan` managed/external action separation with `phasegate.config.json` patch previews, target-aware install permission error guidance, and regression coverage for strict setup no-diff behavior.
15
+
16
+ ## [0.152.9] - 2026-05-13
17
+
18
+ ### Added
19
+
20
+ - **WI-171 / WI-172 / WI-173 / WI-174 — user onboarding and agent-driven setup** — adds first-run recipes and troubleshooting guides, managed `AGENTS.md` / `CLAUDE.md` setup sections, dedicated AGENTS lesson pointer refresh, `setup:agent` setup planning/apply flow, and `config:plan` configuration-change intent planning.
21
+
10
22
  ## [0.152.8] - 2026-05-13
11
23
 
12
24
  ### Changed
package/README.md CHANGED
@@ -60,6 +60,8 @@ The point is not just to fail the edit. The error gives the AI agent enough stru
60
60
 
61
61
  ## Quick Start
62
62
 
63
+ For a guided first run, start with [Getting Started](docs/guide/getting-started.md). It maps new repo, existing repo, CI-only, agent-hook, and strict rollout paths to the next command and success state. <!-- @work-item-id WI-171 -->
64
+
63
65
  ### Requirements
64
66
 
65
67
  Node.js >= 18, npm >= 9, TypeScript 5.x
@@ -98,7 +100,18 @@ npx phasegate install --apply
98
100
  npx phasegate doctor
99
101
  ```
100
102
 
101
- `install` merges PhaseGate into the current project without discarding existing Claude/Codex hooks or Husky scripts. It reports planned changes before writing, adds package scripts and the `phasegate` devDependency, creates agent skill links, writes the CI workflow when missing, and records managed files in `.phasegate/manifest.json`. If an existing file needs a forced managed update, run `npx phasegate install --apply --force`; PhaseGate backs up replaced files under `.phasegate/backups/`.
103
+ `install` merges PhaseGate into the current project without discarding existing Claude/Codex hooks or Husky scripts. It reports planned changes before writing, adds package scripts and the `phasegate` devDependency, creates agent skill links, writes `AGENTS.md` / `CLAUDE.md` PhaseGate managed sections for the selected agent targets, writes the CI workflow when missing, and records managed files in `.phasegate/manifest.json`. If an existing file needs a forced managed update, run `npx phasegate install --apply --force`; PhaseGate backs up replaced files under `.phasegate/backups/`. <!-- @work-item-id WI-174 -->
104
+
105
+ For agent-driven setup planning, use:
106
+
107
+ ```bash
108
+ npx phasegate setup:agent --intent recommended --dry-run --json
109
+ npx phasegate config:plan --intent codex-hooks --dry-run --json
110
+ ```
111
+
112
+ `setup:agent --json` includes `plan.completeness`, which separates local configured/planned areas from external manual checks such as Codex user-level feature enablement or the first CI run. `config:plan` includes a read-only `configPatch` preview when an intent would change `phasegate.config.json`. <!-- @work-item-id WI-175 -->
113
+
114
+ The first command reports detected setup state, missing questions, planned managed targets, rollback, and validation. The second maps a configuration change intent to files, commands, risks, and checks. <!-- @work-item-id WI-172, WI-173 -->
102
115
 
103
116
  To remove PhaseGate from that project later, run:
104
117
 
@@ -507,6 +520,8 @@ README keeps only the entry points most users need. The full public/compatibilit
507
520
  | `doctor` | Diagnose silent or partial installations (`--json`, `--strict`, `--report-out <path>`). `--report-out` is an explicit file path, not `reporting.outputDir`. |
508
521
  | `uninstall --dry-run` / `--apply` | Remove PhaseGate-managed files and managed blocks using `.phasegate/manifest.json`, preserving user content. |
509
522
  | `reconcile --dry-run` / `--apply` | Update PhaseGate-managed files to the current package templates and refresh manifest hashes. |
523
+ | `setup:agent --dry-run` / `--apply` | Diagnose repository setup and produce or apply an agent-readable setup plan with questions, risks, rollback, and validation. |
524
+ | `config:plan --intent <intent>` | Map a safe configuration-change intent to target files, commands, risks, rollback, and validation. |
510
525
  | `lint` / `phasegate:lint` | Run L1 Biome AST checks. The `phasegate:*` form is a binary subcommand, not an npm script unless `package.json` defines it locally. |
511
526
  | `validate --layer <L1-L4\|all>` | Run validators for the specified layer (`--layer L0` prints runtime hook guidance). `--fail-on-warning` / `--no-fail-on-warning` override config. |
512
527
  | `ci-check` | Full CI check (L2-L4; disabled L4 is reported as skipped). Supports `--quick`, `--fail-on-reject`, `--dry-run`, and `--files`. |
@@ -547,6 +562,9 @@ See the [CLI Reference](docs/guide/cli-reference.md) for the complete catalog an
547
562
  Detailed guides are available under `docs/guide/`:
548
563
 
549
564
  - [Installation](docs/guide/installation.md) -- Detailed install and setup instructions
565
+ - [Getting Started](docs/guide/getting-started.md) -- First-run, daily-use, CI-use, and agent-use paths
566
+ - [Recipes](docs/guide/recipes.md) -- Focused onboarding and configuration recipes
567
+ - [Troubleshooting](docs/guide/troubleshooting.md) -- Doctor finding, repairHint, suggestedSkill, and setup recovery guide
550
568
  - [Configuration](docs/guide/configuration.md) -- `phasegate.config.json` full reference
551
569
  - [CLI Reference](docs/guide/cli-reference.md) -- All CLI commands and options
552
570
  - [Skills Overview](docs/guide/skills-overview.md) -- 30 skills with AIDLC execution order
@@ -23,10 +23,12 @@ Command names in this document are split into three surfaces:
23
23
  | Command | Description |
24
24
  |---|---|
25
25
  | `init --name <name>` | Legacy-compatible bootstrap for new projects: deploy skills, generate config, and optionally add hooks/CI. Options: `--preset <full\|standard\|minimal\|custom>`, `--skills <core\|all>`, `--agent <claude\|codex\|both>`, `--workflow <standard\|strict>`, `--with-husky`, `--with-ci`, `--yes`. |
26
- | `install --dry-run` / `--apply` | Idempotently merge PhaseGate into an existing project, preserve user content, add package scripts/devDependency, and write `.phasegate/manifest.json`. `--force` replaces managed targets after backup. |
26
+ | `install --dry-run` / `--apply` | Idempotently merge PhaseGate into an existing project, preserve user content, add package scripts/devDependency, create selected `AGENTS.md` / `CLAUDE.md` managed sections, and write `.phasegate/manifest.json`. `--agent <claude\|codex\|both>`, `--skills <core\|all>`, and `--workflow <standard\|strict>` affect rendered agent context; `--force` replaces managed targets after backup. |
27
27
  | `doctor` | Diagnose silent or partial installations and report repair hints (`--json`, `--strict`, `--report-out <path>`). `--report-out` writes exactly to the supplied path, not to `reporting.outputDir`. |
28
28
  | `uninstall --dry-run` / `--apply` | Remove PhaseGate-managed files and managed blocks using `.phasegate/manifest.json`; `--force` handles managed conflict cases. |
29
29
  | `reconcile --dry-run` / `--apply` | Update PhaseGate-managed files to current package templates and refresh manifest hashes; `--force` allows managed-file replacement with backup. |
30
+ | `setup:agent` | Agent-readable setup planner and optional apply path. Options: `--intent <minimal\|recommended\|strict\|ci-only\|agent-hooks\|retrofit>`, `--agent <claude\|codex\|both>`, `--workflow <standard\|strict>`, `--with-husky`, `--with-ci`, `--dry-run`, `--apply`, `--json`. <!-- @work-item-id WI-172 --> |
31
+ | `config:plan` | Agent-readable configuration change planner. Options: `--intent <l4-strict\|codex-hooks\|ci-fail-on-warning\|baseline-reset\|quick-mode-strict>`, `--dry-run`, `--json`. <!-- @work-item-id WI-173 --> |
30
32
  | `update-skills` | Compatibility alias for `reconcile`; use `reconcile` for new automation. |
31
33
  | `scaffold-wi <unit> <type>` | Create `docs/inception/{unit}/WI-XXX/description.md` using the next free WI number. |
32
34
  | `emit-agent-rules` | Print the AGENTS.md / CLAUDE.md WI workflow rules block. |
@@ -374,7 +376,7 @@ ISSUE-005 P3-10 で明確化された境界:
374
376
  |---|---|---|
375
377
  | `ci:generate-template` | `--preset <id>`(省略時 `standard`) `--type <type>` `--render` `--json` | Generate CI/CD template |
376
378
  | `ci:migrate-agents-md` | `--dry-run` `--validate-only` `--json` | Migrate AGENTS.md to pointer format |
377
- | `ci:auto-refresh-agent-context` | `--dry-run` `--apply` `--json` | Refresh AGENTS.md pointers and CLAUDE.md standard sections |
379
+ | `ci:auto-refresh-agent-context` | `--dry-run` `--apply` `--json` | Refresh AGENTS.md lesson pointers in a dedicated section and CLAUDE.md standard sections without replacing user-owned agent instructions |
378
380
  | `refresh-claude-md` | `--dry-run` `--apply` `--json` | Refresh CLAUDE.md while preserving the user-owned section |
379
381
  | `p2:check-agent-context` | `--threshold-days <n>` `--json` | Check AGENTS.md / CLAUDE.md freshness |
380
382
  | `ci:check-repetition` | `--code <errorCode>` `--reset` `--json` | Detect repetitive errors |
@@ -8,6 +8,15 @@ This file is the **Single Source of Truth** for all quality configuration in a P
8
8
 
9
9
  It is not the whole setup state. Hook JSON, Husky scripts, CI workflow files, skill links, `.phasegate/manifest.json`, runtime reports, and Codex user-level feature flags are tracked separately. Use [Setup Artifacts](setup-artifacts.md) when auditing whether a project is fully installed. <!-- @work-item-id WI-152 -->
10
10
 
11
+ For agent-assisted changes, preview the intent before editing the config:
12
+
13
+ ```bash
14
+ npx phasegate config:plan --intent l4-strict --dry-run --json
15
+ npx phasegate config:plan --intent quick-mode-strict --dry-run --json
16
+ ```
17
+
18
+ The plan identifies target fields, managed artifacts, commands, validation, risks, and rollback so an agent can explain the change before applying it. <!-- @work-item-id WI-173 -->
19
+
11
20
  ### Full Reference
12
21
 
13
22
  ```jsonc
@@ -0,0 +1,66 @@
1
+ # Getting Started
2
+
3
+ <!-- @work-item-id WI-171, WI-175 -->
4
+
5
+ Use this page when you want the shortest path from "PhaseGate is installed" to "the next command is obvious".
6
+
7
+ ## First Run
8
+
9
+ Start with one question: what kind of repository are you setting up?
10
+
11
+ | Answer | Command | Success state |
12
+ |---|---|---|
13
+ | New project with agent hooks | `npx phasegate init --name <project> --agent both --with-husky --with-ci` | `phasegate.config.json`, skills, hooks, agent context files, Husky, and CI targets exist |
14
+ | Existing repository | `npx phasegate install --dry-run` then `npx phasegate install --apply` | Existing hooks/scripts are preserved and `.phasegate/manifest.json` records managed targets |
15
+ | CI-only rollout | `npx phasegate setup:agent --intent ci-only --with-ci --dry-run --json` | The plan explains CI changes without requiring local hooks |
16
+ | Codex-only project | `npx phasegate init --agent codex --with-husky` | `.codex/hooks.json`, `AGENTS.md`, `.codex/skills`, and pre-commit backstop are present |
17
+ | Strict validation rollout | `npx phasegate setup:agent --intent strict --dry-run --json` | The plan lists strict checks, L4 risk, rollback, and validation commands |
18
+
19
+ After any setup path:
20
+
21
+ ```bash
22
+ npx phasegate doctor
23
+ npx phasegate phasegate:check-ready
24
+ npx phasegate validate --layer L2 --format human
25
+ ```
26
+
27
+ The first successful run is:
28
+
29
+ - `doctor` has no unexpected red finding for the targets you chose.
30
+ - `phasegate:check-ready` exits successfully.
31
+ - L2 validators pass or report only issues you intentionally left for a later rollout.
32
+ - The active agent can read `AGENTS.md` or `CLAUDE.md` and see the PhaseGate managed instructions.
33
+
34
+ `setup:agent --json` also returns `plan.completeness`. Treat `configured` and `planned` as local repository evidence, and treat `manual` entries as work PhaseGate cannot prove from local files, such as Codex user-level feature enablement or the first hosted CI run.
35
+
36
+ ## Daily Use
37
+
38
+ ```bash
39
+ npx phasegate work-items:status --dry-run
40
+ npx phasegate validate --layer L2 --format human
41
+ npx phasegate phasegate:status --json
42
+ ```
43
+
44
+ Use `work-items:status` before commit when a WI is close to completion. Use `phasegate:status --json` when an agent needs machine-readable hook, baseline, and validator health.
45
+
46
+ ## Agent Use
47
+
48
+ ```bash
49
+ npx phasegate setup:agent --dry-run --json
50
+ npx phasegate config:plan --intent codex-hooks --dry-run --json
51
+ ```
52
+
53
+ `setup:agent` reads repository setup state and returns missing targets, completeness, questions, risk, rollback, and validation steps. `config:plan` maps natural-language change intents such as "enable Codex hooks" or "make L4 stricter" to concrete files, commands, checks, and a read-only `phasegate.config.json` patch preview when the intent changes local config.
54
+
55
+ ## CI Use
56
+
57
+ ```bash
58
+ npx phasegate ci:generate-template --type aidlc-gate --render
59
+ npx phasegate validate --layer all --format ci
60
+ ```
61
+
62
+ For warning-as-failure rollout, preview the change first:
63
+
64
+ ```bash
65
+ npx phasegate config:plan --intent ci-fail-on-warning --dry-run --json
66
+ ```
@@ -17,7 +17,7 @@ Or add it directly to your `package.json`:
17
17
  ```json
18
18
  {
19
19
  "devDependencies": {
20
- "phasegate": "^0.152.8"
20
+ "phasegate": "^0.152.9"
21
21
  }
22
22
  }
23
23
  ```
@@ -38,7 +38,7 @@ npx phasegate init --name <project-name>
38
38
 
39
39
  This deploys 30 skills to `skills/`, creates the agent-facing skill links (for example `.claude/skills/` or `.codex/skills/`), and generates `phasegate.config.json`.
40
40
 
41
- `init` is the legacy-compatible bootstrap path for new projects. Use `install` when the project may already have hooks, package scripts, or CI files that should be preserved.
41
+ `init` is the legacy-compatible bootstrap path for new projects. It also runs the structured install path for the selected agent target so `CLAUDE.md` and/or `AGENTS.md` receive a PhaseGate managed section. Use `install` when the project may already have hooks, package scripts, or CI files that should be preserved. <!-- @work-item-id WI-174 -->
42
42
 
43
43
  For Codex, project initialization stops at the project boundary. After `npx phasegate init --agent codex`, enable the Codex CLI feature flag manually:
44
44
 
@@ -56,7 +56,16 @@ npx phasegate install --apply
56
56
  npx phasegate doctor
57
57
  ```
58
58
 
59
- `install --dry-run` reports whether each target will be created, merged, skipped, or refused. `install --apply` performs the merge, adds package scripts and the `phasegate` devDependency, creates `.claude/skills` and `.codex/skills` links, writes `.github/workflows/phasegate-aidlc-gate.yml` when CI is enabled, and records managed entries in `.phasegate/manifest.json`. See [Setup Artifacts](setup-artifacts.md) for the full managed target, generated artifact, runtime state, legacy artifact, and user-level setting inventory. <!-- @work-item-id WI-152 --> <!-- @work-item-id WI-169 -->
59
+ `install --dry-run` reports whether each target will be created, merged, skipped, or refused. `install --apply` performs the merge, adds package scripts and the `phasegate` devDependency, creates `.claude/skills` and `.codex/skills` links, writes `CLAUDE.md` / `AGENTS.md` managed sections for selected agent targets, writes `.github/workflows/phasegate-aidlc-gate.yml` when CI is enabled, and records managed entries in `.phasegate/manifest.json`. See [Setup Artifacts](setup-artifacts.md) for the full managed target, generated artifact, runtime state, legacy artifact, and user-level setting inventory. <!-- @work-item-id WI-152 --> <!-- @work-item-id WI-169 --> <!-- @work-item-id WI-174 -->
60
+
61
+ For agent-readable planning before writing files:
62
+
63
+ ```bash
64
+ npx phasegate setup:agent --intent recommended --dry-run --json
65
+ npx phasegate setup:agent --intent strict --with-ci --with-husky --dry-run --json
66
+ ```
67
+
68
+ The setup plan includes detected state, questions, planned changes, risks, rollback, and validation commands. <!-- @work-item-id WI-172 -->
60
69
 
61
70
  If a managed update must replace existing custom content, use:
62
71
 
@@ -73,7 +82,7 @@ npx phasegate uninstall --dry-run
73
82
  npx phasegate uninstall --apply
74
83
  ```
75
84
 
76
- `uninstall` reads `.phasegate/manifest.json`, deletes files that PhaseGate created, removes only PhaseGate-managed portions from merged JSON, Husky, and `package.json` files, and archives the manifest as `.phasegate/uninstalled-<timestamp>.json`. If a managed file was modified after install, `uninstall --apply` refuses that entry until you rerun with `--force`, which creates a backup under `.phasegate/backups/uninstall-<timestamp>/`.
85
+ `uninstall` reads `.phasegate/manifest.json`, deletes files that PhaseGate created, removes only PhaseGate-managed portions from merged JSON, markdown agent context files, Husky, and `package.json` files, and archives the manifest as `.phasegate/uninstalled-<timestamp>.json`. If a managed file was modified after install, `uninstall --apply` refuses that entry until you rerun with `--force`, which creates a backup under `.phasegate/backups/uninstall-<timestamp>/`. <!-- @work-item-id WI-174 -->
77
86
 
78
87
  After upgrading PhaseGate, reconcile existing managed files with the bundled templates from the new version:
79
88
 
@@ -0,0 +1,65 @@
1
+ # Recipes
2
+
3
+ <!-- @work-item-id WI-171, WI-172, WI-173 -->
4
+
5
+ ## First-Run Recipe
6
+
7
+ ```bash
8
+ npm install --save-dev phasegate
9
+ npx phasegate setup:agent --intent recommended --dry-run --json
10
+ npx phasegate install --apply
11
+ npx phasegate doctor
12
+ ```
13
+
14
+ Use this when you want an existing repository to keep user-owned hooks, scripts, and CI files. The dry-run explains the managed targets before any file is written.
15
+
16
+ ## Retrofit Recipe
17
+
18
+ ```bash
19
+ npx phasegate setup:agent --intent retrofit --dry-run --json
20
+ npx phasegate install --dry-run
21
+ npx phasegate install --apply
22
+ npx phasegate baseline --dry-run
23
+ ```
24
+
25
+ Use this when a repository already has meaningful history or custom automation. Treat any refused target as an agent-assisted review task instead of forcing it blindly.
26
+
27
+ ## Agent Hooks Recipe
28
+
29
+ ```bash
30
+ npx phasegate setup:agent --intent agent-hooks --agent both --with-husky --dry-run --json
31
+ npx phasegate install --agent both --apply
32
+ codex features enable codex_hooks
33
+ npx phasegate doctor --json
34
+ ```
35
+
36
+ The repository-managed portion covers `.claude/settings.json`, `.codex/hooks.json`, `CLAUDE.md`, `AGENTS.md`, skills links, and the Husky backstop. The Codex user-level feature flag remains a local manual setting.
37
+
38
+ ## CI Recipe
39
+
40
+ ```bash
41
+ npx phasegate setup:agent --intent ci-only --with-ci --dry-run --json
42
+ npx phasegate install --apply
43
+ npx phasegate ci:generate-template --type aidlc-gate --render
44
+ ```
45
+
46
+ Use this when local hooks are not part of the rollout. The plan still includes validation and rollback steps so the agent can explain what changed.
47
+
48
+ ## Strict L4 Recipe
49
+
50
+ ```bash
51
+ npx phasegate config:plan --intent l4-strict --dry-run --json
52
+ npx phasegate validate --layer L4 --fail-on-warning --format human
53
+ ```
54
+
55
+ Only enable fail-on-warning after reviewing the drift, consistency, dead-code, pointer, and freshness findings. The plan output identifies the config fields and validations the agent should cite in its change summary.
56
+
57
+ ## Configuration Change Recipe
58
+
59
+ ```bash
60
+ npx phasegate config:plan --intent quick-mode-strict --dry-run --json
61
+ npx phasegate check-change-category --paths <changed-files> --format json
62
+ npx phasegate ci-check --quick --dry-run
63
+ ```
64
+
65
+ Use `config:plan` before changing `phasegate.config.json`. It separates repo-managed artifacts from user-level settings, previews the local config before/after for config-backed intents, and lists the checks needed after the change. <!-- @work-item-id WI-175 -->
@@ -10,7 +10,7 @@ PhaseGate setup is more than `phasegate.config.json`. A healthy installation is
10
10
 
11
11
  | Class | Examples | Owner | Lifecycle |
12
12
  |---|---|---|---|
13
- | Managed target | `.claude/settings.json`, `.codex/hooks.json`, `.husky/pre-commit`, `.husky/commit-msg`, `.husky/pre-push`, `.github/workflows/phasegate-aidlc-gate.yml`, `.claude/skills`, `.codex/skills`, `package.json` PhaseGate scripts/devDependency | PhaseGate managed block or symlink plus user content | Created or merged by `install`, refreshed by `reconcile`, removed or reversed by `uninstall` |
13
+ | Managed target | `.claude/settings.json`, `.codex/hooks.json`, `CLAUDE.md`, `AGENTS.md`, `.husky/pre-commit`, `.husky/commit-msg`, `.husky/pre-push`, `.github/workflows/phasegate-aidlc-gate.yml`, `.claude/skills`, `.codex/skills`, `package.json` PhaseGate scripts/devDependency | PhaseGate managed block or symlink plus user content | Created or merged by `install`, refreshed by `reconcile`, removed or reversed by `uninstall` |
14
14
  | Configuration | `phasegate.config.json`, `package.json` | User owned, PhaseGate assisted | Created by `init`; `install` may merge scripts/devDependency into `package.json` |
15
15
  | Generated artifact | `.phasegate/manifest.json`, `.phasegate/backups/*`, `.phasegate/uninstalled-*.json`, `.phasegate/baseline.json` | PhaseGate | Written by lifecycle commands and validators; safe to regenerate only through the owning command |
16
16
  | Runtime state/report | `.phasegate/hook-skip-events.jsonl`, explicit `doctor --report-out <path>` output, `reports/regression/*`, resolved `reporting.outputDir` reports | PhaseGate command output | Produced while hooks, doctor, and validation commands run |
@@ -22,12 +22,15 @@ PhaseGate setup is more than `phasegate.config.json`. A healthy installation is
22
22
  `install --apply` and `reconcile --apply` manage only explicit targets. The current structured lifecycle covers:
23
23
 
24
24
  - Agent hook JSON: `.claude/settings.json`, `.codex/hooks.json`
25
+ - Agent context files: `CLAUDE.md` and `AGENTS.md` managed sections. `AGENT.md` singular is not a PhaseGate managed target; treat it as user-owned content or migrate it manually. <!-- @work-item-id WI-174 -->
25
26
  - Husky scripts when requested: `.husky/pre-commit`, `.husky/commit-msg`, `.husky/pre-push`
26
27
  - CI workflow when requested: `.github/workflows/phasegate-aidlc-gate.yml`
27
28
  - Agent skill links: `.claude/skills`, `.codex/skills`
28
29
  - Package metadata: PhaseGate scripts and `devDependencies.phasegate` in `package.json`
29
30
  - Manifest: `.phasegate/manifest.json`
30
31
 
32
+ `AGENTS.md` has two PhaseGate sections with separate ownership. `<!-- phasegate:managed-section:start -->` contains standard setup/WI workflow instructions. `<!-- phasegate:lesson-pointers:start -->` is reserved for `ci:auto-refresh-agent-context` lesson pointers. Refreshing lesson pointers must not replace the standard managed section or user-owned content. <!-- @work-item-id WI-174 -->
33
+
31
34
  `init --with-ci` still deploys the legacy-compatible template set, including `.github/workflows/aidlc-gate.yml`, `.github/workflows/consistency-check.yml`, and `.github/workflows/agent-context-refresh.yml`. Structured `install` uses `.github/workflows/phasegate-aidlc-gate.yml` so it can coexist with existing project CI without taking over a generic workflow filename.
32
35
 
33
36
  ## Doctor Findings
@@ -0,0 +1,73 @@
1
+ # Troubleshooting
2
+
3
+ <!-- @work-item-id WI-171, WI-172, WI-173, WI-175 -->
4
+
5
+ Start with:
6
+
7
+ ```bash
8
+ npx phasegate doctor --json
9
+ ```
10
+
11
+ Each finding has a severity, a repair mode, and optional next-step fields.
12
+
13
+ | Field | Meaning |
14
+ |---|---|
15
+ | `severity` | `red` blocks the expected setup state; `warn` needs review but may be acceptable for partial rollout |
16
+ | `repairMode` | `mechanical` can be handled by PhaseGate commands; `ai-assisted` needs an agent to preserve user intent; `manual` needs human review |
17
+ | `repairHint` | Copyable command for mechanical repair |
18
+ | `suggestedSkill` | Agent skill to invoke when a merge or setup choice needs reasoning |
19
+
20
+ ## Common Findings
21
+
22
+ | Finding | First action |
23
+ |---|---|
24
+ | `claude-hook-missing` | `npx phasegate install --agent claude --dry-run` |
25
+ | `codex-hook-missing` | `npx phasegate install --agent codex --dry-run` |
26
+ | `husky-pre-commit-missing` | `npx phasegate setup:agent --intent agent-hooks --with-husky --dry-run --json` |
27
+ | `ci-workflow-missing` | `npx phasegate setup:agent --intent ci-only --with-ci --dry-run --json` |
28
+ | agent context drift | `npx phasegate reconcile --dry-run` |
29
+
30
+ ## Refused Managed Target
31
+
32
+ If `install`, `reconcile`, or `uninstall` refuses a target, do not immediately force it. Inspect the diff and ask the agent to explain:
33
+
34
+ - which file is repo-managed and which part is user-owned;
35
+ - why the target cannot be merged mechanically;
36
+ - what backup and rollback path will exist if `--force` is used;
37
+ - which validation commands will be run afterward.
38
+
39
+ ## Codex Hooks Do Not Fire
40
+
41
+ Check both project and user-level state:
42
+
43
+ ```bash
44
+ npx phasegate doctor --json
45
+ codex features enable codex_hooks
46
+ npx phasegate phasegate:status --json
47
+ ```
48
+
49
+ Native Codex `apply_patch` writes are validated by the pre-commit backstop. Bash-based writes can be blocked before execution when hooks are enabled.
50
+
51
+ ## Agent Setup Is Ambiguous
52
+
53
+ Use the planner instead of guessing:
54
+
55
+ ```bash
56
+ npx phasegate setup:agent --intent retrofit --dry-run --json
57
+ npx phasegate config:plan --intent codex-hooks --dry-run --json
58
+ ```
59
+
60
+ The planner output is intentionally agent-readable: detected state, questions, planned targets, risks, rollback, and validation commands are all explicit.
61
+
62
+ ## Setup Completeness Still Has Manual Checks
63
+
64
+ `doctor` green means the local managed setup is consistent for the inspected targets. It does not prove user-level Codex feature flags, hosted GitHub Actions execution, npm registry state, or team policy acceptance.
65
+
66
+ Check `plan.completeness` in `setup:agent --json`:
67
+
68
+ - `configured`: PhaseGate found local evidence.
69
+ - `planned`: `--apply` will create or refresh the local target.
70
+ - `manual`: complete the listed external action yourself.
71
+ - `not-applicable`: the current intent/options did not select that area.
72
+
73
+ When `install` or `setup:agent --apply` returns a structured `error`, use its `target`, `operation`, `code`, `recovery`, and `partialChanges` fields before rerunning.
@@ -0,0 +1,45 @@
1
+ # AGENTS.md
2
+
3
+ <!-- @work-item-id WI-174 -->
4
+
5
+ <!-- phasegate:managed-section:start -->
6
+ ## PhaseGate Managed Instructions
7
+
8
+ ### Required Documents
9
+
10
+ - `docs/folder_management_rules.md`
11
+ - `docs/principles/architecture-philosophy.md`
12
+ - `docs/principles/testing-rules.md`
13
+
14
+ ### Workflow
15
+
16
+ - Create or update the relevant `docs/inception/**/WI-XXX/` work item before planning, design, implementation, or tests.
17
+ - Reflect accepted design into `docs/product/...` with `@work-item-id WI-XXX` before changing source files.
18
+ - Run the relevant PhaseGate checks after changing docs, source, hooks, skills, or setup artifacts.
19
+ - Do not bypass git hooks unless the user explicitly approves the reason, residual risk, and replacement validation.
20
+
21
+ ### Setup State
22
+
23
+ - Agent target: `{{PHASEGATE_AGENT}}`
24
+ - Skill set: `{{PHASEGATE_SKILLS_MODE}}`
25
+ - Workflow mode: `{{PHASEGATE_WORKFLOW}}`
26
+ - Husky hooks: `{{PHASEGATE_HUSKY_STATE}}`
27
+ - CI workflow: `{{PHASEGATE_CI_STATE}}`
28
+
29
+ ### Common Commands
30
+
31
+ {{PHASEGATE_COMMANDS}}
32
+
33
+ ### Codex Notes
34
+
35
+ - Enable native hook execution with `codex features enable codex_hooks` when Codex hooks are installed.
36
+ - Keep local-only Codex settings outside repository-managed targets unless PhaseGate explicitly reports them as managed.
37
+ <!-- phasegate:managed-section:end -->
38
+
39
+ <!-- phasegate:lesson-pointers:start -->
40
+ <!-- lesson pointers are managed by phasegate ci:auto-refresh-agent-context -->
41
+ <!-- phasegate:lesson-pointers:end -->
42
+
43
+ <!-- phasegate:user-section:start -->
44
+ Project-specific agent instructions go here.
45
+ <!-- phasegate:user-section:end -->
@@ -1,5 +1,8 @@
1
1
  # CLAUDE.md
2
2
 
3
+ <!-- @work-item-id WI-174 -->
4
+
5
+ <!-- phasegate:managed-section:start -->
3
6
  ## 必読ドキュメント
4
7
 
5
8
  - `docs/folder_management_rules.md`
@@ -27,3 +30,4 @@
27
30
  ## Agent Context Refresh
28
31
 
29
32
  Run `phasegate ci:auto-refresh-agent-context --dry-run` to preview updates and `phasegate ci:auto-refresh-agent-context --apply` to write AGENTS.md / CLAUDE.md.
33
+ <!-- phasegate:managed-section:end -->
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phasegate",
3
- "version": "0.152.8",
3
+ "version": "0.153.0",
4
4
  "packageManager": "pnpm@10.30.1",
5
5
  "description": "Phasegate — AI-agnostic quality defense toolkit. Enforces structural integrity between design intent and code.",
6
6
  "license": "MIT",
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @layer infrastructure
3
3
  * @unit ci-governance
4
+ * @work-item-id WI-174
4
5
  *
5
6
  * AgentsMdPort実装(AGENTS.mdファイルI/O)
6
7
  */
@@ -13,6 +14,7 @@ import { PointerEntry } from '../../domain/value-objects/pointer-entry.js';
13
14
 
14
15
  export class AgentsMdFileAdapter implements AgentsMdPort {
15
16
  private readonly filePath: string;
17
+ private lastReadContent: string | null = null;
16
18
 
17
19
  constructor(baseDir: string) {
18
20
  this.filePath = path.join(baseDir, 'AGENTS.md');
@@ -21,8 +23,10 @@ export class AgentsMdFileAdapter implements AgentsMdPort {
21
23
  async read(): Promise<AgentsMdPointer> {
22
24
  try {
23
25
  const content = await fs.readFile(this.filePath, 'utf-8');
26
+ this.lastReadContent = content;
24
27
  return this.parseAgentsMd(content);
25
28
  } catch {
29
+ this.lastReadContent = null;
26
30
  return AgentsMdPointer.create();
27
31
  }
28
32
  }
@@ -36,7 +40,7 @@ export class AgentsMdFileAdapter implements AgentsMdPort {
36
40
  before = 0;
37
41
  }
38
42
 
39
- const content = this.serializeAgentsMd(pointer);
43
+ const content = this.serializeAgentsMd(pointer, this.lastReadContent ?? null);
40
44
  await fs.writeFile(this.filePath, content, 'utf-8');
41
45
  const after = content.split('\n').length;
42
46
 
@@ -81,11 +85,28 @@ export class AgentsMdFileAdapter implements AgentsMdPort {
81
85
  return AgentsMdPointer.create(pointers, adrLinks);
82
86
  }
83
87
 
84
- private serializeAgentsMd(pointer: AgentsMdPointer): string {
85
- const lines: string[] = ['# AGENTS.md', ''];
88
+ private serializeAgentsMd(pointer: AgentsMdPointer, existing: string | null): string {
89
+ const section = this.serializeLessonPointerSection(pointer);
90
+ if (existing !== null && existing.trim().length > 0) {
91
+ const start = '<!-- phasegate:lesson-pointers:start -->';
92
+ const end = '<!-- phasegate:lesson-pointers:end -->';
93
+ const pattern = new RegExp(`${this.escapeRegExp(start)}[\\s\\S]*?${this.escapeRegExp(end)}`);
94
+ if (pattern.test(existing)) {
95
+ return existing.replace(pattern, section.trim()).replace(/\s*$/, '\n');
96
+ }
97
+ return `${existing.replace(/\s*$/, '\n\n')}${section}`;
98
+ }
99
+ return ['# AGENTS.md', '', section].join('\n');
100
+ }
101
+
102
+ private serializeLessonPointerSection(pointer: AgentsMdPointer): string {
103
+ const lines: string[] = [
104
+ '<!-- phasegate:lesson-pointers:start -->',
105
+ '## PhaseGate Lesson Pointers',
106
+ '',
107
+ ];
86
108
 
87
109
  if (pointer.pointers.length > 0) {
88
- lines.push('## Pointers', '');
89
110
  for (const entry of pointer.pointers) {
90
111
  if (entry.isCommand()) {
91
112
  lines.push(`- [cmd:${entry.key}](${entry.command ?? ''}) ${entry.description}`);
@@ -97,13 +118,18 @@ export class AgentsMdFileAdapter implements AgentsMdPort {
97
118
  }
98
119
 
99
120
  if (pointer.adrLinks.length > 0) {
100
- lines.push('## ADR Links', '');
121
+ lines.push('### ADR Links', '');
101
122
  for (const adr of pointer.adrLinks) {
102
123
  lines.push(`- ADR: ${adr}`);
103
124
  }
104
125
  lines.push('');
105
126
  }
106
127
 
128
+ lines.push('<!-- phasegate:lesson-pointers:end -->', '');
107
129
  return lines.join('\n');
108
130
  }
131
+
132
+ private escapeRegExp(value: string): string {
133
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
134
+ }
109
135
  }