@ai-development-environment/control-agent 0.0.81 → 0.0.83

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.
@@ -5031,6 +5031,26 @@ var AgentGraphQLClient = class {
5031
5031
  })
5032
5032
  };
5033
5033
  }
5034
+ async ready() {
5035
+ const response = await fetch(`${this.server}/api/auth/config`, {
5036
+ headers: { ...this.headers },
5037
+ signal: AbortSignal.timeout(this.requestTimeoutMs)
5038
+ });
5039
+ const raw = await response.text();
5040
+ let body;
5041
+ try {
5042
+ body = raw ? JSON.parse(raw) : void 0;
5043
+ } catch {
5044
+ body = void 0;
5045
+ }
5046
+ if (!response.ok || typeof body?.mode !== "string") {
5047
+ const detail = `HTTP ${response.status} ${response.statusText}`.trim();
5048
+ throw new Error(
5049
+ !body && raw ? `${detail}: ${raw.slice(0, 500)}` : detail
5050
+ );
5051
+ }
5052
+ return { mode: body.mode };
5053
+ }
5034
5054
  async request(query, variables) {
5035
5055
  const response = await fetch(`${this.server}/api/graphql`, {
5036
5056
  method: "POST",
@@ -8380,6 +8400,7 @@ function captureCommand(options) {
8380
8400
  let cancelled = false;
8381
8401
  let settled = false;
8382
8402
  let killTimer = null;
8403
+ const detached = process.platform !== "win32";
8383
8404
  const child = spawn(options.command, options.args, {
8384
8405
  shell: false,
8385
8406
  stdio: [
@@ -8388,7 +8409,11 @@ function captureCommand(options) {
8388
8409
  "pipe"
8389
8410
  ],
8390
8411
  env: options.env ?? process.env,
8391
- cwd: options.cwd
8412
+ cwd: options.cwd,
8413
+ // Git can leave credential helpers, SSH processes, hooks, or signing
8414
+ // prompts behind. A separate process group lets timeout and cancellation
8415
+ // stop the entire command tree instead of only the immediate Git process.
8416
+ detached
8392
8417
  });
8393
8418
  const append = (current, chunk) => `${current}${String(chunk)}`.slice(0, MAX_OUTPUT_BYTES);
8394
8419
  child.stdout?.on("data", (chunk) => {
@@ -8397,11 +8422,24 @@ function captureCommand(options) {
8397
8422
  child.stderr?.on("data", (chunk) => {
8398
8423
  stderr = append(stderr, chunk);
8399
8424
  });
8425
+ const sendSignal = (signal) => {
8426
+ if (detached && child.pid) {
8427
+ try {
8428
+ process.kill(-child.pid, signal);
8429
+ return;
8430
+ } catch (error) {
8431
+ if (!(error instanceof Error) || !("code" in error) || error.code !== "ESRCH") {
8432
+ throw error;
8433
+ }
8434
+ }
8435
+ }
8436
+ child.kill(signal);
8437
+ };
8400
8438
  const terminate = () => {
8401
8439
  if (child.exitCode !== null || child.killed) return;
8402
- child.kill("SIGTERM");
8440
+ sendSignal("SIGTERM");
8403
8441
  killTimer = setTimeout(() => {
8404
- if (child.exitCode === null) child.kill("SIGKILL");
8442
+ if (child.exitCode === null) sendSignal("SIGKILL");
8405
8443
  }, 5e3);
8406
8444
  killTimer.unref();
8407
8445
  };
@@ -51405,7 +51443,7 @@ async function waitForServer(client2, timeoutMs, signal, dependencies) {
51405
51443
  let lastError;
51406
51444
  while (!signal.aborted && Date.now() < deadline) {
51407
51445
  try {
51408
- await client2.health();
51446
+ await client2.ready();
51409
51447
  return;
51410
51448
  } catch (error) {
51411
51449
  lastError = error;
@@ -51447,10 +51485,15 @@ async function prepareDevelopmentAgent(options, signal, dependencies = defaultDe
51447
51485
  }
51448
51486
  } catch {
51449
51487
  }
51450
- const enrollment2 = await anonymousClient.createEnrollmentToken();
51488
+ const enrollmentToken = options.enrollmentToken?.trim();
51489
+ if (!enrollmentToken) {
51490
+ throw new Error(
51491
+ "The development agent needs a one-time enrollment token. Create one on the Agents page and set CONTROL_AGENT_DEV_ENROLLMENT_TOKEN."
51492
+ );
51493
+ }
51451
51494
  const response = await anonymousClient.enroll({
51452
51495
  ...inventory,
51453
- enrollmentToken: enrollment2.createAgentEnrollmentToken.token,
51496
+ enrollmentToken,
51454
51497
  name
51455
51498
  });
51456
51499
  const config = {
@@ -51684,10 +51727,10 @@ async function doctor() {
51684
51727
  null,
51685
51728
  1e4,
51686
51729
  config?.headers
51687
- ).health();
51730
+ ).ready();
51688
51731
  return {
51689
- ok: health.health === "ok",
51690
- detail: `${endpoint.kind} ${endpoint.server}: ${health.health}`
51732
+ ok: true,
51733
+ detail: `${endpoint.kind} ${endpoint.server}: ready (${health.mode})`
51691
51734
  };
51692
51735
  } catch (error) {
51693
51736
  return {
@@ -51734,7 +51777,8 @@ async function main() {
51734
51777
  {
51735
51778
  server,
51736
51779
  websocketServer: options["websocket-server"] ?? process.env.CONTROL_AGENT_DEV_WEBSOCKET_SERVER ?? process.env.NEXT_PUBLIC_AGENT_WS_URL,
51737
- name: options.name
51780
+ name: options.name,
51781
+ enrollmentToken: options["enrollment-token"] ?? process.env.CONTROL_AGENT_DEV_ENROLLMENT_TOKEN
51738
51782
  },
51739
51783
  controller.signal
51740
51784
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-development-environment/control-agent",
3
- "version": "0.0.81",
3
+ "version": "0.0.83",
4
4
  "description": "Control agent for the AI Development Environment",
5
5
  "license": "MIT",
6
6
  "repository": {