@andares/pi-toolkits 0.14.0 → 1.0.1

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.
Files changed (59) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +101 -34
  3. package/README.zh-CN.md +68 -32
  4. package/package.json +10 -3
  5. package/src/features/ask/index.test.ts +15 -0
  6. package/src/features/ask/index.ts +18 -1
  7. package/src/features/init/audit.test.ts +19 -2
  8. package/src/features/init/audit.ts +117 -15
  9. package/src/features/init/index.test.ts +123 -1
  10. package/src/features/init/index.ts +156 -46
  11. package/src/features/init/parity.test.ts +176 -0
  12. package/src/features/init/parity.ts +229 -0
  13. package/src/features/init/plan.ts +25 -3
  14. package/src/features/init/refresh.test.ts +88 -1
  15. package/src/features/init/refresh.ts +43 -64
  16. package/src/features/init/spec.ts +11 -0
  17. package/src/features/init/templates/memory-readme.md +9 -2
  18. package/src/features/init/templates/workflow-block.md +2 -2
  19. package/src/features/init/test-helpers.ts +1 -0
  20. package/src/features/init/workflow.ts +159 -0
  21. package/src/features/permission/index.ts +1 -1
  22. package/src/features/quit-guard/constants.ts +18 -5
  23. package/src/features/quit-guard/index.ts +75 -29
  24. package/src/features/quit-guard/killer.test.ts +77 -0
  25. package/src/features/quit-guard/killer.ts +215 -0
  26. package/src/features/review/index.ts +14 -0
  27. package/src/features/review/review.test.ts +34 -2
  28. package/src/features/spec/assets/index-CdTerMvN.css +1 -0
  29. package/src/features/spec/assets/index-Dv52AIjX.js +1 -0
  30. package/src/features/{plan → spec}/assets/index.html +3 -3
  31. package/src/features/{plan → spec}/assets.test.ts +5 -5
  32. package/src/features/{plan → spec}/blocks.ts +1 -1
  33. package/src/features/{plan → spec}/feedback.test.ts +26 -26
  34. package/src/features/{plan → spec}/feedback.ts +14 -14
  35. package/src/features/{plan → spec}/index.test.ts +148 -63
  36. package/src/features/{plan → spec}/index.ts +136 -105
  37. package/src/features/{plan → spec}/prompt.test.ts +20 -20
  38. package/src/features/{plan → spec}/prompt.ts +25 -25
  39. package/src/features/{plan → spec}/render.test.ts +2 -2
  40. package/src/features/{plan → spec}/server.test.ts +21 -21
  41. package/src/features/{plan → spec}/server.ts +22 -22
  42. package/src/features/{plan → spec}/store.test.ts +77 -35
  43. package/src/features/{plan → spec}/store.ts +80 -52
  44. package/src/features/uat/index.test.ts +20 -5
  45. package/src/features/uat/index.ts +16 -13
  46. package/src/features/uat/record-tool.ts +6 -5
  47. package/src/features/uat/records.test.ts +5 -5
  48. package/src/features/uat/state.ts +13 -5
  49. package/src/index.ts +6 -6
  50. package/src/lib/ask-control.ts +2 -2
  51. package/src/lib/permission-control.ts +4 -4
  52. package/src/lib/phases.ts +50 -0
  53. package/src/lib/web-review.ts +1 -1
  54. package/src/features/plan/assets/index-C1YLIi4I.js +0 -1
  55. package/src/features/plan/assets/index-DMEpYC3V.css +0 -1
  56. /package/src/features/{plan → spec}/blocks.test.ts +0 -0
  57. /package/src/features/{plan → spec}/diff.test.ts +0 -0
  58. /package/src/features/{plan → spec}/diff.ts +0 -0
  59. /package/src/features/{plan → spec}/render.ts +0 -0
@@ -1,14 +1,14 @@
1
1
  /**
2
- * plan store — every submitted revision, on disk.
2
+ * spec store — every submitted revision, on disk.
3
3
  *
4
- * A plan review is a series of revisions, and the operator needs to look back
4
+ * A spec review is a series of revisions, and the operator needs to look back
5
5
  * at any of them ("what did v2 say before I asked for the split?"). So each
6
- * submit snapshots the file into `<agent-dir>/ask-plan/<slug>/vNNN.md` and
6
+ * submit snapshots the file into `<agent-dir>/ask-spec/<slug>/vNNN.md` and
7
7
  * `state.json` keeps the metadata: blocks, the block-level diff against the
8
8
  * previous revision, the annotations attached to it, and the decision.
9
9
  *
10
10
  * Deliberately outside the project tree: a review generates many revisions and
11
- * polluting `git status` with them would be noise. The approved plan itself
11
+ * polluting `git status` with them would be noise. The approved spec itself
12
12
  * stays where the agent wrote it (`specs/<slug>.md`) — the store never rewrites
13
13
  * that file, so "approved bytes == committed bytes" holds.
14
14
  */
@@ -26,17 +26,17 @@ import { parseBlocks, type Block } from "./blocks.js";
26
26
  import { diffBlocks, type DiffEntry } from "./diff.js";
27
27
  import type { Annotation, BlockAnnotations } from "./feedback.js";
28
28
 
29
- export interface PlanAnnotations {
29
+ export interface SpecAnnotations {
30
30
  global: Annotation[];
31
31
  blocks: BlockAnnotations[];
32
32
  }
33
33
 
34
- export interface PlanDecision {
34
+ export interface SpecDecision {
35
35
  action: "approve" | "deny";
36
36
  at: string;
37
37
  }
38
38
 
39
- export interface PlanVersionMeta {
39
+ export interface SpecVersionMeta {
40
40
  /** 1-based revision number. */
41
41
  n: number;
42
42
  at: string;
@@ -45,32 +45,32 @@ export interface PlanVersionMeta {
45
45
  blocks: Block[];
46
46
  /** Diff against revision n-1 ([] for the first). */
47
47
  diff: DiffEntry[];
48
- annotations: PlanAnnotations;
49
- decision?: PlanDecision;
48
+ annotations: SpecAnnotations;
49
+ decision?: SpecDecision;
50
50
  }
51
51
 
52
- export interface PlanSession {
52
+ export interface SpecSession {
53
53
  slug: string;
54
54
  dir: string;
55
55
  createdAt: string;
56
- versions: PlanVersionMeta[];
56
+ versions: SpecVersionMeta[];
57
57
  }
58
58
 
59
59
  /** Keep at most this many revisions; the oldest undecided ones go first. */
60
60
  const MAX_VERSIONS = 50;
61
61
 
62
- export function emptyAnnotations(): PlanAnnotations {
62
+ export function emptyAnnotations(): SpecAnnotations {
63
63
  return { global: [], blocks: [] };
64
64
  }
65
65
 
66
66
  /** Slug for a directory name: ascii-ish, lowercase, bounded. */
67
- export function planSlug(raw: string): string {
67
+ export function specSlug(raw: string): string {
68
68
  const slug = raw
69
69
  .toLowerCase()
70
70
  .replace(/[^a-z0-9\u4e00-\u9fff]+/g, "-")
71
71
  .replace(/^-+|-+$/g, "")
72
72
  .slice(0, 40);
73
- return slug || "plan";
73
+ return slug || "spec";
74
74
  }
75
75
 
76
76
  function versionFile(dir: string, n: number): string {
@@ -94,17 +94,17 @@ function allocateDir(root: string, slug: string): { dir: string; slug: string }
94
94
  return { dir, slug: candidate };
95
95
  }
96
96
  }
97
- throw new Error(`cannot allocate a directory for plan slug "${slug}" in ${root}`);
97
+ throw new Error(`cannot allocate a directory for spec slug "${slug}" in ${root}`);
98
98
  }
99
99
 
100
- function saveState(session: PlanSession): void {
100
+ function saveState(session: SpecSession): void {
101
101
  writeAtomic(join(session.dir, "state.json"), `${JSON.stringify(session, null, 2)}\n`);
102
102
  }
103
103
 
104
104
  /** Trim old revisions: never drop the latest, never drop a decided one. */
105
- function pruneVersions(session: PlanSession): void {
105
+ function pruneVersions(session: SpecSession): void {
106
106
  if (session.versions.length <= MAX_VERSIONS) return;
107
- const keep: PlanVersionMeta[] = [];
107
+ const keep: SpecVersionMeta[] = [];
108
108
  const latest = session.versions.at(-1);
109
109
  // Iterate oldest → newest, dropping undecided revisions while over budget.
110
110
  for (const version of session.versions) {
@@ -120,8 +120,8 @@ function pruneVersions(session: PlanSession): void {
120
120
  session.versions = keep;
121
121
  }
122
122
 
123
- export interface CreatePlanSessionOptions {
124
- /** `<agent-dir>` — the store lives at `<agentDir>/ask-plan/`. */
123
+ export interface CreateSpecSessionOptions {
124
+ /** `<agent-dir>` — the store lives at `<agentDir>/ask-spec/`. */
125
125
  agentDir: string;
126
126
  slug: string;
127
127
  text: string;
@@ -129,17 +129,38 @@ export interface CreatePlanSessionOptions {
129
129
  now?: Date;
130
130
  }
131
131
 
132
- export function createPlanSession(options: CreatePlanSessionOptions): PlanSession {
132
+ const STORE_DIR = "ask-spec";
133
+ const LEGACY_STORE_DIR = "ask-plan";
134
+
135
+ /**
136
+ * Store root, migrating the pre-rename `ask-plan` directory when it is the only
137
+ * one present. If the rename fails (read-only agent dir), the legacy directory
138
+ * keeps working instead of silently starting a second history.
139
+ */
140
+ function storeRoot(agentDir: string): string {
141
+ const root = join(agentDir, STORE_DIR);
142
+ const legacy = join(agentDir, LEGACY_STORE_DIR);
143
+ if (!existsSync(root) && existsSync(legacy)) {
144
+ try {
145
+ renameSync(legacy, root);
146
+ } catch {
147
+ return legacy;
148
+ }
149
+ }
150
+ return root;
151
+ }
152
+
153
+ export function createSpecSession(options: CreateSpecSessionOptions): SpecSession {
133
154
  const now = options.now ?? new Date();
134
- const root = join(options.agentDir, "ask-plan");
135
- const { dir, slug } = allocateDir(root, planSlug(options.slug));
136
- const session: PlanSession = {
155
+ const root = storeRoot(options.agentDir);
156
+ const { dir, slug } = allocateDir(root, specSlug(options.slug));
157
+ const session: SpecSession = {
137
158
  slug,
138
159
  dir,
139
160
  createdAt: now.toISOString(),
140
161
  versions: [],
141
162
  };
142
- appendPlanVersion(session, {
163
+ appendSpecVersion(session, {
143
164
  text: options.text,
144
165
  source: options.source,
145
166
  now,
@@ -154,17 +175,17 @@ export interface AppendVersionOptions {
154
175
  }
155
176
 
156
177
  /** Snapshot a new revision, diffing it against the previous one. */
157
- export function appendPlanVersion(
158
- session: PlanSession,
178
+ export function appendSpecVersion(
179
+ session: SpecSession,
159
180
  options: AppendVersionOptions,
160
- ): PlanVersionMeta {
181
+ ): SpecVersionMeta {
161
182
  const now = options.now ?? new Date();
162
183
  const previous = session.versions.at(-1);
163
184
  const blocks = parseBlocks(options.text);
164
185
  // Revision numbers are identities, not positions. Pruning old revisions must
165
186
  // never make the next submission reuse an existing number (and overwrite its
166
187
  // snapshot or merge its annotations into the wrong review round).
167
- const version: PlanVersionMeta = {
188
+ const version: SpecVersionMeta = {
168
189
  n: (previous?.n ?? 0) + 1,
169
190
  at: now.toISOString(),
170
191
  source: options.source,
@@ -179,66 +200,73 @@ export function appendPlanVersion(
179
200
  return version;
180
201
  }
181
202
 
182
- export function setPlanAnnotations(
183
- session: PlanSession,
203
+ export function setSpecAnnotations(
204
+ session: SpecSession,
184
205
  n: number,
185
- annotations: PlanAnnotations,
206
+ annotations: SpecAnnotations,
186
207
  ): void {
187
208
  const version = session.versions.find((candidate) => candidate.n === n);
188
- if (!version) throw new Error(`no plan revision ${n} in ${session.dir}`);
209
+ if (!version) throw new Error(`no spec revision ${n} in ${session.dir}`);
189
210
  version.annotations = annotations;
190
211
  saveState(session);
191
212
  }
192
213
 
193
- export function recordPlanDecision(
194
- session: PlanSession,
214
+ export function recordSpecDecision(
215
+ session: SpecSession,
195
216
  n: number,
196
217
  action: "approve" | "deny",
197
218
  now: Date = new Date(),
198
219
  ): void {
199
220
  const version = session.versions.find((candidate) => candidate.n === n);
200
- if (!version) throw new Error(`no plan revision ${n} in ${session.dir}`);
221
+ if (!version) throw new Error(`no spec revision ${n} in ${session.dir}`);
201
222
  version.decision = { action, at: now.toISOString() };
202
223
  saveState(session);
203
224
  }
204
225
 
205
- export function latestVersion(session: PlanSession): PlanVersionMeta {
226
+ export function latestVersion(session: SpecSession): SpecVersionMeta {
206
227
  const version = session.versions.at(-1);
207
- if (!version) throw new Error(`plan session ${session.dir} has no revisions`);
228
+ if (!version) throw new Error(`spec session ${session.dir} has no revisions`);
208
229
  return version;
209
230
  }
210
231
 
211
- export function readVersionText(session: PlanSession, n: number): string {
232
+ export function readVersionText(session: SpecSession, n: number): string {
212
233
  return readFileSync(versionFile(session.dir, n), "utf8");
213
234
  }
214
235
 
215
236
  /**
216
- * Load a session from disk (used by tests and by `/ask-plan open` after a reload).
237
+ * Load a session from disk (used by tests and by `/ask-spec open` after a reload).
217
238
  * A corrupt state file is reported with the path — a raw SyntaxError from
218
239
  * JSON.parse would leave the operator guessing which file is broken.
219
240
  */
220
- export function loadPlanSession(dir: string): PlanSession {
241
+ export function loadSpecSession(dir: string): SpecSession {
221
242
  const path = join(dir, "state.json");
222
243
  let parsed: unknown;
223
244
  try {
224
245
  parsed = JSON.parse(readFileSync(path, "utf8"));
225
246
  } catch (error) {
226
247
  const reason = error instanceof Error ? error.message : String(error);
227
- throw new Error(`cannot read plan state at ${path}: ${reason}`);
248
+ throw new Error(`cannot read spec state at ${path}: ${reason}`);
228
249
  }
229
250
  if (!parsed || typeof parsed !== "object") {
230
- throw new Error(`plan state at ${path} is not an object`);
251
+ throw new Error(`spec state at ${path} is not an object`);
231
252
  }
232
- return { ...(parsed as PlanSession), dir };
253
+ return { ...(parsed as SpecSession), dir };
233
254
  }
234
255
 
235
- /** Directories under `<agentDir>/ask-plan/`, newest first. */
236
- export function listPlanSessions(agentDir: string): string[] {
237
- const root = join(agentDir, "ask-plan");
238
- if (!existsSync(root)) return [];
239
- return readdirSync(root, { withFileTypes: true })
240
- .filter((entry) => entry.isDirectory())
241
- .map((entry) => join(root, entry.name))
242
- .filter((dir) => existsSync(join(dir, "state.json")))
256
+ /** Directories under `<agentDir>/ask-spec/`, newest first. */
257
+ export function listSpecSessions(agentDir: string): string[] {
258
+ const root = storeRoot(agentDir);
259
+ const legacy = join(agentDir, LEGACY_STORE_DIR);
260
+ // A partially migrated agent dir can contain both. Keep every session
261
+ // readable instead of hiding the legacy half or merging directories.
262
+ const roots = legacy === root || !existsSync(legacy) ? [root] : [root, legacy];
263
+ return roots
264
+ .filter((candidate) => existsSync(candidate))
265
+ .flatMap((candidate) =>
266
+ readdirSync(candidate, { withFileTypes: true })
267
+ .filter((entry) => entry.isDirectory())
268
+ .map((entry) => join(candidate, entry.name))
269
+ .filter((dir) => existsSync(join(dir, "state.json"))),
270
+ )
243
271
  .sort((a, b) => a.localeCompare(b));
244
272
  }
@@ -31,6 +31,10 @@ beforeEach(() => {
31
31
  sessionId = `s-${Math.random().toString(36).slice(2, 8)}`;
32
32
  mkdirSync(join(root, ".agents/framework"), { recursive: true });
33
33
  writeFileSync(join(root, ".agents/framework/state.toml"), 'version = 1\ntool = "test"\n', "utf8");
34
+ writeFileSync(join(root, "AGENTS.md"), "# demo\n", "utf8");
35
+ mkdirSync(join(root, ".agents/memory"), { recursive: true });
36
+ writeFileSync(join(root, ".agents/memory/README.md"), "# contract\n", "utf8");
37
+ mkdirSync(join(root, ".agents/implementations"), { recursive: true });
34
38
  });
35
39
 
36
40
  afterEach(() => {
@@ -168,6 +172,17 @@ describe("ask-uat command", () => {
168
172
  expect(h.openBrowser).not.toHaveBeenCalled();
169
173
  });
170
174
 
175
+ it("refuses a half-installed framework and names the missing piece", async () => {
176
+ rmSync(join(root, ".agents/memory/README.md"));
177
+ const h = harness();
178
+ await h.commands.get(UAT_COMMAND)!.handler("", h.ctx);
179
+ expect(h.notify).toHaveBeenCalledWith(
180
+ expect.stringContaining(".agents/memory/README.md"),
181
+ "error",
182
+ );
183
+ expect(h.openBrowser).not.toHaveBeenCalled();
184
+ });
185
+
171
186
  it("opens the page and dispatches clustering only when records are pending", async () => {
172
187
  createRecord(root, { title: "alpha change", body: "body", now: new Date(2026, 10, 12, 9, 0) });
173
188
  const h = harness();
@@ -225,7 +240,7 @@ describe("ask-uat command", () => {
225
240
  h.shutdown();
226
241
  });
227
242
 
228
- it("exits consult mode deliberately and refuses to start during planning", async () => {
243
+ it("exits consult mode deliberately and refuses to start during spec review", async () => {
229
244
  let consulting = true;
230
245
  setAskControl({ isActive: () => consulting, exit: () => { consulting = false; } });
231
246
  const h = harness();
@@ -234,14 +249,14 @@ describe("ask-uat command", () => {
234
249
  expect(h.openBrowser).toHaveBeenCalledTimes(1);
235
250
  await h.commands.get(UAT_COMMAND)!.handler("off", h.ctx);
236
251
 
237
- h.pi.setActiveTools([...h.activeTools(), "plan_submit"]);
252
+ h.pi.setActiveTools([...h.activeTools(), "spec_submit"]);
238
253
  await h.commands.get(UAT_COMMAND)!.handler("", h.ctx);
239
- expect(h.notify).toHaveBeenLastCalledWith(expect.stringContaining("finish or approve the plan"), "warning");
254
+ expect(h.notify).toHaveBeenLastCalledWith(expect.stringContaining("finish or approve the spec"), "warning");
240
255
  expect(h.openBrowser).toHaveBeenCalledTimes(1);
241
256
  h.shutdown();
242
257
  });
243
258
 
244
- it("keeps record_change out of read-only consult and planning phases", async () => {
259
+ it("keeps record_change out of read-only consult and spec-review phases", async () => {
245
260
  setAskControl({ isActive: () => true, exit: () => {} });
246
261
  const h = harness();
247
262
  for (const handler of h.handlers.before_agent_start ?? []) handler({ systemPrompt: "base" }, h.ctx);
@@ -257,7 +272,7 @@ describe("ask-uat command", () => {
257
272
  expect(existsSync(join(root, ".agents/implementations/2026-11-13_2107_forbidden.md"))).toBe(false);
258
273
 
259
274
  setAskControl(undefined);
260
- h.pi.setActiveTools([...h.activeTools(), "plan_submit"]);
275
+ h.pi.setActiveTools([...h.activeTools(), "spec_submit"]);
261
276
  for (const handler of h.handlers.before_agent_start ?? []) handler({ systemPrompt: "base" }, h.ctx);
262
277
  expect(h.activeTools()).not.toContain(RECORD_CHANGE_TOOL);
263
278
  h.shutdown();
@@ -10,7 +10,7 @@
10
10
  * items stream into the page while the agent works;
11
11
  * - `uat_item` is the only writer of item identity, and it is active only in
12
12
  * this phase; `record_change` is active in framework projects outside the
13
- * read-only consult and planning phases;
13
+ * read-only consult and spec-review phases;
14
14
  * - nothing here edits code, and there is no submit: a checkbox appends one
15
15
  * event to `.agents/uat/ledger.jsonl` and that is the whole decision.
16
16
  *
@@ -19,6 +19,7 @@
19
19
  */
20
20
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
21
21
  import { getAskControl } from "../../lib/ask-control.js";
22
+ import { SPEC_PHASE_TOOL, LEGACY_SPEC_PHASE_TOOL } from "../../lib/phases.js";
22
23
  import { openInBrowser } from "../../lib/opener.js";
23
24
  import {
24
25
  MAX_CANDIDATES_PER_RUN,
@@ -26,6 +27,7 @@ import {
26
27
  RECORD_CHANGE_TOOL,
27
28
  UAT_COMMAND,
28
29
  UAT_IDLE_CLOSE_MS,
30
+ UAT_ITEM_TOOL,
29
31
  } from "./constants.js";
30
32
  import { registerUatItemTool } from "./item-tool.js";
31
33
  import { deriveState, ledgerPath, readEvents, appendEvent, newEventId } from "./ledger.js";
@@ -33,7 +35,7 @@ import { listRecords } from "./records.js";
33
35
  import { buildUatKickoff, describeCounts, UAT_MODE_BANNER } from "./prompt.js";
34
36
  import { registerRecordTool } from "./record-tool.js";
35
37
  import { startUatServer, type UatServerHandle } from "./server.js";
36
- import { frameworkInstalled, loadSnapshot, resolveProjectRoot } from "./state.js";
38
+ import { frameworkInstalled, frameworkMissing, loadSnapshot, resolveProjectRoot } from "./state.js";
37
39
 
38
40
  export interface UatOptions {
39
41
  /** Opening the browser is injectable so tests never spawn one. */
@@ -72,13 +74,13 @@ export function registerUat(pi: ExtensionAPI, options: UatOptions = {}): void {
72
74
  let lastActivity = Date.now();
73
75
  let idleTimer: NodeJS.Timeout | undefined;
74
76
 
75
- // `plan_submit` is the owning feature's phase marker. Detecting the active
77
+ // `spec_submit` is the owning feature's phase marker. Detecting the active
76
78
  // tool avoids a second global control registry while still keeping the two
77
79
  // phases' write surfaces disjoint.
78
- const planningTool = "plan_submit";
80
+ const specTools = new Set([SPEC_PHASE_TOOL, LEGACY_SPEC_PHASE_TOOL]);
79
81
 
80
82
  function recordChangeAllowed(tools: readonly string[] = pi.getActiveTools()): boolean {
81
- return !getAskControl()?.isActive() && !tools.includes(planningTool);
83
+ return !getAskControl()?.isActive() && !tools.some((name) => specTools.has(name));
82
84
  }
83
85
 
84
86
  function syncRecordTool(installed: boolean): void {
@@ -129,7 +131,7 @@ export function registerUat(pi: ExtensionAPI, options: UatOptions = {}): void {
129
131
  batch = undefined;
130
132
  clearIdle();
131
133
  closeServer();
132
- pi.setActiveTools(toolsWith([], ["uat_item"]));
134
+ pi.setActiveTools(toolsWith([], [UAT_ITEM_TOOL]));
133
135
  ctx.ui.notify(`ask-uat: ${reason}`, "info");
134
136
  }
135
137
 
@@ -186,8 +188,9 @@ export function registerUat(pi: ExtensionAPI, options: UatOptions = {}): void {
186
188
  async function start(ctx: ExtensionContext): Promise<void> {
187
189
  const projectRoot = rootOf(ctx.cwd || process.cwd());
188
190
  if (!frameworkInstalled(projectRoot)) {
191
+ const missing = frameworkMissing(projectRoot);
189
192
  ctx.ui.notify(
190
- "ask-uat: this project has no agent framework (.agents/framework/state.toml) — run /ask-init first.",
193
+ `ask-uat: the agent framework is incomplete (missing: ${missing.join(", ")}) — run /ask-init first.`,
191
194
  "error",
192
195
  );
193
196
  return;
@@ -195,8 +198,8 @@ export function registerUat(pi: ExtensionAPI, options: UatOptions = {}): void {
195
198
  root = projectRoot;
196
199
  ctxRef = ctx;
197
200
 
198
- if (pi.getActiveTools().includes(planningTool)) {
199
- ctx.ui.notify("ask-uat: finish or approve the plan before acceptance.", "warning");
201
+ if (pi.getActiveTools().some((name) => specTools.has(name))) {
202
+ ctx.ui.notify("ask-uat: finish or approve the spec before acceptance.", "warning");
200
203
  return;
201
204
  }
202
205
 
@@ -216,7 +219,7 @@ export function registerUat(pi: ExtensionAPI, options: UatOptions = {}): void {
216
219
  }
217
220
 
218
221
  // UAT legitimately writes ledger events, so it cannot run inside the
219
- // read-only consult phase. Match /ask-plan: the explicit phase command
222
+ // read-only consult phase. Match /ask-spec: the explicit phase command
220
223
  // exits consult mode through its owner, preserving its tool snapshot.
221
224
  const ask = getAskControl();
222
225
  if (ask?.isActive()) ask.exit(ctx);
@@ -234,7 +237,7 @@ export function registerUat(pi: ExtensionAPI, options: UatOptions = {}): void {
234
237
  startIdleTimer();
235
238
  // The framework is installed here, so both tools belong in the request:
236
239
  // clustering writes items, and the same turn may need to record a change.
237
- pi.setActiveTools(toolsWith(["record_change", "uat_item"]));
240
+ pi.setActiveTools(toolsWith(["record_change", UAT_ITEM_TOOL]));
238
241
  open(server.url);
239
242
 
240
243
  const pending = snapshot.state.pending;
@@ -292,7 +295,7 @@ export function registerUat(pi: ExtensionAPI, options: UatOptions = {}): void {
292
295
  syncRecordTool(frameworkInstalled(projectRoot));
293
296
  if (active) {
294
297
  const current = pi.getActiveTools();
295
- if (!current.includes("uat_item")) pi.setActiveTools([...current, "uat_item"]);
298
+ if (!current.includes(UAT_ITEM_TOOL)) pi.setActiveTools([...current, UAT_ITEM_TOOL]);
296
299
  }
297
300
  if (!active) return undefined;
298
301
  return { systemPrompt: `${event.systemPrompt}\n\n${UAT_MODE_BANNER}` };
@@ -310,7 +313,7 @@ export function registerUat(pi: ExtensionAPI, options: UatOptions = {}): void {
310
313
  closeServer();
311
314
  // Session state never leaks: remove the phase tool unconditionally, then
312
315
  // recompute the record tool from the new project's framework and phase.
313
- pi.setActiveTools(toolsWith([], ["uat_item"]));
316
+ pi.setActiveTools(toolsWith([], [UAT_ITEM_TOOL]));
314
317
  root = rootOf(ctx.cwd || process.cwd());
315
318
  syncRecordTool(frameworkInstalled(root));
316
319
  });
@@ -22,7 +22,7 @@ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-a
22
22
  import { RECORD_CHANGE_TOOL } from "./constants.js";
23
23
  import { appendEvent, ledgerPath, newEventId } from "./ledger.js";
24
24
  import { createRecord } from "./records.js";
25
- import { frameworkInstalled, resolveProjectRoot } from "./state.js";
25
+ import { frameworkInstalled, frameworkMissing, resolveProjectRoot } from "./state.js";
26
26
 
27
27
  const PARAMS = Type.Object({
28
28
  title: Type.String({
@@ -43,7 +43,7 @@ const PARAMS = Type.Object({
43
43
  }),
44
44
  ),
45
45
  area: Type.Optional(
46
- Type.String({ description: 'Short area label used for clustering, e.g. "ask-plan", "auth".' }),
46
+ Type.String({ description: 'Short area label used for clustering, e.g. "ask-spec", "auth".' }),
47
47
  ),
48
48
  files: Type.Optional(
49
49
  Type.Array(Type.String({ description: "File touched by this change." }), {
@@ -83,7 +83,7 @@ export interface RecordToolOptions {
83
83
  /** Resolve the project root (main worktree). Injectable for tests. */
84
84
  root?: (cwd: string) => string;
85
85
  /**
86
- * Phase guard, not just a registration guard: read-only consult and planning
86
+ * Phase guard, not just a registration guard: read-only consult and spec review
87
87
  * must not acquire a project-writing tool merely because the framework exists.
88
88
  */
89
89
  canRecord?: () => boolean;
@@ -104,13 +104,14 @@ export function registerRecordTool(pi: ExtensionAPI, options: RecordToolOptions
104
104
  async execute(_toolCallId, params, _signal, _onUpdate, ctx: ExtensionContext) {
105
105
  if (options.canRecord && !options.canRecord()) {
106
106
  return errorResult(
107
- "record_change: disabled during read-only consult or planning — exit /ask, or approve the plan and finish the implementation first.",
107
+ "record_change: disabled during read-only consult or spec review — exit /ask, or approve the spec and finish the implementation first.",
108
108
  );
109
109
  }
110
110
  const root = rootOf(ctx.cwd || process.cwd());
111
111
  if (!frameworkInstalled(root)) {
112
+ const missing = frameworkMissing(root);
112
113
  return errorResult(
113
- "record_change: this project has no agent framework (.agents/framework/state.toml). Run /ask-init first, or write the record by hand.",
114
+ `record_change: the agent framework is incomplete (missing: ${missing.join(", ")}). Run /ask-init first, or write the record by hand.`,
114
115
  );
115
116
  }
116
117
  const title = params.title.trim();
@@ -55,10 +55,10 @@ describe("header and name shapes", () => {
55
55
  hhmm: "2107",
56
56
  slug: "ask-uat",
57
57
  });
58
- expect(parseRecordFileName("2026-11-11_ask-plan.md")).toEqual({
58
+ expect(parseRecordFileName("2026-11-11_ask-spec.md")).toEqual({
59
59
  date: "2026-11-11",
60
60
  hhmm: undefined,
61
- slug: "ask-plan",
61
+ slug: "ask-spec",
62
62
  });
63
63
  });
64
64
 
@@ -71,10 +71,10 @@ describe("header and name shapes", () => {
71
71
 
72
72
  describe("listRecords", () => {
73
73
  it("accepts old records and marks them non-canonical", () => {
74
- writeRaw("2026-11-11_ask-plan.md", "# 2026-11-11T02:55:59+08:00 — plan review\n\nbody\n");
74
+ writeRaw("2026-11-11_ask-spec.md", "# 2026-11-11T02:55:59+08:00 — spec review\n\nbody\n");
75
75
  const [record] = listRecords(root);
76
- expect(record.id).toBe("2026-11-11_ask-plan");
77
- expect(record.title).toBe("plan review");
76
+ expect(record.id).toBe("2026-11-11_ask-spec");
77
+ expect(record.title).toBe("spec review");
78
78
  expect(record.canonical).toBe(false);
79
79
  expect(record.epochMs).toBeGreaterThan(0);
80
80
  });
@@ -11,9 +11,8 @@
11
11
  * changed in between. The cache is the reason a UI refresh does not spawn git.
12
12
  */
13
13
  import { execFileSync } from "node:child_process";
14
- import { existsSync } from "node:fs";
15
- import { join, resolve } from "node:path";
16
- import { STATE_FILE } from "../init/spec.js";
14
+ import { resolve } from "node:path";
15
+ import { frameworkReadiness } from "../init/parity.js";
17
16
  import { deriveState, ledgerPath, readEvents, type UatState } from "./ledger.js";
18
17
  import { listRecords, type RecordEntry } from "./records.js";
19
18
 
@@ -47,9 +46,18 @@ export function resetProjectRootCache(): void {
47
46
  rootCache.clear();
48
47
  }
49
48
 
50
- /** The UAT flow only exists in a project that installed the framework. */
49
+ /**
50
+ * The ask loop needs a usable framework, not byte-identical files: state,
51
+ * AGENTS.md, the memory contract and the evidence directory. Small edits to any
52
+ * of them are the operator's business and do not block acceptance.
53
+ */
51
54
  export function frameworkInstalled(root: string): boolean {
52
- return existsSync(join(root, STATE_FILE));
55
+ return frameworkReadiness(root).ready;
56
+ }
57
+
58
+ /** Missing pieces, for a refusal message that tells the operator what to fix. */
59
+ export function frameworkMissing(root: string): string[] {
60
+ return frameworkReadiness(root).missing;
53
61
  }
54
62
 
55
63
  export interface UatSnapshot {
package/src/index.ts CHANGED
@@ -30,7 +30,7 @@ import { registerCompact } from "./features/compact/index.js";
30
30
  import { registerFavorites } from "./features/favorites/index.js";
31
31
  import { registerInit } from "./features/init/index.js";
32
32
  import { registerPermission } from "./features/permission/index.js";
33
- import { registerPlan } from "./features/plan/index.js";
33
+ import { registerSpec } from "./features/spec/index.js";
34
34
  import { registerQuitGuard } from "./features/quit-guard/index.js";
35
35
  import { registerReview } from "./features/review/index.js";
36
36
  import { registerStash } from "./features/stash/index.js";
@@ -47,9 +47,9 @@ export default function piToolkits(pi: ExtensionAPI): void {
47
47
  // Permission registers its session_start reset before autostart, so a
48
48
  // project-declared `/ask-perm ...` runs against a freshly reset mode.
49
49
  registerPermission(pi, gates, { audit });
50
- // Plan mode drives the permission control that `registerPermission` just
51
- // published (it turns checks on while planning and restores them after).
52
- registerPlan(pi, gates);
50
+ // Spec mode drives the permission control that `registerPermission` just
51
+ // published (it turns checks on while reviewing and restores them after).
52
+ registerSpec(pi, gates);
53
53
  registerAutostart(pi);
54
54
  registerCompact(pi);
55
55
  registerFavorites(pi);
@@ -57,8 +57,8 @@ export default function piToolkits(pi: ExtensionAPI): void {
57
57
  registerQuitGuard(pi);
58
58
  registerReview(pi);
59
59
  registerStash(pi);
60
- // UAT registers after plan so its `before_agent_start` re-assertion runs last
61
- // and can add `record_change` to whatever tool set plan installed.
60
+ // UAT registers after spec so its `before_agent_start` re-assertion runs last
61
+ // and can add `record_change` to whatever tool set spec installed.
62
62
  registerUat(pi);
63
63
  registerWhatsNew(pi);
64
64
 
@@ -1,6 +1,6 @@
1
1
  /**
2
- * ask control — lets `/ask-plan` leave consult mode before opening its broader
3
- * planning phase.
2
+ * ask control — lets `/ask-spec` leave consult mode before opening its broader
3
+ * spec-review phase.
4
4
  *
5
5
  * `/ask` owns its state and its tool-set snapshot, so another feature must not
6
6
  * imitate the exit by manipulating tools itself. This small handle is the same
@@ -1,13 +1,13 @@
1
1
  /**
2
- * permission control — the handle `/ask-plan` uses to turn the boundary checks
3
- * on for the planning phase and put them back afterwards.
2
+ * permission control — the handle `/ask-spec` uses to turn the boundary checks
3
+ * on for the spec-review phase and put them back afterwards.
4
4
  *
5
5
  * Why a registry instead of an import: `/ask-perm` keeps its state in a closure
6
6
  * inside `registerPermission()`, so there is no module-level setter to call.
7
7
  * A tiny registry (same pattern as `src/lib/startup.ts` for the autostart
8
8
  * handoff) lets the permission feature publish a control handle at registration
9
- * time and the plan feature look it up — without either feature importing the
10
- * other's internals, and without the plan feature knowing anything about modes.
9
+ * time and the spec feature look it up — without either feature importing the
10
+ * other's internals, and without the spec feature knowing anything about modes.
11
11
  */
12
12
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
13
13
  import type { PermissionModes } from "../features/permission/constants.js";