@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.
- package/CHANGELOG.md +64 -0
- package/README.md +135 -6
- package/dist/agent/controller.d.ts +98 -0
- package/dist/agent/controller.js +341 -1
- package/dist/agent/redteam-prompt.d.ts +47 -0
- package/dist/agent/redteam-prompt.js +161 -0
- package/dist/agent/redteam-wiring.d.ts +159 -0
- package/dist/agent/redteam-wiring.js +349 -0
- package/dist/agent/system-prompt.d.ts +27 -0
- package/dist/agent/system-prompt.js +10 -0
- package/dist/app/App.d.ts +17 -1
- package/dist/app/App.js +266 -26
- package/dist/app/use-redteam-mode.d.ts +56 -0
- package/dist/app/use-redteam-mode.js +121 -0
- package/dist/cli.js +78 -4
- package/dist/commands/builtins.js +49 -1
- package/dist/commands/catalog.js +5 -0
- package/dist/commands/index-build.js +2 -1
- package/dist/commands/redteam-command.d.ts +22 -0
- package/dist/commands/redteam-command.js +141 -0
- package/dist/commands/registry.d.ts +7 -0
- package/dist/compaction/compactor.d.ts +26 -0
- package/dist/compaction/compactor.js +81 -8
- package/dist/compaction/summarize-call.d.ts +22 -0
- package/dist/compaction/summarize-call.js +29 -0
- package/dist/compaction/wiring.js +22 -3
- package/dist/config/app-paths.d.ts +13 -0
- package/dist/config/app-paths.js +15 -0
- package/dist/config/cli-commands.d.ts +15 -0
- package/dist/config/cli-commands.js +32 -1
- package/dist/config/env.d.ts +3 -1
- package/dist/config/env.js +23 -1
- package/dist/config/load.d.ts +18 -0
- package/dist/config/load.js +19 -1
- package/dist/config/redteam-launch.d.ts +77 -0
- package/dist/config/redteam-launch.js +58 -0
- package/dist/config/store.js +20 -1
- package/dist/config/ui-state.d.ts +44 -0
- package/dist/config/ui-state.js +38 -0
- package/dist/exec/bridge/server.js +9 -2
- package/dist/exec/options.js +16 -2
- package/dist/governance/prompts/orchestrator-block.js +2 -2
- package/dist/host/controller-factory.d.ts +33 -0
- package/dist/host/controller-factory.js +14 -0
- package/dist/host/follow-up-seed.d.ts +109 -0
- package/dist/host/follow-up-seed.js +196 -0
- package/dist/host/follow-up.d.ts +73 -0
- package/dist/host/follow-up.js +123 -0
- package/dist/host/index.d.ts +3 -0
- package/dist/host/index.js +3 -0
- package/dist/host/memory.d.ts +21 -0
- package/dist/host/memory.js +17 -0
- package/dist/host/sessions.d.ts +32 -2
- package/dist/host/sessions.js +40 -2
- package/dist/logging/install.d.ts +1 -0
- package/dist/logging/install.js +4 -0
- package/dist/logging/logger.d.ts +1 -1
- package/dist/memory/block.d.ts +24 -0
- package/dist/memory/block.js +54 -0
- package/dist/memory/command.d.ts +31 -0
- package/dist/memory/command.js +350 -0
- package/dist/memory/format.d.ts +51 -0
- package/dist/memory/format.js +308 -0
- package/dist/memory/paths.d.ts +68 -0
- package/dist/memory/paths.js +172 -0
- package/dist/memory/plan.d.ts +37 -0
- package/dist/memory/plan.js +184 -0
- package/dist/memory/resolve.d.ts +45 -0
- package/dist/memory/resolve.js +54 -0
- package/dist/memory/secrets.d.ts +30 -0
- package/dist/memory/secrets.js +73 -0
- package/dist/memory/service.d.ts +175 -0
- package/dist/memory/service.js +576 -0
- package/dist/memory/store.d.ts +133 -0
- package/dist/memory/store.js +694 -0
- package/dist/memory/tools.d.ts +36 -0
- package/dist/memory/tools.js +527 -0
- package/dist/memory/transfer.d.ts +53 -0
- package/dist/memory/transfer.js +93 -0
- package/dist/session/checkpoint.d.ts +33 -0
- package/dist/session/checkpoint.js +52 -0
- package/dist/session/limits.d.ts +16 -0
- package/dist/session/limits.js +16 -0
- package/dist/session/persist.d.ts +68 -0
- package/dist/session/persist.js +11 -0
- package/dist/session/startup-session.d.ts +17 -2
- package/dist/session/startup-session.js +15 -2
- package/dist/session/store.d.ts +14 -0
- package/dist/session/store.js +18 -0
- package/dist/session/validate-session.js +129 -0
- package/dist/team/runtime.d.ts +11 -0
- package/dist/team/runtime.js +6 -0
- package/dist/team/subagent.d.ts +21 -0
- package/dist/team/subagent.js +7 -0
- package/dist/tools/index.d.ts +45 -2
- package/dist/tools/index.js +53 -3
- package/package.json +3 -3
- package/skills/project-indexer/SKILL.md +275 -147
- package/skills/project-indexer/templates/artifact-hygiene-template.md +14 -0
- package/skills/project-indexer/templates/config-template.md +12 -0
- package/skills/project-indexer/templates/index-template.md +4 -0
package/dist/agent/controller.js
CHANGED
|
@@ -10,7 +10,7 @@ import { countAllImages, countHistoryImages, makeImageProjection, projectImagesF
|
|
|
10
10
|
import { buildImageInputBlock } from './image-input-prompt.js';
|
|
11
11
|
import { isImageCapabilityRefusal } from '@aragon-agent/tui/model/agent/image-refusal';
|
|
12
12
|
import { Agent, IMAGE_TOKEN_ESTIMATE, initProviders, ModelRegistry, } from '@aragon-agent/core';
|
|
13
|
-
import { clampCompactionConfig, clampFastConfig, clampRetryConfig, clampTeamConfig, clampTodoConfig, isAdapterProvider, toRetryPolicy, } from '@aragon-agent/tui/model/config/schema';
|
|
13
|
+
import { clampCompactionConfig, clampFastConfig, clampRetryConfig, clampMemoryConfig, clampTeamConfig, clampTodoConfig, isAdapterProvider, toRetryPolicy, } from '@aragon-agent/tui/model/config/schema';
|
|
14
14
|
import { resolveModelProfileState } from '@aragon-agent/tui/model/config/model-profile-resolution';
|
|
15
15
|
import { makeGetApiKey } from '../config/load.js';
|
|
16
16
|
import { updatePersistedConfig } from '../config/store.js';
|
|
@@ -30,6 +30,13 @@ 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';
|
|
38
|
+
import { MemoryService, UNAVAILABLE_VIEW } from '../memory/service.js';
|
|
39
|
+
import { createMemoryTools } from '../memory/tools.js';
|
|
33
40
|
import { buildFastBlock } from '../fast/prompt.js';
|
|
34
41
|
import { ProcSupervisor } from '../proc/supervisor.js';
|
|
35
42
|
import { buildBackgroundJobsBlock, buildBackgroundServicesBlock } from '../proc/prompt.js';
|
|
@@ -224,6 +231,28 @@ export class AgentController {
|
|
|
224
231
|
// -----------------------------------------------------------------------
|
|
225
232
|
teamMode;
|
|
226
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
|
+
// -----------------------------------------------------------------------
|
|
247
|
+
// Agent memory (agent-memory spec 8.4)
|
|
248
|
+
// -----------------------------------------------------------------------
|
|
249
|
+
// `undefined` when memory is off, the host is headless, or this is a subagent - which is
|
|
250
|
+
// what leaves the tool array, the prompt and the status bar byte-identical to the build
|
|
251
|
+
// before this feature existed (I-2 / I-17). Fixed at construction: tools cannot be
|
|
252
|
+
// unregistered, so `memory.enabled` turned off mid-session makes the block disappear and
|
|
253
|
+
// the tools refuse, but a fully clean session needs a restart.
|
|
254
|
+
memory;
|
|
255
|
+
// -----------------------------------------------------------------------
|
|
227
256
|
// Todo planning (todo-plan-execution §3.6a) — THE SAME TWO FLAGS, FOR THE
|
|
228
257
|
// SAME REASON.
|
|
229
258
|
//
|
|
@@ -524,6 +553,30 @@ export class AgentController {
|
|
|
524
553
|
rebuildPrompt: () => this.rebuildSystemPrompt(),
|
|
525
554
|
defaultCount: DEFAULT_FORCED_COUNT,
|
|
526
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();
|
|
527
580
|
this.teamRuntime = this.teamRegistered
|
|
528
581
|
? new TeamRuntime({
|
|
529
582
|
getConfig: () => this.config,
|
|
@@ -594,6 +647,26 @@ export class AgentController {
|
|
|
594
647
|
// mid-dispatch and abort it at `idleTimeoutMs`. The queue pauses the
|
|
595
648
|
// CHILD's watchdog instead, which is the one that needs it (P0-4).
|
|
596
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
|
+
: {}),
|
|
597
670
|
// SITE ONE OF TWO FOR THE CHILD GATE (headless-host-bridge 2.3.7). The
|
|
598
671
|
// second is `runtime.ts::subDeps`; declaring it here and forgetting that
|
|
599
672
|
// one type-checks and forwards nothing, and every child would then run
|
|
@@ -645,6 +718,22 @@ export class AgentController {
|
|
|
645
718
|
// With either off, no `job_*` tool, no prompt block, no mirror - which is what
|
|
646
719
|
// makes I-3 (byte-identical when off) measurable rather than asserted.
|
|
647
720
|
this.jobsRegistered = config.jobs.enabled && config.bash.background;
|
|
721
|
+
// AGENT MEMORY (agent-memory spec 8.4), ABOVE `createBuiltinTools` because its tools are
|
|
722
|
+
// passed in. THREE CONDITIONS, ALL REQUIRED: the section exists and is on (a hand-built
|
|
723
|
+
// test fixture without one is simply not asking for the feature), and the host can show a
|
|
724
|
+
// human a preview - `planInteractive` is the same signal `planTools` and `bash` use, so a
|
|
725
|
+
// headless run and a subagent never build the block or register the tools (D-20).
|
|
726
|
+
this.memory =
|
|
727
|
+
config.memory?.enabled === true && this.planInteractive
|
|
728
|
+
? new MemoryService({
|
|
729
|
+
getConfig: () => this.config,
|
|
730
|
+
getCwd: () => this.cwd,
|
|
731
|
+
resolveWindowTokens: (cfg) => this.memoryWindowTokens(cfg),
|
|
732
|
+
isBusy: () => this.isRunning() || this.isCompactionBusy(),
|
|
733
|
+
rebuildPrompt: () => this.rebuildSystemPrompt(),
|
|
734
|
+
knownSecrets: () => this.memoryKnownSecrets(),
|
|
735
|
+
})
|
|
736
|
+
: undefined;
|
|
648
737
|
this.jobMirror =
|
|
649
738
|
this.jobsRegistered && config.jobs.persistLog
|
|
650
739
|
? new JobLogMirror({
|
|
@@ -735,6 +824,21 @@ export class AgentController {
|
|
|
735
824
|
}
|
|
736
825
|
: {}),
|
|
737
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
|
+
: {}),
|
|
738
842
|
// Routed through the same watchdog pause as the plan tools. This is a
|
|
739
843
|
// pre-existing bug being fixed in passing: a `--confirm` user who took
|
|
740
844
|
// longer than `idleTimeoutMs` over `Proceed? (y/N)` had their run killed
|
|
@@ -820,6 +924,23 @@ export class AgentController {
|
|
|
820
924
|
}),
|
|
821
925
|
]
|
|
822
926
|
: [],
|
|
927
|
+
// THE THREE MEMORY TOOLS, spread conditionally for the reason `resultTool` is: with the
|
|
928
|
+
// feature off the options bag has no such key and the array is the one built before it
|
|
929
|
+
// existed. `memory_write` is left out when `agentWrites` is `off` (D-7). The approval
|
|
930
|
+
// gate is `deps.approval`, which defaults to DENY-ALL: a memory write must never be
|
|
931
|
+
// approved by the `confirm` channel, whose fallback with no human attached is `true`.
|
|
932
|
+
...(this.memory
|
|
933
|
+
? {
|
|
934
|
+
memoryTools: createMemoryTools({
|
|
935
|
+
service: this.memory,
|
|
936
|
+
approval: deps.approval ?? DENY_ALL_APPROVAL,
|
|
937
|
+
withHumanWait: (fn) => this.withHumanWait(fn),
|
|
938
|
+
isEnabled: () => this.config.memory?.enabled === true,
|
|
939
|
+
agentWrites: () => this.memory?.effectiveAgentWrites() ?? 'off',
|
|
940
|
+
includeWrite: config.memory?.agentWrites !== 'off',
|
|
941
|
+
}),
|
|
942
|
+
}
|
|
943
|
+
: {}),
|
|
823
944
|
// SPREAD, NEVER `resultTool: deps.resultTool` (the D-12 lesson, and the shape
|
|
824
945
|
// every optional dep in this bag follows). With no schema the options bag has no
|
|
825
946
|
// such key, so `createBuiltinTools` adds nothing and the tool array is the one it
|
|
@@ -1004,6 +1125,11 @@ export class AgentController {
|
|
|
1004
1125
|
toolTimeoutOverrides: {
|
|
1005
1126
|
ask_user: config.planModeHumanTimeoutMs,
|
|
1006
1127
|
submit_plan: config.planModeHumanTimeoutMs,
|
|
1128
|
+
// A memory write waits on a human reading a preview (agent-memory RV-4). Only
|
|
1129
|
+
// while the tool is registered, so every other session's table is unchanged.
|
|
1130
|
+
...(this.memory && config.memory?.agentWrites !== 'off'
|
|
1131
|
+
? { memory_write: config.planModeHumanTimeoutMs }
|
|
1132
|
+
: {}),
|
|
1007
1133
|
// THE TWO PHASES, ADDED (headless-host-bridge §2.3.4). The executor
|
|
1008
1134
|
// arms its timer BEFORE the approval wrapper runs, so a ceiling of
|
|
1009
1135
|
// `toolTimeoutMs` alone would leave the tool less than its configured
|
|
@@ -1142,6 +1268,13 @@ export class AgentController {
|
|
|
1142
1268
|
this.jobRelay?.requeueUndelivered();
|
|
1143
1269
|
}
|
|
1144
1270
|
if (event.type === 'agent_end') {
|
|
1271
|
+
// A mount changed mid-turn lands now (agent-memory D-13): the flag clears and surfaces
|
|
1272
|
+
// stop saying "applies after this turn". The prompt itself is rebuilt at the START of
|
|
1273
|
+
// the next turn, which is also where outside edits are picked up.
|
|
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();
|
|
1145
1278
|
// The same reconciliation at the other end of a run. Both ends are
|
|
1146
1279
|
// required: `turn_start` covers the next turn of the same run, and this
|
|
1147
1280
|
// covers a run that ended with a notice stranded in the queue.
|
|
@@ -1153,6 +1286,9 @@ export class AgentController {
|
|
|
1153
1286
|
});
|
|
1154
1287
|
// The switch's baseline view, taken once everything it reads exists (team-mode-toggle-keys).
|
|
1155
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();
|
|
1156
1292
|
if (this.fast) {
|
|
1157
1293
|
this.rebuildSystemPrompt();
|
|
1158
1294
|
}
|
|
@@ -1227,6 +1363,10 @@ export class AgentController {
|
|
|
1227
1363
|
cwd: this.cwd,
|
|
1228
1364
|
tools: this.tools,
|
|
1229
1365
|
skillsBlock: this.skillsEnabled ? skillsCatalog + this.skills.alwaysBlock() : '',
|
|
1366
|
+
// FROM THE `config` ARGUMENT, never `this.config` (agent-memory I-5): a model switch
|
|
1367
|
+
// pre-builds the INCOMING model's prompt, and budgets sized for the outgoing window
|
|
1368
|
+
// would overrun a smaller one. `''` when memory is off, which splices nothing.
|
|
1369
|
+
memoryBlock: this.memory?.renderBlock(config) ?? '',
|
|
1230
1370
|
// Immediately after the catalog it refers to, before the plan block whose
|
|
1231
1371
|
// first step defers to it (§4.2.4).
|
|
1232
1372
|
skillTriageBlock: triageBlock,
|
|
@@ -1302,6 +1442,18 @@ export class AgentController {
|
|
|
1302
1442
|
model: `${config.provider}/${config.model}`,
|
|
1303
1443
|
})
|
|
1304
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() ?? '',
|
|
1305
1457
|
// FROM THE FIELD, so the block survives every rebuild for the reason the field's
|
|
1306
1458
|
// own comment records. Empty everywhere but `aragon exec --result-schema`, and
|
|
1307
1459
|
// `buildSystemPrompt` splices it conditionally - so every existing prompt is
|
|
@@ -1337,6 +1489,12 @@ export class AgentController {
|
|
|
1337
1489
|
// LAST: every change to what the switch shows passes through here, so one notification
|
|
1338
1490
|
// point replaces "each call site remembers to notify" (D-7).
|
|
1339
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();
|
|
1497
|
+
this.memory?.emitIfChanged();
|
|
1340
1498
|
}
|
|
1341
1499
|
currentImageKey() {
|
|
1342
1500
|
if (!this.toolImagesEnabled)
|
|
@@ -1468,6 +1626,8 @@ export class AgentController {
|
|
|
1468
1626
|
// survived the cancellation check, so neither a superseded `prompt()` nor a live turn
|
|
1469
1627
|
// can apply it early (team-mode-toggle-keys RV-P1-3).
|
|
1470
1628
|
this.teamMode.applyPending();
|
|
1629
|
+
// The same net for memory: `agent_end` may never have reached us (agent-memory RV-3).
|
|
1630
|
+
this.memory?.applyPending();
|
|
1471
1631
|
return await this.startPrompt(text, options, request);
|
|
1472
1632
|
}
|
|
1473
1633
|
catch (err) {
|
|
@@ -1563,6 +1723,11 @@ export class AgentController {
|
|
|
1563
1723
|
// one turn late. This is also why steer does not rebuild: `continue()` runs
|
|
1564
1724
|
// while the loop already holds its snapshot, so the cost would be an idle
|
|
1565
1725
|
// compaction aborted for a prompt nothing has read yet (§4.2.5).
|
|
1726
|
+
//
|
|
1727
|
+
// `memory.sync()` FIRST (agent-memory RV-3): the one place an edit made by another
|
|
1728
|
+
// process, another window or a text editor reaches the model, because the rebuild
|
|
1729
|
+
// below is the only thing that reads the directory's contents into the prompt.
|
|
1730
|
+
this.memory?.sync();
|
|
1566
1731
|
this.rebuildSystemPrompt();
|
|
1567
1732
|
}
|
|
1568
1733
|
this.fast?.setGoal(text);
|
|
@@ -2238,6 +2403,173 @@ export class AgentController {
|
|
|
2238
2403
|
getTeamConfig() {
|
|
2239
2404
|
return this.config.team;
|
|
2240
2405
|
}
|
|
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
|
+
// -----------------------------------------------------------------------
|
|
2519
|
+
// Agent memory - public surface (agent-memory spec 8.4)
|
|
2520
|
+
// -----------------------------------------------------------------------
|
|
2521
|
+
/** The memory service, or `undefined` when memory is off / headless / a subagent. */
|
|
2522
|
+
getMemoryService() {
|
|
2523
|
+
return this.memory;
|
|
2524
|
+
}
|
|
2525
|
+
/**
|
|
2526
|
+
* Adopt the memory state a saved session carried (mounts, switches). Tolerant: anything
|
|
2527
|
+
* malformed is dropped by the service. The prompt is rebuilt so the restored mounts are in
|
|
2528
|
+
* effect for the first turn.
|
|
2529
|
+
*/
|
|
2530
|
+
restoreMemory(state) {
|
|
2531
|
+
if (!this.memory)
|
|
2532
|
+
return;
|
|
2533
|
+
this.memory.restoreState(state);
|
|
2534
|
+
this.rebuildSystemPrompt();
|
|
2535
|
+
}
|
|
2536
|
+
/** The whole session view; `available: false` when there is no service. */
|
|
2537
|
+
getMemoryView() {
|
|
2538
|
+
return this.memory?.getView() ?? UNAVAILABLE_VIEW;
|
|
2539
|
+
}
|
|
2540
|
+
/** Subscribe to view changes; the returned function unsubscribes. */
|
|
2541
|
+
subscribeMemory(listener) {
|
|
2542
|
+
return this.memory?.subscribe(listener) ?? (() => { });
|
|
2543
|
+
}
|
|
2544
|
+
/**
|
|
2545
|
+
* Adopt a new memory config for this session (Settings > Memory), clamped here as well as
|
|
2546
|
+
* on the persist path. Like `setTeamConfig` this does NOT persist: `persistConfig` writes
|
|
2547
|
+
* the file, this updates the runtime.
|
|
2548
|
+
*/
|
|
2549
|
+
setMemoryConfig(patch) {
|
|
2550
|
+
const memory = clampMemoryConfig({ ...this.config.memory, ...patch });
|
|
2551
|
+
this.advanceSettingsRevision();
|
|
2552
|
+
this.config = { ...this.config, memory };
|
|
2553
|
+
this.memory?.updateConfig(memory);
|
|
2554
|
+
this.rebuildSystemPrompt();
|
|
2555
|
+
return memory;
|
|
2556
|
+
}
|
|
2557
|
+
/** The window of the model `cfg` selects, or `undefined` when only a fallback is known. */
|
|
2558
|
+
memoryWindowTokens(cfg) {
|
|
2559
|
+
if (typeof cfg.contextWindow === 'number' && cfg.contextWindow > 0)
|
|
2560
|
+
return cfg.contextWindow;
|
|
2561
|
+
const info = this.getModelInfoFor({
|
|
2562
|
+
providerId: cfg.provider,
|
|
2563
|
+
modelId: cfg.model,
|
|
2564
|
+
...(cfg.baseUrl ? { baseUrl: cfg.baseUrl } : {}),
|
|
2565
|
+
});
|
|
2566
|
+
return info.contextWindowSource === 'fallback' ? undefined : info.contextWindow;
|
|
2567
|
+
}
|
|
2568
|
+
/** Configured API keys, so a note that contains one is refused by value. */
|
|
2569
|
+
memoryKnownSecrets() {
|
|
2570
|
+
const key = this.resolveKey(this.config.provider);
|
|
2571
|
+
return key ? [key] : [];
|
|
2572
|
+
}
|
|
2241
2573
|
/**
|
|
2242
2574
|
* Adopt a new team config for this session and re-render the prompt (the block
|
|
2243
2575
|
* quotes the numbers). Clamped here as well as on the persist path, so a bad
|
|
@@ -2562,6 +2894,11 @@ export class AgentController {
|
|
|
2562
2894
|
this.modelRegistry.clearCache();
|
|
2563
2895
|
}
|
|
2564
2896
|
this.fast?.onConfigChanged(false, snapshot.config.fast.enabled);
|
|
2897
|
+
// The memory service keeps its own copy of the section (for `effectiveAgentWrites` and the
|
|
2898
|
+
// view); a Settings > Memory save must reach it, or the page would say "auto" while the tool
|
|
2899
|
+
// still asked (agent-memory 8.4).
|
|
2900
|
+
if (snapshot.config.memory)
|
|
2901
|
+
this.memory?.updateConfig(snapshot.config.memory);
|
|
2565
2902
|
this.compaction?.onConfigChanged(snapshot.config.compaction.enabled);
|
|
2566
2903
|
if (connectionChanged) {
|
|
2567
2904
|
this.requestVersion += 1;
|
|
@@ -2662,6 +2999,9 @@ export class AgentController {
|
|
|
2662
2999
|
// directory and the new skill set (I-S2 / AC-17).
|
|
2663
3000
|
if (this.skillsEnabled)
|
|
2664
3001
|
this.skills.discover();
|
|
3002
|
+
// The PROJECT scope moved with the directory: recompute which notes are visible before
|
|
3003
|
+
// the rebuild reads them (agent-memory 5.3).
|
|
3004
|
+
this.memory?.setCwd(cwd);
|
|
2665
3005
|
this.rebuildSystemPrompt();
|
|
2666
3006
|
this.onSkillsChanged?.();
|
|
2667
3007
|
}
|
|
@@ -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[];
|