diff --git a/.mcp.json b/.mcp.json new file mode 100644 index 000000000..b63e3de44 --- /dev/null +++ b/.mcp.json @@ -0,0 +1,8 @@ +{ + "mcpServers": { + "okf": { + "type": "http", + "url": "http://localhost:8765/archie-core/" + } + } +} diff --git a/.okf/architecture/index.md b/.okf/architecture/index.md new file mode 100644 index 000000000..05a06e065 --- /dev/null +++ b/.okf/architecture/index.md @@ -0,0 +1,3 @@ +# Architecture + +* [archie-core Overview](overview.md) - Root architecture and project structure for archie-core. diff --git a/.okf/architecture/overview.md b/.okf/architecture/overview.md new file mode 100644 index 000000000..1397fd7e1 --- /dev/null +++ b/.okf/architecture/overview.md @@ -0,0 +1,68 @@ +--- +description: Root architecture and project structure for archie-core. +resource: /work/apps/archie-core +tags: + - overview + - architecture + - codebase +timestamp: "2026-07-21T18:36:22Z" +title: archie-core Overview +type: Architecture +--- + +# Overview + + + +# Codebase Navigation + +* [main.go](/codebase/cmd/archie-agent/main.md) - `cmd/archie-agent/main.go` +* [main.go](/codebase/cmd/archied/main.md) - `cmd/archied/main.go` +* [inprocess.go](/codebase/internal/agentexec/inprocess.md) - `internal/agentexec/inprocess.go` +* [inprocess_test.go](/codebase/internal/agentexec/inprocess_test.md) - `internal/agentexec/inprocess_test.go` +* [nats.go](/codebase/internal/agentexec/nats.md) - `internal/agentexec/nats.go` +* [nats_test.go](/codebase/internal/agentexec/nats_test.md) - `internal/agentexec/nats_test.go` +* [protocol.go](/codebase/internal/agentexec/protocol.md) - `internal/agentexec/protocol.go` +* [protocol_test.go](/codebase/internal/agentexec/protocol_test.md) - `internal/agentexec/protocol_test.go` +* [runtime.go](/codebase/internal/agentexec/runtime.md) - `internal/agentexec/runtime.go` +* [skill_test.go](/codebase/internal/agentexec/skill_test.md) - `internal/agentexec/skill_test.go` +* [subprocess.go](/codebase/internal/agentexec/subprocess.md) - `internal/agentexec/subprocess.go` +* [subprocess_process_unix.go](/codebase/internal/agentexec/subprocess_process_unix.md) - `internal/agentexec/subprocess_process_unix.go` +* [subprocess_process_windows.go](/codebase/internal/agentexec/subprocess_process_windows.md) - `internal/agentexec/subprocess_process_windows.go` +* [subprocess_test.go](/codebase/internal/agentexec/subprocess_test.md) - `internal/agentexec/subprocess_test.go` +* [worker.go](/codebase/internal/agentexec/worker.md) - `internal/agentexec/worker.go` +* [config.go](/codebase/internal/config/config.md) - `internal/config/config.go` +* [config_test.go](/codebase/internal/config/config_test.md) - `internal/config/config_test.go` +* [ecosystem.go](/codebase/internal/config/ecosystem.md) - `internal/config/ecosystem.go` +* [pool.go](/codebase/internal/container/pool.md) - `internal/container/pool.go` +* [pool_test.go](/codebase/internal/container/pool_test.md) - `internal/container/pool_test.go` +* [daemon.go](/codebase/internal/daemon/daemon.md) - `internal/daemon/daemon.go` +* [daemon_test.go](/codebase/internal/daemon/daemon_test.md) - `internal/daemon/daemon_test.go` +* [events.go](/codebase/internal/events/events.md) - `internal/events/events.go` +* [events_test.go](/codebase/internal/events/events_test.md) - `internal/events/events_test.go` +* [forge.go](/codebase/internal/forge/forge.md) - `internal/forge/forge.go` +* [github.go](/codebase/internal/forge/github.md) - `internal/forge/github.go` +* [github_methods_test.go](/codebase/internal/forge/github_methods_test.md) - `internal/forge/github_methods_test.go` +* [github_test.go](/codebase/internal/forge/github_test.md) - `internal/forge/github_test.go` +* [testclient_test.go](/codebase/internal/forge/testclient_test.md) - `internal/forge/testclient_test.go` +* [gate.go](/codebase/internal/gate/gate.md) - `internal/gate/gate.go` +* [yaegi.go](/codebase/internal/gate/gateeval/yaegi.md) - `internal/gate/gateeval/yaegi.go` +* [yaegi_test.go](/codebase/internal/gate/gateeval/yaegi_test.md) - `internal/gate/gateeval/yaegi_test.go` +* [gateextract.go](/codebase/internal/gate/gateextract/gateextract.md) - `internal/gate/gateextract/gateextract.go` +* [github_com-samcharles93-archie-core-internal-gate.go](/codebase/internal/gate/gateextract/github_com-samcharles93-archie-core-internal-gate.md) - `internal/gate/gateextract/github_com-samcharles93-archie-core-internal-gate.go` +* [client.go](/codebase/internal/nats/client.md) - `internal/nats/client.go` +* [client_test.go](/codebase/internal/nats/client_test.md) - `internal/nats/client_test.go` +* [subjects.go](/codebase/internal/nats/subjects.md) - `internal/nats/subjects.go` +* [plugin.go](/codebase/internal/plugin/plugin.md) - `internal/plugin/plugin.go` +* [plugin_test.go](/codebase/internal/plugin/plugin_test.md) - `internal/plugin/plugin_test.go` +* [github_com-samcharles93-archie-core-internal-plugin.go](/codebase/internal/plugin/pluginextract/github_com-samcharles93-archie-core-internal-plugin.md) - `internal/plugin/pluginextract/github_com-samcharles93-archie-core-internal-plugin.go` +* [pluginextract.go](/codebase/internal/plugin/pluginextract/pluginextract.md) - `internal/plugin/pluginextract/pluginextract.go` +* [catalog_test.go](/codebase/internal/skill/catalog_test.md) - `internal/skill/catalog_test.go` +* [frontmatter_test.go](/codebase/internal/skill/frontmatter_test.md) - `internal/skill/frontmatter_test.go` +* [plugin.go](/codebase/internal/skill/plugin.md) - `internal/skill/plugin.go` +* [plugin_test.go](/codebase/internal/skill/plugin_test.md) - `internal/skill/plugin_test.go` +* [skill.go](/codebase/internal/skill/skill.md) - `internal/skill/skill.go` +* [skill_test.go](/codebase/internal/skill/skill_test.md) - `internal/skill/skill_test.go` +* [yaegi.go](/codebase/internal/skillscript/yaegi.md) - `internal/skillscript/yaegi.go` +* [yaegi_test.go](/codebase/internal/skillscript/yaegi_test.md) - `internal/skillscript/yaegi_test.go` +* [storage.go](/codebase/internal/storage/storage.md) - `internal/storage/storage.go` diff --git a/.okf/codebase/cmd/archie-agent/index.md b/.okf/codebase/cmd/archie-agent/index.md new file mode 100644 index 000000000..52848d923 --- /dev/null +++ b/.okf/codebase/cmd/archie-agent/index.md @@ -0,0 +1,3 @@ +# Module + +* [main.go](main.md) - Source module cmd/archie-agent/main.go (177 lines). diff --git a/.okf/codebase/cmd/archie-agent/main.md b/.okf/codebase/cmd/archie-agent/main.md new file mode 100644 index 000000000..1bc166635 --- /dev/null +++ b/.okf/codebase/cmd/archie-agent/main.md @@ -0,0 +1,50 @@ +--- +description: Source module cmd/archie-agent/main.go (177 lines). +resource: cmd/archie-agent/main.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: main.go +type: Module +--- + +# Module main.go + +**Path**: `cmd/archie-agent/main.go` +**Lines**: 177 + +## Snippet Preview + +``` +// Command archie-agent is a long-running NATS-connected worker that executes +// autonomous agent stages. It subscribes to archie.agent.> on the ARCHIE_TASKS +// JetStream stream, runs the agent loop for each received request, and publishes +// the result back to the daemon's reply inbox. +package main + +import ( + "context" + "encoding/json" + "flag" + "fmt" + "log/slog" + "os" + "os/signal" + "syscall" + "time" + + "github.com/nats-io/nats.go" + "github.com/nats-io/nats.go/jetstream" + + "github.com/samcharles93/archie-core/internal/agentexec" + arnats "github.com/samcharles93/archie-core/internal/nats" +) + +const ( + streamName = "ARCHIE_TASKS" + consumerName = "archie-agent" + dedupWindow = 2 * time.Minute + pollTimeout = 5 * time.Second + ackWait = 30 * time.Minute +``` diff --git a/.okf/codebase/cmd/archied/index.md b/.okf/codebase/cmd/archied/index.md new file mode 100644 index 000000000..aecd59354 --- /dev/null +++ b/.okf/codebase/cmd/archied/index.md @@ -0,0 +1,3 @@ +# Module + +* [main.go](main.md) - Source module cmd/archied/main.go (263 lines). diff --git a/.okf/codebase/cmd/archied/main.md b/.okf/codebase/cmd/archied/main.md new file mode 100644 index 000000000..b6a7c2b04 --- /dev/null +++ b/.okf/codebase/cmd/archied/main.md @@ -0,0 +1,50 @@ +--- +description: Source module cmd/archied/main.go (263 lines). +resource: cmd/archied/main.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: main.go +type: Module +--- + +# Module main.go + +**Path**: `cmd/archied/main.go` +**Lines**: 263 + +## Snippet Preview + +``` +// Command archied is the archie orchestrator daemon: it watches GitHub +// for issues labelled for archie, works each one in an isolated +// worktree through its routed workflow, and opens pull requests for +// human review. +package main + +import ( + "context" + "flag" + "fmt" + "log/slog" + "os" + "os/signal" + "path/filepath" + "syscall" + + "github.com/samcharles93/archie-core/internal/agentexec" + "github.com/samcharles93/archie-core/internal/config" + "github.com/samcharles93/archie-core/internal/container" + "github.com/samcharles93/archie-core/internal/daemon" + "github.com/samcharles93/archie-core/internal/events" + "github.com/samcharles93/archie-core/internal/forge" + "github.com/samcharles93/archie-core/internal/nats" + "github.com/moby/moby/client" + + "github.com/samcharles93/archie-core/internal/plugin" + "github.com/samcharles93/archie-core/internal/plugin/pluginextract" + "github.com/samcharles93/archie-core/internal/storage" + "github.com/samcharles93/archie-core/internal/store" + "github.com/samcharles93/archie-core/internal/webui" +``` diff --git a/.okf/codebase/cmd/index.md b/.okf/codebase/cmd/index.md new file mode 100644 index 000000000..e26de9d93 --- /dev/null +++ b/.okf/codebase/cmd/index.md @@ -0,0 +1,4 @@ +# Subdirectories + +* [archie-agent](archie-agent/index.md) - Source module cmd/archie-agent/main.go (177 lines). +* [archied](archied/index.md) - Source module cmd/archied/main.go (263 lines). diff --git a/.okf/codebase/index.md b/.okf/codebase/index.md new file mode 100644 index 000000000..6e7f7ea6b --- /dev/null +++ b/.okf/codebase/index.md @@ -0,0 +1,4 @@ +# Subdirectories + +* [cmd](cmd/index.md) - Directory containing 2 items, including: archie-agent. +* [internal](internal/index.md) - Directory containing 16 items, including: agentexec. diff --git a/.okf/codebase/internal/agentexec/index.md b/.okf/codebase/internal/agentexec/index.md new file mode 100644 index 000000000..89015b2dd --- /dev/null +++ b/.okf/codebase/internal/agentexec/index.md @@ -0,0 +1,15 @@ +# Module + +* [inprocess.go](inprocess.md) - Source module internal/agentexec/inprocess.go (229 lines). +* [inprocess_test.go](inprocess_test.md) - Source module internal/agentexec/inprocess_test.go (173 lines). +* [nats.go](nats.md) - Source module internal/agentexec/nats.go (115 lines). +* [nats_test.go](nats_test.md) - Source module internal/agentexec/nats_test.go (291 lines). +* [protocol.go](protocol.md) - Source module internal/agentexec/protocol.go (206 lines). +* [protocol_test.go](protocol_test.md) - Source module internal/agentexec/protocol_test.go (46 lines). +* [runtime.go](runtime.md) - Source module internal/agentexec/runtime.go (23 lines). +* [skill_test.go](skill_test.md) - Source module internal/agentexec/skill_test.go (94 lines). +* [subprocess.go](subprocess.md) - Source module internal/agentexec/subprocess.go (162 lines). +* [subprocess_process_unix.go](subprocess_process_unix.md) - Source module internal/agentexec/subprocess_process_unix.go (27 lines). +* [subprocess_process_windows.go](subprocess_process_windows.md) - Source module internal/agentexec/subprocess_process_windows.go (9 lines). +* [subprocess_test.go](subprocess_test.md) - Source module internal/agentexec/subprocess_test.go (247 lines). +* [worker.go](worker.md) - Source module internal/agentexec/worker.go (185 lines). diff --git a/.okf/codebase/internal/agentexec/inprocess.md b/.okf/codebase/internal/agentexec/inprocess.md new file mode 100644 index 000000000..a4fafbef0 --- /dev/null +++ b/.okf/codebase/internal/agentexec/inprocess.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/agentexec/inprocess.go (229 lines). +resource: internal/agentexec/inprocess.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: inprocess.go +type: Module +--- + +# Module inprocess.go + +**Path**: `internal/agentexec/inprocess.go` +**Lines**: 229 + +## Snippet Preview + +``` +package agentexec + +import ( + "context" + "encoding/json" + "fmt" + "log/slog" + "maps" + "path/filepath" + "strings" + + "github.com/samcharles93/ai-sdk/agentloop" + "github.com/samcharles93/ai-sdk/core" + "github.com/samcharles93/ai-sdk/runtime" + + "github.com/samcharles93/archie-core/internal/skillscript" +) + +// Runner executes one autonomous stage against an already prepared workspace. +type Runner interface { + Run(ctx context.Context, workspace string, req Request) (Result, error) +} + +type loopFunc func(context.Context, agentloop.Config) (agentloop.Result, error) + +// InProcessRunner preserves the current execution behavior behind the v1 +// agent protocol. It is replaced by a subprocess or container runner without +// changing workflow orchestration. +type InProcessRunner struct { + runtime *runtime.Runtime +``` diff --git a/.okf/codebase/internal/agentexec/inprocess_test.md b/.okf/codebase/internal/agentexec/inprocess_test.md new file mode 100644 index 000000000..7ddbbb694 --- /dev/null +++ b/.okf/codebase/internal/agentexec/inprocess_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/agentexec/inprocess_test.go (173 lines). +resource: internal/agentexec/inprocess_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: inprocess_test.go +type: Module +--- + +# Module inprocess_test.go + +**Path**: `internal/agentexec/inprocess_test.go` +**Lines**: 173 + +## Snippet Preview + +``` +package agentexec + +import ( + "context" + "encoding/json" + "errors" + "os" + "path/filepath" + "testing" + + "github.com/samcharles93/ai-sdk/agentloop" + "github.com/samcharles93/ai-sdk/runtime" +) + +func TestInProcessRunnerMapsRequestAndCapturesOutput(t *testing.T) { + runner := &InProcessRunner{ + runtime: runtime.NewRuntime(runtime.Config{}), + run: func(ctx context.Context, cfg agentloop.Config) (agentloop.Result, error) { + if cfg.WorkDir != "/workspace" || cfg.ModelRef != "provider/model" || cfg.Mission != "mission" { + t.Fatalf("unexpected config: workdir=%q model=%q mission=%q", cfg.WorkDir, cfg.ModelRef, cfg.Mission) + } + if cfg.ProtectPaths == nil || !cfg.ProtectPaths("nested/file_test.go") || !cfg.ProtectPaths("view_templ.go") { + t.Fatal("declarative path protection was not applied") + } + if err := cfg.Notes.Append(ctx, "verified note"); err != nil { + t.Fatal(err) + } + if _, err := cfg.Extra["decide"].Execute(ctx, `{"fit":true}`); err != nil { + t.Fatal(err) + } +``` diff --git a/.okf/codebase/internal/agentexec/nats.md b/.okf/codebase/internal/agentexec/nats.md new file mode 100644 index 000000000..5ddd48081 --- /dev/null +++ b/.okf/codebase/internal/agentexec/nats.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/agentexec/nats.go (115 lines). +resource: internal/agentexec/nats.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: nats.go +type: Module +--- + +# Module nats.go + +**Path**: `internal/agentexec/nats.go` +**Lines**: 115 + +## Snippet Preview + +``` +package agentexec + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "log/slog" + "time" + + natsio "github.com/nats-io/nats.go" + + arnats "github.com/samcharles93/archie-core/internal/nats" +) + +// AgentRequestMessage is the NATS payload for an agent stage execution request. +// When Workflow is set and Stages is populated, the agent runs all stages as a +// per-task batch rather than a single stage. PRD §1. +type AgentRequestMessage struct { + TaskID int64 `json:"task_id"` + Attempt int `json:"attempt"` + Stage string `json:"stage"` + Workflow string `json:"workflow,omitempty"` + Channel string `json:"channel,omitempty"` // "response" (default) or "system" + Workspace string `json:"workspace"` + Request Request `json:"request"` + Stages []Request `json:"stages,omitempty"` // batch: all agent stages for this task + Providers map[string]Provider `json:"providers,omitempty"` +} + +``` diff --git a/.okf/codebase/internal/agentexec/nats_test.md b/.okf/codebase/internal/agentexec/nats_test.md new file mode 100644 index 000000000..a673a9219 --- /dev/null +++ b/.okf/codebase/internal/agentexec/nats_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/agentexec/nats_test.go (291 lines). +resource: internal/agentexec/nats_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: nats_test.go +type: Module +--- + +# Module nats_test.go + +**Path**: `internal/agentexec/nats_test.go` +**Lines**: 291 + +## Snippet Preview + +``` +package agentexec + +import ( + "context" + "encoding/json" + "log/slog" + "testing" + "time" + + "github.com/nats-io/nats-server/v2/server" + natssrv "github.com/nats-io/nats-server/v2/test" + natsio "github.com/nats-io/nats.go" + "github.com/nats-io/nats.go/jetstream" + + arnats "github.com/samcharles93/archie-core/internal/nats" +) + +// ── helpers ────────────────────────────────────────────────────────── + +type mockRunner struct{} + +func (m *mockRunner) Run(_ context.Context, _ string, req Request) (Result, error) { + return Result{ + Version: ProtocolVersion, + TaskID: req.TaskID, + Attempt: req.Attempt, + Stage: req.Stage, + Status: StatusPassed, + Summary: "mock:" + req.Mission, + TokensUsed: 10, +``` diff --git a/.okf/codebase/internal/agentexec/protocol.md b/.okf/codebase/internal/agentexec/protocol.md new file mode 100644 index 000000000..8fd141be3 --- /dev/null +++ b/.okf/codebase/internal/agentexec/protocol.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/agentexec/protocol.go (206 lines). +resource: internal/agentexec/protocol.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: protocol.go +type: Module +--- + +# Module protocol.go + +**Path**: `internal/agentexec/protocol.go` +**Lines**: 206 + +## Snippet Preview + +``` +// Package agentexec defines the unprivileged agent execution boundary. +// Workflow orchestration and external side effects remain daemon-owned. +package agentexec + +import ( + "encoding/json" + "errors" + "fmt" + "net/url" + "strings" + "time" +) + +const ProtocolVersion = 1 + +// ErrBlocked is returned by ReviewResult when the daemon blocks agent output +// from reaching human channels. +var ErrBlocked = errors.New("agent output blocked by daemon review") + +const StatusPassed = "passed" + +// Command is one executable gate or preflight command. +type Command struct { + Name string `json:"name"` + Argv []string `json:"argv"` + ExpectFailure bool `json:"expect_failure,omitempty"` +} + +// Gate is the quality gate an agent must satisfy. +type Gate struct { +``` diff --git a/.okf/codebase/internal/agentexec/protocol_test.md b/.okf/codebase/internal/agentexec/protocol_test.md new file mode 100644 index 000000000..5e29eb1c1 --- /dev/null +++ b/.okf/codebase/internal/agentexec/protocol_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/agentexec/protocol_test.go (46 lines). +resource: internal/agentexec/protocol_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: protocol_test.go +type: Module +--- + +# Module protocol_test.go + +**Path**: `internal/agentexec/protocol_test.go` +**Lines**: 46 + +## Snippet Preview + +``` +package agentexec + +import ( + "encoding/json" + "reflect" + "testing" + "time" +) + +func TestProtocolRoundTrip(t *testing.T) { + want := Request{ + Version: ProtocolVersion, TaskID: 42, Attempt: 3, Stage: "fix", Model: "openai/gpt-5", + Mission: "fix it", Budget: Budget{MaxSteps: 12, MaxTokens: 4000, WallClock: 2 * time.Minute}, + Gate: Gate{Commands: []Command{{Name: "go", Argv: []string{"go", "test", "./..."}}}, MaxConsecutiveFailures: 2}, + Protection: Protection{Suffixes: []string{"_templ.go"}, Globs: []string{"*_test.go"}}, + CaptureTools: []CaptureTool{{Name: "decide", Parameters: json.RawMessage(`{"type":"object"}`), MaxCalls: 1}}, + } + b, err := json.Marshal(want) + if err != nil { + t.Fatal(err) + } + var got Request + if err := json.Unmarshal(b, &got); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(got, want) { + t.Fatalf("round trip mismatch\ngot: %#v\nwant: %#v", got, want) + } +} + +``` diff --git a/.okf/codebase/internal/agentexec/runtime.md b/.okf/codebase/internal/agentexec/runtime.md new file mode 100644 index 000000000..491a208fe --- /dev/null +++ b/.okf/codebase/internal/agentexec/runtime.md @@ -0,0 +1,43 @@ +--- +description: Source module internal/agentexec/runtime.go (23 lines). +resource: internal/agentexec/runtime.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: runtime.go +type: Module +--- + +# Module runtime.go + +**Path**: `internal/agentexec/runtime.go` +**Lines**: 23 + +## Snippet Preview + +``` +package agentexec + +import "github.com/samcharles93/ai-sdk/runtime" + +// NewRuntime builds the provider runtime shared by archied's in-process mode +// and the archie-agent worker. Nil means no providers were configured. +func NewRuntime(providers map[string]Provider) *runtime.Runtime { + if len(providers) == 0 { + return nil + } + runtime.RegisterBuiltinClasses() + catalog := make(map[string]runtime.ProviderConfig, len(providers)) + for name, provider := range providers { + cfg := runtime.ProviderConfig{ID: name, Class: provider.Class, BaseURL: provider.BaseURL} + if provider.APIKeyEnv == "" { + cfg.Auth = runtime.AuthConfig{Type: runtime.AuthTypeNone} + } else { + cfg.Auth = runtime.AuthConfig{APIKeyEnv: provider.APIKeyEnv} + } + catalog[name] = cfg + } + return runtime.NewRuntime(runtime.Config{Providers: catalog}) +} +``` diff --git a/.okf/codebase/internal/agentexec/skill_test.md b/.okf/codebase/internal/agentexec/skill_test.md new file mode 100644 index 000000000..9c03a7ba8 --- /dev/null +++ b/.okf/codebase/internal/agentexec/skill_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/agentexec/skill_test.go (94 lines). +resource: internal/agentexec/skill_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: skill_test.go +type: Module +--- + +# Module skill_test.go + +**Path**: `internal/agentexec/skill_test.go` +**Lines**: 94 + +## Snippet Preview + +``` +package agentexec + +import ( + "context" + "log/slog" + "os" + "path/filepath" + "testing" +) + +// captureRunner records the Request it receives for test assertions. +type captureRunner struct { + callback func(Request) +} + +func (c *captureRunner) Run(_ context.Context, _ string, req Request) (Result, error) { + c.callback(req) + return Result{ + Version: ProtocolVersion, + TaskID: req.TaskID, + Attempt: req.Attempt, + Stage: req.Stage, + Status: StatusPassed, + Summary: "done", + TokensUsed: 1, + }, nil +} + +// ── regression: Agent doesn't load its own skills ─────────────────── + +``` diff --git a/.okf/codebase/internal/agentexec/subprocess.md b/.okf/codebase/internal/agentexec/subprocess.md new file mode 100644 index 000000000..9bf58567d --- /dev/null +++ b/.okf/codebase/internal/agentexec/subprocess.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/agentexec/subprocess.go (162 lines). +resource: internal/agentexec/subprocess.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: subprocess.go +type: Module +--- + +# Module subprocess.go + +**Path**: `internal/agentexec/subprocess.go` +**Lines**: 162 + +## Snippet Preview + +``` +package agentexec + +import ( + "bytes" + "context" + "encoding/json" + "errors" + "fmt" + "io" + "os/exec" + "strings" +) + +const maxDiagnosticBytes = 64 << 10 + +// SubprocessRunner executes each agent stage in a fresh archie-agent process. +type SubprocessRunner struct { + Command string + Args []string + // Environ is the daemon environment to select from. AdditionalEnv names + // operator-approved compatibility variables; the requested provider's key + // variable is added automatically for that invocation only. + Environ []string + AdditionalEnv []string + Diagnostics io.Writer + Providers map[string]Provider +} + +func (r *SubprocessRunner) Run(ctx context.Context, workspace string, req Request) (Result, error) { + providerName, _, ok := strings.Cut(req.Model, "/") +``` diff --git a/.okf/codebase/internal/agentexec/subprocess_process_unix.md b/.okf/codebase/internal/agentexec/subprocess_process_unix.md new file mode 100644 index 000000000..2647dec1b --- /dev/null +++ b/.okf/codebase/internal/agentexec/subprocess_process_unix.md @@ -0,0 +1,47 @@ +--- +description: Source module internal/agentexec/subprocess_process_unix.go (27 lines). +resource: internal/agentexec/subprocess_process_unix.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: subprocess_process_unix.go +type: Module +--- + +# Module subprocess_process_unix.go + +**Path**: `internal/agentexec/subprocess_process_unix.go` +**Lines**: 27 + +## Snippet Preview + +``` +//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris + +package agentexec + +import ( + "errors" + "os" + "os/exec" + "syscall" +) + +// configureProcessCancellation puts the worker and every command it starts in +// a dedicated process group. CommandContext cancellation then kills the whole +// group so toolchain grandchildren cannot continue mutating the worktree. +func configureProcessCancellation(cmd *exec.Cmd) { + cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} + cmd.Cancel = func() error { + if cmd.Process == nil { + return os.ErrProcessDone + } + err := syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL) + if errors.Is(err, syscall.ESRCH) { + return os.ErrProcessDone + } + return err + } +} +``` diff --git a/.okf/codebase/internal/agentexec/subprocess_process_windows.md b/.okf/codebase/internal/agentexec/subprocess_process_windows.md new file mode 100644 index 000000000..6933e8d3f --- /dev/null +++ b/.okf/codebase/internal/agentexec/subprocess_process_windows.md @@ -0,0 +1,29 @@ +--- +description: Source module internal/agentexec/subprocess_process_windows.go (9 lines). +resource: internal/agentexec/subprocess_process_windows.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: subprocess_process_windows.go +type: Module +--- + +# Module subprocess_process_windows.go + +**Path**: `internal/agentexec/subprocess_process_windows.go` +**Lines**: 9 + +## Snippet Preview + +``` +//go:build windows + +package agentexec + +import "os/exec" + +// Windows keeps exec.CommandContext's direct-process cancellation. Production +// subprocess and container execution are currently supported on Unix hosts. +func configureProcessCancellation(_ *exec.Cmd) {} +``` diff --git a/.okf/codebase/internal/agentexec/subprocess_test.md b/.okf/codebase/internal/agentexec/subprocess_test.md new file mode 100644 index 000000000..3e385a08a --- /dev/null +++ b/.okf/codebase/internal/agentexec/subprocess_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/agentexec/subprocess_test.go (247 lines). +resource: internal/agentexec/subprocess_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: subprocess_test.go +type: Module +--- + +# Module subprocess_test.go + +**Path**: `internal/agentexec/subprocess_test.go` +**Lines**: 247 + +## Snippet Preview + +``` +package agentexec + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "os" + "os/exec" + "path/filepath" + "strings" + "testing" + "time" +) + +func TestSubprocessRunnerRoundTrip(t *testing.T) { + req := testRequest() + result, err := helperRunner("success").Run(context.Background(), "/workspace", req) + if err != nil { + t.Fatal(err) + } + if result.Summary != "from child" || result.TaskID != req.TaskID || result.Attempt != req.Attempt { + t.Fatalf("result = %#v", result) + } +} + +func TestSubprocessRunnerReturnsStampedWorkerError(t *testing.T) { + req := testRequest() + result, err := helperRunner("worker-error").Run(context.Background(), "/workspace", req) + if err == nil || err.Error() != "provider unavailable" { +``` diff --git a/.okf/codebase/internal/agentexec/worker.md b/.okf/codebase/internal/agentexec/worker.md new file mode 100644 index 000000000..f39b19e05 --- /dev/null +++ b/.okf/codebase/internal/agentexec/worker.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/agentexec/worker.go (185 lines). +resource: internal/agentexec/worker.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: worker.go +type: Module +--- + +# Module worker.go + +**Path**: `internal/agentexec/worker.go` +**Lines**: 185 + +## Snippet Preview + +``` +package agentexec + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "log/slog" + "strings" + + "github.com/samcharles93/archie-core/internal/skill" +) + +const maxProtocolBytes = 8 << 20 + +// DefaultRunnerFactory creates an InProcessRunner backed by the ai-sdk runtime. +func DefaultRunnerFactory(providers map[string]Provider, log *slog.Logger) Runner { + return NewInProcessRunner(NewRuntime(providers), log) +} + +// ServeOne decodes and executes exactly one invocation. +func ServeOne(ctx context.Context, in io.Reader, out io.Writer, log *slog.Logger) error { + return serveOne(ctx, in, out, func(invocation Invocation) Runner { + return DefaultRunnerFactory(invocation.Providers, log) + }) +} + +func serveOne(ctx context.Context, in io.Reader, out io.Writer, newRunner func(Invocation) Runner) error { + var invocation Invocation +``` diff --git a/.okf/codebase/internal/config/config.md b/.okf/codebase/internal/config/config.md new file mode 100644 index 000000000..bda7c9df8 --- /dev/null +++ b/.okf/codebase/internal/config/config.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/config/config.go (424 lines). +resource: internal/config/config.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: config.go +type: Module +--- + +# Module config.go + +**Path**: `internal/config/config.go` +**Lines**: 424 + +## Snippet Preview + +``` +// Package config loads archied's TOML configuration. The forge API token is +// deliberately not part of the file: it comes from a configurable env var. +package config + +import ( + "errors" + "fmt" + "net/url" + "os" + "path/filepath" + "strings" + "time" + + "github.com/BurntSushi/toml" +) + +// Duration is a time.Duration that unmarshals from TOML strings ("60s"). +type Duration time.Duration + +func (d *Duration) UnmarshalText(b []byte) error { + v, err := time.ParseDuration(string(b)) + if err != nil { + return err + } + *d = Duration(v) + return nil +} + +func (d Duration) Std() time.Duration { return time.Duration(d) } + +``` diff --git a/.okf/codebase/internal/config/config_test.md b/.okf/codebase/internal/config/config_test.md new file mode 100644 index 000000000..c6f2e83ed --- /dev/null +++ b/.okf/codebase/internal/config/config_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/config/config_test.go (287 lines). +resource: internal/config/config_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: config_test.go +type: Module +--- + +# Module config_test.go + +**Path**: `internal/config/config_test.go` +**Lines**: 287 + +## Snippet Preview + +``` +package config + +import ( + "os" + "path/filepath" + "strings" + "testing" +) + +func TestDispatchDefaults(t *testing.T) { + // Simulate a config with no [dispatch] section — all fields zero. + var d Dispatch + d.Labels = map[string]string{} + + // Per-key defaults (mimicking Load's loop). + for k, v := range dispatchLabelDefaults { + if d.Labels[k] == "" { + d.Labels[k] = v + } + } + if d.Trigger == "" { + d.Trigger = "assignee" + } + if d.AckReaction == "" { + d.AckReaction = "eyes" + } + + // StateLabel should return the legacy constants. + if got := d.StateLabel("queued"); got != "archie:queued" { + t.Errorf("queued: got %q, want archie:queued", got) +``` diff --git a/.okf/codebase/internal/config/ecosystem.md b/.okf/codebase/internal/config/ecosystem.md new file mode 100644 index 000000000..9ccc6c7df --- /dev/null +++ b/.okf/codebase/internal/config/ecosystem.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/config/ecosystem.go (30 lines). +resource: internal/config/ecosystem.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: ecosystem.go +type: Module +--- + +# Module ecosystem.go + +**Path**: `internal/config/ecosystem.go` +**Lines**: 30 + +## Snippet Preview + +``` +package config + +// ecosystemDefaults holds the per-ecosystem default preflight check and +// test-file glob. An ecosystem not listed here (or "custom") means: no +// preflight at all, empty test glob (protection no-ops). +type ecosystemDefaults struct { + Preflight [][]string + TestGlob string +} + +// ecosystems maps known ecosystem names to their defaults. +// "custom" is deliberately absent — it means user-configured everything. +var ecosystems = map[string]ecosystemDefaults{ + "go": { + Preflight: [][]string{{"go", "version"}}, + TestGlob: "*_test.go", + }, + "python": { + Preflight: [][]string{{"python", "--version"}}, + TestGlob: "test_*.py", + }, + "node": { + Preflight: [][]string{{"node", "--version"}}, + TestGlob: "*.test.ts", + }, + "rust": { + Preflight: [][]string{{"cargo", "--version"}}, + TestGlob: "tests/*.rs", + }, +} +``` diff --git a/.okf/codebase/internal/config/index.md b/.okf/codebase/internal/config/index.md new file mode 100644 index 000000000..72bf4f086 --- /dev/null +++ b/.okf/codebase/internal/config/index.md @@ -0,0 +1,5 @@ +# Module + +* [config.go](config.md) - Source module internal/config/config.go (424 lines). +* [config_test.go](config_test.md) - Source module internal/config/config_test.go (287 lines). +* [ecosystem.go](ecosystem.md) - Source module internal/config/ecosystem.go (30 lines). diff --git a/.okf/codebase/internal/container/index.md b/.okf/codebase/internal/container/index.md new file mode 100644 index 000000000..5baf64464 --- /dev/null +++ b/.okf/codebase/internal/container/index.md @@ -0,0 +1,4 @@ +# Module + +* [pool.go](pool.md) - Source module internal/container/pool.go (258 lines). +* [pool_test.go](pool_test.md) - Source module internal/container/pool_test.go (115 lines). diff --git a/.okf/codebase/internal/container/pool.md b/.okf/codebase/internal/container/pool.md new file mode 100644 index 000000000..248b282df --- /dev/null +++ b/.okf/codebase/internal/container/pool.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/container/pool.go (258 lines). +resource: internal/container/pool.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: pool.go +type: Module +--- + +# Module pool.go + +**Path**: `internal/container/pool.go` +**Lines**: 258 + +## Snippet Preview + +``` +// Package container manages Docker containers running archie-agent. +// A Pool acquires and releases containers per task, handling image pull, +// creation, startup, health check, and teardown. The daemon's existing +// NATSRunner handles agent communication unchanged. +package container + +import ( + "context" + "encoding/json" + "fmt" + "io" + "log/slog" + "os" + "path/filepath" + "sync" + "time" + + "github.com/moby/moby/api/types/container" + "github.com/moby/moby/client" + + "github.com/samcharles93/archie-core/internal/storage" +) + +// Container wraps a running Docker container. +type Container struct { + ID string +} + +// TaskPayload is the boot-time brief written to /data/task.json before +// the container starts, per PRD section 3. +``` diff --git a/.okf/codebase/internal/container/pool_test.md b/.okf/codebase/internal/container/pool_test.md new file mode 100644 index 000000000..1ca469fea --- /dev/null +++ b/.okf/codebase/internal/container/pool_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/container/pool_test.go (115 lines). +resource: internal/container/pool_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: pool_test.go +type: Module +--- + +# Module pool_test.go + +**Path**: `internal/container/pool_test.go` +**Lines**: 115 + +## Snippet Preview + +``` +package container + +import ( + "encoding/json" + "os" + "path/filepath" + "testing" + "time" +) + +// ── regression: Gap 2 — post-completion grace period ──────────────── + +func TestContainerSupportsGracePeriod(t *testing.T) { + // Gap 2: MaxUptime is a container-level context timeout at creation, + // not a post-completion grace period. PRD section 1 says: + // "max_uptime — grace period after task completion before kill." + // + // The agent should stay alive after the task finishes so it can + // handle follow-ups (gate re-runs, human replies). Currently + // Release() stops the container immediately — there's no way to + // keep it alive after task completion. + + c := &Container{ID: "test"} + grace := 5 * time.Minute + + // A container must support being kept alive after task completion. + // This means: after Release() is called (task done), the container + // stays up for the grace period to handle follow-ups. Only after + // the grace period expires (or on explicit shutdown) is it killed. + // +``` diff --git a/.okf/codebase/internal/daemon/daemon.md b/.okf/codebase/internal/daemon/daemon.md new file mode 100644 index 000000000..137def635 --- /dev/null +++ b/.okf/codebase/internal/daemon/daemon.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/daemon/daemon.go (577 lines). +resource: internal/daemon/daemon.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: daemon.go +type: Module +--- + +# Module daemon.go + +**Path**: `internal/daemon/daemon.go` +**Lines**: 577 + +## Snippet Preview + +``` +// Package daemon is archied's resident loop: poll GitHub for labelled +// issues, enqueue them, and process one task at a time through its +// routed workflow. State lives in the store; the daemon is restartable +// at any point. +package daemon + +import ( + "context" + "fmt" + "log/slog" + "os" + "slices" + "strings" + "time" + + "github.com/samcharles93/ai-sdk/core" + "github.com/samcharles93/ai-sdk/runtime" + + "github.com/nats-io/nats.go/jetstream" + + "github.com/samcharles93/archie-core/internal/agentexec" + "github.com/samcharles93/archie-core/internal/config" + "github.com/samcharles93/archie-core/internal/container" + "github.com/samcharles93/archie-core/internal/events" + "github.com/samcharles93/archie-core/internal/forge" + arnats "github.com/samcharles93/archie-core/internal/nats" + "github.com/samcharles93/archie-core/internal/plugin" + "github.com/samcharles93/archie-core/internal/storage" + "github.com/samcharles93/archie-core/internal/store" + "github.com/samcharles93/archie-core/internal/workflow" +``` diff --git a/.okf/codebase/internal/daemon/daemon_test.md b/.okf/codebase/internal/daemon/daemon_test.md new file mode 100644 index 000000000..d7e65dfb0 --- /dev/null +++ b/.okf/codebase/internal/daemon/daemon_test.md @@ -0,0 +1,37 @@ +--- +description: Source module internal/daemon/daemon_test.go (17 lines). +resource: internal/daemon/daemon_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: daemon_test.go +type: Module +--- + +# Module daemon_test.go + +**Path**: `internal/daemon/daemon_test.go` +**Lines**: 17 + +## Snippet Preview + +``` +package daemon + +import "testing" + +func TestHasLabelUsesExactNames(t *testing.T) { + labels := []string{"bug", "archie:parked-old", "feature", "custom,label"} + if hasLabel(labels, "archie:parked") { + t.Fatal("hasLabel matched a label-name substring") + } + if !hasLabel(labels, "custom,label") { + t.Fatal("hasLabel did not preserve a label containing a comma") + } + labels = append(labels, "archie:parked") + if !hasLabel(labels, "archie:parked") { + t.Fatal("hasLabel did not match the exact label name") + } +} +``` diff --git a/.okf/codebase/internal/daemon/index.md b/.okf/codebase/internal/daemon/index.md new file mode 100644 index 000000000..5bacab739 --- /dev/null +++ b/.okf/codebase/internal/daemon/index.md @@ -0,0 +1,4 @@ +# Module + +* [daemon.go](daemon.md) - Source module internal/daemon/daemon.go (577 lines). +* [daemon_test.go](daemon_test.md) - Source module internal/daemon/daemon_test.go (17 lines). diff --git a/.okf/codebase/internal/events/events.md b/.okf/codebase/internal/events/events.md new file mode 100644 index 000000000..4b640f183 --- /dev/null +++ b/.okf/codebase/internal/events/events.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/events/events.go (128 lines). +resource: internal/events/events.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: events.go +type: Module +--- + +# Module events.go + +**Path**: `internal/events/events.go` +**Lines**: 128 + +## Snippet Preview + +``` +// Package events is archied's in-process observability stream, adapted +// from tau's eventbus but slimmed for a small daemon: one event type, +// mutex fan-out instead of a router goroutine, and — unlike tau's +// blocking delivery — bounded per-subscriber buffers that DROP on +// overflow, so a stalled dashboard connection can never apply +// backpressure to the task engine. +package events + +import ( + "sync" + "sync/atomic" + "time" +) + +// Kind values. Data carries kind-specific fields. +const ( + KindTaskQueued = "task_queued" + KindStageStart = "stage_start" + KindStageFinish = "stage_finish" // data: duration_ms, error + KindAgentFinish = "agent_finish" // data: status, stop_reason, tokens, iterations, model + KindParked = "parked" // data: reason + KindOutcome = "outcome" // data: status, detail + KindPRMerged = "pr_merged" + KindPRRejected = "pr_rejected" + KindLog = "log" // data: level, msg +) + +// Event is the single wire type: task lifecycle, stage progress, agent +// stats, and log lines all flow through it — every consumer (SQLite +// sink, SSE fan-out, future aggregators) is just another subscriber. +``` diff --git a/.okf/codebase/internal/events/events_test.md b/.okf/codebase/internal/events/events_test.md new file mode 100644 index 000000000..a06e8173e --- /dev/null +++ b/.okf/codebase/internal/events/events_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/events/events_test.go (46 lines). +resource: internal/events/events_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: events_test.go +type: Module +--- + +# Module events_test.go + +**Path**: `internal/events/events_test.go` +**Lines**: 46 + +## Snippet Preview + +``` +package events + +import "testing" + +func TestBusFanOutAndDrop(t *testing.T) { + b := NewBus() + defer b.Close() + + fast := b.Subscribe(8) + slow := b.Subscribe(2) // will overflow + + for i := range 5 { + b.Publish(Event{Kind: KindLog, Issue: i}) + } + + if got := len(fast.C); got != 5 { + t.Fatalf("fast subscriber buffered %d, want 5", got) + } + if got := len(slow.C); got != 2 { + t.Fatalf("slow subscriber buffered %d, want 2", got) + } + if d := slow.Dropped(); d != 3 { + t.Fatalf("slow.Dropped() = %d, want 3", d) + } + + e := <-fast.C + if e.At.IsZero() { + t.Fatal("Publish must stamp At") + } + +``` diff --git a/.okf/codebase/internal/events/index.md b/.okf/codebase/internal/events/index.md new file mode 100644 index 000000000..dfd1e555c --- /dev/null +++ b/.okf/codebase/internal/events/index.md @@ -0,0 +1,4 @@ +# Module + +* [events.go](events.md) - Source module internal/events/events.go (128 lines). +* [events_test.go](events_test.md) - Source module internal/events/events_test.go (46 lines). diff --git a/.okf/codebase/internal/forge/forge.md b/.okf/codebase/internal/forge/forge.md new file mode 100644 index 000000000..fd0e3bfe6 --- /dev/null +++ b/.okf/codebase/internal/forge/forge.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/forge/forge.go (56 lines). +resource: internal/forge/forge.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: forge.go +type: Module +--- + +# Module forge.go + +**Path**: `internal/forge/forge.go` +**Lines**: 56 + +## Snippet Preview + +``` +// Package forge defines the interface archie uses to interact with a git +// host — polling issues, managing labels, opening PRs, and reacting to +// comments. GitHub is the primary implementation; other hosts (Gitea, +// GitLab) can be added later by implementing this interface. +package forge + +import "context" + +// Issue is a forge-neutral representation of an issue (not a PR). +type Issue struct { + Number int + Title string + Body string + Labels []string +} + +// Forge is the interface for interacting with a git host. +type Forge interface { + // AcceptInvitations auto-accepts pending repository invitations. + AcceptInvitations(ctx context.Context) error + + // AssignedIssues returns open issues assigned to the given user, + // excluding PRs. + AssignedIssues(ctx context.Context, owner, repo, assignee string) ([]Issue, error) + + // IssuesWithLabel returns open issues matching the given label, + // excluding PRs. Used when Dispatch.Trigger is "label" or "either". + IssuesWithLabel(ctx context.Context, owner, repo, label string) ([]Issue, error) + + // Comment posts an issue (or PR) comment and returns its id. +``` diff --git a/.okf/codebase/internal/forge/github.md b/.okf/codebase/internal/forge/github.md new file mode 100644 index 000000000..ef35e2e00 --- /dev/null +++ b/.okf/codebase/internal/forge/github.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/forge/github.go (309 lines). +resource: internal/forge/github.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: github.go +type: Module +--- + +# Module github.go + +**Path**: `internal/forge/github.go` +**Lines**: 309 + +## Snippet Preview + +``` +// Package forge wraps the GitHub API surface archied needs: polling +// labelled issues, accepting collaborator invitations, commenting, and +// opening pull requests. Gitea support later lands as a second +// implementation behind the same methods. +package forge + +import ( + "context" + "fmt" + "log/slog" + "strings" + "sync" + + "github.com/google/go-github/v78/github" +) + +// GitHubClient implements Forge against the GitHub API. +type GitHubClient struct { + gh *github.Client + log *slog.Logger + + labelMu sync.Mutex + labelsEnsured map[string]bool +} + +// New creates a GitHub-backed Forge implementation. Non-github.com hosts +// are configured using GitHub Enterprise's API and upload URL conventions. +func New(token, host string, log *slog.Logger) (Forge, error) { + client := github.NewClient(nil) + if strings.TrimRight(host, "/") != "https://github.com" { +``` diff --git a/.okf/codebase/internal/forge/github_methods_test.md b/.okf/codebase/internal/forge/github_methods_test.md new file mode 100644 index 000000000..2dd3cae28 --- /dev/null +++ b/.okf/codebase/internal/forge/github_methods_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/forge/github_methods_test.go (359 lines). +resource: internal/forge/github_methods_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: github_methods_test.go +type: Module +--- + +# Module github_methods_test.go + +**Path**: `internal/forge/github_methods_test.go` +**Lines**: 359 + +## Snippet Preview + +``` +package forge + +import ( + "encoding/json" + "net/http" + "testing" +) + +func writeJSON(t *testing.T, w http.ResponseWriter, v any) { + t.Helper() + w.Header().Set("Content-Type", "application/json") + if err := json.NewEncoder(w).Encode(v); err != nil { + t.Fatal(err) + } +} + +func TestAssignedIssuesExcludesPRs(t *testing.T) { + c, mux := newTestClient(t) + mux.HandleFunc("GET /repos/o/r/issues", func(w http.ResponseWriter, r *http.Request) { + if got := r.URL.Query().Get("assignee"); got != "archie-bot" { + t.Errorf("assignee = %q", got) + } + writeJSON(t, w, []map[string]any{ + {"number": 1, "title": "real issue", "body": "b", "labels": []map[string]any{{"name": "bug"}}}, + {"number": 2, "title": "a pr", "pull_request": map[string]any{"url": "x"}}, + }) + }) + + issues, err := c.AssignedIssues(t.Context(), "o", "r", "archie-bot") + if err != nil { +``` diff --git a/.okf/codebase/internal/forge/github_test.md b/.okf/codebase/internal/forge/github_test.md new file mode 100644 index 000000000..1d698898c --- /dev/null +++ b/.okf/codebase/internal/forge/github_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/forge/github_test.go (45 lines). +resource: internal/forge/github_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: github_test.go +type: Module +--- + +# Module github_test.go + +**Path**: `internal/forge/github_test.go` +**Lines**: 45 + +## Snippet Preview + +``` +package forge + +import ( + "io" + "log/slog" + "testing" +) + +func TestNewConfiguresHost(t *testing.T) { + tests := []struct { + name string + host string + wantBase string + wantUpload string + }{ + { + name: "github.com", + host: "https://github.com", + wantBase: "https://api.github.com/", + wantUpload: "https://uploads.github.com/", + }, + { + name: "enterprise", + host: "https://git.example.com", + wantBase: "https://git.example.com/api/v3/", + wantUpload: "https://git.example.com/api/uploads/", + }, + } + + for _, tt := range tests { +``` diff --git a/.okf/codebase/internal/forge/index.md b/.okf/codebase/internal/forge/index.md new file mode 100644 index 000000000..2cf2b6904 --- /dev/null +++ b/.okf/codebase/internal/forge/index.md @@ -0,0 +1,7 @@ +# Module + +* [forge.go](forge.md) - Source module internal/forge/forge.go (56 lines). +* [github.go](github.md) - Source module internal/forge/github.go (309 lines). +* [github_methods_test.go](github_methods_test.md) - Source module internal/forge/github_methods_test.go (359 lines). +* [github_test.go](github_test.md) - Source module internal/forge/github_test.go (45 lines). +* [testclient_test.go](testclient_test.md) - Source module internal/forge/testclient_test.go (31 lines). diff --git a/.okf/codebase/internal/forge/testclient_test.md b/.okf/codebase/internal/forge/testclient_test.md new file mode 100644 index 000000000..3f1b48bd2 --- /dev/null +++ b/.okf/codebase/internal/forge/testclient_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/forge/testclient_test.go (31 lines). +resource: internal/forge/testclient_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: testclient_test.go +type: Module +--- + +# Module testclient_test.go + +**Path**: `internal/forge/testclient_test.go` +**Lines**: 31 + +## Snippet Preview + +``` +package forge + +import ( + "io" + "log/slog" + "net/http" + "net/http/httptest" + "net/url" + "testing" + + "github.com/google/go-github/v78/github" +) + +// newTestClient wires a GitHubClient at a local httptest server so its +// methods can be exercised without hitting the real GitHub API. +func newTestClient(t *testing.T) (*GitHubClient, *http.ServeMux) { + t.Helper() + mux := http.NewServeMux() + srv := httptest.NewServer(mux) + t.Cleanup(srv.Close) + + gh := github.NewClient(nil) + base, err := url.Parse(srv.URL + "/") + if err != nil { + t.Fatal(err) + } + gh.BaseURL = base + gh.UploadURL = base + + return &GitHubClient{gh: gh, log: slog.New(slog.NewTextHandler(io.Discard, nil))}, mux +``` diff --git a/.okf/codebase/internal/gate/gate.md b/.okf/codebase/internal/gate/gate.md new file mode 100644 index 000000000..b904503a4 --- /dev/null +++ b/.okf/codebase/internal/gate/gate.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/gate/gate.go (41 lines). +resource: internal/gate/gate.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: gate.go +type: Module +--- + +# Module gate.go + +**Path**: `internal/gate/gate.go` +**Lines**: 41 + +## Snippet Preview + +``` +// Package gate defines the runtime-evaluated custom gate surface: a +// per-repo .archie/gate.go, interpreted via Yaegi after the shell-based +// gate passes, that inspects the diff and worktree for project-specific +// rules shell commands can't express (AST checks, diff scanning, and +// the like). +package gate + +// GateContext carries everything a custom gate function can inspect. +type GateContext struct { + // Diff is the unified diff of all changes against BaseRef. + Diff string + // ChangedFiles lists changed file paths, repo-relative. + ChangedFiles []string + // Dir is the absolute worktree path. + Dir string + // BaseRef is the base branch the diff is against (e.g. "origin/main"). + BaseRef string + // Repo is "owner/name". + Repo string +} + +// Finding is one gate violation. +type Finding struct { + // Level is "error" (blocks the gate) or "warn" (advisory, logged only). + Level string + // File is the optional file path the finding applies to. + File string + // Line is the optional line number within File. + Line int + Message string +``` diff --git a/.okf/codebase/internal/gate/gateeval/index.md b/.okf/codebase/internal/gate/gateeval/index.md new file mode 100644 index 000000000..6914bb283 --- /dev/null +++ b/.okf/codebase/internal/gate/gateeval/index.md @@ -0,0 +1,4 @@ +# Module + +* [yaegi.go](yaegi.md) - Source module internal/gate/gateeval/yaegi.go (67 lines). +* [yaegi_test.go](yaegi_test.md) - Source module internal/gate/gateeval/yaegi_test.go (145 lines). diff --git a/.okf/codebase/internal/gate/gateeval/yaegi.md b/.okf/codebase/internal/gate/gateeval/yaegi.md new file mode 100644 index 000000000..6f129835c --- /dev/null +++ b/.okf/codebase/internal/gate/gateeval/yaegi.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/gate/gateeval/yaegi.go (67 lines). +resource: internal/gate/gateeval/yaegi.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: yaegi.go +type: Module +--- + +# Module yaegi.go + +**Path**: `internal/gate/gateeval/yaegi.go` +**Lines**: 67 + +## Snippet Preview + +``` +// Package gateeval evaluates a repo's .archie/gate.go via Yaegi. Split +// from internal/gate (which only declares the GateContext/Finding types) +// because the generated symbol table in gateextract imports internal/gate — +// this package sits above both to avoid the resulting import cycle. +package gateeval + +import ( + "errors" + "fmt" + "os" + "path/filepath" + + "github.com/traefik/yaegi/interp" + "github.com/traefik/yaegi/stdlib" + + "github.com/samcharles93/archie-core/internal/gate" + "github.com/samcharles93/archie-core/internal/gate/gateextract" +) + +// scriptPath is the per-repo custom gate script, relative to the +// worktree root. +const scriptPath = ".archie/gate.go" + +// Evaluate loads and runs the repo's .archie/gate.go against gctx. A +// missing script is not an error — it returns (nil, nil), meaning no +// custom gate is configured for this repo. The script runs in-process +// (interpreted, not sandboxed), so a panic inside it — nil dereference, +// out-of-range index — is recovered and returned as an error rather than +// taking down the daemon. +func Evaluate(gctx gate.GateContext) (findings []gate.Finding, err error) { +``` diff --git a/.okf/codebase/internal/gate/gateeval/yaegi_test.md b/.okf/codebase/internal/gate/gateeval/yaegi_test.md new file mode 100644 index 000000000..58c9482b7 --- /dev/null +++ b/.okf/codebase/internal/gate/gateeval/yaegi_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/gate/gateeval/yaegi_test.go (145 lines). +resource: internal/gate/gateeval/yaegi_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: yaegi_test.go +type: Module +--- + +# Module yaegi_test.go + +**Path**: `internal/gate/gateeval/yaegi_test.go` +**Lines**: 145 + +## Snippet Preview + +``` +package gateeval + +import ( + "os" + "path/filepath" + "testing" + + "github.com/samcharles93/archie-core/internal/gate" +) + +func writeGateScript(t *testing.T, dir, src string) { + t.Helper() + archieDir := filepath.Join(dir, ".archie") + if err := os.MkdirAll(archieDir, 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(archieDir, "gate.go"), []byte(src), 0o644); err != nil { + t.Fatal(err) + } +} + +func TestEvaluateNoScript(t *testing.T) { + dir := t.TempDir() + findings, err := Evaluate(gate.GateContext{Dir: dir}) + if err != nil { + t.Fatalf("Evaluate() error = %v, want nil (no script configured)", err) + } + if findings != nil { + t.Fatalf("Evaluate() findings = %v, want nil", findings) + } +``` diff --git a/.okf/codebase/internal/gate/gateextract/gateextract.md b/.okf/codebase/internal/gate/gateextract/gateextract.md new file mode 100644 index 000000000..b52ef61fc --- /dev/null +++ b/.okf/codebase/internal/gate/gateextract/gateextract.md @@ -0,0 +1,30 @@ +--- +description: Source module internal/gate/gateextract/gateextract.go (10 lines). +resource: internal/gate/gateextract/gateextract.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: gateextract.go +type: Module +--- + +# Module gateextract.go + +**Path**: `internal/gate/gateextract/gateextract.go` +**Lines**: 10 + +## Snippet Preview + +``` +// Package gateextract holds the Yaegi symbol table for internal/gate, +// generated by `go generate`. Kept separate from internal/gate itself so +// the generated file can import it without a self-import cycle. +package gateextract + +import "reflect" + +//go:generate go run github.com/traefik/yaegi/cmd/yaegi extract -name gateextract github.com/samcharles93/archie-core/internal/gate + +var Symbols = map[string]map[string]reflect.Value{} +``` diff --git a/.okf/codebase/internal/gate/gateextract/github_com-samcharles93-archie-core-internal-gate.md b/.okf/codebase/internal/gate/gateextract/github_com-samcharles93-archie-core-internal-gate.md new file mode 100644 index 000000000..54e1acc92 --- /dev/null +++ b/.okf/codebase/internal/gate/gateextract/github_com-samcharles93-archie-core-internal-gate.md @@ -0,0 +1,39 @@ +--- +description: Source module internal/gate/gateextract/github_com-samcharles93-archie-core-internal-gate.go (19 lines). +resource: internal/gate/gateextract/github_com-samcharles93-archie-core-internal-gate.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: github_com-samcharles93-archie-core-internal-gate.go +type: Module +--- + +# Module github_com-samcharles93-archie-core-internal-gate.go + +**Path**: `internal/gate/gateextract/github_com-samcharles93-archie-core-internal-gate.go` +**Lines**: 19 + +## Snippet Preview + +``` +// Code generated by 'yaegi extract github.com/samcharles93/archie-core/internal/gate'. DO NOT EDIT. + +package gateextract + +import ( + "github.com/samcharles93/archie-core/internal/gate" + "reflect" +) + +func init() { + Symbols["github.com/samcharles93/archie-core/internal/gate/gate"] = map[string]reflect.Value{ + // function, constant and variable definitions + "Blocking": reflect.ValueOf(gate.Blocking), + + // type definitions + "Finding": reflect.ValueOf((*gate.Finding)(nil)), + "GateContext": reflect.ValueOf((*gate.GateContext)(nil)), + } +} +``` diff --git a/.okf/codebase/internal/gate/gateextract/index.md b/.okf/codebase/internal/gate/gateextract/index.md new file mode 100644 index 000000000..d298bf77a --- /dev/null +++ b/.okf/codebase/internal/gate/gateextract/index.md @@ -0,0 +1,4 @@ +# Module + +* [gateextract.go](gateextract.md) - Source module internal/gate/gateextract/gateextract.go (10 lines). +* [github_com-samcharles93-archie-core-internal-gate.go](github_com-samcharles93-archie-core-internal-gate.md) - Source module internal/gate/gateextract/github_com-samcharles93-archie-core-internal-gate.go (19 lines). diff --git a/.okf/codebase/internal/gate/index.md b/.okf/codebase/internal/gate/index.md new file mode 100644 index 000000000..a0d855553 --- /dev/null +++ b/.okf/codebase/internal/gate/index.md @@ -0,0 +1,8 @@ +# Module + +* [gate.go](gate.md) - Source module internal/gate/gate.go (41 lines). + +# Subdirectories + +* [gateeval](gateeval/index.md) - Directory containing 2 items, including: yaegi.go. +* [gateextract](gateextract/index.md) - Directory containing 2 items, including: gateextract.go. diff --git a/.okf/codebase/internal/index.md b/.okf/codebase/internal/index.md new file mode 100644 index 000000000..e45823456 --- /dev/null +++ b/.okf/codebase/internal/index.md @@ -0,0 +1,18 @@ +# Subdirectories + +* [agentexec](agentexec/index.md) - Directory containing 13 items, including: inprocess.go. +* [config](config/index.md) - Directory containing 3 items, including: config.go. +* [container](container/index.md) - Directory containing 2 items, including: pool.go. +* [daemon](daemon/index.md) - Directory containing 2 items, including: daemon.go. +* [events](events/index.md) - Directory containing 2 items, including: events.go. +* [forge](forge/index.md) - Directory containing 5 items, including: forge.go. +* [gate](gate/index.md) - Directory containing 3 items, including: gate.go. +* [nats](nats/index.md) - Directory containing 3 items, including: client.go. +* [plugin](plugin/index.md) - Directory containing 3 items, including: plugin.go. +* [skill](skill/index.md) - Directory containing 6 items, including: catalog_test.go. +* [skillscript](skillscript/index.md) - Directory containing 2 items, including: yaegi.go. +* [storage](storage/index.md) - Directory containing 2 items, including: storage.go. +* [store](store/index.md) - Directory containing 4 items, including: events.go. +* [webui](webui/index.md) - Directory containing 2 items, including: webui.go. +* [workflow](workflow/index.md) - Directory containing 13 items, including: agent.go. +* [worktree](worktree/index.md) - Directory containing 2 items, including: worktree.go. diff --git a/.okf/codebase/internal/nats/client.md b/.okf/codebase/internal/nats/client.md new file mode 100644 index 000000000..4f8fb7de5 --- /dev/null +++ b/.okf/codebase/internal/nats/client.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/nats/client.go (176 lines). +resource: internal/nats/client.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: client.go +type: Module +--- + +# Module client.go + +**Path**: `internal/nats/client.go` +**Lines**: 176 + +## Snippet Preview + +``` +package nats + +import ( + "context" + "encoding/json" + "fmt" + "log/slog" + "strings" + "time" + + "github.com/nats-io/nats.go" + "github.com/nats-io/nats.go/jetstream" +) + +const ( + streamName = "ARCHIE_TASKS" + consumerName = "archie-daemon" + msgPrefix = "archie:" // for Nats-Msg-Id dedup + dedupWindow = 2 * time.Minute + pollTimeout = 2 * time.Second +) + +// TaskMessage is the NATS payload for a discovered issue. +type TaskMessage struct { + Owner string `json:"owner"` + Repo string `json:"repo"` + Number int `json:"number"` + Title string `json:"title"` + Body string `json:"body"` + Labels string `json:"labels"` // comma-separated +``` diff --git a/.okf/codebase/internal/nats/client_test.md b/.okf/codebase/internal/nats/client_test.md new file mode 100644 index 000000000..dad9cfa82 --- /dev/null +++ b/.okf/codebase/internal/nats/client_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/nats/client_test.go (118 lines). +resource: internal/nats/client_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: client_test.go +type: Module +--- + +# Module client_test.go + +**Path**: `internal/nats/client_test.go` +**Lines**: 118 + +## Snippet Preview + +``` +package nats + +import ( + "context" + "log/slog" + "testing" + + "github.com/nats-io/nats-server/v2/server" + natssrv "github.com/nats-io/nats-server/v2/test" +) + +func startEmbedded(t *testing.T) *server.Server { + t.Helper() + srv := natssrv.RunRandClientPortServer() + t.Cleanup(srv.Shutdown) + jsDir := t.TempDir() + if err := srv.EnableJetStream(&server.JetStreamConfig{StoreDir: jsDir}); err != nil { + t.Fatalf("enable jetstream: %v", err) + } + return srv +} + +func TestConnectAndPublish(t *testing.T) { + srv := startEmbedded(t) + url := srv.ClientURL() + + ctx := context.Background() + client, err := Connect(ctx, url, slog.New(slog.DiscardHandler)) + if err != nil { + t.Fatal(err) +``` diff --git a/.okf/codebase/internal/nats/index.md b/.okf/codebase/internal/nats/index.md new file mode 100644 index 000000000..368d7a213 --- /dev/null +++ b/.okf/codebase/internal/nats/index.md @@ -0,0 +1,5 @@ +# Module + +* [client.go](client.md) - Source module internal/nats/client.go (176 lines). +* [client_test.go](client_test.md) - Source module internal/nats/client_test.go (118 lines). +* [subjects.go](subjects.md) - Source module internal/nats/subjects.go (74 lines). diff --git a/.okf/codebase/internal/nats/subjects.md b/.okf/codebase/internal/nats/subjects.md new file mode 100644 index 000000000..a0238146c --- /dev/null +++ b/.okf/codebase/internal/nats/subjects.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/nats/subjects.go (74 lines). +resource: internal/nats/subjects.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: subjects.go +type: Module +--- + +# Module subjects.go + +**Path**: `internal/nats/subjects.go` +**Lines**: 74 + +## Snippet Preview + +``` +// Package nats manages the NATS JetStream connection for task distribution +// and agent communication. When configured, the daemon publishes discovered +// issues to NATS subjects and consumes them back via a JetStream pull +// consumer. Agent workers consume stage execution requests and reply via +// core NATS inboxes. When not configured (nil client), the existing SQLite +// ClaimNext flow is used unchanged. +package nats + +import ( + "fmt" + "strings" +) + +// Task distribution subjects. Each subject encodes the workflow type so +// future multi-daemon deployments can filter by workflow. +const ( + SubjectTaskBug = "archie.task.bug" + SubjectTaskFeature = "archie.task.feature" + SubjectTaskDefault = "archie.task.default" + SubjectTaskBootstrap = "archie.task.bootstrap" +) + +// SubjectForLabels picks the NATS subject based on issue labels, mirroring +// the label-to-workflow mapping in workflow.Route. +// +// "bug" -> archie.task.bug +// "feature" -> archie.task.feature +// "bootstrap" -> archie.task.bootstrap +// default -> archie.task.default +func SubjectForLabels(labels []string) string { +``` diff --git a/.okf/codebase/internal/plugin/index.md b/.okf/codebase/internal/plugin/index.md new file mode 100644 index 000000000..589bf9364 --- /dev/null +++ b/.okf/codebase/internal/plugin/index.md @@ -0,0 +1,8 @@ +# Module + +* [plugin.go](plugin.md) - Source module internal/plugin/plugin.go (96 lines). +* [plugin_test.go](plugin_test.md) - Source module internal/plugin/plugin_test.go (417 lines). + +# Subdirectories + +* [pluginextract](pluginextract/index.md) - Directory containing 2 items, including: github_com-samcharles93-archie-core-internal-plugin.go. diff --git a/.okf/codebase/internal/plugin/plugin.md b/.okf/codebase/internal/plugin/plugin.md new file mode 100644 index 000000000..764fa8b53 --- /dev/null +++ b/.okf/codebase/internal/plugin/plugin.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/plugin/plugin.go (96 lines). +resource: internal/plugin/plugin.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: plugin.go +type: Module +--- + +# Module plugin.go + +**Path**: `internal/plugin/plugin.go` +**Lines**: 96 + +## Snippet Preview + +``` +// Package plugin defines the core plugin interface for extending archie-core's +// daemon at startup. Plugins are Yaegi-interpreted .go files loaded from +// ~/.config/archie/plugins/ that register themselves with the daemon's +// extension registry. PRD section 5 Layer 2. +package plugin + +import ( + "fmt" + "os" + "path/filepath" + "reflect" + "sort" + "strings" + + "github.com/traefik/yaegi/interp" + "github.com/traefik/yaegi/stdlib" +) + +// Plugin is a core plugin loaded by the daemon at startup. Each .go file +// in ~/.config/archie/plugins/ must export a variable named "Plugin" that +// satisfies this interface. +type Plugin interface { + Name() string + Version() string +} + +// Registry holds loaded plugins and dispatches extension point calls. +type Registry struct { + plugins []Plugin +} +``` diff --git a/.okf/codebase/internal/plugin/plugin_test.md b/.okf/codebase/internal/plugin/plugin_test.md new file mode 100644 index 000000000..3a59b9cce --- /dev/null +++ b/.okf/codebase/internal/plugin/plugin_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/plugin/plugin_test.go (417 lines). +resource: internal/plugin/plugin_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: plugin_test.go +type: Module +--- + +# Module plugin_test.go + +**Path**: `internal/plugin/plugin_test.go` +**Lines**: 417 + +## Snippet Preview + +``` +package plugin_test + +import ( + "os" + "path/filepath" + "testing" + + "github.com/samcharles93/archie-core/internal/plugin" + "github.com/samcharles93/archie-core/internal/plugin/pluginextract" +) + +// ── Plugin interface and registry ──────────────────────────────────── + +func TestPluginInterfaceExists(t *testing.T) { + var p plugin.Plugin + _ = p + type nameVersioner interface { + Name() string + Version() string + } + var _ nameVersioner = p +} + +func TestRegistryExists(t *testing.T) { + r := &plugin.Registry{} + if r == nil { + t.Fatal("Registry type is not defined") + } +} + +``` diff --git a/.okf/codebase/internal/plugin/pluginextract/github_com-samcharles93-archie-core-internal-plugin.md b/.okf/codebase/internal/plugin/pluginextract/github_com-samcharles93-archie-core-internal-plugin.md new file mode 100644 index 000000000..aee1aa6f4 --- /dev/null +++ b/.okf/codebase/internal/plugin/pluginextract/github_com-samcharles93-archie-core-internal-plugin.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/plugin/pluginextract/github_com-samcharles93-archie-core-internal-plugin.go (42 lines). +resource: internal/plugin/pluginextract/github_com-samcharles93-archie-core-internal-plugin.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: github_com-samcharles93-archie-core-internal-plugin.go +type: Module +--- + +# Module github_com-samcharles93-archie-core-internal-plugin.go + +**Path**: `internal/plugin/pluginextract/github_com-samcharles93-archie-core-internal-plugin.go` +**Lines**: 42 + +## Snippet Preview + +``` +// Code generated by 'yaegi extract github.com/samcharles93/archie-core/internal/plugin'. DO NOT EDIT. + +package pluginextract + +import ( + "github.com/samcharles93/archie-core/internal/plugin" + "reflect" +) + +func init() { + Symbols["github.com/samcharles93/archie-core/internal/plugin/plugin"] = map[string]reflect.Value{ + // function, constant and variable definitions + "LoadDir": reflect.ValueOf(plugin.LoadDir), + + // type definitions + "Plugin": reflect.ValueOf((*plugin.Plugin)(nil)), + "Registry": reflect.ValueOf((*plugin.Registry)(nil)), + + // interface wrapper definitions + "_Plugin": reflect.ValueOf((*_github_com_samcharles93_archie_core_internal_plugin_Plugin)(nil)), + } +} + +// _github_com_samcharles93_archie_core_internal_plugin_Plugin is an interface wrapper for Plugin type +type _github_com_samcharles93_archie_core_internal_plugin_Plugin struct { + IValue interface{} + WName func() string + WVersion func() string +} + +``` diff --git a/.okf/codebase/internal/plugin/pluginextract/index.md b/.okf/codebase/internal/plugin/pluginextract/index.md new file mode 100644 index 000000000..b056b7053 --- /dev/null +++ b/.okf/codebase/internal/plugin/pluginextract/index.md @@ -0,0 +1,4 @@ +# Module + +* [github_com-samcharles93-archie-core-internal-plugin.go](github_com-samcharles93-archie-core-internal-plugin.md) - Source module internal/plugin/pluginextract/github_com-samcharles93-archie-core-internal-plugin.go (42 lines). +* [pluginextract.go](pluginextract.md) - Source module internal/plugin/pluginextract/pluginextract.go (10 lines). diff --git a/.okf/codebase/internal/plugin/pluginextract/pluginextract.md b/.okf/codebase/internal/plugin/pluginextract/pluginextract.md new file mode 100644 index 000000000..041a34ab4 --- /dev/null +++ b/.okf/codebase/internal/plugin/pluginextract/pluginextract.md @@ -0,0 +1,30 @@ +--- +description: Source module internal/plugin/pluginextract/pluginextract.go (10 lines). +resource: internal/plugin/pluginextract/pluginextract.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: pluginextract.go +type: Module +--- + +# Module pluginextract.go + +**Path**: `internal/plugin/pluginextract/pluginextract.go` +**Lines**: 10 + +## Snippet Preview + +``` +// Package pluginextract holds the Yaegi symbol table for internal/plugin, +// generated by `go generate`. Kept separate from internal/plugin itself +// so the generated file can import it without a self-import cycle. +package pluginextract + +import "reflect" + +//go:generate go run github.com/traefik/yaegi/cmd/yaegi extract -name pluginextract github.com/samcharles93/archie-core/internal/plugin + +var Symbols = map[string]map[string]reflect.Value{} +``` diff --git a/.okf/codebase/internal/skill/catalog_test.md b/.okf/codebase/internal/skill/catalog_test.md new file mode 100644 index 000000000..184275aba --- /dev/null +++ b/.okf/codebase/internal/skill/catalog_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/skill/catalog_test.go (211 lines). +resource: internal/skill/catalog_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: catalog_test.go +type: Module +--- + +# Module catalog_test.go + +**Path**: `internal/skill/catalog_test.go` +**Lines**: 211 + +## Snippet Preview + +``` +package skill + +import ( + "os" + "path/filepath" + "strings" + "testing" +) + +// ── progressive disclosure: catalog tier ───────────────────────────── + +func TestCatalogReturnsNameAndDescriptionOnly(t *testing.T) { + // Catalog tier (~100 tokens per skill): name + description loaded at + // daemon startup. Full body is Tier 2, loaded on skill activation. + // Currently Discover() returns the full Skill (frontmatter + body). + // Catalog() must return only the catalog entries without bodies. + + dir := t.TempDir() + skillsDir := filepath.Join(dir, ".agents", "skills", "archie-wf-tdd") + if err := os.MkdirAll(skillsDir, 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(skillsDir, "SKILL.md"), []byte(`--- +name: archie-wf-tdd +description: TDD bugfix workflow — reproduce, prove, fix. +version: 1.0.0 +metadata: + archie: + tools: [go] + engine: any +``` diff --git a/.okf/codebase/internal/skill/frontmatter_test.md b/.okf/codebase/internal/skill/frontmatter_test.md new file mode 100644 index 000000000..ffe1d22ad --- /dev/null +++ b/.okf/codebase/internal/skill/frontmatter_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/skill/frontmatter_test.go (40 lines). +resource: internal/skill/frontmatter_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: frontmatter_test.go +type: Module +--- + +# Module frontmatter_test.go + +**Path**: `internal/skill/frontmatter_test.go` +**Lines**: 40 + +## Snippet Preview + +``` +package skill + +import "testing" + +// ── regression: Gap 8 — frontmatter missing plugins key ───────────── + +func TestFrontmatterMetadataArchieHasPluginsField(t *testing.T) { + // Gap 8: Frontmatter.Metadata.Archie has Tools and Engine only. + // PRD section 5 shows a plugins array in metadata.archie: + // plugins: [plugins/custom-gate.go, plugins/gosec-check.go] + + fm, _, err := Parse([]byte(`--- +name: test-skill +description: desc +version: 1.0.0 +metadata: + archie: + tools: [go] + engine: any + plugins: + - plugins/custom-gate.go + - plugins/gosec-check.go +--- +Body. +`)) + if err != nil { + t.Fatal(err) + } + if fm.Metadata.Archie == nil { + t.Fatal("Metadata.Archie is nil") +``` diff --git a/.okf/codebase/internal/skill/index.md b/.okf/codebase/internal/skill/index.md new file mode 100644 index 000000000..1ebd2c9cc --- /dev/null +++ b/.okf/codebase/internal/skill/index.md @@ -0,0 +1,8 @@ +# Module + +* [catalog_test.go](catalog_test.md) - Source module internal/skill/catalog_test.go (211 lines). +* [frontmatter_test.go](frontmatter_test.md) - Source module internal/skill/frontmatter_test.go (40 lines). +* [plugin.go](plugin.md) - Source module internal/skill/plugin.go (83 lines). +* [plugin_test.go](plugin_test.md) - Source module internal/skill/plugin_test.go (209 lines). +* [skill.go](skill.md) - Source module internal/skill/skill.go (193 lines). +* [skill_test.go](skill_test.md) - Source module internal/skill/skill_test.go (164 lines). diff --git a/.okf/codebase/internal/skill/plugin.md b/.okf/codebase/internal/skill/plugin.md new file mode 100644 index 000000000..deaf492cf --- /dev/null +++ b/.okf/codebase/internal/skill/plugin.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/skill/plugin.go (83 lines). +resource: internal/skill/plugin.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: plugin.go +type: Module +--- + +# Module plugin.go + +**Path**: `internal/skill/plugin.go` +**Lines**: 83 + +## Snippet Preview + +``` +package skill + +import ( + "fmt" + "os" + "path/filepath" + "sort" + "strings" + + "github.com/traefik/yaegi/interp" + "github.com/traefik/yaegi/stdlib" +) + +// Plugin is a discovered Yaegi-interpreted .go file in a skill's plugins/ +// directory. The source must be a valid Go package exporting a Run function: +// +// func Run(input string) string +type Plugin struct { + Name string // filename without .go extension + Path string // full path to the .go file + Src string // source code content +} + +// Run interprets the plugin source via Yaegi and calls its Run function +// with the given input. The plugin runs with full standard library access. +func (p *Plugin) Run(input string) (string, error) { + i := interp.New(interp.Options{}) + if err := i.Use(stdlib.Symbols); err != nil { + return "", fmt.Errorf("plugin %s: stdlib: %w", p.Name, err) + } +``` diff --git a/.okf/codebase/internal/skill/plugin_test.md b/.okf/codebase/internal/skill/plugin_test.md new file mode 100644 index 000000000..18f99da1b --- /dev/null +++ b/.okf/codebase/internal/skill/plugin_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/skill/plugin_test.go (209 lines). +resource: internal/skill/plugin_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: plugin_test.go +type: Module +--- + +# Module plugin_test.go + +**Path**: `internal/skill/plugin_test.go` +**Lines**: 209 + +## Snippet Preview + +``` +package skill + +import ( + "os" + "path/filepath" + "testing" +) + +func TestDiscoverPlugins(t *testing.T) { + dir := t.TempDir() + skillsDir := filepath.Join(dir, ".agents", "skills", "my-skill") + pluginsDir := filepath.Join(skillsDir, "plugins") + if err := os.MkdirAll(pluginsDir, 0o755); err != nil { + t.Fatal(err) + } + + // Write a SKILL.md so the skill directory is valid. + if err := os.WriteFile(filepath.Join(skillsDir, "SKILL.md"), []byte(`--- +name: my-skill +description: A test skill +version: 1.0.0 +--- +Body. +`), 0o644); err != nil { + t.Fatal(err) + } + + // Write two plugin files. + checkGo := `package main + +``` diff --git a/.okf/codebase/internal/skill/skill.md b/.okf/codebase/internal/skill/skill.md new file mode 100644 index 000000000..54398db5d --- /dev/null +++ b/.okf/codebase/internal/skill/skill.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/skill/skill.go (193 lines). +resource: internal/skill/skill.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: skill.go +type: Module +--- + +# Module skill.go + +**Path**: `internal/skill/skill.go` +**Lines**: 193 + +## Snippet Preview + +``` +// Package skill parses agentskills.io SKILL.md files and discovers skills +// from the .agents/skills/ directory convention. It follows the same discovery +// pattern as internal/workflow/wfeval (missing directory is not an error). +package skill + +import ( + "fmt" + "os" + "path/filepath" + "sort" + "strings" + + "gopkg.in/yaml.v3" +) + +// Frontmatter is the parsed YAML frontmatter of a SKILL.md file. +type Frontmatter struct { + Name string `yaml:"name"` + Description string `yaml:"description"` + Version string `yaml:"version"` + Metadata struct { + Archie *struct { + Tools []string `yaml:"tools"` + Engine string `yaml:"engine"` + Plugins []string `yaml:"plugins,omitempty"` + Workflow string `yaml:"workflow,omitempty"` + } `yaml:"archie"` + } `yaml:"metadata"` +} + +``` diff --git a/.okf/codebase/internal/skill/skill_test.md b/.okf/codebase/internal/skill/skill_test.md new file mode 100644 index 000000000..fd2c41dfc --- /dev/null +++ b/.okf/codebase/internal/skill/skill_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/skill/skill_test.go (164 lines). +resource: internal/skill/skill_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: skill_test.go +type: Module +--- + +# Module skill_test.go + +**Path**: `internal/skill/skill_test.go` +**Lines**: 164 + +## Snippet Preview + +``` +package skill + +import ( + "os" + "path/filepath" + "testing" +) + +func TestParse(t *testing.T) { + src := []byte(`--- +name: tdd-bugfix +description: Fix bugs with TDD +version: 1.0.0 +metadata: + archie: + tools: [go, golangci-lint] + engine: any +--- + +## Stage 1: Analyse + +Read the code and find the bug. +`) + fm, body, err := Parse(src) + if err != nil { + t.Fatal(err) + } + if fm.Name != "tdd-bugfix" { + t.Errorf("Name: got %q, want tdd-bugfix", fm.Name) + } +``` diff --git a/.okf/codebase/internal/skillscript/index.md b/.okf/codebase/internal/skillscript/index.md new file mode 100644 index 000000000..ce8be19a6 --- /dev/null +++ b/.okf/codebase/internal/skillscript/index.md @@ -0,0 +1,4 @@ +# Module + +* [yaegi.go](yaegi.md) - Source module internal/skillscript/yaegi.go (53 lines). +* [yaegi_test.go](yaegi_test.md) - Source module internal/skillscript/yaegi_test.go (92 lines). diff --git a/.okf/codebase/internal/skillscript/yaegi.md b/.okf/codebase/internal/skillscript/yaegi.md new file mode 100644 index 000000000..33bc8a926 --- /dev/null +++ b/.okf/codebase/internal/skillscript/yaegi.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/skillscript/yaegi.go (53 lines). +resource: internal/skillscript/yaegi.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: yaegi.go +type: Module +--- + +# Module yaegi.go + +**Path**: `internal/skillscript/yaegi.go` +**Lines**: 53 + +## Snippet Preview + +``` +// Package skillscript runs skill-bundled Go scripts (.agents/skills//scripts/*.go) +// via Yaegi. Unlike the gate and workflow-stage extension surfaces, these +// scripts only need the Go standard library — they wrap external tools +// (gitleaks, trivy, ...) the way a shell script would — so no +// archie-core-specific symbol table is required here. +package skillscript + +import ( + "bytes" + "fmt" + "os" + + "github.com/traefik/yaegi/interp" + "github.com/traefik/yaegi/stdlib" + "github.com/traefik/yaegi/stdlib/unrestricted" +) + +// Run interprets the Go script at path and executes its main function, +// returning everything it wrote to stdout and stderr. The script runs +// in-process (interpreted, not sandboxed) with unrestricted symbols +// (os/exec included — these scripts wrap external tools the way a shell +// script would), so a panic inside it is recovered and returned as an +// error rather than taking down the daemon. +func Run(path string) (output string, err error) { + if _, statErr := os.Stat(path); statErr != nil { + return "", statErr + } + + defer func() { + if r := recover(); r != nil { +``` diff --git a/.okf/codebase/internal/skillscript/yaegi_test.md b/.okf/codebase/internal/skillscript/yaegi_test.md new file mode 100644 index 000000000..9ded6de72 --- /dev/null +++ b/.okf/codebase/internal/skillscript/yaegi_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/skillscript/yaegi_test.go (92 lines). +resource: internal/skillscript/yaegi_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: yaegi_test.go +type: Module +--- + +# Module yaegi_test.go + +**Path**: `internal/skillscript/yaegi_test.go` +**Lines**: 92 + +## Snippet Preview + +``` +package skillscript + +import ( + "os" + "path/filepath" + "testing" +) + +func writeScript(t *testing.T, src string) string { + t.Helper() + dir := t.TempDir() + path := filepath.Join(dir, "script.go") + if err := os.WriteFile(path, []byte(src), 0o644); err != nil { + t.Fatal(err) + } + return path +} + +func TestRunCapturesStdout(t *testing.T) { + path := writeScript(t, `package main + +import "fmt" + +func main() { + fmt.Println("hello from a skill script") +} +`) + out, err := Run(path) + if err != nil { + t.Fatalf("Run() error = %v", err) +``` diff --git a/.okf/codebase/internal/storage/index.md b/.okf/codebase/internal/storage/index.md new file mode 100644 index 000000000..58583ee3e --- /dev/null +++ b/.okf/codebase/internal/storage/index.md @@ -0,0 +1,4 @@ +# Module + +* [storage.go](storage.md) - Source module internal/storage/storage.go (216 lines). +* [storage_test.go](storage_test.md) - Source module internal/storage/storage_test.go (389 lines). diff --git a/.okf/codebase/internal/storage/storage.md b/.okf/codebase/internal/storage/storage.md new file mode 100644 index 000000000..743b9299b --- /dev/null +++ b/.okf/codebase/internal/storage/storage.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/storage/storage.go (216 lines). +resource: internal/storage/storage.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: storage.go +type: Module +--- + +# Module storage.go + +**Path**: `internal/storage/storage.go` +**Lines**: 216 + +## Snippet Preview + +``` +// Package storage defines the pluggable storage backend interface for agent +// container execution. The Docker backend (DockerBackend) is the MVP +// implementation — no NFS/SMB/S3 yet, just Docker volumes + bind mounts. +// +// /data/ volume layout: +// +// /data/ +// task.json — boot-time brief (written by container.WriteTaskJSON) +// worktree/ — bind mount of host worktree +// cache/ +// go/ — GOMODCACHE (shared across all tasks) +// node/ — npm cache (shared) +// pnpm/ — pnpm store (shared) +// pip/ — pip cache (shared) +// cargo/ — Rust cargo cache (shared) +// plugins/ — skill plugins staged from worktree +// +// Cache volumes are named Docker volumes created once and shared across all +// tasks. They are never deleted — the daemon operator manages them. +package storage + +import ( + "context" + "fmt" + "sort" + + "github.com/moby/moby/api/types/mount" + "github.com/moby/moby/client" +) + +``` diff --git a/.okf/codebase/internal/storage/storage_test.md b/.okf/codebase/internal/storage/storage_test.md new file mode 100644 index 000000000..9d61a7f1f --- /dev/null +++ b/.okf/codebase/internal/storage/storage_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/storage/storage_test.go (389 lines). +resource: internal/storage/storage_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: storage_test.go +type: Module +--- + +# Module storage_test.go + +**Path**: `internal/storage/storage_test.go` +**Lines**: 389 + +## Snippet Preview + +``` +package storage + +import ( + "context" + "os" + "sort" + "testing" +) + +// ── interface contract ─────────────────────────────────────────────── + +func TestBackendInterfaceIsSatisfied(t *testing.T) { + // Compile-time check that DockerBackend satisfies Backend. + var _ Backend = (*DockerBackend)(nil) +} + +func TestTaskRefFields(t *testing.T) { + ref := TaskRef{ + Owner: "alice", + Repo: "demo", + IssueNumber: 42, + Ecosystem: "go", + WorktreeDir: "/tmp/worktree", + } + if ref.Owner != "alice" || ref.Repo != "demo" || ref.IssueNumber != 42 { + t.Fatal("TaskRef fields not assignable") + } +} + +func TestMountStruct(t *testing.T) { +``` diff --git a/.okf/codebase/internal/store/events.md b/.okf/codebase/internal/store/events.md new file mode 100644 index 000000000..f7a8ce295 --- /dev/null +++ b/.okf/codebase/internal/store/events.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/store/events.go (243 lines). +resource: internal/store/events.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: events.go +type: Module +--- + +# Module events.go + +**Path**: `internal/store/events.go` +**Lines**: 243 + +## Snippet Preview + +``` +package store + +import ( + "context" + "database/sql" + "encoding/json" + "errors" + "fmt" + "time" + + "github.com/samcharles93/archie-core/internal/events" +) + +const eventsSchema = ` +CREATE TABLE IF NOT EXISTS events ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + at TEXT NOT NULL, + kind TEXT NOT NULL, + task_id INTEGER NOT NULL DEFAULT 0, + repo TEXT NOT NULL DEFAULT '', + issue INTEGER NOT NULL DEFAULT 0, + workflow TEXT NOT NULL DEFAULT '', + stage TEXT NOT NULL DEFAULT '', + detail TEXT NOT NULL DEFAULT '', + data TEXT NOT NULL DEFAULT '{}' +); +CREATE INDEX IF NOT EXISTS idx_events_task ON events(task_id, id); +CREATE INDEX IF NOT EXISTS idx_events_kind ON events(kind, id); +` + +``` diff --git a/.okf/codebase/internal/store/index.md b/.okf/codebase/internal/store/index.md new file mode 100644 index 000000000..c85d48dc1 --- /dev/null +++ b/.okf/codebase/internal/store/index.md @@ -0,0 +1,6 @@ +# Module + +* [events.go](events.md) - Source module internal/store/events.go (243 lines). +* [queries_test.go](queries_test.md) - Source module internal/store/queries_test.go (224 lines). +* [store.go](store.md) - Source module internal/store/store.go (286 lines). +* [store_test.go](store_test.md) - Source module internal/store/store_test.go (114 lines). diff --git a/.okf/codebase/internal/store/queries_test.md b/.okf/codebase/internal/store/queries_test.md new file mode 100644 index 000000000..777c2ab1c --- /dev/null +++ b/.okf/codebase/internal/store/queries_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/store/queries_test.go (224 lines). +resource: internal/store/queries_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: queries_test.go +type: Module +--- + +# Module queries_test.go + +**Path**: `internal/store/queries_test.go` +**Lines**: 224 + +## Snippet Preview + +``` +package store + +import ( + "context" + "testing" + "time" + + "github.com/samcharles93/archie-core/internal/events" +) + +func TestTaskByIssue(t *testing.T) { + s := openTest(t) + ctx := context.Background() + + if got, err := s.TaskByIssue(ctx, "sam", "archie", 1); err != nil || got != nil { + t.Fatalf("TaskByIssue on empty store = (%+v, %v)", got, err) + } + + if _, err := s.EnqueueIssue(ctx, "sam", "archie", 1, "title", "body", "bug"); err != nil { + t.Fatal(err) + } + got, err := s.TaskByIssue(ctx, "sam", "archie", 1) + if err != nil || got == nil { + t.Fatalf("TaskByIssue = (%+v, %v)", got, err) + } + if got.Title != "title" || got.IssueNumber != 1 { + t.Fatalf("TaskByIssue = %+v", got) + } + + if got, err := s.TaskByIssue(ctx, "sam", "archie", 2); err != nil || got != nil { +``` diff --git a/.okf/codebase/internal/store/store.md b/.okf/codebase/internal/store/store.md new file mode 100644 index 000000000..33ef5d4f5 --- /dev/null +++ b/.okf/codebase/internal/store/store.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/store/store.go (286 lines). +resource: internal/store/store.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: store.go +type: Module +--- + +# Module store.go + +**Path**: `internal/store/store.go` +**Lines**: 286 + +## Snippet Preview + +``` +// Package store is archied's SQLite state: one row per task (a GitHub +// issue picked up for work), with every lifecycle transition recorded. +package store + +import ( + "context" + "database/sql" + "errors" + "fmt" + "os" + "path/filepath" + "strings" + + _ "modernc.org/sqlite" +) + +// Task lifecycle statuses. Workflows move tasks between them; the +// daemon owns queued→running claims and crash recovery. +const ( + StatusQueued = "queued" + StatusRunning = "running" + StatusWaitingHuman = "waiting_human" + StatusPROpen = "pr_open" + StatusMerged = "merged" + StatusParked = "parked" + StatusRejected = "rejected" + StatusClosedWontDo = "closed_wont_do" +) + +type Task struct { +``` diff --git a/.okf/codebase/internal/store/store_test.md b/.okf/codebase/internal/store/store_test.md new file mode 100644 index 000000000..7157184fb --- /dev/null +++ b/.okf/codebase/internal/store/store_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/store/store_test.go (114 lines). +resource: internal/store/store_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: store_test.go +type: Module +--- + +# Module store_test.go + +**Path**: `internal/store/store_test.go` +**Lines**: 114 + +## Snippet Preview + +``` +package store + +import ( + "context" + "path/filepath" + "testing" + + "github.com/samcharles93/archie-core/internal/events" +) + +func openTest(t *testing.T) *Store { + t.Helper() + s, err := Open(filepath.Join(t.TempDir(), "test.db")) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { + if err := s.Close(); err != nil { + t.Errorf("close store: %v", err) + } + }) + return s +} + +func TestEnqueueIsIdempotent(t *testing.T) { + s := openTest(t) + ctx := context.Background() + + ins, err := s.EnqueueIssue(ctx, "sam", "todo", 1, "add tests", "body", "archie") + if err != nil || !ins { +``` diff --git a/.okf/codebase/internal/webui/index.md b/.okf/codebase/internal/webui/index.md new file mode 100644 index 000000000..717836fa3 --- /dev/null +++ b/.okf/codebase/internal/webui/index.md @@ -0,0 +1,4 @@ +# Module + +* [webui.go](webui.md) - Source module internal/webui/webui.go (177 lines). +* [webui_test.go](webui_test.md) - Source module internal/webui/webui_test.go (180 lines). diff --git a/.okf/codebase/internal/webui/webui.md b/.okf/codebase/internal/webui/webui.md new file mode 100644 index 000000000..a6b539b48 --- /dev/null +++ b/.okf/codebase/internal/webui/webui.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/webui/webui.go (177 lines). +resource: internal/webui/webui.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: webui.go +type: Module +--- + +# Module webui.go + +**Path**: `internal/webui/webui.go` +**Lines**: 177 + +## Snippet Preview + +``` +// Package webui is archied's observability dashboard: task board, +// per-task timelines, workflow/stage metrics, and a live event tail +// over SSE. Read-only — the daemon is steered through GitHub, not here. +// Bind it to localhost or a tailnet address; it has no auth. +package webui + +import ( + "context" + _ "embed" + "encoding/json" + "log/slog" + "net/http" + "strconv" + "sync" + "time" + + "github.com/samcharles93/archie-core/internal/events" + "github.com/samcharles93/archie-core/internal/store" +) + +//go:embed index.html +var indexHTML []byte + +type Server struct { + Store *store.Store + Log *slog.Logger + + mu sync.Mutex + conns map[chan events.Event]struct{} +} +``` diff --git a/.okf/codebase/internal/webui/webui_test.md b/.okf/codebase/internal/webui/webui_test.md new file mode 100644 index 000000000..a46aaf4d5 --- /dev/null +++ b/.okf/codebase/internal/webui/webui_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/webui/webui_test.go (180 lines). +resource: internal/webui/webui_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: webui_test.go +type: Module +--- + +# Module webui_test.go + +**Path**: `internal/webui/webui_test.go` +**Lines**: 180 + +## Snippet Preview + +``` +package webui + +import ( + "bufio" + "encoding/json" + "io" + "log/slog" + "net/http" + "net/http/httptest" + "path/filepath" + "strconv" + "strings" + "testing" + "time" + + "github.com/samcharles93/archie-core/internal/events" + "github.com/samcharles93/archie-core/internal/store" +) + +func newTestServer(t *testing.T) *Server { + t.Helper() + s, err := store.Open(filepath.Join(t.TempDir(), "test.db")) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = s.Close() }) + return &Server{Store: s, Log: slog.New(slog.NewTextHandler(io.Discard, nil))} +} + +func TestHandleSummary(t *testing.T) { +``` diff --git a/.okf/codebase/internal/workflow/agent.md b/.okf/codebase/internal/workflow/agent.md new file mode 100644 index 000000000..3ded7eff8 --- /dev/null +++ b/.okf/codebase/internal/workflow/agent.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/workflow/agent.go (221 lines). +resource: internal/workflow/agent.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: agent.go +type: Module +--- + +# Module agent.go + +**Path**: `internal/workflow/agent.go` +**Lines**: 221 + +## Snippet Preview + +``` +package workflow + +import ( + "context" + "fmt" + + "github.com/samcharles93/archie-core/internal/agentexec" + "github.com/samcharles93/archie-core/internal/config" + "github.com/samcharles93/archie-core/internal/skill" +) + +// AgentStage is the reusable bridge from a workflow stage to an +// agentloop run. Every LLM-driven stage in any workflow (implement's +// planner/builder, tdd's test-writer/fixer, feasibility's analyst) +// is an AgentStage with a different mission, gate, and result handler — +// never a new engine. +type AgentStage struct { + Name string + // Role selects the model via cfg.Models[Role]; falls back to + // cfg.Models["builder"]. + Role string + ReadOnly bool + // Mission produces the task statement from the current context. + Mission func(*TaskContext) string + // Gate returns the stage's quality gate; nil means ungated (e.g. + // read-only analysis stages). + Gate func(*TaskContext) agentexec.Gate + // ExtraRules is appended to the system prompt. + ExtraRules string + // MaxSteps overrides the configured step budget when > 0 (planner +``` diff --git a/.okf/codebase/internal/workflow/agent_test.md b/.okf/codebase/internal/workflow/agent_test.md new file mode 100644 index 000000000..f8f14d0c4 --- /dev/null +++ b/.okf/codebase/internal/workflow/agent_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/workflow/agent_test.go (276 lines). +resource: internal/workflow/agent_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: agent_test.go +type: Module +--- + +# Module agent_test.go + +**Path**: `internal/workflow/agent_test.go` +**Lines**: 276 + +## Snippet Preview + +``` +package workflow + +import ( + "context" + "encoding/json" + "errors" + "log/slog" + "path/filepath" + "reflect" + "testing" + + "github.com/samcharles93/archie-core/internal/agentexec" + "github.com/samcharles93/archie-core/internal/config" + "github.com/samcharles93/archie-core/internal/store" +) + +type fakeAgentRunner struct { + workspace string + request agentexec.Request + result agentexec.Result + err error +} + +type agentRunnerFunc func(context.Context, string, agentexec.Request) (agentexec.Result, error) + +func (f agentRunnerFunc) Run(ctx context.Context, workspace string, req agentexec.Request) (agentexec.Result, error) { + return f(ctx, workspace, req) +} + +func (r *fakeAgentRunner) Run(_ context.Context, workspace string, req agentexec.Request) (agentexec.Result, error) { +``` diff --git a/.okf/codebase/internal/workflow/feasibility.md b/.okf/codebase/internal/workflow/feasibility.md new file mode 100644 index 000000000..1576f783e --- /dev/null +++ b/.okf/codebase/internal/workflow/feasibility.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/workflow/feasibility.go (168 lines). +resource: internal/workflow/feasibility.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: feasibility.go +type: Module +--- + +# Module feasibility.go + +**Path**: `internal/workflow/feasibility.go` +**Lines**: 168 + +## Snippet Preview + +``` +package workflow + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "net/http" + "time" + + "github.com/samcharles93/archie-core/internal/agentexec" + "github.com/samcharles93/archie-core/internal/store" +) + +// Feasibility is the feature-request workflow: assess the request +// against the project's direction, close it with reasons when it +// doesn't fit, otherwise produce a PRD, deliver it to Sam (issue +// comment + notify webhook), and hand the task to waiting_human. The +// daemon watches for Sam's reply and — LLM-judged, not keyword-matched — +// requeues approved features under the implement workflow or closes +// rejected ones. Routed via the "feature" label. +func Feasibility() Workflow { + return Workflow{ + Name: "feasibility", + Stages: []Stage{ + StagePrepareWorktree(), // read-only stages still need the checkout + + AgentStage{ + Name: "assess", + Role: "planner", +``` diff --git a/.okf/codebase/internal/workflow/implement.md b/.okf/codebase/internal/workflow/implement.md new file mode 100644 index 000000000..f2b15cd43 --- /dev/null +++ b/.okf/codebase/internal/workflow/implement.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/workflow/implement.go (111 lines). +resource: internal/workflow/implement.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: implement.go +type: Module +--- + +# Module implement.go + +**Path**: `internal/workflow/implement.go` +**Lines**: 111 + +## Snippet Preview + +``` +package workflow + +import ( + "context" + "fmt" + "os/exec" + "strings" + + "github.com/samcharles93/archie-core/internal/agentexec" +) + +// StageBaselineGate verifies the repo's gate is green at the base commit +// before any planning starts — a red baseline would park-storm the +// builder with failures it didn't cause. +func StageBaselineGate() Stage { + return Stage{Name: "baseline", Run: func(ctx context.Context, tc *TaskContext) error { + for _, argv := range tc.Repo.Gate { + if len(argv) == 0 { + continue + } + cmd := exec.CommandContext(ctx, argv[0], argv[1:]...) + cmd.Dir = tc.Dir + if out, err := cmd.CombinedOutput(); err != nil { + return fmt.Errorf("baseline red — %s fails at %s before archie touched anything:\n%s", + strings.Join(argv, " "), tc.Repo.BaseBranch(), clip(string(out), 2000)) + } + } + return nil + }} +} +``` diff --git a/.okf/codebase/internal/workflow/index.md b/.okf/codebase/internal/workflow/index.md new file mode 100644 index 000000000..27d7b53cb --- /dev/null +++ b/.okf/codebase/internal/workflow/index.md @@ -0,0 +1,18 @@ +# Module + +* [agent.go](agent.md) - Source module internal/workflow/agent.go (221 lines). +* [agent_test.go](agent_test.md) - Source module internal/workflow/agent_test.go (276 lines). +* [feasibility.go](feasibility.md) - Source module internal/workflow/feasibility.go (168 lines). +* [implement.go](implement.md) - Source module internal/workflow/implement.go (111 lines). +* [plugin_test.go](plugin_test.md) - Source module internal/workflow/plugin_test.go (106 lines). +* [steps.go](steps.md) - Source module internal/workflow/steps.go (203 lines). +* [steps_test.go](steps_test.md) - Source module internal/workflow/steps_test.go (201 lines). +* [tdd.go](tdd.md) - Source module internal/workflow/tdd.go (195 lines). +* [tdd_test.go](tdd_test.md) - Source module internal/workflow/tdd_test.go (47 lines). +* [workflow.go](workflow.md) - Source module internal/workflow/workflow.go (244 lines). + +# Subdirectories + +* [skillbuild](skillbuild/index.md) - Directory containing 2 items, including: skillbuild.go. +* [wfeval](wfeval/index.md) - Directory containing 2 items, including: yaegi.go. +* [wfextract](wfextract/index.md) - Directory containing 2 items, including: github_com-samcharles93-archie-core-internal-workflow.go. diff --git a/.okf/codebase/internal/workflow/plugin_test.md b/.okf/codebase/internal/workflow/plugin_test.md new file mode 100644 index 000000000..019651777 --- /dev/null +++ b/.okf/codebase/internal/workflow/plugin_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/workflow/plugin_test.go (106 lines). +resource: internal/workflow/plugin_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: plugin_test.go +type: Module +--- + +# Module plugin_test.go + +**Path**: `internal/workflow/plugin_test.go` +**Lines**: 106 + +## Snippet Preview + +``` +package workflow + +import ( + "log/slog" + "os" + "path/filepath" + "testing" + + "github.com/samcharles93/archie-core/internal/agentexec" + "github.com/samcharles93/archie-core/internal/config" + "github.com/samcharles93/archie-core/internal/store" +) + +// ── regression: Gap 7 — plugins discovered but not executed ───────── + +func TestSkillPluginsAvailableDuringStageExecution(t *testing.T) { + // Gap 7: skill.Discover() populates Skill.Plugins but nothing calls + // plugin.Run() during stage execution. Plugins must be loaded from + // the skill directory alongside the SKILL.md body and made available + // to the agent as tools during stage runs. + // + // This test creates a worktree with a skill that has a bundled plugin. + // It runs an AgentStage and verifies the plugin was loaded and is + // accessible via the TaskContext. + + dir := t.TempDir() + skillsDir := filepath.Join(dir, ".agents", "skills", "archie-wf-tdd") + pluginsDir := filepath.Join(skillsDir, "plugins") + if err := os.MkdirAll(pluginsDir, 0o755); err != nil { + t.Fatal(err) +``` diff --git a/.okf/codebase/internal/workflow/skillbuild/index.md b/.okf/codebase/internal/workflow/skillbuild/index.md new file mode 100644 index 000000000..d5c0316ae --- /dev/null +++ b/.okf/codebase/internal/workflow/skillbuild/index.md @@ -0,0 +1,4 @@ +# Module + +* [skillbuild.go](skillbuild.md) - Source module internal/workflow/skillbuild/skillbuild.go (184 lines). +* [skillbuild_test.go](skillbuild_test.md) - Source module internal/workflow/skillbuild/skillbuild_test.go (741 lines). diff --git a/.okf/codebase/internal/workflow/skillbuild/skillbuild.md b/.okf/codebase/internal/workflow/skillbuild/skillbuild.md new file mode 100644 index 000000000..edc5d82f3 --- /dev/null +++ b/.okf/codebase/internal/workflow/skillbuild/skillbuild.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/workflow/skillbuild/skillbuild.go (184 lines). +resource: internal/workflow/skillbuild/skillbuild.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: skillbuild.go +type: Module +--- + +# Module skillbuild.go + +**Path**: `internal/workflow/skillbuild/skillbuild.go` +**Lines**: 184 + +## Snippet Preview + +``` +// Package skillbuild constructs Workflows from skill catalog entries by +// loading Yaegi-interpreted stage plugins from the skill's plugins/ directory. +package skillbuild + +import ( + "context" + "fmt" + "os" + "path/filepath" + "sort" + "strings" + + "github.com/traefik/yaegi/interp" + "github.com/traefik/yaegi/stdlib" + + "github.com/samcharles93/archie-core/internal/skill" + "github.com/samcharles93/archie-core/internal/workflow" + "github.com/samcharles93/archie-core/internal/workflow/wfextract" +) + +// builtins returns the hardcoded fallback workflows. These are used when +// no skill declares a given workflow name in its metadata.archie.workflow. +func builtins() workflow.Registry { + return workflow.Registry{ + "bootstrap": workflow.Bootstrap(), + "implement": workflow.Implement(), + "tdd": workflow.TDD(), + "feasibility": workflow.Feasibility(), + "default": workflow.Implement(), + } +``` diff --git a/.okf/codebase/internal/workflow/skillbuild/skillbuild_test.md b/.okf/codebase/internal/workflow/skillbuild/skillbuild_test.md new file mode 100644 index 000000000..42af41a02 --- /dev/null +++ b/.okf/codebase/internal/workflow/skillbuild/skillbuild_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/workflow/skillbuild/skillbuild_test.go (741 lines). +resource: internal/workflow/skillbuild/skillbuild_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: skillbuild_test.go +type: Module +--- + +# Module skillbuild_test.go + +**Path**: `internal/workflow/skillbuild/skillbuild_test.go` +**Lines**: 741 + +## Snippet Preview + +``` +package skillbuild + +import ( + "context" + "os" + "path/filepath" + "testing" + + "github.com/samcharles93/archie-core/internal/workflow" +) + +// ── workflows built from skill plugins ──────────────────────────────── + +func TestBuildWorkflowFromSkillPlugins(t *testing.T) { + dir := t.TempDir() + skillDir := filepath.Join(dir, ".agents", "skills", "archie-wf-greet") + pluginsDir := filepath.Join(skillDir, "plugins") + if err := os.MkdirAll(pluginsDir, 0o755); err != nil { + t.Fatal(err) + } + + if err := os.WriteFile(filepath.Join(skillDir, "SKILL.md"), []byte(`--- +name: archie-wf-greet +description: A custom greeting workflow built entirely from plugins. +version: 1.0.0 +metadata: + archie: + workflow: greet +--- +Greet the world, then say goodbye. +``` diff --git a/.okf/codebase/internal/workflow/steps.md b/.okf/codebase/internal/workflow/steps.md new file mode 100644 index 000000000..285febe27 --- /dev/null +++ b/.okf/codebase/internal/workflow/steps.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/workflow/steps.go (203 lines). +resource: internal/workflow/steps.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: steps.go +type: Module +--- + +# Module steps.go + +**Path**: `internal/workflow/steps.go` +**Lines**: 203 + +## Snippet Preview + +``` +package workflow + +import ( + "context" + "fmt" + "os" + "path/filepath" + "strings" + "time" + + "github.com/samcharles93/archie-core/internal/gate" + "github.com/samcharles93/archie-core/internal/gate/gateeval" + "github.com/samcharles93/archie-core/internal/store" +) + +// Shared step library. Every workflow composes these; workflow-specific +// stages live next to their workflow definition. + +// StagePrepareWorktree clones the repo fresh and checks out the task +// branch. +func StagePrepareWorktree() Stage { + return Stage{Name: "prepare", Run: func(ctx context.Context, tc *TaskContext) error { + dir, branch, err := tc.Trees.Prepare(ctx, tc.Task.Owner, tc.Task.Repo, tc.Repo.BaseBranch(), tc.Task.IssueNumber) + if err != nil { + return err + } + tc.Dir, tc.Branch = dir, branch + tc.Task.Branch = branch + return nil + }} +``` diff --git a/.okf/codebase/internal/workflow/steps_test.md b/.okf/codebase/internal/workflow/steps_test.md new file mode 100644 index 000000000..edd7e7e5a --- /dev/null +++ b/.okf/codebase/internal/workflow/steps_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/workflow/steps_test.go (201 lines). +resource: internal/workflow/steps_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: steps_test.go +type: Module +--- + +# Module steps_test.go + +**Path**: `internal/workflow/steps_test.go` +**Lines**: 201 + +## Snippet Preview + +``` +package workflow + +import ( + "context" + "errors" + "log/slog" + "os" + "os/exec" + "path/filepath" + "testing" + + "github.com/samcharles93/archie-core/internal/config" + "github.com/samcharles93/archie-core/internal/store" + "github.com/samcharles93/archie-core/internal/worktree" +) + +// runGit runs git in dir, failing the test on error. +func runGit(t *testing.T, dir string, args ...string) { + t.Helper() + cmd := exec.Command("git", args...) + cmd.Dir = dir + cmd.Env = append(os.Environ(), "GIT_TERMINAL_PROMPT=0") + if out, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("git %v: %v\n%s", args, err, out) + } +} + +// gitRepoWithOriginRef creates a repo with a base commit, then labels +// that commit "origin/" (a plain local branch standing in for a +// remote-tracking ref) so Manager.Diff/ChangedFiles — which always diff +``` diff --git a/.okf/codebase/internal/workflow/tdd.md b/.okf/codebase/internal/workflow/tdd.md new file mode 100644 index 000000000..051718db3 --- /dev/null +++ b/.okf/codebase/internal/workflow/tdd.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/workflow/tdd.go (195 lines). +resource: internal/workflow/tdd.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: tdd.go +type: Module +--- + +# Module tdd.go + +**Path**: `internal/workflow/tdd.go` +**Lines**: 195 + +## Snippet Preview + +``` +package workflow + +import ( + "context" + "fmt" + "os/exec" + "strings" + + "github.com/samcharles93/archie-core/internal/agentexec" + "github.com/samcharles93/archie-core/internal/config" +) + +// TDD is the bugfix workflow: prove the bug with failing tests before +// fixing it. The repro stage's gate INVERTS the test command +// (ExpectFailure) — the run cannot proceed until the new tests fail for +// the right reason — and the fix stage restores the repo's full gate. +// Routed via the "bug" label. +func TDD() Workflow { + return Workflow{ + Name: "tdd", + Stages: []Stage{ + StagePrepareWorktree(), + StageRepoStages(), + StageBaselineGate(), + + AgentStage{ + Name: "analyse", + Role: "planner", + ReadOnly: true, + MaxSteps: 15, +``` diff --git a/.okf/codebase/internal/workflow/tdd_test.md b/.okf/codebase/internal/workflow/tdd_test.md new file mode 100644 index 000000000..67b7c0c0a --- /dev/null +++ b/.okf/codebase/internal/workflow/tdd_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/workflow/tdd_test.go (47 lines). +resource: internal/workflow/tdd_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: tdd_test.go +type: Module +--- + +# Module tdd_test.go + +**Path**: `internal/workflow/tdd_test.go` +**Lines**: 47 + +## Snippet Preview + +``` +package workflow + +import ( + "reflect" + "testing" + + "github.com/samcharles93/archie-core/internal/config" +) + +func TestTDDGateUsesLastNonEmptyCommand(t *testing.T) { + repo := config.Repo{Gate: [][]string{ + {"go", "vet", "./..."}, + {"go", "test", "./..."}, + {}, + }} + + gate := tddReproGate(repo, config.Budgets{GateMaxFailures: 3}) + if len(gate.Commands) != 2 { + t.Fatalf("gate has %d commands, want 2", len(gate.Commands)) + } + if gate.Commands[0].ExpectFailure { + t.Error("first gate command unexpectedly requires failure") + } + if !gate.Commands[1].ExpectFailure { + t.Error("last non-empty gate command does not require failure") + } + if got, want := testCommandArgv(repo), []string{"go", "test", "./..."}; !reflect.DeepEqual(got, want) { + t.Errorf("testCommandArgv() = %v, want %v", got, want) + } + if got, want := testCommand(repo), "go test ./..."; got != want { +``` diff --git a/.okf/codebase/internal/workflow/wfeval/index.md b/.okf/codebase/internal/workflow/wfeval/index.md new file mode 100644 index 000000000..0317e1e37 --- /dev/null +++ b/.okf/codebase/internal/workflow/wfeval/index.md @@ -0,0 +1,4 @@ +# Module + +* [yaegi.go](yaegi.md) - Source module internal/workflow/wfeval/yaegi.go (95 lines). +* [yaegi_test.go](yaegi_test.md) - Source module internal/workflow/wfeval/yaegi_test.go (139 lines). diff --git a/.okf/codebase/internal/workflow/wfeval/yaegi.md b/.okf/codebase/internal/workflow/wfeval/yaegi.md new file mode 100644 index 000000000..932a62f64 --- /dev/null +++ b/.okf/codebase/internal/workflow/wfeval/yaegi.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/workflow/wfeval/yaegi.go (95 lines). +resource: internal/workflow/wfeval/yaegi.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: yaegi.go +type: Module +--- + +# Module yaegi.go + +**Path**: `internal/workflow/wfeval/yaegi.go` +**Lines**: 95 + +## Snippet Preview + +``` +// Package wfeval discovers and interprets a repo's custom workflow +// stages: .archie/stages/*.go files, each exporting a Stage() function +// that returns a workflow.Stage. Split from internal/workflow (and its +// generated symbol table in wfextract) to avoid the import cycle that +// would result from workflow depending on its own extracted symbols. +package wfeval + +import ( + "fmt" + "os" + "path/filepath" + "sort" + + "github.com/traefik/yaegi/interp" + "github.com/traefik/yaegi/stdlib" + + "github.com/samcharles93/archie-core/internal/workflow" + "github.com/samcharles93/archie-core/internal/workflow/wfextract" +) + +// stagesDir is where a repo's custom stage scripts live, relative to +// the worktree root. +const stagesDir = ".archie/stages" + +// Discover loads every .archie/stages/*.go file in dir and returns the +// workflow.Stage each exports, in filename order. A missing directory is +// not an error — it returns (nil, nil), meaning no custom stages are +// configured for this repo. +func Discover(dir string) ([]workflow.Stage, error) { + entries, err := os.ReadDir(filepath.Join(dir, stagesDir)) +``` diff --git a/.okf/codebase/internal/workflow/wfeval/yaegi_test.md b/.okf/codebase/internal/workflow/wfeval/yaegi_test.md new file mode 100644 index 000000000..b6ba741c4 --- /dev/null +++ b/.okf/codebase/internal/workflow/wfeval/yaegi_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/workflow/wfeval/yaegi_test.go (139 lines). +resource: internal/workflow/wfeval/yaegi_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: yaegi_test.go +type: Module +--- + +# Module yaegi_test.go + +**Path**: `internal/workflow/wfeval/yaegi_test.go` +**Lines**: 139 + +## Snippet Preview + +``` +package wfeval + +import ( + "context" + "os" + "path/filepath" + "testing" + + "github.com/samcharles93/archie-core/internal/workflow" +) + +func writeStageScript(t *testing.T, dir, name, src string) { + t.Helper() + stagesDir := filepath.Join(dir, ".archie", "stages") + if err := os.MkdirAll(stagesDir, 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(stagesDir, name), []byte(src), 0o644); err != nil { + t.Fatal(err) + } +} + +func TestDiscoverNoStagesDir(t *testing.T) { + stages, err := Discover(t.TempDir()) + if err != nil { + t.Fatalf("Discover() error = %v, want nil (no .archie/stages)", err) + } + if stages != nil { + t.Fatalf("Discover() = %v, want nil", stages) + } +``` diff --git a/.okf/codebase/internal/workflow/wfextract/github_com-samcharles93-archie-core-internal-workflow.md b/.okf/codebase/internal/workflow/wfextract/github_com-samcharles93-archie-core-internal-workflow.md new file mode 100644 index 000000000..2d770272c --- /dev/null +++ b/.okf/codebase/internal/workflow/wfextract/github_com-samcharles93-archie-core-internal-workflow.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/workflow/wfextract/github_com-samcharles93-archie-core-internal-workflow.go (38 lines). +resource: internal/workflow/wfextract/github_com-samcharles93-archie-core-internal-workflow.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: github_com-samcharles93-archie-core-internal-workflow.go +type: Module +--- + +# Module github_com-samcharles93-archie-core-internal-workflow.go + +**Path**: `internal/workflow/wfextract/github_com-samcharles93-archie-core-internal-workflow.go` +**Lines**: 38 + +## Snippet Preview + +``` +// Code generated by 'yaegi extract github.com/samcharles93/archie-core/internal/workflow'. DO NOT EDIT. + +package wfextract + +import ( + "github.com/samcharles93/archie-core/internal/workflow" + "reflect" +) + +func init() { + Symbols["github.com/samcharles93/archie-core/internal/workflow/workflow"] = map[string]reflect.Value{ + // function, constant and variable definitions + "Bootstrap": reflect.ValueOf(workflow.Bootstrap), + "Feasibility": reflect.ValueOf(workflow.Feasibility), + "GateFromRepo": reflect.ValueOf(workflow.GateFromRepo), + "Implement": reflect.ValueOf(workflow.Implement), + "OpenPR": reflect.ValueOf(workflow.OpenPR), + "Route": reflect.ValueOf(workflow.Route), + "Run": reflect.ValueOf(workflow.Run), + "StageBaselineGate": reflect.ValueOf(workflow.StageBaselineGate), + "StageCommit": reflect.ValueOf(workflow.StageCommit), + "StageCommitPush": reflect.ValueOf(workflow.StageCommitPush), + "StageDiffCap": reflect.ValueOf(workflow.StageDiffCap), + "StageOpenPR": reflect.ValueOf(workflow.StageOpenPR), + "StagePrepareWorktree": reflect.ValueOf(workflow.StagePrepareWorktree), + "StageRepoStages": reflect.ValueOf(workflow.StageRepoStages), + "StageYaegiGate": reflect.ValueOf(workflow.StageYaegiGate), + "TDD": reflect.ValueOf(workflow.TDD), + + // type definitions +``` diff --git a/.okf/codebase/internal/workflow/wfextract/index.md b/.okf/codebase/internal/workflow/wfextract/index.md new file mode 100644 index 000000000..fd7680e3b --- /dev/null +++ b/.okf/codebase/internal/workflow/wfextract/index.md @@ -0,0 +1,4 @@ +# Module + +* [github_com-samcharles93-archie-core-internal-workflow.go](github_com-samcharles93-archie-core-internal-workflow.md) - Source module internal/workflow/wfextract/github_com-samcharles93-archie-core-internal-workflow.go (38 lines). +* [wfextract.go](wfextract.md) - Source module internal/workflow/wfextract/wfextract.go (10 lines). diff --git a/.okf/codebase/internal/workflow/wfextract/wfextract.md b/.okf/codebase/internal/workflow/wfextract/wfextract.md new file mode 100644 index 000000000..9d557e4b6 --- /dev/null +++ b/.okf/codebase/internal/workflow/wfextract/wfextract.md @@ -0,0 +1,30 @@ +--- +description: Source module internal/workflow/wfextract/wfextract.go (10 lines). +resource: internal/workflow/wfextract/wfextract.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: wfextract.go +type: Module +--- + +# Module wfextract.go + +**Path**: `internal/workflow/wfextract/wfextract.go` +**Lines**: 10 + +## Snippet Preview + +``` +// Package wfextract holds the Yaegi symbol table for internal/workflow, +// generated by `go generate`. Kept separate from internal/workflow itself +// so the generated file can import it without a self-import cycle. +package wfextract + +import "reflect" + +//go:generate go run github.com/traefik/yaegi/cmd/yaegi extract -name wfextract github.com/samcharles93/archie-core/internal/workflow + +var Symbols = map[string]map[string]reflect.Value{} +``` diff --git a/.okf/codebase/internal/workflow/workflow.md b/.okf/codebase/internal/workflow/workflow.md new file mode 100644 index 000000000..661e067ad --- /dev/null +++ b/.okf/codebase/internal/workflow/workflow.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/workflow/workflow.go (244 lines). +resource: internal/workflow/workflow.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: workflow.go +type: Module +--- + +# Module workflow.go + +**Path**: `internal/workflow/workflow.go` +**Lines**: 244 + +## Snippet Preview + +``` +// Package workflow is archied's extensible pipeline engine. A Workflow +// is an ordered list of stages over a shared TaskContext; stages are +// either deterministic steps (git, gate, PR, comments) or agent stages +// (agentloop runs). New workflows compose from the shared step library — +// adding one must never require reimplementing the engine or the steps. +package workflow + +import ( + "context" + "fmt" + "log/slog" + "strings" + "time" + + "github.com/samcharles93/archie-core/internal/agentexec" + "github.com/samcharles93/archie-core/internal/config" + "github.com/samcharles93/archie-core/internal/events" + "github.com/samcharles93/archie-core/internal/forge" + "github.com/samcharles93/archie-core/internal/skill" + "github.com/samcharles93/archie-core/internal/store" + "github.com/samcharles93/archie-core/internal/worktree" +) + +// TaskContext carries everything a stage may need. Stages communicate +// forward by mutating Task (persisted after every stage) and the +// scratch fields below. +type TaskContext struct { + Task *store.Task + Repo config.Repo + Cfg config.Config +``` diff --git a/.okf/codebase/internal/worktree/index.md b/.okf/codebase/internal/worktree/index.md new file mode 100644 index 000000000..b86634bf6 --- /dev/null +++ b/.okf/codebase/internal/worktree/index.md @@ -0,0 +1,4 @@ +# Module + +* [worktree.go](worktree.md) - Source module internal/worktree/worktree.go (176 lines). +* [worktree_test.go](worktree_test.md) - Source module internal/worktree/worktree_test.go (138 lines). diff --git a/.okf/codebase/internal/worktree/worktree.md b/.okf/codebase/internal/worktree/worktree.md new file mode 100644 index 000000000..8b403dde9 --- /dev/null +++ b/.okf/codebase/internal/worktree/worktree.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/worktree/worktree.go (176 lines). +resource: internal/worktree/worktree.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: worktree.go +type: Module +--- + +# Module worktree.go + +**Path**: `internal/worktree/worktree.go` +**Lines**: 176 + +## Snippet Preview + +``` +// Package worktree owns archied's git operations: fresh clone per task, +// branch, commit as the bot identity, push, diff stats, cleanup. The +// daemon performs these deterministically — the model's shell tool never +// drives git. +package worktree + +import ( + "context" + "fmt" + "os" + "os/exec" + "path/filepath" + "strings" +) + +type Manager struct { + // WorkDir is the root under which task worktrees are created. + WorkDir string + // Token authenticates clone/push over HTTPS via an askpass helper, + // keeping it out of .git/config and process argv. + Token string + BotUser string + BotEmail string + // BaseURL overrides the forge host. Set from config [forge].host. + // Empty falls back to https://github.com. + BaseURL string +} + +// Dir is the worktree path for a task. +func (m *Manager) Dir(owner, repo string, issue int) string { +``` diff --git a/.okf/codebase/internal/worktree/worktree_test.md b/.okf/codebase/internal/worktree/worktree_test.md new file mode 100644 index 000000000..133178283 --- /dev/null +++ b/.okf/codebase/internal/worktree/worktree_test.md @@ -0,0 +1,50 @@ +--- +description: Source module internal/worktree/worktree_test.go (138 lines). +resource: internal/worktree/worktree_test.go +tags: + - go + - source +timestamp: "2026-07-21T18:36:22Z" +title: worktree_test.go +type: Module +--- + +# Module worktree_test.go + +**Path**: `internal/worktree/worktree_test.go` +**Lines**: 138 + +## Snippet Preview + +``` +package worktree + +import ( + "context" + "os" + "os/exec" + "path/filepath" + "strings" + "testing" +) + +// newLocalRemote creates a bare repo with one commit on main and +// returns the directory that serves as the fake forge host: the bare +// repo lives at //.git so cloneURL resolves it via +// file://. +func newLocalRemote(t *testing.T, owner, repo string) string { + t.Helper() + host := t.TempDir() + bare := filepath.Join(host, owner, repo+".git") + seed := filepath.Join(t.TempDir(), "seed") + + run := func(dir string, args ...string) { + t.Helper() + cmd := exec.Command("git", args...) + cmd.Dir = dir + cmd.Env = append(os.Environ(), "GIT_TERMINAL_PROMPT=0") + if out, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("git %v: %v\n%s", args, err, out) + } + } +``` diff --git a/.okf/index.md b/.okf/index.md new file mode 100644 index 000000000..e530e3379 --- /dev/null +++ b/.okf/index.md @@ -0,0 +1,4 @@ +# Subdirectories + +* [architecture](architecture/index.md) - Root architecture and project structure for archie-core. +* [codebase](codebase/index.md) - Directory containing 2 items, including: cmd.