A2A Worker
NOTE: Startup and cleanup are handled by worker-base. This skill defines the WORK PROCEDURE.
When to Use This Skill
Features involving:
- A2A server auto-start hook creation
- A2A client library development
- Router-to-A2A integration
- Cross-session communication via A2A HTTP
- A2A test suite development
Work Procedure
Read CTO Directive #3 from AGENTS.md: A2A server MUST be spawned as fully detached background subprocess. NEVER synchronous.
Study the existing pattern in .claude/hooks/channels/channel-auto-start.cjs:
- How it checks env vars and prerequisites
- How it uses lockfile with
wx flag for cooldown
- How it records PID in
terminal-pids.json
- How it spawns a detached process via
.bat file + start "" /D
- How it uses VBScript for auto-accept
Write tests first (red) for the component you're building:
- Auto-start hook: test lockfile creation, PID tracking, duplicate prevention
- Client library: test discovery, send, get, cancel, subscribe
- Router integration: test dispatch flow
Implement following existing A2A code patterns:
- Server code is in
.claude/lib/a2a/server.cjs (Express, JSON-RPC 2.0)
- Task state machine in
.claude/lib/a2a/task-state-machine.cjs
- Agent card in
.claude/lib/a2a/agent-card.cjs
- SSE in
.claude/lib/a2a/sse-stream.cjs
- JSON-RPC in
.claude/lib/a2a/jsonrpc-handler.cjs
For auto-start hook (a2a-server-autostart.cjs):
- Register as UserPromptSubmit hook in settings.json
- Check
A2A_AUTO_START=true env var
- Check not already inside A2A session
- Use atomic lockfile with 2-min cooldown
- Check terminal-pids.json for existing live PID
- Spawn via
.bat file + start "" /D pattern (Windows)
- Record PID in terminal-pids.json with purpose: 'a2a-server'
- Exit hook promptly (< 5 seconds)
For client library (client.cjs):
- Create at
.claude/lib/a2a/client.cjs
- Methods: discover(), sendTask(), getTask(), cancelTask(), sendSubscribe()
- Uses standard http/https module (no external dependencies)
- Handles JSON-RPC 2.0 request/response envelope
- Handles SSE streaming for subscribe
For router integration:
- Wire A2A client into the routing/dispatch flow
- Router can send tasks to channel session via A2A HTTP
- Handle task results and failures
Run tests:
node --test tests/lib/a2a/*.test.cjs
Verify coexistence with Telegram:
- Both auto-start hooks should work independently
- Separate lockfiles, separate PID entries
- No port conflicts
Commit with descriptive message.
Example Handoff
{
"salientSummary": "Created a2a-server-autostart.cjs hook following channel-auto-start.cjs pattern. Spawns Express server on port 3100 as detached background process via .bat file. Uses independent lockfile and PID tracking. Created A2A client at .claude/lib/a2a/client.cjs with discover/send/get/cancel/subscribe methods. Both Telegram and A2A auto-start work independently.",
"whatWasImplemented": "Auto-start hook with env check, lockfile, PID tracking, detached spawn. Client library with full JSON-RPC 2.0 support and SSE streaming. Both registered in settings.json.",
"whatWasLeftUndone": "",
"verification": {
"commandsRun": [
{
"command": "node --test tests/lib/a2a/a2a-server.test.cjs",
"exitCode": 0,
"observation": "All server tests pass"
},
{
"command": "node --test tests/lib/a2a/a2a-client.test.cjs",
"exitCode": 0,
"observation": "All client tests pass"
},
{ "command": "pnpm test:framework", "exitCode": 0, "observation": "No regressions" }
],
"interactiveChecks": []
},
"tests": {
"added": [
{
"file": "tests/lib/a2a/a2a-client.test.cjs",
"cases": [
{ "name": "discovers remote agent card", "verifies": "client discovery" },
{ "name": "sends task via JSON-RPC", "verifies": "task creation" },
{ "name": "polls task status", "verifies": "status retrieval" }
]
}
],
"coverage": "A2A server, client, and autostart hook covered"
},
"discoveredIssues": []
}
When to Return to Orchestrator
- Express server can't bind to port 3100 (port conflict)
- Telegram auto-start interferes with A2A auto-start
- Existing A2A server code has bugs that block integration
- Windows-specific spawn pattern doesn't work as expected
1---2name: a2a-worker3description: Builds A2A protocol integration - auto-start hook, client library, router wiring4---56# A2A Worker78NOTE: Startup and cleanup are handled by `worker-base`. This skill defines the WORK PROCEDURE.910## When to Use This Skill1112Features involving:1314- A2A server auto-start hook creation15- A2A client library development16- Router-to-A2A integration17- Cross-session communication via A2A HTTP18- A2A test suite development1920## Work Procedure21221. **Read CTO Directive #3 from AGENTS.md:** A2A server MUST be spawned as fully detached background subprocess. NEVER synchronous.23242. **Study the existing pattern** in `.claude/hooks/channels/channel-auto-start.cjs`:25 - How it checks env vars and prerequisites26 - How it uses lockfile with `wx` flag for cooldown27 - How it records PID in `terminal-pids.json`28 - How it spawns a detached process via `.bat` file + `start "" /D`29 - How it uses VBScript for auto-accept30313. **Write tests first (red)** for the component you're building:32 - Auto-start hook: test lockfile creation, PID tracking, duplicate prevention33 - Client library: test discovery, send, get, cancel, subscribe34 - Router integration: test dispatch flow35364. **Implement following existing A2A code patterns:**37 - Server code is in `.claude/lib/a2a/server.cjs` (Express, JSON-RPC 2.0)38 - Task state machine in `.claude/lib/a2a/task-state-machine.cjs`39 - Agent card in `.claude/lib/a2a/agent-card.cjs`40 - SSE in `.claude/lib/a2a/sse-stream.cjs`41 - JSON-RPC in `.claude/lib/a2a/jsonrpc-handler.cjs`42435. **For auto-start hook (`a2a-server-autostart.cjs`):**44 - Register as UserPromptSubmit hook in settings.json45 - Check `A2A_AUTO_START=true` env var46 - Check not already inside A2A session47 - Use atomic lockfile with 2-min cooldown48 - Check terminal-pids.json for existing live PID49 - Spawn via `.bat` file + `start "" /D` pattern (Windows)50 - Record PID in terminal-pids.json with purpose: 'a2a-server'51 - Exit hook promptly (< 5 seconds)52536. **For client library (`client.cjs`):**54 - Create at `.claude/lib/a2a/client.cjs`55 - Methods: discover(), sendTask(), getTask(), cancelTask(), sendSubscribe()56 - Uses standard http/https module (no external dependencies)57 - Handles JSON-RPC 2.0 request/response envelope58 - Handles SSE streaming for subscribe59607. **For router integration:**61 - Wire A2A client into the routing/dispatch flow62 - Router can send tasks to channel session via A2A HTTP63 - Handle task results and failures64658. **Run tests:**6667 ```68 node --test tests/lib/a2a/*.test.cjs69 ```70719. **Verify coexistence with Telegram:**72 - Both auto-start hooks should work independently73 - Separate lockfiles, separate PID entries74 - No port conflicts757610. **Commit** with descriptive message.7778## Example Handoff7980```json81{82 "salientSummary": "Created a2a-server-autostart.cjs hook following channel-auto-start.cjs pattern. Spawns Express server on port 3100 as detached background process via .bat file. Uses independent lockfile and PID tracking. Created A2A client at .claude/lib/a2a/client.cjs with discover/send/get/cancel/subscribe methods. Both Telegram and A2A auto-start work independently.",83 "whatWasImplemented": "Auto-start hook with env check, lockfile, PID tracking, detached spawn. Client library with full JSON-RPC 2.0 support and SSE streaming. Both registered in settings.json.",84 "whatWasLeftUndone": "",85 "verification": {86 "commandsRun": [87 {88 "command": "node --test tests/lib/a2a/a2a-server.test.cjs",89 "exitCode": 0,90 "observation": "All server tests pass"91 },92 {93 "command": "node --test tests/lib/a2a/a2a-client.test.cjs",94 "exitCode": 0,95 "observation": "All client tests pass"96 },97 { "command": "pnpm test:framework", "exitCode": 0, "observation": "No regressions" }98 ],99 "interactiveChecks": []100 },101 "tests": {102 "added": [103 {104 "file": "tests/lib/a2a/a2a-client.test.cjs",105 "cases": [106 { "name": "discovers remote agent card", "verifies": "client discovery" },107 { "name": "sends task via JSON-RPC", "verifies": "task creation" },108 { "name": "polls task status", "verifies": "status retrieval" }109 ]110 }111 ],112 "coverage": "A2A server, client, and autostart hook covered"113 },114 "discoveredIssues": []115}116```117118## When to Return to Orchestrator119120- Express server can't bind to port 3100 (port conflict)121- Telegram auto-start interferes with A2A auto-start122- Existing A2A server code has bugs that block integration123- Windows-specific spawn pattern doesn't work as expected