@caddis/cli 0.4.102 → 0.4.104
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 +8 -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 +9 -9
- package/bundles/antigravity-plugin/skills/_registry.md +2 -1
- package/bundles/antigravity-plugin/skills/graph-email/SKILL.md +6 -5
- package/bundles/{antigravity-plugin-extras/skills/graph-email → antigravity-plugin/skills/send-email}/SKILL.md +13 -2
- package/bundles/{antigravity-plugin-extras/skills/graph-email → antigravity-plugin/skills/send-email}/email.toml.example +1 -1
- package/bundles/{antigravity-plugin-extras/skills/graph-email → antigravity-plugin/skills/send-email}/scripts/send_email.py +22 -7
- package/bundles/antigravity-plugin-extras/plugin.json +1 -1
- package/bundles/antigravity-plugin-extras/skills/_registry.md +0 -1
- package/bundles/codex/.codex/skills/devops/send-email/SKILL.md +64 -0
- package/bundles/codex/.codex/skills/devops/send-email/email.toml.example +44 -0
- package/bundles/codex/.codex/skills/devops/send-email/scripts/send_email.py +447 -0
- package/bundles/manifest.json +3 -3
- package/dist/cli.js +894 -234
- 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 path29 = __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 = path29.resolve(baseDir, baseName);
|
|
2226
2226
|
if (fs.existsSync(localBin)) return localBin;
|
|
2227
|
-
if (sourceExt.includes(
|
|
2227
|
+
if (sourceExt.includes(path29.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 = path29.resolve(
|
|
2246
|
+
path29.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 = path29.basename(
|
|
2254
2254
|
this._scriptPath,
|
|
2255
|
-
|
|
2255
|
+
path29.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(path29.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 = path29.basename(filename, path29.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(path30) {
|
|
3196
|
+
if (path30 === void 0) return this._executableDir;
|
|
3197
|
+
this._executableDir = path30;
|
|
3198
3198
|
return this;
|
|
3199
3199
|
}
|
|
3200
3200
|
/**
|
|
@@ -3605,7 +3605,7 @@ var require_index_min = __commonJS({
|
|
|
3605
3605
|
}) : (function(t, e2, r2, s) {
|
|
3606
3606
|
s === void 0 && (s = r2), t[s] = e2[r2];
|
|
3607
3607
|
}));
|
|
3608
|
-
var
|
|
3608
|
+
var G3 = exports && exports.__setModuleDefault || (Object.create ? (function(t, e2) {
|
|
3609
3609
|
Object.defineProperty(t, "default", { enumerable: true, value: e2 });
|
|
3610
3610
|
}) : function(t, e2) {
|
|
3611
3611
|
t.default = e2;
|
|
@@ -3622,7 +3622,7 @@ var require_index_min = __commonJS({
|
|
|
3622
3622
|
if (e2 && e2.__esModule) return e2;
|
|
3623
3623
|
var r2 = {};
|
|
3624
3624
|
if (e2 != null) for (var s = t(e2), n = 0; n < s.length; n++) s[n] !== "default" && v2(r2, e2, s[n]);
|
|
3625
|
-
return
|
|
3625
|
+
return G3(r2, e2), r2;
|
|
3626
3626
|
};
|
|
3627
3627
|
})();
|
|
3628
3628
|
var X2 = exports && exports.__exportStar || function(t, e2) {
|
|
@@ -4234,7 +4234,7 @@ function fD({ input: e2 = j, output: u2 = M, overwrite: t = true, hideCursor: F2
|
|
|
4234
4234
|
e2.off("keypress", i), F2 && u2.write(import_sisteransi.cursor.show), e2.isTTY && !AD && e2.setRawMode(false), s.terminal = false, s.close();
|
|
4235
4235
|
};
|
|
4236
4236
|
}
|
|
4237
|
-
var import_sisteransi, import_picocolors4, uD, W, tD, eD, FD, sD, w, N, I, R, r, iD, CD, ED, d, oD, y, V, nD, G, _, z, K, aD, k, hD, lD, xD, B, AD, S, gD, vD, h, x, dD, A, TD, jD, U, MD;
|
|
4237
|
+
var import_sisteransi, import_picocolors4, uD, W, tD, eD, FD, sD, w, N, I, R, r, iD, CD, ED, d, oD, y, V, nD, G, _, z, K, aD, k, hD, lD, xD, B, AD, S, gD, vD, h, x, dD, A, TD, jD, U, MD, OD, PD, J, LD, RD;
|
|
4238
4238
|
var init_dist = __esm({
|
|
4239
4239
|
"node_modules/@clack/core/dist/index.mjs"() {
|
|
4240
4240
|
"use strict";
|
|
@@ -4494,6 +4494,48 @@ var init_dist = __esm({
|
|
|
4494
4494
|
return this.value.replaceAll(/./g, this._mask);
|
|
4495
4495
|
}
|
|
4496
4496
|
};
|
|
4497
|
+
OD = Object.defineProperty;
|
|
4498
|
+
PD = (e2, u2, t) => u2 in e2 ? OD(e2, u2, { enumerable: true, configurable: true, writable: true, value: t }) : e2[u2] = t;
|
|
4499
|
+
J = (e2, u2, t) => (PD(e2, typeof u2 != "symbol" ? u2 + "" : u2, t), t);
|
|
4500
|
+
LD = class extends x {
|
|
4501
|
+
constructor(u2) {
|
|
4502
|
+
super(u2, false), J(this, "options"), J(this, "cursor", 0), this.options = u2.options, this.cursor = this.options.findIndex(({ value: t }) => t === u2.initialValue), this.cursor === -1 && (this.cursor = 0), this.changeValue(), this.on("cursor", (t) => {
|
|
4503
|
+
switch (t) {
|
|
4504
|
+
case "left":
|
|
4505
|
+
case "up":
|
|
4506
|
+
this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
|
|
4507
|
+
break;
|
|
4508
|
+
case "down":
|
|
4509
|
+
case "right":
|
|
4510
|
+
this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
|
|
4511
|
+
break;
|
|
4512
|
+
}
|
|
4513
|
+
this.changeValue();
|
|
4514
|
+
});
|
|
4515
|
+
}
|
|
4516
|
+
get _value() {
|
|
4517
|
+
return this.options[this.cursor];
|
|
4518
|
+
}
|
|
4519
|
+
changeValue() {
|
|
4520
|
+
this.value = this._value.value;
|
|
4521
|
+
}
|
|
4522
|
+
};
|
|
4523
|
+
RD = class extends x {
|
|
4524
|
+
get valueWithCursor() {
|
|
4525
|
+
if (this.state === "submit") return this.value;
|
|
4526
|
+
if (this.cursor >= this.value.length) return `${this.value}\u2588`;
|
|
4527
|
+
const u2 = this.value.slice(0, this.cursor), [t, ...F2] = this.value.slice(this.cursor);
|
|
4528
|
+
return `${u2}${import_picocolors4.default.inverse(t)}${F2.join("")}`;
|
|
4529
|
+
}
|
|
4530
|
+
get cursor() {
|
|
4531
|
+
return this._cursor;
|
|
4532
|
+
}
|
|
4533
|
+
constructor(u2) {
|
|
4534
|
+
super(u2), this.on("finalize", () => {
|
|
4535
|
+
this.value || (this.value = u2.defaultValue);
|
|
4536
|
+
});
|
|
4537
|
+
}
|
|
4538
|
+
};
|
|
4497
4539
|
}
|
|
4498
4540
|
});
|
|
4499
4541
|
|
|
@@ -4503,7 +4545,7 @@ import y2 from "process";
|
|
|
4503
4545
|
function ce() {
|
|
4504
4546
|
return y2.platform !== "win32" ? y2.env.TERM !== "linux" : !!y2.env.CI || !!y2.env.WT_SESSION || !!y2.env.TERMINUS_SUBLIME || y2.env.ConEmuTask === "{cmd::Cmder}" || y2.env.TERM_PROGRAM === "Terminus-Sublime" || y2.env.TERM_PROGRAM === "vscode" || y2.env.TERM === "xterm-256color" || y2.env.TERM === "alacritty" || y2.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
4505
4547
|
}
|
|
4506
|
-
var import_picocolors5, import_sisteransi2, V2, u, le, L2, W2, C, ue, o, d2, k2, P2, A2, T, F, $e, _2, me, de, pe, q, D, U2, K2, b2, ge, ye, xe, Ie, Se,
|
|
4548
|
+
var import_picocolors5, import_sisteransi2, V2, u, le, L2, W2, C, ue, o, d2, k2, P2, A2, T, F, $e, _2, me, de, pe, q, D, U2, K2, b2, G2, he, ge, ye, ve, xe, Ie, Se, J2, Y2;
|
|
4507
4549
|
var init_dist2 = __esm({
|
|
4508
4550
|
"node_modules/@clack/prompts/dist/index.mjs"() {
|
|
4509
4551
|
"use strict";
|
|
@@ -4547,6 +4589,37 @@ var init_dist2 = __esm({
|
|
|
4547
4589
|
return import_picocolors5.default.green(C);
|
|
4548
4590
|
}
|
|
4549
4591
|
};
|
|
4592
|
+
G2 = (t) => {
|
|
4593
|
+
const { cursor: n, options: r2, style: i } = t, s = t.maxItems ?? Number.POSITIVE_INFINITY, c = Math.max(process.stdout.rows - 4, 0), a = Math.min(c, Math.max(s, 5));
|
|
4594
|
+
let l2 = 0;
|
|
4595
|
+
n >= l2 + a - 3 ? l2 = Math.max(Math.min(n - a + 3, r2.length - a), 0) : n < l2 + 2 && (l2 = Math.max(n - 2, 0));
|
|
4596
|
+
const $2 = a < r2.length && l2 > 0, g2 = a < r2.length && l2 + a < r2.length;
|
|
4597
|
+
return r2.slice(l2, l2 + a).map((p2, v2, f) => {
|
|
4598
|
+
const j2 = v2 === 0 && $2, E = v2 === f.length - 1 && g2;
|
|
4599
|
+
return j2 || E ? import_picocolors5.default.dim("...") : i(p2, v2 + l2 === n);
|
|
4600
|
+
});
|
|
4601
|
+
};
|
|
4602
|
+
he = (t) => new RD({ validate: t.validate, placeholder: t.placeholder, defaultValue: t.defaultValue, initialValue: t.initialValue, render() {
|
|
4603
|
+
const n = `${import_picocolors5.default.gray(o)}
|
|
4604
|
+
${b2(this.state)} ${t.message}
|
|
4605
|
+
`, r2 = t.placeholder ? import_picocolors5.default.inverse(t.placeholder[0]) + import_picocolors5.default.dim(t.placeholder.slice(1)) : import_picocolors5.default.inverse(import_picocolors5.default.hidden("_")), i = this.value ? this.valueWithCursor : r2;
|
|
4606
|
+
switch (this.state) {
|
|
4607
|
+
case "error":
|
|
4608
|
+
return `${n.trim()}
|
|
4609
|
+
${import_picocolors5.default.yellow(o)} ${i}
|
|
4610
|
+
${import_picocolors5.default.yellow(d2)} ${import_picocolors5.default.yellow(this.error)}
|
|
4611
|
+
`;
|
|
4612
|
+
case "submit":
|
|
4613
|
+
return `${n}${import_picocolors5.default.gray(o)} ${import_picocolors5.default.dim(this.value || t.placeholder)}`;
|
|
4614
|
+
case "cancel":
|
|
4615
|
+
return `${n}${import_picocolors5.default.gray(o)} ${import_picocolors5.default.strikethrough(import_picocolors5.default.dim(this.value ?? ""))}${this.value?.trim() ? `
|
|
4616
|
+
${import_picocolors5.default.gray(o)}` : ""}`;
|
|
4617
|
+
default:
|
|
4618
|
+
return `${n}${import_picocolors5.default.cyan(o)} ${i}
|
|
4619
|
+
${import_picocolors5.default.cyan(d2)}
|
|
4620
|
+
`;
|
|
4621
|
+
}
|
|
4622
|
+
} }).prompt();
|
|
4550
4623
|
ge = (t) => new MD({ validate: t.validate, mask: t.mask ?? $e, render() {
|
|
4551
4624
|
const n = `${import_picocolors5.default.gray(o)}
|
|
4552
4625
|
${b2(this.state)} ${t.message}
|
|
@@ -4583,6 +4656,38 @@ ${import_picocolors5.default.gray(o)}`;
|
|
|
4583
4656
|
default:
|
|
4584
4657
|
return `${i}${import_picocolors5.default.cyan(o)} ${this.value ? `${import_picocolors5.default.green(k2)} ${n}` : `${import_picocolors5.default.dim(P2)} ${import_picocolors5.default.dim(n)}`} ${import_picocolors5.default.dim("/")} ${this.value ? `${import_picocolors5.default.dim(P2)} ${import_picocolors5.default.dim(r2)}` : `${import_picocolors5.default.green(k2)} ${r2}`}
|
|
4585
4658
|
${import_picocolors5.default.cyan(d2)}
|
|
4659
|
+
`;
|
|
4660
|
+
}
|
|
4661
|
+
} }).prompt();
|
|
4662
|
+
};
|
|
4663
|
+
ve = (t) => {
|
|
4664
|
+
const n = (r2, i) => {
|
|
4665
|
+
const s = r2.label ?? String(r2.value);
|
|
4666
|
+
switch (i) {
|
|
4667
|
+
case "selected":
|
|
4668
|
+
return `${import_picocolors5.default.dim(s)}`;
|
|
4669
|
+
case "active":
|
|
4670
|
+
return `${import_picocolors5.default.green(k2)} ${s} ${r2.hint ? import_picocolors5.default.dim(`(${r2.hint})`) : ""}`;
|
|
4671
|
+
case "cancelled":
|
|
4672
|
+
return `${import_picocolors5.default.strikethrough(import_picocolors5.default.dim(s))}`;
|
|
4673
|
+
default:
|
|
4674
|
+
return `${import_picocolors5.default.dim(P2)} ${import_picocolors5.default.dim(s)}`;
|
|
4675
|
+
}
|
|
4676
|
+
};
|
|
4677
|
+
return new LD({ options: t.options, initialValue: t.initialValue, render() {
|
|
4678
|
+
const r2 = `${import_picocolors5.default.gray(o)}
|
|
4679
|
+
${b2(this.state)} ${t.message}
|
|
4680
|
+
`;
|
|
4681
|
+
switch (this.state) {
|
|
4682
|
+
case "submit":
|
|
4683
|
+
return `${r2}${import_picocolors5.default.gray(o)} ${n(this.options[this.cursor], "selected")}`;
|
|
4684
|
+
case "cancel":
|
|
4685
|
+
return `${r2}${import_picocolors5.default.gray(o)} ${n(this.options[this.cursor], "cancelled")}
|
|
4686
|
+
${import_picocolors5.default.gray(o)}`;
|
|
4687
|
+
default:
|
|
4688
|
+
return `${r2}${import_picocolors5.default.cyan(o)} ${G2({ cursor: this.cursor, options: this.options, maxItems: t.maxItems, style: (i, s) => n(i, s ? "active" : "inactive") }).join(`
|
|
4689
|
+
${import_picocolors5.default.cyan(o)} `)}
|
|
4690
|
+
${import_picocolors5.default.cyan(d2)}
|
|
4586
4691
|
`;
|
|
4587
4692
|
}
|
|
4588
4693
|
} }).prompt();
|
|
@@ -4602,7 +4707,7 @@ ${import_picocolors5.default.gray(d2)} ${t}
|
|
|
4602
4707
|
|
|
4603
4708
|
`);
|
|
4604
4709
|
};
|
|
4605
|
-
|
|
4710
|
+
J2 = `${import_picocolors5.default.gray(o)} `;
|
|
4606
4711
|
Y2 = ({ indicator: t = "dots" } = {}) => {
|
|
4607
4712
|
const n = V2 ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"], r2 = V2 ? 80 : 120, i = process.env.CI === "true";
|
|
4608
4713
|
let s, c, a = false, l2 = "", $2, g2 = performance.now();
|
|
@@ -4907,10 +5012,10 @@ function keysFilePath(env) {
|
|
|
4907
5012
|
const expanded = expandHome(configured);
|
|
4908
5013
|
return isAbsolute(expanded) ? expanded : expanded;
|
|
4909
5014
|
}
|
|
4910
|
-
function parseKeysFile(
|
|
5015
|
+
function parseKeysFile(path29) {
|
|
4911
5016
|
let text2;
|
|
4912
5017
|
try {
|
|
4913
|
-
text2 = readFileSync3(
|
|
5018
|
+
text2 = readFileSync3(path29, "utf8");
|
|
4914
5019
|
} catch {
|
|
4915
5020
|
return {};
|
|
4916
5021
|
}
|
|
@@ -5022,18 +5127,18 @@ function upsertKeyLines(existing, updates) {
|
|
|
5022
5127
|
if (!text2.endsWith("\n")) text2 += "\n";
|
|
5023
5128
|
return text2;
|
|
5024
5129
|
}
|
|
5025
|
-
function restrictPermissions(
|
|
5130
|
+
function restrictPermissions(path29) {
|
|
5026
5131
|
if (process.platform === "win32") return null;
|
|
5027
5132
|
try {
|
|
5028
|
-
chmodSync(
|
|
5133
|
+
chmodSync(path29, 384);
|
|
5029
5134
|
return null;
|
|
5030
5135
|
} catch (error) {
|
|
5031
5136
|
return error instanceof Error ? error.message : String(error);
|
|
5032
5137
|
}
|
|
5033
5138
|
}
|
|
5034
5139
|
async function keys(options = {}) {
|
|
5035
|
-
const
|
|
5036
|
-
const fileKeys = parseKeysFile(
|
|
5140
|
+
const path29 = keysFilePath(process.env);
|
|
5141
|
+
const fileKeys = parseKeysFile(path29);
|
|
5037
5142
|
const names = Object.keys(PROVIDERS).sort();
|
|
5038
5143
|
const current = names.map((name) => {
|
|
5039
5144
|
const preset = PROVIDERS[name];
|
|
@@ -5049,7 +5154,7 @@ async function keys(options = {}) {
|
|
|
5049
5154
|
if (options.check) {
|
|
5050
5155
|
const configured = current.filter((entry) => entry.value);
|
|
5051
5156
|
if (!configured.length) {
|
|
5052
|
-
process.stdout.write(`no provider keys configured (looked in $ENV and ${
|
|
5157
|
+
process.stdout.write(`no provider keys configured (looked in $ENV and ${path29})
|
|
5053
5158
|
`);
|
|
5054
5159
|
return 1;
|
|
5055
5160
|
}
|
|
@@ -5064,7 +5169,7 @@ async function keys(options = {}) {
|
|
|
5064
5169
|
return bad ? 1 : 0;
|
|
5065
5170
|
}
|
|
5066
5171
|
Ie("caddis keys");
|
|
5067
|
-
process.stdout.write(` keys file: ${
|
|
5172
|
+
process.stdout.write(` keys file: ${path29}
|
|
5068
5173
|
|
|
5069
5174
|
`);
|
|
5070
5175
|
for (const entry of current) {
|
|
@@ -5124,20 +5229,20 @@ async function keys(options = {}) {
|
|
|
5124
5229
|
return 0;
|
|
5125
5230
|
}
|
|
5126
5231
|
if (options.dryRun) {
|
|
5127
|
-
Se(`dry run \u2014 would write ${Object.keys(collected).join(", ")} to ${
|
|
5232
|
+
Se(`dry run \u2014 would write ${Object.keys(collected).join(", ")} to ${path29}`);
|
|
5128
5233
|
return 0;
|
|
5129
5234
|
}
|
|
5130
5235
|
let existing = "";
|
|
5131
5236
|
try {
|
|
5132
|
-
existing = readFileSync4(
|
|
5237
|
+
existing = readFileSync4(path29, "utf8");
|
|
5133
5238
|
} catch {
|
|
5134
5239
|
existing = "";
|
|
5135
5240
|
}
|
|
5136
|
-
mkdirSync2(dirname(
|
|
5137
|
-
writeFileSync(
|
|
5138
|
-
const permWarning = restrictPermissions(
|
|
5241
|
+
mkdirSync2(dirname(path29), { recursive: true });
|
|
5242
|
+
writeFileSync(path29, upsertKeyLines(existing, collected), { encoding: "utf8" });
|
|
5243
|
+
const permWarning = restrictPermissions(path29);
|
|
5139
5244
|
process.stdout.write(`
|
|
5140
|
-
wrote ${Object.keys(collected).join(", ")} to ${
|
|
5245
|
+
wrote ${Object.keys(collected).join(", ")} to ${path29}
|
|
5141
5246
|
`);
|
|
5142
5247
|
if (permWarning) process.stdout.write(color2.yellow(` could not set 0600 on the keys file: ${permWarning}
|
|
5143
5248
|
`));
|
|
@@ -5740,35 +5845,555 @@ var init_status = __esm({
|
|
|
5740
5845
|
}
|
|
5741
5846
|
});
|
|
5742
5847
|
|
|
5743
|
-
// src/
|
|
5848
|
+
// src/commands/email.ts
|
|
5849
|
+
var email_exports = {};
|
|
5850
|
+
__export(email_exports, {
|
|
5851
|
+
GRAPH_CLIENT_KEY: () => GRAPH_CLIENT_KEY,
|
|
5852
|
+
GRAPH_SECRET_KEY: () => GRAPH_SECRET_KEY,
|
|
5853
|
+
GRAPH_TENANT_KEY: () => GRAPH_TENANT_KEY,
|
|
5854
|
+
SECRET_ENV_GRAPH: () => SECRET_ENV_GRAPH,
|
|
5855
|
+
SECRET_ENV_SMTP: () => SECRET_ENV_SMTP,
|
|
5856
|
+
SMTP_PASSWORD_KEY: () => SMTP_PASSWORD_KEY,
|
|
5857
|
+
buildEnvText: () => buildEnvText,
|
|
5858
|
+
buildToml: () => buildToml,
|
|
5859
|
+
defaultPort: () => defaultPort,
|
|
5860
|
+
emailCheck: () => emailCheck,
|
|
5861
|
+
emailPaths: () => emailPaths,
|
|
5862
|
+
emailSetup: () => emailSetup,
|
|
5863
|
+
envFileMissingKeys: () => envFileMissingKeys,
|
|
5864
|
+
findEmailScript: () => findEmailScript,
|
|
5865
|
+
isGuid: () => isGuid,
|
|
5866
|
+
summariseExisting: () => summariseExisting,
|
|
5867
|
+
tomlLiteral: () => tomlLiteral
|
|
5868
|
+
});
|
|
5869
|
+
import { chmodSync as chmodSync2, existsSync as existsSync6, mkdirSync as mkdirSync3, readFileSync as readFileSync6, readdirSync as readdirSync3, statSync, writeFileSync as writeFileSync2 } from "fs";
|
|
5870
|
+
import "os";
|
|
5744
5871
|
import path7 from "path";
|
|
5872
|
+
function defaultPort(security) {
|
|
5873
|
+
return SMTP_PORTS[security];
|
|
5874
|
+
}
|
|
5875
|
+
function isGuid(value) {
|
|
5876
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
|
5877
|
+
}
|
|
5878
|
+
function isMailbox(value) {
|
|
5879
|
+
return /^[^\s@"'\\]+@[^\s@"'\\]+\.[^\s@"'\\]+$/.test(value);
|
|
5880
|
+
}
|
|
5881
|
+
function tomlLiteral(value) {
|
|
5882
|
+
if (value.includes("'")) throw new Error("the path contains a single quote; move the file to a path without one");
|
|
5883
|
+
if (/[\r\n]/.test(value)) throw new Error("the path contains a line break");
|
|
5884
|
+
return `'${value}'`;
|
|
5885
|
+
}
|
|
5886
|
+
function tomlString(value) {
|
|
5887
|
+
return JSON.stringify(value);
|
|
5888
|
+
}
|
|
5889
|
+
function buildToml(a) {
|
|
5890
|
+
const lines = [
|
|
5891
|
+
"# Written by `caddis email setup`. Secrets are never stored in this file.",
|
|
5892
|
+
"# Every key is described in email.toml.example in the send-email skill folder.",
|
|
5893
|
+
`provider = ${tomlString(a.provider)}`,
|
|
5894
|
+
`sender = ${tomlString(a.sender)}`
|
|
5895
|
+
];
|
|
5896
|
+
if (a.envFile) lines.push(`env_file = ${tomlLiteral(a.envFile)}`);
|
|
5897
|
+
lines.push("");
|
|
5898
|
+
if (a.provider === "graph") {
|
|
5899
|
+
lines.push(
|
|
5900
|
+
"[graph]",
|
|
5901
|
+
`tenant_id_key = ${tomlString(GRAPH_TENANT_KEY)}`,
|
|
5902
|
+
`client_id_key = ${tomlString(GRAPH_CLIENT_KEY)}`,
|
|
5903
|
+
`client_secret_key = ${tomlString(GRAPH_SECRET_KEY)}`
|
|
5904
|
+
);
|
|
5905
|
+
} else {
|
|
5906
|
+
const s = a.smtp;
|
|
5907
|
+
if (!s) throw new Error("smtp settings are required for provider smtp");
|
|
5908
|
+
lines.push(
|
|
5909
|
+
"[smtp]",
|
|
5910
|
+
`host = ${tomlString(s.host)}`,
|
|
5911
|
+
`security = ${tomlString(s.security)}`,
|
|
5912
|
+
`port = ${s.port}`,
|
|
5913
|
+
`username = ${tomlString(s.username)}`,
|
|
5914
|
+
`password_key = ${tomlString(SMTP_PASSWORD_KEY)}`,
|
|
5915
|
+
"timeout = 30"
|
|
5916
|
+
);
|
|
5917
|
+
}
|
|
5918
|
+
lines.push("");
|
|
5919
|
+
return lines.join("\n");
|
|
5920
|
+
}
|
|
5921
|
+
function buildEnvText(values) {
|
|
5922
|
+
const lines = ["# Written by `caddis email setup`. Keep this file private."];
|
|
5923
|
+
for (const [key, value] of Object.entries(values)) lines.push(`${key}=${value}`);
|
|
5924
|
+
return `${lines.join("\n")}
|
|
5925
|
+
`;
|
|
5926
|
+
}
|
|
5927
|
+
function envFileMissingKeys(envText, required) {
|
|
5928
|
+
const present = /* @__PURE__ */ new Set();
|
|
5929
|
+
for (const raw of envText.split(/\r?\n/)) {
|
|
5930
|
+
const line2 = raw.trim();
|
|
5931
|
+
if (!line2 || line2.startsWith("#") || !line2.includes("=")) continue;
|
|
5932
|
+
const at = line2.indexOf("=");
|
|
5933
|
+
const value = line2.slice(at + 1).trim().replace(/^"+|"+$/g, "").replace(/^'+|'+$/g, "");
|
|
5934
|
+
if (value) present.add(line2.slice(0, at).trim());
|
|
5935
|
+
}
|
|
5936
|
+
return required.filter((key) => !present.has(key));
|
|
5937
|
+
}
|
|
5938
|
+
function secretProblem(label, value) {
|
|
5939
|
+
if (!value) return `${label} is empty`;
|
|
5940
|
+
if (/[\r\n]/.test(value)) return `${label} must be one line`;
|
|
5941
|
+
if (value !== value.trim()) return `${label} has leading or trailing spaces`;
|
|
5942
|
+
if (/^["']|["']$/.test(value)) return `${label} cannot start or end with a quote (the reader strips quotes)`;
|
|
5943
|
+
return void 0;
|
|
5944
|
+
}
|
|
5945
|
+
function summariseExisting(tomlText) {
|
|
5946
|
+
return tomlText.split(/\r?\n/).filter((line2) => NON_SECRET_LINE.test(line2)).map((line2) => line2.trim());
|
|
5947
|
+
}
|
|
5948
|
+
function emailPaths(home) {
|
|
5949
|
+
const dir = path7.join(home, ".caddis");
|
|
5950
|
+
return { dir, toml: path7.join(dir, "email.toml"), env: path7.join(dir, "email.env") };
|
|
5951
|
+
}
|
|
5952
|
+
function versionsDesc(dir) {
|
|
5953
|
+
let names;
|
|
5954
|
+
try {
|
|
5955
|
+
names = readdirSync3(dir);
|
|
5956
|
+
} catch {
|
|
5957
|
+
return [];
|
|
5958
|
+
}
|
|
5959
|
+
return names.sort((a, b3) => (compareVersions(b3, a) ?? 0) || b3.localeCompare(a));
|
|
5960
|
+
}
|
|
5961
|
+
function findEmailScript({ home, packageRoot = packageInfo().root }) {
|
|
5962
|
+
const core = [];
|
|
5963
|
+
const extras = [];
|
|
5964
|
+
const pluginsDir = path7.join(home, ".claude", "plugins");
|
|
5965
|
+
try {
|
|
5966
|
+
const parsed = JSON.parse(readFileSync6(path7.join(pluginsDir, "installed_plugins.json"), "utf8"));
|
|
5967
|
+
for (const [key, entries] of Object.entries(parsed.plugins ?? {})) {
|
|
5968
|
+
if (!(key.startsWith("caddis@") || key.startsWith("caddis-extras@")) || !Array.isArray(entries)) continue;
|
|
5969
|
+
for (const entry of entries) {
|
|
5970
|
+
const installPath = entry?.installPath;
|
|
5971
|
+
if (typeof installPath !== "string" || !installPath) continue;
|
|
5972
|
+
if (key.startsWith("caddis@")) core.push(path7.join(installPath, ...SCRIPT_REL));
|
|
5973
|
+
else extras.push(path7.join(installPath, ...LEGACY_SCRIPT_REL));
|
|
5974
|
+
}
|
|
5975
|
+
}
|
|
5976
|
+
} catch {
|
|
5977
|
+
}
|
|
5978
|
+
for (const [plugin, into] of [["caddis", core], ["caddis-extras", extras]]) {
|
|
5979
|
+
const base = path7.join(pluginsDir, "cache", "caddis", plugin);
|
|
5980
|
+
const rel = plugin === "caddis" ? SCRIPT_REL : LEGACY_SCRIPT_REL;
|
|
5981
|
+
for (const version of versionsDesc(base)) into.push(path7.join(base, version, ...rel));
|
|
5982
|
+
}
|
|
5983
|
+
const candidates = [...core, ...extras];
|
|
5984
|
+
candidates.push(path7.join(packageRoot, "bundles", "antigravity-plugin", ...SCRIPT_REL));
|
|
5985
|
+
candidates.push(path7.join(packageRoot, "..", ".github", "skills", "devops", "send-email", "scripts", "send_email.py"));
|
|
5986
|
+
for (const file of candidates) {
|
|
5987
|
+
try {
|
|
5988
|
+
if (statSync(file).isFile()) return file;
|
|
5989
|
+
} catch {
|
|
5990
|
+
}
|
|
5991
|
+
}
|
|
5992
|
+
return null;
|
|
5993
|
+
}
|
|
5994
|
+
async function findPython(run2) {
|
|
5995
|
+
for (const candidate of PYTHON_CANDIDATES) {
|
|
5996
|
+
const res = await run2(candidate.cmd, [...candidate.pre, "--version"], { timeout: 15e3 });
|
|
5997
|
+
if (!res.ok) continue;
|
|
5998
|
+
const m2 = /Python (\d+)\.(\d+)/.exec(`${res.stdout}
|
|
5999
|
+
${res.stderr}`);
|
|
6000
|
+
if (m2 && (Number(m2[1]) < 3 || Number(m2[1]) === 3 && Number(m2[2]) < 11)) continue;
|
|
6001
|
+
return candidate;
|
|
6002
|
+
}
|
|
6003
|
+
return null;
|
|
6004
|
+
}
|
|
6005
|
+
async function emailCheck(options = {}) {
|
|
6006
|
+
const home = options.home ?? caddisHome();
|
|
6007
|
+
const env = options.env ?? process.env;
|
|
6008
|
+
const run2 = options.run ?? run;
|
|
6009
|
+
const config = options.configPath ?? ((env.CADDIS_EMAIL_CONFIG || "").trim() || emailPaths(home).toml);
|
|
6010
|
+
const script = findEmailScript({ home, packageRoot: options.packageRoot });
|
|
6011
|
+
if (!script) {
|
|
6012
|
+
process.stdout.write(` could not find send_email.py (the send-email skill is not installed here).
|
|
6013
|
+
${FALLBACK}
|
|
6014
|
+
`);
|
|
6015
|
+
return 1;
|
|
6016
|
+
}
|
|
6017
|
+
const python = await findPython(run2);
|
|
6018
|
+
if (!python) {
|
|
6019
|
+
process.stdout.write(` Python 3.11 or later was not found on PATH.
|
|
6020
|
+
${FALLBACK}
|
|
6021
|
+
`);
|
|
6022
|
+
return 1;
|
|
6023
|
+
}
|
|
6024
|
+
const result = await run2(python.cmd, [...python.pre, "-I", script, "--check"], {
|
|
6025
|
+
env: { CADDIS_EMAIL_CONFIG: config },
|
|
6026
|
+
timeout: 6e4
|
|
6027
|
+
});
|
|
6028
|
+
if (result.failure) {
|
|
6029
|
+
process.stdout.write(` could not run the check (${result.failure}).
|
|
6030
|
+
${FALLBACK}
|
|
6031
|
+
`);
|
|
6032
|
+
return 1;
|
|
6033
|
+
}
|
|
6034
|
+
for (const line2 of `${result.stdout}
|
|
6035
|
+
${result.stderr}`.split(/\r?\n/)) {
|
|
6036
|
+
if (line2.trim()) process.stdout.write(` ${line2}
|
|
6037
|
+
`);
|
|
6038
|
+
}
|
|
6039
|
+
return result.code ?? 1;
|
|
6040
|
+
}
|
|
6041
|
+
function expandHome2(p2, home) {
|
|
6042
|
+
if (p2 === "~") return home;
|
|
6043
|
+
if (p2.startsWith("~/") || p2.startsWith("~\\")) return path7.join(home, p2.slice(2));
|
|
6044
|
+
return p2;
|
|
6045
|
+
}
|
|
6046
|
+
function writePrivate(file, content) {
|
|
6047
|
+
writeFileSync2(file, content, { encoding: "utf8", mode: 384 });
|
|
6048
|
+
if (process.platform !== "win32") chmodSync2(file, 384);
|
|
6049
|
+
}
|
|
6050
|
+
async function emailSetup(options = {}, deps = {}) {
|
|
6051
|
+
const home = deps.home ?? caddisHome();
|
|
6052
|
+
const env = deps.env ?? process.env;
|
|
6053
|
+
const paths = emailPaths(home);
|
|
6054
|
+
const interactive = !options.yes && (deps.prompts !== void 0 || Boolean(process.stdin.isTTY));
|
|
6055
|
+
const prompts = deps.prompts ?? clackPrompts;
|
|
6056
|
+
const say = (line2 = "") => void process.stdout.write(`${line2}
|
|
6057
|
+
`);
|
|
6058
|
+
const missing = [];
|
|
6059
|
+
const need = (value, flag) => {
|
|
6060
|
+
if (value === void 0 || value === "") missing.push(flag);
|
|
6061
|
+
return value === "" ? void 0 : value;
|
|
6062
|
+
};
|
|
6063
|
+
const orCancel = (value) => {
|
|
6064
|
+
if (value === null) throw new Cancelled();
|
|
6065
|
+
return value;
|
|
6066
|
+
};
|
|
6067
|
+
if (interactive) Ie("caddis email setup");
|
|
6068
|
+
try {
|
|
6069
|
+
const existingToml = existsSync6(paths.toml) ? readFileSync6(paths.toml, "utf8") : null;
|
|
6070
|
+
if (existingToml !== null && !options.force) {
|
|
6071
|
+
say(` ${paths.toml} already exists. Its settings:`);
|
|
6072
|
+
for (const line2 of summariseExisting(existingToml)) say(` ${line2}`);
|
|
6073
|
+
if (!interactive) {
|
|
6074
|
+
say(" Nothing written. Use --force to replace it.");
|
|
6075
|
+
return 1;
|
|
6076
|
+
}
|
|
6077
|
+
const yes = orCancel(await prompts.confirm({ message: "Overwrite it?", initialValue: false }));
|
|
6078
|
+
if (!yes) {
|
|
6079
|
+
xe("kept the existing file; nothing written");
|
|
6080
|
+
return 1;
|
|
6081
|
+
}
|
|
6082
|
+
}
|
|
6083
|
+
let provider;
|
|
6084
|
+
if (options.provider !== void 0) {
|
|
6085
|
+
if (options.provider !== "graph" && options.provider !== "smtp") throw new Invalid("--provider must be graph or smtp");
|
|
6086
|
+
provider = options.provider;
|
|
6087
|
+
} else if (interactive) {
|
|
6088
|
+
provider = orCancel(
|
|
6089
|
+
await prompts.select({
|
|
6090
|
+
message: "Provider",
|
|
6091
|
+
options: [
|
|
6092
|
+
{ value: "graph", label: "Microsoft Graph", hint: "Entra app registration, client credentials" },
|
|
6093
|
+
{ value: "smtp", label: "SMTP" }
|
|
6094
|
+
],
|
|
6095
|
+
initialValue: "graph"
|
|
6096
|
+
})
|
|
6097
|
+
);
|
|
6098
|
+
} else {
|
|
6099
|
+
provider = "graph";
|
|
6100
|
+
}
|
|
6101
|
+
let sender = options.sender?.trim();
|
|
6102
|
+
if (sender === void 0 && interactive) {
|
|
6103
|
+
sender = orCancel(
|
|
6104
|
+
await prompts.text({
|
|
6105
|
+
message: "Sender mailbox (the address mail is sent from)",
|
|
6106
|
+
placeholder: "ba-bot@example.com",
|
|
6107
|
+
validate: (v2) => isMailbox(v2.trim()) ? void 0 : "enter an email address"
|
|
6108
|
+
})
|
|
6109
|
+
).trim();
|
|
6110
|
+
}
|
|
6111
|
+
need(sender, "--sender");
|
|
6112
|
+
if (sender && !isMailbox(sender)) throw new Invalid("the sender must be an email address");
|
|
6113
|
+
let smtp;
|
|
6114
|
+
if (provider === "smtp") {
|
|
6115
|
+
let host = options.smtpHost?.trim();
|
|
6116
|
+
if (host === void 0 && interactive) {
|
|
6117
|
+
host = orCancel(
|
|
6118
|
+
await prompts.text({
|
|
6119
|
+
message: "SMTP host",
|
|
6120
|
+
validate: (v2) => v2.trim() && !/\s/.test(v2.trim()) ? void 0 : "enter a host name"
|
|
6121
|
+
})
|
|
6122
|
+
).trim();
|
|
6123
|
+
}
|
|
6124
|
+
need(host, "--smtp-host");
|
|
6125
|
+
if (host && /\s/.test(host)) throw new Invalid("the SMTP host cannot contain spaces");
|
|
6126
|
+
let security;
|
|
6127
|
+
if (options.smtpSecurity !== void 0) {
|
|
6128
|
+
if (!SECURITIES.includes(options.smtpSecurity)) throw new Invalid("--smtp-security must be starttls, ssl or none");
|
|
6129
|
+
security = options.smtpSecurity;
|
|
6130
|
+
} else if (interactive) {
|
|
6131
|
+
security = orCancel(
|
|
6132
|
+
await prompts.select({
|
|
6133
|
+
message: "SMTP security",
|
|
6134
|
+
options: [
|
|
6135
|
+
{ value: "starttls", label: "starttls", hint: "port 587" },
|
|
6136
|
+
{ value: "ssl", label: "ssl", hint: "port 465" },
|
|
6137
|
+
{ value: "none", label: "none", hint: "port 25, no encryption, no login" }
|
|
6138
|
+
],
|
|
6139
|
+
initialValue: "starttls"
|
|
6140
|
+
})
|
|
6141
|
+
);
|
|
6142
|
+
} else {
|
|
6143
|
+
security = "starttls";
|
|
6144
|
+
}
|
|
6145
|
+
let port;
|
|
6146
|
+
if (options.smtpPort !== void 0 && options.smtpPort !== "") {
|
|
6147
|
+
port = Number(options.smtpPort);
|
|
6148
|
+
} else if (interactive) {
|
|
6149
|
+
const answer = orCancel(
|
|
6150
|
+
await prompts.text({
|
|
6151
|
+
message: "SMTP port",
|
|
6152
|
+
initialValue: String(defaultPort(security)),
|
|
6153
|
+
validate: (v2) => /^\d+$/.test(v2.trim()) && Number(v2) >= 1 && Number(v2) <= 65535 ? void 0 : "enter a port from 1 to 65535"
|
|
6154
|
+
})
|
|
6155
|
+
);
|
|
6156
|
+
port = Number(answer.trim());
|
|
6157
|
+
} else {
|
|
6158
|
+
port = defaultPort(security);
|
|
6159
|
+
}
|
|
6160
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Invalid("the SMTP port must be a number from 1 to 65535");
|
|
6161
|
+
let username = options.smtpUsername?.trim();
|
|
6162
|
+
if (username === void 0 && interactive) {
|
|
6163
|
+
username = orCancel(await prompts.text({ message: "SMTP username (leave empty if the server needs no login)" })).trim();
|
|
6164
|
+
}
|
|
6165
|
+
username = username ?? "";
|
|
6166
|
+
if (/[\r\n]/.test(username)) throw new Invalid("the SMTP username must be one line");
|
|
6167
|
+
if (security === "none" && username) {
|
|
6168
|
+
throw new Invalid('SMTP security "none" cannot carry a login (it would go in clear text); use starttls or ssl');
|
|
6169
|
+
}
|
|
6170
|
+
if (host) smtp = { host, security, port, username };
|
|
6171
|
+
}
|
|
6172
|
+
const requiredKeys = provider === "graph" ? [GRAPH_TENANT_KEY, GRAPH_CLIENT_KEY, GRAPH_SECRET_KEY] : smtp?.username ? [SMTP_PASSWORD_KEY] : [];
|
|
6173
|
+
let envFile = options.envFile?.trim();
|
|
6174
|
+
let envValues = null;
|
|
6175
|
+
if (requiredKeys.length) {
|
|
6176
|
+
let source = envFile ? "file" : void 0;
|
|
6177
|
+
const secretFromEnv = (provider === "graph" ? env[SECRET_ENV_GRAPH] : env[SECRET_ENV_SMTP])?.trim();
|
|
6178
|
+
if (!source && interactive) {
|
|
6179
|
+
source = orCancel(
|
|
6180
|
+
await prompts.select({
|
|
6181
|
+
message: "Where are the secrets",
|
|
6182
|
+
options: [
|
|
6183
|
+
{ value: "file", label: "I have an env file", hint: `it holds ${requiredKeys.join(", ")}` },
|
|
6184
|
+
{ value: "values", label: "Enter the values", hint: "saved to ~/.caddis/email.env, never to email.toml" }
|
|
6185
|
+
],
|
|
6186
|
+
initialValue: "values"
|
|
6187
|
+
})
|
|
6188
|
+
);
|
|
6189
|
+
} else if (!source && !interactive) {
|
|
6190
|
+
source = "values";
|
|
6191
|
+
}
|
|
6192
|
+
if (source === "file") {
|
|
6193
|
+
if (!envFile && interactive) {
|
|
6194
|
+
envFile = orCancel(
|
|
6195
|
+
await prompts.text({
|
|
6196
|
+
message: "Path to the env file",
|
|
6197
|
+
validate: (v2) => {
|
|
6198
|
+
const p2 = path7.resolve(expandHome2(v2.trim(), home));
|
|
6199
|
+
return v2.trim() && existsSync6(p2) && statSync(p2).isFile() ? void 0 : "that file does not exist";
|
|
6200
|
+
}
|
|
6201
|
+
})
|
|
6202
|
+
).trim();
|
|
6203
|
+
}
|
|
6204
|
+
const resolved = path7.resolve(expandHome2(envFile ?? "", home));
|
|
6205
|
+
if (!envFile || !existsSync6(resolved) || !statSync(resolved).isFile()) throw new Invalid(`the env file does not exist: ${envFile || "(none given)"}`);
|
|
6206
|
+
const absent = envFileMissingKeys(readFileSync6(resolved, "utf8"), requiredKeys);
|
|
6207
|
+
if (absent.length) throw new Invalid(`the env file is missing: ${absent.join(", ")}`);
|
|
6208
|
+
envFile = resolved;
|
|
6209
|
+
} else {
|
|
6210
|
+
if (existsSync6(paths.env) && !options.force) {
|
|
6211
|
+
if (!interactive) {
|
|
6212
|
+
say(` ${paths.env} already exists. Nothing written. Use --force to replace it.`);
|
|
6213
|
+
return 1;
|
|
6214
|
+
}
|
|
6215
|
+
const yes = orCancel(await prompts.confirm({ message: `Overwrite ${paths.env}?`, initialValue: false }));
|
|
6216
|
+
if (!yes) {
|
|
6217
|
+
xe("kept the existing file; nothing written");
|
|
6218
|
+
return 1;
|
|
6219
|
+
}
|
|
6220
|
+
}
|
|
6221
|
+
if (provider === "graph") {
|
|
6222
|
+
let tenant = options.tenantId?.trim();
|
|
6223
|
+
if (tenant === void 0 && interactive) {
|
|
6224
|
+
tenant = orCancel(
|
|
6225
|
+
await prompts.text({
|
|
6226
|
+
message: "Tenant ID (a GUID)",
|
|
6227
|
+
validate: (v2) => isGuid(v2.trim()) ? void 0 : "a GUID looks like 00000000-0000-0000-0000-000000000000"
|
|
6228
|
+
})
|
|
6229
|
+
).trim();
|
|
6230
|
+
}
|
|
6231
|
+
let client = options.clientId?.trim();
|
|
6232
|
+
if (client === void 0 && interactive) {
|
|
6233
|
+
client = orCancel(
|
|
6234
|
+
await prompts.text({
|
|
6235
|
+
message: "Client ID (a GUID)",
|
|
6236
|
+
validate: (v2) => isGuid(v2.trim()) ? void 0 : "a GUID looks like 00000000-0000-0000-0000-000000000000"
|
|
6237
|
+
})
|
|
6238
|
+
).trim();
|
|
6239
|
+
}
|
|
6240
|
+
let secret = secretFromEnv || void 0;
|
|
6241
|
+
if (secret === void 0 && interactive) {
|
|
6242
|
+
secret = orCancel(await prompts.password({ message: "Client secret", validate: (v2) => secretProblem("the secret", v2.trim()) })).trim();
|
|
6243
|
+
}
|
|
6244
|
+
need(tenant, "--tenant-id");
|
|
6245
|
+
need(client, "--client-id");
|
|
6246
|
+
need(secret, `${SECRET_ENV_GRAPH} (environment variable)`);
|
|
6247
|
+
if (tenant && !isGuid(tenant)) throw new Invalid("the tenant ID must be a GUID");
|
|
6248
|
+
if (client && !isGuid(client)) throw new Invalid("the client ID must be a GUID");
|
|
6249
|
+
if (secret) {
|
|
6250
|
+
const problem = secretProblem("the client secret", secret);
|
|
6251
|
+
if (problem) throw new Invalid(problem);
|
|
6252
|
+
}
|
|
6253
|
+
if (tenant && client && secret) {
|
|
6254
|
+
envValues = { [GRAPH_TENANT_KEY]: tenant, [GRAPH_CLIENT_KEY]: client, [GRAPH_SECRET_KEY]: secret };
|
|
6255
|
+
}
|
|
6256
|
+
} else {
|
|
6257
|
+
let pw = secretFromEnv || void 0;
|
|
6258
|
+
if (pw === void 0 && interactive) {
|
|
6259
|
+
pw = orCancel(await prompts.password({ message: "SMTP password", validate: (v2) => secretProblem("the password", v2.trim()) })).trim();
|
|
6260
|
+
}
|
|
6261
|
+
need(pw, `${SECRET_ENV_SMTP} (environment variable)`);
|
|
6262
|
+
if (pw) {
|
|
6263
|
+
const problem = secretProblem("the SMTP password", pw);
|
|
6264
|
+
if (problem) throw new Invalid(problem);
|
|
6265
|
+
envValues = { [SMTP_PASSWORD_KEY]: pw };
|
|
6266
|
+
}
|
|
6267
|
+
}
|
|
6268
|
+
if (envValues) envFile = paths.env;
|
|
6269
|
+
}
|
|
6270
|
+
}
|
|
6271
|
+
if (missing.length) throw new Invalid(`missing: ${missing.join(", ")}. Run without --yes to be asked.`);
|
|
6272
|
+
if (!sender) throw new Invalid("missing: --sender");
|
|
6273
|
+
const toml = buildToml({ provider, sender, envFile, smtp });
|
|
6274
|
+
if (options.dryRun) {
|
|
6275
|
+
say(" dry run: would write these non-secret settings to " + paths.toml);
|
|
6276
|
+
for (const line2 of toml.split("\n")) say(` ${line2}`);
|
|
6277
|
+
if (envValues) say(` and the keys ${Object.keys(envValues).join(", ")} to ${paths.env} (values not shown)`);
|
|
6278
|
+
if (interactive) Se("dry run: nothing written");
|
|
6279
|
+
return 0;
|
|
6280
|
+
}
|
|
6281
|
+
mkdirSync3(paths.dir, { recursive: true });
|
|
6282
|
+
if (envValues) writePrivate(paths.env, buildEnvText(envValues));
|
|
6283
|
+
writeFileSync2(paths.toml, toml, { encoding: "utf8" });
|
|
6284
|
+
say();
|
|
6285
|
+
say(` wrote ${paths.toml}`);
|
|
6286
|
+
if (envValues) say(` wrote ${paths.env} (${Object.keys(envValues).join(", ")}; values not shown)`);
|
|
6287
|
+
else if (envFile) say(` using your env file ${envFile}`);
|
|
6288
|
+
} catch (error) {
|
|
6289
|
+
if (error instanceof Cancelled) {
|
|
6290
|
+
xe("cancelled: nothing written");
|
|
6291
|
+
return 1;
|
|
6292
|
+
}
|
|
6293
|
+
errorLine(error instanceof Error ? error.message : String(error));
|
|
6294
|
+
return 2;
|
|
6295
|
+
}
|
|
6296
|
+
if (options.noCheck) {
|
|
6297
|
+
if (interactive) Se("done");
|
|
6298
|
+
return 0;
|
|
6299
|
+
}
|
|
6300
|
+
say();
|
|
6301
|
+
say(" checking the setup (sends nothing):");
|
|
6302
|
+
const code = await emailCheck({ home, env, run: deps.run, packageRoot: deps.packageRoot, configPath: paths.toml });
|
|
6303
|
+
if (interactive) {
|
|
6304
|
+
Se(code === 0 ? color2.green("email is set up. Try /caddis:graph-email in a session.") : "written, but the check did not pass. Fix the item above, then run `caddis email check`.");
|
|
6305
|
+
}
|
|
6306
|
+
return code;
|
|
6307
|
+
}
|
|
6308
|
+
var GRAPH_TENANT_KEY, GRAPH_CLIENT_KEY, GRAPH_SECRET_KEY, SMTP_PASSWORD_KEY, SECRET_ENV_GRAPH, SECRET_ENV_SMTP, SECURITIES, SMTP_PORTS, NON_SECRET_LINE, SCRIPT_REL, LEGACY_SCRIPT_REL, clackPrompts, PYTHON_CANDIDATES, FALLBACK, Cancelled, Invalid;
|
|
6309
|
+
var init_email = __esm({
|
|
6310
|
+
"src/commands/email.ts"() {
|
|
6311
|
+
"use strict";
|
|
6312
|
+
init_dist2();
|
|
6313
|
+
init_exec();
|
|
6314
|
+
init_log();
|
|
6315
|
+
init_pkg();
|
|
6316
|
+
init_semver();
|
|
6317
|
+
init_sessions();
|
|
6318
|
+
GRAPH_TENANT_KEY = "ALERT_GRAPH_TENANT_ID";
|
|
6319
|
+
GRAPH_CLIENT_KEY = "ALERT_GRAPH_CLIENT_ID";
|
|
6320
|
+
GRAPH_SECRET_KEY = "ALERT_GRAPH_CLIENT_SECRET";
|
|
6321
|
+
SMTP_PASSWORD_KEY = "EMAIL_SMTP_PASSWORD";
|
|
6322
|
+
SECRET_ENV_GRAPH = "CADDIS_EMAIL_CLIENT_SECRET";
|
|
6323
|
+
SECRET_ENV_SMTP = "CADDIS_EMAIL_SMTP_PASSWORD";
|
|
6324
|
+
SECURITIES = ["starttls", "ssl", "none"];
|
|
6325
|
+
SMTP_PORTS = { starttls: 587, ssl: 465, none: 25 };
|
|
6326
|
+
NON_SECRET_LINE = /^\s*(provider|sender|env_file|host|security|port|username|password_key|tenant_id_key|client_id_key|client_secret_key|timeout)\s*=/;
|
|
6327
|
+
SCRIPT_REL = ["skills", "send-email", "scripts", "send_email.py"];
|
|
6328
|
+
LEGACY_SCRIPT_REL = ["skills", "graph-email", "scripts", "send_email.py"];
|
|
6329
|
+
clackPrompts = {
|
|
6330
|
+
async select(o2) {
|
|
6331
|
+
const answer = await ve({ message: o2.message, options: o2.options, initialValue: o2.initialValue });
|
|
6332
|
+
return pD(answer) ? null : answer;
|
|
6333
|
+
},
|
|
6334
|
+
async text(o2) {
|
|
6335
|
+
const answer = await he({
|
|
6336
|
+
message: o2.message,
|
|
6337
|
+
placeholder: o2.placeholder,
|
|
6338
|
+
initialValue: o2.initialValue,
|
|
6339
|
+
validate: o2.validate ? (value) => o2.validate(String(value ?? "")) : void 0
|
|
6340
|
+
});
|
|
6341
|
+
return pD(answer) ? null : String(answer ?? "");
|
|
6342
|
+
},
|
|
6343
|
+
async password(o2) {
|
|
6344
|
+
const answer = await ge({
|
|
6345
|
+
message: o2.message,
|
|
6346
|
+
validate: o2.validate ? (value) => o2.validate(String(value ?? "")) : void 0
|
|
6347
|
+
});
|
|
6348
|
+
return pD(answer) ? null : String(answer ?? "");
|
|
6349
|
+
},
|
|
6350
|
+
async confirm(o2) {
|
|
6351
|
+
const answer = await ye({ message: o2.message, initialValue: o2.initialValue });
|
|
6352
|
+
return pD(answer) ? null : Boolean(answer);
|
|
6353
|
+
}
|
|
6354
|
+
};
|
|
6355
|
+
PYTHON_CANDIDATES = [
|
|
6356
|
+
{ cmd: "python", pre: [] },
|
|
6357
|
+
{ cmd: "python3", pre: [] },
|
|
6358
|
+
{ cmd: "py", pre: ["-3"] }
|
|
6359
|
+
];
|
|
6360
|
+
FALLBACK = "Run `/caddis:graph-email --check` in a Claude Code session instead.";
|
|
6361
|
+
Cancelled = class extends Error {
|
|
6362
|
+
};
|
|
6363
|
+
Invalid = class extends Error {
|
|
6364
|
+
};
|
|
6365
|
+
}
|
|
6366
|
+
});
|
|
6367
|
+
|
|
6368
|
+
// src/hub/paths.ts
|
|
6369
|
+
import path8 from "path";
|
|
5745
6370
|
function hubDir(home = caddisHome()) {
|
|
5746
|
-
return
|
|
6371
|
+
return path8.join(home, ".caddis", "hub");
|
|
5747
6372
|
}
|
|
5748
6373
|
function hubHome(home) {
|
|
5749
6374
|
const override = process.env.CADDIS_HUB_HOME;
|
|
5750
6375
|
return override ? override : hubDir(home);
|
|
5751
6376
|
}
|
|
5752
6377
|
function sessionsPath(home) {
|
|
5753
|
-
return
|
|
6378
|
+
return path8.join(hubDir(home), "sessions.json");
|
|
5754
6379
|
}
|
|
5755
6380
|
var configPath, registryPath, keyPath, lockPath, logPath, auditPath;
|
|
5756
6381
|
var init_paths = __esm({
|
|
5757
6382
|
"src/hub/paths.ts"() {
|
|
5758
6383
|
"use strict";
|
|
5759
6384
|
init_sessions();
|
|
5760
|
-
configPath = (home) =>
|
|
5761
|
-
registryPath = (home) =>
|
|
5762
|
-
keyPath = (home) =>
|
|
5763
|
-
lockPath = (home) =>
|
|
5764
|
-
logPath = (home) =>
|
|
5765
|
-
auditPath = (home) =>
|
|
6385
|
+
configPath = (home) => path8.join(hubDir(home), "config.json");
|
|
6386
|
+
registryPath = (home) => path8.join(hubDir(home), "repos.json");
|
|
6387
|
+
keyPath = (home) => path8.join(hubDir(home), "key");
|
|
6388
|
+
lockPath = (home) => path8.join(hubDir(home), "hub.lock");
|
|
6389
|
+
logPath = (home) => path8.join(hubDir(home), "hub.log");
|
|
6390
|
+
auditPath = (home) => path8.join(hubHome(home), "audit.jsonl");
|
|
5766
6391
|
}
|
|
5767
6392
|
});
|
|
5768
6393
|
|
|
5769
6394
|
// src/hub/autostart.ts
|
|
5770
|
-
import { existsSync as
|
|
5771
|
-
import
|
|
6395
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync4, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
6396
|
+
import path9 from "path";
|
|
5772
6397
|
function buildVbs(node, entry) {
|
|
5773
6398
|
const q2 = (s) => `""${s.replace(/"/g, '""""')}""`;
|
|
5774
6399
|
return `CreateObject("WScript.Shell").Run "${q2(node)} ${q2(entry)} hub serve", 0, False\r
|
|
@@ -5810,15 +6435,15 @@ NoDisplay=true
|
|
|
5810
6435
|
`;
|
|
5811
6436
|
}
|
|
5812
6437
|
function writeText(file, text2) {
|
|
5813
|
-
|
|
5814
|
-
|
|
6438
|
+
mkdirSync4(path9.dirname(file), { recursive: true });
|
|
6439
|
+
writeFileSync3(file, text2, "utf8");
|
|
5815
6440
|
}
|
|
5816
6441
|
async function enableAutostart(deps = {}) {
|
|
5817
6442
|
const home = deps.home ?? caddisHome();
|
|
5818
6443
|
const node = deps.node ?? process.execPath;
|
|
5819
6444
|
const rawEntry = deps.entry ?? process.argv[1];
|
|
5820
6445
|
if (!rawEntry) return { ok: false, message: "cannot find the caddis CLI entry script" };
|
|
5821
|
-
const entry =
|
|
6446
|
+
const entry = path9.resolve(rawEntry);
|
|
5822
6447
|
const runCmd = deps.runCmd ?? defaultRun;
|
|
5823
6448
|
const kind = kindOf(deps.platform ?? process.platform);
|
|
5824
6449
|
if (kind === "win") {
|
|
@@ -5860,14 +6485,14 @@ async function disableAutostart(deps = {}) {
|
|
|
5860
6485
|
rmSync3(vbsPath(home), { force: true });
|
|
5861
6486
|
const appData = appDataOf(deps);
|
|
5862
6487
|
const startup = appData ? startupVbsPath(appData) : null;
|
|
5863
|
-
const hadStartup = startup !== null &&
|
|
6488
|
+
const hadStartup = startup !== null && existsSync7(startup);
|
|
5864
6489
|
if (startup) rmSync3(startup, { force: true });
|
|
5865
6490
|
const removed = [r2.ok ? `logon task ${TASK_NAME}` : "", hadStartup ? "Startup folder launcher" : ""].filter(Boolean);
|
|
5866
6491
|
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)" };
|
|
5867
6492
|
}
|
|
5868
6493
|
if (kind === "mac") {
|
|
5869
6494
|
const file = plistPath(home);
|
|
5870
|
-
if (
|
|
6495
|
+
if (existsSync7(file)) await runCmd("launchctl", ["unload", "-w", file]);
|
|
5871
6496
|
rmSync3(file, { force: true });
|
|
5872
6497
|
return { ok: true, message: "caddis hub autostart disabled" };
|
|
5873
6498
|
}
|
|
@@ -5882,11 +6507,11 @@ async function autostartStatus(deps = {}) {
|
|
|
5882
6507
|
const task = (await runCmd("schtasks", schtasksQueryArgs())).ok;
|
|
5883
6508
|
const appData = appDataOf(deps);
|
|
5884
6509
|
const startup = appData ? startupVbsPath(appData) : null;
|
|
5885
|
-
const how = [task ? `logon task ${TASK_NAME}` : "", startup &&
|
|
6510
|
+
const how = [task ? `logon task ${TASK_NAME}` : "", startup && existsSync7(startup) ? `Startup folder: ${startup}` : ""];
|
|
5886
6511
|
const on = how.filter(Boolean);
|
|
5887
6512
|
return on.length ? { ok: true, message: `caddis hub autostart is enabled (${on.join("; ")})` } : { ok: false, message: "caddis hub autostart is not enabled" };
|
|
5888
6513
|
}
|
|
5889
|
-
const enabled =
|
|
6514
|
+
const enabled = existsSync7(kind === "mac" ? plistPath(home) : desktopPath(home));
|
|
5890
6515
|
return { ok: enabled, message: enabled ? "caddis hub autostart is enabled" : "caddis hub autostart is not enabled" };
|
|
5891
6516
|
}
|
|
5892
6517
|
var TASK_NAME, MAC_LABEL, CMD_TIMEOUT_MS, vbsPath, startupVbsPath, schtasksDeleteArgs, schtasksQueryArgs, xml, plistPath, desktopPath, defaultRun, appDataOf, kindOf;
|
|
@@ -5899,13 +6524,13 @@ var init_autostart = __esm({
|
|
|
5899
6524
|
TASK_NAME = "caddis-hub";
|
|
5900
6525
|
MAC_LABEL = "dev.caddis.hub";
|
|
5901
6526
|
CMD_TIMEOUT_MS = 3e4;
|
|
5902
|
-
vbsPath = (home) =>
|
|
5903
|
-
startupVbsPath = (appData) =>
|
|
6527
|
+
vbsPath = (home) => path9.join(hubDir(home), "autostart.vbs");
|
|
6528
|
+
startupVbsPath = (appData) => path9.join(appData, "Microsoft", "Windows", "Start Menu", "Programs", "Startup", `${TASK_NAME}.vbs`);
|
|
5904
6529
|
schtasksDeleteArgs = () => ["/Delete", "/TN", TASK_NAME, "/F"];
|
|
5905
6530
|
schtasksQueryArgs = () => ["/Query", "/TN", TASK_NAME];
|
|
5906
6531
|
xml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
5907
|
-
plistPath = (home) =>
|
|
5908
|
-
desktopPath = (home) =>
|
|
6532
|
+
plistPath = (home) => path9.join(home, "Library", "LaunchAgents", `${MAC_LABEL}.plist`);
|
|
6533
|
+
desktopPath = (home) => path9.join(home, ".config", "autostart", `${TASK_NAME}.desktop`);
|
|
5909
6534
|
defaultRun = async (cmd, args) => {
|
|
5910
6535
|
const r2 = await run(cmd, args, { timeout: CMD_TIMEOUT_MS });
|
|
5911
6536
|
return { ok: r2.ok, code: r2.code };
|
|
@@ -5916,8 +6541,8 @@ var init_autostart = __esm({
|
|
|
5916
6541
|
});
|
|
5917
6542
|
|
|
5918
6543
|
// src/hub/config.ts
|
|
5919
|
-
import { mkdirSync as
|
|
5920
|
-
import
|
|
6544
|
+
import { mkdirSync as mkdirSync5, readFileSync as readFileSync7, renameSync as renameSync2, unlinkSync, writeFileSync as writeFileSync4 } from "fs";
|
|
6545
|
+
import path10 from "path";
|
|
5921
6546
|
import { randomBytes } from "crypto";
|
|
5922
6547
|
function defaultConfig() {
|
|
5923
6548
|
return { schema: 1, port: DEFAULT_PORT, accounts: {}, pinned: [], hidden: [], auto_update: true };
|
|
@@ -5943,10 +6568,10 @@ function renameWithRetry(from, to) {
|
|
|
5943
6568
|
}
|
|
5944
6569
|
}
|
|
5945
6570
|
function writeJsonAtomic(file, data) {
|
|
5946
|
-
|
|
6571
|
+
mkdirSync5(path10.dirname(file), { recursive: true, mode: 448 });
|
|
5947
6572
|
const tmp = `${file}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
|
|
5948
6573
|
try {
|
|
5949
|
-
|
|
6574
|
+
writeFileSync4(tmp, JSON.stringify(data, null, 2) + "\n", { mode: 384 });
|
|
5950
6575
|
renameWithRetry(tmp, file);
|
|
5951
6576
|
} catch (e2) {
|
|
5952
6577
|
try {
|
|
@@ -5959,20 +6584,20 @@ function writeJsonAtomic(file, data) {
|
|
|
5959
6584
|
function readJson(file, normalize, fallback) {
|
|
5960
6585
|
let text2;
|
|
5961
6586
|
try {
|
|
5962
|
-
text2 =
|
|
6587
|
+
text2 = readFileSync7(file, "utf8");
|
|
5963
6588
|
} catch (e2) {
|
|
5964
6589
|
if (e2.code === "ENOENT") {
|
|
5965
6590
|
const good = lastGood.get(file);
|
|
5966
6591
|
return { value: good ?? fallback() };
|
|
5967
6592
|
}
|
|
5968
|
-
return failure(file, fallback, `cannot read ${
|
|
6593
|
+
return failure(file, fallback, `cannot read ${path10.basename(file)}: ${e2.message}`);
|
|
5969
6594
|
}
|
|
5970
6595
|
try {
|
|
5971
6596
|
const value = normalize(JSON.parse(text2));
|
|
5972
6597
|
lastGood.set(file, value);
|
|
5973
6598
|
return { value };
|
|
5974
6599
|
} catch (e2) {
|
|
5975
|
-
return failure(file, fallback, `corrupt ${
|
|
6600
|
+
return failure(file, fallback, `corrupt ${path10.basename(file)}: ${e2.message}`);
|
|
5976
6601
|
}
|
|
5977
6602
|
}
|
|
5978
6603
|
function failure(file, fallback, error) {
|
|
@@ -6010,8 +6635,8 @@ function readRegistry(home) {
|
|
|
6010
6635
|
return readJson(registryPath(home), normalizeRegistry, defaultRegistry);
|
|
6011
6636
|
}
|
|
6012
6637
|
function normalizeRepoPath(p2) {
|
|
6013
|
-
const r2 =
|
|
6014
|
-
const root =
|
|
6638
|
+
const r2 = path10.resolve(p2);
|
|
6639
|
+
const root = path10.parse(r2).root;
|
|
6015
6640
|
let out = r2;
|
|
6016
6641
|
while (out.length > root.length && /[\/]$/.test(out)) out = out.slice(0, -1);
|
|
6017
6642
|
return out;
|
|
@@ -6053,9 +6678,9 @@ var init_config = __esm({
|
|
|
6053
6678
|
});
|
|
6054
6679
|
|
|
6055
6680
|
// src/hub/keyfile.ts
|
|
6056
|
-
import { chmodSync as
|
|
6681
|
+
import { chmodSync as chmodSync3, linkSync, mkdirSync as mkdirSync6, readFileSync as readFileSync8, unlinkSync as unlinkSync2, writeFileSync as writeFileSync5 } from "fs";
|
|
6057
6682
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
6058
|
-
import
|
|
6683
|
+
import path11 from "path";
|
|
6059
6684
|
function windowsAccount(env = process.env) {
|
|
6060
6685
|
const user = env.USERNAME ?? "";
|
|
6061
6686
|
return env.USERDOMAIN ? `${env.USERDOMAIN}\\${user}` : user;
|
|
@@ -6072,18 +6697,18 @@ function removeQuiet(file) {
|
|
|
6072
6697
|
function readKey(file, platform) {
|
|
6073
6698
|
let text2;
|
|
6074
6699
|
try {
|
|
6075
|
-
text2 =
|
|
6700
|
+
text2 = readFileSync8(file, "utf8").trim();
|
|
6076
6701
|
} catch (e2) {
|
|
6077
6702
|
if (e2.code === "ENOENT") return null;
|
|
6078
6703
|
throw e2;
|
|
6079
6704
|
}
|
|
6080
6705
|
if (!KEY_RE.test(text2)) throw new Error(`the hub key file is corrupt: delete ${file} and start again`);
|
|
6081
|
-
if (platform !== "win32")
|
|
6706
|
+
if (platform !== "win32") chmodSync3(file, 384);
|
|
6082
6707
|
return text2;
|
|
6083
6708
|
}
|
|
6084
6709
|
async function ownerOnly(file, platform, deps) {
|
|
6085
6710
|
if (platform !== "win32") {
|
|
6086
|
-
|
|
6711
|
+
chmodSync3(file, 384);
|
|
6087
6712
|
return;
|
|
6088
6713
|
}
|
|
6089
6714
|
const account = deps.account ?? windowsAccount();
|
|
@@ -6096,13 +6721,13 @@ async function ensureKey(deps = {}) {
|
|
|
6096
6721
|
const file = keyPath(deps.home);
|
|
6097
6722
|
const existing = readKey(file, platform);
|
|
6098
6723
|
if (existing) return existing;
|
|
6099
|
-
|
|
6724
|
+
mkdirSync6(path11.dirname(file), { recursive: true, mode: 448 });
|
|
6100
6725
|
const key = randomBytes2(32).toString("hex");
|
|
6101
6726
|
const tmp = `${file}.${process.pid}.${randomBytes2(4).toString("hex")}.tmp`;
|
|
6102
6727
|
try {
|
|
6103
|
-
|
|
6728
|
+
writeFileSync5(tmp, "", { mode: 384, flag: "wx" });
|
|
6104
6729
|
await (deps.setAcl ?? ((f) => ownerOnly(f, platform, deps)))(tmp);
|
|
6105
|
-
|
|
6730
|
+
writeFileSync5(tmp, key, { flag: "r+" });
|
|
6106
6731
|
try {
|
|
6107
6732
|
linkSync(tmp, file);
|
|
6108
6733
|
} catch (e2) {
|
|
@@ -6127,11 +6752,11 @@ var init_keyfile = __esm({
|
|
|
6127
6752
|
});
|
|
6128
6753
|
|
|
6129
6754
|
// src/hub/lock.ts
|
|
6130
|
-
import { closeSync, mkdirSync as
|
|
6131
|
-
import
|
|
6755
|
+
import { closeSync, mkdirSync as mkdirSync7, openSync, readFileSync as readFileSync9, unlinkSync as unlinkSync3, writeSync } from "fs";
|
|
6756
|
+
import path12 from "path";
|
|
6132
6757
|
function readLock(home) {
|
|
6133
6758
|
try {
|
|
6134
|
-
const raw = JSON.parse(
|
|
6759
|
+
const raw = JSON.parse(readFileSync9(lockPath(home), "utf8"));
|
|
6135
6760
|
const pid = raw.pid;
|
|
6136
6761
|
const port = raw.port;
|
|
6137
6762
|
if (typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0) return null;
|
|
@@ -6157,7 +6782,7 @@ function removeFile(file) {
|
|
|
6157
6782
|
function acquireLock(info, home, alive = pidAlive) {
|
|
6158
6783
|
const file = lockPath(home);
|
|
6159
6784
|
const live = (h2) => h2 !== null && holderAlive(h2, home, alive);
|
|
6160
|
-
|
|
6785
|
+
mkdirSync7(path12.dirname(file), { recursive: true, mode: 448 });
|
|
6161
6786
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
6162
6787
|
let fd;
|
|
6163
6788
|
try {
|
|
@@ -6220,8 +6845,8 @@ var init_lock = __esm({
|
|
|
6220
6845
|
});
|
|
6221
6846
|
|
|
6222
6847
|
// src/hub/hubLog.ts
|
|
6223
|
-
import { appendFileSync, mkdirSync as
|
|
6224
|
-
import
|
|
6848
|
+
import { appendFileSync, mkdirSync as mkdirSync8, renameSync as renameSync3, statSync as statSync2 } from "fs";
|
|
6849
|
+
import path13 from "path";
|
|
6225
6850
|
function hubLog(text2, home, now = Date.now) {
|
|
6226
6851
|
try {
|
|
6227
6852
|
process.stderr.write(`${text2}
|
|
@@ -6230,9 +6855,9 @@ function hubLog(text2, home, now = Date.now) {
|
|
|
6230
6855
|
}
|
|
6231
6856
|
const file = logPath(home);
|
|
6232
6857
|
try {
|
|
6233
|
-
|
|
6858
|
+
mkdirSync8(path13.dirname(file), { recursive: true, mode: 448 });
|
|
6234
6859
|
try {
|
|
6235
|
-
if (
|
|
6860
|
+
if (statSync2(file).size > LOG_MAX_BYTES) renameSync3(file, `${file}.1`);
|
|
6236
6861
|
} catch {
|
|
6237
6862
|
}
|
|
6238
6863
|
appendFileSync(file, `${new Date(now()).toISOString()} ${text2.replace(/[\r\n]+/g, " ")}
|
|
@@ -6250,11 +6875,11 @@ var init_hubLog = __esm({
|
|
|
6250
6875
|
});
|
|
6251
6876
|
|
|
6252
6877
|
// src/hub/restart.ts
|
|
6253
|
-
import { readFileSync as
|
|
6254
|
-
import
|
|
6878
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
6879
|
+
import path14 from "path";
|
|
6255
6880
|
function readInstalledVersion2(packageRoot) {
|
|
6256
6881
|
try {
|
|
6257
|
-
const parsed = JSON.parse(
|
|
6882
|
+
const parsed = JSON.parse(readFileSync10(path14.join(packageRoot, "package.json"), "utf8"));
|
|
6258
6883
|
return typeof parsed.version === "string" && parsed.version ? parsed.version : null;
|
|
6259
6884
|
} catch {
|
|
6260
6885
|
return null;
|
|
@@ -6348,7 +6973,7 @@ var init_restart = __esm({
|
|
|
6348
6973
|
});
|
|
6349
6974
|
|
|
6350
6975
|
// src/hub/selfUpdate.ts
|
|
6351
|
-
import
|
|
6976
|
+
import path15 from "path";
|
|
6352
6977
|
async function fetchLatestVersion(fetchFn = fetch) {
|
|
6353
6978
|
const res = await fetchFn(REGISTRY_URL, {
|
|
6354
6979
|
headers: { accept: "application/json" },
|
|
@@ -6359,7 +6984,7 @@ async function fetchLatestVersion(fetchFn = fetch) {
|
|
|
6359
6984
|
return typeof body.version === "string" && PLAIN_VERSION.test(body.version) ? body.version : null;
|
|
6360
6985
|
}
|
|
6361
6986
|
function isGlobalInstall(packageRoot, globalRoot, platform = process.platform) {
|
|
6362
|
-
const p2 = platform === "win32" ?
|
|
6987
|
+
const p2 = platform === "win32" ? path15.win32 : path15.posix;
|
|
6363
6988
|
const norm = (dir) => {
|
|
6364
6989
|
const r2 = p2.resolve(dir).replace(/[\\/]+$/, "");
|
|
6365
6990
|
return platform === "win32" ? r2.toLowerCase() : r2;
|
|
@@ -6474,9 +7099,9 @@ var init_selfUpdate = __esm({
|
|
|
6474
7099
|
|
|
6475
7100
|
// src/hub/append.ts
|
|
6476
7101
|
import { mkdir, open } from "fs/promises";
|
|
6477
|
-
import
|
|
7102
|
+
import path16 from "path";
|
|
6478
7103
|
async function writeLine(file, line2) {
|
|
6479
|
-
await mkdir(
|
|
7104
|
+
await mkdir(path16.dirname(file), { recursive: true });
|
|
6480
7105
|
const deadline = Date.now() + RETRY_FOR_MS;
|
|
6481
7106
|
for (; ; ) {
|
|
6482
7107
|
try {
|
|
@@ -6523,15 +7148,15 @@ var init_append = __esm({
|
|
|
6523
7148
|
RETRY_CODES = /* @__PURE__ */ new Set(["EBUSY", "EPERM", "EACCES"]);
|
|
6524
7149
|
RETRY_FOR_MS = 2e3;
|
|
6525
7150
|
keyOf = (file) => {
|
|
6526
|
-
const abs =
|
|
7151
|
+
const abs = path16.resolve(file);
|
|
6527
7152
|
return process.platform === "win32" ? abs.toLowerCase() : abs;
|
|
6528
7153
|
};
|
|
6529
7154
|
}
|
|
6530
7155
|
});
|
|
6531
7156
|
|
|
6532
7157
|
// src/hub/sources/coordinator.ts
|
|
6533
|
-
import { closeSync as closeSync2, fstatSync, openSync as openSync2, readdirSync as
|
|
6534
|
-
import
|
|
7158
|
+
import { closeSync as closeSync2, fstatSync, openSync as openSync2, readdirSync as readdirSync4, readFileSync as readFileSync11, readSync } from "fs";
|
|
7159
|
+
import path17 from "path";
|
|
6535
7160
|
function stub(repoId, schema) {
|
|
6536
7161
|
return {
|
|
6537
7162
|
repo_id: repoId,
|
|
@@ -6682,20 +7307,20 @@ function createCoordinatorSource(opts = {}) {
|
|
|
6682
7307
|
const errors = /* @__PURE__ */ new Map();
|
|
6683
7308
|
return {
|
|
6684
7309
|
refresh() {
|
|
6685
|
-
const root =
|
|
7310
|
+
const root = path17.join(hubHome(opts.home), "repos");
|
|
6686
7311
|
let ids = [];
|
|
6687
7312
|
try {
|
|
6688
|
-
ids =
|
|
7313
|
+
ids = readdirSync4(root, { withFileTypes: true }).filter((d3) => d3.isDirectory()).map((d3) => d3.name);
|
|
6689
7314
|
} catch {
|
|
6690
7315
|
}
|
|
6691
7316
|
const seen = new Set(ids);
|
|
6692
7317
|
for (const id of [...lastGood2.keys()]) if (!seen.has(id)) lastGood2.delete(id);
|
|
6693
7318
|
for (const id of [...errors.keys()]) if (!seen.has(id)) errors.delete(id);
|
|
6694
7319
|
for (const id of ids) {
|
|
6695
|
-
const requests = parseRequests(readTailLines(
|
|
7320
|
+
const requests = parseRequests(readTailLines(path17.join(root, id, "requests.jsonl")));
|
|
6696
7321
|
let text2;
|
|
6697
7322
|
try {
|
|
6698
|
-
text2 =
|
|
7323
|
+
text2 = readFileSync11(path17.join(root, id, "coordinator.json"), "utf8");
|
|
6699
7324
|
} catch (e2) {
|
|
6700
7325
|
if (e2.code === "ENOENT") {
|
|
6701
7326
|
lastGood2.delete(id);
|
|
@@ -6758,7 +7383,7 @@ var init_coordinator = __esm({
|
|
|
6758
7383
|
});
|
|
6759
7384
|
|
|
6760
7385
|
// src/hub/audit.ts
|
|
6761
|
-
import { statSync as
|
|
7386
|
+
import { statSync as statSync3 } from "fs";
|
|
6762
7387
|
function parseAudit(lines) {
|
|
6763
7388
|
const out = [];
|
|
6764
7389
|
for (const line2 of lines) {
|
|
@@ -6789,7 +7414,7 @@ function readAudit(home) {
|
|
|
6789
7414
|
const file = auditPath(home);
|
|
6790
7415
|
let sig;
|
|
6791
7416
|
try {
|
|
6792
|
-
const st =
|
|
7417
|
+
const st = statSync3(file);
|
|
6793
7418
|
sig = `${st.size}:${st.mtimeMs}`;
|
|
6794
7419
|
} catch {
|
|
6795
7420
|
cache.delete(file);
|
|
@@ -6941,8 +7566,8 @@ var init_spawn = __esm({
|
|
|
6941
7566
|
});
|
|
6942
7567
|
|
|
6943
7568
|
// src/hub/sources/beats.ts
|
|
6944
|
-
import { readFileSync as
|
|
6945
|
-
import
|
|
7569
|
+
import { readFileSync as readFileSync12, readdirSync as readdirSync5 } from "fs";
|
|
7570
|
+
import path18 from "path";
|
|
6946
7571
|
function toEntry(raw, opts) {
|
|
6947
7572
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
6948
7573
|
const r2 = raw;
|
|
@@ -6983,7 +7608,7 @@ function readAgentBeats(opts) {
|
|
|
6983
7608
|
const dir = sessionsDir(opts.home);
|
|
6984
7609
|
let names;
|
|
6985
7610
|
try {
|
|
6986
|
-
names =
|
|
7611
|
+
names = readdirSync5(dir).sort();
|
|
6987
7612
|
} catch {
|
|
6988
7613
|
return [];
|
|
6989
7614
|
}
|
|
@@ -6993,7 +7618,7 @@ function readAgentBeats(opts) {
|
|
|
6993
7618
|
if (!name.endsWith(".json") || name.startsWith(".")) continue;
|
|
6994
7619
|
let entry = null;
|
|
6995
7620
|
try {
|
|
6996
|
-
entry = toEntry(JSON.parse(
|
|
7621
|
+
entry = toEntry(JSON.parse(readFileSync12(path18.join(dir, name), "utf8")), opts);
|
|
6997
7622
|
} catch {
|
|
6998
7623
|
continue;
|
|
6999
7624
|
}
|
|
@@ -7018,8 +7643,8 @@ var init_beats = __esm({
|
|
|
7018
7643
|
});
|
|
7019
7644
|
|
|
7020
7645
|
// src/hub/sources/agents.ts
|
|
7021
|
-
import { existsSync as
|
|
7022
|
-
import
|
|
7646
|
+
import { existsSync as existsSync8, readFileSync as readFileSync13, statSync as statSync4 } from "fs";
|
|
7647
|
+
import path19 from "path";
|
|
7023
7648
|
function classifyWaiting(waitingFor) {
|
|
7024
7649
|
const w2 = (waitingFor ?? "").toLowerCase();
|
|
7025
7650
|
if (w2 === "permission prompt" || w2 === "input needed" || w2.includes("question")) return "owner";
|
|
@@ -7027,33 +7652,33 @@ function classifyWaiting(waitingFor) {
|
|
|
7027
7652
|
}
|
|
7028
7653
|
function repoPathFor(cwd) {
|
|
7029
7654
|
if (!cwd) return null;
|
|
7030
|
-
let dir =
|
|
7655
|
+
let dir = path19.resolve(cwd);
|
|
7031
7656
|
for (; ; ) {
|
|
7032
|
-
const dotGit =
|
|
7033
|
-
if (
|
|
7657
|
+
const dotGit = path19.join(dir, ".git");
|
|
7658
|
+
if (existsSync8(dotGit)) {
|
|
7034
7659
|
if (isDir(dotGit)) return normalizeRepoPath(dir);
|
|
7035
7660
|
if (isFile(dotGit)) return commonRoot(dir, dotGit);
|
|
7036
7661
|
return null;
|
|
7037
7662
|
}
|
|
7038
|
-
const parent =
|
|
7663
|
+
const parent = path19.dirname(dir);
|
|
7039
7664
|
if (parent === dir) return null;
|
|
7040
7665
|
dir = parent;
|
|
7041
7666
|
}
|
|
7042
7667
|
}
|
|
7043
7668
|
function commonRoot(dir, dotGitFile) {
|
|
7044
7669
|
try {
|
|
7045
|
-
const m2 = /^gitdir:\s*(.+?)\s*$/m.exec(
|
|
7670
|
+
const m2 = /^gitdir:\s*(.+?)\s*$/m.exec(readFileSync13(dotGitFile, "utf8"));
|
|
7046
7671
|
if (!m2) return null;
|
|
7047
|
-
const gitdir =
|
|
7672
|
+
const gitdir = path19.resolve(dir, m2[1] ?? "");
|
|
7048
7673
|
let common;
|
|
7049
7674
|
try {
|
|
7050
|
-
const rel =
|
|
7675
|
+
const rel = readFileSync13(path19.join(gitdir, "commondir"), "utf8").trim();
|
|
7051
7676
|
if (!rel) return normalizeRepoPath(dir);
|
|
7052
|
-
common =
|
|
7677
|
+
common = path19.resolve(gitdir, rel);
|
|
7053
7678
|
} catch {
|
|
7054
7679
|
return normalizeRepoPath(dir);
|
|
7055
7680
|
}
|
|
7056
|
-
return normalizeRepoPath(
|
|
7681
|
+
return normalizeRepoPath(path19.dirname(common));
|
|
7057
7682
|
} catch {
|
|
7058
7683
|
return null;
|
|
7059
7684
|
}
|
|
@@ -7183,14 +7808,14 @@ var init_agents = __esm({
|
|
|
7183
7808
|
FIND_TIMEOUT_MS = 1e4;
|
|
7184
7809
|
isFile = (p2) => {
|
|
7185
7810
|
try {
|
|
7186
|
-
return
|
|
7811
|
+
return statSync4(p2).isFile();
|
|
7187
7812
|
} catch {
|
|
7188
7813
|
return false;
|
|
7189
7814
|
}
|
|
7190
7815
|
};
|
|
7191
7816
|
isDir = (p2) => {
|
|
7192
7817
|
try {
|
|
7193
|
-
return
|
|
7818
|
+
return statSync4(p2).isDirectory();
|
|
7194
7819
|
} catch {
|
|
7195
7820
|
return false;
|
|
7196
7821
|
}
|
|
@@ -7200,20 +7825,20 @@ var init_agents = __esm({
|
|
|
7200
7825
|
});
|
|
7201
7826
|
|
|
7202
7827
|
// src/hub/sources/collector.ts
|
|
7203
|
-
import { existsSync as
|
|
7204
|
-
import
|
|
7205
|
-
import
|
|
7828
|
+
import { existsSync as existsSync9, mkdirSync as mkdirSync9, writeFileSync as writeFileSync6 } from "fs";
|
|
7829
|
+
import os6 from "os";
|
|
7830
|
+
import path20 from "path";
|
|
7206
7831
|
function defaultScriptPath() {
|
|
7207
7832
|
const name = "caddis_hub_collect.py";
|
|
7208
7833
|
const bundle = bundlePath("antigravity-plugin", { requireManifest: false });
|
|
7209
7834
|
if (bundle) {
|
|
7210
|
-
const shipped =
|
|
7211
|
-
if (
|
|
7835
|
+
const shipped = path20.join(bundle, "scripts", name);
|
|
7836
|
+
if (existsSync9(shipped)) return shipped;
|
|
7212
7837
|
}
|
|
7213
|
-
const root =
|
|
7214
|
-
const repoScript =
|
|
7215
|
-
const mirrorScript =
|
|
7216
|
-
return !
|
|
7838
|
+
const root = path20.join(packageInfo().root, "..");
|
|
7839
|
+
const repoScript = path20.join(root, "scripts", name);
|
|
7840
|
+
const mirrorScript = path20.join(root, "bundles", "antigravity-plugin", "scripts", name);
|
|
7841
|
+
return !existsSync9(repoScript) && existsSync9(mirrorScript) ? mirrorScript : repoScript;
|
|
7217
7842
|
}
|
|
7218
7843
|
async function resolvePython() {
|
|
7219
7844
|
const py = await find("python");
|
|
@@ -7314,8 +7939,8 @@ function createCollectorSource(opts) {
|
|
|
7314
7939
|
let prsFlag = [];
|
|
7315
7940
|
if (opts.prs && opts.prsFile && repos.length > 0 && !prsFileUnsupported) {
|
|
7316
7941
|
try {
|
|
7317
|
-
|
|
7318
|
-
|
|
7942
|
+
mkdirSync9(path20.dirname(opts.prsFile), { recursive: true });
|
|
7943
|
+
writeFileSync6(opts.prsFile, JSON.stringify({ schema: 1, repos: opts.prs() }));
|
|
7319
7944
|
prsFlag = ["--prs-file", opts.prsFile];
|
|
7320
7945
|
} catch {
|
|
7321
7946
|
}
|
|
@@ -7329,7 +7954,7 @@ function createCollectorSource(opts) {
|
|
|
7329
7954
|
...doneKnown.length ? ["--done-known", ...doneKnown] : [],
|
|
7330
7955
|
...prsFlag,
|
|
7331
7956
|
"--json"
|
|
7332
|
-
] : [...pre, script, "--repos",
|
|
7957
|
+
] : [...pre, script, "--repos", path20.join(os6.tmpdir(), "caddis-hub-no-repos"), "--only", "spend,guide", "--json"];
|
|
7333
7958
|
let result = await spawn2(cmd, build(), { timeoutMs: RUN_TIMEOUT_MS2 });
|
|
7334
7959
|
for (let attempt = 0; attempt < 3 && !result.ok; attempt += 1) {
|
|
7335
7960
|
if (prsFlag.length && /unrecognized arguments:.*--prs-file/.test(result.stderr)) {
|
|
@@ -7401,8 +8026,8 @@ var init_collector = __esm({
|
|
|
7401
8026
|
});
|
|
7402
8027
|
|
|
7403
8028
|
// src/hub/sources/github.ts
|
|
7404
|
-
import { readFileSync as
|
|
7405
|
-
import
|
|
8029
|
+
import { readFileSync as readFileSync14 } from "fs";
|
|
8030
|
+
import path21 from "path";
|
|
7406
8031
|
function parseGithubRemote(url) {
|
|
7407
8032
|
const m2 = /^(?:https?:\/\/(?:[^@/]+@)?|ssh:\/\/git@|git@)github\.com[/:]([^/\s]+)\/([^/\s]+?)(?:\.git)?\/?$/i.exec(url.trim());
|
|
7408
8033
|
return m2 ? `${m2[1]}/${m2[2]}` : null;
|
|
@@ -7412,7 +8037,7 @@ function readOriginUrl(repoDir) {
|
|
|
7412
8037
|
if (!root) return null;
|
|
7413
8038
|
let text2;
|
|
7414
8039
|
try {
|
|
7415
|
-
text2 =
|
|
8040
|
+
text2 = readFileSync14(path21.join(root, ".git", "config"), "utf8");
|
|
7416
8041
|
} catch {
|
|
7417
8042
|
return null;
|
|
7418
8043
|
}
|
|
@@ -7430,7 +8055,7 @@ function readOriginUrl(repoDir) {
|
|
|
7430
8055
|
}
|
|
7431
8056
|
function readRequiredChecks(repoDir) {
|
|
7432
8057
|
try {
|
|
7433
|
-
const text2 =
|
|
8058
|
+
const text2 = readFileSync14(path21.join(repoDir, ".caddis", "coordinator.md"), "utf8");
|
|
7434
8059
|
const m2 = /```json[^\S\r\n]*\r?\n([\s\S]*?)\r?\n[^\S\r\n]*```/.exec(text2);
|
|
7435
8060
|
if (!m2) return null;
|
|
7436
8061
|
const parsed = JSON.parse(m2[1] ?? "");
|
|
@@ -7798,20 +8423,20 @@ var init_github = __esm({
|
|
|
7798
8423
|
|
|
7799
8424
|
// src/hub/state.ts
|
|
7800
8425
|
import { createHash } from "crypto";
|
|
7801
|
-
import { readFileSync as
|
|
7802
|
-
import
|
|
8426
|
+
import { readFileSync as readFileSync15 } from "fs";
|
|
8427
|
+
import path22 from "path";
|
|
7803
8428
|
function repoIdFor(nameWithOwner) {
|
|
7804
8429
|
return nameWithOwner.trim().toLowerCase().replace(/\//g, "__");
|
|
7805
8430
|
}
|
|
7806
8431
|
function localRepoId(repoPath) {
|
|
7807
8432
|
const norm = process.platform === "win32" ? repoPath.toLowerCase().replace(/\//g, "\\") : repoPath;
|
|
7808
8433
|
const digest = createHash("sha256").update(norm, "utf8").digest("hex").slice(0, 6);
|
|
7809
|
-
return `local__${
|
|
8434
|
+
return `local__${path22.basename(repoPath)}__${digest}`;
|
|
7810
8435
|
}
|
|
7811
8436
|
function readPluginVersion(home) {
|
|
7812
8437
|
try {
|
|
7813
|
-
const file =
|
|
7814
|
-
const parsed = JSON.parse(
|
|
8438
|
+
const file = path22.join(home, ".claude", "plugins", "installed_plugins.json");
|
|
8439
|
+
const parsed = JSON.parse(readFileSync15(file, "utf8"));
|
|
7815
8440
|
for (const [key, entries] of Object.entries(parsed.plugins ?? {})) {
|
|
7816
8441
|
if (!key.startsWith("caddis@") || !Array.isArray(entries)) continue;
|
|
7817
8442
|
for (const e2 of entries) {
|
|
@@ -7917,7 +8542,7 @@ function createHub(opts = {}) {
|
|
|
7917
8542
|
repos: repoPaths,
|
|
7918
8543
|
now,
|
|
7919
8544
|
prs: () => prHeads(github.get().data),
|
|
7920
|
-
prsFile:
|
|
8545
|
+
prsFile: path22.join(hubDir(home), "collector-prs.json")
|
|
7921
8546
|
});
|
|
7922
8547
|
const agents = opts.agents ?? createAgentsSource({ now, home });
|
|
7923
8548
|
const coordinator = opts.coordinator ?? createCoordinatorSource({ home, now });
|
|
@@ -8010,7 +8635,7 @@ function createHub(opts = {}) {
|
|
|
8010
8635
|
const relays = c?.relays ?? null;
|
|
8011
8636
|
const out = {
|
|
8012
8637
|
path: p2,
|
|
8013
|
-
name:
|
|
8638
|
+
name: path22.basename(p2),
|
|
8014
8639
|
pinned: pinned.has(k3),
|
|
8015
8640
|
roadmaps: c?.roadmaps ?? null,
|
|
8016
8641
|
plans: c?.plans ?? null,
|
|
@@ -8122,7 +8747,7 @@ var init_state = __esm({
|
|
|
8122
8747
|
|
|
8123
8748
|
// src/hub/actions.ts
|
|
8124
8749
|
import { randomUUID } from "crypto";
|
|
8125
|
-
import
|
|
8750
|
+
import path23 from "path";
|
|
8126
8751
|
function parseBody(raw) {
|
|
8127
8752
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new Refusal(400, "bad_request", "The body must be a JSON object.");
|
|
8128
8753
|
const o2 = raw;
|
|
@@ -8230,7 +8855,7 @@ function createActions(opts) {
|
|
|
8230
8855
|
args: body.what === null ? {} : { what: body.what }
|
|
8231
8856
|
};
|
|
8232
8857
|
try {
|
|
8233
|
-
await appendLine(
|
|
8858
|
+
await appendLine(path23.join(root(), "repos", body.repo_id, "requests.jsonl"), JSON.stringify(request));
|
|
8234
8859
|
} catch {
|
|
8235
8860
|
return refuse(new Refusal(500, "write_failed", "The hub could not write the request."), body);
|
|
8236
8861
|
}
|
|
@@ -8278,8 +8903,8 @@ var init_actions = __esm({
|
|
|
8278
8903
|
|
|
8279
8904
|
// src/hub/auth.ts
|
|
8280
8905
|
import { createHash as createHash2, randomBytes as randomBytes3, timingSafeEqual } from "crypto";
|
|
8281
|
-
import { mkdirSync as
|
|
8282
|
-
import
|
|
8906
|
+
import { mkdirSync as mkdirSync10, readFileSync as readFileSync16, renameSync as renameSync4, writeFileSync as writeFileSync7 } from "fs";
|
|
8907
|
+
import path24 from "path";
|
|
8283
8908
|
function randomToken() {
|
|
8284
8909
|
return randomBytes3(32).toString("base64url");
|
|
8285
8910
|
}
|
|
@@ -8333,7 +8958,7 @@ var init_auth = __esm({
|
|
|
8333
8958
|
if (!this.file) return [];
|
|
8334
8959
|
let raw;
|
|
8335
8960
|
try {
|
|
8336
|
-
raw = JSON.parse(
|
|
8961
|
+
raw = JSON.parse(readFileSync16(this.file, "utf8"));
|
|
8337
8962
|
} catch {
|
|
8338
8963
|
return [];
|
|
8339
8964
|
}
|
|
@@ -8376,8 +9001,8 @@ var init_auth = __esm({
|
|
|
8376
9001
|
};
|
|
8377
9002
|
const tmp = `${this.file}.${process.pid}.tmp`;
|
|
8378
9003
|
try {
|
|
8379
|
-
|
|
8380
|
-
|
|
9004
|
+
mkdirSync10(path24.dirname(this.file), { recursive: true });
|
|
9005
|
+
writeFileSync7(tmp, JSON.stringify(body), { mode: 384 });
|
|
8381
9006
|
renameSync4(tmp, this.file);
|
|
8382
9007
|
for (const s of this.sessions) s.savedSeenAt = s.lastSeenAt;
|
|
8383
9008
|
} catch {
|
|
@@ -8533,16 +9158,16 @@ var init_phaseText = __esm({
|
|
|
8533
9158
|
|
|
8534
9159
|
// src/hub/server.ts
|
|
8535
9160
|
import http from "http";
|
|
8536
|
-
import { existsSync as
|
|
9161
|
+
import { existsSync as existsSync10 } from "fs";
|
|
8537
9162
|
import { readFile, stat } from "fs/promises";
|
|
8538
|
-
import
|
|
9163
|
+
import path25 from "path";
|
|
8539
9164
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
8540
9165
|
import { promisify } from "util";
|
|
8541
9166
|
import { gzip } from "zlib";
|
|
8542
9167
|
function defaultUiDir() {
|
|
8543
|
-
const here =
|
|
8544
|
-
const beside =
|
|
8545
|
-
return
|
|
9168
|
+
const here = path25.dirname(fileURLToPath2(import.meta.url));
|
|
9169
|
+
const beside = path25.join(here, "ui");
|
|
9170
|
+
return existsSync10(beside) ? beside : path25.resolve(here, "..", "..", "dist", "ui");
|
|
8546
9171
|
}
|
|
8547
9172
|
function resolveStatic(root, urlPath) {
|
|
8548
9173
|
let decoded;
|
|
@@ -8553,9 +9178,9 @@ function resolveStatic(root, urlPath) {
|
|
|
8553
9178
|
}
|
|
8554
9179
|
if (decoded.includes(String.fromCharCode(0)) || decoded.includes(String.fromCharCode(92))) return null;
|
|
8555
9180
|
if (decoded.split("/").includes("..")) return null;
|
|
8556
|
-
const base =
|
|
8557
|
-
const file =
|
|
8558
|
-
return file.startsWith(base +
|
|
9181
|
+
const base = path25.resolve(root);
|
|
9182
|
+
const file = path25.resolve(base, "." + decoded);
|
|
9183
|
+
return file.startsWith(base + path25.sep) ? file : null;
|
|
8559
9184
|
}
|
|
8560
9185
|
function send(res, status5, body, extra = {}) {
|
|
8561
9186
|
const text2 = JSON.stringify(body);
|
|
@@ -8647,7 +9272,7 @@ async function serveStatic(res, uiDir, urlPath) {
|
|
|
8647
9272
|
return fail(res, 404, "not_found");
|
|
8648
9273
|
}
|
|
8649
9274
|
res.writeHead(200, {
|
|
8650
|
-
"Content-Type": MIME[
|
|
9275
|
+
"Content-Type": MIME[path25.extname(file).toLowerCase()] ?? "application/octet-stream",
|
|
8651
9276
|
"Content-Length": body.length,
|
|
8652
9277
|
"Cache-Control": urlPath === "/" ? "no-store" : "public, max-age=31536000, immutable"
|
|
8653
9278
|
});
|
|
@@ -8683,23 +9308,23 @@ async function startServer(opts) {
|
|
|
8683
9308
|
fail(res, 400, "bad_url");
|
|
8684
9309
|
return;
|
|
8685
9310
|
}
|
|
8686
|
-
const
|
|
9311
|
+
const path29 = url.pathname;
|
|
8687
9312
|
const method = req.method ?? "GET";
|
|
8688
|
-
if (
|
|
9313
|
+
if (path29.startsWith("/api/") || path29 === "/login") res.setHeader("Cache-Control", "no-store");
|
|
8689
9314
|
if (!hostAllowed(req.headers.host, port)) {
|
|
8690
|
-
if (
|
|
9315
|
+
if (path29 === "/login") auth.discardCode(url.searchParams.get("code") ?? "");
|
|
8691
9316
|
fail(res, 403, "bad_host");
|
|
8692
9317
|
return;
|
|
8693
9318
|
}
|
|
8694
|
-
if (
|
|
9319
|
+
if (path29 === "/api/hub/whoami" && method === "GET") {
|
|
8695
9320
|
if (!opts.instance) return fail(res, 404, "not_found");
|
|
8696
9321
|
return send(res, 200, { instance: opts.instance });
|
|
8697
9322
|
}
|
|
8698
|
-
if (
|
|
9323
|
+
if (path29 === "/api/health" && method === "GET") {
|
|
8699
9324
|
if (!keyOk(req, key)) return fail(res, 401, "unauthorized");
|
|
8700
9325
|
return send(res, 200, { schema: 1, ok: true, versions });
|
|
8701
9326
|
}
|
|
8702
|
-
if (
|
|
9327
|
+
if (path29 === "/api/hub/code" && method === "POST") {
|
|
8703
9328
|
if (!keyOk(req, key)) return fail(res, 401, "unauthorized");
|
|
8704
9329
|
try {
|
|
8705
9330
|
await readBody(req);
|
|
@@ -8710,7 +9335,7 @@ async function startServer(opts) {
|
|
|
8710
9335
|
const code = auth.mintCode();
|
|
8711
9336
|
return send(res, 200, { schema: 1, code, expires_at: auth.codeExpiresAt() });
|
|
8712
9337
|
}
|
|
8713
|
-
if (
|
|
9338
|
+
if (path29 === "/api/hub/stop" && method === "POST") {
|
|
8714
9339
|
if (!keyOk(req, key)) return fail(res, 401, "unauthorized");
|
|
8715
9340
|
try {
|
|
8716
9341
|
await readBody(req);
|
|
@@ -8728,7 +9353,7 @@ async function startServer(opts) {
|
|
|
8728
9353
|
if (!session) return fail(res, 401, "unauthorized");
|
|
8729
9354
|
const token = req.headers[CSRF_HEADER];
|
|
8730
9355
|
if (typeof token !== "string" || !safeEqual(token, session.csrf)) return fail(res, 403, "bad_csrf");
|
|
8731
|
-
if (
|
|
9356
|
+
if (path29 === "/api/actions" && method === "POST" && opts.actions) {
|
|
8732
9357
|
if (!tabSessionOf(req)) return fail(res, 401, "unauthorized");
|
|
8733
9358
|
const type = String(req.headers["content-type"] ?? "").split(";")[0]?.trim().toLowerCase();
|
|
8734
9359
|
if (type !== "application/json") return fail(res, 415, "json_only");
|
|
@@ -8754,7 +9379,7 @@ async function startServer(opts) {
|
|
|
8754
9379
|
if (e2 instanceof BodyTooLarge) return tooLarge(req, res);
|
|
8755
9380
|
throw e2;
|
|
8756
9381
|
}
|
|
8757
|
-
if (
|
|
9382
|
+
if (path29 === "/api/logout" && method === "POST") {
|
|
8758
9383
|
auth.deleteSession(parseCookies(req.headers.cookie)[SESSION_COOKIE] ?? "");
|
|
8759
9384
|
return send(res, 200, { schema: 1, ok: true }, {
|
|
8760
9385
|
"Set-Cookie": `${SESSION_COOKIE}=; HttpOnly; SameSite=Strict; Path=/; Max-Age=0`
|
|
@@ -8762,11 +9387,11 @@ async function startServer(opts) {
|
|
|
8762
9387
|
}
|
|
8763
9388
|
return fail(res, 404, "not_found");
|
|
8764
9389
|
}
|
|
8765
|
-
if (
|
|
8766
|
-
await serveStatic(res, uiDir,
|
|
9390
|
+
if (path29 === "/" || path29.startsWith("/assets/") || path29.startsWith("/fonts/")) {
|
|
9391
|
+
await serveStatic(res, uiDir, path29);
|
|
8767
9392
|
return;
|
|
8768
9393
|
}
|
|
8769
|
-
if (
|
|
9394
|
+
if (path29 === "/login") {
|
|
8770
9395
|
const id = auth.redeemCode(url.searchParams.get("code") ?? "");
|
|
8771
9396
|
const session = id ? auth.getSession(id) : null;
|
|
8772
9397
|
if (!id || !session) return fail(res, 401, "bad_code");
|
|
@@ -8778,12 +9403,12 @@ async function startServer(opts) {
|
|
|
8778
9403
|
res.end();
|
|
8779
9404
|
return;
|
|
8780
9405
|
}
|
|
8781
|
-
if (
|
|
9406
|
+
if (path29 === "/api/session") {
|
|
8782
9407
|
const session = tabSessionOf(req);
|
|
8783
9408
|
if (!session) return fail(res, 401, "unauthorized");
|
|
8784
9409
|
return send(res, 200, { schema: 1, csrf_token: session.csrf, versions });
|
|
8785
9410
|
}
|
|
8786
|
-
if (
|
|
9411
|
+
if (path29 === "/api/state") {
|
|
8787
9412
|
if (!tabSessionOf(req)) return fail(res, 401, "unauthorized");
|
|
8788
9413
|
let state;
|
|
8789
9414
|
try {
|
|
@@ -8793,7 +9418,7 @@ async function startServer(opts) {
|
|
|
8793
9418
|
}
|
|
8794
9419
|
return sendState(req, res, stripPhaseText(state));
|
|
8795
9420
|
}
|
|
8796
|
-
if (
|
|
9421
|
+
if (path29 === "/api/plan-phase") {
|
|
8797
9422
|
if (!tabSessionOf(req)) return fail(res, 401, "unauthorized");
|
|
8798
9423
|
const repo = url.searchParams.get("repo") ?? "";
|
|
8799
9424
|
const plan2 = url.searchParams.get("plan") ?? "";
|
|
@@ -8890,8 +9515,8 @@ __export(hub_exports, {
|
|
|
8890
9515
|
startHub: () => startHub
|
|
8891
9516
|
});
|
|
8892
9517
|
import http2 from "http";
|
|
8893
|
-
import
|
|
8894
|
-
import { mkdirSync as
|
|
9518
|
+
import path26 from "path";
|
|
9519
|
+
import { mkdirSync as mkdirSync11, readFileSync as readFileSync17 } from "fs";
|
|
8895
9520
|
import { randomBytes as randomBytes4 } from "crypto";
|
|
8896
9521
|
function defaultVersions2() {
|
|
8897
9522
|
return { cli: packageInfo().version, caddis: bundleManifest().poolVersion };
|
|
@@ -8908,7 +9533,7 @@ function resolvePort(deps) {
|
|
|
8908
9533
|
}
|
|
8909
9534
|
function readKeyQuiet(home) {
|
|
8910
9535
|
try {
|
|
8911
|
-
const k3 =
|
|
9536
|
+
const k3 = readFileSync17(keyPath(home), "utf8").trim();
|
|
8912
9537
|
return /^[0-9a-f]{64}$/.test(k3) ? k3 : null;
|
|
8913
9538
|
} catch {
|
|
8914
9539
|
return null;
|
|
@@ -8976,7 +9601,7 @@ async function isNodeProcess(pid) {
|
|
|
8976
9601
|
if (!r2.ok) return false;
|
|
8977
9602
|
const name = (r2.stdout.split(/\r?\n/)[0] ?? "").replace(/^"([^"]*)".*$/, "$1").trim().toLowerCase();
|
|
8978
9603
|
if (!name) return false;
|
|
8979
|
-
const runtime =
|
|
9604
|
+
const runtime = path26.basename(process.execPath).toLowerCase().replace(/\.exe$/, "");
|
|
8980
9605
|
return name.includes("node") || name.includes(runtime);
|
|
8981
9606
|
}
|
|
8982
9607
|
async function defaultOpener(url) {
|
|
@@ -9119,7 +9744,7 @@ async function hubServe(deps = {}) {
|
|
|
9119
9744
|
process.once("exit", onExit);
|
|
9120
9745
|
line(`caddis hub serving on ${hubUrl(hub2.port)} (pid ${process.pid}); stop it with: caddis hub stop`);
|
|
9121
9746
|
const pkgRoot = packageInfo().root;
|
|
9122
|
-
const newEntry =
|
|
9747
|
+
const newEntry = path26.join(pkgRoot, "dist", "cli.js");
|
|
9123
9748
|
const runningVersion = (deps.versions ?? defaultVersions2()).cli ?? packageInfo().version;
|
|
9124
9749
|
const log = (text2) => hubLog(text2, home, deps.now);
|
|
9125
9750
|
let installing = () => false;
|
|
@@ -9220,7 +9845,7 @@ async function hubStart(deps = {}) {
|
|
|
9220
9845
|
return 1;
|
|
9221
9846
|
}
|
|
9222
9847
|
const cwd = hubDir(home);
|
|
9223
|
-
|
|
9848
|
+
mkdirSync11(cwd, { recursive: true });
|
|
9224
9849
|
const child = await (deps.spawn ?? defaultSpawn)(process.execPath, [entry, "hub", "serve"], { cwd });
|
|
9225
9850
|
let exited = false;
|
|
9226
9851
|
let exitCode = null;
|
|
@@ -9608,8 +10233,8 @@ var init_data = __esm({
|
|
|
9608
10233
|
});
|
|
9609
10234
|
|
|
9610
10235
|
// src/hub/export/privacy.ts
|
|
9611
|
-
import { lstatSync, readdirSync as
|
|
9612
|
-
import
|
|
10236
|
+
import { lstatSync, readdirSync as readdirSync6, readFileSync as readFileSync18 } from "fs";
|
|
10237
|
+
import path27 from "path";
|
|
9613
10238
|
function parseAllowedUrls(text2) {
|
|
9614
10239
|
const exact = /* @__PURE__ */ new Set();
|
|
9615
10240
|
const templates = [];
|
|
@@ -9622,13 +10247,13 @@ function parseAllowedUrls(text2) {
|
|
|
9622
10247
|
return { exact, templates };
|
|
9623
10248
|
}
|
|
9624
10249
|
function defaultAllowedUrls() {
|
|
9625
|
-
return
|
|
10250
|
+
return readFileSync18(new URL("./allowed-urls.txt", import.meta.url), "utf8");
|
|
9626
10251
|
}
|
|
9627
10252
|
function walk(dir, base = "") {
|
|
9628
10253
|
const out = [];
|
|
9629
|
-
for (const name of
|
|
10254
|
+
for (const name of readdirSync6(dir).sort()) {
|
|
9630
10255
|
const rel = base ? `${base}/${name}` : name;
|
|
9631
|
-
const full =
|
|
10256
|
+
const full = path27.join(dir, name);
|
|
9632
10257
|
if (lstatSync(full).isDirectory()) out.push(...walk(full, rel));
|
|
9633
10258
|
else out.push(rel);
|
|
9634
10259
|
}
|
|
@@ -9673,13 +10298,13 @@ function isPrivateText(text2, deny) {
|
|
|
9673
10298
|
function scanExport(dir, opts) {
|
|
9674
10299
|
const hits = [];
|
|
9675
10300
|
for (const file of walk(dir)) {
|
|
9676
|
-
const full =
|
|
10301
|
+
const full = path27.join(dir, ...file.split("/"));
|
|
9677
10302
|
if (lstatSync(full).isSymbolicLink()) {
|
|
9678
10303
|
hits.push({ file, offset: 0, rule: "symbolic-link" });
|
|
9679
10304
|
continue;
|
|
9680
10305
|
}
|
|
9681
|
-
const buf =
|
|
9682
|
-
const binary = BINARY_EXT.has(
|
|
10306
|
+
const buf = readFileSync18(full);
|
|
10307
|
+
const binary = BINARY_EXT.has(path27.extname(file).toLowerCase());
|
|
9683
10308
|
const text2 = binary ? null : buf.toString("utf8");
|
|
9684
10309
|
scanDeny(file, buf, text2, opts.deny, hits);
|
|
9685
10310
|
if (text2 === null) continue;
|
|
@@ -9758,17 +10383,17 @@ __export(export_exports, {
|
|
|
9758
10383
|
import { createHash as createHash3 } from "crypto";
|
|
9759
10384
|
import {
|
|
9760
10385
|
copyFileSync,
|
|
9761
|
-
existsSync as
|
|
10386
|
+
existsSync as existsSync11,
|
|
9762
10387
|
lstatSync as lstatSync2,
|
|
9763
|
-
mkdirSync as
|
|
9764
|
-
readdirSync as
|
|
9765
|
-
readFileSync as
|
|
10388
|
+
mkdirSync as mkdirSync12,
|
|
10389
|
+
readdirSync as readdirSync7,
|
|
10390
|
+
readFileSync as readFileSync19,
|
|
9766
10391
|
rmSync as rmSync4,
|
|
9767
|
-
statSync as
|
|
9768
|
-
writeFileSync as
|
|
10392
|
+
statSync as statSync5,
|
|
10393
|
+
writeFileSync as writeFileSync8
|
|
9769
10394
|
} from "fs";
|
|
9770
|
-
import
|
|
9771
|
-
import
|
|
10395
|
+
import os7 from "os";
|
|
10396
|
+
import path28 from "path";
|
|
9772
10397
|
function prsForCollector(gh, repo) {
|
|
9773
10398
|
if (!Array.isArray(gh)) return null;
|
|
9774
10399
|
const heads = [];
|
|
@@ -9787,8 +10412,8 @@ function prsForCollector(gh, repo) {
|
|
|
9787
10412
|
return { schema: 1, repos: { [repo]: heads } };
|
|
9788
10413
|
}
|
|
9789
10414
|
function holdsLink(dir) {
|
|
9790
|
-
for (const name of
|
|
9791
|
-
const full =
|
|
10415
|
+
for (const name of readdirSync7(dir)) {
|
|
10416
|
+
const full = path28.join(dir, name);
|
|
9792
10417
|
const st = lstatSync2(full);
|
|
9793
10418
|
if (st.isSymbolicLink()) return true;
|
|
9794
10419
|
if (st.isDirectory() && holdsLink(full)) return true;
|
|
@@ -9806,8 +10431,8 @@ function checkOut(out, repo) {
|
|
|
9806
10431
|
}
|
|
9807
10432
|
if (st.isSymbolicLink()) return "--out is a link";
|
|
9808
10433
|
if (!st.isDirectory()) return "--out is a file";
|
|
9809
|
-
if (
|
|
9810
|
-
if (!
|
|
10434
|
+
if (readdirSync7(out).length === 0) return null;
|
|
10435
|
+
if (!existsSync11(path28.join(out, MARKER)) || lstatSync2(path28.join(out, MARKER)).isSymbolicLink()) {
|
|
9811
10436
|
return `--out is not empty and has no ${MARKER} marker: this command did not make it`;
|
|
9812
10437
|
}
|
|
9813
10438
|
if (holdsLink(out)) return "--out holds a link";
|
|
@@ -9833,43 +10458,43 @@ function notFoundPage() {
|
|
|
9833
10458
|
`;
|
|
9834
10459
|
}
|
|
9835
10460
|
function copyFixedSet(dist, dest) {
|
|
9836
|
-
|
|
9837
|
-
|
|
9838
|
-
|
|
9839
|
-
copyFileSync(
|
|
9840
|
-
for (const name of
|
|
9841
|
-
const from =
|
|
9842
|
-
if (lstatSync2(from).isFile()) copyFileSync(from,
|
|
9843
|
-
}
|
|
9844
|
-
const fonts =
|
|
10461
|
+
mkdirSync12(path28.join(dest, "assets"), { recursive: true });
|
|
10462
|
+
mkdirSync12(path28.join(dest, "fonts"), { recursive: true });
|
|
10463
|
+
mkdirSync12(path28.join(dest, "licenses"), { recursive: true });
|
|
10464
|
+
copyFileSync(path28.join(dist, "index.html"), path28.join(dest, "index.html"));
|
|
10465
|
+
for (const name of readdirSync7(path28.join(dist, "assets"))) {
|
|
10466
|
+
const from = path28.join(dist, "assets", name);
|
|
10467
|
+
if (lstatSync2(from).isFile()) copyFileSync(from, path28.join(dest, "assets", name));
|
|
10468
|
+
}
|
|
10469
|
+
const fonts = path28.join(dist, "fonts");
|
|
9845
10470
|
if (isDir2(fonts)) {
|
|
9846
|
-
for (const name of
|
|
9847
|
-
const from =
|
|
10471
|
+
for (const name of readdirSync7(fonts)) {
|
|
10472
|
+
const from = path28.join(fonts, name);
|
|
9848
10473
|
if (!lstatSync2(from).isFile()) continue;
|
|
9849
|
-
if (name.endsWith(".woff2")) copyFileSync(from,
|
|
10474
|
+
if (name.endsWith(".woff2")) copyFileSync(from, path28.join(dest, "fonts", name));
|
|
9850
10475
|
}
|
|
9851
10476
|
}
|
|
9852
|
-
const licenses =
|
|
10477
|
+
const licenses = path28.join(dist, "licenses");
|
|
9853
10478
|
if (isDir2(licenses)) {
|
|
9854
|
-
for (const name of
|
|
9855
|
-
const from =
|
|
9856
|
-
if (lstatSync2(from).isFile() && /^(OFL-[A-Za-z]+|LICENSE-Lucide)\.txt$/.test(name)) copyFileSync(from,
|
|
10479
|
+
for (const name of readdirSync7(licenses)) {
|
|
10480
|
+
const from = path28.join(licenses, name);
|
|
10481
|
+
if (lstatSync2(from).isFile() && /^(OFL-[A-Za-z]+|LICENSE-Lucide)\.txt$/.test(name)) copyFileSync(from, path28.join(dest, "licenses", name));
|
|
9857
10482
|
}
|
|
9858
10483
|
}
|
|
9859
10484
|
}
|
|
9860
10485
|
function countFiles(dir) {
|
|
9861
|
-
return
|
|
9862
|
-
const full =
|
|
10486
|
+
return readdirSync7(dir).reduce((n, name) => {
|
|
10487
|
+
const full = path28.join(dir, name);
|
|
9863
10488
|
return n + (lstatSync2(full).isDirectory() ? countFiles(full) : name === MARKER ? 0 : 1);
|
|
9864
10489
|
}, 0);
|
|
9865
10490
|
}
|
|
9866
10491
|
function machineOf(over, repo) {
|
|
9867
10492
|
let user = "";
|
|
9868
10493
|
try {
|
|
9869
|
-
user =
|
|
10494
|
+
user = os7.userInfo().username;
|
|
9870
10495
|
} catch {
|
|
9871
10496
|
}
|
|
9872
|
-
return { repoPath: repo, home:
|
|
10497
|
+
return { repoPath: repo, home: os7.homedir(), user, host: os7.hostname(), ...over };
|
|
9873
10498
|
}
|
|
9874
10499
|
async function hubExport(args, deps = {}) {
|
|
9875
10500
|
const out = deps.stdout ?? ((l2) => console.log(l2));
|
|
@@ -9881,7 +10506,7 @@ async function hubExport(args, deps = {}) {
|
|
|
9881
10506
|
return 2;
|
|
9882
10507
|
}
|
|
9883
10508
|
if (args.check !== void 0) {
|
|
9884
|
-
const dir =
|
|
10509
|
+
const dir = path28.resolve(args.check);
|
|
9885
10510
|
if (!isDir2(dir)) {
|
|
9886
10511
|
err(`error: --check folder not found: ${args.check}`);
|
|
9887
10512
|
return 1;
|
|
@@ -9905,9 +10530,9 @@ async function hubExport(args, deps = {}) {
|
|
|
9905
10530
|
err("error: --commit must be 7 to 40 hex characters");
|
|
9906
10531
|
return 2;
|
|
9907
10532
|
}
|
|
9908
|
-
const repo =
|
|
9909
|
-
const outDir =
|
|
9910
|
-
if (!
|
|
10533
|
+
const repo = path28.resolve(args.repo);
|
|
10534
|
+
const outDir = path28.resolve(args.out);
|
|
10535
|
+
if (!existsSync11(path28.join(repo, ".git")) || !(isDir2(path28.join(repo, ".caddis", "roadmaps")) || isDir2(path28.join(repo, ".caddis", "plans")))) {
|
|
9911
10536
|
err("error: --repo must be a git checkout with .caddis/roadmaps/ or .caddis/plans/");
|
|
9912
10537
|
return 2;
|
|
9913
10538
|
}
|
|
@@ -9916,8 +10541,8 @@ async function hubExport(args, deps = {}) {
|
|
|
9916
10541
|
err(`error: ${refused}`);
|
|
9917
10542
|
return 2;
|
|
9918
10543
|
}
|
|
9919
|
-
const dist = deps.distDir ??
|
|
9920
|
-
if (!
|
|
10544
|
+
const dist = deps.distDir ?? path28.join(packageInfo().root, "dist", "export");
|
|
10545
|
+
if (!existsSync11(path28.join(dist, "index.html")) || !isDir2(path28.join(dist, "assets"))) {
|
|
9921
10546
|
err(`error: the export app is not built (${dist}). Run: npm run build:ui`);
|
|
9922
10547
|
return 1;
|
|
9923
10548
|
}
|
|
@@ -9967,7 +10592,7 @@ async function hubExport(args, deps = {}) {
|
|
|
9967
10592
|
if (args.prs !== void 0) {
|
|
9968
10593
|
let gh = null;
|
|
9969
10594
|
try {
|
|
9970
|
-
gh = JSON.parse(
|
|
10595
|
+
gh = JSON.parse(readFileSync19(path28.resolve(args.prs), "utf8"));
|
|
9971
10596
|
} catch {
|
|
9972
10597
|
gh = null;
|
|
9973
10598
|
}
|
|
@@ -9977,8 +10602,8 @@ async function hubExport(args, deps = {}) {
|
|
|
9977
10602
|
} else {
|
|
9978
10603
|
prsFile = `${outDir}.prs-${process.pid}.json`;
|
|
9979
10604
|
try {
|
|
9980
|
-
|
|
9981
|
-
|
|
10605
|
+
mkdirSync12(path28.dirname(prsFile), { recursive: true });
|
|
10606
|
+
writeFileSync8(prsFile, JSON.stringify(body));
|
|
9982
10607
|
} catch (error) {
|
|
9983
10608
|
rmSync4(prsFile, { force: true });
|
|
9984
10609
|
err(`error: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -10012,12 +10637,12 @@ async function hubExport(args, deps = {}) {
|
|
|
10012
10637
|
const build = (page) => {
|
|
10013
10638
|
rmSync4(staging, { recursive: true, force: true });
|
|
10014
10639
|
copyFixedSet(dist, staging);
|
|
10015
|
-
const indexPath =
|
|
10016
|
-
const html =
|
|
10640
|
+
const indexPath = path28.join(staging, "index.html");
|
|
10641
|
+
const html = readFileSync19(indexPath, "utf8");
|
|
10017
10642
|
if (!html.includes(PLACEHOLDER)) throw new Error("the built index.html has no data placeholder");
|
|
10018
10643
|
const block = `<script type="application/json" id="caddis-export-data">${escapeJson(JSON.stringify(page))}</script>`;
|
|
10019
|
-
|
|
10020
|
-
|
|
10644
|
+
writeFileSync8(indexPath, html.replace(PLACEHOLDER, () => block));
|
|
10645
|
+
writeFileSync8(path28.join(staging, "404.html"), notFoundPage());
|
|
10021
10646
|
};
|
|
10022
10647
|
try {
|
|
10023
10648
|
build(data);
|
|
@@ -10043,10 +10668,10 @@ async function hubExport(args, deps = {}) {
|
|
|
10043
10668
|
rmSync4(staging, { recursive: true, force: true });
|
|
10044
10669
|
return 3;
|
|
10045
10670
|
}
|
|
10046
|
-
|
|
10047
|
-
if (
|
|
10671
|
+
mkdirSync12(path28.dirname(outDir), { recursive: true });
|
|
10672
|
+
if (existsSync11(outDir)) rmSync4(outDir, { recursive: true, force: true });
|
|
10048
10673
|
renameWithRetry(staging, outDir);
|
|
10049
|
-
|
|
10674
|
+
writeFileSync8(path28.join(outDir, MARKER), "written by caddis hub export\n");
|
|
10050
10675
|
out(`[EXPORT] ${countFiles(outDir)} file(s) in ${outDir}`);
|
|
10051
10676
|
return 0;
|
|
10052
10677
|
} catch (error) {
|
|
@@ -10076,18 +10701,18 @@ var init_export = __esm({
|
|
|
10076
10701
|
FIXED_FILES = ["index.html", "404.html"];
|
|
10077
10702
|
isDir2 = (p2) => {
|
|
10078
10703
|
try {
|
|
10079
|
-
return
|
|
10704
|
+
return statSync5(p2).isDirectory();
|
|
10080
10705
|
} catch {
|
|
10081
10706
|
return false;
|
|
10082
10707
|
}
|
|
10083
10708
|
};
|
|
10084
10709
|
samePath = (a, b3) => {
|
|
10085
|
-
const norm = (p2) =>
|
|
10710
|
+
const norm = (p2) => path28.resolve(p2).replace(/[\\/]+$/, "").toLowerCase();
|
|
10086
10711
|
return norm(a) === norm(b3);
|
|
10087
10712
|
};
|
|
10088
10713
|
isInside = (child, parent) => {
|
|
10089
|
-
const rel =
|
|
10090
|
-
return rel !== "" && !rel.startsWith("..") && !
|
|
10714
|
+
const rel = path28.relative(path28.resolve(parent), path28.resolve(child));
|
|
10715
|
+
return rel !== "" && !rel.startsWith("..") && !path28.isAbsolute(rel);
|
|
10091
10716
|
};
|
|
10092
10717
|
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]));";
|
|
10093
10718
|
}
|
|
@@ -10148,14 +10773,14 @@ function* pluginBlocks(stdout) {
|
|
|
10148
10773
|
if (current) yield current;
|
|
10149
10774
|
}
|
|
10150
10775
|
async function detect() {
|
|
10151
|
-
const
|
|
10152
|
-
if (!
|
|
10776
|
+
const path29 = await findBin(BIN);
|
|
10777
|
+
if (!path29) {
|
|
10153
10778
|
return { present: false, note: "no `claude` binary on PATH" };
|
|
10154
10779
|
}
|
|
10155
10780
|
const version = await run(BIN, ["--version"], { timeout: 2e4 });
|
|
10156
10781
|
return {
|
|
10157
10782
|
present: true,
|
|
10158
|
-
path:
|
|
10783
|
+
path: path29,
|
|
10159
10784
|
agentVersion: version.ok ? version.stdout.trim().split(/\s+/)[0] || void 0 : void 0,
|
|
10160
10785
|
note: version.ok ? void 0 : "binary found but `claude --version` failed"
|
|
10161
10786
|
};
|
|
@@ -10980,6 +11605,41 @@ withGlobalFlags(program2.command("status")).description("compact table: cli vers
|
|
|
10980
11605
|
const { status: status5 } = await Promise.resolve().then(() => (init_status(), status_exports));
|
|
10981
11606
|
finish(await status5({ adapters: resolveAdapters(flags), json: options.json }));
|
|
10982
11607
|
});
|
|
11608
|
+
var email = program2.command("email").description("one-time setup and check for the send-email skill (Microsoft Graph or SMTP)");
|
|
11609
|
+
withGlobalFlags(email.command("setup")).description("guided setup: ask a few questions, write ~/.caddis/email.toml (and email.env), then check it").option("--provider <name>", "graph (default) or smtp").option("--sender <address>", "the mailbox mail is sent from").option("--env-file <path>", "an existing env file that holds the secrets (key names are checked, values never shown)").option("--tenant-id <guid>", "graph: the Entra tenant ID").option("--client-id <guid>", "graph: the app (client) ID").option("--smtp-host <host>", "smtp: the server host").option("--smtp-security <mode>", "smtp: starttls, ssl or none").option("--smtp-port <port>", "smtp: the port (default by security)").option("--smtp-username <name>", "smtp: the login name (empty if no login)").option("-f, --force", "replace an existing email.toml / email.env without asking", false).option("--no-check", "do not run the check after writing").addHelpText(
|
|
11610
|
+
"after",
|
|
11611
|
+
`
|
|
11612
|
+
The secret is never a flag, so it never lands in shell history. A script sets it in the environment:
|
|
11613
|
+
CADDIS_EMAIL_CLIENT_SECRET graph client secret
|
|
11614
|
+
CADDIS_EMAIL_SMTP_PASSWORD smtp password
|
|
11615
|
+
or points --env-file at a file that holds it. With --yes nothing is asked: a missing value is an error.`
|
|
11616
|
+
).action(
|
|
11617
|
+
async (options) => {
|
|
11618
|
+
const flags = mergeFlags(options);
|
|
11619
|
+
const { emailSetup: emailSetup2 } = await Promise.resolve().then(() => (init_email(), email_exports));
|
|
11620
|
+
finish(
|
|
11621
|
+
await emailSetup2({
|
|
11622
|
+
provider: options.provider,
|
|
11623
|
+
sender: options.sender,
|
|
11624
|
+
envFile: options.envFile,
|
|
11625
|
+
tenantId: options.tenantId,
|
|
11626
|
+
clientId: options.clientId,
|
|
11627
|
+
smtpHost: options.smtpHost,
|
|
11628
|
+
smtpSecurity: options.smtpSecurity,
|
|
11629
|
+
smtpPort: options.smtpPort,
|
|
11630
|
+
smtpUsername: options.smtpUsername,
|
|
11631
|
+
yes: flags.yes,
|
|
11632
|
+
force: options.force === true,
|
|
11633
|
+
dryRun: flags.dryRun,
|
|
11634
|
+
noCheck: options.check === false
|
|
11635
|
+
})
|
|
11636
|
+
);
|
|
11637
|
+
}
|
|
11638
|
+
);
|
|
11639
|
+
email.command("check").description("check the email setup: runs the skill script with --check (sends nothing, prints no secret)").action(async () => {
|
|
11640
|
+
const { emailCheck: emailCheck2 } = await Promise.resolve().then(() => (init_email(), email_exports));
|
|
11641
|
+
finish(await emailCheck2());
|
|
11642
|
+
});
|
|
10983
11643
|
var hub = program2.command("hub").description("the local caddis hub web server (127.0.0.1 only)");
|
|
10984
11644
|
hub.command("start").description("start the hub in the background (hidden)").action(async () => {
|
|
10985
11645
|
const { hubStart: hubStart2 } = await Promise.resolve().then(() => (init_hub(), hub_exports));
|