@aragon-agent/cli 0.6.53 → 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 (101) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +135 -6
  3. package/dist/agent/controller.d.ts +98 -0
  4. package/dist/agent/controller.js +341 -1
  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 +27 -0
  10. package/dist/agent/system-prompt.js +10 -0
  11. package/dist/app/App.d.ts +17 -1
  12. package/dist/app/App.js +266 -26
  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 +78 -4
  16. package/dist/commands/builtins.js +49 -1
  17. package/dist/commands/catalog.js +5 -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/commands/registry.d.ts +7 -0
  22. package/dist/compaction/compactor.d.ts +26 -0
  23. package/dist/compaction/compactor.js +81 -8
  24. package/dist/compaction/summarize-call.d.ts +22 -0
  25. package/dist/compaction/summarize-call.js +29 -0
  26. package/dist/compaction/wiring.js +22 -3
  27. package/dist/config/app-paths.d.ts +13 -0
  28. package/dist/config/app-paths.js +15 -0
  29. package/dist/config/cli-commands.d.ts +15 -0
  30. package/dist/config/cli-commands.js +32 -1
  31. package/dist/config/env.d.ts +3 -1
  32. package/dist/config/env.js +23 -1
  33. package/dist/config/load.d.ts +18 -0
  34. package/dist/config/load.js +19 -1
  35. package/dist/config/redteam-launch.d.ts +77 -0
  36. package/dist/config/redteam-launch.js +58 -0
  37. package/dist/config/store.js +20 -1
  38. package/dist/config/ui-state.d.ts +44 -0
  39. package/dist/config/ui-state.js +38 -0
  40. package/dist/exec/bridge/server.js +9 -2
  41. package/dist/exec/options.js +16 -2
  42. package/dist/governance/prompts/orchestrator-block.js +2 -2
  43. package/dist/host/controller-factory.d.ts +33 -0
  44. package/dist/host/controller-factory.js +14 -0
  45. package/dist/host/follow-up-seed.d.ts +109 -0
  46. package/dist/host/follow-up-seed.js +196 -0
  47. package/dist/host/follow-up.d.ts +73 -0
  48. package/dist/host/follow-up.js +123 -0
  49. package/dist/host/index.d.ts +3 -0
  50. package/dist/host/index.js +3 -0
  51. package/dist/host/memory.d.ts +21 -0
  52. package/dist/host/memory.js +17 -0
  53. package/dist/host/sessions.d.ts +32 -2
  54. package/dist/host/sessions.js +40 -2
  55. package/dist/logging/install.d.ts +1 -0
  56. package/dist/logging/install.js +4 -0
  57. package/dist/logging/logger.d.ts +1 -1
  58. package/dist/memory/block.d.ts +24 -0
  59. package/dist/memory/block.js +54 -0
  60. package/dist/memory/command.d.ts +31 -0
  61. package/dist/memory/command.js +350 -0
  62. package/dist/memory/format.d.ts +51 -0
  63. package/dist/memory/format.js +308 -0
  64. package/dist/memory/paths.d.ts +68 -0
  65. package/dist/memory/paths.js +172 -0
  66. package/dist/memory/plan.d.ts +37 -0
  67. package/dist/memory/plan.js +184 -0
  68. package/dist/memory/resolve.d.ts +45 -0
  69. package/dist/memory/resolve.js +54 -0
  70. package/dist/memory/secrets.d.ts +30 -0
  71. package/dist/memory/secrets.js +73 -0
  72. package/dist/memory/service.d.ts +175 -0
  73. package/dist/memory/service.js +576 -0
  74. package/dist/memory/store.d.ts +133 -0
  75. package/dist/memory/store.js +694 -0
  76. package/dist/memory/tools.d.ts +36 -0
  77. package/dist/memory/tools.js +527 -0
  78. package/dist/memory/transfer.d.ts +53 -0
  79. package/dist/memory/transfer.js +93 -0
  80. package/dist/session/checkpoint.d.ts +33 -0
  81. package/dist/session/checkpoint.js +52 -0
  82. package/dist/session/limits.d.ts +16 -0
  83. package/dist/session/limits.js +16 -0
  84. package/dist/session/persist.d.ts +68 -0
  85. package/dist/session/persist.js +11 -0
  86. package/dist/session/startup-session.d.ts +17 -2
  87. package/dist/session/startup-session.js +15 -2
  88. package/dist/session/store.d.ts +14 -0
  89. package/dist/session/store.js +18 -0
  90. package/dist/session/validate-session.js +129 -0
  91. package/dist/team/runtime.d.ts +11 -0
  92. package/dist/team/runtime.js +6 -0
  93. package/dist/team/subagent.d.ts +21 -0
  94. package/dist/team/subagent.js +7 -0
  95. package/dist/tools/index.d.ts +45 -2
  96. package/dist/tools/index.js +53 -3
  97. package/package.json +3 -3
  98. package/skills/project-indexer/SKILL.md +275 -147
  99. package/skills/project-indexer/templates/artifact-hygiene-template.md +14 -0
  100. package/skills/project-indexer/templates/config-template.md +12 -0
  101. package/skills/project-indexer/templates/index-template.md +4 -0
@@ -0,0 +1,56 @@
1
+ /**
2
+ * `useRedTeamMode`: the terminal's half of red team / security mode (4.3 / 4.8).
3
+ *
4
+ * ASCII ONLY (`app/` is inside the glyph scanner's scope).
5
+ *
6
+ * `App.tsx` is far over the repo's size limit, so the key recognition, the waiver flow and the
7
+ * subscription live here and `App` only wires the result in. The DECISIONS are not here:
8
+ * `planRedTeam` (pure) decides, `RedTeamWiring` (controller) carries out, and this hook is the
9
+ * thin adapter between a keystroke and one `controller.setRedTeam(request)`.
10
+ *
11
+ * EVERY CONTROLLER MEMBER IS OPTIONAL (D-17). Several App-level tests hand `App` a
12
+ * hand-written controller stub that implements only what it needs; an unconditional call would
13
+ * throw `is not a function` at render. A controller without the members reads as "this session
14
+ * has no red team chain": the keys do nothing, no chip is drawn and no toast appears, so those
15
+ * sessions render the bytes they always did (I-1).
16
+ */
17
+ import { type RedTeamRequest } from '@aragon-agent/tui/model/redteam/redteam-mode';
18
+ import type { RedTeamView } from '@aragon-agent/tui/model/redteam/types';
19
+ import type { AgentController } from '../agent/controller.js';
20
+ /** The slice of Ink's `Key` this hook reads; structural so tests need not import Ink. */
21
+ export interface RedTeamKeyLike {
22
+ ctrl: boolean;
23
+ meta: boolean;
24
+ shift: boolean;
25
+ }
26
+ export type RedTeamToastLevel = 'info' | 'warn';
27
+ export type RedTeamControllerPort = Partial<Pick<AgentController, 'getRedTeamView' | 'setRedTeam' | 'applyPendingRedTeam' | 'subscribeRedTeam' | 'acceptRedTeamWaiver' | 'getRedTeamBanner' | 'getRedTeamScope' | 'getConfig'>>;
28
+ export interface UseRedTeamModeArgs {
29
+ controller: RedTeamControllerPort;
30
+ /** App supplies the toast with the right ttl for the level. */
31
+ pushToast(level: RedTeamToastLevel, text: string): void;
32
+ /** A full-width transcript line: the banner and the resume notice go here, not into a toast. */
33
+ pushNotice?(level: RedTeamToastLevel, text: string): void;
34
+ /**
35
+ * Open the waiver overlay. App owns `overlay`, and a `refusal: 'disclaimer'` is exactly the
36
+ * outcome that must NOT be answered with a toast alone (4.3).
37
+ */
38
+ openDisclaimer(): void;
39
+ /** A decision overlay is open, so a key must not fight it (I-7 / D-21). */
40
+ canAct(): boolean;
41
+ }
42
+ export interface UseRedTeamMode {
43
+ view: RedTeamView;
44
+ request(req: RedTeamRequest): void;
45
+ /** True when the key was Ctrl+R and has been consumed. */
46
+ handleKey(input: string, key: RedTeamKeyLike): boolean;
47
+ /** Call at `agent_end`: lands an arming asked for during the turn, and pushes the banner. */
48
+ onTurnEnd(): void;
49
+ /** The waiver was accepted: record it and re-issue the arming. */
50
+ acceptDisclaimer(): void;
51
+ /** The waiver was declined: nothing is recorded, nothing is armed. */
52
+ declineDisclaimer(): void;
53
+ }
54
+ /** How long each level stays on screen. Refusals are longer: they have to be read. */
55
+ export declare function redTeamToastTtlMs(level: RedTeamToastLevel): number;
56
+ export declare function useRedTeamMode(args: UseRedTeamModeArgs): UseRedTeamMode;
@@ -0,0 +1,121 @@
1
+ /**
2
+ * `useRedTeamMode`: the terminal's half of red team / security mode (4.3 / 4.8).
3
+ *
4
+ * ASCII ONLY (`app/` is inside the glyph scanner's scope).
5
+ *
6
+ * `App.tsx` is far over the repo's size limit, so the key recognition, the waiver flow and the
7
+ * subscription live here and `App` only wires the result in. The DECISIONS are not here:
8
+ * `planRedTeam` (pure) decides, `RedTeamWiring` (controller) carries out, and this hook is the
9
+ * thin adapter between a keystroke and one `controller.setRedTeam(request)`.
10
+ *
11
+ * EVERY CONTROLLER MEMBER IS OPTIONAL (D-17). Several App-level tests hand `App` a
12
+ * hand-written controller stub that implements only what it needs; an unconditional call would
13
+ * throw `is not a function` at render. A controller without the members reads as "this session
14
+ * has no red team chain": the keys do nothing, no chip is drawn and no toast appears, so those
15
+ * sessions render the bytes they always did (I-1).
16
+ */
17
+ import { useCallback, useEffect, useReducer, useRef } from 'react';
18
+ import { redTeamToast, } from '@aragon-agent/tui/model/redteam/redteam-mode';
19
+ import { REDTEAM_NOTICE, REDTEAM_TOAST } from '@aragon-agent/tui/ui/redteam-copy';
20
+ import { UNAVAILABLE_RED_TEAM_VIEW } from '../agent/redteam-wiring.js';
21
+ /** How long each level stays on screen. Refusals are longer: they have to be read. */
22
+ export function redTeamToastTtlMs(level) {
23
+ return level === 'warn' ? 3500 : 1800;
24
+ }
25
+ export function useRedTeamMode(args) {
26
+ const { controller } = args;
27
+ const [, bump] = useReducer((n) => n + 1, 0);
28
+ const argsRef = useRef(args);
29
+ argsRef.current = args;
30
+ /** The request that opened the waiver, so accepting re-issues the SAME intent. */
31
+ const awaiting = useRef(null);
32
+ // The view is read at render and never mirrored into App state: a mirror is a second copy
33
+ // that can disagree with the controller.
34
+ const view = controller.getRedTeamView?.() ?? UNAVAILABLE_RED_TEAM_VIEW;
35
+ useEffect(() => controller.subscribeRedTeam?.(() => bump()), [controller]);
36
+ /** Say what an outcome did, and push the banner when the mode just came on. */
37
+ const announce = useCallback((req, outcome) => {
38
+ const live = argsRef.current.controller;
39
+ const current = live.getRedTeamView?.() ?? UNAVAILABLE_RED_TEAM_VIEW;
40
+ const config = live.getConfig?.();
41
+ // "BACK ON" IS ONLY TRUE IF THEY WERE OFF (RV-1 / D-19): both facts are needed.
42
+ const hadBypass = config?.confirmTools === true
43
+ && config?.redteam?.bypassConfirm !== false;
44
+ const toast = redTeamToast(outcome, {
45
+ request: req.kind,
46
+ scope: current.scope,
47
+ bypassesConfirm: current.bypassesConfirm,
48
+ wasBypassing: outcome.ok && outcome.wasArmed && hadBypass,
49
+ // `askEveryArm` refuses an arming that HAS been accepted (D-10), and the sentence has to
50
+ // say "review", not "not accepted".
51
+ waiverAccepted: current.waiverAccepted,
52
+ });
53
+ if (toast)
54
+ argsRef.current.pushToast(toast.level, toast.text);
55
+ // THE BANNER IS A TRANSCRIPT LINE, not a toast: it is three rows and it has to still be
56
+ // there in a minute (4.6). Printed only on a transition INTO armed.
57
+ if (outcome.ok && outcome.effect === 'applied' && outcome.armed && !outcome.wasArmed) {
58
+ const rows = live.getRedTeamBanner?.();
59
+ if (rows && rows.length > 0)
60
+ argsRef.current.pushNotice?.('warn', rows.join('\n'));
61
+ }
62
+ if (outcome.ok && outcome.effect === 'deferred') {
63
+ argsRef.current.pushNotice?.('info', REDTEAM_NOTICE.armingDeferred);
64
+ }
65
+ }, []);
66
+ const request = useCallback((req) => {
67
+ const live = argsRef.current.controller;
68
+ if (!live.setRedTeam)
69
+ return;
70
+ const outcome = live.setRedTeam(req);
71
+ if (!outcome.ok && outcome.refusal === 'disclaimer') {
72
+ // REMEMBER THE INTENT: accepting the waiver re-issues it, and a `toggle` that opened the
73
+ // overlay must not turn into an `on` if the user had actually asked to turn it OFF.
74
+ awaiting.current = req;
75
+ argsRef.current.openDisclaimer();
76
+ return;
77
+ }
78
+ announce(req, outcome);
79
+ }, [announce]);
80
+ const handleKey = useCallback((input, key) => {
81
+ if (!key.ctrl || key.meta)
82
+ return false;
83
+ if (input.toLowerCase() !== 'r')
84
+ return false;
85
+ // THE KEY IS CONSUMED EVEN WHEN THE MODE IS UNAVAILABLE (RV-11): `Ctrl+R` no longer
86
+ // repaints in ANY configuration, and swallowing it silently there would leave a user with
87
+ // no way to tell "off for this session" from "the key is broken". `planRedTeam` answers
88
+ // `unavailable`, and the toast says so once per press.
89
+ if (!argsRef.current.controller.setRedTeam)
90
+ return false;
91
+ // CONSUMED, BUT NOT ACTED ON (the pre-existing overlay guard, kept byte-for-byte): with an
92
+ // overlay open this key belongs to whoever owns the screen, and returning `true` here is
93
+ // what keeps it from reaching anything below in the same handler.
94
+ if (!argsRef.current.canAct())
95
+ return true;
96
+ request({ kind: 'toggle' });
97
+ return true;
98
+ }, [request]);
99
+ const onTurnEnd = useCallback(() => {
100
+ const live = argsRef.current.controller;
101
+ const outcome = live.applyPendingRedTeam?.();
102
+ if (!outcome)
103
+ return;
104
+ // The request that produced it: a landed arming came from `on`, everything else from `off`.
105
+ announce(outcome.ok && outcome.armed ? { kind: 'on' } : { kind: 'off' }, outcome);
106
+ }, [announce]);
107
+ const acceptDisclaimer = useCallback(() => {
108
+ const live = argsRef.current.controller;
109
+ // RECORD FIRST, then re-issue: the state machine refuses an arming before the acceptance
110
+ // is durable, and a waiver recorded after the arm would be a race with a crash (T-A1).
111
+ live.acceptRedTeamWaiver?.();
112
+ const req = awaiting.current ?? { kind: 'on' };
113
+ awaiting.current = null;
114
+ request(req);
115
+ }, [request]);
116
+ const declineDisclaimer = useCallback(() => {
117
+ awaiting.current = null;
118
+ argsRef.current.pushToast('info', REDTEAM_TOAST.declined);
119
+ }, []);
120
+ return { view, request, handleKey, onTurnEnd, acceptDisclaimer, declineDisclaimer };
121
+ }
package/dist/cli.js CHANGED
@@ -13,7 +13,9 @@ import { formatHomeMigrationNotice, migrateToHome } from './config/migrate-home.
13
13
  import { migrateStateOutOfConfig } from './config/migrate-state-out-of-config.js';
14
14
  import { runHistoryCommand } from './config/history-commands.js';
15
15
  import { checkGovernanceCommandLine } from './config/governance-launch.js';
16
- import { COMPACTION_CONFIG_SET_KEYS, FAST_CONFIG_SET_KEYS, LOG_CONFIG_SET_KEYS, RETRY_CONFIG_SET_KEYS, TEAM_CONFIG_SET_KEYS, GOVERNANCE_CONFIG_SET_KEYS, JOBS_CONFIG_SET_KEYS, TASK_SUMMARY_CONFIG_SET_KEYS, UPDATE_CONFIG_SET_KEYS, applyCompactionConfigSet, applyFastConfigSet, applyLogConfigSet, applyRetryConfigSet, applyTeamConfigSet, applyGovernanceConfigSet, applyJobsConfigSet, applyTaskSummaryConfigSet, applyUpdateConfigSet, runConfigEdit, runConfigGet, runConfigHome, runConfigList, warnIfRedactionDisabled, } from './config/cli-commands.js';
16
+ import { checkRedTeamCommandLine } from './config/redteam-launch.js';
17
+ import { getRedTeamWaiverVersion, isRedTeamEnvOff } from './config/ui-state.js';
18
+ import { COMPACTION_CONFIG_SET_KEYS, FAST_CONFIG_SET_KEYS, LOG_CONFIG_SET_KEYS, RETRY_CONFIG_SET_KEYS, TEAM_CONFIG_SET_KEYS, GOVERNANCE_CONFIG_SET_KEYS, MEMORY_CONFIG_SET_KEYS, applyMemoryConfigSet, JOBS_CONFIG_SET_KEYS, TASK_SUMMARY_CONFIG_SET_KEYS, UPDATE_CONFIG_SET_KEYS, applyCompactionConfigSet, applyFastConfigSet, applyLogConfigSet, applyRetryConfigSet, applyTeamConfigSet, applyGovernanceConfigSet, applyJobsConfigSet, applyTaskSummaryConfigSet, applyUpdateConfigSet, runConfigEdit, runConfigGet, runConfigHome, runConfigList, warnIfRedactionDisabled, } from './config/cli-commands.js';
17
19
  import { attachAgentEvents, attachTeamEvents, installLogging, setScreenRestore, setSignalTerminator, } from './logging/install.js';
18
20
  import { getLogger } from './logging/logger.js';
19
21
  import { runLogsCommand } from './logging/cli-commands.js';
@@ -212,6 +214,16 @@ function toFlags(opts) {
212
214
  govern: opts.govern,
213
215
  planGovern: opts.planGovern,
214
216
  governance: opts.governance === false ? false : undefined,
217
+ // Site three of three for `--no-memory`, declared alone like `--no-governance`: commander
218
+ // defaults `opts.memory` to `true` when it is absent, so only an explicit `false` is
219
+ // forwarded and silence can never read as an override.
220
+ memory: opts.memory === false ? false : undefined,
221
+ // Site three of three for the red team pair. BOTH are forwarded, and both are tri-state:
222
+ // `--redteam` absent is `undefined` (no arming), `--no-redteam` absent is `undefined` (no
223
+ // kill switch). Forwarding silence as `false` here would unregister the chain for every run
224
+ // that passed no flag at all.
225
+ redteam: opts.redteam === true ? true : undefined,
226
+ noRedteam: opts.redteam === false ? true : undefined,
215
227
  // Site three of three for `--resume` / `--save` -- ELEVEN features, one trap
216
228
  // (`mouse` P1-2, `team` P1-4, `todo` C-9, render L4, retry, fast, update,
217
229
  // compaction, now session identity). A flag needs the `.option()`
@@ -390,11 +402,17 @@ async function runInteractive(flags, extras = {}) {
390
402
  // MUTABLE BECAUSE `/resume` ROTATES IT (D-15). The chip follows through the
391
403
  // App's `onIdentity`, and the writer reads `parentId` from here on every write.
392
404
  let identity = startup.identity;
393
- const { controller, confirmBridge, humanInputBridge } = makeController(flags);
405
+ const { controller, confirmBridge, humanInputBridge } = makeController(flags, {
406
+ interactive: true,
407
+ // THE ONE LAUNCH PATH THAT MAY START ARMED (4.8). `flags.redteam` is already tri-state and
408
+ // the `preAction` hook has already refused the two impossible combinations, so this is a
409
+ // plain boolean by here - and it is absent for `-p` / `exec` / every subcommand (I-1).
410
+ ...(flags.redteam === true ? { redTeamArmed: true } : {}),
411
+ });
394
412
  // THE RESTORE HAPPENS BEFORE THE FIRST FRAME. `initialEntries` seeds the
395
413
  // reducer, so a resumed transcript is complete on frame one instead of filling
396
414
  // in behind the user's eyes.
397
- startup.apply(controller);
415
+ const redTeamResumeNotice = startup.apply(controller);
398
416
  void controller.refreshModelMetadata();
399
417
  const config = controller.getConfig();
400
418
  const caps = resolveTuiCapabilities({}, config.color);
@@ -1061,6 +1079,10 @@ async function runInteractive(flags, extras = {}) {
1061
1079
  const terminalBridge = {
1062
1080
  mouseSelect: wantSelect,
1063
1081
  deleteDisambiguated: filter !== null,
1082
+ // The memory pages tell a user whose `Ctrl+M` is still Enter where to go instead
1083
+ // (agent-memory 9.1, RV2-2). The SAME expression the translation runs under, never a
1084
+ // second derivation: the line is true exactly when the key frame cannot be produced.
1085
+ enhancedKeys: enhancedKeysOn,
1064
1086
  scrollbar,
1065
1087
  ...(mouseOn
1066
1088
  ? {
@@ -1120,7 +1142,7 @@ async function runInteractive(flags, extras = {}) {
1120
1142
  vtInputWarning: vtInputSupported ? undefined : { nodeVersion: process.versions.node }, updateBridge: updateEligible ? updateBridge : undefined,
1121
1143
  // Absent when nothing can refuse a paste, so a `--no-paste` tree is
1122
1144
  // byte-identical to a build without this feature.
1123
- pasteBridge: pasteOn ? pasteBridge : undefined, terminal: terminalBridge, ...(scrollbackBridge ? { scrollMode: plan.scrollMode, scrollback: scrollbackBridge } : {}), session: identity, sessionBridge: sessionBridge, ...(startup.initialEntries.length > 0 ? { initialEntries: startup.initialEntries } : {}), ...(startup.notice ? { sessionNotice: startup.notice } : {}) }),
1145
+ pasteBridge: pasteOn ? pasteBridge : undefined, terminal: terminalBridge, ...(scrollbackBridge ? { scrollMode: plan.scrollMode, scrollback: scrollbackBridge } : {}), session: identity, sessionBridge: sessionBridge, ...(startup.initialEntries.length > 0 ? { initialEntries: startup.initialEntries } : {}), ...(startup.notice ? { sessionNotice: startup.notice } : {}), ...(redTeamResumeNotice ? { redTeamNotice: redTeamResumeNotice } : {}) }),
1124
1146
  // Full-screen owns console.* itself (I-4): Ink's patchConsole writes
1125
1147
  // straight to stdout and permanently shifts the fixed frame's accounting.
1126
1148
  {
@@ -1466,6 +1488,10 @@ const CONFIG_SET_KEYS = new Set([
1466
1488
  // and without the matching case in `runConfigSet` the membership set accepts a write
1467
1489
  // that never happens.
1468
1490
  ...GOVERNANCE_CONFIG_SET_KEYS,
1491
+ // `memory.*` keys are handled by `applyMemoryConfigSet`, same reasoning again (agent-memory
1492
+ // spec 5.6): without this line they fall through to `Unknown config key`, and without the
1493
+ // matching case in `runConfigSet` the membership set accepts a write that never happens.
1494
+ ...MEMORY_CONFIG_SET_KEYS,
1469
1495
  ]);
1470
1496
  /**
1471
1497
  * `aragon config set maxTokens <n|auto|default>`.
@@ -1646,6 +1672,15 @@ function runConfigSetValue(key, value) {
1646
1672
  process.stdout.write(`Set ${key} = ${String(merged.governance[field])}\n`);
1647
1673
  return;
1648
1674
  }
1675
+ const memoryPatch = applyMemoryConfigSet(key, value);
1676
+ if (memoryPatch) {
1677
+ // Echoed from the STORED value, like every section above: `config set
1678
+ // memory.agentWrites banana` prints `ask`, which is what the read path will report.
1679
+ const merged = updatePersistedConfig(memoryPatch);
1680
+ const field = key.slice('memory.'.length);
1681
+ process.stdout.write(`Set ${key} = ${String(merged.memory?.[field])}\n`);
1682
+ return;
1683
+ }
1649
1684
  const patch = {};
1650
1685
  switch (key) {
1651
1686
  case 'provider':
@@ -2073,6 +2108,19 @@ function buildProgram() {
2073
2108
  .option('--govern', 'Start in GOVERN posture (a governed team of dev / review / test roles)')
2074
2109
  .option('--plan-govern', 'Start in PLAN+GOVERN posture (clarify and plan first, then govern)')
2075
2110
  .option('--no-governance', 'Disable governance mode for this launch (not persisted)')
2111
+ // Negative-only for the reason `--no-governance` records: it can only ever switch the
2112
+ // feature off for this launch, and `toFlags` forwards it only when explicitly given.
2113
+ .option('--no-memory', 'Disable agent memory for this launch (no memory tools or prompt block; not persisted)')
2114
+ // RED TEAM / SECURITY MODE (red-team-security-mode 4.8). The pair is declared POSITIVE FIRST
2115
+ // for the tri-state reason recorded five times above: `redteam.enabled` is persisted and
2116
+ // defaults to `true`, so a negative-only declaration would let commander synthesize `true`
2117
+ // and overwrite a stored `false` on every run that passed no flag at all.
2118
+ //
2119
+ // `--redteam` additionally means "start this session ARMED", which `validateRedTeamLaunch`
2120
+ // refuses in headless mode and before the waiver is accepted - both are cases where nobody
2121
+ // could accept it, and an armed session nobody can leave is worse than no armed session.
2122
+ .option('--redteam', 'Start this session in red team / security mode (needs the waiver accepted)')
2123
+ .option('--no-redteam', 'Disable red team mode for this launch (no chip, no key; not persisted)')
2076
2124
  .option('--no-skills', 'Disable the skill system entirely (no catalog, no skill tools)')
2077
2125
  .option('--skill <name>', 'Force-load a skill at Level 2 for this run (repeatable)', (value, previous = []) => [...previous, value])
2078
2126
  .option('--skills-yes', 'Approve skill installs for this run (CI / headless)')
@@ -2152,6 +2200,32 @@ function buildProgram() {
2152
2200
  process.stderr.write(`${check.message}\n`);
2153
2201
  process.exit(2);
2154
2202
  });
2203
+ /**
2204
+ * The red team flag rules (red-team-security-mode 4.8), in a `preAction` of their own for the
2205
+ * reason the governance hook above records: root-level options, one place, and it covers
2206
+ * `aragon -p` and `aragon exec` too - which is exactly where `--redteam` must be REFUSED.
2207
+ *
2208
+ * The waiver version is read here rather than in `loadConfig` because it lives in `state.json`
2209
+ * (a machine fact, not a preference) and this is the only code path that may open a terminal.
2210
+ */
2211
+ program.hook('preAction', (root, action) => {
2212
+ const raw = root.opts();
2213
+ const check = checkRedTeamCommandLine({ ...(raw.redteam === true ? { redteam: true } : {}),
2214
+ ...(raw.redteam === false ? { noRedteamFlag: false } : {}) }, {
2215
+ commandName: action.name(),
2216
+ isRootAction: action === root,
2217
+ stdinIsTty: !!process.stdin.isTTY,
2218
+ stdoutIsTty: !!process.stdout.isTTY,
2219
+ }, getRedTeamWaiverVersion(),
2220
+ // READ THE VARIABLE DIRECTLY rather than through `readEnvConfig()`: that function also
2221
+ // registers secrets, and a `preAction` hook must not have that side effect for a question
2222
+ // this small. Only the values the other kill switches accept count, and only "off" is one.
2223
+ raw.redteam === false || isRedTeamEnvOff());
2224
+ if (check.ok)
2225
+ return;
2226
+ process.stderr.write(`${check.message}\n`);
2227
+ process.exit(2);
2228
+ });
2155
2229
  // aragon config [set <key> <value> | path]
2156
2230
  const configCmd = program
2157
2231
  .command('config')
@@ -25,6 +25,7 @@ import { runBranchCommand } from './branch-command.js';
25
25
  import { getLogger } from '../logging/logger.js';
26
26
  import { registerQueueCommand } from './queue-command.js';
27
27
  import { registerPromptCommands } from '../prompts/command.js';
28
+ import { registerMemoryCommands } from '../memory/command.js';
28
29
  import { registerKitCommand } from './kit-command.js';
29
30
  import { registerAgentsCommand } from './agents-command.js';
30
31
  import { registerSubagentCommand } from './subagent-command.js';
@@ -32,6 +33,9 @@ import { registerSubagentCommand } from './subagent-command.js';
32
33
  // and this pair of lines is the whole registration; the `team` entry that used to
33
34
  // live in `COMMANDS` above was a CONFIG command and now lives in `Settings > Team`.
34
35
  import { registerTeamCommand } from './team-command.js';
36
+ // `/redteam` (red-team-security-mode 4.8): the body is `commands/redteam-command.ts` and this
37
+ // import is the whole registration, the `/team` shape.
38
+ import { registerRedTeamCommand } from './redteam-command.js';
35
39
  // THE DRAWER AND THE HEADER LABEL (tui-shortcut-drawer-and-task-summary §4.7):
36
40
  // two single-purpose commands in their own modules, registered from here. Both are
37
41
  // UNCONDITIONAL, even with `taskSummary.enabled=false`, because they are the only
@@ -245,6 +249,27 @@ function formatFastStatus(controller) {
245
249
  `${formatTokens(snapshot.usage.outputTokens)}, cost ${cost}.`);
246
250
  return lines.join('\n');
247
251
  }
252
+ /**
253
+ * The two session-file fields red team mode contributes to a `/save` (4.10).
254
+ *
255
+ * A HELPER RATHER THAN FOUR INLINE LINES because the answer is "the whole object, or nothing":
256
+ * an unarmed session must write NO key, so a `/save` from a session that never used the mode is
257
+ * byte-identical to one written before the feature. `getRedTeamSessionState` is optional on the
258
+ * port (D-17), so a host without the chain simply contributes nothing.
259
+ */
260
+ function redTeamSaveFields(port) {
261
+ const state = typeof port.getRedTeamSessionState === 'function'
262
+ ? port.getRedTeamSessionState()
263
+ : undefined;
264
+ if (state?.armed !== true)
265
+ return {};
266
+ return {
267
+ redTeam: true,
268
+ ...(typeof state.waiverVersion === 'number'
269
+ ? { redTeamWaiverVersion: state.waiverVersion }
270
+ : {}),
271
+ };
272
+ }
248
273
  const COMMANDS = [
249
274
  {
250
275
  name: 'help',
@@ -982,6 +1007,9 @@ const COMMANDS = [
982
1007
  // "not started" that the user had already watched being verified. Read
983
1008
  // from the STORE, so a save taken while the capability is off keeps them.
984
1009
  acceptance: ctx.controller.getAcceptanceItems(),
1010
+ // The red team posture, so `/save` and the live checkpoint agree about it (4.10). A
1011
+ // disarmed session contributes no key at all, which keeps this file byte-identical.
1012
+ ...redTeamSaveFields(ctx.controller),
985
1013
  });
986
1014
  ctx.notify('info', `Saved session to ${path}`);
987
1015
  }
@@ -1016,7 +1044,11 @@ const COMMANDS = [
1016
1044
  // live TUI and a no-op at startup, and the second is a VIEW action with
1017
1045
  // no controller to hang it on.
1018
1046
  ctx.controller.clearAllQueues();
1019
- applyRestoredSession(ctx.controller, session);
1047
+ // The notice is the red team reconciliation (4.10): a session that comes back
1048
+ // DISARMED because the waiver moved has to say so, or the user assumes the mode stuck.
1049
+ const notice = applyRestoredSession(ctx.controller, session);
1050
+ if (notice)
1051
+ ctx.notify('warn', notice);
1020
1052
  ctx.dispatch({ type: 'restoreEntries', entries: session.entries });
1021
1053
  // A NEW ID, AND A ZEROED COUNTER, IN THAT ORDER (D-15 / D-10 / R-9).
1022
1054
  // Without the rotation the next checkpoint would write THIS conversation
@@ -1174,6 +1206,13 @@ const COMMANDS = [
1174
1206
  ' { key = "Enter", mods = "Shift", chars = "\\u001b[13;2u" }',
1175
1207
  ' macOS Terminal.app / old conhost cannot rebind Enter; use Ctrl+J',
1176
1208
  '',
1209
+ // Ctrl+M rides the SAME keyboard-enhancement channel (agent-memory spec 9.1): in a terminal
1210
+ // that reports modified keys it opens the memory manager; in one that does not, it is the
1211
+ // same byte as Enter. Said here because this is the command a user runs to find out which
1212
+ // kind of terminal they have.
1213
+ 'Ctrl+M (memory manager) needs the same enhancement: without it Ctrl+M',
1214
+ 'is Enter and submits the draft. Alt+M and /memory work everywhere.',
1215
+ '',
1177
1216
  'Windows needs Node >= 22.17 (or >= 24.2): older versions never',
1178
1217
  'turn on virtual-terminal input, so no report can arrive.',
1179
1218
  'Opt out of the push entirely:',
@@ -1345,6 +1384,8 @@ export function registerBuiltinCommands(registry) {
1345
1384
  // REGISTERED UNCONDITIONALLY, even with `prompts.enabled=false` - that is the only
1346
1385
  // way the command can report that the feature is off (D-19 / AC-30).
1347
1386
  registerPromptCommands(registry);
1387
+ // UNCONDITIONAL, like `/prompts`: with `memory.enabled=false` the command stays and says so.
1388
+ registerMemoryCommands(registry);
1348
1389
  // The read-only subagent board (tui-subagent-panel §6.4). Same shape again: the
1349
1390
  // body is `commands/agents-command.ts` and the registration is this one line.
1350
1391
  registerAgentsCommand(registry);
@@ -1364,6 +1405,10 @@ export function registerBuiltinCommands(registry) {
1364
1405
  // `/gov` (governance-mode 11.3). Unconditional, like `/team` and for the same reason: the
1365
1406
  // session where governance cannot run is exactly where a user asks the command why.
1366
1407
  registerGovernanceCommand(registry);
1408
+ // `/redteam` (red-team-security-mode 4.8). UNCONDITIONAL, like `/team` and `/gov`: the session
1409
+ // where the mode cannot run (`--no-redteam`) is exactly the session where a user types
1410
+ // `/redteam status` to find out why, so registering it may not read the config or the waiver.
1411
+ registerRedTeamCommand(registry);
1367
1412
  // The keyboard drawer (`Ctrl+G` / `/keys`) and the task label (`/task`). Two
1368
1413
  // registrations, no new mechanism: `/keys` sets the panel's pre-filter and opens
1369
1414
  // the same overlay `Ctrl+G` opens, and `/task` reports what the header cell says.
@@ -1383,6 +1428,9 @@ export const BUILTIN_COMMAND_NAMES = ['queue', 'prompts', 'agents', 'subagent',
1383
1428
  // `commands/team-command.ts`), and this array is the documentation/tests surface
1384
1429
  // for every built-in name - the `flatMap` below only sees `COMMANDS`.
1385
1430
  'team',
1431
+ // `redteam` joins the list for the reason `team` above records: its body lives in
1432
+ // `commands/redteam-command.ts`, so only this array can document it to the tests.
1433
+ 'redteam',
1386
1434
  'keys', 'task',
1387
1435
  ...COMMANDS.flatMap((c) => [
1388
1436
  c.name,
@@ -43,9 +43,14 @@ export const BUILTIN_COMMAND_CATALOG = [
43
43
  { name: 'queue', aliases: [], description: '\u67e5\u770b\u5f85\u5904\u7406\u6d88\u606f\u5168\u6587' },
44
44
  { name: 'kit', aliases: [], description: 'Agent kits: status, list, use for this session' },
45
45
  { name: 'prompts', aliases: [], description: 'Quick prompt library: pick, list, add, edit, remove, reorder' },
46
+ { name: 'memory', aliases: ['mem'], description: 'Memory manager: list, save, show, remove, mount, auto-load, agent writes' },
46
47
  { name: 'agents', aliases: [], description: 'Open the subagent board: every child, its facts and its timeline' },
47
48
  { name: 'subagent', aliases: [], description: 'Deprecated alias of /team - same arguments' },
48
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>]' },
49
54
  { name: 'gov', aliases: [], description: 'Governed multi-agent team: /gov help' },
50
55
  { name: 'keys', aliases: [], description: 'List every keyboard shortcut (opens the drawer)' },
51
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
+ }
@@ -14,6 +14,7 @@ import type { UpdateCommandPort } from '@aragon-agent/tui/model/update/types';
14
14
  import type { SessionCommandPort } from './session-command.js';
15
15
  import type { BranchCommandPort } from './branch-command.js';
16
16
  import type { PromptCommandPort } from '@aragon-agent/tui/model/prompts/types';
17
+ import type { MemoryCommandPort } from '@aragon-agent/tui/model/memory/types';
17
18
  export interface CommandContext {
18
19
  /** App-owned shared lock and single feedback path for command and selection copies. */
19
20
  requestCopy?: (request: CopyRequest) => Promise<CopyRequestResult>;
@@ -187,6 +188,12 @@ export interface CommandContext {
187
188
  * needs the SHAPE of the port, never a value at run time.
188
189
  */
189
190
  prompts?: PromptCommandPort;
191
+ /**
192
+ * The memory manager's two capabilities: whether memory is on, and opening the manager on a page
193
+ * (agent-memory spec 9.5). OPTIONAL for the reason `prompts` above records - `CommandContext` is
194
+ * constructed by literal in dozens of fixtures. TYPE-ONLY import: the command needs the SHAPE.
195
+ */
196
+ memory?: MemoryCommandPort;
190
197
  /**
191
198
  * The task label's three capabilities (`/keys`, `/task`; tui-shortcut-drawer-and-
192
199
  * task-summary §6.4).