@staix/agent-hub 0.36.0 → 0.38.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 +27 -0
- package/README.md +6 -2
- package/THIRD_PARTY_NOTICES.md +0 -18
- package/docs/agent-notes/README.md +13 -3
- package/docs/agent-notes/daemon.md +4 -4
- package/docs/agent-notes/local-worker.md +1 -0
- package/docs/agent-notes/models.md +2 -1
- package/docs/agent-notes/tasks.md +1 -1
- package/docs/agent-notes/tests.md +1 -2
- package/docs/contracts/companion-cli-v1.json +70 -0
- package/docs/design/adapters.md +43 -2
- package/docs/design/agent-hub-architecture.md +9 -1
- package/docs/design/guidance-probes.md +1167 -0
- package/docs/design/model-routes.md +437 -12
- package/docs/dogfood.md +12 -13
- package/docs/events.md +20 -1
- package/docs/memory.md +3 -3
- package/docs/operations.md +123 -151
- package/docs/profiles.md +1 -1
- package/docs/quickstart.md +15 -3
- package/docs/research.md +1 -1
- package/docs/sdlc.md +5 -3
- package/docs/security.md +25 -1
- package/docs/specs/2026-09-19-agent-hub-design.md +9 -7
- package/docs/specs/2026-10-04-switchyard-source-port-design.md +3 -1
- package/docs/verification/2026-11-08-qwen-0269-model-setter-1317.md +25 -11
- package/docs/verification/2026-11-09-qwen-0270-model-setter-1317.md +21 -6
- package/docs/verification/2026-11-11-0.37.0.md +40 -0
- package/docs/verification/2026-11-11-0.38.0.md +41 -0
- package/docs/verification/2026-11-11-guidance-probe-t2-1226.md +153 -0
- package/docs/verification/2026-11-11-guidance-probe-t3-1226.md +85 -0
- package/docs/verification/2026-11-11-guidance-probe-t4-1226.md +65 -0
- package/docs/verification/2026-11-11-qwen-setter-suggestions-off.md +167 -0
- package/docs/verified.json +25 -25
- package/package.json +3 -4
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/kimi-hook.js +2403 -1444
- package/plugins/agent-hub/server.js +2480 -1509
- package/src/adapters/channel-peer.ts +7 -1
- package/src/adapters/claude-channel.ts +2 -1
- package/src/adapters/compat.ts +1 -1
- package/src/adapters/local-probe.ts +233 -0
- package/src/adapters/local-worker.ts +232 -21
- package/src/cli/console-state.ts +25 -6
- package/src/cli/console-versions.ts +99 -0
- package/src/cli/console.ts +13 -1
- package/src/cli/help.ts +2 -1
- package/src/cli/init.ts +3 -1
- package/src/cli/install-paths.ts +7 -2
- package/src/cli/main.ts +78 -7
- package/src/cli/output.ts +8 -4
- package/src/cli/runtime-version-warning.ts +2 -2
- package/src/cli/sdlc-output.ts +9 -5
- package/src/cli/upgrade-runtime.ts +1 -1
- package/src/hub/bus.ts +2 -2
- package/src/hub/config-apply.ts +4 -2
- package/src/hub/config-trust.ts +6 -1
- package/src/hub/control-client.ts +5 -2
- package/src/hub/daemon.ts +195 -13
- package/src/hub/envelope.ts +6 -1
- package/src/hub/events.ts +3 -2
- package/src/hub/guidance-probe-store.ts +1044 -0
- package/src/hub/guidance-probes.ts +692 -0
- package/src/hub/inference.ts +18 -5
- package/src/hub/manager.ts +24 -1
- package/src/hub/operational-authority.ts +14 -1
- package/src/hub/peers.ts +5 -0
- package/src/hub/person-command.ts +25 -0
- package/src/hub/ports.ts +1 -1
- package/src/hub/progress.ts +23 -16
- package/src/hub/report.ts +2 -0
- package/src/hub/research.ts +1 -0
- package/src/hub/restart.ts +7 -0
- package/src/hub/sdlc-release-authorization.ts +139 -17
- package/src/hub/sdlc-release-policy.ts +100 -0
- package/src/hub/sdlc-release.ts +59 -7
- package/src/hub/supervision.ts +3 -2
- package/src/hub/tasks.ts +363 -7
- package/src/local/probe-errors.ts +28 -0
- package/src/local/probe-sandbox.ts +224 -0
- package/src/local/probe-types.ts +110 -0
- package/src/local/probe-workspace.ts +426 -0
- package/src/local/sandbox.ts +71 -2
- package/src/local/tools.ts +135 -9
- package/src/models/route/advisor-trigger.ts +88 -0
- package/src/models/route/config.ts +21 -17
- package/src/models/route/conversation-view.ts +179 -0
- package/src/models/route/decision-evidence.ts +1 -1
- package/src/models/route/decision.ts +114 -19
- package/src/models/route/escalation-control.ts +30 -0
- package/src/models/route/hub-prompts.ts +97 -0
- package/src/models/route/judge-choice.ts +155 -0
- package/src/models/route/judge-replies.ts +102 -0
- package/src/models/route/labels.ts +14 -70
- package/src/models/route/observation-signals.ts +250 -0
- package/src/models/route/plan-execute-choice.ts +27 -0
- package/src/models/route/relay-selector.ts +2 -2
- package/src/models/route/runtime.ts +115 -52
- package/src/models/route/turn-state.ts +77 -0
- package/src/omniroute/client.ts +3 -0
- package/src/ui/guidance-panel.ts +34 -2
- package/src/ui/guidance-view.ts +33 -0
- package/src/ui/plugin.ts +80 -23
- package/src/version.ts +4 -0
- package/templates/AGENTS.block.md +14 -14
- package/templates/adec/README.md +32 -0
- package/templates/adec/ahub.plan-execute.json +23 -0
- package/templates/adec/ahub.stage.json +23 -0
- package/templates/profiles/general.json +1 -1
- package/templates/profiles/research.json +1 -1
- package/templates/profiles/writing.json +1 -1
- package/LICENSES/Apache-2.0.txt +0 -204
- package/src/models/route/advisor.ts +0 -102
- package/src/models/route/escalation.ts +0 -82
- package/src/models/route/judge.ts +0 -23
- package/src/models/route/normalize.ts +0 -103
- package/src/models/route/plan-execute.ts +0 -52
- package/src/models/route/prompts.ts +0 -8
- package/src/models/route/signals.ts +0 -247
- package/src/models/route/state.ts +0 -54
- package/src/models/route/text.ts +0 -61
package/src/hub/inference.ts
CHANGED
|
@@ -3,8 +3,10 @@ import type { MlxHandle } from "../models/mlx.ts";
|
|
|
3
3
|
import type { ChatMessage, OmniRoute } from "../omniroute/client.ts";
|
|
4
4
|
import { CLASSES, type TaskClass } from "./board.ts";
|
|
5
5
|
import { DIGEST, newEnvelope, type Envelope } from "./envelope.ts";
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
6
|
+
import { buildEscalationRequest } from "../models/route/hub-prompts.ts";
|
|
7
|
+
import { captureJudgeConversation } from "../models/route/conversation-view.ts";
|
|
8
|
+
import { parseEscalationReply, type EscalationReply } from "../models/route/judge-replies.ts";
|
|
9
|
+
import type { ProgressConversation } from "./progress.ts";
|
|
8
10
|
|
|
9
11
|
export interface InferenceConfig {
|
|
10
12
|
enabled: boolean;
|
|
@@ -148,8 +150,19 @@ export class Inference {
|
|
|
148
150
|
}
|
|
149
151
|
|
|
150
152
|
/** A closed escalation verdict, or no verdict when inference is unavailable or malformed. */
|
|
151
|
-
async escalate(conversation:
|
|
152
|
-
|
|
153
|
+
async escalate(conversation: ProgressConversation, turn: number): Promise<EscalationReply | undefined> {
|
|
154
|
+
// This grouped shape is produced by ProgressObserver, not accepted from native model JSON.
|
|
155
|
+
const messages: ChatMessage[] = conversation.instructions.map(content => ({ role: "system", content }));
|
|
156
|
+
for (const frame of conversation.messages) {
|
|
157
|
+
messages.push({ role: frame.role, content: frame.content, ...(frame.toolCalls.length ? {
|
|
158
|
+
tool_calls: frame.toolCalls.map(call => ({ id: call.id, type: "function" as const,
|
|
159
|
+
function: { name: call.name, arguments: JSON.stringify(call.arguments) } })),
|
|
160
|
+
} : {}) });
|
|
161
|
+
for (const result of frame.toolResults) messages.push({ role: "tool", tool_call_id: result.toolCallId,
|
|
162
|
+
content: result.content, ...(result.isError === undefined ? {} : { is_error: result.isError }) });
|
|
163
|
+
}
|
|
164
|
+
const request = buildEscalationRequest(captureJudgeConversation(messages), turn);
|
|
165
|
+
if (!request) return undefined;
|
|
153
166
|
const user = request.messages[0]?.content;
|
|
154
167
|
if (!user) return undefined;
|
|
155
168
|
const answer = await this.complete(
|
|
@@ -162,7 +175,7 @@ export class Inference {
|
|
|
162
175
|
"new_evidence (boolean, true only for fresh distinct observations) and reason (short string). Return escalate false and category none when evidence is insufficient.",
|
|
163
176
|
user, request.maxOutputTokens,
|
|
164
177
|
);
|
|
165
|
-
return answer ?
|
|
178
|
+
return answer ? parseEscalationReply(answer) : undefined;
|
|
166
179
|
}
|
|
167
180
|
}
|
|
168
181
|
|
package/src/hub/manager.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { parseGuidanceListQuery, parseGuidanceIdQuery, parseGuidancePageResult, parseGuidanceDiffResult } from "./guidance-variants.ts";
|
|
2
|
+
import { parseGuidanceProbeReceiptExport, probeSha256 } from "./guidance-probes.ts";
|
|
2
3
|
import type { ActionMeta, InboxAnswers } from "@staix/agent-console/contract";
|
|
3
4
|
import { assertExecutableRuntimeRoot } from "./project-runtime-state.ts";
|
|
4
5
|
import { BACKLOG_SPLIT_SCREEN_TIMEOUT_MS } from "./planning.ts";
|
|
@@ -257,7 +258,29 @@ export function projectConsole(options: { registry: Registry; lifecycle: Lifecyc
|
|
|
257
258
|
} catch { return { ok: false, error: "guidance read is unavailable; refresh the task scope or upgrade the hub before retrying" }; }
|
|
258
259
|
finally { client?.close(); }
|
|
259
260
|
};
|
|
260
|
-
|
|
261
|
+
/** Producer-only read port for one probe experiment; never forwards an action, an actor or a person-metadata claim, and writes nothing in the hub. */
|
|
262
|
+
const guidanceProbe = async (target: { projectId: unknown; instanceId: unknown }, input: unknown) => {
|
|
263
|
+
if (options.stopping?.()) return { ok: false, error: "guidance probe status is unavailable while the manager stops; reconnect before retrying" };
|
|
264
|
+
const project = typeof target.projectId === "string" ? registry.get(target.projectId) : undefined;
|
|
265
|
+
if (!project || typeof target.instanceId !== "string" || !target.instanceId) return { ok: false, error: "select a running project and current instance before reading a guidance probe" };
|
|
266
|
+
// A closed query: exactly one exact registered content id. Any other field is refused here rather than forwarded.
|
|
267
|
+
if (!input || typeof input !== "object" || Array.isArray(input) || Object.keys(input).some(key => key !== "id") || !probeSha256((input as { id?: unknown }).id))
|
|
268
|
+
return { ok: false, error: "invalid guidance probe query; use the exact 64-character probe id" };
|
|
269
|
+
const id = (input as { id: string }).id;
|
|
270
|
+
let client: ControlClient | undefined;
|
|
271
|
+
try {
|
|
272
|
+
client = await ControlClient.connect(project.stateDir, { role: "console", projectId: project.id, projectRoot: project.root, instanceId: target.instanceId });
|
|
273
|
+
if (!client.features.includes("guidance_probe_receipts")) return { ok: false, error: "running hub lacks guidance_probe_receipts; upgrade and restart the hub before reading a guidance probe" };
|
|
274
|
+
const result = await client.request({ t: "guidance_probe_receipts", id }, options.forwardTimeoutMs?.("guidance_probe_receipts", 10_000) ?? 10_000);
|
|
275
|
+
if (result.ok !== true) return { ok: false, error: typeof result.error === "string" ? result.error.slice(0, 512) : "guidance probe status is unavailable; refresh the probe id and the current daemon before retrying" };
|
|
276
|
+
const receipts = parseGuidanceProbeReceiptExport(result.receipts);
|
|
277
|
+
// The reply must be the experiment that was asked for: a well-formed export of another probe never satisfies this selection.
|
|
278
|
+
if (!receipts || receipts.status.id !== id) return { ok: false, error: "guidance probe receipts are malformed, fail their digest check or name another probe; do not rely on them" };
|
|
279
|
+
return { ok: true, receipts };
|
|
280
|
+
} catch { return { ok: false, error: "guidance probe status is unavailable; refresh the probe id or upgrade the hub before retrying" }; }
|
|
281
|
+
finally { client?.close(); }
|
|
282
|
+
};
|
|
283
|
+
return { list, act, answer, receipt, consoleControl, lineage, guidance, guidanceProbe };
|
|
261
284
|
}
|
|
262
285
|
|
|
263
286
|
export async function startManager(options: ManagerOptions = {}): Promise<ManagerHandle> {
|
|
@@ -32,7 +32,7 @@ export type ConductorLocalAction = typeof CONDUCTOR_LOCAL_ACTIONS[number];
|
|
|
32
32
|
export const conductorLocalAction = (value:unknown): value is ConductorLocalAction => typeof value==="string" && (CONDUCTOR_LOCAL_ACTIONS as readonly string[]).includes(value);
|
|
33
33
|
/** Daemon-authorized labels. Recovery labels pass the initial role check, then require their separate per-operation proof. */
|
|
34
34
|
export const CONDUCTOR_DAEMON_OPERATIONS = ["roster add","roster remove","stop","queue show","queue resolve","queue discard","settings set","doctor orphans kill","logs","export",
|
|
35
|
-
"board import","intake approve","schedule run","schedule pause","schedule resume","goal link","task unassign","restart","upgrade","recovery resume","recovery abort"] as const;
|
|
35
|
+
"board import","intake approve","schedule run","schedule pause","schedule resume","goal link","task unassign","guidance probe register","guidance probe start","guidance probe show","guidance probe receipts","guidance probe cancel","restart","upgrade","recovery resume","recovery abort"] as const;
|
|
36
36
|
/**
|
|
37
37
|
* #933: forms whose effect runs in the CLI process itself (local files). The daemon admits and audits them once at the handshake (`admit`),
|
|
38
38
|
* after the CLI has validated their arguments. Recovery-bearing restart/upgrade forms use the separate source-issued continuation proof.
|
|
@@ -91,6 +91,15 @@ export function conductorOperation(command:string,args:readonly string[]): Condu
|
|
|
91
91
|
if (command==="intake" && sub==="approve" && words.length===2) return "intake approve";
|
|
92
92
|
if (command==="schedule" && (sub==="run" || sub==="pause" || sub==="resume")) return `schedule ${sub}`;
|
|
93
93
|
if (command==="goal" && args.find(arg=>arg!=="--json")==="link") return "goal link";
|
|
94
|
+
if (command === "guidance" && args[0] === "probe") {
|
|
95
|
+
switch (args[1]) {
|
|
96
|
+
case "register": return "guidance probe register";
|
|
97
|
+
case "start": return "guidance probe start";
|
|
98
|
+
case "show": return "guidance probe show";
|
|
99
|
+
case "receipts": return "guidance probe receipts";
|
|
100
|
+
case "cancel": return "guidance probe cancel";
|
|
101
|
+
}
|
|
102
|
+
}
|
|
94
103
|
return undefined;
|
|
95
104
|
}
|
|
96
105
|
|
|
@@ -119,6 +128,10 @@ export function operationalRequestLabel(value:unknown):string|undefined {
|
|
|
119
128
|
if(message.t==="peer_stop")return "stop";
|
|
120
129
|
if(message.t==="goal_link")return "goal link";
|
|
121
130
|
if(message.t==="task" && typeof message.op==="string" && Object.hasOwn(CONDUCTOR_TASK_OPS,message.op))return CONDUCTOR_TASK_OPS[message.op];
|
|
131
|
+
if (typeof message.t === "string" && message.t.startsWith("guidance_probe_")) {
|
|
132
|
+
const operation = message.t.slice("guidance_probe_".length);
|
|
133
|
+
return ["register", "start", "show", "receipts", "cancel"].includes(operation) ? `guidance probe ${operation}` : undefined;
|
|
134
|
+
}
|
|
122
135
|
if(message.t==="queue" && typeof message.op==="string" && ["show","resolve","discard"].includes(message.op))return `queue ${message.op}`;
|
|
123
136
|
if(message.t==="settings_set"||message.t==="settings_preview")return "settings set";
|
|
124
137
|
return undefined;
|
package/src/hub/peers.ts
CHANGED
|
@@ -53,6 +53,11 @@ export interface PeerAdapter {
|
|
|
53
53
|
readonly standbySessions?: readonly PeerStandbySession[];
|
|
54
54
|
/** The current owner's attachment facts, for display only; absent unless a socket is attached and no newer claim is arriving (#1310). */
|
|
55
55
|
readonly ownerAttachment?: PeerOwnerAttachment;
|
|
56
|
+
/**
|
|
57
|
+
* #1385: the agent-hub client this peer runs in another process, for display only. Absent means the adapter runs inside the daemon, so it runs the daemon's own code; `attached` false
|
|
58
|
+
* means no client is attached now, and an attached client without `version` did not report one. Never admission, compatibility or authorization evidence.
|
|
59
|
+
*/
|
|
60
|
+
readonly hubClient?: { attached: boolean; version?: string };
|
|
56
61
|
/** Person-authorized takeover port. The host still performs its own admission and claim fences. */
|
|
57
62
|
takeover?(standbyId: string | undefined, eligible: (socket: object) => boolean): PeerTakeoverClaim | undefined;
|
|
58
63
|
/** Exact transport ownership check for guarding a selected standby through its asynchronous preface. */
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #1399: a command the hub hands a person runs as printed. The first relay of `ahub queue resolve <id>` failed on its two required flags, the second on the
|
|
3
|
+
* revision and on which checkout hosts the hub, so every hint is built here with the values the hub already knows.
|
|
4
|
+
*/
|
|
5
|
+
export interface DeliveryHint { id: string; revision?: number; state?: string; peer?: string; senders?: readonly string[]; kinds?: readonly string[] }
|
|
6
|
+
|
|
7
|
+
const word = (value: string) => value.replace(/[^\w.,:@~-]/g, "");
|
|
8
|
+
const shellPath = (path: string) => /^[\w./@:+-]+$/.test(path) ? path : `'${path.replace(/'/g, `'\\''`)}'`;
|
|
9
|
+
|
|
10
|
+
/** The other actions the row's state allows, one clause each: the hub cannot tell whether the peer handled an uncertain delivery. */
|
|
11
|
+
export const queueResolveChoices = (state?: string): string => state === "failed"
|
|
12
|
+
? "discard drops it; use --action completed instead if it was already handled"
|
|
13
|
+
: "retry sends it again; use --action completed instead if the peer already handled it, or discard if it is stale";
|
|
14
|
+
|
|
15
|
+
/** `[cd <project> && ]ahub queue resolve <id> [--revision N] --action <suggested> --reason "<kind> from <sender> to <peer>"`. */
|
|
16
|
+
export function queueResolveCommand(row: DeliveryHint, project?: string): string {
|
|
17
|
+
const kinds = [...new Set(row.kinds ?? [])].map(word).filter(Boolean).join(","), senders = [...new Set(row.senders ?? [])].map(word).filter(Boolean).join(",");
|
|
18
|
+
const reason = [kinds, senders && `from ${senders}`, row.peer && `to ${word(row.peer)}`].filter(Boolean).join(" ") || "settled by the person";
|
|
19
|
+
return `${project ? `cd ${shellPath(project)} && ` : ""}ahub queue resolve ${row.id}${Number.isSafeInteger(row.revision) ? ` --revision ${row.revision}` : ""} --action ${row.state === "failed" ? "discard" : "retry"} --reason "${reason}"`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The CLI's own argument rule for `ahub queue resolve`, shared with the test that proves a hint passes it. */
|
|
23
|
+
export function queueResolveArgsValid(action: string | undefined, reason: string | undefined, revision: string | undefined, extra: readonly string[]): boolean {
|
|
24
|
+
return !extra.length && ["completed", "retry", "discard"].includes(action ?? "") && !!reason?.trim() && (revision === undefined || (/^\d+$/.test(revision) && Number.isSafeInteger(Number(revision))));
|
|
25
|
+
}
|
package/src/hub/ports.ts
CHANGED
|
@@ -10,7 +10,7 @@ export const CONTROL = 0;
|
|
|
10
10
|
export const CODEX_APP = 1;
|
|
11
11
|
export const CODEX_PROXY = 2;
|
|
12
12
|
/** Reserved after sidecar retirement (#553); never bind this offset or move later allocations. */
|
|
13
|
-
export const
|
|
13
|
+
export const RESERVED_SIDECAR = 3;
|
|
14
14
|
|
|
15
15
|
/** SQLite-backed project allocation; an explicit JSON path retains the legacy utility API under a lock. */
|
|
16
16
|
export function allocatePorts(projectDir: string, registry?: string): number {
|
package/src/hub/progress.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EscalationControl } from "../models/route/escalation-control.ts";
|
|
2
|
+
import type { EscalationCategory, EscalationReply } from "../models/route/judge-replies.ts";
|
|
2
3
|
import { diagnoseStageResult } from "../models/route/stage-diagnostics.ts";
|
|
3
|
-
import {
|
|
4
|
-
import type { Conversation } from "../models/route/normalize.ts";
|
|
4
|
+
import { repeatedObservationFailure, failureFingerprint as fingerprint, type ToolObservation } from "../models/route/observation-signals.ts";
|
|
5
5
|
import type { HubEvent } from "./events.ts";
|
|
6
6
|
import type { Task } from "./board.ts";
|
|
7
7
|
|
|
@@ -10,7 +10,19 @@ const MAX_STATES = 256;
|
|
|
10
10
|
const MAX_OBSERVATIONS = 28;
|
|
11
11
|
const MAX_TEXT = 500;
|
|
12
12
|
|
|
13
|
-
type NativeToolObservation = ToolObservation & { turn?: string };
|
|
13
|
+
export type NativeToolObservation = ToolObservation & { turn?: string };
|
|
14
|
+
|
|
15
|
+
/** The host-owned progress factory's grouped record, not a provider normalizer schema. */
|
|
16
|
+
export interface ProgressConversation {
|
|
17
|
+
instructions: string[];
|
|
18
|
+
instructionRoles: "system"[];
|
|
19
|
+
messages: {
|
|
20
|
+
role: "user" | "assistant";
|
|
21
|
+
content: string;
|
|
22
|
+
toolCalls: { id: string; name: string; arguments: { command?: string } }[];
|
|
23
|
+
toolResults: { toolCallId: string; content: string; isError?: boolean }[];
|
|
24
|
+
}[];
|
|
25
|
+
}
|
|
14
26
|
|
|
15
27
|
/** Normalize only completed Codex work observations; event payloads and unrelated item text are ignored. */
|
|
16
28
|
export function normalizeCodexObservation(value: unknown): ToolObservation | undefined {
|
|
@@ -40,7 +52,7 @@ interface ProgressState {
|
|
|
40
52
|
task: number;
|
|
41
53
|
at: number;
|
|
42
54
|
observations: NativeToolObservation[];
|
|
43
|
-
escalation:
|
|
55
|
+
escalation: EscalationControl;
|
|
44
56
|
generation: number;
|
|
45
57
|
checking: boolean;
|
|
46
58
|
attemptedTurns: Set<string>;
|
|
@@ -81,7 +93,7 @@ export interface ProgressDeps {
|
|
|
81
93
|
tasks(): Task[];
|
|
82
94
|
/** The same project-wide gate used for turn-free facts: no observation while any PII task is open. */
|
|
83
95
|
isPrivate(): boolean;
|
|
84
|
-
inference: { escalate(conversation:
|
|
96
|
+
inference: { escalate(conversation: ProgressConversation, turn: number): Promise<EscalationReply | undefined> };
|
|
85
97
|
emit(event: HubEvent): void;
|
|
86
98
|
notify(line: string): void;
|
|
87
99
|
now?: () => number;
|
|
@@ -162,8 +174,7 @@ export class ProgressObserver {
|
|
|
162
174
|
|
|
163
175
|
private judgeEligible(state: ProgressState): boolean {
|
|
164
176
|
if (!latestNativeTurn(state.observations) || state.escalation.snapshot().latched) return false;
|
|
165
|
-
const
|
|
166
|
-
const repeatedAcrossTurns = signals.repeatedFailure && repeatedFailureAcrossTurns(state.observations);
|
|
177
|
+
const repeatedAcrossTurns = repeatedObservationFailure(state.observations) === true && repeatedFailureAcrossTurns(state.observations);
|
|
167
178
|
return repeatedAcrossTurns || progressDimensions(state.observations).spinning > 0;
|
|
168
179
|
}
|
|
169
180
|
|
|
@@ -188,7 +199,7 @@ export class ProgressObserver {
|
|
|
188
199
|
let state = this.states.get(id);
|
|
189
200
|
if (!state) {
|
|
190
201
|
if (this.states.size >= MAX_STATES) this.states.delete(this.states.keys().next().value!);
|
|
191
|
-
state = { peer, task, at: this.now(), observations: [], escalation: new
|
|
202
|
+
state = { peer, task, at: this.now(), observations: [], escalation: new EscalationControl(), generation: 0, checking: false, attemptedTurns: new Set(), turn: 0 };
|
|
192
203
|
this.states.set(id, state);
|
|
193
204
|
}
|
|
194
205
|
return state;
|
|
@@ -233,17 +244,13 @@ function repeatedFailureAcrossTurns(observations: readonly NativeToolObservation
|
|
|
233
244
|
return [...turnsByFingerprint.values()].some((turns) => turns.size >= 2);
|
|
234
245
|
}
|
|
235
246
|
|
|
236
|
-
function signalsFor(observations: readonly NativeToolObservation[]): ToolSignals {
|
|
237
|
-
return extractToolSignalsFromObservations(observations, knownTurns(observations).length);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
247
|
function pruneAttemptedTurns(state: ProgressState): void {
|
|
241
248
|
const active = new Set(knownTurns(state.observations));
|
|
242
249
|
for (const turn of state.attemptedTurns) if (!active.has(turn)) state.attemptedTurns.delete(turn);
|
|
243
250
|
}
|
|
244
251
|
|
|
245
|
-
function conversation(observations: readonly NativeToolObservation[], task: Task):
|
|
246
|
-
const frames = new Map<string, { role: "assistant"; content: string; toolCalls: { id: string; name: string; arguments:
|
|
252
|
+
function conversation(observations: readonly NativeToolObservation[], task: Task): ProgressConversation {
|
|
253
|
+
const frames = new Map<string, { role: "assistant"; content: string; toolCalls: { id: string; name: string; arguments: { command?: string } }[]; toolResults: { toolCallId: string; content: string; isError?: boolean }[] }>();
|
|
247
254
|
let nextCall = 0;
|
|
248
255
|
for (const item of observations) {
|
|
249
256
|
const nativeTurn = validTurn(item.turn);
|
|
@@ -264,5 +271,5 @@ function conversation(observations: readonly NativeToolObservation[], task: Task
|
|
|
264
271
|
};
|
|
265
272
|
}
|
|
266
273
|
|
|
267
|
-
export type ProgressVerdict =
|
|
274
|
+
export type ProgressVerdict = EscalationReply;
|
|
268
275
|
export type ProgressCategory = Exclude<EscalationCategory, "none">;
|
package/src/hub/report.ts
CHANGED
|
@@ -114,6 +114,7 @@ export function summarize(events: StampedEvent[]): Report {
|
|
|
114
114
|
const seenSupervision = new Set<string>();
|
|
115
115
|
const lastTier = new Map<string, string>();
|
|
116
116
|
for (const e of events) {
|
|
117
|
+
if (e.type === "route" && e.decisionTarget === "judge") continue;
|
|
117
118
|
r.from ??= e.at;
|
|
118
119
|
r.to = e.at;
|
|
119
120
|
switch (e.type) {
|
|
@@ -304,6 +305,7 @@ export function summarizeByTask(events: StampedEvent[]): TaskReport {
|
|
|
304
305
|
const seenUsage = new Set<string>();
|
|
305
306
|
// Resolve latest class/outcome before rolling usage up: usage may precede the task's history in a slice.
|
|
306
307
|
for (const e of events) {
|
|
308
|
+
if (e.type === "route" && e.decisionTarget === "judge") continue;
|
|
307
309
|
r.from ??= e.at; r.to = e.at;
|
|
308
310
|
if (startsAttribution(e) && reportingSince === null) reportingSince = Date.parse(e.at);
|
|
309
311
|
if (e.type !== "task") continue;
|
package/src/hub/research.ts
CHANGED
|
@@ -157,6 +157,7 @@ export function taskRecords(events: StampedEvent[], projectId: string, writer: T
|
|
|
157
157
|
else delete a.tooling[peer]; // a fingerprint of an earlier attachment does not describe this work: unknown until one comes
|
|
158
158
|
};
|
|
159
159
|
for (const e of events) {
|
|
160
|
+
if (e.type === "route" && e.decisionTarget === "judge") continue;
|
|
160
161
|
// A crash writes no offline: a new run is a new attachment, and no fingerprint from before it describes later work.
|
|
161
162
|
if (e.type === "hub_start") { online.clear(); tooling.clear(); if (startsAttribution(e)) personReportingSince ??= Date.parse(e.at); continue; }
|
|
162
163
|
if (e.type === "state") {
|
package/src/hub/restart.ts
CHANGED
|
@@ -48,6 +48,7 @@ export interface RestartSnapshot {
|
|
|
48
48
|
budgetDigest: string;
|
|
49
49
|
modelOverrides?: { count: number; digest: string };
|
|
50
50
|
guidanceVariants?: { experiments: number; variants: number; digest: string };
|
|
51
|
+
guidanceProbes?: { experiments: number; sessions: number; digest: string };
|
|
51
52
|
executionReferences?: { count: number; digest: string };
|
|
52
53
|
/** Whole captured binding set; portable identities are covered alongside queue/board integrity. */
|
|
53
54
|
externalBindingsDigest?: string;
|
|
@@ -122,6 +123,12 @@ export function readRestartSnapshot(stateDir: string, expected: RestartReadExpec
|
|
|
122
123
|
|| !Number.isSafeInteger(value.experiments) || value.experiments < 0 || !Number.isSafeInteger(value.variants) || value.variants < value.experiments
|
|
123
124
|
|| typeof value.digest !== "string" || value.digest.length !== 64 || !/^[a-f0-9]{64}$/.test(value.digest)) return undefined;
|
|
124
125
|
}
|
|
126
|
+
if (s.integrity && Object.hasOwn(s.integrity, "guidanceProbes")) {
|
|
127
|
+
const value = s.integrity.guidanceProbes;
|
|
128
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.keys(value).sort().join(",") !== "digest,experiments,sessions"
|
|
129
|
+
|| !Number.isSafeInteger(value.experiments) || value.experiments < 0 || !Number.isSafeInteger(value.sessions) || value.sessions < value.experiments
|
|
130
|
+
|| typeof value.digest !== "string" || value.digest.length !== 64 || !/^[a-f0-9]{64}$/.test(value.digest)) return undefined;
|
|
131
|
+
}
|
|
125
132
|
if (s.integrity && Object.hasOwn(s.integrity, "executionReferences")) {
|
|
126
133
|
const value = s.integrity.executionReferences;
|
|
127
134
|
if (!value || typeof value !== "object" || Array.isArray(value) || Object.keys(value).sort().join(",") !== "count,digest"
|
|
@@ -2,7 +2,8 @@ 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 } from "./sdlc-release.ts";
|
|
5
|
+
import { readDocEvidenceDetailed, type DocEvidence, type ReleaseGit, type ReleaseReadiness, type ReleaseReportPolicy } from "./sdlc-release.ts";
|
|
6
|
+
import { DEFAULT_RELEASE_POLICY, hasCommittedReleaseNotes, type ReleasePolicy } from "./sdlc-release-policy.ts";
|
|
6
7
|
import type { SdlcGh } from "./sdlc.ts";
|
|
7
8
|
import type { ReleaseGuardRequest, ReleasePushUpdate } from "../cli/sdlc-release-guard.ts";
|
|
8
9
|
|
|
@@ -13,9 +14,12 @@ const SHA = /^[0-9a-f]{40}$/;
|
|
|
13
14
|
const VERSION = /^[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
14
15
|
export const validReleaseVersion = (value: unknown): value is string => typeof value === "string" && value.length <= 128 && VERSION.test(value);
|
|
15
16
|
export interface ReleaseDocsVerdict { fresh: true; errors: 0; documents: number; digest: string }
|
|
16
|
-
export
|
|
17
|
+
export type ReleaseDocsReceipt = ReleaseDocsVerdict | ({ source: "none" } & { fresh?: never; errors?: never; documents?: never; digest?: never });
|
|
18
|
+
export interface ReleaseAuthorization { schemaVersion: 1; id: string; by: PeerId; commit: string; version: string; at: number; docs: ReleaseDocsReceipt }
|
|
17
19
|
export interface ReleaseAuthorizationPorts {
|
|
18
20
|
git?: ReleaseGit;
|
|
21
|
+
/** Host reader for policy committed at the candidate; absence preserves legacy package/checker policy for existing callers. */
|
|
22
|
+
policy?: (commit: string, git: ReleaseGit) => ReleasePolicy;
|
|
19
23
|
docs?: (root: string) => Promise<DocEvidence | undefined>;
|
|
20
24
|
/** Test seam: the checker program the default reader spawns (#1120). Never set from configuration. */
|
|
21
25
|
checker?: string;
|
|
@@ -28,7 +32,7 @@ export interface ReleaseAuthorizationPorts {
|
|
|
28
32
|
}
|
|
29
33
|
export type ReleaseGuardVerdict = { ok: true; receipts: ReleaseAuthorization[] } | { ok: false; error: string };
|
|
30
34
|
interface Origin { hash: string; urls: string[]; repo?: string }
|
|
31
|
-
interface Entry { receipt: ReleaseAuthorization; origin: Origin }
|
|
35
|
+
interface Entry { receipt: ReleaseAuthorization; origin: Origin; policy: ReleasePolicy; order: number }
|
|
32
36
|
const digest = (value: unknown) => createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
33
37
|
function docsVerdict(value: DocEvidence | undefined, commit: string, version: string): ReleaseDocsVerdict | undefined {
|
|
34
38
|
if (!value || value.schemaVersion !== 1 || value.head !== commit || value.version !== version || value.fresh !== true || value.errors !== 0
|
|
@@ -46,6 +50,7 @@ function githubRepo(url: string): string | undefined {
|
|
|
46
50
|
export class ReleaseAuthorizations {
|
|
47
51
|
private readonly entries = new Map<string, Entry>();
|
|
48
52
|
private latest?: Entry;
|
|
53
|
+
private authorizationOrder = 0;
|
|
49
54
|
constructor(private readonly root: string, private readonly ports: ReleaseAuthorizationPorts) {}
|
|
50
55
|
private current(): void { if (this.ports.current?.() === false) throw new ReleaseAuthorizationError("release authorization unavailable during lifecycle transition"); }
|
|
51
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). */
|
|
@@ -75,6 +80,13 @@ export class ReleaseAuthorizations {
|
|
|
75
80
|
if (result.code !== 0 || Buffer.byteLength(result.stdout) > 256 * 1024) throw new ReleaseAuthorizationError("release target evidence unavailable");
|
|
76
81
|
return result.stdout.trim();
|
|
77
82
|
}
|
|
83
|
+
private policy(git: ReleaseGit, commit: string): ReleasePolicy {
|
|
84
|
+
try { return structuredClone(this.ports.policy ? this.ports.policy(commit, git) : DEFAULT_RELEASE_POLICY); }
|
|
85
|
+
catch (error) {
|
|
86
|
+
const detail = error instanceof Error && error.message.length <= 300 ? `: ${error.message}` : "";
|
|
87
|
+
throw new ReleaseAuthorizationError(`committed release policy unavailable${detail}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
78
90
|
private origin(git: ReleaseGit, remote = "origin"): Origin {
|
|
79
91
|
if (!/^[A-Za-z0-9_.-]{1,128}$/.test(remote) || remote.startsWith("-")) throw new ReleaseAuthorizationError("release guard requires a configured named remote");
|
|
80
92
|
const urls = this.read(git, ["remote", "get-url", "--push", "--all", remote]).split("\n");
|
|
@@ -91,36 +103,111 @@ export class ReleaseAuthorizations {
|
|
|
91
103
|
if (!SHA.test(commit)) throw new ReleaseAuthorizationError("release commit unavailable");
|
|
92
104
|
return commit;
|
|
93
105
|
}
|
|
94
|
-
private
|
|
106
|
+
private packageVersion(git: ReleaseGit, commit: string, policy?: ReleasePolicy, purpose: "authorization" | "npm" = "authorization"): string {
|
|
95
107
|
if (!SHA.test(commit)) throw new ReleaseAuthorizationError("invalid release commit");
|
|
96
108
|
let value: unknown;
|
|
97
|
-
try { value = JSON.parse(this.read(git, ["show", `${commit}:package.json`])).version; } catch {
|
|
98
|
-
|
|
109
|
+
try { value = JSON.parse(this.read(git, ["show", `${commit}:package.json`])).version; } catch {
|
|
110
|
+
if (!this.ports.policy) throw new ReleaseAuthorizationError("committed package version unavailable");
|
|
111
|
+
throw new ReleaseAuthorizationError(purpose === "npm"
|
|
112
|
+
? "npm publish needs a committed package.json version to identify its target; add package.json with the target version"
|
|
113
|
+
: `committed package version unavailable; set release.version to release-notes or none in .agenthub/config.json and commit it${policy ? ` (current source: ${policy.version.source})` : ""}`);
|
|
114
|
+
}
|
|
115
|
+
if (!validReleaseVersion(value)) {
|
|
116
|
+
if (!this.ports.policy) throw new ReleaseAuthorizationError("committed package version unavailable");
|
|
117
|
+
throw new ReleaseAuthorizationError(purpose === "npm"
|
|
118
|
+
? "npm publish needs a valid committed package.json version to identify its target; add package.json with the target version"
|
|
119
|
+
: "committed package version unavailable; set release.version to release-notes or none in .agenthub/config.json and commit it");
|
|
120
|
+
}
|
|
99
121
|
return value;
|
|
100
122
|
}
|
|
123
|
+
private version(git: ReleaseGit, commit: string, policy: ReleasePolicy, requested?: string): string {
|
|
124
|
+
if (policy.version.source === "package.json") return this.packageVersion(git, commit, policy);
|
|
125
|
+
if (policy.version.source === "none") {
|
|
126
|
+
if (!requested || !validReleaseVersion(requested)) throw new ReleaseAuthorizationError("release.version is none; provide the requested semantic version and exact candidate commit");
|
|
127
|
+
return requested;
|
|
128
|
+
}
|
|
129
|
+
if (!requested || !validReleaseVersion(requested)) throw new ReleaseAuthorizationError("release.version is release-notes; provide the requested semantic version and exact candidate commit");
|
|
130
|
+
const path = policy.version.notesPath.replace("{version}", requested);
|
|
131
|
+
if (!hasCommittedReleaseNotes(git, commit, path)) throw new ReleaseAuthorizationError(`committed release notes missing: ${path}; add ${path} at the candidate commit`);
|
|
132
|
+
return requested;
|
|
133
|
+
}
|
|
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);
|
|
136
|
+
}
|
|
101
137
|
async authorize(by: string, version: unknown, expectedCommit: unknown): Promise<ReleaseAuthorization> {
|
|
102
138
|
this.actor(by);
|
|
103
139
|
if (!validReleaseVersion(version) || typeof expectedCommit !== "string" || !SHA.test(expectedCommit)) throw new ReleaseAuthorizationError("authorization needs an exact version and candidate commit");
|
|
104
140
|
this.current();
|
|
105
|
-
const git = this.git(), commit = this.commit(git, "HEAD"), origin = this.origin(git);
|
|
106
|
-
if (commit !== expectedCommit
|
|
107
|
-
const
|
|
141
|
+
const git = this.git(), commit = this.commit(git, "HEAD"), origin = this.origin(git), policy = this.policy(git, commit);
|
|
142
|
+
if (commit !== expectedCommit) throw new ReleaseAuthorizationError("candidate commit differs from the person's request");
|
|
143
|
+
const sourceVersion = this.version(git, commit, policy, version);
|
|
144
|
+
if (sourceVersion !== version) throw new ReleaseAuthorizationError(policy.version.source === "package.json" && this.ports.policy
|
|
145
|
+
? `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
|
+
: "candidate version differs from the person's request for the configured source");
|
|
147
|
+
const docs = await this.docsPolicy(commit, policy, version);
|
|
108
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");
|
|
109
149
|
this.current(); this.actor(by);
|
|
110
|
-
|
|
150
|
+
const currentPolicy = this.policy(git, commit);
|
|
151
|
+
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");
|
|
111
152
|
this.current(); this.actor(by);
|
|
112
153
|
const receipt: ReleaseAuthorization = { schemaVersion: 1, id: randomUUID(), by, commit, version, at: (this.ports.now ?? Date.now)(), docs };
|
|
113
154
|
if (!this.ports.record(structuredClone(receipt))) throw new ReleaseAuthorizationError("release approval audit could not be recorded");
|
|
114
|
-
const entry = { receipt, origin };
|
|
155
|
+
const entry = { receipt, origin, policy: structuredClone(policy), order: ++this.authorizationOrder };
|
|
115
156
|
this.entries.set(`${version}:${commit}`, entry); this.latest = entry;
|
|
116
157
|
// ponytail: retain at most 64 approvals in this daemon generation; older candidates need a new person approval.
|
|
117
158
|
if (this.entries.size > 64) this.entries.delete(this.entries.keys().next().value!);
|
|
118
159
|
return structuredClone(receipt);
|
|
119
160
|
}
|
|
161
|
+
/** Host-only report source selector. It reads no caller-selected version and never writes the ledger. */
|
|
162
|
+
reportPolicy(head: string, repo: string): ReleaseReportPolicy | undefined {
|
|
163
|
+
const unavailable = (versionSource: ReleaseReportPolicy["versionSource"] = "unknown", docsSource: ReleaseReportPolicy["docsSource"] = "unknown"): ReleaseReportPolicy => ({ versionSource, docsSource, authorization: "unavailable" });
|
|
164
|
+
if (!SHA.test(head) || !/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(repo)) return unavailable();
|
|
165
|
+
const git = this.git();
|
|
166
|
+
let policy: ReleasePolicy;
|
|
167
|
+
try { policy = this.policy(git, head); } catch { return unavailable(); }
|
|
168
|
+
if (policy.version.source === "package.json" && policy.docs.source === "checker") return;
|
|
169
|
+
let packageVersion: string | undefined;
|
|
170
|
+
if (policy.version.source === "package.json") {
|
|
171
|
+
try { packageVersion = this.packageVersion(git, head, policy); } catch { return unavailable(policy.version.source, policy.docs.source); }
|
|
172
|
+
}
|
|
173
|
+
let origin: Origin;
|
|
174
|
+
try {
|
|
175
|
+
if (this.commit(git, "HEAD") !== head) return { versionSource: policy.version.source, docsSource: policy.docs.source, authorization: "stale", ...(packageVersion ? { version: packageVersion } : {}) };
|
|
176
|
+
origin = this.origin(git);
|
|
177
|
+
} catch { return unavailable(policy.version.source, policy.docs.source); }
|
|
178
|
+
const candidates = [...this.entries.values()].filter(entry => entry.receipt.commit === head
|
|
179
|
+
&& entry.origin.hash === origin.hash && entry.origin.repo?.toLowerCase() === repo.toLowerCase()
|
|
180
|
+
&& JSON.stringify(entry.policy) === JSON.stringify(policy)
|
|
181
|
+
&& (packageVersion === undefined || entry.receipt.version === packageVersion));
|
|
182
|
+
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 } : {}) };
|
|
184
|
+
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" };
|
|
186
|
+
if (policy.version.source === "release-notes") {
|
|
187
|
+
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" };
|
|
189
|
+
}
|
|
190
|
+
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" };
|
|
192
|
+
}
|
|
193
|
+
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" };
|
|
195
|
+
} catch { return unavailable(policy.version.source, policy.docs.source); }
|
|
196
|
+
return { versionSource: policy.version.source, docsSource: policy.docs.source, authorization: "matched", version };
|
|
197
|
+
}
|
|
120
198
|
private matched(git: ReleaseGit, version: string, commit: string, remote?: string, url?: string): ReleaseAuthorization {
|
|
121
199
|
this.current();
|
|
122
200
|
const entry = this.entries.get(`${version}:${commit}`);
|
|
123
|
-
if (!entry
|
|
201
|
+
if (!entry) throw new ReleaseAuthorizationError("no matching person release authorization; ask the person to authorize this commit and version");
|
|
202
|
+
const policy = this.policy(git, commit);
|
|
203
|
+
if (JSON.stringify(policy) !== JSON.stringify(entry.policy)) throw new ReleaseAuthorizationError("committed release policy differs from the authorized candidate");
|
|
204
|
+
const candidateVersion = this.version(git, commit, policy, version);
|
|
205
|
+
if (candidateVersion !== version) {
|
|
206
|
+
if (!this.ports.policy) throw new ReleaseAuthorizationError("no matching person release authorization; ask the person to authorize this commit and version");
|
|
207
|
+
throw new ReleaseAuthorizationError(policy.version.source === "package.json"
|
|
208
|
+
? `committed package.json version is ${candidateVersion}, not ${version}; update package.json and commit the requested release version`
|
|
209
|
+
: `committed ${policy.version.source} source identifies ${candidateVersion}, not ${version}; update the committed release source`);
|
|
210
|
+
}
|
|
124
211
|
const origin = this.origin(git);
|
|
125
212
|
if (origin.hash !== entry.origin.hash || remote && this.origin(git, remote).hash !== origin.hash || url !== undefined && !origin.urls.includes(url)) throw new ReleaseAuthorizationError("release remote differs from the authorized project");
|
|
126
213
|
return structuredClone(entry.receipt);
|
|
@@ -134,11 +221,13 @@ export class ReleaseAuthorizations {
|
|
|
134
221
|
}
|
|
135
222
|
if (request.kind === "npm-publish") {
|
|
136
223
|
if (!releaseTrackedClean(this.root, git)) throw new ReleaseAuthorizationError("npm publish requires a clean tracked worktree");
|
|
137
|
-
const commit = this.commit(git, "HEAD"), version = this.
|
|
224
|
+
const commit = this.commit(git, "HEAD"), version = this.packageVersion(git, commit, undefined, "npm");
|
|
138
225
|
const receipt = this.matched(git, version, commit);
|
|
139
|
-
const docs = await this.
|
|
226
|
+
const policy = this.policy(git, commit), docs = await this.docsPolicy(commit, policy, version);
|
|
140
227
|
this.current();
|
|
141
|
-
|
|
228
|
+
const docsMatch = !!docs && ("source" in docs ? "source" in receipt.docs && receipt.docs.source === "none"
|
|
229
|
+
: "digest" in receipt.docs && docs.digest === receipt.docs.digest);
|
|
230
|
+
if (!docsMatch || this.commit(git, "HEAD") !== commit || JSON.stringify(this.policy(git, commit)) !== JSON.stringify(policy) || !releaseTrackedClean(this.root, git)) throw new ReleaseAuthorizationError("publish checkout, release policy or documentation evidence changed");
|
|
142
231
|
return { ok: true, receipts: [this.matched(git, version, commit)] };
|
|
143
232
|
}
|
|
144
233
|
const origin = this.origin(git), repo = origin.repo;
|
|
@@ -177,10 +266,43 @@ export class ReleaseAuthorizations {
|
|
|
177
266
|
} catch (error) { return { ok: false, error: releaseAuthorizationError(error) }; }
|
|
178
267
|
}
|
|
179
268
|
report<T extends ReleaseReadiness>(report: T): T & { authorization?: { state: "matched" | "stale"; receipt: ReleaseAuthorization } } {
|
|
269
|
+
if (report.releasePolicy) {
|
|
270
|
+
const policy = report.releasePolicy;
|
|
271
|
+
if (policy.authorization !== "matched" || !report.head || !report.version) return report;
|
|
272
|
+
let current: ReleaseReportPolicy | undefined;
|
|
273
|
+
try { current = this.reportPolicy(report.head, report.repo); }
|
|
274
|
+
catch { current = { versionSource: policy.versionSource, docsSource: policy.docsSource, authorization: "unavailable" }; }
|
|
275
|
+
const entry = this.entries.get(`${report.version}:${report.head}`);
|
|
276
|
+
let matched = !!entry && current?.authorization === "matched" && current.version === report.version
|
|
277
|
+
&& current.versionSource === policy.versionSource && current.docsSource === policy.docsSource;
|
|
278
|
+
try {
|
|
279
|
+
if (matched) {
|
|
280
|
+
const git = this.git(), candidatePolicy = this.policy(git, entry!.receipt.commit);
|
|
281
|
+
const verdict = report.documents ? docsVerdict(report.documents, report.head, report.version) : undefined;
|
|
282
|
+
matched = JSON.stringify(candidatePolicy) === JSON.stringify(entry!.policy)
|
|
283
|
+
&& ("source" in entry!.receipt.docs ? candidatePolicy.docs.source === "none" : !!verdict && verdict.digest === entry!.receipt.docs.digest)
|
|
284
|
+
&& this.origin(git).hash === entry!.origin.hash;
|
|
285
|
+
}
|
|
286
|
+
} catch { matched = false; }
|
|
287
|
+
const releasePolicy = { ...policy, authorization: matched ? "matched" as const : "stale" as const };
|
|
288
|
+
if (!matched) return { ...report, releasePolicy, sourceReady: false, ready: false,
|
|
289
|
+
blockers: [...new Set([...report.blockers, "release authorization source is stale; authorize the exact candidate version again"])],
|
|
290
|
+
...(entry ? { authorization: { state: "stale" as const, receipt: structuredClone(entry.receipt) } } : {}) };
|
|
291
|
+
const blockers = report.blockers.map(item => item === "native acceptance and person release decision unverified" ? "native acceptance unverified" : item);
|
|
292
|
+
return { ...report, releasePolicy, blockers, authorization: { state: "matched", receipt: structuredClone(entry!.receipt) } };
|
|
293
|
+
}
|
|
180
294
|
if (!this.latest) return report;
|
|
181
295
|
const entry = this.entries.get(`${report.version}:${report.head}`), verdict = report.head && report.version ? docsVerdict(report.documents, report.head, report.version) : undefined;
|
|
182
|
-
let matched = !!entry && !!entry.origin.repo && entry.origin.repo.toLowerCase() === report.repo.toLowerCase()
|
|
183
|
-
try {
|
|
296
|
+
let matched = !!entry && !!entry.origin.repo && entry.origin.repo.toLowerCase() === report.repo.toLowerCase();
|
|
297
|
+
try {
|
|
298
|
+
if (matched) {
|
|
299
|
+
const git = this.git(), policy = this.policy(git, entry!.receipt.commit);
|
|
300
|
+
matched = JSON.stringify(policy) === JSON.stringify(entry!.policy)
|
|
301
|
+
&& this.version(git, entry!.receipt.commit, policy, report.version) === report.version
|
|
302
|
+
&& ("source" in entry!.receipt.docs ? policy.docs.source === "none" : !!verdict && verdict.digest === entry!.receipt.docs.digest)
|
|
303
|
+
&& this.origin(git).hash === entry!.origin.hash;
|
|
304
|
+
}
|
|
305
|
+
} catch { matched = false; }
|
|
184
306
|
const receipt = structuredClone((matched ? entry! : this.latest).receipt);
|
|
185
307
|
const blockers = matched ? report.blockers.map(item => item === "native acceptance and person release decision unverified" ? "native acceptance unverified" : item) : report.blockers;
|
|
186
308
|
return { ...report, blockers, authorization: { state: matched ? "matched" : "stale", receipt } };
|