Skip to content

feat(ai): unify agent chat lifecycle - #44

Open
moshloop wants to merge 18 commits into
mainfrom
feat/agent-chat-lifecycle
Open

feat(ai): unify agent chat lifecycle#44
moshloop wants to merge 18 commits into
mainfrom
feat/agent-chat-lifecycle

Conversation

@moshloop

@moshloop moshloop commented Aug 3, 2026

Copy link
Copy Markdown
Member

What

  • Add authenticated caller tools with durable execution, approvals, expiry, and revocation.
  • Unify session-backed chat lifecycles and canonical transcript rendering.
  • Expose prompt runtimes, explicit Save as flow, and cmux process inspection.

Notes

  • Includes Gavel workflow and React 19 type-definition upgrades.
  • Breaking changes affect read-only prompt updates, NewCodexAppServer, authoritative MCP execution, and canonical session JSON.

moshloop and others added 17 commits August 3, 2026 08:53
…ntly

Select an available Vite port by default while preserving strict behavior for explicit ports, and let Vite own browser opening in development. Resolve prompt setup through the shared shell configuration so working-directory semantics remain consistent.
… MCP

Add request-scoped, authenticated MCP capabilities for Claude and Codex agent providers, including shared tool policy resolution, schema validation, approvals, expiry, and revocation.
Propagate structured chat runtimes and agent prompts so new and resumed sessions receive consistent caller-owned tools, while disabled tool sets remain tool-free.
Advertise caller-tool support through model capabilities and catalogs.

BREAKING CHANGE: NewCodexAppServer now accepts ai.Config instead of a model string.
Add disabled-model filtering to whoami and expose exact backend/model runtime data for prompts.
Use canonical run requests for preview and execution, and require explicit Save as for read-only prompts to prevent implicit local forks.

BREAKING CHANGE: Updating a read-only prompt now fails; clients must use Save as/create to make an editable copy.
…-tool approvals

Persist chat execution identity, prompt runs, credential leases, and tool approval requests so caller tools are bound to the admitted session and can be revoked or revalidated throughout a run.
Route live approval resolutions through durable authority, recover approval state from stored thread messages, and propagate provider tool-use IDs through the Claude agent bridge.
BREAKING CHANGE: agent-backed caller tools now require an authoritative execution with MCP enabled
Keep runtime model metadata aligned with catalog capability defaults and verify disabled selections remain consistent under concurrent updates.
Expose process diagnostics for cmux surfaces, panes, workspaces, and individual PIDs. Report runtime, resource usage, listeners, process locations, and optional Go stacks for easier local debugging.

Claude-Session-Id: 019fc117-12df-7130-a435-2df0841694df
…ripts

Unwrap static sh/bash/zsh wrappers so rendered transcripts show the actual command while preserving shell flags and arguments. Centralize streaming and history output on canonical transcript rows, with safer tool-result handling and TTY redraw support. Preserve raw history serialization when explicitly requested.
Preserve one canonical transcript representation across Claude, Codex, and live agent events so wrapped shell commands display and serialize consistently.
Use stateful rendering with flush and error propagation for streamed output while avoiding duplicate rows across iterations.
BREAKING CHANGE: Message.Raw is no longer serialized in canonical session JSON
Claude-Session-Id: 019fc16e-32f2-7263-aeaa-d7cad6482315
Use the v0.0.54 action revision for lint and test jobs and align with its updated configuration interface.
Align the webapp's React and React DOM type packages with current React 19 declarations while keeping the runtime on React 18.
Expose cmux workspace, pane, and surface inspection through the CLI.
Resolve target process trees and present runtime, resource, listener, location, and optional Go stack details for easier debugging.
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Important

Review skipped

Too many files!

This PR contains 186 files, which is 86 over the limit of 100.

To get a review, narrow the scope:
• coderabbit review --committed # exclude uncommitted changes
• coderabbit review --dir # limit to a subdirectory
• coderabbit review --base # compare against a closer base

Upgrade to a paid plan to raise the limit.

This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9af96985-2025-465b-95d8-47e7815d188b

📥 Commits

Reviewing files that changed from the base of the PR and between ceff736 and 7c3ec6f.

⛔ Files ignored due to path filters (3)
  • pkg/cli/webapp/dist/.gitkeep is excluded by !**/dist/**
  • pkg/cli/webapp/dist/index.html is excluded by !**/dist/**
  • pkg/cli/webapp/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (186)
  • .github/workflows/test.yml
  • README.md
  • cmd/captain/main.go
  • go.mod
  • migrations/20_prompt_runs_and_plans.pg.hcl
  • migrations/30_execution.pg.hcl
  • migrations/31_execution_events.pg.hcl
  • migrations/32_execution_approvals.pg.hcl
  • migrations/60_view_session_overview.sql
  • migrations/merge_duplicate_sessions_integration_test.go
  • migrations/migrations_test.go
  • pkg/ai/adapters.go
  • pkg/ai/callertools/callertools_suite_test.go
  • pkg/ai/callertools/credential_ginkgo_test.go
  • pkg/ai/callertools/runtime.go
  • pkg/ai/callertools/runtime_ginkgo_test.go
  • pkg/ai/catalog_disabled_ginkgo_test.go
  • pkg/ai/catalog_info.go
  • pkg/ai/history/codex_normalize.go
  • pkg/ai/history/codex_normalize_ginkgo_test.go
  • pkg/ai/provider/caller_tools_ginkgo_test.go
  • pkg/ai/provider/claudeagent/agent.ts
  • pkg/ai/provider/claudeagent/attachments_ginkgo_test.go
  • pkg/ai/provider/claudeagent/bridge_params.go
  • pkg/ai/provider/claudeagent/caller_tools.go
  • pkg/ai/provider/claudeagent/caller_tools_ginkgo_test.go
  • pkg/ai/provider/claudeagent/fake_agent_test.go
  • pkg/ai/provider/claudeagent/interrupt_ginkgo_test.go
  • pkg/ai/provider/claudeagent/process_env.go
  • pkg/ai/provider/claudeagent/protocol.ts
  • pkg/ai/provider/claudeagent/provider.go
  • pkg/ai/provider/claudeagent/provider_test.go
  • pkg/ai/provider/claudeagent/runner.go
  • pkg/ai/provider/claudeagent/turn.go
  • pkg/ai/provider/codex_appserver.go
  • pkg/ai/provider/codex_appserver_approval.go
  • pkg/ai/provider/codex_appserver_lifecycle_ginkgo_test.go
  • pkg/ai/provider/codex_appserver_params_test.go
  • pkg/ai/provider/codex_appserver_process.go
  • pkg/ai/provider/codex_appserver_protocol.go
  • pkg/ai/provider/codex_appserver_test.go
  • pkg/ai/provider/codex_appserver_turn.go
  • pkg/ai/provider/genkit/approval.go
  • pkg/ai/provider/genkit/approval_checkpoint.go
  • pkg/ai/provider/genkit/options.go
  • pkg/ai/provider/genkit/tool_approval_ginkgo_test.go
  • pkg/ai/provider/genkit/tools.go
  • pkg/ai/provider/init.go
  • pkg/ai/runtime_selector_test.go
  • pkg/ai/tools/definitions_ginkgo_test.go
  • pkg/ai/tools/tools.go
  • pkg/aichat/agent_prompt.go
  • pkg/aichat/aimock_lifecycle_integration_test.go
  • pkg/aichat/approval_execution.go
  • pkg/aichat/approval_http.go
  • pkg/aichat/approval_resume.go
  • pkg/aichat/approval_resume_ginkgo_test.go
  • pkg/aichat/database_threads.go
  • pkg/aichat/database_threads_integration_test.go
  • pkg/aichat/events.go
  • pkg/aichat/execution.go
  • pkg/aichat/execution_authority_ginkgo_test.go
  • pkg/aichat/execution_database.go
  • pkg/aichat/execution_database_authority.go
  • pkg/aichat/execution_database_correlation.go
  • pkg/aichat/execution_database_integration_test.go
  • pkg/aichat/interrupt.go
  • pkg/aichat/messages.go
  • pkg/aichat/persistence.go
  • pkg/aichat/provider_config.go
  • pkg/aichat/service.go
  • pkg/aichat/service_ginkgo_test.go
  • pkg/aichat/service_helpers_ginkgo_test.go
  • pkg/aichat/sse.go
  • pkg/aichat/stream_ginkgo_test.go
  • pkg/aichat/threads.go
  • pkg/aichat/threads_http.go
  • pkg/aichat/wire.go
  • pkg/aichat/wire_ginkgo_test.go
  • pkg/aimock/anthropicmock/anthropicmock_suite_test.go
  • pkg/aimock/anthropicmock/health_ginkgo_test.go
  • pkg/aimock/anthropicmock/respond.go
  • pkg/aimock/anthropicmock/server.go
  • pkg/aimock/anthropicmock/server_test.go
  • pkg/aimock/anthropicmock/stream.go
  • pkg/aimock/anthropicmock/wire.go
  • pkg/aimock/journal.go
  • pkg/aimock/openaimock/cancellation_test.go
  • pkg/aimock/openaimock/chat.go
  • pkg/aimock/openaimock/namespace_ginkgo_test.go
  • pkg/aimock/openaimock/openaimock_suite_test.go
  • pkg/aimock/openaimock/respond.go
  • pkg/aimock/openaimock/responses.go
  • pkg/aimock/openaimock/server.go
  • pkg/aimock/openaimock/wire.go
  • pkg/aimock/request.go
  • pkg/aimock/sse.go
  • pkg/aimock/testdata/scenarios/chat-agent-flows.yaml
  • pkg/aimock/testdata/scenarios/chat-api-flows.yaml
  • pkg/aimock/testdata/scenarios/hold-open.yaml
  • pkg/api/registry/model.go
  • pkg/api/registry/provider.go
  • pkg/api/registry/providers.go
  • pkg/api/runtime_config.go
  • pkg/api/runtime_config_ginkgo_test.go
  • pkg/api/runtime_event.go
  • pkg/api/spec_merge_differential_test.go
  • pkg/api/tool_approval.go
  • pkg/bash/shell_transform.go
  • pkg/bash/shell_transform_ginkgo_test.go
  • pkg/claude/shell_transform_ginkgo_test.go
  • pkg/claude/tools/bash.go
  • pkg/claude/tools/bash_shell_ginkgo_test.go
  • pkg/claude/tooluse.go
  • pkg/cli/ai.go
  • pkg/cli/ai_agent.go
  • pkg/cli/ai_render_codex_test.go
  • pkg/cli/chat_thread_store.go
  • pkg/cli/chat_thread_store_test.go
  • pkg/cli/cmux_info.go
  • pkg/cli/cmux_info_ginkgo_test.go
  • pkg/cli/cmux_info_process.go
  • pkg/cli/cmux_info_render.go
  • pkg/cli/event_renderer.go
  • pkg/cli/event_renderer_ginkgo_test.go
  • pkg/cli/history.go
  • pkg/cli/history_render.go
  • pkg/cli/history_render_test.go
  • pkg/cli/prompt_entity.go
  • pkg/cli/prompt_entity_test.go
  • pkg/cli/prompt_records.go
  • pkg/cli/prompt_run_events.go
  • pkg/cli/prompt_runtimes_ginkgo_test.go
  • pkg/cli/prompt_schema_build.go
  • pkg/cli/prompt_schema_test.go
  • pkg/cli/serve.go
  • pkg/cli/serve_chat.go
  • pkg/cli/serve_disabled_test.go
  • pkg/cli/serve_port.go
  • pkg/cli/serve_port_ginkgo_test.go
  • pkg/cli/serve_test.go
  • pkg/cli/session_get.go
  • pkg/cli/session_get_multi_test.go
  • pkg/cli/stdin_claude_command_test.go
  • pkg/cli/webapp/package.json
  • pkg/cli/webapp/pnpm-workspace.yaml
  • pkg/cli/webapp/src/ChatLayer.tsx
  • pkg/cli/webapp/src/PromptRuntimeRows.test.tsx
  • pkg/cli/webapp/src/PromptRuntimeRows.tsx
  • pkg/cli/webapp/src/PromptWorkbench.test.ts
  • pkg/cli/webapp/src/PromptWorkbench.tsx
  • pkg/cli/webapp/src/PromptWriteModal.test.tsx
  • pkg/cli/webapp/src/PromptWriteModal.tsx
  • pkg/cli/webapp/src/WhoamiPage.test.tsx
  • pkg/cli/webapp/src/WhoamiPage.tsx
  • pkg/cli/webapp/src/hooks/usePromptRunStream.test.tsx
  • pkg/cli/webapp/src/promptData.ts
  • pkg/cli/webapp/src/promptRuntimeRowsHelpers.ts
  • pkg/cli/webapp/src/promptWorkbenchHelpers.ts
  • pkg/cli/whoami.go
  • pkg/cli/whoami_ginkgo_test.go
  • pkg/cli/whoami_render.go
  • pkg/cmux/cmux_suite_test.go
  • pkg/cmux/top.go
  • pkg/cmux/top_ginkgo_test.go
  • pkg/database/caller_tool_store.go
  • pkg/database/caller_tool_store_integration_test.go
  • pkg/database/database_error.go
  • pkg/database/prompt_run_operations.go
  • pkg/database/prompt_run_store.go
  • pkg/database/session_chat_store.go
  • pkg/database/session_hierarchy_ginkgo_test.go
  • pkg/database/session_ingest_store.go
  • pkg/database/session_message_ingest.go
  • pkg/database/session_prompt_store.go
  • pkg/database/session_read_store.go
  • pkg/database/store_integration_test.go
  • pkg/session/build_messages.go
  • pkg/session/message.go
  • pkg/session/pretty.go
  • pkg/session/pretty_compact_test.go
  • pkg/session/request.go
  • pkg/session/session.go
  • pkg/session/shell_transform_ginkgo_test.go
  • pkg/session/transcript_pretty.go
  • pkg/session/transcript_row_ginkgo_test.go

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

Gavel summary

Source Pass Fail Skip Duration

Totals: 0 passed · 0 failed · 0 skipped · -

View full results

@socket-security

socket-security Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​@​types/​react-dom@​19.2.31001007590100
Addednpm/​@​types/​react@​19.2.171001007994100

View full report

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

Gavel summary

Source Pass Fail Skip Duration
./pkg/cli/webapp 0 1 0 -
github.com/flanksource/captain/pkg/cli 464 2 0 7.8s
github.com/flanksource/captain/pkg/database 94 1 0 8.3s
migrations 2 1 0 1.5s
ai 74 0 0 15ms
aichat 60 0 2 5.7s
anthropicmock 1 0 0 2ms
api 45 0 0 38ms
attachments 5 0 0 8ms
bash 4 0 0 2ms
callertools 10 0 0 84ms
captain 3 0 0 281.215µs
claude 22 0 0 14ms
claudeagent 8 0 0 262ms
cli 156 0 0 2.0s
cmux 4 0 0 225.02µs
collections 12 0 0 403.276µs
credentials 5 0 0 33ms
database 15 0 0 2.4s
genkit 24 0 0 64ms
github.com/flanksource/captain/migrations 10 0 0 6.7s
github.com/flanksource/captain/pkg/ai 229 0 0 130ms
github.com/flanksource/captain/pkg/ai/agent 20 0 0 -
github.com/flanksource/captain/pkg/ai/agent/commit 43 0 0 3.4s
github.com/flanksource/captain/pkg/ai/agent/setup 16 0 0 50ms
github.com/flanksource/captain/pkg/ai/agent/verify 5 0 0 10ms
github.com/flanksource/captain/pkg/ai/agent/worktree 6 0 0 -
github.com/flanksource/captain/pkg/ai/assistanttags 15 0 0 -
github.com/flanksource/captain/pkg/ai/fixture 37 0 0 280ms
github.com/flanksource/captain/pkg/ai/fixture/kubeproxy 2 0 0 40ms
github.com/flanksource/captain/pkg/ai/fixture/mcpproxy 6 0 0 -
github.com/flanksource/captain/pkg/ai/history 48 0 0 -
github.com/flanksource/captain/pkg/ai/internal/gen-model-registry 12 0 0 -
github.com/flanksource/captain/pkg/ai/middleware 25 0 0 -
github.com/flanksource/captain/pkg/ai/pricing 6 0 0 10ms
github.com/flanksource/captain/pkg/ai/prompt 16 0 0 20ms
github.com/flanksource/captain/pkg/ai/provider 141 0 0 10ms
github.com/flanksource/captain/pkg/ai/provider/claudeagent 35 0 0 1.5s
github.com/flanksource/captain/pkg/ai/provider/cmux 117 0 0 870ms
github.com/flanksource/captain/pkg/ai/provider/genkit 36 0 0 -
github.com/flanksource/captain/pkg/ai/provider/jsonrpc 6 0 0 50ms
github.com/flanksource/captain/pkg/aimock 50 0 7 540ms
github.com/flanksource/captain/pkg/aimock/anthropicmock 14 0 0 10ms
github.com/flanksource/captain/pkg/aimock/openaimock 18 0 0 30ms
github.com/flanksource/captain/pkg/api 116 0 0 360ms
github.com/flanksource/captain/pkg/api/registry 96 0 0 -
github.com/flanksource/captain/pkg/bash 348 0 0 60ms
github.com/flanksource/captain/pkg/captainconfig 15 0 0 -
github.com/flanksource/captain/pkg/claude 138 0 0 -
github.com/flanksource/captain/pkg/claude/tools 13 0 0 -
github.com/flanksource/captain/pkg/cmux 1 0 0 -
github.com/flanksource/captain/pkg/codexconfig 10 0 0 10ms
github.com/flanksource/captain/pkg/container 72 0 1 -
github.com/flanksource/captain/pkg/dod 11 0 0 1m0s
github.com/flanksource/captain/pkg/monitor 54 0 0 2.2s
github.com/flanksource/captain/pkg/sandbox/presets 13 0 0 -
github.com/flanksource/captain/pkg/session 62 0 0 10ms
history 48 0 0 10ms
openaimock 2 0 0 192.871µs
provider 10 0 0 13ms
registry 38 0 0 1ms
session 11 0 0 9ms
tools 37 0 0 2ms

Totals: 3016 passed · 5 failed · 10 skipped · 1m45s

Failing tests

migrations — Captain duplicate session collapse > re-points a subagent at the surviving row instead of cascading it away

the process row was cascaded away with the ghost
Expected success, but got an error:
    <*errors.errorString | 0x76dc720>: 
    sql: no rows in result set
... (3 more lines truncated)

github.com/flanksource/captain/pkg/database — TestDurableSessionPromptRunAndPlanStores

�[2m09:23:07.307�[0m �[92mINF�[0m reusing existing embedded postgres on port 7432
    store_integration_test.go:69: 
        	Error Trace:	/home/runner/work/captain/captain/pkg/database/store_integration_test.go:69
        	Error:      	Not equal: 
... (17 more lines truncated)

github.com/flanksource/captain/pkg/cli — TestHandleSessionGetReturnsAllMatches

�[2m09:23:02.788�[0m �[92mINF�[0m reusing existing embedded postgres on port 7432
    serve_test.go:115: session = &{ID:5775c931-6cf2-48ba-92c8-e8bf5e6cd936 ProviderSessionID:sess-web Revision:0 LifecycleStatus: ActivityState: HealthState: StateReason: Source:claude Project:proj...

github.com/flanksource/captain/pkg/cli — TestRunSessionListAndGetClaude

�[2m09:23:06.164�[0m �[92mINF�[0m reusing existing embedded postgres on port 7432
�[2m09:23:06.443�[0m �[92mINF�[0m (monitor) ingesting 1 changed transcripts
    sessions_test.go:96: RunSessionGet: load canonical Captain session e2b1c992-5bfd-4c3a-8ff7-dd06dcc511db: captain chat session e2b1c992-5bfd-4c3a-8ff7-dd06dcc511db has source "claude"

vitest Execution

bash: line 1: pnpm: command not found

View full results

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