@buildautomaton/cli 0.1.41 → 0.1.43

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.41".length > 0 ? "0.1.41" : "0.0.0-dev";
25177
+ var CLI_VERSION = "0.1.43".length > 0 ? "0.1.43" : "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";
@@ -27435,18 +27435,6 @@ async function closeBridgeConnection(state, acpManager, devServerManager, log2)
27435
27435
  say("Shutdown complete.");
27436
27436
  }
27437
27437
 
27438
- // src/agents/acp/acp-idle-disconnect-ms.ts
27439
- var DEFAULT_ACP_IDLE_DISCONNECT_MS = 10 * 60 * 1e3;
27440
- function resolveAcpIdleDisconnectMs() {
27441
- const raw = process.env.BUILDAUTOMATON_ACP_IDLE_DISCONNECT_MS;
27442
- if (raw === "0") return 0;
27443
- if (raw != null && raw.trim() !== "") {
27444
- const parsed = Number(raw);
27445
- if (Number.isFinite(parsed) && parsed >= 0) return parsed;
27446
- }
27447
- return DEFAULT_ACP_IDLE_DISCONNECT_MS;
27448
- }
27449
-
27450
27438
  // src/agents/acp/acp-prompt-routing-registry.ts
27451
27439
  var AcpPromptRoutingRegistry = class {
27452
27440
  runs = /* @__PURE__ */ new Map();
@@ -27496,9 +27484,7 @@ function createAcpManagerContext(options) {
27496
27484
  acpAgents: /* @__PURE__ */ new Map(),
27497
27485
  promptRouting: new AcpPromptRoutingRegistry(),
27498
27486
  runDispatch: /* @__PURE__ */ new Map(),
27499
- pendingCancelRunIds: /* @__PURE__ */ new Set(),
27500
- idleDisconnectTimers: /* @__PURE__ */ new Map(),
27501
- idleDisconnectMs: options.idleDisconnectMs
27487
+ pendingCancelRunIds: /* @__PURE__ */ new Set()
27502
27488
  };
27503
27489
  }
27504
27490
 
@@ -27917,6 +27903,99 @@ function dedupeSessionFileChangesByPath(items, richness = (item) => defaultRichn
27917
27903
  return Array.from(byPath.entries()).sort(([a], [b]) => a.localeCompare(b)).map(([, v]) => v);
27918
27904
  }
27919
27905
 
27906
+ // ../types/src/diff/line-diff.ts
27907
+ function normalizeDiffLineText(line) {
27908
+ return line.replace(/\r$/, "").replace(/\s*\\s*$/, "");
27909
+ }
27910
+ function normalizePatchContent(patch) {
27911
+ return patch.replace(/^\n+/, "").replace(/\n+$/, "");
27912
+ }
27913
+ function splitTextIntoDiffLines(text) {
27914
+ if (text.length === 0) return [];
27915
+ const lines = text.split("\n").map((line) => normalizeDiffLineText(line));
27916
+ if (text.endsWith("\n") && lines.at(-1) === "") {
27917
+ lines.pop();
27918
+ }
27919
+ return lines;
27920
+ }
27921
+ function createEofNewlineDiffLine(change) {
27922
+ return {
27923
+ type: change === "added" ? "add" : "remove",
27924
+ line: "",
27925
+ oldLineNo: null,
27926
+ newLineNo: null,
27927
+ eofNewlineChange: change
27928
+ };
27929
+ }
27930
+ function hasSameLogicalLines(left, right) {
27931
+ return left.length === right.length && left.every((line, index) => line === right[index]);
27932
+ }
27933
+ function detectEofNewlineChange(oldText, newText, oldLines, newLines) {
27934
+ if (!hasSameLogicalLines(oldLines, newLines) || oldLines.length === 0) return null;
27935
+ if (!oldText.endsWith("\n") && newText.endsWith("\n")) return "added";
27936
+ if (oldText.endsWith("\n") && !newText.endsWith("\n")) return "removed";
27937
+ return null;
27938
+ }
27939
+ function computeLineDiff(oldText, newText) {
27940
+ const oldLines = splitTextIntoDiffLines(oldText);
27941
+ const newLines = splitTextIntoDiffLines(newText);
27942
+ const m = oldLines.length;
27943
+ const n = newLines.length;
27944
+ const dp = Array(m + 1);
27945
+ for (let i2 = 0; i2 <= m; i2++) dp[i2] = Array(n + 1).fill(0);
27946
+ for (let i2 = 1; i2 <= m; i2++) {
27947
+ for (let j2 = 1; j2 <= n; j2++) {
27948
+ if (oldLines[i2 - 1] === newLines[j2 - 1]) {
27949
+ dp[i2][j2] = dp[i2 - 1][j2 - 1] + 1;
27950
+ } else {
27951
+ dp[i2][j2] = Math.max(dp[i2 - 1][j2], dp[i2][j2 - 1]);
27952
+ }
27953
+ }
27954
+ }
27955
+ const result = [];
27956
+ let i = m;
27957
+ let j = n;
27958
+ while (i > 0 || j > 0) {
27959
+ if (i > 0 && j > 0 && oldLines[i - 1] === newLines[j - 1]) {
27960
+ result.unshift({ type: "context", line: oldLines[i - 1] });
27961
+ i--;
27962
+ j--;
27963
+ } else if (j > 0 && (i === 0 || dp[i][j - 1] >= dp[i - 1][j])) {
27964
+ result.unshift({ type: "add", line: newLines[j - 1] });
27965
+ j--;
27966
+ } else {
27967
+ result.unshift({ type: "remove", line: oldLines[i - 1] });
27968
+ i--;
27969
+ }
27970
+ }
27971
+ const eofNewlineChange = detectEofNewlineChange(oldText, newText, oldLines, newLines);
27972
+ if (eofNewlineChange) result.push(createEofNewlineDiffLine(eofNewlineChange));
27973
+ return result;
27974
+ }
27975
+ function editSnippetToUnifiedDiff(filePath, oldText, newText) {
27976
+ const lines = computeLineDiff(oldText, newText);
27977
+ const out = [`--- ${filePath}`, `+++ ${filePath}`];
27978
+ for (const d of lines) {
27979
+ if (d.eofNewlineChange) {
27980
+ const previous = out.at(-1);
27981
+ if (previous?.startsWith(" ")) {
27982
+ const line = previous.slice(1);
27983
+ out.pop();
27984
+ if (d.eofNewlineChange === "added") {
27985
+ out.push(`-${line}`, "\", `+${line}`);
27986
+ } else {
27987
+ out.push(`-${line}`, `+${line}`, "\");
27988
+ }
27989
+ continue;
27990
+ }
27991
+ }
27992
+ if (d.type === "add") out.push(`+${d.line}`);
27993
+ else if (d.type === "remove") out.push(`-${d.line}`);
27994
+ else out.push(` ${d.line}`);
27995
+ }
27996
+ return out.join("\n");
27997
+ }
27998
+
27920
27999
  // ../types/src/artifacts.ts
27921
28000
  init_zod();
27922
28001
  var ArtifactMetaSchema = external_exports.object({
@@ -28433,52 +28512,6 @@ function enrichAcpPermissionRpcResultFromRequestParams(result, params) {
28433
28512
  import { mkdirSync, readFileSync as readFileSync2, writeFileSync } from "node:fs";
28434
28513
  import { dirname as dirname3 } from "node:path";
28435
28514
 
28436
- // src/files/diff/unified-diff.ts
28437
- function computeLineDiff(oldText, newText) {
28438
- const oldLines = oldText.split("\n");
28439
- const newLines = newText.split("\n");
28440
- const m = oldLines.length;
28441
- const n = newLines.length;
28442
- const dp = Array(m + 1);
28443
- for (let i2 = 0; i2 <= m; i2++) dp[i2] = Array(n + 1).fill(0);
28444
- for (let i2 = 1; i2 <= m; i2++) {
28445
- for (let j2 = 1; j2 <= n; j2++) {
28446
- if (oldLines[i2 - 1] === newLines[j2 - 1]) {
28447
- dp[i2][j2] = dp[i2 - 1][j2 - 1] + 1;
28448
- } else {
28449
- dp[i2][j2] = Math.max(dp[i2 - 1][j2], dp[i2][j2 - 1]);
28450
- }
28451
- }
28452
- }
28453
- const result = [];
28454
- let i = m;
28455
- let j = n;
28456
- while (i > 0 || j > 0) {
28457
- if (i > 0 && j > 0 && oldLines[i - 1] === newLines[j - 1]) {
28458
- result.unshift({ type: "context", line: oldLines[i - 1] });
28459
- i--;
28460
- j--;
28461
- } else if (j > 0 && (i === 0 || dp[i][j - 1] >= dp[i - 1][j])) {
28462
- result.unshift({ type: "add", line: newLines[j - 1] });
28463
- j--;
28464
- } else {
28465
- result.unshift({ type: "remove", line: oldLines[i - 1] });
28466
- i--;
28467
- }
28468
- }
28469
- return result;
28470
- }
28471
- function editSnippetToUnifiedDiff(filePath, oldText, newText) {
28472
- const lines = computeLineDiff(oldText, newText);
28473
- const out = [`--- ${filePath}`, `+++ ${filePath}`];
28474
- for (const d of lines) {
28475
- if (d.type === "add") out.push(`+${d.line}`);
28476
- else if (d.type === "remove") out.push(`-${d.line}`);
28477
- else out.push(` ${d.line}`);
28478
- }
28479
- return out.join("\n");
28480
- }
28481
-
28482
28515
  // src/agents/acp/safe-fs-path.ts
28483
28516
  import * as path13 from "node:path";
28484
28517
  function resolveSafePathUnderCwd(cwd, filePath) {
@@ -30846,55 +30879,8 @@ async function ensureAcpClient(options) {
30846
30879
  return state.acpStartPromise;
30847
30880
  }
30848
30881
 
30849
- // src/agents/acp/manager/idle-disconnect.ts
30850
- function hasActiveWorkForAcpAgent(ctx, acpAgentKey) {
30851
- if (ctx.promptRouting.getStreamingRunId(acpAgentKey)) return true;
30852
- for (const meta of ctx.runDispatch.values()) {
30853
- if (meta.acpAgentKey === acpAgentKey) return true;
30854
- }
30855
- return false;
30856
- }
30857
- function clearIdleDisconnectTimer(ctx, acpAgentKey) {
30858
- const timer = ctx.idleDisconnectTimers.get(acpAgentKey);
30859
- if (timer == null) return;
30860
- clearTimeout(timer);
30861
- ctx.idleDisconnectTimers.delete(acpAgentKey);
30862
- }
30863
- function disconnectIdleAcpAgent(ctx, acpAgentKey) {
30864
- clearIdleDisconnectTimer(ctx, acpAgentKey);
30865
- if (hasActiveWorkForAcpAgent(ctx, acpAgentKey)) return;
30866
- const state = ctx.acpAgents.get(acpAgentKey);
30867
- if (!state?.acpHandle && !state?.acpStartPromise) {
30868
- ctx.acpAgents.delete(acpAgentKey);
30869
- return;
30870
- }
30871
- const handle = state.acpHandle;
30872
- void (async () => {
30873
- try {
30874
- await handle?.disconnectGracefully();
30875
- } catch {
30876
- }
30877
- invalidateAcpClientState(state);
30878
- ctx.acpAgents.delete(acpAgentKey);
30879
- logDebug(`[Agent] Idle disconnect (${acpAgentKey.split("::")[0] ?? acpAgentKey})`);
30880
- })();
30881
- }
30882
- function scheduleIdleDisconnect(ctx, acpAgentKey) {
30883
- if (ctx.idleDisconnectMs <= 0) return;
30884
- clearIdleDisconnectTimer(ctx, acpAgentKey);
30885
- const timer = setTimeout(() => {
30886
- ctx.idleDisconnectTimers.delete(acpAgentKey);
30887
- disconnectIdleAcpAgent(ctx, acpAgentKey);
30888
- }, ctx.idleDisconnectMs);
30889
- timer.unref?.();
30890
- ctx.idleDisconnectTimers.set(acpAgentKey, timer);
30891
- }
30892
-
30893
30882
  // src/agents/acp/manager/disconnect-all.ts
30894
30883
  async function disconnectAll(ctx) {
30895
- for (const acpAgentKey of ctx.idleDisconnectTimers.keys()) {
30896
- clearIdleDisconnectTimer(ctx, acpAgentKey);
30897
- }
30898
30884
  await Promise.all(
30899
30885
  [...ctx.acpAgents.values()].map(async (state) => {
30900
30886
  try {
@@ -36205,7 +36191,6 @@ function handlePrompt(ctx, opts) {
36205
36191
  }
36206
36192
  const activeAcpAgentKey = acpAgentKey;
36207
36193
  ctx.pendingCancelRunIds.delete(activeRunId);
36208
- clearIdleDisconnectTimer(ctx, activeAcpAgentKey);
36209
36194
  ctx.promptRouting.registerRun({ sessionId, runId: activeRunId });
36210
36195
  ctx.runDispatch.set(activeRunId, { acpAgentKey: activeAcpAgentKey });
36211
36196
  async function run() {
@@ -36288,7 +36273,6 @@ function handlePrompt(ctx, opts) {
36288
36273
  ctx.promptRouting.unregisterRun(activeRunId);
36289
36274
  ctx.runDispatch.delete(activeRunId);
36290
36275
  ctx.pendingCancelRunIds.delete(activeRunId);
36291
- scheduleIdleDisconnect(ctx, activeAcpAgentKey);
36292
36276
  });
36293
36277
  }
36294
36278
 
@@ -36306,8 +36290,7 @@ function logPromptReceivedFromBridge(ctx, opts) {
36306
36290
  async function createAcpManager(options) {
36307
36291
  const ctx = createAcpManagerContext({
36308
36292
  log: options.log,
36309
- reportAgentCapabilities: options.reportAgentCapabilities,
36310
- idleDisconnectMs: resolveAcpIdleDisconnectMs()
36293
+ reportAgentCapabilities: options.reportAgentCapabilities
36311
36294
  });
36312
36295
  return {
36313
36296
  setPreferredAgentType(agentType) {
@@ -36814,12 +36797,16 @@ async function hydrateUnifiedPatchWithFileContext(patch, filePath, repoGitCwd, p
36814
36797
  }
36815
36798
 
36816
36799
  // src/git/changes/unified-diff-for-file.ts
36800
+ function patchTextFromGitDiffOutput(raw) {
36801
+ if (raw.trim() === "") return void 0;
36802
+ return normalizePatchContent(raw);
36803
+ }
36817
36804
  async function unifiedDiffForFile(repoCwd, pathInRepo, change) {
36818
36805
  const g = cliSimpleGit(repoCwd);
36819
36806
  const args = change === "added" ? ["diff", "--no-color", "HEAD", "--", pathInRepo] : change === "removed" ? ["diff", "--no-color", "HEAD", "--", pathInRepo] : ["diff", "--no-color", "HEAD", "--", pathInRepo];
36820
36807
  const raw = await g.raw([...args]).catch(() => "");
36821
- const t = String(raw).trim();
36822
- return t ? truncatePatch(t) : void 0;
36808
+ const patch = patchTextFromGitDiffOutput(String(raw));
36809
+ return patch ? truncatePatch(patch) : void 0;
36823
36810
  }
36824
36811
 
36825
36812
  // src/git/changes/list-changed-files-for-repo.ts