@trajectonomics/cli 0.8.0-alpha.14 → 0.8.0-alpha.141

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 (2) hide show
  1. package/README.md +322 -2
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -84,9 +84,48 @@ traj report networth --as-of 2026-03-31
84
84
  comes from, and a transaction moves an amount from one to another. Every read states its own
85
85
  date and never reads the clock, so the same command always answers the same question.
86
86
 
87
+ To chart net worth over time, state every month-end of a period in one read instead of one
88
+ call per month:
89
+
90
+ ```bash
91
+ traj report networth --monthly --since 2026-01-01 --until 2026-03-31
92
+ ```
93
+
94
+ Each month is exactly what `--as-of` gives for that date.
95
+
96
+ A figure that sums accounts (net worth, the trial balance's debit and credit columns, the P&L's income
97
+ less expenses) can leave the safe integer range though every account is inside it. The read still
98
+ exits 0 and states every account, and states that figure as `null` with an error object beside it
99
+ (`netWorthError`, `totalsError`); the text form prints a sentence in its place. A figure inside the
100
+ range carries no error key. Run `traj schema balance` or `traj schema report pnl` for the exact shape.
101
+
87
102
  `traj help` lists every command, `traj help <command>` lists one command's flags, and
88
103
  `traj schema --json` prints the whole contract: every command's input, output and error codes.
89
104
 
105
+ ## Importing a statement
106
+
107
+ To load a bank statement, fill the one CSV template instead of adding each transaction by
108
+ hand. `traj tx import` has been in every release since 0.1.0.
109
+
110
+ ```bash
111
+ traj tx import --template # print the template header and nothing else
112
+ traj tx import statement.csv --dry-run
113
+ traj tx import statement.csv
114
+ ```
115
+
116
+ `--template` prints the header the importer reads, and it opens no data directory:
117
+
118
+ ```csv
119
+ date,from,to,amount,memo,external_ref,project
120
+ ```
121
+
122
+ Start your file with that header and write one row per transaction. `--dry-run` reports every
123
+ row and rolls every write back, so run it first. A file name of `-` reads the CSV from stdin, as in
124
+ `traj tx import - --dry-run`. The import is all or nothing, and `external_ref` is the duplicate
125
+ key, so importing the same statement twice adds nothing the second time. Each command's flags and
126
+ the rest of the columns are in
127
+ [the `tx` page of the docs](https://docs.trajectonomics.com/cli/commands/tx/).
128
+
90
129
  ## Development
91
130
 
92
131
  The sources are Bun-only; a released binary needs nothing.
@@ -144,6 +183,14 @@ deduction nobody stated is visible rather than assumed to be zero. It states
144
183
  what the flags said, never what tax-core applied: a premium the statute does
145
184
  not allow for the filing status is still stated, and the Levy zeroes it.
146
185
 
186
+ The write keeps that profile beside the Scenario, and `traj scenario show` prints
187
+ it back as `tax`. `--merge` then changes only the flags it carries
188
+ (`traj scenario tax base --merge --children 2`) and keeps the rest, and
189
+ `--from-stored` writes the Levy again from the profile, for example after a
190
+ tax-year update. Both need a stored profile: a plan taxed before it was kept
191
+ states its profile whole once. `--if-hash` refuses a write over a plan that
192
+ changed since you read it, as on `scenario apply`.
193
+
147
194
  ```json
148
195
  {
149
196
  "status": "updated",
@@ -154,6 +201,47 @@ not allow for the filing status is still stated, and the Levy zeroes it.
154
201
  }
155
202
  ```
156
203
 
204
+ A couple who file jointly get each spouse's own expense ceiling. When the plan's household
205
+ has a partner and `owners` that say whose each Flow and Account is,
206
+ `--filing-status married_joint` writes one Levy over both people as Filers: the CLI adds the Owner's suffix to each tax label (`income.section40_1@me`,
207
+ `@partner`, or `@shared` for income of both), so state the bare label as before.
208
+ Section 42 bis gives each spouse their own 50% expense, capped at 100,000, even on a
209
+ joint return, which one Levy over a single label could not apply. Salaries of
210
+ 1,000,000 and 500,000 owe 160,000 this way, where a Levy over one label owes
211
+ 185,000. A taxed Flow with no Owner, or a person id that is not 1 to 32 lowercase
212
+ letters, digits or hyphens, is refused by name. A plan without a partner or without
213
+ `owners` writes the bare labels it always wrote, for every filing status. The result
214
+ lists the `filers` when it has any, and the household's Owners are read each time the
215
+ tax is written, so after changing them run `traj scenario tax <name> --from-stored`.
216
+
217
+ A couple who file separately get one Levy each. `--filing-status married_separate` writes
218
+ `th-2026-pit@me` and `th-2026-pit@partner`, one per person who has a labelled Flow or
219
+ Account, with the same Owner suffixes. Each Prepayment of the tax moves to the Levy of its
220
+ Flow's Owner (a Prepayment of a Levy of your own stays). A `shared` Flow's Prepayment is
221
+ split half to each, and its capped Prepayment stays whole on the holder's. Each allowance
222
+ flag takes a person (`--parents partner=2`) so each Return states its own claims, a bare
223
+ value names the holder, and each Return's children default to 0. A value for someone with
224
+ no income is refused, because no Return carries it. A Return claims at most its own two
225
+ parents. Interest on one loan borrowed together is stated once, as `--mortgage-interest
226
+ shared=60000`: each Return claims half, an odd satang goes to the holder, and a sole
227
+ person with income claims it all. The shared total is at most 100,000 baht
228
+ (`MORTGAGE_OVER_CEILING`), and `shared=` is refused under any other filing status. A
229
+ person's own `--mortgage-interest` is for their other loans, and each Return claims at
230
+ most 100,000 baht of its own interest and its share together. `traj` cannot tell which
231
+ loan interest is on, so when both claim their own, a loan's Owner is `shared` and no
232
+ shared interest is stated, the result's `assumptions` say the loans are taken to be
233
+ separate. `--merge` and `--from-stored` keep the stored `returns` and
234
+ `sharedMortgageInterest`, and `--merge` to `married_joint` keeps the partner's Return and
235
+ the shared interest for a later switch back; a joint Return claims neither, so state its
236
+ interest bare. A write that claims neither says so in its `assumptions`, on
237
+ `allowances.mortgageInterestCeiling`. The stored profile's `claimsHolder` says whose
238
+ claims its other keys are, so if the household swaps which person is the holder, each
239
+ person's claims stay theirs. A `projection run` then reports a `filer` on each `taxYears`
240
+ entry, `--carry-in` takes one record per Levy, and `projection allowances` answers per
241
+ Return. A person given a new id reads as another person: no separate Return counts the
242
+ claims stored under the old id, and each separate write says so in `assumptions`, at
243
+ `returns.<old id>`, until a `--tax` write states the profile again.
244
+
157
245
  A Projection that starts inside a tax period also needs what that period had
158
246
  already taken: `--carry-in carry-in.json` states it, one record per Scenario,
159
247
  Levy and period, with a `"0.00"` for every class the period had no income in or
@@ -173,6 +261,11 @@ and where it came from, and one that starts on a period boundary needs nothing:
173
261
  ]
174
262
  ```
175
263
 
264
+ A Levy over Filers reads Filer labels, so its record names them: each of its 29 classes
265
+ once per Filer (`income.section40_1@me`) and its 22 income classes once more for income
266
+ of both (`income.section40_1@shared`), 80 for two Filers where a Levy over one label has
267
+ 29. A missing class is listed by name, and a bare label is refused.
268
+
176
269
  ## Chance of success
177
270
 
178
271
  > **Ships in 0.8.0.**
@@ -184,8 +277,43 @@ year. The paths draw from a Return model you state in a JSON file, with
184
277
  seed and count always give the same answer. The CLI ships no Return model: which
185
278
  market history a plan is tested against is your decision, and every figure is
186
279
  only as good as that choice. `traj schema projection chance` describes the file.
187
- Pass the same three flags to `traj dashboard` to add the chance of success to the
188
- Dashboard, as a page of its own.
280
+ Or pass `--return-model plan` to build the model from the plan itself: each asset
281
+ Account's `rate` and its `volatility` (the standard deviation of its yearly
282
+ return, in basis points, which you write into the Scenario). `--buckets` sets its
283
+ size (a power of two from 16 to 1024, 256 by default), the result echoes what it
284
+ was built from as `returnModel`, and `traj projection model --scenario NAME`
285
+ prints the model as JSON, a file `--return-model` reads back. A plan with no
286
+ `volatility` is refused, because every path would be the same path.
287
+ Add `--outcomes` to see what each path came to: its closing and lowest net
288
+ worth, the year it was lowest and when it ran out, with the paths at the 10th,
289
+ 50th and 90th percentile, the earliest to run out and the lowest named as
290
+ `representative` (the human form prints every path, worst first). Then
291
+ `traj projection path --index N`, with the same flags, replays path N year by
292
+ year: `projection run`'s result, with the same flags for the cash flow and each
293
+ Account's value, plus the market return each Account drew in each year as
294
+ `returns`. An index is a path's name under the seed, so it is from 0 to
295
+ `--paths` minus 1.
296
+ Pass `--paths` and `--seed` to `traj dashboard` to add the chance of success to the
297
+ Dashboard, as a page of its own: it uses `plan` unless you name a
298
+ `--return-model` file.
299
+
300
+ ## Tax allowances
301
+
302
+ > **Ships in 0.8.0.**
303
+
304
+ `traj projection allowances` reads a Scenario that has a tax Levy and says, for each
305
+ whole tax year the Projection holds, how much more of each contribution label (RMF, ThaiESG
306
+ and the others the Levy reads) would still lower the tax, and by how much. You name the
307
+ labels in the order they should fill with `--labels`, and the size of one step with
308
+ `--step`, in major units: the CLI ships no default. `--budget` caps what the extra
309
+ contributions may add up to in a year, and `--min-saving` is the least percent of a step
310
+ a step must save. Each suggestion comes with the contribution Flow that would apply it,
311
+ which you add to the Scenario yourself: the command writes nothing. The figures are one
312
+ plan's own tax rules, an estimate and not tax advice, and each fund's holding rules are
313
+ not checked. A year that ended before the As-of, and a year the horizon cuts short, are left out; the
314
+ current year is included, and when the As-of falls mid-year it needs `--carry-in`, the
315
+ record of what was already contributed in that year earlier. `traj schema projection allowances`
316
+ describes the result.
189
317
 
190
318
  ## Money as decimals in a Scenario
191
319
 
@@ -197,6 +325,66 @@ Currency's major unit, such as `"1000.00"` for 100000 satang, and
197
325
  same either way: saving what `show --decimal` printed leaves it unchanged. A value with more places
198
326
  than the Currency has is refused, never rounded.
199
327
 
328
+ ## A what-if, applied to the plan it came from
329
+
330
+ > **Ships in 0.8.0.**
331
+
332
+ `traj projection run --set` projects a change without saving it. `traj scenario apply` saves the same
333
+ change to the stored plan, so the plan you keep is the one you projected. It takes the `--set`,
334
+ `--without` and `--decimal` that `projection run` takes, and refuses what they would be refused for:
335
+
336
+ ```bash
337
+ traj scenario apply base --set flows.salary.amount=9000000 --dry-run
338
+ traj scenario apply base --set flows.salary.amount=9000000 --without flows.gym
339
+ ```
340
+
341
+ The result names the Overrides it wrote. A change that leaves the plan as it is writes nothing and
342
+ exits 0. `--if-hash <contentHash>` writes only when the stored plan still has that hash, as
343
+ `traj scenario show` printed it, and refuses the write otherwise. Without `--file`, `--set` and
344
+ `--without` never take a document, so the what-if cannot replace a plan you did not read.
345
+
346
+ ### Adding an item to a what-if
347
+
348
+ > **Ships in 0.8.0.**
349
+
350
+ `--add <list>=<json>` puts one new item on the end of `accounts`, `flows` or `milestones`, so a new
351
+ loan, an extra payment or a new Flow can be tried before it is saved. The item carries its own `id`,
352
+ and an `id` the list already holds is refused (`--set` is the flag that changes an item that exists).
353
+ Every read that takes `--set` takes `--add` (`projection run`, `projection compare`, `fi`,
354
+ `projection chance` and `projection allowances`), and `scenario fork` and `scenario apply` save it:
355
+
356
+ ```bash
357
+ traj projection run --scenario base --as-of 2026-03-31 --horizon 2027-03-30 \
358
+ --add 'flows={"id":"extra","kind":"expense","amount":"1000.00","frequency":"monthly","start":"2026-04-01","growth":{"bps":0}}' --decimal
359
+ traj scenario apply base --add 'flows={...}' --decimal --if-hash <contentHash>
360
+ ```
361
+
362
+ The flags apply in a fixed order whatever order they are typed in: every `--without`, then every
363
+ `--add`, then every `--set`. So a `--set` can reach an item the same command adds
364
+ (`--add` then `--set flows.extra.amount=...`). An `--add` never replaces: one whose `list.id` the same
365
+ call's `--without` took out is refused, and `--set <path>.<key>=<value>` changes an item field by field,
366
+ so no field is dropped by accident and the plan saved is the plan projected. The result lists the items it added under `additions` (absent when none were), and
367
+ `effectiveContentHash` covers them. The engine checks the document with the item in it, so a refusal names
368
+ `--add` and the item's path (`flows.extra`) with the document path inside it. Under `--decimal` the
369
+ item's money is a decimal string of the Currency's major unit. Nothing is written until
370
+ `scenario apply` or `scenario fork` is run with the same flags.
371
+
372
+ ## Naming plans, keeping notes on them, and marking the main one
373
+
374
+ > **Ships in 0.8.0.**
375
+
376
+ A person who compares "retire at 55" with "retire at 60 and buy a condo" ends up with several plans.
377
+ `traj scenario rename early retire-at-55` gives a plan a better name and keeps its id, document and
378
+ `contentHash`. `traj scenario notes retire-at-55 --text "Sell the condo in 2031."` keeps plain text
379
+ on it (`--file <path>` or `--file -` reads it, `--clear` removes it), and `scenario show` prints it
380
+ back as `notes`. Notes are not part of the plan, so they never change its `contentHash`, and a
381
+ `scenario fork` copies them unless it is given `--no-notes`.
382
+
383
+ `traj scenario main retire-at-55` marks one plan as your main plan, and `scenario list` and
384
+ `scenario show` print `main`. It is a label and not a default: `projection run` and every other read
385
+ still need `--scenario`. `scenario rm` of the main plan is refused until another is chosen
386
+ (`scenario main --clear` takes the mark off), or removed anyway with `--force`.
387
+
200
388
  ## Milestones: points in the plan that a Flow waits for
201
389
 
202
390
  > **Ships in 0.8.0.**
@@ -221,6 +409,138 @@ each side.
221
409
  ]
222
410
  ```
223
411
 
412
+ ## Naming a Flow, a Milestone or a person
413
+
414
+ > **Ships in 0.8.0.**
415
+
416
+ Every Flow, every Milestone and every person of a household may carry a `displayLabel`: the words a
417
+ page reads in place of the id, such as Thai text. It is free text of 1 to 80 code points, with no
418
+ control, invisible or bidirectional characters and no leading or trailing whitespace. It is no key
419
+ and changes no figure: the id still addresses the item, the label may repeat or change, and the
420
+ engine never reads it. `traj schema scenario apply` and `traj schema scenario household` publish it
421
+ with that rule.
422
+
423
+ A label travels in the document, so `--file` and `--add` carry it, and `--set` writes it:
424
+
425
+ ```bash
426
+ traj scenario apply base --set 'flows.school-fees.displayLabel="School fees"'
427
+ traj scenario apply base --set 'milestones.condo.displayLabel="Condo down payment"'
428
+ traj scenario household base --file household.json # a person's label, in the household
429
+ ```
430
+
431
+ A plan written before the field may lack it, and the first `--set` that names it begins it, as
432
+ `--set accounts.<id>.volatility=…` does. Because a label is stored content, a change to one moves the
433
+ plan's `contentHash`; a plan without labels keeps its bytes and its hash. To clear a label, write the
434
+ document without it (`--file`), or empty the Name field in the Dashboard: `--set` writes a value and
435
+ cannot remove a key, so `null` and `""` are refused.
436
+
437
+ ## Where each year's money went
438
+
439
+ > **Ships in 0.8.0.**
440
+
441
+ `traj projection run --breakdown` adds each Annual roll-up's cash flow as the engine routed it: each
442
+ Flow's income, the tax taken at source and each Levy's settlement (a refund is negative), each expense
443
+ and its category, each Contribution applied and the part the cash could not fund, each planned
444
+ withdrawal, what `cashflow.withdraw` drew and what `cashflow.surplus` filled. In JSON it is the
445
+ `cashflow` table, one row per line. Its section totals are the `cashflowTotals` table beside it: nine rows per year,
446
+ in the order money in, tax, withdrawals, drawn, spending, saving, not funded, left over and unmet. The `cashflowTotals` table
447
+ and the human block come from one function (`cashflowTotalsOf`), so they cannot disagree. JSON states a zero total as `0.00`; the human block
448
+ leaves out a zero not funded or unmet, and withdrawals, drawn or tax when its roll-up has no line of that group. In the
449
+ human format it is one block per year, after the body:
450
+
451
+ ```
452
+ cash flow 2026-03-31 to 2027-03-30 (13 rows)
453
+ line amount
454
+ money in 124500.00
455
+ income 120000.00
456
+ withdrawals 3000.00
457
+ drawn 1500.00
458
+ tax 4200.00
459
+ spending 50700.00
460
+ housing 30000.00
461
+ food 18000.00
462
+ transport 1500.00
463
+ (uncategorised) 1200.00
464
+ saving 64800.00
465
+ not funded 19200.00
466
+ left over 4800.00
467
+ ```
468
+
469
+ Each total is the engine's figure, or an exact sum of the engine's own lines, so the CLI adds no figure of
470
+ its own. In every year, money in plus `unmet` (the cash a Shortfall left unpaid) equals tax, spending,
471
+ saving and left over: the engine routes every unit of cash. `not funded` is the part of the
472
+ Contributions the cash could not fund; it is not in saving.
473
+
474
+ ## Where the money goes, and moving it between Accounts
475
+
476
+ > **Ships in 0.8.0.**
477
+
478
+ `cashflow` takes three more forms, every figure in them the caller's own (`traj` ships none): a surplus step's `share`, which takes that
479
+ many basis points of what is still unrouted instead of everything (a percent string such as `"30.00"` under `--decimal`); a `withdraw` entry that is `{ account, downTo }`, which keeps a Reserve floor
480
+ in the Account while the others are drawn; and an `upTo` or `downTo` that is `{ amount, growth }`, which keeps its value in today's money. A
481
+ Flow of `kind: "transfer"` moves money between two of the plan's own Accounts, outside cashflow: a provident fund rolled into a locked RMF, or
482
+ a monthly amount from savings paying a loan down. `traj schema scenario apply` describes each, and `--set` reaches a step or an entry by
483
+ its position, so "what if I kept 100,000.00 in savings before touching the funds" is
484
+ `traj projection run --scenario plan --set cashflow.withdraw.0.downTo=10000000`.
485
+
486
+ `traj projection run` states what each did: the annual row's `transfers`, a `routing` echo of every step and entry by position,
487
+ and with `--breakdown` the `entry` each drawn line came from and a `transfers` table (what moved and what could not); with
488
+ `--liabilities`, `transferred` on a loan's months. The amount a target that keeps its value is worth on a later date is the engine's
489
+ and is not stated yet. A plan without these forms prints exactly as before.
490
+
491
+ ## Loans
492
+
493
+ > **Ships in 0.8.0.**
494
+
495
+ A loan is three parts of a Scenario document: a liability Account with a nominal `rate` and a `compounding`
496
+ period, a `withdrawal` Flow from that liability when the money arrives, and a Contribution into the
497
+ liability whose amount is a `level` payment. `traj schema scenario apply` publishes one as its worked example.
498
+
499
+ `traj projection run --liabilities` adds the engine's statement of each loan: one month row per liability
500
+ (`opening`, `drawn`, `paid`, `interest`, `closing`) and each loan's paid-off date. The rows shown are
501
+ one loan's months, cut from the table; it lists every liability the Scenario holds. In JSON they are the
502
+ `liabilities` and `paidOff` tables. The human format prints one line per loan, then its months:
503
+
504
+ ```
505
+ car: paid off on 2026-12-01
506
+ liabilities (26 rows)
507
+ account from to opening drawn paid interest closing partial
508
+ car 2026-06-01 2026-06-30 0.00 12000.00 0.00 58.00 12058.00 false
509
+ car 2026-07-01 2026-07-31 12058.00 0.00 2035.15 50.44 10073.29 false
510
+ car 2026-12-01 2026-12-31 9.66 0.00 9.66 0.00 0.00 false
511
+ ```
512
+
513
+ The figures are the engine's: `interest` is the residual of the month, so `opening + drawn − paid + interest`
514
+ equals `closing` exactly. Without `--liabilities` the output is unchanged.
515
+
516
+ ### What a fee and a payout came to over the plan
517
+
518
+ > **Ships in 0.8.0.**
519
+
520
+ An asset Account can pay out a share of its value as income (`payout`) and be charged a yearly `fee`.
521
+ `traj projection run` states each one's total over the whole horizon, so nothing needs adding up: the
522
+ engine sums them in the same run as the roll-ups (it is the sum of the `payouts` and `fees` of every
523
+ roll-up). Two fields appear, and only when the Scenario declares the item above 0 bps (0 bps is none):
524
+
525
+ - `accountLifetimes`: one `{ account, lifetimeFees?, lifetimePayouts? }` per Account that declares a fee or a payout,
526
+ in Scenario order. `lifetimeFees` is there when the Account carries a fee, `lifetimePayouts` when it carries a
527
+ payout; each is `0.00` if the Account never charged or paid.
528
+ - `lifetimeFees`: the fees of all Accounts together, present only when an Account carries a fee.
529
+
530
+ Both are money as every figure is, a decimal string at the currency's scale (`--decimal` changes what you
531
+ write, not what is read). The human format prints the plan-wide fees on a line of their own, then each
532
+ Account's totals as a table, and `projection path` states the same fields for a Market path:
533
+
534
+ ```
535
+ Fees over the plan, all accounts: 1514.01
536
+
537
+ accountLifetimes (1 row)
538
+ account lifetimeFees lifetimePayouts
539
+ fund 1514.01 4051.89
540
+ ```
541
+
542
+ Without a fee or a payout the output is unchanged.
543
+
224
544
  ## Seeing it in a browser
225
545
 
226
546
  `traj dashboard --as-of 2026-11-30 --horizon 2056-11-30` reads your ledger once and serves the Dashboard (net worth, the ledger, projections, the FI date, a Scenario compare, tax and health) on `http://127.0.0.1:4321/` until you press Ctrl-C. It only reads, it listens on this machine only, and it takes the same Scenario flags as the projection reads (`--scenario`, `--compare` twice, `--monthly`, `--carry-in`); `--port 0` picks a free port. Run it again to see new figures.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trajectonomics/cli",
3
- "version": "0.8.0-alpha.14",
3
+ "version": "0.8.0-alpha.141",
4
4
  "description": "trajectonomics command line",
5
5
  "license": "MIT",
6
6
  "type": "module",