@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.
Files changed (121) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +6 -2
  3. package/THIRD_PARTY_NOTICES.md +0 -18
  4. package/docs/agent-notes/README.md +13 -3
  5. package/docs/agent-notes/daemon.md +4 -4
  6. package/docs/agent-notes/local-worker.md +1 -0
  7. package/docs/agent-notes/models.md +2 -1
  8. package/docs/agent-notes/tasks.md +1 -1
  9. package/docs/agent-notes/tests.md +1 -2
  10. package/docs/contracts/companion-cli-v1.json +70 -0
  11. package/docs/design/adapters.md +43 -2
  12. package/docs/design/agent-hub-architecture.md +9 -1
  13. package/docs/design/guidance-probes.md +1167 -0
  14. package/docs/design/model-routes.md +437 -12
  15. package/docs/dogfood.md +12 -13
  16. package/docs/events.md +20 -1
  17. package/docs/memory.md +3 -3
  18. package/docs/operations.md +123 -151
  19. package/docs/profiles.md +1 -1
  20. package/docs/quickstart.md +15 -3
  21. package/docs/research.md +1 -1
  22. package/docs/sdlc.md +5 -3
  23. package/docs/security.md +25 -1
  24. package/docs/specs/2026-09-19-agent-hub-design.md +9 -7
  25. package/docs/specs/2026-10-04-switchyard-source-port-design.md +3 -1
  26. package/docs/verification/2026-11-08-qwen-0269-model-setter-1317.md +25 -11
  27. package/docs/verification/2026-11-09-qwen-0270-model-setter-1317.md +21 -6
  28. package/docs/verification/2026-11-11-0.37.0.md +40 -0
  29. package/docs/verification/2026-11-11-0.38.0.md +41 -0
  30. package/docs/verification/2026-11-11-guidance-probe-t2-1226.md +153 -0
  31. package/docs/verification/2026-11-11-guidance-probe-t3-1226.md +85 -0
  32. package/docs/verification/2026-11-11-guidance-probe-t4-1226.md +65 -0
  33. package/docs/verification/2026-11-11-qwen-setter-suggestions-off.md +167 -0
  34. package/docs/verified.json +25 -25
  35. package/package.json +3 -4
  36. package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
  37. package/plugins/agent-hub/kimi-hook.js +2403 -1444
  38. package/plugins/agent-hub/server.js +2480 -1509
  39. package/src/adapters/channel-peer.ts +7 -1
  40. package/src/adapters/claude-channel.ts +2 -1
  41. package/src/adapters/compat.ts +1 -1
  42. package/src/adapters/local-probe.ts +233 -0
  43. package/src/adapters/local-worker.ts +232 -21
  44. package/src/cli/console-state.ts +25 -6
  45. package/src/cli/console-versions.ts +99 -0
  46. package/src/cli/console.ts +13 -1
  47. package/src/cli/help.ts +2 -1
  48. package/src/cli/init.ts +3 -1
  49. package/src/cli/install-paths.ts +7 -2
  50. package/src/cli/main.ts +78 -7
  51. package/src/cli/output.ts +8 -4
  52. package/src/cli/runtime-version-warning.ts +2 -2
  53. package/src/cli/sdlc-output.ts +9 -5
  54. package/src/cli/upgrade-runtime.ts +1 -1
  55. package/src/hub/bus.ts +2 -2
  56. package/src/hub/config-apply.ts +4 -2
  57. package/src/hub/config-trust.ts +6 -1
  58. package/src/hub/control-client.ts +5 -2
  59. package/src/hub/daemon.ts +195 -13
  60. package/src/hub/envelope.ts +6 -1
  61. package/src/hub/events.ts +3 -2
  62. package/src/hub/guidance-probe-store.ts +1044 -0
  63. package/src/hub/guidance-probes.ts +692 -0
  64. package/src/hub/inference.ts +18 -5
  65. package/src/hub/manager.ts +24 -1
  66. package/src/hub/operational-authority.ts +14 -1
  67. package/src/hub/peers.ts +5 -0
  68. package/src/hub/person-command.ts +25 -0
  69. package/src/hub/ports.ts +1 -1
  70. package/src/hub/progress.ts +23 -16
  71. package/src/hub/report.ts +2 -0
  72. package/src/hub/research.ts +1 -0
  73. package/src/hub/restart.ts +7 -0
  74. package/src/hub/sdlc-release-authorization.ts +139 -17
  75. package/src/hub/sdlc-release-policy.ts +100 -0
  76. package/src/hub/sdlc-release.ts +59 -7
  77. package/src/hub/supervision.ts +3 -2
  78. package/src/hub/tasks.ts +363 -7
  79. package/src/local/probe-errors.ts +28 -0
  80. package/src/local/probe-sandbox.ts +224 -0
  81. package/src/local/probe-types.ts +110 -0
  82. package/src/local/probe-workspace.ts +426 -0
  83. package/src/local/sandbox.ts +71 -2
  84. package/src/local/tools.ts +135 -9
  85. package/src/models/route/advisor-trigger.ts +88 -0
  86. package/src/models/route/config.ts +21 -17
  87. package/src/models/route/conversation-view.ts +179 -0
  88. package/src/models/route/decision-evidence.ts +1 -1
  89. package/src/models/route/decision.ts +114 -19
  90. package/src/models/route/escalation-control.ts +30 -0
  91. package/src/models/route/hub-prompts.ts +97 -0
  92. package/src/models/route/judge-choice.ts +155 -0
  93. package/src/models/route/judge-replies.ts +102 -0
  94. package/src/models/route/labels.ts +14 -70
  95. package/src/models/route/observation-signals.ts +250 -0
  96. package/src/models/route/plan-execute-choice.ts +27 -0
  97. package/src/models/route/relay-selector.ts +2 -2
  98. package/src/models/route/runtime.ts +115 -52
  99. package/src/models/route/turn-state.ts +77 -0
  100. package/src/omniroute/client.ts +3 -0
  101. package/src/ui/guidance-panel.ts +34 -2
  102. package/src/ui/guidance-view.ts +33 -0
  103. package/src/ui/plugin.ts +80 -23
  104. package/src/version.ts +4 -0
  105. package/templates/AGENTS.block.md +14 -14
  106. package/templates/adec/README.md +32 -0
  107. package/templates/adec/ahub.plan-execute.json +23 -0
  108. package/templates/adec/ahub.stage.json +23 -0
  109. package/templates/profiles/general.json +1 -1
  110. package/templates/profiles/research.json +1 -1
  111. package/templates/profiles/writing.json +1 -1
  112. package/LICENSES/Apache-2.0.txt +0 -204
  113. package/src/models/route/advisor.ts +0 -102
  114. package/src/models/route/escalation.ts +0 -82
  115. package/src/models/route/judge.ts +0 -23
  116. package/src/models/route/normalize.ts +0 -103
  117. package/src/models/route/plan-execute.ts +0 -52
  118. package/src/models/route/prompts.ts +0 -8
  119. package/src/models/route/signals.ts +0 -247
  120. package/src/models/route/state.ts +0 -54
  121. package/src/models/route/text.ts +0 -61
package/src/hub/tasks.ts CHANGED
@@ -1,3 +1,12 @@
1
+ import { requireConductor } from "./conductor.ts";
2
+ import { pathCandidates } from "@staix/agent-mem";
3
+ import { renderGuidanceVariantV1 } from "./guidance-variants.ts";
4
+ import { GuidanceProbeFixtureHost, type GuidanceProbeStore } from "./guidance-probe-store.ts";
5
+ import { GuidanceProbeError, GUIDANCE_PROBE_STOP_TIMEOUT_MS, GUIDANCE_PROBE_FENCE_INTERVAL_MS, guidanceProbeCanonical, guidanceProbeManifestKey,
6
+ parseGuidanceProbeRegistration, parseGuidanceProbeReceiptExport, probeHash, probeSha256, probeInteger, probeSessionGeneration,
7
+ type ProbeChildBinding, type ProbeStoredState, type ProbePublicReceipt, type ProbePublicStatus, type ProbeHostBinding,
8
+ type ProbeReceiptExport, type ProbeExportSlot, type ProbeReceiptV1, type ProbeRetentionState,
9
+ type ProbeAdmissionRecheck, type ProbeReservation, type ProbeSlot, type GuidanceProbeFakePorts, type GuidanceProbeManifestV1, type ProbeWorkerFramePreparer } from "./guidance-probes.ts";
1
10
  import { GuidanceVariantError, GUIDANCE_PAGE_MAX_RECORDS, GUIDANCE_REPLY_MAX_BYTES, guidanceVariantSectionDiff, guidanceProtectedSectionNames, parseGuidancePageResult, parseGuidanceDiffResult, parseGuidanceListQuery, parseGuidanceIdQuery, guidancePageCursor, guidancePageAfter, guidanceVariantMetadata, parseGuidanceVariantV1, validateGuidanceVariantV1, parseGuidanceSelector, type GuidanceVariantV1, type GuidanceStoredRecord, type GuidanceSelector, type GuidanceIdSelector, type GuidanceWriteFence, type GuidanceWriteReceipt, type GuidanceCurrent, type GuidancePublicRecord, type GuidancePageResult, type GuidanceDiffResult, type GuidanceReadResult } from "./guidance-variants.ts";
2
11
  import { buildEntryDiagnostic } from "./build-entry.ts";
3
12
  import { taskShowAllowed } from "./conductor.ts";
@@ -55,7 +64,7 @@ import { adoptMergeGates, guardedMerge, mergeModeFor, mergeView, readAdoptMergeE
55
64
  import { mirrorVerdict as mirrorToGitHub, type MirrorVerdict } from "./sdlc-mirror.ts";
56
65
  import { CODE_SCOPE_LINE, evidenceOnlyNotice, type ReviewScope } from "./review-scope.ts";
57
66
  import { DEFAULT_MAX_NITS, parseReviewFindings, findingsForHead, findingHead as resolveFindingHead, findingTally, type ReviewFinding, type ReviewFindingSet } from "./review-findings.ts";
58
- import { readReleaseReadiness } from "./sdlc-release.ts";
67
+ import { readReleaseReadiness, type ReleaseReportPolicy } from "./sdlc-release.ts";
59
68
  import { loadRoleCatalog, roleIdentity, taskRole, taskRoleText, type RoleCatalog } from "./roles.ts";
60
69
  import { matchesPolicy, matchesPolicyLexically, policyRealPath, insideRoot } from "./path-policy.ts";
61
70
  import { isDenied } from "../local/deny.ts";
@@ -131,6 +140,15 @@ interface PreparedSpecInspection {
131
140
  export interface ReleaseWindow { at: number; host: boolean; quota: boolean; idle: boolean; reasons: string[]; current?: () => boolean; close?: () => Promise<void>; }
132
141
 
133
142
  export interface TasksDeps {
143
+ /** Private host-owned probe ledger and fixture ports. No configuration, wire or model-selected runner. */
144
+ guidanceProbes?: {
145
+ store: GuidanceProbeStore;
146
+ fakePorts?: GuidanceProbeFakePorts;
147
+ prepareWorkerFrame?: ProbeWorkerFramePreparer;
148
+ prepareEditorFrame?: (state: ProbeStoredState, slot: ProbeSlot) => string | Promise<string>;
149
+ session?: (by: PeerId) => { generation: string | number; nativeSession: string | null; requestConnectionId: string; current: () => void } | undefined;
150
+ timer?: { set(callback: () => void, ms: number): unknown; clear(handle: unknown): void };
151
+ };
134
152
  adapterCatalog?: ProjectAdapterCatalog;
135
153
  /** Host-bound evidence only; absent/expired observations never admit a release cut. */
136
154
  releaseWindow?: () => Promise<ReleaseWindow>;
@@ -186,7 +204,8 @@ export interface TasksDeps {
186
204
  specsRead?: (action: "check" | "covers", paths: readonly string[]) => SpecsCheckReport | SpecsCoverReport;
187
205
  /** Host-verified existing symbols at this task's admitted completion head; never plan guesses. */
188
206
  memorySymbolNodes?: (task: Task) => MemorySymbolNodes | undefined;
189
- sdlc?: { config: () => SdlcConfig; gh?: SdlcGh };
207
+ /** Host-only release report selector; derives its answer from committed policy and the in-memory authorization ledger. */
208
+ sdlc?: { config: () => SdlcConfig; gh?: SdlcGh; reportPolicy?: (head: string, repo: string) => ReleaseReportPolicy | undefined };
190
209
  /** #785 P1b: the per-head CI watcher's bounds; tests shorten them, the defaults are `CI_WATCH_*` in `ci-watch.ts`. */
191
210
  ciWatch?: { deadlineMs?: number; pollMs?: number };
192
211
  /** #785 P1c: `tasks.auto_pull`, read at each capacity release so a reload applies to the next one; absent or false pulls nothing. */
@@ -509,7 +528,17 @@ function hasReviewAnchorInput(raw: unknown): boolean {
509
528
  } catch { return true; }
510
529
  }
511
530
 
531
+ interface GuidanceProbeRuntime {
532
+ id: string; by: PeerId; controller: AbortController; current: () => ProbeAdmissionRecheck;
533
+ requestedRevision: number; variantId?: string;
534
+ reservation?: ProbeReservation; promise?: Promise<ProbePublicReceipt>; stopPromise?: Promise<void>;
535
+ launched: boolean; launchSettled: boolean; stopSettled: boolean; stopKnown: boolean; stopRequested: boolean;
536
+ watch?: { handle: unknown }; failure?: Error;
537
+ }
512
538
  export class Tasks {
539
+ private guidanceProbeStopping = false;
540
+ private guidanceProbeAdmissions = 0;
541
+ private readonly guidanceProbeActive = new Map<string, GuidanceProbeRuntime>();
513
542
  private readonly findingPlacements = new WeakMap<ReviewReadiness, { binding: string; placements: Map<string, ReviewAnchorStatus>; placementOnly: boolean }>();
514
543
  private findingPlacementBinding(task: Task): string {
515
544
  return JSON.stringify([task.id, task.created, this.reviewHead(task), task.refs.paths, task.plan, this.reviewFindingSets(task)]);
@@ -2991,7 +3020,7 @@ export class Tasks {
2991
3020
  if (excluded.includes(peer)) continue;
2992
3021
  const queue = this.d.bus.queueSummary(peer), wip = this.wip(peer, task.id), limit = this.wipLimit(peer);
2993
3022
  if (wip >= limit) parts.push(`${peer} WIP full (${wip}/${limit}); no eligible planner WIP capacity`);
2994
- else if (queue.heldBy) parts.push(`${peer} has a held queue (a delivery is held; resolve it with ahub queue list)`);
3023
+ else if (queue.heldBy) parts.push(`${peer} has a held queue (delivery ${queue.heldBy} is held; ahub queue show ${queue.heldBy} prints the full resolve command for the person)`);
2995
3024
  else if (queue.needsReview > 0) parts.push(`${peer} has ${queue.needsReview} delivery(ies) in needs_review`);
2996
3025
  const refusal = queueBackpressure(peer, pressure.queueBackpressure, peerEntry(pressure.queues, peer), pressure.now ?? NaN);
2997
3026
  if (refusal) parts.push(`${peer} ${refusal.reason}`);
@@ -4954,18 +4983,345 @@ export class Tasks {
4954
4983
  } catch { return { state: "unavailable" }; }
4955
4984
  }
4956
4985
 
4957
- private guidanceRequest(by: PeerId): () => void {
4986
+ private guidanceProbeTimer(): NonNullable<NonNullable<TasksDeps["guidanceProbes"]>["timer"]> {
4987
+ return this.d.guidanceProbes?.timer ?? {
4988
+ set: (callback, ms) => { const timer = setTimeout(callback, ms); timer.unref?.(); return timer; },
4989
+ clear: handle => clearTimeout(handle as ReturnType<typeof setTimeout>),
4990
+ };
4991
+ }
4992
+ /** Owned in-process work only, not persisted held lanes or a quiescence assertion. */
4993
+ guidanceProbesPending = (): number => this.guidanceProbeAdmissions + this.guidanceProbeActive.size;
4994
+ async stopGuidanceProbes(): Promise<void> {
4995
+ this.guidanceProbeStopping = true;
4996
+ const active = [...this.guidanceProbeActive.values()];
4997
+ for (const entry of active) this.guidanceProbeAbort(entry, "observation", true);
4998
+ if (this.guidanceProbesPending() === 0) return;
4999
+ await this.guidanceProbeDrain(active);
5000
+ if (this.guidanceProbesPending() !== 0) throw new Error("guidance probe admission drain is unconfirmed; retain project storage and explicitly retry after owned callbacks settle");
5001
+ }
5002
+ private async guidanceProbeDrain(active: GuidanceProbeRuntime[]): Promise<void> {
5003
+ const settled = Promise.allSettled(active.flatMap(entry => [entry.promise, entry.stopPromise].filter((value): value is Promise<ProbePublicReceipt> | Promise<void> => value !== undefined)));
5004
+ let timeout: { handle: unknown } | undefined;
5005
+ try {
5006
+ await Promise.race([settled, new Promise<never>((_resolve, reject) => {
5007
+ timeout = { handle: this.guidanceProbeTimer().set(() => reject(new Error("guidance probe stop is unconfirmed after the owned drain bound; retain the held lane and explicitly drain after its fixture callbacks settle")), GUIDANCE_PROBE_STOP_TIMEOUT_MS) };
5008
+ })]);
5009
+ if (active.some(entry => this.guidanceProbeActive.get(entry.id) === entry)) throw new Error("guidance probe stop evidence is unknown; retain owned handles and explicitly retry the drain after matching fixture stop evidence");
5010
+ } finally { if (timeout !== undefined) this.guidanceProbeTimer().clear(timeout.handle); }
5011
+ }
5012
+ private guidanceProbeClearWatch(entry: GuidanceProbeRuntime): void {
5013
+ if (entry.watch !== undefined) { this.guidanceProbeTimer().clear(entry.watch.handle); entry.watch = undefined; }
5014
+ }
5015
+ private guidanceProbeRetire(entry: GuidanceProbeRuntime): void {
5016
+ if (this.guidanceProbeActive.get(entry.id) !== entry || !entry.launchSettled || entry.stopRequested && (!entry.stopSettled || !entry.stopKnown)) return;
5017
+ this.guidanceProbeClearWatch(entry); this.guidanceProbeActive.delete(entry.id);
5018
+ }
5019
+ private guidanceProbeAbort(entry: GuidanceProbeRuntime, reason: "elapsed" | "observation", explicitStop = false): void {
5020
+ if (this.guidanceProbeActive.get(entry.id) !== entry) return;
5021
+ this.guidanceProbeClearWatch(entry);
5022
+ if (entry.reservation) {
5023
+ try { this.d.guidanceProbes!.store.latchHold(entry.reservation, reason); }
5024
+ catch { entry.failure = new Error("guidance probe hold bookkeeping is unconfirmed; inspect retained state before any further work"); }
5025
+ }
5026
+ entry.controller.abort();
5027
+ if (!entry.launched || !entry.reservation) { this.guidanceProbeRetire(entry); return; }
5028
+ if (entry.stopRequested && (!entry.stopSettled || entry.stopKnown || !explicitStop)) return;
5029
+ const reservation = entry.reservation, ports = this.d.guidanceProbes!.fakePorts!;
5030
+ entry.stopRequested = true; entry.stopSettled = false; entry.stopKnown = false;
5031
+ entry.stopPromise = (async () => {
5032
+ try {
5033
+ const result = await ports.stop({ reservation }, new AbortController().signal);
5034
+ entry.stopKnown = result?.stopped === "known_fixture" && guidanceProbeCanonical(result.reservation) === guidanceProbeCanonical(reservation);
5035
+ if (!entry.stopKnown) entry.failure = new Error("guidance probe stop evidence is unknown; inspect the owned reservation and explicitly drain without replaying it");
5036
+ } catch { entry.failure = new Error("guidance probe stop failed; retain owned handles and explicitly drain before closing project storage"); }
5037
+ finally { entry.stopSettled = true; this.guidanceProbeRetire(entry); }
5038
+ })();
5039
+ }
5040
+ private guidanceProbeWatch(entry: GuidanceProbeRuntime): void {
5041
+ if (this.guidanceProbeActive.get(entry.id) !== entry || entry.controller.signal.aborted) return;
5042
+ try {
5043
+ entry.current();
5044
+ const state = this.d.guidanceProbes!.store.read({ projectKey: this.guidanceProject(), id: entry.id });
5045
+ if (!state || !entry.reservation || state.firstReservedAt === null) throw new Error("owned probe clock is unavailable");
5046
+ const now = this.d.now?.() ?? Date.now(), elapsed = now - state.firstReservedAt;
5047
+ if (!probeInteger(elapsed) || elapsed < state.counters.elapsedHighWaterMs || state.admissionHold !== "none") { this.guidanceProbeAbort(entry, "elapsed"); return; }
5048
+ const remaining = state.registration.manifest.limits.elapsedMs - elapsed;
5049
+ if (remaining <= 0) { this.guidanceProbeAbort(entry, "elapsed"); return; }
5050
+ entry.watch = { handle: this.guidanceProbeTimer().set(() => {
5051
+ if (this.guidanceProbeActive.get(entry.id) !== entry || entry.controller.signal.aborted) return;
5052
+ entry.watch = undefined; this.guidanceProbeWatch(entry);
5053
+ }, Math.min(GUIDANCE_PROBE_FENCE_INTERVAL_MS, remaining)) };
5054
+ } catch { this.guidanceProbeAbort(entry, "observation"); }
5055
+ }
5056
+ private guidanceProbeProjection(state: ProbeStoredState, already = false): ProbePublicStatus {
5057
+ const holds = state.admissionHold !== "none" || state.counters.usageUnknown;
5058
+ const authoring: ProbePublicStatus["authoring"] = state.sessions.some(item => item.child?.authoring === "uncontrolled") ? "uncontrolled"
5059
+ : state.sessions.some(item => item.child?.authoring === "admitted_fixture") ? "admitted_fixture" : "unknown";
5060
+ const launchedSessions = state.sessions.filter(item => item.coverage.launchExposed);
5061
+ const verifiedCoverage = launchedSessions.length > 0 && launchedSessions.every(item => item.coverage.coverageVerified)
5062
+ && state.sessions.filter(item => item.state === "closed_fixture").every(item => item.coverage.coverageVerified)
5063
+ && state.sessions.every(item => item.state !== "failed_known" || item.coverage.preLaunchFailure || item.coverage.coverageVerified);
5064
+ const evidence: ProbePublicReceipt["evidence"] = state.counters.workerAttempts + state.counters.editorAttempts === 0 ? "declaration"
5065
+ : holds || !verifiedCoverage || state.sessions.some(item => ["reserved", "running", "unknown_held"].includes(item.state)) ? "unknown" : "fixture";
5066
+ return { ...state.receipt, already, taskId: state.registration.manifest.task.id,
5067
+ experimentId: this.guidancePublicField(state.registration.manifest.experimentId), evidence,
5068
+ counters: { ...state.counters }, cancelRequested: state.cancelRequested, notNeeded: state.notNeeded, authoring,
5069
+ comparable: state.receipt.state === "closed_fixture" && !holds && verifiedCoverage && authoring === "admitted_fixture" };
5070
+ }
5071
+ private guidanceProbeReceipt(state: ProbeStoredState, already = false): ProbePublicReceipt {
5072
+ const { counters: _counters, cancelRequested: _cancelRequested, notNeeded: _notNeeded, comparable: _comparable, authoring: _authoring, ...result } = this.guidanceProbeProjection(state, already);
5073
+ return result;
5074
+ }
5075
+ private guidanceProbeState(by: PeerId, id: string, check: () => void): ProbeStoredState {
5076
+ check();
5077
+ if (!probeSha256(id)) throw new PreEffectToolRefusal("guidance probe id is invalid; use the exact registered content id");
5078
+ if (!this.d.guidanceProbes) throw new PreEffectToolRefusal("guidance probe storage is unavailable; restart a supporting hub before retrying");
5079
+ const state = this.d.guidanceProbes.store.read({ projectKey: this.guidanceProject(), id });
5080
+ if (!state) throw new PreEffectToolRefusal("guidance probe is unavailable; inspect a registered declaration in this project");
5081
+ this.guidanceProbeTask(by, state.registration.manifest.task, false); check(); return state;
5082
+ }
5083
+ private guidanceProbeHost(by: PeerId, manifest: GuidanceProbeManifestV1, request: ReturnType<Tasks["guidanceProbeRequest"]>, history?: ProbeHostBinding): ProbeHostBinding {
5084
+ request.check();
5085
+ const projectKey = this.guidanceProject();
5086
+ if (projectKey !== manifest.projectKey) throw new PreEffectToolRefusal("guidance probe project changed; register within the current project namespace");
5087
+ const task = this.guidanceProbeTask(by, manifest.task, history === undefined);
5088
+ const binding = { projectKey, actor: by, task: { id: task.id, created: task.created, flowRevision: task.history.length },
5089
+ sessionGeneration: request.generation, nativeSession: request.nativeSession, requestConnectionId: request.requestConnectionId };
5090
+ // A narrowing cancellation carries its original baseline as history, never a new applicability grant.
5091
+ if (history) return { ...binding, role: history.role, baselineGuidance: history.baselineGuidance };
5092
+ const role = this.guidanceRole(task);
5093
+ return { ...binding, role: { id: role.id, layer: role.layer, baselineSha256: role.hash }, baselineGuidance: taskRoleText(role) };
5094
+ }
5095
+ private guidanceProbeSnapshotClear(state: ProbeStoredState["registration"]): boolean {
5096
+ return Object.entries(state.snapshots).every(([field, value]) => {
5097
+ const text = field === "dataPolicy" ? guidanceProbeCanonical(value) : value as string;
5098
+ return this.nameable(text) && !looksSecret(text);
5099
+ });
5100
+ }
5101
+ private guidanceProbeRenderedClear(text: string): boolean {
5102
+ if (!this.nameable(text) || looksSecret(text)) return false;
5103
+ const policy = [...this.d.deny ?? [], ...this.d.piiPaths ?? []];
5104
+ if ([...pathCandidates(text)].some(candidate => matchesPolicyLexically(this.d.cwd, candidate, policy))) return false;
5105
+ return !policy.some(entry => {
5106
+ const literal = entry.replace(/^\.\//, "").split(/[*?[\]{}]/)[0]!.replace(/\/+$/, "");
5107
+ return /[/\s]/.test(literal) && text.includes(literal);
5108
+ });
5109
+ }
5110
+ async guidanceProbeRegister(by: PeerId, value: unknown): Promise<ProbePublicReceipt> {
5111
+ const request = this.guidanceProbeRequest(by), registration = parseGuidanceProbeRegistration(value);
5112
+ if (!registration) throw new PreEffectToolRefusal("guidance probe declaration is invalid or oversized; use the closed V1 envelope without trimming its snapshots");
5113
+ const binding = this.guidanceProbeHost(by, registration.manifest, request);
5114
+ if (!this.guidanceProbeSnapshotClear(registration)) throw new PreEffectToolRefusal("guidance probe inputs are private; register public task-local inputs in a current public session");
5115
+ this.guidanceProbeAdmissions++;
5116
+ let wrote = false;
5117
+ try {
5118
+ const saved = this.d.guidanceProbes!.store.register(registration, binding, () => {
5119
+ if (!this.guidanceProbeSnapshotClear(registration)) throw new PreEffectToolRefusal("guidance probe input policy changed; inspect its current public scope before retrying");
5120
+ return this.guidanceProbeHost(by, registration.manifest, request);
5121
+ });
5122
+ wrote = !saved.already;
5123
+ const state = this.guidanceProbeState(by, saved.id, request.check);
5124
+ return this.guidanceProbeReceipt(state, saved.already);
5125
+ } catch (error) {
5126
+ if (!wrote && (error instanceof PreEffectToolRefusal || error instanceof GuidanceProbeError && error.reason !== "storage")) throw error;
5127
+ throw new Error("guidance probe registration is unconfirmed; inspect retained state before explicitly retrying");
5128
+ }
5129
+ finally { this.guidanceProbeAdmissions--; }
5130
+ }
5131
+ async guidanceProbeShow(by: PeerId, id: string): Promise<ProbePublicStatus> {
5132
+ const request = this.guidanceProbeRequest(by), state = this.guidanceProbeState(by, id, request.check);
5133
+ request.check();
5134
+ const status = this.guidanceProbeProjection(state);
5135
+ // T3 (#1226): the sealed receipts can only make the verdict stricter, never grant one the older expression refused. The reasons and the denominator stay in
5136
+ // the store's private status; public show keeps just this flag. A store that cannot be read is not comparable.
5137
+ if (!status.comparable) return status;
5138
+ let sealedComparable = false;
5139
+ try { sealedComparable = this.d.guidanceProbes!.store.outcome({ projectKey: this.guidanceProject(), id: state.receipt.id })?.comparability.comparable === true; } catch { /* fail closed */ }
5140
+ return sealedComparable ? status : { ...status, comparable: false };
5141
+ }
5142
+ /**
5143
+ * T4 (#1226): the producer receipt reader and export. The same person/conductor, session and task fences as `guidanceProbeShow`, and read-only: it launches,
5144
+ * reserves, writes and prunes nothing. It carries the status, the outcome denominator and the sealed receipts, each re-verified against its own digest by the
5145
+ * Store, so a tampered row refuses the whole read instead of being skipped. Output names are model-written, so each receipt passes the same screen as any
5146
+ * other public field; one that fails is replaced by its digest alone and the slot says `withheld`. A retained directory is a state, never a path.
5147
+ */
5148
+ async guidanceProbeReceipts(by: PeerId, id: string): Promise<ProbeReceiptExport> {
5149
+ const request = this.guidanceProbeRequest(by), state = this.guidanceProbeState(by, id, request.check);
5150
+ request.check();
5151
+ const store = this.d.guidanceProbes!.store, key = { projectKey: this.guidanceProject(), id: state.receipt.id };
5152
+ const status = await this.guidanceProbeShow(by, id);
5153
+ let receipts: ProbeReceiptV1[], outcome: ReturnType<GuidanceProbeStore["outcome"]>, retention: Map<string, ProbeRetentionState>;
5154
+ try { receipts = store.receipts(key); outcome = store.outcome(key); retention = store.retentionStates(key); }
5155
+ catch (error) { if (error instanceof GuidanceProbeError) throw error; throw new GuidanceProbeError("storage"); }
5156
+ if (!outcome) throw new GuidanceProbeError("storage");
5157
+ request.check();
5158
+ const bySlot = new Map(receipts.map(item => [item.slotId, item]));
5159
+ const slots: ProbeExportSlot[] = state.registration.manifest.slots.map((slot, index) => {
5160
+ const session = state.sessions[index]!, receipt = bySlot.get(slot.id);
5161
+ const shown = receipt !== undefined && this.guidanceProbeReceiptClear(receipt);
5162
+ return { slotId: slot.id, stage: slot.stage, role: slot.role, arm: slot.arm, state: session.state, receipt: shown ? receipt : null,
5163
+ receiptDigest: receipt?.digest ?? null, withheld: receipt !== undefined && !shown, retention: retention.get(slot.id) ?? "none" };
5164
+ });
5165
+ // The sealed verdict can only make the public one stricter, exactly as in `show`: a status that already refused stays refused.
5166
+ const comparable = status.comparable && outcome.comparability.comparable;
5167
+ const result: ProbeReceiptExport = { v: 1, status: { ...status, comparable }, comparable, reasons: outcome.comparability.reasons, counts: outcome.counts, slots };
5168
+ // What leaves this process is what the consumer's parser will accept: a result that does not round-trip is a storage fault, never a partial answer.
5169
+ const checked = parseGuidanceProbeReceiptExport(JSON.parse(JSON.stringify(result)));
5170
+ if (!checked) throw new GuidanceProbeError("storage");
5171
+ return checked;
5172
+ }
5173
+ /** Every free-text name a receipt carries (output paths, exclusions, the served model) must pass the public-field screen; the digest alone is kept otherwise. */
5174
+ private guidanceProbeReceiptClear(receipt: ProbeReceiptV1): boolean {
5175
+ const names = [receipt.experimentId, receipt.slotId, receipt.servedModel ?? "", ...receipt.output.entries.map(item => item.relative), ...receipt.output.excluded.map(item => item.relative)];
5176
+ return names.every(text => text === "" || this.guidanceFieldAllowed(text));
5177
+ }
5178
+ async guidanceProbeStart(by: PeerId, id: string, revision: number, variantId?: string): Promise<ProbePublicReceipt> {
5179
+ const request = this.guidanceProbeRequest(by), state = this.guidanceProbeState(by, id, request.check);
5180
+ const host = this.guidanceProbeHost(by, state.registration.manifest, request);
5181
+ if (!probeInteger(revision) || variantId !== undefined && !probeSha256(variantId))
5182
+ throw new PreEffectToolRefusal("guidance probe start selector is invalid; use its current CAS revision and exact G1 id");
5183
+ const dependency = this.d.guidanceProbes!;
5184
+ // No production runner: refuse before original-child selection, G1 raw read, binding, reservation or timer.
5185
+ if (!dependency.fakePorts) throw new PreEffectToolRefusal("guidance probe runner is unavailable in production T1; use fake-only fixtures, not a live launch");
5186
+ const key = { projectKey: host.projectKey, id }, original = dependency.store.startSelector(key, revision);
5187
+ if (original && (original.actor !== by || original.sessionGeneration !== host.sessionGeneration || original.nativeSession !== host.nativeSession
5188
+ || original.requestConnectionId !== host.requestConnectionId)) throw new PreEffectToolRefusal("guidance probe original start belongs to another request session; inspect its retained id without replaying it");
5189
+ const slot = original ? state.registration.manifest.slots.find(item => item.id === original.slotId)
5190
+ : state.registration.manifest.slots.find(item => state.sessions.find(session => session.slotId === item.id)?.state === "planned");
5191
+ if (!slot) throw new PreEffectToolRefusal("guidance probe has no eligible slot; inspect its retained terminal or held state");
5192
+ if (original && original.variantId !== (variantId ?? null)) throw new PreEffectToolRefusal("guidance probe original selector differs; inspect its original G1 id without rebinding the start");
5193
+ const needsVariant = slot.role === "worker" && slot.arm !== "baseline";
5194
+ if (needsVariant !== (variantId !== undefined)) throw new PreEffectToolRefusal("guidance probe next worker needs its existing G1 id only; use --variant for the next non-baseline worker");
5195
+ const current = (): ProbeAdmissionRecheck => {
5196
+ const fresh = this.guidanceProbeHost(by, state.registration.manifest, request);
5197
+ if (!this.guidanceProbeSnapshotClear(state.registration)) throw new PreEffectToolRefusal("guidance probe input privacy changed; retain its declaration and use current public inputs");
5198
+ return { host: fresh, ...(variantId === undefined ? {} : { child: this.guidanceProbeVariantBinding(by, this.guidanceProbeTask(by, state.registration.manifest.task, true), variantId) }) };
5199
+ };
5200
+ const prepared = current();
5201
+ const active = this.guidanceProbeActive.get(id);
5202
+ if (active) {
5203
+ if (active.requestedRevision !== revision || active.variantId !== variantId)
5204
+ throw new PreEffectToolRefusal("another owned probe attempt is still settling; inspect its state before explicitly starting the next stage");
5205
+ const captured = active.current().host;
5206
+ if (captured.actor !== host.actor || captured.sessionGeneration !== host.sessionGeneration || captured.nativeSession !== host.nativeSession
5207
+ || captured.requestConnectionId !== host.requestConnectionId)
5208
+ throw new PreEffectToolRefusal("guidance probe active start belongs to another request session; inspect its retained id without replaying it");
5209
+ // Frame preparation has not granted a reservation. A duplicate is only a read of truthful current metadata.
5210
+ if (!active.reservation) return this.guidanceProbeReceipt(this.guidanceProbeState(by, id, request.check), true);
5211
+ const replay = dependency.store.reserveSession({ key, expectedRevision: revision, ...prepared, now: this.d.now?.() ?? Date.now() }, current);
5212
+ if (replay.kind !== "existing") throw new Error("guidance probe start is unconfirmed; inspect retained state before any further work");
5213
+ return this.guidanceProbeReceipt(this.guidanceProbeState(by, id, request.check), true);
5214
+ }
5215
+ const entry: GuidanceProbeRuntime = { id, by, requestedRevision: revision, ...(variantId === undefined ? {} : { variantId }), controller: new AbortController(), current, launched: false, launchSettled: false,
5216
+ stopRequested: false, stopSettled: false, stopKnown: false };
5217
+ this.guidanceProbeActive.set(id, entry);
5218
+ const ports: GuidanceProbeFakePorts = {
5219
+ launch: async (input, effects, signal) => {
5220
+ entry.reservation = input.reservation;
5221
+ this.guidanceProbeWatch(entry);
5222
+ if (signal.aborted) throw new Error("owned probe was aborted before launch");
5223
+ entry.launched = true;
5224
+ return dependency.fakePorts!.launch(input, effects, signal);
5225
+ },
5226
+ stop: (input, signal) => dependency.fakePorts!.stop(input, signal),
5227
+ ...(dependency.fakePorts.discardRetained ? { discardRetained: record => dependency.fakePorts!.discardRetained!(record) } : {}),
5228
+ };
5229
+ let reserved = false, returned = false;
5230
+ const runner = new GuidanceProbeFixtureHost(dependency.store, { ports, revalidate: current, now: () => this.d.now?.() ?? Date.now(),
5231
+ prepareWorkerFrame: dependency.prepareWorkerFrame, prepareEditorFrame: dependency.prepareEditorFrame, onReserved: () => { reserved = true; } });
5232
+ entry.promise = (async () => {
5233
+ try {
5234
+ const saved = await runner.start({ key, expectedRevision: revision, ...prepared, now: this.d.now?.() ?? Date.now() }, entry.controller.signal);
5235
+ returned = true;
5236
+ if (saved.state === "unknown_held" && entry.launched) {
5237
+ this.guidanceProbeAbort(entry, "observation", true);
5238
+ if (!entry.stopPromise) throw new Error("owned probe stop was not recorded; retain the held lane and explicitly inspect its outcome");
5239
+ await entry.stopPromise;
5240
+ }
5241
+ request.check();
5242
+ if (entry.failure) throw entry.failure;
5243
+ return this.guidanceProbeReceipt(this.guidanceProbeState(by, id, request.check), saved.already);
5244
+ } catch (error) {
5245
+ this.guidanceProbeAbort(entry, "observation");
5246
+ if (!reserved && !returned && (error instanceof PreEffectToolRefusal || error instanceof GuidanceProbeError && error.reason !== "storage")) throw error;
5247
+ throw new Error("guidance probe attempt outcome is unconfirmed; inspect its retained id without replaying work");
5248
+ } finally { entry.launchSettled = true; this.guidanceProbeClearWatch(entry); this.guidanceProbeRetire(entry); }
5249
+ })();
5250
+ return entry.promise;
5251
+ }
5252
+ async guidanceProbeCancel(by: PeerId, id: string, revision: number): Promise<ProbePublicReceipt> {
5253
+ const request = this.guidanceProbeRequest(by), state = this.guidanceProbeState(by, id, request.check);
5254
+ if (!probeInteger(revision)) throw new PreEffectToolRefusal("guidance probe cancellation revision is invalid; inspect its current CAS revision");
5255
+ const current = () => this.guidanceProbeHost(by, state.registration.manifest, request, state.binding), host = current();
5256
+ try {
5257
+ const saved = this.d.guidanceProbes!.store.cancelIntent({ key: { projectKey: host.projectKey, id }, expectedRevision: revision, host }, current);
5258
+ const entry = this.guidanceProbeActive.get(id);
5259
+ if (entry) { this.guidanceProbeAbort(entry, "observation", true); await this.guidanceProbeDrain([entry]); }
5260
+ request.check();
5261
+ return this.guidanceProbeReceipt(this.guidanceProbeState(by, id, request.check), saved.already);
5262
+ } catch { throw new Error("guidance probe cancellation is unconfirmed; inspect its retained intent and owned drain before retrying"); }
5263
+ }
5264
+ private guidanceProbeRequest(by: PeerId): { check: () => void; generation: number | string; nativeSession: string | null; requestConnectionId: string } {
5265
+ const request = this.guidanceRequest(by, "probe");
5266
+ if (!this.personOrConductor(by)) throw new PreEffectToolRefusal("guidance probes require the person or current configured conductor; use an admitted operational session");
5267
+ const session = this.d.guidanceProbes?.session?.(by);
5268
+ if (!session || !probeSessionGeneration(session.generation) || !executionText(session.requestConnectionId, EXECUTION_REFERENCE_LIMITS.id)
5269
+ || session.nativeSession !== null && !executionText(session.nativeSession, EXECUTION_REFERENCE_LIMITS.id))
5270
+ throw new PreEffectToolRefusal("guidance probe request session is unavailable; reconnect through a current authenticated project connection");
5271
+ const sessionCurrent = session.current;
5272
+ const current = () => {
5273
+ sessionCurrent(); request();
5274
+ if (this.guidanceProbeStopping) throw new PreEffectToolRefusal("guidance probe admission is stopping; inspect retained work after the owned drain");
5275
+ if (this.d.reviewOnly?.(by)) throw new PreEffectToolRefusal("guidance probes are unavailable in a review-only context; use a current public operational session");
5276
+ if (by !== USER) {
5277
+ try { requireConductor(by, this.d.roles); }
5278
+ catch { throw new PreEffectToolRefusal("guidance probe conductor authority changed; refresh the configured role before retrying"); }
5279
+ if (!this.d.bus.isRostered(by)) throw new PreEffectToolRefusal("guidance probe conductor is not currently rostered; restore current membership before retrying");
5280
+ }
5281
+ };
5282
+ current(); return { check: current, generation: session.generation, nativeSession: session.nativeSession, requestConnectionId: session.requestConnectionId };
5283
+ }
5284
+ private guidanceProbeTask(by: PeerId, selected: { id: number; created: number; flowRevision: number }, admission: boolean): Task {
5285
+ const task = this.guidanceTask(by, { taskId: selected.id, taskCreated: selected.created }, false);
5286
+ if (admission && (task.history.length !== selected.flowRevision || !["in_progress", "changes_requested"].includes(task.state)))
5287
+ throw new PreEffectToolRefusal(`guidance probe admission is stale or task state is ${task.state}; accept current work in in_progress or changes_requested and reload its revision`);
5288
+ return task;
5289
+ }
5290
+ /** Actual probe actor only; the source owner validates/hydrates G1, never an impersonated read or separate SQL parser. */
5291
+ private guidanceProbeVariantBinding(by: PeerId, task: Task, variantId: string): ProbeChildBinding {
5292
+ if (by !== USER) {
5293
+ try { requireConductor(by, this.d.roles); }
5294
+ catch { throw new PreEffectToolRefusal("guidance probe conductor authority changed; reconnect in a current operational session"); }
5295
+ if (!this.d.bus.isRostered(by)) throw new PreEffectToolRefusal("guidance probe conductor membership changed; restore current roster membership before retrying");
5296
+ }
5297
+ const current = this.guidanceProbeTask(by, { id: task.id, created: task.created, flowRevision: task.history.length }, true);
5298
+ if (!probeSha256(variantId)) throw new PreEffectToolRefusal("guidance probe variant selector is invalid; choose an existing current G1 content id");
5299
+ const project = this.guidanceProject(), role = this.guidanceRole(current);
5300
+ const experiment = this.guidanceStorage("read", () => this.d.board.guidanceVariantLocation(project, current.id, current.created, variantId));
5301
+ const record = experiment === undefined ? undefined : this.guidanceStorage("read", () => this.d.board.guidanceVariants(project, current.id, current.created, experiment)).find(item => item.variant.id === variantId);
5302
+ if (!record || record.withdrawn || record.variant.flowRevision !== current.history.length || record.variant.baseline.roleId !== role.id
5303
+ || record.variant.baseline.layer !== role.layer || record.variant.baseline.sha256 !== role.hash)
5304
+ throw new PreEffectToolRefusal("guidance probe G1 is unavailable, withdrawn or stale; separately admit a current owner/person variant before retrying");
5305
+ const guidance = renderGuidanceVariantV1(record.variant);
5306
+ if (!this.guidanceProbeRenderedClear(guidance))
5307
+ throw new PreEffectToolRefusal("guidance probe handoff text is private; use a current public G1 before retrying");
5308
+ return { variantId, candidateSha256: record.variant.candidate.sha256, guidanceSha256: probeHash(guidance), guidance,
5309
+ task: { id: current.id, created: current.created, flowRevision: current.history.length },
5310
+ role: { id: role.id, layer: role.layer, baselineSha256: role.hash }, authoring: "uncontrolled", sourceSessionId: null };
5311
+ }
5312
+
5313
+ private guidanceRequest(by: PeerId, mode: "guidance" | "probe" = "guidance"): () => void {
4958
5314
  if (!executionText(by, EXECUTION_REFERENCE_LIMITS.id) || !executionLinkActor(by) || by === HUB || by === "admin")
4959
5315
  throw new PreEffectToolRefusal("guidance requires a current local task actor; ask the task owner or the person");
4960
5316
  const request = this.requestCheck(by, () => this.studyHold());
4961
5317
  const peer = by === USER ? undefined : this.d.bus.peers.get(by), generation = peer?.sessionGeneration, session = peer?.nativeSession;
4962
- const delivery = () => this.d.bus.lastDeliveredTo(by).map(item => item.id).join("\n"), delivered = delivery();
5318
+ const delivery = () => this.d.bus.lastDeliveredTo(by).map(item => item.id).join("\n"), delivered = mode === "guidance" ? delivery() : undefined;
4963
5319
  const check = () => {
4964
5320
  request();
4965
5321
  if (this.d.privateTurn?.(by) || this.reviewObserverTurn(by))
4966
5322
  throw new PreEffectToolRefusal("guidance is unavailable during private or review input; retry in a public owner context");
4967
5323
  if (by !== USER && (!peer || this.d.bus.peers.get(by) !== peer || "sessionGeneration" in peer && generation === undefined
4968
- || peer.sessionGeneration !== generation || peer.nativeSession !== session || delivery() !== delivered))
5324
+ || peer.sessionGeneration !== generation || peer.nativeSession !== session || mode === "guidance" && delivery() !== delivered))
4969
5325
  throw new PreEffectToolRefusal("guidance request session changed or is unavailable; reload the task in the current session before retrying");
4970
5326
  };
4971
5327
  check(); return check;
@@ -6331,7 +6687,7 @@ export class Tasks {
6331
6687
  } catch { /* an approval never fails because of the merge check */ }
6332
6688
  }
6333
6689
  async releaseReadiness(repo: string, liveIssues: number[]) {
6334
- const report = await readReleaseReadiness(this.d.cwd, repo, liveIssues, { gh: this.d.sdlc?.gh });
6690
+ const report = await readReleaseReadiness(this.d.cwd, repo, liveIssues, { gh: this.d.sdlc?.gh, reportPolicy: this.d.sdlc?.reportPolicy });
6335
6691
  if (report.documents) report.documents.documents = report.documents.documents.map(d => {
6336
6692
  if (d.path && (!this.nameable(d.path) || matchesPolicy(this.d.cwd, d.path, this.d.piiPaths ?? [], true))) { const { path: _privatePath, ...metadata } = d; return metadata; }
6337
6693
  return d;
@@ -0,0 +1,28 @@
1
+ /** Closed probe-only causes. They carry no physical path, model text, actor id or native diagnostic. */
2
+ export type ProbeToolRefusalCode = "outside_workspace" | "invalid_path" | "unadmitted_write" | "file_ceiling"
3
+ | "hardlinked_target" | "nonregular_target" | "authority_stopped" | "target_changed" | "tool_unavailable"
4
+ | "workspace_ceiling" | "confinement_unavailable" | "token_bound_unavailable" | "token_ceiling";
5
+ const reasons: Record<ProbeToolRefusalCode, string> = {
6
+ outside_workspace: "path is outside the admitted logical workspace; use a declared /workspace path",
7
+ invalid_path: "path is not an admitted relative name; use a declared /workspace file without traversal, dependency or internal-temp components",
8
+ unadmitted_write: "write target is not admitted; choose a target from the supplied logical /workspace/scratch or /workspace/output list",
9
+ file_ceiling: "file exceeds the 1 MiB file ceiling; reduce the file before requesting another admitted operation",
10
+ hardlinked_target: "hardlinked target is not a private probe file; ask the host for a fresh regular file",
11
+ nonregular_target: "target is not a regular probe file; choose a declared regular file",
12
+ authority_stopped: "probe authority is stopped or unavailable; stop this session and ask the host for a newly admitted session",
13
+ target_changed: "probe target or reservation changed; stop this operation and ask the host to inspect the admitted state",
14
+ tool_unavailable: "tool is unavailable in the confined probe; use only the admitted read, write and edit tools",
15
+ workspace_ceiling: "workspace reservation exceeds its admitted workspace ceiling (at most 64 MiB); reduce the declared data or ask the host for a new bounded session",
16
+ confinement_unavailable: "OS confinement or owned cleanup is unverified; stop this session and ask the host to inspect confinement and retained resources",
17
+ token_bound_unavailable: "trusted token upper-bound proof is unavailable; ask the host to prepare a frozen configuration before another model call",
18
+ token_ceiling: "model call exceeds the admitted token ceiling; reduce its declared input or ask the host for a new bounded session",
19
+ };
20
+ const unknownReason = "confined probe operation refused; stop this operation and ask the host to inspect the admitted state";
21
+ export class ProbeToolRefusal extends Error {
22
+ constructor(readonly code: ProbeToolRefusalCode) { super(Object.hasOwn(reasons, code) ? reasons[code] : unknownReason); }
23
+ }
24
+ /** Never classify from native/error prose or reuse an arbitrary Error.message. */
25
+ export function formatProbeToolRefusal(error: unknown): string {
26
+ const reason = error instanceof ProbeToolRefusal && Object.hasOwn(reasons, error.code) ? reasons[error.code] : unknownReason;
27
+ return `error: ${reason}`;
28
+ }