@aragon-agent/cli 0.6.54 → 0.6.55

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +4111 -4042
  3. package/dist/agent/controller.d.ts +72 -0
  4. package/dist/agent/controller.js +212 -0
  5. package/dist/agent/redteam-prompt.d.ts +47 -0
  6. package/dist/agent/redteam-prompt.js +161 -0
  7. package/dist/agent/redteam-wiring.d.ts +159 -0
  8. package/dist/agent/redteam-wiring.js +349 -0
  9. package/dist/agent/system-prompt.d.ts +13 -0
  10. package/dist/agent/system-prompt.js +7 -0
  11. package/dist/app/App.d.ts +10 -1
  12. package/dist/app/App.js +133 -22
  13. package/dist/app/use-redteam-mode.d.ts +56 -0
  14. package/dist/app/use-redteam-mode.js +121 -0
  15. package/dist/cli.js +53 -3
  16. package/dist/commands/builtins.js +39 -1
  17. package/dist/commands/catalog.js +4 -0
  18. package/dist/commands/index-build.js +2 -1
  19. package/dist/commands/redteam-command.d.ts +22 -0
  20. package/dist/commands/redteam-command.js +141 -0
  21. package/dist/config/env.d.ts +2 -1
  22. package/dist/config/env.js +12 -1
  23. package/dist/config/load.d.ts +12 -0
  24. package/dist/config/load.js +10 -1
  25. package/dist/config/redteam-launch.d.ts +77 -0
  26. package/dist/config/redteam-launch.js +58 -0
  27. package/dist/config/store.js +11 -1
  28. package/dist/config/ui-state.d.ts +44 -0
  29. package/dist/config/ui-state.js +38 -0
  30. package/dist/host/controller-factory.d.ts +8 -0
  31. package/dist/host/controller-factory.js +7 -0
  32. package/dist/session/checkpoint.d.ts +15 -0
  33. package/dist/session/checkpoint.js +18 -0
  34. package/dist/session/persist.d.ts +21 -0
  35. package/dist/session/persist.js +10 -0
  36. package/dist/session/startup-session.d.ts +11 -2
  37. package/dist/session/startup-session.js +12 -2
  38. package/dist/session/validate-session.js +31 -0
  39. package/dist/team/runtime.d.ts +11 -0
  40. package/dist/team/runtime.js +6 -0
  41. package/dist/team/subagent.d.ts +21 -0
  42. package/dist/team/subagent.js +7 -0
  43. package/dist/tools/index.d.ts +24 -0
  44. package/dist/tools/index.js +20 -3
  45. package/package.json +3 -3
  46. package/skills/project-indexer/SKILL.md +275 -147
  47. package/skills/project-indexer/templates/artifact-hygiene-template.md +14 -0
  48. package/skills/project-indexer/templates/config-template.md +12 -0
  49. package/skills/project-indexer/templates/index-template.md +4 -0
@@ -47,6 +47,10 @@ export const BUILTIN_COMMAND_CATALOG = [
47
47
  { name: 'agents', aliases: [], description: 'Open the subagent board: every child, its facts and its timeline' },
48
48
  { name: 'subagent', aliases: [], description: 'Deprecated alias of /team - same arguments' },
49
49
  { name: 'team', aliases: [], description: 'Force team mode and start now: /team <brief>; /team [on [n]|off|status]' },
50
+ // red-team-security-mode 4.8: the fourth session posture. Listed here for the reason every
51
+ // command above is - the catalog is what the slash menu and the drift test read, so a
52
+ // command that exists only in the registry is one the user cannot discover.
53
+ { name: 'redteam', aliases: [], description: 'Red team mode: /redteam [status|on|off|scope <one line>]' },
50
54
  { name: 'gov', aliases: [], description: 'Governed multi-agent team: /gov help' },
51
55
  { name: 'keys', aliases: [], description: 'List every keyboard shortcut (opens the drawer)' },
52
56
  { name: 'task', aliases: [], description: 'Show the header task summary (/task refresh regenerates it)' },
@@ -65,7 +65,8 @@ export function buildIndexConfirmSummary(input) {
65
65
  `\nRuns the bundled "${INDEX_SKILL_NAME}" skill as a normal agent turn:` +
66
66
  `\n- scans the workspace (exclusions apply), extracts exported symbols` +
67
67
  `\n- writes .claude-index/index.md and .claude-index/config.md` +
68
- `\n- updates CLAUDE.md (index section + Clean Code Guidelines)` +
68
+ `\n- writes matching CLAUDE.md and AGENTS.md (project index + optional Clean Code Guidelines)` +
69
+ `\n- adds rules for results in runs/ and checking temporary files before completion` +
69
70
  `${existing}` +
70
71
  `\nWorkspace: ${input.cwd}` +
71
72
  `\nEvery step is visible in the transcript; Esc interrupts.`);
@@ -0,0 +1,22 @@
1
+ /**
2
+ * `/redteam`: report, enter, leave, and declare the engagement scope
3
+ * (red-team-security-mode 4.8 / D-18).
4
+ *
5
+ * ASCII ONLY: `src/commands/**` is inside `glyphs.test.ts::inScope`.
6
+ *
7
+ * FOUR SUBCOMMANDS AND ONE SHARED ENTRY. `on` / `off` go through `controller.setRedTeam()`,
8
+ * the same call `Ctrl+R` makes, so a turn in flight defers the arming instead of being refused
9
+ * and the wording is the shared toast. `status` never refuses, in any posture and any session:
10
+ * a security posture nobody can query is a posture the user cannot verify - and the question
11
+ * "am I in red team mode right now" is exactly the one a person asks while looking at a
12
+ * destructive command in the transcript.
13
+ *
14
+ * THE COMMAND DOES NOT OPEN THE WAIVER OVERLAY. `on` without an accepted waiver answers with
15
+ * the sentence that names the key instead: the overlay is App state, and a command that opened
16
+ * it could not settle it (accepting has to re-plan the request and push the banner).
17
+ */
18
+ import type { CommandContext, CommandRegistry } from './registry.js';
19
+ /** Where the `/redteam` handler lives, so `builtins.ts` only adds one registration. */
20
+ export declare function runRedTeamCommand(ctx: CommandContext): void;
21
+ /** Registered from `builtins.ts` with one line, next to every other subsystem. */
22
+ export declare function registerRedTeamCommand(registry: CommandRegistry): void;
@@ -0,0 +1,141 @@
1
+ /**
2
+ * `/redteam`: report, enter, leave, and declare the engagement scope
3
+ * (red-team-security-mode 4.8 / D-18).
4
+ *
5
+ * ASCII ONLY: `src/commands/**` is inside `glyphs.test.ts::inScope`.
6
+ *
7
+ * FOUR SUBCOMMANDS AND ONE SHARED ENTRY. `on` / `off` go through `controller.setRedTeam()`,
8
+ * the same call `Ctrl+R` makes, so a turn in flight defers the arming instead of being refused
9
+ * and the wording is the shared toast. `status` never refuses, in any posture and any session:
10
+ * a security posture nobody can query is a posture the user cannot verify - and the question
11
+ * "am I in red team mode right now" is exactly the one a person asks while looking at a
12
+ * destructive command in the transcript.
13
+ *
14
+ * THE COMMAND DOES NOT OPEN THE WAIVER OVERLAY. `on` without an accepted waiver answers with
15
+ * the sentence that names the key instead: the overlay is App state, and a command that opened
16
+ * it could not settle it (accepting has to re-plan the request and push the banner).
17
+ */
18
+ import { redTeamStatusLines, REDTEAM_COMMAND, REDTEAM_TOAST, } from '@aragon-agent/tui/ui/redteam-copy';
19
+ import { redTeamToast, } from '@aragon-agent/tui/model/redteam/redteam-mode';
20
+ import { UNAVAILABLE_RED_TEAM_VIEW } from '../agent/redteam-wiring.js';
21
+ /** Where the `/redteam` handler lives, so `builtins.ts` only adds one registration. */
22
+ export function runRedTeamCommand(ctx) {
23
+ const args = ctx.args.trim();
24
+ const [verb = '', ...rest] = args.length > 0 ? args.split(/\s+/) : [];
25
+ switch (verb.toLowerCase()) {
26
+ case '':
27
+ case 'status':
28
+ reportStatus(ctx);
29
+ return;
30
+ case 'on':
31
+ request(ctx, { kind: 'on' });
32
+ return;
33
+ case 'off':
34
+ request(ctx, { kind: 'off' });
35
+ return;
36
+ case 'scope':
37
+ setScope(ctx, rest.join(' ').trim());
38
+ return;
39
+ default:
40
+ ctx.notify('warn', REDTEAM_COMMAND.usage);
41
+ }
42
+ }
43
+ /** The view, or the "no chain here" shape when the controller has none (D-17). */
44
+ function viewOf(ctx) {
45
+ const port = ctx.controller;
46
+ return typeof port.getRedTeamView === 'function'
47
+ ? port.getRedTeamView()
48
+ : UNAVAILABLE_RED_TEAM_VIEW;
49
+ }
50
+ /**
51
+ * The four status lines (RV-18): effective state, scope, what the confirmation gate is doing,
52
+ * and what this mode does NOT lift.
53
+ *
54
+ * The third line is the one the whole feature is judged on (R-13): with `confirmTools` off -
55
+ * the default - it must say that NOTHING about permissions changed, because that is the truth
56
+ * and the disclaimer's clause 2 depends on the same truth.
57
+ */
58
+ function reportStatus(ctx) {
59
+ const view = viewOf(ctx);
60
+ const config = ctx.controller.getConfig();
61
+ const lines = redTeamStatusLines(view, {
62
+ confirmTools: config.confirmTools === true,
63
+ bypassConfirm: config.redteam?.bypassConfirm !== false,
64
+ posture: postureOf(ctx),
65
+ });
66
+ ctx.notify('info', lines.join('\n'));
67
+ }
68
+ /** The live posture, as the two axes the copy table needs to NAME it. */
69
+ function postureOf(ctx) {
70
+ const posture = typeof ctx.controller.getPosture === 'function'
71
+ ? ctx.controller.getPosture()
72
+ : 'build';
73
+ return {
74
+ mode: posture === 'plan' || posture === 'plan_govern' ? 'plan' : 'build',
75
+ governOn: posture === 'govern' || posture === 'plan_govern',
76
+ };
77
+ }
78
+ /** `on` / `off`: one entry, one outcome, one sentence. */
79
+ function request(ctx, req) {
80
+ const port = ctx.controller;
81
+ if (typeof port.setRedTeam !== 'function') {
82
+ ctx.notify('warn', REDTEAM_TOAST.unavailable);
83
+ return;
84
+ }
85
+ const outcome = port.setRedTeam(req);
86
+ if (!outcome.ok && outcome.refusal === 'disclaimer') {
87
+ // NAMES THE KEY: the only surface that can show the waiver is the terminal's overlay.
88
+ ctx.notify('warn', REDTEAM_COMMAND.notOn);
89
+ return;
90
+ }
91
+ reportOutcome(ctx, req, outcome);
92
+ }
93
+ function reportOutcome(ctx, req, outcome) {
94
+ const view = viewOf(ctx);
95
+ const config = ctx.controller.getConfig();
96
+ // "BACK ON" IS ONLY TRUE IF THEY WERE OFF (RV-1 / D-19). Both halves are needed: a session
97
+ // with no `--confirm` gate never had confirmations to turn on, and one with
98
+ // `bypassConfirm: false` never turned them off.
99
+ const hadBypass = config.confirmTools === true && config.redteam?.bypassConfirm !== false;
100
+ const toast = redTeamToast(outcome, {
101
+ request: req.kind,
102
+ scope: view.scope,
103
+ bypassesConfirm: view.bypassesConfirm,
104
+ wasBypassing: outcome.ok && outcome.wasArmed && hadBypass,
105
+ waiverAccepted: view.waiverAccepted,
106
+ });
107
+ if (toast)
108
+ ctx.notify(toast.level, toast.text);
109
+ }
110
+ /**
111
+ * `/redteam scope <one line>` sets it; `/redteam scope` with no argument CLEARS it.
112
+ *
113
+ * The refusal cases are reported rather than silently truncated (4.6 step 4): a user who
114
+ * typed a 300-cell scope has to learn that nothing was set, not discover later that the
115
+ * boundary they believed in was 200 cells of something else.
116
+ */
117
+ function setScope(ctx, line) {
118
+ const port = ctx.controller;
119
+ if (typeof port.setRedTeamScope !== 'function') {
120
+ ctx.notify('warn', REDTEAM_TOAST.unavailable);
121
+ return;
122
+ }
123
+ const result = port.setRedTeamScope(line);
124
+ if (!result.ok) {
125
+ ctx.notify('warn', result.reason === 'too-long'
126
+ ? REDTEAM_COMMAND.scopeTooLong
127
+ : REDTEAM_COMMAND.scopeMultiLine);
128
+ return;
129
+ }
130
+ ctx.notify('info', result.scope === null
131
+ ? REDTEAM_TOAST.scopeCleared
132
+ : `${REDTEAM_COMMAND.scopeSetPrefix}${result.scope}`);
133
+ }
134
+ /** Registered from `builtins.ts` with one line, next to every other subsystem. */
135
+ export function registerRedTeamCommand(registry) {
136
+ registry.register({
137
+ name: 'redteam',
138
+ description: 'Red team mode: /redteam [status|on|off|scope <one line>]',
139
+ run: (ctx) => { runRedTeamCommand(ctx); },
140
+ });
141
+ }
@@ -23,7 +23,8 @@
23
23
  * ARAGON_JOBS_PERSIST_LOG, ARAGON_JOBS_NOTICE_STEER,
24
24
  * ARAGON_PROMPTS (the quick-prompt library's `enabled` switch, and only that),
25
25
  * ARAGON_MEMORY (agent memory's kill switch: `0` turns it off, nothing turns it on),
26
- * ARAGON_GOVERNANCE (a KILL switch: `0` disables governance mode, nothing enables it).
26
+ * ARAGON_GOVERNANCE (a KILL switch: `0` disables governance mode, nothing enables it),
27
+ * ARAGON_REDTEAM (a KILL switch: `0` disables red team mode, nothing enables it).
27
28
  *
28
29
  * READ ELSEWHERE, ON PURPOSE: `ARAGON_UPDATE_REGISTRY` and `npm_config_registry`
29
30
  * are resolved by `update/registry.ts::resolveRegistryUrl`, NOT here, because
@@ -23,7 +23,8 @@
23
23
  * ARAGON_JOBS_PERSIST_LOG, ARAGON_JOBS_NOTICE_STEER,
24
24
  * ARAGON_PROMPTS (the quick-prompt library's `enabled` switch, and only that),
25
25
  * ARAGON_MEMORY (agent memory's kill switch: `0` turns it off, nothing turns it on),
26
- * ARAGON_GOVERNANCE (a KILL switch: `0` disables governance mode, nothing enables it).
26
+ * ARAGON_GOVERNANCE (a KILL switch: `0` disables governance mode, nothing enables it),
27
+ * ARAGON_REDTEAM (a KILL switch: `0` disables red team mode, nothing enables it).
27
28
  *
28
29
  * READ ELSEWHERE, ON PURPOSE: `ARAGON_UPDATE_REGISTRY` and `npm_config_registry`
29
30
  * are resolved by `update/registry.ts::resolveRegistryUrl`, NOT here, because
@@ -348,6 +349,16 @@ export function readEnvConfig() {
348
349
  if (memory === '0' || memory === 'false' || memory === 'off' || memory === 'no') {
349
350
  partial.memory = { enabled: false };
350
351
  }
352
+ // ARAGON_REDTEAM=0 is red team mode's KILL switch (red-team-security-mode 4.8 / D-15): it
353
+ // can only switch `enabled` OFF, and it outranks the config file. Like ARAGON_MEMORY it is
354
+ // not a toggle - `ARAGON_REDTEAM=1` writes nothing - and that asymmetry is the point: an
355
+ // environment must never be able to put a user into a liability posture the user's own
356
+ // config or `--no-redteam` turned off, because the waiver lives in the user's session, not
357
+ // in the shell that launched it.
358
+ const redteam = process.env.ARAGON_REDTEAM?.trim().toLowerCase();
359
+ if (redteam === '0' || redteam === 'false' || redteam === 'off' || redteam === 'no') {
360
+ partial.redteam = { enabled: false };
361
+ }
351
362
  // ARAGON_TASK_SUMMARY is the header label's kill switch
352
363
  // (tui-shortcut-drawer-and-task-summary §4.8 / P2-7), and it maps `enabled` and
353
364
  // NOTHING ELSE - the same wording and the same reason as the block above. A
@@ -261,6 +261,18 @@ export interface CliFlags {
261
261
  * `undefined` for silence. Launch-only: never written to the store.
262
262
  */
263
263
  memory?: boolean;
264
+ /**
265
+ * `--redteam` / `--no-redteam` (red-team-security-mode 4.8), carried as a PAIR for the
266
+ * reason `--compaction` above records: `redteam.enabled` is persisted and defaults to
267
+ * `true`, so a lone `--no-redteam` would make commander default the option to `true`, and
268
+ * the flag would then overwrite a stored `false` on every run that passed no flag at all.
269
+ * `cli.tsx` forwards `undefined` for silence.
270
+ *
271
+ * BOTH ARE LAUNCH-ONLY: neither is written to the store. `--redteam` additionally means
272
+ * "start armed", which is session state and is resolved by `redteam-launch.ts`.
273
+ */
274
+ redteam?: boolean;
275
+ noRedteam?: boolean;
264
276
  /**
265
277
  * `--resume <id|path>` - continue a saved session under a NEW id
266
278
  * (tui-session-id-resume 4).
@@ -6,7 +6,7 @@
6
6
  * legitimately long single tool run can never be watchdog-killed.
7
7
  */
8
8
  import process from 'node:process';
9
- import { DEFAULT_CONFIG, DEFAULT_SCROLL_MODE, IDLE_TIMEOUT_MARGIN_MS, clampDensity, clampHumanTimeout, clampCompactionConfig, clampLogConfig, clampFastConfig, clampRetryConfig, clampSkillsConfig, clampTeamConfig, clampTodoConfig, clampBashConfig, clampJobsConfig, clampPromptsConfig, clampMemoryConfig, clampTaskSummaryConfig, clampUpdateConfig, clampTheme, clampThinkingLevel, clampContextWindow, clampMaxTokens, clampMaxRenderInterval, clampScrollMode, clampScrollResumeMs, clampTranscriptRetain, clampTranscriptWindow, coercePositiveInt, isAutoToken, isSkillsToolPolicyMode, legacyTeamCeilingPatch, legacyTeamFanoutPatch, LEGACY_TEAM_FANOUT_DEFAULTS, parseThresholdInput, } from '@aragon-agent/tui/model/config/schema';
9
+ import { DEFAULT_CONFIG, DEFAULT_SCROLL_MODE, IDLE_TIMEOUT_MARGIN_MS, clampDensity, clampHumanTimeout, clampCompactionConfig, clampLogConfig, clampFastConfig, clampRetryConfig, clampSkillsConfig, clampTeamConfig, clampTodoConfig, clampBashConfig, clampJobsConfig, clampPromptsConfig, clampMemoryConfig, clampRedTeamConfig, clampTaskSummaryConfig, clampUpdateConfig, clampTheme, clampThinkingLevel, clampContextWindow, clampMaxTokens, clampMaxRenderInterval, clampScrollMode, clampScrollResumeMs, clampTranscriptRetain, clampTranscriptWindow, coercePositiveInt, isAutoToken, isSkillsToolPolicyMode, legacyTeamCeilingPatch, legacyTeamFanoutPatch, LEGACY_TEAM_FANOUT_DEFAULTS, parseThresholdInput, } from '@aragon-agent/tui/model/config/schema';
10
10
  import { loadDotenv, readEnvConfig, readEnvDisabledSkills } from './env.js';
11
11
  import { readConfigFile, updatePersistedConfig } from './store.js';
12
12
  import { projectModelProfiles, resolveModelProfileState, resolveModelRoleKey, } from '@aragon-agent/tui/model/config/model-profile-resolution';
@@ -806,6 +806,15 @@ export function loadConfig(flags = {}, options = {}) {
806
806
  ...(env.partial.memory ?? {}),
807
807
  ...(flags.memory === false ? { enabled: false } : {}),
808
808
  }),
809
+ // Red team / security mode: file < env kill switch < `--no-redteam`, clamped like every
810
+ // section. The kill switches can only switch `enabled` OFF and are applied AFTER the file
811
+ // so they outrank it - an environment must never be able to switch the mode ON (D-15).
812
+ redteam: clampRedTeamConfig({
813
+ ...DEFAULT_CONFIG.redteam,
814
+ ...(file.redteam ?? {}),
815
+ ...(env.partial.redteam ?? {}),
816
+ ...(flags.noRedteam === true ? { enabled: false } : {}),
817
+ }),
809
818
  initialPosture,
810
819
  cwd,
811
820
  color,
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Command-line validation for `--redteam` / `--no-redteam` (red-team-security-mode 4.8).
3
+ *
4
+ * PURE, AND OUT OF `cli.tsx` ON PURPOSE: that file is far past the size limit, and these
5
+ * rules are the kind that regress silently - a missing headless rule ships a "start armed"
6
+ * flag into `aragon exec`, where nobody can accept a waiver. `cli.tsx` gathers the facts and
7
+ * prints the message.
8
+ *
9
+ * TWO RULES, AND THE ONE THAT IS ABSENT IS THE POINT (RV-1 / D-20). v1 refused
10
+ * `--redteam --confirm`; that was backwards. `--confirm` is the NARROWER authorization - a
11
+ * user who enters red team mode with the confirmation gate switched on is a configuration
12
+ * this very feature supports (`redteam.bypassConfirm=false`) - so the pair is ALLOWED and the
13
+ * banner and `/redteam status` say what happened to the gate.
14
+ *
15
+ * ASCII ONLY: `src/config/**` is inside the glyph scanner's scope.
16
+ */
17
+ export interface RedTeamLaunchInput {
18
+ /** `--redteam`: start this session armed. */
19
+ redTeam?: boolean;
20
+ /** `--no-redteam`: unregister the whole chain for this launch. */
21
+ noRedTeam?: boolean;
22
+ /** `ARAGON_REDTEAM=0` or `redteam.enabled: false` in the resolved config. */
23
+ unavailable?: boolean;
24
+ /** The waiver version `state.json` holds; `0` means never accepted. */
25
+ waiverVersion: number;
26
+ /**
27
+ * The run cannot reach a human: `-p/--print`, the `exec` subcommand, piped stdin or a
28
+ * non-TTY stdout. A waiver cannot be accepted there, and a posture nobody can leave is
29
+ * worse than no posture.
30
+ */
31
+ headless: boolean;
32
+ }
33
+ export interface RedTeamLaunchDecision {
34
+ /** The chain exists in this session at all. */
35
+ available: boolean;
36
+ /** Start with the mode armed. */
37
+ startArmed: boolean;
38
+ /** `--redteam` was asked for and will NOT be honoured; the reason was already reported. */
39
+ ignored: boolean;
40
+ }
41
+ export type RedTeamLaunchCheck = {
42
+ ok: true;
43
+ decision: RedTeamLaunchDecision;
44
+ } | {
45
+ ok: false;
46
+ message: string;
47
+ };
48
+ export declare const REDTEAM_HEADLESS_MESSAGE = "--redteam is a terminal session posture; it is not available in print or exec mode.";
49
+ export declare const REDTEAM_UNAVAILABLE_MESSAGE: string;
50
+ /** `--redteam needs the disclaimer accepted first.` - the message names the exact next step. */
51
+ export declare const REDTEAM_WAIVER_MESSAGE = "--redteam needs the disclaimer accepted first. Run aragon, press Ctrl+R and accept it.";
52
+ /**
53
+ * Resolve the launch. ORDER IS THE CONTRACT, and it is the order of the two things a user
54
+ * cannot fix by dropping another flag: headless first (no terminal, so no waiver and no way
55
+ * out), then the waiver itself.
56
+ *
57
+ * `--no-redteam` and an unavailable config are NOT errors even when `--redteam` was also
58
+ * passed: the negative wins, the session starts disarmed, and the caller reports it once.
59
+ * Making that combination fatal would punish a wrapper script that always passes
60
+ * `--redteam` and sometimes adds `--no-redteam`.
61
+ */
62
+ export declare function validateRedTeamLaunch(input: RedTeamLaunchInput): RedTeamLaunchCheck;
63
+ /** The root-level options these rules read, as commander materialises them. */
64
+ export interface RedTeamRootOptions {
65
+ /** `--redteam` is declared alone, so an absent flag reads `undefined`. */
66
+ redteam?: boolean;
67
+ /** `--no-redteam` is declared alone: `false` when given. */
68
+ noRedteamFlag?: boolean;
69
+ }
70
+ export interface RedTeamCommandContext {
71
+ commandName: string;
72
+ isRootAction: boolean;
73
+ stdinIsTty: boolean;
74
+ stdoutIsTty: boolean;
75
+ }
76
+ /** The `preAction` hook's decision: `exec` is always headless, the root action is when piped. */
77
+ export declare function checkRedTeamCommandLine(options: RedTeamRootOptions, context: RedTeamCommandContext, waiverVersion: number, unavailable: boolean): RedTeamLaunchCheck;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Command-line validation for `--redteam` / `--no-redteam` (red-team-security-mode 4.8).
3
+ *
4
+ * PURE, AND OUT OF `cli.tsx` ON PURPOSE: that file is far past the size limit, and these
5
+ * rules are the kind that regress silently - a missing headless rule ships a "start armed"
6
+ * flag into `aragon exec`, where nobody can accept a waiver. `cli.tsx` gathers the facts and
7
+ * prints the message.
8
+ *
9
+ * TWO RULES, AND THE ONE THAT IS ABSENT IS THE POINT (RV-1 / D-20). v1 refused
10
+ * `--redteam --confirm`; that was backwards. `--confirm` is the NARROWER authorization - a
11
+ * user who enters red team mode with the confirmation gate switched on is a configuration
12
+ * this very feature supports (`redteam.bypassConfirm=false`) - so the pair is ALLOWED and the
13
+ * banner and `/redteam status` say what happened to the gate.
14
+ *
15
+ * ASCII ONLY: `src/config/**` is inside the glyph scanner's scope.
16
+ */
17
+ import { REDTEAM_DISCLAIMER_VERSION } from '@aragon-agent/tui/model/redteam/limits';
18
+ export const REDTEAM_HEADLESS_MESSAGE = '--redteam is a terminal session posture; it is not available in print or exec mode.';
19
+ export const REDTEAM_UNAVAILABLE_MESSAGE = '--redteam was requested, but red team mode is off for this launch '
20
+ + '(--no-redteam, redteam.enabled=false or ARAGON_REDTEAM=0).';
21
+ /** `--redteam needs the disclaimer accepted first.` - the message names the exact next step. */
22
+ export const REDTEAM_WAIVER_MESSAGE = '--redteam needs the disclaimer accepted first. Run aragon, press Ctrl+R and accept it.';
23
+ /**
24
+ * Resolve the launch. ORDER IS THE CONTRACT, and it is the order of the two things a user
25
+ * cannot fix by dropping another flag: headless first (no terminal, so no waiver and no way
26
+ * out), then the waiver itself.
27
+ *
28
+ * `--no-redteam` and an unavailable config are NOT errors even when `--redteam` was also
29
+ * passed: the negative wins, the session starts disarmed, and the caller reports it once.
30
+ * Making that combination fatal would punish a wrapper script that always passes
31
+ * `--redteam` and sometimes adds `--no-redteam`.
32
+ */
33
+ export function validateRedTeamLaunch(input) {
34
+ const unavailable = input.unavailable === true || input.noRedTeam === true;
35
+ const requested = input.redTeam === true && !unavailable;
36
+ if (!requested) {
37
+ return { ok: true, decision: { available: !unavailable, startArmed: false, ignored: false } };
38
+ }
39
+ if (input.headless)
40
+ return { ok: false, message: REDTEAM_HEADLESS_MESSAGE };
41
+ if (input.waiverVersion < REDTEAM_DISCLAIMER_VERSION) {
42
+ return { ok: false, message: REDTEAM_WAIVER_MESSAGE };
43
+ }
44
+ return { ok: true, decision: { available: true, startArmed: true, ignored: false } };
45
+ }
46
+ /** The `preAction` hook's decision: `exec` is always headless, the root action is when piped. */
47
+ export function checkRedTeamCommandLine(options, context, waiverVersion, unavailable) {
48
+ const headless = context.commandName === 'exec'
49
+ || (context.isRootAction
50
+ && (options.redteam === true && (!context.stdinIsTty || !context.stdoutIsTty)));
51
+ return validateRedTeamLaunch({
52
+ ...(options.redteam === true ? { redTeam: true } : {}),
53
+ ...(options.noRedteamFlag === false ? { noRedTeam: true } : {}),
54
+ unavailable,
55
+ waiverVersion,
56
+ headless,
57
+ });
58
+ }
@@ -17,7 +17,7 @@ import { getConfigPath, getSessionsDir } from './app-paths.js';
17
17
  import { registerProfileSecrets, registerSecretsFrom } from '@aragon-agent/tui/model/logging/secret-registry';
18
18
  import { adaptLegacyConnectionPatch, ModelProfileConfigError, readModelSettingsDisk } from './model-profile-store.js';
19
19
  import { normalizeModelProfiles } from '@aragon-agent/tui/model/config/model-profiles';
20
- import { clampBashConfig, clampJobsConfig, clampPromptsConfig, clampTaskSummaryConfig, CONFIG_VERSION, DEFAULT_CONFIG, clampCompactionConfig, clampFastConfig, clampGovernanceConfig, clampLogConfig, clampMemoryConfig, clampMaxTokens, clampRetryConfig, clampSkillsConfig, clampTeamConfig, clampTodoConfig, clampContextWindow, clampUpdateConfig, isAutoToken, stripLegacyStateKeys, stripRetiredConfigKeys, } from '@aragon-agent/tui/model/config/schema';
20
+ import { clampBashConfig, clampJobsConfig, clampPromptsConfig, clampTaskSummaryConfig, CONFIG_VERSION, DEFAULT_CONFIG, clampCompactionConfig, clampFastConfig, clampGovernanceConfig, clampLogConfig, clampMemoryConfig, clampRedTeamConfig, clampMaxTokens, clampRetryConfig, clampSkillsConfig, clampTeamConfig, clampTodoConfig, clampContextWindow, clampUpdateConfig, isAutoToken, stripLegacyStateKeys, stripRetiredConfigKeys, } from '@aragon-agent/tui/model/config/schema';
21
21
  /**
22
22
  * Normalize `maxTokens` for both directions of the config file.
23
23
  *
@@ -224,6 +224,11 @@ export function normalizePersistedConfig(input) {
224
224
  // section, and a hand-edited one is clamped: the file cannot carry a budget the
225
225
  // planner would refuse or an `agentWrites` that is neither of the three values.
226
226
  memory: clampMemoryConfig({ ...DEFAULT_CONFIG.memory, ...(partial.memory ?? {}) }),
227
+ // And the sixteenth. A `config.json` predating red team mode must resolve a whole
228
+ // section - and this one, unlike most, has a direction that matters: `enabled` defaults
229
+ // to `true`, so an absent section here would arrive with the mode switched OFF for every
230
+ // existing user in exactly the session where `Ctrl+R` is expected to work.
231
+ redteam: clampRedTeamConfig({ ...DEFAULT_CONFIG.redteam, ...(partial.redteam ?? {}) }),
227
232
  };
228
233
  }
229
234
  /**
@@ -356,6 +361,11 @@ export function mergePersistedConfig(current, patch) {
356
361
  // without this merge the shallow spread REPLACES the section and `agentWrites` is
357
362
  // written absent - which must never read back as anything but `ask`.
358
363
  memory: clampMemoryConfig({ ...current.memory, ...(patch.memory ?? {}) }),
364
+ // The sixteenth section, and the eleventh time this file records the same trap.
365
+ // `aragon config set redteam.bypassConfirm false` sends `{ redteam: { bypassConfirm:
366
+ // false } }`; without this merge the shallow spread REPLACES the section and `enabled` is
367
+ // written absent, which reads back as the default rather than as the user's switch.
368
+ redteam: clampRedTeamConfig({ ...current.redteam, ...(patch.redteam ?? {}) }),
359
369
  };
360
370
  return merged;
361
371
  }
@@ -113,6 +113,23 @@ export interface UiState {
113
113
  * it as `false`, which is exactly the first-run behaviour wanted.
114
114
  */
115
115
  governanceIntroSeen: boolean;
116
+ /**
117
+ * The red team waiver version this machine has accepted; `0` = never (red-team-security-mode
118
+ * 4.3 / D-3).
119
+ *
120
+ * IT LIVES HERE, NOT IN `config.json`, and that is a design decision rather than a storage
121
+ * detail: "this machine's user agreed to version N of this text" is a MACHINE FACT about a
122
+ * one-time act, exactly like the notice versions above, while `config.json` is the user's
123
+ * POLICY. `migrateStateOutOfConfig` was written because those two got mixed once already.
124
+ *
125
+ * `>= REDTEAM_DISCLAIMER_VERSION` counts as accepted, so raising the constant asks every
126
+ * user again - which is the only way a one-time acceptance can ever reach new text (RV-20).
127
+ *
128
+ * A NEW SCALAR AND NOT A SCHEMA BUMP, for the fourth time in this file: a schema bump makes
129
+ * `readFromDisk` discard the whole object, resetting every user's `submitCount` to re-ask
130
+ * one question.
131
+ */
132
+ redTeamWaiverVersion: number;
116
133
  }
117
134
  /** Read the state, caching it for the life of the process. Never throws. */
118
135
  export declare function loadUiState(): UiState;
@@ -136,6 +153,33 @@ export declare function setPromptKeyNoticeVersion(version: number): void;
136
153
  /** `false` until the one-time GOVERN explainer has been shown; persisted across launches. */
137
154
  export declare function getGovernanceIntroSeen(): boolean;
138
155
  export declare function setGovernanceIntroSeen(seen: boolean): void;
156
+ /**
157
+ * The accepted red team waiver version; `0` on a file written before the field existed.
158
+ *
159
+ * A READER, NOT A DECISION: whether `0` is "accepted" is
160
+ * `version >= REDTEAM_DISCLAIMER_VERSION`, and that comparison lives in `RedTeamWiring` so the
161
+ * constant has exactly one consumer (I-3).
162
+ */
163
+ export declare function getRedTeamWaiverVersion(): number;
164
+ /**
165
+ * Record the acceptance and RETURN WHAT LANDED ON DISK, read back rather than trusted.
166
+ *
167
+ * It goes through `update` - the same atomic write every state field uses - so a failed write
168
+ * leaves the in-memory value intact and the disk unchanged, and the caller's `disclaimer
169
+ * accepted` claim is never based on a value the process only hopes it wrote (T-A1).
170
+ * `askEveryArm` re-asking goes through THIS function too, which is what makes a re-acceptance
171
+ * idempotent: it re-writes the same number (RV-21).
172
+ */
173
+ export declare function acceptRedTeamWaiver(version: number): number;
174
+ /**
175
+ * `ARAGON_REDTEAM=0` in its kill-switch spellings, read from the LIVE environment.
176
+ *
177
+ * A SECOND READER OF THE SAME RULE, and only for `cli.tsx`'s `preAction` hook, which runs
178
+ * BEFORE `loadConfig` (so the folded `redteam.enabled` does not exist yet) and must refuse
179
+ * `--redteam` in a session the environment killed. `config/env.ts` remains the place the value
180
+ * lands in the resolved config; the two agree because the value set here is the one it accepts.
181
+ */
182
+ export declare function isRedTeamEnvOff(env?: Readonly<Record<string, string | undefined>>): boolean;
139
183
  /**
140
184
  * Migration-only: fill in fields that are still at their default, and never
141
185
  * overwrite a value already here. A second import — after a half-finished
@@ -40,6 +40,7 @@ const DEFAULT_UI_STATE = {
40
40
  scrollModeNoticeVersion: 0,
41
41
  promptKeyNoticeVersion: 0,
42
42
  governanceIntroSeen: false,
43
+ redTeamWaiverVersion: 0,
43
44
  };
44
45
  let memory = null;
45
46
  /** Non-negative integer or `fallback`; shared by both numeric fields. */
@@ -77,6 +78,7 @@ function readFromDisk() {
77
78
  governanceIntroSeen: typeof parsed.governanceIntroSeen === 'boolean'
78
79
  ? parsed.governanceIntroSeen
79
80
  : DEFAULT_UI_STATE.governanceIntroSeen,
81
+ redTeamWaiverVersion: coerceCount(parsed.redTeamWaiverVersion, DEFAULT_UI_STATE.redTeamWaiverVersion),
80
82
  };
81
83
  }
82
84
  catch {
@@ -171,6 +173,42 @@ export function getGovernanceIntroSeen() {
171
173
  export function setGovernanceIntroSeen(seen) {
172
174
  update({ governanceIntroSeen: seen });
173
175
  }
176
+ /**
177
+ * The accepted red team waiver version; `0` on a file written before the field existed.
178
+ *
179
+ * A READER, NOT A DECISION: whether `0` is "accepted" is
180
+ * `version >= REDTEAM_DISCLAIMER_VERSION`, and that comparison lives in `RedTeamWiring` so the
181
+ * constant has exactly one consumer (I-3).
182
+ */
183
+ export function getRedTeamWaiverVersion() {
184
+ return loadUiState().redTeamWaiverVersion;
185
+ }
186
+ /**
187
+ * Record the acceptance and RETURN WHAT LANDED ON DISK, read back rather than trusted.
188
+ *
189
+ * It goes through `update` - the same atomic write every state field uses - so a failed write
190
+ * leaves the in-memory value intact and the disk unchanged, and the caller's `disclaimer
191
+ * accepted` claim is never based on a value the process only hopes it wrote (T-A1).
192
+ * `askEveryArm` re-asking goes through THIS function too, which is what makes a re-acceptance
193
+ * idempotent: it re-writes the same number (RV-21).
194
+ */
195
+ export function acceptRedTeamWaiver(version) {
196
+ const whole = Number.isFinite(version) ? Math.max(0, Math.floor(version)) : 0;
197
+ const next = update({ redTeamWaiverVersion: whole });
198
+ return loadUiState().redTeamWaiverVersion === whole ? whole : next.redTeamWaiverVersion;
199
+ }
200
+ /**
201
+ * `ARAGON_REDTEAM=0` in its kill-switch spellings, read from the LIVE environment.
202
+ *
203
+ * A SECOND READER OF THE SAME RULE, and only for `cli.tsx`'s `preAction` hook, which runs
204
+ * BEFORE `loadConfig` (so the folded `redteam.enabled` does not exist yet) and must refuse
205
+ * `--redteam` in a session the environment killed. `config/env.ts` remains the place the value
206
+ * lands in the resolved config; the two agree because the value set here is the one it accepts.
207
+ */
208
+ export function isRedTeamEnvOff(env = process.env) {
209
+ const value = env.ARAGON_REDTEAM?.trim().toLowerCase();
210
+ return value === '0' || value === 'false' || value === 'off' || value === 'no';
211
+ }
174
212
  /**
175
213
  * Migration-only: fill in fields that are still at their default, and never
176
214
  * overwrite a value already here. A second import — after a half-finished
@@ -87,6 +87,14 @@ export declare function makeController(flags: CliFlags, opts?: {
87
87
  * Absent for every caller except a bridge run's `makeExecController`.
88
88
  */
89
89
  hookRunner?: ToolHookRunner;
90
+ /**
91
+ * `--redteam`: build this session ARMED (red-team-security-mode 4.8).
92
+ *
93
+ * SET BY `runInteractive` ONLY, from the launch decision `validateRedTeamLaunch` produced.
94
+ * Absent everywhere else - `-p`, `aragon exec`, every subcommand - which is what keeps those
95
+ * sessions' prompts and tools byte-identical (I-1).
96
+ */
97
+ redTeamArmed?: boolean;
90
98
  }): {
91
99
  controller: AgentController;
92
100
  confirmBridge: ConfirmBridge;
@@ -120,6 +120,10 @@ export function makeController(flags, opts = { interactive: true }) {
120
120
  ? { structuredResultBlock: opts.structuredResultBlock }
121
121
  : {}),
122
122
  ...(opts.hookRunner ? { hookRunner: opts.hookRunner } : {}),
123
+ // `--redteam` (red-team-security-mode 4.8). SPREAD, so a launch without the flag builds the
124
+ // deps bag it always did; the value is already the output of `validateRedTeamLaunch`, which
125
+ // is the only place allowed to refuse it.
126
+ ...(opts.redTeamArmed === true ? { redTeamArmed: true } : {}),
123
127
  });
124
128
  return { controller, confirmBridge, humanInputBridge };
125
129
  }
@@ -143,6 +147,9 @@ export function createSessionWriter(input) {
143
147
  readAcceptance: () => controller.getAcceptanceItems(),
144
148
  // Mounts and switches only - ids, never text (agent-memory I-18).
145
149
  readMemory: () => controller.getMemoryService()?.exportState(),
150
+ // The armed flag and the waiver version, read at write time: a user can arm or disarm
151
+ // between two checkpoints (red-team-security-mode 4.10).
152
+ readRedTeam: () => controller.getRedTeamSessionState(),
146
153
  // READ AT WRITE TIME: `/model` rebuilds the config, and a checkpoint that
147
154
  // recorded the model from launch would name the wrong one after a switch.
148
155
  readModel: () => {
@@ -73,6 +73,16 @@ export interface CheckpointDeps {
73
73
  * so a session that never touched memory writes no key and a file identical to today's.
74
74
  */
75
75
  readMemory?(): MemorySessionState | undefined;
76
+ /**
77
+ * Red team mode's armed state and the waiver version it was armed under
78
+ * (red-team-security-mode 4.10). OPTIONAL for the reason `readMemory` is: a caller that has no
79
+ * red team chain writes no key at all, and every existing test double keeps compiling.
80
+ *
81
+ * NOT IN THE CHANGE PLAN, AND HAS TO BE HERE ANYWAY: the spec expected `saveSession` to be one
82
+ * call site, but the TUI's route to it is this writer. Recorded in the spec's
83
+ * implementation findings.
84
+ */
85
+ readRedTeam?(): RedTeamSessionState | undefined;
76
86
  readModel(): ModelRef;
77
87
  /** `meta.cwd`; read at every write because `/cwd` can change it. */
78
88
  readCwd(): string;
@@ -280,3 +290,8 @@ export declare class SessionCheckpointWriter {
280
290
  */
281
291
  private fingerprint;
282
292
  }
293
+ /** The armed half of the red team posture, as `saveSession` wants it. */
294
+ export interface RedTeamSessionState {
295
+ armed: boolean;
296
+ waiverVersion?: number;
297
+ }