refactor(daemon): workflows must be bundled to dist/, daemon only loads dist/index.js #219

Closed
opened 2026-04-28 05:13:59 +00:00 by xiaoju · 0 comments
Owner

What

Workflow build output should go to workflows/<name>/dist/index.js (bundled), not scatter .js files alongside .ts source. Daemon should only load and watch dist/.

Current (broken)

  • tsc outputs .js next to .ts source — mixed source and build artifacts
  • Daemon loadWorkflowDefinition looks for index.ts / index.js in workflow root
  • File-watcher watches .ts files — triggers on source edits, not build output
  • Editing source mid-way can mis-trigger hot-reload before build is complete

Target

Build

  • Each workflow bundles to workflows/<name>/dist/index.js (single file, esbuild or similar)
  • Source .ts stays in workflow root, dist/ is gitignored build output
  • nerve create workflow scaffold should include a build script

Daemon loader (workflow-worker.ts)

  • loadWorkflowDefinition looks for workflows/<name>/dist/index.js only
  • No .ts fallback, no root-level .js fallback

File-watcher (file-watcher.ts)

  • Watch workflows/*/dist/**/*.js for changes
  • Ignore workflows/*/*.ts (source edits dont trigger reload)
  • Hot-reload only fires when dist/ content changes (= build completed)

Sense loader (sense-worker.ts)

  • Same pattern: look for senses/<name>/index.js (already correct)

Benefits

  • Clean separation: source vs artifacts
  • No accidental hot-reload during editing
  • Watcher semantics are precise: dist change = ready to load
  • Single bundled file = faster import, no resolution issues

Ref

Supersedes the simpler .ts/.js swap in #217. PR #218 can be closed in favor of this.

## What Workflow build output should go to `workflows/<name>/dist/index.js` (bundled), not scatter `.js` files alongside `.ts` source. Daemon should only load and watch `dist/`. ## Current (broken) - `tsc` outputs `.js` next to `.ts` source — mixed source and build artifacts - Daemon `loadWorkflowDefinition` looks for `index.ts` / `index.js` in workflow root - File-watcher watches `.ts` files — triggers on source edits, not build output - Editing source mid-way can mis-trigger hot-reload before build is complete ## Target ### Build - Each workflow bundles to `workflows/<name>/dist/index.js` (single file, esbuild or similar) - Source `.ts` stays in workflow root, `dist/` is gitignored build output - `nerve create workflow` scaffold should include a build script ### Daemon loader (workflow-worker.ts) - `loadWorkflowDefinition` looks for `workflows/<name>/dist/index.js` only - No `.ts` fallback, no root-level `.js` fallback ### File-watcher (file-watcher.ts) - Watch `workflows/*/dist/**/*.js` for changes - Ignore `workflows/*/*.ts` (source edits dont trigger reload) - Hot-reload only fires when `dist/` content changes (= build completed) ### Sense loader (sense-worker.ts) - Same pattern: look for `senses/<name>/index.js` (already correct) ## Benefits - Clean separation: source vs artifacts - No accidental hot-reload during editing - Watcher semantics are precise: dist change = ready to load - Single bundled file = faster import, no resolution issues ## Ref Supersedes the simpler .ts/.js swap in #217. PR #218 can be closed in favor of this.
xiaoju changed title from fix(daemon): only import and watch built .js, never .ts source to refactor(daemon): workflows must be bundled to dist/, daemon only loads dist/index.js 2026-04-28 05:18:35 +00:00
This repo is archived. You cannot comment on issues.
No Label
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/nerve#219