@akagilnc/pi-workflow-roles 0.1.3623 → 0.1.3629

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.
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Public Notary Role run: admit source-run locator → shared post-admission coordinator
3
+ * → settle Terminal result (#448 / #517). Zero caller prompt/attachment. Lifecycle is
4
+ * the shared post-admission seam; this module keeps only Notary adapters.
5
+ * #637: same-ticket re-summons resume the seat's previous run (no new run).
6
+ */
7
+ import { existsSync } from "node:fs";
8
+ import { gateSubmissionCandidatePath } from "../auditor-dossier-tool.js";
1
9
  import { NotarySourceRunError, resolveNotarySourceRunLocator, } from "../notary-source-run.js";
2
10
  import { engineSessionMaterialFromOptions } from "../package-resources/engine-material.js";
3
11
  import { readRunTicketNumber } from "../run-ticket-number.js";
@@ -5,7 +13,7 @@ import { CliUsageError } from "./cli-errors.js";
5
13
  import { admitNotaryInvocation, buildNotaryTransportPrompt, } from "./invocation.js";
6
14
  import { tryResumeSameTicketSeatRun } from "./seat-ticket-binding.js";
7
15
  import { runPostAdmissionOneShot, runPostAdmissionSeatResume, resumeTurnRequestProjectionOptions, } from "./post-admission.js";
8
- import { loadResumableNotaryRun, markRunAdmitted, } from "./run-lifecycle.js";
16
+ import { appendResumeMaterialReread, loadResumableNotaryRun, markRunAdmitted, } from "./run-lifecycle.js";
9
17
  import { presentStructuralRejection, trySettleNotaryTerminalResult, } from "./settlement.js";
10
18
  import { projectRoleTurnRequest, } from "./turn-request.js";
11
19
  /** Project admitted invocation onto the host-neutral turn request. */
@@ -154,7 +162,17 @@ export async function runPublicNotaryResume(request, env, io) {
154
162
  }
155
163
  return loaded;
156
164
  },
157
- buildTurnRequest: (admitted, effective) => buildNotaryTurnRequest(admitted, resumeTurnRequestProjectionOptions(admitted, effective, env)),
165
+ buildTurnRequest: (admitted, effective) => {
166
+ const projection = resumeTurnRequestProjectionOptions(admitted, effective, env);
167
+ const candidatePath = gateSubmissionCandidatePath(admitted.sourceRunPath);
168
+ const prompt = existsSync(candidatePath)
169
+ ? appendResumeMaterialReread(projection.continuation.prompt, candidatePath)
170
+ : projection.continuation.prompt;
171
+ return buildNotaryTurnRequest(admitted, {
172
+ ...projection,
173
+ continuation: { kind: "resume", prompt },
174
+ });
175
+ },
158
176
  adapters: notaryAdapters(),
159
177
  ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
160
178
  });
@@ -8,7 +8,7 @@
8
8
  import { randomUUID } from "node:crypto";
9
9
  import { readFile, writeFile } from "node:fs/promises";
10
10
  import { isAbsolute, join, resolve } from "node:path";
11
- import { buildResumeContinuationPrompt, } from "./run-lifecycle.js";
11
+ import { buildResumeContinuationPrompt, instructResumeHandbookRead, } from "./run-lifecycle.js";
12
12
  import { CliUsageError } from "./cli-errors.js";
13
13
  import { buildInstructionTransportPrompt, freezeAttachmentsIntoRun, } from "./invocation.js";
14
14
  import { pathContainedIn } from "../activation-ledger-topology.js";
@@ -256,11 +256,11 @@ export function resumeTurnRequestProjectionOptions(admitted, request, env, summo
256
256
  // projection must not re-interpret the caller message as instructionEmpty.
257
257
  if (summonsPrepared !== undefined &&
258
258
  summonsPrepared.attachments.length > 0) {
259
- prompt = buildInstructionTransportPrompt({
259
+ prompt = instructResumeHandbookRead(buildInstructionTransportPrompt({
260
260
  instruction: request.message,
261
261
  instructionEmpty: false,
262
262
  attachments: summonsPrepared.attachments,
263
- }, engineMaterial);
263
+ }, engineMaterial), engineMaterial);
264
264
  }
265
265
  else {
266
266
  prompt = buildResumeContinuationPrompt({
@@ -271,7 +271,7 @@ export function resumeTurnRequestProjectionOptions(admitted, request, env, summo
271
271
  }
272
272
  }
273
273
  else if (summonsPrepared !== undefined) {
274
- prompt = buildInstructionTransportPrompt(summonsPrepared, engineMaterial);
274
+ prompt = instructResumeHandbookRead(buildInstructionTransportPrompt(summonsPrepared, engineMaterial), engineMaterial);
275
275
  }
276
276
  else {
277
277
  prompt = buildResumeContinuationPrompt({
@@ -6,7 +6,7 @@
6
6
  * Prose is never regex-classified as quota evidence.
7
7
  */
8
8
  import { chmod, open, readdir, readFile, unlink, writeFile } from "node:fs/promises";
9
- import { join } from "node:path";
9
+ import { isAbsolute, join } from "node:path";
10
10
  import { activationBookDirectory, resolveActivationLedgerHome, } from "../activation-ledger-topology.js";
11
11
  import { readRunTicketNumber } from "../run-ticket-number.js";
12
12
  import { CliUsageError } from "./cli-errors.js";
@@ -26,15 +26,54 @@ export const V1_RESUMABLE_PROVIDERS = ["openai-codex", "xai"];
26
26
  export const AUTO_RESUME_LIMIT = 2;
27
27
  /** Package-owned turn trigger for resume. Not caller instruction and not semantic task content. */
28
28
  export const RESUME_TRANSPORT_ENVELOPE = "[ak-role:resume-continue]";
29
+ function resumeRereadInstruction(materialPath, handbook) {
30
+ return handbook
31
+ ? `重新读 ${materialPath},再组装外包 argv`
32
+ : `重新读 ${materialPath}`;
33
+ }
34
+ /**
35
+ * Resume-only material lines (#736 ticket exemption to ADR 0073 §3).
36
+ * Neutral `- <absolute path>` pointers already on the continuation
37
+ * (handbook from appendEngineSessionMaterial; frozen attachments from
38
+ * instruction-seat transport) become reread instructions.
39
+ * Handbook keeps the argv suffix; other materials are path-only.
40
+ * First-round delivery is unchanged; never pastes material body.
41
+ */
42
+ export function instructResumeHandbookRead(prompt, engineMaterial) {
43
+ const handbookPath = engineMaterial?.materialPath;
44
+ return prompt
45
+ .split("\n")
46
+ .map((line) => {
47
+ if (!line.startsWith("- "))
48
+ return line;
49
+ const value = line.slice(2);
50
+ if (handbookPath !== undefined && value === handbookPath) {
51
+ return resumeRereadInstruction(handbookPath, true);
52
+ }
53
+ if (isAbsolute(value))
54
+ return resumeRereadInstruction(value, false);
55
+ return line;
56
+ })
57
+ .join("\n");
58
+ }
59
+ /** Append a live-path reread instruction when the pointer is not already on the continuation. */
60
+ export function appendResumeMaterialReread(prompt, materialPath) {
61
+ const instruction = resumeRereadInstruction(materialPath, false);
62
+ const lines = prompt.split("\n");
63
+ if (lines.includes(instruction))
64
+ return prompt;
65
+ return prompt.length === 0 ? instruction : `${prompt}\n${instruction}`;
66
+ }
29
67
  /**
30
- * Unique continuation-prompt selector for manual/auto resume (#471 / #600).
68
+ * Unique continuation-prompt selector for manual/auto resume (#471 / #600 / #736).
31
69
  * Message present → base bytes unchanged; absent → package transport envelope.
32
- * When engine material is present, append structured engine coordinates (same
33
- * delivery as initial transport prompts). Zero parse, zero classify, zero narrow.
70
+ * When engine material is present, append structured engine coordinates then
71
+ * rewrite absolute material pointer lines into 重新读 instructions. Zero parse,
72
+ * zero classify, zero narrow. Pointer only — never material body.
34
73
  */
35
74
  export function selectResumeContinuationPrompt(message, engineMaterial) {
36
75
  const base = message !== undefined ? message : RESUME_TRANSPORT_ENVELOPE;
37
- return appendEngineSessionMaterial([base], engineMaterial).join("\n");
76
+ return instructResumeHandbookRead(appendEngineSessionMaterial([base], engineMaterial).join("\n"), engineMaterial);
38
77
  }
39
78
  /**
40
79
  * Resume continuation with engine material resolved from the seat env (#600).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akagilnc/pi-workflow-roles",
3
- "version": "0.1.3623",
3
+ "version": "0.1.3629",
4
4
  "description": "Soul-bound workflow roles for Pi",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -6,15 +6,19 @@
6
6
  ## 审读步骤
7
7
 
8
8
  **一、立法。** 先为本票立「适用法」,写进判词;后面每一步只对着它问,未立法不得往下走。适用法三部分:
9
- ① 票面本文,含置顶冻结原话;
10
- ② 法源:该票起居录与陛下原话;适用 ADR——由你自行检索,按票面触及的席位、接缝、术语在 docs/adr 与 CONTEXT.md 查全,票面引没引都算——并逐键列出其决策键;全局宪法、仓级 CLAUDE.md、质量法、审刑院法典;
11
- ③ 既有契约:CONTEXT.md 词表、被改动接缝的现行行为、相关票与在飞分支。
9
+ 1 票面本文,含置顶冻结原话;起居录里决策过程
10
+ 2 第一法源立法(最高法):该票起居录与陛下原话;
11
+ 3 第二发源立法:
12
+ 适用 ADR——由你自行检索,按票面触及的席位、接缝、术语在 docs/adr 与 CONTEXT.md 查全,票面引没引都算——并逐键列出其决策键;全局宪法、仓级 CLAUDE.md、质量法、审刑院法典;
13
+ 既有契约:CONTEXT.md 词表、被改动接缝的现行行为、相关票与在飞分支。
14
+
15
+ 4 第二法源合法性检查:根据起居录对话记录,判断第二法源 以及 输入的 prombt 是否有超出或不足,曲解陛下原话的。如有,直接封驳要求改正或陛下批准。
12
16
 
13
17
  **二、相抵。** 票面与适用法有无抵触:违宪、违 ADR 决策键、违既有契约、与在飞票冲突。
14
18
 
15
19
  **三、缺失。** 适用法要求的,票面有没有漏:适用 ADR 未被引用即缺失,引用须写 `docs/adr/...md` 路径(御史台 Spec 轴只按路径取 ADR 字节);ADR 每个决策键须有落点或明写「由 #x 承接」;验收面须覆盖票面每条主张;前置产物、决定、答复须在;承重主张的源头不存在、不支持、已过时,同为缺失。
16
20
 
17
- **四、擅加。** 票面有没有超出法源的机制、约束、验收、术语:每条承重主张追到陛下原话为止;ADR 决策键只是索引,键的表述超出同行原话即加戏(2026-09-06 owner:#636/#637「每次独立 run」判例),追不到原话即加戏。
21
+ **四、擅加。** 票面有没有超出法源的机制、约束、验收、术语:每条承重主张追到陛下原话为止;ADR 决策键只是索引,键的表述超出同行原话即加戏,追不到原话即加戏。
18
22
 
19
23
  各步取证按《审法·取证边界》:读码、开卷、传召皆可;只读,探针只落 worktree 与临时目录,不得删改其外任何路径。
20
24
 
@@ -31,7 +35,7 @@
31
35
 
32
36
  ## 判词
33
37
 
34
- 事实与处方分开对宪:裁决落法度与事实,不落施工设计;把实现细节过早堆上票面即为失职。
38
+ 事实与处方分开对宪:裁决落法度与事实,不落施工设计与实现细节过早堆上票面即为失职。
35
39
 
36
40
  - 署(converged)——四步无碍、五问皆有据可答,具备开工资格;
37
41
  - 封驳(continue)——存在必须退回重议的问题;写明退给谁、缺什么、属哪一步;
@@ -4,6 +4,9 @@
4
4
  * the shared post-admission seam; this module keeps only Notary adapters.
5
5
  * #637: same-ticket re-summons resume the seat's previous run (no new run).
6
6
  */
7
+ import { existsSync } from "node:fs";
8
+
9
+ import { gateSubmissionCandidatePath } from "../auditor-dossier-tool.ts";
7
10
  import type { DurablePrincipalAuthority, RoleTurnRequest } from "../host-contracts.ts";
8
11
  import {
9
12
  NotarySourceRunError,
@@ -27,6 +30,7 @@ import {
27
30
  resumeTurnRequestProjectionOptions,
28
31
  } from "./post-admission.ts";
29
32
  import {
33
+ appendResumeMaterialReread,
30
34
  loadResumableNotaryRun,
31
35
  markRunAdmitted,
32
36
  type PublicResumeRequest,
@@ -235,11 +239,21 @@ export async function runPublicNotaryResume(
235
239
  }
236
240
  return loaded;
237
241
  },
238
- buildTurnRequest: (admitted, effective) =>
239
- buildNotaryTurnRequest(
242
+ buildTurnRequest: (admitted, effective) => {
243
+ const projection = resumeTurnRequestProjectionOptions(
240
244
  admitted,
241
- resumeTurnRequestProjectionOptions(admitted, effective, env),
242
- ),
245
+ effective,
246
+ env,
247
+ );
248
+ const candidatePath = gateSubmissionCandidatePath(admitted.sourceRunPath);
249
+ const prompt = existsSync(candidatePath)
250
+ ? appendResumeMaterialReread(projection.continuation.prompt, candidatePath)
251
+ : projection.continuation.prompt;
252
+ return buildNotaryTurnRequest(admitted, {
253
+ ...projection,
254
+ continuation: { kind: "resume", prompt },
255
+ });
256
+ },
243
257
  adapters: notaryAdapters(),
244
258
  ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
245
259
  });
@@ -11,6 +11,7 @@ import { isAbsolute, join, resolve } from "node:path";
11
11
 
12
12
  import {
13
13
  buildResumeContinuationPrompt,
14
+ instructResumeHandbookRead,
14
15
  type PublicResumeRequest,
15
16
  type SameTicketSummonsMaterials,
16
17
  } from "./run-lifecycle.ts";
@@ -492,12 +493,15 @@ export function resumeTurnRequestProjectionOptions(
492
493
  summonsPrepared !== undefined &&
493
494
  summonsPrepared.attachments.length > 0
494
495
  ) {
495
- prompt = buildInstructionTransportPrompt(
496
- {
497
- instruction: request.message,
498
- instructionEmpty: false,
499
- attachments: summonsPrepared.attachments,
500
- },
496
+ prompt = instructResumeHandbookRead(
497
+ buildInstructionTransportPrompt(
498
+ {
499
+ instruction: request.message,
500
+ instructionEmpty: false,
501
+ attachments: summonsPrepared.attachments,
502
+ },
503
+ engineMaterial,
504
+ ),
501
505
  engineMaterial,
502
506
  );
503
507
  } else {
@@ -508,7 +512,10 @@ export function resumeTurnRequestProjectionOptions(
508
512
  });
509
513
  }
510
514
  } else if (summonsPrepared !== undefined) {
511
- prompt = buildInstructionTransportPrompt(summonsPrepared, engineMaterial);
515
+ prompt = instructResumeHandbookRead(
516
+ buildInstructionTransportPrompt(summonsPrepared, engineMaterial),
517
+ engineMaterial,
518
+ );
512
519
  } else {
513
520
  prompt = buildResumeContinuationPrompt({
514
521
  packageRoot: env.packageRoot,
@@ -10,7 +10,7 @@ import type {
10
10
  * Prose is never regex-classified as quota evidence.
11
11
  */
12
12
  import { chmod, open, readdir, readFile, unlink, writeFile } from "node:fs/promises";
13
- import { join } from "node:path";
13
+ import { isAbsolute, join } from "node:path";
14
14
 
15
15
  import {
16
16
  activationBookDirectory,
@@ -157,18 +157,66 @@ export type SameTicketSummonsMaterials = {
157
157
  readonly sourceRun?: NotarySourceRunLocator;
158
158
  };
159
159
 
160
+ function resumeRereadInstruction(materialPath: string, handbook: boolean): string {
161
+ return handbook
162
+ ? `重新读 ${materialPath},再组装外包 argv`
163
+ : `重新读 ${materialPath}`;
164
+ }
165
+
160
166
  /**
161
- * Unique continuation-prompt selector for manual/auto resume (#471 / #600).
167
+ * Resume-only material lines (#736 ticket exemption to ADR 0073 §3).
168
+ * Neutral `- <absolute path>` pointers already on the continuation
169
+ * (handbook from appendEngineSessionMaterial; frozen attachments from
170
+ * instruction-seat transport) become reread instructions.
171
+ * Handbook keeps the argv suffix; other materials are path-only.
172
+ * First-round delivery is unchanged; never pastes material body.
173
+ */
174
+ export function instructResumeHandbookRead(
175
+ prompt: string,
176
+ engineMaterial?: EngineSessionMaterial,
177
+ ): string {
178
+ const handbookPath = engineMaterial?.materialPath;
179
+ return prompt
180
+ .split("\n")
181
+ .map((line) => {
182
+ if (!line.startsWith("- ")) return line;
183
+ const value = line.slice(2);
184
+ if (handbookPath !== undefined && value === handbookPath) {
185
+ return resumeRereadInstruction(handbookPath, true);
186
+ }
187
+ if (isAbsolute(value)) return resumeRereadInstruction(value, false);
188
+ return line;
189
+ })
190
+ .join("\n");
191
+ }
192
+
193
+ /** Append a live-path reread instruction when the pointer is not already on the continuation. */
194
+ export function appendResumeMaterialReread(
195
+ prompt: string,
196
+ materialPath: string,
197
+ ): string {
198
+ const instruction = resumeRereadInstruction(materialPath, false);
199
+ const lines = prompt.split("\n");
200
+ if (lines.includes(instruction)) return prompt;
201
+ return prompt.length === 0 ? instruction : `${prompt}\n${instruction}`;
202
+ }
203
+
204
+ /**
205
+ * Unique continuation-prompt selector for manual/auto resume (#471 / #600 / #736).
162
206
  * Message present → base bytes unchanged; absent → package transport envelope.
163
- * When engine material is present, append structured engine coordinates (same
164
- * delivery as initial transport prompts). Zero parse, zero classify, zero narrow.
207
+ * When engine material is present, append structured engine coordinates then
208
+ * rewrite absolute material pointer lines into 重新读 instructions. Zero parse,
209
+ * zero classify, zero narrow. Pointer only — never material body.
165
210
  */
166
211
  export function selectResumeContinuationPrompt(
167
212
  message?: string,
168
213
  engineMaterial?: EngineSessionMaterial,
169
214
  ): string {
170
215
  const base = message !== undefined ? message : RESUME_TRANSPORT_ENVELOPE;
171
- return appendEngineSessionMaterial([base], engineMaterial).join("\n");
216
+ return instructResumeHandbookRead(
217
+ appendEngineSessionMaterial([base], engineMaterial).join("\n"),
218
+ engineMaterial,
219
+ );
172
220
  }
173
221
 
174
222
  /**