@akagilnc/pi-workflow-roles 0.1.3625 → 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.
- package/dist/acp-host/production-host.js +77 -35
- package/dist/public-cli/main.js +173 -125
- package/dist/public-cli/notary-run.js +20 -2
- package/dist/public-cli/post-admission.js +4 -4
- package/dist/public-cli/run-lifecycle.js +44 -5
- package/package.json +1 -1
- package/src/public-cli/notary-run.ts +18 -4
- package/src/public-cli/post-admission.ts +14 -7
- package/src/public-cli/run-lifecycle.ts +53 -5
|
@@ -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) =>
|
|
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
|
|
33
|
-
*
|
|
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
|
@@ -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
|
-
|
|
242
|
+
buildTurnRequest: (admitted, effective) => {
|
|
243
|
+
const projection = resumeTurnRequestProjectionOptions(
|
|
240
244
|
admitted,
|
|
241
|
-
|
|
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 =
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
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 =
|
|
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
|
-
*
|
|
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
|
|
164
|
-
*
|
|
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
|
|
216
|
+
return instructResumeHandbookRead(
|
|
217
|
+
appendEngineSessionMaterial([base], engineMaterial).join("\n"),
|
|
218
|
+
engineMaterial,
|
|
219
|
+
);
|
|
172
220
|
}
|
|
173
221
|
|
|
174
222
|
/**
|