context-mode 1.0.111 → 1.0.113

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 (153) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.openclaw-plugin/index.ts +3 -2
  4. package/.openclaw-plugin/openclaw.plugin.json +1 -1
  5. package/.openclaw-plugin/package.json +1 -1
  6. package/README.md +152 -34
  7. package/bin/statusline.mjs +144 -127
  8. package/build/adapters/base.d.ts +8 -5
  9. package/build/adapters/base.js +8 -18
  10. package/build/adapters/claude-code/index.d.ts +24 -3
  11. package/build/adapters/claude-code/index.js +44 -11
  12. package/build/adapters/codex/hooks.d.ts +10 -5
  13. package/build/adapters/codex/hooks.js +10 -5
  14. package/build/adapters/codex/index.d.ts +17 -5
  15. package/build/adapters/codex/index.js +337 -37
  16. package/build/adapters/codex/paths.d.ts +1 -0
  17. package/build/adapters/codex/paths.js +12 -0
  18. package/build/adapters/cursor/index.d.ts +6 -0
  19. package/build/adapters/cursor/index.js +83 -2
  20. package/build/adapters/detect.d.ts +1 -1
  21. package/build/adapters/detect.js +29 -6
  22. package/build/adapters/omp/index.d.ts +65 -0
  23. package/build/adapters/omp/index.js +182 -0
  24. package/build/adapters/omp/plugin.d.ts +75 -0
  25. package/build/adapters/omp/plugin.js +220 -0
  26. package/build/adapters/openclaw/mcp-tools.d.ts +54 -0
  27. package/build/adapters/openclaw/mcp-tools.js +198 -0
  28. package/build/adapters/openclaw/plugin.d.ts +130 -0
  29. package/build/adapters/openclaw/plugin.js +629 -0
  30. package/build/adapters/openclaw/workspace-router.d.ts +29 -0
  31. package/build/adapters/openclaw/workspace-router.js +64 -0
  32. package/build/adapters/opencode/plugin.d.ts +145 -0
  33. package/build/adapters/opencode/plugin.js +457 -0
  34. package/build/adapters/pi/extension.d.ts +26 -0
  35. package/build/adapters/pi/extension.js +552 -0
  36. package/build/adapters/pi/index.d.ts +57 -0
  37. package/build/adapters/pi/index.js +173 -0
  38. package/build/adapters/pi/mcp-bridge.d.ts +113 -0
  39. package/build/adapters/pi/mcp-bridge.js +251 -0
  40. package/build/adapters/types.d.ts +11 -6
  41. package/build/cli.js +186 -170
  42. package/build/db-base.d.ts +15 -2
  43. package/build/db-base.js +50 -5
  44. package/build/executor.d.ts +2 -0
  45. package/build/executor.js +15 -2
  46. package/build/runPool.d.ts +36 -0
  47. package/build/runPool.js +51 -0
  48. package/build/runtime.js +64 -5
  49. package/build/search/auto-memory.js +6 -4
  50. package/build/security.js +30 -10
  51. package/build/server.d.ts +23 -1
  52. package/build/server.js +662 -182
  53. package/build/session/analytics.d.ts +404 -1
  54. package/build/session/analytics.js +1347 -42
  55. package/build/session/db.d.ts +114 -5
  56. package/build/session/db.js +275 -27
  57. package/build/session/event-emit.d.ts +48 -0
  58. package/build/session/event-emit.js +101 -0
  59. package/build/session/extract.d.ts +1 -0
  60. package/build/session/extract.js +79 -12
  61. package/build/session/purge.d.ts +111 -0
  62. package/build/session/purge.js +138 -0
  63. package/build/store.d.ts +7 -0
  64. package/build/store.js +69 -6
  65. package/build/util/claude-config.d.ts +26 -0
  66. package/build/util/claude-config.js +91 -0
  67. package/build/util/hook-config.d.ts +4 -0
  68. package/build/util/hook-config.js +39 -0
  69. package/build/util/project-dir.d.ts +49 -0
  70. package/build/util/project-dir.js +67 -0
  71. package/cli.bundle.mjs +411 -208
  72. package/configs/antigravity/GEMINI.md +0 -3
  73. package/configs/claude-code/CLAUDE.md +1 -4
  74. package/configs/codex/AGENTS.md +1 -4
  75. package/configs/codex/config.toml +3 -0
  76. package/configs/codex/hooks.json +8 -0
  77. package/configs/cursor/context-mode.mdc +0 -3
  78. package/configs/gemini-cli/GEMINI.md +0 -3
  79. package/configs/jetbrains-copilot/copilot-instructions.md +0 -3
  80. package/configs/kilo/AGENTS.md +0 -3
  81. package/configs/kiro/KIRO.md +0 -3
  82. package/configs/omp/SYSTEM.md +85 -0
  83. package/configs/omp/mcp.json +7 -0
  84. package/configs/openclaw/AGENTS.md +0 -3
  85. package/configs/opencode/AGENTS.md +0 -3
  86. package/configs/pi/AGENTS.md +0 -3
  87. package/configs/qwen-code/QWEN.md +1 -4
  88. package/configs/vscode-copilot/copilot-instructions.md +0 -3
  89. package/configs/zed/AGENTS.md +0 -3
  90. package/hooks/codex/posttooluse.mjs +9 -2
  91. package/hooks/codex/precompact.mjs +69 -0
  92. package/hooks/codex/sessionstart.mjs +13 -9
  93. package/hooks/codex/stop.mjs +1 -2
  94. package/hooks/codex/userpromptsubmit.mjs +1 -2
  95. package/hooks/core/routing.mjs +237 -18
  96. package/hooks/cursor/afteragentresponse.mjs +1 -1
  97. package/hooks/cursor/hooks.json +31 -0
  98. package/hooks/cursor/posttooluse.mjs +1 -1
  99. package/hooks/cursor/sessionstart.mjs +5 -5
  100. package/hooks/cursor/stop.mjs +1 -1
  101. package/hooks/ensure-deps.mjs +12 -13
  102. package/hooks/gemini-cli/aftertool.mjs +1 -1
  103. package/hooks/gemini-cli/beforeagent.mjs +1 -1
  104. package/hooks/gemini-cli/precompress.mjs +3 -2
  105. package/hooks/gemini-cli/sessionstart.mjs +9 -9
  106. package/hooks/jetbrains-copilot/posttooluse.mjs +1 -1
  107. package/hooks/jetbrains-copilot/precompact.mjs +3 -2
  108. package/hooks/jetbrains-copilot/sessionstart.mjs +9 -9
  109. package/hooks/kiro/agentspawn.mjs +5 -5
  110. package/hooks/kiro/posttooluse.mjs +2 -2
  111. package/hooks/kiro/userpromptsubmit.mjs +1 -1
  112. package/hooks/posttooluse.mjs +45 -0
  113. package/hooks/precompact.mjs +17 -0
  114. package/hooks/pretooluse.mjs +23 -0
  115. package/hooks/routing-block.mjs +0 -12
  116. package/hooks/run-hook.mjs +16 -3
  117. package/hooks/session-db.bundle.mjs +27 -18
  118. package/hooks/session-extract.bundle.mjs +2 -2
  119. package/hooks/session-helpers.mjs +101 -64
  120. package/hooks/sessionstart.mjs +51 -2
  121. package/hooks/vscode-copilot/posttooluse.mjs +1 -1
  122. package/hooks/vscode-copilot/precompact.mjs +3 -2
  123. package/hooks/vscode-copilot/sessionstart.mjs +9 -9
  124. package/openclaw.plugin.json +1 -1
  125. package/package.json +14 -8
  126. package/server.bundle.mjs +349 -147
  127. package/start.mjs +16 -4
  128. package/skills/UPSTREAM-CREDITS.md +0 -51
  129. package/skills/context-mode-ops/SKILL.md +0 -299
  130. package/skills/context-mode-ops/agent-teams.md +0 -198
  131. package/skills/context-mode-ops/communication.md +0 -224
  132. package/skills/context-mode-ops/marketing.md +0 -124
  133. package/skills/context-mode-ops/release.md +0 -214
  134. package/skills/context-mode-ops/review-pr.md +0 -269
  135. package/skills/context-mode-ops/tdd.md +0 -329
  136. package/skills/context-mode-ops/triage-issue.md +0 -266
  137. package/skills/context-mode-ops/validation.md +0 -307
  138. package/skills/diagnose/SKILL.md +0 -122
  139. package/skills/diagnose/scripts/hitl-loop.template.sh +0 -41
  140. package/skills/grill-me/SKILL.md +0 -15
  141. package/skills/grill-with-docs/ADR-FORMAT.md +0 -47
  142. package/skills/grill-with-docs/CONTEXT-FORMAT.md +0 -77
  143. package/skills/grill-with-docs/SKILL.md +0 -93
  144. package/skills/improve-codebase-architecture/DEEPENING.md +0 -37
  145. package/skills/improve-codebase-architecture/INTERFACE-DESIGN.md +0 -44
  146. package/skills/improve-codebase-architecture/LANGUAGE.md +0 -53
  147. package/skills/improve-codebase-architecture/SKILL.md +0 -76
  148. package/skills/tdd/SKILL.md +0 -114
  149. package/skills/tdd/deep-modules.md +0 -33
  150. package/skills/tdd/interface-design.md +0 -31
  151. package/skills/tdd/mocking.md +0 -59
  152. package/skills/tdd/refactoring.md +0 -10
  153. package/skills/tdd/tests.md +0 -61
@@ -5,43 +5,80 @@
5
5
  *
6
6
  * All functions accept an optional `opts` parameter for platform-specific
7
7
  * configuration. Defaults to Claude Code settings for backward compatibility.
8
+ *
9
+ * ─── PATH / HASH HELPERS ARE BOUND, NOT REIMPLEMENTED ──────────────────
10
+ * Hash + worktree-suffix + legacy migration logic lives in TypeScript at
11
+ * `src/session/db.ts` and is bundled to `hooks/session-db.bundle.mjs` by
12
+ * the existing esbuild step in `npm run bundle`. This file imports those
13
+ * exports via the bundle so the JS hooks and the TS server cannot drift
14
+ * again — the same drift that produced rounds 5 and 6 of case-fold fixes.
15
+ *
16
+ * Bundle-first / build-fallback resolution mirrors the pattern in
17
+ * `session-loaders.mjs` for marketplace installs that ship `build/`
18
+ * artifacts instead of pre-built bundles.
8
19
  */
9
20
 
10
- import { execFileSync } from "node:child_process";
11
- import { createHash } from "node:crypto";
12
- import { join } from "node:path";
13
- import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
21
+ import { join, dirname } from "node:path";
22
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
14
23
  import { homedir, tmpdir } from "node:os";
24
+ import { fileURLToPath, pathToFileURL } from "node:url";
25
+
26
+ // ─────────────────────────────────────────────────────────
27
+ // Bundle binding — single source of truth for path/hash logic.
28
+ // ─────────────────────────────────────────────────────────
29
+
30
+ const __filename = fileURLToPath(import.meta.url);
31
+ const __dirname = dirname(__filename);
32
+
33
+ async function loadSessionDbModule() {
34
+ // Bundle is co-located with this file in published installs.
35
+ const bundlePath = join(__dirname, "session-db.bundle.mjs");
36
+ if (existsSync(bundlePath)) {
37
+ return await import(pathToFileURL(bundlePath).href);
38
+ }
39
+ // Marketplace fallback: build/session/db.js when bundles are absent.
40
+ const buildPath = join(__dirname, "..", "build", "session", "db.js");
41
+ return await import(pathToFileURL(buildPath).href);
42
+ }
43
+
44
+ const _sessionDb = await loadSessionDbModule();
45
+ const {
46
+ hashProjectDirCanonical,
47
+ hashProjectDirLegacy,
48
+ normalizeWorktreePath,
49
+ resolveSessionPath: _resolveSessionPath,
50
+ getWorktreeSuffix: _getWorktreeSuffixBundle,
51
+ } = _sessionDb;
52
+
53
+ // ─────────────────────────────────────────────────────────
54
+ // Cross-process worktree-suffix cache — hook-fork-only optimisation.
55
+ // ─────────────────────────────────────────────────────────
56
+ //
57
+ // The TS bundle's getWorktreeSuffix has an in-process cache, but every
58
+ // Pre/PostToolUse hook is a fresh `node` fork — that cache is dead on
59
+ // arrival. The marker file in tmpdir keyed by sha256(projectDir) lets
60
+ // subsequent forks short-circuit the 12-50ms `git worktree list` cost.
61
+ // The marker filename uses the canonical hash (case-folded on Mac/Win)
62
+ // so two terminals with different casing of the same physical worktree
63
+ // share one marker (and one cached suffix) — same correctness guarantee
64
+ // as the canonical DB filename.
15
65
 
16
- /**
17
- * Returns the worktree suffix for session path isolation.
18
- * Mirrors the logic in src/server.ts — kept in sync manually since
19
- * hooks run as plain .mjs (no TypeScript build step).
20
- *
21
- * Two-level cache:
22
- * 1. In-process module cache — same hook fire calls this 3× (db,
23
- * events, cleanup paths) so cache hits 2 of 3 cold within process.
24
- * 2. Cross-process marker file in tmpdir keyed by sha256(cwd) — every
25
- * Pre/PostToolUse hook is a fresh node fork; without this each fire
26
- * pays 12-50ms for `git worktree list` on Linux/macOS, 50-150ms on
27
- * Windows where fork+exec is heavier.
28
- *
29
- * Marker filename uses sha256(cwd) so it is alphanumeric — safe across
30
- * Windows path/filename rules. tmpdir() resolves correctly on all 3 OS.
31
- */
32
66
  let _wtCacheInProcess;
33
- function workTreeMarkerPath(cwd) {
34
- const hash = createHash("sha256").update(cwd).digest("hex").slice(0, 16);
35
- return join(tmpdir(), `cm-wt-${hash}.txt`);
67
+
68
+ function workTreeMarkerPath(projectDir) {
69
+ return join(
70
+ tmpdir(),
71
+ `cm-wt-${hashProjectDirCanonical(normalizeWorktreePath(projectDir))}.txt`,
72
+ );
36
73
  }
37
74
 
38
- function getWorktreeSuffix() {
75
+ function getWorktreeSuffix(projectDir = process.cwd()) {
39
76
  const envSuffix = process.env.CONTEXT_MODE_SESSION_SUFFIX;
40
- const cwd = process.cwd();
77
+ const normalizedProjectDir = normalizeWorktreePath(projectDir);
41
78
 
42
79
  if (
43
80
  _wtCacheInProcess &&
44
- _wtCacheInProcess.cwd === cwd &&
81
+ _wtCacheInProcess.projectDir === normalizedProjectDir &&
45
82
  _wtCacheInProcess.envSuffix === envSuffix
46
83
  ) {
47
84
  return _wtCacheInProcess.suffix;
@@ -52,31 +89,23 @@ function getWorktreeSuffix() {
52
89
  suffix = envSuffix ? `__${envSuffix}` : "";
53
90
  } else {
54
91
  // Try cross-process marker first.
55
- const markerPath = workTreeMarkerPath(cwd);
92
+ const markerPath = workTreeMarkerPath(projectDir);
56
93
  try {
57
94
  suffix = readFileSync(markerPath, "utf-8");
58
- _wtCacheInProcess = { cwd, envSuffix, suffix };
95
+ _wtCacheInProcess = { projectDir: normalizedProjectDir, envSuffix, suffix };
59
96
  return suffix;
60
97
  } catch {
61
- // marker missing → compute below
98
+ // marker missing → delegate to bundle for the canonical computation.
62
99
  }
63
100
 
64
- suffix = "";
101
+ // Single source of truth: the bundle's getWorktreeSuffix runs the
102
+ // git subprocess, the case-fold comparison, and the suffix hashing.
103
+ // We just persist the result so other forks can skip the git call.
65
104
  try {
66
- const mainWorktree = execFileSync(
67
- "git",
68
- ["worktree", "list", "--porcelain"],
69
- { encoding: "utf-8", timeout: 2000, stdio: ["ignore", "pipe", "ignore"] },
70
- )
71
- .split(/\r?\n/)
72
- .find((l) => l.startsWith("worktree "))
73
- ?.replace("worktree ", "")
74
- ?.trim();
75
- if (mainWorktree && cwd !== mainWorktree) {
76
- suffix = `__${createHash("sha256").update(cwd).digest("hex").slice(0, 8)}`;
77
- }
105
+ suffix = _getWorktreeSuffixBundle(projectDir);
78
106
  } catch {
79
107
  // git not available or not a git repo — no suffix
108
+ suffix = "";
80
109
  }
81
110
 
82
111
  // Best-effort write so subsequent hook forks short-circuit.
@@ -87,10 +116,14 @@ function getWorktreeSuffix() {
87
116
  }
88
117
  }
89
118
 
90
- _wtCacheInProcess = { cwd, envSuffix, suffix };
119
+ _wtCacheInProcess = { projectDir: normalizedProjectDir, envSuffix, suffix };
91
120
  return suffix;
92
121
  }
93
122
 
123
+ // ─────────────────────────────────────────────────────────
124
+ // Platform options (hook-only — the server doesn't fork hooks).
125
+ // ─────────────────────────────────────────────────────────
126
+
94
127
  /** Claude Code platform options (default). */
95
128
  const CLAUDE_OPTS = {
96
129
  configDir: ".claude",
@@ -228,42 +261,46 @@ export function getSessionId(input, opts = CLAUDE_OPTS) {
228
261
  return `pid-${process.ppid}`;
229
262
  }
230
263
 
264
+ // ─────────────────────────────────────────────────────────
265
+ // Per-project file paths — thin wrappers around resolveSessionPath.
266
+ // ─────────────────────────────────────────────────────────
267
+
268
+ function _resolveProjectFile(opts, projectDirOverride, ext) {
269
+ const projectDir = normalizeWorktreePath(projectDirOverride ?? getProjectDir(opts));
270
+ const sessionsDir = join(resolveConfigDir(opts), "context-mode", "sessions");
271
+ mkdirSync(sessionsDir, { recursive: true });
272
+ return _resolveSessionPath({
273
+ projectDir,
274
+ sessionsDir,
275
+ suffix: getWorktreeSuffix(projectDir),
276
+ ext,
277
+ });
278
+ }
279
+
231
280
  /**
232
281
  * Return the per-project session DB path.
233
282
  * Creates the directory if it doesn't exist.
234
- * Path: ~/<configDir>/context-mode/sessions/<SHA256(projectDir)[:16]>.db
283
+ * Path: ~/<configDir>/context-mode/sessions/<canonicalHash><suffix>.db
235
284
  */
236
- export function getSessionDBPath(opts = CLAUDE_OPTS) {
237
- const projectDir = getProjectDir(opts);
238
- const hash = createHash("sha256").update(projectDir).digest("hex").slice(0, 16);
239
- const dir = join(resolveConfigDir(opts), "context-mode", "sessions");
240
- mkdirSync(dir, { recursive: true });
241
- return join(dir, `${hash}${getWorktreeSuffix()}.db`);
285
+ export function getSessionDBPath(opts = CLAUDE_OPTS, projectDirOverride) {
286
+ return _resolveProjectFile(opts, projectDirOverride, ".db");
242
287
  }
243
288
 
244
289
  /**
245
290
  * Return the per-project session events file path.
246
291
  * Used by sessionstart hook (write) and MCP server (read + auto-index).
247
- * Path: ~/<configDir>/context-mode/sessions/<SHA256(projectDir)[:16]>-events.md
292
+ * Path: ~/<configDir>/context-mode/sessions/<canonicalHash><suffix>-events.md
248
293
  */
249
- export function getSessionEventsPath(opts = CLAUDE_OPTS) {
250
- const projectDir = getProjectDir(opts);
251
- const hash = createHash("sha256").update(projectDir).digest("hex").slice(0, 16);
252
- const dir = join(resolveConfigDir(opts), "context-mode", "sessions");
253
- mkdirSync(dir, { recursive: true });
254
- return join(dir, `${hash}${getWorktreeSuffix()}-events.md`);
294
+ export function getSessionEventsPath(opts = CLAUDE_OPTS, projectDirOverride) {
295
+ return _resolveProjectFile(opts, projectDirOverride, "-events.md");
255
296
  }
256
297
 
257
298
  /**
258
299
  * Return the per-project cleanup flag path.
259
300
  * Used to detect true fresh starts vs --continue (which fires startup+resume).
260
- * Path: ~/<configDir>/context-mode/sessions/<SHA256(projectDir)[:16]>.cleanup
301
+ * Path: ~/<configDir>/context-mode/sessions/<canonicalHash><suffix>.cleanup
261
302
  */
262
- export function getCleanupFlagPath(opts = CLAUDE_OPTS) {
263
- const projectDir = getProjectDir(opts);
264
- const hash = createHash("sha256").update(projectDir).digest("hex").slice(0, 16);
265
- const dir = join(resolveConfigDir(opts), "context-mode", "sessions");
266
- mkdirSync(dir, { recursive: true });
267
- return join(dir, `${hash}${getWorktreeSuffix()}.cleanup`);
303
+ export function getCleanupFlagPath(opts = CLAUDE_OPTS, projectDirOverride) {
304
+ return _resolveProjectFile(opts, projectDirOverride, ".cleanup");
268
305
  }
269
306
 
@@ -81,7 +81,31 @@ await runHook(async () => {
81
81
  additionalContext += "\n\n" + autoInjection;
82
82
  }
83
83
 
84
- // Write session-resume event
84
+ // D2 PRD Phase 6.2: emit snapshot-consumed with bytes_returned=snapshot.length.
85
+ // The resumed snapshot bytes ARE returned to the model — that's the whole
86
+ // point of resume — so account them on bytes_returned, not bytes_avoided.
87
+ try {
88
+ const resumeRow = (resume && resume.snapshot)
89
+ ? resume
90
+ : (db.getResume?.(sessionId) ?? null);
91
+ const snapshotBytes = resumeRow?.snapshot?.length ?? 0;
92
+
93
+ db.insertEvent(
94
+ sessionId,
95
+ {
96
+ type: "snapshot-consumed",
97
+ category: "session-resume",
98
+ data: `Session resumed from ${source}. Snapshot ${snapshotBytes} bytes injected.`,
99
+ priority: 1,
100
+ },
101
+ "SessionStart",
102
+ undefined,
103
+ { bytesAvoided: 0, bytesReturned: snapshotBytes },
104
+ );
105
+ } catch { /* best-effort */ }
106
+
107
+ // Legacy resume_completed event retained for back-compat with existing
108
+ // analytics consumers that filter on `type === 'resume_completed'`.
85
109
  try {
86
110
  db.insertEvent(
87
111
  sessionId,
@@ -140,7 +164,32 @@ await runHook(async () => {
140
164
  // If cleanup flag exists from a PREVIOUS startup that was never followed by
141
165
  // resume, that was a true fresh start — aggressively wipe all data.
142
166
  db.cleanupOldSessions(7);
143
- db.db.exec(`DELETE FROM session_events WHERE session_id NOT IN (SELECT session_id FROM session_meta)`);
167
+ // Bug fix: the unconditional DELETE below USED to wipe ALL orphan
168
+ // events (any session_id missing from session_meta). On a power-outage
169
+ // restart this destroyed 1000+ events of real Claude Code work whose
170
+ // UUID session_ids hadn't yet had their session_meta row written
171
+ // (timing window between insertEvent and ensureSession). See
172
+ // tests/session/cleanup-preserves-live-uuid-events.test.ts.
173
+ //
174
+ // Now: protect anything that LOOKS like a real session UUID
175
+ // (4 dashes per RFC 4122 8-4-4-4-12), unless it's already older than
176
+ // the 7-day cleanup horizon. Detection-probe orphans like 'pid-12345'
177
+ // (no UUID shape) are still wiped aggressively — they're noise.
178
+ // Loose 4-dash shape `*-*-*-*-*`. Claude Code session_ids are UUIDs
179
+ // (5 dash-separated segments) and match. `pid-XXXXX` probes have one
180
+ // dash and don't match → wiped aggressively. We deliberately keep
181
+ // this loose so adapters that may eventually share this DB (or reuse
182
+ // this hook with hybrid `claude-code-...`-style IDs across 15
183
+ // platforms) aren't accidentally classified as orphans. The 7-day
184
+ // fallback still wipes truly abandoned UUIDs.
185
+ db.db.exec(`
186
+ DELETE FROM session_events
187
+ WHERE session_id NOT IN (SELECT session_id FROM session_meta)
188
+ AND (
189
+ session_id NOT GLOB '*-*-*-*-*' -- pid-XXX probes etc.
190
+ OR created_at < datetime('now', '-7 day') -- truly abandoned UUIDs
191
+ )
192
+ `);
144
193
 
145
194
  // Proactively capture CLAUDE.md files — Claude Code loads them as system
146
195
  // context at startup, invisible to PostToolUse hooks. We read them from
@@ -33,7 +33,7 @@ try {
33
33
  const { resolveProjectAttributions } = await loadProjectAttribution();
34
34
  const { SessionDB } = await loadSessionDB();
35
35
 
36
- const dbPath = getSessionDBPath(OPTS);
36
+ const dbPath = getSessionDBPath(OPTS, projectDir);
37
37
  const db = new SessionDB({ dbPath });
38
38
  const sessionId = getSessionId(input, OPTS);
39
39
 
@@ -10,7 +10,7 @@ import "../ensure-deps.mjs";
10
10
  */
11
11
 
12
12
  import { createSessionLoaders } from "../session-loaders.mjs";
13
- import { readStdin, parseStdin, getSessionId, getSessionDBPath, VSCODE_OPTS } from "../session-helpers.mjs";
13
+ import { readStdin, parseStdin, getSessionId, getSessionDBPath, getInputProjectDir, VSCODE_OPTS } from "../session-helpers.mjs";
14
14
  import { appendFileSync } from "node:fs";
15
15
  import { join, dirname } from "node:path";
16
16
  import { fileURLToPath } from "node:url";
@@ -24,11 +24,12 @@ const DEBUG_LOG = join(homedir(), ".vscode", "context-mode", "precompact-debug.l
24
24
  try {
25
25
  const raw = await readStdin();
26
26
  const input = parseStdin(raw);
27
+ const projectDir = getInputProjectDir(input, OPTS);
27
28
 
28
29
  const { buildResumeSnapshot } = await loadSnapshot();
29
30
  const { SessionDB } = await loadSessionDB();
30
31
 
31
- const dbPath = getSessionDBPath(OPTS);
32
+ const dbPath = getSessionDBPath(OPTS, projectDir);
32
33
  const db = new SessionDB({ dbPath });
33
34
  const sessionId = getSessionId(input, OPTS);
34
35
 
@@ -26,7 +26,7 @@ const ROUTING_BLOCK = createRoutingBlock(toolNamer);
26
26
  import { writeSessionEventsFile, buildSessionDirective, getSessionEvents } from "../session-directive.mjs";
27
27
  import {
28
28
  readStdin, parseStdin, getSessionId, getSessionDBPath, getSessionEventsPath, getCleanupFlagPath,
29
- getProjectDir, VSCODE_OPTS,
29
+ getInputProjectDir, VSCODE_OPTS,
30
30
  } from "../session-helpers.mjs";
31
31
  import { join } from "node:path";
32
32
  import { readFileSync, unlinkSync } from "node:fs";
@@ -42,10 +42,11 @@ try {
42
42
  const raw = await readStdin();
43
43
  const input = parseStdin(raw);
44
44
  const source = input.source ?? "startup";
45
+ const projectDir = getInputProjectDir(input, OPTS);
45
46
 
46
47
  if (source === "compact") {
47
48
  const { SessionDB } = await loadSessionDB();
48
- const dbPath = getSessionDBPath(OPTS);
49
+ const dbPath = getSessionDBPath(OPTS, projectDir);
49
50
  const db = new SessionDB({ dbPath });
50
51
  const sessionId = getSessionId(input, OPTS);
51
52
  const resume = db.getResume(sessionId);
@@ -56,38 +57,37 @@ try {
56
57
 
57
58
  const events = getSessionEvents(db, sessionId);
58
59
  if (events.length > 0) {
59
- const eventMeta = writeSessionEventsFile(events, getSessionEventsPath(OPTS));
60
+ const eventMeta = writeSessionEventsFile(events, getSessionEventsPath(OPTS, projectDir));
60
61
  additionalContext += buildSessionDirective("compact", eventMeta, toolNamer);
61
62
  }
62
63
 
63
64
  db.close();
64
65
  } else if (source === "resume") {
65
- try { unlinkSync(getCleanupFlagPath(OPTS)); } catch { /* no flag */ }
66
+ try { unlinkSync(getCleanupFlagPath(OPTS, projectDir)); } catch { /* no flag */ }
66
67
 
67
68
  const { SessionDB } = await loadSessionDB();
68
- const dbPath = getSessionDBPath(OPTS);
69
+ const dbPath = getSessionDBPath(OPTS, projectDir);
69
70
  const db = new SessionDB({ dbPath });
70
71
 
71
72
  // Filter events to the session being resumed (cross-session bleed guard).
72
73
  const sessionId = getSessionId(input, OPTS);
73
74
  const events = sessionId ? getSessionEvents(db, sessionId) : [];
74
75
  if (events.length > 0) {
75
- const eventMeta = writeSessionEventsFile(events, getSessionEventsPath(OPTS));
76
+ const eventMeta = writeSessionEventsFile(events, getSessionEventsPath(OPTS, projectDir));
76
77
  additionalContext += buildSessionDirective("resume", eventMeta, toolNamer);
77
78
  }
78
79
 
79
80
  db.close();
80
81
  } else if (source === "startup") {
81
82
  const { SessionDB } = await loadSessionDB();
82
- const dbPath = getSessionDBPath(OPTS);
83
+ const dbPath = getSessionDBPath(OPTS, projectDir);
83
84
  const db = new SessionDB({ dbPath });
84
- try { unlinkSync(getSessionEventsPath(OPTS)); } catch { /* no stale file */ }
85
+ try { unlinkSync(getSessionEventsPath(OPTS, projectDir)); } catch { /* no stale file */ }
85
86
 
86
87
  db.cleanupOldSessions(7);
87
88
  db.db.exec(`DELETE FROM session_events WHERE session_id NOT IN (SELECT session_id FROM session_meta)`);
88
89
 
89
90
  const sessionId = getSessionId(input, OPTS);
90
- const projectDir = getProjectDir(OPTS);
91
91
  db.ensureSession(sessionId, projectDir);
92
92
 
93
93
  // VSCode Copilot's canonical project-level instruction file.
@@ -3,7 +3,7 @@
3
3
  "name": "Context Mode",
4
4
  "kind": "tool",
5
5
  "description": "OpenClaw plugin that saves 98% of your context window. Sandboxed code execution in 11 languages, FTS5 knowledge base with BM25 ranking, and intent-driven search.",
6
- "version": "1.0.111",
6
+ "version": "1.0.113",
7
7
  "sandbox": {
8
8
  "mode": "permissive",
9
9
  "filesystem_access": "full",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "context-mode",
3
- "version": "1.0.111",
3
+ "version": "1.0.113",
4
4
  "type": "module",
5
5
  "description": "MCP plugin that saves 98% of your context window. Works with Claude Code, Gemini CLI, VS Code Copilot, OpenCode, and Codex CLI. Sandboxed code execution, FTS5 knowledge base, and intent-driven search.",
6
6
  "author": "Mert Koseoğlu",
@@ -29,7 +29,7 @@
29
29
  "homepage": "https://github.com/mksglu/context-mode#readme",
30
30
  "pi": {
31
31
  "extensions": [
32
- "./build/pi-extension.js"
32
+ "./build/adapters/pi/extension.js"
33
33
  ],
34
34
  "skills": [
35
35
  "./skills"
@@ -37,15 +37,20 @@
37
37
  },
38
38
  "openclaw": {
39
39
  "extensions": [
40
- "./build/openclaw-plugin.js"
40
+ "./build/adapters/openclaw/plugin.js"
41
41
  ]
42
42
  },
43
+ "omp": {
44
+ "name": "context-mode",
45
+ "description": "Save 98% of your context window in OMP — sandboxed code execution, FTS5 search, hard-block curl/wget, session continuity across compaction.",
46
+ "hooks": "./build/adapters/omp/plugin.js"
47
+ },
43
48
  "bugs": "https://github.com/mksglu/context-mode/issues",
44
- "main": "./build/opencode-plugin.js",
49
+ "main": "./build/adapters/opencode/plugin.js",
45
50
  "exports": {
46
- ".": "./build/opencode-plugin.js",
47
- "./plugin": "./build/opencode-plugin.js",
48
- "./openclaw": "./build/openclaw-plugin.js",
51
+ ".": "./build/adapters/opencode/plugin.js",
52
+ "./plugin": "./build/adapters/opencode/plugin.js",
53
+ "./openclaw": "./build/adapters/openclaw/plugin.js",
49
54
  "./cli": "./cli.bundle.mjs"
50
55
  },
51
56
  "bin": {
@@ -81,12 +86,13 @@
81
86
  "build": "tsc && node -e \"if(process.platform!=='win32'){require('fs').chmodSync('build/cli.js',0o755)}\" && npm run bundle",
82
87
  "bundle": "esbuild src/server.ts --bundle --platform=node --target=node18 --format=esm --outfile=server.bundle.mjs --external:better-sqlite3 --external:turndown --external:turndown-plugin-gfm --external:@mixmark-io/domino --minify && esbuild src/cli.ts --bundle --platform=node --target=node18 --format=esm --outfile=cli.bundle.mjs --external:better-sqlite3 --minify && esbuild src/session/extract.ts --bundle --platform=node --target=node18 --format=esm --outfile=hooks/session-extract.bundle.mjs --minify && esbuild src/session/snapshot.ts --bundle --platform=node --target=node18 --format=esm --outfile=hooks/session-snapshot.bundle.mjs --minify && esbuild src/session/db.ts --bundle --platform=node --target=node18 --format=esm --outfile=hooks/session-db.bundle.mjs --external:better-sqlite3 --minify",
83
88
  "version-sync": "node scripts/version-sync.mjs",
84
- "version": "node scripts/version-sync.mjs && git add .claude-plugin/plugin.json .claude-plugin/marketplace.json .openclaw-plugin/openclaw.plugin.json .openclaw-plugin/package.json openclaw.plugin.json .pi/extensions/context-mode/package.json",
89
+ "version": "node scripts/version-sync.mjs && git add package.json .claude-plugin/plugin.json .claude-plugin/marketplace.json .openclaw-plugin/openclaw.plugin.json .openclaw-plugin/package.json openclaw.plugin.json .pi/extensions/context-mode/package.json",
85
90
  "prepublishOnly": "npm run build",
86
91
  "dev": "npx tsx src/server.ts",
87
92
  "setup": "npx tsx src/cli.ts setup",
88
93
  "doctor": "npx tsx src/cli.ts doctor",
89
94
  "typecheck": "tsc --noEmit",
95
+ "pretest": "npm run build",
90
96
  "test": "vitest run",
91
97
  "test:watch": "vitest",
92
98
  "benchmark": "npx tsx tests/benchmark.ts",