Skip to content

Commit 2c1aef2

Browse files
authored
feat: enrich generated docs with schema descriptions (#2)
1 parent da204ff commit 2c1aef2

File tree

7 files changed

+155
-42
lines changed

7 files changed

+155
-42
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ version: README.md schema/meta.json schema/schema.json
1111
echo $(ACP_VERSION) > $@
1212

1313
schema/meta.json: schema/version
14-
curl -o $@ --fail -L https://raw.githubusercontent.com/agentclientprotocol/agent-client-protocol/refs/tags/v$(ACP_VERSION)/schema/meta.json
14+
curl -o $@ --fail -L https://github.com/agentclientprotocol/agent-client-protocol/releases/download/v$(ACP_VERSION)/meta.json
1515

1616
schema/schema.json: schema/version
17-
curl -o $@ --fail -L https://raw.githubusercontent.com/agentclientprotocol/agent-client-protocol/refs/tags/v$(ACP_VERSION)/schema/schema.json
17+
curl -o $@ --fail -L https://github.com/agentclientprotocol/agent-client-protocol/releases/download/v$(ACP_VERSION)/schema.json
1818

1919
README.md: schema/version
2020
@command -v $(MDSH) >/dev/null || { echo "mdsh not found; run 'nix develop' or install it." 1>&2; exit 1; }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Learn more about the protocol itself at <https://agentclientprotocol.com>.
1414
<!-- `$ printf 'go get github.com/coder/acp-go-sdk@v%s\n' "$(cat schema/version)"` as bash -->
1515

1616
```bash
17-
go get github.com/coder/[email protected].5
17+
go get github.com/coder/[email protected].9
1818
```
1919

2020
## Get Started

cmd/generate/internal/emit/types.go

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ func WriteTypesJen(outDir string, schema *load.Schema, meta *load.Meta) error {
237237
case ir.BindAgentExperimental:
238238
target = &agentExperimentalMethods
239239
}
240+
if desc := methodDescription(schema, mi); desc != "" {
241+
*target = append(*target, Comment(util.SanitizeComment(desc)))
242+
}
240243
if mi.Notif != "" {
241244
name := ir.DispatchMethodNameForNotification(k, mi.Notif)
242245
*target = append(*target, Id(name).Params(Id("ctx").Qual("context", "Context"), Id("params").Id(mi.Notif)).Error())
@@ -276,6 +279,9 @@ func WriteTypesJen(outDir string, schema *load.Schema, meta *load.Meta) error {
276279
case ir.BindClientTerminal:
277280
target = &clientTerminal
278281
}
282+
if desc := methodDescription(schema, mi); desc != "" {
283+
*target = append(*target, Comment(util.SanitizeComment(desc)))
284+
}
279285
if mi.Notif != "" {
280286
name := ir.DispatchMethodNameForNotification(k, mi.Notif)
281287
*target = append(*target, Id(name).Params(Id("ctx").Qual("context", "Context"), Id("params").Id(mi.Notif)).Error())
@@ -359,6 +365,23 @@ func emitValidateJen(f *File, name string, def *load.Definition) {
359365
}
360366
}
361367

368+
func methodDescription(schema *load.Schema, mi *ir.MethodInfo) string {
369+
if mi == nil || mi.DocsIgnored {
370+
return ""
371+
}
372+
// Prefer notification descriptions when present, otherwise fall back to request/response types.
373+
ordered := []string{mi.Notif, mi.Req, mi.Resp}
374+
for _, name := range ordered {
375+
if name == "" {
376+
continue
377+
}
378+
if def := schema.Defs[name]; def != nil && def.Description != "" {
379+
return def.Description
380+
}
381+
}
382+
return ""
383+
}
384+
362385
// Type mapping helpers (unchanged behavior vs original)
363386
func primitiveJenType(t string) Code {
364387
switch t {
@@ -523,13 +546,14 @@ func jenTypeForOptional(d *load.Definition) Code {
523546
// (title: UnstructuredCommandInput) with a required 'hint' field.
524547
func emitUnion(f *File, name string, defs []*load.Definition, exactlyOne bool) {
525548
type variantInfo struct {
526-
fieldName string
527-
typeName string
528-
required []string
529-
isObject bool
530-
discValue string
531-
constPairs [][2]string
532-
isNull bool
549+
fieldName string
550+
typeName string
551+
required []string
552+
isObject bool
553+
discValue string
554+
constPairs [][2]string
555+
isNull bool
556+
description string
533557
}
534558
variants := []variantInfo{}
535559
discKey := ""
@@ -630,11 +654,23 @@ func emitUnion(f *File, name string, defs []*load.Definition, exactlyOne bool) {
630654
f.Type().Id(tname).Struct(st...)
631655
f.Line()
632656
}
633-
variants = append(variants, variantInfo{fieldName: fieldName, typeName: tname, required: v.Required, isObject: isObj, discValue: dv, constPairs: consts, isNull: isNull})
657+
variants = append(variants, variantInfo{
658+
fieldName: fieldName,
659+
typeName: tname,
660+
required: v.Required,
661+
isObject: isObj,
662+
discValue: dv,
663+
constPairs: consts,
664+
isNull: isNull,
665+
description: v.Description,
666+
})
634667
}
635668
// wrapper
636669
st := []Code{}
637670
for _, vi := range variants {
671+
if vi.description != "" {
672+
st = append(st, Comment(util.SanitizeComment(vi.description)))
673+
}
638674
st = append(st, Id(vi.fieldName).Op("*").Id(vi.typeName).Tag(map[string]string{"json": "-"}))
639675
}
640676
f.Type().Id(name).Struct(st...)

schema/schema.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@
3535
"anyOf": [
3636
{
3737
"$ref": "#/$defs/SessionNotification",
38+
"description": "Handles session update notifications from the agent.\n\nThis is a notification endpoint (no response expected) that receives\nreal-time updates about session progress, including message chunks,\ntool calls, and execution plans.\n\nNote: Clients SHOULD continue accepting tool call updates even after\nsending a `session/cancel` notification, as the agent may send final\nupdates before responding with the cancelled stop reason.\n\nSee protocol docs: [Agent Reports Output](https://agentclientprotocol.com/protocol/prompt-turn#3-agent-reports-output)",
3839
"title": "SessionNotification"
3940
},
4041
{
42+
"description": "Handles extension notifications from the agent.\n\nAllows the Agent to send an arbitrary notification that is not part of the ACP spec.\nExtension notifications provide a way to send one-way messages for custom functionality\nwhile maintaining protocol compatibility.\n\nSee protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)",
4143
"title": "ExtNotification"
4244
}
4345
],
@@ -48,37 +50,46 @@
4850
"anyOf": [
4951
{
5052
"$ref": "#/$defs/WriteTextFileRequest",
53+
"description": "Writes content to a text file in the client's file system.\n\nOnly available if the client advertises the `fs.writeTextFile` capability.\nAllows the agent to create or modify files within the client's environment.\n\nSee protocol docs: [Client](https://agentclientprotocol.com/protocol/overview#client)",
5154
"title": "WriteTextFileRequest"
5255
},
5356
{
5457
"$ref": "#/$defs/ReadTextFileRequest",
58+
"description": "Reads content from a text file in the client's file system.\n\nOnly available if the client advertises the `fs.readTextFile` capability.\nAllows the agent to access file contents within the client's environment.\n\nSee protocol docs: [Client](https://agentclientprotocol.com/protocol/overview#client)",
5559
"title": "ReadTextFileRequest"
5660
},
5761
{
5862
"$ref": "#/$defs/RequestPermissionRequest",
63+
"description": "Requests permission from the user for a tool call operation.\n\nCalled by the agent when it needs user authorization before executing\na potentially sensitive operation. The client should present the options\nto the user and return their decision.\n\nIf the client cancels the prompt turn via `session/cancel`, it MUST\nrespond to this request with `RequestPermissionOutcome::Cancelled`.\n\nSee protocol docs: [Requesting Permission](https://agentclientprotocol.com/protocol/tool-calls#requesting-permission)",
5964
"title": "RequestPermissionRequest"
6065
},
6166
{
6267
"$ref": "#/$defs/CreateTerminalRequest",
68+
"description": "Executes a command in a new terminal\n\nOnly available if the `terminal` Client capability is set to `true`.\n\nReturns a `TerminalId` that can be used with other terminal methods\nto get the current output, wait for exit, and kill the command.\n\nThe `TerminalId` can also be used to embed the terminal in a tool call\nby using the `ToolCallContent::Terminal` variant.\n\nThe Agent is responsible for releasing the terminal by using the `terminal/release`\nmethod.\n\nSee protocol docs: [Terminals](https://agentclientprotocol.com/protocol/terminals)",
6369
"title": "CreateTerminalRequest"
6470
},
6571
{
6672
"$ref": "#/$defs/TerminalOutputRequest",
73+
"description": "Gets the terminal output and exit status\n\nReturns the current content in the terminal without waiting for the command to exit.\nIf the command has already exited, the exit status is included.\n\nSee protocol docs: [Terminals](https://agentclientprotocol.com/protocol/terminals)",
6774
"title": "TerminalOutputRequest"
6875
},
6976
{
7077
"$ref": "#/$defs/ReleaseTerminalRequest",
78+
"description": "Releases a terminal\n\nThe command is killed if it hasn't exited yet. Use `terminal/wait_for_exit`\nto wait for the command to exit before releasing the terminal.\n\nAfter release, the `TerminalId` can no longer be used with other `terminal/*` methods,\nbut tool calls that already contain it, continue to display its output.\n\nThe `terminal/kill` method can be used to terminate the command without releasing\nthe terminal, allowing the Agent to call `terminal/output` and other methods.\n\nSee protocol docs: [Terminals](https://agentclientprotocol.com/protocol/terminals)",
7179
"title": "ReleaseTerminalRequest"
7280
},
7381
{
7482
"$ref": "#/$defs/WaitForTerminalExitRequest",
83+
"description": "Waits for the terminal command to exit and return its exit status\n\nSee protocol docs: [Terminals](https://agentclientprotocol.com/protocol/terminals)",
7584
"title": "WaitForTerminalExitRequest"
7685
},
7786
{
7887
"$ref": "#/$defs/KillTerminalCommandRequest",
88+
"description": "Kills the terminal command without releasing the terminal\n\nWhile `terminal/release` will also kill the command, this method will keep\nthe `TerminalId` valid so it can be used with other methods.\n\nThis method can be helpful when implementing command timeouts which terminate\nthe command as soon as elapsed, and then get the final output so it can be sent\nto the model.\n\nNote: `terminal/release` when `TerminalId` is no longer needed.\n\nSee protocol docs: [Terminals](https://agentclientprotocol.com/protocol/terminals)",
7989
"title": "KillTerminalCommandRequest"
8090
},
8191
{
92+
"description": "Handles extension method requests from the agent.\n\nAllows the Agent to send an arbitrary request that is not part of the ACP spec.\nExtension methods provide a way to add custom functionality while maintaining\nprotocol compatibility.\n\nSee protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)",
8293
"title": "ExtMethodRequest"
8394
}
8495
],
@@ -330,9 +341,11 @@
330341
"anyOf": [
331342
{
332343
"$ref": "#/$defs/CancelNotification",
344+
"description": "Cancels ongoing operations for a session.\n\nThis is a notification sent by the client to cancel an ongoing prompt turn.\n\nUpon receiving this notification, the Agent SHOULD:\n- Stop all language model requests as soon as possible\n- Abort all tool call invocations in progress\n- Send any pending `session/update` notifications\n- Respond to the original `session/prompt` request with `StopReason::Cancelled`\n\nSee protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/prompt-turn#cancellation)",
333345
"title": "CancelNotification"
334346
},
335347
{
348+
"description": "Handles extension notifications from the client.\n\nExtension notifications provide a way to send one-way messages for custom functionality\nwhile maintaining protocol compatibility.\n\nSee protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)",
336349
"title": "ExtNotification"
337350
}
338351
],
@@ -343,33 +356,41 @@
343356
"anyOf": [
344357
{
345358
"$ref": "#/$defs/InitializeRequest",
359+
"description": "Establishes the connection with a client and negotiates protocol capabilities.\n\nThis method is called once at the beginning of the connection to:\n- Negotiate the protocol version to use\n- Exchange capability information between client and agent\n- Determine available authentication methods\n\nThe agent should respond with its supported protocol version and capabilities.\n\nSee protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)",
346360
"title": "InitializeRequest"
347361
},
348362
{
349363
"$ref": "#/$defs/AuthenticateRequest",
364+
"description": "Authenticates the client using the specified authentication method.\n\nCalled when the agent requires authentication before allowing session creation.\nThe client provides the authentication method ID that was advertised during initialization.\n\nAfter successful authentication, the client can proceed to create sessions with\n`new_session` without receiving an `auth_required` error.\n\nSee protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)",
350365
"title": "AuthenticateRequest"
351366
},
352367
{
353368
"$ref": "#/$defs/NewSessionRequest",
369+
"description": "Creates a new conversation session with the agent.\n\nSessions represent independent conversation contexts with their own history and state.\n\nThe agent should:\n- Create a new session context\n- Connect to any specified MCP servers\n- Return a unique session ID for future requests\n\nMay return an `auth_required` error if the agent requires authentication.\n\nSee protocol docs: [Session Setup](https://agentclientprotocol.com/protocol/session-setup)",
354370
"title": "NewSessionRequest"
355371
},
356372
{
357373
"$ref": "#/$defs/LoadSessionRequest",
374+
"description": "Loads an existing session to resume a previous conversation.\n\nThis method is only available if the agent advertises the `loadSession` capability.\n\nThe agent should:\n- Restore the session context and conversation history\n- Connect to the specified MCP servers\n- Stream the entire conversation history back to the client via notifications\n\nSee protocol docs: [Loading Sessions](https://agentclientprotocol.com/protocol/session-setup#loading-sessions)",
358375
"title": "LoadSessionRequest"
359376
},
360377
{
361378
"$ref": "#/$defs/SetSessionModeRequest",
379+
"description": "Sets the current mode for a session.\n\nAllows switching between different agent modes (e.g., \"ask\", \"architect\", \"code\")\nthat affect system prompts, tool availability, and permission behaviors.\n\nThe mode must be one of the modes advertised in `availableModes` during session\ncreation or loading. Agents may also change modes autonomously and notify the\nclient via `current_mode_update` notifications.\n\nThis method can be called at any time during a session, whether the Agent is\nidle or actively generating a response.\n\nSee protocol docs: [Session Modes](https://agentclientprotocol.com/protocol/session-modes)",
362380
"title": "SetSessionModeRequest"
363381
},
364382
{
365383
"$ref": "#/$defs/PromptRequest",
384+
"description": "Processes a user prompt within a session.\n\nThis method handles the whole lifecycle of a prompt:\n- Receives user messages with optional context (files, images, etc.)\n- Processes the prompt using language models\n- Reports language model content and tool calls to the Clients\n- Requests permission to run tools\n- Executes any requested tool calls\n- Returns when the turn is complete with a stop reason\n\nSee protocol docs: [Prompt Turn](https://agentclientprotocol.com/protocol/prompt-turn)",
366385
"title": "PromptRequest"
367386
},
368387
{
369388
"$ref": "#/$defs/SetSessionModelRequest",
389+
"description": "**UNSTABLE**\n\nThis capability is not part of the spec yet, and may be removed or changed at any point.\n\nSelect a model for a given session.",
370390
"title": "SetSessionModelRequest"
371391
},
372392
{
393+
"description": "Handles extension method requests from the client.\n\nExtension methods provide a way to add custom functionality while maintaining\nprotocol compatibility.\n\nSee protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)",
373394
"title": "ExtMethodRequest"
374395
}
375396
],

schema/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.5
1+
0.4.9

0 commit comments

Comments
 (0)