@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,77 @@
1
+ /**
2
+ * Command-line validation for `--redteam` / `--no-redteam` (red-team-security-mode 4.8).
3
+ *
4
+ * PURE, AND OUT OF `cli.tsx` ON PURPOSE: that file is far past the size limit, and these
5
+ * rules are the kind that regress silently - a missing headless rule ships a "start armed"
6
+ * flag into `aragon exec`, where nobody can accept a waiver. `cli.tsx` gathers the facts and
7
+ * prints the message.
8
+ *
9
+ * TWO RULES, AND THE ONE THAT IS ABSENT IS THE POINT (RV-1 / D-20). v1 refused
10
+ * `--redteam --confirm`; that was backwards. `--confirm` is the NARROWER authorization - a
11
+ * user who enters red team mode with the confirmation gate switched on is a configuration
12
+ * this very feature supports (`redteam.bypassConfirm=false`) - so the pair is ALLOWED and the
13
+ * banner and `/redteam status` say what happened to the gate.
14
+ *
15
+ * ASCII ONLY: `src/config/**` is inside the glyph scanner's scope.
16
+ */
17
+ export interface RedTeamLaunchInput {
18
+ /** `--redteam`: start this session armed. */
19
+ redTeam?: boolean;
20
+ /** `--no-redteam`: unregister the whole chain for this launch. */
21
+ noRedTeam?: boolean;
22
+ /** `ARAGON_REDTEAM=0` or `redteam.enabled: false` in the resolved config. */
23
+ unavailable?: boolean;
24
+ /** The waiver version `state.json` holds; `0` means never accepted. */
25
+ waiverVersion: number;
26
+ /**
27
+ * The run cannot reach a human: `-p/--print`, the `exec` subcommand, piped stdin or a
28
+ * non-TTY stdout. A waiver cannot be accepted there, and a posture nobody can leave is
29
+ * worse than no posture.
30
+ */
31
+ headless: boolean;
32
+ }
33
+ export interface RedTeamLaunchDecision {
34
+ /** The chain exists in this session at all. */
35
+ available: boolean;
36
+ /** Start with the mode armed. */
37
+ startArmed: boolean;
38
+ /** `--redteam` was asked for and will NOT be honoured; the reason was already reported. */
39
+ ignored: boolean;
40
+ }
41
+ export type RedTeamLaunchCheck = {
42
+ ok: true;
43
+ decision: RedTeamLaunchDecision;
44
+ } | {
45
+ ok: false;
46
+ message: string;
47
+ };
48
+ export declare const REDTEAM_HEADLESS_MESSAGE = "--redteam is a terminal session posture; it is not available in print or exec mode.";
49
+ export declare const REDTEAM_UNAVAILABLE_MESSAGE: string;
50
+ /** `--redteam needs the disclaimer accepted first.` - the message names the exact next step. */
51
+ export declare const REDTEAM_WAIVER_MESSAGE = "--redteam needs the disclaimer accepted first. Run aragon, press Ctrl+R and accept it.";
52
+ /**
53
+ * Resolve the launch. ORDER IS THE CONTRACT, and it is the order of the two things a user
54
+ * cannot fix by dropping another flag: headless first (no terminal, so no waiver and no way
55
+ * out), then the waiver itself.
56
+ *
57
+ * `--no-redteam` and an unavailable config are NOT errors even when `--redteam` was also
58
+ * passed: the negative wins, the session starts disarmed, and the caller reports it once.
59
+ * Making that combination fatal would punish a wrapper script that always passes
60
+ * `--redteam` and sometimes adds `--no-redteam`.
61
+ */
62
+ export declare function validateRedTeamLaunch(input: RedTeamLaunchInput): RedTeamLaunchCheck;
63
+ /** The root-level options these rules read, as commander materialises them. */
64
+ export interface RedTeamRootOptions {
65
+ /** `--redteam` is declared alone, so an absent flag reads `undefined`. */
66
+ redteam?: boolean;
67
+ /** `--no-redteam` is declared alone: `false` when given. */
68
+ noRedteamFlag?: boolean;
69
+ }
70
+ export interface RedTeamCommandContext {
71
+ commandName: string;
72
+ isRootAction: boolean;
73
+ stdinIsTty: boolean;
74
+ stdoutIsTty: boolean;
75
+ }
76
+ /** The `preAction` hook's decision: `exec` is always headless, the root action is when piped. */
77
+ export declare function checkRedTeamCommandLine(options: RedTeamRootOptions, context: RedTeamCommandContext, waiverVersion: number, unavailable: boolean): RedTeamLaunchCheck;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Command-line validation for `--redteam` / `--no-redteam` (red-team-security-mode 4.8).
3
+ *
4
+ * PURE, AND OUT OF `cli.tsx` ON PURPOSE: that file is far past the size limit, and these
5
+ * rules are the kind that regress silently - a missing headless rule ships a "start armed"
6
+ * flag into `aragon exec`, where nobody can accept a waiver. `cli.tsx` gathers the facts and
7
+ * prints the message.
8
+ *
9
+ * TWO RULES, AND THE ONE THAT IS ABSENT IS THE POINT (RV-1 / D-20). v1 refused
10
+ * `--redteam --confirm`; that was backwards. `--confirm` is the NARROWER authorization - a
11
+ * user who enters red team mode with the confirmation gate switched on is a configuration
12
+ * this very feature supports (`redteam.bypassConfirm=false`) - so the pair is ALLOWED and the
13
+ * banner and `/redteam status` say what happened to the gate.
14
+ *
15
+ * ASCII ONLY: `src/config/**` is inside the glyph scanner's scope.
16
+ */
17
+ import { REDTEAM_DISCLAIMER_VERSION } from '@aragon-agent/tui/model/redteam/limits';
18
+ export const REDTEAM_HEADLESS_MESSAGE = '--redteam is a terminal session posture; it is not available in print or exec mode.';
19
+ export const REDTEAM_UNAVAILABLE_MESSAGE = '--redteam was requested, but red team mode is off for this launch '
20
+ + '(--no-redteam, redteam.enabled=false or ARAGON_REDTEAM=0).';
21
+ /** `--redteam needs the disclaimer accepted first.` - the message names the exact next step. */
22
+ export const REDTEAM_WAIVER_MESSAGE = '--redteam needs the disclaimer accepted first. Run aragon, press Ctrl+R and accept it.';
23
+ /**
24
+ * Resolve the launch. ORDER IS THE CONTRACT, and it is the order of the two things a user
25
+ * cannot fix by dropping another flag: headless first (no terminal, so no waiver and no way
26
+ * out), then the waiver itself.
27
+ *
28
+ * `--no-redteam` and an unavailable config are NOT errors even when `--redteam` was also
29
+ * passed: the negative wins, the session starts disarmed, and the caller reports it once.
30
+ * Making that combination fatal would punish a wrapper script that always passes
31
+ * `--redteam` and sometimes adds `--no-redteam`.
32
+ */
33
+ export function validateRedTeamLaunch(input) {
34
+ const unavailable = input.unavailable === true || input.noRedTeam === true;
35
+ const requested = input.redTeam === true && !unavailable;
36
+ if (!requested) {
37
+ return { ok: true, decision: { available: !unavailable, startArmed: false, ignored: false } };
38
+ }
39
+ if (input.headless)
40
+ return { ok: false, message: REDTEAM_HEADLESS_MESSAGE };
41
+ if (input.waiverVersion < REDTEAM_DISCLAIMER_VERSION) {
42
+ return { ok: false, message: REDTEAM_WAIVER_MESSAGE };
43
+ }
44
+ return { ok: true, decision: { available: true, startArmed: true, ignored: false } };
45
+ }
46
+ /** The `preAction` hook's decision: `exec` is always headless, the root action is when piped. */
47
+ export function checkRedTeamCommandLine(options, context, waiverVersion, unavailable) {
48
+ const headless = context.commandName === 'exec'
49
+ || (context.isRootAction
50
+ && (options.redteam === true && (!context.stdinIsTty || !context.stdoutIsTty)));
51
+ return validateRedTeamLaunch({
52
+ ...(options.redteam === true ? { redTeam: true } : {}),
53
+ ...(options.noRedteamFlag === false ? { noRedTeam: true } : {}),
54
+ unavailable,
55
+ waiverVersion,
56
+ headless,
57
+ });
58
+ }
@@ -17,7 +17,7 @@ import { getConfigPath, getSessionsDir } from './app-paths.js';
17
17
  import { registerProfileSecrets, registerSecretsFrom } from '@aragon-agent/tui/model/logging/secret-registry';
18
18
  import { adaptLegacyConnectionPatch, ModelProfileConfigError, readModelSettingsDisk } from './model-profile-store.js';
19
19
  import { normalizeModelProfiles } from '@aragon-agent/tui/model/config/model-profiles';
20
- import { clampBashConfig, clampJobsConfig, clampPromptsConfig, clampTaskSummaryConfig, CONFIG_VERSION, DEFAULT_CONFIG, clampCompactionConfig, clampFastConfig, clampGovernanceConfig, clampLogConfig, clampMaxTokens, clampRetryConfig, clampSkillsConfig, clampTeamConfig, clampTodoConfig, clampContextWindow, clampUpdateConfig, isAutoToken, stripLegacyStateKeys, stripRetiredConfigKeys, } from '@aragon-agent/tui/model/config/schema';
20
+ import { clampBashConfig, clampJobsConfig, clampPromptsConfig, clampTaskSummaryConfig, CONFIG_VERSION, DEFAULT_CONFIG, clampCompactionConfig, clampFastConfig, clampGovernanceConfig, clampLogConfig, clampMemoryConfig, clampRedTeamConfig, clampMaxTokens, clampRetryConfig, clampSkillsConfig, clampTeamConfig, clampTodoConfig, clampContextWindow, clampUpdateConfig, isAutoToken, stripLegacyStateKeys, stripRetiredConfigKeys, } from '@aragon-agent/tui/model/config/schema';
21
21
  /**
22
22
  * Normalize `maxTokens` for both directions of the config file.
23
23
  *
@@ -220,6 +220,15 @@ export function normalizePersistedConfig(input) {
220
220
  ...DEFAULT_CONFIG.governance,
221
221
  ...(partial.governance ?? {}),
222
222
  }),
223
+ // And the fifteenth. A `config.json` predating agent memory must resolve a whole
224
+ // section, and a hand-edited one is clamped: the file cannot carry a budget the
225
+ // planner would refuse or an `agentWrites` that is neither of the three values.
226
+ memory: clampMemoryConfig({ ...DEFAULT_CONFIG.memory, ...(partial.memory ?? {}) }),
227
+ // And the sixteenth. A `config.json` predating red team mode must resolve a whole
228
+ // section - and this one, unlike most, has a direction that matters: `enabled` defaults
229
+ // to `true`, so an absent section here would arrive with the mode switched OFF for every
230
+ // existing user in exactly the session where `Ctrl+R` is expected to work.
231
+ redteam: clampRedTeamConfig({ ...DEFAULT_CONFIG.redteam, ...(partial.redteam ?? {}) }),
223
232
  };
224
233
  }
225
234
  /**
@@ -347,6 +356,16 @@ export function mergePersistedConfig(current, patch) {
347
356
  // absent, and without the clamp 9 reaches the disk and the engine's ceiling is the
348
357
  // only thing that stops it. The WRITE half of the two-direction gate.
349
358
  governance: clampGovernanceConfig({ ...current.governance, ...(patch.governance ?? {}) }),
359
+ // The fifteenth section, and the tenth time this file records the same trap.
360
+ // `aragon config set memory.autoload false` sends `{ memory: { autoload: false } }`;
361
+ // without this merge the shallow spread REPLACES the section and `agentWrites` is
362
+ // written absent - which must never read back as anything but `ask`.
363
+ memory: clampMemoryConfig({ ...current.memory, ...(patch.memory ?? {}) }),
364
+ // The sixteenth section, and the eleventh time this file records the same trap.
365
+ // `aragon config set redteam.bypassConfirm false` sends `{ redteam: { bypassConfirm:
366
+ // false } }`; without this merge the shallow spread REPLACES the section and `enabled` is
367
+ // written absent, which reads back as the default rather than as the user's switch.
368
+ redteam: clampRedTeamConfig({ ...current.redteam, ...(patch.redteam ?? {}) }),
350
369
  };
351
370
  return merged;
352
371
  }
@@ -113,6 +113,23 @@ export interface UiState {
113
113
  * it as `false`, which is exactly the first-run behaviour wanted.
114
114
  */
115
115
  governanceIntroSeen: boolean;
116
+ /**
117
+ * The red team waiver version this machine has accepted; `0` = never (red-team-security-mode
118
+ * 4.3 / D-3).
119
+ *
120
+ * IT LIVES HERE, NOT IN `config.json`, and that is a design decision rather than a storage
121
+ * detail: "this machine's user agreed to version N of this text" is a MACHINE FACT about a
122
+ * one-time act, exactly like the notice versions above, while `config.json` is the user's
123
+ * POLICY. `migrateStateOutOfConfig` was written because those two got mixed once already.
124
+ *
125
+ * `>= REDTEAM_DISCLAIMER_VERSION` counts as accepted, so raising the constant asks every
126
+ * user again - which is the only way a one-time acceptance can ever reach new text (RV-20).
127
+ *
128
+ * A NEW SCALAR AND NOT A SCHEMA BUMP, for the fourth time in this file: a schema bump makes
129
+ * `readFromDisk` discard the whole object, resetting every user's `submitCount` to re-ask
130
+ * one question.
131
+ */
132
+ redTeamWaiverVersion: number;
116
133
  }
117
134
  /** Read the state, caching it for the life of the process. Never throws. */
118
135
  export declare function loadUiState(): UiState;
@@ -136,6 +153,33 @@ export declare function setPromptKeyNoticeVersion(version: number): void;
136
153
  /** `false` until the one-time GOVERN explainer has been shown; persisted across launches. */
137
154
  export declare function getGovernanceIntroSeen(): boolean;
138
155
  export declare function setGovernanceIntroSeen(seen: boolean): void;
156
+ /**
157
+ * The accepted red team waiver version; `0` on a file written before the field existed.
158
+ *
159
+ * A READER, NOT A DECISION: whether `0` is "accepted" is
160
+ * `version >= REDTEAM_DISCLAIMER_VERSION`, and that comparison lives in `RedTeamWiring` so the
161
+ * constant has exactly one consumer (I-3).
162
+ */
163
+ export declare function getRedTeamWaiverVersion(): number;
164
+ /**
165
+ * Record the acceptance and RETURN WHAT LANDED ON DISK, read back rather than trusted.
166
+ *
167
+ * It goes through `update` - the same atomic write every state field uses - so a failed write
168
+ * leaves the in-memory value intact and the disk unchanged, and the caller's `disclaimer
169
+ * accepted` claim is never based on a value the process only hopes it wrote (T-A1).
170
+ * `askEveryArm` re-asking goes through THIS function too, which is what makes a re-acceptance
171
+ * idempotent: it re-writes the same number (RV-21).
172
+ */
173
+ export declare function acceptRedTeamWaiver(version: number): number;
174
+ /**
175
+ * `ARAGON_REDTEAM=0` in its kill-switch spellings, read from the LIVE environment.
176
+ *
177
+ * A SECOND READER OF THE SAME RULE, and only for `cli.tsx`'s `preAction` hook, which runs
178
+ * BEFORE `loadConfig` (so the folded `redteam.enabled` does not exist yet) and must refuse
179
+ * `--redteam` in a session the environment killed. `config/env.ts` remains the place the value
180
+ * lands in the resolved config; the two agree because the value set here is the one it accepts.
181
+ */
182
+ export declare function isRedTeamEnvOff(env?: Readonly<Record<string, string | undefined>>): boolean;
139
183
  /**
140
184
  * Migration-only: fill in fields that are still at their default, and never
141
185
  * overwrite a value already here. A second import — after a half-finished
@@ -40,6 +40,7 @@ const DEFAULT_UI_STATE = {
40
40
  scrollModeNoticeVersion: 0,
41
41
  promptKeyNoticeVersion: 0,
42
42
  governanceIntroSeen: false,
43
+ redTeamWaiverVersion: 0,
43
44
  };
44
45
  let memory = null;
45
46
  /** Non-negative integer or `fallback`; shared by both numeric fields. */
@@ -77,6 +78,7 @@ function readFromDisk() {
77
78
  governanceIntroSeen: typeof parsed.governanceIntroSeen === 'boolean'
78
79
  ? parsed.governanceIntroSeen
79
80
  : DEFAULT_UI_STATE.governanceIntroSeen,
81
+ redTeamWaiverVersion: coerceCount(parsed.redTeamWaiverVersion, DEFAULT_UI_STATE.redTeamWaiverVersion),
80
82
  };
81
83
  }
82
84
  catch {
@@ -171,6 +173,42 @@ export function getGovernanceIntroSeen() {
171
173
  export function setGovernanceIntroSeen(seen) {
172
174
  update({ governanceIntroSeen: seen });
173
175
  }
176
+ /**
177
+ * The accepted red team waiver version; `0` on a file written before the field existed.
178
+ *
179
+ * A READER, NOT A DECISION: whether `0` is "accepted" is
180
+ * `version >= REDTEAM_DISCLAIMER_VERSION`, and that comparison lives in `RedTeamWiring` so the
181
+ * constant has exactly one consumer (I-3).
182
+ */
183
+ export function getRedTeamWaiverVersion() {
184
+ return loadUiState().redTeamWaiverVersion;
185
+ }
186
+ /**
187
+ * Record the acceptance and RETURN WHAT LANDED ON DISK, read back rather than trusted.
188
+ *
189
+ * It goes through `update` - the same atomic write every state field uses - so a failed write
190
+ * leaves the in-memory value intact and the disk unchanged, and the caller's `disclaimer
191
+ * accepted` claim is never based on a value the process only hopes it wrote (T-A1).
192
+ * `askEveryArm` re-asking goes through THIS function too, which is what makes a re-acceptance
193
+ * idempotent: it re-writes the same number (RV-21).
194
+ */
195
+ export function acceptRedTeamWaiver(version) {
196
+ const whole = Number.isFinite(version) ? Math.max(0, Math.floor(version)) : 0;
197
+ const next = update({ redTeamWaiverVersion: whole });
198
+ return loadUiState().redTeamWaiverVersion === whole ? whole : next.redTeamWaiverVersion;
199
+ }
200
+ /**
201
+ * `ARAGON_REDTEAM=0` in its kill-switch spellings, read from the LIVE environment.
202
+ *
203
+ * A SECOND READER OF THE SAME RULE, and only for `cli.tsx`'s `preAction` hook, which runs
204
+ * BEFORE `loadConfig` (so the folded `redteam.enabled` does not exist yet) and must refuse
205
+ * `--redteam` in a session the environment killed. `config/env.ts` remains the place the value
206
+ * lands in the resolved config; the two agree because the value set here is the one it accepts.
207
+ */
208
+ export function isRedTeamEnvOff(env = process.env) {
209
+ const value = env.ARAGON_REDTEAM?.trim().toLowerCase();
210
+ return value === '0' || value === 'false' || value === 'off' || value === 'no';
211
+ }
174
212
  /**
175
213
  * Migration-only: fill in fields that are still at their default, and never
176
214
  * overwrite a value already here. A second import — after a half-finished
@@ -23,7 +23,7 @@
23
23
  * model cannot see it and the caller can.
24
24
  */
25
25
  import { errorResult } from '@aragon-agent/core';
26
- import { HOST_TOOL_NAMES } from '../../tools/index.js';
26
+ import { HOST_TOOL_NAMES, MEMORY_TOOL_NAMES } from '../../tools/index.js';
27
27
  import { TEAM_SUBAGENT_TOOL_NAMES } from '@aragon-agent/tui/model/team/limits';
28
28
  import { BRIDGE_LIMITS } from './limits.js';
29
29
  import { createPendingTable } from './pending.js';
@@ -34,8 +34,15 @@ export function createBridgeServer(options) {
34
34
  const sessionId = options.sessionId;
35
35
  const writer = options.writer;
36
36
  const pending = createPendingTable({ now });
37
+ // The memory tools are in `HOST_TOOL_NAMES` (the superset a skill may name) but a headless
38
+ // run NEVER registers them (agent-memory D-20), so reserving their names would only reject a
39
+ // caller tool called `memory_search` - a perfectly legitimate integration (RV-5).
40
+ const memoryNames = new Set(MEMORY_TOOL_NAMES);
37
41
  const reserved = options.reservedToolNames ??
38
- new Set([...HOST_TOOL_NAMES, ...TEAM_SUBAGENT_TOOL_NAMES]);
42
+ new Set([
43
+ ...HOST_TOOL_NAMES.filter((name) => !memoryNames.has(name)),
44
+ ...TEAM_SUBAGENT_TOOL_NAMES,
45
+ ]);
39
46
  let open = true;
40
47
  let turn = 0;
41
48
  let turnPorts = null;
@@ -14,7 +14,7 @@
14
14
  * half-written event would corrupt every consumer. The caller writes the message
15
15
  * to stderr and exits.
16
16
  */
17
- import { HOST_TOOL_NAMES } from '../tools/index.js';
17
+ import { HOST_TOOL_NAMES, MEMORY_TOOL_NAMES } from '../tools/index.js';
18
18
  import { isValidSessionId } from '../session/store.js';
19
19
  import { BRIDGE_LIMITS } from './bridge/limits.js';
20
20
  import { RESULT_LIMITS } from './result/limits.js';
@@ -43,7 +43,16 @@ const ON_HOOK_TIMEOUT_MODES = ['deny', 'allow', 'error'];
43
43
  * "can this declaration ever take effect?", and the answer for these two is yes,
44
44
  * just not here - so exec accepts it and says one line on stderr.
45
45
  */
46
- const NEVER_REGISTERED_HEADLESS = ['ask_user', 'submit_plan'];
46
+ const NEVER_REGISTERED_HEADLESS = [
47
+ 'ask_user',
48
+ 'submit_plan',
49
+ // The memory tools (agent-memory D-20): a headless run neither builds the memory block nor
50
+ // registers the tools, so naming them here validates (they are in HOST_TOOL_NAMES) and then
51
+ // does nothing - which the warnings below say out loud instead of accepting in silence.
52
+ 'memory_search',
53
+ 'memory_read',
54
+ 'memory_write',
55
+ ];
47
56
  /**
48
57
  * Flags that need to observe or interrupt the stream `runHeadless` owns, and are
49
58
  * therefore REFUSED under `--output-format text` (D-1).
@@ -217,6 +226,11 @@ export function resolveExecOptions(raw, context = {}) {
217
226
  "stopReason 'max_turns' and error.code 'result_schema_unsatisfied'.");
218
227
  }
219
228
  }
229
+ for (const name of denyTools) {
230
+ if (MEMORY_TOOL_NAMES.includes(name)) {
231
+ warnings.push(`--deny-tool ${name}: that tool is never registered in a headless run, so this deny has no effect.`);
232
+ }
233
+ }
220
234
  if (structured.resultSchemaPath === undefined && denyTools.includes('submit_result')) {
221
235
  // W-3. `submit_result` is registered ONLY by `--result-schema`, so denying it here
222
236
  // denies a name that will never exist. Same argument as NEVER_REGISTERED_HEADLESS.
@@ -67,8 +67,8 @@ function powersSection() {
67
67
  '',
68
68
  'Your tools: gov_run, gov_dispatch, ask_user, todo_write, and every tool that only reads',
69
69
  '(read_file, list_dir, glob, grep, skill, skill_find, bash_output, job_wait, job_list).',
70
- 'write_file, edit_file, bash, bash_kill, skill_install, skill_create and task are refused in',
71
- 'this mode on purpose: all implementation happens through dispatched agents.',
70
+ 'write_file, edit_file, bash, bash_kill, skill_install, skill_create, memory_write and task are',
71
+ 'refused in this mode on purpose: all implementation happens through dispatched agents.',
72
72
  ];
73
73
  }
74
74
  function startSteps(maxWorkPackages) {
@@ -19,6 +19,8 @@ import type { ToolPermission } from '../exec/permission.js';
19
19
  import type { ToolHookRunner } from '../exec/hooks/tool-wrapper.js';
20
20
  import type { ApprovalGate } from '../skills/service.js';
21
21
  import { SessionCheckpointWriter, type LiveSessionView } from '../session/checkpoint.js';
22
+ import type { SessionFollowUpMeta } from '../session/persist.js';
23
+ import type { SessionLockHandle } from '../session/store.js';
22
24
  import type { ToolGate } from '../tools/tool-gate.js';
23
25
  import type { ConfirmRequest } from '../tools/index.js';
24
26
  /** Re-exported so a host can name the controller type without a deep import. */
@@ -85,6 +87,14 @@ export declare function makeController(flags: CliFlags, opts?: {
85
87
  * Absent for every caller except a bridge run's `makeExecController`.
86
88
  */
87
89
  hookRunner?: ToolHookRunner;
90
+ /**
91
+ * `--redteam`: build this session ARMED (red-team-security-mode 4.8).
92
+ *
93
+ * SET BY `runInteractive` ONLY, from the launch decision `validateRedTeamLaunch` produced.
94
+ * Absent everywhere else - `-p`, `aragon exec`, every subcommand - which is what keeps those
95
+ * sessions' prompts and tools byte-identical (I-1).
96
+ */
97
+ redTeamArmed?: boolean;
88
98
  }): {
89
99
  controller: AgentController;
90
100
  confirmBridge: ConfirmBridge;
@@ -106,4 +116,27 @@ export declare function createSessionWriter(input: {
106
116
  readView: () => LiveSessionView | undefined;
107
117
  readParentId: () => string | undefined;
108
118
  startPinned: boolean;
119
+ /**
120
+ * Where this session's checkpoints go, and whether it takes the sessions-directory lock
121
+ * (desktop-follow-up-panel P1-1 / P2-11).
122
+ *
123
+ * ABSENT FOR EVERY EXISTING CALLER, which is what keeps `cli.tsx`'s two sites byte-identical:
124
+ * `SessionCheckpointWriter` already defaults `pathFor` to `sessionPathFor` and `lockFor` to
125
+ * `tryAcquireSessionLock`, and a follow-up session is the only producer that answers differently.
126
+ *
127
+ * `lockFor: () => null` IS NOT "NO LOCK NEEDED", it is "THIS PATH CANNOT USE THAT LOCK":
128
+ * `tryAcquireSessionLock` always writes `<sessions>/<id>.lock`, so a follow-up writing under
129
+ * `sessions/follow-ups/` would leave an orphan lock in the SESSIONS directory for a file that is
130
+ * not there. The two keys travel together for that reason.
131
+ */
132
+ paths?: {
133
+ pathFor: (id: string) => string;
134
+ lockFor: (id: string) => SessionLockHandle | null;
135
+ };
136
+ /**
137
+ * The follow-up block this session records, as a VALUE (P1-1). Absent for every ordinary
138
+ * session, which is what keeps its checkpoint bytes identical to one written before this
139
+ * feature.
140
+ */
141
+ followUp?: SessionFollowUpMeta;
109
142
  }): SessionCheckpointWriter;
@@ -120,6 +120,10 @@ export function makeController(flags, opts = { interactive: true }) {
120
120
  ? { structuredResultBlock: opts.structuredResultBlock }
121
121
  : {}),
122
122
  ...(opts.hookRunner ? { hookRunner: opts.hookRunner } : {}),
123
+ // `--redteam` (red-team-security-mode 4.8). SPREAD, so a launch without the flag builds the
124
+ // deps bag it always did; the value is already the output of `validateRedTeamLaunch`, which
125
+ // is the only place allowed to refuse it.
126
+ ...(opts.redTeamArmed === true ? { redTeamArmed: true } : {}),
123
127
  });
124
128
  return { controller, confirmBridge, humanInputBridge };
125
129
  }
@@ -141,6 +145,11 @@ export function createSessionWriter(input) {
141
145
  // The verdicts travel with the plan; read from the STORE, not from the render
142
146
  // projection, so a checkpoint taken while the capability is off still saves them.
143
147
  readAcceptance: () => controller.getAcceptanceItems(),
148
+ // Mounts and switches only - ids, never text (agent-memory I-18).
149
+ readMemory: () => controller.getMemoryService()?.exportState(),
150
+ // The armed flag and the waiver version, read at write time: a user can arm or disarm
151
+ // between two checkpoints (red-team-security-mode 4.10).
152
+ readRedTeam: () => controller.getRedTeamSessionState(),
144
153
  // READ AT WRITE TIME: `/model` rebuilds the config, and a checkpoint that
145
154
  // recorded the model from launch would name the wrong one after a switch.
146
155
  readModel: () => {
@@ -155,5 +164,10 @@ export function createSessionWriter(input) {
155
164
  version: VERSION,
156
165
  readParentId: input.readParentId,
157
166
  startPinned: input.startPinned,
167
+ // NAMED, NOT SPREAD (the R3 lesson above): a dependency this factory does not name here is
168
+ // dropped in silence, and the symptom of a dropped `paths` is a follow-up file written into
169
+ // the sessions directory, where it would appear in the sidebar (R-9).
170
+ ...(input.paths ? { pathFor: input.paths.pathFor, lockFor: input.paths.lockFor } : {}),
171
+ ...(input.followUp ? { followUp: input.followUp } : {}),
158
172
  });
159
173
  }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * The follow-up panel's context seed (desktop-follow-up-panel §4.4).
3
+ *
4
+ * A follow-up conversation starts from a SNAPSHOT of its parent: the newest tail of the parent's
5
+ * history that fits a small budget, cut only at a boundary the engine itself considers safe, plus
6
+ * the excerpt the user highlighted (which travels in the child's system prompt, not here).
7
+ *
8
+ * WHY A CUT INSTEAD OF A SUMMARY. A summary would be a second model call - latency, cost, and a
9
+ * lossy paraphrase - to answer a question about text the user is looking at right now. The
10
+ * structural rules that make a history sendable already exist in the engine
11
+ * (`findSafeCutIndices` / `validateHistory` / `relieveTail`), so this module composes them rather
12
+ * than inventing a second set. It is pure: no IO, no logger, no model, no Ink.
13
+ *
14
+ * `FollowUpSeed` AND `FollowUpSeedInput` ARE DEFINED HERE AND NOWHERE ELSE. They are the payload
15
+ * of a control-plane message (main process <-> host, §7.3), so a second copy in the desktop app's
16
+ * `shared/` would drift; that side re-exports these types with `import type` instead.
17
+ */
18
+ import { type Message } from '@aragon-agent/core';
19
+ export interface FollowUpSeedInput {
20
+ /** The parent's complete history, read-only. */
21
+ messages: readonly Message[];
22
+ /**
23
+ * The system prompt the token projection is measured against.
24
+ *
25
+ * NOT "the child's final system prompt" - the parent cannot obtain that. It is
26
+ * `parentController.getSystemPrompt() + buildFollowUpPromptBlock(anchor)`, which is exact
27
+ * because `appendSystemPrompt` is concatenated verbatim by `buildSystemPrompt`. The child
28
+ * re-measures with its OWN prompt before adopting the seed (§4.4 step 7), so this number only
29
+ * has to be close to be useful and is never the last word.
30
+ */
31
+ systemPrompt: string;
32
+ /** The parent's context window; absent means 200k. */
33
+ contextWindow?: number;
34
+ /** The input budget for the child; absent means window x 0.5, capped at 24k. */
35
+ budgetTokens?: number;
36
+ }
37
+ export interface FollowUpSeed {
38
+ messages: Message[];
39
+ /** Complete turns dropped from the head, for an honest notice in the panel. */
40
+ omittedTurns: number;
41
+ /** Projected input tokens of `messages` (`estimatePromptTokens`). */
42
+ tokens: number;
43
+ /** Tool results whose bodies were clipped by tail relief. */
44
+ clipped: number;
45
+ }
46
+ /** Half the window, and never more than this: a follow-up is a side question, not a session. */
47
+ export declare const FOLLOW_UP_BUDGET_TOKENS = 24000;
48
+ export declare const FOLLOW_UP_BUDGET_WINDOW_RATIO = 0.5;
49
+ /**
50
+ * The first message of a cut history, when the cut left it starting with a non-`user` role.
51
+ *
52
+ * Some providers refuse a history whose first message is not from the user, and a silent refusal
53
+ * is discovered by the user as "the panel does not answer". The text is deliberately plain: it is
54
+ * read by the model, not by the user.
55
+ */
56
+ export declare const FOLLOW_UP_OMITTED_HEADER = "[earlier turns omitted]";
57
+ /**
58
+ * Plan the seed.
59
+ *
60
+ * THE SIX STEPS ARE SEPARATE ON PURPOSE (spec §4.4): each one is a decision a reader has to be
61
+ * able to check on its own, and merging any two of them hides a rule that has a test.
62
+ *
63
+ * AN EMPTY SEED IS NOT AN ERROR. Every failure below (no safe cut, an unsendable result) returns
64
+ * the empty seed, and the caller turns that into `seedSource: 'excerpt'` plus one honest line in
65
+ * the panel. Throwing here would make the panel's first frame depend on the parent's history
66
+ * being tidy, which is exactly the case the excerpt-only fallback exists for.
67
+ */
68
+ export declare function planFollowUpSeed(input: FollowUpSeedInput): FollowUpSeed;
69
+ /** The empty seed, for callers that want to spell "no context" without building one. */
70
+ export declare function emptyFollowUpSeed(): FollowUpSeed;
71
+ /** Why a seed was not adopted. Every value degrades the panel to "excerpt only" with one sentence. */
72
+ export type AdoptSeedRefusal = 'empty' | 'too_large' | 'unsendable';
73
+ export interface AdoptFollowUpSeedInput {
74
+ seed: FollowUpSeed | null;
75
+ /**
76
+ * THE ADOPTING HOST'S OWN system prompt, anchor block included.
77
+ *
78
+ * The parent measured the seed against `parentSystemPrompt + block`; this host may carry a
79
+ * different persona or a model switch that landed in between, so the same messages can cost a
80
+ * different number of tokens here. This second measurement is what makes the parent's "exact
81
+ * equation" degrade into SLOWER rather than wrong when the two prompts drift (P0-2's second gate).
82
+ */
83
+ systemPrompt: string;
84
+ /** The host's budget; absent means `FOLLOW_UP_BUDGET_TOKENS` bounded by half `contextWindow`. */
85
+ budgetTokens?: number;
86
+ contextWindow?: number;
87
+ }
88
+ export interface AdoptFollowUpSeedResult {
89
+ /** The messages to hand `replaceMessages`, or `null` when the seed was refused. */
90
+ messages: Message[] | null;
91
+ refusal?: AdoptSeedRefusal;
92
+ /** Tool results clipped in total: the parent's pass plus this host's re-measurement. */
93
+ clipped: number;
94
+ }
95
+ /**
96
+ * Decide whether this host may adopt a seed the parent produced.
97
+ *
98
+ * THREE GATES, IN THIS ORDER AND NO OTHER:
99
+ *
100
+ * 1. `closeDanglingToolCalls` - an interrupted parent turn left a call with no result, which is
101
+ * normal and must be repaired rather than refused.
102
+ * 2. the budget, measured HERE, with relief as the last rung before giving up.
103
+ * 3. `validateHistory` - the structural gate. `replaceMessages` validates NOTHING (its own source
104
+ * says so), so an unsendable history handed to it becomes a provider 400 in the panel.
105
+ *
106
+ * A REFUSAL IS NOT AN ERROR: the caller starts from the excerpt and says so. Trimming a seed that
107
+ * failed the gate into something smaller would answer confidently about context that was lost.
108
+ */
109
+ export declare function adoptFollowUpSeed(input: AdoptFollowUpSeedInput): AdoptFollowUpSeedResult;