Compare commits

...
99 Commits
Author SHA1 Message Date
sam f8b061c314 chore(release): v1.54.3
deploy / gate (push) Canceled after 0s
deploy / archied-image (push) Canceled after 0s
deploy / agent-image (push) Canceled after 0s
deploy / dist-zip (push) Canceled after 0s
2026-10-16 03:46:35 +11:00
sam c5158edb6c feat(gateway): chat reads workflows and validates drafts
workflow_list, workflow_get and workflow_step_types read the org's
definitions and step catalog; workflow_validate runs the editor's save
check on a proposed definition without saving it.
2026-10-16 03:46:27 +11:00
sam 9ad270b9a4 chore(release): v1.54.2
deploy / gate (push) Canceled after 0s
deploy / archied-image (push) Canceled after 0s
deploy / agent-image (push) Canceled after 0s
deploy / dist-zip (push) Canceled after 0s
2026-10-16 03:33:58 +11:00
sam 51328c9585 fix(deps): ai-sdk v0.3.1 so Gemini Interactions tool calls get valid arguments 2026-10-16 03:33:49 +11:00
sam aa1ca9e653 chore(release): v1.54.1
deploy / gate (push) Canceled after 0s
deploy / archied-image (push) Canceled after 0s
deploy / agent-image (push) Canceled after 0s
deploy / dist-zip (push) Canceled after 0s
2026-10-16 03:11:22 +11:00
sam cb29967e7b fix(releaseupdate): find releases in the public releases repository
The source repository is private, so the updater and install.sh got 404.
Releases are now published to samcharles93/archie-releases by
task release:publish.
2026-10-16 03:11:14 +11:00
sam 474fd59759 chore(release): v1.54.0
deploy / gate (push) Canceled after 0s
deploy / archied-image (push) Canceled after 0s
deploy / agent-image (push) Canceled after 0s
deploy / dist-zip (push) Canceled after 0s
2026-10-16 03:00:32 +11:00
sam 40ee9ffafa fix(rpc): bound gRPC servers and return listener failures
Cap concurrent streams, the handshake and dead peers' streams on every
service, drain shutdown for at most 10s, and stop messaging when its
listener dies instead of running on without Deliver.
2026-10-16 02:57:26 +11:00
sam 939b912889 refactor(ui): unify account administration under Access 2026-10-16 02:57:13 +11:00
sam 83aa17cf8b feat(identity): add browser setup and user accounts 2026-10-16 02:41:24 +11:00
sam 9cdae5642e feat(rpc): mTLS between services from operator-issued certificates
Replace the service bearer tokens with [tls] ca_file and cert_dir. Caller
identity comes from the verified certificate, not metadata. Without TLS,
services listen and dial on loopback only. Task containers get only the CA
and keep their grant.
2026-10-16 02:37:51 +11:00
sam dcf2972f26 feat(ui): start tasks from the dashboard and slim it to activity and setup 2026-10-14 23:28:37 +11:00
sam f96c44d092 refactor(scheduling): remove unused engine accessors 2026-10-14 23:10:35 +11:00
sam f537d5f8cd refactor: delete wrappers superseded by live entry points
Remove controlplanerpc.NewClient (superseded by NewRPCClient), Loader.Overlay
(-config-overlay reaches Resolve directly), and setup.Run (RunParams is
the live entry point). Move ResolverFunc into a test file, since only
tests adapt functions to the egress Resolver.
2026-10-14 23:10:35 +11:00
sam c833b651a9 fix(workflow): set BuildNoChanges from writable stages and clear it on commit
A writable agent stage that passes now marks BuildNoChanges; repo.commit
clears it when the stage commits changes. The flag had no setter, so the
signal was lost in the YAML migration. The outcome of an empty commit
stays with if_empty: unset still fails, complete closes the issue, skip
moves on.
2026-10-14 23:10:34 +11:00
sam 062f5332a0 refactor(gateway): delete unused wrappers and in-memory session store
Remove gateway re-exports of messaging helpers with no callers, the
unused DeltaFunc adapter, DefaultPersonas, NewStoreTaskCreator, the
SortBySeq stub, and the in-memory session store that nothing constructs.
2026-10-14 23:10:34 +11:00
sam d9fe384fd9 build(deps): bump ai-sdk v0.1.43 -> v0.3.0 and update dependencies
Gemini 3.x/4 chat now routes through the Interactions API transport, which
replays thought signatures on tool turns; long decode stays opt-in. Also
takes go get -u updates (x/*, genproto, goose, nats-server, modernc sqlite).
2026-10-14 23:10:34 +11:00
sam 8a7220f5e9 fix(gateway): isolate model selections by org 2026-10-14 21:19:34 +11:00
sam 5b9ff6fa47 fix(gateway): restore provider model selection in chat
Restore provider groups and concrete model references in chat snapshots. Permit catalog selections while retaining named aliases and tenant model restrictions. Show the active model in /profile without requiring a task identity.

Refs: archie-core-mvek6
2026-10-14 21:03:30 +11:00
sam 66b22f4833 build: trim filesystem paths from service and agent binaries 2026-10-14 03:49:31 +11:00
sam acec5d392d feat(archied): read-only run-scoped sandbox view over the harness contract (#1662)
* feat(archied): read-only run-scoped sandbox view over the harness contract

Serve RunTarget: the daemon resolves a running task and attempt to its Kit
container and follows its output, refusing a finished or unknown task with a
stated reason. The dashboard adds a Sandbox tab behind the task log's read
authority. Takeover stays out of scope until the sod1 authority is wired.

* fix(archied): scope and close sandbox views correctly

Forward harness activity into container output, bind containers and dashboard views to their attempt, enforce the asserted org, and report unavailable dependencies and interrupted streams accurately.

Refs: archie-core-qi91, archie-core-252tj
2026-10-14 02:57:32 +11:00
sam 59be81c7f6 fix(webui): an absent setting equals its zero value in drafts; setting rows get roomier padding 2026-10-13 20:20:03 +11:00
sam c0ac39b8da fix(webui): the danger setting row tints without shifting its content 2026-10-13 19:55:05 +11:00
sam 7b19935a14 build(webui): add the CardAccordion chunk missing from the bundle 2026-10-13 19:49:25 +11:00
sam fa7d0d83c1 fix(archied): report schedules apply status at start and on a timer 2026-10-13 19:08:55 +11:00
sam 7542e3b15e fix(archied): report workflow definitions apply status at start and on a timer 2026-10-13 19:06:53 +11:00
sam 6412e6d116 feat(webui): settings lists share a card accordion that opens the new item and blocks adding while unsaved 2026-10-13 19:06:01 +11:00
sam b1dbe519b0 feat(webui): repositories list is an accordion; adding opens the new one and waits for save 2026-10-13 19:04:14 +11:00
sam 3103f87b71 fix(applystatus): the gateway no longer owes an apply status for channel and plugin settings 2026-10-13 19:00:52 +11:00
sam 8664e8cd97 fix(webui): drop settings hints that restate their label 2026-10-13 18:11:12 +11:00
sam 9e566e7278 fix(webui): shorten route descriptions, setup steps, alerts and panel errors 2026-10-13 18:10:39 +11:00
sam f02a3b6d02 fix(agent): drop the one-question cap from the chat prompt and SOUL 2026-10-13 17:49:35 +11:00
sam bf6f3512b1 feat(agent): default persona and SOUL share a reporting-focused identity prompt 2026-10-13 17:47:46 +11:00
sam 00112ae205 fix(webui): attention vocabulary no longer addresses a single user 2026-10-13 17:42:11 +11:00
sam 8001c893bd fix(webui): cut tutorial and marketing prose from labels, hints, empty states and confirms 2026-10-13 17:37:53 +11:00
sam 0e25291d47 fix(webui): review settings drop the in-force echo and rewrite the approval hint 2026-10-13 17:28:31 +11:00
sam 68fb3a7e19 fix(webui): form fields sit on the card colour so they no longer read as disabled 2026-10-13 17:24:48 +11:00
sam 541575a073 fix(archied): load and report EDA playbooks at start instead of at the first dispatch 2026-10-13 17:22:01 +11:00
sam d4d24cb1db fix(webui): default-alias warning states the action only 2026-10-13 17:17:06 +11:00
sam 20cb2fd99d fix(webui): task page drops filler copy, the unattributed-events note and the New run tooltip 2026-10-13 17:16:25 +11:00
sam 4fd6efb7f0 fix(webui): alerts drop UI-explaining prose and align Dismiss with the title 2026-10-13 17:14:43 +11:00
sam 9eabc624ee fix(config): a task snapshot carries only the model limits its aliases resolve to 2026-10-13 17:07:40 +11:00
sam 01418b7e81 fix(webui): harness terminal-unavailable message says what the operator can do 2026-10-13 17:02:45 +11:00
sam cac763a339 feat(webui): finish redesign dashboard task and secret settings 2026-10-13 16:41:35 +11:00
sam 0dde93e57e fix(taskactions): a failed callee cancel no longer leaves the caller's run going
Issue: archie-core-kig5j
2026-10-13 16:22:40 +11:00
sam 7435b6efe5 fix(eda): the undispatched-capture batch lists only captures an enabled binding still owes
Issue: archie-core-kfjz1
2026-10-13 16:21:21 +11:00
sam 796c7a711b fix(postgres): age retention spares captures still waiting to be dispatched
Issue: archie-core-jrh2m
2026-10-13 16:19:12 +11:00
sam 4ac9fd852f fix(postgres): assign bootstrapped agent identities to the default org on every start
Issue: archie-core-n5yj5
2026-10-13 16:18:19 +11:00
sam 06d6293a9d fix(controlplane): instance settings are written by the system org only
Issue: archie-core-f5zso
2026-10-13 16:17:38 +11:00
sam 0c904fb9ef fix(controlplane): playbook dispatch resolves and caches per the task's org
Issue: archie-core-5t4z7
2026-10-13 16:16:31 +11:00
sam 59645969ee fix(e2e): repository policy applies live, so seeding no longer restarts archied
Issue: archie-core-m5aqb
2026-10-13 16:15:07 +11:00
sam acacdfdab5 fix(statestore): an invalid stored policy raises an alert and resolves when it validates
Issue: archie-core-kgxw.16
2026-10-13 16:14:16 +11:00
sam 2090c41960 fix(ops): external NATS needs a token and publishes monitoring on loopback only
Issue: archie-core-ov11
2026-10-13 16:09:23 +11:00
sam e5a67b8ff0 fix(webui): a source create is authorized against the workspace it names
Issue: archie-core-ed8tw
2026-10-13 16:00:37 +11:00
sam 8e6dfd785f fix(webui): channel reload route is authorized as the channel action
Issue: archie-core-4laa1
2026-10-13 15:59:36 +11:00
sam b9547b01a8 fix(staterpc): an org-scoped caller cannot read or write another org's harness secret
Issue: archie-core-jo15w
2026-10-13 15:58:51 +11:00
sam 0720e9629c fix(statestore): a restart never resolves a service alert still inside its grace
Issue: archie-core-07lyl
2026-10-13 15:56:23 +11:00
sam bb67bd77f1 fix(statestore): service-unhealthy grace counts from the last stored report and covers silent services
Issue: archie-core-07lyl
2026-10-13 15:29:29 +11:00
sam 8ecda341e0 fix(servicekit): report apply status only for kinds the process re-applies live
Issue: archie-core-mt91
2026-10-13 15:28:43 +11:00
sam dee78a876a fix(postgres): clamp event, token and denial limits to int32
Issue: archie-core-g14d
2026-10-13 15:27:36 +11:00
sam 33ccfb2505 fix(daemon): run-time workflow check sees the binding event's signature and address
Issue: archie-core-bmro8
2026-10-13 15:10:31 +11:00
sam 0330a65054 fix(postgres): confine identity writes and GetPrincipal to the caller's org
Issue: archie-core-wkey2
2026-10-13 15:07:48 +11:00
sam 4eb9c20c0c fix(workflows): callees of a test run inherit the test source 2026-10-13 12:46:48 +11:00
sam 1f4910a651 feat(workflows): test-run unsaved drafts and browse workflow version history
A test run pins a validated draft, runs with forge and push writes
suppressed and recorded per step, and is excluded from workflow stats.
The History tab lists revisions that changed a workflow, diffs them as
YAML and on the canvas, restores into the editor, and ties runs to the
revision they used.
2026-10-13 12:27:40 +11:00
sam 150bfd4605 fix(postgres): quote the alert lock key so a NUL cannot reach Postgres text 2026-10-13 03:15:06 +11:00
sam 3bf64933b0 fix(ui/topbar): replace Jump to with a command palette, drop filler chrome (#1650)
* fix(ui/topbar): replace Jump to with a command palette, drop filler chrome

Jump to opens a shadcn-vue Command dialog that finds pages, tasks and
workflows by name. The connection indicator shows only when the stream is
lost, the dead documentation link is gone, and the profile menu label has
no stray whitespace.

* fix(ui): trim stray whitespace from template text and drop em dashes from copy

Element text that started or ended with a line break rendered with leading
and trailing spaces. Also removes the unused 'soon' nav state and the nav
group components no route reaches.

* fix(ui): drop the space a hidden spinner left before button text

* fix(ui/status): one dense Status page, full-width settings, problems-only apply status

Status drops its tabs and the duplicate health card; services list only
what is wrong. Settings pages use the full width, the resizable sidebar
handle is gone, and apply status shows only processes that have not
applied a change. PageHeader puts the title and actions on one line.

* refactor(ui): use shadcn ToggleGroup and Badge, drop SegmentedControl and StatusPill

Status badges show only when a state needs attention: no Running, Enabled,
Active, Listening or live pills next to healthy rows. Removes the unused
pagination, radio-group and scroll-area components.

* fix(ui/history): use the shadcn Table with fixed columns so nothing is clipped

* fix(ui/workflows): apply ?workflow= only once the workflow is listed

Selecting it before the definitions loaded opened an empty canvas.

* refactor(ui/workflows): use shadcn Input, NativeSelect, Checkbox and Button in editors

Replaces hand-rolled inputs, selects, the repository mode switch and icon
buttons in the workflow editor, bind dialog, harness page, sources panel
and review gate. Adds the upstream shadcn-vue NativeSelect.

* style(ui): rounded-rectangle controls instead of pills

Halves the radius scale so inputs, selects and buttons stop reading as
pills, and badges and chips lose their full rounding.

* fix(ui/alerts): centre the bell's failed state and stop it contradicting Needs you

* fix(ui/tasks): one header line, aligned columns, no placeholder issue numbers

Tasks puts its filters beside the title and drops the stat tiles the
dashboard already shows. Sort headers align with their cells, chat tasks
no longer show their synthetic issue number, and Logs and the task
not-found page use the shared header.

* fix(ui/dashboard): shared header and cards, empty cards stay silent

Needs you uses the shadcn Card and drops its duplicate Open button; quality
gates and token outlook render only when there is something to show; the
throughput strip moves into the dashboard, its only user.

* refactor(ui/stores): one Pinia store per feature

Splits the site-wide control-plane store and the module-level refs into
settings, workflows, tasks, events, org and session stores. Identity
requests move into lib/api. Drops store fields nothing read: per-resource
stream state, the states map and loadApplyStatus.

* fix(ui/org): one header for the org area, sections drop their repeated titles

The org name is the page title with the admin's org switcher and New org
beside it; Members and Workspaces tables sit in cards like other pages.

* fix(ui/events): shadcn Tabs for the capture, map and bind steps

Replaces the numbered step strip with line tabs that carry each step's
count; the Listening pill is gone and Capture off shows only when it is.

* fix(ui/workflows): confirm a workflow delete in an AlertDialog, not window.confirm

* style(ui/settings): denser setting rows
2026-10-12 04:40:21 +11:00
sam 94d2f98cc0 feat(e2e): local stack, seed and browser checks for release validation 2026-10-12 04:28:26 +11:00
sam 2df2f72fc2 fix(ci): guard apparmor userns sysctl in deploy workflow 2026-10-12 04:17:11 +11:00
sam 8a3ba32c5a Feat/operator alerts (#1635)
* feat(state): durable operator alerts owned by the State Store

Alerts dedup on org+kind+subject, resolve themselves when a condition
clears, and are raised, resolved, dismissed and listed through the state
contract. Task transitions raise needs-human and failed alerts in the same
transaction; the store checks service health and prunes closed alerts.
Each raise and resolve queues a webhook delivery whose attempts are kept.

* feat(notify): deliver operator alerts to the webhook; raise config and release alerts

notify.webhook now receives raised and resolved alerts above a severity
threshold with HMAC-signed payloads, bounded retry and every attempt recorded
on the alert. archied raises model alias, provider and credential-binding
alerts from the effective configuration, an update alert from the release
channel, and a credential-rejected alert from the egress resolver. The
dashboard API lists and dismisses the caller's org's alerts.

* feat(ui): alert bell in the top bar and webhook alert settings

The bell lists the org's open alerts by severity with dismiss and a link per
alert, and refreshes from the event stream. The task settings page gains the
webhook severity threshold and signing secret. ui/dist rebuilt.
2026-10-12 03:30:46 +11:00
sam f34f60f9c7 Feat/org epic (#1634)
* fix(postgres): scope OpenPRs to the caller's org

A principal-carrying caller read every org's pr_open tasks. The query now
honours the request scope; the daemon's unscoped review scan still sees all
orgs.

Issue: archie-core-kgxw.23

* fix(statestore): serve task logs only to the task's org

ReadTaskLog and StreamTaskLogContent took a task ID and read the file with
no org check. The State Store's task-log reader now confirms the task is
visible under the caller's scope first; unscoped services read as before.

Issue: archie-core-kgxw.24

* fix(postgres): scope ListPolicies to the caller's org

Every org's policy text reached any principal-carrying caller. A scoped read
now sees its own org's policies, plus instance policies when scoped to the
system org. The engines and the lockout guard decide for every org, so they
read the full chain unscoped: the dashboard engine loads without the
request's principal and the guard lifts the caller's scope.

Issue: archie-core-kgxw.25

* fix(postgres): scope identity reads to the caller's org

ListIdentities and GetIdentity (and its alias fallback) returned every
identity to any caller. A caller scoped to an org now sees only that org's
members and assigned agents; the system org and unscoped services still see
the whole instance.

Issue: archie-core-kgxw.26

* fix(postgres): hide instance status from other orgs

ListPresence, ListChannelStatus, ListApplyStatus and GetConfigSnapshot
answered any org principal with instance-wide state. They now return nothing
unless the request is unscoped or scoped to the system org. The dashboard
reads the published config as itself, since its handlers project it for
callers of every org.

Issue: archie-core-kgxw.27

* feat(postgres): assign new agents an org and role at creation

A bot or service account created through the API served no org until the
next State Store boot granted it one. Create now assigns it to the org the
request acts in with the developer role in the same transaction, so it is
authorized immediately.

Issue: archie-core-kgxw.14

* feat(edastore): create event records in a chosen workspace

Sources are created in a workspace of the caller's org, the default one when
none is named; event types and bindings take their source's workspace and
mappings their event type's, the same rule the org backfill applied. The
binding, mapping and event type contracts carry the workspace, the four list
endpoints accept ?workspace=, and the Events page has a workspace selector
that filters every step and picks where a new source goes.

Issue: archie-core-kgxw.11

* feat(webui): authorize a record in its workspace

The API built every access request with no workspace, so workspace
policies and per-workspace roles never applied. A request naming a source,
binding, mapping, event type or task now reads the record's workspace under
the caller's scope and authorizes in it; tasks carry their workspace on the
State Store contract for this.

Issue: archie-core-kgxw.9

* feat(access): expose workspace environment to policies

Policies can test resource.workspace.environment. The workspace attribute
is the workspace entity, which carries its environment; the principal
brings its org's workspaces from the State Store, so the dashboard and the
daemon's run checks describe a resource's workspace without another lookup,
and the daemon now authorizes runs in the task's or binding's workspace.

Issue: archie-core-kgxw.10

* fix(webui): ask read_secret when a source secret is read

Rotating a source's secret returns its value, but the route asked update,
which every developer holds, so no policy could narrow who reads a secret.
It now asks read_secret on the secret, which the shipped roles give admins
and an object policy can narrow further.

Issue: archie-core-kgxw.17

* refactor(org): delete the unused upgrade-incomplete sentinel

Nothing returns org.ErrUpgradeIncomplete: the State Store finishes the org
upgrade before it serves.

Issue: archie-core-kgxw.18
2026-10-12 03:24:04 +11:00
sam 8540c9f7c8 feat(releaseupdate): transactional self-update through archied (#1633)
archied update install verifies the release zip, checks every binary
reports the release, pulls the agent image by digest, backs up the
database in-process and stages the binaries before handing off to
archied update watchdog in its own process. The watchdog restarts units
in release order, requires archied healthy for 120s and otherwise rolls
back binaries and image policy, restoring the database only when a
migration ran. Boot recovery resumes the frozen watchdog.

Deletes scripts/archie-update-install, scripts/archie-update-watchdog,
the updater's --from-source and --auto, CommandInstaller,
ScriptInstaller and the update-image and update-topology subcommands.
2026-10-12 03:21:02 +11:00
sam 3014db85e7 Fix/workflow eda audit (#1627)
* fix(webui): accept the merge task action

The action whitelist omitted merge, so the dashboard's Merge button on a
pr_open task was refused with 400 unknown action.

Closes: archie-core-slpoz

* fix(workflow): give each parallel branch its own outputs

Branches shared the task's Outputs map, so concurrent declared-output
writes raced (or were lost when the map started nil). Each branch now
writes a copy; join merges new outputs in branch-name order and refuses
one written by two branches as a second write.

Closes: archie-core-3a7w2

* fix(postgres): dispatch captures oldest first and keep pending ones

ListUndispatchedCaptures ordered newest first and listed captures no
binding can match (failed HMAC), so sustained intake starved older work
and bad signatures held the batch. It is now oldest first and lists only
dispatchable captures. Count retention no longer evicts a capture that
is still pending for an armed binding. The daemon lists only sources
with an enabled workflow, so captures waiting on a disabled one do not
hold the oldest-first batch.

Closes: archie-core-2et4b, archie-core-o0s0z

* fix(ui): refuse renaming a workflow onto an existing id

Saving upserts by id, so editing a workflow's id to another workflow's
id removed the open one and overwrote the other. The editor now refuses
that save and says why.

Closes: archie-core-wpoz8

* fix(workflow): reject unknown step settings at save

Step factories decoded settings with yaml.Node.Decode, which drops keys
it does not know, and settings-less steps ignored settings entirely, so a
misspelt key (readOnly for read_only) saved and silently did nothing.
Every factory now decodes strictly and settings-less steps refuse
settings; ParseDefinition runs the factories, so the save refuses them.

Closes: archie-core-8b5nk

* fix(postgres): keep a stored capture when its prune fails

InsertCapture committed the capture, then returned the prune's error, so
intake answered 500 and a sender without a delivery header retried into
a duplicate capture and a duplicate dispatch. A failed prune is now
logged and the stored capture's id returned.

Closes: archie-core-3miuh

* fix(crondelivery): fail and advance a job no runner can deliver

Router.Run returned nil for a kind with no runner, so the engine reported
a successful run while the schedule never advanced and the job fired on
every tick. The run now fails with the refusal, which the engine reports,
and the schedule advances (a one-shot is removed). The router's own
refusal event is gone with it.

Closes: archie-core-s6ahh

* fix(taskactions): stop the runs of cancelled callees

CancelExecution cancelled a caller's waited-on callees in the store, but
only the caller's run was stopped, so callee containers ran to the end.
CancelExecution now returns the callees it cancelled (nested included)
in place of the step ids nobody read, and every cancelling action stops
their runs too.

Closes: archie-core-9labz

* fix(workflow): treat a zero json.Number as false in when

Task inputs and step results decode numbers as json.Number, which truthy
did not unpack, so when: inputs.count held for a count of 0.

Closes: archie-core-uv270

* fix(webui): read a workflow's runs with a workflow-filtered page

The workflows page and the canvas run picker filtered the newest 100
tasks of every workflow client-side, so on a busy instance a workflow's
older runs were invisible. GET /api/tasks takes a workflow filter, carried
through the State Store's Tasks request to the query, and both views ask
for the selected workflow's runs.

Closes: archie-core-tpiw1

* fix(ui): load the restored workflow into the editor

Restore Defaults saved the shipped definition but left the open draft in
the editor, still marked unsaved, so a later save re-applied it. The
editor now reloads the restored definition.

Closes: archie-core-85e7w
2026-10-12 03:20:00 +11:00
sam aea7c5c9f1 build(tools): provision PostgreSQL 18 in the cloud setup for full checks 2026-10-12 03:00:46 +11:00
sam c792c552cf build(tools): link cloud setup tools onto the default PATH 2026-10-12 02:44:11 +11:00
sam a71f1e0817 ci: drop the Postgres client from the deploy gate 2026-10-12 02:19:51 +11:00
sam 76905c8ec6 ci: run every job on the self-hosted runner 2026-10-12 02:10:14 +11:00
sam 85d8b771f0 Merge pull request #1602 from samcharles93/feat/workflow-runs-as
Feat/workflow runs as
2026-10-12 02:08:30 +11:00
sam d31a950daa feat(workflow): shipped workflows run as the instance root 2026-10-12 01:53:55 +11:00
sam f765e23812 feat(daemon): run each workflow as its declared identity
Every attempt checks that the identity that started the task and the
identity the workflow declares may both run it, recording a denial for
either. A workflow that declares no identity is refused rather than
running as its starter or the root. A workflow.call callee is started by
its caller's declared identity instead of inheriting the caller's row.
The workflow settings panel marks the identity as required and offers
the agent identities.
2026-10-11 14:49:38 +00:00
sam d66dca44e0 Merge pull request #1601 from samcharles93/fix/atomic-dispatch
Fix/atomic dispatch
2026-10-12 01:29:16 +11:00
sam b8f8f9a272 fix(postgres): allocate synthetic issue numbers from a per-repo counter
InsertChatTask and EnqueueCallTask computed MAX(issue_number)+1, so
concurrent inserts in one repository took the same number and the second
failed on the unique key. Both now bump a chat_issue_numbers row, seeded
from the existing maxima, whose row lock serializes allocation.
2026-10-11 14:21:27 +00:00
sam e128f82e11 build(ui): install dashboard deps from the lockfile without rewriting it 2026-10-12 01:21:16 +11:00
sam daab5732e8 fix(daemon): claim binding dispatch and enqueue its task atomically
EnqueueBindingTask now takes the capture and claims the ledger row,
inserts the task, stamps its provenance and links the ledger row in one
State Store transaction. A failure anywhere leaves the delivery
undispatched for the next cycle; a replay or concurrent claim is refused
by the ledger's unique index. SetDispatchTask is removed.
2026-10-11 14:19:43 +00:00
sam eb5703b7dd ci: drop the Postgres client the removed tests needed 2026-10-12 01:17:11 +11:00
sam ce5fc3e226 test(postgres): remove database-backed tests and the testcontainers harness 2026-10-12 01:17:02 +11:00
sam c2a649ded4 docs(agents): forbid database-backed tests 2026-10-12 01:15:19 +11:00
sam 1b0a89ca2e fix(tools): keep bd hook setup out of the checkout 2026-10-12 01:14:38 +11:00
sam 1441585e06 chore: reindent beads config and add agent profile 2026-10-12 01:01:19 +11:00
sam f3576342b6 chore(tools): rely on preinstalled gh in cloud setup 2026-10-12 00:46:51 +11:00
sam ede2102c60 chore(tools): install gh in cloud setup 2026-10-12 00:43:37 +11:00
sam 16d98dd47c chore(tools): install bd via upstream installer and disable attribution in cloud setup 2026-10-12 00:41:07 +11:00
sam 7aca31b18f chore(tools): add Claude cloud environment setup script 2026-10-12 00:12:18 +11:00
sam e97f1fa609 fix(ci): limit gate concurrency to runner memory 2026-10-11 22:28:11 +11:00
sam 62f0baba36 fix(ci): use repository-scoped quality runner 2026-10-11 22:10:52 +11:00
sam 40fa6f9d7d fix(ci): check namespace support before installing tools 2026-10-11 21:33:56 +11:00
sam 6ce605d6ea fix(ci): allow extension namespaces in quality container 2026-10-11 21:30:43 +11:00
sam feba855326 style(ui): tidy org page layouts and empty states
Members and Workspaces get fixed column widths and their add forms move
into labelled sections. Agents lists agents first and moves credential
grants below. Access puts New policy in the card header. Tokens states
when none exist.
2026-10-11 15:59:30 +11:00
sam 47f75f71a7 docs: remove incorrect notice 2026-10-11 12:17:31 +11:00
sam 4e060ce5ef fix(ui): stage history restore as a draft applied from the save bar 2026-10-11 11:35:02 +11:00
618 changed files with 23217 additions and 11255 deletions

No files matched your search

+13 -11
View File
@@ -54,15 +54,15 @@
# Disabled by default; enable only when an integration needs fresh .beads/issues.jsonl.
# Use relative paths under .beads/ for JSONL import/export filenames.
export:
auto: false
path: issues.jsonl
interval: 60s
# issues.jsonl/interactions.jsonl are .gitignore'd local-only files --
# Dolt (synced via sync.remote) is the source of truth. Leave auto off
# and git-add off; do not re-track these in git.
git-add: false
auto: false
path: issues.jsonl
interval: 60s
# issues.jsonl/interactions.jsonl are .gitignore'd local-only files --
# Dolt (synced via sync.remote) is the source of truth. Leave auto off
# and git-add off; do not re-track these in git.
git-add: false
import:
path: issues.jsonl
path: issues.jsonl
# Integration settings (access with 'bd config get/set')
# Non-secret keys (stored in the database):
# - jira.url, jira.project
@@ -74,7 +74,9 @@ import:
# - github.token → use GITHUB_TOKEN env var instead
sync.remote: "git+https://github.com/samcharles93/archie-core.git"
dolt:
shared-server: false
auto-commit: "on"
shared-server: false
auto-commit: "on"
audit:
enabled: true
enabled: true
agent:
profile: team-maintainer
+15 -27
View File
@@ -30,7 +30,7 @@ permissions:
jobs:
gate:
runs-on: ubuntu-latest
runs-on: self-hosted
outputs:
archied_version: ${{ steps.release_tag.outputs.archied_version }}
steps:
@@ -73,22 +73,6 @@ jobs:
- name: Install protobuf tools
run: bash tools/proto.sh install
# The backup/restore tests shell out to pg_dump/pg_restore against a
# postgres:18 testcontainer; the runner's stock client is older and
# refuses the server version.
- name: Install PostgreSQL 18 client
run: |
sudo install -d /usr/share/postgresql-common/pgdg
sudo curl --fail --silent --show-error --location \
https://www.postgresql.org/media/keys/ACCC4CF8.asc \
--output /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc
. /etc/os-release
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt ${VERSION_CODENAME}-pgdg main" \
| sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt-get update
sudo apt-get install -y --no-install-recommends postgresql-client-18
echo "/usr/lib/postgresql/18/bin" >> $GITHUB_PATH
- name: Ensure contract baseline ref
run: |
if ! git show-ref --verify --quiet refs/heads/main; then
@@ -101,7 +85,11 @@ jobs:
# Extensions run in an unprivileged user and network namespace, which
# Ubuntu 24.04 runners forbid through AppArmor by default.
- name: Allow unprivileged user namespaces
run: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
run: |
if [ -e /proc/sys/kernel/apparmor_restrict_unprivileged_userns ]; then
sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
fi
unshare --user --map-root-user --net true
# The gate's uncached `go test ./...` runs the Docker-backed tests that
# -short skips, and those start a container from alpine:3. A fresh runner
@@ -178,7 +166,7 @@ jobs:
archied-image:
needs: gate
runs-on: ubuntu-latest
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v4
@@ -273,7 +261,7 @@ jobs:
outputs:
agent_digest: ${{ steps.agent.outputs.digest }}
needs: gate
runs-on: ubuntu-latest
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v4
@@ -336,7 +324,7 @@ jobs:
# the ref that won the race, and skip only when there is genuinely no
# archied tag at HEAD.
if: needs.gate.outputs.archied_version != ''
runs-on: ubuntu-latest
runs-on: self-hosted
# Least privilege: the workflow default is contents:read, and only this
# job needs to write, to create the Release and attach the zip to it.
permissions:
@@ -388,7 +376,6 @@ jobs:
cp "dist/$cmd" "$name/"
done
cp deployments/INSTRUCTIONS.md CHANGELOG.md "$name/"
cp scripts/archie-update-* "$name/"
digest='${{ needs.agent-image.outputs.agent_digest }}'
test -n "$digest"
jq --arg image "ghcr.io/samcharles93/archie-agent@$digest" '. + {agent_image: $image}' release.json > "$name/release.json"
@@ -421,7 +408,8 @@ jobs:
# already guarantees it describes this version.
- name: Publish GitHub Release with the distribution zip
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# GITHUB_TOKEN cannot write to another repository.
GH_TOKEN: ${{ secrets.RELEASES_TOKEN }}
run: |
set -e
tag="v${{ steps.version.outputs.version }}"
@@ -447,12 +435,12 @@ jobs:
# Idempotent: --clobber replaces the asset and leaves the notes
# alone, so a re-run of this job (a retried or superseded deploy)
# cannot fail on an existing Release or duplicate the zip.
if gh release view "$tag" >/dev/null 2>&1; then
gh release upload "$tag" "${{ steps.zip.outputs.name }}.zip" SHA256SUMS --clobber
if gh release view "$tag" -R samcharles93/archie-releases >/dev/null 2>&1; then
gh release upload "$tag" -R samcharles93/archie-releases "${{ steps.zip.outputs.name }}.zip" SHA256SUMS install.sh --clobber
else
gh release create "$tag" \
gh release create "$tag" -R samcharles93/archie-releases \
--title "archied v$version" \
--notes-file "$notes" \
"${{ steps.zip.outputs.name }}.zip" SHA256SUMS
"${{ steps.zip.outputs.name }}.zip" SHA256SUMS install.sh
fi
echo "published $tag with ${{ steps.zip.outputs.name }}.zip"
+9 -23
View File
@@ -14,12 +14,19 @@ concurrency:
jobs:
check:
runs-on: ubuntu-latest
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Verify extension namespace support
run: |
if [ -e /proc/sys/kernel/apparmor_restrict_unprivileged_userns ]; then
sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
fi
unshare --user --map-root-user --net true
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
@@ -39,22 +46,6 @@ jobs:
sudo apt-get update
sudo apt-get install -y --no-install-recommends ripgrep
sudo install -d /usr/share/postgresql-common/pgdg
sudo curl --fail --silent --show-error --location \
https://www.postgresql.org/media/keys/ACCC4CF8.asc \
--output /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc
. /etc/os-release
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt ${VERSION_CODENAME}-pgdg main" \
| sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt-get update
sudo apt-get install -y --no-install-recommends postgresql-client-18
echo "/usr/lib/postgresql/18/bin" >> $GITHUB_PATH
pg_dump --version
pg_restore --version
- name: Ensure contract baseline ref
run: |
@@ -62,12 +53,7 @@ jobs:
git branch main origin/main
fi
# Extensions run in an unprivileged user and network namespace, which
# Ubuntu 24.04 runners forbid through AppArmor by default.
- name: Allow unprivileged user namespaces
run: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
- name: Run definitive gate
run: |
task check
task --concurrency 1 check
git diff --exit-code
+51
View File
@@ -5,6 +5,57 @@ release's per-component sections are labelled beneath its heading.
## [Unreleased]
## [1.54.3] - 2026-10-16
### archied
- Chat can help write a workflow: it reads your workflows and the step catalog, writes a definition, and checks it the same way saving does, fixing what the check reports. It does not save; paste the YAML it gives you into the editor's YAML view and save there.
## [1.54.2] - 2026-10-16
### archied
- Tool calls from Gemini models (Interactions API) receive their arguments intact. Any tool that takes arguments, such as `dashboard_navigate` in chat, failed with "invalid character '{' after top-level value".
### archie-agent
- Agent steps on Gemini models (Interactions API) pass tools their arguments intact instead of failing to decode them.
## [1.54.1] - 2026-10-16
### archied
- Update checks, `archied update install` and `install.sh` find releases at `github.com/samcharles93/archie-releases`, so a host can update again. A host on 1.54.0 or earlier still looks in the old place and has to be upgraded to 1.54.1 by hand once.
## [1.54.0] - 2026-10-16
**Upgrade note:** services now authenticate each other with TLS certificates from your own CA instead of shared tokens. Before upgrading a host whose services listen on anything but loopback (any host running agent containers), issue a certificate per service (`archied`, `archie-gateway`, `archie-messaging`, `archie-state-store`, `archie-ui`, each with its name as the DNS SAN and both server and client auth), add `[tls] ca_file` and `cert_dir` to `config.toml`, and remove every `target_token`, the `*_TOKEN` service variables and the `--token`/`--*-token` flags, including archie-ui's `-token` and `-token-file`. A unit that still passes a removed flag fails to start. See `config.example.toml`.
### archied
- Services authenticate each other with mutual TLS. Each process presents `<cert_dir>/<service>.pem`, peers must chain to `ca_file`, and a caller is identified by its certificate rather than by what it claims. Renewed certificates are picked up without a restart. Without `[tls]`, services listen on and dial loopback only. The harness setup terminal requires `[tls]`.
- Every gRPC service caps the streams a connection holds, times out stalled handshakes, releases a dead client's streams, and drains for at most 10 seconds on shutdown. Messaging exits when its listener fails instead of staying up without delivering.
- The dashboard has user accounts. First run opens browser setup for the organisation, workspace and first administrator; people then sign in with a password, a passkey or your identity provider, and account administration lives under Access. The shared dashboard token is gone; reach the dashboard remotely through an HTTPS reverse proxy.
- `archied update install` updates a host in one transaction: it verifies the release, stages every binary, pulls the agent image by digest and backs up the database, then restarts the services in order and rolls everything back if archied is not healthy for two minutes.
- Each workflow runs as the identity it declares, checked on every attempt along with the identity that started it. A workflow that declares none is refused, a called workflow runs as its caller's declared identity, and shipped workflows run as the instance root.
- Test-run a workflow draft before saving it, with forge and push writes suppressed and recorded per step. The History tab lists a workflow's revisions, diffs them as YAML and on the canvas, restores one into the editor, and shows which revision each run used.
- Start a task from the dashboard. The dashboard home shows activity and setup, and a running task has a read-only Sandbox tab that follows its container.
- The topbar's Jump to is a command palette, settings lists open as accordions that wait for a new item to be saved, and history restores land as a draft applied from the save bar.
- Labels, hints, alerts and empty states say what is wrong and what to do, without tutorial or marketing prose.
- Org isolation is tighter: harness secrets, identity writes, principals, playbook dispatch and model selections in chat stay in the caller's org, instance settings are written by the system org only, and creating a source or reloading a channel is authorized against the target.
- Binding dispatch claims its capture and enqueues the task atomically, so a capture cannot start two runs, and the run-time workflow check sees the binding event's signature and address.
- Service-unhealthy alerts count their grace from the last report and also cover a service that went silent, and a restart no longer clears an alert still inside its grace. An invalid stored access policy raises an alert until it validates.
- A failed cancel of a called workflow no longer leaves the caller running, retention spares captures still waiting to be dispatched, and EDA playbooks load and report at start instead of on first dispatch.
- Chat model selection works again for provider models.
### archie-agent
- Each run acts as its workflow's declared identity.
- A task snapshot carries only the model limits its aliases resolve to.
- A build step's "no changes" result comes from its writable stages and clears once a commit lands.
- Test runs suppress forge and push writes and record what they would have done.
- The default persona is a reporting-focused identity prompt, without the one-question limit in chat.
## [1.53.0] - 2026-10-11
### archied
+2 -1
View File
@@ -97,7 +97,8 @@ The default for a change is no new test. Write one only when:
A test that exists must catch a real regression, survive refactoring, run fast,
and be cheap to keep. Never test wiring, constants, defaults, struct shapes,
fakes, or call order. One table-driven test per behaviour; extend the table
fakes, or call order. No test opens a real database or needs Docker; test
SQL semantics at the interceptor or domain level with fakes. One table-driven test per behaviour; extend the table
instead of adding a second test. Prefer making an invalid state unrepresentable
to testing that it is rejected. Test helpers live in `_test.go` files only.
-12
View File
@@ -1,17 +1,5 @@
NOTICE
This product includes software derived from PR-AF
(https://github.com/Agent-Field/pr-af), Copyright AgentField,
licensed under the Apache License, Version 2.0.
Derived portions: internal/domain/workflow/prreview -- the unified diff
parser, change clustering, blast radius, evidence extraction, scoring,
deduplication, line mapping and review-event selection.
PR-AF declares the Apache License, Version 2.0 in its pyproject.toml and
ships no license file. A copy of the License is available at
https://www.apache.org/licenses/LICENSE-2.0
This product includes software from the Cedar project
(https://github.com/cedar-policy/cedar), Copyright Amazon.com, Inc. or its
affiliates, licensed under the Apache License, Version 2.0, as implemented by
+7
View File
@@ -58,8 +58,15 @@ task release:prepare VERSION=1.3.0 # write the section into CHANGELOG.md, un
# edit CHANGELOG.md -- generated notes are a starting point, not the release
task release VERSION=1.3.0 # commit + annotated tag
git push --atomic origin main v1.3.0 # both refs or neither
task release:publish VERSION=1.3.0 # images to GHCR, zip to archie-releases
```
The source repository is private, so releases are published to the public
`samcharles93/archie-releases` repository, where `install.sh` and the
updater find them. `release:publish` builds from a clean worktree of the tag
and needs `gh` and `docker` logged in with write access to that repository
and to GHCR.
`release:prepare` emits bare commit subjects; they are a starting point. Rewrite
them to say what a reader gets, per "What the notes are for" above.
+29 -5
View File
@@ -142,7 +142,7 @@ tasks:
run: once
dir: ui
cmds:
- npm install --no-audit --no-fund
- npm ci --no-audit --no-fund
ui:
desc: Build the dashboard into ui/dist (committed; the Go build embeds it)
@@ -245,6 +245,22 @@ tasks:
- npm install --no-audit --no-fund
- npm run dev
e2e:up:
desc: Start the local stack without Docker (PostgreSQL 18, services, Vite) and seed it
cmds:
- bash e2e/stack.sh start
- bash e2e/seed.sh
e2e:down:
desc: Stop the local e2e stack
cmds:
- bash e2e/stack.sh stop
e2e:check:
desc: Run the browser checks against the running e2e stack (-- --record VERSION for release evidence)
cmds:
- node e2e/run.cjs {{.CLI_ARGS}}
dev:mobile:
desc: Serve the dashboard on your LAN (token-protected) for phone viewing
deps:
@@ -273,6 +289,7 @@ tasks:
-X github.com/samcharles93/archie-core/internal/buildinfo.Version={{.GATEWAY_VERSION}}
-X github.com/samcharles93/archie-core/internal/buildinfo.Runtime={{.RUNTIME_VERSION}}
sources:
- Taskfile.yml
- "**/*.go"
- go.mod
- go.sum
@@ -285,11 +302,11 @@ tasks:
- "{{.BIN_DIR}}/archie-messaging"
- "{{.BIN_DIR}}/archie-agent"
cmds:
# One flag set for every service, matching scripts/archie-update-install
# and the release workflow, so each binary reports the same version.
# One flag set for every service, matching the release workflow, so each
# binary reports the same version.
- for: [archied, archie-gateway, archie-state-store, archie-ui, archie-messaging]
cmd: go build -ldflags "{{.SERVICE_LDFLAGS}}" -o {{.BIN_DIR}}/{{.ITEM}} ./cmd/{{.ITEM}}
- go build -ldflags "-X github.com/samcharles93/archie-core/internal/app/agentworker.version={{.RUNTIME_VERSION}} -X github.com/samcharles93/archie-core/internal/installtype.buildType=binary" -o {{.BIN_DIR}}/archie-agent ./cmd/archie-agent
cmd: go build -trimpath -ldflags "{{.SERVICE_LDFLAGS}}" -o {{.BIN_DIR}}/{{.ITEM}} ./cmd/{{.ITEM}}
- go build -trimpath -ldflags "-X github.com/samcharles93/archie-core/internal/app/agentworker.version={{.RUNTIME_VERSION}} -X github.com/samcharles93/archie-core/internal/installtype.buildType=binary" -o {{.BIN_DIR}}/archie-agent ./cmd/archie-agent
test:
desc: Run short Go tests with caching
@@ -343,6 +360,13 @@ tasks:
requires:
vars: [VERSION]
release:publish:
desc: Push the images and publish the pushed tag to the public releases repository (VERSION=1.2.0)
cmds:
- tools/publish.sh {{.VERSION}}
requires:
vars: [VERSION]
clean:
desc: Remove build artifacts
cmds:
+1
View File
@@ -91,6 +91,7 @@ func runCommand(args []string, getenv func(string) string, stderr io.Writer, run
NATSToken: natsToken,
StateStoreTarget: stateStoreURL,
StateStoreToken: stateStoreToken,
StateStoreCA: []byte(getenv("STATE_STORE_CA")),
ModelProxy: getenv(egress.ModelProxyEnv),
ModelProxyHosts: egress.ParseHosts(getenv(egress.ModelProxyHostsEnv)),
ModelProxyCA: getenv(egress.ModelProxyCAEnv),
-1
View File
@@ -22,7 +22,6 @@ func run() int {
flag.StringVar(&options.Config, "config", configuration.DefaultConfigPath(), "configuration file or directory")
flag.StringVar(&options.Overlay, "config-overlay", "", "configuration overlay file or directory")
flag.StringVar(&options.Listen, "listen", "", "gateway gRPC listen address (defaults to [services.gateway].listen, else 127.0.0.1:8585)")
flag.StringVar(&options.Token, "token", "", "Bearer [REDACTED] required for a non-loopback listener (defaults to [services.gateway].target_token)")
flag.Parse()
showVersion()
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
-3
View File
@@ -23,11 +23,8 @@ func run() int {
flag.StringVar(&options.Config, "config", configuration.DefaultConfigPath(), "configuration file or directory")
flag.StringVar(&options.Overlay, "config-overlay", "", "configuration overlay file or directory")
flag.StringVar(&options.Gateway.Target, "gateway-target", "", "archie-gateway gRPC address (defaults to [services.gateway].target, else 127.0.0.1:8585)")
flag.StringVar(&options.Gateway.Token, "gateway-token", "", "bearer token presented to archie-gateway")
flag.StringVar(&options.StateStore.Target, "state-store-target", "", "archie-state-store gRPC address (defaults to [services.state].target)")
flag.StringVar(&options.StateStore.Token, "state-store-token", "", "bearer token presented to archie-state-store")
flag.StringVar(&options.Listen, "listen", "", "MessagingService gRPC listen address (defaults to [services.messaging].listen)")
flag.StringVar(&options.Token, "token", "", "bearer token required from MessagingService callers on a non-loopback listener")
flag.DurationVar(&options.DependencyTimeout, "dependency-timeout", 0, "readiness probe timeout (default 5s)")
flag.DurationVar(&options.ShutdownTimeout, "shutdown-timeout", 0, "shutdown timeout (default 5s)")
flag.Parse()
-1
View File
@@ -34,7 +34,6 @@ func run() int {
flag.StringVar(&options.Config, "config", configuration.DefaultConfigPath(), "configuration file or directory")
flag.StringVar(&options.Overlay, "config-overlay", "", "configuration overlay file or directory")
flag.StringVar(&options.Listen, "listen", "", "state store gRPC listen address (defaults to [services.state].listen, else 127.0.0.1:9090)")
flag.StringVar(&options.Token, "token", "", "bearer token required for a non-loopback listener (defaults to [services.state].target_token)")
flag.StringVar(&options.ReadyAddr, "ready-addr", "", "optional readiness HTTP listen address (e.g. 127.0.0.1:9091)")
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "usage: archie-state-store [flags] # serve the State Store gRPC contract\n\noffline recovery: archie-state-store <backup|restore|validate|rollback> -h | access reset -h\n\n")
-5
View File
@@ -27,19 +27,14 @@ func run() int {
flag.StringVar(&options.Config, "config", configuration.DefaultConfigPath(), "configuration file or directory (only [services.*] targets and [web] are read)")
flag.StringVar(&options.Overlay, "config-overlay", "", "configuration overlay file or directory")
flag.StringVar(&options.Listen, "listen", "", "dashboard HTTP listen address (defaults to [web].listen, else 127.0.0.1:8484)")
flag.StringVar(&options.Token, "token", "", "dashboard token; required for a non-loopback listener")
flag.StringVar(&options.TokenFile, "token-file", "", "file holding the dashboard token, minted on first use")
flag.StringVar(&options.OidcIssuer, "oidc-issuer", "", "identity provider issuer URL; requests must then carry a token it signed")
flag.StringVar(&options.OidcAudience, "oidc-audience", "", "audience (resource identifier) this dashboard accepts tokens for; required with -oidc-issuer")
flag.StringVar(&options.OidcClientID, "oidc-client-id", "", "provider client id for browser sign-in; omitted means no sign-in flow")
flag.StringVar(&options.OidcClientSecretEnv, "oidc-client-secret-env", "", "name of the environment variable holding the sign-in client secret")
flag.StringVar(&options.OidcRedirectURL, "oidc-redirect-url", "", "callback URL registered at the provider (path must be /oauth2/callback)")
flag.StringVar(&options.Gateway.Target, "gateway-target", "", "archie-gateway gRPC address (defaults to [services.gateway].target)")
flag.StringVar(&options.Gateway.Token, "gateway-token", "", "bearer token presented to archie-gateway")
flag.StringVar(&options.State.Target, "state-target", "", "archie-state-store gRPC address (defaults to [services.state].target)")
flag.StringVar(&options.State.Token, "state-token", "", "bearer token presented to archie-state-store")
flag.StringVar(&options.Harness.Target, "harness-target", "", "archied harness session gRPC address (defaults to [services.harness].target); empty leaves the setup terminal unwired")
flag.StringVar(&options.Harness.Token, "harness-token", "", "bearer token presented to the daemon's harness contract")
flag.DurationVar(&options.DependencyTimeout, "dependency-timeout", 0, "per-dependency readiness probe timeout (default 5s)")
flag.DurationVar(&options.EventPollInterval, "event-poll-interval", 0, "how often the activity feed polls the State Store for new events (default 1s)")
// BoolFunc rather than BoolVar so an unset flag stays distinguishable
-6
View File
@@ -20,12 +20,6 @@ func main() {
if len(args) > 0 && args[0] == "update" {
os.Exit(archied.RunUpdate(args[1:], os.Stdout, os.Stderr))
}
if len(args) > 0 && args[0] == "update-image" {
os.Exit(archied.RunUpdateImage(args[1:], os.Stderr))
}
if len(args) > 0 && args[0] == "update-topology" {
os.Exit(archied.RunUpdateTopology(args[1:], os.Stdout, os.Stderr))
}
if len(args) > 0 && args[0] == "status" {
os.Exit(archied.RunStatus(args[1:], os.Stdout, os.Stderr))
}
+20 -21
View File
@@ -246,12 +246,14 @@ listen = "127.0.0.1:8484"
# [memory]
# engine = "builtin" # "builtin" is the only engine implemented so far
# Notifications for human-in-the-loop moments
# (approval requests, gate failures, parked tasks).
# Archie POSTs a JSON payload to the webhook
# wire it to n8n, email, Slack, or any HTTP endpoint.
# Operator alerts (parked tasks, failed runs, unhealthy services, missing
# credentials) are listed in the dashboard. Archie also POSTs each raised and
# resolved alert as JSON to the webhook: wire it to n8n, email, Slack, or any
# HTTP endpoint. Failed deliveries are retried and recorded on the alert.
[notify]
# webhook = "https://n8n.example.com/webhook/archie"
# min_severity = "warning" # info, warning or action: the lowest severity delivered
# secret = {engine = "env", key = "ARCHIE_NOTIFY_SECRET"} # signs X-Archie-Signature (HMAC-SHA256)
[budgets]
max_steps = 60
@@ -259,6 +261,18 @@ wall_clock = "30m" # one agent call
gate_max_failures = 5
task_wall_clock = "4h" # a whole task run; keep containers.max_uptime at or above it
# TLS: every gRPC hop between services uses certificates from your own CA
# (step-ca, cert-manager, Vault, openssl). Each process loads
# cert_dir/<service>.pem and cert_dir/<service>-key.pem, whose DNS SAN is its
# service name: archied, archie-gateway, archie-messaging, archie-state-store,
# archie-ui. Every peer must chain to ca_file. Certificates are reloaded when
# they change. Without [tls], services may only listen on and dial loopback
# addresses, task containers cannot reach the State Store, and the harness
# setup terminal is off.
# [tls]
# ca_file = "/etc/archie/tls/ca.pem"
# cert_dir = "/etc/archie/tls"
# Services selects contract adapters at composition time.
[services.gateway]
target = "127.0.0.1:8585" # archie-gateway's gRPC address (always remote once set)
@@ -267,11 +281,6 @@ target = "127.0.0.1:8585" # archie-gateway's gRPC address (always remot
# # to the target above, so a default deployment's client and
# # server cannot drift onto different ports. Set it when the
# # host already owns that port.
# target_token = "..." # Bearer [REDACTED] for a NON-loopback listener. A loopback listener
# # (127.0.0.1/::1/localhost) needs no token. A non-loopback
# # listener without a token fails closed, as does a
# # non-loopback dial without one. The same token is
# # presented as GATEWAY_TOKEN by remote consumers.
[services.state]
target = "127.0.0.1:9090" # REQUIRED. The State Store gRPC address archied and
@@ -283,25 +292,15 @@ target = "127.0.0.1:9090" # REQUIRED. The State Store gRPC address arch
# # above, so a default deployment's client and server cannot
# # drift onto different ports. Move it when a port is already
# # taken on the host.
# target_token = "..." # bearer token for a NON-loopback target. A loopback target
# # (127.0.0.1/::1/localhost) needs no token. A non-loopback
# # target without a token fails closed. The same token is injected as STATE_STORE_TOKEN into
# # archie-agent containers so the agent authenticates to the
# # same remote store. See deployments/README.md for how to
# # start archie-state-store.
# The daemon's harness session contract: the dashboard's setup terminal opens
# a PTY into an ephemeral Kit container over it. Both ends are optional and
# the dashboard's setup terminal degrades to 503 without them: the daemon
# serves the contract only when target_token (or HARNESS_TOKEN) is set, and
# archie-ui dials it only when a target is set.
# serves the contract only when [tls] is configured, and archie-ui dials it
# only when a target is set.
# [services.harness]
# target = "127.0.0.1:8587" # The address archie-ui dials. Empty leaves the
# # setup terminal unwired.
# target_token = "..." # REQUIRED, even on loopback: a session is a
# # shell in a container that holds an org credential.
# # The daemon reads the same value to authenticate its
# # clients. Leave unset to disable the listener.
# NATS is the sole autonomous workflow handoff. mode changes only where the
# broker runs; every workflow still runs in a managed task container:
+32 -33
View File
@@ -55,14 +55,9 @@ as a host binary. Pull it from GHCR: `ghcr.io/samcharles93/archie-agent`.
./archied -config ~/.config/archie/config.toml
```
Dashboard reachability comes from `[web].listen` (default
`127.0.0.1:8484`, which needs no dashboard token). For a non-loopback
bind pass `-listen` with `-token` or `-token-file` to mint and persist
one. `archie-ui` reads `GATEWAY_TOKEN` / `STATE_STORE_TOKEN` from its
process environment only — it has no secret registry, so when those
tokens live in a secret manager, whatever starts `archie-ui` must export
them into its environment (the `[services.*].target_token` values in
`config.toml` are the other supported source).
Open `[web].listen` (default `127.0.0.1:8484`) to configure the organisation,
workspace and first administrator account. Remote access requires an HTTPS
reverse proxy. Complete setup before exposing the dashboard publicly.
4. For a persistent, 24/7 deployment instead of a foreground run, follow the
systemd user-unit runbook:
@@ -90,12 +85,14 @@ an install (or an upgrade across v1.30.0) needs its unit as well -- see
### Native self-update
`archie-update-install` downloads the approved release's Linux/amd64 archive
and verifies its `SHA256SUMS` entry before executing or installing it. Releases
must include `release.json`, all host binaries, and the two updater scripts.
Older releases without this contract cannot be installed through the artifact
path. `--from-source` (or `ARCHIE_UPDATE_SOURCE_BUILD=1`) explicitly clones and
builds the selected release instead.
Install on Settings → Status runs `archied update install -version X`, which
downloads the release's Linux/amd64 zip and verifies it against `SHA256SUMS`
before unpacking it. Every host binary in the zip must report `X`. It then pulls
the agent image `release.json` pins by digest, backs up the database to
`db.pre-update.dump` in the state directory, stages the new binaries beside the
live ones and hands the transaction to `archied update watchdog` in a process of
its own (a transient systemd user unit). Nothing that runs changes until the
watchdog takes over.
`archied update check` finds the newest GitHub release with a linux-amd64 zip on
the channel chosen under Settings → Status → Updates: stable, next (includes
@@ -103,30 +100,32 @@ prereleases) or a pinned version. From a shell it reads
`ARCHIE_UPDATE_RELEASE_CHANNEL` and `ARCHIE_UPDATE_PIN`, or `-channel` and `-pin`.
The notification destination remains separate from the release channel.
For scheduled, unattended runs, `archie-update-install --auto` discovers the
selected release and refuses if the daemon reports work in flight. It checks
again immediately before promotion. A scheduler can set
`ARCHIE_UPDATE_RELEASE_CHANNEL` and `ARCHIE_UPDATE_PIN`; nothing schedules updates
by default. All services stop through their ordinary graceful shutdown path.
`release.json` supplies the service order and required config sections to both
first-install and self-update. A missing unit or config section produces an
ordered migration plan and refuses installation. Apply that plan before retrying.
Automatic topology edits are intentionally unsupported.
The watchdog switches staged executables by rename, restarts services, and
requires the candidate daemon's existing readiness registry to remain healthy
for 120 seconds. Agent images come from the release manifest by digest. The
image switch updates the control-plane policy, preserving other settings;
rollback restores the prior image policy with conflict detection. Source builds
use the built image's immutable image ID.
The watchdog stops the units in reverse `release.json` order, switches the
staged executables by rename, switches the control-plane image policy (only the
image field, with conflict detection), and restarts the units in order through
`systemctl --user`. archied must report the new version and stay healthy for
120 seconds. Otherwise the watchdog restores the previous binaries and image
policy. Data is not rolled back unless the new release migrated the database:
then the previous binaries cannot serve it, so the pre-update backup is restored
and the outcome report says that every write since the update began is gone.
Without a systemd user manager the watchdog switches binaries and image policy
but restarts nothing, and the install reports that the services need a manual
restart.
Transactions live in `${XDG_STATE_HOME:-~/.local/state}/archie/update`, outside
the binary directory. `phase`, `environment`, `image.json` (when applicable),
and `previous/` describe the transaction. A lock reports the owning process.
On daemon boot, an interrupted transaction schedules independent recovery before
normal startup. To recover manually, run `transaction/watchdog --recover` from
that state directory. A failed recovery keeps the journal for another attempt.
the binary directory: `transaction/journal.json`, `transaction/previous/`, and
`transaction/archied`, the frozen copy of the archied that wrote the journal. On
daemon boot, an interrupted transaction is
handed to that frozen watchdog with `-recover` before normal startup: a
transaction that never started is discarded, one that was switching or observing
is rolled back, and a decided one is finished. To recover manually, run
`transaction/archied update watchdog -recover -bin-dir ~/.local/bin` from that
state directory. A failed recovery keeps the journal for another attempt.
Database snapshots remain available for manual recovery. Schema migrations and
PostgreSQL data are never automatically reversed.
The database backup stays in the state directory after a committed update for
manual recovery with `archie-state-store restore`.
+10 -13
View File
@@ -52,10 +52,10 @@ PostgreSQL database `database_url` names and serves the `StateStore` gRPC
contract. BOTH `archied` and `archie-gateway` dial it via
`[services.state].target` and never open the task tables themselves. The templates set
`[services.state]` accordingly: a host-only agent reaches a loopback bind
(`127.0.0.1:9090`) with no token, while a container-mode agent needs the
Docker bridge gateway address plus a matching bearer token (`target_token` /
`--token` / `STATE_STORE_TOKEN`), because a container cannot reach the host's
loopback.
(`127.0.0.1:9090`), while a container-mode agent needs the Docker bridge
gateway address, because a container cannot reach the host's loopback. A
non-loopback address needs `[tls]` certificates from your own CA; see
`config.example.toml`.
## Running the dashboard
@@ -69,8 +69,8 @@ default). Start it after the Gateway and the State Store:
archie-ui -config ~/.config/archie/config.toml
```
A non-loopback `[web].listen` requires a dashboard token (`-token`, or
`-token-file` to mint and persist one); a loopback bind needs none.
Open the dashboard to configure the organisation, workspace and first administrator account.
Use HTTPS through a reverse proxy for remote access, and complete setup before exposing it publicly.
`archied` runs no dashboard listener at all, so webhook capture
(`POST /webhooks/capture/{source}`) is received by archie-ui and the
binding-dispatch loop in `archied` consumes what arrives from the shared
@@ -84,17 +84,14 @@ archie-ui warns about exactly that at startup. Terminate TLS in front of it
warning; leaving it off while exposing the port directly is the case the
warning names.
Auth note: unlike `archied`, archie-ui has no secret registry --
`GATEWAY_TOKEN`/`STATE_STORE_TOKEN` resolve from its process environment
only (or from `[services.*].target_token` in `config.toml`), so whatever
starts archie-ui must export those tokens into its environment. See the UI
Service unit in `systemd-user-service.md` for the worked example.
Auth note: archie-ui authenticates to its dependencies with its `[tls]`
certificate (`archie-ui.pem`).
```bash
# loopback (host-only agent)
archie-state-store -config ~/.config/archie/config.toml -listen 127.0.0.1:9090
# or container-mode: bind the bridge gateway with a token
archie-state-store -config ~/.config/archie/config.toml -listen 172.17.0.1:9090 -token <token>
# or container-mode: bind the bridge gateway ([tls] required)
archie-state-store -config ~/.config/archie/config.toml -listen 172.17.0.1:9090
```
## Verifying the daemon
+7 -5
View File
@@ -26,13 +26,15 @@ target = "127.0.0.1:8585"
# The State Store gRPC service owns the PostgreSQL task data; archied and
# archie-gateway dial it and never open those tables themselves.
# This deployment runs the agent in containers, so target is the Docker bridge
# gateway (172.17.0.1) the container can reach, with a matching target_token
# that archie-state-store validates. Host-only agent: use 127.0.0.1:9090 with
# no token.
# This deployment runs the agent in containers, so the target is the Docker
# bridge gateway (172.17.0.1) the container can reach. A non-loopback address
# needs [tls]; see config.example.toml.
[services.state]
target = "172.17.0.1:9090"
target_token = "change-me-state-store-token"
[tls]
ca_file = "/etc/archie/tls/ca.pem"
cert_dir = "/etc/archie/tls"
[forge]
type = "gitea"
+3 -5
View File
@@ -18,13 +18,11 @@ target = "127.0.0.1:8585"
# The State Store gRPC service owns the PostgreSQL task data; archied and
# archie-gateway dial it and never open those tables themselves.
# This deployment runs the agent in containers, so target is the Docker bridge
# gateway (172.17.0.1) the container can reach, with a matching target_token
# that archie-state-store validates. Host-only agent: use 127.0.0.1:9090 with
# no token.
# This deployment runs the agent in containers, so the target is the Docker
# bridge gateway (172.17.0.1) the container can reach. A non-loopback address
# needs [tls]; see config.example.toml.
[services.state]
target = "172.17.0.1:9090"
target_token = "change-me-state-store-token"
[models]
triage = "openai/gpt-6-luna"
+3 -8
View File
@@ -25,16 +25,11 @@ target = "127.0.0.1:8585"
# The State Store gRPC service owns the PostgreSQL task data. archied and
# archie-gateway dial it here and never open those tables themselves.
# This deployment runs the
# agent in containers, so the target must be the Docker bridge gateway address
# (172.17.0.1) that the container can reach, and a non-loopback target requires
# a matching target_token that archie-state-store validates -- start it with the
# same token (e.g. `archie-state-store ... -listen 172.17.0.1:9090 -token
# change-me-state-store-token`). For a host-only agent (no [containers]) use the
# loopback target 127.0.0.1:9090 with no token.
# This deployment runs the agent in containers, so the target is the Docker
# bridge gateway (172.17.0.1) the container can reach. A non-loopback address
# needs [tls]; see config.example.toml.
[services.state]
target = "172.17.0.1:9090"
target_token = "change-me-state-store-token"
[forge]
type = "github"
+13 -36
View File
@@ -20,10 +20,9 @@ The State Store unit is `archie-state-store.service`. It owns the task data in
PostgreSQL and serves the `StateStore` gRPC contract. BOTH `archied` and
`archie-gateway` dial it via `[services.state].target` (see the `archied`
config below) and never open the task tables themselves. A
host-only agent uses the loopback bind with no token below; a container-mode
agent needs the Docker bridge gateway address plus a bearer token via
`--token`/`STATE_STORE_TOKEN` or `[services.state].target_token`, and a
non-loopback bind fails closed without one:
host-only agent uses the loopback bind below; a container-mode agent needs the
Docker bridge gateway address, and a non-loopback bind needs `[tls]` (see
`config.example.toml`):
`install.sh` writes `archie-state-store.service` with that loopback bind.
@@ -36,14 +35,12 @@ by `archied`, since the v1.30.0 extraction. `archied` starts no gateway for them
and logs nothing when one is absent, so a host that updates across v1.30.0
without this unit runs on with dead channels and a daemon that looks perfectly
healthy. `install.sh` writes this unit on a fresh install;
`scripts/archie-update-install` refuses an
`archied update install` refuses an
update when a host is missing a unit and names what is missing, which now fires
for a host that drifted or predates this release rather than the normal path.
It dials the Gateway for the chat contract and the State Store for the stored
channel settings, and reads the same `config.toml`. Like `archie-ui` it resolves
`GATEWAY_TOKEN` and `STATE_STORE_TOKEN` from its process environment, hence the
`EnvironmentFile`:
channel settings, and reads the same `config.toml`, including `[tls]`.
`install.sh` writes `archie-messaging.service`. Its `After=` and `Wants=`
lines only tidy the start sequence: nothing depends on that order, because
@@ -53,46 +50,26 @@ each service waits for the peers it needs.
The dashboard is served by the standalone UI Service, not by `archied`. It reads the same `config.toml`, dials
the Gateway and State Store targets already in it, and binds `[web].listen`.
A non-loopback bind requires a dashboard token (`-token`, or `-token-file` to
mint and persist one);
Open the dashboard to configure the organisation, workspace and first administrator account.
Complete setup before exposing it publicly; remote access requires an HTTPS reverse proxy.
**Auth note:** unlike `archied`,
`archie-ui` has no secret registry — it resolves `GATEWAY_TOKEN` and
`STATE_STORE_TOKEN` from its **process environment only** (or from the
`target_token` values in `config.toml`). Whatever starts `archie-ui` is
therefore responsible for exporting those tokens into its environment: keep
them in `~/.config/archie/env` (loaded by the `EnvironmentFile` line below),
not only in a secret manager. A deployment that authenticates `archied`
through bws/Vault but exports nothing for `archie-ui` leaves the dashboard
unable to dial its dependencies.
**Auth note:** `archie-ui` authenticates to the Gateway, State Store and
harness with its `[tls]` certificate (`archie-ui.pem`) from `config.toml`.
For supervision, `GET /healthz` on `[web].listen` is the process's liveness
probe (token-free by design); the authenticated readiness surface lives at
the dashboard's health endpoint behind the token. A watchdog can curl
the dashboard's health endpoint behind account authentication. A watchdog can curl
`/healthz` without credentials.
`install.sh` writes `archie-ui.service`. It has no secret registry of its own,
so its token handling is the `EnvironmentFile` note above.
Concretely, for a deployment whose dependency tokens live outside
`config.toml`, `~/.config/archie/env` carries the two names and the unit
loads it; the dashboard token itself comes from `-token-file` (there is no
environment variable for it):
```bash
# ~/.config/archie/env
GATEWAY_TOKEN=... # presented to archie-gateway
STATE_STORE_TOKEN=... # presented to archie-state-store
```
`install.sh` writes `archie-ui.service`. Browser accounts are configured through the dashboard.
`After=` orders the start, it does not wait for the store to bind. The UI
process closes that gap itself: its event pump retries priming with backoff
until the State Store answers, so the activity feed goes live once the store
is up rather than staying history-only until the next restart.
For a non-loopback bind, override the installed unit's `ExecStart` with
`-token-file %h/.local/share/archie/web-token` (or `-token`) in a drop-in rather
than editing the installer's copy in place.
For remote access, configure a TLS reverse proxy and the instance public URL in
Access → Authentication. Enrol passkeys from Your account on HTTPS or localhost.
---
+10 -2
View File
@@ -44,10 +44,18 @@ services:
# ── NATS JetStream ────────────────────────────────────────────────
nats:
image: nats:2.14-alpine3.22
command: -js -m 8222
# The client port is published on every interface (agent containers reach
# it over the bridge), so it refuses to start without a token. Set
# NATS_TOKEN here and name the same value in [nats] token_env.
entrypoint:
- sh
- -c
- '[ -n "$$NATS_TOKEN" ] || { echo "NATS_TOKEN is required" >&2; exit 1; }; exec nats-server -js -m 8222 --auth "$$NATS_TOKEN"'
environment:
NATS_TOKEN: ${NATS_TOKEN:-}
ports:
- "4222:4222" # client
- "8222:8222" # monitoring (http://localhost:8222)
- "127.0.0.1:8222:8222" # monitoring (http://localhost:8222)
volumes:
- nats_data:/data
restart: unless-stopped
+8
View File
@@ -79,6 +79,10 @@
"/news/archie/1.51.1/": "/news/1.51.1/",
"/news/archie/1.52.0/": "/news/1.52.0/",
"/news/archie/1.53.0/": "/news/1.53.0/",
"/news/archie/1.54.0/": "/news/1.54.0/",
"/news/archie/1.54.1/": "/news/1.54.1/",
"/news/archie/1.54.2/": "/news/1.54.2/",
"/news/archie/1.54.3/": "/news/1.54.3/",
"/news/archie/1.6.0/": "/news/1.6.0/",
"/news/archie/1.7.0/": "/news/1.7.0/",
"/news/archie/1.8.0/": "/news/1.8.0/",
@@ -174,6 +178,10 @@
"/news/archied/1.51.1/": "/news/1.51.1/",
"/news/archied/1.52.0/": "/news/1.52.0/",
"/news/archied/1.53.0/": "/news/1.53.0/",
"/news/archied/1.54.0/": "/news/1.54.0/",
"/news/archied/1.54.1/": "/news/1.54.1/",
"/news/archied/1.54.2/": "/news/1.54.2/",
"/news/archied/1.54.3/": "/news/1.54.3/",
"/news/archied/1.6.0/": "/news/1.6.0/",
"/news/archied/1.7.0/": "/news/1.7.0/",
"/news/archied/1.8.0/": "/news/1.8.0/",
+20
View File
@@ -1,4 +1,24 @@
[
{
"version": "1.54.3",
"date": "2026-10-16",
"body": "### archied\n\n- Chat can help write a workflow: it reads your workflows and the step catalog, writes a definition, and checks it the same way saving does, fixing what the check reports. It does not save; paste the YAML it gives you into the editor's YAML view and save there."
},
{
"version": "1.54.2",
"date": "2026-10-16",
"body": "### archied\n\n- Tool calls from Gemini models (Interactions API) receive their arguments intact. Any tool that takes arguments, such as `dashboard_navigate` in chat, failed with \"invalid character '{' after top-level value\".\n\n### archie-agent\n\n- Agent steps on Gemini models (Interactions API) pass tools their arguments intact instead of failing to decode them."
},
{
"version": "1.54.1",
"date": "2026-10-16",
"body": "### archied\n\n- Update checks, `archied update install` and `install.sh` find releases at `github.com/samcharles93/archie-releases`, so a host can update again. A host on 1.54.0 or earlier still looks in the old place and has to be upgraded to 1.54.1 by hand once."
},
{
"version": "1.54.0",
"date": "2026-10-16",
"body": "**Upgrade note:** services now authenticate each other with TLS certificates from your own CA instead of shared tokens. Before upgrading a host whose services listen on anything but loopback (any host running agent containers), issue a certificate per service (`archied`, `archie-gateway`, `archie-messaging`, `archie-state-store`, `archie-ui`, each with its name as the DNS SAN and both server and client auth), add `[tls] ca_file` and `cert_dir` to `config.toml`, and remove every `target_token`, the `*_TOKEN` service variables and the `--token`/`--*-token` flags, including archie-ui's `-token` and `-token-file`. A unit that still passes a removed flag fails to start. See `config.example.toml`.\n\n### archied\n\n- Services authenticate each other with mutual TLS. Each process presents `<cert_dir>/<service>.pem`, peers must chain to `ca_file`, and a caller is identified by its certificate rather than by what it claims. Renewed certificates are picked up without a restart. Without `[tls]`, services listen on and dial loopback only. The harness setup terminal requires `[tls]`.\n- Every gRPC service caps the streams a connection holds, times out stalled handshakes, releases a dead client's streams, and drains for at most 10 seconds on shutdown. Messaging exits when its listener fails instead of staying up without delivering.\n- The dashboard has user accounts. First run opens browser setup for the organisation, workspace and first administrator; people then sign in with a password, a passkey or your identity provider, and account administration lives under Access. The shared dashboard token is gone; reach the dashboard remotely through an HTTPS reverse proxy.\n- `archied update install` updates a host in one transaction: it verifies the release, stages every binary, pulls the agent image by digest and backs up the database, then restarts the services in order and rolls everything back if archied is not healthy for two minutes.\n- Each workflow runs as the identity it declares, checked on every attempt along with the identity that started it. A workflow that declares none is refused, a called workflow runs as its caller's declared identity, and shipped workflows run as the instance root.\n- Test-run a workflow draft before saving it, with forge and push writes suppressed and recorded per step. The History tab lists a workflow's revisions, diffs them as YAML and on the canvas, restores one into the editor, and shows which revision each run used.\n- Start a task from the dashboard. The dashboard home shows activity and setup, and a running task has a read-only Sandbox tab that follows its container.\n- The topbar's Jump to is a command palette, settings lists open as accordions that wait for a new item to be saved, and history restores land as a draft applied from the save bar.\n- Labels, hints, alerts and empty states say what is wrong and what to do, without tutorial or marketing prose.\n- Org isolation is tighter: harness secrets, identity writes, principals, playbook dispatch and model selections in chat stay in the caller's org, instance settings are written by the system org only, and creating a source or reloading a channel is authorized against the target.\n- Binding dispatch claims its capture and enqueues the task atomically, so a capture cannot start two runs, and the run-time workflow check sees the binding event's signature and address.\n- Service-unhealthy alerts count their grace from the last report and also cover a service that went silent, and a restart no longer clears an alert still inside its grace. An invalid stored access policy raises an alert until it validates.\n- A failed cancel of a called workflow no longer leaves the caller running, retention spares captures still waiting to be dispatched, and EDA playbooks load and report at start instead of on first dispatch.\n- Chat model selection works again for provider models.\n\n### archie-agent\n\n- Each run acts as its workflow's declared identity.\n- A task snapshot carries only the model limits its aliases resolve to.\n- A build step's \"no changes\" result comes from its writable stages and clears once a commit lands.\n- Test runs suppress forge and push writes and record what they would have done.\n- The default persona is a reporting-focused identity prompt, without the one-question limit in chat."
},
{
"version": "1.53.0",
"date": "2026-10-11",
+44 -4
View File
@@ -193,11 +193,51 @@ established egress phase differ.
client's refused connection is gRPC's `Unavailable`. The dashboard's
existing failure surface is the honest degrade; `/api/harness`'s `terminal`
field means "a client is configured", not "the daemon can run a Kit".
- **Run target.** Deferred (`archie-core-qi91`). `Open` answers `Unimplemented`
for it in the setup slice. A finished or absent attempt will be `NotFound`,
not `Unavailable`.
- **Run target.** `RunTarget{task_id, attempt}` opens a read-only view of a
running task's sandbox; it ships as the peek. The daemon resolves the pair
itself, so the dashboard never learns a container name: the task store says
whether the task is `running` and which attempt is current, and the Kit
launcher names the container `kitrun.TaskContainer(task_id, attempt)` (one
container per attempt, removed when the run ends; volumes remain task-scoped
for retries). A finished or unknown task, a task that is not running, an
attempt other than the running one, or a container that is gone is
`NotFound` with the reason in the message; an unreachable task store or
container engine is `Unavailable`. The view follows the container's stdout
and stderr, including the harness output forwarded by the worker, carries
no stdin and no exec, and
ends when the task's container ends or the client leaves, so it confers no
authority over the container. A read-only tail of the existing per-attempt
logs was rejected: those refresh only on task state changes and are the
daemon's account, not the sandbox's.
Mid-stream failures are shown as a reason in the terminal before it closes.
- **Authorisation.** The dashboard route `GET /api/tasks/{id}/sandbox` is
decided as `read-logs` on the task before the handler runs, so a caller
sees a sandbox exactly when they may read that task's log. The daemon
checks that the task belongs to the asserted org before following output.
- **Grants.** The view takes no grant of its own. The run's egress session
(its proxy token, install then `EnterRuntime`) already belongs to the run
and is revoked by `Launcher.Release` when the task ends; the view reads
after that phase switch and dies with the container.
- **Credentials.** The sandbox holds sentinels, never real credentials:
API keys are `egress.Sentinel` (`credentials.go`), and an OAuth token set
is sentinelised in the response and swapped back by the proxy only on a
granted service's resource host in the matching phase (`oauth.go`,
`injectOAuth`). The proxy runs in the daemon outside the container, so a
shell in the container sees only sentinels.
- **Takeover (interactive PTY into a running task) is out of scope for this
bead.** It needs the dangerous-command authority (`archie-core-sod1`) to
gate it, and that authority is not wired for it: the harness listener has
no approval step; `ToolSetOptions.Approval` in `internal/agentexec/modelloop`
is never set by a caller, so task runs never build approval-required tools;
approvals reach a human only on the chat paths (dashboard ask, Telegram,
Gateway). Takeover would also need an audit record naming the actor, task,
attempt and open/close times, and revocation tied to task end (the exec is
closed with the container). Those follow the setup session's shape
(`harnesssession.Session`, `container.ExecPTY`) once the authority exists.
- **Audit.** Opening and closing a session and a successful capture are
recorded with the asserted org and profile.
recorded with the asserted org and profile. A run view's open and close are
logged with the task and attempt; it reads output only, so it has no
takeover record.
Each session is the only interactive path into a harness container.
+239
View File
@@ -0,0 +1,239 @@
# User authorization boundaries
Archie separates authentication (which person or service is calling) from
permission to act on a resource. This inventory follows the [OWASP
Authentication Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html)
and [Authorization Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Authorization_Cheat_Sheet.html),
including its guidance on attributes and relationships. It describes concrete
enforcement points and their regression tests; it is not a compliance certification.
## Transport and authority
The browser uses HTTP/JSON and SSE to the UI service. The UI service calls
State Store, Gateway, Messaging and Harness through their gRPC contracts.
Only the State Store opens the task/control-plane/account database; Gateway
owns conversation storage. Browser HTTP handlers never open either database.
Instance service credentials are administrative authority. They are not user
sessions and must never reach a browser, model, or agent container. A service
forwarding a principal preserves attribution and tenant scope; forwarding alone
does not mean every internal RPC evaluates Cedar. Most internal RPCs trust the
authenticated service and enforce their own resource scope. The public HTTP
boundary evaluates Cedar before invoking them. Task credentials have a separate,
explicit RPC allowlist and cannot call account or identity administration.
Local service listeners are trusted process boundaries. Loopback is not a
substitute for authentication on a remotely reachable listener. OIDC credentials,
local browser sessions, personal API tokens, service credentials, and task grants
must remain distinct.
## Policy and relationship model
`internal/domain/access` defines actions, resources, principals and memberships.
`internal/infrastructure/access` assembles Cedar entities and evaluates the
instance → organization → workspace → object chain. A forbid wins; each applicable
level must permit the operation. Missing or invalid policy chains fail closed.
The default policies grant actions through scoped roles. Policies can also
restrict a named identity, workspace environment, owner, state, source address,
signature, run or step. HTTP task decisions now include the stored initiating identity and task state; binding decisions include the stored binding state. The HTTP source address is the actual connection peer, not an unverified forwarded header. Membership and resource attributes must come from stored
records or authenticated context, never a request's assertion about itself.
Cedar permission is not ownership of another person's private data. Conversation
history, passkeys, recovery codes and personal tokens are bound to the person.
An organization or instance admin role does not override those relationships.
Account creation uses `manage_members` policy rather than a hard-coded admin
role. Authenticating through OIDC does not automatically grant membership, link
accounts by unverified email, or create an administrator.
## Enforcement inventory
| Location | Enforcement | Regression evidence |
| --- | --- | --- |
| Browser credential gate: `webui/auth.go`, `accounts.go` | Account session or verified provider identity; shared dashboard token is not a person when accounts are enabled. No API data before authentication. | `TestAccountBoundary`, `TestAccountSessionFailureIsClosed` |
| Browser policy gate: `webui/authorize.go` | Resolve principal from stored identity; evaluate action against stored org/workspace and resource kind before handler. Missing chain refuses. | `TestHTTPPolicyCannotBeBypassed`, `TestAuthorizeRefusesWithoutAChain`, `TestAuthorizeRecord`, `TestTaskAuthorizationUsesStoredAttributes`, `TestAuthorizeCreateIn` |
| Instance-only HTTP surfaces: `webui/instance_only.go`, server route registration | Hide instance-owned configuration and diagnostics from another org; policy still applies first. | `TestInstanceOnlyHidesTheInstanceFromOtherOrgs`, `TestInstanceAdminOrgs` |
| First setup: `webui/accounts.go`, `postgres/accounts.go` | Initial organization, workspace, instance URL, admin identity and password commit together. Transaction lock closes bootstrap after first account; later requests require `manage_members`. | Disposable PostgreSQL smoke verification for bootstrap race and rollback; account policy tests below |
| Account creation: `webui/accounts.go`, `staterpc/accounts.go`, `postgres/accounts.go` | Cedar `manage_members` at HTTP and RPC; target org is authenticated context. New local accounts cannot request owner role. | `TestAccountManagementUsesPolicy`, `TestAccountBoundary` |
| Local passwords and sessions: `identity/password.go`, `postgres/accounts.go` | Argon2id, independent salts, length/common-password checks, generic login refusal, account throttling, session hashes and expiry, revocation on logout/password change/suspension. | `TestPasswordVerification`, `TestAccountBoundary`; disposable PostgreSQL session verification |
| Transport and CSRF: `webui/accounts.go`, `api_tasks.go` | Password/account mutations require HTTPS or localhost development, JSON, custom CSRF header and same-origin requests. Forwarded headers require explicit trusted-proxy configuration. | `TestAuthenticationTransport`, existing mutation security tests |
| Personal account routes: `webui/accounts.go` | Active signed-in person; principal supplied by server. Password change verifies current password. Sensitive authenticator changes require recent sign-in. No caller-supplied target identity. | `TestAccountBoundary` |
| Recovery: `postgres/account_security.go`, `webui/accounts.go` | Fresh authenticated owner generates a hashed, one-use recovery secret. Redemption replaces password and revokes all sessions atomically. No email-existence disclosure. | Disposable PostgreSQL recovery verification |
| Passkeys: `postgres/passkeys.go`, `webui/passkeys.go` | Configured RP origin, browser-bound one-use expiring challenge, verified credential signature and user verification. Enrollment/management belong to caller. Credential counters persist under a row lock. | Disposable browser virtual-authenticator verification; task-grant denial tests |
| OIDC: `infrastructure/oidc`, `archieui/account_oidc.go`, `webui/auth.go` | Discovery and signed ID token with issuer/client audience/expiry, PKCE, state and nonce. Verified subject resolves to active identity. Browser-local session cannot outlive provider token, and provider credential remains checked. | `TestBrowserFlowVerifiesIDToken`, `TestProviderOutageIsUnavailableThenRecovers`, subject-claim tests; no external provider acceptance implied |
| OIDC settings: `webui/accounts.go`, `postgres/authentication.go` | Instance ownership plus policy; recent sign-in for changes. Public URL cannot change while enrolled passkeys would be orphaned. | `TestAccountBoundary`, `TestAuthenticationSettingsRejectUntrustedOrigins` |
| Org membership/workspaces/agent assignment: `webui/api_orgs.go`, `staterpc/orgs.go`, `postgres/orgs.go` | Own org or instance-owner relationship, allowed role vocabulary, membership escalation/last-owner guards, tenant-scoped SQL. | `TestOrgRPCsActInTheCallersOrg`, `TestSetMembershipRefusesUnknownRole`, org HTTP tests |
| Personal API tokens: `webui/api_personal_tokens.go`, `staterpc/personal_tokens.go`, `postgres/personal_tokens.go` | Token owner comes from principal; store only token hash; revoke only caller's binding. | `TestPersonalTokensWithoutPerson`, `TestPersonalTokenOwner` |
| gRPC caller attribution: `rpcidentity/identity.go` | Authenticated service may forward a principal; State Store resolves memberships/org itself. Task grant metadata is stripped. | `TestCallerAttribution` |
| Agent/task gRPC: `staterpc/task_grants.go` | Durable task-scoped grant, explicit allowed RPC and target task, no definition-pin replacement, no account RPCs. | `TestTaskCredentialsCannotManageAccounts`, `TestTaskCredentialCannotReplaceItsPin`, `TestRecordUsageAuthority`, `TestWorkerPresenceAuthority` |
| Chat HTTP: `webui/api_chat.go` | Server stamps sender and person thread; lists/read/turns/cancel/persona verify session ownership. Browser cannot submit another sender identity. | `TestWebChatOwnership`, `TestWebChatSenderCannotBeSuppliedByBrowser`; HTTP deny matrix |
| Chat history, slash commands and model session tools: `gateway/session_store_postgres.go` | Store filters `Get`, `List`, `GetByChannel`; shared read/write guards check person ownership as well as org. A saved session cannot change its conversation source to claim another person's history. Service curation runs without a person principal. | `TestSessionVisibility`; PostgreSQL smoke for history isolation |
| Chat questions/approvals: `webui/api_chat_ask.go` | Waiting question is bound to the initiating person, in addition to its unguessable ID. | `TestChatQuestionBelongsToInitiatingPerson` |
| Chat downloads: `webui/api_chat_files.go` | Offered file token expires and is bound to the initiating person; requests cannot supply a filesystem path. | `TestChatFileDownload` |
| Per-person memory: `archiegateway/chat_identity.go`, gateway memory tools, `sessioncurator` | Verified web sender identity scopes reads/writes. Curator refuses unidentified or mixed participants instead of guessing a person. | Gateway memory and session-curator tests |
| Workflow/task actions: `webui/api_tasks.go`, `domain/taskactions`, `staterpc` | Policy and stored workspace before action; domain transition, authority and durable dispatch guards remain in force. | HTTP deny matrix, task action/domain tests, task grant tests |
| Incoming webhooks: `forge/webhook`, `captureintake`, access delivery engine | Verify HMAC before parsing; derive source/org from stored source; evaluate source delivery policies and egress rules. No browser-user credential is inferred. | Webhook/capture tests, `TestAuthorizeDelivery` |
| Control-plane configuration, secrets, harness and extensions | Browser policy and instance-only restrictions where registered; service contracts carry principal/org; task grants cannot invoke administrative RPCs. | HTTP deny matrix, `TestAdministrationRoutes`, `TestChannelReloadRoute`, `TestConfineHarnessOrg` |
| Live HTTP/SSE and diagnostics | Authenticated policy gate applies before stream creation; org-scoped event reads; instance logs require administrative visibility. | HTTP deny matrix, instance-only tests, `TestServiceLogsRequireInstanceCredential` |
| Background schedules, dispatch, curation | Service/agent authority, not an implicit browser user. Task-scoped grants and org scopes remain distinct from initiating human attribution. | Existing dispatch, grant, memory and org-scope tests |
The policy HTTP matrix enumerates each registered protected route. It checks
both anonymous refusal and refusal by an explicit Cedar forbid, using the real
handler stack. Separate tests exercise allowed requests and personal ownership;
a denied-request matrix alone is not proof that a workflow works end to end.
## Public and personal routes
Public protocol entry points are `GET /api/auth/status`, `POST /api/auth/setup`,
`POST /api/auth/login`, `POST /api/auth/logout`, `POST /api/auth/recover`,
`POST /api/auth/passkey/begin`, `POST /api/auth/passkey/finish`,
`GET /oauth2/login`, `GET /oauth2/callback`, health probes and signed webhook
intake. Each has its own protocol checks. Static embedded app assets are public;
they do not contain user data. `/health/detailed` remains protected.
Personal routes under `/api/account/` require an active signed-in person and
server-derived ownership: password change, recovery-secret generation, passkey
begin/finish/list/delete. They do not require an organization administrator role.
`POST /api/accounts` and `/api/authentication` are administrative policy routes.
## HTTP route inventory
The following routes are covered by `TestHTTPPolicyCannotBeBypassed` in
`internal/webui/authorization_surfaces_test.go`. `authorize.go` maps each to its
action/resource; the handler may impose a stricter record or instance boundary.
| Method | Route example |
| --- | --- |
| DELETE | `/api/access/policies` |
| DELETE | `/api/bindings/7` |
| DELETE | `/api/event-types/7` |
| DELETE | `/api/extensions/sample` |
| DELETE | `/api/mappings/7` |
| DELETE | `/api/orgs/7/members/sample` |
| DELETE | `/api/sources/sample` |
| DELETE | `/api/tokens/7` |
| GET | `/api/access/policies` |
| GET | `/api/alerts` |
| GET | `/api/authentication` |
| GET | `/api/bindings` |
| GET | `/api/bindings/7` |
| GET | `/api/bindings/7/dispatches` |
| GET | `/api/capabilities` |
| GET | `/api/captures` |
| GET | `/api/captures/7/dispatches` |
| GET | `/api/channels` |
| GET | `/api/chat/file/sample` |
| GET | `/api/chat/sessions` |
| GET | `/api/chat/sessions/7/messages` |
| GET | `/api/chat/sessions/7/turns` |
| GET | `/api/chat/update` |
| GET | `/api/config` |
| GET | `/api/control-plane/apply-status` |
| GET | `/api/control-plane/audit` |
| GET | `/api/control-plane/catalog` |
| GET | `/api/control-plane/resources/sample` |
| GET | `/api/control-plane/resources/sample/history` |
| GET | `/api/curators` |
| GET | `/api/event-types` |
| GET | `/api/extensions` |
| GET | `/api/extensions/catalogue` |
| GET | `/api/harness/bindings` |
| GET | `/api/harness/terminal` |
| GET | `/api/identities` |
| GET | `/api/logs` |
| GET | `/api/mappings` |
| GET | `/api/mappings/7` |
| GET | `/api/orgs` |
| GET | `/api/orgs/7` |
| GET | `/api/orgs/7/members` |
| GET | `/api/orgs/7/workspaces` |
| GET | `/api/secret-engines` |
| GET | `/api/services` |
| GET | `/api/setup` |
| GET | `/api/skills` |
| GET | `/api/sources` |
| GET | `/api/stream` |
| GET | `/api/summary` |
| GET | `/api/task-meta` |
| GET | `/api/tasks` |
| GET | `/api/tasks/7` |
| GET | `/api/tasks/7/attempts` |
| GET | `/api/tasks/7/changes` |
| GET | `/api/tasks/7/debug` |
| GET | `/api/tasks/7/dispatches` |
| GET | `/api/tasks/7/logs` |
| GET | `/api/tasks/7/logs/download` |
| GET | `/api/tasks/7/sandbox` |
| GET | `/api/tokens` |
| GET | `/api/version` |
| GET | `/api/workflows` |
| PATCH | `/api/bindings/7` |
| PATCH | `/api/mappings/7` |
| POST | `/api/accounts` |
| POST | `/api/alerts/7/dismiss` |
| POST | `/api/bindings` |
| POST | `/api/bindings/7/approve` |
| POST | `/api/bindings/7/pause` |
| POST | `/api/bindings/7/resume` |
| POST | `/api/channels/7/reload` |
| POST | `/api/chat/answer` |
| POST | `/api/chat/cancel` |
| POST | `/api/chat/message` |
| POST | `/api/chat/persona` |
| POST | `/api/chat/stream` |
| POST | `/api/chat/update/defer` |
| POST | `/api/chat/update/install` |
| POST | `/api/control-plane/resources/sample/commands/sample` |
| POST | `/api/event-types` |
| POST | `/api/extensions` |
| POST | `/api/extensions/catalogue/sample/install` |
| POST | `/api/extensions/sample/accept` |
| POST | `/api/extensions/sample/approve-update` |
| POST | `/api/extensions/sample/rollback` |
| POST | `/api/extensions/sample/update` |
| POST | `/api/identities` |
| POST | `/api/identities/7/sample` |
| POST | `/api/mappings` |
| POST | `/api/mappings/preview` |
| POST | `/api/orgs` |
| POST | `/api/orgs/7/members` |
| POST | `/api/orgs/7/workspaces` |
| POST | `/api/secret-references/check` |
| POST | `/api/sources` |
| POST | `/api/sources/sample/approve-unsigned` |
| POST | `/api/sources/sample/secret` |
| POST | `/api/sources/sample/signing` |
| POST | `/api/tasks/7/action` |
| POST | `/api/tokens` |
| POST | `/api/work-requests` |
| PUT | `/api/access/policies` |
| PUT | `/api/authentication` |
| PUT | `/api/event-types/7` |
| PUT | `/api/extensions/sample/enabled` |
| PUT | `/api/extensions/sample/update-policy` |
| PUT | `/api/orgs/7/agents/sample` |
| PUT | `/api/orgs/7/members/sample` |
| PUT | `/api/sources/sample/delivery-header` |
| PUT | `/api/sources/sample/name` |
| PUT | `/api/workflows/7/enabled` |
## Verification limits
A synthetic browser authenticator verifies protocol behavior, not a physical
security key or every operating system. An OIDC unit test is not acceptance
against a deployed provider. Disposable PostgreSQL smoke checks verify real SQL
without putting database-dependent tests in the fast unit suite.
Existing anonymous conversations are retained but are not silently assigned to
a new person. Existing service credentials remain privileged; this inventory
does not claim that all internal gRPC methods have independent Cedar gates.
When changing a user-facing operation, update its inventory entry and its
allow/deny behavior cases. Include another user in the same organization, a
caller in another organization, a missing principal, unavailable policy storage,
and the applicable owner/workspace/instance restrictions.
Bootstrap is unauthenticated until the first administrator is created. Complete
setup before exposing a new installation to untrusted users. Last-active-owner
protection for identity suspension/retirement is tracked separately as
`archie-core-d7avc`; membership-policy guards are not that lifecycle guard.
+2
View File
@@ -0,0 +1,2 @@
node_modules/
out/
+61
View File
@@ -0,0 +1,61 @@
# e2e
Validation of the whole stack, run by hand or by an agent, never by
`task check` or CI. It needs PostgreSQL 18, five services, Vite and a browser,
which the gate must not. Docker is not needed: without it tasks queue and
park, which is useful data for the dashboard.
| File | What it does |
| --- | --- |
| `stack.sh` | Starts PostgreSQL 18 (port 55432) and the five services as local processes, then Vite on 5173 |
| `seed.sh` | Seeds the stack through the dashboard API; safe to rerun |
| `run.cjs` | Runs `checks/*.cjs` in headless Chromium; screenshots to `out/` |
| `checks/` | One module per behaviour |
| `results/` | One committed report per release |
## Run
```bash
task e2e:up # build, start everything, seed
task e2e:check # all checks; or: node e2e/run.cjs routes
task e2e:down # stop; e2e/stack.sh reset also deletes the data
```
Nothing reads the installed config: `stack.sh` points the XDG directories at
`${ARCHIE_DEV_DIR:-~/.local/state/archie-dev}` and writes its overlay from
`deployments/dev.toml`. Logs are in its `logs/`. `e2e/stack.sh restart archied`
restarts one service.
The first run needs `npm ci --prefix e2e` and `npx --prefix e2e playwright
install chromium`. In the cloud environment, Chromium and Playwright are
preinstalled; run with `NODE_PATH=$(npm root -g)`.
## Release evidence
```bash
node e2e/run.cjs --record v1.54.0
```
writes `results/v1.54.0.md`, the pass or fail of every check for that
release. Commit it with the release. Screenshots stay in `out/`.
## Writing a check
A module in `checks/` exports `async ({ page, go, shot, fail })`. `go(path)`
loads a dashboard route, `shot(label)` saves a screenshot, `fail(msg)` records
a problem without stopping. A throw, a `fail`, or any console or page error
fails the check. Wait for elements, never for `networkidle`: the event stream
never goes idle.
`routes` loads every static route and flags text with stray leading,
trailing or doubled spaces. `seeded` checks the seed is visible.
## Pitfalls
| Symptom | Cause | Fix |
| --- | --- | --- |
| State Store exits: server is older than PostgreSQL 18 | another server answered | `stack.sh` uses port 55432; set `ARCHIE_DEV_PGPORT` if that is taken |
| Work request: repository is not configured | archied reads repository policies only at boot | `seed.sh` restarts it; do the same after changing policies |
| Your own shell is killed (exit 144) | `pkill -f` matched its own command line | `stack.sh stop` or `restart`, which kill by PID |
| `npx shadcn-vue add` cannot fetch the registry | Node's fetch ignores the cloud agent proxy | `curl` the registry JSON and copy the files |
| Postgres aborts in the cloud | `/tmp/claude-0` is reset to mode 700 | `stack.sh` keeps the root cluster in `/var/lib/archie-dev` |
+36
View File
@@ -0,0 +1,36 @@
// Every static route loads without errors, renders, and shows no text with
// stray leading, trailing or doubled spaces.
const fs = require('fs');
const path = require('path');
function routes() {
const src = fs.readFileSync(path.join(__dirname, '../../ui/src/router/index.ts'), 'utf8');
const out = [];
for (const line of src.split('\n')) {
if (/redirect:/.test(line)) continue;
const m = line.match(/path: "([^"]*)"/);
if (!m || m[1].includes(':')) continue;
if (m[1].startsWith('/')) out.push(m[1]);
else if (m[1]) out.push('/org/' + m[1]);
}
return [...new Set(out)];
}
module.exports = async ({ page, go, shot, fail }) => {
const stray = new Map();
for (const r of routes()) {
await go(r);
await shot(r);
// Log lines are data, not copy.
if (r === '/logs') continue;
const bad = await page.evaluate(() => [...document.querySelectorAll('body *')]
.filter((el) => !el.children.length && !el.closest('pre,code,textarea,.xterm') && el.getClientRects().length && !getComputedStyle(el).whiteSpace.startsWith('pre'))
.map((el) => el.textContent)
.filter((t) => t.trim() && (t !== t.trim() || / /.test(t.trim()))));
for (const t of bad) {
const key = JSON.stringify(t.length > 60 ? t.slice(0, 60) + '…' : t);
stray.set(key, (stray.get(key) || new Set()).add(r));
}
}
for (const [text, where] of stray) fail(`stray whitespace ${text} on ${[...where].join(', ')}`);
};
+9
View File
@@ -0,0 +1,9 @@
// The seed (e2e/seed.sh) is visible where an operator would look for it.
module.exports = async ({ page, go, shot }) => {
await go('/tasks');
await page.getByText('Fix flaky login test').first().waitFor({ timeout: 10000 });
await shot('tasks');
await go('/events');
await page.getByText('e2e-hook').first().waitFor({ timeout: 10000 });
await shot('events');
};
+42
View File
@@ -0,0 +1,42 @@
{
"name": "archie-e2e",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "archie-e2e",
"devDependencies": {
"playwright": "1.64.0"
}
},
"node_modules/playwright": {
"version": "1.64.0",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.64.0.tgz",
"integrity": "sha512-kVzTnYFYEyQ9RGzBjNCd2+yEqWmVbxl3AHPynv3qQ6JTjv4a+kwRcnqQwIpuP3NnrnIrE/Q6wWAIAvMfIE2/Yg==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"playwright-core": "1.64.0"
},
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=20"
}
},
"node_modules/playwright-core": {
"version": "1.64.0",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.64.0.tgz",
"integrity": "sha512-T9r+MZkTECl2+oUcZ26YgZzTrYidTsIhYYkJix+6iDOymOb1FB2RLLSOxRGnZGv5DStt+aduIVbt+E8WygXYpg==",
"dev": true,
"license": "Apache-2.0",
"bin": {
"playwright-core": "cli.js"
},
"engines": {
"node": ">=20"
}
}
}
}
+11
View File
@@ -0,0 +1,11 @@
{
"name": "archie-e2e",
"private": true,
"description": "Validation of a running local stack; never part of the gate",
"scripts": {
"check": "node run.cjs"
},
"devDependencies": {
"playwright": "1.64.0"
}
}
+62
View File
@@ -0,0 +1,62 @@
// Drive the dashboard of a running local stack (e2e/stack.sh) in headless
// Chromium. Each module in checks/ exports async ({ page, go, shot, fail }).
// A check fails on a thrown error or any console or page error.
//
// node e2e/run.cjs [--record VERSION] [check ...]
//
// Screenshots and results.json go to e2e/out/<stamp>/. --record also writes
// e2e/results/VERSION.md, the committed evidence for a release.
const fs = require('fs');
const path = require('path');
const { chromium } = require('playwright');
const base = process.env.ARCHIE_E2E_URL || 'http://localhost:5173';
const args = process.argv.slice(2);
let record = '';
if (args[0] === '--record') { record = args[1]; args.splice(0, 2); }
const names = args.length ? args : fs.readdirSync(path.join(__dirname, 'checks')).filter((f) => f.endsWith('.cjs')).map((f) => f.slice(0, -4)).sort();
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
const out = path.join(__dirname, 'out', stamp);
fs.mkdirSync(out, { recursive: true });
(async () => {
const browser = await chromium.launch();
const results = [];
for (const name of names) {
const check = require(path.join(__dirname, 'checks', name + '.cjs'));
// A fresh page per check: open event streams pile up across navigations.
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });
const errors = [];
const notes = [];
page.on('pageerror', (e) => errors.push(String(e)));
page.on('console', (m) => m.type() === 'error' && errors.push(m.text()));
// Wait for load, never networkidle: the event stream never goes idle.
const go = async (p) => { await page.goto(base + p, { waitUntil: 'load' }); await page.waitForTimeout(1200); };
const shot = (label) => page.screenshot({ path: path.join(out, `${name}-${label.replace(/[^a-z0-9-]+/gi, '_') || 'root'}.png`) });
const fail = (msg) => notes.push(msg);
const started = Date.now();
let error = '';
try { await check({ page, go, shot, fail }); } catch (e) { error = String(e && e.message || e); }
await page.close();
const problems = [error, ...notes, ...errors].filter(Boolean);
results.push({ check: name, ok: problems.length === 0, ms: Date.now() - started, problems });
console.log(`${problems.length ? 'FAIL' : 'ok '} ${name}${problems.length ? '\n ' + problems.join('\n ') : ''}`);
}
await browser.close();
fs.writeFileSync(path.join(out, 'results.json'), JSON.stringify(results, null, 2));
if (record) writeRecord(record, results);
console.log(`evidence: ${out}`);
process.exit(results.every((r) => r.ok) ? 0 : 1);
})().catch((e) => { console.error(e); process.exit(2); });
function writeRecord(version, results) {
const dir = path.join(__dirname, 'results');
fs.mkdirSync(dir, { recursive: true });
const rows = results.map((r) => `| ${r.check} | ${r.ok ? 'pass' : 'fail'} | ${r.problems.join('<br>').replace(/\|/g, '\\|') || ''} |`);
const passed = results.filter((r) => r.ok).length;
fs.writeFileSync(path.join(dir, `${version}.md`), [
`# ${version}`, '',
`Run ${new Date().toISOString()} against ${base}: ${passed} of ${results.length} checks passed.`, '',
'| Check | Result | Problems |', '| --- | --- | --- |', ...rows, '',
].join('\n'));
}
Executable
+50
View File
@@ -0,0 +1,50 @@
#!/usr/bin/env bash
# Seed a running local stack (e2e/stack.sh) through the dashboard's own HTTP
# API, so the seed exercises real validation. Safe to run again: each step
# skips what already exists.
set -euo pipefail
base=${ARCHIE_E2E_API:-http://localhost:8484}
here=$(cd "$(dirname "$0")" && pwd)
H=(-H 'Content-Type: application/json' -H 'X-Archie-CSRF: 1' -H "Origin: $base")
get() { curl -fsS "$base$1"; }
post() { curl -fsS -X POST "$base$1" "${H[@]}" -d "$2"; }
# jq-free JSON reads: py EXPR, with the parsed body as d.
py() { python3 -c "import sys, json; d = json.load(sys.stdin); print($1)"; }
# Repository policy. archied applies it live; the pause lets the watch publish it.
if ! get /api/control-plane/resources/repository-policies | grep -q '"widgets"'; then
version=$(get /api/control-plane/resources/repository-policies | py 'd["resource"]["version"]')
post /api/control-plane/resources/repository-policies/commands/replace \
"{\"value\":[{\"owner\":\"acme\",\"name\":\"widgets\",\"base\":\"main\"}],\"expected_version\":$version}" >/dev/null
sleep 5
fi
# Work requests. Without Docker they park within a minute, which fills
# Needs you, Quality gates and the task pages.
tasks=$(get /api/tasks)
for t in "Fix flaky login test" "Add retry to webhook sender" "Document the gate" "Speed up the CI cache"; do
grep -qF "\"$t\"" <<<"$tasks" && continue
post /api/work-requests "{\"identity\":\"archie-dev\",\"repository\":\"acme/widgets\",\"workflow\":\"triage\",\"title\":\"$t\",\"instructions\":\"Do it.\"}" >/dev/null
done
# An unsigned capture source with one delivery, an event type, a mapping and
# a binding left pending approval.
src=e2e-hook
if ! get /api/sources | grep -q "\"$src\""; then
post /api/sources "{\"path\":\"$src\"}" >/dev/null
post "/api/sources/$src/signing" '{"signed":false}' >/dev/null
post "/api/sources/$src/approve-unsigned" '{}' >/dev/null
bash "$here/../tools/webhook-send.sh" --url "$base" --source "$src" --kind github-issue >/dev/null
fi
et=$(get /api/event-types | py '"".join(t["id"] for t in (d.get("event_types", []) if isinstance(d, dict) else d) if t["name"] == "issue-opened")')
if [ -z "$et" ]; then
et=$(post /api/event-types "{\"source\":\"$src\",\"name\":\"issue-opened\",\"rule\":{\"headers\":[],\"payload\":[{\"path\":\"action\",\"op\":\"equals\",\"value\":\"opened\"}]},\"example\":{\"headers\":{},\"body\":\"{\\\"action\\\":\\\"opened\\\",\\\"issue\\\":{\\\"title\\\":\\\"x\\\"}}\"}}" | py 'd["id"]')
fi
if ! get /api/bindings | grep -q '"e2e-binding"'; then
mapping=$(post /api/mappings "{\"name\":\"e2e-issue\",\"source_hint\":\"$src\",\"event_type_id\":\"$et\",\"fields\":[{\"name\":\"title\",\"path\":\"issue.title\",\"type\":\"string\",\"required\":true}]}" | py 'd["id"]')
post /api/bindings "{\"name\":\"e2e-binding\",\"matcher\":{\"source\":\"$src\"},\"mapping_id\":\"$mapping\",\"workflow\":\"feasibility\",\"owner\":\"acme\",\"repo\":\"widgets\"}" >/dev/null
fi
echo "seeded: $(get /api/tasks | py 'len(d.get("tasks", d) if isinstance(d, dict) else d)') tasks"
Executable
+140
View File
@@ -0,0 +1,140 @@
#!/usr/bin/env bash
# Run the whole stack as local processes against a throwaway PostgreSQL 18,
# for manual and scripted checks. Never part of the gate. Nothing here reads
# the installed config: XDG paths point into the dev directory.
#
# e2e/stack.sh start | stop | restart <service> | status | reset
set -euo pipefail
repo=$(cd "$(dirname "$0")/.." && pwd)
dir=${ARCHIE_DEV_DIR:-${XDG_STATE_HOME:-$HOME/.local/state}/archie-dev}
pgport=${ARCHIE_DEV_PGPORT:-55432}
services=(archie-state-store archie-gateway archied archie-messaging archie-ui)
# initdb refuses root, and postgres cannot traverse root's home.
if [ "$(id -u)" -eq 0 ]; then
pgdata=/var/lib/archie-dev/pg
as_pg() { runuser -u postgres -- "$@"; }
else
pgdata=$dir/pg
as_pg() { "$@"; }
fi
export XDG_CONFIG_HOME=$dir/config XDG_DATA_HOME=$dir/data XDG_STATE_HOME=$dir/state
pgbin() {
local d
for d in /usr/lib/postgresql/18/bin "$(dirname "$(command -v postgres 2>/dev/null || echo /x/x)")"; do
if [ -x "$d/postgres" ] && "$d/postgres" --version | grep -q ' 18\.'; then
echo "$d"
return
fi
done
echo "PostgreSQL 18 server not found" >&2
exit 1
}
wait_port() {
for _ in $(seq 1 "${3:-60}"); do
(echo >"/dev/tcp/127.0.0.1/$1") 2>/dev/null && return 0
sleep 1
done
echo "$2 did not listen on $1; see $dir/logs/$2.log" >&2
return 1
}
start_pg() {
local bin
bin=$(pgbin)
if [ ! -f "$pgdata/PG_VERSION" ]; then
mkdir -p "$pgdata"
[ "$(id -u)" -ne 0 ] || chown postgres "$pgdata"
as_pg "$bin/initdb" -D "$pgdata" -U archie --auth=trust >/dev/null
fi
if ! as_pg "$bin/pg_ctl" -D "$pgdata" status >/dev/null 2>&1; then
as_pg "$bin/pg_ctl" -D "$pgdata" -w -l "$pgdata/server.log" \
-o "-p $pgport -k $pgdata -c listen_addresses=127.0.0.1" start >/dev/null
fi
"$bin/psql" -h 127.0.0.1 -p "$pgport" -U archie -d postgres -qtAc \
"SELECT 1 FROM pg_database WHERE datname = 'archie'" | grep -q 1 ||
"$bin/createdb" -h 127.0.0.1 -p "$pgport" -U archie archie
}
prepare() {
mkdir -p "$dir"/{bin,logs,pids} "$XDG_CONFIG_HOME/archie" "$XDG_DATA_HOME" "$XDG_STATE_HOME"
[ -f "$XDG_CONFIG_HOME/archie/config.toml" ] || cp "$repo/config.example.toml" "$XDG_CONFIG_HOME/archie/config.toml"
sed "s#^database_url = .*#database_url = \"postgres://archie@127.0.0.1:$pgport/archie?sslmode=disable\"#" \
"$repo/deployments/dev.toml" >"$dir/dev.toml"
local s
for s in "${services[@]}"; do
(cd "$repo" && go build -o "$dir/bin/$s" "./cmd/$s")
done
}
# spawn NAME DIR CMD...: a detached session leader, so stop takes its children.
spawn() {
local name=$1 cwd=$2
shift 2
setsid -f bash -c 'cd "$1" && echo $$ >"$2" && shift 2 && exec "$@"' _ "$cwd" "$dir/pids/$name" "$@" \
</dev/null >"$dir/logs/$name.log" 2>&1
}
start_service() {
spawn "$1" "$repo" "$dir/bin/$1" -config-overlay "$dir/dev.toml"
}
stop_pid() {
local f=$1 pid
[ -f "$f" ] || return 0
pid=$(cat "$f")
if kill -- "-$pid" 2>/dev/null; then
for _ in $(seq 1 20); do kill -0 "$pid" 2>/dev/null || break; sleep 0.5; done
kill -9 -- "-$pid" 2>/dev/null || true
fi
rm -f "$f"
}
start() {
prepare
start_pg
start_service archie-state-store
wait_port 9091 archie-state-store 90
local s
for s in archie-gateway archied archie-messaging archie-ui; do start_service "$s"; done
wait_port 8484 archie-ui
[ -d "$repo/ui/node_modules" ] || (cd "$repo/ui" && npm ci --no-audit --no-fund >/dev/null)
spawn vite "$repo/ui" npx vite --host 127.0.0.1 --port 5173 --strictPort
wait_port 5173 vite
echo "dashboard: http://localhost:5173 logs: $dir/logs"
}
stop() {
local f
for f in "$dir"/pids/*; do stop_pid "$f"; done
if [ -f "$pgdata/PG_VERSION" ]; then
as_pg "$(pgbin)/pg_ctl" -D "$pgdata" -m fast stop >/dev/null 2>&1 || true
fi
}
case ${1:-} in
start) start ;;
stop) stop ;;
restart)
stop_pid "$dir/pids/${2:?service}"
start_service "$2"
;;
status)
for f in "$dir"/pids/*; do
[ -f "$f" ] || continue
if kill -0 "$(cat "$f")" 2>/dev/null; then echo "up $(basename "$f")"; else echo "down $(basename "$f")"; fi
done
;;
reset)
stop
rm -rf "$dir" "$pgdata"
;;
*)
echo "usage: $0 start | stop | restart <service> | status | reset" >&2
exit 2
;;
esac
+26 -43
View File
@@ -4,34 +4,28 @@ go 1.27.2
require (
cel.dev/expr v0.25.3 // indirect
dario.cat/mergo v1.0.2 // indirect
github.com/Azure/go-ansiterm v0.0.0-20261008225312-e8a9660d7aea // indirect
github.com/Microsoft/go-winio v0.6.3 // indirect
github.com/Microsoft/go-winio v0.6.4 // indirect
github.com/ProtonMail/go-crypto v1.5.2 // indirect
github.com/antithesishq/antithesis-sdk-go v0.8.0 // indirect
github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudflare/circl v1.6.5 // indirect
github.com/containerd/errdefs v1.0.0 // indirect
github.com/containerd/errdefs/pkg v0.3.0 // indirect
github.com/containerd/log v0.2.0 // indirect
github.com/containerd/platforms v1.0.0-rc.5 // indirect
github.com/cpuguy83/dockercfg v0.3.2 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/go-connections v0.8.2 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.1.0 // indirect
github.com/ebitengine/purego v0.11.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.19.0 // indirect
github.com/felixge/httpsnoop v1.1.0 // indirect
github.com/fxamacker/cbor/v2 v2.9.4 // indirect
github.com/go-git/gcfg/v2 v2.0.2 // indirect
github.com/go-jose/go-jose/v4 v4.1.5 // indirect
github.com/go-json-experiment/json v0.0.0-20260820222146-c27c302e5fc3 // indirect
github.com/go-logr/logr v1.4.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
github.com/go-webauthn/x v0.3.1 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-tpm v0.9.8 // indirect
github.com/hashicorp/yamux v0.1.2 // indirect
@@ -39,38 +33,27 @@ require (
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.3 // indirect
github.com/kevinburke/ssh_config v1.6.0 // indirect
github.com/klauspost/compress v1.20.1 // indirect
github.com/lufia/plan9stats v0.0.0-20260802145828-341c2f0c90b5 // indirect
github.com/magiconair/properties v1.18.12 // indirect
github.com/klauspost/compress v1.20.3 // indirect
github.com/mattn/go-colorable v0.1.16 // indirect
github.com/mattn/go-isatty v0.0.24 // indirect
github.com/mfridman/interpolate v0.0.2 // indirect
github.com/minio/highwayhash v1.0.4 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/go-archive v0.3.3 // indirect
github.com/moby/patternmatcher v0.6.1 // indirect
github.com/moby/sys/sequential v0.7.0 // indirect
github.com/moby/sys/user v0.4.1 // indirect
github.com/moby/sys/userns v0.2.1 // indirect
github.com/moby/term v0.5.2 // indirect
github.com/nats-io/jwt/v2 v2.8.2 // indirect
github.com/nats-io/nkeys v0.4.16 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/oklog/run v1.2.0 // indirect
github.com/philhofer/fwd v1.2.0 // indirect
github.com/pjbgf/sha1cd v0.7.0 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/power-devops/perfstat v0.0.0-20260916203055-22a1a467d9f0 // indirect
github.com/segmentio/asm v1.2.1 // indirect
github.com/segmentio/encoding v0.5.4 // indirect
github.com/sergi/go-diff v1.4.0 // indirect
github.com/sethvargo/go-retry v0.5.0 // indirect
github.com/shirou/gopsutil/v4 v4.26.9 // indirect
github.com/sirupsen/logrus v1.10.2 // indirect
github.com/stretchr/testify v1.12.1 // indirect
github.com/tklauser/go-sysconf v0.4.0 // indirect
github.com/tklauser/numcpus v0.12.0 // indirect
github.com/tinylib/msgp v1.6.4 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.72.0 // indirect
go.opentelemetry.io/otel v1.47.0 // indirect
@@ -79,26 +62,27 @@ require (
go.opentelemetry.io/otel/trace v1.47.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.yaml.in/yaml/v3 v3.0.5 // indirect
golang.org/x/crypto v0.57.0 // indirect
golang.org/x/exp v0.0.0-20261007192929-f45ad48fbe92 // indirect
golang.org/x/sync v0.23.0 // indirect
golang.org/x/text v0.42.0 // indirect
golang.org/x/exp v0.0.0-20261013213113-2ab7f3cbc5fb // indirect
golang.org/x/sync v0.24.0 // indirect
golang.org/x/text v0.43.0 // indirect
golang.org/x/time v0.16.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20261005182115-fad411399dd8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20261005182115-fad411399dd8 // indirect
modernc.org/libc v1.77.1 // indirect
modernc.org/sqlite v1.59.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20261012220534-4341edf3f941 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20261012220534-4341edf3f941 // indirect
)
require (
cel.dev/cel-go v0.32.0
github.com/BurntSushi/toml v1.6.0
github.com/cedar-policy/cedar-go v1.8.0
github.com/containerd/errdefs v1.0.0
github.com/coreos/go-oidc/v3 v3.21.0
github.com/docker/sandbox-kit-spec/v3 v3.0.0-m.8
github.com/go-git/go-billy/v6 v6.0.0-beta.1
github.com/go-git/go-git/v6 v6.0.0-beta.1
github.com/go-jose/go-jose/v4 v4.1.5
github.com/go-telegram/bot v1.27.0
github.com/go-webauthn/webauthn v0.18.2
github.com/golang-jwt/jwt/v5 v5.3.1
github.com/google/jsonschema-go v0.4.3
github.com/google/uuid v1.6.0
github.com/hashicorp/go-hclog v1.6.3
@@ -107,24 +91,23 @@ require (
github.com/moby/moby/api v1.56.1
github.com/moby/moby/client v0.6.2
github.com/modelcontextprotocol/go-sdk v1.8.0
github.com/nats-io/nats-server/v2 v2.15.0
github.com/nats-io/nats-server/v2 v2.15.1
github.com/nats-io/nats.go v1.54.0
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.1
github.com/pressly/goose/v3 v3.28.0
github.com/samcharles93/ai-sdk v0.1.43
github.com/testcontainers/testcontainers-go v0.44.0
github.com/testcontainers/testcontainers-go/modules/postgres v0.44.0
github.com/pressly/goose/v3 v3.29.0
github.com/samcharles93/ai-sdk v0.3.1
go.lsp.dev/jsonrpc2 v1.0.1
go.lsp.dev/protocol v1.0.1
go.lsp.dev/uri v1.0.1
golang.org/x/mod v0.41.0
golang.org/x/net v0.60.0
golang.org/x/crypto v0.58.0
golang.org/x/mod v0.42.0
golang.org/x/net v0.61.0
golang.org/x/oauth2 v0.37.0
golang.org/x/sys v0.48.0
golang.org/x/term v0.46.0
golang.org/x/sys v0.49.0
golang.org/x/term v0.47.0
google.golang.org/grpc v1.86.0-dev
google.golang.org/protobuf v1.36.12
gopkg.in/yaml.v3 v3.0.1
oras.land/oras-go/v2 v2.6.2
oras.land/oras-go/v2 v2.6.3
)
+58 -99
View File
@@ -2,16 +2,10 @@ cel.dev/cel-go v0.32.0 h1:irvpFKr5EuGPyxeME03ERh0rii1TX+BDAnB9eL3IvNk=
cel.dev/cel-go v0.32.0/go.mod h1:DnVip7tpJSsgZymwfT+m1tnEVy3ivAjSMXPx12YrMkU=
cel.dev/expr v0.25.3 h1:A2jO8jwOugrrovveCWfj0KEZOfqiLgAcwjpHPhzIGw0=
cel.dev/expr v0.25.3/go.mod h1:hrXvqGP6G6gyx8UAHSHJ5RGk//1Oj5nXQ2NI02Nrsg4=
dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8=
dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 h1:He8afgbRMd7mFxO99hRNu+6tazq8nFF9lIwo9JFroBk=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8=
github.com/Azure/go-ansiterm v0.0.0-20261008225312-e8a9660d7aea h1:NdVLskj4PaItpD133shAdyHicndDbcDGpManoqR032g=
github.com/Azure/go-ansiterm v0.0.0-20261008225312-e8a9660d7aea/go.mod h1:Ue4ymb+lBljb9NjkybMTsOYOSjH/cJTim9nrhvRJAUU=
github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk=
github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/Microsoft/go-winio v0.6.3 h1:M/52tsoyTfwaxajLnXZm7PqkbMGRH8iSWP+8fcg9MQ4=
github.com/Microsoft/go-winio v0.6.3/go.mod h1:ma0QpxizD4fyyzJ1C7MIblymTD2Nxz5Mho/3CepwIZg=
github.com/Microsoft/go-winio v0.6.4 h1:kJF2pamtYCWXf0xAT8sAkwKC0pMl2HYBrRPHAqyUc+g=
github.com/Microsoft/go-winio v0.6.4/go.mod h1:1xl5JXG4ze/m74GH6Dc4Mwxfc3VL5siRVQjIAlHH07U=
github.com/ProtonMail/go-crypto v1.5.2 h1:cucYnvqcY7UOXVD//mSyjeaPY0SSN3v5cDkYPxumINk=
github.com/ProtonMail/go-crypto v1.5.2/go.mod h1:/RaSu30DaKO4RY+XdV/ACcCcZkGr7AhUIduq5sjzzCo=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
@@ -26,8 +20,6 @@ github.com/bufbuild/protocompile v0.14.1 h1:iA73zAf/fyljNjQKwYzUHD6AD4R8KMasmwa/
github.com/bufbuild/protocompile v0.14.1/go.mod h1:ppVdAIhbr2H8asPk6k4pY7t9zB1OU5DoEw9xY/FUi1c=
github.com/cedar-policy/cedar-go v1.8.0 h1:9gcU7EHXwHC2RMdpph68yTAkdB3behTTssC+kt4GoS8=
github.com/cedar-policy/cedar-go v1.8.0/go.mod h1:h5+3CVW1oI5LXVskJG+my9TFCYI5yjh/+Ul3EJie6MI=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cloudflare/circl v1.6.5 h1:O64F26HEqNhznd/hrC5KZXVKYuKM2rx4deZDTc4ihQA=
@@ -42,10 +34,6 @@ github.com/containerd/platforms v1.0.0-rc.5 h1:vXd569rDrz8LeMXzAnBsy6LADV5YtsD8o
github.com/containerd/platforms v1.0.0-rc.5/go.mod h1:lKlMXyLybmBedS/JJm11uDofzI8L2v0J2ZbYvNsbq1A=
github.com/coreos/go-oidc/v3 v3.21.0 h1:wZo4Q9Pum8dYEj0eMUPrqR+kvuGkeUplbLpNCkBqoWM=
github.com/coreos/go-oidc/v3 v3.21.0/go.mod h1:DYCf24+ncYi+XkIH97GY1+dqoRlbaSI26KVTCI9SrY4=
github.com/cpuguy83/dockercfg v0.3.2 h1:DlJTyZGBDlXqUZ2Dk2Q3xHs/FtnooJJVaad2S9GKorA=
github.com/cpuguy83/dockercfg v0.3.2/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc=
github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s=
github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
@@ -58,8 +46,6 @@ github.com/docker/sandbox-kit-spec/v3 v3.0.0-m.8 h1:ay2XEj0yW3uzsNwN3KXS/c4nlneH
github.com/docker/sandbox-kit-spec/v3 v3.0.0-m.8/go.mod h1:4G6VgFAp9eaQkwy7DbZbOfWRD/Mjvc/TnEtQBRRMEsA=
github.com/dustin/go-humanize v1.1.0 h1:dbKTrvD0klcbBV/h4AWJdMuZogJACoMlvWIWZ5b2xWg=
github.com/dustin/go-humanize v1.1.0/go.mod h1:hc1CvRkJMsgxqjmjMQF3QNRAZBwY8AXBAzKYoSX9sFI=
github.com/ebitengine/purego v0.11.1 h1:2zpWRSQNVKN4eKsKO9eM1ILDgWfYMY9GwqRmK6XeQ/0=
github.com/ebitengine/purego v0.11.1/go.mod h1:DCHPP08djqhNSoTfImcnHYQRZmd0qhakvrozqaEYhGQ=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
@@ -67,6 +53,8 @@ github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w=
github.com/fatih/color v1.19.0/go.mod h1:zNk67I0ZUT1bEGsSGyCZYZNrHuTkJJB+r6Q9VuMi0LE=
github.com/felixge/httpsnoop v1.1.0 h1:3YtUj32ZZkqZtt3sZZsClsymw/QDuVfpNhoA31zeORc=
github.com/felixge/httpsnoop v1.1.0/go.mod h1:Zqxgdd+1Rkcz8euOqdr7lqgCRJztwr5hp9vDSi5UZCE=
github.com/fxamacker/cbor/v2 v2.9.4 h1:xwjVlxEMR3S605oUlgBjKLTTeGFciYPGYCtF/35LKGo=
github.com/fxamacker/cbor/v2 v2.9.4/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ=
github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c=
github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU=
github.com/go-git/gcfg/v2 v2.0.2 h1:MY5SIIfTGGEMhdA7d7JePuVVxtKL7Hp+ApGDJAJ7dpo=
@@ -86,11 +74,14 @@ github.com/go-logr/logr v1.4.4 h1:tG4xh9yMsRCAiodLVTxyrkzSZ9+o0L1Kg/+cPVcbP/8=
github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
github.com/go-telegram/bot v1.27.0 h1:PG9yBDzM8O26oUerE9SZwWlHon4RpH8WcNslZ7CEZmE=
github.com/go-telegram/bot v1.27.0/go.mod h1:i2TRs7fXWIeaceF3z7KzsMt/he0TwkVC680mvdTFYeM=
github.com/go-viper/mapstructure/v2 v2.5.0 h1:vM5IJoUAy3d7zRSVtIwQgBj7BiWtMPfmPEgAXnvj1Ro=
github.com/go-viper/mapstructure/v2 v2.5.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/go-webauthn/webauthn v0.18.2 h1:0BeftmEHU7i3Dv0VFwBtidy/ba37Vcdjvqst9EYu8Sk=
github.com/go-webauthn/webauthn v0.18.2/go.mod h1:hEXaOuLxvZ3zG9miZe3ehlyeVso9AtklXG+kTn36k+A=
github.com/go-webauthn/x v0.3.1 h1:1ff37z3XfmTTomkhlURgGizLIDyOvPgTt2t9nlzKLRo=
github.com/go-webauthn/x v0.3.1/go.mod h1:ZInxAynYXfBPvvm5gzKZ7geBlL23K71xASMgohHl/Rg=
github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY=
github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
@@ -99,6 +90,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo=
github.com/google/go-tpm v0.9.8/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY=
github.com/google/go-tpm-tools v0.3.13-0.20230620182252-4639ecce2aba h1:qJEJcuLzH5KDR0gKc0zcktin6KSAwL7+jWKBYceddTc=
github.com/google/go-tpm-tools v0.3.13-0.20230620182252-4639ecce2aba/go.mod h1:EFYHy8/1y2KfgTAsx7Luu7NGhoxtuVHnNo8jE7FikKc=
github.com/google/jsonschema-go v0.4.3 h1:/DBOLZTfDow7pe2GmaJNhltueGTtDKICi8V8p+DQPd0=
github.com/google/jsonschema-go v0.4.3/go.mod h1:r5quNTdLOYEz95Ru18zA0ydNbBuYoo9tgaYcxEYhJVE=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
@@ -121,8 +114,8 @@ github.com/jhump/protoreflect v1.17.0 h1:qOEr613fac2lOuTgWN4tPAtLL7fUSbuJL5X5Xum
github.com/jhump/protoreflect v1.17.0/go.mod h1:h9+vUUL38jiBzck8ck+6G/aeMX8Z4QUY/NiJPwPNi+8=
github.com/kevinburke/ssh_config v1.6.0 h1:J1FBfmuVosPHf5GRdltRLhPJtJpTlMdKTBjRgTaQBFY=
github.com/kevinburke/ssh_config v1.6.0/go.mod h1:q2RIzfka+BXARoNexmF9gkxEX7DmvbW9P4hIVx2Kg4M=
github.com/klauspost/compress v1.20.1 h1:T7kKElXUMXrUJ2E9QhQhxFtcK5rPyLdsGZvdbLMPdiQ=
github.com/klauspost/compress v1.20.1/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
github.com/klauspost/compress v1.20.3 h1:zWNoFqq/lSuYQRim3dUXlXeA0IqwuZGicdG5ZTfY5j4=
github.com/klauspost/compress v1.20.3/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
@@ -130,12 +123,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lufia/plan9stats v0.0.0-20260802145828-341c2f0c90b5 h1:eveIIGn4BGM3qknO74omf6HYr30/exH+eVUTuAgwjZ0=
github.com/lufia/plan9stats v0.0.0-20260802145828-341c2f0c90b5/go.mod h1:autxFIvghDt3jPTLoqZ9OZ7s9qTGNAWmYCjVFWPX/zg=
github.com/magiconair/properties v1.18.12 h1:sT9zQpvTB3B4gzrX0tmZNTEaGyg8Zw55MFYRE32Mr9I=
github.com/magiconair/properties v1.18.12/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.16 h1:+2YjeAe7xP1OQbZW1jERPWWCDLlNqFNCvjiqGiAt84A=
@@ -144,69 +131,51 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.24 h1:tGZZoVgT/KiqK1c8ocVLeDS8BSWMRd47J3Lbz7vsReI=
github.com/mattn/go-isatty v0.0.24/go.mod h1:nMCL3Zebbrt45jsMDgnfIwz6ydEQApk5oEI3HqDio6A=
github.com/mdelapenya/tlscert v0.2.0 h1:7H81W6Z/4weDvZBNOfQte5GpIMo0lGYEeWbkGp5LJHI=
github.com/mdelapenya/tlscert v0.2.0/go.mod h1:O4njj3ELLnJjGdkN7M/vIVCpZ+Cf0L6muqOG4tLSl8o=
github.com/mfridman/interpolate v0.0.2 h1:pnuTK7MQIxxFz1Gr+rjSIx9u7qVjf5VOoM/u6BbAxPY=
github.com/mfridman/interpolate v0.0.2/go.mod h1:p+7uk6oE07mpE/Ik1b8EckO0O4ZXiGAfshKBWLUM9Xg=
github.com/minio/highwayhash v1.0.4 h1:asJizugGgchQod2ja9NJlGOWq4s7KsAWr5XUc9Clgl4=
github.com/minio/highwayhash v1.0.4/go.mod h1:GGYsuwP/fPD6Y9hMiXuapVvlIUEhFhMTh0rxU3ik1LQ=
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
github.com/moby/go-archive v0.3.3 h1:OxxR9paxsluYi+zDUEXTTaIxtkK3viymW+Ka7vRhhME=
github.com/moby/go-archive v0.3.3/go.mod h1:Npdv43fFqlhZW7Xo8fbm3ZMYFvAGNviUPqX21VERbcE=
github.com/moby/moby/api v1.56.1 h1:PpWkvVPB7Fr/No8w+TfyJ/I6rWZ2YPZhT3JorIg+06c=
github.com/moby/moby/api v1.56.1/go.mod h1:sZ+THbVWkjOmBPPfbnzdD/G1LuIexWhqlSHHPTDQ1Uk=
github.com/moby/moby/client v0.6.2 h1:ekSPlMccrZGcw6Scb8T9D39qE0mB+XupU/yS0zNw9N4=
github.com/moby/moby/client v0.6.2/go.mod h1:DGcnO7qmPJrqobx/ggQgQ/AUk+2wgVdQv7uxB0/mEsc=
github.com/moby/patternmatcher v0.6.1 h1:qlhtafmr6kgMIJjKJMDmMWq7WLkKIo23hsrpR3x084U=
github.com/moby/patternmatcher v0.6.1/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc=
github.com/moby/sys/mount v0.3.5 h1:eS3fsZTjHaBihwjp4/+5Z3jxqLXYsbwxqpVSfFv3M00=
github.com/moby/sys/mount v0.3.5/go.mod h1:WUQDO+/uCiCIkIztx8SrwIDVn2dtMFRBebRhpDFT71M=
github.com/moby/sys/mountinfo v0.7.2 h1:1shs6aH5s4o5H2zQLn796ADW1wMrIwHsyJ2v9KouLrg=
github.com/moby/sys/mountinfo v0.7.2/go.mod h1:1YOa8w8Ih7uW0wALDUgT1dTTSBrZ+HiBLGws92L2RU4=
github.com/moby/sys/sequential v0.7.0 h1:ASQNGNROJSuOO6LL6bPHbKvuZu6NU8P4ldPWk31zj/8=
github.com/moby/sys/sequential v0.7.0/go.mod h1:NfSTAp6V3fw4tmkD62PEcOKeZKquXT8VKCkf7aVR79o=
github.com/moby/sys/user v0.4.1 h1:RgjRlaDKi/Xmyrz4t8lyzXT6v2ooFeO/7xtchmhVWE0=
github.com/moby/sys/user v0.4.1/go.mod h1:E9QsW5WRe1kUAf7kW8hXKwu1uhsZEAdPLYHYSDudF4Y=
github.com/moby/sys/userns v0.2.1 h1:4OvdM7BcPkASbuouHsbW3aeMJSFlYDldBRnXVZhaRk8=
github.com/moby/sys/userns v0.2.1/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
github.com/moby/term v0.5.2 h1:6qk3FJAFDs6i/q3W/pQ97SX192qKfZgGjCQqfCJkgzQ=
github.com/moby/term v0.5.2/go.mod h1:d3djjFCrjnB+fl8NJux+EJzu0msscUP+f8it8hPkFLc=
github.com/modelcontextprotocol/go-sdk v1.8.0 h1:KIvahhYqwtbeniWVPs3TcXEA7b8jEtwfBpOTAI+Urx4=
github.com/modelcontextprotocol/go-sdk v1.8.0/go.mod h1:dL7u98E/zjJTGzEq+j30jQ8K2k1mb6LeAH4inEcSGts=
github.com/nats-io/jwt/v2 v2.8.2 h1:XXRgB60MSTnqsRwejQurVDs/hcv2dkt+86GjI+I/bMc=
github.com/nats-io/jwt/v2 v2.8.2/go.mod h1:Ag/56sq9OblL4JgdYufDd16Egb17Kr/8WwwuO/forVc=
github.com/nats-io/nats-server/v2 v2.15.0 h1:M99yf0y05rTr46/qc/Is6ZAowI58Ryp2SjufLCUeVJc=
github.com/nats-io/nats-server/v2 v2.15.0/go.mod h1:5qLF4CDGzZVFt//3fUrY1ePpwbi05r7QHPNroSUtolk=
github.com/nats-io/nats-server/v2 v2.15.1 h1:fK3AeYFIji1Smng60jB0hVoAPZezA/UzsaI3BqXFNEI=
github.com/nats-io/nats-server/v2 v2.15.1/go.mod h1:yeuYRtKVKIFtmMz2/YPk+6hvmNBnk+WwTUzErBdH6IE=
github.com/nats-io/nats.go v1.54.0 h1:vsXoOxjHp/GmPUN+EcI7uOf/uB+iAP+kEsAFNQN0yzA=
github.com/nats-io/nats.go v1.54.0/go.mod h1:y+DZoD1oBOYfZTU681eTUiUjI0vbqYGixNVFHcjHJ0k=
github.com/nats-io/nkeys v0.4.16 h1:rd5oAuLOb8mnAycB0xleuEBNS1pVVnN0fv/FF34Eypg=
github.com/nats-io/nkeys v0.4.16/go.mod h1:llLgWoI0o4z/Q57q2R1kHfmocyhGV6VG/U18Glg1Afs=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/ncruces/go-strftime v1.1.0 h1:vtPmPWMkb539RGV9WpWT9EwJGvrOCKvMNI4obWL47Hk=
github.com/ncruces/go-strftime v1.1.0/go.mod h1:yVaq7iwCN09vHRrKBrrflXT0M9tTMG2KmZ9Fj7xeG/g=
github.com/oklog/run v1.2.0 h1:O8x3yXwah4A73hJdlrwo/2X6J62gE5qTMusH0dvz60E=
github.com/oklog/run v1.2.0/go.mod h1:mgDbKRSwPhJfesJ4PntqFUbKQRZ50NgmZTSPlFA0YFk=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M=
github.com/philhofer/fwd v1.2.0 h1:e6DnBTl7vGY+Gz322/ASL4Gyp1FspeMvx1RNDoToZuM=
github.com/philhofer/fwd v1.2.0/go.mod h1:RqIHx9QI14HlwKwm98g9Re5prTQ6LdeRQn+gXJFxsJM=
github.com/pjbgf/sha1cd v0.7.0 h1:ZRNPKHj+gfkLBf0KJv/p1Hmz+7bqCT5o311YX0nq+DA=
github.com/pjbgf/sha1cd v0.7.0/go.mod h1:pKR5Li+qTCo+ebqITZfwPlJGoCFCvSO00qxjbNtTUFQ=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/power-devops/perfstat v0.0.0-20260916203055-22a1a467d9f0 h1:XA01Vk/wv9YikCi1V51yRzIHPMT5of9+cMpZoZvDn/M=
github.com/power-devops/perfstat v0.0.0-20260916203055-22a1a467d9f0/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/pressly/goose/v3 v3.28.0 h1:D2M+iL31GmpZxSHOhX8mqyqAT3CXnokUmm0eKoSP+Vc=
github.com/pressly/goose/v3 v3.28.0/go.mod h1:v26MOuB8bL3kzzrt3Vqhb3R0PRVsl8hFQKdrht/L6Rk=
github.com/pressly/goose/v3 v3.29.0 h1:dtEnBCT7CqkHIUCdgrXsrmeisaN8gFkRU4Y5OEwif4o=
github.com/pressly/goose/v3 v3.29.0/go.mod h1:plA4aP4+u+Q3FMTgbFbhF8TuAWpAdfWpoFGkJsIFWh0=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/samcharles93/ai-sdk v0.1.43 h1:u/OER6FuRv/KkS/5xnRttABPD2UNHR2BmcJeRe07hyw=
github.com/samcharles93/ai-sdk v0.1.43/go.mod h1:u4zrQ9/Q58L5mNEut4bNQ1ks+RCKq71LN5EDz2N/0Zk=
github.com/samcharles93/ai-sdk v0.3.1 h1:fD/Byx1Vo6NeZZBsSurxTO9e2/tAdAlEUIW+J7Hc/DM=
github.com/samcharles93/ai-sdk v0.3.1/go.mod h1:u4zrQ9/Q58L5mNEut4bNQ1ks+RCKq71LN5EDz2N/0Zk=
github.com/segmentio/asm v1.2.1 h1:DTNbBqs57ioxAD4PrArqftgypG4/qNpXoJx8TVXxPR0=
github.com/segmentio/asm v1.2.1/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
github.com/segmentio/encoding v0.5.4 h1:OW1VRern8Nw6ITAtwSZ7Idrl3MXCFwXHPgqESYfvNt0=
@@ -215,31 +184,21 @@ github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw=
github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/sethvargo/go-retry v0.5.0 h1:JYfFKmVJ8ER06GReN1efzc5cm52BrVsFVzmcHiKJwfY=
github.com/sethvargo/go-retry v0.5.0/go.mod h1:tvsjdKG6xfiCx4LSiUZ06kcv38xvdVQwv8R6/VnnVWg=
github.com/shirou/gopsutil/v4 v4.26.9 h1:CaBo/hBFqvlJoLvAQEKdHdf5GD97/MN2ACfyv63+2Ig=
github.com/shirou/gopsutil/v4 v4.26.9/go.mod h1:nKH+8wX2zxr/mDbsR+AAy6Qd2z4ZOQ7wfQaEp+yrYmg=
github.com/sirupsen/logrus v1.10.2 h1:G2SED73/qrAu6YwbdxOD6peLkCBI3z7L+ykJFTXJBBo=
github.com/sirupsen/logrus v1.10.2/go.mod h1:SLEg8TqYulVKKfIGHldVp2K2aYz2DKSVBq4g/H5bR7Q=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.5.3 h1:jmXUvGomnU1o3W/V5h2VEradbpJDwGrzugQQvL0POH4=
github.com/stretchr/objx v0.5.3/go.mod h1:rDQraq+vQZU7Fde9LOZLr8Tax6zZvy4kuNKF+QYS+U0=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
github.com/testcontainers/testcontainers-go v0.44.0 h1:/Fwh6HY1mIikhnm9e7HwoxGycx0lzRAE0f5VQpjFxzI=
github.com/testcontainers/testcontainers-go v0.44.0/go.mod h1:IcnwQrYTO86xHXu5bvMaBH7ATlbS3Qn1M1QWW3c66rE=
github.com/testcontainers/testcontainers-go/modules/postgres v0.44.0 h1:8fdv/9y3JMxjQ+ULAcOG8RtgeNu5t9XF9LolSXDuTwM=
github.com/testcontainers/testcontainers-go/modules/postgres v0.44.0/go.mod h1:CFr2LncGYokw+OKjXcr8ARCKG1SaC2UEnGxFBovE86g=
github.com/tklauser/go-sysconf v0.4.0 h1:7H0uAN+7RkwWRaxhYXDLqa5V3LPrJeV8wmD9dRUgPQU=
github.com/tklauser/go-sysconf v0.4.0/go.mod h1:8mTNWyog7H+MpKijp4VmKJAd2bbYQ2zuUwkYRbUArPI=
github.com/tklauser/numcpus v0.12.0 h1:NR85qdvHA9pFse3x3weVZ0r0ST8R6l5RHbZrlRaqob4=
github.com/tklauser/numcpus v0.12.0/go.mod h1:ABHeXzJnr/qqwguhClkZKT1/8VABcYrsyUiUGobwWJg=
github.com/tinylib/msgp v1.6.4 h1:mOwYbyYDLPj35mkA2BjjYejgJk9BuHxDdvRnb6v2ZcQ=
github.com/tinylib/msgp v1.6.4/go.mod h1:RSp0LW9oSxFut3KzESt5Voq4GVWyS+PSulT77roAqEA=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
go.lsp.dev/jsonrpc2 v1.0.1 h1:JZAchpm6RcOuwEOnZ7kF3kA1EpEjdJZ/6rMSfOF3+F4=
go.lsp.dev/jsonrpc2 v1.0.1/go.mod h1:WN+TesqrPumBmUdsuWyn9DHq3zl4i85L/qG0NLdj8qg=
go.lsp.dev/protocol v1.0.1 h1:kLWUIk1v/deXxo1D0VO4avjZnfeuZ82mouJgJd/NbdU=
@@ -262,47 +221,47 @@ go.opentelemetry.io/otel/sdk/metric v1.47.0 h1:lfISg2j93VT6yqdk9OfUaZmw/GfcZqCCV
go.opentelemetry.io/otel/sdk/metric v1.47.0/go.mod h1:ypLp+mW1Nt2x+Szt3b5/i1syodyts49lMOwxpDI3VGw=
go.opentelemetry.io/otel/trace v1.47.0 h1:JOjX/Oci8K94QHddo+bbfya/Ai/nf6/dt9ZfrFNWSrM=
go.opentelemetry.io/otel/trace v1.47.0/go.mod h1:jNaSLa2PZEYFG6fRjJABAu+bw4FS08uDmPg28lTghu0=
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M=
golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA=
golang.org/x/exp v0.0.0-20261007192929-f45ad48fbe92 h1:kc+Gi2MFkd0KWtdDlVxVwjw4KB98/77usJDFj+6YFQ8=
golang.org/x/exp v0.0.0-20261007192929-f45ad48fbe92/go.mod h1:SRjTzy5WcYqRRqquLUvHeeovSwLO0CZ3xcltZNO4Fck=
golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c=
golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o=
golang.org/x/net v0.60.0 h1:79p50tfZlm0J9YfoDsSi639qSXNGVwEzOPLCxM2FsYU=
golang.org/x/net v0.60.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg=
golang.org/x/crypto v0.58.0 h1:COkYLr4k7nDI4r6QtMML2AfzeIswWHAJthLS6K/M/54=
golang.org/x/crypto v0.58.0/go.mod h1:Xh+kl5A+M0gMiWDytH2Hhr5Z7WbNCpv/eB/EFgfSk+w=
golang.org/x/exp v0.0.0-20261013213113-2ab7f3cbc5fb h1:fMK59tNbIKghD6eTnk7DGfVtbK6JiHiFgpmBAWcPaco=
golang.org/x/exp v0.0.0-20261013213113-2ab7f3cbc5fb/go.mod h1:DBoxwWhjaW8DJJw/YeM4zpeOKMC1FMXSblsYy+1mFSw=
golang.org/x/mod v0.42.0 h1:ICeL3t2L30ljSPHHxDnR4fqVcBt/zR2zJAb9juavmQg=
golang.org/x/mod v0.42.0/go.mod h1:u5fzIrRInkL8MaO1cbRkUHT64v303YIT5KEqpNr7jRs=
golang.org/x/net v0.61.0 h1:RR+6j/BTBCrggOLugxa+66R8FvoN6MHlzDlZIbN9YFw=
golang.org/x/net v0.61.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI=
golang.org/x/oauth2 v0.37.0 h1:JUlcxA8oAtauLfiH8FX2/FkAWHAdi0QtGCGc+hofE98=
golang.org/x/oauth2 v0.37.0/go.mod h1:IxwZNxUULJmpBFf9K/9NTMSIfZZuvuTy1gGxhigP/58=
golang.org/x/sync v0.23.0 h1:KameEIfc1IkluZyXWLn39Wd4tURc6GbCiISGiZm2bQk=
golang.org/x/sync v0.23.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sync v0.24.0 h1:iqiDrGoDgyuvAKrhLQthUEzU/R378N78gXbBjxed7oA=
golang.org/x/sync v0.24.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
golang.org/x/term v0.46.0 h1:3+OXuTbaKDgwk8jTi3aSLHRlmWqHEUDUtxnbFigO4YE=
golang.org/x/term v0.46.0/go.mod h1:+K02xbkittuwc0Am4abfA3Fc+XRGXkvBXNO88NCXPoc=
golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI=
golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E=
golang.org/x/sys v0.49.0 h1:XbzkgYJHdqh/8m2Uu0W/dQv8nktxx4BFHp1M0gROTXA=
golang.org/x/sys v0.49.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
golang.org/x/term v0.47.0 h1:cpyOwQkr2Nzxe2p6KnrTG7Ei2wtzjsuSjhpXXepZ/BM=
golang.org/x/term v0.47.0/go.mod h1:efAfAuG6RKABvg1ArGebRkvX6LXul14SM67o2e4mUCY=
golang.org/x/text v0.43.0 h1:1QivrlhwAsnMOcqgOdl9my7s9OyZl8O5/UGUTJVXoWc=
golang.org/x/text v0.43.0/go.mod h1:hbSIYA/amXcRXTFSZqh8tWHEoqRvvbKPJ2uz/KU+a+s=
golang.org/x/time v0.16.0 h1:vMb6ptszcQMkcwiRTAuNNU50gom6++Q/6gY2hDM6VDE=
golang.org/x/time v0.16.0/go.mod h1:rVKOqvZeKvrDKTQiAHJ7wmwP0RzleSphoEA9RcdLA0s=
golang.org/x/tools v0.51.0 h1:k4Xc/1Om9jwkBJBo4NVLMSARBoWtK10mx+W5BnXCeAI=
golang.org/x/tools v0.51.0/go.mod h1:9eEncMayCV6zRMGhR5eZEC2iBx98qWcF1HZ9Z7wJOoA=
golang.org/x/tools v0.52.0 h1:ryxg4U63oaUYk7uOLTF37n43f4qgtGvqV4Ioit1BaEs=
golang.org/x/tools v0.52.0/go.mod h1:ItcP5UNaVGG+Yc4eIYmaFLNJ4soEopkx5Y2d4lcEurs=
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
google.golang.org/genproto/googleapis/api v0.0.0-20261005182115-fad411399dd8 h1:cFbkNigDInw+wVTXc+CyhUsoHGJCw0BR6mlNoRVfre0=
google.golang.org/genproto/googleapis/api v0.0.0-20261005182115-fad411399dd8/go.mod h1:QK6p7IgD7IZEZJBhhSUCib5X2vMOzlrGCGUw2XyVDh0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20261005182115-fad411399dd8 h1:0SXBqli5dnuCKMjI/X3FM226zEaEa0GUcSCJtN1vL2o=
google.golang.org/genproto/googleapis/rpc v0.0.0-20261005182115-fad411399dd8/go.mod h1:OaIUM3+LpYcK2GXM4FTmhWoIq371Owdr+Cc7/BsYHHc=
google.golang.org/genproto/googleapis/api v0.0.0-20261012220534-4341edf3f941 h1:DS/w3N8rsfrwxwgGSj6WhMsPo7aNQGmDx74J81zd0NQ=
google.golang.org/genproto/googleapis/api v0.0.0-20261012220534-4341edf3f941/go.mod h1:AuGAdi9KnXss7xbLxIKhCvk+Ro/SxpET/iS45DNYN+M=
google.golang.org/genproto/googleapis/rpc v0.0.0-20261012220534-4341edf3f941 h1:QG6hS4zFplRZvOQedzei4t2pT/zkQc3VR1u+S9/rcAw=
google.golang.org/genproto/googleapis/rpc v0.0.0-20261012220534-4341edf3f941/go.mod h1:OaIUM3+LpYcK2GXM4FTmhWoIq371Owdr+Cc7/BsYHHc=
google.golang.org/grpc v1.86.0-dev h1:FLq7hcApuJeJ70J9+k0FvmXsNCwS8B2/MeAfYdy3GHY=
google.golang.org/grpc v1.86.0-dev/go.mod h1:Ovl0ECo4xx5r4kn/6d4BPSNB7OIFuu6EAjOzjtVAKaM=
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
@@ -318,15 +277,15 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
modernc.org/libc v1.77.1 h1:Ct8j47QtiZ1Enj2DtFXQtUqrPCAjdCmPjtCuvrYQ0Hs=
modernc.org/libc v1.77.1/go.mod h1:87/pZ4L6nD1zqW4nItuS12YO7hN1igAah34xjnQo/W0=
modernc.org/libc v1.78.0 h1:Lpm+e9K6ruVYEGwWfuBO1xXtYEaXDouFOG1SuWjFDP4=
modernc.org/libc v1.78.0/go.mod h1:wvxR55nOF2/66NkJoNV7/coXBTCvT3HR22rcqW6lOuA=
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
modernc.org/memory v1.12.1 h1:nFMiWrpStgZczNl6XI9GnIk/rWhYIyHGUaR04pGbp9g=
modernc.org/memory v1.12.1/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
modernc.org/sqlite v1.59.0 h1:X1es1GpqBlS/5T+vbM4HLUdaa8OtQx468DF2vrx+38A=
modernc.org/sqlite v1.59.0/go.mod h1:+paeT2A3iPRHkQDwG7oA6Tk0zQd5woMEI8q7orfry8k=
oras.land/oras-go/v2 v2.6.2 h1:N04RXngAp1LJKTG6ifz3xHPipasEkWr+hFmInja5YKo=
oras.land/oras-go/v2 v2.6.2/go.mod h1:PlTtg4JTDJkDe8yVHpM2wz7/YDc00GVas+i4jAW2TZ4=
modernc.org/sqlite v1.60.1 h1:/blz53O951KWFOso4QQvEs/Fq6cDBKLtMVrYNSeJVKw=
modernc.org/sqlite v1.60.1/go.mod h1:1dIoEagfDE72QytD5scH1lxARtaUgKgHC/NuApA27r0=
oras.land/oras-go/v2 v2.6.3 h1:72z4K9YiDKVB5jieM8cuB1WSVnbZkkD2hd+NmO3HYVI=
oras.land/oras-go/v2 v2.6.3/go.mod h1:imXEFiYkTZUVVYkfv/r5GVmWeiLkGtNQA8FU4F/sjKs=
pgregory.net/rapid v1.2.0 h1:keKAYRcjm+e1F0oAuU5F5+YPAWcyxNNRK2wud503Gnk=
pgregory.net/rapid v1.2.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
+5 -6
View File
@@ -10,7 +10,7 @@
set -euo pipefail
REPO="samcharles93/archie-core"
REPO="samcharles93/archie-releases"
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-${HOME}/.config}"
XDG_DATA_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}"
@@ -89,8 +89,8 @@ fi
mkdir -p "${ARCHIE_CONFIG_DIR}" "${ARCHIE_DATA_DIR}" "${ARCHIE_BIN_DIR}"
# 2. Binaries. STAGE ends up holding the binaries, release.json and the
# updater scripts, whichever way they were obtained.
# 2. Binaries. STAGE ends up holding the binaries and release.json, whichever
# way they were obtained.
TMP="$(mktemp -d)"
trap 'rm -rf "${TMP}"' EXIT
@@ -111,7 +111,7 @@ if [ "${FROM_SOURCE}" = true ]; then
for cmd in $(jq -er '.required_topology.units | join(" ")' "${SRC_DIR}/release.json"); do
(cd "${SRC_DIR}" && go build -ldflags "${LDFLAGS}" -o "${STAGE}/${cmd}" "./cmd/${cmd}")
done
cp "${SRC_DIR}/release.json" "${SRC_DIR}"/scripts/archie-update-* "${STAGE}/"
cp "${SRC_DIR}/release.json" "${STAGE}/"
else
if [ -z "${VERSION}" ]; then
tag="$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p')"
@@ -137,8 +137,7 @@ TOPOLOGY_UNITS="$(tr -d '\n' <"${STAGE}/release.json" | sed -n 's/.*"units": *\[
for cmd in ${TOPOLOGY_UNITS}; do
install -m755 "${STAGE}/${cmd}" "${ARCHIE_BIN_DIR}/${cmd}"
done
install -m755 "${STAGE}"/archie-update-* "${ARCHIE_BIN_DIR}/"
echo " Installed ${TOPOLOGY_UNITS} and the updater to ${ARCHIE_BIN_DIR}/"
echo " Installed ${TOPOLOGY_UNITS} to ${ARCHIE_BIN_DIR}/"
# 3. Configuration. archied setup asks every question and writes config.toml
# plus any secrets to the env file beside it; this script asks nothing itself.
+5 -3
View File
@@ -254,16 +254,18 @@ func invoke(ctx context.Context, workspace string, h *agentrun.HarnessSpec, argv
return err
}
var stderr tailBuffer
cmd.Stderr = &stderr
cmd.Stderr = io.MultiWriter(&stderr, os.Stderr)
if err := cmd.Start(); err != nil {
return fmt.Errorf("start harness: %w", err)
}
scanner := bufio.NewScanner(stdout)
// Keep the raw harness activity visible in the container's live output.
output := io.TeeReader(stdout, os.Stdout)
scanner := bufio.NewScanner(output)
scanner.Buffer(make([]byte, 64*1024), 16*1024*1024)
for scanner.Scan() {
out.Line(scanner.Bytes(), report)
}
_, _ = io.Copy(io.Discard, stdout)
_, _ = io.Copy(io.Discard, output)
if err := cmd.Wait(); err != nil {
if ctx.Err() != nil {
return ctx.Err()
+41
View File
@@ -0,0 +1,41 @@
//go:build unix
package agentexec
import (
"os"
"os/exec"
"strings"
"testing"
"github.com/samcharles93/archie-core/internal/domain/agentrun"
)
func TestHarnessLiveOutput(t *testing.T) {
if os.Getenv("ARCHIE_TEST_HARNESS_OUTPUT") == "1" {
adapter := &codexHarnessOutput{}
user := ""
if os.Geteuid() == 0 {
user = "65534"
}
err := invoke(t.Context(), "/tmp", &agentrun.HarnessSpec{User: user}, []string{"sh", "-c", `printf '%s\n' '{"type":"thread.started","thread_id":"live-thread"}'; printf '%s\n' 'live diagnostic' >&2`}, adapter, nil)
if err != nil {
t.Fatal(err)
}
if adapter.SessionID() != "live-thread" {
t.Fatal("forwarding lost the adapter input")
}
return
}
cmd := exec.CommandContext(t.Context(), os.Args[0], "-test.run=^TestHarnessLiveOutput$")
cmd.Env = append(os.Environ(), "ARCHIE_TEST_HARNESS_OUTPUT=1")
got, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("harness: %v: %s", err, got)
}
for _, want := range []string{"live-thread", "live diagnostic"} {
if !strings.Contains(string(got), want) {
t.Errorf("worker output %q is missing %q", got, want)
}
}
}
+13 -4
View File
@@ -267,10 +267,7 @@ func runTask(ctx context.Context, req taskrun.Request, dependencies taskDependen
Log: log,
Guardrails: dependencies.guardrails,
}
// pr-review reads the PR data the daemon prefetched into workDir.
if req.Task.Workflow == "pr-review" {
tc.PRSource = prsource.NewFromMount(filepath.Join(workDir, prsource.PrefetchDirName))
}
configureTaskContext(tc, workDir)
if req.Repo.PersistentStorage {
memory, readErr := readProjectMemory(storage.MemoryPath)
@@ -292,6 +289,18 @@ func runTask(ctx context.Context, req taskrun.Request, dependencies taskDependen
}, nil
}
// configureTaskContext applies what the task's kind changes about its context:
// a test run writes nothing to a forge, and pr-review reads the PR data the
// daemon prefetched into workDir.
func configureTaskContext(tc *workflow.TaskContext, workDir string) {
if tc.Task.IsTestRun() {
workflow.SuppressForgeWrites(tc)
}
if tc.Task.Workflow == "pr-review" {
tc.PRSource = prsource.NewFromMount(filepath.Join(workDir, prsource.PrefetchDirName))
}
}
// CompilePinnedWorkflow compiles the definition the request carries. With
// none, it pins one from the shipped definitions onto req and req.Task.
func CompilePinnedWorkflow(req *taskrun.Request, steps *workflow.Manager) (workflow.Workflow, error) {
+3
View File
@@ -50,6 +50,8 @@ type Settings struct {
// NATS storerpc path is deleted.
StateStoreTarget string
StateStoreToken string
// StateStoreCA is the PEM CA the State Store's certificate chains to.
StateStoreCA []byte
// ModelProxy, ModelProxyHosts and ModelProxyCA route model provider
// requests through the daemon's egress proxy, which holds the keys.
@@ -148,6 +150,7 @@ func run(ctx context.Context, settings Settings, log *slog.Logger, dependencies
TaskID: taskID,
StateStoreURL: settings.StateStoreTarget,
StateStoreToken: settings.StateStoreToken,
StateStoreCA: settings.StateStoreCA,
}, log)
if err != nil {
operation := "nats connect failed"
+349
View File
@@ -0,0 +1,349 @@
package archied
import (
"context"
"fmt"
"maps"
"net/http"
"slices"
"strings"
"sync"
"time"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/alert"
"github.com/samcharles93/archie-core/internal/domain/org"
"github.com/samcharles93/archie-core/internal/infrastructure/alertwebhook"
"github.com/samcharles93/archie-core/internal/infrastructure/controlplanerpc"
"github.com/samcharles93/archie-core/internal/infrastructure/modelcatalog"
"github.com/samcharles93/archie-core/internal/releaseupdate"
)
const (
// deliveryInterval is how often due webhook deliveries are claimed.
deliveryInterval = 15 * time.Second
// releaseCheckInterval is how often GitHub is asked for a newer release.
releaseCheckInterval = 6 * time.Hour
// alertCallTimeout bounds one check's calls to the State Store.
alertCallTimeout = 20 * time.Second
// credentialReportEvery is how long an unchanged credential state goes
// unreported, so the egress path does not call the State Store per request.
credentialReportEvery = 10 * time.Minute
)
// alertChecks raises the alerts that have no transition to hang on: the
// daemon's configuration and the release channel. Each check lists what it
// owns, so alerts from before a restart are still cleared once fixed.
type alertChecks struct {
store alert.Store
log func(msg string, args ...any)
cfg func() config.Config
// catalog is the models the providers currently offer.
catalog func() modelcatalog.Snapshot
// release is the newest release the update channel offers.
release func(context.Context) (releaseupdate.Snapshot, error)
}
func (c alertChecks) reporter() alert.Reporter {
return alert.Reporter{Raiser: c.store, By: "archied"}
}
// sync makes the open alerts of kind in orgID match active: it raises each
// input and resolves the alerts, snoozed or open, whose condition cleared.
func (c alertChecks) sync(ctx context.Context, orgID org.OrgID, kind string, active []alert.Input) {
reporter := c.reporter()
subjects := make([]string, 0, len(active))
for _, in := range active {
reporter.Raise(ctx, in)
subjects = append(subjects, in.Subject)
}
existing, err := c.store.ListAlerts(ctx, orgID, alert.Filter{States: []alert.State{alert.StateOpen, alert.StateDismissed}, Limit: 500})
if err != nil {
c.log("alerts not checked", "kind", kind, "err", err)
return
}
for _, a := range existing {
if a.Kind == kind && a.Condition && !slices.Contains(subjects, a.Subject) {
reporter.Resolve(ctx, a.Key)
}
}
}
// checkConfig raises the alerts the effective configuration implies: a
// missing or dangling model alias, and providers and granted services with no
// usable credential.
func (c alertChecks) checkConfig(ctx context.Context) {
cfg := c.cfg()
c.sync(ctx, org.DefaultOrgID, alert.KindModelAlias, modelAliasAlerts(cfg.Models, c.catalog()))
c.sync(ctx, org.DefaultOrgID, alert.KindProviderNoKey, providerAlerts(cfg.Providers))
unbound := unboundAlerts(cfg)
for _, orgID := range credentialOrgs(cfg) {
c.sync(ctx, orgID, alert.KindToolNoBinding, unbound[orgID])
}
}
func modelAliasAlerts(aliases map[string]string, catalog modelcatalog.Snapshot) []alert.Input {
var out []alert.Input
input := func(alias, title, body string) alert.Input {
return alert.Input{
Org: org.DefaultOrgID, Kind: alert.KindModelAlias, Subject: "alias:" + alias,
Severity: alert.SeverityAction, Condition: true, Title: title, Body: body, Link: "/settings/models",
}
}
if strings.TrimSpace(aliases[config.DefaultModelAlias]) == "" {
out = append(out, input(config.DefaultModelAlias, "No default model alias is set",
"Set it to a model."))
}
for _, alias := range slices.Sorted(maps.Keys(aliases)) {
providerID, modelID, ok := strings.Cut(aliases[alias], "/")
if !ok {
continue
}
offered := catalogModels(catalog, providerID)
// A provider the catalogue does not list is a credential problem, not
// a retired model.
if len(offered) > 0 && !slices.Contains(offered, modelID) {
out = append(out, input(alias, fmt.Sprintf("Model alias %q points at a model that no longer exists", alias),
fmt.Sprintf("The %s provider no longer offers the model this alias names. Choose another model.", providerID)))
}
}
return out
}
func catalogModels(catalog modelcatalog.Snapshot, providerID string) []string {
for _, provider := range catalog.Providers {
if provider.ID == providerID {
ids := make([]string, len(provider.Models))
for i, model := range provider.Models {
ids[i] = model.ID
}
return ids
}
}
return nil
}
func providerAlerts(providers map[string]config.Provider) []alert.Input {
var out []alert.Input
for _, name := range slices.Sorted(maps.Keys(providers)) {
if !providers[name].Disabled {
continue
}
out = append(out, alert.Input{
Org: org.DefaultOrgID, Kind: alert.KindProviderNoKey, Subject: "provider:" + name,
Severity: alert.SeverityAction, Condition: true,
Title: fmt.Sprintf("Provider %q has no usable credential", name),
Body: "Key unresolved; its models cannot run. Check the binding.",
Link: "/settings/credential-bindings",
})
}
return out
}
// credentialOrgs are the orgs whose identities are granted credentials, the
// instance org always among them.
func credentialOrgs(cfg config.Config) []org.OrgID {
orgs := []org.OrgID{org.DefaultOrgID}
for _, name := range append([]string{""}, identityNames(cfg)...) {
orgName, _ := cfg.CredentialAccess(name)
if id := org.OrgID(credentialOrg(orgName)); !slices.Contains(orgs, id) {
orgs = append(orgs, id)
}
}
return orgs
}
func identityNames(cfg config.Config) []string {
names := make([]string, 0, len(cfg.Identities))
for _, id := range cfg.Identities {
names = append(names, id.Name)
}
return names
}
func credentialOrg(name string) string {
if name == "" {
return string(org.DefaultOrgID)
}
return name
}
// unboundAlerts are the granted services with no credential binding in the
// granting identity's org, by org. A model provider needs no binding of its
// own here: its key is the provider's.
func unboundAlerts(cfg config.Config) map[org.OrgID][]alert.Input {
out := map[org.OrgID][]alert.Input{}
seen := map[alert.Key]bool{}
for _, name := range append([]string{""}, identityNames(cfg)...) {
orgName, granted := cfg.CredentialAccess(name)
orgID := org.OrgID(credentialOrg(orgName))
bound := cfg.Containers.BoundCredentials(orgName, granted, granted)
for _, service := range granted {
key := alert.Key{Org: orgID, Kind: alert.KindToolNoBinding, Subject: "service:" + service}
if _, ok := cfg.Providers[service]; ok || bound[service].Service != "" || seen[key] {
continue
}
seen[key] = true
out[orgID] = append(out[orgID], alert.Input{
Key: key, Severity: alert.SeverityAction, Condition: true,
Title: fmt.Sprintf("%q is granted but has no credential binding", service),
Body: "Runs cannot authenticate. Bind a credential.",
Link: "/settings/credential-bindings",
})
}
}
return out
}
// checkRelease raises an info alert while the update channel offers a newer
// release. A failed check changes nothing: the next one decides.
func (c alertChecks) checkRelease(ctx context.Context) {
snapshot, err := c.release(ctx)
if err != nil {
c.log("release check failed", "err", err)
return
}
var active []alert.Input
if available := snapshot.Available(); len(available) > 0 {
parts := make([]string, len(available))
for i, component := range available {
parts[i] = fmt.Sprintf("%s %s", component.Label, component.Available)
}
active = append(active, alert.Input{
Org: org.DefaultOrgID, Kind: alert.KindReleaseAvailable, Subject: "release",
Severity: alert.SeverityInfo, Condition: true,
Title: "Newer release available", Body: "Available: " + strings.Join(parts, ", ") + ".",
Link: "/settings/status",
})
}
c.sync(ctx, org.DefaultOrgID, alert.KindReleaseAvailable, active)
}
// every runs fn now and then each interval until ctx ends.
func every(ctx context.Context, interval time.Duration, fn func(context.Context)) {
ticker := time.NewTicker(interval)
defer ticker.Stop()
for {
callCtx, cancel := context.WithTimeout(ctx, alertCallTimeout)
fn(callCtx)
cancel()
select {
case <-ctx.Done():
return
case <-ticker.C:
}
}
}
// startAlerts starts the daemon's alert checks and the webhook delivery loop.
// The State Store being away costs the checks a tick, nothing else.
func (b *boot) startAlerts(ctx context.Context) {
client, ok := b.stateStore.(alert.Store)
if !ok {
return
}
reader := controlplanerpc.NewRPCClient(b.controlPlaneRPC)
catalog := controlplanerpc.UpdateService(reader, "").Catalog
checks := alertChecks{
store: client, log: b.log.Warn, cfg: b.cfgHolder.Get, catalog: b.catalogState,
release: func(ctx context.Context) (releaseupdate.Snapshot, error) { return catalog.Check(ctx) },
}
b.alertChecks = &checks
go every(ctx, releaseCheckInterval, checks.checkRelease)
go every(ctx, deliveryInterval, b.deliverAlerts(client))
checks.checkConfig(ctx)
}
// recheckAlerts re-evaluates the configuration alerts after the configuration
// changed. It never blocks the change that caused it.
func (b *boot) recheckAlerts(ctx context.Context) {
checks := b.alertChecks
if checks == nil {
return
}
go func() {
ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), alertCallTimeout)
defer cancel()
checks.checkConfig(ctx)
}()
}
// deliverAlerts sends due webhook deliveries. A delivery the webhook is not
// configured for, or whose alert is below the severity threshold, is closed
// as skipped; one that fails is retried by the store on its schedule.
func (b *boot) deliverAlerts(store alert.Deliverer) func(context.Context) {
client := &http.Client{Timeout: 15 * time.Second}
return func(ctx context.Context) {
due, err := store.ClaimAlertDeliveries(ctx, 20)
if err != nil {
b.log.Warn("alert deliveries not claimed", "err", err)
return
}
notify := b.cfgHolder.Get().Notify
for _, d := range due {
outcome := alert.Outcome{DeliveryID: d.ID}
threshold := alert.Severity(notify.MinSeverity)
if !threshold.Valid() {
threshold = alert.SeverityWarning
}
if notify.Webhook == "" || d.Alert.Severity.Rank() < threshold.Rank() {
outcome.Skipped = true
} else {
secret := ""
if notify.Secret != (config.SecretRef{}) {
secret, err = b.secrets.Resolve(notify.Secret)
}
if err != nil {
outcome.Error = "notify secret could not be resolved"
} else {
outcome = alertwebhook.Send(ctx, client, notify.Webhook, secret, d)
}
}
if err := store.RecordAlertAttempt(ctx, outcome); err != nil {
b.log.Warn("alert delivery not recorded", "delivery", d.ID, "err", err)
}
}
}
}
// credentialWatch raises an alert when a bound credential cannot be resolved
// and clears it once it can. The egress path calls observe per request, so an
// unchanged state is reported at most every credentialReportEvery.
type credentialWatch struct {
reporter alert.Reporter
mu sync.Mutex
last map[alert.Key]credentialState
}
type credentialState struct {
rejected bool
at time.Time
}
func (w *credentialWatch) observe(ctx context.Context, orgName, service string, rejected bool) {
if w == nil {
return
}
key := alert.Key{Org: org.OrgID(credentialOrg(orgName)), Kind: alert.KindCredentialInvalid, Subject: "service:" + service}
w.mu.Lock()
if w.last == nil {
w.last = map[alert.Key]credentialState{}
}
previous, known := w.last[key]
if known && previous.rejected == rejected && time.Since(previous.at) < credentialReportEvery {
w.mu.Unlock()
return
}
w.last[key] = credentialState{rejected: rejected, at: time.Now()}
w.mu.Unlock()
go func() {
ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), alertCallTimeout)
defer cancel()
w.reporter.Sync(ctx, rejected, alert.Input{
Key: key, Severity: alert.SeverityAction, Condition: true,
Title: fmt.Sprintf("The credential bound to %q is not working", service),
Body: "Secret unresolved; runs cannot authenticate. Check the binding.",
Link: "/settings/credential-bindings",
})
}()
}
+42 -14
View File
@@ -32,6 +32,7 @@ import (
"github.com/samcharles93/archie-core/internal/daemon"
"github.com/samcharles93/archie-core/internal/domain/access"
"github.com/samcharles93/archie-core/internal/domain/agent"
"github.com/samcharles93/archie-core/internal/domain/alert"
"github.com/samcharles93/archie-core/internal/domain/applystatus"
"github.com/samcharles93/archie-core/internal/domain/health"
"github.com/samcharles93/archie-core/internal/domain/identity"
@@ -66,9 +67,10 @@ import (
// reverse at shutdown, matching the LIFO ordering of the deferred calls
// they replace.
type boot struct {
catalog *modelcatalog.Catalog
cfg config.Config
log *slog.Logger
catalog *modelcatalog.Catalog
cfg config.Config
log *slog.Logger
playbooks *controlplane.LivePlaybooks
// stderrLog keeps setupLogging on stderr, never touching cfg.Log.File. An
// offline command reads the bootstrap config but is not the daemon: creating
@@ -106,7 +108,6 @@ type boot struct {
// (daemon.RunCredentialIssuer), wrapping the same *staterpc.Client as
// stateStore, which also verifies a credential for a worktree push.
stateStoreGrants *staterpc.GrantIssuer
stateStoreToken string
controlPlane *controlplane.Client
// controlPlaneRPC is the State Store's control-plane transport, kept so the
// daemon root can build its workflow-definitions client from it
@@ -201,6 +202,13 @@ type boot struct {
// signal path rather than inventing a new one.
shutdown context.CancelFunc
// alertChecks re-evaluates the configuration alerts when the configuration
// changes. Nil until the daemon's run loop starts them.
alertChecks *alertChecks
// credentialWatch reports bound credentials that stop resolving. Nil
// when the State Store has no alert surface.
credentialWatch *credentialWatch
cleanups []func()
}
@@ -264,18 +272,20 @@ func (b *boot) openStateStoreAdapter(ctx context.Context) error {
if target == "" {
return fmt.Errorf("services.state.target is required: archied/archie-gateway no longer own archie.db; the standalone archie-state-store process owns it (docs/prds/state-store-contract.md §12 step 7)")
}
client, cleanup, err := servicekit.StateStoreClient(presence.Daemon, b.cfg.Services, b.secrets)
client, cleanup, err := servicekit.StateStoreClient(presence.Daemon, b.cfg)
if err != nil {
b.log.Error("state store adapter", "err", err)
return err
}
b.stateStore = client
if alerts, ok := b.stateStore.(alert.Store); ok {
b.credentialWatch = &credentialWatch{reporter: alert.Reporter{Raiser: alerts, Log: b.log, By: "archied"}}
}
b.taskModels = client
b.controlPlaneRPC = client.ControlPlane()
b.controlPlane = controlplane.NewRPCClient(b.controlPlaneRPC)
b.applyStatus = applystatus.New(b.processName, client, b.log)
b.stateStoreGrants = &staterpc.GrantIssuer{Client: client}
b.stateStoreToken = b.cfg.Services.ResolvedToken(config.ServiceNameState, b.secrets.Getenv)
b.addCleanup(cleanup)
b.startSecretEngines(ctx, client)
return nil
@@ -466,13 +476,13 @@ func (b *boot) setupContainers(ctx context.Context) func() {
// only enqueues the chat tasks scheduled workflows create.
func (b *boot) setupGatewayClient(ctx context.Context) error {
b.setupChatTasks(b.cfg)
contract, cleanup, err := composeChatContract(b.cfg.Services, b.secrets)
contract, cleanup, err := composeChatContract(b.cfg)
if err != nil {
return err
}
b.addCleanup(cleanup)
b.chat = &webui.ChatService{Contract: contract}
messaging, closeMessaging, err := composeMessaging(b.cfg.Services, b.secrets)
messaging, closeMessaging, err := composeMessaging(b.cfg)
if err != nil {
return err
}
@@ -568,7 +578,7 @@ func (b *boot) buildDaemon() {
b.d = &daemon.Daemon{
Cfg: b.cfgHolder,
ConnectedNATS: daemon.NATSEndpoint{URL: b.natsURL, Token: b.natsToken, Scoped: b.cfg.NATS.Mode != config.NATSModeExternal},
ConnectedStateStore: daemon.StateStoreEndpoint{URL: strings.TrimSpace(b.cfg.Services.Get(config.ServiceNameState).Target), Token: b.stateStoreToken},
ConnectedStateStore: daemon.StateStoreEndpoint{URL: strings.TrimSpace(b.cfg.Services.Get(config.ServiceNameState).Target), CA: b.stateStoreCA()},
Store: b.stateStore,
Bus: b.bus,
Forge: b.forgeClient,
@@ -680,14 +690,16 @@ func (b *boot) publishConfig(ctx context.Context, cfg config.Config) {
// The daemon owns the published configuration view.
if b.processName != applystatus.Gateway {
b.publishConfigSnapshot(ctx)
b.recheckAlerts(ctx)
}
}
func (b *boot) configViewInput() webui.ConfigViewInput {
catalog := b.catalogState()
in := webui.ConfigViewInput{
Config: b.cfgHolder.Get(),
Catalog: catalogView(catalog),
Config: b.cfgHolder.Get(),
Catalog: catalogView(catalog),
SecretEngines: b.secrets.List(),
}
if b.lastReload != nil {
status := b.lastReload()
@@ -785,6 +797,7 @@ func (b *boot) runLoop(ctx context.Context, once bool) error {
b.log.Info("archied running", "repos", len(b.cfg.Repos), "poll", b.cfg.PollInterval.Std().String(), "label", b.cfg.Label)
b.startDrainMonitor(ctx)
b.startWatchdog(ctx)
b.startAlerts(ctx)
if err := b.d.Run(ctx); err != nil && ctx.Err() == nil {
b.log.Error("daemon exited", "err", err)
return err
@@ -850,7 +863,22 @@ func (b *boot) startModelCatalogRefresh(ctx context.Context) {
}
func (b *boot) livePlaybooks() *controlplane.LivePlaybooks {
live := controlplane.NewLivePlaybooks(b.controlPlaneRPC, b.log)
live.ApplyStatus = b.applyStatus
return live
b.playbooks = controlplane.NewLivePlaybooks(b.controlPlaneRPC, b.log)
b.playbooks.ApplyStatus = b.applyStatus
return b.playbooks
}
// playbookRefreshInterval is how often archied re-reads the resources it
// would otherwise load only on first use, so their apply status stays reported.
const playbookRefreshInterval = 30 * time.Second
// stateStoreCA is the CA a task container verifies the State Store with;
// nil without [tls].
func (b *boot) stateStoreCA() []byte {
id, err := servicekit.Identity(b.cfg.TLS, presence.Daemon)
if err != nil {
b.log.Warn("state store CA for containers", "err", err)
return nil
}
return id.CAPEM()
}
+17 -11
View File
@@ -3,27 +3,29 @@ package archied
import (
"google.golang.org/grpc"
"github.com/samcharles93/archie-core/internal/app/servicekit"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/presence"
"github.com/samcharles93/archie-core/internal/gateway"
"github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc"
"github.com/samcharles93/archie-core/internal/infrastructure/messagingrpc"
"github.com/samcharles93/archie-core/internal/secret"
)
// composeChatContract dials the standalone archie-gateway, the sole owner of
// ChatContract, from the daemon's own configuration key. Token resolution is
// the daemon's (it owns the config keys and the secret registry); the dial
// itself and the fail-closed non-loopback rule belong to the transport, so
// they come from gatewayrpc.Dial.
func composeChatContract(services config.Services, secrets *secret.Registry, options ...grpc.DialOption) (gateway.ChatContract, func(), error) {
target, err := services.RequireTarget(config.ServiceNameGateway)
// ChatContract, from the daemon's own configuration key.
func composeChatContract(cfg config.Config, options ...grpc.DialOption) (gateway.ChatContract, func(), error) {
target, err := cfg.Services.RequireTarget(config.ServiceNameGateway)
if err != nil {
return nil, nil, err
}
id, err := servicekit.Identity(cfg.TLS, presence.Daemon)
if err != nil {
return nil, nil, err
}
// Assigned through a typed variable rather than returned directly: a
// direct forward would hand a failed dial's nil *Client back as a
// non-nil ChatContract interface.
client, cleanup, err := gatewayrpc.Dial(target, services.ResolvedToken(config.ServiceNameGateway, secrets.Getenv), options...)
client, cleanup, err := gatewayrpc.Dial(target, id, options...)
if err != nil {
return nil, nil, err
}
@@ -32,10 +34,14 @@ func composeChatContract(services config.Services, secrets *secret.Registry, opt
// composeMessaging builds the Messaging Service client. The connection is
// lazy, so an absent Messaging Service fails each delivery, not the daemon.
func composeMessaging(services config.Services, secrets *secret.Registry) (*messagingrpc.Client, func(), error) {
target, err := services.RequireTarget(config.ServiceNameMessaging)
func composeMessaging(cfg config.Config) (*messagingrpc.Client, func(), error) {
target, err := cfg.Services.RequireTarget(config.ServiceNameMessaging)
if err != nil {
return nil, nil, err
}
return messagingrpc.Dial(target, services.ResolvedToken(config.ServiceNameMessaging, secrets.Getenv))
id, err := servicekit.Identity(cfg.TLS, presence.Daemon)
if err != nil {
return nil, nil, err
}
return messagingrpc.Dial(target, id)
}
+1 -1
View File
@@ -24,7 +24,7 @@ func (b *boot) runtimeConfig(ctx context.Context, base config.Config) (config.Co
if settings := b.executionSettings.Load(); settings != nil {
applyExecutionBudgets(cfg, *settings)
}
})
}, nil)
}
func (b *boot) loadRuntimeConfig(ctx context.Context) error {
+41 -14
View File
@@ -6,7 +6,6 @@ import (
"io"
"log/slog"
"net"
"os"
"slices"
"sync"
"time"
@@ -17,8 +16,9 @@ import (
"github.com/samcharles93/archie-core/internal/app/servicekit"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/container"
pb "github.com/samcharles93/archie-core/internal/contracts/harness/v1"
"github.com/samcharles93/archie-core/internal/infrastructure/harnessrpc"
"github.com/samcharles93/archie-core/internal/domain/presence"
"github.com/samcharles93/archie-core/internal/infrastructure/harnesssession"
"github.com/samcharles93/archie-core/internal/infrastructure/kitrun"
)
@@ -69,11 +69,13 @@ func (g *sessionGrants) GrantedFor(token string) (string, []string, bool) {
type harnessServer struct {
pb.UnimplementedHarnessServiceServer
sessions *harnesssession.Manager
log *slog.Logger
// runs serves the run target; nil answers Unavailable.
runs *runView
log *slog.Logger
}
// Open dispatches on the first frame's target. Setup sessions are served; the
// run-scoped target is reserved for archie-core-qi91.
// Open dispatches on the first frame's target. Setup sessions open a PTY; a run
// target is a read-only view of the task's running sandbox.
func (h *harnessServer) Open(stream pb.HarnessService_OpenServer) error {
first, err := stream.Recv()
if err != nil {
@@ -90,7 +92,10 @@ func (h *harnessServer) Open(stream pb.HarnessService_OpenServer) error {
}
return h.openSetup(stream, target.GetOrg(), t.Setup.GetProfile(), first.GetSize())
case *pb.OpenTarget_Run:
return status.Error(codes.Unimplemented, "run-scoped sessions are not served yet")
if t.Run.GetTaskId() <= 0 {
return status.Error(codes.InvalidArgument, "the run target names no task")
}
return h.openRun(stream, target.GetOrg(), t.Run)
default:
return status.Error(codes.InvalidArgument, "the target names no session")
}
@@ -183,9 +188,18 @@ func (b *boot) setupHarness(ctx context.Context) {
b.log.Warn("harness sessions disabled", "err", err)
return
}
token := b.cfg.Services.ResolvedToken(config.ServiceNameHarness, os.Getenv)
if token == "" {
b.log.Warn("harness sessions disabled: [services.harness].target_token or HARNESS_TOKEN is required, even on loopback")
id, err := servicekit.Identity(b.cfg.TLS, presence.Daemon)
if err != nil {
b.log.Warn("harness sessions disabled", "err", err)
return
}
if id == nil {
b.log.Warn("harness sessions disabled: a session is a shell holding an org's credential, so it needs [tls] ca_file and cert_dir")
return
}
creds, err := id.ServerOption(listen, false)
if err != nil {
b.log.Warn("harness sessions disabled", "err", err)
return
}
ln, err := (&net.ListenConfig{}).Listen(ctx, "tcp", listen)
@@ -199,11 +213,8 @@ func (b *boot) setupHarness(ctx context.Context) {
Profile: func(name string) (config.AgentProfile, error) { return b.cfgHolder.Get().Containers.Profile(name) },
TTL: setupSessionTTL,
}
srv := grpc.NewServer(
//nolint:contextcheck // grpc.StreamServerInterceptor has no context.Context parameter; the interceptor derives its context from stream.Context()
grpc.StreamInterceptor(harnessrpc.StreamServerInterceptor(token)),
)
pb.RegisterHarnessServiceServer(srv, &harnessServer{sessions: manager, log: b.log})
srv := grpc.NewServer(append(servicekit.ServerLimits(), creds)...)
pb.RegisterHarnessServiceServer(srv, &harnessServer{sessions: manager, runs: b.runView(), log: b.log})
go func() {
if err := srv.Serve(ln); err != nil && !errors.Is(err, grpc.ErrServerStopped) {
b.log.Error("harness listener stopped", "err", err)
@@ -222,3 +233,19 @@ func (b *boot) setupHarness(ctx context.Context) {
}
var _ kitrun.GrantRegistry = (*sessionGrants)(nil)
// runView wires the run target to the task store and the container pool. The
// store is the daemon's own contract client, so a task it cannot read answers
// Unavailable rather than guessing.
func (b *boot) runView() *runView {
if b.stateStore == nil || b.containerPool == nil {
return nil
}
cli := b.containerPool.Client()
return &runView{
tasks: b.stateStore,
follow: func(ctx context.Context, taskID, attempt int64) (io.ReadCloser, error) {
return container.FollowLogs(ctx, cli, kitrun.TaskContainer(taskID, attempt), runTail)
},
}
}
+97
View File
@@ -0,0 +1,97 @@
package archied
import (
"context"
"errors"
"fmt"
"io"
"github.com/containerd/errdefs"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/samcharles93/archie-core/internal/container"
pb "github.com/samcharles93/archie-core/internal/contracts/harness/v1"
"github.com/samcharles93/archie-core/internal/domain/org"
"github.com/samcharles93/archie-core/internal/domain/workflow"
)
// runTail is how much recent output a view opens with, in lines.
const runTail = 200
// taskLookup reads the task a run target names.
type taskLookup interface {
TaskByID(ctx context.Context, id int64) (*workflow.Task, error)
}
// runView resolves a run target to its container and follows its output. It
// is read-only by construction: it holds no exec and no stdin path, so a view
// confers no authority over the container.
type runView struct {
tasks taskLookup
follow func(ctx context.Context, taskID, attempt int64) (io.ReadCloser, error)
}
// open refuses a task the daemon does not know, one that is not running, and
// an attempt that is not the running one. Each refusal states its reason: the
// container is gone with the attempt, so there is nothing to answer
// "unavailable" about.
func (v *runView) open(ctx context.Context, target *pb.RunTarget) (io.ReadCloser, error) {
t, err := v.tasks.TaskByID(ctx, target.GetTaskId())
if err != nil {
return nil, status.Error(codes.Unavailable, "the task store is unavailable: "+err.Error())
}
switch {
case t == nil || t.OrgOrDefault() != string(org.OrgFromContext(ctx)):
return nil, status.Errorf(codes.NotFound, "task %d is unknown", target.GetTaskId())
case t.Status != workflow.StatusRunning:
return nil, status.Errorf(codes.NotFound, "task %d is %s, not running; its sandbox is gone", t.ID, t.Status)
case int64(t.Attempt) != target.GetAttempt():
return nil, status.Errorf(codes.NotFound, "attempt %d is not running; task %d is on attempt %d", target.GetAttempt(), t.ID, t.Attempt)
}
logs, err := v.follow(ctx, t.ID, target.GetAttempt())
if err != nil {
if errdefs.IsNotFound(err) || errors.Is(err, container.ErrNotRunning) {
return nil, status.Errorf(codes.NotFound, "task %d has no running sandbox: %v", t.ID, err)
}
return nil, status.Errorf(codes.Unavailable, "the sandbox view is unavailable: %v", err)
}
return logs, nil
}
// openRun streams a running task's sandbox output until the task's container
// ends or the client leaves. Client frames are ignored: this is the peek, not
// a takeover.
func (h *harnessServer) openRun(stream pb.HarnessService_OpenServer, orgID string, target *pb.RunTarget) error {
if h.runs == nil {
return status.Error(codes.Unavailable, "run-scoped views need the task store and the container pool")
}
logs, err := h.runs.open(org.WithOrg(stream.Context(), org.OrgID(orgID)), target)
if err != nil {
return err
}
defer func() { _ = logs.Close() }()
// An empty frame tells the client the view opened before the sandbox has
// printed anything.
if err := stream.Send(&pb.OpenResponse{Frame: &pb.OpenResponse_Stdout{}}); err != nil {
return err
}
h.log.Info("run view opened", "task", target.GetTaskId(), "attempt", target.GetAttempt())
defer h.log.Info("run view closed", "task", target.GetTaskId(), "attempt", target.GetAttempt())
buf := make([]byte, 32<<10)
for {
n, err := logs.Read(buf)
if n > 0 {
if sendErr := stream.Send(&pb.OpenResponse{Frame: &pb.OpenResponse_Stdout{Stdout: append([]byte(nil), buf[:n]...)}}); sendErr != nil {
return sendErr
}
}
if err != nil {
if err == io.EOF || stream.Context().Err() != nil {
return nil
}
return status.Error(codes.Unavailable, fmt.Sprintf("the sandbox output ended: %v", err))
}
}
}
+65
View File
@@ -0,0 +1,65 @@
package archied
import (
"context"
"errors"
"io"
"strings"
"testing"
"github.com/containerd/errdefs"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
pb "github.com/samcharles93/archie-core/internal/contracts/harness/v1"
"github.com/samcharles93/archie-core/internal/domain/org"
"github.com/samcharles93/archie-core/internal/domain/workflow"
)
type fakeTasks struct {
task *workflow.Task
err error
}
func (f fakeTasks) TaskByID(context.Context, int64) (*workflow.Task, error) { return f.task, f.err }
func TestRunViewOpen(t *testing.T) {
running := &workflow.Task{ID: 7, Status: workflow.StatusRunning, Attempt: 2}
cases := []struct {
name string
tasks fakeTasks
attempt int64
follow error
code codes.Code
reason string
}{
{"running attempt", fakeTasks{task: running}, 2, nil, codes.OK, ""},
{"unknown task", fakeTasks{}, 2, nil, codes.NotFound, "unknown"},
{"finished task", fakeTasks{task: &workflow.Task{ID: 7, Status: workflow.StatusParked, Attempt: 2}}, 2, nil, codes.NotFound, "not running"},
{"earlier attempt", fakeTasks{task: running}, 1, nil, codes.NotFound, "attempt 1 is not running"},
{"container gone", fakeTasks{task: running}, 2, errdefs.ErrNotFound, codes.NotFound, "no running sandbox"},
{"store down", fakeTasks{err: errors.New("dial")}, 2, nil, codes.Unavailable, "unavailable"},
{"other org", fakeTasks{task: &workflow.Task{ID: 7, Org: "other", Status: workflow.StatusRunning, Attempt: 2}}, 2, nil, codes.NotFound, "unknown"},
{"docker down", fakeTasks{task: running}, 2, errors.New("connection refused"), codes.Unavailable, "unavailable"},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
v := &runView{tasks: tc.tasks, follow: func(context.Context, int64, int64) (io.ReadCloser, error) {
if tc.follow != nil {
return nil, tc.follow
}
return io.NopCloser(strings.NewReader("")), nil
}}
rc, err := v.open(org.WithOrg(t.Context(), org.DefaultOrgID), &pb.RunTarget{TaskId: 7, Attempt: tc.attempt})
if got := status.Code(err); got != tc.code {
t.Fatalf("code = %v (%v), want %v", got, err, tc.code)
}
if err != nil && !strings.Contains(err.Error(), tc.reason) {
t.Fatalf("reason %q does not state %q", err, tc.reason)
}
if rc != nil {
_ = rc.Close()
}
})
}
}
+1 -1
View File
@@ -58,7 +58,7 @@ func (b *boot) setupKitLauncher(ctx context.Context) {
// container logs in with, against the live grants and bindings; a setup
// session's token resolves through the session grants instead.
b.sessionGrants = &sessionGrants{}
resolver := runCredentialResolver{runs: b.stateStoreGrants.Client, sessions: b.sessionGrants, models: b.taskModels, config: b.cfgHolder, secrets: b.secrets}
resolver := runCredentialResolver{runs: b.stateStoreGrants.Client, sessions: b.sessionGrants, models: b.taskModels, config: b.cfgHolder, secrets: b.secrets, credentials: b.credentialWatch}
// Without a harness secret store, Register refuses a Kit with a
// required OAuth credential.
oauthStore, _ := b.stateStore.(egress.OAuthStore)
+4 -1
View File
@@ -126,7 +126,7 @@ func Run() int { //nolint:cyclop,funlen // the composition root's setup sequence
return 0
}
if recovering, err := resumeUpdate(context.Background()); err != nil {
if recovering, err := resumeUpdate(context.Background(), args.cfgPath); err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
} else if recovering {
@@ -207,6 +207,9 @@ func Run() int { //nolint:cyclop,funlen // the composition root's setup sequence
}
b.buildDaemon()
b.playbooks.Keep(ctx, playbookRefreshInterval)
b.workflowDefinitions.Keep(ctx, playbookRefreshInterval)
b.controlPlane.KeepSchedules(ctx, playbookRefreshInterval)
b.wireConfigSurfaces(ctx, args.cfgPath, args.overlayPath)
if err := b.startServices(ctx); err != nil {
+1 -1
View File
@@ -98,5 +98,5 @@ type unscopedBroker struct{}
func (unscopedBroker) Name() string { return "nats_credential_scope" }
func (unscopedBroker) Check(context.Context) health.Result {
return health.Result{Status: health.StatusDegraded, Detail: "external NATS: agent containers receive the broker token, which reaches every subject; use the embedded broker to scope them to their task"}
return health.Result{Status: health.StatusDegraded, Detail: "external NATS: containers get a broker token that reaches every subject; use the embedded broker"}
}
@@ -33,12 +33,14 @@ type runCredentialResolver struct {
secrets interface {
Resolve(config.SecretRef) (string, error)
}
// credentials, when set, is told whether each bound secret resolved.
credentials *credentialWatch
}
func (r runCredentialResolver) Resolve(ctx context.Context, credential, service string) (string, error) {
if r.sessions != nil {
if org, services, ok := r.sessions.GrantedFor(credential); ok {
return r.resolveBinding(org, services, service)
return r.resolveBinding(ctx, org, services, service)
}
}
task, err := r.runs.TaskForCredential(ctx, credential)
@@ -53,13 +55,13 @@ func (r runCredentialResolver) Resolve(ctx context.Context, credential, service
if r.isModelProvider(ctx, cfg, task, service) {
granted = append(slices.Clone(granted), service)
}
return r.resolveBinding(org, granted, service)
return r.resolveBinding(ctx, org, granted, service)
}
// resolveBinding resolves service from the org's binding when the run or
// session is granted it. An OAuth binding resolves to the empty string: the
// proxy supplies the org's token set itself.
func (r runCredentialResolver) resolveBinding(org string, granted []string, service string) (string, error) {
func (r runCredentialResolver) resolveBinding(ctx context.Context, org string, granted []string, service string) (string, error) {
cfg := r.config.Get()
binding, ok := cfg.Containers.BoundCredentials(org, granted, []string{service})[service]
if !ok {
@@ -71,7 +73,9 @@ func (r runCredentialResolver) resolveBinding(org string, granted []string, serv
if r.secrets == nil {
return "", egress.ErrUnbound
}
return r.secrets.Resolve(binding.Secret)
value, err := r.secrets.Resolve(binding.Secret)
r.credentials.observe(ctx, org, service, err != nil)
return value, err
}
// isModelProvider reports whether service is a provider the task's models
+1 -1
View File
@@ -76,7 +76,7 @@ func (b *boot) setupScheduling() error {
}
runners[scheduling.KindWorkflow] = workflowRunner
}
router, err := crondelivery.NewRouter(store, runners, cfg.Events)
router, err := crondelivery.NewRouter(store, runners)
if err != nil {
return fmt.Errorf("scheduling: build router: %w", err)
}
+1
View File
@@ -17,5 +17,6 @@ func (b *boot) startSecretEngines(ctx context.Context, client *staterpc.Client)
b.applyStatus.Report(ctx, controlplanerpc.ExtensionSettingsKind, version, err)
}
runner := secretengine.Supervise(ctx, b.secrets, source, b.processName, report, b.log)
runner.OnChange(func() { b.publishConfigSnapshot(ctx) })
b.addCleanup(runner.Close)
}
+1 -2
View File
@@ -12,7 +12,6 @@ import (
"github.com/samcharles93/archie-core/internal/app/servicekit"
"github.com/samcharles93/archie-core/internal/domain/presence"
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
"github.com/samcharles93/archie-core/internal/secret"
)
// RunStatus prints one line per service from the State Store's presence
@@ -31,7 +30,7 @@ func RunStatus(args []string, stdout, stderr io.Writer) int {
fmt.Fprintf(stderr, "archied status: %v\n", err)
return 1
}
client, cleanup, err := servicekit.StateStoreClient(presence.Daemon, doc.Config.Services, secret.NewRegistry())
client, cleanup, err := servicekit.StateStoreClient(presence.Daemon, doc.Config)
if err != nil {
fmt.Fprintf(stderr, "archied status: %v\n", err)
return 1
+199 -43
View File
@@ -7,55 +7,200 @@ import (
"flag"
"fmt"
"io"
"log/slog"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"syscall"
"time"
"github.com/BurntSushi/toml"
"golang.org/x/sys/unix"
"github.com/samcharles93/archie-core/internal/app/servicekit"
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
"github.com/samcharles93/archie-core/internal/releaseupdate"
)
// RunUpdateTopology observes the host using the candidate's topology contract.
func RunUpdateTopology(args []string, out, stderr io.Writer) int {
flags := flag.NewFlagSet("update-topology", flag.ContinueOnError)
// The watchdog's patience: how long the restarted daemon has to report the
// release, and how long it must then stay healthy.
const (
updateHealthTimeout = 60 * time.Second
updateObserve = 120 * time.Second
updatePoll = 3 * time.Second
)
const updateUsage = `usage:
archied update check [-channel stable|next|exact-pin] [-pin version]
archied update install -version X [-config FILE] [-report FILE -channel C -chat ID -thread ID]
archied update watchdog [-config FILE] [-recover]`
// RunUpdate serves `archied update`: check prints the release snapshot,
// install verifies and stages a release and hands it to the watchdog, and
// watchdog switches over, watches the daemon and commits or rolls back.
func RunUpdate(args []string, out, stderr io.Writer) int {
if len(args) == 0 {
fmt.Fprintln(stderr, updateUsage)
return 2
}
switch args[0] {
case "check":
return runUpdateCheck(args[1:], out, stderr)
case "install":
return runUpdateInstall(args[1:], out, stderr)
case "watchdog":
return runUpdateWatchdog(args[1:], stderr)
default:
fmt.Fprintln(stderr, updateUsage)
return 2
}
}
func runUpdateInstall(args []string, out, stderr io.Writer) int {
flags := flag.NewFlagSet("update install", flag.ContinueOnError)
flags.SetOutput(stderr)
configPath := flags.String("config", "", "bootstrap config file")
releasePath := flags.String("release", "", "release manifest")
configPath := flags.String("config", configuration.DefaultConfigPath(), "bootstrap config file")
version := flags.String("version", "", "release version to install")
releaseURL := flags.String("release-url", releaseupdate.ReleaseURL, "base URL of the release downloads")
var meta releaseupdate.InstallMeta
flags.StringVar(&meta.ReportPath, "report", "", "where the watchdog leaves the outcome")
flags.StringVar(&meta.Channel, "channel", "", "channel the outcome is reported on")
flags.Int64Var(&meta.ChatID, "chat", 0, "chat the outcome is reported to")
flags.IntVar(&meta.ThreadID, "thread", 0, "thread the outcome is reported to")
if err := flags.Parse(args); err != nil {
return 2
}
self, err := os.Executable()
if err != nil {
fmt.Fprintln(stderr, err)
return 1
}
if err := checkUpdateTopology(*configPath, *releasePath, out); err != nil {
ctx := context.Background()
tx, err := hostTransaction(*configPath, filepath.Dir(self), func(line string) { fmt.Fprintln(out, line) })
if err != nil {
fmt.Fprintln(stderr, err)
return 1
}
result, err := tx.Prepare(ctx, releaseupdate.PrepareRequest{
Version: *version, ReleaseURL: *releaseURL, Self: self, Meta: meta,
CheckTopology: func(ctx context.Context, required releaseupdate.Topology, managed bool) error {
return checkUpdateTopology(ctx, *configPath, required, managed, out)
},
})
if err != nil {
fmt.Fprintln(stderr, err)
return 1
}
frozen := filepath.Join(releaseupdate.JournalPath(updateStateDir()), releaseupdate.WatchdogBinary)
if err := spawnWatchdog(ctx, result.RestartRequested, frozen, *configPath, false); err != nil {
// The journal stays: the next archied boot recovers it.
fmt.Fprintln(stderr, err)
return 1
}
if !result.RestartRequested {
fmt.Fprintf(out, "no systemd user manager: the watchdog installs %s without restarting; restart the archie services to run it\n", *version)
}
data, err := json.Marshal(result)
if err != nil {
fmt.Fprintln(stderr, err)
return 1
}
fmt.Fprintln(out, releaseupdate.ResultSentinel+string(data))
return 0
}
func runUpdateWatchdog(args []string, stderr io.Writer) int {
flags := flag.NewFlagSet("update watchdog", flag.ContinueOnError)
flags.SetOutput(stderr)
configPath := flags.String("config", configuration.DefaultConfigPath(), "bootstrap config file")
recovering := flags.Bool("recover", false, "recover an interrupted transaction at boot")
binDir := flags.String("bin-dir", "", "directory of the live binaries")
if err := flags.Parse(args); err != nil {
return 2
}
tx, err := hostTransaction(*configPath, *binDir, func(line string) { fmt.Fprintln(stderr, line) })
if err != nil {
fmt.Fprintln(stderr, err)
return 1
}
if err := tx.Run(context.Background(), *recovering); err != nil {
fmt.Fprintln(stderr, err)
return 1
}
return 0
}
func checkUpdateTopology(configPath, releasePath string, out io.Writer) error {
data, err := os.ReadFile(releasePath)
// hostTransaction wires the transaction to this host: systemd user units,
// Docker, the daemon's health endpoint, the control-plane image policy and
// the State Store's own backup and restore.
func hostTransaction(configPath, binDir string, progress func(string)) (*releaseupdate.Transaction, error) {
_, doc, err := servicekit.Resolve(slog.New(slog.DiscardHandler), configPath, "")
if err != nil {
return nil, err
}
if binDir == "" {
return nil, errors.New("-bin-dir is required")
}
return &releaseupdate.Transaction{
StateDir: updateStateDir(),
BinDir: binDir,
Units: systemdUnits{},
Images: dockerImages{},
Policy: imagePolicy{configPath: configPath},
Database: stateDatabase{configPath: configPath},
Health: daemonHealth{url: doc.Config.Health.URL()},
Progress: progress,
HealthTimeout: updateHealthTimeout,
Observe: updateObserve,
Poll: updatePoll,
}, nil
}
// spawnWatchdog runs the frozen watchdog outside this process, so restarting
// any service, including the one that asked for the update, cannot kill it.
// Under systemd it is a transient unit of its own; without one it is a
// detached session.
func spawnWatchdog(ctx context.Context, managed bool, binary, configPath string, recovering bool) error {
exe, err := os.Executable()
if err != nil {
return err
}
var manifest struct {
Required releaseupdate.Topology `json:"required_topology"`
args := []string{"update", "watchdog", "-config", configPath, "-bin-dir", filepath.Dir(exe)}
if recovering {
args = append(args, "-recover")
}
if err := json.Unmarshal(data, &manifest); err != nil {
stateEnv := "ARCHIE_UPDATE_STATE_DIR=" + updateStateDir()
if managed {
// The units load the env file beside the config for database and
// service credentials; the watchdog needs the same ones.
envFile := "EnvironmentFile=-" + filepath.Join(filepath.Dir(configPath), "env")
run := append([]string{"--user", "--collect", "--quiet", "--unit=archied-update-watchdog", "--setenv=" + stateEnv, "--property=" + envFile, binary}, args...)
if output, err := exec.CommandContext(ctx, "systemd-run", run...).CombinedOutput(); err != nil {
return fmt.Errorf("start the update watchdog: %w: %s", err, output)
}
return nil
}
logFile, err := os.OpenFile(filepath.Join(updateStateDir(), "watchdog.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o600)
if err != nil {
return err
}
if len(manifest.Required.Units) == 0 {
return errors.New("release has no required_topology")
defer func() { _ = logFile.Close() }()
cmd := exec.Command(binary, args...) //nolint:noctx // the watchdog must outlive this process
cmd.Env = append(os.Environ(), stateEnv)
cmd.Stdout, cmd.Stderr = logFile, logFile
cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
if err := cmd.Start(); err != nil {
return fmt.Errorf("start the update watchdog: %w", err)
}
for _, unit := range manifest.Required.Units {
if !regexp.MustCompile(`^archie[a-z0-9-]*$`).MatchString(unit) {
return fmt.Errorf("invalid release unit %q", unit)
}
}
data, err = os.ReadFile(configPath)
return cmd.Process.Release()
}
// checkUpdateTopology refuses a host missing a unit or config section the
// release requires. Units are observable only under systemd; without it there
// is nothing to restart, so only the config is checked.
func checkUpdateTopology(ctx context.Context, configPath string, required releaseupdate.Topology, managed bool, out io.Writer) error {
data, err := os.ReadFile(configPath)
if err != nil {
return err
}
@@ -64,25 +209,34 @@ func checkUpdateTopology(configPath, releasePath string, out io.Writer) error {
return fmt.Errorf("observe topology: %w", err)
}
sections := make(map[string]bool)
for _, section := range manifest.Required.ConfigSections {
for _, section := range required.ConfigSections {
sections[section] = hasConfigSection(document, section)
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
output, observeErr := exec.CommandContext(ctx, "systemctl", "--user", "list-unit-files", "archie*.service", "--no-legend", "--no-pager").Output()
units := observedUnits(output, observeErr)
plan := manifest.Required.MigrationPlan(units, sections)
if len(plan) != 0 {
fmt.Fprintln(out, "Required migration, in order:")
for _, step := range plan {
fmt.Fprintln(out, " -", step)
units := make(map[string]bool)
var observeErr error
if managed {
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
var output []byte
output, observeErr = exec.CommandContext(ctx, "systemctl", "--user", "list-unit-files", "archie*.service", "--no-legend", "--no-pager").Output()
units = observedUnits(output, observeErr)
} else {
for _, unit := range required.Units {
units[unit] = true
}
if observeErr != nil {
return fmt.Errorf("topology unknown; apply the printed migration before retrying: %w", observeErr)
}
return errors.New("refusing partial installation; apply the printed migration before retrying")
}
return nil
plan := required.MigrationPlan(units, sections)
if len(plan) == 0 {
return nil
}
fmt.Fprintln(out, "Required migration, in order:")
for _, step := range plan {
fmt.Fprintln(out, " -", step)
}
if observeErr != nil {
return fmt.Errorf("topology unknown; apply the printed migration before retrying: %w", observeErr)
}
return errors.New("refusing partial installation; apply the printed migration before retrying")
}
func hasConfigSection(document map[string]any, section string) bool {
@@ -108,10 +262,11 @@ func updateStateDir() string {
return filepath.Join(dir, "archie", "update")
}
// Recovery runs independently of the daemon unit: it must be able to stop that
// unit and replace its executable without systemd killing the recovery process.
func resumeUpdate(ctx context.Context) (bool, error) {
journal := filepath.Join(updateStateDir(), "transaction")
// resumeUpdate hands an interrupted transaction to the frozen watchdog and
// reports that this boot must stop: recovery may replace this executable and
// restart this unit, so it runs outside it.
func resumeUpdate(ctx context.Context, configPath string) (bool, error) {
journal := releaseupdate.JournalPath(updateStateDir())
if _, err := os.Stat(journal); errors.Is(err, os.ErrNotExist) {
return false, nil
} else if err != nil {
@@ -123,14 +278,15 @@ func resumeUpdate(ctx context.Context) (bool, error) {
}
defer lock.Close()
if err := unix.Flock(int(lock.Fd()), unix.LOCK_EX|unix.LOCK_NB); errors.Is(err, unix.EWOULDBLOCK) {
// A live watchdog owns the transaction and is restarting this unit.
return false, nil
} else if err != nil {
return false, err
}
defer func() { _ = unix.Flock(int(lock.Fd()), unix.LOCK_UN) }()
cmd := exec.CommandContext(ctx, "systemd-run", "--user", "--collect", "--quiet", "--unit=archied-update-recovery", "--setenv=ARCHIE_UPDATE_STATE_DIR="+updateStateDir(), filepath.Join(journal, "watchdog"), "--boot-recover")
if output, err := cmd.CombinedOutput(); err != nil {
return false, fmt.Errorf("schedule update recovery: %w: %s", err, output)
_ = unix.Flock(int(lock.Fd()), unix.LOCK_UN)
frozen := filepath.Join(journal, releaseupdate.WatchdogBinary)
if err := spawnWatchdog(ctx, (systemdUnits{}).Managed(ctx), frozen, configPath, true); err != nil {
return false, fmt.Errorf("schedule update recovery: %w", err)
}
return true, nil
}
+4 -8
View File
@@ -11,18 +11,14 @@ import (
"github.com/samcharles93/archie-core/internal/releaseupdate"
)
// RunUpdate serves `archied update check`, printing the release snapshot as
// JSON. The channel defaults to the environment the installer passes on.
func RunUpdate(args []string, out, stderr io.Writer) int {
if len(args) == 0 || args[0] != "check" {
fmt.Fprintln(stderr, "usage: archied update check [-channel stable|next|exact-pin] [-pin version]")
return 2
}
// runUpdateCheck serves `archied update check`, printing the release snapshot
// as JSON. The channel defaults to the environment.
func runUpdateCheck(args []string, out, stderr io.Writer) int {
flags := flag.NewFlagSet("update check", flag.ContinueOnError)
flags.SetOutput(stderr)
channel := flags.String("channel", envOr("ARCHIE_UPDATE_RELEASE_CHANNEL", "stable"), "stable, next, or exact-pin")
pin := flags.String("pin", os.Getenv("ARCHIE_UPDATE_PIN"), "exact release version")
if err := flags.Parse(args[1:]); err != nil {
if err := flags.Parse(args); err != nil {
return 2
}
catalog := &releaseupdate.GitHubCatalog{Channel: func(context.Context) (string, string, error) { return *channel, *pin, nil }}
+101
View File
@@ -0,0 +1,101 @@
package archied
import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"os/exec"
"strings"
"time"
"github.com/samcharles93/archie-core/internal/app/statestore"
"github.com/samcharles93/archie-core/internal/domain/health"
)
// systemdUnits drives the archie user units through systemctl --user.
type systemdUnits struct{}
// Managed reports whether a systemd user manager answers.
func (systemdUnits) Managed(ctx context.Context) bool {
return systemctl(ctx, "show-environment") == nil
}
func (systemdUnits) Start(ctx context.Context, unit string) error {
return systemctl(ctx, "restart", unit+".service")
}
func (systemdUnits) Stop(ctx context.Context, unit string) error {
return systemctl(ctx, "stop", unit+".service")
}
func systemctl(ctx context.Context, args ...string) error {
ctx, cancel := context.WithTimeout(ctx, 2*time.Minute)
defer cancel()
output, err := exec.CommandContext(ctx, "systemctl", append([]string{"--user"}, args...)...).CombinedOutput()
if err != nil {
return fmt.Errorf("systemctl --user %s: %w: %s", strings.Join(args, " "), err, strings.TrimSpace(string(output)))
}
return nil
}
// dockerImages pulls through the Docker CLI.
type dockerImages struct{}
func (dockerImages) Pull(ctx context.Context, ref string) error {
ctx, cancel := context.WithTimeout(ctx, 15*time.Minute)
defer cancel()
if output, err := exec.CommandContext(ctx, "docker", "pull", ref).CombinedOutput(); err != nil {
return fmt.Errorf("docker pull %s: %w: %s", ref, err, strings.TrimSpace(string(output)))
}
return nil
}
// stateDatabase is the task database, backed up and restored in-process by
// the State Store's own recovery code.
type stateDatabase struct{ configPath string }
func (d stateDatabase) Backup(ctx context.Context, out string) error {
_, err := statestore.RunRecovery(ctx, statestore.RecoveryOptions{Operation: statestore.RecoveryBackup, Out: out, Config: d.configPath})
return err
}
func (d stateDatabase) Restore(ctx context.Context, from string) error {
_, err := statestore.RunRecovery(ctx, statestore.RecoveryOptions{Operation: statestore.RecoveryRestore, From: from, Config: d.configPath})
return err
}
func (d stateDatabase) SchemaVersion(ctx context.Context) (int64, error) {
return statestore.SchemaVersion(ctx, statestore.RecoveryOptions{Config: d.configPath})
}
// daemonHealth asks archied's /health/detailed, which answers 200 only once
// the daemon serves and every readiness probe passes.
type daemonHealth struct{ url string }
func (h daemonHealth) Healthy(ctx context.Context) (string, error) {
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, h.url+"/health/detailed", nil)
if err != nil {
return "", err
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return "", err
}
defer func() { _ = resp.Body.Close() }()
body, err := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
if err != nil {
return "", err
}
var report struct {
Status health.Status `json:"status"`
Version string `json:"version"`
}
if resp.StatusCode != http.StatusOK || json.Unmarshal(body, &report) != nil || report.Status != health.StatusOK {
return report.Version, fmt.Errorf("%s: %s", resp.Status, strings.TrimSpace(string(body)))
}
return report.Version, nil
}
+35 -76
View File
@@ -5,54 +5,56 @@ import (
"crypto/sha256"
"encoding/json"
"errors"
"flag"
"fmt"
"io"
"log/slog"
"os"
"path/filepath"
"regexp"
"time"
"github.com/samcharles93/archie-core/internal/app/controlplane"
"github.com/samcharles93/archie-core/internal/app/servicekit"
pb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
"github.com/samcharles93/archie-core/internal/domain/presence"
"github.com/samcharles93/archie-core/internal/secret"
)
type imageChange struct {
Previous string `json:"previous"`
Candidate string `json:"candidate"`
// imagePolicy is the control plane's agent image, reached through the State
// Store contract. Only the image field changes, preserving concurrent edits
// to unrelated settings.
type imagePolicy struct{ configPath string }
func (p imagePolicy) Image(ctx context.Context) (string, error) {
var image string
err := p.with(ctx, func(_ pb.ControlPlaneServiceClient, _ *pb.QueryResponse, _ map[string]json.RawMessage, current string) error {
image = current
return nil
})
return image, err
}
// RunUpdateImage journals and switches the control-plane image policy. It only
// changes the image field, preserving concurrent edits to unrelated settings.
func RunUpdateImage(args []string, stderr io.Writer) int {
flags := flag.NewFlagSet("update-image", flag.ContinueOnError)
flags.SetOutput(stderr)
configPath := flags.String("config", "", "bootstrap config")
journal := flags.String("journal", "", "transaction directory")
candidate := flags.String("prepare", "", "candidate image digest")
rollback := flags.Bool("rollback", false, "restore the prior image")
if err := flags.Parse(args); err != nil {
return 1
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
if err := updateImage(ctx, *configPath, *journal, *candidate, *rollback); err != nil {
fmt.Fprintln(stderr, err)
return 1
}
return 0
func (p imagePolicy) SetImage(ctx context.Context, expected, desired string) error {
return p.with(ctx, func(rpc pb.ControlPlaneServiceClient, response *pb.QueryResponse, policy map[string]json.RawMessage, current string) error {
if current == desired {
return nil
}
if current != expected {
return errors.New("image policy changed during update; refusing to overwrite it")
}
var err error
if policy["image"], err = json.Marshal(desired); err != nil {
return err
}
data, err := json.Marshal(policy)
if err != nil {
return err
}
_, err = rpc.Command(ctx, &pb.CommandRequest{Kind: controlplane.ContainerRuntimePoliciesKind, Command: "replace", ValueJson: data, ExpectedVersion: response.Resource.Version, Actor: "self-update", Source: "installer", RequestId: fmt.Sprintf("self-update-%x-%d", sha256.Sum256(data), response.Resource.Version)})
return err
})
}
func updateImage(ctx context.Context, configPath, journal, candidate string, rollback bool) error {
_, doc, err := servicekit.Resolve(slog.New(slog.DiscardHandler), configPath, "")
func (p imagePolicy) with(ctx context.Context, use func(pb.ControlPlaneServiceClient, *pb.QueryResponse, map[string]json.RawMessage, string) error) error {
_, doc, err := servicekit.Resolve(slog.New(slog.DiscardHandler), p.configPath, "")
if err != nil {
return err
}
client, cleanup, err := servicekit.StateStoreClient(presence.Daemon, doc.Config.Services, secret.NewRegistry())
client, cleanup, err := servicekit.StateStoreClient(presence.Daemon, doc.Config)
if err != nil {
return err
}
@@ -70,48 +72,5 @@ func updateImage(ctx context.Context, configPath, journal, candidate string, rol
if err := json.Unmarshal(policy["image"], &current); err != nil {
return err
}
path := filepath.Join(journal, "image.json")
if candidate != "" {
return prepareImageChange(path, current, candidate)
}
data, err := os.ReadFile(path)
if err != nil {
return err
}
var change imageChange
if err := json.Unmarshal(data, &change); err != nil {
return err
}
expected, desired := change.Previous, change.Candidate
if rollback {
expected, desired = desired, expected
}
if current == desired {
return nil
}
if current != expected {
return errors.New("image policy changed during update; refusing to overwrite it")
}
policy["image"], err = json.Marshal(desired)
if err != nil {
return err
}
data, err = json.Marshal(policy)
if err != nil {
return err
}
_, err = rpc.Command(ctx, &pb.CommandRequest{Kind: controlplane.ContainerRuntimePoliciesKind, Command: "replace", ValueJson: data, ExpectedVersion: response.Resource.Version, Actor: "self-update", Source: "installer", RequestId: fmt.Sprintf("self-update-%x-%d", sha256.Sum256(data), response.Resource.Version)})
return err
}
func prepareImageChange(path, current, candidate string) error {
if !regexp.MustCompile(`^([a-zA-Z0-9./:_-]+@)?sha256:[a-f0-9]{64}$`).MatchString(candidate) {
return errors.New("candidate image must be pinned by digest")
}
data, err := json.Marshal(imageChange{Previous: current, Candidate: candidate})
if err != nil {
return err
}
return os.WriteFile(path, data, 0o600)
return use(rpc, response, policy, current)
}
+7 -5
View File
@@ -8,18 +8,19 @@ import (
"testing"
"golang.org/x/sys/unix"
"github.com/samcharles93/archie-core/internal/releaseupdate"
)
func TestUpdateTopologyRefusal(t *testing.T) {
root := t.TempDir()
manifest := filepath.Join(root, "release.json")
config := filepath.Join(root, "config.toml")
writeUpdateFixture(t, manifest, `{"required_topology":{"units":["archie-state-store","archie-gateway","archied"],"config_sections":["services.state","services.gateway"]}}`)
required := releaseupdate.Topology{Units: []string{"archie-state-store", "archie-gateway", "archied"}, ConfigSections: []string{"services.state", "services.gateway"}}
writeUpdateFixture(t, config, "[services.state]\ntarget='localhost:9090'\n")
writeUpdateFixture(t, filepath.Join(root, "systemctl"), "#!/bin/sh\nprintf 'archied.service enabled enabled\\n'\n")
t.Setenv("PATH", root+":"+os.Getenv("PATH"))
var output bytes.Buffer
if err := checkUpdateTopology(config, manifest, &output); err == nil {
if err := checkUpdateTopology(t.Context(), config, required, true, &output); err == nil {
t.Fatal("partial topology accepted")
}
for _, missing := range []string{"configure [services.gateway]", "install and enable archie-state-store.service", "install and enable archie-gateway.service"} {
@@ -39,6 +40,7 @@ func TestResumeUpdate(t *testing.T) {
}
called := filepath.Join(root, "called")
writeUpdateFixture(t, filepath.Join(root, "systemd-run"), "#!/bin/sh\nprintf '%s\\n' \"$@\" > '"+called+"'\n")
writeUpdateFixture(t, filepath.Join(root, "systemctl"), "#!/bin/sh\n")
t.Setenv("PATH", root+":"+os.Getenv("PATH"))
lock, err := os.OpenFile(filepath.Join(root, "lock"), os.O_CREATE|os.O_RDWR, 0o600)
if err != nil {
@@ -50,7 +52,7 @@ func TestResumeUpdate(t *testing.T) {
t.Fatal(err)
}
}
resumed, err := resumeUpdate(t.Context())
resumed, err := resumeUpdate(t.Context(), filepath.Join(root, "config.toml"))
if err != nil || resumed == active {
t.Fatalf("resumed=%v err=%v", resumed, err)
}
@@ -59,7 +61,7 @@ func TestResumeUpdate(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(data), "--boot-recover") {
if !strings.Contains(string(data), "-recover") {
t.Fatalf("not a rollback: %s", data)
}
}
+5 -3
View File
@@ -9,6 +9,7 @@ import (
"github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc"
"github.com/samcharles93/archie-core/internal/infrastructure/logrpc"
"github.com/samcharles93/archie-core/internal/logging"
"github.com/samcharles93/archie-core/internal/secret"
"github.com/samcharles93/archie-core/internal/skill"
)
@@ -25,9 +26,10 @@ func (b *server) setSkillList(entries []skill.CatalogEntry) {
// channels, so channel reload is left unset and answers Unavailable.
func (b *server) chatCatalog() gatewayrpc.Catalog {
return gatewayrpc.Catalog{
Logs: b.recentLogs,
Skills: b.skillEntries,
Curators: b.curatorStates,
CheckSecret: func(ref secret.SecretRef) bool { _, err := b.secrets.Resolve(ref); return err == nil },
Logs: b.recentLogs,
Skills: b.skillEntries,
Curators: b.curatorStates,
}
}
+3 -6
View File
@@ -7,17 +7,14 @@ import (
// carriesPersonIdentity reports whether a platform's SenderID names a person.
//
// Telegram and email carry a native per-person sender id (a Telegram numeric
// user id, an SMTP from address). The dashboard ("web") has one bearer token,
// not users. Treating a shared token as an identity
// would give it the same standing as a real user, which the read path's
// isolation guarantee depends on never happening.
// Web sender IDs are supplied by the authenticated UI service.
// Telegram and email carry native person identifiers.
//
// An unknown platform fails closed, so a channel added later gets global and
// agent scopes only until someone decides deliberately that it carries people.
func carriesPersonIdentity(platform string) bool {
switch platform {
case "telegram", "email":
case "telegram", "email", "web":
return true
default:
return false
+91 -34
View File
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"slices"
"strings"
"sync"
"github.com/samcharles93/archie-core/internal/config"
@@ -12,13 +13,13 @@ import (
"github.com/samcharles93/archie-core/internal/infrastructure/modelcatalog"
)
// chatModelManager owns the process-local model alias selected for
// interactive chat. Switching it does not rewrite configuration or affect
// workflow steps.
// chatModelManager owns the model selection for interactive chat. Named
// aliases remain defaults; choosing a catalog model does not rewrite them
// or affect workflow steps.
type chatModelManager struct {
mu sync.RWMutex
aliases map[string]string
active string
active map[org.OrgID]string
details map[string]gateway.ModelDetails
providerNames map[string]string
// orgAliases answers the aliases the principal ctx carries may use. Nil
@@ -27,21 +28,18 @@ type chatModelManager struct {
}
func newChatModelManager(aliases map[string]string) *chatModelManager {
m := &chatModelManager{details: make(map[string]gateway.ModelDetails), providerNames: make(map[string]string)}
m := &chatModelManager{active: make(map[org.OrgID]string), details: make(map[string]gateway.ModelDetails), providerNames: make(map[string]string)}
m.SetConfigured(aliases)
return m
}
// SetConfigured replaces the alias table after a live change to model-aliases.
// The active alias survives when it still exists; otherwise chat returns to
// the default alias.
// An available selection survives; otherwise chat returns to the default alias.
func (m *chatModelManager) SetConfigured(aliases map[string]string) {
m.mu.Lock()
defer m.mu.Unlock()
m.aliases = aliases
if !slices.Contains(config.ChatAliases(aliases), m.active) {
m.active = config.PurposeChat.DefaultAlias()
}
m.keepActiveLocked()
}
// SetModelCatalog replaces the provider display names and per-model details
@@ -64,6 +62,15 @@ func (m *chatModelManager) SetModelCatalog(snapshot modelcatalog.Snapshot) {
}
}
}
m.keepActiveLocked()
}
// keepActiveLocked retains an alias or an available model across live updates.
func (m *chatModelManager) keepActiveLocked() {
selection := m.selectionLocked(org.DefaultOrgID)
if !slices.Contains(config.ChatAliases(m.aliases), selection) && !slices.Contains(chatModelRefs(m.aliases, m.details), selection) {
m.active[org.DefaultOrgID] = config.PurposeChat.DefaultAlias()
}
}
func (m *chatModelManager) ProviderDisplayName(provider string) string {
@@ -79,37 +86,41 @@ func (m *chatModelManager) ModelDetails(ref string) (gateway.ModelDetails, bool)
return details, ok
}
// Models returns the aliases chat may switch between.
func (m *chatModelManager) Models() []string {
m.mu.RLock()
defer m.mu.RUnlock()
return config.ChatAliases(m.aliases)
func (m *chatModelManager) selectionLocked(id org.OrgID) string {
if selection := m.active[id]; selection != "" {
return selection
}
return config.PurposeChat.DefaultAlias()
}
func (m *chatModelManager) ActiveAlias() string {
func (m *chatModelManager) ActiveAlias(ctx context.Context) string {
m.mu.RLock()
defer m.mu.RUnlock()
return m.active
selection := m.selectionLocked(org.OrgFromContext(ctx))
if strings.Contains(selection, "/") {
return ""
}
return selection
}
// ActiveModel returns the active alias's model ref, or "" when it is unset.
func (m *chatModelManager) ActiveModel() string {
m.mu.RLock()
defer m.mu.RUnlock()
ref, _ := config.ResolveModel(m.aliases, m.active, config.PurposeChat)
return ref
}
func (m *chatModelManager) SetActiveModel(ctx context.Context, alias string) error {
func (m *chatModelManager) SetActiveModel(ctx context.Context, selection string) error {
if err := ctx.Err(); err != nil {
return err
}
aliases, err := m.aliasesFor(ctx)
if err != nil {
return err
}
m.mu.Lock()
defer m.mu.Unlock()
if !slices.Contains(config.ChatAliases(m.aliases), alias) {
return fmt.Errorf("model alias %q is not configured", alias)
id := org.OrgFromContext(ctx)
if id == org.DefaultOrgID || m.orgAliases == nil {
aliases = m.aliases
}
m.active = alias
if !slices.Contains(config.ChatAliases(aliases), selection) && !slices.Contains(m.refsLocked(id, aliases), selection) {
return fmt.Errorf("model or alias %q is not available", selection)
}
m.active[id] = selection
return nil
}
@@ -124,21 +135,67 @@ func (m *chatModelManager) aliasesFor(ctx context.Context) (map[string]string, e
return m.orgAliases(ctx)
}
// ModelsFor returns the aliases ctx's org may switch between.
// ModelsFor returns the model references ctx's org may select.
func (m *chatModelManager) ModelsFor(ctx context.Context) ([]string, error) {
aliases, err := m.aliasesFor(ctx)
if err != nil {
return nil, err
}
return config.ChatAliases(aliases), nil
m.mu.RLock()
defer m.mu.RUnlock()
id := org.OrgFromContext(ctx)
if id == org.DefaultOrgID || m.orgAliases == nil {
aliases = m.aliases
}
return m.refsLocked(id, aliases), nil
}
// ModelFor resolves the active alias in ctx's org. An org that cannot use it
// gets an error, never another model.
// ModelFor resolves the current selection in the caller's org. A direct
// selection is checked again so revoked models stop serving turns.
func (m *chatModelManager) ModelFor(ctx context.Context) (string, error) {
aliases, err := m.aliasesFor(ctx)
if err != nil {
return "", err
}
return config.ResolveModel(aliases, m.ActiveAlias(), config.PurposeChat)
m.mu.RLock()
defer m.mu.RUnlock()
id := org.OrgFromContext(ctx)
if id == org.DefaultOrgID || m.orgAliases == nil {
aliases = m.aliases
}
selection := m.selectionLocked(id)
if strings.Contains(selection, "/") {
if !slices.Contains(m.refsLocked(id, aliases), selection) {
return "", fmt.Errorf("model %q is not available in this org", selection)
}
return selection, nil
}
return config.ResolveModel(aliases, selection, config.PurposeChat)
}
// refsLocked keeps tenant choices within their assigned aliases; the system
// org can also select from its credential-filtered provider catalog.
func (m *chatModelManager) refsLocked(id org.OrgID, aliases map[string]string) []string {
if id != org.DefaultOrgID {
return chatModelRefs(aliases, nil)
}
return chatModelRefs(aliases, m.details)
}
func chatModelRefs(aliases map[string]string, catalog map[string]gateway.ModelDetails) []string {
refs := make(map[string]struct{}, len(catalog)+len(aliases))
for ref := range catalog {
refs[ref] = struct{}{}
}
for _, alias := range config.ChatAliases(aliases) {
if ref := strings.TrimSpace(aliases[alias]); ref != "" {
refs[ref] = struct{}{}
}
}
out := make([]string, 0, len(refs))
for ref := range refs {
out = append(out, ref)
}
slices.Sort(out)
return out
}
@@ -0,0 +1,119 @@
package archiegateway
import (
"context"
"slices"
"strings"
"testing"
"github.com/samcharles93/archie-core/internal/domain/messaging"
"github.com/samcharles93/archie-core/internal/domain/org"
"github.com/samcharles93/archie-core/internal/gateway"
"github.com/samcharles93/archie-core/internal/infrastructure/modelcatalog"
)
type modelSelectionSessions struct{ gateway.SessionStore }
func (modelSelectionSessions) List(context.Context) ([]gateway.SessionContext, error) {
return nil, nil
}
func TestChatModelSelection(t *testing.T) {
for _, tc := range []struct {
name string
org org.OrgID
selection string
want string
denied bool
}{
{"catalog model", org.DefaultOrgID, "openai/new", "openai/new", false},
{"configured alias", org.DefaultOrgID, "fast", "openai/small", false},
{"unknown model", org.DefaultOrgID, "openai/unknown", "openai/old", true},
{"org model", "tenant", "anthropic/sonnet", "anthropic/sonnet", false},
{"org alias", "tenant", "tenant-chat", "anthropic/sonnet", false},
{"other org model", "tenant", "openai/new", "anthropic/sonnet", true},
{"other org alias", "tenant", "fast", "anthropic/sonnet", true},
} {
t.Run(tc.name, func(t *testing.T) {
manager := newChatModelManager(map[string]string{"default": "openai/old", "fast": "openai/small"})
manager.SetModelCatalog(modelcatalog.Snapshot{Providers: []modelcatalog.Provider{
{ID: "openai", Models: []modelcatalog.Model{{ID: "old"}, {ID: "small"}, {ID: "new"}}},
{ID: "anthropic", Models: []modelcatalog.Model{{ID: "sonnet"}}},
}})
manager.orgAliases = func(context.Context) (map[string]string, error) {
return map[string]string{"default": "anthropic/sonnet", "tenant-chat": "anthropic/sonnet"}, nil
}
ctx := org.WithOrg(t.Context(), tc.org)
router := gateway.NewRouter(nil, nil, "telegram")
router.Models = manager
reply, err := router.Route(ctx, gateway.Inbound{Message: messaging.Message{Text: "/model " + tc.selection}})
if err != nil {
t.Fatal(err)
}
if denied := strings.HasPrefix(reply, "Cannot switch"); denied != tc.denied {
t.Fatalf("reply = %q, denied = %v", reply, tc.denied)
}
got, err := manager.ModelFor(ctx)
if err != nil || got != tc.want {
t.Fatalf("runtime model = %q, %v; want %q", got, err, tc.want)
}
adapter := &gateway.LocalChatAdapter{Router: router, Sessions: modelSelectionSessions{}, Models: manager}
snapshot, err := adapter.Snapshot(ctx)
if err != nil {
t.Fatal(err)
}
provider, _, _ := strings.Cut(tc.want, "/")
if snapshot.ActiveModel != tc.want || snapshot.ActiveProvider != provider || !slices.Contains(snapshot.ModelsByProvider[provider], tc.want) || !slices.Contains(snapshot.Providers, provider) {
t.Fatalf("selector lost model/provider: %+v", snapshot)
}
if tc.org != org.DefaultOrgID && slices.Contains(snapshot.Models, "openai/new") {
t.Fatal("selector exposed another org's model")
}
profile, err := router.Route(ctx, gateway.Inbound{Message: messaging.Message{Text: "/profile"}})
if err != nil || !strings.Contains(profile, tc.want) {
t.Fatalf("profile without task identity = %q, %v", profile, err)
}
})
}
}
func TestChatModelOrgIsolation(t *testing.T) {
for _, selection := range []string{"fast", "tenant/fast"} {
t.Run(selection, func(t *testing.T) {
m := newChatModelManager(map[string]string{"default": "openai/main"})
tenantAliases := map[string]string{"default": "tenant/main", "fast": "tenant/fast"}
m.orgAliases = func(ctx context.Context) (map[string]string, error) {
if org.OrgFromContext(ctx) == "tenant" {
return tenantAliases, nil
}
return map[string]string{"default": "other/main"}, nil
}
tenant := org.WithOrg(t.Context(), "tenant")
if err := m.SetActiveModel(tenant, selection); err != nil {
t.Fatal(err)
}
check := func(systemModel string) {
t.Helper()
for id, want := range map[org.OrgID]string{org.DefaultOrgID: systemModel, "tenant": "tenant/fast", "other": "other/main"} {
got, err := m.ModelFor(org.WithOrg(t.Context(), id))
if err != nil || got != want {
t.Errorf("org %s model = %q, %v; want %q", id, got, err, want)
}
}
}
check("openai/main")
m.SetConfigured(map[string]string{"default": "openai/updated"})
m.SetModelCatalog(modelcatalog.Snapshot{})
check("openai/updated")
delete(tenantAliases, "fast")
if _, err := m.ModelFor(tenant); err == nil {
t.Fatal("revoked tenant choice still executes")
}
adapter := &gateway.LocalChatAdapter{Router: gateway.NewRouter(nil, nil, "telegram"), Sessions: modelSelectionSessions{}, Models: m}
snapshot, err := adapter.Snapshot(tenant)
if err != nil || snapshot.ActiveModel != "" || !slices.Contains(snapshot.ModelsByProvider["tenant"], "tenant/main") {
t.Fatalf("picker cannot recover: %+v, %v", snapshot, err)
}
})
}
}
+8 -2
View File
@@ -51,6 +51,7 @@ type chatSetup struct {
ChatTaskLogs gateway.ChatTaskLogReader
ChatTaskActor gateway.ChatTaskActor
DefaultChatIdentity string
Workflows gateway.WorkflowSource
// Bus carries primary-input events: a completed
// chat turn is published here so input-driven curators can wake. Nil
// disables turn events (tests, minimal setups).
@@ -100,7 +101,7 @@ func componentInstallTypeEnricher(nats config.NATSConfig) func(string) (string,
}
func makeUpdateService(reader controlplanerpc.ResourceReader, cfg config.Config) *releaseupdate.Service {
updates := controlplanerpc.UpdateService(reader, filepath.Join(cfg.WorkDir, "telegram-update-deferrals.json"), cfg.Health.URL())
updates := controlplanerpc.UpdateService(reader, filepath.Join(cfg.WorkDir, "telegram-update-deferrals.json"))
updates.Enrich = componentInstallTypeEnricher(cfg.NATS)
return updates
}
@@ -138,6 +139,7 @@ func newChatTurnRunner(
TaskLogs: s.ChatTaskLogs,
TaskActor: s.ChatTaskActor,
TaskIdentity: s.DefaultChatIdentity,
Workflows: s.Workflows,
Bus: s.Bus,
BotUser: cfg.BotUser,
Channel: channel,
@@ -367,7 +369,11 @@ func (g *chatTitleGenerator) GenerateTitle(ctx context.Context, sessionID, first
if llm == nil {
return "", fmt.Errorf("no model runtime is configured")
}
text, err := sendChatTurn(ctx, llm, g.chatModels.ActiveModel(),
model, err := g.chatModels.ModelFor(ctx)
if err != nil {
return "", err
}
text, err := sendChatTurn(ctx, llm, model,
core.GenerateOptions{Messages: messages, MaxSteps: 1}, nil, nil, g.usage, nil)
if err != nil {
if g.log != nil {
+6 -1
View File
@@ -24,6 +24,11 @@ import (
func (b *server) setupCurators(ctx context.Context) {
log := b.log.With("component", "curator")
model, err := b.chatModels.ModelFor(ctx)
if err != nil {
log.Warn("curators disabled: chat model unavailable", "err", err)
return
}
skillsRoot := b.cfg.SkillsDir
if skillsRoot == "" {
skillsRoot = b.cfg.WorkDir
@@ -36,7 +41,7 @@ func (b *server) setupCurators(ctx context.Context) {
Skills: skillcurator.NewStore(skillsRoot),
Conversations: sessioncurator.NewAdapter(b.chatSessionStore, b.cfg.BotUser),
LLM: curatorLLMRunner{llm: b.chatLLM, outcomes: b.providerOutcomes, usage: b.usage},
Model: b.chatModels.ActiveModel(),
Model: model,
})
if err := b.curatorRegistry.Register(skillcurator.New(skillcurator.DefaultInterval)); err != nil {
+18 -40
View File
@@ -4,26 +4,27 @@ import (
"context"
"fmt"
"net"
"time"
"google.golang.org/grpc"
"github.com/samcharles93/archie-core/internal/app/controlplane"
"github.com/samcharles93/archie-core/internal/app/servicekit"
"github.com/samcharles93/archie-core/internal/domain/access"
"github.com/samcharles93/archie-core/internal/domain/messaging"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/gateway"
"github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc"
"github.com/samcharles93/archie-core/internal/infrastructure/rpcidentity"
"github.com/samcharles93/archie-core/internal/infrastructure/rpctls"
"github.com/samcharles93/archie-core/internal/plugin"
)
// serveGatewayListener is the serving tail of Run: the listener is
// bound, the process declares itself serving, and the chat contract answers
// until ctx ends.
func (b *server) serveGatewayListener(ctx context.Context, listener net.Listener, loopback bool, contract gateway.ChatContract, opts []grpc.ServerOption) error {
func (b *server) serveGatewayListener(ctx context.Context, listener net.Listener, contract gateway.ChatContract, opts []grpc.ServerOption) error {
defer listener.Close()
b.log.Info("archie-gateway running", "addr", listener.Addr().String(), "token_required", !loopback)
b.log.Info("archie-gateway running", "addr", listener.Addr().String(), "tls", b.id != nil)
// Boot is over and this listener is about to accept: the same fact
// systemd's READY=1 asserts, so the announcement goes out here rather than
// from a second notion of "started". Not later: Serve
@@ -90,53 +91,30 @@ func (b *server) startGatewayRuntime(ctx context.Context, actor gateway.ChatTask
// rather than rejected as an oversized gRPC message.
const inboundMessageHeadroomBytes = 1 << 20
// gatewayServerOpts applies the transport security boundary: a loopback
// listener is served insecure with no token; any non-loopback address
// requires a Bearer [REDACTED], else the process fails closed. It mirrors
// stateStoreServerOpts, minus the State Store's task-scoped grants: the
// Gateway has one administrative token for all callers.
// gatewayServerOpts serves listen with id's credentials; every caller
// presents a service certificate.
//
// The receive limit is raised above gRPC's 4 MB default because an inbound
// request carries a channel attachment's bytes: the channel frontend
// downloads the file, and this process -- which runs the turn -- holds no
// platform credential to fetch it again.
func gatewayServerOpts(listen, token string, principals access.PrincipalSource) (opts []grpc.ServerOption, loopback bool, err error) {
callers := rpcidentity.Callers{Principals: principals}
recv := grpc.MaxRecvMsgSize(messaging.MaxInboundAttachmentBytes + inboundMessageHeadroomBytes)
loopback, err = gatewayrpc.TargetIsLoopback(listen)
func gatewayServerOpts(listen string, id *rpctls.Identity, principals access.PrincipalSource) ([]grpc.ServerOption, error) {
creds, err := id.ServerOption(listen, false)
if err != nil {
return nil, false, err
}
if loopback {
return []grpc.ServerOption{recv, grpc.ChainUnaryInterceptor(callers.Unary()), grpc.ChainStreamInterceptor(callers.Stream())}, true, nil
}
if token == "" {
return nil, false, fmt.Errorf(
"gateway listen address %q is non-loopback; non-loopback exposure requires a Bearer [REDACTED] (--token / [services.gateway].target_token) or TLS",
listen,
)
return nil, fmt.Errorf("gateway: %w", err)
}
callers := rpcidentity.Callers{Principals: principals}
return []grpc.ServerOption{
recv,
grpc.ChainUnaryInterceptor(gatewayrpc.UnaryServerInterceptor(token), callers.Unary()),
grpc.ChainStreamInterceptor(gatewayrpc.StreamServerInterceptor(token), callers.Stream()),
}, false, nil
creds,
grpc.MaxRecvMsgSize(messaging.MaxInboundAttachmentBytes + inboundMessageHeadroomBytes),
grpc.ChainUnaryInterceptor(callers.Unary()),
grpc.ChainStreamInterceptor(callers.Stream()),
}, nil
}
func serveGateway(ctx context.Context, listener net.Listener, contract gateway.ChatContract, sessions gateway.SessionStore, catalog gatewayrpc.Catalog, opts []grpc.ServerOption) error {
server := grpc.NewServer(opts...)
server := grpc.NewServer(append(servicekit.ServerLimits(), opts...)...)
gatewayrpc.RegisterServer(server, contract, sessions, catalog)
serveErr := make(chan error, 1)
go func() { serveErr <- server.Serve(listener) }()
select {
case <-ctx.Done():
// A client can keep a streaming RPC open indefinitely. Allow draining,
// then force cancellation before closing the session store and tools.
timer := time.AfterFunc(10*time.Second, server.Stop)
server.GracefulStop()
timer.Stop()
return nil
case err := <-serveErr:
return err
}
// Serve's bounded drain returns before the session store and tools close.
return servicekit.Serve(ctx, server, listener)
}
@@ -252,6 +252,7 @@ func (b *server) setupGatewayChat(ctx context.Context, actor gateway.ChatTaskAct
ChatTaskLogs: chatTaskLogReaderAdapter{tasks: b.stateStore.TaskByID, taskLogs: b.stateStore},
ChatTaskActor: actor,
DefaultChatIdentity: b.defaultChatIdentity,
Workflows: controlplanerpc.NewWorkflows(b.stateStore.ControlPlane()),
Bus: b.bus, Log: b.log,
MemoryEngine: b.memoryStore(),
MemoryWriter: b.memoryWriter(),
+3 -3
View File
@@ -27,9 +27,9 @@ func (b *server) mcpSamplingHandler() mcp.SamplingHandler {
if b.chatModels == nil {
return mcp.SamplingResult{}, errors.New("mcp sampling: no chat model is configured")
}
model := b.chatModels.ActiveModel()
if model == "" {
return mcp.SamplingResult{}, errors.New("mcp sampling: no chat model is configured")
model, err := b.chatModels.ModelFor(ctx)
if err != nil {
return mcp.SamplingResult{}, fmt.Errorf("mcp sampling: %w", err)
}
messages, err := modelloop.SamplingMessages(req)
if err != nil {
+8 -13
View File
@@ -30,6 +30,7 @@ import (
"github.com/samcharles93/archie-core/internal/infrastructure/controlplanerpc"
"github.com/samcharles93/archie-core/internal/infrastructure/modelcatalog"
"github.com/samcharles93/archie-core/internal/infrastructure/readiness"
"github.com/samcharles93/archie-core/internal/infrastructure/rpctls"
"github.com/samcharles93/archie-core/internal/infrastructure/secretengine"
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
"github.com/samcharles93/archie-core/internal/infrastructure/taskactions"
@@ -51,9 +52,6 @@ type Options struct {
// Listen is the gRPC listen address. Empty falls back to
// [services.gateway].listen.
Listen string
// Token is the bearer token a non-loopback listener requires. Empty falls
// back to [services.gateway].target_token.
Token string
}
// server is the Gateway process: the owner of conversations and of every
@@ -65,6 +63,7 @@ type server struct {
log *slog.Logger
secrets *secret.Registry
id *rpctls.Identity
engines *secretengine.Runner
stateStore *staterpc.Client
controlPlane *controlplane.Client
@@ -130,12 +129,7 @@ func Run(ctx context.Context, options Options) error {
if err != nil {
return err
}
token := options.Token
if token == "" {
token = b.cfg.Services.ResolvedToken(config.ServiceNameGateway, b.secrets.Getenv)
}
//nolint:contextcheck // grpc.StreamServerInterceptor has no context.Context parameter; gatewayrpc.StreamServerInterceptor derives its context from stream.Context() instead
opts, loopback, err := gatewayServerOpts(listen, token, b.stateStore)
opts, err := gatewayServerOpts(listen, b.id, b.stateStore)
if err != nil {
return err
}
@@ -143,7 +137,7 @@ func Run(ctx context.Context, options Options) error {
if err != nil {
return fmt.Errorf("listen for gateway: %w", err)
}
return b.serveGatewayListener(ctx, listener, loopback, contract, opts)
return b.serveGatewayListener(ctx, listener, contract, opts)
}
func (b *server) addCleanup(fn func()) { b.cleanups = append(b.cleanups, fn) }
@@ -171,7 +165,8 @@ func (b *server) loadConfig(cfgPath, overlayPath string) error {
b.log, b.logFeed = logs.Log, logs.Feed
b.addCleanup(func() { _ = logs.Closer.Close() })
b.secrets = secret.NewRegistry()
return nil
b.id, err = servicekit.Identity(b.cfg.TLS, presence.Gateway)
return err
}
// openState claims the conversation store, dials the State Store, starts the
@@ -183,7 +178,7 @@ func (b *server) openState(ctx context.Context) error {
if err := b.claimGatewayOwnership(ctx); err != nil {
return err
}
client, cleanup, err := servicekit.StateStoreClient(presence.Gateway, b.cfg.Services, b.secrets)
client, cleanup, err := servicekit.StateStoreClient(presence.Gateway, b.cfg)
if err != nil {
return fmt.Errorf("state store client: %w", err)
}
@@ -209,7 +204,7 @@ func (b *server) openState(ctx context.Context) error {
}
func (b *server) runtimeConfig(ctx context.Context, base config.Config) (config.Config, map[string]int64, error) {
return servicekit.RuntimeConfig(ctx, b.controlPlane, b.applyStatus, b.secrets, b.log, base, nil)
return servicekit.RuntimeConfig(ctx, b.controlPlane, b.applyStatus, b.secrets, b.log, base, nil, gatewayRuntimeKinds)
}
// connectNATS joins the broker task actions travel over. The daemon owns the
+4 -2
View File
@@ -28,8 +28,10 @@ func (u *usageSink) record(ctx context.Context, source usage.Source, ref string,
return
}
alias := ""
if u.models != nil && u.models.ActiveModel() == ref {
alias = u.models.ActiveAlias()
if u.models != nil {
if model, err := u.models.ModelFor(ctx); err == nil && model == ref {
alias = u.models.ActiveAlias(ctx)
}
}
record := usage.Record{
Source: source, Alias: alias,
+16 -37
View File
@@ -8,22 +8,23 @@ import (
"os"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/presence"
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
"github.com/samcharles93/archie-core/internal/infrastructure/rpctls"
"github.com/samcharles93/archie-core/internal/secret"
)
// ResolvedConfig contains the resolved inputs needed by the Messaging Service.
type ResolvedConfig struct {
Options Options
Options Options
// Identity is this process's certificate; nil is plaintext, loopback only.
Identity *rpctls.Identity
TelegramToken string
Telegram config.TelegramConfig
// WorkDir, BotUser and HealthURL are not channel transport settings. They
// locate this identity's release-announcement and update-report state
// files, and give the update installer the daemon health endpoint to poll
// after it applies one.
// WorkDir and BotUser are not channel transport settings. They locate
// this identity's release-announcement and update-report state files.
WorkDir string
BotUser string
HealthURL string
ShowToolCalls bool
}
@@ -31,10 +32,10 @@ type projection struct {
gateway ServiceTarget
stateStore ServiceTarget
messaging config.ServiceConnection
tls config.TLS
telegram config.TelegramConfig
workDir string
botUser string
healthURL string
showToolCalls bool
}
@@ -55,17 +56,20 @@ func Resolve(o Options, log *slog.Logger) (ResolvedConfig, error) {
}
}
o = withDefaults(o)
o = withEnvTokens(o)
if err := o.validate(); err != nil {
return ResolvedConfig{}, err
}
id, err := rpctls.Load(proj.tls.CAFile, proj.tls.CertDir, presence.Messaging)
if err != nil {
return ResolvedConfig{}, err
}
return ResolvedConfig{
Options: o,
Identity: id,
Telegram: proj.telegram,
WorkDir: proj.workDir,
BotUser: proj.botUser,
HealthURL: proj.healthURL,
ShowToolCalls: proj.showToolCalls,
}, nil
}
@@ -83,52 +87,27 @@ func readProjection(path, overlay string, log *slog.Logger) (projection, bool, e
func project(cfg config.Config) projection {
return projection{
gateway: ServiceTarget{
Target: cfg.Services.Get(config.ServiceNameGateway).Target,
Token: cfg.Services.Get(config.ServiceNameGateway).TargetToken,
},
stateStore: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameState).Target, Token: cfg.Services.Get(config.ServiceNameState).TargetToken},
gateway: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameGateway).Target},
stateStore: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameState).Target},
messaging: cfg.Services.Get(config.ServiceNameMessaging),
tls: cfg.TLS,
telegram: cfg.Chat.Telegram,
workDir: cfg.WorkDir,
botUser: cfg.BotUser,
healthURL: cfg.Health.URL(),
showToolCalls: cfg.Chat.ShowToolCalls,
}
}
func withEnvTokens(o Options) Options {
if o.Gateway.Token == "" {
o.Gateway.Token = os.Getenv("GATEWAY_TOKEN")
}
if o.StateStore.Token == "" {
o.StateStore.Token = os.Getenv("STATE_STORE_TOKEN")
}
if o.Token == "" {
o.Token = os.Getenv("MESSAGING_TOKEN")
}
return o
}
func merge(o Options, p projection) Options {
if o.Gateway.Target == "" {
o.Gateway.Target = p.gateway.Target
}
if o.Gateway.Token == "" {
o.Gateway.Token = p.gateway.Token
}
if o.StateStore.Target == "" {
o.StateStore.Target = p.stateStore.Target
}
if o.StateStore.Token == "" {
o.StateStore.Token = p.stateStore.Token
}
if o.Listen == "" {
o.Listen = p.messaging.Listen
}
if o.Token == "" {
o.Token = p.messaging.TargetToken
}
return o
}
+2 -39
View File
@@ -4,9 +4,6 @@ package archiemessaging
import (
"errors"
"fmt"
"net"
"strings"
"time"
)
@@ -18,11 +15,9 @@ const (
defaultShutdownTimeout = 5 * time.Second
)
// ServiceTarget is one remote contract's endpoint and the service-to-service
// bearer token this process presents to it.
// ServiceTarget is one remote contract's endpoint.
type ServiceTarget struct {
Target string
Token string
}
// Options contains the process inputs for the Messaging Service.
@@ -32,10 +27,8 @@ type Options struct {
Gateway ServiceTarget
StateStore ServiceTarget
// Listen is where MessagingService is served; Token is the bearer token
// its callers present on a non-loopback address.
// Listen is where MessagingService is served.
Listen string
Token string
DependencyTimeout time.Duration
ShutdownTimeout time.Duration
}
@@ -60,35 +53,5 @@ func (o Options) validate() error {
if o.Gateway.Target == "" {
return errors.New("gateway target is required (pass -gateway-target or configure [services.gateway].target)")
}
if err := validateServiceTarget("gateway", o.Gateway); err != nil {
return err
}
if o.StateStore.Target != "" {
if err := validateServiceTarget("state store", o.StateStore); err != nil {
return err
}
}
return validateServiceTarget("messaging listen", ServiceTarget{Target: o.Listen, Token: o.Token})
}
func validateServiceTarget(serviceName string, target ServiceTarget) error {
host, _, err := net.SplitHostPort(target.Target)
if err != nil {
host = target.Target
}
if isLoopback(host) {
return nil
}
if target.Token == "" {
return fmt.Errorf("%s target %q is non-loopback and requires a bearer token", serviceName, target.Target)
}
return nil
}
func isLoopback(host string) bool {
if host == "localhost" {
return true
}
ip := net.ParseIP(strings.Trim(host, "[]"))
return ip != nil && ip.IsLoopback()
}
+24 -15
View File
@@ -19,6 +19,7 @@ import (
"github.com/samcharles93/archie-core/internal/infrastructure/extension"
"github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc"
"github.com/samcharles93/archie-core/internal/infrastructure/messagingrpc"
"github.com/samcharles93/archie-core/internal/infrastructure/rpctls"
"github.com/samcharles93/archie-core/internal/infrastructure/secretengine"
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
"github.com/samcharles93/archie-core/internal/logging"
@@ -36,7 +37,7 @@ func Run(ctx context.Context, o Options) error {
return fmt.Errorf("resolve messaging options: %w", err)
}
chat, closeGateway, err := gatewayrpc.Dial(cfg.Options.Gateway.Target, cfg.Options.Gateway.Token)
chat, closeGateway, err := gatewayrpc.Dial(cfg.Options.Gateway.Target, cfg.Identity)
if err != nil {
return fmt.Errorf("dial gateway (%s): %w", cfg.Options.Gateway.Target, err)
}
@@ -59,7 +60,7 @@ func Run(ctx context.Context, o Options) error {
var updates *releaseupdate.Service
var extensionChannels []*channelInstance
if cfg.Options.StateStore.Target != "" {
stateStore, closeClient, dialErr := staterpc.Dial(cfg.Options.StateStore.Target, presence.Messaging, cfg.Options.StateStore.Token, staterpc.WaitForPeer)
stateStore, closeClient, dialErr := staterpc.Dial(cfg.Options.StateStore.Target, presence.Messaging, cfg.Identity, staterpc.WaitForPeer)
if dialErr != nil {
return fmt.Errorf("dial state store control plane (%s): %w", cfg.Options.StateStore.Target, dialErr)
}
@@ -86,7 +87,7 @@ func Run(ctx context.Context, o Options) error {
settings = messaging.NewSettingsCommand(controlplanerpc.NewSettingsClient(stateStore.ControlPlane())).WithIdentities(stateStore)
channelStatusStore, presenceStore = stateStore, stateStore
settingsSource, applyReporter, appliedVersion = controlPlaneClient, reporter, channelVersion
updates = controlplanerpc.UpdateService(controlPlaneClient, filepath.Join(cfg.WorkDir, "telegram-update-deferrals.json"), cfg.HealthURL)
updates = controlplanerpc.UpdateService(controlPlaneClient, filepath.Join(cfg.WorkDir, "telegram-update-deferrals.json"))
}
if cfg.Options.StateStore.Target == "" {
@@ -112,29 +113,37 @@ func Run(ctx context.Context, o Options) error {
if err != nil {
return err
}
return serve(ctx, cfg.Options, srv, log, feed)
return serve(ctx, cfg.Options.Listen, cfg.Identity, srv, log, feed)
}
// serve runs srv and serves MessagingService over it until ctx is cancelled.
func serve(ctx context.Context, o Options, srv *Service, log *slog.Logger, feed *logging.Feed) error {
opts, err := messagingrpc.ServerOptions(o.Listen, o.Token)
func serve(ctx context.Context, listen string, id *rpctls.Identity, srv *Service, log *slog.Logger, feed *logging.Feed) error {
opts, err := messagingrpc.ServerOptions(listen, id)
if err != nil {
return err
}
listener, err := (&net.ListenConfig{}).Listen(ctx, "tcp", o.Listen)
listener, err := (&net.ListenConfig{}).Listen(ctx, "tcp", listen)
if err != nil {
return fmt.Errorf("listen messaging (%s): %w", o.Listen, err)
return fmt.Errorf("listen messaging (%s): %w", listen, err)
}
server := grpc.NewServer(opts...)
server := grpc.NewServer(append(servicekit.ServerLimits(), opts...)...)
messagingrpc.RegisterServer(server, srv, feed)
ctx, cancel := context.WithCancel(ctx)
defer cancel()
// A dead listener stops the channels too: the process exits and its
// supervisor restarts it, rather than it running on without Deliver.
serveErr := make(chan error, 1)
go func() {
if err := server.Serve(listener); err != nil {
log.Error("messaging gRPC server stopped", "err", err)
}
serveErr <- servicekit.Serve(ctx, server, listener)
cancel()
}()
defer server.GracefulStop()
log.Info("messaging service listening", "listen", o.Listen)
return srv.Start(ctx)
log.Info("messaging service listening", "listen", listen)
startErr := srv.Start(ctx)
cancel()
if err := <-serveErr; err != nil {
return fmt.Errorf("serve messaging: %w", err)
}
return startErr
}
// superviseSecretEngines runs the secret-engine extensions and reports their
+91
View File
@@ -0,0 +1,91 @@
package archieui
import (
"context"
"sync"
"github.com/samcharles93/archie-core/internal/domain/identity"
"github.com/samcharles93/archie-core/internal/infrastructure/oidc"
)
// accountOIDC reloads browser-managed provider settings without restarting UI.
// The provider retains its discovery and signing-key cache until settings change.
type accountOIDC struct {
fallbackFlow identity.LoginFlow
fallbackProvider *oidc.Provider
settings identity.AuthenticationSettingsStore
subjects identity.SubjectResolver
fallback identity.AuthenticationSettings
mu sync.Mutex
current identity.AuthenticationSettings
provider *oidc.Provider
}
func (a *accountOIDC) flow(ctx context.Context) (identity.LoginFlow, *oidc.Verifier, error) {
settings, err := a.settings.AuthenticationSettings(ctx)
if err != nil {
return nil, nil, err
}
if settings.PublicURL == "" {
settings = a.fallback
if a.fallbackFlow != nil {
return a.fallbackFlow, oidc.NewVerifierForAudience(a.fallbackProvider, a.fallback.OIDCClientID), nil
}
}
if settings.OIDCIssuer == "" {
return nil, nil, identity.ErrNoCredential
}
a.mu.Lock()
defer a.mu.Unlock()
if a.provider == nil || a.current != settings {
provider, err := oidc.NewProvider(oidc.Config{Issuer: settings.OIDCIssuer, Audience: settings.OIDCAudience})
if err != nil {
return nil, nil, err
}
a.provider, a.current = provider, settings
}
flow, err := oidc.NewFlow(a.provider, settings.OIDCClientID, "", settings.PublicURL+"/oauth2/callback")
return flow, oidc.NewVerifierForAudience(a.provider, settings.OIDCClientID), err
}
func (a *accountOIDC) AuthenticateBrowser(ctx context.Context, credential string) (identity.Identity, error) {
_, verifier, err := a.flow(ctx)
if err != nil {
return identity.Identity{}, err
}
value, _, err := identity.Authenticate(ctx, a.subjects, verifier, credential)
return value, err
}
func (a *accountOIDC) AuthCodeURL(ctx context.Context, state string) (string, string, error) {
flow, _, err := a.flow(ctx)
if err != nil {
return "", "", err
}
return flow.AuthCodeURL(ctx, state)
}
func (a *accountOIDC) Exchange(ctx context.Context, code, verifier string) (identity.ProviderSession, error) {
flow, _, err := a.flow(ctx)
if err != nil {
return identity.ProviderSession{}, err
}
return flow.Exchange(ctx, code, verifier)
}
func (a *accountOIDC) Authenticate(ctx context.Context, credential string) (identity.Identity, error) {
if subject, ok := identity.PersonalTokenSubject(credential); ok {
return identity.Resolve(ctx, a.subjects, identity.Credential{Subject: subject})
}
if _, _, err := a.flow(ctx); err != nil {
return identity.Identity{}, err
}
a.mu.Lock()
provider := a.provider
if provider == nil {
provider = a.fallbackProvider
}
a.mu.Unlock()
value, _, err := identity.Authenticate(ctx, a.subjects, oidc.NewVerifier(provider), credential)
return value, err
}
-21
View File
@@ -1,8 +1,6 @@
package archieui
import (
"context"
"log/slog"
"os"
"strings"
@@ -20,25 +18,6 @@ func signInProvider(opts Options) (*oidc.Provider, error) {
return oidc.NewProvider(oidc.Config{Issuer: opts.OidcIssuer, Audience: opts.OidcAudience})
}
// dashboardAuthenticator builds the credential check, or nil when no provider
// is configured.
func dashboardAuthenticator(provider *oidc.Provider, opts Options, subjects identity.SubjectResolver, log *slog.Logger) func(context.Context, string) (identity.Identity, error) {
if provider == nil {
return nil
}
verifier := oidc.NewVerifier(provider)
log.Info("dashboard authenticates provider credentials", "issuer", opts.OidcIssuer, "audience", opts.OidcAudience)
return func(ctx context.Context, credential string) (identity.Identity, error) {
// A personal token is bound in the State Store, not issued by the
// provider, so it resolves without the provider's verifier.
if subject, ok := identity.PersonalTokenSubject(credential); ok {
return identity.Resolve(ctx, subjects, identity.Credential{Subject: subject})
}
value, _, err := identity.Authenticate(ctx, subjects, verifier, credential)
return value, err
}
}
// dashboardLoginFlow builds the browser sign-in flow, or nil when not
// configured. The client secret is read from the named env var.
func dashboardLoginFlow(provider *oidc.Provider, opts Options) (identity.LoginFlow, error) {
+16 -2
View File
@@ -38,7 +38,8 @@ type deps struct {
Identities identity.Repository
// Authenticate resolves a presented credential to the identity that may
// act. Nil when no provider is configured, which keeps the shared token.
Authenticate func(context.Context, string) (identity.Identity, error)
Authenticate func(context.Context, string) (identity.Identity, error)
AuthenticateBrowser func(context.Context, string) (identity.Identity, error)
// Login drives the browser sign-in flow, or nil when no provider is
// configured for it.
Login identity.LoginFlow
@@ -56,8 +57,8 @@ func compose(ctx context.Context, d deps) *webui.Server {
srv := &webui.Server{
Store: d.Store,
Log: d.Log,
Token: d.Options.Token,
Authenticate: d.Authenticate,
AuthenticateBrowser: d.AuthenticateBrowser,
Login: d.Login,
TrustForwardedHeaders: d.Options.trustForwardedHeaders(),
Health: d.Health,
@@ -94,6 +95,7 @@ func compose(ctx context.Context, d deps) *webui.Server {
srv.Policies = policies
}
wireOrgSurface(srv, d.Store)
wireAlerts(srv, d.Store)
if presence, ok := d.Store.(storecontract.PresenceStore); ok {
srv.Presence = presence
srv.RunningVersions = servicekit.RunningVersions(ctx, presence, 0)
@@ -133,6 +135,9 @@ func compose(ctx context.Context, d deps) *webui.Server {
// wireOrgSurface attaches the dashboard's org surface when the state client
// carries it.
func wireOrgSurface(srv *webui.Server, store storecontract.TaskStore) {
if accounts, ok := store.(identity.Accounts); ok {
srv.Accounts = accounts
}
if orgs, ok := store.(org.API); ok {
srv.Orgs = orgs
}
@@ -150,6 +155,7 @@ func wireCatalog(d deps, srv *webui.Server) {
}
srv.Skills = skillCatalog{client: catalog}
srv.Curators = curatorStatus{client: catalog}
srv.CheckSecret = catalog.CheckSecret
}
// wireTaskLogs attaches the task-log read when the store client carries the
@@ -228,3 +234,11 @@ func refusalStore(store storecontract.TaskStore) storecontract.CaptureRefusalSto
refusals, _ := store.(storecontract.CaptureRefusalStore)
return refusals
}
// wireAlerts gives the dashboard the State Store's alert surface when the
// store has one.
func wireAlerts(srv *webui.Server, store any) {
if alerts, ok := store.(webui.AlertSource); ok {
srv.Alerts = alerts
}
}
+14 -47
View File
@@ -8,13 +8,16 @@ import (
"os"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/presence"
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
"github.com/samcharles93/archie-core/internal/infrastructure/rpctls"
"github.com/samcharles93/archie-core/internal/webui"
)
// Resolve returns the effective Options: flags first, then the config file's
// projection, then defaults, and validates the result.
func Resolve(o Options, log *slog.Logger) (Options, error) {
var tls config.TLS
if o.Config != "" {
cfg, found, err := readProjection(o.Config, o.Overlay, log)
if err != nil {
@@ -22,15 +25,15 @@ func Resolve(o Options, log *slog.Logger) (Options, error) {
}
if found {
o = merge(o, cfg)
tls = cfg.tls
}
}
o = withDefaults(o)
o = withEnvTokens(o)
token, err := resolveToken(o)
id, err := rpctls.Load(tls.CAFile, tls.CertDir, presence.UI)
if err != nil {
return Options{}, err
}
o.Token = token
o.identity = id
if err := o.validate(); err != nil {
return Options{}, err
}
@@ -60,6 +63,7 @@ type projection struct {
state ServiceTarget
messaging ServiceTarget
harness ServiceTarget
tls config.TLS
capture CaptureOptions
}
@@ -67,10 +71,11 @@ func project(cfg config.Config) projection {
return projection{
listen: cfg.Web.Listen,
trustForwardedHeaders: cfg.Web.TrustForwardedHeaders,
gateway: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameGateway).Target, Token: cfg.Services.Get(config.ServiceNameGateway).TargetToken},
messaging: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameMessaging).Target, Token: cfg.Services.Get(config.ServiceNameMessaging).TargetToken},
state: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameState).Target, Token: cfg.Services.Get(config.ServiceNameState).TargetToken},
harness: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameHarness).Target, Token: cfg.Services.Get(config.ServiceNameHarness).TargetToken},
gateway: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameGateway).Target},
messaging: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameMessaging).Target},
state: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameState).Target},
harness: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameHarness).Target},
tls: cfg.TLS,
capture: CaptureOptions{
Retention: cfg.Capture.Retention.Std(),
MaxEvents: cfg.Capture.MaxEvents,
@@ -81,23 +86,6 @@ func project(cfg config.Config) projection {
}
}
// withEnvTokens fills service tokens left unset from the environment.
func withEnvTokens(o Options) Options {
if o.Gateway.Token == "" {
o.Gateway.Token = os.Getenv("GATEWAY_TOKEN")
}
if o.State.Token == "" {
o.State.Token = os.Getenv("STATE_STORE_TOKEN")
}
if o.Messaging.Token == "" {
o.Messaging.Token = os.Getenv("MESSAGING_TOKEN")
}
if o.Harness.Token == "" {
o.Harness.Token = os.Getenv("HARNESS_TOKEN")
}
return o
}
// merge fills only the fields the flags left empty.
func merge(o Options, p projection) Options {
if o.Listen == "" {
@@ -153,20 +141,7 @@ func withDefaults(o Options) Options {
return o
}
// resolveToken returns the dashboard token, minting and persisting one when
// the operator named a token file and gave no token directly. Naming the file
// is how a non-loopback listener opts in to a generated token instead of
// being refused.
func resolveToken(o Options) (string, error) {
if o.Token != "" || o.TokenFile == "" {
return o.Token, nil
}
return webui.LoadOrCreateToken(o.TokenFile)
}
// Unlike the daemon, which mints a token silently, this process refuses to
// start -- an operator who exposed the dashboard by accident learns about it
// here rather than from the log.
// Browser access is gated by accounts; service endpoints must still be configured.
func (o Options) validate() error {
if o.Gateway.Target == "" {
return fmt.Errorf("gateway target is required (-gateway-target or [services.gateway].target)")
@@ -174,12 +149,7 @@ func (o Options) validate() error {
if o.State.Target == "" {
return fmt.Errorf("state store target is required (-state-target or [services.state].target)")
}
if !webui.IsLoopback(o.Listen) && o.Token == "" {
return fmt.Errorf(
"ui listen address %q is non-loopback; a reachable dashboard requires a token (-token) or a token file to mint one (-token-file) (deployments/README.md, running the dashboard)",
o.Listen,
)
}
return nil
}
@@ -187,8 +157,5 @@ func mergeTarget(o, p ServiceTarget) ServiceTarget {
if o.Target == "" {
o.Target = p.Target
}
if o.Token == "" {
o.Token = p.Token
}
return o
}
+1 -1
View File
@@ -23,7 +23,7 @@ func wireServiceLogs(opts Options, srv *webui.Server, tasks *staterpc.Client, ch
return chat.RecentLogs(ctx, presence.Daemon, q)
},
}
messaging, closeMessaging, dialErr := messagingrpc.Dial(opts.Messaging.Target, opts.Messaging.Token)
messaging, closeMessaging, dialErr := messagingrpc.Dial(opts.Messaging.Target, opts.identity)
if dialErr != nil {
return nil, dialErr
}
+8 -13
View File
@@ -6,6 +6,7 @@ import (
"time"
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
"github.com/samcharles93/archie-core/internal/infrastructure/rpctls"
)
// Process defaults. Listen matches the dashboard's historical bind
@@ -18,12 +19,9 @@ const (
defaultShutdownTimeout = 5 * time.Second
)
// ServiceTarget is one remote contract's endpoint and the service-to-service
// bearer token this process presents to it. It is an endpoint reference, not
// a resolved daemon credential: the UI authenticates each client itself.
// ServiceTarget is one remote contract's endpoint.
type ServiceTarget struct {
Target string
Token string
}
// Options is the UI-owned input DTO. It carries process-local settings and
@@ -39,15 +37,8 @@ type Options struct {
// Listen is the dashboard HTTP bind address.
Listen string
// Token gates browser access. Empty is permitted only for a loopback
// listener; see Options.validate.
Token string
// TokenFile is where the dashboard token is persisted, minted on first
// use. It is the explicit opt-in to a non-loopback listener: without it
// a reachable bind must be given a token.
TokenFile string
// OidcIssuer and OidcAudience configure the identity provider. Both empty
// keeps the shared token; an issuer without an audience is refused.
// OidcIssuer and OidcAudience configure the identity provider. Local accounts remain available;
// an issuer without an audience is refused.
OidcIssuer string
OidcAudience string
// OidcClientID and OidcClientSecretEnv register the browser sign-in; the
@@ -83,6 +74,10 @@ type Options struct {
// ReadHeaderTimeout and ShutdownTimeout bound the HTTP lifecycle.
ReadHeaderTimeout time.Duration
ShutdownTimeout time.Duration
// identity is this process's certificate, loaded by Resolve from
// [tls]; nil is plaintext, loopback only.
identity *rpctls.Identity
}
// CaptureOptions carries the [capture] settings the capture receiver needs.
+30 -24
View File
@@ -10,10 +10,13 @@ import (
"os"
"path/filepath"
"slices"
"strings"
"time"
"github.com/samcharles93/archie-core/internal/app/servicekit"
"github.com/samcharles93/archie-core/internal/domain/access"
"github.com/samcharles93/archie-core/internal/domain/applystatus"
"github.com/samcharles93/archie-core/internal/domain/identity"
"github.com/samcharles93/archie-core/internal/domain/presence"
infraaccess "github.com/samcharles93/archie-core/internal/infrastructure/access"
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
@@ -29,7 +32,12 @@ import (
// retrying, so a State Store or database that is down or slow at start
// closes the dashboard rather than opening it or stopping it.
func buildAccessChain(ctx context.Context, store *staterpc.Client, log *slog.Logger) *infraaccess.Live {
live := infraaccess.NewPending(store.ListPolicies, log)
// The chain decides for every org, so it loads as the dashboard service,
// never as the person whose policy edit triggered a reload.
load := func(ctx context.Context) ([]access.Policy, error) {
return store.ListPolicies(access.WithoutPrincipal(ctx))
}
live := infraaccess.NewPending(load, log)
go live.Run(ctx, applystatus.RestampInterval)
return live
}
@@ -52,12 +60,12 @@ func Run(ctx context.Context, options Options) error {
cleanup()
}
}()
tasks, closeState, err := staterpc.Dial(opts.State.Target, presence.UI, opts.State.Token)
tasks, closeState, err := staterpc.Dial(opts.State.Target, presence.UI, opts.identity)
if err != nil {
return err
}
cleanups = append(cleanups, closeState)
chat, closeGateway, err := gatewayrpc.Dial(opts.Gateway.Target, opts.Gateway.Token)
chat, closeGateway, err := gatewayrpc.Dial(opts.Gateway.Target, opts.identity)
if err != nil {
return err
}
@@ -67,25 +75,27 @@ func Run(ctx context.Context, options Options) error {
if err != nil {
return err
}
authenticate := dashboardAuthenticator(provider, opts, tasks, log)
login, err := dashboardLoginFlow(provider, opts)
if err != nil {
return err
}
runtimeOIDC := &accountOIDC{settings: tasks, subjects: tasks, fallbackFlow: login, fallbackProvider: provider, fallback: identity.AuthenticationSettings{PublicURL: strings.TrimSuffix(opts.OidcRedirectURL, "/oauth2/callback"), OIDCIssuer: opts.OidcIssuer, OIDCAudience: opts.OidcAudience, OIDCClientID: opts.OidcClientID}}
srv := compose(ctx, deps{
Options: opts,
Log: log,
Store: tasks,
Chat: chat,
Updates: controlplanerpc.UpdateService(controlplanerpc.NewRPCClient(tasks.ControlPlane()), filepath.Join(configuration.DefaultWorkDir(), "ui-update-deferrals.json"), ""),
Health: newReadinessRegistry(opts, tasks, chat, chain, provider),
ControlPlane: tasks.ControlPlane(),
Identities: tasks,
Authenticate: authenticate,
Login: login,
Access: chain,
Principals: tasks,
Denials: tasks,
Options: opts,
Log: log,
Store: tasks,
Chat: chat,
Updates: controlplanerpc.UpdateService(controlplanerpc.NewRPCClient(tasks.ControlPlane()), filepath.Join(configuration.DefaultWorkDir(), "ui-update-deferrals.json")),
Health: newReadinessRegistry(opts, tasks, chat, chain, provider),
ControlPlane: tasks.ControlPlane(),
Identities: tasks,
Authenticate: runtimeOIDC.Authenticate,
AuthenticateBrowser: runtimeOIDC.AuthenticateBrowser,
Login: runtimeOIDC,
Access: chain,
Principals: tasks,
Denials: tasks,
})
stopLogs, err := wireServiceLogs(opts, srv, tasks, chat, feed)
if err != nil {
@@ -112,11 +122,6 @@ func Run(ctx context.Context, options Options) error {
"gateway", opts.Gateway.Target,
"state", opts.State.Target,
}
// Name the file holding the token, never the token itself: this line
// reaches the journal and any log an operator pastes.
if opts.TokenFile != "" {
attrs = append(attrs, "token_file", opts.TokenFile)
}
log.Info("archie-ui running", attrs...)
return serve(ctx, listener, srv.Handler(), opts)
}
@@ -134,17 +139,18 @@ func warnPlainHTTP(log *slog.Logger, opts Options) {
"listen", opts.Listen)
}
// wireHarness attaches the setup terminal to the daemon's session contract
// wireHarness attaches the setup terminal and the run-scoped sandbox view to the daemon's session contract
// when the operator configured one, and registers its cleanup.
func wireHarness(opts Options, srv *webui.Server, cleanups *[]func()) error {
if opts.Harness.Target == "" {
return nil
}
harness, closeHarness, err := harnessrpc.Dial(opts.Harness.Target, opts.Harness.Token)
harness, closeHarness, err := harnessrpc.Dial(opts.Harness.Target, opts.identity)
if err != nil {
return err
}
srv.HarnessTerminal = harness
srv.SandboxView = harness
*cleanups = append(*cleanups, closeHarness)
return nil
}
+2 -2
View File
@@ -15,7 +15,7 @@ import (
type Writer struct {
Enqueue func(
ctx context.Context,
owner, repo, title, body, workflow, identity, origin string,
owner, repo, title, body, workflow, identity, origin, draft string,
inputs map[string]any,
) (*workflow.Task, error)
}
@@ -25,7 +25,7 @@ func (a Writer) EnqueueChatTask(
owner, repo, title, body, workflow, identity, origin string,
inputs map[string]any,
) (int64, error) {
task, err := a.Enqueue(ctx, owner, repo, title, body, workflow, identity, origin, inputs)
task, err := a.Enqueue(ctx, owner, repo, title, body, workflow, identity, origin, "", inputs)
if err != nil {
return 0, err
}
@@ -1,73 +0,0 @@
package controlplane_test
import (
"encoding/json"
"testing"
"github.com/samcharles93/archie-core/internal/app/controlplane"
pb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
"github.com/samcharles93/archie-core/internal/infrastructure/controlplanerpc"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
"github.com/samcharles93/archie-core/internal/infrastructure/workflowsteps"
)
func TestStoredChannelSettingsCanBeEdited(t *testing.T) {
ctx := t.Context()
db := pgstore.Open(t)
if err := db.BootstrapIdentities(ctx, nil); err != nil {
t.Fatal(err)
}
if err := db.UpgradeDefaultOrg(ctx); err != nil {
t.Fatal(err)
}
steps, err := workflowsteps.NewManager()
if err != nil {
t.Fatal(err)
}
server, err := controlplane.NewServer(db, steps)
if err != nil {
t.Fatal(err)
}
client := workflowRPC(t, server, db).ControlPlane()
stored, err := db.PutResource(ctx, storecontract.ResourceWrite{
OrgID: storecontract.DefaultOrgID, Kind: controlplane.ChannelSettingsKind,
Value: []byte(`{"email":{"listen_addr":""},"webhook":{},"webhook_addr":"","telegram":{"allowed_user_ids":[42],"token_ref":{"engine":"bws","key":"telegram"}},"workspace":"/workspace","max_steps":17,"rate_limit":{"window":"30s","max_requests":5}}`),
Actor: "operator", Source: "test", RequestID: "old-settings",
})
if err != nil {
t.Fatal(err)
}
got, err := client.Query(ctx, &pb.QueryRequest{Kind: controlplane.ChannelSettingsKind})
if err != nil {
t.Fatal(err)
}
var settings controlplanerpc.ChannelSettings
if err := json.Unmarshal(got.Resource.ValueJson, &settings); err != nil {
t.Fatal(err)
}
var document map[string]json.RawMessage
if err := json.Unmarshal(got.Resource.ValueJson, &document); err != nil {
t.Fatal(err)
}
for _, retired := range []string{"email", "webhook", "webhook_addr"} {
if _, exists := document[retired]; exists {
t.Fatalf("served retired %s field in editable settings", retired)
}
}
if settings.Telegram.Token.Key != "telegram" || len(settings.Telegram.AllowedUserIDs) != 1 || settings.Telegram.AllowedUserIDs[0] != 42 || settings.Workspace != "/workspace" || settings.MaxSteps != 17 || settings.RateLimit.MaxRequests != 5 {
t.Fatalf("lost supported settings: %+v", settings)
}
settings.Telegram.AllowedUserIDs = []int64{42, 43}
value, err := json.Marshal(settings)
if err != nil {
t.Fatal(err)
}
changed, err := client.Command(ctx, &pb.CommandRequest{Kind: controlplane.ChannelSettingsKind, Command: "replace", ValueJson: value, ExpectedVersion: got.Resource.Version, Actor: "operator", Source: "test", RequestId: "edit"})
if err != nil {
t.Fatalf("saving edited channel settings: %v", err)
}
if changed.Resource.Version != stored.Version+1 {
t.Fatalf("saved version %d", changed.Resource.Version)
}
}
@@ -1,143 +0,0 @@
package controlplane_test
import (
"context"
"net"
"strings"
"testing"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/status"
"github.com/samcharles93/archie-core/internal/app/controlplane"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/access"
"github.com/samcharles93/archie-core/internal/domain/identity"
"github.com/samcharles93/archie-core/internal/domain/messaging"
"github.com/samcharles93/archie-core/internal/domain/org"
"github.com/samcharles93/archie-core/internal/gateway"
"github.com/samcharles93/archie-core/internal/infrastructure/controlplanerpc"
"github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
"github.com/samcharles93/archie-core/internal/infrastructure/rpcidentity"
"github.com/samcharles93/archie-core/internal/infrastructure/workflowsteps"
)
func TestWebChatSettingsActor(t *testing.T) {
ctx := t.Context()
db := pgstore.Open(t)
if err := db.BootstrapIdentities(ctx, nil); err != nil {
t.Fatal(err)
}
if err := db.UpgradeDefaultOrg(ctx); err != nil {
t.Fatal(err)
}
steps, err := workflowsteps.NewManager()
if err != nil {
t.Fatal(err)
}
cp, err := controlplane.NewServer(db, steps)
if err != nil {
t.Fatal(err)
}
if _, _, err := cp.ImportConfig(ctx, config.Config{}); err != nil {
t.Fatal(err)
}
state := workflowRPC(t, cp, db)
router := gateway.NewRouter(state, nil, "web")
router.Settings = messaging.NewSettingsCommand(controlplanerpc.NewSettingsClient(state.ControlPlane())).WithIdentities(state)
listener, err := (&net.ListenConfig{}).Listen(ctx, "tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
callers := rpcidentity.Callers{Principals: state}
srv := grpc.NewServer(grpc.ChainUnaryInterceptor(gatewayrpc.UnaryServerInterceptor("gateway-secret"), callers.Unary()), grpc.ChainStreamInterceptor(gatewayrpc.StreamServerInterceptor("gateway-secret"), callers.Stream()))
gatewayrpc.RegisterServer(srv, &gateway.LocalChatAdapter{Router: router}, nil, gatewayrpc.Catalog{})
go func() { _ = srv.Serve(listener) }()
t.Cleanup(srv.Stop)
person, err := db.PrincipalFor(ctx, identity.OperatorID())
if err != nil {
t.Fatal(err)
}
tests := []struct {
name, token, sender string
person, write, stream bool
code codes.Code
}{
{name: "streamed signed-in person", stream: true, token: "gateway-secret", person: true, write: true},
{name: "streamed wrong service credential", stream: true, token: "wrong", person: true, code: codes.Unauthenticated},
{name: "signed-in person", token: "gateway-secret", person: true, write: true},
{name: "message cannot spoof actor", token: "gateway-secret", sender: string(identity.SystemID), person: true, write: true},
{name: "message alone cannot name a person", token: "gateway-secret", sender: string(identity.OperatorID())},
{name: "wrong service credential cannot forward a principal", token: "wrong", person: true, code: codes.Unauthenticated},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
conn, err := grpc.NewClient(listener.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithUnaryInterceptor(gatewayrpc.UnaryClientTokenInterceptor(tt.token)), grpc.WithStreamInterceptor(gatewayrpc.StreamClientTokenInterceptor(tt.token)))
if err != nil {
t.Fatal(err)
}
defer conn.Close()
requestCtx := ctx
if tt.person {
requestCtx = access.WithPrincipal(ctx, person)
}
before, err := db.Resource(ctx, string(org.DefaultOrgID), controlplane.ReviewSettingsKind)
if err != nil {
t.Fatal(err)
}
in := messaging.Inbound{Platform: "web", Message: messaging.Message{SenderID: tt.sender, Text: "/settings set review-settings precision_gate=true"}}
client := gatewayrpc.NewClient(conn)
reply, err := settingsReply(t, client, requestCtx, in, tt.stream, tt.code)
if status.Code(err) != tt.code {
t.Fatalf("route error = %v, want %s", err, tt.code)
}
after, err := db.Resource(ctx, string(org.DefaultOrgID), controlplane.ReviewSettingsKind)
if err != nil {
t.Fatal(err)
}
if !tt.write {
if after.Version != before.Version {
t.Fatal("unauthenticated command changed settings")
}
return
}
history, err := db.ResourceHistory(ctx, string(org.DefaultOrgID), controlplane.ReviewSettingsKind, 1)
if err != nil {
t.Fatal(err)
}
if len(history) != 1 {
t.Fatal("settings audit missing")
}
if !strings.Contains(reply.Text, "Updated review-settings") || after.Version != before.Version+1 || history[0].Actor != string(person.IdentityID) {
t.Fatalf("reply %q, version %d -> %d, actor %q", reply.Text, before.Version, after.Version, history[0].Actor)
}
})
}
}
func settingsReply(t *testing.T, client *gatewayrpc.Client, ctx context.Context, in messaging.Inbound, stream bool, want codes.Code) (messaging.ChatReply, error) {
t.Helper()
if !stream {
return client.Route(ctx, in)
}
events, err := client.Stream(ctx, in)
if err != nil {
return messaging.ChatReply{}, err
}
var reply messaging.ChatReply
for event := range events {
if event.Kind == "error" {
if want == codes.OK || !strings.Contains(event.Text, "code = "+want.String()) {
t.Fatalf("stream: %s", event.Text)
}
return messaging.ChatReply{}, status.Error(want, event.Text)
}
if event.Kind == "done" {
reply.Text = event.Text
}
}
return reply, nil
}
+13
View File
@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"time"
"google.golang.org/grpc"
@@ -70,6 +71,12 @@ func (c *WorkflowDefinitionsClient) WorkflowDefinitions(ctx context.Context) (wo
return definitions, response.Resource.Version, err
}
// Keep reads the collection now and every interval after, so the apply status
// is reported without waiting for the first workflow to resolve.
func (c *WorkflowDefinitionsClient) Keep(ctx context.Context, interval time.Duration) {
keepLoading(ctx, interval, func() { _, _, _ = c.WorkflowDefinitions(ctx) })
}
// ReplaceWorkflowDefinitions replaces the collection, keeping the previous
// value in history.
func (c *WorkflowDefinitionsClient) ReplaceWorkflowDefinitions(ctx context.Context, definitions workflow.WorkflowDefinitionCollection, expectedVersion int64, actor, source, requestID string) (int64, error) {
@@ -240,6 +247,12 @@ func sendUpdate[T any](ctx context.Context, out chan<- T, update T) bool {
}
}
// KeepSchedules reads the schedules now and every interval after, so the apply
// status is reported before the scheduler first polls.
func (c *Client) KeepSchedules(ctx context.Context, interval time.Duration) {
keepLoading(ctx, interval, func() { _, _, _ = c.Schedules(ctx) })
}
func (c *Client) Schedules(ctx context.Context) ([]scheduling.JobSpec, int64, error) {
response, err := c.rpc.Query(ctx, &pb.QueryRequest{Kind: SchedulesKind})
if err != nil {
+14 -1
View File
@@ -162,9 +162,22 @@ func (s *Server) Audit(ctx context.Context, request *pb.AuditRequest) (*pb.Audit
func (s *Server) Command(ctx context.Context, request *pb.CommandRequest) (*pb.CommandResponse, error) {
definition, ok := s.definitions[request.GetKind()]
if !ok || request.GetCommand() != "replace" {
command := request.GetCommand()
if !ok || (command != "replace" && command != "validate") {
return nil, status.Error(codes.NotFound, "resource or command not found")
}
if command == "validate" {
// The same checks a replace runs, without writing: a caller can learn
// that a document would be refused before it asks for the change.
value, err := definition.Decode(request.ValueJson)
if err == nil {
err = s.checkOrgWrite(ctx, requestOrg(ctx), request.Kind, value)
}
if err != nil {
return nil, mapError(err)
}
return &pb.CommandResponse{}, nil
}
if request.GetActor() == "" || request.GetSource() == "" || request.GetRequestId() == "" {
return nil, status.Error(codes.InvalidArgument, "actor, source, and request ID are required")
}
@@ -0,0 +1,27 @@
package controlplane
import (
"errors"
"testing"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
)
func TestInstanceOnlyKindsRefuseOtherOrgs(t *testing.T) {
tests := []struct {
name, org, kind string
refused bool
}{
{"another org writes an instance setting", "acme", ToolSettingsKind, true},
{"the system org writes an instance setting", storecontract.DefaultOrgID, ToolSettingsKind, false},
{"another org writes an org-scoped kind", "acme", PersonasKind, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := (&Server{}).checkOrgWrite(t.Context(), tt.org, tt.kind, []byte(`{}`))
if refused := errors.Is(err, ErrValidation); refused != tt.refused {
t.Fatalf("refused = %v, want %v (err %v)", refused, tt.refused, err)
}
})
}
}
+13 -1
View File
@@ -152,11 +152,23 @@ func (s *Server) readResource(ctx context.Context, orgID, kind string, into any)
return nil
}
// instanceOnlyKinds are the kinds the runtime layers from the system org's
// copy alone. Another org's write would be stored and never applied.
var instanceOnlyKinds = map[string]bool{
RepositoryPoliciesKind: true, ChannelSettingsKind: true, SchedulingPolicyKind: true,
ReviewSettingsKind: true, TaskPolicyKind: true, ToolSettingsKind: true,
PluginSettingsKind: true, ContainerRuntimePoliciesKind: true, AgentProfileKind: true,
ExtensionSettingsKind: true, UpdateSettingsKind: true, WorkflowExecutionSettingsKind: true,
}
// checkOrgWrite applies the rules a resource's static validation cannot: the
// policy is the system org's alone, an org's providers need its policy's
// leave and its own credentials, and every alias must name a model the
// writing org may use.
// writing org may use. Instance settings are refused from any other org.
func (s *Server) checkOrgWrite(ctx context.Context, orgID, kind string, value []byte) error {
if instanceOnlyKinds[kind] && orgID != storecontract.DefaultOrgID {
return fmt.Errorf("%w: %s is an instance setting and only the system org writes it", ErrValidation, kind)
}
switch kind {
case OrgModelPolicyKind:
if orgID != storecontract.DefaultOrgID {
@@ -1,102 +0,0 @@
package controlplane_test
import (
"context"
"maps"
"slices"
"strings"
"testing"
"time"
"github.com/samcharles93/archie-core/internal/app/controlplane"
pb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
"github.com/samcharles93/archie-core/internal/domain/identity"
"github.com/samcharles93/archie-core/internal/domain/org"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
"github.com/samcharles93/archie-core/internal/infrastructure/workflowsteps"
)
// An org reaches only the models the instance admin allows it and the
// providers it was allowed to add; an org with no policy reaches nothing.
func TestOrgModelPolicy(t *testing.T) {
ctx := t.Context()
db := pgstore.Open(t)
if err := db.BootstrapIdentities(ctx, nil); err != nil {
t.Fatal(err)
}
if err := db.UpgradeDefaultOrg(ctx); err != nil {
t.Fatal(err)
}
steps, err := workflowsteps.NewManager()
if err != nil {
t.Fatal(err)
}
server, err := controlplane.NewServer(db, steps)
if err != nil {
t.Fatal(err)
}
owner, err := db.Create(ctx, identity.Identity{ID: "owner", Kind: identity.KindUser, DisplayName: "Owner", Lifecycle: identity.LifecycleActive}, identity.Audit{ActorID: identity.SystemID, Source: "test", RequestID: "owner", At: time.Now()})
if err != nil {
t.Fatal(err)
}
for _, id := range []org.OrgID{"acme", "newco"} {
if _, err := db.CreateOrg(ctx, org.Org{ID: id, Name: string(id)}, owner.ID); err != nil {
t.Fatal(err)
}
}
sys := org.WithOrg(ctx, org.DefaultOrgID)
acme := org.WithOrg(ctx, "acme")
put := func(ctx context.Context, kind, value string) error {
_, err := server.Command(ctx, &pb.CommandRequest{Kind: kind, Command: "replace", ValueJson: []byte(value), Actor: "test", Source: "test", RequestId: kind + value})
return err
}
for _, w := range [][2]string{
{controlplane.ProviderSettingsKind, `{"openai":{"class":"openai","api_key_ref":{}},"deepseek":{"class":"deepseek","api_key_ref":{}}}`},
{controlplane.ModelAliasesKind, `{"default":"openai/gpt-6-luna","cheap":"deepseek/chat"}`},
{controlplane.OrgModelPolicyKind, `{"acme":{"allowed":["openai/*"],"own_providers":true}}`},
} {
if err := put(sys, w[0], w[1]); err != nil {
t.Fatalf("seed %s: %v", w[0], err)
}
}
for _, tt := range []struct {
name, kind, value string
ok bool
}{
{"an alias to a model the org may not use", controlplane.ModelAliasesKind, `{"fast":"deepseek/chat"}`, false},
{"an org provider named like an instance one", controlplane.ProviderSettingsKind, `{"openai":{"class":"openai","api_key_ref":{}}}`, false},
{"an org provider pointing at a secret", controlplane.ProviderSettingsKind, `{"mine":{"class":"openai","api_key_ref":{"engine":"env","key":"X"}}}`, false},
{"an org writing the instance policy", controlplane.OrgModelPolicyKind, `{"acme":{"allowed":["deepseek/*"]}}`, false},
{"an org provider of its own", controlplane.ProviderSettingsKind, `{"mine":{"class":"openai","api_key_ref":{}}}`, true},
{"aliases to allowed and own models", controlplane.ModelAliasesKind, `{"fast":"openai/gpt-6-mini","own":"mine/m1"}`, true},
} {
t.Run(tt.name, func(t *testing.T) {
if err := put(acme, tt.kind, tt.value); (err == nil) != tt.ok {
t.Fatalf("err = %v, want ok %v", err, tt.ok)
}
})
}
for _, tt := range []struct {
org string
aliases, prov []string
}{
{"acme", []string{"default", "fast", "own"}, []string{"mine"}},
{"newco", nil, nil},
{string(org.DefaultOrgID), []string{"cheap", "default"}, nil},
} {
t.Run("resolve "+tt.org, func(t *testing.T) {
models, err := server.ModelsFor(ctx, tt.org)
if err != nil {
t.Fatal(err)
}
if got := slices.Sorted(maps.Keys(models.Aliases)); strings.Join(got, ",") != strings.Join(tt.aliases, ",") {
t.Fatalf("aliases = %v, want %v", got, tt.aliases)
}
if got := slices.Sorted(maps.Keys(models.Providers)); strings.Join(got, ",") != strings.Join(tt.prov, ",") {
t.Fatalf("providers = %v, want %v", got, tt.prov)
}
})
}
}
+50 -13
View File
@@ -10,6 +10,7 @@ import (
pb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
"github.com/samcharles93/archie-core/internal/domain/applystatus"
"github.com/samcharles93/archie-core/internal/domain/eda/playbook"
"github.com/samcharles93/archie-core/internal/domain/org"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
"github.com/samcharles93/archie-core/internal/infrastructure/controlplanerpc"
)
@@ -26,50 +27,86 @@ type LivePlaybooks struct {
log *slog.Logger
ApplyStatus *applystatus.Reporter
mu sync.Mutex
mu sync.Mutex
orgs map[org.OrgID]*orgPlaybooks
}
// orgPlaybooks is one org's compiled set and the version it came from.
type orgPlaybooks struct {
version int64
store *playbook.Store
}
func NewLivePlaybooks(client pb.ControlPlaneServiceClient, log *slog.Logger) *LivePlaybooks {
return &LivePlaybooks{rpc: client, log: log}
return &LivePlaybooks{rpc: client, log: log, orgs: map[org.OrgID]*orgPlaybooks{}}
}
// Keep loads the default org's playbooks now and every interval after, so the
// apply status is reported without waiting for the first dispatch.
func (l *LivePlaybooks) Keep(ctx context.Context, interval time.Duration) {
keepLoading(ctx, interval, func() { l.current(ctx) })
}
// keepLoading runs load now and every interval until ctx ends.
func keepLoading(ctx context.Context, interval time.Duration, load func()) {
load()
go func() {
ticker := time.NewTicker(interval)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
load()
}
}
}()
}
// current reads the playbooks of the org ctx acts in; the query carries that
// org, so a task is matched against its own org's document.
func (l *LivePlaybooks) current(ctx context.Context) *playbook.Store {
l.mu.Lock()
defer l.mu.Unlock()
id := org.OrgFromContext(ctx)
held := l.orgs[id]
if held == nil {
held = &orgPlaybooks{}
l.orgs[id] = held
}
ctx, cancel := context.WithTimeout(ctx, playbookQueryTimeout)
defer cancel()
response, err := l.rpc.Query(ctx, &pb.QueryRequest{Kind: PlaybooksKind})
if err != nil {
l.ApplyStatus.Report(ctx, PlaybooksKind, 0, err)
l.log.Warn("eda playbooks unavailable; keeping the last good set", "err", controlplanerpc.ClientError(err))
return l.store
return held.store
}
if l.store != nil && response.Resource.Version == l.version {
l.ApplyStatus.Report(ctx, PlaybooksKind, l.version, nil)
return l.store
if held.store != nil && response.Resource.Version == held.version {
l.ApplyStatus.Report(ctx, PlaybooksKind, held.version, nil)
return held.store
}
var collection PlaybookCollection
if err := json.Unmarshal(response.Resource.ValueJson, &collection); err != nil {
l.ApplyStatus.Report(ctx, PlaybooksKind, response.Resource.Version, err)
l.log.Error("eda playbooks undecodable; keeping the last good set", "err", err)
return l.store
return held.store
}
store, err := CompilePlaybooks(collection)
if err != nil {
l.ApplyStatus.Report(ctx, PlaybooksKind, response.Resource.Version, err)
l.log.Error("eda playbooks do not compile; keeping the last good set", "err", err)
return l.store
return held.store
}
l.version, l.store = response.Resource.Version, store
l.ApplyStatus.Report(ctx, PlaybooksKind, l.version, nil)
l.log.Info("eda playbooks loaded", "version", l.version, "playbooks", len(store.Playbooks))
held.version, held.store = response.Resource.Version, store
l.ApplyStatus.Report(ctx, PlaybooksKind, held.version, nil)
l.log.Info("eda playbooks loaded", "org", id, "version", held.version, "playbooks", len(store.Playbooks))
return store
}
func (l *LivePlaybooks) Dispatch(input playbook.DispatchInput) (playbook.Decision, bool) {
return l.current(context.Background()).Dispatch(input)
func (l *LivePlaybooks) Dispatch(ctx context.Context, input playbook.DispatchInput) (playbook.Decision, bool) {
return l.current(ctx).Dispatch(input)
}
func (l *LivePlaybooks) Run(ctx context.Context, ledger storecontract.PlaybookDispatcher, log *slog.Logger, input playbook.DispatchInput) error {
+2 -2
View File
@@ -124,12 +124,12 @@ func runtimeConfigFrom(ctx context.Context, reader controlplanerpc.ResourceReade
}
func runtimeToolConfigFrom(ctx context.Context, reader controlplanerpc.ResourceReader, versions map[string]int64, out config.Config) (config.Config, map[string]int64, error) {
policy := taskPolicy{DiffCapLines: out.DiffCap(), NotifyWebhook: out.Notify.Webhook}
policy := taskPolicyOf(out)
if err := layerResourceJSON(ctx, reader, versions, TaskPolicyKind, &policy); err != nil {
return config.Config{}, nil, err
}
out.DiffCapLines = new(policy.DiffCapLines)
out.Notify.Webhook = policy.NotifyWebhook
out.Notify = config.Notify{Webhook: policy.NotifyWebhook, MinSeverity: policy.NotifyMinSeverity, Secret: policy.NotifySecret}
if err := layerResource(ctx, reader, versions, ToolSettingsKind, func(settings toolSettings) error {
headers := make(map[string]map[string]string, len(out.Tools.MCPServers))
+19 -3
View File
@@ -5,18 +5,21 @@ import (
"net/url"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/alert"
)
const TaskPolicyKind = "task-policy"
type taskPolicy struct {
DiffCapLines int `json:"diff_cap_lines"`
NotifyWebhook string `json:"notify_webhook"`
DiffCapLines int `json:"diff_cap_lines"`
NotifyWebhook string `json:"notify_webhook"`
NotifyMinSeverity string `json:"notify_min_severity"`
NotifySecret config.SecretRef `json:"notify_secret"`
}
func taskPolicyDefinition() Definition {
return Definition{Kind: TaskPolicyKind, Title: "Task policy", ApplyMode: "live", Document: taskPolicy{}, Seed: func(cfg config.Config) any {
return taskPolicy{DiffCapLines: cfg.DiffCap(), NotifyWebhook: cfg.Notify.Webhook}
return taskPolicyOf(cfg)
}, Validate: func(input []byte) error {
return validateAs(input, func(doc taskPolicy) error {
if doc.DiffCapLines < 0 {
@@ -28,7 +31,20 @@ func taskPolicyDefinition() Definition {
return fmt.Errorf("notify_webhook must be an HTTP or HTTPS URL")
}
}
if !alert.Severity(doc.NotifyMinSeverity).Valid() && doc.NotifyMinSeverity != "" {
return fmt.Errorf("notify_min_severity must be info, warning or action")
}
if (doc.NotifySecret.Engine == "") != (doc.NotifySecret.Key == "") {
return fmt.Errorf("notify_secret needs both an engine and a key")
}
return nil
})
}}
}
func taskPolicyOf(cfg config.Config) taskPolicy {
return taskPolicy{
DiffCapLines: cfg.DiffCap(), NotifyWebhook: cfg.Notify.Webhook,
NotifyMinSeverity: cfg.Notify.MinSeverity, NotifySecret: cfg.Notify.Secret,
}
}
@@ -1,209 +0,0 @@
package controlplane_test
import (
"context"
"encoding/json"
"net"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
"time"
"google.golang.org/grpc"
"github.com/samcharles93/archie-core/internal/app/controlplane"
"github.com/samcharles93/archie-core/internal/config"
pb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
"github.com/samcharles93/archie-core/internal/domain/access"
"github.com/samcharles93/archie-core/internal/domain/identity"
"github.com/samcharles93/archie-core/internal/domain/org"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
"github.com/samcharles93/archie-core/internal/domain/workflow"
infraaccess "github.com/samcharles93/archie-core/internal/infrastructure/access"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest"
"github.com/samcharles93/archie-core/internal/infrastructure/rpcidentity"
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
"github.com/samcharles93/archie-core/internal/infrastructure/workflowsteps"
"github.com/samcharles93/archie-core/internal/webui"
)
func TestMain(m *testing.M) { os.Exit(pgtest.Main(m)) }
func TestOrgWorkflowResources(t *testing.T) {
for _, kind := range []string{controlplane.WorkflowDefinitionsKind, controlplane.WorkflowEnablementKind} {
t.Run(kind, func(t *testing.T) {
ctx := t.Context()
db := pgstore.Open(t)
if err := db.BootstrapIdentities(ctx, nil); err != nil {
t.Fatal(err)
}
if err := db.UpgradeDefaultOrg(ctx); err != nil {
t.Fatal(err)
}
steps, err := workflowsteps.NewManager()
if err != nil {
t.Fatal(err)
}
server, err := controlplane.NewServer(db, steps)
if err != nil {
t.Fatal(err)
}
if _, _, err := server.ImportConfig(ctx, config.Config{}); err != nil {
t.Fatal(err)
}
owner, err := db.Create(ctx, identity.Identity{ID: "acme-owner", Kind: identity.KindUser, DisplayName: "Owner", Lifecycle: identity.LifecycleActive}, identity.Audit{ActorID: identity.SystemID, Source: "test", RequestID: "owner", At: time.Now()})
if err != nil {
t.Fatal(err)
}
if _, err := db.CreateOrg(ctx, org.Org{ID: "acme", Name: "Acme"}, owner.ID); err != nil {
t.Fatal(err)
}
client := workflowRPC(t, server, db)
principal, err := db.PrincipalFor(ctx, owner.ID)
if err != nil {
t.Fatal(err)
}
other := access.WithPrincipal(ctx, principal)
initial, err := client.ControlPlane().Query(other, &pb.QueryRequest{Kind: kind})
if err != nil {
t.Fatalf("new org cannot read its shipped %s: %v", kind, err)
}
if initial.Resource.OrgId != "acme" {
t.Fatalf("read org %q", initial.Resource.OrgId)
}
value := []byte(`{"orgs":{"acme":{"disabled":["tdd"]}}}`)
if kind == controlplane.WorkflowDefinitionsKind {
collection := workflow.ShippedDefinitions()
collection.Definitions = append(collection.Definitions, workflow.WorkflowDefinitionEntry{ID: "acme-only", YAML: "id: acme-only\nrepository: none\nsteps:\n - type: workflow.finish\n"})
value, err = json.Marshal(collection)
if err != nil {
t.Fatal(err)
}
}
changed, err := client.ControlPlane().Command(other, &pb.CommandRequest{Kind: kind, Command: "replace", ValueJson: value, ExpectedVersion: initial.Resource.Version, Actor: "owner", Source: "test", RequestId: "edit"})
if err != nil {
t.Fatal(err)
}
if _, _, err := server.ImportConfig(ctx, config.Config{}); err != nil {
t.Fatal(err)
}
for _, tc := range []struct {
ctxOrg org.OrgID
want bool
}{{"acme", true}, {org.DefaultOrgID, false}} {
queryCtx := ctx
if tc.ctxOrg == "acme" {
queryCtx = other
}
got, err := client.ControlPlane().Query(queryCtx, &pb.QueryRequest{Kind: kind})
if err != nil {
t.Fatal(err)
}
if strings.Contains(string(got.Resource.ValueJson), "acme") != tc.want {
t.Fatalf("org %q got %s", tc.ctxOrg, got.Resource.ValueJson)
}
if tc.want && got.Resource.Version != changed.Resource.Version {
t.Fatalf("boot replaced operator's document")
}
}
if kind == controlplane.WorkflowDefinitionsKind {
checkWorkflowDashboard(t, db, client)
}
})
}
}
func workflowRPC(t *testing.T, control *controlplane.Server, db *pgstore.TaskDB) *staterpc.Client {
t.Helper()
listener, err := (&net.ListenConfig{}).Listen(t.Context(), "tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = listener.Close() })
grants := &staterpc.TaskGrants{}
callers := rpcidentity.Callers{Principals: db}
srv := grpc.NewServer(grpc.ChainUnaryInterceptor(grants.UnaryInterceptor("test-token"), callers.Unary()), grpc.ChainStreamInterceptor(grants.StreamInterceptor("test-token"), callers.Stream()))
staterpc.RegisterServer(srv, staterpc.Deps{ControlPlane: control, Tasks: db, Principals: db, Identities: db})
t.Cleanup(srv.Stop)
go func() { _ = srv.Serve(listener) }()
client, closeClient, err := staterpc.Dial(listener.Addr().String(), "archie-ui", "test-token")
if err != nil {
t.Fatal(err)
}
t.Cleanup(closeClient)
return client
}
func TestValidateStoredOrgWorkflows(t *testing.T) {
ctx := t.Context()
db := pgstore.Open(t)
if err := db.BootstrapIdentities(ctx, nil); err != nil {
t.Fatal(err)
}
if err := db.UpgradeDefaultOrg(ctx); err != nil {
t.Fatal(err)
}
steps, err := workflowsteps.NewManager()
if err != nil {
t.Fatal(err)
}
server, err := controlplane.NewServer(db, steps)
if err != nil {
t.Fatal(err)
}
if _, err := db.CreateOrg(ctx, org.Org{ID: "acme", Name: "Acme"}, identity.SystemID); err != nil {
t.Fatal(err)
}
if _, err := db.PutResource(ctx, storecontract.ResourceWrite{OrgID: "acme", Kind: controlplane.WorkflowDefinitionsKind, Value: []byte(`{"definitions":[{"id":"broken","yaml":"id: broken\nsteps:\n - type: nonexistent\n"}]}`), Actor: "owner", Source: "test", RequestID: "invalid"}); err != nil {
t.Fatal(err)
}
if _, err := server.ValidateStored(ctx); err == nil || !strings.Contains(err.Error(), "acme") {
t.Fatalf("invalid org workflow was not reported: %v", err)
}
}
func checkWorkflowDashboard(t *testing.T, db *pgstore.TaskDB, client *staterpc.Client) {
t.Helper()
ctx := t.Context()
policies := append(access.ShippedOrgPolicies("acme"), access.ShippedOrgPolicies(org.DefaultOrgID)...)
chain := infraaccess.New(policies)
srv := &webui.Server{Store: client, ControlPlane: client.ControlPlane(), Access: chain, Principals: client, Authenticate: func(ctx context.Context, token string) (identity.Identity, error) {
return db.Get(ctx, identity.IdentityID(token))
}}
handler := srv.Handler()
for _, tc := range []struct {
method, path, body string
status int
}{
{"GET", "/api/workflows", "", http.StatusOK},
{"POST", "/api/work-requests", `{"identity":"acme-owner","workflow":"acme-only","title":"Org work","instructions":"Finish"}`, http.StatusCreated},
} {
r := httptest.NewRequestWithContext(ctx, tc.method, tc.path, strings.NewReader(tc.body))
r.Header.Set("Authorization", "Bearer acme-owner")
r.Header.Set("Content-Type", "application/json")
r.Header.Set("X-Archie-CSRF", "1")
w := httptest.NewRecorder()
handler.ServeHTTP(w, r)
if w.Code != tc.status {
t.Fatalf("%s %s: %d %s", tc.method, tc.path, w.Code, w.Body.String())
}
if tc.method == "GET" && !strings.Contains(w.Body.String(), "acme-only") {
t.Fatalf("dashboard omitted the org's workflow: %s", w.Body.String())
}
if tc.method == "POST" {
var reply struct {
TaskID int64 `json:"task_id"`
}
if err := json.Unmarshal(w.Body.Bytes(), &reply); err != nil {
t.Fatal(err)
}
run, err := db.TaskByID(ctx, reply.TaskID)
if err != nil || run.Org != "acme" || run.Workflow != "acme-only" {
t.Fatalf("admitted task %#v err %v", run, err)
}
}
}
}
+48
View File
@@ -0,0 +1,48 @@
package servicekit
import (
"context"
"net"
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
)
// maxConcurrentStreams caps the calls one connection holds open at once, so a
// single client cannot pin unbounded server memory. It is far above what a
// service's own clients open: a few watches plus in-flight calls.
const maxConcurrentStreams = 256
// ServerLimits bounds what one peer can hold on a service's gRPC server: open
// streams per connection, the handshake, and a dead peer's streams, which the
// server's keepalive pings detect and release instead of holding them until
// the OS gives up on the socket.
func ServerLimits() []grpc.ServerOption {
return []grpc.ServerOption{
grpc.MaxConcurrentStreams(maxConcurrentStreams),
grpc.ConnectionTimeout(10 * time.Second),
grpc.KeepaliveParams(keepalive.ServerParameters{
Time: time.Minute,
Timeout: 20 * time.Second,
}),
}
}
// Serve serves server on listener until ctx ends, then drains in-flight calls
// for up to 10 seconds before cancelling them: a streaming call can stay open
// indefinitely and would otherwise hold shutdown. A listener failure is
// returned, so the process exits rather than staying up with nothing serving.
func Serve(ctx context.Context, server *grpc.Server, listener net.Listener) error {
serveErr := make(chan error, 1)
go func() { serveErr <- server.Serve(listener) }()
select {
case <-ctx.Done():
timer := time.AfterFunc(10*time.Second, server.Stop)
server.GracefulStop()
timer.Stop()
return nil
case err := <-serveErr:
return err
}
}
+8 -2
View File
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log/slog"
"slices"
"github.com/samcharles93/archie-core/internal/app/controlplane"
"github.com/samcharles93/archie-core/internal/config"
@@ -15,8 +16,10 @@ import (
// RuntimeConfig layers the control plane's stored settings over base, lets
// adjust apply the caller's own live settings, then validates the result and
// resolves its provider secrets. The outcome is reported for every layered
// kind, so a refused document keeps the version still running on the record.
func RuntimeConfig(ctx context.Context, cp *controlplane.Client, status *applystatus.Reporter, secrets *secret.Registry, log *slog.Logger, base config.Config, adjust func(*config.Config)) (config.Config, map[string]int64, error) {
// kind in reportKinds (every kind when nil), so a refused document keeps the
// version still running on the record and a process never reports a kind it
// does not re-apply live.
func RuntimeConfig(ctx context.Context, cp *controlplane.Client, status *applystatus.Reporter, secrets *secret.Registry, log *slog.Logger, base config.Config, adjust func(*config.Config), reportKinds []string) (config.Config, map[string]int64, error) {
cfg, versions, err := cp.RuntimeConfig(ctx, base)
if err != nil {
return config.Config{}, nil, err
@@ -26,6 +29,9 @@ func RuntimeConfig(ctx context.Context, cp *controlplane.Client, status *applyst
}
report := func(applyErr error) {
for kind, version := range versions {
if reportKinds != nil && !slices.Contains(reportKinds, kind) {
continue
}
status.Report(ctx, kind, version, applyErr)
}
}
+16 -9
View File
@@ -2,20 +2,27 @@ package servicekit
import (
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/infrastructure/rpctls"
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
"github.com/samcharles93/archie-core/internal/secret"
)
// Identity loads service's certificate from [tls]; nil means plaintext,
// loopback only.
func Identity(cfg config.TLS, service string) (*rpctls.Identity, error) {
return rpctls.Load(cfg.CAFile, cfg.CertDir, service)
}
// StateStoreClient dials the State Store gRPC service as the caller service.
// Token resolution is the daemon's
// (it owns the config keys and the secret registry); the dial itself and the
// fail-closed non-loopback rule belong to the transport, so they come
// from staterpc.Dial. Calls wait for the State Store rather than fail while it
// is down, so boot order between services does not matter.
func StateStoreClient(caller string, services config.Services, secrets *secret.Registry) (*staterpc.Client, func(), error) {
target, err := services.RequireTarget(config.ServiceNameState)
// Calls wait for the State Store rather than fail while it is down, so boot
// order between services does not matter.
func StateStoreClient(caller string, cfg config.Config) (*staterpc.Client, func(), error) {
target, err := cfg.Services.RequireTarget(config.ServiceNameState)
if err != nil {
return nil, nil, err
}
return staterpc.Dial(target, caller, services.ResolvedToken(config.ServiceNameState, secrets.Getenv), staterpc.WaitForPeer)
id, err := Identity(cfg.TLS, caller)
if err != nil {
return nil, nil, err
}
return staterpc.Dial(target, caller, id, staterpc.WaitForPeer)
}
+195
View File
@@ -0,0 +1,195 @@
package statestore
import (
"context"
"fmt"
"slices"
"time"
"github.com/samcharles93/archie-core/internal/domain/access"
"github.com/samcharles93/archie-core/internal/domain/alert"
"github.com/samcharles93/archie-core/internal/domain/org"
"github.com/samcharles93/archie-core/internal/domain/presence"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
infraaccess "github.com/samcharles93/archie-core/internal/infrastructure/access"
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
)
const (
// alertSweepInterval is how often the store checks service health and
// prunes closed alerts.
alertSweepInterval = time.Minute
// alertRetention is how long a resolved or dismissed alert is kept.
alertRetention = 30 * 24 * time.Hour
// serviceGrace is how long a service may be unhealthy before it is worth
// an operator's attention: restarts and updates pass through it.
serviceGrace = 5 * time.Minute
)
// serviceWatch remembers since when each service has been unhealthy.
type serviceWatch struct {
since map[string]time.Time
}
// unhealthy returns the services that have been down or degraded for longer
// than serviceGrace, and forgets those that recovered. A service gone silent
// counts from its last report, which is stored, so a restart of this store does
// not restart the grace; one that never reported counts from first sight.
func (w *serviceWatch) unhealthy(mesh []presence.Service, now time.Time) []string {
if w.since == nil {
w.since = map[string]time.Time{}
}
var out []string
for _, service := range mesh {
if !slices.Contains(presence.Services(), service.Service) {
continue
}
if service.State == presence.StateUp {
delete(w.since, service.Service)
continue
}
since, ok := w.since[service.Service]
if !ok {
since = now
if service.State == presence.StateDown && !service.ReportedAt.IsZero() {
since = service.ReportedAt
}
w.since[service.Service] = since
}
if now.Sub(since) >= serviceGrace {
out = append(out, service.Service)
}
}
return out
}
func serviceAlert(name string) alert.Input {
return alert.Input{
Org: org.DefaultOrgID, Kind: alert.KindServiceUnhealthy, Subject: "service:" + name,
Severity: alert.SeverityWarning, Condition: true,
Title: name + " is unhealthy",
Body: fmt.Sprintf("Down for over %d minutes.", int(serviceGrace.Minutes())),
Link: "/settings/status",
}
}
// startSweeps starts the store's periodic work: auto-updating packages, and
// checking service health and pruning alerts.
func (b *server) startSweeps(ctx context.Context, deps staterpc.Deps) {
go b.autoUpdatePackages(ctx, deps.Packages)
if deps.Alerts != nil {
go b.sweepAlerts(ctx, deps.Alerts)
}
}
// sweepAlerts raises and clears service health alerts and prunes closed
// alerts, until ctx ends. Service health has no transition to hang an alert
// on, so it is checked here, next to the presence records it reads.
func (b *server) sweepAlerts(ctx context.Context, store alert.Store) {
pruner, _ := b.st.(alert.Pruner)
records, _ := b.st.(interface {
ListPresence(context.Context) ([]storecontract.Presence, error)
})
reporter := alert.Reporter{Raiser: store, Log: b.log, By: "state-store"}
var watch serviceWatch
ticker := time.NewTicker(alertSweepInterval)
defer ticker.Stop()
for {
if records != nil {
b.checkServices(ctx, reporter, records, &watch)
}
b.checkPolicies(ctx, reporter, store)
if pruner != nil {
if _, err := pruner.PruneAlerts(ctx, time.Now().Add(-alertRetention)); err != nil && ctx.Err() == nil {
b.log.Warn("prune alerts", "err", err)
}
}
select {
case <-ctx.Done():
return
case <-ticker.C:
}
}
}
func (b *server) checkServices(ctx context.Context, reporter alert.Reporter, records interface {
ListPresence(context.Context) ([]storecontract.Presence, error)
}, watch *serviceWatch,
) {
list, err := records.ListPresence(ctx)
if err != nil {
if ctx.Err() == nil {
b.log.Warn("service health not checked", "err", err)
}
return
}
now := time.Now()
mesh := presence.Mesh(list, now)
down := watch.unhealthy(mesh, now)
for _, service := range mesh {
if !slices.Contains(presence.Services(), service.Service) {
continue
}
// An unhealthy service still inside its grace leaves an open alert
// alone, so a restart of this store never resolves what it has raised.
raise := slices.Contains(down, service.Service)
if raise || service.State == presence.StateUp {
reporter.Sync(ctx, raise, serviceAlert(service.Service))
}
}
}
// checkPolicies raises an alert for every stored policy that does not compile
// and clears it once the policy validates. An invalid policy keeps denying its
// level, so the dashboard stays up to repair it: an instance policy asks for
// action in the system org, any other level warns in its own org. The text is
// fixed; the compile error is logged once at boot.
func (b *server) checkPolicies(ctx context.Context, reporter alert.Reporter, store alert.Store) {
policies, ok := b.st.(access.PolicyStore)
orgs, hasOrgs := b.st.(org.Repository)
if !ok || !hasOrgs {
return
}
stored, err := policies.ListPolicies(ctx)
if err != nil {
if ctx.Err() == nil {
b.log.Warn("policies not checked", "err", err)
}
return
}
invalid := map[alert.Key]bool{}
for _, problem := range infraaccess.New(stored).Problems() {
in := policyAlert(problem.Policy)
invalid[in.Key] = true
reporter.Raise(ctx, in)
}
list, err := orgs.ListOrgs(ctx)
if err != nil {
return
}
for _, o := range list {
open, err := store.ListAlerts(ctx, o.ID, alert.Filter{})
if err != nil {
continue
}
for _, a := range open {
if a.Kind == alert.KindPolicyInvalid && !invalid[a.Key] {
reporter.Resolve(ctx, a.Key)
}
}
}
}
func policyAlert(p access.Policy) alert.Input {
orgID, severity := p.OrgID, alert.SeverityWarning
if p.Level == access.LevelInstance {
orgID, severity = org.DefaultOrgID, alert.SeverityAction
}
return alert.Input{
Org: orgID, Kind: alert.KindPolicyInvalid, Subject: "policy:" + p.ID,
Severity: severity, Condition: true,
Title: fmt.Sprintf("Access policy %s is invalid", p.ID),
Body: fmt.Sprintf("The %s-level policy %s does not compile and denies everything at that level.", p.Level, p.ID),
Link: "/org/access",
}
}
+1 -1
View File
@@ -25,5 +25,5 @@ type eventCaptureStore interface { //nolint:interfacebloat // composite of the s
// openEDAStore serves the event-capture store from the State Store's Postgres
// pool, sealing binding secrets with cipher.
func (b *server) openEDAStore(cipher bindingcipher.BindingCipher) {
b.eda = postgres.NewEDA(b.pg, cipher)
b.eda = postgres.NewEDA(b.pg, cipher, b.log)
}
+71
View File
@@ -0,0 +1,71 @@
package statestore
import (
"context"
"io"
"testing"
"github.com/samcharles93/archie-core/internal/domain/org"
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
"github.com/samcharles93/archie-core/internal/logging"
)
// tasksByOrg answers TaskByID the way the store does: a scoped read sees only
// its own org's tasks.
type tasksByOrg map[int64]org.OrgID
func (t tasksByOrg) TaskByID(ctx context.Context, id int64) (*task.Task, error) {
owner, ok := t[id]
if scope, scoped := org.Scope(ctx); !ok || (scoped && scope != owner) {
return nil, nil
}
return &task.Task{ID: id}, nil
}
// everyLog has a log for every task.
type everyLog struct{}
func (everyLog) TaskLog(context.Context, int64, int, logging.Query) (logging.TaskLogPage, error) {
return logging.TaskLogPage{Found: true}, nil
}
func (everyLog) TaskLogContent(context.Context, int64, int, io.Writer) (bool, error) {
return true, nil
}
// TestOrgScopedReads pins that a caller scoped to one org reads nothing of
// another org's, while an unscoped internal service reads everything.
func TestOrgScopedReads(t *testing.T) {
logs := orgTaskLogs{TaskLogStore: everyLog{}, tasks: tasksByOrg{1: "acme"}}
reads := map[string]func(ctx context.Context) bool{
"ReadTaskLog": func(ctx context.Context) bool {
page, err := logs.TaskLog(ctx, 1, 0, logging.Query{})
return err == nil && page.Found
},
"StreamTaskLogContent": func(ctx context.Context) bool {
found, err := logs.TaskLogContent(ctx, 1, 0, io.Discard)
return err == nil && found
},
}
for _, tt := range []struct {
name string
scope org.OrgID
want bool
}{
{"unscoped service", "", true},
{"owning org", "acme", true},
{"another org", "globex", false},
} {
for rpc, read := range reads {
t.Run(rpc+"/"+tt.name, func(t *testing.T) {
ctx := context.Background()
if tt.scope != "" {
ctx = org.WithScope(ctx, tt.scope)
}
if got := read(ctx); got != tt.want {
t.Fatalf("read = %v, want %v", got, tt.want)
}
})
}
}
}
Loaded 100 of 618 files, more files were not shown because too many files have changed in this diff. Show more