context-mode 1.0.98 → 1.0.100

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 (56) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.openclaw-plugin/openclaw.plugin.json +1 -1
  4. package/.openclaw-plugin/package.json +1 -1
  5. package/README.md +9 -7
  6. package/build/adapters/claude-code-base.js +4 -4
  7. package/build/adapters/codex/index.js +23 -1
  8. package/build/adapters/qwen-code/index.d.ts +1 -1
  9. package/build/adapters/qwen-code/index.js +110 -4
  10. package/build/cli.js +2 -0
  11. package/build/opencode-plugin.js +1 -1
  12. package/build/pi-extension.js +1 -1
  13. package/build/search/auto-memory.d.ts +29 -0
  14. package/build/search/auto-memory.js +121 -0
  15. package/build/search/unified.d.ts +41 -0
  16. package/build/search/unified.js +89 -0
  17. package/build/server.js +88 -40
  18. package/build/session/analytics.js +1 -1
  19. package/build/session/db.d.ts +17 -0
  20. package/build/session/db.js +28 -0
  21. package/build/session/extract.d.ts +4 -0
  22. package/build/session/extract.js +232 -1
  23. package/build/session/snapshot.js +31 -0
  24. package/build/store.js +118 -8
  25. package/build/types.d.ts +1 -0
  26. package/cli.bundle.mjs +260 -125
  27. package/configs/claude-code/CLAUDE.md +21 -1
  28. package/configs/codex/AGENTS.md +23 -2
  29. package/configs/codex/hooks.json +14 -0
  30. package/configs/cursor/context-mode.mdc +18 -1
  31. package/configs/gemini-cli/GEMINI.md +22 -1
  32. package/configs/jetbrains-copilot/copilot-instructions.md +22 -1
  33. package/configs/kilo/AGENTS.md +19 -2
  34. package/configs/kiro/KIRO.md +18 -1
  35. package/configs/openclaw/AGENTS.md +22 -2
  36. package/configs/opencode/AGENTS.md +18 -1
  37. package/configs/pi/AGENTS.md +18 -1
  38. package/configs/qwen-code/QWEN.md +38 -18
  39. package/configs/vscode-copilot/copilot-instructions.md +22 -1
  40. package/hooks/auto-injection.mjs +76 -0
  41. package/hooks/codex/stop.mjs +43 -0
  42. package/hooks/codex/userpromptsubmit.mjs +75 -0
  43. package/hooks/core/mcp-ready.mjs +7 -1
  44. package/hooks/posttooluse.mjs +50 -1
  45. package/hooks/precompact.mjs +9 -0
  46. package/hooks/pretooluse.mjs +27 -0
  47. package/hooks/routing-block.mjs +7 -1
  48. package/hooks/session-db.bundle.mjs +19 -13
  49. package/hooks/session-extract.bundle.mjs +2 -2
  50. package/hooks/session-snapshot.bundle.mjs +18 -17
  51. package/hooks/sessionstart.mjs +17 -0
  52. package/hooks/userpromptsubmit.mjs +1 -1
  53. package/openclaw.plugin.json +1 -1
  54. package/package.json +1 -1
  55. package/server.bundle.mjs +228 -93
  56. package/skills/context-mode-ops/agent-teams.md +1 -1
@@ -33,8 +33,9 @@ Use `ctx_execute(language: "shell", code: "grep ...")` in sandbox.
33
33
 
34
34
  ## Tool selection
35
35
 
36
+ 0. **MEMORY**: `ctx_search(sort: "timeline")` — after resume, check prior context before asking user.
36
37
  1. **GATHER**: `ctx_batch_execute(commands, queries)` — runs all commands, auto-indexes, returns search. ONE call replaces 30+. Each command: `{label: "header", command: "..."}`.
37
- 2. **FOLLOW-UP**: `ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call.
38
+ 2. **FOLLOW-UP**: `ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call (default relevance mode).
38
39
  3. **PROCESSING**: `ctx_execute(language, code)` | `ctx_execute_file(path, language, code)` — sandbox, only stdout enters context.
39
40
  4. **WEB**: `ctx_fetch_and_index(url, source)` then `ctx_search(queries)` — raw HTML never enters context.
40
41
  5. **INDEX**: `ctx_index(content, source)` — store in FTS5 for later search.
@@ -51,6 +52,25 @@ Pattern: [thing] [action] [reason]. [next step]. Auto-expand for: security warni
51
52
  Write artifacts to FILES — never inline. Return: file path + 1-line description.
52
53
  Descriptive source labels for `ctx_search(source: "label")`.
53
54
 
55
+ ## Session Continuity
56
+
57
+ Skills, roles, and decisions persist for the entire session. Do not abandon them as the conversation grows.
58
+
59
+ ## Memory
60
+
61
+ Session history is persistent and searchable. On resume, search BEFORE asking the user:
62
+
63
+ | Need | Command |
64
+ |------|---------|
65
+ | What were we working on? | `ctx_search(queries: ["summary"], source: "compaction", sort: "timeline")` |
66
+ | What was the first request? | `ctx_search(queries: ["prompt"], source: "user-prompt", sort: "timeline")` |
67
+ | What did we decide? | `ctx_search(queries: ["decision"], source: "decision", sort: "timeline")` |
68
+ | What NOT to repeat? | `ctx_search(queries: ["rejected"], source: "rejected-approach")` |
69
+ | What constraints exist? | `ctx_search(queries: ["constraint"], source: "constraint")` |
70
+
71
+ DO NOT ask "what were we working on?" — SEARCH FIRST.
72
+ If search returns 0 results, proceed as a fresh session.
73
+
54
74
  ## ctx commands
55
75
 
56
76
  | Command | Action |
@@ -34,8 +34,9 @@ Use `ctx_execute(language: "shell", code: "grep ...")` in sandbox.
34
34
 
35
35
  ## Tool selection
36
36
 
37
+ 0. **MEMORY**: `ctx_search(sort: "timeline")` — after resume, check prior context before asking user.
37
38
  1. **GATHER**: `ctx_batch_execute(commands, queries)` — runs all commands, auto-indexes, returns search. ONE call replaces 30+. Each command: `{label: "header", command: "..."}`.
38
- 2. **FOLLOW-UP**: `ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call.
39
+ 2. **FOLLOW-UP**: `ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call (default relevance mode).
39
40
  3. **PROCESSING**: `ctx_execute(language, code)` | `ctx_execute_file(path, language, code)` — sandbox, only stdout enters context.
40
41
  4. **WEB**: `ctx_fetch_and_index(url, source)` then `ctx_search(queries)` — raw HTML never enters context.
41
42
  5. **INDEX**: `ctx_index(content, source)` — store in FTS5 for later search.
@@ -46,7 +47,27 @@ Terse like caveman. Technical substance exact. Only fluff die.
46
47
  Drop: articles, filler (just/really/basically), pleasantries, hedging. Fragments OK. Short synonyms. Code unchanged.
47
48
  Pattern: [thing] [action] [reason]. [next step]. Auto-expand for: security warnings, irreversible actions, user confusion.
48
49
  Write artifacts to FILES — never inline. Return: file path + 1-line description.
49
- Descriptive source labels for `search(source: "label")`.
50
+ Descriptive source labels for `ctx_search(source: "label")`.
51
+
52
+ ## Session Continuity
53
+
54
+ Skills, roles, and decisions persist for the entire session. Do not abandon them as the conversation grows.
55
+
56
+ ## Memory
57
+
58
+ Session history is persistent and searchable. On resume, search BEFORE asking the user:
59
+
60
+ | Need | Command |
61
+ |------|---------|
62
+ | What were we working on? | `ctx_search(queries: ["summary"], source: "compaction", sort: "timeline")` |
63
+ | What did we decide? | `ctx_search(queries: ["decision"], source: "decision", sort: "timeline")` |
64
+ | What NOT to repeat? | `ctx_search(queries: ["rejected"], source: "rejected-approach")` |
65
+ | What constraints exist? | `ctx_search(queries: ["constraint"], source: "constraint")` |
66
+
67
+ Note: user-prompt history not available.
68
+
69
+ DO NOT ask "what were we working on?" — SEARCH FIRST.
70
+ If search returns 0 results, proceed as a fresh session.
50
71
 
51
72
  ## ctx commands
52
73
 
@@ -20,6 +20,20 @@
20
20
  { "type": "command", "command": "context-mode hook codex sessionstart" }
21
21
  ]
22
22
  }
23
+ ],
24
+ "UserPromptSubmit": [
25
+ {
26
+ "hooks": [
27
+ { "type": "command", "command": "context-mode hook codex userpromptsubmit" }
28
+ ]
29
+ }
30
+ ],
31
+ "Stop": [
32
+ {
33
+ "hooks": [
34
+ { "type": "command", "command": "context-mode hook codex stop" }
35
+ ]
36
+ }
23
37
  ]
24
38
  }
25
39
  }
@@ -13,8 +13,9 @@ Analyze/count/filter/compare/search/parse/transform data: **write code** via `ct
13
13
 
14
14
  ## Tool Selection
15
15
 
16
+ 0. **MEMORY**: `ctx_search(sort: "timeline")` — after resume, check prior context before asking user.
16
17
  1. **GATHER**: `ctx_batch_execute(commands, queries)` — runs all commands, auto-indexes, searches. ONE call replaces many steps.
17
- 2. **FOLLOW-UP**: `ctx_search(queries: ["q1", "q2", ...])` — all follow-up questions, ONE call.
18
+ 2. **FOLLOW-UP**: `ctx_search(queries: ["q1", "q2", ...])` — all follow-up questions, ONE call (default relevance mode).
18
19
  3. **PROCESSING**: `ctx_execute(language, code)` | `ctx_execute_file(path, language, code)` — sandbox, only stdout enters context.
19
20
  4. **WEB**: `ctx_fetch_and_index(url)` then `ctx_search(queries)` — never dump raw HTML.
20
21
  5. **INDEX**: `ctx_index(content, source)` — store in FTS5 for later search.
@@ -39,6 +40,22 @@ Drop: articles, filler (just/really/basically), pleasantries, hedging. Fragments
39
40
  Pattern: [thing] [action] [reason]. [next step]. Auto-expand for: security warnings, irreversible actions, user confusion.
40
41
  Write artifacts to FILES — never inline. Return: file path + 1-line description.
41
42
 
43
+ ## Session Continuity
44
+
45
+ Skills, roles, and decisions persist for the entire session. Do not abandon them as the conversation grows.
46
+
47
+ ## Memory
48
+
49
+ Session history is persistent and searchable. On resume, search BEFORE asking the user:
50
+
51
+ | Need | Command |
52
+ |------|---------|
53
+ | What did we decide? | `ctx_search(queries: ["decision"], source: "decision", sort: "timeline")` |
54
+ | What constraints exist? | `ctx_search(queries: ["constraint"], source: "constraint")` |
55
+
56
+ DO NOT ask "what were we working on?" — SEARCH FIRST.
57
+ If search returns 0 results, proceed as a fresh session.
58
+
42
59
  ## ctx Commands
43
60
 
44
61
  | Command | Action |
@@ -33,8 +33,9 @@ Use `mcp__context-mode__ctx_execute(language: "shell", code: "grep ...")` in san
33
33
 
34
34
  ## Tool selection
35
35
 
36
+ 0. **MEMORY**: `mcp__context-mode__ctx_search(sort: "timeline")` — after resume, check prior context before asking user.
36
37
  1. **GATHER**: `mcp__context-mode__ctx_batch_execute(commands, queries)` — runs all commands, auto-indexes, returns search. ONE call replaces 30+. Each command: `{label: "header", command: "..."}`.
37
- 2. **FOLLOW-UP**: `mcp__context-mode__ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call.
38
+ 2. **FOLLOW-UP**: `mcp__context-mode__ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call (default relevance mode).
38
39
  3. **PROCESSING**: `mcp__context-mode__ctx_execute(language, code)` | `mcp__context-mode__ctx_execute_file(path, language, code)` — sandbox, only stdout enters context.
39
40
  4. **WEB**: `mcp__context-mode__ctx_fetch_and_index(url, source)` then `mcp__context-mode__ctx_search(queries)` — raw HTML never enters context.
40
41
  5. **INDEX**: `mcp__context-mode__ctx_index(content, source)` — store in FTS5 for later search.
@@ -47,6 +48,26 @@ Pattern: [thing] [action] [reason]. [next step]. Auto-expand for: security warni
47
48
  Write artifacts to FILES — never inline. Return: file path + 1-line description.
48
49
  Descriptive source labels for `search(source: "label")`.
49
50
 
51
+ ## Session Continuity
52
+
53
+ Skills, roles, and decisions persist for the entire session. Do not abandon them as the conversation grows.
54
+
55
+ ## Memory
56
+
57
+ Session history is persistent and searchable. On resume, search BEFORE asking the user:
58
+
59
+ | Need | Command |
60
+ |------|---------|
61
+ | What were we working on? | `mcp__context-mode__ctx_search(queries: ["summary"], source: "compaction", sort: "timeline")` |
62
+ | What did we decide? | `mcp__context-mode__ctx_search(queries: ["decision"], source: "decision", sort: "timeline")` |
63
+ | What NOT to repeat? | `mcp__context-mode__ctx_search(queries: ["rejected"], source: "rejected-approach")` |
64
+ | What constraints exist? | `mcp__context-mode__ctx_search(queries: ["constraint"], source: "constraint")` |
65
+
66
+ Note: user-prompt history not available.
67
+
68
+ DO NOT ask "what were we working on?" — SEARCH FIRST.
69
+ If search returns 0 results, proceed as a fresh session.
70
+
50
71
  ## ctx commands
51
72
 
52
73
  | Command | Action |
@@ -33,8 +33,9 @@ Use `ctx_execute(language: "shell", code: "grep ...")` in sandbox.
33
33
 
34
34
  ## Tool selection
35
35
 
36
+ 0. **MEMORY**: `ctx_search(sort: "timeline")` — after resume, check prior context before asking user.
36
37
  1. **GATHER**: `ctx_batch_execute(commands, queries)` — runs all commands, auto-indexes, returns search. ONE call replaces 30+. Each command: `{label: "header", command: "..."}`.
37
- 2. **FOLLOW-UP**: `ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call.
38
+ 2. **FOLLOW-UP**: `ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call (default relevance mode).
38
39
  3. **PROCESSING**: `ctx_execute(language, code)` | `ctx_execute_file(path, language, code)` — sandbox, only stdout enters context.
39
40
  4. **WEB**: `ctx_fetch_and_index(url, source)` then `ctx_search(queries)` — raw HTML never enters context.
40
41
  5. **INDEX**: `ctx_index(content, source)` — store in FTS5 for later search.
@@ -47,6 +48,26 @@ Pattern: [thing] [action] [reason]. [next step]. Auto-expand for: security warni
47
48
  Write artifacts to FILES — never inline. Return: file path + 1-line description.
48
49
  Descriptive source labels for `ctx_search(source: "label")`.
49
50
 
51
+ ## Session Continuity
52
+
53
+ Skills, roles, and decisions persist for the entire session. Do not abandon them as the conversation grows.
54
+
55
+ ## Memory
56
+
57
+ Session history is persistent and searchable. On resume, search BEFORE asking the user:
58
+
59
+ | Need | Command |
60
+ |------|---------|
61
+ | What were we working on? | `ctx_search(queries: ["summary"], source: "compaction", sort: "timeline")` |
62
+ | What did we decide? | `ctx_search(queries: ["decision"], source: "decision", sort: "timeline")` |
63
+ | What NOT to repeat? | `ctx_search(queries: ["rejected"], source: "rejected-approach")` |
64
+ | What constraints exist? | `ctx_search(queries: ["constraint"], source: "constraint")` |
65
+
66
+ Note: user-prompt history not available.
67
+
68
+ DO NOT ask "what were we working on?" — SEARCH FIRST.
69
+ If search returns 0 results, proceed as a fresh session.
70
+
50
71
  ## ctx commands
51
72
 
52
73
  | Command | Action |
@@ -33,8 +33,9 @@ Use `context-mode_ctx_execute(language: "shell", code: "grep ...")` in sandbox.
33
33
 
34
34
  ## Tool selection
35
35
 
36
+ 0. **MEMORY**: `context-mode_ctx_search(sort: "timeline")` — after resume, check prior context before asking user.
36
37
  1. **GATHER**: `context-mode_ctx_batch_execute(commands, queries)` — runs all commands, auto-indexes, returns search. ONE call replaces 30+. Each command: `{label: "header", command: "..."}`.
37
- 2. **FOLLOW-UP**: `context-mode_ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call.
38
+ 2. **FOLLOW-UP**: `context-mode_ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call (default relevance mode).
38
39
  3. **PROCESSING**: `context-mode_ctx_execute(language, code)` | `context-mode_ctx_execute_file(path, language, code)` — sandbox, only stdout enters context.
39
40
  4. **WEB**: `context-mode_ctx_fetch_and_index(url, source)` then `context-mode_ctx_search(queries)` — raw HTML never enters context.
40
41
  5. **INDEX**: `context-mode_ctx_index(content, source)` — store in FTS5 for later search.
@@ -45,7 +46,23 @@ Terse like caveman. Technical substance exact. Only fluff die.
45
46
  Drop: articles, filler (just/really/basically), pleasantries, hedging. Fragments OK. Short synonyms. Code unchanged.
46
47
  Pattern: [thing] [action] [reason]. [next step]. Auto-expand for: security warnings, irreversible actions, user confusion.
47
48
  Write artifacts to FILES — never inline. Return: file path + 1-line description.
48
- Descriptive source labels for `search(source: "label")`.
49
+ Descriptive source labels for `context-mode_ctx_search(source: "label")`.
50
+
51
+ ## Session Continuity
52
+
53
+ Skills, roles, and decisions persist for the entire session. Do not abandon them as the conversation grows.
54
+
55
+ ## Memory
56
+
57
+ Session history is persistent and searchable. On resume, search BEFORE asking the user:
58
+
59
+ | Need | Command |
60
+ |------|---------|
61
+ | What did we decide? | `context-mode_ctx_search(queries: ["decision"], source: "decision", sort: "timeline")` |
62
+ | What constraints exist? | `context-mode_ctx_search(queries: ["constraint"], source: "constraint")` |
63
+
64
+ DO NOT ask "what were we working on?" — SEARCH FIRST.
65
+ If search returns 0 results, proceed as a fresh session.
49
66
 
50
67
  ## ctx commands
51
68
 
@@ -33,8 +33,9 @@ Use `@context-mode/ctx_execute(language: "shell", code: "grep ...")` in sandbox.
33
33
 
34
34
  ## Tool selection
35
35
 
36
+ 0. **MEMORY**: `@context-mode/ctx_search(sort: "timeline")` — after resume, check prior context before asking user.
36
37
  1. **GATHER**: `@context-mode/ctx_batch_execute(commands, queries)` — runs all commands, auto-indexes, returns search. ONE call replaces 30+. Each command: `{label: "header", command: "..."}`.
37
- 2. **FOLLOW-UP**: `@context-mode/ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call.
38
+ 2. **FOLLOW-UP**: `@context-mode/ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call (default relevance mode).
38
39
  3. **PROCESSING**: `@context-mode/ctx_execute(language, code)` | `@context-mode/ctx_execute_file(path, language, code)` — sandbox, only stdout enters context.
39
40
  4. **WEB**: `@context-mode/ctx_fetch_and_index(url, source)` then `@context-mode/ctx_search(queries)` — raw HTML never enters context.
40
41
  5. **INDEX**: `@context-mode/ctx_index(content, source)` — store in FTS5 for later search.
@@ -47,6 +48,22 @@ Pattern: [thing] [action] [reason]. [next step]. Auto-expand for: security warni
47
48
  Write artifacts to FILES — never inline. Return: file path + 1-line description.
48
49
  Descriptive source labels for `search(source: "label")`.
49
50
 
51
+ ## Session Continuity
52
+
53
+ Skills, roles, and decisions persist for the entire session. Do not abandon them as the conversation grows.
54
+
55
+ ## Memory
56
+
57
+ Session history is persistent and searchable. On resume, search BEFORE asking the user:
58
+
59
+ | Need | Command |
60
+ |------|---------|
61
+ | What did we decide? | `@context-mode/ctx_search(queries: ["decision"], source: "decision", sort: "timeline")` |
62
+ | What constraints exist? | `@context-mode/ctx_search(queries: ["constraint"], source: "constraint")` |
63
+
64
+ DO NOT ask "what were we working on?" — SEARCH FIRST.
65
+ If search returns 0 results, proceed as a fresh session.
66
+
50
67
  ## ctx commands
51
68
 
52
69
  | Command | Action |
@@ -33,8 +33,9 @@ Use `context-mode__ctx_execute(language: "shell", code: "grep ...")` in sandbox.
33
33
 
34
34
  ## Tool selection
35
35
 
36
+ 0. **MEMORY**: `context-mode__ctx_search(sort: "timeline")` — after resume, check prior context before asking user.
36
37
  1. **GATHER**: `context-mode__ctx_batch_execute(commands, queries)` — runs all commands, auto-indexes, returns search. ONE call replaces 30+. Each command: `{label: "header", command: "..."}`.
37
- 2. **FOLLOW-UP**: `context-mode__ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call.
38
+ 2. **FOLLOW-UP**: `context-mode__ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call (default relevance mode).
38
39
  3. **PROCESSING**: `context-mode__ctx_execute(language, code)` | `context-mode__ctx_execute_file(path, language, code)` — sandbox, only stdout enters context.
39
40
  4. **WEB**: `context-mode__ctx_fetch_and_index(url, source)` then `context-mode__ctx_search(queries)` — raw HTML never enters context.
40
41
  5. **INDEX**: `context-mode__ctx_index(content, source)` — store in FTS5 for later search.
@@ -45,7 +46,26 @@ Terse like caveman. Technical substance exact. Only fluff die.
45
46
  Drop: articles, filler (just/really/basically), pleasantries, hedging. Fragments OK. Short synonyms. Code unchanged.
46
47
  Pattern: [thing] [action] [reason]. [next step]. Auto-expand for: security warnings, irreversible actions, user confusion.
47
48
  Write artifacts to FILES — never inline. Return: file path + 1-line description.
48
- Descriptive source labels for `search(source: "label")`.
49
+ Descriptive source labels for `context-mode__ctx_search(source: "label")`.
50
+
51
+ ## Session Continuity
52
+
53
+ Skills, roles, and decisions persist for the entire session. Do not abandon them as the conversation grows.
54
+
55
+ ## Memory
56
+
57
+ Session history is persistent and searchable. On resume, search BEFORE asking the user:
58
+
59
+ | Need | Command |
60
+ |------|---------|
61
+ | What were we working on? | `context-mode__ctx_search(queries: ["summary"], source: "compaction", sort: "timeline")` |
62
+ | What was the first request? | `context-mode__ctx_search(queries: ["prompt"], source: "user-prompt", sort: "timeline")` |
63
+ | What did we decide? | `context-mode__ctx_search(queries: ["decision"], source: "decision", sort: "timeline")` |
64
+ | What NOT to repeat? | `context-mode__ctx_search(queries: ["rejected"], source: "rejected-approach")` |
65
+ | What constraints exist? | `context-mode__ctx_search(queries: ["constraint"], source: "constraint")` |
66
+
67
+ DO NOT ask "what were we working on?" — SEARCH FIRST.
68
+ If search returns 0 results, proceed as a fresh session.
49
69
 
50
70
  ## ctx commands
51
71
 
@@ -33,8 +33,9 @@ Use `context-mode_ctx_execute(language: "shell", code: "grep ...")` in sandbox.
33
33
 
34
34
  ## Tool selection
35
35
 
36
+ 0. **MEMORY**: `context-mode_ctx_search(sort: "timeline")` — after resume, check prior context before asking user.
36
37
  1. **GATHER**: `context-mode_ctx_batch_execute(commands, queries)` — runs all commands, auto-indexes, returns search. ONE call replaces 30+. Each command: `{label: "header", command: "..."}`.
37
- 2. **FOLLOW-UP**: `context-mode_ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call.
38
+ 2. **FOLLOW-UP**: `context-mode_ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call (default relevance mode).
38
39
  3. **PROCESSING**: `context-mode_ctx_execute(language, code)` | `context-mode_ctx_execute_file(path, language, code)` — sandbox, only stdout enters context.
39
40
  4. **WEB**: `context-mode_ctx_fetch_and_index(url, source)` then `context-mode_ctx_search(queries)` — raw HTML never enters context.
40
41
  5. **INDEX**: `context-mode_ctx_index(content, source)` — store in FTS5 for later search.
@@ -47,6 +48,22 @@ Pattern: [thing] [action] [reason]. [next step]. Auto-expand for: security warni
47
48
  Write artifacts to FILES — never inline. Return: file path + 1-line description.
48
49
  Descriptive source labels for `search(source: "label")`.
49
50
 
51
+ ## Session Continuity
52
+
53
+ Skills, roles, and decisions persist for the entire session. Do not abandon them as the conversation grows.
54
+
55
+ ## Memory
56
+
57
+ Session history is persistent and searchable. On resume, search BEFORE asking the user:
58
+
59
+ | Need | Command |
60
+ |------|---------|
61
+ | What did we decide? | `context-mode_ctx_search(queries: ["decision"], source: "decision", sort: "timeline")` |
62
+ | What constraints exist? | `context-mode_ctx_search(queries: ["constraint"], source: "constraint")` |
63
+
64
+ DO NOT ask "what were we working on?" — SEARCH FIRST.
65
+ If search returns 0 results, proceed as a fresh session.
66
+
50
67
  ## ctx commands
51
68
 
52
69
  | Command | Action |
@@ -34,8 +34,9 @@ Use `ctx_execute(language: "shell", code: "grep ...")` in sandbox.
34
34
 
35
35
  ## Tool selection
36
36
 
37
+ 0. **MEMORY**: `ctx_search(sort: "timeline")` — after resume, check prior context before asking user.
37
38
  1. **GATHER**: `ctx_batch_execute(commands, queries)` — runs all commands, auto-indexes, returns search. ONE call replaces 30+. Each command: `{label: "header", command: "..."}`.
38
- 2. **FOLLOW-UP**: `ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call.
39
+ 2. **FOLLOW-UP**: `ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call (default relevance mode).
39
40
  3. **PROCESSING**: `ctx_execute(language, code)` | `ctx_execute_file(path, language, code)` — sandbox, only stdout enters context.
40
41
  4. **WEB**: `ctx_fetch_and_index(url, source)` then `ctx_search(queries)` — raw HTML never enters context.
41
42
  5. **INDEX**: `ctx_index(content, source)` — store in FTS5 for later search.
@@ -48,6 +49,22 @@ Pattern: [thing] [action] [reason]. [next step]. Auto-expand for: security warni
48
49
  Write artifacts to FILES — never inline. Return: file path + 1-line description.
49
50
  Descriptive source labels for `search(source: "label")`.
50
51
 
52
+ ## Session Continuity
53
+
54
+ Skills, roles, and decisions persist for the entire session. Do not abandon them as the conversation grows.
55
+
56
+ ## Memory
57
+
58
+ Session history is persistent and searchable. On resume, search BEFORE asking the user:
59
+
60
+ | Need | Command |
61
+ |------|---------|
62
+ | What did we decide? | `ctx_search(queries: ["decision"], source: "decision", sort: "timeline")` |
63
+ | What constraints exist? | `ctx_search(queries: ["constraint"], source: "constraint")` |
64
+
65
+ DO NOT ask "what were we working on?" — SEARCH FIRST.
66
+ If search returns 0 results, proceed as a fresh session.
67
+
51
68
  ## ctx commands
52
69
 
53
70
  | Command | Action |
@@ -4,40 +4,41 @@ context-mode MCP tools available. Rules protect context window from flooding. On
4
4
 
5
5
  ## Think in Code — MANDATORY
6
6
 
7
- Analyze/count/filter/compare/search/parse/transform data: **write code** via `ctx_execute(language, code)`, `console.log()` only the answer. Do NOT read raw data into context. PROGRAM the analysis, not COMPUTE it. Pure JavaScript — Node.js built-ins only (`fs`, `path`, `child_process`). `try/catch`, handle `null`/`undefined`. One script replaces ten tool calls.
7
+ Analyze/count/filter/compare/search/parse/transform data: **write code** via `mcp__context-mode__ctx_execute(language, code)`, `console.log()` only the answer. Do NOT read raw data into context. PROGRAM the analysis, not COMPUTE it. Pure JavaScript — Node.js built-ins only (`fs`, `path`, `child_process`). `try/catch`, handle `null`/`undefined`. One script replaces ten tool calls.
8
8
 
9
9
  ## BLOCKED — do NOT attempt
10
10
 
11
11
  ### curl / wget — BLOCKED
12
12
  Bash `curl`/`wget` intercepted and replaced with error. Do NOT retry.
13
- Use: `ctx_fetch_and_index(url, source)` or `ctx_execute(language: "javascript", code: "const r = await fetch(...)")`
13
+ Use: `mcp__context-mode__ctx_fetch_and_index(url, source)` or `mcp__context-mode__ctx_execute(language: "javascript", code: "const r = await fetch(...)")`
14
14
 
15
15
  ### Inline HTTP — BLOCKED
16
16
  `fetch('http`, `requests.get(`, `requests.post(`, `http.get(`, `http.request(` — intercepted. Do NOT retry.
17
- Use: `ctx_execute(language, code)` — only stdout enters context
17
+ Use: `mcp__context-mode__ctx_execute(language, code)` — only stdout enters context
18
18
 
19
19
  ### WebFetch — BLOCKED
20
- Use: `ctx_fetch_and_index(url, source)` then `ctx_search(queries)`
20
+ Use: `mcp__context-mode__ctx_fetch_and_index(url, source)` then `mcp__context-mode__ctx_search(queries)`
21
21
 
22
22
  ## REDIRECTED — use sandbox
23
23
 
24
24
  ### Bash (>20 lines output)
25
25
  Bash ONLY for: `git`, `mkdir`, `rm`, `mv`, `cd`, `ls`, `npm install`, `pip install`.
26
- Otherwise: `ctx_batch_execute(commands, queries)` or `ctx_execute(language: "shell", code: "...")`
26
+ Otherwise: `mcp__context-mode__ctx_batch_execute(commands, queries)` or `mcp__context-mode__ctx_execute(language: "shell", code: "...")`
27
27
 
28
28
  ### Read (for analysis)
29
- Reading to **Edit** → Read correct. Reading to **analyze/explore/summarize** → `ctx_execute_file(path, language, code)`.
29
+ Reading to **Edit** → Read correct. Reading to **analyze/explore/summarize** → `mcp__context-mode__ctx_execute_file(path, language, code)`.
30
30
 
31
31
  ### Grep (large results)
32
- Use `ctx_execute(language: "shell", code: "grep ...")` in sandbox.
32
+ Use `mcp__context-mode__ctx_execute(language: "shell", code: "grep ...")` in sandbox.
33
33
 
34
34
  ## Tool selection
35
35
 
36
- 1. **GATHER**: `ctx_batch_execute(commands, queries)` — runs all commands, auto-indexes, returns search. ONE call replaces 30+. Each command: `{label: "header", command: "..."}`.
37
- 2. **FOLLOW-UP**: `ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call.
38
- 3. **PROCESSING**: `ctx_execute(language, code)` | `ctx_execute_file(path, language, code)` — sandbox, only stdout enters context.
39
- 4. **WEB**: `ctx_fetch_and_index(url, source)` then `ctx_search(queries)` — raw HTML never enters context.
40
- 5. **INDEX**: `ctx_index(content, source)` — store in FTS5 for later search.
36
+ 0. **MEMORY**: `mcp__context-mode__ctx_search(sort: "timeline")` — after resume, check prior context before asking user.
37
+ 1. **GATHER**: `mcp__context-mode__ctx_batch_execute(commands, queries)` — runs all commands, auto-indexes, returns search. ONE call replaces 30+. Each command: `{label: "header", command: "..."}`.
38
+ 2. **FOLLOW-UP**: `mcp__context-mode__ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call (default relevance mode).
39
+ 3. **PROCESSING**: `mcp__context-mode__ctx_execute(language, code)` | `mcp__context-mode__ctx_execute_file(path, language, code)` — sandbox, only stdout enters context.
40
+ 4. **WEB**: `mcp__context-mode__ctx_fetch_and_index(url, source)` then `mcp__context-mode__ctx_search(queries)` raw HTML never enters context.
41
+ 5. **INDEX**: `mcp__context-mode__ctx_index(content, source)` — store in FTS5 for later search.
41
42
 
42
43
  ## Subagent routing
43
44
 
@@ -49,15 +50,34 @@ Terse like caveman. Technical substance exact. Only fluff die.
49
50
  Drop: articles, filler (just/really/basically), pleasantries, hedging. Fragments OK. Short synonyms. Code unchanged.
50
51
  Pattern: [thing] [action] [reason]. [next step]. Auto-expand for: security warnings, irreversible actions, user confusion.
51
52
  Write artifacts to FILES — never inline. Return: file path + 1-line description.
52
- Descriptive source labels for `ctx_search(source: "label")`.
53
+ Descriptive source labels for `mcp__context-mode__ctx_search(source: "label")`.
54
+
55
+ ## Session Continuity
56
+
57
+ Skills, roles, and decisions persist for the entire session. Do not abandon them as the conversation grows.
58
+
59
+ ## Memory
60
+
61
+ Session history is persistent and searchable. On resume, search BEFORE asking the user:
62
+
63
+ | Need | Command |
64
+ |------|---------|
65
+ | What were we working on? | `mcp__context-mode__ctx_search(queries: ["summary"], source: "compaction", sort: "timeline")` |
66
+ | What was the first request? | `mcp__context-mode__ctx_search(queries: ["prompt"], source: "user-prompt", sort: "timeline")` |
67
+ | What did we decide? | `mcp__context-mode__ctx_search(queries: ["decision"], source: "decision", sort: "timeline")` |
68
+ | What NOT to repeat? | `mcp__context-mode__ctx_search(queries: ["rejected"], source: "rejected-approach")` |
69
+ | What constraints exist? | `mcp__context-mode__ctx_search(queries: ["constraint"], source: "constraint")` |
70
+
71
+ DO NOT ask "what were we working on?" — SEARCH FIRST.
72
+ If search returns 0 results, proceed as a fresh session.
53
73
 
54
74
  ## ctx commands
55
75
 
56
76
  | Command | Action |
57
77
  |---------|--------|
58
- | `ctx stats` | Call `ctx_stats` MCP tool, display full output verbatim |
59
- | `ctx doctor` | Call `ctx_doctor` MCP tool, run returned shell command, display as checklist |
60
- | `ctx upgrade` | Call `ctx_upgrade` MCP tool, run returned shell command, display as checklist |
61
- | `ctx purge` | Call `ctx_purge` MCP tool with confirm: true. Warns before wiping knowledge base. |
78
+ | `ctx stats` | Call `mcp__context-mode__ctx_stats` MCP tool, display full output verbatim |
79
+ | `ctx doctor` | Call `mcp__context-mode__ctx_doctor` MCP tool, run returned shell command, display as checklist |
80
+ | `ctx upgrade` | Call `mcp__context-mode__ctx_upgrade` MCP tool, run returned shell command, display as checklist |
81
+ | `ctx purge` | Call `mcp__context-mode__ctx_purge` MCP tool with confirm: true. Warns before wiping knowledge base. |
62
82
 
63
- After /clear or /compact: knowledge base and session stats preserved. Use `ctx purge` to start fresh.
83
+ After /clear or /compact: knowledge base and session stats preserved. Use `mcp__context-mode__ctx_purge` to start fresh.
@@ -33,8 +33,9 @@ Use `ctx_execute(language: "shell", code: "grep ...")` in sandbox.
33
33
 
34
34
  ## Tool selection
35
35
 
36
+ 0. **MEMORY**: `ctx_search(sort: "timeline")` — after resume, check prior context before asking user.
36
37
  1. **GATHER**: `ctx_batch_execute(commands, queries)` — runs all commands, auto-indexes, returns search. ONE call replaces 30+. Each command: `{label: "header", command: "..."}`.
37
- 2. **FOLLOW-UP**: `ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call.
38
+ 2. **FOLLOW-UP**: `ctx_search(queries: ["q1", "q2", ...])` — all questions as array, ONE call (default relevance mode).
38
39
  3. **PROCESSING**: `ctx_execute(language, code)` | `ctx_execute_file(path, language, code)` — sandbox, only stdout enters context.
39
40
  4. **WEB**: `ctx_fetch_and_index(url, source)` then `ctx_search(queries)` — raw HTML never enters context.
40
41
  5. **INDEX**: `ctx_index(content, source)` — store in FTS5 for later search.
@@ -47,6 +48,26 @@ Pattern: [thing] [action] [reason]. [next step]. Auto-expand for: security warni
47
48
  Write artifacts to FILES — never inline. Return: file path + 1-line description.
48
49
  Descriptive source labels for `ctx_search(source: "label")`.
49
50
 
51
+ ## Session Continuity
52
+
53
+ Skills, roles, and decisions persist for the entire session. Do not abandon them as the conversation grows.
54
+
55
+ ## Memory
56
+
57
+ Session history is persistent and searchable. On resume, search BEFORE asking the user:
58
+
59
+ | Need | Command |
60
+ |------|---------|
61
+ | What were we working on? | `ctx_search(queries: ["summary"], source: "compaction", sort: "timeline")` |
62
+ | What did we decide? | `ctx_search(queries: ["decision"], source: "decision", sort: "timeline")` |
63
+ | What NOT to repeat? | `ctx_search(queries: ["rejected"], source: "rejected-approach")` |
64
+ | What constraints exist? | `ctx_search(queries: ["constraint"], source: "constraint")` |
65
+
66
+ Note: user-prompt history not available.
67
+
68
+ DO NOT ask "what were we working on?" — SEARCH FIRST.
69
+ If search returns 0 results, proceed as a fresh session.
70
+
50
71
  ## ctx commands
51
72
 
52
73
  | Command | Action |
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Auto-injection for compaction events.
3
+ *
4
+ * Builds a prioritized, budget-capped injection block from session events.
5
+ * Only fires on source === "compact" (wired in sessionstart.mjs).
6
+ *
7
+ * Priority order:
8
+ * P1: Role (behavioral_directive) — always first, never truncated
9
+ * P2: Decisions (rules) — latest 5, overflow reduces to 3
10
+ * P3: Skills (active_skills) — unique names, latest 10
11
+ * P4: Intent (session_mode) — latest
12
+ *
13
+ * Hard cap: 500 tokens (~2000 chars at 4 chars/token).
14
+ */
15
+
16
+ /**
17
+ * Rough token estimate: ~4 chars per token.
18
+ * @param {string} text
19
+ * @returns {number}
20
+ */
21
+ export function estimateTokens(text) {
22
+ return Math.ceil(text.length / 4);
23
+ }
24
+
25
+ /**
26
+ * Build auto-injection block from session events.
27
+ * @param {Array<{category: string, data: string}>} events
28
+ * @returns {string} XML block or empty string
29
+ */
30
+ export function buildAutoInjection(events) {
31
+ const parts = [];
32
+ let budget = 500; // hard cap in tokens
33
+
34
+ // P1: Role (always first, never truncated from output)
35
+ const roleEvent = events.filter(e => e.category === "role").pop(); // latest
36
+ if (roleEvent) {
37
+ const text = `<behavioral_directive>\n${roleEvent.data.slice(0, 400)}\n</behavioral_directive>`;
38
+ parts.push(text);
39
+ budget -= estimateTokens(text);
40
+ }
41
+
42
+ // P2: Decisions (latest 5)
43
+ const decisions = events.filter(e => e.category === "decision").slice(-5);
44
+ if (decisions.length > 0) {
45
+ const lines = decisions.map(d => `- ${d.data.slice(0, 100)}`).join("\n");
46
+ const text = `<rules>\nFollow these decisions:\n${lines}\n</rules>`;
47
+ const cost = estimateTokens(text);
48
+ if (cost <= budget) {
49
+ parts.push(text);
50
+ budget -= cost;
51
+ } else {
52
+ // Overflow: reduce to 3 decisions
53
+ const reduced = decisions.slice(-3).map(d => `- ${d.data.slice(0, 100)}`).join("\n");
54
+ const fallback = `<rules>\nFollow these decisions:\n${reduced}\n</rules>`;
55
+ parts.push(fallback);
56
+ budget -= estimateTokens(fallback);
57
+ }
58
+ }
59
+
60
+ // P3: Skills (unique names, latest 10)
61
+ const skills = [...new Set(events.filter(e => e.category === "skill").map(e => e.data))];
62
+ if (skills.length > 0 && budget > 50) {
63
+ const text = `<active_skills>\nRe-invoke if relevant: ${skills.slice(-10).join(", ")}\nTo reload: call the Skill tool with the skill name.\n</active_skills>`;
64
+ parts.push(text);
65
+ budget -= estimateTokens(text);
66
+ }
67
+
68
+ // P4: Intent (latest)
69
+ const intentEvent = events.filter(e => e.category === "intent").pop();
70
+ if (intentEvent && budget > 20) {
71
+ parts.push(`<session_mode>${intentEvent.data}</session_mode>`);
72
+ }
73
+
74
+ if (parts.length === 0) return "";
75
+ return `<session_state source="compaction">\n\n${parts.join("\n\n")}\n\n</session_state>`;
76
+ }
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+ import "../suppress-stderr.mjs";
3
+ import "../ensure-deps.mjs";
4
+ /**
5
+ * Codex CLI Stop hook — record turn/session end state for continuity.
6
+ */
7
+
8
+ import { readStdin, parseStdin, getSessionId, getSessionDBPath, getInputProjectDir, CODEX_OPTS } from "../session-helpers.mjs";
9
+ import { createSessionLoaders } from "../session-loaders.mjs";
10
+ import { dirname } from "node:path";
11
+ import { fileURLToPath } from "node:url";
12
+
13
+ const HOOK_DIR = dirname(fileURLToPath(import.meta.url));
14
+ const { loadSessionDB } = createSessionLoaders(HOOK_DIR);
15
+ const OPTS = CODEX_OPTS;
16
+
17
+ try {
18
+ const raw = await readStdin();
19
+ const input = parseStdin(raw);
20
+ const projectDir = getInputProjectDir(input, OPTS);
21
+
22
+ const { SessionDB } = await loadSessionDB();
23
+ const dbPath = getSessionDBPath(OPTS);
24
+ const db = new SessionDB({ dbPath });
25
+ const sessionId = getSessionId(input, OPTS);
26
+
27
+ db.ensureSession(sessionId, projectDir);
28
+ db.insertEvent(sessionId, {
29
+ type: "session_end",
30
+ status: "completed",
31
+ stop_hook_active: input.stop_hook_active ?? false,
32
+ last_assistant_message: typeof input.last_assistant_message === "string"
33
+ ? input.last_assistant_message.slice(0, 2000)
34
+ : null,
35
+ }, "Stop");
36
+
37
+ db.close();
38
+ } catch {
39
+ // Codex hooks must not block the session.
40
+ }
41
+
42
+ process.stdout.write("{}\n");
43
+