@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.
- package/CHANGELOG.md +26 -0
- package/README.md +4111 -4042
- package/dist/agent/controller.d.ts +72 -0
- package/dist/agent/controller.js +212 -0
- 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 +13 -0
- package/dist/agent/system-prompt.js +7 -0
- package/dist/app/App.d.ts +10 -1
- package/dist/app/App.js +133 -22
- package/dist/app/use-redteam-mode.d.ts +56 -0
- package/dist/app/use-redteam-mode.js +121 -0
- package/dist/cli.js +53 -3
- package/dist/commands/builtins.js +39 -1
- package/dist/commands/catalog.js +4 -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/config/env.d.ts +2 -1
- package/dist/config/env.js +12 -1
- package/dist/config/load.d.ts +12 -0
- package/dist/config/load.js +10 -1
- package/dist/config/redteam-launch.d.ts +77 -0
- package/dist/config/redteam-launch.js +58 -0
- package/dist/config/store.js +11 -1
- package/dist/config/ui-state.d.ts +44 -0
- package/dist/config/ui-state.js +38 -0
- package/dist/host/controller-factory.d.ts +8 -0
- package/dist/host/controller-factory.js +7 -0
- package/dist/session/checkpoint.d.ts +15 -0
- package/dist/session/checkpoint.js +18 -0
- package/dist/session/persist.d.ts +21 -0
- package/dist/session/persist.js +10 -0
- package/dist/session/startup-session.d.ts +11 -2
- package/dist/session/startup-session.js +12 -2
- package/dist/session/validate-session.js +31 -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 +24 -0
- package/dist/tools/index.js +20 -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
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RedTeamWiring - the stateful half of red team / security mode (4.4).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY (`agent/` is inside the glyph scanner's scope).
|
|
5
|
+
*
|
|
6
|
+
* The controller is far over the repo's size limit, so the mode's state and rules live here and
|
|
7
|
+
* the controller only forwards, the same shape as `TeamModeWiring` and `GovernanceWiring`. The
|
|
8
|
+
* DECISIONS are not here either: `planRedTeam` (tui/model/redteam/redteam-mode.ts) is a pure
|
|
9
|
+
* function, and `redTeamPaused` is the ONE definition of "a stricter posture holds this back"
|
|
10
|
+
* (I-10). This class holds the four things a pure function cannot: `armed`, `scope`, `pending`
|
|
11
|
+
* and the subscription that tells a surface to repaint.
|
|
12
|
+
*
|
|
13
|
+
* THE PERMISSION SURFACE IS ONE METHOD (I-5): `bypassesConfirmation()`. It is read by exactly
|
|
14
|
+
* two call sites - `tools/index.ts`'s confirm wrapper (the lead) and `team/subagent.ts` (a
|
|
15
|
+
* child, through a predicate the controller passes down). Nothing else may consult it, and a
|
|
16
|
+
* later feature that makes plan mode or governance read it would be turning a liability mode
|
|
17
|
+
* into a back door (R-4).
|
|
18
|
+
*
|
|
19
|
+
* THE WAIVER IS READ, NEVER INFERRED (I-3 / I-4): `waiverVersion()` comes from `state.json`
|
|
20
|
+
* through an injected reader, and nothing in `config.json` or the environment can express
|
|
21
|
+
* "accepted".
|
|
22
|
+
*/
|
|
23
|
+
import type { CliConfig } from '@aragon-agent/tui/model/config/schema';
|
|
24
|
+
import { type RedTeamOutcome, type RedTeamPosture, type RedTeamRequest } from '@aragon-agent/tui/model/redteam/redteam-mode';
|
|
25
|
+
import type { RedTeamLogEvent, RedTeamView } from '@aragon-agent/tui/model/redteam/types';
|
|
26
|
+
/** What a `--no-redteam` / `ARAGON_REDTEAM=0` / `redteam.enabled=false` session looks like. */
|
|
27
|
+
export declare const UNAVAILABLE_RED_TEAM_VIEW: RedTeamView;
|
|
28
|
+
export interface RedTeamWiringDeps {
|
|
29
|
+
/** Live config: the four `redteam.*` keys are read through it on every question. */
|
|
30
|
+
getConfig(): CliConfig;
|
|
31
|
+
/**
|
|
32
|
+
* The chain exists for this launch: `--no-redteam` / `ARAGON_REDTEAM=0` are already folded
|
|
33
|
+
* into `redteam.enabled` by the config layer, so the controller passes that one predicate
|
|
34
|
+
* rather than three flags (the `--no-redteam` table in 4.8).
|
|
35
|
+
*/
|
|
36
|
+
isAvailable(): boolean;
|
|
37
|
+
/** The accepted waiver version from `state.json` (0 = never). */
|
|
38
|
+
readWaiverVersion(): number;
|
|
39
|
+
/** Write an acceptance and return what landed on disk. */
|
|
40
|
+
saveWaiverVersion(version: number): number;
|
|
41
|
+
/** The live posture: `paused` is derived from it by `redTeamPaused` and nowhere else. */
|
|
42
|
+
getPosture(): RedTeamPosture;
|
|
43
|
+
/** A turn or a compaction is in flight (arming is deferred, disarming is not - D-12). */
|
|
44
|
+
isRunning(): boolean;
|
|
45
|
+
/** Re-render the system prompt (the controller's single rebuild funnel). */
|
|
46
|
+
rebuildPrompt(): void;
|
|
47
|
+
log(event: RedTeamLogEvent): void;
|
|
48
|
+
/** The clause-set version this build asks for; injectable for the version-scope tests. */
|
|
49
|
+
disclaimerVersion?: number;
|
|
50
|
+
}
|
|
51
|
+
export type ScopeSetResult = {
|
|
52
|
+
ok: true;
|
|
53
|
+
scope: string | null;
|
|
54
|
+
} | {
|
|
55
|
+
ok: false;
|
|
56
|
+
reason: 'too-long' | 'multi-line';
|
|
57
|
+
};
|
|
58
|
+
export declare class RedTeamWiring {
|
|
59
|
+
private readonly deps;
|
|
60
|
+
private armed;
|
|
61
|
+
private scope;
|
|
62
|
+
private pending;
|
|
63
|
+
private view;
|
|
64
|
+
private lastEmitted;
|
|
65
|
+
private readonly listeners;
|
|
66
|
+
constructor(deps: RedTeamWiringDeps);
|
|
67
|
+
/** The disclaimer version this build's clause set carries. */
|
|
68
|
+
get disclaimerVersion(): number;
|
|
69
|
+
/** Does this session have the chain at all? Config, flag and env all fold in here. */
|
|
70
|
+
available(): boolean;
|
|
71
|
+
/** The cached view: recomputed when something actually changes, never during render. */
|
|
72
|
+
getView(): RedTeamView;
|
|
73
|
+
/** Take the baseline view once the controller is fully built. */
|
|
74
|
+
prime(): void;
|
|
75
|
+
/**
|
|
76
|
+
* Plan and carry out one request. The outcome tells the caller what to say; a
|
|
77
|
+
* `refusal: 'disclaimer'` is also the caller's cue to open the waiver overlay (4.3).
|
|
78
|
+
*/
|
|
79
|
+
request(req: RedTeamRequest): RedTeamOutcome;
|
|
80
|
+
/** Land a deferred change at `agent_end`. `null` = nothing was pending or it was a no-op. */
|
|
81
|
+
applyPending(): RedTeamOutcome | null;
|
|
82
|
+
/** A posture change can only move `paused`; the prompt rebuild is the caller's job. */
|
|
83
|
+
onPostureChange(): void;
|
|
84
|
+
/** The engagement scope, or `null`. Never persisted, never logged (D-9). */
|
|
85
|
+
getScope(): string | null;
|
|
86
|
+
/**
|
|
87
|
+
* Set or clear the scope. Refuses rather than truncating (4.6 step 4): a user who typed 300
|
|
88
|
+
* cells must not be told they set 200.
|
|
89
|
+
*/
|
|
90
|
+
setScope(line: string): ScopeSetResult;
|
|
91
|
+
/**
|
|
92
|
+
* THE ONE PREDICATE THE CONFIRM GATE READS (I-5).
|
|
93
|
+
*
|
|
94
|
+
* Effective AND configured: `paused` and `bypassConfirm: false` both read false here, so an
|
|
95
|
+
* operator can have "red team prompt plus ordinary confirmations" (4.5 point 4).
|
|
96
|
+
*/
|
|
97
|
+
bypassesConfirmation(): boolean;
|
|
98
|
+
/** The lead's `<redteam_mode>` block, or `''` when the mode is off (I-1 byte-identity). */
|
|
99
|
+
block(): string;
|
|
100
|
+
/** The subagent's trimmed block. Same arming condition, so a child can never out-run the lead. */
|
|
101
|
+
childBlock(): string;
|
|
102
|
+
/**
|
|
103
|
+
* Accept the waiver and REPORT WHAT WAS WRITTEN, read back from disk.
|
|
104
|
+
*
|
|
105
|
+
* `askEveryArm` re-askings go through this same call, which is what makes a re-acceptance
|
|
106
|
+
* idempotent: the recorded version does not move (RV-21).
|
|
107
|
+
*/
|
|
108
|
+
acceptWaiver(): number;
|
|
109
|
+
/** The waiver is current for this build (the fact `/redteam status` reports). */
|
|
110
|
+
waiverAccepted(): boolean;
|
|
111
|
+
/** Whether the state machine should ask again before arming. */
|
|
112
|
+
private needsWaiver;
|
|
113
|
+
/**
|
|
114
|
+
* Adopt the state a saved session carried (4.10 / I-12).
|
|
115
|
+
*
|
|
116
|
+
* TWO OUTCOMES AND BOTH ARE REPORTED: a current waiver restores `armed` and reprints the
|
|
117
|
+
* banner (the user has to know what posture they are in), and a stale waiver leaves the mode
|
|
118
|
+
* OFF with a notice that says why and how to fix it. The scope is never restored - it belongs
|
|
119
|
+
* to one engagement (D-9).
|
|
120
|
+
*/
|
|
121
|
+
restoreFromSession(saved: {
|
|
122
|
+
armed?: boolean;
|
|
123
|
+
waiverVersion?: number;
|
|
124
|
+
}): {
|
|
125
|
+
armed: boolean;
|
|
126
|
+
notice: string | null;
|
|
127
|
+
};
|
|
128
|
+
/** Arm directly, bypassing the state machine: the `--redteam` launch path, already checked. */
|
|
129
|
+
armForLaunch(): void;
|
|
130
|
+
/** The armed/disarmed split for the session file (4.10). */
|
|
131
|
+
isArmed(): boolean;
|
|
132
|
+
subscribe(listener: () => void): () => void;
|
|
133
|
+
/** Recompute the view and tell subscribers only when it really changed. */
|
|
134
|
+
emitIfChanged(): void;
|
|
135
|
+
/** The scope's LENGTH for a log line, or `null` when none is set. Never the text (D-9). */
|
|
136
|
+
private scopeCells;
|
|
137
|
+
private config;
|
|
138
|
+
private state;
|
|
139
|
+
private execute;
|
|
140
|
+
private computeView;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* The waiver READER, behind a guard that has a real job.
|
|
144
|
+
*
|
|
145
|
+
* `state.json` is the only source of an acceptance (I-3) and `getRedTeamWaiverVersion` is total.
|
|
146
|
+
* The case this defends is the other one: several App-level tests replace `config/ui-state.js`
|
|
147
|
+
* with a PARTIAL mock, and a named import the mock does not provide is `undefined` at call time
|
|
148
|
+
* - which would crash the controller CONSTRUCTOR for a feature those tests are not about.
|
|
149
|
+
*
|
|
150
|
+
* An unreadable version reads as `0` ("never accepted"), which is the safe direction: it can
|
|
151
|
+
* never arm a session, only fail to.
|
|
152
|
+
*/
|
|
153
|
+
export declare function readWaiverVersionPort(read: () => number): number;
|
|
154
|
+
/** The same guard on the write side; it returns what the store reports, or 0. */
|
|
155
|
+
export declare function writeWaiverVersionPort(write: (version: number) => number, version: number): number;
|
|
156
|
+
/** The transcript banner rows for an armed session (4.6). */
|
|
157
|
+
export declare function bannerConfirmations(config: {
|
|
158
|
+
bypassConfirm?: boolean;
|
|
159
|
+
}, confirmTools: boolean): 'off' | 'on' | 'none';
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RedTeamWiring - the stateful half of red team / security mode (4.4).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY (`agent/` is inside the glyph scanner's scope).
|
|
5
|
+
*
|
|
6
|
+
* The controller is far over the repo's size limit, so the mode's state and rules live here and
|
|
7
|
+
* the controller only forwards, the same shape as `TeamModeWiring` and `GovernanceWiring`. The
|
|
8
|
+
* DECISIONS are not here either: `planRedTeam` (tui/model/redteam/redteam-mode.ts) is a pure
|
|
9
|
+
* function, and `redTeamPaused` is the ONE definition of "a stricter posture holds this back"
|
|
10
|
+
* (I-10). This class holds the four things a pure function cannot: `armed`, `scope`, `pending`
|
|
11
|
+
* and the subscription that tells a surface to repaint.
|
|
12
|
+
*
|
|
13
|
+
* THE PERMISSION SURFACE IS ONE METHOD (I-5): `bypassesConfirmation()`. It is read by exactly
|
|
14
|
+
* two call sites - `tools/index.ts`'s confirm wrapper (the lead) and `team/subagent.ts` (a
|
|
15
|
+
* child, through a predicate the controller passes down). Nothing else may consult it, and a
|
|
16
|
+
* later feature that makes plan mode or governance read it would be turning a liability mode
|
|
17
|
+
* into a back door (R-4).
|
|
18
|
+
*
|
|
19
|
+
* THE WAIVER IS READ, NEVER INFERRED (I-3 / I-4): `waiverVersion()` comes from `state.json`
|
|
20
|
+
* through an injected reader, and nothing in `config.json` or the environment can express
|
|
21
|
+
* "accepted".
|
|
22
|
+
*/
|
|
23
|
+
import { REDTEAM_DISCLAIMER_VERSION } from '@aragon-agent/tui/model/redteam/limits';
|
|
24
|
+
import { applyPendingRedTeam, planRedTeam, redTeamPaused, } from '@aragon-agent/tui/model/redteam/redteam-mode';
|
|
25
|
+
import { normalizeScope, scopeCells } from '@aragon-agent/tui/model/redteam/scope';
|
|
26
|
+
import { REDTEAM_NOTICE } from '@aragon-agent/tui/ui/redteam-copy';
|
|
27
|
+
import { buildRedTeamBlock } from './redteam-prompt.js';
|
|
28
|
+
/** What a `--no-redteam` / `ARAGON_REDTEAM=0` / `redteam.enabled=false` session looks like. */
|
|
29
|
+
export const UNAVAILABLE_RED_TEAM_VIEW = Object.freeze({
|
|
30
|
+
available: false,
|
|
31
|
+
armed: false,
|
|
32
|
+
paused: false,
|
|
33
|
+
effective: 'off',
|
|
34
|
+
scope: null,
|
|
35
|
+
bypassesConfirm: false,
|
|
36
|
+
waiverAccepted: false,
|
|
37
|
+
pending: null,
|
|
38
|
+
});
|
|
39
|
+
export class RedTeamWiring {
|
|
40
|
+
deps;
|
|
41
|
+
armed = false;
|
|
42
|
+
scope = null;
|
|
43
|
+
pending = null;
|
|
44
|
+
view = null;
|
|
45
|
+
lastEmitted = null;
|
|
46
|
+
listeners = new Set();
|
|
47
|
+
constructor(deps) {
|
|
48
|
+
this.deps = deps;
|
|
49
|
+
}
|
|
50
|
+
/** The disclaimer version this build's clause set carries. */
|
|
51
|
+
get disclaimerVersion() {
|
|
52
|
+
return this.deps.disclaimerVersion ?? REDTEAM_DISCLAIMER_VERSION;
|
|
53
|
+
}
|
|
54
|
+
/** Does this session have the chain at all? Config, flag and env all fold in here. */
|
|
55
|
+
available() {
|
|
56
|
+
if (!this.deps.isAvailable())
|
|
57
|
+
return false;
|
|
58
|
+
return this.config().enabled !== false;
|
|
59
|
+
}
|
|
60
|
+
/** The cached view: recomputed when something actually changes, never during render. */
|
|
61
|
+
getView() {
|
|
62
|
+
if (this.view === null)
|
|
63
|
+
this.prime();
|
|
64
|
+
return this.view;
|
|
65
|
+
}
|
|
66
|
+
/** Take the baseline view once the controller is fully built. */
|
|
67
|
+
prime() {
|
|
68
|
+
this.view = this.computeView();
|
|
69
|
+
this.lastEmitted = JSON.stringify(this.view);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Plan and carry out one request. The outcome tells the caller what to say; a
|
|
73
|
+
* `refusal: 'disclaimer'` is also the caller's cue to open the waiver overlay (4.3).
|
|
74
|
+
*/
|
|
75
|
+
request(req) {
|
|
76
|
+
const plan = planRedTeam(this.state(), req);
|
|
77
|
+
this.execute(plan.action);
|
|
78
|
+
this.emitIfChanged();
|
|
79
|
+
return plan.outcome;
|
|
80
|
+
}
|
|
81
|
+
/** Land a deferred change at `agent_end`. `null` = nothing was pending or it was a no-op. */
|
|
82
|
+
applyPending() {
|
|
83
|
+
const plan = applyPendingRedTeam(this.state());
|
|
84
|
+
if (!plan)
|
|
85
|
+
return null;
|
|
86
|
+
this.execute(plan.action);
|
|
87
|
+
this.emitIfChanged();
|
|
88
|
+
return plan.outcome;
|
|
89
|
+
}
|
|
90
|
+
/** A posture change can only move `paused`; the prompt rebuild is the caller's job. */
|
|
91
|
+
onPostureChange() {
|
|
92
|
+
this.emitIfChanged();
|
|
93
|
+
}
|
|
94
|
+
/** The engagement scope, or `null`. Never persisted, never logged (D-9). */
|
|
95
|
+
getScope() {
|
|
96
|
+
return this.scope;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Set or clear the scope. Refuses rather than truncating (4.6 step 4): a user who typed 300
|
|
100
|
+
* cells must not be told they set 200.
|
|
101
|
+
*/
|
|
102
|
+
setScope(line) {
|
|
103
|
+
const normalized = normalizeScope(line);
|
|
104
|
+
if (!normalized.ok)
|
|
105
|
+
return { ok: false, reason: normalized.reason };
|
|
106
|
+
this.scope = normalized.scope.length > 0 ? normalized.scope : null;
|
|
107
|
+
// THE LENGTH, NEVER THE TEXT (R-12): a target name can itself be sensitive.
|
|
108
|
+
this.deps.log({ type: 'redteam.scope_set', cells: scopeCells(this.scope ?? '') });
|
|
109
|
+
this.deps.rebuildPrompt();
|
|
110
|
+
this.emitIfChanged();
|
|
111
|
+
return { ok: true, scope: this.scope };
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* THE ONE PREDICATE THE CONFIRM GATE READS (I-5).
|
|
115
|
+
*
|
|
116
|
+
* Effective AND configured: `paused` and `bypassConfirm: false` both read false here, so an
|
|
117
|
+
* operator can have "red team prompt plus ordinary confirmations" (4.5 point 4).
|
|
118
|
+
*/
|
|
119
|
+
bypassesConfirmation() {
|
|
120
|
+
if (!this.available() || !this.armed)
|
|
121
|
+
return false;
|
|
122
|
+
if (redTeamPaused(this.deps.getPosture()))
|
|
123
|
+
return false;
|
|
124
|
+
return this.config().bypassConfirm !== false;
|
|
125
|
+
}
|
|
126
|
+
/** The lead's `<redteam_mode>` block, or `''` when the mode is off (I-1 byte-identity). */
|
|
127
|
+
block() {
|
|
128
|
+
if (!this.available() || !this.armed)
|
|
129
|
+
return '';
|
|
130
|
+
return buildRedTeamBlock({
|
|
131
|
+
scope: this.scope,
|
|
132
|
+
paused: redTeamPaused(this.deps.getPosture()),
|
|
133
|
+
postureLabel: postureLabel(this.deps.getPosture()),
|
|
134
|
+
role: 'lead',
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/** The subagent's trimmed block. Same arming condition, so a child can never out-run the lead. */
|
|
138
|
+
childBlock() {
|
|
139
|
+
if (!this.available() || !this.armed)
|
|
140
|
+
return '';
|
|
141
|
+
return buildRedTeamBlock({
|
|
142
|
+
scope: this.scope,
|
|
143
|
+
paused: redTeamPaused(this.deps.getPosture()),
|
|
144
|
+
postureLabel: postureLabel(this.deps.getPosture()),
|
|
145
|
+
role: 'child',
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Accept the waiver and REPORT WHAT WAS WRITTEN, read back from disk.
|
|
150
|
+
*
|
|
151
|
+
* `askEveryArm` re-askings go through this same call, which is what makes a re-acceptance
|
|
152
|
+
* idempotent: the recorded version does not move (RV-21).
|
|
153
|
+
*/
|
|
154
|
+
acceptWaiver() {
|
|
155
|
+
const landed = this.deps.saveWaiverVersion(this.disclaimerVersion);
|
|
156
|
+
this.deps.log({ type: 'redteam.waiver_accepted', version: landed });
|
|
157
|
+
this.emitIfChanged();
|
|
158
|
+
return landed;
|
|
159
|
+
}
|
|
160
|
+
/** The waiver is current for this build (the fact `/redteam status` reports). */
|
|
161
|
+
waiverAccepted() {
|
|
162
|
+
return this.deps.readWaiverVersion() >= this.disclaimerVersion;
|
|
163
|
+
}
|
|
164
|
+
/** Whether the state machine should ask again before arming. */
|
|
165
|
+
needsWaiver() {
|
|
166
|
+
if (this.config().askEveryArm === true)
|
|
167
|
+
return true;
|
|
168
|
+
return !this.waiverAccepted();
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Adopt the state a saved session carried (4.10 / I-12).
|
|
172
|
+
*
|
|
173
|
+
* TWO OUTCOMES AND BOTH ARE REPORTED: a current waiver restores `armed` and reprints the
|
|
174
|
+
* banner (the user has to know what posture they are in), and a stale waiver leaves the mode
|
|
175
|
+
* OFF with a notice that says why and how to fix it. The scope is never restored - it belongs
|
|
176
|
+
* to one engagement (D-9).
|
|
177
|
+
*/
|
|
178
|
+
restoreFromSession(saved) {
|
|
179
|
+
const wanted = saved.armed === true;
|
|
180
|
+
const fileVersion = typeof saved.waiverVersion === 'number' ? saved.waiverVersion : 0;
|
|
181
|
+
if (!wanted || !this.available())
|
|
182
|
+
return { armed: false, notice: null };
|
|
183
|
+
// STALE MEANS THE FILE IS OLDER THAN THE CLAUSE SET THIS BUILD ASKS FOR (RV-20 / I-12).
|
|
184
|
+
// A file armed under version 1 must not silently re-arm under version 2: the user signed
|
|
185
|
+
// six clauses they can no longer see, so the mode comes back OFF and says why.
|
|
186
|
+
if (fileVersion < this.disclaimerVersion) {
|
|
187
|
+
this.deps.log({ type: 'redteam.resume_restored', armed: false, reason: 'stale_waiver' });
|
|
188
|
+
return { armed: false, notice: REDTEAM_NOTICE.resumeStaleWaiver };
|
|
189
|
+
}
|
|
190
|
+
// AND THE MACHINE HAS TO AGREE (I-3). A session file is a document the user can copy
|
|
191
|
+
// between machines; the acceptance it names is a MACHINE fact (`state.json`), and without a
|
|
192
|
+
// current record here there is no waiver to restore - only a file that says there was one.
|
|
193
|
+
if (!this.waiverAccepted()) {
|
|
194
|
+
this.deps.log({ type: 'redteam.resume_restored', armed: false, reason: 'no_record' });
|
|
195
|
+
return { armed: false, notice: REDTEAM_NOTICE.resumeNoRecord };
|
|
196
|
+
}
|
|
197
|
+
this.armed = true;
|
|
198
|
+
this.pending = null;
|
|
199
|
+
this.deps.log({ type: 'redteam.resume_restored', armed: true, reason: 'ok' });
|
|
200
|
+
this.deps.rebuildPrompt();
|
|
201
|
+
this.emitIfChanged();
|
|
202
|
+
return { armed: true, notice: REDTEAM_NOTICE.resumeRestored };
|
|
203
|
+
}
|
|
204
|
+
/** Arm directly, bypassing the state machine: the `--redteam` launch path, already checked. */
|
|
205
|
+
armForLaunch() {
|
|
206
|
+
if (!this.available())
|
|
207
|
+
return;
|
|
208
|
+
this.armed = true;
|
|
209
|
+
this.pending = null;
|
|
210
|
+
this.deps.log({ type: 'redteam.arm', scopeCells: this.scopeCells(), deferred: false });
|
|
211
|
+
this.deps.rebuildPrompt();
|
|
212
|
+
this.emitIfChanged();
|
|
213
|
+
}
|
|
214
|
+
/** The armed/disarmed split for the session file (4.10). */
|
|
215
|
+
isArmed() {
|
|
216
|
+
return this.armed;
|
|
217
|
+
}
|
|
218
|
+
subscribe(listener) {
|
|
219
|
+
this.listeners.add(listener);
|
|
220
|
+
return () => { this.listeners.delete(listener); };
|
|
221
|
+
}
|
|
222
|
+
/** Recompute the view and tell subscribers only when it really changed. */
|
|
223
|
+
emitIfChanged() {
|
|
224
|
+
this.view = this.computeView();
|
|
225
|
+
const key = JSON.stringify(this.view);
|
|
226
|
+
if (key === this.lastEmitted)
|
|
227
|
+
return;
|
|
228
|
+
this.lastEmitted = key;
|
|
229
|
+
for (const listener of [...this.listeners]) {
|
|
230
|
+
try {
|
|
231
|
+
listener();
|
|
232
|
+
}
|
|
233
|
+
catch { /* a repaint hook must not break a mode change */ }
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/** The scope's LENGTH for a log line, or `null` when none is set. Never the text (D-9). */
|
|
237
|
+
scopeCells() {
|
|
238
|
+
return this.scope === null ? null : scopeCells(this.scope);
|
|
239
|
+
}
|
|
240
|
+
config() {
|
|
241
|
+
return this.deps.getConfig().redteam ?? DEFAULT_RED_TEAM_CONFIG;
|
|
242
|
+
}
|
|
243
|
+
state() {
|
|
244
|
+
return {
|
|
245
|
+
available: this.available(),
|
|
246
|
+
armed: this.armed,
|
|
247
|
+
waiverAccepted: !this.needsWaiver(),
|
|
248
|
+
running: this.deps.isRunning(),
|
|
249
|
+
posture: this.deps.getPosture(),
|
|
250
|
+
pending: this.pending,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
execute(action) {
|
|
254
|
+
switch (action.type) {
|
|
255
|
+
case 'none':
|
|
256
|
+
return;
|
|
257
|
+
case 'arm':
|
|
258
|
+
this.armed = true;
|
|
259
|
+
this.pending = null;
|
|
260
|
+
this.deps.log({ type: 'redteam.arm', scopeCells: this.scopeCells(), deferred: false });
|
|
261
|
+
this.deps.rebuildPrompt();
|
|
262
|
+
return;
|
|
263
|
+
case 'disarm':
|
|
264
|
+
if (!this.armed && this.pending === null)
|
|
265
|
+
return;
|
|
266
|
+
this.armed = false;
|
|
267
|
+
this.pending = null;
|
|
268
|
+
this.deps.log({ type: 'redteam.disarm' });
|
|
269
|
+
this.deps.rebuildPrompt();
|
|
270
|
+
return;
|
|
271
|
+
case 'defer':
|
|
272
|
+
// NO prompt rebuild: this turn's tool array and system prompt are already assembled,
|
|
273
|
+
// and rewriting them mid-turn is exactly what deferring avoids (D-12).
|
|
274
|
+
this.pending = action.target;
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
computeView() {
|
|
279
|
+
const available = this.available();
|
|
280
|
+
const armed = available && this.armed;
|
|
281
|
+
const paused = armed && redTeamPaused(this.deps.getPosture());
|
|
282
|
+
return {
|
|
283
|
+
available,
|
|
284
|
+
armed,
|
|
285
|
+
paused,
|
|
286
|
+
effective: paused ? 'paused' : armed ? 'armed' : 'off',
|
|
287
|
+
scope: this.scope,
|
|
288
|
+
bypassesConfirm: armed && !paused && this.config().bypassConfirm !== false,
|
|
289
|
+
waiverAccepted: this.waiverAccepted(),
|
|
290
|
+
pending: this.pending,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* The waiver READER, behind a guard that has a real job.
|
|
296
|
+
*
|
|
297
|
+
* `state.json` is the only source of an acceptance (I-3) and `getRedTeamWaiverVersion` is total.
|
|
298
|
+
* The case this defends is the other one: several App-level tests replace `config/ui-state.js`
|
|
299
|
+
* with a PARTIAL mock, and a named import the mock does not provide is `undefined` at call time
|
|
300
|
+
* - which would crash the controller CONSTRUCTOR for a feature those tests are not about.
|
|
301
|
+
*
|
|
302
|
+
* An unreadable version reads as `0` ("never accepted"), which is the safe direction: it can
|
|
303
|
+
* never arm a session, only fail to.
|
|
304
|
+
*/
|
|
305
|
+
export function readWaiverVersionPort(read) {
|
|
306
|
+
if (typeof read !== 'function')
|
|
307
|
+
return 0;
|
|
308
|
+
try {
|
|
309
|
+
const version = read();
|
|
310
|
+
return Number.isFinite(version) && version > 0 ? Math.floor(version) : 0;
|
|
311
|
+
}
|
|
312
|
+
catch {
|
|
313
|
+
return 0;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/** The same guard on the write side; it returns what the store reports, or 0. */
|
|
317
|
+
export function writeWaiverVersionPort(write, version) {
|
|
318
|
+
if (typeof write !== 'function')
|
|
319
|
+
return 0;
|
|
320
|
+
try {
|
|
321
|
+
const landed = write(version);
|
|
322
|
+
return Number.isFinite(landed) ? Math.floor(landed) : 0;
|
|
323
|
+
}
|
|
324
|
+
catch {
|
|
325
|
+
return 0;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
/** The section a hand-built `CliConfig` fixture may omit; identical to the schema default. */
|
|
329
|
+
const DEFAULT_RED_TEAM_CONFIG = {
|
|
330
|
+
enabled: true,
|
|
331
|
+
bypassConfirm: true,
|
|
332
|
+
banner: true,
|
|
333
|
+
askEveryArm: false,
|
|
334
|
+
};
|
|
335
|
+
/** The posture's NAME, for the prompt note. It never decides anything (I-10). */
|
|
336
|
+
function postureLabel(posture) {
|
|
337
|
+
const parts = [];
|
|
338
|
+
if (posture.mode === 'plan')
|
|
339
|
+
parts.push('PLAN');
|
|
340
|
+
if (posture.governOn)
|
|
341
|
+
parts.push('GOVERN');
|
|
342
|
+
return parts.length > 0 ? parts.join('+') : undefined;
|
|
343
|
+
}
|
|
344
|
+
/** The transcript banner rows for an armed session (4.6). */
|
|
345
|
+
export function bannerConfirmations(config, confirmTools) {
|
|
346
|
+
if (!confirmTools)
|
|
347
|
+
return 'none';
|
|
348
|
+
return config.bypassConfirm === false ? 'on' : 'off';
|
|
349
|
+
}
|
|
@@ -205,6 +205,19 @@ export interface SystemPromptParams {
|
|
|
205
205
|
* Only read when `agentMode` is `'plan'`; absent leaves the plan block unchanged.
|
|
206
206
|
*/
|
|
207
207
|
governAddendum?: string;
|
|
208
|
+
/**
|
|
209
|
+
* The rendered `<redteam_mode>` block, or '' (red-team-security-mode 4.6 / D-7).
|
|
210
|
+
*
|
|
211
|
+
* SPLICED IMMEDIATELY AFTER `buildProjectGuidanceBlock()` AND BEFORE `memoryBlock`, and that
|
|
212
|
+
* position is the argument: this block declares who authorized this session and where the
|
|
213
|
+
* boundary is, so it is the frame that explains the scale of every capability block after
|
|
214
|
+
* it. It also has to come after the base prompt's environment and tool list, because a
|
|
215
|
+
* scope sits on top of a real working directory and a real toolset.
|
|
216
|
+
*
|
|
217
|
+
* CONDITIONAL LIKE EVERY BLOCK ABOVE, which is what makes I-1 true: with the mode off the
|
|
218
|
+
* prompt is byte-identical to the pre-feature text for a fixed tool array.
|
|
219
|
+
*/
|
|
220
|
+
redteamBlock?: string;
|
|
208
221
|
}
|
|
209
222
|
/** Describe the active shell so the model does not emit incompatible syntax. */
|
|
210
223
|
export declare function describeShell(): {
|
|
@@ -53,6 +53,7 @@ export function buildSystemPrompt(params) {
|
|
|
53
53
|
const jobsBlock = params.jobsBlock ?? '';
|
|
54
54
|
const imageInputBlock = params.imageInputBlock ?? '';
|
|
55
55
|
const structuredResultBlock = params.structuredResultBlock ?? '';
|
|
56
|
+
const redteamBlock = params.redteamBlock ?? '';
|
|
56
57
|
const appended = (params.appendSystemPrompt ?? '').trim();
|
|
57
58
|
return [
|
|
58
59
|
'You are AragonAgent, an autonomous coding assistant operating inside a terminal (TUI).',
|
|
@@ -68,6 +69,12 @@ export function buildSystemPrompt(params) {
|
|
|
68
69
|
// Base-prompt upgrade; optional blocks still preserve empty/absent equivalence.
|
|
69
70
|
'',
|
|
70
71
|
buildProjectGuidanceBlock(),
|
|
72
|
+
// IMMEDIATELY AFTER THE PROJECT GUIDANCE AND BEFORE THE SKILLS CATALOG
|
|
73
|
+
// (red-team-security-mode D-7). This block says WHO authorized this session and WHERE the
|
|
74
|
+
// boundary is; a model that reads "you may do X" first and "the boundary is Y" afterwards
|
|
75
|
+
// has been given the capability before the constraint, which is not how a professional
|
|
76
|
+
// reads an engagement letter. Conditional, so `''` splices nothing (I-1).
|
|
77
|
+
...(redteamBlock ? ['', redteamBlock] : []),
|
|
71
78
|
// AFTER the project guidance and BEFORE the skills catalog (agent-memory D-5).
|
|
72
79
|
...(memoryBlock ? ['', memoryBlock] : []),
|
|
73
80
|
...(hasSkills ? ['', skillsBlock] : []),
|
package/dist/app/App.d.ts
CHANGED
|
@@ -112,6 +112,15 @@ export interface AppProps {
|
|
|
112
112
|
* affordance, and a notice on every launch trains users to ignore notices.
|
|
113
113
|
*/
|
|
114
114
|
sessionNotice?: string;
|
|
115
|
+
/**
|
|
116
|
+
* What the red team reconciliation produced when this session was resumed
|
|
117
|
+
* (red-team-security-mode 4.10 / I-12).
|
|
118
|
+
*
|
|
119
|
+
* PRESENT ONLY WHEN A RESUME ACTUALLY SAID SOMETHING: the mode came back armed (and the user
|
|
120
|
+
* has to know the posture they are in before the first message), or it did not because the
|
|
121
|
+
* waiver moved. Absent on an ordinary launch, which is what keeps its first frame identical.
|
|
122
|
+
*/
|
|
123
|
+
redTeamNotice?: string;
|
|
115
124
|
}
|
|
116
125
|
/**
|
|
117
126
|
* `App`'s and `cli.tsx`'s small two-way surface for the session, shaped exactly
|
|
@@ -163,4 +172,4 @@ export interface TerminalBridge {
|
|
|
163
172
|
writeForeign?: (text: string) => void;
|
|
164
173
|
selection?: SelectionBridge;
|
|
165
174
|
}
|
|
166
|
-
export declare function App({ controller, version, initialOverlay, initialPrompt, confirmBridge, humanInputBridge, mouseSource, vtInputWarning, updateBridge, pasteBridge, terminal, scrollMode, scrollback, initialEntries, session, sessionBridge, sessionNotice, }: AppProps): React.ReactElement;
|
|
175
|
+
export declare function App({ controller, version, initialOverlay, initialPrompt, confirmBridge, humanInputBridge, mouseSource, vtInputWarning, updateBridge, pasteBridge, terminal, scrollMode, scrollback, initialEntries, session, sessionBridge, sessionNotice, redTeamNotice, }: AppProps): React.ReactElement;
|