@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,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The prompt-profile STORE: the only place a red team profile touches the disk
|
|
3
|
+
* (redteam-prompt-profile 5.4 / 5.7 / 6.1).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY - `src/redteam/**` is inside `glyphs.test.ts::inScope`.
|
|
6
|
+
*
|
|
7
|
+
* NOTHING HERE THROWS, AND THAT IS THE FEATURE (D-9 / PF-9). Every failure is an issue plus a
|
|
8
|
+
* fallback: a profile is a convenience, so a missing, oversized or unreadable file must leave
|
|
9
|
+
* the mode armed and the user informed. The one case that could take a security posture down
|
|
10
|
+
* with it - an exception escaping into the prompt builder - is the case this file exists to
|
|
11
|
+
* make impossible.
|
|
12
|
+
*
|
|
13
|
+
* TWO ENTRY POINTS, ONE CACHE. `loadProfileFile` is the read path (stat, byte cap, decode,
|
|
14
|
+
* `(mtimeMs, size)` memo); `writeScaffold` is the only write in the whole feature, and it
|
|
15
|
+
* REFUSES TO OVERWRITE a profile the user already has.
|
|
16
|
+
*
|
|
17
|
+
* `builtin` NEVER REACHES THIS FILE (PF-11): the resolver returns before calling in, and the
|
|
18
|
+
* test that proves it injects an `fs` port whose every method throws.
|
|
19
|
+
*/
|
|
20
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync, } from 'node:fs';
|
|
21
|
+
import { join } from 'node:path';
|
|
22
|
+
import process from 'node:process';
|
|
23
|
+
import { getRedTeamProfilesDir } from '../config/app-paths.js';
|
|
24
|
+
import { REDTEAM_PROMPT_LIMITS } from '@aragon-agent/tui/model/redteam/limits';
|
|
25
|
+
import { PROFILE_SLUG_PATTERN } from '@aragon-agent/tui/model/redteam/prompt-file';
|
|
26
|
+
/** The real filesystem, wired explicitly so the port's shape stays small and honest. */
|
|
27
|
+
export const NODE_REDTEAM_FS = {
|
|
28
|
+
statSync: (path) => statSync(path),
|
|
29
|
+
readFileSync: (path) => readFileSync(path, 'utf-8'),
|
|
30
|
+
existsSync: (path) => existsSync(path),
|
|
31
|
+
writeFileSync: (path, data, options) => writeFileSync(path, data, options),
|
|
32
|
+
renameSync: (from, to) => renameSync(from, to),
|
|
33
|
+
mkdirSync: (path, options) => { mkdirSync(path, options); },
|
|
34
|
+
rmSync: (path, options) => { rmSync(path, options); },
|
|
35
|
+
chmodSync: (path, mode) => { chmodSync(path, mode); },
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* `(mtimeMs, size)` memo, keyed by absolute path.
|
|
39
|
+
*
|
|
40
|
+
* NO "hot reload" SWITCH EXISTS AND NONE IS NEEDED (D-10): the key changes when the file
|
|
41
|
+
* changes, so the next assembly picks the new text up. A switch that could leave a file
|
|
42
|
+
* unread is worse than no switch at all.
|
|
43
|
+
*/
|
|
44
|
+
const cache = new Map();
|
|
45
|
+
/** `/redteam prompt reload` and the "file was deleted" path both empty this (5.7). */
|
|
46
|
+
export function clearPromptProfileCache() {
|
|
47
|
+
cache.clear();
|
|
48
|
+
}
|
|
49
|
+
/** Drop ONE path; used when the file vanished, so a re-created file is read again. */
|
|
50
|
+
export function forgetPromptProfile(path) {
|
|
51
|
+
cache.delete(path);
|
|
52
|
+
}
|
|
53
|
+
/** The number of memoised files - asserted by the cache tests. */
|
|
54
|
+
export function promptProfileCacheSize() {
|
|
55
|
+
return cache.size;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Read one profile file, subject to the byte cap.
|
|
59
|
+
*
|
|
60
|
+
* THE BYTE CAP IS CHECKED ON `stat` FIRST (PF-7 / R-4): decoding a 40 MiB file into a string
|
|
61
|
+
* to find out it was too large would defeat the limit it is meant to enforce.
|
|
62
|
+
*/
|
|
63
|
+
export function loadProfileFile(path, deps = {}) {
|
|
64
|
+
const fs = deps.fs ?? NODE_REDTEAM_FS;
|
|
65
|
+
let stat;
|
|
66
|
+
try {
|
|
67
|
+
stat = fs.statSync(path);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
forgetPromptProfile(path);
|
|
71
|
+
return {
|
|
72
|
+
ok: false,
|
|
73
|
+
issue: {
|
|
74
|
+
code: 'file_missing',
|
|
75
|
+
severity: 'warn',
|
|
76
|
+
detail: 'The selected profile file does not exist; the built-in text is used.',
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
if (stat.size > REDTEAM_PROMPT_LIMITS.fileMaxBytes) {
|
|
81
|
+
forgetPromptProfile(path);
|
|
82
|
+
return {
|
|
83
|
+
ok: false,
|
|
84
|
+
issue: {
|
|
85
|
+
code: 'too_large',
|
|
86
|
+
severity: 'error',
|
|
87
|
+
detail: `The profile is ${stat.size} bytes; the limit is `
|
|
88
|
+
+ `${REDTEAM_PROMPT_LIMITS.fileMaxBytes}.`,
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const cached = cache.get(path);
|
|
93
|
+
if (cached !== undefined && cached.mtimeMs === stat.mtimeMs && cached.size === stat.size) {
|
|
94
|
+
return { ok: true, text: cached.text, bytes: cached.bytes, fromCache: true };
|
|
95
|
+
}
|
|
96
|
+
let text;
|
|
97
|
+
try {
|
|
98
|
+
text = fs.readFileSync(path);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
forgetPromptProfile(path);
|
|
102
|
+
return {
|
|
103
|
+
ok: false,
|
|
104
|
+
issue: {
|
|
105
|
+
code: 'file_missing',
|
|
106
|
+
severity: 'warn',
|
|
107
|
+
detail: 'The selected profile could not be read; the built-in text is used.',
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const entry = { mtimeMs: stat.mtimeMs, size: stat.size, text, bytes: stat.size };
|
|
112
|
+
cache.set(path, entry);
|
|
113
|
+
return { ok: true, text, bytes: entry.bytes, fromCache: false };
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Write a starter profile, REFUSING to replace one that exists (5.3 / AC-10).
|
|
117
|
+
*
|
|
118
|
+
* The refusal is the important half: `init` is offered in a transcript as a safe first step,
|
|
119
|
+
* and a command that silently overwrites the file the user has been editing for an hour is
|
|
120
|
+
* the opposite of that. The write itself copies `prompts/store.ts`'s three steps - tmp file
|
|
121
|
+
* named for the pid, `rename`, `chmod` - because a half-written profile is worse than none.
|
|
122
|
+
*/
|
|
123
|
+
export function writePromptScaffold(text, slug, deps = {}) {
|
|
124
|
+
const fs = deps.fs ?? NODE_REDTEAM_FS;
|
|
125
|
+
const dir = deps.profilesDir?.() ?? getRedTeamProfilesDir();
|
|
126
|
+
if (!PROFILE_SLUG_PATTERN.test(slug))
|
|
127
|
+
return { ok: false, reason: 'write_failed' };
|
|
128
|
+
const path = join(dir, `${slug}.md`);
|
|
129
|
+
try {
|
|
130
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
return { ok: false, reason: 'write_failed' };
|
|
134
|
+
}
|
|
135
|
+
if (fs.existsSync(path))
|
|
136
|
+
return { ok: false, reason: 'exists' };
|
|
137
|
+
const tmp = `${path}.tmp-${process.pid}`;
|
|
138
|
+
try {
|
|
139
|
+
fs.writeFileSync(tmp, text, { encoding: 'utf-8', mode: 0o600 });
|
|
140
|
+
fs.renameSync(tmp, path);
|
|
141
|
+
// BEST EFFORT, and a no-op on Windows (RV-P2-7): this is not a defence against another
|
|
142
|
+
// local user, it is the conventional "not world-readable" bit.
|
|
143
|
+
if (process.platform !== 'win32')
|
|
144
|
+
fs.chmodSync(path, 0o600);
|
|
145
|
+
return { ok: true, path };
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
try {
|
|
149
|
+
fs.rmSync(tmp, { force: true });
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
// Nothing further to try: the scaffold simply was not written, and the caller says so.
|
|
153
|
+
}
|
|
154
|
+
return { ok: false, reason: 'write_failed' };
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `/redteam prompt init` scaffold (redteam-prompt-profile 5.3 / 7.1).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - `src/redteam/**` is inside `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* AN EMPTY SKELETON IS THE RIGHT STARTER, not a filled-in example. Every section body in this
|
|
7
|
+
* file is EMPTY, so a user who runs `init` and changes nothing gets the built-in behaviour:
|
|
8
|
+
* the scaffold can never become a silently different prompt. The instructions live in the
|
|
9
|
+
* PREAMBLE, before the first `##` heading, which the parser ignores - so the explanation is
|
|
10
|
+
* for the human and never reaches the model.
|
|
11
|
+
*
|
|
12
|
+
* The seven headings use the natural spelling ("## Rules of engagement"), which is the form
|
|
13
|
+
* `HEADING_ALIASES` exists to bind (RV-P1-2).
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* The scaffold for `slug`.
|
|
17
|
+
*
|
|
18
|
+
* The header keys are the minimal set a reader needs: `schema` (required), `name`, `title`,
|
|
19
|
+
* `extends` and `mode`. `title` is left as a visible prompt rather than an empty value,
|
|
20
|
+
* because a human editing this file wants to know what the line is for.
|
|
21
|
+
*/
|
|
22
|
+
export declare function promptProfileScaffold(slug: string): string;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `/redteam prompt init` scaffold (redteam-prompt-profile 5.3 / 7.1).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - `src/redteam/**` is inside `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* AN EMPTY SKELETON IS THE RIGHT STARTER, not a filled-in example. Every section body in this
|
|
7
|
+
* file is EMPTY, so a user who runs `init` and changes nothing gets the built-in behaviour:
|
|
8
|
+
* the scaffold can never become a silently different prompt. The instructions live in the
|
|
9
|
+
* PREAMBLE, before the first `##` heading, which the parser ignores - so the explanation is
|
|
10
|
+
* for the human and never reaches the model.
|
|
11
|
+
*
|
|
12
|
+
* The seven headings use the natural spelling ("## Rules of engagement"), which is the form
|
|
13
|
+
* `HEADING_ALIASES` exists to bind (RV-P1-2).
|
|
14
|
+
*/
|
|
15
|
+
import { REDTEAM_PROMPT_LIMITS } from '@aragon-agent/tui/model/redteam/limits';
|
|
16
|
+
const PREAMBLE = `<!--
|
|
17
|
+
One file, one profile. Rename nothing here unless you also change "name:" below.
|
|
18
|
+
|
|
19
|
+
How this file is used
|
|
20
|
+
- Every "## <heading>" section REPLACES the built-in text of that section.
|
|
21
|
+
- A section you leave empty keeps the built-in text, so an untouched file behaves
|
|
22
|
+
exactly like the default mode.
|
|
23
|
+
- The sections Authorization, What this mode changes and the closing sentence are NOT
|
|
24
|
+
editable: a profile cannot restate what this session is allowed to do. Writing one of
|
|
25
|
+
those headings is ignored and reported.
|
|
26
|
+
- "mode: replace" drops every SECTION YOU DO NOT WRITE. Leave it as "merge".
|
|
27
|
+
- "extends: <slug>" starts from another profile instead of the built-in text.
|
|
28
|
+
|
|
29
|
+
Validate before you rely on it: /redteam prompt validate <path>
|
|
30
|
+
Switch this session to it: /redteam prompt <slug>
|
|
31
|
+
Go back to the default: /redteam prompt builtin
|
|
32
|
+
-->`;
|
|
33
|
+
/** The section list, in the order a reader expects them (not the emission order). */
|
|
34
|
+
const SECTIONS = [
|
|
35
|
+
'## Role and engagement framing',
|
|
36
|
+
'',
|
|
37
|
+
'## Execution',
|
|
38
|
+
'',
|
|
39
|
+
'## Rules of engagement',
|
|
40
|
+
'',
|
|
41
|
+
'## Method',
|
|
42
|
+
'',
|
|
43
|
+
'## Routing and vocabulary',
|
|
44
|
+
'',
|
|
45
|
+
'## Deliverable',
|
|
46
|
+
'',
|
|
47
|
+
'## House rules',
|
|
48
|
+
'',
|
|
49
|
+
];
|
|
50
|
+
/**
|
|
51
|
+
* The scaffold for `slug`.
|
|
52
|
+
*
|
|
53
|
+
* The header keys are the minimal set a reader needs: `schema` (required), `name`, `title`,
|
|
54
|
+
* `extends` and `mode`. `title` is left as a visible prompt rather than an empty value,
|
|
55
|
+
* because a human editing this file wants to know what the line is for.
|
|
56
|
+
*/
|
|
57
|
+
export function promptProfileScaffold(slug) {
|
|
58
|
+
const name = slug.length > 0 ? slug : REDTEAM_PROMPT_LIMITS.scaffoldSlugFallback;
|
|
59
|
+
return [
|
|
60
|
+
'---',
|
|
61
|
+
'schema: 1',
|
|
62
|
+
`name: ${name}`,
|
|
63
|
+
'title: ',
|
|
64
|
+
'extends: builtin',
|
|
65
|
+
'mode: merge',
|
|
66
|
+
'---',
|
|
67
|
+
'',
|
|
68
|
+
PREAMBLE,
|
|
69
|
+
'',
|
|
70
|
+
...SECTIONS,
|
|
71
|
+
].join('\n');
|
|
72
|
+
}
|
package/dist/team/bus.d.ts
CHANGED
|
@@ -109,6 +109,24 @@ export declare class TeamBus {
|
|
|
109
109
|
messageCount(): number;
|
|
110
110
|
lastMessage(): TeamMessage | undefined;
|
|
111
111
|
sentCount(label: string): number;
|
|
112
|
+
/**
|
|
113
|
+
* Add a participant mid-dispatch (team-detached-dispatch section 5.2.6).
|
|
114
|
+
*
|
|
115
|
+
* `team_spawn` creates children after the first batch, and a late child that
|
|
116
|
+
* cannot be addressed would be a subagent its own siblings cannot message and
|
|
117
|
+
* whose mail nobody can send - a silent half-participant. `participants()` keeps
|
|
118
|
+
* the lead LAST, which is the order every bus consumer already assumes.
|
|
119
|
+
*/
|
|
120
|
+
addParticipant(label: string): void;
|
|
121
|
+
/**
|
|
122
|
+
* Messages addressed to `lead` from `cursor` onward, for the live reminder path
|
|
123
|
+
* (section 5.2.3). `leadMail()` returns everything, which is what the REPORT
|
|
124
|
+
* wants; a relay that re-reported every message on every event would repeat
|
|
125
|
+
* itself once per notice.
|
|
126
|
+
*/
|
|
127
|
+
leadMailSince(cursor: number): TeamMessage[];
|
|
128
|
+
/** How many messages have been addressed to `lead` so far (the relay's cursor). */
|
|
129
|
+
leadMailCount(): number;
|
|
112
130
|
/**
|
|
113
131
|
* Canonical label for a model-supplied `from`, or `undefined` (P1-3).
|
|
114
132
|
*
|
package/dist/team/bus.js
CHANGED
|
@@ -70,6 +70,33 @@ export class TeamBus {
|
|
|
70
70
|
sentCount(label) {
|
|
71
71
|
return this.sentBy.get(label) ?? 0;
|
|
72
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Add a participant mid-dispatch (team-detached-dispatch section 5.2.6).
|
|
75
|
+
*
|
|
76
|
+
* `team_spawn` creates children after the first batch, and a late child that
|
|
77
|
+
* cannot be addressed would be a subagent its own siblings cannot message and
|
|
78
|
+
* whose mail nobody can send - a silent half-participant. `participants()` keeps
|
|
79
|
+
* the lead LAST, which is the order every bus consumer already assumes.
|
|
80
|
+
*/
|
|
81
|
+
addParticipant(label) {
|
|
82
|
+
if (this.labels.includes(label))
|
|
83
|
+
return;
|
|
84
|
+
this.labels.push(label);
|
|
85
|
+
this.mailboxes.set(label, []);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Messages addressed to `lead` from `cursor` onward, for the live reminder path
|
|
89
|
+
* (section 5.2.3). `leadMail()` returns everything, which is what the REPORT
|
|
90
|
+
* wants; a relay that re-reported every message on every event would repeat
|
|
91
|
+
* itself once per notice.
|
|
92
|
+
*/
|
|
93
|
+
leadMailSince(cursor) {
|
|
94
|
+
return this.lead.slice(Math.max(0, cursor));
|
|
95
|
+
}
|
|
96
|
+
/** How many messages have been addressed to `lead` so far (the relay's cursor). */
|
|
97
|
+
leadMailCount() {
|
|
98
|
+
return this.lead.length;
|
|
99
|
+
}
|
|
73
100
|
/**
|
|
74
101
|
* Canonical label for a model-supplied `from`, or `undefined` (P1-3).
|
|
75
102
|
*
|
|
@@ -118,8 +145,13 @@ export class TeamBus {
|
|
|
118
145
|
return { ok: false, reason: 'recipient_finished', who: addressed };
|
|
119
146
|
}
|
|
120
147
|
const used = this.sentCount(from);
|
|
121
|
-
|
|
122
|
-
|
|
148
|
+
// THE LEAD HAS ITS OWN CAP (section 5.2.3): it is the only participant that
|
|
149
|
+
// reacts to the user changing their mind mid-dispatch, and six corrections
|
|
150
|
+
// across a two-hour dispatch is too few. Everything else keeps
|
|
151
|
+
// `messagesPerAgent`.
|
|
152
|
+
const perSenderCap = from === LEAD_KEY ? TEAM_LIMITS.messagesFromLeadPerDispatch : TEAM_LIMITS.messagesPerAgent;
|
|
153
|
+
if (used + cost > perSenderCap) {
|
|
154
|
+
return { ok: false, reason: 'agent_quota', used, max: perSenderCap };
|
|
123
155
|
}
|
|
124
156
|
if (this.total + cost > TEAM_LIMITS.messagesPerDispatch) {
|
|
125
157
|
return {
|
|
@@ -129,7 +161,17 @@ export class TeamBus {
|
|
|
129
161
|
max: TEAM_LIMITS.messagesPerDispatch,
|
|
130
162
|
};
|
|
131
163
|
}
|
|
132
|
-
|
|
164
|
+
// THE RATE WINDOW IS KEYED DIFFERENTLY FOR THE LEAD (REV-17 / R15).
|
|
165
|
+
//
|
|
166
|
+
// A child's window makes chatter expensive, and its natural key is the sender:
|
|
167
|
+
// one child, one voice, one interval. The lead's window exists for a different
|
|
168
|
+
// reason - to stop it flooding ONE child - and a per-sender key would refuse
|
|
169
|
+
// the second and third message of a single decision the user made ("drop the
|
|
170
|
+
// bundle work, look at render instead"), which is precisely the moment the
|
|
171
|
+
// console exists for. So the lead's key is `lead:<recipient>`; every other
|
|
172
|
+
// sender keeps the plain sender key.
|
|
173
|
+
const windowKey = from === LEAD_KEY ? `${from}:${target}` : from;
|
|
174
|
+
const last = this.lastSentAt.get(windowKey);
|
|
133
175
|
const now = this.now();
|
|
134
176
|
if (last !== undefined && now - last < TEAM_LIMITS.minSendIntervalMs) {
|
|
135
177
|
return {
|
|
@@ -143,17 +185,20 @@ export class TeamBus {
|
|
|
143
185
|
const subject = subjectRaw.trim().slice(0, TEAM_LIMITS.subjectChars);
|
|
144
186
|
const body = bodyRaw.trim().slice(0, TEAM_LIMITS.bodyChars);
|
|
145
187
|
this.sentBy.set(from, used + cost);
|
|
146
|
-
this.lastSentAt.set(
|
|
188
|
+
this.lastSentAt.set(windowKey, now);
|
|
147
189
|
this.total += cost;
|
|
148
190
|
for (const recipient of recipients) {
|
|
149
191
|
const message = { from, to: recipient, subject, body, at: now };
|
|
150
192
|
this.last = message;
|
|
151
193
|
this.onMessage?.(message);
|
|
152
194
|
if (recipient === LEAD_KEY) {
|
|
153
|
-
// The lead is
|
|
154
|
-
//
|
|
155
|
-
//
|
|
156
|
-
//
|
|
195
|
+
// The lead's mail is COLLECTED here rather than injected into its history
|
|
196
|
+
// mid-tool. That was the pre-feature rule because the lead was blocked
|
|
197
|
+
// inside `task` for the whole dispatch; with a detached dispatch the lead
|
|
198
|
+
// is idle between turns, so the SAME collection now also feeds a live
|
|
199
|
+
// reminder path (`agent/team-notices.ts`) and `team_status`'s mail line.
|
|
200
|
+
// Injection still belongs to the notice/steering machinery, not to this
|
|
201
|
+
// class - one delivery mechanism, not two.
|
|
157
202
|
this.lead.push(message);
|
|
158
203
|
continue;
|
|
159
204
|
}
|
|
@@ -165,7 +210,10 @@ export class TeamBus {
|
|
|
165
210
|
ok: true,
|
|
166
211
|
delivered: recipients,
|
|
167
212
|
spent: cost,
|
|
168
|
-
|
|
213
|
+
// THE SAME CAP THAT WAS JUST ENFORCED. A hard-coded `messagesPerAgent` here
|
|
214
|
+
// answered the lead's budget with the child budget (6 instead of 24) - wrong
|
|
215
|
+
// for every caller that reads `remaining` rather than recomputing it.
|
|
216
|
+
remaining: Math.max(0, perSenderCap - (used + cost)),
|
|
169
217
|
};
|
|
170
218
|
}
|
|
171
219
|
resolveRecipients(from, target) {
|
|
@@ -210,11 +258,13 @@ export class TeamBus {
|
|
|
210
258
|
let acceptable = peers;
|
|
211
259
|
let want;
|
|
212
260
|
if (opts.from !== undefined) {
|
|
213
|
-
const
|
|
214
|
-
//
|
|
215
|
-
//
|
|
216
|
-
//
|
|
217
|
-
//
|
|
261
|
+
const asked = opts.from.trim().toLowerCase();
|
|
262
|
+
// THE LEAD IS A LEGAL SENDER NOW (team-detached-dispatch section 5.2.3): the
|
|
263
|
+
// console tools let it write to a child, so a child waiting for a lead reply
|
|
264
|
+
// is a wait that can be satisfied. The old reading - "lead never sends, so
|
|
265
|
+
// asking for it can never be satisfied" - was true before this feature and is
|
|
266
|
+
// now exactly wrong.
|
|
267
|
+
const canonical = asked === LEAD_KEY ? LEAD_KEY : this.resolveLabel(opts.from);
|
|
218
268
|
if (canonical === undefined || canonical === key) {
|
|
219
269
|
return { reason: 'unknown_sender', asked: opts.from.trim(), peers };
|
|
220
270
|
}
|
|
@@ -281,10 +331,12 @@ export class TeamBus {
|
|
|
281
331
|
continue;
|
|
282
332
|
}
|
|
283
333
|
// Who could release `p`? Its own acceptable senders - and `peersOf`, NOT
|
|
284
|
-
// `participants`, because
|
|
285
|
-
//
|
|
286
|
-
//
|
|
287
|
-
// unreachable for exactly the from-less waits it was written for.
|
|
334
|
+
// `participants`, because `participants` includes `lead`, which would put the
|
|
335
|
+
// lead in every from-less waiter's waker set. The lead is never in
|
|
336
|
+
// `cannotAct` (it runs no loop here), so `all_blocked` would become
|
|
337
|
+
// unreachable for exactly the from-less waits it was written for. The lead
|
|
338
|
+
// CAN send now (`sendFromLead`); that changes which messages arrive, not who
|
|
339
|
+
// counts as a peer for this reachability argument.
|
|
288
340
|
const wakers = w.from ? [w.from] : this.peersOf(p);
|
|
289
341
|
if (wakers.some((x) => x !== p && !cannotAct.has(x))) {
|
|
290
342
|
cannotAct.delete(p);
|
|
@@ -0,0 +1,54 @@
|
|
|
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 { type AgentTool } from '@aragon-agent/core';
|
|
27
|
+
import type { TeamControlBy } from '@aragon-agent/tui/model/team/types';
|
|
28
|
+
import type { TeamRuntime } from './runtime.js';
|
|
29
|
+
export interface ConsoleToolDeps {
|
|
30
|
+
runtime: TeamRuntime;
|
|
31
|
+
/**
|
|
32
|
+
* `controller.hasPendingUserMessages()` (I-DD2). The one signal `team_collect`
|
|
33
|
+
* must never miss: the lead waiting is acceptable, the USER waiting is not.
|
|
34
|
+
*/
|
|
35
|
+
hasPendingUserInput: () => boolean;
|
|
36
|
+
/** Who is acting. `'lead'` for these tools; `'user'` for `/team` verbs. */
|
|
37
|
+
by?: TeamControlBy;
|
|
38
|
+
}
|
|
39
|
+
/** `team_status` - the read surface. */
|
|
40
|
+
export declare function makeTeamStatusTool(deps: ConsoleToolDeps): AgentTool;
|
|
41
|
+
/** `team_message` - steer a child, or all of them. */
|
|
42
|
+
export declare function makeTeamMessageTool(deps: ConsoleToolDeps): AgentTool;
|
|
43
|
+
/** `team_pause` - hold one child. */
|
|
44
|
+
export declare function makeTeamPauseTool(deps: ConsoleToolDeps): AgentTool;
|
|
45
|
+
/** `team_resume` - release one child, optionally with an instruction. */
|
|
46
|
+
export declare function makeTeamResumeTool(deps: ConsoleToolDeps): AgentTool;
|
|
47
|
+
/** `team_stop` - end one child or the whole dispatch. */
|
|
48
|
+
export declare function makeTeamStopTool(deps: ConsoleToolDeps): AgentTool;
|
|
49
|
+
/** `team_spawn` - add subagents to the dispatch that is already running. */
|
|
50
|
+
export declare function makeTeamSpawnTool(deps: ConsoleToolDeps): AgentTool;
|
|
51
|
+
/** `team_collect` - the one bounded wait, and it yields to the user. */
|
|
52
|
+
export declare function makeTeamCollectTool(deps: ConsoleToolDeps): AgentTool;
|
|
53
|
+
/** The seven tools, in the order the prompt block lists them. */
|
|
54
|
+
export declare function createConsoleTools(deps: ConsoleToolDeps): AgentTool[];
|