Commit Graph
35 Commits
Author SHA1 Message Date
samcharles93 70afbf7f95 fix: baseline gate repair (go test ./... -count=1) 2026-09-02 03:53:40 +00:00
sam 14d3a9461f feat(workflow): adversarial self-review stage before PR open
Implements archie-core-h019.3 (reviewer isolation) and h019.4 (wiring),
per docs/prds/adversarial-self-review.md.

- internal/domain/workflow: new Reviewer interface and StageReview,
  inserted between StageDiffCap and StageOpenPR in the implement
  workflow. Fail-closed: a review that didn't run, or a confirmed
  error-level finding, parks the task (store.StatusParked) with
  findings in Detail; warn/plausible findings never block. Inert
  unless Repo.ReviewEnabled.
- internal/worktree: Manager.Snapshot exports HEAD's tracked files into
  a fresh directory with no .git, for the reviewer's isolated
  workspace. Trees interface gains Snapshot; hybridTrees delegates to
  it.
- internal/app/agentworker: subagentReviewer implements Reviewer using
  ai-sdk's agent.Subagent (nested, in-process, non-streaming
  generation) -- conversation isolation is structural (Subagent.Run
  never carries message history), workspace isolation is the snapshot
  above. The reviewer's toolset is read-only (read/grep/find) rooted
  at the snapshot, never the worker's own toolset, so it cannot reach
  the worktreerpc publication grant. Findings are captured via a typed
  record_finding tool appending to a slice the stage owns, read even
  when Subagent.Run errors (a truncated run's captured findings
  survive).
- internal/config: Repo.ReviewEnabled (default false) and
  Models["reviewer"] (falls back to Models["builder"], no schema
  change).

Judgment calls: Reviewer.Review never returns a Go error -- every
failure folds into ReviewReport per the PRD's fail-closed contract,
which the stage can act on uniformly. A Subagent.Run error with zero
captured findings resolves to ReviewStatusNotRun (park); a
Subagent.Run error with >=1 captured findings resolves to
ReviewStatusCompleted with those findings, since the PRD's own example
("three defects survive a step-limit truncation") requires them to
still be evaluated for blocking rather than discarded.
2026-08-31 21:51:33 +10:00
sam 2e8fd4d75c refactor(worktree): go fix modernisation of parseTitlePrefix
strings.Index plus slicing becomes strings.Cut. Semantics are unchanged:
Cut splits on the first separator, so before/after equal the previous
title[:idx] and title[idx+1:], and ok mirrors idx != -1.
2026-08-24 18:07:27 +10:00
sam b5fe44cd83 fix(worktree): remove dead body parameter and wire branchPrefix to archieBranch 2026-08-24 18:01:09 +10:00
sam 867ef5f0bf fix(worktree): handle post-push metadata resilience, cancellation, and branch naming
Fix three distinct bugs in worktree operations:
- Push post-publication metadata failure no longer reports a push error after successful ref publication; errors recording upstream tracking are logged as warnings via Manager.Log/slog.Default().
- CommitAll honours context cancellation and deadline expiration before and between go-git staging and committing phases, preventing unintended index or HEAD mutations.
- Align branch naming precedence by deriving conventional commit prefixes from issue titles first before falling back to labels and defaulting to feat; remove dead parameters and TrimSuffix no-op; align branchSlug documentation and boundary limit to 60 characters.
2026-08-24 17:56:18 +10:00
sam 41446c5c96 fix(worktree): clean untracked files when .git is a gitdir file
cleanUntracked returned filepath.SkipDir for the ".git" entry
unconditionally. On a non-directory, SkipDir skips the remaining
entries of the *parent* directory -- at the worktree root that is the
rest of the walk. A repository whose .git is a gitdir pointer file
(a linked worktree, or a clone adopted by migrateLegacy) therefore had
cleaning silently no-op, and CommitAll staged and published the
previous attempt's abandoned untracked files onto the task branch.

Suppress descent only for the directory shape; the pointer file is
skipped as an ordinary tracked-path miss would be, and left intact.

Refs archie-core-1ysw.3
2026-08-24 13:11:40 +10:00
sam 00c5e06152 refactor: remove dead BasePlatformAdapter code 2026-08-22 23:23:51 +10:00
sam 770cada41a fix(worktree): reject diffs without merge base 2026-08-22 22:06:54 +10:00
sam 6988f8b4a2 fix(worktree): reset retries to pristine base
Retry used to retain ignored and untracked output from an interrupted attempt, which CommitAll could publish later. Refresh now derives the tracked HEAD shape, removes every other worktree entry outside .git, and fails closed when the configured base cannot resolve.
2026-08-22 22:06:54 +10:00
sam 9e46e31759 fix(worktree): bind publication to dispatch grants
Worktree RPC used to accept repository coordinates from the sandbox. It now accepts only an opaque per-dispatch grant, and the daemon derives the repository path and branch from grant-owned state.

Repository worktree paths also move from an ambiguous flattened key to encoded owner/repo components. Origin-matched legacy clones migrate safely; mismatched legacy paths are preserved.
2026-08-22 22:06:54 +10:00
sam 37792c9ec0 fix(worktree): force checkout so retry recovers from a dirty worktree
refresh checked out the task branch without Force before hard-resetting
to base. A prior attempt's leftover uncommitted changes -- a killed
container, or a stage that edits files before ever reaching a commit --
made go-git's default MergeReset checkout refuse to reconcile them, even
with HEAD already on the correct branch and the target commit unmoved.
The fallback then made it worse: any checkout failure was assumed to
mean the branch didn't exist yet, so it retried with Create: true, which
failed with a much more confusing error since the branch did exist --
"a branch named ... already exists" -- masking the real cause and
parking the retry with the same unhelpful message every time.

Reproduced directly against a live deployment's actual broken worktree
(modified tracked file, untracked file, branch already checked out) and
confirmed retry then succeeds and correctly restores to base.

Force is safe unconditionally here: refresh hard-resets to base a few
lines later regardless of what checkout leaves behind.

Closes #523
2026-08-15 11:22:22 +10:00
sam efdc652488 fix(worktree): name the missing forge credential when push fails
Push previously handed an empty token straight to go-git and let the
push fail with a bare transport/auth error. When a repo is configured
while the forge is disabled (missing credential), that failure surfaced
late -- at push time -- with a message that didn't explain the cause.

Push now checks whether the worktree's origin remote is HTTP(S) (the
only transport that needs a token) before attempting the push, and
fails immediately with a message naming the missing forge.token
configuration. Local/file transports (used by the test double) are
unaffected -- they never needed a token.

Refs archie-core-3fb
2026-08-05 11:55:39 +10:00
sam f800e1de36 refactor(worktree): replace git shell-out with go-git v6
internal/worktree no longer executes the git binary. Clone, fetch,
checkout, commit, push and diff all run in-process through go-git v6,
which also removes the package's 9 noctx findings since the Context
variants are first-class.

Security: the forge token no longer leaves the process. The old
implementation wrote a GIT_ASKPASS shell script to disk and exported the
token into the environment of every git child process. Authentication is
now an in-process credential passed via client.WithHTTPAuth. cloneURL
also stops embedding the bot user in the GitHub URL.

Dropped the per-repo object cache (PreparePersistent, prepareCache,
CleanupExpiredCaches). go-git can clone with shared alternates but has no
equivalent of --dissociate, so a cached bare repo would remain a live
dependency of every worktree built from it, and expiring one would
corrupt running tasks rather than fail cleanly. Every task now gets an
independent full clone. repo.PersistentStorage still governs the
container volume; only the git object cache is gone.

Two real defects surfaced while porting, both caught by the new tests:

  - go-git honours the host's global git config and cannot sign commits
    (no gpg fallback, only an ObjectSigner plugin). On any machine with
    commit.gpgSign=true set globally, every bot commit would have failed
    with "cannot auto-sign commit". setIdentity now pins gpgsign=false in
    the clone's own config so daemon behaviour does not depend on the
    ambient config of whatever host it runs on.
  - go-git's Add(All) does NOT honour .git/info/exclude, which is how the
    .archie-prepared sentinel was kept untracked. It was being committed
    and would have been pushed onto every task branch. The sentinel now
    lives at .git/archie-prepared, where nothing can ever track it, and a
    regression test asserts it never appears in a commit.

Diff is now merge-base relative via Commit.MergeBase, matching the three
dot semantics of `git diff origin/base...HEAD`; diffing against the remote
tip would attribute commits landed on base since the branch started to
this task and could trip the diff-size cap. Base resolution tries the
remote-tracking ref first and falls back to the short "origin/<base>"
revision, keeping git's more permissive lookup.

The test suite was rebuilt on go-git fixtures and no longer needs a git
binary installed to run.
2026-07-28 01:56:59 +10:00
sam 529b25eada docs: phase 3a — nilerr review, all 11 sites were false positives (qa4)
97 -> 85. Not one of the eleven nilerr findings was a bug.

I called these "real bug candidates" when I planned the phases. I was
wrong, and the reason is worth recording: every site is the same
deliberate idiom, and a linter cannot see intent.

  - inprocess.go (5) and gateway.go (2) are handlers that report a
    problem as TEXT to their consumer. A tool handler returning a Go
    error aborts the tool call; returning "rejected: ..." lets the model
    read the feedback and retry with valid arguments. A chat handler
    returning a Go error surfaces as a gateway fault instead of a usage
    hint to the human.
  - worker.go carries runErr in the response envelope's Error field.
    Returning it as a Go error too would double-report and abort the
    NATS reply.
  - email.go returns nil when Accept fails because context cancellation
    closed the listener. That is a clean shutdown.
  - codesearch.go skips an unreadable entry and continues the walk. A
    best-effort index must not abort on one bad file.
  - skill.go is documented in the function comment already: a
    non-directory skills path means "no skills", not a fatal error.

Annotated each with //nolint:nilerr and the specific reason rather than
excluding the linter by path, so nilerr stays live everywhere else and
the next reader wondering "why nil here?" gets an answer at the site.

This is the phase I insisted on keeping single-session and out of the
subagent fan-out. A worker told to "fix nilerr" would have converted all
eleven to error returns: malformed tool arguments would hard-fail the
agent loop instead of being correctable, chat typos would read as
gateway faults, and shutdown would log spurious errors. Every test would
still have passed.
2026-07-28 01:39:22 +10:00
sam f6d51416f0 chore: replace 607 em-dashes with double hyphens project-wide
Includes MCP crash-after-init test fix (crash moved from handle() to serve()
entry point so transport sees immediate subprocess death).
2026-07-26 09:53:33 +10:00
sam 9df02f2b60 fix: golangci-lint baseline to zero findings (39→0)
19 files touched. All fixes are in code — no lint configuration
weakened:
- Added unchecked error handling in defer cleanup paths
- Removed dead variables and unused functions
- Added missing imports (io in gitea.go)
- Simplified conditions (TrimSuffix, De Morgan, slices.Contains)

Also fixes JetStream TempDir teardown race (archie-core-340):
t.Cleanup(srv.Shutdown) now registers after t.TempDir() so
server shutdown (including JetStream files) completes before
temp dir removal. Added srv.WaitForShutdown() for deterministic
cleanup ordering.

Closes: archie-core-756, archie-core-340
2026-07-25 23:51:13 +10:00
sam 918b198258 fix: resolve merge conflicts with main 2026-07-24 23:12:25 +10:00
sam d8379ecf22 Merge branch 'main' into fix/58-add-tests-for-prepares-idempotent-fast-path-and-git-error-pa 2026-07-24 07:44:55 +00:00
archie d2d10685e7 Prepare() treats worktree as ready from .git dir existence alone (archie)
Implements #57
2026-07-24 05:32:41 +00:00
archie cd2da34c39 fix: Add tests for Prepare's idempotent fast path and git error paths (archie)
Fixes #58
2026-07-24 05:28:19 +00:00
archie e780596bf9 askpass helper rewritten on every git call despite "(once)" comment (archie)
Implements #59
2026-07-24 05:16:57 +00:00
sam 920c56a14b fix: create branch on reuse if not found, add dolt+beads to Dockerfile 2026-07-24 11:31:27 +10:00
sam 1ce6489823 fix: bump branch slug limit to 60 chars 2026-07-24 11:22:34 +10:00
sam e4368f70af feat: persistent volumes with TTL for container/worktree storage (archie-core-j7v)
Add [containers].volume_ttl (default 72h). Persistent-storage repos get a
per-repo bare Git cache (--reference-if-able --dissociate) so task
worktrees clone fast without repeated full network clones, while staying
fully independent of the cache's lifecycle — cache expiry can never
corrupt an active or parked task's worktree. Docker repo volumes are
labeled as Archie-owned and swept non-forced (a volume still attached to a
running container survives and retries next cycle); the repo cache
directory is swept by mtime. Both cleanups run at daemon startup and each
poll cycle.

Filed archie-core-756 (repo-wide golangci-lint baseline) and archie-core-340
(intermittent JetStream TempDir teardown flake) as separate follow-ups
rather than scope-creeping them into this change.
2026-07-24 10:22:11 +10:00
sam f8df051b19 feat: bounded concurrent task dispatch in daemon (archie-core-u64)
Daemon previously processed one task at a time. Add bounded concurrent
dispatch for SQLite and NATS agent modes, reusing [containers].max_concurrency
(0 = unlimited). Same-repository tasks stay FIFO-serialized to avoid worktree
conflicts; different repositories now run concurrently.

Unblocks archie-core-l1q (NATS transport) and archie-core-g1l
(per-repo allow_concurrent override).
2026-07-24 07:42:13 +10:00
sam 368221b285 fix: pull latest instead of skipping when worktree exists 2026-07-23 23:00:43 +10:00
sam 739c3d5c46 fix: branch prefix from labels, default feat 2026-07-23 22:39:46 +10:00
sam 51ade3e503 fix: conventional commit prefix in branch names (feat/62-... not archie/issue-62) 2026-07-23 22:29:32 +10:00
sam 3898fd179c fix: descriptive branch names — archie/62-clear-finished-button instead of archie/issue-62 2026-07-23 20:25:38 +10:00
sam 898f9c4681 chore: whitespace 2026-07-22 21:13:31 +10:00
sam 3598498813 fix: clone worktree before container acquire to fix bind-mount race 2026-07-22 21:02:25 +10:00
sam c0d108a5d0 feat: add Yaegi-based plugin system (gates, custom stages, skill scripts)
Implements the full PRD (docs/prds/yaegi-plugin-system.md): repos can
now define .archie/gate.go for diff-inspecting quality rules shell
commands can't express, .archie/stages/*.go for custom pipeline steps,
and skills can ship Go scripts run via a new run_go_script agent tool —
all interpreted in-process with Yaegi, with panics recovered so a bad
script can't take down the daemon. Hot reload (phase 4) needed no code:
every loader reads from disk per call and every task gets a fresh
clone, so nothing is ever cached to go stale.
2026-07-22 00:54:46 +10:00
sam 86339b4d0d feat: add subprocess agent runner 2026-07-21 23:21:24 +10:00
sam 251cc7022c feat: add configurable forge and workflow behavior 2026-07-21 15:03:41 +10:00
sam c2c8e92304 feat: archied walking skeleton — poll, store, worktree, workflow engine, bootstrap PR
Repurposes archie-core as the archie orchestrator daemon (the old
Pocketbase PM-backend plan is archived under .references/).

- cmd/archied: -config, -once (single cycle for timers/testing)
- internal/config: TOML; per-repo gate command lists; role->model refs
- internal/store: SQLite (modernc, WAL) task state machine with
  transitions audit, idempotent enqueue, crash recovery (running ->
  queued, attempt++)
- internal/forge: go-github v78 — labelled-issue polling, invitation
  auto-accept, push verification, PR create/state, comments, close
- internal/worktree: fresh clone per task, bot identity, askpass token
  handling, diff-size stats, cleanup on merge/reject
- internal/workflow: extensible engine (stages over TaskContext, shared
  step library, label routing bug->tdd feature->feasibility default->
  implement); parks always comment on the issue. Bootstrap workflow
  (deterministic marker-file PR) proves the plumbing without LLM spend.

Store and worktree round-trips covered by tests (local bare remote).
2026-07-21 03:46:06 +10:00