+ );
+}
+```
+
+**2. Modify profile/page.tsx** — two targeted changes:
+
+a) Update the DB query to fetch `agentInitialsData` alongside `agentSignatureData` (single query, one round-trip):
+```typescript
+// BEFORE:
+columns: { agentSignatureData: true },
+// AFTER:
+columns: { agentSignatureData: true, agentInitialsData: true },
+```
+
+b) Add import for `AgentInitialsPanel` and a second `` below the existing Agent Signature section:
+```typescript
+import { AgentInitialsPanel } from '../../_components/AgentInitialsPanel';
+```
+
+Add this section after the closing `` of the Agent Signature block:
+```tsx
+
+
+
Agent Initials
+
+ Draw your initials once. They will be embedded in any "Agent Initials" fields when you prepare a document.
+
+
+
+
+```
+
+**3. Modify FieldPlacer.tsx** — two targeted changes:
+
+a) Add `'agent-initials'` token to `PALETTE_TOKENS` (7th entry, after `agent-signature`):
+```typescript
+{ id: 'agent-initials', label: 'Agent Initials', color: '#ea580c' },
+```
+Orange (`#ea580c`) is unused by any existing token. It visually groups with red (agent-signature) as "agent-owned" while remaining distinct from client-visible tokens.
+
+b) Add `'agent-initials'` to the `validTypes` Set:
+```typescript
+// Add 'agent-initials' to the existing set — do not change any other entries
+const validTypes = new Set(['client-signature', 'initials', 'text', 'checkbox', 'date', 'agent-signature', 'agent-initials']);
+```
+
+Do NOT change any other FieldPlacer logic — drag behavior, overlay rendering, and coordinate conversion all apply to agent-initials the same way they apply to agent-signature.
+
+
+ cd /Users/ccopeland/temp/red/teressa-copeland-homes && npx tsc --noEmit 2>&1 | head -20
+
+ TypeScript compiles clean; `npm run dev` starts without error; /portal/profile shows both the Agent Signature section (unchanged) and the new Agent Initials section below it; FieldPlacer palette shows an orange "Agent Initials" token as the 7th entry; the existing purple "Initials" client token is still present and unchanged.
+
+
+
+
+
+After both tasks complete, verify the full Plan 01 state:
+
+1. `npx tsc --noEmit` passes with zero errors
+2. `npm run dev` starts without errors
+3. Migration applied: `psql -d [db] -c "SELECT column_name FROM information_schema.columns WHERE table_name='users' AND column_name='agent_initials_data';"` returns one row
+4. GET /api/agent/initials returns 401 without session; returns `{ agentInitialsData: null }` with valid session
+5. /portal/profile renders both sections — Agent Signature (existing, unchanged) and Agent Initials (new) — with their respective canvases
+6. Agent can draw on the initials canvas and click "Save Initials" — PUT /api/agent/initials returns 200, thumbnail appears
+7. Agent can click "Update Initials" — canvas reappears for redraw
+8. FieldPlacer shows "Agent Initials" as a draggable orange token (7th entry); purple "Initials" client token still present
+9. Placing an "Agent Initials" field on a document page saves it with `type: 'agent-initials'` in signatureFields
+10. GET /api/sign/[token] does NOT return agent-initials fields (isClientVisibleField returns false)
+
+
+
+- INIT-01: Agent can draw and save initials from /portal/profile; thumbnail shows after save
+- INIT-02: "Update Initials" button replaces saved initials with a new one (same PUT route)
+- INIT-03 (partial): "Agent Initials" token appears in FieldPlacer palette; placed fields have type 'agent-initials'; isClientVisibleField() excludes them from client signing session (Plan 02 completes the embedding)
+- INIT-04 (confirmed): Existing purple "Initials" token still present in palette; no changes to SigningPageClient.tsx or any client-initials pipeline
+- TypeScript build clean; zero new npm packages
+
+
+
diff --git a/.planning/phases/11.1-agent-and-client-initials/11.1-02-PLAN.md b/.planning/phases/11.1-agent-and-client-initials/11.1-02-PLAN.md
new file mode 100644
index 0000000..7c3854b
--- /dev/null
+++ b/.planning/phases/11.1-agent-and-client-initials/11.1-02-PLAN.md
@@ -0,0 +1,300 @@
+---
+phase: 11.1-agent-and-client-initials
+plan: "02"
+type: execute
+wave: 2
+depends_on:
+ - "11.1-01"
+files_modified:
+ - teressa-copeland-homes/src/lib/pdf/prepare-document.ts
+ - teressa-copeland-homes/src/app/api/documents/[id]/prepare/route.ts
+autonomous: true
+requirements:
+ - INIT-03
+ - INIT-04
+
+must_haves:
+ truths:
+ - "When agent prepares a document with agent-initials fields and saved initials, the prepared PDF contains the initials image at each agent-initials field coordinate"
+ - "The agent initials are invisible to the client — GET /api/sign/[token] never returns agent-initials field coordinates (isClientVisibleField already guards this from Plan 01)"
+ - "When agent prepares a document with agent-initials fields but no saved initials, the prepare route returns 422 with { error: 'agent-initials-missing' } — no silent failure"
+ - "When agent prepares a document with no agent-initials fields, the prepare route succeeds normally regardless of whether initials are saved"
+ - "The existing 'initials' (client-initials) branch in preparePdf() is completely untouched — purple placeholder still drawn at prepare time, client still prompted during signing"
+ - "Agent-signature embedding (from Phase 11) continues to work unchanged alongside agent-initials"
+ artifacts:
+ - path: "teressa-copeland-homes/src/lib/pdf/prepare-document.ts"
+ provides: "preparePdf() with agentInitialsData param (6th, optional); embedPng + drawImage at agent-initials field coordinates; existing agent-signature and initials branches untouched"
+ contains: "agentInitialsData"
+ - path: "teressa-copeland-homes/src/app/api/documents/[id]/prepare/route.ts"
+ provides: "Fetches both agentSignatureData and agentInitialsData in a single DB query; 422 guard for missing initials when agent-initials fields present; passes agentInitialsData as 6th arg to preparePdf()"
+ contains: "agent-initials-missing"
+ key_links:
+ - from: "teressa-copeland-homes/src/app/api/documents/[id]/prepare/route.ts"
+ to: "teressa-copeland-homes/src/lib/pdf/prepare-document.ts"
+ via: "preparePdf(srcPath, destPath, textFields, sigFields, agentSignatureData, agentInitialsData)"
+ pattern: "preparePdf.*agentInitialsData"
+ - from: "teressa-copeland-homes/src/app/api/documents/[id]/prepare/route.ts"
+ to: "teressa-copeland-homes/src/lib/db/schema.ts"
+ via: "db.query.users.findFirst({ columns: { agentSignatureData: true, agentInitialsData: true } })"
+ pattern: "agentInitialsData.*findFirst"
+---
+
+
+Wire the agent initials into the prepare pipeline: `preparePdf()` gains an optional `agentInitialsData` parameter (6th, default null) and embeds the PNG at each agent-initials field coordinate using the same embed-once-draw-many pattern already used for agent-signature. The prepare route updates its single DB query to fetch `agentInitialsData` alongside `agentSignatureData`, adds a 422 guard for missing initials, and passes `agentInitialsData` as the 6th argument to `preparePdf()`.
+
+Purpose: Fulfills INIT-03 — agent's saved initials are baked into the prepared PDF before it reaches the client. Confirms INIT-04 — the existing `'initials'` (client-initials) branch is deliberately left untouched; client-initials already work end-to-end.
+Output: Prepared PDFs with embedded agent initials; 422 error when initials are missing; client signing session unaffected; zero regressions.
+
+
+
+@/Users/ccopeland/.claude/get-shit-done/workflows/execute-plan.md
+@/Users/ccopeland/.claude/get-shit-done/templates/summary.md
+
+
+
+@.planning/STATE.md
+@.planning/phases/11.1-agent-and-client-initials/11.1-01-SUMMARY.md
+
+
+
+
+From src/lib/pdf/prepare-document.ts (current function signature — Phase 11 complete, agentInitialsData NOT YET present):
+```typescript
+export async function preparePdf(
+ srcPath: string,
+ destPath: string,
+ textFields: Record,
+ sigFields: SignatureFieldData[],
+ agentSignatureData: string | null = null, // Added Phase 11
+ // Phase 11.1 adds: agentInitialsData: string | null = null,
+): Promise
+```
+
+Current 'initials' branch in preparePdf() — DO NOT TOUCH (this is client-initials):
+```typescript
+} else if (fieldType === 'initials') {
+ // Purple "Initials" placeholder — transparent background, border + label only
+ page.drawRectangle({
+ x: field.x, y: field.y, width: field.width, height: field.height,
+ borderColor: rgb(0.49, 0.23, 0.93), borderWidth: 1.5,
+ });
+ page.drawText('Initials', {
+ x: field.x + 4, y: field.y + 4, size: 8, font: helvetica,
+ color: rgb(0.49, 0.23, 0.93),
+ });
+}
+```
+
+Current agent-signature branch in preparePdf() (Phase 11 — working — do not change):
+```typescript
+} else if (fieldType === 'agent-signature') {
+ if (agentSigImage) {
+ page.drawImage(agentSigImage, {
+ x: field.x,
+ y: field.y,
+ width: field.width,
+ height: field.height,
+ });
+ }
+}
+```
+
+Pattern for embed-once-draw-many (Phase 11 confirmed working):
+```typescript
+// BEFORE the field loop — embed once:
+let agentSigImage: PDFImage | null = null;
+if (agentSignatureData) {
+ agentSigImage = await pdfDoc.embedPng(agentSignatureData);
+}
+
+// Phase 11.1 parallel pattern — add after agentSigImage block:
+let agentInitialsImage: PDFImage | null = null;
+if (agentInitialsData) {
+ agentInitialsImage = await pdfDoc.embedPng(agentInitialsData);
+}
+```
+
+CRITICAL: Do NOT call embedPng() inside the field loop. The Phase 11 pattern calls it once
+before the loop and reuses the PDFImage reference. Phase 11.1 follows the same pattern.
+
+From src/app/api/documents/[id]/prepare/route.ts (Phase 11 state — current):
+```typescript
+// Current: fetches only agentSignatureData
+const agentUser = await db.query.users.findFirst({
+ where: eq(users.id, session.user.id),
+ columns: { agentSignatureData: true }, // Phase 11.1: ADD agentInitialsData: true
+});
+const agentSignatureData = agentUser?.agentSignatureData ?? null;
+
+// Phase 11 guard (existing — leave unchanged):
+const hasAgentSigFields = sigFields.some(f => getFieldType(f) === 'agent-signature');
+if (hasAgentSigFields && !agentSignatureData) {
+ return Response.json(
+ { error: 'agent-signature-missing', message: '...' },
+ { status: 422 }
+ );
+}
+
+// Current call (5 args):
+await preparePdf(srcPath, destPath, textFields, sigFields, agentSignatureData);
+```
+
+PDFImage type note: PDFImage is already imported (or available as a type import) from
+@cantoo/pdf-lib in prepare-document.ts since Phase 11. Use the same import pattern.
+Do not add a new import if PDFImage is already destructured from the existing import.
+
+
+
+
+
+
+ Task 1: preparePdf() — add agentInitialsData param and embed at agent-initials field coordinates
+
+ teressa-copeland-homes/src/lib/pdf/prepare-document.ts
+
+
+Three targeted changes to `preparePdf()` — no other logic changes:
+
+**1. Add `agentInitialsData` parameter** as the 6th parameter with a default of `null` (so the existing 5-arg call site in the prepare route still compiles until Task 2 updates it):
+```typescript
+export async function preparePdf(
+ srcPath: string,
+ destPath: string,
+ textFields: Record,
+ sigFields: SignatureFieldData[],
+ agentSignatureData: string | null = null,
+ agentInitialsData: string | null = null, // ADD THIS
+): Promise
+```
+
+**2. Embed agent initials image once** — add this block immediately AFTER the existing `agentSigImage` embed block (before the field loop):
+```typescript
+// Embed agent initials image once — reused across all agent-initials fields
+let agentInitialsImage: PDFImage | null = null;
+if (agentInitialsData) {
+ agentInitialsImage = await pdfDoc.embedPng(agentInitialsData);
+}
+```
+
+If `PDFImage` is already in the existing `@cantoo/pdf-lib` import destructure, use it directly. If not, add `PDFImage` to the existing import — do not create a new import statement.
+
+**3. Add `'agent-initials'` branch** in the field loop — add it as a new `else if` block after the existing `'agent-signature'` branch:
+```typescript
+} else if (fieldType === 'agent-initials') {
+ if (agentInitialsImage) {
+ page.drawImage(agentInitialsImage, {
+ x: field.x,
+ y: field.y,
+ width: field.width,
+ height: field.height,
+ });
+ }
+ // If no initials saved: the prepare route guards against this with 422 before calling preparePdf
+}
+```
+
+Do NOT modify:
+- The `'initials'` branch (client-initials purple placeholder) — leave completely untouched
+- The `'agent-signature'` branch — leave completely untouched
+- Any other field type branches or function logic
+
+
+ cd /Users/ccopeland/temp/red/teressa-copeland-homes && npx tsc --noEmit 2>&1 | head -20
+
+ TypeScript compiles clean; preparePdf() function signature now has 6 parameters (last two optional); agent-initials branch draws the image; existing 'initials' (client-initials) and 'agent-signature' branches are untouched; no regressions on other field type branches.
+
+
+
+ Task 2: prepare route — fetch agentInitialsData in same query, 422 guard, pass to preparePdf
+
+ teressa-copeland-homes/src/app/api/documents/[id]/prepare/route.ts
+
+
+Three targeted additions to the POST handler — do not change any other logic:
+
+**1. Update the existing DB query** to fetch `agentInitialsData` alongside `agentSignatureData` in the same `findFirst()` call (one DB round-trip, not two):
+```typescript
+// BEFORE:
+const agentUser = await db.query.users.findFirst({
+ where: eq(users.id, session.user.id),
+ columns: { agentSignatureData: true },
+});
+const agentSignatureData = agentUser?.agentSignatureData ?? null;
+
+// AFTER:
+const agentUser = await db.query.users.findFirst({
+ where: eq(users.id, session.user.id),
+ columns: { agentSignatureData: true, agentInitialsData: true }, // ADD agentInitialsData
+});
+const agentSignatureData = agentUser?.agentSignatureData ?? null;
+const agentInitialsData = agentUser?.agentInitialsData ?? null; // ADD
+```
+
+**2. Add the agent-initials 422 guard** — add this block immediately AFTER the existing `hasAgentSigFields` guard (NOT before it):
+```typescript
+// Guard: agent-initials fields present but no initials saved
+const hasAgentInitialsFields = sigFields.some(f => getFieldType(f) === 'agent-initials');
+if (hasAgentInitialsFields && !agentInitialsData) {
+ return Response.json(
+ { error: 'agent-initials-missing', message: 'No agent initials saved. Go to Profile to save your initials first.' },
+ { status: 422 }
+ );
+}
+```
+
+**3. Update the preparePdf() call** to pass `agentInitialsData` as the 6th argument:
+```typescript
+// BEFORE (5 args):
+await preparePdf(srcPath, destPath, textFields, sigFields, agentSignatureData);
+
+// AFTER (6 args):
+await preparePdf(srcPath, destPath, textFields, sigFields, agentSignatureData, agentInitialsData);
+```
+
+Do not change any other logic in the route handler — DB update, audit logging, and response all remain unchanged.
+
+
+ cd /Users/ccopeland/temp/red/teressa-copeland-homes && npx tsc --noEmit 2>&1 | head -20
+
+ TypeScript compiles clean; prepare route fetches both agentSignatureData and agentInitialsData in a single query; guard returns 422 with { error: 'agent-initials-missing' } when agent-initials fields exist but no initials saved; preparePdf called with 6 args including agentInitialsData.
+
+
+
+
+
+After both tasks complete, verify the full Plan 02 state:
+
+1. `npx tsc --noEmit` passes with zero errors
+2. `npm run dev` starts without errors (or `npm run build` succeeds)
+3. Agent-initials round-trip test:
+ a. Visit /portal/profile, draw and save initials
+ b. Open a document in the portal, place an "Agent Initials" field (orange token) on any page
+ c. Fill text fields and click Prepare
+ d. Prepare succeeds (200 response)
+ e. Download the prepared PDF and verify the agent initials PNG is embedded at the correct position
+4. Agent-initials guard test — prepare with no saved initials:
+ a. Place an agent-initials field on a document for an account with no initials saved
+ b. Prepare route returns 422 with `{ error: 'agent-initials-missing' }`
+5. Agent-signature regression test — confirm Phase 11 behavior unchanged:
+ a. Place an agent-signature field, ensure a signature is saved, prepare the document
+ b. Signature still embeds correctly; no regression
+6. Client-initials regression test — confirm existing 'initials' behavior unchanged:
+ a. Place a purple "Initials" field, prepare the document
+ b. Prepared PDF shows purple "Initials" placeholder at the field location
+ c. Open the signing link — client still sees the initials overlay and can initial the field
+7. Client signing page isolation test:
+ a. Open the signing link for a document with agent-initials fields
+ b. Signing page does NOT show an overlay at agent-initials coordinates (isClientVisibleField already returns false from Plan 01)
+
+
+
+- INIT-03: Agent's saved initials PNG is embedded at each agent-initials field coordinate in the prepared PDF; field is never exposed to the client
+- INIT-04: Existing 'initials' type (client-initials) behavior confirmed unchanged — client is still prompted to initial during signing session
+- Prepare fails with actionable 422 when agent-initials fields exist but no initials saved
+- Agent-signature embedding (Phase 11) still works — no regression
+- TypeScript build clean; zero new npm packages; no regressions on any other field type
+
+
+
diff --git a/.planning/phases/11.1-agent-and-client-initials/11.1-03-PLAN.md b/.planning/phases/11.1-agent-and-client-initials/11.1-03-PLAN.md
new file mode 100644
index 0000000..a2df41c
--- /dev/null
+++ b/.planning/phases/11.1-agent-and-client-initials/11.1-03-PLAN.md
@@ -0,0 +1,129 @@
+---
+phase: 11.1-agent-and-client-initials
+plan: "03"
+type: execute
+wave: 3
+depends_on:
+ - "11.1-01"
+ - "11.1-02"
+files_modified: []
+autonomous: false
+requirements:
+ - INIT-01
+ - INIT-02
+ - INIT-03
+ - INIT-04
+
+must_haves:
+ truths:
+ - "All four INIT requirements (INIT-01 through INIT-04) verified by human in a single live test"
+ - "Agent initials draw, save, place, prepare, and PDF embedding round-trip confirmed working"
+ - "Client-initials (existing 'initials' type) confirmed unchanged — client can still initial fields during signing"
+ - "Agent-initials field never surfaces to the client signing page"
+ artifacts:
+ - path: "teressa-copeland-homes/src/app/portal/(protected)/profile/page.tsx"
+ provides: "Profile page with both Agent Signature and Agent Initials sections visible"
+ - path: "teressa-copeland-homes/src/lib/pdf/prepare-document.ts"
+ provides: "preparePdf() embeds agent initials at agent-initials field coordinates"
+ key_links:
+ - from: "Agent saves initials at /portal/profile"
+ to: "Prepared PDF"
+ via: "PUT /api/agent/initials → users.agentInitialsData → preparePdf() → pdfDoc.embedPng + drawImage"
+ pattern: "full pipeline"
+---
+
+
+Human end-to-end verification of all Phase 11.1 requirements: draw and save initials on the profile page, place an agent-initials field, prepare the document, confirm the initials are embedded in the prepared PDF and absent from the client signing session, and confirm the existing client-initials flow is unaffected.
+
+Purpose: All four INIT requirements are verified end-to-end by a human using the portal. No code changes in this plan — all deliverables were completed in Plans 01 and 02.
+Output: Phase 11.1 marked complete; INIT-01 through INIT-04 confirmed working.
+
+
+
+@/Users/ccopeland/.claude/get-shit-done/workflows/execute-plan.md
+@/Users/ccopeland/.claude/get-shit-done/templates/summary.md
+
+
+
+@.planning/STATE.md
+@.planning/phases/11.1-agent-and-client-initials/11.1-01-SUMMARY.md
+@.planning/phases/11.1-agent-and-client-initials/11.1-02-SUMMARY.md
+
+
+
+
+
+ Task 1: Human verification — full Phase 11.1 agent and client initials end-to-end
+ Run the dev server and execute the verification steps below. There are no code changes in this plan — all code was delivered in Plans 01 and 02.
+
+Complete Phase 11.1 agent and client initials implementation:
+- DB migration: agentInitialsData TEXT column on users table
+- GET/PUT /api/agent/initials API routes
+- AgentInitialsPanel component on /portal/profile (below Agent Signature section)
+- Orange "Agent Initials" token in FieldPlacer palette (7th token)
+- isClientVisibleField() updated to exclude agent-initials from client signing session
+- preparePdf() embeds agentInitialsData PNG at agent-initials field coordinates
+- prepare route 422 guard for missing initials + combined single-query fetch
+- Existing 'initials' (client-initials) pipeline confirmed untouched throughout
+
+
+Start the dev server: `cd /Users/ccopeland/temp/red/teressa-copeland-homes && npm run dev`
+
+**Step 1 — Save agent initials (INIT-01):**
+- Visit http://localhost:3000/portal/profile
+- Confirm the page shows BOTH the "Agent Signature" section (existing, unchanged) AND a new "Agent Initials" section below it
+- Draw your initials on the Agent Initials canvas
+- Click "Save Initials"
+- Expected: Canvas is replaced by a thumbnail of your initials with an "Update Initials" button
+
+**Step 2 — Update agent initials (INIT-02):**
+- Click "Update Initials" on the profile page
+- Draw different initials
+- Click "Save Updated Initials"
+- Expected: New thumbnail replaces the old one
+
+**Step 3 — Place agent-initials field and prepare (INIT-03):**
+- Open any document in the portal and go to the prepare tab
+- Confirm the FieldPlacer palette shows an orange "Agent Initials" token (7th token, distinct from the purple "Initials" client token)
+- Drag the orange "Agent Initials" token and drop it onto the document (any page, any position)
+- Expected: An orange field box appears on the PDF where you dropped it
+- Assign the document to a client and click Prepare
+- Expected: Prepare succeeds (no 422 error)
+- Download the prepared PDF
+- Open the prepared PDF — confirm your initials PNG is embedded at the position where you placed the field
+
+**Step 4 — Confirm agent-initials absent from client signing page (INIT-03):**
+- Send the prepared document to a client (or use the signing link directly)
+- Open the signing link in the browser
+- Expected: NO interactive overlay appears at the agent-initials field position
+- Expected: Client-signature and initials overlays (if placed) still appear normally for the client
+
+**Step 5 — Confirm client-initials unchanged (INIT-04):**
+- Open a document and place the purple "Initials" token on it
+- Prepare the document — confirm the prepared PDF shows a purple "Initials" placeholder at that position
+- Open the signing link — confirm the purple initials overlay appears with animation
+- Click the overlay — confirm the modal opens with "Add Initials" as the title
+- Submit initials — confirm they are embedded in the signed PDF
+
+ Type "approved" if all 5 steps pass. Describe any issues found if not (include step number and observed vs expected behavior).
+ All 5 steps pass and human types "approved"
+ Full end-to-end round-trip confirmed: agent draws/saves initials, places agent-initials field, prepares document with embedded initials PNG, client signing session shows no agent-initials overlay; existing client-initials ('initials' type) flow is unaffected
+
+
+
+
+
+Human verification approved — all four INIT requirements confirmed by live testing:
+- INIT-01: Agent drew and saved initials; thumbnail visible at /portal/profile
+- INIT-02: "Update Initials" replaced saved initials with a new one
+- INIT-03: Orange "Agent Initials" token visible and usable in FieldPlacer palette; initials PNG embedded in prepared PDF at correct position; absent from client signing session
+- INIT-04: Existing purple "Initials" client token unchanged; client still prompted to initial during signing; modal shows "Add Initials"
+
+
+
+Human approves all 5 verification steps. Phase 11.1 is complete and all INIT requirements are satisfied.
+
+
+