@trajectonomics/cli 0.2.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 +100 -7
- package/bin/install.d.ts +2 -0
- package/bin/install.js +52 -0
- package/bin/launcher.d.ts +1 -0
- package/bin/launcher.js +18 -0
- package/bin/traj.js +3 -28
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -37,10 +37,10 @@ npx skills add trajectonomics/skills --skill traj-onboarding -y
|
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
The setup skill asks about your situation and goal, then its second step installs the `traj`
|
|
40
|
-
operating skill from `trajectonomics/
|
|
40
|
+
operating skill from `trajectonomics/skills`, the repository both skills publish from.
|
|
41
41
|
|
|
42
42
|
```bash
|
|
43
|
-
npx skills add trajectonomics/
|
|
43
|
+
npx skills add trajectonomics/skills --skill traj -y
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
That is the operating skill on its own, for an agent that is already set up. Both commands
|
|
@@ -53,7 +53,39 @@ Bun and want one command. Pin a release with `TRAJ_VERSION=X.Y.Z` for the script
|
|
|
53
53
|
`@X.Y.Z` for npm.
|
|
54
54
|
|
|
55
55
|
Uninstall by deleting the one file: `~/.local/bin/traj`, `%LOCALAPPDATA%\traj\bin`,
|
|
56
|
-
`~/.traj/bin` (the download cache), or nothing at all for
|
|
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.
|
|
57
89
|
|
|
58
90
|
## Development
|
|
59
91
|
|
|
@@ -85,15 +117,46 @@ nominal and real (monthly rows with `--monthly`); `traj projection compare`
|
|
|
85
117
|
puts two Scenarios side by side, or one against a `--set` what-if, with the
|
|
86
118
|
deltas in FI date, net worth at the ages you name and run-out year; and
|
|
87
119
|
`traj fi` reports the survival FI date beside the 25× rule of thumb as a
|
|
88
|
-
labelled reference. Every
|
|
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
|
|
89
122
|
Scenario's hashes, the Overrides it applied, and its tax status.
|
|
90
123
|
`traj schema <command>` describes each one.
|
|
91
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
|
+
|
|
92
133
|
Tax is the Scenario's. `traj scenario tax <name> --tax th-2026` writes Thailand's
|
|
93
134
|
2026 personal income tax into it, and `--label salary=income.section40_1` says
|
|
94
135
|
which Section 40 class each income Flow belongs to, because a Levy tallies
|
|
95
|
-
labels and never guesses them; `--none` takes both out again
|
|
96
|
-
|
|
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
|
+
```
|
|
97
160
|
|
|
98
161
|
A Projection that starts inside a tax period also needs what that period had
|
|
99
162
|
already taken: `--carry-in carry-in.json` states it, one record per Scenario,
|
|
@@ -114,6 +177,35 @@ and where it came from, and one that starts on a period boundary needs nothing:
|
|
|
114
177
|
]
|
|
115
178
|
```
|
|
116
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
|
+
|
|
117
209
|
## Docs
|
|
118
210
|
|
|
119
211
|
- [`GLOSSARY.md`](GLOSSARY.md): the project's vocabulary.
|
|
@@ -129,7 +221,8 @@ examples, the error codes it raises, and a `run` that returns `ok(data)` or
|
|
|
129
221
|
`fail(code)`. Register it in `src/commands/index.ts`, inside a `defineGroup` if
|
|
130
222
|
it is nested. Fields of the input schema that are not positionals become flags
|
|
131
223
|
automatically (`fromDate` is `--from-date`). A new failure is a new entry in the
|
|
132
|
-
registry in `src/registry.ts` with its exit class
|
|
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
|
|
133
226
|
comes from the shared table beside it, so a new command needs no wording of its
|
|
134
227
|
own. Commands never format output or
|
|
135
228
|
exit; `traj help <path>` and `traj schema <path>` are generated from the same
|
package/bin/install.d.ts
ADDED
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 {
|
|
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.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "trajectonomics command line",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -31,7 +31,7 @@
|
|
|
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
|
},
|