@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
@@ -37,6 +37,14 @@ export declare class InteractionCoordinator {
37
37
  private sequence;
38
38
  private gesture;
39
39
  private disposed;
40
+ /**
41
+ * The team settle timer (team-detached-dispatch section 5.3.3).
42
+ *
43
+ * THIS HOST'S OWN, exactly like the TUI's `followTimer`, and armed from the SAME
44
+ * pure decision table: that is what makes the two front ends answer one sentence
45
+ * identically (R9) without either owning the policy.
46
+ */
47
+ private settleTimer;
40
48
  constructor(ports: InteractionPorts);
41
49
  get phase(): InteractionPhase;
42
50
  /** Feed `agent_start` / `agent_end` here so `phase` follows the engine. */
@@ -47,6 +55,17 @@ export declare class InteractionCoordinator {
47
55
  * else.
48
56
  */
49
57
  onAgentEnd(): void;
58
+ /**
59
+ * Arm, announce, or skip the settle continuation (5.3.3).
60
+ *
61
+ * THE SAME TRUTH TABLE THE TERMINAL RUNS (`planSettleContinuation`), fed this
62
+ * host's facts. `followThroughArmed` is false here because this host has no todo
63
+ * follow-through and no forced-dispatch nudge: the flag exists for the hosts
64
+ * that do, and passing `false` is the honest answer rather than a guess.
65
+ */
66
+ private armTeamSettle;
67
+ /** Release the settle timer. Called from `dispose()` so it cannot fire into a dead host. */
68
+ private clearSettleTimer;
50
69
  /** Land the team-mode change that was asked for during the turn, and say what happened. */
51
70
  private landTeamMode;
52
71
  /** Send a message to the agent, bypassing slash parsing. */
@@ -23,12 +23,21 @@ import { teamModeToast, teamRefusalText } from '@aragon-agent/tui/model/team/tea
23
23
  import { buildInvocationCard, invocationCardsEnabled } from '@aragon-agent/tui/model/agent/invocation-card';
24
24
  import { getSecrets } from '@aragon-agent/tui/model/logging/secret-registry';
25
25
  import { redactText } from '../logging/redact.js';
26
+ import { planSettleContinuation } from '@aragon-agent/tui/model/team/settle-plan';
26
27
  export class InteractionCoordinator {
27
28
  ports;
28
29
  phaseValue = 'idle';
29
30
  sequence = 0;
30
31
  gesture = { phase: 'ready' };
31
32
  disposed = false;
33
+ /**
34
+ * The team settle timer (team-detached-dispatch section 5.3.3).
35
+ *
36
+ * THIS HOST'S OWN, exactly like the TUI's `followTimer`, and armed from the SAME
37
+ * pure decision table: that is what makes the two front ends answer one sentence
38
+ * identically (R9) without either owning the policy.
39
+ */
40
+ settleTimer = null;
32
41
  constructor(ports) {
33
42
  this.ports = ports;
34
43
  }
@@ -53,6 +62,12 @@ export class InteractionCoordinator {
53
62
  // otherwise be skipped by the `if (!applied) return` below and sit pending until the next
54
63
  // `prompt()` safety net (team-mode-toggle-keys R-10).
55
64
  this.landTeamMode();
65
+ // THE TEAM SETTLE, BEFORE THE POSTURE'S EARLY RETURN (5.3.3): the decision has
66
+ // to be made once per `agent_end`, and the posture returns early for almost
67
+ // every turn. A dispatch that settled during this turn announces or continues
68
+ // here; one that settled inside the turn itself is `none` by the table's own
69
+ // rule, because its report already arrived as a steering message.
70
+ this.armTeamSettle();
56
71
  const applied = controller.applyPendingPosture();
57
72
  if (!applied)
58
73
  return;
@@ -66,6 +81,63 @@ export class InteractionCoordinator {
66
81
  });
67
82
  dispatch({ type: 'pushToast', level: 'info', text: postureAppliedToast(applied.effective) });
68
83
  }
84
+ /**
85
+ * Arm, announce, or skip the settle continuation (5.3.3).
86
+ *
87
+ * THE SAME TRUTH TABLE THE TERMINAL RUNS (`planSettleContinuation`), fed this
88
+ * host's facts. `followThroughArmed` is false here because this host has no todo
89
+ * follow-through and no forced-dispatch nudge: the flag exists for the hosts
90
+ * that do, and passing `false` is the honest answer rather than a guess.
91
+ */
92
+ armTeamSettle() {
93
+ const { controller, dispatch } = this.ports;
94
+ const facts = controller.teamSettleFacts?.() ?? null;
95
+ if (facts === null)
96
+ return;
97
+ const team = controller.getTeamConfig();
98
+ const decision = planSettleContinuation({
99
+ mode: team.autoResume,
100
+ settled: facts.settled,
101
+ settledInsideTurn: facts.settledInsideTurn,
102
+ runEnd: { aborted: facts.aborted, errored: facts.errored },
103
+ continuedThisDispatch: facts.continuedThisDispatch,
104
+ userPending: controller.hasPendingUserMessages(),
105
+ followThroughArmed: false,
106
+ graceMs: team.settleGraceMs,
107
+ outcome: facts.outcome,
108
+ });
109
+ if (decision.kind === 'notice') {
110
+ this.ports.notify(decision.level, decision.text);
111
+ return;
112
+ }
113
+ if (decision.kind !== 'continue')
114
+ return;
115
+ this.ports.notify(decision.level, decision.notice);
116
+ if (this.settleTimer !== null)
117
+ clearTimeout(this.settleTimer);
118
+ this.settleTimer = setTimeout(() => {
119
+ this.settleTimer = null;
120
+ // Re-read at fire time: the user may have typed in the grace window, and a
121
+ // continuation that starts over their message is the one promise this table
122
+ // must never break.
123
+ if (this.disposed)
124
+ return;
125
+ if (controller.isRunning() || controller.isCompactionBusy?.())
126
+ return;
127
+ if (controller.hasPendingUserMessages())
128
+ return;
129
+ // The id comes from the facts: the dispatch has settled, so `live()` is null.
130
+ controller.markTeamContinued(facts.dispatchId);
131
+ void controller.prompt(decision.message, { todoPolicy: 'continue' });
132
+ }, decision.graceMs);
133
+ this.settleTimer.unref?.();
134
+ }
135
+ /** Release the settle timer. Called from `dispose()` so it cannot fire into a dead host. */
136
+ clearSettleTimer() {
137
+ if (this.settleTimer !== null)
138
+ clearTimeout(this.settleTimer);
139
+ this.settleTimer = null;
140
+ }
69
141
  /** Land the team-mode change that was asked for during the turn, and say what happened. */
70
142
  landTeamMode() {
71
143
  const { controller, dispatch } = this.ports;
@@ -195,6 +267,9 @@ export class InteractionCoordinator {
195
267
  }
196
268
  dispose() {
197
269
  this.disposed = true;
270
+ // An armed continuation must not fire into a disposed host: the timer would
271
+ // call `controller.prompt()` for a coordinator nobody is listening to.
272
+ this.clearSettleTimer();
198
273
  this.sequence += 1;
199
274
  if (this.phaseValue === 'starting' || this.ports.controller.isCompactionBusy?.()) {
200
275
  this.ports.controller.abort();
@@ -0,0 +1,83 @@
1
+ /**
2
+ * `host/team-control.ts` - the desktop control surface for a live dispatch
3
+ * (team-detached-dispatch section 7.3).
4
+ *
5
+ * ASCII ONLY, and NO INK, NO REACT: this file is inside the `host/**` import
6
+ * closure that layering rule L9 keeps free of the UI packages, because the Electron
7
+ * main process evaluates it.
8
+ *
9
+ * THE POINT OF THIS FILE IS THE BOUNDARY. A renderer panel gets a handful of
10
+ * strings and sends a handful of verbs; it never sees a `TeamRuntime`, a handle or
11
+ * a phase enum of its own. That is what keeps the desktop honest about the same
12
+ * facts the terminal shows - both read `TeamRuntime.inspect()`, and the panel
13
+ * renders what it is given rather than re-deriving it.
14
+ *
15
+ * NO NEW STREAM. The live roster keeps arriving over the existing team channel
16
+ * (`attachTeamChannel`); this only answers "what is true now" and "do this".
17
+ */
18
+ import type { SubagentPhase } from '@aragon-agent/tui/model/team/types';
19
+ import type { DispatchInspection, TeamRuntime } from '../team/runtime.js';
20
+ import type { TeamControlRequest } from '../team/console-view.js';
21
+ /**
22
+ * What a control surface may read. A STRUCTURAL subset of the controller, so this
23
+ * file compiles without importing the 4 500-line controller and a test can pass a
24
+ * two-line stub.
25
+ */
26
+ export interface TeamControlSource {
27
+ readTeamControl(): {
28
+ inspection: DispatchInspection | null;
29
+ live: {
30
+ dispatchId: string;
31
+ } | null;
32
+ };
33
+ sendTeamControl(request: TeamControlRequest, by?: 'lead' | 'user'): {
34
+ ok: boolean;
35
+ detail: string;
36
+ };
37
+ stopTeam(by: 'lead' | 'user', reason?: string): {
38
+ stopped: string[];
39
+ live: string[];
40
+ };
41
+ }
42
+ /** One row of the roster, as the panel draws it. */
43
+ export interface TeamControlRow {
44
+ label: string;
45
+ description: string;
46
+ phase: SubagentPhase;
47
+ /** Who holds it, when it is paused. */
48
+ by?: 'lead' | 'user' | 'supervisor';
49
+ elapsedMs: number;
50
+ turns: number;
51
+ toolCalls: number;
52
+ lastTool?: string;
53
+ pausedMs?: number;
54
+ error?: string;
55
+ }
56
+ /** Everything the panel needs for one render. */
57
+ export interface TeamControlView {
58
+ dispatch: {
59
+ id: string;
60
+ live: boolean;
61
+ startedAt: number;
62
+ requested: number;
63
+ } | null;
64
+ rows: TeamControlRow[];
65
+ /** Messages the children addressed to the lead, for the "mail" badge. */
66
+ mail: number;
67
+ }
68
+ /** Project the runtime's inspection into the panel's shape. Pure. */
69
+ export declare function readTeamControl(source: TeamControlSource): TeamControlView;
70
+ /**
71
+ * Run one control verb.
72
+ *
73
+ * `by: 'user'` ALWAYS, and not a parameter: this surface is a human pressing a
74
+ * button. A lead-initiated action reaches the runtime through its own tool, and
75
+ * conflating the two would make the report's Control section attribute a button
76
+ * press to the model.
77
+ */
78
+ export declare function controlTeam(source: TeamControlSource, request: TeamControlRequest): {
79
+ ok: boolean;
80
+ detail: string;
81
+ };
82
+ /** Exported for the tests' convenience: the runtime type this file must never leak. */
83
+ export type { TeamRuntime };
@@ -0,0 +1,55 @@
1
+ /**
2
+ * `host/team-control.ts` - the desktop control surface for a live dispatch
3
+ * (team-detached-dispatch section 7.3).
4
+ *
5
+ * ASCII ONLY, and NO INK, NO REACT: this file is inside the `host/**` import
6
+ * closure that layering rule L9 keeps free of the UI packages, because the Electron
7
+ * main process evaluates it.
8
+ *
9
+ * THE POINT OF THIS FILE IS THE BOUNDARY. A renderer panel gets a handful of
10
+ * strings and sends a handful of verbs; it never sees a `TeamRuntime`, a handle or
11
+ * a phase enum of its own. That is what keeps the desktop honest about the same
12
+ * facts the terminal shows - both read `TeamRuntime.inspect()`, and the panel
13
+ * renders what it is given rather than re-deriving it.
14
+ *
15
+ * NO NEW STREAM. The live roster keeps arriving over the existing team channel
16
+ * (`attachTeamChannel`); this only answers "what is true now" and "do this".
17
+ */
18
+ /** Project the runtime's inspection into the panel's shape. Pure. */
19
+ export function readTeamControl(source) {
20
+ const { inspection } = source.readTeamControl();
21
+ if (inspection === null)
22
+ return { dispatch: null, rows: [], mail: 0 };
23
+ return {
24
+ dispatch: {
25
+ id: inspection.dispatchId,
26
+ live: inspection.live,
27
+ startedAt: inspection.startedAt,
28
+ requested: inspection.requested,
29
+ },
30
+ rows: inspection.children.map((child) => ({
31
+ label: child.label,
32
+ description: child.description,
33
+ phase: child.phase,
34
+ ...(child.pausedBy !== undefined ? { by: child.pausedBy } : {}),
35
+ elapsedMs: child.elapsedMs,
36
+ turns: child.turns,
37
+ toolCalls: child.toolCalls,
38
+ ...(child.lastTool !== undefined ? { lastTool: child.lastTool } : {}),
39
+ ...(child.pausedMs !== undefined ? { pausedMs: child.pausedMs } : {}),
40
+ ...(child.error !== undefined ? { error: child.error } : {}),
41
+ })),
42
+ mail: inspection.mail.length,
43
+ };
44
+ }
45
+ /**
46
+ * Run one control verb.
47
+ *
48
+ * `by: 'user'` ALWAYS, and not a parameter: this surface is a human pressing a
49
+ * button. A lead-initiated action reaches the runtime through its own tool, and
50
+ * conflating the two would make the report's Control section attribute a button
51
+ * press to the model.
52
+ */
53
+ export function controlTeam(source, request) {
54
+ return source.sendTeamControl(request, 'user');
55
+ }
@@ -261,11 +261,15 @@ export declare function attachAgentEvents(logger: Logger, controller: AgentEvent
261
261
  export interface TeamEventSource {
262
262
  subscribeTeam?(listener: (event: TeamLogEvent) => void): () => void;
263
263
  }
264
- /** The five members of the CLI-local `TeamEvent` union, as this module reads them. */
264
+ /** The seven members of the CLI-local `TeamEvent` union, as this module reads them. */
265
265
  export type TeamLogEvent = {
266
266
  type: 'dispatch_start';
267
267
  dispatchId: string;
268
268
  requested: number;
269
+ /** The turn that started it (team-detached-dispatch I-DD11). */
270
+ turnId?: number;
271
+ /** True when the dispatch outlives the `task` call that started it. */
272
+ detached?: boolean;
269
273
  specs?: Array<{
270
274
  label?: string;
271
275
  description?: string;
@@ -293,6 +297,33 @@ export type TeamLogEvent = {
293
297
  subject?: string;
294
298
  body?: string;
295
299
  };
300
+ } | {
301
+ /**
302
+ * A pause / resume / stop / spawn / message, by the lead, the user or the
303
+ * supervisor (team-detached-dispatch I-DD5). Logged because the audit trail
304
+ * is the whole reason a console tool is safe to give a model: every
305
+ * mutation of a running dispatch names its author here.
306
+ */
307
+ type: 'control';
308
+ dispatchId: string;
309
+ action?: string;
310
+ label?: string;
311
+ by?: string;
312
+ reason?: string;
313
+ at?: number;
314
+ } | {
315
+ /**
316
+ * A child's mail to the lead. Logged as a SUBJECT ONLY: the body is prose a
317
+ * child wrote for the lead, and the log is not the place a child's text
318
+ * becomes an unreadable line.
319
+ */
320
+ type: 'lead_mail';
321
+ dispatchId: string;
322
+ message?: {
323
+ from?: string;
324
+ to?: string;
325
+ subject?: string;
326
+ };
296
327
  } | {
297
328
  type: 'overseer';
298
329
  dispatchId: string;
@@ -514,6 +514,27 @@ export function attachTeamEvents(logger, controller) {
514
514
  subject: event.message?.subject,
515
515
  });
516
516
  break;
517
+ case 'control':
518
+ // WHO DID WHAT, at info: a control action is a deliberate act on a running
519
+ // dispatch, and the audit trail is what makes giving a model these tools
520
+ // defensible in the first place (I-DD5). The reason is the short one the
521
+ // caller supplied, never a child's prose.
522
+ logger.info('agent', 'team_control', {
523
+ dispatchId: event.dispatchId,
524
+ action: event.action,
525
+ label: event.label,
526
+ by: event.by,
527
+ reason: event.reason,
528
+ });
529
+ break;
530
+ case 'lead_mail':
531
+ // SUBJECT ONLY, for the same reason a `team_send` body is never recorded.
532
+ logger.debug('agent', 'team_lead_mail', {
533
+ dispatchId: event.dispatchId,
534
+ from: event.message?.from,
535
+ subject: event.message?.subject,
536
+ });
537
+ break;
517
538
  case 'overseer':
518
539
  // REASON ONLY, and at debug: interventions are routine supervision,
519
540
  // not failures; the report and the panel carry them to the user.
@@ -33,6 +33,26 @@
33
33
  * this to decide the WORDING (note or not) and, together with the `'end'`
34
34
  * events, to settle the ordinary path without waiting for `'close'` at all.
35
35
  *
36
+ * AND READ THEM TWICE, because one sample is still a clock. The SECOND release
37
+ * gate failure of the same sentence (2026-11-10) printed the note for
38
+ * `node -e "console.log('hi')"`: not a verdict-from-expiry this time, but a
39
+ * verdict from a single look taken in the milliseconds before libuv dispatched
40
+ * the EOF behind a starved loop. So `bash` keeps waiting past
41
+ * `PROC_LIMITS.drainMs` - event driven, so an ordinary command pays nothing -
42
+ * and prints the note only if the pipes are STILL open a whole
43
+ * `PROC_LIMITS.drainVerifyMs` later. A pipe that lets go in between is not a
44
+ * held pipe, it is a slow notification, and the model must not be told to
45
+ * background a command that already finished.
46
+ *
47
+ * AND THAT WINDOW IS SIZED FROM THE HOST, NOT FROM HABIT. The THIRD failure of
48
+ * the same sentence (2026-11-10, AC-9b in `bash-settle.test.ts`) came from a
49
+ * window calibrated by eyeball: one second was inside the measured distribution
50
+ * of last-byte-to-EOF lag on a loaded machine, so the wait expired before the
51
+ * notification did. `PROC_LIMITS.drainVerifyMs` records the measurement that
52
+ * replaced it; the takeaway for anyone editing either number is that the
53
+ * quantity being raced belongs to the host, so the window has to be justified
54
+ * against a loaded one.
55
+ *
36
56
  * ASCII ONLY: `src/proc/**` is inside the glyph scanner's scope.
37
57
  */
38
58
  import type { Readable } from 'node:stream';
@@ -33,6 +33,26 @@
33
33
  * this to decide the WORDING (note or not) and, together with the `'end'`
34
34
  * events, to settle the ordinary path without waiting for `'close'` at all.
35
35
  *
36
+ * AND READ THEM TWICE, because one sample is still a clock. The SECOND release
37
+ * gate failure of the same sentence (2026-11-10) printed the note for
38
+ * `node -e "console.log('hi')"`: not a verdict-from-expiry this time, but a
39
+ * verdict from a single look taken in the milliseconds before libuv dispatched
40
+ * the EOF behind a starved loop. So `bash` keeps waiting past
41
+ * `PROC_LIMITS.drainMs` - event driven, so an ordinary command pays nothing -
42
+ * and prints the note only if the pipes are STILL open a whole
43
+ * `PROC_LIMITS.drainVerifyMs` later. A pipe that lets go in between is not a
44
+ * held pipe, it is a slow notification, and the model must not be told to
45
+ * background a command that already finished.
46
+ *
47
+ * AND THAT WINDOW IS SIZED FROM THE HOST, NOT FROM HABIT. The THIRD failure of
48
+ * the same sentence (2026-11-10, AC-9b in `bash-settle.test.ts`) came from a
49
+ * window calibrated by eyeball: one second was inside the measured distribution
50
+ * of last-byte-to-EOF lag on a loaded machine, so the wait expired before the
51
+ * notification did. `PROC_LIMITS.drainVerifyMs` records the measurement that
52
+ * replaced it; the takeaway for anyone editing either number is that the
53
+ * quantity being raced belongs to the host, so the window has to be justified
54
+ * against a loaded one.
55
+ *
36
56
  * ASCII ONLY: `src/proc/**` is inside the glyph scanner's scope.
37
57
  */
38
58
  /**
@@ -0,0 +1,61 @@
1
+ /**
2
+ * The THREE-LAYER prompt resolution and its inheritance merge
3
+ * (redteam-prompt-profile 5.1 / 5.5).
4
+ *
5
+ * ASCII ONLY - `src/redteam/**` is inside `glyphs.test.ts::inScope`.
6
+ *
7
+ * --redteam-prompt <path> > redteam.profile > builtin
8
+ * (this session only) (persisted) (code, no I/O)
9
+ *
10
+ * TOTAL, AND TOTAL IS A SECURITY PROPERTY (D-9 / PF-9). No layer can throw and no layer can
11
+ * change whether the mode is available or armed: a profile that is missing, oversized,
12
+ * headerless or self-inheriting produces an issue and a fallback, and the mode still arms.
13
+ * The alternative - a prompt file that can disable a security posture by being broken - is
14
+ * the one failure mode this design refuses to have.
15
+ *
16
+ * THE DISPLAY NAME NEVER CONTAINS A REAL PATH (D-11 / PF-6). A slug stays a slug, an absolute
17
+ * profile path becomes `'<path>'`, and a `--redteam-prompt` file becomes `'<flag>'` - because
18
+ * a path can hold a user's real name and a profile body can hold a client's.
19
+ */
20
+ import { type EditableSlotId, type RedTeamPromptSlotId } from '@aragon-agent/tui/model/redteam/prompt-slots';
21
+ import type { RedTeamPromptIssue } from '@aragon-agent/tui/model/redteam/types';
22
+ import { type RedTeamPromptStoreDeps } from './prompt-store.js';
23
+ /** Where the resolved text came from; `profile` says what was CHOSEN. */
24
+ export type PromptSource = 'builtin' | 'file' | 'flag';
25
+ export interface ResolvedPrompt {
26
+ /** `'builtin'` | `'<slug>'` | `'<flag>'` | `'<path>'` - a display name, never a path. */
27
+ profile: string;
28
+ source: PromptSource;
29
+ /** Editable sections in effect. Locked sections never appear here (PF-2). */
30
+ sections: ReadonlyMap<RedTeamPromptSlotId, string>;
31
+ /** The editable slots a FILE actually replaced, in emission order. */
32
+ overridden: readonly EditableSlotId[];
33
+ /** At most two free-form sections, from the leaf only. */
34
+ extras: readonly {
35
+ title: string;
36
+ body: string;
37
+ }[];
38
+ /** Bytes read from disk; `0` when nothing was read. */
39
+ bytes: number;
40
+ /** Every file read was a cache hit. `false` for `builtin`, which reads nothing. */
41
+ fromCache: boolean;
42
+ issues: readonly RedTeamPromptIssue[];
43
+ }
44
+ export interface PromptResolveRequest {
45
+ /** `--redteam-prompt <path>`; absent when the flag was not given. */
46
+ flagPath?: string;
47
+ /** `redteam.profile`, in any of its three forms. */
48
+ profile: string;
49
+ /** Base directory for a relative flag path. */
50
+ cwd: string;
51
+ /** Injected filesystem / directories, for the tests and for a host that owns its own home. */
52
+ deps?: RedTeamPromptStoreDeps;
53
+ }
54
+ /**
55
+ * Resolve the prompt. NEVER THROWS (PF-5 / PF-9).
56
+ *
57
+ * The flag layer is tried first and falls THROUGH to the configured layer on failure, while
58
+ * the reported `profile` stays `'<flag>'`: a user who typed the flag needs to know that the
59
+ * file they named did not take effect, and they need the issue that says why.
60
+ */
61
+ export declare function resolveRedTeamPrompt(req: PromptResolveRequest): ResolvedPrompt;