@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
|
@@ -1,23 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `/redteam`: report, enter, leave,
|
|
3
|
-
* (red-team-security-mode 4.8 / D-18).
|
|
2
|
+
* `/redteam`: report, enter, leave, declare the engagement scope, and manage the prompt profile
|
|
3
|
+
* (red-team-security-mode 4.8 / D-18; `prompt` since redteam-prompt-profile 7.1).
|
|
4
4
|
*
|
|
5
5
|
* ASCII ONLY: `src/commands/**` is inside `glyphs.test.ts::inScope`.
|
|
6
6
|
*
|
|
7
|
-
* FOUR SUBCOMMANDS AND ONE SHARED ENTRY
|
|
8
|
-
* the same call `Ctrl+R` makes, so a turn in flight defers the
|
|
9
|
-
* and the wording is the shared toast. `status` never refuses,
|
|
10
|
-
* a security posture nobody can query is a posture the user
|
|
11
|
-
* "am I in red team mode right now" is exactly the one a
|
|
12
|
-
* destructive command in the transcript.
|
|
7
|
+
* FOUR SUBCOMMANDS AND ONE SHARED ENTRY, PLUS `prompt`. `on` / `off` go through
|
|
8
|
+
* `controller.setRedTeam()`, the same call `Ctrl+R` makes, so a turn in flight defers the
|
|
9
|
+
* arming instead of being refused and the wording is the shared toast. `status` never refuses,
|
|
10
|
+
* in any posture and any session: a security posture nobody can query is a posture the user
|
|
11
|
+
* cannot verify - and the question "am I in red team mode right now" is exactly the one a
|
|
12
|
+
* person asks while looking at a destructive command in the transcript.
|
|
13
13
|
*
|
|
14
14
|
* THE COMMAND DOES NOT OPEN THE WAIVER OVERLAY. `on` without an accepted waiver answers with
|
|
15
15
|
* the sentence that names the key instead: the overlay is App state, and a command that opened
|
|
16
16
|
* it could not settle it (accepting has to re-plan the request and push the banner).
|
|
17
|
+
*
|
|
18
|
+
* `/redteam prompt` HAS ONE RULE THAT IS NOT NEGOTIABLE (RV-P1-10 / AC-23): a word that is
|
|
19
|
+
* already a `/redteam` verb is NEVER a profile name. `/redteam prompt status` is what a user
|
|
20
|
+
* types after `/redteam status`, and turning it into `redteam.profile = "status"` would be a
|
|
21
|
+
* silent configuration write - the exact failure a "one file, one setting" feature must not
|
|
22
|
+
* have.
|
|
17
23
|
*/
|
|
18
|
-
import {
|
|
24
|
+
import { clampRedTeamProfile } from '@aragon-agent/tui/model/config/schema';
|
|
25
|
+
import { PROFILE_SLUG_PATTERN } from '@aragon-agent/tui/model/redteam/prompt-file';
|
|
26
|
+
import { REDTEAM_PROMPT_LIMITS } from '@aragon-agent/tui/model/redteam/limits';
|
|
27
|
+
import { redTeamStatusLines, REDTEAM_COMMAND, REDTEAM_PROMPT, REDTEAM_PROMPT_ISSUE_TEXT, REDTEAM_TOAST, } from '@aragon-agent/tui/ui/redteam-copy';
|
|
19
28
|
import { redTeamToast, } from '@aragon-agent/tui/model/redteam/redteam-mode';
|
|
20
29
|
import { UNAVAILABLE_RED_TEAM_VIEW } from '../agent/redteam-wiring.js';
|
|
30
|
+
import { resolveRedTeamPrompt } from '../redteam/prompt-resolve.js';
|
|
21
31
|
/** Where the `/redteam` handler lives, so `builtins.ts` only adds one registration. */
|
|
22
32
|
export function runRedTeamCommand(ctx) {
|
|
23
33
|
const args = ctx.args.trim();
|
|
@@ -36,6 +46,9 @@ export function runRedTeamCommand(ctx) {
|
|
|
36
46
|
case 'scope':
|
|
37
47
|
setScope(ctx, rest.join(' ').trim());
|
|
38
48
|
return;
|
|
49
|
+
case 'prompt':
|
|
50
|
+
runPromptCommand(ctx, rest);
|
|
51
|
+
return;
|
|
39
52
|
default:
|
|
40
53
|
ctx.notify('warn', REDTEAM_COMMAND.usage);
|
|
41
54
|
}
|
|
@@ -47,9 +60,16 @@ function viewOf(ctx) {
|
|
|
47
60
|
? port.getRedTeamView()
|
|
48
61
|
: UNAVAILABLE_RED_TEAM_VIEW;
|
|
49
62
|
}
|
|
63
|
+
/** The prompt view, or the `builtin` shape when the controller has no profile machinery. */
|
|
64
|
+
function promptViewOf(ctx) {
|
|
65
|
+
const port = ctx.controller;
|
|
66
|
+
return typeof port.getRedTeamPromptView === 'function'
|
|
67
|
+
? port.getRedTeamPromptView()
|
|
68
|
+
: { profile: 'builtin', source: 'builtin', overridden: [], bytes: 0, issues: [] };
|
|
69
|
+
}
|
|
50
70
|
/**
|
|
51
|
-
* The
|
|
52
|
-
*
|
|
71
|
+
* The five status lines (RV-18): effective state, scope, what the confirmation gate is doing,
|
|
72
|
+
* what this mode does NOT lift, and which prompt profile supplies the wording.
|
|
53
73
|
*
|
|
54
74
|
* The third line is the one the whole feature is judged on (R-13): with `confirmTools` off -
|
|
55
75
|
* the default - it must say that NOTHING about permissions changed, because that is the truth
|
|
@@ -62,6 +82,7 @@ function reportStatus(ctx) {
|
|
|
62
82
|
confirmTools: config.confirmTools === true,
|
|
63
83
|
bypassConfirm: config.redteam?.bypassConfirm !== false,
|
|
64
84
|
posture: postureOf(ctx),
|
|
85
|
+
prompt: promptViewOf(ctx),
|
|
65
86
|
});
|
|
66
87
|
ctx.notify('info', lines.join('\n'));
|
|
67
88
|
}
|
|
@@ -131,11 +152,221 @@ function setScope(ctx, line) {
|
|
|
131
152
|
? REDTEAM_TOAST.scopeCleared
|
|
132
153
|
: `${REDTEAM_COMMAND.scopeSetPrefix}${result.scope}`);
|
|
133
154
|
}
|
|
155
|
+
// ---------------------------------------------------------------------------
|
|
156
|
+
// /redteam prompt (7.1)
|
|
157
|
+
// ---------------------------------------------------------------------------
|
|
158
|
+
/** The words `/redteam prompt` treats as ACTIONS. They are never profile names (AC-23). */
|
|
159
|
+
const RESERVED_ACTIONS = new Set(['status', 'builtin', 'reload', 'validate', 'init']);
|
|
160
|
+
/** Words that are already `/redteam` verbs; typing one here is a slip, not a profile. */
|
|
161
|
+
const RESERVED_VERBS = new Set(['status', 'on', 'off', 'scope', 'redteam', 'prompt']);
|
|
162
|
+
/**
|
|
163
|
+
* The subcommand. THE DECISION ORDER IS FIXED (7.1): an action first, then the reserved-word
|
|
164
|
+
* guard, then path-vs-slug. Any other order turns a slip of the keyboard into a config write.
|
|
165
|
+
*/
|
|
166
|
+
function runPromptCommand(ctx, rest) {
|
|
167
|
+
const first = (rest[0] ?? '').trim();
|
|
168
|
+
if (first.length === 0 || first === 'status') {
|
|
169
|
+
reportPrompt(ctx);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const lower = first.toLowerCase();
|
|
173
|
+
if (lower === 'builtin') {
|
|
174
|
+
setBuiltin(ctx);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (lower === 'reload') {
|
|
178
|
+
reload(ctx);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (lower === 'validate') {
|
|
182
|
+
validate(ctx, rest.slice(1).join(' ').trim());
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (lower === 'init') {
|
|
186
|
+
init(ctx, rest.slice(1).join(' ').trim());
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (RESERVED_ACTIONS.has(lower) || RESERVED_VERBS.has(lower)) {
|
|
190
|
+
// REPORT ONLY. Persisting this would be a silent `redteam.profile = "on"`.
|
|
191
|
+
ctx.notify('warn', `${REDTEAM_PROMPT.reservedWord} ${REDTEAM_PROMPT.usage}`);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (isPathArgument(first)) {
|
|
195
|
+
setPath(ctx, rest.join(' ').trim());
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
setSlug(ctx, lower);
|
|
199
|
+
}
|
|
200
|
+
/** A separator, a drive letter or `.md` means the user is naming a FILE (D-18 rule 2). */
|
|
201
|
+
function isPathArgument(value) {
|
|
202
|
+
return value.includes('/')
|
|
203
|
+
|| value.includes('\\')
|
|
204
|
+
|| /^[A-Za-z]:[\\/]/u.test(value)
|
|
205
|
+
|| value.toLowerCase().endsWith('.md');
|
|
206
|
+
}
|
|
207
|
+
/** The report: what is in effect, what it replaced, and what is wrong with it (§7.1). */
|
|
208
|
+
function reportPrompt(ctx) {
|
|
209
|
+
const prompt = promptViewOf(ctx);
|
|
210
|
+
const lines = [];
|
|
211
|
+
if (prompt.source === 'builtin') {
|
|
212
|
+
lines.push(REDTEAM_PROMPT.builtinLine);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
lines.push(`Prompt: ${prompt.profile} (${prompt.source}, ${prompt.bytes} bytes).`);
|
|
216
|
+
}
|
|
217
|
+
lines.push(prompt.overridden.length === 0
|
|
218
|
+
? 'Sections overridden: none.'
|
|
219
|
+
: `Sections overridden: ${prompt.overridden.join(', ')}.`);
|
|
220
|
+
for (const issue of prompt.issues.slice(0, REDTEAM_PROMPT_LIMITS.issuesShownMax)) {
|
|
221
|
+
// THE LINE NUMBER IS THE USEFUL HALF of an issue, and it is safe: it points into the
|
|
222
|
+
// user's own file, which they already have open.
|
|
223
|
+
const where = issue.line === undefined ? '' : ` line ${issue.line}:`;
|
|
224
|
+
lines.push(`- ${issue.code}${where} ${REDTEAM_PROMPT_ISSUE_TEXT[issue.code] ?? ''}`);
|
|
225
|
+
}
|
|
226
|
+
ctx.notify('info', lines.join('\n'));
|
|
227
|
+
}
|
|
228
|
+
/** `/redteam prompt builtin`: back to the code default, in this session AND in the config. */
|
|
229
|
+
function setBuiltin(ctx) {
|
|
230
|
+
persistProfile(ctx, 'builtin');
|
|
231
|
+
const port = ctx.controller;
|
|
232
|
+
if (typeof port.setRedTeamPromptPath === 'function')
|
|
233
|
+
port.setRedTeamPromptPath(null);
|
|
234
|
+
if (typeof port.setRedTeamPromptProfile === 'function')
|
|
235
|
+
port.setRedTeamPromptProfile('builtin');
|
|
236
|
+
ctx.notify('info', REDTEAM_PROMPT.builtinReset);
|
|
237
|
+
}
|
|
238
|
+
/** `/redteam prompt <slug>`: validate, persist, switch. A missing file is still a setting. */
|
|
239
|
+
function setSlug(ctx, raw) {
|
|
240
|
+
const slug = clampRedTeamProfile(raw);
|
|
241
|
+
if (slug === 'builtin' || !PROFILE_SLUG_PATTERN.test(slug)) {
|
|
242
|
+
ctx.notify('warn', REDTEAM_PROMPT.usage);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
persistProfile(ctx, slug);
|
|
246
|
+
const port = ctx.controller;
|
|
247
|
+
if (typeof port.setRedTeamPromptProfile === 'function')
|
|
248
|
+
port.setRedTeamPromptProfile(slug);
|
|
249
|
+
const prompt = promptViewOf(ctx);
|
|
250
|
+
if (prompt.source === 'builtin') {
|
|
251
|
+
ctx.notify('warn', `${REDTEAM_PROMPT.setSlugPrefix}${slug}. ${REDTEAM_PROMPT.setSlugMissing}`);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
ctx.notify('info', `${REDTEAM_PROMPT.setSlugPrefix}${slug} (${prompt.bytes} bytes).`);
|
|
255
|
+
}
|
|
256
|
+
/** `/redteam prompt <path>`: THIS SESSION only, and the config is deliberately untouched. */
|
|
257
|
+
function setPath(ctx, path) {
|
|
258
|
+
const port = ctx.controller;
|
|
259
|
+
if (typeof port.setRedTeamPromptPath !== 'function') {
|
|
260
|
+
ctx.notify('warn', REDTEAM_PROMPT.unavailable);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
port.setRedTeamPromptPath(path);
|
|
264
|
+
const prompt = promptViewOf(ctx);
|
|
265
|
+
if (prompt.source === 'builtin') {
|
|
266
|
+
// The file did not load; the user is told immediately rather than at the next arm.
|
|
267
|
+
const first = prompt.issues[0];
|
|
268
|
+
const why = first === undefined ? '' : ` ${REDTEAM_PROMPT_ISSUE_TEXT[first.code] ?? first.code}.`;
|
|
269
|
+
ctx.notify('warn', `${REDTEAM_PROMPT.setPathPrefix}${prompt.profile}.${why}`);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
ctx.notify('info', `${REDTEAM_PROMPT.setPathPrefix}${prompt.profile} (${prompt.bytes} bytes).`);
|
|
273
|
+
}
|
|
274
|
+
/** `/redteam prompt reload`: purge, rebuild, and report whether the block moved. */
|
|
275
|
+
function reload(ctx) {
|
|
276
|
+
const port = ctx.controller;
|
|
277
|
+
if (typeof port.reloadRedTeamPrompt !== 'function') {
|
|
278
|
+
ctx.notify('warn', REDTEAM_PROMPT.unavailable);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const result = port.reloadRedTeamPrompt();
|
|
282
|
+
ctx.notify('info', result.changed ? REDTEAM_PROMPT.reloadChanged : REDTEAM_PROMPT.reloadUnchanged);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* `/redteam prompt validate [<slug>|<path>]`: parse and REPORT, apply nothing (AC-11).
|
|
286
|
+
*
|
|
287
|
+
* THE ARGUMENT IS RESOLVED EXACTLY AS THE REAL LAYER WOULD RESOLVE IT: a path form is read from
|
|
288
|
+
* that path, and a bare slug is read from `<profiles>/<slug>.md` - the scaffold written by
|
|
289
|
+
* `init` ends with `validate <path>` / `validate <slug>` in its own instructions, and a
|
|
290
|
+
* `validate` that only understood paths answered `file_missing` for the slug form. Without an
|
|
291
|
+
* argument it reports the profile in effect.
|
|
292
|
+
*/
|
|
293
|
+
function validate(ctx, target) {
|
|
294
|
+
const lines = [REDTEAM_PROMPT.validateHeader];
|
|
295
|
+
if (target.length === 0) {
|
|
296
|
+
const prompt = promptViewOf(ctx);
|
|
297
|
+
lines.push(`Profile: ${prompt.profile} (${prompt.source}, ${prompt.bytes} bytes).`);
|
|
298
|
+
lines.push(prompt.overridden.length === 0
|
|
299
|
+
? 'Sections bound: none.'
|
|
300
|
+
: `Sections bound: ${prompt.overridden.join(', ')}.`);
|
|
301
|
+
for (const issue of prompt.issues)
|
|
302
|
+
lines.push(describe(issue));
|
|
303
|
+
if (prompt.issues.length === 0)
|
|
304
|
+
lines.push(REDTEAM_PROMPT.validateClean);
|
|
305
|
+
ctx.notify('info', lines.join('\n'));
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
// `profile:` rather than `flagPath:` so BOTH forms work; the raw argument is echoed back
|
|
309
|
+
// because it is the user's own words in the user's own terminal (PF-6 governs logs, not this).
|
|
310
|
+
const resolved = resolveRedTeamPrompt({
|
|
311
|
+
profile: target,
|
|
312
|
+
cwd: process.cwd(),
|
|
313
|
+
});
|
|
314
|
+
lines.push(`File: ${target} (${resolved.source}, ${resolved.bytes} bytes).`);
|
|
315
|
+
lines.push(resolved.overridden.length === 0
|
|
316
|
+
? 'Sections bound: none.'
|
|
317
|
+
: `Sections bound: ${resolved.overridden.join(', ')}.`);
|
|
318
|
+
for (const issue of resolved.issues)
|
|
319
|
+
lines.push(describe(issue));
|
|
320
|
+
if (resolved.issues.length === 0)
|
|
321
|
+
lines.push(REDTEAM_PROMPT.validateClean);
|
|
322
|
+
ctx.notify(resolved.issues.some((issue) => issue.severity === 'error') ? 'warn' : 'info', lines.join('\n'));
|
|
323
|
+
}
|
|
324
|
+
function describe(issue) {
|
|
325
|
+
const where = issue.line === undefined ? '' : ` (line ${issue.line})`;
|
|
326
|
+
return `- ${issue.code}${where}: ${REDTEAM_PROMPT_ISSUE_TEXT[issue.code] ?? ''}`;
|
|
327
|
+
}
|
|
328
|
+
/** `/redteam prompt init [<slug>]`: write a scaffold, never over an existing file (AC-10). */
|
|
329
|
+
function init(ctx, rawSlug) {
|
|
330
|
+
const port = ctx.controller;
|
|
331
|
+
if (typeof port.writeRedTeamPromptScaffold !== 'function') {
|
|
332
|
+
ctx.notify('warn', REDTEAM_PROMPT.unavailable);
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
const slug = clampRedTeamProfile(rawSlug.length === 0 ? 'custom' : rawSlug);
|
|
336
|
+
const result = port.writeRedTeamPromptScaffold(slug === 'builtin' ? 'custom' : slug);
|
|
337
|
+
if (!result.ok) {
|
|
338
|
+
ctx.notify('warn', result.reason === 'exists'
|
|
339
|
+
? REDTEAM_PROMPT.initExists
|
|
340
|
+
: REDTEAM_PROMPT.initFailed);
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
// THE PATH IS THE OUTPUT: the user asked for a file, so the answer is where it is. The
|
|
344
|
+
// follow-up names that PATH - `validate` resolves a slug through `<profiles>/`, and this is
|
|
345
|
+
// the one file whose location the user may want to confirm.
|
|
346
|
+
ctx.notify('info', `${REDTEAM_PROMPT.initWritten}${result.path ?? ''}\n`
|
|
347
|
+
+ `Next: edit it, then /redteam prompt validate ${result.path ?? slug}.`);
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Write `redteam.profile` and keep the four other keys. The spread is what makes this safe:
|
|
351
|
+
* `PersistedConfig['redteam']` is a five-key shape, and a command that sent a partial object
|
|
352
|
+
* would reset the switches a user set in the settings screen (I-4's neighbour rule).
|
|
353
|
+
*/
|
|
354
|
+
function persistProfile(ctx, profile) {
|
|
355
|
+
const current = ctx.controller.getConfig().redteam;
|
|
356
|
+
const next = {
|
|
357
|
+
enabled: current?.enabled ?? true,
|
|
358
|
+
bypassConfirm: current?.bypassConfirm ?? true,
|
|
359
|
+
banner: current?.banner ?? true,
|
|
360
|
+
askEveryArm: current?.askEveryArm ?? false,
|
|
361
|
+
profile,
|
|
362
|
+
};
|
|
363
|
+
ctx.persistConfig({ redteam: next });
|
|
364
|
+
}
|
|
134
365
|
/** Registered from `builtins.ts` with one line, next to every other subsystem. */
|
|
135
366
|
export function registerRedTeamCommand(registry) {
|
|
136
367
|
registry.register({
|
|
137
368
|
name: 'redteam',
|
|
138
|
-
description: 'Red team mode: /redteam [status|on|off|scope <one line
|
|
369
|
+
description: 'Red team mode: /redteam [status|on|off|scope <one line>|prompt [...]]',
|
|
139
370
|
run: (ctx) => { runRedTeamCommand(ctx); },
|
|
140
371
|
});
|
|
141
372
|
}
|
|
@@ -45,7 +45,9 @@
|
|
|
45
45
|
* screen refresh (the old P1-6 contract).
|
|
46
46
|
*/
|
|
47
47
|
import { buildForcedDirective } from '../team/forced-dispatch.js';
|
|
48
|
-
import { forcedCardNote, planForced, planNotice, readTeamIntent, } from '../team/forced-mode.js';
|
|
48
|
+
import { forcedCardNote, planForced, planNotice, readTeamControlIntent, readTeamIntent, } from '../team/forced-mode.js';
|
|
49
|
+
import { renderTeamStatus } from '../team/console-view.js';
|
|
50
|
+
import { TEAM_LIMITS } from '@aragon-agent/tui/model/team/limits';
|
|
49
51
|
import { subagentModelSummary } from '@aragon-agent/tui/ui/overlays/model-profile-state';
|
|
50
52
|
import { teamModeToast, } from '@aragon-agent/tui/model/team/team-mode';
|
|
51
53
|
/**
|
|
@@ -99,6 +101,14 @@ function reportStatus(ctx) {
|
|
|
99
101
|
if (forced && ctx.controller.getAgentMode() === 'plan') {
|
|
100
102
|
lines.push('Plan mode is on: dispatch read-only research, then submit_plan.');
|
|
101
103
|
}
|
|
104
|
+
// THE LIVE ROSTER TOO, from the renderer `team_status` uses (section 7.4: one
|
|
105
|
+
// question, one formatter). "How is my team doing" is the reason a user types
|
|
106
|
+
// `/team status` at all, and answering it with the config alone made them ask
|
|
107
|
+
// the model instead - a whole turn for one line of text.
|
|
108
|
+
const inspection = ctx.controller.readTeamControl?.()?.inspection ?? null;
|
|
109
|
+
if (inspection !== null) {
|
|
110
|
+
lines.push(renderTeamStatus(inspection, { includeSummary: true }), 'Control it without a turn: /team send|pause|resume|stop|wait|spawn.');
|
|
111
|
+
}
|
|
102
112
|
ctx.notify('info', lines.join('\n'));
|
|
103
113
|
}
|
|
104
114
|
/**
|
|
@@ -300,8 +310,89 @@ function armAndSubmit(ctx, intent) {
|
|
|
300
310
|
...(cards ? { invocation: forcedCardInput(ctx.args, planned, note, ctx) } : {}),
|
|
301
311
|
});
|
|
302
312
|
}
|
|
313
|
+
/**
|
|
314
|
+
* The six control verbs (team-detached-dispatch section 5.8).
|
|
315
|
+
*
|
|
316
|
+
* THEY SKIP THE BUSY AND RUNNING GUARDS, DELIBERATELY. Those two guards exist to
|
|
317
|
+
* protect a NEW dispatch, and a control verb exists precisely because one is
|
|
318
|
+
* running - refusing `/team stop all` with "a team dispatch is already running"
|
|
319
|
+
* would be the control panel locked by the thing it controls. The capability
|
|
320
|
+
* guards still apply (registered, enabled-for-this-session), and `hasApiKey` does
|
|
321
|
+
* not: nothing here spends a model call.
|
|
322
|
+
*
|
|
323
|
+
* `wait` is the only one that blocks, and it defers to `team_collect`: same
|
|
324
|
+
* budget, same "the user wins" rule, so the user pressing a key ends it exactly as
|
|
325
|
+
* a user typing a message does.
|
|
326
|
+
*/
|
|
327
|
+
function runControlVerb(ctx, intent) {
|
|
328
|
+
if (!ctx.controller.isTeamRegistered()) {
|
|
329
|
+
ctx.notify('warn', 'Team mode is off for this session (started with --no-team).');
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
// OPTIONAL CHAINING, TWICE: a hand-written controller double has no team surface,
|
|
333
|
+
// and `/team stop all` in such a test must answer "none is running" rather than
|
|
334
|
+
// throwing out of a command handler.
|
|
335
|
+
const live = ctx.controller.readTeamControl?.() ?? { inspection: null, live: null };
|
|
336
|
+
if (live.live === null && intent.action !== 'wait') {
|
|
337
|
+
// SAME WORDING AS THE TOOL (section 5.2.1): "no dispatch" is an answer, not an
|
|
338
|
+
// error, and a command and a tool describing one state differently is the
|
|
339
|
+
// second-source-of-truth failure this feature is otherwise careful about.
|
|
340
|
+
ctx.notify('info', 'No team dispatch is running. Use /team <brief> to start one.');
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if (intent.action === 'wait') {
|
|
344
|
+
// BOUNDED AND INTERRUPTIBLE, exactly like `team_collect`: the same numbers, the
|
|
345
|
+
// same "stop when the user is owed an answer" rule, so the two cannot disagree
|
|
346
|
+
// about how long "wait" means.
|
|
347
|
+
const seconds = Math.min(TEAM_LIMITS.waitMaxSeconds, Math.max(TEAM_LIMITS.waitMinSeconds, intent.seconds ?? TEAM_LIMITS.waitDefaultSeconds));
|
|
348
|
+
const deadline = Date.now() + seconds * 1000;
|
|
349
|
+
const poll = () => {
|
|
350
|
+
const now = ctx.controller.readTeamControl();
|
|
351
|
+
if (now.live === null || Date.now() >= deadline) {
|
|
352
|
+
const inspection = now.inspection;
|
|
353
|
+
ctx.notify('info', inspection === null
|
|
354
|
+
? 'No team dispatch is running.'
|
|
355
|
+
: renderTeamStatus(inspection, { includeSummary: true }));
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
setTimeout(poll, TEAM_LIMITS.collectPollMs);
|
|
359
|
+
};
|
|
360
|
+
poll();
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
if (typeof ctx.controller.sendTeamControl !== 'function') {
|
|
364
|
+
ctx.notify('warn', 'This host cannot control a dispatch.');
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
const result = ctx.controller.sendTeamControl(intent.action === 'send'
|
|
368
|
+
? { action: 'message', to: intent.target, body: intent.text }
|
|
369
|
+
: intent.action === 'pause'
|
|
370
|
+
? { action: 'pause', label: intent.label, ...(intent.reason ? { reason: intent.reason } : {}) }
|
|
371
|
+
: intent.action === 'resume'
|
|
372
|
+
? { action: 'resume', label: intent.label, ...(intent.message ? { message: intent.message } : {}) }
|
|
373
|
+
: intent.action === 'stop'
|
|
374
|
+
? { action: 'stop', label: intent.target, ...(intent.reason ? { reason: intent.reason } : {}) }
|
|
375
|
+
: { action: 'spawn', brief: intent.brief, count: intent.count }, 'user');
|
|
376
|
+
ctx.notify(result.ok ? 'info' : 'warn', result.detail);
|
|
377
|
+
}
|
|
303
378
|
/** The command body; `registerTeamCommand` is the only registration site. */
|
|
304
379
|
export function runTeamCommand(ctx) {
|
|
380
|
+
// CONTROL VERBS FIRST, AND ONLY WHEN THE LINE PROVES THE INTENT (REV-14).
|
|
381
|
+
//
|
|
382
|
+
// Every verb below is also a perfectly good first word of a brief, so the
|
|
383
|
+
// parser is handed the LIVE labels: `/team stop all` and `/team pause bundle-a`
|
|
384
|
+
// are controls, while `/team stop the leak hunt` falls through to the brief
|
|
385
|
+
// grammar and still dispatches. The quote escape runs before this in
|
|
386
|
+
// `readTeamIntent`, which is why `/team "stop all"` stays a brief.
|
|
387
|
+
const control = readTeamControlIntent(ctx.args,
|
|
388
|
+
// A controller WITHOUT the team surface (a host double, a --no-team session)
|
|
389
|
+
// has no live labels, so every verb stays a brief - which is exactly right:
|
|
390
|
+
// with no dispatch there is nothing to control and the sentence is a request.
|
|
391
|
+
ctx.controller.readTeamControl?.()?.inspection?.children.map((child) => child.label) ?? []);
|
|
392
|
+
if (control !== null) {
|
|
393
|
+
runControlVerb(ctx, control);
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
305
396
|
const intent = readTeamIntent(ctx.args);
|
|
306
397
|
if (intent.kind === 'status') {
|
|
307
398
|
reportStatus(ctx);
|
|
@@ -330,7 +421,7 @@ export function registerTeamCommand(registry) {
|
|
|
330
421
|
registry.register({
|
|
331
422
|
name: 'team',
|
|
332
423
|
rendersInvocationCard: teamRendersInvocationCard,
|
|
333
|
-
description: 'Force team mode and start now: /team <brief
|
|
424
|
+
description: 'Force team mode and start now: /team <brief>|on|off|status|wait|send|pause|resume|stop|spawn',
|
|
334
425
|
run: (ctx) => { runTeamCommand(ctx); },
|
|
335
426
|
});
|
|
336
427
|
}
|
|
@@ -184,6 +184,25 @@ export declare function getMemoryDir(): string;
|
|
|
184
184
|
* (0700 on POSIX); this function only names it.
|
|
185
185
|
*/
|
|
186
186
|
export declare function getGeneDir(): string;
|
|
187
|
+
/**
|
|
188
|
+
* `<home>/redteam` - red team prompt profiles (redteam-prompt-profile 8.1).
|
|
189
|
+
*
|
|
190
|
+
* ITS OWN ROOT, for the reason `getMemoryDir` records: `logs/`, `sessions/` and `skills/` are
|
|
191
|
+
* scan roots, and every extra file inside one is another thing each walk has to recognise and
|
|
192
|
+
* skip. A profile carries customer and target names, so it must not land in `config.json`
|
|
193
|
+
* either (that file holds the API key). Derived from the same `resolution.root`, so the
|
|
194
|
+
* `ARAGON_HOME` / VITEST isolation contract at the top of this file covers it too.
|
|
195
|
+
* The caller creates it (0700 on POSIX, best effort); this function only names it.
|
|
196
|
+
*/
|
|
197
|
+
export declare function getRedTeamDir(): string;
|
|
198
|
+
/**
|
|
199
|
+
* `<home>/redteam/profiles` - one Markdown file per prompt profile (D-2).
|
|
200
|
+
*
|
|
201
|
+
* A SUBDIRECTORY RATHER THAN THE ROOT ITSELF: `redteam/` is the feature's namespace, and a
|
|
202
|
+
* later artifact (a run log, an export) can live beside `profiles/` without every profile scan
|
|
203
|
+
* having to learn a new skip rule.
|
|
204
|
+
*/
|
|
205
|
+
export declare function getRedTeamProfilesDir(): string;
|
|
187
206
|
/** `<home>` — parent of `skills/`, and where sidecar state such as usage lives. */
|
|
188
207
|
export declare function getUserDataDir(): string;
|
|
189
208
|
export declare function getUserSkillsDir(): string;
|
package/dist/config/app-paths.js
CHANGED
|
@@ -281,6 +281,29 @@ export function getMemoryDir() {
|
|
|
281
281
|
export function getGeneDir() {
|
|
282
282
|
return join(resolution.root, 'genes');
|
|
283
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* `<home>/redteam` - red team prompt profiles (redteam-prompt-profile 8.1).
|
|
286
|
+
*
|
|
287
|
+
* ITS OWN ROOT, for the reason `getMemoryDir` records: `logs/`, `sessions/` and `skills/` are
|
|
288
|
+
* scan roots, and every extra file inside one is another thing each walk has to recognise and
|
|
289
|
+
* skip. A profile carries customer and target names, so it must not land in `config.json`
|
|
290
|
+
* either (that file holds the API key). Derived from the same `resolution.root`, so the
|
|
291
|
+
* `ARAGON_HOME` / VITEST isolation contract at the top of this file covers it too.
|
|
292
|
+
* The caller creates it (0700 on POSIX, best effort); this function only names it.
|
|
293
|
+
*/
|
|
294
|
+
export function getRedTeamDir() {
|
|
295
|
+
return join(resolution.root, 'redteam');
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* `<home>/redteam/profiles` - one Markdown file per prompt profile (D-2).
|
|
299
|
+
*
|
|
300
|
+
* A SUBDIRECTORY RATHER THAN THE ROOT ITSELF: `redteam/` is the feature's namespace, and a
|
|
301
|
+
* later artifact (a run log, an export) can live beside `profiles/` without every profile scan
|
|
302
|
+
* having to learn a new skip rule.
|
|
303
|
+
*/
|
|
304
|
+
export function getRedTeamProfilesDir() {
|
|
305
|
+
return join(getRedTeamDir(), 'profiles');
|
|
306
|
+
}
|
|
284
307
|
/** `<home>` — parent of `skills/`, and where sidecar state such as usage lives. */
|
|
285
308
|
export function getUserDataDir() {
|
|
286
309
|
return resolution.root;
|
package/dist/config/load.d.ts
CHANGED
|
@@ -273,6 +273,14 @@ export interface CliFlags {
|
|
|
273
273
|
*/
|
|
274
274
|
redteam?: boolean;
|
|
275
275
|
noRedteam?: boolean;
|
|
276
|
+
/**
|
|
277
|
+
* `--redteam-prompt <path>` (redteam-prompt-profile 7.3): the prompt profile for THIS session.
|
|
278
|
+
*
|
|
279
|
+
* LAUNCH-ONLY LIKE THE PAIR ABOVE: it is never written to the store, and `undefined` (the
|
|
280
|
+
* flag was absent) leaves both the persisted `redteam.profile` and the built-in text in
|
|
281
|
+
* charge. It reaches the wiring through `makeController`, not through a config key.
|
|
282
|
+
*/
|
|
283
|
+
redTeamPrompt?: string;
|
|
276
284
|
/**
|
|
277
285
|
* `--no-gene` (gene-bank spec 14.3), carried as `true` ONLY. A lone negative flag makes
|
|
278
286
|
* commander default its option (`opts.gene`) to `true`, so `cli.tsx` translates the explicit
|
|
@@ -258,32 +258,53 @@ export async function rebuildScope(env, state, paths) {
|
|
|
258
258
|
env.setRebuilding(state.sid, false);
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* How often a reload looks at the snapshot/journal pair again before it gives up and rescans
|
|
263
|
+
* the heads. Three attempts cover the writer's compaction window: the replacement rename, the
|
|
264
|
+
* journal truncation and the first append of the next generation all land inside it.
|
|
265
|
+
*/
|
|
266
|
+
const RELOAD_ATTEMPTS = 3;
|
|
261
267
|
async function reloadScope(env, state, paths, first) {
|
|
262
268
|
let stamps = first;
|
|
263
|
-
for (let attempt = 0; attempt <
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
269
|
+
for (let attempt = 0; attempt < RELOAD_ATTEMPTS; attempt += 1) {
|
|
270
|
+
if (stamps.snap === null)
|
|
271
|
+
break; // no snapshot at all: the heads are the only truth
|
|
272
|
+
const snapshot = await env.io.readJson(paths.snapshot);
|
|
273
|
+
if (snapshot !== null) {
|
|
274
|
+
if (!usableSnapshot(snapshot, env.vecAlgo))
|
|
275
|
+
break; // schema / vecAlgo moved on
|
|
276
|
+
const changed = replaceRows(env, state, snapshot.rows);
|
|
277
|
+
state.gen = snapshot.gen;
|
|
278
|
+
state.journalOffset = snapshot.journalOffset;
|
|
279
|
+
state.journalLines = 0;
|
|
280
|
+
const tail = await tailJournal(env, state, paths.journal);
|
|
281
|
+
if (tail.status === 'ok') {
|
|
282
|
+
commit(state, stamps);
|
|
283
|
+
const applied = snapshot.rows.length + tail.applied;
|
|
284
|
+
return done('reloaded', applied, changed || tail.visibleChanged);
|
|
285
|
+
}
|
|
286
|
+
if (tail.status === 'corrupt')
|
|
287
|
+
break; // a line that does not parse: heads are the truth
|
|
275
288
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
//
|
|
289
|
+
// Either the read raced a rename (a snapshot being replaced can read as absent for a
|
|
290
|
+
// moment) or the journal was rewritten under the offset we took from it. Both are the
|
|
291
|
+
// compaction window, not corruption, so look at the current pair again.
|
|
279
292
|
stamps = await restat(env, paths);
|
|
280
293
|
}
|
|
281
294
|
return rebuildScope(env, state, paths);
|
|
282
295
|
}
|
|
296
|
+
/**
|
|
297
|
+
* A failed tail is NOT yet a reason to rescan the heads. `truncated` means our byte offset no
|
|
298
|
+
* longer exists in the file, and `corrupt` covers the same case one step further on: a journal
|
|
299
|
+
* truncated and refilled by another process' compaction can be longer than our offset while our
|
|
300
|
+
* offset now points into the middle of a line, and the first "line" read from there cannot parse.
|
|
301
|
+
* The snapshot knows the offset that does belong to the current journal, so re-read it first -
|
|
302
|
+
* only when the snapshot cannot square the pair either is a head rescan the honest answer.
|
|
303
|
+
*/
|
|
283
304
|
async function tailScope(env, state, paths, stamps) {
|
|
284
305
|
const tail = await tailJournal(env, state, paths.journal);
|
|
285
306
|
if (tail.status !== 'ok')
|
|
286
|
-
return
|
|
307
|
+
return reloadScope(env, state, paths, stamps);
|
|
287
308
|
commit(state, stamps);
|
|
288
309
|
return done('tailed', tail.applied, tail.visibleChanged);
|
|
289
310
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
5
|
*
|
|
6
6
|
* THREE LAYERS, EACH VISIBLE:
|
|
7
|
-
* - per TASK tokens (`gene.curatorTaskTokens`), turns (
|
|
7
|
+
* - per TASK tokens (`gene.curatorTaskTokens`), turns (20) and wall clock (240 s). A task that
|
|
8
8
|
* crosses one is stopped and retried later; it cannot run away.
|
|
9
9
|
* - per DAY a rolling 24 h sum of every `tokens` field in the run log (the learner's, the
|
|
10
10
|
* curator's, the validators' and retrieval's share ONE budget). At the limit the
|
|
@@ -133,6 +133,12 @@ export declare class GeneCurator {
|
|
|
133
133
|
idle(): Promise<void>;
|
|
134
134
|
/** Test and shutdown helper: schedule, wait, and repeat until a pass finds nothing to do. */
|
|
135
135
|
runUntilIdle(maxRounds?: number): Promise<void>;
|
|
136
|
+
/**
|
|
137
|
+
* Test helper: one lease heartbeat, awaited. The scheduler calls `leaseBeat` fire-and-forget, so
|
|
138
|
+
* a test that only advances the clock and fires the timer cannot tell "the beat has not run yet"
|
|
139
|
+
* from "the beat did nothing".
|
|
140
|
+
*/
|
|
141
|
+
beatNow(): Promise<void>;
|
|
136
142
|
private kick;
|
|
137
143
|
private notify;
|
|
138
144
|
private tickOnce;
|
|
@@ -268,6 +268,14 @@ export class GeneCurator {
|
|
|
268
268
|
return;
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Test helper: one lease heartbeat, awaited. The scheduler calls `leaseBeat` fire-and-forget, so
|
|
273
|
+
* a test that only advances the clock and fires the timer cannot tell "the beat has not run yet"
|
|
274
|
+
* from "the beat did nothing".
|
|
275
|
+
*/
|
|
276
|
+
async beatNow() {
|
|
277
|
+
await this.leaseBeat();
|
|
278
|
+
}
|
|
271
279
|
// ---- the pass -----------------------------------------------------------------
|
|
272
280
|
kick() {
|
|
273
281
|
this.scheduler.after(0, () => void this.tick());
|
|
@@ -179,7 +179,10 @@ async function modelOutcome(deps, env, summary) {
|
|
|
179
179
|
if (ctx.finish !== null)
|
|
180
180
|
return finishedOutcome(deps, env, ctx.finish);
|
|
181
181
|
await settleLeftovers(env, 'reject_failed');
|
|
182
|
-
|
|
182
|
+
// Tokens and turns are two different ceilings, and which one was hit decides what to do next:
|
|
183
|
+
// `task_tokens` means raise `gene.curatorTaskTokens`, `task_turns` means the task is doing too
|
|
184
|
+
// many small steps (RC-6). One `task_budget` name used to hide that from the run log.
|
|
185
|
+
const error = summary.stop === 'tokens' ? 'task_tokens' : summary.stop === 'turns' ? 'task_turns' : 'no_finish';
|
|
183
186
|
return { kind: 'fail', failure: { kind: 'transient', error }, infra: false };
|
|
184
187
|
}
|
|
185
188
|
async function runModelTask(deps, claimed, plan, signal) {
|