@ponbac/token-ledger 0.11.0 → 0.11.2
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 +17 -1
- package/dist/main.js +163 -28
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -447,6 +447,22 @@ their common Git directory. Relative config paths resolve from the config file;
|
|
|
447
447
|
`~/` resolves from the current developer's home. Directory mappings respect path
|
|
448
448
|
boundaries, so `/work/app` never matches `/work/application`.
|
|
449
449
|
|
|
450
|
+
The CLI remembers network repository identities in its local application data directory
|
|
451
|
+
(`$XDG_DATA_HOME/token-ledger/repositories`, normally
|
|
452
|
+
`~/.local/share/token-ledger/repositories`; on Windows under `%LOCALAPPDATA%`, and on
|
|
453
|
+
macOS under `~/Library/Application Support`). Once a scan has saved a checkout or
|
|
454
|
+
worktree's network origin, later scans keep its repository even after that directory is deleted.
|
|
455
|
+
The nearest live or remembered repository wins, and explicit mappings take precedence; an existing directory
|
|
456
|
+
without Git is never assigned from an old identity. Each directory is keyed by a
|
|
457
|
+
hash, and saved identities omit credentials. Observing a local or absent origin
|
|
458
|
+
invalidates its former network identity, including after the directory is deleted.
|
|
459
|
+
The same applies to a remembered root observed to exist without Git metadata.
|
|
460
|
+
A history read or write failure stops
|
|
461
|
+
a real upload rather than replacing known attribution with missing metadata.
|
|
462
|
+
Local reports and dry runs warn about history failures and continue; they also
|
|
463
|
+
remember identities when the history directory is writable.
|
|
464
|
+
This history cannot recover directories deleted before the first scan with it.
|
|
465
|
+
|
|
450
466
|
Grok logs currently lack project metadata in the usage parser. Copilot CLI can put
|
|
451
467
|
repository metadata on a parent agent span rather than the counted request span;
|
|
452
468
|
Token Ledger associates the two. If an export has no repository metadata, use a
|
|
@@ -946,7 +962,7 @@ For manual publication:
|
|
|
946
962
|
1. Log in with `npm login` using an account with publish access to `@ponbac/token-ledger`.
|
|
947
963
|
2. Run `bun run check`. The CLI test packs the package, installs it offline outside
|
|
948
964
|
the repository with lifecycle scripts disabled, and exercises the installed CLI.
|
|
949
|
-
3. Run `bun run pack` to create `dist/ponbac-token-ledger-0.11.
|
|
965
|
+
3. Run `bun run pack` to create `dist/ponbac-token-ledger-0.11.2.tgz` (filename follows version).
|
|
950
966
|
4. Inspect `npm publish ./dist/npm --dry-run`.
|
|
951
967
|
5. Publish with `npm publish ./dist/npm --access public`; complete npm's authentication
|
|
952
968
|
prompt if requested.
|
package/dist/main.js
CHANGED
|
@@ -32791,6 +32791,10 @@ var Day = exports_Schema.String.check(exports_Schema.isPattern(/^\d{4}-\d{2}-\d{
|
|
|
32791
32791
|
return Number.isFinite(date2.getTime()) && date2.toISOString().slice(0, 10) === s;
|
|
32792
32792
|
}));
|
|
32793
32793
|
var ReportRequest = exports_Schema.Struct({
|
|
32794
|
+
repositoryHistory: exports_Schema.optionalKey(exports_Schema.Struct({
|
|
32795
|
+
directory: exports_Schema.NonEmptyString,
|
|
32796
|
+
required: exports_Schema.Boolean
|
|
32797
|
+
})),
|
|
32794
32798
|
billingHints: exports_Schema.optionalKey(exports_Schema.Struct({ directory: exports_Schema.NonEmptyString, required: exports_Schema.Boolean })),
|
|
32795
32799
|
since: Day,
|
|
32796
32800
|
until: Day,
|
|
@@ -34309,9 +34313,49 @@ var fetch = /* @__PURE__ */ make48((request3, url, signal, fiber3) => {
|
|
|
34309
34313
|
var layer14 = /* @__PURE__ */ layerMergedContext(/* @__PURE__ */ succeed6(fetch));
|
|
34310
34314
|
// packages/core/src/copilot-rates.json
|
|
34311
34315
|
var copilot_rates_default = {
|
|
34312
|
-
version: "2026-
|
|
34316
|
+
version: "2026-11-17",
|
|
34313
34317
|
description: "GitHub Copilot's AI credit rates in USD per million tokens (1 credit = $0.01). effectiveFrom is the UTC day a rate took effect: the day GitHub's usage report starts billing it where that is known, otherwise the day of the GitHub docs change that listed it; 2026-08-21 is the oldest version read, and a model's first entry also prices its earlier usage. long applies to the whole request when input + cacheRead + cacheWrite exceeds its above. uncachedInput cacheWrite bills all but three uncached input tokens at the cache-write rate when a record reports no cache writes. confirmed entries match GitHub's bills or usage report; provisional ones have not been matched yet.",
|
|
34314
34318
|
entries: [
|
|
34319
|
+
{
|
|
34320
|
+
model: "gpt-6.2-astra",
|
|
34321
|
+
effectiveFrom: "2026-11-17",
|
|
34322
|
+
status: "provisional",
|
|
34323
|
+
source: "https://docs.github.com/en/copilot/reference/copilot-billing/models-and-pricing",
|
|
34324
|
+
uncachedInput: "cacheWrite",
|
|
34325
|
+
base: {
|
|
34326
|
+
input: 8,
|
|
34327
|
+
cacheRead: 0.4,
|
|
34328
|
+
cacheWrite: 10,
|
|
34329
|
+
output: 40
|
|
34330
|
+
},
|
|
34331
|
+
long: {
|
|
34332
|
+
above: 272000,
|
|
34333
|
+
input: 16,
|
|
34334
|
+
cacheRead: 0.8,
|
|
34335
|
+
cacheWrite: 20,
|
|
34336
|
+
output: 60
|
|
34337
|
+
}
|
|
34338
|
+
},
|
|
34339
|
+
{
|
|
34340
|
+
model: "gpt-6.2-sol",
|
|
34341
|
+
effectiveFrom: "2026-11-17",
|
|
34342
|
+
status: "provisional",
|
|
34343
|
+
source: "https://docs.github.com/en/copilot/reference/copilot-billing/models-and-pricing",
|
|
34344
|
+
uncachedInput: "cacheWrite",
|
|
34345
|
+
base: {
|
|
34346
|
+
input: 2,
|
|
34347
|
+
cacheRead: 0.1,
|
|
34348
|
+
cacheWrite: 2.5,
|
|
34349
|
+
output: 10
|
|
34350
|
+
},
|
|
34351
|
+
long: {
|
|
34352
|
+
above: 272000,
|
|
34353
|
+
input: 4,
|
|
34354
|
+
cacheRead: 0.2,
|
|
34355
|
+
cacheWrite: 5,
|
|
34356
|
+
output: 15
|
|
34357
|
+
}
|
|
34358
|
+
},
|
|
34315
34359
|
{
|
|
34316
34360
|
model: "gpt-6.1-sol",
|
|
34317
34361
|
effectiveFrom: "2026-09-29",
|
|
@@ -35011,6 +35055,63 @@ function priceRecord(record3, vendor) {
|
|
|
35011
35055
|
return { usd, base };
|
|
35012
35056
|
}
|
|
35013
35057
|
|
|
35058
|
+
// packages/core/src/repository-history.ts
|
|
35059
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
35060
|
+
class RepositoryHistoryError extends exports_Schema.TaggedError()("RepositoryHistoryError", { message: exports_Schema.String }) {
|
|
35061
|
+
}
|
|
35062
|
+
var Entry = exports_Schema.Struct({
|
|
35063
|
+
version: exports_Schema.Literal(1),
|
|
35064
|
+
repository: exports_Schema.NullOr(exports_Schema.NonEmptyString.check(exports_Schema.isPattern(/^[^/\s@]+\/[^\r\n]+$/u)))
|
|
35065
|
+
});
|
|
35066
|
+
var repositoryHistory = exports_Effect.fn("RepositoryHistory.open")(function* (config, onWarning) {
|
|
35067
|
+
const fs = yield* exports_FileSystem.FileSystem;
|
|
35068
|
+
const path = yield* exports_Path.Path;
|
|
35069
|
+
const pending = new Map;
|
|
35070
|
+
const loaded = new Map;
|
|
35071
|
+
const directory = config?.directory;
|
|
35072
|
+
const filename = (root) => `${createHash3("sha256").update(path.resolve(root)).digest("hex")}.json`;
|
|
35073
|
+
const recover = (error2) => config?.required ? exports_Effect.fail(error2) : onWarning?.(error2.message) ?? exports_Effect.void;
|
|
35074
|
+
const read2 = exports_Effect.fn("RepositoryHistory.read")(function* (root) {
|
|
35075
|
+
if (directory === undefined)
|
|
35076
|
+
return null;
|
|
35077
|
+
const key = filename(root);
|
|
35078
|
+
const observed = pending.get(key);
|
|
35079
|
+
if (observed !== undefined)
|
|
35080
|
+
return observed;
|
|
35081
|
+
const cached3 = loaded.get(key);
|
|
35082
|
+
if (cached3 !== undefined)
|
|
35083
|
+
return cached3;
|
|
35084
|
+
const file2 = path.join(directory, key);
|
|
35085
|
+
const saved = yield* fs.readFileString(file2).pipe(exports_Effect.catchTag("PlatformError", (error2) => exports_Predicate.isTagged(error2.reason, "NotFound") ? exports_Effect.succeed(null) : exports_Effect.fail(error2)), exports_Effect.flatMap((text2) => text2 === null ? exports_Effect.succeed(null) : exports_Schema.decodeUnknownEffect(exports_Schema.fromJsonString(Entry))(text2)), exports_Effect.mapError(() => new RepositoryHistoryError({
|
|
35086
|
+
message: `Cannot read repository history at ${file2}. Fix its permissions or repair its contents before syncing. If it is damaged beyond repair, remove only this file; attribution for that deleted directory will then be unknown until restored.`
|
|
35087
|
+
})), exports_Effect.catchTag("RepositoryHistoryError", (error2) => recover(error2).pipe(exports_Effect.as(null))));
|
|
35088
|
+
loaded.set(key, saved);
|
|
35089
|
+
return saved;
|
|
35090
|
+
});
|
|
35091
|
+
const remember = (root, repository) => {
|
|
35092
|
+
const entry = exports_Schema.decodeUnknownOption(Entry)({ version: 1, repository });
|
|
35093
|
+
if (directory !== undefined && exports_Option.isSome(entry))
|
|
35094
|
+
pending.set(filename(root), entry.value);
|
|
35095
|
+
};
|
|
35096
|
+
const flush = exports_Effect.fn("RepositoryHistory.save")(function* () {
|
|
35097
|
+
if (directory === undefined || pending.size === 0)
|
|
35098
|
+
return;
|
|
35099
|
+
yield* exports_Effect.gen(function* () {
|
|
35100
|
+
yield* fs.makeDirectory(directory, { recursive: true, mode: 448 });
|
|
35101
|
+
for (const [key, entry] of pending) {
|
|
35102
|
+
const temporary = yield* fs.makeTempFileScoped({ directory, prefix: ".repository-" });
|
|
35103
|
+
yield* fs.writeFileString(temporary, JSON.stringify(entry) + `
|
|
35104
|
+
`);
|
|
35105
|
+
yield* fs.chmod(temporary, 384);
|
|
35106
|
+
yield* fs.rename(temporary, path.join(directory, key));
|
|
35107
|
+
}
|
|
35108
|
+
}).pipe(exports_Effect.scoped, exports_Effect.mapError(() => new RepositoryHistoryError({
|
|
35109
|
+
message: `Cannot save repository history in ${directory}.${config?.required ? " Sync stopped to preserve attribution." : ""}`
|
|
35110
|
+
})), exports_Effect.catchTag("RepositoryHistoryError", recover));
|
|
35111
|
+
});
|
|
35112
|
+
return { read: read2, remember, flush };
|
|
35113
|
+
});
|
|
35114
|
+
|
|
35014
35115
|
// packages/core/src/projects.ts
|
|
35015
35116
|
var scpRemote = /^(?:[^/@\s]+@)?(\[[^\]\s]+\]|[^/:\\\s]+):((?!\/\/).+)$/;
|
|
35016
35117
|
function repositoryIdentity(remote) {
|
|
@@ -35029,9 +35130,10 @@ function isNetworkRemote(remote) {
|
|
|
35029
35130
|
const parsed = URL.parse(value5);
|
|
35030
35131
|
return parsed !== null && parsed.host !== "" ? ["http:", "https:", "ssh:", "git:", "ftp:", "ftps:"].includes(parsed.protocol) : scpRemote.test(value5);
|
|
35031
35132
|
}
|
|
35032
|
-
var projectResolver = exports_Effect.fn("Projects.resolver")(function* (mappings) {
|
|
35133
|
+
var projectResolver = exports_Effect.fn("Projects.resolver")(function* (mappings, historyConfig, onWarning) {
|
|
35033
35134
|
const fs = yield* exports_FileSystem.FileSystem;
|
|
35034
35135
|
const path = yield* exports_Path.Path;
|
|
35136
|
+
const history = yield* repositoryHistory(historyConfig, onWarning);
|
|
35035
35137
|
const resolved = new Map;
|
|
35036
35138
|
const readOptional = (file2) => fs.readFileString(file2).pipe(exports_Effect.option);
|
|
35037
35139
|
const discover = exports_Effect.fn("Projects.discover")(function* (cwd) {
|
|
@@ -35040,14 +35142,14 @@ var projectResolver = exports_Effect.fn("Projects.resolver")(function* (mappings
|
|
|
35040
35142
|
return cached3;
|
|
35041
35143
|
let current = cwd;
|
|
35042
35144
|
let root = cwd;
|
|
35043
|
-
let
|
|
35145
|
+
let repository = null;
|
|
35044
35146
|
while (true) {
|
|
35045
35147
|
const git = path.join(current, ".git");
|
|
35046
|
-
const stat3 = yield* fs.stat(git).pipe(exports_Effect.
|
|
35047
|
-
if (
|
|
35148
|
+
const stat3 = yield* fs.stat(git).pipe(exports_Effect.result);
|
|
35149
|
+
if (exports_Result.isSuccess(stat3)) {
|
|
35048
35150
|
root = current;
|
|
35049
35151
|
let gitDirectory = git;
|
|
35050
|
-
if (stat3.
|
|
35152
|
+
if (stat3.success.type === "File") {
|
|
35051
35153
|
const pointer = yield* readOptional(git);
|
|
35052
35154
|
const match10 = /^gitdir:\s*(.+)\s*$/m.exec(exports_Option.getOrElse(pointer, () => ""));
|
|
35053
35155
|
if (match10?.[1])
|
|
@@ -35061,26 +35163,40 @@ var projectResolver = exports_Effect.fn("Projects.resolver")(function* (mappings
|
|
|
35061
35163
|
const config = yield* readOptional(path.join(gitDirectory, "config"));
|
|
35062
35164
|
const origin = /\[remote "origin"\]([^[]*)/.exec(exports_Option.getOrElse(config, () => ""));
|
|
35063
35165
|
const url = /^\s*url\s*=\s*(.+)$/m.exec(origin?.[1] ?? "");
|
|
35064
|
-
if (url?.[1])
|
|
35065
|
-
remote = url[1].trim();
|
|
35166
|
+
if (url?.[1]) {
|
|
35167
|
+
const remote = url[1].trim();
|
|
35168
|
+
repository = RepositoryReference.Remote({ value: remote });
|
|
35169
|
+
}
|
|
35170
|
+
if (exports_Option.isSome(config))
|
|
35171
|
+
history.remember(current, url?.[1] && isNetworkRemote(url[1].trim()) ? repositoryIdentity(url[1].trim()) : null);
|
|
35066
35172
|
break;
|
|
35067
35173
|
}
|
|
35174
|
+
if (historyConfig !== undefined && exports_Predicate.isTagged(stat3.failure.reason, "NotFound")) {
|
|
35175
|
+
const exists2 = yield* fs.exists(current).pipe(exports_Effect.option);
|
|
35176
|
+
if (exports_Option.isSome(exists2)) {
|
|
35177
|
+
const previous = yield* history.read(current);
|
|
35178
|
+
if (previous !== null && !exists2.value) {
|
|
35179
|
+
root = current;
|
|
35180
|
+
repository = previous.repository === null ? null : RepositoryReference.Identity({ value: previous.repository });
|
|
35181
|
+
break;
|
|
35182
|
+
}
|
|
35183
|
+
if (previous !== null && previous.repository !== null)
|
|
35184
|
+
history.remember(current, null);
|
|
35185
|
+
}
|
|
35186
|
+
}
|
|
35068
35187
|
const parent = path.dirname(current);
|
|
35069
35188
|
if (parent === current)
|
|
35070
35189
|
break;
|
|
35071
35190
|
current = parent;
|
|
35072
35191
|
}
|
|
35073
|
-
const identity3 = { root,
|
|
35192
|
+
const identity3 = { root, repository };
|
|
35074
35193
|
resolved.set(cwd, identity3);
|
|
35075
35194
|
return identity3;
|
|
35076
35195
|
});
|
|
35077
|
-
|
|
35196
|
+
const resolve7 = exports_Effect.fn("Projects.resolve")(function* (record3, fixedProject) {
|
|
35078
35197
|
if (fixedProject !== undefined)
|
|
35079
35198
|
return { project: fixedProject, shareable: true };
|
|
35080
35199
|
const cwd = record3.cwd;
|
|
35081
|
-
const identity3 = cwd === null ? null : yield* discover(cwd);
|
|
35082
|
-
const rawRemote = record3.repository?.value ?? identity3?.remote ?? null;
|
|
35083
|
-
const remote = rawRemote === null ? null : repositoryIdentity(rawRemote);
|
|
35084
35200
|
let bestPath = null;
|
|
35085
35201
|
for (const mapping of mappings) {
|
|
35086
35202
|
for (const prefix3 of mapping.paths) {
|
|
@@ -35092,17 +35208,21 @@ var projectResolver = exports_Effect.fn("Projects.resolver")(function* (mappings
|
|
|
35092
35208
|
}
|
|
35093
35209
|
if (bestPath !== null)
|
|
35094
35210
|
return { project: bestPath.project, shareable: true };
|
|
35211
|
+
const identity3 = record3.repository !== null || cwd === null ? null : yield* discover(cwd);
|
|
35212
|
+
const reference = record3.repository ?? identity3?.repository ?? null;
|
|
35213
|
+
const remote = reference === null ? null : exports_Predicate.isTagged(reference, "Identity") ? reference.value : repositoryIdentity(reference.value);
|
|
35095
35214
|
for (const mapping of mappings) {
|
|
35096
35215
|
if (remote !== null && mapping.repositories.some((entry) => repositoryIdentity(entry) === remote))
|
|
35097
35216
|
return { project: mapping.project, shareable: true };
|
|
35098
35217
|
}
|
|
35099
|
-
if (
|
|
35218
|
+
if (reference !== null && remote !== null)
|
|
35100
35219
|
return {
|
|
35101
35220
|
project: remote,
|
|
35102
|
-
shareable: remote !== "" && (
|
|
35221
|
+
shareable: remote !== "" && (exports_Predicate.isTagged(reference, "Identity") || isNetworkRemote(reference.value))
|
|
35103
35222
|
};
|
|
35104
35223
|
return { project: identity3?.root ?? "Unassigned", shareable: false };
|
|
35105
35224
|
});
|
|
35225
|
+
return { resolve: resolve7, flush: history.flush };
|
|
35106
35226
|
});
|
|
35107
35227
|
|
|
35108
35228
|
// packages/core/src/providers/shared.ts
|
|
@@ -36064,7 +36184,7 @@ function piParser(file2) {
|
|
|
36064
36184
|
}
|
|
36065
36185
|
|
|
36066
36186
|
// packages/core/src/sync.ts
|
|
36067
|
-
import { createHash as
|
|
36187
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
36068
36188
|
var hour = 3600000;
|
|
36069
36189
|
var UtcInstant = exports_Schema.String.check(exports_Schema.isPattern(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/), exports_Schema.makeFilter((s) => {
|
|
36070
36190
|
const ms = Date.parse(s);
|
|
@@ -36205,7 +36325,7 @@ function hourRange(range3) {
|
|
|
36205
36325
|
};
|
|
36206
36326
|
}
|
|
36207
36327
|
function sessionKey(provider, session) {
|
|
36208
|
-
return
|
|
36328
|
+
return createHash4("sha256").update(`${provider}\x00${session}`).digest("hex").slice(0, 32);
|
|
36209
36329
|
}
|
|
36210
36330
|
function sessionBuckets(pricing) {
|
|
36211
36331
|
const totals = new Map;
|
|
@@ -36304,9 +36424,9 @@ class Ledger extends exports_Context.Service()("token-ledger/Ledger") {
|
|
|
36304
36424
|
const request3 = yield* exports_Schema.decodeUnknownEffect(ReportRequest)(input).pipe(exports_Effect.mapError(() => new InvalidRequest({
|
|
36305
36425
|
message: "Expected an ordered inclusive day window, a named time zone, and valid sources, mappings, and prices."
|
|
36306
36426
|
})));
|
|
36307
|
-
if (request3.billingHints !== undefined && !path.isAbsolute(request3.billingHints.directory) || request3.sources.some((source) => !path.isAbsolute(source.path)) || request3.projects.some((mapping) => mapping.paths.some((prefix3) => !path.isAbsolute(prefix3)))) {
|
|
36427
|
+
if (request3.repositoryHistory !== undefined && !path.isAbsolute(request3.repositoryHistory.directory) || request3.billingHints !== undefined && !path.isAbsolute(request3.billingHints.directory) || request3.sources.some((source) => !path.isAbsolute(source.path)) || request3.projects.some((mapping) => mapping.paths.some((prefix3) => !path.isAbsolute(prefix3)))) {
|
|
36308
36428
|
return yield* new InvalidRequest({
|
|
36309
|
-
message: "Source, billing hint, and project mapping paths must be absolute."
|
|
36429
|
+
message: "Source, repository history, billing hint, and project mapping paths must be absolute."
|
|
36310
36430
|
});
|
|
36311
36431
|
}
|
|
36312
36432
|
return request3;
|
|
@@ -36317,7 +36437,7 @@ class Ledger extends exports_Context.Service()("token-ledger/Ledger") {
|
|
|
36317
36437
|
const routing = notice !== undefined && request3.billingHints !== undefined && exports_Result.isSuccess(hints) ? chatgptRequests : undefined;
|
|
36318
36438
|
if (exports_Result.isFailure(hints))
|
|
36319
36439
|
yield* onWarning?.(`Billing hints: ${hints.failure.message} Copilot will not be uploaded. Repair the hints and rerun sync with --since <first missed day>.`) ?? exports_Effect.void;
|
|
36320
|
-
const
|
|
36440
|
+
const projects = yield* projectResolver(request3.projects, request3.repositoryHistory, onWarning).pipe(exports_Effect.provideService(exports_FileSystem.FileSystem, fs), exports_Effect.provideService(exports_Path.Path, path));
|
|
36321
36441
|
const seen = new Set;
|
|
36322
36442
|
const visitedFiles = new Set;
|
|
36323
36443
|
const settledFiles = new Set;
|
|
@@ -36344,7 +36464,7 @@ class Ledger extends exports_Context.Service()("token-ledger/Ledger") {
|
|
|
36344
36464
|
return;
|
|
36345
36465
|
}
|
|
36346
36466
|
seen.add(id2);
|
|
36347
|
-
collect2(record3, yield*
|
|
36467
|
+
collect2(record3, yield* projects.resolve(record3, source.project), slot);
|
|
36348
36468
|
});
|
|
36349
36469
|
const accept2 = exports_Effect.fn("Ledger.acceptRecords")(function* (result6, fromSession = false) {
|
|
36350
36470
|
malformedLines += result6.malformed;
|
|
@@ -36432,6 +36552,8 @@ class Ledger extends exports_Context.Service()("token-ledger/Ledger") {
|
|
|
36432
36552
|
}
|
|
36433
36553
|
}).pipe(exports_Effect.result);
|
|
36434
36554
|
if (exports_Result.isFailure(result6)) {
|
|
36555
|
+
if (exports_Predicate.isTagged(result6.failure, "RepositoryHistoryError"))
|
|
36556
|
+
return yield* result6.failure;
|
|
36435
36557
|
if (entry === source.path && exports_Predicate.isTagged(result6.failure, "PlatformError") && exports_Predicate.isTagged(result6.failure.reason, "NotFound"))
|
|
36436
36558
|
missingRoot = true;
|
|
36437
36559
|
failedFiles++;
|
|
@@ -36479,10 +36601,15 @@ class Ledger extends exports_Context.Service()("token-ledger/Ledger") {
|
|
|
36479
36601
|
yield* legacy;
|
|
36480
36602
|
for (const copy4 of inherited)
|
|
36481
36603
|
yield* copy4;
|
|
36604
|
+
yield* projects.flush();
|
|
36482
36605
|
return coverage.map((summarize) => summarize());
|
|
36483
36606
|
});
|
|
36484
|
-
const report = exports_Effect.fn("Ledger.report")(function* (input) {
|
|
36485
|
-
const
|
|
36607
|
+
const report = exports_Effect.fn("Ledger.report")(function* (input, onWarning) {
|
|
36608
|
+
const decoded = yield* decode5(input);
|
|
36609
|
+
const request3 = decoded.repositoryHistory === undefined ? decoded : {
|
|
36610
|
+
...decoded,
|
|
36611
|
+
repositoryHistory: { ...decoded.repositoryHistory, required: false }
|
|
36612
|
+
};
|
|
36486
36613
|
const window = dayWindow(request3.since, request3.until, request3.timeZone);
|
|
36487
36614
|
const rows = new Map;
|
|
36488
36615
|
const coverage = yield* scan2(request3, window, window.dayOf, (record3, { project }, day) => {
|
|
@@ -36496,7 +36623,7 @@ class Ledger extends exports_Context.Service()("token-ledger/Ledger") {
|
|
|
36496
36623
|
pricePerMillion: base,
|
|
36497
36624
|
...addUsage(rows.get(key), record3.tokens, usd)
|
|
36498
36625
|
});
|
|
36499
|
-
});
|
|
36626
|
+
}, undefined, onWarning);
|
|
36500
36627
|
return UsageReport.make({
|
|
36501
36628
|
version: 2,
|
|
36502
36629
|
since: request3.since,
|
|
@@ -43933,7 +44060,7 @@ var runWith2 = (command, config) => {
|
|
|
43933
44060
|
// packages/cli/package.json
|
|
43934
44061
|
var package_default = {
|
|
43935
44062
|
name: "@ponbac/token-ledger",
|
|
43936
|
-
version: "0.11.
|
|
44063
|
+
version: "0.11.2",
|
|
43937
44064
|
private: true,
|
|
43938
44065
|
type: "module",
|
|
43939
44066
|
bin: {
|
|
@@ -43969,10 +44096,14 @@ var dataHome = exports_Effect.gen(function* () {
|
|
|
43969
44096
|
const path = yield* exports_Path.Path;
|
|
43970
44097
|
return yield* exports_Config.String("XDG_DATA_HOME").pipe(exports_Config.option, exports_Effect.map(exports_Option.filter((directory) => path.isAbsolute(directory))));
|
|
43971
44098
|
});
|
|
43972
|
-
function
|
|
44099
|
+
function tokenLedgerDataDirectory(platform, home, localAppData, xdgDataHome) {
|
|
43973
44100
|
const path = platform === "win32" ? win322 : posix2;
|
|
43974
44101
|
const root = exports_Match.value(platform).pipe(exports_Match.when("win32", () => exports_Option.getOrElse(exports_Option.filter(localAppData, (directory) => path.isAbsolute(directory)), () => path.join(home, "AppData", "Local"))), exports_Match.when("darwin", () => path.join(home, "Library", "Application Support")), exports_Match.orElse(() => exports_Option.getOrElse(xdgDataHome, () => path.join(home, ".local", "share"))));
|
|
43975
|
-
return path.join(root, "token-ledger"
|
|
44102
|
+
return path.join(root, "token-ledger");
|
|
44103
|
+
}
|
|
44104
|
+
function billingHintsDirectory(platform, home, localAppData, xdgDataHome) {
|
|
44105
|
+
const path = platform === "win32" ? win322 : posix2;
|
|
44106
|
+
return path.join(tokenLedgerDataDirectory(platform, home, localAppData, xdgDataHome), "billing-hints");
|
|
43976
44107
|
}
|
|
43977
44108
|
// node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
43978
44109
|
function createScanner(text2, ignoreTrivia = false) {
|
|
@@ -47413,6 +47544,10 @@ var usageRequest = exports_Effect.fn("CLI.usageRequest")(function* (flags, defau
|
|
|
47413
47544
|
if (pricing.status === "unavailable")
|
|
47414
47545
|
yield* exports_Console.error("Pricing unavailable: unknown rates remain unpriced. Configure prices or rerun online.");
|
|
47415
47546
|
const request3 = yield* ReportRequest.makeEffect({
|
|
47547
|
+
repositoryHistory: {
|
|
47548
|
+
directory: path.join(tokenLedgerDataDirectory(process.platform, home, yield* exports_Config.String("LOCALAPPDATA").pipe(exports_Config.option), yield* dataHome), "repositories"),
|
|
47549
|
+
required: !flags.dryRun
|
|
47550
|
+
},
|
|
47416
47551
|
billingHints: configuration.billingHintsDirectory === undefined ? {
|
|
47417
47552
|
directory: billingHintsDirectory(process.platform, home, yield* exports_Config.String("LOCALAPPDATA").pipe(exports_Config.option), yield* dataHome),
|
|
47418
47553
|
required: false
|
|
@@ -47437,7 +47572,7 @@ var report = exports_Command.make("report", {
|
|
|
47437
47572
|
}, exports_Effect.fn("CLI.report")(function* (flags) {
|
|
47438
47573
|
const { request: request3 } = yield* usageRequest(flags, (today) => `${today.slice(0, 7)}-01`);
|
|
47439
47574
|
const ledger = yield* Ledger;
|
|
47440
|
-
const result6 = yield* ledger.report(request3);
|
|
47575
|
+
const result6 = yield* ledger.report(request3, exports_Console.error);
|
|
47441
47576
|
const output = exports_Match.value(flags.json ? "json" : flags.format).pipe(exports_Match.when("json", () => JSON.stringify(result6, null, 2)), exports_Match.when("csv", () => csv(result6)), exports_Match.when("table", () => table2(result6, process.stdout.columns ?? 120, process.stdout.isTTY && process.stdout.hasColors())), exports_Match.exhaustive);
|
|
47442
47577
|
yield* exports_Console.log(output);
|
|
47443
47578
|
for (const source of result6.coverage) {
|