@leitwerk-dev/test-support 0.1.0 → 0.1.2
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/fakes/index.js +10 -2
- package/dist/fakes/index.js.map +1 -1
- package/dist/fixtures.js +35 -2
- package/dist/fixtures.js.map +1 -1
- package/dist/index.js +56 -12
- package/dist/index.js.map +1 -1
- package/dist/integration.js +19 -4
- package/dist/integration.js.map +1 -1
- package/dist/stub-worker-entry.js +9 -5
- package/dist/stub-worker-entry.js.map +1 -1
- package/dist/worker-testing/index.js +350 -7
- package/dist/worker-testing/index.js.map +1 -1
- package/dist/worker-testing/worker-runtime-harness.d.ts +2 -1
- package/dist/worker-testing/worker-runtime-harness.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/worker-testing/worker-runtime-harness.ts +8 -0
- package/dist/compact-process-detail-fixture.js +0 -73
- package/dist/compact-process-detail-fixture.js.map +0 -1
- package/dist/fakes/fake-git-ops.js +0 -101
- package/dist/fakes/fake-git-ops.js.map +0 -1
- package/dist/fakes/fake-llm.js +0 -27
- package/dist/fakes/fake-llm.js.map +0 -1
- package/dist/in-process-worker.js +0 -2
- package/dist/in-process-worker.js.map +0 -1
- package/dist/integration-harness.js +0 -38
- package/dist/integration-harness.js.map +0 -1
- package/dist/polling.js +0 -14
- package/dist/polling.js.map +0 -1
- package/dist/question-fixtures.js +0 -26
- package/dist/question-fixtures.js.map +0 -1
- package/dist/server-extension-test-harness.js +0 -167
- package/dist/server-extension-test-harness.js.map +0 -1
- package/dist/test-app.js +0 -47
- package/dist/test-app.js.map +0 -1
- package/dist/worker-testing/in-process-worker-spawn.js +0 -61
- package/dist/worker-testing/in-process-worker-spawn.js.map +0 -1
- package/dist/worker-testing/ipc-harness.js +0 -17
- package/dist/worker-testing/ipc-harness.js.map +0 -1
- package/dist/worker-testing/schema-driven-stub-pi.js +0 -65
- package/dist/worker-testing/schema-driven-stub-pi.js.map +0 -1
- package/dist/worker-testing/stub-pi-controls.js +0 -10
- package/dist/worker-testing/stub-pi-controls.js.map +0 -1
- package/dist/worker-testing/stub-pi-tree-handle.js +0 -515
- package/dist/worker-testing/stub-pi-tree-handle.js.map +0 -1
- package/dist/worker-testing/worker-runtime-harness.js +0 -210
- package/dist/worker-testing/worker-runtime-harness.js.map +0 -1
- package/dist/worker-testing/worker-start-payload.js +0 -101
- package/dist/worker-testing/worker-start-payload.js.map +0 -1
- package/dist/workspace-source-aliases.js +0 -126
- package/dist/workspace-source-aliases.js.map +0 -1
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "node:events";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import { PassThrough } from "node:stream";
|
|
4
|
-
import { createWorkerEntryRuntime } from "@leitwerk-dev/worker";
|
|
5
|
-
import { createSchemaDrivenStubPiFactory } from "./schema-driven-stub-pi.js";
|
|
6
|
-
const require = createRequire(import.meta.url);
|
|
7
|
-
const WebSocket = require("ws").WebSocket ??
|
|
8
|
-
require("ws").default ??
|
|
9
|
-
require("ws");
|
|
10
|
-
/**
|
|
11
|
-
* Fast local-runner-shaped spawn fake. The worker receives the local runner's
|
|
12
|
-
* env and connects over WebSocket just like Docker/Kubernetes workers do.
|
|
13
|
-
*/
|
|
14
|
-
export function createInProcessWorkerSpawn(options = {}) {
|
|
15
|
-
const piFactory = options.piFactory ??
|
|
16
|
-
createSchemaDrivenStubPiFactory({
|
|
17
|
-
toolCallScriptResolver: options.toolCallScriptResolver,
|
|
18
|
-
});
|
|
19
|
-
return ((command, args = [], spawnOptions) => {
|
|
20
|
-
const stderr = new PassThrough();
|
|
21
|
-
const child = new EventEmitter();
|
|
22
|
-
const emitter = child;
|
|
23
|
-
let exited = false;
|
|
24
|
-
let runtime = null;
|
|
25
|
-
const finish = (code) => {
|
|
26
|
-
if (!exited) {
|
|
27
|
-
exited = true;
|
|
28
|
-
emitter.emit("exit", code, null);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
Object.assign(child, {
|
|
32
|
-
stderr,
|
|
33
|
-
pid: Math.floor(Math.random() * 100_000) + 1_000,
|
|
34
|
-
kill: (_signal) => {
|
|
35
|
-
finish(0);
|
|
36
|
-
void runtime?.stop("test_kill").catch(() => { });
|
|
37
|
-
return true;
|
|
38
|
-
},
|
|
39
|
-
spawnfile: command,
|
|
40
|
-
spawnargs: [command, ...args],
|
|
41
|
-
});
|
|
42
|
-
runtime = createWorkerEntryRuntime({
|
|
43
|
-
extensionCatalog: options.extensionCatalog,
|
|
44
|
-
piFactory,
|
|
45
|
-
stderr,
|
|
46
|
-
env: spawnOptions?.env ?? process.env,
|
|
47
|
-
exit: finish,
|
|
48
|
-
});
|
|
49
|
-
setImmediate(() => {
|
|
50
|
-
if (exited)
|
|
51
|
-
return;
|
|
52
|
-
globalThis.WebSocket = WebSocket;
|
|
53
|
-
void runtime?.start().catch((error) => {
|
|
54
|
-
stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
55
|
-
finish(1);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
return child;
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=in-process-worker-spawn.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"in-process-worker-spawn.js","sourceRoot":"","sources":["../../src/worker-testing/in-process-worker-spawn.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,+BAA+B,EAAE,MAAM,4BAA4B,CAAC;AAG7E,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,SAAS,GACb,OAAO,CAAC,IAAI,CAAgD,CAAC,SAAS;IACtE,OAAO,CAAC,IAAI,CAA2B,CAAC,OAAO;IAChD,OAAO,CAAC,IAAI,CAAC,CAAC;AAQf;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CACzC,UAAuC,EAAE;IAEzC,MAAM,SAAS,GACd,OAAO,CAAC,SAAS;QACjB,+BAA+B,CAAC;YAC/B,sBAAsB,EAAE,OAAO,CAAC,sBAAsB;SACtD,CAAC,CAAC;IACJ,OAAO,CAAC,CACP,OAAe,EACf,OAA0B,EAAE,EAC5B,YAA0C,EACzC,EAAE;QACH,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QACjC,MAAM,KAAK,GAAG,IAAI,YAAY,EAA6B,CAAC;QAC5D,MAAM,OAAO,GAAG,KAAgC,CAAC;QACjD,IAAI,MAAM,GAAG,KAAK,CAAC;QAEnB,IAAI,OAAO,GAAuD,IAAI,CAAC;QACvE,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,EAAE;YAC/B,IAAI,CAAC,MAAM,EAAE,CAAC;gBACb,MAAM,GAAG,IAAI,CAAC;gBACd,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;YAClC,CAAC;QACF,CAAC,CAAC;QAEF,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE;YACpB,MAAM;YACN,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,KAAK;YAChD,IAAI,EAAE,CAAC,OAAiC,EAAE,EAAE;gBAC3C,MAAM,CAAC,CAAC,CAAC,CAAC;gBACV,KAAK,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;gBAChD,OAAO,IAAI,CAAC;YACb,CAAC;YACD,SAAS,EAAE,OAAO;YAClB,SAAS,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;SAC7B,CAAC,CAAC;QAEH,OAAO,GAAG,wBAAwB,CAAC;YAClC,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;YAC1C,SAAS;YACT,MAAM;YACN,GAAG,EAAE,YAAY,EAAE,GAAG,IAAI,OAAO,CAAC,GAAG;YACrC,IAAI,EAAE,MAAM;SACZ,CAAC,CAAC;QAEH,YAAY,CAAC,GAAG,EAAE;YACjB,IAAI,MAAM;gBAAE,OAAO;YAClB,UAAiD,CAAC,SAAS,GAAG,SAAS,CAAC;YACzE,KAAK,OAAO,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;gBAC9C,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAC5E,MAAM,CAAC,CAAC,CAAC,CAAC;YACX,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACd,CAAC,CAAiB,CAAC;AACpB,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { createTestConfigSnapshot, IPC_PROTOCOL_VERSION } from "@leitwerk-dev/worker-protocol";
|
|
2
|
-
export async function flushAsyncWork(iterations = 30) {
|
|
3
|
-
for (let i = 0; i < iterations; i++) {
|
|
4
|
-
await new Promise((resolve) => setImmediate(resolve));
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
export const testConfigSnapshot = createTestConfigSnapshot;
|
|
8
|
-
export function baseEnvelope(instanceId, workerId, messageId) {
|
|
9
|
-
return {
|
|
10
|
-
protocol: IPC_PROTOCOL_VERSION,
|
|
11
|
-
messageId,
|
|
12
|
-
instanceId,
|
|
13
|
-
workerId,
|
|
14
|
-
sentAt: new Date().toISOString(),
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=ipc-harness.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ipc-harness.js","sourceRoot":"","sources":["../../src/worker-testing/ipc-harness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAE/F,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,UAAU,GAAG,EAAE;IACnD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7D,CAAC;AACF,CAAC;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,wBAAwB,CAAC;AAE3D,MAAM,UAAU,YAAY,CAAC,UAAkB,EAAE,QAAgB,EAAE,SAAiB;IACnF,OAAO;QACN,QAAQ,EAAE,oBAAmD;QAC7D,SAAS;QACT,UAAU;QACV,QAAQ;QACR,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KAChC,CAAC;AACH,CAAC"}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { StubPiTreeHandleFactory, } from "./stub-pi-tree-handle.js";
|
|
2
|
-
function isObjectLike(value) {
|
|
3
|
-
return typeof value === "object" && value !== null;
|
|
4
|
-
}
|
|
5
|
-
export function synthesizeStubArgValue(key, spec) {
|
|
6
|
-
if (key === "changedProjects") {
|
|
7
|
-
return undefined;
|
|
8
|
-
}
|
|
9
|
-
const type = isObjectLike(spec) && typeof spec.type === "string" ? spec.type : "string";
|
|
10
|
-
switch (type) {
|
|
11
|
-
case "number":
|
|
12
|
-
case "integer":
|
|
13
|
-
return 1;
|
|
14
|
-
case "boolean":
|
|
15
|
-
return true;
|
|
16
|
-
case "array": {
|
|
17
|
-
const itemSpec = isObjectLike(spec) ? spec.items : undefined;
|
|
18
|
-
return [synthesizeStubArgValue(`${key}_item`, itemSpec)];
|
|
19
|
-
}
|
|
20
|
-
case "object":
|
|
21
|
-
return {};
|
|
22
|
-
default:
|
|
23
|
-
return `${key} value`;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export function synthesizeStubToolArgs(parameters) {
|
|
27
|
-
const parameterEntries = isObjectLike(parameters) && parameters.type === "object" && isObjectLike(parameters.properties)
|
|
28
|
-
? Object.entries(parameters.properties)
|
|
29
|
-
: Object.entries(parameters);
|
|
30
|
-
return Object.fromEntries(parameterEntries.map(([key, spec]) => [key, synthesizeStubArgValue(key, spec)]));
|
|
31
|
-
}
|
|
32
|
-
export function createSchemaDrivenToolCallScriptResolver() {
|
|
33
|
-
return ({ tools }) => {
|
|
34
|
-
const markdownTool = tools.find((tool) => tool.name === "markdown_result");
|
|
35
|
-
const completionTool = tools.find((tool) => tool.name !== "markdown_result" && tool.name !== "upload_result_images");
|
|
36
|
-
if (markdownTool && completionTool) {
|
|
37
|
-
return {
|
|
38
|
-
calls: [
|
|
39
|
-
{
|
|
40
|
-
toolName: markdownTool.name,
|
|
41
|
-
args: synthesizeStubToolArgs(markdownTool.parameters),
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
toolName: completionTool.name,
|
|
45
|
-
args: synthesizeStubToolArgs(completionTool.parameters),
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
const tool = markdownTool ?? completionTool ?? tools[0];
|
|
51
|
-
if (!tool) {
|
|
52
|
-
return undefined;
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
toolName: tool.name,
|
|
56
|
-
args: synthesizeStubToolArgs(tool.parameters),
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
export function createSchemaDrivenStubPiFactory(options = {}) {
|
|
61
|
-
return new StubPiTreeHandleFactory({
|
|
62
|
-
toolCallScriptResolver: options.toolCallScriptResolver ?? createSchemaDrivenToolCallScriptResolver(),
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
//# sourceMappingURL=schema-driven-stub-pi.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema-driven-stub-pi.js","sourceRoot":"","sources":["../../src/worker-testing/schema-driven-stub-pi.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stub-pi-controls.js","sourceRoot":"","sources":["../../src/worker-testing/stub-pi-controls.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,8BAA8B;IAC7C,MAAM,KAAK,GAA6B,EAAE,CAAC;IAC3C,OAAO;QACN,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE;QAC7B,GAAG,CAAC,MAAM;YACT,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC;QAC1C,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -1,515 +0,0 @@
|
|
|
1
|
-
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
function stringifyToolResult(result) {
|
|
4
|
-
if (typeof result === "string") {
|
|
5
|
-
return result;
|
|
6
|
-
}
|
|
7
|
-
if (result === undefined) {
|
|
8
|
-
return "ok";
|
|
9
|
-
}
|
|
10
|
-
try {
|
|
11
|
-
return JSON.stringify(result, null, 2);
|
|
12
|
-
}
|
|
13
|
-
catch {
|
|
14
|
-
return String(result);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
function expandStubToolCallScriptItem(item) {
|
|
18
|
-
if ("calls" in item) {
|
|
19
|
-
return [...item.calls];
|
|
20
|
-
}
|
|
21
|
-
return [item];
|
|
22
|
-
}
|
|
23
|
-
function stubToolCallId(turnSeq, totalCalls, index) {
|
|
24
|
-
if (totalCalls <= 1) {
|
|
25
|
-
return `tool-${turnSeq}`;
|
|
26
|
-
}
|
|
27
|
-
return `tool-${turnSeq}-${index + 1}`;
|
|
28
|
-
}
|
|
29
|
-
function createEmptyStubPiTreeState() {
|
|
30
|
-
return {
|
|
31
|
-
turnSeq: 0,
|
|
32
|
-
currentLeafId: null,
|
|
33
|
-
entries: new Map(),
|
|
34
|
-
childIdsByParent: new Map(),
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function deriveStubLeafIdFromEntries(state) {
|
|
38
|
-
let leafId = null;
|
|
39
|
-
for (const entryId of state.entries.keys()) {
|
|
40
|
-
leafId = entryId;
|
|
41
|
-
}
|
|
42
|
-
return leafId;
|
|
43
|
-
}
|
|
44
|
-
function serializeStubPiTreeState(state) {
|
|
45
|
-
const persisted = {
|
|
46
|
-
turnSeq: state.turnSeq,
|
|
47
|
-
currentLeafId: state.currentLeafId,
|
|
48
|
-
entries: [...state.entries.values()],
|
|
49
|
-
childIdsByParent: [...state.childIdsByParent.entries()].map(([parentId, childIds]) => ({
|
|
50
|
-
parentId,
|
|
51
|
-
childIds: [...childIds],
|
|
52
|
-
})),
|
|
53
|
-
};
|
|
54
|
-
return JSON.stringify(persisted);
|
|
55
|
-
}
|
|
56
|
-
function deserializeStubPiTreeState(value) {
|
|
57
|
-
const parsed = JSON.parse(value);
|
|
58
|
-
return {
|
|
59
|
-
turnSeq: typeof parsed.turnSeq === "number" ? parsed.turnSeq : 0,
|
|
60
|
-
currentLeafId: typeof parsed.currentLeafId === "string" || parsed.currentLeafId === null
|
|
61
|
-
? parsed.currentLeafId
|
|
62
|
-
: null,
|
|
63
|
-
entries: new Map((parsed.entries ?? []).map((entry) => [entry.id, entry])),
|
|
64
|
-
childIdsByParent: new Map((parsed.childIdsByParent ?? []).map((entry) => [entry.parentId, [...entry.childIds]])),
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
export class StubPiTreeHandle {
|
|
68
|
-
sessionId;
|
|
69
|
-
treeFile;
|
|
70
|
-
isResumed;
|
|
71
|
-
prompts = [];
|
|
72
|
-
steers = [];
|
|
73
|
-
beforeTurn;
|
|
74
|
-
_closed = false;
|
|
75
|
-
branchDriftPending = false;
|
|
76
|
-
handlers = new Set();
|
|
77
|
-
diagnosticHandlers = new Set();
|
|
78
|
-
toolCallScriptResolver;
|
|
79
|
-
state;
|
|
80
|
-
runDetails;
|
|
81
|
-
persistState;
|
|
82
|
-
constructor(options) {
|
|
83
|
-
this.sessionId = options.sessionId;
|
|
84
|
-
this.treeFile = options.treeFile;
|
|
85
|
-
this.isResumed = options.isResumed;
|
|
86
|
-
this.toolCallScriptResolver = options.toolCallScriptResolver;
|
|
87
|
-
this.state = options.state ?? createEmptyStubPiTreeState();
|
|
88
|
-
this.persistState = options.persistState;
|
|
89
|
-
this.runDetails = {
|
|
90
|
-
loadedAgentsFiles: options.runDetails?.loadedAgentsFiles?.map((file) => ({ ...file })) ?? [],
|
|
91
|
-
loadedSkills: options.runDetails?.loadedSkills?.map((skill) => ({ ...skill })) ?? [],
|
|
92
|
-
availableToolNames: [...(options.runDetails?.availableToolNames ?? [])],
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
get closed() {
|
|
96
|
-
return this._closed;
|
|
97
|
-
}
|
|
98
|
-
failNextTurnWithBranchDrift() {
|
|
99
|
-
this.branchDriftPending = true;
|
|
100
|
-
}
|
|
101
|
-
assertOpen() {
|
|
102
|
-
if (this._closed) {
|
|
103
|
-
throw new Error("Handle is closed");
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
addEntry(entry) {
|
|
107
|
-
this.state.entries.set(entry.id, entry);
|
|
108
|
-
const siblings = this.state.childIdsByParent.get(entry.parentId) ?? [];
|
|
109
|
-
siblings.push(entry.id);
|
|
110
|
-
this.state.childIdsByParent.set(entry.parentId, siblings);
|
|
111
|
-
this.state.currentLeafId = entry.id;
|
|
112
|
-
}
|
|
113
|
-
createMessageEntry(id, parentId, role, content, timestamp) {
|
|
114
|
-
return {
|
|
115
|
-
id,
|
|
116
|
-
parentId,
|
|
117
|
-
type: "message",
|
|
118
|
-
timestamp,
|
|
119
|
-
message: {
|
|
120
|
-
role,
|
|
121
|
-
content,
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
emitEvent(event) {
|
|
126
|
-
for (const handler of this.handlers) {
|
|
127
|
-
handler(event);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
getRunDetails() {
|
|
131
|
-
return {
|
|
132
|
-
loadedAgentsFiles: this.runDetails.loadedAgentsFiles.map((file) => ({ ...file })),
|
|
133
|
-
loadedSkills: this.runDetails.loadedSkills.map((skill) => ({ ...skill })),
|
|
134
|
-
availableToolNames: [...this.runDetails.availableToolNames],
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
getLeafId() {
|
|
138
|
-
return this.state.currentLeafId;
|
|
139
|
-
}
|
|
140
|
-
getEntry(id) {
|
|
141
|
-
return this.state.entries.get(id);
|
|
142
|
-
}
|
|
143
|
-
getBranch(fromId = this.state.currentLeafId ?? undefined) {
|
|
144
|
-
if (!fromId) {
|
|
145
|
-
return [];
|
|
146
|
-
}
|
|
147
|
-
const branch = [];
|
|
148
|
-
let currentId = fromId;
|
|
149
|
-
while (currentId) {
|
|
150
|
-
const entry = this.state.entries.get(currentId);
|
|
151
|
-
if (!entry) {
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
branch.push(entry);
|
|
155
|
-
currentId = entry.parentId;
|
|
156
|
-
}
|
|
157
|
-
branch.reverse();
|
|
158
|
-
return branch;
|
|
159
|
-
}
|
|
160
|
-
getChildren(parentId) {
|
|
161
|
-
return (this.state.childIdsByParent.get(parentId) ?? [])
|
|
162
|
-
.map((childId) => this.state.entries.get(childId))
|
|
163
|
-
.filter((entry) => entry !== undefined);
|
|
164
|
-
}
|
|
165
|
-
getTree() {
|
|
166
|
-
const buildNode = (entry) => ({
|
|
167
|
-
entry,
|
|
168
|
-
children: this.getChildren(entry.id).map(buildNode),
|
|
169
|
-
});
|
|
170
|
-
return (this.state.childIdsByParent.get(null) ?? [])
|
|
171
|
-
.map((entryId) => this.state.entries.get(entryId))
|
|
172
|
-
.filter((entry) => entry !== undefined)
|
|
173
|
-
.map(buildNode);
|
|
174
|
-
}
|
|
175
|
-
async branch(entryId) {
|
|
176
|
-
this.assertOpen();
|
|
177
|
-
if (!this.state.entries.has(entryId)) {
|
|
178
|
-
throw new Error(`Unknown Pi entry '${entryId}'`);
|
|
179
|
-
}
|
|
180
|
-
this.state.currentLeafId = entryId;
|
|
181
|
-
await this.persistState?.();
|
|
182
|
-
}
|
|
183
|
-
async branchFromRoot() {
|
|
184
|
-
this.assertOpen();
|
|
185
|
-
this.state.currentLeafId = null;
|
|
186
|
-
await this.persistState?.();
|
|
187
|
-
}
|
|
188
|
-
async resetLeaf() {
|
|
189
|
-
await this.branchFromRoot();
|
|
190
|
-
}
|
|
191
|
-
async compact(_customInstructions, details) {
|
|
192
|
-
this.assertOpen();
|
|
193
|
-
const timestamp = new Date().toISOString();
|
|
194
|
-
const compactionEntryId = `compaction-${++this.state.turnSeq}`;
|
|
195
|
-
this.addEntry({
|
|
196
|
-
id: compactionEntryId,
|
|
197
|
-
parentId: this.state.currentLeafId,
|
|
198
|
-
type: "compaction",
|
|
199
|
-
timestamp,
|
|
200
|
-
details,
|
|
201
|
-
});
|
|
202
|
-
await this.persistState?.();
|
|
203
|
-
return { summary: "Stub compaction" };
|
|
204
|
-
}
|
|
205
|
-
async executeTurn(input) {
|
|
206
|
-
this.assertOpen();
|
|
207
|
-
if ((await this.beforeTurn?.(input.kind, input.options, input.promptText)) === false) {
|
|
208
|
-
input.options = undefined;
|
|
209
|
-
}
|
|
210
|
-
if (this.branchDriftPending) {
|
|
211
|
-
this.branchDriftPending = false;
|
|
212
|
-
throw Object.assign(new Error("stubbed Pi branch drift"), {
|
|
213
|
-
name: "PiBranchDriftError",
|
|
214
|
-
failureCode: "branch_drift",
|
|
215
|
-
toTurnFailureOptions: () => ({
|
|
216
|
-
failureCode: "branch_drift",
|
|
217
|
-
failureDetails: { operation: input.kind },
|
|
218
|
-
recoveryContext: null,
|
|
219
|
-
restorePrimaryLeaf: false,
|
|
220
|
-
}),
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
if (input.promptText !== undefined) {
|
|
224
|
-
this.prompts.push(input.promptText);
|
|
225
|
-
}
|
|
226
|
-
const startLeafId = this.state.currentLeafId;
|
|
227
|
-
const turnId = `turn-${++this.state.turnSeq}`;
|
|
228
|
-
const timestamp = new Date().toISOString();
|
|
229
|
-
const createdEntryIds = [];
|
|
230
|
-
if (input.appendPromptUserMessage) {
|
|
231
|
-
const userEntryId = `user-${this.state.turnSeq}`;
|
|
232
|
-
this.addEntry(this.createMessageEntry(userEntryId, this.state.currentLeafId, "user", input.promptText ?? "", timestamp));
|
|
233
|
-
createdEntryIds.push(userEntryId);
|
|
234
|
-
}
|
|
235
|
-
this.emitEvent({ type: "turn.start", turnId, data: {}, timestamp });
|
|
236
|
-
const tools = new Map((input.options?.tools ?? []).map((tool) => [tool.name, tool]));
|
|
237
|
-
let assistantContent = input.promptText ?? "Continued.";
|
|
238
|
-
let assistantContentFromScriptedMarkdown = false;
|
|
239
|
-
const scriptedItem = this.toolCallScriptResolver?.({
|
|
240
|
-
promptText: input.promptText ?? "",
|
|
241
|
-
tools: input.options?.tools ?? [],
|
|
242
|
-
});
|
|
243
|
-
const scriptedCalls = scriptedItem ? expandStubToolCallScriptItem(scriptedItem) : [];
|
|
244
|
-
if (scriptedCalls.length > 0) {
|
|
245
|
-
for (const [callIndex, scriptedCall] of scriptedCalls.entries()) {
|
|
246
|
-
const toolCallId = stubToolCallId(this.state.turnSeq, scriptedCalls.length, callIndex);
|
|
247
|
-
this.emitEvent({
|
|
248
|
-
type: "tool.call",
|
|
249
|
-
turnId,
|
|
250
|
-
data: {
|
|
251
|
-
toolCallId,
|
|
252
|
-
name: scriptedCall.toolName,
|
|
253
|
-
arguments: scriptedCall.args,
|
|
254
|
-
},
|
|
255
|
-
timestamp,
|
|
256
|
-
});
|
|
257
|
-
const tool = tools.get(scriptedCall.toolName);
|
|
258
|
-
if (!tool && scriptedCall.toolName === "markdown_result") {
|
|
259
|
-
const markdown = scriptedCall.args.markdown;
|
|
260
|
-
if (typeof markdown === "string") {
|
|
261
|
-
assistantContent = markdown;
|
|
262
|
-
assistantContentFromScriptedMarkdown = true;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
if (tool) {
|
|
266
|
-
try {
|
|
267
|
-
const result = await tool.execute(scriptedCall.args);
|
|
268
|
-
if (!assistantContentFromScriptedMarkdown) {
|
|
269
|
-
assistantContent = stringifyToolResult(result);
|
|
270
|
-
}
|
|
271
|
-
this.emitEvent({
|
|
272
|
-
type: "tool.result",
|
|
273
|
-
turnId,
|
|
274
|
-
data: { toolCallId, name: scriptedCall.toolName, result },
|
|
275
|
-
timestamp,
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
catch (error) {
|
|
279
|
-
this.emitEvent({
|
|
280
|
-
type: "error",
|
|
281
|
-
turnId,
|
|
282
|
-
data: {
|
|
283
|
-
message: error instanceof Error ? error.message : String(error),
|
|
284
|
-
toolName: scriptedCall.toolName,
|
|
285
|
-
},
|
|
286
|
-
timestamp,
|
|
287
|
-
});
|
|
288
|
-
throw error;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
for (let i = 0; i < (scriptedCall.intermediateEntryCount ?? 0); i++) {
|
|
292
|
-
const intermediateEntryId = scriptedCalls.length === 1
|
|
293
|
-
? `intermediate-${this.state.turnSeq}-${i + 1}`
|
|
294
|
-
: `intermediate-${this.state.turnSeq}-${callIndex + 1}-${i + 1}`;
|
|
295
|
-
this.addEntry(this.createMessageEntry(intermediateEntryId, this.state.currentLeafId, "assistant", `Intermediate entry ${i + 1}`, timestamp));
|
|
296
|
-
createdEntryIds.push(intermediateEntryId);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
else if (tools.size > 0) {
|
|
301
|
-
throw new Error(`Stub Pi prompt requires a stub tool-call script when tools are provided (${[...tools.keys()].join(", ")})`);
|
|
302
|
-
}
|
|
303
|
-
else if (input.promptText !== undefined) {
|
|
304
|
-
this.emitEvent({
|
|
305
|
-
type: "stream.delta",
|
|
306
|
-
turnId,
|
|
307
|
-
data: { text: input.promptText },
|
|
308
|
-
timestamp,
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
this.addEntry(this.createMessageEntry(turnId, this.state.currentLeafId, "assistant", assistantContent, timestamp));
|
|
312
|
-
createdEntryIds.push(turnId);
|
|
313
|
-
await this.persistState?.();
|
|
314
|
-
this.emitEvent({ type: "turn.end", turnId, data: {}, timestamp });
|
|
315
|
-
const resultEntryId = this.state.currentLeafId;
|
|
316
|
-
if (!resultEntryId) {
|
|
317
|
-
throw new Error(input.appendPromptUserMessage
|
|
318
|
-
? "Stub Pi prompt completed without an active leaf"
|
|
319
|
-
: "Stub Pi continuation completed without an active leaf");
|
|
320
|
-
}
|
|
321
|
-
return {
|
|
322
|
-
startLeafId,
|
|
323
|
-
endLeafId: resultEntryId,
|
|
324
|
-
createdEntryIds,
|
|
325
|
-
resultEntryId,
|
|
326
|
-
assistantMarkdown: assistantContent,
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
async prompt(text, options = {}) {
|
|
330
|
-
return await this.executeTurn({
|
|
331
|
-
kind: "prompt",
|
|
332
|
-
promptText: text,
|
|
333
|
-
options,
|
|
334
|
-
appendPromptUserMessage: true,
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
async promptLiteral(text, options = {}) {
|
|
338
|
-
return await this.executeTurn({
|
|
339
|
-
kind: "literal",
|
|
340
|
-
promptText: text,
|
|
341
|
-
options,
|
|
342
|
-
appendPromptUserMessage: true,
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
async promptCustom(input, options = {}) {
|
|
346
|
-
const startLeafId = this.getLeafId();
|
|
347
|
-
const promptEntryId = await this.appendCustomMessage(input);
|
|
348
|
-
const result = await this.executeTurn({
|
|
349
|
-
kind: "custom",
|
|
350
|
-
options,
|
|
351
|
-
appendPromptUserMessage: false,
|
|
352
|
-
});
|
|
353
|
-
return {
|
|
354
|
-
...result,
|
|
355
|
-
startLeafId,
|
|
356
|
-
createdEntryIds: [promptEntryId, ...result.createdEntryIds],
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
async continueTurn(options = {}) {
|
|
360
|
-
return await this.executeTurn({
|
|
361
|
-
kind: "continue",
|
|
362
|
-
options,
|
|
363
|
-
appendPromptUserMessage: false,
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
async appendUserMessage(text) {
|
|
367
|
-
this.assertOpen();
|
|
368
|
-
const timestamp = new Date().toISOString();
|
|
369
|
-
const userEntryId = `user-${++this.state.turnSeq}`;
|
|
370
|
-
this.addEntry(this.createMessageEntry(userEntryId, this.state.currentLeafId, "user", text, timestamp));
|
|
371
|
-
await this.persistState?.();
|
|
372
|
-
return userEntryId;
|
|
373
|
-
}
|
|
374
|
-
async appendCustomMessage(input) {
|
|
375
|
-
this.assertOpen();
|
|
376
|
-
const timestamp = new Date().toISOString();
|
|
377
|
-
const entryId = `custom-${++this.state.turnSeq}`;
|
|
378
|
-
this.addEntry({
|
|
379
|
-
id: entryId,
|
|
380
|
-
parentId: this.state.currentLeafId,
|
|
381
|
-
type: "custom_message",
|
|
382
|
-
timestamp,
|
|
383
|
-
customType: "leitwerk",
|
|
384
|
-
content: input.content,
|
|
385
|
-
details: input.details,
|
|
386
|
-
});
|
|
387
|
-
await this.persistState?.();
|
|
388
|
-
return entryId;
|
|
389
|
-
}
|
|
390
|
-
async steer(text) {
|
|
391
|
-
this.assertOpen();
|
|
392
|
-
this.steers.push(text);
|
|
393
|
-
}
|
|
394
|
-
async abortTurn() {
|
|
395
|
-
this.assertOpen();
|
|
396
|
-
}
|
|
397
|
-
subscribe(handler) {
|
|
398
|
-
this.handlers.add(handler);
|
|
399
|
-
return () => {
|
|
400
|
-
this.handlers.delete(handler);
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
subscribeDiagnostics(handler) {
|
|
404
|
-
this.diagnosticHandlers.add(handler);
|
|
405
|
-
return () => {
|
|
406
|
-
this.diagnosticHandlers.delete(handler);
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
emitDiagnostic(diagnostic) {
|
|
410
|
-
for (const handler of this.diagnosticHandlers)
|
|
411
|
-
handler(diagnostic);
|
|
412
|
-
}
|
|
413
|
-
async close() {
|
|
414
|
-
await this.persistState?.();
|
|
415
|
-
this._closed = true;
|
|
416
|
-
this.handlers.clear();
|
|
417
|
-
this.diagnosticHandlers.clear();
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
export class StubPiTreeHandleFactory {
|
|
421
|
-
sessions = [];
|
|
422
|
-
toolCallScriptResolver;
|
|
423
|
-
seq = 0;
|
|
424
|
-
treeStateByFile = new Map();
|
|
425
|
-
constructor(options = {}) {
|
|
426
|
-
this.toolCallScriptResolver = options.toolCallScriptResolver;
|
|
427
|
-
}
|
|
428
|
-
async prepareManagedBootstrap(opts) {
|
|
429
|
-
return {
|
|
430
|
-
loadedResourceIds: opts.manifest.provenance.map((resource) => resource.snapshotPath),
|
|
431
|
-
loadedAgentsFiles: [],
|
|
432
|
-
loadedSkillFiles: [],
|
|
433
|
-
resolvedModel: { ...opts.expectedModel },
|
|
434
|
-
diagnostics: [],
|
|
435
|
-
};
|
|
436
|
-
}
|
|
437
|
-
async inspectPrimaryTree(opts) {
|
|
438
|
-
let treeState = this.treeStateByFile.get(opts.treeFile);
|
|
439
|
-
if (!treeState) {
|
|
440
|
-
try {
|
|
441
|
-
treeState = deserializeStubPiTreeState(readFileSync(opts.treeFile, "utf8"));
|
|
442
|
-
}
|
|
443
|
-
catch (error) {
|
|
444
|
-
if (typeof error === "object" &&
|
|
445
|
-
error !== null &&
|
|
446
|
-
"code" in error &&
|
|
447
|
-
error.code === "ENOENT") {
|
|
448
|
-
return { currentLeafId: null, entries: [] };
|
|
449
|
-
}
|
|
450
|
-
throw error;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
return {
|
|
454
|
-
currentLeafId: treeState.currentLeafId ?? deriveStubLeafIdFromEntries(treeState),
|
|
455
|
-
entries: [...treeState.entries.values()].map((entry) => ({
|
|
456
|
-
id: entry.id,
|
|
457
|
-
parentId: entry.parentId,
|
|
458
|
-
})),
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
|
-
async createPrimaryTreeHandle(opts) {
|
|
462
|
-
const persistState = async (state) => {
|
|
463
|
-
this.treeStateByFile.set(opts.treeFile, state);
|
|
464
|
-
try {
|
|
465
|
-
mkdirSync(path.dirname(opts.treeFile), { recursive: true });
|
|
466
|
-
writeFileSync(opts.treeFile, serializeStubPiTreeState(state), "utf8");
|
|
467
|
-
}
|
|
468
|
-
catch (error) {
|
|
469
|
-
if (typeof error !== "object" ||
|
|
470
|
-
error === null ||
|
|
471
|
-
!("code" in error) ||
|
|
472
|
-
!["ENOENT", "EACCES", "EROFS", "EPERM"].includes(String(error.code))) {
|
|
473
|
-
throw error;
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
};
|
|
477
|
-
let treeState = this.treeStateByFile.get(opts.treeFile);
|
|
478
|
-
if (!treeState && opts.resume) {
|
|
479
|
-
try {
|
|
480
|
-
const persisted = readFileSync(opts.treeFile, "utf8");
|
|
481
|
-
treeState = deserializeStubPiTreeState(persisted);
|
|
482
|
-
}
|
|
483
|
-
catch (error) {
|
|
484
|
-
if (typeof error === "object" &&
|
|
485
|
-
error !== null &&
|
|
486
|
-
"code" in error &&
|
|
487
|
-
error.code !== "ENOENT") {
|
|
488
|
-
throw error;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
treeState ??= createEmptyStubPiTreeState();
|
|
493
|
-
if (opts.resume) {
|
|
494
|
-
treeState.currentLeafId = deriveStubLeafIdFromEntries(treeState);
|
|
495
|
-
}
|
|
496
|
-
this.treeStateByFile.set(opts.treeFile, treeState);
|
|
497
|
-
const piHandle = new StubPiTreeHandle({
|
|
498
|
-
sessionId: `stub-${++this.seq}`,
|
|
499
|
-
treeFile: opts.treeFile,
|
|
500
|
-
isResumed: opts.resume,
|
|
501
|
-
toolCallScriptResolver: this.toolCallScriptResolver,
|
|
502
|
-
state: treeState,
|
|
503
|
-
persistState: () => persistState(treeState),
|
|
504
|
-
runDetails: {
|
|
505
|
-
availableToolNames: opts.piConfig?.availableToolNames ?? [],
|
|
506
|
-
},
|
|
507
|
-
});
|
|
508
|
-
this.sessions.push(piHandle);
|
|
509
|
-
if (!opts.resume) {
|
|
510
|
-
await persistState(treeState);
|
|
511
|
-
}
|
|
512
|
-
return piHandle;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
//# sourceMappingURL=stub-pi-tree-handle.js.map
|