@akagilnc/pi-workflow-roles 0.1.4276 → 0.1.4286

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.
@@ -16142,32 +16142,29 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
16142
16142
  const entries = await readLawfulSettlementEntries(sessionFile) ?? [];
16143
16143
  const submissions = await recordedSubmissionPayloads(admitted, scope);
16144
16144
  const scanStart = currentAttemptStartIndex(entries);
16145
+ let thisAttemptHasSeatSuccess = false;
16146
+ let residual;
16145
16147
  for (let index = entries.length - 1; index >= scanStart; index -= 1) {
16146
16148
  const message = entries[index]?.message;
16147
16149
  if (message?.role !== "toolResult") continue;
16148
- const residual = boundErroredToolCandidate(
16149
- entries,
16150
- index,
16151
- message,
16152
- spec.toolName
16153
- );
16154
- if (residual !== void 0) {
16155
- const details = isRecord11(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
16156
- const failed = await settleFailureTerminalResult(
16157
- admitted,
16158
- {
16159
- cause: "output",
16160
- diagnostic: residual.diagnostic,
16161
- details
16162
- },
16163
- authority,
16164
- scope ?? {}
16150
+ if (message.toolName !== spec.toolName) continue;
16151
+ if (message.isError === false) {
16152
+ if (boundRoleToolCallForResult(entries, index, message, spec.toolName) !== void 0) {
16153
+ thisAttemptHasSeatSuccess = true;
16154
+ }
16155
+ continue;
16156
+ }
16157
+ if (residual === void 0) {
16158
+ residual = boundErroredToolCandidate(
16159
+ entries,
16160
+ index,
16161
+ message,
16162
+ spec.toolName
16165
16163
  );
16166
- return withSubmissions(failed, submissions);
16167
16164
  }
16168
16165
  }
16169
16166
  const roleOutcome = await closedLedgerOutcome(admitted, spec.role, scope);
16170
- if (roleOutcome?.kind === "audit_escalation") {
16167
+ if (roleOutcome !== void 0 && (thisAttemptHasSeatSuccess || residual === void 0)) {
16171
16168
  const navigator = extractNavigatorFact(entries);
16172
16169
  return withSubmissions(
16173
16170
  await withOptionalGateProjection(
@@ -16183,21 +16180,19 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
16183
16180
  submissions
16184
16181
  );
16185
16182
  }
16186
- if (roleOutcome?.role === spec.role) {
16187
- const navigator = extractNavigatorFact(entries);
16188
- return withSubmissions(
16189
- await withOptionalGateProjection(
16190
- {
16191
- roleOutcome,
16192
- navigator,
16193
- artifacts: [],
16194
- runId: admitted.runId
16195
- },
16196
- sessionDirectory,
16197
- detourGateContext(admitted, scope)
16198
- ),
16199
- submissions
16183
+ if (residual !== void 0) {
16184
+ const details = isRecord11(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
16185
+ const failed = await settleFailureTerminalResult(
16186
+ admitted,
16187
+ {
16188
+ cause: "output",
16189
+ diagnostic: residual.diagnostic,
16190
+ details
16191
+ },
16192
+ authority,
16193
+ scope ?? {}
16200
16194
  );
16195
+ return withSubmissions(failed, submissions);
16201
16196
  }
16202
16197
  return void 0;
16203
16198
  }
@@ -15508,32 +15508,29 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
15508
15508
  const entries = await readLawfulSettlementEntries(sessionFile) ?? [];
15509
15509
  const submissions = await recordedSubmissionPayloads(admitted, scope);
15510
15510
  const scanStart = currentAttemptStartIndex(entries);
15511
+ let thisAttemptHasSeatSuccess = false;
15512
+ let residual;
15511
15513
  for (let index = entries.length - 1; index >= scanStart; index -= 1) {
15512
15514
  const message = entries[index]?.message;
15513
15515
  if (message?.role !== "toolResult") continue;
15514
- const residual = boundErroredToolCandidate(
15515
- entries,
15516
- index,
15517
- message,
15518
- spec.toolName
15519
- );
15520
- if (residual !== void 0) {
15521
- const details = isRecord11(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
15522
- const failed = await settleFailureTerminalResult(
15523
- admitted,
15524
- {
15525
- cause: "output",
15526
- diagnostic: residual.diagnostic,
15527
- details
15528
- },
15529
- authority,
15530
- scope ?? {}
15516
+ if (message.toolName !== spec.toolName) continue;
15517
+ if (message.isError === false) {
15518
+ if (boundRoleToolCallForResult(entries, index, message, spec.toolName) !== void 0) {
15519
+ thisAttemptHasSeatSuccess = true;
15520
+ }
15521
+ continue;
15522
+ }
15523
+ if (residual === void 0) {
15524
+ residual = boundErroredToolCandidate(
15525
+ entries,
15526
+ index,
15527
+ message,
15528
+ spec.toolName
15531
15529
  );
15532
- return withSubmissions(failed, submissions);
15533
15530
  }
15534
15531
  }
15535
15532
  const roleOutcome = await closedLedgerOutcome(admitted, spec.role, scope);
15536
- if (roleOutcome?.kind === "audit_escalation") {
15533
+ if (roleOutcome !== void 0 && (thisAttemptHasSeatSuccess || residual === void 0)) {
15537
15534
  const navigator = extractNavigatorFact(entries);
15538
15535
  return withSubmissions(
15539
15536
  await withOptionalGateProjection(
@@ -15549,21 +15546,19 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
15549
15546
  submissions
15550
15547
  );
15551
15548
  }
15552
- if (roleOutcome?.role === spec.role) {
15553
- const navigator = extractNavigatorFact(entries);
15554
- return withSubmissions(
15555
- await withOptionalGateProjection(
15556
- {
15557
- roleOutcome,
15558
- navigator,
15559
- artifacts: [],
15560
- runId: admitted.runId
15561
- },
15562
- sessionDirectory,
15563
- detourGateContext(admitted, scope)
15564
- ),
15565
- submissions
15549
+ if (residual !== void 0) {
15550
+ const details = isRecord11(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
15551
+ const failed = await settleFailureTerminalResult(
15552
+ admitted,
15553
+ {
15554
+ cause: "output",
15555
+ diagnostic: residual.diagnostic,
15556
+ details
15557
+ },
15558
+ authority,
15559
+ scope ?? {}
15566
15560
  );
15561
+ return withSubmissions(failed, submissions);
15567
15562
  }
15568
15563
  return void 0;
15569
15564
  }
@@ -26701,32 +26701,29 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
26701
26701
  const entries = await readLawfulSettlementEntries(sessionFile) ?? [];
26702
26702
  const submissions = await recordedSubmissionPayloads(admitted, scope);
26703
26703
  const scanStart = currentAttemptStartIndex(entries);
26704
+ let thisAttemptHasSeatSuccess = false;
26705
+ let residual;
26704
26706
  for (let index = entries.length - 1; index >= scanStart; index -= 1) {
26705
26707
  const message = entries[index]?.message;
26706
26708
  if (message?.role !== "toolResult") continue;
26707
- const residual = boundErroredToolCandidate(
26708
- entries,
26709
- index,
26710
- message,
26711
- spec.toolName
26712
- );
26713
- if (residual !== void 0) {
26714
- const details = isRecord10(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
26715
- const failed = await settleFailureTerminalResult(
26716
- admitted,
26717
- {
26718
- cause: "output",
26719
- diagnostic: residual.diagnostic,
26720
- details
26721
- },
26722
- authority,
26723
- scope ?? {}
26709
+ if (message.toolName !== spec.toolName) continue;
26710
+ if (message.isError === false) {
26711
+ if (boundRoleToolCallForResult(entries, index, message, spec.toolName) !== void 0) {
26712
+ thisAttemptHasSeatSuccess = true;
26713
+ }
26714
+ continue;
26715
+ }
26716
+ if (residual === void 0) {
26717
+ residual = boundErroredToolCandidate(
26718
+ entries,
26719
+ index,
26720
+ message,
26721
+ spec.toolName
26724
26722
  );
26725
- return withSubmissions(failed, submissions);
26726
26723
  }
26727
26724
  }
26728
26725
  const roleOutcome = await closedLedgerOutcome(admitted, spec.role, scope);
26729
- if (roleOutcome?.kind === "audit_escalation") {
26726
+ if (roleOutcome !== void 0 && (thisAttemptHasSeatSuccess || residual === void 0)) {
26730
26727
  const navigator = extractNavigatorFact(entries);
26731
26728
  return withSubmissions(
26732
26729
  await withOptionalGateProjection(
@@ -26742,21 +26739,19 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
26742
26739
  submissions
26743
26740
  );
26744
26741
  }
26745
- if (roleOutcome?.role === spec.role) {
26746
- const navigator = extractNavigatorFact(entries);
26747
- return withSubmissions(
26748
- await withOptionalGateProjection(
26749
- {
26750
- roleOutcome,
26751
- navigator,
26752
- artifacts: [],
26753
- runId: admitted.runId
26754
- },
26755
- sessionDirectory,
26756
- detourGateContext(admitted, scope)
26757
- ),
26758
- submissions
26742
+ if (residual !== void 0) {
26743
+ const details = isRecord10(residual.candidate) ? residual.candidate : { candidate: residual.candidate };
26744
+ const failed = await settleFailureTerminalResult(
26745
+ admitted,
26746
+ {
26747
+ cause: "output",
26748
+ diagnostic: residual.diagnostic,
26749
+ details
26750
+ },
26751
+ authority,
26752
+ scope ?? {}
26759
26753
  );
26754
+ return withSubmissions(failed, submissions);
26760
26755
  }
26761
26756
  return void 0;
26762
26757
  }
@@ -2244,27 +2244,37 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
2244
2244
  const { sessionDirectory, sessionFile } = coordinates;
2245
2245
  const entries = await readLawfulSettlementEntries(sessionFile) ?? [];
2246
2246
  const submissions = await recordedSubmissionPayloads(admitted, scope);
2247
- // Host isError residual wins over any recorded projection (#836 A.3 coexistence).
2247
+ // #843: collector shape (ledger closed first) plus current user-turn freshness.
2248
+ // A lawful bound non-error seat toolResult (isError === false + one-to-one call
2249
+ // bind, same grade as residual) means this turn sealed — a prior bounce residual
2250
+ // in the same turn must not outrank it. Missing isError, unbound, or mis-bound
2251
+ // results do not establish success and do not reject/abort. A current-attempt
2252
+ // residual without that success is this turn's own failure and must not be
2253
+ // masked by run-scoped stale acceptance (bare resume without courtAttemptId).
2254
+ // Same-turn accept-then-bounce keeps the success marker: terminal stays
2255
+ // accepted; rejection facts remain on payloads/gate (not latest-wins flip).
2248
2256
  const scanStart = currentAttemptStartIndex(entries);
2257
+ let thisAttemptHasSeatSuccess = false;
2258
+ let residual;
2249
2259
  for (let index = entries.length - 1; index >= scanStart; index -= 1) {
2250
2260
  const message = entries[index]?.message;
2251
2261
  if (message?.role !== "toolResult")
2252
2262
  continue;
2253
- const residual = boundErroredToolCandidate(entries, index, message, spec.toolName);
2254
- if (residual !== undefined) {
2255
- const details = isRecord(residual.candidate)
2256
- ? residual.candidate
2257
- : { candidate: residual.candidate };
2258
- const failed = await settleFailureTerminalResult(admitted, {
2259
- cause: "output",
2260
- diagnostic: residual.diagnostic,
2261
- details,
2262
- }, authority, scope ?? {});
2263
- return withSubmissions(failed, submissions);
2263
+ if (message.toolName !== spec.toolName)
2264
+ continue;
2265
+ if (message.isError === false) {
2266
+ if (boundRoleToolCallForResult(entries, index, message, spec.toolName) !==
2267
+ undefined) {
2268
+ thisAttemptHasSeatSuccess = true;
2269
+ }
2270
+ continue;
2271
+ }
2272
+ if (residual === undefined) {
2273
+ residual = boundErroredToolCandidate(entries, index, message, spec.toolName);
2264
2274
  }
2265
2275
  }
2266
2276
  const roleOutcome = await closedLedgerOutcome(admitted, spec.role, scope);
2267
- if (roleOutcome?.kind === "audit_escalation") {
2277
+ if (roleOutcome !== undefined && (thisAttemptHasSeatSuccess || residual === undefined)) {
2268
2278
  const navigator = extractNavigatorFact(entries);
2269
2279
  return withSubmissions(await withOptionalGateProjection({
2270
2280
  roleOutcome,
@@ -2273,14 +2283,16 @@ async function settleLawfulSeatAcceptedTerminalResult(admitted, authority, spec,
2273
2283
  runId: admitted.runId,
2274
2284
  }, sessionDirectory, detourGateContext(admitted, scope)), submissions);
2275
2285
  }
2276
- if (roleOutcome?.role === spec.role) {
2277
- const navigator = extractNavigatorFact(entries);
2278
- return withSubmissions(await withOptionalGateProjection({
2279
- roleOutcome,
2280
- navigator,
2281
- artifacts: [],
2282
- runId: admitted.runId,
2283
- }, sessionDirectory, detourGateContext(admitted, scope)), submissions);
2286
+ if (residual !== undefined) {
2287
+ const details = isRecord(residual.candidate)
2288
+ ? residual.candidate
2289
+ : { candidate: residual.candidate };
2290
+ const failed = await settleFailureTerminalResult(admitted, {
2291
+ cause: "output",
2292
+ diagnostic: residual.diagnostic,
2293
+ details,
2294
+ }, authority, scope ?? {});
2295
+ return withSubmissions(failed, submissions);
2284
2296
  }
2285
2297
  return undefined;
2286
2298
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akagilnc/pi-workflow-roles",
3
- "version": "0.1.4276",
3
+ "version": "0.1.4286",
4
4
  "description": "Soul-bound workflow roles for Pi",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -44,3 +44,6 @@
44
44
 
45
45
 
46
46
  主张必须附证据或法的具体条目。finding 提类别,同类一次说全(审刑院法典·审官纪律)。
47
+
48
+ 案例:
49
+ #858 seal 5 核「擅加」的手段是 rg 一串已驳旧措辞(「该席申报」「待建接缝」「typed 交卷里申报」…),旧词零命中即判「未见擅加」放行开工;放过的是同一个被驳方案换了说法的版本——「新增前置读取接缝」,其授权栏挂着陛下两句驳回。
@@ -3226,36 +3226,42 @@ async function settleLawfulSeatAcceptedTerminalResult(
3226
3226
  const { sessionDirectory, sessionFile } = coordinates;
3227
3227
  const entries = await readLawfulSettlementEntries(sessionFile) ?? [];
3228
3228
  const submissions = await recordedSubmissionPayloads(admitted, scope);
3229
- // Host isError residual wins over any recorded projection (#836 A.3 coexistence).
3229
+ // #843: collector shape (ledger closed first) plus current user-turn freshness.
3230
+ // A lawful bound non-error seat toolResult (isError === false + one-to-one call
3231
+ // bind, same grade as residual) means this turn sealed — a prior bounce residual
3232
+ // in the same turn must not outrank it. Missing isError, unbound, or mis-bound
3233
+ // results do not establish success and do not reject/abort. A current-attempt
3234
+ // residual without that success is this turn's own failure and must not be
3235
+ // masked by run-scoped stale acceptance (bare resume without courtAttemptId).
3236
+ // Same-turn accept-then-bounce keeps the success marker: terminal stays
3237
+ // accepted; rejection facts remain on payloads/gate (not latest-wins flip).
3230
3238
  const scanStart = currentAttemptStartIndex(entries);
3239
+ let thisAttemptHasSeatSuccess = false;
3240
+ let residual: BoundErroredToolCandidate | undefined;
3231
3241
  for (let index = entries.length - 1; index >= scanStart; index -= 1) {
3232
3242
  const message = entries[index]?.message;
3233
3243
  if (message?.role !== "toolResult") continue;
3234
- const residual = boundErroredToolCandidate(
3235
- entries,
3236
- index,
3237
- message,
3238
- spec.toolName,
3239
- );
3240
- if (residual !== undefined) {
3241
- const details = isRecord(residual.candidate)
3242
- ? residual.candidate
3243
- : { candidate: residual.candidate };
3244
- const failed = await settleFailureTerminalResult(
3245
- admitted,
3246
- {
3247
- cause: "output",
3248
- diagnostic: residual.diagnostic,
3249
- details,
3250
- },
3251
- authority,
3252
- scope ?? {},
3244
+ if (message.toolName !== spec.toolName) continue;
3245
+ if (message.isError === false) {
3246
+ if (
3247
+ boundRoleToolCallForResult(entries, index, message, spec.toolName) !==
3248
+ undefined
3249
+ ) {
3250
+ thisAttemptHasSeatSuccess = true;
3251
+ }
3252
+ continue;
3253
+ }
3254
+ if (residual === undefined) {
3255
+ residual = boundErroredToolCandidate(
3256
+ entries,
3257
+ index,
3258
+ message,
3259
+ spec.toolName,
3253
3260
  );
3254
- return withSubmissions(failed, submissions);
3255
3261
  }
3256
3262
  }
3257
3263
  const roleOutcome = await closedLedgerOutcome(admitted, spec.role as TerminalRoleName, scope);
3258
- if (roleOutcome?.kind === "audit_escalation") {
3264
+ if (roleOutcome !== undefined && (thisAttemptHasSeatSuccess || residual === undefined)) {
3259
3265
  const navigator = extractNavigatorFact(entries);
3260
3266
  return withSubmissions(
3261
3267
  await withOptionalGateProjection(
@@ -3271,21 +3277,21 @@ async function settleLawfulSeatAcceptedTerminalResult(
3271
3277
  submissions,
3272
3278
  );
3273
3279
  }
3274
- if (roleOutcome?.role === spec.role) {
3275
- const navigator = extractNavigatorFact(entries);
3276
- return withSubmissions(
3277
- await withOptionalGateProjection(
3278
- {
3279
- roleOutcome,
3280
- navigator,
3281
- artifacts: [],
3282
- runId: admitted.runId,
3283
- },
3284
- sessionDirectory,
3285
- detourGateContext(admitted, scope),
3286
- ),
3287
- submissions,
3280
+ if (residual !== undefined) {
3281
+ const details = isRecord(residual.candidate)
3282
+ ? residual.candidate
3283
+ : { candidate: residual.candidate };
3284
+ const failed = await settleFailureTerminalResult(
3285
+ admitted,
3286
+ {
3287
+ cause: "output",
3288
+ diagnostic: residual.diagnostic,
3289
+ details,
3290
+ },
3291
+ authority,
3292
+ scope ?? {},
3288
3293
  );
3294
+ return withSubmissions(failed, submissions);
3289
3295
  }
3290
3296
  return undefined;
3291
3297
  }