@scalequality/cli 0.4.43 → 0.4.45
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/README.md +28 -0
- package/bin/scalequality.mjs +7 -2
- package/dist/connect.build.json +3 -2
- package/dist/connect.cjs +956 -395
- package/dist/hook.cjs +6 -0
- package/package.json +2 -2
package/dist/connect.cjs
CHANGED
|
@@ -34,9 +34,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
34
34
|
mod
|
|
35
35
|
));
|
|
36
36
|
|
|
37
|
-
//
|
|
37
|
+
// node_modules/ws/lib/constants.js
|
|
38
38
|
var require_constants = __commonJS({
|
|
39
|
-
"
|
|
39
|
+
"node_modules/ws/lib/constants.js"(exports2, module2) {
|
|
40
40
|
"use strict";
|
|
41
41
|
var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
|
|
42
42
|
var hasBlob = typeof Blob !== "undefined";
|
|
@@ -57,9 +57,9 @@ var require_constants = __commonJS({
|
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
//
|
|
60
|
+
// node_modules/ws/lib/buffer-util.js
|
|
61
61
|
var require_buffer_util = __commonJS({
|
|
62
|
-
"
|
|
62
|
+
"node_modules/ws/lib/buffer-util.js"(exports2, module2) {
|
|
63
63
|
"use strict";
|
|
64
64
|
var { EMPTY_BUFFER } = require_constants();
|
|
65
65
|
var FastBuffer = Buffer[Symbol.species];
|
|
@@ -132,9 +132,9 @@ var require_buffer_util = __commonJS({
|
|
|
132
132
|
}
|
|
133
133
|
});
|
|
134
134
|
|
|
135
|
-
//
|
|
135
|
+
// node_modules/ws/lib/limiter.js
|
|
136
136
|
var require_limiter = __commonJS({
|
|
137
|
-
"
|
|
137
|
+
"node_modules/ws/lib/limiter.js"(exports2, module2) {
|
|
138
138
|
"use strict";
|
|
139
139
|
var kDone = /* @__PURE__ */ Symbol("kDone");
|
|
140
140
|
var kRun = /* @__PURE__ */ Symbol("kRun");
|
|
@@ -182,9 +182,9 @@ var require_limiter = __commonJS({
|
|
|
182
182
|
}
|
|
183
183
|
});
|
|
184
184
|
|
|
185
|
-
//
|
|
185
|
+
// node_modules/ws/lib/permessage-deflate.js
|
|
186
186
|
var require_permessage_deflate = __commonJS({
|
|
187
|
-
"
|
|
187
|
+
"node_modules/ws/lib/permessage-deflate.js"(exports2, module2) {
|
|
188
188
|
"use strict";
|
|
189
189
|
var zlib = require("zlib");
|
|
190
190
|
var bufferUtil = require_buffer_util();
|
|
@@ -565,9 +565,9 @@ var require_permessage_deflate = __commonJS({
|
|
|
565
565
|
}
|
|
566
566
|
});
|
|
567
567
|
|
|
568
|
-
//
|
|
568
|
+
// node_modules/ws/lib/validation.js
|
|
569
569
|
var require_validation = __commonJS({
|
|
570
|
-
"
|
|
570
|
+
"node_modules/ws/lib/validation.js"(exports2, module2) {
|
|
571
571
|
"use strict";
|
|
572
572
|
var { isUtf8 } = require("buffer");
|
|
573
573
|
var { hasBlob } = require_constants();
|
|
@@ -766,9 +766,9 @@ var require_validation = __commonJS({
|
|
|
766
766
|
}
|
|
767
767
|
});
|
|
768
768
|
|
|
769
|
-
//
|
|
769
|
+
// node_modules/ws/lib/receiver.js
|
|
770
770
|
var require_receiver = __commonJS({
|
|
771
|
-
"
|
|
771
|
+
"node_modules/ws/lib/receiver.js"(exports2, module2) {
|
|
772
772
|
"use strict";
|
|
773
773
|
var { Writable } = require("stream");
|
|
774
774
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
@@ -1389,9 +1389,9 @@ var require_receiver = __commonJS({
|
|
|
1389
1389
|
}
|
|
1390
1390
|
});
|
|
1391
1391
|
|
|
1392
|
-
//
|
|
1392
|
+
// node_modules/ws/lib/sender.js
|
|
1393
1393
|
var require_sender = __commonJS({
|
|
1394
|
-
"
|
|
1394
|
+
"node_modules/ws/lib/sender.js"(exports2, module2) {
|
|
1395
1395
|
"use strict";
|
|
1396
1396
|
var { Duplex } = require("stream");
|
|
1397
1397
|
var { randomFillSync } = require("crypto");
|
|
@@ -1882,9 +1882,9 @@ var require_sender = __commonJS({
|
|
|
1882
1882
|
}
|
|
1883
1883
|
});
|
|
1884
1884
|
|
|
1885
|
-
//
|
|
1885
|
+
// node_modules/ws/lib/event-target.js
|
|
1886
1886
|
var require_event_target = __commonJS({
|
|
1887
|
-
"
|
|
1887
|
+
"node_modules/ws/lib/event-target.js"(exports2, module2) {
|
|
1888
1888
|
"use strict";
|
|
1889
1889
|
var { kForOnEventAttribute, kListener } = require_constants();
|
|
1890
1890
|
var kCode = /* @__PURE__ */ Symbol("kCode");
|
|
@@ -2111,9 +2111,9 @@ var require_event_target = __commonJS({
|
|
|
2111
2111
|
}
|
|
2112
2112
|
});
|
|
2113
2113
|
|
|
2114
|
-
//
|
|
2114
|
+
// node_modules/ws/lib/extension.js
|
|
2115
2115
|
var require_extension = __commonJS({
|
|
2116
|
-
"
|
|
2116
|
+
"node_modules/ws/lib/extension.js"(exports2, module2) {
|
|
2117
2117
|
"use strict";
|
|
2118
2118
|
var { tokenChars } = require_validation();
|
|
2119
2119
|
function push(dest, name, elem) {
|
|
@@ -2264,16 +2264,16 @@ var require_extension = __commonJS({
|
|
|
2264
2264
|
}
|
|
2265
2265
|
});
|
|
2266
2266
|
|
|
2267
|
-
//
|
|
2267
|
+
// node_modules/ws/lib/websocket.js
|
|
2268
2268
|
var require_websocket = __commonJS({
|
|
2269
|
-
"
|
|
2269
|
+
"node_modules/ws/lib/websocket.js"(exports2, module2) {
|
|
2270
2270
|
"use strict";
|
|
2271
2271
|
var EventEmitter = require("events");
|
|
2272
2272
|
var https = require("https");
|
|
2273
2273
|
var http = require("http");
|
|
2274
2274
|
var net = require("net");
|
|
2275
2275
|
var tls = require("tls");
|
|
2276
|
-
var { randomBytes, createHash:
|
|
2276
|
+
var { randomBytes, createHash: createHash11 } = require("crypto");
|
|
2277
2277
|
var { Duplex, Readable } = require("stream");
|
|
2278
2278
|
var { URL: URL2 } = require("url");
|
|
2279
2279
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
@@ -2941,7 +2941,7 @@ var require_websocket = __commonJS({
|
|
|
2941
2941
|
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
2942
2942
|
return;
|
|
2943
2943
|
}
|
|
2944
|
-
const digest =
|
|
2944
|
+
const digest = createHash11("sha1").update(key + GUID).digest("base64");
|
|
2945
2945
|
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
2946
2946
|
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
2947
2947
|
return;
|
|
@@ -3160,9 +3160,9 @@ var require_websocket = __commonJS({
|
|
|
3160
3160
|
}
|
|
3161
3161
|
});
|
|
3162
3162
|
|
|
3163
|
-
//
|
|
3163
|
+
// node_modules/ws/lib/stream.js
|
|
3164
3164
|
var require_stream = __commonJS({
|
|
3165
|
-
"
|
|
3165
|
+
"node_modules/ws/lib/stream.js"(exports2, module2) {
|
|
3166
3166
|
"use strict";
|
|
3167
3167
|
var WebSocket2 = require_websocket();
|
|
3168
3168
|
var { Duplex } = require("stream");
|
|
@@ -3258,9 +3258,9 @@ var require_stream = __commonJS({
|
|
|
3258
3258
|
}
|
|
3259
3259
|
});
|
|
3260
3260
|
|
|
3261
|
-
//
|
|
3261
|
+
// node_modules/ws/lib/subprotocol.js
|
|
3262
3262
|
var require_subprotocol = __commonJS({
|
|
3263
|
-
"
|
|
3263
|
+
"node_modules/ws/lib/subprotocol.js"(exports2, module2) {
|
|
3264
3264
|
"use strict";
|
|
3265
3265
|
var { tokenChars } = require_validation();
|
|
3266
3266
|
function parse2(header) {
|
|
@@ -3303,14 +3303,14 @@ var require_subprotocol = __commonJS({
|
|
|
3303
3303
|
}
|
|
3304
3304
|
});
|
|
3305
3305
|
|
|
3306
|
-
//
|
|
3306
|
+
// node_modules/ws/lib/websocket-server.js
|
|
3307
3307
|
var require_websocket_server = __commonJS({
|
|
3308
|
-
"
|
|
3308
|
+
"node_modules/ws/lib/websocket-server.js"(exports2, module2) {
|
|
3309
3309
|
"use strict";
|
|
3310
3310
|
var EventEmitter = require("events");
|
|
3311
3311
|
var http = require("http");
|
|
3312
3312
|
var { Duplex } = require("stream");
|
|
3313
|
-
var { createHash:
|
|
3313
|
+
var { createHash: createHash11 } = require("crypto");
|
|
3314
3314
|
var extension2 = require_extension();
|
|
3315
3315
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
3316
3316
|
var subprotocol2 = require_subprotocol();
|
|
@@ -3617,7 +3617,7 @@ var require_websocket_server = __commonJS({
|
|
|
3617
3617
|
);
|
|
3618
3618
|
}
|
|
3619
3619
|
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
3620
|
-
const digest =
|
|
3620
|
+
const digest = createHash11("sha1").update(key + GUID).digest("base64");
|
|
3621
3621
|
const headers = [
|
|
3622
3622
|
"HTTP/1.1 101 Switching Protocols",
|
|
3623
3623
|
"Upgrade: websocket",
|
|
@@ -3705,9 +3705,9 @@ var require_websocket_server = __commonJS({
|
|
|
3705
3705
|
});
|
|
3706
3706
|
|
|
3707
3707
|
// src/main/workspace-connect.ts
|
|
3708
|
-
var
|
|
3708
|
+
var import_fs18 = require("fs");
|
|
3709
3709
|
var import_os7 = require("os");
|
|
3710
|
-
var
|
|
3710
|
+
var import_path24 = require("path");
|
|
3711
3711
|
var import_url2 = require("url");
|
|
3712
3712
|
|
|
3713
3713
|
// src/application/services/workspaceSandbox/importers.ts
|
|
@@ -4269,8 +4269,8 @@ async function writeScrubbedTranscript(source, target) {
|
|
|
4269
4269
|
// src/application/services/workspaceSandbox/backgroundService.ts
|
|
4270
4270
|
var import_child_process2 = require("child_process");
|
|
4271
4271
|
var import_crypto4 = require("crypto");
|
|
4272
|
-
var
|
|
4273
|
-
var
|
|
4272
|
+
var import_fs6 = require("fs");
|
|
4273
|
+
var import_path7 = require("path");
|
|
4274
4274
|
|
|
4275
4275
|
// src/application/services/workspaceSandbox/HttpSessionTransport.ts
|
|
4276
4276
|
var import_crypto2 = require("crypto");
|
|
@@ -5134,6 +5134,14 @@ function parseProtections(raw) {
|
|
|
5134
5134
|
toolApproval: r["tool-approval"] === "require"
|
|
5135
5135
|
};
|
|
5136
5136
|
}
|
|
5137
|
+
var PROTECTION_REASON_RULE = {
|
|
5138
|
+
PROTECTION_SECRET_FILE: "secret-files",
|
|
5139
|
+
PROTECTION_DESTRUCTIVE_COMMAND: "destructive-commands",
|
|
5140
|
+
PROTECTION_DEPLOY: "deploy-approval",
|
|
5141
|
+
PROTECTION_PROTECTED_PUSH: "protected-push",
|
|
5142
|
+
PROTECTION_UNKNOWN_PACKAGE: "unknown-package",
|
|
5143
|
+
PROTECTION_TOOL_APPROVAL: "tool-approval"
|
|
5144
|
+
};
|
|
5137
5145
|
var SECRET_FILE_MESSAGE = "Blocked by your organization's protection: secret files are never sent to the model. Do not try to read this file another way; ask the user for the specific value your task needs, or use the example file (such as .env.example).";
|
|
5138
5146
|
var ENV_TEMPLATES = /* @__PURE__ */ new Set(["example", "sample", "template", "dist"]);
|
|
5139
5147
|
var SECRET_EXTENSIONS = /\.(pem|key|p12|pfx|jks|keystore)$/;
|
|
@@ -5741,6 +5749,27 @@ var TransportError = class extends Error {
|
|
|
5741
5749
|
code;
|
|
5742
5750
|
};
|
|
5743
5751
|
|
|
5752
|
+
// src/application/services/workspaceSandbox/engineVersion.ts
|
|
5753
|
+
var import_fs4 = require("fs");
|
|
5754
|
+
var import_path4 = require("path");
|
|
5755
|
+
var SDK = "@anthropic-ai/claude-agent-sdk";
|
|
5756
|
+
var VERSION = /^\d{1,5}\.\d{1,5}\.\d{1,5}$/;
|
|
5757
|
+
function engineVersion(resolve8 = require.resolve) {
|
|
5758
|
+
try {
|
|
5759
|
+
let dir = (0, import_path4.dirname)(resolve8(SDK));
|
|
5760
|
+
for (let i = 0; i < 4; i++) {
|
|
5761
|
+
const file = (0, import_path4.join)(dir, "package.json");
|
|
5762
|
+
if ((0, import_fs4.existsSync)(file)) {
|
|
5763
|
+
const pkg = JSON.parse((0, import_fs4.readFileSync)(file, "utf8"));
|
|
5764
|
+
if (pkg.name === SDK) return typeof pkg.version === "string" && VERSION.test(pkg.version) ? pkg.version : null;
|
|
5765
|
+
}
|
|
5766
|
+
dir = (0, import_path4.dirname)(dir);
|
|
5767
|
+
}
|
|
5768
|
+
} catch {
|
|
5769
|
+
}
|
|
5770
|
+
return null;
|
|
5771
|
+
}
|
|
5772
|
+
|
|
5744
5773
|
// src/application/services/workspaceSandbox/HttpSessionTransport.ts
|
|
5745
5774
|
var gzipAsync = (0, import_util2.promisify)(import_zlib.gzip);
|
|
5746
5775
|
var gunzipAsync = (0, import_util2.promisify)(import_zlib.gunzip);
|
|
@@ -5757,8 +5786,10 @@ var HttpSessionTransport = class {
|
|
|
5757
5786
|
fetchImpl;
|
|
5758
5787
|
root;
|
|
5759
5788
|
gone;
|
|
5789
|
+
/** The engine's version, said at every start so the API can tell a session still on an older one (engineVersion.ts). */
|
|
5790
|
+
engine = engineVersion();
|
|
5760
5791
|
async bootstrap() {
|
|
5761
|
-
const raw = await this.get(`/bootstrap?features=${(this.opts.features ?? ENGINE_FEATURES).join(",")}`, this.opts.requestTimeoutMs ?? 3e4);
|
|
5792
|
+
const raw = await this.get(`/bootstrap?features=${(this.opts.features ?? ENGINE_FEATURES).join(",")}${this.engine ? `&engine=${this.engine}` : ""}`, this.opts.requestTimeoutMs ?? 3e4);
|
|
5762
5793
|
const parts = checkpointPartsOf(raw?.checkpointParts);
|
|
5763
5794
|
if (parts && typeof raw?.checkpointPatch !== "string") raw.checkpointPatch = await this.checkpointFromParts(parts);
|
|
5764
5795
|
return toSessionBootstrap(raw);
|
|
@@ -5907,6 +5938,17 @@ var HttpSessionTransport = class {
|
|
|
5907
5938
|
if (!raw || typeof raw !== "object" || !("protections" in raw)) throw new TransportError("invalid protections response", 502, false);
|
|
5908
5939
|
return protectionsWireOf(raw.protections);
|
|
5909
5940
|
}
|
|
5941
|
+
/**
|
|
5942
|
+
* What a protection refused, for the API to count (no command, no path, no text). Whatever the answer, nothing is
|
|
5943
|
+
* thrown: a 404 from an API older than this route must never read as "the session is gone".
|
|
5944
|
+
*/
|
|
5945
|
+
async reportProtectionDecisions(decisions) {
|
|
5946
|
+
if (!decisions.length) return;
|
|
5947
|
+
try {
|
|
5948
|
+
await this.post("/protection-decisions", { decisions }, 5e3);
|
|
5949
|
+
} catch {
|
|
5950
|
+
}
|
|
5951
|
+
}
|
|
5910
5952
|
headers(json) {
|
|
5911
5953
|
return {
|
|
5912
5954
|
"x-workspace-session-secret": this.opts.secret,
|
|
@@ -6149,15 +6191,15 @@ function orgMcpCatalogOf(raw) {
|
|
|
6149
6191
|
// src/application/services/workspaceSandbox/localWorkspace.ts
|
|
6150
6192
|
var import_promises6 = require("fs/promises");
|
|
6151
6193
|
var import_os3 = require("os");
|
|
6152
|
-
var
|
|
6194
|
+
var import_path6 = require("path");
|
|
6153
6195
|
|
|
6154
6196
|
// src/application/services/workspaceSandbox/localTracking.ts
|
|
6155
6197
|
var import_crypto3 = require("crypto");
|
|
6156
|
-
var
|
|
6198
|
+
var import_fs5 = require("fs");
|
|
6157
6199
|
var import_promises5 = require("fs/promises");
|
|
6158
6200
|
var import_os2 = require("os");
|
|
6159
|
-
var
|
|
6160
|
-
var posix = (p) => p.split(
|
|
6201
|
+
var import_path5 = require("path");
|
|
6202
|
+
var posix = (p) => p.split(import_path5.sep).join("/");
|
|
6161
6203
|
function underPrefix(path, prefix) {
|
|
6162
6204
|
if (!prefix) return true;
|
|
6163
6205
|
const clean = path.replace(/^\/+/, "");
|
|
@@ -6230,7 +6272,7 @@ async function discoverRepositories(root, limits = {}) {
|
|
|
6230
6272
|
continue;
|
|
6231
6273
|
}
|
|
6232
6274
|
if (!e.isDirectory() || e.name.startsWith(".") || DISCOVERY_SKIP.has(e.name)) continue;
|
|
6233
|
-
children.push((0,
|
|
6275
|
+
children.push((0, import_path5.join)(dir, e.name));
|
|
6234
6276
|
}
|
|
6235
6277
|
} catch {
|
|
6236
6278
|
continue;
|
|
@@ -6271,7 +6313,7 @@ async function repoFingerprint(root) {
|
|
|
6271
6313
|
const r = recs[i];
|
|
6272
6314
|
if (!r || r.length < 4) continue;
|
|
6273
6315
|
n++;
|
|
6274
|
-
const st = await (0, import_promises5.stat)((0,
|
|
6316
|
+
const st = await (0, import_promises5.stat)((0, import_path5.join)(root, r.slice(3))).catch(() => null);
|
|
6275
6317
|
h.update(`\0${st ? `${st.size}:${st.mtimeMs}` : "-"}`);
|
|
6276
6318
|
if (r[0] === "R" || r[0] === "C") i++;
|
|
6277
6319
|
}
|
|
@@ -6292,13 +6334,13 @@ var LooseFileTracker = class {
|
|
|
6292
6334
|
return this.o.root;
|
|
6293
6335
|
}
|
|
6294
6336
|
get gitDir() {
|
|
6295
|
-
return (0,
|
|
6337
|
+
return (0, import_path5.join)(this.o.stateDir, "shadow.git");
|
|
6296
6338
|
}
|
|
6297
6339
|
get baseIndex() {
|
|
6298
|
-
return (0,
|
|
6340
|
+
return (0, import_path5.join)(this.o.stateDir, "base.index");
|
|
6299
6341
|
}
|
|
6300
6342
|
get manifest() {
|
|
6301
|
-
return (0,
|
|
6343
|
+
return (0, import_path5.join)(this.o.stateDir, "manifest.json");
|
|
6302
6344
|
}
|
|
6303
6345
|
get env() {
|
|
6304
6346
|
return { GIT_DIR: this.gitDir, GIT_WORK_TREE: this.o.root };
|
|
@@ -6309,7 +6351,7 @@ var LooseFileTracker = class {
|
|
|
6309
6351
|
}
|
|
6310
6352
|
async init() {
|
|
6311
6353
|
await (0, import_promises5.mkdir)(this.o.stateDir, { recursive: true, mode: 448 });
|
|
6312
|
-
if (!(0,
|
|
6354
|
+
if (!(0, import_fs5.existsSync)((0, import_path5.join)(this.gitDir, "HEAD"))) {
|
|
6313
6355
|
await git(["init", "-q", "--bare", this.gitDir], { cwd: this.o.stateDir });
|
|
6314
6356
|
for (const [k, v] of [
|
|
6315
6357
|
["core.bare", "false"],
|
|
@@ -6334,11 +6376,11 @@ var LooseFileTracker = class {
|
|
|
6334
6376
|
return next;
|
|
6335
6377
|
}
|
|
6336
6378
|
async track(abs) {
|
|
6337
|
-
const rel = (0,
|
|
6338
|
-
if (!rel || rel.startsWith("..") || (0,
|
|
6379
|
+
const rel = (0, import_path5.relative)(this.o.root, abs);
|
|
6380
|
+
if (!rel || rel.startsWith("..") || (0, import_path5.isAbsolute)(rel)) return;
|
|
6339
6381
|
const path = posix(rel);
|
|
6340
6382
|
if (path.split("/").includes(".git") || this.entries.some((e) => e.path === path) || this.skipped.has(path)) return;
|
|
6341
|
-
if (this.o.excluded().some((r) => abs === r || abs.startsWith(r +
|
|
6383
|
+
if (this.o.excluded().some((r) => abs === r || abs.startsWith(r + import_path5.sep))) return;
|
|
6342
6384
|
const st = await (0, import_promises5.lstat)(abs).catch(() => null);
|
|
6343
6385
|
if (st && !st.isFile()) return;
|
|
6344
6386
|
if (st && st.size > (this.o.maxBytes ?? LOOSE_FILE_MAX_BYTES)) {
|
|
@@ -6372,8 +6414,8 @@ var LooseFileTracker = class {
|
|
|
6372
6414
|
scope() {
|
|
6373
6415
|
return {
|
|
6374
6416
|
env: this.env,
|
|
6375
|
-
index: (0,
|
|
6376
|
-
paths: this.entries.filter((e) => e.existed || (0,
|
|
6417
|
+
index: (0, import_fs5.existsSync)(this.baseIndex) ? this.baseIndex : null,
|
|
6418
|
+
paths: this.entries.filter((e) => e.existed || (0, import_fs5.existsSync)((0, import_path5.join)(this.o.root, e.path))).map((e) => e.path)
|
|
6377
6419
|
};
|
|
6378
6420
|
}
|
|
6379
6421
|
entry(path) {
|
|
@@ -6418,7 +6460,7 @@ var LooseFileTracker = class {
|
|
|
6418
6460
|
await this.chain;
|
|
6419
6461
|
const snap = JSON.parse(snapshot);
|
|
6420
6462
|
if (!this.entries.length) return;
|
|
6421
|
-
const idx = (0,
|
|
6463
|
+
const idx = (0, import_path5.join)((0, import_os2.tmpdir)(), `sq-loose-${process.pid}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`);
|
|
6422
6464
|
const env = { ...this.env, GIT_INDEX_FILE: idx };
|
|
6423
6465
|
let target;
|
|
6424
6466
|
try {
|
|
@@ -6455,9 +6497,9 @@ var SESSION_STATE_MAX_AGE_MS = 30 * 24 * 60 * 6e4;
|
|
|
6455
6497
|
async function pruneSessionStates(parent, keep, now = Date.now(), maxAgeMs = SESSION_STATE_MAX_AGE_MS) {
|
|
6456
6498
|
const removed = [];
|
|
6457
6499
|
for (const name of await (0, import_promises5.readdir)(parent).catch(() => [])) {
|
|
6458
|
-
const dir = (0,
|
|
6500
|
+
const dir = (0, import_path5.join)(parent, name);
|
|
6459
6501
|
if (dir === keep) continue;
|
|
6460
|
-
const st = await (0, import_promises5.stat)((0,
|
|
6502
|
+
const st = await (0, import_promises5.stat)((0, import_path5.join)(dir, "manifest.json")).catch(() => null) ?? await (0, import_promises5.stat)(dir).catch(() => null);
|
|
6461
6503
|
if (!st || now - st.mtimeMs < maxAgeMs) continue;
|
|
6462
6504
|
await (0, import_promises5.rm)(dir, { recursive: true, force: true }).catch(() => void 0);
|
|
6463
6505
|
removed.push(name);
|
|
@@ -6481,12 +6523,12 @@ var LocalWorkspaceError = class extends Error {
|
|
|
6481
6523
|
publicMessage;
|
|
6482
6524
|
};
|
|
6483
6525
|
async function localFolderRoot(dir) {
|
|
6484
|
-
const abs = (0,
|
|
6526
|
+
const abs = (0, import_path6.resolve)(dir);
|
|
6485
6527
|
const st = await (0, import_promises6.stat)(abs).catch(() => null);
|
|
6486
6528
|
if (!st || !st.isDirectory()) throw new LocalWorkspaceError("FOLDER_NOT_FOUND", `The folder ${abs} does not exist.`);
|
|
6487
6529
|
return (0, import_promises6.realpath)(abs);
|
|
6488
6530
|
}
|
|
6489
|
-
var posix2 = (p) => p.split(
|
|
6531
|
+
var posix2 = (p) => p.split(import_path6.sep).join("/");
|
|
6490
6532
|
async function enclosingRepository(root) {
|
|
6491
6533
|
let missing = false;
|
|
6492
6534
|
const top = await git(["rev-parse", "--show-toplevel"], { cwd: root }).then((o) => o.trim(), (e) => {
|
|
@@ -6497,14 +6539,14 @@ async function enclosingRepository(root) {
|
|
|
6497
6539
|
if (!top) return null;
|
|
6498
6540
|
const realTop = await (0, import_promises6.realpath)(top).catch(() => top);
|
|
6499
6541
|
if (realTop === root) return { top: realTop, prefix: "" };
|
|
6500
|
-
const prefix = posix2((0,
|
|
6542
|
+
const prefix = posix2((0, import_path6.relative)(realTop, root));
|
|
6501
6543
|
if (!prefix || prefix.startsWith("..")) return null;
|
|
6502
6544
|
const env = { GIT_LITERAL_PATHSPECS: "1" };
|
|
6503
6545
|
const inHead = (await git(["ls-tree", "-d", "--name-only", "HEAD", "--", prefix], { cwd: realTop, env }).catch(() => "")).trim().length > 0;
|
|
6504
6546
|
if (inHead) return { top: realTop, prefix };
|
|
6505
6547
|
const home = await (0, import_promises6.realpath)((0, import_os3.homedir)()).catch(() => (0, import_os3.homedir)());
|
|
6506
|
-
const toHome = (0,
|
|
6507
|
-
if (realTop === home || !(0,
|
|
6548
|
+
const toHome = (0, import_path6.relative)(realTop, home);
|
|
6549
|
+
if (realTop === home || !(0, import_path6.isAbsolute)(toHome) && toHome.split(import_path6.sep)[0] !== "..") return null;
|
|
6508
6550
|
const ignored = await git(["check-ignore", "-q", "--", prefix], { cwd: realTop, env }).then(() => true, () => false);
|
|
6509
6551
|
return ignored ? null : { top: realTop, prefix };
|
|
6510
6552
|
}
|
|
@@ -6526,7 +6568,7 @@ async function nestedRepo(folder, dir) {
|
|
|
6526
6568
|
if (!real) return null;
|
|
6527
6569
|
const top = (await git(["rev-parse", "--show-toplevel"], { cwd: real }).catch(() => "")).trim();
|
|
6528
6570
|
if (!top || await (0, import_promises6.realpath)(top).catch(() => top) !== real) return null;
|
|
6529
|
-
return { root: real, rel: posix2((0,
|
|
6571
|
+
return { root: real, rel: posix2((0, import_path6.relative)(folder, real)), ...await repoHead(real) };
|
|
6530
6572
|
}
|
|
6531
6573
|
async function inspectLocalFolder(dir, opts = {}) {
|
|
6532
6574
|
const root = await localFolderRoot(dir);
|
|
@@ -7424,30 +7466,30 @@ function serviceNames(api) {
|
|
|
7424
7466
|
};
|
|
7425
7467
|
}
|
|
7426
7468
|
function sqHome(home) {
|
|
7427
|
-
return (0,
|
|
7469
|
+
return (0, import_path7.join)(home, ".scalequality");
|
|
7428
7470
|
}
|
|
7429
7471
|
function logDir(env) {
|
|
7430
|
-
if (env.platform === "darwin") return (0,
|
|
7431
|
-
if (env.platform === "win32") return (0,
|
|
7432
|
-
return (0,
|
|
7472
|
+
if (env.platform === "darwin") return (0, import_path7.join)(env.home, "Library", "Logs", "ScaleQuality");
|
|
7473
|
+
if (env.platform === "win32") return (0, import_path7.join)(env.env.LOCALAPPDATA || (0, import_path7.join)(env.home, "AppData", "Local"), "ScaleQuality", "Logs");
|
|
7474
|
+
return (0, import_path7.join)(env.env.XDG_STATE_HOME || (0, import_path7.join)(env.home, ".local", "state"), "scalequality", "logs");
|
|
7433
7475
|
}
|
|
7434
7476
|
function serviceLogFile(env, api) {
|
|
7435
|
-
return (0,
|
|
7477
|
+
return (0, import_path7.join)(logDir(env), `${serviceNames(api).file}.log`);
|
|
7436
7478
|
}
|
|
7437
7479
|
function lockFile(home, api) {
|
|
7438
|
-
return (0,
|
|
7480
|
+
return (0, import_path7.join)(sqHome(home), "run", `${serviceNames(api).file}.pid`);
|
|
7439
7481
|
}
|
|
7440
7482
|
function launchAgentPath(env, api) {
|
|
7441
|
-
return (0,
|
|
7483
|
+
return (0, import_path7.join)(env.home, "Library", "LaunchAgents", `${serviceNames(api).label}.plist`);
|
|
7442
7484
|
}
|
|
7443
7485
|
function systemdUnitPath(env, api) {
|
|
7444
|
-
return (0,
|
|
7486
|
+
return (0, import_path7.join)(env.env.XDG_CONFIG_HOME || (0, import_path7.join)(env.home, ".config"), "systemd", "user", serviceNames(api).unit);
|
|
7445
7487
|
}
|
|
7446
7488
|
function windowsLauncherPath(env, api) {
|
|
7447
|
-
return (0,
|
|
7489
|
+
return (0, import_path7.join)(env.env.LOCALAPPDATA || (0, import_path7.join)(env.home, "AppData", "Local"), "ScaleQuality", `${serviceNames(api).file}.vbs`);
|
|
7448
7490
|
}
|
|
7449
7491
|
function windowsStartupPath(env, api) {
|
|
7450
|
-
return (0,
|
|
7492
|
+
return (0, import_path7.join)(env.env.APPDATA || (0, import_path7.join)(env.home, "AppData", "Roaming"), "Microsoft", "Windows", "Start Menu", "Programs", "Startup", `${serviceNames(api).file}.vbs`);
|
|
7451
7493
|
}
|
|
7452
7494
|
var ServiceError = class extends Error {
|
|
7453
7495
|
constructor(code, message) {
|
|
@@ -7460,49 +7502,49 @@ var ServiceError = class extends Error {
|
|
|
7460
7502
|
var MARKER = ".scalequality-install.json";
|
|
7461
7503
|
function readJson(file) {
|
|
7462
7504
|
try {
|
|
7463
|
-
return JSON.parse((0,
|
|
7505
|
+
return JSON.parse((0, import_fs6.readFileSync)(file, "utf8"));
|
|
7464
7506
|
} catch {
|
|
7465
7507
|
return null;
|
|
7466
7508
|
}
|
|
7467
7509
|
}
|
|
7468
7510
|
function inside2(parent, child) {
|
|
7469
|
-
const rel = (0,
|
|
7470
|
-
return rel === "" || !!rel && !rel.startsWith("..") && !(0,
|
|
7511
|
+
const rel = (0, import_path7.relative)(parent, child);
|
|
7512
|
+
return rel === "" || !!rel && !rel.startsWith("..") && !(0, import_path7.isAbsolute)(rel);
|
|
7471
7513
|
}
|
|
7472
7514
|
function findPackageDir(fromDir, name) {
|
|
7473
7515
|
let dir = fromDir;
|
|
7474
7516
|
for (; ; ) {
|
|
7475
|
-
const candidate = (0,
|
|
7476
|
-
if ((0,
|
|
7477
|
-
const parent = (0,
|
|
7517
|
+
const candidate = (0, import_path7.join)(dir, "node_modules", ...name.split("/"));
|
|
7518
|
+
if ((0, import_fs6.existsSync)((0, import_path7.join)(candidate, "package.json"))) return candidate;
|
|
7519
|
+
const parent = (0, import_path7.dirname)(dir);
|
|
7478
7520
|
if (parent === dir) return null;
|
|
7479
7521
|
dir = parent;
|
|
7480
7522
|
}
|
|
7481
7523
|
}
|
|
7482
7524
|
function installRoot(dir) {
|
|
7483
|
-
const parts = dir.split(
|
|
7525
|
+
const parts = dir.split(import_path7.sep);
|
|
7484
7526
|
const i = parts.indexOf("node_modules");
|
|
7485
|
-
return i > 0 ? parts.slice(0, i).join(
|
|
7527
|
+
return i > 0 ? parts.slice(0, i).join(import_path7.sep) || import_path7.sep : null;
|
|
7486
7528
|
}
|
|
7487
7529
|
function placeFile(src, dst) {
|
|
7488
7530
|
try {
|
|
7489
|
-
(0,
|
|
7531
|
+
(0, import_fs6.linkSync)(src, dst);
|
|
7490
7532
|
return;
|
|
7491
7533
|
} catch {
|
|
7492
7534
|
}
|
|
7493
|
-
(0,
|
|
7535
|
+
(0, import_fs6.copyFileSync)(src, dst);
|
|
7494
7536
|
try {
|
|
7495
|
-
(0,
|
|
7537
|
+
(0, import_fs6.chmodSync)(dst, (0, import_fs6.statSync)(src).mode & 511);
|
|
7496
7538
|
} catch {
|
|
7497
7539
|
}
|
|
7498
7540
|
}
|
|
7499
7541
|
function copyPackageDir(src, dst) {
|
|
7500
|
-
(0,
|
|
7501
|
-
for (const entry of (0,
|
|
7542
|
+
(0, import_fs6.mkdirSync)(dst, { recursive: true });
|
|
7543
|
+
for (const entry of (0, import_fs6.readdirSync)(src)) {
|
|
7502
7544
|
if (entry === "node_modules") continue;
|
|
7503
|
-
const from = (0,
|
|
7504
|
-
const to = (0,
|
|
7505
|
-
const st = (0,
|
|
7545
|
+
const from = (0, import_path7.join)(src, entry);
|
|
7546
|
+
const to = (0, import_path7.join)(dst, entry);
|
|
7547
|
+
const st = (0, import_fs6.statSync)(from, { throwIfNoEntry: false });
|
|
7506
7548
|
if (!st) continue;
|
|
7507
7549
|
if (st.isDirectory()) copyPackageDir(from, to);
|
|
7508
7550
|
else if (st.isFile()) placeFile(from, to);
|
|
@@ -7510,12 +7552,12 @@ function copyPackageDir(src, dst) {
|
|
|
7510
7552
|
}
|
|
7511
7553
|
function copyPackageClosure(packageRoot, target) {
|
|
7512
7554
|
const root = installRoot(packageRoot);
|
|
7513
|
-
const pkgName = readJson((0,
|
|
7514
|
-
const destPkg = (0,
|
|
7555
|
+
const pkgName = readJson((0, import_path7.join)(packageRoot, "package.json"))?.name;
|
|
7556
|
+
const destPkg = (0, import_path7.join)(target, "node_modules", ...pkgName.split("/"));
|
|
7515
7557
|
const destFor = (dir, name) => {
|
|
7516
|
-
if (inside2(packageRoot, dir)) return (0,
|
|
7517
|
-
if (root && inside2(root, dir)) return (0,
|
|
7518
|
-
return (0,
|
|
7558
|
+
if (inside2(packageRoot, dir)) return (0, import_path7.join)(destPkg, (0, import_path7.relative)(packageRoot, dir));
|
|
7559
|
+
if (root && inside2(root, dir)) return (0, import_path7.join)(target, (0, import_path7.relative)(root, dir));
|
|
7560
|
+
return (0, import_path7.join)(target, "node_modules", ...name.split("/"));
|
|
7519
7561
|
};
|
|
7520
7562
|
const seen = /* @__PURE__ */ new Set();
|
|
7521
7563
|
const queue = [{ dir: packageRoot, name: pkgName, required: true }];
|
|
@@ -7526,7 +7568,7 @@ function copyPackageClosure(packageRoot, target) {
|
|
|
7526
7568
|
seen.add(dir);
|
|
7527
7569
|
copyPackageDir(dir, destFor(dir, name));
|
|
7528
7570
|
copied++;
|
|
7529
|
-
const pkg = readJson((0,
|
|
7571
|
+
const pkg = readJson((0, import_path7.join)(dir, "package.json")) ?? {};
|
|
7530
7572
|
const deps = [
|
|
7531
7573
|
...Object.keys(pkg.dependencies ?? {}).map((d) => [d, true]),
|
|
7532
7574
|
...Object.keys(pkg.optionalDependencies ?? {}).map((d) => [d, false]),
|
|
@@ -7544,45 +7586,45 @@ function copyPackageClosure(packageRoot, target) {
|
|
|
7544
7586
|
return copied;
|
|
7545
7587
|
}
|
|
7546
7588
|
function installStableCopy(o) {
|
|
7547
|
-
const pkg = readJson((0,
|
|
7589
|
+
const pkg = readJson((0, import_path7.join)(o.packageRoot, "package.json"));
|
|
7548
7590
|
if (!pkg || pkg.name !== "@scalequality/cli" || typeof pkg.version !== "string" || !/^[0-9A-Za-z.+-]{1,40}$/.test(pkg.version)) {
|
|
7549
7591
|
throw new ServiceError("NOT_AN_INSTALLED_CLI", "This is not an installed @scalequality/cli package, so it cannot be copied for the background service.");
|
|
7550
7592
|
}
|
|
7551
|
-
const bundle = (0,
|
|
7552
|
-
const bin = (dir2) => (0,
|
|
7553
|
-
if (!(0,
|
|
7554
|
-
const sha = (0, import_crypto4.createHash)("sha256").update((0,
|
|
7555
|
-
const base = (0,
|
|
7556
|
-
const dir = (0,
|
|
7593
|
+
const bundle = (0, import_path7.join)(o.packageRoot, "dist", "connect.cjs");
|
|
7594
|
+
const bin = (dir2) => (0, import_path7.join)(dir2, "node_modules", "@scalequality", "cli", "bin", "scalequality.mjs");
|
|
7595
|
+
if (!(0, import_fs6.existsSync)(bundle)) throw new ServiceError("NOT_AN_INSTALLED_CLI", "This installation of @scalequality/cli is incomplete (dist/connect.cjs is missing).");
|
|
7596
|
+
const sha = (0, import_crypto4.createHash)("sha256").update((0, import_fs6.readFileSync)(bundle)).digest("hex");
|
|
7597
|
+
const base = (0, import_path7.join)(sqHome(o.home), "cli");
|
|
7598
|
+
const dir = (0, import_path7.join)(base, pkg.version);
|
|
7557
7599
|
if (inside2(dir, o.packageRoot)) return { dir, bin: bin(dir), version: pkg.version, reused: true };
|
|
7558
|
-
const marker = readJson((0,
|
|
7559
|
-
if (marker?.version === pkg.version && marker?.bundleSha256 === sha && (0,
|
|
7560
|
-
(0,
|
|
7561
|
-
const partial = (0,
|
|
7562
|
-
(0,
|
|
7600
|
+
const marker = readJson((0, import_path7.join)(dir, MARKER));
|
|
7601
|
+
if (marker?.version === pkg.version && marker?.bundleSha256 === sha && (0, import_fs6.existsSync)(bin(dir))) return { dir, bin: bin(dir), version: pkg.version, reused: true };
|
|
7602
|
+
(0, import_fs6.mkdirSync)(base, { recursive: true, mode: 448 });
|
|
7603
|
+
const partial = (0, import_path7.join)(base, `.${pkg.version}.${process.pid}.partial`);
|
|
7604
|
+
(0, import_fs6.rmSync)(partial, { recursive: true, force: true });
|
|
7563
7605
|
try {
|
|
7564
7606
|
copyPackageClosure(o.packageRoot, partial);
|
|
7565
|
-
(0,
|
|
7607
|
+
(0, import_fs6.writeFileSync)((0, import_path7.join)(partial, MARKER), `${JSON.stringify({ version: pkg.version, bundleSha256: sha, installedAt: (/* @__PURE__ */ new Date()).toISOString() }, null, 2)}
|
|
7566
7608
|
`);
|
|
7567
|
-
const old = (0,
|
|
7568
|
-
if (old) (0,
|
|
7569
|
-
(0,
|
|
7570
|
-
if (old) (0,
|
|
7609
|
+
const old = (0, import_fs6.existsSync)(dir) ? (0, import_path7.join)(base, `.${pkg.version}.${process.pid}.old`) : null;
|
|
7610
|
+
if (old) (0, import_fs6.renameSync)(dir, old);
|
|
7611
|
+
(0, import_fs6.renameSync)(partial, dir);
|
|
7612
|
+
if (old) (0, import_fs6.rmSync)(old, { recursive: true, force: true });
|
|
7571
7613
|
} catch (e) {
|
|
7572
|
-
(0,
|
|
7614
|
+
(0, import_fs6.rmSync)(partial, { recursive: true, force: true });
|
|
7573
7615
|
throw e instanceof ServiceError ? e : new ServiceError("COPY_FAILED", `The CLI could not be copied to ${dir}: ${e.message}`);
|
|
7574
7616
|
}
|
|
7575
7617
|
return { dir, bin: bin(dir), version: pkg.version, reused: false };
|
|
7576
7618
|
}
|
|
7577
7619
|
function removeStableCopies(home, keep = null) {
|
|
7578
|
-
const base = (0,
|
|
7620
|
+
const base = (0, import_path7.join)(sqHome(home), "cli");
|
|
7579
7621
|
const kept = new Set(keep === null ? [] : typeof keep === "string" ? [keep] : keep);
|
|
7580
7622
|
const removed = [];
|
|
7581
|
-
for (const name of (0,
|
|
7623
|
+
for (const name of (0, import_fs6.existsSync)(base) ? (0, import_fs6.readdirSync)(base) : []) {
|
|
7582
7624
|
if (kept.has(name) || !/^\.?[0-9A-Za-z.+-]{1,60}$/.test(name)) continue;
|
|
7583
|
-
const full = (0,
|
|
7584
|
-
if (!(0,
|
|
7585
|
-
(0,
|
|
7625
|
+
const full = (0, import_path7.join)(base, name);
|
|
7626
|
+
if (!(0, import_fs6.lstatSync)(full).isDirectory()) continue;
|
|
7627
|
+
(0, import_fs6.rmSync)(full, { recursive: true, force: true });
|
|
7586
7628
|
removed.push(name);
|
|
7587
7629
|
}
|
|
7588
7630
|
return removed;
|
|
@@ -7627,9 +7669,9 @@ ${args}
|
|
|
7627
7669
|
<string>1</string>
|
|
7628
7670
|
</dict>
|
|
7629
7671
|
<key>StandardOutPath</key>
|
|
7630
|
-
<string>${xml((0,
|
|
7672
|
+
<string>${xml((0, import_path7.join)(logs, `${names.file}.launchd.log`))}</string>
|
|
7631
7673
|
<key>StandardErrorPath</key>
|
|
7632
|
-
<string>${xml((0,
|
|
7674
|
+
<string>${xml((0, import_path7.join)(logs, `${names.file}.launchd.log`))}</string>
|
|
7633
7675
|
</dict>
|
|
7634
7676
|
</plist>
|
|
7635
7677
|
`;
|
|
@@ -7662,10 +7704,10 @@ shell.Run "${commandLine}", 0, False\r
|
|
|
7662
7704
|
`;
|
|
7663
7705
|
}
|
|
7664
7706
|
function writeFileSafely(file, content, mode = 420) {
|
|
7665
|
-
(0,
|
|
7707
|
+
(0, import_fs6.mkdirSync)((0, import_path7.dirname)(file), { recursive: true });
|
|
7666
7708
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
7667
|
-
(0,
|
|
7668
|
-
(0,
|
|
7709
|
+
(0, import_fs6.writeFileSync)(tmp, content, { mode });
|
|
7710
|
+
(0, import_fs6.renameSync)(tmp, file);
|
|
7669
7711
|
}
|
|
7670
7712
|
var failed = (r) => `${r.stderr || r.stdout}`.trim().split("\n").slice(-1)[0]?.slice(0, 200) || `exit ${r.code}`;
|
|
7671
7713
|
var LAUNCHD_REPLACE_WAIT_MS = 3e4;
|
|
@@ -7674,7 +7716,7 @@ var LAUNCHD_BOOTSTRAP_ATTEMPTS = 6;
|
|
|
7674
7716
|
async function installLaunchd(env, bin, api) {
|
|
7675
7717
|
const names = serviceNames(api);
|
|
7676
7718
|
const plist = launchAgentPath(env, api);
|
|
7677
|
-
(0,
|
|
7719
|
+
(0, import_fs6.mkdirSync)(logDir(env), { recursive: true });
|
|
7678
7720
|
writeFileSafely(plist, launchAgentPlist(env, bin, api));
|
|
7679
7721
|
const domain = `gui/${env.uid}`;
|
|
7680
7722
|
const sleep2 = env.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
@@ -7691,7 +7733,7 @@ async function installLaunchd(env, bin, api) {
|
|
|
7691
7733
|
if (boot.code === 0) return { ok: true, manager: "launchd", hints: [] };
|
|
7692
7734
|
const legacy = await env.run("launchctl", ["load", "-w", plist]);
|
|
7693
7735
|
if (legacy.code === 0 && await loaded()) return { ok: true, manager: "launchd", hints: [] };
|
|
7694
|
-
(0,
|
|
7736
|
+
(0, import_fs6.rmSync)(plist, { force: true });
|
|
7695
7737
|
return { ok: false, code: "LAUNCHD_REFUSED", message: `macOS did not accept the background service (${failed(boot)}). A device management profile may block login items.` };
|
|
7696
7738
|
}
|
|
7697
7739
|
async function installSystemd(env, bin, api) {
|
|
@@ -7707,7 +7749,7 @@ async function installSystemd(env, bin, api) {
|
|
|
7707
7749
|
const r = await env.run("systemctl", args);
|
|
7708
7750
|
if (r.code !== 0) {
|
|
7709
7751
|
await env.run("systemctl", ["--user", "disable", names.unit]);
|
|
7710
|
-
(0,
|
|
7752
|
+
(0, import_fs6.rmSync)(unit, { force: true });
|
|
7711
7753
|
await env.run("systemctl", ["--user", "daemon-reload"]);
|
|
7712
7754
|
return { ok: false, code: "SYSTEMD_REFUSED", message: `systemd did not start the background service (${failed(r)}).` };
|
|
7713
7755
|
}
|
|
@@ -7722,19 +7764,19 @@ async function installSystemd(env, bin, api) {
|
|
|
7722
7764
|
async function installWindows(env, bin, api) {
|
|
7723
7765
|
const names = serviceNames(api);
|
|
7724
7766
|
const launcher = windowsLauncherPath(env, api);
|
|
7725
|
-
(0,
|
|
7767
|
+
(0, import_fs6.mkdirSync)(logDir(env), { recursive: true });
|
|
7726
7768
|
writeFileSafely(launcher, windowsLauncher(env, bin, api));
|
|
7727
7769
|
const startup = windowsStartupPath(env, api);
|
|
7728
7770
|
let manager;
|
|
7729
7771
|
const created = await env.run("schtasks", ["/Create", "/F", "/TN", names.task, "/SC", "ONLOGON", "/RL", "LIMITED", "/TR", `wscript.exe "${launcher}"`]);
|
|
7730
7772
|
if (created.code === 0) {
|
|
7731
7773
|
manager = "schtasks";
|
|
7732
|
-
(0,
|
|
7774
|
+
(0, import_fs6.rmSync)(startup, { force: true });
|
|
7733
7775
|
} else {
|
|
7734
7776
|
try {
|
|
7735
7777
|
writeFileSafely(startup, windowsLauncher(env, bin, api));
|
|
7736
7778
|
} catch (e) {
|
|
7737
|
-
(0,
|
|
7779
|
+
(0, import_fs6.rmSync)(launcher, { force: true });
|
|
7738
7780
|
return { ok: false, code: "STARTUP_REFUSED", message: `Windows did not accept the background service (${failed(created)}; ${e.message}).` };
|
|
7739
7781
|
}
|
|
7740
7782
|
manager = "startup-folder";
|
|
@@ -7772,7 +7814,7 @@ function lockHolder(home, api) {
|
|
|
7772
7814
|
}
|
|
7773
7815
|
function takeLock(home, api, mode, pid = process.pid) {
|
|
7774
7816
|
const file = lockFile(home, api);
|
|
7775
|
-
(0,
|
|
7817
|
+
(0, import_fs6.mkdirSync)((0, import_path7.dirname)(file), { recursive: true, mode: 448 });
|
|
7776
7818
|
const holder = lockHolder(home, api);
|
|
7777
7819
|
if (holder && holder.pid !== pid) return false;
|
|
7778
7820
|
writeFileSafely(file, JSON.stringify({ pid, mode, at: (/* @__PURE__ */ new Date()).toISOString() }), 384);
|
|
@@ -7780,7 +7822,7 @@ function takeLock(home, api, mode, pid = process.pid) {
|
|
|
7780
7822
|
}
|
|
7781
7823
|
function releaseLock(home, api, pid = process.pid) {
|
|
7782
7824
|
const raw = readJson(lockFile(home, api));
|
|
7783
|
-
if (Number(raw?.pid) === pid) (0,
|
|
7825
|
+
if (Number(raw?.pid) === pid) (0, import_fs6.rmSync)(lockFile(home, api), { force: true });
|
|
7784
7826
|
}
|
|
7785
7827
|
function binFromDefinition(text3) {
|
|
7786
7828
|
if (!text3) return null;
|
|
@@ -7794,7 +7836,7 @@ async function serviceStatus(env, api) {
|
|
|
7794
7836
|
const servicePid = holder?.mode === "service" ? holder.pid : null;
|
|
7795
7837
|
if (env.platform === "darwin") {
|
|
7796
7838
|
const file = launchAgentPath(env, api);
|
|
7797
|
-
const text3 = (0,
|
|
7839
|
+
const text3 = (0, import_fs6.existsSync)(file) ? (0, import_fs6.readFileSync)(file, "utf8") : null;
|
|
7798
7840
|
const printed = env.uid === null ? null : await env.run("launchctl", ["print", `gui/${env.uid}/${names.label}`]);
|
|
7799
7841
|
const pid = printed?.code === 0 ? Number(/\bpid = (\d+)/.exec(printed.stdout)?.[1]) || null : null;
|
|
7800
7842
|
const running = printed?.code === 0 && /\bstate = running\b/.test(printed.stdout);
|
|
@@ -7802,7 +7844,7 @@ async function serviceStatus(env, api) {
|
|
|
7802
7844
|
}
|
|
7803
7845
|
if (env.platform === "linux") {
|
|
7804
7846
|
const file = systemdUnitPath(env, api);
|
|
7805
|
-
const text3 = (0,
|
|
7847
|
+
const text3 = (0, import_fs6.existsSync)(file) ? (0, import_fs6.readFileSync)(file, "utf8") : null;
|
|
7806
7848
|
const active = text3 ? await env.run("systemctl", ["--user", "is-active", names.unit]) : null;
|
|
7807
7849
|
const pidOut = text3 ? await env.run("systemctl", ["--user", "show", names.unit, "--property=MainPID", "--value"]) : null;
|
|
7808
7850
|
const pid = Number(pidOut?.stdout.trim()) || null;
|
|
@@ -7818,9 +7860,9 @@ async function serviceStatus(env, api) {
|
|
|
7818
7860
|
}
|
|
7819
7861
|
if (env.platform === "win32") {
|
|
7820
7862
|
const launcher = windowsLauncherPath(env, api);
|
|
7821
|
-
const text3 = (0,
|
|
7863
|
+
const text3 = (0, import_fs6.existsSync)(launcher) ? (0, import_fs6.readFileSync)(launcher, "utf8") : null;
|
|
7822
7864
|
const task = await env.run("schtasks", ["/Query", "/TN", names.task]);
|
|
7823
|
-
const manager = task.code === 0 ? "schtasks" : (0,
|
|
7865
|
+
const manager = task.code === 0 ? "schtasks" : (0, import_fs6.existsSync)(windowsStartupPath(env, api)) ? "startup-folder" : null;
|
|
7824
7866
|
return { ...base, installed: !!manager && !!text3, running: !!servicePid, pid: servicePid, manager, definition: text3 ? launcher : null, bin: binFromDefinition(text3?.replace(/""/g, '"') ?? null) };
|
|
7825
7867
|
}
|
|
7826
7868
|
return { ...base, installed: false, running: false, pid: null, manager: null, definition: null, bin: null };
|
|
@@ -7832,17 +7874,17 @@ async function uninstallService(env, api, o = {}) {
|
|
|
7832
7874
|
const file = launchAgentPath(env, api);
|
|
7833
7875
|
if (!o.self && env.uid !== null) {
|
|
7834
7876
|
const out2 = await env.run("launchctl", ["bootout", `gui/${env.uid}/${names.label}`]);
|
|
7835
|
-
if (out2.code !== 0 && (0,
|
|
7877
|
+
if (out2.code !== 0 && (0, import_fs6.existsSync)(file)) await env.run("launchctl", ["unload", "-w", file]);
|
|
7836
7878
|
}
|
|
7837
|
-
if ((0,
|
|
7838
|
-
(0,
|
|
7879
|
+
if ((0, import_fs6.existsSync)(file)) {
|
|
7880
|
+
(0, import_fs6.rmSync)(file, { force: true });
|
|
7839
7881
|
removed = true;
|
|
7840
7882
|
}
|
|
7841
7883
|
} else if (env.platform === "linux") {
|
|
7842
7884
|
const file = systemdUnitPath(env, api);
|
|
7843
|
-
if ((0,
|
|
7885
|
+
if ((0, import_fs6.existsSync)(file)) {
|
|
7844
7886
|
await env.run("systemctl", o.self ? ["--user", "disable", names.unit] : ["--user", "disable", "--now", names.unit]);
|
|
7845
|
-
(0,
|
|
7887
|
+
(0, import_fs6.rmSync)(file, { force: true });
|
|
7846
7888
|
await env.run("systemctl", ["--user", "daemon-reload"]);
|
|
7847
7889
|
removed = true;
|
|
7848
7890
|
}
|
|
@@ -7850,8 +7892,8 @@ async function uninstallService(env, api, o = {}) {
|
|
|
7850
7892
|
const task = await env.run("schtasks", ["/Delete", "/F", "/TN", names.task]);
|
|
7851
7893
|
if (task.code === 0) removed = true;
|
|
7852
7894
|
for (const file of [windowsStartupPath(env, api), windowsLauncherPath(env, api)]) {
|
|
7853
|
-
if ((0,
|
|
7854
|
-
(0,
|
|
7895
|
+
if ((0, import_fs6.existsSync)(file)) {
|
|
7896
|
+
(0, import_fs6.rmSync)(file, { force: true });
|
|
7855
7897
|
removed = true;
|
|
7856
7898
|
}
|
|
7857
7899
|
}
|
|
@@ -7866,60 +7908,60 @@ async function uninstallService(env, api, o = {}) {
|
|
|
7866
7908
|
return { removed };
|
|
7867
7909
|
}
|
|
7868
7910
|
function anyServiceDefinition(env) {
|
|
7869
|
-
const dirs = env.platform === "darwin" ? [[(0,
|
|
7870
|
-
return dirs.some(([dir, re]) => (0,
|
|
7911
|
+
const dirs = env.platform === "darwin" ? [[(0, import_path7.join)(env.home, "Library", "LaunchAgents"), /^io\.scalequality\.cli(\..+)?\.plist$/]] : env.platform === "linux" ? [[(0, import_path7.join)(env.env.XDG_CONFIG_HOME || (0, import_path7.join)(env.home, ".config"), "systemd", "user"), /^scalequality(-.+)?\.service$/]] : env.platform === "win32" ? [[(0, import_path7.join)(env.env.LOCALAPPDATA || (0, import_path7.join)(env.home, "AppData", "Local"), "ScaleQuality"), /^scalequality(-.+)?\.vbs$/]] : [];
|
|
7912
|
+
return dirs.some(([dir, re]) => (0, import_fs6.existsSync)(dir) && (0, import_fs6.readdirSync)(dir).some((f) => re.test(f)));
|
|
7871
7913
|
}
|
|
7872
7914
|
var MAX_LOG_BYTES = 5 * 1024 * 1024;
|
|
7873
7915
|
var LogFile = class {
|
|
7874
7916
|
constructor(file) {
|
|
7875
7917
|
this.file = file;
|
|
7876
|
-
(0,
|
|
7918
|
+
(0, import_fs6.mkdirSync)((0, import_path7.dirname)(file), { recursive: true, mode: 448 });
|
|
7877
7919
|
}
|
|
7878
7920
|
file;
|
|
7879
7921
|
write(text3) {
|
|
7880
7922
|
try {
|
|
7881
|
-
const size2 = (0,
|
|
7923
|
+
const size2 = (0, import_fs6.statSync)(this.file, { throwIfNoEntry: false })?.size ?? 0;
|
|
7882
7924
|
if (size2 > MAX_LOG_BYTES) {
|
|
7883
7925
|
try {
|
|
7884
|
-
(0,
|
|
7926
|
+
(0, import_fs6.unlinkSync)(`${this.file}.1`);
|
|
7885
7927
|
} catch {
|
|
7886
7928
|
}
|
|
7887
|
-
(0,
|
|
7929
|
+
(0, import_fs6.renameSync)(this.file, `${this.file}.1`);
|
|
7888
7930
|
}
|
|
7889
7931
|
const at = (/* @__PURE__ */ new Date()).toISOString();
|
|
7890
7932
|
const stamped = text3.split("\n").map((l) => l ? `${at} ${l}` : l).join("\n");
|
|
7891
|
-
(0,
|
|
7933
|
+
(0, import_fs6.writeFileSync)(this.file, stamped, { flag: "a", mode: 384 });
|
|
7892
7934
|
} catch {
|
|
7893
7935
|
}
|
|
7894
7936
|
}
|
|
7895
7937
|
};
|
|
7896
7938
|
function tailFile(file, lines2) {
|
|
7897
|
-
if (!(0,
|
|
7898
|
-
const size2 = (0,
|
|
7939
|
+
if (!(0, import_fs6.existsSync)(file)) return null;
|
|
7940
|
+
const size2 = (0, import_fs6.statSync)(file).size;
|
|
7899
7941
|
const length = Math.min(size2, 1024 * 1024);
|
|
7900
7942
|
const buf = Buffer.alloc(length);
|
|
7901
|
-
const fd = (0,
|
|
7943
|
+
const fd = (0, import_fs6.openSync)(file, "r");
|
|
7902
7944
|
try {
|
|
7903
|
-
(0,
|
|
7945
|
+
(0, import_fs6.readSync)(fd, buf, 0, length, size2 - length);
|
|
7904
7946
|
} finally {
|
|
7905
|
-
(0,
|
|
7947
|
+
(0, import_fs6.closeSync)(fd);
|
|
7906
7948
|
}
|
|
7907
7949
|
const all = buf.toString("utf8").split("\n");
|
|
7908
7950
|
if (all[all.length - 1] === "") all.pop();
|
|
7909
7951
|
return all.slice(-lines2).join("\n");
|
|
7910
7952
|
}
|
|
7911
7953
|
function packageRootOf(bundleDir) {
|
|
7912
|
-
const root = (0,
|
|
7913
|
-
const pkg = readJson((0,
|
|
7914
|
-
return pkg?.name === "@scalequality/cli" && (0,
|
|
7954
|
+
const root = (0, import_path7.dirname)(bundleDir);
|
|
7955
|
+
const pkg = readJson((0, import_path7.join)(root, "package.json"));
|
|
7956
|
+
return pkg?.name === "@scalequality/cli" && (0, import_path7.basename)(bundleDir) === "dist" ? root : null;
|
|
7915
7957
|
}
|
|
7916
7958
|
|
|
7917
7959
|
// src/application/services/workspaceSandbox/terminalHost.ts
|
|
7918
7960
|
var import_crypto5 = require("crypto");
|
|
7919
|
-
var
|
|
7961
|
+
var import_fs7 = require("fs");
|
|
7920
7962
|
var import_http = require("http");
|
|
7921
7963
|
|
|
7922
|
-
//
|
|
7964
|
+
// node_modules/ws/wrapper.mjs
|
|
7923
7965
|
var import_stream = __toESM(require_stream(), 1);
|
|
7924
7966
|
var import_extension = __toESM(require_extension(), 1);
|
|
7925
7967
|
var import_permessage_deflate = __toESM(require_permessage_deflate(), 1);
|
|
@@ -7953,7 +7995,7 @@ function loadPty() {
|
|
|
7953
7995
|
var tokenHash = (token) => (0, import_crypto5.createHash)("sha256").update(token).digest("hex");
|
|
7954
7996
|
function cloudTerminalUser(passwd = "/etc/passwd") {
|
|
7955
7997
|
try {
|
|
7956
|
-
const line = (0,
|
|
7998
|
+
const line = (0, import_fs7.readFileSync)(passwd, "utf8").split("\n").find((l) => l.startsWith("workspace:"));
|
|
7957
7999
|
const [, , uid, gid, , home, shell] = (line ?? "").split(":");
|
|
7958
8000
|
const u = Number(uid), g = Number(gid);
|
|
7959
8001
|
if (!line || !Number.isInteger(u) || u <= 0 || !Number.isInteger(g) || g <= 0 || !home) return null;
|
|
@@ -8223,13 +8265,13 @@ var TerminalHost = class {
|
|
|
8223
8265
|
};
|
|
8224
8266
|
|
|
8225
8267
|
// src/application/services/workspaceSandbox/machineCli.ts
|
|
8226
|
-
var
|
|
8268
|
+
var import_fs8 = require("fs");
|
|
8227
8269
|
var import_promises8 = require("fs/promises");
|
|
8228
|
-
var
|
|
8270
|
+
var import_path9 = require("path");
|
|
8229
8271
|
|
|
8230
8272
|
// src/application/services/workspaceSandbox/machineFolders.ts
|
|
8231
8273
|
var import_promises7 = require("fs/promises");
|
|
8232
|
-
var
|
|
8274
|
+
var import_path8 = require("path");
|
|
8233
8275
|
var FOLDER_LIST_LIMIT = 300;
|
|
8234
8276
|
var FOLDER_SUGGEST_LIMIT = 200;
|
|
8235
8277
|
var FOLDER_LIST_BUDGET_MS = 4e3;
|
|
@@ -8279,9 +8321,9 @@ function browsable(path, home) {
|
|
|
8279
8321
|
}
|
|
8280
8322
|
function logical(home, real) {
|
|
8281
8323
|
if (home.logical === home.real) return real;
|
|
8282
|
-
const rel = (0,
|
|
8283
|
-
if (rel.startsWith("..") || (0,
|
|
8284
|
-
return rel ? (0,
|
|
8324
|
+
const rel = (0, import_path8.relative)(home.real, real);
|
|
8325
|
+
if (rel.startsWith("..") || (0, import_path8.isAbsolute)(rel)) return real;
|
|
8326
|
+
return rel ? (0, import_path8.join)(home.logical, rel) : home.logical;
|
|
8285
8327
|
}
|
|
8286
8328
|
async function realBrowsable(home, path) {
|
|
8287
8329
|
const found = await (0, import_promises7.realpath)(path).catch(() => null);
|
|
@@ -8322,7 +8364,7 @@ async function resolveBrowsePath(raw, home) {
|
|
|
8322
8364
|
else {
|
|
8323
8365
|
const rest = text3.startsWith("~/") || text3.startsWith("~\\") ? text3.slice(2) : text3;
|
|
8324
8366
|
if (rest.split(/[\\/]+/).some((part) => part === ".." || part === ".")) throw new FolderBrowseError("INVALID_PATH");
|
|
8325
|
-
target = (0,
|
|
8367
|
+
target = (0, import_path8.isAbsolute)(rest) && rest === text3 ? rest : (0, import_path8.resolve)(home.logical, rest);
|
|
8326
8368
|
const problem2 = folderBrowseProblem(target, home.logical);
|
|
8327
8369
|
if (problem2) throw new FolderBrowseError(problem2);
|
|
8328
8370
|
}
|
|
@@ -8337,17 +8379,17 @@ async function resolveBrowsePath(raw, home) {
|
|
|
8337
8379
|
}
|
|
8338
8380
|
async function originRemote(repo2) {
|
|
8339
8381
|
try {
|
|
8340
|
-
const dotGit = (0,
|
|
8382
|
+
const dotGit = (0, import_path8.join)(repo2, ".git");
|
|
8341
8383
|
const st = await (0, import_promises7.lstat)(dotGit);
|
|
8342
8384
|
let gitDir = dotGit;
|
|
8343
8385
|
if (st.isFile()) {
|
|
8344
8386
|
const pointer = /^gitdir:\s*(.+)\s*$/m.exec(await (0, import_promises7.readFile)(dotGit, "utf8"))?.[1];
|
|
8345
8387
|
if (!pointer) return null;
|
|
8346
|
-
gitDir = (0,
|
|
8347
|
-
const common = (await (0, import_promises7.readFile)((0,
|
|
8348
|
-
if (common) gitDir = (0,
|
|
8388
|
+
gitDir = (0, import_path8.resolve)(repo2, pointer.trim());
|
|
8389
|
+
const common = (await (0, import_promises7.readFile)((0, import_path8.join)(gitDir, "commondir"), "utf8").catch(() => "")).trim();
|
|
8390
|
+
if (common) gitDir = (0, import_path8.resolve)(gitDir, common);
|
|
8349
8391
|
} else if (!st.isDirectory()) return null;
|
|
8350
|
-
const config = await (0, import_promises7.readFile)((0,
|
|
8392
|
+
const config = await (0, import_promises7.readFile)((0, import_path8.join)(gitDir, "config"), "utf8");
|
|
8351
8393
|
let inOrigin = false;
|
|
8352
8394
|
for (const line of config.split(/\r?\n/)) {
|
|
8353
8395
|
const section = /^\s*\[\s*([^\]]+?)\s*\]/.exec(line);
|
|
@@ -8365,7 +8407,7 @@ async function originRemote(repo2) {
|
|
|
8365
8407
|
}
|
|
8366
8408
|
}
|
|
8367
8409
|
async function isGitRepo(dir) {
|
|
8368
|
-
const st = await (0, import_promises7.lstat)((0,
|
|
8410
|
+
const st = await (0, import_promises7.lstat)((0, import_path8.join)(dir, ".git")).catch(() => null);
|
|
8369
8411
|
return !!st && (st.isDirectory() || st.isFile());
|
|
8370
8412
|
}
|
|
8371
8413
|
async function hasVisibleChild(dir) {
|
|
@@ -8442,7 +8484,7 @@ async function listFolders(homePath, rawPath, opts = {}) {
|
|
|
8442
8484
|
const found = [];
|
|
8443
8485
|
const seen = /* @__PURE__ */ new Set();
|
|
8444
8486
|
truncated = !await eachUntil(names, deadline, async ({ name, link }) => {
|
|
8445
|
-
let target = (0,
|
|
8487
|
+
let target = (0, import_path8.join)(real, name);
|
|
8446
8488
|
if (link) {
|
|
8447
8489
|
const st = await (0, import_promises7.stat)(target).catch(() => null);
|
|
8448
8490
|
if (!st?.isDirectory()) return;
|
|
@@ -8463,12 +8505,12 @@ async function listFolders(homePath, rawPath, opts = {}) {
|
|
|
8463
8505
|
entries[i] = { name: f.name, path: logical(home, f.real), isGitRepo: f.isGitRepo, remoteUrl, hasChildren };
|
|
8464
8506
|
}) || truncated;
|
|
8465
8507
|
const path = logical(home, real);
|
|
8466
|
-
const rel = (0,
|
|
8467
|
-
const parentReal = (0,
|
|
8508
|
+
const rel = (0, import_path8.relative)(home.logical, path);
|
|
8509
|
+
const parentReal = (0, import_path8.resolve)(real, "..");
|
|
8468
8510
|
const parent = parentReal !== real && browsable(parentReal, home.real) ? logical(home, parentReal) : null;
|
|
8469
|
-
const inHome = !rel.startsWith("..") && !(0,
|
|
8511
|
+
const inHome = !rel.startsWith("..") && !(0, import_path8.isAbsolute)(rel);
|
|
8470
8512
|
const drives = windowsHome(home) ? { drives: await windowsDrives() } : {};
|
|
8471
|
-
return fit({ home: "~", homePath: home.logical, path, relative: inHome ? rel.split(
|
|
8513
|
+
return fit({ home: "~", homePath: home.logical, path, relative: inHome ? rel.split(import_path8.sep).join("/") : null, parent, entries: entries.filter((e) => !!e), truncated, ...drives });
|
|
8472
8514
|
}
|
|
8473
8515
|
async function suggestFolders(homePath, sources, opts = {}) {
|
|
8474
8516
|
const started = Date.now();
|
|
@@ -8501,13 +8543,13 @@ async function suggestFolders(homePath, sources, opts = {}) {
|
|
|
8501
8543
|
add(dir, "CONVERSATION");
|
|
8502
8544
|
break;
|
|
8503
8545
|
}
|
|
8504
|
-
const up = (0,
|
|
8546
|
+
const up = (0, import_path8.resolve)(dir, "..");
|
|
8505
8547
|
if (up === dir) break;
|
|
8506
8548
|
dir = up;
|
|
8507
8549
|
}
|
|
8508
8550
|
}
|
|
8509
8551
|
const roots = [];
|
|
8510
|
-
const candidates = DEV_ROOTS.map((root) => (0,
|
|
8552
|
+
const candidates = DEV_ROOTS.map((root) => (0, import_path8.join)(home.logical, root));
|
|
8511
8553
|
if (windowsHome(home)) for (const drive of await windowsDrives()) for (const root of DRIVE_DEV_ROOTS) candidates.push(drive + root);
|
|
8512
8554
|
for (const candidate of candidates) {
|
|
8513
8555
|
if (Date.now() > deadline) {
|
|
@@ -8529,7 +8571,7 @@ async function suggestFolders(homePath, sources, opts = {}) {
|
|
|
8529
8571
|
const finished = await eachUntil(level, deadline, async (dir) => {
|
|
8530
8572
|
const { names } = await subfolderNames(dir, null);
|
|
8531
8573
|
for (const { name, link } of names) {
|
|
8532
|
-
const child = (0,
|
|
8574
|
+
const child = (0, import_path8.join)(dir, name);
|
|
8533
8575
|
const real = link ? await realConnectable(home, child) : child;
|
|
8534
8576
|
if (!real) continue;
|
|
8535
8577
|
if (await isGitRepo(real)) devFound.push(real);
|
|
@@ -8561,14 +8603,14 @@ var CredentialStore = class {
|
|
|
8561
8603
|
}
|
|
8562
8604
|
file;
|
|
8563
8605
|
read() {
|
|
8564
|
-
if (!(0,
|
|
8606
|
+
if (!(0, import_fs8.existsSync)(this.file)) return { version: 1, apis: {} };
|
|
8565
8607
|
try {
|
|
8566
|
-
const mode = (0,
|
|
8567
|
-
if (mode & 63) (0,
|
|
8608
|
+
const mode = (0, import_fs8.statSync)(this.file).mode & 511;
|
|
8609
|
+
if (mode & 63) (0, import_fs8.chmodSync)(this.file, 384);
|
|
8568
8610
|
} catch {
|
|
8569
8611
|
}
|
|
8570
8612
|
try {
|
|
8571
|
-
const raw = JSON.parse((0,
|
|
8613
|
+
const raw = JSON.parse((0, import_fs8.readFileSync)(this.file, "utf8"));
|
|
8572
8614
|
const apis = {};
|
|
8573
8615
|
for (const [api, c] of Object.entries(raw.apis ?? {})) {
|
|
8574
8616
|
if (c && typeof c.machineId === "string" && typeof c.machineToken === "string" && typeof c.orgId === "string") {
|
|
@@ -8588,15 +8630,15 @@ var CredentialStore = class {
|
|
|
8588
8630
|
}
|
|
8589
8631
|
}
|
|
8590
8632
|
write(data) {
|
|
8591
|
-
(0,
|
|
8633
|
+
(0, import_fs8.mkdirSync)((0, import_path9.dirname)(this.file), { recursive: true, mode: 448 });
|
|
8592
8634
|
const tmp = `${this.file}.${process.pid}.tmp`;
|
|
8593
|
-
(0,
|
|
8635
|
+
(0, import_fs8.writeFileSync)(tmp, `${JSON.stringify(data, null, 2)}
|
|
8594
8636
|
`, { mode: 384 });
|
|
8595
8637
|
try {
|
|
8596
|
-
(0,
|
|
8638
|
+
(0, import_fs8.chmodSync)(tmp, 384);
|
|
8597
8639
|
} catch {
|
|
8598
8640
|
}
|
|
8599
|
-
(0,
|
|
8641
|
+
(0, import_fs8.renameSync)(tmp, this.file);
|
|
8600
8642
|
}
|
|
8601
8643
|
get(api) {
|
|
8602
8644
|
return this.read().apis[api] ?? null;
|
|
@@ -8752,10 +8794,10 @@ function claudeProjectDir(cwd) {
|
|
|
8752
8794
|
}
|
|
8753
8795
|
async function copyClaudeTranscript(sources, externalId, root, engineConfigDir) {
|
|
8754
8796
|
if (!isExternalId(externalId)) return false;
|
|
8755
|
-
const projects = (0,
|
|
8797
|
+
const projects = (0, import_path9.join)(sources.claudeDir, "projects");
|
|
8756
8798
|
let original = null;
|
|
8757
8799
|
for (const dir of await (0, import_promises8.readdir)(projects).catch(() => [])) {
|
|
8758
|
-
const candidate = (0,
|
|
8800
|
+
const candidate = (0, import_path9.join)(projects, dir, `${externalId}.jsonl`);
|
|
8759
8801
|
const st = await (0, import_promises8.lstat)(candidate).catch(() => null);
|
|
8760
8802
|
if (st?.isFile()) {
|
|
8761
8803
|
original = candidate;
|
|
@@ -8763,9 +8805,9 @@ async function copyClaudeTranscript(sources, externalId, root, engineConfigDir)
|
|
|
8763
8805
|
}
|
|
8764
8806
|
}
|
|
8765
8807
|
if (!original) return false;
|
|
8766
|
-
const targetDir = (0,
|
|
8767
|
-
const target = (0,
|
|
8768
|
-
if ((0,
|
|
8808
|
+
const targetDir = (0, import_path9.join)(engineConfigDir, "projects", claudeProjectDir(root));
|
|
8809
|
+
const target = (0, import_path9.join)(targetDir, `${externalId}.jsonl`);
|
|
8810
|
+
if ((0, import_fs8.existsSync)(target)) return true;
|
|
8769
8811
|
await (0, import_promises8.mkdir)(targetDir, { recursive: true, mode: 448 });
|
|
8770
8812
|
const partial = `${target}.${process.pid}.partial`;
|
|
8771
8813
|
try {
|
|
@@ -9055,10 +9097,10 @@ async function addFolder(credentials2, api, path, home) {
|
|
|
9055
9097
|
// src/application/services/workspaceSandbox/WorkspaceEngine.ts
|
|
9056
9098
|
var import_child_process5 = require("child_process");
|
|
9057
9099
|
var import_promises17 = require("fs/promises");
|
|
9058
|
-
var
|
|
9100
|
+
var import_fs13 = require("fs");
|
|
9059
9101
|
var import_os6 = require("os");
|
|
9060
9102
|
var import_crypto9 = require("crypto");
|
|
9061
|
-
var
|
|
9103
|
+
var import_path19 = require("path");
|
|
9062
9104
|
|
|
9063
9105
|
// src/application/services/execution/LanguageAdapter.ts
|
|
9064
9106
|
var import_async_hooks = require("async_hooks");
|
|
@@ -9189,10 +9231,10 @@ var ApprovalBroker = class {
|
|
|
9189
9231
|
|
|
9190
9232
|
// src/application/services/workspaceSandbox/appScreenshot.ts
|
|
9191
9233
|
var import_child_process3 = require("child_process");
|
|
9192
|
-
var
|
|
9234
|
+
var import_fs9 = require("fs");
|
|
9193
9235
|
var import_promises9 = require("fs/promises");
|
|
9194
9236
|
var import_os4 = require("os");
|
|
9195
|
-
var
|
|
9237
|
+
var import_path10 = require("path");
|
|
9196
9238
|
var LOCAL_APP_URL = /^http:\/\/(localhost|127\.0\.0\.1)(:\d{2,5})?(\/[^\s]*)?$/i;
|
|
9197
9239
|
function chromeCandidates(env = process.env, platform2 = process.platform) {
|
|
9198
9240
|
const own = env.SQ_CHROME_PATH ? [env.SQ_CHROME_PATH] : [];
|
|
@@ -9205,16 +9247,16 @@ function chromeCandidates(env = process.env, platform2 = process.platform) {
|
|
|
9205
9247
|
];
|
|
9206
9248
|
if (platform2 === "win32") {
|
|
9207
9249
|
const roots = [env.PROGRAMFILES, env["PROGRAMFILES(X86)"], env.LOCALAPPDATA].filter((r) => !!r);
|
|
9208
|
-
return [...own, ...roots.flatMap((r) => [(0,
|
|
9250
|
+
return [...own, ...roots.flatMap((r) => [(0, import_path10.join)(r, "Google", "Chrome", "Application", "chrome.exe"), (0, import_path10.join)(r, "Microsoft", "Edge", "Application", "msedge.exe")])];
|
|
9209
9251
|
}
|
|
9210
9252
|
return [...own, "/usr/bin/chromium", "/usr/bin/chromium-browser", "/usr/bin/google-chrome", "/usr/bin/google-chrome-stable", "/snap/bin/chromium"];
|
|
9211
9253
|
}
|
|
9212
9254
|
var chromeSandboxArgs = (uid = process.getuid?.()) => uid === 0 ? ["--no-sandbox"] : [];
|
|
9213
9255
|
function findChrome(candidates = chromeCandidates()) {
|
|
9214
|
-
return candidates.find((path) => (0,
|
|
9256
|
+
return candidates.find((path) => (0, import_fs9.existsSync)(path)) ?? null;
|
|
9215
9257
|
}
|
|
9216
9258
|
async function screenshotPage(chrome, url, target, size2) {
|
|
9217
|
-
const profile = await (0, import_promises9.mkdtemp)((0,
|
|
9259
|
+
const profile = await (0, import_promises9.mkdtemp)((0, import_path10.join)((0, import_os4.tmpdir)(), "sq-shot-"));
|
|
9218
9260
|
try {
|
|
9219
9261
|
await new Promise((resolve8, reject) => {
|
|
9220
9262
|
(0, import_child_process3.execFile)(chrome, [
|
|
@@ -9243,10 +9285,10 @@ async function screenshotPage(chrome, url, target, size2) {
|
|
|
9243
9285
|
var import_child_process4 = require("child_process");
|
|
9244
9286
|
var import_promises10 = require("fs/promises");
|
|
9245
9287
|
var import_os5 = require("os");
|
|
9246
|
-
var
|
|
9288
|
+
var import_path11 = require("path");
|
|
9247
9289
|
var import_url = require("url");
|
|
9248
9290
|
|
|
9249
|
-
//
|
|
9291
|
+
// node_modules/zod/v3/external.js
|
|
9250
9292
|
var external_exports = {};
|
|
9251
9293
|
__export(external_exports, {
|
|
9252
9294
|
BRAND: () => BRAND,
|
|
@@ -9358,7 +9400,7 @@ __export(external_exports, {
|
|
|
9358
9400
|
void: () => voidType
|
|
9359
9401
|
});
|
|
9360
9402
|
|
|
9361
|
-
//
|
|
9403
|
+
// node_modules/zod/v3/helpers/util.js
|
|
9362
9404
|
var util;
|
|
9363
9405
|
(function(util2) {
|
|
9364
9406
|
util2.assertEqual = (_) => {
|
|
@@ -9492,7 +9534,7 @@ var getParsedType = (data) => {
|
|
|
9492
9534
|
}
|
|
9493
9535
|
};
|
|
9494
9536
|
|
|
9495
|
-
//
|
|
9537
|
+
// node_modules/zod/v3/ZodError.js
|
|
9496
9538
|
var ZodIssueCode = util.arrayToEnum([
|
|
9497
9539
|
"invalid_type",
|
|
9498
9540
|
"invalid_literal",
|
|
@@ -9610,7 +9652,7 @@ ZodError.create = (issues) => {
|
|
|
9610
9652
|
return error;
|
|
9611
9653
|
};
|
|
9612
9654
|
|
|
9613
|
-
//
|
|
9655
|
+
// node_modules/zod/v3/locales/en.js
|
|
9614
9656
|
var errorMap = (issue, _ctx) => {
|
|
9615
9657
|
let message;
|
|
9616
9658
|
switch (issue.code) {
|
|
@@ -9713,7 +9755,7 @@ var errorMap = (issue, _ctx) => {
|
|
|
9713
9755
|
};
|
|
9714
9756
|
var en_default = errorMap;
|
|
9715
9757
|
|
|
9716
|
-
//
|
|
9758
|
+
// node_modules/zod/v3/errors.js
|
|
9717
9759
|
var overrideErrorMap = en_default;
|
|
9718
9760
|
function setErrorMap(map) {
|
|
9719
9761
|
overrideErrorMap = map;
|
|
@@ -9722,7 +9764,7 @@ function getErrorMap() {
|
|
|
9722
9764
|
return overrideErrorMap;
|
|
9723
9765
|
}
|
|
9724
9766
|
|
|
9725
|
-
//
|
|
9767
|
+
// node_modules/zod/v3/helpers/parseUtil.js
|
|
9726
9768
|
var makeIssue = (params) => {
|
|
9727
9769
|
const { data, path, errorMaps, issueData } = params;
|
|
9728
9770
|
const fullPath = [...path, ...issueData.path || []];
|
|
@@ -9832,14 +9874,14 @@ var isDirty = (x) => x.status === "dirty";
|
|
|
9832
9874
|
var isValid = (x) => x.status === "valid";
|
|
9833
9875
|
var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
9834
9876
|
|
|
9835
|
-
//
|
|
9877
|
+
// node_modules/zod/v3/helpers/errorUtil.js
|
|
9836
9878
|
var errorUtil;
|
|
9837
9879
|
(function(errorUtil2) {
|
|
9838
9880
|
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
9839
9881
|
errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
|
|
9840
9882
|
})(errorUtil || (errorUtil = {}));
|
|
9841
9883
|
|
|
9842
|
-
//
|
|
9884
|
+
// node_modules/zod/v3/types.js
|
|
9843
9885
|
var ParseInputLazyPath = class {
|
|
9844
9886
|
constructor(parent, value, path, key) {
|
|
9845
9887
|
this._cachedPath = [];
|
|
@@ -13311,7 +13353,7 @@ var DesignError = class extends Error {
|
|
|
13311
13353
|
code;
|
|
13312
13354
|
};
|
|
13313
13355
|
async function readDesign(absManifest) {
|
|
13314
|
-
if (!absManifest.endsWith(`${
|
|
13356
|
+
if (!absManifest.endsWith(`${import_path11.sep}${DESIGN_MANIFEST}`) && !absManifest.endsWith(`/${DESIGN_MANIFEST}`))
|
|
13315
13357
|
throw new DesignError("NOT_A_DESIGN", `A design is described by its ${DESIGN_MANIFEST} (for example design/stock-control/${DESIGN_MANIFEST}).`);
|
|
13316
13358
|
let raw;
|
|
13317
13359
|
try {
|
|
@@ -13324,9 +13366,9 @@ async function readDesign(absManifest) {
|
|
|
13324
13366
|
const first = parsed.error.issues[0];
|
|
13325
13367
|
throw new DesignError("MANIFEST_INVALID", `${DESIGN_MANIFEST} does not follow the format: ${first ? `${first.path.join(".") || "root"}: ${first.message}` : "invalid"}.`);
|
|
13326
13368
|
}
|
|
13327
|
-
const folder = (0,
|
|
13369
|
+
const folder = (0, import_path11.dirname)(absManifest);
|
|
13328
13370
|
for (const b of parsed.data.boards) {
|
|
13329
|
-
const st = await (0, import_promises10.stat)((0,
|
|
13371
|
+
const st = await (0, import_promises10.stat)((0, import_path11.join)(folder, b.file)).catch(() => null);
|
|
13330
13372
|
if (!st?.isFile()) throw new DesignError("BOARD_MISSING", `The screen ${b.file} listed in ${DESIGN_MANIFEST} does not exist in ${folder}.`);
|
|
13331
13373
|
}
|
|
13332
13374
|
return { folder, manifest: parsed.data };
|
|
@@ -13458,7 +13500,7 @@ function diagramBoard(source, width, height) {
|
|
|
13458
13500
|
return { page: diagramPage(parsed.data, width, height), problems: diagramProblems(parsed.data, width, height) };
|
|
13459
13501
|
}
|
|
13460
13502
|
async function writeDiagramFile(abs, raw) {
|
|
13461
|
-
if (!DIAGRAM_FILE.test((0,
|
|
13503
|
+
if (!DIAGRAM_FILE.test((0, import_path11.basename)(abs))) throw new DesignError("NOT_A_DESIGN", "Only a .diagram.json file is written.");
|
|
13462
13504
|
const parsed = designDiagram.safeParse(raw);
|
|
13463
13505
|
if (!parsed.success) throw new DesignError("MANIFEST_INVALID", "The diagram does not follow the format.");
|
|
13464
13506
|
const body = `${JSON.stringify(parsed.data, null, 2)}
|
|
@@ -13466,8 +13508,8 @@ async function writeDiagramFile(abs, raw) {
|
|
|
13466
13508
|
if (Buffer.byteLength(body) > MAX_DIAGRAM_BYTES) throw new DesignError("MANIFEST_INVALID", "The diagram is too large.");
|
|
13467
13509
|
const st = await (0, import_promises10.lstat)(abs).catch(() => null);
|
|
13468
13510
|
if (!st?.isFile()) throw new DesignError("BOARD_MISSING", "The diagram does not exist.");
|
|
13469
|
-
const { manifest } = await readDesign((0,
|
|
13470
|
-
if (!manifest.boards.some((b) => b.file === (0,
|
|
13511
|
+
const { manifest } = await readDesign((0, import_path11.join)((0, import_path11.dirname)(abs), DESIGN_MANIFEST));
|
|
13512
|
+
if (!manifest.boards.some((b) => b.file === (0, import_path11.basename)(abs))) throw new DesignError("BOARD_MISSING", "The diagram is not a board of its design.");
|
|
13471
13513
|
await (0, import_promises10.writeFile)(abs, body);
|
|
13472
13514
|
}
|
|
13473
13515
|
var CHECKER = `<script>(function(){var errors=[];function push(m){if(errors.length<20)errors.push(String(m).slice(0,240));}
|
|
@@ -13490,7 +13532,7 @@ var doc=document.documentElement;var overflow=Math.max(doc.scrollWidth,document.
|
|
|
13490
13532
|
doc.setAttribute("data-sq-check",JSON.stringify({errors:errors,contrast:contrast,overflow:overflow}));}
|
|
13491
13533
|
addEventListener("load",function(){setTimeout(finish,700);});})();</script>`;
|
|
13492
13534
|
function checkedPage(html, folder) {
|
|
13493
|
-
const base = `<base href="${(0, import_url.pathToFileURL)(folder +
|
|
13535
|
+
const base = `<base href="${(0, import_url.pathToFileURL)(folder + import_path11.sep).href}">`;
|
|
13494
13536
|
const head = /<head[^>]*>/i.exec(html);
|
|
13495
13537
|
if (head) return html.slice(0, head.index + head[0].length) + base + CHECKER + html.slice(head.index + head[0].length);
|
|
13496
13538
|
const open2 = /<html[^>]*>/i.exec(html);
|
|
@@ -13516,10 +13558,10 @@ var run2 = (chrome, args, timeoutMs) => new Promise((resolve8, reject) => {
|
|
|
13516
13558
|
var SCREENS_AT_ONCE = 3;
|
|
13517
13559
|
async function checkDesign(chrome, folder, manifest, opts = {}) {
|
|
13518
13560
|
const runner = opts.runner ?? run2;
|
|
13519
|
-
const work = await (0, import_promises10.mkdtemp)((0,
|
|
13561
|
+
const work = await (0, import_promises10.mkdtemp)((0, import_path11.join)((0, import_os5.tmpdir)(), "sq-design-"));
|
|
13520
13562
|
const one = async (b, i) => {
|
|
13521
|
-
const page = (0,
|
|
13522
|
-
const source = await (0, import_promises10.readFile)((0,
|
|
13563
|
+
const page = (0, import_path11.join)(work, `screen-${i}.html`);
|
|
13564
|
+
const source = await (0, import_promises10.readFile)((0, import_path11.join)(folder, b.file), "utf8");
|
|
13523
13565
|
const diagram = b.device === "diagram" ? diagramBoard(source, b.width, b.height) : null;
|
|
13524
13566
|
await (0, import_promises10.writeFile)(page, checkedPage(diagram ? diagram.page : source, folder));
|
|
13525
13567
|
const url = (0, import_url.pathToFileURL)(page).href;
|
|
@@ -13531,7 +13573,7 @@ async function checkDesign(chrome, folder, manifest, opts = {}) {
|
|
|
13531
13573
|
"--hide-scrollbars",
|
|
13532
13574
|
"--no-first-run",
|
|
13533
13575
|
"--no-default-browser-check",
|
|
13534
|
-
`--user-data-dir=${(0,
|
|
13576
|
+
`--user-data-dir=${(0, import_path11.join)(work, profile)}`,
|
|
13535
13577
|
`--window-size=${b.width},${b.height}`,
|
|
13536
13578
|
"--virtual-time-budget=6000"
|
|
13537
13579
|
];
|
|
@@ -13545,7 +13587,7 @@ async function checkDesign(chrome, folder, manifest, opts = {}) {
|
|
|
13545
13587
|
})();
|
|
13546
13588
|
const pictured = (async () => {
|
|
13547
13589
|
if (i >= MAX_PICTURES) return;
|
|
13548
|
-
const shot = (0,
|
|
13590
|
+
const shot = (0, import_path11.join)(work, `screen-${i}.png`);
|
|
13549
13591
|
try {
|
|
13550
13592
|
await runner(chrome, [...base(`profile-${i}-shot`), `--screenshot=${shot}`, url], 45e3);
|
|
13551
13593
|
const png = await (0, import_promises10.readFile)(shot);
|
|
@@ -13592,17 +13634,17 @@ function designReport(path, manifest, checks) {
|
|
|
13592
13634
|
lines2.push(s.errors || s.contrast || s.overflow || s.unread ? "Fix these problems and what you see wrong in the pictures, then call check_design again before you show the design." : `All clean. Look at the pictures to be sure the screens look right, then show it as .`);
|
|
13593
13635
|
return lines2.join("\n");
|
|
13594
13636
|
}
|
|
13595
|
-
var designPath = (root, absManifest) => (0,
|
|
13637
|
+
var designPath = (root, absManifest) => (0, import_path11.relative)(root, absManifest).split(import_path11.sep).join("/");
|
|
13596
13638
|
|
|
13597
13639
|
// src/application/services/workspaceSandbox/rootFiles.ts
|
|
13598
13640
|
var import_promises11 = require("fs/promises");
|
|
13599
|
-
var
|
|
13600
|
-
var
|
|
13641
|
+
var import_fs10 = require("fs");
|
|
13642
|
+
var import_path12 = require("path");
|
|
13601
13643
|
var ROOT_FILE_MAX_BYTES = 5 * 1024 * 1024;
|
|
13602
13644
|
var ROOT_FILES_MAX_BYTES = 24 * 1024 * 1024;
|
|
13603
13645
|
var ROOT_FILES_MAX_COUNT = 2e3;
|
|
13604
13646
|
var ROOT_FILES_SCAN_MAX = 2e4;
|
|
13605
|
-
var posix3 = (p) => p.split(
|
|
13647
|
+
var posix3 = (p) => p.split(import_path12.sep).join("/");
|
|
13606
13648
|
async function listRootFiles(root, excluded) {
|
|
13607
13649
|
const skip = new Set(excluded.map((d) => d.replace(/[\\/]+$/, "")));
|
|
13608
13650
|
const found = [];
|
|
@@ -13611,15 +13653,15 @@ async function listRootFiles(root, excluded) {
|
|
|
13611
13653
|
if (!handle) return;
|
|
13612
13654
|
for await (const entry of handle) {
|
|
13613
13655
|
if (found.length >= ROOT_FILES_SCAN_MAX) break;
|
|
13614
|
-
const abs = (0,
|
|
13656
|
+
const abs = (0, import_path12.join)(dir, entry.name);
|
|
13615
13657
|
if (entry.isSymbolicLink()) continue;
|
|
13616
13658
|
if (entry.isDirectory()) {
|
|
13617
13659
|
if (entry.name.startsWith(".") || DISCOVERY_SKIP.has(entry.name) || skip.has(abs)) continue;
|
|
13618
|
-
if ((0,
|
|
13660
|
+
if ((0, import_fs10.existsSync)((0, import_path12.join)(abs, ".git"))) continue;
|
|
13619
13661
|
await walk(abs);
|
|
13620
13662
|
} else if (entry.isFile()) {
|
|
13621
13663
|
const st = await (0, import_promises11.lstat)(abs).catch(() => null);
|
|
13622
|
-
if (st?.isFile()) found.push({ path: posix3((0,
|
|
13664
|
+
if (st?.isFile()) found.push({ path: posix3((0, import_path12.relative)(root, abs)), size: st.size, mtimeMs: st.mtimeMs });
|
|
13623
13665
|
}
|
|
13624
13666
|
}
|
|
13625
13667
|
};
|
|
@@ -13636,7 +13678,7 @@ async function listRootFiles(root, excluded) {
|
|
|
13636
13678
|
}
|
|
13637
13679
|
async function withScratchGit(scratch, workTree, fn) {
|
|
13638
13680
|
await (0, import_promises11.mkdir)(scratch, { recursive: true });
|
|
13639
|
-
const gitDir = await (0, import_promises11.mkdtemp)((0,
|
|
13681
|
+
const gitDir = await (0, import_promises11.mkdtemp)((0, import_path12.join)(scratch, "root-files-"));
|
|
13640
13682
|
try {
|
|
13641
13683
|
await git(["init", "-q", "--bare", gitDir], { cwd: scratch });
|
|
13642
13684
|
for (const [k, v] of [["core.bare", "false"], ["core.autocrlf", "false"], ["core.safecrlf", "false"], ["gc.auto", "0"]]) {
|
|
@@ -13654,9 +13696,9 @@ async function rootFilesCheckpoint(root, scratch, files) {
|
|
|
13654
13696
|
async function restoreRootFiles(root, scratch, patch) {
|
|
13655
13697
|
if (!patch.includes("diff --git ")) return { restored: 0, kept: 0 };
|
|
13656
13698
|
await (0, import_promises11.mkdir)(scratch, { recursive: true });
|
|
13657
|
-
const out2 = await (0, import_promises11.mkdtemp)((0,
|
|
13699
|
+
const out2 = await (0, import_promises11.mkdtemp)((0, import_path12.join)(scratch, "root-restore-"));
|
|
13658
13700
|
try {
|
|
13659
|
-
const patchFile = (0,
|
|
13701
|
+
const patchFile = (0, import_path12.join)(scratch, `${Date.now().toString(36)}-root-files.patch`);
|
|
13660
13702
|
await (0, import_promises11.writeFile)(patchFile, patch, "utf8");
|
|
13661
13703
|
try {
|
|
13662
13704
|
await withScratchGit(scratch, out2, (env) => git(["apply", "--binary", "--whitespace=nowarn", patchFile], { cwd: out2, env, timeoutMs: 5 * 6e4 }));
|
|
@@ -13669,12 +13711,12 @@ async function restoreRootFiles(root, scratch, patch) {
|
|
|
13669
13711
|
for (const f of files) {
|
|
13670
13712
|
const target = await resolveInside(root, f.path);
|
|
13671
13713
|
if (!target) continue;
|
|
13672
|
-
if ((0,
|
|
13714
|
+
if ((0, import_fs10.existsSync)(target)) {
|
|
13673
13715
|
kept++;
|
|
13674
13716
|
continue;
|
|
13675
13717
|
}
|
|
13676
|
-
await (0, import_promises11.mkdir)((0,
|
|
13677
|
-
const from = (0,
|
|
13718
|
+
await (0, import_promises11.mkdir)((0, import_path12.dirname)(target), { recursive: true });
|
|
13719
|
+
const from = (0, import_path12.join)(out2, f.path);
|
|
13678
13720
|
await (0, import_promises11.copyFile)(from, target);
|
|
13679
13721
|
const mode = (await (0, import_promises11.stat)(from)).mode & 511;
|
|
13680
13722
|
await (0, import_promises11.chmod)(target, mode).catch(() => void 0);
|
|
@@ -13690,13 +13732,13 @@ async function restoreKeptDesign(root, path, files) {
|
|
|
13690
13732
|
if (!/(^|\/)design\.json$/.test(path) || !files.some((f) => f.name === "design.json")) return 0;
|
|
13691
13733
|
const folder = path.replace(/design\.json$/, "");
|
|
13692
13734
|
const manifest = await resolveInside(root, `${folder}design.json`);
|
|
13693
|
-
if (!manifest || (0,
|
|
13735
|
+
if (!manifest || (0, import_fs10.existsSync)(manifest)) return 0;
|
|
13694
13736
|
let written = 0;
|
|
13695
13737
|
for (const f of files) {
|
|
13696
13738
|
if (!DESIGN_FILE.test(f.name) || typeof f.data !== "string") continue;
|
|
13697
13739
|
const target = await resolveInside(root, `${folder}${f.name}`);
|
|
13698
|
-
if (!target || (0,
|
|
13699
|
-
await (0, import_promises11.mkdir)((0,
|
|
13740
|
+
if (!target || (0, import_fs10.existsSync)(target)) continue;
|
|
13741
|
+
await (0, import_promises11.mkdir)((0, import_path12.dirname)(target), { recursive: true });
|
|
13700
13742
|
await (0, import_promises11.writeFile)(target, Buffer.from(f.data, "base64"));
|
|
13701
13743
|
written++;
|
|
13702
13744
|
}
|
|
@@ -14208,7 +14250,7 @@ function buildScaleQualityServer(sdk, host) {
|
|
|
14208
14250
|
|
|
14209
14251
|
// src/application/services/workspaceSandbox/projectConventions.ts
|
|
14210
14252
|
var import_promises12 = require("fs/promises");
|
|
14211
|
-
var
|
|
14253
|
+
var import_path13 = require("path");
|
|
14212
14254
|
var CONVENTION_FILES = ["CLAUDE.md", "AGENTS.md", ".claude/CLAUDE.md"];
|
|
14213
14255
|
var CONVENTION_CAPS = { perFileBytes: 24 * 1024, totalBytes: 64 * 1024 };
|
|
14214
14256
|
async function readConventions(repos, caps = CONVENTION_CAPS) {
|
|
@@ -14219,11 +14261,11 @@ async function readConventions(repos, caps = CONVENTION_CAPS) {
|
|
|
14219
14261
|
if (!realRoot) continue;
|
|
14220
14262
|
for (const name of CONVENTION_FILES) {
|
|
14221
14263
|
if (total >= caps.totalBytes) return out2;
|
|
14222
|
-
const abs = (0,
|
|
14264
|
+
const abs = (0, import_path13.join)(repo2.root, name);
|
|
14223
14265
|
const st = await (0, import_promises12.lstat)(abs).catch(() => null);
|
|
14224
14266
|
if (!st?.isFile()) continue;
|
|
14225
14267
|
const real = await (0, import_promises12.realpath)(abs).catch(() => null);
|
|
14226
|
-
if (!real || (0,
|
|
14268
|
+
if (!real || (0, import_path13.relative)(realRoot, real).startsWith("..") || (0, import_path13.relative)(realRoot, real).split(import_path13.sep).includes("..")) continue;
|
|
14227
14269
|
const buf = await (0, import_promises12.readFile)(abs).catch(() => null);
|
|
14228
14270
|
if (!buf || buf.includes(0)) continue;
|
|
14229
14271
|
const room = Math.min(caps.perFileBytes, caps.totalBytes - total);
|
|
@@ -14250,7 +14292,7 @@ ${f.text.replace(/<\/project_conventions>/g, "")}
|
|
|
14250
14292
|
}
|
|
14251
14293
|
|
|
14252
14294
|
// src/application/services/workspaceSandbox/sdkEventMapper.ts
|
|
14253
|
-
var
|
|
14295
|
+
var import_path14 = require("path");
|
|
14254
14296
|
var TERMINAL_TAIL_BYTES = 64 * 1024;
|
|
14255
14297
|
var FILE_CHANGING = /* @__PURE__ */ new Set(["Edit", "MultiEdit", "Write", "NotebookEdit", "Bash", "Agent", "Task"]);
|
|
14256
14298
|
var SUBAGENT_NAMES = /* @__PURE__ */ new Set(["Agent", "Task"]);
|
|
@@ -14671,8 +14713,8 @@ function describeTool(name, input, root) {
|
|
|
14671
14713
|
const s = (k) => typeof input[k] === "string" ? input[k] : "";
|
|
14672
14714
|
const rel = (p) => {
|
|
14673
14715
|
if (!p) return "";
|
|
14674
|
-
if (!(0,
|
|
14675
|
-
const r = (0,
|
|
14716
|
+
if (!(0, import_path14.isAbsolute)(p)) return p;
|
|
14717
|
+
const r = (0, import_path14.relative)(root, p);
|
|
14676
14718
|
return r && !r.startsWith("..") ? r : p;
|
|
14677
14719
|
};
|
|
14678
14720
|
switch (name) {
|
|
@@ -14686,10 +14728,10 @@ function describeTool(name, input, root) {
|
|
|
14686
14728
|
return { kind: "search", label: `Searching for "${clip(s("pattern"), 80)}"`, detail: s("pattern"), code: "STEP_SEARCH", params: { pattern: clip(s("pattern"), 80) } };
|
|
14687
14729
|
case "Edit":
|
|
14688
14730
|
case "MultiEdit":
|
|
14689
|
-
if (/[\\/]plans[\\/][^\\/]+\.md$/.test(s("file_path")) && (0,
|
|
14731
|
+
if (/[\\/]plans[\\/][^\\/]+\.md$/.test(s("file_path")) && (0, import_path14.isAbsolute)(rel(s("file_path")))) return { kind: "think", label: "Writing the plan", code: "STEP_PLAN_WRITE" };
|
|
14690
14732
|
return { kind: "edit", label: `Editing ${rel(s("file_path"))}`, detail: rel(s("file_path")), code: "STEP_EDIT", params: { path: rel(s("file_path")) } };
|
|
14691
14733
|
case "Write":
|
|
14692
|
-
if (/[\\/]plans[\\/][^\\/]+\.md$/.test(s("file_path")) && (0,
|
|
14734
|
+
if (/[\\/]plans[\\/][^\\/]+\.md$/.test(s("file_path")) && (0, import_path14.isAbsolute)(rel(s("file_path")))) return { kind: "think", label: "Writing the plan", code: "STEP_PLAN_WRITE" };
|
|
14693
14735
|
return { kind: "edit", label: `Writing ${rel(s("file_path"))}`, detail: rel(s("file_path")), code: "STEP_WRITE", params: { path: rel(s("file_path")) } };
|
|
14694
14736
|
case "NotebookEdit":
|
|
14695
14737
|
return { kind: "edit", label: `Editing ${rel(s("notebook_path"))}`, detail: rel(s("notebook_path")), code: "STEP_EDIT", params: { path: rel(s("notebook_path")) } };
|
|
@@ -15146,9 +15188,9 @@ function buildSystemAppend(c) {
|
|
|
15146
15188
|
}
|
|
15147
15189
|
|
|
15148
15190
|
// src/application/services/workspaceSandbox/testCommand.ts
|
|
15149
|
-
var
|
|
15191
|
+
var import_fs11 = require("fs");
|
|
15150
15192
|
var import_promises13 = require("fs/promises");
|
|
15151
|
-
var
|
|
15193
|
+
var import_path15 = require("path");
|
|
15152
15194
|
function commandForFramework(framework, dir, pkgTestScript) {
|
|
15153
15195
|
switch (framework) {
|
|
15154
15196
|
case "jest":
|
|
@@ -15160,13 +15202,13 @@ function commandForFramework(framework, dir, pkgTestScript) {
|
|
|
15160
15202
|
case "go-test":
|
|
15161
15203
|
return "go test ./...";
|
|
15162
15204
|
case "junit":
|
|
15163
|
-
return (0,
|
|
15205
|
+
return (0, import_fs11.existsSync)((0, import_path15.join)(dir, "gradlew")) ? "./gradlew test" : (0, import_fs11.existsSync)((0, import_path15.join)(dir, "build.gradle")) || (0, import_fs11.existsSync)((0, import_path15.join)(dir, "build.gradle.kts")) ? "gradle test" : "mvn -q test";
|
|
15164
15206
|
case "xunit":
|
|
15165
15207
|
case "nunit":
|
|
15166
15208
|
case "mstest":
|
|
15167
15209
|
return "dotnet test";
|
|
15168
15210
|
case "phpunit":
|
|
15169
|
-
return (0,
|
|
15211
|
+
return (0, import_fs11.existsSync)((0, import_path15.join)(dir, "vendor", "bin", "phpunit")) ? "vendor/bin/phpunit" : "phpunit";
|
|
15170
15212
|
case "rspec":
|
|
15171
15213
|
return "bundle exec rspec";
|
|
15172
15214
|
case "cargo-test":
|
|
@@ -15174,7 +15216,7 @@ function commandForFramework(framework, dir, pkgTestScript) {
|
|
|
15174
15216
|
case "exunit":
|
|
15175
15217
|
return "mix test";
|
|
15176
15218
|
case "dart-test":
|
|
15177
|
-
return (0,
|
|
15219
|
+
return (0, import_fs11.existsSync)((0, import_path15.join)(dir, "pubspec.yaml")) && /flutter:/.test(safeRead((0, import_path15.join)(dir, "pubspec.yaml"))) ? "flutter test" : "dart test";
|
|
15178
15220
|
case "xctest":
|
|
15179
15221
|
return "swift test";
|
|
15180
15222
|
case "scalatest":
|
|
@@ -15187,13 +15229,13 @@ function commandForFramework(framework, dir, pkgTestScript) {
|
|
|
15187
15229
|
}
|
|
15188
15230
|
function safeRead(p) {
|
|
15189
15231
|
try {
|
|
15190
|
-
return (0,
|
|
15232
|
+
return (0, import_fs11.readFileSync)(p, "utf8");
|
|
15191
15233
|
} catch {
|
|
15192
15234
|
return "";
|
|
15193
15235
|
}
|
|
15194
15236
|
}
|
|
15195
15237
|
async function hasTestScript(dir) {
|
|
15196
|
-
const raw = await (0, import_promises13.readFile)((0,
|
|
15238
|
+
const raw = await (0, import_promises13.readFile)((0, import_path15.join)(dir, "package.json"), "utf8").catch(() => null);
|
|
15197
15239
|
if (!raw) return false;
|
|
15198
15240
|
try {
|
|
15199
15241
|
const script = JSON.parse(raw).scripts?.test;
|
|
@@ -15203,7 +15245,7 @@ async function hasTestScript(dir) {
|
|
|
15203
15245
|
}
|
|
15204
15246
|
}
|
|
15205
15247
|
async function detectTestCommandFromManifests(dir) {
|
|
15206
|
-
const has = (f) => (0,
|
|
15248
|
+
const has = (f) => (0, import_fs11.existsSync)((0, import_path15.join)(dir, f));
|
|
15207
15249
|
const pkgScript = await hasTestScript(dir);
|
|
15208
15250
|
if (pkgScript) return { command: "npm test --silent", framework: "npm-script", source: "manifest" };
|
|
15209
15251
|
const checks = [
|
|
@@ -15228,9 +15270,9 @@ async function detectTestCommandFromManifests(dir) {
|
|
|
15228
15270
|
|
|
15229
15271
|
// src/application/services/workspaceSandbox/transcript.ts
|
|
15230
15272
|
var import_crypto8 = require("crypto");
|
|
15231
|
-
var
|
|
15273
|
+
var import_fs12 = require("fs");
|
|
15232
15274
|
var import_promises14 = require("fs/promises");
|
|
15233
|
-
var
|
|
15275
|
+
var import_path16 = require("path");
|
|
15234
15276
|
var import_zlib2 = require("zlib");
|
|
15235
15277
|
var TRANSCRIPT_CAPS = { maxRawBytes: 64 * 1024 * 1024, maxCompressedBytes: 4 * 1024 * 1024 };
|
|
15236
15278
|
function engineProjectDir(cwd) {
|
|
@@ -15239,9 +15281,9 @@ function engineProjectDir(cwd) {
|
|
|
15239
15281
|
var SESSION_ID = /^[A-Za-z0-9-]{8,80}$/;
|
|
15240
15282
|
async function findTranscript(configDir, sessionId) {
|
|
15241
15283
|
if (!SESSION_ID.test(sessionId)) return null;
|
|
15242
|
-
const projects = (0,
|
|
15284
|
+
const projects = (0, import_path16.join)(configDir, "projects");
|
|
15243
15285
|
for (const dir of await (0, import_promises14.readdir)(projects).catch(() => [])) {
|
|
15244
|
-
const file = (0,
|
|
15286
|
+
const file = (0, import_path16.join)(projects, dir, `${sessionId}.jsonl`);
|
|
15245
15287
|
const st = await (0, import_promises14.stat)(file).catch(() => null);
|
|
15246
15288
|
if (st?.isFile()) return file;
|
|
15247
15289
|
}
|
|
@@ -15287,9 +15329,9 @@ async function restoreTranscript(configDir, cwd, t) {
|
|
|
15287
15329
|
return false;
|
|
15288
15330
|
}
|
|
15289
15331
|
if (t.sha256 && (0, import_crypto8.createHash)("sha256").update(text3).digest("hex") !== t.sha256) return false;
|
|
15290
|
-
const dir = (0,
|
|
15332
|
+
const dir = (0, import_path16.join)(configDir, "projects", engineProjectDir(cwd));
|
|
15291
15333
|
await (0, import_promises14.mkdir)(dir, { recursive: true, mode: 448 });
|
|
15292
|
-
const target = (0,
|
|
15334
|
+
const target = (0, import_path16.join)(dir, `${t.sdkSessionId}.jsonl`);
|
|
15293
15335
|
const partial = `${target}.${process.pid}.partial`;
|
|
15294
15336
|
try {
|
|
15295
15337
|
await (0, import_promises14.writeFile)(partial, text3, { mode: 384 });
|
|
@@ -15299,7 +15341,7 @@ async function restoreTranscript(configDir, cwd, t) {
|
|
|
15299
15341
|
await (0, import_promises14.rm)(partial, { force: true }).catch(() => void 0);
|
|
15300
15342
|
return false;
|
|
15301
15343
|
}
|
|
15302
|
-
return (0,
|
|
15344
|
+
return (0, import_fs12.existsSync)(target);
|
|
15303
15345
|
}
|
|
15304
15346
|
|
|
15305
15347
|
// src/application/services/workspaceSandbox/askQuestion.ts
|
|
@@ -15400,7 +15442,7 @@ function questionResult(o, input) {
|
|
|
15400
15442
|
|
|
15401
15443
|
// src/application/services/workspaceSandbox/workspaceFiles.ts
|
|
15402
15444
|
var import_promises15 = require("fs/promises");
|
|
15403
|
-
var
|
|
15445
|
+
var import_path17 = require("path");
|
|
15404
15446
|
var FILE_CAPS = { maxEntries: 500, maxReadBytes: 256 * 1024, maxFileBytes: 20 * 1024 * 1024, maxLines: 5e3, maxImageBytes: 6 * 1024 * 1024 };
|
|
15405
15447
|
var FileRequestError = class extends Error {
|
|
15406
15448
|
constructor(code) {
|
|
@@ -15415,31 +15457,31 @@ async function fenced(root, rel, denied) {
|
|
|
15415
15457
|
if (clean.split(/[\\/]/).includes("..")) throw new FileRequestError("PATH_OUTSIDE_WORKSPACE");
|
|
15416
15458
|
const abs = await resolveInside(root, clean || ".");
|
|
15417
15459
|
if (!abs) throw new FileRequestError("PATH_OUTSIDE_WORKSPACE");
|
|
15418
|
-
const realRoot = await (0, import_promises15.realpath)(root).catch(() => (0,
|
|
15419
|
-
const r = (0,
|
|
15420
|
-
if (r.split(
|
|
15460
|
+
const realRoot = await (0, import_promises15.realpath)(root).catch(() => (0, import_path17.resolve)(root));
|
|
15461
|
+
const r = (0, import_path17.relative)(realRoot, abs);
|
|
15462
|
+
if (r.split(import_path17.sep).includes(".git")) throw new FileRequestError("PATH_OUTSIDE_WORKSPACE");
|
|
15421
15463
|
for (const d of denied) {
|
|
15422
|
-
const realDenied = await (0, import_promises15.realpath)(d).catch(() => (0,
|
|
15423
|
-
if (abs === realDenied || abs.startsWith(realDenied +
|
|
15464
|
+
const realDenied = await (0, import_promises15.realpath)(d).catch(() => (0, import_path17.resolve)(d));
|
|
15465
|
+
if (abs === realDenied || abs.startsWith(realDenied + import_path17.sep)) throw new FileRequestError("PATH_OUTSIDE_WORKSPACE");
|
|
15424
15466
|
}
|
|
15425
|
-
return { abs, rel: r.split(
|
|
15467
|
+
return { abs, rel: r.split(import_path17.sep).join("/") };
|
|
15426
15468
|
}
|
|
15427
15469
|
async function listFiles(root, rel, denied = []) {
|
|
15428
15470
|
const { abs, rel: clean } = await fenced(root, rel, denied);
|
|
15429
15471
|
const st = await (0, import_promises15.stat)(abs).catch(() => null);
|
|
15430
15472
|
if (!st) throw new FileRequestError("NOT_FOUND");
|
|
15431
15473
|
if (!st.isDirectory()) throw new FileRequestError("NOT_A_DIRECTORY");
|
|
15432
|
-
const deniedReal = await Promise.all(denied.map((d) => (0, import_promises15.realpath)(d).catch(() => (0,
|
|
15474
|
+
const deniedReal = await Promise.all(denied.map((d) => (0, import_promises15.realpath)(d).catch(() => (0, import_path17.resolve)(d))));
|
|
15433
15475
|
const dirents = await (0, import_promises15.readdir)(abs, { withFileTypes: true });
|
|
15434
15476
|
const entries = [];
|
|
15435
15477
|
for (const d of dirents) {
|
|
15436
15478
|
if (d.name === ".git") continue;
|
|
15437
|
-
const child = (0,
|
|
15438
|
-
if (deniedReal.some((x) => child === x || child.startsWith(x +
|
|
15479
|
+
const child = (0, import_path17.join)(abs, d.name);
|
|
15480
|
+
if (deniedReal.some((x) => child === x || child.startsWith(x + import_path17.sep))) continue;
|
|
15439
15481
|
let type = d.isDirectory() ? "dir" : d.isFile() ? "file" : null;
|
|
15440
15482
|
let size2;
|
|
15441
15483
|
if (d.isSymbolicLink()) {
|
|
15442
|
-
const inside3 = await resolveInside(root, (0,
|
|
15484
|
+
const inside3 = await resolveInside(root, (0, import_path17.relative)(root, child)).catch(() => null);
|
|
15443
15485
|
const target = inside3 ? await (0, import_promises15.stat)(child).catch(() => null) : null;
|
|
15444
15486
|
type = target?.isDirectory() ? "dir" : target?.isFile() ? "file" : null;
|
|
15445
15487
|
size2 = target?.isFile() ? target.size : void 0;
|
|
@@ -15497,12 +15539,12 @@ function imageMime(buf) {
|
|
|
15497
15539
|
}
|
|
15498
15540
|
async function insideRelative(path, bases) {
|
|
15499
15541
|
const clean = (path ?? "").trim().replace(/^file:\/\//i, "");
|
|
15500
|
-
if (!(0,
|
|
15542
|
+
if (!(0, import_path17.isAbsolute)(clean)) return clean.replace(/^\.\//, "");
|
|
15501
15543
|
for (const base of bases) {
|
|
15502
|
-
for (const root of [(0,
|
|
15503
|
-
const rel = (0,
|
|
15544
|
+
for (const root of [(0, import_path17.resolve)(base), await (0, import_promises15.realpath)(base).catch(() => (0, import_path17.resolve)(base))]) {
|
|
15545
|
+
const rel = (0, import_path17.relative)(root, (0, import_path17.resolve)(clean));
|
|
15504
15546
|
if (!rel) return "";
|
|
15505
|
-
if (rel !== ".." && !rel.startsWith(`..${
|
|
15547
|
+
if (rel !== ".." && !rel.startsWith(`..${import_path17.sep}`) && !(0, import_path17.isAbsolute)(rel)) return rel.split(import_path17.sep).join("/");
|
|
15506
15548
|
}
|
|
15507
15549
|
}
|
|
15508
15550
|
throw new FileRequestError("PATH_OUTSIDE_WORKSPACE");
|
|
@@ -15582,10 +15624,10 @@ function buildOrgMcpServers(sdk, types, catalog, host) {
|
|
|
15582
15624
|
}
|
|
15583
15625
|
async function callOrgTool(host, server, tool, args) {
|
|
15584
15626
|
if (!host.transport.mcpCall) return text2("The organization MCP servers are not available in this workspace.", true);
|
|
15585
|
-
const
|
|
15627
|
+
const call2 = (approvalId) => host.transport.mcpCall({ server, tool, arguments: args, ...approvalId ? { approvalId } : {} });
|
|
15586
15628
|
let res;
|
|
15587
15629
|
try {
|
|
15588
|
-
res = await
|
|
15630
|
+
res = await call2();
|
|
15589
15631
|
} catch {
|
|
15590
15632
|
return text2(`${server} could not be reached through ScaleQuality. Tell the user; do not retry without being asked.`, true);
|
|
15591
15633
|
}
|
|
@@ -15595,7 +15637,7 @@ async function callOrgTool(host, server, tool, args) {
|
|
|
15595
15637
|
if (!decision) return text2(`The call to ${server} (${tool}) was stopped before the user decided. Nothing ran.`, true);
|
|
15596
15638
|
if (decision.decision === "REJECT") return text2(`The user declined the call to ${server} (${tool}). Nothing ran.`);
|
|
15597
15639
|
try {
|
|
15598
|
-
res = await
|
|
15640
|
+
res = await call2(pending);
|
|
15599
15641
|
} catch {
|
|
15600
15642
|
return text2(`${server} could not be reached through ScaleQuality after the approval. Tell the user; do not retry without being asked.`, true);
|
|
15601
15643
|
}
|
|
@@ -15609,7 +15651,7 @@ async function callOrgTool(host, server, tool, args) {
|
|
|
15609
15651
|
|
|
15610
15652
|
// src/application/services/workspaceSandbox/workspaceSkills.ts
|
|
15611
15653
|
var import_promises16 = require("fs/promises");
|
|
15612
|
-
var
|
|
15654
|
+
var import_path18 = require("path");
|
|
15613
15655
|
var SKILLS_PLUGIN = "sq";
|
|
15614
15656
|
var BUILTIN_SKILLS = ["code-review", "simplify", "debug", "verify"];
|
|
15615
15657
|
var SKILL_CAPS = { fileBytes: 256 * 1024, skillBytes: 2 * 1024 * 1024, skillFiles: 200, totalBytes: 16 * 1024 * 1024, skills: 200 };
|
|
@@ -15656,26 +15698,26 @@ async function regularFile(abs, realRoot) {
|
|
|
15656
15698
|
const st = await (0, import_promises16.lstat)(abs).catch(() => null);
|
|
15657
15699
|
if (!st?.isFile()) return false;
|
|
15658
15700
|
const real = await (0, import_promises16.realpath)(abs).catch(() => null);
|
|
15659
|
-
return !!real && !(0,
|
|
15701
|
+
return !!real && !(0, import_path18.relative)(realRoot, real).split(import_path18.sep).includes("..");
|
|
15660
15702
|
}
|
|
15661
15703
|
async function copySkillDir(src, dest, realRoot, budget) {
|
|
15662
15704
|
let files = 0, bytes = 0;
|
|
15663
15705
|
const walk = async (rel) => {
|
|
15664
|
-
const entries = await (0, import_promises16.readdir)((0,
|
|
15706
|
+
const entries = await (0, import_promises16.readdir)((0, import_path18.join)(src, rel), { withFileTypes: true }).catch(() => []);
|
|
15665
15707
|
for (const e of entries) {
|
|
15666
15708
|
if (files >= SKILL_CAPS.skillFiles || bytes >= SKILL_CAPS.skillBytes) return;
|
|
15667
|
-
const r = rel ? (0,
|
|
15709
|
+
const r = rel ? (0, import_path18.join)(rel, e.name) : e.name;
|
|
15668
15710
|
if (e.isDirectory()) {
|
|
15669
15711
|
if (!SKIP_DIRS.has(e.name)) await walk(r);
|
|
15670
15712
|
continue;
|
|
15671
15713
|
}
|
|
15672
15714
|
if (!e.isFile() || r === "SKILL.md") continue;
|
|
15673
|
-
const abs = (0,
|
|
15715
|
+
const abs = (0, import_path18.join)(src, r);
|
|
15674
15716
|
if (!await regularFile(abs, realRoot)) continue;
|
|
15675
15717
|
const buf = await (0, import_promises16.readFile)(abs).catch(() => null);
|
|
15676
15718
|
if (!buf || buf.length > SKILL_CAPS.fileBytes || bytes + buf.length > SKILL_CAPS.skillBytes || budget.bytes < buf.length) continue;
|
|
15677
|
-
await (0, import_promises16.mkdir)((0,
|
|
15678
|
-
await (0, import_promises16.writeFile)((0,
|
|
15719
|
+
await (0, import_promises16.mkdir)((0, import_path18.join)(dest, rel), { recursive: true });
|
|
15720
|
+
await (0, import_promises16.writeFile)((0, import_path18.join)(dest, r), buf, { mode: 384 });
|
|
15679
15721
|
files++;
|
|
15680
15722
|
bytes += buf.length;
|
|
15681
15723
|
budget.bytes -= buf.length;
|
|
@@ -15685,8 +15727,8 @@ async function copySkillDir(src, dest, realRoot, budget) {
|
|
|
15685
15727
|
}
|
|
15686
15728
|
async function buildSkillsPlugin(opts) {
|
|
15687
15729
|
await (0, import_promises16.rm)(opts.dir, { recursive: true, force: true });
|
|
15688
|
-
await (0, import_promises16.mkdir)((0,
|
|
15689
|
-
await (0, import_promises16.writeFile)((0,
|
|
15730
|
+
await (0, import_promises16.mkdir)((0, import_path18.join)(opts.dir, ".claude-plugin"), { recursive: true, mode: 448 });
|
|
15731
|
+
await (0, import_promises16.writeFile)((0, import_path18.join)(opts.dir, ".claude-plugin", "plugin.json"), JSON.stringify({ name: SKILLS_PLUGIN, description: "Skills and commands of this ScaleQuality workspace" }));
|
|
15690
15732
|
const out2 = [];
|
|
15691
15733
|
const taken = new Set(BUILTIN_SKILLS);
|
|
15692
15734
|
const budget = { bytes: SKILL_CAPS.totalBytes };
|
|
@@ -15697,8 +15739,8 @@ async function buildSkillsPlugin(opts) {
|
|
|
15697
15739
|
const meta = { description: s.description ?? "", ...s.argumentHint ? { "argument-hint": s.argumentHint } : {} };
|
|
15698
15740
|
const text3 = rebuild(meta, name, s.body);
|
|
15699
15741
|
if (Buffer.byteLength(text3) > SKILL_CAPS.fileBytes) continue;
|
|
15700
|
-
await (0, import_promises16.mkdir)((0,
|
|
15701
|
-
await (0, import_promises16.writeFile)((0,
|
|
15742
|
+
await (0, import_promises16.mkdir)((0, import_path18.join)(opts.dir, "skills", name), { recursive: true });
|
|
15743
|
+
await (0, import_promises16.writeFile)((0, import_path18.join)(opts.dir, "skills", name, "SKILL.md"), text3, { mode: 384 });
|
|
15702
15744
|
budget.bytes -= Buffer.byteLength(text3);
|
|
15703
15745
|
taken.add(name);
|
|
15704
15746
|
out2.push({ name, description: meta.description.slice(0, 300), kind: "skill", source: "organization", ...s.argumentHint ? { argumentHint: s.argumentHint.slice(0, 120) } : {} });
|
|
@@ -15706,22 +15748,22 @@ async function buildSkillsPlugin(opts) {
|
|
|
15706
15748
|
for (const repo2 of opts.repos) {
|
|
15707
15749
|
const realRoot = await (0, import_promises16.realpath)(repo2.root).catch(() => null);
|
|
15708
15750
|
if (!realRoot) continue;
|
|
15709
|
-
const skillsDir = (0,
|
|
15751
|
+
const skillsDir = (0, import_path18.join)(repo2.root, ".claude", "skills");
|
|
15710
15752
|
for (const e of (await (0, import_promises16.readdir)(skillsDir, { withFileTypes: true }).catch(() => [])).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
15711
15753
|
if (!room() || !e.isDirectory()) continue;
|
|
15712
|
-
const file = (0,
|
|
15754
|
+
const file = (0, import_path18.join)(skillsDir, e.name, "SKILL.md");
|
|
15713
15755
|
if (!await regularFile(file, realRoot)) continue;
|
|
15714
15756
|
const buf = await (0, import_promises16.readFile)(file).catch(() => null);
|
|
15715
15757
|
if (!buf || buf.length > SKILL_CAPS.fileBytes || buf.includes(0)) continue;
|
|
15716
15758
|
const { meta, body } = parseSkillFile(buf.toString("utf8"));
|
|
15717
15759
|
const name = (meta.name || e.name).toLowerCase();
|
|
15718
15760
|
if (!NAME.test(name) || taken.has(name)) continue;
|
|
15719
|
-
const dest = (0,
|
|
15761
|
+
const dest = (0, import_path18.join)(opts.dir, "skills", name);
|
|
15720
15762
|
await (0, import_promises16.mkdir)(dest, { recursive: true });
|
|
15721
15763
|
const text3 = rebuild(meta, name, body);
|
|
15722
|
-
await (0, import_promises16.writeFile)((0,
|
|
15764
|
+
await (0, import_promises16.writeFile)((0, import_path18.join)(dest, "SKILL.md"), text3, { mode: 384 });
|
|
15723
15765
|
budget.bytes -= Buffer.byteLength(text3);
|
|
15724
|
-
await copySkillDir((0,
|
|
15766
|
+
await copySkillDir((0, import_path18.join)(skillsDir, e.name), dest, realRoot, budget);
|
|
15725
15767
|
taken.add(name);
|
|
15726
15768
|
out2.push({
|
|
15727
15769
|
name,
|
|
@@ -15732,10 +15774,10 @@ async function buildSkillsPlugin(opts) {
|
|
|
15732
15774
|
...meta["argument-hint"] ? { argumentHint: meta["argument-hint"].slice(0, 120) } : {}
|
|
15733
15775
|
});
|
|
15734
15776
|
}
|
|
15735
|
-
const commandsDir = (0,
|
|
15777
|
+
const commandsDir = (0, import_path18.join)(repo2.root, ".claude", "commands");
|
|
15736
15778
|
for (const e of (await (0, import_promises16.readdir)(commandsDir, { withFileTypes: true }).catch(() => [])).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
15737
15779
|
if (!room() || !e.isFile() || !e.name.endsWith(".md")) continue;
|
|
15738
|
-
const file = (0,
|
|
15780
|
+
const file = (0, import_path18.join)(commandsDir, e.name);
|
|
15739
15781
|
if (!await regularFile(file, realRoot)) continue;
|
|
15740
15782
|
const buf = await (0, import_promises16.readFile)(file).catch(() => null);
|
|
15741
15783
|
if (!buf || buf.length > SKILL_CAPS.fileBytes || buf.includes(0)) continue;
|
|
@@ -15748,8 +15790,8 @@ ${lines2.join("\n")}
|
|
|
15748
15790
|
---
|
|
15749
15791
|
|
|
15750
15792
|
` : ""}${neutralize(body)}`;
|
|
15751
|
-
await (0, import_promises16.mkdir)((0,
|
|
15752
|
-
await (0, import_promises16.writeFile)((0,
|
|
15793
|
+
await (0, import_promises16.mkdir)((0, import_path18.join)(opts.dir, "commands"), { recursive: true });
|
|
15794
|
+
await (0, import_promises16.writeFile)((0, import_path18.join)(opts.dir, "commands", `${name}.md`), text3, { mode: 384 });
|
|
15753
15795
|
budget.bytes -= Buffer.byteLength(text3);
|
|
15754
15796
|
taken.add(name);
|
|
15755
15797
|
out2.push({
|
|
@@ -15793,13 +15835,13 @@ async function buildOrganizationPlugins(opts) {
|
|
|
15793
15835
|
for (const p of opts.plugins) {
|
|
15794
15836
|
const plugin = p.name.toLowerCase();
|
|
15795
15837
|
if (!/^[a-z0-9][a-z0-9-]{0,39}$/.test(plugin) || plugin === SKILLS_PLUGIN || dirs.some((d) => d.endsWith(`/${plugin}`))) continue;
|
|
15796
|
-
const root = (0,
|
|
15797
|
-
await (0, import_promises16.mkdir)((0,
|
|
15798
|
-
await (0, import_promises16.writeFile)((0,
|
|
15838
|
+
const root = (0, import_path18.join)(opts.dir, plugin);
|
|
15839
|
+
await (0, import_promises16.mkdir)((0, import_path18.join)(root, ".claude-plugin"), { recursive: true, mode: 448 });
|
|
15840
|
+
await (0, import_promises16.writeFile)((0, import_path18.join)(root, ".claude-plugin", "plugin.json"), JSON.stringify({ name: plugin }));
|
|
15799
15841
|
const write = async (rel, text3) => {
|
|
15800
|
-
const abs = (0,
|
|
15801
|
-
if ((0,
|
|
15802
|
-
await (0, import_promises16.mkdir)((0,
|
|
15842
|
+
const abs = (0, import_path18.join)(root, rel);
|
|
15843
|
+
if ((0, import_path18.relative)(root, abs).split(import_path18.sep).includes("..")) return;
|
|
15844
|
+
await (0, import_promises16.mkdir)((0, import_path18.join)(abs, ".."), { recursive: true });
|
|
15803
15845
|
await (0, import_promises16.writeFile)(abs, text3, { mode: 384 });
|
|
15804
15846
|
};
|
|
15805
15847
|
for (const f of p.files) {
|
|
@@ -15927,7 +15969,7 @@ function turnOffering(raw, loaded) {
|
|
|
15927
15969
|
mcpCatalog: loaded.catalog ? { ...loaded.catalog, servers: loaded.catalog.servers.filter((sv) => !connectors.has(sv.server.toLowerCase())) } : null,
|
|
15928
15970
|
mcpServers: Object.fromEntries(Object.entries(loaded.servers).filter(([key]) => !connectors.has(key.slice(ORG_MCP_PREFIX.length).toLowerCase()))),
|
|
15929
15971
|
skillEntries: loaded.skillEntries.filter((e) => !(e.source === "plugin" && e.plugin && plugins.has(e.plugin))),
|
|
15930
|
-
pluginDirs: loaded.pluginDirs.filter((d) => !plugins.has((0,
|
|
15972
|
+
pluginDirs: loaded.pluginDirs.filter((d) => !plugins.has((0, import_path19.basename)(d).toLowerCase()))
|
|
15931
15973
|
};
|
|
15932
15974
|
}
|
|
15933
15975
|
function sameModel(a, b) {
|
|
@@ -16325,7 +16367,7 @@ var WorkspaceEngine = class {
|
|
|
16325
16367
|
}
|
|
16326
16368
|
await this.backgroundOutputDir();
|
|
16327
16369
|
if (boot.plugins?.length) {
|
|
16328
|
-
this.orgPlugins = await buildOrganizationPlugins({ dir: (0,
|
|
16370
|
+
this.orgPlugins = await buildOrganizationPlugins({ dir: (0, import_path19.join)(this.deps.configDir, "sq-org-plugins"), plugins: boot.plugins }).catch((e) => {
|
|
16329
16371
|
this.deps.log.warn("organization plugins unavailable", { error: this.redactor.text(e.message) });
|
|
16330
16372
|
return { entries: [], dirs: [] };
|
|
16331
16373
|
});
|
|
@@ -16352,8 +16394,8 @@ var WorkspaceEngine = class {
|
|
|
16352
16394
|
}
|
|
16353
16395
|
/** Where a background command writes its output: inside the config dir, which Read may read. */
|
|
16354
16396
|
async backgroundOutputDir() {
|
|
16355
|
-
await (0, import_promises17.mkdir)((0,
|
|
16356
|
-
await (0, import_promises17.mkdir)((0,
|
|
16397
|
+
await (0, import_promises17.mkdir)((0, import_path19.join)(this.deps.configDir, "tmp"), { recursive: true, mode: 448 }).catch(() => void 0);
|
|
16398
|
+
await (0, import_promises17.mkdir)((0, import_path19.join)(this.deps.configDir, "plans"), { recursive: true, mode: 448 }).catch(() => void 0);
|
|
16357
16399
|
}
|
|
16358
16400
|
/** Runs until shutdown. */
|
|
16359
16401
|
async run() {
|
|
@@ -16382,7 +16424,7 @@ var WorkspaceEngine = class {
|
|
|
16382
16424
|
const repo2 = {
|
|
16383
16425
|
...r,
|
|
16384
16426
|
tracker: r.tracker ?? gitTracker(r.root, r.prepared.baseRevision, r.prefix),
|
|
16385
|
-
measurer: this.deps.createMeasurer && !this.local ? this.deps.createMeasurer(r.repoFullName ?? (0,
|
|
16427
|
+
measurer: this.deps.createMeasurer && !this.local ? this.deps.createMeasurer(r.repoFullName ?? (0, import_path19.basename)(r.root), r.root, this.baseStore(r.repoFullName), r.repoFullName) : null,
|
|
16386
16428
|
lastDiff: null
|
|
16387
16429
|
};
|
|
16388
16430
|
this.repos.set(r.root, repo2);
|
|
@@ -16411,14 +16453,14 @@ var WorkspaceEngine = class {
|
|
|
16411
16453
|
const short = folderName(lastSegment(repoFullName));
|
|
16412
16454
|
const full = folderName(repoFullName.split("/").filter(Boolean).join("__"));
|
|
16413
16455
|
const clash = this.scope.repos.some((r) => r.repoFullName !== repoFullName && folderName(lastSegment(r.repoFullName)) === short);
|
|
16414
|
-
const privateDirs = (this.deps.privateDirs ?? []).map((d) => (0,
|
|
16456
|
+
const privateDirs = (this.deps.privateDirs ?? []).map((d) => (0, import_path19.resolve)(d));
|
|
16415
16457
|
const taken = (name2) => {
|
|
16416
|
-
const dir = (0,
|
|
16417
|
-
return this.repos.has(dir) || privateDirs.includes(dir) || (0,
|
|
16458
|
+
const dir = (0, import_path19.resolve)(this.deps.root, name2);
|
|
16459
|
+
return this.repos.has(dir) || privateDirs.includes(dir) || (0, import_fs13.existsSync)(dir);
|
|
16418
16460
|
};
|
|
16419
16461
|
let name = clash || taken(short) ? full : short;
|
|
16420
16462
|
for (let n = 2; taken(name); n++) name = `${full}-${n}`;
|
|
16421
|
-
return (0,
|
|
16463
|
+
return (0, import_path19.join)(this.deps.root, name);
|
|
16422
16464
|
}
|
|
16423
16465
|
/** Clones one repository into its folder and registers it. The token is dropped either way. */
|
|
16424
16466
|
async cloneInto(access, onStep) {
|
|
@@ -16465,7 +16507,7 @@ var WorkspaceEngine = class {
|
|
|
16465
16507
|
}
|
|
16466
16508
|
if (open2.length === 1) return { repo: open2[0] };
|
|
16467
16509
|
if (!open2.length) return { error: "No repository is open in this workspace. Call list_repositories, then open_repository." };
|
|
16468
|
-
return { error: `Several repositories are open (${open2.map((o) => o.repoFullName ?? (0,
|
|
16510
|
+
return { error: `Several repositories are open (${open2.map((o) => o.repoFullName ?? (0, import_path19.basename)(o.root)).join(", ")}). Pass repoFullName.` };
|
|
16469
16511
|
}
|
|
16470
16512
|
notInScope(repo2, target) {
|
|
16471
16513
|
const loose = repo2.localId === LOOSE_REPO_ID;
|
|
@@ -16738,7 +16780,7 @@ var WorkspaceEngine = class {
|
|
|
16738
16780
|
PUB_CACHE: ".pub-cache",
|
|
16739
16781
|
BUNDLE_PATH: ".bundle"
|
|
16740
16782
|
};
|
|
16741
|
-
for (const [k, rel] of Object.entries(caches)) if (env[k] !== void 0) env[k] = (0,
|
|
16783
|
+
for (const [k, rel] of Object.entries(caches)) if (env[k] !== void 0) env[k] = (0, import_path19.join)(user.home, rel);
|
|
16742
16784
|
return {
|
|
16743
16785
|
file: user.shell,
|
|
16744
16786
|
args: ["-l"],
|
|
@@ -16753,8 +16795,8 @@ var WorkspaceEngine = class {
|
|
|
16753
16795
|
* (default ACL), never the engine's own folders (its state and transcripts stay root's, 0700).
|
|
16754
16796
|
*/
|
|
16755
16797
|
async shareWithTerminal(uid) {
|
|
16756
|
-
const root = (0,
|
|
16757
|
-
const own = new Set((this.deps.privateDirs ?? []).map((d) => (0,
|
|
16798
|
+
const root = (0, import_path19.resolve)(this.deps.root);
|
|
16799
|
+
const own = new Set((this.deps.privateDirs ?? []).map((d) => (0, import_path19.resolve)(d)));
|
|
16758
16800
|
for (const dir of own) await (0, import_promises17.chmod)(dir, 448).catch(() => void 0);
|
|
16759
16801
|
const acl = (args) => new Promise((done) => {
|
|
16760
16802
|
const child = (0, import_child_process5.spawn)("setfacl", args, { stdio: "ignore" });
|
|
@@ -16766,8 +16808,8 @@ var WorkspaceEngine = class {
|
|
|
16766
16808
|
this.terminalShared.add(root);
|
|
16767
16809
|
}
|
|
16768
16810
|
const sweep = Promise.all((await (0, import_promises17.readdir)(root).catch(() => [])).map(async (name) => {
|
|
16769
|
-
const path = (0,
|
|
16770
|
-
if (this.terminalShared.has(path) || own.has(path) || [...own].some((d) => d.startsWith(path +
|
|
16811
|
+
const path = (0, import_path19.join)(root, name);
|
|
16812
|
+
if (this.terminalShared.has(path) || own.has(path) || [...own].some((d) => d.startsWith(path + import_path19.sep))) return;
|
|
16771
16813
|
if (await acl(["-R", "-m", `u:${uid}:rwX`, "-m", `d:u:${uid}:rwX`, path])) this.terminalShared.add(path);
|
|
16772
16814
|
}));
|
|
16773
16815
|
await Promise.race([sweep, new Promise((r) => setTimeout(r, TERMINAL_SHARE_WAIT_MS).unref?.())]);
|
|
@@ -17084,7 +17126,7 @@ ${String(item.content)}` : String(item.content);
|
|
|
17084
17126
|
askQuestions: !!this.boot?.askQuestions
|
|
17085
17127
|
});
|
|
17086
17128
|
const conventions = await readConventions([...this.repos.values()].filter((r) => !r.dormant).flatMap((r) => {
|
|
17087
|
-
const label = r.repoFullName ?? r.localId ?? (0,
|
|
17129
|
+
const label = r.repoFullName ?? r.localId ?? (0, import_path19.basename)(r.root);
|
|
17088
17130
|
return r.fence && r.fence !== r.root ? [{ label, root: r.root }, { label: `${label} (${r.prefix})`, root: r.fence }] : [{ label, root: r.root }];
|
|
17089
17131
|
})).catch(() => []);
|
|
17090
17132
|
return base + conventionsSection(conventions);
|
|
@@ -17173,12 +17215,22 @@ ${String(item.content)}` : String(item.content);
|
|
|
17173
17215
|
const raw = this.boot?.runtime?.protections;
|
|
17174
17216
|
return raw ? parseProtections(raw) : NO_PROTECTIONS;
|
|
17175
17217
|
}
|
|
17218
|
+
/**
|
|
17219
|
+
* A protection refused an action: the API counts the decision (which rule, which kind of action), never the
|
|
17220
|
+
* command, the path or the text. What a protection holds for a person is the approval card itself, already kept.
|
|
17221
|
+
*/
|
|
17222
|
+
reportRefusal(reason, action) {
|
|
17223
|
+
const rule = PROTECTION_REASON_RULE[reason];
|
|
17224
|
+
if (!rule || rule === "tool-approval" || !this.deps.transport.reportProtectionDecisions) return;
|
|
17225
|
+
const policyVersion = protectionsWireOf(this.boot?.runtime?.protections)?.version ?? 0;
|
|
17226
|
+
void this.deps.transport.reportProtectionDecisions([{ id: (0, import_crypto9.randomUUID)(), action, rule, outcome: "BLOCKED", policyVersion, occurredAt: (/* @__PURE__ */ new Date()).toISOString() }]).catch(() => void 0);
|
|
17227
|
+
}
|
|
17176
17228
|
/** What the protections read from the workspace: the registries, the checked out branch, the installed packages. */
|
|
17177
17229
|
protectionDeps() {
|
|
17178
17230
|
return {
|
|
17179
17231
|
registry: this.registry,
|
|
17180
17232
|
currentBranch: async () => (await git(["rev-parse", "--abbrev-ref", "HEAD"], { cwd: this.deps.root, timeoutMs: 3e3 })).trim() || null,
|
|
17181
|
-
installedLocally: (name) => [this.deps.root, ...[...this.repos.values()].map((r) => r.root)].some((dir) => (0,
|
|
17233
|
+
installedLocally: (name) => [this.deps.root, ...[...this.repos.values()].map((r) => r.root)].some((dir) => (0, import_fs13.existsSync)((0, import_path19.join)(dir, "node_modules", name, "package.json")) || (0, import_fs13.existsSync)((0, import_path19.join)(dir, "node_modules", ".bin", name)))
|
|
17182
17234
|
};
|
|
17183
17235
|
}
|
|
17184
17236
|
/**
|
|
@@ -17285,7 +17337,7 @@ ${String(item.content)}` : String(item.content);
|
|
|
17285
17337
|
for (const repo2 of this.repos.values()) {
|
|
17286
17338
|
const tree = cp.trees.get(repo2.root);
|
|
17287
17339
|
if (!tree) {
|
|
17288
|
-
if (!repo2.dormant) untouched.push(repo2.repoFullName ?? repo2.localId ?? (0,
|
|
17340
|
+
if (!repo2.dormant) untouched.push(repo2.repoFullName ?? repo2.localId ?? (0, import_path19.basename)(repo2.root));
|
|
17289
17341
|
continue;
|
|
17290
17342
|
}
|
|
17291
17343
|
try {
|
|
@@ -17321,7 +17373,7 @@ ${String(item.content)}` : String(item.content);
|
|
|
17321
17373
|
return;
|
|
17322
17374
|
}
|
|
17323
17375
|
const repo2 = picked.repo;
|
|
17324
|
-
const label = repo2.repoFullName ?? repo2.localId ?? (0,
|
|
17376
|
+
const label = repo2.repoFullName ?? repo2.localId ?? (0, import_path19.basename)(repo2.root);
|
|
17325
17377
|
const cwd = repo2.fence ?? repo2.root;
|
|
17326
17378
|
const detected = (this.deps.detectTests ? await this.deps.detectTests(cwd).catch(() => null) : null) ?? await detectTestCommandFromManifests(cwd).catch(() => null);
|
|
17327
17379
|
if (!detected) {
|
|
@@ -17418,9 +17470,9 @@ ${String(item.content)}` : String(item.content);
|
|
|
17418
17470
|
}
|
|
17419
17471
|
/** A file the person attached, saved whole in the engine's own folder (the file tools read there, nothing writes there). */
|
|
17420
17472
|
async saveAttachment(name, bytes) {
|
|
17421
|
-
const dir = (0,
|
|
17473
|
+
const dir = (0, import_path19.join)(this.deps.configDir, "attachments", (0, import_crypto9.randomUUID)());
|
|
17422
17474
|
await (0, import_promises17.mkdir)(dir, { recursive: true });
|
|
17423
|
-
const path = (0,
|
|
17475
|
+
const path = (0, import_path19.join)(dir, (0, import_path19.basename)(name ?? "").replace(/[\u0000-\u001f\\/:]/g, "_").replace(/^\.+/, "") || "attachment");
|
|
17424
17476
|
await (0, import_promises17.writeFile)(path, bytes);
|
|
17425
17477
|
return path;
|
|
17426
17478
|
}
|
|
@@ -17559,7 +17611,7 @@ ${json}
|
|
|
17559
17611
|
}
|
|
17560
17612
|
/** The plugin with the repositories' and the organization's skills, rebuilt; the list goes to the screen when it changed. */
|
|
17561
17613
|
async refreshSkills() {
|
|
17562
|
-
const repos = [...this.repos.values()].filter((r) => !r.dormant).map((r) => ({ label: r.repoFullName ?? r.localId ?? (0,
|
|
17614
|
+
const repos = [...this.repos.values()].filter((r) => !r.dormant).map((r) => ({ label: r.repoFullName ?? r.localId ?? (0, import_path19.basename)(r.root), root: r.fence ?? r.root }));
|
|
17563
17615
|
try {
|
|
17564
17616
|
this.skillEntries = [...await buildSkillsPlugin({ dir: this.skillsDir(), repos, organization: this.boot?.skills ?? [] }), ...this.orgPlugins.entries];
|
|
17565
17617
|
} catch (e) {
|
|
@@ -17572,7 +17624,7 @@ ${json}
|
|
|
17572
17624
|
this.emit({ type: "skills", data: { skills: this.skillEntries } });
|
|
17573
17625
|
}
|
|
17574
17626
|
skillsDir() {
|
|
17575
|
-
return (0,
|
|
17627
|
+
return (0, import_path19.join)(this.deps.configDir, "sq-plugin");
|
|
17576
17628
|
}
|
|
17577
17629
|
/**
|
|
17578
17630
|
* The organization's MCP servers (their tools, from the API): one in-process server each, forwarding calls to
|
|
@@ -17623,7 +17675,7 @@ ${json}
|
|
|
17623
17675
|
}
|
|
17624
17676
|
}
|
|
17625
17677
|
async runEnvSetup(repo2, command, secrets) {
|
|
17626
|
-
const label = repo2.repoFullName ?? (0,
|
|
17678
|
+
const label = repo2.repoFullName ?? (0, import_path19.basename)(repo2.root);
|
|
17627
17679
|
const step = this.ownStep("setup", "command", `Preparing the environment of ${label}`, "STEP_ENV_SETUP", { repoFullName: label }, this.redactor.text(command));
|
|
17628
17680
|
const started = Date.now();
|
|
17629
17681
|
const { exitCode, output } = await this.runStreaming(command, repo2.fence ?? repo2.root, step.id, this.envAbort.signal, secrets);
|
|
@@ -18130,7 +18182,7 @@ ${text3}`;
|
|
|
18130
18182
|
deniedRoots: this.deps.privateDirs,
|
|
18131
18183
|
local: this.local,
|
|
18132
18184
|
plan: t.planMode,
|
|
18133
|
-
planDir: (0,
|
|
18185
|
+
planDir: (0, import_path19.join)(this.deps.configDir, "plans"),
|
|
18134
18186
|
orgMcpTools: orgMcpToolNames(org ? t.off.mcpCatalog : null)
|
|
18135
18187
|
},
|
|
18136
18188
|
plan: t.planMode,
|
|
@@ -18172,6 +18224,7 @@ ${text3}`;
|
|
|
18172
18224
|
secretFiles: i.secretFiles,
|
|
18173
18225
|
protections: () => this.protections(),
|
|
18174
18226
|
protection: { deps: this.protectionDeps(), approver: this.protectionApprover() },
|
|
18227
|
+
onRefused: (reason, action) => this.reportRefusal(reason, action),
|
|
18175
18228
|
...this.deps.talkFirst ? { talkFirst: (name, toolUseId) => this.talkFirst(name, toolUseId) } : {},
|
|
18176
18229
|
beforeTool: async () => {
|
|
18177
18230
|
const t0 = Date.now();
|
|
@@ -18338,8 +18391,8 @@ ${text3}`;
|
|
|
18338
18391
|
const keptDesign = this.deps.transport.keptDesign?.bind(this.deps.transport);
|
|
18339
18392
|
if (!keptDesign) return;
|
|
18340
18393
|
for (const d of boot.keptDesigns ?? []) {
|
|
18341
|
-
if (!/^design\/[^/]+\/design\.json$/.test(d.path) || this.repos.has((0,
|
|
18342
|
-
if ((0,
|
|
18394
|
+
if (!/^design\/[^/]+\/design\.json$/.test(d.path) || this.repos.has((0, import_path19.join)(this.deps.root, "design"))) continue;
|
|
18395
|
+
if ((0, import_fs13.existsSync)((0, import_path19.join)(this.deps.root, d.path))) continue;
|
|
18343
18396
|
try {
|
|
18344
18397
|
const kept = await keptDesign(d.path);
|
|
18345
18398
|
const written = kept ? await restoreKeptDesign(this.deps.root, d.path, kept.files) : 0;
|
|
@@ -18479,7 +18532,7 @@ ${patch}`;
|
|
|
18479
18532
|
this.pendingCheckpoints.delete(repo2.localId);
|
|
18480
18533
|
repo2.dormant = !repo2.unsaved;
|
|
18481
18534
|
}
|
|
18482
|
-
const stateDir = this.deps.stateDir ?? (0,
|
|
18535
|
+
const stateDir = this.deps.stateDir ?? (0, import_path19.join)(this.deps.scratch, `folder-${(0, import_crypto9.createHash)("sha256").update(local.root).digest("hex").slice(0, 16)}`);
|
|
18483
18536
|
const tracker = new LooseFileTracker({ root: local.root, stateDir, excluded: () => local.repos.map((r) => r.root) });
|
|
18484
18537
|
const tracked = local.gitAvailable && await tracker.init().then(() => true, (e) => {
|
|
18485
18538
|
this.deps.log.warn("loose files not tracked", { error: e.message });
|
|
@@ -18531,7 +18584,7 @@ ${patch}`;
|
|
|
18531
18584
|
let owner = null;
|
|
18532
18585
|
for (const r of this.repos.values()) {
|
|
18533
18586
|
if (r.localId === LOOSE_REPO_ID) continue;
|
|
18534
|
-
if ((abs === r.root || abs.startsWith(r.root +
|
|
18587
|
+
if ((abs === r.root || abs.startsWith(r.root + import_path19.sep)) && (!owner || r.root.length > owner.root.length)) owner = r;
|
|
18535
18588
|
}
|
|
18536
18589
|
if (owner) {
|
|
18537
18590
|
if (owner.dormant) await this.wake(owner, true);
|
|
@@ -18570,7 +18623,7 @@ ${patch}`;
|
|
|
18570
18623
|
if (!f || f.kind === "repo") return void 0;
|
|
18571
18624
|
if (f.kind === "subfolder") return { kind: "subfolder", repoRoot: f.repoRoot ?? "", prefix: f.prefix };
|
|
18572
18625
|
const repos = [...this.repos.values()].filter((r) => r.localId && r.localId !== LOOSE_REPO_ID).map((r) => ({
|
|
18573
|
-
path: (0,
|
|
18626
|
+
path: (0, import_path19.relative)(f.root, r.root).split(import_path19.sep).join("/"),
|
|
18574
18627
|
id: r.repoFullName ?? r.localId,
|
|
18575
18628
|
repoFullName: r.repoFullName,
|
|
18576
18629
|
projectId: r.repoFullName ? this.scope.repos.find((x) => x.repoFullName === r.repoFullName)?.projectId ?? null : null,
|
|
@@ -18647,13 +18700,13 @@ ${patch}`;
|
|
|
18647
18700
|
let bytes = 0;
|
|
18648
18701
|
const NAME2 = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
|
|
18649
18702
|
const top = await (0, import_promises17.readdir)(folder, { withFileTypes: true }).catch(() => []);
|
|
18650
|
-
const nested = await Promise.all(top.filter((e) => e.isDirectory() && NAME2.test(e.name)).slice(0, 10).map(async (d) => (await (0, import_promises17.readdir)((0,
|
|
18703
|
+
const nested = await Promise.all(top.filter((e) => e.isDirectory() && NAME2.test(e.name)).slice(0, 10).map(async (d) => (await (0, import_promises17.readdir)((0, import_path19.join)(folder, d.name), { withFileTypes: true }).catch(() => [])).filter((e) => e.isFile() && NAME2.test(e.name)).map((e) => `${d.name}/${e.name}`)));
|
|
18651
18704
|
const rank = (n) => n === "design.json" ? 0 : n.includes("/") ? 2 : 1;
|
|
18652
18705
|
const names = [...top.filter((e) => e.isFile() && NAME2.test(e.name)).map((e) => e.name), ...nested.flat()].sort((a, b) => rank(a) - rank(b) || a.localeCompare(b)).slice(0, 60);
|
|
18653
18706
|
for (const name of names) {
|
|
18654
|
-
const st = await (0, import_promises17.stat)((0,
|
|
18707
|
+
const st = await (0, import_promises17.stat)((0, import_path19.join)(folder, name)).catch(() => null);
|
|
18655
18708
|
if (!st || st.size > 4 * 1024 * 1024 || bytes + st.size > 6 * 1024 * 1024) continue;
|
|
18656
|
-
const data = await (0, import_promises17.readFile)((0,
|
|
18709
|
+
const data = await (0, import_promises17.readFile)((0, import_path19.join)(folder, name)).catch(() => null);
|
|
18657
18710
|
if (!data) continue;
|
|
18658
18711
|
bytes += data.length;
|
|
18659
18712
|
files.push({ name, data: data.toString("base64") });
|
|
@@ -18703,14 +18756,14 @@ ${patch}`;
|
|
|
18703
18756
|
const chrome = findChrome();
|
|
18704
18757
|
if (!chrome) return text("No Chrome or Chromium is installed here, so no screenshot was taken. The user sees the app in the conversation when you write ; say so in one sentence.", true);
|
|
18705
18758
|
try {
|
|
18706
|
-
await (0, import_promises17.mkdir)((0,
|
|
18759
|
+
await (0, import_promises17.mkdir)((0, import_path19.dirname)(target), { recursive: true });
|
|
18707
18760
|
await screenshotPage(chrome, args.url, target, { width: args.width ?? 1280, height: args.height ?? 800 });
|
|
18708
18761
|
} catch (e) {
|
|
18709
18762
|
this.deps.log.warn("app screenshot failed", { error: this.redactor.text(e.message) });
|
|
18710
18763
|
return text(`The screenshot of ${args.url} failed: is the app running there? Start it in the background and try again.`, true);
|
|
18711
18764
|
}
|
|
18712
18765
|
this.scheduleDiff();
|
|
18713
|
-
const rel = (0,
|
|
18766
|
+
const rel = (0, import_path19.relative)(await (0, import_promises17.realpath)(this.deps.root).catch(() => this.deps.root), target).split(import_path19.sep).join("/");
|
|
18714
18767
|
return text(`Saved the screenshot to ${rel}. Read it to see the app, and show it as  when it helps the user.`);
|
|
18715
18768
|
}
|
|
18716
18769
|
async searchWeb(query) {
|
|
@@ -18748,7 +18801,7 @@ ${sources}` : ""}`);
|
|
|
18748
18801
|
try {
|
|
18749
18802
|
const image = await readImageFile(root, await insideRelative(args.editPath, [root]), this.deps.privateDirs ?? []);
|
|
18750
18803
|
if (!["image/png", "image/jpeg", "image/webp"].includes(image.mime)) return text(`${args.editPath} is not a PNG, JPEG or WebP image, so it cannot be changed. Nothing was created.`, true);
|
|
18751
|
-
reference = { name: (0,
|
|
18804
|
+
reference = { name: (0, import_path19.basename)(image.path), mimeType: image.mime, sizeBytes: image.size, dataBase64: image.data };
|
|
18752
18805
|
} catch (e) {
|
|
18753
18806
|
return text(`Could not read ${args.editPath} to change it (${e instanceof FileRequestError ? e.code : "UNREADABLE"}). Nothing was created.`, true);
|
|
18754
18807
|
}
|
|
@@ -18763,10 +18816,10 @@ ${sources}` : ""}`);
|
|
|
18763
18816
|
if ("refused" in created) return text(`The image could not be created (${created.refused}). Tell the user plainly in one sentence; do not claim an image was made and do not offer a prompt for another tool instead.`, true);
|
|
18764
18817
|
const bytes = Buffer.from(created.dataBase64, "base64");
|
|
18765
18818
|
if (!bytes.length || !imageMime(bytes)) return text("The image model returned something that is not an image. Nothing was saved.", true);
|
|
18766
|
-
await (0, import_promises17.mkdir)((0,
|
|
18819
|
+
await (0, import_promises17.mkdir)((0, import_path19.dirname)(target), { recursive: true });
|
|
18767
18820
|
await (0, import_promises17.writeFile)(target, bytes);
|
|
18768
18821
|
this.scheduleDiff();
|
|
18769
|
-
const rel = (0,
|
|
18822
|
+
const rel = (0, import_path19.relative)(await (0, import_promises17.realpath)(root).catch(() => root), target).split(import_path19.sep).join("/");
|
|
18770
18823
|
return text(`Saved the image to ${rel}. Show it to the user in your answer as  and say in one or two sentences what you made.`);
|
|
18771
18824
|
}
|
|
18772
18825
|
listRepositories() {
|
|
@@ -18845,7 +18898,7 @@ ${JSON.stringify(data, null, 1)}`);
|
|
|
18845
18898
|
const repo2 = picked.repo;
|
|
18846
18899
|
const refused = this.notInScope(repo2);
|
|
18847
18900
|
if (refused) {
|
|
18848
|
-
say2("REPOSITORY_NOT_IN_SCOPE", { repoFullName: repo2.repoFullName ?? (0,
|
|
18901
|
+
say2("REPOSITORY_NOT_IN_SCOPE", { repoFullName: repo2.repoFullName ?? (0, import_path19.basename)(repo2.root) });
|
|
18849
18902
|
return text(refused, true);
|
|
18850
18903
|
}
|
|
18851
18904
|
if (!repo2.measurer) {
|
|
@@ -18866,7 +18919,7 @@ ${JSON.stringify(data, null, 1)}`);
|
|
|
18866
18919
|
return text("The measurement did not finish in time. Say it was not measured; do not estimate.", true);
|
|
18867
18920
|
}
|
|
18868
18921
|
if ("empty" in r) {
|
|
18869
|
-
say2("NOTHING_TO_MEASURE", { repoFullName: repo2.repoFullName ?? (0,
|
|
18922
|
+
say2("NOTHING_TO_MEASURE", { repoFullName: repo2.repoFullName ?? (0, import_path19.basename)(repo2.root) });
|
|
18870
18923
|
return text(`There is no change in ${repo2.repoFullName} to measure.`);
|
|
18871
18924
|
}
|
|
18872
18925
|
this.emit({ type: "measurement", data: { ...r.data, ...repo2.repoFullName ? { repoFullName: repo2.repoFullName } : {} } });
|
|
@@ -19088,7 +19141,7 @@ function buildEngineEnv(boot, configDir, model, opts = {}) {
|
|
|
19088
19141
|
Object.assign(env, {
|
|
19089
19142
|
CLAUDE_CONFIG_DIR: configDir,
|
|
19090
19143
|
// Background command output lands here, inside the config dir the policy lets Read read.
|
|
19091
|
-
CLAUDE_CODE_TMPDIR: (0,
|
|
19144
|
+
CLAUDE_CODE_TMPDIR: (0, import_path19.join)(configDir, "tmp"),
|
|
19092
19145
|
CLAUDE_AGENT_SDK_CLIENT_APP: opts.local ? "scalequality-cli-connect/1.0" : "scalequality-workspace/1.0",
|
|
19093
19146
|
DISABLE_TELEMETRY: "1",
|
|
19094
19147
|
DISABLE_ERROR_REPORTING: "1",
|
|
@@ -19118,6 +19171,13 @@ function buildEngineEnv(boot, configDir, model, opts = {}) {
|
|
|
19118
19171
|
return env;
|
|
19119
19172
|
}
|
|
19120
19173
|
function buildQueryOptions(o) {
|
|
19174
|
+
const refused = (reason, action) => {
|
|
19175
|
+
if (!reason || !o.onRefused) return;
|
|
19176
|
+
try {
|
|
19177
|
+
o.onRefused(reason, action);
|
|
19178
|
+
} catch {
|
|
19179
|
+
}
|
|
19180
|
+
};
|
|
19121
19181
|
const gate = o.commandGate;
|
|
19122
19182
|
const beforeWrite = async (name, input) => {
|
|
19123
19183
|
const field = WRITE_TOOL_PATHS[name];
|
|
@@ -19148,6 +19208,7 @@ function buildQueryOptions(o) {
|
|
|
19148
19208
|
const d = await decideToolUse(name, input.tool_input ?? {}, { ...o.policy, protections });
|
|
19149
19209
|
const guarded = d.behavior === "allow" && (name === "Bash" && mayNeedProtection(String(d.updatedInput.command ?? ""), protections) || protections.toolApproval && !o.plan && name in WRITE_TOOL_PATHS);
|
|
19150
19210
|
const gated = guarded || d.behavior === "allow" && !!gate && (name === "Bash" || !!gate.checkEdit && !o.plan && name in WRITE_TOOL_PATHS);
|
|
19211
|
+
if (d.behavior !== "allow") refused(d.reason, name === "Bash" ? "COMMAND" : "FILE");
|
|
19151
19212
|
if (d.behavior === "allow" && !gated) await beforeWrite(name, d.updatedInput);
|
|
19152
19213
|
if (gated) {
|
|
19153
19214
|
return { hookSpecificOutput: { hookEventName: "PreToolUse", permissionDecision: "ask", permissionDecisionReason: guarded ? "This action follows the organization's protections." : "Commands and changes on this machine follow the person's permission mode." } };
|
|
@@ -19172,14 +19233,20 @@ function buildQueryOptions(o) {
|
|
|
19172
19233
|
}
|
|
19173
19234
|
const protections = o.protections?.() ?? NO_PROTECTIONS;
|
|
19174
19235
|
const d = await decideToolUse(toolName, input, { ...o.policy, protections });
|
|
19175
|
-
if (d.behavior !== "allow")
|
|
19236
|
+
if (d.behavior !== "allow") {
|
|
19237
|
+
refused(d.reason, toolName === "Bash" ? "COMMAND" : "FILE");
|
|
19238
|
+
return { behavior: "deny", message: d.message };
|
|
19239
|
+
}
|
|
19176
19240
|
let protectionApproved = false;
|
|
19177
19241
|
if (toolName === "Bash" && mayNeedProtection(String(d.updatedInput.command ?? ""), protections)) {
|
|
19178
19242
|
const command = String(d.updatedInput.command ?? "");
|
|
19179
19243
|
const signal = opts?.signal ?? o.abortController.signal;
|
|
19180
19244
|
if (!o.protection) return { behavior: "deny", message: PROTECTION_MESSAGES.unavailable };
|
|
19181
19245
|
const v = await protectionVerdict(command, protections, o.protection.deps);
|
|
19182
|
-
if (v.kind === "deny")
|
|
19246
|
+
if (v.kind === "deny") {
|
|
19247
|
+
refused(v.reason, v.reason === "PROTECTION_UNKNOWN_PACKAGE" ? "PACKAGE" : "COMMAND");
|
|
19248
|
+
return { behavior: "deny", message: v.message };
|
|
19249
|
+
}
|
|
19183
19250
|
if (v.kind === "ask") {
|
|
19184
19251
|
const approver = o.protection.approver;
|
|
19185
19252
|
const r = approver ? await approver.ask(command, {
|
|
@@ -19195,7 +19262,7 @@ function buildQueryOptions(o) {
|
|
|
19195
19262
|
const changes = !o.plan && toolName in WRITE_TOOL_PATHS;
|
|
19196
19263
|
const changePath = () => {
|
|
19197
19264
|
const field = WRITE_TOOL_PATHS[toolName];
|
|
19198
|
-
return typeof d.updatedInput[field] === "string" ? (0,
|
|
19265
|
+
return typeof d.updatedInput[field] === "string" ? (0, import_path19.relative)(o.root, d.updatedInput[field]) || String(d.updatedInput[field]) : "";
|
|
19199
19266
|
};
|
|
19200
19267
|
if (changes && protections.toolApproval) {
|
|
19201
19268
|
const path = changePath(), askEdit = o.protection?.approver?.askEdit;
|
|
@@ -19272,15 +19339,15 @@ function timedGate(gate, took) {
|
|
|
19272
19339
|
}
|
|
19273
19340
|
async function hasLocalTranscript(configDir, sessionId) {
|
|
19274
19341
|
if (!/^[A-Za-z0-9-]{8,80}$/.test(sessionId)) return false;
|
|
19275
|
-
const projects = (0,
|
|
19342
|
+
const projects = (0, import_path19.join)(configDir, "projects");
|
|
19276
19343
|
const dirs = await (0, import_promises17.readdir)(projects).catch(() => []);
|
|
19277
|
-
return dirs.some((d) => (0,
|
|
19344
|
+
return dirs.some((d) => (0, import_fs13.existsSync)((0, import_path19.join)(projects, d, `${sessionId}.jsonl`)));
|
|
19278
19345
|
}
|
|
19279
19346
|
|
|
19280
19347
|
// src/application/services/workspaceSandbox/selfUpdate.ts
|
|
19281
19348
|
var import_crypto10 = require("crypto");
|
|
19282
|
-
var
|
|
19283
|
-
var
|
|
19349
|
+
var import_fs14 = require("fs");
|
|
19350
|
+
var import_path20 = require("path");
|
|
19284
19351
|
var REGISTRY_LATEST = "https://registry.npmjs.org/@scalequality%2fcli/latest";
|
|
19285
19352
|
var UPDATE_FIRST_CHECK_MS = 2 * 6e4;
|
|
19286
19353
|
var UPDATE_INTERVAL_MS = 6 * 36e5;
|
|
@@ -19289,13 +19356,13 @@ var UPDATE_RETRY_MS = 15 * 6e4;
|
|
|
19289
19356
|
var CONFIRM_AFTER_MS = 9e4;
|
|
19290
19357
|
var RESTART_EXIT_CODE = 75;
|
|
19291
19358
|
var MAX_START_ATTEMPTS = 3;
|
|
19292
|
-
var cliDir = (home) => (0,
|
|
19293
|
-
var launcherPath = (home) => (0,
|
|
19294
|
-
var currentPath = (home) => (0,
|
|
19295
|
-
var autoUpdateOffPath = (home) => (0,
|
|
19296
|
-
var
|
|
19359
|
+
var cliDir = (home) => (0, import_path20.join)(sqHome(home), "cli");
|
|
19360
|
+
var launcherPath = (home) => (0, import_path20.join)(cliDir(home), "launcher.mjs");
|
|
19361
|
+
var currentPath = (home) => (0, import_path20.join)(cliDir(home), "current.json");
|
|
19362
|
+
var autoUpdateOffPath = (home) => (0, import_path20.join)(cliDir(home), "auto-update-off");
|
|
19363
|
+
var VERSION2 = /^(\d{1,5})\.(\d{1,5})\.(\d{1,5})$/;
|
|
19297
19364
|
function isNewer(candidate, current) {
|
|
19298
|
-
const a =
|
|
19365
|
+
const a = VERSION2.exec(candidate), b = VERSION2.exec(current);
|
|
19299
19366
|
if (!a || !b) return false;
|
|
19300
19367
|
for (let i = 1; i <= 3; i++) {
|
|
19301
19368
|
const d = Number(a[i]) - Number(b[i]);
|
|
@@ -19305,18 +19372,18 @@ function isNewer(candidate, current) {
|
|
|
19305
19372
|
}
|
|
19306
19373
|
function readJson2(file) {
|
|
19307
19374
|
try {
|
|
19308
|
-
const v = JSON.parse((0,
|
|
19375
|
+
const v = JSON.parse((0, import_fs14.readFileSync)(file, "utf8"));
|
|
19309
19376
|
return v && typeof v === "object" ? v : null;
|
|
19310
19377
|
} catch {
|
|
19311
19378
|
return null;
|
|
19312
19379
|
}
|
|
19313
19380
|
}
|
|
19314
19381
|
function writeJsonAtomic(file, value) {
|
|
19315
|
-
(0,
|
|
19382
|
+
(0, import_fs14.mkdirSync)((0, import_path20.dirname)(file), { recursive: true, mode: 448 });
|
|
19316
19383
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
19317
|
-
(0,
|
|
19384
|
+
(0, import_fs14.writeFileSync)(tmp, `${JSON.stringify(value, null, 2)}
|
|
19318
19385
|
`, { mode: 384 });
|
|
19319
|
-
(0,
|
|
19386
|
+
(0, import_fs14.renameSync)(tmp, file);
|
|
19320
19387
|
}
|
|
19321
19388
|
var installed = (v) => {
|
|
19322
19389
|
const r = v;
|
|
@@ -19372,8 +19439,8 @@ function installLauncher(home, copy) {
|
|
|
19372
19439
|
writeJsonAtomic(currentPath(home), { version: copy.version, bin: copy.bin, previous: null, pending: false, attempts: 0, rejected: current?.rejected ?? [] });
|
|
19373
19440
|
const file = launcherPath(home);
|
|
19374
19441
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
19375
|
-
(0,
|
|
19376
|
-
(0,
|
|
19442
|
+
(0, import_fs14.writeFileSync)(tmp, launcherSource(copy.bin), { mode: 420 });
|
|
19443
|
+
(0, import_fs14.renameSync)(tmp, file);
|
|
19377
19444
|
return file;
|
|
19378
19445
|
}
|
|
19379
19446
|
function confirmCurrent(home, version) {
|
|
@@ -19385,17 +19452,17 @@ function confirmCurrent(home, version) {
|
|
|
19385
19452
|
}
|
|
19386
19453
|
function behindCurrent(home, version) {
|
|
19387
19454
|
const current = readCurrent(home);
|
|
19388
|
-
if (!current || current.pending || current.version === version || !isNewer(current.version, version) || !(0,
|
|
19455
|
+
if (!current || current.pending || current.version === version || !isNewer(current.version, version) || !(0, import_fs14.existsSync)(current.bin)) return null;
|
|
19389
19456
|
return current.version;
|
|
19390
19457
|
}
|
|
19391
19458
|
function autoUpdateEnabled(home, env) {
|
|
19392
|
-
return env.SCALEQUALITY_NO_AUTO_UPDATE !== "1" && !(0,
|
|
19459
|
+
return env.SCALEQUALITY_NO_AUTO_UPDATE !== "1" && !(0, import_fs14.existsSync)(autoUpdateOffPath(home));
|
|
19393
19460
|
}
|
|
19394
19461
|
function setAutoUpdate(home, on) {
|
|
19395
|
-
if (on) (0,
|
|
19462
|
+
if (on) (0, import_fs14.rmSync)(autoUpdateOffPath(home), { force: true });
|
|
19396
19463
|
else {
|
|
19397
|
-
(0,
|
|
19398
|
-
(0,
|
|
19464
|
+
(0, import_fs14.mkdirSync)(cliDir(home), { recursive: true, mode: 448 });
|
|
19465
|
+
(0, import_fs14.writeFileSync)(autoUpdateOffPath(home), `${(/* @__PURE__ */ new Date()).toISOString()}
|
|
19399
19466
|
`, { mode: 384 });
|
|
19400
19467
|
}
|
|
19401
19468
|
}
|
|
@@ -19404,25 +19471,25 @@ async function latestVersion(fetchImpl = fetch) {
|
|
|
19404
19471
|
const res = await fetchImpl(REGISTRY_LATEST, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(15e3) });
|
|
19405
19472
|
if (!res.ok) return null;
|
|
19406
19473
|
const body = await res.json();
|
|
19407
|
-
return body?.name === "@scalequality/cli" && typeof body.version === "string" &&
|
|
19474
|
+
return body?.name === "@scalequality/cli" && typeof body.version === "string" && VERSION2.test(body.version) ? body.version : null;
|
|
19408
19475
|
} catch {
|
|
19409
19476
|
return null;
|
|
19410
19477
|
}
|
|
19411
19478
|
}
|
|
19412
|
-
function npmCli(nodePath, exists =
|
|
19413
|
-
const dir = (0,
|
|
19479
|
+
function npmCli(nodePath, exists = import_fs14.existsSync, resolve8 = realOrNull, pathEnv = process.env.PATH ?? "") {
|
|
19480
|
+
const dir = (0, import_path20.dirname)(nodePath);
|
|
19414
19481
|
const script = (p) => p && /npm-cli\.js$/.test(p) && exists(p) ? p : null;
|
|
19415
19482
|
const linked = (p) => exists(p) ? script(resolve8(p)) : null;
|
|
19416
19483
|
const layouts = [
|
|
19417
|
-
(0,
|
|
19418
|
-
(0,
|
|
19419
|
-
(0,
|
|
19484
|
+
(0, import_path20.join)(dir, "node_modules", "npm", "bin", "npm-cli.js"),
|
|
19485
|
+
(0, import_path20.join)(dir, "..", "lib", "node_modules", "npm", "bin", "npm-cli.js"),
|
|
19486
|
+
(0, import_path20.join)(dir, "..", "libexec", "lib", "node_modules", "npm", "bin", "npm-cli.js")
|
|
19420
19487
|
];
|
|
19421
|
-
return linked((0,
|
|
19488
|
+
return linked((0, import_path20.join)(dir, "npm")) ?? layouts.map(script).find(Boolean) ?? pathEnv.split(import_path20.delimiter).filter(Boolean).map((d) => linked((0, import_path20.join)(d, "npm"))).find(Boolean) ?? null;
|
|
19422
19489
|
}
|
|
19423
19490
|
function realOrNull(p) {
|
|
19424
19491
|
try {
|
|
19425
|
-
return (0,
|
|
19492
|
+
return (0, import_fs14.realpathSync)(p);
|
|
19426
19493
|
} catch {
|
|
19427
19494
|
return null;
|
|
19428
19495
|
}
|
|
@@ -19442,11 +19509,11 @@ function npmReason(output) {
|
|
|
19442
19509
|
async function installVersion(o) {
|
|
19443
19510
|
const npm = o.npm === void 0 ? npmCli(o.nodePath) : o.npm;
|
|
19444
19511
|
if (!npm) throw new UpdateError("NPM_NOT_FOUND", `npm was not found next to ${o.nodePath}.`);
|
|
19445
|
-
const staging = (0,
|
|
19446
|
-
(0,
|
|
19447
|
-
(0,
|
|
19512
|
+
const staging = (0, import_path20.join)(cliDir(o.home), `.update-${o.version}`);
|
|
19513
|
+
(0, import_fs14.rmSync)(staging, { recursive: true, force: true });
|
|
19514
|
+
(0, import_fs14.mkdirSync)(staging, { recursive: true, mode: 448 });
|
|
19448
19515
|
try {
|
|
19449
|
-
(0,
|
|
19516
|
+
(0, import_fs14.writeFileSync)((0, import_path20.join)(staging, "package.json"), '{ "private": true }\n');
|
|
19450
19517
|
const r = await o.run(o.nodePath, [
|
|
19451
19518
|
npm,
|
|
19452
19519
|
"install",
|
|
@@ -19461,12 +19528,12 @@ async function installVersion(o) {
|
|
|
19461
19528
|
`@scalequality/cli@${o.version}`
|
|
19462
19529
|
]);
|
|
19463
19530
|
if (r.code !== 0) throw new UpdateError("NPM_INSTALL_FAILED", `npm could not install @scalequality/cli@${o.version}: ${npmReason(`${r.stderr || r.stdout}`) || r.code}`);
|
|
19464
|
-
const root = (0,
|
|
19465
|
-
const pkg = readJson2((0,
|
|
19531
|
+
const root = (0, import_path20.join)(staging, "node_modules", "@scalequality", "cli");
|
|
19532
|
+
const pkg = readJson2((0, import_path20.join)(root, "package.json"));
|
|
19466
19533
|
if (pkg?.name !== "@scalequality/cli" || pkg?.version !== o.version) throw new UpdateError("WRONG_PACKAGE", `npm installed ${String(pkg?.name)}@${String(pkg?.version)} instead of ${o.version}.`);
|
|
19467
|
-
const build = readJson2((0,
|
|
19468
|
-
const bundle = (0,
|
|
19469
|
-
const sha = (0,
|
|
19534
|
+
const build = readJson2((0, import_path20.join)(root, "dist", "connect.build.json"));
|
|
19535
|
+
const bundle = (0, import_path20.join)(root, "dist", "connect.cjs");
|
|
19536
|
+
const sha = (0, import_fs14.existsSync)(bundle) ? (0, import_crypto10.createHash)("sha256").update((0, import_fs14.readFileSync)(bundle)).digest("hex") : null;
|
|
19470
19537
|
if (!sha || typeof build?.sha256 !== "string" || build.sha256 !== sha) throw new UpdateError("BUNDLE_MISMATCH", `The engine of ${o.version} does not match the sha256 it declares.`);
|
|
19471
19538
|
let copy;
|
|
19472
19539
|
try {
|
|
@@ -19476,7 +19543,7 @@ async function installVersion(o) {
|
|
|
19476
19543
|
}
|
|
19477
19544
|
return { version: copy.version, bin: copy.bin };
|
|
19478
19545
|
} finally {
|
|
19479
|
-
(0,
|
|
19546
|
+
(0, import_fs14.rmSync)(staging, { recursive: true, force: true });
|
|
19480
19547
|
}
|
|
19481
19548
|
}
|
|
19482
19549
|
function stageVersion(home, next, running) {
|
|
@@ -19509,6 +19576,364 @@ async function checkForUpdate(d) {
|
|
|
19509
19576
|
|
|
19510
19577
|
// src/main/workspace-connect.ts
|
|
19511
19578
|
var import_child_process6 = require("child_process");
|
|
19579
|
+
|
|
19580
|
+
// src/application/services/workspaceSandbox/codeAgentHook.ts
|
|
19581
|
+
var import_crypto11 = require("crypto");
|
|
19582
|
+
var import_fs15 = require("fs");
|
|
19583
|
+
var import_path21 = require("path");
|
|
19584
|
+
var CLAUDE_CODE_TOOLS = ["Bash", "Read", "Write", "Edit", "MultiEdit", "NotebookEdit", "Grep", "Glob"];
|
|
19585
|
+
var OUTBOX_MAX_BYTES = 512 * 1024;
|
|
19586
|
+
var agentsDir = (sqHome2) => (0, import_path21.join)(sqHome2, "agents");
|
|
19587
|
+
var policyPath = (sqHome2) => (0, import_path21.join)(agentsDir(sqHome2), "policy.json");
|
|
19588
|
+
var outboxDir = (sqHome2) => (0, import_path21.join)(agentsDir(sqHome2), "outbox");
|
|
19589
|
+
var apiKey = (api) => (0, import_crypto11.createHash)("sha256").update(api).digest("hex").slice(0, 16);
|
|
19590
|
+
var outboxPath = (sqHome2, api) => (0, import_path21.join)(outboxDir(sqHome2), `${apiKey(api)}.jsonl`);
|
|
19591
|
+
var syncStampPath = (sqHome2) => (0, import_path21.join)(agentsDir(sqHome2), "sync.stamp");
|
|
19592
|
+
function policyOf(raw) {
|
|
19593
|
+
const r = raw;
|
|
19594
|
+
if (!r || typeof r !== "object" || typeof r.version !== "number" || !r.rules || typeof r.rules !== "object" || Array.isArray(r.rules)) return null;
|
|
19595
|
+
const rules = {};
|
|
19596
|
+
for (const [rule, option] of Object.entries(r.rules)) if (typeof option === "string") rules[rule] = option;
|
|
19597
|
+
return { version: r.version, mode: r.mode === "observe" ? "observe" : "off", rules };
|
|
19598
|
+
}
|
|
19599
|
+
function readPolicyFile(sqHome2) {
|
|
19600
|
+
const out2 = { version: 1, apis: {} };
|
|
19601
|
+
try {
|
|
19602
|
+
const raw = JSON.parse((0, import_fs15.readFileSync)(policyPath(sqHome2), "utf8"));
|
|
19603
|
+
for (const [api, entry] of Object.entries(raw?.apis ?? {})) {
|
|
19604
|
+
const policy = policyOf(entry?.policy);
|
|
19605
|
+
if (!policy) continue;
|
|
19606
|
+
out2.apis[api] = {
|
|
19607
|
+
policy,
|
|
19608
|
+
fetchedAt: typeof entry.fetchedAt === "string" ? entry.fetchedAt : "",
|
|
19609
|
+
refreshSeconds: typeof entry.refreshSeconds === "number" && entry.refreshSeconds >= 15 && entry.refreshSeconds <= 3600 ? entry.refreshSeconds : 60
|
|
19610
|
+
};
|
|
19611
|
+
}
|
|
19612
|
+
} catch {
|
|
19613
|
+
}
|
|
19614
|
+
return out2;
|
|
19615
|
+
}
|
|
19616
|
+
|
|
19617
|
+
// src/application/services/workspaceSandbox/codeAgentInstall.ts
|
|
19618
|
+
var import_fs16 = require("fs");
|
|
19619
|
+
var import_path22 = require("path");
|
|
19620
|
+
var CodeAgentInstallError = class extends Error {
|
|
19621
|
+
constructor(code, message) {
|
|
19622
|
+
super(message);
|
|
19623
|
+
this.code = code;
|
|
19624
|
+
}
|
|
19625
|
+
code;
|
|
19626
|
+
};
|
|
19627
|
+
var hookBundlePath = (sqHome2) => (0, import_path22.join)(agentsDir(sqHome2), "hook.cjs");
|
|
19628
|
+
var hookScriptPath = (sqHome2) => (0, import_path22.join)(agentsDir(sqHome2), "claude-code-hook.sh");
|
|
19629
|
+
var claudeSettingsPath = (env) => (0, import_path22.join)(env.env.CLAUDE_CONFIG_DIR || (0, import_path22.join)(env.home, ".claude"), "settings.json");
|
|
19630
|
+
var shellQuote = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
|
|
19631
|
+
function hookScript(node, bundle) {
|
|
19632
|
+
return [
|
|
19633
|
+
"#!/bin/sh",
|
|
19634
|
+
"# ScaleQuality CLI: asks the organization's rules before a coding agent acts.",
|
|
19635
|
+
"# It only observes: it never blocks the agent, prints nothing and always ends with 0.",
|
|
19636
|
+
'# Written by "scalequality agents install", removed by "scalequality agents remove". Do not edit.',
|
|
19637
|
+
`NODE=${shellQuote(node)}`,
|
|
19638
|
+
`HOOK=${shellQuote(bundle)}`,
|
|
19639
|
+
// The Node that installed it may be gone after an upgrade: the one on the PATH does the same.
|
|
19640
|
+
'[ -x "$NODE" ] || NODE=$(command -v node 2>/dev/null)',
|
|
19641
|
+
'[ -n "$NODE" ] && [ -f "$HOOK" ] || exit 0',
|
|
19642
|
+
'"$NODE" "$HOOK" "$@" >/dev/null 2>&1',
|
|
19643
|
+
"exit 0",
|
|
19644
|
+
""
|
|
19645
|
+
].join("\n");
|
|
19646
|
+
}
|
|
19647
|
+
var hookCommand = (script) => `${shellQuote(script)} claude-code`;
|
|
19648
|
+
var MATCHER = CLAUDE_CODE_TOOLS.join("|");
|
|
19649
|
+
var isOurs = (hook) => typeof hook?.command === "string" && /[\\/]\.scalequality[\\/]agents[\\/]claude-code-hook\.sh/.test(hook.command);
|
|
19650
|
+
var entriesOf = (settings) => {
|
|
19651
|
+
const list = settings.hooks?.PreToolUse;
|
|
19652
|
+
return Array.isArray(list) ? list.filter((e) => !!e && typeof e === "object") : [];
|
|
19653
|
+
};
|
|
19654
|
+
function hasHook(settings) {
|
|
19655
|
+
return entriesOf(settings).some((e) => Array.isArray(e.hooks) && e.hooks.some(isOurs));
|
|
19656
|
+
}
|
|
19657
|
+
function withoutHook(settings) {
|
|
19658
|
+
if (!hasHook(settings)) return settings;
|
|
19659
|
+
const hooks = { ...settings.hooks };
|
|
19660
|
+
const kept = hooks.PreToolUse.flatMap((entry) => {
|
|
19661
|
+
const e = entry;
|
|
19662
|
+
if (!e || typeof e !== "object" || !Array.isArray(e.hooks) || !e.hooks.some(isOurs)) return [entry];
|
|
19663
|
+
const rest = e.hooks.filter((h) => !isOurs(h));
|
|
19664
|
+
return rest.length ? [{ ...e, hooks: rest }] : [];
|
|
19665
|
+
});
|
|
19666
|
+
if (kept.length) hooks.PreToolUse = kept;
|
|
19667
|
+
else delete hooks.PreToolUse;
|
|
19668
|
+
const out2 = { ...settings };
|
|
19669
|
+
if (Object.keys(hooks).length) out2.hooks = hooks;
|
|
19670
|
+
else delete out2.hooks;
|
|
19671
|
+
return out2;
|
|
19672
|
+
}
|
|
19673
|
+
function withHook(settings, command) {
|
|
19674
|
+
const clean = withoutHook(settings);
|
|
19675
|
+
const hooks = { ...clean.hooks ?? {} };
|
|
19676
|
+
const before = Array.isArray(hooks.PreToolUse) ? hooks.PreToolUse : [];
|
|
19677
|
+
hooks.PreToolUse = [...before, { matcher: MATCHER, hooks: [{ type: "command", command, timeout: 10 }] }];
|
|
19678
|
+
return { ...clean, hooks };
|
|
19679
|
+
}
|
|
19680
|
+
function readSettings(file) {
|
|
19681
|
+
if (!(0, import_fs16.existsSync)(file)) return { settings: {}, indent: " ", exists: false };
|
|
19682
|
+
const text3 = (0, import_fs16.readFileSync)(file, "utf8");
|
|
19683
|
+
let parsed;
|
|
19684
|
+
try {
|
|
19685
|
+
parsed = text3.trim() ? JSON.parse(text3) : {};
|
|
19686
|
+
} catch {
|
|
19687
|
+
parsed = null;
|
|
19688
|
+
}
|
|
19689
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
19690
|
+
throw new CodeAgentInstallError("SETTINGS_UNREADABLE", `${file} is not valid JSON, so it was left untouched. Fix the file and run the command again.`);
|
|
19691
|
+
}
|
|
19692
|
+
return { settings: parsed, indent: /^([ \t]+)"/m.exec(text3)?.[1] ?? " ", exists: true };
|
|
19693
|
+
}
|
|
19694
|
+
var keptCopyPath = (target) => `${target}.before-scalequality`;
|
|
19695
|
+
function canonical(value) {
|
|
19696
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
19697
|
+
if (value && typeof value === "object") return `{${Object.keys(value).sort().map((k) => `${JSON.stringify(k)}:${canonical(value[k])}`).join(",")}}`;
|
|
19698
|
+
return JSON.stringify(value) ?? "null";
|
|
19699
|
+
}
|
|
19700
|
+
function writeSettings(file, settings, indent, existed, keepCopy) {
|
|
19701
|
+
const target = existed ? (0, import_fs16.realpathSync)(file) : file;
|
|
19702
|
+
(0, import_fs16.mkdirSync)((0, import_path22.dirname)(target), { recursive: true });
|
|
19703
|
+
let mode = 384;
|
|
19704
|
+
if (existed) {
|
|
19705
|
+
try {
|
|
19706
|
+
mode = (0, import_fs16.statSync)(target).mode & 511;
|
|
19707
|
+
} catch {
|
|
19708
|
+
}
|
|
19709
|
+
if (keepCopy) (0, import_fs16.copyFileSync)(target, keptCopyPath(target));
|
|
19710
|
+
}
|
|
19711
|
+
const tmp = `${target}.${process.pid}.tmp`;
|
|
19712
|
+
(0, import_fs16.writeFileSync)(tmp, `${JSON.stringify(settings, null, indent)}
|
|
19713
|
+
`, { mode });
|
|
19714
|
+
(0, import_fs16.renameSync)(tmp, target);
|
|
19715
|
+
}
|
|
19716
|
+
function claudeCodeHookInstalled(env) {
|
|
19717
|
+
try {
|
|
19718
|
+
return hasHook(readSettings(claudeSettingsPath(env)).settings) && (0, import_fs16.existsSync)(hookScriptPath(env.sqHome)) && (0, import_fs16.existsSync)(hookBundlePath(env.sqHome));
|
|
19719
|
+
} catch {
|
|
19720
|
+
return false;
|
|
19721
|
+
}
|
|
19722
|
+
}
|
|
19723
|
+
function writeHookFiles(env, bundleSource) {
|
|
19724
|
+
if (!(0, import_fs16.existsSync)(bundleSource)) throw new CodeAgentInstallError("HOOK_BUNDLE_MISSING", "This installation of @scalequality/cli is incomplete (dist/hook.cjs is missing). Run it again with npx @scalequality/cli@latest.");
|
|
19725
|
+
(0, import_fs16.mkdirSync)(agentsDir(env.sqHome), { recursive: true, mode: 448 });
|
|
19726
|
+
const bundle = hookBundlePath(env.sqHome), script = hookScriptPath(env.sqHome);
|
|
19727
|
+
const put = (file, content, mode) => {
|
|
19728
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
19729
|
+
(0, import_fs16.writeFileSync)(tmp, content, { mode });
|
|
19730
|
+
try {
|
|
19731
|
+
(0, import_fs16.chmodSync)(tmp, mode);
|
|
19732
|
+
} catch {
|
|
19733
|
+
}
|
|
19734
|
+
(0, import_fs16.renameSync)(tmp, file);
|
|
19735
|
+
};
|
|
19736
|
+
put(bundle, (0, import_fs16.readFileSync)(bundleSource), 384);
|
|
19737
|
+
put(script, hookScript(env.node, bundle), 448);
|
|
19738
|
+
}
|
|
19739
|
+
function refreshHookFiles(env, bundleSource) {
|
|
19740
|
+
try {
|
|
19741
|
+
if (!claudeCodeHookInstalled(env) || !(0, import_fs16.existsSync)(bundleSource)) return false;
|
|
19742
|
+
const same = (0, import_fs16.readFileSync)(bundleSource).equals((0, import_fs16.readFileSync)(hookBundlePath(env.sqHome))) && (0, import_fs16.readFileSync)(hookScriptPath(env.sqHome), "utf8") === hookScript(env.node, hookBundlePath(env.sqHome));
|
|
19743
|
+
if (same) return false;
|
|
19744
|
+
writeHookFiles(env, bundleSource);
|
|
19745
|
+
return true;
|
|
19746
|
+
} catch {
|
|
19747
|
+
return false;
|
|
19748
|
+
}
|
|
19749
|
+
}
|
|
19750
|
+
function installClaudeCodeHook(env, bundleSource) {
|
|
19751
|
+
if (env.platform === "win32") {
|
|
19752
|
+
throw new CodeAgentInstallError("PLATFORM_NOT_SUPPORTED", "Installing the rule in Claude Code is available on macOS and Linux for now.");
|
|
19753
|
+
}
|
|
19754
|
+
const file = claudeSettingsPath(env);
|
|
19755
|
+
const { settings, indent, exists } = readSettings(file);
|
|
19756
|
+
writeHookFiles(env, bundleSource);
|
|
19757
|
+
const added = !hasHook(settings);
|
|
19758
|
+
const next = withHook(settings, hookCommand(hookScriptPath(env.sqHome)));
|
|
19759
|
+
if (JSON.stringify(next) !== JSON.stringify(settings)) writeSettings(file, next, indent, exists, added);
|
|
19760
|
+
return { settings: file, added };
|
|
19761
|
+
}
|
|
19762
|
+
function removeClaudeCodeHook(env) {
|
|
19763
|
+
const file = claudeSettingsPath(env);
|
|
19764
|
+
const { settings, indent, exists } = readSettings(file);
|
|
19765
|
+
const removed = hasHook(settings);
|
|
19766
|
+
if (removed) {
|
|
19767
|
+
const clean = withoutHook(settings);
|
|
19768
|
+
const target = (0, import_fs16.realpathSync)(file);
|
|
19769
|
+
const copy = keptCopyPath(target);
|
|
19770
|
+
if (!Object.keys(clean).length && !(0, import_fs16.existsSync)(copy) && !(0, import_fs16.lstatSync)(file).isSymbolicLink()) (0, import_fs16.rmSync)(file, { force: true });
|
|
19771
|
+
else {
|
|
19772
|
+
writeSettings(file, clean, indent, exists, false);
|
|
19773
|
+
try {
|
|
19774
|
+
if (canonical(JSON.parse((0, import_fs16.readFileSync)(copy, "utf8"))) === canonical(clean)) (0, import_fs16.rmSync)(copy, { force: true });
|
|
19775
|
+
} catch {
|
|
19776
|
+
}
|
|
19777
|
+
}
|
|
19778
|
+
}
|
|
19779
|
+
(0, import_fs16.rmSync)(hookScriptPath(env.sqHome), { force: true });
|
|
19780
|
+
(0, import_fs16.rmSync)(hookBundlePath(env.sqHome), { force: true });
|
|
19781
|
+
return { settings: file, removed };
|
|
19782
|
+
}
|
|
19783
|
+
|
|
19784
|
+
// src/application/services/workspaceSandbox/codeAgentSync.ts
|
|
19785
|
+
var import_fs17 = require("fs");
|
|
19786
|
+
var import_path23 = require("path");
|
|
19787
|
+
function machineTokens(sqHome2) {
|
|
19788
|
+
try {
|
|
19789
|
+
const raw = JSON.parse((0, import_fs17.readFileSync)((0, import_path23.join)(sqHome2, "credentials.json"), "utf8"));
|
|
19790
|
+
return Object.entries(raw?.apis ?? {}).flatMap(([api, c]) => typeof c?.machineToken === "string" && c.machineToken ? [{ api, token: c.machineToken }] : []);
|
|
19791
|
+
} catch {
|
|
19792
|
+
return [];
|
|
19793
|
+
}
|
|
19794
|
+
}
|
|
19795
|
+
function savePolicies(sqHome2, change) {
|
|
19796
|
+
const file = readPolicyFile(sqHome2);
|
|
19797
|
+
change(file.apis);
|
|
19798
|
+
(0, import_fs17.mkdirSync)(agentsDir(sqHome2), { recursive: true, mode: 448 });
|
|
19799
|
+
const tmp = `${policyPath(sqHome2)}.${process.pid}.tmp`;
|
|
19800
|
+
(0, import_fs17.writeFileSync)(tmp, `${JSON.stringify(file, null, 2)}
|
|
19801
|
+
`, { mode: 384 });
|
|
19802
|
+
(0, import_fs17.renameSync)(tmp, policyPath(sqHome2));
|
|
19803
|
+
}
|
|
19804
|
+
async function call(deps, api, token, path, body) {
|
|
19805
|
+
try {
|
|
19806
|
+
const res = await (deps.fetchImpl ?? fetch)(`${api.replace(/\/+$/, "")}/api/ai-governance${path}`, {
|
|
19807
|
+
method: "POST",
|
|
19808
|
+
body: JSON.stringify(body),
|
|
19809
|
+
signal: AbortSignal.timeout(8e3),
|
|
19810
|
+
headers: { accept: "application/json", "content-type": "application/json", "x-machine-token": token, "user-agent": deps.userAgent ?? "scalequality-cli (agents)" }
|
|
19811
|
+
});
|
|
19812
|
+
const text3 = await res.text().catch(() => "");
|
|
19813
|
+
let data = null;
|
|
19814
|
+
try {
|
|
19815
|
+
data = text3 ? JSON.parse(text3) : null;
|
|
19816
|
+
} catch {
|
|
19817
|
+
data = null;
|
|
19818
|
+
}
|
|
19819
|
+
const code = typeof data?.code === "string" && /^[A-Z_]{3,80}$/.test(data.code) ? data.code : null;
|
|
19820
|
+
return { status: res.status, code, data: res.ok ? data : null };
|
|
19821
|
+
} catch {
|
|
19822
|
+
return { status: null, code: null, data: null };
|
|
19823
|
+
}
|
|
19824
|
+
}
|
|
19825
|
+
function policyOf2(raw) {
|
|
19826
|
+
const p = raw;
|
|
19827
|
+
if (!p || typeof p !== "object" || typeof p.version !== "number" || !p.rules || typeof p.rules !== "object" || Array.isArray(p.rules)) return null;
|
|
19828
|
+
return { version: p.version, mode: p.mode === "observe" ? "observe" : "off", rules: Object.fromEntries(Object.entries(p.rules).filter(([, v]) => typeof v === "string")) };
|
|
19829
|
+
}
|
|
19830
|
+
function batches(sqHome2, api, now) {
|
|
19831
|
+
const dir = outboxDir(sqHome2), key = apiKey(api);
|
|
19832
|
+
try {
|
|
19833
|
+
(0, import_fs17.renameSync)(outboxPath(sqHome2, api), (0, import_path23.join)(dir, `${key}.${now.getTime()}.${process.pid}.sending`));
|
|
19834
|
+
} catch {
|
|
19835
|
+
}
|
|
19836
|
+
try {
|
|
19837
|
+
return (0, import_fs17.readdirSync)(dir).filter((f) => f.startsWith(`${key}.`) && f.endsWith(".sending")).sort().map((f) => (0, import_path23.join)(dir, f));
|
|
19838
|
+
} catch {
|
|
19839
|
+
return [];
|
|
19840
|
+
}
|
|
19841
|
+
}
|
|
19842
|
+
function waiting(sqHome2, api) {
|
|
19843
|
+
const dir = outboxDir(sqHome2), key = apiKey(api);
|
|
19844
|
+
let lines2 = 0;
|
|
19845
|
+
try {
|
|
19846
|
+
for (const f of (0, import_fs17.readdirSync)(dir)) {
|
|
19847
|
+
if (!f.startsWith(`${key}.`)) continue;
|
|
19848
|
+
lines2 += (0, import_fs17.readFileSync)((0, import_path23.join)(dir, f), "utf8").split("\n").filter(Boolean).length;
|
|
19849
|
+
}
|
|
19850
|
+
} catch {
|
|
19851
|
+
}
|
|
19852
|
+
return lines2;
|
|
19853
|
+
}
|
|
19854
|
+
function forget(sqHome2, api, queueToo) {
|
|
19855
|
+
savePolicies(sqHome2, (apis) => {
|
|
19856
|
+
delete apis[api];
|
|
19857
|
+
});
|
|
19858
|
+
if (!queueToo) return;
|
|
19859
|
+
const dir = outboxDir(sqHome2), key = apiKey(api);
|
|
19860
|
+
try {
|
|
19861
|
+
for (const f of (0, import_fs17.readdirSync)(dir)) if (f.startsWith(`${key}.`)) (0, import_fs17.rmSync)((0, import_path23.join)(dir, f), { force: true });
|
|
19862
|
+
} catch {
|
|
19863
|
+
}
|
|
19864
|
+
}
|
|
19865
|
+
async function syncApi(deps, api, token) {
|
|
19866
|
+
const now = deps.now?.() ?? /* @__PURE__ */ new Date();
|
|
19867
|
+
const checkin = await call(deps, api, token, "/machines/self/code-agents/checkin", { agents: { claudeCode: { installed: deps.claudeCodeInstalled, scope: deps.claudeCodeInstalled ? "user" : null } } });
|
|
19868
|
+
const policy = policyOf2(checkin.data?.policy);
|
|
19869
|
+
let outcome = "UNREACHABLE";
|
|
19870
|
+
if (checkin.status === 200 && policy) {
|
|
19871
|
+
outcome = "OK";
|
|
19872
|
+
const refresh = typeof checkin.data?.refreshSeconds === "number" ? checkin.data.refreshSeconds : 60;
|
|
19873
|
+
savePolicies(deps.sqHome, (apis) => {
|
|
19874
|
+
apis[api] = { policy, fetchedAt: now.toISOString(), refreshSeconds: refresh };
|
|
19875
|
+
});
|
|
19876
|
+
} else if (checkin.status === 401 && checkin.code === "MACHINE_AUTH_REQUIRED") {
|
|
19877
|
+
outcome = "DISCONNECTED";
|
|
19878
|
+
forget(deps.sqHome, api, true);
|
|
19879
|
+
} else if (checkin.status === 404) {
|
|
19880
|
+
outcome = "NOT_SERVED";
|
|
19881
|
+
forget(deps.sqHome, api, true);
|
|
19882
|
+
}
|
|
19883
|
+
let sent = 0;
|
|
19884
|
+
if (outcome === "OK") {
|
|
19885
|
+
for (const file of batches(deps.sqHome, api, now)) {
|
|
19886
|
+
let decisions = [];
|
|
19887
|
+
try {
|
|
19888
|
+
decisions = (0, import_fs17.readFileSync)(file, "utf8").split("\n").filter(Boolean).flatMap((l) => {
|
|
19889
|
+
try {
|
|
19890
|
+
return [JSON.parse(l)];
|
|
19891
|
+
} catch {
|
|
19892
|
+
return [];
|
|
19893
|
+
}
|
|
19894
|
+
});
|
|
19895
|
+
} catch {
|
|
19896
|
+
}
|
|
19897
|
+
let delivered = true;
|
|
19898
|
+
for (let i = 0; i < decisions.length && delivered; i += 200) {
|
|
19899
|
+
const r = await call(deps, api, token, "/machines/self/code-agents/decisions", { decisions: decisions.slice(i, i + 200) });
|
|
19900
|
+
if (r.status !== null && (r.status < 300 || r.status === 400)) {
|
|
19901
|
+
if (r.status < 300) sent += Math.min(200, decisions.length - i);
|
|
19902
|
+
} else delivered = false;
|
|
19903
|
+
}
|
|
19904
|
+
if (!delivered) break;
|
|
19905
|
+
(0, import_fs17.rmSync)(file, { force: true });
|
|
19906
|
+
}
|
|
19907
|
+
}
|
|
19908
|
+
return { api, checkin: outcome, policy: outcome === "OK" ? policy : readPolicyFile(deps.sqHome).apis[api]?.policy ?? null, sent, waiting: waiting(deps.sqHome, api) };
|
|
19909
|
+
}
|
|
19910
|
+
async function syncAll(deps, only) {
|
|
19911
|
+
const tokens = machineTokens(deps.sqHome).filter((t) => !only || t.api === only);
|
|
19912
|
+
try {
|
|
19913
|
+
(0, import_fs17.mkdirSync)(agentsDir(deps.sqHome), { recursive: true, mode: 448 });
|
|
19914
|
+
const stamp = syncStampPath(deps.sqHome), at = deps.now?.() ?? /* @__PURE__ */ new Date();
|
|
19915
|
+
if ((0, import_fs17.existsSync)(stamp)) (0, import_fs17.utimesSync)(stamp, at, at);
|
|
19916
|
+
else (0, import_fs17.writeFileSync)(stamp, "", { mode: 384 });
|
|
19917
|
+
} catch {
|
|
19918
|
+
}
|
|
19919
|
+
if (!only) {
|
|
19920
|
+
const known = new Set(tokens.map((t) => t.api));
|
|
19921
|
+
const stale = Object.keys(readPolicyFile(deps.sqHome).apis).filter((api) => !known.has(api));
|
|
19922
|
+
for (const api of stale) forget(deps.sqHome, api, true);
|
|
19923
|
+
}
|
|
19924
|
+
const out2 = [];
|
|
19925
|
+
for (const t of tokens) out2.push(await syncApi(deps, t.api, t.token));
|
|
19926
|
+
return out2;
|
|
19927
|
+
}
|
|
19928
|
+
function lastSyncAt(sqHome2) {
|
|
19929
|
+
try {
|
|
19930
|
+
return (0, import_fs17.statSync)(syncStampPath(sqHome2)).mtime;
|
|
19931
|
+
} catch {
|
|
19932
|
+
return null;
|
|
19933
|
+
}
|
|
19934
|
+
}
|
|
19935
|
+
|
|
19936
|
+
// src/main/workspace-connect.ts
|
|
19512
19937
|
var importEsm = new Function("specifier", "return import(specifier)");
|
|
19513
19938
|
async function loadSdk() {
|
|
19514
19939
|
const resolved = require.resolve("@anthropic-ai/claude-agent-sdk");
|
|
@@ -19523,9 +19948,9 @@ var say = (line = "") => {
|
|
|
19523
19948
|
var cliVersion = process.env.SCALEQUALITY_CLI_VERSION || "dev";
|
|
19524
19949
|
var userAgent = (mode) => `scalequality-cli/${cliVersion} (${mode}; node ${process.versions.node}; ${process.platform})`;
|
|
19525
19950
|
var HOME = (0, import_os7.homedir)();
|
|
19526
|
-
var SQ_HOME = (0,
|
|
19527
|
-
var ENGINE_HOME = (0,
|
|
19528
|
-
var credentials = new CredentialStore((0,
|
|
19951
|
+
var SQ_HOME = (0, import_path24.join)(HOME, ".scalequality");
|
|
19952
|
+
var ENGINE_HOME = (0, import_path24.join)(SQ_HOME, "workspace");
|
|
19953
|
+
var credentials = new CredentialStore((0, import_path24.join)(SQ_HOME, "credentials.json"));
|
|
19529
19954
|
function startFailure(e, api) {
|
|
19530
19955
|
if (e instanceof NotLocalSessionError) return 'This code belongs to a cloud workspace session. In the AI Workspace, choose "Use a folder on your computer" to get a code for this command.';
|
|
19531
19956
|
if (e instanceof SessionGoneError) {
|
|
@@ -19538,16 +19963,16 @@ function startFailure(e, api) {
|
|
|
19538
19963
|
return "ScaleQuality could not start this session. Try again in a moment, or get a new code from the AI Workspace.";
|
|
19539
19964
|
}
|
|
19540
19965
|
function engineDirs() {
|
|
19541
|
-
const configDir = (0,
|
|
19542
|
-
const scratch = (0,
|
|
19543
|
-
(0,
|
|
19544
|
-
(0,
|
|
19966
|
+
const configDir = (0, import_path24.join)(ENGINE_HOME, "claude-home");
|
|
19967
|
+
const scratch = (0, import_path24.join)(ENGINE_HOME, "tmp");
|
|
19968
|
+
(0, import_fs18.mkdirSync)(configDir, { recursive: true, mode: 448 });
|
|
19969
|
+
(0, import_fs18.mkdirSync)(scratch, { recursive: true, mode: 448 });
|
|
19545
19970
|
return { configDir, scratch };
|
|
19546
19971
|
}
|
|
19547
19972
|
function createLocalEngine(o) {
|
|
19548
19973
|
const { configDir, scratch } = engineDirs();
|
|
19549
|
-
const sessions = (0,
|
|
19550
|
-
const stateDir = (0,
|
|
19974
|
+
const sessions = (0, import_path24.join)(ENGINE_HOME, "sessions");
|
|
19975
|
+
const stateDir = (0, import_path24.join)(sessions, o.sessionId);
|
|
19551
19976
|
void pruneSessionStates(sessions, stateDir).catch(() => void 0);
|
|
19552
19977
|
const log = {
|
|
19553
19978
|
info: (msg, ctx) => {
|
|
@@ -19850,7 +20275,7 @@ async function upMain(api, verbose, service) {
|
|
|
19850
20275
|
let shuttingDown = false;
|
|
19851
20276
|
let agent;
|
|
19852
20277
|
const startSession = ({ sessionId, secret, root }) => {
|
|
19853
|
-
const label = (0,
|
|
20278
|
+
const label = (0, import_path24.basename)(root);
|
|
19854
20279
|
const prefix = style.dim(`[${label}] `);
|
|
19855
20280
|
const consoleLog = new ConsoleLog(style);
|
|
19856
20281
|
let resolveDone = () => void 0;
|
|
@@ -19920,6 +20345,7 @@ async function upMain(api, verbose, service) {
|
|
|
19920
20345
|
}
|
|
19921
20346
|
process.exit(RESTART_EXIT_CODE);
|
|
19922
20347
|
});
|
|
20348
|
+
startAgentsSync(api);
|
|
19923
20349
|
say(style.bold(`ScaleQuality: keeping "${credential.name}" connected to ${api}${service ? " (background service)" : ""}`));
|
|
19924
20350
|
say(` Folders: ${credential.folders.length ? credential.folders.join(", ") : "none yet (scalequality add <folder>)"}`);
|
|
19925
20351
|
say(style.dim(" Commands that sessions want to run are approved in the browser."));
|
|
@@ -19944,6 +20370,137 @@ async function upMain(api, verbose, service) {
|
|
|
19944
20370
|
throw e;
|
|
19945
20371
|
}
|
|
19946
20372
|
}
|
|
20373
|
+
var AGENTS_USAGE = [
|
|
20374
|
+
"Usage: scalequality agents <install|status|remove> [--api URL]",
|
|
20375
|
+
"",
|
|
20376
|
+
"Your organization's secure development rules in the coding agents of this",
|
|
20377
|
+
"computer (Claude Code for now). The agent asks the rules on this computer",
|
|
20378
|
+
"before it acts: the command and the file never leave it, only the decision.",
|
|
20379
|
+
"While your organization observes, nothing is blocked.",
|
|
20380
|
+
"",
|
|
20381
|
+
" install Put the rule in Claude Code for you (you can remove it).",
|
|
20382
|
+
" status Whether it is installed, and the rules this computer holds.",
|
|
20383
|
+
" remove Take it out of Claude Code."
|
|
20384
|
+
].join("\n");
|
|
20385
|
+
var agentsEnv = () => ({ home: HOME, sqHome: SQ_HOME, platform: process.platform, env: process.env, node: process.execPath });
|
|
20386
|
+
var hookBundle = () => (0, import_path24.join)(__dirname, "hook.cjs");
|
|
20387
|
+
var agentsSyncDeps = () => ({ sqHome: SQ_HOME, claudeCodeInstalled: claudeCodeHookInstalled(agentsEnv()), userAgent: userAgent("agents") });
|
|
20388
|
+
function startAgentsSync(api) {
|
|
20389
|
+
const round2 = async () => {
|
|
20390
|
+
let installed2 = false;
|
|
20391
|
+
try {
|
|
20392
|
+
refreshHookFiles(agentsEnv(), hookBundle());
|
|
20393
|
+
const deps = agentsSyncDeps();
|
|
20394
|
+
installed2 = deps.claudeCodeInstalled;
|
|
20395
|
+
await syncAll(deps, api);
|
|
20396
|
+
} catch {
|
|
20397
|
+
}
|
|
20398
|
+
setTimeout(() => void round2(), installed2 ? 6e4 : 6e5).unref();
|
|
20399
|
+
};
|
|
20400
|
+
setTimeout(() => void round2(), 5e3).unref();
|
|
20401
|
+
}
|
|
20402
|
+
function agentsLines(results, installed2) {
|
|
20403
|
+
const lines2 = [`Claude Code ${installed2 ? `rule installed for you (${claudeSettingsPath(agentsEnv())})` : "rule not installed (scalequality agents install)"}`];
|
|
20404
|
+
if (!results.length) lines2.push("ScaleQuality this computer is not connected (scalequality login)");
|
|
20405
|
+
for (const r of results) {
|
|
20406
|
+
const kept = readPolicyFile(SQ_HOME).apis[r.api];
|
|
20407
|
+
const state = r.checkin === "OK" ? r.policy?.mode === "observe" ? "observing" : "off in your organization" : r.checkin === "NOT_SERVED" ? "not available at this address yet" : r.checkin === "DISCONNECTED" ? "this computer was disconnected there" : kept ? `not reached now; keeping the rules read at ${kept.fetchedAt}` : "not reached now";
|
|
20408
|
+
lines2.push(`ScaleQuality address ${r.api}`);
|
|
20409
|
+
lines2.push(` Rules ${state}${r.policy && r.checkin === "OK" ? ` (version ${r.policy.version}: ${Object.keys(r.policy.rules).join(", ") || "no secure development rule is on"})` : ""}`);
|
|
20410
|
+
if (r.sent || r.waiting) lines2.push(` Decisions ${r.sent} sent now, ${r.waiting} waiting`);
|
|
20411
|
+
}
|
|
20412
|
+
return lines2;
|
|
20413
|
+
}
|
|
20414
|
+
async function agentsMain(argv) {
|
|
20415
|
+
const [action, ...rest] = argv;
|
|
20416
|
+
if (action === "-h" || action === "--help" || !action) {
|
|
20417
|
+
process.stdout.write(`${AGENTS_USAGE}
|
|
20418
|
+
`);
|
|
20419
|
+
process.exit(action ? 0 : 2);
|
|
20420
|
+
}
|
|
20421
|
+
let apiArg = null;
|
|
20422
|
+
let quiet = false;
|
|
20423
|
+
for (let i = 0; i < rest.length; i++) {
|
|
20424
|
+
const a = rest[i];
|
|
20425
|
+
if (a === "--quiet") {
|
|
20426
|
+
quiet = true;
|
|
20427
|
+
continue;
|
|
20428
|
+
}
|
|
20429
|
+
if (a === "-h" || a === "--help") {
|
|
20430
|
+
process.stdout.write(`${AGENTS_USAGE}
|
|
20431
|
+
`);
|
|
20432
|
+
process.exit(0);
|
|
20433
|
+
}
|
|
20434
|
+
if (a === "--api" || a.startsWith("--api=")) {
|
|
20435
|
+
const v = a.includes("=") ? a.slice(a.indexOf("=") + 1) : rest[++i];
|
|
20436
|
+
apiArg = v ? normalizeApiUrl(v) : null;
|
|
20437
|
+
if (!apiArg) {
|
|
20438
|
+
say(style.red("--api must be an https address (http is accepted only for localhost)."));
|
|
20439
|
+
process.exit(2);
|
|
20440
|
+
}
|
|
20441
|
+
continue;
|
|
20442
|
+
}
|
|
20443
|
+
say(style.red(`Unexpected argument ${a}.`));
|
|
20444
|
+
say();
|
|
20445
|
+
say(AGENTS_USAGE);
|
|
20446
|
+
process.exit(2);
|
|
20447
|
+
}
|
|
20448
|
+
const env = agentsEnv();
|
|
20449
|
+
if (action === "sync") {
|
|
20450
|
+
refreshHookFiles(env, hookBundle());
|
|
20451
|
+
const results = await syncAll(agentsSyncDeps(), apiArg);
|
|
20452
|
+
if (!quiet) process.stdout.write(`${agentsLines(results, claudeCodeHookInstalled(env)).join("\n")}
|
|
20453
|
+
`);
|
|
20454
|
+
return;
|
|
20455
|
+
}
|
|
20456
|
+
if (action === "status") {
|
|
20457
|
+
const results = await syncAll(agentsSyncDeps(), apiArg);
|
|
20458
|
+
const at = lastSyncAt(SQ_HOME);
|
|
20459
|
+
process.stdout.write(`${[...agentsLines(results, claudeCodeHookInstalled(env)), ...at ? [`Last read ${at.toISOString()}`] : []].join("\n")}
|
|
20460
|
+
`);
|
|
20461
|
+
return;
|
|
20462
|
+
}
|
|
20463
|
+
if (action === "install") {
|
|
20464
|
+
if (!credentials.apis().length) {
|
|
20465
|
+
say(style.red("This computer is not connected to ScaleQuality. Run scalequality login first."));
|
|
20466
|
+
process.exit(1);
|
|
20467
|
+
}
|
|
20468
|
+
try {
|
|
20469
|
+
const { settings, added } = installClaudeCodeHook(env, hookBundle());
|
|
20470
|
+
say(style.green(added ? `The rule is now in Claude Code for you (${settings}).` : `The rule was already in Claude Code (${settings}); its files were refreshed.`));
|
|
20471
|
+
} catch (e) {
|
|
20472
|
+
if (e instanceof CodeAgentInstallError) {
|
|
20473
|
+
say(style.red(e.message));
|
|
20474
|
+
process.exit(1);
|
|
20475
|
+
}
|
|
20476
|
+
throw e;
|
|
20477
|
+
}
|
|
20478
|
+
const results = await syncAll(agentsSyncDeps(), apiArg);
|
|
20479
|
+
process.stdout.write(`${agentsLines(results, true).join("\n")}
|
|
20480
|
+
`);
|
|
20481
|
+
say(style.dim("Claude Code asks the rules on this computer before it acts. Nothing is blocked while your organization observes;"));
|
|
20482
|
+
say(style.dim('only the decision leaves this computer, never the command or the file. "scalequality agents remove" takes it out.'));
|
|
20483
|
+
return;
|
|
20484
|
+
}
|
|
20485
|
+
if (action === "remove") {
|
|
20486
|
+
try {
|
|
20487
|
+
const { settings, removed } = removeClaudeCodeHook(env);
|
|
20488
|
+
say(removed ? `The rule was taken out of Claude Code (${settings}).` : "The rule was not installed in Claude Code.");
|
|
20489
|
+
} catch (e) {
|
|
20490
|
+
if (e instanceof CodeAgentInstallError) {
|
|
20491
|
+
say(style.red(e.message));
|
|
20492
|
+
process.exit(1);
|
|
20493
|
+
}
|
|
20494
|
+
throw e;
|
|
20495
|
+
}
|
|
20496
|
+
await syncAll(agentsSyncDeps(), apiArg);
|
|
20497
|
+
return;
|
|
20498
|
+
}
|
|
20499
|
+
say(style.red(`Unknown agents action ${action}.`));
|
|
20500
|
+
say();
|
|
20501
|
+
say(AGENTS_USAGE);
|
|
20502
|
+
process.exit(2);
|
|
20503
|
+
}
|
|
19947
20504
|
function startSelfUpdate(api, busy, restart) {
|
|
19948
20505
|
const confirm = setTimeout(() => {
|
|
19949
20506
|
try {
|
|
@@ -19994,7 +20551,7 @@ function startSelfUpdate(api, busy, restart) {
|
|
|
19994
20551
|
}
|
|
19995
20552
|
async function addMain(api, path) {
|
|
19996
20553
|
try {
|
|
19997
|
-
const real = await addFolder(credentials, api, (0,
|
|
20554
|
+
const real = await addFolder(credentials, api, (0, import_path24.resolve)(path ?? process.cwd()), HOME);
|
|
19998
20555
|
say(style.green(`Added ${real}.`));
|
|
19999
20556
|
const credential = credentials.get(api);
|
|
20000
20557
|
const client = new MachineClient(api, { token: credential.machineToken, userAgent: userAgent("add") });
|
|
@@ -20096,6 +20653,10 @@ async function main() {
|
|
|
20096
20653
|
}
|
|
20097
20654
|
const argv = process.argv.slice(2);
|
|
20098
20655
|
const command = argv[0];
|
|
20656
|
+
if (command === "agents") {
|
|
20657
|
+
await agentsMain(argv.slice(1));
|
|
20658
|
+
return;
|
|
20659
|
+
}
|
|
20099
20660
|
if (!isMachineCommand(command)) {
|
|
20100
20661
|
await connectMain(argv);
|
|
20101
20662
|
return;
|