Phase 8: Integration — Wire Memory, Skills, Session DB, Curator - #143
Merged
Conversation
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.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wires all seven phases into dirge's agent lifecycle, plus all review fixes.
Integration points:
Review fixes included:
1249 tests passing. Existing memory/skill tools unchanged — they serve a different purpose.