pal-code 0.0.10 → 0.0.12

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.
@@ -27,7 +27,12 @@ import {
27
27
  } from '@earendil-works/pi-tui';
28
28
  import type {TUI} from '@earendil-works/pi-tui';
29
29
  import {c, editorTheme, agentColors, agentLabels, colorByName} from './theme.js';
30
- import {generateTitle, sanitizeTitle, formatMessageTimestamp} from './utils/format.js';
30
+ import {
31
+ generateTitle,
32
+ sanitizeTitle,
33
+ formatMessageTimestamp,
34
+ subagentStatusText,
35
+ } from './utils/format.js';
31
36
  import {MessageBox} from './components/message-box.js';
32
37
  import {renderHistory} from './components/render-history.js';
33
38
  import {loadConfig} from './config.js';
@@ -59,6 +64,8 @@ import {
59
64
  restoreSnapshot,
60
65
  listSnapshots,
61
66
  onAgentEvent,
67
+ getSubagentStatus,
68
+ onSubagentStatusChange,
62
69
  providerAccessible,
63
70
  rollbackTurn,
64
71
  seqToCount,
@@ -81,7 +88,7 @@ import type {SessionStore as SessionStoreType} from '@pal-code/core';
81
88
  // (see buildModelOptions). Static curated lists live in @pal-code/core PROVIDERS as fallback.
82
89
 
83
90
  // Version synced from version.json via `node scripts/sync-version.js`.
84
- const VERSION = '0.0.10';
91
+ const VERSION = '0.0.12';
85
92
 
86
93
  import {showModelSelector} from './overlays/model-picker.js';
87
94
  import {showKeyInput} from './overlays/key-input.js';
@@ -115,7 +122,7 @@ async function main() {
115
122
  // Handle CLI extension commands (no TUI needed)
116
123
  if (process.argv[2] === 'add' && process.argv[3]) {
117
124
  const {extAdd} = await import('./commands/ext.js');
118
- const result = extAdd(process.argv[3]);
125
+ const result = await extAdd(process.argv[3]);
119
126
  console.log(result.message);
120
127
  process.exit(result.ok ? 0 : 1);
121
128
  }
@@ -125,6 +132,23 @@ async function main() {
125
132
  console.log(result.message);
126
133
  process.exit(result.ok ? 0 : 1);
127
134
  }
135
+ if (process.argv[2] === 'export') {
136
+ const {exportConfig} = await import('./commands/config-export.js');
137
+ const result = exportConfig(process.argv[3]);
138
+ console.log(result.message);
139
+ process.exit(result.ok ? 0 : 1);
140
+ }
141
+ if (process.argv[2] === 'import') {
142
+ const {importConfig} = await import('./commands/config-io.js');
143
+ const file = process.argv[3];
144
+ if (!file) {
145
+ console.log('Usage: pal import <file>');
146
+ process.exit(1);
147
+ }
148
+ const result = importConfig(file);
149
+ console.log(result.message);
150
+ process.exit(result.ok ? 0 : 1);
151
+ }
128
152
  // ── BYOK gate: force setup when no key is configured ──
129
153
  let allKeys = resolveAllKeys();
130
154
  const forceSetup = process.argv.includes('--setup') || process.argv.includes('--login');
@@ -363,7 +387,7 @@ async function main() {
363
387
 
364
388
  tui.addInputListener((data) => {
365
389
  // SGR mouse: ESC [ < b ; x ; y M|m (preferred, enabled via ?1006h)
366
- const mouse = data.match(/^\x1b\[<(\d+);\d+;\d+[Mm]$/);
390
+ const mouse = data.startsWith('\x1b[<') ? data.slice(3).match(/^(\d+);\d+;\d+[Mm]$/) : null;
367
391
  if (mouse) {
368
392
  const btn = Number(mouse[1]) & 0xff;
369
393
  if (btn === 64) {
@@ -471,6 +495,9 @@ async function main() {
471
495
  {name: 'cost', description: 'Show token usage and cost'},
472
496
  {name: 'model', description: 'Switch model'},
473
497
  {name: 'ext', description: 'Manage extensions'},
498
+ {name: 'export', description: 'Export config to a versionable JSON file'},
499
+ {name: 'import', description: 'Import config from an export file'},
500
+ {name: 'roles', description: 'List agent roles'},
474
501
  ],
475
502
  process.cwd(),
476
503
  ),
@@ -497,6 +524,9 @@ async function main() {
497
524
  const agentStr = state.backgroundAgents.length
498
525
  ? ` ${c.yellow}⛭ ${running}/${state.backgroundAgents.length} agents${c.reset}`
499
526
  : '';
527
+ const sub = getSubagentStatus();
528
+ const subLine = subagentStatusText(sub.active, sub.startedAt);
529
+ const subStr = subLine ? ` ${c.yellow}${subLine}${c.reset}` : '';
500
530
  // The status line now only carries identity/nav; token, cost and context
501
531
  // usage live in the sidebar's Info block.
502
532
  //
@@ -514,7 +544,7 @@ async function main() {
514
544
  );
515
545
  } else {
516
546
  statusLine.setText(
517
- `${modelShort} ${c.dim}${providerName}${agentStr}${c.reset} ${c.dim}/help${c.reset}`,
547
+ `${modelShort} ${c.dim}${providerName}${agentStr}${subStr}${c.reset} ${c.dim}/help${c.reset}`,
518
548
  );
519
549
  }
520
550
  sidebar.setStats({
@@ -797,7 +827,9 @@ async function main() {
797
827
  const teardownPermission = (): void => {
798
828
  // Remove the centered prompt from the message area
799
829
  if (state.permissionPrompt) {
800
- try { messagesContainer.removeChild(state.permissionPrompt); } catch {}
830
+ try {
831
+ messagesContainer.removeChild(state.permissionPrompt);
832
+ } catch {}
801
833
  }
802
834
  // Restore the editor
803
835
  editorRow.addChild(editor);
@@ -907,6 +939,20 @@ async function main() {
907
939
  }
908
940
  });
909
941
 
942
+ // Fan-out status line (OMO unit 3): core's spawn/settle counter drives the
943
+ // segment in updateStatusLine. Tick advances elapsed seconds while the main
944
+ // loop awaits children; at zero the segment vanishes and the tick clears.
945
+ let subagentTick: ReturnType<typeof setInterval> | undefined;
946
+ onSubagentStatusChange((sub) => {
947
+ if (sub.active > 0 && subagentTick === undefined) {
948
+ subagentTick = setInterval(() => state.refreshStatusLine(), 1000);
949
+ } else if (sub.active === 0 && subagentTick !== undefined) {
950
+ clearInterval(subagentTick);
951
+ subagentTick = undefined;
952
+ }
953
+ state.refreshStatusLine();
954
+ });
955
+
910
956
  // ═══════════════════════════════════════════════════════════════════════════
911
957
  // Editor submit handler
912
958
  // ═══════════════════════════════════════════════════════════════════════════
@@ -1055,9 +1101,7 @@ async function main() {
1055
1101
  state.currentTodos = [];
1056
1102
  state.permissionWhitelist = [];
1057
1103
  refreshSidebar();
1058
- messagesContainer.addChild(
1059
- new Text(`${c.yellow}New session started.${c.reset}`, 1, 0),
1060
- );
1104
+ messagesContainer.addChild(new Text(`${c.yellow}New session started.${c.reset}`, 1, 0));
1061
1105
  tui.requestRender();
1062
1106
  return;
1063
1107
  }
@@ -1065,7 +1109,11 @@ async function main() {
1065
1109
  // /clear was removed in favour of /new: history is append-only now, so
1066
1110
  // "erase this session" has no clean representation. Point users at /new.
1067
1111
  messagesContainer.addChild(
1068
- new Text(`${c.dim} /clear was removed — use /new to start a fresh session.${c.reset}`, 1, 0),
1112
+ new Text(
1113
+ `${c.dim} /clear was removed — use /new to start a fresh session.${c.reset}`,
1114
+ 1,
1115
+ 0,
1116
+ ),
1069
1117
  );
1070
1118
  tui.requestRender();
1071
1119
  return;
@@ -1132,11 +1180,7 @@ async function main() {
1132
1180
  store.recordCompaction(currentSessionId, alreadyUpto, newMark, summary);
1133
1181
  }
1134
1182
  messagesContainer.addChild(
1135
- new Text(
1136
- `${c.green}Compacted ${boundary} messages into a checkpoint.${c.reset}`,
1137
- 1,
1138
- 0,
1139
- ),
1183
+ new Text(`${c.green}Compacted ${boundary} messages into a checkpoint.${c.reset}`, 1, 0),
1140
1184
  );
1141
1185
  tui.requestRender();
1142
1186
  return;
@@ -1180,8 +1224,11 @@ async function main() {
1180
1224
  } else {
1181
1225
  for (const rule of perm.rules) {
1182
1226
  const tools = Array.isArray(rule.tool) ? rule.tool.join(',') : rule.tool;
1183
- const color = rule.action === 'allow' ? c.green : rule.action === 'deny' ? c.red : c.yellow;
1184
- lines.push(` ${tools.padEnd(20)} ${rule.match.padEnd(20)} ${color}${rule.action}${c.reset}`);
1227
+ const color =
1228
+ rule.action === 'allow' ? c.green : rule.action === 'deny' ? c.red : c.yellow;
1229
+ lines.push(
1230
+ ` ${tools.padEnd(20)} ${rule.match.padEnd(20)} ${color}${rule.action}${c.reset}`,
1231
+ );
1185
1232
  }
1186
1233
  }
1187
1234
  if (state.permissionWhitelist.length > 0) {
@@ -1192,7 +1239,9 @@ async function main() {
1192
1239
  }
1193
1240
  }
1194
1241
  lines.push('');
1195
- lines.push(`${c.dim}Edit permissions.json in your project root or ~/.pal/ to customize.${c.reset}`);
1242
+ lines.push(
1243
+ `${c.dim}Edit permissions.json in your project root or ~/.pal/ to customize.${c.reset}`,
1244
+ );
1196
1245
  for (const line of lines) {
1197
1246
  messagesContainer.addChild(new Text(line, 1, 0));
1198
1247
  }
@@ -1282,7 +1331,13 @@ async function main() {
1282
1331
 
1283
1332
  if (sub === 'add' && pkg) {
1284
1333
  const {extAdd} = await import('./commands/ext.js');
1285
- const result = extAdd(pkg);
1334
+ const result = await extAdd(pkg);
1335
+ messagesContainer.addChild(
1336
+ new Text(`${result.ok ? c.green : c.red} ${result.message}${c.reset}`, 1, 0),
1337
+ );
1338
+ } else if (sub === 'search') {
1339
+ const {extSearch} = await import('./commands/ext.js');
1340
+ const result = await extSearch(parts.slice(1).join(' '));
1286
1341
  messagesContainer.addChild(
1287
1342
  new Text(`${result.ok ? c.green : c.red} ${result.message}${c.reset}`, 1, 0),
1288
1343
  );
@@ -1308,7 +1363,7 @@ async function main() {
1308
1363
  } else {
1309
1364
  messagesContainer.addChild(
1310
1365
  new Text(
1311
- `${c.dim} Usage: /ext add <name> | /ext remove <name> | /ext list${c.reset}`,
1366
+ `${c.dim} Usage: /ext add <name> | /ext remove <name> | /ext search <query> | /ext list${c.reset}`,
1312
1367
  1,
1313
1368
  0,
1314
1369
  ),
@@ -1318,6 +1373,32 @@ async function main() {
1318
1373
  return;
1319
1374
  }
1320
1375
 
1376
+ if (trimmed === '/export' || trimmed.startsWith('/export ')) {
1377
+ const file = trimmed.slice('/export'.length).trim();
1378
+ const {exportConfig} = await import('./commands/config-export.js');
1379
+ const result = exportConfig(file || undefined);
1380
+ messagesContainer.addChild(
1381
+ new Text(`${result.ok ? c.green : c.red} ${result.message}${c.reset}`, 1, 0),
1382
+ );
1383
+ tui.requestRender();
1384
+ return;
1385
+ }
1386
+
1387
+ if (trimmed === '/import' || trimmed.startsWith('/import ')) {
1388
+ const file = trimmed.slice('/import'.length).trim();
1389
+ if (!file) {
1390
+ messagesContainer.addChild(new Text(`${c.dim} Usage: /import <file>${c.reset}`, 1, 0));
1391
+ } else {
1392
+ const {importConfig} = await import('./commands/config-io.js');
1393
+ const result = importConfig(file);
1394
+ messagesContainer.addChild(
1395
+ new Text(`${result.ok ? c.green : c.red} ${result.message}${c.reset}`, 1, 0),
1396
+ );
1397
+ }
1398
+ tui.requestRender();
1399
+ return;
1400
+ }
1401
+
1321
1402
  if (trimmed === '/mcp' || trimmed.startsWith('/mcp ')) {
1322
1403
  const args = trimmed.slice('/mcp'.length).trim();
1323
1404
  const parts = args.split(/\s+/);
@@ -1347,7 +1428,11 @@ async function main() {
1347
1428
  }
1348
1429
  }
1349
1430
  const {mcpAddRemote} = await import('./commands/mcp.js');
1350
- const result = mcpAddRemote(name, url, Object.keys(headers).length > 0 ? headers : undefined);
1431
+ const result = mcpAddRemote(
1432
+ name,
1433
+ url,
1434
+ Object.keys(headers).length > 0 ? headers : undefined,
1435
+ );
1351
1436
  messagesContainer.addChild(
1352
1437
  new Text(`${result.ok ? c.green : c.red} ${result.message}${c.reset}`, 1, 0),
1353
1438
  );
@@ -1360,9 +1445,7 @@ async function main() {
1360
1445
  } else if (sub === 'list') {
1361
1446
  const {mcpList} = await import('./commands/mcp.js');
1362
1447
  const lines = mcpList();
1363
- messagesContainer.addChild(
1364
- new Text(`${c.bold}${lines.join('\n')}${c.reset}`, 1, 0),
1365
- );
1448
+ messagesContainer.addChild(new Text(`${c.bold}${lines.join('\n')}${c.reset}`, 1, 0));
1366
1449
  } else if (sub === 'browse') {
1367
1450
  const {REGISTRY} = await import('./commands/mcp-registry.js');
1368
1451
  const lines: string[] = [`${c.bold}Curated MCP Servers${c.reset}`, ''];
@@ -1371,10 +1454,14 @@ async function main() {
1371
1454
  lines.push(` ${c.dim}${entry.description}${c.reset}`);
1372
1455
  if (entry.url) {
1373
1456
  // Remote server
1374
- lines.push(` ${c.green}/mcp add-remote ${entry.name.toLowerCase()} ${entry.url}${c.reset}`);
1457
+ lines.push(
1458
+ ` ${c.green}/mcp add-remote ${entry.name.toLowerCase()} ${entry.url}${c.reset}`,
1459
+ );
1375
1460
  } else if (entry.package) {
1376
1461
  // Local server
1377
- lines.push(` ${c.green}/mcp add ${entry.name.toLowerCase()} npx -y ${entry.package}${c.reset}`);
1462
+ lines.push(
1463
+ ` ${c.green}/mcp add ${entry.name.toLowerCase()} npx -y ${entry.package}${c.reset}`,
1464
+ );
1378
1465
  }
1379
1466
  lines.push('');
1380
1467
  }
@@ -1388,16 +1475,17 @@ async function main() {
1388
1475
  new Text(`${c.dim} No MCP servers found for "${query}".${c.reset}`, 1, 0),
1389
1476
  );
1390
1477
  } else {
1391
- const lines: string[] = [
1392
- `${c.bold}Search results for "${query}"${c.reset}`,
1393
- '',
1394
- ];
1478
+ const lines: string[] = [`${c.bold}Search results for "${query}"${c.reset}`, ''];
1395
1479
  for (const entry of results) {
1396
1480
  lines.push(` ${c.cyan}${entry.name}${c.reset} — ${entry.description}`);
1397
1481
  if (entry.url) {
1398
- lines.push(` ${c.green}/mcp add-remote ${entry.name.toLowerCase()} ${entry.url}${c.reset}`);
1482
+ lines.push(
1483
+ ` ${c.green}/mcp add-remote ${entry.name.toLowerCase()} ${entry.url}${c.reset}`,
1484
+ );
1399
1485
  } else if (entry.package) {
1400
- lines.push(` ${c.green}/mcp add ${entry.name.toLowerCase()} npx -y ${entry.package}${c.reset}`);
1486
+ lines.push(
1487
+ ` ${c.green}/mcp add ${entry.name.toLowerCase()} npx -y ${entry.package}${c.reset}`,
1488
+ );
1401
1489
  }
1402
1490
  lines.push('');
1403
1491
  }
@@ -1433,7 +1521,9 @@ async function main() {
1433
1521
  // Record the role for this user turn so repaint can colour it correctly.
1434
1522
  userRoles.set(messages.length, activeRole);
1435
1523
  messagesContainer.addChild(new Spacer(1));
1436
- messagesContainer.addChild(new MessageBox(trimmed, activeRole, formatMessageTimestamp(Date.now())));
1524
+ messagesContainer.addChild(
1525
+ new MessageBox(trimmed, activeRole, formatMessageTimestamp(Date.now())),
1526
+ );
1437
1527
  messagesContainer.addChild(new Spacer(1));
1438
1528
  tui.requestRender();
1439
1529
 
@@ -1584,7 +1674,8 @@ async function main() {
1584
1674
  // Restore the terminal: leaving SGR mouse reporting on would make the
1585
1675
  // parent shell print raw mouse escape codes.
1586
1676
  disableMouse();
1587
- });}
1677
+ });
1678
+ }
1588
1679
 
1589
1680
  main().catch((err) => {
1590
1681
  // A startup failure (e.g. locked DB, broken import) after tui.start() leaves
@@ -1598,7 +1689,9 @@ main().catch((err) => {
1598
1689
  if (process.stdin.isTTY) process.stdin.setRawMode(false);
1599
1690
  // 3. Show the cursor in case it was hidden.
1600
1691
  process.stdout.write('\x1b[?25h');
1601
- } catch { /* best-effort — may crash again if stdin/stdout are gone */ }
1692
+ } catch {
1693
+ /* best-effort — may crash again if stdin/stdout are gone */
1694
+ }
1602
1695
  console.error(err);
1603
1696
  process.exit(1);
1604
1697
  });
@@ -8,17 +8,22 @@ import {
8
8
  registerExtensionTools,
9
9
  executeTool,
10
10
  registerExtensionHandlers,
11
+ registerExtensionLifecycle,
11
12
  loadExtensions,
12
13
  resolveExtensionSpecifier,
13
14
  runWithFallback,
14
15
  shortModel,
15
16
  buildRolesPrompt,
17
+ buildSkillsPrompt,
18
+ clearFileRolesCache,
19
+ clearSkillsCache,
16
20
  listPrimaries,
17
21
  resolvePrimary,
18
22
  defaultPrimaryName,
19
23
  type Provider,
20
24
  type ProviderKeys,
21
25
  type ConversationMessage as Message,
26
+ type LoadedExtensions,
22
27
  type ToolResult,
23
28
  } from '@pal-code/core';
24
29
  import type {TUI, Container} from '@earendil-works/pi-tui';
@@ -44,21 +49,17 @@ let extensionsLoaded = false;
44
49
  export const DEFAULT_EXTENSIONS = ['@pal-code/web-search', '@pal-code/agents', '@pal-code/mcp'];
45
50
 
46
51
  /**
47
- * Apply a successful load to the process: register tools + handlers centrally,
48
- * record status for the sidebar, and adopt the configured default primary.
52
+ * Apply a successful load to the process: register tools, handlers and
53
+ * lifecycle hooks centrally, record status for the sidebar, and adopt the
54
+ * configured default primary.
49
55
  */
50
- async function applyLoaded(
51
- requested: string[],
52
- loaded: string[],
53
- failed: Array<{pkg: string; reason: string}>,
54
- tools: import('@pal-code/core').ToolDef[],
55
- handlers: Record<string, import('@pal-code/core').ToolHandler>,
56
- ): Promise<void> {
57
- registerExtensionHandlers(handlers);
58
- registerExtensionTools(tools);
56
+ async function applyLoaded(requested: string[], result: LoadedExtensions): Promise<void> {
57
+ registerExtensionHandlers(result.handlers);
58
+ registerExtensionTools(result.tools);
59
+ registerExtensionLifecycle(result.lifecycle);
59
60
 
60
- const active = new Set(loaded);
61
- const failedByPkg = new Map(failed.map((f) => [f.pkg, f.reason]));
61
+ const active = new Set(result.loaded);
62
+ const failedByPkg = new Map(result.failed.map((f) => [f.pkg, f.reason]));
62
63
  state.extensions = requested.map((pkg) => ({
63
64
  name: pkg.replace(/^@pal-code\//, ''),
64
65
  active: active.has(pkg),
@@ -95,9 +96,9 @@ export async function ensureExtensionsLoaded(extensions?: string[]): Promise<voi
95
96
  if (extensionsLoaded) return;
96
97
 
97
98
  const requested = extensions ?? DEFAULT_EXTENSIONS;
98
- const {tools, handlers, loaded, failed} = await loadExtensions(requested);
99
+ const result = await loadExtensions(requested);
99
100
  extensionsLoaded = true;
100
- await applyLoaded(requested, loaded, failed, tools, handlers);
101
+ await applyLoaded(requested, result);
101
102
  }
102
103
 
103
104
  /**
@@ -109,19 +110,21 @@ export async function ensureExtensionsLoaded(extensions?: string[]): Promise<voi
109
110
  */
110
111
  export async function reloadExtensions(extensions?: string[]): Promise<number> {
111
112
  const requested = extensions ?? DEFAULT_EXTENSIONS;
112
- const {tools, handlers, loaded, failed} = await loadExtensions(requested, {
113
+ const result = await loadExtensions(requested, {
113
114
  cacheBust: true,
114
115
  });
115
116
  extensionsLoaded = true;
116
- await applyLoaded(requested, loaded, failed, tools, handlers);
117
- return tools.length;
117
+ clearFileRolesCache();
118
+ clearSkillsCache();
119
+ await applyLoaded(requested, result);
120
+ return result.tools.length;
118
121
  }
119
122
 
120
123
  /**
121
124
  * Compose the system prompt for a turn: the base prompt, an optional primary
122
- * agent preamble, and the role-awareness block (only when an orchestration
123
- * extension registered roles). Every piece is skipped when absent, so users
124
- * with no extensions pay nothing in tokens.
125
+ * agent preamble, the role-awareness block, and the skill listing (only when
126
+ * skill files exist). Every piece is skipped when absent, so users with no
127
+ * extensions or skills pay nothing in tokens.
125
128
  */
126
129
  function composeSystemPrompt(base: string, primaryName?: string): string {
127
130
  const parts: string[] = [];
@@ -130,6 +133,8 @@ function composeSystemPrompt(base: string, primaryName?: string): string {
130
133
  parts.push(base);
131
134
  const roles = buildRolesPrompt();
132
135
  if (roles) parts.push(roles);
136
+ const skills = buildSkillsPrompt();
137
+ if (skills) parts.push(skills);
133
138
  return parts.join('\n\n');
134
139
  }
135
140
 
@@ -180,6 +185,8 @@ async function gatedExecuteTool(
180
185
  apiKey: string;
181
186
  baseUrl: string;
182
187
  keys?: Record<string, string>;
188
+ headers?: Record<string, string>;
189
+ systemPromptAppend?: string;
183
190
  readOnly?: boolean;
184
191
  allowedTools?: string[];
185
192
  },
@@ -244,6 +251,7 @@ export async function agentLoop(
244
251
  executeTool: gatedExecuteTool,
245
252
  childExecuteTool: gatedExecuteTool,
246
253
  signal: state.activeAbort?.signal,
254
+ primary: primaryName,
247
255
  readOnly: isReadOnlyPrimary(primaryName),
248
256
  allowedTools: allowedToolsForPrimary(primaryName),
249
257
  createProvider: (spec: string) => createProvider(spec),
@@ -154,7 +154,10 @@ function buildHeader(
154
154
  // Fixed columns: ╭(1) ─(1) ␠(1) tag ␠(1) [dashes] ╮(1)
155
155
  const dashes = W - tagWidth - 5;
156
156
  if (dashes >= 1) {
157
- return `${paint('╭─')} ${roleColor}${tagText}${c.reset} ` + `${paint('─'.repeat(dashes))}${paint('╮')}`;
157
+ return (
158
+ `${paint('╭─')} ${roleColor}${tagText}${c.reset} ` +
159
+ `${paint('─'.repeat(dashes))}${paint('╮')}`
160
+ );
158
161
  }
159
162
  return '';
160
163
  };
@@ -246,3 +249,18 @@ export function formatMessageTimestamp(epochMs: number, now = Date.now()): strin
246
249
 
247
250
  return `${weekday} ${day} ${month} ${year} ${time}`;
248
251
  }
252
+
253
+ /**
254
+ * Live fan-out indicator for the status line: `⟳ 2 subagents running… 4s`.
255
+ * Returns an empty string while no child is running, so the caller can splice
256
+ * it in unconditionally and the idle status line stays byte-identical.
257
+ *
258
+ * `startedAt` is the burst clock from core's subagent status (epoch ms of the
259
+ * first spawn); `now` is injectable so tests can pin the elapsed seconds.
260
+ */
261
+ export function subagentStatusText(active: number, startedAt: number, now = Date.now()): string {
262
+ if (active <= 0) return '';
263
+ const elapsed = Math.max(0, Math.floor((now - startedAt) / 1000));
264
+ const noun = active === 1 ? 'subagent' : 'subagents';
265
+ return `⟳ ${active} ${noun} running… ${elapsed}s`;
266
+ }