agentsclimarketplace

Memory

Skill lkv1988/collie-harness/skills/memory

Boids-inspired memory management for AI agents. Evaluates conversation content against a fixed decision tree to decide what to remember, where to store it, and when to consolidate. Activate on Stop hook and PreCompact hook for automatic memory capture. Also activate when the agent detects information during conversation that might change future behavior — user corrections, preferences, role info, project constraints, or external system references. Do NOT activate for knowledge questions, in-session operations, or debug conclusions.From its SKILL.md

Install
npx -y skills add lkv1988/collie-harness --skill memory

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 3 stars3 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

10.4 KB, as published. Nobody here has run it

Memory

7 local rules, emergent global memory. Inspired by Boids, grounded in cognitive science.

Storage

Directory structure

~/.collie/memory/                           ← agent-independent, all agents share
├── user/                                   ← user-level (cross-project)
│   ├── INDEX.md                            ← index of long/ only, ≤200 lines
│   ├── short/
│   └── long/
├── projects/
│   └── -Users-kevin-git-corp-lara/         ← project-level
│       ├── INDEX.md
│       ├── short/
│       └── long/
└── sessions/                               ← session logs (transient)
    └── 2026-05-07_14-32-00.jsonl

Project naming convention

Absolute cwd path, every / replaced with -, including leading -:

/Users/kevin/git/notes/obsidian  →  -Users-kevin-git-notes-obsidian
/tmp/my project                  →  -tmp-my project

Spaces kept as-is (quote paths in scripts). Matches Claude Code's ~/.claude/projects/ convention.

Scope rules

typescopewrites to
feedbackuseruser/short/
useruseruser/short/
projectprojectprojects/<project>/short/
referencedependsproject-specific → projects/<project>/short/, general → user/short/

Memory file format

---
type: feedback | user | project | reference
summary: one line
created: YYYY-MM-DD
last_accessed: YYYY-MM-DD
access_count: 1
---
Content in your own words. Not a copy of user's message.

File naming: YYYY-MM-DD_<keyword>.md

INDEX.md only indexes long/. short/ is invisible to the index.

Hook Pipeline

Five hooks form a complete capture-and-consume pipeline. Capture is synchronous and fast; consumption is asynchronous and thorough.

Overview

SessionStart         UserPromptSubmit      PostToolUse(Read)   PreCompact          Stop
(session begin)      (every message)       (after Read tool)   (before compress)   (session end)
     │                    │                      │                   │                  │
     ▼                    ▼                      ▼                   ▼                  ▼
cleanup stale        append message to     path in               systemMessage →    consolidate.js
short/ + long/       session log           ~/.collie/memory/?    read session log   promote short→long
sync INDEX           lines % 20 == 0?      yes → bump            run decision tree  merge long dups
read INDEX files     ├─ no → done          last_accessed +        write memories     (no agent prompt)
inject into context  └─ yes → inject       access_count          (keep log)
                              "evaluate    no → skip
                               recent msgs"

Hook details

1. SessionStart — load + cleanup

Fires when the agent starts. The script (load-index.js) does:

  1. Run resolve-project.js to compute the current project name from cwd
  2. Scan short/ (user + project): items untouched for 7 days → delete
  3. Scan long/ (user + project): items untouched for 60 days → mark [review]; [review] items untouched 30 more days → delete
  4. Sync INDEX.md with long/ directory (remove stale entries, add missing ones)
  5. Read ~/.collie/memory/user/INDEX.md and ~/.collie/memory/projects/<project>/INDEX.md
  6. Output both INDEX contents for injection into agent context

Agent starts every session knowing who the user is, what this project needs, and with stale memories already pruned.

2. UserPromptSubmit — capture (blocking, < 10ms)

Fires on every user message. The script (capture-message.js) does:

  • Append user message to ~/.collie/memory/sessions/<session-id>.jsonl
  • Count lines in the session log

When line count is a multiple of 20, output a prompt telling the agent to invoke the memory skill and evaluate recent messages against the decision tree.

No separate counter file. The session log is the single source of truth. No regex, no analysis, no LLM. Pure file append + line count check.

3. PostToolUse (Read) — access reinforcement

Fires after every Read tool call. The script (bump-access.js) does:

  1. Check if the file path is under ~/.collie/memory/
  2. Yes → update last_accessed = today and access_count++ in the file's frontmatter
  3. No → no-op

This ensures memories that are actively referenced stay promoted and don't get pruned.

4. PreCompact — mid-session consume (no delete)

Fires before context compression. Output the session log path and invoke memory skill. The agent:

  • Loads this SKILL.md
  • Reads the session log
  • Runs the decision tree
  • Writes any new memories

The session log is not deleted (session is still ongoing). Acts as insurance for long sessions where context compression would otherwise lose information.

5. Stop — consolidate only (no agent prompt)

Fires when the session ends. Stop hooks cannot inject prompts into Claude (no hookSpecificOutput support; decision: "block" would prevent session exit). The script runs consolidate.js synchronously:

  • Promote: short/ items with access_count ≥ 3 across 2+ sessions → move to long/, add to INDEX.md
  • Merge: long/ items with overlapping content → combine into one

Memory capture (decision tree) relies on hooks #2 (every 20 messages) and #4 (PreCompact). Stop only does structural maintenance.

Why this works

The session log solves the compaction information loss problem. Even after multiple context compressions, the raw user messages are preserved in the log file. The agent evaluates against the complete record, not just what's left in context.

Decision Tree

Run this on every candidate piece of information. No shortcuts.

STEP 0 — Hard veto (any hit → discard, stop)
  □ User is asking a knowledge question
  □ User is requesting an in-session operation
  □ Info is visible in code / git log / docs
  □ Info is a specific debug conclusion (expires when fixed)

STEP 1 — Future behavior test
  "If next session doesn't know this, what happens?"
  · Would repeat the same mistake → STORE
  · Would mistreat the user → STORE
  · Would waste time re-researching → STORE
  · Nothing different → discard, stop

STEP 2 — Dedup
  Search the target scope (user/ or projects/<project>/) for similar memory
  · Found → update existing (edit, don't create new), stop
  · Not found → continue

STEP 3 — Classify (pick one, determines write scope)
  a. User corrected agent behavior → feedback → user/
  b. User role / preference / workflow → user → user/
  c. Non-obvious project constraint → project → projects/<project>/
  d. External system location / purpose → reference → scope by content
  e. None of the above → discard, stop

STEP 4 — Write to short/
  Create file in the target scope's short/ directory.

Consolidation

Consolidation is fully integrated into hooks — no cron, no manual steps required.

SessionStart hook (cleanup):

  1. Prune short/: items untouched 7 days → delete
  2. Prune long/: items untouched 60 days → mark [review]; [review] untouched 30 more days → delete
  3. Sync INDEX.md ↔ long/ directory consistency

Stop hook (promote + merge):

  1. Promote: short/ item with access_count ≥ 3 across 2+ sessions → move to long/, add to INDEX.md
  2. Merge: long/ items with overlapping content → combine into one

The PostToolUse(Read) hook keeps access_count accurate so promotion thresholds are meaningful.

Read & Update

Read triggers

WhenWhat
Session startBoth INDEX files loaded via SessionStart hook
Mid-conversationRead specific long/ file when topic is relevant
Before writingSearch short/ + long/ in target scope for dedup (Step 2)

On every read → last_accessed and access_count updated automatically by PostToolUse(Read) hook.

Update (on access)

When referencing an existing memory and new context exists:

  • Contradicts old content → rewrite
  • Supplements old content → extend
  • No new context → just bump timestamps (hook handles this automatically)

Always Edit existing file. Never create a duplicate.

Multi-Agent Adaptation

This skill is agent-agnostic. The decision tree and lifecycle rules apply to any agent. Platform-specific differences are isolated to hooks and scripts.

Hook configs per agent

AgentHook configInstall location
Claude Codehooks/hooks.json~/.claude/settings.json
Cursorhooks/hooks-cursor.jsonCursor config
Codeflickerhooks/hooks-codeflicker.jsonCodeflicker config

Scripts (deterministic logic only — no LLM judgment)

ScriptPurpose
hooks/memory/resolve-project.jscwd → project directory name
hooks/memory/capture-message.jsAppend to session log; trigger memory skill every 20 lines (UserPromptSubmit)
hooks/memory/load-index.jsCleanup stale memories + read INDEX files + output for injection (SessionStart)
hooks/memory/bump-access.jsUpdate last_accessed + access_count on Read tool use (PostToolUse)
hooks/memory/write-memory.jsCreate memory file with frontmatter in correct scope
hooks/memory/search-memory.jsGrep short/ + long/ for dedup candidates
hooks/memory/consolidate.jsPromote short→long, merge long duplicates, prune stale, sync index

Tool name mapping

Skills reference tools by intent. Platform adapters map to actual tool names:

IntentClaude CodeCursorCodex
Read fileReadread_fileread_file
Write fileWritewrite_filewrite_file
Edit fileEditedit_filereplace
Search filesGrep / Bashgrep_searchgrep_search

Keep looking

Skills are one crate of 627,801. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.