diff --git a/.air.toml b/.air.toml index 4b119f6ea..82feff8c5 100644 --- a/.air.toml +++ b/.air.toml @@ -1,24 +1,20 @@ -# Live reload for archied during dashboard work. +# Live reload for the single archie binary during development. # -# The frontend has its own loop -- `task ui:dev` runs Vite with HMR and proxies -# /api and /events here -- so this watcher deliberately ignores ui/. Watching -# it would rebuild the Go binary on every keystroke in a CSS file, and -# rebuilding on ui/dist changes would loop against `task ui`. +# The frontend has its own loop -- `task dev:ui` runs Vite with HMR and proxies +# /api here -- so this watcher deliberately ignores ui/. Watching it would +# rebuild the Go binary on every keystroke in a CSS file, and rebuilding on +# ui/dist changes would loop against `task ui`. # -# ui/dist is NOT rebuilt here. During development the Vite server serves the -# frontend directly with HMR, so dist is not what you are looking at; it only -# matters for the embedded build, and `task ui` produces it before a commit. -# An earlier rule here claimed to keep dist current and never ran: air -# requires a file to satisfy include_dir AND include_file together, and ui/ is -# excluded from the walk anyway. +# Built with `-tags no_ui`: during development Vite serves the frontend +# directly with HMR, so embedding ui/dist would only slow down reloads. root = "." tmp_dir = ".air" [build] - cmd = "go build -o ./.air/archied ./cmd/archied" + cmd = "go build -tags no_ui -o ./.air/archie ./cmd/archie" # `bin` is deprecated in air; entrypoint is the current key. - entrypoint = "./.air/archied" - include_ext = ["go", "toml"] + entrypoint = "./.air/archie" + include_ext = ["go", "toml", "sql", "yaml", "cedar", "tmpl", "md"] exclude_dir = ["ui", "bin", "docs", ".git", ".task", ".air", "tmp"] exclude_regex = ["_test\\.go"] stop_on_error = true diff --git a/Taskfile.yml b/Taskfile.yml index aae5dbbc4..2ae977b83 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -136,7 +136,11 @@ tasks: - go run ./cmd/archied prbench {{.CLI_ARGS}} dev: - desc: Run development services and Vite at http://localhost:5173 + desc: Run archie (with live reload) and Vite at http://localhost:5173 + deps: [dev:archie, dev:ui] + + dev:legacy: + desc: Run the legacy multi-service stack and Vite at http://localhost:5173 deps: [dev:daemon, dev:gateway, dev:messaging, dev:state-store, dev:dashboard, dev:ui] dev:tls: @@ -175,13 +179,36 @@ tasks: exit 1 - | # docker-compose.yml creates the dev database with a superuser named - # archie; provision the least-privilege roles deployments/dev.toml - # points at. Idempotent, so this also upgrades a volume created before - # the role split. - go run ./cmd/archie-state-store provision \ - -admin-url "postgres://archie:archie@127.0.0.1:5432/archie?sslmode=disable" \ - -runtime-url "postgres://archie_runtime:archie@127.0.0.1:5432/archie?sslmode=disable" \ - -migration-url "postgres://archie_migrator:archie@127.0.0.1:5432/archie?sslmode=disable" + # archie; provision the least-privilege runtime and migrator roles + # idempotently without depending on the legacy state-store binary. + # Single-binary archie uses its own database (archie_dev) so its goose + # migration history does not collide with the legacy archie database. + docker compose exec -T postgres psql -v ON_ERROR_STOP=1 -U archie -d postgres <<'SQL' + DO $$ + BEGIN + IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'archie_migrator') THEN + CREATE ROLE archie_migrator LOGIN PASSWORD 'archie'; + ELSE + ALTER ROLE archie_migrator WITH LOGIN PASSWORD 'archie'; + END IF; + IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'archie_runtime') THEN + CREATE ROLE archie_runtime LOGIN PASSWORD 'archie'; + ELSE + ALTER ROLE archie_runtime WITH LOGIN PASSWORD 'archie'; + END IF; + END + $$; + SELECT 'CREATE DATABASE archie_dev OWNER archie_migrator' + WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'archie_dev')\gexec + GRANT CREATE, CONNECT ON DATABASE archie TO archie_migrator; + GRANT CONNECT ON DATABASE archie TO archie_runtime; + GRANT CREATE, CONNECT ON DATABASE archie_dev TO archie_migrator; + GRANT CONNECT ON DATABASE archie_dev TO archie_runtime; + SQL + docker compose exec -T postgres psql -v ON_ERROR_STOP=1 -U archie -d archie \ + -c "GRANT CREATE, USAGE ON SCHEMA public TO archie_migrator; GRANT USAGE ON SCHEMA public TO archie_runtime;" + docker compose exec -T postgres psql -v ON_ERROR_STOP=1 -U archie -d archie_dev \ + -c "GRANT CREATE, USAGE ON SCHEMA public TO archie_migrator; GRANT USAGE ON SCHEMA public TO archie_runtime;" dev:wait-state: internal: true @@ -195,78 +222,93 @@ tasks: exit 1 dev:daemon: - desc: Run archied with live reload + desc: Run legacy archied cmds: - task: dev:wait-state - - air -build.args_bin="-config-overlay,deployments/dev.toml" + - go run ./cmd/archied -config-overlay deployments/dev.toml dev:dashboard: - desc: Run the dashboard backend + desc: Run the legacy dashboard backend cmds: - go run ./cmd/archie-ui -config-overlay deployments/dev.toml dev:state-store: - desc: Run the State Store with development PostgreSQL + desc: Run the legacy State Store with development PostgreSQL deps: [dev:postgres, dev:tls] cmds: - go run ./cmd/archie-state-store -config-overlay deployments/dev.toml dev:gateway: - desc: Run the development Gateway + desc: Run the legacy development Gateway cmds: - task: dev:wait-state - go run ./cmd/archie-gateway -config-overlay deployments/dev.toml dev:messaging: - desc: Run the development Messaging Service + desc: Run the legacy development Messaging Service cmds: - task: dev:wait-state - go run ./cmd/archie-messaging -config-overlay deployments/dev.toml dev:archie: - desc: Run the single archie binary against the development PostgreSQL (admin token "dev") + desc: Run the single archie binary against the development PostgreSQL (admin token "dev", live reload via air if installed) deps: [dev:postgres] vars: DIR: tmp/dev-archie cmds: - | set -eu - mkdir -p {{.DIR}} + mkdir -p {{.DIR}}/state # Generated once: the age identity seals the dev credentials, so keep # it across runs. Roles come from dev:postgres. if [ ! -f {{.DIR}}/config.toml ]; then - umask 077 + install -m 0600 /dev/null {{.DIR}}/config.toml { - echo 'listen = "127.0.0.1:8080"' + echo 'listen = "127.0.0.1:8484"' + echo 'state_dir = "{{.ROOT_DIR}}/{{.DIR}}/state"' echo "admin_token_sha256 = \"$(printf dev | sha256sum | cut -d' ' -f1)\"" - echo "age_identity = \"$(go run ./cmd/archie -new-age-identity)\"" + echo "age_identity = \"$(go run -tags no_ui ./cmd/archie -new-age-identity)\"" echo '[database]' - echo 'url = "postgres://archie_runtime:archie@127.0.0.1:5432/archie?sslmode=disable"' - echo 'owner_url = "postgres://archie_migrator:archie@127.0.0.1:5432/archie?sslmode=disable"' + echo 'url = "postgres://archie_runtime:archie@127.0.0.1:5432/archie_dev?sslmode=disable"' + echo 'owner_url = "postgres://archie_migrator:archie@127.0.0.1:5432/archie_dev?sslmode=disable"' } > {{.DIR}}/config.toml + elif ! grep -q '^state_dir' {{.DIR}}/config.toml; then + sed -i '1i state_dir = "{{.ROOT_DIR}}/{{.DIR}}/state"' {{.DIR}}/config.toml fi - - go run ./cmd/archie -config {{.DIR}}/config.toml + - | + if command -v air >/dev/null 2>&1; then + exec air -build.args_bin="-config,{{.DIR}}/config.toml" + fi + exec go run -tags no_ui ./cmd/archie -config {{.DIR}}/config.toml dev:ui: - desc: Run Vite (requires the dashboard backend) + desc: Run Vite (proxies API requests to 127.0.0.1:8484 by default; override with ARCHIE_DEV_API) dir: ui + deps: [ui:deps] cmds: - - pnpm install - pnpm run dev + e2e:smoke: + desc: Run the single-binary smoke check against a disposable archie instance (defaults to dev:archie on 127.0.0.1:8484) + cmds: + - | + ARCHIE_SMOKE_URL="${ARCHIE_SMOKE_URL:-http://127.0.0.1:8484}" \ + ARCHIE_SMOKE_TOKEN="${ARCHIE_SMOKE_TOKEN:-dev}" \ + node e2e/archie-smoke.cjs + e2e:up: - desc: Start the local stack without Docker (PostgreSQL 18, services, Vite) and seed it + desc: Start the legacy local multi-service 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 + desc: Stop the legacy local e2e stack cmds: - bash e2e/stack.sh stop e2e:check: - desc: List browser checks; use -- all or -- CHECK to run, add --headed to watch + desc: List legacy browser checks; use -- all or -- CHECK to run, add --headed to watch cmds: - node e2e/run.cjs {{.CLI_ARGS}} @@ -288,14 +330,19 @@ tasks: - Taskfile.yml - "**/*.go" # Files the binaries embed. + - config.example.toml - "internal/**/*.sql" - "internal/**/*.yaml" - "internal/**/*.json" - "internal/**/*.tpl" + - "internal/**/*.tmpl" - "internal/**/*.md" + - "modules/**/*.cedar" + - "modules/**/*.yaml" - go.mod - go.sum - "ui/dist/**" + - ui/pages/pages.json generates: - "{{.BIN_DIR}}/archied" - "{{.BIN_DIR}}/archie-gateway" diff --git a/docker-compose.yml b/docker-compose.yml index aab8017ee..49a65eb5c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -44,6 +44,7 @@ services: # ── NATS JetStream ──────────────────────────────────────────────── nats: + profiles: ["nats"] image: nats:2.14-alpine3.22 # The client port is published on every interface (agent containers reach # it over the bridge), so it defers every login to archied. Set NATS_TOKEN @@ -51,8 +52,8 @@ services: # the account nkey seed named in [nats] callout_issuer_seed_env. command: ["-c", "/etc/nats/nats.conf"] environment: - NATS_TOKEN: ${NATS_TOKEN:?NATS_TOKEN is required} - NATS_CALLOUT_ISSUER: ${NATS_CALLOUT_ISSUER:?NATS_CALLOUT_ISSUER is required} + - NATS_TOKEN + - NATS_CALLOUT_ISSUER ports: - "4222:4222" # client - "127.0.0.1:8222:8222" # monitoring (http://localhost:8222) diff --git a/modules/chat/tools.go b/modules/chat/tools.go index ec918e6a5..aed8117ba 100644 --- a/modules/chat/tools.go +++ b/modules/chat/tools.go @@ -20,6 +20,7 @@ import ( "github.com/samcharles93/archie-core/modules/governance" "github.com/samcharles93/archie-core/modules/judgement" "github.com/samcharles93/archie-core/modules/memory" + "github.com/samcharles93/archie-core/ui/pages" ) // principal is who hard rules see acting when the chat agent calls an action. @@ -495,20 +496,25 @@ func typedTool[In any](name, description, schema string, run func(context.Contex }) } -// dashboardPages are the dashboard's top-level pages. -var dashboardPages = []string{ - "composer", "runs", "unmatched", "events", "people", "controls", - "extensions", "sources", "triggers", "credentials", "settings", -} - var pageID = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._:-]*$`) -// dashboardPath accepts a top-level page or one item under it, and nothing -// that could leave the dashboard. +// dashboardPath accepts a page from the dashboard's route catalogue or one item +// under it, and nothing that could leave the dashboard. func dashboardPath(path string) bool { - parts := strings.Split(strings.TrimPrefix(path, "/"), "/") - if !strings.HasPrefix(path, "/") || len(parts) > 2 || !slices.Contains(dashboardPages, parts[0]) { + catalogue, err := pages.All() + if err != nil { return false } - return len(parts) == 1 || pageID.MatchString(parts[1]) + for _, p := range catalogue { + if path == p.Path { + return true + } + if p.Path != "/" && strings.HasPrefix(path, p.Path+"/") { + rest := strings.TrimPrefix(path, p.Path+"/") + if pageID.MatchString(rest) { + return true + } + } + } + return false } diff --git a/modules/chat/tools_test.go b/modules/chat/tools_test.go index b4246a6cf..77c07657c 100644 --- a/modules/chat/tools_test.go +++ b/modules/chat/tools_test.go @@ -6,9 +6,12 @@ import "testing" // the operator: it must never lead off the dashboard or outside its pages. func TestDashboardPathStaysInTheDashboard(t *testing.T) { cases := map[string]bool{ + "/": true, "/runs": true, "/runs/0b8f6c1e-4a7e-4f6d": true, "/controls/github:merge_pr": true, + "/proposals": true, + "/settings/extensions": true, "//evil.example/runs": false, "https://evil.example/runs": false, "javascript:alert(1)": false, diff --git a/ui/vite.config.ts b/ui/vite.config.ts index 318e03576..2e7c1ce55 100644 --- a/ui/vite.config.ts +++ b/ui/vite.config.ts @@ -2,6 +2,8 @@ import { defineConfig } from "vite"; import vue from "@vitejs/plugin-vue"; import tailwindcss from "@tailwindcss/vite"; +const apiTarget = process.env.ARCHIE_DEV_API ?? "http://127.0.0.1:8484"; + export default defineConfig({ plugins: [vue(), tailwindcss()], resolve: { @@ -15,14 +17,16 @@ export default defineConfig({ emptyOutDir: true, }, server: { - // Proxies the API to a locally running archie-ui (the process that serves - // the dashboard) so the frontend can be developed without rebuilding Go. - // changeOrigin stays false: archie-ui refuses a mutation whose Origin - // does not match its Host, and the browser's Origin is this dev server. + // Proxies the API to a locally running archie binary (or legacy archie-ui + // when ARCHIE_DEV_API is set) so the frontend can be developed without + // rebuilding Go. changeOrigin stays false so Origin matches Host on + // mutations. proxy: { - "/api": { target: "http://127.0.0.1:8484", changeOrigin: false }, - "/health": { target: "http://127.0.0.1:8484", changeOrigin: false }, - "/webhooks": { target: "http://127.0.0.1:8484", changeOrigin: false }, + "/api": { target: apiTarget, changeOrigin: false }, + "/healthz": { target: apiTarget, changeOrigin: false }, + "/readyz": { target: apiTarget, changeOrigin: false }, + "/health": { target: apiTarget, changeOrigin: false }, + "/webhooks": { target: apiTarget, changeOrigin: false }, }, }, });