pal-code 0.0.9 → 0.0.11

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 (47) hide show
  1. package/README.md +3 -3
  2. package/SYSTEM.md +3 -3
  3. package/bin/pal-code.js +37 -11
  4. package/package.json +7 -14
  5. package/packages/cli/README.md +2 -2
  6. package/packages/cli/src/commands/ext.ts +1 -1
  7. package/packages/cli/src/commands.ts +1 -1
  8. package/packages/cli/src/components/render-history.ts +2 -2
  9. package/packages/cli/src/config.ts +2 -2
  10. package/packages/cli/src/index.ts +7 -7
  11. package/packages/cli/src/overlays/key-input.ts +1 -1
  12. package/packages/cli/src/overlays/model-picker.ts +2 -2
  13. package/packages/cli/src/overlays/session-picker.ts +1 -1
  14. package/packages/cli/src/overlays/wizard.ts +1 -1
  15. package/packages/cli/src/state.ts +2 -2
  16. package/packages/cli/src/turn.ts +16 -9
  17. package/packages/cli/src/utils/permissions.ts +3 -3
  18. package/packages/core/src/agent/events.ts +0 -36
  19. package/packages/core/src/agent/fallback.ts +0 -344
  20. package/packages/core/src/agent/index.ts +0 -35
  21. package/packages/core/src/agent/roles.ts +0 -188
  22. package/packages/core/src/agent/run.ts +0 -713
  23. package/packages/core/src/agent/scope.ts +0 -34
  24. package/packages/core/src/agent/todos.ts +0 -66
  25. package/packages/core/src/compaction.ts +0 -243
  26. package/packages/core/src/config.ts +0 -387
  27. package/packages/core/src/extensions.ts +0 -178
  28. package/packages/core/src/index.ts +0 -157
  29. package/packages/core/src/logger.ts +0 -54
  30. package/packages/core/src/provider/auth.ts +0 -153
  31. package/packages/core/src/provider/complete.ts +0 -63
  32. package/packages/core/src/provider/index.ts +0 -6
  33. package/packages/core/src/provider/openrouter.ts +0 -304
  34. package/packages/core/src/provider/pick-model.ts +0 -43
  35. package/packages/core/src/provider/registry.ts +0 -222
  36. package/packages/core/src/provider/types.ts +0 -61
  37. package/packages/core/src/repo-map.ts +0 -177
  38. package/packages/core/src/session/index.ts +0 -2
  39. package/packages/core/src/session/store.ts +0 -677
  40. package/packages/core/src/session/types.ts +0 -72
  41. package/packages/core/src/snapshots.ts +0 -107
  42. package/packages/core/src/tools/definitions.ts +0 -365
  43. package/packages/core/src/tools/executor.ts +0 -1363
  44. package/packages/core/src/tools/index.ts +0 -5
  45. package/packages/core/src/tools/search.ts +0 -201
  46. package/scripts/postinstall.js +0 -121
  47. package/scripts/preinstall.js +0 -51
package/README.md CHANGED
@@ -74,8 +74,8 @@ key (or press Enter for a keyless provider like OpenCode Zen).
74
74
  Install extensions from any directory:
75
75
 
76
76
  ```bash
77
- pal add @pal/web-search # Web search tools (fetch_url, web_search)
78
- pal add @pal/agents # Multi-agent orchestration (delegate, explore, etc.)
77
+ pal add @pal-code/web-search # Web search tools (fetch_url, web_search)
78
+ pal add @pal-code/agents # Multi-agent orchestration (delegate, explore, etc.)
79
79
  ```
80
80
 
81
81
  Extensions are installed to `~/.pal/extensions/` and persist across sessions.
@@ -135,7 +135,7 @@ All user data lives in `~/.pal/`:
135
135
 
136
136
  ## Architecture
137
137
 
138
- **Logic lives in `@pal/core`; rendering lives in `@pal/cli`.**
138
+ **Logic lives in `@pal-code/core`; rendering lives in `@pal-code/cli`.**
139
139
 
140
140
  The one agent loop (`runAgent`) lives in core and streams events; the CLI only
141
141
  renders them. Full rules, the event protocol, and the termination/interrupt
package/SYSTEM.md CHANGED
@@ -4,12 +4,12 @@ How pal is put together, and the rules that keep it that way.
4
4
 
5
5
  ## The boundary rule
6
6
 
7
- **Logic lives in `@pal/core`. Rendering lives in `@pal/cli`.**
7
+ **Logic lives in `@pal-code/core`. Rendering lives in `@pal-code/cli`.**
8
8
 
9
9
  This is the single most important rule in the codebase. Every capability has
10
10
  exactly one home, and the split is by *responsibility*, not convenience:
11
11
 
12
- | Lives in `@pal/core` | Lives in `@pal/cli` |
12
+ | Lives in `@pal-code/core` | Lives in `@pal-code/cli` |
13
13
  |---|---|
14
14
  | The agent loop (`runAgent`) | The pi-tui `RunView`, todo panel, status bar |
15
15
  | Tool implementations + `executeTool` | Slash-command parsing and command output |
@@ -22,7 +22,7 @@ Consequences:
22
22
 
23
23
  - A front-end **must never reimplement engine behaviour**. If two front-ends
24
24
  would both need it, it belongs in core.
25
- - Core **must never import a TUI**. `@pal/core` has no knowledge of pi-tui.
25
+ - Core **must never import a TUI**. `@pal-code/core` has no knowledge of pi-tui.
26
26
  - The **only vocabulary** between the layers is the event stream below.
27
27
 
28
28
  If you are unsure where something goes, ask: *does this decide what the agent
package/bin/pal-code.js CHANGED
@@ -76,22 +76,48 @@ function findBinary() {
76
76
  return distBin;
77
77
  }
78
78
 
79
- // Fallback: check if bun is available and run source directly
79
+ // Fallback: run the bundled TypeScript source under Bun. No prebuilt binary
80
+ // is published for this platform (yet), so this is the normal path.
80
81
  const { execSync } = require('child_process');
82
+ const srcPath = join(__dirname, '../packages/cli/src/index.ts');
83
+
84
+ let bunVersion = null;
81
85
  try {
82
- execSync('bun --version', { stdio: 'ignore' });
83
- const srcPath = join(__dirname, '../packages/cli/src/index.ts');
84
- if (existsSync(srcPath)) {
85
- console.error('pal-code: Using Bun runtime (binary not found, falling back to source)');
86
- return 'bun';
87
- }
88
- } catch (e) {
89
- // Bun not available
86
+ bunVersion = execSync('bun --version', { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] })
87
+ .toString()
88
+ .trim();
89
+ } catch {
90
+ // Bun not installed, or not on PATH.
91
+ }
92
+
93
+ if (bunVersion && existsSync(srcPath)) {
94
+ console.error(`pal-code: running from source with Bun ${bunVersion}`);
95
+ return 'bun';
96
+ }
97
+
98
+ // No usable runtime. Report the actionable cause: a missing Bun, not a
99
+ // corrupt install. (This replaces the old preinstall/postinstall hooks, which
100
+ // npm and Bun increasingly refuse to run — Bun blocks them until the package
101
+ // is trusted, and warns on every install.)
102
+ if (!bunVersion) {
103
+ console.error('');
104
+ console.error(' pal-code requires Bun — it was not found on your PATH.');
105
+ console.error('');
106
+ console.error(' macOS / Linux:');
107
+ console.error(' curl -fsSL https://bun.sh/install | bash');
108
+ console.error('');
109
+ console.error(' Windows (PowerShell):');
110
+ console.error(' powershell -c "irm bun.sh/install.ps1 | iex"');
111
+ console.error('');
112
+ console.error(' Then run: pal');
113
+ console.error('');
114
+ console.error(' https://bun.sh');
115
+ console.error('');
116
+ process.exit(1);
90
117
  }
91
118
 
92
- console.error('Error: pal binary not found.');
119
+ console.error('Error: pal binary not found for this platform.');
93
120
  console.error('Please reinstall: npm install -g pal-code');
94
- console.error('Or install Bun and run from source: bun add -g pal-code');
95
121
  process.exit(1);
96
122
  }
97
123
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pal-code",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "A terminal coding agent with BYOK, tool use, and extensions",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -11,23 +11,17 @@
11
11
  ],
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "https://github.com/fngadiyo/the-agent.git"
14
+ "url": "git+https://github.com/fngadiyo/the-agent.git"
15
15
  },
16
16
  "bin": {
17
- "pal": "./bin/pal-code.js"
17
+ "pal": "bin/pal-code.js"
18
18
  },
19
19
  "files": [
20
20
  "bin/",
21
- "scripts/postinstall.js",
22
- "scripts/preinstall.js",
23
21
  "packages/cli/src/**/*.ts",
24
22
  "packages/cli/src/**/*.tsx",
25
- "packages/core/src/**/*.ts",
26
- "packages/core/src/**/*.tsx",
27
23
  "!**/*.test.ts",
28
24
  "!**/*.test.js",
29
- "!packages/core/src/**/*.test.db",
30
- "!packages/core/src/**/*.test-*.db",
31
25
  "SYSTEM.md",
32
26
  "README.md",
33
27
  "LICENSE"
@@ -47,12 +41,11 @@
47
41
  "build:linux-x64": "bun build --compile packages/cli/src/index.ts --target=bun-linux-x64 --outfile dist/pal-linux-x64",
48
42
  "build:linux-arm64": "bun build --compile packages/cli/src/index.ts --target=bun-linux-arm64 --outfile dist/pal-linux-arm64",
49
43
  "build:windows-x64": "bun build --compile packages/cli/src/index.ts --target=bun-windows-x64 --outfile dist/pal-windows-x64.exe",
50
- "publish:all": "npm publish && npm run publish:web-search && npm run publish:agents && npm run publish:mcp",
44
+ "publish:all": "npm run publish:core && npm publish && npm run publish:web-search && npm run publish:agents && npm run publish:mcp",
45
+ "publish:core": "cd packages/core && npm publish",
51
46
  "publish:web-search": "cd packages/web-search && npm publish",
52
47
  "publish:agents": "cd packages/agents && npm publish",
53
48
  "publish:mcp": "cd packages/mcp && npm publish",
54
- "preinstall": "node scripts/preinstall.js",
55
- "postinstall": "node scripts/postinstall.js",
56
49
  "prepublishOnly": "node scripts/sync-version.js"
57
50
  },
58
51
  "keywords": [
@@ -68,8 +61,8 @@
68
61
  "gemini"
69
62
  ],
70
63
  "dependencies": {
71
- "@earendil-works/pi-tui": "^0.85.1",
72
- "cheerio": "^1.0.0"
64
+ "@pal-code/core": "0.0.11",
65
+ "@earendil-works/pi-tui": "^0.85.1"
73
66
  },
74
67
  "devDependencies": {
75
68
  "@biomejs/biome": "^2.5.13",
@@ -1,8 +1,8 @@
1
- # @pal/cli
1
+ # @pal-code/cli
2
2
 
3
3
  Terminal UI for the [pal](../..) coding agent. This package provides the TUI
4
4
  interface — streaming markdown display, editor, model picker, session selector,
5
- and live status line — while [`@pal/core`](../core) supplies the provider
5
+ and live status line — while [`@pal-code/core`](../core) supplies the provider
6
6
  abstraction, session store, agent loop, and tools.
7
7
 
8
8
  ## Quick start
@@ -10,7 +10,7 @@ import {homedir} from 'node:os';
10
10
  import {join} from 'node:path';
11
11
  import {existsSync, mkdirSync, readFileSync, writeFileSync} from 'node:fs';
12
12
  import {execSync} from 'node:child_process';
13
- import {readPalConfig, saveSetting} from '@pal/core';
13
+ import {readPalConfig, saveSetting} from '@pal-code/core';
14
14
 
15
15
  const EXTENSIONS_DIR = join(homedir(), '.pal', 'extensions');
16
16
 
@@ -10,7 +10,7 @@ import type {TUI, Container} from '@earendil-works/pi-tui';
10
10
 
11
11
  import {c} from './theme.js';
12
12
  import {formatTokens, formatCost} from './utils/cost.js';
13
- import {isDebugEnabled} from '@pal/core';
13
+ import {isDebugEnabled} from '@pal-code/core';
14
14
 
15
15
  export function cmdHelp(container: Container, tui: TUI): void {
16
16
  container.addChild(new Text('', 0, 0));
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * renderHistory — replay a stored session transcript into the message area.
3
3
  *
4
- * Sessions are stored as an append-only, normalized log (see @pal/core's
4
+ * Sessions are stored as an append-only, normalized log (see @pal-code/core's
5
5
  * SessionStore), so resuming can show everything the user saw: user boxes,
6
6
  * assistant answers, tool activity, and a seam marker at each compaction
7
7
  * checkpoint. The model view is built separately; this is purely for the human.
@@ -11,7 +11,7 @@
11
11
  */
12
12
 
13
13
  import {Container, Text, Markdown} from '@earendil-works/pi-tui';
14
- import type {StoredMessage, CompactionRecord} from '@pal/core';
14
+ import type {StoredMessage, CompactionRecord} from '@pal-code/core';
15
15
 
16
16
  import {c, markdownTheme} from '../theme.js';
17
17
  import {MessageBox} from './message-box.js';
@@ -7,8 +7,8 @@
7
7
  * context limit).
8
8
  */
9
9
 
10
- import {readPalConfig, loadPermissionConfig} from '@pal/core';
11
- import type {PermissionConfig} from '@pal/core';
10
+ import {readPalConfig, loadPermissionConfig} from '@pal-code/core';
11
+ import type {PermissionConfig} from '@pal-code/core';
12
12
 
13
13
  export interface Config {
14
14
  model: string;
@@ -68,20 +68,20 @@ import {
68
68
  resolvePrimary,
69
69
  defaultPrimaryName,
70
70
  resolveProjectRoot,
71
- } from '@pal/core';
72
- import type {Provider, ConversationMessage as Message} from '@pal/core';
71
+ } from '@pal-code/core';
72
+ import type {Provider, ConversationMessage as Message} from '@pal-code/core';
73
73
  // SessionStore deferred — bun:sqlite import may break pi-tui stdin
74
- import type {SessionStore as SessionStoreType} from '@pal/core';
74
+ import type {SessionStore as SessionStoreType} from '@pal-code/core';
75
75
 
76
76
  // ═══════════════════════════════════════════════════════════════════════════════
77
77
  // Config
78
78
  // ═══════════════════════════════════════════════════════════════════════════════
79
79
 
80
80
  // Model lists are now resolved dynamically from each provider's /models endpoint
81
- // (see buildModelOptions). Static curated lists live in @pal/core PROVIDERS as fallback.
81
+ // (see buildModelOptions). Static curated lists live in @pal-code/core PROVIDERS as fallback.
82
82
 
83
83
  // Version synced from version.json via `node scripts/sync-version.js`.
84
- const VERSION = '0.0.9';
84
+ const VERSION = '0.0.11';
85
85
 
86
86
  import {showModelSelector} from './overlays/model-picker.js';
87
87
  import {showKeyInput} from './overlays/key-input.js';
@@ -96,7 +96,7 @@ async function main() {
96
96
  // Fast exit for version flags (no config/project root needed)
97
97
  const flag = process.argv[2];
98
98
  if (flag === '--version' || flag === '--v' || flag === '-v' || flag === '-version') {
99
- console.log(`pal-code v${pkg.version}`);
99
+ console.log(`pal-code v${VERSION}`);
100
100
  process.exit(0);
101
101
  }
102
102
 
@@ -1572,7 +1572,7 @@ async function main() {
1572
1572
  ensureExtensionsLoaded(config.extensions).catch(() => {});
1573
1573
 
1574
1574
  // Initialize session store AFTER tui starts (bun:sqlite import must not run before pi-tui stdin setup)
1575
- const {SessionStore} = await import('@pal/core');
1575
+ const {SessionStore} = await import('@pal-code/core');
1576
1576
  store = new SessionStore();
1577
1577
  store.init();
1578
1578
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  import {Text, Input} from '@earendil-works/pi-tui';
4
4
  import type {TUI, Container, Editor} from '@earendil-works/pi-tui';
5
- import {PROVIDERS, detectProvider, saveKey, saveSetting} from '@pal/core';
5
+ import {PROVIDERS, detectProvider, saveKey, saveSetting} from '@pal-code/core';
6
6
  import type {Config} from '../config.js';
7
7
 
8
8
  import {c} from '../theme.js';
@@ -2,8 +2,8 @@
2
2
 
3
3
  import {Text, SelectList} from '@earendil-works/pi-tui';
4
4
  import type {TUI, Container, Editor, SelectItem} from '@earendil-works/pi-tui';
5
- import {PROVIDERS, resolveModelIds, saveSetting} from '@pal/core';
6
- import type {Provider, ProviderKeys} from '@pal/core';
5
+ import {PROVIDERS, resolveModelIds, saveSetting} from '@pal-code/core';
6
+ import type {Provider, ProviderKeys} from '@pal-code/core';
7
7
 
8
8
  import {c} from '../theme.js';
9
9
  import {state} from '../state.js';
@@ -10,7 +10,7 @@ import type {TUI, Container, Editor, SelectItem} from '@earendil-works/pi-tui';
10
10
 
11
11
  import {c} from '../theme.js';
12
12
  import {truncate} from '../utils/format.js';
13
- import type {ConversationMessage as Message, Session, SessionStore} from '@pal/core';
13
+ import type {ConversationMessage as Message, Session, SessionStore} from '@pal-code/core';
14
14
 
15
15
  export function groupByDate(sessions: readonly Session[]): Map<string, Session[]> {
16
16
  const now = new Date();
@@ -6,7 +6,7 @@
6
6
  * lets the wizard run without entering raw mode.
7
7
  */
8
8
 
9
- import {PROVIDERS, detectProvider, saveKey, saveSetting, configPath} from '@pal/core';
9
+ import {PROVIDERS, detectProvider, saveKey, saveSetting, configPath} from '@pal-code/core';
10
10
 
11
11
  import {c} from '../theme.js';
12
12
 
@@ -13,7 +13,7 @@
13
13
  * import site).
14
14
  *
15
15
  * Only *presentation* state lives here. Anything that decides what the agent
16
- * does belongs in `@pal/core` (see SYSTEM.md).
16
+ * does belongs in `@pal-code/core` (see SYSTEM.md).
17
17
  */
18
18
 
19
19
  import type {RunView} from './components/run-view.js';
@@ -26,7 +26,7 @@ export type OverlayMode = 'none' | 'model-select' | 'key-input' | 'agents' | 'pe
26
26
  * Tab). Populated from the orchestration extension at load time; defaults to
27
27
  * 'pal' (the orchestrator) when no extension provides primaries.
28
28
  *
29
- * Not to be confused with a delegation role — see `@pal/core`'s `PrimarySpec`.
29
+ * Not to be confused with a delegation role — see `@pal-code/core`'s `PrimarySpec`.
30
30
  */
31
31
  export type AgentRole = string;
32
32
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * One agent turn: drive `runWithFallback` and translate its events into
3
- * RunView calls. The reliability policy itself lives in @pal/core.
3
+ * RunView calls. The reliability policy itself lives in @pal-code/core.
4
4
  */
5
5
 
6
6
  import {
@@ -9,6 +9,7 @@ import {
9
9
  executeTool,
10
10
  registerExtensionHandlers,
11
11
  loadExtensions,
12
+ resolveExtensionSpecifier,
12
13
  runWithFallback,
13
14
  shortModel,
14
15
  buildRolesPrompt,
@@ -19,7 +20,7 @@ import {
19
20
  type ProviderKeys,
20
21
  type ConversationMessage as Message,
21
22
  type ToolResult,
22
- } from '@pal/core';
23
+ } from '@pal-code/core';
23
24
  import type {TUI, Container} from '@earendil-works/pi-tui';
24
25
 
25
26
  import type {Config} from './config.js';
@@ -50,8 +51,8 @@ async function applyLoaded(
50
51
  requested: string[],
51
52
  loaded: string[],
52
53
  failed: Array<{pkg: string; reason: string}>,
53
- tools: import('@pal/core').ToolDef[],
54
- handlers: Record<string, import('@pal/core').ToolHandler>,
54
+ tools: import('@pal-code/core').ToolDef[],
55
+ handlers: Record<string, import('@pal-code/core').ToolHandler>,
55
56
  ): Promise<void> {
56
57
  registerExtensionHandlers(handlers);
57
58
  registerExtensionTools(tools);
@@ -59,14 +60,18 @@ async function applyLoaded(
59
60
  const active = new Set(loaded);
60
61
  const failedByPkg = new Map(failed.map((f) => [f.pkg, f.reason]));
61
62
  state.extensions = requested.map((pkg) => ({
62
- name: pkg.replace(/^@pal\//, ''),
63
+ name: pkg.replace(/^@pal-code\//, ''),
63
64
  active: active.has(pkg),
64
65
  reason: failedByPkg.get(pkg),
65
66
  }));
66
67
 
67
- // Populate MCP server status for the sidebar (live from manager)
68
+ // Populate MCP server status for the sidebar (live from manager).
69
+ //
70
+ // Resolved through core rather than a bare import: `pal add` installs the
71
+ // extension under ~/.pal/extensions/node_modules, which a plain
72
+ // `import('@pal-code/mcp')` from here would not search.
68
73
  try {
69
- const mcpMod = await import('@pal-code/mcp').catch(() => null);
74
+ const mcpMod = await import(resolveExtensionSpecifier('@pal-code/mcp')).catch(() => null);
70
75
  if (mcpMod?.mcpManager) {
71
76
  state.mcpServers = mcpMod.mcpManager.getServerDetails();
72
77
  state.refreshSidebar();
@@ -99,7 +104,7 @@ export async function ensureExtensionsLoaded(extensions?: string[]): Promise<voi
99
104
  * Re-import extensions without restarting pal. Called by `/reload`.
100
105
  *
101
106
  * Uses the loader's `cacheBust` option so edited extension source is picked up.
102
- * `@pal/core` is not re-imported, so a re-registered role provider lands in the
107
+ * `@pal-code/core` is not re-imported, so a re-registered role provider lands in the
103
108
  * one registry core already holds.
104
109
  */
105
110
  export async function reloadExtensions(extensions?: string[]): Promise<number> {
@@ -129,7 +134,7 @@ function composeSystemPrompt(base: string, primaryName?: string): string {
129
134
  }
130
135
 
131
136
  /** Tools the turn may use, narrowed to the primary agent's set when it declares one. */
132
- function toolsForPrimary(primaryName?: string): import('@pal/core').ToolDef[] {
137
+ function toolsForPrimary(primaryName?: string): import('@pal-code/core').ToolDef[] {
133
138
  const all = getAllTools();
134
139
  const primary = primaryName ? resolvePrimary(primaryName) : null;
135
140
  if (!primary?.tools) return all;
@@ -175,6 +180,8 @@ async function gatedExecuteTool(
175
180
  apiKey: string;
176
181
  baseUrl: string;
177
182
  keys?: Record<string, string>;
183
+ headers?: Record<string, string>;
184
+ systemPromptAppend?: string;
178
185
  readOnly?: boolean;
179
186
  allowedTools?: string[];
180
187
  },
@@ -6,9 +6,9 @@
6
6
  * The TUI key handler in index.ts routes y/n/a/Esc to the resolver.
7
7
  */
8
8
 
9
- import {checkPermission, loadPermissionConfig, detectDangerousBash} from '@pal/core';
10
- import type {PermissionConfig} from '@pal/core';
11
- import type {ToolResult} from '@pal/core';
9
+ import {checkPermission, loadPermissionConfig, detectDangerousBash} from '@pal-code/core';
10
+ import type {PermissionConfig} from '@pal-code/core';
11
+ import type {ToolResult} from '@pal-code/core';
12
12
 
13
13
  import {state} from '../state.js';
14
14
 
@@ -1,36 +0,0 @@
1
- /**
2
- * Agent lifecycle events — lets the UI observe sub-agents spawned by `delegate`
3
- * without the tool executor knowing anything about the TUI.
4
- */
5
-
6
- export type AgentEvent =
7
- | {type: 'delegate-start'; id: string; task: string}
8
- | {type: 'delegate-round'; id: string; round: number}
9
- | {type: 'delegate-tool'; id: string; tool: string}
10
- | {type: 'delegate-done'; id: string; summary: string; error?: boolean}
11
- | {type: 'todos-updated'; todos: readonly {content: string; status: string}[]}
12
- /** The agent asks the front-end to switch primary agent (e.g. → plan mode). */
13
- | {type: 'primary-request'; name: string; reason?: string};
14
-
15
- type Listener = (ev: AgentEvent) => void;
16
-
17
- const listeners = new Set<Listener>();
18
-
19
- /** Subscribe to agent events. Returns an unsubscribe function. */
20
- export function onAgentEvent(fn: Listener): () => void {
21
- listeners.add(fn);
22
- return () => {
23
- listeners.delete(fn);
24
- };
25
- }
26
-
27
- /** Emit an agent event to all subscribers. Never throws. */
28
- export function emitAgentEvent(ev: AgentEvent): void {
29
- for (const fn of [...listeners]) {
30
- try {
31
- fn(ev);
32
- } catch {
33
- /* a broken listener must not break the agent */
34
- }
35
- }
36
- }