@akagilnc/pi-workflow-roles 0.1.3391 → 0.1.3397

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.
@@ -8584,16 +8584,8 @@ function runIdentity(context) {
8584
8584
  if (typeof headerId === "string" && headerId.length > 0) return headerId;
8585
8585
  throw new Error("\u63D0\u4EA4\u8D26\u9700\u8981\u5DF2\u53D7\u7406\u7684 run \u8EAB\u4EFD");
8586
8586
  }
8587
- function latestUserAttemptId(entries) {
8588
- const ordered = [...entries];
8589
- for (let index = ordered.length - 1; index >= 0; index -= 1) {
8590
- const entry = ordered[index];
8591
- if (entry?.message?.role === "user" && typeof entry.id === "string") return entry.id;
8592
- }
8593
- return void 0;
8594
- }
8595
8587
  function attemptIdentity(context, runId) {
8596
- return latestUserAttemptId(context.sessionManager.getEntries?.() ?? []) ?? context.sessionManager.getHeader?.()?.id ?? context.sessionManager.getLeafId?.() ?? `${runId}:initial`;
8588
+ return context.sessionManager.getHeader?.()?.id ?? context.sessionManager.getLeafId?.() ?? `${runId}:initial`;
8597
8589
  }
8598
8590
  function submissionRecordFile(cwd, runId, home) {
8599
8591
  const ledgerHome = resolveActivationLedgerHome(home);
@@ -24326,14 +24326,6 @@ var init_run_terminal_artifacts = __esm({
24326
24326
  });
24327
24327
 
24328
24328
  // src/submission-ledger.ts
24329
- function latestUserAttemptId(entries) {
24330
- const ordered = [...entries];
24331
- for (let index = ordered.length - 1; index >= 0; index -= 1) {
24332
- const entry = ordered[index];
24333
- if (entry?.message?.role === "user" && typeof entry.id === "string") return entry.id;
24334
- }
24335
- return void 0;
24336
- }
24337
24329
  function isAcceptedProjection(value) {
24338
24330
  if (typeof value !== "object" || value === null) return false;
24339
24331
  const candidate = value;
@@ -24372,17 +24364,13 @@ async function readSealedSubmission(cwd, runId, home) {
24372
24364
  }
24373
24365
  return void 0;
24374
24366
  }
24375
- async function readAuditEscalationSubmission(cwd, runId, home, currentAttemptId) {
24367
+ async function readAuditEscalationSubmission(cwd, runId, home) {
24376
24368
  const { owned } = await readOwnedSubmissionRecords(cwd, runId, home);
24377
- const latestAttemptId = currentAttemptId ?? owned.at(-1)?.subject?.attemptId;
24378
- if (typeof latestAttemptId !== "string") return void 0;
24379
24369
  for (let index = owned.length - 1; index >= 0; index -= 1) {
24380
24370
  const record4 = owned[index];
24381
- if (record4?.subject?.attemptId !== latestAttemptId) continue;
24382
24371
  if (record4?.kind !== "outcome") continue;
24383
24372
  const payload = record4.payload;
24384
- if (payload?.type !== "outcome") continue;
24385
- if (payload.outcome !== "audit-escalation") return void 0;
24373
+ if (payload?.type !== "outcome" || payload.outcome !== "audit-escalation") continue;
24386
24374
  if (isAuditEscalationTerminalProjection(payload.projection)) return payload.projection;
24387
24375
  }
24388
24376
  return void 0;
@@ -24959,24 +24947,18 @@ async function sealedLedgerOutcome(admitted) {
24959
24947
  async function hasSealedAcceptedProjection(admitted) {
24960
24948
  return await sealedLedgerOutcome(admitted) !== void 0;
24961
24949
  }
24962
- async function auditEscalationLedgerOutcome(admitted, role, authority) {
24963
- let currentAttemptId;
24964
- if (role === "coder" || role === "fixer") {
24965
- const entries = await readBoundSessionEntries(coordinatesFromAdmitted(authority, admitted).sessionFile);
24966
- currentAttemptId = latestUserAttemptId(entries);
24967
- }
24950
+ async function auditEscalationLedgerOutcome(admitted, role) {
24968
24951
  const projection = await readAuditEscalationSubmission(
24969
24952
  admitted.projectRoot,
24970
24953
  admitted.runId,
24971
- sealedLedgerHome(admitted),
24972
- currentAttemptId
24954
+ sealedLedgerHome(admitted)
24973
24955
  );
24974
24956
  if (projection?.role !== role) return void 0;
24975
24957
  return projection;
24976
24958
  }
24977
- async function closedLedgerOutcome(admitted, role, authority) {
24959
+ async function closedLedgerOutcome(admitted, role) {
24978
24960
  const sealed = await sealedLedgerOutcome(admitted);
24979
- return sealed?.role === role ? sealed : auditEscalationLedgerOutcome(admitted, role, authority);
24961
+ return sealed?.role === role ? sealed : auditEscalationLedgerOutcome(admitted, role);
24980
24962
  }
24981
24963
  function coordinatesFromAdmitted(authority, admitted) {
24982
24964
  return authority.decode(admitted.principal);
@@ -26301,7 +26283,7 @@ async function readLawfulJudgeRoleOutcome(admitted, authority) {
26301
26283
  decisiveFacts: judgeDecisiveFacts(details, sealed.status)
26302
26284
  };
26303
26285
  }
26304
- return auditEscalationLedgerOutcome(admitted, "judge", authority);
26286
+ return auditEscalationLedgerOutcome(admitted, "judge");
26305
26287
  }
26306
26288
  async function settleLawfulJudgeTerminalResult(admitted, authority) {
26307
26289
  const roleOutcome = await readLawfulJudgeRoleOutcome(admitted, authority);
@@ -26328,7 +26310,7 @@ async function trySettleJudgeTerminalResult(admitted, authority) {
26328
26310
  return settleLawfulJudgeTerminalResult(admitted, authority);
26329
26311
  }
26330
26312
  async function settleLawfulCoderTerminalResult(admitted, authority, options = {}) {
26331
- const ledgerOutcome = await closedLedgerOutcome(admitted, "coder", authority);
26313
+ const ledgerOutcome = await closedLedgerOutcome(admitted, "coder");
26332
26314
  if (ledgerOutcome === void 0) return void 0;
26333
26315
  let roleOutcome = ledgerOutcome;
26334
26316
  let output;
@@ -26448,7 +26430,7 @@ async function publishFixerArtifacts(admitted, roleOutcome, coordinates, options
26448
26430
  ];
26449
26431
  }
26450
26432
  async function settleLawfulFixerTerminalResult(admitted, authority, options) {
26451
- const ledgerOutcome = await closedLedgerOutcome(admitted, "fixer", authority);
26433
+ const ledgerOutcome = await closedLedgerOutcome(admitted, "fixer");
26452
26434
  if (ledgerOutcome === void 0) return void 0;
26453
26435
  let roleOutcome = ledgerOutcome;
26454
26436
  let output;
@@ -26655,7 +26637,7 @@ async function settleLawfulDoctorTerminalResult(admitted, authority) {
26655
26637
  const { sessionDirectory, sessionFile } = coordinates;
26656
26638
  const entries = await readLawfulSettlementEntries(sessionFile) ?? [];
26657
26639
  if (sealed?.role !== "doctor") {
26658
- const escalation = await auditEscalationLedgerOutcome(admitted, "doctor", authority);
26640
+ const escalation = await auditEscalationLedgerOutcome(admitted, "doctor");
26659
26641
  if (escalation === void 0) return void 0;
26660
26642
  const artifacts2 = await publishDoctorArtifacts(admitted, escalation, coordinates);
26661
26643
  return withOptionalGateProjection(
@@ -26719,7 +26701,7 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec)
26719
26701
  const coordinates = coordinatesFromAdmitted(authority, admitted);
26720
26702
  const { sessionDirectory, sessionFile } = coordinates;
26721
26703
  const entries = await readLawfulSettlementEntries(sessionFile) ?? [];
26722
- const roleOutcome = await closedLedgerOutcome(admitted, spec.role, authority);
26704
+ const roleOutcome = await closedLedgerOutcome(admitted, spec.role);
26723
26705
  if (roleOutcome?.kind === "audit_escalation") {
26724
26706
  const navigator2 = extractNavigatorFact(entries);
26725
26707
  return withOptionalGateProjection(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akagilnc/pi-workflow-roles",
3
- "version": "0.1.3391",
3
+ "version": "0.1.3397",
4
4
  "description": "Soul-bound workflow roles for Pi",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -13,7 +13,6 @@ import {
13
13
  } from "../analyst-gate-cycles-read.ts";
14
14
  import { readSitianRecords, resolveSitianRecordPath, sitianReport } from "../sitian-facade.ts";
15
15
  import {
16
- latestUserAttemptId,
17
16
  readAuditEscalationSubmission,
18
17
  readLatestSubmissionOutcome,
19
18
  readSealedSubmission,
@@ -178,18 +177,11 @@ export async function hasSealedAcceptedProjection(
178
177
  async function auditEscalationLedgerOutcome(
179
178
  admitted: AdmittedRoleInvocation,
180
179
  role: TerminalRoleName,
181
- authority: DurablePrincipalAuthority,
182
180
  ): Promise<Extract<TerminalRoleOutcome, { kind: "audit_escalation" }> | undefined> {
183
- let currentAttemptId: string | undefined;
184
- if (role === "coder" || role === "fixer") {
185
- const entries = await readBoundSessionEntries(coordinatesFromAdmitted(authority, admitted).sessionFile);
186
- currentAttemptId = latestUserAttemptId(entries);
187
- }
188
181
  const projection = await readAuditEscalationSubmission(
189
182
  admitted.projectRoot,
190
183
  admitted.runId,
191
184
  sealedLedgerHome(admitted),
192
- currentAttemptId,
193
185
  );
194
186
  if (projection?.role !== role) return undefined;
195
187
  return projection;
@@ -198,12 +190,11 @@ async function auditEscalationLedgerOutcome(
198
190
  async function closedLedgerOutcome(
199
191
  admitted: AdmittedRoleInvocation,
200
192
  role: TerminalRoleName,
201
- authority: DurablePrincipalAuthority,
202
193
  ): Promise<Extract<TerminalRoleOutcome, { kind: "accepted" | "audit_escalation" }> | undefined> {
203
194
  const sealed = await sealedLedgerOutcome(admitted);
204
195
  return sealed?.role === role
205
196
  ? sealed
206
- : auditEscalationLedgerOutcome(admitted, role, authority);
197
+ : auditEscalationLedgerOutcome(admitted, role);
207
198
  }
208
199
 
209
200
  /** Transitional host-session reads remain only for non-sealed failure and audit evidence. */
@@ -2513,7 +2504,7 @@ export async function readLawfulJudgeRoleOutcome(
2513
2504
  };
2514
2505
  }
2515
2506
  // Non-final: consume ledger audit-escalation projection (no JSONL accepted rebuild).
2516
- return auditEscalationLedgerOutcome(admitted, "judge", authority);
2507
+ return auditEscalationLedgerOutcome(admitted, "judge");
2517
2508
  }
2518
2509
 
2519
2510
  /**
@@ -2590,7 +2581,7 @@ async function settleLawfulCoderTerminalResult(
2590
2581
  readonly methodProvenance?: PackagedMethodSkillProvenance;
2591
2582
  } = {},
2592
2583
  ): Promise<TerminalResult | undefined> {
2593
- const ledgerOutcome = await closedLedgerOutcome(admitted, "coder", authority);
2584
+ const ledgerOutcome = await closedLedgerOutcome(admitted, "coder");
2594
2585
  if (ledgerOutcome === undefined) return undefined;
2595
2586
  let roleOutcome: TerminalRoleOutcome = ledgerOutcome;
2596
2587
  let output: CoderOutput | undefined;
@@ -2778,7 +2769,7 @@ async function settleLawfulFixerTerminalResult(
2778
2769
  readonly methodSkillConfiguredPath: string;
2779
2770
  },
2780
2771
  ): Promise<TerminalResult | undefined> {
2781
- const ledgerOutcome = await closedLedgerOutcome(admitted, "fixer", authority);
2772
+ const ledgerOutcome = await closedLedgerOutcome(admitted, "fixer");
2782
2773
  if (ledgerOutcome === undefined) return undefined;
2783
2774
  let roleOutcome: TerminalRoleOutcome = ledgerOutcome;
2784
2775
  let output: FixerOutput | undefined;
@@ -3071,7 +3062,7 @@ async function settleLawfulDoctorTerminalResult(
3071
3062
  const { sessionDirectory, sessionFile } = coordinates;
3072
3063
  const entries = await readLawfulSettlementEntries(sessionFile) ?? [];
3073
3064
  if (sealed?.role !== "doctor") {
3074
- const escalation = await auditEscalationLedgerOutcome(admitted, "doctor", authority);
3065
+ const escalation = await auditEscalationLedgerOutcome(admitted, "doctor");
3075
3066
  if (escalation === undefined) return undefined;
3076
3067
  const artifacts = await publishDoctorArtifacts(admitted, escalation, coordinates);
3077
3068
  return withOptionalGateProjection(
@@ -3196,7 +3187,7 @@ async function settleLawfulSeatAcceptedTerminalResult(
3196
3187
  const coordinates = coordinatesFromAdmitted(authority, admitted);
3197
3188
  const { sessionDirectory, sessionFile } = coordinates;
3198
3189
  const entries = await readLawfulSettlementEntries(sessionFile) ?? [];
3199
- const roleOutcome = await closedLedgerOutcome(admitted, spec.role as TerminalRoleName, authority);
3190
+ const roleOutcome = await closedLedgerOutcome(admitted, spec.role as TerminalRoleName);
3200
3191
  if (roleOutcome?.kind === "audit_escalation") {
3201
3192
  const navigator = extractNavigatorFact(entries);
3202
3193
  return withOptionalGateProjection(
@@ -56,22 +56,8 @@ function runIdentity(context: HostContext): string {
56
56
  throw new Error("提交账需要已受理的 run 身份");
57
57
  }
58
58
 
59
- export function latestUserAttemptId(
60
- entries: Iterable<{ readonly id?: unknown; readonly message?: { readonly role?: unknown } }>,
61
- ): string | undefined {
62
- const ordered = [...entries];
63
- for (let index = ordered.length - 1; index >= 0; index -= 1) {
64
- const entry = ordered[index];
65
- if (entry?.message?.role === "user" && typeof entry.id === "string") return entry.id;
66
- }
67
- return undefined;
68
- }
69
-
70
59
  function attemptIdentity(context: HostContext, runId: string): string {
71
- return latestUserAttemptId(context.sessionManager.getEntries?.() ?? [])
72
- ?? context.sessionManager.getHeader?.()?.id
73
- ?? context.sessionManager.getLeafId?.()
74
- ?? `${runId}:initial`;
60
+ return context.sessionManager.getHeader?.()?.id ?? context.sessionManager.getLeafId?.() ?? `${runId}:initial`;
75
61
  }
76
62
 
77
63
  function isAcceptedProjection(value: unknown): value is Extract<TerminalRoleOutcome, { kind: "accepted" }> {
@@ -139,18 +125,13 @@ export async function readAuditEscalationSubmission(
139
125
  cwd: string,
140
126
  runId: string,
141
127
  home?: string,
142
- currentAttemptId?: string,
143
128
  ): Promise<AuditEscalationSubmissionProjection | undefined> {
144
129
  const { owned } = await readOwnedSubmissionRecords(cwd, runId, home);
145
- const latestAttemptId = currentAttemptId ?? (owned.at(-1)?.subject as { attemptId?: unknown } | undefined)?.attemptId;
146
- if (typeof latestAttemptId !== "string") return undefined;
147
130
  for (let index = owned.length - 1; index >= 0; index -= 1) {
148
131
  const record = owned[index];
149
- if ((record?.subject as { attemptId?: unknown } | undefined)?.attemptId !== latestAttemptId) continue;
150
132
  if (record?.kind !== "outcome") continue;
151
133
  const payload = record.payload as Partial<Extract<SubmissionLedgerEvent, { type: "outcome" }>> | undefined;
152
- if (payload?.type !== "outcome") continue;
153
- if (payload.outcome !== "audit-escalation") return undefined;
134
+ if (payload?.type !== "outcome" || payload.outcome !== "audit-escalation") continue;
154
135
  if (isAuditEscalationTerminalProjection(payload.projection)) return payload.projection;
155
136
  }
156
137
  return undefined;