Skip to content

refactor(cli): convert debug agent command to effectCmd#25485

Open
kitlangton wants to merge 1 commit intodevfrom
kit/cli-effectify-debug-agent
Open

refactor(cli): convert debug agent command to effectCmd#25485
kitlangton wants to merge 1 commit intodevfrom
kit/cli-effectify-debug-agent

Conversation

@kitlangton
Copy link
Copy Markdown
Contributor

Summary

  • Convert `debug agent ` from `cmd()` + `bootstrap()` to `effectCmd` + `Effect.ensuring(store.dispose(ctx))`.
  • Helpers (`getAvailableTools`, `createToolContext`) converted from `async/Promise` to `Effect.fn` so they yield services directly. `createToolContext` takes `ctx: InstanceContext` explicitly so it can read `ctx.directory/.worktree` (was `Instance.directory/.worktree` from ALS).
  • 3× `process.exit(1)` paths → `fail("", 1)` (stderr message printed inline; empty message means no spurious `Error:` prefix from the global formatter).

Behavioral notes (subagent purity audit)

MOSTLY PURE WITH NOTES — pure on the agent-info path; observable improvements on error paths:

  1. `--tool` execution fix (intentional latent bug fix): legacy `await tool.execute(params, ctx)` awaited an `Effect` object, which is not PromiseLike in effect-smol — `await` resolved to the Effect itself, the tool never actually ran, and `JSON.stringify` of the Effect produced garbage. New `yield* tool.execute(...)` actually executes the tool and returns the real `ExecuteResult`. Strictly correct.
  2. Disposal on error paths: legacy `process.exit(1)` bypassed bootstrap's finally → no disposal. New flows through `Effect.ensuring` so disposal runs on all three error paths. Same exit code 1.

Test plan

  • `bun run typecheck`
  • `bun run test test/cli/` — 137 pass
  • `debug agent build` prints agent JSON
  • `debug agent build --tool glob --params '{"pattern":"*.json"}'` now actually runs glob and prints real `ExecuteResult` JSON (was printing garbage Effect object before)

Drops bootstrap() + 3 AppRuntime.runPromise wrappers. Helpers
(getAvailableTools, createToolContext) now return Effects yielded
directly. Instance.directory/.worktree → ctx.directory/.worktree from
InstanceRef. process.exit(1) → fail("", 1) for the three error paths
(stderr message printed inline, exit code 1).

Bonus fix: --tool execution path was awaiting tool.execute() which
returns an Effect (not a Promise), so result was the Effect object
itself — JSON.stringify produced garbage. Now properly yields the Effect
to get the ExecuteResult.
}),
)
}
const getAvailableTools = Effect.fn("Cli.debug.agent.getAvailableTools")(function* (agent: Agent.Info) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hello

}),
)
}
const getAvailableTools = Effect.fn("Cli.debug.agent.getAvailableTools")(function* (agent: Agent.Info) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

testing

@@ -7,14 +7,14 @@ import { Session } from "@/session/session"
import type { MessageV2 } from "../../../session/message-v2"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

test

@@ -7,14 +7,14 @@ import { Session } from "@/session/session"
import type { MessageV2 } from "../../../session/message-v2"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

testing

}),
)
}
const getAvailableTools = Effect.fn("Cli.debug.agent.getAvailableTools")(function* (agent: Agent.Info) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

funky. fukny

@@ -7,14 +7,14 @@ import { Session } from "@/session/session"
import type { MessageV2 } from "../../../session/message-v2"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ay

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant