@agentuity/opencode 1.0.15 → 1.0.16
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/dist/agents/expert-backend.js +1 -1
- package/dist/agents/expert-backend.js.map +1 -1
- package/dist/agents/expert-frontend.js +1 -1
- package/dist/agents/expert-frontend.js.map +1 -1
- package/dist/agents/expert-ops.js +1 -1
- package/dist/agents/expert-ops.js.map +1 -1
- package/dist/agents/expert.js +1 -1
- package/dist/agents/expert.js.map +1 -1
- package/dist/agents/monitor.d.ts +1 -1
- package/dist/agents/monitor.d.ts.map +1 -1
- package/dist/agents/monitor.js +22 -33
- package/dist/agents/monitor.js.map +1 -1
- package/dist/agents/reviewer.js +1 -1
- package/dist/agents/reviewer.js.map +1 -1
- package/dist/agents/scout.js +1 -1
- package/dist/agents/scout.js.map +1 -1
- package/dist/background/manager.d.ts +1 -0
- package/dist/background/manager.d.ts.map +1 -1
- package/dist/background/manager.js +60 -26
- package/dist/background/manager.js.map +1 -1
- package/dist/plugin/hooks/cadence.d.ts +3 -1
- package/dist/plugin/hooks/cadence.d.ts.map +1 -1
- package/dist/plugin/hooks/cadence.js +167 -66
- package/dist/plugin/hooks/cadence.js.map +1 -1
- package/dist/plugin/hooks/compaction-utils.d.ts +48 -0
- package/dist/plugin/hooks/compaction-utils.d.ts.map +1 -0
- package/dist/plugin/hooks/compaction-utils.js +259 -0
- package/dist/plugin/hooks/compaction-utils.js.map +1 -0
- package/dist/plugin/hooks/params.d.ts +1 -1
- package/dist/plugin/hooks/params.d.ts.map +1 -1
- package/dist/plugin/hooks/params.js +5 -1
- package/dist/plugin/hooks/params.js.map +1 -1
- package/dist/plugin/hooks/session-memory.d.ts +2 -1
- package/dist/plugin/hooks/session-memory.d.ts.map +1 -1
- package/dist/plugin/hooks/session-memory.js +97 -48
- package/dist/plugin/hooks/session-memory.js.map +1 -1
- package/dist/plugin/plugin.d.ts.map +1 -1
- package/dist/plugin/plugin.js +31 -9
- package/dist/plugin/plugin.js.map +1 -1
- package/dist/sqlite/index.d.ts +1 -1
- package/dist/sqlite/index.d.ts.map +1 -1
- package/dist/sqlite/queries.d.ts +1 -0
- package/dist/sqlite/queries.d.ts.map +1 -1
- package/dist/sqlite/queries.js +4 -0
- package/dist/sqlite/queries.js.map +1 -1
- package/dist/sqlite/reader.d.ts +11 -1
- package/dist/sqlite/reader.d.ts.map +1 -1
- package/dist/sqlite/reader.js +62 -0
- package/dist/sqlite/reader.js.map +1 -1
- package/dist/sqlite/types.d.ts +40 -0
- package/dist/sqlite/types.d.ts.map +1 -1
- package/dist/types.d.ts +36 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -1
- package/package.json +3 -3
- package/src/agents/expert-backend.ts +1 -1
- package/src/agents/expert-frontend.ts +1 -1
- package/src/agents/expert-ops.ts +1 -1
- package/src/agents/expert.ts +1 -1
- package/src/agents/monitor.ts +22 -33
- package/src/agents/reviewer.ts +1 -1
- package/src/agents/scout.ts +1 -1
- package/src/background/manager.ts +67 -31
- package/src/plugin/hooks/cadence.ts +184 -66
- package/src/plugin/hooks/compaction-utils.ts +291 -0
- package/src/plugin/hooks/params.ts +10 -1
- package/src/plugin/hooks/session-memory.ts +109 -47
- package/src/plugin/plugin.ts +47 -10
- package/src/sqlite/index.ts +4 -0
- package/src/sqlite/queries.ts +5 -0
- package/src/sqlite/reader.ts +69 -0
- package/src/sqlite/types.ts +40 -0
- package/src/types.ts +30 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the current git branch name.
|
|
3
|
+
* Moved here from cadence.ts and session-memory.ts to deduplicate.
|
|
4
|
+
*/
|
|
5
|
+
export async function getCurrentBranch() {
|
|
6
|
+
try {
|
|
7
|
+
const proc = Bun.spawn(['git', 'branch', '--show-current'], {
|
|
8
|
+
stdout: 'pipe',
|
|
9
|
+
stderr: 'pipe',
|
|
10
|
+
});
|
|
11
|
+
const stdout = await new Response(proc.stdout).text();
|
|
12
|
+
await proc.exited;
|
|
13
|
+
return stdout.trim() || 'unknown';
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return 'unknown';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Access Agentuity KV storage via CLI.
|
|
21
|
+
* All calls are wrapped in try/catch — returns null on failure.
|
|
22
|
+
*/
|
|
23
|
+
async function kvGet(namespace, key) {
|
|
24
|
+
try {
|
|
25
|
+
const proc = Bun.spawn(['agentuity', 'cloud', 'kv', 'get', namespace, key, '--json'], {
|
|
26
|
+
stdout: 'pipe',
|
|
27
|
+
stderr: 'pipe',
|
|
28
|
+
});
|
|
29
|
+
const output = await new Response(proc.stdout).text();
|
|
30
|
+
const exitCode = await proc.exited;
|
|
31
|
+
if (exitCode !== 0)
|
|
32
|
+
return null;
|
|
33
|
+
return JSON.parse(output);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function kvSet(namespace, key, value) {
|
|
40
|
+
try {
|
|
41
|
+
const proc = Bun.spawn(['agentuity', 'cloud', 'kv', 'set', namespace, key, JSON.stringify(value)], { stdout: 'pipe', stderr: 'pipe' });
|
|
42
|
+
const exitCode = await proc.exited;
|
|
43
|
+
return exitCode === 0;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Build the custom compaction prompt for our agent system.
|
|
51
|
+
* This REPLACES the default OpenCode compaction prompt via output.prompt.
|
|
52
|
+
*/
|
|
53
|
+
export function buildCustomCompactionPrompt(mode) {
|
|
54
|
+
const cadenceSection = mode === 'cadence'
|
|
55
|
+
? `
|
|
56
|
+
|
|
57
|
+
## Cadence Loop State
|
|
58
|
+
- Loop ID, iteration number, max iterations
|
|
59
|
+
- Current phase and what's in progress
|
|
60
|
+
- Whether this is a Lead-of-Leads session with child tasks`
|
|
61
|
+
: '';
|
|
62
|
+
return `You are generating a continuation context for a multi-agent coding system (Agentuity Coder). Your summary will be the ONLY context the orchestrating Lead agent has after this compaction. Preserve everything needed for seamless continuation.
|
|
63
|
+
|
|
64
|
+
## CRITICAL — Preserve These Verbatim
|
|
65
|
+
1. The current task/objective (quote the user's original request exactly)
|
|
66
|
+
2. All background task IDs (bg_xxx) with status, purpose, and session IDs
|
|
67
|
+
3. Active planning state: current phase, completed phases, next steps, blockers
|
|
68
|
+
4. ALL file paths being actively worked on (with role: created/modified/read)
|
|
69
|
+
5. Key decisions made and their rationale
|
|
70
|
+
6. Any corrections or gotchas discovered during the session
|
|
71
|
+
7. Todo list state (what's done, in progress, pending)
|
|
72
|
+
8. Descriptions of any images or attachments that appeared in conversation${cadenceSection}
|
|
73
|
+
|
|
74
|
+
## Structure Your Summary As:
|
|
75
|
+
|
|
76
|
+
### Active Task
|
|
77
|
+
[Verbatim objective + what the agent was doing when compaction fired]
|
|
78
|
+
|
|
79
|
+
### Planning State
|
|
80
|
+
[Phases with status. Include phase notes, not just titles.]
|
|
81
|
+
|
|
82
|
+
### Background Tasks
|
|
83
|
+
[bg_xxx: description → status (running/completed/errored). Include session IDs.]
|
|
84
|
+
|
|
85
|
+
### Key Context
|
|
86
|
+
[Decisions, constraints, user preferences, corrections discovered]
|
|
87
|
+
|
|
88
|
+
### Active Files
|
|
89
|
+
[filepath → role (creating/modifying/reading) + what's being done to it]
|
|
90
|
+
|
|
91
|
+
### Images & Attachments
|
|
92
|
+
[Describe any images/screenshots: what they showed, when they appeared, why they mattered]
|
|
93
|
+
|
|
94
|
+
### Next Steps
|
|
95
|
+
[What should happen immediately after compaction resumes]
|
|
96
|
+
|
|
97
|
+
## Rules
|
|
98
|
+
- Use specific file paths, task IDs, phase names — NOT vague references.
|
|
99
|
+
- State what tools returned, not just that they were called.
|
|
100
|
+
- NEVER drop background task references — the agent MUST know what's still running.
|
|
101
|
+
- Prefer completeness over brevity — this is the agent's entire working memory.`;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Fetch planning state from KV and format as markdown.
|
|
105
|
+
* Returns null if KV is unavailable or no planning state exists.
|
|
106
|
+
*/
|
|
107
|
+
export async function fetchAndFormatPlanningState(sessionId) {
|
|
108
|
+
try {
|
|
109
|
+
const record = await kvGet('agentuity-opencode-memory', `session:${sessionId}`);
|
|
110
|
+
if (!record || typeof record !== 'object')
|
|
111
|
+
return null;
|
|
112
|
+
const data = record.data ?? record;
|
|
113
|
+
const planning = data.planning;
|
|
114
|
+
if (!planning)
|
|
115
|
+
return null;
|
|
116
|
+
const lines = ['## Planning State (from KV)'];
|
|
117
|
+
if (planning.objective)
|
|
118
|
+
lines.push(`**Objective:** ${planning.objective}`);
|
|
119
|
+
if (planning.current)
|
|
120
|
+
lines.push(`**Current:** ${planning.current}`);
|
|
121
|
+
if (planning.next)
|
|
122
|
+
lines.push(`**Next:** ${planning.next}`);
|
|
123
|
+
const phases = planning.phases;
|
|
124
|
+
if (phases?.length) {
|
|
125
|
+
lines.push('', '### Phases:');
|
|
126
|
+
for (const p of phases) {
|
|
127
|
+
const status = p.status ?? 'unknown';
|
|
128
|
+
const title = p.title ?? p.content ?? 'untitled';
|
|
129
|
+
const notes = p.notes ? ` — ${String(p.notes).slice(0, 100)}` : '';
|
|
130
|
+
lines.push(`- [${status}] ${title}${notes}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const findings = planning.findings;
|
|
134
|
+
if (findings?.length) {
|
|
135
|
+
lines.push('', '### Key Findings:');
|
|
136
|
+
for (const f of findings.slice(0, 5)) {
|
|
137
|
+
lines.push(`- ${String(f).slice(0, 150)}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const errors = planning.errors;
|
|
141
|
+
if (errors?.length) {
|
|
142
|
+
lines.push('', '### Errors to Avoid:');
|
|
143
|
+
for (const e of errors.slice(0, 3)) {
|
|
144
|
+
lines.push(`- ${String(e).slice(0, 150)}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return lines.join('\n');
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get image/attachment descriptions from SQLite for compaction context.
|
|
155
|
+
* Returns brief metadata about non-text parts in the conversation.
|
|
156
|
+
*/
|
|
157
|
+
export function getImageDescriptions(dbReader, sessionId) {
|
|
158
|
+
if (!dbReader?.isAvailable())
|
|
159
|
+
return null;
|
|
160
|
+
try {
|
|
161
|
+
const parts = dbReader.getNonTextParts(sessionId);
|
|
162
|
+
if (!parts.length)
|
|
163
|
+
return null;
|
|
164
|
+
// Filter to image-like parts (not tool calls — those are separate)
|
|
165
|
+
const imageParts = parts.filter((p) => !['tool-invocation', 'tool-result', 'text'].includes(p.type));
|
|
166
|
+
if (!imageParts.length)
|
|
167
|
+
return null;
|
|
168
|
+
const lines = ['## Images & Attachments'];
|
|
169
|
+
for (const part of imageParts.slice(0, 10)) {
|
|
170
|
+
const when = part.timestamp ? ` at ${part.timestamp}` : '';
|
|
171
|
+
lines.push(`- [${part.type}]${when}: message ${part.messageId}`);
|
|
172
|
+
}
|
|
173
|
+
return lines.join('\n');
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Get recent tool call summaries for compaction context.
|
|
181
|
+
* CONCISE — capped at limit calls, brief descriptions only.
|
|
182
|
+
*/
|
|
183
|
+
export function getRecentToolCallSummaries(dbReader, sessionId, limit = 5) {
|
|
184
|
+
if (!dbReader?.isAvailable() || limit <= 0)
|
|
185
|
+
return null;
|
|
186
|
+
try {
|
|
187
|
+
const calls = dbReader.getRecentToolCalls(sessionId, limit);
|
|
188
|
+
if (!calls.length)
|
|
189
|
+
return null;
|
|
190
|
+
const lines = ['## Recent Tool Activity'];
|
|
191
|
+
for (const call of calls) {
|
|
192
|
+
const inputBrief = call.input ? ` — ${String(call.input).slice(0, 80)}` : '';
|
|
193
|
+
const outputBrief = call.output ? ` → ${String(call.output).slice(0, 80)}` : '';
|
|
194
|
+
lines.push(`- ${call.toolName}${inputBrief}${outputBrief}`);
|
|
195
|
+
}
|
|
196
|
+
return lines.join('\n');
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Store a pre-compaction snapshot to KV as a recovery mechanism.
|
|
204
|
+
*/
|
|
205
|
+
export async function storePreCompactionSnapshot(sessionId, snapshot) {
|
|
206
|
+
try {
|
|
207
|
+
await kvSet('agentuity-opencode-memory', `compaction:snapshot:${sessionId}`, snapshot);
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
// Silently fail — this is a best-effort recovery mechanism
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Persist Cadence session state to KV for recovery after plugin restart.
|
|
215
|
+
*/
|
|
216
|
+
export async function persistCadenceStateToKV(sessionId, state) {
|
|
217
|
+
try {
|
|
218
|
+
await kvSet('agentuity-opencode-memory', `cadence:active:${sessionId}`, state);
|
|
219
|
+
}
|
|
220
|
+
catch {
|
|
221
|
+
// Silently fail
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Restore Cadence session state from KV.
|
|
226
|
+
*/
|
|
227
|
+
export async function restoreCadenceStateFromKV(sessionId) {
|
|
228
|
+
try {
|
|
229
|
+
const state = await kvGet('agentuity-opencode-memory', `cadence:active:${sessionId}`);
|
|
230
|
+
return state;
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Format compaction diagnostics — brief summary of what was preserved.
|
|
238
|
+
*/
|
|
239
|
+
export function formatCompactionDiagnostics(stats) {
|
|
240
|
+
const parts = [];
|
|
241
|
+
if (stats.planningPhasesCount > 0)
|
|
242
|
+
parts.push(`${stats.planningPhasesCount} planning phases`);
|
|
243
|
+
if (stats.backgroundTasksCount > 0)
|
|
244
|
+
parts.push(`${stats.backgroundTasksCount} background tasks`);
|
|
245
|
+
if (stats.imageDescriptionsCount > 0)
|
|
246
|
+
parts.push(`${stats.imageDescriptionsCount} image refs`);
|
|
247
|
+
if (stats.toolCallSummariesCount > 0)
|
|
248
|
+
parts.push(`${stats.toolCallSummariesCount} tool calls`);
|
|
249
|
+
if (!parts.length)
|
|
250
|
+
return '';
|
|
251
|
+
return `> **Compaction preserved:** ${parts.join(', ')} (~${stats.estimatedTokens} tokens injected)`;
|
|
252
|
+
}
|
|
253
|
+
/** Count markdown list items in a string */
|
|
254
|
+
export function countListItems(s) {
|
|
255
|
+
if (!s)
|
|
256
|
+
return 0;
|
|
257
|
+
return (s.match(/^- /gm) ?? []).length;
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=compaction-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compaction-utils.js","sourceRoot":"","sources":["../../../src/plugin/hooks/compaction-utils.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACrC,IAAI,CAAC;QACJ,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,gBAAgB,CAAC,EAAE;YAC3D,MAAM,EAAE,MAAM;YACd,MAAM,EAAE,MAAM;SACd,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;QACtD,MAAM,IAAI,CAAC,MAAM,CAAC;QAClB,OAAO,MAAM,CAAC,IAAI,EAAE,IAAI,SAAS,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;I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,CAAC;QAAE,OAAO,CAAC,CAAC;IACjB,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;AACxC,CAAC"}
|
|
@@ -3,7 +3,7 @@ import type { CoderConfig } from '../../types';
|
|
|
3
3
|
export interface ParamsHooks {
|
|
4
4
|
onParams: (input: unknown, output: unknown) => Promise<void>;
|
|
5
5
|
}
|
|
6
|
-
export declare function createParamsHooks(ctx: PluginInput, _config: CoderConfig): ParamsHooks;
|
|
6
|
+
export declare function createParamsHooks(ctx: PluginInput, _config: CoderConfig, lastUserMessages?: Map<string, string>): ParamsHooks;
|
|
7
7
|
/**
|
|
8
8
|
* Advertised magic words for users:
|
|
9
9
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../../src/plugin/hooks/params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,WAAW,WAAW;IAC3B,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7D;AA4FD,wBAAgB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../../src/plugin/hooks/params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,WAAW,WAAW;IAC3B,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7D;AA4FD,wBAAgB,iBAAiB,CAChC,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,WAAW,EACpB,gBAAgB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,WAAW,CAoFb;AAED;;;;;;;;;;;;;GAaG"}
|
|
@@ -80,7 +80,7 @@ function detectMode(messageContent) {
|
|
|
80
80
|
}
|
|
81
81
|
return null;
|
|
82
82
|
}
|
|
83
|
-
export function createParamsHooks(ctx, _config) {
|
|
83
|
+
export function createParamsHooks(ctx, _config, lastUserMessages) {
|
|
84
84
|
return {
|
|
85
85
|
async onParams(input, output) {
|
|
86
86
|
// Input contains: sessionID, agent, model, provider, message
|
|
@@ -91,6 +91,10 @@ export function createParamsHooks(ctx, _config) {
|
|
|
91
91
|
const messageContent = inputObj.message?.content || '';
|
|
92
92
|
if (!messageContent)
|
|
93
93
|
return;
|
|
94
|
+
// Store user message text for downstream hooks (e.g. cadence trigger detection)
|
|
95
|
+
if (lastUserMessages && inputObj.sessionID) {
|
|
96
|
+
lastUserMessages.set(inputObj.sessionID, messageContent);
|
|
97
|
+
}
|
|
94
98
|
// Check for dynamic mode triggers
|
|
95
99
|
const detected = detectMode(messageContent);
|
|
96
100
|
if (!detected)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"params.js","sourceRoot":"","sources":["../../../src/plugin/hooks/params.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,MAAM,aAAa,GAAG;IACrB;;;OAGG;IACH,QAAQ,EAAE;QACT,QAAQ,EAAE;YACT,YAAY;YACZ,aAAa;YACb,cAAc;YACd,eAAe;YACf,iBAAiB;YACjB,sBAAsB;YACtB,uBAAuB;SACvB;QACD,QAAQ,EAAE;YACT,WAAW,EAAE,GAAG;SAChB;KACD;IAED;;;OAGG;IACH,SAAS,EAAE;QACV,QAAQ,EAAE;YACT,YAAY;YACZ,cAAc;YACd,qBAAqB;YACrB,mBAAmB;YACnB,oBAAoB;YACpB,yBAAyB;SACzB;QACD,QAAQ,EAAE;YACT,yDAAyD;YACzD,+CAA+C;YAC/C,QAAQ,EAAE;gBACT,IAAI,EAAE,SAAS;gBACf,YAAY,EAAE,KAAK;aACnB;SACD;KACD;IAED;;;OAGG;IACH,QAAQ,EAAE;QACT,QAAQ,EAAE;YACT,UAAU;YACV,SAAS;YACT,WAAW;YACX,gBAAgB;YAChB,aAAa;YACb,eAAe;SACf;QACD,QAAQ,EAAE;YACT,QAAQ,EAAE,EAAE;SACZ;KACD;CACQ,CAAC;AAEX;;GAEG;AACH,SAAS,UAAU,CAClB,cAAsB;IAEtB,MAAM,KAAK,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC;IAE3C,KAAK,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;QAChE,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YACvC,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC7B,OAAO;oBACN,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,MAAM,CAAC,QAAmC;iBACpD,CAAC;YACH,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AAED,MAAM,UAAU,iBAAiB,
|
|
1
|
+
{"version":3,"file":"params.js","sourceRoot":"","sources":["../../../src/plugin/hooks/params.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,MAAM,aAAa,GAAG;IACrB;;;OAGG;IACH,QAAQ,EAAE;QACT,QAAQ,EAAE;YACT,YAAY;YACZ,aAAa;YACb,cAAc;YACd,eAAe;YACf,iBAAiB;YACjB,sBAAsB;YACtB,uBAAuB;SACvB;QACD,QAAQ,EAAE;YACT,WAAW,EAAE,GAAG;SAChB;KACD;IAED;;;OAGG;IACH,SAAS,EAAE;QACV,QAAQ,EAAE;YACT,YAAY;YACZ,cAAc;YACd,qBAAqB;YACrB,mBAAmB;YACnB,oBAAoB;YACpB,yBAAyB;SACzB;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AAO,QAAQ,CAAC,QAAQ,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;gBACvF,SAAS,CAAC,OAAO,GAAG;oBACnB,GAAG,SAAS,CAAC,OAAO;oBACpB,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,QAAQ;iBACpC,CAAC;YACH,CAAC;YAED,yDAAyD;YACzD,IAAI,UAAU,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;gBACrC,SAAS,CAAC,OAAO,GAAG;oBACnB,GAAG,SAAS,CAAC,OAAO;oBACpB,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,QAAQ;iBACpC,CAAC;YACH,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;GAaG"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PluginInput } from '@opencode-ai/plugin';
|
|
2
2
|
import type { CoderConfig } from '../../types';
|
|
3
3
|
import type { BackgroundManager } from '../../background';
|
|
4
|
+
import type { OpenCodeDBReader } from '../../sqlite';
|
|
4
5
|
export interface SessionMemoryHooks {
|
|
5
6
|
onEvent: (input: {
|
|
6
7
|
event: {
|
|
@@ -22,5 +23,5 @@ export interface SessionMemoryHooks {
|
|
|
22
23
|
* 1. On compacting: Inject Memory system info into compaction prompt
|
|
23
24
|
* 2. On session.compacted: Tell Lead to have Memory save the summary (it's already in context!)
|
|
24
25
|
*/
|
|
25
|
-
export declare function createSessionMemoryHooks(ctx: PluginInput,
|
|
26
|
+
export declare function createSessionMemoryHooks(ctx: PluginInput, config: CoderConfig, backgroundManager?: BackgroundManager, dbReader?: OpenCodeDBReader): SessionMemoryHooks;
|
|
26
27
|
//# sourceMappingURL=session-memory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-memory.d.ts","sourceRoot":"","sources":["../../../src/plugin/hooks/session-memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"session-memory.d.ts","sourceRoot":"","sources":["../../../src/plugin/hooks/session-memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAarD,MAAM,WAAW,kBAAkB;IAClC,OAAO,EAAE,CAAC,KAAK,EAAE;QAChB,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;SAAE,CAAC;KAC9D,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpB,YAAY,EAAE,CACb,KAAK,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,EAC5B,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,EAAE,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,KAC1C,OAAO,CAAC,IAAI,CAAC,CAAC;CACnB;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,WAAW,EACnB,iBAAiB,CAAC,EAAE,iBAAiB,EACrC,QAAQ,CAAC,EAAE,gBAAgB,GACzB,kBAAkB,CAoOpB"}
|
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Get the current git branch name.
|
|
3
|
-
*/
|
|
4
|
-
async function getCurrentBranch() {
|
|
5
|
-
try {
|
|
6
|
-
const proc = Bun.spawn(['git', 'branch', '--show-current'], {
|
|
7
|
-
stdout: 'pipe',
|
|
8
|
-
stderr: 'pipe',
|
|
9
|
-
});
|
|
10
|
-
const stdout = await new Response(proc.stdout).text();
|
|
11
|
-
await proc.exited;
|
|
12
|
-
return stdout.trim() || 'unknown';
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
return 'unknown';
|
|
16
|
-
}
|
|
17
|
-
}
|
|
1
|
+
import { getCurrentBranch, buildCustomCompactionPrompt, fetchAndFormatPlanningState, getImageDescriptions, getRecentToolCallSummaries, storePreCompactionSnapshot, formatCompactionDiagnostics, countListItems, } from './compaction-utils';
|
|
18
2
|
/**
|
|
19
3
|
* Session memory hooks handle compaction for non-Cadence sessions.
|
|
20
4
|
*
|
|
@@ -22,7 +6,7 @@ async function getCurrentBranch() {
|
|
|
22
6
|
* 1. On compacting: Inject Memory system info into compaction prompt
|
|
23
7
|
* 2. On session.compacted: Tell Lead to have Memory save the summary (it's already in context!)
|
|
24
8
|
*/
|
|
25
|
-
export function createSessionMemoryHooks(ctx,
|
|
9
|
+
export function createSessionMemoryHooks(ctx, config, backgroundManager, dbReader) {
|
|
26
10
|
const log = (msg) => {
|
|
27
11
|
ctx.client.app.log({
|
|
28
12
|
body: {
|
|
@@ -118,51 +102,116 @@ Then continue with the current task if there is one.`,
|
|
|
118
102
|
},
|
|
119
103
|
/**
|
|
120
104
|
* Inject Memory system info during compaction.
|
|
121
|
-
*
|
|
105
|
+
* Uses output.prompt to REPLACE the default compaction prompt with
|
|
106
|
+
* enriched context (planning state, images, tool calls, diagnostics).
|
|
122
107
|
*/
|
|
123
108
|
async onCompacting(input, output) {
|
|
124
109
|
const sessionId = input.sessionID;
|
|
125
110
|
log(`Compacting session ${sessionId}`);
|
|
126
|
-
//
|
|
127
|
-
const
|
|
128
|
-
|
|
111
|
+
// Config flags for compaction behavior
|
|
112
|
+
const compactionCfg = config?.compaction ?? {};
|
|
113
|
+
const useCustomPrompt = compactionCfg.customPrompt !== false;
|
|
114
|
+
const useInlinePlanning = compactionCfg.inlinePlanning !== false;
|
|
115
|
+
const useImageAwareness = compactionCfg.imageAwareness !== false;
|
|
116
|
+
const useSnapshotToKV = compactionCfg.snapshotToKV !== false;
|
|
117
|
+
const maxTokens = compactionCfg.maxContextTokens ?? 4000;
|
|
118
|
+
// 1. Build custom compaction instructions
|
|
119
|
+
const instructions = useCustomPrompt ? buildCustomCompactionPrompt('regular') : null;
|
|
120
|
+
// 2. Gather enrichment data in parallel
|
|
121
|
+
const toolCallLimit = config?.compaction?.toolCallSummaryLimit ?? 5;
|
|
122
|
+
const [branch, planningState, imageDescs, toolSummaries] = await Promise.all([
|
|
123
|
+
getCurrentBranch(),
|
|
124
|
+
useInlinePlanning ? fetchAndFormatPlanningState(sessionId) : Promise.resolve(null),
|
|
125
|
+
useImageAwareness
|
|
126
|
+
? Promise.resolve(getImageDescriptions(dbReader ?? null, sessionId))
|
|
127
|
+
: Promise.resolve(null),
|
|
128
|
+
Promise.resolve(getRecentToolCallSummaries(dbReader ?? null, sessionId, toolCallLimit)),
|
|
129
|
+
]);
|
|
130
|
+
// 3. Build session state section
|
|
131
|
+
const sessionStateSection = `## Session Memory
|
|
132
|
+
|
|
133
|
+
This session's context is being saved to persistent memory.
|
|
134
|
+
Session record location: \`session:${sessionId}\` in agentuity-opencode-memory
|
|
135
|
+
Current branch: ${branch}
|
|
136
|
+
|
|
137
|
+
After compaction:
|
|
138
|
+
1. Memory will save this summary to the session record
|
|
139
|
+
2. If planning is active, Memory should update planning.progress with this compaction
|
|
140
|
+
3. Memory will apply inline reasoning if significant patterns/corrections emerged`;
|
|
141
|
+
// 4. Build background tasks section
|
|
129
142
|
const tasks = backgroundManager?.getTasksByParent(sessionId) ?? [];
|
|
130
|
-
let
|
|
143
|
+
let backgroundSection = null;
|
|
131
144
|
if (tasks.length > 0) {
|
|
132
145
|
const taskList = tasks
|
|
133
146
|
.map((t) => `- **${t.id}**: ${t.description || 'No description'} (session: ${t.sessionId ?? 'pending'}, status: ${t.status})`)
|
|
134
147
|
.join('\n');
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
## Active Background Tasks
|
|
148
|
+
backgroundSection = `## Active Background Tasks
|
|
138
149
|
|
|
139
150
|
This session has ${tasks.length} background task(s) running in separate sessions:
|
|
140
151
|
${taskList}
|
|
141
152
|
|
|
142
153
|
**CRITICAL:** Task IDs and session IDs persist across compaction - these tasks are still running.
|
|
143
|
-
Use \`agentuity_background_output({ task_id: "..." })\` to check their status
|
|
144
|
-
|
|
154
|
+
Use \`agentuity_background_output({ task_id: "..." })\` to check their status.`;
|
|
155
|
+
}
|
|
156
|
+
// 5. Combine everything into the full prompt
|
|
157
|
+
const sections = [];
|
|
158
|
+
if (instructions)
|
|
159
|
+
sections.push(instructions);
|
|
160
|
+
sections.push(sessionStateSection);
|
|
161
|
+
if (backgroundSection)
|
|
162
|
+
sections.push(backgroundSection);
|
|
163
|
+
if (planningState)
|
|
164
|
+
sections.push(planningState);
|
|
165
|
+
if (imageDescs)
|
|
166
|
+
sections.push(imageDescs);
|
|
167
|
+
if (toolSummaries)
|
|
168
|
+
sections.push(toolSummaries);
|
|
169
|
+
// 6. Add diagnostics
|
|
170
|
+
const stats = {
|
|
171
|
+
planningPhasesCount: countListItems(planningState),
|
|
172
|
+
backgroundTasksCount: tasks.length,
|
|
173
|
+
imageDescriptionsCount: countListItems(imageDescs),
|
|
174
|
+
toolCallSummariesCount: countListItems(toolSummaries),
|
|
175
|
+
estimatedTokens: Math.ceil(sections.join('\n\n').length / 4),
|
|
176
|
+
};
|
|
177
|
+
const diagnostics = formatCompactionDiagnostics(stats);
|
|
178
|
+
if (diagnostics)
|
|
179
|
+
sections.push(diagnostics);
|
|
180
|
+
// 7. Enforce token budget
|
|
181
|
+
let fullPrompt = sections.join('\n\n');
|
|
182
|
+
const estimatedTokens = Math.ceil(fullPrompt.length / 4);
|
|
183
|
+
if (maxTokens > 0 && estimatedTokens > maxTokens) {
|
|
184
|
+
// Trim least-critical sections first
|
|
185
|
+
const trimOrder = [diagnostics, toolSummaries, imageDescs, planningState].filter(Boolean);
|
|
186
|
+
let trimmed = [...sections];
|
|
187
|
+
for (const candidate of trimOrder) {
|
|
188
|
+
if (Math.ceil(trimmed.join('\n\n').length / 4) <= maxTokens)
|
|
189
|
+
break;
|
|
190
|
+
trimmed = trimmed.filter((s) => s !== candidate);
|
|
191
|
+
}
|
|
192
|
+
fullPrompt = trimmed.join('\n\n');
|
|
193
|
+
}
|
|
194
|
+
// 8. Set the full prompt or push to context
|
|
195
|
+
if (useCustomPrompt) {
|
|
196
|
+
output.prompt = fullPrompt;
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
output.context.push(fullPrompt);
|
|
200
|
+
}
|
|
201
|
+
// 9. Store pre-compaction snapshot to KV (fire-and-forget)
|
|
202
|
+
if (useSnapshotToKV) {
|
|
203
|
+
storePreCompactionSnapshot(sessionId, {
|
|
204
|
+
timestamp: new Date().toISOString(),
|
|
205
|
+
sessionId,
|
|
206
|
+
planningState: planningState ? { raw: planningState } : undefined,
|
|
207
|
+
backgroundTasks: tasks.map((t) => ({
|
|
208
|
+
id: t.id,
|
|
209
|
+
description: t.description || 'No description',
|
|
210
|
+
status: t.status,
|
|
211
|
+
})),
|
|
212
|
+
branch,
|
|
213
|
+
}).catch(() => { }); // Fire and forget
|
|
145
214
|
}
|
|
146
|
-
output.context.push(`
|
|
147
|
-
## Session Memory
|
|
148
|
-
|
|
149
|
-
This session's context is being saved to persistent memory.
|
|
150
|
-
Session record location: \`session:${sessionId}\` in agentuity-opencode-memory
|
|
151
|
-
Current branch: ${branch}
|
|
152
|
-
|
|
153
|
-
**Planning State (if active):**
|
|
154
|
-
If this session has planning active (user requested "track progress" or similar), the session record contains:
|
|
155
|
-
- \`planning.prdKey\` - Link to PRD if one exists
|
|
156
|
-
- \`planning.objective\` - What we're trying to accomplish
|
|
157
|
-
- \`planning.phases\` - Current phases with status and notes
|
|
158
|
-
- \`planning.findings\` - Discoveries made during work
|
|
159
|
-
- \`planning.errors\` - Failures to avoid repeating
|
|
160
|
-
${backgroundTaskContext}
|
|
161
|
-
After compaction:
|
|
162
|
-
1. Memory will save this summary to the session record
|
|
163
|
-
2. If planning is active, Memory should update planning.progress with this compaction
|
|
164
|
-
3. Memory will apply inline reasoning if significant patterns/corrections emerged
|
|
165
|
-
`);
|
|
166
215
|
},
|
|
167
216
|
};
|
|
168
217
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-memory.js","sourceRoot":"","sources":["../../../src/plugin/hooks/session-memory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"session-memory.js","sourceRoot":"","sources":["../../../src/plugin/hooks/session-memory.ts"],"names":[],"mappings":"AAKA,OAAO,EACN,gBAAgB,EAChB,2BAA2B,EAC3B,2BAA2B,EAC3B,oBAAoB,EACpB,0BAA0B,EAC1B,0BAA0B,EAC1B,2BAA2B,EAC3B,cAAc,GACd,MAAM,oBAAoB,CAAC;AAY5B;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACvC,GAAgB,EAChB,MAAmB,EACnB,iBAAqC,EACrC,QAA2B;IAE3B,MAAM,GAAG,GAAG,CAAC,GAAW,EAAE,EAAE;QAC3B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;YAClB,IAAI,EAAE;gBACL,OAAO,EAAE,gBAAgB;gBACzB,KAAK,EAAE,OAAO;gBACd,OAAO,EAAE,GAAG;aACZ;SACD,CAAC,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACN;;;WAGG;QACH,KAAK,CAAC,OAAO,CAAC,KAEb;YACA,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;YACxB,IAAI,KAAK,EAAE,IAAI,KAAK,mBAAmB;gBAAE,OAAO;YAEhD,MAAM,SAAS,GACb,KAAK,CAAC,UAAU,EAAE,SAAgC;gBAClD,KAAK,CAAC,UAAU,EAAE,SAAgC,CAAC;YAErD,IAAI,CAAC,SAAS;gBA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,CAAC,CAAC,WAAW,IAAI,gBAAgB;wBAC9C,MAAM,EAAE,CAAC,CAAC,MAAM;qBAChB,CAAC,CAAC;oBACH,MAAM;iBACN,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC,CAAC,kBAAkB;YACvC,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/plugin/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAgF9D,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/plugin/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAgF9D,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,CAqMxE"}
|
package/dist/plugin/plugin.js
CHANGED
|
@@ -64,10 +64,13 @@ export async function createCoderPlugin(ctx) {
|
|
|
64
64
|
const coderConfig = mergeConfig(getDefaultConfig(), userConfig);
|
|
65
65
|
const resolvedDbPath = resolveOpenCodeDBPath();
|
|
66
66
|
const dbReader = new OpenCodeDBReader(resolvedDbPath ? { dbPath: resolvedDbPath } : undefined);
|
|
67
|
+
// Shared Map: chat.params stores the user's message text per session,
|
|
68
|
+
// chat.message reads it for trigger detection (avoids scanning model output).
|
|
69
|
+
const lastUserMessages = new Map();
|
|
67
70
|
const sessionHooks = createSessionHooks(ctx, coderConfig);
|
|
68
71
|
const toolHooks = createToolHooks(ctx, coderConfig);
|
|
69
72
|
const keywordHooks = createKeywordHooks(ctx, coderConfig);
|
|
70
|
-
const paramsHooks = createParamsHooks(ctx, coderConfig);
|
|
73
|
+
const paramsHooks = createParamsHooks(ctx, coderConfig, lastUserMessages);
|
|
71
74
|
const tmuxManager = coderConfig.tmux?.enabled
|
|
72
75
|
? new TmuxSessionManager(ctx, coderConfig.tmux, {
|
|
73
76
|
onLog: (message) => ctx.client.app.log({
|
|
@@ -121,10 +124,10 @@ export async function createCoderPlugin(ctx) {
|
|
|
121
124
|
});
|
|
122
125
|
});
|
|
123
126
|
// Create hooks that need backgroundManager for task reference injection during compaction
|
|
124
|
-
const cadenceHooks = createCadenceHooks(ctx, coderConfig, backgroundManager, dbReader);
|
|
127
|
+
const cadenceHooks = createCadenceHooks(ctx, coderConfig, backgroundManager, dbReader, lastUserMessages);
|
|
125
128
|
// Session memory hooks handle checkpointing and compaction for non-Cadence sessions
|
|
126
129
|
// Orchestration (deciding which module handles which session) happens below in the hooks
|
|
127
|
-
const sessionMemoryHooks = createSessionMemoryHooks(ctx, coderConfig, backgroundManager);
|
|
130
|
+
const sessionMemoryHooks = createSessionMemoryHooks(ctx, coderConfig, backgroundManager, dbReader);
|
|
128
131
|
const configHandler = createConfigHandler(coderConfig);
|
|
129
132
|
// Create plugin tools using the @opencode-ai/plugin tool helper
|
|
130
133
|
const tools = createTools(backgroundManager, dbReader);
|
|
@@ -187,15 +190,25 @@ export async function createCoderPlugin(ctx) {
|
|
|
187
190
|
}
|
|
188
191
|
// Orchestrate: route to appropriate module based on session type
|
|
189
192
|
const sessionId = extractSessionIdFromEvent(input);
|
|
190
|
-
if (sessionId
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
193
|
+
if (sessionId) {
|
|
194
|
+
// Try lazy restore from KV if not in memory (survives plugin restarts)
|
|
195
|
+
if (!cadenceHooks.isActiveCadenceSession(sessionId)) {
|
|
196
|
+
await cadenceHooks.tryRestoreFromKV(sessionId);
|
|
197
|
+
}
|
|
198
|
+
if (cadenceHooks.isActiveCadenceSession(sessionId)) {
|
|
199
|
+
await cadenceHooks.onEvent(input);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
// Non-Cadence sessions - handle session.compacted for checkpointing
|
|
203
|
+
await sessionMemoryHooks.onEvent(input);
|
|
204
|
+
}
|
|
196
205
|
}
|
|
197
206
|
},
|
|
198
207
|
'experimental.session.compacting': async (input, output) => {
|
|
208
|
+
// Try lazy restore from KV if not in memory (survives plugin restarts)
|
|
209
|
+
if (!cadenceHooks.isActiveCadenceSession(input.sessionID)) {
|
|
210
|
+
await cadenceHooks.tryRestoreFromKV(input.sessionID);
|
|
211
|
+
}
|
|
199
212
|
// Orchestrate: route to appropriate module based on session type
|
|
200
213
|
if (cadenceHooks.isActiveCadenceSession(input.sessionID)) {
|
|
201
214
|
await cadenceHooks.onCompacting(input, output);
|
|
@@ -265,6 +278,15 @@ function createConfigHandler(coderConfig) {
|
|
|
265
278
|
},
|
|
266
279
|
};
|
|
267
280
|
}
|
|
281
|
+
// Compaction config: increase reserved token buffer to accommodate our enriched
|
|
282
|
+
// compaction prompts (planning state, image descriptions, tool summaries, diagnostics).
|
|
283
|
+
// Default OpenCode reserved buffer is too small for the context we inject.
|
|
284
|
+
const existingCompaction = (config.compaction ?? {});
|
|
285
|
+
const existingReserved = existingCompaction.reserved;
|
|
286
|
+
config.compaction = {
|
|
287
|
+
...existingCompaction,
|
|
288
|
+
reserved: typeof existingReserved === 'number' ? existingReserved : 40_000,
|
|
289
|
+
};
|
|
268
290
|
config.command = {
|
|
269
291
|
...config.command,
|
|
270
292
|
...commands,
|