Skip to content

docs: update README with shipped library extraction, agent harness, MCP HTTP, Messages proxy#5

Closed
chazmaniandinkle wants to merge 19 commits intocogos-dev:mainfrom
chazmaniandinkle:docs/readme-update-shipped-work
Closed

docs: update README with shipped library extraction, agent harness, MCP HTTP, Messages proxy#5
chazmaniandinkle wants to merge 19 commits intocogos-dev:mainfrom
chazmaniandinkle:docs/readme-update-shipped-work

Conversation

@chazmaniandinkle
Copy link
Copy Markdown
Contributor

Summary

  • Documents the pkg/ library extraction: 7 importable Go packages (69 files, ~10.2K LOC, 190 tests) with a go.work multi-module workspace
  • Adds sections for the native Go agent harness (adaptive interval, 6 kernel tools, panic recovery, /v1/agent/status endpoint)
  • Documents MCP Streamable HTTP transport (8 tools: 4 kernel + 4 Mod3 bridged, JSON-RPC 2.0, session management)
  • Documents Anthropic Messages API proxy with streaming SSE passthrough
  • Adds embedded dashboard and cog claude usage to getting started
  • Updates API table, project layout, file counts (65 source / 42 test in engine), and ecosystem table (removes archived repos)
  • All claims verified against the actual codebase

Test plan

  • Verify all file counts match: find pkg/ -name "*.go" | wc -l returns 69
  • Verify test count: grep -r "func Test" pkg/ | wc -l returns 190
  • Verify engine file counts: 65 source, 42 test files in internal/engine/
  • Confirm pkg/bep dependency note is accurate (only non-stdlib dep is google.golang.org/protobuf)
  • Check all linked design docs still exist

🤖 Generated with Claude Code

chazmaniandinkle and others added 19 commits April 14, 2026 20:47
Set up Go workspace (go.work) with 7 new library modules under pkg/:
cogblock, bep, coordination, reconcile, modality, cogfield, uri.
Each module has a go.mod and doc.go stub. No code moved yet — this
establishes the skeleton so `go work sync` resolves all modules.

Implements ADR-074 layer 0-3 decomposition structure.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move the canonical CogBlock type definitions (CogBlockKind, BlockProvenance,
TrustContext, BlockArtifact) and the full ledger implementation (EventEnvelope,
canonicalization, hash chaining, AppendEvent, VerifyLedger) into the importable
pkg/cogblock library package with zero kernel dependencies.

The engine retains its own CogBlock struct with the typed Messages field
([]ProviderMessage) since that couples to provider internals. Shared types
are re-exported as type aliases for backward compatibility. The kernel's
ledger_core.go becomes a thin delegation layer.

17 new tests cover block JSON round-trips, kind constants, canonicalization,
hashing, hash chaining, and tamper detection.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Extracts the cog:// URI parsing, formatting, and validation logic into a
standalone stdlib-only package. Includes URI struct, Parse/String functions,
namespace registry, query helpers, inline reference extraction, and
structured error types. Resolution (filesystem lookup) stays in the kernel.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…reconcile

Moves the Reconcilable interface (7-method plan/apply contract), all type
definitions (State, Plan, Action, Summary, Result, status enums), state
management with lineage tracking, provider registry, event emission, and
meta-reconciler with Kahn's topological sort into pkg/reconcile as a
stdlib-only importable library.

Kernel files become thin re-export layers with type aliases and function
wrappers for backward compatibility. CLI commands, serve loop, watch mode,
and MCP tool integration remain in the kernel since they depend on runtime
internals (ResolveWorkspace, CogBus, field conditions).

34 tests in pkg/reconcile, all kernel reconcile tests continue to pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…kg/modality

Moves the core modality abstractions (Module interface, Bus, WireMessage,
SubprocessConn, ChannelRegistry, Salience, ProcessSupervisor, TextModule)
into pkg/modality as a stdlib-only reusable package. Kernel files become
thin re-export wrappers via type aliases, preserving backward compatibility.

Layer A (types + interfaces) and Layer B (bus, wire, supervisor) are
fully extracted. Layer C (ledger integration, HTTP modules, serve wiring,
tools, HUD) remains in the kernel where it depends on kernel-specific types.

33 tests cover bus dispatch, wire serialization, channel registry,
salience scoring, event validation, and text module lifecycle.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Selective extraction of the BEP (Block Exchange Protocol) types package
from the kernel. Moves wire-compatible protocol types, TLS/DeviceID
management, version vectors, index types, event types, and the framing
layer into an importable package. Creates Engine and SyncProvider
interfaces for decoupled consumption.

Files left in kernel (coupled to bus, AgentCRD, fsnotify):
  - bep_engine.go, bep_model.go, bep_provider.go, bep_receiver.go

52 tests covering proto round-trips, TLS cert gen, wire framing,
version vector logic, index scanning/diffing/persistence, and events.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move all CogField data types, pure functions, and interfaces into a
standalone package at pkg/cogfield/. The kernel retains HTTP handlers,
adapter implementations, and constellation/reconcile integration, importing
types from the package via aliases.

Extracted: Node, Edge, Stats, Graph, Block, GraphBlock, BlockAdapter,
AdapterNodeConfig, BlockTypeConfig, ExpandNodeResponse, BusDetail,
BusRegistryEntry, SessionMessage, SessionDetail, DocumentDetail, DocRef,
FieldCondition, TriggeredCondition, FieldConditionState, SignalFieldState,
PersistedSignal, SessionJSONLEvent.

Pure functions: NormalizeEntityType, InferSector, StrengthFromMetrics,
ParseCSVSet, FilterNodes, BFSSubgraph, ComputeStats, FilterByMeta,
GraphBlockToNode, ParseConditionQueryString, EvaluateFieldConditions,
ComputeRelevance, SignalIsActive, ExtractTimestamp.

21 tests covering construction, validation, JSON round-trip, BFS,
condition evaluation, and signal decay.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Thin observation-assessment-execution loop using a local model (Gemma E4B
via Ollama) through the OpenAI chat completions wire protocol. Runs as a
goroutine inside the kernel process with kernel-native tool dispatch.

- AgentHarness: assess (JSON mode) + execute (tool loop) + RunCycle
- 6 core tools: memory_search/read/write, coherence_check, bus_emit, workspace_status
- Self-contained wire protocol types (no harness package import)
- MaxTurns safety limit, context cancellation, tool error recovery
- 10 tests with httptest mock servers

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…e Code sessions

Adds a transparent proxy at POST /v1/messages that accepts Anthropic Messages
API requests, forwards them to the upstream Anthropic API, and streams SSE
responses back to the client. This enables Claude Code to route through the
kernel via ANTHROPIC_BASE_URL=http://localhost:5100.

- serve_messages.go: proxy handler with streaming/non-streaming support,
  header forwarding, API key resolution, bus event emission, and
  Anthropic-format error responses
- serve_messages_test.go: 8 tests covering non-streaming, streaming,
  error passthrough, header forwarding, auth, bearer auth, unreachable
  upstream, and tool_use event counting
- serve.go: mux registration and banner output
- cog.go: `cog claude` command that checks kernel health and launches
  claude with ANTHROPIC_BASE_URL set, falling back to direct launch

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- agent_serve.go: ServeAgent runs E4B via native harness on 30-min ticker
  - Gathers workspace observations (git, memory, coherence)
  - Calls E4B for assessment (sleep/consolidate/repair/observe/escalate)
  - Executes actions through kernel-native tool functions
  - Emits cycle events to CogBus
  - Configurable via COG_AGENT_INTERVAL, COG_AGENT_MODEL env vars
- serve_daemon.go: Wired into cog serve alongside reconciler
- serve.go: defaultServePort changed from 5100 to 6931 (5100 decommed)
- cog.go: cog claude uses single port check against 6931

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Agent loop starts at 5m, doubles toward 30m on consecutive "sleep" assessments,
  resets to 5m when action is needed (homeostatic backoff)
- Strip <think>...</think> tags from model responses before JSON parsing
  (Gemma 4 sometimes wraps output in thinking blocks even in JSON mode)
- Tighter system prompt: no markdown, no explanation, JSON only

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Use /api/chat instead of /v1/chat/completions (OpenAI compat)
- Set think: false explicitly to control thinking at the source
- Use format: "json" instead of response_format for structured output
- Arguments field is now json.RawMessage (Ollama returns object, not string)
- Remove stripThinkingTags — no longer needed when thinking is disabled properly
- Update all tests for native response format

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The agent harness was writing events to bus_agent_harness but never
registering it in the bus registry. This meant the bus was invisible
to /v1/bus/list and cross-bus event queries. ensureBus() now creates
the directory, events file, and registry entry during Start().

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The agent goroutine was dying silently after ~1-4.5 hours, likely from
an unrecovered panic in the Ollama HTTP call or JSON parsing. The
reconciler (separate goroutine) kept running, masking the failure.

Added safeCycle() wrapper with defer/recover around runCycle(). Panics
are now logged and the loop continues after the normal interval.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…t tab

- agent_serve.go: AgentStatusResponse struct, Status() method, tracks
  startedAt/lastAction/lastUrgency/lastReason/lastDurMs per cycle
- serve.go: GET /v1/agent/status endpoint, agent field on serveServer
- serve_dashboard.go: GET /dashboard serves embedded HTML dashboard
- dashboard.html: Agent status pill in header (▲ cycleCount · timeAgo),
  Agent tab with status card, cycle history from bus events, urgency sparkline
- Switched cycleCount from atomic to mutex-protected (consistent with other fields)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Rename mcp_http.go.wip → mcp_http.go, activating the Streamable HTTP
  transport (spec 2025-03-26) with session management, batch support,
  and bus integration
- Delete mcp_stub.go (replaced by full implementation)
- Add public HandleRequest() method on MCPServer for use by both stdio
  loop and HTTP transport
- Add NewMCPServerForHTTP() constructor (no stdin/stdout binding)
- Add busID/busManager fields to MCPServer for HTTP session bus tracking
- Add createMCPBus() on busSessionManager for MCP session buses
- Add BlockMCPSessionInit/BlockMCPSessionEnd constants
- Update protocol version from 2024-11-05 to 2025-03-26
- Add 4 Mod3 tools (mod3_speak, mod3_stop, mod3_voices, mod3_status)
  that proxy to Mod3's REST API on localhost:7860
- Mod3 URL configurable via MOD3_URL env var
- go build and go vet pass clean

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Two tests referenced features that don't exist yet:
- TestMCPHTTP_ToolCallEmitsBusEvents: tool.invoke/tool.result bus events
  not emitted by MCP handler (the tool router emits these, MCP doesn't yet)
- TestMCPHTTP_BusSendRead: cogos_bus_send/cogos_bus_read tools never built

Tests deferred (prefixed with _) with comments explaining what needs
implementing to re-enable them. No partial implementations to clean up —
the underlying infrastructure (BlockToolInvoke/Result constants, tool
router) is real and used by other paths.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Deleted TestMCPHTTP_ToolCallEmitsBusEvents and TestMCPHTTP_BusSendRead.
Both tested features that were never implemented:
- tool.invoke/tool.result bus emission from MCP handler (tool router
  handles this on its own path in bus_tool_router.go)
- cogos_bus_send/cogos_bus_read MCP tools (never built)

Tests should match implementation. No dead test code.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… Messages proxy

Reflects all shipped work that was missing from the README:
- pkg/ library extraction (7 packages, 69 files, ~10.2K LOC, 190 tests)
- Native Go agent harness with adaptive interval and 6 kernel tools
- MCP Streamable HTTP transport (8 tools, session management)
- Anthropic Messages API proxy with streaming SSE
- Embedded web dashboard with agent tab
- Port consolidation on 6931
- Updated file counts verified against codebase
- Removed archived repos (desktop) from ecosystem table

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@chazmaniandinkle
Copy link
Copy Markdown
Contributor Author

Superseded by #6 (clean rebase)

@chazmaniandinkle chazmaniandinkle deleted the docs/readme-update-shipped-work branch April 20, 2026 21:11
chazmaniandinkle added a commit that referenced this pull request Apr 21, 2026
…HTTP

Implements the v1 Config Mutation API per Agent O's design (closes Agent F
gap #5). Exposes kernel.yaml read + RFC 7396 merge-patch write + backup
rollback over both MCP (three tools + one resource) and HTTP (GET / PATCH /
POST /v1/config[/rollback]).

Key decisions per spec:
- RFC 7396 merge-patch semantics: missing keys preserved, explicit null
  deletes. Handler decodes raw JSON (preserves null-vs-absent distinction).
- Pre-write validation against the merged state (not the patch alone).
  Invalid patches return violations without touching disk.
- Atomic write via temp-file + rename. Dedicated package-scope helper in
  config_write.go; hook_working_memory.go's helper lives in package main
  and is unreachable from internal/engine, so we duplicate rather than
  promote.
- Rotating .bak-<timestamp> backups, keep the most recent 10.
- Pre-write refusal when the existing file is unparseable — LoadConfig's
  silent-swallow behaviour is preserved on read (not load-bearing) but we
  refuse to clobber corrupt YAML without an explicit rollback first.
- Global writeConfigMu serializes concurrent writes; last-writer-wins.
- v1 is write-to-disk + requires_restart: true. Reload-safety hint lives
  in the response's changed_fields so callers can reason about v1.5.
- Authentication: none — kernel assumes a trusted localhost caller.

20 new tests (14 unit + 6 wire) cover: full/sparse/null/v3 patches,
reload-safe hint, dry-run, validation rejection for port + heartbeat,
atomic write, 10-deep backup rotation, corrupt-file refusal, concurrent
writes, read+defaults, MCP roundtrip (read/write/rollback/resource), HTTP
GET/PATCH success + validation-failure shapes.

Tests pass with -race. No hot-reload, no auth — both are out-of-scope per
design.
chazmaniandinkle pushed a commit that referenced this pull request Apr 22, 2026
… gap

Closes Agent F gap #3 (session management, CRITICAL) — the last of the
eight critical MCP surface gaps. Implements the hybrid design in
cog://mem/semantic/surveys/2026-04-21-consolidation/
agent-P-session-management-evaluation with a few user-approved amendments
(see below).

Kernel changes
--------------
- internal/engine/sessions.go: typed SessionState, SessionRegistry,
  HandoffState, HandoffRegistry with RWMutex / Mutex guards; session-id
  format validation; idempotent-register "update semantics"; atomic
  first-wins claim with TTL enforcement; replay-from-bus at startup so
  the in-memory view rebuilds from bus_sessions + bus_handoffs.
- internal/engine/serve_sessions_mgmt.go: 8 HTTP handlers —
    POST /v1/sessions/register
    POST /v1/sessions/{id}/heartbeat
    POST /v1/sessions/{id}/end
    GET  /v1/sessions/presence
    POST /v1/handoffs/offer
    GET  /v1/handoffs
    POST /v1/handoffs/{id}/claim
    POST /v1/handoffs/{id}/complete
  The existing /v1/sessions and /v1/sessions/{id}[/context] routes (TAA
  inference context, regression-locked) are preserved untouched; the new
  specific patterns coexist thanks to Go 1.22 method-aware routing.
- internal/engine/mcp_sessions.go: 8 cog_* MCP tools over the same
  registries so a future native client (Wave widget, desktop app, cog
  CLI) can use handoff without the Python bridge (amendment #5 — two
  MCP surfaces coexist by design).
- internal/engine/sessions_test.go: 15 unit + integration tests
  (validation, lifecycle 404/409, active-window presence, task-field
  validation, 8-way concurrent claim atomicity, TTL expiry, phantom
  offer, complete-without-claim, replay rebuilds state, claim_rejected
  observability, end-to-end MCP round-trip).

Amendments applied vs the survey
--------------------------------
1. No parallel coexistence. All four consumers are in-tree (this PR,
   the bridge on a local branch, the skill doc, and cmd_bus.go);
   migrated atomically. The survey's Open Question #1 was skipped.
2. Idempotent register = update-semantics (survey's Open Question #2
   recommendation). Re-register during the active window updates the
   in-memory row; re-register after end is allowed if the prior row is
   ended or its heartbeat is outside the active window.
3. `handoff.claim_rejected` event emitted on every rejected claim, with
   reason ∈ {already_claimed, ttl_expired, offer_not_found,
   out_of_order}, attempting_session, and conflicting_session when
   relevant. Cheap; big audit value (amendment #4).
4. Two MCP surfaces coexist by design — 8 cogos_* bridge tools over the
   Python sandbox + 8 cog_* kernel-native tools via /mcp. Both hit the
   same kernel registries (amendment #5).

Bridge migration
----------------
A paired local branch on cog-sandbox-mcp (`feat/sessions-kernel-native-
bridge`, NOT pushed) refactors the 8 cogos_* tools to shim over the new
kernel routes, removes client-side aggregation, and rewrites
tests/test_session_handoff.py for the new wire shape. Bridge MCP
signatures and the never-raise {"success": False, "error": ..., "bus_id"}
envelope are preserved — no breaking change for agents using the bridge.

Testing
-------
- `go build ./...`, `go vet ./...`: silent.
- `go test ./internal/engine/... -short -race -count=1`: green
  (pre-existing + new suite passes under race detector).
- End-to-end smoke on port 6932 with a test workspace: register →
  heartbeat → offer → list → claim → second claim (→ 409 +
  claim_rejected event) → complete. bus_sessions chain: 3 events.
  bus_handoffs chain: 4 events (offer, claim, claim_rejected,
  complete). Bridge tools replayed the same flow against the live
  kernel with back-compat response shapes intact.
- The running kernel at :6931 was NOT touched during this work.

Survey reference: cog://mem/semantic/surveys/2026-04-21-consolidation/
agent-P-session-management-evaluation
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