Repository navigation
feat(coderd/x/chatd): write enabled plugin packs into chat workspaces - #205
Conversation
Adds the plugin_packs and plugin_pack_resources tables (chatdmig node), their forkdb queries with dbauthz and dbmetrics wrappers, and coderd/x/pluginpacks, which fetches one commit of a pack directory over smart HTTP with a host allowlist and fixed size caps. Packs reuse the organization skill RBAC object, so only organization admins and auditors read or manage them.
The 64 MiB transfer cap does not bound memory, because go-git inflates every fetched object into memory storage before the per-file limits run. Read the pack first and reject it when its object headers, and the target sizes of its deltas, add up to more than 256 MiB.
Organization admins can allowlist Git hosts and install, update, list and
delete plugin packs through /api/v2/chats/fork/organizations/{organization}
behind the fork-plugin-packs experiment. An install or update fetches the
pack, pins the resolved commit and stores its files. Members cannot see
packs and auditors can only read them.
…nstall-api # Conflicts: # coderd/database/dbauthz/fork_forkdb.go # coderd/database/dbauthz/fork_forkdb_test.go # coderd/database/dbmetrics/fork_forkdb.go # coderd/database/forkdb/forkdbmock/forkdbmock.go # coderd/database/forkdb/models.go # coderd/database/forkdb/plugin_packs.sql.go # coderd/database/forkdb/querier.go # coderd/database/forkdb/queries/plugin_packs.sql # coderd/database/forkdb/sqlc.yaml # coderd/x/pluginpacks/fetch_test.go
…nablement-api # Conflicts: # coderd/database/dbauthz/fork_forkdb.go # coderd/database/forkdb/forkdbmock/forkdbmock.go # coderd/database/forkdb/querier.go # coderd/database/forkdb/sqlc.yaml # coderd/fork_chat_routes.go
…cks-5-chatd-gating
…cks-5-chatd-gating
…s-6-materialize # Conflicts: # coderd/x/chatd/fork_plugin_gate.go
|
@codex review
|
Codex Review Summary: ✅ CompletedThis 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. |
…s-6-materialize # Conflicts: # coderd/x/chatd/fork_plugin_gate.go
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b31913f824
ℹ️ 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".
…iles Re-pin a chat on its first context-dirty turn after a pack write, drop pack files the pack's current commit no longer has, record the pack ID in the commit marker, and write packs over a connection without the chat headers so the writes stay out of the chat's git changes.
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4ae4535cc5
ℹ️ 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".
…k defining files Re-pin each dirty chat with an enabled pack once after the pack reaches the agent, not only the chat whose turn wrote it, and keep a pack row only when its SKILL.md or agent file and its manifest are files of the pack's current commit.
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 804d553654
ℹ️ 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".
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b387467264
ℹ️ 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".
|
@codex review
|
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 48433f7956
ℹ️ 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".
|
@codex review
|
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Merged as a squash of head
|
Third and last part of PR3 of plugin packs (R7.3), stacked on #204. chatd now writes the packs enabled for a chat into the chat's workspace, so the workspace agent discovers them and the gate from #204 shows them to that chat.
What changes
materializePluginPacksincoderd/x/chatd/fork_pack_materializer.goruns once per turn inbuildTurnEnvironment, right after the first-turn context pin. One hook line inturn_environment.goand oneforkPacksfield onServerinchatd.goare the only upstream edits.<home>/.coder/plugins/<name>/.<home>comes fromchattool.ResolveWorkspaceHome. The pack's files are written withWriteFile, up to 16 at a time, each write bounded to 2 seconds and tried up to 3 times, then a.coder-pack-commitmarker holding the pack's ID and commit. A matching marker skips the pack, so a restarted coderd, which has lost its in-memory record, does not rewrite it, while a pack reinstalled under the same name is written again.agentConnFn, without the chat headers, so the agent does not record them in the chat's git changes.(agent ID, pack ID) -> markerit wrote, so later turns on the same agent need no connection. A rebuilt workspace has a new agent ID and is written again...,\or:, are not clean, or name the marker are rejected before any file is written. The pack then gets no files and no marker and is retried on the next turn.RefreshChatContexton its turns whose context the agent's push has marked dirty, until it pins an agent snapshot received after the pack was written (so a push from before the write, or one that caught only part of it, does not count), so a pack enabled for a pinned chat reaches the model by the next turn without a manual refresh, including chats that share the workspace with the chat that wrote it.filterPackResourcesalso drops rows whoseSKILL.md(or agent file) or manifest is not a file of the enabled pack's current commit, read once per pack and commit, since an update leaves removed files on disk.AsSystemRestricted: org members cannot read packs, and enabling a pack for a project or chat is what delivers its files to the chat's workspace. The pack name is validated again before it becomes a path.enabledPackNamesfrom feat(coderd/x/chatd): gate plugin packs by project and chat enablement #204 becomesenabledPacks, which also returns the ID and commit the materializer needs. A pack enabled in several places is written once per turn.coderd/x/chatd/ARCHITECTURE.mdgets a TODO for the materializer, for the human author.Known limitations
WriteFileround trips to the agent sometimes stalled while the rest finished in milliseconds. The per-write timeout and retry work around it; its root cause (agent, tailnet or netstack) is unproven.read_fileorexecute..claude-plugin/plugin.jsontoplugin.json(the stale manifest stays on disk and hides the pack until removed files are cleaned up); two packs whose names differ only by case on a case-insensitive (Windows) workspace; concurrent turns writing the same pack (identical bytes, duplicate work only); a malformed admin-installed pack with a path under.coder-pack-commit/(its marker write fails and it is retried each turn); symlinks a workspace user creates under~/.coder/plugins/redirect the writes, as the agent follows them.Follow-ups
Validation
go build ./coderd/... ./enterprise/...andgo vet ./coderd/x/chatd/.TestMaterializePluginPacks(against Postgres through dbauthz: writes files concurrently then a marker naming the pack, retries a write that stalls and still completes the pack, skips a known agent and commit without connecting, re-pins each dirty chat with the pack, writer or not, retries a re-pin of a snapshot from before the write, then stops, skips the write for a new agent ID whose marker matches, writes no file and no marker for a pack with an unsafe path, does nothing with no enabled pack),TestPackResourcePath,TestManagedPackName,TestFilterPackResources(now also drops rows whoseSKILL.mdor manifest the pack's current commit removed),TestAgentRowDefinitionsGatesPackAgents,TestPinnedWorkspaceContext,TestContextResources,TestForkAgentDefinition*, andTestResolveTurnWorkspaceContext.