@aragon-agent/cli 0.6.57 → 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 +71 -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/task-runner.js +4 -1
- package/dist/gene/curator/tools-verify.js +17 -5
- package/dist/gene/curator/validate/evidence-tokens.js +97 -18
- package/dist/gene/curator/validate/knowledge.d.ts +5 -0
- package/dist/gene/curator/validate/knowledge.js +57 -13
- package/dist/gene/curator/validate/types.d.ts +6 -1
- package/dist/gene/learn/learn-prompt.d.ts +10 -1
- package/dist/gene/learn/learn-prompt.js +11 -2
- 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,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).
|
package/dist/team/forced-mode.js
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
* the first `-n=6` someone tried.
|
|
29
29
|
*/
|
|
30
30
|
import { parseSubagentArgs } from './forced-dispatch.js';
|
|
31
|
+
import { TEAM_LIMITS } from '@aragon-agent/tui/model/team/limits';
|
|
31
32
|
/**
|
|
32
33
|
* The default count when the user names none (D-7).
|
|
33
34
|
*
|
|
@@ -37,6 +38,80 @@ import { parseSubagentArgs } from './forced-dispatch.js';
|
|
|
37
38
|
* user who wants the widest fan-out knows which flag to add.
|
|
38
39
|
*/
|
|
39
40
|
export const DEFAULT_FORCED_COUNT = 4;
|
|
41
|
+
/**
|
|
42
|
+
* Parse a line as a control verb, or `null` when it is (still) a brief.
|
|
43
|
+
*
|
|
44
|
+
* THE AMBIGUITY RULE IS THE WHOLE FUNCTION (REV-14 / AC-24). Every one of these
|
|
45
|
+
* verbs is a perfectly good English word, and `/team stop the leak hunt` dispatches
|
|
46
|
+
* a team TODAY. Turning that sentence into "stop the team and never work on the
|
|
47
|
+
* leak hunt" would be a silent breaking change, so a verb only becomes a control
|
|
48
|
+
* when the token after it PROVES the intent:
|
|
49
|
+
*
|
|
50
|
+
* - the second token is `all`, or a label that exists in the LIVE dispatch;
|
|
51
|
+
* - or, for `wait` / `spawn`, it is a number (and for `wait`, absent is fine).
|
|
52
|
+
*
|
|
53
|
+
* Everything else falls through to the brief grammar, unchanged - which is why
|
|
54
|
+
* `/team stop the leak hunt` still dispatches, and `/team "stop all"` still works
|
|
55
|
+
* through the existing quote escape (checked by the caller BEFORE this function).
|
|
56
|
+
*
|
|
57
|
+
* `liveLabels` is passed in rather than read from the controller here: this is a
|
|
58
|
+
* pure parser, and a parser that reads global state is a parser nobody can test.
|
|
59
|
+
*/
|
|
60
|
+
export function readTeamControlIntent(raw, liveLabels) {
|
|
61
|
+
const trimmed = raw.trim();
|
|
62
|
+
if (trimmed.length === 0)
|
|
63
|
+
return null;
|
|
64
|
+
const tokens = trimmed.split(/\s+/);
|
|
65
|
+
const verb = tokens[0].toLowerCase();
|
|
66
|
+
const rest = tokens.slice(1);
|
|
67
|
+
const isTarget = (token) => token.toLowerCase() === 'all' || liveLabels.some((label) => label.toLowerCase() === token.toLowerCase());
|
|
68
|
+
if (verb === 'wait') {
|
|
69
|
+
if (rest.length === 0)
|
|
70
|
+
return { kind: 'control', action: 'wait' };
|
|
71
|
+
if (rest.length === 1 && /^[0-9]+$/.test(rest[0])) {
|
|
72
|
+
return { kind: 'control', action: 'wait', seconds: Math.min(Number(rest[0]), 1_000_000) };
|
|
73
|
+
}
|
|
74
|
+
// NO DIGITS -> A BRIEF. `/team wait for the build` is a request, not a pause.
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
if (verb === 'spawn') {
|
|
78
|
+
const count = rest[0];
|
|
79
|
+
if (count === undefined || !/^[1-9][0-9]*$/.test(count))
|
|
80
|
+
return null;
|
|
81
|
+
const brief = rest.slice(1).join(' ').trim().slice(0, TEAM_LIMITS.forcedBriefChars);
|
|
82
|
+
if (brief.length === 0)
|
|
83
|
+
return null;
|
|
84
|
+
return { kind: 'control', action: 'spawn', count: Number(count), brief };
|
|
85
|
+
}
|
|
86
|
+
if (verb === 'send') {
|
|
87
|
+
const target = rest[0];
|
|
88
|
+
if (target === undefined || !isTarget(target))
|
|
89
|
+
return null;
|
|
90
|
+
const text = rest.slice(1).join(' ').trim().slice(0, TEAM_LIMITS.bodyChars);
|
|
91
|
+
if (text.length === 0)
|
|
92
|
+
return null;
|
|
93
|
+
return { kind: 'control', action: 'send', target, text };
|
|
94
|
+
}
|
|
95
|
+
if (verb === 'pause' || verb === 'resume' || verb === 'stop') {
|
|
96
|
+
const target = rest[0];
|
|
97
|
+
if (target === undefined)
|
|
98
|
+
return null;
|
|
99
|
+
// `stop all` and `pause <live label>` only; anything else stays a brief.
|
|
100
|
+
if (!isTarget(target))
|
|
101
|
+
return null;
|
|
102
|
+
// `pause all` / `resume all` mean nothing (holding every child is `stop`), so
|
|
103
|
+
// they are refused as briefs rather than silently widening the grammar.
|
|
104
|
+
if (verb !== 'stop' && target.toLowerCase() === 'all')
|
|
105
|
+
return null;
|
|
106
|
+
const words = rest.slice(1).join(' ').trim();
|
|
107
|
+
if (verb === 'stop')
|
|
108
|
+
return { kind: 'control', action: 'stop', target, reason: words };
|
|
109
|
+
if (verb === 'pause')
|
|
110
|
+
return { kind: 'control', action: 'pause', label: target, reason: words };
|
|
111
|
+
return { kind: 'control', action: 'resume', label: target, message: words };
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
40
115
|
/** The three words that command the session rather than describe work. */
|
|
41
116
|
const CONTROL_WORDS = new Set(['on', 'off', 'status']);
|
|
42
117
|
/**
|
package/dist/team/normalize.d.ts
CHANGED
|
@@ -45,6 +45,20 @@ export interface NormalizedSpecs {
|
|
|
45
45
|
* this function stays a pure transformation.
|
|
46
46
|
*/
|
|
47
47
|
export declare function toSlug(raw: unknown): string;
|
|
48
|
+
/**
|
|
49
|
+
* Make `label` unique within the dispatch, case-insensitively, by appending
|
|
50
|
+
* `-2`, `-3`, ...
|
|
51
|
+
*
|
|
52
|
+
* EXPORTED for `team_spawn` (team-detached-dispatch section 5.2.6): a child added
|
|
53
|
+
* mid-dispatch must not collide with a live one, and `normalizeSubagentSpecs` can
|
|
54
|
+
* only dedupe inside the batch it is given. One suffixer, two callers - a copy
|
|
55
|
+
* here would drift the first time either side gained a rule.
|
|
56
|
+
*
|
|
57
|
+
* Two agents the user cannot tell apart in the panel is worse than an ugly label,
|
|
58
|
+
* and the bus addresses children BY label: a duplicate makes `team_send`
|
|
59
|
+
* ambiguous, which is a correctness problem rather than a cosmetic one.
|
|
60
|
+
*/
|
|
61
|
+
export declare function dedupeLabel(label: string, taken: Set<string>): string;
|
|
48
62
|
/**
|
|
49
63
|
* Repair and bound a raw `subagents` array.
|
|
50
64
|
*
|
|
@@ -57,4 +71,21 @@ export declare function toSlug(raw: unknown): string;
|
|
|
57
71
|
* `TEAM_LIMITS.hardMaxSubagents` here so a hand-edited config file
|
|
58
72
|
* cannot raise the requirement's ceiling (R-g).
|
|
59
73
|
*/
|
|
74
|
+
/**
|
|
75
|
+
* Turn ONE sentence plus a count into that many subagent specs, for
|
|
76
|
+
* `/team spawn <n> <brief>` and the desktop control surface
|
|
77
|
+
* (team-detached-dispatch section 5.8).
|
|
78
|
+
*
|
|
79
|
+
* WHY A SHARED HELPER RATHER THAN ELEVEN LINES IN EACH CALLER. The split is a
|
|
80
|
+
* POLICY ("who owns which part"), and the package already has one: a brief fanned
|
|
81
|
+
* out over N children without any of them being told which slice is theirs
|
|
82
|
+
* produces N agents reading the same repository. So every slice gets a distinct
|
|
83
|
+
* ordinal and an explicit instruction to stay inside its own part, and the caller
|
|
84
|
+
* keeps the count and the clamp this file is responsible for.
|
|
85
|
+
*
|
|
86
|
+
* Deterministic, no model call, never throws. `count` is clamped to the structural
|
|
87
|
+
* ceiling for the same reason `normalizeSubagentSpecs` clamps: a hand-typed
|
|
88
|
+
* `/team spawn 40 ...` must not be able to exceed `hardMaxSubagents`.
|
|
89
|
+
*/
|
|
90
|
+
export declare function splitBriefIntoSpecs(brief: string, count: number): SubagentSpec[];
|
|
60
91
|
export declare function normalizeSubagentSpecs(raw: unknown, max: number): NormalizedSpecs;
|
package/dist/team/normalize.js
CHANGED
|
@@ -66,12 +66,16 @@ function slugLabel(raw, index) {
|
|
|
66
66
|
* Make `label` unique within the dispatch, case-insensitively, by appending
|
|
67
67
|
* `-2`, `-3`, ...
|
|
68
68
|
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
69
|
+
* EXPORTED for `team_spawn` (team-detached-dispatch section 5.2.6): a child added
|
|
70
|
+
* mid-dispatch must not collide with a live one, and `normalizeSubagentSpecs` can
|
|
71
|
+
* only dedupe inside the batch it is given. One suffixer, two callers - a copy
|
|
72
|
+
* here would drift the first time either side gained a rule.
|
|
73
|
+
*
|
|
74
|
+
* Two agents the user cannot tell apart in the panel is worse than an ugly label,
|
|
75
|
+
* and the bus addresses children BY label: a duplicate makes `team_send`
|
|
76
|
+
* ambiguous, which is a correctness problem rather than a cosmetic one.
|
|
73
77
|
*/
|
|
74
|
-
function dedupeLabel(label, taken) {
|
|
78
|
+
export function dedupeLabel(label, taken) {
|
|
75
79
|
const base = label.toLowerCase();
|
|
76
80
|
if (!taken.has(base)) {
|
|
77
81
|
taken.add(base);
|
|
@@ -100,6 +104,46 @@ function dedupeLabel(label, taken) {
|
|
|
100
104
|
* `TEAM_LIMITS.hardMaxSubagents` here so a hand-edited config file
|
|
101
105
|
* cannot raise the requirement's ceiling (R-g).
|
|
102
106
|
*/
|
|
107
|
+
/**
|
|
108
|
+
* Turn ONE sentence plus a count into that many subagent specs, for
|
|
109
|
+
* `/team spawn <n> <brief>` and the desktop control surface
|
|
110
|
+
* (team-detached-dispatch section 5.8).
|
|
111
|
+
*
|
|
112
|
+
* WHY A SHARED HELPER RATHER THAN ELEVEN LINES IN EACH CALLER. The split is a
|
|
113
|
+
* POLICY ("who owns which part"), and the package already has one: a brief fanned
|
|
114
|
+
* out over N children without any of them being told which slice is theirs
|
|
115
|
+
* produces N agents reading the same repository. So every slice gets a distinct
|
|
116
|
+
* ordinal and an explicit instruction to stay inside its own part, and the caller
|
|
117
|
+
* keeps the count and the clamp this file is responsible for.
|
|
118
|
+
*
|
|
119
|
+
* Deterministic, no model call, never throws. `count` is clamped to the structural
|
|
120
|
+
* ceiling for the same reason `normalizeSubagentSpecs` clamps: a hand-typed
|
|
121
|
+
* `/team spawn 40 ...` must not be able to exceed `hardMaxSubagents`.
|
|
122
|
+
*/
|
|
123
|
+
export function splitBriefIntoSpecs(brief, count) {
|
|
124
|
+
const text = brief.trim();
|
|
125
|
+
if (text.length === 0)
|
|
126
|
+
return [];
|
|
127
|
+
const wanted = Math.max(1, Math.min(Math.floor(count) || 1, TEAM_LIMITS.hardMaxSubagents));
|
|
128
|
+
const head = text.slice(0, TEAM_LIMITS.descriptionChars);
|
|
129
|
+
const specs = [];
|
|
130
|
+
for (let index = 0; index < wanted; index += 1) {
|
|
131
|
+
const ordinal = index + 1;
|
|
132
|
+
const label = `part-${ordinal}`;
|
|
133
|
+
specs.push({
|
|
134
|
+
label,
|
|
135
|
+
description: `${head} (part ${ordinal} of ${wanted})`.slice(0, TEAM_LIMITS.descriptionChars),
|
|
136
|
+
prompt: `${text}\n\n` +
|
|
137
|
+
`You are part ${ordinal} of ${wanted} working on the request above. Take an ` +
|
|
138
|
+
'independent slice of it, name the files or areas that slice owns in your first ' +
|
|
139
|
+
'sentence, and do not edit anything another part is likely to own - if you need a ' +
|
|
140
|
+
'shared file changed, say so in your report instead of changing it. Your final ' +
|
|
141
|
+
'message is the only thing the lead sees.',
|
|
142
|
+
readOnly: false,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return specs;
|
|
146
|
+
}
|
|
103
147
|
export function normalizeSubagentSpecs(raw, max) {
|
|
104
148
|
if (!Array.isArray(raw))
|
|
105
149
|
return { specs: [], requested: 0 };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TeamNoticeQueue - "a dispatch did something the lead must be told about,
|
|
3
|
+
* exactly once" (team-detached-dispatch section 5.3.1).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY: `src/team/**` is inside `glyphs.test.ts`'s static scan.
|
|
6
|
+
*
|
|
7
|
+
* STRUCTURALLY THE SAME OBJECT AS `proc/notices.ts`, AND DELIBERATELY NOT THE
|
|
8
|
+
* SAME CLASS. Both are idempotent-by-id bounded queues behind three mutually
|
|
9
|
+
* exclusive delivery channels; they differ in every policy that matters. A job
|
|
10
|
+
* notice is "the thing you started has ended"; these are one CHILD settling, the
|
|
11
|
+
* whole DISPATCH settling (carrying the report), and a child writing to the lead.
|
|
12
|
+
* Merging them would put the "never inject while a tool batch is open" rule (job
|
|
13
|
+
* I-5) and the "the settle report must always arrive" rule in one object and let
|
|
14
|
+
* either win.
|
|
15
|
+
*
|
|
16
|
+
* THREE KINDS, THREE LIFETIMES:
|
|
17
|
+
*
|
|
18
|
+
* - `child_settled` is CHATTER. It is dropped the moment the `dispatch_settled`
|
|
19
|
+
* report arrives, because the report already contains every row - five child
|
|
20
|
+
* lines plus a report that repeats them is the duplicate noise this feature
|
|
21
|
+
* would otherwise add to every dispatch.
|
|
22
|
+
* - `dispatch_settled` is THE FACT. Its body is `session.reportText`, generated
|
|
23
|
+
* once by the runtime (spec REV-05), so the notice, `team_collect` and
|
|
24
|
+
* `/team wait` show the same string rather than three renderings of the same
|
|
25
|
+
* outcome.
|
|
26
|
+
* - `lead_mail` is a REMINDER, bounded by `leadNoticesPerDispatch`; the full mail
|
|
27
|
+
* is always in the report as well, so losing one of these loses nothing.
|
|
28
|
+
*/
|
|
29
|
+
export type TeamNotice = {
|
|
30
|
+
kind: 'child_settled';
|
|
31
|
+
/** `${dispatchId}:${label}:${phase}` - a child settles once. */
|
|
32
|
+
id: string;
|
|
33
|
+
dispatchId: string;
|
|
34
|
+
label: string;
|
|
35
|
+
phase: string;
|
|
36
|
+
elapsedMs: number;
|
|
37
|
+
turns: number;
|
|
38
|
+
toolCalls: number;
|
|
39
|
+
/** First line of the error, when there was one. */
|
|
40
|
+
error?: string;
|
|
41
|
+
at: number;
|
|
42
|
+
} | {
|
|
43
|
+
kind: 'dispatch_settled';
|
|
44
|
+
/** `${dispatchId}:end`. */
|
|
45
|
+
id: string;
|
|
46
|
+
dispatchId: string;
|
|
47
|
+
/** `session.reportText`, verbatim. */
|
|
48
|
+
report: string;
|
|
49
|
+
aborted: boolean;
|
|
50
|
+
at: number;
|
|
51
|
+
} | {
|
|
52
|
+
kind: 'lead_mail';
|
|
53
|
+
/** `${dispatchId}:mail:${at}:${from}`. */
|
|
54
|
+
id: string;
|
|
55
|
+
dispatchId: string;
|
|
56
|
+
from: string;
|
|
57
|
+
subject: string;
|
|
58
|
+
/** Body head, already clamped by the producer. */
|
|
59
|
+
bodyHead: string;
|
|
60
|
+
at: number;
|
|
61
|
+
};
|
|
62
|
+
export declare class TeamNoticeQueue {
|
|
63
|
+
private readonly entries;
|
|
64
|
+
/**
|
|
65
|
+
* `lead_mail` notices already admitted, PER DISPATCH.
|
|
66
|
+
*
|
|
67
|
+
* PER DISPATCH, not per drain: the relay drains at every safe point, so a plain
|
|
68
|
+
* counter that `drain()` reset would have allowed `leadNoticesPerDispatch` mails
|
|
69
|
+
* per DRAIN - an unbounded number for a long dispatch, which is the opposite of
|
|
70
|
+
* what the bound is for.
|
|
71
|
+
*/
|
|
72
|
+
private readonly leadMails;
|
|
73
|
+
/**
|
|
74
|
+
* Same id twice keeps ONE entry. That is what makes the relay's re-queue after a
|
|
75
|
+
* queue wipe idempotent: a notice that was delivered and re-queued can only be
|
|
76
|
+
* rendered again, never duplicated (job I-11's argument, same mechanism).
|
|
77
|
+
*/
|
|
78
|
+
push(notice: TeamNotice): void;
|
|
79
|
+
/** Take everything and reset. The one way a notice leaves this object. */
|
|
80
|
+
drain(): TeamNotice[];
|
|
81
|
+
peek(): TeamNotice[];
|
|
82
|
+
pending(): number;
|
|
83
|
+
clear(): void;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Render the `<team_notices>` block, or `''` when there is nothing to say.
|
|
87
|
+
*
|
|
88
|
+
* EMPTY IN, EMPTY OUT, for the same reason `renderJobNotices` is: an unconditional
|
|
89
|
+
* block would add lines to every tool call in every session.
|
|
90
|
+
*
|
|
91
|
+
* ORDER: the settle report FIRST, then mail, then child lines. The report is the
|
|
92
|
+
* fact; the rest is context for it, and a model that reads only the first two
|
|
93
|
+
* lines of a block should still see the thing that ended.
|
|
94
|
+
*/
|
|
95
|
+
export declare function renderTeamNotices(notices: readonly TeamNotice[]): string;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TeamNoticeQueue - "a dispatch did something the lead must be told about,
|
|
3
|
+
* exactly once" (team-detached-dispatch section 5.3.1).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY: `src/team/**` is inside `glyphs.test.ts`'s static scan.
|
|
6
|
+
*
|
|
7
|
+
* STRUCTURALLY THE SAME OBJECT AS `proc/notices.ts`, AND DELIBERATELY NOT THE
|
|
8
|
+
* SAME CLASS. Both are idempotent-by-id bounded queues behind three mutually
|
|
9
|
+
* exclusive delivery channels; they differ in every policy that matters. A job
|
|
10
|
+
* notice is "the thing you started has ended"; these are one CHILD settling, the
|
|
11
|
+
* whole DISPATCH settling (carrying the report), and a child writing to the lead.
|
|
12
|
+
* Merging them would put the "never inject while a tool batch is open" rule (job
|
|
13
|
+
* I-5) and the "the settle report must always arrive" rule in one object and let
|
|
14
|
+
* either win.
|
|
15
|
+
*
|
|
16
|
+
* THREE KINDS, THREE LIFETIMES:
|
|
17
|
+
*
|
|
18
|
+
* - `child_settled` is CHATTER. It is dropped the moment the `dispatch_settled`
|
|
19
|
+
* report arrives, because the report already contains every row - five child
|
|
20
|
+
* lines plus a report that repeats them is the duplicate noise this feature
|
|
21
|
+
* would otherwise add to every dispatch.
|
|
22
|
+
* - `dispatch_settled` is THE FACT. Its body is `session.reportText`, generated
|
|
23
|
+
* once by the runtime (spec REV-05), so the notice, `team_collect` and
|
|
24
|
+
* `/team wait` show the same string rather than three renderings of the same
|
|
25
|
+
* outcome.
|
|
26
|
+
* - `lead_mail` is a REMINDER, bounded by `leadNoticesPerDispatch`; the full mail
|
|
27
|
+
* is always in the report as well, so losing one of these loses nothing.
|
|
28
|
+
*/
|
|
29
|
+
import { TEAM_LIMITS } from '@aragon-agent/tui/model/team/limits';
|
|
30
|
+
export class TeamNoticeQueue {
|
|
31
|
+
entries = new Map();
|
|
32
|
+
/**
|
|
33
|
+
* `lead_mail` notices already admitted, PER DISPATCH.
|
|
34
|
+
*
|
|
35
|
+
* PER DISPATCH, not per drain: the relay drains at every safe point, so a plain
|
|
36
|
+
* counter that `drain()` reset would have allowed `leadNoticesPerDispatch` mails
|
|
37
|
+
* per DRAIN - an unbounded number for a long dispatch, which is the opposite of
|
|
38
|
+
* what the bound is for.
|
|
39
|
+
*/
|
|
40
|
+
leadMails = new Map();
|
|
41
|
+
/**
|
|
42
|
+
* Same id twice keeps ONE entry. That is what makes the relay's re-queue after a
|
|
43
|
+
* queue wipe idempotent: a notice that was delivered and re-queued can only be
|
|
44
|
+
* rendered again, never duplicated (job I-11's argument, same mechanism).
|
|
45
|
+
*/
|
|
46
|
+
push(notice) {
|
|
47
|
+
if (this.entries.has(notice.id))
|
|
48
|
+
return;
|
|
49
|
+
if (notice.kind === 'lead_mail') {
|
|
50
|
+
const used = this.leadMails.get(notice.dispatchId) ?? 0;
|
|
51
|
+
if (used >= TEAM_LIMITS.leadNoticesPerDispatch)
|
|
52
|
+
return;
|
|
53
|
+
this.leadMails.set(notice.dispatchId, used + 1);
|
|
54
|
+
}
|
|
55
|
+
if (notice.kind === 'dispatch_settled') {
|
|
56
|
+
// THE REPORT REPLACES THE CHILD LINES. Dropping them here rather than in the
|
|
57
|
+
// renderer keeps the queue's own bound honest: what is in the map is what
|
|
58
|
+
// will be delivered.
|
|
59
|
+
for (const [id, held] of [...this.entries]) {
|
|
60
|
+
if (held.dispatchId === notice.dispatchId && held.kind === 'child_settled') {
|
|
61
|
+
this.entries.delete(id);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// The dispatch is over, so its mail allowance goes with it.
|
|
65
|
+
this.leadMails.delete(notice.dispatchId);
|
|
66
|
+
}
|
|
67
|
+
this.entries.set(notice.id, notice);
|
|
68
|
+
}
|
|
69
|
+
/** Take everything and reset. The one way a notice leaves this object. */
|
|
70
|
+
drain() {
|
|
71
|
+
if (this.entries.size === 0)
|
|
72
|
+
return [];
|
|
73
|
+
const out = [...this.entries.values()];
|
|
74
|
+
this.entries.clear();
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
peek() {
|
|
78
|
+
return [...this.entries.values()];
|
|
79
|
+
}
|
|
80
|
+
pending() {
|
|
81
|
+
return this.entries.size;
|
|
82
|
+
}
|
|
83
|
+
clear() {
|
|
84
|
+
this.entries.clear();
|
|
85
|
+
this.leadMails.clear();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Render the `<team_notices>` block, or `''` when there is nothing to say.
|
|
90
|
+
*
|
|
91
|
+
* EMPTY IN, EMPTY OUT, for the same reason `renderJobNotices` is: an unconditional
|
|
92
|
+
* block would add lines to every tool call in every session.
|
|
93
|
+
*
|
|
94
|
+
* ORDER: the settle report FIRST, then mail, then child lines. The report is the
|
|
95
|
+
* fact; the rest is context for it, and a model that reads only the first two
|
|
96
|
+
* lines of a block should still see the thing that ended.
|
|
97
|
+
*/
|
|
98
|
+
export function renderTeamNotices(notices) {
|
|
99
|
+
if (notices.length === 0)
|
|
100
|
+
return '';
|
|
101
|
+
const rank = (notice) => notice.kind === 'dispatch_settled' ? 0 : notice.kind === 'lead_mail' ? 1 : 2;
|
|
102
|
+
const sorted = [...notices].sort((a, b) => rank(a) - rank(b));
|
|
103
|
+
const lines = ['<team_notices>'];
|
|
104
|
+
for (const notice of sorted) {
|
|
105
|
+
if (notice.kind === 'dispatch_settled') {
|
|
106
|
+
lines.push(notice.report);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (notice.kind === 'lead_mail') {
|
|
110
|
+
lines.push(`${notice.from} -> lead: ${notice.subject}`);
|
|
111
|
+
if (notice.bodyHead.length > 0)
|
|
112
|
+
lines.push(` ${notice.bodyHead}`);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const detail = `${notice.label} ${notice.phase} after ${Math.round(notice.elapsedMs / 1000)}s` +
|
|
116
|
+
` (${notice.turns} turns / ${notice.toolCalls} tools)`;
|
|
117
|
+
lines.push(notice.error !== undefined ? `${detail}: ${notice.error}` : detail);
|
|
118
|
+
}
|
|
119
|
+
lines.push('</team_notices>');
|
|
120
|
+
return lines.join('\n');
|
|
121
|
+
}
|