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

Let the agent set their name, brokerage and license from the app #8

Merged opened this

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

Merged

There's now a "Your profile" page at /profile, linked from the header, where an admin can set name, brokerage, license, phone and email. Every signed-in person can read it. bun test passes (78 tests) and bun run lint:design is clean.

Notes

shipped production is serving it deploy aba151a

opened this

There's now a "Your profile" page at /profile, linked from the header, where an admin can set name, brokerage, license, phone and email. Every signed-in person can read it. bun test passes (78 tests) and bun run lint:design is clean. bun x tsc --noEmit could not run: the repo has no tsconfig.json or TypeScript dependency, so tsc just printed its help. There's no scripts/gate.ts or scripts/fast.ts, and I didn't try the app in the browser.

What changed

  • Storage: the profile is a new profile table, added as a forward-only migration in src/db.ts. The new src/profile.ts reads it, falling back to the AGENT_* variables until a profile is saved; after that the saved one wins.
  • Policy: contract.json gets a profile resource: read is user, update is admin, create, delete and list are nobody. No existing cell is loosened, but the new resource means a person reviews this pull.
  • No api path in contract.json: the door turns GET <api> into the "list" verb, which is nobody for profile. That would have shut GET /profile to everyone. The actions still ask permit, so the policy holds; the cost is that the door's own pre-check and the forge's probe don't cover this route.
  • Validation: readAgent in src/actions.ts checks every field. All five are required, with length caps, no control characters or line breaks, a phone shape and an email shape. A blank or whitespace-only license is refused.
  • Saving: saveProfile goes through audited, so refusals are logged too. It rewrites the body and signature of every message not yet sent (draft, scheduled, due) and emits lead.changed so open pages refresh. Messages already sent are never touched; they keep the signature stored when they went out.
  • Reach:
    • Pages: layout now takes the current agent, so every page and the header show the saved profile.
    • API: GET and POST /profile answer HTML to a browser and JSON to a script. They are in contract/openapi.json, regenerated with bun run contract:emit.
    • MCP and terminal: MCP has get_profile and set_profile. The terminal's header shows the saved agent.
  • Docs: the README's "Your profile" section tells people to use the page, and AGENTS.md names src/profile.ts.

Tests

  • New src/profile.test.ts covers:
    • the env default before any save;
    • a save changing the next draft and the unsent drafts but not a sent message;
    • a user and a stranger being refused;
    • a blank license and other bad input being refused;
    • audit rows for both the save and the refusal.
  • src/contract.test.ts has the new profile doors, and src/server.test.ts has an end-to-end test of the page, the JSON twin and a cross-site POST.
  • I updated the MCP tool list in server.test.ts, which enumerates the tools and now has two more.

Not done: there is no terminal command to edit the profile, only to see it. Say if you want one.

Try it: sign in as an admin, open "Your profile", save, then open any lead. The unsent draft's signature has changed, and a message already sent still shows the old one.

🤖 Generated with Claude Code

Closes #6

1 earlier comment · 1 event
commented

There's now a "Your profile" page at /profile, linked from the header, where an admin can set name, brokerage, license, phone and email. Every signed-in person can read it. bun test passes (78 tests) and bun run lint:design is clean. bun x tsc --noEmit could not run: the repo has no tsconfig.json or TypeScript dependency, so tsc just printed its help. There's no scripts/gate.ts or scripts/fast.ts, and I didn't try the app in the browser.

What changed

  • Storage: the profile is a new profile table, added as a forward-only migration in src/db.ts. The new src/profile.ts reads it, falling back to the AGENT_* variables until a profile is saved; after that the saved one wins.
  • Policy: contract.json gets a profile resource: read is user, update is admin, create, delete and list are nobody. No existing cell is loosened, but the new resource means a person reviews this pull.
  • No api path in contract.json: the door turns GET <api> into the "list" verb, which is nobody for profile. That would have shut GET /profile to everyone. The actions still ask permit, so the policy holds; the cost is that the door's own pre-check and the forge's probe don't cover this route.
  • Validation: readAgent in src/actions.ts checks every field. All five are required, with length caps, no control characters or line breaks, a phone shape and an email shape. A blank or whitespace-only license is refused.
  • Saving: saveProfile goes through audited, so refusals are logged too. It rewrites the body and signature of every message not yet sent (draft, scheduled, due) and emits lead.changed so open pages refresh. Messages already sent are never touched; they keep the signature stored when they went out.
  • Reach:
    • Pages: layout now takes the current agent, so every page and the header show the saved profile.
    • API: GET and POST /profile answer HTML to a browser and JSON to a script. They are in contract/openapi.json, regenerated with bun run contract:emit.
    • MCP and terminal: MCP has get_profile and set_profile. The terminal's header shows the saved agent.
  • Docs: the README's "Your profile" section tells people to use the page, and AGENTS.md names src/profile.ts.

Tests

  • New src/profile.test.ts covers:
    • the env default before any save;
    • a save changing the next draft and the unsent drafts but not a sent message;
    • a user and a stranger being refused;
    • a blank license and other bad input being refused;
    • audit rows for both the save and the refusal.
  • src/contract.test.ts has the new profile doors, and src/server.test.ts has an end-to-end test of the page, the JSON twin and a cross-site POST.
  • I updated the MCP tool list in server.test.ts, which enumerates the tools and now has two more.

Not done: there is no terminal command to edit the profile, only to see it. Say if you want one.

Try it: sign in as an admin, open "Your profile", save, then open any lead. The unsent draft's signature has changed, and a message already sent still shows the old one.

🤖 Generated with Claude Code

Changes requested — before the latest push

The web side is solid: permit is asked in the actions, the save is audited, input is validated, unsent drafts are redrafted and sent ones are left alone. Three things need fixing in one round.

  1. Both doors (fix first). An admin can edit the profile on the page, MCP and JSON, but not in the terminal (src/tty.ts / src/terminal.ts). The terminal only shows the header. Add a profile view and an edit for admins that goes through saveProfile, so the audit and live emit apply. Gate it as the page does: a guest sees nothing private, a user reads, an admin edits. Document it in the README. "Say if you want one" is not a reason to leave it out.
  2. Tests for the new doors. server.test.ts only checks that get_profile and set_profile appear in the tool list. Add tests that call them: a user calling set_profile is refused, an anon calling get_profile is refused, and an admin set_profile changes what get_profile returns. The terminal edit from item 1 needs a test too.
  3. contract.json. The profile resource has no api path, so the door pre-check and the forge probe do not cover GET/POST /profile. That is a hole in the audit, not a reason to leave it out. Either give it a path the door can map without turning GET into the list verb (and show the contract test or probe passes), or add a test that fetches /profile as anon, user and admin and compares the results with the table. Also say in the pull that a new resource with read=user and update=admin is added on purpose, because the issue is what authorises it.

Smaller point: layout and the terminal header now show the saved name and brokerage to anyone, guests included, while profile read needs a signed-in user. The old env values were already shown to guests, so this is a judgement call. Show only what the guest welcome page needs, or state that this is intended.

I did not run tsc or the preview. The pull says tsc cannot run in this repo.

commented

All three requested changes are made and pushed. bun test passes (82 tests) and bun run lint:design is clean. tsc still can't run here, since the repo has no tsconfig or TypeScript dependency.

1. Terminal profile view and edit

  • Pressing p on the desk opens the profile through getProfile.
    • A guest gets "Sign in to read the profile" and sees no field values.
    • A user reads it, and pressing e tells them only an admin can change it.
  • An admin presses e and types name, brokerage, license, phone and email in turn, with each field prefilled. Enter moves on and the last Enter calls saveProfile, so validation, audit, redrafting of unsent messages and the lead.changed emit all apply.
  • If validation fails (a blank license, say), the terminal shows the message, saves nothing and returns to the profile view, so the typed input is lost.
  • The README documents the key. The screen hints and the AGENTS.md terminal notes are updated to match.

2. Tests for the new doors

  • server.test.ts now calls the MCP tools:
    • get_profile as anon is refused.
    • set_profile as a user is refused with forbidden.
    • set_profile with a blank license is refused.
    • An admin's set_profile changes what get_profile returns.
  • terminal.test.ts has three new tests:
    • A guest sees nothing and a user can't edit.
    • An admin edit is saved, audited, and shows up in the signature of an unsent draft.
    • A blank license typed in the terminal is refused and nothing is saved.

3. Contract

  • I did not add an api path, and I disagree with adding one. The door maps GET <api> to the list verb and POST <api> to create, and both are nobody for this resource. Any path the door can map would shut the page and the JSON twin to everyone, or force me to loosen list or create to user/admin, which the issue doesn't ask for.
  • Instead, a new test fetches /profile as anon, user and admin, for both GET and POST. It compares each status with permit (401 for anon, 403 for user on write) and checks that PATCH, DELETE and PUT are refused.
  • This is a new resource on purpose. Issue #6 asks for it with read=user and update=admin, and nothing on lead or audit is loosened.

Guest visibility (smaller point) Name, brokerage and license stay visible to everyone in the layout, the footer and the terminal header. They are the advertising disclosure, and the env values were already public, so I left that as it was and recorded it in a comment in layout.ts. Phone and email appear only on /profile and in the terminal profile view, and both need a signed-in user.

Approved

Earlier asks met: the terminal now reads (p) and edits (e) the profile through getProfile/saveProfile, gated by permit, with guest/user/admin tests; the MCP tools have tests for anon, user, blank license and admin; the contract has a test that compares /profile statuses with permit for all three identities. No existing contract cell is loosened. profile is a new resource (read user, update admin) that the issue asked for, so a person should look at it. The preview boots, / answers 200 and /profile answers 401 to a stranger. I could not diff against 0118e88 because the clone lacks that commit, so I read the whole change. Non-blocking: the terminal blank-license test has a stray , void current in its loop, which should just be t.key("\r") twice. Non-blocking: a failed terminal save drops what was typed. Non-blocking: profile has no api path in contract.json, so the forge probe skips it. The added test covers this, but check the forge accepts it.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs