Skip to content

refactor(daemon): assemble the workflows subsystem - #4611

Open
lsm wants to merge 2 commits into
devfrom
claude/move-workflows-subsystem
Open

lsm wants to merge 2 commits into
devfrom
claude/move-workflows-subsystem

Conversation

@lsm

@lsm lsm commented Sep 15, 2026

Copy link
Copy Markdown
Owner

Assembles the workflows subsystem as a flat top-level folder, packages/daemon/src/lib/workflows/. Pure move + extraction: no logic changes, exported symbol names unchanged, every import rewritten across src/ and tests/. Test files keep their CI shard directories (only basenames that mirrored a renamed source were renamed).

Resulting layout (src/lib/workflows/)

Definitions and seeding

  • built-in-workflows.ts (110) — registry: getBuiltInWorkflows, resolveBuiltInWorkflowTemplate, builtInWorkflowRequiresPrMerge, legacy identities; re-exports the five definitions
  • built-in-coding-workflows.ts (260), built-in-research-workflows.ts (116) — the five built-in definitions by family
  • built-in-legacy-slot-prompts.ts (264) — legacy stable-slot prompts + patchLegacyStableSlotPrompt
  • built-in-prompt-drift.ts (472) — prompt-drift patch variants, patchKnownBuiltInPromptDrift, patchPinnedBuiltInPromptDrift
  • built-in-retired-prompts-{coder-owned-merge,coder-only,research}.ts (281/310/299) — one retired prompt family per file
  • built-in-template-merge.ts (360) — node/channel/hook merge-from-template + remap helpers
  • built-in-retired-post-approval.ts (124) — retired Post-Approval node stripping
  • seed-built-in-workflows.ts (346) — seedBuiltInWorkflows
  • definition-version.ts, template-hash.ts, run-template-snapshot.ts, plan-run-snapshot-migration.ts, post-approval-template.ts, post-approval-merge-template.ts, post-approval-validator.ts, coding-artifact-profile.ts, artifact-profile.ts

Definition management

  • workflow-manager.ts (373) — SpaceWorkflowManager CRUD; re-exports the error classes and isReservedWorkflowAgentName
  • workflow-node-validation.ts (265), workflow-graph-validation.ts (207), workflow-identity-validation.ts (79), workflow-validation-error.ts (16)
  • node-execution-manager.ts, node-execution-validation.ts

Hooks

  • hook-engine.ts (635) — WorkflowHookEngine (executeAction + queued retryable-action state); re-exports wrapHandlerWithHooks, triggerRetryableHookAction, clearAllRetryableHookActionTimers, PR_READY_VALIDATED_IDENTITY_HOOK_ID
  • hook-binding.ts (424) — wrapHandlerWithHooks + retryable-action timers/replay
  • hook-matching.ts (221) — resolveMatchingHooks, sortHooks, target resolution
  • hook-executor-context.ts (111) — buildExecutorContext, frozen PR URL
  • hook-param-bounds.ts (132) — param/artifact/state bounding, patched-param schema validation
  • hook-user-state.ts (65) — block/allow user-state builders
  • hook-executor.ts (217) — HookExecutor, executeHookScript; hook-script-env.ts (225) — restricted env construction
  • hook-validation.ts (355) — definition-time hook validation, caller authorization; hook-result-validation.ts (72) — validateWorkflowHookResult
  • hook-runtime-service.ts
  • built-in-validator-registry.ts, built-in-validators/{index,post-approval-only-validator,pr-ready-validator (267),pr-ready-gh-commands (315)}.ts

Run execution

  • run-tick-pipeline.ts, run-tick-contract.ts, run-tick-admission-gates.ts, run-spawn-decisions.ts, run-completion-settlement.ts, run-status-machine.ts, completion-detector.ts
  • post-approval-router.ts (344) — PostApprovalRouter; re-exports the pure helpers callers use
  • post-approval-route-selection.ts (110) — pure route selection / flag / warning mapping
  • post-approval-retry.ts, end-node-handlers.ts, workflow-executor.ts, workflow-selector.ts, llm-workflow-selector.ts

Renames

workflow-hook-enginehook-engine, workflow-hook-validationhook-validation, workflow-hook-runtime-servicehook-runtime-service, workflow-node-execution-validationnode-execution-validation, workflow-run-status-machinerun-status-machine, space-workflow-managerworkflow-manager. Kept workflow-executor/workflow-selector/llm-workflow-selector (a bare executor.ts/selector.ts next to hook-executor.ts reads worse).

Left in space/runtime/ on purpose

  • decision-pipeline.ts — generic (deprecated) decisionRun helper consumed by agent/, external-events/, model-service, storage/, goals/; not workflow execution.
  • staged-run.ts — generic (deprecated) stagedRun saga helper; its only consumers are the tasks lane (spawn-flow, verified-stop-flow, task-agent-manager). Moving it would point tasks-lane code at lib/workflows/.
  • goal-outcome-wake-flag.ts — goal-outcome wake feature flag consumed by SpaceRuntimeService; not workflow.

Left whole

  • hook-engine.ts (635): executeAction (~335 lines) is one procedure mutating shared accumulators; splitting it needs restructuring, not extraction.
  • built-in-prompt-drift.ts (472): the ~60 unexported prompt-fragment constants only feed BUILT_IN_PROMPT_PATCH_VARIANTS; exporting them into a separate file would be size-fitting.
  • hook-binding.ts (424): the retryable-action scheduler replays through wrapHandlerWithHooks; splitting them creates a runtime import cycle.

Config

knip.json/knip.ts ignore keys re-keyed; scripts/shard-weights.tsv entries for the four renamed tests updated; file-size-ratchet.json re-keyed (hook-engine.ts at 635, built-in-workflows/workflow-manager entries dropped as they are now under the ceiling).

Verification

bunx tsc --build --noEmit clean; bun run check passes. Targeted daemon tests for the split modules: 810 pass; the 7 failures in space-runtime.test.ts > standalone tasks reproduce identically on pristine origin/dev.

@hyperneo-ai-test

Copy link
Copy Markdown

Review status

Started 2026-09-15T17:37:17-04:00
Finished
Head aaa0529
Engine claude (glm-5.3-flash)
Verdict review in progress

# Conflicts:
#	docs/architecture/target-architecture/execution-plan/file-size-ratchet.json
#	packages/daemon/src/lib/space/evolution-episode-service.ts
#	packages/daemon/src/lib/space/runtime/task-agent-manager.ts
#	packages/daemon/src/lib/workflows/end-node-handlers.ts
#	packages/daemon/src/lib/workflows/post-approval-router.ts
#	packages/daemon/tests/unit/5-space/evolution/episode-service.test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant