@caddis/cli 0.4.98 → 0.4.99
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 +4 -0
- package/bundles/antigravity-plugin/plugin.json +1 -1
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_exit.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_file_lock.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_frontmatter.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_redact.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_roadmap.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_rows.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_status.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_tidy.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_todo.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_workstreams.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_worktree_safety.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/caddis_guide.json +2 -2
- package/bundles/manifest.json +2 -2
- package/dist/cli.js +381 -157
- package/dist/ui/assets/{Activity-CvEIJlnE.js → Activity-D69HiVjS.js} +1 -1
- package/dist/ui/assets/{Guide-BxS9L55s.js → Guide-BUXTwb19.js} +1 -1
- package/dist/ui/assets/{RoadmapTab-CqlWs7dJ.js → RoadmapTab-CjYa5fye.js} +1 -1
- package/dist/ui/assets/{index-DSxeWPax.js → index--fRgH-8i.js} +49 -44
- package/dist/ui/index.html +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1209,7 +1209,7 @@ var require_command = __commonJS({
|
|
|
1209
1209
|
"use strict";
|
|
1210
1210
|
var EventEmitter = __require("events").EventEmitter;
|
|
1211
1211
|
var childProcess = __require("child_process");
|
|
1212
|
-
var
|
|
1212
|
+
var path28 = __require("path");
|
|
1213
1213
|
var fs = __require("fs");
|
|
1214
1214
|
var process3 = __require("process");
|
|
1215
1215
|
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
@@ -2222,9 +2222,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2222
2222
|
let launchWithNode = false;
|
|
2223
2223
|
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
2224
2224
|
function findFile(baseDir, baseName) {
|
|
2225
|
-
const localBin =
|
|
2225
|
+
const localBin = path28.resolve(baseDir, baseName);
|
|
2226
2226
|
if (fs.existsSync(localBin)) return localBin;
|
|
2227
|
-
if (sourceExt.includes(
|
|
2227
|
+
if (sourceExt.includes(path28.extname(baseName))) return void 0;
|
|
2228
2228
|
const foundExt = sourceExt.find(
|
|
2229
2229
|
(ext) => fs.existsSync(`${localBin}${ext}`)
|
|
2230
2230
|
);
|
|
@@ -2242,17 +2242,17 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2242
2242
|
} catch {
|
|
2243
2243
|
resolvedScriptPath = this._scriptPath;
|
|
2244
2244
|
}
|
|
2245
|
-
executableDir =
|
|
2246
|
-
|
|
2245
|
+
executableDir = path28.resolve(
|
|
2246
|
+
path28.dirname(resolvedScriptPath),
|
|
2247
2247
|
executableDir
|
|
2248
2248
|
);
|
|
2249
2249
|
}
|
|
2250
2250
|
if (executableDir) {
|
|
2251
2251
|
let localFile = findFile(executableDir, executableFile);
|
|
2252
2252
|
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
2253
|
-
const legacyName =
|
|
2253
|
+
const legacyName = path28.basename(
|
|
2254
2254
|
this._scriptPath,
|
|
2255
|
-
|
|
2255
|
+
path28.extname(this._scriptPath)
|
|
2256
2256
|
);
|
|
2257
2257
|
if (legacyName !== this._name) {
|
|
2258
2258
|
localFile = findFile(
|
|
@@ -2263,7 +2263,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2263
2263
|
}
|
|
2264
2264
|
executableFile = localFile || executableFile;
|
|
2265
2265
|
}
|
|
2266
|
-
launchWithNode = sourceExt.includes(
|
|
2266
|
+
launchWithNode = sourceExt.includes(path28.extname(executableFile));
|
|
2267
2267
|
let proc;
|
|
2268
2268
|
if (process3.platform !== "win32") {
|
|
2269
2269
|
if (launchWithNode) {
|
|
@@ -3178,7 +3178,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3178
3178
|
* @return {Command}
|
|
3179
3179
|
*/
|
|
3180
3180
|
nameFromFilename(filename) {
|
|
3181
|
-
this._name =
|
|
3181
|
+
this._name = path28.basename(filename, path28.extname(filename));
|
|
3182
3182
|
return this;
|
|
3183
3183
|
}
|
|
3184
3184
|
/**
|
|
@@ -3192,9 +3192,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3192
3192
|
* @param {string} [path]
|
|
3193
3193
|
* @return {(string|null|Command)}
|
|
3194
3194
|
*/
|
|
3195
|
-
executableDir(
|
|
3196
|
-
if (
|
|
3197
|
-
this._executableDir =
|
|
3195
|
+
executableDir(path29) {
|
|
3196
|
+
if (path29 === void 0) return this._executableDir;
|
|
3197
|
+
this._executableDir = path29;
|
|
3198
3198
|
return this;
|
|
3199
3199
|
}
|
|
3200
3200
|
/**
|
|
@@ -4907,10 +4907,10 @@ function keysFilePath(env) {
|
|
|
4907
4907
|
const expanded = expandHome(configured);
|
|
4908
4908
|
return isAbsolute(expanded) ? expanded : expanded;
|
|
4909
4909
|
}
|
|
4910
|
-
function parseKeysFile(
|
|
4910
|
+
function parseKeysFile(path28) {
|
|
4911
4911
|
let text2;
|
|
4912
4912
|
try {
|
|
4913
|
-
text2 = readFileSync3(
|
|
4913
|
+
text2 = readFileSync3(path28, "utf8");
|
|
4914
4914
|
} catch {
|
|
4915
4915
|
return {};
|
|
4916
4916
|
}
|
|
@@ -5022,18 +5022,18 @@ function upsertKeyLines(existing, updates) {
|
|
|
5022
5022
|
if (!text2.endsWith("\n")) text2 += "\n";
|
|
5023
5023
|
return text2;
|
|
5024
5024
|
}
|
|
5025
|
-
function restrictPermissions(
|
|
5025
|
+
function restrictPermissions(path28) {
|
|
5026
5026
|
if (process.platform === "win32") return null;
|
|
5027
5027
|
try {
|
|
5028
|
-
chmodSync(
|
|
5028
|
+
chmodSync(path28, 384);
|
|
5029
5029
|
return null;
|
|
5030
5030
|
} catch (error) {
|
|
5031
5031
|
return error instanceof Error ? error.message : String(error);
|
|
5032
5032
|
}
|
|
5033
5033
|
}
|
|
5034
5034
|
async function keys(options = {}) {
|
|
5035
|
-
const
|
|
5036
|
-
const fileKeys = parseKeysFile(
|
|
5035
|
+
const path28 = keysFilePath(process.env);
|
|
5036
|
+
const fileKeys = parseKeysFile(path28);
|
|
5037
5037
|
const names = Object.keys(PROVIDERS).sort();
|
|
5038
5038
|
const current = names.map((name) => {
|
|
5039
5039
|
const preset = PROVIDERS[name];
|
|
@@ -5049,7 +5049,7 @@ async function keys(options = {}) {
|
|
|
5049
5049
|
if (options.check) {
|
|
5050
5050
|
const configured = current.filter((entry) => entry.value);
|
|
5051
5051
|
if (!configured.length) {
|
|
5052
|
-
process.stdout.write(`no provider keys configured (looked in $ENV and ${
|
|
5052
|
+
process.stdout.write(`no provider keys configured (looked in $ENV and ${path28})
|
|
5053
5053
|
`);
|
|
5054
5054
|
return 1;
|
|
5055
5055
|
}
|
|
@@ -5064,7 +5064,7 @@ async function keys(options = {}) {
|
|
|
5064
5064
|
return bad ? 1 : 0;
|
|
5065
5065
|
}
|
|
5066
5066
|
Ie("caddis keys");
|
|
5067
|
-
process.stdout.write(` keys file: ${
|
|
5067
|
+
process.stdout.write(` keys file: ${path28}
|
|
5068
5068
|
|
|
5069
5069
|
`);
|
|
5070
5070
|
for (const entry of current) {
|
|
@@ -5124,20 +5124,20 @@ async function keys(options = {}) {
|
|
|
5124
5124
|
return 0;
|
|
5125
5125
|
}
|
|
5126
5126
|
if (options.dryRun) {
|
|
5127
|
-
Se(`dry run \u2014 would write ${Object.keys(collected).join(", ")} to ${
|
|
5127
|
+
Se(`dry run \u2014 would write ${Object.keys(collected).join(", ")} to ${path28}`);
|
|
5128
5128
|
return 0;
|
|
5129
5129
|
}
|
|
5130
5130
|
let existing = "";
|
|
5131
5131
|
try {
|
|
5132
|
-
existing = readFileSync4(
|
|
5132
|
+
existing = readFileSync4(path28, "utf8");
|
|
5133
5133
|
} catch {
|
|
5134
5134
|
existing = "";
|
|
5135
5135
|
}
|
|
5136
|
-
mkdirSync2(dirname(
|
|
5137
|
-
writeFileSync(
|
|
5138
|
-
const permWarning = restrictPermissions(
|
|
5136
|
+
mkdirSync2(dirname(path28), { recursive: true });
|
|
5137
|
+
writeFileSync(path28, upsertKeyLines(existing, collected), { encoding: "utf8" });
|
|
5138
|
+
const permWarning = restrictPermissions(path28);
|
|
5139
5139
|
process.stdout.write(`
|
|
5140
|
-
wrote ${Object.keys(collected).join(", ")} to ${
|
|
5140
|
+
wrote ${Object.keys(collected).join(", ")} to ${path28}
|
|
5141
5141
|
`);
|
|
5142
5142
|
if (permWarning) process.stdout.write(color2.yellow(` could not set 0600 on the keys file: ${permWarning}
|
|
5143
5143
|
`));
|
|
@@ -5752,7 +5752,7 @@ function hubHome(home) {
|
|
|
5752
5752
|
function sessionsPath(home) {
|
|
5753
5753
|
return path7.join(hubDir(home), "sessions.json");
|
|
5754
5754
|
}
|
|
5755
|
-
var configPath, registryPath, keyPath, lockPath, auditPath;
|
|
5755
|
+
var configPath, registryPath, keyPath, lockPath, logPath, auditPath;
|
|
5756
5756
|
var init_paths = __esm({
|
|
5757
5757
|
"src/hub/paths.ts"() {
|
|
5758
5758
|
"use strict";
|
|
@@ -5761,6 +5761,7 @@ var init_paths = __esm({
|
|
|
5761
5761
|
registryPath = (home) => path7.join(hubDir(home), "repos.json");
|
|
5762
5762
|
keyPath = (home) => path7.join(hubDir(home), "key");
|
|
5763
5763
|
lockPath = (home) => path7.join(hubDir(home), "hub.lock");
|
|
5764
|
+
logPath = (home) => path7.join(hubDir(home), "hub.log");
|
|
5764
5765
|
auditPath = (home) => path7.join(hubHome(home), "audit.jsonl");
|
|
5765
5766
|
}
|
|
5766
5767
|
});
|
|
@@ -5822,9 +5823,23 @@ async function enableAutostart(deps = {}) {
|
|
|
5822
5823
|
const kind = kindOf(deps.platform ?? process.platform);
|
|
5823
5824
|
if (kind === "win") {
|
|
5824
5825
|
const vbs = vbsPath(home);
|
|
5825
|
-
|
|
5826
|
+
const text2 = buildVbs(node, entry);
|
|
5827
|
+
writeText(vbs, text2);
|
|
5826
5828
|
const r2 = await runCmd("schtasks", schtasksCreateArgs(vbs));
|
|
5827
|
-
|
|
5829
|
+
const appData = appDataOf(deps);
|
|
5830
|
+
if (r2.ok) {
|
|
5831
|
+
if (appData) rmSync3(startupVbsPath(appData), { force: true });
|
|
5832
|
+
return { ok: true, message: `caddis hub autostart enabled (logon task ${TASK_NAME})` };
|
|
5833
|
+
}
|
|
5834
|
+
if (!appData) {
|
|
5835
|
+
return { ok: false, message: `schtasks /Create failed (exit ${r2.code}) and APPDATA is not set, so there is no Startup folder` };
|
|
5836
|
+
}
|
|
5837
|
+
const startup = startupVbsPath(appData);
|
|
5838
|
+
writeText(startup, text2);
|
|
5839
|
+
return {
|
|
5840
|
+
ok: true,
|
|
5841
|
+
message: `caddis hub autostart enabled (Startup folder: ${startup}); the logon task failed (schtasks exit ${r2.code})`
|
|
5842
|
+
};
|
|
5828
5843
|
}
|
|
5829
5844
|
if (kind === "mac") {
|
|
5830
5845
|
const file2 = plistPath(home);
|
|
@@ -5843,7 +5858,12 @@ async function disableAutostart(deps = {}) {
|
|
|
5843
5858
|
if (kind === "win") {
|
|
5844
5859
|
const r2 = await runCmd("schtasks", schtasksDeleteArgs());
|
|
5845
5860
|
rmSync3(vbsPath(home), { force: true });
|
|
5846
|
-
|
|
5861
|
+
const appData = appDataOf(deps);
|
|
5862
|
+
const startup = appData ? startupVbsPath(appData) : null;
|
|
5863
|
+
const hadStartup = startup !== null && existsSync6(startup);
|
|
5864
|
+
if (startup) rmSync3(startup, { force: true });
|
|
5865
|
+
const removed = [r2.ok ? `logon task ${TASK_NAME}` : "", hadStartup ? "Startup folder launcher" : ""].filter(Boolean);
|
|
5866
|
+
return removed.length ? { ok: true, message: `caddis hub autostart disabled (removed ${removed.join(" and ")})` } : { ok: true, message: "caddis hub autostart was not enabled (no logon task or Startup launcher to remove)" };
|
|
5847
5867
|
}
|
|
5848
5868
|
if (kind === "mac") {
|
|
5849
5869
|
const file = plistPath(home);
|
|
@@ -5858,10 +5878,18 @@ async function autostartStatus(deps = {}) {
|
|
|
5858
5878
|
const home = deps.home ?? caddisHome();
|
|
5859
5879
|
const runCmd = deps.runCmd ?? defaultRun;
|
|
5860
5880
|
const kind = kindOf(deps.platform ?? process.platform);
|
|
5861
|
-
|
|
5881
|
+
if (kind === "win") {
|
|
5882
|
+
const task = (await runCmd("schtasks", schtasksQueryArgs())).ok;
|
|
5883
|
+
const appData = appDataOf(deps);
|
|
5884
|
+
const startup = appData ? startupVbsPath(appData) : null;
|
|
5885
|
+
const how = [task ? `logon task ${TASK_NAME}` : "", startup && existsSync6(startup) ? `Startup folder: ${startup}` : ""];
|
|
5886
|
+
const on = how.filter(Boolean);
|
|
5887
|
+
return on.length ? { ok: true, message: `caddis hub autostart is enabled (${on.join("; ")})` } : { ok: false, message: "caddis hub autostart is not enabled" };
|
|
5888
|
+
}
|
|
5889
|
+
const enabled = existsSync6(kind === "mac" ? plistPath(home) : desktopPath(home));
|
|
5862
5890
|
return { ok: enabled, message: enabled ? "caddis hub autostart is enabled" : "caddis hub autostart is not enabled" };
|
|
5863
5891
|
}
|
|
5864
|
-
var TASK_NAME, MAC_LABEL, CMD_TIMEOUT_MS, vbsPath, schtasksDeleteArgs, schtasksQueryArgs, xml, plistPath, desktopPath, defaultRun, kindOf;
|
|
5892
|
+
var TASK_NAME, MAC_LABEL, CMD_TIMEOUT_MS, vbsPath, startupVbsPath, schtasksDeleteArgs, schtasksQueryArgs, xml, plistPath, desktopPath, defaultRun, appDataOf, kindOf;
|
|
5865
5893
|
var init_autostart = __esm({
|
|
5866
5894
|
"src/hub/autostart.ts"() {
|
|
5867
5895
|
"use strict";
|
|
@@ -5872,6 +5900,7 @@ var init_autostart = __esm({
|
|
|
5872
5900
|
MAC_LABEL = "dev.caddis.hub";
|
|
5873
5901
|
CMD_TIMEOUT_MS = 3e4;
|
|
5874
5902
|
vbsPath = (home) => path8.join(hubDir(home), "autostart.vbs");
|
|
5903
|
+
startupVbsPath = (appData) => path8.join(appData, "Microsoft", "Windows", "Start Menu", "Programs", "Startup", `${TASK_NAME}.vbs`);
|
|
5875
5904
|
schtasksDeleteArgs = () => ["/Delete", "/TN", TASK_NAME, "/F"];
|
|
5876
5905
|
schtasksQueryArgs = () => ["/Query", "/TN", TASK_NAME];
|
|
5877
5906
|
xml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
@@ -5881,6 +5910,7 @@ var init_autostart = __esm({
|
|
|
5881
5910
|
const r2 = await run(cmd, args, { timeout: CMD_TIMEOUT_MS });
|
|
5882
5911
|
return { ok: r2.ok, code: r2.code };
|
|
5883
5912
|
};
|
|
5913
|
+
appDataOf = (deps) => deps.appData ?? process.env.APPDATA;
|
|
5884
5914
|
kindOf = (p2) => p2 === "win32" ? "win" : p2 === "darwin" ? "mac" : "linux";
|
|
5885
5915
|
}
|
|
5886
5916
|
});
|
|
@@ -5890,7 +5920,7 @@ import { mkdirSync as mkdirSync4, readFileSync as readFileSync6, renameSync as r
|
|
|
5890
5920
|
import path9 from "path";
|
|
5891
5921
|
import { randomBytes } from "crypto";
|
|
5892
5922
|
function defaultConfig() {
|
|
5893
|
-
return { schema: 1, port: DEFAULT_PORT, accounts: {}, pinned: [], hidden: [] };
|
|
5923
|
+
return { schema: 1, port: DEFAULT_PORT, accounts: {}, pinned: [], hidden: [], auto_update: true };
|
|
5894
5924
|
}
|
|
5895
5925
|
function defaultRegistry() {
|
|
5896
5926
|
return { schema: 1, repos: [] };
|
|
@@ -5958,6 +5988,7 @@ function normalizeConfig(raw) {
|
|
|
5958
5988
|
}
|
|
5959
5989
|
d3.pinned = strings(raw.pinned);
|
|
5960
5990
|
d3.hidden = strings(raw.hidden);
|
|
5991
|
+
if (raw.auto_update === false) d3.auto_update = false;
|
|
5961
5992
|
return d3;
|
|
5962
5993
|
}
|
|
5963
5994
|
function normalizeRegistry(raw) {
|
|
@@ -6188,12 +6219,42 @@ var init_lock = __esm({
|
|
|
6188
6219
|
}
|
|
6189
6220
|
});
|
|
6190
6221
|
|
|
6222
|
+
// src/hub/hubLog.ts
|
|
6223
|
+
import { appendFileSync, mkdirSync as mkdirSync7, renameSync as renameSync3, statSync } from "fs";
|
|
6224
|
+
import path12 from "path";
|
|
6225
|
+
function hubLog(text2, home, now = Date.now) {
|
|
6226
|
+
try {
|
|
6227
|
+
process.stderr.write(`${text2}
|
|
6228
|
+
`);
|
|
6229
|
+
} catch {
|
|
6230
|
+
}
|
|
6231
|
+
const file = logPath(home);
|
|
6232
|
+
try {
|
|
6233
|
+
mkdirSync7(path12.dirname(file), { recursive: true, mode: 448 });
|
|
6234
|
+
try {
|
|
6235
|
+
if (statSync(file).size > LOG_MAX_BYTES) renameSync3(file, `${file}.1`);
|
|
6236
|
+
} catch {
|
|
6237
|
+
}
|
|
6238
|
+
appendFileSync(file, `${new Date(now()).toISOString()} ${text2.replace(/[\r\n]+/g, " ")}
|
|
6239
|
+
`, { mode: 384 });
|
|
6240
|
+
} catch {
|
|
6241
|
+
}
|
|
6242
|
+
}
|
|
6243
|
+
var LOG_MAX_BYTES;
|
|
6244
|
+
var init_hubLog = __esm({
|
|
6245
|
+
"src/hub/hubLog.ts"() {
|
|
6246
|
+
"use strict";
|
|
6247
|
+
init_paths();
|
|
6248
|
+
LOG_MAX_BYTES = 256 * 1024;
|
|
6249
|
+
}
|
|
6250
|
+
});
|
|
6251
|
+
|
|
6191
6252
|
// src/hub/restart.ts
|
|
6192
6253
|
import { readFileSync as readFileSync9 } from "fs";
|
|
6193
|
-
import
|
|
6254
|
+
import path13 from "path";
|
|
6194
6255
|
function readInstalledVersion2(packageRoot) {
|
|
6195
6256
|
try {
|
|
6196
|
-
const parsed = JSON.parse(readFileSync9(
|
|
6257
|
+
const parsed = JSON.parse(readFileSync9(path13.join(packageRoot, "package.json"), "utf8"));
|
|
6197
6258
|
return typeof parsed.version === "string" && parsed.version ? parsed.version : null;
|
|
6198
6259
|
} catch {
|
|
6199
6260
|
return null;
|
|
@@ -6286,11 +6347,136 @@ var init_restart = __esm({
|
|
|
6286
6347
|
}
|
|
6287
6348
|
});
|
|
6288
6349
|
|
|
6350
|
+
// src/hub/selfUpdate.ts
|
|
6351
|
+
import path14 from "path";
|
|
6352
|
+
async function fetchLatestVersion(fetchFn = fetch) {
|
|
6353
|
+
const res = await fetchFn(REGISTRY_URL, {
|
|
6354
|
+
headers: { accept: "application/json" },
|
|
6355
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS)
|
|
6356
|
+
});
|
|
6357
|
+
if (!res.ok) throw new Error(`the npm registry answered HTTP ${res.status}`);
|
|
6358
|
+
const body = await res.json();
|
|
6359
|
+
return typeof body.version === "string" && PLAIN_VERSION.test(body.version) ? body.version : null;
|
|
6360
|
+
}
|
|
6361
|
+
function isGlobalInstall(packageRoot, globalRoot, platform = process.platform) {
|
|
6362
|
+
const p2 = platform === "win32" ? path14.win32 : path14.posix;
|
|
6363
|
+
const norm = (dir) => {
|
|
6364
|
+
const r2 = p2.resolve(dir).replace(/[\\/]+$/, "");
|
|
6365
|
+
return platform === "win32" ? r2.toLowerCase() : r2;
|
|
6366
|
+
};
|
|
6367
|
+
return norm(packageRoot) === norm(p2.join(globalRoot, "@caddis", "cli"));
|
|
6368
|
+
}
|
|
6369
|
+
function createUpdater(deps) {
|
|
6370
|
+
const tried = /* @__PURE__ */ new Map();
|
|
6371
|
+
const noted = /* @__PURE__ */ new Set();
|
|
6372
|
+
let globalRoot = null;
|
|
6373
|
+
let installing = false;
|
|
6374
|
+
let running = Promise.resolve();
|
|
6375
|
+
let cancel = null;
|
|
6376
|
+
let stopped = false;
|
|
6377
|
+
const once = (key, text2) => {
|
|
6378
|
+
if (noted.has(key)) return;
|
|
6379
|
+
noted.add(key);
|
|
6380
|
+
deps.log(text2);
|
|
6381
|
+
};
|
|
6382
|
+
async function isGlobal() {
|
|
6383
|
+
globalRoot ??= await deps.globalRoot();
|
|
6384
|
+
return globalRoot !== null && isGlobalInstall(deps.packageRoot, globalRoot, deps.platform);
|
|
6385
|
+
}
|
|
6386
|
+
async function check2() {
|
|
6387
|
+
const disk = deps.readVersion();
|
|
6388
|
+
if (disk !== null && disk !== deps.currentVersion) {
|
|
6389
|
+
once(`disk:${disk}`, `caddis hub: version ${disk} is installed (running ${deps.currentVersion}); restarting`);
|
|
6390
|
+
await deps.onInstalled(disk);
|
|
6391
|
+
return;
|
|
6392
|
+
}
|
|
6393
|
+
const latest = await deps.fetchLatest();
|
|
6394
|
+
if (latest === null || compareVersions(latest, deps.currentVersion) !== 1) return;
|
|
6395
|
+
if (!deps.autoUpdate()) {
|
|
6396
|
+
once(`off:${latest}`, `caddis hub: version ${latest} is available (running ${deps.currentVersion}); auto_update is off`);
|
|
6397
|
+
return;
|
|
6398
|
+
}
|
|
6399
|
+
if (!await isGlobal()) {
|
|
6400
|
+
once(
|
|
6401
|
+
`local:${latest}`,
|
|
6402
|
+
`caddis hub: update available ${deps.currentVersion} -> ${latest}; this hub does not run from the global npm install, so it does not install it`
|
|
6403
|
+
);
|
|
6404
|
+
return;
|
|
6405
|
+
}
|
|
6406
|
+
const last = tried.get(latest);
|
|
6407
|
+
if (last !== void 0 && deps.now() - last < RETRY_AFTER_MS) return;
|
|
6408
|
+
tried.set(latest, deps.now());
|
|
6409
|
+
deps.log(`caddis hub: installing @caddis/cli@${latest} (running ${deps.currentVersion})`);
|
|
6410
|
+
let result;
|
|
6411
|
+
installing = true;
|
|
6412
|
+
try {
|
|
6413
|
+
result = await deps.install(latest);
|
|
6414
|
+
} finally {
|
|
6415
|
+
installing = false;
|
|
6416
|
+
}
|
|
6417
|
+
if (!result.ok) {
|
|
6418
|
+
deps.log(`caddis hub: install of ${latest} failed (${result.detail}); keeping ${deps.currentVersion}, next try in 1 h`);
|
|
6419
|
+
return;
|
|
6420
|
+
}
|
|
6421
|
+
const after = deps.readVersion();
|
|
6422
|
+
if (after !== latest) {
|
|
6423
|
+
deps.log(`caddis hub: npm finished, but package.json shows ${after ?? "nothing"}, not ${latest}; no restart`);
|
|
6424
|
+
return;
|
|
6425
|
+
}
|
|
6426
|
+
deps.log(`caddis hub: installed ${latest}; restarting`);
|
|
6427
|
+
await deps.onInstalled(latest);
|
|
6428
|
+
}
|
|
6429
|
+
function tick() {
|
|
6430
|
+
running = check2().catch((e2) => {
|
|
6431
|
+
try {
|
|
6432
|
+
deps.log(`caddis hub: update check failed: ${e2 instanceof Error ? e2.message : String(e2)}`);
|
|
6433
|
+
} catch {
|
|
6434
|
+
}
|
|
6435
|
+
});
|
|
6436
|
+
return running;
|
|
6437
|
+
}
|
|
6438
|
+
function schedule(ms) {
|
|
6439
|
+
if (stopped) return;
|
|
6440
|
+
cancel = deps.after(() => {
|
|
6441
|
+
void tick().then(() => schedule(UPDATE_EVERY_MS));
|
|
6442
|
+
}, ms);
|
|
6443
|
+
}
|
|
6444
|
+
return {
|
|
6445
|
+
start: () => {
|
|
6446
|
+
if (cancel) return;
|
|
6447
|
+
stopped = false;
|
|
6448
|
+
schedule(UPDATE_FIRST_MS);
|
|
6449
|
+
},
|
|
6450
|
+
stop: () => {
|
|
6451
|
+
stopped = true;
|
|
6452
|
+
cancel?.();
|
|
6453
|
+
cancel = null;
|
|
6454
|
+
},
|
|
6455
|
+
tick,
|
|
6456
|
+
installing: () => installing,
|
|
6457
|
+
idle: () => running
|
|
6458
|
+
};
|
|
6459
|
+
}
|
|
6460
|
+
var REGISTRY_URL, UPDATE_FIRST_MS, UPDATE_EVERY_MS, RETRY_AFTER_MS, INSTALL_TIMEOUT_MS, FETCH_TIMEOUT_MS, PLAIN_VERSION;
|
|
6461
|
+
var init_selfUpdate = __esm({
|
|
6462
|
+
"src/hub/selfUpdate.ts"() {
|
|
6463
|
+
"use strict";
|
|
6464
|
+
init_semver();
|
|
6465
|
+
REGISTRY_URL = "https://registry.npmjs.org/@caddis/cli/latest";
|
|
6466
|
+
UPDATE_FIRST_MS = 6e4;
|
|
6467
|
+
UPDATE_EVERY_MS = 30 * 6e4;
|
|
6468
|
+
RETRY_AFTER_MS = 60 * 6e4;
|
|
6469
|
+
INSTALL_TIMEOUT_MS = 5 * 6e4;
|
|
6470
|
+
FETCH_TIMEOUT_MS = 1e4;
|
|
6471
|
+
PLAIN_VERSION = /^\d+\.\d+\.\d+$/;
|
|
6472
|
+
}
|
|
6473
|
+
});
|
|
6474
|
+
|
|
6289
6475
|
// src/hub/append.ts
|
|
6290
6476
|
import { mkdir, open } from "fs/promises";
|
|
6291
|
-
import
|
|
6477
|
+
import path15 from "path";
|
|
6292
6478
|
async function writeLine(file, line2) {
|
|
6293
|
-
await mkdir(
|
|
6479
|
+
await mkdir(path15.dirname(file), { recursive: true });
|
|
6294
6480
|
const deadline = Date.now() + RETRY_FOR_MS;
|
|
6295
6481
|
for (; ; ) {
|
|
6296
6482
|
try {
|
|
@@ -6337,7 +6523,7 @@ var init_append = __esm({
|
|
|
6337
6523
|
RETRY_CODES = /* @__PURE__ */ new Set(["EBUSY", "EPERM", "EACCES"]);
|
|
6338
6524
|
RETRY_FOR_MS = 2e3;
|
|
6339
6525
|
keyOf = (file) => {
|
|
6340
|
-
const abs =
|
|
6526
|
+
const abs = path15.resolve(file);
|
|
6341
6527
|
return process.platform === "win32" ? abs.toLowerCase() : abs;
|
|
6342
6528
|
};
|
|
6343
6529
|
}
|
|
@@ -6345,7 +6531,7 @@ var init_append = __esm({
|
|
|
6345
6531
|
|
|
6346
6532
|
// src/hub/sources/coordinator.ts
|
|
6347
6533
|
import { closeSync as closeSync2, fstatSync, openSync as openSync2, readdirSync as readdirSync3, readFileSync as readFileSync10, readSync } from "fs";
|
|
6348
|
-
import
|
|
6534
|
+
import path16 from "path";
|
|
6349
6535
|
function stub(repoId, schema) {
|
|
6350
6536
|
return {
|
|
6351
6537
|
repo_id: repoId,
|
|
@@ -6496,7 +6682,7 @@ function createCoordinatorSource(opts = {}) {
|
|
|
6496
6682
|
const errors = /* @__PURE__ */ new Map();
|
|
6497
6683
|
return {
|
|
6498
6684
|
refresh() {
|
|
6499
|
-
const root =
|
|
6685
|
+
const root = path16.join(hubHome(opts.home), "repos");
|
|
6500
6686
|
let ids = [];
|
|
6501
6687
|
try {
|
|
6502
6688
|
ids = readdirSync3(root, { withFileTypes: true }).filter((d3) => d3.isDirectory()).map((d3) => d3.name);
|
|
@@ -6506,10 +6692,10 @@ function createCoordinatorSource(opts = {}) {
|
|
|
6506
6692
|
for (const id of [...lastGood2.keys()]) if (!seen.has(id)) lastGood2.delete(id);
|
|
6507
6693
|
for (const id of [...errors.keys()]) if (!seen.has(id)) errors.delete(id);
|
|
6508
6694
|
for (const id of ids) {
|
|
6509
|
-
const requests = parseRequests(readTailLines(
|
|
6695
|
+
const requests = parseRequests(readTailLines(path16.join(root, id, "requests.jsonl")));
|
|
6510
6696
|
let text2;
|
|
6511
6697
|
try {
|
|
6512
|
-
text2 = readFileSync10(
|
|
6698
|
+
text2 = readFileSync10(path16.join(root, id, "coordinator.json"), "utf8");
|
|
6513
6699
|
} catch (e2) {
|
|
6514
6700
|
if (e2.code === "ENOENT") {
|
|
6515
6701
|
lastGood2.delete(id);
|
|
@@ -6572,7 +6758,7 @@ var init_coordinator = __esm({
|
|
|
6572
6758
|
});
|
|
6573
6759
|
|
|
6574
6760
|
// src/hub/audit.ts
|
|
6575
|
-
import { statSync } from "fs";
|
|
6761
|
+
import { statSync as statSync2 } from "fs";
|
|
6576
6762
|
function parseAudit(lines) {
|
|
6577
6763
|
const out = [];
|
|
6578
6764
|
for (const line2 of lines) {
|
|
@@ -6603,7 +6789,7 @@ function readAudit(home) {
|
|
|
6603
6789
|
const file = auditPath(home);
|
|
6604
6790
|
let sig;
|
|
6605
6791
|
try {
|
|
6606
|
-
const st =
|
|
6792
|
+
const st = statSync2(file);
|
|
6607
6793
|
sig = `${st.size}:${st.mtimeMs}`;
|
|
6608
6794
|
} catch {
|
|
6609
6795
|
cache.delete(file);
|
|
@@ -6756,7 +6942,7 @@ var init_spawn = __esm({
|
|
|
6756
6942
|
|
|
6757
6943
|
// src/hub/sources/beats.ts
|
|
6758
6944
|
import { readFileSync as readFileSync11, readdirSync as readdirSync4 } from "fs";
|
|
6759
|
-
import
|
|
6945
|
+
import path17 from "path";
|
|
6760
6946
|
function toEntry(raw, opts) {
|
|
6761
6947
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
6762
6948
|
const r2 = raw;
|
|
@@ -6807,7 +6993,7 @@ function readAgentBeats(opts) {
|
|
|
6807
6993
|
if (!name.endsWith(".json") || name.startsWith(".")) continue;
|
|
6808
6994
|
let entry = null;
|
|
6809
6995
|
try {
|
|
6810
|
-
entry = toEntry(JSON.parse(readFileSync11(
|
|
6996
|
+
entry = toEntry(JSON.parse(readFileSync11(path17.join(dir, name), "utf8")), opts);
|
|
6811
6997
|
} catch {
|
|
6812
6998
|
continue;
|
|
6813
6999
|
}
|
|
@@ -6832,8 +7018,8 @@ var init_beats = __esm({
|
|
|
6832
7018
|
});
|
|
6833
7019
|
|
|
6834
7020
|
// src/hub/sources/agents.ts
|
|
6835
|
-
import { existsSync as existsSync7, readFileSync as readFileSync12, statSync as
|
|
6836
|
-
import
|
|
7021
|
+
import { existsSync as existsSync7, readFileSync as readFileSync12, statSync as statSync3 } from "fs";
|
|
7022
|
+
import path18 from "path";
|
|
6837
7023
|
function classifyWaiting(waitingFor) {
|
|
6838
7024
|
const w2 = (waitingFor ?? "").toLowerCase();
|
|
6839
7025
|
if (w2 === "permission prompt" || w2 === "input needed" || w2.includes("question")) return "owner";
|
|
@@ -6841,15 +7027,15 @@ function classifyWaiting(waitingFor) {
|
|
|
6841
7027
|
}
|
|
6842
7028
|
function repoPathFor(cwd) {
|
|
6843
7029
|
if (!cwd) return null;
|
|
6844
|
-
let dir =
|
|
7030
|
+
let dir = path18.resolve(cwd);
|
|
6845
7031
|
for (; ; ) {
|
|
6846
|
-
const dotGit =
|
|
7032
|
+
const dotGit = path18.join(dir, ".git");
|
|
6847
7033
|
if (existsSync7(dotGit)) {
|
|
6848
7034
|
if (isDir(dotGit)) return normalizeRepoPath(dir);
|
|
6849
7035
|
if (isFile(dotGit)) return commonRoot(dir, dotGit);
|
|
6850
7036
|
return null;
|
|
6851
7037
|
}
|
|
6852
|
-
const parent =
|
|
7038
|
+
const parent = path18.dirname(dir);
|
|
6853
7039
|
if (parent === dir) return null;
|
|
6854
7040
|
dir = parent;
|
|
6855
7041
|
}
|
|
@@ -6858,16 +7044,16 @@ function commonRoot(dir, dotGitFile) {
|
|
|
6858
7044
|
try {
|
|
6859
7045
|
const m2 = /^gitdir:\s*(.+?)\s*$/m.exec(readFileSync12(dotGitFile, "utf8"));
|
|
6860
7046
|
if (!m2) return null;
|
|
6861
|
-
const gitdir =
|
|
7047
|
+
const gitdir = path18.resolve(dir, m2[1] ?? "");
|
|
6862
7048
|
let common;
|
|
6863
7049
|
try {
|
|
6864
|
-
const rel = readFileSync12(
|
|
7050
|
+
const rel = readFileSync12(path18.join(gitdir, "commondir"), "utf8").trim();
|
|
6865
7051
|
if (!rel) return normalizeRepoPath(dir);
|
|
6866
|
-
common =
|
|
7052
|
+
common = path18.resolve(gitdir, rel);
|
|
6867
7053
|
} catch {
|
|
6868
7054
|
return normalizeRepoPath(dir);
|
|
6869
7055
|
}
|
|
6870
|
-
return normalizeRepoPath(
|
|
7056
|
+
return normalizeRepoPath(path18.dirname(common));
|
|
6871
7057
|
} catch {
|
|
6872
7058
|
return null;
|
|
6873
7059
|
}
|
|
@@ -6997,14 +7183,14 @@ var init_agents = __esm({
|
|
|
6997
7183
|
FIND_TIMEOUT_MS = 1e4;
|
|
6998
7184
|
isFile = (p2) => {
|
|
6999
7185
|
try {
|
|
7000
|
-
return
|
|
7186
|
+
return statSync3(p2).isFile();
|
|
7001
7187
|
} catch {
|
|
7002
7188
|
return false;
|
|
7003
7189
|
}
|
|
7004
7190
|
};
|
|
7005
7191
|
isDir = (p2) => {
|
|
7006
7192
|
try {
|
|
7007
|
-
return
|
|
7193
|
+
return statSync3(p2).isDirectory();
|
|
7008
7194
|
} catch {
|
|
7009
7195
|
return false;
|
|
7010
7196
|
}
|
|
@@ -7014,19 +7200,19 @@ var init_agents = __esm({
|
|
|
7014
7200
|
});
|
|
7015
7201
|
|
|
7016
7202
|
// src/hub/sources/collector.ts
|
|
7017
|
-
import { existsSync as existsSync8, mkdirSync as
|
|
7203
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync8, writeFileSync as writeFileSync5 } from "fs";
|
|
7018
7204
|
import os5 from "os";
|
|
7019
|
-
import
|
|
7205
|
+
import path19 from "path";
|
|
7020
7206
|
function defaultScriptPath() {
|
|
7021
7207
|
const name = "caddis_hub_collect.py";
|
|
7022
7208
|
const bundle = bundlePath("antigravity-plugin", { requireManifest: false });
|
|
7023
7209
|
if (bundle) {
|
|
7024
|
-
const shipped =
|
|
7210
|
+
const shipped = path19.join(bundle, "scripts", name);
|
|
7025
7211
|
if (existsSync8(shipped)) return shipped;
|
|
7026
7212
|
}
|
|
7027
|
-
const root =
|
|
7028
|
-
const repoScript =
|
|
7029
|
-
const mirrorScript =
|
|
7213
|
+
const root = path19.join(packageInfo().root, "..");
|
|
7214
|
+
const repoScript = path19.join(root, "scripts", name);
|
|
7215
|
+
const mirrorScript = path19.join(root, "bundles", "antigravity-plugin", "scripts", name);
|
|
7030
7216
|
return !existsSync8(repoScript) && existsSync8(mirrorScript) ? mirrorScript : repoScript;
|
|
7031
7217
|
}
|
|
7032
7218
|
async function resolvePython() {
|
|
@@ -7128,7 +7314,7 @@ function createCollectorSource(opts) {
|
|
|
7128
7314
|
let prsFlag = [];
|
|
7129
7315
|
if (opts.prs && opts.prsFile && repos.length > 0 && !prsFileUnsupported) {
|
|
7130
7316
|
try {
|
|
7131
|
-
|
|
7317
|
+
mkdirSync8(path19.dirname(opts.prsFile), { recursive: true });
|
|
7132
7318
|
writeFileSync5(opts.prsFile, JSON.stringify({ schema: 1, repos: opts.prs() }));
|
|
7133
7319
|
prsFlag = ["--prs-file", opts.prsFile];
|
|
7134
7320
|
} catch {
|
|
@@ -7143,7 +7329,7 @@ function createCollectorSource(opts) {
|
|
|
7143
7329
|
...doneKnown.length ? ["--done-known", ...doneKnown] : [],
|
|
7144
7330
|
...prsFlag,
|
|
7145
7331
|
"--json"
|
|
7146
|
-
] : [...pre, script, "--repos",
|
|
7332
|
+
] : [...pre, script, "--repos", path19.join(os5.tmpdir(), "caddis-hub-no-repos"), "--only", "spend,guide", "--json"];
|
|
7147
7333
|
let result = await spawn2(cmd, build(), { timeoutMs: RUN_TIMEOUT_MS2 });
|
|
7148
7334
|
for (let attempt = 0; attempt < 3 && !result.ok; attempt += 1) {
|
|
7149
7335
|
if (prsFlag.length && /unrecognized arguments:.*--prs-file/.test(result.stderr)) {
|
|
@@ -7216,7 +7402,7 @@ var init_collector = __esm({
|
|
|
7216
7402
|
|
|
7217
7403
|
// src/hub/sources/github.ts
|
|
7218
7404
|
import { readFileSync as readFileSync13 } from "fs";
|
|
7219
|
-
import
|
|
7405
|
+
import path20 from "path";
|
|
7220
7406
|
function parseGithubRemote(url) {
|
|
7221
7407
|
const m2 = /^(?:https?:\/\/(?:[^@/]+@)?|ssh:\/\/git@|git@)github\.com[/:]([^/\s]+)\/([^/\s]+?)(?:\.git)?\/?$/i.exec(url.trim());
|
|
7222
7408
|
return m2 ? `${m2[1]}/${m2[2]}` : null;
|
|
@@ -7226,7 +7412,7 @@ function readOriginUrl(repoDir) {
|
|
|
7226
7412
|
if (!root) return null;
|
|
7227
7413
|
let text2;
|
|
7228
7414
|
try {
|
|
7229
|
-
text2 = readFileSync13(
|
|
7415
|
+
text2 = readFileSync13(path20.join(root, ".git", "config"), "utf8");
|
|
7230
7416
|
} catch {
|
|
7231
7417
|
return null;
|
|
7232
7418
|
}
|
|
@@ -7244,7 +7430,7 @@ function readOriginUrl(repoDir) {
|
|
|
7244
7430
|
}
|
|
7245
7431
|
function readRequiredChecks(repoDir) {
|
|
7246
7432
|
try {
|
|
7247
|
-
const text2 = readFileSync13(
|
|
7433
|
+
const text2 = readFileSync13(path20.join(repoDir, ".caddis", "coordinator.md"), "utf8");
|
|
7248
7434
|
const m2 = /```json[^\S\r\n]*\r?\n([\s\S]*?)\r?\n[^\S\r\n]*```/.exec(text2);
|
|
7249
7435
|
if (!m2) return null;
|
|
7250
7436
|
const parsed = JSON.parse(m2[1] ?? "");
|
|
@@ -7372,8 +7558,8 @@ ${url}`;
|
|
|
7372
7558
|
"User-Agent": "caddis-hub"
|
|
7373
7559
|
};
|
|
7374
7560
|
if (cached2) headers["If-None-Match"] = cached2.etag;
|
|
7375
|
-
const signal = AbortSignal.timeout(
|
|
7376
|
-
const res = await withTimeout(doFetch(url, { headers, signal }),
|
|
7561
|
+
const signal = AbortSignal.timeout(FETCH_TIMEOUT_MS2);
|
|
7562
|
+
const res = await withTimeout(doFetch(url, { headers, signal }), FETCH_TIMEOUT_MS2 + 1e3, "GitHub request");
|
|
7377
7563
|
noteRate(account, res);
|
|
7378
7564
|
if (res.status === 304) {
|
|
7379
7565
|
if (cached2) return cached2.body;
|
|
@@ -7383,7 +7569,7 @@ ${url}`;
|
|
|
7383
7569
|
const limited = (res.status === 403 || res.status === 429) && (res.headers.get("x-ratelimit-remaining") === "0" || res.headers.get("retry-after") !== null);
|
|
7384
7570
|
throw new HttpError(res.status, limited, limited ? "GitHub rate limit reached" : `GitHub answered ${res.status}`);
|
|
7385
7571
|
}
|
|
7386
|
-
const body = await withTimeout(res.json(),
|
|
7572
|
+
const body = await withTimeout(res.json(), FETCH_TIMEOUT_MS2 + 1e3, "GitHub response");
|
|
7387
7573
|
const etag = res.headers.get("etag");
|
|
7388
7574
|
if (etag) etags.set(key, { etag, body });
|
|
7389
7575
|
return body;
|
|
@@ -7572,7 +7758,7 @@ ${url}`;
|
|
|
7572
7758
|
}
|
|
7573
7759
|
};
|
|
7574
7760
|
}
|
|
7575
|
-
var STALE_AFTER_MS4, POLL_MS2, SLOW_POLL_MS, RATE_RESERVE, API, TOKEN_TIMEOUT_MS, FIND_TIMEOUT_MS3,
|
|
7761
|
+
var STALE_AFTER_MS4, POLL_MS2, SLOW_POLL_MS, RATE_RESERVE, API, TOKEN_TIMEOUT_MS, FIND_TIMEOUT_MS3, FETCH_TIMEOUT_MS2, MERGES_SHOWN, FAILED, PASSED, HttpError, str4, rec2, list, findGh;
|
|
7576
7762
|
var init_github = __esm({
|
|
7577
7763
|
"src/hub/sources/github.ts"() {
|
|
7578
7764
|
"use strict";
|
|
@@ -7587,7 +7773,7 @@ var init_github = __esm({
|
|
|
7587
7773
|
API = "https://api.github.com";
|
|
7588
7774
|
TOKEN_TIMEOUT_MS = 1e4;
|
|
7589
7775
|
FIND_TIMEOUT_MS3 = 1e4;
|
|
7590
|
-
|
|
7776
|
+
FETCH_TIMEOUT_MS2 = 15e3;
|
|
7591
7777
|
MERGES_SHOWN = 5;
|
|
7592
7778
|
FAILED = /* @__PURE__ */ new Set(["failure", "cancelled", "timed_out", "action_required", "startup_failure", "stale"]);
|
|
7593
7779
|
PASSED = /* @__PURE__ */ new Set(["success", "neutral", "skipped"]);
|
|
@@ -7613,18 +7799,18 @@ var init_github = __esm({
|
|
|
7613
7799
|
// src/hub/state.ts
|
|
7614
7800
|
import { createHash } from "crypto";
|
|
7615
7801
|
import { readFileSync as readFileSync14 } from "fs";
|
|
7616
|
-
import
|
|
7802
|
+
import path21 from "path";
|
|
7617
7803
|
function repoIdFor(nameWithOwner) {
|
|
7618
7804
|
return nameWithOwner.trim().toLowerCase().replace(/\//g, "__");
|
|
7619
7805
|
}
|
|
7620
7806
|
function localRepoId(repoPath) {
|
|
7621
7807
|
const norm = process.platform === "win32" ? repoPath.toLowerCase().replace(/\//g, "\\") : repoPath;
|
|
7622
7808
|
const digest = createHash("sha256").update(norm, "utf8").digest("hex").slice(0, 6);
|
|
7623
|
-
return `local__${
|
|
7809
|
+
return `local__${path21.basename(repoPath)}__${digest}`;
|
|
7624
7810
|
}
|
|
7625
7811
|
function readPluginVersion(home) {
|
|
7626
7812
|
try {
|
|
7627
|
-
const file =
|
|
7813
|
+
const file = path21.join(home, ".claude", "plugins", "installed_plugins.json");
|
|
7628
7814
|
const parsed = JSON.parse(readFileSync14(file, "utf8"));
|
|
7629
7815
|
for (const [key, entries] of Object.entries(parsed.plugins ?? {})) {
|
|
7630
7816
|
if (!key.startsWith("caddis@") || !Array.isArray(entries)) continue;
|
|
@@ -7731,7 +7917,7 @@ function createHub(opts = {}) {
|
|
|
7731
7917
|
repos: repoPaths,
|
|
7732
7918
|
now,
|
|
7733
7919
|
prs: () => prHeads(github.get().data),
|
|
7734
|
-
prsFile:
|
|
7920
|
+
prsFile: path21.join(hubDir(home), "collector-prs.json")
|
|
7735
7921
|
});
|
|
7736
7922
|
const agents = opts.agents ?? createAgentsSource({ now, home });
|
|
7737
7923
|
const coordinator = opts.coordinator ?? createCoordinatorSource({ home, now });
|
|
@@ -7824,7 +8010,7 @@ function createHub(opts = {}) {
|
|
|
7824
8010
|
const relays = c?.relays ?? null;
|
|
7825
8011
|
const out = {
|
|
7826
8012
|
path: p2,
|
|
7827
|
-
name:
|
|
8013
|
+
name: path21.basename(p2),
|
|
7828
8014
|
pinned: pinned.has(k3),
|
|
7829
8015
|
roadmaps: c?.roadmaps ?? null,
|
|
7830
8016
|
plans: c?.plans ?? null,
|
|
@@ -7936,7 +8122,7 @@ var init_state = __esm({
|
|
|
7936
8122
|
|
|
7937
8123
|
// src/hub/actions.ts
|
|
7938
8124
|
import { randomUUID } from "crypto";
|
|
7939
|
-
import
|
|
8125
|
+
import path22 from "path";
|
|
7940
8126
|
function parseBody(raw) {
|
|
7941
8127
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new Refusal(400, "bad_request", "The body must be a JSON object.");
|
|
7942
8128
|
const o2 = raw;
|
|
@@ -8044,7 +8230,7 @@ function createActions(opts) {
|
|
|
8044
8230
|
args: body.what === null ? {} : { what: body.what }
|
|
8045
8231
|
};
|
|
8046
8232
|
try {
|
|
8047
|
-
await appendLine(
|
|
8233
|
+
await appendLine(path22.join(root(), "repos", body.repo_id, "requests.jsonl"), JSON.stringify(request));
|
|
8048
8234
|
} catch {
|
|
8049
8235
|
return refuse(new Refusal(500, "write_failed", "The hub could not write the request."), body);
|
|
8050
8236
|
}
|
|
@@ -8092,8 +8278,8 @@ var init_actions = __esm({
|
|
|
8092
8278
|
|
|
8093
8279
|
// src/hub/auth.ts
|
|
8094
8280
|
import { createHash as createHash2, randomBytes as randomBytes3, timingSafeEqual } from "crypto";
|
|
8095
|
-
import { mkdirSync as
|
|
8096
|
-
import
|
|
8281
|
+
import { mkdirSync as mkdirSync9, readFileSync as readFileSync15, renameSync as renameSync4, writeFileSync as writeFileSync6 } from "fs";
|
|
8282
|
+
import path23 from "path";
|
|
8097
8283
|
function randomToken() {
|
|
8098
8284
|
return randomBytes3(32).toString("base64url");
|
|
8099
8285
|
}
|
|
@@ -8190,9 +8376,9 @@ var init_auth = __esm({
|
|
|
8190
8376
|
};
|
|
8191
8377
|
const tmp = `${this.file}.${process.pid}.tmp`;
|
|
8192
8378
|
try {
|
|
8193
|
-
|
|
8379
|
+
mkdirSync9(path23.dirname(this.file), { recursive: true });
|
|
8194
8380
|
writeFileSync6(tmp, JSON.stringify(body), { mode: 384 });
|
|
8195
|
-
|
|
8381
|
+
renameSync4(tmp, this.file);
|
|
8196
8382
|
for (const s of this.sessions) s.savedSeenAt = s.lastSeenAt;
|
|
8197
8383
|
} catch {
|
|
8198
8384
|
}
|
|
@@ -8349,14 +8535,14 @@ var init_phaseText = __esm({
|
|
|
8349
8535
|
import http from "http";
|
|
8350
8536
|
import { existsSync as existsSync9 } from "fs";
|
|
8351
8537
|
import { readFile, stat } from "fs/promises";
|
|
8352
|
-
import
|
|
8538
|
+
import path24 from "path";
|
|
8353
8539
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
8354
8540
|
import { promisify } from "util";
|
|
8355
8541
|
import { gzip } from "zlib";
|
|
8356
8542
|
function defaultUiDir() {
|
|
8357
|
-
const here =
|
|
8358
|
-
const beside =
|
|
8359
|
-
return existsSync9(beside) ? beside :
|
|
8543
|
+
const here = path24.dirname(fileURLToPath2(import.meta.url));
|
|
8544
|
+
const beside = path24.join(here, "ui");
|
|
8545
|
+
return existsSync9(beside) ? beside : path24.resolve(here, "..", "..", "dist", "ui");
|
|
8360
8546
|
}
|
|
8361
8547
|
function resolveStatic(root, urlPath) {
|
|
8362
8548
|
let decoded;
|
|
@@ -8367,9 +8553,9 @@ function resolveStatic(root, urlPath) {
|
|
|
8367
8553
|
}
|
|
8368
8554
|
if (decoded.includes(String.fromCharCode(0)) || decoded.includes(String.fromCharCode(92))) return null;
|
|
8369
8555
|
if (decoded.split("/").includes("..")) return null;
|
|
8370
|
-
const base =
|
|
8371
|
-
const file =
|
|
8372
|
-
return file.startsWith(base +
|
|
8556
|
+
const base = path24.resolve(root);
|
|
8557
|
+
const file = path24.resolve(base, "." + decoded);
|
|
8558
|
+
return file.startsWith(base + path24.sep) ? file : null;
|
|
8373
8559
|
}
|
|
8374
8560
|
function send(res, status5, body, extra = {}) {
|
|
8375
8561
|
const text2 = JSON.stringify(body);
|
|
@@ -8461,7 +8647,7 @@ async function serveStatic(res, uiDir, urlPath) {
|
|
|
8461
8647
|
return fail(res, 404, "not_found");
|
|
8462
8648
|
}
|
|
8463
8649
|
res.writeHead(200, {
|
|
8464
|
-
"Content-Type": MIME[
|
|
8650
|
+
"Content-Type": MIME[path24.extname(file).toLowerCase()] ?? "application/octet-stream",
|
|
8465
8651
|
"Content-Length": body.length,
|
|
8466
8652
|
"Cache-Control": urlPath === "/" ? "no-store" : "public, max-age=31536000, immutable"
|
|
8467
8653
|
});
|
|
@@ -8497,23 +8683,23 @@ async function startServer(opts) {
|
|
|
8497
8683
|
fail(res, 400, "bad_url");
|
|
8498
8684
|
return;
|
|
8499
8685
|
}
|
|
8500
|
-
const
|
|
8686
|
+
const path28 = url.pathname;
|
|
8501
8687
|
const method = req.method ?? "GET";
|
|
8502
|
-
if (
|
|
8688
|
+
if (path28.startsWith("/api/") || path28 === "/login") res.setHeader("Cache-Control", "no-store");
|
|
8503
8689
|
if (!hostAllowed(req.headers.host, port)) {
|
|
8504
|
-
if (
|
|
8690
|
+
if (path28 === "/login") auth.discardCode(url.searchParams.get("code") ?? "");
|
|
8505
8691
|
fail(res, 403, "bad_host");
|
|
8506
8692
|
return;
|
|
8507
8693
|
}
|
|
8508
|
-
if (
|
|
8694
|
+
if (path28 === "/api/hub/whoami" && method === "GET") {
|
|
8509
8695
|
if (!opts.instance) return fail(res, 404, "not_found");
|
|
8510
8696
|
return send(res, 200, { instance: opts.instance });
|
|
8511
8697
|
}
|
|
8512
|
-
if (
|
|
8698
|
+
if (path28 === "/api/health" && method === "GET") {
|
|
8513
8699
|
if (!keyOk(req, key)) return fail(res, 401, "unauthorized");
|
|
8514
8700
|
return send(res, 200, { schema: 1, ok: true, versions });
|
|
8515
8701
|
}
|
|
8516
|
-
if (
|
|
8702
|
+
if (path28 === "/api/hub/code" && method === "POST") {
|
|
8517
8703
|
if (!keyOk(req, key)) return fail(res, 401, "unauthorized");
|
|
8518
8704
|
try {
|
|
8519
8705
|
await readBody(req);
|
|
@@ -8524,7 +8710,7 @@ async function startServer(opts) {
|
|
|
8524
8710
|
const code = auth.mintCode();
|
|
8525
8711
|
return send(res, 200, { schema: 1, code, expires_at: auth.codeExpiresAt() });
|
|
8526
8712
|
}
|
|
8527
|
-
if (
|
|
8713
|
+
if (path28 === "/api/hub/stop" && method === "POST") {
|
|
8528
8714
|
if (!keyOk(req, key)) return fail(res, 401, "unauthorized");
|
|
8529
8715
|
try {
|
|
8530
8716
|
await readBody(req);
|
|
@@ -8542,7 +8728,7 @@ async function startServer(opts) {
|
|
|
8542
8728
|
if (!session) return fail(res, 401, "unauthorized");
|
|
8543
8729
|
const token = req.headers[CSRF_HEADER];
|
|
8544
8730
|
if (typeof token !== "string" || !safeEqual(token, session.csrf)) return fail(res, 403, "bad_csrf");
|
|
8545
|
-
if (
|
|
8731
|
+
if (path28 === "/api/actions" && method === "POST" && opts.actions) {
|
|
8546
8732
|
if (!tabSessionOf(req)) return fail(res, 401, "unauthorized");
|
|
8547
8733
|
const type = String(req.headers["content-type"] ?? "").split(";")[0]?.trim().toLowerCase();
|
|
8548
8734
|
if (type !== "application/json") return fail(res, 415, "json_only");
|
|
@@ -8568,7 +8754,7 @@ async function startServer(opts) {
|
|
|
8568
8754
|
if (e2 instanceof BodyTooLarge) return tooLarge(req, res);
|
|
8569
8755
|
throw e2;
|
|
8570
8756
|
}
|
|
8571
|
-
if (
|
|
8757
|
+
if (path28 === "/api/logout" && method === "POST") {
|
|
8572
8758
|
auth.deleteSession(parseCookies(req.headers.cookie)[SESSION_COOKIE] ?? "");
|
|
8573
8759
|
return send(res, 200, { schema: 1, ok: true }, {
|
|
8574
8760
|
"Set-Cookie": `${SESSION_COOKIE}=; HttpOnly; SameSite=Strict; Path=/; Max-Age=0`
|
|
@@ -8576,11 +8762,11 @@ async function startServer(opts) {
|
|
|
8576
8762
|
}
|
|
8577
8763
|
return fail(res, 404, "not_found");
|
|
8578
8764
|
}
|
|
8579
|
-
if (
|
|
8580
|
-
await serveStatic(res, uiDir,
|
|
8765
|
+
if (path28 === "/" || path28.startsWith("/assets/") || path28.startsWith("/fonts/")) {
|
|
8766
|
+
await serveStatic(res, uiDir, path28);
|
|
8581
8767
|
return;
|
|
8582
8768
|
}
|
|
8583
|
-
if (
|
|
8769
|
+
if (path28 === "/login") {
|
|
8584
8770
|
const id = auth.redeemCode(url.searchParams.get("code") ?? "");
|
|
8585
8771
|
const session = id ? auth.getSession(id) : null;
|
|
8586
8772
|
if (!id || !session) return fail(res, 401, "bad_code");
|
|
@@ -8592,12 +8778,12 @@ async function startServer(opts) {
|
|
|
8592
8778
|
res.end();
|
|
8593
8779
|
return;
|
|
8594
8780
|
}
|
|
8595
|
-
if (
|
|
8781
|
+
if (path28 === "/api/session") {
|
|
8596
8782
|
const session = tabSessionOf(req);
|
|
8597
8783
|
if (!session) return fail(res, 401, "unauthorized");
|
|
8598
8784
|
return send(res, 200, { schema: 1, csrf_token: session.csrf, versions });
|
|
8599
8785
|
}
|
|
8600
|
-
if (
|
|
8786
|
+
if (path28 === "/api/state") {
|
|
8601
8787
|
if (!tabSessionOf(req)) return fail(res, 401, "unauthorized");
|
|
8602
8788
|
let state;
|
|
8603
8789
|
try {
|
|
@@ -8607,7 +8793,7 @@ async function startServer(opts) {
|
|
|
8607
8793
|
}
|
|
8608
8794
|
return sendState(req, res, stripPhaseText(state));
|
|
8609
8795
|
}
|
|
8610
|
-
if (
|
|
8796
|
+
if (path28 === "/api/plan-phase") {
|
|
8611
8797
|
if (!tabSessionOf(req)) return fail(res, 401, "unauthorized");
|
|
8612
8798
|
const repo = url.searchParams.get("repo") ?? "";
|
|
8613
8799
|
const plan2 = url.searchParams.get("plan") ?? "";
|
|
@@ -8704,8 +8890,8 @@ __export(hub_exports, {
|
|
|
8704
8890
|
startHub: () => startHub
|
|
8705
8891
|
});
|
|
8706
8892
|
import http2 from "http";
|
|
8707
|
-
import
|
|
8708
|
-
import { mkdirSync as
|
|
8893
|
+
import path25 from "path";
|
|
8894
|
+
import { mkdirSync as mkdirSync10, readFileSync as readFileSync16 } from "fs";
|
|
8709
8895
|
import { randomBytes as randomBytes4 } from "crypto";
|
|
8710
8896
|
function defaultVersions2() {
|
|
8711
8897
|
return { cli: packageInfo().version, caddis: bundleManifest().poolVersion };
|
|
@@ -8790,7 +8976,7 @@ async function isNodeProcess(pid) {
|
|
|
8790
8976
|
if (!r2.ok) return false;
|
|
8791
8977
|
const name = (r2.stdout.split(/\r?\n/)[0] ?? "").replace(/^"([^"]*)".*$/, "$1").trim().toLowerCase();
|
|
8792
8978
|
if (!name) return false;
|
|
8793
|
-
const runtime =
|
|
8979
|
+
const runtime = path25.basename(process.execPath).toLowerCase().replace(/\.exe$/, "");
|
|
8794
8980
|
return name.includes("node") || name.includes(runtime);
|
|
8795
8981
|
}
|
|
8796
8982
|
async function defaultOpener(url) {
|
|
@@ -8893,6 +9079,17 @@ async function startHub(deps = {}) {
|
|
|
8893
9079
|
state.start();
|
|
8894
9080
|
return { port: server.port, stop, done };
|
|
8895
9081
|
}
|
|
9082
|
+
async function npmGlobalRoot(cwd) {
|
|
9083
|
+
const r2 = await run("npm", ["root", "-g"], { cwd, timeout: TOOL_TIMEOUT_MS * 2 });
|
|
9084
|
+
const root = r2.stdout.trim().split(/\r?\n/).pop() ?? "";
|
|
9085
|
+
return r2.ok && root ? root : null;
|
|
9086
|
+
}
|
|
9087
|
+
async function npmInstall(version, cwd) {
|
|
9088
|
+
const r2 = await run("npm", ["i", "-g", `@caddis/cli@${version}`], { cwd, timeout: INSTALL_TIMEOUT_MS });
|
|
9089
|
+
if (r2.ok) return { ok: true, detail: "" };
|
|
9090
|
+
const tail3 = (r2.failure ?? r2.stderr.trim().split(/\r?\n/).slice(-3).join(" ")) || `exit ${r2.code}`;
|
|
9091
|
+
return { ok: false, detail: tail3.slice(0, 300) };
|
|
9092
|
+
}
|
|
8896
9093
|
async function killChild(child, deps) {
|
|
8897
9094
|
if (child.pid && (deps.alive ?? pidAlive)(child.pid)) await (deps.kill ?? killTree2)(child.pid);
|
|
8898
9095
|
}
|
|
@@ -8922,11 +9119,14 @@ async function hubServe(deps = {}) {
|
|
|
8922
9119
|
process.once("exit", onExit);
|
|
8923
9120
|
line(`caddis hub serving on ${hubUrl(hub2.port)} (pid ${process.pid}); stop it with: caddis hub stop`);
|
|
8924
9121
|
const pkgRoot = packageInfo().root;
|
|
8925
|
-
const newEntry =
|
|
9122
|
+
const newEntry = path25.join(pkgRoot, "dist", "cli.js");
|
|
8926
9123
|
const runningVersion = (deps.versions ?? defaultVersions2()).cli ?? packageInfo().version;
|
|
9124
|
+
const log = (text2) => hubLog(text2, home, deps.now);
|
|
9125
|
+
let installing = () => false;
|
|
8927
9126
|
const restarter = createRestarter({
|
|
8928
9127
|
currentVersion: runningVersion,
|
|
8929
|
-
|
|
9128
|
+
// While npm replaces the package, package.json can show the new version before all files are there.
|
|
9129
|
+
readVersion: () => installing() ? null : readInstalledVersion2(pkgRoot),
|
|
8930
9130
|
closeServer: async () => {
|
|
8931
9131
|
restarting = true;
|
|
8932
9132
|
await hub2.stop();
|
|
@@ -8954,7 +9154,7 @@ async function hubServe(deps = {}) {
|
|
|
8954
9154
|
exitCode = code;
|
|
8955
9155
|
resolveFinished();
|
|
8956
9156
|
},
|
|
8957
|
-
log
|
|
9157
|
+
log,
|
|
8958
9158
|
every: (fn, ms) => {
|
|
8959
9159
|
const t = setInterval(fn, ms);
|
|
8960
9160
|
t.unref();
|
|
@@ -8962,9 +9162,31 @@ async function hubServe(deps = {}) {
|
|
|
8962
9162
|
},
|
|
8963
9163
|
...deps.restart
|
|
8964
9164
|
});
|
|
9165
|
+
const updater = createUpdater({
|
|
9166
|
+
currentVersion: runningVersion,
|
|
9167
|
+
packageRoot: pkgRoot,
|
|
9168
|
+
autoUpdate: () => readConfig(home).value.auto_update,
|
|
9169
|
+
fetchLatest: () => fetchLatestVersion(),
|
|
9170
|
+
globalRoot: () => npmGlobalRoot(hubDir(home)),
|
|
9171
|
+
install: (version) => npmInstall(version, hubDir(home)),
|
|
9172
|
+
readVersion: () => readInstalledVersion2(pkgRoot),
|
|
9173
|
+
// The restarter does the hand-over: close, release the lock, start the new server, exit.
|
|
9174
|
+
onInstalled: () => restarter.tick(),
|
|
9175
|
+
log,
|
|
9176
|
+
now: deps.now ?? Date.now,
|
|
9177
|
+
after: (fn, ms) => {
|
|
9178
|
+
const t = setTimeout(fn, ms);
|
|
9179
|
+
t.unref();
|
|
9180
|
+
return () => clearTimeout(t);
|
|
9181
|
+
},
|
|
9182
|
+
...deps.update
|
|
9183
|
+
});
|
|
9184
|
+
installing = updater.installing;
|
|
8965
9185
|
restarter.start();
|
|
9186
|
+
updater.start();
|
|
8966
9187
|
await finished;
|
|
8967
9188
|
restarter.stop();
|
|
9189
|
+
updater.stop();
|
|
8968
9190
|
process.off("SIGINT", onSignal);
|
|
8969
9191
|
process.off("SIGTERM", onSignal);
|
|
8970
9192
|
process.off("exit", onExit);
|
|
@@ -8998,7 +9220,7 @@ async function hubStart(deps = {}) {
|
|
|
8998
9220
|
return 1;
|
|
8999
9221
|
}
|
|
9000
9222
|
const cwd = hubDir(home);
|
|
9001
|
-
|
|
9223
|
+
mkdirSync10(cwd, { recursive: true });
|
|
9002
9224
|
const child = await (deps.spawn ?? defaultSpawn)(process.execPath, [entry, "hub", "serve"], { cwd });
|
|
9003
9225
|
let exited = false;
|
|
9004
9226
|
let exitCode = null;
|
|
@@ -9174,8 +9396,10 @@ var init_hub = __esm({
|
|
|
9174
9396
|
init_config();
|
|
9175
9397
|
init_keyfile();
|
|
9176
9398
|
init_lock();
|
|
9399
|
+
init_hubLog();
|
|
9177
9400
|
init_paths();
|
|
9178
9401
|
init_restart();
|
|
9402
|
+
init_selfUpdate();
|
|
9179
9403
|
init_actions();
|
|
9180
9404
|
init_server();
|
|
9181
9405
|
init_state();
|
|
@@ -9385,7 +9609,7 @@ var init_data = __esm({
|
|
|
9385
9609
|
|
|
9386
9610
|
// src/hub/export/privacy.ts
|
|
9387
9611
|
import { lstatSync, readdirSync as readdirSync5, readFileSync as readFileSync17 } from "fs";
|
|
9388
|
-
import
|
|
9612
|
+
import path26 from "path";
|
|
9389
9613
|
function parseAllowedUrls(text2) {
|
|
9390
9614
|
const exact = /* @__PURE__ */ new Set();
|
|
9391
9615
|
const templates = [];
|
|
@@ -9404,7 +9628,7 @@ function walk(dir, base = "") {
|
|
|
9404
9628
|
const out = [];
|
|
9405
9629
|
for (const name of readdirSync5(dir).sort()) {
|
|
9406
9630
|
const rel = base ? `${base}/${name}` : name;
|
|
9407
|
-
const full =
|
|
9631
|
+
const full = path26.join(dir, name);
|
|
9408
9632
|
if (lstatSync(full).isDirectory()) out.push(...walk(full, rel));
|
|
9409
9633
|
else out.push(rel);
|
|
9410
9634
|
}
|
|
@@ -9449,13 +9673,13 @@ function isPrivateText(text2, deny) {
|
|
|
9449
9673
|
function scanExport(dir, opts) {
|
|
9450
9674
|
const hits = [];
|
|
9451
9675
|
for (const file of walk(dir)) {
|
|
9452
|
-
const full =
|
|
9676
|
+
const full = path26.join(dir, ...file.split("/"));
|
|
9453
9677
|
if (lstatSync(full).isSymbolicLink()) {
|
|
9454
9678
|
hits.push({ file, offset: 0, rule: "symbolic-link" });
|
|
9455
9679
|
continue;
|
|
9456
9680
|
}
|
|
9457
9681
|
const buf = readFileSync17(full);
|
|
9458
|
-
const binary = BINARY_EXT.has(
|
|
9682
|
+
const binary = BINARY_EXT.has(path26.extname(file).toLowerCase());
|
|
9459
9683
|
const text2 = binary ? null : buf.toString("utf8");
|
|
9460
9684
|
scanDeny(file, buf, text2, opts.deny, hits);
|
|
9461
9685
|
if (text2 === null) continue;
|
|
@@ -9536,15 +9760,15 @@ import {
|
|
|
9536
9760
|
copyFileSync,
|
|
9537
9761
|
existsSync as existsSync10,
|
|
9538
9762
|
lstatSync as lstatSync2,
|
|
9539
|
-
mkdirSync as
|
|
9763
|
+
mkdirSync as mkdirSync11,
|
|
9540
9764
|
readdirSync as readdirSync6,
|
|
9541
9765
|
readFileSync as readFileSync18,
|
|
9542
9766
|
rmSync as rmSync4,
|
|
9543
|
-
statSync as
|
|
9767
|
+
statSync as statSync4,
|
|
9544
9768
|
writeFileSync as writeFileSync7
|
|
9545
9769
|
} from "fs";
|
|
9546
9770
|
import os6 from "os";
|
|
9547
|
-
import
|
|
9771
|
+
import path27 from "path";
|
|
9548
9772
|
function prsForCollector(gh, repo) {
|
|
9549
9773
|
if (!Array.isArray(gh)) return null;
|
|
9550
9774
|
const heads = [];
|
|
@@ -9564,7 +9788,7 @@ function prsForCollector(gh, repo) {
|
|
|
9564
9788
|
}
|
|
9565
9789
|
function holdsLink(dir) {
|
|
9566
9790
|
for (const name of readdirSync6(dir)) {
|
|
9567
|
-
const full =
|
|
9791
|
+
const full = path27.join(dir, name);
|
|
9568
9792
|
const st = lstatSync2(full);
|
|
9569
9793
|
if (st.isSymbolicLink()) return true;
|
|
9570
9794
|
if (st.isDirectory() && holdsLink(full)) return true;
|
|
@@ -9583,7 +9807,7 @@ function checkOut(out, repo) {
|
|
|
9583
9807
|
if (st.isSymbolicLink()) return "--out is a link";
|
|
9584
9808
|
if (!st.isDirectory()) return "--out is a file";
|
|
9585
9809
|
if (readdirSync6(out).length === 0) return null;
|
|
9586
|
-
if (!existsSync10(
|
|
9810
|
+
if (!existsSync10(path27.join(out, MARKER)) || lstatSync2(path27.join(out, MARKER)).isSymbolicLink()) {
|
|
9587
9811
|
return `--out is not empty and has no ${MARKER} marker: this command did not make it`;
|
|
9588
9812
|
}
|
|
9589
9813
|
if (holdsLink(out)) return "--out holds a link";
|
|
@@ -9609,33 +9833,33 @@ function notFoundPage() {
|
|
|
9609
9833
|
`;
|
|
9610
9834
|
}
|
|
9611
9835
|
function copyFixedSet(dist, dest) {
|
|
9612
|
-
|
|
9613
|
-
|
|
9614
|
-
|
|
9615
|
-
copyFileSync(
|
|
9616
|
-
for (const name of readdirSync6(
|
|
9617
|
-
const from =
|
|
9618
|
-
if (lstatSync2(from).isFile()) copyFileSync(from,
|
|
9619
|
-
}
|
|
9620
|
-
const fonts =
|
|
9836
|
+
mkdirSync11(path27.join(dest, "assets"), { recursive: true });
|
|
9837
|
+
mkdirSync11(path27.join(dest, "fonts"), { recursive: true });
|
|
9838
|
+
mkdirSync11(path27.join(dest, "licenses"), { recursive: true });
|
|
9839
|
+
copyFileSync(path27.join(dist, "index.html"), path27.join(dest, "index.html"));
|
|
9840
|
+
for (const name of readdirSync6(path27.join(dist, "assets"))) {
|
|
9841
|
+
const from = path27.join(dist, "assets", name);
|
|
9842
|
+
if (lstatSync2(from).isFile()) copyFileSync(from, path27.join(dest, "assets", name));
|
|
9843
|
+
}
|
|
9844
|
+
const fonts = path27.join(dist, "fonts");
|
|
9621
9845
|
if (isDir2(fonts)) {
|
|
9622
9846
|
for (const name of readdirSync6(fonts)) {
|
|
9623
|
-
const from =
|
|
9847
|
+
const from = path27.join(fonts, name);
|
|
9624
9848
|
if (!lstatSync2(from).isFile()) continue;
|
|
9625
|
-
if (name.endsWith(".woff2")) copyFileSync(from,
|
|
9849
|
+
if (name.endsWith(".woff2")) copyFileSync(from, path27.join(dest, "fonts", name));
|
|
9626
9850
|
}
|
|
9627
9851
|
}
|
|
9628
|
-
const licenses =
|
|
9852
|
+
const licenses = path27.join(dist, "licenses");
|
|
9629
9853
|
if (isDir2(licenses)) {
|
|
9630
9854
|
for (const name of readdirSync6(licenses)) {
|
|
9631
|
-
const from =
|
|
9632
|
-
if (lstatSync2(from).isFile() && /^(OFL-[A-Za-z]+|LICENSE-Lucide)\.txt$/.test(name)) copyFileSync(from,
|
|
9855
|
+
const from = path27.join(licenses, name);
|
|
9856
|
+
if (lstatSync2(from).isFile() && /^(OFL-[A-Za-z]+|LICENSE-Lucide)\.txt$/.test(name)) copyFileSync(from, path27.join(dest, "licenses", name));
|
|
9633
9857
|
}
|
|
9634
9858
|
}
|
|
9635
9859
|
}
|
|
9636
9860
|
function countFiles(dir) {
|
|
9637
9861
|
return readdirSync6(dir).reduce((n, name) => {
|
|
9638
|
-
const full =
|
|
9862
|
+
const full = path27.join(dir, name);
|
|
9639
9863
|
return n + (lstatSync2(full).isDirectory() ? countFiles(full) : name === MARKER ? 0 : 1);
|
|
9640
9864
|
}, 0);
|
|
9641
9865
|
}
|
|
@@ -9657,7 +9881,7 @@ async function hubExport(args, deps = {}) {
|
|
|
9657
9881
|
return 2;
|
|
9658
9882
|
}
|
|
9659
9883
|
if (args.check !== void 0) {
|
|
9660
|
-
const dir =
|
|
9884
|
+
const dir = path27.resolve(args.check);
|
|
9661
9885
|
if (!isDir2(dir)) {
|
|
9662
9886
|
err(`error: --check folder not found: ${args.check}`);
|
|
9663
9887
|
return 1;
|
|
@@ -9681,9 +9905,9 @@ async function hubExport(args, deps = {}) {
|
|
|
9681
9905
|
err("error: --commit must be 7 to 40 hex characters");
|
|
9682
9906
|
return 2;
|
|
9683
9907
|
}
|
|
9684
|
-
const repo =
|
|
9685
|
-
const outDir =
|
|
9686
|
-
if (!existsSync10(
|
|
9908
|
+
const repo = path27.resolve(args.repo);
|
|
9909
|
+
const outDir = path27.resolve(args.out);
|
|
9910
|
+
if (!existsSync10(path27.join(repo, ".git")) || !(isDir2(path27.join(repo, ".caddis", "roadmaps")) || isDir2(path27.join(repo, ".caddis", "plans")))) {
|
|
9687
9911
|
err("error: --repo must be a git checkout with .caddis/roadmaps/ or .caddis/plans/");
|
|
9688
9912
|
return 2;
|
|
9689
9913
|
}
|
|
@@ -9692,8 +9916,8 @@ async function hubExport(args, deps = {}) {
|
|
|
9692
9916
|
err(`error: ${refused}`);
|
|
9693
9917
|
return 2;
|
|
9694
9918
|
}
|
|
9695
|
-
const dist = deps.distDir ??
|
|
9696
|
-
if (!existsSync10(
|
|
9919
|
+
const dist = deps.distDir ?? path27.join(packageInfo().root, "dist", "export");
|
|
9920
|
+
if (!existsSync10(path27.join(dist, "index.html")) || !isDir2(path27.join(dist, "assets"))) {
|
|
9697
9921
|
err(`error: the export app is not built (${dist}). Run: npm run build:ui`);
|
|
9698
9922
|
return 1;
|
|
9699
9923
|
}
|
|
@@ -9743,7 +9967,7 @@ async function hubExport(args, deps = {}) {
|
|
|
9743
9967
|
if (args.prs !== void 0) {
|
|
9744
9968
|
let gh = null;
|
|
9745
9969
|
try {
|
|
9746
|
-
gh = JSON.parse(readFileSync18(
|
|
9970
|
+
gh = JSON.parse(readFileSync18(path27.resolve(args.prs), "utf8"));
|
|
9747
9971
|
} catch {
|
|
9748
9972
|
gh = null;
|
|
9749
9973
|
}
|
|
@@ -9753,7 +9977,7 @@ async function hubExport(args, deps = {}) {
|
|
|
9753
9977
|
} else {
|
|
9754
9978
|
prsFile = `${outDir}.prs-${process.pid}.json`;
|
|
9755
9979
|
try {
|
|
9756
|
-
|
|
9980
|
+
mkdirSync11(path27.dirname(prsFile), { recursive: true });
|
|
9757
9981
|
writeFileSync7(prsFile, JSON.stringify(body));
|
|
9758
9982
|
} catch (error) {
|
|
9759
9983
|
rmSync4(prsFile, { force: true });
|
|
@@ -9788,12 +10012,12 @@ async function hubExport(args, deps = {}) {
|
|
|
9788
10012
|
const build = (page) => {
|
|
9789
10013
|
rmSync4(staging, { recursive: true, force: true });
|
|
9790
10014
|
copyFixedSet(dist, staging);
|
|
9791
|
-
const indexPath =
|
|
10015
|
+
const indexPath = path27.join(staging, "index.html");
|
|
9792
10016
|
const html = readFileSync18(indexPath, "utf8");
|
|
9793
10017
|
if (!html.includes(PLACEHOLDER)) throw new Error("the built index.html has no data placeholder");
|
|
9794
10018
|
const block = `<script type="application/json" id="caddis-export-data">${escapeJson(JSON.stringify(page))}</script>`;
|
|
9795
10019
|
writeFileSync7(indexPath, html.replace(PLACEHOLDER, () => block));
|
|
9796
|
-
writeFileSync7(
|
|
10020
|
+
writeFileSync7(path27.join(staging, "404.html"), notFoundPage());
|
|
9797
10021
|
};
|
|
9798
10022
|
try {
|
|
9799
10023
|
build(data);
|
|
@@ -9819,10 +10043,10 @@ async function hubExport(args, deps = {}) {
|
|
|
9819
10043
|
rmSync4(staging, { recursive: true, force: true });
|
|
9820
10044
|
return 3;
|
|
9821
10045
|
}
|
|
9822
|
-
|
|
10046
|
+
mkdirSync11(path27.dirname(outDir), { recursive: true });
|
|
9823
10047
|
if (existsSync10(outDir)) rmSync4(outDir, { recursive: true, force: true });
|
|
9824
10048
|
renameWithRetry(staging, outDir);
|
|
9825
|
-
writeFileSync7(
|
|
10049
|
+
writeFileSync7(path27.join(outDir, MARKER), "written by caddis hub export\n");
|
|
9826
10050
|
out(`[EXPORT] ${countFiles(outDir)} file(s) in ${outDir}`);
|
|
9827
10051
|
return 0;
|
|
9828
10052
|
} catch (error) {
|
|
@@ -9852,18 +10076,18 @@ var init_export = __esm({
|
|
|
9852
10076
|
FIXED_FILES = ["index.html", "404.html"];
|
|
9853
10077
|
isDir2 = (p2) => {
|
|
9854
10078
|
try {
|
|
9855
|
-
return
|
|
10079
|
+
return statSync4(p2).isDirectory();
|
|
9856
10080
|
} catch {
|
|
9857
10081
|
return false;
|
|
9858
10082
|
}
|
|
9859
10083
|
};
|
|
9860
10084
|
samePath = (a, b3) => {
|
|
9861
|
-
const norm = (p2) =>
|
|
10085
|
+
const norm = (p2) => path27.resolve(p2).replace(/[\\/]+$/, "").toLowerCase();
|
|
9862
10086
|
return norm(a) === norm(b3);
|
|
9863
10087
|
};
|
|
9864
10088
|
isInside = (child, parent) => {
|
|
9865
|
-
const rel =
|
|
9866
|
-
return rel !== "" && !rel.startsWith("..") && !
|
|
10089
|
+
const rel = path27.relative(path27.resolve(parent), path27.resolve(child));
|
|
10090
|
+
return rel !== "" && !rel.startsWith("..") && !path27.isAbsolute(rel);
|
|
9867
10091
|
};
|
|
9868
10092
|
NOT_FOUND_SCRIPT = "var p=location.pathname.split('/');var f=p.pop();p.pop();var m=/^([A-Za-z0-9._-]+)\\.html$/.exec(f);if(m&&p.length>1)location.replace(p.join('/')+'/#/roadmap/'+encodeURIComponent(m[1]));";
|
|
9869
10093
|
}
|
|
@@ -9924,14 +10148,14 @@ function* pluginBlocks(stdout) {
|
|
|
9924
10148
|
if (current) yield current;
|
|
9925
10149
|
}
|
|
9926
10150
|
async function detect() {
|
|
9927
|
-
const
|
|
9928
|
-
if (!
|
|
10151
|
+
const path28 = await findBin(BIN);
|
|
10152
|
+
if (!path28) {
|
|
9929
10153
|
return { present: false, note: "no `claude` binary on PATH" };
|
|
9930
10154
|
}
|
|
9931
10155
|
const version = await run(BIN, ["--version"], { timeout: 2e4 });
|
|
9932
10156
|
return {
|
|
9933
10157
|
present: true,
|
|
9934
|
-
path:
|
|
10158
|
+
path: path28,
|
|
9935
10159
|
agentVersion: version.ok ? version.stdout.trim().split(/\s+/)[0] || void 0 : void 0,
|
|
9936
10160
|
note: version.ok ? void 0 : "binary found but `claude --version` failed"
|
|
9937
10161
|
};
|