MCPcopy Create free account
hub / github.com/IAmUnbounded/devctx / compressCommand

Function compressCommand

devctx/src/commands/compress.ts:13–119  ·  view source on GitHub ↗
(options?: { force?: boolean })

Source from the content-addressed store, hash-verified

11import { ContextEntry } from "../core/types";
12
13export async function compressCommand(options?: { force?: boolean }) {
14 if (!(await isInitialized())) {
15 console.log(chalk.red("✗ DevContext not initialized. Run `devctx init` first."));
16 return;
17 }
18
19 try {
20 const branch = await getCurrentBranch();
21 const entries = await loadBranchContext(branch);
22
23 if (entries.length <= 2) {
24 console.log(chalk.yellow("⚠ Not enough context to compress (need at least 3 entries)."));
25 return;
26 }
27
28 console.log(
29 chalk.gray(` Compressing ${entries.length} entries for branch: ${branch}...`)
30 );
31
32 // Keep the most recent entry intact, compress older ones
33 const toCompress = entries.slice(0, -1);
34 const latest = entries[entries.length - 1];
35
36 const prompt = `You are a developer assistant. Compress the following ${toCompress.length} coding session entries into a single summary entry. Keep only the most important information: key decisions, approaches that worked or failed, and overall progress.
37
38Sessions to compress:
39${toCompress
40 .map(
41 (e, i) => `
42Session ${i + 1} (${e.timestamp}):
43- Task: ${e.task}
44- Approaches: ${e.approaches.join(", ") || "none"}
45- Decisions: ${e.decisions.join(", ") || "none"}
46- State: ${e.currentState}
47- Next steps: ${e.nextSteps.join(", ") || "none"}
48`
49 )
50 .join("\n")}
51
52Generate a JSON response:
53{
54 "task": "overall task description covering all sessions",
55 "approaches": ["significant approaches tried"],
56 "decisions": ["key decisions made across all sessions"],
57 "currentState": "where things stood after these sessions",
58 "nextSteps": ["remaining next steps"]
59}
60
61Be concise but preserve important decisions and learnings.`;
62
63 const result = await callAI([
64 {
65 role: "system",
66 content: "You are a helpful assistant. Always respond with valid JSON.",
67 },
68 { role: "user", content: prompt },
69 ]);
70

Callers

nothing calls this directly

Calls 5

isInitializedFunction · 0.90
getCurrentBranchFunction · 0.90
loadBranchContextFunction · 0.90
callAIFunction · 0.90
getDevCtxDirFunction · 0.90

Tested by

no test coverage detected