@ftrdotdev/pi-delegates 0.1.0 → 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 +51 -0
- package/OPERATIONS.md +79 -6
- package/README.md +25 -17
- package/ROADMAP.md +21 -0
- package/TESTING.md +153 -318
- package/package.json +4 -3
- package/skills/pi-delegates/SKILL.md +29 -0
- package/skills/pi-delegates/references/launch.md +28 -0
- package/src/docs-contract.test.ts +106 -0
- package/src/domain/definitions.ts +3 -1
- package/src/domain/failure.ts +33 -0
- package/src/domain/model-source.ts +30 -0
- package/src/domain/orchestration/control.test.ts +69 -35
- package/src/domain/orchestration/control.ts +110 -89
- package/src/domain/orchestration/fanout.test.ts +125 -20
- package/src/domain/orchestration/fanout.ts +60 -22
- package/src/domain/orchestration/gates.test.ts +14 -15
- package/src/domain/orchestration/launch.test.ts +210 -11
- package/src/domain/orchestration/launch.ts +142 -32
- package/src/domain/orchestration/requests.test.ts +11 -16
- package/src/domain/orchestration/requests.ts +14 -1
- package/src/domain/orchestration/review.test.ts +89 -11
- package/src/domain/orchestration/run-wait.test.ts +4 -1
- package/src/domain/orchestration/run-wait.ts +1 -1
- package/src/domain/orchestration/workflow.test.ts +157 -16
- package/src/domain/orchestration/workflow.ts +269 -196
- package/src/domain/run-records.ts +214 -52
- package/src/domain/settlement.test.ts +186 -0
- package/src/domain/settlement.ts +137 -0
- package/src/domain/shapes.test.ts +20 -0
- package/src/domain/skills.test.ts +31 -20
- package/src/domain/skills.ts +36 -19
- package/src/domain/toolkit.test.ts +15 -1
- package/src/domain/toolkit.ts +8 -13
- package/src/domain/turn-budget.test.ts +37 -0
- package/src/domain/turn-budget.ts +23 -0
- package/src/domain/view.test.ts +78 -14
- package/src/domain/view.ts +67 -35
- package/src/extension/commands.test.ts +27 -23
- package/src/extension/commands.ts +10 -7
- package/src/extension/entry.test.ts +214 -56
- package/src/extension/entry.ts +78 -40
- package/src/extension/gate-alerts.test.ts +10 -8
- package/src/extension/inspector-command.test.ts +173 -21
- package/src/extension/inspector-command.ts +100 -53
- package/src/extension/prompt.test.ts +2 -4
- package/src/extension/retry-observer.test.ts +292 -0
- package/src/extension/retry-observer.ts +150 -0
- package/src/extension/settle-alerts.test.ts +579 -0
- package/src/extension/settle-alerts.ts +175 -0
- package/src/extension/shortcut.test.ts +6 -8
- package/src/extension/tools.test.ts +325 -24
- package/src/extension/tools.ts +61 -13
- package/src/extension/version.test.ts +21 -29
- package/src/goldens.test.ts +294 -0
- package/src/harness-policy.test.ts +13 -11
- package/src/layers.test.ts +309 -0
- package/src/layers.ts +405 -0
- package/src/package-manifest.test.ts +32 -19
- package/src/presentation/actions.test.ts +8 -8
- package/src/presentation/activity.test.ts +7 -8
- package/src/presentation/close.test.ts +14 -16
- package/src/presentation/inspector.test.ts +14 -11
- package/src/presentation/inspector.ts +27 -25
- package/src/presentation/overlay.test.ts +1 -3
- package/src/presentation/repaint.test.ts +226 -190
- package/src/presentation/snapshot.test.ts +5 -0
- package/src/presentation/status.test.ts +43 -0
- package/src/presentation/status.ts +30 -0
- package/src/presentation/strip.test.ts +13 -6
- package/src/presentation/strip.ts +7 -14
- package/src/presentation/wording.test.ts +153 -3
- package/src/presentation/wording.ts +78 -6
- package/src/runtime/bridge.ts +38 -44
- package/src/runtime/{timers.test.ts → clock.test.ts} +1 -1
- package/src/runtime/clock.ts +31 -0
- package/src/runtime/config.test.ts +26 -7
- package/src/runtime/config.ts +6 -1
- package/src/runtime/execution-env.test.ts +6 -8
- package/src/runtime/extensions.test.ts +4 -4
- package/src/runtime/extensions.ts +23 -11
- package/src/runtime/handle.ts +54 -0
- package/src/runtime/log.test.ts +19 -7
- package/src/runtime/log.ts +23 -0
- package/src/runtime/mcp.test.ts +29 -32
- package/src/runtime/mcp.ts +70 -3
- 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 +24 -31
- package/src/runtime/session.ts +99 -261
- package/src/runtime/storage.ts +29 -0
- package/src/test-hygiene.test.ts +97 -0
- package/src/runtime/timers.ts +0 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ftrdotdev/pi-delegates",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Durable agent delegation for Pi",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"durable",
|
|
@@ -59,13 +59,14 @@
|
|
|
59
59
|
"@earendil-works/pi-durable": "1.6.0",
|
|
60
60
|
"@earendil-works/pi-mcp": "1.6.0",
|
|
61
61
|
"@earendil-works/pi-schema": "1.6.0",
|
|
62
|
-
"@ftrdotdev/pi-tui": "^0.9.
|
|
62
|
+
"@ftrdotdev/pi-tui": "^0.9.1",
|
|
63
63
|
"effect": "4.1.5"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@earendil-works/pi-ai": "1.6.0",
|
|
67
67
|
"@earendil-works/pi-coding-agent": "1.6.0",
|
|
68
68
|
"@earendil-works/pi-tui": "1.6.0",
|
|
69
|
+
"@effect/platform-node": "4.1.5",
|
|
69
70
|
"@effect/tsgo": "0.73.4",
|
|
70
71
|
"@effect/vitest": "4.1.5",
|
|
71
72
|
"@ftrdotdev/pi-test-kit": "0.0.0",
|
|
@@ -78,7 +79,7 @@
|
|
|
78
79
|
},
|
|
79
80
|
"peerDependencies": {
|
|
80
81
|
"@earendil-works/pi-ai": "*",
|
|
81
|
-
"@earendil-works/pi-coding-agent": "
|
|
82
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
82
83
|
"@earendil-works/pi-tui": "*"
|
|
83
84
|
},
|
|
84
85
|
"engines": {
|
|
@@ -87,6 +87,35 @@ result is the aggregate disposition. Call `delegate_status` to read child
|
|
|
87
87
|
answers and reviewer notes. A review task must contain the diff or the files to
|
|
88
88
|
read. Reviewers do not see this conversation.
|
|
89
89
|
|
|
90
|
+
## Turn budget
|
|
91
|
+
|
|
92
|
+
One round is one tool round, not one message: a `read`, a `bash` call and an
|
|
93
|
+
`edit` each consume one. `maxTurns` bounds the rounds one child may take;
|
|
94
|
+
reaching it ends the run `failed (turn_limit)` after that round's tools ran, so
|
|
95
|
+
the edits and the tool results survive.
|
|
96
|
+
|
|
97
|
+
Size it; do not raise a global number: about one round per file edit, three to
|
|
98
|
+
six for a long reference document, five to ten for a verify-and-report cycle.
|
|
99
|
+
Pass `maxTurns` on the request for the whole call, or on one fanout child or
|
|
100
|
+
reviewer for one child. A child's value wins over the request's, which wins over
|
|
101
|
+
the definition's, which wins over `defaults.maxTurns` (120); every value is
|
|
102
|
+
clamped to `caps.maxTurns` (400), and a budget never goes below one round.
|
|
103
|
+
|
|
104
|
+
## Failures
|
|
105
|
+
|
|
106
|
+
A failed run carries `(reason): detail` in `delegate_status` and on its child
|
|
107
|
+
line. Durable retries the generation it can retry: the package logs one line per
|
|
108
|
+
retry, and `retryable: true` on a failure means durable already retried.
|
|
109
|
+
|
|
110
|
+
| Reason | What to do |
|
|
111
|
+
| ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
112
|
+
| `model_error` | Read `retryable`. True: relaunch once, and do not fan out four at a time. False: read the detail and report it. |
|
|
113
|
+
| `turn_limit` | Read the tree before relaunching; the work is there. Relaunch only the remaining scope, or split it into two children. |
|
|
114
|
+
| `no_model` | Fix the configuration (`fix_config`): the definition has no usable model. |
|
|
115
|
+
| `internal` | A package-side failure: read the detail, report it, and relaunch only if the task is still worth running. |
|
|
116
|
+
| `interrupted`, `faulted`, `orphaned`, `restart_limit`, `aborted`, `reset` | Relaunch once after reading the detail; these are transient or host-side. |
|
|
117
|
+
| `nothing_to_answer` | Narrow the task: give the child a concrete deliverable. |
|
|
118
|
+
|
|
90
119
|
## Status and control
|
|
91
120
|
|
|
92
121
|
Call `delegate_status` with `{}` to list the newest 50 runs. Pass `run` or
|
|
@@ -134,6 +134,34 @@ The aggregate alone does not say what to change. Call `delegate_status` with
|
|
|
134
134
|
The review does not capture a diff. Reviewers see only `task` and their role
|
|
135
135
|
prompt. Paste the diff into `task`, or name the files they must read.
|
|
136
136
|
|
|
137
|
+
## Detached execution
|
|
138
|
+
|
|
139
|
+
`"execution": "detached"` returns the run id and the opening status at once,
|
|
140
|
+
with no wait and no deadline; `delegate_status` and one status notice report the
|
|
141
|
+
run afterwards. `"execution": "wait"` and an absent field are the same request
|
|
142
|
+
and the same run. Single, fanout and review requests all accept the field.
|
|
143
|
+
|
|
144
|
+
A workflow script's `launch` and `launch_many` take the same field. They answer
|
|
145
|
+
the run id, the opening status and an empty answer, so a script can start a
|
|
146
|
+
child and keep working. `launch_many` answers one entry per child. A scripted
|
|
147
|
+
detached launch reports the status at claim, which is `queued`; reading the child
|
|
148
|
+
would race its own start. A detached group also waits until its children are
|
|
149
|
+
claimed (at most 5 seconds), so the answer names one entry per child.
|
|
150
|
+
|
|
151
|
+
```json
|
|
152
|
+
{
|
|
153
|
+
"request": {
|
|
154
|
+
"kind": "single",
|
|
155
|
+
"agent": "builder",
|
|
156
|
+
"task": "Run the full test suite and report the failures.",
|
|
157
|
+
"execution": "detached"
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
A gate or request alert still starts a turn, for a detached run too: it needs a
|
|
163
|
+
decision, so it cannot wait for you to type.
|
|
164
|
+
|
|
137
165
|
## Waiting and deadlines
|
|
138
166
|
|
|
139
167
|
A launch returns as soon as one of these happens:
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { assert, it } from "@effect/vitest";
|
|
2
|
+
import { join, readText } from "../test-support/platform.ts";
|
|
3
|
+
import { DEFAULTS } from "./runtime/config.ts";
|
|
4
|
+
|
|
5
|
+
const root = join(import.meta.dirname, "..");
|
|
6
|
+
const read = (relative: string): Promise<string> => readText(join(root, relative));
|
|
7
|
+
|
|
8
|
+
/** The document an agent reads before it launches work. */
|
|
9
|
+
it("the skill teaches the budget and the remedies", async () => {
|
|
10
|
+
const skill = await read("skills/pi-delegates/SKILL.md");
|
|
11
|
+
assert.ok(skill.includes("## Turn budget"), "the skill has a Turn budget section");
|
|
12
|
+
assert.ok(skill.includes("## Failures"), "the skill has a Failures section");
|
|
13
|
+
const budget = skill.slice(skill.indexOf("## Turn budget"), skill.indexOf("## Failures"));
|
|
14
|
+
for (const part of ["maxTurns", "caps.maxTurns", "turn_limit", "defaults.maxTurns"]) {
|
|
15
|
+
assert.ok(budget.includes(part), `the budget section names ${part}`);
|
|
16
|
+
}
|
|
17
|
+
assert.match(budget, /never\s+goes\s+below\s+one\s+round/, "the budget section states the floor");
|
|
18
|
+
// The four levels in order: child, request, definition, then the default. Compared
|
|
19
|
+
// by position, not as one sentence, so the paragraph may wrap anywhere.
|
|
20
|
+
const order = [
|
|
21
|
+
"A child's value wins",
|
|
22
|
+
"the request's",
|
|
23
|
+
"the definition's",
|
|
24
|
+
"`defaults.maxTurns`",
|
|
25
|
+
].map((part) => budget.indexOf(part));
|
|
26
|
+
assert.ok(
|
|
27
|
+
order.every((at) => at >= 0),
|
|
28
|
+
"the budget section states every level of the precedence",
|
|
29
|
+
);
|
|
30
|
+
assert.deepStrictEqual(
|
|
31
|
+
[...order].sort((left, right) => left - right),
|
|
32
|
+
order,
|
|
33
|
+
"the budget section states the precedence in order",
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const failures = skill.slice(skill.indexOf("## Failures"));
|
|
37
|
+
for (const part of [
|
|
38
|
+
"model_error",
|
|
39
|
+
"turn_limit",
|
|
40
|
+
"no_model",
|
|
41
|
+
"internal",
|
|
42
|
+
"nothing_to_answer",
|
|
43
|
+
"relaunch",
|
|
44
|
+
"narrow",
|
|
45
|
+
"fix_config",
|
|
46
|
+
]) {
|
|
47
|
+
assert.ok(failures.includes(part), `the failures section names ${part}`);
|
|
48
|
+
}
|
|
49
|
+
// The rendering is `(reason): detail`, the form `delegate_status` prints.
|
|
50
|
+
assert.ok(failures.includes("`(reason): detail`"), "the failures section states the format");
|
|
51
|
+
assert.ok(
|
|
52
|
+
failures.includes("retryable") && failures.toLowerCase().includes("already"),
|
|
53
|
+
"the failures section states that retryable means durable already retried",
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("the reference documents execution and the empty answer", async () => {
|
|
58
|
+
const reference = await read("skills/pi-delegates/references/launch.md");
|
|
59
|
+
assert.ok(reference.includes('"execution": "detached"'), "the reference names the value");
|
|
60
|
+
assert.ok(reference.includes("empty"), "the reference states the empty scripted answer");
|
|
61
|
+
assert.ok(
|
|
62
|
+
reference.includes("A gate or request alert still starts a turn"),
|
|
63
|
+
"the reference states that a gate or request alert still starts a turn",
|
|
64
|
+
);
|
|
65
|
+
assert.ok(
|
|
66
|
+
reference.includes("at most 5 seconds"),
|
|
67
|
+
"the reference states the detached group's admission bound",
|
|
68
|
+
);
|
|
69
|
+
assert.ok(
|
|
70
|
+
reference.includes("the status at claim, which is `queued`"),
|
|
71
|
+
"the reference states the scripted detached status",
|
|
72
|
+
);
|
|
73
|
+
assert.ok(
|
|
74
|
+
reference.includes("absent") && reference.includes("wait"),
|
|
75
|
+
"the reference states that an absent field means waiting",
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("OPERATIONS lists the codes, their cardinality and three narrow warnings", async () => {
|
|
80
|
+
const operations = await read("OPERATIONS.md");
|
|
81
|
+
for (const code of ["run.retry", "run.failed", "run.settled"]) {
|
|
82
|
+
assert.ok(operations.includes(code), `OPERATIONS lists ${code}`);
|
|
83
|
+
}
|
|
84
|
+
assert.ok(
|
|
85
|
+
operations.includes("one `run.retry` warning per scheduled retry attempt") ||
|
|
86
|
+
operations.includes("one warning per scheduled retry attempt"),
|
|
87
|
+
"OPERATIONS states one retry line per attempt",
|
|
88
|
+
);
|
|
89
|
+
assert.ok(
|
|
90
|
+
operations.includes("exactly one") && operations.includes("run.failed"),
|
|
91
|
+
"OPERATIONS states one failure line per failed run",
|
|
92
|
+
);
|
|
93
|
+
for (const code of ["settle.notify_failed", "retry.observer_failed", "settle.scan_truncated"]) {
|
|
94
|
+
assert.ok(operations.includes(code), `OPERATIONS lists ${code}`);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("the README sample matches the defaults", async () => {
|
|
99
|
+
const readme = await read("README.md");
|
|
100
|
+
assert.ok(readme.includes(`"maxTurns": ${DEFAULTS.maxTurns}`), "the sample shows the default");
|
|
101
|
+
assert.ok(
|
|
102
|
+
readme.includes(`"maxTurns": ${DEFAULTS.maxTurnsCeiling}`),
|
|
103
|
+
"the sample shows the ceiling under caps",
|
|
104
|
+
);
|
|
105
|
+
assert.match(readme, /no\s+budget\s+goes\s+below\s+one\s+round/, "the README states the floor");
|
|
106
|
+
});
|
|
@@ -53,6 +53,8 @@ export const AgentDefinition = Schema.Struct({
|
|
|
53
53
|
skills: Schema.Array(Schema.String).pipe(Schema.optional),
|
|
54
54
|
/** Set to `runs` to let a workflow launch run a script in this definition's conversation. */
|
|
55
55
|
codemode: Schema.optional(Schema.Literal("runs")),
|
|
56
|
+
/** The turn budget for every run of this agent; a request or child value wins. */
|
|
57
|
+
maxTurns: Schema.optional(Schema.Finite),
|
|
56
58
|
});
|
|
57
59
|
export type AgentDefinition = typeof AgentDefinition.Type;
|
|
58
60
|
|
|
@@ -71,7 +73,7 @@ export class DefinitionFieldNotAllowed extends Schema.TaggedError<
|
|
|
71
73
|
{ readonly brand: unique symbol }
|
|
72
74
|
>()("DefinitionFieldNotAllowed", { field: Schema.String, message: Schema.String }) {}
|
|
73
75
|
|
|
74
|
-
const OWNER_ONLY_FIELDS = ["extensions", "approval", "skills", "codemode"] as const;
|
|
76
|
+
const OWNER_ONLY_FIELDS = ["extensions", "approval", "skills", "codemode", "maxTurns"] as const;
|
|
75
77
|
|
|
76
78
|
/** Pre-decode guard: only a registered definition owns these fields. */
|
|
77
79
|
export const assertInlineDefinition = (input: unknown): void => {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
/** The ten durable reasons plus `internal` for package-native failures. */
|
|
4
|
+
export const FailureReason = Schema.Literals([
|
|
5
|
+
"model_error",
|
|
6
|
+
"no_model",
|
|
7
|
+
"aborted",
|
|
8
|
+
"reset",
|
|
9
|
+
"faulted",
|
|
10
|
+
"orphaned",
|
|
11
|
+
"interrupted",
|
|
12
|
+
"restart_limit",
|
|
13
|
+
"nothing_to_answer",
|
|
14
|
+
"turn_limit",
|
|
15
|
+
"internal",
|
|
16
|
+
]);
|
|
17
|
+
export type FailureReason = typeof FailureReason.Type;
|
|
18
|
+
export const FAILURE_REASONS = FailureReason.literals;
|
|
19
|
+
|
|
20
|
+
/** The settle outcome, one per task. A stopped or denied run records it and no failure fact. */
|
|
21
|
+
export const Resolution = Schema.Literals(["answered", "failed", "denied", "stopped"]);
|
|
22
|
+
export type Resolution = typeof Resolution.Type;
|
|
23
|
+
|
|
24
|
+
/** How a launch was asked to run: wait for the answer, or return at claim. */
|
|
25
|
+
export const Execution = Schema.Literals(["wait", "detached"]);
|
|
26
|
+
export type Execution = typeof Execution.Type;
|
|
27
|
+
|
|
28
|
+
/** Evidence only: `retryable` and `remedy` are derived at read and log time. */
|
|
29
|
+
export const FailureFact = Schema.Struct({
|
|
30
|
+
reason: FailureReason,
|
|
31
|
+
detail: Schema.NullOr(Schema.String),
|
|
32
|
+
});
|
|
33
|
+
export type FailureFact = typeof FailureFact.Type;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Models } from "@earendil-works/pi-ai/models";
|
|
2
|
+
import { Context, Layer } from "effect";
|
|
3
|
+
import type { HostDefaults } from "./orchestration/launch.ts";
|
|
4
|
+
|
|
5
|
+
/** The models a session runs on, and the host model a scripted child fills in at each launch. */
|
|
6
|
+
export interface ModelSource {
|
|
7
|
+
readonly models: Models;
|
|
8
|
+
/** Read at each launch, so a host change reaches the next child. */
|
|
9
|
+
readonly host: () => HostDefaults;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** The session's one model source; both reads come from here. */
|
|
13
|
+
export class ModelSourceService extends Context.Service<ModelSourceService, ModelSource>()(
|
|
14
|
+
"@ftrdotdev/pi-delegates/domain/model-source/ModelSourceService",
|
|
15
|
+
) {
|
|
16
|
+
/** `host` is a thunk: `models` freezes at open, the host stays live. */
|
|
17
|
+
static layer(
|
|
18
|
+
models: Models,
|
|
19
|
+
host: (() => HostDefaults) | undefined,
|
|
20
|
+
): Layer.Layer<ModelSourceService> {
|
|
21
|
+
return Layer.sync(ModelSourceService, () => ({
|
|
22
|
+
models,
|
|
23
|
+
host:
|
|
24
|
+
host ??
|
|
25
|
+
(() => {
|
|
26
|
+
throw new Error("No host model for this session.");
|
|
27
|
+
}),
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
2
2
|
import { AgentDoc } from "@earendil-works/pi-durable";
|
|
3
|
-
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { join } from "node:path";
|
|
6
3
|
import { assert, it } from "@effect/vitest";
|
|
7
|
-
import { rejects, throws } from "../../../test-support/assertions.ts";
|
|
8
4
|
import { Effect } from "effect";
|
|
5
|
+
import {
|
|
6
|
+
join,
|
|
7
|
+
makeDir,
|
|
8
|
+
makeTempDir,
|
|
9
|
+
removePath,
|
|
10
|
+
writeText,
|
|
11
|
+
} from "../../../test-support/platform.ts";
|
|
12
|
+
import { rejects, throws } from "../../../test-support/assertions.ts";
|
|
9
13
|
import { stubHostSource, type StubHostOptions } from "../../../test-support/stub-model-source.ts";
|
|
10
14
|
import { createCatalogue, defineAgent } from "../definitions.ts";
|
|
11
15
|
import { launch, type HostDefaults } from "./launch.ts";
|
|
@@ -38,11 +42,8 @@ import { renderStatusText } from "../../extension/tools.ts";
|
|
|
38
42
|
import type { LogFields, LogLevel, LogSink } from "../../runtime/log.ts";
|
|
39
43
|
import { countingRuntime } from "../../../test-support/counting-runtime.ts";
|
|
40
44
|
import { HostModelAdapter } from "../../runtime/models.ts";
|
|
41
|
-
import {
|
|
42
|
-
|
|
43
|
-
type SessionIdentity,
|
|
44
|
-
type SessionRuntime,
|
|
45
|
-
} from "../../runtime/session.ts";
|
|
45
|
+
import { type SessionIdentity, type SessionRuntime } from "../../runtime/session.ts";
|
|
46
|
+
import { openTestSession, type TestSession } from "../../../test-support/seams.ts";
|
|
46
47
|
|
|
47
48
|
const host: HostDefaults = {
|
|
48
49
|
model: { provider: "stub", modelId: "stub-1" },
|
|
@@ -50,7 +51,7 @@ const host: HostDefaults = {
|
|
|
50
51
|
};
|
|
51
52
|
|
|
52
53
|
const identityFor = async (sessionId: string): Promise<SessionIdentity> => {
|
|
53
|
-
const sessionDir = await
|
|
54
|
+
const sessionDir = await makeTempDir("delegates-control-");
|
|
54
55
|
return { sessionId, sessionDir, cwd: sessionDir, agentDir: sessionDir };
|
|
55
56
|
};
|
|
56
57
|
|
|
@@ -82,7 +83,7 @@ const deps = (runtime: SessionRuntime) => ({ runtime, catalogue: createCatalogue
|
|
|
82
83
|
|
|
83
84
|
it("steering a running child delivers the message", async () => {
|
|
84
85
|
const hold = deferred();
|
|
85
|
-
const runtime = await
|
|
86
|
+
const runtime = await openTestSession({
|
|
86
87
|
identity: await identityFor("s-1"),
|
|
87
88
|
models: new HostModelAdapter(stubHostSource({ hold: () => hold.promise })),
|
|
88
89
|
});
|
|
@@ -125,7 +126,7 @@ it("steering a running child delivers the message", async () => {
|
|
|
125
126
|
}, 20_000);
|
|
126
127
|
|
|
127
128
|
it("a steer without a message is refused and the session still reads", async () => {
|
|
128
|
-
const runtime = await
|
|
129
|
+
const runtime = await openTestSession({
|
|
129
130
|
identity: await identityFor("s-1"),
|
|
130
131
|
models: new HostModelAdapter(stubHostSource({ text: "done" })),
|
|
131
132
|
});
|
|
@@ -153,7 +154,7 @@ it("a steer without a message is refused and the session still reads", async ()
|
|
|
153
154
|
});
|
|
154
155
|
|
|
155
156
|
it("stopping ends the run as stopped and keeps its record", async () => {
|
|
156
|
-
const runtime = await
|
|
157
|
+
const runtime = await openTestSession({
|
|
157
158
|
identity: await identityFor("s-1"),
|
|
158
159
|
models: new HostModelAdapter(stubHostSource({ hang: true })),
|
|
159
160
|
});
|
|
@@ -188,7 +189,7 @@ it("stopping ends the run as stopped and keeps its record", async () => {
|
|
|
188
189
|
|
|
189
190
|
it("a stopped run is not restarted by reopen", async () => {
|
|
190
191
|
const identity = await identityFor("s-1");
|
|
191
|
-
const first = await
|
|
192
|
+
const first = await openTestSession({
|
|
192
193
|
identity,
|
|
193
194
|
models: new HostModelAdapter(stubHostSource({ hang: true })),
|
|
194
195
|
});
|
|
@@ -202,7 +203,7 @@ it("a stopped run is not restarted by reopen", async () => {
|
|
|
202
203
|
);
|
|
203
204
|
await first.close();
|
|
204
205
|
|
|
205
|
-
const second = await
|
|
206
|
+
const second = await openTestSession({
|
|
206
207
|
identity,
|
|
207
208
|
models: new HostModelAdapter(stubHostSource()),
|
|
208
209
|
});
|
|
@@ -219,7 +220,7 @@ it("a stopped run is not restarted by reopen", async () => {
|
|
|
219
220
|
|
|
220
221
|
it("resume restarts a stopped fanout and signals every child", async () => {
|
|
221
222
|
const hold = deferred();
|
|
222
|
-
const runtime = await
|
|
223
|
+
const runtime = await openTestSession({
|
|
223
224
|
identity: await identityFor("s-1"),
|
|
224
225
|
models: new HostModelAdapter(stubHostSource({ hold: () => hold.promise })),
|
|
225
226
|
});
|
|
@@ -264,7 +265,7 @@ it("resume keeps answered fanout children and restarts the rest", async () => {
|
|
|
264
265
|
hold: () => hold.promise,
|
|
265
266
|
holdAt: [3],
|
|
266
267
|
});
|
|
267
|
-
const runtime = await
|
|
268
|
+
const runtime = await openTestSession({
|
|
268
269
|
identity: await identityFor("s-1"),
|
|
269
270
|
models: new HostModelAdapter(source),
|
|
270
271
|
});
|
|
@@ -314,7 +315,7 @@ it("resume keeps answered fanout children and restarts the rest", async () => {
|
|
|
314
315
|
|
|
315
316
|
it("resume restarts a stopped review and rebuilds its dispositions", async () => {
|
|
316
317
|
const hold = deferred();
|
|
317
|
-
const runtime = await
|
|
318
|
+
const runtime = await openTestSession({
|
|
318
319
|
identity: await identityFor("s-1"),
|
|
319
320
|
models: new HostModelAdapter(
|
|
320
321
|
stubHostSource({ text: '{"disposition":"accepted"}', hold: () => hold.promise }),
|
|
@@ -368,7 +369,7 @@ it("a stored resume input that no longer matches its shape is refused", () => {
|
|
|
368
369
|
|
|
369
370
|
it("an interrupted run resumes by itself after reopen", async () => {
|
|
370
371
|
const identity = await identityFor("s-1");
|
|
371
|
-
const first = await
|
|
372
|
+
const first = await openTestSession({
|
|
372
373
|
identity,
|
|
373
374
|
models: new HostModelAdapter(stubHostSource({ hang: true })),
|
|
374
375
|
});
|
|
@@ -379,7 +380,7 @@ it("an interrupted run resumes by itself after reopen", async () => {
|
|
|
379
380
|
const firstDoc = await first.snapshot(RunDoc, result.view.runId);
|
|
380
381
|
await first.close();
|
|
381
382
|
|
|
382
|
-
const second = await
|
|
383
|
+
const second = await openTestSession({
|
|
383
384
|
identity,
|
|
384
385
|
models: new HostModelAdapter(stubHostSource({ text: "continued" })),
|
|
385
386
|
});
|
|
@@ -396,7 +397,7 @@ it("an interrupted run resumes by itself after reopen", async () => {
|
|
|
396
397
|
|
|
397
398
|
it("resume continues a run stopped in this session", async () => {
|
|
398
399
|
const hold = deferred();
|
|
399
|
-
const runtime = await
|
|
400
|
+
const runtime = await openTestSession({
|
|
400
401
|
identity: await identityFor("s-1"),
|
|
401
402
|
models: new HostModelAdapter(stubHostSource({ hold: () => hold.promise })),
|
|
402
403
|
});
|
|
@@ -430,7 +431,7 @@ it("resume continues a run stopped in this session", async () => {
|
|
|
430
431
|
it("resume refuses a live run without waiting", async () => {
|
|
431
432
|
const hold = deferred();
|
|
432
433
|
const entries: { code: string }[] = [];
|
|
433
|
-
const runtime = await
|
|
434
|
+
const runtime = await openTestSession({
|
|
434
435
|
identity: await identityFor("s-1"),
|
|
435
436
|
models: new HostModelAdapter(stubHostSource({ hold: () => hold.promise })),
|
|
436
437
|
log: { write: (_level, code) => entries.push({ code }) },
|
|
@@ -462,7 +463,7 @@ it("resume refuses a live run without waiting", async () => {
|
|
|
462
463
|
}, 20_000);
|
|
463
464
|
|
|
464
465
|
it("resume refuses a finished run naming its status", async () => {
|
|
465
|
-
const runtime = await
|
|
466
|
+
const runtime = await openTestSession({
|
|
466
467
|
identity: await identityFor("s-1"),
|
|
467
468
|
models: new HostModelAdapter(stubHostSource()),
|
|
468
469
|
});
|
|
@@ -485,7 +486,7 @@ it("resume refuses a finished run naming its status", async () => {
|
|
|
485
486
|
|
|
486
487
|
it("steering one fanout child uses its child run id", async () => {
|
|
487
488
|
const hold = deferred();
|
|
488
|
-
const runtime = await
|
|
489
|
+
const runtime = await openTestSession({
|
|
489
490
|
identity: await identityFor("s-1"),
|
|
490
491
|
models: new HostModelAdapter(stubHostSource({ hold: () => hold.promise })),
|
|
491
492
|
});
|
|
@@ -534,7 +535,7 @@ it("steering one fanout child uses its child run id", async () => {
|
|
|
534
535
|
}, 20_000);
|
|
535
536
|
|
|
536
537
|
it("steering a run with a missing toolkit name names the alternatives", async () => {
|
|
537
|
-
const runtime = await
|
|
538
|
+
const runtime = await openTestSession({
|
|
538
539
|
identity: await identityFor("s-1"),
|
|
539
540
|
models: new HostModelAdapter(stubHostSource()),
|
|
540
541
|
});
|
|
@@ -570,7 +571,7 @@ it("a refused resume records the names that no longer resolve", async () => {
|
|
|
570
571
|
entries.push({ level, code, fields });
|
|
571
572
|
},
|
|
572
573
|
};
|
|
573
|
-
const runtime = await
|
|
574
|
+
const runtime = await openTestSession({
|
|
574
575
|
identity: await identityFor("s-1"),
|
|
575
576
|
models: new HostModelAdapter(stubHostSource({ hang: true })),
|
|
576
577
|
log: sink,
|
|
@@ -616,7 +617,7 @@ it("a refused resume records the names that no longer resolve", async () => {
|
|
|
616
617
|
|
|
617
618
|
it("control missing check reads no child runs", async () => {
|
|
618
619
|
const hold = deferred();
|
|
619
|
-
const runtime = await
|
|
620
|
+
const runtime = await openTestSession({
|
|
620
621
|
identity: await identityFor("s-1"),
|
|
621
622
|
models: new HostModelAdapter(stubHostSource({ hold: () => hold.promise })),
|
|
622
623
|
});
|
|
@@ -670,7 +671,7 @@ it("control missing check reads no child runs", async () => {
|
|
|
670
671
|
it("a control wait timeout is logged and a settled wait is not", async () => {
|
|
671
672
|
const hold = deferred();
|
|
672
673
|
const entries: { code: string; fields: LogFields }[] = [];
|
|
673
|
-
const runtime = await
|
|
674
|
+
const runtime = await openTestSession({
|
|
674
675
|
identity: await identityFor("s-1"),
|
|
675
676
|
models: new HostModelAdapter(stubHostSource({ hold: () => hold.promise })),
|
|
676
677
|
log: { write: (_level, code, fields = {}) => entries.push({ code, fields }) },
|
|
@@ -710,14 +711,14 @@ it("a control wait timeout is logged and a settled wait is not", async () => {
|
|
|
710
711
|
}, 20_000);
|
|
711
712
|
|
|
712
713
|
it("a steer refuses a run whose declared skill was deleted", async () => {
|
|
713
|
-
const root = await
|
|
714
|
-
await
|
|
715
|
-
await
|
|
714
|
+
const root = await makeTempDir("delegates-control-skills-");
|
|
715
|
+
await makeDir(join(root, "alpha"));
|
|
716
|
+
await writeText(
|
|
716
717
|
join(root, "alpha", "SKILL.md"),
|
|
717
718
|
"---\nname: alpha\ndescription: The alpha skill\n---\n\nALPHA_BODY\n",
|
|
718
719
|
);
|
|
719
720
|
const identity = await identityFor("s-1");
|
|
720
|
-
const runtime = await
|
|
721
|
+
const runtime = await openTestSession({
|
|
721
722
|
identity,
|
|
722
723
|
models: new HostModelAdapter(stubHostSource({ text: "done" })),
|
|
723
724
|
skills: { cwd: identity.cwd, agentDir: identity.agentDir, skillPaths: [root] },
|
|
@@ -736,7 +737,7 @@ it("a steer refuses a run whose declared skill was deleted", async () => {
|
|
|
736
737
|
{ kind: "single", agent: "tester", task: "look" },
|
|
737
738
|
{ ...deps(runtime), catalogue: createCatalogue([definition]), waitMs: 10_000 },
|
|
738
739
|
);
|
|
739
|
-
await
|
|
740
|
+
await removePath(join(root, "alpha", "SKILL.md"));
|
|
740
741
|
await Effect.runPromise(runtime.skills.reload);
|
|
741
742
|
|
|
742
743
|
await rejects(
|
|
@@ -766,8 +767,8 @@ const openAsker = async (
|
|
|
766
767
|
source: StubHostOptions,
|
|
767
768
|
now?: () => number,
|
|
768
769
|
log?: LogSink,
|
|
769
|
-
): Promise<
|
|
770
|
-
|
|
770
|
+
): Promise<TestSession> =>
|
|
771
|
+
openTestSession({
|
|
771
772
|
identity: await identityFor("s-1"),
|
|
772
773
|
models: new HostModelAdapter(stubHostSource(source)),
|
|
773
774
|
...(now === undefined ? {} : { now }),
|
|
@@ -1296,3 +1297,36 @@ it("status names the waiting request", async () => {
|
|
|
1296
1297
|
await runtime.close();
|
|
1297
1298
|
}
|
|
1298
1299
|
}, 30_000);
|
|
1300
|
+
|
|
1301
|
+
it("control names the action's own missing field before run when both are absent", async () => {
|
|
1302
|
+
const runtime = await openTestSession({
|
|
1303
|
+
identity: await identityFor("s-1"),
|
|
1304
|
+
models: new HostModelAdapter(stubHostSource({ text: "done" })),
|
|
1305
|
+
});
|
|
1306
|
+
try {
|
|
1307
|
+
await rejects(
|
|
1308
|
+
control({ action: "answer" }, { runtime, wait: { policy: "commit" } }),
|
|
1309
|
+
(error: unknown) =>
|
|
1310
|
+
error instanceof InvalidControlRequest &&
|
|
1311
|
+
error.message === 'Control action "answer" is invalid: request is required.',
|
|
1312
|
+
);
|
|
1313
|
+
} finally {
|
|
1314
|
+
await runtime.close();
|
|
1315
|
+
}
|
|
1316
|
+
});
|
|
1317
|
+
|
|
1318
|
+
it("control names run last when the action is complete but the run is absent", async () => {
|
|
1319
|
+
const runtime = await openTestSession({
|
|
1320
|
+
identity: await identityFor("s-1"),
|
|
1321
|
+
models: new HostModelAdapter(stubHostSource({ text: "done" })),
|
|
1322
|
+
});
|
|
1323
|
+
try {
|
|
1324
|
+
await rejects(
|
|
1325
|
+
control({ action: "approve", gate: "deploy" }, { runtime, wait: { policy: "commit" } }),
|
|
1326
|
+
(error: unknown) =>
|
|
1327
|
+
error instanceof InvalidControlRequest && error.message.endsWith("run is required."),
|
|
1328
|
+
);
|
|
1329
|
+
} finally {
|
|
1330
|
+
await runtime.close();
|
|
1331
|
+
}
|
|
1332
|
+
});
|