@aragon-agent/cli 0.6.56 → 0.6.58
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 +94 -0
- package/README.md +159 -3
- package/dist/agent/controller.d.ts +112 -1
- package/dist/agent/controller.js +350 -7
- package/dist/agent/project-guidance-prompt.js +97 -97
- package/dist/agent/redteam-prompt.d.ts +29 -11
- package/dist/agent/redteam-prompt.js +118 -103
- package/dist/agent/redteam-wiring.d.ts +117 -2
- package/dist/agent/redteam-wiring.js +204 -1
- package/dist/agent/team-notices.d.ts +68 -0
- package/dist/agent/team-notices.js +82 -0
- package/dist/app/App.js +208 -5
- package/dist/app/use-redteam-mode.d.ts +1 -1
- package/dist/app/use-redteam-mode.js +14 -1
- package/dist/cli.js +13 -0
- package/dist/commands/catalog.js +6 -2
- package/dist/commands/redteam-command.d.ts +14 -8
- package/dist/commands/redteam-command.js +243 -12
- package/dist/commands/team-command.js +93 -2
- package/dist/config/app-paths.d.ts +19 -0
- package/dist/config/app-paths.js +23 -0
- package/dist/config/load.d.ts +8 -0
- package/dist/gene/catalog-sync.js +37 -16
- package/dist/gene/curator/budget.js +1 -1
- package/dist/gene/curator/curator.d.ts +6 -0
- package/dist/gene/curator/curator.js +8 -0
- package/dist/gene/curator/recheck.js +2 -1
- package/dist/gene/curator/task-runner.js +4 -1
- package/dist/gene/curator/tool-support.js +16 -7
- package/dist/gene/curator/tools-verify.js +54 -1
- package/dist/gene/curator/tools-write.js +41 -1
- package/dist/gene/curator/validate/evidence-tokens.d.ts +7 -19
- package/dist/gene/curator/validate/evidence-tokens.js +174 -17
- package/dist/gene/curator/validate/knowledge.d.ts +22 -1
- package/dist/gene/curator/validate/knowledge.js +108 -25
- package/dist/gene/curator/validate/live-check.js +7 -1
- package/dist/gene/curator/validate/prompts.js +7 -3
- package/dist/gene/curator/validate/types.d.ts +6 -1
- package/dist/gene/learn/learn-call.d.ts +58 -5
- package/dist/gene/learn/learn-call.js +38 -30
- package/dist/gene/learn/learn-prompt.d.ts +18 -2
- package/dist/gene/learn/learn-prompt.js +29 -11
- package/dist/gene/learn/learner.d.ts +6 -0
- package/dist/gene/learn/learner.js +31 -9
- package/dist/gene/learn/proposal-build.js +2 -6
- package/dist/gene/wiring-models.js +4 -1
- package/dist/governance/engine/lifecycle.js +1 -1
- package/dist/governance/store/run-lock.d.ts +9 -2
- package/dist/governance/store/run-lock.js +91 -7
- package/dist/host/controller-factory.d.ts +13 -0
- package/dist/host/controller-factory.js +7 -0
- package/dist/host/index.d.ts +1 -0
- package/dist/host/index.js +1 -0
- package/dist/host/interaction.d.ts +19 -0
- package/dist/host/interaction.js +75 -0
- package/dist/host/team-control.d.ts +83 -0
- package/dist/host/team-control.js +55 -0
- package/dist/logging/install.d.ts +32 -1
- package/dist/logging/install.js +21 -0
- package/dist/proc/output-streams.d.ts +11 -0
- package/dist/proc/output-streams.js +11 -0
- package/dist/redteam/prompt-resolve.d.ts +61 -0
- package/dist/redteam/prompt-resolve.js +303 -0
- package/dist/redteam/prompt-store.d.ts +96 -0
- package/dist/redteam/prompt-store.js +156 -0
- package/dist/redteam/prompt-template.d.ts +22 -0
- package/dist/redteam/prompt-template.js +72 -0
- package/dist/team/bus.d.ts +18 -0
- package/dist/team/bus.js +70 -18
- package/dist/team/console-tools.d.ts +54 -0
- package/dist/team/console-tools.js +333 -0
- package/dist/team/console-view.d.ts +88 -0
- package/dist/team/console-view.js +173 -0
- package/dist/team/forced-mode.d.ts +61 -1
- package/dist/team/forced-mode.js +75 -0
- package/dist/team/normalize.d.ts +31 -0
- package/dist/team/normalize.js +49 -5
- package/dist/team/notices.d.ts +95 -0
- package/dist/team/notices.js +121 -0
- package/dist/team/pause-gate.d.ts +79 -0
- package/dist/team/pause-gate.js +127 -0
- package/dist/team/prompt.d.ts +25 -9
- package/dist/team/prompt.js +29 -29
- package/dist/team/report.js +33 -0
- package/dist/team/runtime.d.ts +270 -5
- package/dist/team/runtime.js +732 -64
- package/dist/team/settled.d.ts +5 -2
- package/dist/team/settled.js +12 -2
- package/dist/team/subagent.d.ts +7 -0
- package/dist/team/subagent.js +12 -1
- package/dist/team/task-tool.d.ts +39 -1
- package/dist/team/task-tool.js +75 -18
- package/dist/tools/bash-tool.d.ts +11 -8
- package/dist/tools/bash-tool.js +37 -9
- package/dist/tools/index.d.ts +2 -2
- package/dist/tools/index.js +30 -0
- package/package.json +3 -3
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The seven LEAD-side control tools (team-detached-dispatch section 5.2).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY: `src/team/**` is inside `glyphs.test.ts`'s static scan. The gate
|
|
5
|
+
* `docs/guide-doc` extracts tool names from THIS file with a line-anchored
|
|
6
|
+
* `name: '<tool>',` pattern, so each `name:` literal stays alone on its line.
|
|
7
|
+
*
|
|
8
|
+
* WHY THE LEAD NEEDS THESE AT ALL. Making the lead idle during a dispatch solves
|
|
9
|
+
* the queue problem and creates a responsibility: an idle lead that cannot look,
|
|
10
|
+
* steer or stop is just a lead that has been told to wait somewhere else. The
|
|
11
|
+
* console is the other half of the feature, and every tool here is a thin call
|
|
12
|
+
* into `TeamRuntime`'s public surface - no tool touches a handle, a bus or a
|
|
13
|
+
* phase. That is what keeps the audit (I-DD5) and the abort path (REV-03) single
|
|
14
|
+
* sourced.
|
|
15
|
+
*
|
|
16
|
+
* EVERY REFUSAL IS A NON-ERROR `textResult` (section 5.2.1). An `errorResult`
|
|
17
|
+
* reads to a model as a malfunction and invites an immediate retry, which is how
|
|
18
|
+
* a console turns into a loop. "No dispatch is running" is an ANSWER, and the
|
|
19
|
+
* wording says what to do instead.
|
|
20
|
+
*
|
|
21
|
+
* `team_collect` IS THE ONLY ONE THAT MAY WAIT, and even it must stop waiting the
|
|
22
|
+
* moment the user is owed an answer (I-DD2). It polls `hasPendingUserInput`, which
|
|
23
|
+
* the controller injects from the queue's own predicate - so "the lead is asleep
|
|
24
|
+
* while the user waits" is structurally impossible rather than merely unlikely.
|
|
25
|
+
*/
|
|
26
|
+
import { textResult } from '@aragon-agent/core';
|
|
27
|
+
import { TEAM_LIMITS } from '@aragon-agent/tui/model/team/limits';
|
|
28
|
+
import { renderPauseResult, renderResumeResult, renderSendResult, renderSpawnResult, renderStopResult, renderTeamStatus, } from './console-view.js';
|
|
29
|
+
const NO_DISPATCH = 'No team dispatch is running. Use task to start one.';
|
|
30
|
+
/** A string field, trimmed, or `''`. Shape repair belongs here, not in the schema. */
|
|
31
|
+
function str(value) {
|
|
32
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
33
|
+
}
|
|
34
|
+
function num(value) {
|
|
35
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
36
|
+
}
|
|
37
|
+
/** `team_status` - the read surface. */
|
|
38
|
+
export function makeTeamStatusTool(deps) {
|
|
39
|
+
return {
|
|
40
|
+
name: 'team_status',
|
|
41
|
+
label: 'Team status',
|
|
42
|
+
description: 'Show the running team: each subagent\'s phase, how long it has run, its turns and ' +
|
|
43
|
+
'tool calls, who paused it, the dispatch ceiling and any mail the children sent you. ' +
|
|
44
|
+
'Use it to answer "how is it going" and to decide who needs a message or a pause. ' +
|
|
45
|
+
'Set includeSummary for the settled children\'s own reports.',
|
|
46
|
+
parameters: {
|
|
47
|
+
type: 'object',
|
|
48
|
+
properties: {
|
|
49
|
+
labels: {
|
|
50
|
+
type: 'array',
|
|
51
|
+
items: { type: 'string' },
|
|
52
|
+
description: 'Only these subagent labels. Omit for the whole roster.',
|
|
53
|
+
},
|
|
54
|
+
includeSummary: {
|
|
55
|
+
type: 'boolean',
|
|
56
|
+
default: false,
|
|
57
|
+
description: 'Also show each settled child\'s summary (bounded).',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
async execute(_id, params) {
|
|
62
|
+
const inspection = deps.runtime.inspect();
|
|
63
|
+
if (inspection === null)
|
|
64
|
+
return textResult(NO_DISPATCH);
|
|
65
|
+
const p = params;
|
|
66
|
+
const labels = Array.isArray(p.labels)
|
|
67
|
+
? p.labels.filter((label) => typeof label === 'string')
|
|
68
|
+
: undefined;
|
|
69
|
+
return textResult(renderTeamStatus(inspection, {
|
|
70
|
+
...(labels !== undefined ? { labels } : {}),
|
|
71
|
+
includeSummary: p.includeSummary === true,
|
|
72
|
+
}));
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** `team_message` - steer a child, or all of them. */
|
|
77
|
+
export function makeTeamMessageTool(deps) {
|
|
78
|
+
return {
|
|
79
|
+
name: 'team_message',
|
|
80
|
+
label: 'Message subagents',
|
|
81
|
+
description: 'Send one short instruction to a subagent (or "all"). Use it when the user changes ' +
|
|
82
|
+
'the goal, or when a child is heading the wrong way - not for status updates. ' +
|
|
83
|
+
'The message also reaches a child that is mid-request (interrupt, default on) at its ' +
|
|
84
|
+
'next safe point. You have ' +
|
|
85
|
+
`${TEAM_LIMITS.messagesFromLeadPerDispatch} messages per dispatch.`,
|
|
86
|
+
parameters: {
|
|
87
|
+
type: 'object',
|
|
88
|
+
required: ['to', 'body'],
|
|
89
|
+
properties: {
|
|
90
|
+
to: { type: 'string', description: 'A subagent label, or "all".' },
|
|
91
|
+
subject: { type: 'string', description: `<= ${TEAM_LIMITS.subjectChars} chars.` },
|
|
92
|
+
body: { type: 'string', description: `<= ${TEAM_LIMITS.bodyChars} chars.` },
|
|
93
|
+
interrupt: {
|
|
94
|
+
type: 'boolean',
|
|
95
|
+
default: true,
|
|
96
|
+
description: 'Also steer the child at its next safe point, not only on its next tool result.',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
async execute(_id, params) {
|
|
101
|
+
const p = params;
|
|
102
|
+
const to = str(p.to);
|
|
103
|
+
const body = str(p.body);
|
|
104
|
+
if (to.length === 0 || body.length === 0) {
|
|
105
|
+
return textResult('Not sent: team_message needs a "to" and a "body".');
|
|
106
|
+
}
|
|
107
|
+
const verdict = deps.runtime.sendFromLead(to, body, {
|
|
108
|
+
...(str(p.subject).length > 0 ? { subject: str(p.subject) } : {}),
|
|
109
|
+
interrupt: p.interrupt !== false,
|
|
110
|
+
...(deps.by !== undefined ? { by: deps.by } : {}),
|
|
111
|
+
});
|
|
112
|
+
if (!verdict.ok)
|
|
113
|
+
return textResult(`Not sent: ${verdict.why}.`);
|
|
114
|
+
return textResult(renderSendResult(verdict.delivered, verdict.remaining));
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/** `team_pause` - hold one child. */
|
|
119
|
+
export function makeTeamPauseTool(deps) {
|
|
120
|
+
return {
|
|
121
|
+
name: 'team_pause',
|
|
122
|
+
label: 'Pause subagent',
|
|
123
|
+
description: 'Hold one subagent so its next tool does not start. Pausing is cooperative: a child ' +
|
|
124
|
+
'that is mid-tool or mid-sentence stops at the next boundary, not instantly. It stays ' +
|
|
125
|
+
'paused until team_resume or team_stop - nothing resumes it automatically.',
|
|
126
|
+
parameters: {
|
|
127
|
+
type: 'object',
|
|
128
|
+
required: ['label'],
|
|
129
|
+
properties: {
|
|
130
|
+
label: { type: 'string', description: 'The subagent label.' },
|
|
131
|
+
reason: { type: 'string', description: 'Why, for the report. Keep it short.' },
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
async execute(_id, params) {
|
|
135
|
+
const p = params;
|
|
136
|
+
const label = str(p.label);
|
|
137
|
+
if (label.length === 0)
|
|
138
|
+
return textResult('team_pause needs a "label".');
|
|
139
|
+
const by = deps.by ?? 'lead';
|
|
140
|
+
const result = deps.runtime.pauseChild(label, by, str(p.reason));
|
|
141
|
+
if ('why' in result)
|
|
142
|
+
return textResult(`Not paused: ${result.why}.`);
|
|
143
|
+
return textResult(renderPauseResult(label, result.effect, by));
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** `team_resume` - release one child, optionally with an instruction. */
|
|
148
|
+
export function makeTeamResumeTool(deps) {
|
|
149
|
+
return {
|
|
150
|
+
name: 'team_resume',
|
|
151
|
+
label: 'Resume subagent',
|
|
152
|
+
description: 'Release a subagent held by team_pause and let it continue from where it stopped. ' +
|
|
153
|
+
'A "message" is steered into it as it resumes, which is the cheapest way to redirect ' +
|
|
154
|
+
'a child you paused earlier.',
|
|
155
|
+
parameters: {
|
|
156
|
+
type: 'object',
|
|
157
|
+
required: ['label'],
|
|
158
|
+
properties: {
|
|
159
|
+
label: { type: 'string' },
|
|
160
|
+
message: { type: 'string', description: 'What to tell it as it resumes.' },
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
async execute(_id, params) {
|
|
164
|
+
const p = params;
|
|
165
|
+
const label = str(p.label);
|
|
166
|
+
if (label.length === 0)
|
|
167
|
+
return textResult('team_resume needs a "label".');
|
|
168
|
+
const message = str(p.message);
|
|
169
|
+
const result = deps.runtime.resumeChild(label, deps.by ?? 'lead', message);
|
|
170
|
+
if (!result.ok)
|
|
171
|
+
return textResult(`Not resumed: ${result.why}.`);
|
|
172
|
+
return textResult(renderResumeResult(label, result.effect, message.length > 0));
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/** `team_stop` - end one child or the whole dispatch. */
|
|
177
|
+
export function makeTeamStopTool(deps) {
|
|
178
|
+
return {
|
|
179
|
+
name: 'team_stop',
|
|
180
|
+
label: 'Stop subagents',
|
|
181
|
+
description: 'End one subagent, or the whole dispatch with "all". A stopped child is recorded as ' +
|
|
182
|
+
'aborted and its partial work stays in the report. This is also the only way to end a ' +
|
|
183
|
+
'dispatch that someone else started, so it is what you use when the user asks you to stop.',
|
|
184
|
+
parameters: {
|
|
185
|
+
type: 'object',
|
|
186
|
+
required: ['label'],
|
|
187
|
+
properties: {
|
|
188
|
+
label: { type: 'string', description: 'A label, or "all".' },
|
|
189
|
+
reason: { type: 'string' },
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
async execute(_id, params) {
|
|
193
|
+
const p = params;
|
|
194
|
+
const label = str(p.label);
|
|
195
|
+
if (label.length === 0)
|
|
196
|
+
return textResult('team_stop needs a "label", or "all".');
|
|
197
|
+
const done = deps.runtime.stopChild(label.toLowerCase() === 'all' ? 'all' : label, deps.by ?? 'lead', str(p.reason));
|
|
198
|
+
if (done.stopped.length === 0 && done.live.length === 0)
|
|
199
|
+
return textResult(NO_DISPATCH);
|
|
200
|
+
return textResult(renderStopResult(done.stopped, done.live, done.unknown === true ? { unknownLabel: label } : {}));
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/** `team_spawn` - add subagents to the dispatch that is already running. */
|
|
205
|
+
export function makeTeamSpawnTool(deps) {
|
|
206
|
+
return {
|
|
207
|
+
name: 'team_spawn',
|
|
208
|
+
label: 'Add subagents',
|
|
209
|
+
description: 'Add one or more subagents to the team that is already running - for work the first ' +
|
|
210
|
+
'briefs did not cover. The same total ceiling applies (' +
|
|
211
|
+
`${TEAM_LIMITS.hardMaxSubagents} at most), so a full dispatch must free a slot first. ` +
|
|
212
|
+
'Each spec needs a description and a self-contained prompt, exactly like task.',
|
|
213
|
+
parameters: {
|
|
214
|
+
type: 'object',
|
|
215
|
+
required: ['subagents'],
|
|
216
|
+
properties: {
|
|
217
|
+
subagents: {
|
|
218
|
+
type: 'array',
|
|
219
|
+
items: {
|
|
220
|
+
type: 'object',
|
|
221
|
+
required: ['description', 'prompt'],
|
|
222
|
+
properties: {
|
|
223
|
+
label: { type: 'string', description: `Short id, <= ${TEAM_LIMITS.labelChars} chars.` },
|
|
224
|
+
description: { type: 'string', description: `<= ${TEAM_LIMITS.descriptionChars} chars.` },
|
|
225
|
+
prompt: { type: 'string', description: 'The full brief. Self-contained.' },
|
|
226
|
+
readOnly: { type: 'boolean', default: false },
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
reason: { type: 'string' },
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
async execute(_id, params) {
|
|
234
|
+
const p = params;
|
|
235
|
+
const result = deps.runtime.addSpecs(p.subagents, deps.by ?? 'lead', str(p.reason));
|
|
236
|
+
if ('why' in result)
|
|
237
|
+
return textResult(`Not added: ${result.why}.`);
|
|
238
|
+
return textResult(renderSpawnResult(result.added, result.dropped, result.requested));
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
/** `team_collect` - the one bounded wait, and it yields to the user. */
|
|
243
|
+
export function makeTeamCollectTool(deps) {
|
|
244
|
+
return {
|
|
245
|
+
name: 'team_collect',
|
|
246
|
+
label: 'Collect team report',
|
|
247
|
+
description: 'Wait a bounded moment for the dispatch to finish, then return its report. Use it only ' +
|
|
248
|
+
'when you cannot answer without the result - the report arrives on its own when the team ' +
|
|
249
|
+
'finishes. It returns immediately if you already have it, and it stops waiting the moment ' +
|
|
250
|
+
'the user sends you something.',
|
|
251
|
+
parameters: {
|
|
252
|
+
type: 'object',
|
|
253
|
+
properties: {
|
|
254
|
+
timeoutSeconds: {
|
|
255
|
+
type: 'number',
|
|
256
|
+
description: `${TEAM_LIMITS.waitMinSeconds}..${TEAM_LIMITS.waitMaxSeconds}, default ` +
|
|
257
|
+
`${TEAM_LIMITS.waitDefaultSeconds}.`,
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
async execute(_id, params) {
|
|
262
|
+
const p = params;
|
|
263
|
+
const requested = num(p.timeoutSeconds) ?? TEAM_LIMITS.waitDefaultSeconds;
|
|
264
|
+
const seconds = Math.min(TEAM_LIMITS.waitMaxSeconds, Math.max(TEAM_LIMITS.waitMinSeconds, Math.round(requested)));
|
|
265
|
+
const startId = deps.runtime.currentDispatchId();
|
|
266
|
+
if (startId === null)
|
|
267
|
+
return textResult(NO_DISPATCH);
|
|
268
|
+
if (deps.runtime.live() === null) {
|
|
269
|
+
const report = deps.runtime.reportText(startId);
|
|
270
|
+
if (report === undefined)
|
|
271
|
+
return textResult(NO_DISPATCH);
|
|
272
|
+
return textResult(`settled: true\n\n${report}`);
|
|
273
|
+
}
|
|
274
|
+
const waited = await waitForSettle(deps, startId, seconds * 1000);
|
|
275
|
+
const report = deps.runtime.reportText(startId);
|
|
276
|
+
if (waited === 'settled' && report !== undefined) {
|
|
277
|
+
return textResult(`settled: true\n\n${report}`);
|
|
278
|
+
}
|
|
279
|
+
const inspection = deps.runtime.inspect();
|
|
280
|
+
const counts = inspection?.counts;
|
|
281
|
+
const state = counts === undefined
|
|
282
|
+
? 'the dispatch is no longer live'
|
|
283
|
+
: `${counts.running} running, ${counts.queued} waiting, ${counts.paused} paused, ` +
|
|
284
|
+
`${counts.done} done, ${counts.failed} failed`;
|
|
285
|
+
const why = waited === 'user_message'
|
|
286
|
+
? 'stopped waiting: the user sent you a message. Answer it first; the report will arrive on its own.'
|
|
287
|
+
: `still live after ${seconds}s; ${state}. Do not wait again - answer the user, or use team_status.`;
|
|
288
|
+
return textResult(`settled: false\n${why}`);
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Poll until the dispatch leaves the live state, the budget elapses, or the user
|
|
294
|
+
* is owed an answer (I-DD2).
|
|
295
|
+
*
|
|
296
|
+
* POLLING IS THE DESIGN, not a shortcut: "did the user type something?" has no
|
|
297
|
+
* subscription point on the controller, and `TEAM_LIMITS.collectPollMs` (250 ms)
|
|
298
|
+
* costs nothing measurable in a tool the model is expected to use rarely.
|
|
299
|
+
*/
|
|
300
|
+
function waitForSettle(deps, dispatchId, budgetMs) {
|
|
301
|
+
return new Promise((resolve) => {
|
|
302
|
+
const startedAt = Date.now();
|
|
303
|
+
const tick = () => {
|
|
304
|
+
if (deps.hasPendingUserInput()) {
|
|
305
|
+
resolve('user_message');
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (deps.runtime.live() === null || deps.runtime.currentDispatchId() !== dispatchId) {
|
|
309
|
+
resolve('settled');
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (Date.now() - startedAt >= budgetMs) {
|
|
313
|
+
resolve('timeout');
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const timer = setTimeout(tick, TEAM_LIMITS.collectPollMs);
|
|
317
|
+
timer.unref?.();
|
|
318
|
+
};
|
|
319
|
+
tick();
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
/** The seven tools, in the order the prompt block lists them. */
|
|
323
|
+
export function createConsoleTools(deps) {
|
|
324
|
+
return [
|
|
325
|
+
makeTeamStatusTool(deps),
|
|
326
|
+
makeTeamMessageTool(deps),
|
|
327
|
+
makeTeamPauseTool(deps),
|
|
328
|
+
makeTeamResumeTool(deps),
|
|
329
|
+
makeTeamStopTool(deps),
|
|
330
|
+
makeTeamSpawnTool(deps),
|
|
331
|
+
makeTeamCollectTool(deps),
|
|
332
|
+
];
|
|
333
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `console-view.ts` - how the lead console renders a dispatch as TEXT
|
|
3
|
+
* (team-detached-dispatch section 5.2, "one question, one formatter").
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY: `src/team/**` is inside `glyphs.test.ts`'s static scan.
|
|
6
|
+
*
|
|
7
|
+
* PURE: it takes the runtime's `DispatchInspection` and returns a string. Both
|
|
8
|
+
* `team_status` (a model-facing tool result), `/team status` (a user-facing
|
|
9
|
+
* command result) and the desktop control surface read THIS file, which is what
|
|
10
|
+
* keeps the three from describing the same dispatch in three different ways - the
|
|
11
|
+
* `childStatus` rule of the UI, applied to text.
|
|
12
|
+
*
|
|
13
|
+
* EVERY BLOCK IS BYTE-BOUNDED at `TEAM_LIMITS.statusMaxBytes`: a status read is
|
|
14
|
+
* paid for on every poll the model chooses to make, and an unbounded roster with
|
|
15
|
+
* ten children each carrying a 6 000-byte summary is a context leak with a
|
|
16
|
+
* helpful name.
|
|
17
|
+
*/
|
|
18
|
+
import type { DispatchInspection } from './runtime.js';
|
|
19
|
+
/**
|
|
20
|
+
* The host-facing control contract (team-detached-dispatch section 7.3).
|
|
21
|
+
*
|
|
22
|
+
* DEFINED HERE, IN THE PURE FILE, and not in `host/team-control.ts`, because the
|
|
23
|
+
* controller needs the request type too and `host -> agent -> host` would be a
|
|
24
|
+
* cycle. Nothing here knows what a controller is: it is a request shape and a
|
|
25
|
+
* view shape, which is exactly what a desktop button sends and renders.
|
|
26
|
+
*/
|
|
27
|
+
export type TeamControlRequest = {
|
|
28
|
+
action: 'message';
|
|
29
|
+
to: string;
|
|
30
|
+
body: string;
|
|
31
|
+
interrupt?: boolean;
|
|
32
|
+
} | {
|
|
33
|
+
action: 'pause';
|
|
34
|
+
label: string;
|
|
35
|
+
reason?: string;
|
|
36
|
+
} | {
|
|
37
|
+
action: 'resume';
|
|
38
|
+
label: string;
|
|
39
|
+
message?: string;
|
|
40
|
+
} | {
|
|
41
|
+
action: 'stop';
|
|
42
|
+
label: string;
|
|
43
|
+
reason?: string;
|
|
44
|
+
} | {
|
|
45
|
+
action: 'spawn';
|
|
46
|
+
brief: string;
|
|
47
|
+
count: number;
|
|
48
|
+
};
|
|
49
|
+
/** `12m04s` / `41s` - one duration format, the one the panel already uses. */
|
|
50
|
+
export declare function formatElapsed(ms: number): string;
|
|
51
|
+
/**
|
|
52
|
+
* `team_status`: conclusion first, detail after (section 5.2.2).
|
|
53
|
+
*
|
|
54
|
+
* The four blocks are, in order: the header line (which answers "is anything
|
|
55
|
+
* happening, how long, and will anything stop it"), the roster, the mail and
|
|
56
|
+
* control counters, and optionally the settled summaries.
|
|
57
|
+
*/
|
|
58
|
+
export declare function renderTeamStatus(inspection: DispatchInspection, options?: {
|
|
59
|
+
labels?: string[];
|
|
60
|
+
includeSummary?: boolean;
|
|
61
|
+
}): string;
|
|
62
|
+
/**
|
|
63
|
+
* The `/team stop`-shaped answer: what happened, to whom, and what is still alive.
|
|
64
|
+
*
|
|
65
|
+
* Non-error on purpose: a control action that found nothing to do ("that child
|
|
66
|
+
* had already finished") is information, and an `errorResult` would invite a
|
|
67
|
+
* retry of an operation that is already complete.
|
|
68
|
+
*/
|
|
69
|
+
export declare function renderStopResult(stopped: string[], live: string[], options?: {
|
|
70
|
+
unknownLabel?: string;
|
|
71
|
+
}): string;
|
|
72
|
+
/**
|
|
73
|
+
* The `team_pause` answer, whose whole job is to be HONEST about cooperative
|
|
74
|
+
* pausing (section 5.2.4's table, in words).
|
|
75
|
+
*/
|
|
76
|
+
export declare function renderPauseResult(label: string, effect: 'paused' | 'deferred' | 'finished', by: 'lead' | 'user' | 'supervisor'): string;
|
|
77
|
+
/**
|
|
78
|
+
* The `team_message` / `/team send` answer.
|
|
79
|
+
*
|
|
80
|
+
* ONE AUTHOR FOR BOTH SURFACES (section 5.8's last rule): the lead's tool result and
|
|
81
|
+
* the user's command report the same facts in the same words, so a user who saw the
|
|
82
|
+
* model send a message reads the identical receipt when they send one themselves.
|
|
83
|
+
*/
|
|
84
|
+
export declare function renderSendResult(delivered: string[], remaining: number): string;
|
|
85
|
+
/** The `team_resume` / `/team resume` answer. */
|
|
86
|
+
export declare function renderResumeResult(label: string, effect: 'resumed' | 'was-running', withMessage: boolean): string;
|
|
87
|
+
/** The `team_spawn` / `/team spawn` answer, truncation included (AC-9). */
|
|
88
|
+
export declare function renderSpawnResult(added: string[], dropped: number, requested: number): string;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `console-view.ts` - how the lead console renders a dispatch as TEXT
|
|
3
|
+
* (team-detached-dispatch section 5.2, "one question, one formatter").
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY: `src/team/**` is inside `glyphs.test.ts`'s static scan.
|
|
6
|
+
*
|
|
7
|
+
* PURE: it takes the runtime's `DispatchInspection` and returns a string. Both
|
|
8
|
+
* `team_status` (a model-facing tool result), `/team status` (a user-facing
|
|
9
|
+
* command result) and the desktop control surface read THIS file, which is what
|
|
10
|
+
* keeps the three from describing the same dispatch in three different ways - the
|
|
11
|
+
* `childStatus` rule of the UI, applied to text.
|
|
12
|
+
*
|
|
13
|
+
* EVERY BLOCK IS BYTE-BOUNDED at `TEAM_LIMITS.statusMaxBytes`: a status read is
|
|
14
|
+
* paid for on every poll the model chooses to make, and an unbounded roster with
|
|
15
|
+
* ten children each carrying a 6 000-byte summary is a context leak with a
|
|
16
|
+
* helpful name.
|
|
17
|
+
*/
|
|
18
|
+
import { TEAM_LIMITS } from '@aragon-agent/tui/model/team/limits';
|
|
19
|
+
import { truncateBytes } from './report.js';
|
|
20
|
+
/** `12m04s` / `41s` - one duration format, the one the panel already uses. */
|
|
21
|
+
export function formatElapsed(ms) {
|
|
22
|
+
const totalSeconds = Math.max(0, Math.round(ms / 1000));
|
|
23
|
+
const hours = Math.floor(totalSeconds / 3600);
|
|
24
|
+
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
25
|
+
const seconds = totalSeconds % 60;
|
|
26
|
+
if (hours > 0)
|
|
27
|
+
return `${hours}h${String(minutes).padStart(2, '0')}m`;
|
|
28
|
+
if (minutes > 0)
|
|
29
|
+
return `${minutes}m${String(seconds).padStart(2, '0')}s`;
|
|
30
|
+
return `${seconds}s`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The `ceiling:` column (spec REV-02).
|
|
34
|
+
*
|
|
35
|
+
* `none` is NOT an absence of information - it is the fact that nothing will stop
|
|
36
|
+
* this dispatch on a timer, and it has to be stated because detaching removed the
|
|
37
|
+
* one thing that used to imply it (a pinned turn). Users read this line and know
|
|
38
|
+
* whether they need to end the dispatch themselves.
|
|
39
|
+
*/
|
|
40
|
+
function ceilingText(inspection) {
|
|
41
|
+
if (inspection.ceilingMs <= 0)
|
|
42
|
+
return 'none';
|
|
43
|
+
const left = inspection.ceilingMs - inspection.elapsedMs;
|
|
44
|
+
return left >= 0
|
|
45
|
+
? `${formatElapsed(left)} left (dispatchTimeoutMs)`
|
|
46
|
+
: `exceeded by ${formatElapsed(-left)}`;
|
|
47
|
+
}
|
|
48
|
+
/** One roster row: phase first, then the facts that explain it. */
|
|
49
|
+
function childLine(child) {
|
|
50
|
+
const facts = [formatElapsed(child.elapsedMs)];
|
|
51
|
+
const used = `${child.turns} turns / ${child.toolCalls} tools`;
|
|
52
|
+
if (child.phase === 'paused') {
|
|
53
|
+
// The hold is the most interesting fact about this row, so it goes first and
|
|
54
|
+
// it names WHO holds it - "paused" alone reads as a system state, and the
|
|
55
|
+
// difference between the lead and the user is the difference between an
|
|
56
|
+
// answer and an explanation.
|
|
57
|
+
const by = child.pausedBy === undefined ? '' : ` by ${child.pausedBy}`;
|
|
58
|
+
facts.unshift(`paused${by} ${formatElapsed(child.pausedMs ?? 0)}`);
|
|
59
|
+
}
|
|
60
|
+
facts.push(used);
|
|
61
|
+
if (child.lastTool !== undefined)
|
|
62
|
+
facts.push(`last: ${child.lastTool}`);
|
|
63
|
+
if (child.error !== undefined)
|
|
64
|
+
facts.push(`error: ${child.error.split('\n')[0]}`);
|
|
65
|
+
return ` ${child.label} ${child.phase} ${facts.join(' ')}`;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* `team_status`: conclusion first, detail after (section 5.2.2).
|
|
69
|
+
*
|
|
70
|
+
* The four blocks are, in order: the header line (which answers "is anything
|
|
71
|
+
* happening, how long, and will anything stop it"), the roster, the mail and
|
|
72
|
+
* control counters, and optionally the settled summaries.
|
|
73
|
+
*/
|
|
74
|
+
export function renderTeamStatus(inspection, options = {}) {
|
|
75
|
+
const { counts } = inspection;
|
|
76
|
+
const head = `dispatch ${inspection.dispatchId} ${inspection.live ? 'live' : 'settled'} ` +
|
|
77
|
+
`${formatElapsed(inspection.elapsedMs)} ceiling: ${ceilingText(inspection)} ` +
|
|
78
|
+
`requested ${inspection.requested} running ${counts.running} waiting ${counts.queued} ` +
|
|
79
|
+
`paused ${counts.paused} done ${counts.done} failed ${counts.failed}` +
|
|
80
|
+
(counts.aborted > 0 ? ` aborted ${counts.aborted}` : '');
|
|
81
|
+
const wanted = options.labels?.map((label) => label.trim().toLowerCase());
|
|
82
|
+
const rows = inspection.children.filter((child) => wanted === undefined || wanted.includes(child.label.toLowerCase()));
|
|
83
|
+
const roster = rows.map((child) => childLine(child));
|
|
84
|
+
const mailFrom = new Map();
|
|
85
|
+
for (const message of inspection.mail) {
|
|
86
|
+
mailFrom.set(message.from, (mailFrom.get(message.from) ?? 0) + 1);
|
|
87
|
+
}
|
|
88
|
+
const mailDetail = [...mailFrom.entries()].map(([from, n]) => `${from} x${n}`).join(', ');
|
|
89
|
+
const controls = new Map();
|
|
90
|
+
for (const record of inspection.controls) {
|
|
91
|
+
controls.set(record.action, (controls.get(record.action) ?? 0) + 1);
|
|
92
|
+
}
|
|
93
|
+
const controlDetail = [...controls.entries()].map(([action, n]) => `${n} ${action}`).join(', ');
|
|
94
|
+
const footer = `mail: ${inspection.mail.length} from children` +
|
|
95
|
+
(mailDetail.length > 0 ? ` (${mailDetail})` : '') +
|
|
96
|
+
` interventions: ${inspection.controls.length}` +
|
|
97
|
+
(controlDetail.length > 0 ? ` (${controlDetail})` : '');
|
|
98
|
+
const parts = [head, ...roster, footer];
|
|
99
|
+
if (options.includeSummary === true) {
|
|
100
|
+
for (const child of rows) {
|
|
101
|
+
if (child.summary === undefined || child.summary.length === 0)
|
|
102
|
+
continue;
|
|
103
|
+
parts.push('');
|
|
104
|
+
parts.push(`${child.label} summary:`);
|
|
105
|
+
parts.push(truncateBytes(child.summary, TEAM_LIMITS.statusMaxBytes / 4));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return truncateBytes(parts.join('\n'), TEAM_LIMITS.statusMaxBytes);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The `/team stop`-shaped answer: what happened, to whom, and what is still alive.
|
|
112
|
+
*
|
|
113
|
+
* Non-error on purpose: a control action that found nothing to do ("that child
|
|
114
|
+
* had already finished") is information, and an `errorResult` would invite a
|
|
115
|
+
* retry of an operation that is already complete.
|
|
116
|
+
*/
|
|
117
|
+
export function renderStopResult(stopped, live, options = {}) {
|
|
118
|
+
if (stopped.length === 0 && live.length === 0) {
|
|
119
|
+
return 'Nothing to stop: no dispatch is running.';
|
|
120
|
+
}
|
|
121
|
+
if (options.unknownLabel !== undefined) {
|
|
122
|
+
const names = live.length === 0 ? 'no subagents are left' : live.join(', ');
|
|
123
|
+
return `No subagent named "${options.unknownLabel}". Running: ${names}.`;
|
|
124
|
+
}
|
|
125
|
+
const head = stopped.length === 0
|
|
126
|
+
? 'Nothing was stopped.'
|
|
127
|
+
: `Stopped ${stopped.join(', ')}.`;
|
|
128
|
+
return live.length === 0 ? `${head} No subagents are left running.` : `${head} Still running: ${live.join(', ')}.`;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The `team_pause` answer, whose whole job is to be HONEST about cooperative
|
|
132
|
+
* pausing (section 5.2.4's table, in words).
|
|
133
|
+
*/
|
|
134
|
+
export function renderPauseResult(label, effect, by) {
|
|
135
|
+
if (effect === 'finished') {
|
|
136
|
+
return `${label} has already finished, so there is nothing to hold. Read its summary in team_status.`;
|
|
137
|
+
}
|
|
138
|
+
const tail = ' Pausing does not postpone the dispatch ceiling (team.dispatchTimeoutMs), though it does ' +
|
|
139
|
+
'credit the held time back to the subagent\'s own timeout. Nothing resumes it automatically: ' +
|
|
140
|
+
'use team_resume or team_stop.';
|
|
141
|
+
if (effect === 'paused') {
|
|
142
|
+
return `${label} is held by the ${by}. It is between tool calls now, so its next tool will not start.${tail}`;
|
|
143
|
+
}
|
|
144
|
+
// NOT "frozen". The child is mid-tool or mid-sentence; nothing can stop that
|
|
145
|
+
// without killing it, and claiming otherwise is the promise this design refuses.
|
|
146
|
+
return (`${label} will stop at its next tool boundary - it is running a tool or writing text right ` +
|
|
147
|
+
`now, so this is a deferred hold, not an instant freeze.${tail}`);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* The `team_message` / `/team send` answer.
|
|
151
|
+
*
|
|
152
|
+
* ONE AUTHOR FOR BOTH SURFACES (section 5.8's last rule): the lead's tool result and
|
|
153
|
+
* the user's command report the same facts in the same words, so a user who saw the
|
|
154
|
+
* model send a message reads the identical receipt when they send one themselves.
|
|
155
|
+
*/
|
|
156
|
+
export function renderSendResult(delivered, remaining) {
|
|
157
|
+
return (`Delivered to ${delivered.join(', ')}. ${remaining} of ` +
|
|
158
|
+
`${TEAM_LIMITS.messagesFromLeadPerDispatch} messages left for this dispatch.`);
|
|
159
|
+
}
|
|
160
|
+
/** The `team_resume` / `/team resume` answer. */
|
|
161
|
+
export function renderResumeResult(label, effect, withMessage) {
|
|
162
|
+
const tail = withMessage ? ' with your message' : '';
|
|
163
|
+
return effect === 'resumed'
|
|
164
|
+
? `${label} resumed${tail}.`
|
|
165
|
+
: `${label} was not paused; it is still running${withMessage ? ' and has your message' : ''}.`;
|
|
166
|
+
}
|
|
167
|
+
/** The `team_spawn` / `/team spawn` answer, truncation included (AC-9). */
|
|
168
|
+
export function renderSpawnResult(added, dropped, requested) {
|
|
169
|
+
const truncation = dropped > 0
|
|
170
|
+
? ` ${dropped} of ${requested} were dropped: the dispatch ceiling caps the team.`
|
|
171
|
+
: '';
|
|
172
|
+
return `Added ${added.join(', ')} to the running dispatch.${truncation}`;
|
|
173
|
+
}
|
|
@@ -48,7 +48,8 @@ export type TeamIntent = {
|
|
|
48
48
|
} | {
|
|
49
49
|
kind: 'off';
|
|
50
50
|
}
|
|
51
|
-
/** `count` only for `/team on <n>` (team-mode-toggle-keys D-12);
|
|
51
|
+
/** `count` only for `/team on <n>` (team-mode-toggle-keys D-12);
|
|
52
|
+
* absent = keep the current one. */
|
|
52
53
|
| {
|
|
53
54
|
kind: 'on';
|
|
54
55
|
count?: number;
|
|
@@ -61,6 +62,65 @@ export type TeamIntent = {
|
|
|
61
62
|
error: 'count' | 'conflict' | 'flag' | 'brief';
|
|
62
63
|
token?: string;
|
|
63
64
|
};
|
|
65
|
+
/**
|
|
66
|
+
* A control verb's payload (team-detached-dispatch section 5.8).
|
|
67
|
+
*
|
|
68
|
+
* SEPARATE FROM `TeamIntent` ON PURPOSE: an intent is "what should the session do
|
|
69
|
+
* with this line", a control request is "what should happen to the dispatch that is
|
|
70
|
+
* running". Keeping them apart means the six verbs cannot accidentally take the
|
|
71
|
+
* brief path when a dispatch is absent - they answer "none is running" instead of
|
|
72
|
+
* dispatching a team literally named "stop all".
|
|
73
|
+
*/
|
|
74
|
+
export type TeamControlIntent = {
|
|
75
|
+
kind: 'control';
|
|
76
|
+
action: 'wait';
|
|
77
|
+
seconds?: number;
|
|
78
|
+
} | {
|
|
79
|
+
kind: 'control';
|
|
80
|
+
action: 'send';
|
|
81
|
+
target: string;
|
|
82
|
+
text: string;
|
|
83
|
+
} | {
|
|
84
|
+
kind: 'control';
|
|
85
|
+
action: 'pause';
|
|
86
|
+
label: string;
|
|
87
|
+
reason: string;
|
|
88
|
+
} | {
|
|
89
|
+
kind: 'control';
|
|
90
|
+
action: 'resume';
|
|
91
|
+
label: string;
|
|
92
|
+
message: string;
|
|
93
|
+
} | {
|
|
94
|
+
kind: 'control';
|
|
95
|
+
action: 'stop';
|
|
96
|
+
target: string;
|
|
97
|
+
reason: string;
|
|
98
|
+
} | {
|
|
99
|
+
kind: 'control';
|
|
100
|
+
action: 'spawn';
|
|
101
|
+
count: number;
|
|
102
|
+
brief: string;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Parse a line as a control verb, or `null` when it is (still) a brief.
|
|
106
|
+
*
|
|
107
|
+
* THE AMBIGUITY RULE IS THE WHOLE FUNCTION (REV-14 / AC-24). Every one of these
|
|
108
|
+
* verbs is a perfectly good English word, and `/team stop the leak hunt` dispatches
|
|
109
|
+
* a team TODAY. Turning that sentence into "stop the team and never work on the
|
|
110
|
+
* leak hunt" would be a silent breaking change, so a verb only becomes a control
|
|
111
|
+
* when the token after it PROVES the intent:
|
|
112
|
+
*
|
|
113
|
+
* - the second token is `all`, or a label that exists in the LIVE dispatch;
|
|
114
|
+
* - or, for `wait` / `spawn`, it is a number (and for `wait`, absent is fine).
|
|
115
|
+
*
|
|
116
|
+
* Everything else falls through to the brief grammar, unchanged - which is why
|
|
117
|
+
* `/team stop the leak hunt` still dispatches, and `/team "stop all"` still works
|
|
118
|
+
* through the existing quote escape (checked by the caller BEFORE this function).
|
|
119
|
+
*
|
|
120
|
+
* `liveLabels` is passed in rather than read from the controller here: this is a
|
|
121
|
+
* pure parser, and a parser that reads global state is a parser nobody can test.
|
|
122
|
+
*/
|
|
123
|
+
export declare function readTeamControlIntent(raw: string, liveLabels: readonly string[]): TeamControlIntent | null;
|
|
64
124
|
/**
|
|
65
125
|
* Session-level forced team mode: the state `/team` writes and `<forced_team_mode>`
|
|
66
126
|
* plus the status chip read (team-command-forced-dispatch §3.5 / §6.1).
|