@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
@@ -328,6 +328,10 @@ export class SessionCheckpointWriter {
328
328
  ? { acceptance: this.deps.readAcceptance() }
329
329
  : {}),
330
330
  ...memoryField(this.deps.readMemory?.()),
331
+ // The red team posture travels with the checkpoint (red-team-security-mode 4.10), read at
332
+ // WRITE TIME because a user can arm or disarm between two checkpoints. Absent - the whole
333
+ // object - for a session without the chain, so those files are byte-identical to today's.
334
+ ...redTeamField(this.deps.readRedTeam?.()),
331
335
  meta: this.buildMeta(input),
332
336
  };
333
337
  try {
@@ -552,3 +556,17 @@ function followUpFingerprint(followUp) {
552
556
  function memoryField(state) {
553
557
  return state === undefined ? {} : { memory: state };
554
558
  }
559
+ /**
560
+ * `{ redTeam, redTeamWaiverVersion }` only while ARMED, so a session that never used the mode
561
+ * writes neither key and its file is byte-identical to one from before the feature (4.10).
562
+ */
563
+ function redTeamField(state) {
564
+ if (state?.armed !== true)
565
+ return {};
566
+ return {
567
+ redTeam: true,
568
+ ...(typeof state.waiverVersion === 'number'
569
+ ? { redTeamWaiverVersion: state.waiverVersion }
570
+ : {}),
571
+ };
572
+ }
@@ -145,6 +145,21 @@ export interface SavedSession {
145
145
  * one, and is told apart from an exec file by `meta.origin`.
146
146
  */
147
147
  meta?: SessionMeta;
148
+ /**
149
+ * Red team mode was ARMED at save time (red-team-security-mode 4.10).
150
+ *
151
+ * ADDITIVE AND OPTIONAL, so `SESSION_VERSION` stays 1 for the fifth time: an older file
152
+ * simply yields `undefined`, which restores as disarmed - the right answer for a session that
153
+ * predates the feature. It is a BOOLEAN and not the whole mode: the scope is deliberately
154
+ * absent (D-9 - a target name can itself be the sensitive part of an engagement), and the
155
+ * waiver lives in `state.json` because it is a machine fact (D-3).
156
+ */
157
+ redTeam?: boolean;
158
+ /**
159
+ * The waiver version this session was armed under, for the reconciliation `/resume` does
160
+ * (4.10 / I-12): a file written under version 1 must not silently re-arm under version 2.
161
+ */
162
+ redTeamWaiverVersion?: number;
148
163
  }
149
164
  /** Resolve a `/save` target: absolute/relative path, or a name in the data dir. */
150
165
  export declare function resolveSessionPath(nameOrPath: string | undefined, cwd: string): string;
@@ -175,6 +190,12 @@ export declare function saveSession(filePath: string, data: {
175
190
  /** Omitted when every memory setting is at its default, so such a file is byte-identical. */
176
191
  memory?: MemorySessionState;
177
192
  meta?: SessionMeta;
193
+ /**
194
+ * Red team mode's armed state, ADDED TO `data` AND NOT AS TWO MORE PARAMETERS (RV-14):
195
+ * `saveSession(filePath, data)` takes two positional arguments, the second one this object.
196
+ */
197
+ redTeam?: boolean;
198
+ redTeamWaiverVersion?: number;
178
199
  }): void;
179
200
  /**
180
201
  * Settle any team entry that was saved mid-dispatch (team-subagents §5.3 / P1-5),
@@ -144,6 +144,16 @@ export function saveSession(filePath, data) {
144
144
  : {}),
145
145
  ...(data.memory ? { memory: data.memory } : {}),
146
146
  ...(data.meta ? { meta: data.meta } : {}),
147
+ // WRITTEN ONLY WHEN ARMED, so a session that never used the mode produces a file
148
+ // byte-identical to today's (4.10). The version rides with the flag for the same reason.
149
+ ...(data.redTeam === true
150
+ ? {
151
+ redTeam: true,
152
+ ...(typeof data.redTeamWaiverVersion === 'number'
153
+ ? { redTeamWaiverVersion: data.redTeamWaiverVersion }
154
+ : {}),
155
+ }
156
+ : {}),
147
157
  };
148
158
  writeFileSync(filePath, `${JSON.stringify(payload, null, 2)}\n`, 'utf-8');
149
159
  }
@@ -62,6 +62,15 @@ export interface SessionRestorePort {
62
62
  * compiling, and a headless controller (no memory service) ignores it.
63
63
  */
64
64
  restoreMemory?(state: unknown): void;
65
+ /**
66
+ * The saved red team posture (red-team-security-mode 4.10). OPTIONAL on the port for the same
67
+ * reason the two above are, and it RETURNS WHAT TO TELL THE USER: a session that comes back
68
+ * disarmed because the waiver changed has to say so, or the user will assume the mode stuck.
69
+ */
70
+ restoreRedTeam?(state: {
71
+ armed?: boolean;
72
+ waiverVersion?: number;
73
+ }): string | null;
65
74
  setModel(providerId: string, modelId: string, baseUrl?: string): void;
66
75
  }
67
76
  export type StartupSessionResolution = {
@@ -71,7 +80,7 @@ export type StartupSessionResolution = {
71
80
  notice?: string;
72
81
  /** The file this session was branched from, if any. */
73
82
  saved?: SavedSession;
74
- apply(port: SessionRestorePort): void;
83
+ apply(port: SessionRestorePort): string | null;
75
84
  } | {
76
85
  ok: false;
77
86
  exitCode: 2;
@@ -92,7 +101,7 @@ export type StartupSessionResolution = {
92
101
  */
93
102
  export declare function applyRestoredSession(port: SessionRestorePort, saved: SavedSession, opts?: {
94
103
  skipModel?: boolean;
95
- }): void;
104
+ }): string | null;
96
105
  /**
97
106
  * Work out which session this process is, and what it starts from.
98
107
  *
@@ -47,9 +47,19 @@ export function applyRestoredSession(port, saved, opts = {}) {
47
47
  // Absence means "defaults", exactly as absent todos mean "clear": the file says what the
48
48
  // session had, and a file that predates memory had nothing mounted.
49
49
  port.restoreMemory?.(saved.memory);
50
+ // THE POSTURE, AND THE NOTICE IT MAY PRODUCE (4.10 / I-12). A file that says `redTeam: true`
51
+ // restores the mode only while the waiver it was armed under is still current; otherwise the
52
+ // port answers with the sentence explaining that, which the caller shows.
53
+ const redTeamNotice = port.restoreRedTeam?.({
54
+ ...(saved.redTeam === true ? { armed: true } : {}),
55
+ ...(typeof saved.redTeamWaiverVersion === 'number'
56
+ ? { waiverVersion: saved.redTeamWaiverVersion }
57
+ : {}),
58
+ }) ?? null;
50
59
  if (!opts.skipModel && saved.model?.providerId && saved.model?.modelId) {
51
60
  port.setModel(saved.model.providerId, saved.model.modelId, saved.model.baseUrl);
52
61
  }
62
+ return redTeamNotice;
53
63
  }
54
64
  /**
55
65
  * Work out which session this process is, and what it starts from.
@@ -84,7 +94,7 @@ function resolveFresh(saveAs) {
84
94
  identity: { id: saveAs, kind: 'named', pinned: true },
85
95
  initialEntries: [],
86
96
  notice: `Session ${saveAs} (pinned). Resume it from any terminal: aragon --resume ${saveAs}`,
87
- apply: () => { },
97
+ apply: () => null,
88
98
  };
89
99
  }
90
100
  // A collision is not a failure for an auto-minted id: another process took the
@@ -97,7 +107,7 @@ function resolveFresh(saveAs) {
97
107
  if (fate === 'unwritable')
98
108
  return unwritable(id);
99
109
  if (fate === 'ok') {
100
- return { ok: true, identity: { id, kind: 'fresh' }, initialEntries: [], apply: () => { } };
110
+ return { ok: true, identity: { id, kind: 'fresh' }, initialEntries: [], apply: () => null };
101
111
  }
102
112
  }
103
113
  return {
@@ -302,9 +302,40 @@ export function validateSession(value) {
302
302
  // small enums survive; the service drops ids that no longer exist when it restores.
303
303
  if (source.memory !== undefined)
304
304
  prepared.memory = sanitizeMemoryState(source.memory);
305
+ // TWO NAMED CASES, NOT A GLOBAL LOOSENING (RV-5 / C-4). `shape()` above does not declare these
306
+ // two fields at all, so a wrong TYPE would ride the spread untouched; the alternative - declaring
307
+ // them as `boolean`/`number` - makes a hand-edited `redTeam: "yes"` throw
308
+ // `Invalid session file: ... must be a boolean`, and `loadSession` then refuses the WHOLE
309
+ // conversation. For a session POSTURE that is a punishment out of all proportion to the mistake:
310
+ // losing a mode costs one keystroke, losing the conversation costs the work. So each field is
311
+ // read on its own and dropped if it cannot be read; every other field's strictness is unchanged.
312
+ const armed = readTolerantBoolean(source.redTeam);
313
+ if (armed === undefined)
314
+ delete prepared.redTeam;
315
+ else
316
+ prepared.redTeam = armed;
317
+ const waiver = readTolerantCount(source.redTeamWaiverVersion);
318
+ if (waiver === undefined)
319
+ delete prepared.redTeamWaiverVersion;
320
+ else
321
+ prepared.redTeamWaiverVersion = waiver;
305
322
  prepared.entries = sanitizeGovernanceEntries(sanitizeEntryAcceptance(prepared.entries));
306
323
  return prepared;
307
324
  }
325
+ /** A boolean, or `undefined`. Anything else reads as "the file did not say". */
326
+ function readTolerantBoolean(value) {
327
+ if (value === true)
328
+ return true;
329
+ if (value === false)
330
+ return false;
331
+ return undefined;
332
+ }
333
+ /** A non-negative integer, or `undefined`. Anything else reads as "the file did not say". */
334
+ function readTolerantCount(value) {
335
+ if (typeof value !== 'number' || !Number.isFinite(value) || value < 0)
336
+ return undefined;
337
+ return Math.floor(value);
338
+ }
308
339
  /**
309
340
  * `meta`, repaired field by field - and `meta.followUp` in particular (desktop-follow-up-panel
310
341
  * 8.3).
@@ -65,6 +65,17 @@ export interface TeamRuntimeDeps {
65
65
  sourceNames: string[];
66
66
  }) => void;
67
67
  humanQueue?: TeamHumanQueue;
68
+ /**
69
+ * The lead's red team bypass predicate and its audit sink, forwarded to every child
70
+ * (red-team-security-mode D-16 / RV-2).
71
+ *
72
+ * ABSENT ON EVERY NON-RED-TEAM SESSION, which keeps `SubagentDeps` the object it was - the
73
+ * conditional-spread discipline the four lines below record, applied to a security control.
74
+ */
75
+ confirmBypass?: SubagentDeps['confirmBypass'];
76
+ onConfirmBypass?: SubagentDeps['onConfirmBypass'];
77
+ /** The child's trimmed `<redteam_mode>` block, forwarded; absent means no block. */
78
+ redteamBlock?: SubagentDeps['redteamBlock'];
68
79
  /**
69
80
  * The lead's caller-approval gate, one instance per child (headless-host-bridge
70
81
  * section 2.3.7). Absent outside bridge mode, which is what keeps a dispatch's
@@ -501,6 +501,12 @@ export class TeamRuntime {
501
501
  : {}),
502
502
  confirmTools: config.confirmTools,
503
503
  ...(this.deps.humanQueue ? { humanQueue: this.deps.humanQueue } : {}),
504
+ // SITE TWO OF TWO for the red team predicate, in the shape every line around it records:
505
+ // declared on `TeamRuntimeDeps` and forgotten here, a child would keep its own bypass
506
+ // closed (or worse, the lead's open) with nothing to report it (RV-2 / R-5).
507
+ ...(this.deps.confirmBypass ? { confirmBypass: this.deps.confirmBypass } : {}),
508
+ ...(this.deps.onConfirmBypass ? { onConfirmBypass: this.deps.onConfirmBypass } : {}),
509
+ ...(this.deps.redteamBlock ? { redteamBlock: this.deps.redteamBlock } : {}),
504
510
  // Site two of two, in the same shape as the policy and compaction lines
505
511
  // around it: declaring it on `TeamRuntimeDeps` and forgetting this line
506
512
  // type-checks and forwards nothing, and the failure is silent - every child
@@ -97,6 +97,27 @@ export interface SubagentDeps {
97
97
  sourceNames: string[];
98
98
  }) => void;
99
99
  confirmTools: boolean;
100
+ /**
101
+ * The lead's red team bypass predicate, passed DOWN rather than shared
102
+ * (red-team-security-mode D-16 / RV-2).
103
+ *
104
+ * IT CANNOT BE INHERITED AUTOMATICALLY, and v1 assumed it could: this module builds its OWN
105
+ * `confirm` closure two fields above (`humanQueue.request`), not the lead's, so "the same
106
+ * wrapper is in place" is false. Without this predicate one `task` call walks around the arm
107
+ * state, and a child that writes files then runs with a permission the session says it has
108
+ * switched off - a hole rather than a switch (R-5).
109
+ */
110
+ confirmBypass?: () => boolean;
111
+ /** The audit sink for a bypassed child call; same contract as the lead's. */
112
+ onConfirmBypass?: (tool: string) => void;
113
+ /**
114
+ * The child's trimmed `<redteam_mode>` block, or `''` (D-8 / D-16).
115
+ *
116
+ * A FUNCTION because the block changes with the posture and the scope, and a child is built
117
+ * per dispatch. Absent on every session without the mode, which is what keeps a child's
118
+ * system prompt byte-identical to today's (I-1).
119
+ */
120
+ redteamBlock?: () => string;
100
121
  /** Present only when `--confirm` is on AND a human channel exists. */
101
122
  humanQueue?: TeamHumanQueue;
102
123
  agentFactory: SubagentAgentFactory;
@@ -91,6 +91,10 @@ getModel) {
91
91
  const built = createBuiltinTools({
92
92
  getCwd: deps.getCwd,
93
93
  confirmTools: deps.confirmTools,
94
+ // THE EXPLICIT HAND-OVER (RV-2): the child's own confirm closure is built below, so the
95
+ // bypass has to be passed as a PREDICATE, not assumed to arrive with the wrapper.
96
+ ...(deps.confirmBypass ? { confirmBypass: deps.confirmBypass } : {}),
97
+ ...(deps.onConfirmBypass ? { onConfirmBypass: deps.onConfirmBypass } : {}),
94
98
  // Only when BOTH halves exist; either missing and the child's `read_file` is the old one.
95
99
  ...(imageSupportFor && getModel
96
100
  ? {
@@ -304,6 +308,9 @@ export function createSubagent(spec, deps, hooks) {
304
308
  ...(spec.governance && deps.governanceRoleBlockFor
305
309
  ? { governanceRoleBlock: deps.governanceRoleBlockFor(spec) }
306
310
  : {}),
311
+ // THE CHILD'S HALF OF THE RED TEAM INHERITANCE (D-8 / D-16). `''` for every session without
312
+ // the mode, and `buildSystemPrompt` splices conditionally, so those prompts are unchanged.
313
+ ...(deps.redteamBlock ? { redteamBlock: deps.redteamBlock() } : {}),
307
314
  });
308
315
  // LAZY ACCESSORS OVER `agentRef`, WHICH IS ASSIGNED AFTER THIS RETURNS. A
309
316
  // non-lazy read here is `undefined` at construction and the child's estimate
@@ -81,6 +81,30 @@ export interface BuiltinToolsOptions {
81
81
  confirmTools?: boolean;
82
82
  /** Awaited before a mutating tool runs; resolve `false` to cancel. */
83
83
  confirm?: (req: ConfirmRequest) => Promise<boolean>;
84
+ /**
85
+ * Read AT CALL TIME: red team mode is armed and its bypass applies
86
+ * (red-team-security-mode 4.5 / I-5).
87
+ *
88
+ * A FUNCTION, NOT A BOOLEAN. The tool array is fixed once `new Agent(...)` returns, so a
89
+ * boolean would turn this feature into "active from the next launch"; `armed` changes on a
90
+ * keystroke.
91
+ *
92
+ * IT IS READ IN EXACTLY ONE PLACE (`withConfirmation`) AND NOWHERE ELSE. Plan mode's gate and
93
+ * the governance gate are wrapped OUTSIDE it, so an armed + PLAN turn never reaches the code
94
+ * that consults this - a structural guarantee rather than a promise (I-6 / R-4).
95
+ *
96
+ * Omitting it (every caller but `AgentController`) leaves the confirm wrapper exactly as it
97
+ * was, which is what keeps every other host's tool behaviour byte-identical.
98
+ */
99
+ confirmBypass?: () => boolean;
100
+ /**
101
+ * Called once per BYPASSED call with the tool's name, never its arguments.
102
+ *
103
+ * This is the audit trail that answers "what did it run without asking me", and the reason it
104
+ * is a callback rather than a `getLogger()` call here: `tools/` has no logger import, and the
105
+ * controller already owns the `redteam.*` event vocabulary (D-9 / R-12).
106
+ */
107
+ onConfirmBypass?: (tool: string) => void;
84
108
  /**
85
109
  * `skill` / `skill_install` / `skill_create`, appended verbatim.
86
110
  *
@@ -248,12 +248,25 @@ function summarize(toolName, params) {
248
248
  return `Edit: ${String(params.path ?? '')}`;
249
249
  return toolName;
250
250
  }
251
- /** Wrap a tool so its execution is gated behind a confirmation callback. */
252
- function withConfirmation(tool, confirm) {
251
+ /**
252
+ * Wrap a tool so its execution is gated behind a confirmation callback.
253
+ *
254
+ * `bypass` IS CHECKED FIRST AND COSTS NO `confirm` CALL (red-team-security-mode 4.5): when it
255
+ * answers true the tool runs immediately and `onBypass` records the fact. The order is the whole
256
+ * contract - a bypass consulted AFTER the dialog had been shown would be a slower way of asking.
257
+ */
258
+ function withConfirmation(tool, confirm, bypass, onBypass) {
253
259
  const original = tool.execute;
254
260
  return {
255
261
  ...tool,
256
262
  async execute(id, params, ctx) {
263
+ if (bypass?.() === true) {
264
+ // THE AUDIT LINE, and it carries the tool name ONLY. Deliberately no arguments: a
265
+ // command line can hold a credential, and this is the one log in the product that is
266
+ // written while a user believes they are not being asked.
267
+ onBypass?.(tool.name);
268
+ return original(id, params, ctx);
269
+ }
257
270
  const approved = await confirm({
258
271
  tool: tool.name,
259
272
  summary: summarize(tool.name, params),
@@ -372,7 +385,11 @@ export function createBuiltinTools(options) {
372
385
  ];
373
386
  if (options.confirmTools && options.confirm) {
374
387
  const confirm = options.confirm;
375
- tools = tools.map((t) => (MUTATING_TOOLS.has(t.name) ? withConfirmation(t, confirm) : t));
388
+ const bypass = options.confirmBypass;
389
+ const onBypass = options.onConfirmBypass;
390
+ tools = tools.map((t) => (MUTATING_TOOLS.has(t.name)
391
+ ? withConfirmation(t, confirm, bypass, onBypass)
392
+ : t));
376
393
  }
377
394
  if (options.skillTools && options.skillTools.length > 0) {
378
395
  tools = [...tools, ...options.skillTools];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aragon-agent/cli",
3
- "version": "0.6.54",
3
+ "version": "0.6.55",
4
4
  "description": "AragonAgent CLI — a Claude-Code / Codex-style interactive terminal UI (TUI) on top of the @aragon-agent/core engine. Installable and runnable via npm / npx.",
5
5
  "license": "MIT",
6
6
  "author": "AragonAgent contributors",
@@ -58,8 +58,8 @@
58
58
  "prepublishOnly": "npm run build"
59
59
  },
60
60
  "dependencies": {
61
- "@aragon-agent/core": "^0.2.66",
62
- "@aragon-agent/tui": "0.0.7",
61
+ "@aragon-agent/core": "^0.2.67",
62
+ "@aragon-agent/tui": "0.0.8",
63
63
  "commander": "^12.1.0",
64
64
  "dotenv": "^16.6.1",
65
65
  "env-paths": "^3.0.0",