Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

## 0.13.0

FormLedger ships its own FormTxt templates, and a document started from a template shows where each line posts.

### New
- **FormTxt templates in the box:** `formledger formtxt-template` writes FormLedger's invoice template as a file, and `formledger formtxt-template statement` writes the statement one. Open the file once in FormTxt (File > Open or import file). After that FormLedger finds the template in FormTxt by its name, with nothing to set. `FORMLEDGER_FORMTXT_TEMPLATE_INVOICE` still works and wins when set.
- **Account names on template lines:** in a document started from a template, each free line shows the account it posts to, for example "4100 Sales", at the end of its description.

### Changed
- **FormLedger waits 13 seconds for FormTxt,** down from 100, then prints the plain page and says why.

### Fixed
- Opening a document from a template no longer nudges the buttons at the bottom as "Confirm" becomes "Post".
- Dashboard figures and chart axes follow the currency's decimal places, so a currency with no minor unit is no longer shown 100 times too small.

### Known issues
- FormLedger cannot put its template into FormTxt for you: FormTxt gives an outside program no way to create a document, so you open the file there once (`docs/PRINT.md`).
- Quotes, orders and the buying documents have no FormTxt template yet; they print with the plain renderer.
- FormTxt keeps each page it draws as a document in its own library.

### Under the hood
- Checked for this version: an invoice and a statement drawn by FormTxt 0.38.0 from the shipped templates, and the plain page after an unanswered question at 13 seconds. Not run: the dashboard change with a currency that has no minor unit; the desktop app was not compiled, and nothing ran on macOS or Windows.

## 0.12.0

FormLedger writes a snapshot from the window, keeps its own key on the desktop, tells you when FormTxt did not draw a page, and names the accounts its templates post to.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION := v0.12.0
VERSION := v0.13.0
GO_BUILD := CGO_ENABLED=0 go build -trimpath -ldflags "-s -w"

.PHONY: build web server check clean
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</p>

<p align="center">
<img alt="version v0.12.0" src="https://img.shields.io/badge/version-v0.12.0-eef0f4?style=flat-square">
<img alt="version v0.13.0" src="https://img.shields.io/badge/version-v0.13.0-eef0f4?style=flat-square">
<img alt="Go 1.26+" src="https://img.shields.io/badge/Go-1.26%2B-00ADD8?style=flat-square&logo=go&logoColor=white">
<img alt="TypeScript and Vite" src="https://img.shields.io/badge/TypeScript-Vite-3178c6?style=flat-square">
<img alt="License: Apache-2.0" src="https://img.shields.io/badge/license-Apache--2.0-3a3a3a?style=flat-square">
Expand Down
11 changes: 10 additions & 1 deletion cmd/HASHOUT_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Living log of all comment content, explainers, rationale, TODOs, & removed (hashed-out) code for the entry point, `embed.go`, `internal/server`, `internal/static` and `internal/startup`. Source files stay comment-free per dev-rules `sub-skills/hashout-log/SUB-SKILL.md`; everything they would have said lives here, indexed. Read it first, then edit code surgically.

Current build version: v0.12.0
Current build version: v0.13.0
Last updated: 2026-11-26 (US Eastern) · skeleton port from form.md

---
Expand Down Expand Up @@ -217,3 +217,12 @@ Import path changed to `formledger/internal/nowindow`. No entries.
## internal/startup/proc_other.go {#internal-startup-proc-other-go}

Verbatim from the donor. No entries.

---

### cmd/formledger/main.go · formtxt-template
- refers-to: cmd/formledger/main.go :: run (case "formtxt-template"), usage; internal/printout/template.go :: TemplateCommand
- kind: rationale
- logged: v0.13.0 · 2026-11-27

A top-level command rather than `cli`, because it needs no server and no token: it only writes the embedded template as a `.ftxt` file (`--out FILE`, `-` for standard output, default `formledger-invoice.ftxt` in the current folder) and says to open it in FormTxt with File > Open or import file. Errors exit 2 like an unknown command.
8 changes: 8 additions & 0 deletions cmd/formledger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/nodemode-ai/formledger/internal/config"
"github.com/nodemode-ai/formledger/internal/crypt"
"github.com/nodemode-ai/formledger/internal/nowindow"
"github.com/nodemode-ai/formledger/internal/printout"
"github.com/nodemode-ai/formledger/internal/server"
"github.com/nodemode-ai/formledger/internal/snapshot"
"github.com/nodemode-ai/formledger/internal/startup"
Expand All @@ -40,6 +41,12 @@ func run(args []string) int {
return cli.Run(args[1:], os.Stdout, os.Stderr)
case "report":
return snapshot.Main(args[1:], os.Stdout, os.Stderr)
case "formtxt-template":
if err := printout.TemplateCommand(args[1:], os.Stdout); err != nil {
fmt.Fprintln(os.Stderr, "formledger:", err)
return 2
}
return 0
case "keygen":
fmt.Println(crypt.Generate())
return 0
Expand Down Expand Up @@ -205,6 +212,7 @@ func usage(w io.Writer) {
fmt.Fprintln(w, " serve run the server (default)")
fmt.Fprintln(w, " cli <command> ledger commands against the running server (formledger cli --help)")
fmt.Fprintln(w, " report snapshot write a plain read-only SQLite snapshot (--out FILE, --force; server stopped)")
fmt.Fprintln(w, " formtxt-template write FormLedger's invoice (or statement) template for FormTxt (--out FILE, default formledger-KIND.ftxt)")
fmt.Fprintln(w, " keygen print a new at-rest encryption key")
fmt.Fprintln(w, " encrypt encrypt an existing plain ledger with FORMLEDGER_KEY_FILE (server stopped)")
fmt.Fprintln(w, " version print the version")
Expand Down
20 changes: 13 additions & 7 deletions docs/PRINT.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,21 @@ Rendering goes through a list of renderers, each of which draws a document and a

- It finds FormTxt the way FormTxt's own tools do (`setup/report.py`, `setup/catalogue.py`): the engine at `http://127.0.0.1:$FORMTXT_ENGINE_PORT`, port `8210` when unset. There is no discovery file.
- It posts to `/api/reports/run` with the data as `records` (one record per line, the document's header fields repeated on each: `company`, `title`, `number`, `date`, `dueDate`, `customer`, `customerName`, `supplier`, `supplierName`, `currency`, `status`, `memo`, `subtotal`, `taxTotal`, `total`, then `item`, `description`, `quantity`, `unitPrice`, `taxRate`, `lineSubtotal`; a statement's are `customer`, `customerName`, `currency`, `from`, `to`, `opening`, `closing`, then `lineDate`, `event`, `reference`, `debit`, `credit`, `balance`), `mode` `list`, `format` `pdf`, and `out` a file in a fresh temporary folder that it reads back and removes. Amounts arrive formatted, as on the plain page.
- The template is a FormTxt document id, named per kind in the server's environment: `FORMLEDGER_FORMTXT_TEMPLATE_INVOICE`, `_QUOTE`, `_ORDER`, `_PURCHASE_ORDER`, `_PURCHASE_INVOICE`, `_GOODS_RECEIPT`, `_STATEMENT`. A kind with no template goes to the plain renderer.
- Any failure (no engine, a refusal, a timeout of 100 seconds, a file that is not a PDF) goes to the plain renderer. When FormTxt answered but did not draw, the response carries the reason in `X-FormLedger-Renderer-Note` (path-escaped) and `cli print` writes it on standard error under the renderer line. A 403 reads: `FormTxt refused to draw the page, so FormLedger drew the plain page. FormTxt said: No FormTxt window is open. Start it with ./formtxt and open the app, then retry. Open FormTxt, allow outside agents when it asks, or turn on Allow outside agents in its Preferences under Privacy, then print again.` A template id FormTxt does not hold (404) names the environment variable to set. The wait is 100 seconds so the person can answer FormTxt's question, and stays under `cli print`'s own two minutes; FormTxt itself waits up to 180 seconds for the answer.
- The template is a FormTxt document. FormLedger ships one for invoices (below). When `FORMLEDGER_FORMTXT_TEMPLATE_INVOICE` is unset, FormLedger reads FormTxt's document list (`GET /api/documents`, a read FormTxt answers any local caller) and uses the newest document titled `FormLedger invoice template`. A set id always wins, per kind: `FORMLEDGER_FORMTXT_TEMPLATE_INVOICE`, `_QUOTE`, `_ORDER`, `_PURCHASE_ORDER`, `_PURCHASE_INVOICE`, `_GOODS_RECEIPT`, `_STATEMENT`. Any other kind with no id set goes to the plain renderer.
- Any failure (no engine, a refusal, a timeout of 13 seconds, a file that is not a PDF) goes to the plain renderer. When FormTxt answered but did not draw, the response carries the reason in `X-FormLedger-Renderer-Note` (path-escaped) and `cli print` writes it on standard error under the renderer line. A 403 reads: `FormTxt refused to draw the page, so FormLedger drew the plain page. FormTxt said: No FormTxt window is open. Start it with ./formtxt and open the app, then retry. Open FormTxt, allow outside agents when it asks, or turn on Allow outside agents in its Preferences under Privacy, then print again.` A template id FormTxt does not hold (404) names the environment variable to set. The wait is 13 seconds, the owner's choice: a person who has not answered FormTxt's question by then gets the plain page and prints again after answering. FormTxt itself waits up to 180 seconds for the answer and withdraws the question when FormLedger hangs up.

### Setting it up
### The shipped invoice template

No templates ship: FormTxt's report route merges into a document in FormTxt's own store, and only the FormTxt window can create one (`POST /api/documents` without the window's key answers `Only the FormTxt window can do this`).
FormLedger carries an invoice template as its own data, written in FormTxt's `.ftxt` document format (`internal/printout/formtxt_invoice.json`, embedded in the binary). It is titled `FormLedger invoice template` and holds the company name, the document title and number, date, due date, currency and status, the bill-to customer name and code, a line table whose header row repeats on every page and whose second row is marked to repeat once per line (`item`, `description`, `quantity`, `unitPrice` as Rate, `taxRate`, `lineSubtotal` as Amount), then subtotal, tax, total with the currency, the notes, and "Page N of M" in the footer. A statement template ships the same way (`internal/printout/formtxt_statement.json`, titled `FormLedger statement template`, written by `./formledger formtxt-template statement`): company, period, customer name and code, currency, opening balance, one repeating row per event (`lineDate`, `event`, `reference`, `debit`, `credit`, `balance`) and the closing balance. With no `from` the heading reads "Statement to" and the end date. The two lookups are separate, so each kind uses its template once it is in FormTxt.

1. Open the FormTxt window. Make a document with the header fields as merge fields and a table whose line row is marked to repeat (`merge.repeatRow`), its cells holding `item`, `description`, `quantity`, `unitPrice`, `taxRate`, `lineSubtotal`. A list merge refuses a template with no repeating row.
2. Set `FORMLEDGER_FORMTXT_TEMPLATE_INVOICE` (and the other kinds) to that document's id, and `FORMTXT_ENGINE_PORT` when FormTxt is not on 8210, in FormLedger's server environment.
3. Print once with the window open. FormTxt asks **Allow an outside agent to make changes in FormTxt?**, naming the temporary file it will write, with Deny, Allow once and Always allow all outside agents. Always allow saves `agentsAllowed` in FormTxt's own `settings.json` in its data folder (not the system password store), so later prints draw with no window open. Allow once lets that one print through without saving the answer (read from FormTxt's `consent`, not tried here).
FormLedger does not put the template into FormTxt by itself. FormTxt gives an outside program no way to create a document: every write but `/mcp` and `/api/reports/run` needs the key only FormTxt's own window holds for that launch, `/mcp` runs the window's editing commands (none of which types text or opens a file from a path), and `/api/reports/run` merges into a document that must already be in FormTxt's library. Taking the window's key from its session storage, or writing into FormTxt's data folder, would get past FormTxt's consent, so FormLedger does neither. The person adds it once:

1. Run `./formledger formtxt-template` (or `--out FILE`). It writes `formledger-invoice.ftxt` and names the full path.
2. In the FormTxt window, choose File > Open or import file and pick that file. FormTxt adds it to its library as `FormLedger invoice template`. Set `FORMTXT_ENGINE_PORT` in FormLedger's server environment when FormTxt is not on 8210; no template id is needed.
3. Print once with the window open. FormTxt asks **Allow an outside agent to make changes in FormTxt?**, naming the temporary file it will write, with Deny, Allow once and Always allow all outside agents. Answer within 13 seconds, or print again after answering. Always allow saves `agentsAllowed` in FormTxt's own `settings.json` in its data folder (not the system password store), so later prints draw with no window open. Allow once lets that one print through without saving the answer (read from FormTxt's `consent`, not tried here).

Until step 2 is done, printing goes to the plain renderer with the note: `FormTxt holds no document named FormLedger invoice template, so FormLedger drew the plain page. Run ./formledger formtxt-template, open the file it writes in FormTxt with File > Open or import file, then print again.`

**Run on 2026-11-27 against FormTxt 0.38.0** (a copy with its own engine on port 8701 and data folder, its window built from its own frontend and opened in headless Chrome; FormLedger's server had no `FORMLEDGER_FORMTXT_TEMPLATE_*` variable set). On the fresh FormTxt library, `cli print invoice SI-2026-000001` printed plain in 0.32 seconds with the note above. The file from `formledger formtxt-template` was then opened through File > Open or import file; the next print raised FormTxt's question, Always allow was clicked 2.15 seconds in, and the page was drawn by FormTxt from the shipped template in 2.87 seconds (`printed by the formtxt renderer`): every field, the three lines, subtotal 68.13, tax 5.45 and total USD 73.58 were filled. With the window open but the question left unanswered, FormLedger gave up after 13.13 seconds and printed plain with the 13 second note. With FormTxt's engine stopped it printed plain in 0.35 seconds, since nothing answered on the port. Then `cli print statement ACME` printed plain with the statement note, the statement file was opened the same way, and the next statement print was drawn by FormTxt in 0.20 seconds with outside agents already allowed. FormTxt's report route also keeps each merged result in its own library (here `Invoice SI-2026-000001`); that is FormTxt's behavior and FormLedger does not remove it.

With the engine running and no window, and outside agents not allowed, FormTxt answers 403 `No FormTxt window is open`, and FormLedger prints with the plain renderer and the note above.
9 changes: 8 additions & 1 deletion internal/HASHOUT_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Living log of comment content, rationale and removed code for the core skeleton packages under `internal/`. Source files stay comment-free; what they would have said lives here, indexed. Read it first, then edit code surgically. Covers the packages ported in the core slice only; `internal/server`, `internal/static` and `internal/startup` are logged by their own slice.

Current build version: v0.12.0
Current build version: v0.13.0
Last updated: 2026-11-27 (US Eastern) · profit and loss and the balance sheet

---
Expand Down Expand Up @@ -1875,3 +1875,10 @@ The owner said yes to both: the desktop app makes and keeps its own key, and `fo
- logged: v0.12.0 · 2026-11-27

Run against a copy of FormTxt 0.38.0 (engine on 8504, its window built from its own frontend and opened in headless Chrome). The route, the `records` payload, `mode list`, `format pdf` and the fresh `out` path were right as written; FormTxt answered 200 and the page came out with every merge field filled. What was wrong was the silence: a template id FormTxt does not hold came back 404 and FormLedger printed plain with no word why, and a 403 did the same. `refused` carries a sentence and still `Is` `ErrUnavailable`, so the chain falls through unchanged; `pick` keeps the first such sentence and the route sends it path-escaped in `X-FormLedger-Renderer-Note`, because a header cannot hold every character a FormTxt detail may contain. The wait went from 45 to 100 seconds: the first print blocks on FormTxt's Allow question (FormTxt waits up to 180 seconds and withdraws the question when the caller hangs up), and 100 stays inside `cli print`'s two minute client. Always allow all outside agents saved `agentsAllowed: true` in FormTxt's data-folder `settings.json`; no system password store is involved, so the sandbox had nothing to refuse.

### internal/printout/template.go · shipped FormTxt invoice template, found by name
- refers-to: internal/printout/template.go :: invoiceTemplate, InvoiceTemplateTitle, shipped, InvoiceTemplate, TemplateCommand, findShipped; internal/printout/formtxt.go :: run (http.Client Timeout, findShipped); internal/printout/formtxt_invoice.json
- kind: rationale
- logged: v0.13.0 · 2026-11-27

The owner chose a 13 second wait (down from 100) and a shipped template. The template is FormLedger's own data in FormTxt's `.ftxt` format (docs/FORMAT.md in FormTxt): `document.json` is embedded and packed on demand with `mimetype` stored first, as the format requires, with zip times fixed at 1970 so the file is the same bytes every run. FormTxt gives outside programs no create route: every write but `/mcp` and `/api/reports/run` needs the window's per-launch key, and none of the window commands `/mcp` runs types text or opens a path. So FormLedger never creates the document; the person opens the file once with File > Open or import file, and `findShipped` matches the exact title on FormTxt's open `GET /api/documents` (newest `modified` wins, so a re-import replaces an older copy without clearing it). A set `FORMLEDGER_FORMTXT_TEMPLATE_*` id still wins, and only `invoice` has a shipped title; the list read shares the 13 second limit. Ids in the JSON are FormTxt-style prefixes with 4 or more letters because the format says so, though the merge re-ids every block. Proven on 2026-11-27 against FormTxt 0.38.0 on port 8701: plain with the missing-template note before import, FormTxt-drawn after import and Always allow (2.87 s), plain after 13.13 s with the question unanswered, plain in 0.35 s with the engine stopped.
2 changes: 1 addition & 1 deletion internal/app/version.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package app

var Version = "v0.12.0"
var Version = "v0.13.0"

const Product = "FormLedger"
13 changes: 10 additions & 3 deletions internal/printout/formtxt.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,16 @@ func (f formtxt) Statement(s *Statement) ([]byte, error) {

func (formtxt) run(kind, title string, rows []map[string]any) ([]byte, error) {
base, template := formtxtBase(), formtxtTemplate(kind)
if base == "" || template == "" {
if base == "" {
return nil, ErrUnavailable
}
if template == "" {
found, err := findShipped(base, kind)
if err != nil {
return nil, err
}
template = found
}
dir, err := os.MkdirTemp("", "formledger-print-")
if err != nil {
return nil, ErrUnavailable
Expand All @@ -95,11 +102,11 @@ func (formtxt) run(kind, title string, rows []map[string]any) ([]byte, error) {
if err != nil {
return nil, ErrUnavailable
}
resp, err := (&http.Client{Timeout: 100 * time.Second}).Post(base+"/api/reports/run", "application/json", bytes.NewReader(body))
resp, err := (&http.Client{Timeout: 13 * time.Second}).Post(base+"/api/reports/run", "application/json", bytes.NewReader(body))
if err != nil {
var late interface{ Timeout() bool }
if errors.As(err, &late) && late.Timeout() {
return nil, refused{"FormTxt did not answer within 100 seconds, so FormLedger drew the plain page. If FormTxt is asking Allow outside agents?, answer it and print again."}
return nil, refused{"FormTxt did not answer within 13 seconds, so FormLedger drew the plain page. If FormTxt is asking Allow outside agents?, answer it and print again."}
}
return nil, ErrUnavailable
}
Expand Down
Loading
Loading