Commit Graph
410 Commits
Author SHA1 Message Date
sam 4ece064026 feat(curator): engine family contract, registry, and runtime (archie-core-rfp, archie-core-89x)
internal/curator is a conforming engine family per the strict plugin
engine rule: typed CuratorEngine contract (Lifecycle + domain ops),
owning Registry (registration, discovery, start/health/stop with
failure isolation, reverse-order shutdown, ctx-bounded stop), and a
narrow typed Registrar — each curator receives a capability-filtered
view of the host at Bind, never the daemon.

Runtime: one loop per curator on an injectable clock (fake-clock
testable), best-effort wake nudges with the trigger decision kept in
Check (a dropped nudge only delays to the next check-in, never
corrupts accounting), per-pass timeout and a max-concurrent-passes
slot so curator bursts cannot starve chat turns, per-pass panic
recovery, and bounded shutdown even when a pass ignores cancellation.
curator_run / curator_action / curator_error ride the in-process
event bus so activity stays attributable.

Wired in cmd/archied/main.go (constructed beside memory, Start after
daemon startup, shutdown ordered before memory/LLM teardown) and
exposed as daemon.Daemon.Curators.
2026-08-05 14:54:12 +10:00
sam 0ddc43081e feat(setup): implement the interactive setup steps (archie-core-cbk)
internal/infrastructure/configuration/setup.Run drives operator
identity, LLM provider, models, forge, and Telegram chat channel
prompts and returns TOML edits -- not a config.Config. Building a
parallel in-memory representation to validate against was rejected
during design review: it's a second source of truth about the exact
thing (text vs. struct disagreeing) this whole feature exists to stop.
Tests instead render the edits against the real embedded template and
load the result through a real configuration.Loader, proving the
actual defaults/decode/validate path accepts it.

Two boot-time landmines in config.example.toml surfaced by that
approach, both fixed here:

- [providers.openai] ships active with api_key pointed at the bws
  engine. cmd/archied/provider_secrets.go resolves every entry in
  cfg.Providers at startup, not just the ones [models] references, and
  refuses to start the daemon if any fails -- so picking any other
  provider (or picking openai but skipping the key) left a config that
  wouldn't boot on a machine without the bws CLI installed (the common
  case). stepProvider now neutralises providers.openai.api_key to the
  zero-value secret ref whenever openai wasn't the actual choice.
- [[repos]] shipped active with a placeholder owner/name that
  validates cleanly (owner/name are only checked non-empty) and would
  have archied silently polling a repo that doesn't exist. Commented
  out in the template with an explanation; setup does not write this
  section since tomlwrite cannot target array-of-tables.
  TestExampleConfigLoads updated to expect zero repos.

Also: forge and provider secret env-var names are each defined in one
table (forgeToken, cloudProviders) read by both the config edit and
the secret sink, so the two can't name a secret differently -- the
exact bug class this feature exists to close for the installer, tested
directly (TestRun_ForgeTokenKeyMatchesStoredSecretKey compares the
decoded key against the key the secret was actually stored under, not
a hardcoded literal on both sides). Telegram writes chat.telegram.
token_env, not a secret.SecretRef -- TelegramConfig has no such field.
Telegram also requires at least one allowed_user_id: AllowedUserIDs is
deny-by-default, so a bot token with none configured answers nobody,
which reads as broken rather than as the safe default it is.

SecretSink is a caller-supplied sink (Put buffers, Commit persists),
not a return value: Run never hands back plaintext secrets, and the
caller is expected to call Commit only after proving the generated
config loads -- so a validation failure never leaves a secret written
without the config that references it.

Refs archie-core-cbk
2026-08-05 12:58:53 +10:00
sam 6ee86f2593 feat(setup): Prompter interface and a TTY-gated terminal implementation
archie-core-via. internal/infrastructure/configuration/setup defines
Prompter -- Select, ReadLine, ReadSecret, Confirm, all context-aware --
which is all the setup step logic (to follow) needs from a prompt
surface. No terminal dependency, so steps are testable without a TTY.

internal/infrastructure/terminalprompt.Terminal is the real
implementation, using golang.org/x/term. New refuses construction when
its input isn't a real terminal, with a message naming the problem --
enforcing "a non-TTY invocation fails with a clear message rather than
writing a partial config" at the earliest possible point, rather than
falling back to a plain read that would silently accept piped/scripted
input (ssh, `archied setup < answers.txt`, CI). Terminal satisfies
Prompter structurally; this package does not import that one, so
there's no infrastructure -> infrastructure edge for what Go's type
system already gives for free.

Each blocking read runs in a goroutine raced against ctx.Done(), so
Ctrl+C returns promptly instead of leaving the operator stuck; the
losing goroutine is abandoned on cancellation; term.ReadPassword's own
raw-mode restoration is not interruptible, so an abandoned secret read
can leave the terminal in raw mode until it unblocks on its own --
documented on Terminal.readSecret rather than worked around, since a
cancelled setup command is expected to exit shortly after via its own
signal handling anyway.

Tested by constructing a Terminal directly (bypassing New, same
package) over a plain pipe with an injected readSecret seam -- New's
TTY gate itself is exercised separately against a real os.Pipe(). No
weakening of the production constructor for testability.

Refs archie-core-via
2026-08-05 12:47:20 +10:00
sam 1579b027b8 feat(configuration): export Validate for archied setup to call
Loader.finalize's decode-then-validate sequence called an unexported
validate(cfg *config.Config), so nothing outside the package -- e.g.
archied setup, which builds a config.Config in memory before writing
it to disk -- could run the same checks. Validate wraps it; Loader now
calls the exported form internally (single call site, no behavior
change).

Documented the sharp edge this alone doesn't solve: Validate doesn't
apply defaults (agent.mode, dispatch.trigger, forge.type all only pass
once defaulted), and defaulting is still an unexported method on
*Loader. A cfg setup builds by hand needs those fields filled in
itself, or -- safer, since it can't drift from the real load path --
setup should render to TOML and load it back through a Loader rather
than call Validate on the in-memory value directly.

Refs archie-core-ewk.1
2026-08-05 12:44:42 +10:00
sam 32bd705286 fix(tomlwrite): recognise table headers carrying a trailing comment
activeHeaderRe/commentedHeaderRe were anchored with no allowance for a
trailing "# ..." comment on the header line itself. config.example.toml
has four such headers -- "[models] # role -> ...", [indexing], [web],
[notify] -- so Apply never recognised them as table headers at all. An
edit targeting "models" fell through every matching stage and got
appended as a second, duplicate [models] table at EOF, which
BurntSushi/toml then refuses to decode ("Key 'models' has already been
defined").

This is a real blocker for archied setup (archie-core-cbk): the models
step targets exactly this table. Found via plan review before writing
setup itself, rather than by setup's own tests discovering it later --
would have made the failure look like a setup bug rather than the
tomlwrite one it actually is.

Refs archie-core-ewk
2026-08-05 12:43:29 +10:00
sam 357abc2097 fix(install.sh): three argument/linger handling defects
--force was advertised in --help, accepted, and inert (FORCE_BUILD was
set and never read -- go build already rebuilds unconditionally).
Removed the flag and its help line rather than fake an up-to-date
check that go build's own cache already makes unnecessary.

Unknown flags fell through the case statement with no default branch
and silently kept every default, so a typo like --no-systmd installed
the systemd service the user asked to skip. Unknown options now print
a diagnostic naming the bad flag and exit 1, per the (a) option agreed
2026-07-30: this is a hand-run interactive installer where typos
dominate and silent wrong behaviour is the worst outcome.

Linger detection grepped for "Linger=no" and treated any other output
-- including a failed or empty `loginctl show-user` from a missing
logind session, a container, or unset $USER aborting under `set -u`
-- as "already enabled" without observing anything. Detection now
requires a positive "Linger=yes" and falls through to enable-linger
(idempotent) in every other case, and uses $(id -un) instead of $USER.

Refs archie-core-bfw, archie-core-c6o, archie-core-utt

Verified manually: bash -n syntax check; a real invocation of an
unknown flag (exits 1, no side effects, before any build/network
step); the linger branch logic exercised in isolation against stubbed
loginctl output for Linger=yes, Linger=no, empty output, and a failing
command. No shell test harness (bats or similar) exists in this repo
yet, so this is direct verification rather than a committed test.
2026-08-05 11:57:16 +10:00
sam efdc652488 fix(worktree): name the missing forge credential when push fails
Push previously handed an empty token straight to go-git and let the
push fail with a bare transport/auth error. When a repo is configured
while the forge is disabled (missing credential), that failure surfaced
late -- at push time -- with a message that didn't explain the cause.

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

Refs archie-core-3fb
2026-08-05 11:55:39 +10:00
sam 4a22fcd340 style: gofumpt internal/tools/builtin/find.go
Refs archie-core-ts9
2026-08-05 11:53:04 +10:00
sam 393eb18ec5 fix(tools): report a cancelled find walk as an error, not empty results
The WalkDir callback swallows every per-entry error and returns nil,
so the only error that can escape is ctx.Err() from the cancellation
select. The old guard compared that error against itself and never
fired, so a timeout or /stop fell through to whatever partial matches
had accumulated, or "no matches found" when it had none -- telling the
model a search found nothing when it never finished.

Refs archie-core-ts9
2026-08-05 11:52:19 +10:00
sam 58f3d40683 docs: state the organisation rule as an enforceable invariant
The layering was written down in docs/architecture/organisation.md and
approved, but nothing an agent reads first pointed at it. Reading
internal/ cold shows ~35 packages side by side, so the obvious move is
to add a thirty-sixth -- which is how the flat layout kept regrowing,
and untangling it cost a week.

The section states the four layers and their ownership, names the
dependency direction as the invariant, and explains why the layers stay
under internal/: it is a compiler-enforced visibility boundary, so
hoisting one to the repository root would make Archie's domain types
importable by any dependent module and commit us to API stability on
exactly the code that most needs to keep changing.

Cross-cutting packages get a checkable definition rather than a vibe: a
package that may be imported by any layer and imports none of them.
logging, events, eventbus and taskstate each have zero inward imports
today, which is what lets them sit outside the dependency direction --
they are sinks, never sources. It doubles as the failure test: the
moment one imports a domain type it has become misfiled domain code.

Deliberately no shared/ directory. A directory named for a category
becomes where things go when nobody can say what they are.

Refs archie-core-5d7
2026-08-05 11:37:34 +10:00
sam 4112720b73 chore(beads): remember to commit the meaning, not just the change 2026-08-05 11:00:38 +10:00
sam 5d72920827 chore(beads): sync issue export 2026-08-05 10:49:02 +10:00
sam 68ba3456ee feat(webui): chat from the dashboard
Brings the chat surface to the Web UI: /api/chat with its own handlers
and tests, a self-contained ui/src/chat feature folder, and the shared
plumbing to reach the same router Telegram uses.

Includes a dangerous-command approval path (internal/gateway/dangerous.go,
internal/webui/dangerous.go, and the Telegram counterpart) so /rollback
and /stop are gated the same way on both surfaces, persona handling for
web sessions, and release-update formatting split out of the Telegram
service so both can render it.

web_parity_test.go pins that the two surfaces expose the same commands.

Authored in a parallel session; committed here so it lands with the rest
rather than sitting uncommitted while other work builds on top of it.
task check passes with it in place.

Screenshots used while building are gitignored (*.png) rather than
committed, matching the call made on the earlier design reference.
2026-08-05 10:48:51 +10:00
sam 8ae21f25db fix(nell): honour the transition guard on the backend that ships
cmd/archied opens nell.OpenStore, not internal/store. Adapter.Transition
and Adapter.Requeue accepted a from status and never read it: they loaded
the document, overwrote the status and put. ErrStaleTransition could not
occur, so every compare-and-swap the callers depend on was absent in
production while passing in tests, which use the SQLite store.

Measured on the adapter: eight concurrent dashboard retries requeued one
task four times; twenty concurrent IncrementRetryCount calls landed a
count of one, so the retry cap added in 170fe02 could be evaded
indefinitely by holding Retry down. The same gap made approve and reject
read-then-write races -- a waiting_human task the daemon had since
claimed could be yanked back to queued and executed twice.

All three now take the adapter's existing mutex and check the guard. A
document store has no conditional update, so read-then-write has to be
serialised; the daemon is a single process, which is where the
concurrency is. No internal caller holds the lock when calling these, so
there is no self-deadlock.

Found by the adversarial review. It is the clearest argument yet for the
conformance-suite pattern: the guarantee was tested only on the backend
nobody runs.
2026-08-05 05:51:58 +10:00
sam fa6f4aef5f fix(gateway,daemon): repair regressions found by the adversarial review
Six defects, four of them introduced by the fixes in dbacb96, 44d43ef,
d5e016e, de1a899 and 4d44ef7. This is the third round in this codebase
where a round of fixes broke something the next round caught.

SANDBOX SILENTLY DROPPED. startContainers degrades a failed container
pool to nil, and the daemon's only test was `if ContainerPool != nil`.
So `containers.enabled = true` plus a missing agent image ran every
task's agent loop in-process, with the daemon's own authority and the
host filesystem -- the one thing [containers] exists to prevent -- while
logging only that containers were disabled. Nil now means two things and
they are distinguished: SandboxRequired parks the task instead. The
daemon still stays up; chat and the dashboard are unaffected.

SUMMARY AT THE WRONG END OF HISTORY. compressedHistory returns [head,
summary, tail], but ordering is by timestamp, not slice position. The
retained messages keep their original timestamps -- that is what
preserves their identity -- so the summary, being new, was clamped to
now and sorted after the tail it was meant to precede. The model read
the recent conversation and was only then told earlier context had been
summarised. Confirmed on both backends: index 23 of 24.

The monotonic clamp belongs to the append path, where an inbound message
must not sort ahead of the one that provoked it. ReplaceMessages is a
rewrite primitive and now honours explicit placement, and the summary
takes a timestamp inside the span it replaces.

A COMPRESSION SUMMARY ANSWERED A QUESTION. Following from the above,
PriorReply saw a bot-attributed record immediately after an unanswered
message and replayed it as the answer: a redelivered question was
"answered" with the compression banner and the model never ran. The
user's question was silently swallowed.

RECENCY STILL DIVERGED. sessionRecency preferred LastActiveAt whenever
set; SQLite used MAX(last_active_at, created_at). Those agree only when
LastActiveAt is the later of the two, so a clock step or an older record
made the caller and the store order the same sessions differently.

LASTACTIVEAT WAS NEVER UPDATED. Touch had no caller, so "resolve the
most recently active session" meant the most recently created one -- an
operator who moved to an older session with /topic and worked there was
dropped back into the newer, abandoned one on restart, which is the bug
d5e016e claimed to fix, with the direction reversed.

/branch WITH NO ACTIVE SESSION PANICKED, slicing an empty parent ID for
its default title. Pre-existing, but reachable: email and webhook call
Route directly without resolving first, and the email path runs in a
goroutine with no recover, so one message took the daemon down.

The sandbox guard has no test. The honest reason is that exercising it
needs a daemon with a forge and worktree the current harness does not
build, and a test that re-states the condition proves nothing -- which
is the same false confidence that let these regressions through.
2026-08-05 04:24:16 +10:00
sam 1f2e7a42eb refactor: one definition of what approving or declining a task means
The dashboard and chat both let an operator approve or refuse work, and
they had drifted. Declining from the dashboard left the task
closed_wont_do; cancelling the same task from chat left it rejected. Two
operators looking at one queue saw different states for the same
decision, and "rejected" -- which reconcilePRs also uses for a pull
request closed without merging -- stopped meaning one thing.

internal/gateway deliberately does not import internal/store, so it kept
a hand-synced copy of the status strings with a comment asking future
editors to keep them aligned. That is the same defect one level down,
and it is how the drift happened.

internal/taskstate is a leaf package with no dependencies holding the
lifecycle vocabulary and the rules for operator actions. gateway, store
and the dashboard all import it, so gateway stays decoupled from store
without a copy, and CheckApprove/CheckRetry/CheckDecline have one
implementation. Declined is named for what it is -- a human said no --
and stays distinct from Rejected, which is something archie observed.

Chat cancel now records Declined. That is the behaviour change: same
decision, same state, whichever surface the operator used.

Rules were preserved rather than tidied while unifying. A parked task
still cannot be declined, which both surfaces already refused, even
though "not terminal" would have allowed it -- widening a rule under
cover of a refactor is how you ship a change nobody reviewed. The
comment says where to change it if that is ever wanted.

TestDashboardAndChatAgreeOnTerminalStates drives both real surfaces
against one store, so this cannot drift apart again without a red test.

Also removes a second rule for the dash-top-standalone class: renderSetup
already reconciles it from the data at the top of every call, and a later
branch cleared it again. Harmless, but it reads as two sources of truth
for one bit of layout state.
2026-08-05 04:15:39 +10:00
sam d6e00415fa chore: drop the opspulse design reference
The screenshot was a one-off reference for the dashboard rebuild, never
committed, and its gitignore entry only existed to keep it out. Both are
gone.
2026-08-05 04:04:23 +10:00
sam 170fe0250b fix: close the duplicate-work loop and the dead paths around it
Applies the four-reviewer pass over the forge/dashboard-actions work.
The through-line is that several capabilities were wired but inert, and
one of them could cost real work.

DUPLICATE WORK. "Closes #N" was dropped from PR bodies in favour of
LinkBranch, which is sidebar linkage on Gitea and a no-op stub on
GitHub -- neither closes anything, and nothing else did either. So a
merged task left its issue open, labelled and assigned; the next poll
re-enqueued it, and once the dashboard's Clear removed the task row that
became a second implementation and a second PR for work already merged.
reconcilePRs now closes the issue on merge, and a rejected task closes
its issue too. A PR closed without merging deliberately leaves the issue
open: that usually means "try again".

MAX RETRIES. Configured, defaulted and reported by /api/config, and
enforced nowhere -- markDead was unreachable and EffectiveMaxRetries had
no callers, so the dashboard's retry incremented retry_count forever.
The retry action now retires a task to dead at the cap.

DEAD ON ARRIVAL. Tasks() never selected plan or source, so the
"Decision required" panel could not render and chat tasks -- whose issue
number is synthetic -- linked to forge issues that do not exist.

COSMETIC FAILURE, FATAL RESULT. OpenPR failed the whole stage when
LinkBranch errored, so the pull request was never opened and the task
parked; a retry re-links the same branch, which Gitea answers with a
conflict, so every retry parked again. It is best-effort now.

INVISIBLE ACTIONS. Approve/retry/reject wrote store rows and nothing
else, so the timeline and activity stream never showed that a human had
intervened. They emit events now.

Also: store write failures answer 500 rather than 409; the dashboard
surfaces the server's actual reason instead of "409 Conflict"; action
buttons stop propagation (acting on a task no longer also expands it),
disable in flight, keep per-task errors instead of one shared string,
and confirm before rejecting.

Removed: the maybeRetryParked shim and markDead with their now-vacuous
tests, WaitingTasks (no consumers; its tests were rewritten to assert
the same routing through TaskByID), write-only Daemon.Runtime, and
dir/dirs response bloat from /api/skills. skillSource checked workDir
before sharedDir, mislabelling every shared skill when the two are equal.
DefaultRoots now dedupes roots differing only by a trailing separator.

The air build rule claiming to keep ui/dist current never ran -- it
required one file to satisfy include_dir and include_file together, and
ui/ is excluded from the walk. Deleted with the comment that promised it.
task test:ui joins task check and CI; it ran nowhere before, so the
dashboard suite could rot silently.

Docs corrected where they described behaviour that no longer exists:
parks no longer comment on the issue, state labels no longer drive
retries, and forgerpc's doc claimed four proxied methods while listing
three of five.
2026-08-05 03:54:25 +10:00
sam a751be66b3 chore(beads): close archie-core-ky6 2026-08-04 23:33:08 +10:00
sam a2b2dc9ef2 fix(tools): let an optional provider fail without taking the daemon down
provider.Registry.Start was atomic for every provider: one failure
unregistered every other provider including the builtins, returned an
error up through the capability host, and exited archied. Under
Restart=on-failure that is a crash loop. Observed on carina 2026-07-30 --
mcp.desktop-commander could not start because the runtime image was
missing unzip, and the daemon restarted continuously, losing chat, the
gateway and every builtin tool over one third-party npm package.

Atomicity is right for a provider archied requires. It is wrong for an
external MCP server pulled from a registry at runtime, which is exactly
the category allowed to be absent -- the same reasoning already applied
to the forge, and to containers.

RegisterOptional marks a provider the daemon can run without. Its
failure to start, discover or index stops only itself and excludes it;
Register keeps today's rollback. Required/optional is a deployment fact
rather than a property of the code, so the registrar states it instead
of the engine declaring it in its own manifest -- which also keeps
plugin.Manifest metadata-only, per the plugin engine rule.

A skipped provider's dependents cannot run either: an optional dependent
is skipped with the reason, a required one is a hard failure, since it
declared it cannot work without something now absent.

Degradation is reported, not silent -- Health goes degraded naming each
provider and cause, Skipped() exposes the set, and the daemon logs one
error line per exclusion. Silence is how this went unnoticed until the
crash loop. A provider that half-started before failing is still
stopped, so no child process is left behind.

The regression test drives the real capability host, the path main.go
calls: with desktop-commander registered as required it fails with the
verbatim carina error, and as optional the daemon starts with its
builtins intact.

Closes archie-core-ky6
2026-08-04 23:32:47 +10:00
sam d95b3a871c chore(beads): record a candidate cause for the chat context-loss bug 2026-08-04 22:48:42 +10:00
sam 76e2464278 chore(beads): close the cleared gateway review beads and shipped work 2026-08-04 22:48:19 +10:00
sam de1a899072 fix(gateway): make both backends agree on newest-first
SQLite ordered List and GetByChannel by created_at while NellDB reversed
document order, i.e. by session ID. Both documented "newest first", both
passed the shared suite, and neither meant recency -- so a cutover
between backends could change which session a restart resumes, and
Touch, the live path that makes a session the newest one, changed
nothing on either.

Recency is now LastActiveAt when set and CreatedAt otherwise, on both
sides, with an index matching the SQLite expression.

The conformance suite gains the case that would have caught this: three
sessions whose creation order, ID order and use order all disagree, plus
a Touch, asserted against List and GetByChannel on both backends.

Refs archie-core-8u8.2
2026-08-04 22:47:48 +10:00
sam 558e9ed341 chore(beads): close the gateway review findings that are fixed 2026-08-04 22:25:32 +10:00
sam a1a111ff35 fix(gateway): give branch-inherited messages their own identity
/branch copies the parent's history into the child. Because the store
honours an incoming MessageID -- which is what lets a read-modify-write
preserve identities -- the copies kept the parent's canonical IDs, so
two sessions claimed one identity and branch-point correlation was
ambiguous. Two branches from one parent made it three. It also broke
dedup in the child: an inherited message carried an ID derived from the
parent's session, so redelivering it appended (confirmed on both
backends: 3 messages became 4).

newMessageID's doc already claimed the opposite behaviour, and the
Message.MessageID doc said it was "ignored on write" -- which is exactly
the misreading that produced this. Both now describe what the code does,
including the obligation on a caller copying messages between sessions.

Also removes a doc comment describing msgID and its disambiguating
counter, deleted in 0814f7b, which had come to sit above
messageIDNamespace describing the opposite of the current design; and
corrects the Telegram comment still claiming a redelivered update
"updates the stored turn", the behaviour the immutability fix removed.

Refs archie-core-la1
2026-08-04 22:25:20 +10:00
sam f64353f0b5 fix(gateway): do not answer a redelivered message twice
Making the store idempotent stopped redelivery duplicating the inbound
record, but nothing consulted that result: respond() saved the message,
ignored the fact that nothing had changed, and called the model anyway.
The cost was a second billed turn, any tool side effects run a second
time, and a second assistant reply appended -- replies carry no upstream
reference, so they always get a fresh identity and always append. The
stated problem, "a re-delivered update appends a duplicate turn", was
only half fixed.

PriorReply answers "have I already replied to this?" from the history
the caller has already loaded, and the chat path replays that answer
instead of regenerating it. A message with nothing after it was never
answered -- the turn may have died partway -- so that still runs, since
the user is owed a reply.

CanonicalMessageID exposes the store's own derivation rather than
letting the caller reimplement it, since a lookup that silently never
matches is indistinguishable from a message never seen.

Refs archie-core-i6q
2026-08-04 22:23:17 +10:00
sam 0fd3398cf8 fix(gateway): stop /compress destroying a message that arrives midway
applyCompress reads the history, computes a summary, then replaces it.
ReplaceMessages removed everything outside the replacement set, so a
chat turn saved in that window was deleted without ever having been
read, let alone summarised. Confirmed on both backends. It is
unrecoverable loss, and it sits outside the write-then-delete guarantee
because the window is in the caller, not the store.

ReplaceMessages now takes the messages the caller is superseding instead
of inferring them from the complement of the replacement. A caller
computes a replacement from a history it read; anything that arrives
afterwards is not part of that, and is now left alone. IDs in both lists
are still kept, so read-modify-write callers are unaffected.

The test fake's ReplaceMessages was a slice assignment, which could not
observe ordering or identity at all -- it now mirrors the real stores.

Refs archie-core-6e0
2026-08-04 22:21:15 +10:00
sam 44d43ef286 fix(gateway): claim the session slot before writing it, not after
resolve saved a newly created session to the store and only then asked
the cache who had won a concurrent race. The loser had already persisted
a session that nothing pointed at: unreachable, but still listed by
/topic and /sessions as "(untitled)", and -- now that resolution goes by
recency -- resurrectable on a later restart. Confirmed by forcing the
interleaving: the store held 2 sessions where it should hold 1.

The claim now happens under the same double-check, ahead of the store
write, so only the winner writes. A failed Save releases the claim, or
the cache would point every later message in that chat at a session that
was never stored.

Refs archie-core-x35
2026-08-04 22:17:39 +10:00
sam a3b9eded5a fix(gateway): stop /topic off poisoning the session cache
handleTopic "off" copied the thread's active session onto the flat key
via setActive(getActive(...)). With nothing cached for that thread it
copied the empty string, and resolve treats map presence as
authoritative -- so it returned "" from then on, permanently, since
cacheActive also returned the empty existing value. Every later message
in that chat persisted under session "", history was shared with any
other poisoned chat, and the turn-lane key became "" so /stop in one
chat cancelled a turn in another.

Reachable as a first message on the webhook and email channels, which
call Route directly without resolving a session first.

setActive now rejects an empty session ID, so no caller can poison the
map whatever it computes, and resolve and cacheActive treat an empty
cached value as a miss so an existing entry repairs itself.

The get-then-set was also two critical sections, silently clobbering a
concurrent /resume or /branch with the value read before the switch.
flattenTopic does it in one.

Refs archie-core-jex
2026-08-04 22:15:28 +10:00
sam d5e016ec59 fix(gateway): resolve the most recently active session, not an arbitrary one
resolve's comment claimed to find "the most recent session matching this
thread and bot" and took whichever the store returned first. On the
NellDB store that is document order -- by session ID -- so it was
effectively arbitrary. The tracker cache is in-memory, so every restart
re-resolves from the store, and the operator could be dropped back into
a session they had left with /new, answering against pre-/new history.
Probed over 10 restarts, 4 landed in the older session. LastActiveAt was
populated on every record and never read.

resolve now picks by LastActiveAt, which also makes it independent of
the two backends disagreeing: SQLite's GetByChannel orders created_at
DESC and NellDB's did not, and the conformance suite did not pin it.

listAllLocked reversed document order and passed that off as recency,
so List -- documented newest-first, and what /sessions and the dashboard
render -- returned reverse-lexicographic order. It now sorts on
LastActiveAt, falling back to CreatedAt for records never touched.

Refs archie-core-7s3
2026-08-04 22:13:55 +10:00
sam dbacb96994 fix(gateway): stop /compress destroying history it should have kept
Two defects, both confirmed on the NellDB and SQLite backends.

IDENTITY. applyCompress rebuilt the protected head and tail as bare
Message{From, Text}, so every message that survived a compression was
deleted and re-inserted with a fresh canonical MessageID, no SourceID
and a timestamp of now. A rebuilt message is a different message: after
one compression, redelivery deduplication was broken for the rest of the
session's life, so a Telegram backlog replay after a restart appended
every surviving message a second time -- 24 became 25 on a redelivery
that was a correct no-op beforehand. That made the dedup guarantee
survive only until the first /compress, and violated
messaging-and-work-intake.md:88-90 and 112-114.

CompressHistory now reports which input messages it protected and the
write-back carries those originals through untouched, so only the
summary is a new record. The summary is attributed to the bot rather
than falling through to "user": CompressHistory emits it with role
"system", which has no representation in the store, so the model was
replaying "[Earlier conversation has been summarised...]" as if the
human had typed it.

DISPATCH. Three ways to rewrite a history the operator did not ask to
rewrite, or to fail to rewrite one they did:

- Bare /compress took the preview branch, and the preview closes with
  "Run /compress to apply" -- the documented way to compress could never
  compress, and the failure-safe path was unreachable.
- /compress focus <topic> discarded the topic and ran a full default
  compression. Nothing implements focused summarisation; it now says so
  instead of doing something else irreversibly.
- /compress here (no count) and any typo fell through to a full
  compression. Both now print usage.

compressPreview also read a fixed 200-message window while reporting the
real count, so the two numbers in one sentence described different
conversations and it advised against compressions that were needed.

Refs archie-core-cz8, archie-core-8k8, archie-core-le6
2026-08-04 22:11:53 +10:00
sam 0d4d045050 fix(memory): fall back to the default directory instead of exiting
d615de5 made an unusable memory directory fatal. That was the wrong
call and contradicts the forge and container paths: memory is one
capability among many, and refusing to start over a path denies the
operator chat, the dashboard and everything else -- then crash-loops
under Restart=on-failure with the real error scrolling past unread.

builtin.New now reports an unusable directory through IsAvailable and
Err rather than failing, so the caller decides. The daemon warns and
falls back to the location an unset work_dir would have produced, which
is where someone who copied a config from another host will look. If
that is unusable too it says what the operator loses -- no recollection
between conversations, and failing writes -- and carries on.

The provider stays readable while degraded, so a bad path reads as an
empty memory rather than breaking mid-conversation, and the dashboard's
memory page already renders IsAvailable so this is visible there.

Also fixes a defect the fallback test caught: an empty work_dir made
filepath.Join produce the relative path "memory", which MkdirAll
creates wherever the daemon was started from -- succeeding, and putting
memory somewhere nobody would look.

Refs archie-core-rml
2026-08-04 02:13:05 +10:00
sam 1ec5b507b3 chore(beads): record gateway adversarial review findings 2026-08-04 02:02:30 +10:00
sam d615de5c99 fix(memory): fail startup on an unusable memory directory
Both stores treat a missing file as an empty document, so a memory
directory that does not exist looked exactly like a memory with nothing
in it yet. archied logged "memory manager started" and ran with no
memory at all; the failure would have surfaced at the agent's first
write, as a tool error mid-conversation, long after startup said it was
fine.

Found live: a config copied from carina kept work_dir=/var/lib/archie
/work, a container path with no counterpart on the host.

New now establishes the directory and reports a path it cannot use, so
the existing error path exits at startup where an operator can see it.

Refs archie-core-rml
2026-08-04 02:00:12 +10:00
sam 6532537e24 chore(beads): sync issue export 2026-08-04 01:45:39 +10:00
sam 4d44ef76f5 feat(webui): rebuild the dashboard
The old UI was a single 200-line Go file serving one hand-written HTML
page of task rows. It showed that archied was running and almost nothing
about what it was doing -- skills, workflows, memory, channels, logs and
configuration were all invisible unless you read the source or the
config file.

The dashboard now covers each of those as its own section, built as a
Vite app under ui/ at the repo root: it is a separate artefact from the
Go daemon, not an internal package of it. dist/ is committed so building
archied never needs a Node toolchain, and the !no_ui build tag keeps an
embed-free build available.

Both sides are split by concern rather than by layer -- one Go file per
API area, one folder per UI section with its own CSS -- so a change to
logs cannot disturb tasks.

Pages report consequences, not just state: an empty memory page says
Archie starts every conversation with no recollection of earlier ones,
and the setup checklist names what is missing in plain language instead
of showing a grid of zeroes. Nothing greets by a hardcoded name; the
operator comes from [chat], which is deployment data.

Auth is exposure control, not capability control -- the agent already
holds this user's authority through its own tools. So a loopback bind
needs no token, and only a reachable bind mints one and logs a URL,
which means an instance cannot be exposed merely by omitting config.

Container startup now degrades instead of aborting, for the reason
resolveForge already does: a missing agent image should not deny the
operator chat and the dashboard, and under Restart=on-failure it turns a
recoverable problem into a crash loop with the real error scrolling past.

`task dev` runs the daemon under air and the Vite server together in one
terminal.
2026-08-04 01:45:36 +10:00
sam 449c925f29 feat(logging): optional rotating log file
Under systemd, journald held the only copy of archied's output, and
running it by hand left no record at all -- so "where are the logs?" had
no good answer, and the dashboard had no history to show from before it
connected. [log] adds a file destination alongside stderr, with
size-based rotation and retention done in-package rather than pulling in
a dependency for a few hundred lines.

A file that cannot be opened is reported and the daemon continues on
stderr: losing the durable copy is not worth refusing to start over.

reader.go owns the on-disk format so nothing else has to parse it, and
bounds every read -- tailing keeps the newest entries within a fixed
scan window, so pointing it at a large file cannot exhaust memory.
2026-08-04 01:44:56 +10:00
sam cbe02c1e6b fix(telegram): pause the update loop when rate limited
go-telegram/bot retries a 429 immediately and only then grows its own
backoff, so a rate-limited daemon kept hammering getUpdates and stayed
limited. The pipeline error handler now reads Telegram's own RetryAfter
and waits it out, capped at a minute so a hostile value cannot park the
loop indefinitely, and cancellable so shutdown is not held up.
2026-08-04 01:44:31 +10:00
sam 0814f7b9b4 fix(gateway): give messages durable identity and a SQLite store
Three defects shared one root cause -- messages had no identity of their
own, so the store could not tell a redelivery from a new message:

- SaveMessages destroyed history. Writing a batch replaced records that
  a concurrent write had already stored, and earlier messages vanished.
- A redelivered channel message overwrote the stored one, contradicting
  the append-only sequence in docs/architecture/messaging-and-work-intake
  .md:112-114.
- /compress stranded whatever exceeded one page: deleting 1200 reported
  1000 deleted and left 200 behind.

Messages now carry an application-generated MessageID, derived from
(session, source id) so a redelivery lands on the same record, and
stored records are immutable -- a repeat write is a no-op rather than an
overwrite. SourceID keeps the channel-native id for correlation without
being load-bearing. _ts is written as Unix milliseconds and clamped
monotonic per session: Telegram dates are whole seconds, so replies
arriving inside the same second would otherwise order arbitrarily.
Deletes page with a cursor instead of assuming one page holds everything.

Adds a SQLite session store behind the same interface, per
docs/architecture/messaging-and-work-intake.md:107. A shared conformance
suite runs all 19 groups against both implementations, so the two cannot
drift while the NellDB path is still the one wired up.
2026-08-04 01:44:26 +10:00
sam 7d7d03191f fix(store): surface task timestamps and tag the summary structs
Task carried no created/updated times, so the dashboard had nothing to
sort or age a queue by. Both columns already existed in the schema and
are now scanned through; SQLite returns them as strings in several
shapes, so sqliteTime does the parsing in one place rather than at each
of the five call sites.

WorkflowStat, StageStat and DayTokens had no JSON tags at all, so
/api/summary answered {"Day":...,"Tokens":...} while the dashboard read
d.tokens -- every sparkline would have plotted zero.
2026-08-04 01:44:10 +10:00
sam efa7e65755 perf(tools): drop the embedded ripgrep binaries
The rg package carried three platform binaries (14MB) inside the Go
binary and extracted the matching one to a temp file on every single
run, so a long-lived daemon left a trail of copies behind and paid the
write on each grep. Nothing depended on ripgrep's own output format.

grep now uses the Go implementation unconditionally.
2026-08-04 01:44:03 +10:00
sam bb77f88f73 fix: message history ordering and paged search
- Add Message.At timestamp as the ordering key, stamped at save when zero
- Store each session's messages in its own collection with time-ordered IDs
- Fix bulk saves overwriting history and sequence reuse after deletes
- Walk past NellDB's internal scan limit for history and deletes
- Add paged SearchMessages (MessageQuery/MessagePage) with truncation reporting
- Drop a session's message collection when the session is deleted
2026-08-03 19:08:40 +10:00
sam cfec693716 chore: update NellDB to v0.3.0
- Add .pi-subagents/ to gitignore
2026-08-03 19:08:10 +10:00
sam c7f060584b chore(beads): close archie-core-ci3, add b4i task 2026-08-03 19:07:49 +10:00
sam ef8856872c chore(release): archied v1.4.1 2026-07-31 08:48:49 +10:00
sam 76f6299f22 fix(catalog): match SDK provider fallback 2026-07-31 08:48:38 +10:00
sam e71fc92364 chore(release): archied v1.4.0 2026-07-31 08:46:23 +10:00
sam 3ae59c99c0 fix(secrets): wire provider credentials through engines 2026-07-31 08:45:58 +10:00
sam 059eee412c chore(release): archied v1.3.1 2026-07-31 03:47:42 +10:00
sam b571b207af chore: sync issue export 2026-07-31 03:47:33 +10:00