@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
@@ -28,6 +28,8 @@ import { type ToolOutputListener } from '@aragon-agent/tui/model/tools/tool-outp
28
28
  import type { FilePatch } from '@aragon-agent/tui/model/tools/patch';
29
29
  import type { SubagentModelResolution } from '@aragon-agent/tui/model/team/model';
30
30
  import { type ForcedTeamState } from '../team/forced-mode.js';
31
+ import type { RedTeamOutcome, RedTeamRequest } from '@aragon-agent/tui/model/redteam/redteam-mode';
32
+ import type { RedTeamView } from '@aragon-agent/tui/model/redteam/types';
31
33
  import { MemoryService } from '../memory/service.js';
32
34
  import type { MemorySessionView } from '@aragon-agent/tui/model/memory/types';
33
35
  import type { MemoryConfig } from '@aragon-agent/tui/model/config/schema';
@@ -155,6 +157,15 @@ export interface ControllerDeps {
155
157
  * once at construction and lost at the first `rebuildSystemPrompt()`.
156
158
  */
157
159
  appendSystemPrompt?: string;
160
+ /**
161
+ * `--redteam`: start this session armed (red-team-security-mode 4.8 / D-15).
162
+ *
163
+ * RESOLVED BEFORE CONSTRUCTION, by `validateRedTeamLaunch`, which is the only place that can
164
+ * refuse it (headless, or no accepted waiver). Absent on every other path - the TUI without
165
+ * the flag, `-p`, `aragon exec`, every subagent - which is what keeps those sessions'
166
+ * prompts and tools byte-identical (I-1).
167
+ */
168
+ redTeamArmed?: boolean;
158
169
  /**
159
170
  * `submit_result`, registered with the lead's toolset when the caller supplied
160
171
  * `--result-schema` (headless-request-scope-and-typed-result section 2.3.9).
@@ -322,6 +333,7 @@ export declare class AgentController {
322
333
  */
323
334
  private readonly governance;
324
335
  private readonly teamMode;
336
+ private readonly redTeam;
325
337
  private readonly memory;
326
338
  private readonly todoRegistered;
327
339
  private todoEnabled;
@@ -903,6 +915,66 @@ export declare class AgentController {
903
915
  /** Tell `listener` whenever the switch's view changes. Returns the unsubscribe. */
904
916
  subscribeTeamMode(listener: () => void): () => void;
905
917
  getTeamConfig(): TeamConfig;
918
+ /** The mode as every surface renders it. Cached; cheap to call per render. */
919
+ getRedTeamView(): RedTeamView;
920
+ /**
921
+ * The ONE write entry: `Ctrl+R`, `/redteam on|off` and `--redteam` all arrive here.
922
+ *
923
+ * A `refusal: 'disclaimer'` is the caller's cue to open the waiver overlay - the command
924
+ * handler cannot (it has no overlay access) and App can.
925
+ */
926
+ setRedTeam(req: RedTeamRequest): RedTeamOutcome;
927
+ /** Land a deferred change at `agent_end`. `null` = nothing was pending. */
928
+ applyPendingRedTeam(): RedTeamOutcome | null;
929
+ /** Tell `listener` whenever the view changes. Returns the unsubscribe. */
930
+ subscribeRedTeam(listener: () => void): () => void;
931
+ /** The engagement scope, or `null` when the user declared none. Never persisted. */
932
+ getRedTeamScope(): string | null;
933
+ /** Set or clear the scope; refuses rather than truncating (4.6 step 4). */
934
+ setRedTeamScope(line: string): {
935
+ ok: true;
936
+ scope: string | null;
937
+ } | {
938
+ ok: false;
939
+ reason: 'too-long' | 'multi-line';
940
+ };
941
+ /** Record the waiver acceptance and return the version that landed on disk. */
942
+ acceptRedTeamWaiver(): number;
943
+ /**
944
+ * The three banner rows for an armed session, or `null` when the banner is off in config.
945
+ *
946
+ * `bannerConfirmations` decides WHICH sentence the middle row carries, because this feature's
947
+ * only honest statement about permissions depends on two facts this class has: whether
948
+ * `confirmTools` is on for this session, and whether `bypassConfirm` is (RV-1 / D-19).
949
+ */
950
+ getRedTeamBanner(): string[] | null;
951
+ /**
952
+ * The armed/disarmed pair for the session file (4.10), plus the waiver version it was armed
953
+ * under. `armed: false` with no version writes neither key, so an unarmed session's file is
954
+ * byte-identical to today's.
955
+ */
956
+ getRedTeamSessionState(): {
957
+ armed: boolean;
958
+ waiverVersion?: number;
959
+ };
960
+ /**
961
+ * Adopt the state a saved session carried (`/resume`, `--resume`, a checkpoint replay).
962
+ *
963
+ * TOLERANT AT THIS BOUNDARY (4.10 / RV-5): anything that is not a boolean reads as disarmed,
964
+ * so a hand-edited file costs the mode and not the conversation. Returns the notice App should
965
+ * print, or `null`.
966
+ */
967
+ restoreRedTeam(saved: {
968
+ armed?: boolean;
969
+ waiverVersion?: number;
970
+ } | undefined): string | null;
971
+ /** The posture changed (`Shift+Tab`, `/gov`): `paused` may have, so repaint. */
972
+ noteRedTeamPosture(): void;
973
+ /**
974
+ * One log record per mode event, and NONE of them carries a command, a target or a secret:
975
+ * `scope_set` records a length, `confirm_bypass` records a tool name (D-9 / R-12).
976
+ */
977
+ private logRedTeam;
906
978
  /** The memory service, or `undefined` when memory is off / headless / a subagent. */
907
979
  getMemoryService(): MemoryService | undefined;
908
980
  /**
@@ -30,6 +30,11 @@ import { buildTeamBlock } from '../team/prompt.js';
30
30
  import { buildForcedTeamBlock } from '../team/forced-prompt.js';
31
31
  import { DEFAULT_FORCED_COUNT } from '../team/forced-mode.js';
32
32
  import { TeamModeWiring, effectiveForced } from './team-mode-wiring.js';
33
+ // RED TEAM / SECURITY MODE (red-team-security-mode 4.4). The state, the waiver and the ONE
34
+ // permission predicate live in the wiring; this class forwards and composes the prompt.
35
+ import { RedTeamWiring, bannerConfirmations, readWaiverVersionPort, writeWaiverVersionPort } from './redteam-wiring.js';
36
+ import { buildRedTeamBanner } from './redteam-prompt.js';
37
+ import { acceptRedTeamWaiver, getRedTeamWaiverVersion, } from '../config/ui-state.js';
33
38
  import { MemoryService, UNAVAILABLE_VIEW } from '../memory/service.js';
34
39
  import { createMemoryTools } from '../memory/tools.js';
35
40
  import { buildFastBlock } from '../fast/prompt.js';
@@ -226,6 +231,19 @@ export class AgentController {
226
231
  // -----------------------------------------------------------------------
227
232
  teamMode;
228
233
  // -----------------------------------------------------------------------
234
+ // Red team / security mode (red-team-security-mode 4.4)
235
+ //
236
+ // SESSION STATE, NEVER PERSISTED (D-4): `armed` is the wiring's own field, `config.json`
237
+ // has no key that can express it, and a saved session records it as an OPTIONAL BOOLEAN so
238
+ // `/resume` can restore it honestly (4.10). The scope lives here too and is never written
239
+ // anywhere - a target name can itself be the sensitive part of an engagement (D-9).
240
+ //
241
+ // THE WAIVER IS NOT STATE THIS CLASS OWNS: it is `state.json`, read through two functions
242
+ // from `config/ui-state.ts`, so no code path can arm the mode by writing a config field
243
+ // (I-3 / I-4).
244
+ // -----------------------------------------------------------------------
245
+ redTeam;
246
+ // -----------------------------------------------------------------------
229
247
  // Agent memory (agent-memory spec 8.4)
230
248
  // -----------------------------------------------------------------------
231
249
  // `undefined` when memory is off, the host is headless, or this is a subagent - which is
@@ -535,6 +553,30 @@ export class AgentController {
535
553
  rebuildPrompt: () => this.rebuildSystemPrompt(),
536
554
  defaultCount: DEFAULT_FORCED_COUNT,
537
555
  });
556
+ // AFTER the governance wiring and the launch posture, for the same reason `teamMode` is:
557
+ // `paused` is derived from `getPosture()`, which reads both. BEFORE `createBuiltinTools`,
558
+ // because the confirm-bypass closure below is handed to it (the `fileChanges` rule).
559
+ this.redTeam = new RedTeamWiring({
560
+ getConfig: () => this.config,
561
+ // ONE PREDICATE, not three flags: `--no-redteam` and `ARAGON_REDTEAM=0` are already
562
+ // folded into `redteam.enabled` by the config layer (4.8's table).
563
+ isAvailable: () => this.config.redteam?.enabled !== false,
564
+ readWaiverVersion: () => readWaiverVersionPort(getRedTeamWaiverVersion),
565
+ saveWaiverVersion: (version) => writeWaiverVersionPort(acceptRedTeamWaiver, version),
566
+ getPosture: () => {
567
+ const posture = this.getPosture();
568
+ return { mode: posture === 'plan' || posture === 'plan_govern' ? 'plan' : 'build',
569
+ governOn: posture === 'govern' || posture === 'plan_govern' };
570
+ },
571
+ isRunning: () => this.isRunning() || this.isCompactionBusy(),
572
+ rebuildPrompt: () => this.rebuildSystemPrompt(),
573
+ log: (event) => this.logRedTeam(event),
574
+ });
575
+ // `--redteam`: the launch check already refused the two cases that cannot work (headless,
576
+ // and no accepted waiver), so this is the ONE place a session may start armed without a
577
+ // keystroke. It still goes through the wiring, so the log and the view agree.
578
+ if (deps.redTeamArmed === true)
579
+ this.redTeam.armForLaunch();
538
580
  this.teamRuntime = this.teamRegistered
539
581
  ? new TeamRuntime({
540
582
  getConfig: () => this.config,
@@ -605,6 +647,26 @@ export class AgentController {
605
647
  // mid-dispatch and abort it at `idleTimeoutMs`. The queue pauses the
606
648
  // CHILD's watchdog instead, which is the one that needs it (P0-4).
607
649
  ...(confirm ? { humanQueue: new TeamHumanQueue(confirm) } : {}),
650
+ // THE CHILD INHERITS THE LEAD'S RED TEAM PHRASE (4.5 point 6 / D-16 / RV-2).
651
+ // `buildSubagentTools` builds its OWN confirm closure (`humanQueue.request`), so
652
+ // "the same closure is inherited" is FALSE - the same PREDICATE has to be passed
653
+ // down explicitly, or one `task` call walks around the arm state. Spread so a
654
+ // session without the chain builds `SubagentDeps` exactly as before.
655
+ ...(this.redTeam.available()
656
+ ? {
657
+ confirmBypass: () => this.redTeam.bypassesConfirmation(),
658
+ // The audit sink has to travel WITH the predicate: a child that skips a dialog
659
+ // silently is the one case R-12 exists for.
660
+ onConfirmBypass: (tool) => this.logRedTeam({
661
+ type: 'redteam.confirm_bypass', tool,
662
+ }),
663
+ }
664
+ : {}),
665
+ // THE CHILD'S PROMPT HALF OF THE SAME INHERITANCE: a trimmed `<redteam_mode>` block
666
+ // that tells the child it is bound by the lead's engagement rules.
667
+ ...(this.redTeam.available()
668
+ ? { redteamBlock: () => this.redTeam.childBlock() }
669
+ : {}),
608
670
  // SITE ONE OF TWO FOR THE CHILD GATE (headless-host-bridge 2.3.7). The
609
671
  // second is `runtime.ts::subDeps`; declaring it here and forgetting that
610
672
  // one type-checks and forwards nothing, and every child would then run
@@ -762,6 +824,21 @@ export class AgentController {
762
824
  }
763
825
  : {}),
764
826
  confirmTools: config.confirmTools,
827
+ // THE ONE PERMISSION EFFECT OF RED TEAM MODE (4.5 / I-5). Spread only when the chain
828
+ // exists, so a `--no-redteam` session's options bag is the object it always was. A
829
+ // FUNCTION, not a boolean: `armed` changes mid-session while the tool array cannot, and a
830
+ // boolean here would make this feature "active from the next launch".
831
+ //
832
+ // It is read by `withConfirmation` and by NOTHING ELSE. Plan mode's gate and the
833
+ // governance gate are wrapped OUTSIDE it, so an armed + PLAN turn never reaches the code
834
+ // that would consult this (I-6, structurally).
835
+ ...(this.redTeam.available()
836
+ ? {
837
+ confirmBypass: () => this.redTeam.bypassesConfirmation(),
838
+ // One `redteam.confirm_bypass` record per skipped dialog, tool name only (R-12).
839
+ onConfirmBypass: (tool) => this.logRedTeam({ type: 'redteam.confirm_bypass', tool }),
840
+ }
841
+ : {}),
765
842
  // Routed through the same watchdog pause as the plan tools. This is a
766
843
  // pre-existing bug being fixed in passing: a `--confirm` user who took
767
844
  // longer than `idleTimeoutMs` over `Proceed? (y/N)` had their run killed
@@ -1195,6 +1272,9 @@ export class AgentController {
1195
1272
  // stop saying "applies after this turn". The prompt itself is rebuilt at the START of
1196
1273
  // the next turn, which is also where outside edits are picked up.
1197
1274
  this.memory?.onTurnEnd();
1275
+ // A red team change asked for DURING the turn lands here (D-12): tightening already
1276
+ // took effect immediately, this is the loosening half.
1277
+ this.redTeam.applyPending();
1198
1278
  // The same reconciliation at the other end of a run. Both ends are
1199
1279
  // required: `turn_start` covers the next turn of the same run, and this
1200
1280
  // covers a run that ended with a notice stranded in the queue.
@@ -1206,6 +1286,9 @@ export class AgentController {
1206
1286
  });
1207
1287
  // The switch's baseline view, taken once everything it reads exists (team-mode-toggle-keys).
1208
1288
  this.teamMode.prime();
1289
+ // The same for red team mode: taken AFTER the launch arming above, so an `--redteam`
1290
+ // session's first render already says `RT armed` rather than repainting one frame later.
1291
+ this.redTeam.prime();
1209
1292
  if (this.fast) {
1210
1293
  this.rebuildSystemPrompt();
1211
1294
  }
@@ -1359,6 +1442,18 @@ export class AgentController {
1359
1442
  model: `${config.provider}/${config.model}`,
1360
1443
  })
1361
1444
  : '',
1445
+ // THE RED TEAM BLOCK (4.6 / D-7). '' unless the mode is armed for THIS config, which is
1446
+ // what makes the closed state byte-identical (I-1). Read through the wiring so the block,
1447
+ // the chip and the gate can never disagree about whether the mode is on (I-10).
1448
+ //
1449
+ // NO `config` ARGUMENT, unlike `team` / `memory` above: the two keys that could differ in
1450
+ // a previewed settings snapshot (`enabled`, `bypassConfirm`) change the GATE, not the
1451
+ // block's text, and the block's presence depends on `armed`, which no config can express.
1452
+ // OPTIONAL-CHAINED BECAUSE `skills.discover()` CAN REACH THIS COMPOSER BEFORE THE WIRING
1453
+ // EXISTS: it runs in the constructor, and its `onChange` rebuilds the prompt. A missing
1454
+ // wiring means this session has no red team mode, which is `''` - the same answer the
1455
+ // block gives when the mode is off.
1456
+ redteamBlock: this.redTeam?.block() ?? '',
1362
1457
  // FROM THE FIELD, so the block survives every rebuild for the reason the field's
1363
1458
  // own comment records. Empty everywhere but `aragon exec --result-schema`, and
1364
1459
  // `buildSystemPrompt` splices it conditionally - so every existing prompt is
@@ -1394,6 +1489,11 @@ export class AgentController {
1394
1489
  // LAST: every change to what the switch shows passes through here, so one notification
1395
1490
  // point replaces "each call site remembers to notify" (D-7).
1396
1491
  this.teamMode.emitIfChanged();
1492
+ // The same funnel for red team mode: every way its view can change (arm, disarm, scope,
1493
+ // posture, waiver) ends up here or in `emitIfChanged`, so no surface needs "did every call
1494
+ // site remember to notify". Optional-chained for the constructor-order reason the prompt
1495
+ // composer records.
1496
+ this.redTeam?.emitIfChanged();
1397
1497
  this.memory?.emitIfChanged();
1398
1498
  }
1399
1499
  currentImageKey() {
@@ -2304,6 +2404,118 @@ export class AgentController {
2304
2404
  return this.config.team;
2305
2405
  }
2306
2406
  // -----------------------------------------------------------------------
2407
+ // Red team / security mode - public surface (red-team-security-mode 4.4)
2408
+ // -----------------------------------------------------------------------
2409
+ /** The mode as every surface renders it. Cached; cheap to call per render. */
2410
+ getRedTeamView() {
2411
+ return this.redTeam.getView();
2412
+ }
2413
+ /**
2414
+ * The ONE write entry: `Ctrl+R`, `/redteam on|off` and `--redteam` all arrive here.
2415
+ *
2416
+ * A `refusal: 'disclaimer'` is the caller's cue to open the waiver overlay - the command
2417
+ * handler cannot (it has no overlay access) and App can.
2418
+ */
2419
+ setRedTeam(req) {
2420
+ return this.redTeam.request(req);
2421
+ }
2422
+ /** Land a deferred change at `agent_end`. `null` = nothing was pending. */
2423
+ applyPendingRedTeam() {
2424
+ return this.redTeam.applyPending();
2425
+ }
2426
+ /** Tell `listener` whenever the view changes. Returns the unsubscribe. */
2427
+ subscribeRedTeam(listener) {
2428
+ return this.redTeam.subscribe(listener);
2429
+ }
2430
+ /** The engagement scope, or `null` when the user declared none. Never persisted. */
2431
+ getRedTeamScope() {
2432
+ return this.redTeam.getScope();
2433
+ }
2434
+ /** Set or clear the scope; refuses rather than truncating (4.6 step 4). */
2435
+ setRedTeamScope(line) {
2436
+ return this.redTeam.setScope(line);
2437
+ }
2438
+ /** Record the waiver acceptance and return the version that landed on disk. */
2439
+ acceptRedTeamWaiver() {
2440
+ return this.redTeam.acceptWaiver();
2441
+ }
2442
+ /**
2443
+ * The three banner rows for an armed session, or `null` when the banner is off in config.
2444
+ *
2445
+ * `bannerConfirmations` decides WHICH sentence the middle row carries, because this feature's
2446
+ * only honest statement about permissions depends on two facts this class has: whether
2447
+ * `confirmTools` is on for this session, and whether `bypassConfirm` is (RV-1 / D-19).
2448
+ */
2449
+ getRedTeamBanner() {
2450
+ if (this.config.redteam?.banner === false)
2451
+ return null;
2452
+ if (this.redTeam.getView().effective !== 'armed')
2453
+ return null;
2454
+ return buildRedTeamBanner(this.redTeam.getScope(), bannerConfirmations(this.config.redteam ?? {}, this.config.confirmTools));
2455
+ }
2456
+ /**
2457
+ * The armed/disarmed pair for the session file (4.10), plus the waiver version it was armed
2458
+ * under. `armed: false` with no version writes neither key, so an unarmed session's file is
2459
+ * byte-identical to today's.
2460
+ */
2461
+ getRedTeamSessionState() {
2462
+ const armed = this.redTeam.getView().armed;
2463
+ return armed
2464
+ ? { armed, waiverVersion: this.redTeam.disclaimerVersion }
2465
+ : { armed };
2466
+ }
2467
+ /**
2468
+ * Adopt the state a saved session carried (`/resume`, `--resume`, a checkpoint replay).
2469
+ *
2470
+ * TOLERANT AT THIS BOUNDARY (4.10 / RV-5): anything that is not a boolean reads as disarmed,
2471
+ * so a hand-edited file costs the mode and not the conversation. Returns the notice App should
2472
+ * print, or `null`.
2473
+ */
2474
+ restoreRedTeam(saved) {
2475
+ if (!saved)
2476
+ return null;
2477
+ return this.redTeam.restoreFromSession({
2478
+ armed: saved.armed === true,
2479
+ ...(typeof saved.waiverVersion === 'number' ? { waiverVersion: saved.waiverVersion } : {}),
2480
+ }).notice;
2481
+ }
2482
+ /** The posture changed (`Shift+Tab`, `/gov`): `paused` may have, so repaint. */
2483
+ noteRedTeamPosture() {
2484
+ this.redTeam.onPostureChange();
2485
+ }
2486
+ /**
2487
+ * One log record per mode event, and NONE of them carries a command, a target or a secret:
2488
+ * `scope_set` records a length, `confirm_bypass` records a tool name (D-9 / R-12).
2489
+ */
2490
+ logRedTeam(event) {
2491
+ switch (event.type) {
2492
+ case 'redteam.arm':
2493
+ // `scopeCells` is a length: the scope itself never reaches a log file (D-9 / R-12).
2494
+ getLogger().info('agent', 'redteam_armed', {
2495
+ deferred: event.deferred, scopeCells: event.scopeCells,
2496
+ });
2497
+ return;
2498
+ case 'redteam.disarm':
2499
+ getLogger().info('agent', 'redteam_disarmed', {});
2500
+ return;
2501
+ case 'redteam.confirm_bypass':
2502
+ // ONE LINE PER BYPASSED CALL, with the tool name and nothing else: this is the audit
2503
+ // trail that answers "what did it run without asking me".
2504
+ getLogger().warn('agent', 'redteam_confirm_bypass', { tool: event.tool });
2505
+ return;
2506
+ case 'redteam.waiver_accepted':
2507
+ getLogger().info('agent', 'redteam_waiver_accepted', { version: event.version });
2508
+ return;
2509
+ case 'redteam.scope_set':
2510
+ getLogger().info('agent', 'redteam_scope_set', { cells: event.cells });
2511
+ return;
2512
+ case 'redteam.resume_restored':
2513
+ getLogger().info('agent', 'redteam_resume_restored', {
2514
+ armed: event.armed, reason: event.reason,
2515
+ });
2516
+ }
2517
+ }
2518
+ // -----------------------------------------------------------------------
2307
2519
  // Agent memory - public surface (agent-memory spec 8.4)
2308
2520
  // -----------------------------------------------------------------------
2309
2521
  /** The memory service, or `undefined` when memory is off / headless / a subagent. */
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The `<redteam_mode>` system-prompt block and the session banner
3
+ * (red-team-security-mode 4.6).
4
+ *
5
+ * ASCII ONLY AND ENGLISH, AND BOTH ARE HARD CONSTRAINTS: `agent/**` is inside
6
+ * `glyphs.test.ts::inScope` (a single non-ASCII byte turns the suite red), and the
7
+ * requirement is explicit that this mode's prompt is English.
8
+ *
9
+ * WHERE IT GOES AND WHY (D-7). `buildSystemPrompt` splices it immediately AFTER the project
10
+ * guidance and BEFORE memory / skills, because this block declares who authorized the session
11
+ * and where the boundary is - it is the frame that explains the scale of every capability
12
+ * block after it. It also has to sit after the base prompt's environment and tool list, since
13
+ * the scope and the target sit on top of the real working directory and the real toolset.
14
+ *
15
+ * WHAT IT DOES NOT SAY. It does not say "maximum permission". `confirmTools` is `false` by
16
+ * default, so for most sessions this mode changes no permission at all (RV-1); a prompt that
17
+ * claimed otherwise would be the same untruth as v1's disclaimer clause 2, one layer down.
18
+ * The `What this mode changes` section therefore states the narrow fact and names the four
19
+ * things that are still refused.
20
+ *
21
+ * VERSIONS: `REDTEAM_BLOCK_VERSION` for the lead, `REDTEAM_CHILD_BLOCK_VERSION` for a
22
+ * subagent, so a wording change is greppable from a behaviour report.
23
+ */
24
+ import { type RedTeamConfirmations } from '@aragon-agent/tui/ui/layout/redteam-banner';
25
+ export interface RedTeamBlockParams {
26
+ /** The user's declared engagement scope; `null` = not declared (D-9). */
27
+ scope: string | null;
28
+ /** A stricter posture is holding THIS turn back (PLAN / GOVERN). */
29
+ paused: boolean;
30
+ /** The name of the posture doing it, for the note; ignored when `paused` is false. */
31
+ postureLabel?: string;
32
+ /** `lead` or `child`: a subagent gets the trimmed variant (D-8 / D-16). */
33
+ role: 'lead' | 'child';
34
+ }
35
+ /**
36
+ * The block. TOTAL: every combination of `scope` / `paused` / `role` produces exactly one
37
+ * string with exactly one opening and one closing tag (T-P1 / I-8).
38
+ */
39
+ export declare function buildRedTeamBlock(params: RedTeamBlockParams): string;
40
+ /**
41
+ * The three-row session banner (4.6), as plain lines for the `notice` entry.
42
+ *
43
+ * THE CONFIRMATION SENTENCE IS CONDITIONAL (RV-1 / D-19): the banner is the third place a
44
+ * user could be told something that did not happen, so it states which of the three
45
+ * situations this session is actually in.
46
+ */
47
+ export declare function buildRedTeamBanner(scope: string | null, confirmations: RedTeamConfirmations): string[];
@@ -0,0 +1,161 @@
1
+ /**
2
+ * The `<redteam_mode>` system-prompt block and the session banner
3
+ * (red-team-security-mode 4.6).
4
+ *
5
+ * ASCII ONLY AND ENGLISH, AND BOTH ARE HARD CONSTRAINTS: `agent/**` is inside
6
+ * `glyphs.test.ts::inScope` (a single non-ASCII byte turns the suite red), and the
7
+ * requirement is explicit that this mode's prompt is English.
8
+ *
9
+ * WHERE IT GOES AND WHY (D-7). `buildSystemPrompt` splices it immediately AFTER the project
10
+ * guidance and BEFORE memory / skills, because this block declares who authorized the session
11
+ * and where the boundary is - it is the frame that explains the scale of every capability
12
+ * block after it. It also has to sit after the base prompt's environment and tool list, since
13
+ * the scope and the target sit on top of the real working directory and the real toolset.
14
+ *
15
+ * WHAT IT DOES NOT SAY. It does not say "maximum permission". `confirmTools` is `false` by
16
+ * default, so for most sessions this mode changes no permission at all (RV-1); a prompt that
17
+ * claimed otherwise would be the same untruth as v1's disclaimer clause 2, one layer down.
18
+ * The `What this mode changes` section therefore states the narrow fact and names the four
19
+ * things that are still refused.
20
+ *
21
+ * VERSIONS: `REDTEAM_BLOCK_VERSION` for the lead, `REDTEAM_CHILD_BLOCK_VERSION` for a
22
+ * subagent, so a wording change is greppable from a behaviour report.
23
+ */
24
+ import { REDTEAM_BLOCK_VERSION, REDTEAM_CHILD_BLOCK_VERSION, } from '@aragon-agent/tui/model/redteam/limits';
25
+ import { clipScopeForPrompt } from '@aragon-agent/tui/model/redteam/scope';
26
+ import { redTeamBannerLines } from '@aragon-agent/tui/ui/layout/redteam-banner';
27
+ /** The scope line as it is injected: normalized once more, and clipped to the budget. */
28
+ function scopeLine(scope) {
29
+ if (scope === null) {
30
+ return '- Engagement scope: not declared. Establish it with the user (one ask_user round,'
31
+ + ' at most three questions) before you touch anything that is not a read.';
32
+ }
33
+ return `- Engagement scope: ${clipScopeForPrompt(scope)}.`;
34
+ }
35
+ /** The posture note, appended before the closing tag when a stricter posture is active. */
36
+ function postureNote(params) {
37
+ if (!params.paused)
38
+ return [];
39
+ const label = params.postureLabel && params.postureLabel.length > 0
40
+ ? params.postureLabel
41
+ : 'A stricter posture';
42
+ return [
43
+ '',
44
+ `Posture note: ${label} is active in this turn. Plan mode still refuses writes and the`,
45
+ 'governed Orchestrator is still hard-gated, so the authorization above applies to',
46
+ 'analysis and reporting only. Do not request a write path until the posture changes.',
47
+ ];
48
+ }
49
+ const AUTHORIZATION_LINES = [
50
+ '- Treat that scope as the only authorized target set. Anything outside it is out of scope,',
51
+ ' even when it is reachable from inside it.',
52
+ '- If a request would act on a target outside the scope, say so in one sentence, name the',
53
+ ' boundary, and ask the user to confirm or extend the scope. Ask once; do not lecture.',
54
+ '- The waiver is the user\'s assertion of authorization. Do not re-argue it every turn and',
55
+ ' do not repeat a disclaimer the user has already accepted.',
56
+ ];
57
+ const CHANGE_LINES = [
58
+ 'What this mode changes',
59
+ '- The confirmation prompt before write_file, edit_file and bash is OFF in this session.',
60
+ ' If it was already off, this mode grants no permission you did not already have. A',
61
+ ' destructive command runs the first time you emit it: prefer read-only discovery, and',
62
+ ' copy before you overwrite.',
63
+ '- Nothing else is loosened. Plan-mode write refusals, the governed Orchestrator\'s hard gate,',
64
+ ' the workspace boundary, the skill tool-policy ceiling and every tool contract are',
65
+ ' unchanged.',
66
+ ];
67
+ const RULES_LINES = [
68
+ 'Rules of engagement',
69
+ '1. State the scope at the start of the work: target, environment (lab / staging / production)',
70
+ ' and the property you were asked to prove.',
71
+ '2. Least impact. Prove a finding with the smallest action that is convincing: a benign marker',
72
+ ' (one file, one line of output, one account) beats a full exploit chain.',
73
+ '3. No persistence and no exfiltration. Do not install backdoors, cron jobs, service accounts',
74
+ ' or credentials, and do not copy real user data or secrets out of the target. When you find',
75
+ ' a secret, report its location and type, never its value.',
76
+ '4. Clean up. Revert what you changed and say what you reverted.',
77
+ '5. Evidence. For each finding record where it is, how to reproduce it, what an attacker gains,',
78
+ ' how to fix it, and a severity (critical / high / medium / low / info) with one sentence of',
79
+ ' reasoning.',
80
+ '6. Honest failure. A negative result is a result: say what you tested and what you ruled out.',
81
+ ];
82
+ const METHOD_LINES = [
83
+ 'Method',
84
+ '- Recon before assumptions: read the code, configuration and infrastructure manifests that',
85
+ ' are in scope before attacking anything.',
86
+ '- Prefer a static read to a live probe, and a local reproduction to a remote one.',
87
+ '- An exploit or fuzz harness belongs in the workspace under one clearly named directory, kept',
88
+ ' minimal and marked as engagement material.',
89
+ '- Threat-model the change: name the asset, the attacker, the entry point and the trust',
90
+ ' boundary being crossed.',
91
+ ];
92
+ const DELIVERABLE_LINES = [
93
+ 'Deliverable',
94
+ '- Lead with findings, most severe first, then reproduction, then the fix.',
95
+ '- A finding without a reproduction is a hypothesis; label it as one.',
96
+ '- Close with the residual risk you did not test.',
97
+ ];
98
+ const CLOSING_LINES = [
99
+ 'This mode is a permission posture, not a legal authorization. The user is responsible for',
100
+ 'having the right to test what they point you at.',
101
+ ];
102
+ /**
103
+ * The block. TOTAL: every combination of `scope` / `paused` / `role` produces exactly one
104
+ * string with exactly one opening and one closing tag (T-P1 / I-8).
105
+ */
106
+ export function buildRedTeamBlock(params) {
107
+ const child = params.role === 'child';
108
+ const version = child ? REDTEAM_CHILD_BLOCK_VERSION : REDTEAM_BLOCK_VERSION;
109
+ const intro = child
110
+ ? 'You are a subagent of a session operating in RED TEAM / SECURITY mode: an explicitly'
111
+ + ' authorized security engagement.'
112
+ : 'You are operating in RED TEAM / SECURITY mode: an explicitly authorized security'
113
+ + ' engagement.';
114
+ // A CHILD DROPS TWO AUTHORIZATION ITEMS (3 and 4): it cannot ask the user to extend a scope
115
+ // (it has no user), and it must not re-argue a waiver it did not see.
116
+ const authorization = child ? AUTHORIZATION_LINES.slice(0, 2) : AUTHORIZATION_LINES;
117
+ const method = child ? METHOD_LINES.slice(0, METHOD_LINES.length - 2) : METHOD_LINES;
118
+ return [
119
+ `<redteam_mode version="${version}">`,
120
+ intro,
121
+ // THE ONE SENTENCE v1 HAD HERE THAT IS GONE (RV-1): "this mode holds the widest permission
122
+ // the runtime offers". With `confirmTools: false` by default it does not, and a prompt
123
+ // that says so teaches the model to overstate what it is allowed to do. The facts are in
124
+ // `What this mode changes` below, in the conditional form.
125
+ 'The user has accepted the liability waiver for this session. Work as an',
126
+ 'offensive-security professional, not as a generic assistant.',
127
+ '',
128
+ 'Authorization',
129
+ scopeLine(params.scope),
130
+ ...authorization,
131
+ '',
132
+ ...CHANGE_LINES,
133
+ '',
134
+ ...RULES_LINES,
135
+ '',
136
+ ...method,
137
+ '',
138
+ ...DELIVERABLE_LINES,
139
+ ...(child
140
+ ? [
141
+ '',
142
+ 'You share the lead session\'s permission posture: confirmations are off for your tool',
143
+ 'calls too, and every rule above binds you exactly as it binds the lead.',
144
+ ]
145
+ : []),
146
+ ...postureNote(params),
147
+ '',
148
+ ...CLOSING_LINES,
149
+ '</redteam_mode>',
150
+ ].join('\n');
151
+ }
152
+ /**
153
+ * The three-row session banner (4.6), as plain lines for the `notice` entry.
154
+ *
155
+ * THE CONFIRMATION SENTENCE IS CONDITIONAL (RV-1 / D-19): the banner is the third place a
156
+ * user could be told something that did not happen, so it states which of the three
157
+ * situations this session is actually in.
158
+ */
159
+ export function buildRedTeamBanner(scope, confirmations) {
160
+ return redTeamBannerLines({ scope, confirmations });
161
+ }