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

The agent rewrites how their first reply opens for each lead source, and sees a new draft in their words before saving #45

Merged opened this

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

Merged

The profile page now has a "How your first reply opens" section, so the agent can reword the opening line for each source and preview it before saving. The full bun test run is green (212 tests) and bun run lint:design is clean.

Notes

shipped production is serving it deploy aba151a

opened this

The profile page now has a "How your first reply opens" section, so the agent can reword the opening line for each source and preview it before saving. The full bun test run is green (212 tests) and bun run lint:design is clean. I couldn't run bun x tsc --noEmit: the repo has no tsconfig.json or TypeScript dependency, so it only prints tsc's help. There is no scripts/gate.ts or scripts/fast.ts here.

What changed

  • Page: an admin sees one field per source, prefilled with today's wording, at most 160 characters, trimmed, one line. An empty field means the built-in line, and so does typing the built-in line itself. A user sees the same wording read-only, with no form.
  • Preview: a "Preview" button posts to a new route, POST /profile/preview. It renders the day-0 email and text for a sample lead from each source, and saves nothing. An over-limit value gives a 422 with the reason.
  • Storage: a new migration adds an openers column (JSON) to profile. Existing data is untouched.
  • Drafting: draft() uses the saved opener for new first replies. Drafts already on the desk keep their wording, because saving a profile redrafts unsent messages with the openers as they were before the save.
  • Audit: a save that changes an opener writes one row with the old and new wording, shown on the Activity page as "changed how first replies open: zillow opening “…” → “…”". A save that changes no opener writes a plain profile-update row.
  • JSON and MCP: POST /profile takes an openers object keyed by source, documented in /openapi.json, and set_profile takes the same. A source left out keeps its wording and an empty one resets to the built-in line. An unknown key, a non-string, 161 characters or a line break is a 422. A user gets 403, and a cross-origin POST is refused.
  • Text length: a custom opener that would push a text over MAX_BODY.text (480) falls back to the built-in line for that text. Email keeps the opener. The README says so.
  • Docs and tests: the README's profile section has the new lines and AGENTS.md mentions the openers. The new tests are in src/openers.test.ts.

Existing tests I changed

  • GET /profile and get_profile now return openers, so four exact-shape assertions in profile.test.ts and server.test.ts became toMatchObject or gained the key.
  • db.test.ts and details.test.ts replay old migrations, so they now also drop the new column first, the way they already drop audit.detail.

Not done

  • No contract cell changed; profile update is still admin only.
  • The terminal's profile editor doesn't edit openers; it saves without touching them.
  • A browser form refused for a user redirects back with a notice (303), as other forms here do. The 403 is on the JSON door.

To try it: open /profile as an admin, edit the Zillow line, press Preview, then Save profile. Press "Bring in a new inquiry" and the next Zillow first reply opens with your words.

Closes #43

3 earlier comments · 2 events
commented

The profile page now has a "How your first reply opens" section, so the agent can reword the opening line for each source and preview it before saving. The full bun test run is green (212 tests) and bun run lint:design is clean. I couldn't run bun x tsc --noEmit: the repo has no tsconfig.json or TypeScript dependency, so it only prints tsc's help. There is no scripts/gate.ts or scripts/fast.ts here.

What changed

  • Page: an admin sees one field per source, prefilled with today's wording, at most 160 characters, trimmed, one line. An empty field means the built-in line, and so does typing the built-in line itself. A user sees the same wording read-only, with no form.
  • Preview: a "Preview" button posts to a new route, POST /profile/preview. It renders the day-0 email and text for a sample lead from each source, and saves nothing. An over-limit value gives a 422 with the reason.
  • Storage: a new migration adds an openers column (JSON) to profile. Existing data is untouched.
  • Drafting: draft() uses the saved opener for new first replies. Drafts already on the desk keep their wording, because saving a profile redrafts unsent messages with the openers as they were before the save.
  • Audit: a save that changes an opener writes one row with the old and new wording, shown on the Activity page as "changed how first replies open: zillow opening “…” → “…”". A save that changes no opener writes a plain profile-update row.
  • JSON and MCP: POST /profile takes an openers object keyed by source, documented in /openapi.json, and set_profile takes the same. A source left out keeps its wording and an empty one resets to the built-in line. An unknown key, a non-string, 161 characters or a line break is a 422. A user gets 403, and a cross-origin POST is refused.
  • Text length: a custom opener that would push a text over MAX_BODY.text (480) falls back to the built-in line for that text. Email keeps the opener. The README says so.
  • Docs and tests: the README's profile section has the new lines and AGENTS.md mentions the openers. The new tests are in src/openers.test.ts.

Existing tests I changed

  • GET /profile and get_profile now return openers, so four exact-shape assertions in profile.test.ts and server.test.ts became toMatchObject or gained the key.
  • db.test.ts and details.test.ts replay old migrations, so they now also drop the new column first, the way they already drop audit.detail.

Not done

  • No contract cell changed; profile update is still admin only.
  • The terminal's profile editor doesn't edit openers; it saves without touching them.
  • A browser form refused for a user redirects back with a notice (303), as other forms here do. The 403 is on the JSON door.

To try it: open /profile as an admin, edit the Zillow line, press Preview, then Save profile. Press "Bring in a new inquiry" and the next Zillow first reply opens with your words.

commented

The preview deploy's failing test (/activity: an admin reads a sent reply… in src/audit.test.ts) came from my new tests. It had nothing to do with /activity itself.

My src/openers.test.ts made about ten writes as the same admin id (u0) that src/audit.test.ts uses. The per-person write ration is held at module level and shared by every test file in one bun test process. Root had used up its writes by the time the activity test ran, so its "mark lost" write was refused and the page had no "marked" row.

The fix is in src/openers.test.ts: it now acts as its own admin and user (openers-admin, openers-user), so it no longer spends root's ration. No app code changed.

I could reproduce the failure locally on 4 of 8 full-suite runs. After the fix, 5 full bun test runs gave 0 failures. The new commit is pushed to the same branch, so the forge's check will run again on it.

Changes requested — before the latest push

Solid work on the page, preview, storage, audit, JSON and MCP doors, and no contract cell is loosened. One change is needed.

  1. Fix first: the terminal door lacks this feature. src/terminal.ts has a profile screen and editor (profileScreen, profileEditScreen, PROFILE_FIELDS) that saves the profile without touching openers. The page and the terminal must offer the same abilities, and the pull description admits this is not done. Add the four opener fields to the terminal profile screen, shown read-only for non-admins. Add them to the edit flow for admins (one line, 160 characters, empty means built-in), going through saveProfile so a save reaches web viewers live. Add a terminal test for it. Mention it in the README (the terminal is a door).
  2. Minor: add a note in the README or the pull about the cross-door difference. A user posting the form gets 303 plus a notice, not 403, while the preview gives 403. The issue says 403 and no form. JSON is 403, so this is acceptable if the form path is documented.
  3. Minor: tsc could not be run (the repo has no tsconfig), so confirm the types are clean by other means.
commented

This pull lets an agent reword how the first reply opens for each lead source (Zillow, website, open house, referral). The page shows a new draft in their words before saving. The terminal profile screen now shows and edits the four opener lines too. src/terminal.test.ts passes (20 tests). I did not run the full bun test or the forge's check. The repo has no scripts/gate.ts or scripts/design-lint.ts, so I skipped both.

What changed in this round, in src/terminal.ts

  • Terminal profile screen: it lists the four openers under "How your first reply opens". Non-admins read them but cannot edit.
  • Edit flow (admin): pressing e still walks the five profile fields. It now continues through one line per source, each prefilled with the current wording.
  • Empty or built-in text: an empty line, or the built-in text itself, keeps the built-in wording. Over 160 characters or a line break is refused by the same check the page uses.
  • Saving: the last step goes through saveProfile. That gives the same validation, audit entry and live update to web viewers, and unsent drafts are redrafted.
  • Test: in src/terminal.test.ts, a non-admin sees the openers and an admin sets one in the terminal. It checks the stored value, that a user's screen shows it, and that an over-long line is refused. The two existing profile-edit tests now press enter through the extra four steps.
  • README: it now covers the terminal flow. It also documents the cross-door difference: a browser form from a non-admin gets a 303 and a notice, while JSON and MCP get 403, and nothing is saved either way.

Type check: bun x tsc --noEmit can't run here. The repo has no tsconfig, and the bun and node type packages aren't installed. I ran tsc --strict on src/terminal.ts by hand, ignoring errors from the missing module and global type declarations. It reported no errors in src/terminal.ts.

What I did not do: no contract cell is loosened. The terminal change uses the existing profile update cell.

To try it: run ssh as an admin, press p to read the openers, then e, then enter through the fields. Type a line at an opener step and enter to save.

🤖 Generated with Claude Code

Approved — before the latest push

The clone does not have 5d28aeb9a412, so I read the whole change again. The terminal now shows and edits the openers (the earlier gap), and the README covers it. Saves go through saveProfile and permit, and the preview route refuses a user (403) and a cross-origin POST. No contract cell is loosened. Opener text is escaped on the page, the preview and the Activity page. Existing drafts are redrafted with the old openers, so they are unchanged. Tests cover each behaviour. Non-blocking: profile.ts and actions.ts each define a function called readOpeners, and the shared name will confuse a reader.

commented

I merged main into this branch and pushed it. bun test passes (249 tests). I skipped the type check: the repo has no tsconfig.json, so tsc has nothing to check against. scripts/gate.ts doesn't exist in this clone either.

Both sides touched the profile, so the conflicts were mostly keeping both.

  • Profile: it now carries the time zone and the per-source openers together. currentAgent and storeAgent in src/profile.ts read and write both columns. timeZone stays optional on save, as main made it. openers is optional too.
  • Migrations: the openers column is added after main's profile and message table rebuild. If it came before, the rebuild would have dropped the column. Existing databases that ran only the old migration list are unaffected.
  • Audit: ACTS has main's held and unhold plus this pull's openers.
  • MCP and routes: set_profile and POST /profile accept both timeZone and openers. contract/openapi.json was regenerated with scripts/contract-emit.ts, not hand-merged.
  • Terminal editor: the time zone field now comes before the four opener fields. I updated the key counts in two terminal tests to match. The profile JSON assertions in src/profile.test.ts and src/server.test.ts now include openers and timeZone.

No permission cell changed.

Approved

Approved. Openers are stored with the profile, used only by new first replies (unsent redrafts use the old openers), audited with old/new wording, validated at the boundary (160 chars, no control chars, unknown keys refused), escaped on page and preview, and reachable through page, JSON, MCP and the terminal. Preview and save both ask permit; no contract cell is loosened. Tests cover each behaviour. Non-blocking: a non-admin browser form gets 303 with a notice rather than 403 (JSON and MCP give 403, nothing saved, documented in the README).

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs