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.
This commit is contained in:
1 parent
dbb6550ab3
commit
196dd02a6d
4 files changed
+184
-16
No files matched your search
@@ -40,3 +40,5 @@
|
||||
{"id":"int-d145e6fe5da65f8df6e433afcf8b02e8","kind":"field_change","created_at":"2026-08-22T11:13:23.297308578Z","actor":"Sam Catlow","issue_id":"archie-core-qk8m","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"Fixed: MCP npm servers for per-task containers now reuse a persistent npm cache. Added mcp.NpmCacheEnv (shared with the daemon-side fix), an always-on archie-cache-mcp-npm Docker volume mounted at /data/cache/mcp-npm on every task container regardless of ecosystem, and wired it into internal/app/agentworker/mcp_providers.go's stdio transport construction. Adversarial review found zero surviving findings."}}
|
||||
{"id":"int-c1baa90874e9de48952955e52a5760d2","kind":"field_change","created_at":"2026-08-22T11:47:02.381816994Z","actor":"Sam Catlow","issue_id":"archie-core-1ysw.1","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Implemented per-dispatch publication grants, removed sandbox-selected prepare/path authority, made repository worktree keys collision-free, and added fail-closed legacy migration/cleanup coverage."}}
|
||||
{"id":"int-3eca62d9ff92647ebeb091e5afe7e80a","kind":"field_change","created_at":"2026-08-22T11:47:02.632518654Z","actor":"Sam Catlow","issue_id":"archie-core-1ysw.2","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Implemented per-dispatch publication grants, removed sandbox-selected prepare/path authority, made repository worktree keys collision-free, and added fail-closed legacy migration/cleanup coverage."}}
|
||||
{"id":"int-389951a8f299a389cbb0432044362797","kind":"field_change","created_at":"2026-08-22T11:55:19.903017141Z","actor":"Sam Catlow","issue_id":"archie-core-1ysw.3","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Retry refresh now removes all non-HEAD worktree content including ignored output while preserving .git, tracked symlinks, and gitlinks; missing bases fail closed."}}
|
||||
{"id":"int-56c541cf59441d3b82a65bc0ee53e38c","kind":"field_change","created_at":"2026-08-22T11:55:20.137923996Z","actor":"Sam Catlow","issue_id":"archie-core-1ysw.4","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Retry refresh now removes all non-HEAD worktree content including ignored output while preserving .git, tracked symlinks, and gitlinks; missing bases fail closed."}}
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
{"_type":"issue","id":"archie-core-1ysw.1","title":"Bind worktree RPC operations to the dispatched task","description":"The sandboxed agent can currently choose owner, repo, issue, base, and branch on worktree RPC requests. The daemon then performs host deletion and credentialed forge operations without correlating the request to the dispatched task or enforcing WorkDir containment.","acceptance_criteria":"Reject traversal and unconfigured or task-mismatched coordinates before any filesystem or forge side effect; derive or validate the permitted branch; regression tests fail on the old behavior and pass on the fix.","status":"closed","priority":0,"issue_type":"bug","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-08-22T11:01:43Z","created_by":"Sam Catlow","updated_at":"2026-08-22T11:47:02Z","started_at":"2026-08-22T11:02:03Z","closed_at":"2026-08-22T11:47:02Z","close_reason":"Implemented per-dispatch publication grants, removed sandbox-selected prepare/path authority, made repository worktree keys collision-free, and added fail-closed legacy migration/cleanup coverage.","dependencies":[{"issue_id":"archie-core-1ysw.1","depends_on_id":"archie-core-1ysw","type":"parent-child","created_at":"2026-08-22T21:01:42Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-1ysw","title":"Repair internal/worktree correctness and trust-boundary defects","description":"Track the concrete worktree-package defects proven by the 2026-08-22 evidence-gated review. Child bugs cover RPC authority/path containment, repository-key isolation, retry/base/diff correctness, push lifecycle, terminal cleanup, cancellation, and branch naming. This epic groups implementation only; each child has its own observable acceptance criteria.","acceptance_criteria":"All child bugs are closed with red-green regression tests, scoped lint passes, and the repository quality gate is clean.","status":"open","priority":0,"issue_type":"epic","owner":"sam@catlow.tech","created_at":"2026-08-22T11:01:18Z","created_by":"Sam Catlow","updated_at":"2026-08-22T11:01:18Z","dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-t2db.5","title":"Security: an unauthenticated endpoint must not be able to run an agent","description":"P0 within this epic because the feature's own pitch is the threat model: a public intake surface whose output is an agent with tool access and a repo. Get this wrong and a webhook URL is remote code execution with extra steps.\n\nNon-negotiables to design:\n\n- Per-source authentication. A source registers with a secret (HMAC, as internal/channels/webhook already does per route) before its events can trigger anything. Capture-only for unknown senders is acceptable; triggering is not.\n- Human approval before a binding goes live. An operator authoring a binding is a deliberate act; an event arriving is not. Nothing should self-arm.\n- Rate and volume limits per source, so capture cannot be used to exhaust disk or drown the inspector.\n- Payload content is untrusted input flowing into an agent prompt. Treat prompt injection as expected, not exceptional -- the sender controls that text, and the agent has tools. Bound what a playbook-triggered workflow may do.\n- Captured payloads may contain secrets from the sending system. Decide retention, redaction and who can view them; internal/memory/scrubber may already have applicable prior art.\n\nArchie's own principle applies: environmental enforcement over prompt rules. 'The agent should ignore instructions in the payload' is not a control.","acceptance_criteria":"An event from an unauthenticated source can be captured but cannot trigger a workflow; a new binding requires explicit human approval before it arms; per-source rate limits exist; the blast radius of a playbook-triggered workflow is bounded by code rather than by prompt text; retention and visibility of captured payloads is decided and documented.","notes":"2026-08-22: security design decided and documented in docs/prds/webhook-intake-security.md, covering all five non-negotiables from this bead's description:\n1. Per-source auth reuses internal/channels/webhook's existing HMAC-SHA256 scheme; capture accepts unsigned events (visible, marked unauthenticated), only authenticated events can ever match a binding.\n2. Bindings gain a draft -\u003e pending_approval -\u003e armed state machine; any edit to an armed binding drops it back to pending_approval so approval can't be bypassed by editing. Modeled on telegram's existing dangerousAction/pendingApproval flow (dangerous.go/approval.go).\n3. Per-source token-bucket rate limiting (precedent: pairing/store.go's MaxPendingPerPlatform); limit-exceeded is an observable 429, not a silent drop.\n4. Blast radius bounded by the SAME code-level controls every task already gets -- gate, diff_cap_lines, sandboxed container, worktree isolation -- no new relaxation for playbook-triggered work, and payload text is ordinary untrusted prompt input, never a trusted instruction.\n5. 7-day configurable retention on captured payloads; best-effort redaction reusing gateway/stream.go's sensitiveParameterKey heuristic before persisting; visibility gated by the same dashboard auth as every other webui surface.\n\nThis bead's code-level acceptance criteria (capture-can't-trigger, rate limits exist, blast-radius bounded, approval gate) cannot be implemented yet: they constrain t2db.1 (capture), 7d5u.3 (intake family) and t2db.4 (binding), none of which have landed. This document is the contract those beads build against -- do not build any of them without satisfying it. Leaving this bead in_progress rather than closing it; it closes when t2db.1/7d5u.3/t2db.4 land and demonstrably satisfy points 1-5, not before.","status":"in_progress","priority":0,"issue_type":"feature","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-08-21T13:45:46Z","created_by":"Sam Catlow","updated_at":"2026-08-22T09:25:01Z","started_at":"2026-08-21T14:51:26Z","external_ref":"https://github.com/samcharles93/archie-core/issues/536","dependencies":[{"issue_id":"archie-core-t2db.5","depends_on_id":"archie-core-t2db","type":"parent-child","created_at":"2026-08-21T23:45:45Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":1,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-1ysw.3","title":"Clean abandoned untracked files on retry","description":"Prepare refresh hard-resets tracked files but retains untracked files; CommitAll later stages and publishes them during the next attempt.","acceptance_criteria":"A regression test proves an untracked file left by an interrupted attempt is absent after retry and cannot appear in ChangedFiles or the next commit; deliberate .git control files remain intact.","status":"open","priority":1,"issue_type":"bug","owner":"sam@catlow.tech","created_at":"2026-08-22T11:01:44Z","created_by":"Sam Catlow","updated_at":"2026-08-22T11:01:44Z","dependencies":[{"issue_id":"archie-core-1ysw.3","depends_on_id":"archie-core-1ysw","type":"parent-child","created_at":"2026-08-22T21:01:44Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-1ysw.3","title":"Clean abandoned untracked files on retry","description":"Prepare refresh hard-resets tracked files but retains untracked files; CommitAll later stages and publishes them during the next attempt.","acceptance_criteria":"A regression test proves an untracked file left by an interrupted attempt is absent after retry and cannot appear in ChangedFiles or the next commit; deliberate .git control files remain intact.","status":"closed","priority":1,"issue_type":"bug","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-08-22T11:01:44Z","created_by":"Sam Catlow","updated_at":"2026-08-22T11:55:20Z","started_at":"2026-08-22T11:47:47Z","closed_at":"2026-08-22T11:55:20Z","close_reason":"Retry refresh now removes all non-HEAD worktree content including ignored output while preserving .git, tracked symlinks, and gitlinks; missing bases fail closed.","dependencies":[{"issue_id":"archie-core-1ysw.3","depends_on_id":"archie-core-1ysw","type":"parent-child","created_at":"2026-08-22T21:01:44Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-1ysw.2","title":"Make worktree directory keys collision-free","description":"Manager.Dir flattens owner and repo with a hyphen, so distinct repositories such as a-b/c and a/b-c share a task directory for equal issue numbers.","acceptance_criteria":"Distinct owner/repo tuples always map to distinct contained paths; sequential and concurrent collision regressions cannot reuse, delete, reset, or push the other repository's clone.","status":"closed","priority":1,"issue_type":"bug","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-08-22T11:01:43Z","created_by":"Sam Catlow","updated_at":"2026-08-22T11:47:03Z","started_at":"2026-08-22T11:44:35Z","closed_at":"2026-08-22T11:47:03Z","close_reason":"Implemented per-dispatch publication grants, removed sandbox-selected prepare/path authority, made repository worktree keys collision-free, and added fail-closed legacy migration/cleanup coverage.","dependencies":[{"issue_id":"archie-core-1ysw.2","depends_on_id":"archie-core-1ysw","type":"parent-child","created_at":"2026-08-22T21:01:43Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-t2db.4","title":"Playbook binding: matcher + mapping + workflow, editable at runtime","description":"The object that ties it together. A binding is: a matcher (which inbound events does this apply to), a mapping (which fields the workflow receives), and a target agentic workflow.\n\nRuntime-editable is the whole point -- creating or changing a binding must not require a redeploy or a daemon restart. That has real consequences the design must face:\n\n- Bindings are persisted state, not config. They live in the store, not config.toml, because operators create them from the UI while the daemon runs.\n- They need versioning. A binding that starts a task should record WHICH version ran, or a later edit makes historical task provenance a lie.\n- Matcher ambiguity needs a defined resolution: two bindings matching one event either both run, or the more specific wins, or it is an error. Pick one and say so.\n- A binding referencing a workflow that no longer exists must fail visibly at bind time, not at 3am when the event arrives.","acceptance_criteria":"A binding can be created, edited and disabled from the UI while the daemon runs; a task records the binding version that started it; overlapping matchers resolve by a defined and documented rule; a binding naming a missing workflow is rejected when saved.","notes":"2026-08-22: the draft -\u003e pending_approval -\u003e armed state machine from t2db.5's decision belongs to the binding entity this bead defines, not to a shared package -- 7d5u.3 was narrowed to exclude it since there is exactly one consumer today. Implement the state transitions here.","status":"open","priority":1,"issue_type":"feature","owner":"sam@catlow.tech","created_at":"2026-08-21T13:45:45Z","created_by":"Sam Catlow","updated_at":"2026-08-22T09:25:02Z","external_ref":"https://github.com/samcharles93/archie-core/issues/537","dependencies":[{"issue_id":"archie-core-t2db.4","depends_on_id":"archie-core-t2db.5","type":"blocks","created_at":"2026-08-21T23:45:53Z","created_by":"Sam Catlow","metadata":"{}"},{"issue_id":"archie-core-t2db.4","depends_on_id":"archie-core-t2db.3","type":"blocks","created_at":"2026-08-21T23:45:53Z","created_by":"Sam Catlow","metadata":"{}"},{"issue_id":"archie-core-t2db.4","depends_on_id":"archie-core-t2db","type":"parent-child","created_at":"2026-08-21T23:45:45Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":2,"dependent_count":1,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-t2db.1","title":"Capture inbound events archie does not yet understand","description":"The precondition for everything else. Today an unrecognised inbound request is rejected; for schema-by-example it must be RECORDED, because you cannot map a payload you have never seen.\n\nAccept, store and retain inbound events with no binding: raw body, headers, source, arrival time, and the identity that sent it. Retention must be bounded -- an open capture endpoint is an unbounded disk write, and this is exactly the kind of surface an attacker fills.\n\nStrong argument for NATS JetStream as the store rather than the in-process events.Bus: durable, replayable, retention-bounded natively, already deployed. Note the constraint though -- internal/infrastructure/eventbus/nats/doc.go states 'when no NATS URL is configured the daemon uses its local SQLite claim flow instead; nothing here is required for single-process operation'. NATS is currently OPTIONAL. Decide deliberately whether capture requires it (making this feature unavailable in single-process deployments) or degrades to SQLite, and record which -- do not let it become a hard dependency by accident.","acceptance_criteria":"An unbound webhook POST is captured and visible rather than rejected; capture is retention-bounded with a documented limit; the single-process (no NATS) behaviour is a deliberate, recorded decision; capture cannot exhaust disk.","notes":"2026-08-22: capture-storage ownership confirmed here (not in 7d5u.3, which was narrowed to storage-agnostic HMAC/rate-limit/redaction mechanics only). This bead's capture path should call webhookguard's redaction before persisting and its rate limiter at the HTTP boundary, but owns its own storage engine and the NATS-vs-SQLite decision.","status":"closed","priority":1,"issue_type":"feature","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-08-21T13:45:18Z","created_by":"Sam Catlow","updated_at":"2026-08-22T09:25:03Z","started_at":"2026-08-21T16:18:24Z","closed_at":"2026-08-21T18:51:09Z","close_reason":"Built capture storage + endpoint: docs/prds/event-capture-storage.md decides SQLite over NATS JetStream (NATS not unconditionally available pre-7d5u.2, capture's single-writer/single-reader access pattern doesn't need JetStream fan-out/replay). internal/store/captures.go adds captured_events table + InsertCapture (prune-on-write by retention age and row count) + ListCaptures. internal/webui/api_capture.go adds POST /webhooks/capture/{source}, unauthenticated (bypasses requireToken like /healthz), applying webhookguard redaction before persisting and a per-remote-address rate limit + hard body-size cap before that. New [capture] config section with documented defaults. Adversarial self-review (the usual fresh subagent pass hit a session API limit mid-run, so this was a manual re-read with the same checklist) caught and fixed three real bugs before landing: (1) body-size cap silently unenforced when unset -- added a hardcoded fallback floor since it's the only bound on a SINGLE payload's size; (2) rate limiter was keyed by the request's own unregistered source path segment, violating webhookguard.RateLimiter's documented bounded-key-space assumption -- an attacker could rotate the segment to bypass the limit and grow the bucket map unbounded; rekeyed to remote address; (3) retention prune used time.RFC3339Nano, whose variable-width trimmed fractional seconds break lexicographic string comparison in `WHERE received_at \u003c ?` (an exact-second timestamp can sort after a later fractional one) -- switched to fixed-width RFC3339. All three have regression tests verified to fail against the pre-fix code. task check clean, golangci-lint zero new findings repo-wide.","external_ref":"https://github.com/samcharles93/archie-core/issues/538","dependencies":[{"issue_id":"archie-core-t2db.1","depends_on_id":"archie-core-7d5u.4","type":"relates-to","created_at":"2026-08-22T01:01:02Z","created_by":"Sam Catlow","metadata":"{}"},{"issue_id":"archie-core-t2db.1","depends_on_id":"archie-core-t2db","type":"parent-child","created_at":"2026-08-21T23:45:17Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":2,"comment_count":0}
|
||||
@@ -45,7 +45,7 @@
|
||||
{"_type":"issue","id":"archie-core-1ysw.7","title":"Clean no-change worktrees at terminal completion","description":"BuildNoChanges transitions directly to merged without a PR, bypassing the only production worktree cleanup path and leaking a full clone.","acceptance_criteria":"Both direct and container no-change completion remove the identity-correct worktree while parked worktrees remain available; lifecycle regression tests cover the terminal path.","status":"open","priority":2,"issue_type":"bug","owner":"sam@catlow.tech","created_at":"2026-08-22T11:01:47Z","created_by":"Sam Catlow","updated_at":"2026-08-22T11:01:47Z","dependencies":[{"issue_id":"archie-core-1ysw.7","depends_on_id":"archie-core-1ysw","type":"parent-child","created_at":"2026-08-22T21:01:46Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-1ysw.5","title":"Preserve three-dot failure semantics without a merge base","description":"patch silently computes a direct tree diff when base and HEAD have no merge base, contradicting its three-dot contract and corrupting diff-cap and gate inputs.","acceptance_criteria":"Unrelated histories return a clear error from Diff, ChangedFiles, and ChangedLines; shared-history merge-base behavior remains covered.","status":"open","priority":2,"issue_type":"bug","owner":"sam@catlow.tech","created_at":"2026-08-22T11:01:46Z","created_by":"Sam Catlow","updated_at":"2026-08-22T11:01:46Z","dependencies":[{"issue_id":"archie-core-1ysw.5","depends_on_id":"archie-core-1ysw","type":"parent-child","created_at":"2026-08-22T21:01:45Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-1ysw.6","title":"Do not report push failure after successful publication","description":"Push publishes the remote ref before writing unused local upstream metadata, then returns local config errors as if publication failed.","acceptance_criteria":"A post-publication metadata failure cannot park the task as an unsuccessful push; tests verify the remote ref and returned result remain consistent.","status":"open","priority":2,"issue_type":"bug","owner":"sam@catlow.tech","created_at":"2026-08-22T11:01:46Z","created_by":"Sam Catlow","updated_at":"2026-08-22T11:01:46Z","dependencies":[{"issue_id":"archie-core-1ysw.6","depends_on_id":"archie-core-1ysw","type":"parent-child","created_at":"2026-08-22T21:01:46Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-1ysw.4","title":"Fail refresh when the configured base cannot resolve","description":"Prepared worktrees currently swallow every resolveBase error and report successful refresh against stale history.","acceptance_criteria":"Prepared-worktree refresh returns a contextual error for a missing, renamed, or invalid base; fresh and reused Prepare paths have consistent tests.","status":"open","priority":2,"issue_type":"bug","owner":"sam@catlow.tech","created_at":"2026-08-22T11:01:45Z","created_by":"Sam Catlow","updated_at":"2026-08-22T11:01:45Z","dependencies":[{"issue_id":"archie-core-1ysw.4","depends_on_id":"archie-core-1ysw","type":"parent-child","created_at":"2026-08-22T21:01:44Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-1ysw.4","title":"Fail refresh when the configured base cannot resolve","description":"Prepared worktrees currently swallow every resolveBase error and report successful refresh against stale history.","acceptance_criteria":"Prepared-worktree refresh returns a contextual error for a missing, renamed, or invalid base; fresh and reused Prepare paths have consistent tests.","status":"closed","priority":2,"issue_type":"bug","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-08-22T11:01:45Z","created_by":"Sam Catlow","updated_at":"2026-08-22T11:55:20Z","started_at":"2026-08-22T11:52:19Z","closed_at":"2026-08-22T11:55:20Z","close_reason":"Retry refresh now removes all non-HEAD worktree content including ignored output while preserving .git, tracked symlinks, and gitlinks; missing bases fail closed.","dependencies":[{"issue_id":"archie-core-1ysw.4","depends_on_id":"archie-core-1ysw","type":"parent-child","created_at":"2026-08-22T21:01:44Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-j8b4","title":"Implement persistent session memory and plugin storage","description":"Replace the PRD section 3 placeholder in internal/storage/storage.go with the specified persistent storage behavior for session.jsonl, memory.jsonl, and plugins.","status":"closed","priority":2,"issue_type":"task","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-08-22T10:32:31Z","created_by":"Sam Catlow","updated_at":"2026-08-22T10:56:59Z","started_at":"2026-08-22T10:32:37Z","closed_at":"2026-08-22T10:56:59Z","close_reason":"Implemented persistent session transcript, cross-session memory, and staged plugin storage","dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-t2db.6","title":"Docs: document playbooks, bindings and the intake threat model","description":"Separate so it is not lost when the feature lands.\n\n- The playbook/binding model in docs/architecture/: what a binding is, where it is persisted, how matchers resolve, how versioning works.\n- The threat model, written down plainly: this is a public intake surface that can start agents. Record what protects it and what does not.\n- ARCHITECTURE.md task lifecycle: a task started by a playbook binding has a different provenance from a forge-issue task, and the lifecycle section should say so.\n- Operator docs: how to point an external app at archie and build a first playbook, end to end.\n\nCLAUDE.md's rule: a doc that contradicts its code is worse than none.","acceptance_criteria":"The binding model and threat model are documented in docs/architecture/; ARCHITECTURE.md covers playbook-originated tasks; there is an end-to-end operator walkthrough for building a first playbook.","status":"open","priority":2,"issue_type":"task","owner":"sam@catlow.tech","created_at":"2026-08-21T13:45:46Z","created_by":"Sam Catlow","updated_at":"2026-08-22T09:25:29Z","external_ref":"https://github.com/samcharles93/archie-core/issues/553","dependencies":[{"issue_id":"archie-core-t2db.6","depends_on_id":"archie-core-t2db.4","type":"blocks","created_at":"2026-08-21T23:45:53Z","created_by":"Sam Catlow","metadata":"{}"},{"issue_id":"archie-core-t2db.6","depends_on_id":"archie-core-t2db","type":"parent-child","created_at":"2026-08-21T23:45:45Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":1,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-7d5u.6","title":"Docs: reconcile plugins-and-extensions.md and ARCHITECTURE.md with the shipped event model","description":"Separate bead so it is not lost once the feature lands.\n\n1. docs/architecture/plugins-and-extensions.md is an APPROVED foundation dated 2026-07-28 and currently describes only the plugin framework. If the design bead concluded that extensions may react to events, this doc has to say how -- and if it concluded that generic untyped dispatch is allowed after all, this doc must be amended deliberately rather than contradicted by code.\n\n2. ARCHITECTURE.md describes work intake as polling. Once webhook intake ships, that is no longer the whole picture, and the task lifecycle section needs the new entry path.\n\n3. CLAUDE.md's per-package traps section should gain whatever trap this work creates -- HMAC verification, replay windows, the poll/webhook double-dispatch hazard. That section exists precisely for things an agent will otherwise break.\n\n4. config.example.toml needs the intake flag documented with its default, alongside poll_interval.\n\nCLAUDE.md's own rule: a doc that contradicts its code is worse than none, because the next reader trusts it.","acceptance_criteria":"plugins-and-extensions.md reflects the decided extension model; ARCHITECTURE.md documents webhook intake alongside polling; config.example.toml documents the intake flag and default; any new trap is recorded in CLAUDE.md.","status":"open","priority":2,"issue_type":"task","owner":"sam@catlow.tech","created_at":"2026-08-21T13:26:52Z","created_by":"Sam Catlow","updated_at":"2026-08-22T09:25:30Z","external_ref":"https://github.com/samcharles93/archie-core/issues/554","dependencies":[{"issue_id":"archie-core-7d5u.6","depends_on_id":"archie-core-7d5u","type":"parent-child","created_at":"2026-08-21T23:26:51Z","created_by":"Sam Catlow","metadata":"{}"},{"issue_id":"archie-core-7d5u.6","depends_on_id":"archie-core-7d5u.4","type":"blocks","created_at":"2026-08-21T23:26:58Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":1,"dependent_count":0,"comment_count":0}
|
||||
@@ -377,9 +377,9 @@
|
||||
{"_type":"issue","id":"archie-core-1786637493467-141-ffb91b17","title":"ToolEntry data type definition","description":"Design and implement the ToolEntry data type carrying: name, toolset (which tool group this belongs to), schema (JSON Schema for invocation), handler (function ref), check_fn (availability predicate), requires_env (env vars needed), is_async (async/sync distinction), description, emoji, max_result_size_chars (per-tool result cap), and dynamic_schema_overrides (runtime schema mutations). This is the foundational type that everything in the tools subsystem builds upon.","status":"closed","priority":2,"issue_type":"task","created_at":"2026-08-08T14:38:14Z","updated_at":"2026-08-08T14:38:16Z","closed_at":"2026-08-08T14:38:17Z","external_ref":"https://github.com/samcharles93/archie-core/issues/162","source_system":"github:https://github.com/samcharles93/archie-core/issues/162:162","metadata":null,"labels":["task"],"dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-1786637493439-140-2cee2e9b","title":"[EPIC] Tools: central registry, MCP client, guardrails","description":"Central tool infrastructure to match Hermes parity:\n\n1. **Tool registry**: A central registry where tool modules register themselves with name, schema, handler, toolset membership, and availability check. Dynamic discovery of built-in tools. This replaces the current pattern of manually constructing core.ToolSet maps per invocation.\n\n2. **MCP client**: Connect to external MCP servers via stdio, HTTP/StreamableHTTP, or SSE transport. Discover their tools and register them into the tool registry. Support automatic reconnection with backoff, configurable timeouts, per-server parallel tool call opt-in.\n\n3. **Guardrails**: Tool-call loop detection (repeated calls, repeated failures, no-progress loops). Idempotent/mutating tool classification. Warning vs hard-stop decisions.\n\n4. **Progressive disclosure**: When tool schemas exceed a context-window threshold, replace them with bridge tools (tool_search/tool_describe/tool_call) and surface on demand. Core tools are always visible.\n\nRef: docs/prds/hermes-gap-analysis.md section 3\n\n### Acceptance Criteria\n\nMCP servers can be configured with a TOML block and their tools appear alongside built-ins. The agent loop is protected against tool-call loops. Tool schemas stay within context budget.\n","notes":"docs/prds/hermes-gap-analysis.md (referenced above) was intentionally deleted in commit 65aa5b4 ('chore: cleanup', 2026-07-28) after it had already spawned this and ~14 sibling beads issues from its 60 identified gaps — it is not a broken link to restore. This issue's description is the surviving record of its slice of that analysis.","status":"open","priority":2,"issue_type":"epic","created_at":"2026-08-08T14:38:11Z","updated_at":"2026-08-15T12:47:30Z","external_ref":"https://github.com/samcharles93/archie-core/issues/161","source_system":"github:https://github.com/samcharles93/archie-core/issues/161:161","metadata":null,"labels":["epic"],"dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-1786637493413-139-d157cc71","title":"SessionSource struct for platform identity","status":"closed","priority":2,"issue_type":"task","created_at":"2026-08-08T14:38:06Z","updated_at":"2026-08-08T14:38:08Z","closed_at":"2026-08-08T14:38:09Z","external_ref":"https://github.com/samcharles93/archie-core/issues/160","source_system":"github:https://github.com/samcharles93/archie-core/issues/160:160","metadata":null,"labels":["task"],"dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-1786637493387-138-cad8e7a7","title":"Platform capability flags for adapters","description":"A capability-flag mechanism so callers can ask an adapter which optional features it supports (typing indicator, edit, delete, media send, clarify/approval/picker UI) instead of discovering support by a failed type assertion or a runtime error.\n\n### Context for implementers\n\nThis depends on the optional-method interfaces this issue is meant to describe: `archie-core-1786637493329-136-49b39c78` (typing/edit/delete/media) and `archie-core-1786637493357-137-35af7083` (clarify/approval/pickers). Implement after (or in close coordination with) those two, since the flag set should mirror whatever optional interfaces they land — don't invent a flag taxonomy ahead of the methods it describes.\n\n### Acceptance Criteria\n\n`BasePlatformAdapter` (`internal/gateway/adapter.go`) or a wrapping type exposes a capability query (e.g. `Capabilities() AdapterCapabilities`) that reports which optional methods an adapter implements. Every existing adapter's reported capabilities match its actual method set (a regression test should fail if an adapter claims a capability it doesn't implement, or vice versa).\n","status":"open","priority":2,"issue_type":"task","created_at":"2026-08-08T14:38:02Z","updated_at":"2026-08-15T12:46:48Z","external_ref":"https://github.com/samcharles93/archie-core/issues/159","source_system":"github:https://github.com/samcharles93/archie-core/issues/159:159","metadata":null,"labels":["task"],"dependencies":[{"issue_id":"archie-core-1786637493387-138-cad8e7a7","depends_on_id":"archie-core-1786637493357-137-35af7083","type":"blocks","created_at":"2026-08-15T12:46:57Z","created_by":"Sam Catlow","metadata":"{}"},{"issue_id":"archie-core-1786637493387-138-cad8e7a7","depends_on_id":"archie-core-1786637493329-136-49b39c78","type":"blocks","created_at":"2026-08-15T12:46:57Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":2,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-1786637493387-138-cad8e7a7","title":"Platform capability flags for adapters","description":"A capability-flag mechanism so callers can ask an adapter which optional features it supports (typing indicator, edit, delete, media send, clarify/approval/picker UI) instead of discovering support by a failed type assertion or a runtime error.\n\n### Context for implementers\n\nThis depends on the optional-method interfaces this issue is meant to describe: `archie-core-1786637493329-136-49b39c78` (typing/edit/delete/media) and `archie-core-1786637493357-137-35af7083` (clarify/approval/pickers). Implement after (or in close coordination with) those two, since the flag set should mirror whatever optional interfaces they land — don't invent a flag taxonomy ahead of the methods it describes.\n\n### Acceptance Criteria\n\n`BasePlatformAdapter` (`internal/gateway/adapter.go`) or a wrapping type exposes a capability query (e.g. `Capabilities() AdapterCapabilities`) that reports which optional methods an adapter implements. Every existing adapter's reported capabilities match its actual method set (a regression test should fail if an adapter claims a capability it doesn't implement, or vice versa).\n","status":"in_progress","priority":2,"issue_type":"task","assignee":"Sam Catlow","created_at":"2026-08-08T14:38:02Z","updated_at":"2026-08-22T11:53:10Z","started_at":"2026-08-22T11:53:10Z","external_ref":"https://github.com/samcharles93/archie-core/issues/159","source_system":"github:https://github.com/samcharles93/archie-core/issues/159:159","metadata":null,"labels":["task"],"dependencies":[{"issue_id":"archie-core-1786637493387-138-cad8e7a7","depends_on_id":"archie-core-1786637493357-137-35af7083","type":"blocks","created_at":"2026-08-15T12:46:57Z","created_by":"Sam Catlow","metadata":"{}"},{"issue_id":"archie-core-1786637493387-138-cad8e7a7","depends_on_id":"archie-core-1786637493329-136-49b39c78","type":"blocks","created_at":"2026-08-15T12:46:57Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":2,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-1786637493357-137-35af7083","title":"BasePlatformAdapter interactive UX methods (clarify, approval, pickers)","description":"Add adapter-facing methods for interactive UX: presenting a clarifying question, an approval prompt, and a picker (multi-choice selection) natively on the platform, rather than as plain text the user has to reply to by hand.\n\n### Context for implementers\n\nThe approval *decision* plumbing already exists — `internal/tools/approval.go`, re-exported through `internal/gateway/approval.go` (`ApprovalRequester`, `ApprovalDecision`, `WithApprovalRequester`/`ApprovalFromContext`). What's missing is the adapter-side rendering: `BasePlatformAdapter` (`internal/gateway/adapter.go`) has no method for an adapter to display an approval/clarify/picker UI and report back a decision through that existing plumbing. This issue wires a new adapter method (or interface) into the existing `ApprovalRequester` flow — it should not duplicate or replace the decision model in `internal/tools/approval.go`. Sibling of `archie-core-1786637493329-136-49b39c78` (typing/edit/delete/media) — same \"optional adapter capability\" shape, different capability set.\n\n### Acceptance Criteria\n\nAn adapter can render a clarify/approval/picker prompt and the user's response is delivered back through the existing `ApprovalRequester`/`ApprovalDecision` flow in `internal/tools/approval.go`, not a parallel mechanism. Platforms without native UI (e.g. plain text-only channels) degrade to a text-based fallback rather than failing. Covered by a test double adapter, not a live platform.\n","status":"open","priority":2,"issue_type":"task","created_at":"2026-08-08T14:37:59Z","updated_at":"2026-08-15T12:46:48Z","external_ref":"https://github.com/samcharles93/archie-core/issues/158","source_system":"github:https://github.com/samcharles93/archie-core/issues/158:158","metadata":null,"labels":["task"],"dependency_count":0,"dependent_count":1,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-1786637493329-136-49b39c78","title":"BasePlatformAdapter optional methods (typing, edit, delete, media)","description":"Extend adapter capability beyond the four required `BasePlatformAdapter` methods with optional per-platform methods: typing indicator, message edit, message delete, and media-specific send.\n\n### Context for implementers\n\n`internal/gateway/adapter.go` today defines `BasePlatformAdapter` with exactly four methods: `Connect`, `Disconnect`, `Send`, `ChatInfo` (see full listing — the file is 80 lines). Not every platform supports typing/edit/delete/media uniformly, so these should be a separate optional interface(s) that callers type-assert for, not additions to the required interface (that would break every existing adapter implementation). Pairs with `archie-core-1786637493387-138-cad8e7a7` (platform capability flags) — callers need a way to know *ahead of a type assertion* whether an adapter supports a given optional method, rather than probing via failed assertions at call time.\n\n### Acceptance Criteria\n\nOptional methods are defined on a separate interface (or interfaces) from `BasePlatformAdapter`, so existing adapters keep compiling unchanged. At least one adapter implementation exercises each optional method in a test. Callers that invoke an optional method on an adapter that doesn't implement it get a defined, non-panicking behavior.\n","status":"open","priority":2,"issue_type":"task","created_at":"2026-08-08T14:37:57Z","updated_at":"2026-08-15T12:46:47Z","external_ref":"https://github.com/samcharles93/archie-core/issues/157","source_system":"github:https://github.com/samcharles93/archie-core/issues/157:157","metadata":null,"labels":["task"],"dependency_count":0,"dependent_count":1,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-1786637493329-136-49b39c78","title":"BasePlatformAdapter optional methods (typing, edit, delete, media)","description":"Extend adapter capability beyond the four required `BasePlatformAdapter` methods with optional per-platform methods: typing indicator, message edit, message delete, and media-specific send.\n\n### Context for implementers\n\n`internal/gateway/adapter.go` today defines `BasePlatformAdapter` with exactly four methods: `Connect`, `Disconnect`, `Send`, `ChatInfo` (see full listing — the file is 80 lines). Not every platform supports typing/edit/delete/media uniformly, so these should be a separate optional interface(s) that callers type-assert for, not additions to the required interface (that would break every existing adapter implementation). Pairs with `archie-core-1786637493387-138-cad8e7a7` (platform capability flags) — callers need a way to know *ahead of a type assertion* whether an adapter supports a given optional method, rather than probing via failed assertions at call time.\n\n### Acceptance Criteria\n\nOptional methods are defined on a separate interface (or interfaces) from `BasePlatformAdapter`, so existing adapters keep compiling unchanged. At least one adapter implementation exercises each optional method in a test. Callers that invoke an optional method on an adapter that doesn't implement it get a defined, non-panicking behavior.\n","status":"in_progress","priority":2,"issue_type":"task","assignee":"Sam Catlow","created_at":"2026-08-08T14:37:57Z","updated_at":"2026-08-22T11:53:09Z","started_at":"2026-08-22T11:53:09Z","external_ref":"https://github.com/samcharles93/archie-core/issues/157","source_system":"github:https://github.com/samcharles93/archie-core/issues/157:157","metadata":null,"labels":["task"],"dependency_count":0,"dependent_count":1,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-1786637493304-135-95070200","title":"BasePlatformAdapter interface with required methods","status":"closed","priority":2,"issue_type":"task","created_at":"2026-08-08T14:37:51Z","updated_at":"2026-08-08T14:37:54Z","closed_at":"2026-08-08T14:37:55Z","external_ref":"https://github.com/samcharles93/archie-core/issues/156","source_system":"github:https://github.com/samcharles93/archie-core/issues/156:156","metadata":null,"labels":["task"],"dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-1786637493282-134-cf46838e","title":"EphemeralReply type with auto-delete TTL","description":"An `EphemeralReply` type for messages the gateway sends that should self-delete after a TTL — status/progress placeholders (\"thinking…\", \"running tool X…\") that shouldn't linger in the chat history once superseded.\n\n### Context for implementers\n\nNo ephemeral-reply file exists yet in `internal/gateway`. Deletion requires adapter support: `BasePlatformAdapter` (`internal/gateway/adapter.go`) currently exposes only `Connect`/`Disconnect`/`Send`/`ChatInfo` — no delete method. This depends on (or should land alongside) `archie-core-1786637493329-136-49b39c78` (BasePlatformAdapter optional methods, which includes delete) — an adapter without a delete method can't honor the TTL.\n\n### Acceptance Criteria\n\nAn `EphemeralReply` carries a TTL after which the gateway issues a delete against the originating adapter. Adapters without delete support degrade gracefully (e.g. leave the message, log once) rather than erroring the turn. TTL firing is covered by a test using an injected clock, not a real sleep.\n","status":"open","priority":2,"issue_type":"task","created_at":"2026-08-08T14:37:48Z","updated_at":"2026-08-15T12:46:47Z","external_ref":"https://github.com/samcharles93/archie-core/issues/155","source_system":"github:https://github.com/samcharles93/archie-core/issues/155:155","metadata":null,"labels":["task"],"dependencies":[{"issue_id":"archie-core-1786637493282-134-cf46838e","depends_on_id":"archie-core-1786637493329-136-49b39c78","type":"related","created_at":"2026-08-15T12:46:57Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-1786637493254-133-444ec94e","title":"Telegram: interactive /model selector","description":"When /model is invoked without an argument, present Telegram-native interactive controls rather than only plain text usage. Use the pinned go-telegram/bot SDK inline keyboard and callback query APIs; preserve /model provider/model for typed selection and enforce the existing sender allowlist on callbacks.\n\n### Acceptance Criteria\n\nAn allowlisted user invoking /model receives an inline keyboard of configured models with the active model marked; tapping a model switches it through gateway.ModelManager, acknowledges the callback, and updates the message; unauthorized or malformed callbacks cannot switch models; empty model catalogs degrade safely.","status":"closed","priority":2,"issue_type":"feature","created_at":"2026-08-08T14:37:45Z","updated_at":"2026-08-15T02:48:49Z","closed_at":"2026-08-15T02:48:49Z","external_ref":"https://github.com/samcharles93/archie-core/issues/154","source_system":"github:https://github.com/samcharles93/archie-core/issues/154:154","metadata":null,"labels":["enhancement"],"dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
gitconfig "github.com/go-git/go-git/v6/config"
|
||||
"github.com/go-git/go-git/v6/plumbing"
|
||||
gitclient "github.com/go-git/go-git/v6/plumbing/client"
|
||||
"github.com/go-git/go-git/v6/plumbing/filemode"
|
||||
"github.com/go-git/go-git/v6/plumbing/object"
|
||||
githttp "github.com/go-git/go-git/v6/plumbing/transport/http"
|
||||
)
|
||||
@@ -253,15 +254,93 @@ func (m *Manager) refresh(ctx context.Context, dir, base, branch string) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Reset onto the freshly fetched base. A missing remote base is not
|
||||
// fatal: the branch may exist only locally on a first attempt.
|
||||
// Reset onto the freshly fetched base. This is a prepared clone, so a
|
||||
// missing base is configuration or repository drift and must fail closed.
|
||||
baseHash, err := resolveBase(r, base)
|
||||
if err != nil {
|
||||
return nil //nolint:nilerr // no remote base yet is a normal first-attempt state, not a failure
|
||||
return err
|
||||
}
|
||||
if err := wt.Reset(&git.ResetOptions{Commit: baseHash, Mode: git.HardReset}); err != nil {
|
||||
return fmt.Errorf("reset to %s: %w", remoteBase(base), err)
|
||||
}
|
||||
if err := cleanUntracked(r, dir); err != nil {
|
||||
return fmt.Errorf("clean abandoned worktree files: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func cleanUntracked(r *git.Repository, dir string) error {
|
||||
head, err := r.Head()
|
||||
if err != nil {
|
||||
return fmt.Errorf("resolve HEAD: %w", err)
|
||||
}
|
||||
commit, err := r.CommitObject(head.Hash())
|
||||
if err != nil {
|
||||
return fmt.Errorf("load HEAD commit: %w", err)
|
||||
}
|
||||
tree, err := commit.Tree()
|
||||
if err != nil {
|
||||
return fmt.Errorf("load HEAD tree: %w", err)
|
||||
}
|
||||
files := make(map[string]struct{})
|
||||
dirs := make(map[string]struct{})
|
||||
opaqueDirs := make(map[string]struct{})
|
||||
if err := collectTrackedPaths(tree, "", files, dirs, opaqueDirs); err != nil {
|
||||
return err
|
||||
}
|
||||
return filepath.WalkDir(dir, func(path string, entry os.DirEntry, walkErr error) error {
|
||||
if walkErr != nil {
|
||||
return walkErr
|
||||
}
|
||||
if path == dir {
|
||||
return nil
|
||||
}
|
||||
rel, err := filepath.Rel(dir, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rel = filepath.ToSlash(rel)
|
||||
if rel == ".git" {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
if entry.IsDir() {
|
||||
if _, ok := opaqueDirs[rel]; ok {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
if _, ok := dirs[rel]; ok {
|
||||
return nil
|
||||
}
|
||||
if err := os.RemoveAll(path); err != nil {
|
||||
return err
|
||||
}
|
||||
return filepath.SkipDir
|
||||
}
|
||||
if _, ok := files[rel]; ok {
|
||||
return nil
|
||||
}
|
||||
return os.Remove(path)
|
||||
})
|
||||
}
|
||||
|
||||
func collectTrackedPaths(tree *object.Tree, prefix string, files, dirs, opaqueDirs map[string]struct{}) error {
|
||||
for _, entry := range tree.Entries {
|
||||
path := filepath.ToSlash(filepath.Join(prefix, entry.Name))
|
||||
switch entry.Mode {
|
||||
case filemode.Dir:
|
||||
dirs[path] = struct{}{}
|
||||
child, err := tree.Tree(entry.Name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("load tracked directory %s: %w", path, err)
|
||||
}
|
||||
if err := collectTrackedPaths(child, path, files, dirs, opaqueDirs); err != nil {
|
||||
return err
|
||||
}
|
||||
case filemode.Submodule:
|
||||
opaqueDirs[path] = struct{}{}
|
||||
default:
|
||||
files[path] = struct{}{}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/go-git/go-git/v6"
|
||||
gitconfig "github.com/go-git/go-git/v6/config"
|
||||
"github.com/go-git/go-git/v6/plumbing"
|
||||
"github.com/go-git/go-git/v6/plumbing/filemode"
|
||||
"github.com/go-git/go-git/v6/plumbing/object"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/container"
|
||||
@@ -198,7 +199,7 @@ func TestPrepareIsIdempotent(t *testing.T) {
|
||||
}
|
||||
// A marker file proves the second call reused the clone instead of
|
||||
// wiping and re-cloning it.
|
||||
marker := filepath.Join(dir1, "reuse-marker")
|
||||
marker := filepath.Join(dir1, ".git", "reuse-marker")
|
||||
if err := os.WriteFile(marker, nil, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -232,6 +233,30 @@ func TestPrepareIsIdempotent(t *testing.T) {
|
||||
func TestPrepareRecoversFromADirtyWorktreeOnRetry(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
host := newLocalRemote(t, "acme", "todo")
|
||||
seedDir := filepath.Join(t.TempDir(), "ignore-seed")
|
||||
seedRepo, err := git.PlainClone(seedDir, &git.CloneOptions{URL: filepath.Join(host, "acme", "todo.git")})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeSeedCommit(t, seedRepo, seedDir, ".gitignore", "bin/\n", "chore: ignore build output")
|
||||
if err := os.Symlink("README.md", filepath.Join(seedDir, "readme-link")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
seedWorktree, err := seedRepo.Worktree()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := seedWorktree.Add("readme-link"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sig := testSignature()
|
||||
if _, err := seedWorktree.Commit("chore: add tracked symlink", &git.CommitOptions{Author: sig, Committer: sig}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
baseRef := plumbing.NewBranchReferenceName(testBase)
|
||||
if err := seedRepo.Push(&git.PushOptions{RemoteName: git.DefaultRemoteName, RefSpecs: []gitconfig.RefSpec{gitconfig.RefSpec(baseRef + ":" + baseRef)}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m := newManager(t, host)
|
||||
|
||||
dir, branch, err := m.Prepare(ctx, "acme", "todo", testBase, 9, "fix: retry robustness", "", "bug")
|
||||
@@ -247,6 +272,12 @@ func TestPrepareRecoversFromADirtyWorktreeOnRetry(t *testing.T) {
|
||||
if err := os.WriteFile(filepath.Join(dir, "scratch.txt"), []byte("uncommitted new file\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Join(dir, "bin"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "bin", "stale"), []byte("ignored output\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
dir2, branch2, err := m.Prepare(ctx, "acme", "todo", testBase, 9, "fix: retry robustness", "", "bug")
|
||||
if err != nil {
|
||||
@@ -256,12 +287,9 @@ func TestPrepareRecoversFromADirtyWorktreeOnRetry(t *testing.T) {
|
||||
t.Errorf("retry Prepare() = (%q, %q), want the same (%q, %q)", dir2, branch2, dir, branch)
|
||||
}
|
||||
|
||||
// refresh hard-resets to base immediately after checkout succeeds, so
|
||||
// the tracked file's uncommitted edit must be gone -- restored to
|
||||
// base, not merged in. (An untracked leftover like scratch.txt is real
|
||||
// git's job for `git clean`, not `reset --hard`, and is harmless here:
|
||||
// it doesn't block the retry, which is the only thing this test cares
|
||||
// about.)
|
||||
// Retry starts from the base commit: neither tracked edits nor untracked
|
||||
// output abandoned by the previous attempt may survive into the commit
|
||||
// that CommitAll will publish for this attempt.
|
||||
content, err := os.ReadFile(filepath.Join(dir, "README.md"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -269,6 +297,53 @@ func TestPrepareRecoversFromADirtyWorktreeOnRetry(t *testing.T) {
|
||||
if string(content) != "seed\n" {
|
||||
t.Errorf("README.md = %q, want the base commit's content restored", content)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(dir, "scratch.txt")); !os.IsNotExist(err) {
|
||||
t.Fatalf("abandoned untracked file survived retry: %v", err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(dir, "bin", "stale")); !os.IsNotExist(err) {
|
||||
t.Fatalf("ignored abandoned file survived retry: %v", err)
|
||||
}
|
||||
if target, err := os.Readlink(filepath.Join(dir, "readme-link")); err != nil || target != "README.md" {
|
||||
t.Fatalf("tracked symlink = (%q, %v), want README.md", target, err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(dir, preparedSentinel)); err != nil {
|
||||
t.Fatalf("retry removed prepared sentinel: %v", err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "intended.txt"), []byte("new attempt\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if changed, err := m.CommitAll(ctx, dir, "feat: intended retry change"); err != nil || !changed {
|
||||
t.Fatalf("CommitAll() = (%v, %v), want a commit", changed, err)
|
||||
}
|
||||
files, err := m.ChangedFiles(ctx, dir, testBase)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(files) != 1 || files[0] != "intended.txt" {
|
||||
t.Fatalf("ChangedFiles() = %v, want only intended.txt", files)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCollectTrackedPathsClassifiesGitEntries(t *testing.T) {
|
||||
files := make(map[string]struct{})
|
||||
dirs := make(map[string]struct{})
|
||||
opaque := make(map[string]struct{})
|
||||
tree := &object.Tree{Entries: []object.TreeEntry{
|
||||
{Name: "file", Mode: filemode.Regular},
|
||||
{Name: "link", Mode: filemode.Symlink},
|
||||
{Name: "dependency", Mode: filemode.Submodule},
|
||||
}}
|
||||
if err := collectTrackedPaths(tree, "", files, dirs, opaque); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, name := range []string{"file", "link"} {
|
||||
if _, ok := files[name]; !ok {
|
||||
t.Errorf("tracked file %q was not classified", name)
|
||||
}
|
||||
}
|
||||
if _, ok := opaque["dependency"]; !ok {
|
||||
t.Error("submodule was not classified as an opaque directory")
|
||||
}
|
||||
}
|
||||
|
||||
// An interrupted clone leaves a directory with no sentinel. Prepare must
|
||||
@@ -323,6 +398,18 @@ func TestPrepareErrors(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrepareRefreshRejectsUnknownBase(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
host := newLocalRemote(t, "acme", "todo")
|
||||
m := newManager(t, host)
|
||||
if _, _, err := m.Prepare(ctx, "acme", "todo", testBase, 12, "fix: base", "", "bug"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, _, err := m.Prepare(ctx, "acme", "todo", "missing-base", 12, "fix: base", "", "bug"); err == nil {
|
||||
t.Fatal("prepared worktree accepted an unknown base")
|
||||
}
|
||||
}
|
||||
|
||||
// Every read-only operation must report a clear error on a directory that
|
||||
// is not a repository, rather than panicking or returning a zero value
|
||||
// that reads as "no changes".
|
||||
@@ -564,7 +651,7 @@ func TestPrepareMigratesMatchingLegacyWorktree(t *testing.T) {
|
||||
if err := os.WriteFile(filepath.Join(legacy, preparedSentinel), nil, 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
marker := filepath.Join(legacy, "legacy-marker")
|
||||
marker := filepath.Join(legacy, ".git", "legacy-marker")
|
||||
if err := os.WriteFile(marker, nil, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -576,7 +663,7 @@ func TestPrepareMigratesMatchingLegacyWorktree(t *testing.T) {
|
||||
if dir != m.Dir("acme", "todo", 44) {
|
||||
t.Fatalf("Prepare dir = %q, want %q", dir, m.Dir("acme", "todo", 44))
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(dir, "legacy-marker")); err != nil {
|
||||
if _, err := os.Stat(filepath.Join(dir, ".git", "legacy-marker")); err != nil {
|
||||
t.Fatalf("legacy worktree was not migrated: %v", err)
|
||||
}
|
||||
if _, err := os.Stat(legacy); !os.IsNotExist(err) {
|
||||
|
||||
Reference in new issue
Block a user