context-mode 1.0.12 → 1.0.14
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.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/build/server.js +1 -1
- package/build/session/extract.js +139 -4
- package/build/session/snapshot.d.ts +1 -1
- package/build/session/snapshot.js +19 -18
- package/cli.bundle.mjs +1 -1
- package/hooks/session-directive.mjs +44 -2
- package/package.json +1 -1
- package/server.bundle.mjs +1 -1
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
},
|
|
7
7
|
"metadata": {
|
|
8
8
|
"description": "Claude Code plugins by Mert Koseoğlu",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.14"
|
|
10
10
|
},
|
|
11
11
|
"plugins": [
|
|
12
12
|
{
|
|
13
13
|
"name": "context-mode",
|
|
14
14
|
"source": "./",
|
|
15
15
|
"description": "Claude Code MCP plugin that saves 98% of your context window. Sandboxed code execution in 11 languages, FTS5 knowledge base with BM25 ranking, and intent-driven search.",
|
|
16
|
-
"version": "1.0.
|
|
16
|
+
"version": "1.0.14",
|
|
17
17
|
"author": {
|
|
18
18
|
"name": "Mert Koseoğlu"
|
|
19
19
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "context-mode",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"description": "MCP server that saves 98% of your context window with session continuity. Sandboxed code execution in 11 languages, FTS5 knowledge base with BM25 ranking, and automatic state restore across compactions.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Mert Koseoğlu",
|
package/build/server.js
CHANGED
|
@@ -13,7 +13,7 @@ import { ContentStore, cleanupStaleDBs } from "./store.js";
|
|
|
13
13
|
import { readBashPolicies, evaluateCommandDenyOnly, extractShellCommands, readToolDenyPatterns, evaluateFilePath, } from "./security.js";
|
|
14
14
|
import { detectRuntimes, getRuntimeSummary, getAvailableLanguages, hasBunRuntime, } from "./runtime.js";
|
|
15
15
|
import { classifyNonZeroExit } from "./exit-classify.js";
|
|
16
|
-
const VERSION = "1.0.
|
|
16
|
+
const VERSION = "1.0.14";
|
|
17
17
|
// Prevent silent server death from unhandled async errors
|
|
18
18
|
process.on("unhandledRejection", (err) => {
|
|
19
19
|
process.stderr.write(`[context-mode] unhandledRejection: ${err}\n`);
|
package/build/session/extract.js
CHANGED
|
@@ -66,13 +66,23 @@ function extractFileAndRule(input) {
|
|
|
66
66
|
if (tool_name === "Edit") {
|
|
67
67
|
const filePath = String(tool_input["file_path"] ?? "");
|
|
68
68
|
events.push({
|
|
69
|
-
type: "
|
|
69
|
+
type: "file_edit",
|
|
70
70
|
category: "file",
|
|
71
71
|
data: truncate(filePath),
|
|
72
72
|
priority: 1,
|
|
73
73
|
});
|
|
74
74
|
return events;
|
|
75
75
|
}
|
|
76
|
+
if (tool_name === "NotebookEdit") {
|
|
77
|
+
const notebookPath = String(tool_input["notebook_path"] ?? "");
|
|
78
|
+
events.push({
|
|
79
|
+
type: "file_edit",
|
|
80
|
+
category: "file",
|
|
81
|
+
data: truncate(notebookPath),
|
|
82
|
+
priority: 1,
|
|
83
|
+
});
|
|
84
|
+
return events;
|
|
85
|
+
}
|
|
76
86
|
if (tool_name === "Write") {
|
|
77
87
|
const filePath = String(tool_input["file_path"] ?? "");
|
|
78
88
|
events.push({
|
|
@@ -165,6 +175,12 @@ const GIT_PATTERNS = [
|
|
|
165
175
|
{ pattern: /\bgit\s+status\b/, operation: "status" },
|
|
166
176
|
{ pattern: /\bgit\s+branch\b/, operation: "branch" },
|
|
167
177
|
{ pattern: /\bgit\s+reset\b/, operation: "reset" },
|
|
178
|
+
{ pattern: /\bgit\s+add\b/, operation: "add" },
|
|
179
|
+
{ pattern: /\bgit\s+cherry-pick\b/, operation: "cherry-pick" },
|
|
180
|
+
{ pattern: /\bgit\s+tag\b/, operation: "tag" },
|
|
181
|
+
{ pattern: /\bgit\s+fetch\b/, operation: "fetch" },
|
|
182
|
+
{ pattern: /\bgit\s+clone\b/, operation: "clone" },
|
|
183
|
+
{ pattern: /\bgit\s+worktree\b/, operation: "worktree" },
|
|
168
184
|
];
|
|
169
185
|
function extractGit(input) {
|
|
170
186
|
if (input.tool_name !== "Bash")
|
|
@@ -199,6 +215,77 @@ function extractTask(input) {
|
|
|
199
215
|
priority: 1,
|
|
200
216
|
}];
|
|
201
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Category 15: plan
|
|
220
|
+
* Tracks the full plan mode lifecycle:
|
|
221
|
+
* - EnterPlanMode → plan_enter
|
|
222
|
+
* - Write/Edit to ~/.claude/plans/ → plan_file_write
|
|
223
|
+
* - ExitPlanMode → plan_exit (with allowedPrompts)
|
|
224
|
+
* - ExitPlanMode tool_response → plan_approved / plan_rejected
|
|
225
|
+
*
|
|
226
|
+
* Note: Shift+Tab and /plan command do NOT fire PostToolUse hooks
|
|
227
|
+
* (Claude Code bug #15660). Only programmatic EnterPlanMode is tracked.
|
|
228
|
+
*/
|
|
229
|
+
function extractPlan(input) {
|
|
230
|
+
if (input.tool_name === "EnterPlanMode") {
|
|
231
|
+
return [{
|
|
232
|
+
type: "plan_enter",
|
|
233
|
+
category: "plan",
|
|
234
|
+
data: "entered plan mode",
|
|
235
|
+
priority: 2,
|
|
236
|
+
}];
|
|
237
|
+
}
|
|
238
|
+
if (input.tool_name === "ExitPlanMode") {
|
|
239
|
+
const events = [];
|
|
240
|
+
// Plan exit event with allowedPrompts detail
|
|
241
|
+
const prompts = input.tool_input["allowedPrompts"];
|
|
242
|
+
const detail = Array.isArray(prompts) && prompts.length > 0
|
|
243
|
+
? `exited plan mode (allowed: ${truncateAny(prompts.map((p) => {
|
|
244
|
+
if (typeof p === "object" && p !== null && "prompt" in p)
|
|
245
|
+
return String(p.prompt);
|
|
246
|
+
return String(p);
|
|
247
|
+
}).join(", "), 200)})`
|
|
248
|
+
: "exited plan mode";
|
|
249
|
+
events.push({
|
|
250
|
+
type: "plan_exit",
|
|
251
|
+
category: "plan",
|
|
252
|
+
data: truncate(detail),
|
|
253
|
+
priority: 2,
|
|
254
|
+
});
|
|
255
|
+
// Detect approval/rejection from tool_response
|
|
256
|
+
const response = String(input.tool_response ?? "").toLowerCase();
|
|
257
|
+
if (response.includes("approved") || response.includes("approve")) {
|
|
258
|
+
events.push({
|
|
259
|
+
type: "plan_approved",
|
|
260
|
+
category: "plan",
|
|
261
|
+
data: "plan approved by user",
|
|
262
|
+
priority: 1,
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
else if (response.includes("rejected") || response.includes("decline") || response.includes("denied")) {
|
|
266
|
+
events.push({
|
|
267
|
+
type: "plan_rejected",
|
|
268
|
+
category: "plan",
|
|
269
|
+
data: truncate(`plan rejected: ${input.tool_response ?? ""}`, 300),
|
|
270
|
+
priority: 2,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
return events;
|
|
274
|
+
}
|
|
275
|
+
// Detect plan file writes (Write/Edit to ~/.claude/plans/)
|
|
276
|
+
if (input.tool_name === "Write" || input.tool_name === "Edit") {
|
|
277
|
+
const filePath = String(input.tool_input["file_path"] ?? "");
|
|
278
|
+
if (/[/\\]\.claude[/\\]plans[/\\]/.test(filePath)) {
|
|
279
|
+
return [{
|
|
280
|
+
type: "plan_file_write",
|
|
281
|
+
category: "plan",
|
|
282
|
+
data: truncate(`plan file: ${filePath.split(/[/\\]/).pop() ?? filePath}`),
|
|
283
|
+
priority: 2,
|
|
284
|
+
}];
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return [];
|
|
288
|
+
}
|
|
202
289
|
/**
|
|
203
290
|
* Category 8: env
|
|
204
291
|
* Environment setup commands in Bash: venv, export, nvm, pyenv, conda, rbenv.
|
|
@@ -216,6 +303,12 @@ const ENV_PATTERNS = [
|
|
|
216
303
|
/\bbun\s+install\b/,
|
|
217
304
|
/\byarn\s+(add|install)\b/,
|
|
218
305
|
/\bpnpm\s+(add|install)\b/,
|
|
306
|
+
/\bcargo\s+(install|add)\b/,
|
|
307
|
+
/\bgo\s+(install|get)\b/,
|
|
308
|
+
/\brustup\b/,
|
|
309
|
+
/\basdf\b/,
|
|
310
|
+
/\bvolta\b/,
|
|
311
|
+
/\bdeno\s+install\b/,
|
|
219
312
|
];
|
|
220
313
|
function extractEnv(input) {
|
|
221
314
|
if (input.tool_name !== "Bash")
|
|
@@ -224,10 +317,12 @@ function extractEnv(input) {
|
|
|
224
317
|
const isEnvCmd = ENV_PATTERNS.some(p => p.test(cmd));
|
|
225
318
|
if (!isEnvCmd)
|
|
226
319
|
return [];
|
|
320
|
+
// Sanitize export commands to prevent secret leakage
|
|
321
|
+
const sanitized = cmd.replace(/\bexport\s+(\w+)=\S*/g, "export $1=***");
|
|
227
322
|
return [{
|
|
228
323
|
type: "env",
|
|
229
324
|
category: "env",
|
|
230
|
-
data: truncate(
|
|
325
|
+
data: truncate(sanitized),
|
|
231
326
|
priority: 2,
|
|
232
327
|
}];
|
|
233
328
|
}
|
|
@@ -288,6 +383,43 @@ function extractMcp(input) {
|
|
|
288
383
|
priority: 3,
|
|
289
384
|
}];
|
|
290
385
|
}
|
|
386
|
+
/**
|
|
387
|
+
* Category 6 (tool-based): decision
|
|
388
|
+
* AskUserQuestion tool — tracks questions posed to user and their answers.
|
|
389
|
+
*/
|
|
390
|
+
function extractDecision(input) {
|
|
391
|
+
if (input.tool_name !== "AskUserQuestion")
|
|
392
|
+
return [];
|
|
393
|
+
const questions = input.tool_input["questions"];
|
|
394
|
+
const questionText = Array.isArray(questions) && questions.length > 0
|
|
395
|
+
? String(questions[0]["question"] ?? "")
|
|
396
|
+
: "";
|
|
397
|
+
const answer = truncate(String(input.tool_response ?? ""), 150);
|
|
398
|
+
const summary = questionText
|
|
399
|
+
? `Q: ${truncate(questionText, 120)} → A: ${answer}`
|
|
400
|
+
: `answer: ${answer}`;
|
|
401
|
+
return [{
|
|
402
|
+
type: "decision_question",
|
|
403
|
+
category: "decision",
|
|
404
|
+
data: truncate(summary),
|
|
405
|
+
priority: 2,
|
|
406
|
+
}];
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Category 8: env (worktree)
|
|
410
|
+
* EnterWorktree tool — tracks worktree creation.
|
|
411
|
+
*/
|
|
412
|
+
function extractWorktree(input) {
|
|
413
|
+
if (input.tool_name !== "EnterWorktree")
|
|
414
|
+
return [];
|
|
415
|
+
const name = String(input.tool_input["name"] ?? "unnamed");
|
|
416
|
+
return [{
|
|
417
|
+
type: "worktree",
|
|
418
|
+
category: "env",
|
|
419
|
+
data: truncate(`entered worktree: ${name}`),
|
|
420
|
+
priority: 2,
|
|
421
|
+
}];
|
|
422
|
+
}
|
|
291
423
|
// ── User-message extractors ────────────────────────────────────────────────
|
|
292
424
|
/**
|
|
293
425
|
* Category 6: decision
|
|
@@ -300,7 +432,7 @@ const DECISION_PATTERNS = [
|
|
|
300
432
|
// Turkish patterns
|
|
301
433
|
/\b(hayır|hayir|evet|böyle|boyle|degil|değil|yerine|kullan)\b/i,
|
|
302
434
|
];
|
|
303
|
-
function
|
|
435
|
+
function extractUserDecision(message) {
|
|
304
436
|
const isDecision = DECISION_PATTERNS.some(p => p.test(message));
|
|
305
437
|
if (!isDecision)
|
|
306
438
|
return [];
|
|
@@ -386,9 +518,12 @@ export function extractEvents(input) {
|
|
|
386
518
|
events.push(...extractEnv(input));
|
|
387
519
|
// Tool-specific extractors
|
|
388
520
|
events.push(...extractTask(input));
|
|
521
|
+
events.push(...extractPlan(input));
|
|
389
522
|
events.push(...extractSkill(input));
|
|
390
523
|
events.push(...extractSubagent(input));
|
|
391
524
|
events.push(...extractMcp(input));
|
|
525
|
+
events.push(...extractDecision(input));
|
|
526
|
+
events.push(...extractWorktree(input));
|
|
392
527
|
return events;
|
|
393
528
|
}
|
|
394
529
|
catch {
|
|
@@ -405,7 +540,7 @@ export function extractEvents(input) {
|
|
|
405
540
|
export function extractUserEvents(message) {
|
|
406
541
|
try {
|
|
407
542
|
const events = [];
|
|
408
|
-
events.push(...
|
|
543
|
+
events.push(...extractUserDecision(message));
|
|
409
544
|
events.push(...extractRole(message));
|
|
410
545
|
events.push(...extractIntent(message));
|
|
411
546
|
events.push(...extractData(message));
|
|
@@ -50,7 +50,7 @@ export declare function renderDecisions(decisionEvents: StoredEvent[]): string;
|
|
|
50
50
|
*/
|
|
51
51
|
export declare function renderEnvironment(cwdEvent: StoredEvent | undefined, envEvents: StoredEvent[], gitEvent: StoredEvent | undefined): string;
|
|
52
52
|
/**
|
|
53
|
-
* Render <
|
|
53
|
+
* Render <errors_encountered> from error events.
|
|
54
54
|
*/
|
|
55
55
|
export declare function renderErrors(errorEvents: StoredEvent[]): string;
|
|
56
56
|
/**
|
|
@@ -41,8 +41,10 @@ export function renderActiveFiles(fileEvents) {
|
|
|
41
41
|
op = "write";
|
|
42
42
|
else if (ev.type === "file_read")
|
|
43
43
|
op = "read";
|
|
44
|
+
else if (ev.type === "file_edit")
|
|
45
|
+
op = "edit";
|
|
44
46
|
else
|
|
45
|
-
op =
|
|
47
|
+
op = ev.type;
|
|
46
48
|
entry.ops.set(op, (entry.ops.get(op) ?? 0) + 1);
|
|
47
49
|
entry.last = op;
|
|
48
50
|
}
|
|
@@ -86,7 +88,7 @@ export function renderTaskState(taskEvents) {
|
|
|
86
88
|
}
|
|
87
89
|
if (creates.length === 0)
|
|
88
90
|
return "";
|
|
89
|
-
const DONE = new Set(["completed", "deleted"]);
|
|
91
|
+
const DONE = new Set(["completed", "deleted", "failed"]);
|
|
90
92
|
// Match creates to updates positionally (creates[0] → lowest taskId)
|
|
91
93
|
const sortedIds = Object.keys(updates).sort((a, b) => Number(a) - Number(b));
|
|
92
94
|
const pending = [];
|
|
@@ -173,16 +175,16 @@ export function renderEnvironment(cwdEvent, envEvents, gitEvent) {
|
|
|
173
175
|
return parts.join("\n");
|
|
174
176
|
}
|
|
175
177
|
/**
|
|
176
|
-
* Render <
|
|
178
|
+
* Render <errors_encountered> from error events.
|
|
177
179
|
*/
|
|
178
180
|
export function renderErrors(errorEvents) {
|
|
179
181
|
if (errorEvents.length === 0)
|
|
180
182
|
return "";
|
|
181
|
-
const lines = [" <
|
|
183
|
+
const lines = [" <errors_encountered>"];
|
|
182
184
|
for (const ev of errorEvents) {
|
|
183
185
|
lines.push(` - ${escapeXML(truncateString(ev.data, 150))}`);
|
|
184
186
|
}
|
|
185
|
-
lines.push(" </
|
|
187
|
+
lines.push(" </errors_encountered>");
|
|
186
188
|
return lines.join("\n");
|
|
187
189
|
}
|
|
188
190
|
/**
|
|
@@ -251,12 +253,10 @@ export function buildResumeSnapshot(events, opts) {
|
|
|
251
253
|
const errorEvents = [];
|
|
252
254
|
const envEvents = [];
|
|
253
255
|
const gitEvents = [];
|
|
254
|
-
const skillEvents = [];
|
|
255
256
|
const subagentEvents = [];
|
|
256
|
-
const roleEvents = [];
|
|
257
|
-
const dataEvents = [];
|
|
258
257
|
const intentEvents = [];
|
|
259
258
|
const mcpEvents = [];
|
|
259
|
+
const planEvents = [];
|
|
260
260
|
for (const ev of events) {
|
|
261
261
|
switch (ev.category) {
|
|
262
262
|
case "file":
|
|
@@ -283,24 +283,18 @@ export function buildResumeSnapshot(events, opts) {
|
|
|
283
283
|
case "git":
|
|
284
284
|
gitEvents.push(ev);
|
|
285
285
|
break;
|
|
286
|
-
case "skill":
|
|
287
|
-
skillEvents.push(ev);
|
|
288
|
-
break;
|
|
289
286
|
case "subagent":
|
|
290
287
|
subagentEvents.push(ev);
|
|
291
288
|
break;
|
|
292
|
-
case "role":
|
|
293
|
-
roleEvents.push(ev);
|
|
294
|
-
break;
|
|
295
|
-
case "data":
|
|
296
|
-
dataEvents.push(ev);
|
|
297
|
-
break;
|
|
298
289
|
case "intent":
|
|
299
290
|
intentEvents.push(ev);
|
|
300
291
|
break;
|
|
301
292
|
case "mcp":
|
|
302
293
|
mcpEvents.push(ev);
|
|
303
294
|
break;
|
|
295
|
+
case "plan":
|
|
296
|
+
planEvents.push(ev);
|
|
297
|
+
break;
|
|
304
298
|
}
|
|
305
299
|
}
|
|
306
300
|
// ── Render sections by priority tier ──
|
|
@@ -315,7 +309,7 @@ export function buildResumeSnapshot(events, opts) {
|
|
|
315
309
|
const rules = renderRules(ruleEvents);
|
|
316
310
|
if (rules)
|
|
317
311
|
p1Sections.push(rules);
|
|
318
|
-
// P2 sections (35% budget): decisions, environment,
|
|
312
|
+
// P2 sections (35% budget): decisions, environment, errors_encountered, completed subagents
|
|
319
313
|
const p2Sections = [];
|
|
320
314
|
const decisions = renderDecisions(decisionEvents);
|
|
321
315
|
if (decisions)
|
|
@@ -333,6 +327,13 @@ export function buildResumeSnapshot(events, opts) {
|
|
|
333
327
|
const subagentsP2 = renderSubagents(completedSubagents);
|
|
334
328
|
if (subagentsP2)
|
|
335
329
|
p2Sections.push(subagentsP2);
|
|
330
|
+
// Plan mode state — show if plan is active (last event is plan_enter)
|
|
331
|
+
if (planEvents.length > 0) {
|
|
332
|
+
const lastPlan = planEvents[planEvents.length - 1];
|
|
333
|
+
if (lastPlan.type === "plan_enter") {
|
|
334
|
+
p2Sections.push(` <plan_mode status="active" />`);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
336
337
|
// P3-P4 sections (15% budget): intent, mcp_tools, launched subagents
|
|
337
338
|
const p3Sections = [];
|
|
338
339
|
if (intentEvents.length > 0) {
|
package/cli.bundle.mjs
CHANGED
|
@@ -282,7 +282,7 @@ async function main() {
|
|
|
282
282
|
main();
|
|
283
283
|
`}async function Rz(){let t=r0();t>0&&console.error(`Cleaned up ${t} stale DB file(s) from previous sessions`);let e=()=>{Rs.cleanupBackgrounded(),co&&co.cleanup()};process.on("exit",e),process.on("SIGINT",()=>{e(),process.exit(0)}),process.on("SIGTERM",()=>{e(),process.exit(0)});let r=new tc;await Yt.connect(r);try{let{detectPlatform:n,getAdapter:o}=await Promise.resolve().then(()=>(Hc(),hh)),s=n(),i=await o(s.platform);if(!i.capabilities.sessionStart){let a=gz(Ps(km(import.meta.url)),".."),c=process.env.CLAUDE_PROJECT_DIR??process.env.CODEX_HOME??process.cwd(),u=i.writeRoutingInstructions(c,a);u&&console.error(`Wrote routing instructions: ${u}`)}}catch{}console.error(`Context Mode MCP server v${y0} running on stdio`),console.error(`Detected runtimes:
|
|
284
284
|
${qs(Tm)}`),po()||(console.error(`
|
|
285
|
-
Performance tip: Install Bun for 3-5x faster JS/TS execution`),console.error(" curl -fsSL https://bun.sh/install | bash"))}var y0,Tm,_z,Yt,Rs,co,Je,bz,$z,Sz,wz,sc,vn,bm,kz,f0,m0,$m,Sm,b0=$(()=>{"use strict";Mb();qb();pm();hm();n0();d0();Fs();p0();y0="1.0.
|
|
285
|
+
Performance tip: Install Bun for 3-5x faster JS/TS execution`),console.error(" curl -fsSL https://bun.sh/install | bash"))}var y0,Tm,_z,Yt,Rs,co,Je,bz,$z,Sz,wz,sc,vn,bm,kz,f0,m0,$m,Sm,b0=$(()=>{"use strict";Mb();qb();pm();hm();n0();d0();Fs();p0();y0="1.0.13";process.on("unhandledRejection",t=>{process.stderr.write(`[context-mode] unhandledRejection: ${t}
|
|
286
286
|
`)});process.on("uncaughtException",t=>{process.stderr.write(`[context-mode] uncaughtException: ${t?.message??t}
|
|
287
287
|
`)});Tm=$n(),_z=Us(Tm),Yt=new Qa({name:"context-mode",version:y0}),Rs=new Es({runtimes:Tm,projectRoot:process.env.CLAUDE_PROJECT_DIR}),co=null;Je={calls:{},bytesReturned:{},bytesIndexed:0,bytesSandboxed:0,sessionStart:Date.now()};bz=_z.join(", "),$z=po()?" (Bun detected \u2014 JS/TS runs 3-5x faster)":"",Sz="",wz="";Yt.registerTool("ctx_execute",{title:"Execute Code",description:`MANDATORY: Use for any command where output exceeds 20 lines. Execute code in a sandboxed subprocess. Only stdout enters context \u2014 raw data stays in the subprocess.${$z} Available: ${bz}.
|
|
288
288
|
|
|
@@ -76,7 +76,7 @@ export function writeSessionEventsFile(events, eventsPath) {
|
|
|
76
76
|
creates.push(ev.data);
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
const DONE = new Set(["completed", "deleted"]);
|
|
79
|
+
const DONE = new Set(["completed", "deleted", "failed"]);
|
|
80
80
|
const sortedIds = Object.keys(updates).sort((a, b) => Number(a) - Number(b));
|
|
81
81
|
const pending = [];
|
|
82
82
|
const completed = [];
|
|
@@ -184,6 +184,21 @@ export function writeSessionEventsFile(events, eventsPath) {
|
|
|
184
184
|
lines.push("");
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
+
if (grouped.plan?.length > 0) {
|
|
188
|
+
const hasApproved = grouped.plan.some(e => e.type === "plan_approved");
|
|
189
|
+
const hasRejected = grouped.plan.some(e => e.type === "plan_rejected");
|
|
190
|
+
const lastPlan = grouped.plan[grouped.plan.length - 1];
|
|
191
|
+
const isActive = lastPlan.type === "plan_enter" || lastPlan.type === "plan_file_write";
|
|
192
|
+
lines.push("## Plan Mode");
|
|
193
|
+
lines.push("");
|
|
194
|
+
if (hasApproved) lines.push("- Status: APPROVED AND EXECUTED");
|
|
195
|
+
else if (hasRejected) lines.push("- Status: REJECTED BY USER");
|
|
196
|
+
else if (isActive) lines.push("- Status: ACTIVE (in planning)");
|
|
197
|
+
else lines.push("- Status: COMPLETED");
|
|
198
|
+
for (const ev of grouped.plan) lines.push(`- ${ev.data}`);
|
|
199
|
+
lines.push("");
|
|
200
|
+
}
|
|
201
|
+
|
|
187
202
|
if (lastPrompt) {
|
|
188
203
|
lines.push("## Last User Prompt");
|
|
189
204
|
lines.push("");
|
|
@@ -235,7 +250,7 @@ export function buildSessionDirective(source, eventMeta) {
|
|
|
235
250
|
}
|
|
236
251
|
|
|
237
252
|
if (creates.length > 0) {
|
|
238
|
-
const DONE = new Set(["completed", "deleted"]);
|
|
253
|
+
const DONE = new Set(["completed", "deleted", "failed"]);
|
|
239
254
|
const sortedIds = Object.keys(updates).sort((a, b) => Number(a) - Number(b));
|
|
240
255
|
const pending = [];
|
|
241
256
|
for (let i = 0; i < creates.length; i++) {
|
|
@@ -370,6 +385,33 @@ export function buildSessionDirective(source, eventMeta) {
|
|
|
370
385
|
block += `\n`;
|
|
371
386
|
}
|
|
372
387
|
|
|
388
|
+
// 14. Plan mode state — critical for preventing stale plan restoration
|
|
389
|
+
if (grouped.plan?.length > 0) {
|
|
390
|
+
const hasApproved = grouped.plan.some(e => e.type === "plan_approved");
|
|
391
|
+
const hasRejected = grouped.plan.some(e => e.type === "plan_rejected");
|
|
392
|
+
const hasFileWrite = grouped.plan.some(e => e.type === "plan_file_write");
|
|
393
|
+
const lastPlan = grouped.plan[grouped.plan.length - 1];
|
|
394
|
+
const isActive = lastPlan.type === "plan_enter" || lastPlan.type === "plan_file_write";
|
|
395
|
+
|
|
396
|
+
block += `\n## Plan Mode`;
|
|
397
|
+
if (hasApproved) {
|
|
398
|
+
block += `\n- Status: APPROVED AND EXECUTED`;
|
|
399
|
+
block += `\n- The plan was approved and executed. Do NOT re-enter plan mode or re-propose the same plan.`;
|
|
400
|
+
} else if (hasRejected) {
|
|
401
|
+
block += `\n- Status: REJECTED BY USER`;
|
|
402
|
+
block += `\n- The user rejected the previous plan. Ask what they want changed before re-planning.`;
|
|
403
|
+
} else if (isActive) {
|
|
404
|
+
block += `\n- Status: ACTIVE (in planning phase)`;
|
|
405
|
+
if (hasFileWrite) {
|
|
406
|
+
block += `\n- Plan file has been written. Awaiting user approval via ExitPlanMode.`;
|
|
407
|
+
}
|
|
408
|
+
} else {
|
|
409
|
+
block += `\n- Status: COMPLETED`;
|
|
410
|
+
block += `\n- The plan has been executed. Do NOT re-enter plan mode or re-propose the same plan.`;
|
|
411
|
+
}
|
|
412
|
+
block += `\n`;
|
|
413
|
+
}
|
|
414
|
+
|
|
373
415
|
block += `\n</session_guide>`;
|
|
374
416
|
|
|
375
417
|
// Search on demand — detailed data lives in FTS5
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "context-mode",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
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",
|
package/server.bundle.mjs
CHANGED
|
@@ -227,7 +227,7 @@ stdout:
|
|
|
227
227
|
${n}
|
|
228
228
|
|
|
229
229
|
stderr:
|
|
230
|
-
${o}`}}var lx="1.0.
|
|
230
|
+
${o}`}}var lx="1.0.13";process.on("unhandledRejection",t=>{process.stderr.write(`[context-mode] unhandledRejection: ${t}
|
|
231
231
|
`)});process.on("uncaughtException",t=>{process.stderr.write(`[context-mode] uncaughtException: ${t?.message??t}
|
|
232
232
|
`)});var hp=Ui(),uz=py(hp),Nt=new Zi({name:"context-mode",version:lx}),Wo=new Hi({runtimes:hp,projectRoot:process.env.CLAUDE_PROJECT_DIR}),Dn=null;function lz(t){try{let e=ra(ux(),".claude","context-mode","sessions");if(!cx(e))return;let r=oz(e).filter(n=>n.endsWith("-events.md"));for(let n of r){let o=ra(e,n);try{t.index({path:o,source:"session-events"}),nz(o)}catch{}}}catch{}}function Yo(){return Dn||(Dn=new Vi),lz(Dn),Dn}var qe={calls:{},bytesReturned:{},bytesIndexed:0,bytesSandboxed:0,sessionStart:Date.now()};function J(t,e){let r=e.content.reduce((n,o)=>n+Buffer.byteLength(o.text),0);return qe.calls[t]=(qe.calls[t]||0)+1,qe.bytesReturned[t]=(qe.bytesReturned[t]||0)+r,e}function gr(t){qe.bytesIndexed+=t}function gp(t,e){try{let r=Fd(process.env.CLAUDE_PROJECT_DIR),n=Hd(t,r);if(n.decision==="deny")return J(e,{content:[{type:"text",text:`Command blocked by security policy: matches deny pattern ${n.matchedPattern}`}],isError:!0})}catch{}return null}function dx(t,e,r){try{let n=Iy(t,e);if(n.length===0)return null;let o=Fd(process.env.CLAUDE_PROJECT_DIR);for(let s of n){let i=Hd(s,o);if(i.decision==="deny")return J(r,{content:[{type:"text",text:`Command blocked by security policy: embedded shell command "${s}" matches deny pattern ${i.matchedPattern}`}],isError:!0})}}catch{}return null}function dz(t,e){try{let r=zy("Read",process.env.CLAUDE_PROJECT_DIR),n=Oy(t,r);if(n.denied)return J(e,{content:[{type:"text",text:`File access blocked by security policy: path matches Read deny pattern ${n.matchedPattern}`}],isError:!0})}catch{}return null}var pz=uz.join(", "),fz=Zd()?" (Bun detected \u2014 JS/TS runs 3-5x faster)":"",mz="",hz="";function gz(t){let e=[],r=0,n=0;for(;n<t.length;)if(t[n]===mz){for(e.push(r),n++;n<t.length&&t[n]!==hz;)r++,n++;n<t.length&&n++}else r++,n++;return e}function px(t,e,r=1500,n){if(t.length<=r)return t;let o=[];if(n)for(let u of gz(n))o.push(u);if(o.length===0){let u=e.toLowerCase().split(/\s+/).filter(d=>d.length>2),l=t.toLowerCase();for(let d of u){let f=l.indexOf(d);for(;f!==-1;)o.push(f),f=l.indexOf(d,f+1)}}if(o.length===0)return t.slice(0,r)+`
|
|
233
233
|
\u2026`;o.sort((u,l)=>u-l);let s=300,i=[];for(let u of o){let l=Math.max(0,u-s),d=Math.min(t.length,u+s);i.length>0&&l<=i[i.length-1][1]?i[i.length-1][1]=d:i.push([l,d])}let a=[],c=0;for(let[u,l]of i){if(c>=r)break;let d=t.slice(u,Math.min(l,u+(r-c)));a.push((u>0?"\u2026":"")+d+(l<t.length?"\u2026":"")),c+=d.length}return a.join(`
|