Commit Graph
690 Commits
Author SHA1 Message Date
sam 18c3088b84 merge: park stopped tasks on a detached context (archie-core-0dic) 2026-08-25 01:45:18 +10:00
sam 0b2398f026 feat(telegram): send local files as uploads, not fetchable URLs
The agent could produce a file -- a transcript, a log dump, a screenshot --
and had no way to hand it over. Asked to send one it offered a "download"
link; nothing arrived and it had no signal that anything had failed. The
defect was not that it lied: success and silent non-delivery were
indistinguishable to it.

Three places made a local file undeliverable, and each is fixed here:

  - liveReply.Media skipped any attachment with an empty URL, so a local
    file was dropped before it ever reached a sender.
  - telegramMediaSender built every attachment as models.InputFileString,
    which tells Telegram to FETCH the string as a URL. A host path is not
    fetchable, so the send did nothing while reporting success. It now
    chooses by what the attachment carries: URL -> fetch, Path -> upload
    via models.InputFileUpload over an open file.
  - Nothing let the agent ask for a send at all. New send_file tool
    (internal/tools/sendfile) validates the file and returns a
    MultimodalResult naming it; the turn's channel delivers it.

Meaning changes, called out because the names did not:

  - MediaAttachment gains Path, the alternative to URL. Exactly one is
    meaningful for an outbound send.
  - tools.MultimodalResult.URLs used to mean remote-hosted media only; it
    now means media this result wants delivered, which may be local. JSON
    name unchanged so existing producers keep working.
  - errNoURL is now errNoSource: having neither source, not having no URL,
    is what makes an attachment undeliverable.

Failures are visible at every layer, which is the actual fix. send_file
errors on an absent, irregular, unreadable, oversized or confinement-
refused path, so the model sees it and can report it. The sender checks
Telegram's ceilings (10 MB photos, 50 MB otherwise) before the request and
reports the real size rather than leaving a 400 nobody reads. A delivery
that still fails now appends "could not send <name>" to the reply instead
of an empty link, which read as a delivered file.

Exposing a public URL for local files was explicitly rejected: it trades a
missing feature for a hosting and access-control problem.

send_file resolves paths through builtin.ResolveReadable -- the read tool's
own policy, exported rather than reimplemented -- so sending cannot reach
what reading cannot, whatever [chat] unrestricted_filesystem is set to.
2026-08-25 01:43:15 +10:00
sam fd014f6a7f fix(daemon): detach terminal state transitions and cleanup from cancelled context
When an operator stopped a running task via chat /stop or the dashboard
Stop button, the task's context was cancelled. Container teardown
correctly completed (as Pool.Release detached its context), but terminal
state recording in Daemon.runViaAgent and worktree cleanup in
Daemon.cleanupTerminalTaskWorktree executed using the same cancelled
context. Consequently, SQLite transactions in store.Transition failed
immediately and errors were discarded, leaving the task row in 'running'
indefinitely until a daemon restart.

Extract parkRunningTask in internal/daemon/daemon.go to perform guarded
state transitions (store.StatusRunning -> store.StatusParked) using a
detached context (context.WithoutCancel) with a bounded 10-second timeout.
Update cleanupTerminalTaskWorktree to also use a detached 10-second
context for looking up the task status. Check transition errors and log
warnings for unexpected database failures while suppressing expected
ErrStaleTransition returns when workers have already completed. Add
comprehensive table-driven regression tests covering task cancellation,
worktree cleanup, and logging behavior.
2026-08-25 01:42:54 +10:00
sam bb1ab9682f chore(beads): sync h019.3/.4 requirement updates 2026-08-25 00:57:46 +10:00
sam 64be0e7ec0 docs(prds): decide reviewer isolation via agent.Subagent, fail-closed
Section 1 of the adversarial self-review decision was superseded on
2026-08-24: it assumed daemon-owned in-process execution and a daemon-side
second Pool.Acquire, both removed by archie-core-q15y. It is now re-decided
rather than merely marked dead, so the document is Active again.

The reviewer is an agent.Subagent run from inside the task-scoped worker.
ai-sdk v0.1.22 is already pinned, so this needs no SDK bump, and it adds no
host executor, no second container acquire and no nested container lifecycle
-- the open question the supersession left.

Subagent.Run passes Prompt and never populates Messages, so conversation
isolation is a construction fact rather than prompt text. It does NOT give
filesystem isolation: the sub-agent shares the parent's process, working
directory and credentials, so the .git-stripped snapshot survives from the
original design and is load-bearing, and the reviewer's toolset must be
read-only, rooted at the snapshot, and must exclude the worktreerpc
publication grant -- otherwise a reviewer could push the branch it exists to
block. Run() not Tool(), so the implementer cannot elect to review itself.
Findings return through a closure-captured tool because Run yields only text,
and are read even when Run errors, since captured findings survive.

Also decides fail-closed: a review that fails to RUN parks the task rather
than opening an unreviewed PR. ReviewEnabled is opt-in, so an operator who
turned the gate on wants the gate. This is why h019.2 models "ran and found
nothing" separately from "did not run" -- collapsing them would make an
outage indistinguishable from a clean review.

h019.3 is unblocked and rewritten with the construction rules. h019.4's
description said the task parks as waiting_human, contradicting section 4's
decision of StatusParked; corrected, and the fail-closed rule added.
2026-08-25 00:56:10 +10:00
sam dc5b062d1f chore(release): archied v1.15.0
deploy / gate (push) Failing after 3m33s
deploy / build-and-push (push) Skipped
2026-08-24 23:27:33 +10:00
sam cb85374631 chore(beads): close h019.2 findings contract 2026-08-24 19:15:56 +10:00
sam 954228e909 merge: adversarial-review findings contract for archie-core-h019.2 2026-08-24 19:10:18 +10:00
sam 0c0bdda4ad chore(beads): claim h019.2 and record h019.3 redesign blocker 2026-08-24 19:10:18 +10:00
sam 20a8df2bbb fix(workflow): remove duplicate package doc and consolidate ReviewBlocking
Delete the redundant package doc comment from review_findings.go to preserve
workflow.go as the single canonical package comment, and consolidate the
package-level decision function to a single ReviewBlocking export mirroring
gate.Blocking.
2026-08-24 19:08:46 +10:00
sam 708030845b feat(workflow): define adversarial-review findings contract
Define the ReviewFinding and ReviewReport domain types, enums (verdict,
level, category, disposition, status), and pure decision functions for
adversarial review stages.

Enforces the load-bearing rule that only confirmed error findings may
block workflow execution; plausible findings, regardless of severity,
never block. Explicitly models the distinction between an unexecuted
review stage (ReviewStatusNotRun) and one that completed with zero
findings (ReviewStatusCompleted), ensuring data boundaries across JSON
are robust and unambiguous.
2026-08-24 19:04:26 +10:00
sam a425ccb37f chore(beads): close 1ysw epic and its four remaining children 2026-08-24 18:17:41 +10:00
sam 001664ff20 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 d649463695 merge: terminal no-change worktree cleanup for archie-core-1ysw.7 2026-08-24 18:06:18 +10:00
sam 56cc83e215 merge: worktree repairs for archie-core-1ysw.6/.8/.9 2026-08-24 18:06:18 +10:00
sam f1c10bddd4 chore(beads): claim 1ysw.6-.9 for implementation 2026-08-24 18:06:17 +10:00
sam fa7b70225a fix(daemon): clean worktrees on terminal no-change task completion
Tasks completing with BuildNoChanges transitioned directly to StatusMerged
without opening a pull request, bypassing the only production worktree
cleanup path inside reconcilePRs (which only queries StatusPROpen tasks).
As a result, every no-change task leaked a full git clone on disk.

Clean up the identity-correct worktree on terminal non-PR completions:
- In daemon.process, invoke cleanupTerminalTaskWorktree using the task's
  identity-resolved worktree manager when the task reaches a terminal
  status (Merged/Rejected/ClosedWontDo) with PRNumber == 0.
- Ensure parked tasks and open-PR tasks retain their worktrees for
  post-mortem triage and PR reconciliation respectively.
- Add lifecycle regression tests in internal/daemon/terminal_cleanup_test.go.
2026-08-24 18:04:43 +10:00
sam 1c8eb1b43b fix(worktree): remove dead body parameter and wire branchPrefix to archieBranch 2026-08-24 18:01:09 +10:00
sam 7d5a48529c 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 c2695e10d0 chore(beads): reconcile tracker with GitHub via bd github sync
Converged the export after bd github sync resolved the remaining content
drift. beads and GitHub now agree on all 561 issues.
2026-08-24 17:32:33 +10:00
sam 51cafe30f0 chore(beads): restore closures lost in DB recovery and align GitHub
The beads DB rebuild that left .beads.backup-pre-recovery/ reverted every
closure recorded after its backup point. The code was never lost, only the
tracker state, so 16 issues sat open against work that had already shipped.

Restored those 16 from .beads/interactions.jsonl, taking the last status
change per issue and keeping each original close reason verbatim. Closed a
further 12 after verifying the work on main: the whole q15y epic
(1b7bc00, cc6b093, 5d00ec7, 972fb5b), mzok, bia3, hqst, and 1ysw.1/.2/.4/.5.
Superseded two orphaned re-imports of t2db.3 and t2db.5.

Rewrote the four surviving 1ysw descriptions with verified reproductions;
1ysw.9 in particular claimed a checked-in FIXME that no longer exists.

GitHub is now 561/561 in agreement with beads. dfck's close reason said its
opt-in lived in InProcessRunner, which q15y.3 deleted; the mechanism moved to
agentexec.NewLoopRunner (loop_runner.go:106) and the reason now records that.
tb3a's said its worktree was left uncommitted; it merged as 1e5e1fb (PR #477).
2026-08-24 17:23:17 +10:00
sam 8174f6a8c6 refactor: go fix modernisation of stream.go 2026-08-24 14:56:57 +10:00
sam 972fb5b8e1 feat(deployment): default to managed NATS workers
Autonomous workflows now always hand a complete task to a scoped archie-agent container. Embedded NATS is the default and external NATS changes only broker placement; legacy agent and containers.enabled inputs decode for migration but cannot select an execution path. The daemon flushes task-event subscriptions before a worker can publish, and runtime updates snapshot and restore the configured worker image.
2026-08-24 14:56:57 +10:00
sam 5d00ec7b0c refactor(agentexec): remove legacy execution paths
Autonomous workflows now have exactly one production boundary: a task-scoped archie-agent receives a full-task core-NATS request and runs the worker-local stage loop. The legacy [agent] section remains decode-only for migration; it no longer selects runtime behavior.
2026-08-24 14:56:57 +10:00
sam cc6b093820 fix(daemon): require full-task worker handoff
Autonomous tasks no longer execute workflow stages inside archied; missing worker capability parks before worktree preparation.

A transition to parked now atomically makes its detail the task park reason, so daemon-side failures remain visible in task APIs and the dashboard.
2026-08-24 14:56:57 +10:00
sam 1b7bc004b6 feat(nats): expose embedded broker to managed workers 2026-08-24 14:56:57 +10:00
sam 7b5dca3c42 fix(agentexec): recover omitted finish calls 2026-08-24 14:56:56 +10:00
sam ab99f9acda Merge pull request #615 from samcharles93/worktree-shimmering-churning-lobster
fix(worktree): clean untracked files when .git is a gitdir file
2026-08-24 14:54:32 +10:00
sam eb12a02442 Merge pull request #614 from samcharles93/feat/275-ticker-engine
Feat/275 ticker engine
2026-08-24 14:37:21 +10:00
sam c460a80c11 chore(gateway): apply go fix rewrites in stream.go
Pre-existing code `task fmt` rewrites on every run: a manual clamp to
`max`, and a `strings.Split` range to `strings.SplitSeq`. Both are
semantically identical; committing them keeps the gate from reporting a
dirty tree on unrelated work.
2026-08-24 13:28:51 +10:00
sam 0cb8374269 feat(scheduling): ticker engine with configurable interval and pools
Adds internal/domain/scheduling, the timing half of the cron/scheduling
epic (archie-core-1786637496320-249-be6d9a20): a tick loop that asks a
JobSource what is due at a configurable cadence and dispatches each due
job to the pool it declares.

The package owns *when* a scheduled job runs and nothing else. The job
store, blueprints and delivery routing are separate issues in that epic,
so the engine declares the two contracts it needs from them (JobSource,
Runner) and names no implementation. That is what lets the timing
behaviour be tested against a fake clock with no store, no NATS and no
model.

Behaviour worth stating explicitly, because each is load-bearing:

- The source is authoritative about what is due. The engine applies no
  schedule arithmetic of its own, so cron expressions, fixed intervals
  and catch-up windows stay the store's decision.
- A job never overlaps itself. While a run is queued or in flight, later
  ticks reporting the same ID are skipped rather than stacked, so a job
  slower than the interval runs back-to-back instead of fanning out.
- The pools do not interfere: a blocked sequential job cannot delay a
  parallel one, and a saturated parallel cap cannot delay the sequential
  worker. They share only the tick.
- An empty Pool means sequential, not parallel. Wrongly serialising a
  job costs latency; wrongly parallelising one costs correctness.
- Every failure is contained and reported: source error, job error, job
  panic and job timeout each emit an event and leave the loop running.
- Stop drains gracefully. Run contexts descend from Background rather
  than the loop context, so halting the loop stops new work without
  yanking the context out from under a run already in progress; the
  caller's deadline is what eventually cancels those.
- An engine is single-use. Restarting after Stop is refused because Stop
  leaves the dropped backlog and the claims of runs it did not wait for
  behind, and a restart would re-run stale queued jobs while permanently
  suppressing the claimed ones.

internal/events gains job_run/job_error: a scheduled run has no task and
no chat turn behind it, so without those kinds a job that fired, stalled
or failed is invisible everywhere.
2026-08-24 13:28:45 +10:00
sam 799116c32e 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 f5f819e9c1 fix(telegram): corrected tool outputs to keep context of tool calls (#609) 2026-08-24 07:46:42 +10:00
sam a08891f150 chore(release): archied v1.14.0
deploy / gate (push) Failing after 2m38s
deploy / build-and-push (push) Skipped
2026-08-23 16:47:28 +00:00
sam 37efbb1264 Merge pull request #608 from samcharles93/fix/604-telegram-tool-output-pipeline
fix(telegram): compact tool output and drop turn caps
2026-08-24 02:45:43 +10:00
sam 691e10c251 fix(telegram): compact tool output and drop turn caps
Render completed ToolCallEvents as Telegram-safe streaming blocks
with compact name/status and a short cleaned preview. Summarize
file contents and listings instead of dumping source or quoted
JSON. Collapse repeated legacy turn-budget failures.

Remove max_tokens turn gating and the 200000 turn_budget_chars
default so absent or commented config cannot restore an aggregate
cap. Keep per-result max_result_chars and spill.

Confine find/grep discovery to the active workspace/worktree.

Refs #604
2026-08-23 16:40:16 +00:00
sam d2e7b24cc3 Merge pull request #607 from samcharles93/fix/component-aware-updates
fix(update): install only approved components
2026-08-24 02:31:22 +10:00
sam 5c6d4f4031 fix(update): pin builds to approved release tags
Build selected components from a temporary worktree at the exact approved tag commit instead of the moving branch tip. Validate release version inputs and require combined component tags to resolve to the same source commit.\n\nRefs #606
2026-08-23 16:28:30 +00:00
sam ac404a8c7a fix(update): install only approved components
Carry the revalidated update snapshot through the installer contract so the shell adapter receives an explicit per-component plan. Build, back up, install, and roll back only selected components, and pass the runtime release version into agent image builds.\n\nCovers gateway-only, runtime-only, combined, and no-op updates.\n\nRefs #606\nBead: archie-core-462t
2026-08-23 16:18:30 +00:00
sam 7b0321195d chore(release): archied v1.13.0
deploy / gate (push) Failing after 3m39s
deploy / build-and-push (push) Skipped
2026-08-23 15:49:43 +00:00
sam 73a83a133b chore: apply gofumpt formatting 2026-08-23 15:49:40 +00:00
sam ef6290d9e4 Merge pull request #605 from samcharles93/fix/telegram-tool-progress-project-context
fix: make Telegram tool progress readable and bounded
2026-08-24 01:46:01 +10:00
sam 5d4589c6f7 chore(beads): record tool progress UX task 2026-08-23 15:35:20 +00:00
sam 49e49f364d fix(telegram): render tool progress as bounded code blocks 2026-08-23 15:34:38 +00:00
sam 271e03d820 fix(scripts): replace archie-update-check with carina's real production version
The version committed in the previous commit was authored blind,
without knowing a real archie-update-check already existed and has
been running on carina (production) since Aug 9 -- just never
committed to the repo. That live version is better designed than what
I wrote: it introspects the actually-running binary via `archied
-version` rather than trusting git/filesystem state that could have
silently diverged from what's really installed, and uses `git
ls-remote` for the available version instead of a local fetch, so the
script has no side effects and no dependency on the checkout being a
buildable Go workspace.

Adopt it as the canonical version, with one real fix: it used
Component IDs "archied"/"archie-agent", which don't match
releaseupdate.ComponentDaemon="daemon"/ComponentAgent="agent" --  the
same convention archie-update-watchdog's report and this session's
Service.Enrich already use. Under the old IDs, neither ever actually
applied to carina's real update checks; the mismatch was silent since
an unrecognised component ID just leaves InstallType/Reference/
Verify() unset rather than erroring.
2026-08-24 00:45:38 +10:00
sam e37f409b5f fix(scripts): also refresh archie-update-check on every /update
Install only refreshed itself and the watchdog from the freshly
pulled checkout, so a bootstrapped archie-update-check would never
pick up a later fix to itself the way the other two adapters do.
2026-08-24 00:32:54 +10:00
sam 86faa6965d docs+scripts: add archie-update-check, document missing config sections
The check-side of the reference update adapter never existed:
scripts/ had archie-update-install and archie-update-watchdog but no
archie-update-check, so any deployment that configured
chat.telegram.update_check_command pointing at the documented
"/usr/local/bin/archie-update-check" path had nothing there to run --
/update would report "not configured" regardless of what was actually
set. Add it: read-only, reports the daemon/agent components via git
describe against the local checkout and origin/main (no fetch-and-pull
the way install does), using the same "daemon"/"agent" component IDs
archie-update-watchdog's report and releaseupdate.ComponentDaemon/
ComponentAgent already use, so Service.Enrich and Report.Verify (this
session's earlier work) recognise it automatically.

Also fix archie-update-install's archie-agent build: it stamped
archied's ldflags but built archie-agent with none at all, so even a
native (non-container) archie-agent install reported an unstamped
"dev" build with installtype.Unknown.

config.example.toml gained every section that existed in the Go schema
but wasn't documented anywhere, not even commented: skills_dir,
plugin_dir, [chat.email], [chat].webhook_addr, [log], [memory] (noted
as currently unwired -- RegisterExternal is declared but never called
from cmd/archied, so the section has no effect yet), [[identities]]
(pointer to docs/architecture/identity.md rather than duplicating it),
and [[repos]].max_retries. tools.tool_policy.parallel_execution was
deliberately left undocumented: it's declared on ToolPolicy but never
read anywhere, genuinely dead rather than just underdocumented.
2026-08-24 00:32:37 +10:00
sam e736910ab3 docs: add RELEASING.md, stop asking whether to skip an untouched component
Every release session asked the same question and got the same
answer: archie-agent has no unreleased changes touching its own
package closure, so skip it. Codify the rule instead of asking each
time -- only version a component with actual unreleased commits in
its closure, don't bundle an unrelated backlog into an unrelated
release just because it's "due", and don't ask when the answer is
mechanically decided by tools/release.sh's own dependency check.

CLAUDE.md's Release process section pointed to duplicated instructions;
replaced with a pointer to RELEASING.md so there's one source of truth.
2026-08-23 23:40:45 +10:00
sam 24dc40e370 chore(release): archied v1.12.0
deploy / gate (push) Failing after 2m26s
deploy / build-and-push (push) Skipped
2026-08-23 23:39:22 +10:00
sam 618e4c6dd1 chore(beads): sync interaction log 2026-08-23 23:38:55 +10:00