@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.
Files changed (74) hide show
  1. package/dist/agents/expert-backend.js +1 -1
  2. package/dist/agents/expert-backend.js.map +1 -1
  3. package/dist/agents/expert-frontend.js +1 -1
  4. package/dist/agents/expert-frontend.js.map +1 -1
  5. package/dist/agents/expert-ops.js +1 -1
  6. package/dist/agents/expert-ops.js.map +1 -1
  7. package/dist/agents/expert.js +1 -1
  8. package/dist/agents/expert.js.map +1 -1
  9. package/dist/agents/monitor.d.ts +1 -1
  10. package/dist/agents/monitor.d.ts.map +1 -1
  11. package/dist/agents/monitor.js +22 -33
  12. package/dist/agents/monitor.js.map +1 -1
  13. package/dist/agents/reviewer.js +1 -1
  14. package/dist/agents/reviewer.js.map +1 -1
  15. package/dist/agents/scout.js +1 -1
  16. package/dist/agents/scout.js.map +1 -1
  17. package/dist/background/manager.d.ts +1 -0
  18. package/dist/background/manager.d.ts.map +1 -1
  19. package/dist/background/manager.js +60 -26
  20. package/dist/background/manager.js.map +1 -1
  21. package/dist/plugin/hooks/cadence.d.ts +3 -1
  22. package/dist/plugin/hooks/cadence.d.ts.map +1 -1
  23. package/dist/plugin/hooks/cadence.js +167 -66
  24. package/dist/plugin/hooks/cadence.js.map +1 -1
  25. package/dist/plugin/hooks/compaction-utils.d.ts +48 -0
  26. package/dist/plugin/hooks/compaction-utils.d.ts.map +1 -0
  27. package/dist/plugin/hooks/compaction-utils.js +259 -0
  28. package/dist/plugin/hooks/compaction-utils.js.map +1 -0
  29. package/dist/plugin/hooks/params.d.ts +1 -1
  30. package/dist/plugin/hooks/params.d.ts.map +1 -1
  31. package/dist/plugin/hooks/params.js +5 -1
  32. package/dist/plugin/hooks/params.js.map +1 -1
  33. package/dist/plugin/hooks/session-memory.d.ts +2 -1
  34. package/dist/plugin/hooks/session-memory.d.ts.map +1 -1
  35. package/dist/plugin/hooks/session-memory.js +97 -48
  36. package/dist/plugin/hooks/session-memory.js.map +1 -1
  37. package/dist/plugin/plugin.d.ts.map +1 -1
  38. package/dist/plugin/plugin.js +31 -9
  39. package/dist/plugin/plugin.js.map +1 -1
  40. package/dist/sqlite/index.d.ts +1 -1
  41. package/dist/sqlite/index.d.ts.map +1 -1
  42. package/dist/sqlite/queries.d.ts +1 -0
  43. package/dist/sqlite/queries.d.ts.map +1 -1
  44. package/dist/sqlite/queries.js +4 -0
  45. package/dist/sqlite/queries.js.map +1 -1
  46. package/dist/sqlite/reader.d.ts +11 -1
  47. package/dist/sqlite/reader.d.ts.map +1 -1
  48. package/dist/sqlite/reader.js +62 -0
  49. package/dist/sqlite/reader.js.map +1 -1
  50. package/dist/sqlite/types.d.ts +40 -0
  51. package/dist/sqlite/types.d.ts.map +1 -1
  52. package/dist/types.d.ts +36 -0
  53. package/dist/types.d.ts.map +1 -1
  54. package/dist/types.js +10 -0
  55. package/dist/types.js.map +1 -1
  56. package/package.json +3 -3
  57. package/src/agents/expert-backend.ts +1 -1
  58. package/src/agents/expert-frontend.ts +1 -1
  59. package/src/agents/expert-ops.ts +1 -1
  60. package/src/agents/expert.ts +1 -1
  61. package/src/agents/monitor.ts +22 -33
  62. package/src/agents/reviewer.ts +1 -1
  63. package/src/agents/scout.ts +1 -1
  64. package/src/background/manager.ts +67 -31
  65. package/src/plugin/hooks/cadence.ts +184 -66
  66. package/src/plugin/hooks/compaction-utils.ts +291 -0
  67. package/src/plugin/hooks/params.ts +10 -1
  68. package/src/plugin/hooks/session-memory.ts +109 -47
  69. package/src/plugin/plugin.ts +47 -10
  70. package/src/sqlite/index.ts +4 -0
  71. package/src/sqlite/queries.ts +5 -0
  72. package/src/sqlite/reader.ts +69 -0
  73. package/src/sqlite/types.ts +40 -0
  74. package/src/types.ts +30 -0
@@ -5,10 +5,12 @@ import { join } from 'node:path';
5
5
  import { QUERIES } from './queries';
6
6
  import type {
7
7
  DBMessage,
8
+ DBNonTextPart,
8
9
  DBSession,
9
10
  DBTextPart,
10
11
  DBTodo,
11
12
  DBToolCall,
13
+ DBToolCallSummary,
12
14
  MessageTokens,
13
15
  OpenCodeDBConfig,
14
16
  SessionCostSummary,
@@ -226,6 +228,39 @@ function mapTextPart(row: PartRow): DBTextPart | null {
226
228
  };
227
229
  }
228
230
 
231
+ function mapNonTextPart(row: PartRow): DBNonTextPart | null {
232
+ const payload = safeParseJSON<PartData>(row.data);
233
+ if (!payload || !payload.type || payload.type === 'text') return null;
234
+
235
+ return {
236
+ id: row.id,
237
+ messageId: row.message_id,
238
+ type: payload.type,
239
+ toolName: payload.tool,
240
+ timestamp: new Date(row.time_created).toISOString(),
241
+ };
242
+ }
243
+
244
+ function mapToolCallSummary(row: PartRow): DBToolCallSummary | null {
245
+ const payload = safeParseJSON<PartData>(row.data);
246
+ if (!payload || (payload.type !== 'tool' && payload.type !== 'tool-invocation')) return null;
247
+
248
+ const state = payload.state ?? {};
249
+ const inputStr =
250
+ state.input !== undefined ? String(JSON.stringify(state.input)).slice(0, 200) : undefined;
251
+ const outputStr =
252
+ state.output !== undefined ? String(JSON.stringify(state.output)).slice(0, 200) : undefined;
253
+
254
+ return {
255
+ id: row.id,
256
+ messageId: row.message_id,
257
+ toolName: payload.tool ?? 'unknown',
258
+ input: inputStr,
259
+ output: outputStr,
260
+ timestamp: new Date(row.time_created).toISOString(),
261
+ };
262
+ }
263
+
229
264
  function isNotNull<T>(value: T | null): value is T {
230
265
  return value !== null;
231
266
  }
@@ -475,6 +510,40 @@ export class OpenCodeDBReader {
475
510
  }
476
511
  }
477
512
 
513
+ /**
514
+ * Get non-text parts (images, files, tool calls) for a session.
515
+ * Useful for describing attachments during compaction.
516
+ */
517
+ getNonTextParts(sessionId: string): DBNonTextPart[] {
518
+ if (!this.ensureOpen()) return [];
519
+
520
+ try {
521
+ const statement = this.getStatement('GET_NON_TEXT_PARTS');
522
+ const rows = statement?.all(sessionId, DEFAULT_LIMIT) as PartRow[] | null;
523
+ return rows ? rows.map(mapNonTextPart).filter(isNotNull) : [];
524
+ } catch (error) {
525
+ console.warn('[OpenCodeDBReader] Failed to get non-text parts', error);
526
+ return [];
527
+ }
528
+ }
529
+
530
+ /**
531
+ * Get recent tool calls for a session (newest first).
532
+ * Returns concise summaries for compaction context.
533
+ */
534
+ getRecentToolCalls(sessionId: string, limit: number = 5): DBToolCallSummary[] {
535
+ if (!this.ensureOpen()) return [];
536
+
537
+ try {
538
+ const statement = this.getStatement('GET_TOOL_HISTORY');
539
+ const rows = statement?.all(sessionId, limit) as PartRow[] | null;
540
+ return rows ? rows.map(mapToolCallSummary).filter(isNotNull) : [];
541
+ } catch (error) {
542
+ console.warn('[OpenCodeDBReader] Failed to get recent tool calls', error);
543
+ return [];
544
+ }
545
+ }
546
+
478
547
  getTodos(sessionId: string): DBTodo[] {
479
548
  if (!this.ensureOpen()) return [];
480
549
 
@@ -119,3 +119,43 @@ export interface OpenCodeDBConfig {
119
119
  dbPath?: string;
120
120
  enableSchemaValidation?: boolean;
121
121
  }
122
+
123
+ /** Non-text message part (image, file attachment, etc.) */
124
+ export interface DBNonTextPart {
125
+ id: string;
126
+ messageId: string;
127
+ type: string;
128
+ toolName?: string;
129
+ timestamp?: string;
130
+ }
131
+
132
+ /** Tool call summary for compaction context */
133
+ export interface DBToolCallSummary {
134
+ id: string;
135
+ messageId: string;
136
+ toolName: string;
137
+ input?: string;
138
+ output?: string;
139
+ timestamp: string;
140
+ }
141
+
142
+ /** Stats about what compaction preserved */
143
+ export interface CompactionStats {
144
+ planningPhasesCount: number;
145
+ backgroundTasksCount: number;
146
+ imageDescriptionsCount: number;
147
+ toolCallSummariesCount: number;
148
+ estimatedTokens: number;
149
+ }
150
+
151
+ /** Pre-compaction state snapshot stored to KV */
152
+ export interface PreCompactionSnapshot {
153
+ timestamp: string;
154
+ sessionId: string;
155
+ planningState?: Record<string, unknown>;
156
+ backgroundTasks?: Array<{ id: string; description: string; status: string }>;
157
+ imageDescriptions?: string[];
158
+ toolCallSummaries?: string[];
159
+ cadenceState?: Record<string, unknown>;
160
+ branch?: string;
161
+ }
package/src/types.ts CHANGED
@@ -151,6 +151,24 @@ export const AgentModelConfigSchema = z.object({
151
151
  maxSteps: z.number().optional(),
152
152
  });
153
153
 
154
+ /** Configuration for compaction behavior */
155
+ export interface CompactionConfig {
156
+ /** Use custom compaction prompt tailored to our agent system (default: true) */
157
+ customPrompt?: boolean;
158
+ /** Inline planning state from KV into compaction context (default: true) */
159
+ inlinePlanning?: boolean;
160
+ /** Detect and describe images/attachments (default: true) */
161
+ imageAwareness?: boolean;
162
+ /** Number of recent tool calls to summarize (default: 5, 0 to disable) */
163
+ toolCallSummaryLimit?: number;
164
+ /** Store pre-compaction snapshot to KV for recovery (default: true) */
165
+ snapshotToKV?: boolean;
166
+ /** Max tokens budget for ALL injected compaction context combined (default: 4000) */
167
+ maxContextTokens?: number;
168
+ /** Reserved token buffer for compaction prompts (default: 40000). Must not exceed OpenCode's max context window. */
169
+ reserved?: number;
170
+ }
171
+
154
172
  export interface CoderConfig {
155
173
  org?: string;
156
174
  disabledMcps?: string[];
@@ -159,6 +177,7 @@ export interface CoderConfig {
159
177
  background?: BackgroundTaskConfig;
160
178
  skills?: SkillsConfig;
161
179
  tmux?: TmuxConfig;
180
+ compaction?: CompactionConfig;
162
181
  }
163
182
 
164
183
  export const BackgroundTaskConfigSchema = z.object({
@@ -182,6 +201,16 @@ export const TmuxConfigSchema = z.object({
182
201
  agentPaneMinWidth: z.number(),
183
202
  });
184
203
 
204
+ export const CompactionConfigSchema = z.object({
205
+ customPrompt: z.boolean().optional(),
206
+ inlinePlanning: z.boolean().optional(),
207
+ imageAwareness: z.boolean().optional(),
208
+ toolCallSummaryLimit: z.number().optional(),
209
+ snapshotToKV: z.boolean().optional(),
210
+ maxContextTokens: z.number().optional(),
211
+ reserved: z.number().optional(),
212
+ });
213
+
185
214
  export const CoderConfigSchema = z.object({
186
215
  org: z.string().optional(),
187
216
  disabledMcps: z.array(z.string()).optional(),
@@ -189,6 +218,7 @@ export const CoderConfigSchema = z.object({
189
218
  background: BackgroundTaskConfigSchema.optional(),
190
219
  skills: SkillsConfigSchema.optional(),
191
220
  tmux: TmuxConfigSchema.optional(),
221
+ compaction: CompactionConfigSchema.optional(),
192
222
  });
193
223
 
194
224
  export interface McpConfig {