@adhdev/daemon-core 0.8.34 → 0.8.36

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 (109) hide show
  1. package/dist/boot/daemon-lifecycle.d.ts +4 -0
  2. package/dist/commands/router.d.ts +3 -0
  3. package/dist/config/config.d.ts +5 -0
  4. package/dist/index.d.ts +2 -2
  5. package/dist/index.js +585 -256
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +584 -256
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/shared-types.d.ts +286 -16
  10. package/dist/status/builders.d.ts +5 -1
  11. package/dist/status/normalize.d.ts +11 -1
  12. package/dist/status/normalize.js +36 -16
  13. package/dist/status/normalize.js.map +1 -1
  14. package/dist/status/normalize.mjs +35 -16
  15. package/dist/status/normalize.mjs.map +1 -1
  16. package/dist/status/reporter.d.ts +7 -0
  17. package/dist/status/snapshot.d.ts +5 -5
  18. package/dist/types.d.ts +1 -1
  19. package/node_modules/@adhdev/session-host-core/package.json +1 -1
  20. package/package.json +1 -1
  21. package/src/agent-stream/forward.d.ts +8 -0
  22. package/src/agent-stream/index.d.ts +6 -0
  23. package/src/agent-stream/manager.d.ts +60 -0
  24. package/src/agent-stream/poller.d.ts +41 -0
  25. package/src/agent-stream/provider-adapter.d.ts +36 -0
  26. package/src/agent-stream/types.d.ts +68 -0
  27. package/src/boot/daemon-lifecycle.d.ts +100 -0
  28. package/src/boot/daemon-lifecycle.ts +7 -0
  29. package/src/cdp/devtools.d.ts +51 -0
  30. package/src/cdp/initializer.d.ts +50 -0
  31. package/src/cdp/manager.d.ts +147 -0
  32. package/src/cdp/scanner.d.ts +58 -0
  33. package/src/cdp/setup.d.ts +58 -0
  34. package/src/cli-adapter-types.d.ts +57 -0
  35. package/src/cli-adapters/provider-cli-adapter.d.ts +177 -0
  36. package/src/cli-adapters/provider-cli-adapter.ts +115 -91
  37. package/src/cli-adapters/provider-cli-config.d.ts +30 -0
  38. package/src/cli-adapters/provider-cli-parse.d.ts +42 -0
  39. package/src/cli-adapters/provider-cli-runtime.d.ts +29 -0
  40. package/src/cli-adapters/provider-cli-shared.d.ts +158 -0
  41. package/src/cli-adapters/pty-transport.d.ts +48 -0
  42. package/src/cli-adapters/session-host-transport.d.ts +20 -0
  43. package/src/cli-adapters/spawn-env.d.ts +8 -0
  44. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +16 -0
  45. package/src/cli-adapters/terminal-backends/types.d.ts +18 -0
  46. package/src/cli-adapters/terminal-backends/xterm-backend.d.ts +17 -0
  47. package/src/cli-adapters/terminal-screen.d.ts +33 -0
  48. package/src/commands/cdp-commands.d.ts +15 -0
  49. package/src/commands/chat-commands.d.ts +15 -0
  50. package/src/commands/chat-commands.ts +192 -17
  51. package/src/commands/cli-manager.d.ts +94 -0
  52. package/src/commands/handler.d.ts +103 -0
  53. package/src/commands/router.d.ts +98 -0
  54. package/src/commands/router.ts +25 -0
  55. package/src/commands/stream-commands.d.ts +14 -0
  56. package/src/commands/stream-commands.ts +14 -10
  57. package/src/commands/upgrade-helper.d.ts +10 -0
  58. package/src/commands/workspace-commands.d.ts +11 -0
  59. package/src/config/chat-history.d.ts +99 -0
  60. package/src/config/config.d.ts +14 -0
  61. package/src/config/config.ts +8 -0
  62. package/src/config/recent-activity.d.ts +29 -0
  63. package/src/config/saved-sessions.d.ts +22 -0
  64. package/src/config/state-store.d.ts +32 -0
  65. package/src/config/workspaces.d.ts +0 -1
  66. package/src/daemon/dev-auto-implement.d.ts +43 -0
  67. package/src/daemon/dev-cdp-handlers.d.ts +22 -0
  68. package/src/daemon/dev-cli-debug.d.ts +106 -0
  69. package/src/daemon/dev-server-types.d.ts +43 -0
  70. package/src/daemon/dev-server.d.ts +140 -0
  71. package/src/daemon/scaffold-template.d.ts +32 -0
  72. package/src/daemon-core.d.ts +36 -0
  73. package/src/detection/cli-detector.d.ts +31 -0
  74. package/src/detection/ide-detector.d.ts +35 -0
  75. package/src/index.d.ts +83 -0
  76. package/src/index.ts +34 -1
  77. package/src/installer.d.ts +50 -0
  78. package/src/ipc-protocol.d.ts +111 -0
  79. package/src/launch.d.ts +46 -0
  80. package/src/logging/command-log.d.ts +31 -0
  81. package/src/logging/logger.d.ts +89 -0
  82. package/src/providers/acp-provider-instance.d.ts +102 -0
  83. package/src/providers/approval-utils.d.ts +7 -0
  84. package/src/providers/cli-provider-instance.d.ts +86 -0
  85. package/src/providers/contracts.d.ts +193 -1
  86. package/src/providers/control-effects.d.ts +4 -0
  87. package/src/providers/extension-provider-instance.d.ts +61 -0
  88. package/src/providers/ide-provider-instance.d.ts +70 -0
  89. package/src/providers/provider-instance-manager.d.ts +84 -0
  90. package/src/providers/provider-instance.d.ts +7 -1
  91. package/src/providers/provider-loader.d.ts +299 -0
  92. package/src/providers/status-monitor.d.ts +48 -0
  93. package/src/providers/version-archive.d.ts +52 -0
  94. package/src/session-host/runtime-support.d.ts +8 -0
  95. package/src/sessions/reconcile.d.ts +22 -0
  96. package/src/sessions/registry.d.ts +24 -0
  97. package/src/shared-types-extra.d.ts +29 -0
  98. package/src/shared-types.d.ts +204 -38
  99. package/src/shared-types.ts +319 -16
  100. package/src/status/builders.d.ts +33 -0
  101. package/src/status/builders.ts +110 -54
  102. package/src/status/normalize.ts +54 -19
  103. package/src/status/reporter.d.ts +69 -0
  104. package/src/status/reporter.ts +104 -26
  105. package/src/status/snapshot.d.ts +58 -0
  106. package/src/status/snapshot.ts +79 -41
  107. package/src/system/host-memory.d.ts +19 -0
  108. package/src/types.d.ts +3 -7
  109. package/src/types.ts +1 -1
@@ -1428,8 +1428,6 @@ export class ProviderCliAdapter implements CliAdapter {
1428
1428
  throw new Error(`${this.cliName} is awaiting confirmation before it can accept a prompt`);
1429
1429
  }
1430
1430
 
1431
- this.committedMessages.push({ role: 'user', content: text, timestamp: Date.now() });
1432
- this.syncMessageViews();
1433
1431
  this.isWaitingForResponse = true;
1434
1432
  this.responseBuffer = '';
1435
1433
  this.finishRetryCount = 0;
@@ -1458,6 +1456,13 @@ export class ProviderCliAdapter implements CliAdapter {
1458
1456
  const submitDelayMs = this.sendDelayMs + Math.min(2000, Math.max(0, estimatedLines - 1) * 350);
1459
1457
  const maxEchoWaitMs = submitDelayMs + Math.max(1500, Math.min(5000, estimatedLines * 500));
1460
1458
  const retryDelayMs = Math.max(350, Math.min(1500, Math.max(this.sendDelayMs, submitDelayMs)));
1459
+ let didCommitUserTurn = false;
1460
+ const commitUserTurn = () => {
1461
+ if (didCommitUserTurn) return;
1462
+ didCommitUserTurn = true;
1463
+ this.committedMessages.push({ role: 'user', content: text, timestamp: Date.now() });
1464
+ this.syncMessageViews();
1465
+ };
1461
1466
  if (this.settleTimer) {
1462
1467
  clearTimeout(this.settleTimer);
1463
1468
  this.settleTimer = null;
@@ -1470,115 +1475,134 @@ export class ProviderCliAdapter implements CliAdapter {
1470
1475
  if (this.isWaitingForResponse) this.finishResponse();
1471
1476
  }, this.timeouts.maxResponse);
1472
1477
  };
1478
+ await new Promise<void>((resolve) => {
1479
+ let resolved = false;
1480
+ const resolveOnce = () => {
1481
+ if (resolved) return;
1482
+ resolved = true;
1483
+ resolve();
1484
+ };
1473
1485
 
1474
- const submit = () => {
1475
- if (!this.ptyProcess) return;
1476
- this.submitPendingUntil = 0;
1477
- this.recordTrace('submit_write', {
1478
- mode: 'submit_key',
1479
- sendKey: this.sendKey,
1480
- screenText: summarizeCliTraceText(this.terminalScreen.getText(), 500),
1481
- });
1482
- this.ptyProcess.write(this.sendKey);
1483
- const retrySubmitIfStuck = (attempt: number) => {
1484
- this.submitRetryTimer = null;
1485
- if (!this.ptyProcess || !this.isWaitingForResponse || this.submitRetryUsed) return;
1486
- if (this.currentStatus === 'waiting_approval') return;
1487
- if ((this.responseBuffer || '').trim()) return;
1486
+ const submit = () => {
1487
+ if (!this.ptyProcess) {
1488
+ resolveOnce();
1489
+ return;
1490
+ }
1491
+ commitUserTurn();
1492
+ this.submitPendingUntil = 0;
1488
1493
  const screenText = this.terminalScreen.getText();
1489
- if (!promptLikelyVisible(screenText, normalizedPromptSnippet)) return;
1490
- if (/Esc to interrupt|Do you want to proceed|This command requires approval|Allow Codex to|Approve and run now|Always approve this session|Running…|Running\.\.\./i.test(screenText)) return;
1491
- this.responseSettleIgnoreUntil = Date.now() + this.timeouts.outputSettle + 400;
1492
- LOG.info('CLI', `[${this.cliType}] Retrying submit key for stuck prompt (attempt ${attempt})`);
1493
1494
  this.recordTrace('submit_write', {
1494
- mode: 'submit_retry',
1495
- attempt,
1495
+ mode: 'submit_key',
1496
1496
  sendKey: this.sendKey,
1497
1497
  screenText: summarizeCliTraceText(screenText, 500),
1498
1498
  });
1499
- this.ptyProcess.write(this.sendKey);
1500
- if (attempt >= 3) {
1501
- this.submitRetryUsed = true;
1502
- return;
1503
- }
1504
- this.submitRetryTimer = setTimeout(() => retrySubmitIfStuck(attempt + 1), retryDelayMs);
1499
+ this.ptyProcess!.write(this.sendKey);
1500
+ const retrySubmitIfStuck = (attempt: number) => {
1501
+ this.submitRetryTimer = null;
1502
+ if (!this.ptyProcess || !this.isWaitingForResponse || this.submitRetryUsed) return;
1503
+ if (this.currentStatus === 'waiting_approval') return;
1504
+ if ((this.responseBuffer || '').trim()) return;
1505
+ const screenText = this.terminalScreen.getText();
1506
+ if (!promptLikelyVisible(screenText, normalizedPromptSnippet)) return;
1507
+ if (/Esc to interrupt|Do you want to proceed|This command requires approval|Allow Codex to|Approve and run now|Always approve this session|Running…|Running\.\.\./i.test(screenText)) return;
1508
+ this.responseSettleIgnoreUntil = Date.now() + this.timeouts.outputSettle + 400;
1509
+ LOG.info('CLI', `[${this.cliType}] Retrying submit key for stuck prompt (attempt ${attempt})`);
1510
+ this.recordTrace('submit_write', {
1511
+ mode: 'submit_retry',
1512
+ attempt,
1513
+ sendKey: this.sendKey,
1514
+ screenText: summarizeCliTraceText(screenText, 500),
1515
+ });
1516
+ this.ptyProcess.write(this.sendKey);
1517
+ if (attempt >= 3) {
1518
+ this.submitRetryUsed = true;
1519
+ return;
1520
+ }
1521
+ this.submitRetryTimer = setTimeout(() => retrySubmitIfStuck(attempt + 1), retryDelayMs);
1522
+ };
1523
+ this.submitRetryTimer = setTimeout(() => retrySubmitIfStuck(1), retryDelayMs);
1524
+ startResponseTimeout();
1525
+ resolveOnce();
1505
1526
  };
1506
- this.submitRetryTimer = setTimeout(() => retrySubmitIfStuck(1), retryDelayMs);
1507
- startResponseTimeout();
1508
- };
1509
1527
 
1510
- if (this.submitStrategy === 'immediate') {
1511
- this.submitPendingUntil = 0;
1528
+ if (this.submitStrategy === 'immediate') {
1529
+ commitUserTurn();
1530
+ this.submitPendingUntil = 0;
1531
+ this.recordTrace('submit_write', {
1532
+ mode: 'immediate',
1533
+ text: summarizeCliTraceText(text, 500),
1534
+ sendKey: this.sendKey,
1535
+ screenText: summarizeCliTraceText(this.terminalScreen.getText(), 500),
1536
+ });
1537
+ this.ptyProcess!.write(text + this.sendKey);
1538
+ this.submitRetryTimer = setTimeout(() => {
1539
+ this.submitRetryTimer = null;
1540
+ if (!this.ptyProcess || !this.isWaitingForResponse || this.submitRetryUsed) return;
1541
+ if (this.currentStatus === 'waiting_approval') return;
1542
+ if ((this.responseBuffer || '').trim()) return;
1543
+ const screenText = this.terminalScreen.getText();
1544
+ if (!promptLikelyVisible(screenText, normalizedPromptSnippet)) return;
1545
+ LOG.info('CLI', `[${this.cliType}] Retrying submit key for stuck prompt (attempt 1)`);
1546
+ this.responseSettleIgnoreUntil = Date.now() + this.timeouts.outputSettle + 400;
1547
+ this.recordTrace('submit_write', {
1548
+ mode: 'immediate_retry',
1549
+ attempt: 1,
1550
+ sendKey: this.sendKey,
1551
+ screenText: summarizeCliTraceText(screenText, 500),
1552
+ });
1553
+ this.ptyProcess.write(this.sendKey);
1554
+ this.submitRetryUsed = true;
1555
+ }, retryDelayMs);
1556
+ startResponseTimeout();
1557
+ resolveOnce();
1558
+ return;
1559
+ }
1560
+
1561
+ if (submitDelayMs > 0) {
1562
+ this.submitPendingUntil = Date.now() + submitDelayMs;
1563
+ }
1564
+ this.ptyProcess!.write(text);
1512
1565
  this.recordTrace('submit_write', {
1513
- mode: 'immediate',
1566
+ mode: 'type_then_submit',
1514
1567
  text: summarizeCliTraceText(text, 500),
1515
1568
  sendKey: this.sendKey,
1516
1569
  screenText: summarizeCliTraceText(this.terminalScreen.getText(), 500),
1517
1570
  });
1518
- this.ptyProcess.write(text + this.sendKey);
1519
- this.submitRetryTimer = setTimeout(() => {
1520
- this.submitRetryTimer = null;
1521
- if (!this.ptyProcess || !this.isWaitingForResponse || this.submitRetryUsed) return;
1522
- if (this.currentStatus === 'waiting_approval') return;
1523
- if ((this.responseBuffer || '').trim()) return;
1571
+ const submitStartedAt = Date.now();
1572
+ let lastNormalizedScreen = '';
1573
+ let lastScreenChangeAt = submitStartedAt;
1574
+ const waitForEchoAndSubmit = () => {
1575
+ if (!this.ptyProcess) {
1576
+ resolveOnce();
1577
+ return;
1578
+ }
1579
+ const now = Date.now();
1580
+ const elapsed = now - submitStartedAt;
1524
1581
  const screenText = this.terminalScreen.getText();
1525
- if (!promptLikelyVisible(screenText, normalizedPromptSnippet)) return;
1526
- LOG.info('CLI', `[${this.cliType}] Retrying submit key for stuck prompt (attempt 1)`);
1527
- this.responseSettleIgnoreUntil = Date.now() + this.timeouts.outputSettle + 400;
1528
- this.recordTrace('submit_write', {
1529
- mode: 'immediate_retry',
1530
- attempt: 1,
1531
- sendKey: this.sendKey,
1532
- screenText: summarizeCliTraceText(screenText, 500),
1533
- });
1534
- this.ptyProcess.write(this.sendKey);
1535
- this.submitRetryUsed = true;
1536
- }, retryDelayMs);
1537
- startResponseTimeout();
1538
- return;
1539
- }
1582
+ const normalizedScreen = normalizePromptText(screenText);
1583
+ if (normalizedScreen !== lastNormalizedScreen) {
1584
+ lastNormalizedScreen = normalizedScreen;
1585
+ lastScreenChangeAt = now;
1586
+ }
1587
+ const echoVisible = !normalizedPromptSnippet || promptLikelyVisible(screenText, normalizedPromptSnippet);
1540
1588
 
1541
- if (submitDelayMs > 0) {
1542
- this.submitPendingUntil = Date.now() + submitDelayMs;
1543
- }
1544
- this.ptyProcess.write(text);
1545
- this.recordTrace('submit_write', {
1546
- mode: 'type_then_submit',
1547
- text: summarizeCliTraceText(text, 500),
1548
- sendKey: this.sendKey,
1549
- screenText: summarizeCliTraceText(this.terminalScreen.getText(), 500),
1550
- });
1551
- const submitStartedAt = Date.now();
1552
- let lastNormalizedScreen = '';
1553
- let lastScreenChangeAt = submitStartedAt;
1554
- const waitForEchoAndSubmit = () => {
1555
- if (!this.ptyProcess) return;
1556
- const now = Date.now();
1557
- const elapsed = now - submitStartedAt;
1558
- const screenText = this.terminalScreen.getText();
1559
- const normalizedScreen = normalizePromptText(screenText);
1560
- if (normalizedScreen !== lastNormalizedScreen) {
1561
- lastNormalizedScreen = normalizedScreen;
1562
- lastScreenChangeAt = now;
1563
- }
1564
- const echoVisible = !normalizedPromptSnippet || promptLikelyVisible(screenText, normalizedPromptSnippet);
1589
+ if (echoVisible) {
1590
+ const screenSettled = (now - lastScreenChangeAt) >= 500;
1591
+ if (elapsed >= submitDelayMs && screenSettled) {
1592
+ submit();
1593
+ return;
1594
+ }
1595
+ }
1565
1596
 
1566
- if (echoVisible) {
1567
- const screenSettled = (now - lastScreenChangeAt) >= 500;
1568
- if (elapsed >= submitDelayMs && screenSettled) {
1597
+ if (elapsed >= maxEchoWaitMs) {
1569
1598
  submit();
1570
1599
  return;
1571
1600
  }
1572
- }
1573
1601
 
1574
- if (elapsed >= maxEchoWaitMs) {
1575
- submit();
1576
- return;
1577
- }
1578
-
1579
- setTimeout(waitForEchoAndSubmit, 50);
1580
- };
1581
- waitForEchoAndSubmit();
1602
+ setTimeout(waitForEchoAndSubmit, 50);
1603
+ };
1604
+ waitForEchoAndSubmit();
1605
+ });
1582
1606
  }
1583
1607
 
1584
1608
  getPartialResponse(): string {
@@ -0,0 +1,30 @@
1
+ import type { CliProviderModule } from './provider-cli-shared.js';
2
+ export interface ProviderResolutionMeta {
3
+ type: string;
4
+ name: string;
5
+ resolvedVersion: string | null;
6
+ resolvedOs: string | null;
7
+ providerDir: string | null;
8
+ scriptDir: string | null;
9
+ scriptsPath: string | null;
10
+ scriptsSource: string | null;
11
+ versionWarning: string | null;
12
+ }
13
+ export interface ResolvedCliAdapterConfig {
14
+ timeouts: {
15
+ ptyFlush: number;
16
+ dialogAccept: number;
17
+ approvalCooldown: number;
18
+ generatingIdle: number;
19
+ idleFinish: number;
20
+ maxResponse: number;
21
+ shutdownGrace: number;
22
+ outputSettle: number;
23
+ };
24
+ approvalKeys: Record<number, string>;
25
+ sendDelayMs: number;
26
+ sendKey: string;
27
+ submitStrategy: 'wait_for_echo' | 'immediate';
28
+ providerResolutionMeta: ProviderResolutionMeta;
29
+ }
30
+ export declare function resolveCliAdapterConfig(provider: CliProviderModule): ResolvedCliAdapterConfig;
@@ -0,0 +1,42 @@
1
+ import { type CliChatMessage, type CliScriptInput } from './provider-cli-shared.js';
2
+ export interface TurnParseScope {
3
+ prompt: string;
4
+ startedAt: number;
5
+ bufferStart: number;
6
+ rawBufferStart: number;
7
+ }
8
+ export declare function hydrateCliParsedMessages(parsedMessages: any[], options: {
9
+ committedMessages: CliChatMessage[];
10
+ scope?: TurnParseScope | null;
11
+ lastOutputAt: number;
12
+ now?: number;
13
+ }): any[];
14
+ export declare function normalizeCliParsedMessages(parsedMessages: any[], options: {
15
+ committedMessages: CliChatMessage[];
16
+ scope?: TurnParseScope | null;
17
+ lastOutputAt: number;
18
+ now?: number;
19
+ }): CliChatMessage[];
20
+ export declare function buildCliParseInput(options: {
21
+ accumulatedBuffer: string;
22
+ accumulatedRawBuffer: string;
23
+ recentOutputBuffer: string;
24
+ terminalScreenText: string;
25
+ baseMessages: CliChatMessage[];
26
+ partialResponse: string;
27
+ scope?: TurnParseScope | null;
28
+ runtimeSettings: Record<string, any>;
29
+ }): CliScriptInput;
30
+ export declare function summarizeCliTraceText(text: string, max?: number): string;
31
+ export declare function summarizeCliTraceMessages(messages: CliChatMessage[], limit?: number): {
32
+ role: string;
33
+ content: string;
34
+ timestamp?: number;
35
+ }[];
36
+ export declare function buildCliTraceParseSnapshot(options: {
37
+ accumulatedBuffer: string;
38
+ accumulatedRawBuffer: string;
39
+ responseBuffer: string;
40
+ partialResponse?: string;
41
+ scope?: TurnParseScope | null;
42
+ }): Record<string, any>;
@@ -0,0 +1,29 @@
1
+ import type { PtySpawnOptions, PtyRuntimeTransport } from './pty-transport.js';
2
+ import type { TerminalScreen } from './terminal-screen.js';
3
+ import { type CliProviderModule } from './provider-cli-shared.js';
4
+ export interface CliSpawnPlan {
5
+ binaryPath: string;
6
+ allArgs: string[];
7
+ shellCmd: string;
8
+ shellArgs: string[];
9
+ ptyOptions: PtySpawnOptions;
10
+ isWin: boolean;
11
+ useShell: boolean;
12
+ }
13
+ export declare function resolveCliSpawnPlan(options: {
14
+ provider: CliProviderModule;
15
+ runtimeSettings: Record<string, any>;
16
+ workingDir: string;
17
+ extraArgs: string[];
18
+ }): CliSpawnPlan;
19
+ export declare function buildCliLoginShellRetry(plan: Pick<CliSpawnPlan, 'binaryPath' | 'allArgs'>): {
20
+ shellCmd: string;
21
+ shellArgs: string[];
22
+ };
23
+ export declare function getCliSpawnErrorHint(message: string, shellCmd: string, isWin: boolean): string | null;
24
+ export declare function respondToCliTerminalQueries(options: {
25
+ ptyProcess: PtyRuntimeTransport | null;
26
+ pendingTail: string;
27
+ data: string;
28
+ terminalScreen: TerminalScreen;
29
+ }): string;
@@ -0,0 +1,158 @@
1
+ import type { ProviderResumeCapability } from '../providers/contracts.js';
2
+ import { sanitizeSpawnEnv } from './spawn-env.js';
3
+ export interface CliChatMessage {
4
+ role: 'user' | 'assistant';
5
+ content: string;
6
+ timestamp?: number;
7
+ receivedAt?: number;
8
+ kind?: string;
9
+ id?: string;
10
+ index?: number;
11
+ meta?: Record<string, any>;
12
+ senderName?: string;
13
+ }
14
+ export interface CliSessionStatus {
15
+ status: 'idle' | 'generating' | 'waiting_approval' | 'error' | 'stopped' | 'starting';
16
+ messages: CliChatMessage[];
17
+ workingDir: string;
18
+ activeModal: {
19
+ message: string;
20
+ buttons: string[];
21
+ } | null;
22
+ }
23
+ export interface CliScripts {
24
+ parseOutput?: (input: CliScriptInput) => any;
25
+ detectStatus?: (input: CliStatusInput) => string | null;
26
+ parseApproval?: (input: CliApprovalInput) => {
27
+ message: string;
28
+ buttons: string[];
29
+ } | null;
30
+ resolveAction?: (data: any) => string;
31
+ [name: string]: ((input: any) => any) | undefined;
32
+ }
33
+ export interface CliScreenLine {
34
+ index: number;
35
+ fromTop: number;
36
+ fromBottom: number;
37
+ text: string;
38
+ trimmed: string;
39
+ isEmpty: boolean;
40
+ }
41
+ export interface CliScreenSnapshot {
42
+ text: string;
43
+ lineCount: number;
44
+ lines: CliScreenLine[];
45
+ nonEmptyLines: CliScreenLine[];
46
+ firstNonEmptyLineIndex: number;
47
+ lastNonEmptyLineIndex: number;
48
+ firstNonEmptyLine: CliScreenLine | null;
49
+ lastNonEmptyLine: CliScreenLine | null;
50
+ promptLineIndex: number;
51
+ promptLine: CliScreenLine | null;
52
+ linesAbovePrompt: CliScreenLine[];
53
+ linesBelowPrompt: CliScreenLine[];
54
+ }
55
+ export interface CliScriptInput {
56
+ buffer: string;
57
+ rawBuffer: string;
58
+ recentBuffer: string;
59
+ screenText: string;
60
+ screen: CliScreenSnapshot;
61
+ bufferScreen: CliScreenSnapshot;
62
+ recentScreen: CliScreenSnapshot;
63
+ messages: CliChatMessage[];
64
+ partialResponse: string;
65
+ promptText?: string;
66
+ settings?: Record<string, any>;
67
+ args?: Record<string, any>;
68
+ }
69
+ export interface CliStatusInput {
70
+ tail: string;
71
+ screenText?: string;
72
+ rawBuffer?: string;
73
+ screen: CliScreenSnapshot;
74
+ tailScreen: CliScreenSnapshot;
75
+ }
76
+ export interface CliApprovalInput {
77
+ buffer: string;
78
+ screenText?: string;
79
+ rawBuffer?: string;
80
+ tail: string;
81
+ screen: CliScreenSnapshot;
82
+ bufferScreen: CliScreenSnapshot;
83
+ tailScreen: CliScreenSnapshot;
84
+ }
85
+ export interface CliTraceEntry {
86
+ id: number;
87
+ at: number;
88
+ type: string;
89
+ status: CliSessionStatus['status'];
90
+ isWaitingForResponse: boolean;
91
+ activeModal: {
92
+ message: string;
93
+ buttons: string[];
94
+ } | null;
95
+ payload: Record<string, any>;
96
+ }
97
+ export interface CliProviderModule {
98
+ type: string;
99
+ name: string;
100
+ category: 'cli';
101
+ binary: string;
102
+ approvalKeys?: Record<number, string>;
103
+ sendDelayMs?: number;
104
+ sendKey?: string;
105
+ submitStrategy?: 'wait_for_echo' | 'immediate';
106
+ scripts?: CliScripts;
107
+ spawn: {
108
+ command: string;
109
+ args: string[];
110
+ shell: boolean;
111
+ env: Record<string, string>;
112
+ };
113
+ timeouts?: {
114
+ ptyFlush?: number;
115
+ dialogAccept?: number;
116
+ approvalCooldown?: number;
117
+ generatingIdle?: number;
118
+ idleFinish?: number;
119
+ maxResponse?: number;
120
+ shutdownGrace?: number;
121
+ outputSettle?: number;
122
+ };
123
+ resume?: ProviderResumeCapability;
124
+ _resolvedVersion?: string | null;
125
+ _resolvedOs?: string | null;
126
+ _resolvedProviderDir?: string | null;
127
+ _resolvedScriptDir?: string | null;
128
+ _resolvedScriptsPath?: string | null;
129
+ _resolvedScriptsSource?: string | null;
130
+ _versionWarning?: string | null;
131
+ }
132
+ export declare function sanitizeTerminalText(str: string): string;
133
+ export declare function listCliScriptNames(scripts: CliScripts | undefined): string[];
134
+ export declare function buildCliScreenSnapshot(text: string): CliScreenSnapshot;
135
+ export declare const buildCliSpawnEnv: typeof sanitizeSpawnEnv;
136
+ export declare function computeTerminalQueryTail(buffer: string): string;
137
+ export declare function findBinary(name: string): string;
138
+ export declare function isScriptBinary(binaryPath: string): boolean;
139
+ export declare function looksLikeMachOOrElf(filePath: string): boolean;
140
+ export declare function shSingleQuote(arg: string): string;
141
+ export declare function estimatePromptDisplayLines(text: string, cols?: number): number;
142
+ export declare function extractPromptRetrySnippet(text: string): string;
143
+ export declare function normalizePromptText(text: string): string;
144
+ export declare function compactPromptText(text: string): string;
145
+ export declare function promptLikelyVisible(screenText: string, promptSnippet: string): boolean;
146
+ export declare function normalizeScreenSnapshot(text: string): string;
147
+ export declare function normalizeComparableMessageContent(text: string): string;
148
+ export declare function trimPromptEchoPrefix(text: string, promptText?: string | null): string;
149
+ export declare function getLastUserPromptText(messages: Array<{
150
+ role?: string;
151
+ content?: string;
152
+ }> | null | undefined): string;
153
+ export declare function looksLikeConfirmOnlyLabel(label: string): boolean;
154
+ export declare function normalizeCliProviderForRuntime(raw: unknown): {
155
+ patterns: {
156
+ approval: RegExp[];
157
+ };
158
+ };
@@ -0,0 +1,48 @@
1
+ export interface PtySpawnOptions {
2
+ cwd: string;
3
+ env: Record<string, string>;
4
+ cols: number;
5
+ rows: number;
6
+ }
7
+ export interface PtyRuntimeWriteOwner {
8
+ clientId: string;
9
+ ownerType: 'agent' | 'user';
10
+ }
11
+ export interface PtyRuntimeClientInfo {
12
+ clientId: string;
13
+ type: 'daemon' | 'web' | 'local-terminal';
14
+ readOnly: boolean;
15
+ }
16
+ export interface PtyRuntimeMetadata {
17
+ runtimeId: string;
18
+ runtimeKey?: string;
19
+ displayName?: string;
20
+ workspaceLabel?: string;
21
+ writeOwner?: PtyRuntimeWriteOwner | null;
22
+ attachedClients?: PtyRuntimeClientInfo[];
23
+ restoredFromStorage?: boolean;
24
+ recoveryState?: string | null;
25
+ recoveryError?: string | null;
26
+ }
27
+ export interface PtyRuntimeTransport {
28
+ readonly pid: number;
29
+ readonly ready: Promise<void>;
30
+ readonly terminalQueriesHandled?: boolean;
31
+ write(data: string): void;
32
+ resize(cols: number, rows: number): void;
33
+ kill(): void;
34
+ clearBuffer?(): void;
35
+ detach?(): void;
36
+ updateMeta?(meta: Record<string, unknown>, replace?: boolean): void;
37
+ getMetadata?(): PtyRuntimeMetadata | null;
38
+ onData(callback: (data: string) => void): void;
39
+ onExit(callback: (info: {
40
+ exitCode: number;
41
+ }) => void): void;
42
+ }
43
+ export interface PtyTransportFactory {
44
+ spawn(command: string, args: string[], options: PtySpawnOptions): PtyRuntimeTransport;
45
+ }
46
+ export declare class NodePtyTransportFactory implements PtyTransportFactory {
47
+ spawn(command: string, args: string[], options: PtySpawnOptions): PtyRuntimeTransport;
48
+ }
@@ -0,0 +1,20 @@
1
+ import { type SessionHostEndpoint, type SessionHostCategory } from '@adhdev/session-host-core';
2
+ import type { PtyRuntimeTransport, PtySpawnOptions, PtyTransportFactory } from './pty-transport.js';
3
+ interface SessionHostPtyTransportFactoryOptions {
4
+ endpoint?: SessionHostEndpoint;
5
+ appName?: string;
6
+ ensureReady?: () => Promise<void>;
7
+ clientId: string;
8
+ runtimeId: string;
9
+ providerType: string;
10
+ category?: SessionHostCategory;
11
+ workspace: string;
12
+ meta?: Record<string, unknown>;
13
+ attachExisting?: boolean;
14
+ }
15
+ export declare class SessionHostPtyTransportFactory implements PtyTransportFactory {
16
+ private readonly options;
17
+ constructor(options: SessionHostPtyTransportFactoryOptions);
18
+ spawn(command: string, args: string[], spawnOptions: PtySpawnOptions): PtyRuntimeTransport;
19
+ }
20
+ export {};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Re-export spawn environment utilities from @adhdev/session-host-core.
3
+ *
4
+ * The canonical implementation lives in session-host-core so that both
5
+ * daemon-core and session-host-daemon can share it. This file exists
6
+ * to keep the import path short within daemon-core consumers.
7
+ */
8
+ export { sanitizeSpawnEnv, applyTerminalColorEnv, ensureNodePtySpawnHelperPermissions, } from '@adhdev/session-host-core';
@@ -0,0 +1,16 @@
1
+ import type { TerminalViewportBackend, TerminalViewportBackendOptions, TerminalViewportBackendPreference } from './types.js';
2
+ export declare function resolveTerminalBackendPreference(): TerminalViewportBackendPreference;
3
+ export declare function isGhosttyVtBackendAvailable(): boolean;
4
+ export declare class GhosttyVtTerminalBackend implements TerminalViewportBackend {
5
+ readonly kind: "ghostty-vt";
6
+ private terminal;
7
+ constructor(options: TerminalViewportBackendOptions);
8
+ resize(rows: number, cols: number): void;
9
+ write(data: string): void;
10
+ getText(): string;
11
+ getCursorPosition(): {
12
+ col: number;
13
+ row: number;
14
+ };
15
+ dispose(): void;
16
+ }
@@ -0,0 +1,18 @@
1
+ export type TerminalViewportBackendKind = 'xterm' | 'ghostty-vt';
2
+ export type TerminalViewportBackendPreference = TerminalViewportBackendKind | 'auto';
3
+ export type TerminalViewportBackendOptions = {
4
+ rows: number;
5
+ cols: number;
6
+ scrollback: number;
7
+ };
8
+ export interface TerminalViewportBackend {
9
+ readonly kind: TerminalViewportBackendKind;
10
+ resize(rows: number, cols: number): void;
11
+ write(data: string): void;
12
+ getText(): string;
13
+ getCursorPosition(): {
14
+ col: number;
15
+ row: number;
16
+ };
17
+ dispose(): void;
18
+ }
@@ -0,0 +1,17 @@
1
+ import type { TerminalViewportBackend, TerminalViewportBackendOptions } from './types.js';
2
+ export declare class XtermTerminalBackend implements TerminalViewportBackend {
3
+ readonly kind: "xterm";
4
+ private rows;
5
+ private cols;
6
+ private terminal;
7
+ constructor(options: TerminalViewportBackendOptions);
8
+ resize(rows: number, cols: number): void;
9
+ write(data: string): void;
10
+ getText(): string;
11
+ getCursorPosition(): {
12
+ col: number;
13
+ row: number;
14
+ };
15
+ dispose(): void;
16
+ private createTerminal;
17
+ }