@akagilnc/pi-workflow-roles 0.1.2521 → 0.1.2653-next.71811ca
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/README.md +129 -39
- package/README.zh-CN.md +128 -39
- package/dist/activation-ledger-topology.js +1 -1
- package/dist/archivist-record-entry.js +47 -26
- package/dist/auditor-dossier-tool.js +3 -1
- package/dist/compliance-transport.js +17 -26
- package/dist/doctor-contracts.js +1 -2
- package/dist/dossier-resolution.js +4 -8
- package/dist/engine-detour-tool.js +33 -8
- package/dist/engine-detour.js +1 -0
- package/dist/evidence-child-executor.js +277 -424
- package/dist/host-contracts.js +22 -0
- package/dist/institutional-resolution.js +88 -0
- package/dist/merger-contracts.js +1 -2
- package/dist/navigator-attendance.js +16 -0
- package/dist/notary-contracts.js +2 -3
- package/dist/package-contracts/fixer-output.js +1 -2
- package/dist/packaged-role-registry.js +102 -9
- package/dist/pi/in-process-session.js +671 -0
- package/dist/public-cli/config.js +7 -5
- package/dist/public-cli/main.js +3767 -4113
- package/dist/reviewer-child-executor.js +6 -1
- package/dist/session-opening-materials.js +10 -38
- package/dist/sitian-appender.js +146 -0
- package/dist/sitian-contracts.js +21 -0
- package/dist/sitian-facade.js +15 -0
- package/dist/sitian-reader.js +52 -0
- package/extensions/role-runtime.ts +9 -7
- package/package.json +5 -5
- package/resources/engines/cursor.md +12 -26
- package/resources/engines/hermes.md +2 -23
- package/resources/engines/opus.md +1 -16
- package/resources/navigator-route-playbook.md +2 -2
- package/scripts/build-package.mjs +0 -1
- package/souls/quality-law.md +1 -1
- package/src/activation-ledger-topology.ts +1 -1
- package/src/archivist-record-entry.ts +57 -45
- package/src/auditor-dossier-tool.ts +4 -2
- package/src/canonical-skill-binding.ts +37 -27
- package/src/collector-role.ts +11 -20
- package/src/collector-tool-schemas.ts +1 -4
- package/src/compliance-transport.ts +19 -44
- package/src/doctor-auditor.ts +1 -5
- package/src/doctor-contracts.ts +1 -4
- package/src/doctor-role.ts +31 -8
- package/src/dossier-resolution.ts +8 -8
- package/src/engine-detour-tool.ts +48 -19
- package/src/engine-detour.ts +3 -0
- package/src/evidence-child-executor.ts +277 -485
- package/src/factory-board.ts +3 -3
- package/src/gatekeeper-role.ts +21 -10
- package/src/host-contracts.ts +386 -0
- package/src/in-process-session.ts +1 -115
- package/src/institutional-resolution.ts +135 -0
- package/src/judge-auditor.ts +1 -5
- package/src/judge-role.ts +37 -51
- package/src/merger-contracts.ts +1 -4
- package/src/merger-role.ts +7 -11
- package/src/navigator-attendance.ts +20 -1
- package/src/notary-contracts.ts +8 -11
- package/src/notary-role.ts +7 -23
- package/src/notary-source-run.ts +4 -3
- package/src/package-contracts/fixer-output.ts +1 -4
- package/src/package-resources/method-skill-binding.ts +10 -34
- package/src/packaged-role-registry.ts +122 -12
- package/src/pi/adapter.ts +192 -0
- package/src/pi/durable-principal.ts +98 -0
- package/src/pi/in-process-session.ts +819 -0
- package/src/pi/known-failure.ts +77 -0
- package/src/pi/pi-normalization.ts +284 -0
- package/src/pi/role-turn-host.ts +459 -0
- package/src/public-cli/auto-resume.ts +42 -44
- package/src/public-cli/cli.ts +171 -257
- package/src/public-cli/coder-run.ts +115 -433
- package/src/public-cli/collector-run.ts +62 -314
- package/src/public-cli/config.ts +7 -5
- package/src/public-cli/doctor-run.ts +41 -52
- package/src/public-cli/fixer-run.ts +122 -427
- package/src/public-cli/invocation.ts +287 -96
- package/src/public-cli/judge-run.ts +92 -422
- package/src/public-cli/merger-run.ts +167 -429
- package/src/public-cli/notary-run.ts +41 -47
- package/src/public-cli/option-definitions.ts +136 -3
- package/src/public-cli/post-admission.ts +497 -0
- package/src/public-cli/public-run-credentials.ts +4 -4
- package/src/public-cli/reviewer-dispatch-rejection.ts +106 -0
- package/src/public-cli/reviewer-run.ts +132 -449
- package/src/public-cli/run-lifecycle.ts +339 -327
- package/src/public-cli/settlement.ts +251 -134
- package/src/public-cli/terminal.ts +3 -9
- package/src/public-cli/turn-request.ts +87 -0
- package/src/reviewer-child-executor.ts +9 -1
- package/src/reviewer-role.ts +11 -20
- package/src/role-runtime.ts +129 -78
- package/src/session-opening-materials.ts +25 -39
- package/src/sitian-appender.ts +171 -0
- package/src/sitian-contracts.ts +106 -0
- package/src/sitian-facade.ts +18 -0
- package/src/sitian-reader.ts +62 -0
- package/src/worker-role.ts +42 -40
- package/src/worker-submission-gates.ts +33 -0
- package/dist/archivist-role-run-coordinates.js +0 -28
- package/dist/package-contracts/terminating-infrastructure.js +0 -90
- package/resources/engines/sonnet.md +0 -27
- package/resources/engines/zcode.md +0 -63
- package/src/archivist-role-run-coordinates.ts +0 -45
- package/src/package-contracts/terminating-infrastructure.ts +0 -132
- package/src/public-cli/explicit-internal.ts +0 -427
- package/src/public-cli/one-shot-dispatch.ts +0 -300
|
@@ -33,41 +33,32 @@ export const complianceDecisionSchema = Type.Object({ status: Type.Unknown({ des
|
|
|
33
33
|
export function createComplianceDecisionTool(name, description) {
|
|
34
34
|
return { name, description, parameters: complianceDecisionSchema, async execute(_id, params) { return { content: [{ type: "text", text: "审计决议已收" }], details: params, terminate: true }; } };
|
|
35
35
|
}
|
|
36
|
-
export async function prepareComplianceDispatch(model, context, label) {
|
|
37
|
-
const resolution = await context.modelRegistry.getProviderAuth(model.provider).catch((error) => { throw new Error(`${label} authentication failed: ${error instanceof Error ? error.message : String(error)}`, { cause: error }); });
|
|
38
|
-
if (resolution === undefined)
|
|
39
|
-
throw new Error(`${label} authentication failed: provider is not configured: ${model.provider}`);
|
|
40
|
-
const auth = await context.modelRegistry.getApiKeyAndHeaders(model);
|
|
41
|
-
if (!auth.ok)
|
|
42
|
-
throw new Error(`${label} authentication failed: ${auth.error}`);
|
|
43
|
-
const env = auth.env ?? resolution.env;
|
|
44
|
-
return { model: resolution.auth.baseUrl ? { ...model, baseUrl: resolution.auth.baseUrl } : model, auth: { ...(auth.apiKey === undefined ? {} : { apiKey: auth.apiKey }), ...(auth.headers === undefined ? {} : { headers: auth.headers }), ...(env === undefined ? {} : { env }) } };
|
|
45
|
-
}
|
|
46
36
|
export const COMPLIANCE_RESPONSE_ENTRY_TYPE = "ak_compliance_response";
|
|
47
37
|
export const AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE = "ak_auditor_parent_attempt_binding";
|
|
48
38
|
export const AUDITOR_COMPLIANCE_FAILURE_ENTRY_TYPE = "ak_auditor_compliance_failure";
|
|
39
|
+
import { attachDirectErrnoCode, sitianReport } from "./sitian-facade.js";
|
|
49
40
|
export class ComplianceResponseRetentionError extends Error {
|
|
50
|
-
constructor(message, options) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const manager = context.sessionManager;
|
|
55
|
-
if (typeof manager?.appendCustomEntry !== "function") {
|
|
56
|
-
throw new ComplianceResponseRetentionError(labels.unavailable ?? "session custom entry append is unavailable");
|
|
41
|
+
constructor(message, options) {
|
|
42
|
+
super(message, options);
|
|
43
|
+
this.name = "ComplianceResponseRetentionError";
|
|
44
|
+
attachDirectErrnoCode(this, options?.cause);
|
|
57
45
|
}
|
|
46
|
+
}
|
|
47
|
+
function retainComplianceResponse(context, response) {
|
|
58
48
|
try {
|
|
59
|
-
|
|
49
|
+
sitianReport({
|
|
50
|
+
level: "event",
|
|
51
|
+
kind: "auditor",
|
|
52
|
+
cwd: context.cwd,
|
|
53
|
+
sessionParent: context.sessionManager.getSessionFile(),
|
|
54
|
+
payload: { version: 1, response },
|
|
55
|
+
source: "compliance-transport",
|
|
56
|
+
});
|
|
60
57
|
}
|
|
61
58
|
catch (error) {
|
|
62
|
-
throw new ComplianceResponseRetentionError(
|
|
59
|
+
throw new ComplianceResponseRetentionError(`compliance response retention failed: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
63
60
|
}
|
|
64
61
|
}
|
|
65
|
-
function retainComplianceResponse(context, response) {
|
|
66
|
-
appendActiveSessionCustomEntry(context, COMPLIANCE_RESPONSE_ENTRY_TYPE, { version: 1, response }, {
|
|
67
|
-
unavailable: "compliance response retention is unavailable",
|
|
68
|
-
failed: "compliance response retention failed",
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
62
|
function readListField(value) { return Array.isArray(value) ? value : value === undefined ? [] : [value]; }
|
|
72
63
|
export function readComplianceCandidate(arguments_, usage) {
|
|
73
64
|
if (typeof arguments_ !== "object" || arguments_ === null || Array.isArray(arguments_)) {
|
|
@@ -93,7 +84,7 @@ export async function runComplianceAudit(options) {
|
|
|
93
84
|
roleLabel: options.roleLabel,
|
|
94
85
|
context: options.context,
|
|
95
86
|
retainResponse: (response) => retainComplianceResponse(options.context, response),
|
|
96
|
-
...(options.
|
|
87
|
+
...(options.runDirectory === undefined ? {} : { runDirectory: options.runDirectory }),
|
|
97
88
|
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
98
89
|
});
|
|
99
90
|
if (receipt.noReceiptLifecycle !== undefined) {
|
package/dist/doctor-contracts.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
import { canonicalJson } from "./canonical-json.js";
|
|
3
3
|
import { openToolObjectFromUnion } from "./open-tool-schema.js";
|
|
4
|
-
import { withInfrastructureFailureDeclaration } from "./package-contracts/terminating-infrastructure.js";
|
|
5
4
|
export const DOCTOR_EVIDENCE_TOOL_NAME = "ak_doctor_evidence";
|
|
6
5
|
export const DOCTOR_OUTPUT_TOOL_NAME = "ak_doctor_output";
|
|
7
6
|
export const DOCTOR_ACCEPTED_TEXT = "太医署回执已接受";
|
|
@@ -50,7 +49,7 @@ const doctorSubmissionVariants = Type.Union([
|
|
|
50
49
|
missingEvidence: Type.Array(Type.Object({ need: nonblank, targetKeys: Type.Array(nonblank, { minItems: 1 }) }, { additionalProperties: false }), { minItems: 1, description: "如实证词所需而尚缺的证据" }),
|
|
51
50
|
}, { additionalProperties: false, description: "证据不足以支撑如实案证词" }),
|
|
52
51
|
]);
|
|
53
|
-
export const doctorSubmissionSchema =
|
|
52
|
+
export const doctorSubmissionSchema = openToolObjectFromUnion(doctorSubmissionVariants);
|
|
54
53
|
export const doctorOutputSchema = Type.Union([
|
|
55
54
|
Type.Object({ status: Type.Literal("completed"), case: caseIdentity, findings: Type.Array(finding), cost }, { additionalProperties: false }),
|
|
56
55
|
doctorSubmissionVariants.anyOf[1],
|
|
@@ -36,30 +36,26 @@ export function resolveAuditDossier(env = process.env) {
|
|
|
36
36
|
function isRecord(value) {
|
|
37
37
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
38
38
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Judge subjects must already be on the parent session books before audit starts:
|
|
41
|
-
* assignment (user message) + candidate verdict (sole judge output tool call).
|
|
42
|
-
*/
|
|
43
39
|
export function readJudgeAuditSubjects(context) {
|
|
44
40
|
const entries = context.sessionManager.getEntries?.() ?? [];
|
|
45
41
|
let hasAssignment = false;
|
|
46
42
|
let hasCandidate = false;
|
|
47
43
|
for (const entry of entries) {
|
|
48
|
-
if (entry.type !== "message")
|
|
44
|
+
if (!isRecord(entry) || entry.type !== "message" || !isRecord(entry.message))
|
|
49
45
|
continue;
|
|
50
46
|
const message = entry.message;
|
|
51
47
|
if (message.role === "user") {
|
|
52
48
|
const text = typeof message.content === "string"
|
|
53
49
|
? message.content
|
|
54
50
|
: Array.isArray(message.content)
|
|
55
|
-
? message.content.map((part) => (part.type === "text" ? part.text : "")).join("")
|
|
51
|
+
? message.content.map((part) => (isRecord(part) && part.type === "text" && typeof part.text === "string" ? part.text : "")).join("")
|
|
56
52
|
: "";
|
|
57
53
|
if (text.trim().length > 0)
|
|
58
54
|
hasAssignment = true;
|
|
59
55
|
}
|
|
60
56
|
if (message.role === "assistant" && Array.isArray(message.content)) {
|
|
61
57
|
for (const part of message.content) {
|
|
62
|
-
if (part.type === "toolCall" && part.name === JUDGE_OUTPUT_TOOL_NAME && isRecord(part.arguments)) {
|
|
58
|
+
if (isRecord(part) && part.type === "toolCall" && part.name === JUDGE_OUTPUT_TOOL_NAME && isRecord(part.arguments)) {
|
|
63
59
|
hasCandidate = true;
|
|
64
60
|
}
|
|
65
61
|
}
|
|
@@ -79,7 +75,7 @@ export function readJudgeAuditSubjects(context) {
|
|
|
79
75
|
export function readDoctorAuditSubjects(context) {
|
|
80
76
|
const entries = context.sessionManager.getEntries?.() ?? [];
|
|
81
77
|
for (const entry of entries) {
|
|
82
|
-
if (entry.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
|
|
78
|
+
if (isRecord(entry) && entry.type === "custom" && entry.customType === DOCTOR_CANDIDATE_ENTRY_TYPE) {
|
|
83
79
|
return { status: "ok" };
|
|
84
80
|
}
|
|
85
81
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-owned engine detour tool (#357 T2 / #378 / #380).
|
|
3
|
+
* Registered by shared role-runtime when any role + engine activation signal is present.
|
|
4
|
+
* Evidence-child legs install the same definition via customTools (no spawn in role modules).
|
|
5
|
+
* Engine process failures stop through the host infrastructure-failure seam.
|
|
6
|
+
* Caller AbortSignal cancellation propagates unchanged.
|
|
7
|
+
*/
|
|
1
8
|
import { Type } from "typebox";
|
|
2
|
-
import { ENGINE_DETOUR_TOOL_NAME, engineDetourFailureDiagnostic, engineNameFromEnv, isEngineDetourFailure, runEngineDetourOnce, } from "./engine-detour.js";
|
|
9
|
+
import { ENGINE_DETOUR_ALREADY_USED_DIAGNOSTIC, ENGINE_DETOUR_TOOL_NAME, engineDetourFailureDiagnostic, engineNameFromEnv, isEngineDetourFailure, runEngineDetourOnce, } from "./engine-detour.js";
|
|
3
10
|
const engineDetourArgsSchema = Type.Object({
|
|
4
11
|
argv: Type.Array(Type.String({ minLength: 1 }), {
|
|
5
12
|
minItems: 1,
|
|
@@ -18,20 +25,26 @@ function isCallerCancellation(error, signal) {
|
|
|
18
25
|
return false;
|
|
19
26
|
}
|
|
20
27
|
/**
|
|
21
|
-
* Build one detour tool definition for a configured engine name.
|
|
28
|
+
* Build one once-latch detour tool definition for a configured engine name.
|
|
29
|
+
* `latch` is shared so parent registration can reset between activations.
|
|
22
30
|
* `fail` owns host abort (parent) vs throw (evidence child) for tool misuse only.
|
|
23
31
|
* Engine process failures (nonzero/empty/spawn) stop via `fail` with their cause.
|
|
24
32
|
* Caller AbortSignal cancellation propagates unchanged.
|
|
25
33
|
*/
|
|
26
34
|
export function createEngineDetourToolDefinition(input) {
|
|
35
|
+
const latch = input.latch ?? { used: false };
|
|
27
36
|
const engineName = input.engineName;
|
|
28
37
|
return {
|
|
29
38
|
name: ENGINE_DETOUR_TOOL_NAME,
|
|
30
39
|
label: "劳务引擎",
|
|
31
|
-
description: `运行一次劳务引擎子进程(engine=${engineName}),stdout 返回本 session
|
|
40
|
+
description: `运行一次劳务引擎子进程(engine=${engineName}),stdout 返回本 session;每次激活至多一次。`,
|
|
32
41
|
promptSnippet: "运行配置的劳务引擎一次并返回 stdout",
|
|
33
42
|
parameters: engineDetourArgsSchema,
|
|
34
43
|
async execute(toolCallId, params, signal, _onUpdate, ctx) {
|
|
44
|
+
if (latch.used) {
|
|
45
|
+
input.fail(new Error(ENGINE_DETOUR_ALREADY_USED_DIAGNOSTIC), toolCallId, ctx);
|
|
46
|
+
}
|
|
47
|
+
latch.used = true;
|
|
35
48
|
const args = params;
|
|
36
49
|
const argv = Array.isArray(args.argv) ? args.argv : [];
|
|
37
50
|
if (argv.length === 0 || argv.some((part) => typeof part !== "string" || part.length === 0)) {
|
|
@@ -61,7 +74,6 @@ export function createEngineDetourToolDefinition(input) {
|
|
|
61
74
|
details: {
|
|
62
75
|
tool: ENGINE_DETOUR_TOOL_NAME,
|
|
63
76
|
code: result.code,
|
|
64
|
-
stderr: result.stderr,
|
|
65
77
|
},
|
|
66
78
|
};
|
|
67
79
|
},
|
|
@@ -70,18 +82,31 @@ export function createEngineDetourToolDefinition(input) {
|
|
|
70
82
|
/**
|
|
71
83
|
* Register the engine-generic detour tool once for this process when any role has
|
|
72
84
|
* an engine activation signal. Returns whether registration occurred.
|
|
85
|
+
* Once-latch is activation-scoped via the returned reset handle.
|
|
73
86
|
*/
|
|
74
|
-
export function registerEngineDetourTool(
|
|
87
|
+
export function registerEngineDetourTool(roleHost, hostActions) {
|
|
75
88
|
const engineName = engineNameFromEnv();
|
|
76
89
|
if (engineName === undefined) {
|
|
77
|
-
return
|
|
90
|
+
return {
|
|
91
|
+
registered: false,
|
|
92
|
+
resetLatch() {
|
|
93
|
+
/* no-op when unregistered */
|
|
94
|
+
},
|
|
95
|
+
};
|
|
78
96
|
}
|
|
97
|
+
const latch = { used: false };
|
|
79
98
|
const definition = createEngineDetourToolDefinition({
|
|
80
99
|
engineName,
|
|
100
|
+
latch,
|
|
81
101
|
fail(error, toolCallId, ctx) {
|
|
82
102
|
hostActions.failInfrastructure(error, ctx, toolCallId);
|
|
83
103
|
},
|
|
84
104
|
});
|
|
85
|
-
|
|
86
|
-
return
|
|
105
|
+
roleHost.registerTool(definition);
|
|
106
|
+
return {
|
|
107
|
+
registered: true,
|
|
108
|
+
resetLatch() {
|
|
109
|
+
latch.used = false;
|
|
110
|
+
},
|
|
111
|
+
};
|
|
87
112
|
}
|
package/dist/engine-detour.js
CHANGED
|
@@ -22,6 +22,7 @@ export function applyEngineChildEnv(childEnv, engine) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
export const ENGINE_DETOUR_EMPTY_STDOUT_DIAGNOSTIC = "劳务引擎 stdout 为空";
|
|
25
|
+
export const ENGINE_DETOUR_ALREADY_USED_DIAGNOSTIC = "本激活内劳务引擎已使用";
|
|
25
26
|
function abortReasonError(signal) {
|
|
26
27
|
const reason = signal.reason;
|
|
27
28
|
if (reason instanceof Error)
|