Skip to content

feat: discover custom agent definitions and persist them as subagent context resources - #38

Merged
ibetitsmike merged 9 commits into
mainfrom
mike/custom-agent-types-2-discovery
Nov 9, 2026
Merged

ibetitsmike merged 9 commits into
mainfrom
mike/custom-agent-types-2-discovery

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Xum opened this PR on behalf of @ibetitsmike.

Part of #7 (second PR of the custom agent types stack, on top of #31).

The workspace agent now discovers custom agent definition files and pushes each one to coderd as a subagent context resource. coderd stores it in workspace_agent_context_resources with body_kind = 'subagent'. Nothing reads these rows yet; the next PR lets chats spawn them by name.

  • Discovery runs under every scan root, in agents/, .agents/agents/, .claude/agents/ and .cursor/agents/, so ~/.coder/agents/ works through the ~/.coder root. A scan root that is itself an agents/ directory also works.
  • An agent container that resolves outside its scan root (a symlinked .claude/agents, for example) is skipped, because definitions are shipped whole. When .claude, .cursor or .agents exists but its agents/ directory does not, the watcher watches the parent so the directory is picked up when created.
  • Each *.md file goes through workspacesdk.ParseAgentDefinition (feat(codersdk/workspacesdk): parse custom agent definition files #31). A file without front-matter is skipped. A parse error gives status invalid. Warnings for unknown keys go in the row's error column, and the status stays ok. Symlinks that escape the scan root, unreadable files and oversize files get the same statuses as skills.
  • The first valid definition with a given name wins, as for skills. A definition whose source is already a resource (an AGENTS.md with front-matter in an agents scan root) is skipped, since coderd rejects pushes with duplicate sources.
  • The parser from feat(codersdk/workspacesdk): parse custom agent definition files #31 now rejects inline mcpServers server definitions instead of ignoring them with a warning: they often carry credentials in env or headers, and an invalid file's bytes are never shipped. Server names in mcpServers still work.
  • The watcher re-resolves on writes to agent definition files and on changes to agent containers.
  • SubagentBody (proto tag 100, clear of upstream tags) carries the whole file plus the parsed name and description, so coderd can later use the body as a system prompt without dialing the workspace.
  • Agent definition errors are truncated to 1024 bytes on a rune boundary. coderd rejects the whole push when any resource error is over 4096 bytes, so one definition with many unknown keys, or a long invalid name, would otherwise stop all context sync. UAT round 1 found this.

Hooks in upstream files are one line each (resolve.go, watcher.go, drpc.go, agentapi/context.go); the logic lives in fork_agents.go and fork_context.go. agent.pb.go is generated.

Validation:

  • go test ./agent/agentcontext/ ./codersdk/workspacesdk/, go vet, gofmt. The new error-cap test fails with the truncation removed and fails with the rune-boundary loop removed.
  • Remote UAT through Coder Agents on a dev deployment built from this branch, with real pstack definitions (poteto-agent, comment-sicko) checked byte for byte. Round 1 on 8071f13 passed every criterion and found the error-cap defect above. Round 2 on 65edd5c, which has the same diff against feat(codersdk/workspacesdk): parse custom agent definition files #31 that this PR had against main before the Codex fixes, re-tests the fix. The Codex fixes in 9d557af get a short follow-up round.

Known gaps, tracked on #7: user-level ~/.claude/agents and ~/.cursor/agents are not scan roots, and more than 500 definitions can push other definitions into excluded under the existing resource cap.

…ted MCP servers

Claude Code names the reasoning level `effort`; accept it, with
`reasoning_effort` taking precedence. Claude Code's `mcpServers` adds servers
to the inherited set instead of restricting it, so it no longer switches the
definition to a named allowlist.
coderd rejects a whole PushContextState request when any resource error
exceeds 4096 bytes. A definition with many unknown front-matter fields,
or a long invalid name quoted in the parse error, produced an unbounded
error and stopped every context resource from syncing. Truncate agent
definition errors to 1024 bytes on a rune boundary.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this on behalf of @ibetitsmike.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T09:41:55.865842Z 9d557af Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8fbea907d7

ℹ️ 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".

Comment thread agent/agentcontext/fork_agents.go Resolved
Comment thread agent/agentcontext/watcher.go Resolved
Comment thread agent/agentcontext/fork_agents.go Resolved
Comment thread agent/agentcontext/fork_agents.go Resolved
Comment thread agent/agentcontext/fork_agents.go Resolved
Comment thread agent/agentcontext/fork_agents.go Resolved
Comment thread agent/agentcontext/fork_agents.go Resolved
Comment thread agent/proto/agent.proto Resolved
- Skip agent containers that resolve outside their scan root, since
  definitions are shipped whole.
- Watch the existing parent of a missing container (such as .claude) so
  creating the container later is picked up.
- Skip a definition whose source is already a resource (an AGENTS.md in
  an agents scan root); coderd rejects pushes with duplicate sources.
- Reject inline mcpServers definitions, which often carry credentials,
  instead of shipping them with a warning.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this on behalf of @ibetitsmike.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9d557af4af

ℹ️ 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".

Comment thread agent/agentcontext/fork_agents.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 9d557af4af

ℹ️ 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".

@ibetitsmike
ibetitsmike merged commit 1c8be7b into main Nov 9, 2026
10 checks passed
@ibetitsmike
ibetitsmike deleted the mike/custom-agent-types-2-discovery branch November 9, 2026 11:31
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum (AI agent) merged this on behalf of @ibetitsmike.

Merge evidence at head 9d557af4af:

  • fork-ci pull_request checks all pass (schema, chat-tests, graph, forkdb, agent-sdk, build, site; fork-quiet green).
  • Codex receipt clean on 9d557af4af (09:41:54Z), 0 unresolved review threads, MERGEABLE/CLEAN.
  • Remote UAT round 3 PASS on this head (W1 coordinator).
  • Merged after the previous main commit 1e37dc0eee deployed healthy locally (buildinfo, migrations 640 clean, no new-process errors).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant