@buildautomaton/cli 0.1.9 → 0.1.10
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 +88 -37
- package/dist/cli.js.map +4 -4
- package/dist/index.js +88 -37
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2236,7 +2236,7 @@ var require_websocket = __commonJS({
|
|
|
2236
2236
|
"../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket.js"(exports, module) {
|
|
2237
2237
|
"use strict";
|
|
2238
2238
|
var EventEmitter2 = __require("events");
|
|
2239
|
-
var
|
|
2239
|
+
var https2 = __require("https");
|
|
2240
2240
|
var http = __require("http");
|
|
2241
2241
|
var net = __require("net");
|
|
2242
2242
|
var tls = __require("tls");
|
|
@@ -2771,7 +2771,7 @@ var require_websocket = __commonJS({
|
|
|
2771
2771
|
}
|
|
2772
2772
|
const defaultPort = isSecure ? 443 : 80;
|
|
2773
2773
|
const key = randomBytes(16).toString("base64");
|
|
2774
|
-
const request = isSecure ?
|
|
2774
|
+
const request = isSecure ? https2.request : http.request;
|
|
2775
2775
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
2776
2776
|
let perMessageDeflate;
|
|
2777
2777
|
opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
|
|
@@ -22050,9 +22050,6 @@ var require_dist2 = __commonJS({
|
|
|
22050
22050
|
}
|
|
22051
22051
|
});
|
|
22052
22052
|
|
|
22053
|
-
// src/bridge/connection/create-ws-bridge.ts
|
|
22054
|
-
import https from "node:https";
|
|
22055
|
-
|
|
22056
22053
|
// ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/wrapper.mjs
|
|
22057
22054
|
var import_stream = __toESM(require_stream(), 1);
|
|
22058
22055
|
var import_receiver = __toESM(require_receiver(), 1);
|
|
@@ -22073,20 +22070,44 @@ function applyCliOutboundNetworkPreferences() {
|
|
|
22073
22070
|
}
|
|
22074
22071
|
}
|
|
22075
22072
|
|
|
22073
|
+
// src/bridge/connection/cli-ws-client.ts
|
|
22074
|
+
import https from "node:https";
|
|
22075
|
+
function buildCliWebSocketClientOptions(wsUrl) {
|
|
22076
|
+
const wsOptions = { perMessageDeflate: false, family: 4 };
|
|
22077
|
+
if (wsUrl.startsWith("wss://")) {
|
|
22078
|
+
wsOptions.agent = new https.Agent({ rejectUnauthorized: false, family: 4 });
|
|
22079
|
+
}
|
|
22080
|
+
return wsOptions;
|
|
22081
|
+
}
|
|
22082
|
+
function logCliWebSocketError(log2, serviceLabel, err, detail) {
|
|
22083
|
+
const mid = detail ? ` ${detail}` : "";
|
|
22084
|
+
log2(`${serviceLabel} WebSocket error${mid}: ${err.message}`);
|
|
22085
|
+
}
|
|
22086
|
+
function safeCloseWebSocket(ws) {
|
|
22087
|
+
try {
|
|
22088
|
+
if (ws.readyState === wrapper_default.CLOSED) {
|
|
22089
|
+
ws.removeAllListeners();
|
|
22090
|
+
return;
|
|
22091
|
+
}
|
|
22092
|
+
ws.once("close", () => {
|
|
22093
|
+
ws.removeAllListeners();
|
|
22094
|
+
});
|
|
22095
|
+
ws.close();
|
|
22096
|
+
} catch {
|
|
22097
|
+
try {
|
|
22098
|
+
ws.removeAllListeners();
|
|
22099
|
+
} catch {
|
|
22100
|
+
}
|
|
22101
|
+
}
|
|
22102
|
+
}
|
|
22103
|
+
|
|
22076
22104
|
// src/bridge/connection/create-ws-bridge.ts
|
|
22077
22105
|
var BRIDGE_AUTH_ERROR_HEADER = "x-bridge-auth-error";
|
|
22078
22106
|
var BRIDGE_AUTH_ERROR_TOKEN_INVALID = "token_invalid";
|
|
22079
22107
|
function createWsBridge(options) {
|
|
22080
22108
|
const { url: url2, onMessage, onOpen, onClose, onError: onError2, onAuthInvalid, clientPingIntervalMs } = options;
|
|
22081
22109
|
applyCliOutboundNetworkPreferences();
|
|
22082
|
-
const
|
|
22083
|
-
perMessageDeflate: false,
|
|
22084
|
-
family: 4
|
|
22085
|
-
};
|
|
22086
|
-
if (url2.startsWith("wss://")) {
|
|
22087
|
-
wsOptions.agent = new https.Agent({ rejectUnauthorized: false, family: 4 });
|
|
22088
|
-
}
|
|
22089
|
-
const ws = new wrapper_default(url2, wsOptions);
|
|
22110
|
+
const ws = new wrapper_default(url2, buildCliWebSocketClientOptions(url2));
|
|
22090
22111
|
let clientPingTimer = null;
|
|
22091
22112
|
function clearClientPing() {
|
|
22092
22113
|
if (clientPingTimer != null) {
|
|
@@ -23437,9 +23458,9 @@ function runPendingAuth(options) {
|
|
|
23437
23458
|
keepaliveInterval = null;
|
|
23438
23459
|
}
|
|
23439
23460
|
if (ws) {
|
|
23440
|
-
ws
|
|
23441
|
-
ws.close();
|
|
23461
|
+
const w = ws;
|
|
23442
23462
|
ws = null;
|
|
23463
|
+
safeCloseWebSocket(w);
|
|
23443
23464
|
}
|
|
23444
23465
|
}
|
|
23445
23466
|
function connect() {
|
|
@@ -23482,7 +23503,7 @@ function runPendingAuth(options) {
|
|
|
23482
23503
|
connect();
|
|
23483
23504
|
}, delay2);
|
|
23484
23505
|
},
|
|
23485
|
-
onError: (err) => logFn
|
|
23506
|
+
onError: (err) => logCliWebSocketError(logFn, "[Bridge service]", err, "while waiting for sign-in"),
|
|
23486
23507
|
onMessage: (data) => {
|
|
23487
23508
|
const msg = data;
|
|
23488
23509
|
if (msg.type === "auth_token" && typeof msg.token === "string") {
|
|
@@ -30037,14 +30058,50 @@ async function removeSessionWorktrees(paths, log2) {
|
|
|
30037
30058
|
}
|
|
30038
30059
|
|
|
30039
30060
|
// src/git/working-tree-status.ts
|
|
30040
|
-
async function
|
|
30041
|
-
|
|
30061
|
+
async function tryConfigGet(g, key) {
|
|
30062
|
+
try {
|
|
30063
|
+
const out = await g.raw(["config", "--get", key]);
|
|
30064
|
+
const v = String(out).trim();
|
|
30065
|
+
return v || null;
|
|
30066
|
+
} catch {
|
|
30067
|
+
return null;
|
|
30068
|
+
}
|
|
30069
|
+
}
|
|
30070
|
+
async function resolveRemoteTrackingRefForAhead(g) {
|
|
30042
30071
|
try {
|
|
30043
30072
|
await g.raw(["rev-parse", "--verify", "@{u}"]);
|
|
30073
|
+
return "@{u}";
|
|
30044
30074
|
} catch {
|
|
30045
|
-
return 0;
|
|
30046
30075
|
}
|
|
30047
|
-
const
|
|
30076
|
+
const branch = (await g.raw(["rev-parse", "--abbrev-ref", "HEAD"])).trim();
|
|
30077
|
+
if (!branch || branch === "HEAD") return null;
|
|
30078
|
+
const remote = await tryConfigGet(g, `branch.${branch}.remote`) ?? "origin";
|
|
30079
|
+
const merge2 = await tryConfigGet(g, `branch.${branch}.merge`);
|
|
30080
|
+
if (merge2) {
|
|
30081
|
+
const upstreamBranch = merge2.replace(/^refs\/heads\//, "");
|
|
30082
|
+
const ref = `refs/remotes/${remote}/${upstreamBranch}`;
|
|
30083
|
+
try {
|
|
30084
|
+
await g.raw(["rev-parse", "--verify", ref]);
|
|
30085
|
+
return ref;
|
|
30086
|
+
} catch {
|
|
30087
|
+
}
|
|
30088
|
+
}
|
|
30089
|
+
const fallbackRef = `refs/remotes/${remote}/${branch}`;
|
|
30090
|
+
try {
|
|
30091
|
+
await g.raw(["rev-parse", "--verify", fallbackRef]);
|
|
30092
|
+
return fallbackRef;
|
|
30093
|
+
} catch {
|
|
30094
|
+
return null;
|
|
30095
|
+
}
|
|
30096
|
+
}
|
|
30097
|
+
async function commitsAheadOfRemoteTracking(repoDir) {
|
|
30098
|
+
const g = simpleGit(repoDir);
|
|
30099
|
+
const trackingRef = await resolveRemoteTrackingRefForAhead(g);
|
|
30100
|
+
if (!trackingRef) return 0;
|
|
30101
|
+
const localSha = (await g.raw(["rev-parse", "HEAD"])).trim();
|
|
30102
|
+
const remoteSha = (await g.raw(["rev-parse", trackingRef])).trim();
|
|
30103
|
+
if (localSha === remoteSha) return 0;
|
|
30104
|
+
const out = await g.raw(["rev-list", "--count", `${trackingRef}..HEAD`]);
|
|
30048
30105
|
const n = parseInt(String(out).trim(), 10);
|
|
30049
30106
|
return Number.isNaN(n) ? 0 : n;
|
|
30050
30107
|
}
|
|
@@ -30052,7 +30109,7 @@ async function getRepoWorkingTreeStatus(repoDir) {
|
|
|
30052
30109
|
const g = simpleGit(repoDir);
|
|
30053
30110
|
const st = await g.status();
|
|
30054
30111
|
const hasUncommittedChanges = (st.files?.length ?? 0) > 0;
|
|
30055
|
-
const ahead = await
|
|
30112
|
+
const ahead = await commitsAheadOfRemoteTracking(repoDir);
|
|
30056
30113
|
return { hasUncommittedChanges, hasUnpushedCommits: ahead > 0 };
|
|
30057
30114
|
}
|
|
30058
30115
|
async function aggregateSessionPathsWorkingTreeStatus(paths) {
|
|
@@ -30068,7 +30125,7 @@ async function aggregateSessionPathsWorkingTreeStatus(paths) {
|
|
|
30068
30125
|
async function pushAheadOfUpstreamForPaths(paths) {
|
|
30069
30126
|
for (const p of paths) {
|
|
30070
30127
|
const g = simpleGit(p);
|
|
30071
|
-
const ahead = await
|
|
30128
|
+
const ahead = await commitsAheadOfRemoteTracking(p);
|
|
30072
30129
|
if (ahead <= 0) continue;
|
|
30073
30130
|
await g.push();
|
|
30074
30131
|
}
|
|
@@ -31343,9 +31400,6 @@ var DevServerManager = class {
|
|
|
31343
31400
|
}
|
|
31344
31401
|
};
|
|
31345
31402
|
|
|
31346
|
-
// src/firehose/connect-firehose.ts
|
|
31347
|
-
import https2 from "node:https";
|
|
31348
|
-
|
|
31349
31403
|
// src/firehose/proxy/start-streaming-proxy.ts
|
|
31350
31404
|
function startStreamingProxy(ws, log2, pr) {
|
|
31351
31405
|
proxyToLocalStreaming(pr, {
|
|
@@ -31485,11 +31539,7 @@ function connectFirehose(options) {
|
|
|
31485
31539
|
const { firehoseServerUrl, workspaceId, bridgeName, proxyPorts, log: log2, devServerManager, onOpen, onClose } = options;
|
|
31486
31540
|
const wsUrl = buildFirehoseCliWsUrl(firehoseServerUrl);
|
|
31487
31541
|
applyCliOutboundNetworkPreferences();
|
|
31488
|
-
const
|
|
31489
|
-
if (wsUrl.startsWith("wss://")) {
|
|
31490
|
-
wsOptions.agent = new https2.Agent({ rejectUnauthorized: false, family: 4 });
|
|
31491
|
-
}
|
|
31492
|
-
const ws = new wrapper_default(wsUrl, wsOptions);
|
|
31542
|
+
const ws = new wrapper_default(wsUrl, buildCliWebSocketClientOptions(wsUrl));
|
|
31493
31543
|
let clientPingTimer = null;
|
|
31494
31544
|
function clearClientPing() {
|
|
31495
31545
|
if (clientPingTimer != null) {
|
|
@@ -31540,17 +31590,13 @@ function connectFirehose(options) {
|
|
|
31540
31590
|
});
|
|
31541
31591
|
ws.on("error", (err) => {
|
|
31542
31592
|
clearClientPing();
|
|
31543
|
-
log2
|
|
31593
|
+
logCliWebSocketError(log2, "[Proxy and log service]", err);
|
|
31544
31594
|
});
|
|
31545
31595
|
return {
|
|
31546
31596
|
close() {
|
|
31547
31597
|
clearClientPing();
|
|
31548
31598
|
devServerManager.detachFirehose();
|
|
31549
|
-
|
|
31550
|
-
ws.removeAllListeners();
|
|
31551
|
-
ws.close();
|
|
31552
|
-
} catch {
|
|
31553
|
-
}
|
|
31599
|
+
safeCloseWebSocket(ws);
|
|
31554
31600
|
},
|
|
31555
31601
|
isConnected: () => ws.readyState === wrapper_default.OPEN
|
|
31556
31602
|
};
|
|
@@ -32787,6 +32833,11 @@ function createMainBridgeWebSocketLifecycle(params) {
|
|
|
32787
32833
|
const prev = state.currentWs;
|
|
32788
32834
|
if (prev) {
|
|
32789
32835
|
prev.removeAllListeners();
|
|
32836
|
+
prev.once("error", () => {
|
|
32837
|
+
});
|
|
32838
|
+
prev.once("close", () => {
|
|
32839
|
+
prev.removeAllListeners();
|
|
32840
|
+
});
|
|
32790
32841
|
try {
|
|
32791
32842
|
prev.close();
|
|
32792
32843
|
} catch {
|
|
@@ -32832,7 +32883,7 @@ function createMainBridgeWebSocketLifecycle(params) {
|
|
|
32832
32883
|
},
|
|
32833
32884
|
onOpen: handleOpen,
|
|
32834
32885
|
onClose: handleClose,
|
|
32835
|
-
onError: (err) => logFn
|
|
32886
|
+
onError: (err) => logCliWebSocketError(logFn, "[Bridge service]", err),
|
|
32836
32887
|
onMessage: (data) => handleBridgeMessage(data, messageDeps)
|
|
32837
32888
|
});
|
|
32838
32889
|
}
|