@kinqs/brainrouter-cli 0.3.4

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 (87) hide show
  1. package/.env.example +109 -0
  2. package/README.md +185 -0
  3. package/dist/agent/agent.d.ts +765 -0
  4. package/dist/agent/agent.js +1977 -0
  5. package/dist/cli/cliPrompt.d.ts +15 -0
  6. package/dist/cli/cliPrompt.js +62 -0
  7. package/dist/cli/commands/_context.d.ts +53 -0
  8. package/dist/cli/commands/_context.js +14 -0
  9. package/dist/cli/commands/_helpers.d.ts +45 -0
  10. package/dist/cli/commands/_helpers.js +140 -0
  11. package/dist/cli/commands/guard.d.ts +6 -0
  12. package/dist/cli/commands/guard.js +292 -0
  13. package/dist/cli/commands/memory.d.ts +12 -0
  14. package/dist/cli/commands/memory.js +263 -0
  15. package/dist/cli/commands/obs.d.ts +6 -0
  16. package/dist/cli/commands/obs.js +208 -0
  17. package/dist/cli/commands/orchestration.d.ts +6 -0
  18. package/dist/cli/commands/orchestration.js +218 -0
  19. package/dist/cli/commands/session.d.ts +6 -0
  20. package/dist/cli/commands/session.js +191 -0
  21. package/dist/cli/commands/ui.d.ts +6 -0
  22. package/dist/cli/commands/ui.js +477 -0
  23. package/dist/cli/commands/workflow.d.ts +6 -0
  24. package/dist/cli/commands/workflow.js +691 -0
  25. package/dist/cli/repl.d.ts +12 -0
  26. package/dist/cli/repl.js +894 -0
  27. package/dist/config/config.d.ts +22 -0
  28. package/dist/config/config.js +105 -0
  29. package/dist/config/workspace.d.ts +7 -0
  30. package/dist/config/workspace.js +62 -0
  31. package/dist/index.d.ts +2 -0
  32. package/dist/index.js +610 -0
  33. package/dist/memory/briefing.d.ts +46 -0
  34. package/dist/memory/briefing.js +152 -0
  35. package/dist/memory/consolidation.d.ts +60 -0
  36. package/dist/memory/consolidation.js +208 -0
  37. package/dist/memory/formatters.d.ts +38 -0
  38. package/dist/memory/formatters.js +102 -0
  39. package/dist/memory/mentions.d.ts +10 -0
  40. package/dist/memory/mentions.js +72 -0
  41. package/dist/orchestration/orchestrator.d.ts +36 -0
  42. package/dist/orchestration/orchestrator.js +71 -0
  43. package/dist/orchestration/roles.d.ts +11 -0
  44. package/dist/orchestration/roles.js +117 -0
  45. package/dist/orchestration/tools.d.ts +244 -0
  46. package/dist/orchestration/tools.js +528 -0
  47. package/dist/prompt/breadthHint.d.ts +48 -0
  48. package/dist/prompt/breadthHint.js +93 -0
  49. package/dist/prompt/compactor.d.ts +31 -0
  50. package/dist/prompt/compactor.js +112 -0
  51. package/dist/prompt/initAgentMd.d.ts +13 -0
  52. package/dist/prompt/initAgentMd.js +194 -0
  53. package/dist/prompt/skillRunner.d.ts +34 -0
  54. package/dist/prompt/skillRunner.js +146 -0
  55. package/dist/prompt/systemPrompt.d.ts +10 -0
  56. package/dist/prompt/systemPrompt.js +171 -0
  57. package/dist/runtime/clipboard.d.ts +17 -0
  58. package/dist/runtime/clipboard.js +52 -0
  59. package/dist/runtime/llmSemaphore.d.ts +30 -0
  60. package/dist/runtime/llmSemaphore.js +67 -0
  61. package/dist/runtime/loopRunner.d.ts +25 -0
  62. package/dist/runtime/loopRunner.js +79 -0
  63. package/dist/runtime/mcpClient.d.ts +156 -0
  64. package/dist/runtime/mcpClient.js +234 -0
  65. package/dist/runtime/mcpUtils.d.ts +36 -0
  66. package/dist/runtime/mcpUtils.js +64 -0
  67. package/dist/runtime/sandbox.d.ts +48 -0
  68. package/dist/runtime/sandbox.js +156 -0
  69. package/dist/runtime/tracing.d.ts +25 -0
  70. package/dist/runtime/tracing.js +91 -0
  71. package/dist/state/cliState.d.ts +59 -0
  72. package/dist/state/cliState.js +311 -0
  73. package/dist/state/goalStore.d.ts +174 -0
  74. package/dist/state/goalStore.js +410 -0
  75. package/dist/state/hookifyStore.d.ts +80 -0
  76. package/dist/state/hookifyStore.js +237 -0
  77. package/dist/state/hooksStore.d.ts +42 -0
  78. package/dist/state/hooksStore.js +71 -0
  79. package/dist/state/preferencesStore.d.ts +41 -0
  80. package/dist/state/preferencesStore.js +25 -0
  81. package/dist/state/sessionStore.d.ts +42 -0
  82. package/dist/state/sessionStore.js +193 -0
  83. package/dist/state/taskStore.d.ts +23 -0
  84. package/dist/state/taskStore.js +80 -0
  85. package/dist/state/workflowArtifacts.d.ts +33 -0
  86. package/dist/state/workflowArtifacts.js +139 -0
  87. package/package.json +71 -0
@@ -0,0 +1,765 @@
1
+ import type { McpClientWrapper } from '../runtime/mcpClient.js';
2
+ import type { LLMConfig } from '../config/config.js';
3
+ import type { AccessMode } from '../orchestration/roles.js';
4
+ export interface RunTurnCallbacks {
5
+ onStatusUpdate: (status: string) => void;
6
+ onToolStart: (name: string, args: Record<string, any>) => void;
7
+ onToolEnd: (name: string, result: {
8
+ success: boolean;
9
+ summary: string;
10
+ preview?: string;
11
+ }) => void;
12
+ /**
13
+ * Optional: invoked whenever the agent calls update_plan during a turn,
14
+ * so the REPL can render a live ✓ / ⏳ / ☐ checklist instead of leaving the
15
+ * plan invisible until the user runs `/plan`.
16
+ */
17
+ onPlanUpdate?: (items: Array<{
18
+ step: string;
19
+ status: 'pending' | 'in_progress' | 'completed';
20
+ }>, explanation?: string) => void;
21
+ /**
22
+ * Optional: invoked when a child agent (spawn_agent) finishes its runTurn —
23
+ * either succeeded with a final answer (preview supplied) or failed (error
24
+ * supplied). Lets the REPL signal "Agent X is done" so the user isn't
25
+ * staring at silence after the tool stream stops.
26
+ */
27
+ onChildComplete?: (event: {
28
+ childId: string;
29
+ role: string;
30
+ status: 'completed' | 'failed';
31
+ preview?: string;
32
+ error?: string;
33
+ }) => void;
34
+ /**
35
+ * Optional: invoked when the agent's automatic memory pipeline runs —
36
+ * pre-turn briefing, post-turn capture, citation marking. Surfacing these
37
+ * tells the user the BrainRouter cognitive memory engine is active even
38
+ * though those MCP calls are hidden from the LLM's tool stream.
39
+ */
40
+ onMemoryEvent?: (event: MemoryEvent) => void;
41
+ }
42
+ export type MemoryEvent = {
43
+ kind: 'briefing';
44
+ sources: string[];
45
+ recordCount: number;
46
+ } | {
47
+ kind: 'capture';
48
+ sessionKey: string;
49
+ messageCount: number;
50
+ /** Number of sensory rows the MCP server wrote (raw conversation log). */
51
+ sensoryRecorded?: number;
52
+ /** True iff cognitive extraction was attempted this turn (may still have failed). */
53
+ extractionTriggered?: boolean;
54
+ /** Number of cognitive records produced — 0 indicates extraction is silently broken. */
55
+ extractedCount?: number;
56
+ /** Set when the extractor reports it couldn't reach the LLM. */
57
+ extractionWarning?: string;
58
+ } | {
59
+ kind: 'citation';
60
+ recordIds: string[];
61
+ } | {
62
+ kind: 'contradiction';
63
+ warning: string;
64
+ } | {
65
+ kind: 'skipped';
66
+ reason: string;
67
+ };
68
+ export interface ChatCompletionPayload {
69
+ model: string;
70
+ messages: any[];
71
+ tools?: Array<{
72
+ type: 'function';
73
+ function: {
74
+ name: string;
75
+ description: string;
76
+ parameters: Record<string, any>;
77
+ };
78
+ }>;
79
+ tool_choice?: 'auto';
80
+ }
81
+ export interface AgentOptions {
82
+ workspaceRoot: string;
83
+ launchCwd: string;
84
+ sessionKey?: string;
85
+ roleOverlay?: string;
86
+ accessMode?: AccessMode;
87
+ silent?: boolean;
88
+ systemPromptOverride?: string;
89
+ /** When true (default for silent children: false), pre-turn memory recall runs even in silent mode. */
90
+ enableRecall?: boolean;
91
+ /**
92
+ * Parent OTEL trace context. Set by `spawn_agent` so the child's per-turn
93
+ * spans nest under the parent's `brainrouter.turn` span. Without this each
94
+ * child started a fresh trace tree and fan-out runs flattened in trace
95
+ * viewers — you couldn't see "this child belongs to that parent turn".
96
+ */
97
+ parentTraceId?: string;
98
+ parentSpanId?: string;
99
+ }
100
+ export declare const LOCAL_TOOLS: ({
101
+ name: string;
102
+ description: string;
103
+ inputSchema: {
104
+ type: string;
105
+ properties: {};
106
+ };
107
+ } | {
108
+ name: string;
109
+ description: string;
110
+ inputSchema: {
111
+ type: string;
112
+ properties: {
113
+ path: {
114
+ type: string;
115
+ description: string;
116
+ };
117
+ startLine: {
118
+ type: string;
119
+ description: string;
120
+ };
121
+ endLine: {
122
+ type: string;
123
+ description: string;
124
+ };
125
+ content?: undefined;
126
+ targetContent?: undefined;
127
+ replacementContent?: undefined;
128
+ query?: undefined;
129
+ pattern?: undefined;
130
+ command?: undefined;
131
+ url?: undefined;
132
+ maxResults?: undefined;
133
+ patch?: undefined;
134
+ explanation?: undefined;
135
+ plan?: undefined;
136
+ proof?: undefined;
137
+ reason?: undefined;
138
+ needed?: undefined;
139
+ };
140
+ required: string[];
141
+ };
142
+ } | {
143
+ name: string;
144
+ description: string;
145
+ inputSchema: {
146
+ type: string;
147
+ properties: {
148
+ path: {
149
+ type: string;
150
+ description: string;
151
+ };
152
+ content: {
153
+ type: string;
154
+ description: string;
155
+ };
156
+ startLine?: undefined;
157
+ endLine?: undefined;
158
+ targetContent?: undefined;
159
+ replacementContent?: undefined;
160
+ query?: undefined;
161
+ pattern?: undefined;
162
+ command?: undefined;
163
+ url?: undefined;
164
+ maxResults?: undefined;
165
+ patch?: undefined;
166
+ explanation?: undefined;
167
+ plan?: undefined;
168
+ proof?: undefined;
169
+ reason?: undefined;
170
+ needed?: undefined;
171
+ };
172
+ required: string[];
173
+ };
174
+ } | {
175
+ name: string;
176
+ description: string;
177
+ inputSchema: {
178
+ type: string;
179
+ properties: {
180
+ path: {
181
+ type: string;
182
+ description: string;
183
+ };
184
+ targetContent: {
185
+ type: string;
186
+ description: string;
187
+ };
188
+ replacementContent: {
189
+ type: string;
190
+ description: string;
191
+ };
192
+ startLine?: undefined;
193
+ endLine?: undefined;
194
+ content?: undefined;
195
+ query?: undefined;
196
+ pattern?: undefined;
197
+ command?: undefined;
198
+ url?: undefined;
199
+ maxResults?: undefined;
200
+ patch?: undefined;
201
+ explanation?: undefined;
202
+ plan?: undefined;
203
+ proof?: undefined;
204
+ reason?: undefined;
205
+ needed?: undefined;
206
+ };
207
+ required: string[];
208
+ };
209
+ } | {
210
+ name: string;
211
+ description: string;
212
+ inputSchema: {
213
+ type: string;
214
+ properties: {
215
+ path: {
216
+ type: string;
217
+ description: string;
218
+ };
219
+ startLine?: undefined;
220
+ endLine?: undefined;
221
+ content?: undefined;
222
+ targetContent?: undefined;
223
+ replacementContent?: undefined;
224
+ query?: undefined;
225
+ pattern?: undefined;
226
+ command?: undefined;
227
+ url?: undefined;
228
+ maxResults?: undefined;
229
+ patch?: undefined;
230
+ explanation?: undefined;
231
+ plan?: undefined;
232
+ proof?: undefined;
233
+ reason?: undefined;
234
+ needed?: undefined;
235
+ };
236
+ required?: undefined;
237
+ };
238
+ } | {
239
+ name: string;
240
+ description: string;
241
+ inputSchema: {
242
+ type: string;
243
+ properties: {
244
+ path: {
245
+ type: string;
246
+ description: string;
247
+ };
248
+ query: {
249
+ type: string;
250
+ description: string;
251
+ };
252
+ startLine?: undefined;
253
+ endLine?: undefined;
254
+ content?: undefined;
255
+ targetContent?: undefined;
256
+ replacementContent?: undefined;
257
+ pattern?: undefined;
258
+ command?: undefined;
259
+ url?: undefined;
260
+ maxResults?: undefined;
261
+ patch?: undefined;
262
+ explanation?: undefined;
263
+ plan?: undefined;
264
+ proof?: undefined;
265
+ reason?: undefined;
266
+ needed?: undefined;
267
+ };
268
+ required: string[];
269
+ };
270
+ } | {
271
+ name: string;
272
+ description: string;
273
+ inputSchema: {
274
+ type: string;
275
+ properties: {
276
+ pattern: {
277
+ type: string;
278
+ description: string;
279
+ };
280
+ path?: undefined;
281
+ startLine?: undefined;
282
+ endLine?: undefined;
283
+ content?: undefined;
284
+ targetContent?: undefined;
285
+ replacementContent?: undefined;
286
+ query?: undefined;
287
+ command?: undefined;
288
+ url?: undefined;
289
+ maxResults?: undefined;
290
+ patch?: undefined;
291
+ explanation?: undefined;
292
+ plan?: undefined;
293
+ proof?: undefined;
294
+ reason?: undefined;
295
+ needed?: undefined;
296
+ };
297
+ required: string[];
298
+ };
299
+ } | {
300
+ name: string;
301
+ description: string;
302
+ inputSchema: {
303
+ type: string;
304
+ properties: {
305
+ command: {
306
+ type: string;
307
+ description: string;
308
+ };
309
+ path?: undefined;
310
+ startLine?: undefined;
311
+ endLine?: undefined;
312
+ content?: undefined;
313
+ targetContent?: undefined;
314
+ replacementContent?: undefined;
315
+ query?: undefined;
316
+ pattern?: undefined;
317
+ url?: undefined;
318
+ maxResults?: undefined;
319
+ patch?: undefined;
320
+ explanation?: undefined;
321
+ plan?: undefined;
322
+ proof?: undefined;
323
+ reason?: undefined;
324
+ needed?: undefined;
325
+ };
326
+ required: string[];
327
+ };
328
+ } | {
329
+ name: string;
330
+ description: string;
331
+ inputSchema: {
332
+ type: string;
333
+ properties: {
334
+ url: {
335
+ type: string;
336
+ description: string;
337
+ };
338
+ path?: undefined;
339
+ startLine?: undefined;
340
+ endLine?: undefined;
341
+ content?: undefined;
342
+ targetContent?: undefined;
343
+ replacementContent?: undefined;
344
+ query?: undefined;
345
+ pattern?: undefined;
346
+ command?: undefined;
347
+ maxResults?: undefined;
348
+ patch?: undefined;
349
+ explanation?: undefined;
350
+ plan?: undefined;
351
+ proof?: undefined;
352
+ reason?: undefined;
353
+ needed?: undefined;
354
+ };
355
+ required: string[];
356
+ };
357
+ } | {
358
+ name: string;
359
+ description: string;
360
+ inputSchema: {
361
+ type: string;
362
+ properties: {
363
+ query: {
364
+ type: string;
365
+ description: string;
366
+ };
367
+ maxResults: {
368
+ type: string;
369
+ description: string;
370
+ };
371
+ path?: undefined;
372
+ startLine?: undefined;
373
+ endLine?: undefined;
374
+ content?: undefined;
375
+ targetContent?: undefined;
376
+ replacementContent?: undefined;
377
+ pattern?: undefined;
378
+ command?: undefined;
379
+ url?: undefined;
380
+ patch?: undefined;
381
+ explanation?: undefined;
382
+ plan?: undefined;
383
+ proof?: undefined;
384
+ reason?: undefined;
385
+ needed?: undefined;
386
+ };
387
+ required: string[];
388
+ };
389
+ } | {
390
+ name: string;
391
+ description: string;
392
+ inputSchema: {
393
+ type: string;
394
+ properties: {
395
+ patch: {
396
+ type: string;
397
+ description: string;
398
+ };
399
+ path?: undefined;
400
+ startLine?: undefined;
401
+ endLine?: undefined;
402
+ content?: undefined;
403
+ targetContent?: undefined;
404
+ replacementContent?: undefined;
405
+ query?: undefined;
406
+ pattern?: undefined;
407
+ command?: undefined;
408
+ url?: undefined;
409
+ maxResults?: undefined;
410
+ explanation?: undefined;
411
+ plan?: undefined;
412
+ proof?: undefined;
413
+ reason?: undefined;
414
+ needed?: undefined;
415
+ };
416
+ required: string[];
417
+ };
418
+ } | {
419
+ name: string;
420
+ description: string;
421
+ inputSchema: {
422
+ type: string;
423
+ properties: {
424
+ explanation: {
425
+ type: string;
426
+ description: string;
427
+ };
428
+ plan: {
429
+ type: string;
430
+ description: string;
431
+ items: {
432
+ type: string;
433
+ properties: {
434
+ step: {
435
+ type: string;
436
+ };
437
+ status: {
438
+ type: string;
439
+ enum: string[];
440
+ };
441
+ };
442
+ required: string[];
443
+ };
444
+ };
445
+ path?: undefined;
446
+ startLine?: undefined;
447
+ endLine?: undefined;
448
+ content?: undefined;
449
+ targetContent?: undefined;
450
+ replacementContent?: undefined;
451
+ query?: undefined;
452
+ pattern?: undefined;
453
+ command?: undefined;
454
+ url?: undefined;
455
+ maxResults?: undefined;
456
+ patch?: undefined;
457
+ proof?: undefined;
458
+ reason?: undefined;
459
+ needed?: undefined;
460
+ };
461
+ required: string[];
462
+ };
463
+ } | {
464
+ name: string;
465
+ description: string;
466
+ inputSchema: {
467
+ type: string;
468
+ properties: {
469
+ proof: {
470
+ type: string;
471
+ description: string;
472
+ };
473
+ path?: undefined;
474
+ startLine?: undefined;
475
+ endLine?: undefined;
476
+ content?: undefined;
477
+ targetContent?: undefined;
478
+ replacementContent?: undefined;
479
+ query?: undefined;
480
+ pattern?: undefined;
481
+ command?: undefined;
482
+ url?: undefined;
483
+ maxResults?: undefined;
484
+ patch?: undefined;
485
+ explanation?: undefined;
486
+ plan?: undefined;
487
+ reason?: undefined;
488
+ needed?: undefined;
489
+ };
490
+ required: string[];
491
+ };
492
+ } | {
493
+ name: string;
494
+ description: string;
495
+ inputSchema: {
496
+ type: string;
497
+ properties: {
498
+ reason: {
499
+ type: string;
500
+ description: string;
501
+ };
502
+ needed: {
503
+ type: string;
504
+ description: string;
505
+ };
506
+ path?: undefined;
507
+ startLine?: undefined;
508
+ endLine?: undefined;
509
+ content?: undefined;
510
+ targetContent?: undefined;
511
+ replacementContent?: undefined;
512
+ query?: undefined;
513
+ pattern?: undefined;
514
+ command?: undefined;
515
+ url?: undefined;
516
+ maxResults?: undefined;
517
+ patch?: undefined;
518
+ explanation?: undefined;
519
+ plan?: undefined;
520
+ proof?: undefined;
521
+ };
522
+ required: string[];
523
+ };
524
+ })[];
525
+ /**
526
+ * @deprecated Prefer passing an explicit workspaceRoot. Returns process.cwd()
527
+ * which is brittle when the Agent was constructed with a workspace different
528
+ * from cwd (e.g. when /resume re-attaches a session originally captured in
529
+ * another dir, or when the user cd's away after launch).
530
+ */
531
+ export declare function getWorkspaceRoot(): string;
532
+ /**
533
+ * Best-effort guidance for the LLM when it calls a tool name that doesn't
534
+ * exist (JSON-RPC -32601). The most common cause is confusing a BrainRouter
535
+ * skill (documentation) for an invocable tool. Pattern-match on the name and
536
+ * return a corrective hint that the next agent turn will see as the tool
537
+ * result.
538
+ */
539
+ export declare function explainUnknownToolName(name: string): string;
540
+ /**
541
+ * Normalize a tool name the LLM emitted into the canonical form used by the
542
+ * tool registry. Handles common variants: case (`Read_File`), separators
543
+ * (`read-file`, `read.file`), surrounding whitespace, and a short list of
544
+ * cross-vendor aliases (`Bash` → `run_command`).
545
+ *
546
+ * Returns the exact canonical name if a unique match is found among the
547
+ * provided candidates; otherwise returns the trimmed input (so the regular
548
+ * dispatch/explainUnknownToolName path still runs).
549
+ */
550
+ export declare function normalizeToolName(raw: string, candidates: string[]): string;
551
+ export declare function isPathInside(parent: string, candidate: string): boolean;
552
+ /**
553
+ * Resolve a workspace-relative path against the given workspaceRoot. Throws
554
+ * if the result escapes the workspace.
555
+ *
556
+ * `workspaceRoot` is REQUIRED — passing a stale `process.cwd()` was the bug
557
+ * that let tool writes land in `~/.brainrouter` when the user's cwd drifted.
558
+ *
559
+ * For backwards compatibility, the workspaceRoot parameter may be omitted; it
560
+ * then falls back to process.cwd(). New code should always pass it explicitly.
561
+ */
562
+ export declare function resolveWorkspacePath(workspaceRootOrPath?: string, inputPathOrOptions?: string | {
563
+ forWrite?: boolean;
564
+ }, maybeOptions?: {
565
+ forWrite?: boolean;
566
+ }): string;
567
+ export declare class Agent {
568
+ private mcpClient;
569
+ private llmConfig;
570
+ sessionKey: string;
571
+ workspaceRoot: string;
572
+ launchCwd: string;
573
+ private chatHistory;
574
+ private initialized;
575
+ private recalledRecordIds;
576
+ private recalledRecords;
577
+ private lastBriefingSources;
578
+ private roleOverlay?;
579
+ private accessMode;
580
+ private silent;
581
+ private enableRecall;
582
+ private systemPromptOverride?;
583
+ /**
584
+ * Name of the BrainRouter skill currently being executed (e.g. via `/skill`
585
+ * or implicit memetic activation). Threaded into `memory_recall` and
586
+ * `memory_capture_turn` so skill-scoped recall boost, neural-spark
587
+ * prewarming, and per-record `skill_tag` extraction all fire correctly.
588
+ * Null/undefined when no skill is active.
589
+ */
590
+ activeSkill?: string;
591
+ /**
592
+ * Parent trace context (set by spawn_agent for child agents). When present,
593
+ * the per-turn span uses these as its trace/parent so OTEL viewers can
594
+ * stitch the fan-out tree together. Top-level (REPL) agents leave these
595
+ * undefined and get a fresh trace per turn.
596
+ */
597
+ private parentTraceId?;
598
+ private parentSpanId?;
599
+ /**
600
+ * Synthetic agent id used in OTEL attributes so child spans can be grouped
601
+ * even without trace links. Equals `agent-<6 random hex>` per Agent
602
+ * instance. Surfaced as the `agent_id` / `parent_agent_id` span attrs.
603
+ */
604
+ readonly agentId: string;
605
+ /** agent_id of the parent (set by spawn_agent for children). */
606
+ private parentAgentId?;
607
+ constructor(mcpClient: McpClientWrapper, llmConfig: LLMConfig, options: AgentOptions);
608
+ /** Expose for orchestration so spawn_agent can record the parent linkage. */
609
+ getAgentId(): string;
610
+ /** Internal — used by spawn_agent to record which parent dispatched us. */
611
+ setParentAgentId(id: string | undefined): void;
612
+ private allowedToolsForAccess;
613
+ runTurn(prompt: string, callbacks: RunTurnCallbacks): Promise<string>;
614
+ /** Rough token estimate (1 token ≈ 4 characters of English / code). */
615
+ static estimateTokens(text: string): number;
616
+ private executeLocalTool;
617
+ clearHistory(): void;
618
+ /**
619
+ * Compaction for /compact: summarize current chat history via the LLM,
620
+ * then replace the verbose log with [system, compactedSummary,
621
+ * lastUserMessage]. Returns the summary so the REPL can display it.
622
+ */
623
+ compactHistory(): Promise<{
624
+ summary: string;
625
+ estimatedTokens: number;
626
+ durationMs: number;
627
+ replacedMessages: number;
628
+ } | null>;
629
+ /** Runtime model switch. Used by `/model` slash command. */
630
+ setModel(model: string): void;
631
+ getModel(): string;
632
+ /** Runtime access-mode cycle for `/permissions` and Shift+Tab plan-mode toggle. */
633
+ getAccessMode(): AccessMode;
634
+ setAccessMode(mode: AccessMode): void;
635
+ /**
636
+ * Seed the chat history from a persisted transcript so the user can resume
637
+ * a previous session. The system message is regenerated for the current
638
+ * runtime so workspace/session context is fresh, but the user/assistant/tool
639
+ * messages are kept verbatim.
640
+ */
641
+ loadHistory(entries: Array<{
642
+ role: string;
643
+ content?: unknown;
644
+ name?: string;
645
+ tool_call_id?: string;
646
+ tool_calls?: unknown;
647
+ }>): number;
648
+ /** Cumulative token usage across the last runTurn. Cleared at each new turn. */
649
+ lastTurnUsage: {
650
+ promptTokens: number;
651
+ completionTokens: number;
652
+ calls: number;
653
+ };
654
+ /** Cumulative token usage across the WHOLE CLI session (all turns). */
655
+ sessionUsage: {
656
+ promptTokens: number;
657
+ completionTokens: number;
658
+ calls: number;
659
+ turns: number;
660
+ };
661
+ /**
662
+ * Memory-derived savings counters. These let `/tokens` produce a "memory
663
+ * saved you ~N tokens" narrative the user can actually point at.
664
+ *
665
+ * - briefingTokensInjected: approx tokens added to context as memory
666
+ * briefings (recall + persona + scenes + recency). Each briefing
667
+ * provides cross-session context that would otherwise require re-reading
668
+ * files or re-explaining via prompts.
669
+ * - offloadCharsAvoided: chars of child-agent output that were pushed
670
+ * to working memory instead of pasted back into parent context.
671
+ * - recallRecordsConsulted: count of memory record references the
672
+ * briefing put in front of the model this session.
673
+ */
674
+ memoryMetrics: {
675
+ briefingTokensInjected: number;
676
+ offloadCharsAvoided: number;
677
+ recallRecordsConsulted: number;
678
+ };
679
+ /** Last assistant message of the most recent turn — used by `/copy`. */
680
+ lastAnswer: string;
681
+ /** Last user prompt (post-mention-expansion). Used by `/continue` to resume after a loop-limit abort. */
682
+ lastUserPrompt: string;
683
+ /** True when the most recent turn hit the loop-limit ceiling before producing a final answer. */
684
+ lastTurnHitLoopLimit: boolean;
685
+ /** Count of tool calls executed during the most recent runTurn. The goal */
686
+ /** continuation loop uses this to suppress auto-continuation after prose-only turns. */
687
+ lastTurnToolCalls: number;
688
+ /** Goal lifecycle transition the LLM triggered during the most recent turn, if any. */
689
+ lastGoalTransition: 'complete' | 'blocked' | undefined;
690
+ /** Allow REPL slash commands to refresh the system prompt without bumping a new turn. */
691
+ refreshSystemPrompt(): void;
692
+ /**
693
+ * Push (or replace) a tagged system message in `chatHistory`. Per-turn
694
+ * directives like the briefing block and the fan-out hint used to be pushed
695
+ * unconditionally — each turn added a fresh copy without removing the prior
696
+ * one, so a 10-turn conversation carried 10 stacked briefings. This helper
697
+ * removes any older entry with the same tag before appending the new one,
698
+ * keeping the model's view of "current memory state" current.
699
+ */
700
+ replaceTaggedSystemMessage(tag: string, content: string): void;
701
+ /**
702
+ * Drop any system message previously installed under `tag`. Used to retract
703
+ * one-off directives once the condition that motivated them no longer
704
+ * holds — e.g. the budget-steering "wrap up gracefully" message must
705
+ * disappear after the user extends the goal's budget, otherwise it keeps
706
+ * telling the model "this is your last turn" for every subsequent turn.
707
+ *
708
+ * Idempotent: calling this with a tag that isn't present is a no-op.
709
+ */
710
+ removeTaggedSystemMessage(tag: string): void;
711
+ /** Fork the current chat history into a fresh sessionKey. Returns the new key. */
712
+ fork(newSessionKey: string): string;
713
+ private bootstrapSession;
714
+ private createSystemMessage;
715
+ private injectRecallContext;
716
+ /** Inspectable summary of the most recent memory briefing. Used by the `/briefing` slash command. */
717
+ getLastBriefing(): {
718
+ sources: string[];
719
+ recordIds: string[];
720
+ };
721
+ /** One-line summary of any new contradiction surfaced after the last capture, or undefined if none. */
722
+ private lastContradictionWarning?;
723
+ takeContradictionWarning(): string | undefined;
724
+ private checkContradictions;
725
+ private captureTurn;
726
+ private recordTranscript;
727
+ }
728
+ /**
729
+ * Apply a Begin/End-envelope patch:
730
+ *
731
+ * *** Begin Patch
732
+ * *** Update File: path/relative/to/workspace
733
+ * @@ optional context anchor
734
+ * -old line
735
+ * +new line
736
+ * unchanged line
737
+ * *** Add File: another/path
738
+ * +line 1
739
+ * +line 2
740
+ * *** Delete File: third/path
741
+ * *** End Patch
742
+ *
743
+ * Returns a JSON summary of operations performed; throws on a malformed envelope
744
+ * or when an Update fails to match its context block uniquely.
745
+ */
746
+ export declare function applyPatchEnvelope(patch: string, workspaceRoot?: string): string;
747
+ export declare function matchGlob(pattern: string, filePath: string): boolean;
748
+ export declare function globFiles(pattern: string, workspaceRoot?: string, dir?: string): string[];
749
+ export declare function getToolSummary(name: string, args: Record<string, any>, result: string): string;
750
+ /**
751
+ * Optional inline preview for inspection-style tools. The REPL renders this
752
+ * indented below the one-line summary so the user can SEE the result even if
753
+ * the LLM forgets to echo it in its reply. Limited to a handful of tools where
754
+ * the result is concise and the user's intent is almost always "show me this":
755
+ * `list_dir`, `grep_search`, `glob_files`. Other tools (read_file, run_command)
756
+ * fire too often as internal exploration steps — previewing them would flood
757
+ * the terminal. Returns undefined when no useful preview is available.
758
+ */
759
+ export declare function getToolPreview(name: string, args: Record<string, any>, result: string): string | undefined;
760
+ export declare function buildChatCompletionPayload(config: LLMConfig, messages: any[], tools: any[]): ChatCompletionPayload;
761
+ export declare function callOpenAI(config: LLMConfig, messages: any[], tools: any[]): Promise<{
762
+ content: any;
763
+ toolCalls: any;
764
+ usage: any;
765
+ }>;