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

feat(dev): agent mode — --json NDJSON events, /__kody/dev/status, --ready-file, attach - #61

Merged
kody-bot merged 12 commits into
mainfrom
cursor/kody-dev-agent-json-354f
Oct 15, 2026
Merged

kody-bot merged 12 commits into
mainfrom
cursor/kody-dev-agent-json-354f

Conversation

@kentcdodds

@kentcdodds kentcdodds commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Stack: #63 → #58 → #61 → #59 → #60

Intent

Third of five stacked kody dev PRs (base: the live reload PR). Lets agents drive kody dev without scraping human output.

Door: two-way

Cleanup: none

Summary

  • kody dev --json prints one JSON object per line on stdout, each with type and ts:

    • ready {url, port, basePath, pid, statusUrl, buildId}
    • rebuild_start {files}
    • rebuild_ok {ms, buildId, restarted}
    • build_error {file, line, col, message, diagnostics}
    • runtime_error {message, stack, request}
    • log {source, level, message, request}

    Status lines stay on stderr.

  • GET /__kody/dev/status returns { ok, state, buildId, url, port, basePath, target, package, pid, lastRebuild, lastError }.

  • --ready-file <path> writes { url, port, basePath, pid, statusUrl } once the first build settles and removes the file on exit.

  • kody dev fetch attaches to a running kody dev for the same package and --target. It finds the server through a registry file in the user cache dir, confirms it via the status endpoint, and waits for any in-progress rebuild. --no-attach forces a one-shot server. Attached fetches get no live-reload script.

  • The stat poll is re-baselined after each build, so it no longer causes a duplicate no-op rebuild.

Testing

  • npm run validate passes.
  • New test/dev-agent.test.ts covers: status through ready, runtime error, and build error states; --json event order with ts; the ready file and registry existing at ready and removed on shutdown; attached fetch seeing a fresh build, and not attaching across targets; and stale registrations being dropped.
  • Manual end-to-end run: the ready file, status JSON, NDJSON stream, and an attached kody dev fetch (132ms) all worked.
Open in Web Open in Cursor 

Note

Medium Risk
Touches dev-server request gating, file watching/rebuild scheduling, and cross-process registry files; mistakes could cause stale builds, duplicate rebuilds, or wrong attach targets, but scope is local dev tooling with tests.

Reviewed by Cursor Bugbot for commit 5d1349f. Bugbot is set up for automated code reviews on this repo. Configure here.

@kentcdodds

Copy link
Copy Markdown
Owner Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/dev-command.ts Outdated
@kentcdodds

Copy link
Copy Markdown
Owner Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/dev/dev-watcher.ts Outdated
@kentcdodds

Copy link
Copy Markdown
Owner Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/dev/dev-watcher.ts Outdated

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@kentcdodds

Copy link
Copy Markdown
Owner Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@cursor
cursor Bot force-pushed the cursor/kody-dev-live-reload-354f branch from 69a26a8 to 98621b7 Compare October 15, 2026 06:25
@cursor
cursor Bot force-pushed the cursor/kody-dev-agent-json-354f branch from 9b119c7 to 26c9bff Compare October 15, 2026 06:27

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/dev/dev-watcher.ts
Comment thread src/dev/dev-watcher.ts

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/dev/dev-watcher.ts Outdated
Comment thread src/dev/dev-watcher.ts
@cursor
cursor Bot force-pushed the cursor/kody-dev-agent-json-354f branch from 57fe438 to cf978e1 Compare October 15, 2026 06:48
@cursor
cursor Bot force-pushed the cursor/kody-dev-live-reload-354f branch from 8362887 to 98621b7 Compare October 15, 2026 06:50
@cursor
cursor Bot force-pushed the cursor/kody-dev-agent-json-354f branch from cf978e1 to 4fdadfe Compare October 15, 2026 06:50
Base automatically changed from cursor/kody-dev-live-reload-354f to main October 15, 2026 06:51
cursoragent and others added 5 commits October 15, 2026 06:51
…eady-file, attach

- kody dev --json prints ready / rebuild_start / rebuild_ok / build_error /
  runtime_error / log events as NDJSON on stdout.
- GET /__kody/dev/status returns state, build id, and the last build or
  runtime error.
- --ready-file writes { url, port, basePath, pid, statusUrl } once the first
  build settles and removes it on exit.
- kody dev fetch attaches to a running kody dev for the same package and
  target (registry in the user cache dir, confirmed via status); --no-attach
  forces a one-shot server.
- Live reload only injects into requests that accept text/html, so agent
  fetches see the app's bytes.
- The watcher's stat poll re-baselines after each build (no echo rebuilds).
- Dev server tests reuse the cached workerd instead of re-downloading it.
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Re-baseline after each build still suppresses echo rebuilds, but paths
that changed since the previous baseline and were not the rebuild trigger
fire onChange (mid-build edit). A track generation makes in-flight polls
abandon so they cannot pair old fingerprints with the new map.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Poll retains the map it started with so a concurrent track() swap cannot
pair old fingerprints with the new baseline. Mid-build edits returned from
track() are queued onto changedFiles/rebuildAgain directly instead of
onChange, so a debounced chokidar delivery of the same paths cannot
schedule a second rebuild.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Prebuild (and similar) rewrite tracked inputs before esbuild runs.
rebaseline() absorbs those fingerprints so track()'s mid-build
comparison only reports edits that land during the bundle itself.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@cursor
cursor Bot force-pushed the cursor/kody-dev-agent-json-354f branch from 4fdadfe to 3440bc9 Compare October 15, 2026 06:51
@kentcdodds

Copy link
Copy Markdown
Owner Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/dev/dev-registry.ts
Comment thread src/dev/dev-registry.ts
Comment thread src/dev-command.ts

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Bugbot on #61: registry files are per root+target; remove only when the
pid still matches (leave unreadable successor files alone); watcher
debounce reports building and gates proxy fetches until the rebuild
starts.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@kentcdodds

Copy link
Copy Markdown
Owner Author

bugbot run

1 similar comment
@kentcdodds

Copy link
Copy Markdown
Owner Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@kentcdodds

Copy link
Copy Markdown
Owner Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@cursor
cursor Bot force-pushed the cursor/kody-dev-agent-json-354f branch from cb20f60 to d5bb07a Compare October 15, 2026 07:18
@kentcdodds

Copy link
Copy Markdown
Owner Author

bugbot run

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@kentcdodds

Copy link
Copy Markdown
Owner Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/dev-command.ts Outdated
Comment thread src/dev/dev-watcher.ts Outdated
Bugbot: wrap post-listen ready-file/registration in shutdown-on-error so
a bad --ready-file cannot leave listen handles hanging; poll also checks
trackGeneration so an in-flight poll cannot echo rebuilds mid-track.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/dev-command.ts Outdated
Comment thread src/dev/dev-registry.ts
Comment thread src/package-app-dev.ts
@kentcdodds

Copy link
Copy Markdown
Owner Author

bugbot run

…lete

Bugbot: no-op same-bundle rebuilds still update lastRebuild.at for agents
polling status; findRunningDevServer re-reads before deleting a dead-pid
entry so a successor registration is not wiped.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@kentcdodds

Copy link
Copy Markdown
Owner Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/dev/dev-watcher.ts

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

kentcdodds and others added 2 commits October 15, 2026 07:47
Detach the tracked fingerprint map at the start of track/rebaseline so an
in-flight poll cannot compare post-build bytes to the pre-build baseline.
Fold mid-build watcher events into the active loop, ignore echoes of the
files already building, and skip buildOnce when every path still matches
the baseline.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
…dits

Fingerprint equality is not a reliable content check on coarse mtime
filesystems, so skipping buildOnce when paths still matched the baseline
could ignore real saves (e.g. v0→v1). Poll-map detach and mid-build
chokidar folding remain the echo guards.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0667555. Configure here.

Comment thread src/package-app-dev.ts
Ignoring onChange for paths in buildingFiles meant a second save (or
format-on-save) during an in-progress rebuild was discarded, and track()'s
ignoreChanges could not recover it — kody dev kept serving the earlier
bundle. Fold every mid-build watcher event into rebuildAgain instead.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@kody-bot
kody-bot merged commit 45f73c6 into main Oct 15, 2026
7 checks passed
@kody-bot
kody-bot deleted the cursor/kody-dev-agent-json-354f branch October 15, 2026 07:59
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.25.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants