Skip to content
This repository was archived by the owner on Sep 2, 2026. It is now read-only.

[Spec #22] Stage derivation engine - #57

Merged
64ix merged 12 commits into
mainfrom
spec/22-stage-derivation
Aug 24, 2026
Merged

64ix merged 12 commits into
mainfrom
spec/22-stage-derivation

Conversation

@64ix

@64ix 64ix commented Aug 23, 2026 •

Copy link
Copy Markdown
Owner
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1222 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1219
Prod 23 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​633 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​628

Summary

Implements the stage derivation engine (Spec #22): one pure function turns GitHub facts across a task tree (root + children, most-recent activity wins) into the effective workflow stage — any open PR → review, unconsumed merged PR → shipped, closed unmerged PR → triage, an open spec issue → spec only from idea/exploring/unstaged, otherwise the declared stage applies. The engine never derives implementing; folder workspaces run a manual regime; a merge ships a card exactly once (consumed-merge guard keeps a human de-ship stable). Facts reach the engine through a neutral fact-source interface whose GitHub implementation reads client-side caches, so local, SSH, and runtime-host workspaces all derive identically. Derived stages are computed at read time and never persisted.

Spec & Tickets

Closes #22

Acceptance Criteria

Scope Criterion Verdict Evidence
#33 Precedence chains: open > merged > closed > spec-issue > declared ✅ Fixed precedence in deriveWorkflowStage; precedence describe-block covers every ranking pair
#33 A new PR on an already-shipped feature brings the card back to review ✅ regression-on-shipped test: open PR outranks an unconsumed merge
#33 De-shipped card stays de-shipped for the same merge; only new facts move it again ✅ consumed-merge tests: spent id drives nothing; fresh open→merge cycle re-drives
#33 An open spec issue never regresses a card out of implementing ✅ SPEC_ISSUE_ALLOWED_BASES = idea/exploring/unstaged; it.each over implementing/review/shipped/triage/spec
#33 The engine never derives implementing ✅ no return path yields it; dedicated guard test
#33 Folder workspaces skip derivation entirely ✅ workspaceKind: 'folder' short-circuits to declared stage (folder-manual-regime)
#33 Inputs are serializable; one mock fact source in tests ✅ JSON round-trip equality test; mock source feeds engine end-to-end
#38 Real PR/issue states drive effective stages on read ✅ deriveEffectiveWorkflowStage folds branch-scoped prCache/issueCache entries into engine facts through the GitHubStageFactSource seam; consumer surfaces arrive with the board specs
#38 PR refresh events re-drive derivation without manual refresh ✅ projection memoizes per cache snapshot; applyGitHubPRRefreshEvent swaps prCache identity on every found outcome
#38 Remote-host workspaces derive identically to local ones ✅ keys built with shared getGitHubPRCacheKey/issueCacheKey so local, ssh: and runtime: scopes each read their own entries (per-host test)
#38 Fact-derived stages are never persisted ✅ zero production writers of any derived value; purity/input-immutability tests; declared-stage write paths untouched
#38 Swapping the source implementation requires no engine change ✅ engine consumes plain facts only; injected alternate source changes outcomes without touching the engine (override test)

Problem → Resolution

  • Merged vs closed conflict inside one tree (chain says closed beats merged, AC says merged ships) → class precedence wins: any unconsumed merged beats any closed; abandoned sibling PRs don't regress shipped features.
  • Consumed-merge semantics for mixed trees → consumed merges drop out entirely (drive nothing); "only new facts re-drive" preserved.
  • Most-recent-wins needs an ordering key without clock access → caller-supplied opaque activityAt (epoch ms or ISO string, compared same-typed only).
  • Neutral interface is async/ref-shaped while React read paths are synchronous selectors → GitHubStageFactSource exposes both faces over one loader: async loadTaskTreeFacts for loaders, sync factsForSubject for in-memory caches (pending async reads as "no facts").
  • Persisted markers are number[] while the engine compares string ids → fact id = decimal PR number string; consumedMergeIdsFromNumbers is the single conversion point (ids not repo-qualified; adequate while derivation covers self-only facts — task-tree rollup deferred to the board tickets).
  • Reused branch could falsely ship new work off a stale merged entry → merged facts require head provenance (isCachedMergedBranchPRCurrentForWorktree) or carry no signal. Open entries need no gate: an open PR on the branch is an open PR for this line of work.
  • Classic-drawer exclusivity initially counted fact-derived stages → reverted to declared-only: spec 22 keeps the two-board model out of scope, and rows would vanish from both boards before the feature board exists.
  • Folder workspaces got consumed-marker plumbing despite never being fact-moved → kept deliberately: exact symmetry with the shipped workflowStage field, zero behavior impact (folder rows take the manual-regime branch).

Changes by theme

Theme Files Notes
Pure derivation core (#33) src/shared/stage-derivation/stage-derivation.ts
stage-derivation.test.ts
Pure, I/O-free, optional-tolerant engine + 30+ criterion tests
Neutral fact-source seam (#33/#38) src/shared/stage-derivation/stage-fact-source.ts
github-stage-fact-source.ts
Interface, GitHub translation (PRInfo/IssueInfo → facts), dual-face source
Read-time projection (#38) src/renderer/src/components/sidebar/effective-workflow-stage.ts Per-row derivation over client caches, ready for the board/sidebar specs
Consumed-merge persistence (#38) meta-types.ts, folder-workspace-types.ts, worktree-metadata-merge.ts, loading-store/store.ts, ipc/worktrees.ts, runtime RPC schema/preload/repos slice Optional consumedMergedPRNumbers field mirroring the workflowStage contract; field added, no writer yet (de-ship UI is a later ticket)

QA plan

  • Staging a workspace via existing paths still hides it from the classic drawer; unstaging restores it with its previous status (unchanged Two-board exclusivity filter #40 behavior)
  • A worktree with an open PR and no declared stage remains visible in the classic drawer (regression guard of the scope fix)
  • Declared stages still persist across restart; corrupt persisted values still degrade to unstaged
  • pnpm vitest run src/shared/stage-derivation passes locally (engine + seam + GitHub translation)
  • Once the feature board lands (spec 24): card with open PR shows review without manual refresh; after merge shows shipped; de-ship survives re-reads until a new fact arrives

64ix added 12 commits August 23, 2026 09:56
…ral stage facts (#38)

Implements the WorkflowStageFactSource boundary for GitHub over
client-side cached PRInfo/IssueInfo: draft maps to open, fact ids are
raw PR numbers so persisted consumed-merge markers round-trip into the
engine's consumedMergeIds, and a snapshot loader keeps the async
interface intact for future remote/RPC loaders.
…cts in staged-exclusivity read path (#38)

deriveEffectiveWorkflowStage folds branch-scoped prCache entries and
linkedIssue state into the engine per row; local/ssh/runtime host
scopes all hit their own cache keys, merged-PR entries stale for the
current head carry no signal, and folder rows run the manual regime.
The classic drawer projector consumes effective stages so fact-staged
workspaces leave the drawer without any declared write.
…s meta plumbing (#38)

consumedMergedPRNumbers rides the existing updateMeta paths: WorktreeMeta,
FolderWorkspace, folder scope branch, IPC boundary guard, store
sanitization, read-time degradation in mergeWorktree, runtime worktree.set
and folderWorkspace.update schemas. Nothing writes it yet; derivation only
reads it into consumedMergeIds.
…the fact-source seam (#38)

deriveEffectiveWorkflowStage no longer folds GitHub snapshots inline;
createGitHubStageFactSource gains a synchronous factsForSubject face
sharing the same snapshot loader as the async loadTaskTreeFacts, and the
renderer projector reads facts through a source instance (injectable for
alternate providers). Engine untouched.
…ing (#38)

Review finding on #38: deriving effective stages into the classic-drawer
filter made rows vanish from both boards before the feature board exists,
and the two-board model is out of scope for spec 22. isStagedWorkspace and
computeClassicDrawerWorktreeIds read only the declared stage again; the
hook stops subscribing prCache/issueCache for this purpose.

deriveEffectiveWorkflowStage stays exported with its pure logic intact for
the upcoming board/sidebar specs, now fed through the GitHub fact source.
@64ix
64ix marked this pull request as ready for review August 23, 2026 10:10
@64ix
64ix merged commit 4903d30 into main Aug 24, 2026
95 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Spec] Stage derivation engine

1 participant