phasegate 0.153.1 → 0.155.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,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.154.0] - 2026-05-13
11
+
12
+ ### Added
13
+
14
+ - **WI-176 — Claude Code dogfood readiness** — adds `setup:agent` agent-specific readiness output for Claude, Codex, and shared setup state, plus Claude Code managed context and guide updates for recovery and validation.
15
+
10
16
  ## [0.153.1] - 2026-05-13
11
17
 
12
18
  ### Fixed
package/README.md CHANGED
@@ -109,7 +109,7 @@ npx phasegate setup:agent --intent recommended --dry-run --json
109
109
  npx phasegate config:plan --intent codex-hooks --dry-run --json
110
110
  ```
111
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 -->
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. It also includes `plan.agentReadiness` so Claude Code, Codex, and shared setup state can be evaluated separately. `config:plan` includes a read-only `configPatch` preview when an intent would change `phasegate.config.json`. <!-- @work-item-id WI-175, WI-176 -->
113
113
 
114
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 -->
115
115
 
@@ -1,6 +1,6 @@
1
1
  # Getting Started
2
2
 
3
- <!-- @work-item-id WI-171, WI-175 -->
3
+ <!-- @work-item-id WI-171, WI-175, WI-176 -->
4
4
 
5
5
  Use this page when you want the shortest path from "PhaseGate is installed" to "the next command is obvious".
6
6
 
@@ -31,7 +31,7 @@ The first successful run is:
31
31
  - L2 validators pass or report only issues you intentionally left for a later rollout.
32
32
  - The active agent can read `AGENTS.md` or `CLAUDE.md` and see the PhaseGate managed instructions.
33
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.
34
+ `setup:agent --json` also returns `plan.completeness` and `plan.agentReadiness`. 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. For Claude Code setup, check the `agent=claude` row before assuming `.claude/settings.json`, `CLAUDE.md`, and shared skills are ready.
35
35
 
36
36
  ## Daily Use
37
37
 
@@ -50,7 +50,7 @@ npx phasegate setup:agent --dry-run --json
50
50
  npx phasegate config:plan --intent codex-hooks --dry-run --json
51
51
  ```
52
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.
53
+ `setup:agent` reads repository setup state and returns missing targets, completeness, agent readiness, 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
54
 
55
55
  ## CI Use
56
56
 
@@ -1,6 +1,6 @@
1
1
  # Troubleshooting
2
2
 
3
- <!-- @work-item-id WI-171, WI-172, WI-173, WI-175 -->
3
+ <!-- @work-item-id WI-171, WI-172, WI-173, WI-175, WI-176, WI-177 -->
4
4
 
5
5
  Start with:
6
6
 
@@ -71,3 +71,27 @@ Check `plan.completeness` in `setup:agent --json`:
71
71
  - `not-applicable`: the current intent/options did not select that area.
72
72
 
73
73
  When `install` or `setup:agent --apply` returns a structured `error`, use its `target`, `operation`, `code`, `recovery`, and `partialChanges` fields before rerunning.
74
+
75
+ Common structured setup errors:
76
+
77
+ | Code | Usually means | First recovery step |
78
+ |---|---|---|
79
+ | `EPERM` / `EACCES` | The current sandbox, user, or filesystem denied the write. | Ask the user to rerun in a writable workspace or approve the write, then retry the same `--apply` command. |
80
+ | `EEXIST` / `ENOTDIR` | A parent path such as `.claude` or `.codex` exists as a file or incompatible path. | Inspect the path, decide whether it is user-owned, then move or rename it before rerunning. |
81
+ | hash mismatch / refused target | A PhaseGate managed target contains user edits outside the expected hash. | Use `invoke /phasegate-config-doctor` and explain backup, merge, and `--force` tradeoffs before applying. |
82
+
83
+ ## Claude Code Setup Still Feels Unclear
84
+
85
+ Run the Claude-specific planner path:
86
+
87
+ ```bash
88
+ npx phasegate setup:agent --agent claude --intent strict --with-husky --dry-run --json
89
+ ```
90
+
91
+ Check `plan.agentReadiness`:
92
+
93
+ - `agent=claude`: local Claude Code targets (`.claude/settings.json`, `CLAUDE.md`, skills).
94
+ - `agent=shared`: package/config/skills plus selected Husky and CI targets.
95
+ - `agent=codex`: should be `not-applicable` unless you selected `--agent both` or `--agent codex`.
96
+
97
+ When `claude` and `shared` are `configured`, the next step is work planning, not more setup. Confirm or create the WI under `docs/inception/**/{WI-XXX}/description.md`, write the needed inception plan/design files, reflect accepted design into `docs/product/...` with `@work-item-id WI-XXX`, then run `npx phasegate phasegate:check-ready` or the relevant `validate --layer ...` command.
@@ -1,6 +1,6 @@
1
1
  # CLAUDE.md
2
2
 
3
- <!-- @work-item-id WI-174 -->
3
+ <!-- @work-item-id WI-174, WI-176, WI-177 -->
4
4
 
5
5
  <!-- phasegate:managed-section:start -->
6
6
  ## 必読ドキュメント
@@ -13,6 +13,23 @@
13
13
 
14
14
  {{PHASEGATE_COMMANDS}}
15
15
 
16
+ ## Setup Readiness
17
+
18
+ Before planning implementation work in a new or upgraded repository, run `phasegate setup:agent --agent claude --dry-run --json` and inspect `plan.agentReadiness`.
19
+
20
+ - `agent=claude` covers `.claude/settings.json`, `CLAUDE.md`, and shared skills.
21
+ - `agent=shared` covers package scripts, `phasegate.config.json`, skills, and selected Husky/CI targets.
22
+ - `manual` or `external-actions` entries require user or hosted-service confirmation; do not treat local readiness as proof that external CI or user-level agent settings are complete.
23
+
24
+ After the `claude` and `shared` rows are `configured`, move from setup to work planning:
25
+
26
+ 1. Confirm the target WI under `docs/inception/**/{WI-XXX}/description.md`, or create the next unused WI if the user asks for new work.
27
+ 2. For implementation work, prepare or update the WI plan/design files under `docs/inception/.../{WI-XXX}/` before editing source or tests.
28
+ 3. Reflect the accepted design into the relevant `docs/product/...` files with `@work-item-id WI-XXX`.
29
+ 4. Run `phasegate phasegate:check-ready` or the requested `phasegate validate --layer ...` command before committing.
30
+
31
+ If `setup:agent --apply --json` or `install --apply --json` fails with a structured `error`, explain `target`, `operation`, `code`, `likelyCause`, `recovery`, and `partialChanges` before retrying. Use `invoke /phasegate-config-doctor` for managed target conflicts and `invoke /phasegate-toolkit-guide` for read-only setup guidance.
32
+
16
33
  ## Phase Presets
17
34
 
18
35
  {{PHASEGATE_PRESETS}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phasegate",
3
- "version": "0.153.1",
3
+ "version": "0.155.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",
@@ -3,6 +3,7 @@
3
3
  // @work-item-id WI-146
4
4
  // @work-item-id WI-174
5
5
  // @work-item-id WI-175
6
+ // @work-item-id WI-177
6
7
 
7
8
  import { mkdir, readFile, writeFile, copyFile, chmod, access, lstat, readlink, symlink } from "node:fs/promises";
8
9
  import { dirname, join } from "node:path";
@@ -236,14 +237,16 @@ function likelyCauseFor(code: string): string {
236
237
  if (code === "EPERM") return "The filesystem or sandbox denied this write operation.";
237
238
  if (code === "EACCES") return "The current user does not have permission to write this target.";
238
239
  if (code === "EROFS") return "The project is on a read-only filesystem.";
240
+ if (code === "EEXIST") return "A parent path already exists as a file or incompatible filesystem entry.";
239
241
  if (code === "ENOTDIR") return "A parent path exists but is not a directory.";
240
242
  return "The managed target could not be written.";
241
243
  }
242
244
 
243
245
  function recoveryFor(code: string, target: string): string {
244
- if (code === "EPERM") return `Review sandbox or filesystem permissions for ${target}, then rerun phasegate setup:agent --apply or phasegate install --apply.`;
246
+ if (code === "EPERM") return `Review sandbox or filesystem permissions for ${target}, ask the user for write access when needed, then rerun phasegate setup:agent --apply or phasegate install --apply.`;
245
247
  if (code === "EACCES") return `Fix ownership or permissions for ${target}, then rerun phasegate install --apply.`;
246
248
  if (code === "EROFS") return `Move the project to a writable filesystem or rerun in a writable workspace before applying ${target}.`;
249
+ if (code === "EEXIST" || code === "ENOTDIR") return `Inspect the parent path for ${target}; if it is user-owned, rename or move it before rerunning phasegate install --dry-run --json and then --apply.`;
247
250
  return `Inspect ${target}, run phasegate install --dry-run --json, then rerun with --apply after resolving the filesystem issue.`;
248
251
  }
249
252
 
@@ -5,6 +5,7 @@
5
5
  * @work-item-id WI-113 / WI-142
6
6
  * @work-item-id WI-171 / WI-172 / WI-173
7
7
  * @work-item-id WI-175
8
+ * @work-item-id WI-176
8
9
  *
9
10
  * Phasegate CLI エントリポイント。
10
11
  * 各Unitの Composition Root からハンドラーを取得し、コマンドに応じてディスパッチする。
@@ -734,6 +735,14 @@ interface SetupCompletenessEntry {
734
735
  readonly risk: string | null;
735
736
  }
736
737
 
738
+ interface AgentReadinessEntry {
739
+ readonly agent: "claude" | "codex" | "shared";
740
+ readonly status: SetupCompletenessStatus;
741
+ readonly evidence: readonly string[];
742
+ readonly nextAction: string | null;
743
+ readonly risk: string | null;
744
+ }
745
+
737
746
  interface ConfigPatchOperation {
738
747
  readonly op: "add" | "replace";
739
748
  readonly pointer: string;
@@ -931,6 +940,117 @@ function buildSetupCompleteness(input: {
931
940
  return entries;
932
941
  }
933
942
 
943
+ function setupReadinessEntry(input: {
944
+ readonly agent: AgentReadinessEntry["agent"];
945
+ readonly included: boolean;
946
+ readonly configured: boolean;
947
+ readonly configuredEvidence: readonly string[];
948
+ readonly plannedEvidence: readonly string[];
949
+ readonly nextAction: string;
950
+ readonly risk?: string;
951
+ }): AgentReadinessEntry {
952
+ if (!input.included) {
953
+ return {
954
+ agent: input.agent,
955
+ status: "not-applicable",
956
+ evidence: ["Not selected for this setup run."],
957
+ nextAction: null,
958
+ risk: null,
959
+ };
960
+ }
961
+ if (input.configured) {
962
+ return {
963
+ agent: input.agent,
964
+ status: "configured",
965
+ evidence: input.configuredEvidence,
966
+ nextAction: null,
967
+ risk: input.risk ?? null,
968
+ };
969
+ }
970
+ return {
971
+ agent: input.agent,
972
+ status: "planned",
973
+ evidence: input.plannedEvidence,
974
+ nextAction: input.nextAction,
975
+ risk: input.risk ?? null,
976
+ };
977
+ }
978
+
979
+ function buildAgentReadiness(input: {
980
+ readonly agent: AgentTarget;
981
+ readonly withHusky: boolean;
982
+ readonly withCi: boolean;
983
+ readonly checks: {
984
+ readonly packageJson: boolean;
985
+ readonly phasegateConfig: boolean;
986
+ readonly claudeSettings: boolean;
987
+ readonly codexHooks: boolean;
988
+ readonly agentsMd: boolean;
989
+ readonly claudeMd: boolean;
990
+ readonly huskyPreCommit: boolean;
991
+ readonly ciWorkflow: boolean;
992
+ readonly skillsVersion: boolean;
993
+ };
994
+ }): readonly AgentReadinessEntry[] {
995
+ const includeClaude = input.agent === "claude" || input.agent === "both";
996
+ const includeCodex = input.agent === "codex" || input.agent === "both";
997
+ const sharedConfigured =
998
+ input.checks.packageJson &&
999
+ input.checks.phasegateConfig &&
1000
+ input.checks.skillsVersion &&
1001
+ (!input.withHusky || input.checks.huskyPreCommit) &&
1002
+ (!input.withCi || input.checks.ciWorkflow);
1003
+
1004
+ return [
1005
+ setupReadinessEntry({
1006
+ agent: "claude",
1007
+ included: includeClaude,
1008
+ configured: input.checks.claudeSettings && input.checks.claudeMd && input.checks.skillsVersion,
1009
+ configuredEvidence: [
1010
+ ".claude/settings.json is present.",
1011
+ "CLAUDE.md is present.",
1012
+ "skills/.harness-version is present for the .claude/skills link target.",
1013
+ ],
1014
+ plannedEvidence: [
1015
+ "setup:agent will create or refresh .claude/settings.json.",
1016
+ "setup:agent will create or refresh the CLAUDE.md PhaseGate managed section.",
1017
+ "setup:agent will deploy bundled skills for Claude Code.",
1018
+ ],
1019
+ nextAction: "Run setup:agent --agent claude --apply, then ask Claude Code to read CLAUDE.md before planning work.",
1020
+ }),
1021
+ setupReadinessEntry({
1022
+ agent: "codex",
1023
+ included: includeCodex,
1024
+ configured: input.checks.codexHooks && input.checks.agentsMd && input.checks.skillsVersion,
1025
+ configuredEvidence: [
1026
+ ".codex/hooks.json is present.",
1027
+ "AGENTS.md is present.",
1028
+ "skills/.harness-version is present for the .codex/skills link target.",
1029
+ ],
1030
+ plannedEvidence: [
1031
+ "setup:agent will create or refresh .codex/hooks.json.",
1032
+ "setup:agent will create or refresh the AGENTS.md PhaseGate managed section.",
1033
+ "setup:agent will deploy bundled skills for Codex.",
1034
+ ],
1035
+ nextAction: "Run setup:agent --agent codex --apply, then enable codex_hooks at user level if needed.",
1036
+ risk: "Codex user-level hook feature enablement remains a manual external check.",
1037
+ }),
1038
+ setupReadinessEntry({
1039
+ agent: "shared",
1040
+ included: true,
1041
+ configured: sharedConfigured,
1042
+ configuredEvidence: [
1043
+ "package.json, phasegate.config.json, skills, and selected Husky/CI targets are present.",
1044
+ ],
1045
+ plannedEvidence: [
1046
+ "setup:agent will create or refresh package scripts, phasegate.config.json, skills, and selected Husky/CI targets.",
1047
+ ],
1048
+ nextAction: "Run setup:agent --apply, then phasegate doctor, phasegate phasegate:check-ready, and phasegate validate --layer L2 --format human.",
1049
+ risk: input.withCi ? "A hosted CI run remains an external manual check." : undefined,
1050
+ }),
1051
+ ];
1052
+ }
1053
+
934
1054
  async function buildAgentSetupPlan(rootDir: string, input: {
935
1055
  readonly intent: SetupIntent;
936
1056
  readonly agent: AgentTarget;
@@ -970,6 +1090,7 @@ async function buildAgentSetupPlan(rootDir: string, input: {
970
1090
  agent: input.agent,
971
1091
  detected: checks,
972
1092
  completeness: buildSetupCompleteness({ ...input, checks }),
1093
+ agentReadiness: buildAgentReadiness({ ...input, checks }),
973
1094
  questions,
974
1095
  changes,
975
1096
  risks: [
@@ -133,6 +133,7 @@ product-architect で Unit を作り、いくつかの logical_design を書い
133
133
  - Codex の `codex_hooks` feature flag は user-level setting。project-local `install` では変更されないため、必要なら `codex features enable codex_hooks` を案内
134
134
  - Codex native `apply_patch` bypass は hook で完全捕捉できない。`.husky/pre-commit` の `phasegate pre-commit` が backstop になるため、Husky 配線を診断対象に含める
135
135
  - 初回 setup / retrofit / CI-only / agent-hooks の判断が曖昧な場合は `npx phasegate setup:agent --dry-run --json` を先に使い、検出済み状態、質問、変更案、rollback、validation を根拠として提案する。<!-- @work-item-id WI-172 -->
136
+ - Claude Code setup 相談では `npx phasegate setup:agent --agent claude --dry-run --json` を先に使い、`plan.agentReadiness` の `claude` / `shared` が `configured` なら setup 修復ではなく WI 起票、inception 計画、product reflection、validation の順で作業開始を案内する。`setup:agent --apply --json` または `install --apply --json` の structured `error` がある場合は、`target`, `operation`, `code`, `likelyCause`, `recovery`, `partialChanges` を読み、`.claude` が file として存在する path conflict、sandbox/permission denial、PhaseGate managed target hash mismatch を区別して説明する。<!-- @work-item-id WI-177 -->
136
137
  - 「L4 を厳しめにして」「Codex hook を有効にして」「CI で warning を fail にして」などの自然言語依頼は、`npx phasegate config:plan --intent <intent> --dry-run --json` で対象ファイル、コマンド、リスク、検証を確認してから diff を提案する。<!-- @work-item-id WI-173 -->
137
138
  - `AGENTS.md` は標準運用ルールの managed section と lesson pointer section を分ける。`ci:auto-refresh-agent-context --apply` は lesson pointers 専用 section を更新し、標準運用ルールや user-owned content を置換してはいけない。<!-- @work-item-id WI-174 -->
138
139
 
@@ -134,6 +134,8 @@ docs/guide/ # phasegate リポジトリ自体 (dogfood)
134
134
 
135
135
  `setup:agent` は初回 setup / retrofit / CI-only / agent hook 有効化の agent-readable planner、`config:plan` は安全な設定変更 intent planner。質問が「次に何を実行するか」「この変更はどの file/validation に対応するか」に寄っている場合は、これらの guide と CLI を案内する。<!-- @work-item-id WI-171, WI-172, WI-173 -->
136
136
 
137
+ Claude Code readiness の質問では `npx phasegate setup:agent --agent claude --dry-run --json` を案内し、`plan.agentReadiness` の `claude` / `shared` が `configured` なら setup ではなく作業導線へ進める。最短ルートは、WI の確認または起票、`docs/inception/.../{WI-XXX}/` への計画/設計、`docs/product/...` への `@work-item-id WI-XXX` 反映、`phasegate phasegate:check-ready` または該当 `validate` の実行である。`setup:agent --apply --json` の structured `error` は troubleshooting に委譲し、`target` / `operation` / `code` / `recovery` を読ませる。<!-- @work-item-id WI-177 -->
138
+
137
139
  ### 8. skill 一覧と使い分け
138
140
 
139
141
  ユーザー質問例: