@ponbac/token-ledger 0.5.0 → 0.5.1

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.
Files changed (3) hide show
  1. package/README.md +17 -4
  2. package/dist/main.js +45 -35
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -524,6 +524,15 @@ does not keep a process running. Run it again to change the job.
524
524
  `journalctl --user -u token-ledger-sync` on Linux and in
525
525
  `~/Library/Logs/token-ledger-sync.log` on macOS.
526
526
 
527
+ On Windows, scheduled sync runs in the background without opening a terminal
528
+ window. A [Windows Script Host](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/wscript)
529
+ launcher in your token-ledger settings directory waits for sync to finish and
530
+ passes its exit code back to Task Scheduler. Windows Script Host must be enabled.
531
+ To update a task installed by an older CLI version, run
532
+ `npx.cmd --yes @ponbac/token-ledger@latest schedule install` again, including any
533
+ `--at`, `--config`, `--time-zone`, or `--provider` options you used before. This
534
+ replaces the existing task; your saved server and token are kept.
535
+
527
536
  | Platform | Scheduler | A missed run |
528
537
  | -------- | ------------------- | ------------------------------------------------------ |
529
538
  | Linux | systemd user timer | Runs within ten minutes of your next login |
@@ -632,13 +641,17 @@ but does not replay intervals missed while powered off.
632
641
  **Windows (Task Scheduler).** In PowerShell:
633
642
 
634
643
  ```powershell
635
- $action = New-ScheduledTaskAction -Execute "cmd.exe" -Argument "/c npx --yes @ponbac/token-ledger@latest sync"
644
+ $runner = Join-Path $env:APPDATA "token-ledger\token-ledger-sync.js"
645
+ New-Item -ItemType Directory -Path (Split-Path $runner) -Force | Out-Null
646
+ 'WScript.Quit(WScript.CreateObject("WScript.Shell").Run("cmd.exe /d /v:off /c npx --yes @ponbac/token-ledger@latest sync", 0, true));' | Set-Content -Path $runner -Encoding ASCII
647
+ $action = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "//B //Nologo //E:JScript `"$runner`""
636
648
  $trigger = New-ScheduledTaskTrigger -Daily -At 12:30
637
649
  $settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
638
- Register-ScheduledTask -TaskName "token-ledger sync" -Action $action -Trigger $trigger -Settings $settings
650
+ Register-ScheduledTask -TaskName "token-ledger sync" -Action $action -Trigger $trigger -Settings $settings -Force
639
651
  ```
640
652
 
641
- `-StartWhenAvailable` runs a missed sync at the next opportunity. The battery
653
+ The launcher hides the sync window and waits for its exit code. `//B` prevents
654
+ script dialogs. `-StartWhenAvailable` runs a missed sync at the next opportunity. The battery
642
655
  switches allow starts on battery and keep a running sync from being stopped when
643
656
  AC power disconnects. See [Task Scheduler settings](https://learn.microsoft.com/en-us/powershell/module/scheduledtasks/new-scheduledtasksettingsset).
644
657
 
@@ -749,7 +762,7 @@ For manual publication:
749
762
  1. Log in with `npm login` using an account with publish access to `@ponbac/token-ledger`.
750
763
  2. Run `bun run check`. The CLI test packs the package, installs it offline outside
751
764
  the repository with lifecycle scripts disabled, and exercises the installed CLI.
752
- 3. Run `bun run pack` to create `dist/ponbac-token-ledger-0.5.0.tgz` (filename follows version).
765
+ 3. Run `bun run pack` to create `dist/ponbac-token-ledger-0.5.1.tgz` (filename follows version).
753
766
  4. Inspect `npm publish ./dist/npm --dry-run`.
754
767
  5. Publish with `npm publish ./dist/npm --access public`; complete npm's authentication
755
768
  prompt if requested.
package/dist/main.js CHANGED
@@ -42699,7 +42699,7 @@ var runWith2 = (command, config) => {
42699
42699
  // packages/cli/package.json
42700
42700
  var package_default = {
42701
42701
  name: "@ponbac/token-ledger",
42702
- version: "0.5.0",
42702
+ version: "0.5.1",
42703
42703
  private: true,
42704
42704
  type: "module",
42705
42705
  bin: {
@@ -43999,46 +43999,56 @@ var powershellArguments = (script) => [
43999
43999
  ...powershellOptions,
44000
44000
  Buffer.from(script, "utf16le").toString("base64")
44001
44001
  ];
44002
- var taskScheduler = {
44003
- name: "Task Scheduler task",
44004
- install: (job) => quotable(job, /[\p{Cc}"%]/u, 'a control character, `"`, or `%`').pipe(exports_Effect.map((job2) => {
44005
- const command = [
44006
- ...exports_Option.toArray(job2.configHome).map((directory) => `set "XDG_CONFIG_HOME=${directory}"`),
44007
- `set "PATH=${job2.nodeDirectory};%PATH%"`,
44008
- `npx --yes ${packageSpec} ${["sync", ...job2.flags].map(cmdWord).join(" ")}`
44009
- ].join(" && ");
44010
- const script = [
44011
- "$ErrorActionPreference = 'Stop'",
44012
- "$ProgressPreference = 'SilentlyContinue'",
44013
- `$action = New-ScheduledTaskAction -Execute 'cmd.exe' -Argument ${powershellString(`/d /v:off /s /c "${command}"`)}`,
44014
- `$trigger = New-ScheduledTaskTrigger -Daily -At '${job2.at}'`,
44015
- "$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries",
44016
- `Register-ScheduledTask -TaskName ${powershellString(task)} -Action $action -Trigger $trigger -Settings $settings -Force | Out-Null`
44017
- ].join(`
44002
+ var jscriptString = (value5) => JSON.stringify(value5).replaceAll(/[\u007f-\uffff]/g, (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`);
44003
+ function taskScheduler(file2) {
44004
+ return {
44005
+ name: "Task Scheduler task",
44006
+ install: (job) => quotable(job, /[\p{Cc}"%]/u, 'a control character, `"`, or `%`').pipe(exports_Effect.map((job2) => {
44007
+ const command = [
44008
+ ...exports_Option.toArray(job2.configHome).map((directory) => `set "XDG_CONFIG_HOME=${directory}"`),
44009
+ `set "PATH=${job2.nodeDirectory};%PATH%"`,
44010
+ `npx --yes ${packageSpec} ${["sync", ...job2.flags].map(cmdWord).join(" ")}`
44011
+ ].join(" && ");
44012
+ const script = [
44013
+ "$ErrorActionPreference = 'Stop'",
44014
+ "$ProgressPreference = 'SilentlyContinue'",
44015
+ `$action = New-ScheduledTaskAction -Execute 'wscript.exe' -Argument ${powershellString(`//B //Nologo //E:JScript "${file2}"`)}`,
44016
+ `$trigger = New-ScheduledTaskTrigger -Daily -At '${job2.at}'`,
44017
+ "$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries",
44018
+ `Register-ScheduledTask -TaskName ${powershellString(task)} -Action $action -Trigger $trigger -Settings $settings -Force | Out-Null`
44019
+ ].join(`
44018
44020
  `);
44019
- return [
44020
- Action3.Run({
44021
- program: "powershell.exe",
44022
- args: powershellArguments(script),
44023
- shown: `powershell.exe ${powershellOptions.join(" ")} <the script below, as UTF-16LE Base64>
44021
+ return [
44022
+ Action3.Write({
44023
+ file: file2,
44024
+ contents: `var shell = WScript.CreateObject("WScript.Shell");
44025
+ WScript.Quit(shell.Run(${jscriptString(`cmd.exe /d /v:off /s /c "${command}"`)}, 0, true));
44026
+ `
44027
+ }),
44028
+ Action3.Run({
44029
+ program: "powershell.exe",
44030
+ args: powershellArguments(script),
44031
+ shown: `powershell.exe ${powershellOptions.join(" ")} <the script below, as UTF-16LE Base64>
44024
44032
  ${script}`,
44025
- outcome: "required",
44026
- hint: "",
44027
- gone: []
44028
- })
44029
- ];
44030
- })),
44031
- uninstall: [
44032
- run6("reported", "schtasks.exe", ["/Delete", "/TN", task, "/F"]),
44033
- run6("absent", "schtasks.exe", ["/Query", "/TN", task], "The task is still registered; Task Scheduler's reason is shown above.")
44034
- ],
44035
- status: [run6("reported", "schtasks.exe", ["/Query", "/TN", task, "/V", "/FO", "LIST"])]
44036
- };
44033
+ outcome: "required",
44034
+ hint: "",
44035
+ gone: []
44036
+ })
44037
+ ];
44038
+ })),
44039
+ uninstall: [
44040
+ run6("reported", "schtasks.exe", ["/Delete", "/TN", task, "/F"]),
44041
+ run6("absent", "schtasks.exe", ["/Query", "/TN", task], "The task is still registered; Task Scheduler's reason is shown above."),
44042
+ Action3.Remove({ file: file2 })
44043
+ ],
44044
+ status: [run6("reported", "schtasks.exe", ["/Query", "/TN", task, "/V", "/FO", "LIST"])]
44045
+ };
44046
+ }
44037
44047
  var hostScheduler = exports_Effect.gen(function* () {
44038
44048
  const path = yield* exports_Path.Path;
44039
44049
  const home = homedir2();
44040
44050
  const units = exports_Option.getOrElse(yield* configHome, () => path.join(home, ".config"));
44041
- 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({
44051
+ 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.map(settingsDirectory, (directory) => taskScheduler(path.join(directory, `${unit}.js`)))), exports_Match.orElse((platform) => exports_Effect.fail(new ScheduleError({
44042
44052
  message: `No scheduler is supported on ${platform}; schedule token-ledger sync yourself.`
44043
44053
  }))));
44044
44054
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ponbac/token-ledger",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Local AI token usage and API-equivalent cost reports by project",
5
5
  "license": "MIT",
6
6
  "engines": {