Skip to content

Run 2: Lifecycle Framework

Introduces the minimal lifecycle framework types (FieldError, ValidationResult, Validator<T>, EditPhase, EditLifecycleCallbacks<T>, EditableComponentProps<T>), the setNestedField utility, and the useDraft<T> hook into ux-prototype. Also creates the authoritative Edit Lifecycle architecture documentation in the documentation repository. Corresponds to specification.md.

Author: Claude Code for jmpicnic | Date: 2026-04-07 | Status: Planning

Implement the minimal lifecycle framework as the foundation for Phase 3.3 component updates. Scope is intentionally minimal per FD-03: only the types and hooks needed by the image upload components. The full framework (useComposedDraft<T>, createCellEditorFactory, EditablePanel<T>) is deferred to ux-prototype#77.

#CriterionVerification CommandExpected Output
1Run 1 exit gate passednpm view @arda-cards/api-proxy versions --registry=https://npm.pkg.github.comNew version present
2ux-prototype worktree on correct branchgit -C /Users/jmp/code/arda/projects/image-upload-frontend-worktrees/ux-prototype branch --show-currentjmpicnic/image-upload-frontend
3documentation worktree on correct branchgit -C /Users/jmp/code/arda/projects/image-upload-frontend-worktrees/documentation branch --show-currentjmpicnic/image-upload-frontend
4Existing ux-prototype checks passmake -C /Users/jmp/code/arda/projects/image-upload-frontend-worktrees/ux-prototype checkExit 0
5Existing ux-prototype tests passmake -C /Users/jmp/code/arda/projects/image-upload-frontend-worktrees/ux-prototype testExit 0
6Existing ux-prototype build passesmake -C /Users/jmp/code/arda/projects/image-upload-frontend-worktrees/ux-prototype buildExit 0
#TaskPersonaDepends OnStatusAcceptance Criteria
2.1Create Edit Lifecycle architecture documentation in documentation worktreefront-end-engineerPendingedit-lifecycle.md (and splits if > 300 lines) published to current-system/architecture/user-interaction/; state machine, activity, validation model, type catalog, hook reference, composition diagrams present; make pr-checks passes
2.2Create lifecycle types file src/types/canary/utilities/edit-lifecycle.tsfront-end-engineerPendingAll 6 types (FieldError, ValidationResult, Validator<T>, EditPhase, EditLifecycleCallbacks<T>, EditableComponentProps<T>) defined and exported; type-level unit tests (8+ cases) in edit-lifecycle.test.ts pass
2.3Create setNestedField utility src/types/canary/utilities/set-nested-field.tsfront-end-engineerPending8 unit test cases pass: shallow path, nested path, deep path, creates intermediates, no mutation, preserves siblings, single segment, sibling field preservation
2.4Implement useDraft<T> hook src/types/canary/utilities/use-draft.tsfront-end-engineer2.2, 2.3Pending15+ unit test cases pass covering: initial state, update(), function updater, updateField(), confirm() valid/invalid, cancel(), reset(), initialValue change, isEqual option, contextErrors merge, errorsFor() filtering, warning severity
2.5Export types and hook from canary barrelfront-end-engineer2.2, 2.3, 2.4PendinguseDraft importable from @arda-cards/design-system/canary; lifecycle types importable from @arda-cards/design-system/types/canary; setNestedField exported from canary barrel
2.6Full checks (ux-prototype)front-end-engineer2.5Pendingmake check, make test, make build all exit 0; new tests included in counts
2.7Documentation checks and commitfront-end-engineer2.1, 2.6Pendingmake pr-checks passes in documentation worktree; documentation changes committed referencing Phase 3.2

Two worktrees are active in this run:

WorktreePurpose
/Users/jmp/code/arda/projects/image-upload-frontend-worktrees/ux-prototypeImplementation (T-2 through T-6)
/Users/jmp/code/arda/projects/image-upload-frontend-worktrees/documentationArchitecture documentation (T-1) and final commit (T-7)

T-1 (architecture documentation) and T-2/T-3 (types and utility) are independent and could proceed in parallel within a single session. In practice, a single agent handles them sequentially — T-1 before T-2, since the documentation work clarifies the type contracts.

Single agent executes all tasks sequentially. T-2 and T-3 are independent new files but the sequential cost is minimal. T-4 depends on both.

2.1 (architecture docs — documentation worktree)
2.2 (lifecycle types) ─┐
2.3 (setNestedField) ─┤→ 2.4 (useDraft<T>) → 2.5 (barrel exports) → 2.6 (full checks) → 2.7 (docs commit)

Single agent; no idle time.

PersonaAgent NameTasks AssignedWorking DirectorySpawn Order
front-end-engineerfe-lifecycle2.1 through 2.7ux-prototype + documentation worktreesFirst
ArtifactPath (relative to ux-prototype worktree)FormatDescription
FieldError typesrc/types/canary/utilities/edit-lifecycle.tsTypeScriptfield, message, optional code, severity
ValidationResult typesrc/types/canary/utilities/edit-lifecycle.tsTypeScriptvalid: boolean, errors: FieldError[]
Validator<T> typesrc/types/canary/utilities/edit-lifecycle.tsTypeScript(value: T) => ValidationResult
EditPhase typesrc/types/canary/utilities/edit-lifecycle.tsTypeScript'idle' | 'editing' | 'confirming' | 'error'
EditLifecycleCallbacks<T> interfacesrc/types/canary/utilities/edit-lifecycle.tsTypeScriptOptional onChange, onConfirm, onCancel
EditableComponentProps<T> interfacesrc/types/canary/utilities/edit-lifecycle.tsTypeScriptExtends EditLifecycleCallbacks<T>; adds initialValue, contextErrors?, disabled?
Lifecycle types unit testssrc/types/canary/utilities/edit-lifecycle.test.tsTypeScript/Vitest8+ expectTypeOf structural tests
setNestedField utilitysrc/types/canary/utilities/set-nested-field.tsTypeScriptPure dot-path update, no mutation, shallow copy per level
setNestedField unit testssrc/types/canary/utilities/set-nested-field.test.tsTypeScript/Vitest8 test cases
useDraft<T> hooksrc/types/canary/utilities/use-draft.tsTypeScript/ReactFull state machine for edit lifecycle
useDraft<T> unit testssrc/types/canary/utilities/use-draft.test.tsTypeScript/Vitest15+ test cases using renderHook + act
ArtifactPath (relative to documentation worktree)FormatDescription
Edit Lifecycle docsrc/content/docs/current-system/architecture/user-interaction/edit-lifecycle/index.mdMarkdownOverview, state machine, activity diagram, validation model
Edit Lifecycle types docsrc/content/docs/current-system/architecture/user-interaction/edit-lifecycle/types.mdMarkdownType catalog, useDraft<T> hook reference
Edit Lifecycle composition docsrc/content/docs/current-system/architecture/user-interaction/edit-lifecycle/composition.mdMarkdownHierarchical composition, FD-01 relationship
2.1 (architecture docs — documentation worktree, independent)
2.2 (lifecycle types) ─┐
├──→ 2.4 (useDraft<T>) → 2.5 (barrel exports) → 2.6 (checks) → 2.7 (docs commit)
2.3 (setNestedField) ──┘
#CriterionVerification CommandExpected Output
1Architecture docs present in documentation worktreels /Users/jmp/code/arda/projects/image-upload-frontend-worktrees/documentation/src/content/docs/current-system/architecture/user-interaction/edit-lifecycle.md present (and splits if applicable)
2ValidationResult, FieldError, and all 6 types exportednpm --prefix <ux-worktree> run typecheckExit 0
3setNestedField unit tests passnpm --prefix <ux-worktree> run test -- --reporter=verbose 2>&1 | grep "set-nested-field"8 tests PASS
4useDraft<T> unit tests passnpm --prefix <ux-worktree> run test -- --reporter=verbose 2>&1 | grep "use-draft"15+ tests PASS
5Lifecycle type tests passnpm --prefix <ux-worktree> run test -- --reporter=verbose 2>&1 | grep "edit-lifecycle"8+ tests PASS
6useDraft importable from canary barrelnpm --prefix <ux-worktree> run typecheckExit 0 (import compiles)
7Full checks passmake -C <ux-worktree> check && make -C <ux-worktree> test && make -C <ux-worktree> buildAll exit 0
8No existing test regressionsnpm --prefix <ux-worktree> run testSame or greater test count as entry; all existing tests PASS
9Documentation make pr-checks passesmake -C /Users/jmp/code/arda/projects/image-upload-frontend-worktrees/documentation pr-checksExit 0
10Documentation changes committedgit -C /Users/jmp/code/arda/projects/image-upload-frontend-worktrees/documentation status --porcelainEmpty (committed)

Where <ux-worktree> = /Users/jmp/code/arda/projects/image-upload-frontend-worktrees/ux-prototype.

Primary working directory: /Users/jmp/code/arda/projects/image-upload-frontend-worktrees/ux-prototype Secondary working directory: /Users/jmp/code/arda/projects/image-upload-frontend-worktrees/documentation Use absolute paths for all tool calls.

Implement Phase 3.2 of the item image upload frontend project: specification.md.

Load skills: ui-component, unit-tests-frontend, document-writing, path-conventions, plantuml-diagrams.

T-1 (architecture documentation): Write authoritative reference docs in the documentation worktree. Use source material from the architectural exploration docs in 3-frontend-implementation/architectural-exploration/ but write for an engineer who hasn’t seen those documents. Split into multiple files if the main file exceeds 300 lines. Use PlantUML for all diagrams (state machine, activity, class, composition).

T-2/T-3: edit-lifecycle.ts and set-nested-field.ts are new files in src/types/canary/utilities/. They are independent of each other.

T-4 (useDraft<T>): Implement the full state machine per the specification interface. Key behaviors: Object.is equality for initialValue by default (callers must memoize); isEqual option for structural equality; errorsFor() prefix matching (not substring).

Key decisions: FD-03 (minimal scope), FD-14 (isEqual parameter). Location of useDraft: src/types/canary/utilities/ (decided: alongside types it depends on). Spread strategy: shallow per level (decided: React best practices, retains referential identity for siblings).

For T-7, run make pr-checks in the documentation worktree and commit any documentation changes including byproducts for Phase 3.2.

ArtifactProducer RunPath
Run 1 exit gate passedRun 1Implicit (entry criterion)
ArtifactConsumer RunPath
FieldError, ValidationResult, Validator<T>, EditPhase, EditLifecycleCallbacks<T>, EditableComponentProps<T>Run 3asrc/types/canary/utilities/edit-lifecycle.ts
setNestedField utilityRun 3asrc/types/canary/utilities/set-nested-field.ts
useDraft<T> hookRun 3asrc/types/canary/utilities/use-draft.ts
Edit Lifecycle architecture docsAll engineersdocumentation/src/content/docs/current-system/architecture/user-interaction/

STOP: Review architecture documentation, lifecycle types, and useDraft<T> implementation before proceeding to Run 3a (component updates).

#QuestionOptionsRecommendationDecision
1Location of useDraft: utilities/ vs. hooks/A: utilities/ (colocate), B: src/hooks/canary/ADecided: A
2updateField deep clone strategyA: shallow spread per level, B: structuredClone, C: immerADecided: A — shallow spread; siblings retain referential identity
3Architecture doc: single file or split?A: single edit-lifecycle.md, B: split by concernSplit if > 300 linesDeferred to implementation
  • Edit Lifecycle architecture documentation published with all required sections and diagrams
  • All 6 lifecycle types exported from src/types/canary/utilities/edit-lifecycle.ts
  • setNestedField utility passes 8 unit test cases
  • useDraft<T> hook passes 15+ unit test cases
  • useDraft importable from @arda-cards/design-system/canary
  • make check, make test, make build all pass in ux-prototype
  • No existing test regressions
  • Documentation make pr-checks passes; changes committed
Risk / BlockerImpactMitigation
useDraft<T> state machine complexity causes test failuresMedium — rework requiredWrite tests before implementation (TDD); test each state transition independently
PlantUML diagram syntax errors block documentation buildLow — documentation onlyUse plantuml-diagrams skill conventions; validate via make pr-checks
Canary barrel export conflicts with existing exportsLow — typecheck catchesRun make check after T-5 before moving to T-6
FileDescription
changelog.mdSummary of types, hook, and documentation changes in Run 2
learnings.mdObservations about React hook testing patterns, Vitest expectTypeOf
suggestions.mdImprovement suggestions, deferred framework items

The team’s TaskList is the single source of truth for task status. Follow the protocol at every phase boundary per the team-lead agent definition.

DateEventNotes
2026-04-07Plan created

Copyright: (c) Arda Systems 2025-2026, All rights reserved