From 71b462d579c2a007ffaa0597a9cec5350903be79 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 21 Jul 2026 11:25:01 +0000 Subject: [PATCH] Revamp 5.3: Approval workflow + attribution in versioning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Complete Milestone 5 (roles & workflow → web v2 launch candidate). - ProjectVersion gains authorId (the shared profile.identity id used by marks/comments/presence — attribution unified) + approval metadata. - versionRepo.capture stamps authorId on every version; new versionRepo.signOff records a labeled "Approved by {name}" version with approval {authorId, authorName, at}. - useWorkflowStore.useCanReview gates a Sign off button in VersionHistoryPanel (revisor/PM; local-only = PM-of-self); approval versions render with an accent BadgeCheck. - Tests: every capture stamps a stable authorId; signOff records the approval milestone while a plain saveNamed does not. No migration (versions are local Dexie; the new fields are additive). Green: 673 unit (+2) / version e2e / typecheck / build (flag-off Supabase-free). Milestone 5 complete. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_015AEnTYBecWG64R3iP8GBiE --- docs/revamp/ROADMAP.md | 2 +- docs/revamp/STATUS.md | 5 +- src/core/types/index.ts | 11 +++ .../editor/history/VersionHistoryPanel.tsx | 68 ++++++++++++++---- .../editor/workflow/useWorkflowStore.ts | 5 ++ src/storage/repositories/versionRepo.ts | Bin 9344 -> 10161 bytes tests/unit/versionRepo.test.ts | 23 ++++++ 7 files changed, 97 insertions(+), 17 deletions(-) diff --git a/docs/revamp/ROADMAP.md b/docs/revamp/ROADMAP.md index a058021..2aa3b04 100644 --- a/docs/revamp/ROADMAP.md +++ b/docs/revamp/ROADMAP.md @@ -84,7 +84,7 @@ Roadmap, status checklist, prompt pack, and vision docs committed to the repo. ### Milestone 5 — Roles & workflow - **5.1 Members & roles management — M — deps: 4.1.** `cloud/members.ts` (invite by email via profiles lookup, change role, remove), `MembersPanel`, `0006_member_policies.sql` (PM-only member writes; trigger keeps ≥1 PM). **DoD**: PM invites translator + revisor; non-PM read-only; server rejects non-PM writes. *Shipped as `0008_member_policies.sql` (0006/0007 taken) + `cloud/members.ts` + a `ManageMembersDialog` on the project card (lazy-loaded) instead of a sidebar `MembersPanel`; invite resolves the email inside the SECURITY DEFINER `invite_member` RPC (PM-checked, no enumeration surface) rather than a client-side profiles lookup; `profiles.email` + a co-member SELECT policy added; a `enforce_min_one_pm` trigger guards the last manager.* - **5.2 Role-gated editing workflow — M — deps: 5.1, 1.6.** Pure `core/workflow/rules.ts`: `(role, stage, status) → {canEditDirect, mustSuggest, canResolveChanges, canReview, canManage}`; `projects.stage (translation|review|final)` + `deadline` (`0007_workflow.sql`, PM-only update). Translator in review stage is forced into suggesting (toggle disabled); accept/reject visible only to revisor/PM; local-only projects = PM-of-self (all permissive, zero regression). **DoD**: full role matrix works; local-only unchanged. *Shipped: pure `core/workflow/rules.ts` + `useWorkflowStore` gating (forced-suggest toggle, reviewer-only accept/reject in `ChangesPanel`/`ChangeHoverCard`), `0009_workflow.sql` (`project_stage` + `deadline`, PM-only via existing `projects_update`), `Project.cloud.stage` read on open + `changeProjectStage`, and a PM stage selector in `ManageMembersDialog`.* -- **5.3 Approval + attribution in versioning — S — deps: 5.2.** `ProjectVersion.authorId?/approval?`; revisor/PM "Sign off" creates a labeled approval version; one stable author identity across marks, comments, versions, presence. **DoD**: sign-off flow; attribution unified. *Milestone 5 = roles shipped → **web v2 launch candidate**.* +- **5.3 Approval + attribution in versioning — S — deps: 5.2.** `ProjectVersion.authorId?/approval?`; revisor/PM "Sign off" creates a labeled approval version; one stable author identity across marks, comments, versions, presence. **DoD**: sign-off flow; attribution unified. *Milestone 5 = roles shipped → **web v2 launch candidate**.* *Shipped: `ProjectVersion.authorId`/`approval`; `versionRepo` stamps `authorId` (the shared `ensureLocalAuthor` identity) on every capture + a `signOff()` that records a labeled approval version; `useCanReview` gates a **Sign off** button in `VersionHistoryPanel`, which badges approval versions. No migration (versions are local Dexie). **Milestone 5 complete.*** ### Milestone 6 — Extensions & connectors - **6.1 Extension registry + MT providers as built-in addons — M — deps: 0.1.** `core/extensions/types.ts` (`ExtensionManifest {id, name, version, kinds, permissions, builtIn}`; kinds: `mt-provider|qa-rule|panel|import-format|export-format|storage-connector`), `registry.ts` (enablement persisted in settings), `builtins.ts`; `src/extensions/mt/*` manifest wrappers delegating to existing `src/core/mt/*` (no logic moves); `mt/index.ts` resolves via registry. Existing MT tests untouched prove behavior preservation. **DoD**: four MT providers run through registry; disabling removes from panel. diff --git a/docs/revamp/STATUS.md b/docs/revamp/STATUS.md index 49f8464..c65f934 100644 --- a/docs/revamp/STATUS.md +++ b/docs/revamp/STATUS.md @@ -34,8 +34,8 @@ Rules for autonomous sessions: | 4.4 | Live collab UX: cursors, leases, attribution | M | 4.3, 1.6 | done (PR #58) | | 4.4.1 | Remote caret overlay (live cursors, deferred from 4.4) | S | 4.4 | done (PR #59) | | 5.1 | Members & roles management | M | 4.1 | done (PR #60) | -| 5.2 | Role-gated editing workflow | M | 5.1, 1.6 | in-review (PR #61) | -| 5.3 | Approval workflow + attribution in versioning | S | 5.2 | pending | +| 5.2 | Role-gated editing workflow | M | 5.1, 1.6 | done (PR #61) | +| 5.3 | Approval workflow + attribution in versioning | S | 5.2 | in-review (PR #62) | | 6.1 | Extension registry + MT providers as built-in addons | M | 0.1 | pending | | 6.2 | QA rules + formats as addons + Add-ons page | M | 6.1 | pending | | 6.3 | Google Drive connector | M | 6.1, 2.4 | pending | @@ -77,3 +77,4 @@ Rules for autonomous sessions: - 2026-07-20 — Phase 4.4 merged in PR #58. Phase 4.4.1 built: the live remote-caret overlay deferred from 4.4 (**Milestone 4 fully complete**). `src/core/spell/offsets.ts` gains pure `mapOffsetToNode(spans, offset)` — the caret counterpart to `mapTokenToNode`, resolving a plain-text offset to a text node + local offset (a text/text boundary snaps to the earlier node's end; a tag boundary or past-the-end returns null → the overlay skips that frame). `src/features/editor/rich/richOffsets.ts` — `selectionToCaretRange(selection)` converts a live Lexical selection to plain anchor/focus offsets and `buildLeafSpans(paragraph)` produces the ordered leaf spans, both reproducing exactly the plain projection `richStateToPlain` derives (a tag contributes `{id}`, a **delete change-mark projects to '' and its subtree is skipped**) so a caret one peer reports lands on the same character in another peer's editor. `RemoteCaretOverlay.tsx` (a Lexical plugin mounted in `RichSegmentEditor` beside the spell overlay) paints a coloured caret + name label for each remote peer whose presence puts them on the segment with a caret, measured via `getElementByKey`+DOM range like `SpellUnderlinePlugin` — it never mutates the node tree and every measurement is guarded (renders nothing on failure). Reporting: the **focused** segment's editor (the only one given `onCaret`) computes `selectionToCaretRange` in its update listener and reports it through `EditorPage`→`useProjectSync`→`setActiveSegment(id, caret)`, throttled to one send per 100ms; `useProjectSync.setActiveSegment` now forwards the caret. Deviations (noted): built on the designated session branch, not `claude/revamp-phase-4-4-1`. Tests: `spell.offsets` extended (`mapOffsetToNode`: inside/boundary/after-tag/end/out-of-range), `richOffsets` (headless: caret offsets + leaf spans agree with the plain projection for text+tag, and a **delete change-mark projects to nothing** so a caret past it collapses correctly), and e2e `lan-collaboration.spec.ts` extended (**a peer's caret renders as a live remote cursor in the other tab**). Green: 653 unit (+8) / 29 e2e (+1) / build (flag-off zero `GoTrueClient`; the overlay is local-capable and ships in the entry, no Supabase). **Milestone 4 (cloud projects + real-time collaboration) complete.** - 2026-07-20 — Phase 4.4.1 merged in PR #59. Phase 5.1 built: members & roles management (start of **Milestone 5**, roles & workflow). `supabase/migrations/0008_member_policies.sql` — adds `profiles.email` (backfilled from `auth.users` + seeded on signup) and a co-member `profiles` SELECT policy via a new `private.shares_project(other)` SECURITY DEFINER helper (the "broader read for member lookup" 0001 deferred to 5.1); switches `project_members` **update/delete to project_manager-only** (`private.has_project_role`), keeping `insert` reachable by the owner's publish self-seed OR a PM; a `enforce_min_one_pm` BEFORE UPDATE/DELETE trigger that blocks removing/demoting a project's **last** manager; and the `invite_member(project_id, email, role)` RPC (SECURITY DEFINER, PM-checked) that resolves the email → user id and upserts membership, returning NULL when no account matches (no id/email enumeration surface). Numbering deviation: ROADMAP §5.1 sketched `0006_member_policies.sql`, but `0006`/`0007` were taken (4.1 helpers + 4.3 compaction), so it ships as `0008`; and invite resolves the email **inside** the RPC rather than a client-side profiles lookup, keeping it server-side. `src/storage/cloud/members.ts` — pure client-injected `listMembers` (joins the roster to profiles for names/emails, marks self, sorts managers first), `inviteMember` (RPC → `{status:'invited'|'not_found'}`), `changeMemberRole`/`removeMember` (direct writes gated by PM-only RLS + the trigger, surfaced as thrown errors). UI: `features/projects/cloud/ManageMembersDialog.tsx` (roster; a PM gets an invite-by-email form + per-member role `` (+ read-only badge for non-PMs) lives in `ManageMembersDialog`. Deviations (noted): built on the designated session branch, not `claude/revamp-phase-5-2`; content-level rules are client-enforced per D8 (the append-only authored log is the audit trail), stated honestly. `docs/cloud.md` (§3 migration list + §12 manual role-matrix). Tests: `workflow.rules` (full role × stage × status matrix incl. reviewed-segment suggest, final lock, local-only PM-of-self, `forcesSuggesting`), `cloud.projectCloud` extended (stage read defaults to translation + `setCloudProjectStage` update). Verified: flag-OFF `dist` has **zero** `GoTrueClient`; the tracked-changes e2e still green (local-only = PM keeps accept/reject). Green: 671 unit (+10) / 8 tracked-changes e2e / build. No new e2e (ROADMAP §5.2 asks none; the full role matrix needs three real accounts, per the §12 manual matrix). +- 2026-07-21 — Phase 5.2 merged in PR #61. Phase 5.3 built: approval workflow + unified attribution in versioning (**Milestone 5 complete → web v2 launch candidate**). `ProjectVersion` gains `authorId?` (the stable `profile.identity` author id — the *same* identity tracked-change marks, comments, and presence use, so attribution is unified across the app, D8) and `approval?: { authorId, authorName, at }`. `versionRepo.capture` now stamps `authorId` on **every** version (via `ensureLocalAuthor()`), and a new `versionRepo.signOff(projectId, liveDoc?)` records a `named` version labeled `Approved by {name}` with the `approval` metadata set (its presence marks an approval milestone). Wiring: `useWorkflowStore` gains a `useCanReview()` selector (revisor/PM; local-only → PM-of-self → true); `VersionHistoryPanel` shows a **Sign off** button beside Save version only when `canReview`, and renders approval versions with an accent `BadgeCheck` + their `Approved by …` label. No migration + no schema bump (versions are local Dexie; `authorId`/`approval` are additive unindexed fields; pre-5.3 rows simply lack them). Deviations (noted): built on the designated session branch, not `claude/revamp-phase-5-3`; sign-off gating is client-enforced via the workflow rules at the call site (D8) — the append-only authored update log remains the tamper-evident audit trail. Tests: `versionRepo` extended (every capture stamps a stable authorId consistent across captures; `signOff` records a labeled approval version whose `approval.authorId`/`at` match the version's `authorId`/`createdAt`, while a plain `saveNamed` has no `approval`). Verified: flag-OFF `dist` has **zero** `GoTrueClient`; the version-history e2e still green. Green: 673 unit (+2) / 1 version e2e / build. No new e2e (ROADMAP §5.3 asks none). **Milestone 5 (roles & workflow) complete — the web v2 launch candidate.** diff --git a/src/core/types/index.ts b/src/core/types/index.ts index 08cc352..93fd637 100644 --- a/src/core/types/index.ts +++ b/src/core/types/index.ts @@ -151,6 +151,17 @@ export interface ProjectVersion { segmentCount: number /** Display name of the local identity that captured the version, if set. */ author?: string + /** + * Stable author id (from `profile.identity`) that captured the version — the + * same identity used by tracked-change marks, comments, and presence, so + * attribution is unified across the app (ROADMAP §5.3, D8). + */ + authorId?: string + /** + * Set on a revisor/PM **sign-off** version: who approved the project and when. + * Its presence marks the version as an approval milestone in the timeline. + */ + approval?: { authorId: string; authorName: string; at: string } createdAt: string } diff --git a/src/features/editor/history/VersionHistoryPanel.tsx b/src/features/editor/history/VersionHistoryPanel.tsx index 0e80ea9..ad09532 100644 --- a/src/features/editor/history/VersionHistoryPanel.tsx +++ b/src/features/editor/history/VersionHistoryPanel.tsx @@ -1,8 +1,9 @@ import { useState } from 'react' import { useLiveQuery } from 'dexie-react-hooks' -import { History, RotateCcw, Save } from 'lucide-react' +import { History, RotateCcw, Save, BadgeCheck } from 'lucide-react' import { Button } from '@/components/ui/button' import { versionRepo } from '@/storage/repositories/versionRepo' +import { useCanReview } from '../workflow/useWorkflowStore' import { relativeTime } from './relativeTime' interface VersionHistoryPanelProps { @@ -19,8 +20,12 @@ export function VersionHistoryPanel({ projectId }: VersionHistoryPanelProps) { const versions = useLiveQuery(() => versionRepo.listByProject(projectId), [projectId]) const [label, setLabel] = useState('') const [saving, setSaving] = useState(false) + const [signingOff, setSigningOff] = useState(false) const [confirmId, setConfirmId] = useState(null) const [restoringId, setRestoringId] = useState(null) + // Sign-off is a review action — revisor / project_manager only (§5.3). A + // local-only project resolves to PM-of-self, so it's always available there. + const canReview = useCanReview() async function handleSave() { setSaving(true) @@ -32,6 +37,15 @@ export function VersionHistoryPanel({ projectId }: VersionHistoryPanelProps) { } } + async function handleSignOff() { + setSigningOff(true) + try { + await versionRepo.signOff(projectId) + } finally { + setSigningOff(false) + } + } + async function handleRestore(id: string) { setRestoringId(id) try { @@ -61,17 +75,35 @@ export function VersionHistoryPanel({ projectId }: VersionHistoryPanelProps) { className="rounded-md border px-2 py-1.5 text-sm bg-transparent" style={{ borderColor: 'var(--color-border)', color: 'var(--color-text)' }} /> - +
+ + {canReview && ( + + )} +
{!versions || versions.length === 0 ? ( @@ -96,9 +128,17 @@ export function VersionHistoryPanel({ projectId }: VersionHistoryPanelProps) { >
+ {v.approval && } {v.label || (v.kind === 'auto' ? 'Auto-saved' : 'Untitled version')} forcesSuggesting(s.role, s.stage)) } + +/** Whether the current role may perform review actions incl. sign-off (revisor / PM). */ +export function useCanReview(): boolean { + return useWorkflowStore((s) => workflowCapabilities(s.role, s.stage, 'translated').canReview) +} diff --git a/src/storage/repositories/versionRepo.ts b/src/storage/repositories/versionRepo.ts index 9c2950c9f7252ef1a89ad56dbe46e93e46d43286..d3f8d2cf0e2e9f74531d736b2acbd167da0814ed 100644 GIT binary patch delta 747 zcmZ{i(P|Sx6o!c)(n#w?E<~aFQv{PWCW`bXMI;iCpf#oS!aFnBJ=+~RI}>JRvxE}j zJM2SvsggJF4SWH?7ZJ~H+XPW>hFSJM=Y0S9=i~6}=!>c~+92&ROK(glR6p~Hu`5;k zexm_6d8$WojOU1ja@4LDPj>c-4_lv?-7elG1Se8HyqGA0j7WRw=kST}5Z+rk$viov z!k)P{LX)Pf;G579rj{J(kkI`0X}|NV)v1FO+IgHqR1m|6mDTNSIc32VA{Ww^xCejo zHe2iJ(30>J^*zfqh1(tkl$emB2xHCm zqA_M*nI{I1kSC;D?P|Gfs?><(r3<7|k@H4#D4OG- zi(X!)q@<<}UI|~;RGm^WuS|nMTab>|8yg!k7^ld!;8&qo;R!P-Hr;Y#&theA*o=oA z@DI7?V6>XUQfO@CAbpuCf-awzPpSBE>uzy>=jHxY%7173k7&UyeP(rWZ+kZw_bZzW gIGN+Y`R0i%#%(A$qk#$A@HV63=Wb*5e!F@5H}1{+SpWb4 delta 72 zcmdn!-{83+hjDW~<3;w#$($D#f97JG?8n2YXr+*sTCU)dSdyxtsaKNk8SEciQk0pO cuA!;JrJzvDr7(G;r10iK9$u!+odO!-0G*&0C;$Ke diff --git a/tests/unit/versionRepo.test.ts b/tests/unit/versionRepo.test.ts index 5c0ae5c..384967f 100644 --- a/tests/unit/versionRepo.test.ts +++ b/tests/unit/versionRepo.test.ts @@ -87,6 +87,29 @@ describe('versionRepo', () => { expect(seg?.targetRich).toBeUndefined() }) + it('stamps a stable authorId on every capture (unified attribution, §5.3)', async () => { + await segmentRepo.bulkCreate([makeSeg({ id: 's1', target: 'x' })]) + const v1 = await versionRepo.saveNamed('p1', 'v1', doc) + const v2 = await versionRepo.saveNamed('p1', 'v2', doc) + expect(v1!.authorId).toBeTruthy() + // Same local identity across captures (the id marks/comments/presence use). + expect(v2!.authorId).toBe(v1!.authorId) + }) + + it('signOff records a labeled approval version stamped with the signer (§5.3)', async () => { + await segmentRepo.bulkCreate([makeSeg({ id: 's1', target: 'x', status: 'translated' })]) + const v = await versionRepo.signOff('p1', doc) + expect(v!.kind).toBe('named') + expect(v!.label).toMatch(/Approved by/) + expect(v!.approval).toBeTruthy() + expect(v!.approval!.authorId).toBe(v!.authorId) + expect(v!.approval!.at).toBe(v!.createdAt) + + // A plain named version carries no approval. + const plain = await versionRepo.saveNamed('p1', 'plain', doc) + expect(plain!.approval).toBeUndefined() + }) + it('maybeAutoSnapshot throttles to one per window', async () => { await segmentRepo.bulkCreate([makeSeg({ id: 's1' })]) const first = await versionRepo.maybeAutoSnapshot('p1', doc)