Repository navigation
feat(cli): work on the running app or server instead of a second engine - #442
Conversation
Add `ketch add`, `list`, `pause`, `resume` and `watch`, which attach through RemoteKetch to the Ketch that runs the downloads: `--server`/KETCH_SERVER, else the desktop app (asked over its SingleInstance endpoint for its loopback API server, `cli/connect`), else the `ketch server` this machine runs. `add` sends a request ID and retries with it, and `--idempotency-key` keeps retried submissions from adding a download twice. `watch` prints task changes as JSON lines. `ketch mcp` attaches the same way, finding the instance when a tool first needs it and again after losing it; `--standalone` keeps the old engine of its own. `ketch server` and `ketch mcp --standalone` refuse to open ketch.db while the desktop app or another one runs it (instance.lock), and describe themselves in an owner-only instance.json for the attaching commands. Also fixes, found while testing the native binary: - a request sent again with its ID to a token-less server kept failing as a different request once its file existed; the guard now keeps the first destination (DestinationPathPolicy.confinesTo) - kotlin-reflect was still compiled into the native image, whose StatusPages then turned every 4xx into a 500 - the native binary skipped shutdown hooks on SIGINT and SIGTERM BrowserExtensionServer is now LocalApiServer, as it serves the CLI too.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 334fe98366
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
`ketch server` and `ketch mcp --standalone` published their endpoint before restoring tasks, so a client that found them right away could see an empty list. Worse, Ketch.start replaced the task list with the stored snapshot, so a download added while the records loaded, through any server that already listens, vanished from the list while it still ran. Start now keeps such downloads, and the endpoint is published after restoration. The MCP startDownload tool refuses a requestId when the instance lacks KetchFeatures.REQUEST_ID, which an older server would drop and so add the download again on a retry.
Test Results 1 419 files +11 1 446 suites +11 9m 30s ⏱️ +32s Results for commit 7ecf25d. ± Comparison against base commit bbd62d6. This pull request removes 8 and adds 74 tests. Note that renamed tests count towards both. |
Implements the Command line for running devices roadmap item (AGENTS.md roadmap 15).
What changed
New attaching commands (
cli):ketch add,list,pause,resumeandwatchwork on the downloads of the Ketch that is already running, throughRemoteKetch, instead of openingketch.dbwith an engine of their own.InstanceLocatorpicks, in order:--server <url>/KETCH_SERVER(with--token/KETCH_API_TOKEN)SingleInstanceendpoint (cli/connect) for the loopback API server it already runs for the browser extension (BrowserExtensionServer, renamedLocalApiServer)ketch serverorketch mcp --standalonethatinstance.jsonnames, if its pid is aliveaddprints the task ID (--jsonfor the task), resolves relative destinations against the cwd for a local instance, sends arequestIdand retries connection failures/5xx with it.--idempotency-keymakes retries safe across runs (a UUID as-is, other text → name-based UUID).watchprints NDJSON (snapshot,added,state,progress,removed); with IDs it exits once they finish (0 all completed, 1 otherwise), and exits 1 when the connection is lost.ketch mcpnow attaches the same way (InstanceConnection): it finds the instance when a tool first needs it and again once the connection is lost (e.g. the app restarts on a new port).KetchToolSet/KetchMcpServertake aconnect: suspend () -> KetchApiprovider, asked per call.startDownloadgains an optionalrequestId.--standalonekeeps the old own-engine behaviour, now with a loopback API the attaching commands use.One engine per database:
ketch serverandketch mcp --standalonerefuse to start while the desktop app runs or another holdsinstance.lock, and publish an owner-onlyinstance.json(command, pid, loopback URL, token).Fixes found while testing the native binary
name (1)).DestinationGuardnow keeps the first destination when it names the same place (DestinationPathPolicy.confinesTo).runtimeClasspathbut notnativeImageClasspath, so Ktor StatusPages crashed (Built-in class kotlin.Any is not found) and every 4xx from the native server became a 500. Now excluded from both; binary 92 MB → 79 MB.--install-exit-handlersso SIGINT/SIGTERM run shutdown hooks (the server now pauses downloads and removesinstance.json).Reviewer notes
ketch mcpno longer runs its own engine by default;--dir/--confignow require--standalone, so MCP client configs passing--dirfail to start until updated.SingleInstance's framing itself (DesktopApp); both sides note to stay in step.cli/README.md(new "Work on a running Ketch" section, MCP, server), AGENTS.md, and all six READMEs (roadmap entry removed, feature line added).Testing
./gradlew :cli:test :library:mcp:test :library:server:test :library:core:jvmTest :library:remote:jvmTest :app:desktop:test -PprebuiltWebDir=/nonexistentpasses, including an end-to-endAttachedCommandsTestagainst a real loopbackKetchServer.installDistand:cli:nativeCompilebinaries against an isolatedketch server(add/re-add with key, list, pause/resume, watch,mcpattach,--standalonerefusal, second-server refusal, SIGTERM cleanup).ketch listreports it must be updated;ketch serverrefuses to start.