diff --git a/.beads/interactions.jsonl b/.beads/interactions.jsonl index aa8e7621d..448f1b5cd 100644 --- a/.beads/interactions.jsonl +++ b/.beads/interactions.jsonl @@ -142,3 +142,4 @@ {"id":"int-79a8456ef9c42caa9babbca0e87b0e63","kind":"field_change","created_at":"2026-07-26T17:44:49.347208513Z","actor":"Sam Catlow","issue_id":"archie-core-abg.17.16","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Stdio transport implemented: JSON-RPC framing, subprocess lifecycle, auto-restart with exponential backoff. Two rounds of adversarial review found and fixed: dead SendTimeout field, Start()/Stop() TOCTOU race, and a Start()/attemptRestart-vs-Stop() race (extracted into shared commitSpawnedProcess guard). Final review: zero findings."}} {"id":"int-73d136618f699f155055eb438881117a","kind":"field_change","created_at":"2026-07-26T17:44:50.351097372Z","actor":"Sam Catlow","issue_id":"archie-core-abg.17.23","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"Adversarial review completed across two rounds; all findings fixed and re-verified clean."}} {"id":"int-545cf6991d178c87be720cda75a8cecb","kind":"field_change","created_at":"2026-07-26T17:44:50.845655116Z","actor":"Sam Catlow","issue_id":"archie-core-abg.17.41","extra":{"field":"status","new_value":"closed","old_value":"blocked","reason":"Blocking dependency abg.17.16 closed; tool-provider engine work was already implementation-complete and previously reviewed clean."}} +{"id":"int-1b6bdffe51700db83938f5128b005a97","kind":"field_change","created_at":"2026-07-26T18:57:43.797683721Z","actor":"Sam Catlow","issue_id":"archie-core-abg.16.32","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Implemented via go-telegram/bot v1.22.0 rich messages. gateway.LLMStreamResponder + Router.RouteStream provide the streaming seam (degrades to Route when unset); telegram draft.go streams deltas through sendRichMessageDraft throttled to 700ms; main.go derives blocking and streaming responders from one shared turn impl using runtime.ChatStream. Also removed the markdownToHTML converter from the prior commit -- v1.22 takes Markdown natively and supports tables, so the conversion was unnecessary. 4 RouteStream tests; full suite + golangci-lint clean."}} diff --git a/.beads/issues.jsonl b/.beads/issues.jsonl index 205aad3fb..770b0c207 100644 --- a/.beads/issues.jsonl +++ b/.beads/issues.jsonl @@ -52,7 +52,7 @@ {"_type":"issue","id":"archie-core-abg.18","title":"[EPIC] Memory: pluggable provider architecture with file-backed persistence","description":"Pluggable memory system to match Hermes parity:\\n\\n1. **MemoryProvider interface**: Abstract interface with methods for initialize(), get_tool_schemas(), prefetch(), sync_turn(), and optional lifecycle hooks (on_session_end, on_session_switch, on_pre_compress, on_memory_write).\\n\\n2. **Built-in file-backed memory**: MEMORY.md and USER.md stored per-session/profile. LLM-callable memory tool with add/replace/remove actions. Frozen snapshot at session start (preserves prefix cache), immediate disk write on updates. Section-sign delimited entries with substring matching.\\n\\n3. **MemoryManager**: Orchestrates built-in + at most one external provider. Background serialized write executor. Prefetch with timeout (8s). Streaming context scrubber that strips injected memory spans from model output.\\n\\nRef: docs/prds/hermes-gap-analysis.md section 4","acceptance_criteria":"An external memory provider (e.g. Honcho, Mem0) can be plugged in via config. The built-in memory tool persists across sessions. Conversation context is recalled on session resume.","status":"open","priority":0,"issue_type":"epic","owner":"sam@catlow.tech","created_at":"2026-07-25T14:02:22Z","created_by":"Sam Catlow","updated_at":"2026-07-25T14:02:22Z","dependencies":[{"issue_id":"archie-core-abg.18","depends_on_id":"archie-core-abg","type":"parent-child","created_at":"2026-07-26T00:02:22Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"archie-core-abg.16","title":"[EPIC] Gateway: rich message model, adapter lifecycle, session management","description":"Foundational gateway infrastructure to match Hermes parity. Three interdependent pieces:\\n\\n1. **Message model**: Replace the 3-field Message struct with a rich MessageEvent (MessageType enum: text/photo/video/audio/voice/document/sticker/command, media_urls, reply_to context, metadata dict, source). This is the wire type every adapter produces.\\n\\n2. **Adapter lifecycle**: Replace the 3-method Gateway interface with a BasePlatformAdapter interface: connect()/disconnect()/send() as required methods, plus optional overrides for typing indicators, edit/delete, image/voice/video/document send, interactive UX (clarify buttons, approval dialogs). Capability flags (supports_code_blocks, splits_long_messages, supports_async_delivery).\\n\\n3. **Session management**: SessionSource struct (platform, chat_id, chat_type, user_id, thread_id, guild_id, profile), AsyncSessionStore for persistent session storage, SessionContext for system prompt injection.\\n\\nAll three blocks together enable adding new platforms as plugins without touching core gateway code.\\n\\nRef: docs/prds/hermes-gap-analysis.md sections 1-2","acceptance_criteria":"New adapters can be added by implementing a Go interface with connect/disconnect/send + optional media methods. Messages carry full metadata through the pipeline. Sessions persist across gateway restarts.","status":"open","priority":0,"issue_type":"epic","owner":"sam@catlow.tech","created_at":"2026-07-25T14:02:21Z","created_by":"Sam Catlow","updated_at":"2026-07-25T14:02:21Z","dependencies":[{"issue_id":"archie-core-abg.16","depends_on_id":"archie-core-abg","type":"parent-child","created_at":"2026-07-26T00:02:21Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"archie-core-jfg","title":"Spawned archie-agent containers not on daemon's docker network — can't reach NATS","description":"Root cause of 'agent still failing on the server': archied's container.Pool.Acquire creates archie-agent containers via the Docker SDK with no NetworkMode set, so Docker attaches them to the default bridge network. archied and nats run on the compose-created 'archie-core_default' network instead, so the spawned container's hostname resolution for 'nats' (from NATS_URL=nats://nats:4222) fails and archie-agent can't connect. Confirmed on carina host logs: archied logs show repeating 'taskrun request failed err=\"nats: no responders available for request\"' for every task, containers created and destroyed within ~1.5s (consistent with archie-agent's NATS client failing fast). Fixed by detecting the daemon's own container's network in NewPool (selfNetwork, via ContainerInspect on os.Hostname()) and setting HostConfig.NetworkMode on spawned containers to match.","status":"closed","priority":0,"issue_type":"bug","owner":"sam@catlow.tech","created_at":"2026-07-24T03:10:26Z","created_by":"Sam Catlow","updated_at":"2026-07-25T13:04:34Z","closed_at":"2026-07-25T13:04:34Z","close_reason":"Fix already implemented and verified: selfNetwork() in internal/container/pool.go detects the daemon's own container network via ContainerInspect(os.Hostname()) and Acquire() sets HostConfig.NetworkMode to match, so spawned archie-agent containers join the same compose network as nats. Build and internal/container tests pass.","dependency_count":0,"dependent_count":0,"comment_count":0} -{"_type":"issue","id":"archie-core-abg.16.32","title":"Telegram: stream LLM replies via sendMessageDraft","description":"Chat replies currently block for the whole LLM turn, then arrive as one message. The typing indicator masks the wait but shows no progress. go-telegram/bot exposes SendMessageDraft (see examples/streaming_draft) and ai-sdk's runtime.ChatStream already returns core.StreamResult with a TextStream \u003c-chan string, so both halves exist -- only the gateway seam is missing, since gateway.LLMResponder is func(ctx, Message) (string, error) and cannot emit partial output.","acceptance_criteria":"Gateway exposes an optional streaming responder; Router falls back to the blocking path when unset. Telegram adapter streams deltas into a draft, then finalises with a formatted SendMessage. Draft updates are throttled to respect Telegram rate limits. Streaming failure falls back to a normal send rather than losing the reply.","status":"in_progress","priority":1,"issue_type":"feature","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-07-26T18:52:20Z","created_by":"Sam Catlow","updated_at":"2026-07-26T18:52:30Z","started_at":"2026-07-26T18:52:30Z","dependencies":[{"issue_id":"archie-core-abg.16.32","depends_on_id":"archie-core-abg.16","type":"parent-child","created_at":"2026-07-27T04:52:20Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0} +{"_type":"issue","id":"archie-core-abg.16.32","title":"Telegram: stream LLM replies via sendMessageDraft","description":"Chat replies currently block for the whole LLM turn, then arrive as one message. The typing indicator masks the wait but shows no progress. go-telegram/bot exposes SendMessageDraft (see examples/streaming_draft) and ai-sdk's runtime.ChatStream already returns core.StreamResult with a TextStream \u003c-chan string, so both halves exist -- only the gateway seam is missing, since gateway.LLMResponder is func(ctx, Message) (string, error) and cannot emit partial output.","acceptance_criteria":"Gateway exposes an optional streaming responder; Router falls back to the blocking path when unset. Telegram adapter streams deltas into a draft, then finalises with a formatted SendMessage. Draft updates are throttled to respect Telegram rate limits. Streaming failure falls back to a normal send rather than losing the reply.","status":"closed","priority":1,"issue_type":"feature","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-07-26T18:52:20Z","created_by":"Sam Catlow","updated_at":"2026-07-26T18:57:44Z","started_at":"2026-07-26T18:52:30Z","closed_at":"2026-07-26T18:57:44Z","close_reason":"Implemented via go-telegram/bot v1.22.0 rich messages. gateway.LLMStreamResponder + Router.RouteStream provide the streaming seam (degrades to Route when unset); telegram draft.go streams deltas through sendRichMessageDraft throttled to 700ms; main.go derives blocking and streaming responders from one shared turn impl using runtime.ChatStream. Also removed the markdownToHTML converter from the prior commit -- v1.22 takes Markdown natively and supports tables, so the conversion was unnecessary. 4 RouteStream tests; full suite + golangci-lint clean.","dependencies":[{"issue_id":"archie-core-abg.16.32","depends_on_id":"archie-core-abg.16","type":"parent-child","created_at":"2026-07-27T04:52:20Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"archie-core-50z","title":"Enforce typed plugin engine architecture rule","description":"Cement the repository invariant that a plugin engine is a typed capability family with an owning registry/manager and lifecycle semantics, never a generic daemon hook. Add one canonical architecture rule referenced by both AGENTS.md and CLAUDE.md, record it in Beads memory, and add an executable architecture test that prevents drift without touching the concurrently edited secret/config packages.","acceptance_criteria":"A canonical rule defines typed domain contract, owning registry/manager, lifecycle and health expectations, narrow host access, and trust boundaries; AGENTS.md and CLAUDE.md both surface the rule through their shared source; an architecture test fails for generic plugin-hook expansion or an engine interface without a family manager; focused tests and task check pass; fresh adversarial review has no surviving findings.","notes":"Complete. Red proof: architecture test failed on missing canonical rule. Green: internal/plugin tests pass; golangci-lint ./internal/plugin reports zero issues; gofumpt diff is empty. Fresh adversarial review initially found bypassable owner checks and ambiguous trust wording; remediated with signature-linked single-owner validation, negative fixtures (metadata-only, embedded-only, unrelated/split owners, pointer and collection wrappers), and precise trusted-in-process/out-of-process/container language. Final fresh review: zero surviving findings. Full task check was attempted but is currently blocked by concurrent unrelated migrations: gateway fakeTaskCreator still implements CreateTask(context.Context,string) while interface now wants SpawnRequest, and daemon EnqueueIssue callers omit the new eighth argument. No secret/config source was edited by this issue.","status":"closed","priority":1,"issue_type":"task","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-07-26T05:00:36Z","created_by":"Sam Catlow","updated_at":"2026-07-26T05:14:06Z","started_at":"2026-07-26T05:00:43Z","closed_at":"2026-07-26T05:14:06Z","close_reason":"Strict plugin-engine invariant documented in canonical architecture and shared AGENTS/CLAUDE instructions, persisted in Beads memory, mechanically enforced with adversarial negative controls, and independently reviewed with zero findings.","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"archie-core-abg.39","title":"MVP: migrate Hermes profiles, memory, skills, and session state","description":"The copied live Hermes instance contains root plus agile-lead, dev, and local-agent profiles with distinct models, gateways, memories, SOUL prompts, skills, sessions, and cron state. archie-core currently has forge identities but no profile-scoped gateway/tool/memory/workspace composition and no importer. Define the mapping into archie-core identities/profiles and build a one-time idempotent migration plus cutover rehearsal.","acceptance_criteria":"Document and implement the mapping for all copied profiles -- MAPPING DOCUMENTED (docs/prds/hermes-migration-dry-run.md), NOT YET IMPLEMENTED (blocked on abg.36). Import SOUL/USER/MEMORY/skills/session/cron without secrets -- NOT STARTED (design-blocked on abg.36, see report). Produce a dry-run report -- DONE. Rehearse dual-run/shadow validation and rollback-safe cutover checklist -- NOT STARTED.","notes":"Dry-run inventory + mapping report delivered: docs/prds/hermes-migration-dry-run.md. Surveyed .hermes-carina/ (live copy of the Hermes deployment) structurally only -- directory listings and non-secret YAML top-level keys, zero secret file contents read (.env/auth.json/mcp-tokens/ explicitly excluded and never opened). Found and catalogued 4 environments (main/agile-lead/dev/local-agent), their skill counts (34/20/25/17), main's 419 session keys (sessions/sessions.json), cron jobs.json presence. Proposed a mapping table: environment-\u003eIdentityConfig, SOUL.md-\u003enew persona system-prompt field (no existing archie-core field for this), memories/-\u003einternal/memory.Manager (needs format translator), skills/-\u003einternal/skill.Catalog (closest 1:1, needs tool-compat pass), sessions-\u003egateway.SessionStore (needs translator), cron/jobs.json-\u003eblocked, no archie-core cron subsystem exists yet (abg.24 territory). Documented explicit exclusion list for the eventual importer (secrets never copied). Documented why actual import tooling is blocked until abg.36 lands (no point importing SOUL/memory/skills into a runtime that doesn't consume them per-turn yet) -- this report is prep, not the importer itself.","status":"in_progress","priority":1,"issue_type":"feature","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-07-26T04:37:09Z","created_by":"Sam Catlow","updated_at":"2026-07-26T05:16:40Z","started_at":"2026-07-26T05:14:49Z","dependencies":[{"issue_id":"archie-core-abg.39","depends_on_id":"archie-core-abg","type":"parent-child","created_at":"2026-07-26T14:37:08Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"archie-core-abg.35","title":"Audit Hermes-to-archie-core MVP takeover gaps","description":"Compare the copied live Hermes state in .hermes-carina with archie-core's current runtime and backlog. Determine the minimum remaining work for archie-core to replace Hermes on carina, explicitly excluding the in-flight secret engine and provider/config work.","acceptance_criteria":"Document current capability parity, concrete blockers, minimum migration sequence, and non-MVP deferrals with file and issue evidence; do not modify implementation code.","notes":"Verdict: not cutover-ready. The copied live surface is root plus three profiles; connected Telegram/email/webhook gateways; 419 persisted session records across root state; one scheduled Gitea Monitor with Telegram delivery; enabled Linear/Gitea MCP; and actual use of terminal/file/patch/web/memory/session/delegation/process tools. Critical gaps: gateway chat is a one-step runtime.Chat call with no tools; email/webhook have nil responders; tool registry/MCP/memory are not wired end-to-end; rich gateway abstractions are parallel dead code; Telegram is instantiated with an empty allowlist; chat /spawn fabricates a forge issue and /approve,/cancel are absent; multi-identity is not composed or ownership-safe; no profile/state importer; cron/delivery/auth/webhook parity remain open. Filed abg.36 full gateway agent loop, abg.37 identity routing, abg.38 native chat tasks, abg.39 migration/cutover. Existing MVP dependencies: abg.17 stdio MCP completion, abg.22 authorization subset, abg.23 delivery, abg.24 scheduler, abg.27 webhook HMAC/filter/template/dedup subset. Focused gateway/channel/memory/tools/daemon/cmd tests passed when rerun with local socket access.","status":"closed","priority":1,"issue_type":"task","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-07-26T04:28:15Z","created_by":"Sam Catlow","updated_at":"2026-07-26T04:37:51Z","started_at":"2026-07-26T04:28:19Z","closed_at":"2026-07-26T04:37:51Z","close_reason":"Completed read-only Hermes takeover audit; findings and MVP remediation issues recorded.","dependencies":[{"issue_id":"archie-core-abg.35","depends_on_id":"archie-core-abg","type":"parent-child","created_at":"2026-07-26T14:28:14Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0} diff --git a/cmd/archied/main.go b/cmd/archied/main.go index e3bd33288..837d916fb 100644 --- a/cmd/archied/main.go +++ b/cmd/archied/main.go @@ -362,14 +362,24 @@ func run() int { if err != nil { return "", fmt.Errorf("llm chat stream: %w", err) } + // Consume FullStream, not TextStream. Per the ai-sdk + // channel contract FullStream is authoritative and MUST + // be drained until close: its writes are synchronous, so + // leaving it unread stalls the producer and deadlocks the + // whole turn. TextStream is a best-effort view that drops + // deltas when it is not being read, so it cannot be used + // to reconstruct the reply either. var sb strings.Builder - for delta := range stream.TextStream { - sb.WriteString(delta) - onDelta(delta) + for part := range stream.FullStream { + if part.Type != core.StreamPartTextDelta || part.TextDelta == "" { + continue + } + sb.WriteString(part.TextDelta) + onDelta(part.TextDelta) } - // FinishReason resolves only once the stream is drained, - // so a mid-stream provider failure surfaces here rather - // than being mistaken for a short but complete reply. + // Resolves once the producer completes, so a mid-stream + // failure surfaces here rather than a truncated reply + // passing as a short but complete one. if _, err := stream.FinishReason(); err != nil { return "", fmt.Errorf("llm chat stream: %w", err) } diff --git a/go.mod b/go.mod index f0731b66e..cba61d087 100644 --- a/go.mod +++ b/go.mod @@ -62,7 +62,7 @@ require ( github.com/nats-io/nats-server/v2 v2.14.3 github.com/nats-io/nats.go v1.52.0 github.com/samcharles93/NellDB v0.2.5 - github.com/samcharles93/ai-sdk v0.1.17 + github.com/samcharles93/ai-sdk v0.1.18 github.com/traefik/yaegi v0.16.1 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index ab14060a6..90ed8e105 100644 --- a/go.sum +++ b/go.sum @@ -120,6 +120,8 @@ github.com/samcharles93/NellDB v0.2.5 h1:VEasjyB4opTFAfWnV3s9TEHkfA41ee+7gYD8LqK github.com/samcharles93/NellDB v0.2.5/go.mod h1:vyfd6/T2Cp5U0acoh2LrebJteZqoFObedDZTxP0j4W0= github.com/samcharles93/ai-sdk v0.1.17 h1:yH48jrYVyFv+VO1qYkbReVpVxP063XMs0T/Jb90bkEY= github.com/samcharles93/ai-sdk v0.1.17/go.mod h1:a4JYsUrwGsmm2eiXgrpcKExtYe7uHQ5zsHDbbkcPB6o= +github.com/samcharles93/ai-sdk v0.1.18 h1:Jvz2OSnzJ68XCAiTHdLKKvgoNI/rKrNw9LJ7jbZs55c= +github.com/samcharles93/ai-sdk v0.1.18/go.mod h1:a4JYsUrwGsmm2eiXgrpcKExtYe7uHQ5zsHDbbkcPB6o= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/traefik/yaegi v0.16.1 h1:f1De3DVJqIDKmnasUF6MwmWv1dSEEat0wcpXhD2On3E=