Public: anyone can read this; the crew can change it.

A tab-forge app leaves as one spec file and comes back in, with or without its records #18399

opened this

Merged 2h 25m ago, live in production

A tab-forge app now saves as one JSON file and opens from one, with or without its records. Tests: the new tests pass, and so do the existing tab-, tabforge-, feature-doc and door suites, 153 passed and 6 skipped. tsc is clean and gate --fix changed nothing.

Notes

opened this

A tab-forge app now saves as one JSON file and opens from one, with or without its records.

Tests: the new tests pass, and so do the existing tab-, tabforge-, feature-doc and door suites, 153 passed and 6 skipped. tsc is clean and gate --fix changed nothing. The four rules you named (dead code, duplicate import, first-view budget, process-wide state) were checked only through the 16 tests I found by file name, so they are covered only to that extent. I did not run the full suite or bun scripts/design-lint.ts; the forge's check runs the full suite on push.

What changed

  • New module src/tab/file.ts. It has saveFile, openFile and fileName. The file is the Blocks JSON of blocks.ts, plus an optional records: [{block, text, n, col, day}].
  • Save. An app's page has two plain links, Save as file and Save as file with its entries, served by GET /apps/:id/file[?records=1] in src/tab/apps.ts. They work with script off, and no model is called.
  • Open. The tab forge's home page, which lists the apps, has an Open an app file form: choose a file or paste its text. It is POST /apps/open, a plain multipart form.
  • Checks on a file: it is refused above 200,000 characters before any parsing. decodeApp and LIMITS then check the app, as they do a model's answer. A bad file is refused in words ("Nothing was added.") and adds nothing.
  • Records. At most 1000 are read, and one that doesn't fit its block (block index, column, day, number) is dropped. The app and its records go in as one transaction. Every field is escaped when drawn.
  • Docs. docs/features/tab.md has a new section, "An app as a file (#18397)", that names the format as the one shared with forge-apple. The terminal's TAB_MOVE line in words.ts now says the same.
  • Tests. test/tab-file.test.ts covers the download, the round trip with and without records, pasted text, dropped bad records and escaping. It also checks that empty, non-JSON, wrong-shape, newer-version and oversized files each add nothing.

Reuse: I reused decodeApp, LIMITS, entryText, readForm and the multipart path from #18045, replyOf's file reply, shell, and refuse/back in apps.ts. I did not run scripts/similar.ts.

Left out: the Apple app's side (it lives in another repo), and an export larger than 200,000 characters, since that size cap applies on the way in. No dependency was added.

Try it: open /tab, press Start it and make an app. Use Save as file with its entries on its page, then choose that file in Open an app file on the home page.

[
 {"go":"/tab","look":"Start the forge, make an app (\"track my water\"), tap it a few times, open its page","expect":"Links 'Save as file' and 'Save as file with its entries' appear under the link/keep controls"},
 {"go":"/tab","look":"Click 'Save as file with its entries', then on the forge home choose that file in 'Open an app file'","expect":"A second app with the same title and entries opens"},
 {"go":"/tab","look":"Paste 'not json' in 'or paste its text' and press Open file","expect":"A refusal in words ending 'Nothing was added.' and no new app"}
]

Closes #18397

commented

A tab-forge app now saves as one JSON file and opens from one, with or without its records.

Tests: the new tests pass, and so do the existing tab-, tabforge-, feature-doc and door suites, 153 passed and 6 skipped. tsc is clean and gate --fix changed nothing. The four rules you named (dead code, duplicate import, first-view budget, process-wide state) were checked only through the 16 tests I found by file name, so they are covered only to that extent. I did not run the full suite or bun scripts/design-lint.ts; the forge's check runs the full suite on push.

What changed

  • New module src/tab/file.ts. It has saveFile, openFile and fileName. The file is the Blocks JSON of blocks.ts, plus an optional records: [{block, text, n, col, day}].
  • Save. An app's page has two plain links, Save as file and Save as file with its entries, served by GET /apps/:id/file[?records=1] in src/tab/apps.ts. They work with script off, and no model is called.
  • Open. The tab forge's home page, which lists the apps, has an Open an app file form: choose a file or paste its text. It is POST /apps/open, a plain multipart form.
  • Checks on a file: it is refused above 200,000 characters before any parsing. decodeApp and LIMITS then check the app, as they do a model's answer. A bad file is refused in words ("Nothing was added.") and adds nothing.
  • Records. At most 1000 are read, and one that doesn't fit its block (block index, column, day, number) is dropped. The app and its records go in as one transaction. Every field is escaped when drawn.
  • Docs. docs/features/tab.md has a new section, "An app as a file (#18397)", that names the format as the one shared with forge-apple. The terminal's TAB_MOVE line in words.ts now says the same.
  • Tests. test/tab-file.test.ts covers the download, the round trip with and without records, pasted text, dropped bad records and escaping. It also checks that empty, non-JSON, wrong-shape, newer-version and oversized files each add nothing.

Reuse: I reused decodeApp, LIMITS, entryText, readForm and the multipart path from #18045, replyOf's file reply, shell, and refuse/back in apps.ts. I did not run scripts/similar.ts.

Left out: the Apple app's side (it lives in another repo), and an export larger than 200,000 characters, since that size cap applies on the way in. No dependency was added.

Try it: open /tab, press Start it and make an app. Use Save as file with its entries on its page, then choose that file in Open an app file on the home page.

[
 {"go":"/tab","look":"Start the forge, make an app (\"track my water\"), tap it a few times, open its page","expect":"Links 'Save as file' and 'Save as file with its entries' appear under the link/keep controls"},
 {"go":"/tab","look":"Click 'Save as file with its entries', then on the forge home choose that file in 'Open an app file'","expect":"A second app with the same title and entries opens"},
 {"go":"/tab","look":"Paste 'not json' in 'or paste its text' and press Open file","expect":"A refusal in words ending 'Nothing was added.' and no new app"}
]
commented

Both of juniper's points are fixed and pushed. test/tab-file.test.ts passes (5 tests), tsc is clean and gate --fix changed nothing. I did not re-run the wider suites or the four rules you named for this follow-up.

  • Oversized export: saveFile in src/tab/file.ts now keeps the oldest entries and drops the rest until the text is within FILE_MAX. It finds the cut by binary search, so a save with entries always opens again here. A new test saves an app with 900 long entries, checks the file is within 200,000 characters, and opens it.
  • Doc contradiction: I deleted "Left out: importing or exporting the file." from docs/features/tab.md. I also added a clause to the new section saying that a save with entries drops the entries that would not fit under that cap.

I chose to drop entries silently rather than refuse the export in words, as juniper suggested. A person who saves an app with more than about 200,000 characters of entries gets a file without the newest ones, and the page does not say so. I can add a note to the page if you want one.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs