squadrant 0.18.0 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +609 -418
- package/dist/index.js.map +1 -1
- package/dist/squadrantd.js +211 -134
- package/dist/squadrantd.js.map +1 -1
- package/package.json +1 -1
package/dist/squadrantd.js
CHANGED
|
@@ -60,22 +60,90 @@ var init_snapshot = __esm({
|
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
// packages/cli/src/squadrantd.ts
|
|
63
|
-
import { join as join19, dirname as
|
|
63
|
+
import { join as join19, dirname as dirname4 } from "path";
|
|
64
64
|
import { homedir as homedir14 } from "os";
|
|
65
65
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
66
|
-
import { readFileSync as
|
|
66
|
+
import { readFileSync as readFileSync13, statSync as statSync4, existsSync as existsSync12 } from "fs";
|
|
67
67
|
|
|
68
68
|
// packages/shared/dist/config.js
|
|
69
|
-
import
|
|
70
|
-
import path from "path";
|
|
69
|
+
import path2 from "path";
|
|
71
70
|
import os from "os";
|
|
72
71
|
import chalk from "chalk";
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
|
|
73
|
+
// packages/shared/dist/lib/config-io.js
|
|
74
|
+
import fs from "fs";
|
|
75
|
+
import path from "path";
|
|
76
|
+
var didLogMigration = false;
|
|
77
|
+
var migrationRun = false;
|
|
78
|
+
function tightenModeSync(p, expectedMode) {
|
|
79
|
+
try {
|
|
80
|
+
if (!fs.existsSync(p))
|
|
81
|
+
return;
|
|
82
|
+
const stat = fs.statSync(p);
|
|
83
|
+
const currentMode = stat.mode & 4095;
|
|
84
|
+
if ((currentMode & ~expectedMode) !== 0) {
|
|
85
|
+
fs.chmodSync(p, expectedMode);
|
|
86
|
+
if (!didLogMigration) {
|
|
87
|
+
console.warn(`\x1B[33m\u26A0\x1B[0m squadrant: tightened config file permissions (security fix #668)`);
|
|
88
|
+
didLogMigration = true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function writeConfigFileSync(filePath, content) {
|
|
95
|
+
ensureDirSync(path.dirname(filePath));
|
|
96
|
+
fs.writeFileSync(filePath, content, { mode: 384 });
|
|
97
|
+
tightenModeSync(filePath, 384);
|
|
98
|
+
}
|
|
99
|
+
function ensureDirSync(dirPath) {
|
|
100
|
+
if (dirPath !== CONFIG_DIR && !dirPath.startsWith(CONFIG_DIR + path.sep)) {
|
|
101
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
fs.mkdirSync(dirPath, { recursive: true, mode: 448 });
|
|
105
|
+
let current = dirPath;
|
|
106
|
+
while (current === CONFIG_DIR || current.startsWith(CONFIG_DIR + path.sep)) {
|
|
107
|
+
tightenModeSync(current, 448);
|
|
108
|
+
if (current === CONFIG_DIR)
|
|
109
|
+
break;
|
|
110
|
+
const parent = path.dirname(current);
|
|
111
|
+
if (parent === current)
|
|
112
|
+
break;
|
|
113
|
+
current = parent;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function readConfigFileSync(filePath) {
|
|
117
|
+
return fs.readFileSync(filePath, "utf-8");
|
|
118
|
+
}
|
|
119
|
+
function migrateConfigPermsSync() {
|
|
120
|
+
if (migrationRun)
|
|
121
|
+
return;
|
|
122
|
+
migrationRun = true;
|
|
123
|
+
tightenModeSync(CONFIG_DIR, 448);
|
|
124
|
+
tightenModeSync(path.join(CONFIG_DIR, "config.json"), 384);
|
|
125
|
+
const projectsDir = path.join(CONFIG_DIR, "projects");
|
|
126
|
+
tightenModeSync(projectsDir, 448);
|
|
127
|
+
try {
|
|
128
|
+
if (fs.existsSync(projectsDir)) {
|
|
129
|
+
const files = fs.readdirSync(projectsDir);
|
|
130
|
+
for (const file of files) {
|
|
131
|
+
if (file.endsWith(".json")) {
|
|
132
|
+
tightenModeSync(path.join(projectsDir, file), 384);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
} catch {
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// packages/shared/dist/config.js
|
|
141
|
+
var DEFAULT_CONFIG_PATH = process.env.SQUADRANT_CONFIG || path2.join(os.homedir(), ".config", "squadrant", "config.json");
|
|
142
|
+
var CONFIG_DIR = path2.dirname(DEFAULT_CONFIG_PATH);
|
|
75
143
|
function getDefaultConfig() {
|
|
76
144
|
return {
|
|
77
145
|
commandName: "\u{1F3DB}\uFE0F command",
|
|
78
|
-
hubVault:
|
|
146
|
+
hubVault: path2.join(os.homedir(), "squadrant-hub"),
|
|
79
147
|
projects: {},
|
|
80
148
|
agents: {
|
|
81
149
|
claude: { cli: "claude", driver: "claude" }
|
|
@@ -119,13 +187,14 @@ function getDefaultConfig() {
|
|
|
119
187
|
},
|
|
120
188
|
metrics: {
|
|
121
189
|
enabled: true,
|
|
122
|
-
path:
|
|
190
|
+
path: path2.join(CONFIG_DIR, "metrics.json")
|
|
123
191
|
}
|
|
124
192
|
};
|
|
125
193
|
}
|
|
126
194
|
function loadConfig(configPath = DEFAULT_CONFIG_PATH) {
|
|
195
|
+
migrateConfigPermsSync();
|
|
127
196
|
try {
|
|
128
|
-
const raw =
|
|
197
|
+
const raw = readConfigFileSync(configPath);
|
|
129
198
|
const config = JSON.parse(raw);
|
|
130
199
|
if (config.defaults.models && !config.defaults.roles) {
|
|
131
200
|
const m = config.defaults.models;
|
|
@@ -150,27 +219,24 @@ function loadConfig(configPath = DEFAULT_CONFIG_PATH) {
|
|
|
150
219
|
}
|
|
151
220
|
}
|
|
152
221
|
function saveConfig(config, configPath = DEFAULT_CONFIG_PATH) {
|
|
153
|
-
|
|
154
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
155
|
-
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
|
|
222
|
+
writeConfigFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
|
|
156
223
|
}
|
|
157
224
|
function resolveHome(p) {
|
|
158
225
|
return p.startsWith("~") ? p.replace("~", os.homedir()) : p;
|
|
159
226
|
}
|
|
160
227
|
|
|
161
228
|
// packages/shared/dist/project-config.js
|
|
162
|
-
import fs2 from "fs";
|
|
163
229
|
import os2 from "os";
|
|
164
|
-
import
|
|
230
|
+
import path3 from "path";
|
|
165
231
|
function defaultRoot() {
|
|
166
|
-
return
|
|
232
|
+
return path3.join(os2.homedir(), ".config", "squadrant");
|
|
167
233
|
}
|
|
168
234
|
function projectConfigPath(name, root = defaultRoot()) {
|
|
169
|
-
return
|
|
235
|
+
return path3.join(root, "projects", `${name}.json`);
|
|
170
236
|
}
|
|
171
237
|
function loadProjectOverride(name, root = defaultRoot()) {
|
|
172
238
|
try {
|
|
173
|
-
return JSON.parse(
|
|
239
|
+
return JSON.parse(readConfigFileSync(projectConfigPath(name, root)));
|
|
174
240
|
} catch {
|
|
175
241
|
return {};
|
|
176
242
|
}
|
|
@@ -187,8 +253,7 @@ function deepMerge(base, patch) {
|
|
|
187
253
|
function saveProjectOverride(name, patch, root = defaultRoot()) {
|
|
188
254
|
const merged = deepMerge(loadProjectOverride(name, root), patch);
|
|
189
255
|
const file = projectConfigPath(name, root);
|
|
190
|
-
|
|
191
|
-
fs2.writeFileSync(file, JSON.stringify(merged, null, 2) + "\n");
|
|
256
|
+
writeConfigFileSync(file, JSON.stringify(merged, null, 2) + "\n");
|
|
192
257
|
}
|
|
193
258
|
var DEFAULT_NOTIFY = { active: false, cap: true, crew: "alert_only" };
|
|
194
259
|
function resolveNotify(globalNotify, override) {
|
|
@@ -208,9 +273,9 @@ var TERMINAL_STATES = /* @__PURE__ */ new Set([
|
|
|
208
273
|
]);
|
|
209
274
|
|
|
210
275
|
// packages/shared/dist/lib/cmux-autoconfig.js
|
|
211
|
-
import { existsSync as existsSync4,
|
|
276
|
+
import { existsSync as existsSync4, rmSync as rmSync2 } from "fs";
|
|
212
277
|
import { homedir as homedir3 } from "os";
|
|
213
|
-
import {
|
|
278
|
+
import { join as join4 } from "path";
|
|
214
279
|
|
|
215
280
|
// packages/shared/dist/lib/cmux-config.js
|
|
216
281
|
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
|
|
@@ -233,22 +298,22 @@ var MINIMAL_TEMPLATE = [
|
|
|
233
298
|
``
|
|
234
299
|
].join("\n");
|
|
235
300
|
function ensureSocketAutomation(opts = {}) {
|
|
236
|
-
const
|
|
237
|
-
if (!existsSync(
|
|
238
|
-
mkdirSync(dirname(
|
|
239
|
-
writeFileSync(
|
|
240
|
-
return { path:
|
|
301
|
+
const path20 = opts.path ?? defaultCmuxConfigPath();
|
|
302
|
+
if (!existsSync(path20)) {
|
|
303
|
+
mkdirSync(dirname(path20), { recursive: true });
|
|
304
|
+
writeFileSync(path20, MINIMAL_TEMPLATE);
|
|
305
|
+
return { path: path20, changed: true, alreadySet: false };
|
|
241
306
|
}
|
|
242
|
-
const text = readFileSync(
|
|
307
|
+
const text = readFileSync(path20, "utf-8");
|
|
243
308
|
const current = parse(text)?.automation?.socketControlMode;
|
|
244
309
|
if (current === AUTOMATION_MODE) {
|
|
245
|
-
return { path:
|
|
310
|
+
return { path: path20, changed: false, alreadySet: true };
|
|
246
311
|
}
|
|
247
312
|
const edits = modify(text, [...SOCKET_CONTROL_MODE_PATH], AUTOMATION_MODE, {
|
|
248
313
|
formattingOptions: { insertSpaces: true, tabSize: 2 }
|
|
249
314
|
});
|
|
250
|
-
writeFileSync(
|
|
251
|
-
return { path:
|
|
315
|
+
writeFileSync(path20, applyEdits(text, edits));
|
|
316
|
+
return { path: path20, changed: true, alreadySet: false };
|
|
252
317
|
}
|
|
253
318
|
|
|
254
319
|
// packages/shared/dist/lib/cmux-probe.js
|
|
@@ -370,9 +435,9 @@ function sleep(ms) {
|
|
|
370
435
|
function defaultStatePath() {
|
|
371
436
|
return join4(homedir3(), ".config", "squadrant", "state", "cmux-autoconfig.json");
|
|
372
437
|
}
|
|
373
|
-
function readState(
|
|
438
|
+
function readState(path20) {
|
|
374
439
|
try {
|
|
375
|
-
return JSON.parse(
|
|
440
|
+
return JSON.parse(readConfigFileSync(path20));
|
|
376
441
|
} catch {
|
|
377
442
|
return {};
|
|
378
443
|
}
|
|
@@ -388,8 +453,7 @@ async function ensureCmuxAutoConfig(opts = {}) {
|
|
|
388
453
|
if (needsRestart) {
|
|
389
454
|
const already = readState(statePath3).promptedRestart === true;
|
|
390
455
|
if (!already) {
|
|
391
|
-
|
|
392
|
-
writeFileSync3(statePath3, JSON.stringify({ promptedRestart: true }));
|
|
456
|
+
writeConfigFileSync(statePath3, JSON.stringify({ promptedRestart: true }));
|
|
393
457
|
promptedThisRun = true;
|
|
394
458
|
}
|
|
395
459
|
} else if (verdict === "reachable") {
|
|
@@ -420,25 +484,25 @@ var compatManifest = {
|
|
|
420
484
|
};
|
|
421
485
|
|
|
422
486
|
// packages/shared/dist/lib/update-check.js
|
|
423
|
-
import
|
|
424
|
-
import
|
|
487
|
+
import fs2 from "fs";
|
|
488
|
+
import path4 from "path";
|
|
425
489
|
import os3 from "os";
|
|
426
490
|
import https from "https";
|
|
427
|
-
var UPDATE_CHECK_STATE_PATH =
|
|
491
|
+
var UPDATE_CHECK_STATE_PATH = path4.join(os3.homedir(), ".config", "squadrant", "update-check.json");
|
|
428
492
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
429
493
|
var FAILURE_RETRY_MS = 60 * 60 * 1e3;
|
|
430
494
|
|
|
431
495
|
// packages/shared/dist/lib/git-worktree.js
|
|
432
496
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
433
|
-
import
|
|
434
|
-
import
|
|
497
|
+
import fs3 from "fs";
|
|
498
|
+
import path5 from "path";
|
|
435
499
|
|
|
436
500
|
// packages/shared/dist/lib/resolve-text-input.js
|
|
437
|
-
import
|
|
501
|
+
import fs4 from "fs";
|
|
438
502
|
|
|
439
503
|
// packages/shared/dist/lib/runtime-sync.js
|
|
440
|
-
import
|
|
441
|
-
import
|
|
504
|
+
import fs5 from "fs";
|
|
505
|
+
import path6 from "path";
|
|
442
506
|
|
|
443
507
|
// packages/shared/dist/lib/tool-compat.js
|
|
444
508
|
function parseSemVer(v) {
|
|
@@ -472,13 +536,13 @@ function checkToolCompat(name, rawVersion, entry) {
|
|
|
472
536
|
}
|
|
473
537
|
|
|
474
538
|
// packages/shared/dist/lib/canonical-source.js
|
|
475
|
-
import
|
|
476
|
-
import
|
|
539
|
+
import fs6 from "fs";
|
|
540
|
+
import path7 from "path";
|
|
477
541
|
|
|
478
542
|
// packages/shared/dist/lib/daily-logs.js
|
|
479
543
|
import { execSync } from "child_process";
|
|
480
|
-
import
|
|
481
|
-
import
|
|
544
|
+
import fs7 from "fs";
|
|
545
|
+
import path8 from "path";
|
|
482
546
|
import matter from "gray-matter";
|
|
483
547
|
|
|
484
548
|
// packages/core/dist/state-machine.js
|
|
@@ -1091,7 +1155,7 @@ function createDaemon(deps) {
|
|
|
1091
1155
|
}
|
|
1092
1156
|
|
|
1093
1157
|
// packages/core/dist/mailbox.js
|
|
1094
|
-
import { promises as
|
|
1158
|
+
import { promises as fs8 } from "fs";
|
|
1095
1159
|
import { join as join5 } from "path";
|
|
1096
1160
|
import { randomUUID } from "crypto";
|
|
1097
1161
|
function inboxDir(stateRoot) {
|
|
@@ -1108,7 +1172,7 @@ async function listRotatedOldestFirst(stateRoot, project) {
|
|
|
1108
1172
|
const dir = inboxDir(stateRoot);
|
|
1109
1173
|
let entries;
|
|
1110
1174
|
try {
|
|
1111
|
-
entries = await
|
|
1175
|
+
entries = await fs8.readdir(dir);
|
|
1112
1176
|
} catch {
|
|
1113
1177
|
return [];
|
|
1114
1178
|
}
|
|
@@ -1117,7 +1181,7 @@ async function listRotatedOldestFirst(stateRoot, project) {
|
|
|
1117
1181
|
}
|
|
1118
1182
|
async function readMaxSeqFromFile(file) {
|
|
1119
1183
|
try {
|
|
1120
|
-
const buf = await
|
|
1184
|
+
const buf = await fs8.readFile(file, "utf-8");
|
|
1121
1185
|
if (!buf.trim())
|
|
1122
1186
|
return 0;
|
|
1123
1187
|
const lines = buf.trim().split("\n");
|
|
@@ -1159,12 +1223,12 @@ function withProjectLock(project, fn) {
|
|
|
1159
1223
|
function appendEntry(stateRoot, project, build) {
|
|
1160
1224
|
return withProjectLock(project, async () => {
|
|
1161
1225
|
const dir = inboxDir(stateRoot);
|
|
1162
|
-
await
|
|
1226
|
+
await fs8.mkdir(dir, { recursive: true });
|
|
1163
1227
|
const file = logPath(stateRoot, project);
|
|
1164
1228
|
const lastSeq = await readMaxSeq(stateRoot, project);
|
|
1165
1229
|
const seq = lastSeq + 1;
|
|
1166
1230
|
const entry = build(seq);
|
|
1167
|
-
await
|
|
1231
|
+
await fs8.appendFile(file, JSON.stringify(entry) + "\n", { encoding: "utf-8" });
|
|
1168
1232
|
return seq;
|
|
1169
1233
|
});
|
|
1170
1234
|
}
|
|
@@ -1195,7 +1259,7 @@ function cursorPath(stateRoot, project, subscriber) {
|
|
|
1195
1259
|
async function readCursor(opts) {
|
|
1196
1260
|
let buf;
|
|
1197
1261
|
try {
|
|
1198
|
-
buf = await
|
|
1262
|
+
buf = await fs8.readFile(cursorPath(opts.stateRoot, opts.project, opts.subscriber), "utf-8");
|
|
1199
1263
|
} catch (e) {
|
|
1200
1264
|
if (e.code === "ENOENT")
|
|
1201
1265
|
return null;
|
|
@@ -1210,7 +1274,7 @@ async function readCursor(opts) {
|
|
|
1210
1274
|
}
|
|
1211
1275
|
}
|
|
1212
1276
|
async function writeCursor(opts) {
|
|
1213
|
-
await
|
|
1277
|
+
await fs8.mkdir(inboxDir(opts.stateRoot), { recursive: true });
|
|
1214
1278
|
const dest = cursorPath(opts.stateRoot, opts.project, opts.subscriber);
|
|
1215
1279
|
const tmp = `${dest}.${process.pid}.${randomUUID()}.tmp`;
|
|
1216
1280
|
const data = {
|
|
@@ -1218,7 +1282,7 @@ async function writeCursor(opts) {
|
|
|
1218
1282
|
subscriber: opts.subscriber,
|
|
1219
1283
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1220
1284
|
};
|
|
1221
|
-
const handle = await
|
|
1285
|
+
const handle = await fs8.open(tmp, "w");
|
|
1222
1286
|
try {
|
|
1223
1287
|
await handle.writeFile(JSON.stringify(data), { encoding: "utf-8" });
|
|
1224
1288
|
await handle.sync();
|
|
@@ -1226,9 +1290,9 @@ async function writeCursor(opts) {
|
|
|
1226
1290
|
await handle.close();
|
|
1227
1291
|
}
|
|
1228
1292
|
try {
|
|
1229
|
-
await
|
|
1293
|
+
await fs8.rename(tmp, dest);
|
|
1230
1294
|
} catch (e) {
|
|
1231
|
-
await
|
|
1295
|
+
await fs8.unlink(tmp).catch(() => {
|
|
1232
1296
|
});
|
|
1233
1297
|
throw e;
|
|
1234
1298
|
}
|
|
@@ -1239,7 +1303,7 @@ async function* readFromCursor(opts) {
|
|
|
1239
1303
|
for (const file of files) {
|
|
1240
1304
|
let buf;
|
|
1241
1305
|
try {
|
|
1242
|
-
buf = await
|
|
1306
|
+
buf = await fs8.readFile(file, "utf-8");
|
|
1243
1307
|
} catch (e) {
|
|
1244
1308
|
if (e.code === "ENOENT")
|
|
1245
1309
|
continue;
|
|
@@ -1265,7 +1329,7 @@ async function mailboxStats(stateRoot, project) {
|
|
|
1265
1329
|
let sizeBytes = 0;
|
|
1266
1330
|
for (const f of [file, ...rotated]) {
|
|
1267
1331
|
try {
|
|
1268
|
-
sizeBytes += (await
|
|
1332
|
+
sizeBytes += (await fs8.stat(f)).size;
|
|
1269
1333
|
} catch (e) {
|
|
1270
1334
|
if (e.code !== "ENOENT")
|
|
1271
1335
|
throw e;
|
|
@@ -1281,7 +1345,7 @@ async function mailboxStats(stateRoot, project) {
|
|
|
1281
1345
|
}
|
|
1282
1346
|
async function oldestEntryAgeMs(file) {
|
|
1283
1347
|
try {
|
|
1284
|
-
const buf = await
|
|
1348
|
+
const buf = await fs8.readFile(file, "utf-8");
|
|
1285
1349
|
const firstLine = buf.split("\n").find((l) => l.trim());
|
|
1286
1350
|
if (!firstLine)
|
|
1287
1351
|
return 0;
|
|
@@ -1296,7 +1360,7 @@ async function rotateIfNeeded(opts) {
|
|
|
1296
1360
|
const file = logPath(opts.stateRoot, opts.project);
|
|
1297
1361
|
let size = 0;
|
|
1298
1362
|
try {
|
|
1299
|
-
size = (await
|
|
1363
|
+
size = (await fs8.stat(file)).size;
|
|
1300
1364
|
} catch (e) {
|
|
1301
1365
|
if (e.code === "ENOENT")
|
|
1302
1366
|
return { rotated: false };
|
|
@@ -1312,29 +1376,29 @@ async function rotateIfNeeded(opts) {
|
|
|
1312
1376
|
const dst = `${file}.${n + 1}`;
|
|
1313
1377
|
if (n + 1 > opts.keepCount) {
|
|
1314
1378
|
try {
|
|
1315
|
-
await
|
|
1379
|
+
await fs8.unlink(src);
|
|
1316
1380
|
} catch (e) {
|
|
1317
1381
|
if (e.code !== "ENOENT")
|
|
1318
1382
|
throw e;
|
|
1319
1383
|
}
|
|
1320
1384
|
} else {
|
|
1321
1385
|
try {
|
|
1322
|
-
await
|
|
1386
|
+
await fs8.rename(src, dst);
|
|
1323
1387
|
} catch (e) {
|
|
1324
1388
|
if (e.code !== "ENOENT")
|
|
1325
1389
|
throw e;
|
|
1326
1390
|
}
|
|
1327
1391
|
}
|
|
1328
1392
|
}
|
|
1329
|
-
await
|
|
1330
|
-
await
|
|
1393
|
+
await fs8.rename(file, `${file}.1`);
|
|
1394
|
+
await fs8.writeFile(file, "", { encoding: "utf-8" });
|
|
1331
1395
|
return { rotated: true, from: file, to: `${file}.1` };
|
|
1332
1396
|
});
|
|
1333
1397
|
}
|
|
1334
1398
|
|
|
1335
1399
|
// packages/core/dist/protocol.js
|
|
1336
1400
|
import { createServer, createConnection } from "net";
|
|
1337
|
-
import { existsSync as existsSync5, unlinkSync } from "fs";
|
|
1401
|
+
import { existsSync as existsSync5, unlinkSync, chmodSync } from "fs";
|
|
1338
1402
|
var PROTOCOL_VERSION = 1;
|
|
1339
1403
|
function encodeMsg(obj) {
|
|
1340
1404
|
return JSON.stringify(obj) + "\n";
|
|
@@ -1448,6 +1512,12 @@ function startServer(sockPath, handlerOrCallbacks, onListenError = defaultListen
|
|
|
1448
1512
|
});
|
|
1449
1513
|
});
|
|
1450
1514
|
server.on("error", onListenError);
|
|
1515
|
+
server.on("listening", () => {
|
|
1516
|
+
try {
|
|
1517
|
+
chmodSync(sockPath, 384);
|
|
1518
|
+
} catch {
|
|
1519
|
+
}
|
|
1520
|
+
});
|
|
1451
1521
|
server.listen(sockPath);
|
|
1452
1522
|
return server;
|
|
1453
1523
|
}
|
|
@@ -1591,7 +1661,7 @@ function reconcileLiveness(prev, next) {
|
|
|
1591
1661
|
}
|
|
1592
1662
|
|
|
1593
1663
|
// packages/core/dist/store.js
|
|
1594
|
-
import { mkdirSync as
|
|
1664
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync4, readdirSync, renameSync, writeFileSync as writeFileSync3, existsSync as existsSync6, rmSync as rmSync3, statSync } from "fs";
|
|
1595
1665
|
import { join as join6, resolve, sep } from "path";
|
|
1596
1666
|
function safeSegment(kind, s) {
|
|
1597
1667
|
if (typeof s !== "string" || s.length === 0) {
|
|
@@ -1617,10 +1687,10 @@ function createStore(root) {
|
|
|
1617
1687
|
const taskFile = (p, id) => assertUnderRoot(join6(projDir(p), `${safeSegment("id", id)}.json`));
|
|
1618
1688
|
return {
|
|
1619
1689
|
put(rec) {
|
|
1620
|
-
|
|
1690
|
+
mkdirSync2(projDir(rec.project), { recursive: true });
|
|
1621
1691
|
const dest = taskFile(rec.project, rec.id);
|
|
1622
1692
|
const tmp = `${dest}.tmp`;
|
|
1623
|
-
|
|
1693
|
+
writeFileSync3(tmp, JSON.stringify(rec, null, 2));
|
|
1624
1694
|
renameSync(tmp, dest);
|
|
1625
1695
|
},
|
|
1626
1696
|
get(project, id) {
|
|
@@ -1628,7 +1698,7 @@ function createStore(root) {
|
|
|
1628
1698
|
if (!existsSync6(f))
|
|
1629
1699
|
return void 0;
|
|
1630
1700
|
try {
|
|
1631
|
-
return JSON.parse(
|
|
1701
|
+
return JSON.parse(readFileSync4(f, "utf-8"));
|
|
1632
1702
|
} catch {
|
|
1633
1703
|
return void 0;
|
|
1634
1704
|
}
|
|
@@ -1639,7 +1709,7 @@ function createStore(root) {
|
|
|
1639
1709
|
return [];
|
|
1640
1710
|
return readdirSync(d).filter((n) => n.endsWith(".json")).map((n) => {
|
|
1641
1711
|
try {
|
|
1642
|
-
return JSON.parse(
|
|
1712
|
+
return JSON.parse(readFileSync4(join6(d, n), "utf-8"));
|
|
1643
1713
|
} catch {
|
|
1644
1714
|
return void 0;
|
|
1645
1715
|
}
|
|
@@ -1673,7 +1743,7 @@ function createStore(root) {
|
|
|
1673
1743
|
import { homedir as homedir4 } from "os";
|
|
1674
1744
|
import { join as join7, resolve as resolve2, sep as sep2 } from "path";
|
|
1675
1745
|
import { randomBytes } from "crypto";
|
|
1676
|
-
import { mkdirSync as
|
|
1746
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync5, readdirSync as readdirSync2, renameSync as renameSync2, writeFileSync as writeFileSync4, existsSync as existsSync7, rmSync as rmSync4, statSync as statSync2 } from "fs";
|
|
1677
1747
|
var WORK_ITEM_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
1678
1748
|
|
|
1679
1749
|
// packages/core/dist/index.js
|
|
@@ -1681,9 +1751,9 @@ init_snapshot();
|
|
|
1681
1751
|
|
|
1682
1752
|
// packages/core/dist/launchd.js
|
|
1683
1753
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
1684
|
-
import { mkdirSync as
|
|
1754
|
+
import { mkdirSync as mkdirSync4, writeFileSync as writeFileSync5, readFileSync as readFileSync6, existsSync as existsSync8, openSync, writeSync, closeSync, unlinkSync as unlinkSync2, constants } from "fs";
|
|
1685
1755
|
import { homedir as homedir5 } from "os";
|
|
1686
|
-
import { dirname as
|
|
1756
|
+
import { dirname as dirname2, join as join8 } from "path";
|
|
1687
1757
|
import { fileURLToPath } from "url";
|
|
1688
1758
|
|
|
1689
1759
|
// packages/core/dist/crew-pane-reader.js
|
|
@@ -1754,10 +1824,10 @@ function makeGate(opts) {
|
|
|
1754
1824
|
import { homedir as homedir6 } from "os";
|
|
1755
1825
|
import { join as join9 } from "path";
|
|
1756
1826
|
import { spawn as realSpawn } from "child_process";
|
|
1757
|
-
import { writeFileSync as
|
|
1827
|
+
import { writeFileSync as writeFileSync7, mkdirSync as mkdirSync5 } from "fs";
|
|
1758
1828
|
|
|
1759
1829
|
// packages/core/dist/daemon/liveness-registry.js
|
|
1760
|
-
import { writeFileSync as
|
|
1830
|
+
import { writeFileSync as writeFileSync6, readFileSync as readFileSync7, renameSync as renameSync3 } from "fs";
|
|
1761
1831
|
var LivenessRegistry = class {
|
|
1762
1832
|
path;
|
|
1763
1833
|
readFile;
|
|
@@ -1767,13 +1837,13 @@ var LivenessRegistry = class {
|
|
|
1767
1837
|
this.path = opts.path;
|
|
1768
1838
|
this.readFile = opts.readFile ?? ((p) => {
|
|
1769
1839
|
try {
|
|
1770
|
-
return
|
|
1840
|
+
return readFileSync7(p, "utf-8");
|
|
1771
1841
|
} catch {
|
|
1772
1842
|
return void 0;
|
|
1773
1843
|
}
|
|
1774
1844
|
});
|
|
1775
1845
|
this.writeFile = opts.writeFile ?? ((p, c) => {
|
|
1776
|
-
|
|
1846
|
+
writeFileSync6(`${p}.tmp`, c);
|
|
1777
1847
|
renameSync3(`${p}.tmp`, p);
|
|
1778
1848
|
});
|
|
1779
1849
|
}
|
|
@@ -1840,10 +1910,10 @@ function buildContext(opts) {
|
|
|
1840
1910
|
const isPidAlive = opts.isPidAlive ?? defaultIsPidAlive;
|
|
1841
1911
|
const spawn2 = opts.spawn ?? realSpawn;
|
|
1842
1912
|
const resultsDir = join9(stateRoot, "_results");
|
|
1843
|
-
|
|
1913
|
+
mkdirSync5(resultsDir, { recursive: true });
|
|
1844
1914
|
const writeResult = (id, payload) => {
|
|
1845
1915
|
const p = join9(resultsDir, `${id}.txt`);
|
|
1846
|
-
|
|
1916
|
+
writeFileSync7(p, payload);
|
|
1847
1917
|
return p;
|
|
1848
1918
|
};
|
|
1849
1919
|
const log = (m) => process.stderr.write(`[squadrantd] ${(/* @__PURE__ */ new Date()).toISOString()} ${m}
|
|
@@ -1944,7 +2014,7 @@ function createAttach(ctx) {
|
|
|
1944
2014
|
}
|
|
1945
2015
|
|
|
1946
2016
|
// packages/core/dist/daemon/start.js
|
|
1947
|
-
import { join as join11, dirname as
|
|
2017
|
+
import { join as join11, dirname as dirname3 } from "path";
|
|
1948
2018
|
import { readdir } from "fs/promises";
|
|
1949
2019
|
|
|
1950
2020
|
// packages/core/dist/daemon/interactive-probe.js
|
|
@@ -2538,7 +2608,7 @@ function createServer2(ctx, handlers) {
|
|
|
2538
2608
|
// packages/core/dist/daemon/snapshot-gather.js
|
|
2539
2609
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
2540
2610
|
import { join as join10 } from "path";
|
|
2541
|
-
import { statSync as statSync3, openSync as openSync2, readSync, closeSync as closeSync2, readdirSync as readdirSync3, readFileSync as
|
|
2611
|
+
import { statSync as statSync3, openSync as openSync2, readSync, closeSync as closeSync2, readdirSync as readdirSync3, readFileSync as readFileSync8 } from "fs";
|
|
2542
2612
|
var SELF_PATH = fileURLToPath2(import.meta.url);
|
|
2543
2613
|
function distBuiltAt() {
|
|
2544
2614
|
try {
|
|
@@ -2547,10 +2617,10 @@ function distBuiltAt() {
|
|
|
2547
2617
|
return 0;
|
|
2548
2618
|
}
|
|
2549
2619
|
}
|
|
2550
|
-
function gatherLogStats(
|
|
2620
|
+
function gatherLogStats(path20, now, windowMs) {
|
|
2551
2621
|
let sizeBytes = 0;
|
|
2552
2622
|
try {
|
|
2553
|
-
sizeBytes = statSync3(
|
|
2623
|
+
sizeBytes = statSync3(path20).size;
|
|
2554
2624
|
} catch {
|
|
2555
2625
|
return { errorCount: 0, sizeBytes: 0, windowMs };
|
|
2556
2626
|
}
|
|
@@ -2561,7 +2631,7 @@ function gatherLogStats(path19, now, windowMs) {
|
|
|
2561
2631
|
const len = sizeBytes - start;
|
|
2562
2632
|
let text = "";
|
|
2563
2633
|
try {
|
|
2564
|
-
const fd = openSync2(
|
|
2634
|
+
const fd = openSync2(path20, "r");
|
|
2565
2635
|
try {
|
|
2566
2636
|
const buf = Buffer.alloc(len);
|
|
2567
2637
|
readSync(fd, buf, 0, len, start);
|
|
@@ -2602,7 +2672,7 @@ function gatherStoreStats(store, stateRoot, project) {
|
|
|
2602
2672
|
if (!n.endsWith(".json"))
|
|
2603
2673
|
continue;
|
|
2604
2674
|
try {
|
|
2605
|
-
JSON.parse(
|
|
2675
|
+
JSON.parse(readFileSync8(join10(dir, n), "utf-8"));
|
|
2606
2676
|
} catch {
|
|
2607
2677
|
corruptCount++;
|
|
2608
2678
|
}
|
|
@@ -2707,7 +2777,7 @@ function startDaemon(ctx, opts, pkgVersion) {
|
|
|
2707
2777
|
return out;
|
|
2708
2778
|
}
|
|
2709
2779
|
async function gatherSnapshotInputs(now) {
|
|
2710
|
-
const logPath2 = join11(
|
|
2780
|
+
const logPath2 = join11(dirname3(stateRoot), "squadrantd.log");
|
|
2711
2781
|
const tier2Projects = opts.registeredProjects ?? Object.keys(loadConfig().projects);
|
|
2712
2782
|
const projects = await Promise.all(tier2Projects.map(async (project) => {
|
|
2713
2783
|
const cursor = await readCursor({ stateRoot, project, subscriber: CURSOR_SUBSCRIBER2 });
|
|
@@ -2896,8 +2966,8 @@ function startDaemon(ctx, opts, pkgVersion) {
|
|
|
2896
2966
|
|
|
2897
2967
|
// packages/core/dist/session-freshness.js
|
|
2898
2968
|
import crypto from "crypto";
|
|
2899
|
-
import
|
|
2900
|
-
import
|
|
2969
|
+
import fs9 from "fs";
|
|
2970
|
+
import path9 from "path";
|
|
2901
2971
|
|
|
2902
2972
|
// packages/core/dist/crew-protocol.js
|
|
2903
2973
|
function buildCompletionProtocol(taskId, project) {
|
|
@@ -3159,17 +3229,16 @@ function formatInbound(text) {
|
|
|
3159
3229
|
}
|
|
3160
3230
|
|
|
3161
3231
|
// packages/core/dist/telegram/state.js
|
|
3162
|
-
import
|
|
3163
|
-
import path9 from "path";
|
|
3232
|
+
import path10 from "path";
|
|
3164
3233
|
function statePath(stateRoot) {
|
|
3165
|
-
return
|
|
3234
|
+
return path10.join(stateRoot, "telegram-state.json");
|
|
3166
3235
|
}
|
|
3167
3236
|
function topicKey(project, scope = "project") {
|
|
3168
3237
|
return `${project}::${scope}`;
|
|
3169
3238
|
}
|
|
3170
3239
|
function loadState(stateRoot) {
|
|
3171
3240
|
try {
|
|
3172
|
-
const raw =
|
|
3241
|
+
const raw = readConfigFileSync(statePath(stateRoot));
|
|
3173
3242
|
const data = JSON.parse(raw);
|
|
3174
3243
|
const result = {
|
|
3175
3244
|
offset: typeof data.offset === "number" ? data.offset : 0,
|
|
@@ -3184,8 +3253,7 @@ function loadState(stateRoot) {
|
|
|
3184
3253
|
}
|
|
3185
3254
|
}
|
|
3186
3255
|
function saveState(stateRoot, s) {
|
|
3187
|
-
|
|
3188
|
-
fs11.writeFileSync(statePath(stateRoot), JSON.stringify(s, null, 2) + "\n");
|
|
3256
|
+
writeConfigFileSync(statePath(stateRoot), JSON.stringify(s, null, 2) + "\n");
|
|
3189
3257
|
}
|
|
3190
3258
|
function setTopic(stateRoot, project, topicId, scope = "project") {
|
|
3191
3259
|
const s = loadState(stateRoot);
|
|
@@ -3276,7 +3344,7 @@ function createTelegramClient(opts) {
|
|
|
3276
3344
|
|
|
3277
3345
|
// packages/core/dist/telegram/bridge.js
|
|
3278
3346
|
import os4 from "os";
|
|
3279
|
-
import
|
|
3347
|
+
import path11 from "path";
|
|
3280
3348
|
|
|
3281
3349
|
// packages/core/dist/telegram/panels.js
|
|
3282
3350
|
var mark = (on, label) => on ? `\u2022 ${label}` : label;
|
|
@@ -3382,7 +3450,7 @@ function notifyToggle(text) {
|
|
|
3382
3450
|
}
|
|
3383
3451
|
function createTelegramBridge(opts) {
|
|
3384
3452
|
const { cfg, stateRoot, client, appendCaptainMessage: appendCaptainMessage2, log, ensureCaptainAlive, runCommand, sendReply } = opts;
|
|
3385
|
-
const configRoot = opts.configRoot ??
|
|
3453
|
+
const configRoot = opts.configRoot ?? path11.join(os4.homedir(), ".config", "squadrant");
|
|
3386
3454
|
const pollMs = cfg.pollMs ?? 1e3;
|
|
3387
3455
|
let running = false;
|
|
3388
3456
|
let lastSuccessfulPollAt = null;
|
|
@@ -3513,14 +3581,14 @@ function createTelegramBridge(opts) {
|
|
|
3513
3581
|
}
|
|
3514
3582
|
function currentEffort() {
|
|
3515
3583
|
try {
|
|
3516
|
-
return loadConfig(
|
|
3584
|
+
return loadConfig(path11.join(configRoot, "config.json")).defaults.effort ?? "balance";
|
|
3517
3585
|
} catch {
|
|
3518
3586
|
return "balance";
|
|
3519
3587
|
}
|
|
3520
3588
|
}
|
|
3521
3589
|
function projectNames() {
|
|
3522
3590
|
try {
|
|
3523
|
-
return Object.keys(loadConfig(
|
|
3591
|
+
return Object.keys(loadConfig(path11.join(configRoot, "config.json")).projects);
|
|
3524
3592
|
} catch {
|
|
3525
3593
|
return [];
|
|
3526
3594
|
}
|
|
@@ -3732,7 +3800,7 @@ function createTelegramBridge(opts) {
|
|
|
3732
3800
|
}
|
|
3733
3801
|
|
|
3734
3802
|
// packages/core/dist/telegram/setup.js
|
|
3735
|
-
import
|
|
3803
|
+
import fs10 from "fs";
|
|
3736
3804
|
|
|
3737
3805
|
// packages/core/dist/restart-daemon.js
|
|
3738
3806
|
import { execFileSync as execFileSync4 } from "child_process";
|
|
@@ -3748,14 +3816,14 @@ import { join as join13 } from "path";
|
|
|
3748
3816
|
var DEFAULT_SOCK_PATH2 = join13(homedir8(), ".config", "squadrant", "squadrant.sock");
|
|
3749
3817
|
|
|
3750
3818
|
// packages/core/dist/side-session.js
|
|
3751
|
-
import
|
|
3819
|
+
import fs11 from "fs";
|
|
3752
3820
|
|
|
3753
3821
|
// packages/core/dist/crew-spawn.js
|
|
3754
|
-
import
|
|
3822
|
+
import fs12 from "fs";
|
|
3755
3823
|
import os5 from "os";
|
|
3756
|
-
import
|
|
3757
|
-
var TEMPLATES_DIR =
|
|
3758
|
-
var STATE_ROOT =
|
|
3824
|
+
import path12 from "path";
|
|
3825
|
+
var TEMPLATES_DIR = path12.join(os5.homedir(), ".config", "squadrant", "templates");
|
|
3826
|
+
var STATE_ROOT = path12.join(os5.homedir(), ".config", "squadrant", "state");
|
|
3759
3827
|
|
|
3760
3828
|
// packages/core/dist/lifecycle-source.js
|
|
3761
3829
|
function reduceLifecycle(prev, next) {
|
|
@@ -3787,27 +3855,27 @@ import { execSync as execSync4 } from "child_process";
|
|
|
3787
3855
|
import { execSync as execSync5 } from "child_process";
|
|
3788
3856
|
|
|
3789
3857
|
// packages/agents/dist/drivers/launch-cmd.js
|
|
3790
|
-
import
|
|
3791
|
-
import
|
|
3858
|
+
import fs13 from "fs";
|
|
3859
|
+
import path13 from "path";
|
|
3792
3860
|
|
|
3793
3861
|
// packages/agents/dist/projection/cursor.js
|
|
3794
3862
|
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
3795
|
-
import
|
|
3863
|
+
import path14 from "path";
|
|
3796
3864
|
import os6 from "os";
|
|
3797
3865
|
|
|
3798
3866
|
// packages/agents/dist/projection/codex.js
|
|
3799
3867
|
import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
|
|
3800
|
-
import
|
|
3868
|
+
import path15 from "path";
|
|
3801
3869
|
import os7 from "os";
|
|
3802
3870
|
|
|
3803
3871
|
// packages/agents/dist/projection/gemini.js
|
|
3804
3872
|
import { mkdir as mkdir3, readFile as readFile3, writeFile as writeFile3 } from "fs/promises";
|
|
3805
|
-
import
|
|
3873
|
+
import path16 from "path";
|
|
3806
3874
|
import os8 from "os";
|
|
3807
3875
|
|
|
3808
3876
|
// packages/agents/dist/projection/opencode.js
|
|
3809
3877
|
import { mkdir as mkdir4, readFile as readFile4, writeFile as writeFile4 } from "fs/promises";
|
|
3810
|
-
import
|
|
3878
|
+
import path17 from "path";
|
|
3811
3879
|
import os9 from "os";
|
|
3812
3880
|
|
|
3813
3881
|
// packages/agents/dist/codex/app-server-client.js
|
|
@@ -4575,7 +4643,7 @@ var OpencodeSseBridge = class {
|
|
|
4575
4643
|
|
|
4576
4644
|
// packages/agents/dist/interactive/claude.js
|
|
4577
4645
|
import { execSync as execSync6 } from "child_process";
|
|
4578
|
-
import { readFileSync as
|
|
4646
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
4579
4647
|
import { homedir as homedir10 } from "os";
|
|
4580
4648
|
import { join as join15 } from "path";
|
|
4581
4649
|
var nextAskUserQuestionRequestId = Date.now();
|
|
@@ -5334,9 +5402,9 @@ var NotifierRegistry = class {
|
|
|
5334
5402
|
};
|
|
5335
5403
|
|
|
5336
5404
|
// packages/workspaces/dist/workspaces/obsidian.js
|
|
5337
|
-
import
|
|
5405
|
+
import fs14 from "fs/promises";
|
|
5338
5406
|
import { existsSync as existsSync10 } from "fs";
|
|
5339
|
-
import
|
|
5407
|
+
import path18 from "path";
|
|
5340
5408
|
|
|
5341
5409
|
// packages/workspaces/dist/cmux-daemon/events-bridge.js
|
|
5342
5410
|
import { spawn as nodeSpawn2 } from "child_process";
|
|
@@ -5473,7 +5541,7 @@ var CmuxEventsBridge = class {
|
|
|
5473
5541
|
};
|
|
5474
5542
|
|
|
5475
5543
|
// packages/workspaces/dist/cmux-daemon/daemon-cmux.js
|
|
5476
|
-
import { readdirSync as readdirSync4, readFileSync as
|
|
5544
|
+
import { readdirSync as readdirSync4, readFileSync as readFileSync10 } from "fs";
|
|
5477
5545
|
import { join as join16 } from "path";
|
|
5478
5546
|
import { homedir as homedir11 } from "os";
|
|
5479
5547
|
|
|
@@ -5602,14 +5670,14 @@ var DaemonCmux = class {
|
|
|
5602
5670
|
} catch (e) {
|
|
5603
5671
|
throw new Error(`liveness: could not read cmux state dir ${dir}: ${e.message}`);
|
|
5604
5672
|
}
|
|
5605
|
-
return readLivenessSnapshot(files, (f) =>
|
|
5673
|
+
return readLivenessSnapshot(files, (f) => readFileSync10(join16(dir, f), "utf-8"), projects);
|
|
5606
5674
|
}
|
|
5607
5675
|
};
|
|
5608
5676
|
|
|
5609
5677
|
// packages/workspaces/dist/cmux-daemon/cmux-store-source.js
|
|
5610
5678
|
import { join as join17 } from "path";
|
|
5611
5679
|
import { homedir as homedir12 } from "os";
|
|
5612
|
-
import { watch, readdirSync as readdirSync5, readFileSync as
|
|
5680
|
+
import { watch, readdirSync as readdirSync5, readFileSync as readFileSync11, existsSync as existsSync11 } from "fs";
|
|
5613
5681
|
var CmuxStoreSource = class {
|
|
5614
5682
|
name = "cmux-store";
|
|
5615
5683
|
stateDir;
|
|
@@ -5763,9 +5831,9 @@ function defaultListFiles(dir) {
|
|
|
5763
5831
|
return [];
|
|
5764
5832
|
}
|
|
5765
5833
|
}
|
|
5766
|
-
function defaultReadFile(
|
|
5834
|
+
function defaultReadFile(path20) {
|
|
5767
5835
|
try {
|
|
5768
|
-
return
|
|
5836
|
+
return readFileSync11(path20, "utf-8");
|
|
5769
5837
|
} catch {
|
|
5770
5838
|
return void 0;
|
|
5771
5839
|
}
|
|
@@ -5782,7 +5850,7 @@ function defaultWatchDir(dir, cb) {
|
|
|
5782
5850
|
// packages/workspaces/dist/native-hooks/native-hook-source.js
|
|
5783
5851
|
import { join as join18 } from "path";
|
|
5784
5852
|
import { homedir as homedir13 } from "os";
|
|
5785
|
-
import { mkdirSync as
|
|
5853
|
+
import { mkdirSync as mkdirSync6, readFileSync as readFileSync12, writeFileSync as writeFileSync8 } from "fs";
|
|
5786
5854
|
var CLAUDE_HOOK_EVENTS = [
|
|
5787
5855
|
["SessionStart", "session-start"],
|
|
5788
5856
|
["UserPromptSubmit", "prompt-submit"],
|
|
@@ -5962,16 +6030,16 @@ function extractDetail(sub, payload) {
|
|
|
5962
6030
|
}
|
|
5963
6031
|
return void 0;
|
|
5964
6032
|
}
|
|
5965
|
-
function defaultReadFile2(
|
|
6033
|
+
function defaultReadFile2(path20) {
|
|
5966
6034
|
try {
|
|
5967
|
-
return
|
|
6035
|
+
return readFileSync12(path20, "utf-8");
|
|
5968
6036
|
} catch {
|
|
5969
6037
|
return void 0;
|
|
5970
6038
|
}
|
|
5971
6039
|
}
|
|
5972
|
-
function defaultWriteFile(
|
|
5973
|
-
|
|
5974
|
-
|
|
6040
|
+
function defaultWriteFile(path20, content) {
|
|
6041
|
+
mkdirSync6(path20.replace(/\/[^/]+$/, ""), { recursive: true });
|
|
6042
|
+
writeFileSync8(path20, content, "utf-8");
|
|
5975
6043
|
}
|
|
5976
6044
|
|
|
5977
6045
|
// packages/workspaces/dist/crew-pane.js
|
|
@@ -6042,17 +6110,16 @@ async function resendCrewFirstTurn(runtime, captainName, project, name, message)
|
|
|
6042
6110
|
}
|
|
6043
6111
|
|
|
6044
6112
|
// packages/cli/src/lib/daemon-restart-broadcast.ts
|
|
6045
|
-
import
|
|
6046
|
-
import path18 from "path";
|
|
6113
|
+
import path19 from "path";
|
|
6047
6114
|
function statePath2(stateRoot) {
|
|
6048
|
-
return
|
|
6115
|
+
return path19.join(stateRoot, "daemon-restart-state.json");
|
|
6049
6116
|
}
|
|
6050
6117
|
function computeRestartSignature(version, buildMtimeMs) {
|
|
6051
6118
|
return `${version}::${buildMtimeMs}`;
|
|
6052
6119
|
}
|
|
6053
6120
|
function readPersistedRestartSignature(stateRoot) {
|
|
6054
6121
|
try {
|
|
6055
|
-
const raw =
|
|
6122
|
+
const raw = readConfigFileSync(statePath2(stateRoot));
|
|
6056
6123
|
const data = JSON.parse(raw);
|
|
6057
6124
|
return typeof data.signature === "string" ? data.signature : null;
|
|
6058
6125
|
} catch {
|
|
@@ -6060,8 +6127,7 @@ function readPersistedRestartSignature(stateRoot) {
|
|
|
6060
6127
|
}
|
|
6061
6128
|
}
|
|
6062
6129
|
function writePersistedRestartSignature(stateRoot, signature) {
|
|
6063
|
-
|
|
6064
|
-
fs17.writeFileSync(statePath2(stateRoot), JSON.stringify({ signature }, null, 2) + "\n");
|
|
6130
|
+
writeConfigFileSync(statePath2(stateRoot), JSON.stringify({ signature }, null, 2) + "\n");
|
|
6065
6131
|
}
|
|
6066
6132
|
function restartNotice(version, isDevRebuild) {
|
|
6067
6133
|
const suffix = isDevRebuild ? " (dev build)" : "";
|
|
@@ -6095,12 +6161,12 @@ async function maybeBroadcastDaemonRestart(opts) {
|
|
|
6095
6161
|
|
|
6096
6162
|
// packages/cli/src/squadrantd.ts
|
|
6097
6163
|
var SELF_PATH2 = fileURLToPath3(import.meta.url);
|
|
6098
|
-
var CLI_BIN = join19(
|
|
6164
|
+
var CLI_BIN = join19(dirname4(SELF_PATH2), "index.js");
|
|
6099
6165
|
var DAEMON_SOCK = join19(homedir14(), ".config", "squadrant", "squadrant.sock");
|
|
6100
6166
|
function readPkgVersion() {
|
|
6101
6167
|
try {
|
|
6102
|
-
const pkgPath = join19(
|
|
6103
|
-
return JSON.parse(
|
|
6168
|
+
const pkgPath = join19(dirname4(SELF_PATH2), "..", "package.json");
|
|
6169
|
+
return JSON.parse(readFileSync13(pkgPath, "utf-8")).version ?? "unknown";
|
|
6104
6170
|
} catch {
|
|
6105
6171
|
return "unknown";
|
|
6106
6172
|
}
|
|
@@ -6122,7 +6188,7 @@ function buildTelegramBridge(cfg, stateRoot, log) {
|
|
|
6122
6188
|
return createTelegramBridge({
|
|
6123
6189
|
cfg,
|
|
6124
6190
|
stateRoot,
|
|
6125
|
-
configRoot:
|
|
6191
|
+
configRoot: dirname4(stateRoot),
|
|
6126
6192
|
client,
|
|
6127
6193
|
appendCaptainMessage,
|
|
6128
6194
|
log,
|
|
@@ -6390,6 +6456,9 @@ function logCrashMarker(kind, err) {
|
|
|
6390
6456
|
process.stderr.write(`[squadrantd] ${(/* @__PURE__ */ new Date()).toISOString()} ${kind} pid=${process.pid} error=${message}
|
|
6391
6457
|
`);
|
|
6392
6458
|
}
|
|
6459
|
+
function isMonorepoCheckout(scriptPath, dirExists = existsSync12) {
|
|
6460
|
+
return dirExists(join19(dirname4(scriptPath), "..", "packages"));
|
|
6461
|
+
}
|
|
6393
6462
|
if (process.argv[1] && process.argv[1].endsWith("squadrantd.js")) {
|
|
6394
6463
|
process.on("uncaughtException", (err) => {
|
|
6395
6464
|
logCrashMarker("uncaughtException", err);
|
|
@@ -6405,6 +6474,13 @@ if (process.argv[1] && process.argv[1].endsWith("squadrantd.js")) {
|
|
|
6405
6474
|
process.stdout.write("squadrantd: launchd-managed daemon entry (no CLI args). Use `squadrant` for commands.\n");
|
|
6406
6475
|
process.exit(0);
|
|
6407
6476
|
}
|
|
6477
|
+
if (isMonorepoCheckout(process.argv[1])) {
|
|
6478
|
+
process.stderr.write(
|
|
6479
|
+
`[squadrantd] refusing to start: '${process.argv[1]}' is a monorepo/worktree checkout, not an installed copy \u2014 it must never become the shared production daemon (#670). This entry takes no CLI flags/sockPath override; for local testing, import startSquadrantd({ sockPath, ... }) programmatically instead of running this entry directly, or run the test suite (\`pnpm test\`).
|
|
6480
|
+
`
|
|
6481
|
+
);
|
|
6482
|
+
process.exit(1);
|
|
6483
|
+
}
|
|
6408
6484
|
const sock = join19(homedir14(), ".config", "squadrant", "squadrant.sock");
|
|
6409
6485
|
if (await isDaemonSocketLive(sock)) {
|
|
6410
6486
|
process.stderr.write(`[squadrantd] refusing to start: a live daemon already owns ${sock}
|
|
@@ -6422,6 +6498,7 @@ if (process.argv[1] && process.argv[1].endsWith("squadrantd.js")) {
|
|
|
6422
6498
|
export {
|
|
6423
6499
|
defaultIsPidAlive,
|
|
6424
6500
|
discoverCaptainSurface,
|
|
6501
|
+
isMonorepoCheckout,
|
|
6425
6502
|
startSquadrantd
|
|
6426
6503
|
};
|
|
6427
6504
|
//# sourceMappingURL=squadrantd.js.map
|