chatroom-cli 1.37.1 → 1.37.3

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.
package/dist/index.js CHANGED
@@ -11035,7 +11035,13 @@ class CopilotStreamReader {
11035
11035
  }
11036
11036
  var DONE_MARKER = "Done.", SKIP_PREFIXES;
11037
11037
  var init_copilot_stream_reader = __esm(() => {
11038
- SKIP_PREFIXES = ["Total usage est:", "API time spent:", "Total session time:", "Total code changes:", "Breakdown by AI model:"];
11038
+ SKIP_PREFIXES = [
11039
+ "Total usage est:",
11040
+ "API time spent:",
11041
+ "Total session time:",
11042
+ "Total code changes:",
11043
+ "Breakdown by AI model:"
11044
+ ];
11039
11045
  });
11040
11046
 
11041
11047
  // src/infrastructure/services/remote-agents/copilot/copilot-agent-service.ts
@@ -14048,11 +14054,21 @@ function getErrorMessage(error) {
14048
14054
  }
14049
14055
  if (error.data !== null && typeof error.data === "object") {
14050
14056
  const data = error.data;
14051
- return data.message ?? data.code ?? String(error.data);
14057
+ const base = data.message ?? data.code ?? String(error.data);
14058
+ const parts = [base];
14059
+ if (Array.isArray(data.fields) && data.fields.length > 0) {
14060
+ parts.push(` offending fields: ${data.fields.join(", ")}`);
14061
+ }
14062
+ return parts.join(`
14063
+ `);
14052
14064
  }
14053
14065
  return String(error.data);
14054
14066
  }
14055
14067
  if (error instanceof Error) {
14068
+ if (error.message.includes("Server Error")) {
14069
+ return `${error.message}
14070
+ hint: ${SERVER_ERROR_HINT}`;
14071
+ }
14056
14072
  return error.message;
14057
14073
  }
14058
14074
  if (error === null || error === undefined) {
@@ -14060,8 +14076,10 @@ function getErrorMessage(error) {
14060
14076
  }
14061
14077
  return String(error);
14062
14078
  }
14079
+ var SERVER_ERROR_HINT;
14063
14080
  var init_convex_error = __esm(() => {
14064
14081
  init_values();
14082
+ SERVER_ERROR_HINT = "This is a generic server error — likely a backend arg-validator rejection or a CLI/backend version mismatch." + " Verify the CLI and backend are on the same commit (run `pnpm install` and check `git log -1 origin/master`).";
14065
14083
  });
14066
14084
 
14067
14085
  // src/commands/auth-status/index.ts
@@ -53659,18 +53677,171 @@ var init_cli = __esm(() => {
53659
53677
  var BACKEND_ERROR_CODES, FATAL_ERROR_CODES, NON_FATAL_ERROR_CODES;
53660
53678
  var init_errorCodes = __esm(() => {
53661
53679
  BACKEND_ERROR_CODES = {
53662
- PARTICIPANT_NOT_FOUND: "PARTICIPANT_NOT_FOUND",
53663
- CHATROOM_NOT_FOUND: "CHATROOM_NOT_FOUND",
53664
53680
  SESSION_INVALID: "SESSION_INVALID",
53665
- CONTEXT_NO_HANDOFF_SINCE_LAST_CONTEXT: "CONTEXT_NO_HANDOFF_SINCE_LAST_CONTEXT"
53681
+ FEATURE_DISABLED: "FEATURE_DISABLED",
53682
+ NOT_AUTHENTICATED: "NOT_AUTHENTICATED",
53683
+ UNAUTHORIZED: "UNAUTHORIZED",
53684
+ FORBIDDEN: "FORBIDDEN",
53685
+ ACCESS_DENIED: "ACCESS_DENIED",
53686
+ AUTH_FAILED: "AUTH_FAILED",
53687
+ EMAIL_ALREADY_EXISTS: "EMAIL_ALREADY_EXISTS",
53688
+ NO_GOOGLE_ACCOUNT: "NO_GOOGLE_ACCOUNT",
53689
+ GOOGLE_ACCOUNT_IN_USE: "GOOGLE_ACCOUNT_IN_USE",
53690
+ INVALID_USER_TYPE: "INVALID_USER_TYPE",
53691
+ USER_TYPE_MISMATCH: "USER_TYPE_MISMATCH",
53692
+ USER_NOT_FOUND: "USER_NOT_FOUND",
53693
+ OAUTH_ERROR: "OAUTH_ERROR",
53694
+ LOGIN_ERROR: "LOGIN_ERROR",
53695
+ CHATROOM_NOT_FOUND: "CHATROOM_NOT_FOUND",
53696
+ TEAM_REQUIRED: "TEAM_REQUIRED",
53697
+ CONFIGURATION_ERROR: "CONFIGURATION_ERROR",
53698
+ PARTICIPANT_NOT_FOUND: "PARTICIPANT_NOT_FOUND",
53699
+ CONTEXT_NO_HANDOFF_SINCE_LAST_CONTEXT: "CONTEXT_NO_HANDOFF_SINCE_LAST_CONTEXT",
53700
+ CONTEXT_NOT_FOUND: "CONTEXT_NOT_FOUND",
53701
+ CONTEXT_RESTRICTED: "CONTEXT_RESTRICTED",
53702
+ INVALID_ROLE: "INVALID_ROLE",
53703
+ INVALID_CONTENT: "INVALID_CONTENT",
53704
+ MISSING_CLASSIFICATION: "MISSING_CLASSIFICATION",
53705
+ MESSAGE_NOT_CLASSIFIED: "MESSAGE_NOT_CLASSIFIED",
53706
+ VALIDATION_ERROR: "VALIDATION_ERROR",
53707
+ UNKNOWN_PARAM: "UNKNOWN_PARAM",
53708
+ INVALID_CONVERSION: "INVALID_CONVERSION",
53709
+ INVALID_STATE: "INVALID_STATE",
53710
+ INVALID_STDIN_FORMAT: "INVALID_STDIN_FORMAT",
53711
+ MISSING_STDIN: "MISSING_STDIN",
53712
+ MISSING_SPECIFICATION: "MISSING_SPECIFICATION",
53713
+ TASK_NOT_FOUND: "TASK_NOT_FOUND",
53714
+ INVALID_TASK: "INVALID_TASK",
53715
+ QUEUED_MESSAGE_NOT_FOUND: "QUEUED_MESSAGE_NOT_FOUND",
53716
+ INVALID_TASK_STATUS: "INVALID_TASK_STATUS",
53717
+ TASK_INVALID_TRANSITION: "TASK_INVALID_TRANSITION",
53718
+ TASK_MISSING_REQUIRED_FIELD: "TASK_MISSING_REQUIRED_FIELD",
53719
+ TASK_VALIDATION_FAILED: "TASK_VALIDATION_FAILED",
53720
+ BACKLOG_ITEM_NOT_FOUND: "BACKLOG_ITEM_NOT_FOUND",
53721
+ BACKLOG_ITEM_WRONG_CHATROOM: "BACKLOG_ITEM_WRONG_CHATROOM",
53722
+ BACKLOG_INVALID_TRANSITION: "BACKLOG_INVALID_TRANSITION",
53723
+ BACKLOG_MISSING_REQUIRED_FIELD: "BACKLOG_MISSING_REQUIRED_FIELD",
53724
+ BACKLOG_VALIDATION_FAILED: "BACKLOG_VALIDATION_FAILED",
53725
+ CONTENT_EMPTY: "CONTENT_EMPTY",
53726
+ REASON_EMPTY: "REASON_EMPTY",
53727
+ NOT_AUTHORIZED_MACHINE: "NOT_AUTHORIZED_MACHINE",
53728
+ COMMAND_NOT_FOUND: "COMMAND_NOT_FOUND",
53729
+ COMMAND_NOT_DISCOVERED: "COMMAND_NOT_DISCOVERED",
53730
+ RUN_NOT_FOUND: "RUN_NOT_FOUND",
53731
+ RUN_WRONG_MACHINE: "RUN_WRONG_MACHINE",
53732
+ COMMAND_NOT_RUNNING: "COMMAND_NOT_RUNNING",
53733
+ TOO_MANY_COMMANDS: "TOO_MANY_COMMANDS",
53734
+ INVALID_STATE_TRANSITION: "INVALID_STATE_TRANSITION",
53735
+ OUTPUT_CHUNK_TOO_LARGE: "OUTPUT_CHUNK_TOO_LARGE",
53736
+ NOT_FOUND: "NOT_FOUND",
53737
+ INVALID_BOT_TOKEN: "INVALID_BOT_TOKEN",
53738
+ WEBHOOK_REGISTRATION_FAILED: "WEBHOOK_REGISTRATION_FAILED",
53739
+ WEBHOOK_REMOVAL_FAILED: "WEBHOOK_REMOVAL_FAILED",
53740
+ WORKFLOW_REQUIRED: "WORKFLOW_REQUIRED",
53741
+ ALREADY_CONNECTED: "ALREADY_CONNECTED",
53742
+ CONNECT_ERROR: "CONNECT_ERROR",
53743
+ UNSAFE_DISCONNECT: "UNSAFE_DISCONNECT",
53744
+ HANDOFF_RESTRICTED: "HANDOFF_RESTRICTED",
53745
+ CHATROOM_NO_TEAM_ID: "CHATROOM_NO_TEAM_ID",
53746
+ SKILL_NOT_FOUND_OR_DISABLED: "SKILL_NOT_FOUND_OR_DISABLED",
53747
+ MISSING_FEATURE_METADATA: "MISSING_FEATURE_METADATA",
53748
+ COMMAND_NAME_EMPTY: "COMMAND_NAME_EMPTY",
53749
+ SAVED_COMMAND_NOT_FOUND: "SAVED_COMMAND_NOT_FOUND",
53750
+ COMMAND_TYPE_IMMUTABLE: "COMMAND_TYPE_IMMUTABLE",
53751
+ NAME_REQUIRED: "NAME_REQUIRED",
53752
+ ATTENDANCE_NOT_FOUND: "ATTENDANCE_NOT_FOUND",
53753
+ ATTENDANCE_DELETE_UNAUTHORIZED: "ATTENDANCE_DELETE_UNAUTHORIZED",
53754
+ ITEM_NOT_FOUND: "ITEM_NOT_FOUND",
53755
+ INVALID_ITEM: "INVALID_ITEM",
53756
+ INVALID_ITEM_STATUS: "INVALID_ITEM_STATUS",
53757
+ INVALID_MESSAGE: "INVALID_MESSAGE",
53758
+ MESSAGE_NOT_FOUND: "MESSAGE_NOT_FOUND",
53759
+ CONFLICT: "CONFLICT"
53666
53760
  };
53667
53761
  FATAL_ERROR_CODES = [
53668
53762
  BACKEND_ERROR_CODES.PARTICIPANT_NOT_FOUND,
53669
53763
  BACKEND_ERROR_CODES.CHATROOM_NOT_FOUND,
53670
- BACKEND_ERROR_CODES.SESSION_INVALID
53764
+ BACKEND_ERROR_CODES.SESSION_INVALID,
53765
+ BACKEND_ERROR_CODES.NOT_AUTHENTICATED,
53766
+ BACKEND_ERROR_CODES.UNAUTHORIZED,
53767
+ BACKEND_ERROR_CODES.FORBIDDEN,
53768
+ BACKEND_ERROR_CODES.ACCESS_DENIED,
53769
+ BACKEND_ERROR_CODES.AUTH_FAILED,
53770
+ BACKEND_ERROR_CODES.NO_GOOGLE_ACCOUNT,
53771
+ BACKEND_ERROR_CODES.GOOGLE_ACCOUNT_IN_USE,
53772
+ BACKEND_ERROR_CODES.USER_TYPE_MISMATCH,
53773
+ BACKEND_ERROR_CODES.INVALID_USER_TYPE,
53774
+ BACKEND_ERROR_CODES.FEATURE_DISABLED
53671
53775
  ];
53672
53776
  NON_FATAL_ERROR_CODES = [
53673
- BACKEND_ERROR_CODES.CONTEXT_NO_HANDOFF_SINCE_LAST_CONTEXT
53777
+ BACKEND_ERROR_CODES.CONTEXT_NO_HANDOFF_SINCE_LAST_CONTEXT,
53778
+ BACKEND_ERROR_CODES.CONTEXT_NOT_FOUND,
53779
+ BACKEND_ERROR_CODES.CONTEXT_RESTRICTED,
53780
+ BACKEND_ERROR_CODES.HANDOFF_RESTRICTED,
53781
+ BACKEND_ERROR_CODES.BACKLOG_ITEM_NOT_FOUND,
53782
+ BACKEND_ERROR_CODES.TASK_NOT_FOUND,
53783
+ BACKEND_ERROR_CODES.QUEUED_MESSAGE_NOT_FOUND,
53784
+ BACKEND_ERROR_CODES.ITEM_NOT_FOUND,
53785
+ BACKEND_ERROR_CODES.MESSAGE_NOT_FOUND,
53786
+ BACKEND_ERROR_CODES.CONTEXT_NOT_FOUND,
53787
+ BACKEND_ERROR_CODES.SAVED_COMMAND_NOT_FOUND,
53788
+ BACKEND_ERROR_CODES.RUN_NOT_FOUND,
53789
+ BACKEND_ERROR_CODES.COMMAND_NOT_FOUND,
53790
+ BACKEND_ERROR_CODES.ATTENDANCE_NOT_FOUND,
53791
+ BACKEND_ERROR_CODES.USER_NOT_FOUND,
53792
+ BACKEND_ERROR_CODES.NOT_FOUND,
53793
+ BACKEND_ERROR_CODES.CONTENT_EMPTY,
53794
+ BACKEND_ERROR_CODES.REASON_EMPTY,
53795
+ BACKEND_ERROR_CODES.NAME_REQUIRED,
53796
+ BACKEND_ERROR_CODES.COMMAND_NAME_EMPTY,
53797
+ BACKEND_ERROR_CODES.MISSING_CLASSIFICATION,
53798
+ BACKEND_ERROR_CODES.MESSAGE_NOT_CLASSIFIED,
53799
+ BACKEND_ERROR_CODES.INVALID_CONTENT,
53800
+ BACKEND_ERROR_CODES.INVALID_ROLE,
53801
+ BACKEND_ERROR_CODES.INVALID_TASK,
53802
+ BACKEND_ERROR_CODES.INVALID_TASK_STATUS,
53803
+ BACKEND_ERROR_CODES.INVALID_ITEM,
53804
+ BACKEND_ERROR_CODES.INVALID_ITEM_STATUS,
53805
+ BACKEND_ERROR_CODES.INVALID_MESSAGE,
53806
+ BACKEND_ERROR_CODES.INVALID_STATE,
53807
+ BACKEND_ERROR_CODES.INVALID_CONVERSION,
53808
+ BACKEND_ERROR_CODES.INVALID_STDIN_FORMAT,
53809
+ BACKEND_ERROR_CODES.INVALID_BOT_TOKEN,
53810
+ BACKEND_ERROR_CODES.INVALID_STATE_TRANSITION,
53811
+ BACKEND_ERROR_CODES.TASK_INVALID_TRANSITION,
53812
+ BACKEND_ERROR_CODES.TASK_MISSING_REQUIRED_FIELD,
53813
+ BACKEND_ERROR_CODES.TASK_VALIDATION_FAILED,
53814
+ BACKEND_ERROR_CODES.BACKLOG_INVALID_TRANSITION,
53815
+ BACKEND_ERROR_CODES.BACKLOG_ITEM_WRONG_CHATROOM,
53816
+ BACKEND_ERROR_CODES.BACKLOG_MISSING_REQUIRED_FIELD,
53817
+ BACKEND_ERROR_CODES.BACKLOG_VALIDATION_FAILED,
53818
+ BACKEND_ERROR_CODES.SKILL_NOT_FOUND_OR_DISABLED,
53819
+ BACKEND_ERROR_CODES.MISSING_FEATURE_METADATA,
53820
+ BACKEND_ERROR_CODES.MISSING_SPECIFICATION,
53821
+ BACKEND_ERROR_CODES.MISSING_STDIN,
53822
+ BACKEND_ERROR_CODES.UNKNOWN_PARAM,
53823
+ BACKEND_ERROR_CODES.VALIDATION_ERROR,
53824
+ BACKEND_ERROR_CODES.OUTPUT_CHUNK_TOO_LARGE,
53825
+ BACKEND_ERROR_CODES.TOO_MANY_COMMANDS,
53826
+ BACKEND_ERROR_CODES.COMMAND_NOT_DISCOVERED,
53827
+ BACKEND_ERROR_CODES.COMMAND_NOT_RUNNING,
53828
+ BACKEND_ERROR_CODES.RUN_WRONG_MACHINE,
53829
+ BACKEND_ERROR_CODES.COMMAND_TYPE_IMMUTABLE,
53830
+ BACKEND_ERROR_CODES.NOT_AUTHORIZED_MACHINE,
53831
+ BACKEND_ERROR_CODES.ATTENDANCE_DELETE_UNAUTHORIZED,
53832
+ BACKEND_ERROR_CODES.CONFLICT,
53833
+ BACKEND_ERROR_CODES.EMAIL_ALREADY_EXISTS,
53834
+ BACKEND_ERROR_CODES.ALREADY_CONNECTED,
53835
+ BACKEND_ERROR_CODES.CONNECT_ERROR,
53836
+ BACKEND_ERROR_CODES.UNSAFE_DISCONNECT,
53837
+ BACKEND_ERROR_CODES.CONFIGURATION_ERROR,
53838
+ BACKEND_ERROR_CODES.CHATROOM_NO_TEAM_ID,
53839
+ BACKEND_ERROR_CODES.TEAM_REQUIRED,
53840
+ BACKEND_ERROR_CODES.WEBHOOK_REGISTRATION_FAILED,
53841
+ BACKEND_ERROR_CODES.WEBHOOK_REMOVAL_FAILED,
53842
+ BACKEND_ERROR_CODES.OAUTH_ERROR,
53843
+ BACKEND_ERROR_CODES.LOGIN_ERROR,
53844
+ BACKEND_ERROR_CODES.WORKFLOW_REQUIRED
53674
53845
  ];
53675
53846
  });
53676
53847
 
@@ -55094,6 +55265,7 @@ async function updateBacklog(chatroomId, options, deps) {
55094
55265
  try {
55095
55266
  await d.backend.mutation(api.backlog.updateBacklogItem, {
55096
55267
  sessionId,
55268
+ chatroomId,
55097
55269
  itemId: options.backlogItemId,
55098
55270
  content: options.content.trim()
55099
55271
  });
@@ -55347,7 +55519,11 @@ function parseSections(input, requiredSections, optionalSections) {
55347
55519
  let match;
55348
55520
  while ((match = regex.exec(input)) !== null) {
55349
55521
  const sectionName = match[1].replace(/^---/, "").replace(/---$/, "");
55350
- markers.push({ section: sectionName, index: match.index + match[0].length, matchStart: match.index });
55522
+ markers.push({
55523
+ section: sectionName,
55524
+ index: match.index + match[0].length,
55525
+ matchStart: match.index
55526
+ });
55351
55527
  }
55352
55528
  for (let i2 = 0;i2 < markers.length; i2++) {
55353
55529
  const start = markers[i2].index;
@@ -59059,7 +59235,7 @@ async function onCommandRun(ctx, event) {
59059
59235
  } else {
59060
59236
  child.kill("SIGKILL");
59061
59237
  }
59062
- }, FORCE_KILL_DELAY_MS);
59238
+ }, SIGTERM_GRACE_PERIOD_MS);
59063
59239
  }, DEFAULT_COMMAND_TIMEOUT_MS);
59064
59240
  timeoutTimer.unref?.();
59065
59241
  const tracked = {
@@ -59129,13 +59305,42 @@ async function onCommandRun(ctx, event) {
59129
59305
  }
59130
59306
  });
59131
59307
  }
59308
+ function killProcess(child, signal) {
59309
+ const pid = child.pid;
59310
+ if (pid) {
59311
+ try {
59312
+ process.kill(-pid, signal);
59313
+ return;
59314
+ } catch {}
59315
+ }
59316
+ try {
59317
+ child.kill(signal);
59318
+ } catch {}
59319
+ }
59320
+ function waitForExit(runIdStr, ms) {
59321
+ return new Promise((resolve5) => {
59322
+ const interval = 100;
59323
+ let elapsed = 0;
59324
+ const timer = setInterval(() => {
59325
+ if (!runningProcesses.has(runIdStr)) {
59326
+ clearInterval(timer);
59327
+ resolve5(true);
59328
+ return;
59329
+ }
59330
+ elapsed += interval;
59331
+ if (elapsed >= ms) {
59332
+ clearInterval(timer);
59333
+ resolve5(false);
59334
+ }
59335
+ }, interval);
59336
+ });
59337
+ }
59132
59338
  async function onCommandStop(ctx, event) {
59133
59339
  const runIdStr = event.runId.toString();
59134
59340
  const tracked = runningProcesses.get(runIdStr);
59135
59341
  if (!tracked) {
59136
- console.log(`[${formatTimestamp()}] ⚠️ No running process found for run: ${runIdStr}`);
59342
+ console.log(`[${formatTimestamp()}] ⚠️ No running process found for run: ${runIdStr} — marking as stopped`);
59137
59343
  pendingStops.set(runIdStr, Date.now());
59138
- console.log(`[${formatTimestamp()}] \uD83D\uDCDD Registered pending stop for run: ${runIdStr}`);
59139
59344
  try {
59140
59345
  await ctx.deps.backend.mutation(api.commands.updateRunStatus, {
59141
59346
  sessionId: ctx.sessionId,
@@ -59143,9 +59348,8 @@ async function onCommandStop(ctx, event) {
59143
59348
  runId: event.runId,
59144
59349
  status: "stopped"
59145
59350
  });
59146
- console.log(`[${formatTimestamp()}] \uD83D\uDCDD Marked orphaned run as stopped: ${runIdStr}`);
59147
59351
  } catch (err) {
59148
- console.warn(`[${formatTimestamp()}] ⚠️ Failed to mark orphaned run as stopped (will retry): ${getErrorMessage(err)}`);
59352
+ console.warn(`[${formatTimestamp()}] ⚠️ Failed to mark run as stopped (will retry): ${getErrorMessage(err)}`);
59149
59353
  throw err;
59150
59354
  }
59151
59355
  return;
@@ -59155,30 +59359,26 @@ async function onCommandStop(ctx, event) {
59155
59359
  clearTimeout(tracked.timeoutTimer);
59156
59360
  tracked.timeoutTimer = null;
59157
59361
  }
59158
- const pid = tracked.process.pid;
59159
- if (pid) {
59160
- try {
59161
- process.kill(-pid, "SIGTERM");
59162
- } catch {
59163
- tracked.process.kill("SIGTERM");
59164
- }
59165
- } else {
59166
- tracked.process.kill("SIGTERM");
59167
- }
59168
- setTimeout(() => {
59169
- if (!runningProcesses.has(runIdStr))
59170
- return;
59362
+ killProcess(tracked.process, "SIGTERM");
59363
+ const exitedAfterSigterm = await waitForExit(runIdStr, SIGTERM_GRACE_PERIOD_MS);
59364
+ if (!exitedAfterSigterm) {
59171
59365
  console.log(`[${formatTimestamp()}] \uD83D\uDD2A Force-killing process: ${runIdStr}`);
59172
- if (pid) {
59173
- try {
59174
- process.kill(-pid, "SIGKILL");
59175
- } catch {
59176
- tracked.process.kill("SIGKILL");
59177
- }
59178
- } else {
59179
- tracked.process.kill("SIGKILL");
59366
+ killProcess(tracked.process, "SIGKILL");
59367
+ const exitedAfterSigkill = await waitForExit(runIdStr, 1000);
59368
+ if (!exitedAfterSigkill) {
59369
+ console.error(`[${formatTimestamp()}] Failed to stop process for run: ${runIdStr} — process did not exit after SIGKILL`);
59180
59370
  }
59181
- }, FORCE_KILL_DELAY_MS);
59371
+ }
59372
+ try {
59373
+ await ctx.deps.backend.mutation(api.commands.updateRunStatus, {
59374
+ sessionId: ctx.sessionId,
59375
+ machineId: ctx.machineId,
59376
+ runId: event.runId,
59377
+ status: "stopped"
59378
+ });
59379
+ } catch (err) {
59380
+ console.warn(`[${formatTimestamp()}] ⚠️ Failed to mark run as stopped in backend: ${getErrorMessage(err)}`);
59381
+ }
59182
59382
  }
59183
59383
  async function shutdownAllCommands(ctx) {
59184
59384
  if (runningProcesses.size === 0)
@@ -59219,7 +59419,7 @@ async function shutdownAllCommands(ctx) {
59219
59419
  runningProcesses.clear();
59220
59420
  console.log(`[${formatTimestamp()}] All commands stopped`);
59221
59421
  }
59222
- var runningProcesses, pendingStops, PENDING_STOP_TTL_MS = 60000, OUTPUT_FLUSH_INTERVAL_MS = 3000, MAX_BUFFER_SIZE, DEFAULT_COMMAND_TIMEOUT_MS, FORCE_KILL_DELAY_MS = 5000;
59422
+ var runningProcesses, pendingStops, PENDING_STOP_TTL_MS = 60000, OUTPUT_FLUSH_INTERVAL_MS = 3000, MAX_BUFFER_SIZE, DEFAULT_COMMAND_TIMEOUT_MS, SIGTERM_GRACE_PERIOD_MS = 5000;
59223
59423
  var init_command_runner = __esm(() => {
59224
59424
  init_api3();
59225
59425
  init_convex_error();
@@ -59278,329 +59478,6 @@ function harnessCapabilitiesFingerprint(harnesses, versions) {
59278
59478
  return `${h}::${v3}`;
59279
59479
  }
59280
59480
 
59281
- // src/infrastructure/local-api/routes/identity.ts
59282
- async function handleIdentity(_req, ctx) {
59283
- const identity = {
59284
- machineId: ctx.machineId,
59285
- hostname: ctx.config?.hostname ?? "unknown",
59286
- os: ctx.config?.os ?? "unknown",
59287
- version: getVersion()
59288
- };
59289
- return {
59290
- status: 200,
59291
- headers: { "Content-Type": "application/json" },
59292
- body: JSON.stringify(identity)
59293
- };
59294
- }
59295
- var identityRoute;
59296
- var init_identity = __esm(() => {
59297
- init_version();
59298
- identityRoute = {
59299
- method: "GET",
59300
- path: "/api/identity",
59301
- handler: handleIdentity
59302
- };
59303
- });
59304
-
59305
- // src/infrastructure/local-api/routes/shared-utils.ts
59306
- import { exec as exec5 } from "node:child_process";
59307
- import { access as access4 } from "node:fs/promises";
59308
- function jsonResponse(status, body) {
59309
- return {
59310
- status,
59311
- headers: { "Content-Type": "application/json" },
59312
- body: JSON.stringify(body)
59313
- };
59314
- }
59315
- async function parseWorkingDir(req) {
59316
- let body = {};
59317
- try {
59318
- if (req.body) {
59319
- body = JSON.parse(req.body);
59320
- }
59321
- } catch {
59322
- return { ok: false, response: jsonResponse(400, { success: false, error: "Invalid JSON body" }) };
59323
- }
59324
- const { workingDir } = body;
59325
- if (!workingDir || typeof workingDir !== "string" || workingDir.trim() === "") {
59326
- return { ok: false, response: jsonResponse(400, { success: false, error: "workingDir is required" }) };
59327
- }
59328
- try {
59329
- await access4(workingDir);
59330
- } catch {
59331
- return {
59332
- ok: false,
59333
- response: jsonResponse(400, { success: false, error: `Directory not found: ${workingDir}` })
59334
- };
59335
- }
59336
- return { ok: true, workingDir };
59337
- }
59338
- function escapeShellArg(arg) {
59339
- return `"${arg.replace(/"/g, "\\\"")}"`;
59340
- }
59341
- function resolveWhichCommand(name) {
59342
- return process.platform === "win32" ? `where ${name}` : `which ${name}`;
59343
- }
59344
- function isCliAvailable(cliName) {
59345
- return new Promise((resolve5) => {
59346
- exec5(resolveWhichCommand(cliName), (err) => {
59347
- resolve5(!err);
59348
- });
59349
- });
59350
- }
59351
- function execFireAndForget(command, logTag) {
59352
- exec5(command, (err) => {
59353
- if (err) {
59354
- console.warn(`[${logTag}] exec failed: ${err.message}`);
59355
- }
59356
- });
59357
- }
59358
- var init_shared_utils = () => {};
59359
-
59360
- // src/infrastructure/local-api/routes/open-finder.ts
59361
- function resolveOpenCommand(platform) {
59362
- switch (platform) {
59363
- case "darwin":
59364
- return "open";
59365
- case "win32":
59366
- return "explorer";
59367
- default:
59368
- return "xdg-open";
59369
- }
59370
- }
59371
- async function handleOpenFinder(req) {
59372
- const parsed = await parseWorkingDir(req);
59373
- if (!parsed.ok)
59374
- return parsed.response;
59375
- const cmd = resolveOpenCommand(process.platform);
59376
- execFireAndForget(`${cmd} ${escapeShellArg(parsed.workingDir)}`, "open-finder");
59377
- return jsonResponse(200, { success: true });
59378
- }
59379
- var openFinderRoute;
59380
- var init_open_finder = __esm(() => {
59381
- init_shared_utils();
59382
- openFinderRoute = {
59383
- method: "POST",
59384
- path: "/api/open-finder",
59385
- handler: (req) => handleOpenFinder(req)
59386
- };
59387
- });
59388
-
59389
- // src/infrastructure/local-api/routes/open-github-desktop.ts
59390
- async function handleOpenGitHubDesktop(req) {
59391
- const parsed = await parseWorkingDir(req);
59392
- if (!parsed.ok)
59393
- return parsed.response;
59394
- const available = await isCliAvailable("github");
59395
- if (!available) {
59396
- return jsonResponse(200, { success: false, error: "GitHub Desktop CLI not found" });
59397
- }
59398
- execFireAndForget(`github ${escapeShellArg(parsed.workingDir)}`, "open-github-desktop");
59399
- return jsonResponse(200, { success: true });
59400
- }
59401
- var openGitHubDesktopRoute;
59402
- var init_open_github_desktop = __esm(() => {
59403
- init_shared_utils();
59404
- openGitHubDesktopRoute = {
59405
- method: "POST",
59406
- path: "/api/open-github-desktop",
59407
- handler: (req) => handleOpenGitHubDesktop(req)
59408
- };
59409
- });
59410
-
59411
- // src/infrastructure/local-api/routes/open-vscode.ts
59412
- async function handleOpenVSCode(req) {
59413
- const parsed = await parseWorkingDir(req);
59414
- if (!parsed.ok)
59415
- return parsed.response;
59416
- const available = await isCliAvailable("code");
59417
- if (!available) {
59418
- return jsonResponse(200, { success: false, error: CODE_CLI_NOT_FOUND });
59419
- }
59420
- execFireAndForget(`code ${escapeShellArg(parsed.workingDir)}`, "open-vscode");
59421
- return jsonResponse(200, { success: true });
59422
- }
59423
- var CODE_CLI_NOT_FOUND = "VS Code CLI (code) not found. Install via: VS Code → Cmd+Shift+P → 'Shell Command: Install code in PATH'", openVSCodeRoute;
59424
- var init_open_vscode = __esm(() => {
59425
- init_shared_utils();
59426
- openVSCodeRoute = {
59427
- method: "POST",
59428
- path: "/api/open-vscode",
59429
- handler: (req) => handleOpenVSCode(req)
59430
- };
59431
- });
59432
-
59433
- // src/infrastructure/local-api/cors.ts
59434
- function applyCorsHeaders(response) {
59435
- return {
59436
- ...response,
59437
- headers: {
59438
- ...CORS_HEADERS,
59439
- ...response.headers ?? {}
59440
- }
59441
- };
59442
- }
59443
- function buildPreflightResponse() {
59444
- return {
59445
- status: 204,
59446
- headers: CORS_HEADERS,
59447
- body: ""
59448
- };
59449
- }
59450
- var CORS_HEADERS;
59451
- var init_cors = __esm(() => {
59452
- CORS_HEADERS = {
59453
- "Access-Control-Allow-Origin": "*",
59454
- "Access-Control-Allow-Methods": "GET, POST, OPTIONS",
59455
- "Access-Control-Allow-Headers": "Content-Type",
59456
- "Access-Control-Allow-Private-Network": "true"
59457
- };
59458
- });
59459
-
59460
- // src/infrastructure/local-api/router.ts
59461
- class LocalApiRouter {
59462
- routes = [];
59463
- registerRoute(route) {
59464
- this.routes.push(route);
59465
- }
59466
- async handleRequest(req, ctx) {
59467
- if (req.method === "OPTIONS") {
59468
- return buildPreflightResponse();
59469
- }
59470
- const pathname = req.url.split("?")[0] ?? req.url;
59471
- const route = this.routes.find((r) => r.method === req.method && r.path === pathname);
59472
- let response;
59473
- if (route) {
59474
- try {
59475
- response = await route.handler(req, ctx);
59476
- } catch (error) {
59477
- response = {
59478
- status: 500,
59479
- headers: { "Content-Type": "application/json" },
59480
- body: JSON.stringify({ error: "Internal server error" })
59481
- };
59482
- }
59483
- } else {
59484
- response = {
59485
- status: 404,
59486
- headers: { "Content-Type": "application/json" },
59487
- body: JSON.stringify({ error: "Not found" })
59488
- };
59489
- }
59490
- return applyCorsHeaders(response);
59491
- }
59492
- }
59493
- var init_router = __esm(() => {
59494
- init_cors();
59495
- });
59496
-
59497
- // src/infrastructure/local-api/server.ts
59498
- import { createServer } from "node:http";
59499
- function readBody(req) {
59500
- return new Promise((resolve5, reject) => {
59501
- const chunks = [];
59502
- req.on("data", (chunk) => chunks.push(chunk));
59503
- req.on("end", () => resolve5(Buffer.concat(chunks).toString("utf-8")));
59504
- req.on("error", reject);
59505
- });
59506
- }
59507
- async function normalizeRequest(req) {
59508
- const body = await readBody(req);
59509
- const headers = {};
59510
- for (const [key, value] of Object.entries(req.headers)) {
59511
- if (typeof value === "string") {
59512
- headers[key] = value;
59513
- } else if (Array.isArray(value)) {
59514
- headers[key] = value.join(", ");
59515
- }
59516
- }
59517
- return {
59518
- method: (req.method ?? "GET").toUpperCase(),
59519
- url: req.url ?? "/",
59520
- headers,
59521
- body: body || undefined
59522
- };
59523
- }
59524
- function writeResponse(res, status, headers, body) {
59525
- res.writeHead(status, headers);
59526
- res.end(body);
59527
- }
59528
- function createRouter() {
59529
- const router = new LocalApiRouter;
59530
- router.registerRoute(identityRoute);
59531
- router.registerRoute(openFinderRoute);
59532
- router.registerRoute(openGitHubDesktopRoute);
59533
- router.registerRoute(openVSCodeRoute);
59534
- return router;
59535
- }
59536
- function resolvePort() {
59537
- const envPort = process.env.CHATROOM_LOCAL_API_PORT;
59538
- if (envPort) {
59539
- const parsed = parseInt(envPort, 10);
59540
- if (!isNaN(parsed) && parsed > 0 && parsed < 65536) {
59541
- return parsed;
59542
- }
59543
- }
59544
- return LOCAL_API_PORT;
59545
- }
59546
- function ts() {
59547
- return new Date().toISOString().replace("T", " ").slice(0, 19);
59548
- }
59549
- async function startLocalApi(ctx, port = resolvePort()) {
59550
- const router = createRouter();
59551
- const server2 = createServer(async (req, res) => {
59552
- try {
59553
- const localReq = await normalizeRequest(req);
59554
- const localRes = await router.handleRequest(localReq, ctx);
59555
- writeResponse(res, localRes.status, { "Content-Type": "application/json", ...localRes.headers ?? {} }, localRes.body);
59556
- } catch {
59557
- writeResponse(res, 500, { "Content-Type": "application/json" }, JSON.stringify({ error: "Internal server error" }));
59558
- }
59559
- });
59560
- await new Promise((resolve5) => {
59561
- server2.listen(port, "127.0.0.1", () => {
59562
- console.log(`[${ts()}] \uD83C\uDF10 Local API started on http://localhost:${port}`);
59563
- resolve5();
59564
- });
59565
- server2.on("error", (err) => {
59566
- if (err.code === "EADDRINUSE") {
59567
- console.warn(`[${ts()}] ⚠️ Local API port ${port} already in use — skipping local API`);
59568
- } else {
59569
- console.warn(`[${ts()}] ⚠️ Local API failed to start: ${err.message}`);
59570
- }
59571
- resolve5();
59572
- });
59573
- });
59574
- const stop2 = () => new Promise((resolve5, reject) => {
59575
- if (!server2.listening) {
59576
- resolve5();
59577
- return;
59578
- }
59579
- server2.close((err) => {
59580
- if (err) {
59581
- reject(err);
59582
- } else {
59583
- console.log(`[${ts()}] \uD83C\uDF10 Local API stopped`);
59584
- resolve5();
59585
- }
59586
- });
59587
- });
59588
- return { stop: stop2 };
59589
- }
59590
- var LOCAL_API_PORT = 19847;
59591
- var init_server3 = __esm(() => {
59592
- init_identity();
59593
- init_open_finder();
59594
- init_open_github_desktop();
59595
- init_open_vscode();
59596
- init_router();
59597
- });
59598
-
59599
- // src/infrastructure/local-api/index.ts
59600
- var init_local_api = __esm(() => {
59601
- init_server3();
59602
- });
59603
-
59604
59481
  // src/events/daemon/event-bus.ts
59605
59482
  class DaemonEventBus {
59606
59483
  listeners = new Map;
@@ -59643,15 +59520,15 @@ function onAgentExited(ctx, payload) {
59643
59520
 
59644
59521
  // src/events/daemon/agent/on-agent-started.ts
59645
59522
  function onAgentStarted(ctx, payload) {
59646
- const ts2 = formatTimestamp();
59647
- console.log(`[${ts2}] \uD83D\uDFE2 Agent started: ${payload.role} (PID: ${payload.pid}, harness: ${payload.harness})`);
59523
+ const ts = formatTimestamp();
59524
+ console.log(`[${ts}] \uD83D\uDFE2 Agent started: ${payload.role} (PID: ${payload.pid}, harness: ${payload.harness})`);
59648
59525
  }
59649
59526
  var init_on_agent_started = () => {};
59650
59527
 
59651
59528
  // src/events/daemon/agent/on-agent-stopped.ts
59652
59529
  function onAgentStopped(ctx, payload) {
59653
- const ts2 = formatTimestamp();
59654
- console.log(`[${ts2}] \uD83D\uDD34 Agent stopped: ${payload.role} (PID: ${payload.pid})`);
59530
+ const ts = formatTimestamp();
59531
+ console.log(`[${ts}] \uD83D\uDD34 Agent stopped: ${payload.role} (PID: ${payload.pid})`);
59655
59532
  }
59656
59533
  var init_on_agent_stopped = () => {};
59657
59534
 
@@ -59780,7 +59657,7 @@ class CrashLoopTracker {
59780
59657
  const key = `${chatroomId}:${role.toLowerCase()}`;
59781
59658
  const windowStart = now - CRASH_LOOP_WINDOW_MS;
59782
59659
  const raw = this.history.get(key) ?? [];
59783
- const recent = raw.filter((ts2) => ts2 >= windowStart);
59660
+ const recent = raw.filter((ts) => ts >= windowStart);
59784
59661
  const restartCount = recent.length;
59785
59662
  if (restartCount >= CRASH_LOOP_MAX_RESTARTS) {
59786
59663
  return {
@@ -59823,7 +59700,7 @@ class CrashLoopTracker {
59823
59700
  const key = `${chatroomId}:${role.toLowerCase()}`;
59824
59701
  const windowStart = now - CRASH_LOOP_WINDOW_MS;
59825
59702
  const raw = this.history.get(key) ?? [];
59826
- return raw.filter((ts2) => ts2 >= windowStart).length;
59703
+ return raw.filter((ts) => ts >= windowStart).length;
59827
59704
  }
59828
59705
  }
59829
59706
  var CRASH_LOOP_MAX_RESTARTS = 10, CRASH_LOOP_WINDOW_MS, BACKOFF_INTERVALS;
@@ -60542,8 +60419,6 @@ async function initDaemon() {
60542
60419
  registerEventListeners(ctx);
60543
60420
  logStartup(ctx, availableModels);
60544
60421
  await recoverState(ctx);
60545
- const localApiHandle = await startLocalApi(ctx);
60546
- ctx.stopLocalApi = localApiHandle.stop;
60547
60422
  return ctx;
60548
60423
  } catch (error) {
60549
60424
  if (isNetworkError(error)) {
@@ -60566,7 +60441,6 @@ var AUTH_POLL_INTERVAL_MS2 = 2000, AUTH_WAIT_TIMEOUT_MS, CONNECTION_RETRY_INTERV
60566
60441
  var init_init2 = __esm(() => {
60567
60442
  init_state_recovery();
60568
60443
  init_api3();
60569
- init_local_api();
60570
60444
  init_register_listeners();
60571
60445
  init_storage();
60572
60446
  init_client2();
@@ -60618,7 +60492,7 @@ var init_on_daemon_shutdown = __esm(() => {
60618
60492
  });
60619
60493
 
60620
60494
  // src/infrastructure/git/git-writer.ts
60621
- import { exec as exec6 } from "node:child_process";
60495
+ import { exec as exec5 } from "node:child_process";
60622
60496
  import { promisify as promisify5 } from "node:util";
60623
60497
  async function runGit2(args, cwd) {
60624
60498
  try {
@@ -60682,7 +60556,7 @@ async function gitPull(workingDir) {
60682
60556
  }
60683
60557
  var execAsync4;
60684
60558
  var init_git_writer = __esm(() => {
60685
- execAsync4 = promisify5(exec6);
60559
+ execAsync4 = promisify5(exec5);
60686
60560
  });
60687
60561
 
60688
60562
  // src/infrastructure/git/index.ts
@@ -60692,8 +60566,29 @@ var init_git = __esm(() => {
60692
60566
  });
60693
60567
 
60694
60568
  // src/infrastructure/local-actions/execute-local-action.ts
60695
- import { access as access5 } from "node:fs/promises";
60696
- function resolveOpenCommand2(platform) {
60569
+ import { exec as exec6 } from "node:child_process";
60570
+ import { access as access4 } from "node:fs/promises";
60571
+ function escapeShellArg(arg) {
60572
+ return `"${arg.replace(/"/g, "\\\"")}"`;
60573
+ }
60574
+ function resolveWhichCommand(name) {
60575
+ return process.platform === "win32" ? `where ${name}` : `which ${name}`;
60576
+ }
60577
+ function isCliAvailable(cliName) {
60578
+ return new Promise((resolve5) => {
60579
+ exec6(resolveWhichCommand(cliName), (err) => {
60580
+ resolve5(!err);
60581
+ });
60582
+ });
60583
+ }
60584
+ function execFireAndForget(command, logTag) {
60585
+ exec6(command, (err) => {
60586
+ if (err) {
60587
+ console.warn(`[${logTag}] exec failed: ${err.message}`);
60588
+ }
60589
+ });
60590
+ }
60591
+ function resolveOpenCommand(platform) {
60697
60592
  switch (platform) {
60698
60593
  case "darwin":
60699
60594
  return "open";
@@ -60705,7 +60600,7 @@ function resolveOpenCommand2(platform) {
60705
60600
  }
60706
60601
  async function executeLocalAction(action, workingDir) {
60707
60602
  try {
60708
- await access5(workingDir);
60603
+ await access4(workingDir);
60709
60604
  } catch {
60710
60605
  return { success: false, error: `Directory not found: ${workingDir}` };
60711
60606
  }
@@ -60722,7 +60617,7 @@ async function executeLocalAction(action, workingDir) {
60722
60617
  return { success: true };
60723
60618
  }
60724
60619
  case "open-finder": {
60725
- const cmd = resolveOpenCommand2(process.platform);
60620
+ const cmd = resolveOpenCommand(process.platform);
60726
60621
  execFireAndForget(`${cmd} ${escapeShellArg(workingDir)}`, "open-finder");
60727
60622
  return { success: true };
60728
60623
  }
@@ -60771,7 +60666,6 @@ async function executeLocalAction(action, workingDir) {
60771
60666
  }
60772
60667
  }
60773
60668
  var init_execute_local_action = __esm(() => {
60774
- init_shared_utils();
60775
60669
  init_git();
60776
60670
  });
60777
60671
 
@@ -60846,32 +60740,32 @@ async function refreshModels(ctx) {
60846
60740
  }
60847
60741
  function evictStaleDedupEntries(tracker) {
60848
60742
  const evictBefore = Date.now() - AGENT_REQUEST_DEADLINE_MS;
60849
- for (const [id, ts2] of tracker.commandIds) {
60850
- if (ts2 < evictBefore)
60743
+ for (const [id, ts] of tracker.commandIds) {
60744
+ if (ts < evictBefore)
60851
60745
  tracker.commandIds.delete(id);
60852
60746
  }
60853
- for (const [id, ts2] of tracker.pingIds) {
60854
- if (ts2 < evictBefore)
60747
+ for (const [id, ts] of tracker.pingIds) {
60748
+ if (ts < evictBefore)
60855
60749
  tracker.pingIds.delete(id);
60856
60750
  }
60857
- for (const [id, ts2] of tracker.gitRefreshIds) {
60858
- if (ts2 < evictBefore)
60751
+ for (const [id, ts] of tracker.gitRefreshIds) {
60752
+ if (ts < evictBefore)
60859
60753
  tracker.gitRefreshIds.delete(id);
60860
60754
  }
60861
- for (const [id, ts2] of tracker.capabilitiesRefreshIds) {
60862
- if (ts2 < evictBefore)
60755
+ for (const [id, ts] of tracker.capabilitiesRefreshIds) {
60756
+ if (ts < evictBefore)
60863
60757
  tracker.capabilitiesRefreshIds.delete(id);
60864
60758
  }
60865
- for (const [id, ts2] of tracker.localActionIds) {
60866
- if (ts2 < evictBefore)
60759
+ for (const [id, ts] of tracker.localActionIds) {
60760
+ if (ts < evictBefore)
60867
60761
  tracker.localActionIds.delete(id);
60868
60762
  }
60869
- for (const [id, ts2] of tracker.commandRunIds) {
60870
- if (ts2 < evictBefore)
60763
+ for (const [id, ts] of tracker.commandRunIds) {
60764
+ if (ts < evictBefore)
60871
60765
  tracker.commandRunIds.delete(id);
60872
60766
  }
60873
- for (const [id, ts2] of tracker.commandStopIds) {
60874
- if (ts2 < evictBefore)
60767
+ for (const [id, ts] of tracker.commandStopIds) {
60768
+ if (ts < evictBefore)
60875
60769
  tracker.commandStopIds.delete(id);
60876
60770
  }
60877
60771
  evictStalePendingStops();
@@ -61007,9 +60901,6 @@ async function startCommandLoop(ctx) {
61007
60901
  if (observedSyncSubscriptionHandle)
61008
60902
  observedSyncSubscriptionHandle.stop();
61009
60903
  await onDaemonShutdown(ctx);
61010
- if (ctx.stopLocalApi) {
61011
- await ctx.stopLocalApi().catch(() => {});
61012
- }
61013
60904
  releaseLock();
61014
60905
  process.exit(0);
61015
60906
  };
@@ -61865,7 +61756,11 @@ backlogCommand.command("update").description("Update the content of an existing
61865
61756
  process.exit(1);
61866
61757
  }
61867
61758
  const { updateBacklog: updateBacklog2 } = await Promise.resolve().then(() => (init_backlog(), exports_backlog));
61868
- await updateBacklog2(options.chatroomId, { role: options.role, backlogItemId: options.backlogItemId, content });
61759
+ await updateBacklog2(options.chatroomId, {
61760
+ role: options.role,
61761
+ backlogItemId: options.backlogItemId,
61762
+ content
61763
+ });
61869
61764
  });
61870
61765
  backlogCommand.command("complete").description("Mark a backlog item as complete. Use --force for stuck in_progress/pending tasks.").requiredOption("--chatroom-id <id>", "Chatroom identifier").requiredOption("--role <role>", "Your role").requiredOption("--backlog-item-id <id>", "Backlog item ID to complete").option("-f, --force", "Force complete a stuck in_progress or pending task").action(async (options) => {
61871
61766
  await maybeRequireAuth();
@@ -62168,5 +62063,5 @@ program2.hook("preAction", async (_thisCommand, actionCommand) => {
62168
62063
  });
62169
62064
  program2.parse();
62170
62065
 
62171
- //# debugId=1C43E3169710F16B64756E2164756E21
62066
+ //# debugId=B38A342DEDB6508164756E2164756E21
62172
62067
  //# sourceMappingURL=index.js.map