@adhdev/daemon-core 0.9.76-rc.51 → 0.9.76-rc.52

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.
@@ -1,8 +1,9 @@
1
- import { type SessionHostEndpoint } from '@adhdev/session-host-core';
1
+ import { type SessionHostEndpoint, type SessionHostRequestType } from '@adhdev/session-host-core';
2
2
  import type { HostedCliRuntimeDescriptor } from '../commands/cli-manager.js';
3
3
  export declare function ensureSessionHostReady(options: {
4
4
  appName?: string;
5
5
  spawnHost: () => void;
6
6
  timeoutMs?: number;
7
+ requiredRequestTypes?: readonly SessionHostRequestType[];
7
8
  }): Promise<SessionHostEndpoint>;
8
9
  export declare function listHostedCliRuntimes(endpoint: SessionHostEndpoint): Promise<HostedCliRuntimeDescriptor[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/daemon-core",
3
- "version": "0.9.76-rc.51",
3
+ "version": "0.9.76-rc.52",
4
4
  "description": "ADHDev daemon core — CDP, IDE detection, providers, command execution",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,8 +1,10 @@
1
1
  import {
2
2
  SessionHostClient,
3
3
  getDefaultSessionHostEndpoint,
4
+ type SessionHostDiagnostics,
4
5
  type SessionHostEndpoint,
5
6
  type SessionHostRecord,
7
+ type SessionHostRequestType,
6
8
  } from '@adhdev/session-host-core';
7
9
  import type { HostedCliRuntimeDescriptor } from '../commands/cli-manager.js';
8
10
  import { DEFAULT_SESSION_HOST_READY_TIMEOUT_MS } from '../runtime-defaults.js';
@@ -10,21 +12,65 @@ import { DEFAULT_SESSION_HOST_READY_TIMEOUT_MS } from '../runtime-defaults.js';
10
12
  const STARTUP_TIMEOUT_MS = DEFAULT_SESSION_HOST_READY_TIMEOUT_MS;
11
13
  const STARTUP_POLL_MS = 200;
12
14
 
13
- async function canConnect(endpoint: SessionHostEndpoint): Promise<boolean> {
15
+ class SessionHostCompatibilityError extends Error {
16
+ constructor(message: string) {
17
+ super(message);
18
+ this.name = 'SessionHostCompatibilityError';
19
+ }
20
+ }
21
+
22
+ function getMissingRequestTypes(
23
+ diagnostics: SessionHostDiagnostics | undefined,
24
+ requiredRequestTypes: readonly SessionHostRequestType[],
25
+ ): SessionHostRequestType[] {
26
+ const supported = new Set(diagnostics?.supportedRequestTypes || []);
27
+ return requiredRequestTypes.filter((requestType) => !supported.has(requestType));
28
+ }
29
+
30
+ async function assertRequiredRequestTypes(
31
+ client: SessionHostClient,
32
+ requiredRequestTypes: readonly SessionHostRequestType[],
33
+ ): Promise<void> {
34
+ if (requiredRequestTypes.length === 0) return;
35
+
36
+ const response = await client.request<SessionHostDiagnostics>({
37
+ type: 'get_host_diagnostics',
38
+ payload: { includeSessions: false },
39
+ });
40
+ const missing = getMissingRequestTypes(response.success ? response.result : undefined, requiredRequestTypes);
41
+ if (missing.length > 0) {
42
+ const detail = response.success ? '' : ` (${response.error || 'capability probe failed'})`;
43
+ throw new SessionHostCompatibilityError(
44
+ `Session host does not support required request types: ${missing.join(', ')}${detail}`,
45
+ );
46
+ }
47
+ }
48
+
49
+ async function canConnect(
50
+ endpoint: SessionHostEndpoint,
51
+ requiredRequestTypes: readonly SessionHostRequestType[] = [],
52
+ ): Promise<boolean> {
14
53
  const client = new SessionHostClient({ endpoint });
15
54
  try {
16
55
  await client.connect();
17
- await client.close();
56
+ await assertRequiredRequestTypes(client, requiredRequestTypes);
18
57
  return true;
19
- } catch {
58
+ } catch (error) {
59
+ if (error instanceof SessionHostCompatibilityError) throw error;
20
60
  return false;
61
+ } finally {
62
+ await client.close().catch(() => {});
21
63
  }
22
64
  }
23
65
 
24
- async function waitForReady(endpoint: SessionHostEndpoint, timeoutMs = STARTUP_TIMEOUT_MS): Promise<void> {
66
+ async function waitForReady(
67
+ endpoint: SessionHostEndpoint,
68
+ timeoutMs = STARTUP_TIMEOUT_MS,
69
+ requiredRequestTypes: readonly SessionHostRequestType[] = [],
70
+ ): Promise<void> {
25
71
  const deadline = Date.now() + timeoutMs;
26
72
  while (Date.now() < deadline) {
27
- if (await canConnect(endpoint)) return;
73
+ if (await canConnect(endpoint, requiredRequestTypes)) return;
28
74
  await new Promise((resolve) => setTimeout(resolve, STARTUP_POLL_MS));
29
75
  }
30
76
  throw new Error(`Session host did not become ready within ${timeoutMs}ms`);
@@ -34,11 +80,13 @@ export async function ensureSessionHostReady(options: {
34
80
  appName?: string;
35
81
  spawnHost: () => void;
36
82
  timeoutMs?: number;
83
+ requiredRequestTypes?: readonly SessionHostRequestType[];
37
84
  }): Promise<SessionHostEndpoint> {
38
85
  const endpoint = getDefaultSessionHostEndpoint(options.appName || 'adhdev');
39
- if (await canConnect(endpoint)) return endpoint;
86
+ const requiredRequestTypes = options.requiredRequestTypes || [];
87
+ if (await canConnect(endpoint, requiredRequestTypes)) return endpoint;
40
88
  options.spawnHost();
41
- await waitForReady(endpoint, options.timeoutMs);
89
+ await waitForReady(endpoint, options.timeoutMs, requiredRequestTypes);
42
90
  return endpoint;
43
91
  }
44
92