@ponbac/token-ledger 0.2.0 → 0.4.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 +135 -20
- package/THIRD_PARTY_NOTICES.txt +27 -0
- package/dist/main.js +2953 -1279
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -32687,7 +32687,7 @@ function dayWindow(since, until, timeZone) {
|
|
|
32687
32687
|
}
|
|
32688
32688
|
|
|
32689
32689
|
// packages/core/src/model.ts
|
|
32690
|
-
var Provider = exports_Schema.Literals(["codex", "claude", "grok", "copilot"]);
|
|
32690
|
+
var Provider = exports_Schema.Literals(["codex", "claude", "grok", "copilot", "pi"]);
|
|
32691
32691
|
var Tokens = exports_Schema.Struct({
|
|
32692
32692
|
input: exports_Schema.Natural,
|
|
32693
32693
|
cacheRead: exports_Schema.Natural,
|
|
@@ -34428,6 +34428,7 @@ var projectResolver = exports_Effect.fn("Projects.resolver")(function* (mappings
|
|
|
34428
34428
|
// packages/core/src/providers/shared.ts
|
|
34429
34429
|
var empty14 = {
|
|
34430
34430
|
records: [],
|
|
34431
|
+
inherited: [],
|
|
34431
34432
|
hints: [],
|
|
34432
34433
|
malformed: 0,
|
|
34433
34434
|
skipped: 0,
|
|
@@ -34898,6 +34899,103 @@ function grokParser(file2) {
|
|
|
34898
34899
|
};
|
|
34899
34900
|
}
|
|
34900
34901
|
|
|
34902
|
+
// packages/core/src/providers/pi.ts
|
|
34903
|
+
var decodeKind = exports_Schema.decodeUnknownOption(exports_Schema.Struct({ type: exports_Schema.String }));
|
|
34904
|
+
var decodeHeader = exports_Schema.decodeUnknownOption(exports_Schema.Struct({
|
|
34905
|
+
id: exports_Schema.optionalKey(exports_Schema.String),
|
|
34906
|
+
timestamp: exports_Schema.optionalKey(exports_Schema.String),
|
|
34907
|
+
cwd: exports_Schema.optionalKey(exports_Schema.String),
|
|
34908
|
+
parentSession: exports_Schema.optionalKey(exports_Schema.String)
|
|
34909
|
+
}));
|
|
34910
|
+
var decodeWrapper = exports_Schema.decodeUnknownOption(exports_Schema.Struct({ message: exports_Schema.Unknown }));
|
|
34911
|
+
var decodeCarrier = exports_Schema.decodeUnknownOption(exports_Schema.Struct({
|
|
34912
|
+
role: exports_Schema.optionalKey(exports_Schema.String),
|
|
34913
|
+
usage: exports_Schema.optionalKey(exports_Schema.Unknown)
|
|
34914
|
+
}));
|
|
34915
|
+
var decodeStamp = exports_Schema.decodeUnknownOption(exports_Schema.Struct({ id: exports_Schema.optionalKey(exports_Schema.String), timestamp: exports_Schema.String }));
|
|
34916
|
+
var decodeNames = exports_Schema.decodeUnknownOption(exports_Schema.Struct({
|
|
34917
|
+
provider: exports_Schema.optionalKey(exports_Schema.String),
|
|
34918
|
+
model: exports_Schema.optionalKey(exports_Schema.String),
|
|
34919
|
+
responseModel: exports_Schema.optionalKey(exports_Schema.String)
|
|
34920
|
+
}));
|
|
34921
|
+
var decodeCounts = exports_Schema.decodeUnknownOption(exports_Schema.Struct({
|
|
34922
|
+
input: exports_Schema.Natural,
|
|
34923
|
+
output: exports_Schema.Natural,
|
|
34924
|
+
cacheRead: exports_Schema.Natural,
|
|
34925
|
+
cacheWrite: exports_Schema.Natural
|
|
34926
|
+
}));
|
|
34927
|
+
var unattributedModel = "unknown";
|
|
34928
|
+
var chatGptSignIn = "openai-codex";
|
|
34929
|
+
function piParser(file2) {
|
|
34930
|
+
let session = file2;
|
|
34931
|
+
let cwd = null;
|
|
34932
|
+
let sawHeader = false;
|
|
34933
|
+
let forked = null;
|
|
34934
|
+
return {
|
|
34935
|
+
parse(line, lineNumber) {
|
|
34936
|
+
const raw2 = exports_Option.getOrNull(decodeJson(line));
|
|
34937
|
+
if (raw2 === null)
|
|
34938
|
+
return malformed;
|
|
34939
|
+
const type3 = exports_Option.getOrNull(decodeKind(raw2))?.type;
|
|
34940
|
+
if (type3 === "session") {
|
|
34941
|
+
if (sawHeader)
|
|
34942
|
+
return empty14;
|
|
34943
|
+
const header = exports_Option.getOrNull(decodeHeader(raw2));
|
|
34944
|
+
if (header === null)
|
|
34945
|
+
return malformed;
|
|
34946
|
+
sawHeader = true;
|
|
34947
|
+
session = header.id ?? file2;
|
|
34948
|
+
cwd = header.cwd ?? null;
|
|
34949
|
+
forked = header.parentSession === undefined ? null : timestamp(header.timestamp);
|
|
34950
|
+
return empty14;
|
|
34951
|
+
}
|
|
34952
|
+
const wrapper = type3 === "message" ? exports_Option.getOrNull(decodeWrapper(raw2)) : { message: raw2 };
|
|
34953
|
+
const carrier = wrapper === null ? null : exports_Option.getOrNull(decodeCarrier(wrapper.message));
|
|
34954
|
+
if (wrapper === null || carrier === null)
|
|
34955
|
+
return type3 === "message" ? malformed : empty14;
|
|
34956
|
+
const assistant = type3 === "message" && carrier.role === "assistant";
|
|
34957
|
+
const attributed = assistant || type3 === "usage";
|
|
34958
|
+
const counted = attributed || type3 === "message" && carrier.role === "toolResult" || type3 === "compaction" || type3 === "branch_summary";
|
|
34959
|
+
const usage = carrier.usage;
|
|
34960
|
+
if (usage === undefined || usage === null)
|
|
34961
|
+
return attributed ? skipped : empty14;
|
|
34962
|
+
if (!counted)
|
|
34963
|
+
return skipped;
|
|
34964
|
+
const stamp = exports_Option.getOrNull(decodeStamp(raw2));
|
|
34965
|
+
const names = exports_Option.getOrNull(decodeNames(wrapper.message));
|
|
34966
|
+
const count2 = exports_Option.getOrNull(decodeCounts(usage));
|
|
34967
|
+
const ms = timestamp(stamp?.timestamp);
|
|
34968
|
+
if (stamp === null || names === null || count2 === null || ms === null)
|
|
34969
|
+
return skipped;
|
|
34970
|
+
const model = attributed ? names.responseModel ?? names.model : undefined;
|
|
34971
|
+
const record3 = {
|
|
34972
|
+
provider: "pi",
|
|
34973
|
+
id: stamp.id === undefined ? `${file2}:${lineNumber}` : `${stamp.id}:${stamp.timestamp}`,
|
|
34974
|
+
session,
|
|
34975
|
+
timestamp: ms,
|
|
34976
|
+
model: model ?? unattributedModel,
|
|
34977
|
+
cwd,
|
|
34978
|
+
repository: null,
|
|
34979
|
+
tokens: count2
|
|
34980
|
+
};
|
|
34981
|
+
const copied = forked !== null && ms < forked;
|
|
34982
|
+
return {
|
|
34983
|
+
...empty14,
|
|
34984
|
+
records: copied ? [] : [record3],
|
|
34985
|
+
inherited: copied ? [record3] : [],
|
|
34986
|
+
hints: attributed && names.provider === chatGptSignIn && totalTokens(count2) > 0 ? [{ timestamp: ms, plan: names.provider }] : [],
|
|
34987
|
+
warnings: [
|
|
34988
|
+
...sawHeader ? [] : ["Pi session header is missing; attribution uses the file identity."],
|
|
34989
|
+
...stamp.id === undefined ? ["Some Pi entries lack stable IDs; forked sessions may overlap."] : [],
|
|
34990
|
+
...model === undefined ? [
|
|
34991
|
+
"Pi tool and summary usage names no model; these tokens remain unpriced unless an explicit rate is supplied."
|
|
34992
|
+
] : []
|
|
34993
|
+
]
|
|
34994
|
+
};
|
|
34995
|
+
}
|
|
34996
|
+
};
|
|
34997
|
+
}
|
|
34998
|
+
|
|
34901
34999
|
// packages/core/src/sync.ts
|
|
34902
35000
|
import { createHash as createHash2 } from "node:crypto";
|
|
34903
35001
|
var hour = 3600000;
|
|
@@ -35091,6 +35189,7 @@ class Ledger extends exports_Context.Service()("token-ledger/Ledger") {
|
|
|
35091
35189
|
const visitedFiles = new Set;
|
|
35092
35190
|
const settledFiles = new Set;
|
|
35093
35191
|
const coverage = [];
|
|
35192
|
+
const inherited = [];
|
|
35094
35193
|
for (const source of request3.sources) {
|
|
35095
35194
|
let files = 0;
|
|
35096
35195
|
let filesBeforeWindow = 0;
|
|
@@ -35101,6 +35200,15 @@ class Ledger extends exports_Context.Service()("token-ledger/Ledger") {
|
|
|
35101
35200
|
let missingRoot = false;
|
|
35102
35201
|
const warnings = new Set;
|
|
35103
35202
|
const copilot = source.provider === "copilot" ? copilotParser(source.path) : undefined;
|
|
35203
|
+
const place = exports_Effect.fn("Ledger.placeRecord")(function* (record3, slot) {
|
|
35204
|
+
const id2 = `${record3.provider}:${record3.id}`;
|
|
35205
|
+
if (seen.has(id2)) {
|
|
35206
|
+
duplicates++;
|
|
35207
|
+
return;
|
|
35208
|
+
}
|
|
35209
|
+
seen.add(id2);
|
|
35210
|
+
collect2(record3, yield* resolveProject(record3, source.project), slot);
|
|
35211
|
+
});
|
|
35104
35212
|
const accept2 = exports_Effect.fn("Ledger.acceptRecords")(function* (result6) {
|
|
35105
35213
|
malformedLines += result6.malformed;
|
|
35106
35214
|
skippedRecords += result6.skipped;
|
|
@@ -35112,15 +35220,13 @@ class Ledger extends exports_Context.Service()("token-ledger/Ledger") {
|
|
|
35112
35220
|
}
|
|
35113
35221
|
for (const record3 of result6.records) {
|
|
35114
35222
|
const slot = locate(record3.timestamp);
|
|
35115
|
-
if (slot
|
|
35116
|
-
|
|
35117
|
-
|
|
35118
|
-
|
|
35119
|
-
|
|
35120
|
-
|
|
35121
|
-
|
|
35122
|
-
seen.add(id2);
|
|
35123
|
-
collect2(record3, yield* resolveProject(record3, source.project), slot);
|
|
35223
|
+
if (slot !== undefined && totalTokens(record3.tokens) > 0)
|
|
35224
|
+
yield* place(record3, slot);
|
|
35225
|
+
}
|
|
35226
|
+
for (const record3 of result6.inherited) {
|
|
35227
|
+
const slot = locate(record3.timestamp);
|
|
35228
|
+
if (slot !== undefined && totalTokens(record3.tokens) > 0)
|
|
35229
|
+
inherited.push(place(record3, slot));
|
|
35124
35230
|
}
|
|
35125
35231
|
});
|
|
35126
35232
|
const scanFile = exports_Effect.fn("Ledger.scanFile")(function* (file2, info2) {
|
|
@@ -35137,7 +35243,7 @@ class Ledger extends exports_Context.Service()("token-ledger/Ledger") {
|
|
|
35137
35243
|
return;
|
|
35138
35244
|
}
|
|
35139
35245
|
visitedFiles.add(identity3);
|
|
35140
|
-
const parser = exports_Match.value(source.provider).pipe(exports_Match.when("codex", () => codexParser(canonical)), exports_Match.when("claude", () => claudeParser(canonical)), exports_Match.when("grok", () => grokParser(canonical)), exports_Match.when("copilot", () => copilot ?? copilotParser(canonical)), exports_Match.exhaustive);
|
|
35246
|
+
const parser = exports_Match.value(source.provider).pipe(exports_Match.when("codex", () => codexParser(canonical)), exports_Match.when("claude", () => claudeParser(canonical)), exports_Match.when("grok", () => grokParser(canonical)), exports_Match.when("copilot", () => copilot ?? copilotParser(canonical)), exports_Match.when("pi", () => piParser(canonical)), exports_Match.exhaustive);
|
|
35141
35247
|
let lineNumber = 0;
|
|
35142
35248
|
files++;
|
|
35143
35249
|
const lines = source.provider === "copilot" && canonical.endsWith(".db") ? exports_Stream.fromIterableEffect(copilotDatabaseLines(canonical)) : fs.stream(canonical).pipe(exports_Stream.decodeText, exports_Stream.splitLines);
|
|
@@ -35180,7 +35286,7 @@ class Ledger extends exports_Context.Service()("token-ledger/Ledger") {
|
|
|
35180
35286
|
if (copilot?.finish !== undefined)
|
|
35181
35287
|
yield* accept2(copilot.finish());
|
|
35182
35288
|
const status = missingRoot ? "missing" : failedFiles > 0 && files === 0 ? "failed" : failedFiles > 0 || malformedLines > 0 || skippedRecords > 0 ? "partial" : "ok";
|
|
35183
|
-
coverage.push({
|
|
35289
|
+
coverage.push(() => ({
|
|
35184
35290
|
provider: source.provider,
|
|
35185
35291
|
source: source.path,
|
|
35186
35292
|
status,
|
|
@@ -35191,9 +35297,11 @@ class Ledger extends exports_Context.Service()("token-ledger/Ledger") {
|
|
|
35191
35297
|
skippedRecords,
|
|
35192
35298
|
duplicates,
|
|
35193
35299
|
warnings: [...warnings]
|
|
35194
|
-
});
|
|
35300
|
+
}));
|
|
35195
35301
|
}
|
|
35196
|
-
|
|
35302
|
+
for (const copy4 of inherited)
|
|
35303
|
+
yield* copy4;
|
|
35304
|
+
return coverage.map((summarize) => summarize());
|
|
35197
35305
|
});
|
|
35198
35306
|
const report = exports_Effect.fn("Ledger.report")(function* (input) {
|
|
35199
35307
|
const request3 = yield* decode5(input);
|
|
@@ -42575,7 +42683,7 @@ var runWith2 = (command, config) => {
|
|
|
42575
42683
|
// packages/cli/package.json
|
|
42576
42684
|
var package_default = {
|
|
42577
42685
|
name: "@ponbac/token-ledger",
|
|
42578
|
-
version: "0.
|
|
42686
|
+
version: "0.4.0",
|
|
42579
42687
|
private: true,
|
|
42580
42688
|
type: "module",
|
|
42581
42689
|
bin: {
|
|
@@ -42586,6 +42694,7 @@ var package_default = {
|
|
|
42586
42694
|
"@token-ledger/core": "workspace:*",
|
|
42587
42695
|
"cli-table3": "^0.6.5",
|
|
42588
42696
|
effect: "4.0.0",
|
|
42697
|
+
"jsonc-parser": "^3.3.1",
|
|
42589
42698
|
"wrap-ansi": "^10.0.2"
|
|
42590
42699
|
},
|
|
42591
42700
|
description: "Local AI token usage and API-equivalent cost reports by project",
|
|
@@ -42603,1363 +42712,2866 @@ var package_default = {
|
|
|
42603
42712
|
url: "https://github.com/ponbac/token-ledger/issues"
|
|
42604
42713
|
}
|
|
42605
42714
|
};
|
|
42606
|
-
|
|
42607
|
-
|
|
42608
|
-
|
|
42609
|
-
|
|
42610
|
-
|
|
42611
|
-
|
|
42612
|
-
|
|
42613
|
-
|
|
42614
|
-
|
|
42615
|
-
|
|
42616
|
-
|
|
42617
|
-
|
|
42618
|
-
|
|
42619
|
-
|
|
42620
|
-
|
|
42621
|
-
|
|
42622
|
-
|
|
42623
|
-
|
|
42624
|
-
|
|
42715
|
+
// node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
42716
|
+
function createScanner(text2, ignoreTrivia = false) {
|
|
42717
|
+
const len = text2.length;
|
|
42718
|
+
let pos = 0, value5 = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
|
|
42719
|
+
function scanHexDigits(count2, exact) {
|
|
42720
|
+
let digits = 0;
|
|
42721
|
+
let value6 = 0;
|
|
42722
|
+
while (digits < count2 || !exact) {
|
|
42723
|
+
let ch = text2.charCodeAt(pos);
|
|
42724
|
+
if (ch >= 48 && ch <= 57) {
|
|
42725
|
+
value6 = value6 * 16 + ch - 48;
|
|
42726
|
+
} else if (ch >= 65 && ch <= 70) {
|
|
42727
|
+
value6 = value6 * 16 + ch - 65 + 10;
|
|
42728
|
+
} else if (ch >= 97 && ch <= 102) {
|
|
42729
|
+
value6 = value6 * 16 + ch - 97 + 10;
|
|
42730
|
+
} else {
|
|
42731
|
+
break;
|
|
42732
|
+
}
|
|
42733
|
+
pos++;
|
|
42734
|
+
digits++;
|
|
42735
|
+
}
|
|
42736
|
+
if (digits < count2) {
|
|
42737
|
+
value6 = -1;
|
|
42738
|
+
}
|
|
42739
|
+
return value6;
|
|
42625
42740
|
}
|
|
42626
|
-
|
|
42627
|
-
|
|
42741
|
+
function setPosition(newPosition) {
|
|
42742
|
+
pos = newPosition;
|
|
42743
|
+
value5 = "";
|
|
42744
|
+
tokenOffset = 0;
|
|
42745
|
+
token = 16;
|
|
42746
|
+
scanError = 0;
|
|
42628
42747
|
}
|
|
42629
|
-
|
|
42630
|
-
|
|
42631
|
-
|
|
42632
|
-
|
|
42633
|
-
var ambiguousMinimalCodePoint = 161;
|
|
42634
|
-
var ambiguousMaximumCodePoint = 1114109;
|
|
42635
|
-
var ambiguousRanges = [161, 161, 164, 164, 167, 168, 170, 170, 173, 174, 176, 180, 182, 186, 188, 191, 198, 198, 208, 208, 215, 216, 222, 225, 230, 230, 232, 234, 236, 237, 240, 240, 242, 243, 247, 250, 252, 252, 254, 254, 257, 257, 273, 273, 275, 275, 283, 283, 294, 295, 299, 299, 305, 307, 312, 312, 319, 322, 324, 324, 328, 331, 333, 333, 338, 339, 358, 359, 363, 363, 462, 462, 464, 464, 466, 466, 468, 468, 470, 470, 472, 472, 474, 474, 476, 476, 593, 593, 609, 609, 708, 708, 711, 711, 713, 715, 717, 717, 720, 720, 728, 731, 733, 733, 735, 735, 768, 879, 913, 929, 931, 937, 945, 961, 963, 969, 1025, 1025, 1040, 1103, 1105, 1105, 8208, 8208, 8211, 8214, 8216, 8217, 8220, 8221, 8224, 8226, 8228, 8231, 8240, 8240, 8242, 8243, 8245, 8245, 8251, 8251, 8254, 8254, 8308, 8308, 8319, 8319, 8321, 8324, 8364, 8364, 8451, 8451, 8453, 8453, 8457, 8457, 8467, 8467, 8470, 8470, 8481, 8482, 8486, 8486, 8491, 8491, 8531, 8532, 8539, 8542, 8544, 8555, 8560, 8569, 8585, 8585, 8592, 8601, 8632, 8633, 8658, 8658, 8660, 8660, 8679, 8679, 8704, 8704, 8706, 8707, 8711, 8712, 8715, 8715, 8719, 8719, 8721, 8721, 8725, 8725, 8730, 8730, 8733, 8736, 8739, 8739, 8741, 8741, 8743, 8748, 8750, 8750, 8756, 8759, 8764, 8765, 8776, 8776, 8780, 8780, 8786, 8786, 8800, 8801, 8804, 8807, 8810, 8811, 8814, 8815, 8834, 8835, 8838, 8839, 8853, 8853, 8857, 8857, 8869, 8869, 8895, 8895, 8978, 8978, 9312, 9449, 9451, 9547, 9552, 9587, 9600, 9615, 9618, 9621, 9632, 9633, 9635, 9641, 9650, 9651, 9654, 9655, 9660, 9661, 9664, 9665, 9670, 9672, 9675, 9675, 9678, 9681, 9698, 9701, 9711, 9711, 9733, 9734, 9737, 9737, 9742, 9743, 9756, 9756, 9758, 9758, 9792, 9792, 9794, 9794, 9824, 9825, 9827, 9829, 9831, 9834, 9836, 9837, 9839, 9839, 9886, 9887, 9919, 9919, 9926, 9933, 9935, 9939, 9941, 9953, 9955, 9955, 9960, 9961, 9963, 9969, 9972, 9972, 9974, 9977, 9979, 9980, 9982, 9983, 10045, 10045, 10102, 10111, 11094, 11097, 12872, 12879, 57344, 63743, 65024, 65039, 65533, 65533, 127232, 127242, 127248, 127277, 127280, 127337, 127344, 127373, 127375, 127376, 127387, 127404, 917760, 917999, 983040, 1048573, 1048576, 1114109];
|
|
42636
|
-
var fullwidthMinimalCodePoint = 12288;
|
|
42637
|
-
var fullwidthMaximumCodePoint = 65510;
|
|
42638
|
-
var fullwidthRanges = [12288, 12288, 65281, 65376, 65504, 65510];
|
|
42639
|
-
var wideMinimalCodePoint = 4352;
|
|
42640
|
-
var wideMaximumCodePoint = 262141;
|
|
42641
|
-
var wideRanges = [4352, 4447, 8986, 8987, 9001, 9002, 9193, 9196, 9200, 9200, 9203, 9203, 9725, 9726, 9748, 9749, 9776, 9783, 9800, 9811, 9855, 9855, 9866, 9871, 9875, 9875, 9889, 9889, 9898, 9899, 9917, 9918, 9924, 9925, 9934, 9934, 9940, 9940, 9962, 9962, 9970, 9971, 9973, 9973, 9978, 9978, 9981, 9981, 9989, 9989, 9994, 9995, 10024, 10024, 10060, 10060, 10062, 10062, 10067, 10069, 10071, 10071, 10133, 10135, 10160, 10160, 10175, 10175, 11035, 11036, 11088, 11088, 11093, 11093, 11904, 11929, 11931, 12019, 12032, 12245, 12272, 12287, 12289, 12350, 12353, 12438, 12441, 12543, 12549, 12591, 12593, 12686, 12688, 12773, 12783, 12830, 12832, 12871, 12880, 42124, 42128, 42182, 43360, 43388, 44032, 55203, 63744, 64255, 65040, 65049, 65072, 65106, 65108, 65126, 65128, 65131, 94176, 94180, 94192, 94198, 94208, 101594, 101631, 101664, 101760, 101874, 101888, 102801, 102816, 102866, 110576, 110579, 110581, 110587, 110589, 110590, 110592, 110888, 110898, 110898, 110928, 110930, 110933, 110933, 110948, 110952, 110960, 111355, 119552, 119638, 119648, 119670, 126980, 126980, 127183, 127183, 127374, 127374, 127377, 127386, 127406, 127406, 127488, 127490, 127504, 127547, 127552, 127560, 127568, 127569, 127584, 127589, 127744, 127776, 127789, 127797, 127799, 127868, 127870, 127891, 127904, 127946, 127951, 127955, 127968, 127984, 127988, 127988, 127992, 128062, 128064, 128064, 128066, 128252, 128255, 128317, 128331, 128334, 128336, 128359, 128378, 128378, 128405, 128406, 128420, 128420, 128507, 128591, 128640, 128709, 128716, 128716, 128720, 128722, 128725, 128729, 128732, 128735, 128747, 128748, 128756, 128764, 128986, 128986, 128992, 129003, 129008, 129008, 129292, 129338, 129340, 129349, 129351, 129535, 129648, 129660, 129664, 129734, 129736, 129736, 129740, 129757, 129759, 129771, 129775, 129786, 131072, 196605, 196608, 262141];
|
|
42642
|
-
|
|
42643
|
-
// node_modules/.bun/get-east-asian-width@1.7.0/node_modules/get-east-asian-width/utilities.js
|
|
42644
|
-
var isInRange = (ranges, codePoint) => {
|
|
42645
|
-
let low = 0;
|
|
42646
|
-
let high = Math.floor(ranges.length / 2) - 1;
|
|
42647
|
-
while (low <= high) {
|
|
42648
|
-
const mid = Math.floor((low + high) / 2);
|
|
42649
|
-
const i = mid * 2;
|
|
42650
|
-
if (codePoint < ranges[i]) {
|
|
42651
|
-
high = mid - 1;
|
|
42652
|
-
} else if (codePoint > ranges[i + 1]) {
|
|
42653
|
-
low = mid + 1;
|
|
42748
|
+
function scanNumber() {
|
|
42749
|
+
let start = pos;
|
|
42750
|
+
if (text2.charCodeAt(pos) === 48) {
|
|
42751
|
+
pos++;
|
|
42654
42752
|
} else {
|
|
42655
|
-
|
|
42753
|
+
pos++;
|
|
42754
|
+
while (pos < text2.length && isDigit(text2.charCodeAt(pos))) {
|
|
42755
|
+
pos++;
|
|
42756
|
+
}
|
|
42656
42757
|
}
|
|
42657
|
-
|
|
42658
|
-
|
|
42659
|
-
|
|
42660
|
-
|
|
42661
|
-
|
|
42662
|
-
|
|
42663
|
-
|
|
42664
|
-
|
|
42665
|
-
|
|
42666
|
-
|
|
42667
|
-
|
|
42668
|
-
const start = ranges[index2];
|
|
42669
|
-
const end3 = ranges[index2 + 1];
|
|
42670
|
-
if (commonCjkCodePoint >= start && commonCjkCodePoint <= end3) {
|
|
42671
|
-
return [start, end3];
|
|
42758
|
+
if (pos < text2.length && text2.charCodeAt(pos) === 46) {
|
|
42759
|
+
pos++;
|
|
42760
|
+
if (pos < text2.length && isDigit(text2.charCodeAt(pos))) {
|
|
42761
|
+
pos++;
|
|
42762
|
+
while (pos < text2.length && isDigit(text2.charCodeAt(pos))) {
|
|
42763
|
+
pos++;
|
|
42764
|
+
}
|
|
42765
|
+
} else {
|
|
42766
|
+
scanError = 3;
|
|
42767
|
+
return text2.substring(start, pos);
|
|
42768
|
+
}
|
|
42672
42769
|
}
|
|
42673
|
-
|
|
42674
|
-
|
|
42675
|
-
|
|
42770
|
+
let end3 = pos;
|
|
42771
|
+
if (pos < text2.length && (text2.charCodeAt(pos) === 69 || text2.charCodeAt(pos) === 101)) {
|
|
42772
|
+
pos++;
|
|
42773
|
+
if (pos < text2.length && text2.charCodeAt(pos) === 43 || text2.charCodeAt(pos) === 45) {
|
|
42774
|
+
pos++;
|
|
42775
|
+
}
|
|
42776
|
+
if (pos < text2.length && isDigit(text2.charCodeAt(pos))) {
|
|
42777
|
+
pos++;
|
|
42778
|
+
while (pos < text2.length && isDigit(text2.charCodeAt(pos))) {
|
|
42779
|
+
pos++;
|
|
42780
|
+
}
|
|
42781
|
+
end3 = pos;
|
|
42782
|
+
} else {
|
|
42783
|
+
scanError = 3;
|
|
42784
|
+
}
|
|
42676
42785
|
}
|
|
42786
|
+
return text2.substring(start, end3);
|
|
42677
42787
|
}
|
|
42678
|
-
|
|
42679
|
-
|
|
42680
|
-
|
|
42681
|
-
|
|
42682
|
-
|
|
42788
|
+
function scanString() {
|
|
42789
|
+
let result6 = "", start = pos;
|
|
42790
|
+
while (true) {
|
|
42791
|
+
if (pos >= len) {
|
|
42792
|
+
result6 += text2.substring(start, pos);
|
|
42793
|
+
scanError = 2;
|
|
42794
|
+
break;
|
|
42795
|
+
}
|
|
42796
|
+
const ch = text2.charCodeAt(pos);
|
|
42797
|
+
if (ch === 34) {
|
|
42798
|
+
result6 += text2.substring(start, pos);
|
|
42799
|
+
pos++;
|
|
42800
|
+
break;
|
|
42801
|
+
}
|
|
42802
|
+
if (ch === 92) {
|
|
42803
|
+
result6 += text2.substring(start, pos);
|
|
42804
|
+
pos++;
|
|
42805
|
+
if (pos >= len) {
|
|
42806
|
+
scanError = 2;
|
|
42807
|
+
break;
|
|
42808
|
+
}
|
|
42809
|
+
const ch2 = text2.charCodeAt(pos++);
|
|
42810
|
+
switch (ch2) {
|
|
42811
|
+
case 34:
|
|
42812
|
+
result6 += '"';
|
|
42813
|
+
break;
|
|
42814
|
+
case 92:
|
|
42815
|
+
result6 += "\\";
|
|
42816
|
+
break;
|
|
42817
|
+
case 47:
|
|
42818
|
+
result6 += "/";
|
|
42819
|
+
break;
|
|
42820
|
+
case 98:
|
|
42821
|
+
result6 += "\b";
|
|
42822
|
+
break;
|
|
42823
|
+
case 102:
|
|
42824
|
+
result6 += "\f";
|
|
42825
|
+
break;
|
|
42826
|
+
case 110:
|
|
42827
|
+
result6 += `
|
|
42828
|
+
`;
|
|
42829
|
+
break;
|
|
42830
|
+
case 114:
|
|
42831
|
+
result6 += "\r";
|
|
42832
|
+
break;
|
|
42833
|
+
case 116:
|
|
42834
|
+
result6 += "\t";
|
|
42835
|
+
break;
|
|
42836
|
+
case 117:
|
|
42837
|
+
const ch3 = scanHexDigits(4, true);
|
|
42838
|
+
if (ch3 >= 0) {
|
|
42839
|
+
result6 += String.fromCharCode(ch3);
|
|
42840
|
+
} else {
|
|
42841
|
+
scanError = 4;
|
|
42842
|
+
}
|
|
42843
|
+
break;
|
|
42844
|
+
default:
|
|
42845
|
+
scanError = 5;
|
|
42846
|
+
}
|
|
42847
|
+
start = pos;
|
|
42848
|
+
continue;
|
|
42849
|
+
}
|
|
42850
|
+
if (ch >= 0 && ch <= 31) {
|
|
42851
|
+
if (isLineBreak3(ch)) {
|
|
42852
|
+
result6 += text2.substring(start, pos);
|
|
42853
|
+
scanError = 2;
|
|
42854
|
+
break;
|
|
42855
|
+
} else {
|
|
42856
|
+
scanError = 6;
|
|
42857
|
+
}
|
|
42858
|
+
}
|
|
42859
|
+
pos++;
|
|
42860
|
+
}
|
|
42861
|
+
return result6;
|
|
42683
42862
|
}
|
|
42684
|
-
|
|
42685
|
-
|
|
42686
|
-
|
|
42687
|
-
|
|
42688
|
-
|
|
42863
|
+
function scanNext() {
|
|
42864
|
+
value5 = "";
|
|
42865
|
+
scanError = 0;
|
|
42866
|
+
tokenOffset = pos;
|
|
42867
|
+
lineStartOffset = lineNumber;
|
|
42868
|
+
prevTokenLineStartOffset = tokenLineStartOffset;
|
|
42869
|
+
if (pos >= len) {
|
|
42870
|
+
tokenOffset = len;
|
|
42871
|
+
return token = 17;
|
|
42872
|
+
}
|
|
42873
|
+
let code = text2.charCodeAt(pos);
|
|
42874
|
+
if (isWhiteSpace(code)) {
|
|
42875
|
+
do {
|
|
42876
|
+
pos++;
|
|
42877
|
+
value5 += String.fromCharCode(code);
|
|
42878
|
+
code = text2.charCodeAt(pos);
|
|
42879
|
+
} while (isWhiteSpace(code));
|
|
42880
|
+
return token = 15;
|
|
42881
|
+
}
|
|
42882
|
+
if (isLineBreak3(code)) {
|
|
42883
|
+
pos++;
|
|
42884
|
+
value5 += String.fromCharCode(code);
|
|
42885
|
+
if (code === 13 && text2.charCodeAt(pos) === 10) {
|
|
42886
|
+
pos++;
|
|
42887
|
+
value5 += `
|
|
42888
|
+
`;
|
|
42889
|
+
}
|
|
42890
|
+
lineNumber++;
|
|
42891
|
+
tokenLineStartOffset = pos;
|
|
42892
|
+
return token = 14;
|
|
42893
|
+
}
|
|
42894
|
+
switch (code) {
|
|
42895
|
+
case 123:
|
|
42896
|
+
pos++;
|
|
42897
|
+
return token = 1;
|
|
42898
|
+
case 125:
|
|
42899
|
+
pos++;
|
|
42900
|
+
return token = 2;
|
|
42901
|
+
case 91:
|
|
42902
|
+
pos++;
|
|
42903
|
+
return token = 3;
|
|
42904
|
+
case 93:
|
|
42905
|
+
pos++;
|
|
42906
|
+
return token = 4;
|
|
42907
|
+
case 58:
|
|
42908
|
+
pos++;
|
|
42909
|
+
return token = 6;
|
|
42910
|
+
case 44:
|
|
42911
|
+
pos++;
|
|
42912
|
+
return token = 5;
|
|
42913
|
+
case 34:
|
|
42914
|
+
pos++;
|
|
42915
|
+
value5 = scanString();
|
|
42916
|
+
return token = 10;
|
|
42917
|
+
case 47:
|
|
42918
|
+
const start = pos - 1;
|
|
42919
|
+
if (text2.charCodeAt(pos + 1) === 47) {
|
|
42920
|
+
pos += 2;
|
|
42921
|
+
while (pos < len) {
|
|
42922
|
+
if (isLineBreak3(text2.charCodeAt(pos))) {
|
|
42923
|
+
break;
|
|
42924
|
+
}
|
|
42925
|
+
pos++;
|
|
42926
|
+
}
|
|
42927
|
+
value5 = text2.substring(start, pos);
|
|
42928
|
+
return token = 12;
|
|
42929
|
+
}
|
|
42930
|
+
if (text2.charCodeAt(pos + 1) === 42) {
|
|
42931
|
+
pos += 2;
|
|
42932
|
+
const safeLength = len - 1;
|
|
42933
|
+
let commentClosed = false;
|
|
42934
|
+
while (pos < safeLength) {
|
|
42935
|
+
const ch = text2.charCodeAt(pos);
|
|
42936
|
+
if (ch === 42 && text2.charCodeAt(pos + 1) === 47) {
|
|
42937
|
+
pos += 2;
|
|
42938
|
+
commentClosed = true;
|
|
42939
|
+
break;
|
|
42940
|
+
}
|
|
42941
|
+
pos++;
|
|
42942
|
+
if (isLineBreak3(ch)) {
|
|
42943
|
+
if (ch === 13 && text2.charCodeAt(pos) === 10) {
|
|
42944
|
+
pos++;
|
|
42945
|
+
}
|
|
42946
|
+
lineNumber++;
|
|
42947
|
+
tokenLineStartOffset = pos;
|
|
42948
|
+
}
|
|
42949
|
+
}
|
|
42950
|
+
if (!commentClosed) {
|
|
42951
|
+
pos++;
|
|
42952
|
+
scanError = 1;
|
|
42953
|
+
}
|
|
42954
|
+
value5 = text2.substring(start, pos);
|
|
42955
|
+
return token = 13;
|
|
42956
|
+
}
|
|
42957
|
+
value5 += String.fromCharCode(code);
|
|
42958
|
+
pos++;
|
|
42959
|
+
return token = 16;
|
|
42960
|
+
case 45:
|
|
42961
|
+
value5 += String.fromCharCode(code);
|
|
42962
|
+
pos++;
|
|
42963
|
+
if (pos === len || !isDigit(text2.charCodeAt(pos))) {
|
|
42964
|
+
return token = 16;
|
|
42965
|
+
}
|
|
42966
|
+
case 48:
|
|
42967
|
+
case 49:
|
|
42968
|
+
case 50:
|
|
42969
|
+
case 51:
|
|
42970
|
+
case 52:
|
|
42971
|
+
case 53:
|
|
42972
|
+
case 54:
|
|
42973
|
+
case 55:
|
|
42974
|
+
case 56:
|
|
42975
|
+
case 57:
|
|
42976
|
+
value5 += scanNumber();
|
|
42977
|
+
return token = 11;
|
|
42978
|
+
default:
|
|
42979
|
+
while (pos < len && isUnknownContentCharacter(code)) {
|
|
42980
|
+
pos++;
|
|
42981
|
+
code = text2.charCodeAt(pos);
|
|
42982
|
+
}
|
|
42983
|
+
if (tokenOffset !== pos) {
|
|
42984
|
+
value5 = text2.substring(tokenOffset, pos);
|
|
42985
|
+
switch (value5) {
|
|
42986
|
+
case "true":
|
|
42987
|
+
return token = 8;
|
|
42988
|
+
case "false":
|
|
42989
|
+
return token = 9;
|
|
42990
|
+
case "null":
|
|
42991
|
+
return token = 7;
|
|
42992
|
+
}
|
|
42993
|
+
return token = 16;
|
|
42994
|
+
}
|
|
42995
|
+
value5 += String.fromCharCode(code);
|
|
42996
|
+
pos++;
|
|
42997
|
+
return token = 16;
|
|
42998
|
+
}
|
|
42689
42999
|
}
|
|
42690
|
-
|
|
42691
|
-
|
|
42692
|
-
|
|
42693
|
-
|
|
43000
|
+
function isUnknownContentCharacter(code) {
|
|
43001
|
+
if (isWhiteSpace(code) || isLineBreak3(code)) {
|
|
43002
|
+
return false;
|
|
43003
|
+
}
|
|
43004
|
+
switch (code) {
|
|
43005
|
+
case 125:
|
|
43006
|
+
case 93:
|
|
43007
|
+
case 123:
|
|
43008
|
+
case 91:
|
|
43009
|
+
case 34:
|
|
43010
|
+
case 58:
|
|
43011
|
+
case 44:
|
|
43012
|
+
case 47:
|
|
43013
|
+
return false;
|
|
43014
|
+
}
|
|
42694
43015
|
return true;
|
|
42695
43016
|
}
|
|
42696
|
-
|
|
42697
|
-
|
|
43017
|
+
function scanNextNonTrivia() {
|
|
43018
|
+
let result6;
|
|
43019
|
+
do {
|
|
43020
|
+
result6 = scanNext();
|
|
43021
|
+
} while (result6 >= 12 && result6 <= 15);
|
|
43022
|
+
return result6;
|
|
43023
|
+
}
|
|
43024
|
+
return {
|
|
43025
|
+
setPosition,
|
|
43026
|
+
getPosition: () => pos,
|
|
43027
|
+
scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
|
|
43028
|
+
getToken: () => token,
|
|
43029
|
+
getTokenValue: () => value5,
|
|
43030
|
+
getTokenOffset: () => tokenOffset,
|
|
43031
|
+
getTokenLength: () => pos - tokenOffset,
|
|
43032
|
+
getTokenStartLine: () => lineStartOffset,
|
|
43033
|
+
getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
|
|
43034
|
+
getTokenError: () => scanError
|
|
43035
|
+
};
|
|
43036
|
+
}
|
|
43037
|
+
function isWhiteSpace(ch) {
|
|
43038
|
+
return ch === 32 || ch === 9;
|
|
43039
|
+
}
|
|
43040
|
+
function isLineBreak3(ch) {
|
|
43041
|
+
return ch === 10 || ch === 13;
|
|
43042
|
+
}
|
|
43043
|
+
function isDigit(ch) {
|
|
43044
|
+
return ch >= 48 && ch <= 57;
|
|
43045
|
+
}
|
|
43046
|
+
var CharacterCodes;
|
|
43047
|
+
(function(CharacterCodes2) {
|
|
43048
|
+
CharacterCodes2[CharacterCodes2["lineFeed"] = 10] = "lineFeed";
|
|
43049
|
+
CharacterCodes2[CharacterCodes2["carriageReturn"] = 13] = "carriageReturn";
|
|
43050
|
+
CharacterCodes2[CharacterCodes2["space"] = 32] = "space";
|
|
43051
|
+
CharacterCodes2[CharacterCodes2["_0"] = 48] = "_0";
|
|
43052
|
+
CharacterCodes2[CharacterCodes2["_1"] = 49] = "_1";
|
|
43053
|
+
CharacterCodes2[CharacterCodes2["_2"] = 50] = "_2";
|
|
43054
|
+
CharacterCodes2[CharacterCodes2["_3"] = 51] = "_3";
|
|
43055
|
+
CharacterCodes2[CharacterCodes2["_4"] = 52] = "_4";
|
|
43056
|
+
CharacterCodes2[CharacterCodes2["_5"] = 53] = "_5";
|
|
43057
|
+
CharacterCodes2[CharacterCodes2["_6"] = 54] = "_6";
|
|
43058
|
+
CharacterCodes2[CharacterCodes2["_7"] = 55] = "_7";
|
|
43059
|
+
CharacterCodes2[CharacterCodes2["_8"] = 56] = "_8";
|
|
43060
|
+
CharacterCodes2[CharacterCodes2["_9"] = 57] = "_9";
|
|
43061
|
+
CharacterCodes2[CharacterCodes2["a"] = 97] = "a";
|
|
43062
|
+
CharacterCodes2[CharacterCodes2["b"] = 98] = "b";
|
|
43063
|
+
CharacterCodes2[CharacterCodes2["c"] = 99] = "c";
|
|
43064
|
+
CharacterCodes2[CharacterCodes2["d"] = 100] = "d";
|
|
43065
|
+
CharacterCodes2[CharacterCodes2["e"] = 101] = "e";
|
|
43066
|
+
CharacterCodes2[CharacterCodes2["f"] = 102] = "f";
|
|
43067
|
+
CharacterCodes2[CharacterCodes2["g"] = 103] = "g";
|
|
43068
|
+
CharacterCodes2[CharacterCodes2["h"] = 104] = "h";
|
|
43069
|
+
CharacterCodes2[CharacterCodes2["i"] = 105] = "i";
|
|
43070
|
+
CharacterCodes2[CharacterCodes2["j"] = 106] = "j";
|
|
43071
|
+
CharacterCodes2[CharacterCodes2["k"] = 107] = "k";
|
|
43072
|
+
CharacterCodes2[CharacterCodes2["l"] = 108] = "l";
|
|
43073
|
+
CharacterCodes2[CharacterCodes2["m"] = 109] = "m";
|
|
43074
|
+
CharacterCodes2[CharacterCodes2["n"] = 110] = "n";
|
|
43075
|
+
CharacterCodes2[CharacterCodes2["o"] = 111] = "o";
|
|
43076
|
+
CharacterCodes2[CharacterCodes2["p"] = 112] = "p";
|
|
43077
|
+
CharacterCodes2[CharacterCodes2["q"] = 113] = "q";
|
|
43078
|
+
CharacterCodes2[CharacterCodes2["r"] = 114] = "r";
|
|
43079
|
+
CharacterCodes2[CharacterCodes2["s"] = 115] = "s";
|
|
43080
|
+
CharacterCodes2[CharacterCodes2["t"] = 116] = "t";
|
|
43081
|
+
CharacterCodes2[CharacterCodes2["u"] = 117] = "u";
|
|
43082
|
+
CharacterCodes2[CharacterCodes2["v"] = 118] = "v";
|
|
43083
|
+
CharacterCodes2[CharacterCodes2["w"] = 119] = "w";
|
|
43084
|
+
CharacterCodes2[CharacterCodes2["x"] = 120] = "x";
|
|
43085
|
+
CharacterCodes2[CharacterCodes2["y"] = 121] = "y";
|
|
43086
|
+
CharacterCodes2[CharacterCodes2["z"] = 122] = "z";
|
|
43087
|
+
CharacterCodes2[CharacterCodes2["A"] = 65] = "A";
|
|
43088
|
+
CharacterCodes2[CharacterCodes2["B"] = 66] = "B";
|
|
43089
|
+
CharacterCodes2[CharacterCodes2["C"] = 67] = "C";
|
|
43090
|
+
CharacterCodes2[CharacterCodes2["D"] = 68] = "D";
|
|
43091
|
+
CharacterCodes2[CharacterCodes2["E"] = 69] = "E";
|
|
43092
|
+
CharacterCodes2[CharacterCodes2["F"] = 70] = "F";
|
|
43093
|
+
CharacterCodes2[CharacterCodes2["G"] = 71] = "G";
|
|
43094
|
+
CharacterCodes2[CharacterCodes2["H"] = 72] = "H";
|
|
43095
|
+
CharacterCodes2[CharacterCodes2["I"] = 73] = "I";
|
|
43096
|
+
CharacterCodes2[CharacterCodes2["J"] = 74] = "J";
|
|
43097
|
+
CharacterCodes2[CharacterCodes2["K"] = 75] = "K";
|
|
43098
|
+
CharacterCodes2[CharacterCodes2["L"] = 76] = "L";
|
|
43099
|
+
CharacterCodes2[CharacterCodes2["M"] = 77] = "M";
|
|
43100
|
+
CharacterCodes2[CharacterCodes2["N"] = 78] = "N";
|
|
43101
|
+
CharacterCodes2[CharacterCodes2["O"] = 79] = "O";
|
|
43102
|
+
CharacterCodes2[CharacterCodes2["P"] = 80] = "P";
|
|
43103
|
+
CharacterCodes2[CharacterCodes2["Q"] = 81] = "Q";
|
|
43104
|
+
CharacterCodes2[CharacterCodes2["R"] = 82] = "R";
|
|
43105
|
+
CharacterCodes2[CharacterCodes2["S"] = 83] = "S";
|
|
43106
|
+
CharacterCodes2[CharacterCodes2["T"] = 84] = "T";
|
|
43107
|
+
CharacterCodes2[CharacterCodes2["U"] = 85] = "U";
|
|
43108
|
+
CharacterCodes2[CharacterCodes2["V"] = 86] = "V";
|
|
43109
|
+
CharacterCodes2[CharacterCodes2["W"] = 87] = "W";
|
|
43110
|
+
CharacterCodes2[CharacterCodes2["X"] = 88] = "X";
|
|
43111
|
+
CharacterCodes2[CharacterCodes2["Y"] = 89] = "Y";
|
|
43112
|
+
CharacterCodes2[CharacterCodes2["Z"] = 90] = "Z";
|
|
43113
|
+
CharacterCodes2[CharacterCodes2["asterisk"] = 42] = "asterisk";
|
|
43114
|
+
CharacterCodes2[CharacterCodes2["backslash"] = 92] = "backslash";
|
|
43115
|
+
CharacterCodes2[CharacterCodes2["closeBrace"] = 125] = "closeBrace";
|
|
43116
|
+
CharacterCodes2[CharacterCodes2["closeBracket"] = 93] = "closeBracket";
|
|
43117
|
+
CharacterCodes2[CharacterCodes2["colon"] = 58] = "colon";
|
|
43118
|
+
CharacterCodes2[CharacterCodes2["comma"] = 44] = "comma";
|
|
43119
|
+
CharacterCodes2[CharacterCodes2["dot"] = 46] = "dot";
|
|
43120
|
+
CharacterCodes2[CharacterCodes2["doubleQuote"] = 34] = "doubleQuote";
|
|
43121
|
+
CharacterCodes2[CharacterCodes2["minus"] = 45] = "minus";
|
|
43122
|
+
CharacterCodes2[CharacterCodes2["openBrace"] = 123] = "openBrace";
|
|
43123
|
+
CharacterCodes2[CharacterCodes2["openBracket"] = 91] = "openBracket";
|
|
43124
|
+
CharacterCodes2[CharacterCodes2["plus"] = 43] = "plus";
|
|
43125
|
+
CharacterCodes2[CharacterCodes2["slash"] = 47] = "slash";
|
|
43126
|
+
CharacterCodes2[CharacterCodes2["formFeed"] = 12] = "formFeed";
|
|
43127
|
+
CharacterCodes2[CharacterCodes2["tab"] = 9] = "tab";
|
|
43128
|
+
})(CharacterCodes || (CharacterCodes = {}));
|
|
43129
|
+
|
|
43130
|
+
// node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/string-intern.js
|
|
43131
|
+
var cachedSpaces = new Array(20).fill(0).map((_, index2) => {
|
|
43132
|
+
return " ".repeat(index2);
|
|
43133
|
+
});
|
|
43134
|
+
var maxCachedValues = 200;
|
|
43135
|
+
var cachedBreakLinesWithSpaces = {
|
|
43136
|
+
" ": {
|
|
43137
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index2) => {
|
|
43138
|
+
return `
|
|
43139
|
+
` + " ".repeat(index2);
|
|
43140
|
+
}),
|
|
43141
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index2) => {
|
|
43142
|
+
return "\r" + " ".repeat(index2);
|
|
43143
|
+
}),
|
|
43144
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index2) => {
|
|
43145
|
+
return `\r
|
|
43146
|
+
` + " ".repeat(index2);
|
|
43147
|
+
})
|
|
43148
|
+
},
|
|
43149
|
+
"\t": {
|
|
43150
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index2) => {
|
|
43151
|
+
return `
|
|
43152
|
+
` + "\t".repeat(index2);
|
|
43153
|
+
}),
|
|
43154
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index2) => {
|
|
43155
|
+
return "\r" + "\t".repeat(index2);
|
|
43156
|
+
}),
|
|
43157
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index2) => {
|
|
43158
|
+
return `\r
|
|
43159
|
+
` + "\t".repeat(index2);
|
|
43160
|
+
})
|
|
42698
43161
|
}
|
|
42699
|
-
return isInRange(wideRanges, codePoint);
|
|
42700
43162
|
};
|
|
42701
43163
|
|
|
42702
|
-
// node_modules/.bun/
|
|
42703
|
-
|
|
42704
|
-
|
|
42705
|
-
|
|
43164
|
+
// node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/parser.js
|
|
43165
|
+
var ParseOptions;
|
|
43166
|
+
(function(ParseOptions2) {
|
|
43167
|
+
ParseOptions2.DEFAULT = {
|
|
43168
|
+
allowTrailingComma: false
|
|
43169
|
+
};
|
|
43170
|
+
})(ParseOptions || (ParseOptions = {}));
|
|
43171
|
+
function parseTree(text2, errors = [], options3 = ParseOptions.DEFAULT) {
|
|
43172
|
+
let currentParent = { type: "array", offset: -1, length: -1, children: [], parent: undefined };
|
|
43173
|
+
function ensurePropertyComplete(endOffset) {
|
|
43174
|
+
if (currentParent.type === "property") {
|
|
43175
|
+
currentParent.length = endOffset - currentParent.offset;
|
|
43176
|
+
currentParent = currentParent.parent;
|
|
43177
|
+
}
|
|
43178
|
+
}
|
|
43179
|
+
function onValue(valueNode) {
|
|
43180
|
+
currentParent.children.push(valueNode);
|
|
43181
|
+
return valueNode;
|
|
43182
|
+
}
|
|
43183
|
+
const visitor = {
|
|
43184
|
+
onObjectBegin: (offset) => {
|
|
43185
|
+
currentParent = onValue({ type: "object", offset, length: -1, parent: currentParent, children: [] });
|
|
43186
|
+
},
|
|
43187
|
+
onObjectProperty: (name, offset, length) => {
|
|
43188
|
+
currentParent = onValue({ type: "property", offset, length: -1, parent: currentParent, children: [] });
|
|
43189
|
+
currentParent.children.push({ type: "string", value: name, offset, length, parent: currentParent });
|
|
43190
|
+
},
|
|
43191
|
+
onObjectEnd: (offset, length) => {
|
|
43192
|
+
ensurePropertyComplete(offset + length);
|
|
43193
|
+
currentParent.length = offset + length - currentParent.offset;
|
|
43194
|
+
currentParent = currentParent.parent;
|
|
43195
|
+
ensurePropertyComplete(offset + length);
|
|
43196
|
+
},
|
|
43197
|
+
onArrayBegin: (offset, length) => {
|
|
43198
|
+
currentParent = onValue({ type: "array", offset, length: -1, parent: currentParent, children: [] });
|
|
43199
|
+
},
|
|
43200
|
+
onArrayEnd: (offset, length) => {
|
|
43201
|
+
currentParent.length = offset + length - currentParent.offset;
|
|
43202
|
+
currentParent = currentParent.parent;
|
|
43203
|
+
ensurePropertyComplete(offset + length);
|
|
43204
|
+
},
|
|
43205
|
+
onLiteralValue: (value5, offset, length) => {
|
|
43206
|
+
onValue({ type: getNodeType(value5), offset, length, parent: currentParent, value: value5 });
|
|
43207
|
+
ensurePropertyComplete(offset + length);
|
|
43208
|
+
},
|
|
43209
|
+
onSeparator: (sep, offset, length) => {
|
|
43210
|
+
if (currentParent.type === "property") {
|
|
43211
|
+
if (sep === ":") {
|
|
43212
|
+
currentParent.colonOffset = offset;
|
|
43213
|
+
} else if (sep === ",") {
|
|
43214
|
+
ensurePropertyComplete(offset);
|
|
43215
|
+
}
|
|
43216
|
+
}
|
|
43217
|
+
},
|
|
43218
|
+
onError: (error2, offset, length) => {
|
|
43219
|
+
errors.push({ error: error2, offset, length });
|
|
43220
|
+
}
|
|
43221
|
+
};
|
|
43222
|
+
visit(text2, visitor, options3);
|
|
43223
|
+
const result6 = currentParent.children[0];
|
|
43224
|
+
if (result6) {
|
|
43225
|
+
delete result6.parent;
|
|
42706
43226
|
}
|
|
43227
|
+
return result6;
|
|
42707
43228
|
}
|
|
42708
|
-
function
|
|
42709
|
-
|
|
42710
|
-
|
|
42711
|
-
|
|
43229
|
+
function getNodeValue(node) {
|
|
43230
|
+
switch (node.type) {
|
|
43231
|
+
case "array":
|
|
43232
|
+
return node.children.map(getNodeValue);
|
|
43233
|
+
case "object":
|
|
43234
|
+
const obj = Object.create(null);
|
|
43235
|
+
for (let prop of node.children) {
|
|
43236
|
+
const valueNode = prop.children[1];
|
|
43237
|
+
if (valueNode) {
|
|
43238
|
+
obj[prop.children[0].value] = getNodeValue(valueNode);
|
|
43239
|
+
}
|
|
43240
|
+
}
|
|
43241
|
+
return obj;
|
|
43242
|
+
case "null":
|
|
43243
|
+
case "string":
|
|
43244
|
+
case "number":
|
|
43245
|
+
case "boolean":
|
|
43246
|
+
return node.value;
|
|
43247
|
+
default:
|
|
43248
|
+
return;
|
|
42712
43249
|
}
|
|
42713
|
-
return 1;
|
|
42714
43250
|
}
|
|
42715
|
-
|
|
42716
|
-
|
|
42717
|
-
|
|
42718
|
-
|
|
42719
|
-
|
|
42720
|
-
|
|
42721
|
-
var rgiEmojiRegex = /^\p{RGI_Emoji}$/v;
|
|
42722
|
-
var unqualifiedKeycapRegex = /^[\d#*]\u20E3$/;
|
|
42723
|
-
var extendedPictographicRegex = /\p{Extended_Pictographic}/gu;
|
|
42724
|
-
function isDoubleWidthNonRgiEmojiSequence(segment) {
|
|
42725
|
-
if (segment.length > 50) {
|
|
42726
|
-
return false;
|
|
43251
|
+
function visit(text2, visitor, options3 = ParseOptions.DEFAULT) {
|
|
43252
|
+
const _scanner = createScanner(text2, false);
|
|
43253
|
+
const _jsonPath = [];
|
|
43254
|
+
let suppressedCallbacks = 0;
|
|
43255
|
+
function toNoArgVisit(visitFunction) {
|
|
43256
|
+
return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
42727
43257
|
}
|
|
42728
|
-
|
|
42729
|
-
return true;
|
|
43258
|
+
function toOneArgVisit(visitFunction) {
|
|
43259
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
42730
43260
|
}
|
|
42731
|
-
|
|
42732
|
-
|
|
42733
|
-
return pictographics !== null && pictographics.length >= 2;
|
|
43261
|
+
function toOneArgVisitWithPath(visitFunction) {
|
|
43262
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
|
|
42734
43263
|
}
|
|
42735
|
-
|
|
42736
|
-
|
|
42737
|
-
|
|
42738
|
-
|
|
42739
|
-
}
|
|
42740
|
-
|
|
42741
|
-
|
|
42742
|
-
|
|
42743
|
-
|
|
42744
|
-
|
|
42745
|
-
}
|
|
42746
|
-
function isHangulVowelJamo(codePoint) {
|
|
42747
|
-
return codePoint >= 4448 && codePoint <= 4519 || codePoint >= 55216 && codePoint <= 55238;
|
|
42748
|
-
}
|
|
42749
|
-
function isHangulTrailingJamo(codePoint) {
|
|
42750
|
-
return codePoint >= 4520 && codePoint <= 4607 || codePoint >= 55243 && codePoint <= 55291;
|
|
42751
|
-
}
|
|
42752
|
-
function isHangulJamo(codePoint) {
|
|
42753
|
-
return isHangulLeadingJamo(codePoint) || isHangulVowelJamo(codePoint) || isHangulTrailingJamo(codePoint);
|
|
42754
|
-
}
|
|
42755
|
-
function hangulClusterWidth(visibleSegment, eastAsianWidthOptions) {
|
|
42756
|
-
const codePoints = [];
|
|
42757
|
-
for (const character of visibleSegment) {
|
|
42758
|
-
if (zeroWidthClusterRegex.test(character)) {
|
|
42759
|
-
continue;
|
|
42760
|
-
}
|
|
42761
|
-
codePoints.push(character.codePointAt(0));
|
|
43264
|
+
function toBeginVisit(visitFunction) {
|
|
43265
|
+
return visitFunction ? () => {
|
|
43266
|
+
if (suppressedCallbacks > 0) {
|
|
43267
|
+
suppressedCallbacks++;
|
|
43268
|
+
} else {
|
|
43269
|
+
let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
|
|
43270
|
+
if (cbReturn === false) {
|
|
43271
|
+
suppressedCallbacks = 1;
|
|
43272
|
+
}
|
|
43273
|
+
}
|
|
43274
|
+
} : () => true;
|
|
42762
43275
|
}
|
|
42763
|
-
|
|
42764
|
-
return
|
|
43276
|
+
function toEndVisit(visitFunction) {
|
|
43277
|
+
return visitFunction ? () => {
|
|
43278
|
+
if (suppressedCallbacks > 0) {
|
|
43279
|
+
suppressedCallbacks--;
|
|
43280
|
+
}
|
|
43281
|
+
if (suppressedCallbacks === 0) {
|
|
43282
|
+
visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
|
|
43283
|
+
}
|
|
43284
|
+
} : () => true;
|
|
42765
43285
|
}
|
|
42766
|
-
|
|
42767
|
-
|
|
42768
|
-
|
|
42769
|
-
|
|
42770
|
-
|
|
42771
|
-
|
|
43286
|
+
const onObjectBegin = toBeginVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toEndVisit(visitor.onObjectEnd), onArrayBegin = toBeginVisit(visitor.onArrayBegin), onArrayEnd = toEndVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError5 = toOneArgVisit(visitor.onError);
|
|
43287
|
+
const disallowComments = options3 && options3.disallowComments;
|
|
43288
|
+
const allowTrailingComma = options3 && options3.allowTrailingComma;
|
|
43289
|
+
function scanNext() {
|
|
43290
|
+
while (true) {
|
|
43291
|
+
const token = _scanner.scan();
|
|
43292
|
+
switch (_scanner.getTokenError()) {
|
|
43293
|
+
case 4:
|
|
43294
|
+
handleError(14);
|
|
43295
|
+
break;
|
|
43296
|
+
case 5:
|
|
43297
|
+
handleError(15);
|
|
43298
|
+
break;
|
|
43299
|
+
case 3:
|
|
43300
|
+
handleError(13);
|
|
43301
|
+
break;
|
|
43302
|
+
case 1:
|
|
43303
|
+
if (!disallowComments) {
|
|
43304
|
+
handleError(11);
|
|
43305
|
+
}
|
|
43306
|
+
break;
|
|
43307
|
+
case 2:
|
|
43308
|
+
handleError(12);
|
|
43309
|
+
break;
|
|
43310
|
+
case 6:
|
|
43311
|
+
handleError(16);
|
|
43312
|
+
break;
|
|
42772
43313
|
}
|
|
42773
|
-
|
|
42774
|
-
|
|
43314
|
+
switch (token) {
|
|
43315
|
+
case 12:
|
|
43316
|
+
case 13:
|
|
43317
|
+
if (disallowComments) {
|
|
43318
|
+
handleError(10);
|
|
43319
|
+
} else {
|
|
43320
|
+
onComment();
|
|
43321
|
+
}
|
|
43322
|
+
break;
|
|
43323
|
+
case 16:
|
|
43324
|
+
handleError(1);
|
|
43325
|
+
break;
|
|
43326
|
+
case 15:
|
|
43327
|
+
case 14:
|
|
43328
|
+
break;
|
|
43329
|
+
default:
|
|
43330
|
+
return token;
|
|
42775
43331
|
}
|
|
42776
|
-
return width2;
|
|
42777
|
-
}
|
|
42778
|
-
if (isHangulLeadingJamo(codePoint) && isHangulVowelJamo(codePoints[index2 + 1])) {
|
|
42779
|
-
width2 += 2;
|
|
42780
|
-
index2 += isHangulTrailingJamo(codePoints[index2 + 2]) ? 2 : 1;
|
|
42781
|
-
continue;
|
|
42782
43332
|
}
|
|
42783
|
-
width2 += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
42784
43333
|
}
|
|
42785
|
-
|
|
42786
|
-
|
|
42787
|
-
|
|
42788
|
-
|
|
42789
|
-
|
|
42790
|
-
|
|
42791
|
-
|
|
42792
|
-
|
|
42793
|
-
|
|
42794
|
-
|
|
42795
|
-
|
|
42796
|
-
|
|
43334
|
+
function handleError(error2, skipUntilAfter = [], skipUntil = []) {
|
|
43335
|
+
onError5(error2);
|
|
43336
|
+
if (skipUntilAfter.length + skipUntil.length > 0) {
|
|
43337
|
+
let token = _scanner.getToken();
|
|
43338
|
+
while (token !== 17) {
|
|
43339
|
+
if (skipUntilAfter.indexOf(token) !== -1) {
|
|
43340
|
+
scanNext();
|
|
43341
|
+
break;
|
|
43342
|
+
} else if (skipUntil.indexOf(token) !== -1) {
|
|
43343
|
+
break;
|
|
43344
|
+
}
|
|
43345
|
+
token = scanNext();
|
|
43346
|
+
}
|
|
42797
43347
|
}
|
|
42798
43348
|
}
|
|
42799
|
-
|
|
42800
|
-
|
|
42801
|
-
|
|
42802
|
-
|
|
42803
|
-
|
|
43349
|
+
function parseString(isValue) {
|
|
43350
|
+
const value5 = _scanner.getTokenValue();
|
|
43351
|
+
if (isValue) {
|
|
43352
|
+
onLiteralValue(value5);
|
|
43353
|
+
} else {
|
|
43354
|
+
onObjectProperty(value5);
|
|
43355
|
+
_jsonPath.push(value5);
|
|
43356
|
+
}
|
|
43357
|
+
scanNext();
|
|
43358
|
+
return true;
|
|
42804
43359
|
}
|
|
42805
|
-
|
|
42806
|
-
|
|
42807
|
-
|
|
42808
|
-
|
|
42809
|
-
|
|
42810
|
-
|
|
42811
|
-
|
|
43360
|
+
function parseLiteral() {
|
|
43361
|
+
switch (_scanner.getToken()) {
|
|
43362
|
+
case 11:
|
|
43363
|
+
const tokenValue = _scanner.getTokenValue();
|
|
43364
|
+
let value5 = Number(tokenValue);
|
|
43365
|
+
if (isNaN(value5)) {
|
|
43366
|
+
handleError(2);
|
|
43367
|
+
value5 = 0;
|
|
43368
|
+
}
|
|
43369
|
+
onLiteralValue(value5);
|
|
43370
|
+
break;
|
|
43371
|
+
case 7:
|
|
43372
|
+
onLiteralValue(null);
|
|
43373
|
+
break;
|
|
43374
|
+
case 8:
|
|
43375
|
+
onLiteralValue(true);
|
|
43376
|
+
break;
|
|
43377
|
+
case 9:
|
|
43378
|
+
onLiteralValue(false);
|
|
43379
|
+
break;
|
|
43380
|
+
default:
|
|
43381
|
+
return false;
|
|
43382
|
+
}
|
|
43383
|
+
scanNext();
|
|
43384
|
+
return true;
|
|
42812
43385
|
}
|
|
42813
|
-
|
|
42814
|
-
|
|
43386
|
+
function parseProperty() {
|
|
43387
|
+
if (_scanner.getToken() !== 10) {
|
|
43388
|
+
handleError(3, [], [2, 5]);
|
|
43389
|
+
return false;
|
|
43390
|
+
}
|
|
43391
|
+
parseString(false);
|
|
43392
|
+
if (_scanner.getToken() === 6) {
|
|
43393
|
+
onSeparator(":");
|
|
43394
|
+
scanNext();
|
|
43395
|
+
if (!parseValue()) {
|
|
43396
|
+
handleError(4, [], [2, 5]);
|
|
43397
|
+
}
|
|
43398
|
+
} else {
|
|
43399
|
+
handleError(5, [], [2, 5]);
|
|
43400
|
+
}
|
|
43401
|
+
_jsonPath.pop();
|
|
43402
|
+
return true;
|
|
42815
43403
|
}
|
|
42816
|
-
|
|
42817
|
-
|
|
43404
|
+
function parseObject() {
|
|
43405
|
+
onObjectBegin();
|
|
43406
|
+
scanNext();
|
|
43407
|
+
let needsComma = false;
|
|
43408
|
+
while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
|
|
43409
|
+
if (_scanner.getToken() === 5) {
|
|
43410
|
+
if (!needsComma) {
|
|
43411
|
+
handleError(4, [], []);
|
|
43412
|
+
}
|
|
43413
|
+
onSeparator(",");
|
|
43414
|
+
scanNext();
|
|
43415
|
+
if (_scanner.getToken() === 2 && allowTrailingComma) {
|
|
43416
|
+
break;
|
|
43417
|
+
}
|
|
43418
|
+
} else if (needsComma) {
|
|
43419
|
+
handleError(6, [], []);
|
|
43420
|
+
}
|
|
43421
|
+
if (!parseProperty()) {
|
|
43422
|
+
handleError(4, [], [2, 5]);
|
|
43423
|
+
}
|
|
43424
|
+
needsComma = true;
|
|
43425
|
+
}
|
|
43426
|
+
onObjectEnd();
|
|
43427
|
+
if (_scanner.getToken() !== 2) {
|
|
43428
|
+
handleError(7, [2], []);
|
|
43429
|
+
} else {
|
|
43430
|
+
scanNext();
|
|
43431
|
+
}
|
|
43432
|
+
return true;
|
|
42818
43433
|
}
|
|
42819
|
-
|
|
42820
|
-
|
|
42821
|
-
|
|
42822
|
-
|
|
42823
|
-
|
|
43434
|
+
function parseArray2() {
|
|
43435
|
+
onArrayBegin();
|
|
43436
|
+
scanNext();
|
|
43437
|
+
let isFirstElement = true;
|
|
43438
|
+
let needsComma = false;
|
|
43439
|
+
while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
|
|
43440
|
+
if (_scanner.getToken() === 5) {
|
|
43441
|
+
if (!needsComma) {
|
|
43442
|
+
handleError(4, [], []);
|
|
43443
|
+
}
|
|
43444
|
+
onSeparator(",");
|
|
43445
|
+
scanNext();
|
|
43446
|
+
if (_scanner.getToken() === 4 && allowTrailingComma) {
|
|
43447
|
+
break;
|
|
43448
|
+
}
|
|
43449
|
+
} else if (needsComma) {
|
|
43450
|
+
handleError(6, [], []);
|
|
43451
|
+
}
|
|
43452
|
+
if (isFirstElement) {
|
|
43453
|
+
_jsonPath.push(0);
|
|
43454
|
+
isFirstElement = false;
|
|
43455
|
+
} else {
|
|
43456
|
+
_jsonPath[_jsonPath.length - 1]++;
|
|
43457
|
+
}
|
|
43458
|
+
if (!parseValue()) {
|
|
43459
|
+
handleError(4, [], [4, 5]);
|
|
43460
|
+
}
|
|
43461
|
+
needsComma = true;
|
|
42824
43462
|
}
|
|
42825
|
-
|
|
42826
|
-
|
|
42827
|
-
|
|
43463
|
+
onArrayEnd();
|
|
43464
|
+
if (!isFirstElement) {
|
|
43465
|
+
_jsonPath.pop();
|
|
42828
43466
|
}
|
|
42829
|
-
|
|
42830
|
-
|
|
42831
|
-
|
|
42832
|
-
|
|
42833
|
-
continue;
|
|
43467
|
+
if (_scanner.getToken() !== 4) {
|
|
43468
|
+
handleError(8, [4], []);
|
|
43469
|
+
} else {
|
|
43470
|
+
scanNext();
|
|
42834
43471
|
}
|
|
42835
|
-
|
|
42836
|
-
width2 += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
42837
|
-
width2 += trailingWidth(visibleSegment, eastAsianWidthOptions);
|
|
43472
|
+
return true;
|
|
42838
43473
|
}
|
|
42839
|
-
|
|
42840
|
-
|
|
42841
|
-
|
|
42842
|
-
|
|
42843
|
-
|
|
42844
|
-
|
|
42845
|
-
|
|
42846
|
-
|
|
42847
|
-
|
|
42848
|
-
|
|
42849
|
-
|
|
42850
|
-
bold: [1, 22],
|
|
42851
|
-
dim: [2, 22],
|
|
42852
|
-
italic: [3, 23],
|
|
42853
|
-
underline: [4, 24],
|
|
42854
|
-
overline: [53, 55],
|
|
42855
|
-
inverse: [7, 27],
|
|
42856
|
-
hidden: [8, 28],
|
|
42857
|
-
strikethrough: [9, 29]
|
|
42858
|
-
},
|
|
42859
|
-
color: {
|
|
42860
|
-
black: [30, 39],
|
|
42861
|
-
red: [31, 39],
|
|
42862
|
-
green: [32, 39],
|
|
42863
|
-
yellow: [33, 39],
|
|
42864
|
-
blue: [34, 39],
|
|
42865
|
-
magenta: [35, 39],
|
|
42866
|
-
cyan: [36, 39],
|
|
42867
|
-
white: [37, 39],
|
|
42868
|
-
blackBright: [90, 39],
|
|
42869
|
-
gray: [90, 39],
|
|
42870
|
-
grey: [90, 39],
|
|
42871
|
-
redBright: [91, 39],
|
|
42872
|
-
greenBright: [92, 39],
|
|
42873
|
-
yellowBright: [93, 39],
|
|
42874
|
-
blueBright: [94, 39],
|
|
42875
|
-
magentaBright: [95, 39],
|
|
42876
|
-
cyanBright: [96, 39],
|
|
42877
|
-
whiteBright: [97, 39]
|
|
42878
|
-
},
|
|
42879
|
-
bgColor: {
|
|
42880
|
-
bgBlack: [40, 49],
|
|
42881
|
-
bgRed: [41, 49],
|
|
42882
|
-
bgGreen: [42, 49],
|
|
42883
|
-
bgYellow: [43, 49],
|
|
42884
|
-
bgBlue: [44, 49],
|
|
42885
|
-
bgMagenta: [45, 49],
|
|
42886
|
-
bgCyan: [46, 49],
|
|
42887
|
-
bgWhite: [47, 49],
|
|
42888
|
-
bgBlackBright: [100, 49],
|
|
42889
|
-
bgGray: [100, 49],
|
|
42890
|
-
bgGrey: [100, 49],
|
|
42891
|
-
bgRedBright: [101, 49],
|
|
42892
|
-
bgGreenBright: [102, 49],
|
|
42893
|
-
bgYellowBright: [103, 49],
|
|
42894
|
-
bgBlueBright: [104, 49],
|
|
42895
|
-
bgMagentaBright: [105, 49],
|
|
42896
|
-
bgCyanBright: [106, 49],
|
|
42897
|
-
bgWhiteBright: [107, 49]
|
|
43474
|
+
function parseValue() {
|
|
43475
|
+
switch (_scanner.getToken()) {
|
|
43476
|
+
case 3:
|
|
43477
|
+
return parseArray2();
|
|
43478
|
+
case 1:
|
|
43479
|
+
return parseObject();
|
|
43480
|
+
case 10:
|
|
43481
|
+
return parseString(true);
|
|
43482
|
+
default:
|
|
43483
|
+
return parseLiteral();
|
|
43484
|
+
}
|
|
42898
43485
|
}
|
|
42899
|
-
|
|
42900
|
-
|
|
42901
|
-
|
|
42902
|
-
|
|
42903
|
-
var colorNames = [...foregroundColorNames, ...backgroundColorNames];
|
|
42904
|
-
function assembleStyles() {
|
|
42905
|
-
const codes2 = new Map;
|
|
42906
|
-
for (const [groupName, group2] of Object.entries(styles)) {
|
|
42907
|
-
for (const [styleName, style] of Object.entries(group2)) {
|
|
42908
|
-
styles[styleName] = {
|
|
42909
|
-
open: `\x1B[${style[0]}m`,
|
|
42910
|
-
close: `\x1B[${style[1]}m`
|
|
42911
|
-
};
|
|
42912
|
-
group2[styleName] = styles[styleName];
|
|
42913
|
-
codes2.set(style[0], style[1]);
|
|
43486
|
+
scanNext();
|
|
43487
|
+
if (_scanner.getToken() === 17) {
|
|
43488
|
+
if (options3.allowEmptyContent) {
|
|
43489
|
+
return true;
|
|
42914
43490
|
}
|
|
42915
|
-
|
|
42916
|
-
|
|
42917
|
-
enumerable: false
|
|
42918
|
-
});
|
|
43491
|
+
handleError(4, [], []);
|
|
43492
|
+
return false;
|
|
42919
43493
|
}
|
|
42920
|
-
|
|
42921
|
-
|
|
42922
|
-
|
|
43494
|
+
if (!parseValue()) {
|
|
43495
|
+
handleError(4, [], []);
|
|
43496
|
+
return false;
|
|
43497
|
+
}
|
|
43498
|
+
if (_scanner.getToken() !== 17) {
|
|
43499
|
+
handleError(9, [], []);
|
|
43500
|
+
}
|
|
43501
|
+
return true;
|
|
43502
|
+
}
|
|
43503
|
+
function getNodeType(value5) {
|
|
43504
|
+
switch (typeof value5) {
|
|
43505
|
+
case "boolean":
|
|
43506
|
+
return "boolean";
|
|
43507
|
+
case "number":
|
|
43508
|
+
return "number";
|
|
43509
|
+
case "string":
|
|
43510
|
+
return "string";
|
|
43511
|
+
case "object": {
|
|
43512
|
+
if (!value5) {
|
|
43513
|
+
return "null";
|
|
43514
|
+
} else if (Array.isArray(value5)) {
|
|
43515
|
+
return "array";
|
|
43516
|
+
}
|
|
43517
|
+
return "object";
|
|
43518
|
+
}
|
|
43519
|
+
default:
|
|
43520
|
+
return "null";
|
|
43521
|
+
}
|
|
43522
|
+
}
|
|
43523
|
+
|
|
43524
|
+
// node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/main.js
|
|
43525
|
+
var ScanError;
|
|
43526
|
+
(function(ScanError2) {
|
|
43527
|
+
ScanError2[ScanError2["None"] = 0] = "None";
|
|
43528
|
+
ScanError2[ScanError2["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
|
|
43529
|
+
ScanError2[ScanError2["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
|
|
43530
|
+
ScanError2[ScanError2["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
|
|
43531
|
+
ScanError2[ScanError2["InvalidUnicode"] = 4] = "InvalidUnicode";
|
|
43532
|
+
ScanError2[ScanError2["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
|
|
43533
|
+
ScanError2[ScanError2["InvalidCharacter"] = 6] = "InvalidCharacter";
|
|
43534
|
+
})(ScanError || (ScanError = {}));
|
|
43535
|
+
var SyntaxKind;
|
|
43536
|
+
(function(SyntaxKind2) {
|
|
43537
|
+
SyntaxKind2[SyntaxKind2["OpenBraceToken"] = 1] = "OpenBraceToken";
|
|
43538
|
+
SyntaxKind2[SyntaxKind2["CloseBraceToken"] = 2] = "CloseBraceToken";
|
|
43539
|
+
SyntaxKind2[SyntaxKind2["OpenBracketToken"] = 3] = "OpenBracketToken";
|
|
43540
|
+
SyntaxKind2[SyntaxKind2["CloseBracketToken"] = 4] = "CloseBracketToken";
|
|
43541
|
+
SyntaxKind2[SyntaxKind2["CommaToken"] = 5] = "CommaToken";
|
|
43542
|
+
SyntaxKind2[SyntaxKind2["ColonToken"] = 6] = "ColonToken";
|
|
43543
|
+
SyntaxKind2[SyntaxKind2["NullKeyword"] = 7] = "NullKeyword";
|
|
43544
|
+
SyntaxKind2[SyntaxKind2["TrueKeyword"] = 8] = "TrueKeyword";
|
|
43545
|
+
SyntaxKind2[SyntaxKind2["FalseKeyword"] = 9] = "FalseKeyword";
|
|
43546
|
+
SyntaxKind2[SyntaxKind2["StringLiteral"] = 10] = "StringLiteral";
|
|
43547
|
+
SyntaxKind2[SyntaxKind2["NumericLiteral"] = 11] = "NumericLiteral";
|
|
43548
|
+
SyntaxKind2[SyntaxKind2["LineCommentTrivia"] = 12] = "LineCommentTrivia";
|
|
43549
|
+
SyntaxKind2[SyntaxKind2["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
|
|
43550
|
+
SyntaxKind2[SyntaxKind2["LineBreakTrivia"] = 14] = "LineBreakTrivia";
|
|
43551
|
+
SyntaxKind2[SyntaxKind2["Trivia"] = 15] = "Trivia";
|
|
43552
|
+
SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
|
|
43553
|
+
SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
|
|
43554
|
+
})(SyntaxKind || (SyntaxKind = {}));
|
|
43555
|
+
var parseTree2 = parseTree;
|
|
43556
|
+
var getNodeValue2 = getNodeValue;
|
|
43557
|
+
var visit2 = visit;
|
|
43558
|
+
var ParseErrorCode;
|
|
43559
|
+
(function(ParseErrorCode2) {
|
|
43560
|
+
ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
|
|
43561
|
+
ParseErrorCode2[ParseErrorCode2["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
|
|
43562
|
+
ParseErrorCode2[ParseErrorCode2["PropertyNameExpected"] = 3] = "PropertyNameExpected";
|
|
43563
|
+
ParseErrorCode2[ParseErrorCode2["ValueExpected"] = 4] = "ValueExpected";
|
|
43564
|
+
ParseErrorCode2[ParseErrorCode2["ColonExpected"] = 5] = "ColonExpected";
|
|
43565
|
+
ParseErrorCode2[ParseErrorCode2["CommaExpected"] = 6] = "CommaExpected";
|
|
43566
|
+
ParseErrorCode2[ParseErrorCode2["CloseBraceExpected"] = 7] = "CloseBraceExpected";
|
|
43567
|
+
ParseErrorCode2[ParseErrorCode2["CloseBracketExpected"] = 8] = "CloseBracketExpected";
|
|
43568
|
+
ParseErrorCode2[ParseErrorCode2["EndOfFileExpected"] = 9] = "EndOfFileExpected";
|
|
43569
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCommentToken"] = 10] = "InvalidCommentToken";
|
|
43570
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
|
|
43571
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
|
|
43572
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
|
|
43573
|
+
ParseErrorCode2[ParseErrorCode2["InvalidUnicode"] = 14] = "InvalidUnicode";
|
|
43574
|
+
ParseErrorCode2[ParseErrorCode2["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
|
|
43575
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCharacter"] = 16] = "InvalidCharacter";
|
|
43576
|
+
})(ParseErrorCode || (ParseErrorCode = {}));
|
|
43577
|
+
|
|
43578
|
+
// packages/cli/src/jsonc.ts
|
|
43579
|
+
var parseOptions = { allowTrailingComma: true, allowEmptyContent: true };
|
|
43580
|
+
var defaultIndent = " ";
|
|
43581
|
+
function parse6(text2) {
|
|
43582
|
+
const errors = [];
|
|
43583
|
+
const root = parseTree2(text2, errors, parseOptions);
|
|
43584
|
+
const comments = [];
|
|
43585
|
+
const commas = [];
|
|
43586
|
+
visit2(text2, {
|
|
43587
|
+
onComment: (offset, length) => {
|
|
43588
|
+
comments.push({ offset, length });
|
|
43589
|
+
},
|
|
43590
|
+
onSeparator: (character, offset) => {
|
|
43591
|
+
if (character === ",")
|
|
43592
|
+
commas.push(offset);
|
|
43593
|
+
}
|
|
43594
|
+
}, parseOptions);
|
|
43595
|
+
return errors.length > 0 ? exports_Option.none() : exports_Option.some({ root: exports_Option.fromUndefinedOr(root), comments, commas });
|
|
43596
|
+
}
|
|
43597
|
+
function members(root) {
|
|
43598
|
+
return (root.children ?? []).flatMap((property) => {
|
|
43599
|
+
const [key, value5] = property.children ?? [];
|
|
43600
|
+
return key === undefined || value5 === undefined ? [] : [{ key, value: value5 }];
|
|
43601
|
+
});
|
|
43602
|
+
}
|
|
43603
|
+
function indentAt(text2, offset) {
|
|
43604
|
+
const prefix3 = text2.slice(text2.lastIndexOf(`
|
|
43605
|
+
`, offset - 1) + 1, offset);
|
|
43606
|
+
return /^[ \t]*$/.test(prefix3) ? exports_Option.some(prefix3) : exports_Option.none();
|
|
43607
|
+
}
|
|
43608
|
+
function lineBreak(text2, parsed, from, to) {
|
|
43609
|
+
let index2 = from;
|
|
43610
|
+
while (index2 < to) {
|
|
43611
|
+
const position = index2;
|
|
43612
|
+
const comment = parsed.comments.find((range3) => position >= range3.offset && position < range3.offset + range3.length);
|
|
43613
|
+
if (comment !== undefined)
|
|
43614
|
+
index2 = comment.offset + comment.length;
|
|
43615
|
+
else if (text2[index2] === `
|
|
43616
|
+
` || text2[index2] === "\r" && text2[index2 + 1] === `
|
|
43617
|
+
`)
|
|
43618
|
+
return exports_Option.some(index2);
|
|
43619
|
+
else
|
|
43620
|
+
index2++;
|
|
43621
|
+
}
|
|
43622
|
+
return exports_Option.none();
|
|
43623
|
+
}
|
|
43624
|
+
function additions(text2, parsed, root, lines2) {
|
|
43625
|
+
const eol = text2.includes(`\r
|
|
43626
|
+
`) ? `\r
|
|
43627
|
+
` : `
|
|
43628
|
+
`;
|
|
43629
|
+
const close3 = root.offset + root.length - 1;
|
|
43630
|
+
const last = members(root).at(-1);
|
|
43631
|
+
if (last === undefined) {
|
|
43632
|
+
const outer = exports_Option.getOrElse(indentAt(text2, root.offset), () => "");
|
|
43633
|
+
const body = lines2.map((line) => `${eol}${outer}${defaultIndent}${line}`).join(",");
|
|
43634
|
+
return [
|
|
43635
|
+
exports_Option.match(lineBreak(text2, parsed, root.offset + 1, close3), {
|
|
43636
|
+
onNone: () => ({ offset: root.offset + 1, length: 0, text: `${body}${eol}${outer}` }),
|
|
43637
|
+
onSome: (offset) => ({ offset, length: 0, text: body })
|
|
43638
|
+
})
|
|
43639
|
+
];
|
|
43640
|
+
}
|
|
43641
|
+
const end3 = last.value.offset + last.value.length;
|
|
43642
|
+
const comma = parsed.commas.find((offset) => offset >= end3 && offset < close3);
|
|
43643
|
+
const indent = exports_Option.getOrElse(indentAt(text2, last.key.offset), () => defaultIndent);
|
|
43644
|
+
return exports_Option.match(lineBreak(text2, parsed, comma === undefined ? end3 : comma + 1, close3), {
|
|
43645
|
+
onNone: () => [
|
|
43646
|
+
comma === undefined ? { offset: end3, length: 0, text: lines2.map((line) => `, ${line}`).join("") } : { offset: comma + 1, length: 0, text: lines2.map((line) => ` ${line},`).join("") }
|
|
43647
|
+
],
|
|
43648
|
+
onSome: (offset) => comma === undefined ? [
|
|
43649
|
+
{
|
|
43650
|
+
offset: end3,
|
|
43651
|
+
length: offset - end3,
|
|
43652
|
+
text: `,${text2.slice(end3, offset)}${lines2.map((line) => `${eol}${indent}${line}`).join(",")}`
|
|
43653
|
+
}
|
|
43654
|
+
] : [{ offset, length: 0, text: lines2.map((line) => `${eol}${indent}${line},`).join("") }]
|
|
42923
43655
|
});
|
|
42924
|
-
styles.color.close = "\x1B[39m";
|
|
42925
|
-
styles.bgColor.close = "\x1B[49m";
|
|
42926
|
-
styles.color.ansi = wrapAnsi16();
|
|
42927
|
-
styles.color.ansi256 = wrapAnsi256();
|
|
42928
|
-
styles.color.ansi16m = wrapAnsi16m();
|
|
42929
|
-
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
42930
|
-
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
42931
|
-
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
42932
|
-
Object.defineProperties(styles, {
|
|
42933
|
-
rgbToAnsi256: {
|
|
42934
|
-
value(red2, green2, blue) {
|
|
42935
|
-
if (red2 === green2 && green2 === blue) {
|
|
42936
|
-
if (red2 < 8) {
|
|
42937
|
-
return 16;
|
|
42938
|
-
}
|
|
42939
|
-
if (red2 > 248) {
|
|
42940
|
-
return 231;
|
|
42941
|
-
}
|
|
42942
|
-
return Math.round((red2 - 8) / 247 * 24) + 232;
|
|
42943
|
-
}
|
|
42944
|
-
return 16 + 36 * Math.round(red2 / 255 * 5) + 6 * Math.round(green2 / 255 * 5) + Math.round(blue / 255 * 5);
|
|
42945
|
-
},
|
|
42946
|
-
enumerable: false
|
|
42947
|
-
},
|
|
42948
|
-
hexToRgb: {
|
|
42949
|
-
value(hex2) {
|
|
42950
|
-
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex2.toString(16));
|
|
42951
|
-
if (!matches) {
|
|
42952
|
-
return [0, 0, 0];
|
|
42953
|
-
}
|
|
42954
|
-
let [colorString] = matches;
|
|
42955
|
-
if (colorString.length === 3) {
|
|
42956
|
-
colorString = [...colorString].map((character) => character + character).join("");
|
|
42957
|
-
}
|
|
42958
|
-
const integer = Number.parseInt(colorString, 16);
|
|
42959
|
-
return [
|
|
42960
|
-
integer >> 16 & 255,
|
|
42961
|
-
integer >> 8 & 255,
|
|
42962
|
-
integer & 255
|
|
42963
|
-
];
|
|
42964
|
-
},
|
|
42965
|
-
enumerable: false
|
|
42966
|
-
},
|
|
42967
|
-
hexToAnsi256: {
|
|
42968
|
-
value: (hex2) => styles.rgbToAnsi256(...styles.hexToRgb(hex2)),
|
|
42969
|
-
enumerable: false
|
|
42970
|
-
},
|
|
42971
|
-
ansi256ToAnsi: {
|
|
42972
|
-
value(code) {
|
|
42973
|
-
if (code < 8) {
|
|
42974
|
-
return 30 + code;
|
|
42975
|
-
}
|
|
42976
|
-
if (code < 16) {
|
|
42977
|
-
return 90 + (code - 8);
|
|
42978
|
-
}
|
|
42979
|
-
let red2;
|
|
42980
|
-
let green2;
|
|
42981
|
-
let blue;
|
|
42982
|
-
if (code >= 232) {
|
|
42983
|
-
red2 = ((code - 232) * 10 + 8) / 255;
|
|
42984
|
-
green2 = red2;
|
|
42985
|
-
blue = red2;
|
|
42986
|
-
} else {
|
|
42987
|
-
code -= 16;
|
|
42988
|
-
const remainder2 = code % 36;
|
|
42989
|
-
red2 = Math.floor(code / 36) / 5;
|
|
42990
|
-
green2 = Math.floor(remainder2 / 6) / 5;
|
|
42991
|
-
blue = remainder2 % 6 / 5;
|
|
42992
|
-
}
|
|
42993
|
-
const value5 = Math.max(red2, green2, blue) * 2;
|
|
42994
|
-
if (value5 === 0) {
|
|
42995
|
-
return 30;
|
|
42996
|
-
}
|
|
42997
|
-
let result6 = 30 + (Math.round(blue) << 2 | Math.round(green2) << 1 | Math.round(red2));
|
|
42998
|
-
if (value5 === 2) {
|
|
42999
|
-
result6 += 60;
|
|
43000
|
-
}
|
|
43001
|
-
return result6;
|
|
43002
|
-
},
|
|
43003
|
-
enumerable: false
|
|
43004
|
-
},
|
|
43005
|
-
rgbToAnsi: {
|
|
43006
|
-
value: (red2, green2, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red2, green2, blue)),
|
|
43007
|
-
enumerable: false
|
|
43008
|
-
},
|
|
43009
|
-
hexToAnsi: {
|
|
43010
|
-
value: (hex2) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex2)),
|
|
43011
|
-
enumerable: false
|
|
43012
|
-
}
|
|
43013
|
-
});
|
|
43014
|
-
return styles;
|
|
43015
43656
|
}
|
|
43016
|
-
var
|
|
43017
|
-
var
|
|
43018
|
-
|
|
43019
|
-
|
|
43020
|
-
|
|
43021
|
-
|
|
43022
|
-
|
|
43023
|
-
|
|
43024
|
-
|
|
43025
|
-
|
|
43026
|
-
|
|
43027
|
-
|
|
43028
|
-
var
|
|
43029
|
-
|
|
43030
|
-
|
|
43031
|
-
|
|
43032
|
-
|
|
43033
|
-
|
|
43034
|
-
|
|
43035
|
-
|
|
43036
|
-
|
|
43037
|
-
|
|
43038
|
-
|
|
43039
|
-
])
|
|
43040
|
-
|
|
43041
|
-
|
|
43042
|
-
|
|
43043
|
-
|
|
43044
|
-
|
|
43045
|
-
|
|
43046
|
-
|
|
43047
|
-
|
|
43048
|
-
|
|
43049
|
-
|
|
43050
|
-
|
|
43051
|
-
|
|
43052
|
-
|
|
43053
|
-
|
|
43054
|
-
|
|
43055
|
-
|
|
43056
|
-
|
|
43057
|
-
|
|
43058
|
-
|
|
43059
|
-
|
|
43060
|
-
|
|
43061
|
-
return;
|
|
43657
|
+
var spliced = (text2, splices) => splices.toSorted((a, b) => b.offset - a.offset).reduce((result6, splice) => `${result6.slice(0, splice.offset)}${splice.text}${result6.slice(splice.offset + splice.length)}`, text2);
|
|
43658
|
+
var others = (root, keys4) => members(root).filter(({ key }) => !keys4.has(String(key.value))).map(({ key, value: value5 }) => `${JSON.stringify(key.value)}=${JSON.stringify(getNodeValue2(value5))}`).join(`
|
|
43659
|
+
`);
|
|
43660
|
+
var holds = (root, properties) => properties.every(([key, value5]) => {
|
|
43661
|
+
const found = members(root).filter((member) => member.key.value === key);
|
|
43662
|
+
return found.length === 1 && found.every((member) => getNodeValue2(member.value) === value5);
|
|
43663
|
+
});
|
|
43664
|
+
function listed(root, key) {
|
|
43665
|
+
const found = members(root).filter((member2) => member2.key.value === key);
|
|
43666
|
+
const [member] = found;
|
|
43667
|
+
return found.length === 1 && member?.value.type === "array" ? exports_Option.some((member.value.children ?? []).map((item) => JSON.stringify(getNodeValue2(item)))) : exports_Option.none();
|
|
43668
|
+
}
|
|
43669
|
+
var includes = (result6, root, memberships) => memberships.every(([key, item]) => {
|
|
43670
|
+
const before = exports_Option.getOrElse(listed(root, key), () => []);
|
|
43671
|
+
const wanted = before.includes(JSON.stringify(item)) ? before : [...before, JSON.stringify(item)];
|
|
43672
|
+
return exports_Option.getOrElse(listed(result6, key), () => []).join(`
|
|
43673
|
+
`) === wanted.join(`
|
|
43674
|
+
`);
|
|
43675
|
+
});
|
|
43676
|
+
function setProperties(source, properties, memberships = []) {
|
|
43677
|
+
const mark = source.startsWith("\uFEFF") ? "\uFEFF" : "";
|
|
43678
|
+
const text2 = source.slice(mark.length);
|
|
43679
|
+
const keys4 = new Set([...properties, ...memberships].map(([key]) => key));
|
|
43680
|
+
const rendered = ([key, value5]) => `${JSON.stringify(key)}: ${JSON.stringify(value5)}`;
|
|
43681
|
+
const holding = ([key, item]) => `${JSON.stringify(key)}: [${JSON.stringify(item)}]`;
|
|
43682
|
+
const parsed = parse6(text2);
|
|
43683
|
+
if (exports_Option.isNone(parsed))
|
|
43684
|
+
return exports_Option.none();
|
|
43685
|
+
if (exports_Option.isNone(parsed.value.root)) {
|
|
43686
|
+
const eol = text2.includes(`\r
|
|
43687
|
+
`) ? `\r
|
|
43688
|
+
` : `
|
|
43689
|
+
`;
|
|
43690
|
+
const lead = text2 === "" || text2.endsWith(`
|
|
43691
|
+
`) ? text2 : `${text2}${eol}`;
|
|
43692
|
+
const body = [...properties.map(rendered), ...memberships.map(holding)].map((line) => `${defaultIndent}${line}`);
|
|
43693
|
+
return exports_Option.some({
|
|
43694
|
+
text: `${mark}${lead}{${eol}${body.join(`,${eol}`)}${eol}}${eol}`,
|
|
43695
|
+
changes: properties.map(([key, value5]) => ({
|
|
43696
|
+
key,
|
|
43697
|
+
value: JSON.stringify(value5),
|
|
43698
|
+
previous: exports_Option.none()
|
|
43699
|
+
})),
|
|
43700
|
+
included: memberships
|
|
43701
|
+
});
|
|
43062
43702
|
}
|
|
43063
|
-
|
|
43064
|
-
|
|
43065
|
-
|
|
43066
|
-
|
|
43067
|
-
|
|
43068
|
-
|
|
43069
|
-
|
|
43070
|
-
|
|
43071
|
-
const
|
|
43072
|
-
|
|
43073
|
-
|
|
43074
|
-
|
|
43075
|
-
|
|
43076
|
-
if (
|
|
43077
|
-
index2 = introducer.index + 1;
|
|
43703
|
+
const root = parsed.value.root.value;
|
|
43704
|
+
if (root.type !== "object")
|
|
43705
|
+
return exports_Option.none();
|
|
43706
|
+
const changes2 = [];
|
|
43707
|
+
const splices = [];
|
|
43708
|
+
const included = [];
|
|
43709
|
+
const missing2 = [];
|
|
43710
|
+
for (const property of properties) {
|
|
43711
|
+
const [key, value5] = property;
|
|
43712
|
+
const found = members(root).filter((member2) => member2.key.value === key);
|
|
43713
|
+
const [member] = found;
|
|
43714
|
+
if (found.length > 1)
|
|
43715
|
+
return exports_Option.none();
|
|
43716
|
+
if (member !== undefined && getNodeValue2(member.value) === value5)
|
|
43078
43717
|
continue;
|
|
43079
|
-
|
|
43080
|
-
|
|
43081
|
-
|
|
43082
|
-
|
|
43083
|
-
|
|
43084
|
-
|
|
43085
|
-
|
|
43086
|
-
|
|
43087
|
-
|
|
43088
|
-
|
|
43089
|
-
|
|
43090
|
-
|
|
43091
|
-
|
|
43092
|
-
let plainText = "";
|
|
43093
|
-
forEachSegment(string4, (part) => {
|
|
43094
|
-
plainText += part;
|
|
43095
|
-
});
|
|
43096
|
-
return getStringWidth(plainText);
|
|
43097
|
-
};
|
|
43098
|
-
var getTokens = (string4) => {
|
|
43099
|
-
const tokens = [];
|
|
43100
|
-
forEachSegment(string4, (plainText) => {
|
|
43101
|
-
if (ASCII_PRINTABLE_REGEX.test(plainText)) {
|
|
43102
|
-
for (const character of plainText) {
|
|
43103
|
-
tokens.push({ value: character, width: 1 });
|
|
43104
|
-
}
|
|
43105
|
-
return;
|
|
43106
|
-
}
|
|
43107
|
-
for (const { segment } of segmenter2.segment(plainText)) {
|
|
43108
|
-
tokens.push({ value: segment, width: getStringWidth(segment) });
|
|
43109
|
-
}
|
|
43110
|
-
}, (escape2) => {
|
|
43111
|
-
tokens.push({ value: escape2, width: 0 });
|
|
43112
|
-
});
|
|
43113
|
-
return tokens;
|
|
43114
|
-
};
|
|
43115
|
-
var splitWords = (string4) => {
|
|
43116
|
-
let currentWord = { value: "", plainText: "" };
|
|
43117
|
-
const words = [currentWord];
|
|
43118
|
-
forEachSegment(string4, (plainText) => {
|
|
43119
|
-
const parts2 = plainText.split(" ");
|
|
43120
|
-
currentWord.value += parts2[0];
|
|
43121
|
-
currentWord.plainText += parts2[0];
|
|
43122
|
-
for (let index2 = 1;index2 < parts2.length; index2++) {
|
|
43123
|
-
currentWord = { value: parts2[index2], plainText: parts2[index2] };
|
|
43124
|
-
words.push(currentWord);
|
|
43125
|
-
}
|
|
43126
|
-
}, (escape2) => {
|
|
43127
|
-
currentWord.value += escape2;
|
|
43128
|
-
});
|
|
43129
|
-
for (const word of words) {
|
|
43130
|
-
word.width = getStringWidth(word.plainText);
|
|
43131
|
-
}
|
|
43132
|
-
return words;
|
|
43133
|
-
};
|
|
43134
|
-
var getColonColorToken = (parameter) => {
|
|
43135
|
-
const parts2 = parameter.split(":");
|
|
43136
|
-
const code = Number.parseInt(parts2[0], 10);
|
|
43137
|
-
const mode = Number.parseInt(parts2[1], 10);
|
|
43138
|
-
if (![ANSI_SGR_FOREGROUND_EXTENDED, ANSI_SGR_BACKGROUND_EXTENDED, ANSI_SGR_UNDERLINE_COLOR_EXTENDED].includes(code)) {
|
|
43139
|
-
return;
|
|
43140
|
-
}
|
|
43141
|
-
if (mode === ANSI_SGR_COLOR_MODE_256 && parts2.length === 3 && /^\d+$/.test(parts2[2])) {
|
|
43142
|
-
return { code, open: parameter, hasArguments: true };
|
|
43143
|
-
}
|
|
43144
|
-
if (mode !== ANSI_SGR_COLOR_MODE_RGB) {
|
|
43145
|
-
return;
|
|
43146
|
-
}
|
|
43147
|
-
const components = parts2.length === 6 ? parts2.slice(3) : parts2.slice(2);
|
|
43148
|
-
const colorSpace = parts2.length === 6 ? parts2[2] : undefined;
|
|
43149
|
-
if (components.length === 3 && components.every((component) => /^\d+$/.test(component)) && (colorSpace === undefined || /^\d*$/.test(colorSpace))) {
|
|
43150
|
-
return { code, open: parameter, hasArguments: true };
|
|
43718
|
+
changes2.push({
|
|
43719
|
+
key,
|
|
43720
|
+
value: JSON.stringify(value5),
|
|
43721
|
+
previous: exports_Option.map(exports_Option.fromUndefinedOr(member), ({ value: node }) => text2.slice(node.offset, node.offset + node.length))
|
|
43722
|
+
});
|
|
43723
|
+
if (member === undefined)
|
|
43724
|
+
missing2.push(rendered(property));
|
|
43725
|
+
else
|
|
43726
|
+
splices.push({
|
|
43727
|
+
offset: member.value.offset,
|
|
43728
|
+
length: member.value.length,
|
|
43729
|
+
text: JSON.stringify(value5)
|
|
43730
|
+
});
|
|
43151
43731
|
}
|
|
43152
|
-
|
|
43153
|
-
|
|
43154
|
-
|
|
43155
|
-
|
|
43156
|
-
|
|
43157
|
-
|
|
43158
|
-
|
|
43159
|
-
|
|
43160
|
-
if (colonColorToken) {
|
|
43161
|
-
sgrTokens.push(colonColorToken);
|
|
43162
|
-
}
|
|
43163
|
-
continue;
|
|
43164
|
-
}
|
|
43165
|
-
const code = parameter === "" ? ANSI_SGR_RESET : Number.parseInt(parameter, 10);
|
|
43166
|
-
if (!Number.isFinite(code)) {
|
|
43732
|
+
for (const membership of memberships) {
|
|
43733
|
+
const [key, item] = membership;
|
|
43734
|
+
const found = members(root).filter((member2) => member2.key.value === key);
|
|
43735
|
+
const [member] = found;
|
|
43736
|
+
if (found.length > 1 || member !== undefined && member.value.type !== "array")
|
|
43737
|
+
return exports_Option.none();
|
|
43738
|
+
const items = member?.value.children ?? [];
|
|
43739
|
+
if (items.some((node) => getNodeValue2(node) === item))
|
|
43167
43740
|
continue;
|
|
43168
|
-
|
|
43169
|
-
|
|
43170
|
-
|
|
43171
|
-
|
|
43172
|
-
|
|
43173
|
-
|
|
43174
|
-
|
|
43175
|
-
|
|
43176
|
-
|
|
43177
|
-
|
|
43178
|
-
|
|
43179
|
-
|
|
43180
|
-
|
|
43181
|
-
|
|
43182
|
-
|
|
43183
|
-
|
|
43184
|
-
|
|
43185
|
-
|
|
43186
|
-
|
|
43741
|
+
included.push(membership);
|
|
43742
|
+
const last = items.at(-1);
|
|
43743
|
+
if (member === undefined)
|
|
43744
|
+
missing2.push(holding(membership));
|
|
43745
|
+
else
|
|
43746
|
+
splices.push(last === undefined ? { offset: member.value.offset + 1, length: 0, text: JSON.stringify(item) } : { offset: last.offset + last.length, length: 0, text: `, ${JSON.stringify(item)}` });
|
|
43747
|
+
}
|
|
43748
|
+
if (missing2.length > 0)
|
|
43749
|
+
splices.push(...additions(text2, parsed.value, root, missing2));
|
|
43750
|
+
const edited = spliced(text2, splices);
|
|
43751
|
+
return exports_Option.flatMap(parse6(edited), (result6) => exports_Option.match(result6.root, {
|
|
43752
|
+
onNone: () => exports_Option.none(),
|
|
43753
|
+
onSome: (object) => object.type === "object" && holds(object, properties) && includes(object, root, memberships) && others(object, keys4) === others(root, keys4) ? exports_Option.some({ text: `${mark}${edited}`, changes: changes2, included }) : exports_Option.none()
|
|
43754
|
+
}));
|
|
43755
|
+
}
|
|
43756
|
+
|
|
43757
|
+
// packages/cli/src/schedule.ts
|
|
43758
|
+
import { homedir as homedir2, userInfo } from "node:os";
|
|
43759
|
+
|
|
43760
|
+
// packages/cli/src/settings.ts
|
|
43761
|
+
import { randomUUID } from "node:crypto";
|
|
43762
|
+
import { homedir, hostname } from "node:os";
|
|
43763
|
+
class SettingsError extends exports_Schema.TaggedError()("SettingsError", {
|
|
43764
|
+
message: exports_Schema.String
|
|
43765
|
+
}) {
|
|
43766
|
+
}
|
|
43767
|
+
var loopback = new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
43768
|
+
var ServerUrl = exports_Schema.URLFromString.check(exports_Schema.makeFilter((url) => url.protocol === "https:" || url.protocol === "http:" && loopback.has(url.hostname), { expected: "an https:// URL, or http:// on localhost" }));
|
|
43769
|
+
var SyncSettings = exports_Schema.Struct({
|
|
43770
|
+
server: exports_Schema.optionalKey(ServerUrl),
|
|
43771
|
+
token: exports_Schema.optionalKey(exports_Schema.RedactedFromValue(exports_Schema.NonEmptyString))
|
|
43772
|
+
});
|
|
43773
|
+
var configHome = exports_Effect.gen(function* () {
|
|
43774
|
+
const path = yield* exports_Path.Path;
|
|
43775
|
+
return yield* exports_Config.String("XDG_CONFIG_HOME").pipe(exports_Config.option, exports_Effect.map(exports_Option.filter((directory) => path.isAbsolute(directory))));
|
|
43776
|
+
});
|
|
43777
|
+
var settingsDirectory = exports_Effect.gen(function* () {
|
|
43778
|
+
const path = yield* exports_Path.Path;
|
|
43779
|
+
const home = homedir();
|
|
43780
|
+
const xdg = yield* configHome;
|
|
43781
|
+
const appData = yield* exports_Config.String("APPDATA").pipe(exports_Config.option);
|
|
43782
|
+
const root = exports_Option.getOrElse(xdg, () => exports_Match.value(process.platform).pipe(exports_Match.when("win32", () => exports_Option.getOrElse(appData, () => path.join(home, "AppData", "Roaming"))), exports_Match.when("darwin", () => path.join(home, "Library", "Application Support")), exports_Match.orElse(() => path.join(home, ".config"))));
|
|
43783
|
+
return path.join(root, "token-ledger");
|
|
43784
|
+
});
|
|
43785
|
+
var loadMachine = exports_Effect.fn("Settings.loadMachine")(function* (directory) {
|
|
43786
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
43787
|
+
const path = yield* exports_Path.Path;
|
|
43788
|
+
const file2 = path.join(directory, "machine.json");
|
|
43789
|
+
const read2 = fs.readFileString(file2).pipe(exports_Effect.flatMap(exports_Schema.decodeUnknownEffect(exports_Schema.fromJsonString(SyncMachine))), exports_Effect.mapError(() => new SettingsError({ message: `Cannot read ${file2}; fix or remove it.` })));
|
|
43790
|
+
if (yield* fs.exists(file2).pipe(exports_Effect.orElseSucceed(() => true)))
|
|
43791
|
+
return yield* read2;
|
|
43792
|
+
const machine = yield* SyncMachine.makeEffect({
|
|
43793
|
+
id: randomUUID(),
|
|
43794
|
+
label: hostname().trim() || "machine"
|
|
43795
|
+
}).pipe(exports_Effect.orDie);
|
|
43796
|
+
const created = yield* exports_Effect.gen(function* () {
|
|
43797
|
+
yield* fs.makeDirectory(directory, { recursive: true });
|
|
43798
|
+
const temporaryDirectory = yield* fs.makeTempDirectoryScoped({
|
|
43799
|
+
directory,
|
|
43800
|
+
prefix: ".machine-"
|
|
43801
|
+
});
|
|
43802
|
+
const temporary = path.join(temporaryDirectory, "machine.json");
|
|
43803
|
+
yield* fs.writeFileString(temporary, `${JSON.stringify(machine, null, 2)}
|
|
43804
|
+
`, {
|
|
43805
|
+
flag: "wx",
|
|
43806
|
+
mode: 384
|
|
43807
|
+
});
|
|
43808
|
+
return yield* fs.link(temporary, file2).pipe(exports_Effect.as(true), exports_Effect.catchReason("PlatformError", "AlreadyExists", () => exports_Effect.succeed(false)));
|
|
43809
|
+
}).pipe(exports_Effect.scoped, exports_Effect.mapError(() => new SettingsError({ message: `Cannot create ${file2}.` })));
|
|
43810
|
+
return created ? machine : yield* read2;
|
|
43811
|
+
});
|
|
43812
|
+
var loadSyncSettings = exports_Effect.fn("Settings.loadSync")(function* (directory) {
|
|
43813
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
43814
|
+
const path = yield* exports_Path.Path;
|
|
43815
|
+
const file2 = path.join(directory, "sync.json");
|
|
43816
|
+
const failure = new SettingsError({ message: `Cannot read or decode ${file2}.` });
|
|
43817
|
+
if (!(yield* fs.exists(file2).pipe(exports_Effect.mapError(() => failure))))
|
|
43818
|
+
return {};
|
|
43819
|
+
return yield* fs.readFileString(file2).pipe(exports_Effect.flatMap(exports_Schema.decodeUnknownEffect(exports_Schema.fromJsonString(SyncSettings))), exports_Effect.mapError(() => failure));
|
|
43820
|
+
});
|
|
43821
|
+
var saveSyncSettings = exports_Effect.fn("Settings.saveSync")(function* (directory, server, token) {
|
|
43822
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
43823
|
+
const path = yield* exports_Path.Path;
|
|
43824
|
+
const file2 = path.join(directory, "sync.json");
|
|
43825
|
+
yield* exports_Effect.gen(function* () {
|
|
43826
|
+
const settings = yield* exports_Schema.encodeEffect(SyncSettings)({ server, token });
|
|
43827
|
+
yield* fs.makeDirectory(directory, { recursive: true });
|
|
43828
|
+
const temporaryDirectory = yield* fs.makeTempDirectoryScoped({ directory, prefix: ".sync-" });
|
|
43829
|
+
const temporary = path.join(temporaryDirectory, "sync.json");
|
|
43830
|
+
yield* fs.writeFileString(temporary, `${JSON.stringify(settings, null, 2)}
|
|
43831
|
+
`, {
|
|
43832
|
+
flag: "wx",
|
|
43833
|
+
mode: 384
|
|
43834
|
+
});
|
|
43835
|
+
yield* fs.rename(temporary, file2);
|
|
43836
|
+
}).pipe(exports_Effect.scoped, exports_Effect.mapError(() => new SettingsError({ message: `Cannot save ${file2}.` })));
|
|
43837
|
+
return file2;
|
|
43838
|
+
});
|
|
43839
|
+
|
|
43840
|
+
// packages/cli/src/schedule.ts
|
|
43841
|
+
class ScheduleError extends exports_Schema.TaggedError()("ScheduleError", {
|
|
43842
|
+
message: exports_Schema.String
|
|
43843
|
+
}) {
|
|
43844
|
+
}
|
|
43845
|
+
var TimeOfDay = exports_Schema.String.check(exports_Schema.isPattern(/^(?:[01]\d|2[0-3]):[0-5]\d$/));
|
|
43846
|
+
var Action3 = exports_Data.taggedEnum();
|
|
43847
|
+
var unit = "token-ledger-sync";
|
|
43848
|
+
var label = "com.github.ponbac.token-ledger.sync";
|
|
43849
|
+
var task = "token-ledger sync";
|
|
43850
|
+
var packageSpec = "@ponbac/token-ledger@latest";
|
|
43851
|
+
function run6(outcome, program, args2, hint = "") {
|
|
43852
|
+
return Action3.Run({
|
|
43853
|
+
program,
|
|
43854
|
+
args: args2,
|
|
43855
|
+
shown: [program, ...args2].join(" "),
|
|
43856
|
+
outcome,
|
|
43857
|
+
hint,
|
|
43858
|
+
gone: []
|
|
43859
|
+
});
|
|
43860
|
+
}
|
|
43861
|
+
function quotable(job, forbidden2, described) {
|
|
43862
|
+
const offending = [job.nodeDirectory, ...exports_Option.toArray(job.configHome), ...job.flags].find((value5) => forbidden2.test(value5));
|
|
43863
|
+
return offending === undefined ? exports_Effect.succeed(job) : exports_Effect.fail(new ScheduleError({
|
|
43864
|
+
message: `Cannot schedule with ${JSON.stringify(offending)}: it contains ${described}.`
|
|
43865
|
+
}));
|
|
43866
|
+
}
|
|
43867
|
+
var posixWord = (value5) => /^[\w@+=:,./-]+$/.test(value5) ? value5 : `'${value5.replaceAll("'", "'\\''")}'`;
|
|
43868
|
+
var posixScript = (job) => [
|
|
43869
|
+
"cd /",
|
|
43870
|
+
...exports_Option.toArray(job.configHome).map((directory) => `export XDG_CONFIG_HOME=${posixWord(directory)}`),
|
|
43871
|
+
`export PATH=${posixWord(job.nodeDirectory)}:"$PATH"`,
|
|
43872
|
+
`exec npx --yes ${packageSpec} ${["sync", ...job.flags].map(posixWord).join(" ")}`
|
|
43873
|
+
].join("; ");
|
|
43874
|
+
var posixJob = (job) => quotable(job, /\p{Cc}/u, "a control character");
|
|
43875
|
+
var systemdQuoted = (value5) => `"${value5.replaceAll("\\", "\\\\").replaceAll('"', "\\\"").replaceAll("%", "%%").replaceAll("$", () => "$$")}"`;
|
|
43876
|
+
function systemdTimer(directory) {
|
|
43877
|
+
const service4 = `${directory}/${unit}.service`;
|
|
43878
|
+
const timer = `${directory}/${unit}.timer`;
|
|
43879
|
+
const systemctl = (outcome, args2, hint = "") => run6(outcome, "systemctl", ["--user", ...args2], hint);
|
|
43880
|
+
return {
|
|
43881
|
+
name: "systemd user timer",
|
|
43882
|
+
install: (job) => posixJob(job).pipe(exports_Effect.map((job2) => [
|
|
43883
|
+
systemctl("required", ["daemon-reload"], "A systemd user session is required; without one, add the cron entry from the README."),
|
|
43884
|
+
Action3.Write({
|
|
43885
|
+
file: service4,
|
|
43886
|
+
contents: `[Unit]
|
|
43887
|
+
Description=Upload AI usage to toki2
|
|
43888
|
+
|
|
43889
|
+
[Service]
|
|
43890
|
+
Type=oneshot
|
|
43891
|
+
ExecStart=/bin/sh -lc ${systemdQuoted(posixScript(job2))}
|
|
43892
|
+
`
|
|
43893
|
+
}),
|
|
43894
|
+
Action3.Write({
|
|
43895
|
+
file: timer,
|
|
43896
|
+
contents: `[Unit]
|
|
43897
|
+
Description=Daily AI usage sync
|
|
43898
|
+
|
|
43899
|
+
[Timer]
|
|
43900
|
+
OnCalendar=*-*-* ${job2.at}:00
|
|
43901
|
+
Persistent=true
|
|
43902
|
+
RandomizedDelaySec=10m
|
|
43903
|
+
|
|
43904
|
+
[Install]
|
|
43905
|
+
WantedBy=timers.target
|
|
43906
|
+
`
|
|
43907
|
+
}),
|
|
43908
|
+
systemctl("required", ["daemon-reload"]),
|
|
43909
|
+
systemctl("required", ["enable", `${unit}.timer`]),
|
|
43910
|
+
systemctl("required", ["restart", `${unit}.timer`])
|
|
43911
|
+
])),
|
|
43912
|
+
uninstall: [
|
|
43913
|
+
systemctl("reported", ["disable", "--now", `${unit}.timer`]),
|
|
43914
|
+
systemctl("reported", ["clean", "--what=state", `${unit}.timer`]),
|
|
43915
|
+
Action3.Remove({ file: service4 }),
|
|
43916
|
+
Action3.Remove({ file: timer }),
|
|
43917
|
+
systemctl("reported", ["daemon-reload"]),
|
|
43918
|
+
Action3.Run({
|
|
43919
|
+
...systemctl("absent", ["is-active", "--quiet", `${unit}.timer`], "Cannot confirm that the timer is gone; systemd's reason is shown above."),
|
|
43920
|
+
gone: [3, 4]
|
|
43921
|
+
})
|
|
43922
|
+
],
|
|
43923
|
+
status: [systemctl("reported", ["status", "--no-pager", `${unit}.timer`, `${unit}.service`])]
|
|
43924
|
+
};
|
|
43925
|
+
}
|
|
43926
|
+
var xmlText = (value5) => value5.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
43927
|
+
function launchAgent(home, uid) {
|
|
43928
|
+
const plist = `${home}/Library/LaunchAgents/${label}.plist`;
|
|
43929
|
+
const log3 = `${home}/Library/Logs/${unit}.log`;
|
|
43930
|
+
const domain = `gui/${uid}`;
|
|
43931
|
+
return {
|
|
43932
|
+
name: "launchd agent",
|
|
43933
|
+
install: (job) => posixJob(job).pipe(exports_Effect.map((job2) => {
|
|
43934
|
+
const [hour2, minute] = job2.at.split(":").map(Number);
|
|
43935
|
+
return [
|
|
43936
|
+
Action3.Write({
|
|
43937
|
+
file: plist,
|
|
43938
|
+
contents: `<?xml version="1.0" encoding="UTF-8"?>
|
|
43939
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
43940
|
+
<plist version="1.0">
|
|
43941
|
+
<dict>
|
|
43942
|
+
<key>Label</key>
|
|
43943
|
+
<string>${label}</string>
|
|
43944
|
+
<key>ProgramArguments</key>
|
|
43945
|
+
<array>
|
|
43946
|
+
<string>/bin/zsh</string>
|
|
43947
|
+
<string>-lc</string>
|
|
43948
|
+
<string>${xmlText(posixScript(job2))}</string>
|
|
43949
|
+
</array>
|
|
43950
|
+
<key>RunAtLoad</key>
|
|
43951
|
+
<true/>
|
|
43952
|
+
<key>StartCalendarInterval</key>
|
|
43953
|
+
<dict>
|
|
43954
|
+
<key>Hour</key>
|
|
43955
|
+
<integer>${hour2}</integer>
|
|
43956
|
+
<key>Minute</key>
|
|
43957
|
+
<integer>${minute}</integer>
|
|
43958
|
+
</dict>
|
|
43959
|
+
<key>StandardOutPath</key>
|
|
43960
|
+
<string>${xmlText(log3)}</string>
|
|
43961
|
+
<key>StandardErrorPath</key>
|
|
43962
|
+
<string>${xmlText(log3)}</string>
|
|
43963
|
+
</dict>
|
|
43964
|
+
</plist>
|
|
43965
|
+
`
|
|
43966
|
+
}),
|
|
43967
|
+
run6("silent", "launchctl", ["bootout", `${domain}/${label}`]),
|
|
43968
|
+
run6("required", "launchctl", ["bootstrap", domain, plist])
|
|
43969
|
+
];
|
|
43970
|
+
})),
|
|
43971
|
+
uninstall: [
|
|
43972
|
+
run6("reported", "launchctl", ["bootout", `${domain}/${label}`]),
|
|
43973
|
+
Action3.Remove({ file: plist }),
|
|
43974
|
+
run6("absent", "launchctl", ["print", `${domain}/${label}`], "The agent is still loaded; launchd's reason is shown above.")
|
|
43975
|
+
],
|
|
43976
|
+
status: [run6("reported", "launchctl", ["print", `${domain}/${label}`])]
|
|
43977
|
+
};
|
|
43978
|
+
}
|
|
43979
|
+
var cmdWord = (value5) => /^[\w@+=:,./\\-]+$/.test(value5) ? value5 : `"${value5}"`;
|
|
43980
|
+
var powershellString = (value5) => `'${value5.replaceAll("'", "''")}'`;
|
|
43981
|
+
var powershellOptions = ["-NoProfile", "-NonInteractive", "-EncodedCommand"];
|
|
43982
|
+
var powershellArguments = (script) => [
|
|
43983
|
+
...powershellOptions,
|
|
43984
|
+
Buffer.from(script, "utf16le").toString("base64")
|
|
43985
|
+
];
|
|
43986
|
+
var taskScheduler = {
|
|
43987
|
+
name: "Task Scheduler task",
|
|
43988
|
+
install: (job) => quotable(job, /[\p{Cc}"%]/u, 'a control character, `"`, or `%`').pipe(exports_Effect.map((job2) => {
|
|
43989
|
+
const command = [
|
|
43990
|
+
...exports_Option.toArray(job2.configHome).map((directory) => `set "XDG_CONFIG_HOME=${directory}"`),
|
|
43991
|
+
`set "PATH=${job2.nodeDirectory};%PATH%"`,
|
|
43992
|
+
`npx --yes ${packageSpec} ${["sync", ...job2.flags].map(cmdWord).join(" ")}`
|
|
43993
|
+
].join(" && ");
|
|
43994
|
+
const script = [
|
|
43995
|
+
"$ErrorActionPreference = 'Stop'",
|
|
43996
|
+
"$ProgressPreference = 'SilentlyContinue'",
|
|
43997
|
+
`$action = New-ScheduledTaskAction -Execute 'cmd.exe' -Argument ${powershellString(`/d /v:off /s /c "${command}"`)}`,
|
|
43998
|
+
`$trigger = New-ScheduledTaskTrigger -Daily -At '${job2.at}'`,
|
|
43999
|
+
"$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries",
|
|
44000
|
+
`Register-ScheduledTask -TaskName ${powershellString(task)} -Action $action -Trigger $trigger -Settings $settings -Force | Out-Null`
|
|
44001
|
+
].join(`
|
|
44002
|
+
`);
|
|
44003
|
+
return [
|
|
44004
|
+
Action3.Run({
|
|
44005
|
+
program: "powershell.exe",
|
|
44006
|
+
args: powershellArguments(script),
|
|
44007
|
+
shown: `powershell.exe ${powershellOptions.join(" ")} <the script below, as UTF-16LE Base64>
|
|
44008
|
+
${script}`,
|
|
44009
|
+
outcome: "required",
|
|
44010
|
+
hint: "",
|
|
44011
|
+
gone: []
|
|
44012
|
+
})
|
|
44013
|
+
];
|
|
44014
|
+
})),
|
|
44015
|
+
uninstall: [
|
|
44016
|
+
run6("reported", "schtasks.exe", ["/Delete", "/TN", task, "/F"]),
|
|
44017
|
+
run6("absent", "schtasks.exe", ["/Query", "/TN", task], "The task is still registered; Task Scheduler's reason is shown above.")
|
|
44018
|
+
],
|
|
44019
|
+
status: [run6("reported", "schtasks.exe", ["/Query", "/TN", task, "/V", "/FO", "LIST"])]
|
|
44020
|
+
};
|
|
44021
|
+
var hostScheduler = exports_Effect.gen(function* () {
|
|
44022
|
+
const path = yield* exports_Path.Path;
|
|
44023
|
+
const home = homedir2();
|
|
44024
|
+
const units = exports_Option.getOrElse(yield* configHome, () => path.join(home, ".config"));
|
|
44025
|
+
return yield* exports_Match.value(process.platform).pipe(exports_Match.when("linux", () => exports_Effect.succeed(systemdTimer(path.join(units, "systemd", "user")))), exports_Match.when("darwin", () => exports_Effect.succeed(launchAgent(home, userInfo().uid))), exports_Match.when("win32", () => exports_Effect.succeed(taskScheduler)), exports_Match.orElse((platform) => exports_Effect.fail(new ScheduleError({
|
|
44026
|
+
message: `No scheduler is supported on ${platform}; schedule token-ledger sync yourself.`
|
|
44027
|
+
}))));
|
|
44028
|
+
});
|
|
44029
|
+
var describe = (actions) => actions.map(Action3.$match({
|
|
44030
|
+
Write: ({ file: file2, contents }) => `write ${file2}
|
|
44031
|
+
${contents.replaceAll(/^(?=.)/gm, " ")}`,
|
|
44032
|
+
Remove: ({ file: file2 }) => `remove ${file2}
|
|
44033
|
+
`,
|
|
44034
|
+
Run: ({ shown }) => `run ${shown}
|
|
44035
|
+
`
|
|
44036
|
+
})).join(`
|
|
44037
|
+
`);
|
|
44038
|
+
var perform = exports_Effect.fn("Schedule.perform")(function* (actions) {
|
|
44039
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
44040
|
+
const path = yield* exports_Path.Path;
|
|
44041
|
+
const spawner = yield* exports_ChildProcessSpawner.ChildProcessSpawner;
|
|
44042
|
+
for (const action of actions)
|
|
44043
|
+
yield* Action3.$match(action, {
|
|
44044
|
+
Write: ({ file: file2, contents }) => fs.makeDirectory(path.dirname(file2), { recursive: true }).pipe(exports_Effect.andThen(fs.writeFileString(file2, contents)), exports_Effect.mapError(() => new ScheduleError({ message: `Cannot write ${file2}.` }))),
|
|
44045
|
+
Remove: ({ file: file2 }) => fs.remove(file2, { force: true }).pipe(exports_Effect.mapError(() => new ScheduleError({ message: `Cannot remove ${file2}.` }))),
|
|
44046
|
+
Run: ({ program, args: args2, outcome, hint, gone }) => {
|
|
44047
|
+
const output = outcome === "silent" || outcome === "absent" ? "ignore" : "inherit";
|
|
44048
|
+
const exit3 = spawner.exitCode(exports_ChildProcess.make(program, args2, { stdin: "ignore", stdout: output, stderr: output })).pipe(exports_Effect.mapError(() => new ScheduleError({ message: `Cannot run ${program}. ${hint}`.trim() })));
|
|
44049
|
+
return exports_Match.value(outcome).pipe(exports_Match.when("required", () => exports_Effect.filterOrFail(exit3, (code) => code === 0, (code) => new ScheduleError({
|
|
44050
|
+
message: `${[program, ...args2.slice(0, 2)].join(" ")} failed with exit code ${code}. ${hint}`.trim()
|
|
44051
|
+
}))), exports_Match.when("reported", () => exit3), exports_Match.when("silent", () => exports_Effect.ignore(exit3)), exports_Match.when("absent", () => exit3.pipe(exports_Effect.map((code) => gone.length === 0 ? code !== 0 : gone.includes(code)), exports_Effect.orElseSucceed(() => true), exports_Effect.filterOrFail((confirmed) => confirmed, () => new ScheduleError({ message: hint })))), exports_Match.exhaustive);
|
|
43187
44052
|
}
|
|
43188
|
-
|
|
44053
|
+
});
|
|
44054
|
+
});
|
|
44055
|
+
|
|
44056
|
+
// packages/cli/src/copilot.ts
|
|
44057
|
+
class CopilotError extends exports_Schema.TaggedError()("CopilotError", {
|
|
44058
|
+
message: exports_Schema.String
|
|
44059
|
+
}) {
|
|
44060
|
+
}
|
|
44061
|
+
var variable = "COPILOT_OTEL_FILE_EXPORTER_PATH";
|
|
44062
|
+
var marker = "# Added by token-ledger copilot enable: Copilot CLI records its usage here.";
|
|
44063
|
+
var affectedVersion = "1.139.1";
|
|
44064
|
+
var builds = [
|
|
44065
|
+
{ name: "VS Code", folder: "Code", file: "vscode-chat.jsonl" },
|
|
44066
|
+
{ name: "VS Code Insiders", folder: "Code - Insiders", file: "vscode-insiders-chat.jsonl" }
|
|
44067
|
+
];
|
|
44068
|
+
var placed = exports_Effect.fn("Copilot.placed")(function* (directory, file2) {
|
|
44069
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
44070
|
+
const path = yield* exports_Path.Path;
|
|
44071
|
+
const resolved = (folder) => fs.realPath(folder).pipe(exports_Effect.orElseSucceed(() => folder));
|
|
44072
|
+
const relative = path.relative(yield* resolved(directory), path.join(yield* resolved(path.dirname(file2)), path.basename(file2)));
|
|
44073
|
+
return relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative) ? exports_Option.some(relative) : exports_Option.none();
|
|
44074
|
+
});
|
|
44075
|
+
var copilotSources = exports_Effect.fn("Copilot.sources")(function* (directory, exporter) {
|
|
44076
|
+
if (exports_Option.isNone(exporter))
|
|
44077
|
+
return [directory];
|
|
44078
|
+
const relative = yield* placed(directory, exporter.value);
|
|
44079
|
+
if (exports_Option.isNone(relative))
|
|
44080
|
+
return [exporter.value];
|
|
44081
|
+
return /\.(?:jsonl|db)$/.test(relative.value) || relative.value === "" ? [directory] : [directory, exporter.value];
|
|
44082
|
+
});
|
|
44083
|
+
var Action4 = exports_Data.taggedEnum();
|
|
44084
|
+
var Step = exports_Data.taggedEnum();
|
|
44085
|
+
var indented = (text2, width2) => text2.replaceAll(/^(?=.)/gm, " ".repeat(width2));
|
|
44086
|
+
function assignedValue(assigned, home) {
|
|
44087
|
+
const text2 = assigned.trim();
|
|
44088
|
+
const single = /^'([^']*)'$/.exec(text2);
|
|
44089
|
+
if (single !== null)
|
|
44090
|
+
return exports_Option.fromUndefinedOr(single[1]);
|
|
44091
|
+
const double = /^"([^"\\`]*)"$/.exec(text2)?.[1];
|
|
44092
|
+
const bare = /^([^\s"'`\\;&|<>()#]+)$/.exec(text2)?.[1]?.replace(/^~(?=\/)/, () => home);
|
|
44093
|
+
const expanding = double ?? bare;
|
|
44094
|
+
if (expanding === undefined)
|
|
44095
|
+
return exports_Option.none();
|
|
44096
|
+
const expanded = expanding.replaceAll(/\$HOME\b|\$\{HOME\}/g, () => home);
|
|
44097
|
+
return expanded.includes("$") ? exports_Option.none() : exports_Option.some(expanded);
|
|
44098
|
+
}
|
|
44099
|
+
var touches = (line) => !/^\s*#/.test(line) && new RegExp(`(?<![$\\w{])${variable}\\b`).test(line);
|
|
44100
|
+
var StartupEdit = exports_Data.taggedEnum();
|
|
44101
|
+
var exportsTo = (target, home) => (line) => exports_Option.contains(exports_Option.flatMap(exports_Option.fromUndefinedOr(new RegExp(`^\\s*export\\s+${variable}=(.*)$`).exec(line)?.[1]), (assigned) => assignedValue(assigned, home)), target);
|
|
44102
|
+
function startupEdit(contents, wanted, satisfies) {
|
|
44103
|
+
const lines2 = contents.split(`
|
|
44104
|
+
`);
|
|
44105
|
+
const index2 = lines2.findLastIndex(touches);
|
|
44106
|
+
const current = lines2[index2];
|
|
44107
|
+
if (current === undefined) {
|
|
44108
|
+
const lead = contents === "" ? "" : contents.endsWith(`
|
|
44109
|
+
`) ? `
|
|
44110
|
+
` : `
|
|
44111
|
+
|
|
44112
|
+
`;
|
|
44113
|
+
return exports_Option.some(StartupEdit.Append({ text: `${lead}${marker}
|
|
44114
|
+
${wanted}
|
|
44115
|
+
` }));
|
|
44116
|
+
}
|
|
44117
|
+
if (current === wanted || satisfies(current))
|
|
44118
|
+
return exports_Option.none();
|
|
44119
|
+
return exports_Option.some(lines2[index2 - 1] === marker ? StartupEdit.Replace({ contents: lines2.with(index2, wanted).join(`
|
|
44120
|
+
`) }) : StartupEdit.Conflict({ line: index2 + 1, text: current.trim() }));
|
|
44121
|
+
}
|
|
44122
|
+
function homeWord(path, host, file2, quoted) {
|
|
44123
|
+
const relative = path.relative(host.home, file2);
|
|
44124
|
+
return /^(?!\.\.)[\w@+=:,./-]+$/.test(relative) && !path.isAbsolute(relative) ? `"$HOME/${relative}"` : quoted(file2);
|
|
44125
|
+
}
|
|
44126
|
+
var fishWord = (value5) => /^[\w@+=:,./-]+$/.test(value5) ? value5 : `'${value5.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'`;
|
|
44127
|
+
var readOptional = exports_Effect.fn("Copilot.readOptional")(function* (file2) {
|
|
44128
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
44129
|
+
return yield* fs.readFileString(file2).pipe(exports_Effect.map(exports_Option.some), exports_Effect.catchReason("PlatformError", "NotFound", () => exports_Effect.succeed(exports_Option.none())));
|
|
44130
|
+
});
|
|
44131
|
+
var bashStartup = exports_Effect.fn("Copilot.bashStartup")(function* (host) {
|
|
44132
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
44133
|
+
const path = yield* exports_Path.Path;
|
|
44134
|
+
if (host.platform !== "darwin")
|
|
44135
|
+
return path.join(host.home, ".bashrc");
|
|
44136
|
+
for (const name of [".bash_profile", ".bash_login", ".profile"]) {
|
|
44137
|
+
const file2 = path.join(host.home, name);
|
|
44138
|
+
if (yield* fs.exists(file2).pipe(exports_Effect.orElseSucceed(() => false)))
|
|
44139
|
+
return file2;
|
|
44140
|
+
}
|
|
44141
|
+
return path.join(host.home, ".bash_profile");
|
|
44142
|
+
});
|
|
44143
|
+
var startupSteps = exports_Effect.fn("Copilot.startupSteps")(function* (host, target) {
|
|
44144
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
44145
|
+
const path = yield* exports_Path.Path;
|
|
44146
|
+
const shell = exports_Option.match(host.shell, {
|
|
44147
|
+
onNone: () => "",
|
|
44148
|
+
onSome: (file3) => path.basename(file3)
|
|
44149
|
+
});
|
|
44150
|
+
const exported = `export ${variable}=${homeWord(path, host, target, posixWord)}`;
|
|
44151
|
+
const posix2 = (file3) => ({
|
|
44152
|
+
file: file3,
|
|
44153
|
+
line: exported,
|
|
44154
|
+
satisfies: exportsTo(target, host.home),
|
|
44155
|
+
others: []
|
|
44156
|
+
});
|
|
44157
|
+
const startup = yield* exports_Match.value(shell).pipe(exports_Match.when("zsh", () => exports_Effect.succeed(exports_Option.some(posix2(path.join(exports_Option.getOrElse(host.zshDirectory, () => host.home), ".zshrc"))))), exports_Match.when("bash", () => exports_Effect.map(bashStartup(host), (file3) => exports_Option.some(posix2(file3)))), exports_Match.when("fish", () => {
|
|
44158
|
+
const directory = path.join(exports_Option.getOrElse(host.configHome, () => path.join(host.home, ".config")), "fish");
|
|
44159
|
+
const line2 = `set -gx ${variable} ${homeWord(path, host, target, fishWord)}`;
|
|
44160
|
+
const snippets = path.join(directory, "conf.d");
|
|
44161
|
+
const file3 = path.join(snippets, "token-ledger-copilot.fish");
|
|
44162
|
+
return fs.readDirectory(snippets).pipe(exports_Effect.orElseSucceed(() => []), exports_Effect.map((names) => exports_Option.some({
|
|
44163
|
+
file: file3,
|
|
44164
|
+
line: line2,
|
|
44165
|
+
satisfies: (text2) => text2.trim() === line2,
|
|
44166
|
+
others: [
|
|
44167
|
+
...names.toSorted((a, b) => a.localeCompare(b)).flatMap((name) => name.endsWith(".fish") && path.join(snippets, name) !== file3 ? [path.join(snippets, name)] : []),
|
|
44168
|
+
path.join(directory, "config.fish")
|
|
44169
|
+
]
|
|
44170
|
+
})));
|
|
44171
|
+
}), exports_Match.orElse(() => exports_Effect.succeed(exports_Option.none())));
|
|
44172
|
+
if (exports_Option.isNone(startup))
|
|
44173
|
+
return [
|
|
44174
|
+
Step.ByHand({
|
|
44175
|
+
part: "cli",
|
|
44176
|
+
reason: shell === "" ? "SHELL is not set, so there is no startup file to choose." : `${shell} is not a shell this command sets up; it knows bash, zsh, and fish.`,
|
|
44177
|
+
instructions: `Add the equivalent of this line to your shell's startup file:
|
|
44178
|
+
${indented(exported, 4)}`
|
|
44179
|
+
})
|
|
44180
|
+
];
|
|
44181
|
+
const { file: file2, line, satisfies, others: others2 } = startup.value;
|
|
44182
|
+
const byHand = `Add this line to ${file2}:
|
|
44183
|
+
${indented(line, 4)}`;
|
|
44184
|
+
const conflict = (where, found) => Step.ByHand({
|
|
44185
|
+
part: "cli",
|
|
44186
|
+
reason: `${where}, and was left alone:
|
|
44187
|
+
${indented(found, 4)}`,
|
|
44188
|
+
instructions: `To record Copilot CLI usage where token-ledger reads it, change that line to:
|
|
44189
|
+
${indented(line, 4)}`
|
|
44190
|
+
});
|
|
44191
|
+
const read2 = yield* exports_Effect.all([
|
|
44192
|
+
readOptional(file2),
|
|
44193
|
+
exports_Effect.forEach(others2, (other) => exports_Effect.map(readOptional(other), (text2) => ({
|
|
44194
|
+
other,
|
|
44195
|
+
found: exports_Option.getOrElse(text2, () => "").split(`
|
|
44196
|
+
`).find(touches)
|
|
44197
|
+
})))
|
|
44198
|
+
]).pipe(exports_Effect.option);
|
|
44199
|
+
if (exports_Option.isNone(read2))
|
|
44200
|
+
return [Step.ByHand({ part: "cli", reason: `Cannot read ${file2}.`, instructions: byHand })];
|
|
44201
|
+
const [original, mentions] = read2.value;
|
|
44202
|
+
for (const { other, found } of mentions)
|
|
44203
|
+
if (found !== undefined)
|
|
44204
|
+
return [conflict(`${other} already sets ${variable}`, found.trim())];
|
|
44205
|
+
const existing = exports_Option.getOrElse(original, () => "");
|
|
44206
|
+
return [
|
|
44207
|
+
exports_Option.match(startupEdit(existing, line, satisfies), {
|
|
44208
|
+
onNone: () => Step.Kept({ part: "cli", summary: `${file2} already exports ${variable}.` }),
|
|
44209
|
+
onSome: StartupEdit.$match({
|
|
44210
|
+
Append: ({ text: text2 }) => Step.Change({
|
|
44211
|
+
part: "cli",
|
|
44212
|
+
summary: `${exports_Option.isSome(original) ? "add to the end of" : "create"} ${file2}`,
|
|
44213
|
+
detail: [marker, line],
|
|
44214
|
+
action: Action4.Write({ file: file2, contents: `${existing}${text2}`, original }),
|
|
44215
|
+
byHand
|
|
44216
|
+
}),
|
|
44217
|
+
Replace: ({ contents }) => Step.Change({
|
|
44218
|
+
part: "cli",
|
|
44219
|
+
summary: `correct the line this command added to ${file2}`,
|
|
44220
|
+
detail: [line],
|
|
44221
|
+
action: Action4.Write({ file: file2, contents, original }),
|
|
44222
|
+
byHand
|
|
44223
|
+
}),
|
|
44224
|
+
Conflict: ({ line: number4, text: text2 }) => conflict(`${file2} already sets ${variable} on line ${number4}`, text2)
|
|
44225
|
+
})
|
|
44226
|
+
})
|
|
44227
|
+
];
|
|
44228
|
+
});
|
|
44229
|
+
var userVariableSteps = exports_Effect.fn("Copilot.userVariableSteps")(function* (target) {
|
|
44230
|
+
const spawner = yield* exports_ChildProcessSpawner.ChildProcessSpawner;
|
|
44231
|
+
const assignment = `[Environment]::SetEnvironmentVariable(${powershellString(variable)}, ${powershellString(target)}, 'User')`;
|
|
44232
|
+
const byHand = `Run this in PowerShell:
|
|
44233
|
+
${indented(assignment, 4)}`;
|
|
44234
|
+
const current = yield* spawner.string(exports_ChildProcess.make("powershell.exe", powershellArguments(`[Console]::Out.Write('value=' + [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes([string][Environment]::GetEnvironmentVariable(${powershellString(variable)}, 'User'))))`), { stdin: "ignore", stderr: "ignore" })).pipe(exports_Effect.map((output) => /^value=([A-Za-z0-9+/=]*)\s*$/.exec(output)?.[1]), exports_Effect.map(exports_Option.fromUndefinedOr), exports_Effect.orElseSucceed(() => exports_Option.none()), exports_Effect.map(exports_Option.map((encoded) => Buffer.from(encoded, "base64").toString("utf8"))));
|
|
44235
|
+
if (exports_Option.isNone(current))
|
|
44236
|
+
return [
|
|
44237
|
+
Step.ByHand({
|
|
44238
|
+
part: "cli",
|
|
44239
|
+
reason: `Cannot read the user environment variable ${variable} through PowerShell.`,
|
|
44240
|
+
instructions: byHand
|
|
44241
|
+
})
|
|
44242
|
+
];
|
|
44243
|
+
const comparable = (file2) => file2.replaceAll("/", "\\").toLowerCase();
|
|
44244
|
+
return [
|
|
44245
|
+
comparable(current.value) === comparable(target) ? Step.Kept({
|
|
44246
|
+
part: "cli",
|
|
44247
|
+
summary: `The user environment variable ${variable} is already set.`
|
|
44248
|
+
}) : Step.Change({
|
|
44249
|
+
part: "cli",
|
|
44250
|
+
summary: `set the user environment variable ${variable}`,
|
|
44251
|
+
detail: [current.value === "" ? target : `${target} (now ${current.value})`],
|
|
44252
|
+
action: Action4.Run({
|
|
44253
|
+
program: "powershell.exe",
|
|
44254
|
+
args: powershellArguments([
|
|
44255
|
+
"$ErrorActionPreference = 'Stop'",
|
|
44256
|
+
"$ProgressPreference = 'SilentlyContinue'",
|
|
44257
|
+
assignment
|
|
44258
|
+
].join(`
|
|
44259
|
+
`))
|
|
44260
|
+
}),
|
|
44261
|
+
byHand
|
|
44262
|
+
})
|
|
44263
|
+
];
|
|
44264
|
+
});
|
|
44265
|
+
var installedVersion = exports_Effect.fn("Copilot.installedVersion")(function* (host) {
|
|
44266
|
+
const spawner = yield* exports_ChildProcessSpawner.ChildProcessSpawner;
|
|
44267
|
+
const commands = host.platform === "win32" ? [exports_ChildProcess.make("cmd.exe", ["/d", "/s", "/c", "code --version"])] : [
|
|
44268
|
+
"code",
|
|
44269
|
+
...host.platform === "darwin" ? ["/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code"] : []
|
|
44270
|
+
].map((program) => exports_ChildProcess.make(program, ["--version"]));
|
|
44271
|
+
for (const command of commands) {
|
|
44272
|
+
const version = yield* spawner.lines(command).pipe(exports_Effect.timeoutOption("5 seconds"), exports_Effect.map(exports_Option.flatMap((lines2) => exports_Option.fromUndefinedOr(lines2[0]))), exports_Effect.map(exports_Option.filter((line) => /^\d+\.\d+\.\d+$/.test(line))), exports_Effect.orElseSucceed(() => exports_Option.none()));
|
|
44273
|
+
if (exports_Option.isSome(version))
|
|
44274
|
+
return version;
|
|
44275
|
+
}
|
|
44276
|
+
return exports_Option.none();
|
|
44277
|
+
});
|
|
44278
|
+
var settingsSteps = exports_Effect.fn("Copilot.settingsSteps")(function* (host, directory) {
|
|
44279
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
44280
|
+
const path = yield* exports_Path.Path;
|
|
44281
|
+
const root = exports_Match.value(host.platform).pipe(exports_Match.when("win32", () => exports_Option.getOrElse(host.appData, () => path.join(host.home, "AppData", "Roaming"))), exports_Match.when("darwin", () => path.join(host.home, "Library", "Application Support")), exports_Match.orElse(() => exports_Option.getOrElse(host.configHome, () => path.join(host.home, ".config"))));
|
|
44282
|
+
const properties = (file2) => [
|
|
44283
|
+
["github.copilot.chat.otel.enabled", true],
|
|
44284
|
+
["github.copilot.chat.otel.exporterType", "file"],
|
|
44285
|
+
["github.copilot.chat.otel.outfile", path.join(directory, file2).replaceAll("\\", "/")],
|
|
44286
|
+
["github.copilot.chat.otel.captureContent", false]
|
|
44287
|
+
];
|
|
44288
|
+
const unsynced = [
|
|
44289
|
+
["settingsSync.ignoredSettings", "github.copilot.chat.otel.outfile"]
|
|
44290
|
+
];
|
|
44291
|
+
const unsyncing = unsynced.map(([key, item]) => `add ${JSON.stringify(item)} to the ${JSON.stringify(key)} list, so that Settings Sync does not copy this machine's path to your other machines`);
|
|
44292
|
+
const byHand = (lines2, lists) => [
|
|
44293
|
+
...lines2.length === 0 ? [] : [
|
|
44294
|
+
`In VS Code, run "Preferences: Open User Settings (JSON)" from the Command Palette; in a profile other than the default, run "Preferences: Open Application Settings (JSON)" instead, where settings shared by all profiles are kept. Give each of these settings the value shown: change its line if the setting is already there, and paste the others on a new line right after the opening {
|
|
44295
|
+
${indented(lines2.map((line) => `${line},`).join(`
|
|
44296
|
+
`), 4)}`
|
|
44297
|
+
],
|
|
44298
|
+
...lists.map((list) => `In the same file, ${list}.`)
|
|
44299
|
+
].join(`
|
|
44300
|
+
`);
|
|
44301
|
+
const every4 = (file2) => byHand(properties(file2).map(([key, value5]) => `${JSON.stringify(key)}: ${JSON.stringify(value5)}`), unsyncing);
|
|
44302
|
+
const steps = [];
|
|
44303
|
+
for (const build2 of builds) {
|
|
44304
|
+
const user = path.join(root, build2.folder, "User");
|
|
44305
|
+
const file2 = path.join(user, "settings.json");
|
|
44306
|
+
if (!(yield* fs.exists(user).pipe(exports_Effect.orElseSucceed(() => false))))
|
|
44307
|
+
continue;
|
|
44308
|
+
const original = yield* readOptional(file2).pipe(exports_Effect.option);
|
|
44309
|
+
if (exports_Option.isNone(original)) {
|
|
44310
|
+
steps.push(Step.ByHand({
|
|
44311
|
+
part: "vscode",
|
|
44312
|
+
reason: `Cannot read ${file2}.`,
|
|
44313
|
+
instructions: every4(build2.file)
|
|
44314
|
+
}));
|
|
44315
|
+
continue;
|
|
43189
44316
|
}
|
|
43190
|
-
|
|
44317
|
+
steps.push(exports_Option.match(setProperties(exports_Option.getOrElse(original.value, () => ""), properties(build2.file), unsynced), {
|
|
44318
|
+
onNone: () => Step.ByHand({
|
|
44319
|
+
part: "vscode",
|
|
44320
|
+
reason: `${file2} has a syntax error, repeats one of these settings, or holds one in a form this command does not expect, so it was left alone.`,
|
|
44321
|
+
instructions: `Repair it first: VS Code marks what is wrong, and a repeated setting should be there once. Then run this command again, or finish by hand.
|
|
44322
|
+
${every4(build2.file)}`
|
|
44323
|
+
}),
|
|
44324
|
+
onSome: ({ text: text2, changes: changes2, included }) => changes2.length === 0 && included.length === 0 ? Step.Kept({ part: "vscode", summary: `${file2} already has the export settings.` }) : Step.Change({
|
|
44325
|
+
part: "vscode",
|
|
44326
|
+
summary: `${exports_Option.isSome(original.value) ? "edit" : "create"} ${file2}`,
|
|
44327
|
+
detail: [
|
|
44328
|
+
...changes2.map(({ key, value: value5, previous }) => `${JSON.stringify(key)}: ${value5}${exports_Option.match(previous, {
|
|
44329
|
+
onNone: () => "",
|
|
44330
|
+
onSome: (was) => ` (now ${was})`
|
|
44331
|
+
})}`),
|
|
44332
|
+
...included.length === 0 ? [] : unsyncing
|
|
44333
|
+
],
|
|
44334
|
+
action: Action4.Write({ file: file2, contents: text2, original: original.value }),
|
|
44335
|
+
byHand: byHand(changes2.map(({ key, value: value5 }) => `${JSON.stringify(key)}: ${value5}`), included.length === 0 ? [] : unsyncing)
|
|
44336
|
+
})
|
|
44337
|
+
}));
|
|
43191
44338
|
}
|
|
43192
|
-
|
|
43193
|
-
|
|
43194
|
-
|
|
43195
|
-
|
|
43196
|
-
|
|
43197
|
-
|
|
44339
|
+
if (steps.length === 0)
|
|
44340
|
+
return [
|
|
44341
|
+
Step.ByHand({
|
|
44342
|
+
part: "vscode",
|
|
44343
|
+
reason: `No VS Code settings folder at ${path.join(root, builds[0].folder, "User")}.`,
|
|
44344
|
+
instructions: every4(builds[0].file)
|
|
44345
|
+
})
|
|
44346
|
+
];
|
|
44347
|
+
if (exports_Option.contains(yield* installedVersion(host), affectedVersion))
|
|
44348
|
+
steps.push(Step.Note({
|
|
44349
|
+
part: "vscode",
|
|
44350
|
+
text: `VS Code ${affectedVersion} is installed. Its file export leaves out the repository, so Chat usage is counted but stays Unassigned. Update VS Code, or see "Workaround for VS Code's file exporter bug" in the token-ledger README.`
|
|
44351
|
+
}));
|
|
44352
|
+
return steps;
|
|
44353
|
+
});
|
|
44354
|
+
var plan = exports_Effect.fn("Copilot.plan")(function* (host, wanted) {
|
|
44355
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
44356
|
+
const path = yield* exports_Path.Path;
|
|
44357
|
+
if (exports_Option.contains(host.uid, 0) && !wanted.allowRoot)
|
|
44358
|
+
return yield* new CopilotError({
|
|
44359
|
+
message: "Run this as yourself, without sudo. As root, the export folder, your shell startup file, and VS Code's settings would end up owned by root, and Copilot and VS Code could no longer write them. Nothing here needs admin rights. If root really is the account that runs Copilot, as in some containers, add --allow-root."
|
|
44360
|
+
});
|
|
44361
|
+
const directory = path.join(host.copilotHome, "otel");
|
|
44362
|
+
const target = path.join(directory, "usage.jsonl");
|
|
44363
|
+
const existing = yield* fs.stat(directory).pipe(exports_Effect.map((info2) => exports_Option.some(info2.type)), exports_Effect.orElseSucceed(() => exports_Option.none()));
|
|
44364
|
+
if (exports_Option.isSome(existing) && existing.value !== "Directory")
|
|
44365
|
+
return yield* new CopilotError({
|
|
44366
|
+
message: `${directory} exists but is not a folder, so Copilot cannot write its export there. Move it away, then run this again.`
|
|
44367
|
+
});
|
|
44368
|
+
for (const entry of [
|
|
44369
|
+
directory,
|
|
44370
|
+
...wanted.cli ? [target] : [],
|
|
44371
|
+
...wanted.vscode ? builds.map((build2) => path.join(directory, build2.file)) : []
|
|
44372
|
+
]) {
|
|
44373
|
+
const folder = yield* fs.stat(entry).pipe(exports_Effect.map((info2) => entry !== directory && info2.type === "Directory"), exports_Effect.orElseSucceed(() => false));
|
|
44374
|
+
if (folder)
|
|
44375
|
+
return yield* new CopilotError({
|
|
44376
|
+
message: `${entry} is a folder, so Copilot cannot write its export to that name. Move it away, then run this again.`
|
|
44377
|
+
});
|
|
44378
|
+
const locked = yield* fs.access(entry, { writable: true }).pipe(exports_Effect.as(false), exports_Effect.catchReason("PlatformError", "NotFound", () => exports_Effect.succeed(false)), exports_Effect.orElseSucceed(() => true));
|
|
44379
|
+
if (locked)
|
|
44380
|
+
return yield* new CopilotError({
|
|
44381
|
+
message: `Your account cannot write to ${entry}, so Copilot could not record its usage there. Give your account write access to it, then run this again.${host.platform === "win32" ? "" : ` If it was created with sudo, take it back with: sudo chown -R "$(id -un)" ${posixWord(directory)}`}`
|
|
44382
|
+
});
|
|
43198
44383
|
}
|
|
43199
|
-
|
|
43200
|
-
|
|
43201
|
-
|
|
43202
|
-
|
|
43203
|
-
}
|
|
43204
|
-
|
|
43205
|
-
|
|
43206
|
-
|
|
43207
|
-
|
|
43208
|
-
|
|
44384
|
+
const steps = [
|
|
44385
|
+
...exports_Option.isSome(existing) ? [] : [
|
|
44386
|
+
Step.Change({
|
|
44387
|
+
part: "folder",
|
|
44388
|
+
summary: `create the folder ${directory}`,
|
|
44389
|
+
detail: [],
|
|
44390
|
+
action: Action4.MakeDirectory({ directory }),
|
|
44391
|
+
byHand: ""
|
|
44392
|
+
})
|
|
44393
|
+
],
|
|
44394
|
+
...wanted.cli ? yield* host.platform === "win32" ? userVariableSteps(target) : startupSteps(host, target) : [],
|
|
44395
|
+
...wanted.vscode ? yield* settingsSteps(host, directory) : []
|
|
44396
|
+
];
|
|
44397
|
+
const elsewhere = exports_Option.isSome(host.exporter) ? exports_Option.match(yield* placed(directory, host.exporter.value), {
|
|
44398
|
+
onNone: () => host.exporter,
|
|
44399
|
+
onSome: () => exports_Option.none()
|
|
44400
|
+
}) : exports_Option.none();
|
|
44401
|
+
const settled = steps.some((step) => step.part === "cli" && (Step.$is("Change")(step) || Step.$is("Kept")(step)));
|
|
44402
|
+
return {
|
|
44403
|
+
directory,
|
|
44404
|
+
steps: exports_Option.match(elsewhere, {
|
|
44405
|
+
onNone: () => steps,
|
|
44406
|
+
onSome: (file2) => [
|
|
44407
|
+
...steps,
|
|
44408
|
+
Step.Note({
|
|
44409
|
+
part: "cli",
|
|
44410
|
+
text: `This terminal has ${variable} set to ${file2}, outside ${directory}. While it is, reports and syncs that see the variable read only that file and skip the exports in ${directory}, VS Code's among them. ${settled ? `Run them from a new terminal; if it still has that value, something else sets it, and should name ${target} instead.` : `Point it at ${target} to have both read.`}`
|
|
44411
|
+
})
|
|
44412
|
+
]
|
|
44413
|
+
})
|
|
44414
|
+
};
|
|
44415
|
+
});
|
|
44416
|
+
var entries3 = (steps, tag4, render) => steps.flatMap((step) => Step.$is(tag4)(step) ? [indented(render(step), 2)] : []);
|
|
44417
|
+
var leftByHand = (steps) => entries3(steps, "ByHand", ({ reason, instructions }) => `${reason}
|
|
44418
|
+
${instructions}`);
|
|
44419
|
+
var notes = (steps) => entries3(steps, "Note", ({ text: text2 }) => text2);
|
|
44420
|
+
var sections = (parts2) => parts2.flatMap(([title, lines2]) => lines2.length === 0 ? [] : [`${title}
|
|
44421
|
+
|
|
44422
|
+
${lines2.join(lines2.some((line) => line.includes(`
|
|
44423
|
+
`)) ? `
|
|
44424
|
+
|
|
44425
|
+
` : `
|
|
44426
|
+
`)}`]).join(`
|
|
44427
|
+
|
|
44428
|
+
`);
|
|
44429
|
+
var describe2 = (steps) => sections([
|
|
44430
|
+
[
|
|
44431
|
+
"Copilot records no usage until its local export is switched on. This will:",
|
|
44432
|
+
entries3(steps, "Change", ({ summary, detail }) => [summary, ...detail.map((line) => indented(line, 4))].join(`
|
|
44433
|
+
`))
|
|
44434
|
+
],
|
|
44435
|
+
["Already in place:", entries3(steps, "Kept", ({ summary }) => summary)],
|
|
44436
|
+
["Left for you to do by hand:", leftByHand(steps)],
|
|
44437
|
+
["Note:", notes(steps)]
|
|
44438
|
+
]);
|
|
44439
|
+
var replaceFile = exports_Effect.fn("Copilot.replaceFile")(function* (file2, contents) {
|
|
44440
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
44441
|
+
const path = yield* exports_Path.Path;
|
|
44442
|
+
yield* exports_Effect.gen(function* () {
|
|
44443
|
+
const target = yield* fs.realPath(file2).pipe(exports_Effect.catchReason("PlatformError", "NotFound", () => exports_Effect.matchEffect(fs.readLink(file2), {
|
|
44444
|
+
onFailure: () => exports_Effect.succeed(file2),
|
|
44445
|
+
onSuccess: (destination) => exports_Effect.fail(new CopilotError({
|
|
44446
|
+
message: `${file2} is a link to ${destination}, which does not exist, so it was left alone.`
|
|
44447
|
+
}))
|
|
44448
|
+
})));
|
|
44449
|
+
const mode = yield* fs.stat(target).pipe(exports_Effect.map((info2) => exports_Option.some(info2.mode & 4095)), exports_Effect.catchReason("PlatformError", "NotFound", () => exports_Effect.succeed(exports_Option.none())));
|
|
44450
|
+
yield* fs.makeDirectory(path.dirname(target), { recursive: true });
|
|
44451
|
+
const temporary = path.join(yield* fs.makeTempDirectoryScoped({
|
|
44452
|
+
directory: path.dirname(target),
|
|
44453
|
+
prefix: ".token-ledger-"
|
|
44454
|
+
}), path.basename(target));
|
|
44455
|
+
yield* fs.writeFileString(temporary, contents);
|
|
44456
|
+
if (exports_Option.isSome(mode))
|
|
44457
|
+
yield* fs.chmod(temporary, mode.value);
|
|
44458
|
+
yield* fs.rename(temporary, target);
|
|
44459
|
+
}).pipe(exports_Effect.scoped);
|
|
44460
|
+
});
|
|
44461
|
+
var perform2 = exports_Effect.fn("Copilot.perform")(function* (steps) {
|
|
44462
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
44463
|
+
const spawner = yield* exports_ChildProcessSpawner.ChildProcessSpawner;
|
|
44464
|
+
const results2 = [];
|
|
44465
|
+
for (const step of steps) {
|
|
44466
|
+
if (!Step.$is("Change")(step)) {
|
|
44467
|
+
results2.push(step);
|
|
44468
|
+
continue;
|
|
43209
44469
|
}
|
|
44470
|
+
const { part, summary, byHand } = step;
|
|
44471
|
+
const done4 = Step.Done({ part, summary });
|
|
44472
|
+
const failed = (reason) => Step.ByHand({ part, reason, instructions: byHand });
|
|
44473
|
+
results2.push(yield* Action4.$match(step.action, {
|
|
44474
|
+
MakeDirectory: ({ directory }) => fs.makeDirectory(directory, { recursive: true }).pipe(exports_Effect.as(done4), exports_Effect.mapError(() => new CopilotError({ message: `Cannot create ${directory}.` }))),
|
|
44475
|
+
Write: ({ file: file2, contents, original }) => exports_Effect.gen(function* () {
|
|
44476
|
+
if (exports_Option.getOrNull(yield* readOptional(file2)) !== exports_Option.getOrNull(original))
|
|
44477
|
+
return failed(`${file2} changed while this command was waiting. Run it again.`);
|
|
44478
|
+
yield* replaceFile(file2, contents);
|
|
44479
|
+
return done4;
|
|
44480
|
+
}).pipe(exports_Effect.catchTag("CopilotError", ({ message }) => exports_Effect.succeed(failed(message))), exports_Effect.orElseSucceed(() => failed(`Cannot write ${file2}.`))),
|
|
44481
|
+
Run: ({ program, args: args2 }) => spawner.exitCode(exports_ChildProcess.make(program, args2, {
|
|
44482
|
+
stdin: "ignore",
|
|
44483
|
+
stdout: "ignore",
|
|
44484
|
+
stderr: "inherit"
|
|
44485
|
+
})).pipe(exports_Effect.map((code) => code === 0 ? done4 : failed(`${program} could not ${summary}.`)), exports_Effect.orElseSucceed(() => failed(`Cannot run ${program}.`)))
|
|
44486
|
+
}));
|
|
43210
44487
|
}
|
|
43211
|
-
|
|
43212
|
-
|
|
43213
|
-
|
|
43214
|
-
|
|
43215
|
-
|
|
43216
|
-
|
|
43217
|
-
|
|
43218
|
-
|
|
43219
|
-
|
|
43220
|
-
|
|
43221
|
-
|
|
43222
|
-
|
|
43223
|
-
|
|
43224
|
-
|
|
43225
|
-
|
|
43226
|
-
|
|
43227
|
-
|
|
43228
|
-
|
|
43229
|
-
|
|
43230
|
-
|
|
43231
|
-
|
|
43232
|
-
|
|
43233
|
-
|
|
43234
|
-
|
|
43235
|
-
|
|
43236
|
-
|
|
43237
|
-
|
|
43238
|
-
|
|
43239
|
-
|
|
43240
|
-
|
|
43241
|
-
|
|
43242
|
-
|
|
43243
|
-
|
|
43244
|
-
}
|
|
43245
|
-
|
|
43246
|
-
|
|
43247
|
-
|
|
44488
|
+
return results2;
|
|
44489
|
+
});
|
|
44490
|
+
function summarize(steps, directory) {
|
|
44491
|
+
const changed = (part) => steps.some((step) => Step.$is("Done")(step) && step.part === part);
|
|
44492
|
+
const next2 = [
|
|
44493
|
+
...changed("cli") ? ["Copilot CLI: open a new terminal before you start copilot."] : [],
|
|
44494
|
+
...changed("vscode") ? [
|
|
44495
|
+
'VS Code: run "Developer: Reload Window" in each open window, or restart VS Code, then start a new chat.'
|
|
44496
|
+
] : []
|
|
44497
|
+
];
|
|
44498
|
+
return sections([
|
|
44499
|
+
["Done:", entries3(steps, "Done", ({ summary }) => summary)],
|
|
44500
|
+
["Left for you to do by hand:", leftByHand(steps)],
|
|
44501
|
+
["Note:", notes(steps)],
|
|
44502
|
+
[
|
|
44503
|
+
"Next:",
|
|
44504
|
+
next2.length === 0 ? [] : [
|
|
44505
|
+
...next2,
|
|
44506
|
+
`Usage is recorded in ${directory} from then on; earlier sessions cannot be recovered.`,
|
|
44507
|
+
"Check it with: token-ledger report --provider copilot"
|
|
44508
|
+
].map((line) => indented(line, 2))
|
|
44509
|
+
]
|
|
44510
|
+
]);
|
|
44511
|
+
}
|
|
44512
|
+
|
|
44513
|
+
// packages/cli/src/format.ts
|
|
44514
|
+
import { styleText } from "node:util";
|
|
44515
|
+
var import_cli_table3 = __toESM(require_table(), 1);
|
|
44516
|
+
|
|
44517
|
+
// node_modules/.bun/ansi-regex@6.3.0/node_modules/ansi-regex/index.js
|
|
44518
|
+
function ansiRegex({ onlyFirst = false } = {}) {
|
|
44519
|
+
const ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
|
|
44520
|
+
const osc = `(?:\\u001B\\][^\\u0007\\u001B\\u009C]*${ST})`;
|
|
44521
|
+
const csi = "[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]";
|
|
44522
|
+
const pattern = `${osc}|${csi}`;
|
|
44523
|
+
return new RegExp(pattern, onlyFirst ? undefined : "g");
|
|
44524
|
+
}
|
|
44525
|
+
|
|
44526
|
+
// node_modules/.bun/strip-ansi@7.2.0/node_modules/strip-ansi/index.js
|
|
44527
|
+
var regex = ansiRegex();
|
|
44528
|
+
function stripAnsi2(string4) {
|
|
44529
|
+
if (typeof string4 !== "string") {
|
|
44530
|
+
throw new TypeError(`Expected a \`string\`, got \`${typeof string4}\``);
|
|
43248
44531
|
}
|
|
43249
|
-
if (
|
|
43250
|
-
|
|
43251
|
-
return true;
|
|
44532
|
+
if (!string4.includes("\x1B") && !string4.includes("")) {
|
|
44533
|
+
return string4;
|
|
43252
44534
|
}
|
|
43253
|
-
|
|
43254
|
-
|
|
43255
|
-
|
|
44535
|
+
return string4.replace(regex, "");
|
|
44536
|
+
}
|
|
44537
|
+
|
|
44538
|
+
// node_modules/.bun/get-east-asian-width@1.7.0/node_modules/get-east-asian-width/lookup-data.js
|
|
44539
|
+
var ambiguousMinimalCodePoint = 161;
|
|
44540
|
+
var ambiguousMaximumCodePoint = 1114109;
|
|
44541
|
+
var ambiguousRanges = [161, 161, 164, 164, 167, 168, 170, 170, 173, 174, 176, 180, 182, 186, 188, 191, 198, 198, 208, 208, 215, 216, 222, 225, 230, 230, 232, 234, 236, 237, 240, 240, 242, 243, 247, 250, 252, 252, 254, 254, 257, 257, 273, 273, 275, 275, 283, 283, 294, 295, 299, 299, 305, 307, 312, 312, 319, 322, 324, 324, 328, 331, 333, 333, 338, 339, 358, 359, 363, 363, 462, 462, 464, 464, 466, 466, 468, 468, 470, 470, 472, 472, 474, 474, 476, 476, 593, 593, 609, 609, 708, 708, 711, 711, 713, 715, 717, 717, 720, 720, 728, 731, 733, 733, 735, 735, 768, 879, 913, 929, 931, 937, 945, 961, 963, 969, 1025, 1025, 1040, 1103, 1105, 1105, 8208, 8208, 8211, 8214, 8216, 8217, 8220, 8221, 8224, 8226, 8228, 8231, 8240, 8240, 8242, 8243, 8245, 8245, 8251, 8251, 8254, 8254, 8308, 8308, 8319, 8319, 8321, 8324, 8364, 8364, 8451, 8451, 8453, 8453, 8457, 8457, 8467, 8467, 8470, 8470, 8481, 8482, 8486, 8486, 8491, 8491, 8531, 8532, 8539, 8542, 8544, 8555, 8560, 8569, 8585, 8585, 8592, 8601, 8632, 8633, 8658, 8658, 8660, 8660, 8679, 8679, 8704, 8704, 8706, 8707, 8711, 8712, 8715, 8715, 8719, 8719, 8721, 8721, 8725, 8725, 8730, 8730, 8733, 8736, 8739, 8739, 8741, 8741, 8743, 8748, 8750, 8750, 8756, 8759, 8764, 8765, 8776, 8776, 8780, 8780, 8786, 8786, 8800, 8801, 8804, 8807, 8810, 8811, 8814, 8815, 8834, 8835, 8838, 8839, 8853, 8853, 8857, 8857, 8869, 8869, 8895, 8895, 8978, 8978, 9312, 9449, 9451, 9547, 9552, 9587, 9600, 9615, 9618, 9621, 9632, 9633, 9635, 9641, 9650, 9651, 9654, 9655, 9660, 9661, 9664, 9665, 9670, 9672, 9675, 9675, 9678, 9681, 9698, 9701, 9711, 9711, 9733, 9734, 9737, 9737, 9742, 9743, 9756, 9756, 9758, 9758, 9792, 9792, 9794, 9794, 9824, 9825, 9827, 9829, 9831, 9834, 9836, 9837, 9839, 9839, 9886, 9887, 9919, 9919, 9926, 9933, 9935, 9939, 9941, 9953, 9955, 9955, 9960, 9961, 9963, 9969, 9972, 9972, 9974, 9977, 9979, 9980, 9982, 9983, 10045, 10045, 10102, 10111, 11094, 11097, 12872, 12879, 57344, 63743, 65024, 65039, 65533, 65533, 127232, 127242, 127248, 127277, 127280, 127337, 127344, 127373, 127375, 127376, 127387, 127404, 917760, 917999, 983040, 1048573, 1048576, 1114109];
|
|
44542
|
+
var fullwidthMinimalCodePoint = 12288;
|
|
44543
|
+
var fullwidthMaximumCodePoint = 65510;
|
|
44544
|
+
var fullwidthRanges = [12288, 12288, 65281, 65376, 65504, 65510];
|
|
44545
|
+
var wideMinimalCodePoint = 4352;
|
|
44546
|
+
var wideMaximumCodePoint = 262141;
|
|
44547
|
+
var wideRanges = [4352, 4447, 8986, 8987, 9001, 9002, 9193, 9196, 9200, 9200, 9203, 9203, 9725, 9726, 9748, 9749, 9776, 9783, 9800, 9811, 9855, 9855, 9866, 9871, 9875, 9875, 9889, 9889, 9898, 9899, 9917, 9918, 9924, 9925, 9934, 9934, 9940, 9940, 9962, 9962, 9970, 9971, 9973, 9973, 9978, 9978, 9981, 9981, 9989, 9989, 9994, 9995, 10024, 10024, 10060, 10060, 10062, 10062, 10067, 10069, 10071, 10071, 10133, 10135, 10160, 10160, 10175, 10175, 11035, 11036, 11088, 11088, 11093, 11093, 11904, 11929, 11931, 12019, 12032, 12245, 12272, 12287, 12289, 12350, 12353, 12438, 12441, 12543, 12549, 12591, 12593, 12686, 12688, 12773, 12783, 12830, 12832, 12871, 12880, 42124, 42128, 42182, 43360, 43388, 44032, 55203, 63744, 64255, 65040, 65049, 65072, 65106, 65108, 65126, 65128, 65131, 94176, 94180, 94192, 94198, 94208, 101594, 101631, 101664, 101760, 101874, 101888, 102801, 102816, 102866, 110576, 110579, 110581, 110587, 110589, 110590, 110592, 110888, 110898, 110898, 110928, 110930, 110933, 110933, 110948, 110952, 110960, 111355, 119552, 119638, 119648, 119670, 126980, 126980, 127183, 127183, 127374, 127374, 127377, 127386, 127406, 127406, 127488, 127490, 127504, 127547, 127552, 127560, 127568, 127569, 127584, 127589, 127744, 127776, 127789, 127797, 127799, 127868, 127870, 127891, 127904, 127946, 127951, 127955, 127968, 127984, 127988, 127988, 127992, 128062, 128064, 128064, 128066, 128252, 128255, 128317, 128331, 128334, 128336, 128359, 128378, 128378, 128405, 128406, 128420, 128420, 128507, 128591, 128640, 128709, 128716, 128716, 128720, 128722, 128725, 128729, 128732, 128735, 128747, 128748, 128756, 128764, 128986, 128986, 128992, 129003, 129008, 129008, 129292, 129338, 129340, 129349, 129351, 129535, 129648, 129660, 129664, 129734, 129736, 129736, 129740, 129757, 129759, 129771, 129775, 129786, 131072, 196605, 196608, 262141];
|
|
44548
|
+
|
|
44549
|
+
// node_modules/.bun/get-east-asian-width@1.7.0/node_modules/get-east-asian-width/utilities.js
|
|
44550
|
+
var isInRange = (ranges, codePoint) => {
|
|
44551
|
+
let low = 0;
|
|
44552
|
+
let high = Math.floor(ranges.length / 2) - 1;
|
|
44553
|
+
while (low <= high) {
|
|
44554
|
+
const mid = Math.floor((low + high) / 2);
|
|
44555
|
+
const i = mid * 2;
|
|
44556
|
+
if (codePoint < ranges[i]) {
|
|
44557
|
+
high = mid - 1;
|
|
44558
|
+
} else if (codePoint > ranges[i + 1]) {
|
|
44559
|
+
low = mid + 1;
|
|
44560
|
+
} else {
|
|
44561
|
+
return true;
|
|
44562
|
+
}
|
|
43256
44563
|
}
|
|
43257
44564
|
return false;
|
|
43258
44565
|
};
|
|
43259
|
-
|
|
43260
|
-
|
|
43261
|
-
|
|
43262
|
-
|
|
43263
|
-
|
|
43264
|
-
|
|
43265
|
-
|
|
43266
|
-
|
|
43267
|
-
|
|
44566
|
+
|
|
44567
|
+
// node_modules/.bun/get-east-asian-width@1.7.0/node_modules/get-east-asian-width/lookup.js
|
|
44568
|
+
var commonCjkCodePoint = 19968;
|
|
44569
|
+
var [wideFastPathStart, wideFastPathEnd] = /* @__PURE__ */ findWideFastPathRange(wideRanges);
|
|
44570
|
+
function findWideFastPathRange(ranges) {
|
|
44571
|
+
let fastPathStart = ranges[0];
|
|
44572
|
+
let fastPathEnd = ranges[1];
|
|
44573
|
+
for (let index2 = 0;index2 < ranges.length; index2 += 2) {
|
|
44574
|
+
const start = ranges[index2];
|
|
44575
|
+
const end3 = ranges[index2 + 1];
|
|
44576
|
+
if (commonCjkCodePoint >= start && commonCjkCodePoint <= end3) {
|
|
44577
|
+
return [start, end3];
|
|
44578
|
+
}
|
|
44579
|
+
if (end3 - start > fastPathEnd - fastPathStart) {
|
|
44580
|
+
fastPathStart = start;
|
|
44581
|
+
fastPathEnd = end3;
|
|
44582
|
+
}
|
|
43268
44583
|
}
|
|
43269
|
-
|
|
43270
|
-
|
|
43271
|
-
|
|
43272
|
-
|
|
43273
|
-
|
|
43274
|
-
close: close3
|
|
43275
|
-
});
|
|
44584
|
+
return [fastPathStart, fastPathEnd];
|
|
44585
|
+
}
|
|
44586
|
+
var isAmbiguous = (codePoint) => {
|
|
44587
|
+
if (codePoint < ambiguousMinimalCodePoint || codePoint > ambiguousMaximumCodePoint) {
|
|
44588
|
+
return false;
|
|
43276
44589
|
}
|
|
44590
|
+
return isInRange(ambiguousRanges, codePoint);
|
|
43277
44591
|
};
|
|
43278
|
-
var
|
|
43279
|
-
|
|
43280
|
-
|
|
44592
|
+
var isFullwidth = (codePoint) => {
|
|
44593
|
+
if (codePoint < fullwidthMinimalCodePoint || codePoint > fullwidthMaximumCodePoint) {
|
|
44594
|
+
return false;
|
|
43281
44595
|
}
|
|
44596
|
+
return isInRange(fullwidthRanges, codePoint);
|
|
43282
44597
|
};
|
|
43283
|
-
var
|
|
43284
|
-
|
|
43285
|
-
|
|
44598
|
+
var isWide = (codePoint) => {
|
|
44599
|
+
if (codePoint >= wideFastPathStart && codePoint <= wideFastPathEnd) {
|
|
44600
|
+
return true;
|
|
43286
44601
|
}
|
|
43287
|
-
|
|
43288
|
-
|
|
43289
|
-
let index2 = startIndex;
|
|
43290
|
-
while (index2 < string4.length) {
|
|
43291
|
-
const match10 = matchAnsiEscape(string4, index2);
|
|
43292
|
-
if (!match10) {
|
|
43293
|
-
break;
|
|
43294
|
-
}
|
|
43295
|
-
if (match10.groups.sgr !== undefined) {
|
|
43296
|
-
applySgrResets(match10.groups.sgr, activeStyles);
|
|
43297
|
-
}
|
|
43298
|
-
index2 += match10[0].length;
|
|
44602
|
+
if (codePoint < wideMinimalCodePoint || codePoint > wideMaximumCodePoint) {
|
|
44603
|
+
return false;
|
|
43299
44604
|
}
|
|
44605
|
+
return isInRange(wideRanges, codePoint);
|
|
43300
44606
|
};
|
|
43301
|
-
|
|
43302
|
-
|
|
43303
|
-
|
|
43304
|
-
|
|
43305
|
-
|
|
43306
|
-
|
|
43307
|
-
|
|
43308
|
-
|
|
43309
|
-
|
|
43310
|
-
|
|
43311
|
-
|
|
43312
|
-
|
|
43313
|
-
|
|
43314
|
-
|
|
43315
|
-
|
|
43316
|
-
|
|
43317
|
-
|
|
44607
|
+
|
|
44608
|
+
// node_modules/.bun/get-east-asian-width@1.7.0/node_modules/get-east-asian-width/index.js
|
|
44609
|
+
function validate3(codePoint) {
|
|
44610
|
+
if (!Number.isSafeInteger(codePoint)) {
|
|
44611
|
+
throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
|
|
44612
|
+
}
|
|
44613
|
+
}
|
|
44614
|
+
function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
|
|
44615
|
+
validate3(codePoint);
|
|
44616
|
+
if (isFullwidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) {
|
|
44617
|
+
return 2;
|
|
44618
|
+
}
|
|
44619
|
+
return 1;
|
|
44620
|
+
}
|
|
44621
|
+
|
|
44622
|
+
// node_modules/.bun/string-width@8.2.2/node_modules/string-width/index.js
|
|
44623
|
+
var segmenter = new Intl.Segmenter;
|
|
44624
|
+
var zeroWidthClusterRegex = /^(?:\p{Default_Ignorable_Code_Point}|\p{Control}|\p{Format}|\p{Nonspacing_Mark}|\p{Enclosing_Mark}|\p{Surrogate})+$/v;
|
|
44625
|
+
var leadingNonPrintingRegex = /^[\p{Default_Ignorable_Code_Point}\p{Control}\p{Format}\p{Nonspacing_Mark}\p{Enclosing_Mark}\p{Surrogate}]+/v;
|
|
44626
|
+
var spacingMarkRegex = /\p{Spacing_Mark}/v;
|
|
44627
|
+
var rgiEmojiRegex = /^\p{RGI_Emoji}$/v;
|
|
44628
|
+
var unqualifiedKeycapRegex = /^[\d#*]\u20E3$/;
|
|
44629
|
+
var extendedPictographicRegex = /\p{Extended_Pictographic}/gu;
|
|
44630
|
+
function isDoubleWidthNonRgiEmojiSequence(segment) {
|
|
44631
|
+
if (segment.length > 50) {
|
|
44632
|
+
return false;
|
|
43318
44633
|
}
|
|
43319
|
-
if (
|
|
43320
|
-
|
|
44634
|
+
if (unqualifiedKeycapRegex.test(segment)) {
|
|
44635
|
+
return true;
|
|
43321
44636
|
}
|
|
43322
|
-
|
|
43323
|
-
|
|
43324
|
-
|
|
43325
|
-
if (!string4.includes(" ")) {
|
|
43326
|
-
return string4;
|
|
44637
|
+
if (segment.includes("")) {
|
|
44638
|
+
const pictographics = segment.match(extendedPictographicRegex);
|
|
44639
|
+
return pictographics !== null && pictographics.length >= 2;
|
|
43327
44640
|
}
|
|
43328
|
-
|
|
43329
|
-
|
|
43330
|
-
|
|
43331
|
-
|
|
43332
|
-
|
|
43333
|
-
|
|
43334
|
-
|
|
43335
|
-
|
|
43336
|
-
|
|
44641
|
+
return false;
|
|
44642
|
+
}
|
|
44643
|
+
function baseVisible(segment) {
|
|
44644
|
+
return segment.replace(leadingNonPrintingRegex, "");
|
|
44645
|
+
}
|
|
44646
|
+
function isZeroWidthCluster(segment) {
|
|
44647
|
+
return zeroWidthClusterRegex.test(segment);
|
|
44648
|
+
}
|
|
44649
|
+
function isHangulLeadingJamo(codePoint) {
|
|
44650
|
+
return codePoint >= 4352 && codePoint <= 4447 || codePoint >= 43360 && codePoint <= 43388;
|
|
44651
|
+
}
|
|
44652
|
+
function isHangulVowelJamo(codePoint) {
|
|
44653
|
+
return codePoint >= 4448 && codePoint <= 4519 || codePoint >= 55216 && codePoint <= 55238;
|
|
44654
|
+
}
|
|
44655
|
+
function isHangulTrailingJamo(codePoint) {
|
|
44656
|
+
return codePoint >= 4520 && codePoint <= 4607 || codePoint >= 55243 && codePoint <= 55291;
|
|
44657
|
+
}
|
|
44658
|
+
function isHangulJamo(codePoint) {
|
|
44659
|
+
return isHangulLeadingJamo(codePoint) || isHangulVowelJamo(codePoint) || isHangulTrailingJamo(codePoint);
|
|
44660
|
+
}
|
|
44661
|
+
function hangulClusterWidth(visibleSegment, eastAsianWidthOptions) {
|
|
44662
|
+
const codePoints = [];
|
|
44663
|
+
for (const character of visibleSegment) {
|
|
44664
|
+
if (zeroWidthClusterRegex.test(character)) {
|
|
43337
44665
|
continue;
|
|
43338
44666
|
}
|
|
43339
|
-
|
|
43340
|
-
while (end3 > 0 && segment.value[end3 - 1] === " ") {
|
|
43341
|
-
end3--;
|
|
43342
|
-
}
|
|
43343
|
-
segment.value = segment.value.slice(0, end3);
|
|
43344
|
-
if (getStringWidth(segment.value) > 0) {
|
|
43345
|
-
break;
|
|
43346
|
-
}
|
|
44667
|
+
codePoints.push(character.codePointAt(0));
|
|
43347
44668
|
}
|
|
43348
|
-
|
|
43349
|
-
|
|
43350
|
-
var expandTabs = (line) => {
|
|
43351
|
-
if (!line.includes("\t")) {
|
|
43352
|
-
return line;
|
|
44669
|
+
if (codePoints.length === 0) {
|
|
44670
|
+
return;
|
|
43353
44671
|
}
|
|
43354
|
-
let
|
|
43355
|
-
let
|
|
43356
|
-
|
|
43357
|
-
|
|
43358
|
-
|
|
43359
|
-
|
|
43360
|
-
expandedLine += segment;
|
|
43361
|
-
plainTextSinceTab += segment;
|
|
43362
|
-
if (index2 < segments.length - 1) {
|
|
43363
|
-
visible += getStringWidth(plainTextSinceTab);
|
|
43364
|
-
plainTextSinceTab = "";
|
|
43365
|
-
const spaces = TAB_SIZE - visible % TAB_SIZE;
|
|
43366
|
-
expandedLine += " ".repeat(spaces);
|
|
43367
|
-
visible += spaces;
|
|
43368
|
-
}
|
|
43369
|
-
}
|
|
43370
|
-
};
|
|
43371
|
-
forEachSegment(line, expandPlainText, (escape2) => {
|
|
43372
|
-
expandedLine += escape2;
|
|
43373
|
-
});
|
|
43374
|
-
return expandedLine;
|
|
43375
|
-
};
|
|
43376
|
-
var restoreStylesAcrossRows = (preString) => {
|
|
43377
|
-
let returnValue = "";
|
|
43378
|
-
let activeHyperlink;
|
|
43379
|
-
const activeStyles = [];
|
|
43380
|
-
let index2 = 0;
|
|
43381
|
-
let copiedIndex = 0;
|
|
43382
|
-
while (index2 < preString.length) {
|
|
43383
|
-
ROW_BOUNDARY_REGEX.lastIndex = index2;
|
|
43384
|
-
const boundary = ROW_BOUNDARY_REGEX.exec(preString);
|
|
43385
|
-
if (!boundary) {
|
|
43386
|
-
break;
|
|
43387
|
-
}
|
|
43388
|
-
index2 = boundary.index;
|
|
43389
|
-
if (boundary[0] !== `
|
|
43390
|
-
`) {
|
|
43391
|
-
const escape2 = matchAnsiEscape(preString, index2);
|
|
43392
|
-
if (!escape2) {
|
|
43393
|
-
index2++;
|
|
43394
|
-
continue;
|
|
44672
|
+
let width2 = 0;
|
|
44673
|
+
for (let index2 = 0;index2 < codePoints.length; index2++) {
|
|
44674
|
+
const codePoint = codePoints[index2];
|
|
44675
|
+
if (!isHangulJamo(codePoint)) {
|
|
44676
|
+
if (width2 === 0) {
|
|
44677
|
+
return;
|
|
43395
44678
|
}
|
|
43396
|
-
|
|
43397
|
-
|
|
43398
|
-
applySgrParameters(groups.sgr, activeStyles);
|
|
43399
|
-
} else if (groups.uri !== undefined) {
|
|
43400
|
-
activeHyperlink = groups.uri.length === 0 ? undefined : { parameters: groups.parameters, uri: groups.uri };
|
|
44679
|
+
for (let remaining = index2;remaining < codePoints.length; remaining++) {
|
|
44680
|
+
width2 += eastAsianWidth(codePoints[remaining], eastAsianWidthOptions);
|
|
43401
44681
|
}
|
|
43402
|
-
|
|
44682
|
+
return width2;
|
|
44683
|
+
}
|
|
44684
|
+
if (isHangulLeadingJamo(codePoint) && isHangulVowelJamo(codePoints[index2 + 1])) {
|
|
44685
|
+
width2 += 2;
|
|
44686
|
+
index2 += isHangulTrailingJamo(codePoints[index2 + 2]) ? 2 : 1;
|
|
43403
44687
|
continue;
|
|
43404
44688
|
}
|
|
43405
|
-
|
|
43406
|
-
|
|
43407
|
-
|
|
43408
|
-
|
|
43409
|
-
|
|
43410
|
-
|
|
44689
|
+
width2 += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
44690
|
+
}
|
|
44691
|
+
return width2;
|
|
44692
|
+
}
|
|
44693
|
+
function trailingWidth(visibleSegment, eastAsianWidthOptions) {
|
|
44694
|
+
let extra = 0;
|
|
44695
|
+
let first = true;
|
|
44696
|
+
for (const character of visibleSegment) {
|
|
44697
|
+
if (first) {
|
|
44698
|
+
first = false;
|
|
44699
|
+
continue;
|
|
43411
44700
|
}
|
|
43412
|
-
|
|
43413
|
-
|
|
43414
|
-
index2++;
|
|
43415
|
-
copiedIndex = index2;
|
|
43416
|
-
if (index2 < preString.length && preString[index2] !== `
|
|
43417
|
-
`) {
|
|
43418
|
-
const openingStyles = [...activeStyles];
|
|
43419
|
-
applyLeadingSgrResets(preString, index2, openingStyles);
|
|
43420
|
-
returnValue += getOpeningSgrSequence(openingStyles);
|
|
43421
|
-
if (activeHyperlink) {
|
|
43422
|
-
returnValue += wrapAnsiHyperlink(activeHyperlink.uri, activeHyperlink.parameters);
|
|
43423
|
-
}
|
|
44701
|
+
if (spacingMarkRegex.test(character) || character >= "" && character <= "") {
|
|
44702
|
+
extra += eastAsianWidth(character.codePointAt(0), eastAsianWidthOptions);
|
|
43424
44703
|
}
|
|
43425
44704
|
}
|
|
43426
|
-
return
|
|
43427
|
-
}
|
|
43428
|
-
|
|
43429
|
-
if (
|
|
43430
|
-
return
|
|
44705
|
+
return extra;
|
|
44706
|
+
}
|
|
44707
|
+
function stringWidth(input, options3 = {}) {
|
|
44708
|
+
if (typeof input !== "string" || input.length === 0) {
|
|
44709
|
+
return 0;
|
|
43431
44710
|
}
|
|
43432
|
-
const
|
|
43433
|
-
|
|
43434
|
-
|
|
43435
|
-
|
|
43436
|
-
let
|
|
43437
|
-
|
|
43438
|
-
|
|
43439
|
-
|
|
43440
|
-
|
|
43441
|
-
|
|
43442
|
-
|
|
43443
|
-
|
|
43444
|
-
|
|
43445
|
-
|
|
43446
|
-
|
|
43447
|
-
|
|
43448
|
-
|
|
43449
|
-
|
|
43450
|
-
if (isFirstWord) {
|
|
43451
|
-
isFirstWord = false;
|
|
43452
|
-
} else {
|
|
43453
|
-
if (rowLength >= columns && (options3.wordWrap === false || options3.trim === false)) {
|
|
43454
|
-
rows.push("");
|
|
43455
|
-
rowLength = 0;
|
|
43456
|
-
}
|
|
43457
|
-
if (rowLength > 0 || options3.trim === false) {
|
|
43458
|
-
rows[rows.length - 1] += " ";
|
|
43459
|
-
rowLength++;
|
|
43460
|
-
}
|
|
43461
|
-
}
|
|
43462
|
-
if (options3.hard && options3.wordWrap !== false && word.width > columns) {
|
|
43463
|
-
const remainingColumns = columns - rowLength;
|
|
43464
|
-
const breaksStartingThisLine = 1 + Math.floor((word.width - remainingColumns - 1) / columns);
|
|
43465
|
-
const breaksStartingNextLine = Math.floor((word.width - 1) / columns);
|
|
43466
|
-
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
43467
|
-
rows.push("");
|
|
43468
|
-
rowLength = 0;
|
|
43469
|
-
}
|
|
43470
|
-
rowLength = wrapWord(rows, word.value, columns, rowLength);
|
|
44711
|
+
const {
|
|
44712
|
+
ambiguousIsNarrow = true,
|
|
44713
|
+
countAnsiEscapeCodes = false
|
|
44714
|
+
} = options3;
|
|
44715
|
+
let string4 = input;
|
|
44716
|
+
if (!countAnsiEscapeCodes && (string4.includes("\x1B") || string4.includes(""))) {
|
|
44717
|
+
string4 = stripAnsi2(string4);
|
|
44718
|
+
}
|
|
44719
|
+
if (string4.length === 0) {
|
|
44720
|
+
return 0;
|
|
44721
|
+
}
|
|
44722
|
+
if (/^[\u0020-\u007E]*$/.test(string4)) {
|
|
44723
|
+
return string4.length;
|
|
44724
|
+
}
|
|
44725
|
+
let width2 = 0;
|
|
44726
|
+
const eastAsianWidthOptions = { ambiguousAsWide: !ambiguousIsNarrow };
|
|
44727
|
+
for (const { segment } of segmenter.segment(string4)) {
|
|
44728
|
+
if (isZeroWidthCluster(segment)) {
|
|
43471
44729
|
continue;
|
|
43472
44730
|
}
|
|
43473
|
-
if (
|
|
43474
|
-
|
|
43475
|
-
|
|
43476
|
-
continue;
|
|
43477
|
-
}
|
|
43478
|
-
rows.push("");
|
|
43479
|
-
rowLength = 0;
|
|
44731
|
+
if (rgiEmojiRegex.test(segment) || isDoubleWidthNonRgiEmojiSequence(segment)) {
|
|
44732
|
+
width2 += 2;
|
|
44733
|
+
continue;
|
|
43480
44734
|
}
|
|
43481
|
-
|
|
43482
|
-
|
|
44735
|
+
const visibleSegment = baseVisible(segment);
|
|
44736
|
+
const hangulWidth = hangulClusterWidth(visibleSegment, eastAsianWidthOptions);
|
|
44737
|
+
if (hangulWidth !== undefined) {
|
|
44738
|
+
width2 += hangulWidth;
|
|
43483
44739
|
continue;
|
|
43484
44740
|
}
|
|
43485
|
-
|
|
43486
|
-
|
|
43487
|
-
|
|
43488
|
-
if (options3.trim !== false) {
|
|
43489
|
-
rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
|
|
44741
|
+
const codePoint = visibleSegment.codePointAt(0);
|
|
44742
|
+
width2 += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
44743
|
+
width2 += trailingWidth(visibleSegment, eastAsianWidthOptions);
|
|
43490
44744
|
}
|
|
43491
|
-
return
|
|
43492
|
-
`));
|
|
43493
|
-
};
|
|
43494
|
-
var normalizeText = (string4) => {
|
|
43495
|
-
let normalizedString = "";
|
|
43496
|
-
forEachSegment(string4, (plainText) => {
|
|
43497
|
-
normalizedString += plainText.normalize();
|
|
43498
|
-
}, (escape2) => {
|
|
43499
|
-
normalizedString += escape2;
|
|
43500
|
-
});
|
|
43501
|
-
return normalizedString;
|
|
43502
|
-
};
|
|
43503
|
-
function wrapAnsi(string4, columns, options3) {
|
|
43504
|
-
return normalizeText(String(string4)).replaceAll(`\r
|
|
43505
|
-
`, `
|
|
43506
|
-
`).split(`
|
|
43507
|
-
`).map((line) => exec(expandTabs(line), columns, options3)).join(`
|
|
43508
|
-
`);
|
|
44745
|
+
return width2;
|
|
43509
44746
|
}
|
|
43510
44747
|
|
|
43511
|
-
//
|
|
43512
|
-
|
|
43513
|
-
|
|
43514
|
-
|
|
43515
|
-
|
|
43516
|
-
|
|
43517
|
-
|
|
43518
|
-
|
|
43519
|
-
|
|
43520
|
-
|
|
43521
|
-
|
|
43522
|
-
|
|
43523
|
-
|
|
43524
|
-
|
|
43525
|
-
|
|
43526
|
-
|
|
43527
|
-
|
|
43528
|
-
|
|
43529
|
-
|
|
43530
|
-
|
|
43531
|
-
|
|
43532
|
-
|
|
43533
|
-
|
|
43534
|
-
|
|
44748
|
+
// node_modules/.bun/ansi-styles@6.2.3/node_modules/ansi-styles/index.js
|
|
44749
|
+
var ANSI_BACKGROUND_OFFSET = 10;
|
|
44750
|
+
var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
|
|
44751
|
+
var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
|
|
44752
|
+
var wrapAnsi16m = (offset = 0) => (red2, green2, blue) => `\x1B[${38 + offset};2;${red2};${green2};${blue}m`;
|
|
44753
|
+
var styles = {
|
|
44754
|
+
modifier: {
|
|
44755
|
+
reset: [0, 0],
|
|
44756
|
+
bold: [1, 22],
|
|
44757
|
+
dim: [2, 22],
|
|
44758
|
+
italic: [3, 23],
|
|
44759
|
+
underline: [4, 24],
|
|
44760
|
+
overline: [53, 55],
|
|
44761
|
+
inverse: [7, 27],
|
|
44762
|
+
hidden: [8, 28],
|
|
44763
|
+
strikethrough: [9, 29]
|
|
44764
|
+
},
|
|
44765
|
+
color: {
|
|
44766
|
+
black: [30, 39],
|
|
44767
|
+
red: [31, 39],
|
|
44768
|
+
green: [32, 39],
|
|
44769
|
+
yellow: [33, 39],
|
|
44770
|
+
blue: [34, 39],
|
|
44771
|
+
magenta: [35, 39],
|
|
44772
|
+
cyan: [36, 39],
|
|
44773
|
+
white: [37, 39],
|
|
44774
|
+
blackBright: [90, 39],
|
|
44775
|
+
gray: [90, 39],
|
|
44776
|
+
grey: [90, 39],
|
|
44777
|
+
redBright: [91, 39],
|
|
44778
|
+
greenBright: [92, 39],
|
|
44779
|
+
yellowBright: [93, 39],
|
|
44780
|
+
blueBright: [94, 39],
|
|
44781
|
+
magentaBright: [95, 39],
|
|
44782
|
+
cyanBright: [96, 39],
|
|
44783
|
+
whiteBright: [97, 39]
|
|
44784
|
+
},
|
|
44785
|
+
bgColor: {
|
|
44786
|
+
bgBlack: [40, 49],
|
|
44787
|
+
bgRed: [41, 49],
|
|
44788
|
+
bgGreen: [42, 49],
|
|
44789
|
+
bgYellow: [43, 49],
|
|
44790
|
+
bgBlue: [44, 49],
|
|
44791
|
+
bgMagenta: [45, 49],
|
|
44792
|
+
bgCyan: [46, 49],
|
|
44793
|
+
bgWhite: [47, 49],
|
|
44794
|
+
bgBlackBright: [100, 49],
|
|
44795
|
+
bgGray: [100, 49],
|
|
44796
|
+
bgGrey: [100, 49],
|
|
44797
|
+
bgRedBright: [101, 49],
|
|
44798
|
+
bgGreenBright: [102, 49],
|
|
44799
|
+
bgYellowBright: [103, 49],
|
|
44800
|
+
bgBlueBright: [104, 49],
|
|
44801
|
+
bgMagentaBright: [105, 49],
|
|
44802
|
+
bgCyanBright: [106, 49],
|
|
44803
|
+
bgWhiteBright: [107, 49]
|
|
43535
44804
|
}
|
|
43536
|
-
|
|
43537
|
-
|
|
43538
|
-
|
|
43539
|
-
|
|
43540
|
-
|
|
43541
|
-
|
|
43542
|
-
|
|
43543
|
-
|
|
43544
|
-
|
|
43545
|
-
|
|
43546
|
-
|
|
43547
|
-
|
|
43548
|
-
|
|
43549
|
-
|
|
43550
|
-
|
|
43551
|
-
|
|
43552
|
-
|
|
43553
|
-
|
|
43554
|
-
|
|
43555
|
-
|
|
43556
|
-
currency: "USD",
|
|
43557
|
-
useGrouping: grouped2
|
|
43558
|
-
});
|
|
43559
|
-
let allTokens = zeroTokens;
|
|
43560
|
-
const rows = [];
|
|
43561
|
-
const ranked = [...projects].toSorted(([leftProject, left], [rightProject, right]) => right.cost - left.cost || leftProject.localeCompare(rightProject));
|
|
43562
|
-
for (const [project, total] of ranked) {
|
|
43563
|
-
rows.push([
|
|
43564
|
-
project,
|
|
43565
|
-
number4.format(total.tokens.input),
|
|
43566
|
-
number4.format(total.tokens.cacheRead),
|
|
43567
|
-
number4.format(total.tokens.cacheWrite),
|
|
43568
|
-
number4.format(total.tokens.output),
|
|
43569
|
-
`${dollars.format(total.cost)}${total.unpriced ? " + unknown" : ""}`,
|
|
43570
|
-
share2(total.cost)
|
|
43571
|
-
]);
|
|
43572
|
-
allTokens = addTokens(allTokens, total.tokens);
|
|
44805
|
+
};
|
|
44806
|
+
var modifierNames = Object.keys(styles.modifier);
|
|
44807
|
+
var foregroundColorNames = Object.keys(styles.color);
|
|
44808
|
+
var backgroundColorNames = Object.keys(styles.bgColor);
|
|
44809
|
+
var colorNames = [...foregroundColorNames, ...backgroundColorNames];
|
|
44810
|
+
function assembleStyles() {
|
|
44811
|
+
const codes2 = new Map;
|
|
44812
|
+
for (const [groupName, group2] of Object.entries(styles)) {
|
|
44813
|
+
for (const [styleName, style] of Object.entries(group2)) {
|
|
44814
|
+
styles[styleName] = {
|
|
44815
|
+
open: `\x1B[${style[0]}m`,
|
|
44816
|
+
close: `\x1B[${style[1]}m`
|
|
44817
|
+
};
|
|
44818
|
+
group2[styleName] = styles[styleName];
|
|
44819
|
+
codes2.set(style[0], style[1]);
|
|
44820
|
+
}
|
|
44821
|
+
Object.defineProperty(styles, groupName, {
|
|
44822
|
+
value: group2,
|
|
44823
|
+
enumerable: false
|
|
44824
|
+
});
|
|
43573
44825
|
}
|
|
43574
|
-
|
|
43575
|
-
|
|
43576
|
-
|
|
43577
|
-
number4.format(allTokens.input),
|
|
43578
|
-
number4.format(allTokens.cacheRead),
|
|
43579
|
-
number4.format(allTokens.cacheWrite),
|
|
43580
|
-
number4.format(allTokens.output),
|
|
43581
|
-
`${dollars.format(cost)}${unpriced ? " + unknown" : ""}`,
|
|
43582
|
-
share2(cost)
|
|
43583
|
-
]);
|
|
43584
|
-
return { headings, rows, allTokens, unpriced, projectCount: projects.size };
|
|
43585
|
-
}
|
|
43586
|
-
function table2(report, columns = 120, colorful = false) {
|
|
43587
|
-
const paint = (format9, value5) => colorful ? styleText(format9, value5, { validateStream: false }) : value5;
|
|
43588
|
-
const { headings, rows, allTokens, unpriced, projectCount } = projectSummary(report, true);
|
|
43589
|
-
const number4 = new Intl.NumberFormat("en-US");
|
|
43590
|
-
if (projectCount === 0)
|
|
43591
|
-
return `No observed usage from ${report.since} through ${report.until} (${report.timeZone}).`;
|
|
43592
|
-
const numericWidths = headings.slice(1).map((heading, i) => Math.max(heading.length, ...rows.map((row) => row[i + 1]?.length ?? 0)) + 2);
|
|
43593
|
-
const projectWidth = columns - numericWidths.reduce((sum3, width2) => sum3 + width2, 0) - (headings.length + 1);
|
|
43594
|
-
const narrow = projectWidth < 22;
|
|
43595
|
-
const colWidths = narrow ? [16, Math.max(4, columns - 19)] : [Math.min(50, projectWidth), ...numericWidths];
|
|
43596
|
-
const output = new import_cli_table3.default({
|
|
43597
|
-
head: narrow ? [] : headings.map((heading) => paint(["bold", "cyan"], heading)),
|
|
43598
|
-
colWidths,
|
|
43599
|
-
colAligns: narrow ? ["left", "right"] : ["left", "right", "right", "right", "right", "right", "right"],
|
|
43600
|
-
wordWrap: false,
|
|
43601
|
-
style: { head: [], border: [] }
|
|
44826
|
+
Object.defineProperty(styles, "codes", {
|
|
44827
|
+
value: codes2,
|
|
44828
|
+
enumerable: false
|
|
43602
44829
|
});
|
|
43603
|
-
|
|
43604
|
-
|
|
43605
|
-
|
|
43606
|
-
|
|
43607
|
-
|
|
43608
|
-
|
|
43609
|
-
|
|
43610
|
-
|
|
43611
|
-
|
|
43612
|
-
|
|
43613
|
-
|
|
43614
|
-
|
|
43615
|
-
|
|
43616
|
-
|
|
43617
|
-
|
|
43618
|
-
|
|
43619
|
-
|
|
43620
|
-
|
|
43621
|
-
|
|
43622
|
-
|
|
43623
|
-
|
|
43624
|
-
|
|
43625
|
-
|
|
43626
|
-
}
|
|
43627
|
-
|
|
43628
|
-
|
|
43629
|
-
|
|
43630
|
-
|
|
43631
|
-
|
|
43632
|
-
|
|
43633
|
-
|
|
44830
|
+
styles.color.close = "\x1B[39m";
|
|
44831
|
+
styles.bgColor.close = "\x1B[49m";
|
|
44832
|
+
styles.color.ansi = wrapAnsi16();
|
|
44833
|
+
styles.color.ansi256 = wrapAnsi256();
|
|
44834
|
+
styles.color.ansi16m = wrapAnsi16m();
|
|
44835
|
+
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
44836
|
+
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
44837
|
+
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
44838
|
+
Object.defineProperties(styles, {
|
|
44839
|
+
rgbToAnsi256: {
|
|
44840
|
+
value(red2, green2, blue) {
|
|
44841
|
+
if (red2 === green2 && green2 === blue) {
|
|
44842
|
+
if (red2 < 8) {
|
|
44843
|
+
return 16;
|
|
44844
|
+
}
|
|
44845
|
+
if (red2 > 248) {
|
|
44846
|
+
return 231;
|
|
44847
|
+
}
|
|
44848
|
+
return Math.round((red2 - 8) / 247 * 24) + 232;
|
|
44849
|
+
}
|
|
44850
|
+
return 16 + 36 * Math.round(red2 / 255 * 5) + 6 * Math.round(green2 / 255 * 5) + Math.round(blue / 255 * 5);
|
|
44851
|
+
},
|
|
44852
|
+
enumerable: false
|
|
44853
|
+
},
|
|
44854
|
+
hexToRgb: {
|
|
44855
|
+
value(hex2) {
|
|
44856
|
+
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex2.toString(16));
|
|
44857
|
+
if (!matches) {
|
|
44858
|
+
return [0, 0, 0];
|
|
44859
|
+
}
|
|
44860
|
+
let [colorString] = matches;
|
|
44861
|
+
if (colorString.length === 3) {
|
|
44862
|
+
colorString = [...colorString].map((character) => character + character).join("");
|
|
44863
|
+
}
|
|
44864
|
+
const integer = Number.parseInt(colorString, 16);
|
|
44865
|
+
return [
|
|
44866
|
+
integer >> 16 & 255,
|
|
44867
|
+
integer >> 8 & 255,
|
|
44868
|
+
integer & 255
|
|
44869
|
+
];
|
|
44870
|
+
},
|
|
44871
|
+
enumerable: false
|
|
44872
|
+
},
|
|
44873
|
+
hexToAnsi256: {
|
|
44874
|
+
value: (hex2) => styles.rgbToAnsi256(...styles.hexToRgb(hex2)),
|
|
44875
|
+
enumerable: false
|
|
44876
|
+
},
|
|
44877
|
+
ansi256ToAnsi: {
|
|
44878
|
+
value(code) {
|
|
44879
|
+
if (code < 8) {
|
|
44880
|
+
return 30 + code;
|
|
44881
|
+
}
|
|
44882
|
+
if (code < 16) {
|
|
44883
|
+
return 90 + (code - 8);
|
|
44884
|
+
}
|
|
44885
|
+
let red2;
|
|
44886
|
+
let green2;
|
|
44887
|
+
let blue;
|
|
44888
|
+
if (code >= 232) {
|
|
44889
|
+
red2 = ((code - 232) * 10 + 8) / 255;
|
|
44890
|
+
green2 = red2;
|
|
44891
|
+
blue = red2;
|
|
44892
|
+
} else {
|
|
44893
|
+
code -= 16;
|
|
44894
|
+
const remainder2 = code % 36;
|
|
44895
|
+
red2 = Math.floor(code / 36) / 5;
|
|
44896
|
+
green2 = Math.floor(remainder2 / 6) / 5;
|
|
44897
|
+
blue = remainder2 % 6 / 5;
|
|
44898
|
+
}
|
|
44899
|
+
const value5 = Math.max(red2, green2, blue) * 2;
|
|
44900
|
+
if (value5 === 0) {
|
|
44901
|
+
return 30;
|
|
44902
|
+
}
|
|
44903
|
+
let result6 = 30 + (Math.round(blue) << 2 | Math.round(green2) << 1 | Math.round(red2));
|
|
44904
|
+
if (value5 === 2) {
|
|
44905
|
+
result6 += 60;
|
|
44906
|
+
}
|
|
44907
|
+
return result6;
|
|
44908
|
+
},
|
|
44909
|
+
enumerable: false
|
|
44910
|
+
},
|
|
44911
|
+
rgbToAnsi: {
|
|
44912
|
+
value: (red2, green2, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red2, green2, blue)),
|
|
44913
|
+
enumerable: false
|
|
44914
|
+
},
|
|
44915
|
+
hexToAnsi: {
|
|
44916
|
+
value: (hex2) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex2)),
|
|
44917
|
+
enumerable: false
|
|
43634
44918
|
}
|
|
43635
|
-
}
|
|
43636
|
-
return
|
|
43637
|
-
`${paint(["bold", "cyan"], colorful ? "⚡ Token Ledger" : "Token Ledger")} · ${paint("dim", `${report.since} through ${report.until} (${report.timeZone})`)}`,
|
|
43638
|
-
"",
|
|
43639
|
-
output.toString(),
|
|
43640
|
-
"",
|
|
43641
|
-
paint("bold", `${colorful ? "\uD83D\uDCCA " : ""}${number4.format(totalTokens(allTokens))} observed tokens · ${number4.format(projectCount)} ${projectCount === 1 ? "project" : "projects"}`),
|
|
43642
|
-
...unpriced > 0 ? [
|
|
43643
|
-
paint("yellow", "Incomplete pricing: sorting and percentages use known API subtotals; unknown costs are additional.")
|
|
43644
|
-
] : [],
|
|
43645
|
-
paint("dim", "USD API-equivalent estimates; not your subscription bill.")
|
|
43646
|
-
].join(`
|
|
43647
|
-
`);
|
|
43648
|
-
}
|
|
43649
|
-
function syncSummary(payload, request3, storedBuckets) {
|
|
43650
|
-
const number4 = new Intl.NumberFormat("en-US");
|
|
43651
|
-
const dollars = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" });
|
|
43652
|
-
const sessions = new Set(payload.buckets.map((bucket) => bucket.sessionKey)).size;
|
|
43653
|
-
const cost = payload.buckets.reduce((sum3, bucket) => sum3 + (bucket.estimatedCostUsd ?? 0), 0);
|
|
43654
|
-
const unknown2 = payload.buckets.some((bucket) => bucket.estimatedCostUsd === null);
|
|
43655
|
-
return [
|
|
43656
|
-
`Synced ${terminalText(payload.machine.label)} · ${request3.since} through ${request3.until} (${payload.timeZone})`,
|
|
43657
|
-
[
|
|
43658
|
-
`${number4.format(payload.buckets.length)} hourly buckets`,
|
|
43659
|
-
`${number4.format(sessions)} sessions`,
|
|
43660
|
-
`${dollars.format(cost)}${unknown2 ? " + unknown" : ""} API estimate`,
|
|
43661
|
-
exports_Option.match(storedBuckets, {
|
|
43662
|
-
onNone: () => "accepted by the server",
|
|
43663
|
-
onSome: (stored) => `server stored ${number4.format(stored)}`
|
|
43664
|
-
})
|
|
43665
|
-
].join(" · ")
|
|
43666
|
-
].join(`
|
|
43667
|
-
`);
|
|
43668
|
-
}
|
|
43669
|
-
|
|
43670
|
-
// packages/cli/src/schedule.ts
|
|
43671
|
-
import { homedir as homedir2, userInfo } from "node:os";
|
|
43672
|
-
// packages/cli/src/settings.ts
|
|
43673
|
-
import { randomUUID } from "node:crypto";
|
|
43674
|
-
import { homedir, hostname } from "node:os";
|
|
43675
|
-
class SettingsError extends exports_Schema.TaggedError()("SettingsError", {
|
|
43676
|
-
message: exports_Schema.String
|
|
43677
|
-
}) {
|
|
44919
|
+
});
|
|
44920
|
+
return styles;
|
|
43678
44921
|
}
|
|
43679
|
-
var
|
|
43680
|
-
var
|
|
43681
|
-
var SyncSettings = exports_Schema.Struct({
|
|
43682
|
-
server: exports_Schema.optionalKey(ServerUrl),
|
|
43683
|
-
token: exports_Schema.optionalKey(exports_Schema.RedactedFromValue(exports_Schema.NonEmptyString))
|
|
43684
|
-
});
|
|
43685
|
-
var configHome = exports_Effect.gen(function* () {
|
|
43686
|
-
const path = yield* exports_Path.Path;
|
|
43687
|
-
return yield* exports_Config.String("XDG_CONFIG_HOME").pipe(exports_Config.option, exports_Effect.map(exports_Option.filter((directory) => path.isAbsolute(directory))));
|
|
43688
|
-
});
|
|
43689
|
-
var settingsDirectory = exports_Effect.gen(function* () {
|
|
43690
|
-
const path = yield* exports_Path.Path;
|
|
43691
|
-
const home = homedir();
|
|
43692
|
-
const xdg = yield* configHome;
|
|
43693
|
-
const appData = yield* exports_Config.String("APPDATA").pipe(exports_Config.option);
|
|
43694
|
-
const root = exports_Option.getOrElse(xdg, () => exports_Match.value(process.platform).pipe(exports_Match.when("win32", () => exports_Option.getOrElse(appData, () => path.join(home, "AppData", "Roaming"))), exports_Match.when("darwin", () => path.join(home, "Library", "Application Support")), exports_Match.orElse(() => path.join(home, ".config"))));
|
|
43695
|
-
return path.join(root, "token-ledger");
|
|
43696
|
-
});
|
|
43697
|
-
var loadMachine = exports_Effect.fn("Settings.loadMachine")(function* (directory) {
|
|
43698
|
-
const fs = yield* exports_FileSystem.FileSystem;
|
|
43699
|
-
const path = yield* exports_Path.Path;
|
|
43700
|
-
const file2 = path.join(directory, "machine.json");
|
|
43701
|
-
const read2 = fs.readFileString(file2).pipe(exports_Effect.flatMap(exports_Schema.decodeUnknownEffect(exports_Schema.fromJsonString(SyncMachine))), exports_Effect.mapError(() => new SettingsError({ message: `Cannot read ${file2}; fix or remove it.` })));
|
|
43702
|
-
if (yield* fs.exists(file2).pipe(exports_Effect.orElseSucceed(() => true)))
|
|
43703
|
-
return yield* read2;
|
|
43704
|
-
const machine = yield* SyncMachine.makeEffect({
|
|
43705
|
-
id: randomUUID(),
|
|
43706
|
-
label: hostname().trim() || "machine"
|
|
43707
|
-
}).pipe(exports_Effect.orDie);
|
|
43708
|
-
const created = yield* exports_Effect.gen(function* () {
|
|
43709
|
-
yield* fs.makeDirectory(directory, { recursive: true });
|
|
43710
|
-
const temporaryDirectory = yield* fs.makeTempDirectoryScoped({
|
|
43711
|
-
directory,
|
|
43712
|
-
prefix: ".machine-"
|
|
43713
|
-
});
|
|
43714
|
-
const temporary = path.join(temporaryDirectory, "machine.json");
|
|
43715
|
-
yield* fs.writeFileString(temporary, `${JSON.stringify(machine, null, 2)}
|
|
43716
|
-
`, {
|
|
43717
|
-
flag: "wx",
|
|
43718
|
-
mode: 384
|
|
43719
|
-
});
|
|
43720
|
-
return yield* fs.link(temporary, file2).pipe(exports_Effect.as(true), exports_Effect.catchReason("PlatformError", "AlreadyExists", () => exports_Effect.succeed(false)));
|
|
43721
|
-
}).pipe(exports_Effect.scoped, exports_Effect.mapError(() => new SettingsError({ message: `Cannot create ${file2}.` })));
|
|
43722
|
-
return created ? machine : yield* read2;
|
|
43723
|
-
});
|
|
43724
|
-
var loadSyncSettings = exports_Effect.fn("Settings.loadSync")(function* (directory) {
|
|
43725
|
-
const fs = yield* exports_FileSystem.FileSystem;
|
|
43726
|
-
const path = yield* exports_Path.Path;
|
|
43727
|
-
const file2 = path.join(directory, "sync.json");
|
|
43728
|
-
const failure = new SettingsError({ message: `Cannot read or decode ${file2}.` });
|
|
43729
|
-
if (!(yield* fs.exists(file2).pipe(exports_Effect.mapError(() => failure))))
|
|
43730
|
-
return {};
|
|
43731
|
-
return yield* fs.readFileString(file2).pipe(exports_Effect.flatMap(exports_Schema.decodeUnknownEffect(exports_Schema.fromJsonString(SyncSettings))), exports_Effect.mapError(() => failure));
|
|
43732
|
-
});
|
|
43733
|
-
var saveSyncSettings = exports_Effect.fn("Settings.saveSync")(function* (directory, server, token) {
|
|
43734
|
-
const fs = yield* exports_FileSystem.FileSystem;
|
|
43735
|
-
const path = yield* exports_Path.Path;
|
|
43736
|
-
const file2 = path.join(directory, "sync.json");
|
|
43737
|
-
yield* exports_Effect.gen(function* () {
|
|
43738
|
-
const settings = yield* exports_Schema.encodeEffect(SyncSettings)({ server, token });
|
|
43739
|
-
yield* fs.makeDirectory(directory, { recursive: true });
|
|
43740
|
-
const temporaryDirectory = yield* fs.makeTempDirectoryScoped({ directory, prefix: ".sync-" });
|
|
43741
|
-
const temporary = path.join(temporaryDirectory, "sync.json");
|
|
43742
|
-
yield* fs.writeFileString(temporary, `${JSON.stringify(settings, null, 2)}
|
|
43743
|
-
`, {
|
|
43744
|
-
flag: "wx",
|
|
43745
|
-
mode: 384
|
|
43746
|
-
});
|
|
43747
|
-
yield* fs.rename(temporary, file2);
|
|
43748
|
-
}).pipe(exports_Effect.scoped, exports_Effect.mapError(() => new SettingsError({ message: `Cannot save ${file2}.` })));
|
|
43749
|
-
return file2;
|
|
43750
|
-
});
|
|
44922
|
+
var ansiStyles = assembleStyles();
|
|
44923
|
+
var ansi_styles_default = ansiStyles;
|
|
43751
44924
|
|
|
43752
|
-
//
|
|
43753
|
-
|
|
43754
|
-
|
|
43755
|
-
|
|
43756
|
-
|
|
43757
|
-
var
|
|
43758
|
-
var
|
|
43759
|
-
var
|
|
43760
|
-
var
|
|
43761
|
-
var
|
|
43762
|
-
var
|
|
43763
|
-
|
|
43764
|
-
|
|
43765
|
-
|
|
43766
|
-
|
|
43767
|
-
|
|
43768
|
-
|
|
43769
|
-
|
|
43770
|
-
|
|
44925
|
+
// node_modules/.bun/wrap-ansi@10.0.2/node_modules/wrap-ansi/index.js
|
|
44926
|
+
var ANSI_ESCAPE = "\x1B";
|
|
44927
|
+
var ANSI_ESCAPE_BELL = "\x07";
|
|
44928
|
+
var C1_CSI = "";
|
|
44929
|
+
var ANSI_CSI = "[";
|
|
44930
|
+
var ANSI_OSC = "]";
|
|
44931
|
+
var ANSI_SGR_TERMINATOR = "m";
|
|
44932
|
+
var ANSI_SGR_RESET = 0;
|
|
44933
|
+
var ANSI_SGR_RESET_FOREGROUND = 39;
|
|
44934
|
+
var ANSI_SGR_RESET_BACKGROUND = 49;
|
|
44935
|
+
var ANSI_SGR_RESET_UNDERLINE_COLOR = 59;
|
|
44936
|
+
var ANSI_SGR_FOREGROUND_EXTENDED = 38;
|
|
44937
|
+
var ANSI_SGR_BACKGROUND_EXTENDED = 48;
|
|
44938
|
+
var ANSI_SGR_UNDERLINE_COLOR_EXTENDED = 58;
|
|
44939
|
+
var ANSI_SGR_COLOR_MODE_RGB = 2;
|
|
44940
|
+
var ANSI_SGR_COLOR_MODE_256 = 5;
|
|
44941
|
+
var ANSI_ESCAPE_LINK = `${ANSI_OSC}8;`;
|
|
44942
|
+
var ESCAPES = new Set([
|
|
44943
|
+
ANSI_ESCAPE,
|
|
44944
|
+
C1_CSI
|
|
44945
|
+
]);
|
|
44946
|
+
var ESCAPE_CHARACTERS = [...ESCAPES].join("");
|
|
44947
|
+
var CSI_INTRODUCER = `(?:${ANSI_ESCAPE}\\${ANSI_CSI}|${C1_CSI})`;
|
|
44948
|
+
var CSI_PARAMETERS = "[0-?]*[ -/]*[@-~]";
|
|
44949
|
+
var SGR_PARAMETERS = `(?<sgr>[0-9;:]*)${ANSI_SGR_TERMINATOR}`;
|
|
44950
|
+
var OSC_STRING_TERMINATOR = `(?:${ANSI_ESCAPE_BELL}|${ANSI_ESCAPE}\\\\)`;
|
|
44951
|
+
var OSC_STRING_PAYLOAD = String.raw`[^\u0000-\u001F\u007F-\u009F]*`;
|
|
44952
|
+
var LINK_PARAMETERS = String.raw`8;(?<parameters>[^;\u0000-\u001F\u007F-\u009F]*);(?<uri>${OSC_STRING_PAYLOAD})${OSC_STRING_TERMINATOR}`;
|
|
44953
|
+
var OSC_STRING = `${OSC_STRING_PAYLOAD}${OSC_STRING_TERMINATOR}`;
|
|
44954
|
+
var ANSI_ESCAPE_REGEX = new RegExp(`${CSI_INTRODUCER}(?:${SGR_PARAMETERS}|${CSI_PARAMETERS})` + `|${ANSI_ESCAPE}\\${ANSI_OSC}(?:${LINK_PARAMETERS}|${OSC_STRING})`, "y");
|
|
44955
|
+
var ANSI_SGR_MODIFIER_CLOSE_CODES = new Set(ansi_styles_default.codes.values());
|
|
44956
|
+
ANSI_SGR_MODIFIER_CLOSE_CODES.delete(ANSI_SGR_RESET);
|
|
44957
|
+
var segmenter2 = new Intl.Segmenter;
|
|
44958
|
+
var getStringWidth = (string4) => stringWidth(string4, { countAnsiEscapeCodes: true });
|
|
44959
|
+
var TAB_SIZE = 8;
|
|
44960
|
+
var ESCAPE_INTRODUCER_REGEX = new RegExp(`[${ESCAPE_CHARACTERS}]`, "g");
|
|
44961
|
+
var ROW_BOUNDARY_REGEX = new RegExp(`[\\n${ESCAPE_CHARACTERS}]`, "g");
|
|
44962
|
+
var ASCII_PRINTABLE_REGEX = /^[ -~]*$/;
|
|
44963
|
+
var wrapAnsiCode = (code) => `${ANSI_ESCAPE}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
|
|
44964
|
+
var wrapAnsiHyperlink = (url, parameters = "") => `${ANSI_ESCAPE}${ANSI_ESCAPE_LINK}${parameters};${url}${ANSI_ESCAPE_BELL}`;
|
|
44965
|
+
var matchAnsiEscape = (string4, index2) => {
|
|
44966
|
+
if (!ESCAPES.has(string4[index2])) {
|
|
44967
|
+
return;
|
|
44968
|
+
}
|
|
44969
|
+
ANSI_ESCAPE_REGEX.lastIndex = index2;
|
|
44970
|
+
return ANSI_ESCAPE_REGEX.exec(string4) ?? undefined;
|
|
44971
|
+
};
|
|
44972
|
+
var forEachSegment = (string4, onPlainText, onEscape = () => {}) => {
|
|
44973
|
+
let plainStart = 0;
|
|
44974
|
+
let index2 = 0;
|
|
44975
|
+
while (index2 < string4.length) {
|
|
44976
|
+
ESCAPE_INTRODUCER_REGEX.lastIndex = index2;
|
|
44977
|
+
const introducer = ESCAPE_INTRODUCER_REGEX.exec(string4);
|
|
44978
|
+
if (!introducer) {
|
|
44979
|
+
break;
|
|
44980
|
+
}
|
|
44981
|
+
const escape2 = matchAnsiEscape(string4, introducer.index);
|
|
44982
|
+
if (!escape2) {
|
|
44983
|
+
index2 = introducer.index + 1;
|
|
44984
|
+
continue;
|
|
44985
|
+
}
|
|
44986
|
+
if (introducer.index > plainStart) {
|
|
44987
|
+
onPlainText(string4.slice(plainStart, introducer.index));
|
|
44988
|
+
}
|
|
44989
|
+
onEscape(escape2[0]);
|
|
44990
|
+
index2 = introducer.index + escape2[0].length;
|
|
44991
|
+
plainStart = index2;
|
|
44992
|
+
}
|
|
44993
|
+
if (plainStart < string4.length) {
|
|
44994
|
+
onPlainText(string4.slice(plainStart));
|
|
44995
|
+
}
|
|
44996
|
+
};
|
|
44997
|
+
var getWidth = (string4) => {
|
|
44998
|
+
let plainText = "";
|
|
44999
|
+
forEachSegment(string4, (part) => {
|
|
45000
|
+
plainText += part;
|
|
43771
45001
|
});
|
|
43772
|
-
|
|
43773
|
-
|
|
43774
|
-
|
|
43775
|
-
|
|
43776
|
-
|
|
43777
|
-
|
|
43778
|
-
|
|
43779
|
-
|
|
43780
|
-
|
|
43781
|
-
|
|
43782
|
-
|
|
43783
|
-
|
|
43784
|
-
|
|
43785
|
-
|
|
43786
|
-
|
|
43787
|
-
|
|
43788
|
-
|
|
43789
|
-
|
|
43790
|
-
|
|
43791
|
-
|
|
43792
|
-
|
|
43793
|
-
|
|
43794
|
-
|
|
43795
|
-
|
|
43796
|
-
|
|
43797
|
-
|
|
43798
|
-
|
|
43799
|
-
|
|
43800
|
-
|
|
43801
|
-
|
|
43802
|
-
|
|
43803
|
-
|
|
43804
|
-
|
|
43805
|
-
|
|
43806
|
-
|
|
43807
|
-
|
|
43808
|
-
|
|
43809
|
-
|
|
43810
|
-
|
|
43811
|
-
|
|
43812
|
-
|
|
43813
|
-
|
|
43814
|
-
|
|
43815
|
-
|
|
43816
|
-
|
|
43817
|
-
|
|
43818
|
-
|
|
43819
|
-
|
|
43820
|
-
|
|
43821
|
-
|
|
43822
|
-
|
|
43823
|
-
|
|
43824
|
-
|
|
43825
|
-
|
|
43826
|
-
|
|
43827
|
-
|
|
43828
|
-
|
|
43829
|
-
|
|
43830
|
-
|
|
43831
|
-
|
|
43832
|
-
|
|
43833
|
-
|
|
43834
|
-
|
|
43835
|
-
|
|
43836
|
-
|
|
43837
|
-
|
|
43838
|
-
|
|
43839
|
-
|
|
43840
|
-
|
|
43841
|
-
|
|
43842
|
-
|
|
43843
|
-
|
|
43844
|
-
|
|
43845
|
-
|
|
43846
|
-
|
|
43847
|
-
|
|
43848
|
-
|
|
43849
|
-
|
|
43850
|
-
|
|
43851
|
-
|
|
43852
|
-
|
|
43853
|
-
|
|
43854
|
-
|
|
43855
|
-
|
|
43856
|
-
|
|
43857
|
-
|
|
43858
|
-
|
|
43859
|
-
|
|
43860
|
-
|
|
43861
|
-
|
|
43862
|
-
|
|
43863
|
-
|
|
43864
|
-
|
|
43865
|
-
|
|
43866
|
-
|
|
43867
|
-
|
|
43868
|
-
|
|
43869
|
-
|
|
43870
|
-
|
|
43871
|
-
|
|
43872
|
-
|
|
43873
|
-
|
|
43874
|
-
|
|
43875
|
-
|
|
43876
|
-
|
|
43877
|
-
|
|
43878
|
-
|
|
43879
|
-
|
|
43880
|
-
|
|
43881
|
-
|
|
43882
|
-
|
|
43883
|
-
|
|
43884
|
-
|
|
43885
|
-
|
|
43886
|
-
|
|
43887
|
-
|
|
43888
|
-
|
|
45002
|
+
return getStringWidth(plainText);
|
|
45003
|
+
};
|
|
45004
|
+
var getTokens = (string4) => {
|
|
45005
|
+
const tokens = [];
|
|
45006
|
+
forEachSegment(string4, (plainText) => {
|
|
45007
|
+
if (ASCII_PRINTABLE_REGEX.test(plainText)) {
|
|
45008
|
+
for (const character of plainText) {
|
|
45009
|
+
tokens.push({ value: character, width: 1 });
|
|
45010
|
+
}
|
|
45011
|
+
return;
|
|
45012
|
+
}
|
|
45013
|
+
for (const { segment } of segmenter2.segment(plainText)) {
|
|
45014
|
+
tokens.push({ value: segment, width: getStringWidth(segment) });
|
|
45015
|
+
}
|
|
45016
|
+
}, (escape2) => {
|
|
45017
|
+
tokens.push({ value: escape2, width: 0 });
|
|
45018
|
+
});
|
|
45019
|
+
return tokens;
|
|
45020
|
+
};
|
|
45021
|
+
var splitWords = (string4) => {
|
|
45022
|
+
let currentWord = { value: "", plainText: "" };
|
|
45023
|
+
const words = [currentWord];
|
|
45024
|
+
forEachSegment(string4, (plainText) => {
|
|
45025
|
+
const parts2 = plainText.split(" ");
|
|
45026
|
+
currentWord.value += parts2[0];
|
|
45027
|
+
currentWord.plainText += parts2[0];
|
|
45028
|
+
for (let index2 = 1;index2 < parts2.length; index2++) {
|
|
45029
|
+
currentWord = { value: parts2[index2], plainText: parts2[index2] };
|
|
45030
|
+
words.push(currentWord);
|
|
45031
|
+
}
|
|
45032
|
+
}, (escape2) => {
|
|
45033
|
+
currentWord.value += escape2;
|
|
45034
|
+
});
|
|
45035
|
+
for (const word of words) {
|
|
45036
|
+
word.width = getStringWidth(word.plainText);
|
|
45037
|
+
}
|
|
45038
|
+
return words;
|
|
45039
|
+
};
|
|
45040
|
+
var getColonColorToken = (parameter) => {
|
|
45041
|
+
const parts2 = parameter.split(":");
|
|
45042
|
+
const code = Number.parseInt(parts2[0], 10);
|
|
45043
|
+
const mode = Number.parseInt(parts2[1], 10);
|
|
45044
|
+
if (![ANSI_SGR_FOREGROUND_EXTENDED, ANSI_SGR_BACKGROUND_EXTENDED, ANSI_SGR_UNDERLINE_COLOR_EXTENDED].includes(code)) {
|
|
45045
|
+
return;
|
|
45046
|
+
}
|
|
45047
|
+
if (mode === ANSI_SGR_COLOR_MODE_256 && parts2.length === 3 && /^\d+$/.test(parts2[2])) {
|
|
45048
|
+
return { code, open: parameter, hasArguments: true };
|
|
45049
|
+
}
|
|
45050
|
+
if (mode !== ANSI_SGR_COLOR_MODE_RGB) {
|
|
45051
|
+
return;
|
|
45052
|
+
}
|
|
45053
|
+
const components = parts2.length === 6 ? parts2.slice(3) : parts2.slice(2);
|
|
45054
|
+
const colorSpace = parts2.length === 6 ? parts2[2] : undefined;
|
|
45055
|
+
if (components.length === 3 && components.every((component) => /^\d+$/.test(component)) && (colorSpace === undefined || /^\d*$/.test(colorSpace))) {
|
|
45056
|
+
return { code, open: parameter, hasArguments: true };
|
|
45057
|
+
}
|
|
45058
|
+
};
|
|
45059
|
+
var getSgrTokens = (sgrParameters) => {
|
|
45060
|
+
const parameters = sgrParameters.split(";");
|
|
45061
|
+
const sgrTokens = [];
|
|
45062
|
+
for (let index2 = 0;index2 < parameters.length; index2++) {
|
|
45063
|
+
const parameter = parameters[index2];
|
|
45064
|
+
if (parameter.includes(":")) {
|
|
45065
|
+
const colonColorToken = getColonColorToken(parameter);
|
|
45066
|
+
if (colonColorToken) {
|
|
45067
|
+
sgrTokens.push(colonColorToken);
|
|
45068
|
+
}
|
|
45069
|
+
continue;
|
|
45070
|
+
}
|
|
45071
|
+
const code = parameter === "" ? ANSI_SGR_RESET : Number.parseInt(parameter, 10);
|
|
45072
|
+
if (!Number.isFinite(code)) {
|
|
45073
|
+
continue;
|
|
45074
|
+
}
|
|
45075
|
+
if (code === ANSI_SGR_FOREGROUND_EXTENDED || code === ANSI_SGR_BACKGROUND_EXTENDED || code === ANSI_SGR_UNDERLINE_COLOR_EXTENDED) {
|
|
45076
|
+
if (index2 + 1 >= parameters.length) {
|
|
45077
|
+
break;
|
|
45078
|
+
}
|
|
45079
|
+
const mode = Number.parseInt(parameters[index2 + 1], 10);
|
|
45080
|
+
const colorIndex = Number.parseInt(parameters[index2 + 2], 10);
|
|
45081
|
+
if (mode === ANSI_SGR_COLOR_MODE_256 && Number.isFinite(colorIndex)) {
|
|
45082
|
+
sgrTokens.push({ code, open: [code, mode, colorIndex].join(";"), hasArguments: true });
|
|
45083
|
+
index2 += 2;
|
|
45084
|
+
continue;
|
|
45085
|
+
}
|
|
45086
|
+
const red2 = Number.parseInt(parameters[index2 + 2], 10);
|
|
45087
|
+
const green2 = Number.parseInt(parameters[index2 + 3], 10);
|
|
45088
|
+
const blue = Number.parseInt(parameters[index2 + 4], 10);
|
|
45089
|
+
if (mode === ANSI_SGR_COLOR_MODE_RGB && Number.isFinite(red2) && Number.isFinite(green2) && Number.isFinite(blue)) {
|
|
45090
|
+
sgrTokens.push({ code, open: [code, mode, red2, green2, blue].join(";"), hasArguments: true });
|
|
45091
|
+
index2 += 4;
|
|
45092
|
+
continue;
|
|
45093
|
+
}
|
|
45094
|
+
break;
|
|
45095
|
+
}
|
|
45096
|
+
sgrTokens.push({ code, open: String(code), hasArguments: false });
|
|
45097
|
+
}
|
|
45098
|
+
return sgrTokens;
|
|
45099
|
+
};
|
|
45100
|
+
var removeActiveStyle = (activeStyles, family) => {
|
|
45101
|
+
const activeStyleIndex = activeStyles.findIndex((activeStyle) => activeStyle.family === family);
|
|
45102
|
+
if (activeStyleIndex !== -1) {
|
|
45103
|
+
activeStyles.splice(activeStyleIndex, 1);
|
|
45104
|
+
}
|
|
45105
|
+
};
|
|
45106
|
+
var upsertActiveStyle = (activeStyles, nextActiveStyle) => {
|
|
45107
|
+
removeActiveStyle(activeStyles, nextActiveStyle.family);
|
|
45108
|
+
activeStyles.push(nextActiveStyle);
|
|
45109
|
+
};
|
|
45110
|
+
var removeModifierStylesByClose = (activeStyles, closeCode) => {
|
|
45111
|
+
for (let index2 = activeStyles.length - 1;index2 >= 0; index2--) {
|
|
45112
|
+
const activeStyle = activeStyles[index2];
|
|
45113
|
+
if (activeStyle.family.startsWith("modifier-") && activeStyle.close === closeCode) {
|
|
45114
|
+
activeStyles.splice(index2, 1);
|
|
45115
|
+
}
|
|
45116
|
+
}
|
|
45117
|
+
};
|
|
45118
|
+
var getColorStyle = (sgrToken) => {
|
|
45119
|
+
const { code, open: open3, hasArguments } = sgrToken;
|
|
45120
|
+
if (code >= 30 && code <= 37 || code >= 90 && code <= 97 || code === ANSI_SGR_FOREGROUND_EXTENDED && hasArguments) {
|
|
45121
|
+
return {
|
|
45122
|
+
family: "foreground",
|
|
45123
|
+
open: open3,
|
|
45124
|
+
close: ANSI_SGR_RESET_FOREGROUND
|
|
45125
|
+
};
|
|
45126
|
+
}
|
|
45127
|
+
if (code >= 40 && code <= 47 || code >= 100 && code <= 107 || code === ANSI_SGR_BACKGROUND_EXTENDED && hasArguments) {
|
|
45128
|
+
return {
|
|
45129
|
+
family: "background",
|
|
45130
|
+
open: open3,
|
|
45131
|
+
close: ANSI_SGR_RESET_BACKGROUND
|
|
45132
|
+
};
|
|
45133
|
+
}
|
|
45134
|
+
if (code === ANSI_SGR_UNDERLINE_COLOR_EXTENDED && hasArguments) {
|
|
45135
|
+
return {
|
|
45136
|
+
family: "underlineColor",
|
|
45137
|
+
open: open3,
|
|
45138
|
+
close: ANSI_SGR_RESET_UNDERLINE_COLOR
|
|
45139
|
+
};
|
|
45140
|
+
}
|
|
45141
|
+
};
|
|
45142
|
+
var applySgrResetCode = (code, activeStyles) => {
|
|
45143
|
+
if (code === ANSI_SGR_RESET) {
|
|
45144
|
+
activeStyles.length = 0;
|
|
45145
|
+
return true;
|
|
45146
|
+
}
|
|
45147
|
+
if (code === ANSI_SGR_RESET_FOREGROUND) {
|
|
45148
|
+
removeActiveStyle(activeStyles, "foreground");
|
|
45149
|
+
return true;
|
|
45150
|
+
}
|
|
45151
|
+
if (code === ANSI_SGR_RESET_BACKGROUND) {
|
|
45152
|
+
removeActiveStyle(activeStyles, "background");
|
|
45153
|
+
return true;
|
|
45154
|
+
}
|
|
45155
|
+
if (code === ANSI_SGR_RESET_UNDERLINE_COLOR) {
|
|
45156
|
+
removeActiveStyle(activeStyles, "underlineColor");
|
|
45157
|
+
return true;
|
|
45158
|
+
}
|
|
45159
|
+
if (ANSI_SGR_MODIFIER_CLOSE_CODES.has(code)) {
|
|
45160
|
+
removeModifierStylesByClose(activeStyles, code);
|
|
45161
|
+
return true;
|
|
45162
|
+
}
|
|
45163
|
+
return false;
|
|
45164
|
+
};
|
|
45165
|
+
var applySgrToken = (sgrToken, activeStyles) => {
|
|
45166
|
+
const { code } = sgrToken;
|
|
45167
|
+
if (applySgrResetCode(code, activeStyles)) {
|
|
45168
|
+
return;
|
|
45169
|
+
}
|
|
45170
|
+
const colorStyle = getColorStyle(sgrToken);
|
|
45171
|
+
if (colorStyle) {
|
|
45172
|
+
upsertActiveStyle(activeStyles, colorStyle);
|
|
45173
|
+
return;
|
|
45174
|
+
}
|
|
45175
|
+
const close3 = ansi_styles_default.codes.get(code);
|
|
45176
|
+
if (close3 !== undefined && close3 !== ANSI_SGR_RESET) {
|
|
45177
|
+
upsertActiveStyle(activeStyles, {
|
|
45178
|
+
family: `modifier-${code}`,
|
|
45179
|
+
open: sgrToken.open,
|
|
45180
|
+
close: close3
|
|
45181
|
+
});
|
|
45182
|
+
}
|
|
45183
|
+
};
|
|
45184
|
+
var applySgrParameters = (sgrParameters, activeStyles) => {
|
|
45185
|
+
for (const sgrToken of getSgrTokens(sgrParameters)) {
|
|
45186
|
+
applySgrToken(sgrToken, activeStyles);
|
|
45187
|
+
}
|
|
45188
|
+
};
|
|
45189
|
+
var applySgrResets = (sgrParameters, activeStyles) => {
|
|
45190
|
+
for (const { code } of getSgrTokens(sgrParameters)) {
|
|
45191
|
+
applySgrResetCode(code, activeStyles);
|
|
45192
|
+
}
|
|
45193
|
+
};
|
|
45194
|
+
var applyLeadingSgrResets = (string4, startIndex, activeStyles) => {
|
|
45195
|
+
let index2 = startIndex;
|
|
45196
|
+
while (index2 < string4.length) {
|
|
45197
|
+
const match10 = matchAnsiEscape(string4, index2);
|
|
45198
|
+
if (!match10) {
|
|
45199
|
+
break;
|
|
45200
|
+
}
|
|
45201
|
+
if (match10.groups.sgr !== undefined) {
|
|
45202
|
+
applySgrResets(match10.groups.sgr, activeStyles);
|
|
45203
|
+
}
|
|
45204
|
+
index2 += match10[0].length;
|
|
45205
|
+
}
|
|
45206
|
+
};
|
|
45207
|
+
var getClosingSgrSequence = (activeStyles) => [...activeStyles].reverse().map((activeStyle) => wrapAnsiCode(activeStyle.close)).join("");
|
|
45208
|
+
var getOpeningSgrSequence = (activeStyles) => activeStyles.map((activeStyle) => wrapAnsiCode(activeStyle.open)).join("");
|
|
45209
|
+
var wrapWord = (rows, word, columns, rowWidth) => {
|
|
45210
|
+
const tokens = getTokens(word);
|
|
45211
|
+
let visible = rowWidth;
|
|
45212
|
+
for (let index2 = 0;index2 < tokens.length; index2++) {
|
|
45213
|
+
const token = tokens[index2];
|
|
45214
|
+
if (token.width > 0 && visible > 0 && visible + token.width > columns) {
|
|
45215
|
+
rows.push("");
|
|
45216
|
+
visible = 0;
|
|
45217
|
+
}
|
|
45218
|
+
rows[rows.length - 1] += token.value;
|
|
45219
|
+
visible += token.width;
|
|
45220
|
+
if (visible === columns && index2 < tokens.length - 1) {
|
|
45221
|
+
rows.push("");
|
|
45222
|
+
visible = 0;
|
|
45223
|
+
}
|
|
45224
|
+
}
|
|
45225
|
+
if (!visible && rows.at(-1).length > 0 && rows.length > 1) {
|
|
45226
|
+
rows[rows.length - 2] += rows.pop();
|
|
45227
|
+
}
|
|
45228
|
+
return getWidth(rows.at(-1));
|
|
45229
|
+
};
|
|
45230
|
+
var stringVisibleTrimSpacesRight = (string4) => {
|
|
45231
|
+
if (!string4.includes(" ")) {
|
|
45232
|
+
return string4;
|
|
45233
|
+
}
|
|
45234
|
+
const segments = [];
|
|
45235
|
+
forEachSegment(string4, (plainText) => {
|
|
45236
|
+
segments.push({ value: plainText, isEscape: false });
|
|
45237
|
+
}, (escape2) => {
|
|
45238
|
+
segments.push({ value: escape2, isEscape: true });
|
|
45239
|
+
});
|
|
45240
|
+
for (let index2 = segments.length - 1;index2 >= 0; index2--) {
|
|
45241
|
+
const segment = segments[index2];
|
|
45242
|
+
if (segment.isEscape) {
|
|
45243
|
+
continue;
|
|
45244
|
+
}
|
|
45245
|
+
let end3 = segment.value.length;
|
|
45246
|
+
while (end3 > 0 && segment.value[end3 - 1] === " ") {
|
|
45247
|
+
end3--;
|
|
45248
|
+
}
|
|
45249
|
+
segment.value = segment.value.slice(0, end3);
|
|
45250
|
+
if (getStringWidth(segment.value) > 0) {
|
|
45251
|
+
break;
|
|
45252
|
+
}
|
|
45253
|
+
}
|
|
45254
|
+
return segments.map((segment) => segment.value).join("");
|
|
45255
|
+
};
|
|
45256
|
+
var expandTabs = (line) => {
|
|
45257
|
+
if (!line.includes("\t")) {
|
|
45258
|
+
return line;
|
|
45259
|
+
}
|
|
45260
|
+
let visible = 0;
|
|
45261
|
+
let expandedLine = "";
|
|
45262
|
+
let plainTextSinceTab = "";
|
|
45263
|
+
const expandPlainText = (plainText) => {
|
|
45264
|
+
const segments = plainText.split("\t");
|
|
45265
|
+
for (const [index2, segment] of segments.entries()) {
|
|
45266
|
+
expandedLine += segment;
|
|
45267
|
+
plainTextSinceTab += segment;
|
|
45268
|
+
if (index2 < segments.length - 1) {
|
|
45269
|
+
visible += getStringWidth(plainTextSinceTab);
|
|
45270
|
+
plainTextSinceTab = "";
|
|
45271
|
+
const spaces = TAB_SIZE - visible % TAB_SIZE;
|
|
45272
|
+
expandedLine += " ".repeat(spaces);
|
|
45273
|
+
visible += spaces;
|
|
45274
|
+
}
|
|
45275
|
+
}
|
|
43889
45276
|
};
|
|
45277
|
+
forEachSegment(line, expandPlainText, (escape2) => {
|
|
45278
|
+
expandedLine += escape2;
|
|
45279
|
+
});
|
|
45280
|
+
return expandedLine;
|
|
45281
|
+
};
|
|
45282
|
+
var restoreStylesAcrossRows = (preString) => {
|
|
45283
|
+
let returnValue = "";
|
|
45284
|
+
let activeHyperlink;
|
|
45285
|
+
const activeStyles = [];
|
|
45286
|
+
let index2 = 0;
|
|
45287
|
+
let copiedIndex = 0;
|
|
45288
|
+
while (index2 < preString.length) {
|
|
45289
|
+
ROW_BOUNDARY_REGEX.lastIndex = index2;
|
|
45290
|
+
const boundary = ROW_BOUNDARY_REGEX.exec(preString);
|
|
45291
|
+
if (!boundary) {
|
|
45292
|
+
break;
|
|
45293
|
+
}
|
|
45294
|
+
index2 = boundary.index;
|
|
45295
|
+
if (boundary[0] !== `
|
|
45296
|
+
`) {
|
|
45297
|
+
const escape2 = matchAnsiEscape(preString, index2);
|
|
45298
|
+
if (!escape2) {
|
|
45299
|
+
index2++;
|
|
45300
|
+
continue;
|
|
45301
|
+
}
|
|
45302
|
+
const { groups } = escape2;
|
|
45303
|
+
if (groups.sgr !== undefined) {
|
|
45304
|
+
applySgrParameters(groups.sgr, activeStyles);
|
|
45305
|
+
} else if (groups.uri !== undefined) {
|
|
45306
|
+
activeHyperlink = groups.uri.length === 0 ? undefined : { parameters: groups.parameters, uri: groups.uri };
|
|
45307
|
+
}
|
|
45308
|
+
index2 += escape2[0].length;
|
|
45309
|
+
continue;
|
|
45310
|
+
}
|
|
45311
|
+
returnValue += preString.slice(copiedIndex, index2);
|
|
45312
|
+
if (index2 > copiedIndex) {
|
|
45313
|
+
if (activeHyperlink) {
|
|
45314
|
+
returnValue += wrapAnsiHyperlink("");
|
|
45315
|
+
}
|
|
45316
|
+
returnValue += getClosingSgrSequence(activeStyles);
|
|
45317
|
+
}
|
|
45318
|
+
returnValue += `
|
|
45319
|
+
`;
|
|
45320
|
+
index2++;
|
|
45321
|
+
copiedIndex = index2;
|
|
45322
|
+
if (index2 < preString.length && preString[index2] !== `
|
|
45323
|
+
`) {
|
|
45324
|
+
const openingStyles = [...activeStyles];
|
|
45325
|
+
applyLeadingSgrResets(preString, index2, openingStyles);
|
|
45326
|
+
returnValue += getOpeningSgrSequence(openingStyles);
|
|
45327
|
+
if (activeHyperlink) {
|
|
45328
|
+
returnValue += wrapAnsiHyperlink(activeHyperlink.uri, activeHyperlink.parameters);
|
|
45329
|
+
}
|
|
45330
|
+
}
|
|
45331
|
+
}
|
|
45332
|
+
return returnValue + preString.slice(copiedIndex);
|
|
45333
|
+
};
|
|
45334
|
+
var exec = (string4, columns, options3 = {}) => {
|
|
45335
|
+
if (options3.trim !== false && string4.trim() === "") {
|
|
45336
|
+
return "";
|
|
45337
|
+
}
|
|
45338
|
+
const words = splitWords(string4);
|
|
45339
|
+
let rows = [""];
|
|
45340
|
+
let rowLength = 0;
|
|
45341
|
+
let trimmedRowIndex = -1;
|
|
45342
|
+
let isFirstWord = true;
|
|
45343
|
+
for (const word of words) {
|
|
45344
|
+
const rowIndex = rows.length - 1;
|
|
45345
|
+
if (options3.trim !== false && trimmedRowIndex !== rowIndex) {
|
|
45346
|
+
const row = rows[rowIndex];
|
|
45347
|
+
const trimmedRow = row.trimStart();
|
|
45348
|
+
if (trimmedRow.length !== row.length) {
|
|
45349
|
+
rows[rowIndex] = trimmedRow;
|
|
45350
|
+
rowLength = getWidth(trimmedRow);
|
|
45351
|
+
}
|
|
45352
|
+
if (trimmedRow.length > 0) {
|
|
45353
|
+
trimmedRowIndex = rowIndex;
|
|
45354
|
+
}
|
|
45355
|
+
}
|
|
45356
|
+
if (isFirstWord) {
|
|
45357
|
+
isFirstWord = false;
|
|
45358
|
+
} else {
|
|
45359
|
+
if (rowLength >= columns && (options3.wordWrap === false || options3.trim === false)) {
|
|
45360
|
+
rows.push("");
|
|
45361
|
+
rowLength = 0;
|
|
45362
|
+
}
|
|
45363
|
+
if (rowLength > 0 || options3.trim === false) {
|
|
45364
|
+
rows[rows.length - 1] += " ";
|
|
45365
|
+
rowLength++;
|
|
45366
|
+
}
|
|
45367
|
+
}
|
|
45368
|
+
if (options3.hard && options3.wordWrap !== false && word.width > columns) {
|
|
45369
|
+
const remainingColumns = columns - rowLength;
|
|
45370
|
+
const breaksStartingThisLine = 1 + Math.floor((word.width - remainingColumns - 1) / columns);
|
|
45371
|
+
const breaksStartingNextLine = Math.floor((word.width - 1) / columns);
|
|
45372
|
+
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
45373
|
+
rows.push("");
|
|
45374
|
+
rowLength = 0;
|
|
45375
|
+
}
|
|
45376
|
+
rowLength = wrapWord(rows, word.value, columns, rowLength);
|
|
45377
|
+
continue;
|
|
45378
|
+
}
|
|
45379
|
+
if (rowLength + word.width > columns && rowLength > 0 && word.width > 0) {
|
|
45380
|
+
if (options3.wordWrap === false && rowLength < columns) {
|
|
45381
|
+
rowLength = wrapWord(rows, word.value, columns, rowLength);
|
|
45382
|
+
continue;
|
|
45383
|
+
}
|
|
45384
|
+
rows.push("");
|
|
45385
|
+
rowLength = 0;
|
|
45386
|
+
}
|
|
45387
|
+
if (rowLength + word.width > columns && options3.wordWrap === false) {
|
|
45388
|
+
rowLength = wrapWord(rows, word.value, columns, rowLength);
|
|
45389
|
+
continue;
|
|
45390
|
+
}
|
|
45391
|
+
rows[rows.length - 1] += word.value;
|
|
45392
|
+
rowLength += word.width;
|
|
45393
|
+
}
|
|
45394
|
+
if (options3.trim !== false) {
|
|
45395
|
+
rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
|
|
45396
|
+
}
|
|
45397
|
+
return restoreStylesAcrossRows(rows.join(`
|
|
45398
|
+
`));
|
|
45399
|
+
};
|
|
45400
|
+
var normalizeText = (string4) => {
|
|
45401
|
+
let normalizedString = "";
|
|
45402
|
+
forEachSegment(string4, (plainText) => {
|
|
45403
|
+
normalizedString += plainText.normalize();
|
|
45404
|
+
}, (escape2) => {
|
|
45405
|
+
normalizedString += escape2;
|
|
45406
|
+
});
|
|
45407
|
+
return normalizedString;
|
|
45408
|
+
};
|
|
45409
|
+
function wrapAnsi(string4, columns, options3) {
|
|
45410
|
+
return normalizeText(String(string4)).replaceAll(`\r
|
|
45411
|
+
`, `
|
|
45412
|
+
`).split(`
|
|
45413
|
+
`).map((line) => exec(expandTabs(line), columns, options3)).join(`
|
|
45414
|
+
`);
|
|
43890
45415
|
}
|
|
43891
|
-
|
|
43892
|
-
|
|
43893
|
-
|
|
43894
|
-
|
|
43895
|
-
|
|
43896
|
-
|
|
43897
|
-
|
|
43898
|
-
|
|
43899
|
-
|
|
43900
|
-
|
|
43901
|
-
|
|
43902
|
-
"$ErrorActionPreference = 'Stop'",
|
|
43903
|
-
"$ProgressPreference = 'SilentlyContinue'",
|
|
43904
|
-
`$action = New-ScheduledTaskAction -Execute 'cmd.exe' -Argument ${powershellString(`/d /v:off /s /c "${command}"`)}`,
|
|
43905
|
-
`$trigger = New-ScheduledTaskTrigger -Daily -At '${job2.at}'`,
|
|
43906
|
-
"$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries",
|
|
43907
|
-
`Register-ScheduledTask -TaskName ${powershellString(task)} -Action $action -Trigger $trigger -Settings $settings -Force | Out-Null`
|
|
43908
|
-
].join(`
|
|
45416
|
+
|
|
45417
|
+
// packages/cli/src/format.ts
|
|
45418
|
+
function csvCell(value5) {
|
|
45419
|
+
const text2 = value5 === null ? "" : String(value5);
|
|
45420
|
+
const safe = /^[=+\-@\t\r\n]/.test(text2) ? `'${text2}` : text2;
|
|
45421
|
+
return `"${safe.replaceAll('"', '""')}"`;
|
|
45422
|
+
}
|
|
45423
|
+
function csv(report) {
|
|
45424
|
+
const summary = projectSummary(report, false);
|
|
45425
|
+
const headings = summary.headings.map((heading) => heading === "API estimate" ? "API estimate (USD)" : heading);
|
|
45426
|
+
return [headings, ...summary.rows].map((row) => row.map(csvCell).join(",")).join(`
|
|
43909
45427
|
`);
|
|
43910
|
-
|
|
43911
|
-
|
|
43912
|
-
|
|
43913
|
-
|
|
43914
|
-
|
|
43915
|
-
|
|
43916
|
-
|
|
43917
|
-
|
|
43918
|
-
|
|
43919
|
-
|
|
45428
|
+
}
|
|
45429
|
+
function terminalText(value5) {
|
|
45430
|
+
return value5.replace(/[\x00-\x1f\x7f-\x9f]/g, " ");
|
|
45431
|
+
}
|
|
45432
|
+
function projectSummary(report, grouped2) {
|
|
45433
|
+
const projects = new Map;
|
|
45434
|
+
for (const row of report.rows) {
|
|
45435
|
+
const previous = projects.get(row.project);
|
|
45436
|
+
projects.set(row.project, {
|
|
45437
|
+
tokens: addTokens(previous?.tokens ?? zeroTokens, row.tokens),
|
|
45438
|
+
cost: (previous?.cost ?? 0) + row.pricedCostUsd,
|
|
45439
|
+
unpriced: (previous?.unpriced ?? 0) + row.unpricedRecords
|
|
45440
|
+
});
|
|
45441
|
+
}
|
|
45442
|
+
const cost = [...projects.values()].reduce((sum3, project) => sum3 + project.cost, 0);
|
|
45443
|
+
const unpriced = [...projects.values()].reduce((sum3, project) => sum3 + project.unpriced, 0);
|
|
45444
|
+
const headings = [
|
|
45445
|
+
"Project",
|
|
45446
|
+
"Input",
|
|
45447
|
+
"Cache read",
|
|
45448
|
+
"Cache write",
|
|
45449
|
+
"Output",
|
|
45450
|
+
"API estimate",
|
|
45451
|
+
unpriced ? "Known cost %" : "Cost %"
|
|
45452
|
+
];
|
|
45453
|
+
const percentage = new Intl.NumberFormat("en-US", {
|
|
45454
|
+
style: "percent",
|
|
45455
|
+
minimumFractionDigits: 1,
|
|
45456
|
+
maximumFractionDigits: 1
|
|
45457
|
+
});
|
|
45458
|
+
const share2 = (value5) => cost > 0 ? percentage.format(value5 / cost) : "—";
|
|
45459
|
+
const number4 = new Intl.NumberFormat("en-US", { useGrouping: grouped2 });
|
|
45460
|
+
const dollars = new Intl.NumberFormat("en-US", {
|
|
45461
|
+
style: "currency",
|
|
45462
|
+
currency: "USD",
|
|
45463
|
+
useGrouping: grouped2
|
|
45464
|
+
});
|
|
45465
|
+
let allTokens = zeroTokens;
|
|
45466
|
+
const rows = [];
|
|
45467
|
+
const ranked = [...projects].toSorted(([leftProject, left], [rightProject, right]) => right.cost - left.cost || leftProject.localeCompare(rightProject));
|
|
45468
|
+
for (const [project, total] of ranked) {
|
|
45469
|
+
rows.push([
|
|
45470
|
+
project,
|
|
45471
|
+
number4.format(total.tokens.input),
|
|
45472
|
+
number4.format(total.tokens.cacheRead),
|
|
45473
|
+
number4.format(total.tokens.cacheWrite),
|
|
45474
|
+
number4.format(total.tokens.output),
|
|
45475
|
+
`${dollars.format(total.cost)}${total.unpriced ? " + unknown" : ""}`,
|
|
45476
|
+
share2(total.cost)
|
|
45477
|
+
]);
|
|
45478
|
+
allTokens = addTokens(allTokens, total.tokens);
|
|
45479
|
+
}
|
|
45480
|
+
if (projects.size > 0)
|
|
45481
|
+
rows.push([
|
|
45482
|
+
"Total",
|
|
45483
|
+
number4.format(allTokens.input),
|
|
45484
|
+
number4.format(allTokens.cacheRead),
|
|
45485
|
+
number4.format(allTokens.cacheWrite),
|
|
45486
|
+
number4.format(allTokens.output),
|
|
45487
|
+
`${dollars.format(cost)}${unpriced ? " + unknown" : ""}`,
|
|
45488
|
+
share2(cost)
|
|
45489
|
+
]);
|
|
45490
|
+
return { headings, rows, allTokens, unpriced, projectCount: projects.size };
|
|
45491
|
+
}
|
|
45492
|
+
function table2(report, columns = 120, colorful = false) {
|
|
45493
|
+
const paint = (format10, value5) => colorful ? styleText(format10, value5, { validateStream: false }) : value5;
|
|
45494
|
+
const { headings, rows, allTokens, unpriced, projectCount } = projectSummary(report, true);
|
|
45495
|
+
const number4 = new Intl.NumberFormat("en-US");
|
|
45496
|
+
if (projectCount === 0)
|
|
45497
|
+
return `No observed usage from ${report.since} through ${report.until} (${report.timeZone}).`;
|
|
45498
|
+
const numericWidths = headings.slice(1).map((heading, i) => Math.max(heading.length, ...rows.map((row) => row[i + 1]?.length ?? 0)) + 2);
|
|
45499
|
+
const projectWidth = columns - numericWidths.reduce((sum3, width2) => sum3 + width2, 0) - (headings.length + 1);
|
|
45500
|
+
const narrow = projectWidth < 22;
|
|
45501
|
+
const colWidths = narrow ? [16, Math.max(4, columns - 19)] : [Math.min(50, projectWidth), ...numericWidths];
|
|
45502
|
+
const output = new import_cli_table3.default({
|
|
45503
|
+
head: narrow ? [] : headings.map((heading) => paint(["bold", "cyan"], heading)),
|
|
45504
|
+
colWidths,
|
|
45505
|
+
colAligns: narrow ? ["left", "right"] : ["left", "right", "right", "right", "right", "right", "right"],
|
|
45506
|
+
wordWrap: false,
|
|
45507
|
+
style: { head: [], border: [] }
|
|
45508
|
+
});
|
|
45509
|
+
const projectColors = [
|
|
45510
|
+
"cyan",
|
|
45511
|
+
"blueBright",
|
|
45512
|
+
"magenta",
|
|
45513
|
+
"yellow",
|
|
45514
|
+
"green",
|
|
45515
|
+
"cyanBright"
|
|
45516
|
+
];
|
|
45517
|
+
for (const [index2, row] of rows.entries()) {
|
|
45518
|
+
const styled = row.map((value5, column) => {
|
|
45519
|
+
const width2 = narrow ? column === 0 ? columns - 4 : columns - 21 : (colWidths[column] ?? 4) - 2;
|
|
45520
|
+
const cell = wrapAnsi(terminalText(value5), Math.max(2, width2), {
|
|
45521
|
+
hard: true,
|
|
45522
|
+
wordWrap: false,
|
|
45523
|
+
trim: false
|
|
45524
|
+
});
|
|
45525
|
+
if (index2 === rows.length - 1)
|
|
45526
|
+
return paint(["bold", "magenta"], cell);
|
|
45527
|
+
if (column === 0)
|
|
45528
|
+
return paint(projectColors[index2 % projectColors.length] ?? "cyan", cell);
|
|
45529
|
+
if (column >= headings.length - 2)
|
|
45530
|
+
return paint(value5.includes("unknown") ? "yellow" : "green", cell);
|
|
45531
|
+
return cell === "0" ? paint("dim", cell) : cell;
|
|
45532
|
+
});
|
|
45533
|
+
if (narrow) {
|
|
45534
|
+
output.push([{ content: styled[0] ?? "", colSpan: 2, hAlign: "left" }]);
|
|
45535
|
+
for (const [i, heading] of headings.slice(1).entries()) {
|
|
45536
|
+
output.push([paint("cyan", heading), styled[i + 1] ?? ""]);
|
|
45537
|
+
}
|
|
45538
|
+
} else {
|
|
45539
|
+
output.push(styled);
|
|
45540
|
+
}
|
|
45541
|
+
}
|
|
45542
|
+
return [
|
|
45543
|
+
`${paint(["bold", "cyan"], colorful ? "⚡ Token Ledger" : "Token Ledger")} · ${paint("dim", `${report.since} through ${report.until} (${report.timeZone})`)}`,
|
|
45544
|
+
"",
|
|
45545
|
+
output.toString(),
|
|
45546
|
+
"",
|
|
45547
|
+
paint("bold", `${colorful ? "\uD83D\uDCCA " : ""}${number4.format(totalTokens(allTokens))} observed tokens · ${number4.format(projectCount)} ${projectCount === 1 ? "project" : "projects"}`),
|
|
45548
|
+
...unpriced > 0 ? [
|
|
45549
|
+
paint("yellow", "Incomplete pricing: sorting and percentages use known API subtotals; unknown costs are additional.")
|
|
45550
|
+
] : [],
|
|
45551
|
+
paint("dim", "USD API-equivalent estimates; not your subscription bill.")
|
|
45552
|
+
].join(`
|
|
45553
|
+
`);
|
|
45554
|
+
}
|
|
45555
|
+
function syncSummary(payload, request3, storedBuckets) {
|
|
45556
|
+
const number4 = new Intl.NumberFormat("en-US");
|
|
45557
|
+
const dollars = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" });
|
|
45558
|
+
const sessions = new Set(payload.buckets.map((bucket) => bucket.sessionKey)).size;
|
|
45559
|
+
const cost = payload.buckets.reduce((sum3, bucket) => sum3 + (bucket.estimatedCostUsd ?? 0), 0);
|
|
45560
|
+
const unknown2 = payload.buckets.some((bucket) => bucket.estimatedCostUsd === null);
|
|
45561
|
+
return [
|
|
45562
|
+
`Synced ${terminalText(payload.machine.label)} · ${request3.since} through ${request3.until} (${payload.timeZone})`,
|
|
45563
|
+
[
|
|
45564
|
+
`${number4.format(payload.buckets.length)} hourly buckets`,
|
|
45565
|
+
`${number4.format(sessions)} sessions`,
|
|
45566
|
+
`${dollars.format(cost)}${unknown2 ? " + unknown" : ""} API estimate`,
|
|
45567
|
+
exports_Option.match(storedBuckets, {
|
|
45568
|
+
onNone: () => "accepted by the server",
|
|
45569
|
+
onSome: (stored) => `server stored ${number4.format(stored)}`
|
|
43920
45570
|
})
|
|
43921
|
-
]
|
|
43922
|
-
|
|
43923
|
-
uninstall: [
|
|
43924
|
-
run6("reported", "schtasks.exe", ["/Delete", "/TN", task, "/F"]),
|
|
43925
|
-
run6("absent", "schtasks.exe", ["/Query", "/TN", task], "The task is still registered; Task Scheduler's reason is shown above.")
|
|
43926
|
-
],
|
|
43927
|
-
status: [run6("reported", "schtasks.exe", ["/Query", "/TN", task, "/V", "/FO", "LIST"])]
|
|
43928
|
-
};
|
|
43929
|
-
var hostScheduler = exports_Effect.gen(function* () {
|
|
43930
|
-
const path = yield* exports_Path.Path;
|
|
43931
|
-
const home = homedir2();
|
|
43932
|
-
const units = exports_Option.getOrElse(yield* configHome, () => path.join(home, ".config"));
|
|
43933
|
-
return yield* exports_Match.value(process.platform).pipe(exports_Match.when("linux", () => exports_Effect.succeed(systemdTimer(path.join(units, "systemd", "user")))), exports_Match.when("darwin", () => exports_Effect.succeed(launchAgent(home, userInfo().uid))), exports_Match.when("win32", () => exports_Effect.succeed(taskScheduler)), exports_Match.orElse((platform) => exports_Effect.fail(new ScheduleError({
|
|
43934
|
-
message: `No scheduler is supported on ${platform}; schedule token-ledger sync yourself.`
|
|
43935
|
-
}))));
|
|
43936
|
-
});
|
|
43937
|
-
var describe = (actions) => actions.map(Action3.$match({
|
|
43938
|
-
Write: ({ file: file2, contents }) => `write ${file2}
|
|
43939
|
-
${contents.replaceAll(/^(?=.)/gm, " ")}`,
|
|
43940
|
-
Remove: ({ file: file2 }) => `remove ${file2}
|
|
43941
|
-
`,
|
|
43942
|
-
Run: ({ shown }) => `run ${shown}
|
|
43943
|
-
`
|
|
43944
|
-
})).join(`
|
|
45571
|
+
].join(" · ")
|
|
45572
|
+
].join(`
|
|
43945
45573
|
`);
|
|
43946
|
-
|
|
43947
|
-
const fs = yield* exports_FileSystem.FileSystem;
|
|
43948
|
-
const path = yield* exports_Path.Path;
|
|
43949
|
-
const spawner = yield* exports_ChildProcessSpawner.ChildProcessSpawner;
|
|
43950
|
-
for (const action of actions)
|
|
43951
|
-
yield* Action3.$match(action, {
|
|
43952
|
-
Write: ({ file: file2, contents }) => fs.makeDirectory(path.dirname(file2), { recursive: true }).pipe(exports_Effect.andThen(fs.writeFileString(file2, contents)), exports_Effect.mapError(() => new ScheduleError({ message: `Cannot write ${file2}.` }))),
|
|
43953
|
-
Remove: ({ file: file2 }) => fs.remove(file2, { force: true }).pipe(exports_Effect.mapError(() => new ScheduleError({ message: `Cannot remove ${file2}.` }))),
|
|
43954
|
-
Run: ({ program, args: args2, outcome, hint, gone }) => {
|
|
43955
|
-
const output = outcome === "silent" || outcome === "absent" ? "ignore" : "inherit";
|
|
43956
|
-
const exit3 = spawner.exitCode(exports_ChildProcess.make(program, args2, { stdin: "ignore", stdout: output, stderr: output })).pipe(exports_Effect.mapError(() => new ScheduleError({ message: `Cannot run ${program}. ${hint}`.trim() })));
|
|
43957
|
-
return exports_Match.value(outcome).pipe(exports_Match.when("required", () => exports_Effect.filterOrFail(exit3, (code) => code === 0, (code) => new ScheduleError({
|
|
43958
|
-
message: `${[program, ...args2.slice(0, 2)].join(" ")} failed with exit code ${code}. ${hint}`.trim()
|
|
43959
|
-
}))), exports_Match.when("reported", () => exit3), exports_Match.when("silent", () => exports_Effect.ignore(exit3)), exports_Match.when("absent", () => exit3.pipe(exports_Effect.map((code) => gone.length === 0 ? code !== 0 : gone.includes(code)), exports_Effect.orElseSucceed(() => true), exports_Effect.filterOrFail((confirmed) => confirmed, () => new ScheduleError({ message: hint })))), exports_Match.exhaustive);
|
|
43960
|
-
}
|
|
43961
|
-
});
|
|
43962
|
-
});
|
|
45574
|
+
}
|
|
43963
45575
|
|
|
43964
45576
|
// packages/cli/src/upload.ts
|
|
43965
45577
|
class SyncUnreachable extends exports_Schema.TaggedError()("SyncUnreachable", {
|
|
@@ -44028,7 +45640,7 @@ function usageFlags(sinceDefault, strict) {
|
|
|
44028
45640
|
since: exports_Flag.String("since").pipe(exports_Flag.withSchema(Day), exports_Flag.optional, exports_Flag.withDescription(`First local day, inclusive; defaults to ${sinceDefault}`)),
|
|
44029
45641
|
until: exports_Flag.String("until").pipe(exports_Flag.withSchema(Day), exports_Flag.optional, exports_Flag.withDescription("Last local day, inclusive; defaults to today")),
|
|
44030
45642
|
timeZone: exports_Flag.String("time-zone").pipe(exports_Flag.withSchema(exports_Schema.TimeZoneNamedFromString), exports_Flag.optional, exports_Flag.withDescription("IANA time zone for days and the window, such as Europe/Stockholm; defaults to the system zone")),
|
|
44031
|
-
provider: exports_Flag.Literals("provider", ["all", "codex", "claude", "grok", "copilot"]).pipe(exports_Flag.withDefault("all")),
|
|
45643
|
+
provider: exports_Flag.Literals("provider", ["all", "codex", "claude", "grok", "copilot", "pi"]).pipe(exports_Flag.withDefault("all")),
|
|
44032
45644
|
project: exports_Flag.String("project").pipe(exports_Flag.withSchema(ProjectName), exports_Flag.optional, exports_Flag.withDescription("Assign all selected usage to this project")),
|
|
44033
45645
|
config: exports_Flag.String("config").pipe(exports_Flag.optional, exports_Flag.withDescription("JSON config; otherwise reads ./token-ledger.json when present")),
|
|
44034
45646
|
offline: exports_Flag.Boolean("offline").pipe(exports_Flag.withDefault(false), exports_Flag.withDescription("Use only cached and configured prices")),
|
|
@@ -44053,15 +45665,18 @@ var usageRequest = exports_Effect.fn("CLI.usageRequest")(function* (flags, defau
|
|
|
44053
45665
|
const grokHome = yield* exports_Config.String("GROK_HOME").pipe(exports_Config.withDefault(path.join(home, ".grok")));
|
|
44054
45666
|
const copilotHome = yield* exports_Config.String("COPILOT_HOME").pipe(exports_Config.withDefault(path.join(home, ".copilot")));
|
|
44055
45667
|
const copilotFile = yield* exports_Config.String("COPILOT_OTEL_FILE_EXPORTER_PATH").pipe(exports_Config.option);
|
|
45668
|
+
const piHome = yield* exports_Config.String("PI_CODING_AGENT_DIR").pipe(exports_Config.withDefault(path.join(home, ".pi", "agent")));
|
|
45669
|
+
const piSessions = yield* exports_Config.String("PI_CODING_AGENT_SESSION_DIR").pipe(exports_Config.option);
|
|
44056
45670
|
const defaults2 = [
|
|
44057
45671
|
{ provider: "codex", path: path.join(expand(codexHome), "sessions") },
|
|
44058
45672
|
{ provider: "codex", path: path.join(expand(codexHome), "archived_sessions") },
|
|
44059
45673
|
{ provider: "claude", path: path.join(expand(claudeHome), "projects") },
|
|
44060
45674
|
{ provider: "grok", path: path.join(expand(grokHome), "sessions") },
|
|
45675
|
+
...(yield* copilotSources(path.join(expand(copilotHome), "otel"), exports_Option.map(copilotFile, (value5) => expand(value5)))).map((source) => ({ provider: "copilot", path: source })),
|
|
44061
45676
|
{
|
|
44062
|
-
provider: "
|
|
44063
|
-
path: exports_Option.match(
|
|
44064
|
-
onNone: () => path.join(expand(
|
|
45677
|
+
provider: "pi",
|
|
45678
|
+
path: exports_Option.match(piSessions, {
|
|
45679
|
+
onNone: () => path.join(expand(piHome), "sessions"),
|
|
44065
45680
|
onSome: (value5) => expand(value5)
|
|
44066
45681
|
})
|
|
44067
45682
|
}
|
|
@@ -44075,7 +45690,7 @@ var usageRequest = exports_Effect.fn("CLI.usageRequest")(function* (flags, defau
|
|
|
44075
45690
|
if (exports_Option.isSome(flags.source)) {
|
|
44076
45691
|
if (flags.provider === "all")
|
|
44077
45692
|
return yield* new CliError2({
|
|
44078
|
-
message: "--source requires --provider codex, claude, grok, or
|
|
45693
|
+
message: "--source requires --provider codex, claude, grok, copilot, or pi."
|
|
44079
45694
|
});
|
|
44080
45695
|
sources = [{ provider: flags.provider, path: expand(flags.source.value) }];
|
|
44081
45696
|
}
|
|
@@ -44206,7 +45821,7 @@ var scheduleInstall = exports_Command.make("install", {
|
|
|
44206
45821
|
at: exports_Flag.String("at").pipe(exports_Flag.withDefault("12:30"), exports_Flag.withSchema(TimeOfDay), exports_Flag.withDescription("Daily local time as HH:MM; defaults to 12:30")),
|
|
44207
45822
|
config: exports_Flag.String("config").pipe(exports_Flag.optional, exports_Flag.withDescription("JSON config for the scheduled sync; ./token-ledger.json is not read")),
|
|
44208
45823
|
timeZone: exports_Flag.String("time-zone").pipe(exports_Flag.withSchema(exports_Schema.TimeZoneNamedFromString), exports_Flag.optional, exports_Flag.withDescription("IANA time zone for the scheduled sync; defaults to the system zone")),
|
|
44209
|
-
provider: exports_Flag.Literals("provider", ["all", "codex", "claude", "grok", "copilot"]).pipe(exports_Flag.withDefault("all")),
|
|
45824
|
+
provider: exports_Flag.Literals("provider", ["all", "codex", "claude", "grok", "copilot", "pi"]).pipe(exports_Flag.withDefault("all")),
|
|
44210
45825
|
dryRun: exports_Flag.Boolean("dry-run").pipe(exports_Flag.withDefault(false), exports_Flag.withDescription("Print the files and commands; change nothing"))
|
|
44211
45826
|
}, exports_Effect.fn("CLI.scheduleInstall")(function* (flags) {
|
|
44212
45827
|
const fs = yield* exports_FileSystem.FileSystem;
|
|
@@ -44249,6 +45864,65 @@ var scheduleUninstall = exports_Command.make("uninstall", {}, exports_Effect.fn(
|
|
|
44249
45864
|
yield* exports_Console.log(`Removed the ${scheduler.name}. Saved settings were kept.`);
|
|
44250
45865
|
})).pipe(exports_Command.withDescription("Remove the daily sync; saved settings stay"));
|
|
44251
45866
|
var schedule4 = exports_Command.make("schedule").pipe(exports_Command.withDescription("Run sync daily with systemd, launchd, or Task Scheduler"), exports_Command.withSubcommands([scheduleInstall, scheduleStatus, scheduleUninstall]));
|
|
45867
|
+
var copilotEnable = exports_Command.make("enable", {
|
|
45868
|
+
cli: exports_Flag.Boolean("cli").pipe(exports_Flag.withDefault(false), exports_Flag.withDescription("Copilot CLI: export its usage from every new terminal")),
|
|
45869
|
+
vscode: exports_Flag.Boolean("vscode").pipe(exports_Flag.withDefault(false), exports_Flag.withDescription("VS Code Copilot Chat: set its export in the user settings.json")),
|
|
45870
|
+
yes: exports_Flag.Boolean("yes").pipe(exports_Flag.withDefault(false), exports_Flag.withDescription("Make the listed changes without asking")),
|
|
45871
|
+
dryRun: exports_Flag.Boolean("dry-run").pipe(exports_Flag.withDefault(false), exports_Flag.withDescription("Print the changes; change nothing")),
|
|
45872
|
+
allowRoot: exports_Flag.Boolean("allow-root").pipe(exports_Flag.withDefault(false), exports_Flag.withDescription("Run as root, where root is the account that uses Copilot"))
|
|
45873
|
+
}, exports_Effect.fn("CLI.copilotEnable")(function* (flags) {
|
|
45874
|
+
const path = yield* exports_Path.Path;
|
|
45875
|
+
const copilotHome = yield* exports_Config.String("COPILOT_HOME").pipe(exports_Config.withDefault(path.join(home, ".copilot")));
|
|
45876
|
+
const host = {
|
|
45877
|
+
platform: process.platform,
|
|
45878
|
+
home,
|
|
45879
|
+
uid: exports_Option.fromUndefinedOr(process.getuid?.()),
|
|
45880
|
+
copilotHome: expandPath(path, copilotHome),
|
|
45881
|
+
shell: yield* exports_Config.String("SHELL").pipe(exports_Config.option),
|
|
45882
|
+
zshDirectory: yield* exports_Config.String("ZDOTDIR").pipe(exports_Config.option),
|
|
45883
|
+
configHome: yield* configHome,
|
|
45884
|
+
appData: yield* exports_Config.String("APPDATA").pipe(exports_Config.option),
|
|
45885
|
+
exporter: exports_Option.map(yield* exports_Config.String("COPILOT_OTEL_FILE_EXPORTER_PATH").pipe(exports_Config.option), (file2) => expandPath(path, file2))
|
|
45886
|
+
};
|
|
45887
|
+
const stop = (message) => exports_Console.error(message).pipe(exports_Effect.andThen(exports_Effect.sync(() => {
|
|
45888
|
+
process.exitCode = 1;
|
|
45889
|
+
})));
|
|
45890
|
+
const planned = yield* plan(host, {
|
|
45891
|
+
cli: flags.cli || !flags.vscode,
|
|
45892
|
+
vscode: flags.vscode || !flags.cli,
|
|
45893
|
+
allowRoot: flags.allowRoot
|
|
45894
|
+
}).pipe(exports_Effect.result);
|
|
45895
|
+
if (exports_Result.isFailure(planned))
|
|
45896
|
+
return yield* stop(planned.failure.message);
|
|
45897
|
+
const { directory, steps } = planned.success;
|
|
45898
|
+
const incomplete = (results3) => {
|
|
45899
|
+
if (results3.some(Step.$is("ByHand")))
|
|
45900
|
+
process.exitCode = 2;
|
|
45901
|
+
};
|
|
45902
|
+
if (!steps.some(Step.$is("Change"))) {
|
|
45903
|
+
yield* exports_Console.log(steps.some(Step.$is("ByHand")) ? describe2(steps) : `Copilot's usage export is already on; nothing to change.
|
|
45904
|
+
|
|
45905
|
+
${describe2(steps)}`);
|
|
45906
|
+
return incomplete(steps);
|
|
45907
|
+
}
|
|
45908
|
+
yield* exports_Console.log(`${describe2(steps)}
|
|
45909
|
+
`);
|
|
45910
|
+
if (flags.dryRun)
|
|
45911
|
+
return incomplete(steps);
|
|
45912
|
+
if (!flags.yes) {
|
|
45913
|
+
if (!process.stdin.isTTY)
|
|
45914
|
+
return yield* stop("Nothing was changed: there is no terminal to ask on. Run it again with --yes to make these changes.");
|
|
45915
|
+
const agreed = yield* exports_Prompt.run(exports_Prompt.Confirm({ message: "Make these changes?", initial: true })).pipe(exports_Effect.orElseSucceed(() => false));
|
|
45916
|
+
if (!agreed)
|
|
45917
|
+
return yield* stop("Nothing was changed.");
|
|
45918
|
+
}
|
|
45919
|
+
const results2 = yield* perform2(steps).pipe(exports_Effect.result);
|
|
45920
|
+
if (exports_Result.isFailure(results2))
|
|
45921
|
+
return yield* stop(results2.failure.message);
|
|
45922
|
+
yield* exports_Console.log(summarize(results2.success, directory));
|
|
45923
|
+
return incomplete(results2.success);
|
|
45924
|
+
})).pipe(exports_Command.withDescription("Switch on Copilot's local usage export, after listing the changes and asking"));
|
|
45925
|
+
var copilot = exports_Command.make("copilot").pipe(exports_Command.withDescription("Set up Copilot CLI and VS Code Copilot Chat to record usage"), exports_Command.withSubcommands([copilotEnable]));
|
|
44252
45926
|
var example = exports_Command.make("config-example", {}, () => exports_Console.log(JSON.stringify({
|
|
44253
45927
|
projects: [
|
|
44254
45928
|
{
|
|
@@ -44259,4 +45933,4 @@ var example = exports_Command.make("config-example", {}, () => exports_Console.l
|
|
|
44259
45933
|
],
|
|
44260
45934
|
prices: { "example-model": { input: 2, output: 10, cacheRead: 0.2, cacheWrite: null } }
|
|
44261
45935
|
}, null, 2))).pipe(exports_Command.withDescription("Print an example configuration to customize"));
|
|
44262
|
-
exports_Command.make("token-ledger").pipe(exports_Command.withDescription("Local token accounting across coding agents. API estimates, not subscription bills."), exports_Command.withSubcommands([report, sync6, login, schedule4, example]), exports_Command.run({ version: package_default.version }), exports_Effect.provide(Ledger.layer), exports_Effect.provide(exports_NodeServices.layer), exports_Effect.provide(exports_FetchHttpClient.layer), exports_NodeRuntime.runMain);
|
|
45936
|
+
exports_Command.make("token-ledger").pipe(exports_Command.withDescription("Local token accounting across coding agents. API estimates, not subscription bills."), exports_Command.withSubcommands([report, sync6, login, schedule4, copilot, example]), exports_Command.run({ version: package_default.version }), exports_Effect.provide(Ledger.layer), exports_Effect.provide(exports_NodeServices.layer), exports_Effect.provide(exports_FetchHttpClient.layer), exports_NodeRuntime.runMain);
|