Commit Graph
18 Commits
Author SHA1 Message Date
sam f498f593c9 fix(eda): authoritative module ids and stricter action load errors 2026-09-22 09:41:31 +10:00
sam 85a671491f fix(eda): tie module results to checker and tighten action ids 2026-09-22 09:22:45 +10:00
sam 826f87e414 feat(eda): wire action playbooks through loader and module schemas
Pass 2 of archie-core-nx30. Pass 1 typed each prior action's result in
the CEL env; this pass wires that typing through the loader, module
schemas, and daemon, and removes the now-redundant id classifier.

Loader shape (D2): one playbook is exactly one workflow action
(unchanged) OR one or more module actions; the shapes never mix. Mixed,
unsupported, or zero actions fail the load naming the playbook.
playbook.Load now takes a KindSchemas source (a small interface this
package defines, satisfied by *module.ModuleRegistry) so playbook grows
no module import. Callers: bootstrap.loadEDAPlaybooks passes b.modules;
daemon and playbook tests pass module.New().

Per-playbook env (D3): each action's when and args values compile against
an env built from the PRIOR actions' ids typed by their kinds' Result
structs (expr.NewEnv(DeclaredResult{ID,Type})). event stays dyn. An
undeclared id, a forward reference, or a field the kind's Result lacks is
a compile-time undefined-field error.

Args schema (D4): an args key the kind's Args struct does not define
fails the load. An args VALUE whose compiled type mismatches the field
type is left as a named gap (not cheap without leaking cel-go type kinds
into playbook and handling dyn reads); a wrong-typed value still surfaces
at module invoke, not load.

D1: Store.Dispatch routes workflow playbooks only, so an action playbook
cannot hijack the definition pin. bootstrap.loadEDAPlaybooks logs a
visible Warn (not debug) for each loaded action playbook naming it and
stating it does not execute yet.

D5: ModuleRegistry.Invoke is deliberately schema-agnostic (the stored
invoker is type-erased and returns map[string]any). The map-to-Result
marshalling belongs in the coordinator named by the doc, which is the
t2db.31 run path and out of scope here.

Classifier enumeration (E) and verdict, all proven for a typed action
playbook via CEL (expr.NewEnv with a declared log.Result id):

  unknown id                        CEL compile (undefined field)       -> delete unknownActionReference
  literal map index actions["x"]    CEL compile (no _[_] overload)      -> covered
  computed index actions[key]       CEL compile (undeclared 'key')      -> covered
  dynamic index actions[event.name] CEL compile (no _[_] overload)      -> covered
  "x" in actions                    CEL compile (no @in overload)       -> covered
  size(actions)                     CEL compile (no size overload)      -> covered
  actions.all(...)                  CEL compile (not a range)           -> covered
  actions == {}                     CEL compile (no _==_ overload)      -> covered
  bare actions                      compiles; KEPT classifier           -> retained resolvable check

unknownActionReference is deleted; actionReferences/ActionReferences are
kept solely for the bare-actions spelling CEL does not reject.
2026-09-22 09:02:33 +10:00
sam 6b7c123782 feat(eda): type per-playbook action results in CEL env
Declare `actions` as a per-playbook object type with one field per
declared prior action id, each typed by that kind's Go Result struct
(multi-action-playbooks.md D3). A data-driven types.Provider exposes
lower-cased Result fields to the checker, so a result-field typo, an
undeclared id, or a dynamic actions read is a compile-time rejection.
Evaluation still reads an ordinary map value; no custom ref.Val adapter
is needed.

NewEnv now takes the declared results (an empty set is valid); `event`
stays dyn. The playbook loader keeps its current single-action boundary,
so its zero-declared-results env is unchanged and playbook.go needed no
call-site edit. Two playbook tests are updated to assert the new
compile-time rejection semantics.
2026-09-22 08:47:48 +10:00
sam e10a05933a feat(eda): evaluate action args as CEL expressions (J2) 2026-09-22 05:56:26 +10:00
sam 39ba283e47 test(eda): pin playbook dispatch ledger docs and regression gaps 2026-09-22 04:51:17 +10:00
sam 3be7e4cdb0 fix(eda): wire playbook dispatch ledger and validate its key 2026-09-22 04:36:28 +10:00
sam 68c4cf096d style(eda): apply go fix to the ledger coordinator test 2026-09-22 04:36:28 +10:00
sam e8356ed1dd feat(eda): playbook dispatch idempotency ledger
Add the playbook_dispatches at-most-once ledger (docs/prds/eda-playbook-engine.md
gap 2) and the record-then-invoke coordinator helper, with the cross-process
plumbing the State Store boundary requires.

- proto: RecordPlaybookDispatch and DeletePlaybookDispatches RPCs (string keys)
- storecontract: PlaybookDispatcher interface (no *sql.Tx, reuses ErrAlreadyDispatched)
- store: playbook_dispatches table + INSERT OR IGNORE dedup + delete-by-playbook
- staterpc: client/server methods and Deps field; error sentinel survives the hop
- eda/playbook: InvokeOnce record-before-invoke helper, keyed on
  (playbook, version, event, action) with a "1" action-position fallback

The ledger is administrative-only: task-scoped grants never reach it, matching
TaskGrants' Update/Transition/InsertEvent allowlist. Not wired into the daemon
workflow pin; the production call site arrives with the first side-effecting
position.
2026-09-22 04:36:28 +10:00
sam 98c46e210f refactor(eda): extract playbook when-compilation helper 2026-09-22 04:36:28 +10:00
sam c36983d0b1 fix(eda): classify actions references by ident/static access counts
Replace the per-form actions select/index special-casing with one AST
visitor that counts actions identifier nodes and statically-resolvable
accesses. resolvable = (identCount == staticCount): any actions read not
consumed by a static access (non-literal index, in operator, size, bare
actions, equality) now fails playbook load instead of slipping through to
a runtime miss.
2026-09-22 04:36:28 +10:00
sam 753a9f9655 fix(eda): reject non-literal actions index at load 2026-09-22 04:36:28 +10:00
sam 825239405f fix(eda): reject map-index actions references to unknown prior ids 2026-09-22 04:36:28 +10:00
sam e941410370 feat(eda): add optional playbook action ids and when reference validation 2026-09-22 04:36:28 +10:00
sam 61887fd781 feat(eda): wire the playbook coordinator into production workflow selection
A loaded playbook now decides a real task's workflow. The wiring point is the
daemon's definition pin (Daemon.resolveWorkflowID, consumed by
pinWorkflowFromCollection), not pollNATS/publishTask as the design doc
assumed: routing moved out of the agent process when workflow definitions
became database rows pinned before dispatch, so the pin is the one place a
task's workflow is chosen.

Precedence: an explicit Task.Workflow (the waiting_human -> approved requeue)
still wins, then a matching playbook, then workflow.ResolveWorkflowID's
existing label/kind bindings. A playbook naming an undefined workflow is a
reported failure that parks the task rather than a silent fall-through to the
binding's choice -- the operator bound that trigger deliberately.

Store.Dispatch returns the selected workflow name plus the matching playbook's
id and version, instead of a compiled workflow.Workflow: the production caller
decides against the active definition collection, and the id/version are the
first two components of the resolved gap-2 idempotency key. The playbook
package no longer imports internal/domain/workflow.

The shipped example's `when` read event.priority, a field no intake supplies,
so it could never have fired once wired. Both examples now read the event
surface playbookInput really builds, and label-trigger.yaml documents the axis
an instance defines for itself: trigger.kind is the closed workintake
vocabulary because a kind addresses a NATS subject, while trigger.labels is
free-form and binds an operator's own taxonomy to a workflow.

Module/Channel/Forge positions stay rejected at load; they need the
playbook_dispatches ledger first (archie-core-t2db.24).

Closes archie-core-t2db.23
2026-09-21 23:47:06 +10:00
sam 5e94cef784 refactor(workflow): relocate Task/Status/Source and define workflow.Store (#754)
* refactor(workflow,store): relocate Task/Status/Source and define workflow.Store

Move store.Task, store.Status*/store.Source*, and the 3-method workflow
store interface out of internal/store into internal/domain/workflow as
workflow.Task/workflow.Status/workflow.Source plus a consumer-owned
workflow.Store, superseding store.WorkflowStore. internal/domain/workflow
now imports zero internal/store symbols; internal/store persists the
domain type instead (infrastructure depends on domain), and its Store
satisfies workflow.Store.

Updates every production and test caller of the relocated symbols across
daemon, webui, gateway, agentworker, agenttransport/nats, storerpc,
taskrun, and worktreerpc, and removes TestRecordDispatchViaExplicitTx per
docs/prds/state-store-contract.md (rev. 2c) sections 4 and 12 step 2.

Two workflow-package integration tests that exercise the real *store.Store
move to an external workflow_test package (store_integration_test.go) to
avoid a workflow(test)->store->workflow(prod) import cycle now that store
depends on workflow.

* no-mistakes(document): docs(state-store): mark §4.8 relocation done in state-store-contract
2026-09-07 00:39:26 +10:00
sam a4a8ae7e92 feat(eda): thread Playbook ID/Version and DispatchInput task identity (gap-2 prereqs)
Playbook now carries ID (path-relative to the configured root) and Version
(sha256 content hash recomputed on load), both populated in loadOne, mirroring
Binding.Version's provenance pin without a DB row. DispatchInput gains TaskID
carrying TaskEnvelope.IdempotencyKey(), the identity available at the
discovery point (pollNATS / webhook receiver compute kind+labels from a
TaskEnvelope before any store.Task row exists), NOT a store.Task.ID int64.

These are the two implementation prerequisites named by the t2db.17
idempotency resolution; the playbook_dispatches ledger is built on top.

Note: task check fails on 5 lint findings PRE-EXISTING at HEAD in unrelated
files (bootstrap.go cyclop/nestif, install_script_test.go noctx,
telegram_setup_test.go usetesting), reproduced in a clean worktree and not
caused by this change; the eda/playbook package is gofumpt/vet/lint clean.
2026-09-05 03:10:58 +10:00
sam e7afe2da8b feat(eda): playbook document + event coordinator, single-action workflow-kind dispatch
Seventh slice of docs/prds/eda-playbook-engine.md (t2db.15), consuming
t2db.14's expr package: the rich trigger+actions playbook document and
the coordinator that dispatches it.

- internal/domain/eda/playbook: Load(dir) reads *.yaml/*.yml playbook
  documents (trigger + exactly one workflow-kind action + optional CEL
  when), validating the HARD BOUNDARY at load: a playbook with 2+ actions
  or a non-workflow action position is a reported load failure --
  multi-action and Module/Channel/Forge actions stay blocked on the
  unresolved execution-time gaps. Any malformed YAML, invalid trigger,
  missing workflow name, or when compile failure fails the WHOLE load
  (reject-at-load, same shape as routing collisions); a missing dir is an
  empty store. Trigger reuses the existing workintake kind/label
  vocabulary (no second label-matching mechanism). Dispatch matches
  trigger, evaluates when (CEL, event context with actions: {} -- no
  prior actions in single-action playbooks), and returns the named
  workflow from the registry via the same lookup Route() uses -- no
  duplicated dispatch logic. when eval error follows the resolved doc's
  J3: false, skip, caller logs.
- Store.Dispatch(reg, DispatchInput) is the coordinator entrypoint; input
  carries Labels/Kind/Event. Production task intake wiring
  (daemon.go/pollNATS/publishTask) is explicitly NOT in this ticket -- a
  follow-up; proven end to end via direct tests plus the shipped example
  (examples/eda-playbooks/bug-tdd.yaml) loaded and dispatched through the
  real path.
- Config: EDAPlaybookDir (eda_playbook_dir), documented as DISTINCT from
  PlaybookDirs (flat binding files) -- a reader cannot confuse the two.
- Bootstrap: playbook.Load wired in loadWorkflows, log-and-abort on
  failure matching every prior slice; nonexistent dir is an empty store.
- workflow.Route(), workflowForLabels, and the t2db.9-.12 binding loaders
  are UNTOUCHED (verified: their full test suites pass, zero regressions).

Also carries small lint cleanups on t2db.13/.14 code flagged by the gate
run: expr Eval no longer type-asserts to ref.Val (Eval returns ref.Val
directly in v0.32.0; cel-go's own Eval wraps evaluation in recover --
verified in source); module decodeLogArgs extracted to clear the nestif
finding. golangci-lint: 0 issues.

Tests (10): single-action round trip, when-false skip, 2-action load
failure, non-workflow position load failure, when compile failure drops
playbook, empty trigger load failure, trigger mismatch skip, no-when
match, one-invalid-file fails whole load, missing dir empty store, plus
the shipped example load+dispatch. task check clean (113/113 UI, exit 0).
2026-09-03 04:05:59 +10:00