@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/index.js CHANGED
@@ -23402,6 +23402,11 @@ var BRIDGE_MCP_TOOL_LABELS = {
23402
23402
  [GET_PARENT_SESSION_TURN_TRANSCRIPT_TOOL]: "Read parent session transcript"
23403
23403
  };
23404
23404
 
23405
+ // ../types/src/prompts/server.ts
23406
+ function isRunnableBridgePromptTurnServerState(state) {
23407
+ return state === "queued" || state === "requeued" || state === "requeued_with_revert";
23408
+ }
23409
+
23405
23410
  // ../types/src/claude-code-permission-mode.ts
23406
23411
  var CLAUDE_CODE_PERMISSION_MODES = [
23407
23412
  "default",
@@ -24711,7 +24716,7 @@ function installBridgeProcessResilience() {
24711
24716
  }
24712
24717
 
24713
24718
  // src/cli-version.ts
24714
- var CLI_VERSION = "0.1.52".length > 0 ? "0.1.52" : "0.0.0-dev";
24719
+ var CLI_VERSION = "0.1.53".length > 0 ? "0.1.53" : "0.0.0-dev";
24715
24720
 
24716
24721
  // src/connection/heartbeat/constants.ts
24717
24722
  var BRIDGE_APP_HEARTBEAT_INTERVAL_MS = 1e4;
@@ -34614,24 +34619,45 @@ function truncatePatch(s) {
34614
34619
  }
34615
34620
 
34616
34621
  // src/git/changes/patch/unified-diff-for-file.ts
34622
+ var RENAME_DIFF_ARGS = ["-M", "--find-renames"];
34623
+ function devNullPath() {
34624
+ return process.platform === "win32" ? "NUL" : "/dev/null";
34625
+ }
34617
34626
  function patchTextFromGitDiffOutput(raw) {
34618
34627
  if (raw.trim() === "") return void 0;
34619
34628
  return normalizePatchContent(raw);
34620
34629
  }
34630
+ async function rawGitDiff(g, args) {
34631
+ return String(await g.raw([...args]).catch(() => ""));
34632
+ }
34633
+ async function unifiedDiffAgainstHead(g, pathInRepo, change, movedFromPathInRepo) {
34634
+ 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];
34635
+ return patchTextFromGitDiffOutput(await rawGitDiff(g, args));
34636
+ }
34637
+ async function unifiedDiffForAddedUntrackedFile(g, pathInRepo) {
34638
+ const raw = await rawGitDiff(g, [
34639
+ "diff",
34640
+ "--no-color",
34641
+ ...RENAME_DIFF_ARGS,
34642
+ "--no-index",
34643
+ "--",
34644
+ devNullPath(),
34645
+ pathInRepo
34646
+ ]);
34647
+ return patchTextFromGitDiffOutput(raw);
34648
+ }
34621
34649
  async function unifiedDiffForFile(repoCwd, pathInRepo, change, movedFromPathInRepo) {
34622
34650
  const g = cliSimpleGit(repoCwd);
34623
- const renameArgs = ["-M", "--find-renames"];
34624
- 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];
34625
- const raw = await g.raw([...args]).catch(() => "");
34626
- const patch = patchTextFromGitDiffOutput(String(raw));
34651
+ let patch = await unifiedDiffAgainstHead(g, pathInRepo, change, movedFromPathInRepo);
34652
+ if (!patch && change === "added") {
34653
+ patch = await unifiedDiffForAddedUntrackedFile(g, pathInRepo);
34654
+ }
34627
34655
  return patch ? truncatePatch(patch) : void 0;
34628
34656
  }
34629
34657
  async function unifiedDiffForFileInRange(repoCwd, range, pathInRepo, change, movedFromPathInRepo) {
34630
34658
  const g = cliSimpleGit(repoCwd);
34631
- const renameArgs = ["-M", "--find-renames"];
34632
- const args = change === "moved" && movedFromPathInRepo ? ["diff", "--no-color", ...renameArgs, "-U20000", range, "--", movedFromPathInRepo, pathInRepo] : ["diff", "--no-color", ...renameArgs, "-U20000", range, "--", pathInRepo];
34633
- const raw = await g.raw([...args]).catch(() => "");
34634
- const patch = patchTextFromGitDiffOutput(String(raw));
34659
+ const args = change === "moved" && movedFromPathInRepo ? ["diff", "--no-color", ...RENAME_DIFF_ARGS, "-U20000", range, "--", movedFromPathInRepo, pathInRepo] : ["diff", "--no-color", ...RENAME_DIFF_ARGS, "-U20000", range, "--", pathInRepo];
34660
+ const patch = patchTextFromGitDiffOutput(await rawGitDiff(g, args));
34635
34661
  return patch ? truncatePatch(patch) : void 0;
34636
34662
  }
34637
34663
 
@@ -34809,7 +34835,7 @@ async function parentForCommitDiff(g, sha) {
34809
34835
  }
34810
34836
 
34811
34837
  // src/git/changes/listing/rename-diff-args.ts
34812
- var RENAME_DIFF_ARGS = ["-M", "--find-renames"];
34838
+ var RENAME_DIFF_ARGS2 = ["-M", "--find-renames"];
34813
34839
 
34814
34840
  // src/git/changes/rows/pick-preferred-changed-file-row.ts
34815
34841
  function rowRank(row) {
@@ -34862,7 +34888,7 @@ async function listChangedFilesForCommit(repoGitCwd, repoRelPath, commitSha, opt
34862
34888
  const g = cliSimpleGit(repoGitCwd);
34863
34889
  const normRel = normalizeRepoRelPath(repoRelPath);
34864
34890
  const [nameStatusRaw, numstatRaw] = await Promise.all([
34865
- g.raw(["diff-tree", "--no-commit-id", "--name-status", "-r", ...RENAME_DIFF_ARGS, commitSha]).catch(() => ""),
34891
+ g.raw(["diff-tree", "--no-commit-id", "--name-status", "-r", ...RENAME_DIFF_ARGS2, commitSha]).catch(() => ""),
34866
34892
  g.raw(["show", "--numstat", "--format=format:", commitSha]).catch(() => "")
34867
34893
  ]);
34868
34894
  const parsed = parseDiffOutput(String(nameStatusRaw), String(numstatRaw));
@@ -35134,8 +35160,8 @@ async function enrichWorkingTreeFileRows(options) {
35134
35160
  async function listChangedFilesForRepo(repoGitCwd, repoRelPath, options = {}) {
35135
35161
  const g = cliSimpleGit(repoGitCwd);
35136
35162
  const [nameStatusRaw, numstatRaw, untrackedRaw] = await Promise.all([
35137
- g.raw(["diff", ...RENAME_DIFF_ARGS, "--name-status", "HEAD"]).catch(() => ""),
35138
- g.raw(["diff", ...RENAME_DIFF_ARGS, "HEAD", "--numstat"]).catch(() => ""),
35163
+ g.raw(["diff", ...RENAME_DIFF_ARGS2, "--name-status", "HEAD"]).catch(() => ""),
35164
+ g.raw(["diff", ...RENAME_DIFF_ARGS2, "HEAD", "--numstat"]).catch(() => ""),
35139
35165
  g.raw(["ls-files", "--others", "--exclude-standard"]).catch(() => "")
35140
35166
  ]);
35141
35167
  const parsed = parseDiffOutput(String(nameStatusRaw), String(numstatRaw));
@@ -37870,12 +37896,16 @@ var handleAgentConfigMessage = (msg, deps) => {
37870
37896
  // src/prompt-turn-queue/client-report.ts
37871
37897
  function sendPromptQueueClientReport(ws, queues) {
37872
37898
  if (!ws) return false;
37873
- sendWsMessage(ws, { type: "prompt_queue_client_report", queues });
37899
+ const wireQueues = {};
37900
+ for (const [queueKey, rows] of Object.entries(queues)) {
37901
+ wireQueues[queueKey] = rows.map((r) => ({ turnId: r.turnId, clientState: r.cliState }));
37902
+ }
37903
+ sendWsMessage(ws, { type: "prompt_queue_client_report", queues: wireQueues });
37874
37904
  return true;
37875
37905
  }
37876
37906
 
37877
37907
  // src/prompt-turn-queue/disk-store.ts
37878
- var MERGEABLE_SERVER_STATES = /* @__PURE__ */ new Set([
37908
+ var MERGEABLE_BRIDGE_SERVER_STATES = /* @__PURE__ */ new Set([
37879
37909
  "queued",
37880
37910
  "requeued",
37881
37911
  "requeued_with_revert",
@@ -37907,7 +37937,7 @@ async function writePersistedQueue(file2) {
37907
37937
  );
37908
37938
  });
37909
37939
  }
37910
- async function mergeServerQueueSnapshot(queueKey, serverTurns) {
37940
+ async function mergeBridgeServerQueueSnapshot(queueKey, serverTurns) {
37911
37941
  const prev = await readPersistedQueue(queueKey);
37912
37942
  const turns = [];
37913
37943
  for (const raw of serverTurns) {
@@ -37916,19 +37946,19 @@ async function mergeServerQueueSnapshot(queueKey, serverTurns) {
37916
37946
  const turnId = typeof o.turnId === "string" ? o.turnId : "";
37917
37947
  const sessionId = typeof o.sessionId === "string" ? o.sessionId : "";
37918
37948
  const turnOrd = typeof o.turnOrd === "number" ? o.turnOrd : Number(o.turnOrd) || 0;
37919
- const serverState = o.serverState;
37920
- const lastClientState = o.lastClientState ?? null;
37949
+ const bridgeServerState = o.serverState ?? o.bridgeServerState;
37950
+ const lastCliState = o.lastClientState ?? o.lastCliState ?? null;
37921
37951
  const payload = o.payload && typeof o.payload === "object" ? o.payload : {};
37922
37952
  if (!turnId || !sessionId) continue;
37923
- if (!MERGEABLE_SERVER_STATES.has(String(serverState))) continue;
37953
+ if (!MERGEABLE_BRIDGE_SERVER_STATES.has(String(bridgeServerState))) continue;
37924
37954
  const old = prev?.turns.find((t) => t.turnId === turnId);
37925
- const mergedClient = old?.lastClientState === "running" && lastClientState == null ? "running" : lastClientState;
37955
+ const mergedCli = old?.lastCliState === "running" && lastCliState == null ? "running" : lastCliState;
37926
37956
  turns.push({
37927
37957
  turnId,
37928
37958
  sessionId,
37929
37959
  turnOrd,
37930
- serverState,
37931
- lastClientState: mergedClient,
37960
+ bridgeServerState,
37961
+ lastCliState: mergedCli,
37932
37962
  payload
37933
37963
  });
37934
37964
  }
@@ -37966,15 +37996,12 @@ function dispatchLocalPrompt(next, deps) {
37966
37996
  }
37967
37997
 
37968
37998
  // src/prompt-turn-queue/runner/queue-selection.ts
37969
- function isRunnableServerState(s) {
37970
- return s === "queued" || s === "requeued" || s === "requeued_with_revert";
37971
- }
37972
37999
  function pickNextRunnableTurn(turns) {
37973
38000
  for (const t of turns) {
37974
- if (t.serverState === "discarded" || t.serverState === "stopping") continue;
37975
- if (t.serverState === "cancel_requested") continue;
37976
- if (!isRunnableServerState(t.serverState)) continue;
37977
- if (t.lastClientState === "running" || t.lastClientState === "stopped" || t.lastClientState === "failed" || t.lastClientState === "cancelled") {
38001
+ if (t.bridgeServerState === "discarded" || t.bridgeServerState === "stopping") continue;
38002
+ if (t.bridgeServerState === "cancel_requested") continue;
38003
+ if (!isRunnableBridgePromptTurnServerState(t.bridgeServerState)) continue;
38004
+ if (t.lastCliState === "running" || t.lastCliState === "stopped" || t.lastCliState === "failed" || t.lastCliState === "cancelled") {
37978
38005
  continue;
37979
38006
  }
37980
38007
  return t;
@@ -37982,7 +38009,7 @@ function pickNextRunnableTurn(turns) {
37982
38009
  return null;
37983
38010
  }
37984
38011
  function hasRunningTurn(turns) {
37985
- return turns.some((t) => t.lastClientState === "running");
38012
+ return turns.some((t) => t.lastCliState === "running");
37986
38013
  }
37987
38014
 
37988
38015
  // src/prompt-turn-queue/runner/run-id-queue-key-map.ts
@@ -37999,7 +38026,7 @@ function deleteRunIdQueueKey(runId) {
37999
38026
  return queueKey;
38000
38027
  }
38001
38028
  function syncRunningTurnQueueKeys(turns, queueKey) {
38002
- for (const running of turns.filter((t) => t.lastClientState === "running")) {
38029
+ for (const running of turns.filter((t) => t.lastCliState === "running")) {
38003
38030
  runIdToQueueKey.set(running.turnId, queueKey);
38004
38031
  }
38005
38032
  }
@@ -38007,7 +38034,7 @@ function syncRunningTurnQueueKeys(turns, queueKey) {
38007
38034
  // src/prompt-turn-queue/runner/run-local-revert-before-queued-prompt.ts
38008
38035
  import fs37 from "node:fs";
38009
38036
  async function runLocalRevertBeforeQueuedPrompt(next, deps) {
38010
- if (next.serverState !== "requeued_with_revert") return true;
38037
+ if (next.bridgeServerState !== "requeued_with_revert") return true;
38011
38038
  const sid = next.sessionId;
38012
38039
  const pl = next.payload;
38013
38040
  const tid = typeof pl.snapshotRevertTurnId === "string" && pl.snapshotRevertTurnId.trim() !== "" ? pl.snapshotRevertTurnId.trim() : next.turnId;
@@ -38037,9 +38064,9 @@ async function finalizePromptTurnOnBridge(getWs, runId, success2, opts) {
38037
38064
  if (!f) return false;
38038
38065
  const t = f.turns.find((x) => x.turnId === runId);
38039
38066
  if (!t) return false;
38040
- t.lastClientState = opts?.terminalClientState ?? (success2 ? "stopped" : "failed");
38067
+ t.lastCliState = opts?.terminalCliState ?? (success2 ? "stopped" : "failed");
38041
38068
  await writePersistedQueue(f);
38042
- sendPromptQueueClientReport(getWs(), { [queueKey]: [{ turnId: runId, clientState: t.lastClientState }] });
38069
+ sendPromptQueueClientReport(getWs(), { [queueKey]: [{ turnId: runId, cliState: t.lastCliState }] });
38043
38070
  return true;
38044
38071
  }
38045
38072
 
@@ -38050,7 +38077,7 @@ async function applyPromptQueueStateFromServer(msg, deps) {
38050
38077
  const getWs = deps.getWs;
38051
38078
  for (const [queueKey, serverTurns] of Object.entries(raw)) {
38052
38079
  if (!Array.isArray(serverTurns)) continue;
38053
- const file2 = await mergeServerQueueSnapshot(queueKey, serverTurns);
38080
+ const file2 = await mergeBridgeServerQueueSnapshot(queueKey, serverTurns);
38054
38081
  await writePersistedQueue(file2);
38055
38082
  }
38056
38083
  for (const [queueKey, serverTurns] of Object.entries(raw)) {
@@ -38063,14 +38090,14 @@ async function applyPromptQueueStateFromServer(msg, deps) {
38063
38090
  if (!Array.isArray(serverTurns)) continue;
38064
38091
  const file2 = await readPersistedQueue(queueKey);
38065
38092
  if (!file2) continue;
38066
- const cancelRow = file2.turns.find((t) => t.serverState === "cancel_requested" && t.lastClientState === "running");
38093
+ const cancelRow = file2.turns.find((t) => t.bridgeServerState === "cancel_requested" && t.lastCliState === "running");
38067
38094
  if (cancelRow) {
38068
38095
  const localCancelHandled = await deps.acpManager.cancelRun(cancelRow.turnId);
38069
38096
  if (!localCancelHandled) {
38070
38097
  deps.log(
38071
- `[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.`
38098
+ `[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.`
38072
38099
  );
38073
- await finalizePromptTurnOnBridge(deps.getWs, cancelRow.turnId, false, { terminalClientState: "cancelled" });
38100
+ await finalizePromptTurnOnBridge(deps.getWs, cancelRow.turnId, false, { terminalCliState: "cancelled" });
38074
38101
  const ws = deps.getWs();
38075
38102
  if (ws && cancelRow.sessionId) {
38076
38103
  sendWsMessage(ws, {
@@ -38095,16 +38122,16 @@ async function applyPromptQueueStateFromServer(msg, deps) {
38095
38122
  const next = pickNextRunnableTurn(file2.turns);
38096
38123
  if (!next) continue;
38097
38124
  if (!await runLocalRevertBeforeQueuedPrompt(next, deps)) {
38098
- next.lastClientState = "failed";
38125
+ next.lastCliState = "failed";
38099
38126
  await writePersistedQueue(file2);
38100
- sendPromptQueueClientReport(getWs(), { [queueKey]: [{ turnId: next.turnId, clientState: "failed" }] });
38127
+ sendPromptQueueClientReport(getWs(), { [queueKey]: [{ turnId: next.turnId, cliState: "failed" }] });
38101
38128
  continue;
38102
38129
  }
38103
- next.lastClientState = "running";
38130
+ next.lastCliState = "running";
38104
38131
  await writePersistedQueue(file2);
38105
38132
  setRunIdQueueKey(next.turnId, queueKey);
38106
38133
  startedThisTick.add(next.turnId);
38107
- report[queueKey] = [{ turnId: next.turnId, clientState: "running" }];
38134
+ report[queueKey] = [{ turnId: next.turnId, cliState: "running" }];
38108
38135
  }
38109
38136
  if (Object.keys(report).length > 0) {
38110
38137
  sendPromptQueueClientReport(getWs(), report);
@@ -38113,7 +38140,7 @@ async function applyPromptQueueStateFromServer(msg, deps) {
38113
38140
  if (!Array.isArray(serverTurns)) continue;
38114
38141
  const file2 = await readPersistedQueue(queueKey);
38115
38142
  if (!file2) continue;
38116
- const running = file2.turns.find((t) => t.lastClientState === "running");
38143
+ const running = file2.turns.find((t) => t.lastCliState === "running");
38117
38144
  if (!running || !startedThisTick.has(running.turnId)) continue;
38118
38145
  if (getRunIdQueueKey(running.turnId) !== queueKey) continue;
38119
38146
  dispatchLocalPrompt(running, deps);
@@ -38140,7 +38167,7 @@ function createBridgePromptSenders(deps, getWs) {
38140
38167
  getWs,
38141
38168
  typeof pr.runId === "string" ? pr.runId : void 0,
38142
38169
  pr.success === true,
38143
- cancelled ? { terminalClientState: "cancelled" } : void 0
38170
+ cancelled ? { terminalCliState: "cancelled" } : void 0
38144
38171
  ).catch(() => {
38145
38172
  });
38146
38173
  }