@staix/agent-hub 0.50.0 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/README.md +1 -1
- package/docs/adding-an-ai-tool.md +26 -4
- package/docs/agent-notes/README.md +1 -0
- package/docs/agent-notes/adapters.md +4 -3
- package/docs/agent-notes/budget.md +8 -2
- package/docs/agent-notes/daemon.md +13 -8
- package/docs/agent-notes/local-worker.md +3 -3
- package/docs/agent-notes/security-review.md +6 -5
- package/docs/agent-notes/tasks.md +10 -3
- package/docs/agent-notes/tests.md +4 -3
- package/docs/cooperbench.md +1 -1
- package/docs/design/adapters.md +21 -0
- package/docs/design/cli-output-inventory.md +165 -150
- package/docs/design/cli-output.md +4 -3
- package/docs/design/guidance-probes.md +1 -0
- package/docs/design/roadmap.md +3 -1
- package/docs/design/task-board.md +35 -0
- package/docs/dogfood.md +21 -3
- package/docs/events.md +4 -2
- package/docs/memory.md +5 -3
- package/docs/operations.md +259 -19
- package/docs/quickstart.md +29 -2
- package/docs/roadmap.json +20 -20
- package/docs/roadmap.md +2 -2
- package/docs/roles.md +1 -1
- package/docs/sdlc.md +29 -5
- package/docs/security.md +11 -5
- package/docs/specs/2026-09-19-agent-hub-design.md +44 -0
- package/docs/specs/2026-09-19-multi-project-design.md +4 -0
- package/docs/specs/2026-09-20-upgrade-recovery-design.md +17 -0
- package/docs/specs/mcp-endpoint.md +63 -0
- package/docs/verification/2026-11-29-agy-1.5.20.md +33 -0
- package/docs/verification/2026-11-29-claude-profile-hook.md +12 -0
- package/docs/verification/2026-11-29-idle-daemon-footprint.md +75 -0
- package/docs/verification/2026-11-29-kimi-281-reviewer-compat.md +38 -0
- package/docs/verification/2026-11-29-kimi-tui-281.md +12 -0
- package/docs/verification/2026-11-30-0.51.0.md +91 -0
- package/docs/verification/2026-11-30-account-switch-1806.md +445 -0
- package/docs/verification/2026-11-30-capability-listing-shape-1808.md +45 -0
- package/docs/verification/2026-11-30-upgrade-keep-1807.md +174 -0
- package/docs/verification/2026-12-01-1811-confirmation-receipt.md +19 -0
- package/docs/verification/2026-12-01-1811-orca-agent-list.md +20 -0
- package/docs/verification/2026-12-01-1811-orca-pane-key.md +21 -0
- package/docs/verification/2026-12-02-1819-claude-process-after-renewal.md +54 -0
- package/docs/verification/2026-12-02-agy-1.5.21.md +74 -0
- package/docs/verification/2026-12-02-claude-implementer-2.1.334.md +44 -0
- package/docs/verification/2026-12-02-cli-import-graph.md +33 -0
- package/docs/verification/2026-12-03-0.52.0.md +150 -0
- package/docs/verification/2026-12-03-codex-0173-reviewer-isolation.md +53 -0
- package/docs/verification/2026-12-03-codex-0173-reviewer-tool-call.md +34 -0
- package/docs/verification/2026-12-03-jcode-1.3.0.md +25 -0
- package/docs/verification/agy/README.md +17 -0
- package/docs/verification/agy/cli-surface.ts +68 -0
- package/docs/verification/agy/interactive-bridge.ts +92 -0
- package/docs/verification/agy/interactive-session.ts +131 -0
- package/docs/verification/agy/launcher-nonce.ts +215 -0
- package/docs/verification/agy/native-hooks.ts +210 -0
- package/docs/verification/agy/originals/agent-hub-681/cli-surface.ts +87 -0
- package/docs/verification/agy/originals/agent-hub-681/native-hooks-adapted.ts +91 -0
- package/docs/verification/agy/originals/agent-hub-681/tui-actual.ts +200 -0
- package/docs/verification/agy/originals/agent-hub-684/probe.ts +107 -0
- package/docs/verification/agy/originals.json +25 -0
- package/docs/verification/agy/permission-new-functions.ts +128 -0
- package/docs/verification/agy/run-probe.py +108 -0
- package/docs/verification/agy/runtime.ts +171 -0
- package/docs/verification/agy/tmux-helper-control.ts +6 -0
- package/docs/verification/agy/tmux-session.ts +235 -0
- package/docs/verified.json +87 -42
- package/package.json +3 -3
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/compat.json +157 -0
- package/plugins/agent-hub/kimi-hook.js +1416 -24985
- package/plugins/agent-hub/server.js +17415 -32755
- package/scripts/check-docs.mjs +1 -1
- package/src/adapters/acp.ts +13 -13
- package/src/adapters/agy/definition.ts +9 -26
- package/src/adapters/agy/entry.ts +2 -0
- package/src/adapters/channel-peer.ts +3 -1
- package/src/adapters/claude-channel-evidence.ts +7 -3
- package/src/adapters/claude-channel.ts +38 -257
- package/src/adapters/claude-implementer.ts +3 -1
- package/src/adapters/codex-appserver.ts +77 -15
- package/src/adapters/compat.ts +78 -14
- package/src/adapters/configured-acp.ts +23 -163
- package/src/adapters/configured-adapter-policy.ts +160 -0
- package/src/adapters/configured-pull-entry.ts +53 -0
- package/src/adapters/configured-pull.ts +38 -0
- package/src/adapters/conformance/fakes/app-server.ts +9 -2
- package/src/adapters/declaration-catalog.ts +25 -0
- package/src/adapters/declaration-data.ts +342 -0
- package/src/adapters/declaration-resolution.ts +53 -0
- package/src/adapters/definitions/builtin-metadata.ts +62 -84
- package/src/adapters/definitions/jcode-launch.ts +13 -0
- package/src/adapters/definitions/native-adapter-policy.ts +390 -0
- package/src/adapters/definitions/native-cli-claude-launch.ts +6 -3
- package/src/adapters/definitions/native-cli-codex-launch.ts +2 -1
- package/src/adapters/definitions/native-cli-entry-claude.ts +17 -2
- package/src/adapters/definitions/native-cli-entry-codex.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-jcode.ts +6 -2
- package/src/adapters/definitions/native-cli-entry-kimi.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-pi.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-qwen.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-types.ts +12 -3
- package/src/adapters/definitions/native-cli-jcode-home-init.ts +1 -1
- package/src/adapters/definitions/native-cli-launch-common.ts +2 -2
- package/src/adapters/definitions/native-cli-preview-common.ts +1 -1
- package/src/adapters/definitions/native-cli-retained.ts +1 -1
- package/src/adapters/definitions/native-config-defaults.ts +1 -1
- package/src/adapters/definitions/native-configuration.ts +18 -0
- package/src/adapters/definitions/native-help.ts +24 -0
- package/src/adapters/definitions/native-launch-declarations.ts +34 -0
- package/src/adapters/definitions/native-launch-policy.ts +4 -0
- package/src/adapters/definitions/native-launch-settings.ts +72 -0
- package/src/adapters/definitions/native-light-cli.ts +18 -0
- package/src/adapters/definitions/native-light-preview.ts +10 -0
- package/src/adapters/definitions/native-wrapper-launch.ts +10 -0
- package/src/adapters/definitions/qwen.ts +6 -29
- package/src/adapters/definitions/reviewer-variants.ts +7 -8
- package/src/adapters/external-declarations.ts +31 -0
- package/src/adapters/external-modules.ts +4 -29
- package/src/adapters/jcode.ts +19 -12
- package/src/adapters/native-capabilities.ts +18 -8
- package/src/adapters/native-facts-hooks.ts +12 -0
- package/src/adapters/native-proof-ports.ts +1 -1
- package/src/adapters/presets.ts +136 -0
- package/src/adapters/qwen-dual.ts +2 -2
- package/src/adapters/registry-types.ts +3 -0
- package/src/adapters/registry.ts +20 -81
- package/src/adapters/reviewer-print.ts +26 -9
- package/src/adapters/role-eligibility.ts +2 -1
- package/src/cli/accounts-import.ts +72 -0
- package/src/cli/agents-latest-table.ts +88 -0
- package/src/cli/agents-latest.ts +22 -0
- package/src/cli/agents-output.ts +10 -0
- package/src/cli/agents-presets.ts +100 -0
- package/src/cli/agents.ts +1 -1
- package/src/cli/attention.ts +3 -2
- package/src/cli/autonomy-homes.ts +7 -2
- package/src/cli/autonomy-offline.ts +1 -1
- package/src/cli/bench.ts +1 -1
- package/src/cli/budget-renew-guidance.ts +129 -0
- package/src/cli/claude-homes.ts +9 -5
- package/src/cli/claude-profile-hook.ts +31 -11
- package/src/cli/command-context.ts +3 -0
- package/src/cli/command-table.ts +123 -0
- package/src/cli/commands/accounts.ts +8 -0
- package/src/cli/commands/agents.ts +18 -0
- package/src/cli/commands/answer.ts +28 -0
- package/src/cli/commands/ask.ts +17 -0
- package/src/cli/commands/autonomy.ts +83 -0
- package/src/cli/commands/backlog.ts +46 -0
- package/src/cli/commands/bench.ts +60 -0
- package/src/cli/commands/board.ts +48 -0
- package/src/cli/commands/broker.ts +9 -0
- package/src/cli/commands/budget.ts +96 -0
- package/src/cli/commands/capabilities.ts +12 -0
- package/src/cli/commands/check-path.ts +55 -0
- package/src/cli/commands/completion.ts +8 -0
- package/src/cli/commands/console.ts +12 -0
- package/src/cli/commands/daemon.ts +8 -0
- package/src/cli/commands/deliverables.ts +25 -0
- package/src/cli/commands/doctor.ts +249 -0
- package/src/cli/commands/down.ts +3 -0
- package/src/cli/commands/export.ts +15 -0
- package/src/cli/commands/facts.ts +15 -0
- package/src/cli/commands/goal.ts +22 -0
- package/src/cli/commands/guidance.ts +102 -0
- package/src/cli/commands/help.ts +17 -0
- package/src/cli/commands/host.ts +45 -0
- package/src/cli/commands/init.ts +121 -0
- package/src/cli/commands/instructed.ts +19 -0
- package/src/cli/commands/instruction-hook.ts +15 -0
- package/src/cli/commands/intake.ts +24 -0
- package/src/cli/commands/kill.ts +15 -0
- package/src/cli/commands/learn.ts +23 -0
- package/src/cli/commands/lineage.ts +30 -0
- package/src/cli/commands/logs.ts +21 -0
- package/src/cli/commands/manager.ts +15 -0
- package/src/cli/commands/memory.ts +21 -0
- package/src/cli/commands/model.ts +25 -0
- package/src/cli/commands/models.ts +40 -0
- package/src/cli/commands/native.ts +39 -0
- package/src/cli/commands/pause.ts +5 -0
- package/src/cli/commands/peer.ts +32 -0
- package/src/cli/commands/permission.ts +26 -0
- package/src/cli/commands/permit.ts +12 -0
- package/src/cli/commands/pet.ts +24 -0
- package/src/cli/commands/projects.ts +49 -0
- package/src/cli/commands/queue.ts +70 -0
- package/src/cli/commands/recovery-run.ts +13 -0
- package/src/cli/commands/recovery.ts +130 -0
- package/src/cli/commands/release.ts +23 -0
- package/src/cli/commands/releases.ts +91 -0
- package/src/cli/commands/remember.ts +6 -0
- package/src/cli/commands/report.ts +27 -0
- package/src/cli/commands/research.ts +53 -0
- package/src/cli/commands/reset.ts +89 -0
- package/src/cli/commands/restart.ts +5 -0
- package/src/cli/commands/results.ts +31 -0
- package/src/cli/commands/resume.ts +5 -0
- package/src/cli/commands/review.ts +24 -0
- package/src/cli/commands/roadmap.ts +21 -0
- package/src/cli/commands/role.ts +34 -0
- package/src/cli/commands/roles.ts +30 -0
- package/src/cli/commands/room.ts +14 -0
- package/src/cli/commands/roster.ts +48 -0
- package/src/cli/commands/route.ts +9 -0
- package/src/cli/commands/say.ts +21 -0
- package/src/cli/commands/schedule.ts +17 -0
- package/src/cli/commands/sdlc.ts +321 -0
- package/src/cli/commands/settings.ts +148 -0
- package/src/cli/commands/setup.ts +89 -0
- package/src/cli/commands/shared-refusals.ts +25 -0
- package/src/cli/commands/smoke.ts +44 -0
- package/src/cli/commands/source.ts +64 -0
- package/src/cli/commands/specs.ts +13 -0
- package/src/cli/commands/status.ts +28 -0
- package/src/cli/commands/stop.ts +17 -0
- package/src/cli/commands/structure.ts +60 -0
- package/src/cli/commands/study.ts +39 -0
- package/src/cli/commands/tail.ts +19 -0
- package/src/cli/commands/task.ts +114 -0
- package/src/cli/commands/title.ts +17 -0
- package/src/cli/commands/turns.ts +10 -0
- package/src/cli/commands/ui.ts +47 -0
- package/src/cli/commands/undo.ts +77 -0
- package/src/cli/commands/up.ts +39 -0
- package/src/cli/commands/upgrade.ts +5 -0
- package/src/cli/commands/usage.ts +33 -0
- package/src/cli/commands/version.ts +5 -0
- package/src/cli/commands/watch.ts +30 -0
- package/src/cli/commands/worktrees.ts +31 -0
- package/src/cli/conductor-recovery.ts +1 -1
- package/src/cli/console-state.ts +5 -138
- package/src/cli/console-versions.ts +1 -1
- package/src/cli/facts-hook.ts +11 -4
- package/src/cli/help.ts +44 -20
- package/src/cli/identity.ts +27 -4
- package/src/cli/init-prompt.ts +1 -1
- package/src/cli/init-settings.ts +4 -35
- package/src/cli/init.ts +1 -1
- package/src/cli/json-text-spans.ts +57 -0
- package/src/cli/launch-check.ts +156 -0
- package/src/cli/launch.ts +19 -70
- package/src/cli/light-dispatch.ts +29 -0
- package/src/cli/main.js +8 -1
- package/src/cli/main.ts +257 -2799
- package/src/cli/memory.ts +1 -1
- package/src/cli/orca-probe.ts +119 -0
- package/src/cli/output.ts +45 -3
- package/src/cli/preview.ts +11 -6
- package/src/cli/recovery-launch.ts +1 -1
- package/src/cli/recovery-version-preflight.ts +28 -9
- package/src/cli/replace-process.ts +22 -0
- package/src/cli/report-layout.ts +142 -0
- package/src/cli/roadmap-usage.ts +16 -0
- package/src/cli/roadmap.ts +3 -16
- package/src/cli/sdlc-doctor.ts +27 -0
- package/src/cli/sdlc-output.ts +55 -1
- package/src/cli/setup-homes.ts +2 -2
- package/src/cli/start-agents-run.ts +85 -7
- package/src/cli/start-check.ts +28 -0
- package/src/cli/statusline-tee.ts +25 -4
- package/src/cli/terminal-recovery.ts +53 -10
- package/src/cli/upgrade-interactive.ts +1 -0
- package/src/cli/upgrade-runtime.ts +12 -1
- package/src/cli/upgrade.ts +4 -15
- package/src/cli/warn-line.ts +1 -1
- package/src/hub/accounts.ts +148 -0
- package/src/hub/addons.ts +20 -0
- package/src/hub/agent-drift.ts +2 -1
- package/src/hub/budget-projection.ts +39 -7
- package/src/hub/budget.ts +231 -16
- package/src/hub/channel-project.ts +3 -3
- package/src/hub/ci-watch.ts +311 -79
- package/src/hub/conductor-peer.ts +24 -0
- package/src/hub/conductor.ts +2 -21
- package/src/hub/config-apply.ts +25 -14
- package/src/hub/config-edit.ts +1 -1
- package/src/hub/config-tier.ts +2 -0
- package/src/hub/config.ts +535 -0
- package/src/hub/control-client.ts +49 -1
- package/src/hub/daemon.ts +492 -569
- package/src/hub/delivery-public.ts +11 -0
- package/src/hub/events.ts +3 -0
- package/src/hub/home-tag.ts +12 -0
- package/src/hub/host.ts +217 -0
- package/src/hub/hub-check.ts +125 -0
- package/src/hub/hub-tools.ts +2 -1
- package/src/hub/instance-budget.ts +2 -2
- package/src/hub/instance-config.ts +15 -126
- package/src/hub/instances.ts +22 -6
- package/src/hub/instruction-receipt.ts +2 -2
- package/src/hub/kimi-usage.ts +38 -11
- package/src/hub/lifecycle.ts +86 -4
- package/src/hub/mcp-bridge-core.ts +98 -0
- package/src/hub/mcp-channel-push.ts +20 -0
- package/src/hub/mcp-endpoint-serve.ts +178 -0
- package/src/hub/mcp-endpoint.ts +226 -0
- package/src/hub/mcp-tool-call.ts +181 -0
- package/src/hub/operational-settings.ts +2 -0
- package/src/hub/orca-env.ts +6 -0
- package/src/hub/orca-state.ts +84 -0
- package/src/hub/path-policy.ts +1 -1
- package/src/hub/peers.ts +5 -1
- package/src/hub/permission-mode.ts +5 -41
- package/src/hub/permission-paths.ts +41 -0
- package/src/hub/project.ts +20 -0
- package/src/hub/protocol-window.ts +58 -0
- package/src/hub/quota-origin.ts +20 -0
- package/src/hub/recovery-policy.ts +1 -1
- package/src/hub/registry.ts +36 -2
- package/src/hub/releases-inventory.ts +198 -0
- package/src/hub/report.ts +1 -1
- package/src/hub/research.ts +1 -1
- package/src/hub/review-brief.ts +47 -2
- package/src/hub/roster.ts +6 -3
- package/src/hub/routing.ts +9 -2
- package/src/hub/runtime-capture-prune.ts +25 -3
- package/src/hub/runtime-prune-health.ts +8 -1
- package/src/hub/sdlc-check.ts +205 -0
- package/src/hub/sdlc-release-authorization.ts +42 -21
- package/src/hub/sdlc-release-diagnostics.ts +5 -0
- package/src/hub/sdlc-release-policy.ts +21 -7
- package/src/hub/sdlc-release.ts +80 -20
- package/src/hub/sdlc-sync.ts +146 -0
- package/src/hub/sdlc.ts +38 -5
- package/src/hub/settings.ts +7 -4
- package/src/hub/start-agents.ts +1 -1
- package/src/hub/start-mode.ts +11 -4
- package/src/hub/structure-budget.ts +131 -0
- package/src/hub/structure-scan.ts +149 -0
- package/src/hub/tasks-experiment.ts +455 -0
- package/src/hub/tasks-guidance.ts +606 -0
- package/src/hub/tasks-roadmap-plan.ts +419 -0
- package/src/hub/tasks-roadmap.ts +491 -0
- package/src/hub/tasks-study.ts +661 -0
- package/src/hub/tasks-survey.ts +192 -0
- package/src/hub/tasks.ts +457 -2584
- package/src/hub/terminal-open.ts +5 -3
- package/src/hub/tooling.ts +3 -19
- package/src/hub/usage-rollup.ts +9 -3
- package/src/local/tools.ts +5 -0
- package/src/ui/index.html +1 -1
- package/src/ui/needs.ts +17 -5
- package/src/ui/peer-palette.ts +2 -4
- package/src/ui/plugin.ts +1 -1
- package/templates/presets/agents.json +60 -0
- package/templates/presets/confirmation-matrix.json +8 -8
package/src/hub/review-brief.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { checkStructureBudget, updateStructureBaseline, type StructureRules } from "./structure-budget.ts";
|
|
3
|
+
import { parseStructureBaseline, scanStructureRevision } from "./structure-scan.ts";
|
|
1
4
|
import type { CodeFactResult, CodeSymbol } from "./code-facts.ts";
|
|
2
5
|
import { sanitize } from "./envelope.ts";
|
|
3
6
|
import { childEnv } from "./child-process.ts";
|
|
@@ -47,6 +50,7 @@ export interface ReviewBrief {
|
|
|
47
50
|
unlisted: string[];
|
|
48
51
|
/** #1645 T4: the tier this head was filed at and what it still owes, already rendered by `risk-tier.ts`; absent without a `[risk]` table. */
|
|
49
52
|
risk?: string;
|
|
53
|
+
structure?: string[];
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
/** A bounded, public summary of the design specs affected by one exact task head. */
|
|
@@ -64,7 +68,7 @@ export function renderSpecTaskReport(report: SpecTaskReport): string {
|
|
|
64
68
|
if (report.complete && report.errors === 0 && report.unchanged.length === 0 && report.changed.length === 0) lines.push("No covering specs were found for the changed files.");
|
|
65
69
|
return sanitize(lines.join("\n"));
|
|
66
70
|
}
|
|
67
|
-
export interface BriefPolicy { privatePath(path: string): boolean; nameable(text: string): boolean }
|
|
71
|
+
export interface BriefPolicy { privatePath(path: string): boolean; nameable(text: string): boolean; structureRules?(config: unknown): StructureRules | undefined }
|
|
68
72
|
|
|
69
73
|
const MAX_FILES = 500, RULE_BYTES = 32_000, MAX_RULE_FILES = 8;
|
|
70
74
|
const LOCKFILES = new Set(["bun.lock", "bun.lockb", "package-lock.json", "yarn.lock", "pnpm-lock.yaml", "Cargo.lock", "poetry.lock", "uv.lock", "go.sum", "composer.lock", "Gemfile.lock"]);
|
|
@@ -154,7 +158,47 @@ export function buildReviewBrief(cwd: string, head: unknown, policy: BriefPolicy
|
|
|
154
158
|
if (plain.status !== 0 || typeof plain.stdout !== "string") return { unavailable: `the name list of ${head} could not be read` };
|
|
155
159
|
const listed = new Set(shown.flatMap(g => g.paths)), hidden = new Set(groups.filter(g => !shown.includes(g)).flatMap(g => g.paths));
|
|
156
160
|
const unlisted = plain.stdout.split("\0").filter(path => path && !listed.has(path) && !hidden.has(path));
|
|
157
|
-
|
|
161
|
+
const structure = reviewStructure(cwd, mergeBase, commit, policy);
|
|
162
|
+
return { ...(structure?.length ? { structure } : {}), head: commit, base: from, mergeBase, reviewable, excluded, withheld, rules: [...ruleText].map(([source, text]) => ({ source, text })), rulesMissing: [...rulesMissing].map(([source, reason]) => ({ source, reason })), ruleGroups: [...byKey.values()], unlisted };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function reviewStructure(cwd: string, base: string, head: string, policy: BriefPolicy): string[] | undefined {
|
|
166
|
+
if (!policy.structureRules) return;
|
|
167
|
+
try {
|
|
168
|
+
const config = git(cwd, ["show", `${base}:.agenthub/sdlc.toml`]);
|
|
169
|
+
if (config.status !== 0 || typeof config.stdout !== "string") return;
|
|
170
|
+
const rules = policy.structureRules(Bun.TOML.parse(config.stdout));
|
|
171
|
+
if (!rules) return;
|
|
172
|
+
const visible = (path: string) => !policy.privatePath(path) && policy.nameable(path);
|
|
173
|
+
if (!visible(rules.baseline)) return;
|
|
174
|
+
const baselineFile = git(cwd, ["show", `${base}:${rules.baseline}`]);
|
|
175
|
+
const baseline = baselineFile.status === 0 ? parseStructureBaseline(baselineFile.stdout) : undefined;
|
|
176
|
+
const run = (args: string[], input?: string) => {
|
|
177
|
+
const result = hubGitSync(["-C", cwd, ...args], { input, env: childEnv(process.env), maxBuffer: 16 * 1024 * 1024, timeout: 15_000 });
|
|
178
|
+
return result.status === 0 && Buffer.isBuffer(result.stdout) ? result.stdout : undefined;
|
|
179
|
+
};
|
|
180
|
+
const before = scanStructureRevision(rules, base, run, visible);
|
|
181
|
+
const after = before && scanStructureRevision(rules, head, run, visible);
|
|
182
|
+
if (!before || !after) return;
|
|
183
|
+
const previous = updateStructureBaseline(rules, undefined, before);
|
|
184
|
+
const result = checkStructureBudget(rules, previous, after);
|
|
185
|
+
const rows = [...result.findings, ...result.warnings].filter(finding => {
|
|
186
|
+
if (finding.kind === "growth") return baseline && Object.hasOwn(baseline.sizes, finding.path)
|
|
187
|
+
&& after.some(file => file.path === finding.path && file.lines > previous.sizes[finding.path]!.lines);
|
|
188
|
+
return !finding.detail.startsWith("Stale ");
|
|
189
|
+
}).map(finding => `- ${finding.path}: ${finding.detail}. ${finding.next}`)
|
|
190
|
+
.filter(line => policy.nameable(line));
|
|
191
|
+
if (!rows.length) return;
|
|
192
|
+
const ripwire = Bun.which("ripwire");
|
|
193
|
+
if (ripwire) {
|
|
194
|
+
const range = `--quality-delta=${base}..${head}`;
|
|
195
|
+
const advisory = spawnSync(ripwire, [".", range], { cwd, env: childEnv(process.env), encoding: "utf8", timeout: 5_000, maxBuffer: 16 * 1024 });
|
|
196
|
+
if (advisory.status === 0 && policy.nameable(advisory.stdout)) rows.push(`Ripwire advisory: ripwire . ${range}`);
|
|
197
|
+
}
|
|
198
|
+
return rows;
|
|
199
|
+
} catch {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
158
202
|
}
|
|
159
203
|
|
|
160
204
|
function numstat(cwd: string, head: string, base: string, attrSource: string): Map<string, { insertions: number; deletions: number; binary: boolean }> | undefined {
|
|
@@ -230,6 +274,7 @@ export function renderReviewBrief(brief: ReviewBrief): string {
|
|
|
230
274
|
...(brief.unlisted.length ? ["Not in the brief's list, read directly:", ...brief.unlisted.map(path => `- ${path}`)] : []),
|
|
231
275
|
...brief.ruleGroups.filter(g => g.sources.length).map(g => `Rules ${g.sources.join(" + ")} apply to: ${brief.ruleGroups.length === 1 ? "every reviewable file" : g.paths.join(", ")}`),
|
|
232
276
|
...(brief.rulesMissing.length ? ["Configured rules not loaded (read them in the repository):", ...brief.rulesMissing.map(m => `- ${m.source}: ${m.reason}`)] : []),
|
|
277
|
+
...(brief.structure?.length ? ["Structure changes:", ...brief.structure] : []),
|
|
233
278
|
...brief.rules.map(r => `--- ${r.source} ---\n${r.text.trimEnd()}`),
|
|
234
279
|
`Coverage: pass hub_review coverage {reviewed: [paths], skipped: [{path, reason}]} naming every reviewable path above.`,
|
|
235
280
|
].join("\n");
|
package/src/hub/roster.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { builtinDeclarationOf as builtinDefinitionOf, createProjectDeclarationCatalog as builtinCatalog } from "../adapters/declaration-catalog.ts";
|
|
2
|
+
import type { ProjectAdapterCatalog, KindMap } from "../adapters/registry-types.ts";
|
|
2
3
|
import { validateInstances } from "./instances.ts";
|
|
3
|
-
import { defaultRosterEnabled as builtinDefaultRosterEnabled, createProjectAdapterCatalog as builtinCatalog } from "../adapters/registry.ts";
|
|
4
4
|
|
|
5
5
|
export type PeerRoster = Partial<Record<string, boolean>>;
|
|
6
6
|
|
|
@@ -45,7 +45,10 @@ export function peerRosterConfig(value: unknown, instances?: KindMap, catalog?:
|
|
|
45
45
|
/** External ids keep their existing admission rules; Pi's legacy switch is only its default. */
|
|
46
46
|
export function rosterAllows(roster: PeerRoster, peer: string, piEnabled: boolean, instances: KindMap | undefined, catalog: ProjectAdapterCatalog, inertUnknown = false): boolean {
|
|
47
47
|
const definitionOf = catalog.definitionOf;
|
|
48
|
-
const defaultRosterEnabled = (id: string, enabled: boolean) =>
|
|
48
|
+
const defaultRosterEnabled = (id: string, enabled: boolean) => {
|
|
49
|
+
const builtin = builtinDefinitionOf(id);
|
|
50
|
+
return builtin?.enabledSwitchStartOnly ? enabled : catalog.definitionOf(id)?.defaultOnRoster ?? false;
|
|
51
|
+
};
|
|
49
52
|
const definition = definitionOf(peer, instances);
|
|
50
53
|
if (!definition) return !inertUnknown || !Object.hasOwn(roster, peer); // Only a captured module scope makes unresolved rows inert; legacy external clients keep their admission rules.
|
|
51
54
|
return roster[peer] ?? (definition.kind === peer ? defaultRosterEnabled(peer, piEnabled) : true);
|
package/src/hub/routing.ts
CHANGED
|
@@ -2,7 +2,12 @@ import { contextHeadroom, type ContextAdmission } from "./context-window.ts";
|
|
|
2
2
|
import { queueBackpressure, type QueueBackpressureCode, type QueueBackpressurePolicy, type QueuePressure } from "./queue-backpressure.ts";
|
|
3
3
|
import { selectReviewerPool, type ReviewerPoolSelection } from "./reviewer-pool.ts";
|
|
4
4
|
import type { ReviewBudgetSnapshot } from "./review-budget.ts";
|
|
5
|
-
import {
|
|
5
|
+
import type { ProjectAdapterCatalog } from "../adapters/registry-types.ts";
|
|
6
|
+
|
|
7
|
+
const runtimeAdapters = () => require("../adapters/registry.ts") as typeof import("../adapters/registry.ts");
|
|
8
|
+
const definitionOf: typeof import("../adapters/registry.ts").definitionOf = (...args) => runtimeAdapters().definitionOf(...args);
|
|
9
|
+
const kindOf: typeof import("../adapters/registry.ts").kindOf = (...args) => runtimeAdapters().kindOf(...args);
|
|
10
|
+
const familyOf: typeof import("../adapters/registry.ts").familyOf = (...args) => runtimeAdapters().familyOf(...args);
|
|
6
11
|
import { readFileSync, statSync } from "node:fs";
|
|
7
12
|
import { join, resolve } from "node:path";
|
|
8
13
|
import { CLASSES, type Task, type TaskClass } from "./board.ts";
|
|
@@ -169,7 +174,7 @@ function orderSiblingSlots(peers: PeerId[], states: Readonly<Record<string, Peer
|
|
|
169
174
|
|
|
170
175
|
/** The quota/roster relay keeps its native preference order, then the class's original tail. */
|
|
171
176
|
export function relayCandidates(classPeers: readonly PeerId[], pii: boolean, opts: InstanceRoutingOptions & { states?: Readonly<Record<string, PeerState>> } = {}): PeerId[] {
|
|
172
|
-
const preferred = (opts.adapterCatalog?.definitions ?? ADAPTERS).filter(adapter => adapter.routing?.handoffPriority !== undefined)
|
|
177
|
+
const preferred = (opts.adapterCatalog?.definitions ?? runtimeAdapters().ADAPTERS).filter(adapter => adapter.routing?.handoffPriority !== undefined)
|
|
173
178
|
.sort((a, b) => a.routing!.handoffPriority! - b.routing!.handoffPriority!);
|
|
174
179
|
const candidates = [
|
|
175
180
|
...preferred.filter(adapter => !pii || adapter.trust.onPrem).map(adapter => adapter.kind),
|
|
@@ -512,6 +517,8 @@ export function assign(
|
|
|
512
517
|
if (isRemotePeerId(peer)) return deny("policy", "remote peers cannot hold local roles");
|
|
513
518
|
const definition = (opts.adapterCatalog?.definitionOf ?? definitionOf)(peer, opts.instances);
|
|
514
519
|
if (definition?.start.daemonPort === "configured-print") return deny("policy", "print peers return advisory answers and cannot own tasks or submit verdicts");
|
|
520
|
+
// #1809: `tasks: false` (a configured pull kind) is read here, never the transport, so allowing pull ownership later is a validation change.
|
|
521
|
+
if (definition?.tasks === false) return deny("policy", "a pull peer owns no task: its declaration has tasks: false");
|
|
515
522
|
const ceiling = definition?.routing?.allowedRoles;
|
|
516
523
|
const requiredRole = role === "reviewer" ? "reviewer" : ownerRoleOfClass(task.class);
|
|
517
524
|
if (ceiling && !ceiling.includes(requiredRole)) return deny("policy", "adapter role ceiling excludes this assignment");
|
|
@@ -16,7 +16,7 @@ export interface RuntimeCapturePrunePlan { remove: string[]; kept: string[]; def
|
|
|
16
16
|
export interface RuntimeCapturePruneResult { removed: string[]; kept: string[]; quarantined?: string[]; deferred?: string }
|
|
17
17
|
interface Capture { root: string; version: string; digest: string; dev: number; ino: number; modified: number }
|
|
18
18
|
interface ManagerOwner { slot: number; instance_id: string; pid: number; signature: string | null }
|
|
19
|
-
interface Observation { files: Map<string, string | null>; lists: Map<string, string[]>; projects: string; roots: Set<string>; managerRoot?: string; bytes: number }
|
|
19
|
+
interface Observation { files: Map<string, string | null>; lists: Map<string, string[]>; projects: string; roots: Set<string>; referrers?: Map<string, Set<string>>; managerRoot?: string; bytes: number }
|
|
20
20
|
interface LockBudget { deadline: number; remaining: number }
|
|
21
21
|
const VERSION = /^[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?$/;
|
|
22
22
|
const CAPTURE = /^source-([a-f0-9]{64})$/;
|
|
@@ -92,6 +92,11 @@ function metadata(file: string, observation?: Observation): unknown {
|
|
|
92
92
|
try { return JSON.parse(bytes.subarray(0, count).toString("utf8")); } catch { return fail("runtime retention metadata is invalid"); }
|
|
93
93
|
} finally { closeSync(fd); }
|
|
94
94
|
}
|
|
95
|
+
function addRoot(observation: Observation, root: string, who: string): void {
|
|
96
|
+
observation.roots.add(root);
|
|
97
|
+
const map = observation.referrers ??= new Map();
|
|
98
|
+
const set = map.get(root) ?? new Set<string>(); set.add(who); map.set(root, set);
|
|
99
|
+
}
|
|
95
100
|
function canonicalReference(root: string, observation: Observation): string {
|
|
96
101
|
const canonical = realPath(root); // process-backed platform resolution remains outside the registry writer lock
|
|
97
102
|
const info = optionalInfo(root, observation);
|
|
@@ -155,7 +160,7 @@ function observeReferences(home: string, registry: Registry): Observation {
|
|
|
155
160
|
const root = canonicalReference(runtime.root, observation), named = CAPTURE.exec(basename(root)), version = basename(dirname(root));
|
|
156
161
|
if (named?.[0] === basename(root) && VERSION.exec(version)?.[0] === version && basename(dirname(dirname(root))) === "releases"
|
|
157
162
|
&& (named[1] !== runtime.digest || version !== runtime.version)) fail("project runtime capture path identity is inconsistent");
|
|
158
|
-
observation.
|
|
163
|
+
addRoot(observation, root, `project ${project.root}`);
|
|
159
164
|
}
|
|
160
165
|
// Retain uncertain claims conservatively, rather than running one process probe per registry row under a writer lock.
|
|
161
166
|
if (project.instanceId !== null && (!runtime || runtime.instanceId !== project.instanceId)) fail("a live or uncertain project has no matching retained runtime identity");
|
|
@@ -195,7 +200,7 @@ function observeReferences(home: string, registry: Registry): Observation {
|
|
|
195
200
|
// A retired mutable install may be gone; its lexical path still cannot authorize deletion elsewhere.
|
|
196
201
|
let root: string;
|
|
197
202
|
try { root = realPath(value); } catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error; root = resolve(value); }
|
|
198
|
-
observation.
|
|
203
|
+
addRoot(observation, root, `recovery operation ${record.id}`);
|
|
199
204
|
}
|
|
200
205
|
if (record.targetRoot !== undefined && (typeof record.targetDigest !== "string" || !/^[a-f0-9]{64}$/.test(record.targetDigest))
|
|
201
206
|
|| record.targetRoot === undefined && (record.phase === "completed" || record.targetDigest !== undefined)) fail("retained recovery target identity is incomplete");
|
|
@@ -551,3 +556,20 @@ if (import.meta.main) {
|
|
|
551
556
|
try { if (!home || !isAbsolute(home) || !id || !/^[a-f0-9-]{36}$/.test(id)) fail("runtime maintenance worker identity is invalid"); runScheduledWorker(home, id); }
|
|
552
557
|
catch { process.exitCode = 1; }
|
|
553
558
|
}
|
|
559
|
+
|
|
560
|
+
/** #1781: what `ahub releases` reads. The same observation, lock and registry the background worker uses; nothing here parses runtime.json again. */
|
|
561
|
+
export interface RuntimeReferences { observation: Observation; referrers: ReadonlyMap<string, ReadonlySet<string>>; managerRoot?: string }
|
|
562
|
+
export function observeRuntimeReferences(home: string, registry: Registry): RuntimeReferences {
|
|
563
|
+
const observation = observeReferences(home, registry);
|
|
564
|
+
return { observation, referrers: observation.referrers ?? new Map(), ...(observation.managerRoot ? { managerRoot: observation.managerRoot } : {}) };
|
|
565
|
+
}
|
|
566
|
+
/** Opens the home's registry the way the worker does; throws the worker's own cause when the home or registry is unavailable. */
|
|
567
|
+
export function openRuntimeRegistry(home: string): { home: string; registry: Registry } { return openRegistry(home); }
|
|
568
|
+
/** Runs `action` under the registry writer lock after proving the observed references are unchanged, with the worker's metadata budget. */
|
|
569
|
+
export function underRuntimeReferences<T>(registry: Registry, references: RuntimeReferences, action: () => T): T {
|
|
570
|
+
return registry.runtimeCaptureLocked(() => {
|
|
571
|
+
const budget = { deadline: performance.now() + LOCK_METADATA_MS, remaining: MAX_REFERENCE_FILES * 4 };
|
|
572
|
+
validateObservation(registry, references.observation, budget);
|
|
573
|
+
return action();
|
|
574
|
+
});
|
|
575
|
+
}
|
|
@@ -79,7 +79,7 @@ function admissionHealth(file: string): LedgerHealth {
|
|
|
79
79
|
finally { try { db?.close(); } catch { /* Inspection never repairs or alters admission state. */ } }
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
/** Scan only the two release directory levels, never capture contents or a referenced/symlinked directory. */
|
|
82
|
+
/** Scan only the two release directory levels (and the top-level reserved names), never capture contents or a referenced/symlinked directory. */
|
|
83
83
|
function quarantineHealth(home: string, active: boolean | undefined): RuntimePruneHealthCheck[] {
|
|
84
84
|
const releases = join(home, "releases"), checks: RuntimePruneHealthCheck[] = [];
|
|
85
85
|
let remaining = MAX_SCAN_ENTRIES, found = 0;
|
|
@@ -93,6 +93,13 @@ function quarantineHealth(home: string, active: boolean | undefined): RuntimePru
|
|
|
93
93
|
};
|
|
94
94
|
try {
|
|
95
95
|
scan(releases, version => {
|
|
96
|
+
if (version.name.startsWith(".runtime-prune-")) { // #1781: `ahub releases prune` quarantines a bare coordinator source here
|
|
97
|
+
if (++found > MAX_QUARANTINES) throw new Error("quarantine result bound exceeded");
|
|
98
|
+
const path = join(releases, version.name), stat = info(path); if (!stat) return;
|
|
99
|
+
const unsafe = stat.isSymbolicLink() || !stat.isDirectory();
|
|
100
|
+
checks.push({ ok: undefined, name: "runtime quarantine", detail: `${unsafe ? "unsafe reserved quarantine path" : active === true ? "maintenance quarantine is in use" : "runtime quarantine remains"}; inspect ${path}` });
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
96
103
|
if (VERSION.exec(version.name)?.[0] !== version.name) return;
|
|
97
104
|
const directory = join(releases, version.name);
|
|
98
105
|
if (!version.isDirectory() || version.isSymbolicLink()) throw new Error(`unsafe version directory: ${directory}`);
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// #1856 T2: `ahub sdlc check`, a read-only audit of the lifecycle's moving parts. Pure over injected reads: it never writes, every GitHub read shares one deadline, a private task is only counted.
|
|
2
|
+
import { requiredCheckNames, type SdlcConfig, type SdlcGh, type SdlcMode } from "./sdlc.ts";
|
|
3
|
+
|
|
4
|
+
type CheckState = "ok" | "warn" | "fail" | "unknown";
|
|
5
|
+
type CheckSection = "config" | "repository" | "bindings" | "roadmap";
|
|
6
|
+
const CHECK_SECTIONS: readonly CheckSection[] = ["config", "repository", "bindings", "roadmap"];
|
|
7
|
+
/** A non-ok row always carries its cause and a runnable next step. */
|
|
8
|
+
interface SdlcCheckRow { section: CheckSection; id: string; state: CheckState; detail: string; cause?: string; next?: string }
|
|
9
|
+
interface SdlcCheckTask {
|
|
10
|
+
id: number; state: string; /** Public title only (`Tasks.publicTitle`). */ title: string; pii: boolean; branch?: string;
|
|
11
|
+
sdlc?: { repo?: string; issue?: number; pr?: number; localHead?: string };
|
|
12
|
+
}
|
|
13
|
+
interface RoadmapFinding { rule: number; milestone: number | null; items: string[]; cause: string; remedy: string }
|
|
14
|
+
interface SdlcCheckInput {
|
|
15
|
+
/** Skips every GitHub read and every check that needs one (`ahub doctor` uses this). */
|
|
16
|
+
offline: boolean;
|
|
17
|
+
/** The mode and required checks the running hub loaded. */
|
|
18
|
+
running: { mode: SdlcMode; requiredChecks: readonly string[]; /** The list that applies to this repository (a `repos` override included); defaults to requiredChecks. */ effectiveChecks?: readonly string[] };
|
|
19
|
+
/** The file on disk: parsed, or the parse failure; `present` is false when the file does not exist. */
|
|
20
|
+
file: () => { present: boolean; config: SdlcConfig };
|
|
21
|
+
/** Rostered holders of each flow role as the loader settled them. */
|
|
22
|
+
holders: Record<"planner" | "reviewer" | "conductor", readonly string[]>;
|
|
23
|
+
repository: string | undefined;
|
|
24
|
+
gh: SdlcGh;
|
|
25
|
+
/** The check names the latest completed default-branch workflow run produced (init's bounded discovery). */
|
|
26
|
+
discover: (gh: SdlcGh) => Promise<{ names: readonly string[]; source: string; reason?: string }>;
|
|
27
|
+
securityScan: () => { configured: boolean; counts?: Record<string, number | null> };
|
|
28
|
+
/** Unsettled tasks only; the caller lists proposed, in_progress, in_review and changes_requested. */
|
|
29
|
+
tasks: readonly SdlcCheckTask[];
|
|
30
|
+
/** Present only when milestones or a tracked docs/roadmap.json exist. */
|
|
31
|
+
roadmap?: {
|
|
32
|
+
drift: () => Promise<{ findings: RoadmapFinding[]; unknown: number[]; truncated?: true }>;
|
|
33
|
+
/** `Tasks.roadmapUnplaced`: milestone placement with issue inheritance already applied. */
|
|
34
|
+
unplaced: () => Promise<{ tasks: readonly { id: number }[]; issues: readonly { ref: string }[]; partial: boolean; unavailable: readonly string[]; more: { issues: number; tasks: number } }>;
|
|
35
|
+
};
|
|
36
|
+
now?: () => number;
|
|
37
|
+
deadlineMs?: number;
|
|
38
|
+
}
|
|
39
|
+
export interface SdlcCheckReport {
|
|
40
|
+
/** True when no row failed; the control reply keeps its own `ok`. */ passed: boolean; offline: boolean; deadlineMs: number; rows: SdlcCheckRow[];
|
|
41
|
+
counts: Record<CheckState, number>; /** Private unsettled tasks, never described. */ withheld: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const CHECK_DEADLINE_MS = 20_000;
|
|
45
|
+
const READ_MS = 8_000, READ_BYTES = 512 * 1024, LIST = 100, SHOWN = 8;
|
|
46
|
+
const short = (text: string, max = 160) => (text.length > max ? `${text.slice(0, max - 1)}…` : text).replace(/[\u0000-\u001f\u007f]/g, " ");
|
|
47
|
+
const ids = (list: readonly number[]) => `${list.slice(0, SHOWN).map(id => `#${id}`).join(", ")}${list.length > SHOWN ? ` and ${list.length - SHOWN} more` : ""}`;
|
|
48
|
+
/** Exactly one unqualified `#N` in a title; `owner/repo#N` and several numbers stay unnamed. */
|
|
49
|
+
function titleIssue(title: string): number | undefined {
|
|
50
|
+
const found = [...title.matchAll(/(?<![A-Za-z0-9_/.-])#([1-9][0-9]*)\b/g)].map(match => Number(match[1]));
|
|
51
|
+
const unique = [...new Set(found)];
|
|
52
|
+
return unique.length === 1 && Number.isSafeInteger(unique[0]) ? unique[0] : undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function runSdlcCheck(input: SdlcCheckInput): Promise<SdlcCheckReport> {
|
|
56
|
+
const now = input.now ?? (() => performance.now()), deadlineMs = input.deadlineMs ?? CHECK_DEADLINE_MS, deadline = now() + deadlineMs;
|
|
57
|
+
const rows: SdlcCheckRow[] = [];
|
|
58
|
+
const add = (section: CheckSection, id: string, state: CheckState, detail: string, cause?: string, next?: string) => {
|
|
59
|
+
if (state !== "ok" && (!cause || !next)) throw new Error(`sdlc check row ${id} needs a cause and a next step`);
|
|
60
|
+
rows.push({ section, id, state, detail: short(detail, 240), ...(cause ? { cause: short(cause, 400) } : {}), ...(next ? { next: short(next, 240) } : {}) });
|
|
61
|
+
};
|
|
62
|
+
// One shared allowance for every GitHub read; an exhausted deadline is an unknown row, never a hang.
|
|
63
|
+
const gh: SdlcGh = async (args, timeoutMs, cwd, maxBytes) => {
|
|
64
|
+
if (input.offline) throw new Error("offline");
|
|
65
|
+
const remaining = deadline - now();
|
|
66
|
+
if (remaining <= 0) throw new Error("deadline");
|
|
67
|
+
return input.gh(args, Math.min(timeoutMs ?? READ_MS, remaining), cwd, maxBytes);
|
|
68
|
+
};
|
|
69
|
+
const read = async (args: string[]): Promise<unknown | undefined> => {
|
|
70
|
+
try { const reply = await gh(args, READ_MS, undefined, READ_BYTES); if (reply.code !== 0 || Buffer.byteLength(reply.stdout) >= READ_BYTES) return undefined; return JSON.parse(reply.stdout); }
|
|
71
|
+
catch { return undefined; }
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// 1. Lifecycle config and roles.
|
|
75
|
+
let file: { present: boolean; config: SdlcConfig } | undefined, parseError: string | undefined;
|
|
76
|
+
try { file = input.file(); } catch (error) { parseError = error instanceof Error ? error.message : "unreadable"; }
|
|
77
|
+
if (!file) add("config", "sdlc.toml", "fail", ".agenthub/sdlc.toml does not parse", parseError!, "fix .agenthub/sdlc.toml, then run ahub restart; the running hub keeps its last good configuration until then");
|
|
78
|
+
else if (!file.present) add("config", "sdlc.toml", "warn", "no .agenthub/sdlc.toml", "the lifecycle is off without the file", "ahub init --sdlc advise --dry-run");
|
|
79
|
+
else add("config", "sdlc.toml", "ok", `parses; mode ${file.config.mode}`);
|
|
80
|
+
if (file) {
|
|
81
|
+
const mode = file.config.mode;
|
|
82
|
+
if (mode === "off" && file.present) add("config", "mode", "warn", "mode is off", "no lifecycle gates or receipts run in mode off", "ahub init --sdlc advise --dry-run");
|
|
83
|
+
else if (mode !== "off") add("config", "mode", "ok", `mode ${mode}`);
|
|
84
|
+
const sameChecks = JSON.stringify([...file.config.requiredChecks]) === JSON.stringify([...input.running.requiredChecks]);
|
|
85
|
+
if (mode !== input.running.mode || !sameChecks) add("config", "restart", "warn", `the running hub holds mode ${input.running.mode}, the file says ${mode}${sameChecks ? "" : " and other required_checks"}`, "an edit of .agenthub/sdlc.toml applies only after a restart", "ahub restart");
|
|
86
|
+
else add("config", "restart", "ok", "the running hub matches the file");
|
|
87
|
+
}
|
|
88
|
+
for (const role of ["planner", "reviewer", "conductor"] as const) {
|
|
89
|
+
const holders = input.holders[role];
|
|
90
|
+
if (holders.length) add("config", `role ${role}`, "ok", `${role} ${holders.join(", ")}`);
|
|
91
|
+
else add("config", `role ${role}`, "warn", `no rostered ${role}`,
|
|
92
|
+
role === "conductor" ? "no rostered peer holds the conductor role, so the person conducts from ahub console" : role === "planner" ? "no rostered planner is eligible, so plan work falls back to the first eligible rostered kind or has none" : "no rostered reviewer can run, so reviews go to the person",
|
|
93
|
+
"ahub roles, then ahub roster add <peer> for a peer that can hold it");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 2. Repository and required checks (skipped offline).
|
|
97
|
+
const enabled = input.running.mode !== "off", repo = input.repository;
|
|
98
|
+
if (!input.offline) {
|
|
99
|
+
if (!repo) add("repository", "origin", "warn", "no GitHub origin", "origin does not name a GitHub owner/repo, so CI, PR and issue reads cannot run", "git remote add origin <https://github.com/owner/repo.git>");
|
|
100
|
+
else add("repository", "origin", "ok", repo);
|
|
101
|
+
if (repo) {
|
|
102
|
+
let auth: boolean | undefined;
|
|
103
|
+
try { auth = (await gh(["auth", "status"], READ_MS)).code === 0; } catch { auth = undefined; }
|
|
104
|
+
if (auth === true) add("repository", "gh auth", "ok", "gh is authenticated");
|
|
105
|
+
else if (auth === false) add("repository", "gh auth", enabled ? "fail" : "warn", "gh is not authenticated", "gh auth status failed, so no GitHub read below can run", "gh auth login");
|
|
106
|
+
else add("repository", "gh auth", "unknown", "gh auth could not be read", "the 20 s GitHub deadline passed or gh is missing", "gh auth status");
|
|
107
|
+
}
|
|
108
|
+
const required = input.running.effectiveChecks ?? input.running.requiredChecks;
|
|
109
|
+
if (!required.length) add("repository", "required_checks", enabled ? "warn" : "ok", enabled ? "required_checks is empty" : "required_checks is empty (mode off)",
|
|
110
|
+
"with no required check the merge and review gates have nothing to compare CI against", "ahub sdlc configure --required-checks check,lint");
|
|
111
|
+
else if (repo) {
|
|
112
|
+
let found: Awaited<ReturnType<SdlcCheckInput["discover"]>> | undefined;
|
|
113
|
+
try { found = await input.discover(gh); } catch { found = undefined; }
|
|
114
|
+
if (!found || !found.names.length) add("repository", "required_checks", "unknown", `${required.length} required, none compared`, found?.reason ?? "the default branch's check names could not be read", "gh run list --branch main --limit 1, or pass the names to ahub sdlc configure --required-checks");
|
|
115
|
+
else {
|
|
116
|
+
const names = new Set(found.names), unmatched = requiredCheckNames(repo, required).filter(name => !names.has(name));
|
|
117
|
+
if (unmatched.length) add("repository", "required_checks", "warn", `${unmatched.length} of ${required.length} required checks not produced by ${found.source}`, `no completed default-branch job is named ${unmatched.map(name => `"${short(name, 60)}"`).join(", ")}; the gate would wait for a check that never reports`, `ahub sdlc configure --required-checks ${found.names.join(",")}`);
|
|
118
|
+
else add("repository", "required_checks", "ok", `${required.length} required checks all produced (${found.source})`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const scan = input.securityScan();
|
|
122
|
+
if (scan.configured) {
|
|
123
|
+
const counts = scan.counts;
|
|
124
|
+
if (!counts) add("repository", "security_scan", "unknown", "no recorded scan", "[security_scan] is configured and no scan has run yet", "ahub sdlc status shows the scan counts once one has run");
|
|
125
|
+
else {
|
|
126
|
+
const unknown = Object.entries(counts).filter(([, value]) => value === null || value === undefined).map(([source]) => source);
|
|
127
|
+
if (unknown.length) add("repository", "security_scan", "warn", `${unknown.length} source${unknown.length === 1 ? "" : "s"} unknown`, `the latest scan could not read ${unknown.join(", ")}`, "ahub sdlc status");
|
|
128
|
+
else add("repository", "security_scan", "ok", "all sources read in the latest scan");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// 3. Active task bindings (non-private, unsettled).
|
|
134
|
+
const visible = input.tasks.filter(task => !task.pii), withheld = input.tasks.length - visible.length;
|
|
135
|
+
const noIssue = visible.filter(task => !task.sdlc?.issue && titleIssue(task.title) !== undefined).map(task => task.id);
|
|
136
|
+
if (noIssue.length) add("bindings", "issue binding", "warn", `${noIssue.length} task${noIssue.length === 1 ? "" : "s"} name an issue but record none: ${ids(noIssue)}`, "sdlc.issue is empty although the title names one #N, so milestone inheritance and issue links are missing",
|
|
137
|
+
`ahub sdlc record ${noIssue[0]} '{"repo":"${repo ?? "owner/repo"}","issue":${titleIssue(visible.find(task => task.id === noIssue[0])!.title)}}'`);
|
|
138
|
+
else add("bindings", "issue binding", "ok", visible.length ? "every task that names an issue records it" : "no unsettled task");
|
|
139
|
+
if (input.offline) add("bindings", "pr binding", "unknown", "not read offline", "PR bindings need GitHub, and this view makes no network call", "ahub sdlc check");
|
|
140
|
+
else if (!repo) add("bindings", "pr binding", "unknown", "not read", "no GitHub origin to read PRs from", "git remote add origin <https://github.com/owner/repo.git>");
|
|
141
|
+
else {
|
|
142
|
+
const prs = await read(["pr", "list", "--repo", repo, "--state", "all", "--limit", String(LIST), "--json", "number,state,headRefName,headRefOid"]) as { number: number; state: string; headRefName: string; headRefOid: string }[] | undefined;
|
|
143
|
+
if (!Array.isArray(prs)) add("bindings", "pr binding", "unknown", "PRs not read", "the GitHub PR list was unavailable or past the deadline", `gh pr list --repo ${repo} --state all`);
|
|
144
|
+
else {
|
|
145
|
+
const byNumber = new Map(prs.map(pr => [pr.number, pr])), unbound: number[] = [], lagging: number[] = [], merged: { id: number; pr: number }[] = [];
|
|
146
|
+
for (const task of visible) {
|
|
147
|
+
const bound = task.sdlc?.pr === undefined ? undefined : byNumber.get(task.sdlc.pr);
|
|
148
|
+
if (task.sdlc?.pr !== undefined && bound?.state === "MERGED" && task.state !== "approved") merged.push({ id: task.id, pr: task.sdlc.pr });
|
|
149
|
+
if (bound?.state === "OPEN" && task.sdlc?.localHead !== undefined && task.sdlc.localHead !== bound.headRefOid) lagging.push(task.id);
|
|
150
|
+
const open = task.branch ? prs.find(pr => pr.state === "OPEN" && pr.headRefName === task.branch) : undefined;
|
|
151
|
+
if (open && task.sdlc?.pr === undefined) unbound.push(task.id);
|
|
152
|
+
}
|
|
153
|
+
const note = prs.length >= LIST ? ` (the latest ${LIST} PRs were read)` : "";
|
|
154
|
+
if (unbound.length) add("bindings", "pr binding", "warn", `${unbound.length} open PR${unbound.length === 1 ? "" : "s"} not recorded on the task: ${ids(unbound)}${note}`, "the task's branch has an open PR and no sdlc.pr, so ci-watch observes nothing", `ahub sdlc record ${unbound[0]} '{"pr":<number>,"localHead":"<head sha>"}'`);
|
|
155
|
+
else add("bindings", "pr binding", "ok", `every open PR of a task branch is recorded${note}`);
|
|
156
|
+
if (lagging.length) add("bindings", "head binding", "warn", `${lagging.length} task${lagging.length === 1 ? "" : "s"} record an older head than the open PR: ${ids(lagging)}`, "sdlc.localHead lags the PR's head, so ci-watch watches a superseded commit", `ahub sdlc record ${lagging[0]} '{"localHead":"<current head sha>"}'`);
|
|
157
|
+
else add("bindings", "head binding", "ok", "recorded heads match their open PRs");
|
|
158
|
+
if (merged.length) add("bindings", "merged PR", "warn", `${merged.length} linked PR${merged.length === 1 ? "" : "s"} already merged: ${ids(merged.map(row => row.id))}`, "the PR merged on GitHub and the task still waits for adopt-merge", `ahub sdlc adopt-merge ${merged[0]!.id} --pr ${merged[0]!.pr}`);
|
|
159
|
+
else add("bindings", "merged PR", "ok", "no linked PR is merged and waiting");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (withheld) add("bindings", "private tasks", "ok", `${withheld} private task${withheld === 1 ? "" : "s"} withheld`);
|
|
163
|
+
|
|
164
|
+
// 4. Roadmap and issue hygiene, only when the project has one.
|
|
165
|
+
if (input.roadmap && !input.offline) {
|
|
166
|
+
let unplaced: Awaited<ReturnType<NonNullable<SdlcCheckInput["roadmap"]>["unplaced"]>> | undefined;
|
|
167
|
+
try {
|
|
168
|
+
const remaining = deadline - now();
|
|
169
|
+
unplaced = remaining > 0 ? await Promise.race([input.roadmap.unplaced(), new Promise<undefined>(accept => setTimeout(() => accept(undefined), remaining))]) : undefined;
|
|
170
|
+
} catch { unplaced = undefined; }
|
|
171
|
+
if (!unplaced) {
|
|
172
|
+
add("roadmap", "unplaced tasks", "unknown", "placement not read", "the roadmap placement read was unavailable or past the 20 s deadline", "ahub roadmap unplaced");
|
|
173
|
+
add("roadmap", "unplaced issues", "unknown", "placement not read", "the roadmap placement read was unavailable or past the 20 s deadline", "ahub roadmap unplaced");
|
|
174
|
+
} else {
|
|
175
|
+
const visibleIds = new Set(visible.map(task => task.id)), taskIds = unplaced.tasks.map(task => task.id).filter(id => visibleIds.has(id));
|
|
176
|
+
if (taskIds.length) add("roadmap", "unplaced tasks", "warn", `${taskIds.length} unsettled task${taskIds.length === 1 ? "" : "s"} in no milestone: ${ids(taskIds)}${unplaced.more.tasks ? " (at least; more were cut)" : ""}`, "no milestone holds the task directly or through its issue, so the roadmap omits it", "ahub roadmap unplaced");
|
|
177
|
+
else add("roadmap", "unplaced tasks", "ok", "every unsettled task is in a milestone, directly or through its issue");
|
|
178
|
+
if (unplaced.unavailable.includes("issues")) add("roadmap", "unplaced issues", "unknown", "open issues not read", "the GitHub issue list was unavailable or past the deadline", "ahub roadmap unplaced");
|
|
179
|
+
else if (unplaced.issues.length) add("roadmap", "unplaced issues", "warn", `${unplaced.issues.length + unplaced.more.issues} open issue${unplaced.issues.length + unplaced.more.issues === 1 ? "" : "s"} in no milestone: ${unplaced.issues.slice(0, SHOWN).map(issue => issue.ref).join(", ")}${unplaced.partial ? " (partial read)" : ""}`, "the roadmap shows only issues linked to a milestone", "ahub roadmap unplaced");
|
|
180
|
+
else if (unplaced.partial) add("roadmap", "unplaced issues", "unknown", "issue read was partial", "the issue list or placement read was partial", "ahub roadmap unplaced");
|
|
181
|
+
else add("roadmap", "unplaced issues", "ok", "every open issue is in a milestone");
|
|
182
|
+
}
|
|
183
|
+
let drift: Awaited<ReturnType<NonNullable<SdlcCheckInput["roadmap"]>["drift"]>> | undefined;
|
|
184
|
+
try {
|
|
185
|
+
const remaining = deadline - now();
|
|
186
|
+
drift = remaining > 0 ? await Promise.race([input.roadmap.drift(), new Promise<undefined>(accept => setTimeout(() => accept(undefined), remaining))]) : undefined;
|
|
187
|
+
} catch { drift = undefined; }
|
|
188
|
+
if (!drift) add("roadmap", "roadmap drift", "unknown", "drift not read", "the roadmap check was unavailable or past the 20 s deadline", "ahub roadmap check");
|
|
189
|
+
else {
|
|
190
|
+
const lagging = drift.findings.filter(finding => finding.rule === 2), mismatch = drift.findings.filter(finding => finding.rule === 8), other = drift.findings.filter(finding => ![2, 8].includes(finding.rule));
|
|
191
|
+
if (lagging.length) add("roadmap", "settled issues open", "warn", `${lagging.length} merged task${lagging.length === 1 ? "" : "s"} with an issue still open past 24 h`, lagging[0]!.cause, lagging[0]!.remedy);
|
|
192
|
+
else add("roadmap", "settled issues open", drift.unknown.some(rule => rule === 1 || rule === 2) ? "unknown" : "ok", "no merged task leaves its issue open past 24 h", ...(drift.unknown.some(rule => rule === 1 || rule === 2) ? ["an issue state or merge time was unavailable", "ahub roadmap check"] as const : []));
|
|
193
|
+
if (mismatch.length) add("roadmap", "roadmap export", "warn", "docs/roadmap.json or docs/roadmap.md differs from the board", mismatch[0]!.cause, mismatch[0]!.remedy);
|
|
194
|
+
else add("roadmap", "roadmap export", drift.unknown.includes(8) ? "unknown" : "ok", drift.unknown.includes(8) ? "export not compared" : "export matches the board", ...(drift.unknown.includes(8) ? ["the roadmap export could not be read", "ahub roadmap check"] as const : []));
|
|
195
|
+
if (other.length) add("roadmap", "roadmap drift", "warn", `${other.length} other roadmap finding${other.length === 1 ? "" : "s"}${drift.truncated ? " (truncated)" : ""}`, other[0]!.cause, other[0]!.remedy);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const counts: Record<CheckState, number> = { ok: 0, warn: 0, fail: 0, unknown: 0 };
|
|
200
|
+
for (const row of rows) counts[row.state]++;
|
|
201
|
+
return { passed: counts.fail === 0, offline: input.offline, deadlineMs, rows, counts, withheld };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** CLI output standard v1: exit 1 on a fail row; warn and unknown change nothing. */
|
|
205
|
+
export const sdlcCheckExitCode = (report: Pick<SdlcCheckReport, "counts">): 0 | 1 => report.counts.fail > 0 ? 1 : 0;
|
|
@@ -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
|
|
135
|
-
|
|
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)
|
|
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
|
|
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;
|