@akagilnc/pi-workflow-roles 0.1.5323 → 0.1.5325
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 +256 -310
- package/dist/engine-detour.js +1 -56
- package/dist/headless-host/production-host.js +203 -257
- package/package.json +1 -1
- package/src/engine-detour.ts +7 -88
package/package.json
CHANGED
package/src/engine-detour.ts
CHANGED
|
@@ -2,13 +2,8 @@
|
|
|
2
2
|
* Engine-generic one-shot subprocess detour (#357 T2 / ADR 0069).
|
|
3
3
|
* Spawn once; no retry, hang surface, or per-engine branch.
|
|
4
4
|
* Material body is LLM data — this module only executes argv the model assembled.
|
|
5
|
-
* Large prompt bodies stage through a seam-owned temp file (never argv) so
|
|
6
|
-
* collectors avoid spawn E2BIG / ENAMETOOLONG (engine-dispatch / #582).
|
|
7
5
|
*/
|
|
8
6
|
import { spawn } from "node:child_process";
|
|
9
|
-
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
10
|
-
import { tmpdir } from "node:os";
|
|
11
|
-
import { join } from "node:path";
|
|
12
7
|
|
|
13
8
|
/** Package-owned detour tool name (settlement whitelist + session principal). */
|
|
14
9
|
export const ENGINE_DETOUR_TOOL_NAME = "ak_engine_detour" as const;
|
|
@@ -27,12 +22,6 @@ export const ENGINE_FLAG_NAME = "ak-engine" as const;
|
|
|
27
22
|
/** Request-scoped engine model flag on RoleHost (#883). Empty = no model. */
|
|
28
23
|
export const ENGINE_MODEL_FLAG_NAME = "ak-engine-model" as const;
|
|
29
24
|
|
|
30
|
-
/**
|
|
31
|
-
* Argv placeholder replaced by a seam-owned temp prompt file path when
|
|
32
|
-
* `stagedPrompt` is set. Exactly one argv entry must equal this token.
|
|
33
|
-
*/
|
|
34
|
-
export const ENGINE_DETOUR_STAGED_PROMPT_TOKEN = "<<ak-engine-staged-prompt>>" as const;
|
|
35
|
-
|
|
36
25
|
/** Non-empty trimmed engine name, else undefined. */
|
|
37
26
|
export function normalizeEngineName(engine: string | undefined): string | undefined {
|
|
38
27
|
if (engine === undefined) return undefined;
|
|
@@ -73,12 +62,6 @@ export type EngineDetourRunInput = Readonly<{
|
|
|
73
62
|
cwd: string;
|
|
74
63
|
env?: NodeJS.ProcessEnv;
|
|
75
64
|
signal?: AbortSignal;
|
|
76
|
-
/**
|
|
77
|
-
* Large prompt body owned by this seam. Written to a temp file; the sole argv
|
|
78
|
-
* entry equal to ENGINE_DETOUR_STAGED_PROMPT_TOKEN is replaced with that path.
|
|
79
|
-
* File is unlinked after the child settles (success or failure).
|
|
80
|
-
*/
|
|
81
|
-
stagedPrompt?: string;
|
|
82
65
|
}>;
|
|
83
66
|
|
|
84
67
|
function abortReasonError(signal: AbortSignal): Error {
|
|
@@ -92,28 +75,13 @@ function abortReasonError(signal: AbortSignal): Error {
|
|
|
92
75
|
return error;
|
|
93
76
|
}
|
|
94
77
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
replaced += 1;
|
|
103
|
-
return stagedPath;
|
|
104
|
-
});
|
|
105
|
-
if (replaced !== 1) {
|
|
106
|
-
throw new Error(
|
|
107
|
-
`劳务引擎 stagedPrompt 需要 argv 中恰好一个 ${ENGINE_DETOUR_STAGED_PROMPT_TOKEN}(实际 ${replaced})`,
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
return out;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
async function spawnEngineDetourOnce(
|
|
114
|
-
input: Omit<EngineDetourRunInput, "stagedPrompt"> & {
|
|
115
|
-
readonly argv: readonly string[];
|
|
116
|
-
},
|
|
78
|
+
/**
|
|
79
|
+
* Run one engine subprocess. First argv element is the executable (PATH lookup).
|
|
80
|
+
* stdio: ignore stdin, pipe stdout+stderr. No shell, no retry, no hang timer.
|
|
81
|
+
* AbortSignal cancels the child immediately via an explicit listener (reason preserved).
|
|
82
|
+
*/
|
|
83
|
+
export async function runEngineDetourOnce(
|
|
84
|
+
input: EngineDetourRunInput,
|
|
117
85
|
): Promise<EngineDetourResult> {
|
|
118
86
|
if (input.argv.length === 0) {
|
|
119
87
|
throw new Error("劳务引擎 argv 不得为空");
|
|
@@ -177,55 +145,6 @@ async function spawnEngineDetourOnce(
|
|
|
177
145
|
});
|
|
178
146
|
}
|
|
179
147
|
|
|
180
|
-
/**
|
|
181
|
-
* Run one engine subprocess. First argv element is the executable (PATH lookup).
|
|
182
|
-
* stdio: ignore stdin, pipe stdout+stderr. No shell, no retry, no hang timer.
|
|
183
|
-
* AbortSignal cancels the child immediately via an explicit listener (reason preserved).
|
|
184
|
-
* Optional stagedPrompt: seam owns temp-file lifecycle for large bodies (ADR 0069).
|
|
185
|
-
*/
|
|
186
|
-
export async function runEngineDetourOnce(
|
|
187
|
-
input: EngineDetourRunInput,
|
|
188
|
-
): Promise<EngineDetourResult> {
|
|
189
|
-
if (input.stagedPrompt === undefined) {
|
|
190
|
-
return spawnEngineDetourOnce(input);
|
|
191
|
-
}
|
|
192
|
-
const stagingDir = await mkdtemp(join(tmpdir(), "ak-engine-detour-"));
|
|
193
|
-
const stagedPath = join(stagingDir, "prompt.txt");
|
|
194
|
-
let result: EngineDetourResult;
|
|
195
|
-
let runError: unknown;
|
|
196
|
-
try {
|
|
197
|
-
await writeFile(stagedPath, input.stagedPrompt, "utf8");
|
|
198
|
-
const argv = resolveArgvWithStagedPrompt(input.argv, stagedPath);
|
|
199
|
-
result = await spawnEngineDetourOnce({
|
|
200
|
-
argv,
|
|
201
|
-
cwd: input.cwd,
|
|
202
|
-
...(input.env === undefined ? {} : { env: input.env }),
|
|
203
|
-
...(input.signal === undefined ? {} : { signal: input.signal }),
|
|
204
|
-
});
|
|
205
|
-
} catch (error) {
|
|
206
|
-
runError = error;
|
|
207
|
-
}
|
|
208
|
-
// Cleanup is seam-owned and fail-closed: never wash rm failure into success
|
|
209
|
-
// (失败诚实). force only covers already-absent nodes, not permission/IO faults.
|
|
210
|
-
try {
|
|
211
|
-
await rm(stagingDir, { recursive: true, force: true });
|
|
212
|
-
} catch (cleanupError) {
|
|
213
|
-
if (runError !== undefined) {
|
|
214
|
-
throw new Error(
|
|
215
|
-
`劳务引擎 stagedPrompt 清理失败(原运行错误保留为 cause): ${cleanupError instanceof Error ? cleanupError.message : String(cleanupError)}`,
|
|
216
|
-
{ cause: runError },
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
throw cleanupError instanceof Error
|
|
220
|
-
? cleanupError
|
|
221
|
-
: new Error(String(cleanupError));
|
|
222
|
-
}
|
|
223
|
-
if (runError !== undefined) {
|
|
224
|
-
throw runError instanceof Error ? runError : new Error(String(runError));
|
|
225
|
-
}
|
|
226
|
-
return result!;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
148
|
/** Failure predicate: nonzero exit OR stdout trim-empty (including whitespace-only). */
|
|
230
149
|
export function isEngineDetourFailure(result: {
|
|
231
150
|
code: number;
|