@aragon-agent/cli 0.6.57 → 0.6.61

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 (85) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/README.md +159 -3
  3. package/dist/agent/controller.d.ts +112 -1
  4. package/dist/agent/controller.js +350 -7
  5. package/dist/agent/project-guidance-prompt.js +97 -97
  6. package/dist/agent/redteam-prompt.d.ts +29 -11
  7. package/dist/agent/redteam-prompt.js +118 -103
  8. package/dist/agent/redteam-wiring.d.ts +117 -2
  9. package/dist/agent/redteam-wiring.js +204 -1
  10. package/dist/agent/team-notices.d.ts +68 -0
  11. package/dist/agent/team-notices.js +82 -0
  12. package/dist/app/App.js +208 -5
  13. package/dist/app/use-redteam-mode.d.ts +1 -1
  14. package/dist/app/use-redteam-mode.js +14 -1
  15. package/dist/cli.js +13 -0
  16. package/dist/commands/catalog.js +6 -2
  17. package/dist/commands/redteam-command.d.ts +14 -8
  18. package/dist/commands/redteam-command.js +243 -12
  19. package/dist/commands/team-command.js +93 -2
  20. package/dist/config/app-paths.d.ts +19 -0
  21. package/dist/config/app-paths.js +23 -0
  22. package/dist/config/load.d.ts +8 -0
  23. package/dist/gene/catalog-sync.js +37 -16
  24. package/dist/gene/curator/budget.js +1 -1
  25. package/dist/gene/curator/curator.d.ts +6 -0
  26. package/dist/gene/curator/curator.js +8 -0
  27. package/dist/gene/curator/task-runner.js +4 -1
  28. package/dist/gene/curator/tools-verify.js +17 -5
  29. package/dist/gene/curator/validate/evidence-tokens.js +97 -18
  30. package/dist/gene/curator/validate/knowledge.d.ts +5 -0
  31. package/dist/gene/curator/validate/knowledge.js +57 -13
  32. package/dist/gene/curator/validate/types.d.ts +6 -1
  33. package/dist/gene/learn/learn-prompt.d.ts +10 -1
  34. package/dist/gene/learn/learn-prompt.js +11 -2
  35. package/dist/governance/engine/lifecycle.js +1 -1
  36. package/dist/governance/store/run-lock.d.ts +9 -2
  37. package/dist/governance/store/run-lock.js +91 -7
  38. package/dist/host/controller-factory.d.ts +13 -0
  39. package/dist/host/controller-factory.js +7 -0
  40. package/dist/host/index.d.ts +1 -0
  41. package/dist/host/index.js +1 -0
  42. package/dist/host/interaction.d.ts +19 -0
  43. package/dist/host/interaction.js +75 -0
  44. package/dist/host/team-control.d.ts +83 -0
  45. package/dist/host/team-control.js +55 -0
  46. package/dist/logging/install.d.ts +32 -1
  47. package/dist/logging/install.js +21 -0
  48. package/dist/proc/output-streams.d.ts +20 -0
  49. package/dist/proc/output-streams.js +20 -0
  50. package/dist/redteam/prompt-resolve.d.ts +61 -0
  51. package/dist/redteam/prompt-resolve.js +303 -0
  52. package/dist/redteam/prompt-store.d.ts +96 -0
  53. package/dist/redteam/prompt-store.js +156 -0
  54. package/dist/redteam/prompt-template.d.ts +22 -0
  55. package/dist/redteam/prompt-template.js +72 -0
  56. package/dist/team/bus.d.ts +18 -0
  57. package/dist/team/bus.js +70 -18
  58. package/dist/team/console-tools.d.ts +54 -0
  59. package/dist/team/console-tools.js +333 -0
  60. package/dist/team/console-view.d.ts +88 -0
  61. package/dist/team/console-view.js +173 -0
  62. package/dist/team/forced-mode.d.ts +61 -1
  63. package/dist/team/forced-mode.js +75 -0
  64. package/dist/team/normalize.d.ts +31 -0
  65. package/dist/team/normalize.js +49 -5
  66. package/dist/team/notices.d.ts +95 -0
  67. package/dist/team/notices.js +121 -0
  68. package/dist/team/pause-gate.d.ts +79 -0
  69. package/dist/team/pause-gate.js +127 -0
  70. package/dist/team/prompt.d.ts +25 -9
  71. package/dist/team/prompt.js +29 -29
  72. package/dist/team/report.js +33 -0
  73. package/dist/team/runtime.d.ts +270 -5
  74. package/dist/team/runtime.js +732 -64
  75. package/dist/team/settled.d.ts +5 -2
  76. package/dist/team/settled.js +12 -2
  77. package/dist/team/subagent.d.ts +7 -0
  78. package/dist/team/subagent.js +12 -1
  79. package/dist/team/task-tool.d.ts +39 -1
  80. package/dist/team/task-tool.js +75 -18
  81. package/dist/tools/bash-tool.d.ts +11 -8
  82. package/dist/tools/bash-tool.js +44 -9
  83. package/dist/tools/index.d.ts +2 -2
  84. package/dist/tools/index.js +30 -0
  85. package/package.json +3 -3
@@ -22,11 +22,12 @@
22
22
  */
23
23
  import type { CliConfig } from '@aragon-agent/tui/model/config/schema';
24
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';
25
+ import type { RedTeamLogEvent, RedTeamPromptView, RedTeamView } from '@aragon-agent/tui/model/redteam/types';
26
+ import type { PromptResolveRequest, ResolvedPrompt } from '../redteam/prompt-resolve.js';
26
27
  /** What a `--no-redteam` / `ARAGON_REDTEAM=0` / `redteam.enabled=false` session looks like. */
27
28
  export declare const UNAVAILABLE_RED_TEAM_VIEW: RedTeamView;
28
29
  export interface RedTeamWiringDeps {
29
- /** Live config: the four `redteam.*` keys are read through it on every question. */
30
+ /** Live config: the five `redteam.*` keys are read through it on every question. */
30
31
  getConfig(): CliConfig;
31
32
  /**
32
33
  * The chain exists for this launch: `--no-redteam` / `ARAGON_REDTEAM=0` are already folded
@@ -47,6 +48,31 @@ export interface RedTeamWiringDeps {
47
48
  log(event: RedTeamLogEvent): void;
48
49
  /** The clause-set version this build asks for; injectable for the version-scope tests. */
49
50
  disclaimerVersion?: number;
51
+ /**
52
+ * Resolve the prompt profile (three layers, redteam-prompt-profile 5.1).
53
+ *
54
+ * OPTIONAL AND ABSENT MEANS `builtin` (D-17): a hand-written controller stub, a desktop host
55
+ * and the prompt tests all keep working without a filesystem, and a session with no resolver
56
+ * behaves exactly like the pre-feature build.
57
+ */
58
+ resolvePrompt?(request: PromptResolveRequest): ResolvedPrompt;
59
+ /**
60
+ * The session-level override: `--redteam-prompt <path>` at launch, or
61
+ * `/redteam prompt <path>` later. Highest priority; never persisted (D-3).
62
+ */
63
+ promptPath?: string;
64
+ /** Purge the profile read cache (`/redteam prompt reload`, 5.7). */
65
+ purgePromptCache?(): void;
66
+ /** Write the starter profile; the controller supplies the store-backed implementation. */
67
+ writePromptScaffold?(slug?: string): {
68
+ ok: boolean;
69
+ path?: string;
70
+ reason?: string;
71
+ };
72
+ /** A line for the transcript (issue reports, PF-9). Absent = stay silent. */
73
+ notify?(level: 'info' | 'warn' | 'error', text: string): void;
74
+ /** The working directory a relative `--redteam-prompt` path is resolved against. */
75
+ getCwd?(): string;
50
76
  }
51
77
  export type ScopeSetResult = {
52
78
  ok: true;
@@ -63,6 +89,21 @@ export declare class RedTeamWiring {
63
89
  private view;
64
90
  private lastEmitted;
65
91
  private readonly listeners;
92
+ /**
93
+ * The session-level prompt path: `--redteam-prompt`, or `/redteam prompt <path>`.
94
+ * `null` means "no override", which is what makes `builtin` reachable again (AC-22).
95
+ */
96
+ private promptPath;
97
+ /** The profile this session switched to, ahead of the persisted value the config still holds. */
98
+ private profileOverride;
99
+ /**
100
+ * `(code, profile)` pairs already reported as a notice.
101
+ *
102
+ * NOTICE ONCE, LOG ALWAYS (5.1 rule 5): a file that was deleted is a normal state that
103
+ * recurs every turn, so the transcript would otherwise fill with the same sentence; the log
104
+ * still records it, because a silent fallback is the failure this whole feature guards.
105
+ */
106
+ private readonly reportedIssues;
66
107
  constructor(deps: RedTeamWiringDeps);
67
108
  /** The disclaimer version this build's clause set carries. */
68
109
  get disclaimerVersion(): number;
@@ -99,6 +140,80 @@ export declare class RedTeamWiring {
99
140
  block(): string;
100
141
  /** The subagent's trimmed block. Same arming condition, so a child can never out-run the lead. */
101
142
  childBlock(): string;
143
+ /**
144
+ * What `/redteam prompt` reports, and what the status line's fifth row reads.
145
+ *
146
+ * IT RESOLVES ON DEMAND: the view has to be true even before the first block is built, and
147
+ * the read is memoised by `(mtimeMs, size)` in the store, so asking twice costs a `stat`.
148
+ */
149
+ getPromptView(): RedTeamPromptView;
150
+ /**
151
+ * Choose a profile for this session (the command persists the key separately).
152
+ *
153
+ * `builtin` ALSO CLEARS THE SESSION PATH (RV-P1-11 / AC-22): the flag layer outranks the
154
+ * config, so a command that only rewrote the config would report "builtin" while the block
155
+ * still came from the file the flag named - the exact class of lie this feature exists to
156
+ * avoid.
157
+ */
158
+ setPromptProfile(profile: string): {
159
+ ok: boolean;
160
+ resolved: string;
161
+ };
162
+ /**
163
+ * Set or clear the SESSION-LEVEL path (`--redteam-prompt`, `/redteam prompt <path>`).
164
+ *
165
+ * `null` CLEARS IT, AND THAT IS THE POINT (RV-P1-11): `/redteam prompt builtin` has to move
166
+ * the highest-priority layer out of the way, or the report would say "builtin" while the
167
+ * block still came from the file. `undefined` leaves it alone, which is what the launch
168
+ * flag needs.
169
+ */
170
+ setPromptPath(path: string | null): void;
171
+ /** The path currently overriding the config, or `null`. */
172
+ getPromptPath(): string | null;
173
+ /**
174
+ * `/redteam prompt reload`: purge the read cache and say whether the resolved text moved.
175
+ *
176
+ * THE COMPARISON IS A HASH OF THE RESOLUTION, NOT OF THE BLOCK (5.7 / AC-12 / AC-13). The
177
+ * block is `''` whenever the mode is not armed, so comparing blocks told a user in the OFF
178
+ * posture that their edit "changed nothing" whatever it said - and `/redteam prompt` is
179
+ * documented as available in every posture. The digest covers the profile name, the slots and
180
+ * their bodies, never leaves this method, and never reaches a log field.
181
+ *
182
+ * LOGGING FOLLOWS THE ANSWER (AC-13): an unchanged reload writes NOTHING - a second identical
183
+ * `prompt_profile` record is exactly the noise `fromCache` exists to prevent - and a changed
184
+ * one writes exactly one, because there really was a new parse to report.
185
+ */
186
+ reloadPrompt(): {
187
+ changed: boolean;
188
+ };
189
+ /** Write the starter profile through the injected port (there is no I/O in this class). */
190
+ writePromptScaffold(slug?: string): {
191
+ ok: boolean;
192
+ path?: string;
193
+ reason?: string;
194
+ };
195
+ /**
196
+ * The session's override, as the resolver wants it.
197
+ *
198
+ * `quiet` SKIPS THE LOG AND THE NOTICE, and exists for exactly one caller: `reloadPrompt`
199
+ * resolves twice (before and after the cache purge) to answer "did the text move", and a
200
+ * comparison pass must not write two records or repeat a notice.
201
+ */
202
+ private resolvePrompt;
203
+ /** The resolution as one comparison key; see `reloadPrompt`. */
204
+ private promptFingerprint;
205
+ /**
206
+ * Log ONCE PER PARSE and tell the user ONCE PER REASON (5.8 / PF-6).
207
+ *
208
+ * `fromCache` is the switch, not "have I said this before": a cache hit means nothing was
209
+ * parsed this turn, so there is nothing new to log, and without that bit every prompt
210
+ * rebuild would append another identical line.
211
+ *
212
+ * `force` IS THE ONE EXCEPTION, and only `reloadPrompt` uses it: the comparison pass it runs
213
+ * is quiet, so the single record for a genuinely changed reload is written here rather than
214
+ * by the cache miss that pass consumed.
215
+ */
216
+ private noteResolution;
102
217
  /**
103
218
  * Accept the waiver and REPORT WHAT WAS WRITTEN, read back from disk.
104
219
  *
@@ -20,10 +20,12 @@
20
20
  * through an injected reader, and nothing in `config.json` or the environment can express
21
21
  * "accepted".
22
22
  */
23
+ import { createHash } from 'node:crypto';
24
+ import process from 'node:process';
23
25
  import { REDTEAM_DISCLAIMER_VERSION } from '@aragon-agent/tui/model/redteam/limits';
24
26
  import { applyPendingRedTeam, planRedTeam, redTeamPaused, } from '@aragon-agent/tui/model/redteam/redteam-mode';
25
27
  import { normalizeScope, scopeCells } from '@aragon-agent/tui/model/redteam/scope';
26
- import { REDTEAM_NOTICE } from '@aragon-agent/tui/ui/redteam-copy';
28
+ import { REDTEAM_NOTICE, REDTEAM_PROMPT, REDTEAM_PROMPT_ISSUE_TEXT } from '@aragon-agent/tui/ui/redteam-copy';
27
29
  import { buildRedTeamBlock } from './redteam-prompt.js';
28
30
  /** What a `--no-redteam` / `ARAGON_REDTEAM=0` / `redteam.enabled=false` session looks like. */
29
31
  export const UNAVAILABLE_RED_TEAM_VIEW = Object.freeze({
@@ -44,8 +46,26 @@ export class RedTeamWiring {
44
46
  view = null;
45
47
  lastEmitted = null;
46
48
  listeners = new Set();
49
+ /**
50
+ * The session-level prompt path: `--redteam-prompt`, or `/redteam prompt <path>`.
51
+ * `null` means "no override", which is what makes `builtin` reachable again (AC-22).
52
+ */
53
+ promptPath;
54
+ /** The profile this session switched to, ahead of the persisted value the config still holds. */
55
+ profileOverride = null;
56
+ /**
57
+ * `(code, profile)` pairs already reported as a notice.
58
+ *
59
+ * NOTICE ONCE, LOG ALWAYS (5.1 rule 5): a file that was deleted is a normal state that
60
+ * recurs every turn, so the transcript would otherwise fill with the same sentence; the log
61
+ * still records it, because a silent fallback is the failure this whole feature guards.
62
+ */
63
+ reportedIssues = new Set();
47
64
  constructor(deps) {
48
65
  this.deps = deps;
66
+ this.promptPath = deps.promptPath === undefined || deps.promptPath.trim().length === 0
67
+ ? null
68
+ : deps.promptPath;
49
69
  }
50
70
  /** The disclaimer version this build's clause set carries. */
51
71
  get disclaimerVersion() {
@@ -127,23 +147,181 @@ export class RedTeamWiring {
127
147
  block() {
128
148
  if (!this.available() || !this.armed)
129
149
  return '';
150
+ const resolved = this.resolvePrompt();
130
151
  return buildRedTeamBlock({
131
152
  scope: this.scope,
132
153
  paused: redTeamPaused(this.deps.getPosture()),
133
154
  postureLabel: postureLabel(this.deps.getPosture()),
134
155
  role: 'lead',
156
+ ...(resolved === null ? {} : { sections: resolved.sections, extras: resolved.extras }),
135
157
  });
136
158
  }
137
159
  /** The subagent's trimmed block. Same arming condition, so a child can never out-run the lead. */
138
160
  childBlock() {
139
161
  if (!this.available() || !this.armed)
140
162
  return '';
163
+ const resolved = this.resolvePrompt();
141
164
  return buildRedTeamBlock({
142
165
  scope: this.scope,
143
166
  paused: redTeamPaused(this.deps.getPosture()),
144
167
  postureLabel: postureLabel(this.deps.getPosture()),
145
168
  role: 'child',
169
+ ...(resolved === null ? {} : { sections: resolved.sections, extras: resolved.extras }),
170
+ });
171
+ }
172
+ // -------------------------------------------------------------------------
173
+ // Prompt profiles (redteam-prompt-profile 7.5 / D-17)
174
+ // -------------------------------------------------------------------------
175
+ /**
176
+ * What `/redteam prompt` reports, and what the status line's fifth row reads.
177
+ *
178
+ * IT RESOLVES ON DEMAND: the view has to be true even before the first block is built, and
179
+ * the read is memoised by `(mtimeMs, size)` in the store, so asking twice costs a `stat`.
180
+ */
181
+ getPromptView() {
182
+ const resolved = this.resolvePrompt();
183
+ if (resolved === null) {
184
+ return { profile: 'builtin', source: 'builtin', overridden: [], bytes: 0, issues: [] };
185
+ }
186
+ return {
187
+ profile: resolved.profile,
188
+ source: resolved.source,
189
+ overridden: resolved.overridden,
190
+ bytes: resolved.bytes,
191
+ issues: resolved.issues,
192
+ };
193
+ }
194
+ /**
195
+ * Choose a profile for this session (the command persists the key separately).
196
+ *
197
+ * `builtin` ALSO CLEARS THE SESSION PATH (RV-P1-11 / AC-22): the flag layer outranks the
198
+ * config, so a command that only rewrote the config would report "builtin" while the block
199
+ * still came from the file the flag named - the exact class of lie this feature exists to
200
+ * avoid.
201
+ */
202
+ setPromptProfile(profile) {
203
+ this.profileOverride = profile;
204
+ // ANY EXPLICIT SELECTION CLEARS THE SESSION PATH (RV-P1-11 / AC-22). The flag layer
205
+ // outranks the config, so `/redteam prompt <slug>` while `--redteam-prompt` (or an earlier
206
+ // `/redteam prompt <path>`) is still set would report the slug while the block kept coming
207
+ // from that file. `builtin` was the case RV-P1-11 named; every slug is the same lie.
208
+ this.promptPath = null;
209
+ this.deps.rebuildPrompt();
210
+ const view = this.getPromptView();
211
+ this.emitIfChanged();
212
+ return { ok: true, resolved: view.profile };
213
+ }
214
+ /**
215
+ * Set or clear the SESSION-LEVEL path (`--redteam-prompt`, `/redteam prompt <path>`).
216
+ *
217
+ * `null` CLEARS IT, AND THAT IS THE POINT (RV-P1-11): `/redteam prompt builtin` has to move
218
+ * the highest-priority layer out of the way, or the report would say "builtin" while the
219
+ * block still came from the file. `undefined` leaves it alone, which is what the launch
220
+ * flag needs.
221
+ */
222
+ setPromptPath(path) {
223
+ this.promptPath = path === null || path.trim().length === 0 ? null : path;
224
+ this.deps.rebuildPrompt();
225
+ this.emitIfChanged();
226
+ }
227
+ /** The path currently overriding the config, or `null`. */
228
+ getPromptPath() {
229
+ return this.promptPath;
230
+ }
231
+ /**
232
+ * `/redteam prompt reload`: purge the read cache and say whether the resolved text moved.
233
+ *
234
+ * THE COMPARISON IS A HASH OF THE RESOLUTION, NOT OF THE BLOCK (5.7 / AC-12 / AC-13). The
235
+ * block is `''` whenever the mode is not armed, so comparing blocks told a user in the OFF
236
+ * posture that their edit "changed nothing" whatever it said - and `/redteam prompt` is
237
+ * documented as available in every posture. The digest covers the profile name, the slots and
238
+ * their bodies, never leaves this method, and never reaches a log field.
239
+ *
240
+ * LOGGING FOLLOWS THE ANSWER (AC-13): an unchanged reload writes NOTHING - a second identical
241
+ * `prompt_profile` record is exactly the noise `fromCache` exists to prevent - and a changed
242
+ * one writes exactly one, because there really was a new parse to report.
243
+ */
244
+ reloadPrompt() {
245
+ const before = this.promptFingerprint();
246
+ this.deps.purgePromptCache?.();
247
+ // QUIET: the fresh parse is only here to be compared. It is logged below, once, and only
248
+ // when the comparison says there is something new to log.
249
+ const after = this.resolvePrompt({ quiet: true });
250
+ const changed = (after === null ? '' : fingerprintOf(after)) !== before;
251
+ if (changed && after !== null)
252
+ this.noteResolution(after, true);
253
+ this.deps.rebuildPrompt();
254
+ this.emitIfChanged();
255
+ return { changed };
256
+ }
257
+ /** Write the starter profile through the injected port (there is no I/O in this class). */
258
+ writePromptScaffold(slug) {
259
+ const write = this.deps.writePromptScaffold;
260
+ if (typeof write !== 'function')
261
+ return { ok: false, reason: 'unavailable' };
262
+ return write(slug);
263
+ }
264
+ /**
265
+ * The session's override, as the resolver wants it.
266
+ *
267
+ * `quiet` SKIPS THE LOG AND THE NOTICE, and exists for exactly one caller: `reloadPrompt`
268
+ * resolves twice (before and after the cache purge) to answer "did the text move", and a
269
+ * comparison pass must not write two records or repeat a notice.
270
+ */
271
+ resolvePrompt(options = {}) {
272
+ const resolver = this.deps.resolvePrompt;
273
+ if (typeof resolver !== 'function')
274
+ return null;
275
+ const resolved = resolver({
276
+ profile: this.profileOverride ?? this.config().profile,
277
+ cwd: this.deps.getCwd?.() ?? process.cwd(),
278
+ ...(this.promptPath === null ? {} : { flagPath: this.promptPath }),
146
279
  });
280
+ if (options.quiet !== true)
281
+ this.noteResolution(resolved);
282
+ return resolved;
283
+ }
284
+ /** The resolution as one comparison key; see `reloadPrompt`. */
285
+ promptFingerprint() {
286
+ const resolved = this.resolvePrompt({ quiet: true });
287
+ return resolved === null ? '' : fingerprintOf(resolved);
288
+ }
289
+ /**
290
+ * Log ONCE PER PARSE and tell the user ONCE PER REASON (5.8 / PF-6).
291
+ *
292
+ * `fromCache` is the switch, not "have I said this before": a cache hit means nothing was
293
+ * parsed this turn, so there is nothing new to log, and without that bit every prompt
294
+ * rebuild would append another identical line.
295
+ *
296
+ * `force` IS THE ONE EXCEPTION, and only `reloadPrompt` uses it: the comparison pass it runs
297
+ * is quiet, so the single record for a genuinely changed reload is written here rather than
298
+ * by the cache miss that pass consumed.
299
+ */
300
+ noteResolution(resolved, force = false) {
301
+ const log = force || !resolved.fromCache;
302
+ if (resolved.source !== 'builtin' && log) {
303
+ this.deps.log({
304
+ type: 'redteam.prompt_profile',
305
+ profile: resolved.profile,
306
+ source: resolved.source,
307
+ bytes: resolved.bytes,
308
+ sections: resolved.overridden.length,
309
+ issues: resolved.issues.length,
310
+ fromCache: resolved.fromCache,
311
+ });
312
+ }
313
+ for (const issue of resolved.issues) {
314
+ // ISSUE CODES AND PROFILE NAMES ONLY: `detail` can hold a file name (D-11).
315
+ if (log) {
316
+ this.deps.log({ type: 'redteam.prompt_issue', code: issue.code, severity: issue.severity });
317
+ }
318
+ const key = `${issue.code}|${resolved.profile}`;
319
+ if (this.reportedIssues.has(key))
320
+ continue;
321
+ this.reportedIssues.add(key);
322
+ const text = REDTEAM_PROMPT_ISSUE_TEXT[issue.code] ?? issue.code;
323
+ this.deps.notify?.('warn', `${REDTEAM_PROMPT.issuePrefix}${resolved.profile} - ${text}.`);
324
+ }
147
325
  }
148
326
  /**
149
327
  * Accept the waiver and REPORT WHAT WAS WRITTEN, read back from disk.
@@ -331,7 +509,32 @@ const DEFAULT_RED_TEAM_CONFIG = {
331
509
  bypassConfirm: true,
332
510
  banner: true,
333
511
  askEveryArm: false,
512
+ profile: 'builtin',
334
513
  };
514
+ /**
515
+ * The first 8 hex characters of a SHA-256, for the "did the block change" answer only.
516
+ *
517
+ * NEVER A LOG FIELD (5.7 / D-11): the user asked a yes-or-no question about their own edit, and
518
+ * a digest of a prompt that may contain a client name is not something to keep.
519
+ */
520
+ function digest(text) {
521
+ return createHash('sha256').update(text, 'utf-8').digest('hex').slice(0, 8);
522
+ }
523
+ /**
524
+ * The resolution as one comparison key: the profile's NAME plus the text it produced.
525
+ *
526
+ * NOT THE BLOCK, and not the bytes: the block depends on arming, scope and posture (so it
527
+ * answers a different question), and `bytes` moves with a comment-only edit while the prompt a
528
+ * model would read is identical. What a user means by "did my edit take effect" is this.
529
+ */
530
+ function fingerprintOf(resolved) {
531
+ return digest(JSON.stringify({
532
+ profile: resolved.profile,
533
+ source: resolved.source,
534
+ sections: [...resolved.sections.entries()],
535
+ extras: resolved.extras,
536
+ }));
537
+ }
335
538
  /** The posture's NAME, for the prompt note. It never decides anything (I-10). */
336
539
  function postureLabel(posture) {
337
540
  const parts = [];
@@ -0,0 +1,68 @@
1
+ /**
2
+ * TeamNoticeRelay - "a team event happened, and the lead hears about it exactly
3
+ * once" (team-detached-dispatch section 5.3.2).
4
+ *
5
+ * ASCII ONLY: `src/agent/**` is inside `glyphs.test.ts`'s static scan.
6
+ *
7
+ * EVERY LINE OF THIS FILE IS THE ARGUMENT `job-notices.ts` ALREADY MADE, one
8
+ * feature up, and the reason it is copied rather than shared is that the two
9
+ * policies genuinely differ - see the note below. The mechanism, though, is the
10
+ * same and the failure it prevents is the same:
11
+ *
12
+ * `fast/reviewer.ts` calls `clearAllQueues()` when `userSteerCount() === 0`.
13
+ * A notice steered with `enqueueSteering(text, false)` has no receipt, never
14
+ * enters `pendingUserSteering`, and is therefore invisible to that counter.
15
+ * With `fast` on, the LAST notice of a run could be wiped silently.
16
+ *
17
+ * So: three channels that all take from ONE queue, plus a ledger. A notice that has
18
+ * been steered is held until a `steering_accepted` receipt proves the queue was
19
+ * drained; anything still held at `turn_start` or at the end of a run goes back
20
+ * into the queue. `TeamNoticeQueue.push` is idempotent by id, so a re-queue can
21
+ * only delay a notice, never duplicate it.
22
+ *
23
+ * WHY NOT ABSTRACTED TOGETHER WITH THE JOB RELAY (spec 5.3.2). The job relay's
24
+ * channel 1 must never inject while a tool batch is open (its I-5), because a job
25
+ * notice is a courtesy. A settle report is not a courtesy: the lead was told "you
26
+ * will get the report", and a dispatch that ends mid-batch must still deliver it.
27
+ * One shared class would have to be parameterised into two different policies and
28
+ * would end up being two classes anyway, one of them hidden.
29
+ */
30
+ import { type TeamNoticeQueue } from '../team/notices.js';
31
+ export interface TeamNoticeRelayDeps {
32
+ queue: TeamNoticeQueue;
33
+ /** `enqueueSteering(text, false)` - the receipt-less path. */
34
+ steer: (text: string) => void;
35
+ /** `activeToolCalls === 0 && isRunning() && !abortRequested` (push channel). */
36
+ isAtSafeSteerPoint: () => boolean;
37
+ /**
38
+ * `activeToolCalls === 0 && !abortRequested` - the FILL channel's precondition.
39
+ *
40
+ * NOT `isAtSafeSteerPoint()`, for the reason `job-notices.ts` records at length:
41
+ * the fill runs immediately before `agent.prompt()`, where `isRunning()` is
42
+ * FALSE by contract, so the push predicate would make this channel dead.
43
+ */
44
+ canSteerBeforeTurn: () => boolean;
45
+ }
46
+ export declare class TeamNoticeRelay {
47
+ private readonly deps;
48
+ /** Notices steered but not yet proven delivered, keyed by their queue id. */
49
+ private readonly pendingSteered;
50
+ constructor(deps: TeamNoticeRelayDeps);
51
+ /** The push channel: called from the controller's one safe steer point. */
52
+ tryPush(): boolean;
53
+ /** The fill channel: just before the next turn starts. */
54
+ flushForTurn(): boolean;
55
+ /** A receipt proves the steering queue was drained, so nothing is stranded. */
56
+ onSteeringAccepted(): void;
57
+ /**
58
+ * Put undelivered notices back at `turn_start` and at the end of a run.
59
+ *
60
+ * THIS IS WHAT TURNS "swallowed by clearAllQueues()" INTO "delivered one turn
61
+ * later" - the difference between a report the user gets and a report that
62
+ * exists only in a file.
63
+ */
64
+ requeueUndelivered(): void;
65
+ /** How many notices are waiting. Used by the tests and the diagnostics path. */
66
+ pending(): number;
67
+ private steerQueued;
68
+ }
@@ -0,0 +1,82 @@
1
+ /**
2
+ * TeamNoticeRelay - "a team event happened, and the lead hears about it exactly
3
+ * once" (team-detached-dispatch section 5.3.2).
4
+ *
5
+ * ASCII ONLY: `src/agent/**` is inside `glyphs.test.ts`'s static scan.
6
+ *
7
+ * EVERY LINE OF THIS FILE IS THE ARGUMENT `job-notices.ts` ALREADY MADE, one
8
+ * feature up, and the reason it is copied rather than shared is that the two
9
+ * policies genuinely differ - see the note below. The mechanism, though, is the
10
+ * same and the failure it prevents is the same:
11
+ *
12
+ * `fast/reviewer.ts` calls `clearAllQueues()` when `userSteerCount() === 0`.
13
+ * A notice steered with `enqueueSteering(text, false)` has no receipt, never
14
+ * enters `pendingUserSteering`, and is therefore invisible to that counter.
15
+ * With `fast` on, the LAST notice of a run could be wiped silently.
16
+ *
17
+ * So: three channels that all take from ONE queue, plus a ledger. A notice that has
18
+ * been steered is held until a `steering_accepted` receipt proves the queue was
19
+ * drained; anything still held at `turn_start` or at the end of a run goes back
20
+ * into the queue. `TeamNoticeQueue.push` is idempotent by id, so a re-queue can
21
+ * only delay a notice, never duplicate it.
22
+ *
23
+ * WHY NOT ABSTRACTED TOGETHER WITH THE JOB RELAY (spec 5.3.2). The job relay's
24
+ * channel 1 must never inject while a tool batch is open (its I-5), because a job
25
+ * notice is a courtesy. A settle report is not a courtesy: the lead was told "you
26
+ * will get the report", and a dispatch that ends mid-batch must still deliver it.
27
+ * One shared class would have to be parameterised into two different policies and
28
+ * would end up being two classes anyway, one of them hidden.
29
+ */
30
+ import { renderTeamNotices } from '../team/notices.js';
31
+ export class TeamNoticeRelay {
32
+ deps;
33
+ /** Notices steered but not yet proven delivered, keyed by their queue id. */
34
+ pendingSteered = new Map();
35
+ constructor(deps) {
36
+ this.deps = deps;
37
+ }
38
+ /** The push channel: called from the controller's one safe steer point. */
39
+ tryPush() {
40
+ if (!this.deps.isAtSafeSteerPoint())
41
+ return false;
42
+ return this.steerQueued();
43
+ }
44
+ /** The fill channel: just before the next turn starts. */
45
+ flushForTurn() {
46
+ if (!this.deps.canSteerBeforeTurn())
47
+ return false;
48
+ return this.steerQueued();
49
+ }
50
+ /** A receipt proves the steering queue was drained, so nothing is stranded. */
51
+ onSteeringAccepted() {
52
+ this.pendingSteered.clear();
53
+ }
54
+ /**
55
+ * Put undelivered notices back at `turn_start` and at the end of a run.
56
+ *
57
+ * THIS IS WHAT TURNS "swallowed by clearAllQueues()" INTO "delivered one turn
58
+ * later" - the difference between a report the user gets and a report that
59
+ * exists only in a file.
60
+ */
61
+ requeueUndelivered() {
62
+ if (this.pendingSteered.size === 0)
63
+ return;
64
+ const stranded = [...this.pendingSteered.values()];
65
+ this.pendingSteered.clear();
66
+ for (const notice of stranded)
67
+ this.deps.queue.push(notice);
68
+ }
69
+ /** How many notices are waiting. Used by the tests and the diagnostics path. */
70
+ pending() {
71
+ return this.deps.queue.pending();
72
+ }
73
+ steerQueued() {
74
+ const notices = this.deps.queue.drain();
75
+ if (notices.length === 0)
76
+ return false;
77
+ for (const notice of notices)
78
+ this.pendingSteered.set(notice.id, notice);
79
+ this.deps.steer(renderTeamNotices(notices));
80
+ return true;
81
+ }
82
+ }