agentsrc 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -34
- package/dist/index.js +2351 -143
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -6821,6 +6821,1136 @@ var init_did_you_mean_report_ySwx_o4J = __esm(() => {
|
|
|
6821
6821
|
init_tooling();
|
|
6822
6822
|
});
|
|
6823
6823
|
|
|
6824
|
+
// node_modules/fast-string-truncated-width/dist/utils.js
|
|
6825
|
+
var getCodePointsLength, isFullWidth2 = (x) => {
|
|
6826
|
+
return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
|
|
6827
|
+
}, isWideNotCJKTNotEmoji = (x) => {
|
|
6828
|
+
return x === 8987 || x === 9001 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12771 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 19903 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
|
|
6829
|
+
};
|
|
6830
|
+
var init_utils = __esm(() => {
|
|
6831
|
+
getCodePointsLength = (() => {
|
|
6832
|
+
const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
|
6833
|
+
return (input) => {
|
|
6834
|
+
let surrogatePairsNr = 0;
|
|
6835
|
+
SURROGATE_PAIR_RE.lastIndex = 0;
|
|
6836
|
+
while (SURROGATE_PAIR_RE.test(input)) {
|
|
6837
|
+
surrogatePairsNr += 1;
|
|
6838
|
+
}
|
|
6839
|
+
return input.length - surrogatePairsNr;
|
|
6840
|
+
};
|
|
6841
|
+
})();
|
|
6842
|
+
});
|
|
6843
|
+
|
|
6844
|
+
// node_modules/fast-string-truncated-width/dist/index.js
|
|
6845
|
+
var ANSI_RE, CONTROL_RE, CJKT_WIDE_RE, TAB_RE, EMOJI_RE, LATIN_RE, MODIFIER_RE, NO_TRUNCATION, getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
|
|
6846
|
+
const LIMIT = truncationOptions.limit ?? Infinity;
|
|
6847
|
+
const ELLIPSIS = truncationOptions.ellipsis ?? "";
|
|
6848
|
+
const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION, widthOptions).width : 0);
|
|
6849
|
+
const ANSI_WIDTH = 0;
|
|
6850
|
+
const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
|
|
6851
|
+
const TAB_WIDTH = widthOptions.tabWidth ?? 8;
|
|
6852
|
+
const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
|
|
6853
|
+
const FULL_WIDTH_WIDTH = 2;
|
|
6854
|
+
const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
|
|
6855
|
+
const WIDE_WIDTH = widthOptions.wideWidth ?? FULL_WIDTH_WIDTH;
|
|
6856
|
+
const PARSE_BLOCKS = [
|
|
6857
|
+
[LATIN_RE, REGULAR_WIDTH],
|
|
6858
|
+
[ANSI_RE, ANSI_WIDTH],
|
|
6859
|
+
[CONTROL_RE, CONTROL_WIDTH],
|
|
6860
|
+
[TAB_RE, TAB_WIDTH],
|
|
6861
|
+
[EMOJI_RE, EMOJI_WIDTH],
|
|
6862
|
+
[CJKT_WIDE_RE, WIDE_WIDTH]
|
|
6863
|
+
];
|
|
6864
|
+
let indexPrev = 0;
|
|
6865
|
+
let index = 0;
|
|
6866
|
+
let length = input.length;
|
|
6867
|
+
let lengthExtra = 0;
|
|
6868
|
+
let truncationEnabled = false;
|
|
6869
|
+
let truncationIndex = length;
|
|
6870
|
+
let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
|
|
6871
|
+
let unmatchedStart = 0;
|
|
6872
|
+
let unmatchedEnd = 0;
|
|
6873
|
+
let width = 0;
|
|
6874
|
+
let widthExtra = 0;
|
|
6875
|
+
outer:
|
|
6876
|
+
while (true) {
|
|
6877
|
+
if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
|
|
6878
|
+
const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
|
|
6879
|
+
lengthExtra = 0;
|
|
6880
|
+
for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
|
|
6881
|
+
const codePoint = char.codePointAt(0) || 0;
|
|
6882
|
+
if (isFullWidth2(codePoint)) {
|
|
6883
|
+
widthExtra = FULL_WIDTH_WIDTH;
|
|
6884
|
+
} else if (isWideNotCJKTNotEmoji(codePoint)) {
|
|
6885
|
+
widthExtra = WIDE_WIDTH;
|
|
6886
|
+
} else {
|
|
6887
|
+
widthExtra = REGULAR_WIDTH;
|
|
6888
|
+
}
|
|
6889
|
+
if (width + widthExtra > truncationLimit) {
|
|
6890
|
+
truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
|
|
6891
|
+
}
|
|
6892
|
+
if (width + widthExtra > LIMIT) {
|
|
6893
|
+
truncationEnabled = true;
|
|
6894
|
+
break outer;
|
|
6895
|
+
}
|
|
6896
|
+
lengthExtra += char.length;
|
|
6897
|
+
width += widthExtra;
|
|
6898
|
+
}
|
|
6899
|
+
unmatchedStart = unmatchedEnd = 0;
|
|
6900
|
+
}
|
|
6901
|
+
if (index >= length) {
|
|
6902
|
+
break outer;
|
|
6903
|
+
}
|
|
6904
|
+
for (let i = 0, l = PARSE_BLOCKS.length;i < l; i++) {
|
|
6905
|
+
const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i];
|
|
6906
|
+
BLOCK_RE.lastIndex = index;
|
|
6907
|
+
if (BLOCK_RE.test(input)) {
|
|
6908
|
+
lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index;
|
|
6909
|
+
widthExtra = lengthExtra * BLOCK_WIDTH;
|
|
6910
|
+
if (width + widthExtra > truncationLimit) {
|
|
6911
|
+
truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / BLOCK_WIDTH));
|
|
6912
|
+
}
|
|
6913
|
+
if (width + widthExtra > LIMIT) {
|
|
6914
|
+
truncationEnabled = true;
|
|
6915
|
+
break outer;
|
|
6916
|
+
}
|
|
6917
|
+
width += widthExtra;
|
|
6918
|
+
unmatchedStart = indexPrev;
|
|
6919
|
+
unmatchedEnd = index;
|
|
6920
|
+
index = indexPrev = BLOCK_RE.lastIndex;
|
|
6921
|
+
continue outer;
|
|
6922
|
+
}
|
|
6923
|
+
}
|
|
6924
|
+
index += 1;
|
|
6925
|
+
}
|
|
6926
|
+
return {
|
|
6927
|
+
width: truncationEnabled ? truncationLimit : width,
|
|
6928
|
+
index: truncationEnabled ? truncationIndex : length,
|
|
6929
|
+
truncated: truncationEnabled,
|
|
6930
|
+
ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
|
|
6931
|
+
};
|
|
6932
|
+
}, dist_default;
|
|
6933
|
+
var init_dist3 = __esm(() => {
|
|
6934
|
+
init_utils();
|
|
6935
|
+
ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y;
|
|
6936
|
+
CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
|
|
6937
|
+
CJKT_WIDE_RE = /(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu;
|
|
6938
|
+
TAB_RE = /\t{1,1000}/y;
|
|
6939
|
+
EMOJI_RE = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu;
|
|
6940
|
+
LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
|
|
6941
|
+
MODIFIER_RE = /\p{M}+/gu;
|
|
6942
|
+
NO_TRUNCATION = { limit: Infinity, ellipsis: "" };
|
|
6943
|
+
dist_default = getStringTruncatedWidth;
|
|
6944
|
+
});
|
|
6945
|
+
|
|
6946
|
+
// node_modules/fast-string-width/dist/index.js
|
|
6947
|
+
var NO_TRUNCATION2, fastStringWidth = (input, options = {}) => {
|
|
6948
|
+
return dist_default(input, NO_TRUNCATION2, options).width;
|
|
6949
|
+
}, dist_default2;
|
|
6950
|
+
var init_dist4 = __esm(() => {
|
|
6951
|
+
init_dist3();
|
|
6952
|
+
NO_TRUNCATION2 = {
|
|
6953
|
+
limit: Infinity,
|
|
6954
|
+
ellipsis: "",
|
|
6955
|
+
ellipsisWidth: 0
|
|
6956
|
+
};
|
|
6957
|
+
dist_default2 = fastStringWidth;
|
|
6958
|
+
});
|
|
6959
|
+
|
|
6960
|
+
// node_modules/fast-wrap-ansi/lib/main.js
|
|
6961
|
+
function wrapAnsi(string, columns, options) {
|
|
6962
|
+
return String(string).normalize().split(CRLF_OR_LF).map((line) => exec(line, columns, options)).join(`
|
|
6963
|
+
`);
|
|
6964
|
+
}
|
|
6965
|
+
var ESC = "\x1B", CSI = "", END_CODE = 39, ANSI_ESCAPE_BELL = "\x07", ANSI_CSI = "[", ANSI_OSC = "]", ANSI_SGR_TERMINATOR = "m", ANSI_ESCAPE_LINK, GROUP_REGEX, getClosingCode = (openingCode) => {
|
|
6966
|
+
if (openingCode >= 30 && openingCode <= 37)
|
|
6967
|
+
return 39;
|
|
6968
|
+
if (openingCode >= 90 && openingCode <= 97)
|
|
6969
|
+
return 39;
|
|
6970
|
+
if (openingCode >= 40 && openingCode <= 47)
|
|
6971
|
+
return 49;
|
|
6972
|
+
if (openingCode >= 100 && openingCode <= 107)
|
|
6973
|
+
return 49;
|
|
6974
|
+
if (openingCode === 1 || openingCode === 2)
|
|
6975
|
+
return 22;
|
|
6976
|
+
if (openingCode === 3)
|
|
6977
|
+
return 23;
|
|
6978
|
+
if (openingCode === 4)
|
|
6979
|
+
return 24;
|
|
6980
|
+
if (openingCode === 7)
|
|
6981
|
+
return 27;
|
|
6982
|
+
if (openingCode === 8)
|
|
6983
|
+
return 28;
|
|
6984
|
+
if (openingCode === 9)
|
|
6985
|
+
return 29;
|
|
6986
|
+
if (openingCode === 0)
|
|
6987
|
+
return 0;
|
|
6988
|
+
return;
|
|
6989
|
+
}, wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`, wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`, wrapWord = (rows, word, columns) => {
|
|
6990
|
+
const characters = word[Symbol.iterator]();
|
|
6991
|
+
let isInsideEscape = false;
|
|
6992
|
+
let isInsideLinkEscape = false;
|
|
6993
|
+
let lastRow = rows.at(-1);
|
|
6994
|
+
let visible = lastRow === undefined ? 0 : dist_default2(lastRow);
|
|
6995
|
+
let currentCharacter = characters.next();
|
|
6996
|
+
let nextCharacter = characters.next();
|
|
6997
|
+
let rawCharacterIndex = 0;
|
|
6998
|
+
while (!currentCharacter.done) {
|
|
6999
|
+
const character = currentCharacter.value;
|
|
7000
|
+
const characterLength = dist_default2(character);
|
|
7001
|
+
if (visible + characterLength <= columns) {
|
|
7002
|
+
rows[rows.length - 1] += character;
|
|
7003
|
+
} else {
|
|
7004
|
+
rows.push(character);
|
|
7005
|
+
visible = 0;
|
|
7006
|
+
}
|
|
7007
|
+
if (character === ESC || character === CSI) {
|
|
7008
|
+
isInsideEscape = true;
|
|
7009
|
+
isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
|
|
7010
|
+
}
|
|
7011
|
+
if (isInsideEscape) {
|
|
7012
|
+
if (isInsideLinkEscape) {
|
|
7013
|
+
if (character === ANSI_ESCAPE_BELL) {
|
|
7014
|
+
isInsideEscape = false;
|
|
7015
|
+
isInsideLinkEscape = false;
|
|
7016
|
+
}
|
|
7017
|
+
} else if (character === ANSI_SGR_TERMINATOR) {
|
|
7018
|
+
isInsideEscape = false;
|
|
7019
|
+
}
|
|
7020
|
+
} else {
|
|
7021
|
+
visible += characterLength;
|
|
7022
|
+
if (visible === columns && !nextCharacter.done) {
|
|
7023
|
+
rows.push("");
|
|
7024
|
+
visible = 0;
|
|
7025
|
+
}
|
|
7026
|
+
}
|
|
7027
|
+
currentCharacter = nextCharacter;
|
|
7028
|
+
nextCharacter = characters.next();
|
|
7029
|
+
rawCharacterIndex += character.length;
|
|
7030
|
+
}
|
|
7031
|
+
lastRow = rows.at(-1);
|
|
7032
|
+
if (!visible && lastRow !== undefined && lastRow.length && rows.length > 1) {
|
|
7033
|
+
rows[rows.length - 2] += rows.pop();
|
|
7034
|
+
}
|
|
7035
|
+
}, stringVisibleTrimSpacesRight = (string) => {
|
|
7036
|
+
const words = string.split(" ");
|
|
7037
|
+
let last = words.length;
|
|
7038
|
+
while (last) {
|
|
7039
|
+
if (dist_default2(words[last - 1])) {
|
|
7040
|
+
break;
|
|
7041
|
+
}
|
|
7042
|
+
last--;
|
|
7043
|
+
}
|
|
7044
|
+
if (last === words.length) {
|
|
7045
|
+
return string;
|
|
7046
|
+
}
|
|
7047
|
+
return words.slice(0, last).join(" ") + words.slice(last).join("");
|
|
7048
|
+
}, exec = (string, columns, options = {}) => {
|
|
7049
|
+
if (options.trim !== false && string.trim() === "") {
|
|
7050
|
+
return "";
|
|
7051
|
+
}
|
|
7052
|
+
let returnValue = "";
|
|
7053
|
+
let escapeCode;
|
|
7054
|
+
let escapeUrl;
|
|
7055
|
+
const words = string.split(" ");
|
|
7056
|
+
let rows = [""];
|
|
7057
|
+
let rowLength = 0;
|
|
7058
|
+
for (let index = 0;index < words.length; index++) {
|
|
7059
|
+
const word = words[index];
|
|
7060
|
+
if (options.trim !== false) {
|
|
7061
|
+
const row = rows.at(-1) ?? "";
|
|
7062
|
+
const trimmed = row.trimStart();
|
|
7063
|
+
if (row.length !== trimmed.length) {
|
|
7064
|
+
rows[rows.length - 1] = trimmed;
|
|
7065
|
+
rowLength = dist_default2(trimmed);
|
|
7066
|
+
}
|
|
7067
|
+
}
|
|
7068
|
+
if (index !== 0) {
|
|
7069
|
+
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
|
|
7070
|
+
rows.push("");
|
|
7071
|
+
rowLength = 0;
|
|
7072
|
+
}
|
|
7073
|
+
if (rowLength || options.trim === false) {
|
|
7074
|
+
rows[rows.length - 1] += " ";
|
|
7075
|
+
rowLength++;
|
|
7076
|
+
}
|
|
7077
|
+
}
|
|
7078
|
+
const wordLength = dist_default2(word);
|
|
7079
|
+
if (options.hard && wordLength > columns) {
|
|
7080
|
+
const remainingColumns = columns - rowLength;
|
|
7081
|
+
const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
|
|
7082
|
+
const breaksStartingNextLine = Math.floor((wordLength - 1) / columns);
|
|
7083
|
+
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
7084
|
+
rows.push("");
|
|
7085
|
+
}
|
|
7086
|
+
wrapWord(rows, word, columns);
|
|
7087
|
+
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
7088
|
+
continue;
|
|
7089
|
+
}
|
|
7090
|
+
if (rowLength + wordLength > columns && rowLength && wordLength) {
|
|
7091
|
+
if (options.wordWrap === false && rowLength < columns) {
|
|
7092
|
+
wrapWord(rows, word, columns);
|
|
7093
|
+
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
7094
|
+
continue;
|
|
7095
|
+
}
|
|
7096
|
+
rows.push("");
|
|
7097
|
+
rowLength = 0;
|
|
7098
|
+
}
|
|
7099
|
+
if (rowLength + wordLength > columns && options.wordWrap === false) {
|
|
7100
|
+
wrapWord(rows, word, columns);
|
|
7101
|
+
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
7102
|
+
continue;
|
|
7103
|
+
}
|
|
7104
|
+
rows[rows.length - 1] += word;
|
|
7105
|
+
rowLength += wordLength;
|
|
7106
|
+
}
|
|
7107
|
+
if (options.trim !== false) {
|
|
7108
|
+
rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
|
|
7109
|
+
}
|
|
7110
|
+
const preString = rows.join(`
|
|
7111
|
+
`);
|
|
7112
|
+
let inSurrogate = false;
|
|
7113
|
+
for (let i = 0;i < preString.length; i++) {
|
|
7114
|
+
const character = preString[i];
|
|
7115
|
+
returnValue += character;
|
|
7116
|
+
if (!inSurrogate) {
|
|
7117
|
+
inSurrogate = character >= "\uD800" && character <= "\uDBFF";
|
|
7118
|
+
if (inSurrogate) {
|
|
7119
|
+
continue;
|
|
7120
|
+
}
|
|
7121
|
+
} else {
|
|
7122
|
+
inSurrogate = false;
|
|
7123
|
+
}
|
|
7124
|
+
if (character === ESC || character === CSI) {
|
|
7125
|
+
GROUP_REGEX.lastIndex = i + 1;
|
|
7126
|
+
const groupsResult = GROUP_REGEX.exec(preString);
|
|
7127
|
+
const groups = groupsResult?.groups;
|
|
7128
|
+
if (groups?.code !== undefined) {
|
|
7129
|
+
const code = Number.parseFloat(groups.code);
|
|
7130
|
+
escapeCode = code === END_CODE ? undefined : code;
|
|
7131
|
+
} else if (groups?.uri !== undefined) {
|
|
7132
|
+
escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
|
|
7133
|
+
}
|
|
7134
|
+
}
|
|
7135
|
+
if (preString[i + 1] === `
|
|
7136
|
+
`) {
|
|
7137
|
+
if (escapeUrl) {
|
|
7138
|
+
returnValue += wrapAnsiHyperlink("");
|
|
7139
|
+
}
|
|
7140
|
+
const closingCode = escapeCode ? getClosingCode(escapeCode) : undefined;
|
|
7141
|
+
if (escapeCode && closingCode) {
|
|
7142
|
+
returnValue += wrapAnsiCode(closingCode);
|
|
7143
|
+
}
|
|
7144
|
+
} else if (character === `
|
|
7145
|
+
`) {
|
|
7146
|
+
if (escapeCode && getClosingCode(escapeCode)) {
|
|
7147
|
+
returnValue += wrapAnsiCode(escapeCode);
|
|
7148
|
+
}
|
|
7149
|
+
if (escapeUrl) {
|
|
7150
|
+
returnValue += wrapAnsiHyperlink(escapeUrl);
|
|
7151
|
+
}
|
|
7152
|
+
}
|
|
7153
|
+
}
|
|
7154
|
+
return returnValue;
|
|
7155
|
+
}, CRLF_OR_LF;
|
|
7156
|
+
var init_main = __esm(() => {
|
|
7157
|
+
init_dist4();
|
|
7158
|
+
ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
7159
|
+
GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
|
|
7160
|
+
CRLF_OR_LF = /\r?\n/;
|
|
7161
|
+
});
|
|
7162
|
+
|
|
7163
|
+
// node_modules/sisteransi/dist/index.js
|
|
7164
|
+
var ESC2 = "\x1B", CSI2, cursor, erase, clear;
|
|
7165
|
+
var init_dist5 = __esm(() => {
|
|
7166
|
+
CSI2 = `${ESC2}[`;
|
|
7167
|
+
cursor = {
|
|
7168
|
+
to(x, y) {
|
|
7169
|
+
if (!y)
|
|
7170
|
+
return `${CSI2}${x + 1}G`;
|
|
7171
|
+
return `${CSI2}${y + 1};${x + 1}H`;
|
|
7172
|
+
},
|
|
7173
|
+
move(x, y) {
|
|
7174
|
+
let ret = "";
|
|
7175
|
+
if (x < 0)
|
|
7176
|
+
ret += `${CSI2}${-x}D`;
|
|
7177
|
+
else if (x > 0)
|
|
7178
|
+
ret += `${CSI2}${x}C`;
|
|
7179
|
+
if (y < 0)
|
|
7180
|
+
ret += `${CSI2}${-y}A`;
|
|
7181
|
+
else if (y > 0)
|
|
7182
|
+
ret += `${CSI2}${y}B`;
|
|
7183
|
+
return ret;
|
|
7184
|
+
},
|
|
7185
|
+
up: (count = 1) => `${CSI2}${count}A`,
|
|
7186
|
+
down: (count = 1) => `${CSI2}${count}B`,
|
|
7187
|
+
forward: (count = 1) => `${CSI2}${count}C`,
|
|
7188
|
+
backward: (count = 1) => `${CSI2}${count}D`,
|
|
7189
|
+
nextLine: (count = 1) => `${CSI2}E`.repeat(count),
|
|
7190
|
+
prevLine: (count = 1) => `${CSI2}F`.repeat(count),
|
|
7191
|
+
left: `${CSI2}G`,
|
|
7192
|
+
hide: `${CSI2}?25l`,
|
|
7193
|
+
show: `${CSI2}?25h`,
|
|
7194
|
+
save: `${ESC2}7`,
|
|
7195
|
+
restore: `${ESC2}8`
|
|
7196
|
+
};
|
|
7197
|
+
erase = {
|
|
7198
|
+
screen: `${CSI2}2J`,
|
|
7199
|
+
up: (count = 1) => `${CSI2}1J`.repeat(count),
|
|
7200
|
+
down: (count = 1) => `${CSI2}J`.repeat(count),
|
|
7201
|
+
line: `${CSI2}2K`,
|
|
7202
|
+
lineEnd: `${CSI2}K`,
|
|
7203
|
+
lineStart: `${CSI2}1K`,
|
|
7204
|
+
lines(count) {
|
|
7205
|
+
let clear = "";
|
|
7206
|
+
for (let i = 0;i < count; i++)
|
|
7207
|
+
clear += this.line + (i < count - 1 ? cursor.up() : "");
|
|
7208
|
+
if (count)
|
|
7209
|
+
clear += cursor.left;
|
|
7210
|
+
return clear;
|
|
7211
|
+
}
|
|
7212
|
+
};
|
|
7213
|
+
clear = {
|
|
7214
|
+
screen: `${ESC2}c`
|
|
7215
|
+
};
|
|
7216
|
+
});
|
|
7217
|
+
|
|
7218
|
+
// node_modules/@clack/core/dist/index.mjs
|
|
7219
|
+
import { stdout, stdin } from "node:process";
|
|
7220
|
+
import * as f$1 from "node:readline";
|
|
7221
|
+
import f__default from "node:readline";
|
|
7222
|
+
import { ReadStream } from "node:tty";
|
|
7223
|
+
function findCursor(o, s, l) {
|
|
7224
|
+
if (!l.some((r) => !r.disabled))
|
|
7225
|
+
return o;
|
|
7226
|
+
const t = o + s, n = Math.max(l.length - 1, 0), e = t < 0 ? n : t > n ? 0 : t;
|
|
7227
|
+
return l[e]?.disabled ? findCursor(e, s < 0 ? -1 : 1, l) : e;
|
|
7228
|
+
}
|
|
7229
|
+
function isAccessible(n) {
|
|
7230
|
+
if (n !== undefined)
|
|
7231
|
+
return n;
|
|
7232
|
+
if (settings.accessible !== undefined)
|
|
7233
|
+
return settings.accessible;
|
|
7234
|
+
const e = process.env.ACCESSIBLE;
|
|
7235
|
+
return e !== undefined && e !== "" && e !== "0" && e !== "false";
|
|
7236
|
+
}
|
|
7237
|
+
function isActionKey(n, e) {
|
|
7238
|
+
if (typeof n == "string")
|
|
7239
|
+
return settings.aliases.get(n) === e;
|
|
7240
|
+
for (const s of n)
|
|
7241
|
+
if (s !== undefined && isActionKey(s, e))
|
|
7242
|
+
return true;
|
|
7243
|
+
return false;
|
|
7244
|
+
}
|
|
7245
|
+
function diffLines(i, s) {
|
|
7246
|
+
if (i === s)
|
|
7247
|
+
return;
|
|
7248
|
+
const e = i.split(`
|
|
7249
|
+
`), t = s.split(`
|
|
7250
|
+
`), r = Math.max(e.length, t.length), f = [];
|
|
7251
|
+
for (let n = 0;n < r; n++)
|
|
7252
|
+
e[n] !== t[n] && f.push(n);
|
|
7253
|
+
return {
|
|
7254
|
+
lines: f,
|
|
7255
|
+
numLinesBefore: e.length,
|
|
7256
|
+
numLinesAfter: t.length,
|
|
7257
|
+
numLines: r
|
|
7258
|
+
};
|
|
7259
|
+
}
|
|
7260
|
+
function isCancel(e) {
|
|
7261
|
+
return e === CANCEL_SYMBOL;
|
|
7262
|
+
}
|
|
7263
|
+
function setRawMode(e, r) {
|
|
7264
|
+
const o = e;
|
|
7265
|
+
o.isTTY && o.setRawMode(r);
|
|
7266
|
+
}
|
|
7267
|
+
function block({
|
|
7268
|
+
input: e = stdin,
|
|
7269
|
+
output: r = stdout,
|
|
7270
|
+
overwrite: o = true,
|
|
7271
|
+
hideCursor: n = true
|
|
7272
|
+
} = {}) {
|
|
7273
|
+
const s = f$1.createInterface({
|
|
7274
|
+
input: e,
|
|
7275
|
+
output: r,
|
|
7276
|
+
prompt: "",
|
|
7277
|
+
tabSize: 1
|
|
7278
|
+
});
|
|
7279
|
+
f$1.emitKeypressEvents(e, s), e instanceof ReadStream && e.isTTY && e.setRawMode(true);
|
|
7280
|
+
const t = (l, { name: i, sequence: p }) => {
|
|
7281
|
+
const w = String(l);
|
|
7282
|
+
if (isActionKey([w, i, p], "cancel")) {
|
|
7283
|
+
n && r.write(cursor.show), process.exit(0);
|
|
7284
|
+
return;
|
|
7285
|
+
}
|
|
7286
|
+
if (!o)
|
|
7287
|
+
return;
|
|
7288
|
+
const c = i === "return" ? 0 : -1, a = i === "return" ? -1 : 0;
|
|
7289
|
+
f$1.moveCursor(r, c, a, () => {
|
|
7290
|
+
f$1.clearLine(r, 1, () => {
|
|
7291
|
+
e.once("keypress", t);
|
|
7292
|
+
});
|
|
7293
|
+
});
|
|
7294
|
+
};
|
|
7295
|
+
return n && r.write(cursor.hide), e.once("keypress", t), () => {
|
|
7296
|
+
e.off("keypress", t), n && r.write(cursor.show), e instanceof ReadStream && e.isTTY && !R && e.setRawMode(false), s.terminal = false, s.close();
|
|
7297
|
+
};
|
|
7298
|
+
}
|
|
7299
|
+
function wrapTextWithPrefix(e, r, o, n = o, s = o, t) {
|
|
7300
|
+
const l = getColumns(e ?? stdout), i = dist_default2(o);
|
|
7301
|
+
return wrapAnsi(r, l - i, {
|
|
7302
|
+
hard: true,
|
|
7303
|
+
trim: false
|
|
7304
|
+
}).split(`
|
|
7305
|
+
`).map((c, a, g) => {
|
|
7306
|
+
const m = t ? t(c, a) : c;
|
|
7307
|
+
return a === 0 ? `${n}${m}` : a === g.length - 1 ? `${s}${m}` : `${o}${m}`;
|
|
7308
|
+
}).join(`
|
|
7309
|
+
`);
|
|
7310
|
+
}
|
|
7311
|
+
function runValidation(e, a) {
|
|
7312
|
+
if ("~standard" in e) {
|
|
7313
|
+
const n = e["~standard"].validate(a);
|
|
7314
|
+
return n instanceof Promise ? n.then((r) => r.issues?.at(0)?.message) : n.issues?.at(0)?.message;
|
|
7315
|
+
}
|
|
7316
|
+
return e(a);
|
|
7317
|
+
}
|
|
7318
|
+
var a$1, t, settings, R, CANCEL_SYMBOL, getColumns = (e) => ("columns" in e) && typeof e.columns == "number" ? e.columns : 80, getRows = (e) => ("rows" in e) && typeof e.rows == "number" ? e.rows : 20, C$1 = class C {
|
|
7319
|
+
input;
|
|
7320
|
+
output;
|
|
7321
|
+
_abortSignal;
|
|
7322
|
+
rl;
|
|
7323
|
+
opts;
|
|
7324
|
+
_render;
|
|
7325
|
+
_track = false;
|
|
7326
|
+
_prevFrame = "";
|
|
7327
|
+
_subscribers = /* @__PURE__ */ new Map;
|
|
7328
|
+
_cursor = 0;
|
|
7329
|
+
state = "initial";
|
|
7330
|
+
error = "";
|
|
7331
|
+
value;
|
|
7332
|
+
userInput = "";
|
|
7333
|
+
get accessible() {
|
|
7334
|
+
return isAccessible(this.opts.accessible);
|
|
7335
|
+
}
|
|
7336
|
+
constructor(t, e = true) {
|
|
7337
|
+
const { input: i = stdin, output: s = stdout, render: r, signal: n, ...o } = t;
|
|
7338
|
+
this.opts = o, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = r.bind(this), this._track = e, this._abortSignal = n, this.input = i, this.output = s;
|
|
7339
|
+
}
|
|
7340
|
+
unsubscribe() {
|
|
7341
|
+
this._subscribers.clear();
|
|
7342
|
+
}
|
|
7343
|
+
setSubscriber(t, e) {
|
|
7344
|
+
const i = this._subscribers.get(t) ?? [];
|
|
7345
|
+
i.push(e), this._subscribers.set(t, i);
|
|
7346
|
+
}
|
|
7347
|
+
on(t, e) {
|
|
7348
|
+
this.setSubscriber(t, { cb: e });
|
|
7349
|
+
}
|
|
7350
|
+
once(t, e) {
|
|
7351
|
+
this.setSubscriber(t, { cb: e, once: true });
|
|
7352
|
+
}
|
|
7353
|
+
emit(t, ...e) {
|
|
7354
|
+
const i = this._subscribers.get(t) ?? [], s = [];
|
|
7355
|
+
for (const r of i)
|
|
7356
|
+
r.cb(...e), r.once && s.push(() => i.splice(i.indexOf(r), 1));
|
|
7357
|
+
for (const r of s)
|
|
7358
|
+
r();
|
|
7359
|
+
}
|
|
7360
|
+
prompt() {
|
|
7361
|
+
return new Promise((t) => {
|
|
7362
|
+
if (this._abortSignal) {
|
|
7363
|
+
if (this._abortSignal.aborted)
|
|
7364
|
+
return this.state = "cancel", this.close(), t(CANCEL_SYMBOL);
|
|
7365
|
+
this._abortSignal.addEventListener("abort", () => {
|
|
7366
|
+
this.state = "cancel", this.close();
|
|
7367
|
+
}, { once: true });
|
|
7368
|
+
}
|
|
7369
|
+
this.rl = f__default.createInterface({
|
|
7370
|
+
input: this.input,
|
|
7371
|
+
tabSize: 2,
|
|
7372
|
+
prompt: "",
|
|
7373
|
+
escapeCodeTimeout: 50,
|
|
7374
|
+
terminal: true
|
|
7375
|
+
}), this.rl.prompt(), this.opts.initialUserInput !== undefined && this._setUserInput(this.opts.initialUserInput, true), this.input.on("keypress", this.onKeypress), setRawMode(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
|
|
7376
|
+
this.output.write(cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t(this.value);
|
|
7377
|
+
}), this.once("cancel", () => {
|
|
7378
|
+
this.output.write(cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t(CANCEL_SYMBOL);
|
|
7379
|
+
});
|
|
7380
|
+
});
|
|
7381
|
+
}
|
|
7382
|
+
_isActionKey(t, e) {
|
|
7383
|
+
return t === "\t";
|
|
7384
|
+
}
|
|
7385
|
+
_shouldSubmit(t, e) {
|
|
7386
|
+
return true;
|
|
7387
|
+
}
|
|
7388
|
+
_setValue(t) {
|
|
7389
|
+
this.value = t, this.emit("value", this.value);
|
|
7390
|
+
}
|
|
7391
|
+
_setUserInput(t, e) {
|
|
7392
|
+
this.userInput = t ?? "", this.emit("userInput", this.userInput), e && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
|
|
7393
|
+
}
|
|
7394
|
+
_clearUserInput() {
|
|
7395
|
+
this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
|
|
7396
|
+
}
|
|
7397
|
+
async onKeypress(t, e) {
|
|
7398
|
+
if (this.state !== "validating") {
|
|
7399
|
+
if (this._track && e.name !== "return" && (e.name && this._isActionKey(t, e) && this.rl?.write(null, { ctrl: true, name: "h" }), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), e?.name && (!this._track && settings.aliases.has(e.name) && this.emit("cursor", settings.aliases.get(e.name)), settings.actions.has(e.name) && this.emit("cursor", e.name)), t && (t.toLowerCase() === "y" || t.toLowerCase() === "n") && this.emit("confirm", t.toLowerCase() === "y"), this.emit("key", t, e), e?.name === "return" && this._shouldSubmit(t, e)) {
|
|
7400
|
+
if (this.opts.validate) {
|
|
7401
|
+
const i = runValidation(this.opts.validate, this.value);
|
|
7402
|
+
let s;
|
|
7403
|
+
i instanceof Promise ? (this.state = "validating", this.render(), s = await i) : s = i, s && (this.error = s instanceof Error ? s.message : s, this.state = "error", this.rl?.write(this.userInput));
|
|
7404
|
+
}
|
|
7405
|
+
this.state !== "error" && (this.state = "submit");
|
|
7406
|
+
}
|
|
7407
|
+
isActionKey([t, e?.name, e?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
|
|
7408
|
+
}
|
|
7409
|
+
}
|
|
7410
|
+
close() {
|
|
7411
|
+
this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
|
|
7412
|
+
`), setRawMode(this.input, false), this.rl?.close(), this.rl = undefined, this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
7413
|
+
}
|
|
7414
|
+
restoreCursor() {
|
|
7415
|
+
const t = wrapAnsi(this._prevFrame, getColumns(this.output), { hard: true, trim: false }).split(`
|
|
7416
|
+
`).length - 1;
|
|
7417
|
+
this.output.write(cursor.move(-999, t * -1));
|
|
7418
|
+
}
|
|
7419
|
+
render() {
|
|
7420
|
+
const t = wrapAnsi(this._render(this) ?? "", getColumns(this.output), {
|
|
7421
|
+
hard: true,
|
|
7422
|
+
trim: false
|
|
7423
|
+
});
|
|
7424
|
+
if (t !== this._prevFrame) {
|
|
7425
|
+
if (this.state === "initial")
|
|
7426
|
+
this.output.write(cursor.hide);
|
|
7427
|
+
else {
|
|
7428
|
+
const e = diffLines(this._prevFrame, t), i = getRows(this.output);
|
|
7429
|
+
if (this.restoreCursor(), e) {
|
|
7430
|
+
const s = Math.max(0, e.numLinesAfter - i), r = Math.max(0, e.numLinesBefore - i);
|
|
7431
|
+
let n = e.lines.find((o) => o >= s);
|
|
7432
|
+
if (n === undefined) {
|
|
7433
|
+
this._prevFrame = t;
|
|
7434
|
+
return;
|
|
7435
|
+
}
|
|
7436
|
+
if (e.lines.length === 1) {
|
|
7437
|
+
this.output.write(cursor.move(0, n - r)), this.output.write(erase.lines(1));
|
|
7438
|
+
const o = t.split(`
|
|
7439
|
+
`);
|
|
7440
|
+
this.output.write(o[n]), this._prevFrame = t, this.output.write(cursor.move(0, o.length - n - 1));
|
|
7441
|
+
return;
|
|
7442
|
+
} else if (e.lines.length > 1) {
|
|
7443
|
+
if (s < r)
|
|
7444
|
+
n = s;
|
|
7445
|
+
else {
|
|
7446
|
+
const h = n - r;
|
|
7447
|
+
h > 0 && this.output.write(cursor.move(0, h));
|
|
7448
|
+
}
|
|
7449
|
+
this.output.write(erase.down());
|
|
7450
|
+
const m = t.split(`
|
|
7451
|
+
`).slice(n);
|
|
7452
|
+
this.output.write(m.join(`
|
|
7453
|
+
`)), this._prevFrame = t;
|
|
7454
|
+
return;
|
|
7455
|
+
}
|
|
7456
|
+
}
|
|
7457
|
+
this.output.write(erase.down());
|
|
7458
|
+
}
|
|
7459
|
+
this.output.write(t), this.state === "initial" && (this.state = "active"), this._prevFrame = t;
|
|
7460
|
+
}
|
|
7461
|
+
}
|
|
7462
|
+
}, r, n$1;
|
|
7463
|
+
var init_dist6 = __esm(() => {
|
|
7464
|
+
init_main();
|
|
7465
|
+
init_dist5();
|
|
7466
|
+
init_dist4();
|
|
7467
|
+
a$1 = ["up", "down", "left", "right", "space", "enter", "cancel"];
|
|
7468
|
+
t = [
|
|
7469
|
+
"January",
|
|
7470
|
+
"February",
|
|
7471
|
+
"March",
|
|
7472
|
+
"April",
|
|
7473
|
+
"May",
|
|
7474
|
+
"June",
|
|
7475
|
+
"July",
|
|
7476
|
+
"August",
|
|
7477
|
+
"September",
|
|
7478
|
+
"October",
|
|
7479
|
+
"November",
|
|
7480
|
+
"December"
|
|
7481
|
+
];
|
|
7482
|
+
settings = {
|
|
7483
|
+
actions: new Set(a$1),
|
|
7484
|
+
aliases: /* @__PURE__ */ new Map([
|
|
7485
|
+
["k", "up"],
|
|
7486
|
+
["j", "down"],
|
|
7487
|
+
["h", "left"],
|
|
7488
|
+
["l", "right"],
|
|
7489
|
+
["\x03", "cancel"],
|
|
7490
|
+
["escape", "cancel"]
|
|
7491
|
+
]),
|
|
7492
|
+
messages: {
|
|
7493
|
+
cancel: "Canceled",
|
|
7494
|
+
error: "Something went wrong"
|
|
7495
|
+
},
|
|
7496
|
+
withGuide: true,
|
|
7497
|
+
accessible: undefined,
|
|
7498
|
+
date: {
|
|
7499
|
+
monthNames: [...t],
|
|
7500
|
+
messages: {
|
|
7501
|
+
required: "Please enter a valid date",
|
|
7502
|
+
invalidMonth: "There are only 12 months in a year",
|
|
7503
|
+
invalidDay: (n, e) => `There are only ${n} days in ${e}`,
|
|
7504
|
+
afterMin: (n) => `Date must be on or after ${n.toISOString().slice(0, 10)}`,
|
|
7505
|
+
beforeMax: (n) => `Date must be on or before ${n.toISOString().slice(0, 10)}`
|
|
7506
|
+
}
|
|
7507
|
+
}
|
|
7508
|
+
};
|
|
7509
|
+
R = globalThis.process.platform.startsWith("win");
|
|
7510
|
+
CANCEL_SYMBOL = Symbol("clack:cancel");
|
|
7511
|
+
r = class r extends C$1 {
|
|
7512
|
+
get cursor() {
|
|
7513
|
+
return this.value ? 0 : 1;
|
|
7514
|
+
}
|
|
7515
|
+
get _value() {
|
|
7516
|
+
return this.cursor === 0;
|
|
7517
|
+
}
|
|
7518
|
+
constructor(t) {
|
|
7519
|
+
super(t, false), this.value = !!t.initialValue, this.on("userInput", () => {
|
|
7520
|
+
this.value = this._value;
|
|
7521
|
+
}), this.on("confirm", (i) => {
|
|
7522
|
+
this.output.write(cursor.move(0, -1)), this.value = i, this.state = "submit", this.close();
|
|
7523
|
+
}), this.on("cursor", () => {
|
|
7524
|
+
this.value = !this.value;
|
|
7525
|
+
});
|
|
7526
|
+
}
|
|
7527
|
+
};
|
|
7528
|
+
n$1 = class n extends C$1 {
|
|
7529
|
+
options;
|
|
7530
|
+
cursor = 0;
|
|
7531
|
+
get _selectedValue() {
|
|
7532
|
+
return this.options[this.cursor];
|
|
7533
|
+
}
|
|
7534
|
+
changeValue() {
|
|
7535
|
+
const e = this._selectedValue;
|
|
7536
|
+
this.value = e === undefined ? undefined : e.value;
|
|
7537
|
+
}
|
|
7538
|
+
constructor(e) {
|
|
7539
|
+
super(e, false), this.options = e.options;
|
|
7540
|
+
const o = this.options.findIndex(({ value: s }) => s === e.initialValue), t = o === -1 ? 0 : o;
|
|
7541
|
+
this.cursor = this.options[t]?.disabled ? findCursor(t, 1, this.options) : t, this.changeValue(), this.on("cursor", (s) => {
|
|
7542
|
+
switch (s) {
|
|
7543
|
+
case "left":
|
|
7544
|
+
case "up":
|
|
7545
|
+
this.cursor = findCursor(this.cursor, -1, this.options);
|
|
7546
|
+
break;
|
|
7547
|
+
case "down":
|
|
7548
|
+
case "right":
|
|
7549
|
+
this.cursor = findCursor(this.cursor, 1, this.options);
|
|
7550
|
+
break;
|
|
7551
|
+
}
|
|
7552
|
+
this.changeValue();
|
|
7553
|
+
});
|
|
7554
|
+
}
|
|
7555
|
+
};
|
|
7556
|
+
});
|
|
7557
|
+
|
|
7558
|
+
// node_modules/@clack/prompts/dist/index.mjs
|
|
7559
|
+
import { styleText, stripVTControlCharacters } from "node:util";
|
|
7560
|
+
import process$1 from "node:process";
|
|
7561
|
+
function isUnicodeSupported() {
|
|
7562
|
+
if (process$1.platform !== "win32") {
|
|
7563
|
+
return process$1.env.TERM !== "linux";
|
|
7564
|
+
}
|
|
7565
|
+
return Boolean(process$1.env.CI) || Boolean(process$1.env.WT_SESSION) || Boolean(process$1.env.TERMINUS_SUBLIME) || process$1.env.ConEmuTask === "{cmd::Cmder}" || process$1.env.TERM_PROGRAM === "Terminus-Sublime" || process$1.env.TERM_PROGRAM === "vscode" || process$1.env.TERM === "xterm-256color" || process$1.env.TERM === "alacritty" || process$1.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
7566
|
+
}
|
|
7567
|
+
function formatInstructionFooter(e, o, r) {
|
|
7568
|
+
const s = r ? `${styleText("cyan", S_BAR)} ` : "", n = wrapTextWithPrefix(e, o.join(" • "), s).split(`
|
|
7569
|
+
`);
|
|
7570
|
+
return r && n.push(styleText("cyan", S_BAR_END)), n;
|
|
7571
|
+
}
|
|
7572
|
+
var unicode, isCI = () => process.env.CI === "true", unicodeOr = (e, o) => unicode ? e : o, S_STEP_ACTIVE, S_STEP_CANCEL, S_STEP_ERROR, S_STEP_SUBMIT, S_BAR_START, S_BAR, S_BAR_END, S_BAR_START_RIGHT, S_BAR_END_RIGHT, S_RADIO_ACTIVE, S_RADIO_INACTIVE, S_CHECKBOX_ACTIVE, S_CHECKBOX_SELECTED, S_CHECKBOX_INACTIVE, S_PASSWORD_MASK, S_BAR_H, S_CORNER_TOP_RIGHT, S_CONNECT_LEFT, S_CORNER_BOTTOM_RIGHT, S_CORNER_BOTTOM_LEFT, S_CORNER_TOP_LEFT, S_INFO, S_SUCCESS, S_WARN, S_ERROR, symbol = (e) => {
|
|
7573
|
+
switch (e) {
|
|
7574
|
+
case "initial":
|
|
7575
|
+
case "active":
|
|
7576
|
+
return styleText("cyan", S_STEP_ACTIVE);
|
|
7577
|
+
case "cancel":
|
|
7578
|
+
return styleText("red", S_STEP_CANCEL);
|
|
7579
|
+
case "error":
|
|
7580
|
+
return styleText("yellow", S_STEP_ERROR);
|
|
7581
|
+
case "submit":
|
|
7582
|
+
return styleText("green", S_STEP_SUBMIT);
|
|
7583
|
+
case "validating":
|
|
7584
|
+
return styleText("dim", S_STEP_ACTIVE);
|
|
7585
|
+
}
|
|
7586
|
+
}, symbolBar = (e) => {
|
|
7587
|
+
switch (e) {
|
|
7588
|
+
case "initial":
|
|
7589
|
+
case "active":
|
|
7590
|
+
return styleText("cyan", S_BAR);
|
|
7591
|
+
case "cancel":
|
|
7592
|
+
return styleText("red", S_BAR);
|
|
7593
|
+
case "error":
|
|
7594
|
+
return styleText("yellow", S_BAR);
|
|
7595
|
+
case "submit":
|
|
7596
|
+
return styleText("green", S_BAR);
|
|
7597
|
+
}
|
|
7598
|
+
}, E$1 = (l, e, w, p, b, C = false) => {
|
|
7599
|
+
let r = e, O = 0;
|
|
7600
|
+
if (C)
|
|
7601
|
+
for (let i = p - 1;i >= w; i--) {
|
|
7602
|
+
const m = l[i];
|
|
7603
|
+
if (m && (r -= m.length), O++, r <= b)
|
|
7604
|
+
break;
|
|
7605
|
+
}
|
|
7606
|
+
else
|
|
7607
|
+
for (let i = w;i < p; i++) {
|
|
7608
|
+
const m = l[i];
|
|
7609
|
+
if (m && (r -= m.length), O++, r <= b)
|
|
7610
|
+
break;
|
|
7611
|
+
}
|
|
7612
|
+
return { lineCount: r, removals: O };
|
|
7613
|
+
}, limitOptions = ({
|
|
7614
|
+
cursor: l,
|
|
7615
|
+
options: e,
|
|
7616
|
+
style: w,
|
|
7617
|
+
output: p = process.stdout,
|
|
7618
|
+
maxItems: b = Number.POSITIVE_INFINITY,
|
|
7619
|
+
columnPadding: C = 0,
|
|
7620
|
+
rowPadding: r = 4
|
|
7621
|
+
}) => {
|
|
7622
|
+
const i = getColumns(p) - C, m = getRows(p), M = styleText("dim", "..."), v = Math.max(m - r, 0), a = Math.max(Math.min(b, v), 5);
|
|
7623
|
+
let f = 0;
|
|
7624
|
+
l >= a - 3 && (f = Math.max(Math.min(l - a + 3, e.length - a), 0));
|
|
7625
|
+
let d = a < e.length && f > 0, c = a < e.length && f + a < e.length;
|
|
7626
|
+
const I = Math.min(f + a, e.length), s = [];
|
|
7627
|
+
let g = 0;
|
|
7628
|
+
d && g++, c && g++;
|
|
7629
|
+
const T = f + (d ? 1 : 0), W = I - (c ? 1 : 0);
|
|
7630
|
+
for (let t = T;t < W; t++) {
|
|
7631
|
+
const n = e[t], o = n !== undefined ? w(n, t === l) : "", h = wrapAnsi(o, i, {
|
|
7632
|
+
hard: true,
|
|
7633
|
+
trim: false
|
|
7634
|
+
}).split(`
|
|
7635
|
+
`);
|
|
7636
|
+
s.push(h), g += h.length;
|
|
7637
|
+
}
|
|
7638
|
+
if (g > v) {
|
|
7639
|
+
let t = 0, n = 0, o = g;
|
|
7640
|
+
const h = l - T;
|
|
7641
|
+
let u = v;
|
|
7642
|
+
const L = () => E$1(s, o, 0, h, u), y = () => E$1(s, o, h + 1, s.length, u, true);
|
|
7643
|
+
d ? ({ lineCount: o, removals: t } = L(), o > u && (c || (u -= 1), { lineCount: o, removals: n } = y())) : (c || (u -= 1), { lineCount: o, removals: n } = y(), o > u && (u -= 1, { lineCount: o, removals: t } = L())), t > 0 && (d = true, s.splice(0, t)), n > 0 && (c = true, s.splice(s.length - n, n));
|
|
7644
|
+
}
|
|
7645
|
+
const x = [];
|
|
7646
|
+
d && x.push(M);
|
|
7647
|
+
for (const t of s)
|
|
7648
|
+
for (const n of t)
|
|
7649
|
+
x.push(n);
|
|
7650
|
+
return c && x.push(M), x;
|
|
7651
|
+
}, confirm = (e) => {
|
|
7652
|
+
const a = e.active ?? "Yes", o = e.inactive ?? "No";
|
|
7653
|
+
return new r({
|
|
7654
|
+
active: a,
|
|
7655
|
+
inactive: o,
|
|
7656
|
+
signal: e.signal,
|
|
7657
|
+
input: e.input,
|
|
7658
|
+
output: e.output,
|
|
7659
|
+
initialValue: e.initialValue ?? true,
|
|
7660
|
+
render() {
|
|
7661
|
+
const i = e.withGuide ?? settings.withGuide, u = `${symbol(this.state)} `, l = i ? `${styleText("gray", S_BAR)} ` : "", f = wrapTextWithPrefix(e.output, e.message, l, u), s = `${i ? `${styleText("gray", S_BAR)}
|
|
7662
|
+
` : ""}${f}
|
|
7663
|
+
`, c = this.value ? a : o;
|
|
7664
|
+
switch (this.state) {
|
|
7665
|
+
case "submit": {
|
|
7666
|
+
const r = i ? `${styleText("gray", S_BAR)} ` : "";
|
|
7667
|
+
return `${s}${r}${styleText("dim", c)}`;
|
|
7668
|
+
}
|
|
7669
|
+
case "cancel": {
|
|
7670
|
+
const r = i ? `${styleText("gray", S_BAR)} ` : "";
|
|
7671
|
+
return `${s}${r}${styleText(["strikethrough", "dim"], c)}${i ? `
|
|
7672
|
+
${styleText("gray", S_BAR)}` : ""}`;
|
|
7673
|
+
}
|
|
7674
|
+
default: {
|
|
7675
|
+
const r = i ? `${styleText("cyan", S_BAR)} ` : "", g = i ? styleText("cyan", S_BAR_END) : "";
|
|
7676
|
+
return `${s}${r}${this.value ? `${styleText("green", S_RADIO_ACTIVE)} ${a}` : `${styleText("dim", S_RADIO_INACTIVE)} ${styleText("dim", a)}`}${e.vertical ? i ? `
|
|
7677
|
+
${styleText("cyan", S_BAR)} ` : `
|
|
7678
|
+
` : ` ${styleText("dim", "/")} `}${this.value ? `${styleText("dim", S_RADIO_INACTIVE)} ${styleText("dim", o)}` : `${styleText("green", S_RADIO_ACTIVE)} ${o}`}
|
|
7679
|
+
${g}
|
|
7680
|
+
`;
|
|
7681
|
+
}
|
|
7682
|
+
}
|
|
7683
|
+
}
|
|
7684
|
+
}).prompt();
|
|
7685
|
+
}, MULTISELECT_INSTRUCTIONS, log, W = (o) => o, C = (o, e, s) => {
|
|
7686
|
+
const a = {
|
|
7687
|
+
hard: true,
|
|
7688
|
+
trim: false
|
|
7689
|
+
}, i = wrapAnsi(o, e, a).split(`
|
|
7690
|
+
`), c = i.reduce((n, t) => Math.max(dist_default2(t), n), 0), u = i.map(s).reduce((n, t) => Math.max(dist_default2(t), n), 0), g = e - (u - c);
|
|
7691
|
+
return wrapAnsi(o, g, a);
|
|
7692
|
+
}, note = (o = "", e = "", s) => {
|
|
7693
|
+
const a = s?.output ?? process$1.stdout, i = s?.withGuide ?? settings.withGuide, c = s?.format ?? W, g = ["", ...C(o, getColumns(a) - 6, c).split(`
|
|
7694
|
+
`).map(c), ""], n = dist_default2(e), t = Math.max(g.reduce((m, F) => {
|
|
7695
|
+
const O = dist_default2(F);
|
|
7696
|
+
return O > m ? O : m;
|
|
7697
|
+
}, 0), n) + 2, h = g.map((m) => `${styleText("gray", S_BAR)} ${m}${" ".repeat(t - dist_default2(m))}${styleText("gray", S_BAR)}`).join(`
|
|
7698
|
+
`), T = i ? `${styleText("gray", S_BAR)}
|
|
7699
|
+
` : "", l$1 = i ? S_CONNECT_LEFT : S_CORNER_BOTTOM_LEFT;
|
|
7700
|
+
a.write(`${T}${styleText("green", S_STEP_SUBMIT)} ${styleText("reset", e)} ${styleText("gray", S_BAR_H.repeat(Math.max(t - n - 1, 1)) + S_CORNER_TOP_RIGHT)}
|
|
7701
|
+
${h}
|
|
7702
|
+
${styleText("gray", l$1 + S_BAR_H.repeat(t + 2) + S_CORNER_BOTTOM_RIGHT)}
|
|
7703
|
+
`);
|
|
7704
|
+
}, Y = 30000, Z = (c) => styleText("magenta", c), spinner = ({
|
|
7705
|
+
indicator: c = "dots",
|
|
7706
|
+
onCancel: b,
|
|
7707
|
+
output: n = process.stdout,
|
|
7708
|
+
cancelMessage: _,
|
|
7709
|
+
errorMessage: C,
|
|
7710
|
+
frames: M = unicode ? ["◒", "◐", "◓", "◑"] : ["•", "o", "O", "0"],
|
|
7711
|
+
delay: O = unicode ? 80 : 120,
|
|
7712
|
+
signal: g,
|
|
7713
|
+
...E
|
|
7714
|
+
} = {}) => {
|
|
7715
|
+
const u = isCI(), h = isAccessible(E.accessible);
|
|
7716
|
+
let x, I, p = false, l = false, r = "", v, w = performance.now();
|
|
7717
|
+
const y = getColumns(n), F = E?.styleFrame ?? Z, S = (e) => {
|
|
7718
|
+
const s = e > 1 ? C ?? settings.messages.error : _ ?? settings.messages.cancel;
|
|
7719
|
+
l = e === 1, p && (m(s, e), l && typeof b == "function" && b());
|
|
7720
|
+
}, $ = () => S(2), a = () => S(1), H = () => {
|
|
7721
|
+
process.on("uncaughtExceptionMonitor", $), process.on("unhandledRejection", $), process.on("SIGINT", a), process.on("SIGTERM", a), process.on("exit", S), g && g.addEventListener("abort", a);
|
|
7722
|
+
}, B = () => {
|
|
7723
|
+
process.removeListener("uncaughtExceptionMonitor", $), process.removeListener("unhandledRejection", $), process.removeListener("SIGINT", a), process.removeListener("SIGTERM", a), process.removeListener("exit", S), g && g.removeEventListener("abort", a);
|
|
7724
|
+
}, R = () => {
|
|
7725
|
+
if (v === undefined)
|
|
7726
|
+
return;
|
|
7727
|
+
u && n.write(`
|
|
7728
|
+
`);
|
|
7729
|
+
const s = wrapAnsi(v, y, {
|
|
7730
|
+
hard: true,
|
|
7731
|
+
trim: false
|
|
7732
|
+
}).split(`
|
|
7733
|
+
`);
|
|
7734
|
+
s.length > 1 && n.write(cursor.up(s.length - 1)), n.write(cursor.to(0)), n.write(erase.down());
|
|
7735
|
+
}, L = (e) => e.replace(/\.+$/, ""), T = (e) => {
|
|
7736
|
+
const s = (performance.now() - e) / 1000, i = Math.floor(s / 60), t = Math.floor(s % 60);
|
|
7737
|
+
return i > 0 ? `[${i}m ${t}s]` : `[${t}s]`;
|
|
7738
|
+
}, N = E.withGuide ?? settings.withGuide, P = (e = "") => {
|
|
7739
|
+
if (p = true, l = false, r = L(e), w = performance.now(), H(), h) {
|
|
7740
|
+
r !== "" && n.write(`${r}
|
|
7741
|
+
`), I = setInterval(() => {
|
|
7742
|
+
n.write(r === "" ? `still working
|
|
7743
|
+
` : `still working: ${r}
|
|
7744
|
+
`);
|
|
7745
|
+
}, Y);
|
|
7746
|
+
return;
|
|
7747
|
+
}
|
|
7748
|
+
x = block({ output: n }), N && n.write(`${styleText("gray", S_BAR)}
|
|
7749
|
+
`);
|
|
7750
|
+
let s = 0, i = 0;
|
|
7751
|
+
I = setInterval(() => {
|
|
7752
|
+
if (u && r === v)
|
|
7753
|
+
return;
|
|
7754
|
+
R(), v = r;
|
|
7755
|
+
const t = F(M[s]);
|
|
7756
|
+
let o;
|
|
7757
|
+
if (u)
|
|
7758
|
+
o = `${t} ${r}...`;
|
|
7759
|
+
else if (c === "timer")
|
|
7760
|
+
o = `${t} ${r} ${T(w)}`;
|
|
7761
|
+
else {
|
|
7762
|
+
const j = ".".repeat(Math.floor(i)).slice(0, 3);
|
|
7763
|
+
o = `${t} ${r}${j}`;
|
|
7764
|
+
}
|
|
7765
|
+
const D = wrapAnsi(o, y, {
|
|
7766
|
+
hard: true,
|
|
7767
|
+
trim: false
|
|
7768
|
+
});
|
|
7769
|
+
n.write(D), s = s + 1 < M.length ? s + 1 : 0, i = i < 4 ? i + 0.125 : 0;
|
|
7770
|
+
}, O);
|
|
7771
|
+
}, m = (e = "", s = 0, i = false) => {
|
|
7772
|
+
if (p) {
|
|
7773
|
+
if (p = false, l = s === 1, clearInterval(I), h || R(), r = e ?? r, !i)
|
|
7774
|
+
if (h) {
|
|
7775
|
+
const t = s === 1 ? _ ?? settings.messages.cancel : s === 2 ? C ?? settings.messages.error : "Done", o = r || t;
|
|
7776
|
+
c === "timer" ? n.write(`${o} ${T(w)}
|
|
7777
|
+
`) : n.write(`${o}
|
|
7778
|
+
`);
|
|
7779
|
+
} else {
|
|
7780
|
+
const t = s === 0 ? styleText("green", S_STEP_SUBMIT) : s === 1 ? styleText("red", S_STEP_CANCEL) : styleText("red", S_STEP_ERROR);
|
|
7781
|
+
c === "timer" ? n.write(`${t} ${r} ${T(w)}
|
|
7782
|
+
`) : n.write(`${t} ${r}
|
|
7783
|
+
`);
|
|
7784
|
+
}
|
|
7785
|
+
B(), x?.();
|
|
7786
|
+
}
|
|
7787
|
+
};
|
|
7788
|
+
return {
|
|
7789
|
+
start: P,
|
|
7790
|
+
stop: (e = "") => m(e, 0),
|
|
7791
|
+
message: (e = "") => {
|
|
7792
|
+
r = L(e ?? r);
|
|
7793
|
+
},
|
|
7794
|
+
cancel: (e = "") => m(e, 1),
|
|
7795
|
+
error: (e = "") => m(e, 2),
|
|
7796
|
+
clear: () => m("", 0, true),
|
|
7797
|
+
get isCancelled() {
|
|
7798
|
+
return l;
|
|
7799
|
+
}
|
|
7800
|
+
};
|
|
7801
|
+
}, u2, SELECT_INSTRUCTIONS, c2 = (t, o) => t.includes(`
|
|
7802
|
+
`) ? t.split(`
|
|
7803
|
+
`).map((d) => o(d)).join(`
|
|
7804
|
+
`) : o(t), select = (t) => {
|
|
7805
|
+
const o = (n, m) => {
|
|
7806
|
+
if (n === undefined)
|
|
7807
|
+
return "";
|
|
7808
|
+
const s = n.label ?? String(n.value);
|
|
7809
|
+
switch (m) {
|
|
7810
|
+
case "disabled":
|
|
7811
|
+
return `${styleText("gray", S_RADIO_INACTIVE)} ${c2(s, (i) => styleText("gray", i))}${n.hint ? ` ${styleText("dim", `(${n.hint ?? "disabled"})`)}` : ""}`;
|
|
7812
|
+
case "selected":
|
|
7813
|
+
return `${c2(s, (i) => styleText("dim", i))}`;
|
|
7814
|
+
case "active":
|
|
7815
|
+
return `${styleText("green", S_RADIO_ACTIVE)} ${s}${n.hint ? ` ${styleText("dim", `(${n.hint})`)}` : ""}`;
|
|
7816
|
+
case "cancelled":
|
|
7817
|
+
return `${c2(s, (i) => styleText(["strikethrough", "dim"], i))}`;
|
|
7818
|
+
default:
|
|
7819
|
+
return `${styleText("dim", S_RADIO_INACTIVE)} ${c2(s, (i) => styleText("dim", i))}`;
|
|
7820
|
+
}
|
|
7821
|
+
}, d = t.showInstructions ?? true;
|
|
7822
|
+
return new n$1({
|
|
7823
|
+
options: t.options,
|
|
7824
|
+
signal: t.signal,
|
|
7825
|
+
input: t.input,
|
|
7826
|
+
output: t.output,
|
|
7827
|
+
initialValue: t.initialValue,
|
|
7828
|
+
render() {
|
|
7829
|
+
const n = t.withGuide ?? settings.withGuide, m = `${symbol(this.state)} `, s = `${symbolBar(this.state)} `, i = wrapTextWithPrefix(t.output, t.message, s, m), u = `${n ? `${styleText("gray", S_BAR)}
|
|
7830
|
+
` : ""}${i}
|
|
7831
|
+
`;
|
|
7832
|
+
switch (this.state) {
|
|
7833
|
+
case "submit": {
|
|
7834
|
+
const r = n ? `${styleText("gray", S_BAR)} ` : "", a = wrapTextWithPrefix(t.output, o(this.options[this.cursor], "selected"), r);
|
|
7835
|
+
return `${u}${a}`;
|
|
7836
|
+
}
|
|
7837
|
+
case "cancel": {
|
|
7838
|
+
const r = n ? `${styleText("gray", S_BAR)} ` : "", a = wrapTextWithPrefix(t.output, o(this.options[this.cursor], "cancelled"), r);
|
|
7839
|
+
return `${u}${a}${n ? `
|
|
7840
|
+
${styleText("gray", S_BAR)}` : ""}`;
|
|
7841
|
+
}
|
|
7842
|
+
default: {
|
|
7843
|
+
const r = n ? `${styleText("cyan", S_BAR)} ` : "", a = u.split(`
|
|
7844
|
+
`).length, p = d ? formatInstructionFooter(t.output, SELECT_INSTRUCTIONS, n) : n ? [styleText("cyan", S_BAR_END)] : [], f = p.join(`
|
|
7845
|
+
`), b = p.length + 1;
|
|
7846
|
+
return `${u}${r}${limitOptions({
|
|
7847
|
+
output: t.output,
|
|
7848
|
+
cursor: this.cursor,
|
|
7849
|
+
options: this.options,
|
|
7850
|
+
maxItems: t.maxItems,
|
|
7851
|
+
columnPadding: r.length,
|
|
7852
|
+
rowPadding: a + b,
|
|
7853
|
+
style: (g, x) => o(g, g.disabled ? "disabled" : x ? "active" : "inactive")
|
|
7854
|
+
}).join(`
|
|
7855
|
+
${r}`)}
|
|
7856
|
+
${f}
|
|
7857
|
+
`;
|
|
7858
|
+
}
|
|
7859
|
+
}
|
|
7860
|
+
}
|
|
7861
|
+
}).prompt();
|
|
7862
|
+
}, i;
|
|
7863
|
+
var init_dist7 = __esm(() => {
|
|
7864
|
+
init_dist6();
|
|
7865
|
+
init_dist6();
|
|
7866
|
+
init_main();
|
|
7867
|
+
init_dist4();
|
|
7868
|
+
init_dist5();
|
|
7869
|
+
unicode = isUnicodeSupported();
|
|
7870
|
+
S_STEP_ACTIVE = unicodeOr("◆", "*");
|
|
7871
|
+
S_STEP_CANCEL = unicodeOr("■", "x");
|
|
7872
|
+
S_STEP_ERROR = unicodeOr("▲", "x");
|
|
7873
|
+
S_STEP_SUBMIT = unicodeOr("◇", "o");
|
|
7874
|
+
S_BAR_START = unicodeOr("┌", "T");
|
|
7875
|
+
S_BAR = unicodeOr("│", "|");
|
|
7876
|
+
S_BAR_END = unicodeOr("└", "—");
|
|
7877
|
+
S_BAR_START_RIGHT = unicodeOr("┐", "T");
|
|
7878
|
+
S_BAR_END_RIGHT = unicodeOr("┘", "—");
|
|
7879
|
+
S_RADIO_ACTIVE = unicodeOr("●", ">");
|
|
7880
|
+
S_RADIO_INACTIVE = unicodeOr("○", " ");
|
|
7881
|
+
S_CHECKBOX_ACTIVE = unicodeOr("◻", "[•]");
|
|
7882
|
+
S_CHECKBOX_SELECTED = unicodeOr("◼", "[+]");
|
|
7883
|
+
S_CHECKBOX_INACTIVE = unicodeOr("◻", "[ ]");
|
|
7884
|
+
S_PASSWORD_MASK = unicodeOr("▪", "•");
|
|
7885
|
+
S_BAR_H = unicodeOr("─", "-");
|
|
7886
|
+
S_CORNER_TOP_RIGHT = unicodeOr("╮", "+");
|
|
7887
|
+
S_CONNECT_LEFT = unicodeOr("├", "+");
|
|
7888
|
+
S_CORNER_BOTTOM_RIGHT = unicodeOr("╯", "+");
|
|
7889
|
+
S_CORNER_BOTTOM_LEFT = unicodeOr("╰", "+");
|
|
7890
|
+
S_CORNER_TOP_LEFT = unicodeOr("╭", "+");
|
|
7891
|
+
S_INFO = unicodeOr("●", "•");
|
|
7892
|
+
S_SUCCESS = unicodeOr("◆", "*");
|
|
7893
|
+
S_WARN = unicodeOr("▲", "!");
|
|
7894
|
+
S_ERROR = unicodeOr("■", "x");
|
|
7895
|
+
MULTISELECT_INSTRUCTIONS = [
|
|
7896
|
+
`${styleText("dim", "↑/↓")} to navigate`,
|
|
7897
|
+
`${styleText("dim", "Space:")} select`,
|
|
7898
|
+
`${styleText("dim", "Enter:")} confirm`
|
|
7899
|
+
];
|
|
7900
|
+
log = {
|
|
7901
|
+
message: (s = [], {
|
|
7902
|
+
symbol: e = styleText("gray", S_BAR),
|
|
7903
|
+
secondarySymbol: r = styleText("gray", S_BAR),
|
|
7904
|
+
output: m = process.stdout,
|
|
7905
|
+
spacing: l = 1,
|
|
7906
|
+
withGuide: c
|
|
7907
|
+
} = {}) => {
|
|
7908
|
+
const t = [], o = c ?? settings.withGuide, f = o ? r : "", O = o ? `${e} ` : "", u = o ? `${r} ` : "";
|
|
7909
|
+
for (let i = 0;i < l; i++)
|
|
7910
|
+
t.push(f);
|
|
7911
|
+
const g = Array.isArray(s) ? s : s.split(`
|
|
7912
|
+
`);
|
|
7913
|
+
if (g.length > 0) {
|
|
7914
|
+
const [i, ...y] = g;
|
|
7915
|
+
i.length > 0 ? t.push(`${O}${i}`) : t.push(o ? e : "");
|
|
7916
|
+
for (const p of y)
|
|
7917
|
+
p.length > 0 ? t.push(`${u}${p}`) : t.push(o ? r : "");
|
|
7918
|
+
}
|
|
7919
|
+
m.write(`${t.join(`
|
|
7920
|
+
`)}
|
|
7921
|
+
`);
|
|
7922
|
+
},
|
|
7923
|
+
info: (s, e) => {
|
|
7924
|
+
log.message(s, { ...e, symbol: styleText("blue", S_INFO) });
|
|
7925
|
+
},
|
|
7926
|
+
success: (s, e) => {
|
|
7927
|
+
log.message(s, { ...e, symbol: styleText("green", S_SUCCESS) });
|
|
7928
|
+
},
|
|
7929
|
+
step: (s, e) => {
|
|
7930
|
+
log.message(s, { ...e, symbol: styleText("green", S_STEP_SUBMIT) });
|
|
7931
|
+
},
|
|
7932
|
+
warn: (s, e) => {
|
|
7933
|
+
log.message(s, { ...e, symbol: styleText("yellow", S_WARN) });
|
|
7934
|
+
},
|
|
7935
|
+
warning: (s, e) => {
|
|
7936
|
+
log.warn(s, e);
|
|
7937
|
+
},
|
|
7938
|
+
error: (s, e) => {
|
|
7939
|
+
log.message(s, { ...e, symbol: styleText("red", S_ERROR) });
|
|
7940
|
+
}
|
|
7941
|
+
};
|
|
7942
|
+
u2 = {
|
|
7943
|
+
light: unicodeOr("─", "-"),
|
|
7944
|
+
heavy: unicodeOr("━", "="),
|
|
7945
|
+
block: unicodeOr("█", "#")
|
|
7946
|
+
};
|
|
7947
|
+
SELECT_INSTRUCTIONS = [
|
|
7948
|
+
`${styleText("dim", "↑/↓")} to navigate`,
|
|
7949
|
+
`${styleText("dim", "Enter:")} confirm`
|
|
7950
|
+
];
|
|
7951
|
+
i = `${styleText("gray", S_BAR)} `;
|
|
7952
|
+
});
|
|
7953
|
+
|
|
6824
7954
|
// node_modules/@crustjs/prompts/dist/index.js
|
|
6825
7955
|
import * as readline from "node:readline";
|
|
6826
7956
|
function themeFromStyle(s) {
|
|
@@ -7057,7 +8187,7 @@ function calculateScrollOffset(cursor, scrollOffset, totalItems, maxVisible) {
|
|
|
7057
8187
|
return cursor - visibleCount + 1;
|
|
7058
8188
|
return scrollOffset;
|
|
7059
8189
|
}
|
|
7060
|
-
function
|
|
8190
|
+
function moveCursor3(cursor, totalItems, delta, scrollOffset, maxVisible) {
|
|
7061
8191
|
if (totalItems === 0)
|
|
7062
8192
|
return {
|
|
7063
8193
|
cursor: 0,
|
|
@@ -7112,7 +8242,7 @@ function renderSubmitted$6(value, theme, message, activeLabel, inactiveLabel) {
|
|
|
7112
8242
|
const answer = value ? activeLabel : inactiveLabel;
|
|
7113
8243
|
return formatSubmitted(prefix, msg, theme.success(answer));
|
|
7114
8244
|
}
|
|
7115
|
-
async function
|
|
8245
|
+
async function confirm2(options, io) {
|
|
7116
8246
|
const shortCircuit = await resolveShortCircuit(options, io);
|
|
7117
8247
|
if (shortCircuit.shortCircuited)
|
|
7118
8248
|
return shortCircuit.value;
|
|
@@ -7217,7 +8347,7 @@ function createHandleKey$1(maxVisible, required, min, max) {
|
|
|
7217
8347
|
const delta = key.name === "up" || key.name === "k" ? -1 : 1;
|
|
7218
8348
|
return {
|
|
7219
8349
|
...state,
|
|
7220
|
-
...
|
|
8350
|
+
...moveCursor3(state.cursor, totalItems, delta, state.scrollOffset, maxVisible),
|
|
7221
8351
|
error: null
|
|
7222
8352
|
};
|
|
7223
8353
|
}
|
|
@@ -7261,8 +8391,8 @@ async function multiselect(options, io) {
|
|
|
7261
8391
|
renderSubmitted: (state, _value, t) => renderSubmitted$2(state, t, options.message)
|
|
7262
8392
|
}, promptIO);
|
|
7263
8393
|
}
|
|
7264
|
-
var defaultTheme, SUBMIT, activeInputs, activeOutputs,
|
|
7265
|
-
var
|
|
8394
|
+
var defaultTheme, SUBMIT, activeInputs, activeOutputs, ESC3 = "\x1B[", HIDE_CURSOR, SHOW_CURSOR, NonInteractiveError, SEPARATOR = " · ", HINT_LINE = "(Space to toggle, a to toggle all, i to invert, Enter to confirm)";
|
|
8395
|
+
var init_dist8 = __esm(() => {
|
|
7266
8396
|
init_dist2();
|
|
7267
8397
|
init_terminal();
|
|
7268
8398
|
defaultTheme = themeFromStyle({
|
|
@@ -7275,8 +8405,8 @@ var init_dist3 = __esm(() => {
|
|
|
7275
8405
|
SUBMIT = Symbol("submit");
|
|
7276
8406
|
activeInputs = /* @__PURE__ */ new WeakSet;
|
|
7277
8407
|
activeOutputs = /* @__PURE__ */ new WeakSet;
|
|
7278
|
-
HIDE_CURSOR = `${
|
|
7279
|
-
SHOW_CURSOR = `${
|
|
8408
|
+
HIDE_CURSOR = `${ESC3}?25l`;
|
|
8409
|
+
SHOW_CURSOR = `${ESC3}?25h`;
|
|
7280
8410
|
NonInteractiveError = class extends Error {
|
|
7281
8411
|
constructor(message) {
|
|
7282
8412
|
super(message ?? "Prompts require an interactive terminal (TTY).");
|
|
@@ -18736,6 +19866,89 @@ var $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
|
|
|
18736
19866
|
});
|
|
18737
19867
|
};
|
|
18738
19868
|
});
|
|
19869
|
+
function discriminatorMap(def) {
|
|
19870
|
+
const map = new Map;
|
|
19871
|
+
for (const option of def.options) {
|
|
19872
|
+
const values = option._zod.propValues?.[def.discriminator];
|
|
19873
|
+
if (!values || values.size === 0)
|
|
19874
|
+
throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
|
|
19875
|
+
for (const value of values) {
|
|
19876
|
+
if (map.has(value)) {
|
|
19877
|
+
if (value !== undefined)
|
|
19878
|
+
throw new Error(`Duplicate discriminator value "${String(value)}"`);
|
|
19879
|
+
map.set(value, null);
|
|
19880
|
+
} else {
|
|
19881
|
+
map.set(value, option);
|
|
19882
|
+
}
|
|
19883
|
+
}
|
|
19884
|
+
}
|
|
19885
|
+
return map;
|
|
19886
|
+
}
|
|
19887
|
+
var $ZodDiscriminatedUnion = /* @__PURE__ */ $constructor("$ZodDiscriminatedUnion", (inst, def) => {
|
|
19888
|
+
def.inclusive = false;
|
|
19889
|
+
$ZodUnion.init(inst, def);
|
|
19890
|
+
const _super = inst._zod.parse;
|
|
19891
|
+
defineLazyInternal(inst, "propValues", (zod) => {
|
|
19892
|
+
const propValues = {};
|
|
19893
|
+
let undefinedCount = 0;
|
|
19894
|
+
for (const option of zod.def.options) {
|
|
19895
|
+
const pv = option._zod.propValues;
|
|
19896
|
+
if (!pv || Object.keys(pv).length === 0)
|
|
19897
|
+
throw new Error(`Invalid discriminated union option at index "${zod.def.options.indexOf(option)}"`);
|
|
19898
|
+
if (pv[zod.def.discriminator]?.has(undefined))
|
|
19899
|
+
undefinedCount++;
|
|
19900
|
+
for (const [k, v] of Object.entries(pv)) {
|
|
19901
|
+
if (!Object.prototype.hasOwnProperty.call(propValues, k)) {
|
|
19902
|
+
assignProp(propValues, k, new Set);
|
|
19903
|
+
}
|
|
19904
|
+
for (const val of v) {
|
|
19905
|
+
propValues[k].add(val);
|
|
19906
|
+
}
|
|
19907
|
+
}
|
|
19908
|
+
}
|
|
19909
|
+
if (!zod.def.unionFallback && undefinedCount > 1)
|
|
19910
|
+
propValues[zod.def.discriminator]?.delete(undefined);
|
|
19911
|
+
return propValues;
|
|
19912
|
+
});
|
|
19913
|
+
def.options.forEach((option, i) => {
|
|
19914
|
+
const propShape = rawShape(option._zod.def);
|
|
19915
|
+
if (propShape && !Object.prototype.hasOwnProperty.call(propShape, def.discriminator)) {
|
|
19916
|
+
throw new Error(`Invalid discriminated union option at index "${i}"`);
|
|
19917
|
+
}
|
|
19918
|
+
});
|
|
19919
|
+
const disc = cached(() => discriminatorMap(def));
|
|
19920
|
+
inst._zod.parse = (payload, ctx) => {
|
|
19921
|
+
const input = payload.value;
|
|
19922
|
+
if (!isObject(input)) {
|
|
19923
|
+
payload.issues.push({
|
|
19924
|
+
code: "invalid_type",
|
|
19925
|
+
expected: "object",
|
|
19926
|
+
input,
|
|
19927
|
+
inst
|
|
19928
|
+
});
|
|
19929
|
+
return payload;
|
|
19930
|
+
}
|
|
19931
|
+
const value = input?.[def.discriminator];
|
|
19932
|
+
const opt = disc.value.get(value);
|
|
19933
|
+
if (opt && (value !== undefined || ctx.direction !== "backward")) {
|
|
19934
|
+
return opt._zod.run(payload, ctx);
|
|
19935
|
+
}
|
|
19936
|
+
if (def.unionFallback || ctx.direction === "backward") {
|
|
19937
|
+
return _super(payload, ctx);
|
|
19938
|
+
}
|
|
19939
|
+
payload.issues.push({
|
|
19940
|
+
code: "invalid_union",
|
|
19941
|
+
errors: [],
|
|
19942
|
+
note: "No matching discriminator",
|
|
19943
|
+
discriminator: def.discriminator,
|
|
19944
|
+
options: Array.from(disc.value.keys()).filter((value) => disc.value.get(value) !== null),
|
|
19945
|
+
input,
|
|
19946
|
+
path: [def.discriminator],
|
|
19947
|
+
inst
|
|
19948
|
+
});
|
|
19949
|
+
return payload;
|
|
19950
|
+
};
|
|
19951
|
+
});
|
|
18739
19952
|
var $ZodIntersection = /* @__PURE__ */ $constructor("$ZodIntersection", (inst, def) => {
|
|
18740
19953
|
$ZodType.init(inst, def);
|
|
18741
19954
|
inst._zod.parse = (payload, ctx) => {
|
|
@@ -21316,6 +22529,7 @@ var initializer2 = (inst, issues) => {
|
|
|
21316
22529
|
}
|
|
21317
22530
|
});
|
|
21318
22531
|
};
|
|
22532
|
+
var ZodError = /* @__PURE__ */ $constructor("ZodError", initializer2);
|
|
21319
22533
|
var ZodRealError = /* @__PURE__ */ $constructor("ZodError", initializer2, undefined, {
|
|
21320
22534
|
Parent: Error
|
|
21321
22535
|
});
|
|
@@ -21972,6 +23186,18 @@ function union(options, params) {
|
|
|
21972
23186
|
...normalizeParams(params)
|
|
21973
23187
|
});
|
|
21974
23188
|
}
|
|
23189
|
+
var ZodDiscriminatedUnion = /* @__PURE__ */ $constructor("ZodDiscriminatedUnion", (inst, def) => {
|
|
23190
|
+
ZodUnion.init(inst, def);
|
|
23191
|
+
$ZodDiscriminatedUnion.init(inst, def);
|
|
23192
|
+
});
|
|
23193
|
+
function discriminatedUnion(discriminator, options, params) {
|
|
23194
|
+
return new ZodDiscriminatedUnion({
|
|
23195
|
+
type: "union",
|
|
23196
|
+
options,
|
|
23197
|
+
discriminator,
|
|
23198
|
+
...normalizeParams(params)
|
|
23199
|
+
});
|
|
23200
|
+
}
|
|
21975
23201
|
var ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
|
|
21976
23202
|
$ZodIntersection.init(inst, def);
|
|
21977
23203
|
ZodType.init(inst, def);
|
|
@@ -34497,10 +35723,39 @@ function anchorSkillSources(layer) {
|
|
|
34497
35723
|
}
|
|
34498
35724
|
|
|
34499
35725
|
// src/ui.ts
|
|
34500
|
-
|
|
35726
|
+
init_dist7();
|
|
35727
|
+
init_dist8();
|
|
35728
|
+
import { styleText as styleText2 } from "node:util";
|
|
34501
35729
|
var Ui = {
|
|
34502
35730
|
async confirm(message) {
|
|
34503
|
-
|
|
35731
|
+
await Promise.resolve().then(() => init_dist8());
|
|
35732
|
+
return await confirm2({ default: false, message });
|
|
35733
|
+
},
|
|
35734
|
+
async pick(message, options) {
|
|
35735
|
+
const value = await select({ message, options, output: process.stderr });
|
|
35736
|
+
return isCancel(value) ? null : value;
|
|
35737
|
+
},
|
|
35738
|
+
async confirmReset(message) {
|
|
35739
|
+
await Promise.resolve().then(() => init_dist7());
|
|
35740
|
+
const value = await confirm({ message, initialValue: false, output: process.stderr });
|
|
35741
|
+
return !isCancel(value) && value;
|
|
35742
|
+
},
|
|
35743
|
+
style(format, text, enabled = true) {
|
|
35744
|
+
const forced = process.env.FORCE_COLOR;
|
|
35745
|
+
const supported = forced === undefined ? Boolean(process.stdout.isTTY) && process.env.TERM !== "dumb" : forced !== "0";
|
|
35746
|
+
if (!enabled || process.env.NO_COLOR !== undefined || !supported) {
|
|
35747
|
+
return text;
|
|
35748
|
+
}
|
|
35749
|
+
return styleText2(format, text, { validateStream: false });
|
|
35750
|
+
},
|
|
35751
|
+
success(message) {
|
|
35752
|
+
log.success(message, { output: process.stdout, withGuide: false });
|
|
35753
|
+
},
|
|
35754
|
+
note(message, title) {
|
|
35755
|
+
note(message, title, { output: process.stdout, withGuide: false });
|
|
35756
|
+
},
|
|
35757
|
+
spinner() {
|
|
35758
|
+
return spinner({ output: process.stderr, withGuide: false });
|
|
34504
35759
|
},
|
|
34505
35760
|
info(message) {
|
|
34506
35761
|
process.stderr.write(`${message}
|
|
@@ -34691,25 +35946,248 @@ function parseAgents(values) {
|
|
|
34691
35946
|
|
|
34692
35947
|
// src/init/index.ts
|
|
34693
35948
|
import { mkdir as mkdir3, writeFile as writeFile3 } from "node:fs/promises";
|
|
34694
|
-
import
|
|
35949
|
+
import path16 from "node:path";
|
|
34695
35950
|
|
|
34696
35951
|
// src/init/discover.ts
|
|
34697
35952
|
import { realpath as realpath3 } from "node:fs/promises";
|
|
34698
|
-
import
|
|
35953
|
+
import path15 from "node:path";
|
|
34699
35954
|
|
|
34700
|
-
// src/harness/adapters/claude-code.ts
|
|
34701
|
-
import { execFile } from "node:child_process";
|
|
35955
|
+
// src/harness/adapters/claude-code/index.ts
|
|
35956
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
34702
35957
|
import { existsSync as existsSync3 } from "node:fs";
|
|
34703
35958
|
import { homedir as homedir4 } from "node:os";
|
|
34704
|
-
import
|
|
35959
|
+
import path9 from "node:path";
|
|
35960
|
+
import { promisify as promisify2 } from "node:util";
|
|
35961
|
+
|
|
35962
|
+
// src/harness/adapters/claude-code/usage.ts
|
|
35963
|
+
import { execFile } from "node:child_process";
|
|
35964
|
+
import path7 from "node:path";
|
|
34705
35965
|
import { promisify } from "node:util";
|
|
34706
35966
|
|
|
34707
|
-
// src/
|
|
34708
|
-
|
|
34709
|
-
|
|
34710
|
-
|
|
34711
|
-
|
|
34712
|
-
|
|
35967
|
+
// src/usage/auth.ts
|
|
35968
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
35969
|
+
async function readCredentialsFile(file, schema) {
|
|
35970
|
+
try {
|
|
35971
|
+
return schema.parse(JSON.parse(await readFile2(file, "utf-8")));
|
|
35972
|
+
} catch (error) {
|
|
35973
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
35974
|
+
return null;
|
|
35975
|
+
}
|
|
35976
|
+
throw new Error(`Cannot read provider credentials at ${file}. Sign in with the provider CLI again.`);
|
|
35977
|
+
}
|
|
35978
|
+
}
|
|
35979
|
+
|
|
35980
|
+
// src/usage/http.ts
|
|
35981
|
+
async function request(provider, url, headers, init, transport) {
|
|
35982
|
+
let response;
|
|
35983
|
+
try {
|
|
35984
|
+
response = await transport(url, {
|
|
35985
|
+
...init,
|
|
35986
|
+
headers,
|
|
35987
|
+
redirect: "error",
|
|
35988
|
+
signal: AbortSignal.timeout(25000)
|
|
35989
|
+
});
|
|
35990
|
+
} catch {
|
|
35991
|
+
throw new Error(`${provider}: request failed or timed out.${init.method === "POST" ? " Reset claims may have succeeded; retry with the same credit and request IDs." : " Check your connection and try again."}`);
|
|
35992
|
+
}
|
|
35993
|
+
if (response.status === 401 || response.status === 403) {
|
|
35994
|
+
throw new Error(`${provider}: Sign in with the provider CLI again (HTTP ${response.status}).`);
|
|
35995
|
+
}
|
|
35996
|
+
if (!response.ok) {
|
|
35997
|
+
throw new Error(`${provider}: request failed (HTTP ${response.status})${response.status === 429 ? "; try again later" : ""}.`);
|
|
35998
|
+
}
|
|
35999
|
+
try {
|
|
36000
|
+
return await response.json();
|
|
36001
|
+
} catch {
|
|
36002
|
+
throw new Error(`${provider}: invalid JSON response.`);
|
|
36003
|
+
}
|
|
36004
|
+
}
|
|
36005
|
+
|
|
36006
|
+
// src/harness/adapters/claude-code/usage.ts
|
|
36007
|
+
var PercentSchema = number2().finite().min(0);
|
|
36008
|
+
var CountSchema = number2().int().nonnegative();
|
|
36009
|
+
var ExpirySchema = union([string2().datetime({ offset: true }), number2().finite()]).nullish();
|
|
36010
|
+
var ClaudeWindowSchema = object({
|
|
36011
|
+
utilization: PercentSchema,
|
|
36012
|
+
resets_at: string2().datetime({ offset: true }).nullish()
|
|
36013
|
+
});
|
|
36014
|
+
var GrantsSchema = object({
|
|
36015
|
+
eligible: boolean2(),
|
|
36016
|
+
ineligible_reason: string2().nullish(),
|
|
36017
|
+
grants: array(object({
|
|
36018
|
+
id: string2().regex(/^[a-z0-9_-]{1,40}$/u),
|
|
36019
|
+
resets_left: CountSchema,
|
|
36020
|
+
ends_at: ExpirySchema,
|
|
36021
|
+
paused: boolean2().optional(),
|
|
36022
|
+
usable_now: boolean2().optional(),
|
|
36023
|
+
clears: array(string2()).optional(),
|
|
36024
|
+
type: string2().optional(),
|
|
36025
|
+
gives_back_weekly: boolean2().optional()
|
|
36026
|
+
})).optional()
|
|
36027
|
+
});
|
|
36028
|
+
var ClaudeSchema = object({ cedar_ember: unknown().optional() }).catchall(unknown());
|
|
36029
|
+
function parseClaude(raw, now) {
|
|
36030
|
+
const body = ClaudeSchema.parse(raw);
|
|
36031
|
+
const windows = Object.entries(body).flatMap(([key, value]) => {
|
|
36032
|
+
if (key === "seven_day_breakdown" || !key.startsWith("five_hour") && !key.startsWith("seven_day")) {
|
|
36033
|
+
return [];
|
|
36034
|
+
}
|
|
36035
|
+
if (value === null) {
|
|
36036
|
+
return [];
|
|
36037
|
+
}
|
|
36038
|
+
const window2 = ClaudeWindowSchema.parse(value);
|
|
36039
|
+
return [
|
|
36040
|
+
{
|
|
36041
|
+
id: key,
|
|
36042
|
+
label: key.replaceAll("_", " "),
|
|
36043
|
+
usedPercent: window2.utilization,
|
|
36044
|
+
resetsAt: window2.resets_at ?? null
|
|
36045
|
+
}
|
|
36046
|
+
];
|
|
36047
|
+
});
|
|
36048
|
+
const parsedGrants = GrantsSchema.safeParse(body.cedar_ember);
|
|
36049
|
+
const grants = parsedGrants.success ? parsedGrants.data : null;
|
|
36050
|
+
const credits = (grants?.grants ?? []).map((grant) => {
|
|
36051
|
+
const expiresAt = timestamp(grant.ends_at);
|
|
36052
|
+
return {
|
|
36053
|
+
id: grant.id,
|
|
36054
|
+
count: grant.resets_left,
|
|
36055
|
+
label: grant.gives_back_weekly ? "Fable reset (returns Fable weekly usage)" : grant.type ?? ((grant.clears ?? []).join(", ") || "Reset"),
|
|
36056
|
+
expiresAt,
|
|
36057
|
+
restores: grant.clears ?? [],
|
|
36058
|
+
expiry: expiryStatus(grant.ends_at),
|
|
36059
|
+
canClaim: grants?.eligible === true && grant.usable_now === true && !grant.paused && grant.resets_left > 0 && (!expiresAt || Date.parse(expiresAt) > now)
|
|
36060
|
+
};
|
|
36061
|
+
});
|
|
36062
|
+
return {
|
|
36063
|
+
provider: "claude",
|
|
36064
|
+
account: { name: null, id: null },
|
|
36065
|
+
plan: null,
|
|
36066
|
+
windows,
|
|
36067
|
+
limited: windows.some((window2) => window2.usedPercent >= 100),
|
|
36068
|
+
resets: {
|
|
36069
|
+
available: grants ? credits.filter((credit) => credit.canClaim).reduce((sum, credit) => sum + credit.count, 0) : null,
|
|
36070
|
+
credits,
|
|
36071
|
+
note: grantNote(grants)
|
|
36072
|
+
}
|
|
36073
|
+
};
|
|
36074
|
+
}
|
|
36075
|
+
function timestamp(value) {
|
|
36076
|
+
if (value === null || value === undefined) {
|
|
36077
|
+
return null;
|
|
36078
|
+
}
|
|
36079
|
+
return new Date(typeof value === "number" ? value * 1000 : value).toISOString();
|
|
36080
|
+
}
|
|
36081
|
+
function grantNote(grants) {
|
|
36082
|
+
if (!grants) {
|
|
36083
|
+
return "Reset grants not reported.";
|
|
36084
|
+
}
|
|
36085
|
+
if (!grants.eligible) {
|
|
36086
|
+
return `Not eligible for resets: ${grants.ineligible_reason ?? "provider restriction"}.`;
|
|
36087
|
+
}
|
|
36088
|
+
return null;
|
|
36089
|
+
}
|
|
36090
|
+
function expiryStatus(value) {
|
|
36091
|
+
if (value === undefined) {
|
|
36092
|
+
return "unknown";
|
|
36093
|
+
}
|
|
36094
|
+
return value === null ? "never" : "dated";
|
|
36095
|
+
}
|
|
36096
|
+
var Run = promisify(execFile);
|
|
36097
|
+
var ClaudeBase = "https://api.anthropic.com/api";
|
|
36098
|
+
var AuthSchema = object({
|
|
36099
|
+
claudeAiOauth: object({ accessToken: string2().min(1) }).optional()
|
|
36100
|
+
});
|
|
36101
|
+
var ConfigSchema = object({
|
|
36102
|
+
oauthAccount: object({
|
|
36103
|
+
organizationUuid: string2().optional(),
|
|
36104
|
+
accountUuid: string2().optional(),
|
|
36105
|
+
emailAddress: string2().optional(),
|
|
36106
|
+
displayName: string2().optional()
|
|
36107
|
+
}).optional()
|
|
36108
|
+
});
|
|
36109
|
+
function createClaudeUsage(directory, configFile, transport = fetch, now = Date.now) {
|
|
36110
|
+
return {
|
|
36111
|
+
provider: "claude",
|
|
36112
|
+
async connect() {
|
|
36113
|
+
const credentials = await readCredentials(directory(), configFile());
|
|
36114
|
+
if (!credentials) {
|
|
36115
|
+
return null;
|
|
36116
|
+
}
|
|
36117
|
+
return {
|
|
36118
|
+
read: () => readClaudeUsage(credentials, transport, now()),
|
|
36119
|
+
claimReset: (claim) => claimClaudeReset(credentials, claim.creditId, claim.requestId, transport)
|
|
36120
|
+
};
|
|
36121
|
+
}
|
|
36122
|
+
};
|
|
36123
|
+
}
|
|
36124
|
+
async function readCredentials(directory, configFile) {
|
|
36125
|
+
let auth = await readCredentialsFile(path7.join(directory, ".credentials.json"), AuthSchema);
|
|
36126
|
+
if (auth === null && process.platform === "darwin") {
|
|
36127
|
+
try {
|
|
36128
|
+
const result = await Run("security", ["find-generic-password", "-s", "Claude Code-credentials", "-w"], { timeout: 5000 });
|
|
36129
|
+
auth = AuthSchema.parse(JSON.parse(result.stdout));
|
|
36130
|
+
} catch {
|
|
36131
|
+
return null;
|
|
36132
|
+
}
|
|
36133
|
+
}
|
|
36134
|
+
if (!auth?.claudeAiOauth) {
|
|
36135
|
+
return null;
|
|
36136
|
+
}
|
|
36137
|
+
const config = await readCredentialsFile(configFile, ConfigSchema);
|
|
36138
|
+
return {
|
|
36139
|
+
token: auth.claudeAiOauth.accessToken,
|
|
36140
|
+
accountId: config?.oauthAccount?.accountUuid,
|
|
36141
|
+
accountName: config?.oauthAccount?.emailAddress ?? config?.oauthAccount?.displayName,
|
|
36142
|
+
organizationId: config?.oauthAccount?.organizationUuid
|
|
36143
|
+
};
|
|
36144
|
+
}
|
|
36145
|
+
async function readClaudeUsage(credentials, transport = fetch, now = Date.now()) {
|
|
36146
|
+
const body = await request("claude", `${ClaudeBase}/oauth/usage?cedar_ember=1`, claudeHeaders(credentials), {}, transport);
|
|
36147
|
+
return {
|
|
36148
|
+
...parseClaude(body, now),
|
|
36149
|
+
account: { name: credentials.accountName ?? null, id: credentials.accountId ?? null }
|
|
36150
|
+
};
|
|
36151
|
+
}
|
|
36152
|
+
async function claimClaudeReset(credentials, creditId, requestId, transport = fetch) {
|
|
36153
|
+
if (!/^[a-z0-9_-]{1,40}$/u.test(creditId)) {
|
|
36154
|
+
throw new Error("Invalid Claude grant ID.");
|
|
36155
|
+
}
|
|
36156
|
+
if (!credentials.organizationId) {
|
|
36157
|
+
throw new Error("Claude organization is missing. Sign in with Claude Code again.");
|
|
36158
|
+
}
|
|
36159
|
+
const body = await request("claude", `${ClaudeBase}/organizations/${encodeURIComponent(credentials.organizationId)}/reset_rate_limits`, claudeHeaders(credentials), {
|
|
36160
|
+
method: "POST",
|
|
36161
|
+
body: JSON.stringify({ program: "cedar_ember", grant_id: creditId, request_id: requestId })
|
|
36162
|
+
}, transport);
|
|
36163
|
+
const outcome = object({
|
|
36164
|
+
result: _enum([
|
|
36165
|
+
"reset",
|
|
36166
|
+
"already_used",
|
|
36167
|
+
"not_limited",
|
|
36168
|
+
"cooldown",
|
|
36169
|
+
"ineligible",
|
|
36170
|
+
"unavailable"
|
|
36171
|
+
])
|
|
36172
|
+
}).parse(body).result;
|
|
36173
|
+
return { outcome, success: outcome === "reset" || outcome === "already_used" };
|
|
36174
|
+
}
|
|
36175
|
+
function claudeHeaders(credentials) {
|
|
36176
|
+
return {
|
|
36177
|
+
Authorization: `Bearer ${credentials.token}`,
|
|
36178
|
+
Accept: "application/json",
|
|
36179
|
+
"Content-Type": "application/json",
|
|
36180
|
+
"anthropic-beta": "oauth-2025-04-20",
|
|
36181
|
+
"User-Agent": "claude-cli/2.1.294 (external, cli)"
|
|
36182
|
+
};
|
|
36183
|
+
}
|
|
36184
|
+
|
|
36185
|
+
// src/harness/import-value.ts
|
|
36186
|
+
function literal2(value) {
|
|
36187
|
+
return value.replaceAll("${", () => "$${");
|
|
36188
|
+
}
|
|
36189
|
+
function parseImported(schema, server) {
|
|
36190
|
+
const result = schema.safeParse(server.config);
|
|
34713
36191
|
if (!result.success) {
|
|
34714
36192
|
throw new OperationError(`Cannot import ${server.name}: unsupported or disabled MCP configuration.`);
|
|
34715
36193
|
}
|
|
@@ -34719,16 +36197,16 @@ function parseImported(schema, server) {
|
|
|
34719
36197
|
// src/harness/skill-dirs.ts
|
|
34720
36198
|
import { existsSync as existsSync2 } from "node:fs";
|
|
34721
36199
|
import { cp, lstat, mkdir as mkdir2, readdir, readlink, rm, symlink, writeFile as writeFile2 } from "node:fs/promises";
|
|
34722
|
-
import
|
|
36200
|
+
import path8 from "node:path";
|
|
34723
36201
|
async function listSkillDirs(dir) {
|
|
34724
36202
|
if (!existsSync2(dir)) {
|
|
34725
36203
|
return [];
|
|
34726
36204
|
}
|
|
34727
36205
|
const names = await readdir(dir);
|
|
34728
|
-
return names.toSorted().filter((name) => existsSync2(
|
|
36206
|
+
return names.toSorted().filter((name) => existsSync2(path8.join(dir, name, "SKILL.md"))).map((name) => ({ dir: path8.join(dir, name), name }));
|
|
34729
36207
|
}
|
|
34730
36208
|
async function findSkillDir(dir, name) {
|
|
34731
|
-
const target =
|
|
36209
|
+
const target = path8.join(dir, name);
|
|
34732
36210
|
const stats = await lstat(target).catch((error) => {
|
|
34733
36211
|
if (error.code === "ENOENT") {
|
|
34734
36212
|
return;
|
|
@@ -34740,12 +36218,12 @@ async function findSkillDir(dir, name) {
|
|
|
34740
36218
|
function createLinkedSkills(getDir) {
|
|
34741
36219
|
return {
|
|
34742
36220
|
async add(scope, skill) {
|
|
34743
|
-
const target =
|
|
36221
|
+
const target = path8.join(getDir(scope), skill.name);
|
|
34744
36222
|
const existing = await findSkillDir(getDir(scope), skill.name);
|
|
34745
36223
|
if (existing !== undefined && !skill.force && !await isOwnedSkill(target, skill.dir)) {
|
|
34746
36224
|
throw new OperationError(`Cannot replace unmanaged skill ${target}. Use --force to take it over.`);
|
|
34747
36225
|
}
|
|
34748
|
-
await mkdir2(
|
|
36226
|
+
await mkdir2(path8.dirname(target), { recursive: true });
|
|
34749
36227
|
await rm(target, { force: true, recursive: true });
|
|
34750
36228
|
if (skill.copy) {
|
|
34751
36229
|
await copySkill(skill.dir, target);
|
|
@@ -34760,8 +36238,8 @@ function createLinkedSkills(getDir) {
|
|
|
34760
36238
|
find: (scope, name) => findSkillDir(getDir(scope), name),
|
|
34761
36239
|
list: (scope) => listSkillDirs(getDir(scope)),
|
|
34762
36240
|
async remove(scope, name) {
|
|
34763
|
-
const target =
|
|
34764
|
-
const canonical =
|
|
36241
|
+
const target = path8.join(getDir(scope), name);
|
|
36242
|
+
const canonical = path8.join(skillsDir(scope), name);
|
|
34765
36243
|
if (await isOwnedSkill(target, canonical)) {
|
|
34766
36244
|
await rm(target, { force: true, recursive: true });
|
|
34767
36245
|
}
|
|
@@ -34769,7 +36247,7 @@ function createLinkedSkills(getDir) {
|
|
|
34769
36247
|
};
|
|
34770
36248
|
}
|
|
34771
36249
|
async function isOwnedSkill(target, canonical) {
|
|
34772
|
-
if (
|
|
36250
|
+
if (path8.resolve(target) === path8.resolve(canonical)) {
|
|
34773
36251
|
return true;
|
|
34774
36252
|
}
|
|
34775
36253
|
const stats = await lstat(target).catch((error) => {
|
|
@@ -34782,30 +36260,30 @@ async function isOwnedSkill(target, canonical) {
|
|
|
34782
36260
|
return false;
|
|
34783
36261
|
}
|
|
34784
36262
|
if (stats.isSymbolicLink()) {
|
|
34785
|
-
return
|
|
36263
|
+
return path8.resolve(path8.dirname(target), await readlink(target)) === path8.resolve(canonical);
|
|
34786
36264
|
}
|
|
34787
36265
|
if (!stats.isDirectory()) {
|
|
34788
36266
|
return false;
|
|
34789
36267
|
}
|
|
34790
|
-
const marker = await readText(
|
|
36268
|
+
const marker = await readText(path8.join(target, "metadata.json"));
|
|
34791
36269
|
return marker === ownershipMarker(target, canonical);
|
|
34792
36270
|
}
|
|
34793
36271
|
async function copySkill(source, target) {
|
|
34794
36272
|
await cp(source, target, { recursive: true });
|
|
34795
|
-
await writeFile2(
|
|
36273
|
+
await writeFile2(path8.join(target, "metadata.json"), ownershipMarker(target, source));
|
|
34796
36274
|
}
|
|
34797
36275
|
function ownershipMarker(target, canonical) {
|
|
34798
36276
|
return JSON.stringify({
|
|
34799
36277
|
agentsrc: 1,
|
|
34800
|
-
canonical:
|
|
36278
|
+
canonical: path8.relative(target, canonical).split(path8.sep).join("/")
|
|
34801
36279
|
});
|
|
34802
36280
|
}
|
|
34803
36281
|
async function linkDirectory(source, target) {
|
|
34804
36282
|
if (process.platform === "win32") {
|
|
34805
|
-
await symlink(
|
|
36283
|
+
await symlink(path8.resolve(source), target, "junction");
|
|
34806
36284
|
return;
|
|
34807
36285
|
}
|
|
34808
|
-
await symlink(
|
|
36286
|
+
await symlink(path8.relative(path8.dirname(target), source), target);
|
|
34809
36287
|
}
|
|
34810
36288
|
|
|
34811
36289
|
// src/mcp/env.ts
|
|
@@ -34857,11 +36335,11 @@ function getLiteral(value) {
|
|
|
34857
36335
|
});
|
|
34858
36336
|
}
|
|
34859
36337
|
|
|
34860
|
-
// src/harness/adapters/claude-code.ts
|
|
34861
|
-
var run =
|
|
36338
|
+
// src/harness/adapters/claude-code/index.ts
|
|
36339
|
+
var run = promisify2(execFile2);
|
|
34862
36340
|
var ServersKey = "mcpServers";
|
|
34863
36341
|
var ClaudeCode = {
|
|
34864
|
-
detect: (scope) => scope?.kind === "project" ? existsSync3(projectFile(scope)) || existsSync3(
|
|
36342
|
+
detect: (scope) => scope?.kind === "project" ? existsSync3(projectFile(scope)) || existsSync3(path9.join(scope.root, ".claude")) : existsSync3(configDir()) || existsSync3(userFile()),
|
|
34865
36343
|
id: "claude-code",
|
|
34866
36344
|
mcp: {
|
|
34867
36345
|
import: importServer,
|
|
@@ -34907,16 +36385,17 @@ var ClaudeCode = {
|
|
|
34907
36385
|
},
|
|
34908
36386
|
render
|
|
34909
36387
|
},
|
|
34910
|
-
|
|
36388
|
+
usage: createClaudeUsage(configDir, userFile),
|
|
36389
|
+
skills: createLinkedSkills((scope) => scope.kind === "global" ? path9.join(configDir(), "skills") : path9.join(scope.root, ".claude", "skills"))
|
|
34911
36390
|
};
|
|
34912
36391
|
function configDir() {
|
|
34913
|
-
return process.env.CLAUDE_CONFIG_DIR ??
|
|
36392
|
+
return process.env.CLAUDE_CONFIG_DIR ?? path9.join(homedir4(), ".claude");
|
|
34914
36393
|
}
|
|
34915
36394
|
function projectFile(scope) {
|
|
34916
|
-
return
|
|
36395
|
+
return path9.join(scope.root, ".mcp.json");
|
|
34917
36396
|
}
|
|
34918
36397
|
function userFile() {
|
|
34919
|
-
return
|
|
36398
|
+
return path9.join(process.env.CLAUDE_CONFIG_DIR ?? homedir4(), ".claude.json");
|
|
34920
36399
|
}
|
|
34921
36400
|
async function listServers(scope) {
|
|
34922
36401
|
const file = scope.kind === "global" ? userFile() : projectFile(scope);
|
|
@@ -34999,10 +36478,223 @@ function importServer(server) {
|
|
|
34999
36478
|
return "url" in entry && type !== undefined && type !== "stdio" ? { ...entry, transport: type } : entry;
|
|
35000
36479
|
}
|
|
35001
36480
|
|
|
35002
|
-
// src/harness/adapters/codex.ts
|
|
36481
|
+
// src/harness/adapters/codex/index.ts
|
|
35003
36482
|
import { existsSync as existsSync4 } from "node:fs";
|
|
35004
36483
|
import { homedir as homedir5 } from "node:os";
|
|
35005
|
-
import
|
|
36484
|
+
import path11 from "node:path";
|
|
36485
|
+
|
|
36486
|
+
// src/harness/adapters/codex/usage.ts
|
|
36487
|
+
import path10 from "node:path";
|
|
36488
|
+
var PercentSchema2 = number2().finite().min(0);
|
|
36489
|
+
var CountSchema2 = number2().int().nonnegative();
|
|
36490
|
+
var ExpirySchema2 = union([string2().datetime({ offset: true }), number2().finite()]).nullish();
|
|
36491
|
+
var CodexWindowSchema = object({
|
|
36492
|
+
used_percent: PercentSchema2,
|
|
36493
|
+
limit_window_seconds: number2().positive().optional(),
|
|
36494
|
+
reset_at: number2().finite().optional(),
|
|
36495
|
+
reset_after_seconds: number2().finite().nonnegative().optional()
|
|
36496
|
+
});
|
|
36497
|
+
var RateLimitSchema = object({
|
|
36498
|
+
limit_reached: boolean2().optional(),
|
|
36499
|
+
primary_window: CodexWindowSchema.nullish(),
|
|
36500
|
+
secondary_window: CodexWindowSchema.nullish()
|
|
36501
|
+
});
|
|
36502
|
+
var InventorySchema = object({
|
|
36503
|
+
available_count: CountSchema2,
|
|
36504
|
+
credits: array(object({
|
|
36505
|
+
id: string2().min(1),
|
|
36506
|
+
status: string2().optional(),
|
|
36507
|
+
expires_at: ExpirySchema2,
|
|
36508
|
+
reset_type: string2().optional()
|
|
36509
|
+
})).optional()
|
|
36510
|
+
});
|
|
36511
|
+
var CodexSchema = object({
|
|
36512
|
+
plan_type: string2().optional(),
|
|
36513
|
+
rate_limit: RateLimitSchema.nullish(),
|
|
36514
|
+
code_review_rate_limit: RateLimitSchema.nullish(),
|
|
36515
|
+
additional_rate_limits: array(object({
|
|
36516
|
+
limit_name: string2().optional(),
|
|
36517
|
+
metered_feature: string2().optional(),
|
|
36518
|
+
rate_limit: RateLimitSchema
|
|
36519
|
+
})).nullish(),
|
|
36520
|
+
rate_limit_reset_credits: object({ available_count: CountSchema2 }).nullish()
|
|
36521
|
+
});
|
|
36522
|
+
function parseCodex(raw, inventory, now) {
|
|
36523
|
+
const body = CodexSchema.parse(raw);
|
|
36524
|
+
const limits = [
|
|
36525
|
+
{ label: "Usage", value: body.rate_limit },
|
|
36526
|
+
{ label: "Code review", value: body.code_review_rate_limit },
|
|
36527
|
+
...(body.additional_rate_limits ?? []).map((entry) => ({
|
|
36528
|
+
label: entry.limit_name ?? entry.metered_feature ?? "Additional",
|
|
36529
|
+
value: entry.rate_limit
|
|
36530
|
+
}))
|
|
36531
|
+
];
|
|
36532
|
+
const windows = limits.flatMap(({ label, value }) => [value?.primary_window, value?.secondary_window].flatMap((window2, index) => {
|
|
36533
|
+
if (!window2) {
|
|
36534
|
+
return [];
|
|
36535
|
+
}
|
|
36536
|
+
const seconds = window2.limit_window_seconds ?? null;
|
|
36537
|
+
const period = windowLabel(seconds, index);
|
|
36538
|
+
const reset = window2.reset_at ?? (window2.reset_after_seconds === undefined ? null : now / 1000 + window2.reset_after_seconds);
|
|
36539
|
+
return [
|
|
36540
|
+
{
|
|
36541
|
+
id: `${label}:${index}`,
|
|
36542
|
+
label: `${label} ${period}`,
|
|
36543
|
+
usedPercent: window2.used_percent,
|
|
36544
|
+
resetsAt: reset === null ? null : timestamp2(reset)
|
|
36545
|
+
}
|
|
36546
|
+
];
|
|
36547
|
+
}));
|
|
36548
|
+
const parsedInventory = InventorySchema.safeParse(inventory);
|
|
36549
|
+
const list = parsedInventory.success ? parsedInventory.data : null;
|
|
36550
|
+
const credits = (list?.credits ?? []).filter((credit) => !credit.status || credit.status === "available").map((credit) => {
|
|
36551
|
+
const expiresAt = timestamp2(credit.expires_at);
|
|
36552
|
+
return {
|
|
36553
|
+
id: credit.id,
|
|
36554
|
+
count: 1,
|
|
36555
|
+
label: credit.reset_type ?? "Full reset",
|
|
36556
|
+
restores: credit.reset_type === undefined || credit.reset_type === "codex_rate_limits" ? windows.flatMap((window2) => window2.id ? [window2.id] : []) : [],
|
|
36557
|
+
expiresAt,
|
|
36558
|
+
expiry: expiryStatus2(credit.expires_at),
|
|
36559
|
+
canClaim: !expiresAt || Date.parse(expiresAt) > now
|
|
36560
|
+
};
|
|
36561
|
+
});
|
|
36562
|
+
const available = body.rate_limit_reset_credits?.available_count ?? list?.available_count ?? null;
|
|
36563
|
+
const agrees = list === null || available === list.available_count;
|
|
36564
|
+
return {
|
|
36565
|
+
provider: "codex",
|
|
36566
|
+
account: { name: null, id: null },
|
|
36567
|
+
plan: body.plan_type ?? null,
|
|
36568
|
+
limited: limits.some(({ value }) => value?.limit_reached === true) || windows.some((window2) => window2.usedPercent >= 100),
|
|
36569
|
+
windows,
|
|
36570
|
+
resets: {
|
|
36571
|
+
available,
|
|
36572
|
+
credits: agrees ? credits : [],
|
|
36573
|
+
note: inventoryNote(list === null, agrees)
|
|
36574
|
+
}
|
|
36575
|
+
};
|
|
36576
|
+
}
|
|
36577
|
+
function timestamp2(value) {
|
|
36578
|
+
if (value === null || value === undefined) {
|
|
36579
|
+
return null;
|
|
36580
|
+
}
|
|
36581
|
+
return new Date(typeof value === "number" ? value * 1000 : value).toISOString();
|
|
36582
|
+
}
|
|
36583
|
+
function windowLabel(seconds, index) {
|
|
36584
|
+
if (seconds === 18000) {
|
|
36585
|
+
return "5-hour";
|
|
36586
|
+
}
|
|
36587
|
+
if (seconds === 604800) {
|
|
36588
|
+
return "weekly";
|
|
36589
|
+
}
|
|
36590
|
+
return index === 0 ? "primary" : "secondary";
|
|
36591
|
+
}
|
|
36592
|
+
function inventoryNote(missing, agrees) {
|
|
36593
|
+
if (missing) {
|
|
36594
|
+
return "Reset inventory unavailable; expiry and claim IDs unknown.";
|
|
36595
|
+
}
|
|
36596
|
+
if (!agrees) {
|
|
36597
|
+
return "Reset count changed during retrieval; run usage again for expiry and claim IDs.";
|
|
36598
|
+
}
|
|
36599
|
+
return null;
|
|
36600
|
+
}
|
|
36601
|
+
function expiryStatus2(value) {
|
|
36602
|
+
if (value === undefined) {
|
|
36603
|
+
return "unknown";
|
|
36604
|
+
}
|
|
36605
|
+
return value === null ? "never" : "dated";
|
|
36606
|
+
}
|
|
36607
|
+
var CodexBase = "https://chatgpt.com/backend-api/wham";
|
|
36608
|
+
var AuthSchema2 = object({
|
|
36609
|
+
tokens: object({
|
|
36610
|
+
access_token: string2().min(1),
|
|
36611
|
+
id_token: string2().optional(),
|
|
36612
|
+
account_id: string2().optional()
|
|
36613
|
+
}).nullish()
|
|
36614
|
+
});
|
|
36615
|
+
var IdentitySchema = object({
|
|
36616
|
+
name: string2().optional(),
|
|
36617
|
+
email: string2().optional(),
|
|
36618
|
+
sub: string2().optional(),
|
|
36619
|
+
"https://api.openai.com/profile": object({ email: string2().optional() }).optional(),
|
|
36620
|
+
"https://api.openai.com/auth": object({ chatgpt_account_id: string2().optional() }).optional()
|
|
36621
|
+
});
|
|
36622
|
+
function createCodexUsage(directory, transport = fetch, now = Date.now) {
|
|
36623
|
+
return {
|
|
36624
|
+
provider: "codex",
|
|
36625
|
+
async connect() {
|
|
36626
|
+
const credentials = await readCredentials2(directory());
|
|
36627
|
+
if (!credentials) {
|
|
36628
|
+
return null;
|
|
36629
|
+
}
|
|
36630
|
+
return {
|
|
36631
|
+
read: () => readCodexUsage(credentials, transport, now()),
|
|
36632
|
+
claimReset: (claim) => claimCodexReset(credentials, claim.creditId, claim.requestId, transport)
|
|
36633
|
+
};
|
|
36634
|
+
}
|
|
36635
|
+
};
|
|
36636
|
+
}
|
|
36637
|
+
async function readCredentials2(directory) {
|
|
36638
|
+
const auth = await readCredentialsFile(path10.join(directory, "auth.json"), AuthSchema2);
|
|
36639
|
+
if (!auth) {
|
|
36640
|
+
return null;
|
|
36641
|
+
}
|
|
36642
|
+
if (!auth.tokens) {
|
|
36643
|
+
throw new Error("Codex subscription usage requires ChatGPT login; API keys do not expose subscription limits.");
|
|
36644
|
+
}
|
|
36645
|
+
const identity = readIdentity(auth.tokens.id_token) ?? readIdentity(auth.tokens.access_token);
|
|
36646
|
+
return {
|
|
36647
|
+
token: auth.tokens.access_token,
|
|
36648
|
+
accountId: auth.tokens.account_id ?? identity?.["https://api.openai.com/auth"]?.chatgpt_account_id,
|
|
36649
|
+
userId: identity?.sub,
|
|
36650
|
+
accountName: identity?.email ?? identity?.["https://api.openai.com/profile"]?.email ?? identity?.name
|
|
36651
|
+
};
|
|
36652
|
+
}
|
|
36653
|
+
function readIdentity(token) {
|
|
36654
|
+
const payload = token?.split(".")[1];
|
|
36655
|
+
if (!payload) {
|
|
36656
|
+
return null;
|
|
36657
|
+
}
|
|
36658
|
+
try {
|
|
36659
|
+
const parsed = IdentitySchema.safeParse(JSON.parse(Buffer.from(payload, "base64url").toString("utf-8")));
|
|
36660
|
+
return parsed.success ? parsed.data : null;
|
|
36661
|
+
} catch {
|
|
36662
|
+
return null;
|
|
36663
|
+
}
|
|
36664
|
+
}
|
|
36665
|
+
async function readCodexUsage(credentials, transport = fetch, now = Date.now()) {
|
|
36666
|
+
const headers = codexHeaders(credentials);
|
|
36667
|
+
const body = await request("codex", `${CodexBase}/usage`, headers, {}, transport);
|
|
36668
|
+
const inventory = await request("codex", `${CodexBase}/rate-limit-reset-credits`, headers, {}, transport).catch(() => null);
|
|
36669
|
+
return {
|
|
36670
|
+
...parseCodex(body, inventory, now),
|
|
36671
|
+
account: {
|
|
36672
|
+
name: credentials.accountName ?? null,
|
|
36673
|
+
id: credentials.accountId ?? credentials.userId ?? null
|
|
36674
|
+
}
|
|
36675
|
+
};
|
|
36676
|
+
}
|
|
36677
|
+
async function claimCodexReset(credentials, creditId, requestId, transport = fetch) {
|
|
36678
|
+
const body = await request("codex", `${CodexBase}/rate-limit-reset-credits/consume`, codexHeaders(credentials), {
|
|
36679
|
+
method: "POST",
|
|
36680
|
+
body: JSON.stringify({ credit_id: creditId, redeem_request_id: requestId })
|
|
36681
|
+
}, transport);
|
|
36682
|
+
const outcome = object({ code: _enum(["reset", "already_redeemed", "nothing_to_reset", "no_credit"]) }).parse(body).code;
|
|
36683
|
+
return { outcome, success: outcome === "reset" || outcome === "already_redeemed" };
|
|
36684
|
+
}
|
|
36685
|
+
function codexHeaders(credentials) {
|
|
36686
|
+
const headers = new Headers({
|
|
36687
|
+
Authorization: `Bearer ${credentials.token}`,
|
|
36688
|
+
Accept: "application/json",
|
|
36689
|
+
"Content-Type": "application/json",
|
|
36690
|
+
"OpenAI-Beta": "codex-1",
|
|
36691
|
+
originator: "Codex Desktop"
|
|
36692
|
+
});
|
|
36693
|
+
if (credentials.accountId) {
|
|
36694
|
+
headers.set("ChatGPT-Account-Id", credentials.accountId);
|
|
36695
|
+
}
|
|
36696
|
+
return headers;
|
|
36697
|
+
}
|
|
35006
36698
|
|
|
35007
36699
|
// src/harness/universal.ts
|
|
35008
36700
|
var UniversalSkills = {
|
|
@@ -35012,11 +36704,11 @@ var UniversalSkills = {
|
|
|
35012
36704
|
async remove() {}
|
|
35013
36705
|
};
|
|
35014
36706
|
|
|
35015
|
-
// src/harness/adapters/codex.ts
|
|
36707
|
+
// src/harness/adapters/codex/index.ts
|
|
35016
36708
|
var ServersKey2 = "mcp_servers";
|
|
35017
36709
|
var BearerPrefix = "Bearer ";
|
|
35018
36710
|
var Codex = {
|
|
35019
|
-
detect: (scope) => scope?.kind === "project" ? existsSync4(
|
|
36711
|
+
detect: (scope) => scope?.kind === "project" ? existsSync4(path11.join(scope.root, ".codex")) : existsSync4(configDir2()) || scope === undefined && existsSync4("/etc/codex"),
|
|
35020
36712
|
id: "codex",
|
|
35021
36713
|
mcp: {
|
|
35022
36714
|
import: importServer2,
|
|
@@ -35044,13 +36736,14 @@ var Codex = {
|
|
|
35044
36736
|
},
|
|
35045
36737
|
render: render2
|
|
35046
36738
|
},
|
|
36739
|
+
usage: createCodexUsage(configDir2),
|
|
35047
36740
|
skills: UniversalSkills
|
|
35048
36741
|
};
|
|
35049
36742
|
function configDir2() {
|
|
35050
|
-
return process.env.CODEX_HOME ??
|
|
36743
|
+
return process.env.CODEX_HOME ?? path11.join(homedir5(), ".codex");
|
|
35051
36744
|
}
|
|
35052
36745
|
function configFile(scope) {
|
|
35053
|
-
return scope.kind === "global" ?
|
|
36746
|
+
return scope.kind === "global" ? path11.join(configDir2(), "config.toml") : path11.join(scope.root, ".codex", "config.toml");
|
|
35054
36747
|
}
|
|
35055
36748
|
async function listServers2(scope) {
|
|
35056
36749
|
const file = configFile(scope);
|
|
@@ -35169,24 +36862,179 @@ function importServer2(server) {
|
|
|
35169
36862
|
return { url: literal2(config.url), headers };
|
|
35170
36863
|
}
|
|
35171
36864
|
|
|
35172
|
-
// src/harness/adapters/opencode.ts
|
|
35173
|
-
import { execFile as
|
|
36865
|
+
// src/harness/adapters/opencode/index.ts
|
|
36866
|
+
import { execFile as execFile4 } from "node:child_process";
|
|
35174
36867
|
import { existsSync as existsSync5 } from "node:fs";
|
|
35175
36868
|
import { homedir as homedir6 } from "node:os";
|
|
35176
|
-
import
|
|
35177
|
-
import { promisify as
|
|
35178
|
-
|
|
36869
|
+
import path12 from "node:path";
|
|
36870
|
+
import { promisify as promisify4 } from "node:util";
|
|
36871
|
+
|
|
36872
|
+
// src/harness/adapters/opencode/usage.ts
|
|
36873
|
+
import { execFile as execFile3 } from "node:child_process";
|
|
36874
|
+
import { promisify as promisify3 } from "node:util";
|
|
36875
|
+
var Run2 = promisify3(execFile3);
|
|
36876
|
+
var UsageUrl = "https://opencode.ai/zen/go/v1/usage";
|
|
36877
|
+
var ExportsSchema = array(object({
|
|
36878
|
+
id: string2().min(1),
|
|
36879
|
+
integrationID: string2(),
|
|
36880
|
+
label: string2(),
|
|
36881
|
+
active: boolean2(),
|
|
36882
|
+
value: unknown()
|
|
36883
|
+
}));
|
|
36884
|
+
var MetadataSchema = object({
|
|
36885
|
+
email: string2().optional(),
|
|
36886
|
+
accountID: string2().optional(),
|
|
36887
|
+
orgID: string2().optional(),
|
|
36888
|
+
orgName: string2().optional(),
|
|
36889
|
+
server: string2().optional()
|
|
36890
|
+
});
|
|
36891
|
+
var CredentialSchema = discriminatedUnion("type", [
|
|
36892
|
+
object({ type: literal("key"), key: string2().min(1), metadata: MetadataSchema.optional() }),
|
|
36893
|
+
object({ type: literal("api"), key: string2().min(1), metadata: MetadataSchema.optional() }),
|
|
36894
|
+
object({
|
|
36895
|
+
type: literal("oauth"),
|
|
36896
|
+
access: string2().min(1),
|
|
36897
|
+
metadata: MetadataSchema.optional()
|
|
36898
|
+
})
|
|
36899
|
+
]);
|
|
36900
|
+
var MeterSchema = object({
|
|
36901
|
+
percent: number2().finite().nonnegative(),
|
|
36902
|
+
resetsAt: string2().datetime({ offset: true }).nullish()
|
|
36903
|
+
});
|
|
36904
|
+
var UsageSchema = object({
|
|
36905
|
+
usage: object({
|
|
36906
|
+
rolling: MeterSchema,
|
|
36907
|
+
weekly: MeterSchema.nullish(),
|
|
36908
|
+
monthly: MeterSchema.nullish()
|
|
36909
|
+
})
|
|
36910
|
+
});
|
|
36911
|
+
function createOpenCodeUsage(readExport = exportCredentials, transport = fetch, now = Date.now) {
|
|
36912
|
+
return {
|
|
36913
|
+
provider: "opencode",
|
|
36914
|
+
async connect() {
|
|
36915
|
+
const credentials = await readCredentials3(readExport);
|
|
36916
|
+
if (!credentials) {
|
|
36917
|
+
return null;
|
|
36918
|
+
}
|
|
36919
|
+
return { read: () => readUsage(credentials, transport, now()) };
|
|
36920
|
+
}
|
|
36921
|
+
};
|
|
36922
|
+
}
|
|
36923
|
+
async function exportCredentials() {
|
|
36924
|
+
try {
|
|
36925
|
+
const result = await Run2("opencode", ["auth", "export"], {
|
|
36926
|
+
timeout: 25000,
|
|
36927
|
+
maxBuffer: 2000000
|
|
36928
|
+
});
|
|
36929
|
+
return result.stdout;
|
|
36930
|
+
} catch (error) {
|
|
36931
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
36932
|
+
return "[]";
|
|
36933
|
+
}
|
|
36934
|
+
throw new Error("Cannot export OpenCode credentials. Update OpenCode and check `opencode auth list`.");
|
|
36935
|
+
}
|
|
36936
|
+
}
|
|
36937
|
+
async function readCredentials3(readExport) {
|
|
36938
|
+
const text = await readExport();
|
|
36939
|
+
try {
|
|
36940
|
+
const rows = ExportsSchema.parse(JSON.parse(text));
|
|
36941
|
+
const row = rows.find((item) => item.active && item.integrationID === "opencode-go") ?? rows.find((item) => item.active && item.integrationID === "opencode");
|
|
36942
|
+
if (!row) {
|
|
36943
|
+
return null;
|
|
36944
|
+
}
|
|
36945
|
+
const value = CredentialSchema.parse(row.value);
|
|
36946
|
+
if (row.integrationID === "opencode" && value.type !== "oauth") {
|
|
36947
|
+
return null;
|
|
36948
|
+
}
|
|
36949
|
+
const { metadata } = value;
|
|
36950
|
+
if (metadata?.server) {
|
|
36951
|
+
const server = new URL(metadata.server);
|
|
36952
|
+
if (server.protocol !== "https:" || server.hostname !== "opencode.ai") {
|
|
36953
|
+
throw new Error("Unsupported Console server");
|
|
36954
|
+
}
|
|
36955
|
+
}
|
|
36956
|
+
return {
|
|
36957
|
+
token: value.type === "oauth" ? value.access : value.key,
|
|
36958
|
+
organizationId: metadata?.orgID,
|
|
36959
|
+
account: getAccount(row, metadata)
|
|
36960
|
+
};
|
|
36961
|
+
} catch {
|
|
36962
|
+
throw new Error("Cannot read OpenCode credentials. Check `opencode auth list` and reconnect OpenCode Go.");
|
|
36963
|
+
}
|
|
36964
|
+
}
|
|
36965
|
+
async function readUsage(credentials, transport, now) {
|
|
36966
|
+
const headers = new Headers({
|
|
36967
|
+
Authorization: `Bearer ${credentials.token}`,
|
|
36968
|
+
Accept: "application/json",
|
|
36969
|
+
"User-Agent": "agentsrc"
|
|
36970
|
+
});
|
|
36971
|
+
if (credentials.organizationId) {
|
|
36972
|
+
headers.set("x-opencode-org-id", credentials.organizationId);
|
|
36973
|
+
}
|
|
36974
|
+
let capturedAt = now;
|
|
36975
|
+
const raw = await request("opencode", UsageUrl, headers, {}, async (url, init) => {
|
|
36976
|
+
const response = await transport(url, init);
|
|
36977
|
+
const date = Date.parse(response.headers.get("date") ?? "");
|
|
36978
|
+
if (Number.isFinite(date)) {
|
|
36979
|
+
capturedAt = date;
|
|
36980
|
+
}
|
|
36981
|
+
return response;
|
|
36982
|
+
});
|
|
36983
|
+
const body = UsageSchema.parse(raw);
|
|
36984
|
+
const meters = [
|
|
36985
|
+
{ value: body.usage.rolling, label: "5h" },
|
|
36986
|
+
{ value: body.usage.weekly, label: "Weekly" },
|
|
36987
|
+
{ value: body.usage.monthly, label: "Monthly" }
|
|
36988
|
+
];
|
|
36989
|
+
const windows = meters.flatMap(({ value, label }) => {
|
|
36990
|
+
if (!value) {
|
|
36991
|
+
return [];
|
|
36992
|
+
}
|
|
36993
|
+
const reset = value.resetsAt ? Date.parse(value.resetsAt) : null;
|
|
36994
|
+
const isIdle = label === "5h" && value.percent === 0 && reset !== null && Math.abs(reset - capturedAt - 18000000) <= 2000;
|
|
36995
|
+
return [
|
|
36996
|
+
{
|
|
36997
|
+
label,
|
|
36998
|
+
usedPercent: value.percent,
|
|
36999
|
+
resetsAt: reset === null || isIdle ? null : new Date(reset).toISOString()
|
|
37000
|
+
}
|
|
37001
|
+
];
|
|
37002
|
+
});
|
|
37003
|
+
return {
|
|
37004
|
+
provider: "opencode",
|
|
37005
|
+
displayName: "OpenCode Go",
|
|
37006
|
+
account: credentials.account,
|
|
37007
|
+
plan: null,
|
|
37008
|
+
limited: windows.some((window2) => window2.usedPercent >= 100),
|
|
37009
|
+
windows,
|
|
37010
|
+
resets: {
|
|
37011
|
+
available: null,
|
|
37012
|
+
credits: [],
|
|
37013
|
+
supported: false,
|
|
37014
|
+
note: "OpenCode Go does not expose banked reset credits or claims."
|
|
37015
|
+
}
|
|
37016
|
+
};
|
|
37017
|
+
}
|
|
37018
|
+
function getAccount(row, metadata) {
|
|
37019
|
+
return {
|
|
37020
|
+
name: metadata?.email ?? metadata?.orgName ?? (row.label === "default" ? null : row.label),
|
|
37021
|
+
id: metadata?.orgID ?? metadata?.accountID ?? row.id
|
|
37022
|
+
};
|
|
37023
|
+
}
|
|
37024
|
+
|
|
37025
|
+
// src/harness/adapters/opencode/index.ts
|
|
37026
|
+
var run2 = promisify4(execFile4);
|
|
35179
37027
|
var ServersKeys = ["mcp", "servers"];
|
|
35180
37028
|
var SupportedMajor = 2;
|
|
35181
37029
|
var ProjectFiles = [
|
|
35182
37030
|
"opencode.json",
|
|
35183
37031
|
"opencode.jsonc",
|
|
35184
|
-
|
|
35185
|
-
|
|
37032
|
+
path12.join(".opencode", "opencode.json"),
|
|
37033
|
+
path12.join(".opencode", "opencode.jsonc")
|
|
35186
37034
|
];
|
|
35187
37035
|
var GlobalFiles = ["opencode.json", "opencode.jsonc"];
|
|
35188
37036
|
var OpenCode = {
|
|
35189
|
-
detect: (scope) => scope?.kind === "project" ? ProjectFiles.some((file) => existsSync5(
|
|
37037
|
+
detect: (scope) => scope?.kind === "project" ? ProjectFiles.some((file) => existsSync5(path12.join(scope.root, file))) || existsSync5(path12.join(scope.root, ".opencode")) : existsSync5(configDir3()),
|
|
35190
37038
|
id: "opencode",
|
|
35191
37039
|
mcp: {
|
|
35192
37040
|
import: importServer3,
|
|
@@ -35213,17 +37061,18 @@ var OpenCode = {
|
|
|
35213
37061
|
},
|
|
35214
37062
|
render: render3
|
|
35215
37063
|
},
|
|
37064
|
+
usage: createOpenCodeUsage(),
|
|
35216
37065
|
skills: UniversalSkills
|
|
35217
37066
|
};
|
|
35218
37067
|
function configDir3() {
|
|
35219
|
-
const base = process.env.XDG_CONFIG_HOME ??
|
|
35220
|
-
return
|
|
37068
|
+
const base = process.env.XDG_CONFIG_HOME ?? path12.join(homedir6(), ".config");
|
|
37069
|
+
return path12.join(base, "opencode");
|
|
35221
37070
|
}
|
|
35222
37071
|
function configFile2(scope) {
|
|
35223
37072
|
const dir = scope.kind === "global" ? configDir3() : scope.root;
|
|
35224
37073
|
const names = scope.kind === "global" ? GlobalFiles : ProjectFiles;
|
|
35225
|
-
const existing = names.map((name) =>
|
|
35226
|
-
return existing ??
|
|
37074
|
+
const existing = names.map((name) => path12.join(dir, name)).find((file) => existsSync5(file));
|
|
37075
|
+
return existing ?? path12.join(dir, "opencode.json");
|
|
35227
37076
|
}
|
|
35228
37077
|
async function listServers3(scope) {
|
|
35229
37078
|
const file = configFile2(scope);
|
|
@@ -35353,12 +37202,12 @@ function detectHarnesses() {
|
|
|
35353
37202
|
}
|
|
35354
37203
|
|
|
35355
37204
|
// src/lock/skills-lock.ts
|
|
35356
|
-
import
|
|
37205
|
+
import path14 from "node:path";
|
|
35357
37206
|
|
|
35358
37207
|
// src/lock/hash.ts
|
|
35359
37208
|
import { createHash as createHash2 } from "node:crypto";
|
|
35360
|
-
import { readFile as
|
|
35361
|
-
import
|
|
37209
|
+
import { readFile as readFile3, readdir as readdir2, realpath as realpath2, stat } from "node:fs/promises";
|
|
37210
|
+
import path13 from "node:path";
|
|
35362
37211
|
var ExcludedFiles = new Set(["metadata.json"]);
|
|
35363
37212
|
var ExcludedDirs = new Set([".git", "__pycache__", "__pypackages__"]);
|
|
35364
37213
|
var OwnerExecuteBit = 64;
|
|
@@ -35425,7 +37274,7 @@ async function collectFiles(state) {
|
|
|
35425
37274
|
if (isExcludedName(entry.name, entry.isDirectory())) {
|
|
35426
37275
|
return;
|
|
35427
37276
|
}
|
|
35428
|
-
const fullPath =
|
|
37277
|
+
const fullPath = path13.join(state.dir, entry.name);
|
|
35429
37278
|
const relativePath = `${state.prefix}${entry.name}`;
|
|
35430
37279
|
const kind = await getEntryKind(fullPath, entry, state.root);
|
|
35431
37280
|
if (kind === "skip" || kind === "directory" && isExcludedName(entry.name, true)) {
|
|
@@ -35437,7 +37286,7 @@ async function collectFiles(state) {
|
|
|
35437
37286
|
}
|
|
35438
37287
|
const stats = await stat(fullPath);
|
|
35439
37288
|
state.files.push({
|
|
35440
|
-
content: await
|
|
37289
|
+
content: await readFile3(fullPath),
|
|
35441
37290
|
mode: stats.mode % PermissionUnit,
|
|
35442
37291
|
path: relativePath
|
|
35443
37292
|
});
|
|
@@ -35468,7 +37317,7 @@ function isOwnerExecutable(mode) {
|
|
|
35468
37317
|
return Math.floor(mode / OwnerExecuteBit) % 2 === 1;
|
|
35469
37318
|
}
|
|
35470
37319
|
function isInside(root, target) {
|
|
35471
|
-
return target === root || target.startsWith(`${root}${
|
|
37320
|
+
return target === root || target.startsWith(`${root}${path13.sep}`);
|
|
35472
37321
|
}
|
|
35473
37322
|
function normalizeLineEndings(content) {
|
|
35474
37323
|
if (content.includes(0) || !content.includes(`\r
|
|
@@ -35506,7 +37355,7 @@ function hashGitObject(type, body) {
|
|
|
35506
37355
|
async function collectLegacyFiles(root, dir, files) {
|
|
35507
37356
|
const entries = await readdir2(dir, { withFileTypes: true });
|
|
35508
37357
|
await Promise.all(entries.map(async (entry) => {
|
|
35509
|
-
const fullPath =
|
|
37358
|
+
const fullPath = path13.join(dir, entry.name);
|
|
35510
37359
|
if (entry.isDirectory()) {
|
|
35511
37360
|
if (entry.name !== ".git" && entry.name !== "node_modules") {
|
|
35512
37361
|
await collectLegacyFiles(root, fullPath, files);
|
|
@@ -35514,8 +37363,8 @@ async function collectLegacyFiles(root, dir, files) {
|
|
|
35514
37363
|
return;
|
|
35515
37364
|
}
|
|
35516
37365
|
if (entry.isFile()) {
|
|
35517
|
-
const relativePath =
|
|
35518
|
-
files.push({ content: await
|
|
37366
|
+
const relativePath = path13.relative(root, fullPath).split("\\").join("/");
|
|
37367
|
+
files.push({ content: await readFile3(fullPath), path: relativePath });
|
|
35519
37368
|
}
|
|
35520
37369
|
}));
|
|
35521
37370
|
}
|
|
@@ -35581,13 +37430,13 @@ function parseSkillsLock(text, base) {
|
|
|
35581
37430
|
if (!isKnownVersion) {
|
|
35582
37431
|
throw new OperationError(`${base.file} has lock version ${version}. This agentsrc reads version ${base.kind === "global" ? GlobalVersion : LocalVersion}.`);
|
|
35583
37432
|
}
|
|
35584
|
-
const lockDir =
|
|
37433
|
+
const lockDir = path14.dirname(base.file);
|
|
35585
37434
|
const entries = Object.entries(skills).map(([name, value]) => {
|
|
35586
37435
|
const entry = parseEntry(base.kind, value, `${base.file}: skills.${name}`);
|
|
35587
|
-
const isRelativeLocal = entry.sourceType === "local" && !
|
|
37436
|
+
const isRelativeLocal = entry.sourceType === "local" && !path14.isAbsolute(entry.source);
|
|
35588
37437
|
return [
|
|
35589
37438
|
name,
|
|
35590
|
-
isRelativeLocal ? { ...entry, source:
|
|
37439
|
+
isRelativeLocal ? { ...entry, source: path14.resolve(lockDir, entry.source) } : entry
|
|
35591
37440
|
];
|
|
35592
37441
|
});
|
|
35593
37442
|
return { ...base, exists: true, extra, skills: Object.fromEntries(entries), version };
|
|
@@ -35611,7 +37460,7 @@ function serializeSkillsLock(lock) {
|
|
|
35611
37460
|
const skills = Object.fromEntries(Object.entries(lock.skills).map(([name, entry]) => [name, toGlobalEntry(entry)]));
|
|
35612
37461
|
return JSON.stringify({ version: GlobalVersion, skills, ...lock.extra }, undefined, 2);
|
|
35613
37462
|
}
|
|
35614
|
-
const lockDir =
|
|
37463
|
+
const lockDir = path14.dirname(lock.file);
|
|
35615
37464
|
const skills = Object.fromEntries(Object.keys(lock.skills).toSorted().flatMap((name) => {
|
|
35616
37465
|
const entry = lock.skills[name];
|
|
35617
37466
|
return entry ? [[name, toLocalEntry(entry, lockDir)]] : [];
|
|
@@ -35699,12 +37548,12 @@ function toGlobalEntry(entry) {
|
|
|
35699
37548
|
});
|
|
35700
37549
|
}
|
|
35701
37550
|
function toPortablePath(source, lockDir) {
|
|
35702
|
-
const absolute =
|
|
35703
|
-
const relative =
|
|
35704
|
-
if (
|
|
35705
|
-
return absolute.split(
|
|
37551
|
+
const absolute = path14.isAbsolute(source) ? source : path14.resolve(lockDir, source);
|
|
37552
|
+
const relative = path14.relative(lockDir, absolute);
|
|
37553
|
+
if (path14.isAbsolute(relative)) {
|
|
37554
|
+
return absolute.split(path14.sep).join("/");
|
|
35706
37555
|
}
|
|
35707
|
-
const portable = relative.split(
|
|
37556
|
+
const portable = relative.split(path14.sep).join("/");
|
|
35708
37557
|
if (portable === "") {
|
|
35709
37558
|
return ".";
|
|
35710
37559
|
}
|
|
@@ -35845,7 +37694,7 @@ function skillEntry(scope, dir, locked) {
|
|
|
35845
37694
|
entry.copy = true;
|
|
35846
37695
|
}
|
|
35847
37696
|
if (locked?.skillPath !== undefined) {
|
|
35848
|
-
entry.path =
|
|
37697
|
+
entry.path = path15.posix.dirname(locked.skillPath);
|
|
35849
37698
|
}
|
|
35850
37699
|
return entry;
|
|
35851
37700
|
}
|
|
@@ -35859,8 +37708,8 @@ function lockedSource(scope, locked) {
|
|
|
35859
37708
|
throw new OperationError(`Cannot import skill source type ${locked.sourceType}.`);
|
|
35860
37709
|
}
|
|
35861
37710
|
function relativeSource(scope, dir) {
|
|
35862
|
-
const relative =
|
|
35863
|
-
if (
|
|
37711
|
+
const relative = path15.relative(path15.dirname(manifestPath(scope)), dir).split(path15.sep).join("/");
|
|
37712
|
+
if (path15.isAbsolute(relative)) {
|
|
35864
37713
|
return relative;
|
|
35865
37714
|
}
|
|
35866
37715
|
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
@@ -35901,7 +37750,7 @@ async function initialize(options, cwd = process.cwd()) {
|
|
|
35901
37750
|
Ui.print(text);
|
|
35902
37751
|
return;
|
|
35903
37752
|
}
|
|
35904
|
-
await mkdir3(
|
|
37753
|
+
await mkdir3(path16.dirname(file), { recursive: true });
|
|
35905
37754
|
await writeFile3(file, text, { flag: "wx", mode: 384 });
|
|
35906
37755
|
Ui.info(`Created ${file}.`);
|
|
35907
37756
|
if (skills.length > 0 || mcp.length > 0) {
|
|
@@ -36607,15 +38456,15 @@ init_dist();
|
|
|
36607
38456
|
init_dist();
|
|
36608
38457
|
|
|
36609
38458
|
// src/skills/index.ts
|
|
36610
|
-
import
|
|
38459
|
+
import path22 from "node:path";
|
|
36611
38460
|
|
|
36612
38461
|
// src/skills/apply.ts
|
|
36613
38462
|
import { chmod, mkdir as mkdir4, rm as rm2, writeFile as writeFile4 } from "node:fs/promises";
|
|
36614
|
-
import
|
|
38463
|
+
import path20 from "node:path";
|
|
36615
38464
|
|
|
36616
38465
|
// src/skills/discover.ts
|
|
36617
|
-
import { readFile as
|
|
36618
|
-
import
|
|
38466
|
+
import { readFile as readFile4, readdir as readdir3, stat as stat2 } from "node:fs/promises";
|
|
38467
|
+
import path17 from "node:path";
|
|
36619
38468
|
|
|
36620
38469
|
// node_modules/yaml/dist/index.js
|
|
36621
38470
|
var composer = require_composer();
|
|
@@ -36816,8 +38665,8 @@ function sanitizeMetadata(value) {
|
|
|
36816
38665
|
return stripTerminalEscapes(value).replaceAll(/[\r\n]+/gu, " ").trim();
|
|
36817
38666
|
}
|
|
36818
38667
|
async function searchSkills(root, subpath, options) {
|
|
36819
|
-
const searchPath = subpath ?
|
|
36820
|
-
if (!isInside(
|
|
38668
|
+
const searchPath = subpath ? path17.join(root, subpath) : root;
|
|
38669
|
+
if (!isInside(path17.resolve(root), path17.resolve(searchPath))) {
|
|
36821
38670
|
throw new UsageError(`The path ${subpath} leaves the source.`);
|
|
36822
38671
|
}
|
|
36823
38672
|
const [lockedNames, plugins] = await Promise.all([
|
|
@@ -36827,15 +38676,15 @@ async function searchSkills(root, subpath, options) {
|
|
|
36827
38676
|
const groupings = getPluginGroupings(searchPath, plugins);
|
|
36828
38677
|
const reads = new Map;
|
|
36829
38678
|
const read = (dir) => {
|
|
36830
|
-
const key =
|
|
38679
|
+
const key = path17.resolve(dir);
|
|
36831
38680
|
const pending = reads.get(key) ?? readSkill(dir, options.includeInternal);
|
|
36832
38681
|
reads.set(key, pending);
|
|
36833
38682
|
return pending;
|
|
36834
38683
|
};
|
|
36835
38684
|
const isInstalledCopy = (skill) => {
|
|
36836
|
-
const relative =
|
|
38685
|
+
const relative = path17.relative(root, skill.dir).split(path17.sep).join("/");
|
|
36837
38686
|
const isInAgentDir = AgentSkillDirs.some((dir) => relative === dir || relative.startsWith(`${dir}/`));
|
|
36838
|
-
return isInAgentDir && (lockedNames.has(normalizeSkillName(skill.name)) || lockedNames.has(normalizeSkillName(
|
|
38687
|
+
return isInAgentDir && (lockedNames.has(normalizeSkillName(skill.name)) || lockedNames.has(normalizeSkillName(path17.basename(skill.dir))));
|
|
36839
38688
|
};
|
|
36840
38689
|
const skills = [];
|
|
36841
38690
|
const keep = async (dirs) => {
|
|
@@ -36843,7 +38692,7 @@ async function searchSkills(root, subpath, options) {
|
|
|
36843
38692
|
for (const skill of found) {
|
|
36844
38693
|
const isNew = skill !== undefined && skills.every((kept) => kept.name !== skill.name);
|
|
36845
38694
|
if (isNew && !isInstalledCopy(skill)) {
|
|
36846
|
-
const pluginName = groupings.get(
|
|
38695
|
+
const pluginName = groupings.get(path17.resolve(skill.dir));
|
|
36847
38696
|
skills.push(pluginName === undefined ? skill : { ...skill, pluginName });
|
|
36848
38697
|
}
|
|
36849
38698
|
}
|
|
@@ -36860,7 +38709,7 @@ async function searchSkills(root, subpath, options) {
|
|
|
36860
38709
|
"skills/.experimental",
|
|
36861
38710
|
"skills/.system",
|
|
36862
38711
|
...AgentSkillDirs
|
|
36863
|
-
].map((dir) =>
|
|
38712
|
+
].map((dir) => path17.join(searchPath, dir));
|
|
36864
38713
|
const candidates = await Promise.all([
|
|
36865
38714
|
findChildSkillDirs(searchPath, RootDepth),
|
|
36866
38715
|
...[...containers, ...await getSkillsShDirs(searchPath)].map((dir) => findChildSkillDirs(dir, ContainerDepth)),
|
|
@@ -36875,7 +38724,7 @@ async function searchSkills(root, subpath, options) {
|
|
|
36875
38724
|
async function findChildSkillDirs(dir, maxDepth, depth = 1) {
|
|
36876
38725
|
const entries = await readdir3(dir, { withFileTypes: true }).catch(() => []);
|
|
36877
38726
|
const found = await Promise.all(entries.filter((entry) => entry.isDirectory()).map(async (entry) => {
|
|
36878
|
-
const child =
|
|
38727
|
+
const child = path17.join(dir, entry.name);
|
|
36879
38728
|
if (await hasSkillFile(child)) {
|
|
36880
38729
|
return [child];
|
|
36881
38730
|
}
|
|
@@ -36892,15 +38741,15 @@ async function findAllSkillDirs(dir, depth) {
|
|
|
36892
38741
|
hasSkillFile(dir),
|
|
36893
38742
|
readdir3(dir, { withFileTypes: true }).catch(() => [])
|
|
36894
38743
|
]);
|
|
36895
|
-
const children = await Promise.all(entries.filter((entry) => entry.isDirectory() && !SkippedDirs.has(entry.name)).map((entry) => findAllSkillDirs(
|
|
38744
|
+
const children = await Promise.all(entries.filter((entry) => entry.isDirectory() && !SkippedDirs.has(entry.name)).map((entry) => findAllSkillDirs(path17.join(dir, entry.name), depth + 1)));
|
|
36896
38745
|
return [...isSkill ? [dir] : [], ...children.flat()];
|
|
36897
38746
|
}
|
|
36898
38747
|
async function readSkill(dir, includeInternal) {
|
|
36899
|
-
const file =
|
|
38748
|
+
const file = path17.join(dir, "SKILL.md");
|
|
36900
38749
|
const label = sanitizeMetadata(file);
|
|
36901
38750
|
let parsed;
|
|
36902
38751
|
try {
|
|
36903
|
-
parsed = parseFrontmatter(await
|
|
38752
|
+
parsed = parseFrontmatter(await readFile4(file, "utf-8"));
|
|
36904
38753
|
} catch (error) {
|
|
36905
38754
|
const reason = error instanceof Error ? error.message : "it cannot be read";
|
|
36906
38755
|
Ui.warn(`Skipped ${label}: ${sanitizeMetadata(reason)}`);
|
|
@@ -36930,35 +38779,35 @@ function isInternalSkillsEnabled() {
|
|
|
36930
38779
|
}
|
|
36931
38780
|
async function hasSkillFile(dir) {
|
|
36932
38781
|
try {
|
|
36933
|
-
const stats = await stat2(
|
|
38782
|
+
const stats = await stat2(path17.join(dir, "SKILL.md"));
|
|
36934
38783
|
return stats.isFile();
|
|
36935
38784
|
} catch {
|
|
36936
38785
|
return false;
|
|
36937
38786
|
}
|
|
36938
38787
|
}
|
|
36939
38788
|
async function readSourceLockNames(root) {
|
|
36940
|
-
const value = await readJsonFile(
|
|
38789
|
+
const value = await readJsonFile(path17.join(root, "skills-lock.json"));
|
|
36941
38790
|
const result = SourceLockSchema.safeParse(value);
|
|
36942
38791
|
const names = result.success ? Object.keys(result.data.skills) : [];
|
|
36943
38792
|
return new Set(names.map(normalizeSkillName));
|
|
36944
38793
|
}
|
|
36945
38794
|
async function getSkillsShDirs(root) {
|
|
36946
|
-
const result = SkillsShConfigSchema.safeParse(await readJsonFile(
|
|
38795
|
+
const result = SkillsShConfigSchema.safeParse(await readJsonFile(path17.join(root, "skills.sh.json")));
|
|
36947
38796
|
const paths = result.success ? result.data.paths : [];
|
|
36948
38797
|
const normalized = paths.flatMap((entry) => {
|
|
36949
38798
|
if (!entry.startsWith("./") || entry.includes("\\")) {
|
|
36950
38799
|
return [];
|
|
36951
38800
|
}
|
|
36952
|
-
const clean =
|
|
38801
|
+
const clean = path17.posix.normalize(entry).replace(/\/+$/u, "");
|
|
36953
38802
|
const isOutside = clean === "." || clean === "" || clean === ".." || clean.startsWith("../");
|
|
36954
|
-
return isOutside ||
|
|
38803
|
+
return isOutside || path17.posix.isAbsolute(clean) ? [] : [clean];
|
|
36955
38804
|
});
|
|
36956
|
-
return [...new Set(normalized)].map((entry) =>
|
|
38805
|
+
return [...new Set(normalized)].map((entry) => path17.join(root, entry));
|
|
36957
38806
|
}
|
|
36958
38807
|
async function readPlugins(root) {
|
|
36959
38808
|
const [marketplaceValue, pluginValue] = await Promise.all([
|
|
36960
|
-
readJsonFile(
|
|
36961
|
-
readJsonFile(
|
|
38809
|
+
readJsonFile(path17.join(root, ".claude-plugin/marketplace.json")),
|
|
38810
|
+
readJsonFile(path17.join(root, ".claude-plugin/plugin.json"))
|
|
36962
38811
|
]);
|
|
36963
38812
|
const marketplace = MarketplaceSchema.safeParse(marketplaceValue);
|
|
36964
38813
|
const plugin = PluginSchema.safeParse(pluginValue);
|
|
@@ -36970,16 +38819,16 @@ async function readPlugins(root) {
|
|
|
36970
38819
|
if (entry.source !== undefined && !ManifestPathSchema.safeParse(source).success) {
|
|
36971
38820
|
return [];
|
|
36972
38821
|
}
|
|
36973
|
-
const base =
|
|
38822
|
+
const base = path17.join(root, pluginRoot ?? "", ManifestPathSchema.parse(source || "./"));
|
|
36974
38823
|
return [{ base, name: entry.name, skills: entry.skills ?? [] }];
|
|
36975
38824
|
});
|
|
36976
38825
|
const fromPlugin = plugin.success ? [{ base: root, name: plugin.data.name, skills: plugin.data.skills ?? [] }] : [];
|
|
36977
|
-
return [...fromMarketplace, ...fromPlugin].filter((entry) => isInside(
|
|
38826
|
+
return [...fromMarketplace, ...fromPlugin].filter((entry) => isInside(path17.resolve(root), path17.resolve(entry.base)));
|
|
36978
38827
|
}
|
|
36979
38828
|
function getPluginSkillDirs(root, plugins) {
|
|
36980
38829
|
return plugins.flatMap((plugin) => [
|
|
36981
|
-
...plugin.skills.filter((skill) => skill.startsWith("./")).map((skill) =>
|
|
36982
|
-
|
|
38830
|
+
...plugin.skills.filter((skill) => skill.startsWith("./")).map((skill) => path17.dirname(path17.join(plugin.base, skill))).filter((dir) => isInside(path17.resolve(root), path17.resolve(dir))),
|
|
38831
|
+
path17.join(plugin.base, "skills")
|
|
36983
38832
|
]);
|
|
36984
38833
|
}
|
|
36985
38834
|
function getPluginGroupings(root, plugins) {
|
|
@@ -36989,8 +38838,8 @@ function getPluginGroupings(root, plugins) {
|
|
|
36989
38838
|
return [];
|
|
36990
38839
|
}
|
|
36991
38840
|
return plugin.skills.flatMap((skill) => {
|
|
36992
|
-
const dir =
|
|
36993
|
-
const isValid = skill.startsWith("./") && isInside(
|
|
38841
|
+
const dir = path17.resolve(plugin.base, skill);
|
|
38842
|
+
const isValid = skill.startsWith("./") && isInside(path17.resolve(root), dir);
|
|
36994
38843
|
return isValid ? [[dir, name]] : [];
|
|
36995
38844
|
});
|
|
36996
38845
|
});
|
|
@@ -37061,10 +38910,10 @@ function skipEscape(codes, start) {
|
|
|
37061
38910
|
|
|
37062
38911
|
// src/skills/plan.ts
|
|
37063
38912
|
import { existsSync as existsSync6 } from "node:fs";
|
|
37064
|
-
import
|
|
38913
|
+
import path19 from "node:path";
|
|
37065
38914
|
|
|
37066
38915
|
// src/skills/source.ts
|
|
37067
|
-
import
|
|
38916
|
+
import path18 from "node:path";
|
|
37068
38917
|
var DefaultGitHubHost = "github.com";
|
|
37069
38918
|
var SourceAliases = new Map([
|
|
37070
38919
|
["coinbase/agentWallet", "coinbase/agentic-wallet-skills"],
|
|
@@ -37118,8 +38967,8 @@ function getLockSourceUrl(parsed, lockKind) {
|
|
|
37118
38967
|
}
|
|
37119
38968
|
function toManifestSource(parsed, manifestDir) {
|
|
37120
38969
|
if (parsed.type === "local") {
|
|
37121
|
-
const relative =
|
|
37122
|
-
if (
|
|
38970
|
+
const relative = path18.relative(manifestDir, parsed.url).split(path18.sep).join("/");
|
|
38971
|
+
if (path18.isAbsolute(relative)) {
|
|
37123
38972
|
return relative;
|
|
37124
38973
|
}
|
|
37125
38974
|
return relative.startsWith("../") || relative === ".." ? relative : `./${relative}`;
|
|
@@ -37491,7 +39340,7 @@ async function getInstalledState(scope, lock, name, locked) {
|
|
|
37491
39340
|
return await getDirectoryState(getCanonicalDir(scope, name), lock, name, locked);
|
|
37492
39341
|
}
|
|
37493
39342
|
async function getDirectoryState(dir, lock, name, locked) {
|
|
37494
|
-
if (!existsSync6(
|
|
39343
|
+
if (!existsSync6(path19.join(dir, "SKILL.md"))) {
|
|
37495
39344
|
return "missing";
|
|
37496
39345
|
}
|
|
37497
39346
|
if (locked === undefined || locked.hash === "") {
|
|
@@ -37520,7 +39369,7 @@ async function getSkillState(scope, lock, skill) {
|
|
|
37520
39369
|
}
|
|
37521
39370
|
function getCanonicalDir(scope, name) {
|
|
37522
39371
|
assertSkillName(name, "The skill name");
|
|
37523
|
-
return
|
|
39372
|
+
return path19.join(skillsDir(scope), name);
|
|
37524
39373
|
}
|
|
37525
39374
|
async function loadSkillsLock(scope) {
|
|
37526
39375
|
const lock = await readSkillsLock(scope);
|
|
@@ -37528,7 +39377,7 @@ async function loadSkillsLock(scope) {
|
|
|
37528
39377
|
return lock;
|
|
37529
39378
|
}
|
|
37530
39379
|
const migrated = await Promise.all(Object.entries(lock.skills).map(async ([name, entry]) => {
|
|
37531
|
-
const dir =
|
|
39380
|
+
const dir = path19.join(skillsDir(scope), sanitizeName(name));
|
|
37532
39381
|
const hash = await migrateHash(dir, entry.hash);
|
|
37533
39382
|
return [name, { ...entry, hash }];
|
|
37534
39383
|
}));
|
|
@@ -37538,7 +39387,7 @@ function isLockCurrent(skill, locked) {
|
|
|
37538
39387
|
const isRenamed = skill.sourceName !== skill.name;
|
|
37539
39388
|
const isSameName = isRenamed ? locked.skillName !== undefined && normalizeSkillName(locked.skillName) === normalizeSkillName(skill.sourceName) : locked.skillName === undefined;
|
|
37540
39389
|
const subpath = skill.source.subpath?.replaceAll("\\", "/").replace(/\/+$/u, "");
|
|
37541
|
-
const folder =
|
|
39390
|
+
const folder = path19.posix.dirname(locked.skillPath ?? "SKILL.md");
|
|
37542
39391
|
const isInPath = subpath === undefined || folder === subpath || folder.startsWith(`${subpath}/`);
|
|
37543
39392
|
return locked.source === getLockSource(skill.source) && locked.sourceType === getLockSourceType(skill.source) && locked.ref === skill.source.ref && locked.installMode === (skill.entry.copy === true ? "copy" : undefined) && isSameName && isInPath;
|
|
37544
39393
|
}
|
|
@@ -37651,7 +39500,7 @@ function resolveEntrySource(entry, scope) {
|
|
|
37651
39500
|
const ref = entry.ref ?? parsed.ref;
|
|
37652
39501
|
const subpath = entry.path === undefined ? parsed.subpath : sanitizeSubpath(entry.path);
|
|
37653
39502
|
if (parsed.type === "local") {
|
|
37654
|
-
const url = subpath === undefined ? parsed.url :
|
|
39503
|
+
const url = subpath === undefined ? parsed.url : path19.join(parsed.url, subpath);
|
|
37655
39504
|
return { type: "local", url };
|
|
37656
39505
|
}
|
|
37657
39506
|
const resolved = { type: parsed.type, url: parsed.url };
|
|
@@ -37664,7 +39513,7 @@ function resolveEntrySource(entry, scope) {
|
|
|
37664
39513
|
return resolved;
|
|
37665
39514
|
}
|
|
37666
39515
|
async function migrateHash(dir, legacyHash) {
|
|
37667
|
-
if (legacyHash === "" || !existsSync6(
|
|
39516
|
+
if (legacyHash === "" || !existsSync6(path19.join(dir, "SKILL.md"))) {
|
|
37668
39517
|
return "";
|
|
37669
39518
|
}
|
|
37670
39519
|
try {
|
|
@@ -37728,13 +39577,13 @@ async function linkSkill(scope, skill, adapters, force) {
|
|
|
37728
39577
|
await Promise.all(adapters.map((adapter) => adapter.skills.add(scope, canonical)));
|
|
37729
39578
|
}
|
|
37730
39579
|
async function writeCanonical(scope, name, files) {
|
|
37731
|
-
const base =
|
|
37732
|
-
const target =
|
|
39580
|
+
const base = path20.resolve(skillsDir(scope));
|
|
39581
|
+
const target = path20.resolve(getCanonicalDir(scope, name));
|
|
37733
39582
|
if (target === base || !isInside(base, target)) {
|
|
37734
39583
|
throw new OperationError(`The skill name ${name} resolves outside ${base}.`);
|
|
37735
39584
|
}
|
|
37736
39585
|
const destinations = files.map((file) => {
|
|
37737
|
-
const destination =
|
|
39586
|
+
const destination = path20.resolve(target, file.path);
|
|
37738
39587
|
if (!isInside(target, destination)) {
|
|
37739
39588
|
throw new OperationError(`The file ${file.path} of ${name} resolves outside the skill directory.`);
|
|
37740
39589
|
}
|
|
@@ -37743,7 +39592,7 @@ async function writeCanonical(scope, name, files) {
|
|
|
37743
39592
|
await rm2(target, { force: true, recursive: true });
|
|
37744
39593
|
await mkdir4(target, { recursive: true });
|
|
37745
39594
|
await Promise.all(destinations.map(async ({ destination, file }) => {
|
|
37746
|
-
await mkdir4(
|
|
39595
|
+
await mkdir4(path20.dirname(destination), { recursive: true });
|
|
37747
39596
|
await writeFile4(destination, file.content);
|
|
37748
39597
|
await chmod(destination, file.mode);
|
|
37749
39598
|
}));
|
|
@@ -37774,7 +39623,7 @@ async function prepareSkill(scope, lock, action, cache) {
|
|
|
37774
39623
|
}
|
|
37775
39624
|
async function findSkill(fetched, skill, lockedPath) {
|
|
37776
39625
|
const requested = [skill.sourceName];
|
|
37777
|
-
const lockedDir = lockedPath === undefined ? undefined :
|
|
39626
|
+
const lockedDir = lockedPath === undefined ? undefined : path20.posix.dirname(lockedPath);
|
|
37778
39627
|
const atLockedPath = lockedDir === undefined || lockedDir === "." ? [] : await discoverSkills(fetched.root, { requested, subpath: lockedDir }).catch(() => []);
|
|
37779
39628
|
const [pinned] = filterSkills(atLockedPath, requested);
|
|
37780
39629
|
if (pinned !== undefined) {
|
|
@@ -37789,7 +39638,7 @@ async function findSkill(fetched, skill, lockedPath) {
|
|
|
37789
39638
|
throw new OperationError(`${skill.entry.source} has no skill named ${skill.sourceName}, which the manifest declares as ${skill.name}. Skills found: ${names}.`);
|
|
37790
39639
|
}
|
|
37791
39640
|
function getSkillPath(root, dir) {
|
|
37792
|
-
const folder =
|
|
39641
|
+
const folder = path20.relative(root, dir).split(path20.sep).join("/");
|
|
37793
39642
|
return folder === "" ? "SKILL.md" : `${folder}/SKILL.md`;
|
|
37794
39643
|
}
|
|
37795
39644
|
function describeInstall(prepared) {
|
|
@@ -37802,14 +39651,14 @@ function describeInstall(prepared) {
|
|
|
37802
39651
|
}
|
|
37803
39652
|
|
|
37804
39653
|
// src/skills/fetch.ts
|
|
37805
|
-
import { execFile as
|
|
39654
|
+
import { execFile as execFile5 } from "node:child_process";
|
|
37806
39655
|
import { existsSync as existsSync7 } from "node:fs";
|
|
37807
39656
|
import { mkdir as mkdir5, mkdtemp, readdir as readdir4, rm as rm3, stat as stat3, writeFile as writeFile5 } from "node:fs/promises";
|
|
37808
39657
|
import { tmpdir } from "node:os";
|
|
37809
|
-
import
|
|
37810
|
-
import { promisify as
|
|
39658
|
+
import path21 from "node:path";
|
|
39659
|
+
import { promisify as promisify5 } from "node:util";
|
|
37811
39660
|
import { gunzipSync, inflateRawSync } from "node:zlib";
|
|
37812
|
-
var run3 =
|
|
39661
|
+
var run3 = promisify5(execFile5);
|
|
37813
39662
|
var DefaultCloneTimeoutMs = 300000;
|
|
37814
39663
|
var DownloadTimeoutMs = 30000;
|
|
37815
39664
|
var MaxDownloadBytes = 10 * 1024 * 1024;
|
|
@@ -37860,7 +39709,7 @@ async function cloneSource(url, ref) {
|
|
|
37860
39709
|
if (/^ext::/iu.test(url)) {
|
|
37861
39710
|
throw new OperationError(`The Git transport "ext::" is not supported: ${url}`);
|
|
37862
39711
|
}
|
|
37863
|
-
const dir = await mkdtemp(
|
|
39712
|
+
const dir = await mkdtemp(path21.join(tmpdir(), "agentsrc-git-"));
|
|
37864
39713
|
const dispose = () => rm3(dir, { force: true, recursive: true });
|
|
37865
39714
|
const cloned = await cloneInto(url, dir, ref);
|
|
37866
39715
|
const sshUrl = getGitHubSshUrl(url);
|
|
@@ -37976,17 +39825,17 @@ async function resetDir(dir) {
|
|
|
37976
39825
|
await mkdir5(dir, { recursive: true });
|
|
37977
39826
|
}
|
|
37978
39827
|
async function downloadSource(url) {
|
|
37979
|
-
const dir = await mkdtemp(
|
|
39828
|
+
const dir = await mkdtemp(path21.join(tmpdir(), "agentsrc-download-"));
|
|
37980
39829
|
const dispose = () => rm3(dir, { force: true, recursive: true });
|
|
37981
39830
|
try {
|
|
37982
39831
|
const bytes = await download(url);
|
|
37983
39832
|
if (isSkillMarkdown(bytes)) {
|
|
37984
|
-
const skillDir =
|
|
39833
|
+
const skillDir = path21.join(dir, "skill");
|
|
37985
39834
|
await mkdir5(skillDir, { recursive: true });
|
|
37986
|
-
await writeFile5(
|
|
39835
|
+
await writeFile5(path21.join(skillDir, "SKILL.md"), bytes);
|
|
37987
39836
|
return { dispose, root: skillDir };
|
|
37988
39837
|
}
|
|
37989
|
-
const extractDir =
|
|
39838
|
+
const extractDir = path21.join(dir, "extract");
|
|
37990
39839
|
const files = readArchive(bytes, url);
|
|
37991
39840
|
await writeArchive(files, extractDir);
|
|
37992
39841
|
return { dispose, root: await getSingleTopDir(extractDir) };
|
|
@@ -38206,14 +40055,14 @@ function checkArchiveLimits(entries, bytes, url) {
|
|
|
38206
40055
|
async function writeArchive(files, dir) {
|
|
38207
40056
|
await mkdir5(dir, { recursive: true });
|
|
38208
40057
|
const targets = files.map((file) => {
|
|
38209
|
-
const target =
|
|
40058
|
+
const target = path21.join(dir, file.path);
|
|
38210
40059
|
if (!isInside(dir, target)) {
|
|
38211
40060
|
throw new OperationError(`The archive entry ${file.path} leaves the archive.`);
|
|
38212
40061
|
}
|
|
38213
40062
|
return { file, target };
|
|
38214
40063
|
});
|
|
38215
40064
|
await Promise.all(targets.map(async ({ file, target }) => {
|
|
38216
|
-
await mkdir5(
|
|
40065
|
+
await mkdir5(path21.dirname(target), { recursive: true });
|
|
38217
40066
|
await writeFile5(target, file.content, { mode: file.mode % PermissionUnit2 });
|
|
38218
40067
|
}));
|
|
38219
40068
|
}
|
|
@@ -38227,7 +40076,7 @@ async function getSingleTopDir(dir) {
|
|
|
38227
40076
|
if (only === undefined) {
|
|
38228
40077
|
return dir;
|
|
38229
40078
|
}
|
|
38230
|
-
const candidate =
|
|
40079
|
+
const candidate = path21.join(dir, only);
|
|
38231
40080
|
const stats = await stat3(candidate);
|
|
38232
40081
|
return stats.isDirectory() ? candidate : dir;
|
|
38233
40082
|
}
|
|
@@ -38457,7 +40306,7 @@ function listNames(skills) {
|
|
|
38457
40306
|
return skills.map((skill) => skill.name).join(", ");
|
|
38458
40307
|
}
|
|
38459
40308
|
function createEntry(workspace, parsed, options) {
|
|
38460
|
-
const manifestDir =
|
|
40309
|
+
const manifestDir = path22.dirname(workspace.manifestFile);
|
|
38461
40310
|
return withoutUndefined2({
|
|
38462
40311
|
source: toManifestSource(parsed, manifestDir),
|
|
38463
40312
|
ref: parsed.ref,
|
|
@@ -38473,7 +40322,7 @@ function withoutUndefined2(entry) {
|
|
|
38473
40322
|
}
|
|
38474
40323
|
function withDeclaredEntries(workspace, entries) {
|
|
38475
40324
|
const declaredIn = { kind: "file", path: workspace.manifestFile };
|
|
38476
|
-
const manifestDir =
|
|
40325
|
+
const manifestDir = path22.dirname(workspace.manifestFile);
|
|
38477
40326
|
const added = entries.map(({ name, entry }) => {
|
|
38478
40327
|
const parsed = parseSource(entry.source, { cwd: manifestDir });
|
|
38479
40328
|
const source = parsed.type === "local" ? parsed.url : entry.source;
|
|
@@ -38626,10 +40475,368 @@ var SyncCommand = defineCommand("sync", { description: "Install skills, then MCP
|
|
|
38626
40475
|
await installSkills(workspace, options);
|
|
38627
40476
|
await installServers(workspace, options);
|
|
38628
40477
|
}));
|
|
40478
|
+
|
|
40479
|
+
// src/commands/usage.ts
|
|
40480
|
+
init_dist();
|
|
40481
|
+
|
|
40482
|
+
// src/usage/report.ts
|
|
40483
|
+
function createReport(snapshot, now) {
|
|
40484
|
+
return {
|
|
40485
|
+
...snapshot,
|
|
40486
|
+
resets: {
|
|
40487
|
+
...snapshot.resets,
|
|
40488
|
+
credits: snapshot.resets.credits.map((credit) => ({ ...credit }))
|
|
40489
|
+
},
|
|
40490
|
+
fetchedAt: new Date(now).toISOString(),
|
|
40491
|
+
windows: snapshot.windows.map((window2) => ({
|
|
40492
|
+
...window2,
|
|
40493
|
+
remainingPercent: Math.max(0, 100 - window2.usedPercent),
|
|
40494
|
+
status: windowStatus(window2, now)
|
|
40495
|
+
}))
|
|
40496
|
+
};
|
|
40497
|
+
}
|
|
40498
|
+
function reportTitle(report, color = false) {
|
|
40499
|
+
const name = report.displayName ?? `${report.provider.charAt(0).toUpperCase()}${report.provider.slice(1)}`;
|
|
40500
|
+
const account = report.account.name ?? report.account.id ?? "account unknown";
|
|
40501
|
+
return `${Ui.style(["bold", "cyan"], name, color)} · ${Ui.style("dim", account, color)}${report.limited ? Ui.style(["bold", "red"], " · LIMIT REACHED", color) : ""}`;
|
|
40502
|
+
}
|
|
40503
|
+
function formatReport(report, now, color = false) {
|
|
40504
|
+
const labels = report.windows.map((window2) => shortLabel(window2.label));
|
|
40505
|
+
const width = Math.max(0, ...labels.map((label) => label.length));
|
|
40506
|
+
const lines = report.windows.map((window2, index) => {
|
|
40507
|
+
const remaining = Math.max(0, Math.min(100, window2.remainingPercent));
|
|
40508
|
+
const filled = Math.round(remaining / 100 * 8);
|
|
40509
|
+
const tone = allowanceColor(remaining);
|
|
40510
|
+
const bar = `${Ui.style(tone, "█".repeat(filled), color)}${Ui.style("dim", "░".repeat(8 - filled), color)}`;
|
|
40511
|
+
const reset = window2.resetsAt ? `resets ${countdown(window2.resetsAt, now)}` : "reset unknown";
|
|
40512
|
+
const status = statusLabel(window2);
|
|
40513
|
+
const percentage = Ui.style(["bold", tone], `${Math.round(remaining)}% left`, color);
|
|
40514
|
+
const warning = status ? ` · ${Ui.style(window2.status === "limited" ? "red" : "yellow", status, color)}` : "";
|
|
40515
|
+
return `${(labels[index] ?? "").padEnd(width)} ${bar} ${percentage} · ${Ui.style("dim", reset, color)}${warning}`;
|
|
40516
|
+
});
|
|
40517
|
+
if (lines.length === 0) {
|
|
40518
|
+
lines.push("No limits reported");
|
|
40519
|
+
}
|
|
40520
|
+
if (report.resets.supported !== false && (report.resets.available ?? 0) > 0) {
|
|
40521
|
+
lines.push(resetSummary(report.resets, now, color));
|
|
40522
|
+
}
|
|
40523
|
+
return lines.join(`
|
|
40524
|
+
`);
|
|
40525
|
+
}
|
|
40526
|
+
function shortLabel(label) {
|
|
40527
|
+
return label.replace(/^Usage /u, "").replace(/^five hour/u, "5h").replace(/^seven day/u, "Weekly").replace("5-hour", "5h").replace("weekly", "Weekly");
|
|
40528
|
+
}
|
|
40529
|
+
function statusLabel(window2) {
|
|
40530
|
+
if (window2.status === "awaiting_refresh") {
|
|
40531
|
+
return "refresh due";
|
|
40532
|
+
}
|
|
40533
|
+
if (window2.status === "limited") {
|
|
40534
|
+
return "limit reached";
|
|
40535
|
+
}
|
|
40536
|
+
return null;
|
|
40537
|
+
}
|
|
40538
|
+
function resetSummary(resets, now, color) {
|
|
40539
|
+
const prefix = `Resets ${Ui.style("cyan", String(resets.available), color)} available · `;
|
|
40540
|
+
const live = resets.credits.filter((credit) => credit.canClaim);
|
|
40541
|
+
const [next] = live.flatMap((credit) => credit.expiresAt ? [credit.expiresAt] : []).toSorted();
|
|
40542
|
+
if (next) {
|
|
40543
|
+
const hours = (Date.parse(next) - now) / 3600000;
|
|
40544
|
+
const timing = countdown(next, now);
|
|
40545
|
+
const label = timing.startsWith("in ") ? "next expires in " : "next expires ";
|
|
40546
|
+
return `${prefix}${Ui.style("dim", label, color)}${Ui.style(expiryColor(hours), timing.replace(/^in /u, ""), color)}`;
|
|
40547
|
+
}
|
|
40548
|
+
const neverExpire = live.length > 0 && live.every((credit) => credit.expiry === "never");
|
|
40549
|
+
return `${prefix}${Ui.style("dim", neverExpire ? "does not expire" : "expiry unknown", color)}`;
|
|
40550
|
+
}
|
|
40551
|
+
function countdown(at, now) {
|
|
40552
|
+
const minutes = Math.ceil((Date.parse(at) - now) / 60000);
|
|
40553
|
+
if (minutes <= 0) {
|
|
40554
|
+
return "now";
|
|
40555
|
+
}
|
|
40556
|
+
if (minutes < 60) {
|
|
40557
|
+
return `in ${minutes}m`;
|
|
40558
|
+
}
|
|
40559
|
+
if (minutes < 1440) {
|
|
40560
|
+
const hours = Math.floor(minutes / 60);
|
|
40561
|
+
const remainder = minutes % 60;
|
|
40562
|
+
return `in ${hours}h${remainder ? ` ${remainder}m` : ""}`;
|
|
40563
|
+
}
|
|
40564
|
+
const days = Math.floor(minutes / 1440);
|
|
40565
|
+
const hours = Math.floor(minutes % 1440 / 60);
|
|
40566
|
+
return `in ${days}d${hours ? ` ${hours}h` : ""}`;
|
|
40567
|
+
}
|
|
40568
|
+
function windowStatus(window2, now) {
|
|
40569
|
+
if (window2.resetsAt && Date.parse(window2.resetsAt) <= now) {
|
|
40570
|
+
return "awaiting_refresh";
|
|
40571
|
+
}
|
|
40572
|
+
return window2.usedPercent >= 100 ? "limited" : "available";
|
|
40573
|
+
}
|
|
40574
|
+
function allowanceColor(remaining) {
|
|
40575
|
+
if (remaining <= 20) {
|
|
40576
|
+
return "red";
|
|
40577
|
+
}
|
|
40578
|
+
if (remaining <= 50) {
|
|
40579
|
+
return "yellow";
|
|
40580
|
+
}
|
|
40581
|
+
return "green";
|
|
40582
|
+
}
|
|
40583
|
+
function expiryColor(hours) {
|
|
40584
|
+
if (hours < 12) {
|
|
40585
|
+
return "red";
|
|
40586
|
+
}
|
|
40587
|
+
if (hours < 24) {
|
|
40588
|
+
return "yellow";
|
|
40589
|
+
}
|
|
40590
|
+
return "dim";
|
|
40591
|
+
}
|
|
40592
|
+
|
|
40593
|
+
// src/usage/reset.ts
|
|
40594
|
+
import { randomUUID } from "node:crypto";
|
|
40595
|
+
var SoonMs = 12 * 3600000;
|
|
40596
|
+
function availableResets(credits, now) {
|
|
40597
|
+
return credits.filter((credit) => credit.canClaim && credit.count > 0 && (!credit.expiresAt || Date.parse(credit.expiresAt) > now)).toSorted((left, right) => expiry(left) - expiry(right));
|
|
40598
|
+
}
|
|
40599
|
+
function resetWarnings(snapshot, credit, now) {
|
|
40600
|
+
const warnings = [];
|
|
40601
|
+
const covered = snapshot.windows.filter((window2) => window2.id && credit.restores?.includes(window2.id));
|
|
40602
|
+
if (covered.length === 0) {
|
|
40603
|
+
warnings.push("Cannot determine which usage limits this reset restores.");
|
|
40604
|
+
return warnings;
|
|
40605
|
+
}
|
|
40606
|
+
const blocked = snapshot.windows.filter((window2) => window2.usedPercent >= 100 && !covered.includes(window2));
|
|
40607
|
+
if (blocked.length > 0) {
|
|
40608
|
+
warnings.push(`Other exhausted limits may still block usage: ${blocked.map((window2) => window2.label).join(", ")}.`);
|
|
40609
|
+
}
|
|
40610
|
+
if (credit.expiry === "unknown") {
|
|
40611
|
+
warnings.push("The reset's expiry is unknown.");
|
|
40612
|
+
}
|
|
40613
|
+
const expiresSoon = credit.expiresAt !== null && Date.parse(credit.expiresAt) - now < SoonMs;
|
|
40614
|
+
if (covered.every((window2) => window2.usedPercent < 100) && !expiresSoon) {
|
|
40615
|
+
warnings.push("All limits this reset restores still have unused allowance, and the reset is not known to expire within 12 hours.");
|
|
40616
|
+
}
|
|
40617
|
+
return warnings;
|
|
40618
|
+
}
|
|
40619
|
+
async function resetUsage(provider, account, options, ui = Ui, now = Date.now) {
|
|
40620
|
+
const { claimReset } = account;
|
|
40621
|
+
if (!claimReset) {
|
|
40622
|
+
throw new UsageError(`${provider} does not support claiming banked resets.`);
|
|
40623
|
+
}
|
|
40624
|
+
validateOptions(options, ui);
|
|
40625
|
+
const requestId = options.requestId ?? randomUUID();
|
|
40626
|
+
if (options.requestId && options.credit) {
|
|
40627
|
+
ui.warn("Retrying an earlier claim. Keep the original signed-in account, credit, and request ID.");
|
|
40628
|
+
if (!options.yes && !await ui.confirmReset(`Retry this ${provider} reset claim?`)) {
|
|
40629
|
+
return null;
|
|
40630
|
+
}
|
|
40631
|
+
return await submitClaim(provider, claimReset, options.credit, requestId, ui);
|
|
40632
|
+
}
|
|
40633
|
+
const snapshot = await account.read();
|
|
40634
|
+
const credits = availableResets(snapshot.resets.credits, now());
|
|
40635
|
+
const credit = await chooseCredit(credits, options, ui);
|
|
40636
|
+
if (!credit) {
|
|
40637
|
+
return null;
|
|
40638
|
+
}
|
|
40639
|
+
for (const warning of resetWarnings(snapshot, credit, now())) {
|
|
40640
|
+
ui.warn(warning);
|
|
40641
|
+
}
|
|
40642
|
+
const identity = snapshot.account.name ?? snapshot.account.id ?? provider;
|
|
40643
|
+
if (!options.yes && !await ui.confirmReset(`Claim ${credit.label} for ${identity}? This spends one reset.`)) {
|
|
40644
|
+
return null;
|
|
40645
|
+
}
|
|
40646
|
+
if (credit.expiresAt && Date.parse(credit.expiresAt) <= now()) {
|
|
40647
|
+
throw new Error("The selected reset expired while awaiting confirmation.");
|
|
40648
|
+
}
|
|
40649
|
+
return await submitClaim(provider, claimReset, credit.id, requestId, ui);
|
|
40650
|
+
}
|
|
40651
|
+
function expiry(credit) {
|
|
40652
|
+
return credit.expiresAt ? Date.parse(credit.expiresAt) : Number.POSITIVE_INFINITY;
|
|
40653
|
+
}
|
|
40654
|
+
async function submitClaim(provider, claimReset, creditId, requestId, ui) {
|
|
40655
|
+
ui.info(`Reset request: ${requestId}`);
|
|
40656
|
+
try {
|
|
40657
|
+
const result = await claimReset({ creditId, requestId });
|
|
40658
|
+
return { provider, creditId, requestId, ...result };
|
|
40659
|
+
} catch {
|
|
40660
|
+
throw new Error(`Reset result unknown. Retry: arc usage reset ${provider} --credit ${creditId} --request-id ${requestId}`);
|
|
40661
|
+
}
|
|
40662
|
+
}
|
|
40663
|
+
function validateOptions(options, ui) {
|
|
40664
|
+
if (!options.yes && !ui.isInteractive()) {
|
|
40665
|
+
throw new UsageError("Reset claims require confirmation. Run interactively or pass --yes.");
|
|
40666
|
+
}
|
|
40667
|
+
if (options.next && options.credit) {
|
|
40668
|
+
throw new UsageError("Choose --next or --credit, not both.");
|
|
40669
|
+
}
|
|
40670
|
+
if (options.requestId && !options.credit) {
|
|
40671
|
+
throw new UsageError("A retry needs --credit with the original --request-id.");
|
|
40672
|
+
}
|
|
40673
|
+
if (options.requestId && !/^[A-Za-z0-9_-]{1,64}$/u.test(options.requestId)) {
|
|
40674
|
+
throw new UsageError("--request-id must contain 1–64 letters, numbers, underscores, or hyphens.");
|
|
40675
|
+
}
|
|
40676
|
+
}
|
|
40677
|
+
async function chooseCredit(credits, options, ui) {
|
|
40678
|
+
if (credits.length === 0) {
|
|
40679
|
+
throw new Error("No claimable resets are available.");
|
|
40680
|
+
}
|
|
40681
|
+
if (options.next) {
|
|
40682
|
+
return credits[0] ?? null;
|
|
40683
|
+
}
|
|
40684
|
+
let chosen = options.credit;
|
|
40685
|
+
if (!chosen) {
|
|
40686
|
+
if (!ui.isInteractive()) {
|
|
40687
|
+
throw new UsageError("Run interactively to choose a reset, or pass --next --yes.");
|
|
40688
|
+
}
|
|
40689
|
+
chosen = await ui.pick("Which reset do you want to claim?", credits.map((credit) => ({
|
|
40690
|
+
value: credit.id,
|
|
40691
|
+
label: `${credit.label} · ${credit.count} available`,
|
|
40692
|
+
hint: creditHint(credit)
|
|
40693
|
+
}))) ?? undefined;
|
|
40694
|
+
if (!chosen) {
|
|
40695
|
+
return null;
|
|
40696
|
+
}
|
|
40697
|
+
}
|
|
40698
|
+
const credit = credits.find((item) => item.id === chosen);
|
|
40699
|
+
if (!credit) {
|
|
40700
|
+
throw new Error("This reset is unavailable or expired. Run usage again.");
|
|
40701
|
+
}
|
|
40702
|
+
return credit;
|
|
40703
|
+
}
|
|
40704
|
+
function creditHint(credit) {
|
|
40705
|
+
if (credit.expiresAt) {
|
|
40706
|
+
return `expires ${credit.expiresAt}`;
|
|
40707
|
+
}
|
|
40708
|
+
return credit.expiry === "never" ? "does not expire" : "expiry unknown";
|
|
40709
|
+
}
|
|
40710
|
+
|
|
40711
|
+
// src/commands/usage.ts
|
|
40712
|
+
var HarnessArg = {
|
|
40713
|
+
name: "harness",
|
|
40714
|
+
type: "string",
|
|
40715
|
+
description: "Harness: claude-code, codex, or opencode"
|
|
40716
|
+
};
|
|
40717
|
+
var ResetCommand = defineCommand("reset", { description: "Choose and claim a banked reset" }, (command) => command.args(HarnessArg).flags({
|
|
40718
|
+
...JsonFlagDef,
|
|
40719
|
+
next: { type: "boolean", description: "Choose the reset that expires first" },
|
|
40720
|
+
yes: { type: "boolean", short: "y", description: "Claim without confirmation" },
|
|
40721
|
+
credit: {
|
|
40722
|
+
type: "string",
|
|
40723
|
+
description: "Explicit credit ID, including when retrying a claim"
|
|
40724
|
+
},
|
|
40725
|
+
"request-id": {
|
|
40726
|
+
type: "string",
|
|
40727
|
+
description: "Original request ID for retrying an uncertain claim"
|
|
40728
|
+
}
|
|
40729
|
+
}).action(async ({ args, flags }) => {
|
|
40730
|
+
const selected = await chooseResetAccount(args.harness);
|
|
40731
|
+
if (!selected) {
|
|
40732
|
+
return;
|
|
40733
|
+
}
|
|
40734
|
+
const result = await resetUsage(selected.provider, selected.account, {
|
|
40735
|
+
next: flags.next ?? false,
|
|
40736
|
+
yes: flags.yes ?? false,
|
|
40737
|
+
credit: flags.credit,
|
|
40738
|
+
requestId: flags["request-id"]
|
|
40739
|
+
});
|
|
40740
|
+
if (!result) {
|
|
40741
|
+
return;
|
|
40742
|
+
}
|
|
40743
|
+
if (flags.json) {
|
|
40744
|
+
Ui.json(result);
|
|
40745
|
+
} else if (result.success) {
|
|
40746
|
+
Ui.success(`${selected.provider}: reset claimed.`);
|
|
40747
|
+
}
|
|
40748
|
+
if (!result.success) {
|
|
40749
|
+
throw new Error(`Reset was not confirmed: ${result.outcome}.`);
|
|
40750
|
+
}
|
|
40751
|
+
}));
|
|
40752
|
+
var UsageCommand = defineCommand("usage", { description: "Show provider limits, reset timing, and banked resets" }, (command) => command.args(HarnessArg).flags(JsonFlagDef).add(ResetCommand).action(async ({ args, flags }) => {
|
|
40753
|
+
const selected = args.harness ? [selectHarness(args.harness)] : AllAdapters.filter((adapter) => adapter.detect() && adapter.usage);
|
|
40754
|
+
const progress = !flags.json && process.stderr.isTTY && !process.env.CI ? Ui.spinner() : undefined;
|
|
40755
|
+
progress?.start("Checking usage");
|
|
40756
|
+
const results = await Promise.all([...new Set(selected)].map(async (adapter) => {
|
|
40757
|
+
const source = adapter.usage;
|
|
40758
|
+
if (!source) {
|
|
40759
|
+
throw new UsageError(`Usage is unavailable for ${adapter.id}.`);
|
|
40760
|
+
}
|
|
40761
|
+
const { provider } = source;
|
|
40762
|
+
try {
|
|
40763
|
+
const account = await source.connect();
|
|
40764
|
+
if (!account) {
|
|
40765
|
+
return {
|
|
40766
|
+
provider,
|
|
40767
|
+
report: null,
|
|
40768
|
+
error: args.harness ? `Sign in with the ${provider} CLI first.` : null
|
|
40769
|
+
};
|
|
40770
|
+
}
|
|
40771
|
+
const snapshot = await account.read();
|
|
40772
|
+
return { provider, report: createReport(snapshot, Date.now()), error: null };
|
|
40773
|
+
} catch (error) {
|
|
40774
|
+
return {
|
|
40775
|
+
provider,
|
|
40776
|
+
report: null,
|
|
40777
|
+
error: error instanceof Error && !(error instanceof ZodError) ? error.message : `${provider}: unexpected provider response. Try updating agentsrc.`
|
|
40778
|
+
};
|
|
40779
|
+
}
|
|
40780
|
+
}));
|
|
40781
|
+
progress?.clear();
|
|
40782
|
+
const reports = results.flatMap((result) => result.report ? [result.report] : []);
|
|
40783
|
+
const errors = results.flatMap((result) => result.error ? [{ provider: result.provider, message: result.error }] : []);
|
|
40784
|
+
if (flags.json) {
|
|
40785
|
+
Ui.json({ providers: reports, errors });
|
|
40786
|
+
} else {
|
|
40787
|
+
for (const report of reports) {
|
|
40788
|
+
Ui.note(formatReport(report, Date.now(), true), reportTitle(report, true));
|
|
40789
|
+
}
|
|
40790
|
+
for (const error of errors) {
|
|
40791
|
+
Ui.warn(error.message);
|
|
40792
|
+
}
|
|
40793
|
+
}
|
|
40794
|
+
if (reports.length === 0 || errors.length > 0) {
|
|
40795
|
+
throw new Error(reports.length === 0 && errors.length === 0 ? "No detected harness logins found. Sign in with a supported harness first." : "Could not retrieve all requested provider usage.");
|
|
40796
|
+
}
|
|
40797
|
+
}));
|
|
40798
|
+
function selectHarness(value) {
|
|
40799
|
+
const adapter = AllAdapters.find((item) => item.id === value || item.usage?.provider === value);
|
|
40800
|
+
if (!adapter?.usage) {
|
|
40801
|
+
throw new UsageError(`Usage is unavailable for \`${value}\`. Choose ${AllAdapters.map((item) => item.id).join(", ")}.`);
|
|
40802
|
+
}
|
|
40803
|
+
return adapter;
|
|
40804
|
+
}
|
|
40805
|
+
async function chooseResetAccount(harness) {
|
|
40806
|
+
if (harness) {
|
|
40807
|
+
const adapter = selectHarness(harness);
|
|
40808
|
+
const source = adapter.usage;
|
|
40809
|
+
if (!source) {
|
|
40810
|
+
throw new UsageError(`Usage is unavailable for ${harness}.`);
|
|
40811
|
+
}
|
|
40812
|
+
const account = await source.connect();
|
|
40813
|
+
if (!account) {
|
|
40814
|
+
throw new Error(`Sign in with the ${source.provider} CLI first.`);
|
|
40815
|
+
}
|
|
40816
|
+
return { provider: source.provider, account };
|
|
40817
|
+
}
|
|
40818
|
+
if (!Ui.isInteractive()) {
|
|
40819
|
+
throw new UsageError("Run interactively to choose a harness, or pass a harness name.");
|
|
40820
|
+
}
|
|
40821
|
+
const connections = await Promise.all(AllAdapters.filter((adapter) => adapter.detect()).map(async (adapter) => {
|
|
40822
|
+
const source = adapter.usage;
|
|
40823
|
+
if (!source) {
|
|
40824
|
+
return null;
|
|
40825
|
+
}
|
|
40826
|
+
const account = await source.connect();
|
|
40827
|
+
return account?.claimReset ? { harness: adapter.id, provider: source.provider, account } : null;
|
|
40828
|
+
}));
|
|
40829
|
+
const accounts = connections.filter((connection) => connection !== null);
|
|
40830
|
+
if (accounts.length === 0) {
|
|
40831
|
+
throw new Error("No detected harness logins support reset claims.");
|
|
40832
|
+
}
|
|
40833
|
+
const chosen = await Ui.pick("Choose a harness", accounts.map((item) => ({ value: item.harness, label: item.harness })));
|
|
40834
|
+
return accounts.find((item) => item.harness === chosen) ?? null;
|
|
40835
|
+
}
|
|
38629
40836
|
// package.json
|
|
38630
40837
|
var package_default = {
|
|
38631
40838
|
name: "agentsrc",
|
|
38632
|
-
version: "0.
|
|
40839
|
+
version: "0.2.0",
|
|
38633
40840
|
description: "agentsrc - sync configuration across AI agent harnesses",
|
|
38634
40841
|
license: "AGPL-3.0",
|
|
38635
40842
|
repository: {
|
|
@@ -38670,6 +40877,7 @@ var package_default = {
|
|
|
38670
40877
|
},
|
|
38671
40878
|
devDependencies: {
|
|
38672
40879
|
"@changesets/cli": "^3.0.3",
|
|
40880
|
+
"@clack/prompts": "^1.9.0",
|
|
38673
40881
|
"@crustjs/core": "^0.6.0",
|
|
38674
40882
|
"@crustjs/extensions": "^0.6.0",
|
|
38675
40883
|
"@crustjs/prompts": "^0.3.0",
|
|
@@ -38687,7 +40895,7 @@ var package_default = {
|
|
|
38687
40895
|
zod: "^4.6.7"
|
|
38688
40896
|
},
|
|
38689
40897
|
engines: {
|
|
38690
|
-
node: ">=20"
|
|
40898
|
+
node: ">=20.12"
|
|
38691
40899
|
},
|
|
38692
40900
|
packageManager: "bun@1.4.4-canary.20261114.1",
|
|
38693
40901
|
patchedDependencies: {
|
|
@@ -38706,7 +40914,7 @@ async function runCli(argv) {
|
|
|
38706
40914
|
const app = new Crust("arc", {
|
|
38707
40915
|
description: "Install agent skills and MCP servers from one manifest into every AI harness",
|
|
38708
40916
|
version: package_default.version
|
|
38709
|
-
}).extend(exitCode, help(), version(), didYouMean()).add(InitCommand, SyncCommand, SkillsCommand, McpCommand);
|
|
40917
|
+
}).extend(exitCode, help(), version(), didYouMean()).add(InitCommand, SyncCommand, SkillsCommand, McpCommand, UsageCommand);
|
|
38710
40918
|
const code = await app.execute({ argv });
|
|
38711
40919
|
return isUsageFailure ? UsageExitCode : code;
|
|
38712
40920
|
}
|