@agentuity/opencode 1.0.15 → 1.0.17

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 (137) hide show
  1. package/dist/agents/architect.d.ts +1 -1
  2. package/dist/agents/architect.d.ts.map +1 -1
  3. package/dist/agents/architect.js +30 -33
  4. package/dist/agents/architect.js.map +1 -1
  5. package/dist/agents/builder.d.ts +1 -1
  6. package/dist/agents/builder.d.ts.map +1 -1
  7. package/dist/agents/builder.js +53 -60
  8. package/dist/agents/builder.js.map +1 -1
  9. package/dist/agents/expert-backend.d.ts +1 -1
  10. package/dist/agents/expert-backend.d.ts.map +1 -1
  11. package/dist/agents/expert-backend.js +32 -40
  12. package/dist/agents/expert-backend.js.map +1 -1
  13. package/dist/agents/expert-frontend.d.ts +1 -1
  14. package/dist/agents/expert-frontend.d.ts.map +1 -1
  15. package/dist/agents/expert-frontend.js +18 -24
  16. package/dist/agents/expert-frontend.js.map +1 -1
  17. package/dist/agents/expert-ops.d.ts +1 -1
  18. package/dist/agents/expert-ops.d.ts.map +1 -1
  19. package/dist/agents/expert-ops.js +37 -51
  20. package/dist/agents/expert-ops.js.map +1 -1
  21. package/dist/agents/expert.d.ts +1 -1
  22. package/dist/agents/expert.d.ts.map +1 -1
  23. package/dist/agents/expert.js +33 -43
  24. package/dist/agents/expert.js.map +1 -1
  25. package/dist/agents/lead.d.ts +1 -1
  26. package/dist/agents/lead.d.ts.map +1 -1
  27. package/dist/agents/lead.js +179 -222
  28. package/dist/agents/lead.js.map +1 -1
  29. package/dist/agents/memory.d.ts +1 -1
  30. package/dist/agents/memory.d.ts.map +1 -1
  31. package/dist/agents/memory.js +62 -90
  32. package/dist/agents/memory.js.map +1 -1
  33. package/dist/agents/monitor.d.ts +1 -1
  34. package/dist/agents/monitor.d.ts.map +1 -1
  35. package/dist/agents/monitor.js +84 -44
  36. package/dist/agents/monitor.js.map +1 -1
  37. package/dist/agents/product.d.ts +1 -1
  38. package/dist/agents/product.d.ts.map +1 -1
  39. package/dist/agents/product.js +16 -22
  40. package/dist/agents/product.js.map +1 -1
  41. package/dist/agents/reviewer.d.ts +1 -1
  42. package/dist/agents/reviewer.d.ts.map +1 -1
  43. package/dist/agents/reviewer.js +15 -27
  44. package/dist/agents/reviewer.js.map +1 -1
  45. package/dist/agents/runner.d.ts +1 -1
  46. package/dist/agents/runner.d.ts.map +1 -1
  47. package/dist/agents/runner.js +52 -76
  48. package/dist/agents/runner.js.map +1 -1
  49. package/dist/agents/scout.d.ts +1 -1
  50. package/dist/agents/scout.d.ts.map +1 -1
  51. package/dist/agents/scout.js +42 -43
  52. package/dist/agents/scout.js.map +1 -1
  53. package/dist/agents/types.d.ts +8 -0
  54. package/dist/agents/types.d.ts.map +1 -1
  55. package/dist/background/manager.d.ts +18 -0
  56. package/dist/background/manager.d.ts.map +1 -1
  57. package/dist/background/manager.js +201 -33
  58. package/dist/background/manager.js.map +1 -1
  59. package/dist/background/types.d.ts +3 -0
  60. package/dist/background/types.d.ts.map +1 -1
  61. package/dist/config/loader.js +2 -2
  62. package/dist/plugin/hooks/cadence.d.ts +3 -1
  63. package/dist/plugin/hooks/cadence.d.ts.map +1 -1
  64. package/dist/plugin/hooks/cadence.js +167 -70
  65. package/dist/plugin/hooks/cadence.js.map +1 -1
  66. package/dist/plugin/hooks/compaction-utils.d.ts +48 -0
  67. package/dist/plugin/hooks/compaction-utils.d.ts.map +1 -0
  68. package/dist/plugin/hooks/compaction-utils.js +259 -0
  69. package/dist/plugin/hooks/compaction-utils.js.map +1 -0
  70. package/dist/plugin/hooks/completion.d.ts +14 -0
  71. package/dist/plugin/hooks/completion.d.ts.map +1 -0
  72. package/dist/plugin/hooks/completion.js +45 -0
  73. package/dist/plugin/hooks/completion.js.map +1 -0
  74. package/dist/plugin/hooks/params.d.ts +47 -2
  75. package/dist/plugin/hooks/params.d.ts.map +1 -1
  76. package/dist/plugin/hooks/params.js +82 -1
  77. package/dist/plugin/hooks/params.js.map +1 -1
  78. package/dist/plugin/hooks/session-memory.d.ts +2 -1
  79. package/dist/plugin/hooks/session-memory.d.ts.map +1 -1
  80. package/dist/plugin/hooks/session-memory.js +101 -48
  81. package/dist/plugin/hooks/session-memory.js.map +1 -1
  82. package/dist/plugin/hooks/tools.d.ts.map +1 -1
  83. package/dist/plugin/hooks/tools.js +26 -1
  84. package/dist/plugin/hooks/tools.js.map +1 -1
  85. package/dist/plugin/plugin.d.ts.map +1 -1
  86. package/dist/plugin/plugin.js +38 -9
  87. package/dist/plugin/plugin.js.map +1 -1
  88. package/dist/sqlite/index.d.ts +1 -1
  89. package/dist/sqlite/index.d.ts.map +1 -1
  90. package/dist/sqlite/queries.d.ts +1 -0
  91. package/dist/sqlite/queries.d.ts.map +1 -1
  92. package/dist/sqlite/queries.js +4 -0
  93. package/dist/sqlite/queries.js.map +1 -1
  94. package/dist/sqlite/reader.d.ts +11 -1
  95. package/dist/sqlite/reader.d.ts.map +1 -1
  96. package/dist/sqlite/reader.js +62 -0
  97. package/dist/sqlite/reader.js.map +1 -1
  98. package/dist/sqlite/types.d.ts +40 -0
  99. package/dist/sqlite/types.d.ts.map +1 -1
  100. package/dist/tools/background.d.ts.map +1 -1
  101. package/dist/tools/background.js +15 -0
  102. package/dist/tools/background.js.map +1 -1
  103. package/dist/types.d.ts +46 -0
  104. package/dist/types.d.ts.map +1 -1
  105. package/dist/types.js +10 -0
  106. package/dist/types.js.map +1 -1
  107. package/package.json +3 -3
  108. package/src/agents/architect.ts +30 -33
  109. package/src/agents/builder.ts +53 -60
  110. package/src/agents/expert-backend.ts +32 -40
  111. package/src/agents/expert-frontend.ts +18 -24
  112. package/src/agents/expert-ops.ts +37 -51
  113. package/src/agents/expert.ts +33 -43
  114. package/src/agents/lead.ts +179 -222
  115. package/src/agents/memory.ts +62 -90
  116. package/src/agents/monitor.ts +84 -44
  117. package/src/agents/product.ts +16 -22
  118. package/src/agents/reviewer.ts +15 -27
  119. package/src/agents/runner.ts +52 -76
  120. package/src/agents/scout.ts +42 -43
  121. package/src/agents/types.ts +8 -0
  122. package/src/background/manager.ts +227 -38
  123. package/src/background/types.ts +3 -0
  124. package/src/config/loader.ts +2 -2
  125. package/src/plugin/hooks/cadence.ts +188 -74
  126. package/src/plugin/hooks/compaction-utils.ts +291 -0
  127. package/src/plugin/hooks/completion.ts +61 -0
  128. package/src/plugin/hooks/params.ts +107 -2
  129. package/src/plugin/hooks/session-memory.ts +113 -47
  130. package/src/plugin/hooks/tools.ts +32 -1
  131. package/src/plugin/plugin.ts +54 -10
  132. package/src/sqlite/index.ts +4 -0
  133. package/src/sqlite/queries.ts +5 -0
  134. package/src/sqlite/reader.ts +69 -0
  135. package/src/sqlite/types.ts +40 -0
  136. package/src/tools/background.ts +28 -0
  137. package/src/types.ts +40 -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
+ }
@@ -105,6 +105,12 @@ export function createBackgroundTools(manager: BackgroundManager): {
105
105
  status: string;
106
106
  result?: string;
107
107
  error?: string;
108
+ progress?: {
109
+ toolCalls: number;
110
+ lastTool?: string;
111
+ lastToolSec: number;
112
+ activeTools: number;
113
+ };
108
114
  }> {
109
115
  const task = manager.getTask(args.task_id);
110
116
  if (!task) {
@@ -114,12 +120,34 @@ export function createBackgroundTools(manager: BackgroundManager): {
114
120
  error: 'Task not found.',
115
121
  };
116
122
  }
123
+
124
+ // Include compact progress snapshot only for active tasks.
125
+ // Three numbers + optional tool name — minimal context cost.
126
+ // lastToolSec: seconds since the last tool call event was received.
127
+ // 0 = active right now; >300 with activeTools=0 = genuinely stuck.
128
+ let progress:
129
+ | { toolCalls: number; lastTool?: string; lastToolSec: number; activeTools: number }
130
+ | undefined;
131
+
132
+ if ((task.status === 'running' || task.status === 'pending') && task.progress) {
133
+ const lastToolSec = Math.floor(
134
+ (Date.now() - task.progress.lastUpdate.getTime()) / 1000
135
+ );
136
+ progress = {
137
+ toolCalls: task.progress.toolCalls,
138
+ lastTool: task.progress.lastTool,
139
+ lastToolSec,
140
+ activeTools: task.progress.activeToolCallsInFlight,
141
+ };
142
+ }
143
+
117
144
  return {
118
145
  taskId: task.id,
119
146
  sessionId: task.sessionId,
120
147
  status: task.status,
121
148
  result: task.result,
122
149
  error: task.error,
150
+ progress,
123
151
  };
124
152
  },
125
153
  };
package/src/types.ts CHANGED
@@ -89,6 +89,16 @@ export interface AgentConfig {
89
89
  reasoningEffort?: ReasoningEffort;
90
90
  /** Extended thinking configuration for Anthropic models */
91
91
  thinking?: ThinkingConfig;
92
+ /**
93
+ * Ordered list of fallback model IDs to try when the primary model fails
94
+ * with a retryable error (429 rate limit, 500/502/503 server error).
95
+ * Models are tried in order until one succeeds.
96
+ *
97
+ * Example: ['anthropic/claude-sonnet-4-20250514', 'openai/gpt-4.1']
98
+ */
99
+ fallbackModels?: string[];
100
+ /** Hidden from @ autocomplete */
101
+ hidden?: boolean;
92
102
  }
93
103
 
94
104
  export interface AgentContext {
@@ -151,6 +161,24 @@ export const AgentModelConfigSchema = z.object({
151
161
  maxSteps: z.number().optional(),
152
162
  });
153
163
 
164
+ /** Configuration for compaction behavior */
165
+ export interface CompactionConfig {
166
+ /** Use custom compaction prompt tailored to our agent system (default: true) */
167
+ customPrompt?: boolean;
168
+ /** Inline planning state from KV into compaction context (default: true) */
169
+ inlinePlanning?: boolean;
170
+ /** Detect and describe images/attachments (default: true) */
171
+ imageAwareness?: boolean;
172
+ /** Number of recent tool calls to summarize (default: 5, 0 to disable) */
173
+ toolCallSummaryLimit?: number;
174
+ /** Store pre-compaction snapshot to KV for recovery (default: true) */
175
+ snapshotToKV?: boolean;
176
+ /** Max tokens budget for ALL injected compaction context combined (default: 4000) */
177
+ maxContextTokens?: number;
178
+ /** Reserved token buffer for compaction prompts (default: 40000). Must not exceed OpenCode's max context window. */
179
+ reserved?: number;
180
+ }
181
+
154
182
  export interface CoderConfig {
155
183
  org?: string;
156
184
  disabledMcps?: string[];
@@ -159,6 +187,7 @@ export interface CoderConfig {
159
187
  background?: BackgroundTaskConfig;
160
188
  skills?: SkillsConfig;
161
189
  tmux?: TmuxConfig;
190
+ compaction?: CompactionConfig;
162
191
  }
163
192
 
164
193
  export const BackgroundTaskConfigSchema = z.object({
@@ -182,6 +211,16 @@ export const TmuxConfigSchema = z.object({
182
211
  agentPaneMinWidth: z.number(),
183
212
  });
184
213
 
214
+ export const CompactionConfigSchema = z.object({
215
+ customPrompt: z.boolean().optional(),
216
+ inlinePlanning: z.boolean().optional(),
217
+ imageAwareness: z.boolean().optional(),
218
+ toolCallSummaryLimit: z.number().optional(),
219
+ snapshotToKV: z.boolean().optional(),
220
+ maxContextTokens: z.number().optional(),
221
+ reserved: z.number().optional(),
222
+ });
223
+
185
224
  export const CoderConfigSchema = z.object({
186
225
  org: z.string().optional(),
187
226
  disabledMcps: z.array(z.string()).optional(),
@@ -189,6 +228,7 @@ export const CoderConfigSchema = z.object({
189
228
  background: BackgroundTaskConfigSchema.optional(),
190
229
  skills: SkillsConfigSchema.optional(),
191
230
  tmux: TmuxConfigSchema.optional(),
231
+ compaction: CompactionConfigSchema.optional(),
192
232
  });
193
233
 
194
234
  export interface McpConfig {