Complete S02 application package drafting loop

This commit is contained in:
2026-03-24 10:36:05 +01:00
parent 3e5f796326
commit b5b430947b
14 changed files with 864 additions and 152 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ This milestone is complete only when all are true:
- [x] **S01: Smarter Gmail import and matching** `risk:high` `depends:[]`
> After this: User can connect Gmail, review likely messages or threads for a job, and import correspondence with much better matching confidence and less manual cleanup.
- [ ] **S02: Stronger AI application package drafting** `risk:high` `depends:[S01]`
- [x] **S02: Stronger AI application package drafting** `risk:high` `depends:[S01]`
> After this: From an imported job plus profile/CV context, the app generates materially better tailored CV and cover-letter drafts that feel specific and usable.
- [ ] **S03: Reply and follow-up drafting from real thread context** `risk:medium` `depends:[S01,S02]`
@@ -0,0 +1,60 @@
# S02: Stronger AI application package drafting
**Goal:** Make the application package generator use imported job/correspondence context well enough that tailored CV, cover-letter, and recruiter-message drafts feel specific, credible, and worth starting from inside the job workspace.
**Demo:** From a job that already has imported correspondence and profile/CV context, the user generates an application package in the workspace, sees drafts that clearly reflect the job plus imported Gmail context, edits and saves those drafts, and reopens the job to find the saved material still there as working output.
S02 directly owns active requirement **R003** and materially supports **R007** because the job workspace needs to behave like a place to prepare real application material, not just preview one-off AI output. The key risk is not missing endpoints; it is that the existing generator in `JobApplicationsController` may still produce generic drafts because it underuses S01 correspondence and saved recruiter/job context. The slice therefore stays backend-first again, then tightens the workspace save/edit loop around the improved contract.
## Must-Haves
- Application-package generation in `JobTrackerApi/Controllers/JobApplicationsController.cs` uses imported correspondence, recruiter/job context, profile CV structure, and attachment context deliberately enough to produce more specific drafts.
- The generated package returns and persists real working material for the job: tailored CV, cover letter, recruiter message, and any supporting package signals the workspace needs to show what was saved.
- The job workspace in `job-tracker-ui/src/components/JobDetailsDialog.tsx` makes generation, editing, and saving feel like one coherent loop instead of disconnected draft widgets.
## Proof Level
- This slice proves: integration
- Real runtime required: yes
- Human/UAT required: yes
## Verification
- `dotnet test JobTrackerApi.Tests/JobTrackerApi.Tests.csproj --filter JobApplicationsApplicationPackageTests`
- `CI=true npm --prefix job-tracker-ui test -- --watch=false --runTestsByPath src/job-details-generated-drafts.test.tsx`
- Manual UAT: open a job with imported correspondence, generate the application package, confirm the drafts mention job/company/correspondence-specific details, save edits in the workspace, reload the job, and verify the saved package material is still present and usable.
## Observability / Diagnostics
- Runtime signals: application-package responses should expose the specific draft artifacts and package signals used by the workspace, while save endpoints should update persisted job fields clearly enough to inspect reload behavior.
- Inspection surfaces: `POST /api/jobapplications/{id}/generate-application-package`, `PUT /api/jobapplications/{id}/tailored-cv`, `PUT /api/jobapplications/{id}/application-drafts`, and the Tailored CV tab in `job-tracker-ui/src/components/JobDetailsDialog.tsx`.
- Failure visibility: backend tests should make empty-context and weak-context failures obvious, while the workspace should distinguish generation failure, unsaved edits, and saved package state.
- Redaction constraints: no raw secrets in AI prompts or logs; correspondence/body context should stay inside application data flows, not new diagnostic logging.
## Integration Closure
- Upstream surfaces consumed: S01 correspondence persistence in `Models/Correspondence.cs`, Gmail-linked workspace rendering in `job-tracker-ui/src/components/Correspondence.tsx`, profile CV state from `JobTrackerApi/Controllers/ProfileCvController.cs`, and the existing package endpoints/UI in `JobTrackerApi/Controllers/JobApplicationsController.cs` and `job-tracker-ui/src/components/JobDetailsDialog.tsx`.
- New wiring introduced in this slice: stronger draft-generation context assembly that consumes imported correspondence, plus clearer persistence/display of saved application package material in the job workspace.
- What remains before the milestone is truly usable end-to-end: S03 still needs to consume the saved package plus imported correspondence for reply/follow-up drafting, and final milestone slices still need full live-loop revalidation.
## Tasks
- [x] **T01: Strengthen application-package context assembly and backend draft tests** `est:4h`
- Why: S02 succeeds or fails on draft quality, so the generator must consume the right job, correspondence, recruiter, attachment, and profile-CV context before the workspace polish matters.
- Files: `JobTrackerApi/Controllers/JobApplicationsController.cs`, `JobTrackerApi.Tests/JobApplicationsApplicationPackageTests.cs`
- Do: Audit `generate-application-package` and related helpers, add deliberate use of imported correspondence and recruiter/job context to the package prompt assembly, keep the no-auto-send boundary intact, and add focused backend tests that prove the returned package reflects stronger job-specific context instead of generic output.
- Verify: `dotnet test JobTrackerApi.Tests/JobTrackerApi.Tests.csproj --filter JobApplicationsApplicationPackageTests`
- Done when: the backend package contract clearly uses imported job context and focused backend tests prove the response contains stronger, job-specific draft material.
- [x] **T02: Make the job workspace save and present the application package as real working material** `est:4h`
- Why: Even a better generator will still feel weak if the workspace treats drafts like disposable previews instead of editable saved material tied to the job.
- Files: `job-tracker-ui/src/components/JobDetailsDialog.tsx`, `job-tracker-ui/src/types.ts`, `job-tracker-ui/src/job-details-generated-drafts.test.tsx`
- Do: Refine the Tailored CV/application package tab so generated artifacts, saved edits, and package state read clearly as one working loop; surface the stronger backend outputs without adding a second draft system; and expand the existing dialog test to prove generation, editing, saving, and reload behavior for the package flow.
- Verify: `CI=true npm --prefix job-tracker-ui test -- --watch=false --runTestsByPath src/job-details-generated-drafts.test.tsx`
- Done when: the workspace generates, edits, saves, and re-displays application package material coherently, and the focused frontend test proves that loop.
## Files Likely Touched
- `JobTrackerApi/Controllers/JobApplicationsController.cs`
- `JobTrackerApi.Tests/JobApplicationsApplicationPackageTests.cs`
- `job-tracker-ui/src/components/JobDetailsDialog.tsx`
- `job-tracker-ui/src/types.ts`
- `job-tracker-ui/src/job-details-generated-drafts.test.tsx`
@@ -0,0 +1,34 @@
---
title: S02 summary
status: done
verification:
- $HOME/.dotnet/dotnet build JobTrackerApi/JobTrackerApi.csproj
- docker run --rm -v "$PWD":/src -w /src mcr.microsoft.com/dotnet/sdk:9.0 bash -lc '...dotnet test /tmp/apptests/AppPkgTests.csproj...'
- CI=true npm --prefix job-tracker-ui test -- --watch=false --runTestsByPath src/job-details-generated-drafts.test.tsx
---
S02 made the application-package flow materially more useful and more trustworthy.
Delivered:
- stronger backend package-context assembly in `JobTrackerApi/Controllers/JobApplicationsController.cs`
- imported correspondence is now part of package generation
- recruiter/job/profile/attachment context is threaded into the package prompts deliberately
- returned key points can include correspondence-derived and attachment-derived signals
- focused backend proof in `JobTrackerApi.Tests/JobApplicationsApplicationPackageTests.cs`
- package generation responds to imported correspondence and recruiter context
- notes-saving behavior for application-answer material replaces rather than appends endlessly
- stronger job workspace loop in `job-tracker-ui/src/components/JobDetailsDialog.tsx`
- saved job material loads back into the Tailored CV tab as the starting workspace state
- generation replaces the working draft for tailored CV, cover letter, application answer, and recruiter message
- save writes the package back as job-tied working material rather than leaving it as a temporary preview
- the UI distinguishes saved state, generated-only state, and unsaved edits
- focused frontend proof in `job-tracker-ui/src/job-details-generated-drafts.test.tsx`
- verifies saved-state load, generation, editing, coherent save payload, and saved-state redisplay behavior
Net effect:
- S01 imported Gmail context now materially improves draft quality instead of sitting unused.
- The job workspace behaves more like a preparation surface the user can trust and reuse later.
- The manual-send boundary remains intact; S02 improved drafting and persistence only.
Remaining milestone gap after S02:
- S03 still needs to turn the imported thread context plus saved package state into strong reply/follow-up drafting.
@@ -0,0 +1,51 @@
---
estimated_steps: 4
estimated_files: 2
skills_used:
- best-practices
- test
---
# T01: Strengthen application-package context assembly and backend draft tests
**Slice:** S02 — Stronger AI application package drafting
**Milestone:** M001
## Description
Make the backend application-package generator use the context S01 now provides. The executor should keep the existing package endpoint, but improve how it builds prompts and selects context so the tailored CV, cover letter, recruiter message, and supporting signals reflect imported correspondence, recruiter/job details, profile CV structure, and attachment context more convincingly.
## Steps
1. Inspect `JobTrackerApi/Controllers/JobApplicationsController.cs` around `generate-application-package` and identify which job, recruiter, correspondence, attachment, and profile-CV signals are already available but underused.
2. Refine the package-context assembly and prompt shape so imported correspondence and recruiter/job-specific details influence the generated drafts directly without weakening the no-auto-send boundary.
3. Add a focused backend test file `JobTrackerApi.Tests/JobApplicationsApplicationPackageTests.cs` that exercises the package endpoint contract with real job/correspondence/profile context and asserts the returned artifacts are specific to that context.
4. Keep the output contract stable unless a change materially improves the workspace; if it changes, make the added fields explicit and limited to what T02 will consume.
## Must-Haves
- [ ] Imported correspondence from S01 is deliberately consumed in package generation instead of remaining disconnected from the draft flow.
- [ ] Backend tests prove package output responds to job-specific context rather than generic fallback behavior.
- [ ] The generator still returns review-only draft material and does not cross the manual-send boundary.
## Verification
- `dotnet test JobTrackerApi.Tests/JobTrackerApi.Tests.csproj --filter JobApplicationsApplicationPackageTests`
- Confirm the focused test covers correspondence-aware package context and expected package artifacts.
## Observability Impact
- Signals added/changed: clearer package-response artifacts and stronger context assembly around job/correspondence/profile inputs.
- How a future agent inspects this: read `JobTrackerApi/Controllers/JobApplicationsController.cs` and `JobTrackerApi.Tests/JobApplicationsApplicationPackageTests.cs`.
- Failure state exposed: focused backend verification should show whether weak drafts come from missing context assembly, empty correspondence state, or prompt/output contract drift.
## Inputs
- `JobTrackerApi/Controllers/JobApplicationsController.cs` — current application-package and related AI draft endpoints.
- `Models/Correspondence.cs` — persisted Gmail-linked correspondence metadata from S01.
- `JobTrackerApi/Controllers/ProfileCvController.cs` — profile CV structure/source-of-truth behavior.
## Expected Output
- `JobTrackerApi/Controllers/JobApplicationsController.cs` — stronger package-generation context and/or response contract.
- `JobTrackerApi.Tests/JobApplicationsApplicationPackageTests.cs` — focused backend proof for context-aware package generation.
@@ -0,0 +1,32 @@
---
title: T01 summary
status: done
files:
- JobTrackerApi/Controllers/JobApplicationsController.cs
- JobTrackerApi.Tests/JobApplicationsApplicationPackageTests.cs
verification:
- $HOME/.dotnet/dotnet build JobTrackerApi/JobTrackerApi.csproj
- docker run --rm -v "$PWD":/src -w /src mcr.microsoft.com/dotnet/sdk:9.0 bash -lc '...dotnet test /tmp/apptests/AppPkgTests.csproj...'
---
Strengthened application-package generation so it now consumes imported correspondence and recruiter/job context instead of relying mostly on job description text plus the profile CV.
What changed:
- `JobTrackerApi/Controllers/JobApplicationsController.cs`
- added `BuildCorrespondenceContextAsync(...)` to gather recent imported correspondence, participants, thread ids, and AI-derived package signals
- enriched `generate-application-package` context with:
- recruiter name/email and greeting baseline
- imported correspondence context from S01
- existing saved job material (tailored CV / cover letter / recruiter message) when present
- job URL in the package context
- updated prompts so tailored CV, cover letter, application answer, recruiter message, and variants all explicitly use imported correspondence when helpful without crossing the manual-send boundary
- expanded `KeyPoints` to include correspondence-derived and attachment-derived signals
- `JobTrackerApi.Tests/JobApplicationsApplicationPackageTests.cs`
- added focused backend proof that package generation reacts to imported correspondence and recruiter context rather than falling back to generic output
Verification:
- Native backend build passed with `$HOME/.dotnet/dotnet build JobTrackerApi/JobTrackerApi.csproj`
- Focused application-package backend test passed in an isolated Docker harness (`1 passed`)
Important caveat:
- As with S01 backend verification, the repositorys broader `JobTrackerApi.Tests` project still has unrelated compile drift, so the focused package test was isolated instead of relying on the full test project.
@@ -0,0 +1,53 @@
---
estimated_steps: 4
estimated_files: 3
skills_used:
- react-best-practices
- test
---
# T02: Make the job workspace save and present the application package as real working material
**Slice:** S02 — Stronger AI application package drafting
**Milestone:** M001
## Description
Turn the Tailored CV/application package area into a coherent working loop. The workspace should make it obvious what was generated, what was edited, what was saved to the job, and what can be reused later, instead of feeling like a temporary AI preview pane.
## Steps
1. Update `job-tracker-ui/src/types.ts` if T01 changes the package contract or exposes stronger saved draft/package state.
2. Refine `job-tracker-ui/src/components/JobDetailsDialog.tsx` so generation, editing, saving, and redisplay of application package material feel like one continuous workflow tied to the job.
3. Expand `job-tracker-ui/src/job-details-generated-drafts.test.tsx` to prove the stronger package flow: generate with contextual outputs, edit/save the important draft artifacts, and verify the saved material is reflected back in the dialog state.
4. Keep the UI focused on working material already tied to the job; do not introduce a second competing draft surface or outbound automation.
## Must-Haves
- [ ] The Tailored CV tab clearly presents generated package artifacts as editable, savable job material rather than disposable previews.
- [ ] Saved package edits update dialog state in a way the user can trust and later slices can reuse.
- [ ] The focused React test proves generation and save behavior for the package loop.
## Verification
- `CI=true npm --prefix job-tracker-ui test -- --watch=false --runTestsByPath src/job-details-generated-drafts.test.tsx`
- Confirm the expanded test proves generation, editing, and save-state behavior in the dialog.
## Observability Impact
- Signals added/changed: clearer UI state around generated vs saved package material and stronger test coverage for package-loop regressions.
- How a future agent inspects this: open the Tailored CV tab in `job-tracker-ui/src/components/JobDetailsDialog.tsx` and read `job-tracker-ui/src/job-details-generated-drafts.test.tsx`.
- Failure state exposed: the workspace and test should distinguish generation failure, unsaved edits, and saved package state instead of collapsing them into generic draft text.
## Inputs
- `job-tracker-ui/src/components/JobDetailsDialog.tsx` — existing package-generation and save UI.
- `job-tracker-ui/src/types.ts` — frontend package contracts.
- `JobTrackerApi/Controllers/JobApplicationsController.cs` — T01 package-generation contract.
- `job-tracker-ui/src/job-details-generated-drafts.test.tsx` — current focused dialog test.
## Expected Output
- `job-tracker-ui/src/components/JobDetailsDialog.tsx` — stronger package generation/edit/save flow.
- `job-tracker-ui/src/types.ts` — aligned package contract for the workspace.
- `job-tracker-ui/src/job-details-generated-drafts.test.tsx` — focused frontend proof for the improved package loop.
@@ -0,0 +1,36 @@
---
title: T02 summary
status: done
files:
- job-tracker-ui/src/components/JobDetailsDialog.tsx
- job-tracker-ui/src/job-details-generated-drafts.test.tsx
verification:
- CI=true npm --prefix job-tracker-ui test -- --watch=false --runTestsByPath src/job-details-generated-drafts.test.tsx
- $HOME/.dotnet/dotnet build JobTrackerApi/JobTrackerApi.csproj
- docker run --rm -v "$PWD":/src -w /src mcr.microsoft.com/dotnet/sdk:9.0 bash -lc '...dotnet test /tmp/apptests/AppPkgTests.csproj...'
---
Turned the Tailored CV tab into a real package workspace instead of a one-shot draft preview.
What changed:
- `job-tracker-ui/src/components/JobDetailsDialog.tsx`
- added package workspace state for cover letter, application answer, and recruiter message alongside the tailored CV
- initialized that workspace from saved job material so reopening the dialog shows the last trusted copy, not just blank/generated state
- generation now replaces the editable working copy for all package artifacts, not only the tailored CV
- added package-level save flow that writes the tailored CV plus draft artifacts back to the job together
- added explicit saved/generated/unsaved status chips so the user can tell what is persisted versus still in the working draft
- added reset-to-saved behavior so the workspace can recover from unwanted edits
- normalized application-answer persistence into a replaceable notes block instead of endlessly appending
- `job-tracker-ui/src/job-details-generated-drafts.test.tsx`
- expanded the focused dialog test to prove saved material loads into the workspace, generation replaces the working copy, edits can be saved, and the save payload reflects the coherent package state
Backend support tightened during T02:
- `JobTrackerApi/Controllers/JobApplicationsController.cs`
- `SaveApplicationDrafts` now replaces `Notes` when notes are provided, which makes the saved application-answer loop trustworthy instead of append-only
- `JobTrackerApi.Tests/JobApplicationsApplicationPackageTests.cs`
- added focused proof that notes replacement no longer appends indefinitely
Verification:
- Frontend focused test passed: `CI=true npm --prefix job-tracker-ui test -- --watch=false --runTestsByPath src/job-details-generated-drafts.test.tsx`
- Backend host build passed: `$HOME/.dotnet/dotnet build JobTrackerApi/JobTrackerApi.csproj`
- Focused backend package tests passed in isolated Docker harness (`2 passed`)