Skip to content

ci: switch to self-hosted GKE runner - #74

Merged
samxu01 merged 11 commits into
v1.0.xfrom
happy-beacon-2
Apr 3, 2026
Merged

samxu01 merged 11 commits into
v1.0.xfrom
happy-beacon-2

Conversation

@samxu01

@samxu01 samxu01 commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Switches all workflows from ubuntu-latest to [self-hosted, linux].

Runner deployed as github-runner Deployment in commonly-dev namespace — uses existing idle GKE nodes, zero extra cost.

🤖 Generated with Claude Code
via Happy

samxu01 and others added 11 commits April 2, 2026 18:53
…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]>
All jobs changed from ubuntu-latest to [self-hosted, linux].
Runner deployed as github-runner deployment in commonly-dev namespace.

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]>
- setupTests.js: add __esModule:true, defaults, interceptors to axios mock
- App.test.js: remove incomplete axios override (no defaults/interceptors)
- Pod.test.js: remove duplicate axios mock, rely on setupTests
- PodSummary.test.js: wrap mock in __esModule:true + default:{...}
- AgentEnsemblePanel.test.js: same wrapping, move jest.mock before require
- ChatRoom.test.js: re-mock getBoundingClientRect after jest.resetAllMocks()

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]>
@samxu01
samxu01 merged commit c6d910b into v1.0.x Apr 3, 2026
3 of 5 checks passed
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]>

* ci: switch workflows to self-hosted GKE runner

All jobs changed from ubuntu-latest to [self-hosted, linux].
Runner deployed as github-runner deployment in commonly-dev namespace.

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 frontend test failures on Node.js 20

- setupTests.js: add __esModule:true, defaults, interceptors to axios mock
- App.test.js: remove incomplete axios override (no defaults/interceptors)
- Pod.test.js: remove duplicate axios mock, rely on setupTests
- PodSummary.test.js: wrap mock in __esModule:true + default:{...}
- AgentEnsemblePanel.test.js: same wrapping, move jest.mock before require
- ChatRoom.test.js: re-mock getBoundingClientRect after jest.resetAllMocks()

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]>

* ci: switch workflows to self-hosted GKE runner

All jobs changed from ubuntu-latest to [self-hosted, linux].
Runner deployed as github-runner deployment in commonly-dev namespace.

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 frontend test failures on Node.js 20

- setupTests.js: add __esModule:true, defaults, interceptors to axios mock
- App.test.js: remove incomplete axios override (no defaults/interceptors)
- Pod.test.js: remove duplicate axios mock, rely on setupTests
- PodSummary.test.js: wrap mock in __esModule:true + default:{...}
- AgentEnsemblePanel.test.js: same wrapping, move jest.mock before require
- ChatRoom.test.js: re-mock getBoundingClientRect after jest.resetAllMocks()

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]>
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