@trajectonomics/cli 0.1.0 → 0.3.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 CHANGED
@@ -1,6 +1,10 @@
1
1
  # trajectonomics
2
2
 
3
- The trajectonomics command line. The sources are Bun-only; a released binary needs nothing.
3
+ `traj` is a free and open source command line for personal money. An AI agent operates it.
4
+ The command line never calls a model, so every result is repeatable.
5
+
6
+ The landing page is [trajectonomics.com](https://trajectonomics.com/) and the docs are at
7
+ [trajectonomics.com/docs](https://trajectonomics.com/docs/).
4
8
 
5
9
  ## Install
6
10
 
@@ -26,16 +30,67 @@ npx @trajectonomics/cli@latest --version
26
30
  bunx @trajectonomics/cli@latest --version
27
31
  ```
28
32
 
33
+ Then give your agent the setup skill:
34
+
35
+ ```bash
36
+ npx skills add trajectonomics/skills --skill traj-onboarding -y
37
+ ```
38
+
39
+ The setup skill asks about your situation and goal, then its second step installs the `traj`
40
+ operating skill from `trajectonomics/skills`, the repository both skills publish from.
41
+
42
+ ```bash
43
+ npx skills add trajectonomics/skills --skill traj -y
44
+ ```
45
+
46
+ That is the operating skill on its own, for an agent that is already set up. Both commands
47
+ use `npx`, so they need Node, which the npm channel already requires; the install scripts
48
+ do not.
49
+
29
50
  Which channel: all three end at the same compiled binary and the same version. Use the
30
51
  script for a machine that should keep `traj` on `PATH`, npm when you already have Node or
31
52
  Bun and want one command. Pin a release with `TRAJ_VERSION=X.Y.Z` for the script, or
32
53
  `@X.Y.Z` for npm.
33
54
 
34
55
  Uninstall by deleting the one file: `~/.local/bin/traj`, `%LOCALAPPDATA%\traj\bin`,
35
- `~/.traj/bin` (the download cache), or nothing at all for `npx`.
56
+ `~/.traj/bin` (the download cache only; your ledger is beside it), or nothing at all for
57
+ `npx`.
58
+
59
+ `traj` keeps the ledger in `~/.traj/traj.db`, or in `traj.db` inside `TRAJ_HOME` when that is
60
+ set, the same path on Linux, macOS and Windows. Beside it is the disposable `bin/` download
61
+ cache; deleting the data directory deletes the ledger. Take a lossless copy with:
62
+
63
+ ```bash
64
+ traj export --format jsonl --out backup
65
+ ```
66
+
67
+ `--out` names a directory that must not exist yet, and JSONL is the only lossless export
68
+ format.
69
+
70
+ ## Your first commands
71
+
72
+ The ledger is one record, and the first run builds it in order:
73
+
74
+ ```bash
75
+ traj init
76
+ traj account add Cash --type asset --currency THB
77
+ traj account add Food --type expense --currency THB
78
+ traj tx add --from Cash --to Food --amount 120.50 --date 2026-03-01
79
+ traj balance --as-of 2026-03-31
80
+ traj report networth --as-of 2026-03-31
81
+ ```
82
+
83
+ `init` creates the data directory and an empty ledger. An account is a place money sits or
84
+ comes from, and a transaction moves an amount from one to another. Every read states its own
85
+ date and never reads the clock, so the same command always answers the same question.
86
+
87
+ `traj help` lists every command, `traj help <command>` lists one command's flags, and
88
+ `traj schema --json` prints the whole contract: every command's input, output and error codes.
36
89
 
37
90
  ## Development
38
91
 
92
+ The sources are Bun-only; a released binary needs nothing.
93
+
39
94
  ```bash
40
95
  bun install
41
96
  bun run dev -- --help # run from source
@@ -50,6 +105,107 @@ From a checkout, run the CLI with `bun run dev -- …`. The npm launcher refuses
50
105
  `0.0.0` a checkout carries, because that version is never a release; set
51
106
  `TRAJ_BINARY_PATH` to run a binary you built with `bun run build`.
52
107
 
108
+ ## Reading the future
109
+
110
+ > **Ships in 0.2.0.**
111
+ > The release you installed has no `projection`, `fi` or `scenario tax`: they are on `main`
112
+ > and reach the install channels with `0.2.0`.
113
+
114
+ Three read-only commands run a stored Scenario over the Baseline the ledger
115
+ states at a date: `traj projection run` rolls net worth up year by year,
116
+ nominal and real (monthly rows with `--monthly`); `traj projection compare`
117
+ puts two Scenarios side by side, or one against a `--set` what-if, with the
118
+ deltas in FI date, net worth at the ages you name and run-out year; and
119
+ `traj fi` reports the survival FI date beside the 25× rule of thumb as a
120
+ labelled reference. Every date flag is a Gregorian year between 1900 and
121
+ 2100, so a Buddhist year is refused instead of read as 543 years later. Every result states its As-of, the engine version, the
122
+ Scenario's hashes, the Overrides it applied, and its tax status.
123
+ `traj schema <command>` describes each one.
124
+
125
+ Each result also says what every tax year owes: `taxYears` in JSON, and the
126
+ `taxYears` table in the human format. A row names its Levy, the period and the
127
+ day it settles, what it owed before Prepayment, what was already paid at source,
128
+ and the `owed` figure — due minus prepaid, so a refund is negative. `settled`
129
+ says whether the settlement date falls inside the Projection, and `partial`
130
+ whether the Projection ended before the period did, so a figure that is still
131
+ ahead of you is never mistaken for one already charged.
132
+
133
+ Tax is the Scenario's. `traj scenario tax <name> --tax th-2026` writes Thailand's
134
+ 2026 personal income tax into it, and `--label salary=income.section40_1` says
135
+ which Section 40 class each income Flow belongs to, because a Levy tallies
136
+ labels and never guesses them; `--none` takes both out again, with the
137
+ Prepayments that named the Levy. A Scenario without the Levy is projected
138
+ pre-tax, and every result says which it is.
139
+
140
+ A real employee's profile goes in on the same command: `--filing-status`,
141
+ `--children`, `--parents`, `--disabled-care`, `--social-security`,
142
+ `--life-insurance`, `--health-insurance`, `--parent-health-insurance`,
143
+ `--spouse-life-insurance`, `--mortgage-interest`, `--donation2x` and
144
+ `--donation1x`, each in THB except the counts. `@trajectonomics/tax` applies
145
+ every statutory ceiling; the CLI holds no amount of its own. The write reports
146
+ which deduction classes the flags stated and which they left out, so a
147
+ deduction nobody stated is visible rather than assumed to be zero. It states
148
+ what the flags said, never what tax-core applied: a premium the statute does
149
+ not allow for the filing status is still stated, and the Levy zeroes it.
150
+
151
+ ```json
152
+ {
153
+ "status": "updated",
154
+ "allowances": {
155
+ "stated": ["lifeInsurance"],
156
+ "notStated": ["children", "socialSecurity", "mortgageInterest", "donation1x"]
157
+ }
158
+ }
159
+ ```
160
+
161
+ A Projection that starts inside a tax period also needs what that period had
162
+ already taken: `--carry-in carry-in.json` states it, one record per Scenario,
163
+ Levy and period, with a `"0.00"` for every class the period had no income in or
164
+ one `"rest": "0.00"` for all the rest. The result echoes every record it used
165
+ and where it came from, and one that starts on a period boundary needs nothing:
166
+
167
+ ```json
168
+ [
169
+ {
170
+ "scenario": "base",
171
+ "levy": "th-2026-pit",
172
+ "periodStart": "2026-01-01",
173
+ "tallies": [{ "label": "income.section40_1", "basis": "gross", "amount": "0.00" }],
174
+ "prepaid": "0.00",
175
+ "rest": "0.00"
176
+ }
177
+ ]
178
+ ```
179
+
180
+ ## Keeping a backup, and removing the data
181
+
182
+ > **Ships in 0.3.0.**
183
+ > The release you installed has no `doctor`, `backup`, `restore` or `data remove`: they are on
184
+ > `main` and reach the install channels with `0.3.0`.
185
+
186
+ Four commands keep the ledger recoverable. `traj doctor` checks the data directory, the
187
+ database and every stored transaction and says what is wrong without changing anything;
188
+ `--as-of` adds the trial balance at a date. It exits 0 when its checks ran, with `"ok": false`
189
+ when one found a problem, because the finding is the answer; a non-zero exit is for what the
190
+ command could not do at all.
191
+
192
+ `traj backup --out backup` writes `traj.jsonl`, the canonical dump, into a directory that must
193
+ not exist yet, and `traj restore backup` writes it into an empty data directory byte for byte.
194
+ A restore refuses a database that already holds data: to replace live data, remove it first,
195
+ or restore into a second `TRAJ_HOME`. CSV and Markdown exports are for people; only the JSONL
196
+ restores.
197
+
198
+ `traj data remove` deletes `traj.db` and nothing else, so the launcher's `bin/` cache beside it
199
+ survives. It prints what would be lost, and it refuses unless `--confirm` names the data
200
+ directory's own path and `--backup` names a backup whose bytes are the data's, so a removal
201
+ cannot outrun the last write:
202
+
203
+ ```bash
204
+ traj doctor --as-of 2026-11-30
205
+ traj backup --out ~/traj-backup-2026-11-30
206
+ traj data remove --confirm ~/.traj --backup ~/traj-backup-2026-11-30
207
+ ```
208
+
53
209
  ## Docs
54
210
 
55
211
  - [`GLOSSARY.md`](GLOSSARY.md): the project's vocabulary.
@@ -65,7 +221,10 @@ examples, the error codes it raises, and a `run` that returns `ok(data)` or
65
221
  `fail(code)`. Register it in `src/commands/index.ts`, inside a `defineGroup` if
66
222
  it is nested. Fields of the input schema that are not positionals become flags
67
223
  automatically (`fromDate` is `--from-date`). A new failure is a new entry in the
68
- registry in `src/errors.ts` with its exit class. Commands never format output or
224
+ registry in `src/registry.ts` with its exit class; add it to `RETRYABLE_CODES` there only when
225
+ retrying the same command can succeed. An input-validation sentence
226
+ comes from the shared table beside it, so a new command needs no wording of its
227
+ own. Commands never format output or
69
228
  exit; `traj help <path>` and `traj schema <path>` are generated from the same
70
229
  schemas that validate them. Test through `run(argv, io, env)`, which needs no
71
230
  process. See ADR 0015.
@@ -0,0 +1,2 @@
1
+ /** The installer's pure entry, which runs on Node as plain JavaScript. */
2
+ export declare function install(bytes: Uint8Array, dest: string): void
package/bin/install.js ADDED
@@ -0,0 +1,52 @@
1
+ /** Writes the release binary into the cache, completely or not at all. */
2
+ import {
3
+ chmodSync,
4
+ existsSync,
5
+ mkdirSync,
6
+ renameSync,
7
+ rmdirSync,
8
+ rmSync,
9
+ writeFileSync,
10
+ } from "node:fs"
11
+ import { dirname, join } from "node:path"
12
+ import { writeProblem } from "./launcher.js"
13
+
14
+ /** Removes the temp file, then the directory this run created when it is empty. */
15
+ function cleanFailedInstall(temp, directory, created) {
16
+ try {
17
+ rmSync(temp, { force: true })
18
+ } catch {
19
+ // The temp file was never written.
20
+ }
21
+ if (!created) return
22
+ try {
23
+ rmdirSync(directory)
24
+ } catch {
25
+ // Another run put a file there first; keep its directory.
26
+ }
27
+ }
28
+
29
+ /** A complete file at the cache path, never a half-written one: same directory, then a rename. */
30
+ export function install(bytes, dest) {
31
+ const directory = dirname(dest)
32
+ const created = !existsSync(directory)
33
+ const temp = join(directory, `.traj-${process.pid}-${Date.now()}`)
34
+ try {
35
+ mkdirSync(directory, { recursive: true })
36
+ writeFileSync(temp, bytes, { mode: 0o755 })
37
+ chmodSync(temp, 0o755)
38
+ renameSync(temp, dest)
39
+ } catch (error) {
40
+ // A concurrent run may have won the race with a complete file; use it and drop ours.
41
+ if (existsSync(dest)) return
42
+ // A first run that cannot install leaves no empty bin/ behind for the next run to trust.
43
+ cleanFailedInstall(temp, directory, created)
44
+ throw new Error(writeProblem(error, directory))
45
+ } finally {
46
+ try {
47
+ rmSync(temp, { force: true })
48
+ } catch {
49
+ // The directory was never created, so there is no half-written file to remove.
50
+ }
51
+ }
52
+ }
package/bin/launcher.d.ts CHANGED
@@ -7,3 +7,4 @@ export declare function sha256(bytes: Uint8Array): string
7
7
  export declare function verifyChecksum(checksums: string, name: string, bytes: Uint8Array): string
8
8
  export declare function exitStatus(code: number | null, signal: string | null): number
9
9
  export declare function releaseUrl(version: string, name: string, base?: string): string
10
+ export declare function writeProblem(error: unknown, directory: string): string
package/bin/launcher.js CHANGED
@@ -62,3 +62,21 @@ export function exitStatus(code, signal) {
62
62
  export function releaseUrl(version, name, base = RELEASE_BASE) {
63
63
  return `${base}/download/v${version}/${name}`
64
64
  }
65
+
66
+ /**
67
+ * A failed write in plain words: the cause, the directory, and the next step. Node reports a
68
+ * full disk as a bare "UNKNOWN: unknown error, write", so a known code carries the sentence.
69
+ */
70
+ export function writeProblem(error, directory) {
71
+ const code = error !== null && typeof error === "object" ? error.code : undefined
72
+ if (code === "ENOSPC" || code === "EDQUOT") {
73
+ return `disk full: needs about 100 MB in ${directory}; free space and retry.`
74
+ }
75
+ if (code === "EACCES" || code === "EPERM" || code === "EROFS") {
76
+ return `permission denied writing ${directory}; check its permissions or set TRAJ_HOME.`
77
+ }
78
+ if (code === "EEXIST" || code === "ENOTDIR" || code === "EISDIR") {
79
+ return `${directory} is not a directory; move the file or set TRAJ_HOME to a directory.`
80
+ }
81
+ return error instanceof Error ? error.message : String(error)
82
+ }
package/bin/traj.js CHANGED
@@ -1,18 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  /** The npm package's command: install the release binary for this package's version, then run it. */
3
3
  import { spawn } from "node:child_process"
4
- import {
5
- chmodSync,
6
- existsSync,
7
- mkdirSync,
8
- readFileSync,
9
- renameSync,
10
- rmSync,
11
- writeFileSync,
12
- } from "node:fs"
4
+ import { existsSync, readFileSync } from "node:fs"
13
5
  import { homedir } from "node:os"
14
- import { dirname, join } from "node:path"
6
+ import { join } from "node:path"
15
7
  import { setTimeout as sleep } from "node:timers/promises"
8
+ import { install } from "./install.js"
16
9
  import { assetName, exitStatus, releaseUrl, verifyChecksum } from "./launcher.js"
17
10
 
18
11
  const RETRY_MS = 5 * 60 * 1000
@@ -55,24 +48,6 @@ async function download(url) {
55
48
  }
56
49
  }
57
50
 
58
- /** A complete file at the cache path, never a half-written one: same directory, then a rename. */
59
- function install(bytes, dest) {
60
- mkdirSync(dirname(dest), { recursive: true })
61
- const temp = join(dirname(dest), `.traj-${process.pid}-${Date.now()}`)
62
- try {
63
- writeFileSync(temp, bytes, { mode: 0o755 })
64
- chmodSync(temp, 0o755)
65
- try {
66
- renameSync(temp, dest)
67
- } catch (error) {
68
- // A concurrent run won the race; its file is complete, so use it and drop ours.
69
- if (!existsSync(dest)) throw error
70
- }
71
- } finally {
72
- rmSync(temp, { force: true })
73
- }
74
- }
75
-
76
51
  async function main(args) {
77
52
  const chosen = process.env["TRAJ_BINARY_PATH"]
78
53
  if (chosen !== undefined) return run(chosen, args)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trajectonomics/cli",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "trajectonomics command line",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -31,14 +31,15 @@
31
31
  "typecheck": "tsc --noEmit",
32
32
  "lint": "biome ci --error-on-warnings .",
33
33
  "format": "biome check --write .",
34
- "build": "bun build src/index.ts --compile --outfile dist/traj",
34
+ "build": "bun build src/index.ts --compile --no-compile-autoload-bunfig --no-compile-autoload-dotenv --outfile dist/traj",
35
35
  "check": "bun run lint && bun run typecheck && bun test && bun run build",
36
36
  "update:skills": "bunx skills@latest update -p -y"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@biomejs/biome": "2.6.3",
40
40
  "@trajectonomics/ledger": "0.1.0-alpha.0",
41
- "@trajectonomics/sim": "0.1.0",
41
+ "@trajectonomics/sim": "0.2.0-alpha.17",
42
+ "@trajectonomics/tax": "0.2.0-alpha.6",
42
43
  "@trajectonomics/tooling": "1.1.0",
43
44
  "@types/bun": "^1.4.4",
44
45
  "typescript": "^7.0.2",