Commit Graph
549 Commits
Author SHA1 Message Date
sam a47ca4ec78 refactor(archied): extract config overlay boot helper and thread ctx 2026-08-16 01:38:11 +10:00
sam 4374bfd57c refactor(builtin): split read executor to lower complexity 2026-08-16 01:37:04 +10:00
sam 81a8b9b5e1 style: remove trailing whitespace 2026-08-16 01:28:25 +10:00
sam 2c6a4f9adc fix(tests): check type assertions in overlay and gateway tests 2026-08-16 01:24:31 +10:00
sam 63cff4fe53 refactor: flatten nested config and tool fallback logic 2026-08-16 01:20:48 +10:00
sam 79a4db5362 fix(tools): flatten write overwrite checks 2026-08-16 01:16:22 +10:00
sam fa826fb486 fix(email): use context-aware test networking 2026-08-16 01:10:48 +10:00
sam 4e03cd7c17 test: use t.Context() for helper subprocess 2026-08-16 01:08:47 +10:00
sam 282f67b6b6 fix(tools): document intentional fallback skips 2026-08-15 23:55:21 +10:00
sam f5f57b3097 fix(tests): add contexts to HTTP test requests 2026-08-15 23:43:55 +10:00
sam f112daa1cd fix(tools): avoid predeclared max names 2026-08-15 23:41:44 +10:00
sam cb8c99b978 fix(indexing): remove unused code search test runner 2026-08-15 23:40:23 +10:00
sam 75d07b2168 docs(architecture): document memory engine family 2026-08-15 23:38:34 +10:00
sam 43308c0fc9 chore(release): archied v1.9.4 archie v1.9.4 2026-08-15 23:17:43 +10:00
sam b5064e570f fix(telegram): preserve URL boundaries in responses
Keep bare GitHub issue and pull-request links separate from following prose across one-shot sends, live edits, and long-message splitting. Preserve Markdown delimiters and newline boundaries while retaining plain-text fallbacks.
2026-08-15 23:09:28 +10:00
sam 0dfdd72f83 feat(gateway): polish /status command response format
Format /status response with clear heading, visual task status icons, canonical lifecycle ordering, and separated runtime details with graceful fallbacks.
2026-08-15 22:43:41 +10:00
sam b41ba3dc76 Merge pull request #525 from samcharles93/ratelimit/evict-stale
Ratelimit/evict stale
2026-08-15 22:32:06 +10:00
sam db9544dc53 feat(ratelimit): add window-based stale-entry eviction
EvictStale sweeps the per-key hit map and removes entries whose hits
have all aged out of the sliding window, so a long-lived limiter
driven on a ticker doesn't accumulate one map entry per identity for
the life of the process. The package doc now states the map is
unbounded until something actually calls EvictStale, rather than
claiming it's bounded by a mechanism nothing yet wires up.
2026-08-15 22:25:07 +10:00
sam 963fff7880 docs: add Beads tracker guidance to CLAUDE.md 2026-08-15 14:12:08 +10:00
sam b2e5f69ea3 chore(release): archied v1.9.3 archie v1.9.3 2026-08-15 12:53:52 +10:00
sam 39d8b067ec feat(agentexec,workflow): surface tool calls on the task timeline
archie-core-467 wired tool-call visibility into the interactive chat
gateway, but a workflow task's own transcript never showed what its
tools actually did -- only stage/agent-finish events existed, so
there was no way to confirm an agent's summary matched what it really
ran.

Adds a ToolCallReporter, invoked once per completed call from
toolExecute (the single choke point every tool call passes through
before reaching a model), reported via a new ToolSetOptions.OnToolCall
hook. Runner.Run grows a report parameter to carry it in: InProcessRunner
wires it through, since it executes in the same process as its tools;
SubprocessRunner and NATSRunner accept and ignore it, since their tool
calls happen in a different process with nothing here to observe them.

The workflow engine turns each report into a tool_call event on the
task's own Bus (agent.go, implement.go), riding the same NATS
event-forwarding archie-core-518 already built to get container
events onto the daemon's timeline.

Scoped to the central tool registry (read/write/edit/grep/shell/...)
built via BuildToolSet; capture tools (structured finish output) and
run_go_script build their ToolSet entries directly and are not yet
covered.
2026-08-15 12:53:41 +10:00
sam 8f73c1febb fix(agentworker): back off before refetching a nak'd stage message
On a stage-handle failure, the main loop logged the error, called
Nak (which requests redelivery), and looped straight back into
FetchStage with no delay -- unlike the fetch-error branch three lines
above, which already backs off for a second. A deterministic failure
(a broken gate, a malformed request) therefore refetched and failed
again immediately, flooding the log with one "handle failed" line per
loop iteration instead of per genuine retry -- hundreds of identical
lines within the same second in production.

Adds the same time.Second backoff after Nak.
2026-08-15 12:53:31 +10:00
sam a37f126f79 fix(logging): resolve error attrs to their message string, not {}
SystemLogHandler and FeedHandler both json.Marshal Entry.Fields
directly rather than through slog's own JSON handler, so a logged
`error` value went straight into a map[string]any as the raw
interface. encoding/json has no Error()-aware special case, and the
concrete type behind almost every Go error (errors.errorString,
fmt.wrapError, ...) holds only unexported fields, so it marshalled to
`{}` and silently discarded the message everywhere it was logged --
including on every container/system-log line shipped to the daemon
and shown in the webui, which is where this was actually noticed: a
flood of `"err":{}}` with no way to see what had actually failed.

attrValue now resolves an error attr to its .Error() string before it
reaches the map. It also guards against the classic Go footgun where
a non-nil error interface wraps a nil concrete pointer (var e *T; var
err error = e) -- a naive err != nil check would call Error() on a
nil receiver and crash the one thing that must never crash: logging
itself.
2026-08-15 12:53:24 +10:00
sam 576757170d fix(webui): scroll selected command into view on keyboard navigation
Arrow-key navigation in the chat composer's command menu updated
aria-selected but never scrolled the option into the visible area, so
selecting past the viewport with the keyboard left the highlighted
item hidden. Mouse scrolling already worked since it doesn't rely on
selection state.
2026-08-15 12:05:52 +10:00
sam 9257ec395e chore(release): archied v1.9.2 archie v1.9.2 2026-08-15 11:22:35 +10:00
sam 37792c9ec0 fix(worktree): force checkout so retry recovers from a dirty worktree
refresh checked out the task branch without Force before hard-resetting
to base. A prior attempt's leftover uncommitted changes -- a killed
container, or a stage that edits files before ever reaching a commit --
made go-git's default MergeReset checkout refuse to reconcile them, even
with HEAD already on the correct branch and the target commit unmoved.
The fallback then made it worse: any checkout failure was assumed to
mean the branch didn't exist yet, so it retried with Create: true, which
failed with a much more confusing error since the branch did exist --
"a branch named ... already exists" -- masking the real cause and
parking the retry with the same unhelpful message every time.

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

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

Closes #523
2026-08-15 11:22:22 +10:00
sam 9c2e41c4da chore(release): archied v1.9.1 archie v1.9.1 2026-08-15 10:35:18 +10:00
sam 54be74ae89 feat(releaseupdate): stamp install type at build time, fail closed on unknown
/update could report success at the correct target version while the
archie-agent container running it never actually changed: the update
mechanism trusted the configured installer's exit code and reported
whatever version number the release claimed, with nothing verifying
the two agreed.

The first piece of the fix: a new internal/installtype package
reports how a binary was built for distribution (Type(), defaulting
to "unknown"), stamped once per release artifact via
"-ldflags -X .../installtype.buildType=<value>" rather than guessed
at runtime by probing the environment -- restic and Tailscale both
treat "which install shape is this" as a build-time decision for the
same reason: a probed signal is guessable, a compiled-in one is not.

releaseupdate.Service.Install now refuses to run the configured
Installer at all when InstallType is unset or installtype.Unknown, so
an unstamped or misconfigured build can no longer silently attempt an
update it has no way to know is even the right kind for how this
instance was deployed. Wired through every real archied build path so
the gate doesn't just exist in principle: Taskfile.yml's build task
(binary), Dockerfile.archied (container), and install.sh (binary) all
now stamp it; cmd/archied/telegram_setup.go wires
Service.InstallType from installtype.Type().

Configuration-page display of install type/version and post-update
verification against the actually-running reference (not just the
installer's reported version) remain open -- this lands the
correctness gate, not the full observability surface.

Refs #522
2026-08-15 10:34:46 +10:00
sam a253d3043b fix(webui): filter turn_completed noise from the Live Activity SSE feed
turn_completed fires on every chat turn so input-driven curators can
wake on it, but it carries no task correlation (TaskID always 0,
Detail a raw session ID) -- on the dashboard's "Live activity" panel
this drowned real task-lifecycle events: 27 of the last 30 rows in a
live sample were content-free turn_completed noise.

Excluded at the SSE boundary (sseVisible), not at publish, so
curators reading the Bus directly are unaffected. since still
advances past a filtered event exactly as it would for a sent one --
EventsSince only ever returns events with id > since, so leaving
since behind a filtered event would make the next catchUp refetch it
forever.

Closes #521
2026-08-15 10:34:33 +10:00
sam 9d6a11f491 fix(agentworker): forward workflow events across the NATS worker boundary
A workflow run through the container/NATS path never wired
workflow.TaskContext.Bus, so every tc.Emit call (stage_start,
stage_finish, outcome, parked) was a silent no-op. archied's own
in-process path sets Bus and always worked; anything dispatched to an
archie-agent worker did not, which meant the dashboard's per-task
timeline showed "No events yet" for every task regardless of status
or stage -- confirmed live across a Working task and two differently
parked tasks.

Bridges the gap the same way system logs already cross this boundary:
ForwardTaskEvents relays a per-task in-process *events.Bus to a new
NATS subject (SubjectForEvents), and a new daemon-side subscriber
(subscribeAgentEvents) republishes decoded events on the daemon's own
Bus, landing them in the same persist-and-broadcast pipeline an
in-process workflow already used.

Closes #518
2026-08-15 10:34:25 +10:00
sam e9a029e900 chore(release): archied v1.9.0 archie v1.9.0 2026-08-15 02:25:10 +10:00
sam 8ae23164bb refactor(webui): decompose handleSSE to cut cognitive complexity
handleSSE mixed connection registration, backlog catch-up, and live
broadcast relay into one function with three nested closures --
gocognit flagged it at 52 against a limit of 30. Extracted each
concern into its own top-level piece: sseSince (resume-point
resolution), registerSSEConn (subscribe/unsubscribe), and a new
sseStream type carrying the per-connection state (send, catchUp,
sendPage, drain) that the closures used to capture implicitly.

Behavior is unchanged -- catchUp/sendPage's page-boundary and
target-reached logic is the same control flow the original closure
had, just named and independently testable. handleSSE itself is now
a straight-line sequence of calls.

Added direct unit tests against sendPage/catchUp for the boundary
cases a full HTTP round-trip test doesn't exercise: a target reached
mid-page vs. at a page boundary, a target of zero (drain everything),
a write failure stopping the page immediately, and backlog spanning
more than one EventsSince fetch.
2026-08-15 02:24:43 +10:00
sam 95bb4b5bb6 fix(telegram): use NewRequestWithContext to satisfy noctx
Pre-existing lint finding, unrelated to any behavior change.
2026-08-15 02:19:57 +10:00
sam c2b6823eba fix(telegram): guarantee no message is stranded on gateway stop/restart
A daemon shutdown or /restart cancels turnCtx without any guarantee
that the goroutine owning a liveReply ever runs again to notice and
clean up after itself -- a full process exit gives it no chance at
all. Gateway now tracks every liveReply mid-turn in a registry and
Stop drains it, marking each as interrupted so nothing is left ending
in the "typing" cursor forever.

finalize and abandon now run their bodies inside a per-reply
sync.Once (the terminal field): a turn finishing naturally and a
concurrent Stop draining the same reply were reaching it from two
goroutines at once, both sending their own edit for the same message
with the outcome decided nondeterministically by which HTTP response
Telegram processed last -- including a complete real answer getting
silently overwritten by the restart marker. Only one side's body now
ever runs; the other blocks on the winner and then does nothing.

The drain itself is bounded (liveDrainTimeout, default 5s): a single
stalled Telegram API call must not hang gateway, and therefore
daemon, shutdown indefinitely. Entries still in flight past the
deadline keep running in the background rather than blocking Stop.

A liveReply created in the narrow window between Stop claiming the
registry and its own registration call is abandoned immediately
instead of being registered into (and lost from) a registry nothing
will drain again.

Regression tests cover the mutual-exclusion race directly (20
iterations of finalize and abandonRestarted racing on the same
reply, asserting exactly one outcome ever wins), the bounded drain
against a deliberately hung API call, and the post-stop registration
gap.
2026-08-15 02:19:53 +10:00
sam ddfc8a7b91 fix(config,webui): make show_tool_calls one cross-channel setting
show_tool_calls gated Telegram's tool-activity narration only; the
web dashboard's SSE chat stream narrated every completed tool call
unconditionally with no way to turn it off, leaking tool names and
parameter shapes to anyone with dashboard access even when an
operator had already opted out for Telegram.

Moved ShowToolCalls from TelegramConfig to ChatConfig so it is one
setting for every channel, and wired the webui stream to it:
chatStreamSink now carries a showToolCalls flag (snapshotted once per
turn, mirroring how Telegram's liveReply snapshots it) and ToolCall
no-ops when it's off.

BREAKING: an existing [chat.telegram] show_tool_calls = true in
config.toml now parses as an unrecognized key under [chat.telegram]
and is silently ignored (TOML decoding is non-strict) rather than
erroring -- move it to the top-level [chat] table.
2026-08-15 01:57:06 +10:00
sam c9ae131317 docs(agent): correct markSafe's doc comment to its actual existence check
The comment claimed a mount was checked before touching the
operator's global gitconfig; the code only ever checked os.Stat
(existence + directory-ness). A directory that merely exists at the
mount path -- a stale leftover, never actually bind-mounted this run
-- already satisfied the guard and got added to safe.directory,
exactly what the comment said it prevented. A real mount check would
need platform-specific mountinfo parsing for an inert failure mode
(the entry does nothing unless a git repo later exists at that exact
path), so this corrects the contract to match the code and pins it
with a test instead of changing behavior.
2026-08-15 01:48:39 +10:00
sam b6505f0232 docs(telegram): note the live-edit timestamp trade-off on liveReply
The finished reply is delivered by editing the message created at the
first streamed frame, and editMessageText does not change a
message's date, so a long tool-using turn's answer keeps its
turn-start timestamp and can sort before conversation that produced
it. Delete-and-resend would fix the ordering but reintroduce the
flicker/reorder streaming exists to avoid, so this documents the
accepted trade-off rather than changing behavior.
2026-08-15 01:48:33 +10:00
sam d43416f2fe fix(webui): style tool-call failure from a structured field, not a string prefix
chatStreamEvent gained a Failed bool, set from ToolCallEvent.Err !=
"" -- the field the rest of the codebase already treats as
authoritative -- rather than the browser sniffing summary.startsWith
"failed:" on rendered text. A successful tool whose own output starts
with that literal string (a grep hit, a log line read back) was being
styled as a failed step.
2026-08-15 01:48:29 +10:00
sam ad93ffb9bb chore(release): archied v1.8.0 2026-08-15 01:44:00 +10:00
sam cad3cf745a fix(config): de-duplicate disabled-forge predicate, export ForgeDisabled
cmd/archied carried a copy of the none/off/disabled predicate because the
configuration package's version was unexported. Two copies of a validation
predicate drift: a fourth disabled alias added in one place would silently
leave the other accepting it.

Export ForgeDisabled in internal/infrastructure/configuration as the single
definition, referenced by both validateIdentities and resolveForge, and
delete the duplicated copy. TestForgeDisabled pins the exact alias set
(including case-variant and empty-string guards); the resolveForge
degradation test now asserts on the warn log so the silent disabled path is
distinguishable from the token-unavailable fallback (verified to fail under
a re-inlined 'none'-only copy).
2026-08-15 01:43:31 +10:00
sam baef64163a fix(telegram): keep tool activity visible and mark failed/empty turns
Three more P2s from the same code-review pass: the live frame's
single clamped buffer mixed tool lines and answer text chronologically,
so early tool lines silently scrolled out of the frame once the answer
grew past liveBodyMaxRunes and only reappeared at finalize (which
already led with tools separately). Tool lines are now tracked
exclusively in toolLines; a new framedText helper keeps the tool block
whole and clamps only the answer tail, used consistently by the live
frame, an abandoned frame, and the finished message.

A tool-only turn with no reply text used to finalize as a bare,
immutable tool line indistinguishable from a real (if terse) answer;
finalText now appends an explicit "(no response)" marker in that case.

A provider error used to funnel into the same clean-partial path as a
deliberate /stop, so a failed turn was indistinguishable from a
successful short one. abandonFailed appends a "turn failed" marker
before dropping the cursor; /stop still goes through the unmarked
abandon path.

Regression tests cover all three paths plus the degenerate case where
a tool block alone exceeds the frame budget, verified red-then-green
against the pre-fix code.
2026-08-15 01:25:20 +10:00
sam 240c91a117 fix(telegram): harden live-reply delivery against /stop and multi-byte content
Three P1s from code review of PR #476: finalize sent the authoritative
reply through the same cancellable turnCtx a /stop kills, so a stop
landing mid-finalize stranded the live message with its cursor
forever; abandon had the identical hazard, saved only by its one
caller wrapping the context correctly. Both now strip cancellation
internally (context.WithoutCancel) rather than trusting callers to
remember.

Tool activity lines were composed unescaped into the same Markdown
body as the model's own reply, so a stray '*', '_', or backtick in
tool output/parameters could unbalance the whole message and take the
reply's formatting down with it. ToolCall now runs name, parameters,
and summary through bot.EscapeMarkdown before joining the line.

splitLongMessage sliced oversized lines on byte offsets, cutting
mid-rune for any multi-byte UTF-8 line crossing the 4000-byte bound
(CJK, emoji) and producing invalid UTF-8 parts. It now counts and
slices on runes throughout.

Regression tests cover all four paths, verified red-then-green
against the pre-fix code.
2026-08-15 01:06:27 +10:00
sam 932625da96 Merge pull request #481 from samcharles93/chore/stop-tracking-beads-jsonl
chore: cleanup of noisey beads files
2026-08-15 01:03:33 +10:00
sam ceee96b0de chore: cleanup of noisey beads files 2026-08-15 01:02:13 +10:00
sam 7298661b0f Merge pull request #480 from samcharles93/refactor/archie-agent-main-cleanup
refactor(agent): move worker runtime into application layer
2026-08-15 00:51:03 +10:00
sam d28ca099c5 refactor(agent): move worker runtime into application layer
cmd/archie-agent used to own worker construction, NATS lifecycle, task execution, MCP setup, and workflow wiring. It now owns process input only and invokes internal/app/agentworker, while transport-specific NATS, boot-brief, and git-safety mechanics live under infrastructure.
2026-08-15 00:43:12 +10:00
sam dd287d3336 Merge pull request #478 from samcharles93/chore/bump-ai-sdk-v0.1.21
chore(deps): bump ai-sdk to v0.1.21
2026-08-15 00:29:27 +10:00
sam d59bb19c3f Merge pull request #477 from samcharles93/fix/archie-core-tb3a
fix(chat): harden inline tool call streaming
2026-08-15 00:25:23 +10:00
sam 566beff1d6 chore(deps): bump ai-sdk to v0.1.21
ai-sdk v0.1.21 wraps the cancellation cause in aborted-stream errors
("%w: %w") instead of formatting it, so errors.Is(err, context.Canceled)
is reliable again. The Telegram channel was compensating with a comment
explaining why errors.Is could not be trusted.

The code was already correct; only the comment was obsolete. It now
states the real reason for context.WithoutCancel(turnCtx): turnCtx is
dead on both stop and fault paths, so the cursor-drop edit needs a live
context. The runtime effect of the bump is that a /stop landing inside
the step loop is now logged as "chat turn stopped" rather than
"route failed".

Refs ai-sdk-0pn
2026-08-15 00:24:33 +10:00
sam 0bbd6e75de fix(chat): harden inline tool call streaming
Telegram streaming callbacks now enqueue cancellable rendering rather than performing network I/O while draining the authoritative model stream. Final edit failures fall back to normal split delivery.

Completed tool events now correlate inputs by call ID and expose only bounded, conservative parameter shapes. Tool-call visibility is snapshotted per reply so reloads cannot change an in-flight turn.
2026-08-14 04:52:48 +10:00