@staix/agent-hub 0.49.1 → 0.51.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 (99) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +1 -1
  3. package/docs/adding-an-ai-tool.md +2 -2
  4. package/docs/agent-notes/README.md +1 -0
  5. package/docs/agent-notes/adapters.md +3 -3
  6. package/docs/agent-notes/daemon.md +1 -1
  7. package/docs/agent-notes/local-worker.md +3 -3
  8. package/docs/agent-notes/tasks.md +5 -1
  9. package/docs/design/adapters.md +17 -0
  10. package/docs/design/agent-hub.md +1 -1
  11. package/docs/design/cli-output-inventory.md +24 -19
  12. package/docs/design/cli-output.md +1 -1
  13. package/docs/design/roadmap.md +2 -2
  14. package/docs/design/task-board.md +34 -0
  15. package/docs/dogfood.md +8 -3
  16. package/docs/operations.md +53 -4
  17. package/docs/quickstart.md +26 -2
  18. package/docs/roadmap.json +20 -20
  19. package/docs/roadmap.md +2 -2
  20. package/docs/sdlc.md +3 -2
  21. package/docs/specs/2026-09-19-agent-hub-design.md +1 -0
  22. package/docs/verification/2026-11-29-0.50.0.md +54 -0
  23. package/docs/verification/2026-11-29-agy-1.5.20.md +33 -0
  24. package/docs/verification/2026-11-29-claude-profile-hook.md +12 -0
  25. package/docs/verification/2026-11-29-idle-daemon-footprint.md +75 -0
  26. package/docs/verification/2026-11-29-kimi-281-reviewer-compat.md +38 -0
  27. package/docs/verification/2026-11-29-kimi-tui-281.md +12 -0
  28. package/docs/verification/2026-11-30-0.51.0.md +91 -0
  29. package/docs/verification/2026-11-30-account-switch-1806.md +445 -0
  30. package/docs/verified.json +31 -27
  31. package/package.json +1 -1
  32. package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
  33. package/plugins/agent-hub/kimi-hook.js +1329 -24629
  34. package/plugins/agent-hub/server.js +638 -414
  35. package/scripts/check-docs.mjs +1 -1
  36. package/src/adapters/acp.ts +13 -13
  37. package/src/adapters/agy/definition.ts +2 -2
  38. package/src/adapters/agy/entry.ts +2 -0
  39. package/src/adapters/claude-channel-evidence.ts +7 -3
  40. package/src/adapters/compat.ts +4 -3
  41. package/src/adapters/definitions/builtin-metadata.ts +2 -2
  42. package/src/adapters/definitions/native-cli-claude-launch.ts +3 -1
  43. package/src/adapters/definitions/native-cli-entry-claude.ts +17 -2
  44. package/src/adapters/definitions/native-cli-entry-codex.ts +2 -0
  45. package/src/adapters/definitions/native-cli-entry-jcode.ts +2 -0
  46. package/src/adapters/definitions/native-cli-entry-kimi.ts +2 -0
  47. package/src/adapters/definitions/native-cli-entry-pi.ts +2 -0
  48. package/src/adapters/definitions/native-cli-entry-qwen.ts +2 -0
  49. package/src/adapters/definitions/native-cli-entry-types.ts +3 -1
  50. package/src/adapters/definitions/native-cli-jcode-home-init.ts +1 -1
  51. package/src/adapters/definitions/native-cli-preview-common.ts +1 -1
  52. package/src/adapters/definitions/native-config-defaults.ts +1 -1
  53. package/src/adapters/jcode.ts +16 -0
  54. package/src/adapters/native-facts-hooks.ts +12 -0
  55. package/src/cli/autonomy-offline.ts +1 -1
  56. package/src/cli/bench.ts +1 -1
  57. package/src/cli/claude-profile-hook.ts +31 -11
  58. package/src/cli/commands/releases.ts +82 -0
  59. package/src/cli/conductor-recovery.ts +1 -1
  60. package/src/cli/facts-hook.ts +11 -4
  61. package/src/cli/help.ts +12 -10
  62. package/src/cli/identity.ts +5 -1
  63. package/src/cli/init-prompt.ts +1 -1
  64. package/src/cli/init-settings.ts +4 -35
  65. package/src/cli/init.ts +1 -1
  66. package/src/cli/json-text-spans.ts +57 -0
  67. package/src/cli/launch-check.ts +157 -0
  68. package/src/cli/launch.ts +19 -1
  69. package/src/cli/main.ts +63 -10
  70. package/src/cli/memory.ts +1 -1
  71. package/src/cli/output.ts +14 -1
  72. package/src/cli/preview.ts +1 -1
  73. package/src/cli/recovery-launch.ts +1 -1
  74. package/src/cli/setup-homes.ts +2 -2
  75. package/src/cli/start-agents-run.ts +85 -7
  76. package/src/cli/start-check.ts +28 -0
  77. package/src/cli/upgrade-runtime.ts +1 -1
  78. package/src/cli/warn-line.ts +1 -1
  79. package/src/hub/ci-watch.ts +311 -79
  80. package/src/hub/config-apply.ts +1 -1
  81. package/src/hub/config.ts +518 -0
  82. package/src/hub/control-client.ts +1 -1
  83. package/src/hub/daemon.ts +76 -513
  84. package/src/hub/delivery-public.ts +11 -0
  85. package/src/hub/hub-check.ts +125 -0
  86. package/src/hub/path-policy.ts +1 -1
  87. package/src/hub/permission-mode.ts +3 -40
  88. package/src/hub/permission-paths.ts +41 -0
  89. package/src/hub/recovery-policy.ts +1 -1
  90. package/src/hub/releases-inventory.ts +198 -0
  91. package/src/hub/runtime-capture-prune.ts +25 -3
  92. package/src/hub/runtime-prune-health.ts +8 -1
  93. package/src/hub/sdlc-release-authorization.ts +42 -21
  94. package/src/hub/sdlc-release-diagnostics.ts +5 -0
  95. package/src/hub/sdlc-release-policy.ts +21 -7
  96. package/src/hub/sdlc-release.ts +80 -20
  97. package/src/hub/sdlc.ts +7 -3
  98. package/src/hub/tasks.ts +138 -36
  99. package/src/ui/plugin.ts +1 -1
@@ -2,7 +2,7 @@ import { releaseTrackedClean } from "./release-worktree.ts";
2
2
  import { createHash, randomUUID } from "node:crypto";
3
3
  import { USER, type PeerId } from "./envelope.ts";
4
4
  import { hubGitEnv, hubGitSync } from "./git.ts";
5
- import { readDocEvidenceDetailed, type DocEvidence, type ReleaseGit, type ReleaseReadiness, type ReleaseReportPolicy } from "./sdlc-release.ts";
5
+ import { documentationRefusal, readDocEvidenceDetailed, verifiedProjectChecker, type DocEvidence, type ReleaseGit, type ReleaseReadiness, type ReleaseReportPolicy } from "./sdlc-release.ts";
6
6
  import { DEFAULT_RELEASE_POLICY, hasCommittedReleaseNotes, type ReleasePolicy } from "./sdlc-release-policy.ts";
7
7
  import type { SdlcGh } from "./sdlc.ts";
8
8
  import type { ReleaseGuardRequest, ReleasePushUpdate } from "../cli/sdlc-release-guard.ts";
@@ -13,7 +13,7 @@ export const releaseAuthorizationError = (error: unknown): string => error insta
13
13
  const SHA = /^[0-9a-f]{40}$/;
14
14
  const VERSION = /^[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
15
15
  export const validReleaseVersion = (value: unknown): value is string => typeof value === "string" && value.length <= 128 && VERSION.test(value);
16
- export interface ReleaseDocsVerdict { fresh: true; errors: 0; documents: number; digest: string }
16
+ export interface ReleaseDocsVerdict { fresh: true; errors: 0; documents: number; digest: string; checker?: string }
17
17
  export type ReleaseDocsReceipt = ReleaseDocsVerdict | ({ source: "none" } & { fresh?: never; errors?: never; documents?: never; digest?: never });
18
18
  export interface ReleaseAuthorization { schemaVersion: 1; id: string; by: PeerId; commit: string; version: string; at: number; docs: ReleaseDocsReceipt }
19
19
  export interface ReleaseAuthorizationPorts {
@@ -34,12 +34,12 @@ export type ReleaseGuardVerdict = { ok: true; receipts: ReleaseAuthorization[] }
34
34
  interface Origin { hash: string; urls: string[]; repo?: string }
35
35
  interface Entry { receipt: ReleaseAuthorization; origin: Origin; policy: ReleasePolicy; order: number }
36
36
  const digest = (value: unknown) => createHash("sha256").update(JSON.stringify(value)).digest("hex");
37
- function docsVerdict(value: DocEvidence | undefined, commit: string, version: string): ReleaseDocsVerdict | undefined {
37
+ function docsVerdict(value: DocEvidence | undefined, commit: string, version: string, checker?: string): ReleaseDocsVerdict | undefined {
38
38
  if (!value || value.schemaVersion !== 1 || value.head !== commit || value.version !== version || value.fresh !== true || value.errors !== 0
39
39
  || !Array.isArray(value.documents) || value.documents.length > 128 || value.documents.some(row => row.state !== "fresh" || row.dirty === true)) return;
40
40
  // Paths may be withheld in a public release report; the commit binds their identities, not this projection.
41
41
  const rows = value.documents.map(({ state, verifiedAgainst, commits, dirty }) => ({ state, verifiedAgainst, commits, dirty })).map(row => JSON.stringify(row)).sort();
42
- return { fresh: true, errors: 0, documents: rows.length, digest: digest({ commit, version, rows }) };
42
+ return { fresh: true, errors: 0, documents: rows.length, digest: digest({ commit, version, rows, ...(checker ? { checker } : {}) }), ...(checker ? { checker } : {}) };
43
43
  }
44
44
  function githubRepo(url: string): string | undefined {
45
45
  const match = url.match(/^(?:https:\/\/github\.com\/|git@github\.com:|ssh:\/\/git@github\.com\/)([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+?)(?:\.git)?\/?$/);
@@ -54,12 +54,6 @@ export class ReleaseAuthorizations {
54
54
  constructor(private readonly root: string, private readonly ports: ReleaseAuthorizationPorts) {}
55
55
  private current(): void { if (this.ports.current?.() === false) throw new ReleaseAuthorizationError("release authorization unavailable during lifecycle transition"); }
56
56
  /** #1120: a checker that is missing or failed is its own refusal; only evidence that is read and not fresh is "stale documentation". An injected reader keeps its undefined meaning (no evidence). */
57
- private async docs(commit: string, version: string): Promise<ReleaseDocsVerdict | undefined> {
58
- if (this.ports.docs) return docsVerdict(await this.ports.docs(this.root), commit, version);
59
- const read = await readDocEvidenceDetailed(this.root, undefined, this.ports.checker);
60
- if ("unavailable" in read) throw new ReleaseAuthorizationError(`release authorization needs the documentation checker: ${read.unavailable}`);
61
- return docsVerdict(read.evidence, commit, version);
62
- }
63
57
  private actor(by: PeerId): void {
64
58
  if (by !== USER && (typeof by !== "string" || !by.trim() || this.ports.conductor?.() !== by)) throw new ReleaseAuthorizationError("only the person or the configured conductor may authorize a release");
65
59
  }
@@ -131,8 +125,25 @@ export class ReleaseAuthorizations {
131
125
  if (!hasCommittedReleaseNotes(git, commit, path)) throw new ReleaseAuthorizationError(`committed release notes missing: ${path}; add ${path} at the candidate commit`);
132
126
  return requested;
133
127
  }
134
- private docsPolicy(commit: string, policy: ReleasePolicy, version: string): Promise<ReleaseDocsReceipt | undefined> {
135
- return policy.docs.source === "none" ? Promise.resolve({ source: "none" }) : this.docs(commit, version);
128
+ private async docsPolicy(commit: string, policy: ReleasePolicy, version: string): Promise<ReleaseDocsReceipt> {
129
+ if (policy.docs.source === "none") return { source: "none" };
130
+ const command = policy.docs.source === "command" ? policy.docs : undefined;
131
+ let evidence: DocEvidence | undefined;
132
+ if (this.ports.docs && !command) evidence = await this.ports.docs(this.root);
133
+ else {
134
+ const read = await readDocEvidenceDetailed(this.root, undefined, command ?? this.ports.checker);
135
+ if ("unavailable" in read) throw new ReleaseAuthorizationError(`release authorization needs the documentation checker: ${read.unavailable}`);
136
+ evidence = read.evidence;
137
+ }
138
+ const verdict = docsVerdict(evidence, commit, version, command && `command:${command.path}@${command.blob}`);
139
+ if (!verdict) {
140
+ let cause = "";
141
+ if (evidence && (evidence.head !== commit || evidence.version !== version)) cause = " checker reported a different head or version.";
142
+ else if (evidence?.documents.some(row => row.state === "nonancestor")) cause = " a documentation stamp is nonancestor.";
143
+ else if (evidence?.documents.some(row => row.state === "stale" || row.dirty === true)) cause = " documentation is stale or dirty.";
144
+ throw new ReleaseAuthorizationError(`release authorization requires fresh committed documentation evidence:${cause} ${await documentationRefusal(this.root, evidence, command)}`);
145
+ }
146
+ return verdict;
136
147
  }
137
148
  async authorize(by: string, version: unknown, expectedCommit: unknown): Promise<ReleaseAuthorization> {
138
149
  this.actor(by);
@@ -145,7 +156,6 @@ export class ReleaseAuthorizations {
145
156
  ? `committed package.json version is ${sourceVersion}, not ${version}; set release.version in .agenthub/config.json to release-notes or none, or update package.json and commit it`
146
157
  : "candidate version differs from the person's request for the configured source");
147
158
  const docs = await this.docsPolicy(commit, policy, version);
148
- if (!docs) throw new ReleaseAuthorizationError("release authorization requires fresh committed documentation evidence: run `node scripts/check-docs.mjs --committed` in the candidate checkout, restamp the stale documents in a committed change, then authorize again");
149
159
  this.current(); this.actor(by);
150
160
  const currentPolicy = this.policy(git, commit);
151
161
  if (this.commit(git, "HEAD") !== commit || JSON.stringify(currentPolicy) !== JSON.stringify(policy) || this.version(git, commit, currentPolicy, version) !== version || this.origin(git).hash !== origin.hash) throw new ReleaseAuthorizationError("release candidate or committed release policy changed during authorization");
@@ -166,13 +176,14 @@ export class ReleaseAuthorizations {
166
176
  let policy: ReleasePolicy;
167
177
  try { policy = this.policy(git, head); } catch { return unavailable(); }
168
178
  if (policy.version.source === "package.json" && policy.docs.source === "checker") return;
179
+ const checker = policy.docs.source === "command" ? { checker: policy.docs } : {};
169
180
  let packageVersion: string | undefined;
170
181
  if (policy.version.source === "package.json") {
171
182
  try { packageVersion = this.packageVersion(git, head, policy); } catch { return unavailable(policy.version.source, policy.docs.source); }
172
183
  }
173
184
  let origin: Origin;
174
185
  try {
175
- if (this.commit(git, "HEAD") !== head) return { versionSource: policy.version.source, docsSource: policy.docs.source, authorization: "stale", ...(packageVersion ? { version: packageVersion } : {}) };
186
+ if (this.commit(git, "HEAD") !== head) return { ...checker, versionSource: policy.version.source, docsSource: policy.docs.source, authorization: "stale", ...(packageVersion ? { version: packageVersion } : {}) };
176
187
  origin = this.origin(git);
177
188
  } catch { return unavailable(policy.version.source, policy.docs.source); }
178
189
  const candidates = [...this.entries.values()].filter(entry => entry.receipt.commit === head
@@ -180,20 +191,27 @@ export class ReleaseAuthorizations {
180
191
  && JSON.stringify(entry.policy) === JSON.stringify(policy)
181
192
  && (packageVersion === undefined || entry.receipt.version === packageVersion));
182
193
  const entry = candidates.reduce<Entry | undefined>((latest, current) => !latest || current.order > latest.order ? current : latest, undefined);
183
- if (!entry) return { versionSource: policy.version.source, docsSource: policy.docs.source, authorization: "missing", ...(packageVersion ? { version: packageVersion } : {}) };
194
+ if (!entry) {
195
+ const prior = this.latest;
196
+ const stale = prior && (policy.docs.source === "command" || prior.policy.docs.source === "command")
197
+ && prior.origin.hash === origin.hash && prior.origin.repo?.toLowerCase() === repo.toLowerCase()
198
+ && JSON.stringify(prior.policy.docs) !== JSON.stringify(policy.docs);
199
+ return { ...checker, versionSource: policy.version.source, docsSource: policy.docs.source,
200
+ authorization: stale ? "stale" : "missing", ...(packageVersion ? { version: packageVersion } : {}) };
201
+ }
184
202
  const version = policy.version.source === "package.json" ? packageVersion : entry.receipt.version;
185
- if (!version || !validReleaseVersion(version) || entry.receipt.version !== version) return { versionSource: policy.version.source, docsSource: policy.docs.source, authorization: "stale" };
203
+ if (!version || !validReleaseVersion(version) || entry.receipt.version !== version) return { ...checker, versionSource: policy.version.source, docsSource: policy.docs.source, authorization: "stale" };
186
204
  if (policy.version.source === "release-notes") {
187
205
  const notes = policy.version.notesPath.replace("{version}", version);
188
- if (!hasCommittedReleaseNotes(git, head, notes)) return { versionSource: policy.version.source, docsSource: policy.docs.source, authorization: "stale" };
206
+ if (!hasCommittedReleaseNotes(git, head, notes)) return { ...checker, versionSource: policy.version.source, docsSource: policy.docs.source, authorization: "stale" };
189
207
  }
190
208
  if (policy.docs.source === "none" ? !("source" in entry.receipt.docs) : !("digest" in entry.receipt.docs)) {
191
- return { versionSource: policy.version.source, docsSource: policy.docs.source, authorization: "stale" };
209
+ return { ...checker, versionSource: policy.version.source, docsSource: policy.docs.source, authorization: "stale" };
192
210
  }
193
211
  try {
194
- if (this.commit(git, "HEAD") !== head || this.origin(git).hash !== origin.hash) return { versionSource: policy.version.source, docsSource: policy.docs.source, authorization: "stale" };
212
+ if (this.commit(git, "HEAD") !== head || this.origin(git).hash !== origin.hash) return { ...checker, versionSource: policy.version.source, docsSource: policy.docs.source, authorization: "stale" };
195
213
  } catch { return unavailable(policy.version.source, policy.docs.source); }
196
- return { versionSource: policy.version.source, docsSource: policy.docs.source, authorization: "matched", version };
214
+ return { ...checker, versionSource: policy.version.source, docsSource: policy.docs.source, authorization: "matched", version };
197
215
  }
198
216
  private matched(git: ReleaseGit, version: string, commit: string, remote?: string, url?: string): ReleaseAuthorization {
199
217
  this.current();
@@ -201,6 +219,8 @@ export class ReleaseAuthorizations {
201
219
  if (!entry) throw new ReleaseAuthorizationError("no matching person release authorization; ask the person to authorize this commit and version");
202
220
  const policy = this.policy(git, commit);
203
221
  if (JSON.stringify(policy) !== JSON.stringify(entry.policy)) throw new ReleaseAuthorizationError("committed release policy differs from the authorized candidate");
222
+ if (policy.docs.source === "command" && !verifiedProjectChecker(this.root, policy.docs))
223
+ throw new ReleaseAuthorizationError(`project documentation checker ${policy.docs.path} differs from the candidate commit; restore it before running ahub sdlc authorize-release`);
204
224
  const candidateVersion = this.version(git, commit, policy, version);
205
225
  if (candidateVersion !== version) {
206
226
  if (!this.ports.policy) throw new ReleaseAuthorizationError("no matching person release authorization; ask the person to authorize this commit and version");
@@ -278,7 +298,8 @@ export class ReleaseAuthorizations {
278
298
  try {
279
299
  if (matched) {
280
300
  const git = this.git(), candidatePolicy = this.policy(git, entry!.receipt.commit);
281
- const verdict = report.documents ? docsVerdict(report.documents, report.head, report.version) : undefined;
301
+ const verdict = report.documents ? docsVerdict(report.documents, report.head, report.version, candidatePolicy.docs.source === "command"
302
+ ? `command:${candidatePolicy.docs.path}@${candidatePolicy.docs.blob}` : undefined) : undefined;
282
303
  matched = JSON.stringify(candidatePolicy) === JSON.stringify(entry!.policy)
283
304
  && ("source" in entry!.receipt.docs ? candidatePolicy.docs.source === "none" : !!verdict && verdict.digest === entry!.receipt.docs.digest)
284
305
  && this.origin(git).hash === entry!.origin.hash;
@@ -0,0 +1,5 @@
1
+ import { terminalText } from "../cli/console-state.ts";
2
+
3
+ export function releaseDiagnostic(message: string): string {
4
+ return terminalText(message);
5
+ }
@@ -4,7 +4,7 @@ export type ReleaseVersionPolicy =
4
4
  | { source: "package.json" }
5
5
  | { source: "release-notes"; notesPath: string }
6
6
  | { source: "none" };
7
- export type ReleaseDocsPolicy = { source: "checker" } | { source: "none" };
7
+ export type ReleaseDocsPolicy = { source: "checker" } | { source: "none" } | { source: "command"; path: string; blob?: string };
8
8
  export interface ReleasePolicy { version: ReleaseVersionPolicy; docs: ReleaseDocsPolicy }
9
9
 
10
10
  export const DEFAULT_RELEASE_POLICY: ReleasePolicy = {
@@ -40,12 +40,21 @@ export function parseReleasePolicy(config: unknown): ReleasePolicy {
40
40
  throw new Error("release.version in committed .agenthub/config.json must be package.json, release-notes or none");
41
41
  }
42
42
  const rawDocs = release.docs === undefined ? "checker" : release.docs;
43
- if (rawDocs !== "checker" && rawDocs !== "none") throw new Error("release.docs in committed .agenthub/config.json must be checker or none");
43
+ let docs: ReleaseDocsPolicy;
44
+ if (rawDocs === "checker" || rawDocs === "none") docs = { source: rawDocs };
45
+ else {
46
+ const command = record(rawDocs), path = command?.command;
47
+ if (!command || Object.keys(command).length !== 1 || typeof path !== "string" || path.length > 1024
48
+ || /[\p{Cc}\\:*?\[\]]/u.test(path) || path.split("/").some(part => !part || part === "." || part === ".." || part.startsWith("-"))) {
49
+ throw new Error('release.docs in committed .agenthub/config.json must be checker, none or { "command": "<safe repository-relative path>" }');
50
+ }
51
+ docs = { source: "command", path };
52
+ }
44
53
  const notesPath = checkedNotesPath(release.notesPath === undefined ? DEFAULT_RELEASE_NOTES_PATH : release.notesPath);
45
54
  return {
46
55
  version: rawVersion === "release-notes" ? { source: rawVersion, notesPath }
47
56
  : rawVersion === "none" ? { source: rawVersion } : { source: rawVersion },
48
- docs: rawDocs === "none" ? { source: rawDocs } : { source: rawDocs },
57
+ docs,
49
58
  };
50
59
  }
51
60
 
@@ -61,15 +70,15 @@ function treeEntry(git: ReleaseGit, commit: string, path: string): TreeEntry | u
61
70
  return { mode: match[1]!, type: match[2]!, oid: match[3]!, path: match[4]! };
62
71
  }
63
72
 
64
- function regularBlob(git: ReleaseGit, commit: string, path: string): boolean {
73
+ function regularBlob(git: ReleaseGit, commit: string, path: string): TreeEntry | undefined {
65
74
  const parts = path.split("/");
66
75
  for (let index = 1; index < parts.length; index++) {
67
76
  const parent = parts.slice(0, index).join("/");
68
77
  const entry = treeEntry(git, commit, parent);
69
- if (!entry || entry.mode !== "040000" || entry.type !== "tree") return false;
78
+ if (!entry || entry.mode !== "040000" || entry.type !== "tree") return undefined;
70
79
  }
71
80
  const file = treeEntry(git, commit, path);
72
- return !!file && (file.mode === "100644" || file.mode === "100755") && file.type === "blob";
81
+ return file && (file.mode === "100644" || file.mode === "100755") && file.type === "blob" ? file : undefined;
73
82
  }
74
83
 
75
84
  /** Read policy only from the candidate commit. Missing shared config means the legacy defaults; unreadable data fails closed. */
@@ -91,10 +100,15 @@ export function readCommittedReleasePolicy(git: ReleaseGit, commit: string): Rel
91
100
  if (policy.docs.source === "none" && regularBlob(git, commit, "docs/verified.json")) {
92
101
  throw new Error("release.docs is none but the candidate commits docs/verified.json; remove release.docs from .agenthub/config.json or delete the manifest, then authorize again");
93
102
  }
103
+ if (policy.docs.source === "command") {
104
+ const file = regularBlob(git, commit, policy.docs.path);
105
+ if (!file) throw new Error(`project checker ${policy.docs.path} must be a regular file at the candidate commit; commit the checker and authorize again`);
106
+ return { ...policy, docs: { ...policy.docs, blob: file.oid } };
107
+ }
94
108
  return policy;
95
109
  }
96
110
 
97
111
  /** Ensure every directory component and the final notes path are committed as non-symlink tree/blob entries. */
98
112
  export function hasCommittedReleaseNotes(git: ReleaseGit, commit: string, path: string): boolean {
99
- try { return regularBlob(git, commit, path); } catch { return false; }
113
+ try { return !!regularBlob(git, commit, path); } catch { return false; }
100
114
  }
@@ -1,10 +1,13 @@
1
1
  import type { Task } from "./board.ts";
2
2
  import type { Release } from "./planning.ts";
3
3
  import { spawn } from "node:child_process";
4
- import { existsSync } from "node:fs";
4
+ import { existsSync, lstatSync } from "node:fs";
5
+ import { dirname, join } from "node:path";
5
6
  import { fileURLToPath } from "node:url";
6
7
  import { childEnv, stopOwnedProcess } from "./child-process.ts";
7
- import { hubGitSync } from "./git.ts";
8
+ import { hubGitSync, hubGitEnv } from "./git.ts";
9
+ import { realPath } from "./project.ts";
10
+ import type { ReleaseDocsPolicy } from "./sdlc-release-policy.ts";
8
11
  import type { SdlcGh } from "./sdlc.ts";
9
12
  // Standalone document evidence does not need lifecycle/review code; load the default remote reader only when used.
10
13
  let importDiagnosticShown = false;
@@ -21,15 +24,18 @@ const sdlcGh: SdlcGh = async (...args) => {
21
24
  try { return await reader.sdlcGh(...args); }
22
25
  catch { return { code: 1, stdout: "" }; }
23
26
  };
24
- export interface DocEvidence { schemaVersion: 1; head?: string; version?: string; documents: { path?: string; state: "fresh" | "stale" | "nonancestor" | "unknown"; verifiedAgainst?: string; commits?: number; dirty?: boolean }[]; errors: number; fresh: boolean; }
27
+ export interface DocEvidence { schemaVersion: 1; head?: string; version?: string; documents: { path?: string; state: "fresh" | "stale" | "nonancestor" | "unknown"; verifiedAgainst?: string; commits?: number; dirty?: boolean }[]; errors: number; fresh: boolean; messages?: string[]; }
25
28
  export type ReleaseReportSource = "package.json" | "release-notes" | "none" | "unknown";
26
- export type ReleaseReportDocsSource = "checker" | "none" | "unknown";
29
+ export type ReleaseReportDocsSource = "checker" | "none" | "command" | "unknown";
30
+ type ProjectChecker = Extract<ReleaseDocsPolicy, { source: "command" }>;
27
31
  export type ReleaseReportAuthorizationState = "matched" | "missing" | "stale" | "unavailable";
28
32
  export interface ReleaseReportPolicy {
29
33
  versionSource: ReleaseReportSource;
30
34
  docsSource: ReleaseReportDocsSource;
31
35
  authorization: ReleaseReportAuthorizationState;
32
36
  version?: string;
37
+ /** Host-only checker selection. Public readiness copies only the policy summary. */
38
+ checker?: ProjectChecker;
33
39
  }
34
40
  export interface ReleaseReadiness { /** #1403 A4: the newest security audit as counts only (ref, profile, partial, unit states, finding tallies); never a path, a finding or a blocker. */ securityAudit?: import("./security-audit.ts").AuditSummary; /** #481 AC12: interval, approval-to-release lead time and hotfix rate over shipped releases, filled by Tasks.releaseReadiness. */ releaseMetrics?: ReturnType<typeof releaseMetrics>; releasePolicy?: ReleaseReportPolicy; repo: string; head?: string; version?: string; tag?: string; tagCommit?: string; commits: string[]; mergedPrs: { pr: number; commit: string }[]; documents?: DocEvidence; liveIssues: { id: number; state: "open" | "closed" | "unknown" }[]; blockers: string[]; sourceReady: boolean; native: "unverified"; ready: false; }
35
41
  export type ReleaseGit = (args: string[]) => { code: number; stdout: string };
@@ -43,32 +49,70 @@ function tagMatches(target: unknown, commit: string): boolean {
43
49
  const oid = parsed?.oid ?? parsed?.target?.oid;
44
50
  return typeof oid === "string" && SHA.test(oid) && oid === commit;
45
51
  }
46
- /** Package-owned checker only; no caller-supplied program or document text is executed. */
52
+ /** The bundled checker or the candidate's verified regular project checker may run. */
47
53
  /** #1120: why no evidence could be read, apart from evidence that says the documents are stale. */
48
54
  export type DocEvidenceRead = { evidence: DocEvidence } | { unavailable: string };
49
55
  const CHECKER_PATH = fileURLToPath(new URL("../../scripts/check-docs.mjs", import.meta.url));
50
- const CHECKER_MISSING = "the documentation checker scripts/check-docs.mjs is missing from the running hub, which predates the fix that carries it into captured runtimes; record consent from a hub started from a checkout or a release that carries the checker (docs/sdlc.md, release preparation)";
51
- const CHECKER_FAILED = "the documentation checker in the running hub did not finish with readable evidence (it timed out, crashed or printed unreadable output); run `node scripts/check-docs.mjs --json --committed` in the candidate checkout to see why, then retry";
56
+ const CHECKER_MISSING = "the documentation checker scripts/check-docs.mjs is missing from the running hub (bundled checker); record consent from a hub started from a checkout or a release that carries the checker (docs/sdlc.md, release preparation)";
57
+ function checkerName(command?: ProjectChecker): string {
58
+ return command ? `project checker ${command.path}` : "bundled checker";
59
+ }
60
+
61
+ async function checkerCommand(root: string, command?: ProjectChecker): Promise<string> {
62
+ const { shellQuote } = await import("../cli/shell-quote.ts");
63
+ return command
64
+ ? `cd ${shellQuote(root)} && ${shellQuote(process.execPath)} ${shellQuote(join(root, command.path))} ${shellQuote(root)} --json --committed`
65
+ : `cd ${shellQuote(dirname(dirname(CHECKER_PATH)))} && node scripts/check-docs.mjs --json --committed ${shellQuote(root)}`;
66
+ }
67
+
68
+ export async function documentationRefusal(root: string, evidence?: DocEvidence, command?: ProjectChecker): Promise<string> {
69
+ const message = evidence?.messages?.[0];
70
+ const reason = message ? (await import("./sdlc-release-diagnostics.ts")).releaseDiagnostic(message) : undefined;
71
+ return `${checkerName(command)}${reason ? `: ${reason}` : ""}; run \`${await checkerCommand(root, command)}\`, restamp the stale documents in a committed change, then authorize again`;
72
+ }
73
+
74
+ export function verifiedProjectChecker(root: string, command: ProjectChecker): string | undefined {
75
+ if (!command.blob || !SHA.test(command.blob)) return;
76
+ try {
77
+ const canonical = realPath(root), path = join(canonical, command.path);
78
+ if (realPath(path) !== path || !lstatSync(path).isFile()) return;
79
+ const hash = hubGitSync(["hash-object", "--no-filters", "--", path], {
80
+ cwd: canonical, env: hubGitEnv(process.env, { repositoryIsolation: true }), encoding: "utf8",
81
+ timeout: 1000, maxBuffer: 1024,
82
+ });
83
+ if (hash.status === 0 && hash.stdout?.trim() === command.blob) return path;
84
+ } catch { /* unavailable checkout evidence */ }
85
+ }
52
86
  export async function readDocEvidence(root: string, timeoutMs = 10_000): Promise<DocEvidence | undefined> {
53
87
  const read = await readDocEvidenceDetailed(root, timeoutMs);
54
88
  return "evidence" in read ? read.evidence : undefined;
55
89
  }
56
- export function readDocEvidenceDetailed(root: string, timeoutMs = 10_000, checker = CHECKER_PATH): Promise<DocEvidenceRead> {
57
- if (!existsSync(checker)) return Promise.resolve({ unavailable: CHECKER_MISSING });
58
- return new Promise(resolve => {
59
- const child = spawn(process.execPath, [checker, root, "--json", "--committed"], { cwd: root, env: childEnv(), detached: true, stdio: ["ignore", "pipe", "ignore"] });
90
+ export async function readDocEvidenceDetailed(root: string, timeoutMs = 10_000, checker: string | ProjectChecker = CHECKER_PATH): Promise<DocEvidenceRead> {
91
+ const command = typeof checker === "string" ? undefined : checker;
92
+ const program = typeof checker === "string" ? checker : verifiedProjectChecker(root, checker);
93
+ if (!program) return Promise.resolve({ unavailable: `project documentation checker ${command!.path} differs from the candidate commit; restore it before running ahub sdlc authorize-release` });
94
+ if (!existsSync(program) && !command) return Promise.resolve({ unavailable: CHECKER_MISSING });
95
+ const failureMessage = async () => `${checkerName(command)} did not finish with readable evidence (it timed out, crashed or printed unreadable output); run \`${await checkerCommand(root, command)}\` to see why, then retry`;
96
+ return new Promise((resolve, reject) => {
97
+ const failed = () => { void failureMessage().then(unavailable => resolve({ unavailable }), reject); };
98
+ const child = spawn(process.execPath, [program, root, "--json", "--committed"], { cwd: root, env: childEnv(), detached: true, stdio: ["ignore", "pipe", "ignore"] });
60
99
  let output = "", invalid = false;
61
100
  const stop = () => { invalid = true; void stopOwnedProcess(child, { group: true }).catch(() => {}); };
62
101
  const timer = setTimeout(stop, Math.max(1, Math.min(10_000, timeoutMs)));
63
102
  child.stdout?.setEncoding("utf8"); child.stdout?.on("data", chunk => { output += chunk; if (Buffer.byteLength(output) > 256 * 1024) { output = ""; stop(); } });
64
- child.once("error", () => { invalid = true; clearTimeout(timer); resolve({ unavailable: CHECKER_FAILED }); });
103
+ child.once("error", () => { invalid = true; clearTimeout(timer); failed(); });
65
104
  child.once("close", (code, signal) => {
66
- clearTimeout(timer); if (invalid || signal || (code !== 0 && code !== 1)) return resolve({ unavailable: CHECKER_FAILED });
105
+ clearTimeout(timer); if (invalid || signal || (code !== 0 && code !== 1)) return failed();
67
106
  try {
68
107
  const data = JSON.parse(output);
69
- if (data.schemaVersion !== 1 || !Array.isArray(data.documents) || data.documents.length > 128 || !Number.isSafeInteger(data.errors) || data.errors < 0 || typeof data.fresh !== "boolean" || (data.head !== undefined && !SHA.test(data.head)) || (data.version !== undefined && !VERSION.test(data.version)) || data.documents.some((d: {state?:string}) => !["fresh","stale","nonancestor","unknown"].includes(d.state ?? ""))) return resolve({ unavailable: CHECKER_FAILED });
108
+ if (data.schemaVersion !== 1 || !Array.isArray(data.documents) || data.documents.length > 128 || !Number.isSafeInteger(data.errors) || data.errors < 0 || typeof data.fresh !== "boolean" || (data.head !== undefined && !SHA.test(data.head)) || (data.version !== undefined && !VERSION.test(data.version)) || data.documents.some((d: {state?:string}) => !["fresh","stale","nonancestor","unknown"].includes(d.state ?? ""))) return failed();
109
+ if (data.messages !== undefined && (!Array.isArray(data.messages) || data.messages.length > 3
110
+ || data.messages.some((message: unknown) => typeof message !== "string" || message.length > 300)))
111
+ return failed();
112
+ if (command && (!data.head || !data.version || data.documents.some((row: DocEvidence["documents"][number]) => typeof row.dirty !== "boolean")))
113
+ return failed();
70
114
  resolve({ evidence: data });
71
- } catch { resolve({ unavailable: CHECKER_FAILED }); }
115
+ } catch { failed(); }
72
116
  });
73
117
  });
74
118
  }
@@ -152,10 +196,25 @@ export async function readReleaseReadiness(root: string, repo: string, liveIssue
152
196
  const skipDocs = report.releasePolicy?.docsSource === "none" || report.releasePolicy?.authorization === "unavailable"
153
197
  || !!report.releasePolicy && report.releasePolicy.versionSource !== "package.json" && report.releasePolicy.authorization !== "matched";
154
198
  const left = deadline - performance.now();
155
- report.documents = !skipDocs && left > 0 ? await (readers.docs ?? ((dir, ms) => readDocEvidenceDetailed(dir, ms, readers.checker).then(read => "evidence" in read ? read.evidence : undefined)))(root,Math.min(10_000,left)) : undefined;
156
- const checkerMissing = !skipDocs && !readers.docs && !existsSync(readers.checker ?? CHECKER_PATH); // #1120: a hub without the checker says so instead of calling the documents stale
157
- if (checkerMissing) report.blockers.push("documentation checker unavailable in the running hub: " + CHECKER_MISSING);
158
- else if (!skipDocs && (!report.documents || report.documents.head !== head || !report.documents.fresh || report.documents.errors || report.documents.documents.some(d => d.state !== "fresh"))) report.blockers.push("documentation freshness or ancestry is unknown or stale");
199
+ const command = releasePolicy?.checker;
200
+ let unavailable: string | undefined;
201
+ if (!skipDocs && left > 0) {
202
+ if (releasePolicy?.docsSource === "command" && !command) unavailable = "project checker identity unavailable; commit the checker and authorize again";
203
+ else if (readers.docs && !command) report.documents = await readers.docs(root, Math.min(10_000, left));
204
+ else {
205
+ const read = await readDocEvidenceDetailed(root, Math.min(10_000, left), command ?? readers.checker);
206
+ if ("unavailable" in read) unavailable = read.unavailable;
207
+ else report.documents = read.evidence;
208
+ }
209
+ }
210
+ if (unavailable) report.blockers.push("documentation checker unavailable in the running hub: " + unavailable);
211
+ else if (!skipDocs && (!report.documents || report.documents.head !== head || command && report.documents.version !== report.version
212
+ || !report.documents.fresh || report.documents.errors || report.documents.documents.some(d => d.state !== "fresh" || command && d.dirty))) {
213
+ report.blockers.push(command || report.documents?.messages?.length
214
+ ? `documentation freshness or ancestry is unknown or stale: ${await documentationRefusal(root, report.documents, command)}`
215
+ : "documentation freshness or ancestry is unknown or stale");
216
+ }
217
+ if (report.documents) delete report.documents.messages;
159
218
  if (!liveIssues.length) report.blockers.push("native verification ledger unspecified");
160
219
  for (const id of liveIssues) {
161
220
  const reply = await gh(["issue","view",String(id),"--repo",repo,"--json","number,state"]); let state: "open"|"closed"|"unknown" = "unknown";
@@ -193,7 +252,8 @@ export async function readReleaseReadiness(root: string, repo: string, liveIssue
193
252
  try { current = readers.reportPolicy(head, repo); } catch { /* a report recheck failure is stale authorization */ }
194
253
  const prior = report.releasePolicy;
195
254
  if (!current || current.authorization !== "matched" || current.versionSource !== prior.versionSource
196
- || current.docsSource !== prior.docsSource || current.version !== report.version) {
255
+ || current.docsSource !== prior.docsSource || current.version !== report.version
256
+ || JSON.stringify(current.checker) !== JSON.stringify(command)) {
197
257
  report.releasePolicy = { ...prior, authorization: "stale" };
198
258
  if (prior.versionSource !== "package.json") report.version = undefined;
199
259
  report.sourceReady = false;
package/src/hub/sdlc.ts CHANGED
@@ -47,7 +47,7 @@ export const AUTO_MERGE_MODES: readonly AutoMergeMode[] = ["off", "dry-run", "on
47
47
  export interface SecurityScanConfig { everyH: number; sources: SecuritySource[]; repo?: string }
48
48
  /** #786: one repository's own gate: its required checks (before the top-level list) and its own merge mode. */
49
49
  export interface RepoMergePolicy { requiredChecks?: string[]; autoMerge?: AutoMergeMode }
50
- export interface SdlcConfig { workflow?: "gsd-lite"; maxNits?: number; /** #481 S7: optional control bands per metric; absent means none. */ bands?: BandsConfig; /** #481 S7: the scheduled security-scan baseline; absent means none is scheduled. */ securityScan?: SecurityScanConfig; /** #481 S5: the one check a configuration PR needs; no default, the person names it. */ evalCheck?: string; /** #481 S5: patterns that mark a PR as a configuration change; absent reads as the defaults in eval-gate.ts, an empty list turns the gate off. */ configPaths?: string[]; /** #1403 A2: sensitive paths that need a recorded security pass, and the review companions that apply; absent means the feature is off. */ security?: SecurityPolicy; /** #1645 T1: paths that make a filed change high or low; absent means no tier is derived and nothing else changes. */ risk?: RiskPolicy; mode: SdlcMode; requiredChecks: string[]; /** #786: absent reads as "off"; written only when the file names it. */ autoMerge?: AutoMergeMode; /** #786: per-repository tables, keyed by lowercase owner/name. */ repos?: Record<string, RepoMergePolicy>; stages: SdlcStage[]; definitions?: Record<string, StageDefinition>; deprecations?: string[]; }
50
+ export interface SdlcConfig { workflow?: "gsd-lite"; maxNits?: number; /** #481 S7: optional control bands per metric; absent means none. */ bands?: BandsConfig; /** #481 S7: the scheduled security-scan baseline; absent means none is scheduled. */ securityScan?: SecurityScanConfig; /** #481 S5: the one check a configuration PR needs; no default, the person names it. */ evalCheck?: string; /** #481 S5: patterns that mark a PR as a configuration change; absent reads as the defaults in eval-gate.ts, an empty list turns the gate off. */ configPaths?: string[]; /** #1403 A2: sensitive paths that need a recorded security pass, and the review companions that apply; absent means the feature is off. */ security?: SecurityPolicy; /** #1645 T1: paths that make a filed change high or low; absent means no tier is derived and nothing else changes. */ risk?: RiskPolicy; mode: SdlcMode; requiredChecks: string[]; ciShardRetries?: number; /** #786: absent reads as "off"; written only when the file names it. */ autoMerge?: AutoMergeMode; /** #786: per-repository tables, keyed by lowercase owner/name. */ repos?: Record<string, RepoMergePolicy>; stages: SdlcStage[]; definitions?: Record<string, StageDefinition>; deprecations?: string[]; }
51
51
  export interface PlanReviewReceipt {
52
52
  planner: string;
53
53
  planAuthor?: string | null;
@@ -213,7 +213,11 @@ export function sdlcConfig(value: unknown, version?: string): SdlcConfig {
213
213
  if (value === undefined) return { mode: "off", requiredChecks: [], stages: [...SDLC_STAGES] };
214
214
  if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("sdlc: expected a table");
215
215
  const raw = value as Record<string, unknown>;
216
- for (const key of Object.keys(raw)) if (!["mode", "required_checks", "stages", "workflow", "definitions", "max_nits", "bands", "auto_merge", "repos", "eval_check", "config_paths", "security_scan", "security", "risk"].includes(key)) throw new Error(`sdlc.${key}: unknown field`);
216
+ for (const key of Object.keys(raw)) if (!["mode", "required_checks", "stages", "workflow", "definitions", "max_nits", "bands", "auto_merge", "repos", "eval_check", "config_paths", "security_scan", "security", "risk", "ci_shard_retries"].includes(key)) throw new Error(`sdlc.${key}: unknown field`);
217
+ const ciShardRetries = raw.ci_shard_retries;
218
+ if (ciShardRetries !== undefined && (typeof ciShardRetries !== "number" || !Number.isSafeInteger(ciShardRetries) || ciShardRetries < 0 || ciShardRetries > 3)) {
219
+ throw new Error("sdlc.ci_shard_retries: expected an integer from 0 to 3; set it in .agenthub/sdlc.toml and restart the hub (0 disables automatic retries)");
220
+ }
217
221
  const maxNits = raw.max_nits === undefined ? DEFAULT_MAX_NITS : raw.max_nits;
218
222
  if (typeof maxNits !== "number" || !Number.isSafeInteger(maxNits) || maxNits < 0 || maxNits > 64) throw new Error("sdlc.max_nits: expected an integer from 0 to 64");
219
223
  const bands = bandsConfig(raw.bands), bandConfig = Object.keys(bands).length ? { bands } : {};
@@ -233,7 +237,7 @@ export function sdlcConfig(value: unknown, version?: string): SdlcConfig {
233
237
  const phaseAlias = { allowed: window, used: false };
234
238
  const checks = checkList(raw.required_checks ?? [], "sdlc.required_checks");
235
239
  // #786: absent keys add nothing to the config, so the off-mode default keeps its #257 shape byte for byte.
236
- const mergeConfig = { ...(raw.auto_merge === undefined ? {} : { autoMerge: autoMergeMode(raw.auto_merge, "sdlc.auto_merge") }), ...(raw.repos === undefined ? {} : { repos: mergeRepos(raw.repos)! }) };
240
+ const mergeConfig = { ...(ciShardRetries === undefined ? {} : { ciShardRetries }), ...(raw.auto_merge === undefined ? {} : { autoMerge: autoMergeMode(raw.auto_merge, "sdlc.auto_merge") }), ...(raw.repos === undefined ? {} : { repos: mergeRepos(raw.repos)! }) };
237
241
  if (raw.definitions !== undefined) {
238
242
  const custom = definitions(raw.definitions, raw.stages, phaseAlias);
239
243
  if (phaseAlias.used) notes.push(`the sdlc phase gate is deprecated and stops loading in ${RETIRED_WORKFLOW_FROM} (#481): name it criteria`);