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

Keep a private note on a lead (budget, timing, what they want) that shows at the top of their page and never goes to the lead #49

Merged opened this

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

Merged

A lead now has a private "Your note" card at the top of its page. The full bun test run passes (232 tests, including the new src/notes.test.ts) and bun scripts/lint-design.ts is clean.

Notes

shipped production is serving it deploy aba151a

opened this

A lead now has a private "Your note" card at the top of its page. The full bun test run passes (232 tests, including the new src/notes.test.ts) and bun scripts/lint-design.ts is clean. bun x tsc --noEmit could not run: the repo has no tsconfig or typescript dependency, so it printed tsc's help instead of checking types. I did not start the app and try it by hand.

What changed

  • Storage: note and note_updated_at are two appended migrations in src/db.ts, so existing leads keep their data. The lead's JSON returns them as note and noteUpdatedAt.
  • Action: setNote in src/actions.ts trims the note and refuses text over 2,000 characters, control characters and non-text with a 422, changing nothing. An empty note clears it. It asks permit for lead update, works in any state, and writes one audit row with the old and new note only when the note actually changed. Anonymous callers get the usual 401.
  • Page: the "Your note" card shows the note, escaped, with its last-edited time. The edit form appears only when permit allows it. With no note and no permission the card is omitted.
  • Desk:
    • Row: the note's first line, cut to 80 characters and escaped, shows under the lead's name.
    • Search: q also matches note text. I changed the search placeholder, aria-label and terminal hint to say so.
    • Style: a small .note-line rule in static/app.css.
  • Other doors:
    • PATCH /leads/:id with {"note": …} and POST /leads/:id/note (form or JSON).
    • A set_note MCP tool.
    • n on the terminal's lead screen, with ctrl-d to save.
    • The same-origin door refuses cross-origin POSTs, and contract/openapi.json is re-emitted.
  • Activity: the Activity page reads "changed the private note on …", with the old and new text.
  • Sample data: Aisha Bello and Marcus Lee each get a realistic note.
  • README: "How it works" gains a paragraph on notes, saying they are private to the agent.

Not sent to the lead: nothing in the draft code reads the note. A test shows a lead with a note gets drafts identical to one without, and that the note's text does not appear in any message after a details edit and a send.

Choices and caveats

  • No contract change: no cell in contract.json changed; lead update is already user.
  • 403 case: anon is the only identity below user, so "no update permission" gets 401 (sign-in required) rather than 403. I tested the no-form page by rendering it with mayUpdate false.
  • PATCH: it now takes one change at a time (state, details or note) and returns 422 if you send more than one.
  • Desk file: in src/pages/desk.ts I touched only the lead row and the search form's text, so it should not collide with #36's CSV link.
  • Migration test: I extended the existing migration-twice test in src/db.test.ts, because the two new ADD COLUMN migrations cannot be run twice.
  • Left out: the note is not in the CSV export, since the issue did not ask for it and the export may be forwarded.

To try it, open any lead's page, save a note, then check the desk row, search for a word from the note, and read the Activity page as an admin.

🤖 Generated with Claude Code

Closes #39

3 earlier comments · 1 event
commented

A lead now has a private "Your note" card at the top of its page. The full bun test run passes (232 tests, including the new src/notes.test.ts) and bun scripts/lint-design.ts is clean. bun x tsc --noEmit could not run: the repo has no tsconfig or typescript dependency, so it printed tsc's help instead of checking types. I did not start the app and try it by hand.

What changed

  • Storage: note and note_updated_at are two appended migrations in src/db.ts, so existing leads keep their data. The lead's JSON returns them as note and noteUpdatedAt.
  • Action: setNote in src/actions.ts trims the note and refuses text over 2,000 characters, control characters and non-text with a 422, changing nothing. An empty note clears it. It asks permit for lead update, works in any state, and writes one audit row with the old and new note only when the note actually changed. Anonymous callers get the usual 401.
  • Page: the "Your note" card shows the note, escaped, with its last-edited time. The edit form appears only when permit allows it. With no note and no permission the card is omitted.
  • Desk:
    • Row: the note's first line, cut to 80 characters and escaped, shows under the lead's name.
    • Search: q also matches note text. I changed the search placeholder, aria-label and terminal hint to say so.
    • Style: a small .note-line rule in static/app.css.
  • Other doors:
    • PATCH /leads/:id with {"note": …} and POST /leads/:id/note (form or JSON).
    • A set_note MCP tool.
    • n on the terminal's lead screen, with ctrl-d to save.
    • The same-origin door refuses cross-origin POSTs, and contract/openapi.json is re-emitted.
  • Activity: the Activity page reads "changed the private note on …", with the old and new text.
  • Sample data: Aisha Bello and Marcus Lee each get a realistic note.
  • README: "How it works" gains a paragraph on notes, saying they are private to the agent.

Not sent to the lead: nothing in the draft code reads the note. A test shows a lead with a note gets drafts identical to one without, and that the note's text does not appear in any message after a details edit and a send.

Choices and caveats

  • No contract change: no cell in contract.json changed; lead update is already user.
  • 403 case: anon is the only identity below user, so "no update permission" gets 401 (sign-in required) rather than 403. I tested the no-form page by rendering it with mayUpdate false.
  • PATCH: it now takes one change at a time (state, details or note) and returns 422 if you send more than one.
  • Desk file: in src/pages/desk.ts I touched only the lead row and the search form's text, so it should not collide with #36's CSV link.
  • Migration test: I extended the existing migration-twice test in src/db.test.ts, because the two new ADD COLUMN migrations cannot be run twice.
  • Left out: the note is not in the CSV export, since the issue did not ask for it and the export may be forwarded.

To try it, open any lead's page, save a note, then check the desk row, search for a word from the note, and read the Activity page as an admin.

🤖 Generated with Claude Code

Changes requested — before the latest push

Mostly good, but two things need fixing in one round.

  1. (fix first) The new door has no row in src/contract.test.ts. Notes are a new write, through setNote, POST /leads/:id/note, PATCH {note} and MCP set_note. The table test checks every lead-update door per role (it does so for editLead), and this one is missing. Add a setNote check beside editLead, for each identity and each lead state, expecting the same outcome as the table's lead update cell.
  2. src/pages/desk.ts imports ResponseRecord and View as values. Make them type imports, as they were.

Smaller points: the note renders in a <p class="body">, so line breaks collapse on the page (add white-space: pre-wrap to the class). Also, tsc could not run, so types are unchecked.

No contract.json cell is loosened. Not verified: I did not exercise the preview.

commented

I pushed all three fixes to the same branch. The full bun test passes (232 tests) and bun scripts/lint-design.ts is clean. I did not exercise the preview.

  • Contract door: src/contract.test.ts now checks the note door beside editLead, for every identity. It calls setNote and the MCP set_note tool on an open lead, then forces the lead to lost and calls setNote again. Each outcome must equal the table's lead-update result. The HTTP routes (POST /leads/:id/note, PATCH {note}) are not in the table test; they call the same action.
  • Imports: in src/pages/desk.ts, ResponseRecord and View are type imports again.
  • Line breaks: I disagree that they collapse. .body is already white-space: pre-line, which keeps newlines, so <p class="body"> shows them as written. I added .note .body { white-space: pre-wrap; } anyway so the note also keeps indentation and repeated spaces. It is scoped to the note card, so other uses of .body are unchanged.
  • Types: tsc still cannot run because the repo has no tsconfig or typescript dependency. Types are unchecked beyond what bun test loads.

No contract.json cell changed.

🤖 Generated with Claude Code

commented

I merged main into the branch, resolved the six conflicts and pushed. The full bun test run passes (262 tests) and bun scripts/lint-design.ts is clean. bun x tsc --noEmit still can't run because the repo has no tsconfig.

All six conflicts kept both sides:

  • src/audit.ts: the act list now holds openers from main and my noted, each in the act list and in the doc comment.
  • src/db.ts and src/db.test.ts: both migrations are kept, main's profile.openers first and my two lead note columns after it. The run-twice test drops both sets of columns.
  • src/pages/desk.ts and src/routes.ts: I combined the imports. main's intake import and NewLead type stay alongside my noteLine, MAX_LEAD_NOTE and type imports.
  • src/terminal.ts: main's v (paste a lead email) key and paste view stay. The desk hint now reads "find by name, email, phone or note". My n note key is on the lead screen, so it doesn't clash with n (log a lead) on the desk.

🤖 Generated with Claude Code

commented

The preview failed because merging main changed the order of the migrations after the preview's database had already run mine. I've fixed it and pushed. Full bun test passes (263 tests). I haven't seen the preview redeploy yet.

  • Cause: the preview database had run my two note-column migrations at positions where main's profile.openers migration now sits. After the merge, its recorded version made the app re-run ADD COLUMN note_updated_at and crash with "duplicate column name". The same shift meant openers would have been skipped on that database.
  • Fix in src/db.ts: migrate now skips an ALTER TABLE … ADD COLUMN when the table already has that column. I also appended a final ADD COLUMN openers migration, which does nothing wherever openers exists and adds it to the preview's database.
  • Production: it is unaffected. It has only run main's migrations, so it picks up the note columns normally and skips the extra openers step.
  • Test: src/db.test.ts covers both cases — a database missing openers with its version past the notes, and a column that is already there.

🤖 Generated with Claude Code

Approved

Approved. Since my last review the only new work is the migration fix: migrate skips an ADD COLUMN whose column already exists, a trailing openers migration repairs the preview database, and src/db.test.ts covers both cases. The regex reads only static migration SQL, so no user text reaches it. The earlier asks (contract-door row for the note, type imports, line breaks) are met. The preview answers 200 for /. I could not diff against 7a8e5e04e887 because the clone lacks that commit, so I read the change as given.

Non-blocking: bun x tsc --noEmit cannot run because the repo has no tsconfig.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs