@caddis/cli 0.4.79 → 0.4.83
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/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_roadmap_page.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_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_coordinate.py +128 -7
- package/bundles/antigravity-plugin/scripts/caddis_gate.py +3 -3
- package/bundles/antigravity-plugin/scripts/caddis_hub_collect.py +8 -0
- package/bundles/antigravity-plugin/scripts/caddis_roadmap.py +29 -3
- package/bundles/antigravity-plugin/scripts/caddis_roadmap_page.py +4 -3
- package/bundles/antigravity-plugin/scripts/caddis_workstreams.py +24 -0
- package/bundles/antigravity-plugin/scripts/schemas/coordinator.schema.json +28 -1
- package/bundles/antigravity-plugin/scripts/schemas/hub-collect.schema.json +127 -0
- package/bundles/antigravity-plugin/scripts/schemas/hub-relays.schema.json +36 -0
- package/bundles/antigravity-plugin/scripts/schemas/hub-roadmaps.schema.json +91 -0
- package/bundles/antigravity-plugin/skills/coordinate/SKILL.md +17 -1
- package/bundles/antigravity-plugin/skills/cross-review/SKILL.md +1 -1
- package/bundles/antigravity-plugin/skills/feature-plan/SKILL.md +18 -9
- package/bundles/antigravity-plugin/skills/handoff/SKILL.md +5 -0
- package/bundles/antigravity-plugin/skills/implement/SKILL.md +23 -8
- package/bundles/antigravity-plugin/skills/mmr/SKILL.md +1 -1
- package/bundles/antigravity-plugin/skills/pr-merge/SKILL.md +2 -2
- package/bundles/antigravity-plugin/skills/ship/SKILL.md +1 -1
- package/bundles/antigravity-plugin/skills/ship-merge/SKILL.md +1 -1
- package/bundles/antigravity-plugin/skills/ship-pr/SKILL.md +2 -2
- package/bundles/antigravity-plugin-extras/plugin.json +1 -1
- package/bundles/antigravity-plugin-extras/skills/cross-review/SKILL.md +1 -1
- package/bundles/manifest.json +3 -3
- package/dist/allowed-urls.txt +19 -0
- package/dist/cli.js +1811 -784
- package/dist/export/assets/export-C0_skoDL.css +1 -0
- package/dist/export/assets/export-DErZHj4B.js +150 -0
- package/dist/export/assets/mark-small-CwCIyjyC.svg +8 -0
- package/dist/export/assets/wordmark-CD0s2ofS.svg +99 -0
- package/dist/export/fonts/LICENSE-Lucide.txt +43 -0
- package/dist/export/fonts/OFL-Atkinson.txt +93 -0
- package/dist/export/fonts/OFL-MapleMono.txt +93 -0
- package/dist/export/fonts/atkinson-400.849ae6f0.woff2 +0 -0
- package/dist/export/fonts/atkinson-700.3a9cc18a.woff2 +0 -0
- package/dist/export/fonts/maple-mono-400.071799fd.woff2 +0 -0
- package/dist/export/fonts/maple-mono-700.1e17b237.woff2 +0 -0
- package/dist/export/index.html +16 -0
- package/dist/ui/assets/Activity-CaqQ_HdD.js +6 -0
- package/dist/ui/assets/{Guide-D6PTiZmH.js → Guide-9PV1m0e9.js} +1 -1
- package/dist/ui/assets/RoadmapTab-CDm42wB2.js +31 -0
- package/dist/ui/assets/{index-DWiypj6N.css → index-Cv4RVfyi.css} +1 -1
- package/dist/ui/assets/index-Dotj3WfG.js +221 -0
- package/dist/ui/assets/time-D00tu2ZP.js +1 -0
- package/dist/ui/fonts/LICENSE-Lucide.txt +43 -0
- package/dist/ui/index.html +2 -2
- package/package.json +2 -2
- package/dist/ui/assets/index-D7fsc0PF.js +0 -221
package/dist/cli.js
CHANGED
|
@@ -639,8 +639,8 @@ var require_help = __commonJS({
|
|
|
639
639
|
* @param {string} str
|
|
640
640
|
* @returns {number}
|
|
641
641
|
*/
|
|
642
|
-
displayWidth(
|
|
643
|
-
return stripColor(
|
|
642
|
+
displayWidth(str5) {
|
|
643
|
+
return stripColor(str5).length;
|
|
644
644
|
}
|
|
645
645
|
/**
|
|
646
646
|
* Style the title for displaying in the help. Called with 'Usage:', 'Options:', etc.
|
|
@@ -648,11 +648,11 @@ var require_help = __commonJS({
|
|
|
648
648
|
* @param {string} str
|
|
649
649
|
* @returns {string}
|
|
650
650
|
*/
|
|
651
|
-
styleTitle(
|
|
652
|
-
return
|
|
651
|
+
styleTitle(str5) {
|
|
652
|
+
return str5;
|
|
653
653
|
}
|
|
654
|
-
styleUsage(
|
|
655
|
-
return
|
|
654
|
+
styleUsage(str5) {
|
|
655
|
+
return str5.split(" ").map((word) => {
|
|
656
656
|
if (word === "[options]") return this.styleOptionText(word);
|
|
657
657
|
if (word === "[command]") return this.styleSubcommandText(word);
|
|
658
658
|
if (word[0] === "[" || word[0] === "<")
|
|
@@ -660,46 +660,46 @@ var require_help = __commonJS({
|
|
|
660
660
|
return this.styleCommandText(word);
|
|
661
661
|
}).join(" ");
|
|
662
662
|
}
|
|
663
|
-
styleCommandDescription(
|
|
664
|
-
return this.styleDescriptionText(
|
|
663
|
+
styleCommandDescription(str5) {
|
|
664
|
+
return this.styleDescriptionText(str5);
|
|
665
665
|
}
|
|
666
|
-
styleOptionDescription(
|
|
667
|
-
return this.styleDescriptionText(
|
|
666
|
+
styleOptionDescription(str5) {
|
|
667
|
+
return this.styleDescriptionText(str5);
|
|
668
668
|
}
|
|
669
|
-
styleSubcommandDescription(
|
|
670
|
-
return this.styleDescriptionText(
|
|
669
|
+
styleSubcommandDescription(str5) {
|
|
670
|
+
return this.styleDescriptionText(str5);
|
|
671
671
|
}
|
|
672
|
-
styleArgumentDescription(
|
|
673
|
-
return this.styleDescriptionText(
|
|
672
|
+
styleArgumentDescription(str5) {
|
|
673
|
+
return this.styleDescriptionText(str5);
|
|
674
674
|
}
|
|
675
|
-
styleDescriptionText(
|
|
676
|
-
return
|
|
675
|
+
styleDescriptionText(str5) {
|
|
676
|
+
return str5;
|
|
677
677
|
}
|
|
678
|
-
styleOptionTerm(
|
|
679
|
-
return this.styleOptionText(
|
|
678
|
+
styleOptionTerm(str5) {
|
|
679
|
+
return this.styleOptionText(str5);
|
|
680
680
|
}
|
|
681
|
-
styleSubcommandTerm(
|
|
682
|
-
return
|
|
681
|
+
styleSubcommandTerm(str5) {
|
|
682
|
+
return str5.split(" ").map((word) => {
|
|
683
683
|
if (word === "[options]") return this.styleOptionText(word);
|
|
684
684
|
if (word[0] === "[" || word[0] === "<")
|
|
685
685
|
return this.styleArgumentText(word);
|
|
686
686
|
return this.styleSubcommandText(word);
|
|
687
687
|
}).join(" ");
|
|
688
688
|
}
|
|
689
|
-
styleArgumentTerm(
|
|
690
|
-
return this.styleArgumentText(
|
|
689
|
+
styleArgumentTerm(str5) {
|
|
690
|
+
return this.styleArgumentText(str5);
|
|
691
691
|
}
|
|
692
|
-
styleOptionText(
|
|
693
|
-
return
|
|
692
|
+
styleOptionText(str5) {
|
|
693
|
+
return str5;
|
|
694
694
|
}
|
|
695
|
-
styleArgumentText(
|
|
696
|
-
return
|
|
695
|
+
styleArgumentText(str5) {
|
|
696
|
+
return str5;
|
|
697
697
|
}
|
|
698
|
-
styleSubcommandText(
|
|
699
|
-
return
|
|
698
|
+
styleSubcommandText(str5) {
|
|
699
|
+
return str5;
|
|
700
700
|
}
|
|
701
|
-
styleCommandText(
|
|
702
|
-
return
|
|
701
|
+
styleCommandText(str5) {
|
|
702
|
+
return str5;
|
|
703
703
|
}
|
|
704
704
|
/**
|
|
705
705
|
* Calculate the pad width from the maximum term length.
|
|
@@ -722,8 +722,8 @@ var require_help = __commonJS({
|
|
|
722
722
|
* @param {string} str
|
|
723
723
|
* @returns {boolean}
|
|
724
724
|
*/
|
|
725
|
-
preformatted(
|
|
726
|
-
return /\n[^\S\r\n]/.test(
|
|
725
|
+
preformatted(str5) {
|
|
726
|
+
return /\n[^\S\r\n]/.test(str5);
|
|
727
727
|
}
|
|
728
728
|
/**
|
|
729
729
|
* Format the "item", which consists of a term and description. Pad the term and wrap the description, indenting the following lines.
|
|
@@ -769,9 +769,9 @@ ${itemIndentStr}`);
|
|
|
769
769
|
* @param {number} width
|
|
770
770
|
* @returns {string}
|
|
771
771
|
*/
|
|
772
|
-
boxWrap(
|
|
773
|
-
if (width < this.minWidthToWrap) return
|
|
774
|
-
const rawLines =
|
|
772
|
+
boxWrap(str5, width) {
|
|
773
|
+
if (width < this.minWidthToWrap) return str5;
|
|
774
|
+
const rawLines = str5.split(/\r\n|\n/);
|
|
775
775
|
const chunkPattern = /[\s]*[^\s]+/g;
|
|
776
776
|
const wrappedLines = [];
|
|
777
777
|
rawLines.forEach((line2) => {
|
|
@@ -799,9 +799,9 @@ ${itemIndentStr}`);
|
|
|
799
799
|
return wrappedLines.join("\n");
|
|
800
800
|
}
|
|
801
801
|
};
|
|
802
|
-
function stripColor(
|
|
802
|
+
function stripColor(str5) {
|
|
803
803
|
const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
|
|
804
|
-
return
|
|
804
|
+
return str5.replace(sgrPattern, "");
|
|
805
805
|
}
|
|
806
806
|
exports.Help = Help2;
|
|
807
807
|
exports.stripColor = stripColor;
|
|
@@ -1073,9 +1073,9 @@ var require_option = __commonJS({
|
|
|
1073
1073
|
return option.negate === (negativeValue === value);
|
|
1074
1074
|
}
|
|
1075
1075
|
};
|
|
1076
|
-
function camelcase(
|
|
1077
|
-
return
|
|
1078
|
-
return
|
|
1076
|
+
function camelcase(str5) {
|
|
1077
|
+
return str5.split("-").reduce((str6, word) => {
|
|
1078
|
+
return str6 + word[0].toUpperCase() + word.slice(1);
|
|
1079
1079
|
});
|
|
1080
1080
|
}
|
|
1081
1081
|
function splitOptionFlags(flags) {
|
|
@@ -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 path24 = __require("path");
|
|
1213
1213
|
var fs = __require("fs");
|
|
1214
1214
|
var process3 = __require("process");
|
|
1215
1215
|
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
@@ -1258,14 +1258,14 @@ var require_command = __commonJS({
|
|
|
1258
1258
|
this._showSuggestionAfterError = true;
|
|
1259
1259
|
this._savedState = null;
|
|
1260
1260
|
this._outputConfiguration = {
|
|
1261
|
-
writeOut: (
|
|
1262
|
-
writeErr: (
|
|
1263
|
-
outputError: (
|
|
1261
|
+
writeOut: (str5) => process3.stdout.write(str5),
|
|
1262
|
+
writeErr: (str5) => process3.stderr.write(str5),
|
|
1263
|
+
outputError: (str5, write) => write(str5),
|
|
1264
1264
|
getOutHelpWidth: () => process3.stdout.isTTY ? process3.stdout.columns : void 0,
|
|
1265
1265
|
getErrHelpWidth: () => process3.stderr.isTTY ? process3.stderr.columns : void 0,
|
|
1266
1266
|
getOutHasColors: () => useColor() ?? (process3.stdout.isTTY && process3.stdout.hasColors?.()),
|
|
1267
1267
|
getErrHasColors: () => useColor() ?? (process3.stderr.isTTY && process3.stderr.hasColors?.()),
|
|
1268
|
-
stripColor: (
|
|
1268
|
+
stripColor: (str5) => stripColor(str5)
|
|
1269
1269
|
};
|
|
1270
1270
|
this._hidden = false;
|
|
1271
1271
|
this._helpOption = void 0;
|
|
@@ -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 = path24.resolve(baseDir, baseName);
|
|
2226
2226
|
if (fs.existsSync(localBin)) return localBin;
|
|
2227
|
-
if (sourceExt.includes(
|
|
2227
|
+
if (sourceExt.includes(path24.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 = path24.resolve(
|
|
2246
|
+
path24.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 = path24.basename(
|
|
2254
2254
|
this._scriptPath,
|
|
2255
|
-
|
|
2255
|
+
path24.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(path24.extname(executableFile));
|
|
2267
2267
|
let proc;
|
|
2268
2268
|
if (process3.platform !== "win32") {
|
|
2269
2269
|
if (launchWithNode) {
|
|
@@ -2989,18 +2989,18 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2989
2989
|
* @param {string} [description]
|
|
2990
2990
|
* @return {(this | string | undefined)} `this` command for chaining, or version string if no arguments
|
|
2991
2991
|
*/
|
|
2992
|
-
version(
|
|
2993
|
-
if (
|
|
2994
|
-
this._version =
|
|
2992
|
+
version(str5, flags, description) {
|
|
2993
|
+
if (str5 === void 0) return this._version;
|
|
2994
|
+
this._version = str5;
|
|
2995
2995
|
flags = flags || "-V, --version";
|
|
2996
2996
|
description = description || "output the version number";
|
|
2997
2997
|
const versionOption = this.createOption(flags, description);
|
|
2998
2998
|
this._versionOptionName = versionOption.attributeName();
|
|
2999
2999
|
this._registerOption(versionOption);
|
|
3000
3000
|
this.on("option:" + versionOption.name(), () => {
|
|
3001
|
-
this._outputConfiguration.writeOut(`${
|
|
3001
|
+
this._outputConfiguration.writeOut(`${str5}
|
|
3002
3002
|
`);
|
|
3003
|
-
this._exit(0, "commander.version",
|
|
3003
|
+
this._exit(0, "commander.version", str5);
|
|
3004
3004
|
});
|
|
3005
3005
|
return this;
|
|
3006
3006
|
}
|
|
@@ -3011,10 +3011,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3011
3011
|
* @param {object} [argsDescription]
|
|
3012
3012
|
* @return {(string|Command)}
|
|
3013
3013
|
*/
|
|
3014
|
-
description(
|
|
3015
|
-
if (
|
|
3014
|
+
description(str5, argsDescription) {
|
|
3015
|
+
if (str5 === void 0 && argsDescription === void 0)
|
|
3016
3016
|
return this._description;
|
|
3017
|
-
this._description =
|
|
3017
|
+
this._description = str5;
|
|
3018
3018
|
if (argsDescription) {
|
|
3019
3019
|
this._argsDescription = argsDescription;
|
|
3020
3020
|
}
|
|
@@ -3026,9 +3026,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3026
3026
|
* @param {string} [str]
|
|
3027
3027
|
* @return {(string|Command)}
|
|
3028
3028
|
*/
|
|
3029
|
-
summary(
|
|
3030
|
-
if (
|
|
3031
|
-
this._summary =
|
|
3029
|
+
summary(str5) {
|
|
3030
|
+
if (str5 === void 0) return this._summary;
|
|
3031
|
+
this._summary = str5;
|
|
3032
3032
|
return this;
|
|
3033
3033
|
}
|
|
3034
3034
|
/**
|
|
@@ -3076,8 +3076,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3076
3076
|
* @param {string} [str]
|
|
3077
3077
|
* @return {(string|Command)}
|
|
3078
3078
|
*/
|
|
3079
|
-
usage(
|
|
3080
|
-
if (
|
|
3079
|
+
usage(str5) {
|
|
3080
|
+
if (str5 === void 0) {
|
|
3081
3081
|
if (this._usage) return this._usage;
|
|
3082
3082
|
const args = this.registeredArguments.map((arg) => {
|
|
3083
3083
|
return humanReadableArgName(arg);
|
|
@@ -3088,7 +3088,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3088
3088
|
this.registeredArguments.length ? args : []
|
|
3089
3089
|
).join(" ");
|
|
3090
3090
|
}
|
|
3091
|
-
this._usage =
|
|
3091
|
+
this._usage = str5;
|
|
3092
3092
|
return this;
|
|
3093
3093
|
}
|
|
3094
3094
|
/**
|
|
@@ -3097,9 +3097,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3097
3097
|
* @param {string} [str]
|
|
3098
3098
|
* @return {(string|Command)}
|
|
3099
3099
|
*/
|
|
3100
|
-
name(
|
|
3101
|
-
if (
|
|
3102
|
-
this._name =
|
|
3100
|
+
name(str5) {
|
|
3101
|
+
if (str5 === void 0) return this._name;
|
|
3102
|
+
this._name = str5;
|
|
3103
3103
|
return this;
|
|
3104
3104
|
}
|
|
3105
3105
|
/**
|
|
@@ -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 = path24.basename(filename, path24.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(path25) {
|
|
3196
|
+
if (path25 === void 0) return this._executableDir;
|
|
3197
|
+
this._executableDir = path25;
|
|
3198
3198
|
return this;
|
|
3199
3199
|
}
|
|
3200
3200
|
/**
|
|
@@ -3211,9 +3211,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3211
3211
|
helpWidth: context.helpWidth,
|
|
3212
3212
|
outputHasColors: context.hasColors
|
|
3213
3213
|
});
|
|
3214
|
-
const
|
|
3215
|
-
if (context.hasColors) return
|
|
3216
|
-
return this._outputConfiguration.stripColor(
|
|
3214
|
+
const text2 = helper.formatHelp(this, helper);
|
|
3215
|
+
if (context.hasColors) return text2;
|
|
3216
|
+
return this._outputConfiguration.stripColor(text2);
|
|
3217
3217
|
}
|
|
3218
3218
|
/**
|
|
3219
3219
|
* @typedef HelpContext
|
|
@@ -3233,17 +3233,17 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3233
3233
|
let hasColors;
|
|
3234
3234
|
let helpWidth;
|
|
3235
3235
|
if (error) {
|
|
3236
|
-
baseWrite = (
|
|
3236
|
+
baseWrite = (str5) => this._outputConfiguration.writeErr(str5);
|
|
3237
3237
|
hasColors = this._outputConfiguration.getErrHasColors();
|
|
3238
3238
|
helpWidth = this._outputConfiguration.getErrHelpWidth();
|
|
3239
3239
|
} else {
|
|
3240
|
-
baseWrite = (
|
|
3240
|
+
baseWrite = (str5) => this._outputConfiguration.writeOut(str5);
|
|
3241
3241
|
hasColors = this._outputConfiguration.getOutHasColors();
|
|
3242
3242
|
helpWidth = this._outputConfiguration.getOutHelpWidth();
|
|
3243
3243
|
}
|
|
3244
|
-
const write = (
|
|
3245
|
-
if (!hasColors)
|
|
3246
|
-
return baseWrite(
|
|
3244
|
+
const write = (str5) => {
|
|
3245
|
+
if (!hasColors) str5 = this._outputConfiguration.stripColor(str5);
|
|
3246
|
+
return baseWrite(str5);
|
|
3247
3247
|
};
|
|
3248
3248
|
return { error, write, hasColors, helpWidth };
|
|
3249
3249
|
}
|
|
@@ -3373,7 +3373,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3373
3373
|
* @param {(string | Function)} text - string to add, or a function returning a string
|
|
3374
3374
|
* @return {Command} `this` command for chaining
|
|
3375
3375
|
*/
|
|
3376
|
-
addHelpText(position,
|
|
3376
|
+
addHelpText(position, text2) {
|
|
3377
3377
|
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
3378
3378
|
if (!allowedValues.includes(position)) {
|
|
3379
3379
|
throw new Error(`Unexpected value for position to addHelpText.
|
|
@@ -3382,10 +3382,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3382
3382
|
const helpEvent = `${position}Help`;
|
|
3383
3383
|
this.on(helpEvent, (context) => {
|
|
3384
3384
|
let helpStr;
|
|
3385
|
-
if (typeof
|
|
3386
|
-
helpStr =
|
|
3385
|
+
if (typeof text2 === "function") {
|
|
3386
|
+
helpStr = text2({ error: context.error, command: context.command });
|
|
3387
3387
|
} else {
|
|
3388
|
-
helpStr =
|
|
3388
|
+
helpStr = text2;
|
|
3389
3389
|
}
|
|
3390
3390
|
if (helpStr) {
|
|
3391
3391
|
context.write(`${helpStr}
|
|
@@ -3826,9 +3826,9 @@ var require_picocolors = __commonJS({
|
|
|
3826
3826
|
var argv = p2.argv || [];
|
|
3827
3827
|
var env = p2.env || {};
|
|
3828
3828
|
var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p2.platform === "win32" || (p2.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
3829
|
-
var formatter = (
|
|
3830
|
-
let string = "" + input, index = string.indexOf(close,
|
|
3831
|
-
return ~index ?
|
|
3829
|
+
var formatter = (open2, close, replace = open2) => (input) => {
|
|
3830
|
+
let string = "" + input, index = string.indexOf(close, open2.length);
|
|
3831
|
+
return ~index ? open2 + replaceClose(string, close, replace, index) + close : open2 + string + close;
|
|
3832
3832
|
};
|
|
3833
3833
|
var replaceClose = (string, close, replace, index) => {
|
|
3834
3834
|
let result = "", cursor = 0;
|
|
@@ -3897,7 +3897,7 @@ function hex(hexStr) {
|
|
|
3897
3897
|
const r2 = parseInt(clean.substring(0, 2), 16);
|
|
3898
3898
|
const g2 = parseInt(clean.substring(2, 4), 16);
|
|
3899
3899
|
const b3 = parseInt(clean.substring(4, 6), 16);
|
|
3900
|
-
return (
|
|
3900
|
+
return (text2) => import_picocolors.default.isColorSupported ? `\x1B[38;2;${r2};${g2};${b3}m${text2}\x1B[39m` : text2;
|
|
3901
3901
|
}
|
|
3902
3902
|
var import_picocolors, theme;
|
|
3903
3903
|
var init_theme = __esm({
|
|
@@ -4012,26 +4012,26 @@ var init_banner = __esm({
|
|
|
4012
4012
|
function mark(kind) {
|
|
4013
4013
|
return MARKS[kind];
|
|
4014
4014
|
}
|
|
4015
|
-
function heading(
|
|
4015
|
+
function heading(text2) {
|
|
4016
4016
|
process.stdout.write(`
|
|
4017
|
-
${import_picocolors3.default.bold(theme.mint("\u25C6"))} ${import_picocolors3.default.bold(
|
|
4017
|
+
${import_picocolors3.default.bold(theme.mint("\u25C6"))} ${import_picocolors3.default.bold(text2)}
|
|
4018
4018
|
`);
|
|
4019
4019
|
}
|
|
4020
|
-
function line(
|
|
4021
|
-
process.stdout.write(`${
|
|
4020
|
+
function line(text2 = "") {
|
|
4021
|
+
process.stdout.write(`${text2}
|
|
4022
4022
|
`);
|
|
4023
4023
|
}
|
|
4024
|
-
function item(kind,
|
|
4025
|
-
line(` ${mark(kind)} ${
|
|
4024
|
+
function item(kind, text2) {
|
|
4025
|
+
line(` ${mark(kind)} ${text2}`);
|
|
4026
4026
|
}
|
|
4027
|
-
function detail(
|
|
4028
|
-
line(` ${import_picocolors3.default.dim(
|
|
4027
|
+
function detail(text2) {
|
|
4028
|
+
line(` ${import_picocolors3.default.dim(text2)}`);
|
|
4029
4029
|
}
|
|
4030
|
-
function hint(
|
|
4031
|
-
line(` ${theme.sky("\u2192")} ${
|
|
4030
|
+
function hint(text2) {
|
|
4031
|
+
line(` ${theme.sky("\u2192")} ${text2}`);
|
|
4032
4032
|
}
|
|
4033
|
-
function errorLine(
|
|
4034
|
-
process.stderr.write(`${theme.coral("error")} ${
|
|
4033
|
+
function errorLine(text2) {
|
|
4034
|
+
process.stderr.write(`${theme.coral("error")} ${text2}
|
|
4035
4035
|
`);
|
|
4036
4036
|
}
|
|
4037
4037
|
var import_picocolors3, OK, WARN, FAIL, SKIP, MARKS, color2;
|
|
@@ -4907,15 +4907,15 @@ function keysFilePath(env) {
|
|
|
4907
4907
|
const expanded = expandHome(configured);
|
|
4908
4908
|
return isAbsolute(expanded) ? expanded : expanded;
|
|
4909
4909
|
}
|
|
4910
|
-
function parseKeysFile(
|
|
4911
|
-
let
|
|
4910
|
+
function parseKeysFile(path24) {
|
|
4911
|
+
let text2;
|
|
4912
4912
|
try {
|
|
4913
|
-
|
|
4913
|
+
text2 = readFileSync3(path24, "utf8");
|
|
4914
4914
|
} catch {
|
|
4915
4915
|
return {};
|
|
4916
4916
|
}
|
|
4917
4917
|
const out = {};
|
|
4918
|
-
for (const raw of
|
|
4918
|
+
for (const raw of text2.split(/\r?\n/)) {
|
|
4919
4919
|
const line2 = raw.trim();
|
|
4920
4920
|
if (!line2 || line2.startsWith("#") || !line2.includes("=")) continue;
|
|
4921
4921
|
const idx = line2.indexOf("=");
|
|
@@ -5018,22 +5018,22 @@ function upsertKeyLines(existing, updates) {
|
|
|
5018
5018
|
out.push("# added by `caddis keys`");
|
|
5019
5019
|
out.push(...added);
|
|
5020
5020
|
}
|
|
5021
|
-
let
|
|
5022
|
-
if (!
|
|
5023
|
-
return
|
|
5021
|
+
let text2 = out.join("\n");
|
|
5022
|
+
if (!text2.endsWith("\n")) text2 += "\n";
|
|
5023
|
+
return text2;
|
|
5024
5024
|
}
|
|
5025
|
-
function restrictPermissions(
|
|
5025
|
+
function restrictPermissions(path24) {
|
|
5026
5026
|
if (process.platform === "win32") return null;
|
|
5027
5027
|
try {
|
|
5028
|
-
chmodSync(
|
|
5028
|
+
chmodSync(path24, 384);
|
|
5029
5029
|
return null;
|
|
5030
5030
|
} catch (error) {
|
|
5031
5031
|
return error instanceof Error ? error.message : String(error);
|
|
5032
5032
|
}
|
|
5033
5033
|
}
|
|
5034
5034
|
async function keys(options = {}) {
|
|
5035
|
-
const
|
|
5036
|
-
const fileKeys = parseKeysFile(
|
|
5035
|
+
const path24 = keysFilePath(process.env);
|
|
5036
|
+
const fileKeys = parseKeysFile(path24);
|
|
5037
5037
|
const names = Object.keys(PROVIDERS).sort();
|
|
5038
5038
|
const current = names.map((name) => {
|
|
5039
5039
|
const preset = PROVIDERS[name];
|
|
@@ -5049,7 +5049,7 @@ async function keys(options = {}) {
|
|
|
5049
5049
|
if (options.check) {
|
|
5050
5050
|
const configured = current.filter((entry) => entry.value);
|
|
5051
5051
|
if (!configured.length) {
|
|
5052
|
-
process.stdout.write(`no provider keys configured (looked in $ENV and ${
|
|
5052
|
+
process.stdout.write(`no provider keys configured (looked in $ENV and ${path24})
|
|
5053
5053
|
`);
|
|
5054
5054
|
return 1;
|
|
5055
5055
|
}
|
|
@@ -5064,7 +5064,7 @@ async function keys(options = {}) {
|
|
|
5064
5064
|
return bad ? 1 : 0;
|
|
5065
5065
|
}
|
|
5066
5066
|
Ie("caddis keys");
|
|
5067
|
-
process.stdout.write(` keys file: ${
|
|
5067
|
+
process.stdout.write(` keys file: ${path24}
|
|
5068
5068
|
|
|
5069
5069
|
`);
|
|
5070
5070
|
for (const entry of current) {
|
|
@@ -5124,20 +5124,20 @@ async function keys(options = {}) {
|
|
|
5124
5124
|
return 0;
|
|
5125
5125
|
}
|
|
5126
5126
|
if (options.dryRun) {
|
|
5127
|
-
Se(`dry run \u2014 would write ${Object.keys(collected).join(", ")} to ${
|
|
5127
|
+
Se(`dry run \u2014 would write ${Object.keys(collected).join(", ")} to ${path24}`);
|
|
5128
5128
|
return 0;
|
|
5129
5129
|
}
|
|
5130
5130
|
let existing = "";
|
|
5131
5131
|
try {
|
|
5132
|
-
existing = readFileSync4(
|
|
5132
|
+
existing = readFileSync4(path24, "utf8");
|
|
5133
5133
|
} catch {
|
|
5134
5134
|
existing = "";
|
|
5135
5135
|
}
|
|
5136
|
-
mkdirSync2(dirname(
|
|
5137
|
-
writeFileSync(
|
|
5138
|
-
const permWarning = restrictPermissions(
|
|
5136
|
+
mkdirSync2(dirname(path24), { recursive: true });
|
|
5137
|
+
writeFileSync(path24, upsertKeyLines(existing, collected), { encoding: "utf8" });
|
|
5138
|
+
const permWarning = restrictPermissions(path24);
|
|
5139
5139
|
process.stdout.write(`
|
|
5140
|
-
wrote ${Object.keys(collected).join(", ")} to ${
|
|
5140
|
+
wrote ${Object.keys(collected).join(", ")} to ${path24}
|
|
5141
5141
|
`);
|
|
5142
5142
|
if (permWarning) process.stdout.write(color2.yellow(` could not set 0600 on the keys file: ${permWarning}
|
|
5143
5143
|
`));
|
|
@@ -5620,11 +5620,11 @@ var init_doctor = __esm({
|
|
|
5620
5620
|
});
|
|
5621
5621
|
|
|
5622
5622
|
// src/util/table.ts
|
|
5623
|
-
function visibleWidth(
|
|
5624
|
-
return
|
|
5623
|
+
function visibleWidth(text2) {
|
|
5624
|
+
return text2.replace(ANSI, "").length;
|
|
5625
5625
|
}
|
|
5626
|
-
function pad(
|
|
5627
|
-
return
|
|
5626
|
+
function pad(text2, width) {
|
|
5627
|
+
return text2 + " ".repeat(Math.max(0, width - visibleWidth(text2)));
|
|
5628
5628
|
}
|
|
5629
5629
|
function renderTable(headers, rows) {
|
|
5630
5630
|
const widths = headers.map(
|
|
@@ -5745,7 +5745,11 @@ import path7 from "path";
|
|
|
5745
5745
|
function hubDir(home = caddisHome()) {
|
|
5746
5746
|
return path7.join(home, ".caddis", "hub");
|
|
5747
5747
|
}
|
|
5748
|
-
|
|
5748
|
+
function hubHome(home) {
|
|
5749
|
+
const override = process.env.CADDIS_HUB_HOME;
|
|
5750
|
+
return override ? override : hubDir(home);
|
|
5751
|
+
}
|
|
5752
|
+
var configPath, registryPath, keyPath, lockPath, auditPath;
|
|
5749
5753
|
var init_paths = __esm({
|
|
5750
5754
|
"src/hub/paths.ts"() {
|
|
5751
5755
|
"use strict";
|
|
@@ -5754,6 +5758,7 @@ var init_paths = __esm({
|
|
|
5754
5758
|
registryPath = (home) => path7.join(hubDir(home), "repos.json");
|
|
5755
5759
|
keyPath = (home) => path7.join(hubDir(home), "key");
|
|
5756
5760
|
lockPath = (home) => path7.join(hubDir(home), "hub.lock");
|
|
5761
|
+
auditPath = (home) => path7.join(hubHome(home), "audit.jsonl");
|
|
5757
5762
|
}
|
|
5758
5763
|
});
|
|
5759
5764
|
|
|
@@ -5800,9 +5805,9 @@ X-GNOME-Autostart-enabled=true
|
|
|
5800
5805
|
NoDisplay=true
|
|
5801
5806
|
`;
|
|
5802
5807
|
}
|
|
5803
|
-
function writeText(file,
|
|
5808
|
+
function writeText(file, text2) {
|
|
5804
5809
|
mkdirSync3(path8.dirname(file), { recursive: true });
|
|
5805
|
-
writeFileSync2(file,
|
|
5810
|
+
writeFileSync2(file, text2, "utf8");
|
|
5806
5811
|
}
|
|
5807
5812
|
async function enableAutostart(deps = {}) {
|
|
5808
5813
|
const home = deps.home ?? caddisHome();
|
|
@@ -5919,9 +5924,9 @@ function writeJsonAtomic(file, data) {
|
|
|
5919
5924
|
}
|
|
5920
5925
|
}
|
|
5921
5926
|
function readJson(file, normalize, fallback) {
|
|
5922
|
-
let
|
|
5927
|
+
let text2;
|
|
5923
5928
|
try {
|
|
5924
|
-
|
|
5929
|
+
text2 = readFileSync6(file, "utf8");
|
|
5925
5930
|
} catch (e2) {
|
|
5926
5931
|
if (e2.code === "ENOENT") {
|
|
5927
5932
|
const good = lastGood.get(file);
|
|
@@ -5930,7 +5935,7 @@ function readJson(file, normalize, fallback) {
|
|
|
5930
5935
|
return failure(file, fallback, `cannot read ${path9.basename(file)}: ${e2.message}`);
|
|
5931
5936
|
}
|
|
5932
5937
|
try {
|
|
5933
|
-
const value = normalize(JSON.parse(
|
|
5938
|
+
const value = normalize(JSON.parse(text2));
|
|
5934
5939
|
lastGood.set(file, value);
|
|
5935
5940
|
return { value };
|
|
5936
5941
|
} catch (e2) {
|
|
@@ -6031,16 +6036,16 @@ function removeQuiet(file) {
|
|
|
6031
6036
|
}
|
|
6032
6037
|
}
|
|
6033
6038
|
function readKey(file, platform) {
|
|
6034
|
-
let
|
|
6039
|
+
let text2;
|
|
6035
6040
|
try {
|
|
6036
|
-
|
|
6041
|
+
text2 = readFileSync7(file, "utf8").trim();
|
|
6037
6042
|
} catch (e2) {
|
|
6038
6043
|
if (e2.code === "ENOENT") return null;
|
|
6039
6044
|
throw e2;
|
|
6040
6045
|
}
|
|
6041
|
-
if (!KEY_RE.test(
|
|
6046
|
+
if (!KEY_RE.test(text2)) throw new Error(`the hub key file is corrupt: delete ${file} and start again`);
|
|
6042
6047
|
if (platform !== "win32") chmodSync2(file, 384);
|
|
6043
|
-
return
|
|
6048
|
+
return text2;
|
|
6044
6049
|
}
|
|
6045
6050
|
async function ownerOnly(file, platform, deps) {
|
|
6046
6051
|
if (platform !== "win32") {
|
|
@@ -6278,400 +6283,345 @@ var init_restart = __esm({
|
|
|
6278
6283
|
}
|
|
6279
6284
|
});
|
|
6280
6285
|
|
|
6281
|
-
// src/hub/
|
|
6282
|
-
import {
|
|
6283
|
-
|
|
6284
|
-
|
|
6285
|
-
}
|
|
6286
|
-
|
|
6287
|
-
|
|
6288
|
-
|
|
6289
|
-
|
|
6290
|
-
|
|
6291
|
-
|
|
6292
|
-
|
|
6293
|
-
|
|
6294
|
-
|
|
6295
|
-
|
|
6296
|
-
|
|
6297
|
-
|
|
6298
|
-
|
|
6299
|
-
|
|
6300
|
-
|
|
6301
|
-
|
|
6302
|
-
|
|
6303
|
-
|
|
6304
|
-
|
|
6305
|
-
|
|
6306
|
-
|
|
6307
|
-
|
|
6286
|
+
// src/hub/append.ts
|
|
6287
|
+
import { mkdir, open } from "fs/promises";
|
|
6288
|
+
import path13 from "path";
|
|
6289
|
+
async function writeLine(file, line2) {
|
|
6290
|
+
await mkdir(path13.dirname(file), { recursive: true });
|
|
6291
|
+
const deadline = Date.now() + RETRY_FOR_MS;
|
|
6292
|
+
for (; ; ) {
|
|
6293
|
+
try {
|
|
6294
|
+
const fh = await open(file, "a+", 384);
|
|
6295
|
+
try {
|
|
6296
|
+
const { size } = await fh.stat();
|
|
6297
|
+
let prefix = "";
|
|
6298
|
+
if (size > 0) {
|
|
6299
|
+
const last = Buffer.alloc(1);
|
|
6300
|
+
await fh.read(last, 0, 1, size - 1);
|
|
6301
|
+
if (last[0] !== 10) prefix = "\n";
|
|
6302
|
+
}
|
|
6303
|
+
await fh.write(`${prefix}${line2}
|
|
6304
|
+
`);
|
|
6305
|
+
await fh.sync();
|
|
6306
|
+
} finally {
|
|
6307
|
+
await fh.close();
|
|
6308
|
+
}
|
|
6309
|
+
return;
|
|
6310
|
+
} catch (e2) {
|
|
6311
|
+
const code = e2.code ?? "";
|
|
6312
|
+
if (process.platform !== "win32" || !RETRY_CODES.has(code) || Date.now() >= deadline) throw e2;
|
|
6313
|
+
await new Promise((r2) => setTimeout(r2, 20));
|
|
6314
|
+
}
|
|
6308
6315
|
}
|
|
6309
|
-
return out;
|
|
6310
6316
|
}
|
|
6311
|
-
|
|
6312
|
-
|
|
6313
|
-
|
|
6317
|
+
function appendLine(file, line2) {
|
|
6318
|
+
if (line2.includes("\n") || line2.includes("\r")) return Promise.reject(new Error("a line must hold no newline"));
|
|
6319
|
+
const key = keyOf(file);
|
|
6320
|
+
const prev = chains.get(key) ?? Promise.resolve();
|
|
6321
|
+
const next = prev.catch(() => void 0).then(() => writeLine(file, line2));
|
|
6322
|
+
chains.set(key, next);
|
|
6323
|
+
const clear = () => {
|
|
6324
|
+
if (chains.get(key) === next) chains.delete(key);
|
|
6325
|
+
};
|
|
6326
|
+
next.then(clear, clear);
|
|
6327
|
+
return next;
|
|
6328
|
+
}
|
|
6329
|
+
var chains, RETRY_CODES, RETRY_FOR_MS, keyOf;
|
|
6330
|
+
var init_append = __esm({
|
|
6331
|
+
"src/hub/append.ts"() {
|
|
6314
6332
|
"use strict";
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
constructor(now = Date.now) {
|
|
6322
|
-
this.now = now;
|
|
6323
|
-
}
|
|
6324
|
-
now;
|
|
6325
|
-
codes = [];
|
|
6326
|
-
sessions = [];
|
|
6327
|
-
/** Mint a single-use code. Expired codes are dropped first; then the oldest goes past the cap. */
|
|
6328
|
-
mintCode() {
|
|
6329
|
-
const t = this.now();
|
|
6330
|
-
this.codes = this.codes.filter((c) => t - c.mintedAt < CODE_TTL_MS);
|
|
6331
|
-
const value = randomToken();
|
|
6332
|
-
this.codes.push({ value, mintedAt: t });
|
|
6333
|
-
while (this.codes.length > MAX_CODES) this.codes.shift();
|
|
6334
|
-
return value;
|
|
6335
|
-
}
|
|
6336
|
-
/** Expiry time of a code minted now, as UTC ISO 8601. */
|
|
6337
|
-
codeExpiresAt() {
|
|
6338
|
-
return new Date(this.now() + CODE_TTL_MS).toISOString();
|
|
6339
|
-
}
|
|
6340
|
-
/**
|
|
6341
|
-
* Swap a code for a new session id. The code is removed before the age check,
|
|
6342
|
-
* so a code is consumed even when this call fails. Returns null on failure.
|
|
6343
|
-
*/
|
|
6344
|
-
redeemCode(code) {
|
|
6345
|
-
if (!code) return null;
|
|
6346
|
-
let found;
|
|
6347
|
-
for (const c of this.codes) if (safeEqual(c.value, code)) found = c;
|
|
6348
|
-
if (!found) return null;
|
|
6349
|
-
this.codes = this.codes.filter((c) => c !== found);
|
|
6350
|
-
const age = this.now() - found.mintedAt;
|
|
6351
|
-
if (age < 0 || age >= CODE_TTL_MS) return null;
|
|
6352
|
-
const t = this.now();
|
|
6353
|
-
const s = { id: randomToken(), csrf: randomToken(), tab: randomToken(), createdAt: t, lastSeenAt: t };
|
|
6354
|
-
this.sessions.push(s);
|
|
6355
|
-
while (this.sessions.length > MAX_SESSIONS) this.sessions.shift();
|
|
6356
|
-
return s.id;
|
|
6357
|
-
}
|
|
6358
|
-
/** Remove a code without making a session (a refused /login still uses up its code). */
|
|
6359
|
-
discardCode(code) {
|
|
6360
|
-
if (!code) return;
|
|
6361
|
-
this.codes = this.codes.filter((c) => !safeEqual(c.value, code));
|
|
6362
|
-
}
|
|
6363
|
-
/**
|
|
6364
|
-
* Find a live session and mark it used. A session past the idle TTL or the absolute TTL
|
|
6365
|
-
* is removed and the call returns null.
|
|
6366
|
-
*/
|
|
6367
|
-
getSession(id) {
|
|
6368
|
-
return this.findSession(id, null);
|
|
6369
|
-
}
|
|
6370
|
-
/**
|
|
6371
|
-
* As getSession, but the session's tab token must match too (constant time). A wrong or missing token
|
|
6372
|
-
* returns null and does not mark the session used.
|
|
6373
|
-
*/
|
|
6374
|
-
getTabSession(id, tab) {
|
|
6375
|
-
return this.findSession(id, tab ?? "");
|
|
6376
|
-
}
|
|
6377
|
-
findSession(id, tab) {
|
|
6378
|
-
if (!id) return null;
|
|
6379
|
-
let found = null;
|
|
6380
|
-
for (const s of this.sessions) if (safeEqual(s.id, id)) found = s;
|
|
6381
|
-
if (!found) return null;
|
|
6382
|
-
if (tab !== null && !safeEqual(found.tab, tab)) return null;
|
|
6383
|
-
const t = this.now();
|
|
6384
|
-
if (t - found.lastSeenAt >= SESSION_IDLE_MS || t - found.createdAt >= SESSION_MAX_MS) {
|
|
6385
|
-
this.sessions = this.sessions.filter((x2) => x2 !== found);
|
|
6386
|
-
return null;
|
|
6387
|
-
}
|
|
6388
|
-
found.lastSeenAt = t;
|
|
6389
|
-
return found;
|
|
6390
|
-
}
|
|
6391
|
-
deleteSession(id) {
|
|
6392
|
-
const s = this.getSession(id);
|
|
6393
|
-
if (s) this.sessions = this.sessions.filter((x2) => x2 !== s);
|
|
6394
|
-
}
|
|
6395
|
-
codeCount() {
|
|
6396
|
-
return this.codes.length;
|
|
6397
|
-
}
|
|
6398
|
-
sessionCount() {
|
|
6399
|
-
return this.sessions.length;
|
|
6400
|
-
}
|
|
6333
|
+
chains = /* @__PURE__ */ new Map();
|
|
6334
|
+
RETRY_CODES = /* @__PURE__ */ new Set(["EBUSY", "EPERM", "EACCES"]);
|
|
6335
|
+
RETRY_FOR_MS = 2e3;
|
|
6336
|
+
keyOf = (file) => {
|
|
6337
|
+
const abs = path13.resolve(file);
|
|
6338
|
+
return process.platform === "win32" ? abs.toLowerCase() : abs;
|
|
6401
6339
|
};
|
|
6402
6340
|
}
|
|
6403
6341
|
});
|
|
6404
6342
|
|
|
6405
|
-
// src/hub/
|
|
6406
|
-
import
|
|
6407
|
-
import
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
|
|
6414
|
-
|
|
6343
|
+
// src/hub/sources/coordinator.ts
|
|
6344
|
+
import { closeSync as closeSync2, fstatSync, openSync as openSync2, readdirSync as readdirSync3, readFileSync as readFileSync10, readSync } from "fs";
|
|
6345
|
+
import path14 from "path";
|
|
6346
|
+
function stub(repoId, schema) {
|
|
6347
|
+
return {
|
|
6348
|
+
repo_id: repoId,
|
|
6349
|
+
schema,
|
|
6350
|
+
coordinator_session: null,
|
|
6351
|
+
heartbeat_at: null,
|
|
6352
|
+
stopped_at: null,
|
|
6353
|
+
queue: [],
|
|
6354
|
+
merging_now: null,
|
|
6355
|
+
deploy_checks: [],
|
|
6356
|
+
ledger: [],
|
|
6357
|
+
processed_requests: [],
|
|
6358
|
+
owner_asks: [],
|
|
6359
|
+
raw_requests: []
|
|
6360
|
+
};
|
|
6415
6361
|
}
|
|
6416
|
-
function
|
|
6417
|
-
let
|
|
6362
|
+
function parse3(repoId, text2) {
|
|
6363
|
+
let raw;
|
|
6418
6364
|
try {
|
|
6419
|
-
|
|
6420
|
-
} catch {
|
|
6421
|
-
return
|
|
6365
|
+
raw = JSON.parse(text2);
|
|
6366
|
+
} catch (e2) {
|
|
6367
|
+
return { error: `corrupt coordinator.json: ${e2.message}` };
|
|
6422
6368
|
}
|
|
6423
|
-
if (
|
|
6424
|
-
|
|
6425
|
-
const
|
|
6426
|
-
|
|
6427
|
-
|
|
6428
|
-
}
|
|
6429
|
-
|
|
6430
|
-
|
|
6431
|
-
|
|
6432
|
-
|
|
6433
|
-
|
|
6434
|
-
|
|
6435
|
-
|
|
6436
|
-
|
|
6437
|
-
|
|
6438
|
-
|
|
6439
|
-
|
|
6440
|
-
|
|
6441
|
-
|
|
6442
|
-
|
|
6443
|
-
|
|
6369
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return { error: "coordinator.json is not a JSON object" };
|
|
6370
|
+
const o2 = raw;
|
|
6371
|
+
const schema = o2.schema;
|
|
6372
|
+
if (typeof schema !== "number" || !Number.isInteger(schema) || schema < COORDINATOR_SCHEMA - 1) {
|
|
6373
|
+
return { error: `coordinator.json has an unusable schema: ${String(schema)}` };
|
|
6374
|
+
}
|
|
6375
|
+
if (schema > COORDINATOR_SCHEMA) {
|
|
6376
|
+
return {
|
|
6377
|
+
newer: stub(repoId, schema),
|
|
6378
|
+
error: `coordinator schema ${schema} is newer than this hub (${COORDINATOR_SCHEMA}): update the hub`
|
|
6379
|
+
};
|
|
6380
|
+
}
|
|
6381
|
+
return {
|
|
6382
|
+
good: {
|
|
6383
|
+
repo_id: repoId,
|
|
6384
|
+
schema,
|
|
6385
|
+
coordinator_session: o2.coordinator_session ?? null,
|
|
6386
|
+
heartbeat_at: typeof o2.heartbeat_at === "string" ? o2.heartbeat_at : null,
|
|
6387
|
+
stopped_at: typeof o2.stopped_at === "string" ? o2.stopped_at : null,
|
|
6388
|
+
queue: arr(o2.queue),
|
|
6389
|
+
merging_now: o2.merging_now ?? null,
|
|
6390
|
+
deploy_checks: arr(o2.deploy_checks).slice(-5),
|
|
6391
|
+
// Kept longer than shown: owner items (R37) and the request view (R38) join on them.
|
|
6392
|
+
ledger: arr(o2.ledger).slice(-100),
|
|
6393
|
+
processed_requests: arr(o2.processed_requests).slice(-100),
|
|
6394
|
+
owner_asks: arr(o2.owner_asks).filter((a) => str(rec(a).id) && str(rec(a).what)),
|
|
6395
|
+
raw_requests: []
|
|
6444
6396
|
}
|
|
6445
|
-
|
|
6446
|
-
let size = 0;
|
|
6447
|
-
let done = false;
|
|
6448
|
-
req.on("data", (c) => {
|
|
6449
|
-
if (done) return;
|
|
6450
|
-
size += c.length;
|
|
6451
|
-
if (size > MAX_BODY_BYTES) {
|
|
6452
|
-
done = true;
|
|
6453
|
-
reject(new BodyTooLarge());
|
|
6454
|
-
return;
|
|
6455
|
-
}
|
|
6456
|
-
chunks.push(c);
|
|
6457
|
-
});
|
|
6458
|
-
req.on("end", () => {
|
|
6459
|
-
if (!done) resolve(Buffer.concat(chunks));
|
|
6460
|
-
});
|
|
6461
|
-
req.on("error", (e2) => {
|
|
6462
|
-
if (!done) reject(e2);
|
|
6463
|
-
});
|
|
6464
|
-
});
|
|
6465
|
-
}
|
|
6466
|
-
function tooLarge(req, res) {
|
|
6467
|
-
res.on("finish", () => req.socket.destroy());
|
|
6468
|
-
fail(res, 413, "body_too_large");
|
|
6397
|
+
};
|
|
6469
6398
|
}
|
|
6470
|
-
|
|
6471
|
-
|
|
6472
|
-
const file = resolveStatic(uiDir, rel);
|
|
6473
|
-
if (!file) return fail(res, 404, "not_found");
|
|
6474
|
-
let body;
|
|
6399
|
+
function readTailLines(file, maxBytes = REQUESTS_TAIL_BYTES) {
|
|
6400
|
+
let fd;
|
|
6475
6401
|
try {
|
|
6476
|
-
|
|
6477
|
-
body = await readFile(file);
|
|
6402
|
+
fd = openSync2(file, "r");
|
|
6478
6403
|
} catch {
|
|
6479
|
-
|
|
6480
|
-
|
|
6481
|
-
|
|
6482
|
-
|
|
6483
|
-
|
|
6484
|
-
|
|
6485
|
-
|
|
6486
|
-
|
|
6404
|
+
return [];
|
|
6405
|
+
}
|
|
6406
|
+
try {
|
|
6407
|
+
const size = fstatSync(fd).size;
|
|
6408
|
+
const start = Math.max(0, size - maxBytes);
|
|
6409
|
+
const buf = Buffer.alloc(size - start);
|
|
6410
|
+
let got = 0;
|
|
6411
|
+
while (got < buf.length) {
|
|
6412
|
+
const n = readSync(fd, buf, got, buf.length - got, start + got);
|
|
6413
|
+
if (n <= 0) break;
|
|
6414
|
+
got += n;
|
|
6487
6415
|
}
|
|
6488
|
-
|
|
6416
|
+
let text2 = buf.subarray(0, got).toString("utf8");
|
|
6417
|
+
const lastNl = text2.lastIndexOf("\n");
|
|
6418
|
+
if (lastNl < 0) return [];
|
|
6419
|
+
text2 = text2.slice(0, lastNl);
|
|
6420
|
+
const lines = text2.split("\n");
|
|
6421
|
+
if (start > 0) lines.shift();
|
|
6422
|
+
return lines.map((l2) => l2.replace(/\r$/, "")).filter((l2) => l2.trim() !== "");
|
|
6423
|
+
} catch {
|
|
6424
|
+
return [];
|
|
6425
|
+
} finally {
|
|
6426
|
+
closeSync2(fd);
|
|
6489
6427
|
}
|
|
6490
|
-
res.writeHead(200, {
|
|
6491
|
-
"Content-Type": MIME[path13.extname(file).toLowerCase()] ?? "application/octet-stream",
|
|
6492
|
-
"Content-Length": body.length,
|
|
6493
|
-
"Cache-Control": urlPath === "/" ? "no-store" : "public, max-age=31536000, immutable"
|
|
6494
|
-
});
|
|
6495
|
-
res.end(body);
|
|
6496
6428
|
}
|
|
6497
|
-
function
|
|
6498
|
-
const
|
|
6499
|
-
|
|
6429
|
+
function parseRequests(lines) {
|
|
6430
|
+
const out = [];
|
|
6431
|
+
for (const line2 of lines) {
|
|
6432
|
+
let o2;
|
|
6433
|
+
try {
|
|
6434
|
+
o2 = rec(JSON.parse(line2));
|
|
6435
|
+
} catch {
|
|
6436
|
+
continue;
|
|
6437
|
+
}
|
|
6438
|
+
const id = str(o2.id);
|
|
6439
|
+
const action = str(o2.action);
|
|
6440
|
+
const created = str(o2.created_at);
|
|
6441
|
+
if (!id || !action || !created) continue;
|
|
6442
|
+
out.push({
|
|
6443
|
+
id,
|
|
6444
|
+
action,
|
|
6445
|
+
pr: typeof o2.pr === "number" && Number.isInteger(o2.pr) ? o2.pr : null,
|
|
6446
|
+
head_sha: str(o2.head_sha),
|
|
6447
|
+
what: str(rec(o2.args).what),
|
|
6448
|
+
created_at: created,
|
|
6449
|
+
expires_at: str(o2.expires_at)
|
|
6450
|
+
});
|
|
6451
|
+
}
|
|
6452
|
+
return out;
|
|
6500
6453
|
}
|
|
6501
|
-
|
|
6502
|
-
const
|
|
6503
|
-
|
|
6504
|
-
|
|
6505
|
-
|
|
6454
|
+
function requestViews(raw, processed, now) {
|
|
6455
|
+
const results = /* @__PURE__ */ new Map();
|
|
6456
|
+
for (const p2 of processed) {
|
|
6457
|
+
const r2 = rec(p2);
|
|
6458
|
+
const id = str(r2.id);
|
|
6459
|
+
if (id) results.set(id, r2);
|
|
6506
6460
|
}
|
|
6507
|
-
const
|
|
6508
|
-
const
|
|
6509
|
-
const
|
|
6510
|
-
|
|
6511
|
-
|
|
6512
|
-
|
|
6513
|
-
|
|
6514
|
-
|
|
6515
|
-
|
|
6516
|
-
|
|
6517
|
-
|
|
6518
|
-
|
|
6519
|
-
|
|
6520
|
-
|
|
6521
|
-
|
|
6522
|
-
|
|
6523
|
-
|
|
6524
|
-
|
|
6525
|
-
return;
|
|
6526
|
-
}
|
|
6527
|
-
const path20 = url.pathname;
|
|
6528
|
-
const method = req.method ?? "GET";
|
|
6529
|
-
if (path20.startsWith("/api/") || path20 === "/login") res.setHeader("Cache-Control", "no-store");
|
|
6530
|
-
if (!hostAllowed(req.headers.host, port)) {
|
|
6531
|
-
if (path20 === "/login") auth.discardCode(url.searchParams.get("code") ?? "");
|
|
6532
|
-
fail(res, 403, "bad_host");
|
|
6533
|
-
return;
|
|
6534
|
-
}
|
|
6535
|
-
if (path20 === "/api/hub/whoami" && method === "GET") {
|
|
6536
|
-
if (!opts.instance) return fail(res, 404, "not_found");
|
|
6537
|
-
return send(res, 200, { instance: opts.instance });
|
|
6538
|
-
}
|
|
6539
|
-
if (path20 === "/api/health" && method === "GET") {
|
|
6540
|
-
if (!keyOk(req, key)) return fail(res, 401, "unauthorized");
|
|
6541
|
-
return send(res, 200, { schema: 1, ok: true, versions });
|
|
6542
|
-
}
|
|
6543
|
-
if (path20 === "/api/hub/code" && method === "POST") {
|
|
6544
|
-
if (!keyOk(req, key)) return fail(res, 401, "unauthorized");
|
|
6545
|
-
try {
|
|
6546
|
-
await readBody(req);
|
|
6547
|
-
} catch (e2) {
|
|
6548
|
-
if (e2 instanceof BodyTooLarge) return tooLarge(req, res);
|
|
6549
|
-
throw e2;
|
|
6550
|
-
}
|
|
6551
|
-
const code = auth.mintCode();
|
|
6552
|
-
return send(res, 200, { schema: 1, code, expires_at: auth.codeExpiresAt() });
|
|
6461
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6462
|
+
const out = [];
|
|
6463
|
+
for (const q2 of raw) {
|
|
6464
|
+
if (seen.has(q2.id)) continue;
|
|
6465
|
+
seen.add(q2.id);
|
|
6466
|
+
const r2 = results.get(q2.id);
|
|
6467
|
+
let status5;
|
|
6468
|
+
let reason = null;
|
|
6469
|
+
let at = null;
|
|
6470
|
+
if (r2) {
|
|
6471
|
+
const result = str(r2.result);
|
|
6472
|
+
status5 = result === "done" || result === "rejected" || result === "expired" ? result : "rejected";
|
|
6473
|
+
reason = str(r2.reason);
|
|
6474
|
+
at = str(r2.at);
|
|
6475
|
+
} else {
|
|
6476
|
+
const created = Date.parse(q2.created_at);
|
|
6477
|
+
status5 = !Number.isNaN(created) && now - created >= PICKUP_WITHIN_MS ? "not_picked_up" : "requested";
|
|
6478
|
+
if (status5 === "not_picked_up") reason = "no coordinator intake for 2 min";
|
|
6553
6479
|
}
|
|
6554
|
-
|
|
6555
|
-
|
|
6480
|
+
out.push({ ...q2, status: status5, reason, at });
|
|
6481
|
+
}
|
|
6482
|
+
return out.slice(-REQUESTS_SHOWN);
|
|
6483
|
+
}
|
|
6484
|
+
function coordinatorStatus(heartbeatAt, stoppedAt, ageS) {
|
|
6485
|
+
const hb = heartbeatAt ? Date.parse(heartbeatAt) : NaN;
|
|
6486
|
+
const stop = stoppedAt ? Date.parse(stoppedAt) : NaN;
|
|
6487
|
+
if (!Number.isNaN(stop) && (Number.isNaN(hb) || stop >= hb)) return "stopped";
|
|
6488
|
+
return ageS !== null && ageS < RESPONDING_WITHIN_S ? "live" : "down";
|
|
6489
|
+
}
|
|
6490
|
+
function createCoordinatorSource(opts = {}) {
|
|
6491
|
+
const now = opts.now ?? Date.now;
|
|
6492
|
+
const lastGood2 = /* @__PURE__ */ new Map();
|
|
6493
|
+
const errors = /* @__PURE__ */ new Map();
|
|
6494
|
+
return {
|
|
6495
|
+
refresh() {
|
|
6496
|
+
const root = path14.join(hubHome(opts.home), "repos");
|
|
6497
|
+
let ids = [];
|
|
6556
6498
|
try {
|
|
6557
|
-
|
|
6558
|
-
} catch
|
|
6559
|
-
if (e2 instanceof BodyTooLarge) return tooLarge(req, res);
|
|
6560
|
-
throw e2;
|
|
6499
|
+
ids = readdirSync3(root, { withFileTypes: true }).filter((d3) => d3.isDirectory()).map((d3) => d3.name);
|
|
6500
|
+
} catch {
|
|
6561
6501
|
}
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
|
|
6565
|
-
|
|
6566
|
-
|
|
6567
|
-
|
|
6568
|
-
|
|
6569
|
-
|
|
6570
|
-
|
|
6571
|
-
|
|
6572
|
-
|
|
6573
|
-
|
|
6574
|
-
|
|
6575
|
-
|
|
6576
|
-
|
|
6502
|
+
const seen = new Set(ids);
|
|
6503
|
+
for (const id of [...lastGood2.keys()]) if (!seen.has(id)) lastGood2.delete(id);
|
|
6504
|
+
for (const id of [...errors.keys()]) if (!seen.has(id)) errors.delete(id);
|
|
6505
|
+
for (const id of ids) {
|
|
6506
|
+
const requests = parseRequests(readTailLines(path14.join(root, id, "requests.jsonl")));
|
|
6507
|
+
let text2;
|
|
6508
|
+
try {
|
|
6509
|
+
text2 = readFileSync10(path14.join(root, id, "coordinator.json"), "utf8");
|
|
6510
|
+
} catch (e2) {
|
|
6511
|
+
if (e2.code === "ENOENT") {
|
|
6512
|
+
lastGood2.delete(id);
|
|
6513
|
+
errors.delete(id);
|
|
6514
|
+
} else {
|
|
6515
|
+
if (!lastGood2.has(id)) lastGood2.set(id, stub(id, null));
|
|
6516
|
+
lastGood2.get(id).raw_requests = requests;
|
|
6517
|
+
errors.set(id, { error: `cannot read coordinator.json: ${e2.message}`, updateNeeded: false });
|
|
6518
|
+
}
|
|
6519
|
+
continue;
|
|
6520
|
+
}
|
|
6521
|
+
const r2 = parse3(id, text2);
|
|
6522
|
+
if (r2.good) {
|
|
6523
|
+
lastGood2.set(id, { ...r2.good, raw_requests: requests });
|
|
6524
|
+
errors.delete(id);
|
|
6525
|
+
continue;
|
|
6526
|
+
}
|
|
6527
|
+
if (!lastGood2.has(id)) lastGood2.set(id, r2.newer ?? stub(id, null));
|
|
6528
|
+
lastGood2.get(id).raw_requests = requests;
|
|
6529
|
+
errors.set(id, { error: r2.error ?? "unreadable", updateNeeded: r2.newer !== void 0 });
|
|
6577
6530
|
}
|
|
6578
|
-
|
|
6579
|
-
|
|
6580
|
-
|
|
6581
|
-
|
|
6531
|
+
},
|
|
6532
|
+
get() {
|
|
6533
|
+
const t = now();
|
|
6534
|
+
const out = [];
|
|
6535
|
+
for (const [id, good] of lastGood2) {
|
|
6536
|
+
const ms = good.heartbeat_at ? Date.parse(good.heartbeat_at) : NaN;
|
|
6537
|
+
const age = Number.isNaN(ms) ? null : Math.max(0, Math.floor((t - ms) / 1e3));
|
|
6538
|
+
const err = errors.get(id);
|
|
6539
|
+
const { raw_requests, ...rest } = good;
|
|
6540
|
+
const status5 = coordinatorStatus(good.heartbeat_at, good.stopped_at, age);
|
|
6541
|
+
out.push({
|
|
6542
|
+
...rest,
|
|
6543
|
+
heartbeat_age_s: age,
|
|
6544
|
+
responding: status5 === "live",
|
|
6545
|
+
status: status5,
|
|
6546
|
+
requests: requestViews(raw_requests, good.processed_requests, t),
|
|
6547
|
+
error: err?.error ?? null,
|
|
6548
|
+
update_needed: err?.updateNeeded ?? false
|
|
6582
6549
|
});
|
|
6583
6550
|
}
|
|
6584
|
-
return
|
|
6585
|
-
}
|
|
6586
|
-
if (path20 === "/" || path20.startsWith("/assets/") || path20.startsWith("/fonts/")) {
|
|
6587
|
-
await serveStatic(res, uiDir, path20);
|
|
6588
|
-
return;
|
|
6589
|
-
}
|
|
6590
|
-
if (path20 === "/login") {
|
|
6591
|
-
const id = auth.redeemCode(url.searchParams.get("code") ?? "");
|
|
6592
|
-
const session = id ? auth.getSession(id) : null;
|
|
6593
|
-
if (!id || !session) return fail(res, 401, "bad_code");
|
|
6594
|
-
res.writeHead(303, {
|
|
6595
|
-
Location: `/#tab=${session.tab}`,
|
|
6596
|
-
"Set-Cookie": `${SESSION_COOKIE}=${id}; HttpOnly; SameSite=Strict; Path=/`,
|
|
6597
|
-
"Content-Length": 0
|
|
6598
|
-
});
|
|
6599
|
-
res.end();
|
|
6600
|
-
return;
|
|
6601
|
-
}
|
|
6602
|
-
if (path20 === "/api/session") {
|
|
6603
|
-
const session = tabSessionOf(req);
|
|
6604
|
-
if (!session) return fail(res, 401, "unauthorized");
|
|
6605
|
-
return send(res, 200, { schema: 1, csrf_token: session.csrf, versions });
|
|
6606
|
-
}
|
|
6607
|
-
if (path20 === "/api/state") {
|
|
6608
|
-
if (!tabSessionOf(req)) return fail(res, 401, "unauthorized");
|
|
6609
|
-
let state;
|
|
6610
|
-
try {
|
|
6611
|
-
state = await opts.getState();
|
|
6612
|
-
} catch {
|
|
6613
|
-
return fail(res, 500, "state_failed");
|
|
6614
|
-
}
|
|
6615
|
-
return send(res, 200, state);
|
|
6551
|
+
return out.sort((a, b3) => a.repo_id.localeCompare(b3.repo_id));
|
|
6616
6552
|
}
|
|
6617
|
-
|
|
6553
|
+
};
|
|
6554
|
+
}
|
|
6555
|
+
var COORDINATOR_SCHEMA, RESPONDING_WITHIN_S, PICKUP_WITHIN_MS, REQUESTS_TAIL_BYTES, REQUESTS_SHOWN, arr, rec, str;
|
|
6556
|
+
var init_coordinator = __esm({
|
|
6557
|
+
"src/hub/sources/coordinator.ts"() {
|
|
6558
|
+
"use strict";
|
|
6559
|
+
init_paths();
|
|
6560
|
+
COORDINATOR_SCHEMA = 1;
|
|
6561
|
+
RESPONDING_WITHIN_S = 180;
|
|
6562
|
+
PICKUP_WITHIN_MS = 2 * 6e4;
|
|
6563
|
+
REQUESTS_TAIL_BYTES = 64 * 1024;
|
|
6564
|
+
REQUESTS_SHOWN = 30;
|
|
6565
|
+
arr = (v2) => Array.isArray(v2) ? v2 : [];
|
|
6566
|
+
rec = (v2) => v2 && typeof v2 === "object" && !Array.isArray(v2) ? v2 : {};
|
|
6567
|
+
str = (v2) => typeof v2 === "string" && v2 ? v2 : null;
|
|
6618
6568
|
}
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
6632
|
-
|
|
6569
|
+
});
|
|
6570
|
+
|
|
6571
|
+
// src/hub/audit.ts
|
|
6572
|
+
import { statSync } from "fs";
|
|
6573
|
+
function parseAudit(lines) {
|
|
6574
|
+
const out = [];
|
|
6575
|
+
for (const line2 of lines) {
|
|
6576
|
+
let o2;
|
|
6577
|
+
try {
|
|
6578
|
+
o2 = JSON.parse(line2);
|
|
6579
|
+
} catch {
|
|
6580
|
+
continue;
|
|
6581
|
+
}
|
|
6582
|
+
if (!o2 || typeof o2 !== "object" || Array.isArray(o2)) continue;
|
|
6583
|
+
const r2 = o2;
|
|
6584
|
+
const at = text(r2.at, 40);
|
|
6585
|
+
if (!at || Number.isNaN(Date.parse(at))) continue;
|
|
6586
|
+
out.push({
|
|
6587
|
+
at,
|
|
6588
|
+
request_id: text(r2.request_id, 80),
|
|
6589
|
+
repo: text(r2.repo, 120),
|
|
6590
|
+
pr: typeof r2.pr === "number" && Number.isInteger(r2.pr) ? r2.pr : null,
|
|
6591
|
+
action: text(r2.action, 20),
|
|
6592
|
+
what: text(r2.what),
|
|
6593
|
+
result: text(r2.result, 20),
|
|
6594
|
+
reason: text(r2.reason)
|
|
6633
6595
|
});
|
|
6634
|
-
}
|
|
6635
|
-
|
|
6636
|
-
port = addr.port;
|
|
6637
|
-
return {
|
|
6638
|
-
port,
|
|
6639
|
-
address: addr.address,
|
|
6640
|
-
close: () => new Promise((resolve) => {
|
|
6641
|
-
server.close(() => resolve());
|
|
6642
|
-
server.closeAllConnections();
|
|
6643
|
-
})
|
|
6644
|
-
};
|
|
6596
|
+
}
|
|
6597
|
+
return out;
|
|
6645
6598
|
}
|
|
6646
|
-
|
|
6647
|
-
|
|
6648
|
-
|
|
6599
|
+
function readAudit(home) {
|
|
6600
|
+
const file = auditPath(home);
|
|
6601
|
+
let sig;
|
|
6602
|
+
try {
|
|
6603
|
+
const st = statSync(file);
|
|
6604
|
+
sig = `${st.size}:${st.mtimeMs}`;
|
|
6605
|
+
} catch {
|
|
6606
|
+
cache.delete(file);
|
|
6607
|
+
return [];
|
|
6608
|
+
}
|
|
6609
|
+
const hit = cache.get(file);
|
|
6610
|
+
if (hit && hit.sig === sig) return hit.value;
|
|
6611
|
+
const value = parseAudit(readTailLines(file, AUDIT_TAIL_BYTES)).slice(-AUDIT_KEEP);
|
|
6612
|
+
cache.set(file, { sig, value });
|
|
6613
|
+
return value;
|
|
6614
|
+
}
|
|
6615
|
+
var AUDIT_KEEP, AUDIT_TAIL_BYTES, text, cache;
|
|
6616
|
+
var init_audit = __esm({
|
|
6617
|
+
"src/hub/audit.ts"() {
|
|
6649
6618
|
"use strict";
|
|
6650
|
-
|
|
6651
|
-
|
|
6652
|
-
|
|
6653
|
-
|
|
6654
|
-
|
|
6655
|
-
|
|
6656
|
-
MIN_KEY_BYTES = 32;
|
|
6657
|
-
CSP = "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'self'";
|
|
6658
|
-
NOT_BUILT_HTML = '<!doctype html><html lang="en"><head><meta charset="utf-8"><title>caddis hub</title></head><body>UI not built: run npm run build</body></html>';
|
|
6659
|
-
MIME = {
|
|
6660
|
-
".html": "text/html; charset=utf-8",
|
|
6661
|
-
".js": "text/javascript; charset=utf-8",
|
|
6662
|
-
".mjs": "text/javascript; charset=utf-8",
|
|
6663
|
-
".css": "text/css; charset=utf-8",
|
|
6664
|
-
".json": "application/json; charset=utf-8",
|
|
6665
|
-
".svg": "image/svg+xml",
|
|
6666
|
-
".png": "image/png",
|
|
6667
|
-
".ico": "image/x-icon",
|
|
6668
|
-
".woff2": "font/woff2",
|
|
6669
|
-
".txt": "text/plain; charset=utf-8",
|
|
6670
|
-
".map": "application/json; charset=utf-8"
|
|
6671
|
-
};
|
|
6672
|
-
BodyTooLarge = class extends Error {
|
|
6673
|
-
};
|
|
6674
|
-
fail = (res, status5, error) => send(res, status5, { schema: 1, error });
|
|
6619
|
+
init_paths();
|
|
6620
|
+
init_coordinator();
|
|
6621
|
+
AUDIT_KEEP = 200;
|
|
6622
|
+
AUDIT_TAIL_BYTES = 64 * 1024;
|
|
6623
|
+
text = (v2, max = 500) => typeof v2 === "string" && v2 ? v2.slice(0, max) : null;
|
|
6624
|
+
cache = /* @__PURE__ */ new Map();
|
|
6675
6625
|
}
|
|
6676
6626
|
});
|
|
6677
6627
|
|
|
@@ -6802,8 +6752,8 @@ var init_spawn = __esm({
|
|
|
6802
6752
|
});
|
|
6803
6753
|
|
|
6804
6754
|
// src/hub/sources/agents.ts
|
|
6805
|
-
import { existsSync as
|
|
6806
|
-
import
|
|
6755
|
+
import { existsSync as existsSync7, readFileSync as readFileSync11, statSync as statSync2 } from "fs";
|
|
6756
|
+
import path15 from "path";
|
|
6807
6757
|
function classifyWaiting(waitingFor) {
|
|
6808
6758
|
const w2 = (waitingFor ?? "").toLowerCase();
|
|
6809
6759
|
if (w2 === "permission prompt" || w2 === "input needed" || w2.includes("question")) return "owner";
|
|
@@ -6811,33 +6761,33 @@ function classifyWaiting(waitingFor) {
|
|
|
6811
6761
|
}
|
|
6812
6762
|
function repoPathFor(cwd) {
|
|
6813
6763
|
if (!cwd) return null;
|
|
6814
|
-
let dir =
|
|
6764
|
+
let dir = path15.resolve(cwd);
|
|
6815
6765
|
for (; ; ) {
|
|
6816
|
-
const dotGit =
|
|
6817
|
-
if (
|
|
6766
|
+
const dotGit = path15.join(dir, ".git");
|
|
6767
|
+
if (existsSync7(dotGit)) {
|
|
6818
6768
|
if (isDir(dotGit)) return normalizeRepoPath(dir);
|
|
6819
6769
|
if (isFile(dotGit)) return commonRoot(dir, dotGit);
|
|
6820
6770
|
return null;
|
|
6821
6771
|
}
|
|
6822
|
-
const parent =
|
|
6772
|
+
const parent = path15.dirname(dir);
|
|
6823
6773
|
if (parent === dir) return null;
|
|
6824
6774
|
dir = parent;
|
|
6825
6775
|
}
|
|
6826
6776
|
}
|
|
6827
6777
|
function commonRoot(dir, dotGitFile) {
|
|
6828
6778
|
try {
|
|
6829
|
-
const m2 = /^gitdir:\s*(.+?)\s*$/m.exec(
|
|
6779
|
+
const m2 = /^gitdir:\s*(.+?)\s*$/m.exec(readFileSync11(dotGitFile, "utf8"));
|
|
6830
6780
|
if (!m2) return null;
|
|
6831
|
-
const gitdir =
|
|
6781
|
+
const gitdir = path15.resolve(dir, m2[1] ?? "");
|
|
6832
6782
|
let common;
|
|
6833
6783
|
try {
|
|
6834
|
-
const rel =
|
|
6784
|
+
const rel = readFileSync11(path15.join(gitdir, "commondir"), "utf8").trim();
|
|
6835
6785
|
if (!rel) return normalizeRepoPath(dir);
|
|
6836
|
-
common =
|
|
6786
|
+
common = path15.resolve(gitdir, rel);
|
|
6837
6787
|
} catch {
|
|
6838
6788
|
return normalizeRepoPath(dir);
|
|
6839
6789
|
}
|
|
6840
|
-
return normalizeRepoPath(
|
|
6790
|
+
return normalizeRepoPath(path15.dirname(common));
|
|
6841
6791
|
} catch {
|
|
6842
6792
|
return null;
|
|
6843
6793
|
}
|
|
@@ -6864,10 +6814,10 @@ function createAgentsSource(opts = {}) {
|
|
|
6864
6814
|
for (const raw of parsed) {
|
|
6865
6815
|
if (!raw || typeof raw !== "object") continue;
|
|
6866
6816
|
const e2 = raw;
|
|
6867
|
-
const sessionId =
|
|
6817
|
+
const sessionId = str2(e2.sessionId);
|
|
6868
6818
|
if (!sessionId) continue;
|
|
6869
|
-
const kind =
|
|
6870
|
-
const status5 =
|
|
6819
|
+
const kind = str2(e2.kind) ?? "interactive";
|
|
6820
|
+
const status5 = str2(e2.status) ?? str2(e2.state) ?? "unknown";
|
|
6871
6821
|
if (kind === "background" && status5 === "done") continue;
|
|
6872
6822
|
const prior = byId.get(sessionId);
|
|
6873
6823
|
if (prior) {
|
|
@@ -6875,10 +6825,10 @@ function createAgentsSource(opts = {}) {
|
|
|
6875
6825
|
continue;
|
|
6876
6826
|
}
|
|
6877
6827
|
const pid = typeof e2.pid === "number" ? e2.pid : null;
|
|
6878
|
-
const cwd =
|
|
6828
|
+
const cwd = str2(e2.cwd);
|
|
6879
6829
|
const isWaiting = status5 === "waiting";
|
|
6880
|
-
const waitingFor = isWaiting ?
|
|
6881
|
-
const key = `${pid ??
|
|
6830
|
+
const waitingFor = isWaiting ? str2(e2.waitingFor) : null;
|
|
6831
|
+
const key = `${pid ?? str2(e2.id) ?? kind}:${sessionId}`;
|
|
6882
6832
|
let since = null;
|
|
6883
6833
|
if (isWaiting) {
|
|
6884
6834
|
seenWaiting.add(key);
|
|
@@ -6890,7 +6840,7 @@ function createAgentsSource(opts = {}) {
|
|
|
6890
6840
|
key,
|
|
6891
6841
|
pid,
|
|
6892
6842
|
session_id: sessionId,
|
|
6893
|
-
name:
|
|
6843
|
+
name: str2(e2.name),
|
|
6894
6844
|
kind,
|
|
6895
6845
|
cwd,
|
|
6896
6846
|
repo_path: repoPathFor(cwd),
|
|
@@ -6944,7 +6894,7 @@ function createAgentsSource(opts = {}) {
|
|
|
6944
6894
|
}
|
|
6945
6895
|
};
|
|
6946
6896
|
}
|
|
6947
|
-
var STALE_AFTER_MS2, WAIT_DEBOUNCE_MS, RUN_TIMEOUT_MS, FIND_TIMEOUT_MS, isFile, isDir,
|
|
6897
|
+
var STALE_AFTER_MS2, WAIT_DEBOUNCE_MS, RUN_TIMEOUT_MS, FIND_TIMEOUT_MS, isFile, isDir, str2;
|
|
6948
6898
|
var init_agents = __esm({
|
|
6949
6899
|
"src/hub/sources/agents.ts"() {
|
|
6950
6900
|
"use strict";
|
|
@@ -6958,34 +6908,37 @@ var init_agents = __esm({
|
|
|
6958
6908
|
FIND_TIMEOUT_MS = 1e4;
|
|
6959
6909
|
isFile = (p2) => {
|
|
6960
6910
|
try {
|
|
6961
|
-
return
|
|
6911
|
+
return statSync2(p2).isFile();
|
|
6962
6912
|
} catch {
|
|
6963
6913
|
return false;
|
|
6964
6914
|
}
|
|
6965
6915
|
};
|
|
6966
6916
|
isDir = (p2) => {
|
|
6967
6917
|
try {
|
|
6968
|
-
return
|
|
6918
|
+
return statSync2(p2).isDirectory();
|
|
6969
6919
|
} catch {
|
|
6970
6920
|
return false;
|
|
6971
6921
|
}
|
|
6972
6922
|
};
|
|
6973
|
-
|
|
6923
|
+
str2 = (v2) => typeof v2 === "string" && v2 ? v2 : null;
|
|
6974
6924
|
}
|
|
6975
6925
|
});
|
|
6976
6926
|
|
|
6977
6927
|
// src/hub/sources/collector.ts
|
|
6978
|
-
import { existsSync as
|
|
6928
|
+
import { existsSync as existsSync8 } from "fs";
|
|
6979
6929
|
import os5 from "os";
|
|
6980
|
-
import
|
|
6930
|
+
import path16 from "path";
|
|
6981
6931
|
function defaultScriptPath() {
|
|
6982
6932
|
const name = "caddis_hub_collect.py";
|
|
6983
6933
|
const bundle = bundlePath("antigravity-plugin", { requireManifest: false });
|
|
6984
6934
|
if (bundle) {
|
|
6985
|
-
const shipped =
|
|
6986
|
-
if (
|
|
6935
|
+
const shipped = path16.join(bundle, "scripts", name);
|
|
6936
|
+
if (existsSync8(shipped)) return shipped;
|
|
6987
6937
|
}
|
|
6988
|
-
|
|
6938
|
+
const root = path16.join(packageInfo().root, "..");
|
|
6939
|
+
const repoScript = path16.join(root, "scripts", name);
|
|
6940
|
+
const mirrorScript = path16.join(root, "bundles", "antigravity-plugin", "scripts", name);
|
|
6941
|
+
return !existsSync8(repoScript) && existsSync8(mirrorScript) ? mirrorScript : repoScript;
|
|
6989
6942
|
}
|
|
6990
6943
|
async function resolvePython() {
|
|
6991
6944
|
const py = await find("python");
|
|
@@ -7001,7 +6954,7 @@ async function resolvePython() {
|
|
|
7001
6954
|
function createCollectorSource(opts) {
|
|
7002
6955
|
const now = opts.now ?? Date.now;
|
|
7003
6956
|
const spawn2 = opts.spawn ?? spawnBounded;
|
|
7004
|
-
const
|
|
6957
|
+
const cache2 = /* @__PURE__ */ new Map();
|
|
7005
6958
|
let spend = null;
|
|
7006
6959
|
let guide = null;
|
|
7007
6960
|
let schema = COLLECTOR_SCHEMA;
|
|
@@ -7031,15 +6984,15 @@ function createCollectorSource(opts) {
|
|
|
7031
6984
|
schema = version;
|
|
7032
6985
|
generatedAt = typeof out.generated_at === "string" ? out.generated_at : "";
|
|
7033
6986
|
const keep = new Set(wanted);
|
|
7034
|
-
for (const key of [...
|
|
6987
|
+
for (const key of [...cache2.keys()]) if (!keep.has(key)) cache2.delete(key);
|
|
7035
6988
|
for (const entry of out.repos) {
|
|
7036
6989
|
if (!entry || typeof entry.path !== "string" || !keep.has(entry.path)) continue;
|
|
7037
|
-
const old =
|
|
6990
|
+
const old = cache2.get(entry.path);
|
|
7038
6991
|
if (entry.error !== void 0 || entry.fingerprint === void 0) {
|
|
7039
|
-
if (!old || old.error !== void 0)
|
|
6992
|
+
if (!old || old.error !== void 0) cache2.set(entry.path, entry);
|
|
7040
6993
|
continue;
|
|
7041
6994
|
}
|
|
7042
|
-
if (!old || old.error !== void 0 || old.fingerprint !== entry.fingerprint)
|
|
6995
|
+
if (!old || old.error !== void 0 || old.fingerprint !== entry.fingerprint) cache2.set(entry.path, entry);
|
|
7043
6996
|
}
|
|
7044
6997
|
const keepOrError = (next, old) => {
|
|
7045
6998
|
if (!next || typeof next !== "object") return old;
|
|
@@ -7064,7 +7017,7 @@ function createCollectorSource(opts) {
|
|
|
7064
7017
|
pre = found.pre;
|
|
7065
7018
|
}
|
|
7066
7019
|
const script = opts.scriptPath ?? defaultScriptPath();
|
|
7067
|
-
const args = repos.length ? [...pre, script, "--repos", ...repos, "--json"] : [...pre, script, "--repos",
|
|
7020
|
+
const args = repos.length ? [...pre, script, "--repos", ...repos, "--json"] : [...pre, script, "--repos", path16.join(os5.tmpdir(), "caddis-hub-no-repos"), "--only", "spend,guide", "--json"];
|
|
7068
7021
|
const result = await spawn2(cmd, args, { timeoutMs: RUN_TIMEOUT_MS2 });
|
|
7069
7022
|
if (result.timedOut) return fail2(`collector timed out after ${RUN_TIMEOUT_MS2 / 1e3} s`);
|
|
7070
7023
|
if (!result.ok) {
|
|
@@ -7096,7 +7049,7 @@ function createCollectorSource(opts) {
|
|
|
7096
7049
|
last_error: lastError,
|
|
7097
7050
|
stale: lastOkAt === null || now() - lastOkAt > STALE_AFTER_MS3,
|
|
7098
7051
|
update_needed: updateNeeded,
|
|
7099
|
-
data: hasData ? { schema, generated_at: generatedAt, repos: [...
|
|
7052
|
+
data: hasData ? { schema, generated_at: generatedAt, repos: [...cache2.values()], spend: spend ?? {}, guide: guide ?? {} } : null
|
|
7100
7053
|
};
|
|
7101
7054
|
}
|
|
7102
7055
|
};
|
|
@@ -7117,146 +7070,24 @@ var init_collector = __esm({
|
|
|
7117
7070
|
}
|
|
7118
7071
|
});
|
|
7119
7072
|
|
|
7120
|
-
// src/hub/sources/
|
|
7121
|
-
import {
|
|
7122
|
-
import
|
|
7123
|
-
function
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
schema,
|
|
7127
|
-
coordinator_session: null,
|
|
7128
|
-
heartbeat_at: null,
|
|
7129
|
-
queue: [],
|
|
7130
|
-
merging_now: null,
|
|
7131
|
-
deploy_checks: [],
|
|
7132
|
-
ledger: [],
|
|
7133
|
-
processed_requests: []
|
|
7134
|
-
};
|
|
7073
|
+
// src/hub/sources/github.ts
|
|
7074
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
7075
|
+
import path17 from "path";
|
|
7076
|
+
function parseGithubRemote(url) {
|
|
7077
|
+
const m2 = /^(?:https?:\/\/(?:[^@/]+@)?|ssh:\/\/git@|git@)github\.com[/:]([^/\s]+)\/([^/\s]+?)(?:\.git)?\/?$/i.exec(url.trim());
|
|
7078
|
+
return m2 ? `${m2[1]}/${m2[2]}` : null;
|
|
7135
7079
|
}
|
|
7136
|
-
function
|
|
7137
|
-
|
|
7080
|
+
function readOriginUrl(repoDir) {
|
|
7081
|
+
const root = repoPathFor(repoDir);
|
|
7082
|
+
if (!root) return null;
|
|
7083
|
+
let text2;
|
|
7138
7084
|
try {
|
|
7139
|
-
|
|
7140
|
-
} catch (e2) {
|
|
7141
|
-
return { error: `corrupt coordinator.json: ${e2.message}` };
|
|
7142
|
-
}
|
|
7143
|
-
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return { error: "coordinator.json is not a JSON object" };
|
|
7144
|
-
const o2 = raw;
|
|
7145
|
-
const schema = o2.schema;
|
|
7146
|
-
if (typeof schema !== "number" || !Number.isInteger(schema) || schema < COORDINATOR_SCHEMA - 1) {
|
|
7147
|
-
return { error: `coordinator.json has an unusable schema: ${String(schema)}` };
|
|
7148
|
-
}
|
|
7149
|
-
if (schema > COORDINATOR_SCHEMA) {
|
|
7150
|
-
return {
|
|
7151
|
-
newer: stub(repoId, schema),
|
|
7152
|
-
error: `coordinator schema ${schema} is newer than this hub (${COORDINATOR_SCHEMA}): update the hub`
|
|
7153
|
-
};
|
|
7154
|
-
}
|
|
7155
|
-
return {
|
|
7156
|
-
good: {
|
|
7157
|
-
repo_id: repoId,
|
|
7158
|
-
schema,
|
|
7159
|
-
coordinator_session: o2.coordinator_session ?? null,
|
|
7160
|
-
heartbeat_at: typeof o2.heartbeat_at === "string" ? o2.heartbeat_at : null,
|
|
7161
|
-
queue: arr(o2.queue),
|
|
7162
|
-
merging_now: o2.merging_now ?? null,
|
|
7163
|
-
deploy_checks: arr(o2.deploy_checks).slice(-5),
|
|
7164
|
-
ledger: arr(o2.ledger).slice(-20),
|
|
7165
|
-
processed_requests: arr(o2.processed_requests).slice(-20)
|
|
7166
|
-
}
|
|
7167
|
-
};
|
|
7168
|
-
}
|
|
7169
|
-
function hubHome(home) {
|
|
7170
|
-
const override = process.env.CADDIS_HUB_HOME;
|
|
7171
|
-
return override ? override : hubDir(home);
|
|
7172
|
-
}
|
|
7173
|
-
function createCoordinatorSource(opts = {}) {
|
|
7174
|
-
const now = opts.now ?? Date.now;
|
|
7175
|
-
const lastGood2 = /* @__PURE__ */ new Map();
|
|
7176
|
-
const errors = /* @__PURE__ */ new Map();
|
|
7177
|
-
return {
|
|
7178
|
-
refresh() {
|
|
7179
|
-
const root = path16.join(hubHome(opts.home), "repos");
|
|
7180
|
-
let ids = [];
|
|
7181
|
-
try {
|
|
7182
|
-
ids = readdirSync3(root, { withFileTypes: true }).filter((d3) => d3.isDirectory()).map((d3) => d3.name);
|
|
7183
|
-
} catch {
|
|
7184
|
-
}
|
|
7185
|
-
const seen = new Set(ids);
|
|
7186
|
-
for (const id of [...lastGood2.keys()]) if (!seen.has(id)) lastGood2.delete(id);
|
|
7187
|
-
for (const id of [...errors.keys()]) if (!seen.has(id)) errors.delete(id);
|
|
7188
|
-
for (const id of ids) {
|
|
7189
|
-
let text;
|
|
7190
|
-
try {
|
|
7191
|
-
text = readFileSync11(path16.join(root, id, "coordinator.json"), "utf8");
|
|
7192
|
-
} catch (e2) {
|
|
7193
|
-
if (e2.code === "ENOENT") {
|
|
7194
|
-
lastGood2.delete(id);
|
|
7195
|
-
errors.delete(id);
|
|
7196
|
-
} else {
|
|
7197
|
-
if (!lastGood2.has(id)) lastGood2.set(id, stub(id, null));
|
|
7198
|
-
errors.set(id, { error: `cannot read coordinator.json: ${e2.message}`, updateNeeded: false });
|
|
7199
|
-
}
|
|
7200
|
-
continue;
|
|
7201
|
-
}
|
|
7202
|
-
const r2 = parse3(id, text);
|
|
7203
|
-
if (r2.good) {
|
|
7204
|
-
lastGood2.set(id, r2.good);
|
|
7205
|
-
errors.delete(id);
|
|
7206
|
-
continue;
|
|
7207
|
-
}
|
|
7208
|
-
if (!lastGood2.has(id)) lastGood2.set(id, r2.newer ?? stub(id, null));
|
|
7209
|
-
errors.set(id, { error: r2.error ?? "unreadable", updateNeeded: r2.newer !== void 0 });
|
|
7210
|
-
}
|
|
7211
|
-
},
|
|
7212
|
-
get() {
|
|
7213
|
-
const t = now();
|
|
7214
|
-
const out = [];
|
|
7215
|
-
for (const [id, good] of lastGood2) {
|
|
7216
|
-
const ms = good.heartbeat_at ? Date.parse(good.heartbeat_at) : NaN;
|
|
7217
|
-
const age = Number.isNaN(ms) ? null : Math.max(0, Math.floor((t - ms) / 1e3));
|
|
7218
|
-
const err = errors.get(id);
|
|
7219
|
-
out.push({
|
|
7220
|
-
...good,
|
|
7221
|
-
heartbeat_age_s: age,
|
|
7222
|
-
responding: age !== null && age < RESPONDING_WITHIN_S,
|
|
7223
|
-
error: err?.error ?? null,
|
|
7224
|
-
update_needed: err?.updateNeeded ?? false
|
|
7225
|
-
});
|
|
7226
|
-
}
|
|
7227
|
-
return out.sort((a, b3) => a.repo_id.localeCompare(b3.repo_id));
|
|
7228
|
-
}
|
|
7229
|
-
};
|
|
7230
|
-
}
|
|
7231
|
-
var COORDINATOR_SCHEMA, RESPONDING_WITHIN_S, arr;
|
|
7232
|
-
var init_coordinator = __esm({
|
|
7233
|
-
"src/hub/sources/coordinator.ts"() {
|
|
7234
|
-
"use strict";
|
|
7235
|
-
init_paths();
|
|
7236
|
-
COORDINATOR_SCHEMA = 1;
|
|
7237
|
-
RESPONDING_WITHIN_S = 180;
|
|
7238
|
-
arr = (v2) => Array.isArray(v2) ? v2 : [];
|
|
7239
|
-
}
|
|
7240
|
-
});
|
|
7241
|
-
|
|
7242
|
-
// src/hub/sources/github.ts
|
|
7243
|
-
import { readFileSync as readFileSync12 } from "fs";
|
|
7244
|
-
import path17 from "path";
|
|
7245
|
-
function parseGithubRemote(url) {
|
|
7246
|
-
const m2 = /^(?:https?:\/\/(?:[^@/]+@)?|ssh:\/\/git@|git@)github\.com[/:]([^/\s]+)\/([^/\s]+?)(?:\.git)?\/?$/i.exec(url.trim());
|
|
7247
|
-
return m2 ? `${m2[1]}/${m2[2]}` : null;
|
|
7248
|
-
}
|
|
7249
|
-
function readOriginUrl(repoDir) {
|
|
7250
|
-
const root = repoPathFor(repoDir);
|
|
7251
|
-
if (!root) return null;
|
|
7252
|
-
let text;
|
|
7253
|
-
try {
|
|
7254
|
-
text = readFileSync12(path17.join(root, ".git", "config"), "utf8");
|
|
7085
|
+
text2 = readFileSync12(path17.join(root, ".git", "config"), "utf8");
|
|
7255
7086
|
} catch {
|
|
7256
7087
|
return null;
|
|
7257
7088
|
}
|
|
7258
7089
|
let inOrigin = false;
|
|
7259
|
-
for (const line2 of
|
|
7090
|
+
for (const line2 of text2.split(/\r?\n/)) {
|
|
7260
7091
|
const section = /^\s*\[(.+)\]\s*$/.exec(line2);
|
|
7261
7092
|
if (section) {
|
|
7262
7093
|
inOrigin = /^remote\s+"origin"$/.test(section[1] ?? "");
|
|
@@ -7269,8 +7100,8 @@ function readOriginUrl(repoDir) {
|
|
|
7269
7100
|
}
|
|
7270
7101
|
function readRequiredChecks(repoDir) {
|
|
7271
7102
|
try {
|
|
7272
|
-
const
|
|
7273
|
-
const m2 = /```json[^\S\r\n]*\r?\n([\s\S]*?)\r?\n[^\S\r\n]*```/.exec(
|
|
7103
|
+
const text2 = readFileSync12(path17.join(repoDir, ".caddis", "coordinator.md"), "utf8");
|
|
7104
|
+
const m2 = /```json[^\S\r\n]*\r?\n([\s\S]*?)\r?\n[^\S\r\n]*```/.exec(text2);
|
|
7274
7105
|
if (!m2) return null;
|
|
7275
7106
|
const parsed = JSON.parse(m2[1] ?? "");
|
|
7276
7107
|
if (!parsed || typeof parsed !== "object") return null;
|
|
@@ -7299,11 +7130,11 @@ async function defaultToken(spawn2, account) {
|
|
|
7299
7130
|
const token = r2.stdout.trim();
|
|
7300
7131
|
return r2.ok && token ? token : null;
|
|
7301
7132
|
}
|
|
7302
|
-
function parseAuthStatus(
|
|
7133
|
+
function parseAuthStatus(text2) {
|
|
7303
7134
|
const accounts = [];
|
|
7304
7135
|
let active = null;
|
|
7305
7136
|
let current = null;
|
|
7306
|
-
for (const line2 of
|
|
7137
|
+
for (const line2 of text2.split(/\r?\n/)) {
|
|
7307
7138
|
const m2 = /Logged in to (\S+) (?:account|as) (\S+)/.exec(line2);
|
|
7308
7139
|
if (m2) {
|
|
7309
7140
|
current = m2[1] === "github.com" ? m2[2] ?? null : null;
|
|
@@ -7407,17 +7238,17 @@ ${url}`;
|
|
|
7407
7238
|
const pulls = list(first);
|
|
7408
7239
|
const prs = [];
|
|
7409
7240
|
for (const p2 of pulls) {
|
|
7410
|
-
const head =
|
|
7241
|
+
const head = str3(rec2(p2.head).sha) ?? "";
|
|
7411
7242
|
const byName = /* @__PURE__ */ new Map();
|
|
7412
7243
|
if (head) {
|
|
7413
|
-
const body =
|
|
7244
|
+
const body = rec2(await getJson(account, token, `/repos/${repo}/commits/${head}/check-runs?per_page=100`));
|
|
7414
7245
|
for (const c of list(body.check_runs)) {
|
|
7415
|
-
const name =
|
|
7246
|
+
const name = str3(c.name);
|
|
7416
7247
|
if (!name) continue;
|
|
7417
7248
|
byName.set(name, {
|
|
7418
7249
|
name,
|
|
7419
|
-
status:
|
|
7420
|
-
conclusion:
|
|
7250
|
+
status: str3(c.status) ?? "unknown",
|
|
7251
|
+
conclusion: str3(c.conclusion),
|
|
7421
7252
|
required: required === null ? null : required.includes(name)
|
|
7422
7253
|
});
|
|
7423
7254
|
}
|
|
@@ -7425,12 +7256,12 @@ ${url}`;
|
|
|
7425
7256
|
const checks = [...byName.values()];
|
|
7426
7257
|
prs.push({
|
|
7427
7258
|
number: Number(p2.number),
|
|
7428
|
-
title:
|
|
7259
|
+
title: str3(p2.title) ?? "",
|
|
7429
7260
|
head_sha: head,
|
|
7430
|
-
author:
|
|
7261
|
+
author: str3(rec2(p2.user).login),
|
|
7431
7262
|
draft: p2.draft === true,
|
|
7432
|
-
updated_at:
|
|
7433
|
-
url:
|
|
7263
|
+
updated_at: str3(p2.updated_at),
|
|
7264
|
+
url: str3(p2.html_url) ?? "",
|
|
7434
7265
|
checks,
|
|
7435
7266
|
required_state: requiredState(checks, required)
|
|
7436
7267
|
});
|
|
@@ -7438,21 +7269,21 @@ ${url}`;
|
|
|
7438
7269
|
const closed = list(
|
|
7439
7270
|
await getJson(account, token, `/repos/${repo}/pulls?state=closed&sort=updated&direction=desc&per_page=20`)
|
|
7440
7271
|
);
|
|
7441
|
-
const merged = closed.filter((p2) =>
|
|
7272
|
+
const merged = closed.filter((p2) => str3(p2.merged_at) && str3(p2.merge_commit_sha)).sort((a, b3) => String(b3.merged_at).localeCompare(String(a.merged_at))).slice(0, MERGES_SHOWN);
|
|
7442
7273
|
const merges = [];
|
|
7443
7274
|
for (const p2 of merged) {
|
|
7444
|
-
const sha =
|
|
7445
|
-
const body =
|
|
7275
|
+
const sha = str3(p2.merge_commit_sha) ?? "";
|
|
7276
|
+
const body = rec2(await getJson(account, token, `/repos/${repo}/actions/runs?head_sha=${sha}&per_page=10`));
|
|
7446
7277
|
merges.push({
|
|
7447
7278
|
number: Number(p2.number),
|
|
7448
|
-
title:
|
|
7279
|
+
title: str3(p2.title) ?? "",
|
|
7449
7280
|
merge_sha: sha,
|
|
7450
|
-
merged_at:
|
|
7281
|
+
merged_at: str3(p2.merged_at) ?? "",
|
|
7451
7282
|
runs: list(body.workflow_runs).map((r2) => ({
|
|
7452
|
-
name:
|
|
7453
|
-
status:
|
|
7454
|
-
conclusion:
|
|
7455
|
-
url:
|
|
7283
|
+
name: str3(r2.name) ?? "",
|
|
7284
|
+
status: str3(r2.status) ?? "unknown",
|
|
7285
|
+
conclusion: str3(r2.conclusion),
|
|
7286
|
+
url: str3(r2.html_url) ?? ""
|
|
7456
7287
|
}))
|
|
7457
7288
|
});
|
|
7458
7289
|
}
|
|
@@ -7575,7 +7406,7 @@ ${url}`;
|
|
|
7575
7406
|
}
|
|
7576
7407
|
};
|
|
7577
7408
|
}
|
|
7578
|
-
var STALE_AFTER_MS4, POLL_MS2, SLOW_POLL_MS, RATE_RESERVE, API, TOKEN_TIMEOUT_MS, FIND_TIMEOUT_MS3, FETCH_TIMEOUT_MS, MERGES_SHOWN, FAILED, PASSED, HttpError,
|
|
7409
|
+
var STALE_AFTER_MS4, POLL_MS2, SLOW_POLL_MS, RATE_RESERVE, API, TOKEN_TIMEOUT_MS, FIND_TIMEOUT_MS3, FETCH_TIMEOUT_MS, MERGES_SHOWN, FAILED, PASSED, HttpError, str3, rec2, list, findGh;
|
|
7579
7410
|
var init_github = __esm({
|
|
7580
7411
|
"src/hub/sources/github.ts"() {
|
|
7581
7412
|
"use strict";
|
|
@@ -7606,15 +7437,15 @@ var init_github = __esm({
|
|
|
7606
7437
|
/** This token cannot see the repo: try the next account. */
|
|
7607
7438
|
access;
|
|
7608
7439
|
};
|
|
7609
|
-
|
|
7610
|
-
|
|
7611
|
-
list = (v2) => Array.isArray(v2) ? v2.map(
|
|
7440
|
+
str3 = (v2) => typeof v2 === "string" && v2 ? v2 : null;
|
|
7441
|
+
rec2 = (v2) => v2 && typeof v2 === "object" ? v2 : {};
|
|
7442
|
+
list = (v2) => Array.isArray(v2) ? v2.map(rec2) : [];
|
|
7612
7443
|
findGh = () => withTimeout(findBin("gh"), FIND_TIMEOUT_MS3, "finding gh");
|
|
7613
7444
|
}
|
|
7614
7445
|
});
|
|
7615
7446
|
|
|
7616
7447
|
// src/hub/state.ts
|
|
7617
|
-
import { createHash
|
|
7448
|
+
import { createHash } from "crypto";
|
|
7618
7449
|
import { readFileSync as readFileSync13 } from "fs";
|
|
7619
7450
|
import path18 from "path";
|
|
7620
7451
|
function repoIdFor(nameWithOwner) {
|
|
@@ -7622,7 +7453,7 @@ function repoIdFor(nameWithOwner) {
|
|
|
7622
7453
|
}
|
|
7623
7454
|
function localRepoId(repoPath) {
|
|
7624
7455
|
const norm = process.platform === "win32" ? repoPath.toLowerCase().replace(/\//g, "\\") : repoPath;
|
|
7625
|
-
const digest =
|
|
7456
|
+
const digest = createHash("sha256").update(norm, "utf8").digest("hex").slice(0, 6);
|
|
7626
7457
|
return `local__${path18.basename(repoPath)}__${digest}`;
|
|
7627
7458
|
}
|
|
7628
7459
|
function readPluginVersion(home) {
|
|
@@ -7644,6 +7475,72 @@ function defaultVersions(home) {
|
|
|
7644
7475
|
const pool = bundleManifest().poolVersion;
|
|
7645
7476
|
return { hub: packageInfo().version, pool: pool === "unknown" ? null : pool, plugin: readPluginVersion(home) };
|
|
7646
7477
|
}
|
|
7478
|
+
function safeRepoId(id) {
|
|
7479
|
+
if (!id || id === "." || id.includes("..") || /[/\\:]/.test(id) || /[. ]$/.test(id)) return false;
|
|
7480
|
+
return !RESERVED_NAMES.has(id.split(".", 1)[0].toLowerCase());
|
|
7481
|
+
}
|
|
7482
|
+
function repoActions(coordinator, repoId) {
|
|
7483
|
+
if (repoId !== void 0 && !safeRepoId(repoId)) return { enabled: false, code: "bad_repo_id", reason: BAD_REPO_ID_REASON };
|
|
7484
|
+
if (!coordinator) return { enabled: false, code: "no_coordinator", reason: NO_COORDINATOR_REASON };
|
|
7485
|
+
if (coordinator.update_needed) {
|
|
7486
|
+
return { enabled: false, code: "no_coordinator", reason: "The coordinator file is newer than this hub. Update the hub." };
|
|
7487
|
+
}
|
|
7488
|
+
if (coordinator.status === "stopped") return { enabled: false, code: "no_coordinator", reason: STOPPED_REASON };
|
|
7489
|
+
if (coordinator.status !== "live") return { enabled: false, code: "no_coordinator", reason: DOWN_REASON };
|
|
7490
|
+
return { enabled: true, code: "ok", reason: null };
|
|
7491
|
+
}
|
|
7492
|
+
function ownerItems(coordinator, relays, sessions) {
|
|
7493
|
+
const out = [];
|
|
7494
|
+
const whats = /* @__PURE__ */ new Set();
|
|
7495
|
+
const from = textOf(recOf(coordinator?.coordinator_session).name);
|
|
7496
|
+
for (const raw of coordinator?.owner_asks ?? []) {
|
|
7497
|
+
const a = recOf(raw);
|
|
7498
|
+
const id = textOf(a.id);
|
|
7499
|
+
const what = textOf(a.what);
|
|
7500
|
+
if (!id || !what || whats.has(what)) continue;
|
|
7501
|
+
const decision = a.recommendation === "approve" || a.recommendation === "hold" ? a.recommendation : null;
|
|
7502
|
+
whats.add(what);
|
|
7503
|
+
out.push({
|
|
7504
|
+
id: `ask:${id}`,
|
|
7505
|
+
what,
|
|
7506
|
+
pr: typeof a.pr === "number" && Number.isInteger(a.pr) ? a.pr : null,
|
|
7507
|
+
head_sha: textOf(a.head_sha),
|
|
7508
|
+
source: "coordinator",
|
|
7509
|
+
recommendation: decision ? { decision, reason: textOf(a.reason), evidence: textOf(a.evidence) } : null,
|
|
7510
|
+
from: textOf(a.from) ?? from,
|
|
7511
|
+
since: textOf(a.at)
|
|
7512
|
+
});
|
|
7513
|
+
}
|
|
7514
|
+
const decided = new Set(
|
|
7515
|
+
(coordinator?.ledger ?? []).map((e2) => textOf(recOf(e2).what)).filter((w2) => w2 !== null)
|
|
7516
|
+
);
|
|
7517
|
+
const list2 = Array.isArray(relays?.relays) ? relays.relays : [];
|
|
7518
|
+
for (const raw of list2) {
|
|
7519
|
+
const r2 = recOf(raw);
|
|
7520
|
+
const name = textOf(r2.name);
|
|
7521
|
+
const gate = textOf(r2.status_arg);
|
|
7522
|
+
if (r2.status !== "OWNER-GATE" || !name || !gate) continue;
|
|
7523
|
+
const what = gateWhat(gate, name);
|
|
7524
|
+
if (whats.has(what) || decided.has(what)) continue;
|
|
7525
|
+
whats.add(what);
|
|
7526
|
+
const rec4 = recOf(r2.recommendation);
|
|
7527
|
+
const decision = rec4.decision === "approve" || rec4.decision === "hold" ? rec4.decision : null;
|
|
7528
|
+
const sid = textOf(r2.session_id);
|
|
7529
|
+
const session = sid ? sessions.find((s) => s.session_id === sid) : void 0;
|
|
7530
|
+
out.push({
|
|
7531
|
+
id: `gate:${name}:${gate}`,
|
|
7532
|
+
what,
|
|
7533
|
+
pr: null,
|
|
7534
|
+
head_sha: null,
|
|
7535
|
+
source: "relay",
|
|
7536
|
+
recommendation: decision ? { decision, reason: textOf(rec4.reason), evidence: textOf(rec4.evidence) } : null,
|
|
7537
|
+
from: session?.name ?? name,
|
|
7538
|
+
since: textOf(r2.updated_at),
|
|
7539
|
+
relay: name
|
|
7540
|
+
});
|
|
7541
|
+
}
|
|
7542
|
+
return out;
|
|
7543
|
+
}
|
|
7647
7544
|
function createHub(opts = {}) {
|
|
7648
7545
|
const home = opts.home ?? caddisHome();
|
|
7649
7546
|
const now = opts.now ?? Date.now;
|
|
@@ -7752,94 +7649,690 @@ function createHub(opts = {}) {
|
|
|
7752
7649
|
const c = colByPath.get(k3);
|
|
7753
7650
|
const g2 = ghByPath.get(k3) ?? null;
|
|
7754
7651
|
const repoId = g2?.repo ? repoIdFor(g2.repo) : g2?.reason === "no github remote" ? localRepoId(p2) : void 0;
|
|
7652
|
+
const coordinator2 = repoId ? coordById.get(repoId) ?? null : null;
|
|
7653
|
+
const relays = c?.relays ?? null;
|
|
7755
7654
|
const out = {
|
|
7756
7655
|
path: p2,
|
|
7757
7656
|
name: path18.basename(p2),
|
|
7758
7657
|
pinned: pinned.has(k3),
|
|
7759
7658
|
roadmaps: c?.roadmaps ?? null,
|
|
7760
7659
|
plans: c?.plans ?? null,
|
|
7761
|
-
relays
|
|
7660
|
+
relays,
|
|
7762
7661
|
github: g2,
|
|
7763
|
-
coordinator:
|
|
7662
|
+
coordinator: coordinator2,
|
|
7663
|
+
owner_items: ownerItems(coordinator2, relays, ag.data ?? []),
|
|
7664
|
+
actions: repoActions(coordinator2, repoId)
|
|
7764
7665
|
};
|
|
7765
7666
|
if (repoId) out.repo_id = repoId;
|
|
7766
7667
|
if (c?.error !== void 0) out.error = c.error;
|
|
7767
7668
|
return out;
|
|
7768
7669
|
});
|
|
7769
|
-
const coordOkAt = coordinatorOkAt === null ? null : new Date(coordinatorOkAt).toISOString();
|
|
7770
|
-
return {
|
|
7771
|
-
schema: STATE_SCHEMA,
|
|
7772
|
-
generated_at: new Date(now()).toISOString(),
|
|
7773
|
-
versions: versions(),
|
|
7774
|
-
sources: {
|
|
7775
|
-
collector: status5("collector", col),
|
|
7776
|
-
agents: status5("agents", ag),
|
|
7777
|
-
github: status5("github", gh),
|
|
7778
|
-
coordinator: status5("coordinator", { ok: coordOkAt !== null, last_ok_at: coordOkAt, last_error: null })
|
|
7779
|
-
},
|
|
7780
|
-
update_needed: col.update_needed || coord.some((c) => c.update_needed),
|
|
7781
|
-
repos,
|
|
7782
|
-
sessions: ag.data ?? [],
|
|
7783
|
-
spend: col.data?.spend ?? null,
|
|
7784
|
-
guide: col.data?.guide ?? null
|
|
7785
|
-
|
|
7786
|
-
|
|
7670
|
+
const coordOkAt = coordinatorOkAt === null ? null : new Date(coordinatorOkAt).toISOString();
|
|
7671
|
+
return {
|
|
7672
|
+
schema: STATE_SCHEMA,
|
|
7673
|
+
generated_at: new Date(now()).toISOString(),
|
|
7674
|
+
versions: versions(),
|
|
7675
|
+
sources: {
|
|
7676
|
+
collector: status5("collector", col),
|
|
7677
|
+
agents: status5("agents", ag),
|
|
7678
|
+
github: status5("github", gh),
|
|
7679
|
+
coordinator: status5("coordinator", { ok: coordOkAt !== null, last_ok_at: coordOkAt, last_error: null })
|
|
7680
|
+
},
|
|
7681
|
+
update_needed: col.update_needed || coord.some((c) => c.update_needed),
|
|
7682
|
+
repos,
|
|
7683
|
+
sessions: ag.data ?? [],
|
|
7684
|
+
spend: col.data?.spend ?? null,
|
|
7685
|
+
guide: col.data?.guide ?? null,
|
|
7686
|
+
github_rate: gh.data?.rate ?? {},
|
|
7687
|
+
audit: readAudit(home)
|
|
7688
|
+
};
|
|
7689
|
+
};
|
|
7690
|
+
return {
|
|
7691
|
+
start() {
|
|
7692
|
+
if (running) return;
|
|
7693
|
+
running = true;
|
|
7694
|
+
schedule("coordinator", 0);
|
|
7695
|
+
const first = setTimeout(() => {
|
|
7696
|
+
timers.delete("agents");
|
|
7697
|
+
void refreshers.agents().finally(() => {
|
|
7698
|
+
schedule("agents", AGENTS_EVERY_MS);
|
|
7699
|
+
schedule("collector", 0);
|
|
7700
|
+
schedule("github", 0);
|
|
7701
|
+
});
|
|
7702
|
+
}, 0);
|
|
7703
|
+
first.unref();
|
|
7704
|
+
timers.set("agents", first);
|
|
7705
|
+
},
|
|
7706
|
+
stop() {
|
|
7707
|
+
running = false;
|
|
7708
|
+
for (const timer of timers.values()) clearTimeout(timer);
|
|
7709
|
+
timers.clear();
|
|
7710
|
+
},
|
|
7711
|
+
getState,
|
|
7712
|
+
async refreshAll() {
|
|
7713
|
+
await refreshers.agents();
|
|
7714
|
+
await refreshers.coordinator();
|
|
7715
|
+
await refreshers.collector();
|
|
7716
|
+
await refreshers.github();
|
|
7717
|
+
},
|
|
7718
|
+
repoPaths
|
|
7719
|
+
};
|
|
7720
|
+
}
|
|
7721
|
+
var STATE_SCHEMA, STALE_AFTER_MS5, COLLECTOR_EVERY_MS, AGENTS_EVERY_MS, COORDINATOR_EVERY_MS, VERSIONS_TTL_MS, REFRESH_CEILING_MS, message, NO_COORDINATOR_REASON, STOPPED_REASON, DOWN_REASON, RESERVED_NAMES, BAD_REPO_ID_REASON, recOf, textOf, gateWhat;
|
|
7722
|
+
var init_state = __esm({
|
|
7723
|
+
"src/hub/state.ts"() {
|
|
7724
|
+
"use strict";
|
|
7725
|
+
init_audit();
|
|
7726
|
+
init_config();
|
|
7727
|
+
init_agents();
|
|
7728
|
+
init_collector();
|
|
7729
|
+
init_coordinator();
|
|
7730
|
+
init_github();
|
|
7731
|
+
init_bounded();
|
|
7732
|
+
init_pkg();
|
|
7733
|
+
init_sessions();
|
|
7734
|
+
STATE_SCHEMA = 1;
|
|
7735
|
+
STALE_AFTER_MS5 = 3 * 6e4;
|
|
7736
|
+
COLLECTOR_EVERY_MS = 6e4;
|
|
7737
|
+
AGENTS_EVERY_MS = 3e4;
|
|
7738
|
+
COORDINATOR_EVERY_MS = 3e4;
|
|
7739
|
+
VERSIONS_TTL_MS = 6e4;
|
|
7740
|
+
REFRESH_CEILING_MS = {
|
|
7741
|
+
collector: 9e4,
|
|
7742
|
+
agents: 9e4,
|
|
7743
|
+
github: 3e5,
|
|
7744
|
+
coordinator: 9e4
|
|
7745
|
+
};
|
|
7746
|
+
message = (e2) => e2 instanceof Error ? e2.message : String(e2);
|
|
7747
|
+
NO_COORDINATOR_REASON = "No coordinator: each session merges its own PRs. Start one with /caddis:coordinate.";
|
|
7748
|
+
STOPPED_REASON = "The coordinator stopped. Start it again with /caddis:coordinate.";
|
|
7749
|
+
DOWN_REASON = "The coordinator is not responding. Actions wait until it is back.";
|
|
7750
|
+
RESERVED_NAMES = /* @__PURE__ */ new Set([
|
|
7751
|
+
"con",
|
|
7752
|
+
"prn",
|
|
7753
|
+
"aux",
|
|
7754
|
+
"nul",
|
|
7755
|
+
...Array.from({ length: 9 }, (_3, i) => `com${i + 1}`),
|
|
7756
|
+
...Array.from({ length: 9 }, (_3, i) => `lpt${i + 1}`)
|
|
7757
|
+
]);
|
|
7758
|
+
BAD_REPO_ID_REASON = "This repo id cannot name a hub folder, so the hub cannot send it actions.";
|
|
7759
|
+
recOf = (v2) => v2 && typeof v2 === "object" && !Array.isArray(v2) ? v2 : {};
|
|
7760
|
+
textOf = (v2) => typeof v2 === "string" && v2.trim() ? v2.trim() : null;
|
|
7761
|
+
gateWhat = (gate, relay) => `owner gate ${gate} (${relay})`;
|
|
7762
|
+
}
|
|
7763
|
+
});
|
|
7764
|
+
|
|
7765
|
+
// src/hub/actions.ts
|
|
7766
|
+
import { randomUUID } from "crypto";
|
|
7767
|
+
import path19 from "path";
|
|
7768
|
+
function parseBody(raw) {
|
|
7769
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new Refusal(400, "bad_request", "The body must be a JSON object.");
|
|
7770
|
+
const o2 = raw;
|
|
7771
|
+
for (const k3 of Object.keys(o2)) if (!BODY_KEYS.has(k3)) throw new Refusal(400, "bad_request", `Unknown key: ${k3.slice(0, 40)}.`);
|
|
7772
|
+
if (typeof o2.action !== "string" || !ACTIONS.includes(o2.action)) {
|
|
7773
|
+
throw new Refusal(400, "unknown_action", "This action is not in the v1 list.");
|
|
7774
|
+
}
|
|
7775
|
+
if (typeof o2.repo_id !== "string" || !o2.repo_id) throw new Refusal(400, "bad_request", "repo_id is missing.");
|
|
7776
|
+
const pr = o2.pr ?? null;
|
|
7777
|
+
if (pr !== null && (typeof pr !== "number" || !Number.isInteger(pr) || pr <= 0)) {
|
|
7778
|
+
throw new Refusal(400, "bad_request", "pr must be a positive integer.");
|
|
7779
|
+
}
|
|
7780
|
+
const head = o2.head_sha ?? null;
|
|
7781
|
+
if (head !== null && (typeof head !== "string" || !SHA.test(head))) {
|
|
7782
|
+
throw new Refusal(400, "bad_request", "head_sha must be a full 40-character SHA.");
|
|
7783
|
+
}
|
|
7784
|
+
if (pr === null !== (head === null)) throw new Refusal(400, "bad_request", "pr and head_sha go together.");
|
|
7785
|
+
const what = o2.what ?? null;
|
|
7786
|
+
if (what !== null && (typeof what !== "string" || !what.trim() || what.length > MAX_WHAT_CHARS)) {
|
|
7787
|
+
throw new Refusal(400, "bad_request", `what must be 1 to ${MAX_WHAT_CHARS} characters.`);
|
|
7788
|
+
}
|
|
7789
|
+
if (QUEUE_ACTIONS.has(o2.action) && (pr === null || what !== null)) {
|
|
7790
|
+
throw new Refusal(400, "bad_request", "A queue action names a PR and its head, and no what.");
|
|
7791
|
+
}
|
|
7792
|
+
if (!QUEUE_ACTIONS.has(o2.action) && what === null) throw new Refusal(400, "bad_request", "An approval names what it decides.");
|
|
7793
|
+
return { repo_id: o2.repo_id, action: o2.action, pr, head_sha: head, what: what === null ? null : what.trim() };
|
|
7794
|
+
}
|
|
7795
|
+
function check(state, b3) {
|
|
7796
|
+
const repo = state.repos.find((r2) => r2.repo_id === b3.repo_id);
|
|
7797
|
+
if (!repo || !safeRepoId(b3.repo_id)) throw new Refusal(404, "unknown_repo", "This repo is not in the hub registry.");
|
|
7798
|
+
const actions = repo.actions;
|
|
7799
|
+
if (!actions?.enabled) throw new Refusal(409, "no_coordinator", actions?.reason ?? "No live coordinator in this repo.");
|
|
7800
|
+
if (b3.pr !== null) {
|
|
7801
|
+
const pr = repo.github?.prs?.find((p2) => p2.number === b3.pr);
|
|
7802
|
+
if (!pr) throw new Refusal(409, "unknown_pr", `PR #${b3.pr} is not in the open PR list the hub has.`);
|
|
7803
|
+
if (pr.head_sha.toLowerCase() !== (b3.head_sha ?? "").toLowerCase()) {
|
|
7804
|
+
throw new Refusal(409, "head_moved", `The head of PR #${b3.pr} moved. Reload and check it again.`);
|
|
7805
|
+
}
|
|
7806
|
+
const queued = (repo.coordinator?.queue ?? []).some((q2) => q2?.pr === b3.pr);
|
|
7807
|
+
if (!queued) throw new Refusal(409, "not_in_queue", `PR #${b3.pr} is not in the coordinator queue.`);
|
|
7808
|
+
}
|
|
7809
|
+
if (b3.what !== null) {
|
|
7810
|
+
const item2 = (repo.owner_items ?? []).find((i) => i.what === b3.what && i.pr === b3.pr);
|
|
7811
|
+
if (!item2) throw new Refusal(409, "unknown_item", "This is not an open owner item of the repo.");
|
|
7812
|
+
if (item2.head_sha && b3.head_sha && item2.head_sha.toLowerCase() !== b3.head_sha.toLowerCase()) {
|
|
7813
|
+
throw new Refusal(409, "head_moved", "The PR head moved after the recommendation. Ask the coordinator again.");
|
|
7814
|
+
}
|
|
7815
|
+
}
|
|
7816
|
+
return repo;
|
|
7817
|
+
}
|
|
7818
|
+
function createActions(opts) {
|
|
7819
|
+
const now = opts.now ?? Date.now;
|
|
7820
|
+
const randomId = opts.randomId ?? randomUUID;
|
|
7821
|
+
const root = () => hubHome(opts.home);
|
|
7822
|
+
const auditFile = () => auditPath(opts.home);
|
|
7823
|
+
let recent = [];
|
|
7824
|
+
const audit = async (entry) => {
|
|
7825
|
+
try {
|
|
7826
|
+
await appendLine(auditFile(), JSON.stringify({ v: 1, at: utcSeconds(now()), ...entry }));
|
|
7827
|
+
} catch {
|
|
7828
|
+
}
|
|
7829
|
+
};
|
|
7830
|
+
const refuse = async (r2, b3) => {
|
|
7831
|
+
await audit({
|
|
7832
|
+
request_id: null,
|
|
7833
|
+
repo: typeof b3.repo_id === "string" ? b3.repo_id.slice(0, 120) : null,
|
|
7834
|
+
pr: typeof b3.pr === "number" ? b3.pr : null,
|
|
7835
|
+
action: typeof b3.action === "string" ? b3.action.slice(0, 20) : null,
|
|
7836
|
+
what: typeof b3.what === "string" ? b3.what.slice(0, MAX_WHAT_CHARS) : null,
|
|
7837
|
+
result: "refused",
|
|
7838
|
+
reason: r2.code
|
|
7839
|
+
});
|
|
7840
|
+
return { status: r2.status, body: { schema: 1, error: r2.code, reason: r2.reason } };
|
|
7841
|
+
};
|
|
7842
|
+
return {
|
|
7843
|
+
async submit(raw) {
|
|
7844
|
+
const t = now();
|
|
7845
|
+
recent = recent.filter((x2) => t - x2 < 6e4);
|
|
7846
|
+
if (recent.length >= MAX_ACTIONS_PER_MINUTE) {
|
|
7847
|
+
return { status: 429, body: { schema: 1, error: "rate_limited", reason: "Too many actions in one minute. Wait, then try again." } };
|
|
7848
|
+
}
|
|
7849
|
+
recent.push(t);
|
|
7850
|
+
let body;
|
|
7851
|
+
try {
|
|
7852
|
+
body = parseBody(raw);
|
|
7853
|
+
} catch (e2) {
|
|
7854
|
+
if (e2 instanceof Refusal) return refuse(e2, raw && typeof raw === "object" ? raw : {});
|
|
7855
|
+
throw e2;
|
|
7856
|
+
}
|
|
7857
|
+
try {
|
|
7858
|
+
check(await opts.getState(), body);
|
|
7859
|
+
} catch (e2) {
|
|
7860
|
+
if (e2 instanceof Refusal) return refuse(e2, body);
|
|
7861
|
+
return refuse(new Refusal(500, "state_failed", "The hub could not read its state."), body);
|
|
7862
|
+
}
|
|
7863
|
+
const request = {
|
|
7864
|
+
v: 1,
|
|
7865
|
+
id: randomId(),
|
|
7866
|
+
created_at: utcSeconds(t),
|
|
7867
|
+
expires_at: utcSeconds(t + REQUEST_LIFE_MS),
|
|
7868
|
+
repo: body.repo_id,
|
|
7869
|
+
pr: body.pr,
|
|
7870
|
+
head_sha: body.head_sha === null ? null : body.head_sha.toLowerCase(),
|
|
7871
|
+
action: body.action,
|
|
7872
|
+
args: body.what === null ? {} : { what: body.what }
|
|
7873
|
+
};
|
|
7874
|
+
try {
|
|
7875
|
+
await appendLine(path19.join(root(), "repos", body.repo_id, "requests.jsonl"), JSON.stringify(request));
|
|
7876
|
+
} catch {
|
|
7877
|
+
return refuse(new Refusal(500, "write_failed", "The hub could not write the request."), body);
|
|
7878
|
+
}
|
|
7879
|
+
await audit({
|
|
7880
|
+
request_id: request.id,
|
|
7881
|
+
repo: body.repo_id,
|
|
7882
|
+
pr: body.pr,
|
|
7883
|
+
action: body.action,
|
|
7884
|
+
what: body.what,
|
|
7885
|
+
result: "requested",
|
|
7886
|
+
reason: null
|
|
7887
|
+
});
|
|
7888
|
+
return { status: 202, body: { schema: 1, request } };
|
|
7889
|
+
}
|
|
7890
|
+
};
|
|
7891
|
+
}
|
|
7892
|
+
var ACTIONS, QUEUE_ACTIONS, REQUEST_LIFE_MS, MAX_ACTIONS_PER_MINUTE, MAX_ACTION_BODY_BYTES, MAX_WHAT_CHARS, BODY_KEYS, SHA, utcSeconds, Refusal;
|
|
7893
|
+
var init_actions = __esm({
|
|
7894
|
+
"src/hub/actions.ts"() {
|
|
7895
|
+
"use strict";
|
|
7896
|
+
init_append();
|
|
7897
|
+
init_paths();
|
|
7898
|
+
init_state();
|
|
7899
|
+
ACTIONS = ["hotfix", "unhotfix", "hold", "release", "approve", "decline"];
|
|
7900
|
+
QUEUE_ACTIONS = /* @__PURE__ */ new Set(["hotfix", "unhotfix", "hold", "release"]);
|
|
7901
|
+
REQUEST_LIFE_MS = 30 * 6e4;
|
|
7902
|
+
MAX_ACTIONS_PER_MINUTE = 20;
|
|
7903
|
+
MAX_ACTION_BODY_BYTES = 2 * 1024;
|
|
7904
|
+
MAX_WHAT_CHARS = 200;
|
|
7905
|
+
BODY_KEYS = /* @__PURE__ */ new Set(["repo_id", "action", "pr", "head_sha", "what"]);
|
|
7906
|
+
SHA = /^[0-9a-fA-F]{40}$/;
|
|
7907
|
+
utcSeconds = (ms) => new Date(ms).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
7908
|
+
Refusal = class {
|
|
7909
|
+
constructor(status5, code, reason) {
|
|
7910
|
+
this.status = status5;
|
|
7911
|
+
this.code = code;
|
|
7912
|
+
this.reason = reason;
|
|
7913
|
+
}
|
|
7914
|
+
status;
|
|
7915
|
+
code;
|
|
7916
|
+
reason;
|
|
7917
|
+
};
|
|
7918
|
+
}
|
|
7919
|
+
});
|
|
7920
|
+
|
|
7921
|
+
// src/hub/auth.ts
|
|
7922
|
+
import { createHash as createHash2, randomBytes as randomBytes3, timingSafeEqual } from "crypto";
|
|
7923
|
+
function randomToken() {
|
|
7924
|
+
return randomBytes3(32).toString("base64url");
|
|
7925
|
+
}
|
|
7926
|
+
function safeEqual(a, b3) {
|
|
7927
|
+
const ha = createHash2("sha256").update(a, "utf8").digest();
|
|
7928
|
+
const hb = createHash2("sha256").update(b3, "utf8").digest();
|
|
7929
|
+
return timingSafeEqual(ha, hb) && a.length === b3.length;
|
|
7930
|
+
}
|
|
7931
|
+
function hostAllowed(host, port) {
|
|
7932
|
+
if (!host) return false;
|
|
7933
|
+
const h2 = host.toLowerCase();
|
|
7934
|
+
return h2 === `127.0.0.1:${port}` || h2 === `localhost:${port}`;
|
|
7935
|
+
}
|
|
7936
|
+
function originAllowed(origin, port) {
|
|
7937
|
+
if (!origin) return false;
|
|
7938
|
+
return origin === `http://127.0.0.1:${port}` || origin === `http://localhost:${port}`;
|
|
7939
|
+
}
|
|
7940
|
+
function parseCookies(header) {
|
|
7941
|
+
const out = {};
|
|
7942
|
+
if (!header) return out;
|
|
7943
|
+
for (const part of header.split(";")) {
|
|
7944
|
+
const i = part.indexOf("=");
|
|
7945
|
+
if (i < 1) continue;
|
|
7946
|
+
const name = part.slice(0, i).trim();
|
|
7947
|
+
if (name && !(name in out)) out[name] = part.slice(i + 1).trim();
|
|
7948
|
+
}
|
|
7949
|
+
return out;
|
|
7950
|
+
}
|
|
7951
|
+
var CODE_TTL_MS, MAX_CODES, MAX_SESSIONS, SESSION_IDLE_MS, SESSION_MAX_MS, AuthStore;
|
|
7952
|
+
var init_auth = __esm({
|
|
7953
|
+
"src/hub/auth.ts"() {
|
|
7954
|
+
"use strict";
|
|
7955
|
+
CODE_TTL_MS = 6e4;
|
|
7956
|
+
MAX_CODES = 20;
|
|
7957
|
+
MAX_SESSIONS = 20;
|
|
7958
|
+
SESSION_IDLE_MS = 12 * 60 * 60 * 1e3;
|
|
7959
|
+
SESSION_MAX_MS = 24 * 60 * 60 * 1e3;
|
|
7960
|
+
AuthStore = class {
|
|
7961
|
+
constructor(now = Date.now) {
|
|
7962
|
+
this.now = now;
|
|
7963
|
+
}
|
|
7964
|
+
now;
|
|
7965
|
+
codes = [];
|
|
7966
|
+
sessions = [];
|
|
7967
|
+
/** Mint a single-use code. Expired codes are dropped first; then the oldest goes past the cap. */
|
|
7968
|
+
mintCode() {
|
|
7969
|
+
const t = this.now();
|
|
7970
|
+
this.codes = this.codes.filter((c) => t - c.mintedAt < CODE_TTL_MS);
|
|
7971
|
+
const value = randomToken();
|
|
7972
|
+
this.codes.push({ value, mintedAt: t });
|
|
7973
|
+
while (this.codes.length > MAX_CODES) this.codes.shift();
|
|
7974
|
+
return value;
|
|
7975
|
+
}
|
|
7976
|
+
/** Expiry time of a code minted now, as UTC ISO 8601. */
|
|
7977
|
+
codeExpiresAt() {
|
|
7978
|
+
return new Date(this.now() + CODE_TTL_MS).toISOString();
|
|
7979
|
+
}
|
|
7980
|
+
/**
|
|
7981
|
+
* Swap a code for a new session id. The code is removed before the age check,
|
|
7982
|
+
* so a code is consumed even when this call fails. Returns null on failure.
|
|
7983
|
+
*/
|
|
7984
|
+
redeemCode(code) {
|
|
7985
|
+
if (!code) return null;
|
|
7986
|
+
let found;
|
|
7987
|
+
for (const c of this.codes) if (safeEqual(c.value, code)) found = c;
|
|
7988
|
+
if (!found) return null;
|
|
7989
|
+
this.codes = this.codes.filter((c) => c !== found);
|
|
7990
|
+
const age = this.now() - found.mintedAt;
|
|
7991
|
+
if (age < 0 || age >= CODE_TTL_MS) return null;
|
|
7992
|
+
const t = this.now();
|
|
7993
|
+
const s = { id: randomToken(), csrf: randomToken(), tab: randomToken(), createdAt: t, lastSeenAt: t };
|
|
7994
|
+
this.sessions.push(s);
|
|
7995
|
+
while (this.sessions.length > MAX_SESSIONS) this.sessions.shift();
|
|
7996
|
+
return s.id;
|
|
7997
|
+
}
|
|
7998
|
+
/** Remove a code without making a session (a refused /login still uses up its code). */
|
|
7999
|
+
discardCode(code) {
|
|
8000
|
+
if (!code) return;
|
|
8001
|
+
this.codes = this.codes.filter((c) => !safeEqual(c.value, code));
|
|
8002
|
+
}
|
|
8003
|
+
/**
|
|
8004
|
+
* Find a live session and mark it used. A session past the idle TTL or the absolute TTL
|
|
8005
|
+
* is removed and the call returns null.
|
|
8006
|
+
*/
|
|
8007
|
+
getSession(id) {
|
|
8008
|
+
return this.findSession(id, null);
|
|
8009
|
+
}
|
|
8010
|
+
/**
|
|
8011
|
+
* As getSession, but the session's tab token must match too (constant time). A wrong or missing token
|
|
8012
|
+
* returns null and does not mark the session used.
|
|
8013
|
+
*/
|
|
8014
|
+
getTabSession(id, tab) {
|
|
8015
|
+
return this.findSession(id, tab ?? "");
|
|
8016
|
+
}
|
|
8017
|
+
findSession(id, tab) {
|
|
8018
|
+
if (!id) return null;
|
|
8019
|
+
let found = null;
|
|
8020
|
+
for (const s of this.sessions) if (safeEqual(s.id, id)) found = s;
|
|
8021
|
+
if (!found) return null;
|
|
8022
|
+
if (tab !== null && !safeEqual(found.tab, tab)) return null;
|
|
8023
|
+
const t = this.now();
|
|
8024
|
+
if (t - found.lastSeenAt >= SESSION_IDLE_MS || t - found.createdAt >= SESSION_MAX_MS) {
|
|
8025
|
+
this.sessions = this.sessions.filter((x2) => x2 !== found);
|
|
8026
|
+
return null;
|
|
8027
|
+
}
|
|
8028
|
+
found.lastSeenAt = t;
|
|
8029
|
+
return found;
|
|
8030
|
+
}
|
|
8031
|
+
deleteSession(id) {
|
|
8032
|
+
const s = this.getSession(id);
|
|
8033
|
+
if (s) this.sessions = this.sessions.filter((x2) => x2 !== s);
|
|
8034
|
+
}
|
|
8035
|
+
codeCount() {
|
|
8036
|
+
return this.codes.length;
|
|
8037
|
+
}
|
|
8038
|
+
sessionCount() {
|
|
8039
|
+
return this.sessions.length;
|
|
8040
|
+
}
|
|
8041
|
+
};
|
|
8042
|
+
}
|
|
8043
|
+
});
|
|
8044
|
+
|
|
8045
|
+
// src/hub/server.ts
|
|
8046
|
+
import http from "http";
|
|
8047
|
+
import { existsSync as existsSync9 } from "fs";
|
|
8048
|
+
import { readFile, stat } from "fs/promises";
|
|
8049
|
+
import path20 from "path";
|
|
8050
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
8051
|
+
function defaultUiDir() {
|
|
8052
|
+
const here = path20.dirname(fileURLToPath2(import.meta.url));
|
|
8053
|
+
const beside = path20.join(here, "ui");
|
|
8054
|
+
return existsSync9(beside) ? beside : path20.resolve(here, "..", "..", "dist", "ui");
|
|
8055
|
+
}
|
|
8056
|
+
function resolveStatic(root, urlPath) {
|
|
8057
|
+
let decoded;
|
|
8058
|
+
try {
|
|
8059
|
+
decoded = decodeURIComponent(urlPath);
|
|
8060
|
+
} catch {
|
|
8061
|
+
return null;
|
|
8062
|
+
}
|
|
8063
|
+
if (decoded.includes(String.fromCharCode(0)) || decoded.includes(String.fromCharCode(92))) return null;
|
|
8064
|
+
if (decoded.split("/").includes("..")) return null;
|
|
8065
|
+
const base = path20.resolve(root);
|
|
8066
|
+
const file = path20.resolve(base, "." + decoded);
|
|
8067
|
+
return file.startsWith(base + path20.sep) ? file : null;
|
|
8068
|
+
}
|
|
8069
|
+
function send(res, status5, body, extra = {}) {
|
|
8070
|
+
const text2 = JSON.stringify(body);
|
|
8071
|
+
res.writeHead(status5, {
|
|
8072
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
8073
|
+
"Content-Length": Buffer.byteLength(text2),
|
|
8074
|
+
...extra
|
|
8075
|
+
});
|
|
8076
|
+
res.end(text2);
|
|
8077
|
+
}
|
|
8078
|
+
function readBody(req, limit = MAX_BODY_BYTES) {
|
|
8079
|
+
return new Promise((resolve, reject) => {
|
|
8080
|
+
const declared = Number(req.headers["content-length"] ?? 0);
|
|
8081
|
+
if (declared > limit) {
|
|
8082
|
+
reject(new BodyTooLarge());
|
|
8083
|
+
return;
|
|
8084
|
+
}
|
|
8085
|
+
const chunks = [];
|
|
8086
|
+
let size = 0;
|
|
8087
|
+
let done = false;
|
|
8088
|
+
req.on("data", (c) => {
|
|
8089
|
+
if (done) return;
|
|
8090
|
+
size += c.length;
|
|
8091
|
+
if (size > limit) {
|
|
8092
|
+
done = true;
|
|
8093
|
+
reject(new BodyTooLarge());
|
|
8094
|
+
return;
|
|
8095
|
+
}
|
|
8096
|
+
chunks.push(c);
|
|
8097
|
+
});
|
|
8098
|
+
req.on("end", () => {
|
|
8099
|
+
if (!done) resolve(Buffer.concat(chunks));
|
|
8100
|
+
});
|
|
8101
|
+
req.on("error", (e2) => {
|
|
8102
|
+
if (!done) reject(e2);
|
|
8103
|
+
});
|
|
8104
|
+
});
|
|
8105
|
+
}
|
|
8106
|
+
function tooLarge(req, res) {
|
|
8107
|
+
res.on("finish", () => req.socket.destroy());
|
|
8108
|
+
fail(res, 413, "body_too_large");
|
|
8109
|
+
}
|
|
8110
|
+
async function serveStatic(res, uiDir, urlPath) {
|
|
8111
|
+
const rel = urlPath === "/" ? "/index.html" : urlPath;
|
|
8112
|
+
const file = resolveStatic(uiDir, rel);
|
|
8113
|
+
if (!file) return fail(res, 404, "not_found");
|
|
8114
|
+
let body;
|
|
8115
|
+
try {
|
|
8116
|
+
if (!(await stat(file)).isFile()) return fail(res, 404, "not_found");
|
|
8117
|
+
body = await readFile(file);
|
|
8118
|
+
} catch {
|
|
8119
|
+
if (urlPath === "/") {
|
|
8120
|
+
res.writeHead(503, {
|
|
8121
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
8122
|
+
"Content-Length": Buffer.byteLength(NOT_BUILT_HTML),
|
|
8123
|
+
"Cache-Control": "no-store"
|
|
8124
|
+
});
|
|
8125
|
+
res.end(NOT_BUILT_HTML);
|
|
8126
|
+
return;
|
|
8127
|
+
}
|
|
8128
|
+
return fail(res, 404, "not_found");
|
|
8129
|
+
}
|
|
8130
|
+
res.writeHead(200, {
|
|
8131
|
+
"Content-Type": MIME[path20.extname(file).toLowerCase()] ?? "application/octet-stream",
|
|
8132
|
+
"Content-Length": body.length,
|
|
8133
|
+
"Cache-Control": urlPath === "/" ? "no-store" : "public, max-age=31536000, immutable"
|
|
8134
|
+
});
|
|
8135
|
+
res.end(body);
|
|
8136
|
+
}
|
|
8137
|
+
function keyOk(req, key) {
|
|
8138
|
+
const v2 = req.headers[KEY_HEADER];
|
|
8139
|
+
return typeof v2 === "string" && safeEqual(v2, key);
|
|
8140
|
+
}
|
|
8141
|
+
async function startServer(opts) {
|
|
8142
|
+
const host = opts.host ?? "127.0.0.1";
|
|
8143
|
+
if (host !== "127.0.0.1") throw new Error("the hub server binds 127.0.0.1 only");
|
|
8144
|
+
if (typeof opts.key !== "string" || Buffer.byteLength(opts.key, "utf8") < MIN_KEY_BYTES) {
|
|
8145
|
+
throw new Error(`the hub server key must be at least ${MIN_KEY_BYTES} bytes`);
|
|
8146
|
+
}
|
|
8147
|
+
const auth = new AuthStore(opts.now ?? Date.now);
|
|
8148
|
+
const { key, versions } = opts;
|
|
8149
|
+
const uiDir = opts.uiDir ?? defaultUiDir();
|
|
8150
|
+
let port = opts.port;
|
|
8151
|
+
const sessionOf = (req) => auth.getSession(parseCookies(req.headers.cookie)[SESSION_COOKIE]);
|
|
8152
|
+
const tabSessionOf = (req) => {
|
|
8153
|
+
const tab = req.headers[TAB_HEADER];
|
|
8154
|
+
return auth.getTabSession(parseCookies(req.headers.cookie)[SESSION_COOKIE], typeof tab === "string" ? tab : "");
|
|
8155
|
+
};
|
|
8156
|
+
async function handle(req, res) {
|
|
8157
|
+
res.setHeader("Content-Security-Policy", CSP);
|
|
8158
|
+
res.setHeader("X-Content-Type-Options", "nosniff");
|
|
8159
|
+
res.setHeader("Referrer-Policy", "no-referrer");
|
|
8160
|
+
let url;
|
|
8161
|
+
try {
|
|
8162
|
+
url = new URL(req.url ?? "/", "http://127.0.0.1");
|
|
8163
|
+
} catch {
|
|
8164
|
+
fail(res, 400, "bad_url");
|
|
8165
|
+
return;
|
|
8166
|
+
}
|
|
8167
|
+
const path24 = url.pathname;
|
|
8168
|
+
const method = req.method ?? "GET";
|
|
8169
|
+
if (path24.startsWith("/api/") || path24 === "/login") res.setHeader("Cache-Control", "no-store");
|
|
8170
|
+
if (!hostAllowed(req.headers.host, port)) {
|
|
8171
|
+
if (path24 === "/login") auth.discardCode(url.searchParams.get("code") ?? "");
|
|
8172
|
+
fail(res, 403, "bad_host");
|
|
8173
|
+
return;
|
|
8174
|
+
}
|
|
8175
|
+
if (path24 === "/api/hub/whoami" && method === "GET") {
|
|
8176
|
+
if (!opts.instance) return fail(res, 404, "not_found");
|
|
8177
|
+
return send(res, 200, { instance: opts.instance });
|
|
8178
|
+
}
|
|
8179
|
+
if (path24 === "/api/health" && method === "GET") {
|
|
8180
|
+
if (!keyOk(req, key)) return fail(res, 401, "unauthorized");
|
|
8181
|
+
return send(res, 200, { schema: 1, ok: true, versions });
|
|
8182
|
+
}
|
|
8183
|
+
if (path24 === "/api/hub/code" && method === "POST") {
|
|
8184
|
+
if (!keyOk(req, key)) return fail(res, 401, "unauthorized");
|
|
8185
|
+
try {
|
|
8186
|
+
await readBody(req);
|
|
8187
|
+
} catch (e2) {
|
|
8188
|
+
if (e2 instanceof BodyTooLarge) return tooLarge(req, res);
|
|
8189
|
+
throw e2;
|
|
8190
|
+
}
|
|
8191
|
+
const code = auth.mintCode();
|
|
8192
|
+
return send(res, 200, { schema: 1, code, expires_at: auth.codeExpiresAt() });
|
|
8193
|
+
}
|
|
8194
|
+
if (path24 === "/api/hub/stop" && method === "POST") {
|
|
8195
|
+
if (!keyOk(req, key)) return fail(res, 401, "unauthorized");
|
|
8196
|
+
try {
|
|
8197
|
+
await readBody(req);
|
|
8198
|
+
} catch (e2) {
|
|
8199
|
+
if (e2 instanceof BodyTooLarge) return tooLarge(req, res);
|
|
8200
|
+
throw e2;
|
|
8201
|
+
}
|
|
8202
|
+
res.on("finish", () => opts.onStop?.());
|
|
8203
|
+
return send(res, 200, { schema: 1, ok: true });
|
|
8204
|
+
}
|
|
8205
|
+
if (method !== "GET") {
|
|
8206
|
+
const origin = req.headers.origin;
|
|
8207
|
+
if (!originAllowed(typeof origin === "string" ? origin : void 0, port)) return fail(res, 403, "bad_origin");
|
|
8208
|
+
const session = sessionOf(req);
|
|
8209
|
+
if (!session) return fail(res, 401, "unauthorized");
|
|
8210
|
+
const token = req.headers[CSRF_HEADER];
|
|
8211
|
+
if (typeof token !== "string" || !safeEqual(token, session.csrf)) return fail(res, 403, "bad_csrf");
|
|
8212
|
+
if (path24 === "/api/actions" && method === "POST" && opts.actions) {
|
|
8213
|
+
if (!tabSessionOf(req)) return fail(res, 401, "unauthorized");
|
|
8214
|
+
const type = String(req.headers["content-type"] ?? "").split(";")[0]?.trim().toLowerCase();
|
|
8215
|
+
if (type !== "application/json") return fail(res, 415, "json_only");
|
|
8216
|
+
let raw;
|
|
8217
|
+
try {
|
|
8218
|
+
raw = await readBody(req, MAX_ACTION_BODY_BYTES);
|
|
8219
|
+
} catch (e2) {
|
|
8220
|
+
if (e2 instanceof BodyTooLarge) return tooLarge(req, res);
|
|
8221
|
+
throw e2;
|
|
8222
|
+
}
|
|
8223
|
+
let body;
|
|
8224
|
+
try {
|
|
8225
|
+
body = JSON.parse(raw.toString("utf8"));
|
|
8226
|
+
} catch {
|
|
8227
|
+
return fail(res, 400, "bad_json");
|
|
8228
|
+
}
|
|
8229
|
+
const reply = await opts.actions.submit(body);
|
|
8230
|
+
return send(res, reply.status, reply.body);
|
|
8231
|
+
}
|
|
8232
|
+
try {
|
|
8233
|
+
await readBody(req);
|
|
8234
|
+
} catch (e2) {
|
|
8235
|
+
if (e2 instanceof BodyTooLarge) return tooLarge(req, res);
|
|
8236
|
+
throw e2;
|
|
8237
|
+
}
|
|
8238
|
+
if (path24 === "/api/logout" && method === "POST") {
|
|
8239
|
+
auth.deleteSession(session.id);
|
|
8240
|
+
return send(res, 200, { schema: 1, ok: true }, {
|
|
8241
|
+
"Set-Cookie": `${SESSION_COOKIE}=; HttpOnly; SameSite=Strict; Path=/; Max-Age=0`
|
|
8242
|
+
});
|
|
8243
|
+
}
|
|
8244
|
+
return fail(res, 404, "not_found");
|
|
8245
|
+
}
|
|
8246
|
+
if (path24 === "/" || path24.startsWith("/assets/") || path24.startsWith("/fonts/")) {
|
|
8247
|
+
await serveStatic(res, uiDir, path24);
|
|
8248
|
+
return;
|
|
8249
|
+
}
|
|
8250
|
+
if (path24 === "/login") {
|
|
8251
|
+
const id = auth.redeemCode(url.searchParams.get("code") ?? "");
|
|
8252
|
+
const session = id ? auth.getSession(id) : null;
|
|
8253
|
+
if (!id || !session) return fail(res, 401, "bad_code");
|
|
8254
|
+
res.writeHead(303, {
|
|
8255
|
+
Location: `/#tab=${session.tab}`,
|
|
8256
|
+
"Set-Cookie": `${SESSION_COOKIE}=${id}; HttpOnly; SameSite=Strict; Path=/`,
|
|
8257
|
+
"Content-Length": 0
|
|
8258
|
+
});
|
|
8259
|
+
res.end();
|
|
8260
|
+
return;
|
|
8261
|
+
}
|
|
8262
|
+
if (path24 === "/api/session") {
|
|
8263
|
+
const session = tabSessionOf(req);
|
|
8264
|
+
if (!session) return fail(res, 401, "unauthorized");
|
|
8265
|
+
return send(res, 200, { schema: 1, csrf_token: session.csrf, versions });
|
|
8266
|
+
}
|
|
8267
|
+
if (path24 === "/api/state") {
|
|
8268
|
+
if (!tabSessionOf(req)) return fail(res, 401, "unauthorized");
|
|
8269
|
+
let state;
|
|
8270
|
+
try {
|
|
8271
|
+
state = await opts.getState();
|
|
8272
|
+
} catch {
|
|
8273
|
+
return fail(res, 500, "state_failed");
|
|
8274
|
+
}
|
|
8275
|
+
return send(res, 200, state);
|
|
8276
|
+
}
|
|
8277
|
+
return fail(res, 404, "not_found");
|
|
8278
|
+
}
|
|
8279
|
+
const server = http.createServer((req, res) => {
|
|
8280
|
+
handle(req, res).catch(() => {
|
|
8281
|
+
if (!res.headersSent) fail(res, 500, "internal");
|
|
8282
|
+
else res.destroy();
|
|
8283
|
+
});
|
|
8284
|
+
});
|
|
8285
|
+
server.headersTimeout = 1e4;
|
|
8286
|
+
server.requestTimeout = 15e3;
|
|
8287
|
+
await new Promise((resolve, reject) => {
|
|
8288
|
+
const onError = (e2) => reject(e2);
|
|
8289
|
+
server.once("error", onError);
|
|
8290
|
+
server.listen(opts.port, host, () => {
|
|
8291
|
+
server.off("error", onError);
|
|
8292
|
+
resolve();
|
|
8293
|
+
});
|
|
8294
|
+
});
|
|
8295
|
+
const addr = server.address();
|
|
8296
|
+
port = addr.port;
|
|
7787
8297
|
return {
|
|
7788
|
-
|
|
7789
|
-
|
|
7790
|
-
|
|
7791
|
-
|
|
7792
|
-
|
|
7793
|
-
|
|
7794
|
-
void refreshers.agents().finally(() => {
|
|
7795
|
-
schedule("agents", AGENTS_EVERY_MS);
|
|
7796
|
-
schedule("collector", 0);
|
|
7797
|
-
schedule("github", 0);
|
|
7798
|
-
});
|
|
7799
|
-
}, 0);
|
|
7800
|
-
first.unref();
|
|
7801
|
-
timers.set("agents", first);
|
|
7802
|
-
},
|
|
7803
|
-
stop() {
|
|
7804
|
-
running = false;
|
|
7805
|
-
for (const timer of timers.values()) clearTimeout(timer);
|
|
7806
|
-
timers.clear();
|
|
7807
|
-
},
|
|
7808
|
-
getState,
|
|
7809
|
-
async refreshAll() {
|
|
7810
|
-
await refreshers.agents();
|
|
7811
|
-
await refreshers.coordinator();
|
|
7812
|
-
await refreshers.collector();
|
|
7813
|
-
await refreshers.github();
|
|
7814
|
-
},
|
|
7815
|
-
repoPaths
|
|
8298
|
+
port,
|
|
8299
|
+
address: addr.address,
|
|
8300
|
+
close: () => new Promise((resolve) => {
|
|
8301
|
+
server.close(() => resolve());
|
|
8302
|
+
server.closeAllConnections();
|
|
8303
|
+
})
|
|
7816
8304
|
};
|
|
7817
8305
|
}
|
|
7818
|
-
var
|
|
7819
|
-
var
|
|
7820
|
-
"src/hub/
|
|
8306
|
+
var SESSION_COOKIE, KEY_HEADER, CSRF_HEADER, TAB_HEADER, MAX_BODY_BYTES, MIN_KEY_BYTES, CSP, NOT_BUILT_HTML, MIME, BodyTooLarge, fail;
|
|
8307
|
+
var init_server = __esm({
|
|
8308
|
+
"src/hub/server.ts"() {
|
|
7821
8309
|
"use strict";
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
|
|
7825
|
-
|
|
7826
|
-
|
|
7827
|
-
|
|
7828
|
-
|
|
7829
|
-
|
|
7830
|
-
|
|
7831
|
-
|
|
7832
|
-
|
|
7833
|
-
|
|
7834
|
-
|
|
7835
|
-
|
|
7836
|
-
|
|
7837
|
-
|
|
7838
|
-
|
|
7839
|
-
|
|
7840
|
-
|
|
8310
|
+
init_actions();
|
|
8311
|
+
init_auth();
|
|
8312
|
+
SESSION_COOKIE = "caddis_hub_session";
|
|
8313
|
+
KEY_HEADER = "x-caddis-hub-key";
|
|
8314
|
+
CSRF_HEADER = "x-csrf-token";
|
|
8315
|
+
TAB_HEADER = "x-caddis-hub-tab";
|
|
8316
|
+
MAX_BODY_BYTES = 16 * 1024;
|
|
8317
|
+
MIN_KEY_BYTES = 32;
|
|
8318
|
+
CSP = "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'self'";
|
|
8319
|
+
NOT_BUILT_HTML = '<!doctype html><html lang="en"><head><meta charset="utf-8"><title>caddis hub</title></head><body>UI not built: run npm run build</body></html>';
|
|
8320
|
+
MIME = {
|
|
8321
|
+
".html": "text/html; charset=utf-8",
|
|
8322
|
+
".js": "text/javascript; charset=utf-8",
|
|
8323
|
+
".mjs": "text/javascript; charset=utf-8",
|
|
8324
|
+
".css": "text/css; charset=utf-8",
|
|
8325
|
+
".json": "application/json; charset=utf-8",
|
|
8326
|
+
".svg": "image/svg+xml",
|
|
8327
|
+
".png": "image/png",
|
|
8328
|
+
".ico": "image/x-icon",
|
|
8329
|
+
".woff2": "font/woff2",
|
|
8330
|
+
".txt": "text/plain; charset=utf-8",
|
|
8331
|
+
".map": "application/json; charset=utf-8"
|
|
7841
8332
|
};
|
|
7842
|
-
|
|
8333
|
+
BodyTooLarge = class extends Error {
|
|
8334
|
+
};
|
|
8335
|
+
fail = (res, status5, error) => send(res, status5, { schema: 1, error });
|
|
7843
8336
|
}
|
|
7844
8337
|
});
|
|
7845
8338
|
|
|
@@ -7860,7 +8353,7 @@ __export(hub_exports, {
|
|
|
7860
8353
|
startHub: () => startHub
|
|
7861
8354
|
});
|
|
7862
8355
|
import http2 from "http";
|
|
7863
|
-
import
|
|
8356
|
+
import path21 from "path";
|
|
7864
8357
|
import { mkdirSync as mkdirSync7, readFileSync as readFileSync14 } from "fs";
|
|
7865
8358
|
import { randomBytes as randomBytes4 } from "crypto";
|
|
7866
8359
|
function defaultVersions2() {
|
|
@@ -7946,7 +8439,7 @@ async function isNodeProcess(pid) {
|
|
|
7946
8439
|
if (!r2.ok) return false;
|
|
7947
8440
|
const name = (r2.stdout.split(/\r?\n/)[0] ?? "").replace(/^"([^"]*)".*$/, "$1").trim().toLowerCase();
|
|
7948
8441
|
if (!name) return false;
|
|
7949
|
-
const runtime =
|
|
8442
|
+
const runtime = path21.basename(process.execPath).toLowerCase().replace(/\.exe$/, "");
|
|
7950
8443
|
return name.includes("node") || name.includes(runtime);
|
|
7951
8444
|
}
|
|
7952
8445
|
async function defaultOpener(url) {
|
|
@@ -7961,8 +8454,8 @@ async function processStartMs(pid) {
|
|
|
7961
8454
|
{ timeout: TOOL_TIMEOUT_MS }
|
|
7962
8455
|
) : await run("ps", ["-o", "lstart=", "-p", String(pid)], { timeout: TOOL_TIMEOUT_MS, env: { LC_ALL: "C" } });
|
|
7963
8456
|
if (!r2.ok) return null;
|
|
7964
|
-
const
|
|
7965
|
-
const t = Date.parse(
|
|
8457
|
+
const text2 = r2.stdout.trim().replace(/(\.\d{3})\d+/, "$1");
|
|
8458
|
+
const t = Date.parse(text2);
|
|
7966
8459
|
return Number.isNaN(t) ? null : t;
|
|
7967
8460
|
}
|
|
7968
8461
|
async function whoami(port) {
|
|
@@ -8031,6 +8524,7 @@ async function startHub(deps = {}) {
|
|
|
8031
8524
|
port,
|
|
8032
8525
|
key,
|
|
8033
8526
|
getState: () => state.getState(),
|
|
8527
|
+
actions: createActions({ home, getState: () => state.getState(), now }),
|
|
8034
8528
|
versions: deps.versions ?? defaultVersions2(),
|
|
8035
8529
|
now,
|
|
8036
8530
|
instance: info.instance,
|
|
@@ -8076,7 +8570,7 @@ async function hubServe(deps = {}) {
|
|
|
8076
8570
|
process.once("exit", onExit);
|
|
8077
8571
|
line(`caddis hub serving on ${hubUrl(hub2.port)} (pid ${process.pid}); stop it with: caddis hub stop`);
|
|
8078
8572
|
const pkgRoot = packageInfo().root;
|
|
8079
|
-
const newEntry =
|
|
8573
|
+
const newEntry = path21.join(pkgRoot, "dist", "cli.js");
|
|
8080
8574
|
const runningVersion = (deps.versions ?? defaultVersions2()).cli ?? packageInfo().version;
|
|
8081
8575
|
const restarter = createRestarter({
|
|
8082
8576
|
currentVersion: runningVersion,
|
|
@@ -8330,6 +8824,7 @@ var init_hub = __esm({
|
|
|
8330
8824
|
init_lock();
|
|
8331
8825
|
init_paths();
|
|
8332
8826
|
init_restart();
|
|
8827
|
+
init_actions();
|
|
8333
8828
|
init_server();
|
|
8334
8829
|
init_state();
|
|
8335
8830
|
init_exec();
|
|
@@ -8361,6 +8856,534 @@ var init_hub = __esm({
|
|
|
8361
8856
|
}
|
|
8362
8857
|
});
|
|
8363
8858
|
|
|
8859
|
+
// src/hub/export/data.ts
|
|
8860
|
+
function blocker(raw) {
|
|
8861
|
+
const b3 = rec3(raw);
|
|
8862
|
+
return { type: str4(b3.type), reason: str4(b3.reason), check: str4(b3.check) };
|
|
8863
|
+
}
|
|
8864
|
+
function phase(raw) {
|
|
8865
|
+
const p2 = rec3(raw);
|
|
8866
|
+
return {
|
|
8867
|
+
ref: str4(p2.ref),
|
|
8868
|
+
state: str4(p2.state),
|
|
8869
|
+
plan: str4(p2.plan),
|
|
8870
|
+
num: int(p2.num),
|
|
8871
|
+
name: str4(p2.name),
|
|
8872
|
+
model: str4(p2.model),
|
|
8873
|
+
lane: str4(p2.lane),
|
|
8874
|
+
risk: str4(p2.risk),
|
|
8875
|
+
tracker: str4(p2.tracker),
|
|
8876
|
+
tile: str4(p2.tile),
|
|
8877
|
+
prs: arr2(p2.prs).filter((n) => typeof n === "number" && Number.isInteger(n) && n > 0)
|
|
8878
|
+
};
|
|
8879
|
+
}
|
|
8880
|
+
function milestone(raw) {
|
|
8881
|
+
const m2 = rec3(raw);
|
|
8882
|
+
return {
|
|
8883
|
+
id: str4(m2.id),
|
|
8884
|
+
status: str4(m2.status),
|
|
8885
|
+
owner: str4(m2.owner),
|
|
8886
|
+
target: strOrNull(m2.target),
|
|
8887
|
+
depends: arr2(m2.depends).filter((d3) => typeof d3 === "string"),
|
|
8888
|
+
blockers: arr2(m2.blockers).map(blocker),
|
|
8889
|
+
phases: arr2(m2.phases).map(phase)
|
|
8890
|
+
};
|
|
8891
|
+
}
|
|
8892
|
+
function roadmap(raw) {
|
|
8893
|
+
const r2 = rec3(raw);
|
|
8894
|
+
if (r2.error !== void 0) return { roadmap: str4(r2.roadmap), error: ERROR_TEXT };
|
|
8895
|
+
const next = rec3(r2.next);
|
|
8896
|
+
const out = {
|
|
8897
|
+
roadmap: str4(r2.roadmap),
|
|
8898
|
+
branch: strOrNull(r2.branch),
|
|
8899
|
+
origin_commit: shortSha(r2.origin_commit),
|
|
8900
|
+
done: int(r2.done),
|
|
8901
|
+
total: int(r2.total),
|
|
8902
|
+
next: Object.keys(next).length ? { milestone: str4(next.milestone), plan: str4(next.plan), phase: int(next.phase) } : null,
|
|
8903
|
+
lanes: arr2(r2.lanes).filter((l2) => typeof l2 === "string"),
|
|
8904
|
+
waiting: arr2(r2.waiting).map((w2) => {
|
|
8905
|
+
const x2 = rec3(w2);
|
|
8906
|
+
return { milestone: str4(x2.milestone), reason: str4(x2.reason), check: str4(x2.check) };
|
|
8907
|
+
}),
|
|
8908
|
+
milestones: arr2(r2.milestones).map(milestone)
|
|
8909
|
+
};
|
|
8910
|
+
if (r2.detail_error !== void 0) out.detail_error = ERROR_TEXT;
|
|
8911
|
+
return out;
|
|
8912
|
+
}
|
|
8913
|
+
function safePlanPath(p2) {
|
|
8914
|
+
if (!p2.startsWith(".caddis/") || p2.includes("\\") || p2.includes("..") || p2.includes(":")) return false;
|
|
8915
|
+
return !p2.startsWith("/");
|
|
8916
|
+
}
|
|
8917
|
+
function plan(raw) {
|
|
8918
|
+
const p2 = rec3(raw);
|
|
8919
|
+
if (p2.error !== void 0 || !safePlanPath(str4(p2.path))) return null;
|
|
8920
|
+
return {
|
|
8921
|
+
path: str4(p2.path),
|
|
8922
|
+
title: str4(p2.title),
|
|
8923
|
+
status: str4(p2.status),
|
|
8924
|
+
tracker: arr2(p2.tracker).map((t) => ({ phase: str4(rec3(t).phase), status: str4(rec3(t).status) })),
|
|
8925
|
+
open_rows: int(p2.open_rows)
|
|
8926
|
+
};
|
|
8927
|
+
}
|
|
8928
|
+
function repoOf(collect) {
|
|
8929
|
+
const repos = arr2(rec3(collect).repos);
|
|
8930
|
+
if (repos.length !== 1) throw new Error("the collector output must hold exactly one repo");
|
|
8931
|
+
const repo = rec3(repos[0]);
|
|
8932
|
+
if (repo.error !== void 0) throw new Error("the collector could not read the repo");
|
|
8933
|
+
return repo;
|
|
8934
|
+
}
|
|
8935
|
+
function exportData(collect, opts) {
|
|
8936
|
+
if (opts.github !== null && !GITHUB_RE.test(opts.github)) throw new Error("--github must look like <owner>/<repo>");
|
|
8937
|
+
let commit = null;
|
|
8938
|
+
if (opts.commit !== null) {
|
|
8939
|
+
if (!/^[0-9a-fA-F]{7,40}$/.test(opts.commit)) throw new Error("--commit must be 7 to 40 hex characters");
|
|
8940
|
+
commit = opts.commit.slice(0, 7);
|
|
8941
|
+
}
|
|
8942
|
+
const repo = repoOf(collect);
|
|
8943
|
+
const slot = rec3(repo.roadmaps);
|
|
8944
|
+
if (slot.error !== void 0) throw new Error("the roadmaps of the repo could not be read");
|
|
8945
|
+
return {
|
|
8946
|
+
schema: 1,
|
|
8947
|
+
generated_at: opts.now,
|
|
8948
|
+
label: opts.label,
|
|
8949
|
+
github: opts.github,
|
|
8950
|
+
commit,
|
|
8951
|
+
roadmaps: arr2(slot.roadmaps).map(roadmap),
|
|
8952
|
+
plans: arr2(rec3(repo.plans).plans).map(plan).filter((p2) => p2 !== null)
|
|
8953
|
+
};
|
|
8954
|
+
}
|
|
8955
|
+
function derivedDeny(collect, machine) {
|
|
8956
|
+
const out = /* @__PURE__ */ new Set();
|
|
8957
|
+
const add = (v2) => {
|
|
8958
|
+
const s = typeof v2 === "number" ? String(v2) : typeof v2 === "string" ? v2.trim() : "";
|
|
8959
|
+
if (s.length >= 3) out.add(s);
|
|
8960
|
+
};
|
|
8961
|
+
const addPath = (v2) => {
|
|
8962
|
+
const s = str4(v2).trim();
|
|
8963
|
+
if (!s) return;
|
|
8964
|
+
add(s);
|
|
8965
|
+
add(s.replace(/\\/g, "/"));
|
|
8966
|
+
add(s.replace(/\//g, "\\"));
|
|
8967
|
+
};
|
|
8968
|
+
for (const raw of arr2(rec3(collect).repos)) {
|
|
8969
|
+
const repo = rec3(raw);
|
|
8970
|
+
addPath(repo.path);
|
|
8971
|
+
add(repo.fingerprint);
|
|
8972
|
+
for (const rm of arr2(rec3(repo.roadmaps).roadmaps)) {
|
|
8973
|
+
const r2 = rec3(rm);
|
|
8974
|
+
add(r2.runner_host);
|
|
8975
|
+
for (const key of ["lock", "stale_lock"]) {
|
|
8976
|
+
const lock = rec3(rec3(r2.runner)[key]);
|
|
8977
|
+
add(lock.host);
|
|
8978
|
+
add(lock.pid);
|
|
8979
|
+
}
|
|
8980
|
+
}
|
|
8981
|
+
}
|
|
8982
|
+
addPath(machine.repoPath);
|
|
8983
|
+
addPath(machine.home);
|
|
8984
|
+
add(machine.host);
|
|
8985
|
+
if (!GENERIC_NAMES.has(machine.user.toLowerCase())) add(machine.user);
|
|
8986
|
+
return [...out];
|
|
8987
|
+
}
|
|
8988
|
+
var GITHUB_RE, ERROR_TEXT, rec3, arr2, str4, strOrNull, int, shortSha, GENERIC_NAMES;
|
|
8989
|
+
var init_data = __esm({
|
|
8990
|
+
"src/hub/export/data.ts"() {
|
|
8991
|
+
"use strict";
|
|
8992
|
+
GITHUB_RE = /^[A-Za-z0-9-]+\/[A-Za-z0-9._-]+$/;
|
|
8993
|
+
ERROR_TEXT = "could not be read";
|
|
8994
|
+
rec3 = (v2) => v2 && typeof v2 === "object" && !Array.isArray(v2) ? v2 : {};
|
|
8995
|
+
arr2 = (v2) => Array.isArray(v2) ? v2 : [];
|
|
8996
|
+
str4 = (v2) => typeof v2 === "string" ? v2 : "";
|
|
8997
|
+
strOrNull = (v2) => typeof v2 === "string" && v2 ? v2 : null;
|
|
8998
|
+
int = (v2) => typeof v2 === "number" && Number.isInteger(v2) ? v2 : 0;
|
|
8999
|
+
shortSha = (v2) => {
|
|
9000
|
+
const s = str4(v2);
|
|
9001
|
+
return /^[0-9a-fA-F]{7,}$/.test(s) ? s.slice(0, 7) : null;
|
|
9002
|
+
};
|
|
9003
|
+
GENERIC_NAMES = /* @__PURE__ */ new Set(["runner", "root", "user", "users", "admin", "administrator", "ubuntu", "localhost", "github"]);
|
|
9004
|
+
}
|
|
9005
|
+
});
|
|
9006
|
+
|
|
9007
|
+
// src/hub/export/privacy.ts
|
|
9008
|
+
import { lstatSync, readdirSync as readdirSync4, readFileSync as readFileSync15 } from "fs";
|
|
9009
|
+
import path22 from "path";
|
|
9010
|
+
function parseAllowedUrls(text2) {
|
|
9011
|
+
const exact = /* @__PURE__ */ new Set();
|
|
9012
|
+
const templates = [];
|
|
9013
|
+
for (const raw of text2.split(/\r?\n/)) {
|
|
9014
|
+
const line2 = raw.trim();
|
|
9015
|
+
if (!line2 || line2.startsWith("#")) continue;
|
|
9016
|
+
if (line2.startsWith("template:")) templates.push(line2.slice("template:".length).trim());
|
|
9017
|
+
else exact.add(line2);
|
|
9018
|
+
}
|
|
9019
|
+
return { exact, templates };
|
|
9020
|
+
}
|
|
9021
|
+
function defaultAllowedUrls() {
|
|
9022
|
+
return readFileSync15(new URL("./allowed-urls.txt", import.meta.url), "utf8");
|
|
9023
|
+
}
|
|
9024
|
+
function walk(dir, base = "") {
|
|
9025
|
+
const out = [];
|
|
9026
|
+
for (const name of readdirSync4(dir).sort()) {
|
|
9027
|
+
const rel = base ? `${base}/${name}` : name;
|
|
9028
|
+
const full = path22.join(dir, name);
|
|
9029
|
+
if (lstatSync(full).isDirectory()) out.push(...walk(full, rel));
|
|
9030
|
+
else out.push(rel);
|
|
9031
|
+
}
|
|
9032
|
+
return out;
|
|
9033
|
+
}
|
|
9034
|
+
function scanDeny(file, buf, text2, deny, hits) {
|
|
9035
|
+
const inAssets = file.startsWith("assets/");
|
|
9036
|
+
for (const value of deny) {
|
|
9037
|
+
if (text2 === null) {
|
|
9038
|
+
if (value.length < 6 || isNumeric(value)) continue;
|
|
9039
|
+
let at = buf.indexOf(value);
|
|
9040
|
+
while (at !== -1) {
|
|
9041
|
+
hits.push({ file, offset: at, rule: "derived-private-value" });
|
|
9042
|
+
at = buf.indexOf(value, at + value.length);
|
|
9043
|
+
}
|
|
9044
|
+
continue;
|
|
9045
|
+
}
|
|
9046
|
+
if (inAssets && isSoft(value)) continue;
|
|
9047
|
+
const re = isNumeric(value) ? new RegExp(`(?<![0-9])${escapeRe(value)}(?![0-9])`, "gi") : new RegExp(escapeRe(value), "gi");
|
|
9048
|
+
for (const m2 of text2.matchAll(re)) hits.push({ file, offset: m2.index ?? 0, rule: "derived-private-value" });
|
|
9049
|
+
}
|
|
9050
|
+
}
|
|
9051
|
+
function scanUrls(file, text2, opts, hits) {
|
|
9052
|
+
const allowed = parseAllowedUrls(opts.allowedUrls ?? defaultAllowedUrls());
|
|
9053
|
+
const pull = opts.github ? new RegExp(`^https://github\\.com/${escapeRe(opts.github)}/pull/\\d+$`) : null;
|
|
9054
|
+
for (const m2 of text2.matchAll(URL_RE)) {
|
|
9055
|
+
const url = m2[0].replace(/[.,;:]+$/, "");
|
|
9056
|
+
if (allowed.exact.has(url) || pull?.test(url)) continue;
|
|
9057
|
+
if (file.endsWith(".js") && allowed.templates.some((t) => url.startsWith(`${t}\${`))) continue;
|
|
9058
|
+
hits.push({ file, offset: m2.index ?? 0, rule: "url-not-allowed" });
|
|
9059
|
+
}
|
|
9060
|
+
}
|
|
9061
|
+
function scanExport(dir, opts) {
|
|
9062
|
+
const hits = [];
|
|
9063
|
+
for (const file of walk(dir)) {
|
|
9064
|
+
const full = path22.join(dir, ...file.split("/"));
|
|
9065
|
+
if (lstatSync(full).isSymbolicLink()) {
|
|
9066
|
+
hits.push({ file, offset: 0, rule: "symbolic-link" });
|
|
9067
|
+
continue;
|
|
9068
|
+
}
|
|
9069
|
+
const buf = readFileSync15(full);
|
|
9070
|
+
const binary = BINARY_EXT.has(path22.extname(file).toLowerCase());
|
|
9071
|
+
const text2 = binary ? null : buf.toString("utf8");
|
|
9072
|
+
scanDeny(file, buf, text2, opts.deny, hits);
|
|
9073
|
+
if (text2 === null) continue;
|
|
9074
|
+
scanUrls(file, text2, opts, hits);
|
|
9075
|
+
if (file !== "index.html") continue;
|
|
9076
|
+
const decoded = decodeEscapes(text2);
|
|
9077
|
+
for (const variant of decoded === text2 ? [text2] : [text2, decoded]) {
|
|
9078
|
+
for (const name of PRIVATE_NAMES) {
|
|
9079
|
+
let at = variant.indexOf(name);
|
|
9080
|
+
while (at !== -1) {
|
|
9081
|
+
hits.push({ file, offset: at, rule: `private-name:${name}` });
|
|
9082
|
+
at = variant.indexOf(name, at + name.length);
|
|
9083
|
+
}
|
|
9084
|
+
}
|
|
9085
|
+
for (const { name, re } of PATTERNS) {
|
|
9086
|
+
for (const m2 of variant.matchAll(re)) hits.push({ file, offset: m2.index ?? 0, rule: `pattern:${name}` });
|
|
9087
|
+
}
|
|
9088
|
+
}
|
|
9089
|
+
}
|
|
9090
|
+
return hits;
|
|
9091
|
+
}
|
|
9092
|
+
var PRIVATE_NAMES, PATTERNS, URL_RE, BINARY_EXT, escapeRe, isSoft, isNumeric, decodeEscapes, hitLine;
|
|
9093
|
+
var init_privacy = __esm({
|
|
9094
|
+
"src/hub/export/privacy.ts"() {
|
|
9095
|
+
"use strict";
|
|
9096
|
+
PRIVATE_NAMES = [
|
|
9097
|
+
"sessionId",
|
|
9098
|
+
"session_id",
|
|
9099
|
+
"waitingFor",
|
|
9100
|
+
"waiting_for",
|
|
9101
|
+
"prompt",
|
|
9102
|
+
"cap_eur",
|
|
9103
|
+
"committed_eur",
|
|
9104
|
+
"coordinator.json",
|
|
9105
|
+
"requests.jsonl",
|
|
9106
|
+
"audit.jsonl",
|
|
9107
|
+
"coordinator_session",
|
|
9108
|
+
"heartbeat_at",
|
|
9109
|
+
"roadmap-pages",
|
|
9110
|
+
"X-Caddis-Hub"
|
|
9111
|
+
];
|
|
9112
|
+
PATTERNS = [
|
|
9113
|
+
{ name: "windows-drive-path", re: /(?<![A-Za-z0-9])[A-Za-z]:[\\/]/g },
|
|
9114
|
+
{ name: "unc-path", re: /\\\\/g },
|
|
9115
|
+
{ name: "home-path", re: /\/home\//g },
|
|
9116
|
+
{ name: "users-path", re: /\/Users\//g },
|
|
9117
|
+
{ name: "root-path", re: /\/root\//g },
|
|
9118
|
+
{ name: "runner-path", re: /\/runner\//g },
|
|
9119
|
+
{ name: "email-address", re: /[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}/g },
|
|
9120
|
+
{ name: "ipv4-address", re: /(?<![\w.])(?:\d{1,3}\.){3}\d{1,3}(?![\w.])/g },
|
|
9121
|
+
{ name: "sha-40", re: /(?<![0-9A-Fa-f])[0-9A-Fa-f]{40}(?![0-9A-Fa-f])/g }
|
|
9122
|
+
];
|
|
9123
|
+
URL_RE = /(?:https?|wss?|ftp):\/\/[^\s"'`<>)\\]+/g;
|
|
9124
|
+
BINARY_EXT = /* @__PURE__ */ new Set([".woff2", ".woff", ".ttf", ".otf", ".png", ".ico", ".jpg", ".gif", ".webp"]);
|
|
9125
|
+
escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
9126
|
+
isSoft = (v2) => /^[A-Za-z][A-Za-z0-9_-]{2,6}$/.test(v2);
|
|
9127
|
+
isNumeric = (v2) => /^\d+$/.test(v2);
|
|
9128
|
+
decodeEscapes = (s) => s.replace(/\\u([0-9a-fA-F]{4})/g, (_m, h2) => String.fromCharCode(parseInt(h2, 16)));
|
|
9129
|
+
hitLine = (h2) => `privacy: ${h2.file}:${h2.offset}: ${h2.rule}`;
|
|
9130
|
+
}
|
|
9131
|
+
});
|
|
9132
|
+
|
|
9133
|
+
// src/hub/export/export.ts
|
|
9134
|
+
var export_exports = {};
|
|
9135
|
+
__export(export_exports, {
|
|
9136
|
+
FIXED_FILES: () => FIXED_FILES,
|
|
9137
|
+
MARKER: () => MARKER,
|
|
9138
|
+
NOT_FOUND_SCRIPT: () => NOT_FOUND_SCRIPT,
|
|
9139
|
+
PLACEHOLDER: () => PLACEHOLDER,
|
|
9140
|
+
checkOut: () => checkOut,
|
|
9141
|
+
escapeJson: () => escapeJson,
|
|
9142
|
+
hubExport: () => hubExport,
|
|
9143
|
+
notFoundPage: () => notFoundPage
|
|
9144
|
+
});
|
|
9145
|
+
import { createHash as createHash3 } from "crypto";
|
|
9146
|
+
import {
|
|
9147
|
+
copyFileSync,
|
|
9148
|
+
existsSync as existsSync10,
|
|
9149
|
+
lstatSync as lstatSync2,
|
|
9150
|
+
mkdirSync as mkdirSync8,
|
|
9151
|
+
readdirSync as readdirSync5,
|
|
9152
|
+
readFileSync as readFileSync16,
|
|
9153
|
+
renameSync as renameSync3,
|
|
9154
|
+
rmSync as rmSync4,
|
|
9155
|
+
statSync as statSync3,
|
|
9156
|
+
writeFileSync as writeFileSync5
|
|
9157
|
+
} from "fs";
|
|
9158
|
+
import os6 from "os";
|
|
9159
|
+
import path23 from "path";
|
|
9160
|
+
function holdsLink(dir) {
|
|
9161
|
+
for (const name of readdirSync5(dir)) {
|
|
9162
|
+
const full = path23.join(dir, name);
|
|
9163
|
+
const st = lstatSync2(full);
|
|
9164
|
+
if (st.isSymbolicLink()) return true;
|
|
9165
|
+
if (st.isDirectory() && holdsLink(full)) return true;
|
|
9166
|
+
}
|
|
9167
|
+
return false;
|
|
9168
|
+
}
|
|
9169
|
+
function checkOut(out, repo) {
|
|
9170
|
+
if (samePath(out, repo)) return "--out is the repo itself";
|
|
9171
|
+
if (isInside(repo, out)) return "--out holds the repo";
|
|
9172
|
+
let st;
|
|
9173
|
+
try {
|
|
9174
|
+
st = lstatSync2(out);
|
|
9175
|
+
} catch {
|
|
9176
|
+
return null;
|
|
9177
|
+
}
|
|
9178
|
+
if (st.isSymbolicLink()) return "--out is a link";
|
|
9179
|
+
if (!st.isDirectory()) return "--out is a file";
|
|
9180
|
+
if (readdirSync5(out).length === 0) return null;
|
|
9181
|
+
if (!existsSync10(path23.join(out, MARKER)) || lstatSync2(path23.join(out, MARKER)).isSymbolicLink()) {
|
|
9182
|
+
return `--out is not empty and has no ${MARKER} marker: this command did not make it`;
|
|
9183
|
+
}
|
|
9184
|
+
if (holdsLink(out)) return "--out holds a link";
|
|
9185
|
+
return null;
|
|
9186
|
+
}
|
|
9187
|
+
function escapeJson(json) {
|
|
9188
|
+
return json.replace(/[<>&\u2028\u2029]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
9189
|
+
}
|
|
9190
|
+
function notFoundPage() {
|
|
9191
|
+
const hash = createHash3("sha256").update(NOT_FOUND_SCRIPT).digest("base64");
|
|
9192
|
+
return `<!doctype html>
|
|
9193
|
+
<html lang="en">
|
|
9194
|
+
<head>
|
|
9195
|
+
<meta charset="utf-8" />
|
|
9196
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-${hash}'; base-uri 'none'; form-action 'none'" />
|
|
9197
|
+
<title>Page moved</title>
|
|
9198
|
+
</head>
|
|
9199
|
+
<body>
|
|
9200
|
+
<p>This link is old. Open the home page of this site to find the roadmap.</p>
|
|
9201
|
+
<script>${NOT_FOUND_SCRIPT}</script>
|
|
9202
|
+
</body>
|
|
9203
|
+
</html>
|
|
9204
|
+
`;
|
|
9205
|
+
}
|
|
9206
|
+
function copyFixedSet(dist, dest) {
|
|
9207
|
+
mkdirSync8(path23.join(dest, "assets"), { recursive: true });
|
|
9208
|
+
mkdirSync8(path23.join(dest, "fonts"), { recursive: true });
|
|
9209
|
+
mkdirSync8(path23.join(dest, "licenses"), { recursive: true });
|
|
9210
|
+
copyFileSync(path23.join(dist, "index.html"), path23.join(dest, "index.html"));
|
|
9211
|
+
for (const name of readdirSync5(path23.join(dist, "assets"))) {
|
|
9212
|
+
const from = path23.join(dist, "assets", name);
|
|
9213
|
+
if (lstatSync2(from).isFile()) copyFileSync(from, path23.join(dest, "assets", name));
|
|
9214
|
+
}
|
|
9215
|
+
const fonts = path23.join(dist, "fonts");
|
|
9216
|
+
if (isDir2(fonts)) {
|
|
9217
|
+
for (const name of readdirSync5(fonts)) {
|
|
9218
|
+
const from = path23.join(fonts, name);
|
|
9219
|
+
if (!lstatSync2(from).isFile()) continue;
|
|
9220
|
+
if (name.endsWith(".woff2")) copyFileSync(from, path23.join(dest, "fonts", name));
|
|
9221
|
+
else if (/^(OFL-[A-Za-z]+|LICENSE-Lucide)\.txt$/.test(name)) copyFileSync(from, path23.join(dest, "licenses", name));
|
|
9222
|
+
}
|
|
9223
|
+
}
|
|
9224
|
+
}
|
|
9225
|
+
function countFiles(dir) {
|
|
9226
|
+
return readdirSync5(dir).reduce((n, name) => {
|
|
9227
|
+
const full = path23.join(dir, name);
|
|
9228
|
+
return n + (lstatSync2(full).isDirectory() ? countFiles(full) : name === MARKER ? 0 : 1);
|
|
9229
|
+
}, 0);
|
|
9230
|
+
}
|
|
9231
|
+
function machineOf(over, repo) {
|
|
9232
|
+
let user = "";
|
|
9233
|
+
try {
|
|
9234
|
+
user = os6.userInfo().username;
|
|
9235
|
+
} catch {
|
|
9236
|
+
}
|
|
9237
|
+
return { repoPath: repo, home: os6.homedir(), user, host: os6.hostname(), ...over };
|
|
9238
|
+
}
|
|
9239
|
+
async function hubExport(args, deps = {}) {
|
|
9240
|
+
const out = deps.stdout ?? ((l2) => console.log(l2));
|
|
9241
|
+
const err = deps.stderr ?? ((l2) => console.error(l2));
|
|
9242
|
+
const spawn2 = deps.spawn ?? spawnBounded;
|
|
9243
|
+
const now = deps.now ?? (() => /* @__PURE__ */ new Date());
|
|
9244
|
+
if (args.github !== void 0 && !GITHUB_RE.test(args.github)) {
|
|
9245
|
+
err("error: --github must look like <owner>/<repo>");
|
|
9246
|
+
return 2;
|
|
9247
|
+
}
|
|
9248
|
+
if (args.check !== void 0) {
|
|
9249
|
+
const dir = path23.resolve(args.check);
|
|
9250
|
+
if (!isDir2(dir)) {
|
|
9251
|
+
err(`error: --check folder not found: ${args.check}`);
|
|
9252
|
+
return 1;
|
|
9253
|
+
}
|
|
9254
|
+
const machine = machineOf(deps.machine, "");
|
|
9255
|
+
const deny2 = derivedDeny({ repos: [] }, machine);
|
|
9256
|
+
const hits = scanExport(dir, { deny: deny2, github: args.github ?? null, ...deps.allowedUrls !== void 0 ? { allowedUrls: deps.allowedUrls } : {} });
|
|
9257
|
+
for (const h2 of hits) err(hitLine(h2));
|
|
9258
|
+
if (hits.length) {
|
|
9259
|
+
err(`[BLOCKED] ${hits.length} privacy hit(s)`);
|
|
9260
|
+
return 3;
|
|
9261
|
+
}
|
|
9262
|
+
out(`[CHECK] clean: ${countFiles(dir)} file(s) in ${dir}`);
|
|
9263
|
+
return 0;
|
|
9264
|
+
}
|
|
9265
|
+
if (!args.repo || !args.out) {
|
|
9266
|
+
err("usage: caddis hub export --repo <path> --out <dir> [--github <owner>/<repo>] [--commit <sha>] [--label <text>]");
|
|
9267
|
+
return 2;
|
|
9268
|
+
}
|
|
9269
|
+
if (args.commit !== void 0 && !/^[0-9a-fA-F]{7,40}$/.test(args.commit)) {
|
|
9270
|
+
err("error: --commit must be 7 to 40 hex characters");
|
|
9271
|
+
return 2;
|
|
9272
|
+
}
|
|
9273
|
+
const repo = path23.resolve(args.repo);
|
|
9274
|
+
const outDir = path23.resolve(args.out);
|
|
9275
|
+
if (!existsSync10(path23.join(repo, ".git")) || !(isDir2(path23.join(repo, ".caddis", "roadmaps")) || isDir2(path23.join(repo, ".caddis", "plans")))) {
|
|
9276
|
+
err("error: --repo must be a git checkout with .caddis/roadmaps/ or .caddis/plans/");
|
|
9277
|
+
return 2;
|
|
9278
|
+
}
|
|
9279
|
+
const refused = checkOut(outDir, repo);
|
|
9280
|
+
if (refused) {
|
|
9281
|
+
err(`error: ${refused}`);
|
|
9282
|
+
return 2;
|
|
9283
|
+
}
|
|
9284
|
+
const dist = deps.distDir ?? path23.join(packageInfo().root, "dist", "export");
|
|
9285
|
+
if (!existsSync10(path23.join(dist, "index.html")) || !isDir2(path23.join(dist, "assets"))) {
|
|
9286
|
+
err(`error: the export app is not built (${dist}). Run: npm run build:ui`);
|
|
9287
|
+
return 1;
|
|
9288
|
+
}
|
|
9289
|
+
let cmd = deps.python;
|
|
9290
|
+
let pre = [];
|
|
9291
|
+
if (!cmd) {
|
|
9292
|
+
const found = await resolvePython();
|
|
9293
|
+
if (!found) {
|
|
9294
|
+
err("error: python was not found (tried python, then py -3)");
|
|
9295
|
+
return 1;
|
|
9296
|
+
}
|
|
9297
|
+
cmd = found.cmd;
|
|
9298
|
+
pre = found.pre;
|
|
9299
|
+
}
|
|
9300
|
+
const script = deps.scriptPath ?? defaultScriptPath();
|
|
9301
|
+
const run2 = await spawn2(cmd, [...pre, script, "--repos", repo, "--only", "roadmaps,plans", "--json"], { timeoutMs: COLLECT_TIMEOUT_MS });
|
|
9302
|
+
if (run2.timedOut || !run2.ok) {
|
|
9303
|
+
err(`error: the collector ${run2.timedOut ? "timed out" : `failed (exit ${run2.code ?? "none"})`}`);
|
|
9304
|
+
return 1;
|
|
9305
|
+
}
|
|
9306
|
+
let collect;
|
|
9307
|
+
try {
|
|
9308
|
+
collect = JSON.parse(run2.stdout);
|
|
9309
|
+
} catch {
|
|
9310
|
+
err("error: the collector output is not valid JSON");
|
|
9311
|
+
return 1;
|
|
9312
|
+
}
|
|
9313
|
+
let data;
|
|
9314
|
+
try {
|
|
9315
|
+
data = exportData(collect, {
|
|
9316
|
+
label: args.label ?? null,
|
|
9317
|
+
github: args.github ?? null,
|
|
9318
|
+
commit: args.commit ?? null,
|
|
9319
|
+
now: now().toISOString().replace(/\.\d{3}Z$/, "Z")
|
|
9320
|
+
});
|
|
9321
|
+
} catch (error) {
|
|
9322
|
+
err(`error: ${error instanceof Error ? error.message : String(error)}`);
|
|
9323
|
+
return 1;
|
|
9324
|
+
}
|
|
9325
|
+
const deny = derivedDeny(collect, machineOf(deps.machine, repo));
|
|
9326
|
+
const staging = `${outDir}.staging-${process.pid}`;
|
|
9327
|
+
rmSync4(staging, { recursive: true, force: true });
|
|
9328
|
+
try {
|
|
9329
|
+
copyFixedSet(dist, staging);
|
|
9330
|
+
const indexPath = path23.join(staging, "index.html");
|
|
9331
|
+
const html = readFileSync16(indexPath, "utf8");
|
|
9332
|
+
if (!html.includes(PLACEHOLDER)) throw new Error("the built index.html has no data placeholder");
|
|
9333
|
+
const block = `<script type="application/json" id="caddis-export-data">${escapeJson(JSON.stringify(data))}</script>`;
|
|
9334
|
+
writeFileSync5(indexPath, html.replace(PLACEHOLDER, () => block));
|
|
9335
|
+
writeFileSync5(path23.join(staging, "404.html"), notFoundPage());
|
|
9336
|
+
const hits = scanExport(staging, { deny, github: args.github ?? null, ...deps.allowedUrls !== void 0 ? { allowedUrls: deps.allowedUrls } : {} });
|
|
9337
|
+
if (hits.length) {
|
|
9338
|
+
for (const h2 of hits) err(hitLine(h2));
|
|
9339
|
+
err(`[BLOCKED] ${hits.length} privacy hit(s). Nothing was published.`);
|
|
9340
|
+
rmSync4(staging, { recursive: true, force: true });
|
|
9341
|
+
return 3;
|
|
9342
|
+
}
|
|
9343
|
+
mkdirSync8(path23.dirname(outDir), { recursive: true });
|
|
9344
|
+
if (existsSync10(outDir)) rmSync4(outDir, { recursive: true, force: true });
|
|
9345
|
+
renameSync3(staging, outDir);
|
|
9346
|
+
writeFileSync5(path23.join(outDir, MARKER), "written by caddis hub export\n");
|
|
9347
|
+
out(`[EXPORT] ${countFiles(outDir)} file(s) in ${outDir}`);
|
|
9348
|
+
return 0;
|
|
9349
|
+
} catch (error) {
|
|
9350
|
+
rmSync4(staging, { recursive: true, force: true });
|
|
9351
|
+
err(`error: ${error instanceof Error ? error.message : String(error)}`);
|
|
9352
|
+
return 1;
|
|
9353
|
+
}
|
|
9354
|
+
}
|
|
9355
|
+
var MARKER, PLACEHOLDER, COLLECT_TIMEOUT_MS, FIXED_FILES, isDir2, samePath, isInside, NOT_FOUND_SCRIPT;
|
|
9356
|
+
var init_export = __esm({
|
|
9357
|
+
"src/hub/export/export.ts"() {
|
|
9358
|
+
"use strict";
|
|
9359
|
+
init_pkg();
|
|
9360
|
+
init_spawn();
|
|
9361
|
+
init_collector();
|
|
9362
|
+
init_data();
|
|
9363
|
+
init_privacy();
|
|
9364
|
+
MARKER = ".caddis-export";
|
|
9365
|
+
PLACEHOLDER = "<!--caddis-export-data-->";
|
|
9366
|
+
COLLECT_TIMEOUT_MS = 12e4;
|
|
9367
|
+
FIXED_FILES = ["index.html", "404.html"];
|
|
9368
|
+
isDir2 = (p2) => {
|
|
9369
|
+
try {
|
|
9370
|
+
return statSync3(p2).isDirectory();
|
|
9371
|
+
} catch {
|
|
9372
|
+
return false;
|
|
9373
|
+
}
|
|
9374
|
+
};
|
|
9375
|
+
samePath = (a, b3) => {
|
|
9376
|
+
const norm = (p2) => path23.resolve(p2).replace(/[\\/]+$/, "").toLowerCase();
|
|
9377
|
+
return norm(a) === norm(b3);
|
|
9378
|
+
};
|
|
9379
|
+
isInside = (child, parent) => {
|
|
9380
|
+
const rel = path23.relative(path23.resolve(parent), path23.resolve(child));
|
|
9381
|
+
return rel !== "" && !rel.startsWith("..") && !path23.isAbsolute(rel);
|
|
9382
|
+
};
|
|
9383
|
+
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]));";
|
|
9384
|
+
}
|
|
9385
|
+
});
|
|
9386
|
+
|
|
8364
9387
|
// node_modules/commander/esm.mjs
|
|
8365
9388
|
var import_index = __toESM(require_commander(), 1);
|
|
8366
9389
|
var {
|
|
@@ -8416,14 +9439,14 @@ function* pluginBlocks(stdout) {
|
|
|
8416
9439
|
if (current) yield current;
|
|
8417
9440
|
}
|
|
8418
9441
|
async function detect() {
|
|
8419
|
-
const
|
|
8420
|
-
if (!
|
|
9442
|
+
const path24 = await findBin(BIN);
|
|
9443
|
+
if (!path24) {
|
|
8421
9444
|
return { present: false, note: "no `claude` binary on PATH" };
|
|
8422
9445
|
}
|
|
8423
9446
|
const version = await run(BIN, ["--version"], { timeout: 2e4 });
|
|
8424
9447
|
return {
|
|
8425
9448
|
present: true,
|
|
8426
|
-
path:
|
|
9449
|
+
path: path24,
|
|
8427
9450
|
agentVersion: version.ok ? version.stdout.trim().split(/\s+/)[0] || void 0 : void 0,
|
|
8428
9451
|
note: version.ok ? void 0 : "binary found but `claude --version` failed"
|
|
8429
9452
|
};
|
|
@@ -8506,8 +9529,8 @@ ${result.stderr}`;
|
|
|
8506
9529
|
}
|
|
8507
9530
|
return { ok: true, skipped: false, steps: results };
|
|
8508
9531
|
}
|
|
8509
|
-
function tail(
|
|
8510
|
-
return
|
|
9532
|
+
function tail(text2, lines = 3) {
|
|
9533
|
+
return text2.trim().split(/\r?\n/).slice(-lines).join("\n");
|
|
8511
9534
|
}
|
|
8512
9535
|
var claudeAdapter = {
|
|
8513
9536
|
id: "claude",
|
|
@@ -8706,19 +9729,19 @@ function stageAndSwap(bundleDir, home, plugin, required, rename = renameSync) {
|
|
|
8706
9729
|
return { swapped: true, reason: "swapped", staged: live, detail: note("swapped in by rename") };
|
|
8707
9730
|
}
|
|
8708
9731
|
function runningAgyMessage(pids, plugin, outcome, alreadySwapped = []) {
|
|
8709
|
-
let
|
|
8710
|
-
if (alreadySwapped.length > 0)
|
|
9732
|
+
let text2 = `agy is running (${pids}), so ${plugin} was not installed: ${outcome.detail}.`;
|
|
9733
|
+
if (alreadySwapped.length > 0) text2 += ` ${alreadySwapped.join(", ")} was already swapped in.`;
|
|
8711
9734
|
if (outcome.kept) {
|
|
8712
|
-
|
|
9735
|
+
text2 += ` Nothing was installed; the rejected copy is kept at ${outcome.kept}.`;
|
|
8713
9736
|
} else if (outcome.staged && existsSync2(outcome.staged)) {
|
|
8714
|
-
|
|
9737
|
+
text2 += ` The new version is staged at ${outcome.staged}. Stop agy and run \`caddis update\` again to put it in place.`;
|
|
8715
9738
|
} else {
|
|
8716
|
-
|
|
9739
|
+
text2 += " Nothing is staged. Stop agy and run `caddis update` again.";
|
|
8717
9740
|
}
|
|
8718
9741
|
if (outcome.reason === "first-install") {
|
|
8719
|
-
|
|
9742
|
+
text2 += ` Or set ${ALLOW_RUNNING_ENV}=1 if you know no agy holds the plugin folder.`;
|
|
8720
9743
|
}
|
|
8721
|
-
return
|
|
9744
|
+
return text2;
|
|
8722
9745
|
}
|
|
8723
9746
|
function pluginManifestPath(home = os.homedir(), plugin = PLUGIN2) {
|
|
8724
9747
|
return path2.join(home, ".gemini", "config", "plugins", plugin, "plugin.json");
|
|
@@ -9104,8 +10127,8 @@ ${result.stderr}`;
|
|
|
9104
10127
|
...notes.length ? { message: notes.join(" ") } : {}
|
|
9105
10128
|
};
|
|
9106
10129
|
}
|
|
9107
|
-
function tail2(
|
|
9108
|
-
return
|
|
10130
|
+
function tail2(text2, lines = 3) {
|
|
10131
|
+
return text2.trim().split(/\r?\n/).slice(-lines).join("\n");
|
|
9109
10132
|
}
|
|
9110
10133
|
var codexAdapter = {
|
|
9111
10134
|
id: "codex",
|
|
@@ -9269,6 +10292,10 @@ hub.command("serve").description("run the hub in the foreground (used by start a
|
|
|
9269
10292
|
const { hubServe: hubServe2 } = await Promise.resolve().then(() => (init_hub(), hub_exports));
|
|
9270
10293
|
finish(await hubServe2());
|
|
9271
10294
|
});
|
|
10295
|
+
hub.command("export").description("build the static roadmap page for GitHub Pages: roadmap data only, privacy scan (exit 3 on a hit)").option("--repo <path>", "the git checkout with .caddis/roadmaps or .caddis/plans").option("--out <dir>", "the folder to write (emptied only if empty or made by this command)").option("--github <owner/repo>", "the public GitHub repo, for the PR links").option("--commit <sha>", "the commit the page is built from (cut to 7 hex)").option("--label <text>", "extra text for the banner").option("--check <dir>", "scan an already built folder and do nothing else").action(async (options) => {
|
|
10296
|
+
const { hubExport: hubExport2 } = await Promise.resolve().then(() => (init_export(), export_exports));
|
|
10297
|
+
finish(await hubExport2(options));
|
|
10298
|
+
});
|
|
9272
10299
|
hub.command("autostart <action>").description("start the hub at logon: enable, disable or status (per user, opt-in)").action(async (action) => {
|
|
9273
10300
|
const { hubAutostart: hubAutostart2 } = await Promise.resolve().then(() => (init_hub(), hub_exports));
|
|
9274
10301
|
finish(await hubAutostart2(action));
|