universal-agent-memory 2.9.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/bin/cli.js +27 -2
  2. package/dist/bin/cli.js.map +1 -1
  3. package/dist/cli/hooks.d.ts +7 -0
  4. package/dist/cli/hooks.d.ts.map +1 -0
  5. package/dist/cli/hooks.js +127 -0
  6. package/dist/cli/hooks.js.map +1 -0
  7. package/dist/cli/memory.d.ts +4 -1
  8. package/dist/cli/memory.d.ts.map +1 -1
  9. package/dist/cli/memory.js +248 -5
  10. package/dist/cli/memory.js.map +1 -1
  11. package/dist/coordination/service.d.ts +2 -0
  12. package/dist/coordination/service.d.ts.map +1 -1
  13. package/dist/coordination/service.js +13 -1
  14. package/dist/coordination/service.js.map +1 -1
  15. package/dist/index.d.ts +10 -0
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +10 -0
  18. package/dist/index.js.map +1 -1
  19. package/dist/memory/agent-scoped-memory.d.ts +67 -0
  20. package/dist/memory/agent-scoped-memory.d.ts.map +1 -0
  21. package/dist/memory/agent-scoped-memory.js +126 -0
  22. package/dist/memory/agent-scoped-memory.js.map +1 -0
  23. package/dist/memory/correction-propagator.d.ts +44 -0
  24. package/dist/memory/correction-propagator.d.ts.map +1 -0
  25. package/dist/memory/correction-propagator.js +156 -0
  26. package/dist/memory/correction-propagator.js.map +1 -0
  27. package/dist/memory/daily-log.d.ts +67 -0
  28. package/dist/memory/daily-log.d.ts.map +1 -0
  29. package/dist/memory/daily-log.js +143 -0
  30. package/dist/memory/daily-log.js.map +1 -0
  31. package/dist/memory/hierarchical-memory.d.ts +12 -0
  32. package/dist/memory/hierarchical-memory.d.ts.map +1 -1
  33. package/dist/memory/hierarchical-memory.js +68 -0
  34. package/dist/memory/hierarchical-memory.js.map +1 -1
  35. package/dist/memory/memory-maintenance.d.ts +39 -0
  36. package/dist/memory/memory-maintenance.d.ts.map +1 -0
  37. package/dist/memory/memory-maintenance.js +305 -0
  38. package/dist/memory/memory-maintenance.js.map +1 -0
  39. package/dist/memory/write-gate.d.ts +39 -0
  40. package/dist/memory/write-gate.d.ts.map +1 -0
  41. package/dist/memory/write-gate.js +190 -0
  42. package/dist/memory/write-gate.js.map +1 -0
  43. package/package.json +1 -1
  44. package/templates/CLAUDE.template.md +29 -29
  45. package/templates/SCHEMA.md +57 -0
  46. package/templates/hooks/pre-compact.sh +40 -0
  47. package/templates/hooks/session-start.sh +66 -0
@@ -740,9 +740,11 @@ uam agent status # Check other active agents
740
740
 
741
741
  ## MULTI-AGENT COORDINATION PROTOCOL
742
742
 
743
- **Parallel-first rule**: When safe, run independent tool calls in parallel (searches, reads, status checks) and invoke multiple subagents concurrently for review. Optimize for fewer turns and lower tokens without losing accuracy.
743
+ **Skip this section for single-agent sessions.** Only activate when multiple agents work concurrently (e.g., parallel subagents via Task tool, or multiple Claude Code sessions on same repo).
744
744
 
745
- ### Before Claiming Any Work
745
+ **Parallel-first rule**: When safe, run independent tool calls in parallel (searches, reads, status checks) and invoke multiple subagents concurrently for review.
746
+
747
+ ### Before Claiming Any Work (multi-agent only)
746
748
 
747
749
  ```bash
748
750
  uam agent overlaps --resource "<files-or-directories>"
@@ -750,13 +752,12 @@ uam agent overlaps --resource "<files-or-directories>"
750
752
 
751
753
  ### Overlap Response Matrix
752
754
 
753
- | Risk Level | Action | Rationale |
754
- |------------|--------|-----------|
755
- | `none` | Proceed immediately | No conflict possible |
756
- | `low` | Proceed, note merge order | Different files/sections |
757
- | `medium` | Announce, coordinate sections | Same directory |
758
- | `high` | Wait or split work | Same file, different sections |
759
- | `critical` | STOP - request handoff | Same file, same sections |
755
+ | Risk Level | Action |
756
+ |------------|--------|
757
+ | `none` | Proceed immediately |
758
+ | `low` | Proceed, note merge order |
759
+ | `medium` | Announce, coordinate sections |
760
+ | `high`/`critical` | Wait or split work |
760
761
 
761
762
  ### Agent Capability Routing
762
763
 
@@ -786,21 +787,11 @@ uam agent overlaps --resource "<files-or-directories>"
786
787
 
787
788
  ## MULTI-AGENT EXECUTION (DEPENDENCY-AWARE)
788
789
 
789
- **Goal**: Finish faster by parallelizing independent work while preserving correctness and avoiding conflicts.
790
-
791
- **Aggressive parallelization mandate**: Default to multi-agent execution whenever tasks can be safely decomposed; only stay single-threaded when dependencies or overlap risk make parallel work unsafe.
792
-
793
- **Process**:
794
- 1. **Decompose** the request into discrete work items with clear inputs/outputs.
795
- 2. **Map dependencies** (A blocks B). Only run B after A is complete.
796
- 3. **Parallelize** dependency-free items with separate agents and explicit file boundaries.
797
- 4. **Gate edits** with `uam agent overlaps --resource "<files>"` before touching any file.
798
- 5. **Merge in dependency order** (upstream first). Rebase or re-run dependent steps if needed.
799
-
800
- **Conflict avoidance**:
801
- - One agent per file at a time
802
- - Declare file ownership in prompts
803
- - If overlap risk is high, wait or split by section
790
+ **Skip for single-agent sessions.** When using parallel subagents:
791
+ 1. **Decompose** into discrete work items. **Map dependencies** (A blocks B).
792
+ 2. **Parallelize** dependency-free items with separate agents and explicit file boundaries.
793
+ 3. **Gate edits** with `uam agent overlaps --resource "<files>"` before touching any file.
794
+ 4. **Merge in dependency order** (upstream first).
804
795
 
805
796
  ---
806
797
 
@@ -882,13 +873,19 @@ effective_importance = importance * (0.95 ^ days_since_access)
882
873
 
883
874
  ## WORKTREE WORKFLOW
884
875
 
885
- **ALL code changes use worktrees. NO EXCEPTIONS.**
876
+ **Use worktrees for multi-file features/refactors. Skip for single-file fixes.**
877
+
878
+ | Change Scope | Workflow |
879
+ |-------------|----------|
880
+ | Single-file fix (<20 lines) | Direct commit to feature branch, no worktree needed |
881
+ | Multi-file change (2-5 files) | Worktree recommended if touching shared interfaces |
882
+ | Feature/refactor (3+ files, new feature) | Worktree required |
883
+ | CLAUDE.md or config changes | Worktree required |
886
884
 
887
885
  ```bash
888
- # Create
886
+ # Create (when needed)
889
887
  {{WORKTREE_CREATE_CMD}} <slug>
890
888
  cd {{WORKTREE_DIR}}/NNN-<slug>/
891
- pwd | grep -q "{{WORKTREE_DIR}}" || echo "STOP!" # Verify location
892
889
 
893
890
  # Work
894
891
  git add -A && git commit -m "type: description"
@@ -896,7 +893,7 @@ git add -A && git commit -m "type: description"
896
893
  # PR (runs tests, triggers parallel reviewers)
897
894
  {{WORKTREE_PR_CMD}} <id>
898
895
 
899
- # Cleanup
896
+ # Cleanup (ALWAYS cleanup after merge)
900
897
  {{WORKTREE_CLEANUP_CMD}} <id>
901
898
  ```
902
899
 
@@ -934,10 +931,13 @@ Task(subagent_type: "documentation-expert", prompt: "Check: <files>")
934
931
  | work request (fix/add/change/update/create/implement/build) | `uam task create --type task` |
935
932
  | bug report/error | `uam task create --type bug` |
936
933
  | feature request | `uam task create --type feature` |
937
- | code file for editing | check overlaps -> skills -> worktree |
934
+ | single-file fix | direct commit to branch, skip worktree |
935
+ | multi-file feature (3+ files) | create worktree, then work |
938
936
  | review/check/look | query memory first |
939
937
  | ANY code change | tests required |
940
938
 
939
+ **Agent coordination**: Only use `uam agent` commands when multiple agents are active concurrently. For single-agent sessions (most common), skip agent registration and overlap checks.
940
+
941
941
  ---
942
942
 
943
943
  ## UAM VISUAL STATUS FEEDBACK (MANDATORY WHEN UAM IS ACTIVE)
@@ -0,0 +1,57 @@
1
+ # UAM Memory Schema
2
+
3
+ > Loaded every session alongside working memory. Teaches the agent how the memory system works.
4
+
5
+ ## Memory Tiers
6
+
7
+ | Tier | Storage | Latency | Loaded |
8
+ |------|---------|---------|--------|
9
+ | L1 Working | SQLite `memories` | <1ms | Always (last 50) |
10
+ | L2 Session | SQLite `session_memories` | <5ms | Current session |
11
+ | L3 Semantic | Qdrant vectors | ~50ms | On-demand search |
12
+ | L4 Graph | SQLite `entities`/`relationships` | <20ms | On-demand |
13
+ | Daily Log | SQLite `daily_log` | <1ms | Today + yesterday |
14
+
15
+ ## Write Rules
16
+
17
+ **Write Gate**: Before storing anything, it must pass at least one criterion:
18
+ 1. Changes future behavior (preference, boundary, recurring pattern)
19
+ 2. Commitment with consequences (deadline, deliverable, follow-up)
20
+ 3. Decision with rationale (why X over Y)
21
+ 4. Stable recurring fact (not transient, will matter again)
22
+ 5. Explicit "remember this" request
23
+
24
+ **Default destination**: Daily log first. Promote to permanent memory later.
25
+
26
+ **Never**: silently overwrite. Mark old entries `[superseded]` with date and reason.
27
+
28
+ ## Read Rules
29
+
30
+ - Working memory and this schema are always loaded
31
+ - Daily log checked for today and yesterday
32
+ - Registers/semantic memory searched on demand when topic is relevant
33
+ - Use `uam memory query` for anything older
34
+
35
+ ## When to Write
36
+
37
+ | Trigger | Destination |
38
+ |---------|-------------|
39
+ | User says "remember" | Daily log + maybe working memory |
40
+ | User corrects you | Supersede old + write corrected across all tiers |
41
+ | Decision with rationale | Daily log, promote if durable |
42
+ | Preference expressed | Daily log, promote to working memory |
43
+ | Commitment/deadline | Daily log + working memory |
44
+ | Debugging details | **DISCARD** |
45
+ | Transient state | **DISCARD** |
46
+ | Acknowledgments | **DISCARD** |
47
+
48
+ ## Correction Protocol
49
+
50
+ When corrected: (1) find original, (2) mark superseded with reason, (3) write corrected version to daily log + working memory + semantic memory, (4) verify next session.
51
+
52
+ ## Maintenance
53
+
54
+ - Memories decay: `effective_importance = importance * (0.95 ^ days_since_access)`
55
+ - Consolidation triggers every 10 new entries
56
+ - Stale entries (>14 days unaccessed) auto-demote from hot to warm tier
57
+ - Run `uam memory maintain` periodically for health checks
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env bash
2
+ # UAM Pre-Compact Hook for Claude Code
3
+ # 1. Writes a timestamp marker to the daily log before context compaction
4
+ # 2. Marks any agents registered by this session as completed
5
+ # Fails safely - never blocks the agent.
6
+ set -euo pipefail
7
+
8
+ PROJECT_DIR="${CLAUDE_PROJECT_DIR:-.}"
9
+ DB_PATH="${PROJECT_DIR}/agents/data/memory/short_term.db"
10
+ COORD_DB="${PROJECT_DIR}/agents/data/coordination/coordination.db"
11
+
12
+ if [ ! -f "$DB_PATH" ]; then
13
+ exit 0
14
+ fi
15
+
16
+ TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
17
+
18
+ # Record a compaction marker in memory so sessions can detect context resets
19
+ sqlite3 "$DB_PATH" "
20
+ INSERT OR IGNORE INTO memories (timestamp, type, content)
21
+ VALUES ('$TIMESTAMP', 'action', '[pre-compact] Context compaction at $TIMESTAMP');
22
+ " 2>/dev/null || true
23
+
24
+ # Clean up agents with recent heartbeats (likely from this session being compacted)
25
+ # Mark as completed, release their claims
26
+ if [ -f "$COORD_DB" ]; then
27
+ sqlite3 "$COORD_DB" "
28
+ DELETE FROM work_claims WHERE agent_id IN (
29
+ SELECT id FROM agent_registry
30
+ WHERE status='active' AND last_heartbeat >= datetime('now','-5 minutes')
31
+ );
32
+ UPDATE work_announcements SET completed_at='$TIMESTAMP'
33
+ WHERE completed_at IS NULL AND agent_id IN (
34
+ SELECT id FROM agent_registry
35
+ WHERE status='active' AND last_heartbeat >= datetime('now','-5 minutes')
36
+ );
37
+ UPDATE agent_registry SET status='completed'
38
+ WHERE status='active' AND last_heartbeat >= datetime('now','-5 minutes');
39
+ " 2>/dev/null || true
40
+ fi
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env bash
2
+ # UAM Session Start Hook for Claude Code
3
+ # 1. Cleans stale agents (heartbeat >24h old)
4
+ # 2. Injects open loops and recent daily context
5
+ # Fails safely - never blocks the agent.
6
+ set -euo pipefail
7
+
8
+ PROJECT_DIR="${CLAUDE_PROJECT_DIR:-.}"
9
+ DB_PATH="${PROJECT_DIR}/agents/data/memory/short_term.db"
10
+ COORD_DB="${PROJECT_DIR}/agents/data/coordination/coordination.db"
11
+
12
+ if [ ! -f "$DB_PATH" ]; then
13
+ exit 0
14
+ fi
15
+
16
+ # Clean stale agents from coordination DB (heartbeat >24h old)
17
+ if [ -f "$COORD_DB" ]; then
18
+ sqlite3 "$COORD_DB" "
19
+ DELETE FROM work_claims WHERE agent_id IN (
20
+ SELECT id FROM agent_registry
21
+ WHERE status IN ('active','idle') AND last_heartbeat < datetime('now','-24 hours')
22
+ );
23
+ DELETE FROM work_announcements WHERE agent_id IN (
24
+ SELECT id FROM agent_registry
25
+ WHERE status IN ('active','idle') AND last_heartbeat < datetime('now','-24 hours')
26
+ ) AND completed_at IS NULL;
27
+ UPDATE agent_registry SET status='failed'
28
+ WHERE status IN ('active','idle') AND last_heartbeat < datetime('now','-24 hours');
29
+ DELETE FROM agent_registry
30
+ WHERE status IN ('completed','failed') AND started_at < datetime('now','-7 days');
31
+ DELETE FROM agent_messages WHERE created_at < datetime('now','-24 hours');
32
+ " 2>/dev/null || true
33
+ fi
34
+
35
+ output=""
36
+
37
+ # Recent memories (last 24h, high importance)
38
+ recent=$(sqlite3 "$DB_PATH" "
39
+ SELECT type, content FROM memories
40
+ WHERE timestamp >= datetime('now', '-1 day')
41
+ ORDER BY id DESC
42
+ LIMIT 10;
43
+ " 2>/dev/null || true)
44
+
45
+ if [ -n "$recent" ]; then
46
+ output+="## Recent Memory Context"$'\n'
47
+ output+="$recent"$'\n\n'
48
+ fi
49
+
50
+ # Open loops from session memories
51
+ open_loops=$(sqlite3 "$DB_PATH" "
52
+ SELECT content FROM session_memories
53
+ WHERE type IN ('action','goal','decision')
54
+ AND importance >= 7
55
+ ORDER BY id DESC
56
+ LIMIT 5;
57
+ " 2>/dev/null || true)
58
+
59
+ if [ -n "$open_loops" ]; then
60
+ output+="## Open Loops"$'\n'
61
+ output+="$open_loops"$'\n'
62
+ fi
63
+
64
+ if [ -n "$output" ]; then
65
+ echo "$output"
66
+ fi