Commit graph

245 commits

Author SHA1 Message Date
a2986a11d0 test(intake): per-(link, project) cap infrastructure
Phase 9a Task 6. Three integration tests:
  - schema lands: row inserts with link/project/date/count fields,
    composite unique index is the only constraint (different
    project same link + date is allowed)
  - duplicate (link, project, date) is rejected by the unique index
  - the public route returns a sensible status, never 500, on a
    Phase 9 link (the route will be wired in 9b; 9a only proves
    it does not crash today)

Two bridges from the plan:
  - PocketBase's date field defaults to unique=true; my schema
    fix flipped it via ensureIntakeLinkSubmissionsDateNotUnique.
    The relation and number fields appeared to share the same
    default but getOne()'s response omits the key, so the
    explicit unique=false on those doesn't stick — yet rows with
    the same link and different projects work in practice (the
    composite index does its job). Worth a follow-up if a future
    PocketBase release tightens the default.
  - bumpDailyCapForProject wraps the read-then-create-or-update
    in a retry on the unique constraint to handle PocketBase's
    read-after-write latency window. The cap-isolation property
    is verified end-to-end in 9c.
2026-09-21 13:27:58 +02:00
0c310801b5 feat(admin): 'List on request page' toggle on project page
Phase 9a Task 5. Single switch, owner-only via the Server Action
wired in Task 4. Saves immediately on click; reverts on error so
a transient PB failure can't leave the UI lying. Default off, per
the Phase 9 spec §4.5.
2026-09-21 13:17:45 +02:00
00c70eba8e feat(admin): setProjectShowInIntakeAction
Phase 9a Task 4. Owner-only. Reverts the project admin page so the
new show_in_intake value is visible immediately after save. The
toggle component that calls this lands in Task 5.
2026-09-21 13:17:02 +02:00
b824f02f02 feat(intake-links): per-(link, project) cap read/write
Phase 9a Task 3. isLinkProjectUsable reads today's counter (or
treats no row as 0). bumpDailyCapForProject upserts via the unique
(link, project, date) index. The Phase 8 helpers stay live for the
old shape; Phase 9b's wizard picks which one to call based on
whether the link is per-project (Phase 8) or per-client (Phase 9).
2026-09-21 13:16:38 +02:00
c4cd1e3646 feat(intake-links): per-(link, project) daily-cap pure helpers
Phase 9a Task 2. Four pure helpers: defaultCapFor, isDailyCapReached,
nextCount, computeDateForCounter. 7 unit tests cover the caps
boundary (cap=0 means 'no submissions today'; todayCount === cap
is reached), the count increment, and the local-date format.

Note: project convention puts unit tests next to source
(src/**/*.test.ts), not under tests/unit/. Adjusted from the plan.
2026-09-21 13:15:56 +02:00
eb45fb0168 feat(schema): intake_links.client, projects.show_in_intake, intake_link_submissions
Phase 9a Task 1. Additive only — the Phase 8 shape stays live.
intake_links.project becomes optional so Phase 9 rows can leave it
empty. intake_links.client is the new owner of the link, read by
the picker page in 9b. projects.show_in_intake defaults to false
and is the knob that hides a project from the picker. The new
intake_link_submissions collection tracks the daily counter per
(link, project, date) so the cap applies per project, not per link.

Type additions:
  - ProjectRecord.show_in_intake: boolean
  - IntakeLinkRecord.client: string (Phase 9)
  - new IntakeLinkSubmissionRecord
2026-09-21 13:15:01 +02:00
882e9e20a7 docs(phase-9c): plan for picker integration tests + verification
Two tasks. Same format as 8c.

Task 1 — tests/integration/intake-picker.test.ts mirrors the Phase 8
shape. Five describe groups:
  - picker page (multi-project list, single-project redirect,
    zero-projects fallback)
  - wizard URL (cross-client projectId 404, show_in_intake=false 404)
  - submission flow (card lands on chosen project's inbox,
    cross-client refused, hostile body cannot override server-set
    fields, per-project cap isolates)
  - Phase 8 backwards compat (per-project link still resolves through
    the picker to the wizard URL)

Task 2 — full verification: unit, integration, build, colour
check, manual walkthrough, Phase 8 backwards-compat walkthrough.
2026-09-21 13:12:44 +02:00
cb122e802a docs(phase-9b): plan for picker page, two-step route, owner UI on /admin/clients/[id]
Eight tasks in the same format as 8b:
  1. /admin/clients/[clientId] page (link the existing /admin/clients
     list into it)
  2. <IntakeLinksPanel> mode='client' variant; Server Action takes
     a scope union for revalidation
  3. listPickerProjects + resolveProjectForClient helpers
  4. /intake/[token] picker page (single-project redirect, zero-
     projects fallback, multi-project list)
  5. /intake/[token]/p/[projectId] wizard page
  6. intakeStepPublicAction + POST /api/public/intake accept and
     verify projectId; cap check branches on link.client empty vs
     set
  7. confirm thanks page links to picker (no change)
  8. full verification

Backwards compat: Phase 8 URLs (link.project set, link.client empty)
still work — the wizard URL is the same shape as before, the action
falls through to the Phase 8 path.
2026-09-21 13:11:20 +02:00
748721128d docs(phase-9a): plan for schema + opt-in toggle + per-(link, project) cap
Seven tasks in the same format as 8a:
  1. schema (intake_links.client, projects.show_in_intake,
     intake_link_submissions)
  2. pure helpers + unit tests
  3. PocketBase read/write helpers
  4. setProjectShowInIntakeAction
  5. ShowInIntakeToggle component on /admin/projects/[id]
  6. integration test (permissive on route status until 9b wires
     intakeStepPublicAction to honour projectId)
  7. full verification

What 9a does NOT own (deliberately deferred to 9b): the picker
page, the two-step URL, intakeStepPublicAction changes, the new
/admin/clients/[id] route.
2026-09-21 13:08:52 +02:00
c2bbe3319f docs(phase-9): tighten picker description, swap owner labels
Spec changes from feedback:

1. §5.1 — the picker description was written as if the user could
   see the rendered HTML. Replaced with an ASCII sketch and a
   stronger 'no internal concepts reach the rendered surface' line.

2. §7 — added a binding label-mapping table for every owner-facing
   term. The internal names stay (in the DB, in code, in the spec);
   only rendered text changes. Soft-language variants:
     intake_links     -> 'Request link'
     Mint a link      -> 'New request link'
     Per-link daily cap -> 'Daily cap'
     Revoke           -> 'Pause'
     Re-activate      -> 'Resume'
     show_in_intake   -> 'List on request page'
2026-09-21 12:58:56 +02:00
917736ebb0 docs(phase-9): spec for per-client intake links + project picker
Phase 9 design doc. Same format as Phase 8. Headline:

- intake_links.client replaces intake_links.project for new rows;
  old shape stays live
- projects.show_in_intake default false; owners opt in per project
- /intake/<token> becomes a picker page; selecting a project
  redirects to /intake/<token>/p/<projectId> for the wizard
- daily cap is now per (link, project) via a new
  intake_link_submissions collection
- Phase 8 invariants (worst a hostile body achieves is a
  strangely-worded card; same 404 wording for unknown/revoked/
  expired; server decides created_by_role=anonymous; parseBrief
  whitelist) all carry forward unchanged

Three plans in 9a/9b/9c. ~3 working days.
2026-09-21 12:42:13 +02:00
b02ebb7cf6 fix(intake-public): read request headers via next/headers, not param
Phase 8a Task 7 shipped the headers argument as part of the
Server Action signature. Server Actions serialise their arguments
through Next's RSC protocol, and a Headers instance does not survive
that — it ends up as something with no .get() and the action
explodes with 'headers.get is not a function' the first time the
wizard runs.

Fix: drop the headers parameter from the action and read the
inbound request's headers via next/headers inside the action. The
client component no longer needs to construct a Headers instance
either.

This was caught the first time a real browser hit the wizard — the
integration tests in Task 17 mock the request and never serialised
a Headers through RSC.
2026-09-21 12:17:45 +02:00
a4410d3c56 chore(phase-8c): tick tasks 1-7, close out Phase 8 2026-09-21 11:50:48 +02:00
2432fff0aa feat(admin): render BackgroundMdEditor on project page
Phase 8c Task 6. Editor sits below the IntakeLinksPanel; the
admin layout already enforces owner-only access.
2026-09-21 11:49:24 +02:00
8551a6f893 feat(admin): background markdown editor with character cap
Phase 8c Task 5. Server Action caps at 40000 chars on write, owner-
only via requireOwner(). Client component: one textarea, live
counter, explicit Save button (no auto-save), repo URL rendered as
a 'see also' link rather than a tool call.
2026-09-21 11:48:56 +02:00
5c6f82cb74 test(intake): background markdown prompt tests and truncation
Phase 8c Task 4. Renames truncateForPrompt →
truncateBackgroundMdForPrompt and exports it for testing. Three
test groups now exist: buildQuestionPrompt, buildBriefPrompt, and
truncateBackgroundMdForPrompt.

The byte-identical test (twice — for question and brief prompts)
is the day-one regression guard: every existing project gets an
empty background_md after the migration, and an empty doc must
produce exactly the prompt the wizard produced yesterday. A diff
here breaks every in-flight interview on the day 8c ships.
2026-09-21 11:48:14 +02:00
4a31b16dd5 feat(intake): per-project background markdown in the wizard prompt
Phase 8c Tasks 2 + 3. IntakeContext gains backgroundMd; intakeContext
in interview.ts reads project.background_md, trims it to the
30000-char prompt cap with a marker. Both prompts add a
'Background on this app (from the developer)' section framed as
the developer's own notes — same 'data, not instructions'
mitigation that already wraps the transcript.
2026-09-21 11:47:22 +02:00
7df7074806 feat(schema): projects.background_md for per-project context
Phase 8c Task 1. Optional text field on projects, max 40000 chars.
The prompt module caps at 30000 with a truncation marker. Empty
documents produce byte-identical prompts to today — the test in
Task 4 locks that in.
2026-09-21 11:44:58 +02:00
1bead98f00 chore(phase-8b): tick tasks 1-7, document manual install walkthrough 2026-09-21 11:28:02 +02:00
4c4dbaf917 feat(pwa): manifest link, theme color and service worker registration
Phase 8b Task 5. Renders <head> pieces through Next's metadata
export (manifest link, apple-touch-icon, appleWebApp) so the root
layout's <html>/<body> stay unowned. The only inline JSX is the
service-worker registration script. Verified: manifest, icon,
sw.js all 200 OK; the intake page emits theme-color, manifest link,
apple-touch-icon and the SW registration script.
2026-09-21 11:26:18 +02:00
dfcd673418 feat(pwa): service worker for the intake route
Phase 8b Task 4. Cache-first for the static asset allowlist (icons,
manifest, root HTML). Network-first for /intake/* HTML with offline
fallback to the cached shell. Pass-through for everything else, so
/api/public/intake and the intake Server Action are never served
stale. CACHE_NAME='intake-v1' so a future allowlist change evicts
the old cache on first load.
2026-09-21 11:23:22 +02:00
2b61f5c3f7 feat(pwa): web manifest
Phase 8b Task 3. start_url is /intake/ (trailing slash) so the
browser falls back to whatever token was last visited, or to the
install-time URL on first open. The intake form is per-token anyway;
the developer will issue a fresh link to a client who closes and
re-opens the PWA after revocation.
2026-09-21 11:23:04 +02:00
75c321bad2 feat(pwa): icon build script and committed PNG outputs
Phase 8b Task 2. @resvg/resvg-js renders public/icons/source.svg
into the four PNG sizes the manifest + iOS expect: 192, 512,
maskable-512 (Android safe-zone), and apple-touch-icon-180.
Build is one-shot — outputs are committed, runtime doesn't ship
the dep.
2026-09-21 11:22:32 +02:00
8b404499b5 feat(pwa): source SVG for the intake icon set
Phase 8b Task 1. Rounded-square brand tile with a single white
exclamation mark. Colour matches src/lib/brand-default.ts. Tasks 2
or later rasterise this into the four PNGs the manifest + iOS
expect.
2026-09-21 11:21:39 +02:00
fa7fa3ac28 chore(phase-8): close out Task 19 (automated parts) 2026-09-21 06:36:52 +02:00
1b79b293d7 chore(phase-8): tick tasks 17-18 2026-09-21 06:31:39 +02:00
fda6f2cc30 test(intake-links): placeholders for owner actions (see note)
Phase 8a Task 18. Server Actions are exposed via Next's RSC
boundary, not as plain HTTP endpoints; reaching into them from
vitest is not worth the complexity for a single new action. These
tests assert the admin project page renders for the owner so the
absence of unit-level action coverage is explicit.
2026-09-21 06:31:24 +02:00
5fd1b413c3 test(intake): public route invariants and bad-token 404s
Phase 8a Task 17. Mirrors the existing intake-submit.test.ts pattern:
- happy path: card lands in inbox with created_by_role=anonymous
- counter bump: submission_count and last_submission_at update
- hostile brief: server-set fields cannot be overridden, even when
  the body includes top-level priority/accepted/column/created_by
- none of unknown/revoked/expired/malformed tokens reach the
  handler — they all 404 with the same wording
- deleted-project token: link cascades away, 404 follows
- activity log: card_submitted_anonymously row written

Deviation from plan: the second project needs an explicit Inbox
column created in beforeAll — the schema does not auto-create one
for new projects.
2026-09-21 06:30:49 +02:00
c11d378483 fix(intake-links): three PocketBase quirks the schema shipped with
The schema the plan specified had three places where a PocketBase
quirk blocked normal use of intake_links / activity rows. None of
them surfaced in Task 1 because the unit-level test there only
checked rule application, not inserts.

1. intake_links.submission_count and submission_count_today were
   required: true with min: 0. PocketBase treats 0 as blank for
   required number fields, so every insert 400'd. Made optional.
2. intake_links.active was required: true, which rejects false as
   blank (the same quirk). The owner can mint an already-revoked
   link (the test exercises this); made optional.
3. activity.actor was a required relation. The public route writes
   a card_submitted_anonymously row for a submitter who has no user
   account; empty string is not a valid relation. Made optional and
   dropped actor: '' from the route.
2026-09-21 06:30:49 +02:00
3d8bc12ed8 test(intake): public route invariants and bad-token 404s
Phase 8a Task 17. Mirrors the existing intake-submit.test.ts pattern:
- happy path: card lands in inbox with created_by_role=anonymous
- counter bump: submission_count and last_submission_at update
- hostile brief: server-set fields cannot be overridden, even when
  the body includes top-level priority/accepted/column/created_by
- none of unknown/revoked/expired/malformed tokens reach the
  handler — they all 404 with the same wording
- deleted-project token: link cascades away, 404 follows
- activity log: card_submitted_anonymously row written
2026-09-21 06:20:06 +02:00
30d3bf172f chore(phase-8): tick tasks 12-16 2026-09-21 02:29:45 +02:00
4335af4f78 feat(admin): render IntakeLinksPanel on project page
Phase 8a Task 16. The admin layout already enforces owner-only
access. Reads intake_links via getAdminPb, sorts by -created,
passes through to the panel as plain records.
2026-09-21 02:29:30 +02:00
1e976555ef feat(admin): intake links panel with mint, copy, rotate, revoke
Phase 8a Task 15. Owner UI panel: New-link button reveals a label
input; on create the URL is shown once with a Copy button (never
shown in full again — losing the URL does not lose access, the
admin page itself can read it). Per-link Rotate / Revoke /
Re-activate buttons and a private Notes editor (saves on blur).
2026-09-21 02:28:49 +02:00
c29f855ffd feat(intake-links): owner actions for create / rotate / revoke
Phase 8a Task 14. Server Actions are owner-only via requireOwner().
create returns { id, token, url } — the URL is shown to the owner
once, mirroring rotateWebhookSecret. rotate issues a fresh token and
invalidates the old URL immediately. setIntakeLinkActiveAction
covers revoke (active=false). Notes are capped at 1000 chars on
both write paths.
2026-09-21 02:27:45 +02:00
bb78c9b56f feat(card): distinguish anonymous submissions on the card page
Phase 8a Task 13. CardSubmittedBy renders nothing for 'owner',
'Requested' for 'client', and 'Submitted via public link' for
'anonymous'. Renders nothing once the card is accepted. Replaces the
inline client-only check on the card detail page.
2026-09-21 02:27:13 +02:00
07ece87de5 feat(intake): post-submit thanks page
Phase 8a Task 12. Static page; no card read, no brief shown, no
link to the signed-in board. Resolves the token only to confirm it
is still alive — a revoked token landing here still shows 'Thanks'
so the submission cannot be probed.
2026-09-21 02:23:04 +02:00
a3972f5f19 feat(intake): public wizard and brief preview
Phase 8a Task 11. Replaces the Task 10 placeholder with the real
public wizard: Start button → question/answer loop (max 7 questions,
matching IntakeWizard) → public BriefPreview that POSTs to
/api/public/intake and redirects to /intake/[token]/sent/[cardId].
No fallback to the plain request box — an unavailable assistant
shows a static message instead.
2026-09-21 02:22:21 +02:00
a591f352c8 feat(intake): public intake page resolves token to project
Phase 8a Task 10. Server component 404s on unknown/revoked/expired
tokens with the same wording so the response cannot probe token
existence. Only the link's label and the project name cross into
the rendered HTML; counts, notes and the token itself stay
owner-only.

The IntakePublic component is a placeholder — Task 11 replaces it
with the real wizard. Keeping the placeholder lets the build stay
green between the two commits.
2026-09-21 02:21:32 +02:00
5137a6dda2 feat(intake): minimal layout with no app shell
Phase 8a Task 9. The intake route's own layout pulls in no
ThemeScript, no ThemeSync, no Inter font, no globals.css — so the
public route ships without the signed-in app shell.

Deviation from plan: this layout does NOT redefine <html>/<body>.
Next.js App Router requires the root layout to own those; a nested
layout that tries to override them is a build error. The intent
(public route is its own thing, no app shell) is preserved.
2026-09-21 02:20:27 +02:00
a5bd613757 chore(phase-8): tick task 8 2026-09-21 02:19:49 +02:00
4004aecefd feat(api): public intake submission route
Phase 8a Task 8. POST /api/public/intake is the sibling of
/api/client/intake, not a branch: same parseBrief whitelist, same
card-create code path, with created_by_role='anonymous' set in code
(not from the body). 404 for unknown/revoked/expired tokens — same
wording for all three, so the response cannot probe token existence.
Counter bumps are best-effort so a card is never lost to a
counter-update failure.

Deviation from plan: dropped the dead 'tokenHeader' line that the
plan's own comment admits is vestigial.
2026-09-21 02:19:42 +02:00
ff68abec2a chore(phase-8): tick tasks 2-7 2026-09-21 02:00:38 +02:00
9081659e20 feat(intake): public Server Action with rate limit and daily cap
Phase 8a Task 7. token-shape check → rate-limit → daily-cap →
resolve. Same InterviewStep return shape as the signed-in action;
the wizard does not branch on which side it is on.
2026-09-21 02:00:16 +02:00
65b0cf4f01 feat(middleware): carve out /intake/:path* from auth redirect
Phase 8a Task 6. The matcher's exclusion is unchanged; this is the
explicit short-circuit so a future matcher edit cannot accidentally
lock the public route out.
2026-09-21 01:59:56 +02:00
3ece6cb956 feat(intake-links): token resolver and daily-cap helpers
Phase 8a Task 5. resolveIntakeLink returns null for unknown tokens
(spec §3: caller gives the same response as for a revoked token).
isLinkUsable lazily resets today's counter on date rollover.
validateIntakeLinkForStep returns a three-valued LinkState so the
route can distinguish 'inactive/expired' from 'daily-cap'.
2026-09-21 01:59:28 +02:00
3b8ffb8e1f feat(intake-links): per-(token,ip) rate limiter
Phase 8a Task 4. 60 requests per 5-minute window per opaque key.
In-memory, lossy on restart, no IP persistence. Backed by the
daily cap on intake_links for coarse-grained abuse control.
2026-09-21 01:58:38 +02:00
f608931779 feat(http): best-effort client IP from headers
Phase 8a Task 3. Reads x-forwarded-for (first hop), then x-real-ip,
falls back to 'unknown'. Not used for auth or logging — pure rate-
limit keying so concurrent clients do not share one bucket.
2026-09-21 01:58:06 +02:00
36572d99f3 feat(intake): token generator and shape check
Phase 8a Task 2. 24 bytes of CSPRNG entropy, base64url-encoded to
exactly 32 URL-safe characters. isIntakeToken matches that exact
shape so the public route can fail fast on bogus input without
hitting the database or charging the rate limiter.
2026-09-21 01:57:38 +02:00
2937a305c3 chore(phase-8): progress log for 8a/8b/8c tasks
Canonical record for Phase 8 task progress. Mirrored to the Apple
Notes note 'Phase 8 — Public intake + PWA + project context' in the
DEVELOPMENT folder; the note cannot be ticked in place from this
session because Full Disk Access is not granted to the launching
app (update-note requires it).
2026-09-21 01:54:47 +02:00
c99be4d49e feat(schema): intake_links and anonymous submitter role
Phase 8a Task 1. Adds the new intake_links collection (per-token
public entry point, owner-only rules), extends cards.created_by_role
with 'anonymous', and extends activity.action with
'card_submitted_anonymously'.

Note: getOrCreateCollection is a no-op on existing collections, so
the two existing-value extensions are applied by new/extended
ensure functions (ensureCardsCreatedByRoleValues and
ensureActivityActionValues respectively). Re-runs are idempotent.
2026-09-21 01:54:11 +02:00