@akagilnc/pi-workflow-roles 0.1.2091 → 0.1.2096

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.
@@ -34,6 +34,7 @@ import {
34
34
  COLLECTOR_WAIT_TOOL,
35
35
  } from "../collector-ledger.ts";
36
36
  import { ENGINE_DETOUR_TOOL_NAME } from "../engine-detour.ts";
37
+ import { readEngineLaborFallbackFieldFrom } from "../engine-labor-fallback.ts";
37
38
  import {
38
39
  JUDGE_OUTPUT_TOOL_NAME,
39
40
  type JudgeVerdict,
@@ -1060,7 +1061,12 @@ function judgeDecisiveFacts(
1060
1061
  verdict: object,
1061
1062
  judgeStatus: JudgeVerdict["judgeStatus"],
1062
1063
  ): Record<string, unknown> {
1063
- const facts: Record<string, unknown> = { judgeStatus, ...auditNoReceiptDecisiveFact(verdict) };
1064
+ const facts: Record<string, unknown> = {
1065
+ judgeStatus,
1066
+ ...auditNoReceiptDecisiveFact(verdict),
1067
+ // #380: spread sole-built field; do not re-key here (S1).
1068
+ ...readEngineLaborFallbackFieldFrom(verdict),
1069
+ };
1064
1070
  if (judgeStatus === "continue") {
1065
1071
  const fix = safelyRead(verdict, "fix");
1066
1072
  if (fix.readable && isRecord(fix.value)) {
@@ -1260,6 +1266,8 @@ function reviewerDecisiveFacts(
1260
1266
  reportAxes,
1261
1267
  acceptedBatchPresent: acceptedBatch.readable && acceptedBatch.value !== undefined,
1262
1268
  ...auditNoReceiptDecisiveFact(candidate),
1269
+ // #380: spread sole-built field; do not re-key here (S1).
1270
+ ...readEngineLaborFallbackFieldFrom(candidate),
1263
1271
  };
1264
1272
  if (status.readable && typeof status.value === "string") facts.reviewerStatus = status.value;
1265
1273
  if (
@@ -7,6 +7,10 @@ export type { CanonicalSkillBinding };
7
7
  import { disposeComplianceDecision } from "./audit-escalation.ts";
8
8
  import type { ComplianceDecision } from "./compliance-transport.ts";
9
9
  import { appendActiveSessionCustomEntry } from "./compliance-transport.ts";
10
+ import {
11
+ readActivationEngineLaborFallbackField,
12
+ withEngineLaborFallbackField,
13
+ } from "./engine-labor-fallback.ts";
10
14
  import { REVIEWER_CANDIDATE_ENTRY_TYPE } from "./dossier-resolution.ts";
11
15
  import { type ReviewerSpecDisposition } from "./reviewer-construction.ts";
12
16
  import { createReviewerDispatcher, type AcceptedReviewerDispatch, type AcceptedReviewerExecution, type ReviewerIssueFetcher, type ReviewerPinnedGitReader } from "./reviewer-dispatch.ts";
@@ -145,11 +149,15 @@ export function createReviewerRoleRuntime(
145
149
  const output = validateReviewerIntent(parameters);
146
150
  let record: ReviewerExecutionRecord;
147
151
  try { record = ledger.recordForAudit(output.status); } catch (error) { if ((error as any)?.fatalReviewerInfrastructure) hostActions.failInfrastructure(error, toolCtx, id); throw error; }
148
- const candidate = assembleRuntimeReviewerReceipt({
149
- intent: output,
150
- record,
151
- canonicalSkillText: binding.snapshot.raw,
152
- });
152
+ const candidate = withEngineLaborFallbackField(
153
+ assembleRuntimeReviewerReceipt({
154
+ intent: output,
155
+ record,
156
+ canonicalSkillText: binding.snapshot.raw,
157
+ }),
158
+ // #380: sole-built declaration when any leg detour fell back to seat labor.
159
+ readActivationEngineLaborFallbackField(),
160
+ );
153
161
  // First-record-then-audit: candidate lands on the parent session books
154
162
  // before the auditor is spawned (zero hand-delivery).
155
163
  try {
@@ -21,7 +21,13 @@ import {
21
21
  writeToolExecutionObservationRecord,
22
22
  type ToolExecutionObservationWriter,
23
23
  } from "./tool-execution-observation.ts";
24
+ import { ENGINE_DETOUR_TOOL_NAME } from "./engine-detour.ts";
24
25
  import { registerEngineDetourTool } from "./engine-detour-tool.ts";
26
+ import {
27
+ createEngineLaborFallbackLatch,
28
+ installActivationEngineLaborFallbackLatch,
29
+ restoreEngineLaborFallbackFromSessionEntries,
30
+ } from "./engine-labor-fallback.ts";
25
31
  import { installPackageOwnedToolRegistration } from "./package-owned-tool-idle.ts";
26
32
  import { createReceiptDeliveryPolicy, NO_RECEIPT_LIFECYCLE_ENTRY_TYPE, RECEIPT_DELIVERY_PROMPT } from "./receipt-delivery-policy.ts";
27
33
  import { createOAuthKeepalive, type OAuthKeepaliveOptions } from "./oauth-keepalive.ts";
@@ -591,8 +597,9 @@ export function createRoleRuntimeExtension(
591
597
  let pendingNavigatorSettlement: Promise<void> | undefined;
592
598
  let navigatorWorkContext: NavigatorWorkContext | undefined;
593
599
  const pendingInfrastructureToolCallIds = new Set<string>();
594
- // #357 T2 / #378: engine detour once-latch + registration (Judge|Reviewer+engine).
600
+ // #357 T2 / #378 / #380: engine detour once-latch + seat-fallback latch (Judge|Reviewer+engine).
595
601
  let engineDetourRegistration: ReturnType<typeof registerEngineDetourTool> | undefined;
602
+ let engineLaborFallbackLatch = createEngineLaborFallbackLatch();
596
603
  // #288 primary-session thin adapter. The policy is the sole budget owner;
597
604
  // terminating-tool rejections and mechanical delivery requests share two turns.
598
605
  let receiptDelivery = createReceiptDeliveryPolicy();
@@ -1056,6 +1063,18 @@ export function createRoleRuntimeExtension(
1056
1063
  pendingNavigatorPresentation = undefined;
1057
1064
  pendingNavigatorSettlement = undefined;
1058
1065
  pendingInfrastructureToolCallIds.clear();
1066
+ engineLaborFallbackLatch = createEngineLaborFallbackLatch();
1067
+ // #380 resume: restore sole-built fallback from durable same-session detour results.
1068
+ const sessionEntries =
1069
+ typeof ctx.sessionManager?.getEntries === "function"
1070
+ ? ctx.sessionManager.getEntries()
1071
+ : [];
1072
+ restoreEngineLaborFallbackFromSessionEntries(
1073
+ engineLaborFallbackLatch,
1074
+ sessionEntries,
1075
+ ENGINE_DETOUR_TOOL_NAME,
1076
+ );
1077
+ installActivationEngineLaborFallbackLatch(engineLaborFallbackLatch);
1059
1078
  engineDetourRegistration?.resetLatch();
1060
1079
  navigatorWorkContext = undefined;
1061
1080
  // #351: OAuth keepalive is orthogonal to --ak-role; start before role early-return
@@ -1168,8 +1187,9 @@ export function createRoleRuntimeExtension(
1168
1187
  }
1169
1188
 
1170
1189
  await executeActivationStage(entry.role, activationStage(entry.role, runtime), { clock, writeTrace });
1171
- // #357 T2 / #378: Judge|Reviewer+engine activation registers the package detour tool once.
1190
+ // #357 T2 / #378 / #380: Judge|Reviewer+engine activation registers the package detour tool once.
1172
1191
  // Gate is env presence only — no per-engine execute branch; no role-module spawn.
1192
+ // Seat-fallback latch is activation-scoped (installed at session_start) so legs share it.
1173
1193
  if (
1174
1194
  (entry.role === "judge" || entry.role === "reviewer") &&
1175
1195
  engineDetourRegistration === undefined