diff --git a/config.example.toml b/config.example.toml index 44101dfab..1ebffa551 100644 --- a/config.example.toml +++ b/config.example.toml @@ -461,9 +461,11 @@ target = "127.0.0.1:9090" # REQUIRED. The State Store gRPC address arch # # Agent profiles a workflow selects with `profile: `. A workflow that # names none runs under [containers].image with every tool. +# Once the State Store holds container policies, edit profiles in the +# dashboard (Settings, Advanced); a stored set replaces the file's. # [containers.profiles.network-investigator] -# image = "ghcr.io/samcharles93/archie-agent-net:latest" # empty uses [containers].image -# tools = ["whois", "dns_lookup"] # allowlist over MCP, script and plugin tools; empty allows all +# image = "archie-agent-net:local" # docker compose build agent-net; empty uses [containers].image +# tools = [] # allowlist over MCP, script and plugin tools; empty allows all # At least one [[repos]] entry is required before archied will poll # anything -- it is deliberately left commented rather than shipped active: diff --git a/docker-compose.yml b/docker-compose.yml index 2d1a7b224..47d9d6e3b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,12 +1,15 @@ -# Optional external NATS, plus the agent image the daemon spawns per task. +# PostgreSQL for the State Store, optional external NATS, and the agent images +# the daemon spawns per task. # # archied itself runs on the host under systemd, not here -- its chat tools # operate on host files, which a container cannot reach. See # deployments/systemd-user-service.md. # # Embedded NATS is the normal deployment and needs no Compose service. +# State Store DB: docker compose up -d postgres # External broker: docker compose up -d nats # Build worker: docker compose build agent +# Profile image: docker compose build agent-net # Stop external: docker compose down # Logs: journalctl --user -u archied -f (the daemon) # docker compose logs -f nats (the bus) @@ -80,6 +83,18 @@ services: # deployments/systemd-user-service.md#pinning-the-archie-agent-image. image: ghcr.io/samcharles93/archie-agent@sha256:870f1b1357979cfea23fccacb24166ebeb9ab321708ef2c2b218a763ed99b090 + # ── example agent profile image ───────────────────────────────────── + # The agent image plus network lookup tools, for a workflow that names + # `profile: network-investigator` (examples/workflows/firewall-investigate.yaml). + # Build-only for the same reason as agent. It is local, so leave + # containers.pull_policy at "missing": "always" would try to pull it. + agent-net: + profiles: ["build"] + build: + context: examples/profiles + dockerfile: Dockerfile.agent-net + image: archie-agent-net:local + volumes: nats_data: pg_data: diff --git a/examples/profiles/Dockerfile.agent-net b/examples/profiles/Dockerfile.agent-net new file mode 100644 index 000000000..ddc3ade22 --- /dev/null +++ b/examples/profiles/Dockerfile.agent-net @@ -0,0 +1,11 @@ +# An agent profile image: the archie-agent image plus network lookup tools, +# for a workflow that investigates addresses rather than code. Select it with +# [containers.profiles.network-investigator] image = "archie-agent-net:local". +# +# Build: docker compose build agent-net +ARG AGENT_IMAGE=ghcr.io/samcharles93/archie-agent:latest +FROM ${AGENT_IMAGE} + +RUN apt-get update && apt-get install -y --no-install-recommends \ + whois dnsutils iputils-ping traceroute && \ + rm -rf /var/lib/apt/lists/* diff --git a/examples/workflows/firewall-investigate.yaml b/examples/workflows/firewall-investigate.yaml new file mode 100644 index 000000000..e0e4d2df8 --- /dev/null +++ b/examples/workflows/firewall-investigate.yaml @@ -0,0 +1,18 @@ +# A workflow with no repository: a binding on a firewall event type assigns +# src_ip from a mapped parameter and runs one agent mission in a scratch +# workspace under the network-investigator profile. Paste it into the +# dashboard's workflow definitions. +id: firewall-investigate +repository: none +profile: network-investigator +inputs: + src_ip: { type: string, required: true } + severity: { type: string } +steps: + - type: agent.run + settings: + mission: >- + Investigate the source address in the inputs: who owns it, what it + resolves to, and whether it is reachable. Report what you found and + how serious it looks given the severity. + read_only: true diff --git a/internal/app/controlplane/runtime_config.go b/internal/app/controlplane/runtime_config.go index 390a923bd..e44978cc3 100644 --- a/internal/app/controlplane/runtime_config.go +++ b/internal/app/controlplane/runtime_config.go @@ -187,7 +187,20 @@ func runtimeToolConfigFrom(ctx context.Context, reader controlplanerpc.ResourceR }); err != nil { return config.Config{}, nil, err } - if err := layerResourceJSON(ctx, reader, versions, ContainerRuntimePoliciesKind, &out.Containers); err != nil { + if err := layerResource(ctx, reader, versions, ContainerRuntimePoliciesKind, func(value []byte) error { + // A document that omits Profiles (one stored before they existed) + // inherits the file's. One that carries them replaces the file's: + // json.Unmarshal merges into an existing map, so without clearing it a + // profile deleted from the store would come back from the file. + var keys map[string]json.RawMessage + if err := json.Unmarshal(value, &keys); err != nil { + return err + } + if _, stored := keys["Profiles"]; stored { + out.Containers.Profiles = nil + } + return json.Unmarshal(value, &out.Containers) + }); err != nil { return config.Config{}, nil, err } return out, versions, nil diff --git a/internal/app/controlplane/runtime_config_test.go b/internal/app/controlplane/runtime_config_test.go index a5a5b5caf..94c93ea59 100644 --- a/internal/app/controlplane/runtime_config_test.go +++ b/internal/app/controlplane/runtime_config_test.go @@ -333,3 +333,40 @@ func TestSchedulingPolicySeedCarriesTheLabel(t *testing.T) { t.Fatalf("seed label = %q, want the file document's label", label) } } + +// Stored container policies that carry profiles replace the file's outright; +// ones stored before profiles existed inherit the file's. +func TestRuntimeConfigLayersStoredProfiles(t *testing.T) { + base := config.Config{Containers: config.ContainerConfig{Image: "agent:1", Profiles: map[string]config.AgentProfile{ + "file-only": {Image: "file:1"}, + }}} + for _, tt := range []struct { + name string + stored map[string]any + want []string + }{ + {name: "stored profiles replace the file's", stored: map[string]any{"Image": "agent:2", "Profiles": map[string]any{"net": map[string]any{"Tools": []string{"whois"}}}}, want: []string{"net"}}, + {name: "a document without profiles inherits the file's", stored: map[string]any{"Image": "agent:2"}, want: []string{"file-only"}}, + } { + t.Run(tt.name, func(t *testing.T) { + client := NewRPCClient(&runtimeConfigClient{values: map[string]any{ + SchedulingPolicyKind: map[string]any{"poll_interval": "2m", "dispatch": map[string]any{"trigger": "assignee"}}, + ContainerRuntimePoliciesKind: tt.stored, + }}) + got, _, err := client.RuntimeConfig(t.Context(), base) + if err != nil { + t.Fatalf("RuntimeConfig: %v", err) + } + var names []string + for name := range got.Containers.Profiles { + names = append(names, name) + } + if !reflect.DeepEqual(names, tt.want) { + t.Fatalf("profiles = %v, want %v", names, tt.want) + } + }) + } + if got := base.Containers.Profiles; len(got) != 1 { + t.Fatalf("layering mutated the file document's profiles: %v", got) + } +} diff --git a/internal/config/config.go b/internal/config/config.go index 460b165e8..b1c4fa6df 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -909,7 +909,7 @@ type ContainerConfig struct { // Profiles are the named agent profiles a workflow selects with // `profile:`. A workflow that names none runs under the default profile: // Image and every tool. - Profiles map[string]AgentProfile `toml:"profiles" yaml:"profiles" json:"profiles,omitempty"` + Profiles map[string]AgentProfile `toml:"profiles" yaml:"profiles"` } // AgentProfile is a named execution environment for an agent. Secrets and @@ -919,12 +919,12 @@ type ContainerConfig struct { // an operator when it is dispatched (daemon pinTaskProfile). type AgentProfile struct { // Image is the container image; empty means [containers].image. - Image string `toml:"image" yaml:"image" json:"image,omitempty"` + Image string `toml:"image" yaml:"image"` // Tools allowlists the tools archie adds to the agent (MCP servers, // repository scripts and skill plugins) by name. Empty allows them all. // The agent loop's own file tools are always present, read-only when a // step asks for that. - Tools []string `toml:"tools" yaml:"tools" json:"tools,omitempty"` + Tools []string `toml:"tools" yaml:"tools"` } // Profile resolves the profile a workflow names: "" is the default profile, diff --git a/internal/infrastructure/workflowsteps/workflowsteps_test.go b/internal/infrastructure/workflowsteps/workflowsteps_test.go index 03e8b98f8..760d2ab6a 100644 --- a/internal/infrastructure/workflowsteps/workflowsteps_test.go +++ b/internal/infrastructure/workflowsteps/workflowsteps_test.go @@ -1,6 +1,8 @@ package workflowsteps import ( + "os" + "path/filepath" "slices" "strings" "testing" @@ -189,3 +191,26 @@ func TestRepoHookStepsCompileThroughTheManager(t *testing.T) { t.Fatalf("ParseAndCompile(%q) error = %v, want the unusable rule refused by name", broken, err) } } + +// The shipped example workflows parse against the vocabulary the roots +// register, so an example cannot drift from the steps that exist. +func TestExampleWorkflowsParse(t *testing.T) { + paths, err := filepath.Glob("../../../examples/workflows/*.yaml") + if err != nil || len(paths) == 0 { + t.Fatalf("no example workflows found: %v", err) + } + manager, err := NewManager() + if err != nil { + t.Fatal(err) + } + registry := manager.Registry() + for _, path := range paths { + src, err := os.ReadFile(path) + if err != nil { + t.Fatal(err) + } + if _, err := workflow.ParseDefinition(string(src), registry); err != nil { + t.Errorf("%s: %v", path, err) + } + } +}