@ponbac/token-ledger 0.7.0 → 0.8.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 +23 -16
- package/dist/main.js +44 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -460,7 +460,7 @@ telemetry has none.
|
|
|
460
460
|
|
|
461
461
|
`sync` uploads this machine's usage to a [toki2](https://github.com/ponbac/toki2)
|
|
462
462
|
server, which combines every developer's machines for team reporting and billing.
|
|
463
|
-
Run it on **every machine** where you use a coding agent, and schedule it
|
|
463
|
+
Run it on **every machine** where you use a coding agent, and schedule it.
|
|
464
464
|
|
|
465
465
|
### Set up
|
|
466
466
|
|
|
@@ -507,24 +507,31 @@ If you map projects in a `token-ledger.json`, pass it with `--config`; scheduled
|
|
|
507
507
|
do not run in your project directory. Days follow the system time zone; add
|
|
508
508
|
`--time-zone Europe/Stockholm` when a scheduler's environment may lack one.
|
|
509
509
|
|
|
510
|
-
### Schedule a
|
|
510
|
+
### Schedule a sync
|
|
511
511
|
|
|
512
|
-
Schedule a
|
|
512
|
+
Schedule a sync to upload history regularly, and before providers prune it:
|
|
513
513
|
|
|
514
514
|
```sh
|
|
515
515
|
npx @ponbac/token-ledger@latest schedule install
|
|
516
516
|
```
|
|
517
517
|
|
|
518
|
-
This registers a
|
|
519
|
-
does not keep a process running. Run
|
|
518
|
+
This registers a job with the operating system's own scheduler that syncs every two
|
|
519
|
+
hours, at 00:30, 02:30, and so on; token-ledger does not keep a process running. Run
|
|
520
|
+
it again with other flags to change the job: the new schedule replaces the old one.
|
|
520
521
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
|
527
|
-
|
|
|
522
|
+
```sh
|
|
523
|
+
npx @ponbac/token-ledger@latest schedule install --every 1h # hourly, at :30
|
|
524
|
+
npx @ponbac/token-ledger@latest schedule install --every 24h --at 07:30 # once a day
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
| Flag | Effect |
|
|
528
|
+
| ----------------------- | ------------------------------------------------------------------------ |
|
|
529
|
+
| `--every 1h` | `1h`, `2h`, `3h`, `4h`, `6h`, `8h`, `12h`, or `24h`; the default is `2h` |
|
|
530
|
+
| `--at 07:30` | A local time a sync runs at; the default is `12:30` |
|
|
531
|
+
| `--config <file>` | Project mappings for the job, saved as an absolute path |
|
|
532
|
+
| `--time-zone <zone>` | Pass a time zone when the scheduler may not have one |
|
|
533
|
+
| `--provider <provider>` | Sync one provider only |
|
|
534
|
+
| `--dry-run` | Print the files and commands, and change nothing |
|
|
528
535
|
|
|
529
536
|
`schedule status` shows the scheduler's own report, including the last run, and
|
|
530
537
|
`schedule uninstall` removes the job and keeps your settings. A run's output is in
|
|
@@ -537,7 +544,7 @@ launcher in your token-ledger settings directory waits for sync to finish and
|
|
|
537
544
|
passes its exit code back to Task Scheduler. Windows Script Host must be enabled.
|
|
538
545
|
To update a task installed by an older CLI version, run
|
|
539
546
|
`npx.cmd --yes @ponbac/token-ledger@latest schedule install` again, including any
|
|
540
|
-
`--at`, `--config`, `--time-zone`, or `--provider` options you used before. This
|
|
547
|
+
`--every`, `--at`, `--config`, `--time-zone`, or `--provider` options you used before. This
|
|
541
548
|
replaces the existing task; your saved server and token are kept.
|
|
542
549
|
|
|
543
550
|
| Platform | Scheduler | A missed run |
|
|
@@ -563,8 +570,8 @@ Without one, as on Alpine or in WSL with systemd disabled, use the cron entry be
|
|
|
563
570
|
<details>
|
|
564
571
|
<summary>Scheduling by hand</summary>
|
|
565
572
|
|
|
566
|
-
`schedule install --dry-run` prints the exact files and commands for your machine
|
|
567
|
-
The examples below do the same with a login shell finding `npx`; if it is not on the
|
|
573
|
+
`schedule install --dry-run` prints the exact files and commands for your machine,
|
|
574
|
+
with the times for any `--every`. The examples below sync once a day. They do the same with a login shell finding `npx`; if it is not on the
|
|
568
575
|
scheduler's `PATH`, use its absolute path or install the CLI globally with
|
|
569
576
|
`npm install -g @ponbac/token-ledger` and run `token-ledger sync`.
|
|
570
577
|
|
|
@@ -775,7 +782,7 @@ For manual publication:
|
|
|
775
782
|
1. Log in with `npm login` using an account with publish access to `@ponbac/token-ledger`.
|
|
776
783
|
2. Run `bun run check`. The CLI test packs the package, installs it offline outside
|
|
777
784
|
the repository with lifecycle scripts disabled, and exercises the installed CLI.
|
|
778
|
-
3. Run `bun run pack` to create `dist/ponbac-token-ledger-0.
|
|
785
|
+
3. Run `bun run pack` to create `dist/ponbac-token-ledger-0.8.0.tgz` (filename follows version).
|
|
779
786
|
4. Inspect `npm publish ./dist/npm --dry-run`.
|
|
780
787
|
5. Publish with `npm publish ./dist/npm --access public`; complete npm's authentication
|
|
781
788
|
prompt if requested.
|
package/dist/main.js
CHANGED
|
@@ -42809,7 +42809,7 @@ var runWith2 = (command, config) => {
|
|
|
42809
42809
|
// packages/cli/package.json
|
|
42810
42810
|
var package_default = {
|
|
42811
42811
|
name: "@ponbac/token-ledger",
|
|
42812
|
-
version: "0.
|
|
42812
|
+
version: "0.8.0",
|
|
42813
42813
|
private: true,
|
|
42814
42814
|
type: "module",
|
|
42815
42815
|
bin: {
|
|
@@ -43981,6 +43981,22 @@ class ScheduleError extends exports_Schema.TaggedError()("ScheduleError", {
|
|
|
43981
43981
|
}) {
|
|
43982
43982
|
}
|
|
43983
43983
|
var TimeOfDay = exports_Schema.String.check(exports_Schema.isPattern(/^(?:[01]\d|2[0-3]):[0-5]\d$/));
|
|
43984
|
+
var intervals = [
|
|
43985
|
+
["1h", 1],
|
|
43986
|
+
["2h", 2],
|
|
43987
|
+
["3h", 3],
|
|
43988
|
+
["4h", 4],
|
|
43989
|
+
["6h", 6],
|
|
43990
|
+
["8h", 8],
|
|
43991
|
+
["12h", 12],
|
|
43992
|
+
["24h", 24]
|
|
43993
|
+
];
|
|
43994
|
+
function syncTimes(job) {
|
|
43995
|
+
const hour2 = Number(job.at.slice(0, 2));
|
|
43996
|
+
const minute = job.at.slice(3);
|
|
43997
|
+
return Array.from({ length: 24 / job.every }, (_, index2) => `${String(hour2 % job.every + index2 * job.every).padStart(2, "0")}:${minute}`);
|
|
43998
|
+
}
|
|
43999
|
+
var describeTimes = (job) => job.every === 24 ? `daily at ${job.at}` : `every ${job.every === 1 ? "hour" : `${job.every} hours`}, at ${syncTimes(job).join(", ")}`;
|
|
43984
44000
|
var Action3 = exports_Data.taggedEnum();
|
|
43985
44001
|
var unit = "token-ledger-sync";
|
|
43986
44002
|
var label = "com.github.ponbac.token-ledger.sync";
|
|
@@ -44038,10 +44054,10 @@ ExecStart=/bin/sh -lc ${systemdQuoted(posixScript(job2))}
|
|
|
44038
44054
|
Action3.Write({
|
|
44039
44055
|
file: timer,
|
|
44040
44056
|
contents: `[Unit]
|
|
44041
|
-
Description=
|
|
44057
|
+
Description=AI usage sync ${job2.every === 24 ? "once a day" : `every ${job2.every}h`}
|
|
44042
44058
|
|
|
44043
44059
|
[Timer]
|
|
44044
|
-
OnCalendar=*-*-* ${job2.at}:00
|
|
44060
|
+
OnCalendar=*-*-* ${syncTimes(job2).map((time2) => time2.slice(0, 2)).join(",")}:${job2.at.slice(3)}:00
|
|
44045
44061
|
Persistent=true
|
|
44046
44062
|
RandomizedDelaySec=10m
|
|
44047
44063
|
|
|
@@ -44075,7 +44091,16 @@ function launchAgent(home, uid) {
|
|
|
44075
44091
|
return {
|
|
44076
44092
|
name: "launchd agent",
|
|
44077
44093
|
install: (job) => posixJob(job).pipe(exports_Effect.map((job2) => {
|
|
44078
|
-
const
|
|
44094
|
+
const times = syncTimes(job2).map((time2) => {
|
|
44095
|
+
const [hour2, minute] = time2.split(":").map(Number);
|
|
44096
|
+
return ` <dict>
|
|
44097
|
+
<key>Hour</key>
|
|
44098
|
+
<integer>${hour2}</integer>
|
|
44099
|
+
<key>Minute</key>
|
|
44100
|
+
<integer>${minute}</integer>
|
|
44101
|
+
</dict>`;
|
|
44102
|
+
}).join(`
|
|
44103
|
+
`);
|
|
44079
44104
|
return [
|
|
44080
44105
|
Action3.Write({
|
|
44081
44106
|
file: plist,
|
|
@@ -44094,12 +44119,9 @@ function launchAgent(home, uid) {
|
|
|
44094
44119
|
<key>RunAtLoad</key>
|
|
44095
44120
|
<true/>
|
|
44096
44121
|
<key>StartCalendarInterval</key>
|
|
44097
|
-
<
|
|
44098
|
-
|
|
44099
|
-
|
|
44100
|
-
<key>Minute</key>
|
|
44101
|
-
<integer>${minute}</integer>
|
|
44102
|
-
</dict>
|
|
44122
|
+
<array>
|
|
44123
|
+
${times}
|
|
44124
|
+
</array>
|
|
44103
44125
|
<key>StandardOutPath</key>
|
|
44104
44126
|
<string>${xmlText(log3)}</string>
|
|
44105
44127
|
<key>StandardErrorPath</key>
|
|
@@ -44141,7 +44163,10 @@ function taskScheduler(file2) {
|
|
|
44141
44163
|
"$ErrorActionPreference = 'Stop'",
|
|
44142
44164
|
"$ProgressPreference = 'SilentlyContinue'",
|
|
44143
44165
|
`$action = New-ScheduledTaskAction -Execute 'wscript.exe' -Argument ${powershellString(`//B //Nologo //E:JScript "${file2}"`)}`,
|
|
44144
|
-
`$trigger = New-ScheduledTaskTrigger -Daily -At '${job2
|
|
44166
|
+
`$trigger = New-ScheduledTaskTrigger -Daily -At '${syncTimes(job2)[0]}'`,
|
|
44167
|
+
...job2.every === 24 ? [] : [
|
|
44168
|
+
`$trigger.Repetition = (New-ScheduledTaskTrigger -Once -At '${syncTimes(job2)[0]}' -RepetitionInterval (New-TimeSpan -Hours ${job2.every}) -RepetitionDuration (New-TimeSpan -Hours ${24 - job2.every})).Repetition`
|
|
44169
|
+
],
|
|
44145
44170
|
"$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries",
|
|
44146
44171
|
`Register-ScheduledTask -TaskName ${powershellString(task)} -Action $action -Trigger $trigger -Settings $settings -Force | Out-Null`
|
|
44147
44172
|
].join(`
|
|
@@ -46039,7 +46064,8 @@ var login = exports_Command.make("login", {
|
|
|
46039
46064
|
Next: token-ledger sync --dry-run, then token-ledger schedule install.`);
|
|
46040
46065
|
})).pipe(exports_Command.withDescription("Save the toki2 server and API token in sync.json for sync and scheduled syncs"));
|
|
46041
46066
|
var scheduleInstall = exports_Command.make("install", {
|
|
46042
|
-
|
|
46067
|
+
every: exports_Flag.ChoiceWithValue("every", intervals).pipe(exports_Flag.withDefault(2), exports_Flag.withDescription("Time between syncs; defaults to 2h")),
|
|
46068
|
+
at: exports_Flag.String("at").pipe(exports_Flag.withDefault("12:30"), exports_Flag.withSchema(TimeOfDay), exports_Flag.withDescription("A local time, as HH:MM, that a sync runs at; defaults to 12:30")),
|
|
46043
46069
|
config: exports_Flag.String("config").pipe(exports_Flag.optional, exports_Flag.withDescription("JSON config for the scheduled sync; ./token-ledger.json is not read")),
|
|
46044
46070
|
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")),
|
|
46045
46071
|
provider: exports_Flag.Literals("provider", ["all", "codex", "claude", "grok", "copilot", "pi"]).pipe(exports_Flag.withDefault("all")),
|
|
@@ -46053,6 +46079,7 @@ var scheduleInstall = exports_Command.make("install", {
|
|
|
46053
46079
|
return yield* new CliError2({ message: `Cannot find the configuration ${config.value}.` });
|
|
46054
46080
|
const actions = yield* scheduler.install({
|
|
46055
46081
|
at: flags.at,
|
|
46082
|
+
every: flags.every,
|
|
46056
46083
|
nodeDirectory: path.dirname(process.execPath),
|
|
46057
46084
|
configHome: yield* configHome,
|
|
46058
46085
|
dataHome: yield* dataHome,
|
|
@@ -46074,18 +46101,18 @@ var scheduleInstall = exports_Command.make("install", {
|
|
|
46074
46101
|
message: "No saved server and API token. Run token-ledger login first: a scheduled sync cannot read --token or your shell's environment."
|
|
46075
46102
|
});
|
|
46076
46103
|
yield* perform(actions);
|
|
46077
|
-
yield* exports_Console.log(`Scheduled a
|
|
46078
|
-
})).pipe(exports_Command.withDescription("Install or replace the
|
|
46104
|
+
yield* exports_Console.log(`Scheduled a sync ${describeTimes(flags)} as a ${scheduler.name}, replacing any earlier schedule. Inspect it with token-ledger schedule status.`);
|
|
46105
|
+
})).pipe(exports_Command.withDescription("Install or replace the scheduled sync; it needs the server and token saved by login"));
|
|
46079
46106
|
var scheduleStatus = exports_Command.make("status", {}, exports_Effect.fn("CLI.scheduleStatus")(function* () {
|
|
46080
46107
|
const scheduler = yield* hostScheduler;
|
|
46081
46108
|
yield* perform(scheduler.status);
|
|
46082
|
-
})).pipe(exports_Command.withDescription("Show the scheduler's own report of the
|
|
46109
|
+
})).pipe(exports_Command.withDescription("Show the scheduler's own report of the scheduled sync"));
|
|
46083
46110
|
var scheduleUninstall = exports_Command.make("uninstall", {}, exports_Effect.fn("CLI.scheduleUninstall")(function* () {
|
|
46084
46111
|
const scheduler = yield* hostScheduler;
|
|
46085
46112
|
yield* perform(scheduler.uninstall);
|
|
46086
46113
|
yield* exports_Console.log(`Removed the ${scheduler.name}. Saved settings were kept.`);
|
|
46087
|
-
})).pipe(exports_Command.withDescription("Remove the
|
|
46088
|
-
var schedule4 = exports_Command.make("schedule").pipe(exports_Command.withDescription("Run sync
|
|
46114
|
+
})).pipe(exports_Command.withDescription("Remove the scheduled sync; saved settings stay"));
|
|
46115
|
+
var schedule4 = exports_Command.make("schedule").pipe(exports_Command.withDescription("Run sync every few hours with systemd, launchd, or Task Scheduler"), exports_Command.withSubcommands([scheduleInstall, scheduleStatus, scheduleUninstall]));
|
|
46089
46116
|
var copilotEnable = exports_Command.make("enable", {
|
|
46090
46117
|
cli: exports_Flag.Boolean("cli").pipe(exports_Flag.withDefault(false), exports_Flag.withDescription("Copilot CLI: export its usage from every new terminal")),
|
|
46091
46118
|
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")),
|