@ai-devkit/daemon-client 0.1.2 → 0.2.0

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.
@@ -498,6 +498,84 @@ describe.runIf(bin != null)("ensureDaemon (real binary)", function() {
498
498
  });
499
499
  })();
500
500
  }, 30000);
501
+ it("startAgent surfaces coded daemon errors", function() {
502
+ return _async_to_generator(function() {
503
+ var tmpHome, prevHome, client;
504
+ return _ts_generator(this, function(_state) {
505
+ switch(_state.label){
506
+ case 0:
507
+ // Isolated HOME guarantees a fresh devkitd at the current build — a
508
+ // stale user daemon on the real socket would answer "unknown method".
509
+ tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), "aidk-home-"));
510
+ prevHome = process.env.HOME;
511
+ process.env.HOME = tmpHome;
512
+ _state.label = 1;
513
+ case 1:
514
+ _state.trys.push([
515
+ 1,
516
+ ,
517
+ 6,
518
+ 7
519
+ ]);
520
+ return [
521
+ 4,
522
+ ensureDaemon({
523
+ waitMs: 20000
524
+ })
525
+ ];
526
+ case 2:
527
+ client = _state.sent();
528
+ expect(client).not.toBeNull();
529
+ // Unknown harness type → harness_not_startable (no spawn attempted).
530
+ return [
531
+ 4,
532
+ expect(client.startAgent({
533
+ type: "nonsense",
534
+ cwd: "/"
535
+ })).rejects.toMatchObject({
536
+ code: "harness_not_startable"
537
+ })
538
+ ];
539
+ case 3:
540
+ _state.sent();
541
+ // Bad name → invalid_params before anything spawns.
542
+ return [
543
+ 4,
544
+ expect(client.startAgent({
545
+ type: "claude",
546
+ name: "BAD NAME",
547
+ cwd: "/"
548
+ })).rejects.toMatchObject({
549
+ code: "invalid_params"
550
+ })
551
+ ];
552
+ case 4:
553
+ _state.sent();
554
+ return [
555
+ 4,
556
+ client.request("shutdown").catch(function() {})
557
+ ];
558
+ case 5:
559
+ _state.sent();
560
+ client.close();
561
+ return [
562
+ 3,
563
+ 7
564
+ ];
565
+ case 6:
566
+ if (prevHome === undefined) delete process.env.HOME;
567
+ else process.env.HOME = prevHome;
568
+ return [
569
+ 7
570
+ ];
571
+ case 7:
572
+ return [
573
+ 2
574
+ ];
575
+ }
576
+ });
577
+ })();
578
+ }, 30000);
501
579
  });
502
580
  describe.runIf(fs.existsSync(sock))("live daemon", function() {
503
581
  it("daemon.status reports version and socket", function() {
@@ -7,5 +7,6 @@ import { DaemonClient } from "./client.js";
7
7
  */
8
8
  export declare function ensureDaemon(opts?: {
9
9
  waitMs?: number;
10
+ onDebug?: (msg: string) => void;
10
11
  }): Promise<DaemonClient | null>;
11
12
  //# sourceMappingURL=autostart.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"autostart.d.ts","sourceRoot":"","sources":["../src/autostart.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAoB,MAAM,aAAa,CAAC;AAG7D;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,IAAI,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CA2D/F"}
1
+ {"version":3,"file":"autostart.d.ts","sourceRoot":"","sources":["../src/autostart.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAoB,MAAM,aAAa,CAAC;AAG7D;;;;;GAKG;AACH,wBAAsB,YAAY,CAChC,IAAI,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;CAAO,GAC9D,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CA4E9B"}
package/dist/autostart.js CHANGED
@@ -138,39 +138,53 @@ import { resolveDaemonBinary } from "./binary.js";
138
138
  * degrade to today's code paths.
139
139
  */ export function ensureDaemon() {
140
140
  return _async_to_generator(function() {
141
- var opts, _opts_waitMs, waitMs, existing, bin, sockPath, dir, STALE_LOCK_MS, lockPath, acquired, logPath, logFd, child;
141
+ var opts, _opts_waitMs, waitMs, debug, existing, bin, sockPath, dir, STALE_LOCK_MS, lockPath, acquired, logPath, logFd, child;
142
142
  var _arguments = arguments;
143
143
  return _ts_generator(this, function(_state) {
144
144
  switch(_state.label){
145
145
  case 0:
146
146
  opts = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : {};
147
147
  waitMs = (_opts_waitMs = opts.waitMs) !== null && _opts_waitMs !== void 0 ? _opts_waitMs : 3000;
148
+ debug = opts.onDebug;
148
149
  // Test runs must never spawn a real daemon. Callers that want to exercise
149
150
  // autostart do so by pointing DEVKITD_BIN at a real binary in an explicit
150
151
  // integration test — the env below is checked there too via VITEST_SKIP.
151
- if (process.env.AI_DEVKIT_NO_DAEMON) return [
152
- 2,
153
- null
154
- ];
152
+ if (process.env.AI_DEVKIT_NO_DAEMON) {
153
+ debug === null || debug === void 0 ? void 0 : debug("daemon path disabled (AI_DEVKIT_NO_DAEMON set)");
154
+ return [
155
+ 2,
156
+ null
157
+ ];
158
+ }
155
159
  return [
156
160
  4,
157
161
  DaemonClient.tryConnect()
158
162
  ];
159
163
  case 1:
160
164
  existing = _state.sent();
161
- if (existing) return [
162
- 2,
163
- existing
164
- ];
165
- if (process.env.VITEST && !process.env.DEVKITD_BIN && !process.env.AI_DEVKITD_BIN) return [
166
- 2,
167
- null
168
- ];
169
- bin = resolveDaemonBinary();
170
- if (!bin) return [
171
- 2,
172
- null
173
- ];
165
+ if (existing) {
166
+ debug === null || debug === void 0 ? void 0 : debug("connected to live daemon at ".concat(daemonSocketPath()));
167
+ return [
168
+ 2,
169
+ existing
170
+ ];
171
+ }
172
+ debug === null || debug === void 0 ? void 0 : debug("no live daemon on socket; attempting autostart");
173
+ if (process.env.VITEST && !process.env.DEVKITD_BIN && !process.env.AI_DEVKITD_BIN) {
174
+ debug === null || debug === void 0 ? void 0 : debug("autostart skipped in test env (VITEST set, no DEVKITD_BIN)");
175
+ return [
176
+ 2,
177
+ null
178
+ ];
179
+ }
180
+ bin = resolveDaemonBinary(debug);
181
+ if (!bin) {
182
+ debug === null || debug === void 0 ? void 0 : debug("no devkitd binary; daemon path unavailable");
183
+ return [
184
+ 2,
185
+ null
186
+ ];
187
+ }
174
188
  sockPath = daemonSocketPath();
175
189
  dir = path.dirname(sockPath);
176
190
  fs.mkdirSync(dir, {
@@ -184,9 +198,10 @@ import { resolveDaemonBinary } from "./binary.js";
184
198
  acquired = acquireSpawnLock(lockPath, STALE_LOCK_MS);
185
199
  if (!acquired) {
186
200
  // Another process is spawning; just wait for the socket.
201
+ debug === null || debug === void 0 ? void 0 : debug("another process is spawning devkitd; waiting for socket");
187
202
  return [
188
203
  2,
189
- waitForSocket(waitMs)
204
+ waitForSocket(waitMs, debug)
190
205
  ];
191
206
  }
192
207
  try {
@@ -205,7 +220,9 @@ import { resolveDaemonBinary } from "./binary.js";
205
220
  });
206
221
  child.unref();
207
222
  fs.closeSync(logFd);
223
+ debug === null || debug === void 0 ? void 0 : debug("spawned devkitd (pid ".concat(child.pid, ") from ").concat(bin, "; waiting for socket"));
208
224
  } catch (unused) {
225
+ debug === null || debug === void 0 ? void 0 : debug("devkitd spawn failed");
209
226
  try {
210
227
  fs.unlinkSync(lockPath);
211
228
  } catch (unused) {
@@ -225,7 +242,7 @@ import { resolveDaemonBinary } from "./binary.js";
225
242
  ]);
226
243
  return [
227
244
  4,
228
- waitForSocket(waitMs)
245
+ waitForSocket(waitMs, debug)
229
246
  ];
230
247
  case 3:
231
248
  return [
@@ -275,7 +292,7 @@ function acquireSpawnLock(lockPath, staleMs) {
275
292
  return false;
276
293
  }
277
294
  }
278
- function waitForSocket(waitMs) {
295
+ function waitForSocket(waitMs, debug) {
279
296
  return _async_to_generator(function() {
280
297
  var deadline, client;
281
298
  return _ts_generator(this, function(_state) {
@@ -294,10 +311,13 @@ function waitForSocket(waitMs) {
294
311
  ];
295
312
  case 2:
296
313
  client = _state.sent();
297
- if (client) return [
298
- 2,
299
- client
300
- ];
314
+ if (client) {
315
+ debug === null || debug === void 0 ? void 0 : debug("devkitd socket ready");
316
+ return [
317
+ 2,
318
+ client
319
+ ];
320
+ }
301
321
  return [
302
322
  4,
303
323
  new Promise(function(r) {
@@ -311,6 +331,7 @@ function waitForSocket(waitMs) {
311
331
  1
312
332
  ];
313
333
  case 4:
334
+ debug === null || debug === void 0 ? void 0 : debug("timed out after ".concat(waitMs, "ms waiting for devkitd socket"));
314
335
  return [
315
336
  2,
316
337
  null
package/dist/binary.d.ts CHANGED
@@ -4,7 +4,8 @@
4
4
  * 2. Platform package `@ai-devkit/devkitd-<plat>-<arch>` (npm optional dep)
5
5
  * 3. ~/.ai-devkit/bin/devkitd (manual install)
6
6
  * 4. rust/target/{release,debug}/devkitd relative to the monorepo (dev)
7
- * Returns null when nothing is found — callers must degrade gracefully.
7
+ * Returns null when nothing is found — callers
8
+ * must degrade gracefully.
8
9
  */
9
- export declare function resolveDaemonBinary(): string | null;
10
+ export declare function resolveDaemonBinary(onDebug?: (msg: string) => void): string | null;
10
11
  //# sourceMappingURL=binary.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"binary.d.ts","sourceRoot":"","sources":["../src/binary.ts"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,GAAG,IAAI,CAmDnD"}
1
+ {"version":3,"file":"binary.d.ts","sourceRoot":"","sources":["../src/binary.ts"],"names":[],"mappings":"AAMA;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,GAAG,IAAI,CAgElF"}
package/dist/binary.js CHANGED
@@ -9,11 +9,15 @@ import { fileURLToPath } from "node:url";
9
9
  * 2. Platform package `@ai-devkit/devkitd-<plat>-<arch>` (npm optional dep)
10
10
  * 3. ~/.ai-devkit/bin/devkitd (manual install)
11
11
  * 4. rust/target/{release,debug}/devkitd relative to the monorepo (dev)
12
- * Returns null when nothing is found — callers must degrade gracefully.
13
- */ export function resolveDaemonBinary() {
12
+ * Returns null when nothing is found — callers
13
+ * must degrade gracefully.
14
+ */ export function resolveDaemonBinary(onDebug) {
14
15
  var _process_env_DEVKITD_BIN;
15
16
  var env = (_process_env_DEVKITD_BIN = process.env.DEVKITD_BIN) !== null && _process_env_DEVKITD_BIN !== void 0 ? _process_env_DEVKITD_BIN : process.env.AI_DEVKITD_BIN;
16
- if (env && fs.existsSync(env)) return env;
17
+ if (env && fs.existsSync(env)) {
18
+ onDebug === null || onDebug === void 0 ? void 0 : onDebug("devkitd binary from env override: ".concat(env));
19
+ return env;
20
+ }
17
21
  var plats = {
18
22
  linux: "linux",
19
23
  darwin: "darwin",
@@ -30,12 +34,18 @@ import { fileURLToPath } from "node:url";
30
34
  var req = createRequire(import.meta.url);
31
35
  var pkgJson = req.resolve("@ai-devkit/devkitd-".concat(plat, "-").concat(arch, "/package.json"));
32
36
  var candidate = path.join(path.dirname(pkgJson), process.platform === "win32" ? "devkitd.exe" : "devkitd");
33
- if (fs.existsSync(candidate)) return candidate;
37
+ if (fs.existsSync(candidate)) {
38
+ onDebug === null || onDebug === void 0 ? void 0 : onDebug("devkitd binary from platform package: ".concat(candidate));
39
+ return candidate;
40
+ }
34
41
  } catch (unused) {
35
42
  /* package not installed */ }
36
43
  }
37
44
  var home = path.join(os.homedir(), ".ai-devkit", "bin", "devkitd");
38
- if (fs.existsSync(home)) return home;
45
+ if (fs.existsSync(home)) {
46
+ onDebug === null || onDebug === void 0 ? void 0 : onDebug("devkitd binary from ~/.ai-devkit/bin: ".concat(home));
47
+ return home;
48
+ }
39
49
  // Dev checkout: walk up to the nearest rust/target/<profile>/devkitd and
40
50
  // pick the freshest profile — a stale release build otherwise shadows a
41
51
  // freshly-built debug binary forever. fileURLToPath so paths containing
@@ -58,10 +68,14 @@ import { fileURLToPath } from "node:url";
58
68
  } catch (unused) {
59
69
  /* absent */ }
60
70
  }
61
- if (best) return best.file;
71
+ if (best) {
72
+ onDebug === null || onDebug === void 0 ? void 0 : onDebug("devkitd binary from dev checkout: ".concat(best.file));
73
+ return best.file;
74
+ }
62
75
  var parent = path.dirname(dir);
63
76
  if (parent === dir) break;
64
77
  dir = parent;
65
78
  }
79
+ onDebug === null || onDebug === void 0 ? void 0 : onDebug("no devkitd binary found in any location");
66
80
  return null;
67
81
  }
package/dist/client.d.ts CHANGED
@@ -1,7 +1,18 @@
1
+ import type { AgentStartParams } from "./gen/AgentStartParams.js";
2
+ import type { AgentStartResult } from "./gen/AgentStartResult.js";
1
3
  import type { EnrichedAgent } from "./gen/EnrichedAgent.js";
2
4
  import type { Event } from "./gen/Event.js";
3
5
  /** Wire event pushed by the daemon — generated from devkit-core via ts-rs. */
4
6
  export type DaemonEvent = Event;
7
+ /**
8
+ * RPC error with the daemon's structured `code`/`details` when present.
9
+ * `code` is undefined for old daemons and local transport failures.
10
+ */
11
+ export declare class DaemonRpcError extends Error {
12
+ readonly code?: string | undefined;
13
+ readonly details?: unknown | undefined;
14
+ constructor(message: string, code?: string | undefined, details?: unknown | undefined);
15
+ }
5
16
  export declare function daemonSocketPath(): string;
6
17
  /**
7
18
  * Line-delimited JSON-RPC client for devkitd. One request per line;
@@ -25,7 +36,7 @@ export declare class DaemonClient {
25
36
  static connect(socketPath?: string, timeoutMs?: number, requestTimeoutMs?: number): Promise<DaemonClient>;
26
37
  /** Null when the socket is absent/unreachable — callers fall back. */
27
38
  static tryConnect(socketPath?: string): Promise<DaemonClient | null>;
28
- request(method: string, params?: unknown): Promise<unknown>;
39
+ request(method: string, params?: unknown, timeoutMs?: number): Promise<unknown>;
29
40
  subscribe(handler: (e: DaemonEvent) => void, opts?: {
30
41
  afterSeq?: number;
31
42
  liveOnly?: boolean;
@@ -36,6 +47,12 @@ export declare class DaemonClient {
36
47
  * to local adapters for the whole call, not per-agent.
37
48
  */
38
49
  listAgents(): Promise<EnrichedAgent[]>;
50
+ /**
51
+ * Daemon-side agent start — the daemon validates, spawns via the selected
52
+ * runtime, registers the agent, and emits agent.started. The request
53
+ * timeout covers the pid-resolution deadline plus a margin.
54
+ */
55
+ startAgent(params: AgentStartParams): Promise<AgentStartResult>;
39
56
  private onData;
40
57
  /** Reject every in-flight request and mark the socket dead. Idempotent. */
41
58
  private onSocketDead;
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,8EAA8E;AAC9E,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC;AAEhC,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAQD;;;GAGG;AACH,qBAAa,YAAY;IAcrB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,gBAAgB;IAd1B,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,OAAO,CAA8B;IAC7C,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,OAAO,CAA2C;IAC1D;;;;OAIG;IACH,YAAY,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAQ;IAEzC,OAAO;IAKP,MAAM,CAAC,OAAO,CACZ,UAAU,SAAqB,EAC/B,SAAS,SAAO,EAChB,gBAAgB,SAAS,GACxB,OAAO,CAAC,YAAY,CAAC;IA0BxB,sEAAsE;WACzD,UAAU,CAAC,UAAU,SAAqB,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAQtF,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,OAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAgBzD,SAAS,CACb,OAAO,EAAE,CAAC,CAAC,EAAE,WAAW,KAAK,IAAI,EACjC,IAAI,GAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAO,GACnD,OAAO,CAAC,IAAI,CAAC;IAKhB;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;IAI5C,OAAO,CAAC,MAAM;IA2Bd,2EAA2E;IAC3E,OAAO,CAAC,YAAY;IAYpB,KAAK;CAYN"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,8EAA8E;AAC9E,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC;AAEhC;;;GAGG;AACH,qBAAa,cAAe,SAAQ,KAAK;IAGrC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO;gBAF1B,OAAO,EAAE,MAAM,EACN,IAAI,CAAC,EAAE,MAAM,YAAA,EACb,OAAO,CAAC,EAAE,OAAO,YAAA;CAK7B;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAQD;;;GAGG;AACH,qBAAa,YAAY;IAcrB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,gBAAgB;IAd1B,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,OAAO,CAA8B;IAC7C,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,OAAO,CAA2C;IAC1D;;;;OAIG;IACH,YAAY,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAQ;IAEzC,OAAO;IAKP,MAAM,CAAC,OAAO,CACZ,UAAU,SAAqB,EAC/B,SAAS,SAAO,EAChB,gBAAgB,SAAS,GACxB,OAAO,CAAC,YAAY,CAAC;IA0BxB,sEAAsE;WACzD,UAAU,CAAC,UAAU,SAAqB,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAQtF,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,OAAY,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAgB7E,SAAS,CACb,OAAO,EAAE,CAAC,CAAC,EAAE,WAAW,KAAK,IAAI,EACjC,IAAI,GAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAO,GACnD,OAAO,CAAC,IAAI,CAAC;IAKhB;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;IAI5C;;;;OAIG;IACG,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAKrE,OAAO,CAAC,MAAM;IA8Bd,2EAA2E;IAC3E,OAAO,CAAC,YAAY;IAYpB,KAAK;CAYN"}
package/dist/client.js CHANGED
@@ -6,6 +6,12 @@ function _array_like_to_array(arr, len) {
6
6
  function _array_without_holes(arr) {
7
7
  if (Array.isArray(arr)) return _array_like_to_array(arr);
8
8
  }
9
+ function _assert_this_initialized(self) {
10
+ if (self === void 0) {
11
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
12
+ }
13
+ return self;
14
+ }
9
15
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
16
  try {
11
17
  var info = gen[key](arg);
@@ -35,11 +41,32 @@ function _async_to_generator(fn) {
35
41
  });
36
42
  };
37
43
  }
44
+ function _call_super(_this, derived, args) {
45
+ derived = _get_prototype_of(derived);
46
+ return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
47
+ }
38
48
  function _class_call_check(instance, Constructor) {
39
49
  if (!(instance instanceof Constructor)) {
40
50
  throw new TypeError("Cannot call a class as a function");
41
51
  }
42
52
  }
53
+ function _construct(Parent, args, Class) {
54
+ if (_is_native_reflect_construct()) {
55
+ _construct = Reflect.construct;
56
+ } else {
57
+ _construct = function construct(Parent, args, Class) {
58
+ var a = [
59
+ null
60
+ ];
61
+ a.push.apply(a, args);
62
+ var Constructor = Function.bind.apply(Parent, a);
63
+ var instance = new Constructor();
64
+ if (Class) _set_prototype_of(instance, Class.prototype);
65
+ return instance;
66
+ };
67
+ }
68
+ return _construct.apply(null, arguments);
69
+ }
43
70
  function _defineProperties(target, props) {
44
71
  for(var i = 0; i < props.length; i++){
45
72
  var descriptor = props[i];
@@ -67,15 +94,54 @@ function _define_property(obj, key, value) {
67
94
  }
68
95
  return obj;
69
96
  }
97
+ function _get_prototype_of(o) {
98
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
99
+ return o.__proto__ || Object.getPrototypeOf(o);
100
+ };
101
+ return _get_prototype_of(o);
102
+ }
103
+ function _inherits(subClass, superClass) {
104
+ if (typeof superClass !== "function" && superClass !== null) {
105
+ throw new TypeError("Super expression must either be null or a function");
106
+ }
107
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
108
+ constructor: {
109
+ value: subClass,
110
+ writable: true,
111
+ configurable: true
112
+ }
113
+ });
114
+ if (superClass) _set_prototype_of(subClass, superClass);
115
+ }
116
+ function _is_native_function(fn) {
117
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
118
+ }
70
119
  function _iterable_to_array(iter) {
71
120
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
72
121
  }
73
122
  function _non_iterable_spread() {
74
123
  throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
75
124
  }
125
+ function _possible_constructor_return(self, call) {
126
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
127
+ return call;
128
+ }
129
+ return _assert_this_initialized(self);
130
+ }
131
+ function _set_prototype_of(o, p) {
132
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
133
+ o.__proto__ = p;
134
+ return o;
135
+ };
136
+ return _set_prototype_of(o, p);
137
+ }
76
138
  function _to_consumable_array(arr) {
77
139
  return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
78
140
  }
141
+ function _type_of(obj) {
142
+ "@swc/helpers - typeof";
143
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
144
+ }
79
145
  function _unsupported_iterable_to_array(o, minLen) {
80
146
  if (!o) return;
81
147
  if (typeof o === "string") return _array_like_to_array(o, minLen);
@@ -84,6 +150,40 @@ function _unsupported_iterable_to_array(o, minLen) {
84
150
  if (n === "Map" || n === "Set") return Array.from(n);
85
151
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
86
152
  }
153
+ function _wrap_native_super(Class) {
154
+ var _cache = typeof Map === "function" ? new Map() : undefined;
155
+ _wrap_native_super = function wrapNativeSuper(Class) {
156
+ if (Class === null || !_is_native_function(Class)) return Class;
157
+ if (typeof Class !== "function") {
158
+ throw new TypeError("Super expression must either be null or a function");
159
+ }
160
+ if (typeof _cache !== "undefined") {
161
+ if (_cache.has(Class)) return _cache.get(Class);
162
+ _cache.set(Class, Wrapper);
163
+ }
164
+ function Wrapper() {
165
+ return _construct(Class, arguments, _get_prototype_of(this).constructor);
166
+ }
167
+ Wrapper.prototype = Object.create(Class.prototype, {
168
+ constructor: {
169
+ value: Wrapper,
170
+ enumerable: false,
171
+ writable: true,
172
+ configurable: true
173
+ }
174
+ });
175
+ return _set_prototype_of(Wrapper, Class);
176
+ };
177
+ return _wrap_native_super(Class);
178
+ }
179
+ function _is_native_reflect_construct() {
180
+ try {
181
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
182
+ } catch (_) {}
183
+ return (_is_native_reflect_construct = function() {
184
+ return !!result;
185
+ })();
186
+ }
87
187
  function _ts_generator(thisArg, body) {
88
188
  var f, y, t, _ = {
89
189
  label: 0,
@@ -186,6 +286,23 @@ function _ts_generator(thisArg, body) {
186
286
  import * as net from "node:net";
187
287
  import * as os from "node:os";
188
288
  import * as path from "node:path";
289
+ /**
290
+ * RPC error with the daemon's structured `code`/`details` when present.
291
+ * `code` is undefined for old daemons and local transport failures.
292
+ */ export var DaemonRpcError = /*#__PURE__*/ function(Error1) {
293
+ "use strict";
294
+ _inherits(DaemonRpcError, Error1);
295
+ function DaemonRpcError(message, code, details) {
296
+ _class_call_check(this, DaemonRpcError);
297
+ var _this;
298
+ _this = _call_super(this, DaemonRpcError, [
299
+ message
300
+ ]), _define_property(_this, "code", void 0), _define_property(_this, "details", void 0), _this.code = code, _this.details = details;
301
+ _this.name = "DaemonRpcError";
302
+ return _this;
303
+ }
304
+ return DaemonRpcError;
305
+ }(_wrap_native_super(Error));
189
306
  export function daemonSocketPath() {
190
307
  return path.join(os.homedir(), ".ai-devkit", "daemon.sock");
191
308
  }
@@ -223,7 +340,7 @@ export function daemonSocketPath() {
223
340
  key: "request",
224
341
  value: function request(method) {
225
342
  var _this = this;
226
- var params = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
343
+ var params = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, timeoutMs = arguments.length > 2 ? arguments[2] : void 0;
227
344
  if (!this.socket) return Promise.reject(new Error("not connected"));
228
345
  var id = this.nextId++;
229
346
  return new Promise(function(resolve, reject) {
@@ -233,7 +350,7 @@ export function daemonSocketPath() {
233
350
  if (_this.pending.delete(id)) {
234
351
  reject(new Error('daemon request "'.concat(method, '" timed out')));
235
352
  }
236
- }, _this.requestTimeoutMs);
353
+ }, timeoutMs !== null && timeoutMs !== void 0 ? timeoutMs : _this.requestTimeoutMs);
237
354
  _this.pending.set(id, {
238
355
  resolve: resolve,
239
356
  reject: reject,
@@ -300,6 +417,33 @@ export function daemonSocketPath() {
300
417
  }).call(this);
301
418
  }
302
419
  },
420
+ {
421
+ key: "startAgent",
422
+ value: /**
423
+ * Daemon-side agent start — the daemon validates, spawns via the selected
424
+ * runtime, registers the agent, and emits agent.started. The request
425
+ * timeout covers the pid-resolution deadline plus a margin.
426
+ */ function startAgent(params) {
427
+ return _async_to_generator(function() {
428
+ var _params_timeoutMs, timeoutMs;
429
+ return _ts_generator(this, function(_state) {
430
+ switch(_state.label){
431
+ case 0:
432
+ timeoutMs = Number((_params_timeoutMs = params.timeoutMs) !== null && _params_timeoutMs !== void 0 ? _params_timeoutMs : 15000) + 15000;
433
+ return [
434
+ 4,
435
+ this.request("agent.start", params, timeoutMs)
436
+ ];
437
+ case 1:
438
+ return [
439
+ 2,
440
+ _state.sent()
441
+ ];
442
+ }
443
+ });
444
+ }).call(this);
445
+ }
446
+ },
303
447
  {
304
448
  key: "onData",
305
449
  value: function onData(chunk) {
@@ -325,7 +469,7 @@ export function daemonSocketPath() {
325
469
  if (!p) continue;
326
470
  this.pending.delete(id);
327
471
  clearTimeout(p.timer);
328
- if (msg.error) p.reject(new Error(String(msg.error)));
472
+ if (msg.error) p.reject(new DaemonRpcError(String(msg.error), msg.code, msg.details));
329
473
  else p.resolve(msg.result);
330
474
  }
331
475
  }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Params for `agent.start`. Mirrors the TS `StartAgentOptions` surface that
3
+ * crosses the wire — `runtime` is the provider ("tmux" | "herdr"), resolved
4
+ * client-side from config.
5
+ */
6
+ export type AgentStartParams = {
7
+ type: string;
8
+ name?: string;
9
+ cwd: string;
10
+ runtime?: string;
11
+ args?: Array<string>;
12
+ timeoutMs?: number;
13
+ pollIntervalMs?: number;
14
+ };
15
+ //# sourceMappingURL=AgentStartParams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentStartParams.d.ts","sourceRoot":"","sources":["../../src/gen/AgentStartParams.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAAE,CAAC"}
@@ -0,0 +1,6 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ /**
3
+ * Params for `agent.start`. Mirrors the TS `StartAgentOptions` surface that
4
+ * crosses the wire — `runtime` is the provider ("tmux" | "herdr"), resolved
5
+ * client-side from config.
6
+ */ export { };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * `agent.start` result — the registered entry plus non-fatal warnings the
3
+ * CLI renders verbatim.
4
+ */
5
+ export type AgentStartResult = {
6
+ name: string;
7
+ type: string;
8
+ pid: number;
9
+ runtime: string;
10
+ runtimeRef: unknown;
11
+ cwd: string;
12
+ startedAt: string;
13
+ warnings: Array<string>;
14
+ };
15
+ //# sourceMappingURL=AgentStartResult.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentStartResult.d.ts","sourceRoot":"","sources":["../../src/gen/AgentStartResult.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CAAE,CAAC"}
@@ -0,0 +1,5 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ /**
3
+ * `agent.start` result — the registered entry plus non-fatal warnings the
4
+ * CLI renders verbatim.
5
+ */ export { };
@@ -2,5 +2,14 @@ export type Response = {
2
2
  id?: number;
3
3
  result?: unknown;
4
4
  error?: string;
5
+ /**
6
+ * Machine-readable error code (e.g. "name_in_use"). Absent on legacy
7
+ * errors — clients must handle its absence.
8
+ */
9
+ code?: string;
10
+ /**
11
+ * Structured error context (pid, command, timeoutMs, ...).
12
+ */
13
+ details?: unknown;
5
14
  };
6
15
  //# sourceMappingURL=Response.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Response.d.ts","sourceRoot":"","sources":["../../src/gen/Response.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CAAE,CAAC"}
1
+ {"version":3,"file":"Response.d.ts","sourceRoot":"","sources":["../../src/gen/Response.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACvE;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CAAE,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
- export { DaemonClient, daemonSocketPath } from "./client.js";
1
+ export { DaemonClient, daemonSocketPath, DaemonRpcError } from "./client.js";
2
2
  export type { DaemonEvent } from "./client.js";
3
+ export type { AgentStartParams } from "./gen/AgentStartParams.js";
4
+ export type { AgentStartResult } from "./gen/AgentStartResult.js";
3
5
  export type { EnrichedAgent, Event } from "./gen/index.js";
4
6
  export { resolveDaemonBinary } from "./binary.js";
5
7
  export { ensureDaemon } from "./autostart.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC7D,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7E,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,YAAY,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { DaemonClient, daemonSocketPath } from "./client.js";
1
+ export { DaemonClient, daemonSocketPath, DaemonRpcError } from "./client.js";
2
2
  export { resolveDaemonBinary } from "./binary.js";
3
3
  export { ensureDaemon } from "./autostart.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-devkit/daemon-client",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Thin client for the devkitd coordination daemon (unix socket, JSON-RPC, subscribe)",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -38,9 +38,9 @@
38
38
  "vitest": "^4.1.8"
39
39
  },
40
40
  "optionalDependencies": {
41
- "@ai-devkit/devkitd-darwin-arm64": "0.1.2",
42
- "@ai-devkit/devkitd-darwin-x64": "0.1.2",
43
- "@ai-devkit/devkitd-linux-arm64": "0.1.2",
44
- "@ai-devkit/devkitd-linux-x64": "0.1.2"
41
+ "@ai-devkit/devkitd-darwin-arm64": "0.2.0",
42
+ "@ai-devkit/devkitd-darwin-x64": "0.2.0",
43
+ "@ai-devkit/devkitd-linux-arm64": "0.2.0",
44
+ "@ai-devkit/devkitd-linux-x64": "0.2.0"
45
45
  }
46
46
  }