Repository navigation
feat: CAP — Commonly Agent Protocol (Phase 1, 2, 3) - #73
Merged
Merged
Conversation
…DE.md Defines Commonly's identity as the shared environment where agents from any origin connect and coexist alongside humans — not a runtime, but a rendezvous point and protocol (CAP, Commonly Agent Protocol). Key additions: - What Commonly Is: the join-protocol framing, public/self-hosted/federated - Architecture model: kernel (CAP) / drivers / user space / shell layers - Key concepts: CAP, runtimeType, agent portability, shell vs kernel - Design rules for Claude Code (6 principles) - Active implementation tracks mapped to GitHub issues #46, #57–#72 CAP is intentionally parallel to MCP (Model Context Protocol) — MCP = how agents use tools, CAP = how agents join social spaces. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]>
Three foundational specs for the Commonly Agent Protocol (CAP) platform: 1. CAP.md — the join protocol. Four stable HTTP interfaces any agent implements to connect to a Commonly instance. Runtime-agnostic. Intentionally parallel to MCP (tools) — CAP is how agents join spaces. 2. WEBHOOK_RUNTIME.md — runtimeType:'webhook' adapter spec. Any HTTP endpoint anywhere becomes a Commonly agent. Signed delivery, inline response, polling fallback, local dev workflow. 3. CLI.md — @commonly/cli spec. Developer interface to CAP: login, agent register/connect/logs, pod send/tail, dev up/down/test. 'commonly agent connect --port 3001' is the local dev loop. 4. CLAUDE_CODE_AGENT.md — Claude Code as a Commonly agent via Happy. The dogfood: the dev team building Commonly IS the first use case. claude-code runtime type already exists in agentIdentityService. Phase 1 needs only a session-token endpoint, no webhook adapter. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]>
Closes the dev loop: Claude Code (via Happy) can now join the Dev Team
pod as a Commonly agent without a full webhook adapter or provisioner.
Changes:
- User.agentRuntimeTokens: add expiresAt field (null = never expires;
set for session-scoped tokens issued per Happy session)
- agentRuntimeAuth: reject tokens with expiresAt < now (401 expired)
- POST /api/registry/admin/agents/claude-code/session-token (admin auth)
- gets/creates claude-code agent user for the given instanceId
- upserts AgentInstallation so the token is authorized for the pod
- ensures pod membership (plain ObjectId — Pod.members invariant)
- always issues a fresh cm_agent_* token with 24h expiry
- returns { token, agentName, instanceId, podId, podName, expiresAt }
Usage (Happy session start, targeting Dev Team pod):
POST /api/registry/admin/agents/claude-code/session-token
{ "podId": "69b7ddff0ce64c9648365fc4",
"instanceId": "sess-<sessionId>",
"displayName": "Claude Code · <session title>" }
The claude-code agent type already existed in agentIdentityService.
This wires up the token lifecycle and pod authorization around it.
Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Happy <[email protected]>
Any HTTP endpoint anywhere is now a Commonly agent.
Provisioner (Docker + K8s):
- runtimeType 'webhook' and 'claude-code' return early with
{ external: true } — no process to start/stop/provision
- getAgentRuntimeStatus returns { status: 'external' } for both
- Eliminates the throw for unknown runtimeTypes on external agents
Event delivery (agentEventService):
- After WebSocket push, queries active installations for webhookUrl
in config.runtime — fire-and-forget, never blocks the event queue
- deliverEventViaWebhook: POST with X-Commonly-Signature (HMAC-SHA256),
X-Commonly-Event, X-Commonly-Delivery headers; 10s timeout
- Inline response: { outcome, content? } — if outcome='posted' with
content, posts message to pod on agent's behalf via agentMessageService
- Acknowledges event in DB on successful delivery
- All errors are logged (never thrown) to protect the event queue
Registration: no schema changes needed — AgentInstallation.config is
already a Map<String, Mixed>; store webhookUrl/webhookSecret under
config.runtime when installing via POST /api/registry/install.
To register a webhook agent:
POST /api/registry/install
{ agentName, podId, version, runtimeType: 'webhook',
config: { runtime: { webhookUrl: '...', webhookSecret: '...' } } }
Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Happy <[email protected]>
Developer CLI for the Commonly Agent Protocol. Zero build step — ESM,
Node 20+, single dependency (commander). Everything talks to the same
CAP HTTP interfaces built in Phases 1 and 2.
Commands:
login / whoami — auth to any instance, stored in ~/.commonly/config.json
supports multiple named instances (default, local, custom)
agent register — register a webhook agent (runtimeType:'webhook')
agent connect — local dev loop: poll events → forward to localhost:PORT/cap
works against remote GKE or local ./dev.sh instance
agent list / logs — inspect installations and event stream
agent heartbeat — trigger dev agent manually
pod list / send / tail — browse, post, and watch pod messages live
dev up / down / logs/test — wraps ./dev.sh; auto-saves 'local' instance config
dev status — health check against localhost:5000
Full developer workflow:
commonly dev up
commonly login --instance http://localhost:5000 --key local
commonly agent connect --name my-agent --port 3001
# agent code at localhost:3001/cap receives signed event POSTs
Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Happy <[email protected]>
15 tests covering: - HMAC-SHA256 signature format, determinism, and verification - Webhook delivery end-to-end with real local HTTP server - Inline response handling (posted, no_action, acknowledged) - No-op when webhookUrl is null or runtime config is missing - expiresAt field on agentRuntimeTokens (Phase 1 schema) Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]>
All 108 backend suites (571 tests) now pass. 15 CLI tests added.
Test fixes (22 suites → 0 failing):
- db-pg: add pool.on mock (called at module load time)
- PgMessage: update INSERT assertion to 5-arg signature
- pgStatusController: mock query to resolve { rowCount:1 }
- posts route: add toggleAgentComments to postController mock
- userController: add toObject() to mock docs; use objectContaining
- agentsRuntime dm-events: getOrCreateAgentDM → getOrCreateAdminDMPod
- discordService: fetchMessages uses channelId/botToken args; result field is authorName not author
- registry.heartbeat-file/persona: Pod/AgentProfile.findById → mockReturnValue({ lean })
- registry.list-agents-config: add AgentEvent.aggregate mock
- globalModelConfigService: expect 3 Gemini fallback models (not 2)
- agentEnsemble.config: User.findById → mockReturnValue({ select })
- agentMessageService.summary: rename getOrCreateAgentDM → getOrCreateAdminDMPod;
update HEARTBEAT_OK/diagnostic suppression shapes; heartbeat diagnostics now always
route to DM (ownerDm flag doesn't gate this path)
- agentProvisionerService: AGENT_PROVISIONER_K8S=0 in beforeEach; await async calls;
'commonly tools' → 'runtime-token' in heartbeat prompt assertion
- agentProvisionerServiceK8s: primary model gpt-5.4-nano (was gemini); fallbacks include nemotron
- agentAvatarService: case-insensitive SVG assertion
- agentEnsembleService: min-participants check fires before active-discussion check
- auth integration: auto-verify behavior in test env (typeof verified === 'boolean')
- messages integration: PGMessage.create 5th null arg
- clawdbot-e2e: afterEach resets bot agentRuntimeTokens; revoke checks User model;
empty-content post returns 200 skipped (not 500)
- integrations-e2e: same afterEach agentRuntimeTokens reset
- summaries route: ChatSummarizerService → chatSummarizerService (instance method)
- agentEnsembleService: fix undefined spread in toObject()
New tests (CAP Phase 1–3):
- cap/session-token.test.js: 8 tests for POST /admin/agents/claude-code/session-token
- cap/external-runtimes.test.js: 6 tests for runtimeType webhook/claude-code → external:true
- cli/__tests__/lib.test.mjs: 15 ESM tests for config.js, webhook-server.js, poller.js
Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Happy <[email protected]>
…, global-require, numeric separators) - clawdbot-e2e: replace for loops with Promise.all + eslint-disable block for intentionally sequential loop - integrations-e2e: fix import order, i++ → i+=1, eslint-disable-next-line for describe-level requires, remove shadowing DiscordIntegration re-require - cap/session-token, cap/webhook-delivery: replace ES2021 numeric separators with plain numbers (ecmaVersion: 2020) - cap/webhook-delivery: fix no-promise-executor-return in stopServer Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]>
This was referenced Apr 3, 2026
samxu01
pushed a commit
that referenced
this pull request
Apr 3, 2026
* docs: add product vision, architecture model, and CAP concept to CLAUDE.md Defines Commonly's identity as the shared environment where agents from any origin connect and coexist alongside humans — not a runtime, but a rendezvous point and protocol (CAP, Commonly Agent Protocol). Key additions: - What Commonly Is: the join-protocol framing, public/self-hosted/federated - Architecture model: kernel (CAP) / drivers / user space / shell layers - Key concepts: CAP, runtimeType, agent portability, shell vs kernel - Design rules for Claude Code (6 principles) - Active implementation tracks mapped to GitHub issues #46, #57–#72 CAP is intentionally parallel to MCP (Model Context Protocol) — MCP = how agents use tools, CAP = how agents join social spaces. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]> * docs: spec CAP, webhook runtime, CLI, and Claude Code agent Three foundational specs for the Commonly Agent Protocol (CAP) platform: 1. CAP.md — the join protocol. Four stable HTTP interfaces any agent implements to connect to a Commonly instance. Runtime-agnostic. Intentionally parallel to MCP (tools) — CAP is how agents join spaces. 2. WEBHOOK_RUNTIME.md — runtimeType:'webhook' adapter spec. Any HTTP endpoint anywhere becomes a Commonly agent. Signed delivery, inline response, polling fallback, local dev workflow. 3. CLI.md — @commonly/cli spec. Developer interface to CAP: login, agent register/connect/logs, pod send/tail, dev up/down/test. 'commonly agent connect --port 3001' is the local dev loop. 4. CLAUDE_CODE_AGENT.md — Claude Code as a Commonly agent via Happy. The dogfood: the dev team building Commonly IS the first use case. claude-code runtime type already exists in agentIdentityService. Phase 1 needs only a session-token endpoint, no webhook adapter. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]> * feat: CAP Phase 1 — claude-code session-token endpoint Closes the dev loop: Claude Code (via Happy) can now join the Dev Team pod as a Commonly agent without a full webhook adapter or provisioner. Changes: - User.agentRuntimeTokens: add expiresAt field (null = never expires; set for session-scoped tokens issued per Happy session) - agentRuntimeAuth: reject tokens with expiresAt < now (401 expired) - POST /api/registry/admin/agents/claude-code/session-token (admin auth) - gets/creates claude-code agent user for the given instanceId - upserts AgentInstallation so the token is authorized for the pod - ensures pod membership (plain ObjectId — Pod.members invariant) - always issues a fresh cm_agent_* token with 24h expiry - returns { token, agentName, instanceId, podId, podName, expiresAt } Usage (Happy session start, targeting Dev Team pod): POST /api/registry/admin/agents/claude-code/session-token { "podId": "69b7ddff0ce64c9648365fc4", "instanceId": "sess-<sessionId>", "displayName": "Claude Code · <session title>" } The claude-code agent type already existed in agentIdentityService. This wires up the token lifecycle and pod authorization around it. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]> * feat: CAP Phase 2 — webhook runtime adapter (runtimeType: 'webhook') Any HTTP endpoint anywhere is now a Commonly agent. Provisioner (Docker + K8s): - runtimeType 'webhook' and 'claude-code' return early with { external: true } — no process to start/stop/provision - getAgentRuntimeStatus returns { status: 'external' } for both - Eliminates the throw for unknown runtimeTypes on external agents Event delivery (agentEventService): - After WebSocket push, queries active installations for webhookUrl in config.runtime — fire-and-forget, never blocks the event queue - deliverEventViaWebhook: POST with X-Commonly-Signature (HMAC-SHA256), X-Commonly-Event, X-Commonly-Delivery headers; 10s timeout - Inline response: { outcome, content? } — if outcome='posted' with content, posts message to pod on agent's behalf via agentMessageService - Acknowledges event in DB on successful delivery - All errors are logged (never thrown) to protect the event queue Registration: no schema changes needed — AgentInstallation.config is already a Map<String, Mixed>; store webhookUrl/webhookSecret under config.runtime when installing via POST /api/registry/install. To register a webhook agent: POST /api/registry/install { agentName, podId, version, runtimeType: 'webhook', config: { runtime: { webhookUrl: '...', webhookSecret: '...' } } } Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]> * feat: CAP Phase 3 — @commonly/cli skeleton Developer CLI for the Commonly Agent Protocol. Zero build step — ESM, Node 20+, single dependency (commander). Everything talks to the same CAP HTTP interfaces built in Phases 1 and 2. Commands: login / whoami — auth to any instance, stored in ~/.commonly/config.json supports multiple named instances (default, local, custom) agent register — register a webhook agent (runtimeType:'webhook') agent connect — local dev loop: poll events → forward to localhost:PORT/cap works against remote GKE or local ./dev.sh instance agent list / logs — inspect installations and event stream agent heartbeat — trigger dev agent manually pod list / send / tail — browse, post, and watch pod messages live dev up / down / logs/test — wraps ./dev.sh; auto-saves 'local' instance config dev status — health check against localhost:5000 Full developer workflow: commonly dev up commonly login --instance http://localhost:5000 --key local commonly agent connect --name my-agent --port 3001 # agent code at localhost:3001/cap receives signed event POSTs Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]> * chore: mark cli entry point executable * test: CAP unit tests — webhook delivery and session token expiry 15 tests covering: - HMAC-SHA256 signature format, determinism, and verification - Webhook delivery end-to-end with real local HTTP server - Inline response handling (posted, no_action, acknowledged) - No-op when webhookUrl is null or runtime config is missing - expiresAt field on agentRuntimeTokens (Phase 1 schema) Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]> * test: fix 22 failing test suites + add CAP Phase 1-3 coverage All 108 backend suites (571 tests) now pass. 15 CLI tests added. Test fixes (22 suites → 0 failing): - db-pg: add pool.on mock (called at module load time) - PgMessage: update INSERT assertion to 5-arg signature - pgStatusController: mock query to resolve { rowCount:1 } - posts route: add toggleAgentComments to postController mock - userController: add toObject() to mock docs; use objectContaining - agentsRuntime dm-events: getOrCreateAgentDM → getOrCreateAdminDMPod - discordService: fetchMessages uses channelId/botToken args; result field is authorName not author - registry.heartbeat-file/persona: Pod/AgentProfile.findById → mockReturnValue({ lean }) - registry.list-agents-config: add AgentEvent.aggregate mock - globalModelConfigService: expect 3 Gemini fallback models (not 2) - agentEnsemble.config: User.findById → mockReturnValue({ select }) - agentMessageService.summary: rename getOrCreateAgentDM → getOrCreateAdminDMPod; update HEARTBEAT_OK/diagnostic suppression shapes; heartbeat diagnostics now always route to DM (ownerDm flag doesn't gate this path) - agentProvisionerService: AGENT_PROVISIONER_K8S=0 in beforeEach; await async calls; 'commonly tools' → 'runtime-token' in heartbeat prompt assertion - agentProvisionerServiceK8s: primary model gpt-5.4-nano (was gemini); fallbacks include nemotron - agentAvatarService: case-insensitive SVG assertion - agentEnsembleService: min-participants check fires before active-discussion check - auth integration: auto-verify behavior in test env (typeof verified === 'boolean') - messages integration: PGMessage.create 5th null arg - clawdbot-e2e: afterEach resets bot agentRuntimeTokens; revoke checks User model; empty-content post returns 200 skipped (not 500) - integrations-e2e: same afterEach agentRuntimeTokens reset - summaries route: ChatSummarizerService → chatSummarizerService (instance method) - agentEnsembleService: fix undefined spread in toObject() New tests (CAP Phase 1–3): - cap/session-token.test.js: 8 tests for POST /admin/agents/claude-code/session-token - cap/external-runtimes.test.js: 6 tests for runtimeType webhook/claude-code → external:true - cli/__tests__/lib.test.mjs: 15 ESM tests for config.js, webhook-server.js, poller.js Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]> * fix: resolve lint errors in test files (no-plusplus, no-await-in-loop, global-require, numeric separators) - clawdbot-e2e: replace for loops with Promise.all + eslint-disable block for intentionally sequential loop - integrations-e2e: fix import order, i++ → i+=1, eslint-disable-next-line for describe-level requires, remove shadowing DiscordIntegration re-require - cap/session-token, cap/webhook-delivery: replace ES2021 numeric separators with plain numbers (ecmaVersion: 2020) - cap/webhook-delivery: fix no-promise-executor-return in stopServer Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]> --------- Co-authored-by: Claude <[email protected]> Co-authored-by: Happy <[email protected]>
MubaiHua
pushed a commit
that referenced
this pull request
Apr 20, 2026
* docs: add product vision, architecture model, and CAP concept to CLAUDE.md Defines Commonly's identity as the shared environment where agents from any origin connect and coexist alongside humans — not a runtime, but a rendezvous point and protocol (CAP, Commonly Agent Protocol). Key additions: - What Commonly Is: the join-protocol framing, public/self-hosted/federated - Architecture model: kernel (CAP) / drivers / user space / shell layers - Key concepts: CAP, runtimeType, agent portability, shell vs kernel - Design rules for Claude Code (6 principles) - Active implementation tracks mapped to GitHub issues #46, #57–#72 CAP is intentionally parallel to MCP (Model Context Protocol) — MCP = how agents use tools, CAP = how agents join social spaces. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]> * docs: spec CAP, webhook runtime, CLI, and Claude Code agent Three foundational specs for the Commonly Agent Protocol (CAP) platform: 1. CAP.md — the join protocol. Four stable HTTP interfaces any agent implements to connect to a Commonly instance. Runtime-agnostic. Intentionally parallel to MCP (tools) — CAP is how agents join spaces. 2. WEBHOOK_RUNTIME.md — runtimeType:'webhook' adapter spec. Any HTTP endpoint anywhere becomes a Commonly agent. Signed delivery, inline response, polling fallback, local dev workflow. 3. CLI.md — @commonly/cli spec. Developer interface to CAP: login, agent register/connect/logs, pod send/tail, dev up/down/test. 'commonly agent connect --port 3001' is the local dev loop. 4. CLAUDE_CODE_AGENT.md — Claude Code as a Commonly agent via Happy. The dogfood: the dev team building Commonly IS the first use case. claude-code runtime type already exists in agentIdentityService. Phase 1 needs only a session-token endpoint, no webhook adapter. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]> * feat: CAP Phase 1 — claude-code session-token endpoint Closes the dev loop: Claude Code (via Happy) can now join the Dev Team pod as a Commonly agent without a full webhook adapter or provisioner. Changes: - User.agentRuntimeTokens: add expiresAt field (null = never expires; set for session-scoped tokens issued per Happy session) - agentRuntimeAuth: reject tokens with expiresAt < now (401 expired) - POST /api/registry/admin/agents/claude-code/session-token (admin auth) - gets/creates claude-code agent user for the given instanceId - upserts AgentInstallation so the token is authorized for the pod - ensures pod membership (plain ObjectId — Pod.members invariant) - always issues a fresh cm_agent_* token with 24h expiry - returns { token, agentName, instanceId, podId, podName, expiresAt } Usage (Happy session start, targeting Dev Team pod): POST /api/registry/admin/agents/claude-code/session-token { "podId": "69b7ddff0ce64c9648365fc4", "instanceId": "sess-<sessionId>", "displayName": "Claude Code · <session title>" } The claude-code agent type already existed in agentIdentityService. This wires up the token lifecycle and pod authorization around it. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]> * feat: CAP Phase 2 — webhook runtime adapter (runtimeType: 'webhook') Any HTTP endpoint anywhere is now a Commonly agent. Provisioner (Docker + K8s): - runtimeType 'webhook' and 'claude-code' return early with { external: true } — no process to start/stop/provision - getAgentRuntimeStatus returns { status: 'external' } for both - Eliminates the throw for unknown runtimeTypes on external agents Event delivery (agentEventService): - After WebSocket push, queries active installations for webhookUrl in config.runtime — fire-and-forget, never blocks the event queue - deliverEventViaWebhook: POST with X-Commonly-Signature (HMAC-SHA256), X-Commonly-Event, X-Commonly-Delivery headers; 10s timeout - Inline response: { outcome, content? } — if outcome='posted' with content, posts message to pod on agent's behalf via agentMessageService - Acknowledges event in DB on successful delivery - All errors are logged (never thrown) to protect the event queue Registration: no schema changes needed — AgentInstallation.config is already a Map<String, Mixed>; store webhookUrl/webhookSecret under config.runtime when installing via POST /api/registry/install. To register a webhook agent: POST /api/registry/install { agentName, podId, version, runtimeType: 'webhook', config: { runtime: { webhookUrl: '...', webhookSecret: '...' } } } Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]> * feat: CAP Phase 3 — @commonly/cli skeleton Developer CLI for the Commonly Agent Protocol. Zero build step — ESM, Node 20+, single dependency (commander). Everything talks to the same CAP HTTP interfaces built in Phases 1 and 2. Commands: login / whoami — auth to any instance, stored in ~/.commonly/config.json supports multiple named instances (default, local, custom) agent register — register a webhook agent (runtimeType:'webhook') agent connect — local dev loop: poll events → forward to localhost:PORT/cap works against remote GKE or local ./dev.sh instance agent list / logs — inspect installations and event stream agent heartbeat — trigger dev agent manually pod list / send / tail — browse, post, and watch pod messages live dev up / down / logs/test — wraps ./dev.sh; auto-saves 'local' instance config dev status — health check against localhost:5000 Full developer workflow: commonly dev up commonly login --instance http://localhost:5000 --key local commonly agent connect --name my-agent --port 3001 # agent code at localhost:3001/cap receives signed event POSTs Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]> * chore: mark cli entry point executable * test: CAP unit tests — webhook delivery and session token expiry 15 tests covering: - HMAC-SHA256 signature format, determinism, and verification - Webhook delivery end-to-end with real local HTTP server - Inline response handling (posted, no_action, acknowledged) - No-op when webhookUrl is null or runtime config is missing - expiresAt field on agentRuntimeTokens (Phase 1 schema) Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]> * test: fix 22 failing test suites + add CAP Phase 1-3 coverage All 108 backend suites (571 tests) now pass. 15 CLI tests added. Test fixes (22 suites → 0 failing): - db-pg: add pool.on mock (called at module load time) - PgMessage: update INSERT assertion to 5-arg signature - pgStatusController: mock query to resolve { rowCount:1 } - posts route: add toggleAgentComments to postController mock - userController: add toObject() to mock docs; use objectContaining - agentsRuntime dm-events: getOrCreateAgentDM → getOrCreateAdminDMPod - discordService: fetchMessages uses channelId/botToken args; result field is authorName not author - registry.heartbeat-file/persona: Pod/AgentProfile.findById → mockReturnValue({ lean }) - registry.list-agents-config: add AgentEvent.aggregate mock - globalModelConfigService: expect 3 Gemini fallback models (not 2) - agentEnsemble.config: User.findById → mockReturnValue({ select }) - agentMessageService.summary: rename getOrCreateAgentDM → getOrCreateAdminDMPod; update HEARTBEAT_OK/diagnostic suppression shapes; heartbeat diagnostics now always route to DM (ownerDm flag doesn't gate this path) - agentProvisionerService: AGENT_PROVISIONER_K8S=0 in beforeEach; await async calls; 'commonly tools' → 'runtime-token' in heartbeat prompt assertion - agentProvisionerServiceK8s: primary model gpt-5.4-nano (was gemini); fallbacks include nemotron - agentAvatarService: case-insensitive SVG assertion - agentEnsembleService: min-participants check fires before active-discussion check - auth integration: auto-verify behavior in test env (typeof verified === 'boolean') - messages integration: PGMessage.create 5th null arg - clawdbot-e2e: afterEach resets bot agentRuntimeTokens; revoke checks User model; empty-content post returns 200 skipped (not 500) - integrations-e2e: same afterEach agentRuntimeTokens reset - summaries route: ChatSummarizerService → chatSummarizerService (instance method) - agentEnsembleService: fix undefined spread in toObject() New tests (CAP Phase 1–3): - cap/session-token.test.js: 8 tests for POST /admin/agents/claude-code/session-token - cap/external-runtimes.test.js: 6 tests for runtimeType webhook/claude-code → external:true - cli/__tests__/lib.test.mjs: 15 ESM tests for config.js, webhook-server.js, poller.js Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]> * fix: resolve lint errors in test files (no-plusplus, no-await-in-loop, global-require, numeric separators) - clawdbot-e2e: replace for loops with Promise.all + eslint-disable block for intentionally sequential loop - integrations-e2e: fix import order, i++ → i+=1, eslint-disable-next-line for describe-level requires, remove shadowing DiscordIntegration re-require - cap/session-token, cap/webhook-delivery: replace ES2021 numeric separators with plain numbers (ecmaVersion: 2020) - cap/webhook-delivery: fix no-promise-executor-return in stopServer Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]> --------- Co-authored-by: Claude <[email protected]> Co-authored-by: Happy <[email protected]>
samxu01
pushed a commit
that referenced
this pull request
Oct 21, 2026
…d the webhook runtime doc (TASK-005) ADR-004 says the kernel never POSTs to a driver and delivers at least once. Push shipped in #73 (2026-04-02), twelve days before the ADR, and every install with config.runtime.webhookUrl is pushed to. A failed push stays pending and nothing sends it again: the requeue acts only on delivered rows, the stranded-pending sweep covers in-process agents only, and the GC deletes the row after the retention, 168 h by default. Nor is push at most once: a 307 or 308 replays the same POST within one attempt, up to six requests in all. - ADR-004: conformance entry C4, plus an inline marker at each of the six sentences it contradicts and at the rejected push alternative. C4 names the two changes push has had since #73: #822 and #2188. - ADR-006: pointers at the two non-goals that repeat the claim. The second also called webhookSecret unused; it signs each push. - WEBHOOK_RUNTIME.md: the 30-minute failed-close it described applies only to in-process agents. A failed push is never sent again, and a redirect can replay one, so a receiver dedupes on X-Commonly-Delivery. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-authored-by: wren <[email protected]> Agent-Model: claude/claude-opus-5-5/max
samxu01
pushed a commit
that referenced
this pull request
Oct 22, 2026
…d the webhook runtime doc (TASK-005) ADR-004 says the kernel never POSTs to a driver and delivers at least once. Push shipped in #73 (2026-04-02), twelve days before the ADR, and every install with config.runtime.webhookUrl is pushed to. A failed push stays pending and nothing sends it again: the requeue acts only on delivered rows, the stranded-pending sweep covers in-process agents only, and the GC deletes the row after the retention, 168 h by default. Nor is push at most once: a 307 or 308 replays the same POST within one attempt, up to six requests in all. - ADR-004: conformance entry C4, plus an inline marker at each of the six sentences it contradicts and at the rejected push alternative. C4 names the two changes push has had since #73: #822 and #2188. - ADR-006: pointers at the two non-goals that repeat the claim. The second also called webhookSecret unused; it signs each push. - WEBHOOK_RUNTIME.md: the 30-minute failed-close it described applies only to in-process agents. A failed push is never sent again, and a redirect can replay one, so a receiver dedupes on X-Commonly-Delivery. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-authored-by: wren <[email protected]> Agent-Model: claude/claude-opus-5-5/max
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CLAUDE.md— 4-layer model, design rules, implementation tracksPOST /api/registry/admin/agents/claude-code/session-token— issues 24h session-scopedcm_agent_*tokens for Claude Code / Happy.expiresAtfield added toagentRuntimeTokensschema; expiry enforced inagentRuntimeAuthmiddleware.runtimeType: 'webhook'registered as external no-op in both Docker and K8s provisioners.agentEventService.deliverEventViaWebhooksigns events (HMAC-SHA256X-Commonly-Signature), POSTs to the agent'swebhookUrl, and handles inline{ outcome, content }responses.@commonly/cliskeleton (cli/package) —commonly login,commonly agent register/connect/list/logs/heartbeat,commonly pod list/send/tail,commonly dev up/down/logs/test/status.agent connectbridges a poller → local webhook server for local dev loops.docs/architecture/CAP.md,WEBHOOK_RUNTIME.md,CLI.md,CLAUDE_CODE_AGENT.mdexpiresAtschemaTest plan
backend/__tests__/unit/cap/webhook-delivery.test.js— 15/15 passingcommonly login,commonly agent register --webhook <url>, event delivery to a local serverPOST /api/registry/admin/agents/claude-code/session-tokenreturns valid token; expired token rejected with 401🤖 Generated with Claude Code
via Happy