diff --git a/.beads/issues.jsonl b/.beads/issues.jsonl index 6e9a8bfba..771f3c16c 100644 --- a/.beads/issues.jsonl +++ b/.beads/issues.jsonl @@ -95,7 +95,7 @@ {"_type":"issue","id":"archie-core-g7tm","title":"telegram: finalize the reply through a live context, matching the error branch","description":"The success path calls live.finalize(turnCtx, reply) with the raw cancellable turn context (telegram.go:582), while the error branch two lines above deliberately uses context.WithoutCancel(turnCtx). If /stop lands during finalize, the rich edit, the plain-text retry, and the split-send fallback all abort with context.Canceled (go-telegram/bot builds requests with NewRequestWithContext), so the authoritative reply is never delivered and the live message keeps the ▌ cursor forever. The reply is persisted to the ledger, so the loss is delivery-level — but the user sees a frozen half-answer.\n\nFailure: a long tool-using turn is /stop-ped as it completes; turnCtx is cancelled mid-finalize; every send fails on the dead context; the chat shows the last live frame with a blinking cursor and no final answer.\n\nFound by code-review of PR #476 (feat/467, merged 98e8dda).","design":"live.finalize(context.WithoutCancel(turnCtx), reply) — the one-liner the error branch already uses. Consider making finalize take a live context internally rather than trusting each caller to remember.","acceptance_criteria":"A /stop landing mid-finalize still delivers the authoritative reply and drops the cursor; a test covers the cancellable-context finalize path.","status":"closed","priority":1,"issue_type":"bug","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-08-14T14:43:08Z","created_by":"Sam Catlow","updated_at":"2026-08-14T15:07:36Z","started_at":"2026-08-14T14:53:28Z","closed_at":"2026-08-14T15:03:28Z","close_reason":"Fixed in internal/channels/telegram/live.go and telegram.go: finalize/abandon strip context cancellation before sending (mirroring each other), ToolCall escapes Markdown metacharacters via bot.EscapeMarkdown, splitLongMessage splits on rune boundaries. All new/changed tests verified red-then-green; task check clean; adversarial review pass found no blocking issues.","external_ref":"https://github.com/samcharles93/archie-core/issues/484","labels":["code-review","streaming","telegram"],"dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"archie-core-tb3a","title":"Fix streaming review blockers for inline tool calls","description":"Resolve the four evidence-gated findings in merged inline tool-call streaming: preserve the authoritative Telegram reply when final edits fail; keep Telegram network I/O off the model FullStream consumer and cancellable; correlate tool inputs with results and render a bounded redacted parameter summary; snapshot show_tool_calls per live reply to avoid reload races. Add regression tests for every path and run task check plus lint/race validation.","acceptance_criteria":"Regression tests fail on the merged implementation and pass after the fix. Final edit failure falls back to normal split delivery. Delta and ToolCall callbacks do not wait on Telegram HTTP and stop cancels in-flight rendering. Completed tool events include bounded redacted parameters correlated by tool-call ID. Reload cannot race an in-flight reply's show_tool_calls setting. task check passes, golangci-lint reports no new findings, and focused race tests pass.","notes":"Implemented in worktree /tmp/archie-core-tb3a on branch fix/archie-core-tb3a. Added cancellable async Telegram rendering, final edit failure fallback through normal split delivery, call-ID-correlated bounded conservative parameter summaries, atomic per-reply show_tool_calls snapshots, SSE/UI parameter rendering, rebuilt ui/dist, and regression tests. Validation: GOFLAGS=-buildvcs=false task check passed; golangci-lint --new-from-rev=HEAD ./... reported 0 issues; focused race suite passed; fresh adversarial reviewer reported PASS with zero findings. Plain task check is blocked in linked worktrees by Go VCS stamping exit 128, hence buildvcs override.\n2026-08-24 reconciliation: the close reason's 'worktree left uncommitted' is stale. The work did land on main via ba33527 (Merge pull request #477 from samcharles93/fix/archie-core-tb3a); verified on main: gateway/stream.go sensitiveParameterKey+redactToolParameters, telegram/live.go per-reply showToolCalls snapshot, webui/api_chat.go gating. The /tmp/archie-core-tb3a worktree and its branch are gone, as expected.\n","status":"closed","priority":1,"issue_type":"bug","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-08-13T18:05:35Z","created_by":"Sam Catlow","updated_at":"2026-08-24T07:29:09Z","started_at":"2026-08-13T18:05:39Z","closed_at":"2026-08-13T18:35:26Z","close_reason":"Completed and independently reviewed; worktree left uncommitted per conservative repository policy.","external_ref":"https://github.com/samcharles93/archie-core/issues/485","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"archie-core-dzx","title":"Remove duplicate archie-agent safe.directory setup","description":"## Problem\\ncmd/archie-agent/main.go configures git safe.directory inline and then calls markWorktreeSafe, so startup writes the same global git configuration twice.\\n\\n## Scope\\nKeep markWorktreeSafe as the single tested production path and remove the older inline exec.Command block/import. Add regression coverage proving startup wiring has exactly one authoritative safe-directory call.\\n\\n## Acceptance\\n- archie-agent startup invokes markWorktreeSafe exactly once\\n- no second inline safe.directory command remains in main.go\\n- cmd/archie-agent tests and repository quality gate pass","acceptance_criteria":"Single tested safe.directory setup path remains; duplicate inline command is removed; tests and task check pass","notes":"Red proof: TestMainConfiguresWorktreeSafetyOnce failed with 2 setup paths before implementation. Green proof: go test/vet/build ./cmd/archie-agent/... passed; golangci-lint --new-from-rev=HEAD reported 0 issues. Fresh adversarial review found no blockers. Full task check was not run because the working tree contains unrelated in-progress changes and task check rewrites files; scoped package gate used per repository protocol.","status":"closed","priority":1,"issue_type":"bug","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-08-13T16:10:09Z","created_by":"Sam Catlow","updated_at":"2026-08-13T16:13:48Z","started_at":"2026-08-13T16:10:24Z","closed_at":"2026-08-13T16:13:48Z","close_reason":"Removed duplicate inline safe.directory setup; markWorktreeSafe is now the single tested production path","external_ref":"https://github.com/samcharles93/archie-core/issues/470","dependency_count":0,"dependent_count":0,"comment_count":0} -{"_type":"issue","id":"archie-core-t2db.20","title":"eda: LSP/serve mode for cmd/archie-playbooks","description":"Second entrypoint of the gopls-shaped standalone binary from t2db.12 (lint mode already shipped). Sam explicitly kept this in scope, not deferred, because it's the same schema source as the linter, just a different consumer -- the design doc's shared-package, thin-consumer principle.\n\nGrounded by a crew investigation pass (2026-09-03): the loader decodes with yaml.Unmarshal into a plain map, which discards line numbers -- today's lint findings are file-granular only. A useful LSP (hover/completion/inline errors) needs real positions, so the yaml.Node decoding upgrade is a practical prerequisite, not a nice-to-have. internal/domain/eda/expr's Compile/Eval already return structured errors that should map cleanly to diagnostics -- confirm this rather than re-deriving error shapes.","design":"Two-part scope, decide whether to split into two tickets or do both together once you've read the code:\n1. yaml.Node decoding upgrade: replace the plain-map yaml.Unmarshal decode path (internal/domain/workflow/routing.go -- three call sites at time of writing, all doing 'var raw map[string]string; yaml.Unmarshal(data, \u0026raw)') with yaml.Node-based decoding that retains line/column info, without changing any existing collision-detection behavior.\n\nVERIFIED FEASIBLE, concrete shape (2026-09-03): gopkg.in/yaml.v3's Node type has Line/Column fields populated directly by the decoder (confirmed in the vendored source). For a mapping node (Kind == MappingNode), Content is a flat []*Node alternating key-node, value-node pairs -- so decoding into *yaml.Node instead of map[string]string gives Content[i].Line for the i-th key's line number directly, no manual line-counting needed. The upgrade is: yaml.Unmarshal(data, \u0026node) into a *yaml.Node instead of the map, then walk node.Content in pairs extracting key.Value/value.Value (same strings as today) plus key.Line (new). This is a pure additive capability -- existing collision error MESSAGES should stay byte-identical where line info isn't yet surfaced in them, add line numbers to the error format once available. Do not change collision-detection LOGIC, only the decode representation.\n\n2. serve/lsp command: add a new entry to cmd/archie-playbooks's existing command table (do not restructure -- t2db.12 built it explicitly to take this addition without restructuring, confirmed by reading cmd/archie-playbooks/main.go's commands map). Scope: a minimal LSP surface (diagnostics at minimum; hover/completion if straightforward) over the same compile/validate path the lint command already uses. Weigh a tiny hand-rolled LSP protocol implementation (fits organisation.md's thin cmd/ rule and the narrow-capability-family principle) against pulling in an LSP library -- vet any new dependency via the vetting-dependencies skill before adding it, same rigor as the CEL decision (docs/prds/eda-playbook-engine.md's resolved open question 1) -- this is a real, undecided choice, not preempted here.","acceptance_criteria":"cmd/archie-playbooks gains a serve (or lsp) subcommand alongside lint, using the same underlying compile/validate calls -- no second validation path. Diagnostics report file:line where the yaml.Node upgrade provides it. Existing lint-mode tests and behavior are unchanged (regression-tested). task check passes.","notes":"Full vetting record for sourcegraph/jsonrpc2, 2026-09-03 (same rigor as the approved cel.dev/cel-go decision):\n\n- Security: zero advisories on record (GitHub Advisory Database, queried directly). License: MIT (compatible).\n- Maintenance: genuinely active -- commits within the last month (Aug 2026), real CI hygiene work (not a dead repo with a stale README). Not archived (unlike sourcegraph/go-lsp, the other candidate, which IS archived and was ruled out).\n- Dependency footprint: measured directly (not assumed) -- importing only the jsonrpc2.Conn surface pulls in exactly ONE dependency, no gorilla/websocket at all (go.sum showed a single entry). websocket is a lazy/optional dependency of the library, only pulled in if its WS-transport-specific APIs are actually called -- a stdio-only LSP transport never touches it.\n- Binary size cost: measured directly, same baseline methodology as the CEL vetting -- a minimal Go binary baseline was 2,343,283 bytes; adding jsonrpc2 (importing Conn) measured 2,715,265 bytes. Cost: +371,982 bytes (~0.36MB). Far lighter than CEL's +13MB, as expected for a narrow JSON-RPC engine vs. a full expression-language runtime.\n\nVerdict: sourcegraph/jsonrpc2 clears vetting cleanly -- safe, cheap, active, correctness-sensitive-and-worth-depending-on (same reasoning as CEL: reimplementing JSON-RPC request/response ID correlation by hand is a real correctness surface, not free). This is a complete, ready-to-approve recommendation, not yet approved -- do not add the dependency or start implementation until Sam signs off, mirroring the CEL process exactly (full vetting record produced, then explicit approval, then implementation).","status":"open","priority":2,"issue_type":"task","owner":"sam@catlow.tech","created_at":"2026-09-02T18:12:41Z","created_by":"Sam Catlow","updated_at":"2026-09-02T20:33:00Z","dependencies":[{"issue_id":"archie-core-t2db.20","depends_on_id":"archie-core-t2db","type":"parent-child","created_at":"2026-09-02T18:12:41Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0} +{"_type":"issue","id":"archie-core-t2db.20","title":"eda: LSP/serve mode for cmd/archie-playbooks","description":"Second entrypoint of the gopls-shaped standalone binary from t2db.12 (lint mode already shipped). Sam explicitly kept this in scope, not deferred, because it's the same schema source as the linter, just a different consumer -- the design doc's shared-package, thin-consumer principle.\n\nGrounded by a crew investigation pass (2026-09-03): the loader decodes with yaml.Unmarshal into a plain map, which discards line numbers -- today's lint findings are file-granular only. A useful LSP (hover/completion/inline errors) needs real positions, so the yaml.Node decoding upgrade is a practical prerequisite, not a nice-to-have. internal/domain/eda/expr's Compile/Eval already return structured errors that should map cleanly to diagnostics -- confirm this rather than re-deriving error shapes.","design":"Two-part scope, decide whether to split into two tickets or do both together once you've read the code:\n1. yaml.Node decoding upgrade: replace the plain-map yaml.Unmarshal decode path (internal/domain/workflow/routing.go -- three call sites at time of writing, all doing 'var raw map[string]string; yaml.Unmarshal(data, \u0026raw)') with yaml.Node-based decoding that retains line/column info, without changing any existing collision-detection behavior.\n\nVERIFIED FEASIBLE, concrete shape (2026-09-03): gopkg.in/yaml.v3's Node type has Line/Column fields populated directly by the decoder (confirmed in the vendored source). For a mapping node (Kind == MappingNode), Content is a flat []*Node alternating key-node, value-node pairs -- so decoding into *yaml.Node instead of map[string]string gives Content[i].Line for the i-th key's line number directly, no manual line-counting needed. The upgrade is: yaml.Unmarshal(data, \u0026node) into a *yaml.Node instead of the map, then walk node.Content in pairs extracting key.Value/value.Value (same strings as today) plus key.Line (new). This is a pure additive capability -- existing collision error MESSAGES should stay byte-identical where line info isn't yet surfaced in them, add line numbers to the error format once available. Do not change collision-detection LOGIC, only the decode representation.\n\n2. serve/lsp command: add a new entry to cmd/archie-playbooks's existing command table (do not restructure -- t2db.12 built it explicitly to take this addition without restructuring, confirmed by reading cmd/archie-playbooks/main.go's commands map). Scope: a minimal LSP surface (diagnostics at minimum; hover/completion if straightforward) over the same compile/validate path the lint command already uses. Weigh a tiny hand-rolled LSP protocol implementation (fits organisation.md's thin cmd/ rule and the narrow-capability-family principle) against pulling in an LSP library -- vet any new dependency via the vetting-dependencies skill before adding it, same rigor as the CEL decision (docs/prds/eda-playbook-engine.md's resolved open question 1) -- this is a real, undecided choice, not preempted here.","acceptance_criteria":"cmd/archie-playbooks gains a serve (or lsp) subcommand alongside lint, using the same underlying compile/validate calls -- no second validation path. Diagnostics report file:line where the yaml.Node upgrade provides it. Existing lint-mode tests and behavior are unchanged (regression-tested). task check passes.","notes":"Full vetting record for sourcegraph/jsonrpc2, 2026-09-03 (same rigor as the approved cel.dev/cel-go decision):\n\n- Security: zero advisories on record (GitHub Advisory Database, queried directly). License: MIT (compatible).\n- Maintenance: genuinely active -- commits within the last month (Aug 2026), real CI hygiene work (not a dead repo with a stale README). Not archived (unlike sourcegraph/go-lsp, the other candidate, which IS archived and was ruled out).\n- Dependency footprint: measured directly (not assumed) -- importing only the jsonrpc2.Conn surface pulls in exactly ONE dependency, no gorilla/websocket at all (go.sum showed a single entry). websocket is a lazy/optional dependency of the library, only pulled in if its WS-transport-specific APIs are actually called -- a stdio-only LSP transport never touches it.\n- Binary size cost: measured directly, same baseline methodology as the CEL vetting -- a minimal Go binary baseline was 2,343,283 bytes; adding jsonrpc2 (importing Conn) measured 2,715,265 bytes. Cost: +371,982 bytes (~0.36MB). Far lighter than CEL's +13MB, as expected for a narrow JSON-RPC engine vs. a full expression-language runtime.\n\nVerdict: sourcegraph/jsonrpc2 clears vetting cleanly -- safe, cheap, active, correctness-sensitive-and-worth-depending-on (same reasoning as CEL: reimplementing JSON-RPC request/response ID correlation by hand is a real correctness surface, not free). This is a complete, ready-to-approve recommendation, not yet approved -- do not add the dependency or start implementation until Sam signs off, mirroring the CEL process exactly (full vetting record produced, then explicit approval, then implementation).\nRefinement, 2026-09-03: reconsidering the jsonrpc2 recommendation above -- jsonrpc2's main value is correlating a REQUEST this process sends against the eventual RESPONSE (needed for bidirectional JSON-RPC). A minimal diagnostics-only language server (this ticket's stated 'at minimum' scope) never needs to initiate its own request awaiting a correlated response -- it only receives client requests/notifications and sends back responses/notifications synchronously in the same read-dispatch-write loop, plus unprompted notifications (textDocument/publishDiagnostics) that need no correlation either. Under that narrower scope, hand-rolling the Content-Length-framed transport (bufio.Reader + encoding/json, genuinely ~50-100 lines, no ID-correlation subtlety since nothing is being correlated) may be the more honestly 'thin' choice, with zero new dependency. jsonrpc2 becomes the right call specifically if the implementer adds server-initiated requests later (workspace/configuration, client/registerCapability, etc.) -- decide based on which scope is actually being built, not pre-emptively. Recording both paths rather than a single overconfident answer.","status":"open","priority":2,"issue_type":"task","owner":"sam@catlow.tech","created_at":"2026-09-02T18:12:41Z","created_by":"Sam Catlow","updated_at":"2026-09-02T20:33:42Z","dependencies":[{"issue_id":"archie-core-t2db.20","depends_on_id":"archie-core-t2db","type":"parent-child","created_at":"2026-09-02T18:12:41Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"archie-core-t2db.19","title":"eda: scope Channel and Forge action positions (investigation, blocked on execution-time gaps)","description":"Investigation ticket -- decide the typed-contract shape for the two remaining named action positions (Channel, Forge) before implementing either. Blocked on archie-core-t2db.17 (idempotency) since both are naturally side-effecting positions; investigation/scoping can proceed now, implementation cannot land before .17 resolves.\n\nGrounded by a crew investigation pass (2026-09-03): Channel already exists as internal/channels.Channel (embeds gateway.Gateway + ConfigSchema/ValidateConfig, telegram/email/webhook implementations registered at daemon startup). Forge already exists as internal/forge.Forge = IssueForge + PullRequestForge + RepoForge, with New(...) switching on github/gitea/none; the daemon poller currently special-cases forge operations directly rather than through any addressable position.","design":"See docs/prds/channel-forge-positions.md (committed 2026-09-03). Forge is fully scoped and ready to implement once t2db.17 lands: native-Go-by-name (not Module-kind) over the existing internal/forge.Forge interface, close-issue/link-branch as the safe first operations, create-pr deferred. Channel is NOT resolved -- the crew investigation's assumption that channels.Channel has an addressable send capability is FALSE (verified: only Name/Start/Stop + config validation exist, no Send method anywhere in internal/channels or internal/gateway). This is now an open product/architecture decision for Sam: whether 'Channel action' means (1) a new playbook-scoped notification capability distinct from the interactive chat channels, or (2) reusing the interactive channels with some new conversation-scoping mechanism for a non-chat trigger. Do not implement a Channel position until Sam decides which.","acceptance_criteria":"A design-doc addition (new docs/prds/ file or a section in eda-playbook-engine.md, your call which fits better -- state why) resolving: typed-contract shape for each position, Args/Result shapes, and the host-access/resolution mechanism. No implementation in this ticket.","status":"open","priority":2,"issue_type":"task","owner":"sam@catlow.tech","created_at":"2026-09-02T18:12:40Z","created_by":"Sam Catlow","updated_at":"2026-09-02T18:15:31Z","dependencies":[{"issue_id":"archie-core-t2db.19","depends_on_id":"archie-core-t2db","type":"parent-child","created_at":"2026-09-02T18:12:40Z","created_by":"Sam Catlow","metadata":"{}"},{"issue_id":"archie-core-t2db.19","depends_on_id":"archie-core-t2db.17","type":"blocks","created_at":"2026-09-02T18:12:40Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":1,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"archie-core-t2db.16","title":"eda: reduce complexity in bootstrap.go loadWorkflows and routing.go LoadPlaybookDirs","description":"task check now runs golangci-lint (Sam's explicit requirement, 2026-09-03 -- catch lint regressions as part of the definitive gate, not just fmt/vet/build/test). First run surfaced two real findings, both accumulated debt from this session's own EDA slices, not pre-existing:\n\n1. internal/app/archied/bootstrap.go:647 loadWorkflows -- cyclomatic complexity 17, max 15 (cyclop). Grew incrementally across t2db.9 (kindWorkflows), t2db.10 (labelWorkflows), t2db.11 (PlaybookDirs merge), t2db.15 (EDAPlaybookDir) -- each addition was small, the function as a whole crossed the threshold.\n2. internal/domain/workflow/routing.go:103 LoadPlaybookDirs -- cognitive complexity 52, max 30 (gocognit), from t2db.11's directory-merge loader (kind-vs-label detection, per-file and cross-file collision checks all inline).\n\nRoot-cause fix required, not suppression: no //nolint. Extract cohesive sub-steps into named helper functions -- this is exactly the kind of case AGENTS.md's Architectural Simplicity rule describes (prefer a clean extraction over papering past a threshold).","design":"For loadWorkflows: extract the four independent load-and-set steps (kind-file load, label-file load, playbook-dirs load+merge, EDAPlaybookDir load) into named helpers the top-level function calls in sequence, each returning its own error for the existing log-and-abort pattern. Do not change the log-and-abort error-handling shape or field names.\n\nFor LoadPlaybookDirs: split the per-file parsing loop's kind-detection-vs-label-detection-vs-collision-check logic into a couple of named helpers (e.g. classifyBinding, checkCollision) called from the main loop, keeping the existing collision error messages and behavior byte-identical -- this is a pure refactor, not a behavior change.","acceptance_criteria":"golangci-lint run ./... reports zero cyclop/gocognit findings on these two functions. All existing tests for workflow.LoadPlaybookDirs, kindWorkflows, labelWorkflows, and bootstrap's loadWorkflows-adjacent behavior pass unchanged (byte-identical collision error messages -- diff the exact strings, do not just check err != nil). task check (now including lint) passes fully.","status":"open","priority":2,"issue_type":"task","owner":"sam@catlow.tech","created_at":"2026-09-02T18:10:21Z","created_by":"Sam Catlow","updated_at":"2026-09-02T18:10:21Z","dependencies":[{"issue_id":"archie-core-t2db.16","depends_on_id":"archie-core-t2db","type":"parent-child","created_at":"2026-09-02T18:10:21Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"archie-core-t2db.15","title":"eda: playbook document + event coordinator, single-action workflow-kind dispatch","description":"Seventh slice of docs/prds/eda-playbook-engine.md. Builds the rich playbook document shape (trigger + ordered actions with CEL 'when') and an event coordinator that dispatches it -- the first real consumer of t2db.14's expr package. Scoped tightly to what's already safe per this doc's own gating:\n\n- Exactly ONE action per playbook in this slice, and it MUST be position: workflow. Reject (load failure) a playbook declaring more than one action, or an action whose position is module/channel/forge -- those remain blocked on the unresolved execution-time gaps (mid-run failure semantics, idempotency for non-workflow actions) per the 'Execution-time gaps' section. Do not relax this without Sam's sign-off -- this is the one hard boundary in this ticket, everything else is normal implementation judgment.\n- This is an ADDITIONAL loading path alongside the existing flat kind/label binding files (t2db.9/.10/.11). Do NOT modify workflow.Route(), workflow.workflowForLabels, or remove/change the existing single-file/multi-dir binding loaders. Migrating Route() onto the new mechanism is a separate, later, larger decision -- not in scope here.\n- Idempotency is free for this slice for the same reason it was free for t2db.13's first Module slice: a single workflow-kind action reaches the exact same workflow.Registry dispatch path that already carries TaskEnvelope's idempotency key. Nothing new to design here.","design":"Depends on archie-core-t2db.14 (expr package) -- do not start until it is closed and verified.\n\n1. Playbook document type (new package, likely internal/domain/eda/playbook -- confirm against organisation.md's layout rule, follow the log/logextract split precedent from t2db.13 if a generated component turns out to be needed, though this ticket is pure YAML+CEL, no Yaegi, so likely no extract package is needed here):\n - trigger: reuse existing workintake label/kind matching (do not invent a second label-matching mechanism -- workintake.SplitLabels/KindsForLabels already exist and are the one place this vocabulary lives).\n - actions: a list, validated at load to contain exactly one entry with position: workflow and a workflow registry name.\n - when: optional CEL expression string on the action, compiled via t2db.14's Compile() at load time -- a compile failure is a reported load failure (same collision-handling philosophy as t2db.9-.12), not a silently-skipped playbook.\n2. Event coordinator: loads playbook files from a configured directory (mirror the PlaybookDirs pattern from t2db.11 -- reuse its directory-scanning shape, do not reinvent), compiles every playbook's when expression at load (fail the whole load on any compile error, consistent with the existing reject-at-load rule), and at dispatch time: match trigger against an incoming task's labels/kind, evaluate when (if present) against a context of {event: \u003ctask's label/kind fields, whatever is cheaply available -- do not over-engineer the event shape beyond what a workflow-kind dispatch actually needs\u003e, actions: {} (empty -- no prior actions exist in a single-action playbook)}, and if the condition is true (or absent), dispatch to the named workflow via the existing workflow.Registry -- call the same registry lookup Route() already uses, do not duplicate dispatch logic.\n3. Config: a directory field for these playbook documents (distinct from t2db.11's PlaybookDirs, which holds flat binding files -- naming these two similar-but-different directories clearly is important; suggest something like EDAPlaybookDir or clarify in the field doc comment exactly how it differs from PlaybookDirs so a future reader isn't confused). If you judge the distinction is confusing enough that these should share one directory with two file shapes distinguished by content, flag that as a note in the PRD rather than silently deciding it -- but implement SOMETHING reasonable rather than blocking.\n4. Bootstrap wiring: load-and-abort on failure, matching every other slice's established pattern.\n5. Do NOT wire this into production task intake (daemon.go/pollNATS/publishTask) in this ticket -- prove the coordinator end-to-end with tests that construct a task-like input directly, the same way t2db.13 proved ModuleRegistry with direct Register/Invoke calls rather than full daemon wiring. Production wiring (making a real forge-triggered task actually flow through this coordinator instead of only workflow.Route()) is explicitly a follow-up ticket -- note it as such when you close this one.","acceptance_criteria":"A playbook YAML with trigger + one workflow-kind action + optional when loads successfully and dispatches to the correct registered workflow when trigger+when match. A playbook declaring 2+ actions is a reported load failure. A playbook with a non-workflow action position is a reported load failure. A when expression that compiles but evaluates false at dispatch time correctly skips dispatch (logged, not silently ignored). A when compile failure at load time is reported and the playbook is dropped (same collision-handling shape as prior slices). Existing workflow.Route()/label-binding tests (t2db.9-.12) are unaffected -- run their full test suites and confirm zero regressions. task check passes.","status":"closed","priority":2,"issue_type":"task","owner":"sam@catlow.tech","created_at":"2026-09-02T17:57:47Z","created_by":"Sam Catlow","updated_at":"2026-09-02T18:06:08Z","closed_at":"2026-09-02T18:06:08Z","close_reason":"Implemented and gate-verified as 2c2b9b7 (pushed to main). internal/domain/eda/playbook: Load (reject-at-load: 2+ actions, non-workflow position, malformed, bad when compile all fail whole load) + Store.Dispatch (trigger match via workintake kind/labels, CEL when eval, named-workflow registry lookup -- same as Route()'s, no duplicated dispatch). EDAPlaybookDir config field (distinct from PlaybookDirs, documented), bootstrap load-and-abort. workflow.Route()/binding loaders untouched; their suites verified zero-regression. 11 tests + shipped example proving end-to-end; task check clean (113/113 UI). FOLLOW-UP TICKET NEEDED (not in this slice, per design): wire Store.Dispatch into production task intake (daemon.go/pollNATS/publishTask) so real forge-triggered tasks flow through the coordinator instead of only workflow.Route(); plus a separate linter/LSP integration ticket for the expr compile path.","dependencies":[{"issue_id":"archie-core-t2db.15","depends_on_id":"archie-core-t2db","type":"parent-child","created_at":"2026-09-02T17:57:47Z","created_by":"Sam Catlow","metadata":"{}"},{"issue_id":"archie-core-t2db.15","depends_on_id":"archie-core-t2db.14","type":"blocks","created_at":"2026-09-02T17:57:48Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":1,"dependent_count":0,"comment_count":0} diff --git a/internal/app/archied/bootstrap.go b/internal/app/archied/bootstrap.go index 68fec832a..7416300a2 100644 --- a/internal/app/archied/bootstrap.go +++ b/internal/app/archied/bootstrap.go @@ -646,6 +646,45 @@ func (b *boot) setupGateways(ctx context.Context, cfgPath, overlayPath string) b // built-ins fill gaps. func (b *boot) loadWorkflows(ctx context.Context) error { cfg, log := b.cfg, b.log + if err := b.loadWorkflowRouting(cfg, log); err != nil { + return err + } + if err := b.loadModules(cfg, log); err != nil { + return err + } + if err := b.loadEDAPlaybooks(cfg, log); err != nil { + return err + } + + skillsBase := cfg.SkillsDir + if skillsBase == "" { + skillsBase = cfg.WorkDir + } + workflowCatalog, err := skillbuild.BuildCatalog(skillsBase) + if err != nil { + log.Error("skill registry build failed", "err", err) + return err + } + log.Info("workflow registry built", "workflows", len(workflowCatalog.Registry)) + b.web.Workflows = workflow.DefinitionsWithOrigins(workflowCatalog.Registry, workflowCatalog.Origins) + if l := cfg.Web.Listen; l != "" && l != "off" { + b.web.Token = webTokenFor(l, cfg.DBPath, log) + go func() { + if err := b.web.Run(ctx, l); err != nil { + log.Error("web ui failed", "err", err) + } + }() + } + return nil +} + +// loadWorkflowRouting loads the kind/label -> workflow-name bindings from +// the single-file fields and the playbook directories, merges them, and +// installs the result via workflow.SetKindWorkflows/SetLabelWorkflows. +// Split out of loadWorkflows (t2db.16) to keep the top-level function's +// complexity within the lint gate -- pure extraction, same log messages +// and error-return order as before. +func (b *boot) loadWorkflowRouting(cfg config.Config, log *slog.Logger) error { kindWorkflows, err := workflow.LoadKindWorkflowsYAML(cfg.WorkflowRoutingFile) if err != nil { log.Error("workflow routing file load failed", "path", cfg.WorkflowRoutingFile, "err", err) @@ -680,63 +719,54 @@ func (b *boot) loadWorkflows(ctx context.Context) error { workflow.SetKindWorkflows(kindWorkflows) workflow.SetLabelWorkflows(labelWorkflows) + return nil +} - // Module action kinds (EDA playbook Module position, t2db.13): operator- - // trusted, in-process, Yaegi-interpreted. A broken module is a startup - // failure -- the daemon does not start with a partial module set, matching - // the routing-file load pattern (not the degrade-and-skip plugin pattern). - // Kinds whose file is not present in the directory are simply not loaded. +// loadModules builds the daemon's Module registry (EDA playbook Module +// position, t2db.13): operator-trusted, in-process, Yaegi-interpreted. A +// broken module is a startup failure -- the daemon does not start with a +// partial module set, matching the routing-file load pattern (not the +// degrade-and-skip plugin pattern). Kinds whose file is not present in the +// directory are simply not loaded. Split out of loadWorkflows (t2db.16); +// pure extraction, same log messages and error-return order as before. +func (b *boot) loadModules(cfg config.Config, log *slog.Logger) error { b.modules = module.New() - if cfg.ModuleDir != "" { - for _, kind := range module.Kinds() { - path := filepath.Join(cfg.ModuleDir, kind+".go") - if _, err := os.Stat(path); err != nil { - if errors.Is(err, os.ErrNotExist) { - continue // kind not installed in this module dir - } - log.Error("module stat failed", "kind", kind, "path", path, "err", err) - return err - } - if err := b.modules.Register(kind, cfg.ModuleDir); err != nil { - log.Error("module load failed", "kind", kind, "dir", cfg.ModuleDir, "err", err) - return err - } - } - log.Info("module registry built", "dir", cfg.ModuleDir, "kinds", b.modules.Len()) + if cfg.ModuleDir == "" { + return nil } + for _, kind := range module.Kinds() { + path := filepath.Join(cfg.ModuleDir, kind+".go") + if _, err := os.Stat(path); err != nil { + if errors.Is(err, os.ErrNotExist) { + continue // kind not installed in this module dir + } + log.Error("module stat failed", "kind", kind, "path", path, "err", err) + return err + } + if err := b.modules.Register(kind, cfg.ModuleDir); err != nil { + log.Error("module load failed", "kind", kind, "dir", cfg.ModuleDir, "err", err) + return err + } + } + log.Info("module registry built", "dir", cfg.ModuleDir, "kinds", b.modules.Len()) + return nil +} - // EDA playbook documents (t2db.15): trigger + single workflow-kind action - // with CEL when conditions. Loaded at startup with the same reject-at-load - // rule -- any malformed playbook, multi-action playbook, non-workflow - // position, or when compile failure aborts startup, matching the routing- - // file load pattern (not degrade-and-skip). A nonexistent dir is an empty - // store. +// loadEDAPlaybooks loads the EDA playbook documents (t2db.15): trigger + +// single workflow-kind action with CEL when conditions. Loaded at startup +// with the same reject-at-load rule -- any malformed playbook, +// multi-action playbook, non-workflow position, or when compile failure +// aborts startup, matching the routing-file load pattern (not +// degrade-and-skip). A nonexistent dir is an empty store. Split out of +// loadWorkflows (t2db.16); pure extraction, same log messages as before. +func (b *boot) loadEDAPlaybooks(cfg config.Config, log *slog.Logger) error { + var err error b.playbooks, err = playbook.Load(cfg.EDAPlaybookDir) if err != nil { log.Error("eda playbook load failed", "dir", cfg.EDAPlaybookDir, "err", err) return err } log.Info("eda playbooks loaded", "dir", cfg.EDAPlaybookDir, "playbooks", len(b.playbooks.Playbooks)) - - skillsBase := cfg.SkillsDir - if skillsBase == "" { - skillsBase = cfg.WorkDir - } - workflowCatalog, err := skillbuild.BuildCatalog(skillsBase) - if err != nil { - log.Error("skill registry build failed", "err", err) - return err - } - log.Info("workflow registry built", "workflows", len(workflowCatalog.Registry)) - b.web.Workflows = workflow.DefinitionsWithOrigins(workflowCatalog.Registry, workflowCatalog.Origins) - if l := cfg.Web.Listen; l != "" && l != "off" { - b.web.Token = webTokenFor(l, cfg.DBPath, log) - go func() { - if err := b.web.Run(ctx, l); err != nil { - log.Error("web ui failed", "err", err) - } - }() - } return nil } diff --git a/internal/domain/workflow/routing.go b/internal/domain/workflow/routing.go index 89edccbb1..029cad786 100644 --- a/internal/domain/workflow/routing.go +++ b/internal/domain/workflow/routing.go @@ -104,61 +104,13 @@ func LoadPlaybookDirs(dirs []string) (KindWorkflows, LabelWorkflows, error) { kw := make(KindWorkflows) lw := make(LabelWorkflows) for _, dir := range dirs { - entries, err := os.ReadDir(dir) - if os.IsNotExist(err) { - continue - } + names, err := sortedPlaybookFilenames(dir) if err != nil { - return nil, nil, fmt.Errorf("read playbook dir %s: %w", dir, err) + return nil, nil, err } - - var names []string - for _, e := range entries { - if e.IsDir() { - continue - } - if ext := strings.ToLower(filepath.Ext(e.Name())); ext == ".yaml" || ext == ".yml" { - names = append(names, e.Name()) - } - } - sort.Strings(names) - for _, name := range names { - path := filepath.Join(dir, name) - data, err := os.ReadFile(path) - if err != nil { - return nil, nil, fmt.Errorf("read playbook file %s: %w", path, err) - } - raw := map[string]string{} - if err := yaml.Unmarshal(data, &raw); err != nil { - return nil, nil, fmt.Errorf("parse playbook file %s: %w", path, err) - } - for key, value := range raw { - trimmed := strings.TrimSpace(key) - if trimmed == "" { - return nil, nil, fmt.Errorf("playbook file %s: empty binding key", path) - } - if value == "" { - return nil, nil, fmt.Errorf("playbook file %s: key %q has no workflow name", path, trimmed) - } - if err := workintake.Kind(trimmed).Validate(); err == nil { - // It is a kind binding: the closed Kind vocabulary accepts it. - if existing, ok := kw[workintake.Kind(trimmed)]; ok { - return nil, nil, fmt.Errorf("playbook dirs: kind %q bound in two sources (%q and %q)", trimmed, existing, value) - } - kw[workintake.Kind(trimmed)] = value - continue - } - // Otherwise it is an arbitrary-label binding. Reject kind-owned - // labels and empty labels with the same rules the single-file - // loader applies. - if _, ok := defaultKindWorkflows[workintake.Kind(trimmed)]; ok { - return nil, nil, fmt.Errorf("playbook file %s: label %q is already owned by the kind routing layer", path, trimmed) - } - if existing, ok := lw[trimmed]; ok { - return nil, nil, fmt.Errorf("playbook dirs: label %q bound in two sources (%q and %q)", trimmed, existing, value) - } - lw[trimmed] = value + if err := loadPlaybookFile(filepath.Join(dir, name), kw, lw); err != nil { + return nil, nil, err } } } @@ -172,6 +124,82 @@ func LoadPlaybookDirs(dirs []string) (KindWorkflows, LabelWorkflows, error) { return kw, lw, nil } +// sortedPlaybookFilenames lists the *.yaml / *.yml files directly inside dir, +// sorted so LoadPlaybookDirs' source order is deterministic. A missing +// directory is not an error -- it contributes no filenames, matching +// LoadPlaybookDirs' "no playbook dir configured" convention. +func sortedPlaybookFilenames(dir string) ([]string, error) { + entries, err := os.ReadDir(dir) + if os.IsNotExist(err) { + return nil, nil + } + if err != nil { + return nil, fmt.Errorf("read playbook dir %s: %w", dir, err) + } + + var names []string + for _, e := range entries { + if e.IsDir() { + continue + } + if ext := strings.ToLower(filepath.Ext(e.Name())); ext == ".yaml" || ext == ".yml" { + names = append(names, e.Name()) + } + } + sort.Strings(names) + return names, nil +} + +// loadPlaybookFile reads one playbook binding file and merges its keys into +// kw/lw via bindPlaybookKey, mutating both in place. +func loadPlaybookFile(path string, kw KindWorkflows, lw LabelWorkflows) error { + data, err := os.ReadFile(path) + if err != nil { + return fmt.Errorf("read playbook file %s: %w", path, err) + } + raw := map[string]string{} + if err := yaml.Unmarshal(data, &raw); err != nil { + return fmt.Errorf("parse playbook file %s: %w", path, err) + } + for key, value := range raw { + if err := bindPlaybookKey(path, key, value, kw, lw); err != nil { + return err + } + } + return nil +} + +// bindPlaybookKey classifies one playbook binding key as a closed-vocabulary +// kind or an arbitrary label, then merges it into kw/lw -- applying the same +// collision and empty-value rules LoadPlaybookDirs' doc comment describes. +func bindPlaybookKey(path, key, value string, kw KindWorkflows, lw LabelWorkflows) error { + trimmed := strings.TrimSpace(key) + if trimmed == "" { + return fmt.Errorf("playbook file %s: empty binding key", path) + } + if value == "" { + return fmt.Errorf("playbook file %s: key %q has no workflow name", path, trimmed) + } + if err := workintake.Kind(trimmed).Validate(); err == nil { + // It is a kind binding: the closed Kind vocabulary accepts it. + if existing, ok := kw[workintake.Kind(trimmed)]; ok { + return fmt.Errorf("playbook dirs: kind %q bound in two sources (%q and %q)", trimmed, existing, value) + } + kw[workintake.Kind(trimmed)] = value + return nil + } + // Otherwise it is an arbitrary-label binding. Reject kind-owned labels + // and empty labels with the same rules the single-file loader applies. + if _, ok := defaultKindWorkflows[workintake.Kind(trimmed)]; ok { + return fmt.Errorf("playbook file %s: label %q is already owned by the kind routing layer", path, trimmed) + } + if existing, ok := lw[trimmed]; ok { + return fmt.Errorf("playbook dirs: label %q bound in two sources (%q and %q)", trimmed, existing, value) + } + lw[trimmed] = value + return nil +} + // MergeKindWorkflows merges extra into base, failing on a key bound by // both. The single-file field and the playbook directory are independent // sources; a key each claims is a collision, not a precedence question