@aragon-agent/cli 0.6.16 → 0.6.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -47
- package/dist/agent/controller.js +39 -47
- package/dist/agent/reducer.js +0 -4
- package/dist/cli.js +0 -13
- package/dist/commands/builtins.js +3 -17
- package/dist/compaction/child.d.ts +10 -8
- package/dist/compaction/child.js +23 -25
- package/dist/compaction/limits.d.ts +0 -2
- package/dist/compaction/limits.js +0 -2
- package/dist/config/cli-commands.d.ts +1 -1
- package/dist/config/cli-commands.js +16 -15
- package/dist/config/load.d.ts +0 -17
- package/dist/config/load.js +0 -6
- package/dist/config/schema.d.ts +17 -5
- package/dist/config/schema.js +14 -11
- package/dist/exec/events.d.ts +12 -8
- package/dist/exec/events.js +2 -2
- package/dist/exec/runner.js +4 -1
- package/dist/fast/limits.d.ts +2 -2
- package/dist/fast/limits.js +2 -2
- package/dist/fast/prompt.d.ts +10 -11
- package/dist/fast/prompt.js +19 -20
- package/dist/fast/reviewer.d.ts +1 -1
- package/dist/fast/reviewer.js +1 -1
- package/dist/fast/types.d.ts +0 -2
- package/dist/fast/wiring.d.ts +18 -34
- package/dist/fast/wiring.js +20 -51
- package/dist/session/validate-session.js +3 -1
- package/dist/team/child-reviewer.d.ts +105 -0
- package/dist/team/child-reviewer.js +117 -0
- package/dist/team/normalize.d.ts +7 -26
- package/dist/team/normalize.js +9 -22
- package/dist/team/prompt.d.ts +0 -11
- package/dist/team/prompt.js +3 -12
- package/dist/team/report.d.ts +4 -19
- package/dist/team/report.js +1 -27
- package/dist/team/runtime.d.ts +5 -10
- package/dist/team/runtime.js +35 -39
- package/dist/team/subagent.d.ts +18 -18
- package/dist/team/subagent.js +80 -30
- package/dist/team/task-tool.d.ts +6 -26
- package/dist/team/task-tool.js +13 -47
- package/dist/team/types.d.ts +3 -42
- package/dist/ui/App.js +3 -4
- package/dist/ui/BottomStatusRow.js +2 -1
- package/dist/ui/StatusBar.js +2 -1
- package/dist/ui/TeamPanel.js +1 -1
- package/dist/ui/entries/TeamCard.js +1 -6
- package/dist/ui/layout/status-detail-layout.js +12 -2
- package/dist/ui/layout/status-layout.d.ts +4 -2
- package/dist/ui/layout/status-layout.js +24 -1
- package/dist/ui/overlays/HelpOverlay.js +1 -2
- package/package.json +2 -2
- package/dist/ui/ModeChip.d.ts +0 -18
- package/dist/ui/ModeChip.js +0 -24
package/dist/team/runtime.js
CHANGED
|
@@ -65,10 +65,7 @@ export class TeamRuntime {
|
|
|
65
65
|
// -------------------------------------------------------------------------
|
|
66
66
|
// Dispatch
|
|
67
67
|
// -------------------------------------------------------------------------
|
|
68
|
-
async dispatch(specs, requested, signal
|
|
69
|
-
/** Carried through from the normalizer so the report can state it (§3.4 /
|
|
70
|
-
* R-6). Optional, so every existing caller compiles unchanged. */
|
|
71
|
-
extra = {}) {
|
|
68
|
+
async dispatch(specs, requested, signal) {
|
|
72
69
|
this.counter += 1;
|
|
73
70
|
const dispatchId = `d${this.counter}`;
|
|
74
71
|
const config = this.deps.getConfig();
|
|
@@ -131,7 +128,7 @@ export class TeamRuntime {
|
|
|
131
128
|
confirmTools: config.confirmTools,
|
|
132
129
|
...(this.deps.humanQueue ? { humanQueue: this.deps.humanQueue } : {}),
|
|
133
130
|
agentFactory: this.deps.agentFactory ?? defaultSubagentFactory,
|
|
134
|
-
...(this.deps.
|
|
131
|
+
...(this.deps.review ? { review: this.deps.review } : {}),
|
|
135
132
|
// Site two of two, and the omission is silent in the same way the policy
|
|
136
133
|
// one above is: declaring it on `TeamRuntimeDeps` and forgetting this line
|
|
137
134
|
// type-checks and forwards nothing, so every child would quietly run with
|
|
@@ -147,11 +144,7 @@ export class TeamRuntime {
|
|
|
147
144
|
// show the child its brief twice.
|
|
148
145
|
const makeHandle = (spec) => createSubagent(spec, subDeps, {
|
|
149
146
|
onUpdate: (run) => this.publish(dispatchId, run),
|
|
150
|
-
|
|
151
|
-
// event rather than always using the lead's (§3.6 / R-7). Taken from the
|
|
152
|
-
// SPEC, which the normalizer already downgraded when the tier was
|
|
153
|
-
// unavailable, so it names the model that actually billed.
|
|
154
|
-
onUsage: (label, usage) => this.emit({ type: 'usage', dispatchId, label, usage, tier: spec.tier }),
|
|
147
|
+
onUsage: (label, usage) => this.emit({ type: 'usage', dispatchId, label, usage }),
|
|
155
148
|
});
|
|
156
149
|
// ASSIGNMENT, not a declaration: a `const` here would shadow the `let` above
|
|
157
150
|
// the bus, `canSend` would see the empty array forever, and every peer would
|
|
@@ -179,7 +172,15 @@ export class TeamRuntime {
|
|
|
179
172
|
// so the override only bites because `task` listens to `ctx.signal` — and a
|
|
180
173
|
// second, independent timer means a signal that never arrives still ends the
|
|
181
174
|
// dispatch.
|
|
182
|
-
|
|
175
|
+
//
|
|
176
|
+
// `0` MEANS NO CEILING (main-agent parity): the dispatch lasts as long as
|
|
177
|
+
// its slowest child and only an Esc ends it early. The lead's idle
|
|
178
|
+
// watchdog is paused for the whole dispatch either way, exactly as it is
|
|
179
|
+
// for the lead's own long turns.
|
|
180
|
+
this.dispatchTimer =
|
|
181
|
+
team.dispatchTimeoutMs > 0
|
|
182
|
+
? setTimeout(() => this.abortAll(), team.dispatchTimeoutMs)
|
|
183
|
+
: null;
|
|
183
184
|
const runCtx = {
|
|
184
185
|
dispatchId,
|
|
185
186
|
handles,
|
|
@@ -195,24 +196,13 @@ export class TeamRuntime {
|
|
|
195
196
|
signal?.removeEventListener('abort', onAbort);
|
|
196
197
|
for (const handle of handles)
|
|
197
198
|
handle.unsubscribe();
|
|
198
|
-
//
|
|
199
|
-
//
|
|
200
|
-
//
|
|
201
|
-
|
|
202
|
-
// `main` IS THE COMPLEMENT OF `fast`, not an equality test. `SubagentRun.tier`
|
|
203
|
-
// is populated by `createSubagent` from the spec, but a hand-built run in a
|
|
204
|
-
// test — or a run restored from a session file written before this field
|
|
205
|
-
// existed — has it `undefined`, and `=== 'main'` would silently drop that
|
|
206
|
-
// child's spend from the total. Under-reporting is the one failure this
|
|
207
|
-
// split exists to prevent, so the default direction has to be "counted".
|
|
208
|
-
const sumTier = (tier) => handles
|
|
209
|
-
.filter((h) => (tier === 'fast' ? h.run.tier === 'fast' : h.run.tier !== 'fast'))
|
|
210
|
-
.reduce((acc, h) => ({
|
|
199
|
+
// ONE TOTAL, AT THE LEAD'S TABLE. Every child runs the lead's own model
|
|
200
|
+
// (main-agent parity), so there is exactly one tier to sum and one price to
|
|
201
|
+
// sum it at; a split would be two answers to one question.
|
|
202
|
+
const usage = handles.reduce((acc, h) => ({
|
|
211
203
|
inputTokens: acc.inputTokens + h.run.usage.inputTokens,
|
|
212
204
|
outputTokens: acc.outputTokens + h.run.usage.outputTokens,
|
|
213
205
|
}), { inputTokens: 0, outputTokens: 0 });
|
|
214
|
-
const fastUsage = sumTier('fast');
|
|
215
|
-
const ranFast = handles.some((h) => h.run.tier === 'fast');
|
|
216
206
|
const outcome = {
|
|
217
207
|
dispatchId,
|
|
218
208
|
runs: handles.map((h) => ({ ...h.run, filesTouched: [...h.run.filesTouched] })),
|
|
@@ -221,11 +211,7 @@ export class TeamRuntime {
|
|
|
221
211
|
endedAt: Date.now(),
|
|
222
212
|
aborted: this.aborted,
|
|
223
213
|
leadMail: bus.leadMail(),
|
|
224
|
-
usage
|
|
225
|
-
// ABSENT when no fast child ran, which is what keeps a default session's
|
|
226
|
-
// outcome shape byte-identical to the pre-feature one.
|
|
227
|
-
...(ranFast ? { fastUsage } : {}),
|
|
228
|
-
...(extra.downgraded ? { downgraded: extra.downgraded } : {}),
|
|
214
|
+
usage,
|
|
229
215
|
};
|
|
230
216
|
this.live = [];
|
|
231
217
|
this.bus = null;
|
|
@@ -262,14 +248,23 @@ export class TeamRuntime {
|
|
|
262
248
|
for (let attempt = 0;; attempt += 1) {
|
|
263
249
|
const handle = handles[index];
|
|
264
250
|
const { run, agent } = handle;
|
|
251
|
+
// ABORTS GO THROUGH THE HANDLE (never `agent.abort()` directly): the
|
|
252
|
+
// handle sets the synchronous `abortRequested` flag the child's fast
|
|
253
|
+
// reviewer reads as its never-steer-into-a-requested-abort fact.
|
|
265
254
|
run.phase = 'starting';
|
|
266
255
|
run.startedAt = Date.now();
|
|
267
256
|
this.publish(dispatchId, run);
|
|
257
|
+
// `subagentTimeoutMs: 0` MEANS NO CEILING (main-agent parity): no timer
|
|
258
|
+
// is armed and `timedOut` can never become true. A wedged child is still
|
|
259
|
+
// ended by its OWN idle watchdog, which is the exact ceiling the lead
|
|
260
|
+
// runs under.
|
|
268
261
|
let timedOut = false;
|
|
269
|
-
const timer =
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
262
|
+
const timer = subagentTimeoutMs > 0
|
|
263
|
+
? setTimeout(() => {
|
|
264
|
+
timedOut = true;
|
|
265
|
+
handle.abort();
|
|
266
|
+
}, subagentTimeoutMs)
|
|
267
|
+
: null;
|
|
273
268
|
try {
|
|
274
269
|
await agent.prompt(handle.spec.prompt);
|
|
275
270
|
}
|
|
@@ -281,7 +276,8 @@ export class TeamRuntime {
|
|
|
281
276
|
run.error = err instanceof Error ? err.message : String(err);
|
|
282
277
|
}
|
|
283
278
|
finally {
|
|
284
|
-
|
|
279
|
+
if (timer)
|
|
280
|
+
clearTimeout(timer);
|
|
285
281
|
}
|
|
286
282
|
// THE TWO ABORT EXCLUSIONS THAT MAKE THE PREDICATE SAFE. Every abort in
|
|
287
283
|
// this system reaches the provider as an aborted fetch, and `core` marks
|
|
@@ -319,7 +315,7 @@ export class TeamRuntime {
|
|
|
319
315
|
const retries = (handle.run.retries ?? 0) + 1;
|
|
320
316
|
handle.unsubscribe();
|
|
321
317
|
try {
|
|
322
|
-
handle.
|
|
318
|
+
handle.abort();
|
|
323
319
|
}
|
|
324
320
|
catch {
|
|
325
321
|
// Already gone; this must not stop the retry.
|
|
@@ -346,7 +342,7 @@ export class TeamRuntime {
|
|
|
346
342
|
if (this.aborted) {
|
|
347
343
|
run.phase = 'aborted';
|
|
348
344
|
}
|
|
349
|
-
else if (timedOut) {
|
|
345
|
+
else if (timedOut && subagentTimeoutMs > 0) {
|
|
350
346
|
run.phase = 'failed';
|
|
351
347
|
run.error = run.error ?? `subagent exceeded ${Math.round(subagentTimeoutMs / 1000)}s`;
|
|
352
348
|
}
|
|
@@ -398,7 +394,7 @@ export class TeamRuntime {
|
|
|
398
394
|
this.aborted = true;
|
|
399
395
|
for (const handle of this.live) {
|
|
400
396
|
try {
|
|
401
|
-
handle.
|
|
397
|
+
handle.abort();
|
|
402
398
|
}
|
|
403
399
|
catch {
|
|
404
400
|
// A child that is already gone must not stop the others being aborted.
|
package/dist/team/subagent.d.ts
CHANGED
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
* omission has a reason that is a correctness boundary rather than caution.
|
|
12
12
|
*/
|
|
13
13
|
import type { ModelRole } from '../config/model-profiles.js';
|
|
14
|
-
import { type AgentConfig, type AgentEvent, type AgentTool, type Message, type
|
|
14
|
+
import { type AgentConfig, type AgentEvent, type AgentTool, type Message, type ProviderRegistry, type SkillRegistry, type TokenUsage, type ToolPolicyDecision, type ToolPolicyVerdict } from '@aragon-agent/core';
|
|
15
15
|
import type { AgentMode } from '../agent/agent-mode.js';
|
|
16
16
|
import type { ChildContextManagerProvider } from '../compaction/child.js';
|
|
17
17
|
import type { CliConfig } from '../config/schema.js';
|
|
18
18
|
import type { ToolPermission } from '../exec/permission.js';
|
|
19
|
-
import type {
|
|
19
|
+
import type { ChildReviewProvider } from './child-reviewer.js';
|
|
20
20
|
import { TeamBus } from './bus.js';
|
|
21
21
|
import type { TeamHumanQueue, WatchdogPausable } from './human-queue.js';
|
|
22
22
|
import type { SubagentRun, SubagentSpec } from './types.js';
|
|
@@ -31,6 +31,10 @@ export interface SubagentAgentLike extends WatchdogPausable {
|
|
|
31
31
|
prompt(text: string): Promise<void>;
|
|
32
32
|
abort(): void;
|
|
33
33
|
subscribe(listener: (event: AgentEvent) => void): () => void;
|
|
34
|
+
/** Steering surface for the child's own fast reviewer (core `Agent.steer`). */
|
|
35
|
+
steer(text: string): void;
|
|
36
|
+
/** Queued-block hygiene on abort, again mirroring the lead (D-21). */
|
|
37
|
+
clearAllQueues(): void;
|
|
34
38
|
/**
|
|
35
39
|
* The child's live history, for its own context manager
|
|
36
40
|
* (context-auto-compaction-hardening §3.4.3 / W3).
|
|
@@ -95,23 +99,11 @@ export interface SubagentDeps {
|
|
|
95
99
|
humanQueue?: TeamHumanQueue;
|
|
96
100
|
agentFactory: SubagentAgentFactory;
|
|
97
101
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* and test compiles unchanged and a `--no-fast` session builds children
|
|
102
|
-
* exactly as it always did.
|
|
103
|
-
*
|
|
104
|
-
* `resolveTier('fast')` RETURNS THE MAIN TIER when the fast tier is not
|
|
105
|
-
* available, which is what makes the two guards agree BY CONSTRUCTION: the
|
|
106
|
-
* normalizer can never produce a `tier: 'fast'` spec this factory would
|
|
107
|
-
* refuse, and this factory can never build a child against a `ModelRef` the
|
|
108
|
-
* tier stopped resolving twenty minutes ago (RV-3 / R-14).
|
|
102
|
+
* Per-child fast review (main-agent parity): the controller's shared
|
|
103
|
+
* provider, built on the lead's `FastWiring`. ABSENT means the session
|
|
104
|
+
* has no fast wiring, and the child is then exactly what it always was.
|
|
109
105
|
*/
|
|
110
|
-
|
|
111
|
-
ref: ModelRef;
|
|
112
|
-
thinkingLevel: ThinkingLevel;
|
|
113
|
-
role?: ModelRole;
|
|
114
|
-
};
|
|
106
|
+
review?: ChildReviewProvider;
|
|
115
107
|
/**
|
|
116
108
|
* Build this child its own context manager
|
|
117
109
|
* (context-auto-compaction-hardening §3.4.3 / W3).
|
|
@@ -134,6 +126,14 @@ export interface SubagentHandle {
|
|
|
134
126
|
run: SubagentRun;
|
|
135
127
|
agent: SubagentAgentLike;
|
|
136
128
|
tools: AgentTool[];
|
|
129
|
+
/**
|
|
130
|
+
* THE HANDLE-LEVEL ABORT, and the only one `TeamRuntime` may call. It sets a
|
|
131
|
+
* synchronous `abortRequested` flag BEFORE `agent.abort()`, which is what the
|
|
132
|
+
* child's fast reviewer reads as its guard-1 fact: an Esc or a dispatch stop
|
|
133
|
+
* must be visible to the reviewer in the same tick it happens, or the
|
|
134
|
+
* reviewer steers a `<fast_review>` block into a run that is already dying.
|
|
135
|
+
*/
|
|
136
|
+
abort: () => void;
|
|
137
137
|
unsubscribe: () => void;
|
|
138
138
|
}
|
|
139
139
|
/**
|
package/dist/team/subagent.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { Agent, createSkillFindTool, } from '@aragon-agent/core';
|
|
14
14
|
import { formatStreamError } from '../agent/reducer.js';
|
|
15
15
|
import { buildSystemPrompt } from '../agent/system-prompt.js';
|
|
16
|
+
import { buildFastBlock } from '../fast/prompt.js';
|
|
16
17
|
import { createBuiltinTools } from '../tools/index.js';
|
|
17
18
|
import { pickActivityArgs, sanitizeActivity } from './activity.js';
|
|
18
19
|
import { TEAM_LIMITS, TEAM_SUBAGENT_TOOL_NAMES } from './limits.js';
|
|
@@ -40,11 +41,17 @@ function assistantText(message) {
|
|
|
40
41
|
* the security boundary here, so it has to be directly checkable.
|
|
41
42
|
*/
|
|
42
43
|
export function buildSubagentTools(spec, deps, getAgent) {
|
|
44
|
+
// `team_wait`'s ceiling is the STRUCTURAL clamp when the child itself has no
|
|
45
|
+
// wall clock (`subagentTimeoutMs: 0`): a peer wait must stay bounded even when
|
|
46
|
+
// the child's run is not, or one forgotten wait would hold a slot forever.
|
|
47
|
+
const subagentTimeoutMs = deps.config.team.subagentTimeoutMs;
|
|
43
48
|
const commTools = [
|
|
44
49
|
makeTeamSend(deps.bus, spec.label),
|
|
45
50
|
makeTeamWait(deps.bus, spec.label, {
|
|
46
51
|
getAgent,
|
|
47
|
-
maxWaitMs:
|
|
52
|
+
maxWaitMs: subagentTimeoutMs > 0
|
|
53
|
+
? subagentTimeoutMs
|
|
54
|
+
: TEAM_LIMITS.waitMaxSeconds * 1000,
|
|
48
55
|
}),
|
|
49
56
|
];
|
|
50
57
|
const tools = createBuiltinTools({
|
|
@@ -141,9 +148,6 @@ export function createSubagent(spec, deps, hooks) {
|
|
|
141
148
|
const run = {
|
|
142
149
|
label: spec.label,
|
|
143
150
|
description: spec.description,
|
|
144
|
-
// FROM THE SPEC, which the normalizer already downgraded when the tier was
|
|
145
|
-
// unavailable — so this is what RAN, not what was asked for (§3.4).
|
|
146
|
-
tier: spec.tier,
|
|
147
151
|
phase: 'queued',
|
|
148
152
|
turns: 0,
|
|
149
153
|
toolCalls: 0,
|
|
@@ -158,37 +162,38 @@ export function createSubagent(spec, deps, hooks) {
|
|
|
158
162
|
let agentRef = null;
|
|
159
163
|
const getAgent = () => agentRef;
|
|
160
164
|
const tools = buildSubagentTools(spec, deps, getAgent);
|
|
161
|
-
// THE
|
|
162
|
-
//
|
|
163
|
-
//
|
|
165
|
+
// THE CHILD'S MODEL IS THE LEAD'S MODEL, READ FROM THE DISPATCH-TIME CONFIG
|
|
166
|
+
// (main-agent parity). Same provider, same model id, same base URL, same
|
|
167
|
+
// thinking level: a delegation is never a downgrade, and the only model a
|
|
168
|
+
// child may surprise its lead with is one a settings-screen edit made live
|
|
169
|
+
// between two dispatches.
|
|
164
170
|
//
|
|
165
|
-
// `
|
|
166
|
-
//
|
|
167
|
-
//
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
: {
|
|
178
|
-
ref: {
|
|
179
|
-
providerId: deps.config.provider,
|
|
180
|
-
modelId: deps.config.model,
|
|
181
|
-
...(deps.config.baseUrl ? { baseUrl: deps.config.baseUrl } : {}),
|
|
182
|
-
},
|
|
183
|
-
thinkingLevel: deps.config.thinkingLevel,
|
|
184
|
-
role: 'main',
|
|
185
|
-
};
|
|
171
|
+
// `maxTokens` inherits `deps.config.maxTokens` below - the same ambition the
|
|
172
|
+
// lead sends, clamped by the same adapter, so an inherited large value
|
|
173
|
+
// degrades to the right number rather than to an HTTP 400.
|
|
174
|
+
const resolved = {
|
|
175
|
+
ref: {
|
|
176
|
+
providerId: deps.config.provider,
|
|
177
|
+
modelId: deps.config.model,
|
|
178
|
+
...(deps.config.baseUrl ? { baseUrl: deps.config.baseUrl } : {}),
|
|
179
|
+
},
|
|
180
|
+
thinkingLevel: deps.config.thinkingLevel,
|
|
181
|
+
role: 'main',
|
|
182
|
+
};
|
|
186
183
|
const model = resolved.ref;
|
|
187
184
|
// HOISTED TO A LOCAL, AND THAT IS WHAT MAKES W3 POSSIBLE AT ALL. This was built
|
|
188
185
|
// INLINE inside the `agentFactory({...})` argument, so there was nothing for the
|
|
189
186
|
// child manager's `getSystemPrompt` accessor to close over - and the accessor
|
|
190
187
|
// cannot read it back off the agent, because `SubagentAgentLike` is narrowed to
|
|
191
188
|
// `state.messages` on purpose.
|
|
189
|
+
// THE SAME `<fast_tier>` BLOCK THE LEAD GETS, spliced only when this child
|
|
190
|
+
// will actually have a reviewer. The gating expression is written against
|
|
191
|
+
// `deps.review` here and the reviewer is built from the SAME predicate
|
|
192
|
+
// below, so the prompt can never advertise a capability the child lacks -
|
|
193
|
+
// and a child with a reviewer is never surprised by its first injection.
|
|
194
|
+
const fastBlock = deps.review !== undefined && deps.review.active()
|
|
195
|
+
? buildFastBlock({ model: deps.review.modelId(), review: true })
|
|
196
|
+
: '';
|
|
192
197
|
const systemPrompt = buildSystemPrompt({
|
|
193
198
|
cwd: deps.getCwd(),
|
|
194
199
|
tools,
|
|
@@ -203,6 +208,7 @@ export function createSubagent(spec, deps, hooks) {
|
|
|
203
208
|
description: spec.description,
|
|
204
209
|
peers: deps.bus.peersOf(spec.label),
|
|
205
210
|
}),
|
|
211
|
+
...(fastBlock ? { fastBlock } : {}),
|
|
206
212
|
});
|
|
207
213
|
// LAZY ACCESSORS OVER `agentRef`, WHICH IS ASSIGNED AFTER THIS RETURNS. A
|
|
208
214
|
// non-lazy read here is `undefined` at construction and the child's estimate
|
|
@@ -244,6 +250,27 @@ export function createSubagent(spec, deps, hooks) {
|
|
|
244
250
|
...(contextManager ? { contextManager } : {}),
|
|
245
251
|
});
|
|
246
252
|
agentRef = agent;
|
|
253
|
+
// PER-CHILD FAST REVIEW (main-agent parity). GATED ON THE PROVIDER'S OWN
|
|
254
|
+
// LIVE PREDICATE, read once here so the prompt and the reviewer CANNOT
|
|
255
|
+
// DISAGREE about whether the child has one: a child told about
|
|
256
|
+
// `<fast_review>` blocks must be a child that actually receives them, and a
|
|
257
|
+
// child with a reviewer must have been told. `abortRequested` is the flag
|
|
258
|
+
// `handle.abort()` sets (see `SubagentHandle`); the reviewer reads it as its
|
|
259
|
+
// never-steer-into-a-requested-abort fact.
|
|
260
|
+
let abortRequested = false;
|
|
261
|
+
const reviewLive = deps.review !== undefined && deps.review.active() === true;
|
|
262
|
+
const reviewer = reviewLive
|
|
263
|
+
? deps.review?.create({
|
|
264
|
+
label: spec.label,
|
|
265
|
+
goal: spec.description,
|
|
266
|
+
agent,
|
|
267
|
+
isRunning: () => run.phase === 'starting' ||
|
|
268
|
+
run.phase === 'thinking' ||
|
|
269
|
+
run.phase === 'tool' ||
|
|
270
|
+
run.phase === 'waiting',
|
|
271
|
+
isAbortRequested: () => abortRequested,
|
|
272
|
+
})
|
|
273
|
+
: undefined;
|
|
247
274
|
let lastEmit = 0;
|
|
248
275
|
let lastPhase = run.phase;
|
|
249
276
|
/**
|
|
@@ -325,8 +352,16 @@ export function createSubagent(spec, deps, hooks) {
|
|
|
325
352
|
// an aborted run, which the report renders as partial rather than lost.
|
|
326
353
|
if (text.length > 0)
|
|
327
354
|
run.summary = text;
|
|
328
|
-
|
|
355
|
+
// `0` MEANS NO CAP (main-agent parity): the lead has no turn ceiling
|
|
356
|
+
// either, and a child that needs forty turns for a forty-turn job is
|
|
357
|
+
// not runaway - it is working.
|
|
358
|
+
const turnCap = deps.config.team.maxTurnsPerSubagent;
|
|
359
|
+
if (turnCap > 0 && run.turns >= turnCap) {
|
|
329
360
|
run.truncated = true;
|
|
361
|
+
// THE FLAG FIRST, exactly like `handle.abort()`: the child's
|
|
362
|
+
// reviewer reads `abortRequested` as its guard-1 fact, and a
|
|
363
|
+
// turn-cap stop must be visible to it in the same tick.
|
|
364
|
+
abortRequested = true;
|
|
330
365
|
agent.abort();
|
|
331
366
|
}
|
|
332
367
|
break;
|
|
@@ -404,5 +439,20 @@ export function createSubagent(spec, deps, hooks) {
|
|
|
404
439
|
}
|
|
405
440
|
emit();
|
|
406
441
|
});
|
|
407
|
-
return {
|
|
442
|
+
return {
|
|
443
|
+
spec,
|
|
444
|
+
run,
|
|
445
|
+
agent,
|
|
446
|
+
tools,
|
|
447
|
+
// THE HANDLE-LEVEL ABORT (see `SubagentHandle`): the flag first, then the
|
|
448
|
+
// agent, so the reviewer's guard observes the request in the same tick.
|
|
449
|
+
abort: () => {
|
|
450
|
+
abortRequested = true;
|
|
451
|
+
agent.abort();
|
|
452
|
+
},
|
|
453
|
+
unsubscribe: () => {
|
|
454
|
+
reviewer?.dispose();
|
|
455
|
+
unsubscribe();
|
|
456
|
+
},
|
|
457
|
+
};
|
|
408
458
|
}
|
package/dist/team/task-tool.d.ts
CHANGED
|
@@ -19,6 +19,12 @@
|
|
|
19
19
|
* `normalizeSubagentSpecs`, which is deterministic and unit-tested. `maxItems`
|
|
20
20
|
* in the schema would behave differently depending on whether `ajv`, an OPTIONAL
|
|
21
21
|
* dependency of core, happened to install.
|
|
22
|
+
*
|
|
23
|
+
* EVERY CHILD RUNS THE LEAD'S OWN MODEL (main-agent parity): same provider,
|
|
24
|
+
* model, thinking level and token ambition, resolved from the LIVE config at
|
|
25
|
+
* dispatch. There is no per-child `model` property and no cheap tier to pick -
|
|
26
|
+
* a delegation is never a downgrade, and the fast tier reaches children the
|
|
27
|
+
* same way it reaches the lead (compaction summaries, per-child reviews).
|
|
22
28
|
*/
|
|
23
29
|
import { type AgentTool } from '@aragon-agent/core';
|
|
24
30
|
import type { ModelCost } from '@aragon-agent/core';
|
|
@@ -27,38 +33,12 @@ export interface TaskToolDeps {
|
|
|
27
33
|
runtime: TeamRuntime;
|
|
28
34
|
/** Read LIVE, never cached: `/team off` flips this, it does not unregister. */
|
|
29
35
|
isTeamEnabled: () => boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Whether the fast tier was resolvable AT CONSTRUCTION (fast-model-tier §3.3 /
|
|
32
|
-
* C-2).
|
|
33
|
-
*
|
|
34
|
-
* DECIDED ONCE, because the tool array is built once and must never be
|
|
35
|
-
* rebuilt: `Agent.setTools()` mutates the live `ToolRegistry`, and
|
|
36
|
-
* `submit_plan` flips the session mode from INSIDE a tool execution. So the
|
|
37
|
-
* `model` property either exists in this schema for the whole session or never
|
|
38
|
-
* does — and with it absent, `TASK_DESCRIPTION` and the schema are
|
|
39
|
-
* BYTE-IDENTICAL to the pre-feature build (AC-3).
|
|
40
|
-
*
|
|
41
|
-
* Optional so every existing construction site and test compiles unchanged.
|
|
42
|
-
*/
|
|
43
|
-
fastRegistered?: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Whether `model:"fast"` is honoured RIGHT NOW. Read LIVE, at dispatch time
|
|
46
|
-
* (RV-3) — the tier can stop resolving mid-session, and a downgrade is the
|
|
47
|
-
* honest observable either way.
|
|
48
|
-
*/
|
|
49
|
-
fastAvailable?: () => boolean;
|
|
50
36
|
maxSubagents: () => number;
|
|
51
37
|
/** Whether a usable key exists for the active provider right now (P2-3). */
|
|
52
38
|
hasApiKey: () => boolean;
|
|
53
39
|
activeProvider: () => string;
|
|
54
40
|
/** The lead's cost table, so the report header states real spend (R-5). */
|
|
55
41
|
modelCost: () => ModelCost | undefined;
|
|
56
|
-
/** The FAST model's cost table (fast-model-tier §3.4). Absent when the tier is
|
|
57
|
-
* off, which is what leaves the report byte-identical. */
|
|
58
|
-
fastModelCost?: () => ModelCost | undefined;
|
|
59
|
-
/** Whether the static price table has never heard of the fast model (C-11 /
|
|
60
|
-
* RV-4). `unknown` is rendered as unknown, NEVER as `$0.00`. */
|
|
61
|
-
fastPricingUnknown?: () => boolean;
|
|
62
42
|
/**
|
|
63
43
|
* Run the dispatch with the LEAD's idle watchdog paused, `try/finally` inside.
|
|
64
44
|
*
|
package/dist/team/task-tool.js
CHANGED
|
@@ -19,6 +19,12 @@
|
|
|
19
19
|
* `normalizeSubagentSpecs`, which is deterministic and unit-tested. `maxItems`
|
|
20
20
|
* in the schema would behave differently depending on whether `ajv`, an OPTIONAL
|
|
21
21
|
* dependency of core, happened to install.
|
|
22
|
+
*
|
|
23
|
+
* EVERY CHILD RUNS THE LEAD'S OWN MODEL (main-agent parity): same provider,
|
|
24
|
+
* model, thinking level and token ambition, resolved from the LIVE config at
|
|
25
|
+
* dispatch. There is no per-child `model` property and no cheap tier to pick -
|
|
26
|
+
* a delegation is never a downgrade, and the fast tier reaches children the
|
|
27
|
+
* same way it reaches the lead (compaction summaries, per-child reviews).
|
|
22
28
|
*/
|
|
23
29
|
import { errorResult, textResult } from '@aragon-agent/core';
|
|
24
30
|
import { TEAM_LIMITS } from './limits.js';
|
|
@@ -33,7 +39,8 @@ const TEAM_OFF_REFUSAL = 'Team mode is off for this session. Do this work yourse
|
|
|
33
39
|
*/
|
|
34
40
|
const TASK_DESCRIPTION = 'Run several independent subagents in parallel and get one combined report. Each ' +
|
|
35
41
|
'subagent is a fresh agent with the same tools and working directory but NO memory of ' +
|
|
36
|
-
'this conversation - its prompt must be self-contained.
|
|
42
|
+
'this conversation - its prompt must be self-contained. Each runs on the same model ' +
|
|
43
|
+
'you are running on. Use this when a task splits ' +
|
|
37
44
|
'into 2 or more parts that do not depend on each other\'s output, especially reading or ' +
|
|
38
45
|
'searching several areas at once. Do NOT use it when one part needs another part\'s ' +
|
|
39
46
|
'result (do those yourself, in order), when two parts would edit the same file, or for ' +
|
|
@@ -41,37 +48,11 @@ const TASK_DESCRIPTION = 'Run several independent subagents in parallel and get
|
|
|
41
48
|
'cannot ask the user anything. Give each a description of at most ' +
|
|
42
49
|
`${TEAM_LIMITS.descriptionChars} characters and a complete prompt. Extra entries beyond the ` +
|
|
43
50
|
'configured maximum are dropped, so keep within it.';
|
|
44
|
-
/**
|
|
45
|
-
* The one sentence appended when the fast tier exists (fast-model-tier §4.1).
|
|
46
|
-
*
|
|
47
|
-
* WHEN to use a tier is POLICY and lives here and in `<fast_tier>`, where the
|
|
48
|
-
* model actually reads it; the `enum` below is SHAPE and lives in the schema.
|
|
49
|
-
* That split is what keeps behaviour the same whether or not `ajv` — an OPTIONAL
|
|
50
|
-
* dependency of core — happened to install (C-8).
|
|
51
|
-
*/
|
|
52
|
-
const TASK_FAST_SENTENCE = ' Set model:"fast" on a subagent whose job is bulk reading, searching or summarizing; ' +
|
|
53
|
-
'leave it out for work that needs judgement.';
|
|
54
|
-
/**
|
|
55
|
-
* NOT `as const`: `AgentTool.parameters` is a `JSONSchema7`, whose `enum` is a
|
|
56
|
-
* MUTABLE `unknown[]`, and a readonly tuple is not assignable to it.
|
|
57
|
-
*/
|
|
58
|
-
const SUBAGENT_MODEL_PROPERTY = {
|
|
59
|
-
type: 'string',
|
|
60
|
-
enum: ['main', 'fast'],
|
|
61
|
-
default: 'main',
|
|
62
|
-
description: 'Which tier runs this subagent. "fast" is a cheaper, quicker model - use it for ' +
|
|
63
|
-
'mechanical, high-volume work (reading or searching many files, summarizing long ' +
|
|
64
|
-
'output, mechanical edits). Keep "main" for design, tricky debugging, and anything ' +
|
|
65
|
-
'that must be right the first time.',
|
|
66
|
-
};
|
|
67
51
|
export function createTaskTool(deps) {
|
|
68
|
-
const fastRegistered = deps.fastRegistered === true;
|
|
69
52
|
return {
|
|
70
53
|
name: 'task',
|
|
71
54
|
label: 'Dispatch subagents',
|
|
72
|
-
|
|
73
|
-
// default session's description is the exact string it always was.
|
|
74
|
-
description: fastRegistered ? `${TASK_DESCRIPTION}${TASK_FAST_SENTENCE}` : TASK_DESCRIPTION,
|
|
55
|
+
description: TASK_DESCRIPTION,
|
|
75
56
|
parameters: {
|
|
76
57
|
type: 'object',
|
|
77
58
|
properties: {
|
|
@@ -99,11 +80,6 @@ export function createTaskTool(deps) {
|
|
|
99
80
|
default: false,
|
|
100
81
|
description: 'Refuse all writes and shell for this subagent.',
|
|
101
82
|
},
|
|
102
|
-
// Spread rather than a `?:` property, so with the tier off the
|
|
103
|
-
// object has exactly the four keys it always had — `undefined`
|
|
104
|
-
// survives `JSON.stringify` as an absent key but not as an
|
|
105
|
-
// identical object, and AC-3 is asserted on the schema itself.
|
|
106
|
-
...(fastRegistered ? { model: SUBAGENT_MODEL_PROPERTY } : {}),
|
|
107
83
|
},
|
|
108
84
|
required: ['description', 'prompt'],
|
|
109
85
|
},
|
|
@@ -131,31 +107,21 @@ export function createTaskTool(deps) {
|
|
|
131
107
|
'yourself, or ask the user to set a key.');
|
|
132
108
|
}
|
|
133
109
|
// 4. Repair, never reject. Zero survivors is the single hard failure.
|
|
134
|
-
|
|
135
|
-
// construction (RV-3): the tier can stop resolving mid-session, and the
|
|
136
|
-
// normalizer and the subagent factory must agree about that at the same
|
|
137
|
-
// instant or a child gets built against a provider with no key.
|
|
138
|
-
const { specs, requested, downgraded } = normalizeSubagentSpecs(params.subagents, deps.maxSubagents(), { fastAvailable: deps.fastAvailable?.() === true });
|
|
110
|
+
const { specs, requested } = normalizeSubagentSpecs(params.subagents, deps.maxSubagents());
|
|
139
111
|
if (specs.length === 0) {
|
|
140
112
|
return errorResult('No usable subagent specs: each needs a description and a prompt.');
|
|
141
113
|
}
|
|
142
114
|
// 5. Pause the lead's watchdog for the whole dispatch (I-3).
|
|
143
|
-
const outcome = await deps.withPausedWatchdog(() => deps.runtime.dispatch(specs, requested, ctx.signal
|
|
115
|
+
const outcome = await deps.withPausedWatchdog(() => deps.runtime.dispatch(specs, requested, ctx.signal));
|
|
144
116
|
// 6. ALWAYS A NON-ERROR RESULT, abort and all-children-failed included.
|
|
145
117
|
// A cancellation or a partial result rendered as a tool FAILURE invites
|
|
146
118
|
// the model to retry the whole fan-out, which is the most expensive
|
|
147
119
|
// possible reaction (the same reasoning as `ask_user`'s cancelled
|
|
148
|
-
// shape, and D-14 one level up).
|
|
149
|
-
//
|
|
150
|
-
// price is not a rounding error: for a Haiku child under a Sonnet lead
|
|
151
|
-
// it over-reports by roughly an order of magnitude, and the whole
|
|
152
|
-
// justification for the feature is a number in this report.
|
|
120
|
+
// shape, and D-14 one level up). Every child ran the lead's own model,
|
|
121
|
+
// so the lead's cost table is the one honest price for the total.
|
|
153
122
|
const cost = deps.modelCost();
|
|
154
|
-
const fastCost = deps.fastModelCost?.();
|
|
155
123
|
return textResult(buildDispatchReport(outcome, {
|
|
156
124
|
...(cost ? { cost } : {}),
|
|
157
|
-
...(fastCost ? { fastCost } : {}),
|
|
158
|
-
...(deps.fastPricingUnknown?.() ? { fastPricingUnknown: true } : {}),
|
|
159
125
|
}));
|
|
160
126
|
},
|
|
161
127
|
};
|
package/dist/team/types.d.ts
CHANGED
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
* changes ZERO files under `packages/core/` (AC-12).
|
|
12
12
|
*/
|
|
13
13
|
import type { TokenUsage } from '@aragon-agent/core';
|
|
14
|
-
import type { FastTierName } from '../fast/types.js';
|
|
15
14
|
import type { ActivityArgs } from './activity.js';
|
|
16
15
|
/** One normalized delegation request. Produced only by `normalizeSubagentSpecs`. */
|
|
17
16
|
export interface SubagentSpec {
|
|
@@ -27,34 +26,12 @@ export interface SubagentSpec {
|
|
|
27
26
|
* permission than the session it was spawned from.
|
|
28
27
|
*/
|
|
29
28
|
readOnly: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Which model runs this child (fast-model-tier §3.4).
|
|
32
|
-
*
|
|
33
|
-
* THE WIRE NAME IS `model` AND THE INTERNAL NAME IS `tier`, on purpose: a
|
|
34
|
-
* model expects to see `model:"fast"`, while `SubagentSpec.model` would read
|
|
35
|
-
* as a model ID at every call site in this package.
|
|
36
|
-
*
|
|
37
|
-
* DELEGATION IS A MODEL CHOICE, NEVER A PERMISSION BOUNDARY (D-15 / I-4). A
|
|
38
|
-
* fast child gets the same tools, the same `--confirm` gate, the same
|
|
39
|
-
* plan-mode gate and the same skills ceiling as any other; only the model
|
|
40
|
-
* differs. Restricting a fast child's tools would look like security, would
|
|
41
|
-
* not be, and would make the report's `[fast]` rows mean two different things.
|
|
42
|
-
*/
|
|
43
|
-
tier: FastTierName;
|
|
44
29
|
}
|
|
45
30
|
export type SubagentPhase = 'queued' | 'starting' | 'thinking' | 'tool' | 'waiting' | 'done' | 'failed' | 'aborted';
|
|
46
31
|
/** Live, mutable record of one child. Projected into the UI and the report. */
|
|
47
32
|
export interface SubagentRun {
|
|
48
33
|
label: string;
|
|
49
34
|
description: string;
|
|
50
|
-
/**
|
|
51
|
-
* The tier this child actually ran on (fast-model-tier §3.4).
|
|
52
|
-
*
|
|
53
|
-
* WHAT RAN, NOT WHAT WAS ASKED FOR. A spec the normalizer downgraded arrives
|
|
54
|
-
* here as `'main'`, which is what makes the report's `[fast]` annotation and
|
|
55
|
-
* its second cost table agree with the bill.
|
|
56
|
-
*/
|
|
57
|
-
tier: FastTierName;
|
|
58
35
|
phase: SubagentPhase;
|
|
59
36
|
startedAt?: number;
|
|
60
37
|
endedAt?: number;
|
|
@@ -192,26 +169,11 @@ export interface DispatchOutcome {
|
|
|
192
169
|
/** Messages addressed to `lead`; surfaced in their own report section. */
|
|
193
170
|
leadMail: TeamMessage[];
|
|
194
171
|
/**
|
|
195
|
-
* Summed across
|
|
196
|
-
* (§3.9).
|
|
197
|
-
*
|
|
198
|
-
* THE MEANING NARROWED WHEN THE FAST TIER LANDED, and the split is not a
|
|
199
|
-
* rounding concern: a Haiku child under a Sonnet lead priced at the lead's
|
|
200
|
-
* table over-reports by roughly an order of magnitude, and the entire
|
|
201
|
-
* justification for delegating is a number in this report (R-7).
|
|
172
|
+
* Summed across all children. Real spend; it must reach the status bar
|
|
173
|
+
* (§3.9). Every child runs the LEAD's model (main-agent parity), so one
|
|
174
|
+
* total priced at the lead's table is the honest accounting.
|
|
202
175
|
*/
|
|
203
176
|
usage: TokenUsage;
|
|
204
|
-
/** Summed across FAST-TIER children. Absent when none ran, which is what
|
|
205
|
-
* keeps a pre-feature dispatch's report byte-identical. */
|
|
206
|
-
fastUsage?: TokenUsage;
|
|
207
|
-
/**
|
|
208
|
-
* Specs that asked for `model:"fast"` and ran on `main` anyway (§3.4 / R-6).
|
|
209
|
-
*
|
|
210
|
-
* REPORTED, NEVER SILENT. A silent downgrade means the model asked for a cheap
|
|
211
|
-
* child, got an expensive one, and has no way to learn that its cost model is
|
|
212
|
-
* wrong.
|
|
213
|
-
*/
|
|
214
|
-
downgraded?: number;
|
|
215
177
|
}
|
|
216
178
|
/**
|
|
217
179
|
* What the UI renders: a cheap immutable projection, rebuilt per event.
|
|
@@ -246,7 +208,6 @@ export type TeamEvent = {
|
|
|
246
208
|
dispatchId: string;
|
|
247
209
|
label: string;
|
|
248
210
|
usage: TokenUsage;
|
|
249
|
-
tier: FastTierName;
|
|
250
211
|
} | {
|
|
251
212
|
type: 'message';
|
|
252
213
|
dispatchId: string;
|