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

Build deal-clock #2

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

The deal clock is built and pushed to mason/1-build-deal-clock. bun test passes 64 of 64, the type check is clean, and / renders in about 10 ms (7 KB gzipped). I couldn't look at it in a browser: Chromium won't start in this sandbox, so the layout was only checked by reading the HTML and CSS.

Notes

shipped production is serving it deploy d2eada7

opened this

The deal clock is built and pushed to mason/1-build-deal-clock. bun test passes 64 of 64, the type check is clean, and / renders in about 10 ms (7 KB gzipped). I couldn't look at it in a browser: Chromium won't start in this sandbox, so the layout was only checked by reading the HTML and CSS. The preview is the first real look at it, especially on a phone.

Policy change — needs a person's sign-off. contract.json adds a new deal resource: create user · read anon · update user · delete author · list anon. The note and audit rules are unchanged, but this lets people do things they couldn't before. Read and list are open to anyone so the sample deals show in the meeting. That also shows client names to anyone, so read and list should go back to user before real data goes in. Update is user so whoever is signed in can work the sample deals, whose author is "sample".

What changed

  • The clock (/): one lane per deal, time left to right, a Today line, and markers coloured by urgency (overdue red, due within three days amber, done grey). Tapping a marker opens a sheet with who owes what, any earlier moves, the reminder drafts with a one-tap Send, Mark done, and Move this date, which asks for a reason and keeps it. The sheets use the browser's built-in popover, so they need no script. Under the clock, "Reminders for today" lists what goes out this morning.
  • Other pages: /deals/:id lists a deal's dates and parties and lets you add either. /deals/new works out the standard dates: inspection 10 days, appraisal 21, financing 30, title 14 (I added this one) and walkthrough the day before closing. All are editable, and business days are off by default.
  • Reminders and calendar: POST /tick returns today's unsent reminders and changes nothing. GET /deals/:id/ics downloads every date with alarms three days before and at 9 a.m. on the day.
  • Sample data: a new database gets four deals dated relative to today: one overdue, one closing this week, one with a moved appraisal, and one just signed.
  • New modules:

- src/dates.ts and src/deadlines.ts: date math and the standard contract dates. - src/reminders.ts and src/ics.ts: reminder drafts and the calendar file. - src/deals.ts: every deal action, checked through permit and recorded in the audit log. - src/sample.ts: the four sample deals. - src/pages/: replaces src/page.ts. - src/result.ts: the shared result helpers, moved out of actions.ts.

  • Notes: the notes API and MCP tools stay, but they're no longer on the page. The terminal now lists every open date, soonest first, and x marks one done. There are new MCP tools for deals. HTML is gzipped when the browser asks for it.
  • Header and docs: the header shows the agent and brokerage from DEAL_CLOCK_AGENT and DEAL_CLOCK_BROKERAGE. The README now opens with a section for the realtor, and AGENTS.md covers the new modules.

Tests

  • New tests cover the date math (contingency lengths, business days, moving one date leaves the others alone), the deal actions, reminders, the .ics file, and the deal routes.
  • I changed existing tests where the page changed underneath them. The two page tests in server.test.ts now check the clock and the new-deal form instead of the notes form. The body-size and cross-site tests now post to /deals.
  • The event-stream test now waits for its own note.added event, because earlier deal.changed events replay first. The MCP tool-list test now expects the deal tools too.
  • design.test.ts checks contrast for the new urgency colours.

Not done

  • No real email or SMS, e-signature, document storage, or reading dates from a contract PDF. The README says so.
  • Holidays aren't skipped when counting business days.
  • A calendar-day deadline that lands on a weekend isn't moved to Monday.

How to try it: open the preview. As a guest the clock is read-only. Sign in, tap an amber marker, open "Read the draft", tap Send, then Move this date with a reason. The marker moves and nothing else does. Then try curl -X POST <preview>/tick and Add to calendar on a deal's page.

🤖 Generated with Claude Code

Closes #1

5 earlier comments · 4 events
Changes requested — before the latest push

The clock itself is solid. I checked out the head at 8ea2b09 and ran it: bun test passes 64/64. Escaping holds on every page and sheet, forms and the JSON API both go through the actions, cross-site POSTs get a 403, anon writes get a 401 or a sign-in notice, /tick and the .ics work, and the date math is well tested. My sandbox could not reach the preview host or the screenshots, so I judged a local boot of this head.

What blocks it: the terminal is not a second door. src/tty.ts only lists open dates and has one write, x (mark done). Everything else a signed-in person can do on the page is missing there: move a date with a reason, reopen, send a reminder, read a draft, open a deal, add a date or a party, and remove a deal. The README also describes the terminal as x only. The bar here is that what a person can do on the page, they can do in the terminal too.

Fix first: give tty.ts at least the daily work of the page, over the same actions. That means m to move the date under the cursor (prompt for the new date and a reason, then call moveDeadline), u to reopen (markDone with done:false), and a reminders view with today's dueOn drafts, where s sends one (sendReminder). Add a test that drives each key against a temp database, and update the README's terminal paragraph. Writes from the terminal should also reach web viewers live. live.ts is per-process, so for example the server could notice a change in PRAGMA data_version and emit deal.changed. As it stands, an x in the terminal only shows on the page after a reload.

Also fix:

  • Private contacts are open to guests (medium). deal read/list is anon, so GET /api/deals, POST /tick, /deals/:id/ics, the sheets and the MCP list_deals give any stranger every party's email and phone (contact), and the reminder bodies too. The sample deals make this harmless today, and the pull says so. But it is the first thing real data would leak. Either strip contact (and the draft contact) from what a reader who may not update the deal sees, or make read/list user now. This is a new resource, so neither choice loosens an existing cell.
  • Role compared by hand (low). deals.ts:280 checks who.role === "anon" || before permit. Ask permit alone. refuse already words the sign-in case.
  • Leftover doc comment (low). src/pages/sheet.ts:48 is an orphaned /** One reminder… */ that sits on top of draftText's own doc comment. Remove it.

Contract note for whoever lands this: the new deal row (create user, read/list anon, update user, delete author) adds a resource. It loosens no existing cell, and src/contract.test.ts has its doors.

commented

Mason: please address sentinel's review on this pull, point by point, and push; keep the sample data and the README a realtor can read.

commented

This addresses @sentinel's review on top of 8ea2b09; the sample data and the realtor's README are kept. bun test passes (72 tests) and the type check is clean.

Blocking: the terminal is a second door now. The keys and screen moved into src/terminal.ts, which calls the same actions as the page; src/tty.ts only connects it to the ssh session.

  • On a date (the full list or a deal's own list):

- x marks it done and u reopens it. - m moves it: it asks for the new date, then the reason. - o opens its deal.

  • In a deal: a adds a date, p adds a party, and D removes the deal after you type yes.
  • Reminders: h shows done dates. r lists today's reminders, using the same rule as the page's "Reminders for today". Enter reads a draft and s sends it.
  • Guests are asked to sign in before any prompt opens.
  • Keys that arrive together in one burst (a paste, or the test's piped input) are taken one at a time.
  • Tests: src/terminal.test.ts presses each key against a temp database and checks the database afterwards.
  • Live updates: follow in src/live.ts lets the server check SQLite's PRAGMA data_version every second. When another process commits, it sends deal.changed, so a change made in the terminal shows on open pages within about a second. src/live.test.ts writes through a second connection and checks the event arrives.
  • Docs: the README's terminal paragraph lists every key, and AGENTS.md now says a terminal command belongs in terminal.ts, with a test.

Private contacts (medium). I chose to hide them, not to raise read/list to user. getDeal and listDeals blank each party's email and phone unless permit says the reader may update the deal. Every route reads through those two, so guests get names and dates but no contacts from /api/deals, /tick, MCP, the pages and the reminder drafts. The .ics file never carried contacts. I kept read/list at anon so a guest in Tuesday's meeting still sees a full clock, and the contract.json row is unchanged. Party names (buyer, seller and so on) stay public; raise read/list to user before real client names go in. A new test in src/deals.test.ts checks the hiding.

Role compared by hand (low). createDeal now asks only permit. The author's id and name come from a small authorOf(who) helper, which only fills in the row and decides nothing.

Leftover doc comment (low). I removed it from src/pages/sheet.ts.

To try it: in the preview's terminal (the command printed in the page footer), press m on a date, type a new date and a reason, and watch the open clock page move the marker without a reload.

🤖 Generated with Claude Code

Changes requested — before the latest push

This is close and well made. Identity comes only from the signed headers. Every write at every door (page, API, MCP, terminal) goes through permit in deals.ts. Output is escaped everywhere I looked (I created a deal whose address was <script> and it rendered inert). Guests and other agents see names but not party contacts, on the page, in the API, in /tick and in the terminal. A delete by someone other than the deal's author is refused. A cross-site POST gets a 403, and a 3 MB chunked body gets a 413 from the bytes actually read. Terminal writes reach pages through follow, and the tests cover that. I ran the head (52f0b54) locally with a signed identity and bun test passed, 72 of 72. The new deal row in contract.json is a new resource, not a loosened cell. My sandbox could not reach the preview or the screenshots, so I can't vouch for the look; I judged the head running locally.

What to fix first (medium): every new form route answers 500 to a POST without a form content-type. curl -X POST -H 'origin: <app>' <app>/deadlines/1/done with no body returns 500, and so do /deals, /reminders, /deals/:id/deadlines, /deals/:id/parties and /deadlines/:id/move. The server log shows TypeError: Can't decode form data ... ERR_FORMDATA_PARSE_ERROR thrown from form() at src/routes.ts:253. That input isn't validated at the boundary: a malformed request from a client should get a 4xx with the security floor, not an exception. The fix: in form(), catch the parse failure (or check that the content-type is application/x-www-form-urlencoded or multipart/form-data first) and return text("expected a form", 415). Add a test in src/server.test.ts that POSTs to /deadlines/1/done with no content-type and expects a 4xx. That test fails today.

Nit (low, optional): line() strips C0 controls, but C1 controls (U+0080–U+009F, including CSI U+009B) still reach the terminal raw. Widening the class to [\u0000-\u001f\u007f-\u009f] closes that.

commented

Mason: round two from sentinel is on the pull; fix what it names (the high one first), push, and say in one line what changed.

commented

In one line: the form routes now refuse a body that isn't a form with 415 or 400 instead of crashing with a 500, and form fields drop C1 control characters as well. Pushed as 1ae5fe0; bun test passes 74/74 and the type check is clean.

Medium: form routes answered 500. Before reading a byte, form() in src/routes.ts now checks the content-type. If it isn't application/x-www-form-urlencoded or multipart/form-data, the route answers 415 "expected a form". readForm in src/http.ts no longer throws on a body it can't decode; it returns null, and the route answers 400. Both answers carry the security headers.

A new test in src/server.test.ts covers this:

  • a POST to /deadlines/1/done with no content-type gets 415, with the security headers;
  • a JSON body gets 415, and garbled multipart gets 400;
  • a POST with no content-type to /deals, /reminders, /deals/1/deadlines, /deals/1/parties and /deadlines/1/move gets 415.

I didn't run the new test against the old code; your 500s were reproduced the same way, so it should fail there.

Low: C1 controls. line() in src/deals.ts now strips U+0080–U+009F (including CSI U+009B) as well as C0 and DEL. A new test in src/deals.test.ts checks that an address carrying C1 and C0 characters is stored clean.

🤖 Generated with Claude Code

Changes requested — before the latest push

Solid work. Every deal action asks permit and none compares roles by hand. SQL is parameterized throughout. Text from people is stripped of control characters at the boundary, so nothing reaches the terminal or the .ics file as an escape. Contacts are blanked for anyone who may not work the deal, including in /tick and MCP. Form bodies are capped by bytes read: a 200 KB body gets a 413. A stranger's write is refused (401 on DELETE /api/deals/1; the form posts go back with a sign-in notice). CSP, nosniff and Referrer-Policy are on every response. follow on data_version carries terminal writes to the pages live. bun test passes 74/74 at this head, and booted locally / answers 200 with the four sample deals, /tick and /deals/1/ics work. (The preview host and the screenshots were not reachable from my sandbox, so I judged a local boot of 1ae5fe0.)

One thing blocks, and it comes first: the terminal cannot open a deal. The page's main write is New deal (/deals/new → createDeal). src/terminal.ts has no key for it: the deal view handles a/p/D, the date list handles x/u/m/o, and nothing calls createDeal (or updateDeal, the address correction the API offers). The brief makes both doors equal, so a person at the terminal has to be able to do what the page does.

Fix: add an n key in press (from the dates view). It should use the existing ask flow with the prompts address, buyer, seller, contract date (YYYY-MM-DD) and closing date (YYYY-MM-DD), keeping the default lengths. It should call createDeal(db, me, {...}), report the result on the status line, and open the new deal's view. ask currently gates on canChange(me, deal), which needs an existing deal. For the create path, gate on the action's own refusal: call it and report result.message. Do not add a role check by hand. Add a test in src/terminal.test.ts that presses n, types the five answers, and checks the deal is in listDeals. Add a second test that a guest pressing n is told to sign in. Then add n to the key list in the README and the terminal's hint line.

Not blocking, for the person signing off on the contract. deal is a new resource, not a loosened cell, but update: user lets any signed-in forge account move, complete, or add parties to any agent's deal, and see the contacts on it. The pull says it chose that so the sample deals can be worked. That is fine for the sales-meeting prototype; before real clients go in, update should become author.

Approved — before the latest push

Approved. I read the whole change against issue #1 and the security floor.

  • Identity and authorization. Every deal action (src/deals.ts) asks permit on deal, and none compares roles by hand. Dates, parties and reminders are updates of the deal and are audited against its id. dealFor asks the table before it reveals whether a row exists. contract.test.ts has a door for every verb on the new deal row. contract.json only gains a new resource; no existing cell is loosened.
  • Validation and escaping. Inputs go through line() (control characters stripped, length-bounded), isDate and isPartyRole. All SQL uses bound parameters. The only interpolated SQL is the may.where column list, and those names come from the contract. Every value in the pages goes through escape. ICS text is escaped and folded. Redirect targets go through backTo.
  • Privacy. Guests get party contacts blanked everywhere: the API, /tick, drafts and the terminal. Tested in deals.test.ts.
  • Body cap and doors. Forms must declare a form content type (otherwise 415) and are read through the byte-capped readBody. I sent 3 MB and got 413. The terminal goes through the same actions and gates writes with canChange plus the action's own check. Its writes reach the page through follow(data_version), tested in live.test.ts.
  • What I ran. bun test on the head: 74 pass, 0 fail. I booted the head locally. / answers 200 in about 10–35 ms with CSP, nosniff and Referrer-Policy set. /tick, the .ics file and /deals/new all work. As a guest, POST /api/deals gives 401 and a cross-site POST gives 403.
  • Not checked. My sandbox blocks the preview host and the screenshot directory, so I did not see the preview itself; the review rests on the local boot of this exact commit.

Two low-severity notes are inline. Neither blocks the merge.

commented

Mason: one change before this lands, from the owner. A deal is not readable by anonymous visitors: deal.read and deal.list are for signed-in users only (contract.json back to the default), and a guest at /deals or a deal page gets the sign-in notice, as the other pages do. A party's own link to its deal comes later as its own issue. Keep everything else as sentinel approved it; push, and say in one line what changed.

commented

In one line: deals are now for signed-in users only, the terminal can open a new deal with n, and the sample deals are seeded once even if two processes open a new database together. Pushed as eddfc6a; bun test passes 76/76, and the type check and design lint are clean.

Owner's change: deals are private. In contract.json, deal.read and deal.list are back to user; the other deal rules are unchanged.

  • A guest at / or at a deal's page now gets a sign-in notice that sends them back to the same page afterwards, and sees nothing of any deal. This lives in the new src/pages/refused.ts.
  • /api/deals, the .ics file and POST /tick now answer 401 to a guest, and the MCP list_deals tool refuses one.
  • /tick needs an account now. A morning job calling /tick must call it as a signed-in account. The README says so.

Blocking: the terminal can open a deal. From the date list, n asks for the address, buyer, seller, contract date and closing date, keeps the standard lengths, calls createDeal, and opens the new deal's view.

  • Before any prompt, the terminal asks a new mayOpen(who) in src/deals.ts. It is permit worded exactly as createDeal would refuse, so a guest is told "Sign in to open a deal." without typing five answers. createDeal uses the same check, and no role is compared by hand.
  • A bad answer (say, a two-letter address) is refused by createDeal itself, and its message shows on the status line.
  • Tests in src/terminal.test.ts: n with five answers puts the deal in listDeals, a bad answer is reported, and a guest pressing n is told to sign in. n is in the README and the terminal's hint line.

Low: seeding race. The check for "already seeded" and the inserts in src/sample.ts now run in one .immediate() write transaction. A new test in src/db.test.ts opens the same new file three times and finds four sample deals.

Tests I changed, and why:

  • Tests that read deals as a guest now read as a signed-in user and also check that the guest is refused.
  • The contacts test became "a guest sees no deal and no contacts; a signed-in user sees both".
  • The form-415 test uses its own identity, because the extra signed-in posts had pushed alice past the write rate limit and it got 429.

Where I didn't do exactly what was asked:

  • Updating a deal's address in the terminal. I didn't add a key for updateDeal. The page has no form for it either; it is only on the API. Sentinel's blocking item was n.
  • Contact hiding. I kept the code that blanks contacts for readers who may not update a deal, as sentinel approved it. With read and update both user, it currently hides nothing; it starts working if update narrows to author. A comment in src/deals.ts says so, and nothing currently tests it.

🤖 Generated with Claude Code

Approved

Approved. I read every changed line at eddfc6a and booted the head locally. I could not reach the preview from my sandbox: the host was blocked and the screenshots were unreadable. So the look is not judged here; the behaviour is.

Holds:

  • Identity comes only from the signed forge headers (who.ts, unchanged).
  • Every deal action asks permit, and none compares roles by hand. Dates, parties and reminders are audited as update of their deal.
  • A guest gets 401 at every door: /api/deals, /deals/:id, /deals/:id/ics, POST /tick and MCP list_deals. On /, a guest sees the sign-in notice and no deal data.
  • A cross-origin form post gets 403. A 2 MB form body gets 413, capped by the bytes actually read.
  • <script> in an address is escaped on the page.
  • Control characters are stripped at the boundary (line), so nothing reaches the terminal or the .ics file raw. ICS text is escaped and folded.
  • All SQL is parameterised; the one built WHERE uses column names from the table, not user text.
  • CSP, nosniff and Referrer-Policy are on every response. / renders in about 15 ms.
  • The terminal covers every page action. A guest there sees nothing, and its writes reach pages through follow(data_version), which live.test.ts covers.
  • bun test passes 76 of 76. The deal row is in contract.test.ts, and no existing cell is loosened.

Low, not blocking:

  1. /events is public and carries {id} of every deal that changes. A guest can learn that deal ids exist and when they change, but nothing more. Consider dropping the id, or gating the stream on deal list.
  2. The pull's description is stale. It says deal read/list are anon, but contract.json at this head has them as user. The code is right; the description should say what landed.
  3. deal.update is user, so any signed-in account can work any deal. This is fine for one agent's app and the sample deals, but see the line note.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs