Skip to content

Phase 8: Integration — Wire Memory, Skills, Session DB, Curator - #143

Merged
yogthos merged 7 commits into
phase-7-compressionfrom
phase-8-integration
May 26, 2026
Merged

Phase 8: Integration — Wire Memory, Skills, Session DB, Curator#143
yogthos merged 7 commits into
phase-7-compressionfrom
phase-8-integration

Conversation

@yogthos

@yogthos yogthos commented May 26, 2026

Copy link
Copy Markdown
Collaborator

Wires all seven phases into dirge's agent lifecycle, plus all review fixes.

Integration points:

  • Session start: per-project MEMORY.md + PITFALLS.md injected into system prompt
  • Each turn: session DB persistence for user + assistant messages
  • Session end: background review spawns, curator checks for periodic maintenance

Review fixes included:

  • P1: Review fork receives full transcript with tool calls/results
  • P2: FTS5 query sanitization, rate-limited reviews, full last_user_prompt tracking
  • P2: FileLock PID-based staleness detection
  • P2: find_git_root worktree support + symlink canonicalization
  • P3: curator Option, archive_skill no-data-loss fix

1249 tests passing. Existing memory/skill tools unchanged — they serve a different purpose.

Yogthos added 7 commits May 25, 2026 23:12
Wires all seven prior phases into dirge's agent lifecycle:

1. Per-project MEMORY.md + PITFALLS.md injected into the system
   prompt at every session start via agent/builder.rs preamble
   construction. Frozen snapshots are loaded from .dirge/memory/
   and formatted as XML-fenced blocks the LLM treats as reference.

2. Session DB persistence: completed turns are written to the
   SQLite session database (Phase 1) at each Done event. Uses a
   stable session-id (first 8 chars of session.id) so messages
   from the same interactive session are grouped. INSERT OR IGNORE
   makes repeated session creation idempotent.

3. Curator check: periodic skill maintenance (Phase 6) fires
   after each session completes, gated by the 7-day interval.
   Fire-and-forget via tokio::spawn — never blocks the user.

4. Background review (Phase 4) already wired, now with proper
   ProjectPaths sharing across session DB, curator, and review.

The existing memory/skill tools are unchanged — they serve a
different purpose (user-controlled CRUD vs automatic injection).

All 1237 tests pass.
… rate limiting, prompt tracking

Four fixes from the phase code review:

1. dirge-6h5 (P1): Review fork now receives full session transcript
   via build_transcript(session) — includes user messages, assistant
   text, tool call names+args, and tool results. Added 5 tests.

2. dirge-ebq (P2): FTS5 queries now sanitized via sanitize_fts5_query()
   which strips special chars (*, ", (, )) and wraps queries in
   double quotes. Added 5 tests.

3. dirge-rkic (P2): Background review now rate-limited to 15-minute
   intervals via AtomicU64 compare-and-swap. Concurrent Done events
   from multiple sessions won't race.

4. dirge-smsd (P2): last_user_prompt now updated at all 10
   spawn_runner call sites: main text, shell bang, worktree merge,
   loop iteration start/continue, plugin followup, both interjection
   drain paths, ContextOverflow respawn, and question response.

5. dirge-b1lw: Closed as false alarm — memory injection uses
   if let Ok(...) pattern, not unwrap().
Four curator review findings resolved:

1. dirge-del (P3): last_run changed from u64 to Option<u64>.
   None means never run, avoiding epoch-0 collision where a
   valid timestamp could be confused with the first-check sentinel.

2. dirge-88m7 (P3): archive_skill no longer removes existing
   destination before rename. If the destination exists, the
   skill was already archived (possibly by a concurrent curator
   process). Clean no-op instead of data-loss risk.

3. dirge-7030 (P3): Already resolved — only one Curator::new()
   call exists in the integration. Uses a single mut curator for
   both should_run_now() and apply_automatic_transitions().

4. dirge-2rb (P2): Already handled — save() creates parent
   directories before atomic_write_sync, archive_skill() creates
   the archive dir before rename.
Addresses dirge-ld7 (P2). FileLock now writes the process PID into
the lock file at creation time. On contention (AlreadyExists), the
first iteration checks if the lock is stale by reading the stored
PID and testing whether the process still exists via kill(pid, 0)
on Unix platforms.

If the lock holder process has died, the stale lock file is
removed and the lock is re-acquired immediately. Subsequent
contention attempts fall through to spin-wait (100ms total) as
before, since the holder is confirmed alive.

On non-Unix platforms, pid_is_alive() conservatively returns
false (assumes alive) to avoid breaking valid locks.

Also closed dirge-oyr: TOCTOU race already fixed — lock is
acquired before all checks in add/replace/remove.
Two find_git_root fixes:

1. dirge-m7i (P2): Git worktree support. find_git_root now recognises
   .git as a file containing 'gitdir: <path>' (worktree marker) via
   the new is_git_root_marker() helper. Added test with synthetic
   worktree marker.

2. dirge-2hu (P2): Path canonicalization. find_git_root now calls
   cwd.canonicalize() before walking up, resolving symlinks in the
   path chain. Fallback to original path on canonicalization failure.
   Updated tests to account for canonicalized temp dirs (/tmp →
   /private/tmp on macOS).

Also replaced the old .pop() loop with .parent() iteration for
clearer path traversal, with a self-equality check to prevent
infinite loops at the filesystem root.
@yogthos
yogthos merged commit 92934ac into phase-7-compression May 26, 2026
1 check passed
@yogthos
yogthos deleted the phase-8-integration branch May 26, 2026 04:10
allen-munsch pushed a commit to allen-munsch/dirge that referenced this pull request Jun 3, 2026
Phase 8: Integration — Wire Memory, Skills, Session DB, Curator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant