diff --git a/layers/nuxi/README.md b/layers/nuxi/README.md index 148e55680..e821e4518 100644 --- a/layers/nuxi/README.md +++ b/layers/nuxi/README.md @@ -91,6 +91,8 @@ When someone on Slack or in an admin Discord channel gives Nuxi a coding task on - **Approval:** creating the branch, committing and opening the pull request run without asking; a person reviews and merges on GitHub. `updatePullRequest` still asks the person who requested it, with **Approve** and **Deny** buttons in the thread. On Discord, the buttons need the Interactions Endpoint URL from the [Discord setup](#discord-channel). - **Tools:** `coder/tools/` disables eve's sandbox tools (`bash` and the file tools), so it changes code through the GitHub API only and never needs a sandbox. It keeps `web_search` and `web_fetch` to read docs, issues and pages linked in the request. `web_fetch` stays off on the root agent, which serves public chats. +On Slack, Nuxi first moves the request into a [code channel](https://docs.slack.dev/ai/slack-code) with `tools/open_code_channel.ts`, offered to the same people as `coder`. The channel starts with the thread so far and invites the person who asked. Every message in it reaches Nuxi without a mention, the whole channel is one session, and anyone in it can stop the agent from Slack. This needs **Code Channels** turned on in the `slack/nuxi` and `slack/nuxi-preview` connector settings, which adds the `code_channels:manage` scope and the `message.session` and `agent_session_stopped` events, plus the `groups:read` and `mpim:read` bot scopes. Discord has no equivalent and keeps using threads. + Auth uses the `nuxi-code` GitHub App on the `nuxt` org through the Vercel Connect connector `github/nuxi-code`, connected to every environment of the project. `coder` runs with `actAs: 'caller'`: every call uses the GitHub token of the person who asked, so the branch, commits and pull request are theirs, and GitHub enforces their own access to `nuxt/nuxt.com`. The extension's `attribution` still credits the App: the pull request body ends with "Generated by nuxi-code", and the commits list the App's bot as co-author. The first time someone asks, Nuxi replies with a sign-in button to authorize the App on their GitHub account; the task continues once they have. A person never falls back to the App's own token. Only `pnpm nuxi` with `NUXI_CLI_ADMIN=1`, which has no GitHub user, runs as the App, so local tests act with the App's permissions. `searchCode` is excluded because its free-text query can name another repository, which the `repositories` guardrail can't check. The App needs **Contents** and **Pull requests** (read and write) and **Metadata** (read). ## Caller identity diff --git a/layers/nuxi/agent/channels/slack.ts b/layers/nuxi/agent/channels/slack.ts index 03bbeb96a..7057adbb4 100644 --- a/layers/nuxi/agent/channels/slack.ts +++ b/layers/nuxi/agent/channels/slack.ts @@ -55,6 +55,9 @@ const sessionFailure = defineSlackRenderer({ export default slackChannel({ credentials: connectSlackCredentials(slackConnectorId()), botName: 'Nuxi', + // A code channel is one session for one task, and every message in it reaches Nuxi without a + // mention. `tools/open_code_channel.ts` moves coding requests into one. + codeChannels: true, threadContext: { since: 'last-agent-reply' }, onAppMention: dispatchSlackMessage, onDirectMessage: dispatchSlackMessage, diff --git a/layers/nuxi/agent/tools/open_code_channel.ts b/layers/nuxi/agent/tools/open_code_channel.ts new file mode 100644 index 000000000..b49693b17 --- /dev/null +++ b/layers/nuxi/agent/tools/open_code_channel.ts @@ -0,0 +1,29 @@ +import { openCodeChannel } from 'eve/channels/slack' +import { defineDynamic, defineTool } from 'eve/tools' +import { z } from 'zod' +import slack from '../channels/slack.js' +import { canUseGithubTools } from '../lib/github.js' +import { resolveContext } from '../lib/identity/context.js' + +// Slack only, for the people who can use the `coder` subagent: a code channel is where its coding +// work happens, one channel and one session per task. +export default defineDynamic(async (ctx) => { + const auth = ctx.session.auth.current + if (resolveContext(auth).surface !== 'slack') return null + if (!(await ctx.memo(ctx.turn?.id ?? null, () => canUseGithubTools(auth)))) return null + + return defineTool({ + description: [ + 'Move this Slack conversation into a new code channel before handing a coding task on nuxt.com to `coder`, such as a fix, a feature, or an investigation with long output.', + 'Answer in place when one message answers the request. Call it once per request; Slack links the new channel here and invites the person who asked, so afterward reply in one short sentence at most and continue the work in the channel.', + 'If it returns unavailable, such as when this already is a code channel, or Slack refuses, continue here and quote the reason without guessing its cause. Don\'t call it again for the same request, but do when the person asks you to try again, since the Slack setup may have changed.' + ].join(' '), + inputSchema: z.object({ + message: z.string().describe('The task and where to start. The channel sees the conversation so far.'), + name: z.string().max(80).describe('A short title, such as `Fix the useFetch example`.') + }), + async execute({ message, name }, toolCtx) { + return await openCodeChannel(toolCtx, slack, message, { name }) + } + }) +})