@staix/agent-hub 0.37.0 → 0.39.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.
Files changed (164) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +17 -7
  3. package/docs/adding-an-ai-tool.md +6 -4
  4. package/docs/agent-notes/README.md +16 -0
  5. package/docs/agent-notes/adapters.md +4 -2
  6. package/docs/agent-notes/budget.md +8 -0
  7. package/docs/agent-notes/daemon.md +15 -8
  8. package/docs/agent-notes/local-worker.md +1 -1
  9. package/docs/agent-notes/security-review.md +55 -0
  10. package/docs/agent-notes/tasks.md +15 -4
  11. package/docs/agent-notes/tests.md +3 -2
  12. package/docs/design/adapters.md +51 -0
  13. package/docs/design/agent-hub-architecture.md +29 -1
  14. package/docs/design/guidance-probes.md +365 -0
  15. package/docs/design/task-board.md +151 -5
  16. package/docs/dogfood.md +22 -7
  17. package/docs/events.md +3 -3
  18. package/docs/memory.md +5 -5
  19. package/docs/operations.md +189 -32
  20. package/docs/profiles.md +101 -9
  21. package/docs/quickstart.md +38 -4
  22. package/docs/research.md +6 -3
  23. package/docs/roles.md +52 -0
  24. package/docs/sdlc.md +187 -1
  25. package/docs/security.md +56 -13
  26. package/docs/text-projection.md +1 -0
  27. package/docs/verification/2026-11-11-0.38.0.md +41 -0
  28. package/docs/verification/2026-11-11-guidance-probe-t3-1226.md +85 -0
  29. package/docs/verification/2026-11-11-guidance-probe-t4-1226.md +65 -0
  30. package/docs/verification/2026-11-13-claude-implementer-2.1.323.md +59 -0
  31. package/docs/verification/2026-11-13-codex-01672-reviewer-isolation.md +69 -0
  32. package/docs/verification/2026-11-14-0.39.0.md +51 -0
  33. package/docs/verified.json +48 -25
  34. package/package.json +3 -3
  35. package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
  36. package/plugins/agent-hub/kimi-hook.js +1989 -474
  37. package/plugins/agent-hub/server.js +2056 -512
  38. package/src/adapters/acp-model-policy.ts +1 -1
  39. package/src/adapters/acp-session-model.ts +35 -0
  40. package/src/adapters/acp.ts +14 -0
  41. package/src/adapters/agy/definition.ts +1 -1
  42. package/src/adapters/agy/hooks.ts +7 -0
  43. package/src/adapters/claude-channel.ts +3 -2
  44. package/src/adapters/claude-implementer.ts +8 -0
  45. package/src/adapters/claude-print-child.ts +26 -2
  46. package/src/adapters/claude-print.ts +4 -0
  47. package/src/adapters/codex-appserver.ts +90 -16
  48. package/src/adapters/codex-review-isolation.ts +2 -0
  49. package/src/adapters/compat.ts +4 -4
  50. package/src/adapters/conformance/fakes/acp-server.ts +11 -2
  51. package/src/adapters/conformance/fakes/app-server.ts +5 -1
  52. package/src/adapters/conformance/fakes/pi-rpc.ts +1 -1
  53. package/src/adapters/definitions/builtin-metadata.ts +6 -6
  54. package/src/adapters/definitions/native-cli-jcode-mcp.ts +18 -3
  55. package/src/adapters/definitions/native-quota.ts +122 -0
  56. package/src/adapters/definitions/native-recovery.ts +3 -0
  57. package/src/adapters/definitions/qwen.ts +1 -1
  58. package/src/adapters/kimi-review.ts +23 -0
  59. package/src/adapters/kimi-wire-usage.ts +39 -16
  60. package/src/adapters/local-probe.ts +65 -6
  61. package/src/adapters/local-worker.ts +6 -3
  62. package/src/adapters/pi-state-model.ts +12 -0
  63. package/src/adapters/pi.ts +22 -0
  64. package/src/adapters/print-result-model.ts +24 -0
  65. package/src/adapters/registry-types.ts +10 -1
  66. package/src/adapters/registry.ts +19 -2
  67. package/src/adapters/reviewer-print.ts +130 -15
  68. package/src/adapters/role-eligibility.ts +99 -0
  69. package/src/adapters/same-directory.ts +16 -0
  70. package/src/cli/agy-mcp.ts +18 -7
  71. package/src/cli/console-state.ts +3 -1
  72. package/src/cli/free-text.ts +20 -0
  73. package/src/cli/handoff-args.ts +1 -1
  74. package/src/cli/help.ts +61 -6
  75. package/src/cli/identity.ts +10 -4
  76. package/src/cli/init-prompt.ts +31 -2
  77. package/src/cli/init-roles.ts +156 -0
  78. package/src/cli/init-settings.ts +24 -2
  79. package/src/cli/init.ts +141 -17
  80. package/src/cli/main.ts +216 -56
  81. package/src/cli/model.ts +1 -1
  82. package/src/cli/output.ts +64 -5
  83. package/src/cli/preview.ts +1 -1
  84. package/src/cli/recovery-launch.ts +114 -0
  85. package/src/cli/recovery-package.ts +14 -7
  86. package/src/cli/recovery-version-preflight.ts +104 -0
  87. package/src/cli/role-doctor.ts +39 -0
  88. package/src/cli/sdlc-output.ts +66 -1
  89. package/src/cli/study-output.ts +54 -0
  90. package/src/cli/study.ts +14 -1
  91. package/src/cli/terminal-recovery.ts +14 -0
  92. package/src/cli/upgrade-presentation.ts +4 -0
  93. package/src/cli/upgrade-restore-state.ts +12 -3
  94. package/src/cli/upgrade-runtime.ts +41 -3
  95. package/src/cli/upgrade.ts +8 -4
  96. package/src/hub/advisor-survey.ts +139 -0
  97. package/src/hub/audit-source.ts +66 -0
  98. package/src/hub/board.ts +479 -14
  99. package/src/hub/budget.ts +54 -4
  100. package/src/hub/bus.ts +2 -2
  101. package/src/hub/conductor.ts +14 -8
  102. package/src/hub/config-apply.ts +2 -1
  103. package/src/hub/config-edit-host.ts +77 -5
  104. package/src/hub/considered-findings.ts +47 -0
  105. package/src/hub/control-client.ts +1 -1
  106. package/src/hub/daemon.ts +373 -66
  107. package/src/hub/deliverable-files.ts +17 -1
  108. package/src/hub/dogfood-profile.ts +3 -2
  109. package/src/hub/envelope.ts +6 -1
  110. package/src/hub/events.ts +23 -2
  111. package/src/hub/folder-trigger.ts +11 -4
  112. package/src/hub/guidance-probe-store.ts +345 -14
  113. package/src/hub/guidance-probes.ts +338 -4
  114. package/src/hub/hub-tools.ts +88 -16
  115. package/src/hub/kimi-usage.ts +34 -2
  116. package/src/hub/lifecycle-schema.ts +3 -3
  117. package/src/hub/manager.ts +24 -1
  118. package/src/hub/memory-profile.ts +9 -1
  119. package/src/hub/memory-sync-state.ts +1 -0
  120. package/src/hub/model-overrides.ts +2 -1
  121. package/src/hub/no-writes.ts +2 -0
  122. package/src/hub/operational-authority.ts +8 -2
  123. package/src/hub/operational-view.ts +5 -1
  124. package/src/hub/peers.ts +2 -0
  125. package/src/hub/person-command.ts +25 -0
  126. package/src/hub/plan-conformance.ts +20 -2
  127. package/src/hub/quota-account.ts +34 -0
  128. package/src/hub/recovery-policy.ts +18 -4
  129. package/src/hub/research-evidence.ts +51 -3
  130. package/src/hub/research.ts +77 -13
  131. package/src/hub/restart.ts +14 -0
  132. package/src/hub/review-budget.ts +88 -0
  133. package/src/hub/review-findings.ts +93 -12
  134. package/src/hub/reviewer-pool-config.ts +6 -2
  135. package/src/hub/reviewer-pool.ts +39 -6
  136. package/src/hub/routing.ts +7 -3
  137. package/src/hub/sdlc-merge.ts +1 -1
  138. package/src/hub/sdlc-queue.ts +14 -4
  139. package/src/hub/sdlc-release.ts +1 -1
  140. package/src/hub/sdlc.ts +10 -6
  141. package/src/hub/security-audit.ts +178 -0
  142. package/src/hub/security-pass.ts +115 -0
  143. package/src/hub/settings.ts +11 -5
  144. package/src/hub/source-read.ts +80 -2
  145. package/src/hub/sources.ts +57 -9
  146. package/src/hub/startup-event-seeds.ts +5 -3
  147. package/src/hub/startup-timing.ts +1 -0
  148. package/src/hub/supervision.ts +3 -2
  149. package/src/hub/synthesis-readiness.ts +279 -0
  150. package/src/hub/tasks.ts +1131 -72
  151. package/src/hub/text-projection.ts +11 -1
  152. package/src/local/probe-types.ts +2 -0
  153. package/src/local/probe-workspace.ts +191 -2
  154. package/src/memory/capture.ts +2 -1
  155. package/src/ui/guidance-panel.ts +34 -2
  156. package/src/ui/guidance-view.ts +33 -0
  157. package/src/ui/index.html +3 -0
  158. package/src/ui/office-model.ts +11 -3
  159. package/src/ui/office-space.ts +50 -30
  160. package/src/ui/plugin.ts +31 -14
  161. package/templates/AGENTS.block.md +14 -14
  162. package/templates/profiles/general.json +1 -1
  163. package/templates/profiles/research.json +1 -1
  164. package/templates/profiles/writing.json +1 -1
package/src/cli/init.ts CHANGED
@@ -3,7 +3,7 @@ import { initShadow, repoOf } from "../hub/snapshots.ts";
3
3
  import { PROFILE_NAMES, profileName, projectProfile, resolveProfile, mergeProfileOverrides, type ProfileName } from "../hub/profiles.ts";
4
4
  import { canonicalJson, loadPacks, packOverrides, type DomainPack } from "../hub/packs.ts";
5
5
  import { JCODE_MCP_FILE } from "./jcode-mcp.ts";
6
- import { existsSync, lstatSync, mkdirSync, readFileSync, statSync, unlinkSync, writeFileSync, renameSync } from "node:fs";
6
+ import { closeSync, constants, fstatSync, openSync, readSync, existsSync, lstatSync, mkdirSync, readFileSync, statSync, unlinkSync, writeFileSync, renameSync } from "node:fs";
7
7
  import { dirname, isAbsolute, join, resolve } from "node:path";
8
8
  import { spawnSync } from "node:child_process";
9
9
  import type { Stats } from "node:fs";
@@ -11,12 +11,14 @@ import { realPath } from "../hub/project.ts";
11
11
  import { hubGitArgv, hubGitEnv, hubGitSync } from "../hub/git.ts";
12
12
  import { KIMI_MCP_FILE } from "./kimi-mcp.ts";
13
13
  import { AGY_PLUGIN_FILES } from "./agy-mcp.ts";
14
- import { loadConfig } from "../hub/daemon.ts";
14
+ import { DEFAULT_CONFIG, loadConfig } from "../hub/daemon.ts";
15
+ import { ALL_MACHINE_LOCAL } from "../hub/config-trust.ts";
15
16
  import { requiredChecksFor } from "../hub/sdlc-merge.ts";
16
17
  import { githubOriginRepository } from "../hub/task-repository.ts";
17
18
  import { loadSdlc, sdlcConfig } from "../hub/sdlc.ts";
18
19
  import { VERSION } from "../version.ts";
19
- import { planInitSettings, type InitSettingFile, type InitSettingRow, type InitSettingsRequest } from "./init-settings.ts";
20
+ import { roleSummaryLines } from "./init-roles.ts";
21
+ import { planInitSettings, TRACK_CONFIG, type InitSettingFile, type InitSettingRow, type InitSettingsRequest } from "./init-settings.ts";
20
22
 
21
23
  const TEMPLATES = join(import.meta.dir, "..", "..", "templates");
22
24
  const BEGIN = "<!-- AGENT_HUB:BEGIN (managed by `ahub init`, edits inside are overwritten) -->";
@@ -40,6 +42,77 @@ export function removeBlock(existing: string): string {
40
42
  return rest && `${rest}\n`;
41
43
  }
42
44
 
45
+ /** #1411: the files a repository either commits (the team shares roles and defaults) or keeps per checkout. */
46
+ const SHARED_CONFIG = ["config.json", "routing.toml", "sdlc.toml"] as const;
47
+ /** #1411: the managed block's role sentence, one per choice. The tracked one is the template's own text. */
48
+ export const ROLES_TRACKED = "`.agenthub/config.json` `roles` says who plans, implements, verifies and reviews.";
49
+ export const ROLES_UNTRACKED = "Roles are held by this checkout's hub, not by a file in the repository: `ahub roles` prints who plans, implements, verifies, reviews and conducts; your own roles are in your session instructions.";
50
+
51
+ /**
52
+ * #1411: git's own verdict on whether its ignore rules (the repository's, `.git/info/exclude` and the person's global file) ignore `path`, tracked or not: the rule as
53
+ * `source:line:pattern`, `null` when no rule ignores it, `undefined` when git cannot say (no repository). `-v` also reports a `!` rule that re-includes the path, with
54
+ * exit 0, so the pattern decides.
55
+ */
56
+ export function ignoreRule(cwd: string, path: string): string | null | undefined {
57
+ const r = hubGitSync(["check-ignore", "-v", "-z", "--no-index", "--stdin"], { cwd, encoding: "utf8", timeout: 3000, input: `${path}\0` });
58
+ if (r.status === 1) return null;
59
+ if (r.status !== 0) return undefined;
60
+ const [source, line, pattern] = r.stdout.split("\0");
61
+ return pattern === undefined || pattern.startsWith("!") ? null : `${source}:${line}:${pattern}`;
62
+ }
63
+ /** #1411 (owner comment): `hub_routes` keys that name this machine's endpoints; routing.local.toml cannot hold them yet, so a routing.toml that sets one stays untracked. */
64
+ function routingMachineKeys(cwd: string): string[] {
65
+ const path = join(cwd, ".agenthub", "routing.toml");
66
+ if (!existsSync(path)) return [];
67
+ let routes: unknown;
68
+ try { routes = (Bun.TOML.parse(readFileSync(path, "utf8")) as Record<string, unknown>).hub_routes; } catch { return []; } // the routing loader reports a bad file itself
69
+ if (!routes || typeof routes !== "object") return [];
70
+ return Object.entries(routes as Record<string, unknown>).filter(([, route]) => route && typeof route === "object" && Object.hasOwn(route, "adec_endpoint")).map(([id]) => `hub_routes."${id}".adec_endpoint`);
71
+ }
72
+ /** #1411: machine-local fields a committed config.json would set; the loader ignores them there, so they belong in config.local.json. */
73
+ function personalValues(cwd: string): string[] {
74
+ const path = join(cwd, ".agenthub", "config.json");
75
+ if (!existsSync(path)) return [];
76
+ let file: unknown;
77
+ try { file = JSON.parse(readFileSync(path, "utf8")); } catch { return []; }
78
+ const at = (doc: unknown, key: string) => key.split(".").reduce<unknown>((node, part) => node && typeof node === "object" ? (node as Record<string, unknown>)[part] : undefined, doc);
79
+ const empty = (value: unknown) => value === undefined || value === null || value === "" || Array.isArray(value) && !value.length;
80
+ return ALL_MACHINE_LOCAL.filter(key => !empty(at(file, key)) && JSON.stringify(at(file, key)) !== JSON.stringify(at(DEFAULT_CONFIG, key)));
81
+ }
82
+ /** #1411: whether the block should say the config is tracked. A choice wins; without one an existing block keeps its sentence (AC2), and a new block follows what git says today. */
83
+ function rolesTracked(cwd: string, existing: string, settings: InitSettingsRequest | undefined): boolean {
84
+ const choice = settings?.values[TRACK_CONFIG];
85
+ if (typeof choice === "boolean") return choice;
86
+ if (existing.includes(ROLES_UNTRACKED)) return false;
87
+ if (existing.includes("<!-- AGENT_HUB:BEGIN")) return true;
88
+ return !ignoreRule(cwd, ".agenthub/config.json");
89
+ }
90
+
91
+ /**
92
+ * #1411 T2: doctor's `shared config` row. Whether `.agenthub/config.json` is committed agrees with the managed block's role sentence: `ok` true for both deliberate
93
+ * states, `undefined` (a warning) for a mismatch or a git state it cannot read, with the command that fixes it; `null` when there is no block sentence or no config to compare.
94
+ */
95
+ export function sharedConfigRow(cwd: string): { ok: true | undefined; detail: string } | null {
96
+ const agents = join(cwd, "AGENTS.md"), file = ".agenthub/config.json";
97
+ if (!existsSync(agents) || !existsSync(join(cwd, file))) return null;
98
+ const block = readFileSync(agents, "utf8");
99
+ const saysTracked = block.includes(ROLES_TRACKED), saysUntracked = block.includes(ROLES_UNTRACKED);
100
+ if (saysTracked === saysUntracked) return null; // no managed sentence (an older block): the hub instructions row says to refresh it
101
+ const listed = hubGitSync(["ls-files", "--error-unmatch", "--", file], { cwd, encoding: "utf8", timeout: 3000 }).status;
102
+ const rule = ignoreRule(cwd, file);
103
+ if (listed !== 0 && listed !== 1 || rule === undefined) return { ok: undefined, detail: `git could not say whether ${file} is committed; check with: cd ${cwd} && git ls-files ${file}` };
104
+ const committed = listed === 0, toUntracked = `cd ${cwd} && ahub init --no-track-config --yes`;
105
+ if (saysUntracked) return committed
106
+ ? { ok: undefined, detail: `the AGENTS block says roles are per checkout, but ${file} is committed; share it: cd ${cwd} && ahub init --track-config --yes; or stop tracking it: cd ${cwd} && git rm --cached ${file}, then commit` }
107
+ : { ok: true, detail: "untracked (by choice): each checkout holds its own roles; ahub roles prints them" };
108
+ if (!committed) return { ok: undefined, detail: rule
109
+ ? `the AGENTS block points at ${file}, which ${rule} ignores; keep it per checkout: ${toUntracked}; or remove that rule and commit the file`
110
+ : `the AGENTS block points at ${file}, which is not committed; commit it: cd ${cwd} && git add ${file} && git commit; or keep it per checkout: ${toUntracked}` };
111
+ return rule
112
+ ? { ok: undefined, detail: `${file} is committed but ${rule} ignores it, so a re-added copy is skipped; remove that rule, or stop tracking it: ${toUntracked} && git rm --cached ${file}` }
113
+ : { ok: true, detail: `tracked: ${file} is committed and the AGENTS block points at it` };
114
+ }
115
+
43
116
  export interface InitChange {
44
117
  action: "create" | "modify" | "delete";
45
118
  path: string;
@@ -212,7 +285,10 @@ function changes(cwd: string, requestedName?: string, shadow = false, releaseGua
212
285
  }
213
286
  const agents = join(cwd, "AGENTS.md");
214
287
  const existing = existsSync(agents) ? readFileSync(agents, "utf8") : "";
215
- const hubBlock = upsertBlock(existing, overrides && Object.hasOwn(overrides as object, "agents") ? profile.agents : profile.agents || readFileSync(join(TEMPLATES, "AGENTS.block.md"), "utf8"));
288
+ // #1399: one source for the block. A shipped profile's `agents` is only its addition, appended to the template; a project's own `profile_overrides.agents` still replaces the whole block.
289
+ const shipped = readFileSync(join(TEMPLATES, "AGENTS.block.md"), "utf8");
290
+ const template = rolesTracked(cwd, existing, settings) ? shipped : shipped.replace(ROLES_TRACKED, ROLES_UNTRACKED);
291
+ const hubBlock = upsertBlock(existing, overrides && Object.hasOwn(overrides as object, "agents") ? profile.agents : profile.agents ? `${template.trim()}\n\n${profile.agents}` : template);
216
292
  const instructions = specsBlock(hubBlock, specsEnabled(cwd, settings)); // #1064 T3: a project that turned specs off keeps no block
217
293
  write(agents, guarded ? releaseBlock(instructions) : instructions, "refresh hub instructions; preserve surrounding text", existing.includes("<!-- AGENT_HUB:BEGIN") ? "replace" : "insert");
218
294
  const claude = join(cwd, "CLAUDE.md");
@@ -227,18 +303,31 @@ function changes(cwd: string, requestedName?: string, shadow = false, releaseGua
227
303
  }
228
304
  const ignore = join(cwd, ".gitignore");
229
305
  let lines = existsSync(ignore) ? readFileSync(ignore, "utf8") : "";
230
- for (const entry of [".agenthub/state/", ".agenthub/config.local.json", ".agenthub/routing.local.toml", ...(shadow ? [".agenthub/shadow.git/"] : [])]) {
231
- if (!lines.split("\n").includes(entry)) lines = `${lines}${lines && !lines.endsWith("\n") ? "\n" : ""}${entry}\n`;
232
- }
233
- if (existsSync(join(cwd, KIMI_MCP_FILE)) && hubGitSync(["ls-files", "--error-unmatch", "--", KIMI_MCP_FILE], { cwd, encoding: "utf8", timeout: 3000 }).status !== 0 && !lines.split("\n").includes(KIMI_MCP_FILE)) lines = `${lines}${lines && !lines.endsWith("\n") ? "\n" : ""}${KIMI_MCP_FILE}\n`;
306
+ // #1411 AC6: git decides whether a path is already ignored (a broader rule, .git/info/exclude, the person's global file); the line check covers no repository and lines added in this run.
307
+ const add = (entry: string) => {
308
+ if (lines.split("\n").includes(entry) || ignoreRule(cwd, entry)) return;
309
+ lines = `${lines}${lines && !lines.endsWith("\n") ? "\n" : ""}${entry}\n`;
310
+ };
311
+ for (const entry of [".agenthub/state/", ".agenthub/config.local.json", ".agenthub/routing.local.toml", ...(shadow ? [".agenthub/shadow.git/"] : [])]) add(entry);
312
+ if (existsSync(join(cwd, KIMI_MCP_FILE)) && hubGitSync(["ls-files", "--error-unmatch", "--", KIMI_MCP_FILE], { cwd, encoding: "utf8", timeout: 3000 }).status !== 0) add(KIMI_MCP_FILE);
234
313
  const agyPlugin = ".agents/plugins/agent-hub/";
235
314
  if (existsSync(join(cwd, agyPlugin))) {
236
315
  const tracked = new Set(hubGitSync(["ls-files", "--", agyPlugin], { cwd, encoding: "utf8", timeout: 3000 }).stdout.trim().split("\n").filter(Boolean));
237
- const entries = tracked.size ? AGY_PLUGIN_FILES.filter(file => !tracked.has(file)) : [agyPlugin];
238
- for (const entry of entries) if (!lines.split("\n").includes(entry)) lines = `${lines}${lines && !lines.endsWith("\n") ? "\n" : ""}${entry}\n`;
316
+ for (const entry of tracked.size ? AGY_PLUGIN_FILES.filter(file => !tracked.has(file)) : [agyPlugin]) add(entry);
239
317
  }
240
- if (existsSync(join(cwd, JCODE_MCP_FILE)) && hubGitSync(["ls-files", "--error-unmatch", "--", JCODE_MCP_FILE], { cwd, encoding: "utf8", timeout: 3000 }).status !== 0 && !lines.split("\n").includes(JCODE_MCP_FILE)) lines = `${lines}${lines && !lines.endsWith("\n") ? "\n" : ""}${JCODE_MCP_FILE}\n`;
241
- write(ignore, lines, "ignore runtime state and machine-local configuration");
318
+ if (existsSync(join(cwd, JCODE_MCP_FILE)) && hubGitSync(["ls-files", "--error-unmatch", "--", JCODE_MCP_FILE], { cwd, encoding: "utf8", timeout: 3000 }).status !== 0) add(JCODE_MCP_FILE);
319
+ // #1411: the shared config. Tracked: a rule that ignores one of the files is named and nothing is written (AC3), except a routing.toml that names a machine endpoint,
320
+ // which stays ignored until the local overlay can hold it. Untracked: each file is ignored unless git already ignores it.
321
+ const track = settings?.values[TRACK_CONFIG];
322
+ if (track === true) {
323
+ for (const name of SHARED_CONFIG) {
324
+ const path = `.agenthub/${name}`;
325
+ if (name === "routing.toml" && routingMachineKeys(cwd).length) { add(path); continue; }
326
+ const rule = ignoreRule(cwd, path);
327
+ if (rule) throw new Error(`--track-config: ${path} is ignored by ${rule}; change that line so git sees the file (after a directory rule such as .agenthub/, add !/.agenthub/, /.agenthub/* and !/${path}), then run ahub init again; nothing was written`);
328
+ }
329
+ } else if (track === false) for (const name of SHARED_CONFIG) add(`.agenthub/${name}`);
330
+ if (lines || existsSync(ignore)) write(ignore, lines, track === false ? "ignore runtime state, machine-local configuration and the per-checkout hub config" : "ignore runtime state and machine-local configuration");
242
331
  // #1065 T1: the settings table. config.json is the text it will have after the template and pack writes above; the rest is what is on disk.
243
332
  let settingRows: InitSettingRow[] = [];
244
333
  if (settings && (Object.keys(settings.values).length)) {
@@ -317,19 +406,54 @@ export function withInitResearch(cwd: string, request: InitSettingsRequest, mach
317
406
  if (existsSync(join(cwd, ".agenthub", "config.json")) || Object.hasOwn(request.values, "research.enabled") || !initResearchDefault(cwd, machineValue)) return request;
318
407
  return { ...request, values: { ...request.values, "research.enabled": true } };
319
408
  }
409
+ /** Read only the bounded frontmatter prefix; a GSD archive is evidence, never an init input to execute or rewrite. */
410
+ function gsdPlanningState(cwd: string): boolean {
411
+ let fd: number | undefined;
412
+ try {
413
+ if (!lstatSync(join(cwd, ".planning")).isDirectory()) return false;
414
+ fd = openSync(join(cwd, ".planning", "STATE.md"), constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
415
+ if (!fstatSync(fd).isFile()) return false;
416
+ const prefix = Buffer.alloc(4096), size = readSync(fd, prefix, 0, prefix.length, 0);
417
+ const header = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(prefix.toString("utf8", 0, size));
418
+ return !!header && /^gsd_state_version:[ \t]*["']?[0-9]+(?:\.[0-9]+)*["']?[ \t]*(?:#.*)?$/m.test(header[1]!);
419
+ } catch { return false; }
420
+ finally { if (fd !== undefined) closeSync(fd); }
421
+ }
320
422
  /** Prepare person guidance before writes; the CLI prints it only after successful apply. Creates no lifecycle evidence or acceptance. */
321
423
  export function initNextSteps(cwd: string, settings?: InitSettingsRequest): string[] {
322
- const lines = [
323
- "Next steps:",
324
- "- Review and commit AGENTS.md, .agenthub/config.json and other shared init changes; keep config.local.json untracked.",
325
- "- Start with ahub up or ahub claude; sessions started otherwise miss hub pushes.",
326
- ];
424
+ const track = settings?.values[TRACK_CONFIG];
327
425
  const mode = settings?.values["sdlc.mode"] ?? loadSdlc(cwd, VERSION).mode;
426
+ const lines = ["Next steps:"];
427
+ // An ignore line does not untrack a file git already has: name the command that does.
428
+ const committed = (names: readonly string[]) => names.map(name => `.agenthub/${name}`).filter(path => hubGitSync(["ls-files", "--error-unmatch", "--", path], { cwd, encoding: "utf8", timeout: 3000 }).status === 0);
429
+ const untrack = (paths: string[]) => { if (paths.length) lines.push(`- ${paths.join(", ")} ${paths.length === 1 ? "is" : "are"} still committed: run git rm --cached ${paths.join(" ")} and commit, or git keeps tracking ${paths.length === 1 ? "it" : "them"}.`); };
430
+ const agentsPath = join(cwd, "AGENTS.md");
431
+ // The words follow the block's role sentence, so the next steps never contradict it (a project with neither flag whose config git ignores gets the untracked sentence).
432
+ if (track === false || track === undefined && !rolesTracked(cwd, existsSync(agentsPath) ? readFileSync(agentsPath, "utf8") : "", settings)) {
433
+ lines.push("- Review and commit AGENTS.md. .agenthub/config.json, routing.toml and sdlc.toml stay untracked: each checkout and each machine holds its own roles.");
434
+ untrack(committed(SHARED_CONFIG));
435
+ } else if (track === true) {
436
+ // #1411: the files to commit, and what must not go in with them.
437
+ const endpoints = routingMachineKeys(cwd);
438
+ const files = SHARED_CONFIG.filter(name => !(name === "routing.toml" && endpoints.length) && (name !== "sdlc.toml" || existsSync(join(cwd, ".agenthub", name)) || mode !== "off"));
439
+ lines.push(`- Review and commit AGENTS.md and ${files.map(name => `.agenthub/${name}`).join(", ")}; keep config.local.json untracked.`);
440
+ if (endpoints.length) { lines.push(`- .agenthub/routing.toml stays untracked: ${endpoints.join(", ")} names this machine's endpoint, and routing.local.toml cannot hold it yet.`); untrack(committed(["routing.toml"])); }
441
+ const personal = personalValues(cwd);
442
+ if (personal.length) lines.push(`- Before the first commit, move ${personal.join(", ")} from .agenthub/config.json to .agenthub/config.local.json: they are this machine's values, and the hub ignores them in a committed config.json.`);
443
+ } else lines.push("- Review and commit AGENTS.md, .agenthub/config.json and other shared init changes; keep config.local.json untracked.");
444
+ lines.push(
445
+ "- Your own settings go in .agenthub/config.local.json; it wins over config.json key by key.",
446
+ "- Start with ahub up or ahub claude; sessions started otherwise miss hub pushes.",
447
+ );
448
+ // #1408 T2: what each role choice means, for a choice that changed nothing too (AC5: `none` and `person` are described, not only accepted).
449
+ lines.push(...roleSummaryLines(settings?.values ?? {}));
328
450
  if (mode !== "off") lines.push(
329
451
  `- SDLC ${mode}: accept the planner-recorded spec with ahub sdlc accept <task> --issue <n>.`,
330
452
  "- When a plan departure needs your consent: ahub sdlc accept-departure <task> <head> <reason...>.",
331
453
  "- After hub_task_done on the open PR, reviewer approval and green exact-head CI, use guarded merge: ahub sdlc merge <task>.",
332
454
  );
455
+ if (["advise", "enforce"].includes(String(settings?.values["sdlc.mode"])) && gsdPlanningState(cwd))
456
+ lines.push("- GSD planning state found: see docs/sdlc.md#moving-from-gsd before migrating; archive .planning/ and retain its evidence.");
333
457
  return lines;
334
458
  }
335
459
  /** Returns the paths it changed, applying the same plan as the preview. */