@buildautomaton/cli 0.1.52 → 0.1.53

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/cli.js CHANGED
@@ -25174,7 +25174,7 @@ var {
25174
25174
  } = import_index.default;
25175
25175
 
25176
25176
  // src/cli-version.ts
25177
- var CLI_VERSION = "0.1.52".length > 0 ? "0.1.52" : "0.0.0-dev";
25177
+ var CLI_VERSION = "0.1.53".length > 0 ? "0.1.53" : "0.0.0-dev";
25178
25178
 
25179
25179
  // src/cli/defaults.ts
25180
25180
  var DEFAULT_API_URL = process.env.BUILDAUTOMATON_API_URL ?? "https://api.buildautomaton.com";
@@ -28347,6 +28347,11 @@ var BRIDGE_MCP_TOOL_LABELS = {
28347
28347
  [GET_PARENT_SESSION_TURN_TRANSCRIPT_TOOL]: "Read parent session transcript"
28348
28348
  };
28349
28349
 
28350
+ // ../types/src/prompts/server.ts
28351
+ function isRunnableBridgePromptTurnServerState(state) {
28352
+ return state === "queued" || state === "requeued" || state === "requeued_with_revert";
28353
+ }
28354
+
28350
28355
  // ../types/src/claude-code-permission-mode.ts
28351
28356
  var CLAUDE_CODE_PERMISSION_MODES = [
28352
28357
  "default",
@@ -37574,24 +37579,45 @@ function truncatePatch(s) {
37574
37579
  }
37575
37580
 
37576
37581
  // src/git/changes/patch/unified-diff-for-file.ts
37582
+ var RENAME_DIFF_ARGS = ["-M", "--find-renames"];
37583
+ function devNullPath() {
37584
+ return process.platform === "win32" ? "NUL" : "/dev/null";
37585
+ }
37577
37586
  function patchTextFromGitDiffOutput(raw) {
37578
37587
  if (raw.trim() === "") return void 0;
37579
37588
  return normalizePatchContent(raw);
37580
37589
  }
37590
+ async function rawGitDiff(g, args) {
37591
+ return String(await g.raw([...args]).catch(() => ""));
37592
+ }
37593
+ async function unifiedDiffAgainstHead(g, pathInRepo, change, movedFromPathInRepo) {
37594
+ const args = change === "moved" && movedFromPathInRepo ? ["diff", "--no-color", ...RENAME_DIFF_ARGS, "HEAD", "--", movedFromPathInRepo, pathInRepo] : change === "removed" ? ["diff", "--no-color", ...RENAME_DIFF_ARGS, "HEAD", "--", pathInRepo] : ["diff", "--no-color", ...RENAME_DIFF_ARGS, "HEAD", "--", pathInRepo];
37595
+ return patchTextFromGitDiffOutput(await rawGitDiff(g, args));
37596
+ }
37597
+ async function unifiedDiffForAddedUntrackedFile(g, pathInRepo) {
37598
+ const raw = await rawGitDiff(g, [
37599
+ "diff",
37600
+ "--no-color",
37601
+ ...RENAME_DIFF_ARGS,
37602
+ "--no-index",
37603
+ "--",
37604
+ devNullPath(),
37605
+ pathInRepo
37606
+ ]);
37607
+ return patchTextFromGitDiffOutput(raw);
37608
+ }
37581
37609
  async function unifiedDiffForFile(repoCwd, pathInRepo, change, movedFromPathInRepo) {
37582
37610
  const g = cliSimpleGit(repoCwd);
37583
- const renameArgs = ["-M", "--find-renames"];
37584
- const args = change === "moved" && movedFromPathInRepo ? ["diff", "--no-color", ...renameArgs, "HEAD", "--", movedFromPathInRepo, pathInRepo] : change === "removed" ? ["diff", "--no-color", ...renameArgs, "HEAD", "--", pathInRepo] : ["diff", "--no-color", ...renameArgs, "HEAD", "--", pathInRepo];
37585
- const raw = await g.raw([...args]).catch(() => "");
37586
- const patch = patchTextFromGitDiffOutput(String(raw));
37611
+ let patch = await unifiedDiffAgainstHead(g, pathInRepo, change, movedFromPathInRepo);
37612
+ if (!patch && change === "added") {
37613
+ patch = await unifiedDiffForAddedUntrackedFile(g, pathInRepo);
37614
+ }
37587
37615
  return patch ? truncatePatch(patch) : void 0;
37588
37616
  }
37589
37617
  async function unifiedDiffForFileInRange(repoCwd, range, pathInRepo, change, movedFromPathInRepo) {
37590
37618
  const g = cliSimpleGit(repoCwd);
37591
- const renameArgs = ["-M", "--find-renames"];
37592
- const args = change === "moved" && movedFromPathInRepo ? ["diff", "--no-color", ...renameArgs, "-U20000", range, "--", movedFromPathInRepo, pathInRepo] : ["diff", "--no-color", ...renameArgs, "-U20000", range, "--", pathInRepo];
37593
- const raw = await g.raw([...args]).catch(() => "");
37594
- const patch = patchTextFromGitDiffOutput(String(raw));
37619
+ const args = change === "moved" && movedFromPathInRepo ? ["diff", "--no-color", ...RENAME_DIFF_ARGS, "-U20000", range, "--", movedFromPathInRepo, pathInRepo] : ["diff", "--no-color", ...RENAME_DIFF_ARGS, "-U20000", range, "--", pathInRepo];
37620
+ const patch = patchTextFromGitDiffOutput(await rawGitDiff(g, args));
37595
37621
  return patch ? truncatePatch(patch) : void 0;
37596
37622
  }
37597
37623
 
@@ -37769,7 +37795,7 @@ async function parentForCommitDiff(g, sha) {
37769
37795
  }
37770
37796
 
37771
37797
  // src/git/changes/listing/rename-diff-args.ts
37772
- var RENAME_DIFF_ARGS = ["-M", "--find-renames"];
37798
+ var RENAME_DIFF_ARGS2 = ["-M", "--find-renames"];
37773
37799
 
37774
37800
  // src/git/changes/rows/pick-preferred-changed-file-row.ts
37775
37801
  function rowRank(row) {
@@ -37822,7 +37848,7 @@ async function listChangedFilesForCommit(repoGitCwd, repoRelPath, commitSha, opt
37822
37848
  const g = cliSimpleGit(repoGitCwd);
37823
37849
  const normRel = normalizeRepoRelPath(repoRelPath);
37824
37850
  const [nameStatusRaw, numstatRaw] = await Promise.all([
37825
- g.raw(["diff-tree", "--no-commit-id", "--name-status", "-r", ...RENAME_DIFF_ARGS, commitSha]).catch(() => ""),
37851
+ g.raw(["diff-tree", "--no-commit-id", "--name-status", "-r", ...RENAME_DIFF_ARGS2, commitSha]).catch(() => ""),
37826
37852
  g.raw(["show", "--numstat", "--format=format:", commitSha]).catch(() => "")
37827
37853
  ]);
37828
37854
  const parsed = parseDiffOutput(String(nameStatusRaw), String(numstatRaw));
@@ -38094,8 +38120,8 @@ async function enrichWorkingTreeFileRows(options) {
38094
38120
  async function listChangedFilesForRepo(repoGitCwd, repoRelPath, options = {}) {
38095
38121
  const g = cliSimpleGit(repoGitCwd);
38096
38122
  const [nameStatusRaw, numstatRaw, untrackedRaw] = await Promise.all([
38097
- g.raw(["diff", ...RENAME_DIFF_ARGS, "--name-status", "HEAD"]).catch(() => ""),
38098
- g.raw(["diff", ...RENAME_DIFF_ARGS, "HEAD", "--numstat"]).catch(() => ""),
38123
+ g.raw(["diff", ...RENAME_DIFF_ARGS2, "--name-status", "HEAD"]).catch(() => ""),
38124
+ g.raw(["diff", ...RENAME_DIFF_ARGS2, "HEAD", "--numstat"]).catch(() => ""),
38099
38125
  g.raw(["ls-files", "--others", "--exclude-standard"]).catch(() => "")
38100
38126
  ]);
38101
38127
  const parsed = parseDiffOutput(String(nameStatusRaw), String(numstatRaw));
@@ -40998,12 +41024,16 @@ var handleAgentConfigMessage = (msg, deps) => {
40998
41024
  // src/prompt-turn-queue/client-report.ts
40999
41025
  function sendPromptQueueClientReport(ws, queues) {
41000
41026
  if (!ws) return false;
41001
- sendWsMessage(ws, { type: "prompt_queue_client_report", queues });
41027
+ const wireQueues = {};
41028
+ for (const [queueKey, rows] of Object.entries(queues)) {
41029
+ wireQueues[queueKey] = rows.map((r) => ({ turnId: r.turnId, clientState: r.cliState }));
41030
+ }
41031
+ sendWsMessage(ws, { type: "prompt_queue_client_report", queues: wireQueues });
41002
41032
  return true;
41003
41033
  }
41004
41034
 
41005
41035
  // src/prompt-turn-queue/disk-store.ts
41006
- var MERGEABLE_SERVER_STATES = /* @__PURE__ */ new Set([
41036
+ var MERGEABLE_BRIDGE_SERVER_STATES = /* @__PURE__ */ new Set([
41007
41037
  "queued",
41008
41038
  "requeued",
41009
41039
  "requeued_with_revert",
@@ -41035,7 +41065,7 @@ async function writePersistedQueue(file2) {
41035
41065
  );
41036
41066
  });
41037
41067
  }
41038
- async function mergeServerQueueSnapshot(queueKey, serverTurns) {
41068
+ async function mergeBridgeServerQueueSnapshot(queueKey, serverTurns) {
41039
41069
  const prev = await readPersistedQueue(queueKey);
41040
41070
  const turns = [];
41041
41071
  for (const raw of serverTurns) {
@@ -41044,19 +41074,19 @@ async function mergeServerQueueSnapshot(queueKey, serverTurns) {
41044
41074
  const turnId = typeof o.turnId === "string" ? o.turnId : "";
41045
41075
  const sessionId = typeof o.sessionId === "string" ? o.sessionId : "";
41046
41076
  const turnOrd = typeof o.turnOrd === "number" ? o.turnOrd : Number(o.turnOrd) || 0;
41047
- const serverState = o.serverState;
41048
- const lastClientState = o.lastClientState ?? null;
41077
+ const bridgeServerState = o.serverState ?? o.bridgeServerState;
41078
+ const lastCliState = o.lastClientState ?? o.lastCliState ?? null;
41049
41079
  const payload = o.payload && typeof o.payload === "object" ? o.payload : {};
41050
41080
  if (!turnId || !sessionId) continue;
41051
- if (!MERGEABLE_SERVER_STATES.has(String(serverState))) continue;
41081
+ if (!MERGEABLE_BRIDGE_SERVER_STATES.has(String(bridgeServerState))) continue;
41052
41082
  const old = prev?.turns.find((t) => t.turnId === turnId);
41053
- const mergedClient = old?.lastClientState === "running" && lastClientState == null ? "running" : lastClientState;
41083
+ const mergedCli = old?.lastCliState === "running" && lastCliState == null ? "running" : lastCliState;
41054
41084
  turns.push({
41055
41085
  turnId,
41056
41086
  sessionId,
41057
41087
  turnOrd,
41058
- serverState,
41059
- lastClientState: mergedClient,
41088
+ bridgeServerState,
41089
+ lastCliState: mergedCli,
41060
41090
  payload
41061
41091
  });
41062
41092
  }
@@ -41094,15 +41124,12 @@ function dispatchLocalPrompt(next, deps) {
41094
41124
  }
41095
41125
 
41096
41126
  // src/prompt-turn-queue/runner/queue-selection.ts
41097
- function isRunnableServerState(s) {
41098
- return s === "queued" || s === "requeued" || s === "requeued_with_revert";
41099
- }
41100
41127
  function pickNextRunnableTurn(turns) {
41101
41128
  for (const t of turns) {
41102
- if (t.serverState === "discarded" || t.serverState === "stopping") continue;
41103
- if (t.serverState === "cancel_requested") continue;
41104
- if (!isRunnableServerState(t.serverState)) continue;
41105
- if (t.lastClientState === "running" || t.lastClientState === "stopped" || t.lastClientState === "failed" || t.lastClientState === "cancelled") {
41129
+ if (t.bridgeServerState === "discarded" || t.bridgeServerState === "stopping") continue;
41130
+ if (t.bridgeServerState === "cancel_requested") continue;
41131
+ if (!isRunnableBridgePromptTurnServerState(t.bridgeServerState)) continue;
41132
+ if (t.lastCliState === "running" || t.lastCliState === "stopped" || t.lastCliState === "failed" || t.lastCliState === "cancelled") {
41106
41133
  continue;
41107
41134
  }
41108
41135
  return t;
@@ -41110,7 +41137,7 @@ function pickNextRunnableTurn(turns) {
41110
41137
  return null;
41111
41138
  }
41112
41139
  function hasRunningTurn(turns) {
41113
- return turns.some((t) => t.lastClientState === "running");
41140
+ return turns.some((t) => t.lastCliState === "running");
41114
41141
  }
41115
41142
 
41116
41143
  // src/prompt-turn-queue/runner/run-id-queue-key-map.ts
@@ -41127,7 +41154,7 @@ function deleteRunIdQueueKey(runId) {
41127
41154
  return queueKey;
41128
41155
  }
41129
41156
  function syncRunningTurnQueueKeys(turns, queueKey) {
41130
- for (const running of turns.filter((t) => t.lastClientState === "running")) {
41157
+ for (const running of turns.filter((t) => t.lastCliState === "running")) {
41131
41158
  runIdToQueueKey.set(running.turnId, queueKey);
41132
41159
  }
41133
41160
  }
@@ -41135,7 +41162,7 @@ function syncRunningTurnQueueKeys(turns, queueKey) {
41135
41162
  // src/prompt-turn-queue/runner/run-local-revert-before-queued-prompt.ts
41136
41163
  import fs38 from "node:fs";
41137
41164
  async function runLocalRevertBeforeQueuedPrompt(next, deps) {
41138
- if (next.serverState !== "requeued_with_revert") return true;
41165
+ if (next.bridgeServerState !== "requeued_with_revert") return true;
41139
41166
  const sid = next.sessionId;
41140
41167
  const pl = next.payload;
41141
41168
  const tid = typeof pl.snapshotRevertTurnId === "string" && pl.snapshotRevertTurnId.trim() !== "" ? pl.snapshotRevertTurnId.trim() : next.turnId;
@@ -41165,9 +41192,9 @@ async function finalizePromptTurnOnBridge(getWs, runId, success2, opts) {
41165
41192
  if (!f) return false;
41166
41193
  const t = f.turns.find((x) => x.turnId === runId);
41167
41194
  if (!t) return false;
41168
- t.lastClientState = opts?.terminalClientState ?? (success2 ? "stopped" : "failed");
41195
+ t.lastCliState = opts?.terminalCliState ?? (success2 ? "stopped" : "failed");
41169
41196
  await writePersistedQueue(f);
41170
- sendPromptQueueClientReport(getWs(), { [queueKey]: [{ turnId: runId, clientState: t.lastClientState }] });
41197
+ sendPromptQueueClientReport(getWs(), { [queueKey]: [{ turnId: runId, cliState: t.lastCliState }] });
41171
41198
  return true;
41172
41199
  }
41173
41200
 
@@ -41178,7 +41205,7 @@ async function applyPromptQueueStateFromServer(msg, deps) {
41178
41205
  const getWs = deps.getWs;
41179
41206
  for (const [queueKey, serverTurns] of Object.entries(raw)) {
41180
41207
  if (!Array.isArray(serverTurns)) continue;
41181
- const file2 = await mergeServerQueueSnapshot(queueKey, serverTurns);
41208
+ const file2 = await mergeBridgeServerQueueSnapshot(queueKey, serverTurns);
41182
41209
  await writePersistedQueue(file2);
41183
41210
  }
41184
41211
  for (const [queueKey, serverTurns] of Object.entries(raw)) {
@@ -41191,14 +41218,14 @@ async function applyPromptQueueStateFromServer(msg, deps) {
41191
41218
  if (!Array.isArray(serverTurns)) continue;
41192
41219
  const file2 = await readPersistedQueue(queueKey);
41193
41220
  if (!file2) continue;
41194
- const cancelRow = file2.turns.find((t) => t.serverState === "cancel_requested" && t.lastClientState === "running");
41221
+ const cancelRow = file2.turns.find((t) => t.bridgeServerState === "cancel_requested" && t.lastCliState === "running");
41195
41222
  if (cancelRow) {
41196
41223
  const localCancelHandled = await deps.acpManager.cancelRun(cancelRow.turnId);
41197
41224
  if (!localCancelHandled) {
41198
41225
  deps.log(
41199
- `[Queue] server cancel_requested for ${cancelRow.turnId.slice(0, 8)}\u2026 but no local agent run is active (e.g. after CLI restart); marking cancelled and notifying bridge.`
41226
+ `[Queue] bridge server cancel_requested for ${cancelRow.turnId.slice(0, 8)}\u2026 but no local agent run is active (e.g. after CLI restart); marking cancelled and notifying bridge.`
41200
41227
  );
41201
- await finalizePromptTurnOnBridge(deps.getWs, cancelRow.turnId, false, { terminalClientState: "cancelled" });
41228
+ await finalizePromptTurnOnBridge(deps.getWs, cancelRow.turnId, false, { terminalCliState: "cancelled" });
41202
41229
  const ws = deps.getWs();
41203
41230
  if (ws && cancelRow.sessionId) {
41204
41231
  sendWsMessage(ws, {
@@ -41223,16 +41250,16 @@ async function applyPromptQueueStateFromServer(msg, deps) {
41223
41250
  const next = pickNextRunnableTurn(file2.turns);
41224
41251
  if (!next) continue;
41225
41252
  if (!await runLocalRevertBeforeQueuedPrompt(next, deps)) {
41226
- next.lastClientState = "failed";
41253
+ next.lastCliState = "failed";
41227
41254
  await writePersistedQueue(file2);
41228
- sendPromptQueueClientReport(getWs(), { [queueKey]: [{ turnId: next.turnId, clientState: "failed" }] });
41255
+ sendPromptQueueClientReport(getWs(), { [queueKey]: [{ turnId: next.turnId, cliState: "failed" }] });
41229
41256
  continue;
41230
41257
  }
41231
- next.lastClientState = "running";
41258
+ next.lastCliState = "running";
41232
41259
  await writePersistedQueue(file2);
41233
41260
  setRunIdQueueKey(next.turnId, queueKey);
41234
41261
  startedThisTick.add(next.turnId);
41235
- report[queueKey] = [{ turnId: next.turnId, clientState: "running" }];
41262
+ report[queueKey] = [{ turnId: next.turnId, cliState: "running" }];
41236
41263
  }
41237
41264
  if (Object.keys(report).length > 0) {
41238
41265
  sendPromptQueueClientReport(getWs(), report);
@@ -41241,7 +41268,7 @@ async function applyPromptQueueStateFromServer(msg, deps) {
41241
41268
  if (!Array.isArray(serverTurns)) continue;
41242
41269
  const file2 = await readPersistedQueue(queueKey);
41243
41270
  if (!file2) continue;
41244
- const running = file2.turns.find((t) => t.lastClientState === "running");
41271
+ const running = file2.turns.find((t) => t.lastCliState === "running");
41245
41272
  if (!running || !startedThisTick.has(running.turnId)) continue;
41246
41273
  if (getRunIdQueueKey(running.turnId) !== queueKey) continue;
41247
41274
  dispatchLocalPrompt(running, deps);
@@ -41268,7 +41295,7 @@ function createBridgePromptSenders(deps, getWs) {
41268
41295
  getWs,
41269
41296
  typeof pr.runId === "string" ? pr.runId : void 0,
41270
41297
  pr.success === true,
41271
- cancelled ? { terminalClientState: "cancelled" } : void 0
41298
+ cancelled ? { terminalCliState: "cancelled" } : void 0
41272
41299
  ).catch(() => {
41273
41300
  });
41274
41301
  }