Commit Graph
737 Commits
Author SHA1 Message Date
sam b2da85ead1 refactor: go modernisation fixes 2026-08-29 00:20:05 +10:00
sam 8e4923991d chore: bump ai-sdk version. 2026-08-29 00:17:16 +10:00
sam 0af19ba983 refactor: remove unnecessary AI shit 2026-08-29 00:16:43 +10:00
sam 212f762021 fix: go.mod bumped to 1.27.0 and stupid tests removed 2026-08-28 23:44:41 +10:00
sam 7b0f745fb1 chore: fix CLAUDE.md to flow and remove contradictions. 2026-08-28 23:06:17 +10:00
sam 17ea3c4807 chore: beads interactions and issues 2026-08-28 22:28:49 +10:00
sam 37f7408474 feat(cronstore): durable job store with cross-process locking
Slice 1 of the cron/scheduling epic (archie-core-1786637496320-249-be6d9a20).
Implements the file-backed job store the scheduling ticker engine polls
through scheduling.JobSource. The engine applies no schedule arithmetic
of its own, so the store owns cron expressions, fixed intervals, and
catch-up windows — Slice 1 ships Interval fully, with Once accepted at
Create/fired at Due, and Cron reserved as a wire shape for Slice 2.

Files: per-profile JSON at <path>/jobs.json with a version-stamped
schema. CRUD by job id with merge-semantic Update (nil Patch fields are
preserved). Truncated/partial-write files return ErrCorruptFile; forward
schema versions return ErrUnsupportedSchema. DisallowUnknownFields means
additive shape changes must bump schemaVersion.

Concurrency: three locks stack in fixed order. (1) A package-level
mutex keyed by lock-file path serialises Stores within one process —
Linux flock is per file description, so two Store instances in the
same process have independent fds and would otherwise proceed in
parallel. (2) Cross-process flock serialises Stores across processes
(CLI vs daemon). (3) s.mu guards the in-memory mirror. Every
operation re-hydrates from disk before applying its change so a writer
that just acquired the locks sees every change the previous writer
committed. Atomic write via temp-file + rename + fsync for durability.

Validation: Create and Update validate Pool, Schedule, and required
fields up front so a hand-edited file cannot persist a job the engine
cannot reason about. MarkRun on a kind without next-run arithmetic
returns ErrScheduleUnsupported. Get/List return deep copies so caller
mutation cannot corrupt the in-memory mirror. Files are written 0o600
because payloads can carry operator-identifying data; SetEscapeHTML(false)
keeps operator-readable files human-friendly.
2026-08-28 22:28:49 +10:00
sam b5ca9c8867 chore: update issue tracker, remove ai-sdk ADR 2026-08-28 22:28:49 +10:00
sam 5a4c10fb07 fix(middleware): remove off-by-one tail call in retry streaming paths
ChatStream and StreamObject were issuing one extra unscheduled provider
call after MaxAttempts was exhausted, billing MaxAttempts+1 calls instead
of MaxAttempts on permanent-failure retries. Capture the last stream/err
across iterations and return them after the loop instead.

Adds middleware/retry_test.go with exact call-count assertions for all
four retry paths (Chat, ChatStream, GenerateObject, StreamObject),
MaxAttempts=1 short-circuit, non-retryable short-circuit, success-after-
retries, and ctx-cancellation paths.

Refs ai-sdk-5jb.1
2026-08-28 22:28:48 +10:00
sam 8120dc0760 feat(curator): track and expose recent activity per curator
Add a small bounded activity tracker (activityTracker, in
internal/domain/curator/activity.go) fed directly from the runtime's
existing emitRun point: last-run time, last-run action count, and up to
20 recent actions per curator, newest first. No persistence layer -- it
resets on restart, same as the rest of the runtime's in-memory state.
Registry.RecordActivity/Activity expose it.

Closes archie-core-1786637489932-6-1f803e02.
2026-08-28 22:28:48 +10:00
sam a84085c89e fix(telegram): drop retry_after bandaid, bump go-telegram/bot to v1.24.0
go-telegram/bot v1.24.0 fixes getUpdates to honour Telegram's retry_after
on a 429 instead of its own 100ms-doubling-to-5s backoff (release notes:
https://github.com/go-telegram/bot/releases/tag/v1.24.0). pipelineErrorHandler
was our workaround for that upstream gap -- it now just logs.
2026-08-28 22:28:43 +10:00
sam 99a989725f docs: record ai-sdk to goai migration decision 2026-08-28 22:28:26 +10:00
sam ea1017af94 feat(webui): dashboard-aware chat — Archie sees the page, points you there
The web chat is now a persistent slide-over drawer available on any page
(not just the /chat route), and the agent is told which dashboard page the
operator is on so it can point them to the relevant page with a clickable chip.

Backend (gateway):
- Message gains a per-message Page field; the system prompt renders it in
  the <env> block (Current page), so Archie knows where the operator is.
- New dashboard_tools.go: a DashboardPages registry plus two web-only tools
  — page_index (lists every page and what it shows) and dashboard_navigate
  (validates a path, returns {path,label}; rejects unknown/empty paths).
- The web chat sink emits a dedicated navigate stream event when the model
  calls dashboard_navigate, independent of ShowToolCalls.

Frontend (webui):
- chat sends currentPage() (location.hash) with each stream request; a
  dashboard_navigate result renders as a clickable link chip (href=#/path).
- The chat is mounted once in a slide-over drawer with a topbar launcher,
  scrim and Esc-to-close; /chat opens the drawer instead of a second page.
- ui/dist rebuilt (committed) with the bundled changes.
- .gitignore: ignore .impeccable/ (impeccable tool critique snapshots).

New capability (per scope discipline): designed in
docs/prds/dashboard-aware-chat-navigation.md.

Tests: dashboard_tools_test (registry, resolve/reject, web-only gating),
prompt page-line cases, webui Message.Page + navigate-frame capture, and
chat-tools chip tests. task check is green.
2026-08-28 22:28:10 +10:00
sam 3ffc4df8d6 chore(release): archied v1.19.4 2026-08-28 01:42:27 +00:00
sam 47b17833cd refactor(telegram): render replies as structured rich blocks
Telegram's rich-message Markdown has no ATX heading support and its MarkdownV2
dialect needs escaping, so hand-building a Markdown string and sending it as
myMarkdown showed literal heading/code markers and mangled unescaped characters.
The previous fix layered blank-line insertion on top of a dialect that could
not render headings at all.

Replace the whole markdown-string pipeline with structured InputRichMessage
blocks: markdownToBlocks emits SectionHeading, Preformatted, List, BlockQuotation
and Paragraph (inline emphasis/code/links reduced to plain text so no marker can
leak), blocksToPlainText feeds the fallback send, and splitBlocks chunks at block
boundaries. sendBlocks, open, edit and the live renderer now send myBlocks.

Delete the dead string surgery (normalizeTelegramText, telegramMarkdown,
telegramPlainText, splitLongMessage, the fence-split cluster and their regexes)
and the tests that pinned it, removing about 1100 lines. splitBlocks and the
parser are unit-tested.
2026-08-28 01:42:09 +00:00
sam 2652d2d1ea chore(release): archied v1.19.3 2026-08-28 00:55:33 +00:00
sam c026ada077 feat(dashboard): render task actions, statuses and filters from the server catalog
Three surfaces stopped keeping hand-synced copies of the lifecycle vocabulary,
so a status or action added on the backend shows up without a frontend change:

- task actions render label/variant/confirm from taskstate.ActionCatalog via
  actionFor(); unknown actions no longer vanish behind a hardcoded switch and
  a new action needs no frontend case
- status labels and pill severities come from taskstate.Statuses via
  statusLabel()/statusKind(); the local copy and the dom.js switch are gone
- the status filter vocabulary and the "needs you" grouping derive from
  statusIds()/attentionStatusIds(); a new status appears in the filter and in
  the settings page's Work lifecycle card, driven by /api/task-meta

Regenerated ui/dist so the embedded binary ships the new dashboard.
2026-08-28 00:55:17 +00:00
sam 815272a421 feat(tasks): serve the lifecycle presentation catalog from /api/task-meta
Archie owns the status and action vocabulary in internal/taskstate, but the
dashboard had to keep a hand-synced copy of the display labels, pill severities
and action confirm prompts -- so a new status or action silently rendered
wrong until someone edited the frontend.

- add taskstate.Statuses() and taskstate.ActionCatalog() so the rules and their
  presentation live in one place
- expose GET /api/task-meta returning {statuses, actions}
- add a client base/task-meta.js that fetches the catalog and exposes
  statusLabel/statusKind/statusIds/attentionStatusIds/actionFor, with a
  freeze-dried default snapshot so the dashboard renders instantly and keeps
  working when archied is unreachable
- tests for the catalog, the endpoint and the client accessors
2026-08-28 00:41:12 +00:00
sam 42b7eed622 chore(release): archied v1.19.2 2026-08-28 00:19:45 +00:00
sam 96c82cd4e0 feat(tasks): allow rejecting a task from any non-terminal state
An operator could only reject work that was waiting on a human decision, so a
task sitting in review (PR open) or running had no way to be refused even
when it was clearly dangerous.

- expose reject in taskstate.Actions for every non-terminal state (queued,
  running, waiting_human, parked, pr_open) so both the dashboard and the chat
  tool surface it; terminal states still only expose archive
- make rejectTask transition from the task's actual status to closed_wont_do
  and interrupt running execution first, so nothing keeps working against a
  task being closed out
- keep the distinct stop (recoverable → parked) semantics; reject is the
  terminal escape hatch
- update the lifecycle contract tests to the new intent
2026-08-28 00:19:27 +00:00
sam 8ef6980fe6 chore(release): archied v1.19.1 2026-08-27 23:33:46 +00:00
sam 7520e15778 fix(telegram): keep Markdown headings/lists as blocks and strip Markdown on plain fallback
- insert blank lines around ATX headings and list blocks so Telegram does not
  collapse them into the surrounding paragraph
- leave the SDK's compact triple-backtick tool fences unstyled (do not re-space)
- strip Markdown syntax when the rich send/edit falls back to plain, so the
  user never sees raw '#', '**', backticks or link brackets
- log telegramRenderVersion + mode on every outgoing message
2026-08-27 23:33:24 +00:00
sam 79b038a9b5 chore(release): archied v1.19.0 archie v1.18.0 2026-08-27 21:40:38 +00:00
sam 2395254559 build(deps): upgrade github.com/samcharles93/ai-sdk to v0.1.29 2026-08-27 21:40:01 +00:00
sam eaeadc191d chore(beads): close vq92 (task_logs pagination) 2026-08-26 02:02:42 +10:00
sam 48133e68fe feat(logging): cursor pagination and filtering for task_logs
task_logs could only read the newest N entries with no way to walk the
rest, so a task's log beyond the page cap was unreachable and the agent
had no honest way to say what was missing. Add logging.Page -- a
byte-offset cursor over the tail-most 8 MiB scan window -- plus
Query.Since/Until time bounds, and wire the gateway's task_logs tool to
expose level/since/until/after_id with cursor and more_available in the
result.

The reader now reads the scan window into a single in-memory buffer and
walks it by exact slice offsets. Offsets into a contiguous buffer are
trivially correct, which an incremental reader over the file is not:
bufio.Reader buffers ahead, so its underlying file position runs one
buffer past its logical position and cannot be used as a cursor. The
same rewrite removes f.Read in favour of f.ReadAt (full-or-error), since
a silent short read would drop the newest entries and still report
success.

The scan window is a documented hard ceiling: for a log over 8 MiB the
oldest bytes are unreachable by any cursor -- that is what Truncated
reports, and send_file remains the path for a complete archive. The
tool description teaches the model the difference between more_available
(more this call did not return) and truncated (older entries the scan
cap hides).

Closes archie-core-vq92 (#625).
2026-08-26 02:02:36 +10:00
sam 79d810ad13 chore(beads): close shipped production fixes 2026-08-26 01:05:56 +10:00
sam 9c5f29411f chore(beads): record GitHub issue links 2026-08-25 05:57:01 +10:00
sam 2da2561328 chore(release): archied v1.18.0 archie v1.17.0 2026-08-25 05:50:01 +10:00
sam d8478e1a4d chore(beads): record task observability work 2026-08-25 05:49:28 +10:00
sam 4b340d2b56 fix: harden task and chat execution
Task runs now preserve real model context limits, provider usage, baseline-repair spend, commit identity, durable agent-finish telemetry, and useful timeline details without imposing a token cap. Dashboard forge links are canonical per owning GitHub or Gitea identity. Chat turn claims acquire SQLite writer intent before reading, eliminating the concurrent SQLITE_BUSY snapshot race.
2026-08-25 05:48:17 +10:00
sam 1740bd12d8 chore(release): archied v1.17.1 archie v1.16.1 2026-08-25 03:29:11 +10:00
sam 9604a7d602 fix(agentworker): reconcile task clone ownership after commits 2026-08-25 03:28:40 +10:00
sam 9d2c1e661d fix(gateway): make UUIDv7 session references unambiguous 2026-08-25 03:28:38 +10:00
sam a27fb5f36e fix(update): remove source checkout dependency
Dashboard-initiated updates also retain a configured Telegram restart-report route, while falling back to the web UI report when Telegram is unavailable.
2026-08-25 03:28:37 +10:00
sam 24b50192f6 chore(release): archied v1.17.0 2026-08-25 03:06:24 +10:00
sam bb8cd3f687 fix(chat): restore transcript and update replay 2026-08-25 03:05:28 +10:00
sam 4a009e73c5 Merge branch 'crew/proxyfix' 2026-08-25 02:36:56 +10:00
sam 711d62423e fix(webui): add nil receiver guard to Server.trustForwardedHeaders 2026-08-25 02:13:36 +10:00
sam 97be14b809 chore(release): archied v1.16.0 archie v1.16.0 2026-08-25 02:12:44 +10:00
sam b0c9afa0f0 chore(webui): go fix modernises boolPtr to new(value)
task check's go fix pass rewrote the test helper to Go 1.26's generic
new(v) and marked it //go:fix inline. Committed from the gate rather than
left dirty in the tree.
2026-08-25 02:06:37 +10:00
sam 45fbed4228 merge: proxy-aware Origin validation for dashboard mutations (crew/proxyfix) 2026-08-25 02:06:05 +10:00
sam 29efce7049 fix(webui): validate mutation Origin against the effective external scheme
Origin validation compared the request's Origin against the daemon's own
direct connection: scheme from r.TLS, host from r.Host. Behind a TLS-
terminating reverse proxy the browser sends Origin: https://host while the
daemon sees a plain HTTP connection, so every dashboard mutation was
refused as cross-origin.

Taking X-Forwarded-Proto/-Host unconditionally would be worse than the bug:
any client can set them, so an exposed daemon would let an attacker forge
the scheme half of the CSRF check. They are honoured only when
web.trust_forwarded_headers is explicitly enabled, which is off by default
and documented as safe only behind a proxy that overwrites or strips
untrusted forwarded headers.

authorizeTaskMutation becomes a method because the decision now depends on
server configuration; its three call sites move with it.
2026-08-25 02:06:02 +10:00
sam 901864a9df merge: task_action chat tool (crew/taskact) 2026-08-25 02:05:25 +10:00
sam e8df26f6a6 fix(webui,sendfile): close three holes the adversarial review found
Follow-up to e5e0316, which claimed non-delivery is never silent and that
oversized files fail visibly. Both claims had gaps.

chatStreamSink.Media skipped any attachment with an empty URL, exactly as
liveReply.Media used to. The tool registry is shared between the Telegram
and dashboard chat setups, so send_file is offered on the dashboard too:
the model announced a sent file, the sink dropped the event, and nothing
reached the transcript. The dashboard cannot upload at all, so the fix is
to REPORT the file as undeliverable and name where it is on the host,
rather than to stay quiet. The skip was right while media meant a hosted
URL; it stopped being right when a host path could arrive here.

send_file applied one 50MB ceiling to every type while the sender enforces
10MB for photos, so an 11-50MB image passed the early check, was reported
sent, and was rejected by a layer the model cannot see. The early check is
now per-type and mirrors the sender's limits.

MediaType called every image/* an image, but a photo endpoint rejects
image/svg+xml and image/tiff outright. Photo-safe formats are now an
explicit set, so an svg goes as a document and arrives, which is what the
"unrecognised means document" reasoning intended all along.

Also tests the readability probe's own error path (mode 0000), which was
the one case it exists for and the one case not covered; verified it fails
with the probe removed.

Remaining review findings are filed, not fixed: fallback lines appended
after the live reply finalizes are dropped by a stopped renderer
(archie-core-atv2), confinement is symlink-blind and re-opens after
checking (archie-core-jkmu), and concurrent uploads are uncapped
(archie-core-3svc).
2026-08-25 01:55:16 +10:00
sam 51d67a8903 chore(beads): file transcript findings -- logging, log pagination, env block, /status vs /tasks, transcript replay, silent action failures, intercom epic 2026-08-25 01:51:04 +10:00
sam 069977eb17 merge: park stopped tasks on a detached context (archie-core-0dic) 2026-08-25 01:45:18 +10:00
sam e5e0316475 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 09ed7642c0 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 64da3952aa feat(gateway): add task_action chat tool for operator task management
Adds the task_action tool to internal/gateway/task_tools.go and wires it via
chatTaskActorAdapter in cmd/archied. This enables operators in chat to execute
lifecycle actions (abandon, archive, retry, stop, cancel, approve, reject) on
tasks using the same action path and state machine as the dashboard.

Enforces identity scoping so an instance cannot mutate another identity's
tasks, verifies status permissions via internal/taskstate, and classifies the
tool as mutating with required human approval.
2026-08-25 01:19:21 +10:00