Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(templates): clear GitHub checkout credentials on coding-agent turns (#5172)

Colton Padden45f04c95e0a6
diff --git a/apps/templates/eve-coding-agent-template/agent/hooks/reset-github-egress.ts b/apps/templates/eve-coding-agent-template/agent/hooks/reset-github-egress.ts
index 80a180626..698786a22 100644
--- a/apps/templates/eve-coding-agent-template/agent/hooks/reset-github-egress.ts
+++ b/apps/templates/eve-coding-agent-template/agent/hooks/reset-github-egress.ts
@@ -1,14 +1,18 @@
+import { isChannel } from "eve/channels";
import { defineHook } from "eve/hooks";
+import github from "../channels/github";
import { brokerGitHubLease } from "../lib/github";
// The GitHub channel's checkout leaves its installation token attached to all
// of github.com. Hooks run after the channel's `turn.started` handler, so this
// clears it before the model runs. Only `git__gh` leases then carry credentials.
+// `ctx.channel.kind` is the path-derived `channel:<slug>`, never the bare
+// platform name, so match the channel definition with `isChannel`.
export default defineHook({
events: {
async "turn.started"(_event, ctx) {
- if (ctx.channel.kind !== "github") return;
+ if (!isChannel(ctx.channel, github)) return;
try {
await brokerGitHubLease(await ctx.getSandbox(), null);
} catch (error) {
diff --git a/docs/guides/hooks.md b/docs/guides/hooks.md
index 8f0ea0721..49b0f8d57 100644
--- a/docs/guides/hooks.md
+++ b/docs/guides/hooks.md
@@ -50,7 +50,27 @@ export default githubChannel({
A GitHub channel event handler cannot fire for a Slack-owned session, so platform-specific side effects do not depend on an early-return guard. On a built-in channel, an authored handler replaces that channel's default handler for the same event key. Check the channel page before overriding events that deliver replies, progress, errors, or human-input prompts. The [Slack channel](/docs/channels/slack#customize-rendering) takes renderers instead: a renderer's handler keeps Slack's default by calling `next()` and replaces it by skipping `next`.
-Use `ctx.channel.kind` inside a global hook only when the operation is otherwise agent-wide and conditional handling is intentional. For typed channel metadata in dynamic resolvers or instrumentation, import the channel definition and narrow with `isChannel`; see [OpenTelemetry runtime context](../observability/otel#add-runtime-context).
+Use `ctx.channel.kind` inside a global hook only when the operation is otherwise agent-wide and conditional handling is intentional. For a channel with event handlers, such as `githubChannel`, `slackChannel`, and the other built-ins, the kind is the path-derived identity. `agent/channels/github.ts` reports `channel:github`, so `ctx.channel.kind === "github"` never matches. Import the channel definition and compare it with `isChannel` from `eve/channels`:
+
+```ts title="agent/hooks/github-only.ts"
+import { isChannel } from "eve/channels";
+import { defineHook } from "eve/hooks";
+
+import github from "../channels/github";
+
+export default defineHook({
+ events: {
+ async "turn.started"(_event, ctx) {
+ if (!isChannel(ctx.channel, github)) return;
+ // GitHub-owned turns only.
+ },
+ },
+});
+```
+
+A route-only `defineChannel` with no event handlers keeps the kind `"http"`, so `isChannel` does not match it in a hook. Compare `ctx.channel.kind === "http"` for those channels instead.
+
+For typed channel metadata in dynamic resolvers or instrumentation, narrow with `isChannel` the same way; see [OpenTelemetry runtime context](../observability/otel#add-runtime-context).
## Hook structure and context