Skip to content

Adds Agent Memory - #10289

Merged
michaelstaib merged 305 commits into
mainfrom
pse/adds-agent-memory-to-nitro
Aug 26, 2026
Merged

michaelstaib merged 305 commits into
mainfrom
pse/adds-agent-memory-to-nitro

Conversation

@PascalSenn

@PascalSenn PascalSenn commented Aug 24, 2026 •

Copy link
Copy Markdown
Member

No description provided.

# Conflicts:
#	src/Nitro/CommandLine/src/CommandLine/Commands/Agent/AgentTuiLauncher.cs
Adds TaskStates.Archived, a terminal state that keeps releasing blocked
dependents like closed. After CloseTaskAsync and CloseEligibleEpicsAsync
commit, the store archives the oldest closed tasks (by closed_at, tie-break
id) until the closed count is back at TaskStates.ClosedTaskCap (100), writing
a TaskEventTypes.Archived event per archival. The null-Statuses default and
IncludeAll no longer return archived tasks; they only come back when Statuses
explicitly lists "archived". Id-addressed reads still find archived tasks,
and reopening one returns it to open, same as reopening a closed task.
Checks files/index agreement (per scope, only when the index's
fingerprint claims to be fresh), cross-scope duplicate ids across
curated and journal, and malformed frontmatter, collecting every
offending path and reason instead of throwing on the first one.
Structured JSON diagnostics, nonzero exit when unhealthy, mirrors
DoctorTaskCommand.
…o-close and updates (perles-net-8zp)

QueryEpicStatusesAsync counted only status = closed toward an epic's
Closed total, so an epic whose children were closed then auto-archived
past the 100-task cap could never satisfy IsEligibleForClose and never
auto-close. Count archived alongside closed for both the query and
IsEligibleForClose, and stop UpdateTaskAsync from setting status to
archived directly or changing the status of an already-archived task
(archiving is automatic and reopen is the only way out). Also make the
tree/lint node lookups include archived tasks via a new
TaskFilter.IncludeArchived flag, add Archived to StatusOrder so it
sorts deterministically, and fix the reopen error message to mention
archived tasks.
…d tasks (perles-net-8zp)

Adds TaskStoreTests coverage for the archived-as-closed epic fix: an
epic with a closed and an archived child auto-closes, an already
archived epic is not re-closed, and closing an epic that pushes the
closed count past the cap archives the overflow (exercising the
previously untested ArchiveExcessClosedTasksAsync call from
CloseEligibleEpicsAsync). Also covers UpdateTaskAsync rejecting
--status archived and rejecting status changes on an archived task,
and updates the reopen-error snapshot for the new message wording.
MemoryFrontmatterParser and MemoryJournalFrontmatterParser only checked
that the frontmatter id was non-empty before comparing it to the
filename-derived id, so a malformed but non-empty id (e.g. wrong
length or characters) would parse successfully as long as it matched
the filename. Both now reject any id that is not a well-formed
MemoryId shape, failing as InvalidValue.

Fixture ids in MemoryFtsIndexTests that used the old "mem-<n>" shape
are updated to valid ULID-shaped ids so they keep parsing.

perles-net-198.7 (carry-forward from slice (a) review, comment 14).
…yIds

A curated file whose frontmatter fails to parse was excluded from
InspectScopeAsync's curatedPathsById, so if a fresh index still held a
row for that id (e.g. from before the file was corrupted, with the
corruption preserving the directory fingerprint), InspectIndexAsync
reported the id under both the Frontmatter check and, redundantly and
misleadingly, under Index agreement's indexOnlyIds ("in the index but
has no curated file on disk" is not true, the file exists, it just
does not parse).

Collect the ids of parse-failed curated files and exclude them from
the indexOnly computation, so a malformed-but-present file is reported
only once, by the Frontmatter check.

perles-net-198.7 (Finding 5).
…ex/fingerprint

MemoryFtsIndex and MemoryIndexFingerprint take IFileSystem for content
and enumeration but read file metadata (FileInfo) and perform the
atomic index replacement (File.Move/File.Delete) against the real
filesystem. This is a deliberate scope split, not an oversight; record
it in the XML doc remarks rather than unifying it.

perles-net-198.7 (Finding 4, carry-forward from slice (d) review,
comment 25 item 1: "unify or document").
…y, and tree/lint gates

Archived is a closed-adjacent status (tasks age from closed to archived
past the closed-task cap), but several TUI/CLI gates only matched
TaskStates.Closed, silently dropping archived tasks:

- DependencyTreeView.RefreshBlocking omitted IncludeArchived, so archived
  tasks vanished from the dependency tree (TreeTaskDependencyCommand
  already passed IncludeArchived: true).
- TaskLifecycleActions.CanReopen only offered reopen for Closed, even
  though TaskStore.ReopenTaskAsync already accepts Closed or Archived.
- ShowTaskCommand, TaskDetailSidebar, and LintTaskCommand's
  closed-epic-open-children check only matched Closed, so archived tasks/
  epics lost their "Closed: ..." line and closed-epic linting.
- TaskGlyphs had no glyph for Archived, falling through to the open glyph.

Pins TaskFilter's existing IncludeAll/IncludeArchived interaction with
tests rather than changing BuildFilter, since the behavior was already
correct.
…et-198.8)

Adds a fourth "Memory" tab to the nitro agent TUI (Tui/Memory/), mirroring
the Tui/Mail component family: state, data loader, list/detail views, key
map, and lifecycle actions. Lists curated memories or journal entries
(f cycles the collection, s cycles the scope filter), with a search box
(tag:/type: tokens narrow the same way --tag/--type do, everything else is
free text passed to the store's own lexical search). Read-only beyond two
writes that go through the same store members the CLI uses: p promotes the
selected journal entry (mechanical, idempotent), d forgets the selected
curated memory (hard delete, behind a confirmation). A cross-scope
duplicate id under --scope all surfaces inline instead of crashing the tab.

AgentTuiLauncher.RunAsync registers the tab after Agents (perles-net-w27),
mnemonic 'e' since 'M' is already Mail's; AgentTuiLauncherTests pins the
[Tasks, Mail, Agents, Memory] tab order, closing the finding w27's review
left for this slice.
…refresh (perles-net-198.8)

RefreshAsync now catches ExitException (a store read rejected, such as
malformed frontmatter) the same way it already catches
MemoryScopeConflictException: surfaced through the existing LoadError
field instead of throwing out of OnEnter, so a corrupted memory file no
longer prevents TuiShell from constructing. The shared list-clearing
for both catch branches is extracted into ClearActiveCollection.
…limit (perles-net-198.8)

LoadCuratedAsync now pulls the full recent page (int.MaxValue) before
applying a type/tag filter, then takes Limit off the filtered result, so
a type: or tag: term narrows the returned page instead of narrowing an
already-limited one. ListTitle's "(filtered)" suffix on the Journal
collection now only appears for free text, since journal entries carry
no type or tags for tag:/type: terms to narrow.
… pane not the list pane (perles-net-198.8)

MemoryDetailView.NoSelectionMessage is what renders LoadError, not the
list pane the doc comment claimed. No behavior change.
…net-198.8)

_promoteTarget was written and cleared alongside _promoteForm but never
read; MemoryPromoteForm already carries the journal entry being
promoted. No behavior change.
…98.8)

Extracts the Tasks/Mail/Agents/Memory tab construction out of RunAsync into a
testable internal static BuildTabs method, closing the w27 gap where the tab
order assertion replicated construction instead of exercising the real code
path. RunAsync now calls BuildTabs and keeps only searchMode/treeView/actor
inline. Tests rewritten to build shells from BuildTabs output.
…e (perles-net-198.8)

MemoryMode.ListTitle silently dropped type:/tag: qualifiers when the search
box was applied against the Journal collection, since journal entries have
no type or tags to filter by. Parse the query once and append " (type/tag
ignored)" to the title when a type or tag qualifier was present, so the
qualifier's no-op is visible instead of silent.
…andle (perles-net-198.8)

OnEnter blocked on a synchronous store read every time the Memory tab is
entered, even though the tab title is static and nothing in the tab strip
needs the data eagerly. OnEnter now only sets a pending-refresh flag; the
blocking refresh happens once, lazily, on the first Render or Handle call
after entering. TuiShell is untouched. Adjusted the tests that asserted
state right after OnEnter without rendering or handling a message first.
TaskStore.CloseTaskAsync only checked status == Closed, so closing an
archived task un-archived it back to closed with a fresh closed_at
instead of raising the documented "reopen is the only way out of
archived" error.
… doctor

DoctorMemoryCommand.FindCrossScopeDuplicates only reported ids duplicated
across the project and global scopes. An id duplicated between curated/
and journal/ within the SAME scope was silently missed. Add
FindSameScopeCollectionDuplicates and surface it as
sameScopeCollectionDuplicates in JSON and a new "Same-scope collection
duplicate ids" check in human output.
…uncherTests (perles-net-don)

Shell_Should_StillOpenOnTheTasksTab_When_TheMemoryStoreThrows asserted that
constructing the shell with a malformed curated memory file on disk did not
throw. Since f1cfa65 deferred MemoryMode.OnEnter's refresh to the first
Render/Handle, OnEnter no longer touches the store during shell construction,
so the test's arrange no longer exercises the path its comment describes.
Coverage for the actual error-handling behavior already lives in
MemoryModeTests.OnEnter_Should_SetLoadError_Instead_Of_Throwing_When_ACuratedFileHasMalformedFrontmatter.
…anges (perles-net-don)

MemoryDetailView.ResetScroll's doc says a different item being selected
resets the detail pane's scroll, but MoveOrScroll and MoveOrScrollToEdge
never called it, so switching items in the list left the detail pane at the
previous item's scroll offset instead of opening at the top.
RunAsync_Should_CoalesceBurstOfWalGrowth_IntoSingleEvent and its
CoalesceBurstOfWrites sibling paced their write bursts with
Task.Delay(Debounce / 5) between iterations. Under a loaded thread
pool that delay can stretch past the debounce window itself, letting
the timer fire mid-burst and emit a second event that the trailing
"settled" assertion then catches as a failure. Reproduced reliably
under synthetic CPU load (15/15 failures avoided after the fix vs.
1/6 before). Writing the burst back-to-back with no inter-write delay
removes the dependency on thread-pool timer scheduling under load.
FindCrossScopeDuplicates was listing each entry's scope, so an id
duplicated across curated/journal within one scope in addition to
another scope reported a repeated scope entry instead of the distinct
set. Add a regression test covering an id in project curated + project
journal + global asserting Scopes is ["project", "global"].

perles-net-e2k
…-collection all

recent/search --collection all previously handed each band the full
--limit and truncated the concatenation afterward, so enough curated
matches could consume the whole limit and starve the journal band even
when it held more recent entries. Split an explicit limit into a
curated ceiling half and a journal floor half instead; if a band comes
up short, the unused remainder flows to the other band so the total
still reaches the limit when enough entries exist. Band order and
scope banding within each band are unchanged. --collection curated,
--collection journal, and no --limit are unaffected.

perles-net-dne
…short

Under --collection all with an explicit --limit, an empty or short journal
band left its remainder unused instead of flowing back to the curated band.
Restructure both RecentMemoryCommand and SearchMemoryCommand to hold curated
and journal results separately and concatenate at the end, so the curated
band can be re-queried once with the freed-up share (explicitLimit - journal.
Count) when the journal band underfilled and curated was truncated at its
own share. Band order (curated first, then journal) is unchanged.

Extends MemoryBandLimit with GrowCuratedWithJournalShortfall, symmetric to
the existing GrowJournalWithCuratedShortfall.

perles-net-dne
Adds an unscoped workspace-wide message read: no actor pins the query,
so cross-agent traffic that no single agent's inbox reaches is now
reachable. MailWorkspaceFilter (Agent, Since, Limit) mirrors
MailInboxFilter but deliberately omits UnreadOnly and IncludeArchived,
since read/archived state lives per recipient and has no
workspace-wide meaning. The query joins message_recipients only when
Agent is set and de-dupes with DISTINCT, reusing the id-query-then-
GetMessageAsync shape QueryInboxAsync uses so recipients stay
embedded.

FakeMailStore in both test doubles throws NotSupportedException for
the new member, matching the existing pattern for members their
callers do not exercise.

perles-net-wi3.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants