@ftrdotdev/pi-delegates 0.0.0-stage → 0.2.0
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/CHANGELOG.md +128 -0
- package/LICENSE +21 -0
- package/OPERATIONS.md +130 -0
- package/README.md +456 -2
- package/ROADMAP.md +179 -0
- package/TESTING.md +896 -0
- package/agents.ts +8 -0
- package/examples/README.md +114 -0
- package/examples/gated.ts +28 -0
- package/index.ts +9 -0
- package/package.json +94 -4
- package/skills/pi-delegates/SKILL.md +176 -0
- package/skills/pi-delegates/references/control.md +159 -0
- package/skills/pi-delegates/references/definitions.md +163 -0
- package/skills/pi-delegates/references/gates.md +175 -0
- package/skills/pi-delegates/references/launch.md +184 -0
- package/src/docs-contract.test.ts +106 -0
- package/src/domain/definitions.test.ts +41 -0
- package/src/domain/definitions.ts +163 -0
- package/src/domain/failure.ts +33 -0
- package/src/domain/ids.ts +13 -0
- package/src/domain/model-source.ts +30 -0
- package/src/domain/names.ts +35 -0
- package/src/domain/orchestration/admission.ts +78 -0
- package/src/domain/orchestration/control.test.ts +1332 -0
- package/src/domain/orchestration/control.ts +457 -0
- package/src/domain/orchestration/fanout.test.ts +524 -0
- package/src/domain/orchestration/fanout.ts +372 -0
- package/src/domain/orchestration/gates.test.ts +685 -0
- package/src/domain/orchestration/gates.ts +360 -0
- package/src/domain/orchestration/launch.test.ts +372 -0
- package/src/domain/orchestration/launch.ts +691 -0
- package/src/domain/orchestration/requests.test.ts +695 -0
- package/src/domain/orchestration/requests.ts +782 -0
- package/src/domain/orchestration/review.test.ts +292 -0
- package/src/domain/orchestration/review.ts +168 -0
- package/src/domain/orchestration/run-wait.test.ts +265 -0
- package/src/domain/orchestration/run-wait.ts +256 -0
- package/src/domain/orchestration/workflow-section.test.ts +62 -0
- package/src/domain/orchestration/workflow-section.ts +99 -0
- package/src/domain/orchestration/workflow.test.ts +1566 -0
- package/src/domain/orchestration/workflow.ts +778 -0
- package/src/domain/run-records.test.ts +27 -0
- package/src/domain/run-records.ts +689 -0
- package/src/domain/settlement.test.ts +186 -0
- package/src/domain/settlement.ts +137 -0
- package/src/domain/shapes.test.ts +185 -0
- package/src/domain/skills.test.ts +477 -0
- package/src/domain/skills.ts +114 -0
- package/src/domain/tool-schema.test.ts +46 -0
- package/src/domain/tool-schema.ts +20 -0
- package/src/domain/toolkit.test.ts +215 -0
- package/src/domain/toolkit.ts +374 -0
- package/src/domain/turn-budget.test.ts +37 -0
- package/src/domain/turn-budget.ts +23 -0
- package/src/domain/view.test.ts +803 -0
- package/src/domain/view.ts +491 -0
- package/src/example.test.ts +15 -0
- package/src/extension/commands.test.ts +485 -0
- package/src/extension/commands.ts +230 -0
- package/src/extension/entry.test.ts +1276 -0
- package/src/extension/entry.ts +380 -0
- package/src/extension/gate-alerts.test.ts +237 -0
- package/src/extension/gate-alerts.ts +143 -0
- package/src/extension/guard.test.ts +48 -0
- package/src/extension/guard.ts +31 -0
- package/src/extension/host-signals.test.ts +20 -0
- package/src/extension/host-signals.ts +13 -0
- package/src/extension/inspector-command.test.ts +1343 -0
- package/src/extension/inspector-command.ts +685 -0
- package/src/extension/prompt.test.ts +108 -0
- package/src/extension/prompt.ts +50 -0
- package/src/extension/request-alerts.test.ts +183 -0
- package/src/extension/request-alerts.ts +181 -0
- package/src/extension/retry-observer.test.ts +292 -0
- package/src/extension/retry-observer.ts +150 -0
- package/src/extension/revocation.test.ts +81 -0
- package/src/extension/revocation.ts +84 -0
- package/src/extension/settle-alerts.test.ts +579 -0
- package/src/extension/settle-alerts.ts +175 -0
- package/src/extension/shortcut.test.ts +62 -0
- package/src/extension/shortcut.ts +105 -0
- package/src/extension/tools.test.ts +1294 -0
- package/src/extension/tools.ts +553 -0
- package/src/extension/version.test.ts +115 -0
- package/src/extension/version.ts +97 -0
- package/src/goldens.test.ts +294 -0
- package/src/harness-policy.test.ts +76 -0
- package/src/layers.test.ts +309 -0
- package/src/layers.ts +405 -0
- package/src/package-manifest.test.ts +170 -0
- package/src/presentation/actions.test.ts +221 -0
- package/src/presentation/actions.ts +85 -0
- package/src/presentation/activity.test.ts +386 -0
- package/src/presentation/activity.ts +66 -0
- package/src/presentation/close.test.ts +359 -0
- package/src/presentation/inspector.test.ts +682 -0
- package/src/presentation/inspector.ts +442 -0
- package/src/presentation/overlay.test.ts +553 -0
- package/src/presentation/overlay.ts +229 -0
- package/src/presentation/repaint.test.ts +365 -0
- package/src/presentation/shortcut.ts +2 -0
- package/src/presentation/snapshot.test.ts +535 -0
- package/src/presentation/snapshot.ts +306 -0
- package/src/presentation/status.test.ts +43 -0
- package/src/presentation/status.ts +30 -0
- package/src/presentation/strip.test.ts +203 -0
- package/src/presentation/strip.ts +67 -0
- package/src/presentation/wording.test.ts +388 -0
- package/src/presentation/wording.ts +294 -0
- package/src/runtime/bridge.test.ts +131 -0
- package/src/runtime/bridge.ts +128 -0
- package/src/runtime/clock.test.ts +31 -0
- package/src/runtime/clock.ts +31 -0
- package/src/runtime/config.test.ts +63 -0
- package/src/runtime/config.ts +92 -0
- package/src/runtime/context.test.ts +19 -0
- package/src/runtime/context.ts +9 -0
- package/src/runtime/execution-env.test.ts +33 -0
- package/src/runtime/execution-env.ts +15 -0
- package/src/runtime/extensions.test.ts +86 -0
- package/src/runtime/extensions.ts +152 -0
- package/src/runtime/handle.ts +54 -0
- package/src/runtime/log.test.ts +140 -0
- package/src/runtime/log.ts +91 -0
- package/src/runtime/mcp.test.ts +1450 -0
- package/src/runtime/mcp.ts +1005 -0
- package/src/runtime/models.test.ts +145 -0
- package/src/runtime/models.ts +259 -0
- package/src/runtime/observe.test.ts +50 -0
- package/src/runtime/observe.ts +150 -0
- package/src/runtime/runtime-state.test.ts +25 -0
- package/src/runtime/runtime-state.ts +36 -0
- package/src/runtime/session-tag.ts +11 -0
- package/src/runtime/session.test.ts +352 -0
- package/src/runtime/session.ts +263 -0
- package/src/runtime/storage.ts +29 -0
- package/src/test-hygiene.test.ts +97 -0
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { AgentDoc, MemoryStorage } from "@earendil-works/pi-durable";
|
|
2
|
+
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
3
|
+
import { assert, it } from "@effect/vitest";
|
|
4
|
+
import { makeTempDir } from "../../../test-support/platform.ts";
|
|
5
|
+
import { rejects } from "../../../test-support/assertions.ts";
|
|
6
|
+
import { stubHostSource, type StubModelSource } from "../../../test-support/stub-model-source.ts";
|
|
7
|
+
import { waitFor } from "../../../test-support/wait.ts";
|
|
8
|
+
import { createCatalogue, defineAgent } from "../definitions.ts";
|
|
9
|
+
import { RunDoc, RunIndexDoc } from "../run-records.ts";
|
|
10
|
+
import { viewRun } from "../view.ts";
|
|
11
|
+
import { CODING_EXTENSION } from "../names.ts";
|
|
12
|
+
import { control } from "./control.ts";
|
|
13
|
+
import { HostModelAdapter } from "../../runtime/models.ts";
|
|
14
|
+
import type { LogFields, LogLevel, LogSink } from "../../runtime/log.ts";
|
|
15
|
+
import { type SessionRuntime } from "../../runtime/session.ts";
|
|
16
|
+
|
|
17
|
+
import { HostModelMissing, launch, type HostDefaults } from "./launch.ts";
|
|
18
|
+
import { openTestSession, type TestSession } from "../../../test-support/seams.ts";
|
|
19
|
+
|
|
20
|
+
const host: HostDefaults = {
|
|
21
|
+
model: { provider: "stub", modelId: "stub-1" },
|
|
22
|
+
thinkingLevel: "low",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const deployer = defineAgent({
|
|
26
|
+
name: "deployer",
|
|
27
|
+
role: "Deploy agent",
|
|
28
|
+
prompt: { role: "You deploy things." },
|
|
29
|
+
tools: ["bash"],
|
|
30
|
+
extensions: [CODING_EXTENSION],
|
|
31
|
+
approval: { gates: [{ name: "deploy", tools: ["bash"], match: "deploy" }] },
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const catalogue = createCatalogue([deployer]);
|
|
35
|
+
|
|
36
|
+
const scoutDefinition = defineAgent({
|
|
37
|
+
name: "scout",
|
|
38
|
+
role: "Read-only explorer",
|
|
39
|
+
prompt: { role: "You explore the repository." },
|
|
40
|
+
tools: ["read"],
|
|
41
|
+
extensions: [CODING_EXTENSION],
|
|
42
|
+
approval: { gates: [] },
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const recordingSink = () => {
|
|
46
|
+
const entries: { level: LogLevel; code: string; fields: LogFields }[] = [];
|
|
47
|
+
const sink: LogSink = {
|
|
48
|
+
write: (level, code, fields = {}) => {
|
|
49
|
+
entries.push({ level, code, fields });
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
return { sink, entries };
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const open = async (
|
|
56
|
+
log?: LogSink,
|
|
57
|
+
options: {
|
|
58
|
+
readonly hang?: boolean;
|
|
59
|
+
readonly text?: string;
|
|
60
|
+
readonly source?: StubModelSource;
|
|
61
|
+
readonly toolCall?: { readonly name: string; readonly arguments: Record<string, unknown> };
|
|
62
|
+
} = {},
|
|
63
|
+
): Promise<TestSession> => {
|
|
64
|
+
const sessionDir = await makeTempDir("delegates-launch-");
|
|
65
|
+
const { source, ...stub } = options;
|
|
66
|
+
return openTestSession({
|
|
67
|
+
identity: { sessionId: "s-1", sessionDir, cwd: sessionDir, agentDir: sessionDir },
|
|
68
|
+
models: new HostModelAdapter(source ?? stubHostSource(stub)),
|
|
69
|
+
storage: new MemoryStorage(),
|
|
70
|
+
...(log === undefined ? {} : { log }),
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const deps = (runtime: SessionRuntime, waitMs = 5_000) => ({
|
|
75
|
+
runtime,
|
|
76
|
+
catalogue,
|
|
77
|
+
host,
|
|
78
|
+
waitMs,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("a launch fails before task creation when the host model is empty", async () => {
|
|
82
|
+
const { sink, entries } = recordingSink();
|
|
83
|
+
const runtime = await open(sink);
|
|
84
|
+
try {
|
|
85
|
+
await rejects(
|
|
86
|
+
launch(
|
|
87
|
+
{ kind: "single", agent: "scout", task: "look" },
|
|
88
|
+
{
|
|
89
|
+
runtime,
|
|
90
|
+
catalogue,
|
|
91
|
+
host: { model: { provider: "", modelId: "" }, thinkingLevel: "low" },
|
|
92
|
+
waitMs: 5_000,
|
|
93
|
+
},
|
|
94
|
+
),
|
|
95
|
+
(error: unknown) =>
|
|
96
|
+
error instanceof HostModelMissing &&
|
|
97
|
+
error.message.includes("scout") &&
|
|
98
|
+
error.message.includes("model.provider") &&
|
|
99
|
+
error.message.includes("model.modelId"),
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const index = await runtime.snapshot(RunIndexDoc);
|
|
103
|
+
assert.deepStrictEqual(index?.runIds ?? [], []);
|
|
104
|
+
assert.deepStrictEqual(
|
|
105
|
+
entries.map((entry) => entry.code),
|
|
106
|
+
["launch.host_model_missing"],
|
|
107
|
+
);
|
|
108
|
+
assert.strictEqual(entries[0]?.level, "error");
|
|
109
|
+
assert.strictEqual(entries[0]?.fields.agent, "scout");
|
|
110
|
+
} finally {
|
|
111
|
+
await runtime.close();
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("a timeout and a gate are logged with the run id, and settled is not", async () => {
|
|
116
|
+
const timed = recordingSink();
|
|
117
|
+
const slow = await open(timed.sink, { hang: true });
|
|
118
|
+
try {
|
|
119
|
+
const result = await launch({ kind: "single", agent: "scout", task: "slow" }, deps(slow, 50));
|
|
120
|
+
const waits = timed.entries.filter((entry) => entry.code.startsWith("wait."));
|
|
121
|
+
assert.deepStrictEqual(
|
|
122
|
+
waits.map((entry) => [entry.code, entry.fields.runId]),
|
|
123
|
+
[["wait.timeout", result.view.runId]],
|
|
124
|
+
);
|
|
125
|
+
} finally {
|
|
126
|
+
await slow.close();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const gated = recordingSink();
|
|
130
|
+
const gatedRuntime = await open(gated.sink, {
|
|
131
|
+
text: "deployed",
|
|
132
|
+
toolCall: { name: "bash", arguments: { command: "echo deploy" } },
|
|
133
|
+
});
|
|
134
|
+
try {
|
|
135
|
+
const parked = await launch(
|
|
136
|
+
{ kind: "single", agent: "deployer", task: "deploy it" },
|
|
137
|
+
deps(gatedRuntime, 10_000),
|
|
138
|
+
);
|
|
139
|
+
assert.strictEqual(parked.view.status, "waiting");
|
|
140
|
+
const waits = gated.entries.filter((entry) => entry.code.startsWith("wait."));
|
|
141
|
+
assert.deepStrictEqual(
|
|
142
|
+
waits.map((entry) => [entry.code, entry.fields.runId]),
|
|
143
|
+
[["wait.gate", parked.view.runId]],
|
|
144
|
+
);
|
|
145
|
+
await control(
|
|
146
|
+
{ action: "approve", run: parked.view.runId, gate: "deploy" },
|
|
147
|
+
{ runtime: gatedRuntime, wait: { policy: "settle", waitMs: 10_000 } },
|
|
148
|
+
);
|
|
149
|
+
} finally {
|
|
150
|
+
await gatedRuntime.close();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const answered = recordingSink();
|
|
154
|
+
const done = await open(answered.sink, { text: "done" });
|
|
155
|
+
try {
|
|
156
|
+
await launch({ kind: "single", agent: "scout", task: "look" }, deps(done));
|
|
157
|
+
assert.deepStrictEqual(
|
|
158
|
+
answered.entries.filter((entry) => entry.code.startsWith("wait.")),
|
|
159
|
+
[],
|
|
160
|
+
);
|
|
161
|
+
} finally {
|
|
162
|
+
await done.close();
|
|
163
|
+
}
|
|
164
|
+
}, 20_000);
|
|
165
|
+
|
|
166
|
+
it("a cancelled launch logs aborted and ends stopped", async () => {
|
|
167
|
+
const { sink, entries } = recordingSink();
|
|
168
|
+
const runtime = await open(sink, { hang: true });
|
|
169
|
+
try {
|
|
170
|
+
const controller = new AbortController();
|
|
171
|
+
const pending = launch(
|
|
172
|
+
{ kind: "single", agent: "scout", task: "slow" },
|
|
173
|
+
{ ...deps(runtime), signal: controller.signal },
|
|
174
|
+
);
|
|
175
|
+
setTimeout(() => controller.abort(), 25);
|
|
176
|
+
const result = await pending;
|
|
177
|
+
|
|
178
|
+
assert.strictEqual(result.view.status, "stopped");
|
|
179
|
+
const waits = entries.filter((entry) => entry.code.startsWith("wait."));
|
|
180
|
+
assert.deepStrictEqual(
|
|
181
|
+
waits.map((entry) => [entry.code, entry.fields.runId]),
|
|
182
|
+
[["wait.aborted", result.view.runId]],
|
|
183
|
+
);
|
|
184
|
+
} finally {
|
|
185
|
+
await runtime.close();
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("a detached single launch returns before the child answers", async () => {
|
|
190
|
+
let release = (): void => {};
|
|
191
|
+
const held = new Promise<void>((resolve) => {
|
|
192
|
+
release = resolve;
|
|
193
|
+
});
|
|
194
|
+
const source = stubHostSource({ text: "late answer", hold: () => held, holdAt: [1] });
|
|
195
|
+
const runtime = await open(undefined, { source });
|
|
196
|
+
try {
|
|
197
|
+
const result = await launch(
|
|
198
|
+
{ kind: "single", agent: "scout", task: "look", execution: "detached" },
|
|
199
|
+
deps(runtime),
|
|
200
|
+
);
|
|
201
|
+
assert.strictEqual(result.view.answer, null);
|
|
202
|
+
assert.ok(
|
|
203
|
+
result.view.status === "queued" || result.view.status === "running",
|
|
204
|
+
result.view.status,
|
|
205
|
+
);
|
|
206
|
+
assert.match(result.text, /^Run .* is (queued|running)\.$/);
|
|
207
|
+
await waitFor(() => source.active === 1, "the child generation started while held");
|
|
208
|
+
assert.ok(
|
|
209
|
+
result.view.status === "queued" || result.view.status === "running",
|
|
210
|
+
result.view.status,
|
|
211
|
+
);
|
|
212
|
+
release();
|
|
213
|
+
await waitFor(
|
|
214
|
+
async () => (await viewRun(result.view.runId, runtime)).status === "answered",
|
|
215
|
+
"the detached run settles",
|
|
216
|
+
);
|
|
217
|
+
} finally {
|
|
218
|
+
await runtime.close();
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("a detached launch arms no deadline and writes no wait line", async () => {
|
|
223
|
+
let release = (): void => {};
|
|
224
|
+
const held = new Promise<void>((resolve) => {
|
|
225
|
+
release = resolve;
|
|
226
|
+
});
|
|
227
|
+
const source = stubHostSource({ text: "done", hold: () => held, holdAt: [1] });
|
|
228
|
+
const { sink, entries } = recordingSink();
|
|
229
|
+
const runtime = await open(sink, { source });
|
|
230
|
+
try {
|
|
231
|
+
const result = await launch(
|
|
232
|
+
{ kind: "single", agent: "scout", task: "look", execution: "detached" },
|
|
233
|
+
deps(runtime),
|
|
234
|
+
);
|
|
235
|
+
await waitFor(() => source.active === 1, "the child generation started while held");
|
|
236
|
+
release();
|
|
237
|
+
await waitFor(
|
|
238
|
+
async () => (await runtime.snapshot(RunDoc, result.view.runId))?.resolution === "answered",
|
|
239
|
+
"the detached run settles",
|
|
240
|
+
);
|
|
241
|
+
assert.deepStrictEqual(
|
|
242
|
+
entries.filter((entry) => entry.code.startsWith("wait.")).map((entry) => entry.code),
|
|
243
|
+
[],
|
|
244
|
+
);
|
|
245
|
+
} finally {
|
|
246
|
+
await runtime.close();
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("an absent execution and execution wait share one request identity", async () => {
|
|
251
|
+
let release = (): void => {};
|
|
252
|
+
const held = new Promise<void>((resolve) => {
|
|
253
|
+
release = resolve;
|
|
254
|
+
});
|
|
255
|
+
const source = stubHostSource({ text: "ok", hold: () => held, holdAt: [1] });
|
|
256
|
+
const runtime = await open(undefined, { source });
|
|
257
|
+
try {
|
|
258
|
+
const first = launch({ kind: "single", agent: "scout", task: "look" }, deps(runtime));
|
|
259
|
+
await waitFor(
|
|
260
|
+
async () => ((await runtime.snapshot(RunIndexDoc))?.runIds.length ?? 0) === 1,
|
|
261
|
+
"the first run is claimed",
|
|
262
|
+
);
|
|
263
|
+
const second = launch(
|
|
264
|
+
{ kind: "single", agent: "scout", task: "look", execution: "wait" },
|
|
265
|
+
deps(runtime),
|
|
266
|
+
);
|
|
267
|
+
release();
|
|
268
|
+
const [absent, waited] = await Promise.all([first, second]);
|
|
269
|
+
assert.strictEqual(absent.view.runId, waited.view.runId);
|
|
270
|
+
assert.deepStrictEqual((await runtime.snapshot(RunIndexDoc))?.runIds, [absent.view.runId]);
|
|
271
|
+
|
|
272
|
+
const third = await launch({ kind: "single", agent: "scout", task: "look" }, deps(runtime));
|
|
273
|
+
assert.notStrictEqual(third.view.runId, absent.view.runId);
|
|
274
|
+
assert.ok(third.view.runId.endsWith("#2"), third.view.runId);
|
|
275
|
+
} finally {
|
|
276
|
+
await runtime.close();
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it("a detached and a wait launch of one request are two runs", async () => {
|
|
281
|
+
const runtime = await open(undefined, { text: "ok" });
|
|
282
|
+
try {
|
|
283
|
+
const detached = await launch(
|
|
284
|
+
{ kind: "single", agent: "scout", task: "look", execution: "detached" },
|
|
285
|
+
deps(runtime),
|
|
286
|
+
);
|
|
287
|
+
const waited = await launch({ kind: "single", agent: "scout", task: "look" }, deps(runtime));
|
|
288
|
+
assert.notStrictEqual(detached.view.runId, waited.view.runId);
|
|
289
|
+
const index = await runtime.snapshot(RunIndexDoc);
|
|
290
|
+
assert.deepStrictEqual(
|
|
291
|
+
[...(index?.runIds ?? [])].sort(),
|
|
292
|
+
[detached.view.runId, waited.view.runId].sort(),
|
|
293
|
+
);
|
|
294
|
+
assert.strictEqual(
|
|
295
|
+
(await runtime.snapshot(RunDoc, detached.view.runId))?.execution,
|
|
296
|
+
"detached",
|
|
297
|
+
);
|
|
298
|
+
assert.strictEqual((await runtime.snapshot(RunDoc, waited.view.runId))?.execution, "wait");
|
|
299
|
+
} finally {
|
|
300
|
+
await runtime.close();
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it("a request without execution still waits for the answer", async () => {
|
|
305
|
+
const runtime = await open(undefined, { text: "hello" });
|
|
306
|
+
try {
|
|
307
|
+
const result = await launch({ kind: "single", agent: "scout", task: "look" }, deps(runtime));
|
|
308
|
+
assert.strictEqual(result.view.status, "answered");
|
|
309
|
+
assert.strictEqual(result.text, "hello");
|
|
310
|
+
} finally {
|
|
311
|
+
await runtime.close();
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("a detached launch refuses an unknown definition before claiming", async () => {
|
|
316
|
+
const runtime = await open(undefined, { text: "ok" });
|
|
317
|
+
try {
|
|
318
|
+
await rejects(
|
|
319
|
+
launch({ kind: "single", agent: "nope", task: "x", execution: "detached" }, deps(runtime)),
|
|
320
|
+
(error: unknown) => error instanceof Error && error.message.includes("nope"),
|
|
321
|
+
);
|
|
322
|
+
assert.deepStrictEqual((await runtime.snapshot(RunIndexDoc))?.runIds ?? [], []);
|
|
323
|
+
} finally {
|
|
324
|
+
await runtime.close();
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
const childAgentOf = async (runtime: TestSession, childId: number) =>
|
|
329
|
+
runtime.harness.snapshot(AgentDoc, childId as never, BACKGROUND_CONTEXT);
|
|
330
|
+
|
|
331
|
+
it("a request budget reaches the conversation and the document", async () => {
|
|
332
|
+
const runtime = await open(undefined, { text: "ok" });
|
|
333
|
+
try {
|
|
334
|
+
const result = await launch(
|
|
335
|
+
{ kind: "single", agent: "scout", task: "look", maxTurns: 60 },
|
|
336
|
+
deps(runtime),
|
|
337
|
+
);
|
|
338
|
+
const doc = await runtime.snapshot(RunDoc, result.view.runId);
|
|
339
|
+
assert.strictEqual(doc?.maxTurns, 60);
|
|
340
|
+
assert.ok(doc?.childConversationId !== null && doc?.childConversationId !== undefined);
|
|
341
|
+
const agent = await childAgentOf(runtime, doc.childConversationId);
|
|
342
|
+
assert.strictEqual(agent?.maxTurns, 60);
|
|
343
|
+
} finally {
|
|
344
|
+
await runtime.close();
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it("a definition budget applies and a request budget overrides it", async () => {
|
|
349
|
+
const runtime = await open(undefined, { text: "ok" });
|
|
350
|
+
const budgeted = createCatalogue([defineAgent({ ...scoutDefinition, maxTurns: 100 })]);
|
|
351
|
+
try {
|
|
352
|
+
const fromDefinition = await launch(
|
|
353
|
+
{ kind: "single", agent: "scout", task: "look" },
|
|
354
|
+
{ runtime, catalogue: budgeted, host, waitMs: 5_000 },
|
|
355
|
+
);
|
|
356
|
+
assert.strictEqual((await runtime.snapshot(RunDoc, fromDefinition.view.runId))?.maxTurns, 100);
|
|
357
|
+
|
|
358
|
+
const fromRequest = await launch(
|
|
359
|
+
{ kind: "single", agent: "scout", task: "look", maxTurns: 60 },
|
|
360
|
+
{ runtime, catalogue: budgeted, host, waitMs: 5_000 },
|
|
361
|
+
);
|
|
362
|
+
assert.strictEqual((await runtime.snapshot(RunDoc, fromRequest.view.runId))?.maxTurns, 60);
|
|
363
|
+
|
|
364
|
+
const fromDefault = await launch(
|
|
365
|
+
{ kind: "single", agent: "scout", task: "another" },
|
|
366
|
+
deps(runtime),
|
|
367
|
+
);
|
|
368
|
+
assert.strictEqual((await runtime.snapshot(RunDoc, fromDefault.view.runId))?.maxTurns, 120);
|
|
369
|
+
} finally {
|
|
370
|
+
await runtime.close();
|
|
371
|
+
}
|
|
372
|
+
});
|