@tarquinen/opencode-dcp 0.3.15 → 0.3.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.
- package/README.md +39 -50
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -60
- package/dist/index.js.map +1 -1
- package/dist/lib/config.d.ts +1 -15
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +22 -95
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/deduplicator.d.ts +0 -30
- package/dist/lib/deduplicator.d.ts.map +1 -1
- package/dist/lib/deduplicator.js +1 -62
- package/dist/lib/deduplicator.js.map +1 -1
- package/dist/lib/janitor.d.ts +2 -61
- package/dist/lib/janitor.d.ts.map +1 -1
- package/dist/lib/janitor.js +67 -199
- package/dist/lib/janitor.js.map +1 -1
- package/dist/lib/logger.d.ts +0 -24
- package/dist/lib/logger.d.ts.map +1 -1
- package/dist/lib/logger.js +3 -58
- package/dist/lib/logger.js.map +1 -1
- package/dist/lib/model-selector.d.ts +0 -31
- package/dist/lib/model-selector.d.ts.map +1 -1
- package/dist/lib/model-selector.js +0 -55
- package/dist/lib/model-selector.js.map +1 -1
- package/dist/lib/prompt.d.ts.map +1 -1
- package/dist/lib/prompt.js +3 -29
- package/dist/lib/prompt.js.map +1 -1
- package/dist/lib/tokenizer.d.ts +0 -23
- package/dist/lib/tokenizer.d.ts.map +1 -1
- package/dist/lib/tokenizer.js +0 -25
- package/dist/lib/tokenizer.js.map +1 -1
- package/dist/lib/version-checker.d.ts +0 -15
- package/dist/lib/version-checker.d.ts.map +1 -1
- package/dist/lib/version-checker.js +1 -19
- package/dist/lib/version-checker.js.map +1 -1
- package/package.json +1 -1
package/dist/lib/config.js
CHANGED
|
@@ -1,39 +1,33 @@
|
|
|
1
|
-
// lib/config.ts
|
|
2
1
|
import { readFileSync, writeFileSync, existsSync, mkdirSync, statSync, copyFileSync } from 'fs';
|
|
3
2
|
import { join, dirname } from 'path';
|
|
4
3
|
import { homedir } from 'os';
|
|
5
4
|
import { parse } from 'jsonc-parser';
|
|
6
5
|
import { Logger } from './logger';
|
|
7
6
|
const defaultConfig = {
|
|
8
|
-
enabled: true,
|
|
9
|
-
debug: false,
|
|
10
|
-
protectedTools: ['task', 'todowrite', 'todoread', 'context_pruning'],
|
|
11
|
-
showModelErrorToasts: true,
|
|
12
|
-
|
|
7
|
+
enabled: true,
|
|
8
|
+
debug: false,
|
|
9
|
+
protectedTools: ['task', 'todowrite', 'todoread', 'context_pruning'],
|
|
10
|
+
showModelErrorToasts: true,
|
|
11
|
+
strictModelSelection: false,
|
|
12
|
+
pruning_summary: 'detailed',
|
|
13
13
|
strategies: {
|
|
14
|
-
// Default: Full analysis on idle (like previous "smart" mode)
|
|
15
14
|
onIdle: ['deduplication', 'ai-analysis'],
|
|
16
|
-
// Default: Only deduplication when AI calls the tool (faster, no extra LLM cost)
|
|
17
15
|
onTool: ['deduplication']
|
|
18
16
|
}
|
|
19
17
|
};
|
|
20
|
-
// Valid top-level keys in the current config schema
|
|
21
18
|
const VALID_CONFIG_KEYS = new Set([
|
|
22
19
|
'enabled',
|
|
23
20
|
'debug',
|
|
24
21
|
'protectedTools',
|
|
25
22
|
'model',
|
|
26
23
|
'showModelErrorToasts',
|
|
24
|
+
'strictModelSelection',
|
|
27
25
|
'pruning_summary',
|
|
28
26
|
'strategies'
|
|
29
27
|
]);
|
|
30
28
|
const GLOBAL_CONFIG_DIR = join(homedir(), '.config', 'opencode');
|
|
31
29
|
const GLOBAL_CONFIG_PATH_JSONC = join(GLOBAL_CONFIG_DIR, 'dcp.jsonc');
|
|
32
30
|
const GLOBAL_CONFIG_PATH_JSON = join(GLOBAL_CONFIG_DIR, 'dcp.json');
|
|
33
|
-
/**
|
|
34
|
-
* Searches for .opencode directory starting from current directory and going up
|
|
35
|
-
* Returns the path to .opencode directory if found, null otherwise
|
|
36
|
-
*/
|
|
37
31
|
function findOpencodeDir(startDir) {
|
|
38
32
|
let current = startDir;
|
|
39
33
|
while (current !== '/') {
|
|
@@ -43,17 +37,12 @@ function findOpencodeDir(startDir) {
|
|
|
43
37
|
}
|
|
44
38
|
const parent = dirname(current);
|
|
45
39
|
if (parent === current)
|
|
46
|
-
break;
|
|
40
|
+
break;
|
|
47
41
|
current = parent;
|
|
48
42
|
}
|
|
49
43
|
return null;
|
|
50
44
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Determines which config file to use (prefers .jsonc, falls back to .json)
|
|
53
|
-
* Checks both project-level and global configs
|
|
54
|
-
*/
|
|
55
45
|
function getConfigPaths(ctx) {
|
|
56
|
-
// Global config paths
|
|
57
46
|
let globalPath = null;
|
|
58
47
|
if (existsSync(GLOBAL_CONFIG_PATH_JSONC)) {
|
|
59
48
|
globalPath = GLOBAL_CONFIG_PATH_JSONC;
|
|
@@ -61,7 +50,6 @@ function getConfigPaths(ctx) {
|
|
|
61
50
|
else if (existsSync(GLOBAL_CONFIG_PATH_JSON)) {
|
|
62
51
|
globalPath = GLOBAL_CONFIG_PATH_JSON;
|
|
63
52
|
}
|
|
64
|
-
// Project config paths (if context provided)
|
|
65
53
|
let projectPath = null;
|
|
66
54
|
if (ctx?.directory) {
|
|
67
55
|
const opencodeDir = findOpencodeDir(ctx.directory);
|
|
@@ -78,63 +66,36 @@ function getConfigPaths(ctx) {
|
|
|
78
66
|
}
|
|
79
67
|
return { global: globalPath, project: projectPath };
|
|
80
68
|
}
|
|
81
|
-
/**
|
|
82
|
-
* Creates the default configuration file with helpful comments
|
|
83
|
-
*/
|
|
84
69
|
function createDefaultConfig() {
|
|
85
|
-
// Ensure the directory exists
|
|
86
70
|
if (!existsSync(GLOBAL_CONFIG_DIR)) {
|
|
87
71
|
mkdirSync(GLOBAL_CONFIG_DIR, { recursive: true });
|
|
88
72
|
}
|
|
89
73
|
const configContent = `{
|
|
90
|
-
// Enable or disable the
|
|
74
|
+
// Enable or disable the plugin
|
|
91
75
|
"enabled": true,
|
|
92
|
-
|
|
93
76
|
// Enable debug logging to ~/.config/opencode/logs/dcp/
|
|
94
|
-
// Outputs include:
|
|
95
|
-
// - daily/YYYY-MM-DD.log (plugin activity, decisions, errors)
|
|
96
|
-
// - ai-context/*.json (messages sent to AI after pruning)
|
|
97
77
|
"debug": false,
|
|
98
|
-
|
|
99
|
-
// Optional: Specify a model to use for analysis instead of the session model
|
|
100
|
-
// Format: "provider/model" (same as agent model config in opencode.jsonc)
|
|
101
|
-
// NOTE: Anthropic OAuth sonnet 4+ tier models are currently not supported
|
|
78
|
+
// Override model for analysis (format: "provider/model", e.g. "anthropic/claude-haiku-4-5")
|
|
102
79
|
// "model": "anthropic/claude-haiku-4-5",
|
|
103
|
-
|
|
104
|
-
// Show toast notifications when model selection fails and falls back
|
|
105
|
-
// Set to false to disable these informational toasts
|
|
80
|
+
// Show toast notifications when model selection fails
|
|
106
81
|
"showModelErrorToasts": true,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
//
|
|
110
|
-
// Empty array = disabled
|
|
82
|
+
// Only run AI analysis with session model or configured model (disables fallback models)
|
|
83
|
+
"strictModelSelection": false,
|
|
84
|
+
// Pruning strategies: "deduplication", "ai-analysis" (empty array = disabled)
|
|
111
85
|
"strategies": {
|
|
112
|
-
// Strategies to run when session goes idle
|
|
86
|
+
// Strategies to run when session goes idle
|
|
113
87
|
"onIdle": ["deduplication", "ai-analysis"],
|
|
114
|
-
|
|
115
|
-
// Strategies to run when AI calls the context_pruning tool
|
|
116
|
-
// Empty array = tool not exposed to AI
|
|
88
|
+
// Strategies to run when AI calls context_pruning tool
|
|
117
89
|
"onTool": ["deduplication"]
|
|
118
90
|
},
|
|
119
|
-
|
|
120
|
-
// Pruning summary display mode:
|
|
121
|
-
// "off": No UI summary (silent pruning)
|
|
122
|
-
// "minimal": Show tokens saved and count (e.g., "Saved ~2.5K tokens (6 tools pruned)")
|
|
123
|
-
// "detailed": Show full breakdown by tool type and pruning method (default)
|
|
91
|
+
// Summary display: "off", "minimal", or "detailed"
|
|
124
92
|
"pruning_summary": "detailed",
|
|
125
|
-
|
|
126
|
-
// List of tools that should never be pruned from context
|
|
127
|
-
// "task": Each subagent invocation is intentional
|
|
128
|
-
// "todowrite"/"todoread": Stateful tools where each call matters
|
|
129
|
-
// "context_pruning": The pruning tool itself
|
|
93
|
+
// Tools that should never be pruned
|
|
130
94
|
"protectedTools": ["task", "todowrite", "todoread", "context_pruning"]
|
|
131
95
|
}
|
|
132
96
|
`;
|
|
133
97
|
writeFileSync(GLOBAL_CONFIG_PATH_JSONC, configContent, 'utf-8');
|
|
134
98
|
}
|
|
135
|
-
/**
|
|
136
|
-
* Loads a single config file and parses it
|
|
137
|
-
*/
|
|
138
99
|
function loadConfigFile(configPath) {
|
|
139
100
|
try {
|
|
140
101
|
const fileContent = readFileSync(configPath, 'utf-8');
|
|
@@ -144,9 +105,6 @@ function loadConfigFile(configPath) {
|
|
|
144
105
|
return null;
|
|
145
106
|
}
|
|
146
107
|
}
|
|
147
|
-
/**
|
|
148
|
-
* Check if config has any unknown or deprecated keys
|
|
149
|
-
*/
|
|
150
108
|
function getInvalidKeys(config) {
|
|
151
109
|
const invalidKeys = [];
|
|
152
110
|
for (const key of Object.keys(config)) {
|
|
@@ -156,17 +114,11 @@ function getInvalidKeys(config) {
|
|
|
156
114
|
}
|
|
157
115
|
return invalidKeys;
|
|
158
116
|
}
|
|
159
|
-
/**
|
|
160
|
-
* Backs up existing config and creates fresh default config
|
|
161
|
-
* Returns the backup path if successful, null if failed
|
|
162
|
-
*/
|
|
163
117
|
function backupAndResetConfig(configPath, logger) {
|
|
164
118
|
try {
|
|
165
119
|
const backupPath = configPath + '.bak';
|
|
166
|
-
// Create backup
|
|
167
120
|
copyFileSync(configPath, backupPath);
|
|
168
121
|
logger.info('config', 'Created config backup', { backup: backupPath });
|
|
169
|
-
// Write fresh default config
|
|
170
122
|
createDefaultConfig();
|
|
171
123
|
logger.info('config', 'Created fresh default config', { path: GLOBAL_CONFIG_PATH_JSONC });
|
|
172
124
|
return backupPath;
|
|
@@ -176,9 +128,6 @@ function backupAndResetConfig(configPath, logger) {
|
|
|
176
128
|
return null;
|
|
177
129
|
}
|
|
178
130
|
}
|
|
179
|
-
/**
|
|
180
|
-
* Merge strategies config, handling partial overrides
|
|
181
|
-
*/
|
|
182
131
|
function mergeStrategies(base, override) {
|
|
183
132
|
if (!override)
|
|
184
133
|
return base;
|
|
@@ -187,49 +136,30 @@ function mergeStrategies(base, override) {
|
|
|
187
136
|
onTool: override.onTool ?? base.onTool
|
|
188
137
|
};
|
|
189
138
|
}
|
|
190
|
-
/**
|
|
191
|
-
* Loads configuration with support for both global and project-level configs
|
|
192
|
-
*
|
|
193
|
-
* Config resolution order:
|
|
194
|
-
* 1. Start with default config
|
|
195
|
-
* 2. Merge with global config (~/.config/opencode/dcp.jsonc)
|
|
196
|
-
* 3. Merge with project config (.opencode/dcp.jsonc) if found
|
|
197
|
-
*
|
|
198
|
-
* If config has invalid/deprecated keys, backs up and resets to defaults.
|
|
199
|
-
*
|
|
200
|
-
* Project config overrides global config, which overrides defaults.
|
|
201
|
-
*
|
|
202
|
-
* @param ctx - Plugin input context (optional). If provided, will search for project-level config.
|
|
203
|
-
* @returns ConfigResult with merged configuration and any migration messages
|
|
204
|
-
*/
|
|
205
139
|
export function getConfig(ctx) {
|
|
206
140
|
let config = { ...defaultConfig, protectedTools: [...defaultConfig.protectedTools] };
|
|
207
141
|
const configPaths = getConfigPaths(ctx);
|
|
208
|
-
const logger = new Logger(true);
|
|
142
|
+
const logger = new Logger(true);
|
|
209
143
|
const migrations = [];
|
|
210
|
-
// 1. Load global config
|
|
211
144
|
if (configPaths.global) {
|
|
212
145
|
const globalConfig = loadConfigFile(configPaths.global);
|
|
213
146
|
if (globalConfig) {
|
|
214
|
-
// Check for invalid keys
|
|
215
147
|
const invalidKeys = getInvalidKeys(globalConfig);
|
|
216
148
|
if (invalidKeys.length > 0) {
|
|
217
|
-
// Config has deprecated/unknown keys - backup and reset
|
|
218
149
|
logger.info('config', 'Found invalid config keys', { keys: invalidKeys });
|
|
219
150
|
const backupPath = backupAndResetConfig(configPaths.global, logger);
|
|
220
151
|
if (backupPath) {
|
|
221
152
|
migrations.push(`Old config backed up to ${backupPath}`);
|
|
222
153
|
}
|
|
223
|
-
// Config is now reset to defaults, no need to merge
|
|
224
154
|
}
|
|
225
155
|
else {
|
|
226
|
-
// Valid config - merge with defaults
|
|
227
156
|
config = {
|
|
228
157
|
enabled: globalConfig.enabled ?? config.enabled,
|
|
229
158
|
debug: globalConfig.debug ?? config.debug,
|
|
230
159
|
protectedTools: globalConfig.protectedTools ?? config.protectedTools,
|
|
231
160
|
model: globalConfig.model ?? config.model,
|
|
232
161
|
showModelErrorToasts: globalConfig.showModelErrorToasts ?? config.showModelErrorToasts,
|
|
162
|
+
strictModelSelection: globalConfig.strictModelSelection ?? config.strictModelSelection,
|
|
233
163
|
strategies: mergeStrategies(config.strategies, globalConfig.strategies),
|
|
234
164
|
pruning_summary: globalConfig.pruning_summary ?? config.pruning_summary
|
|
235
165
|
};
|
|
@@ -238,31 +168,28 @@ export function getConfig(ctx) {
|
|
|
238
168
|
}
|
|
239
169
|
}
|
|
240
170
|
else {
|
|
241
|
-
// Create default global config if it doesn't exist
|
|
242
171
|
createDefaultConfig();
|
|
243
172
|
logger.info('config', 'Created default global config', { path: GLOBAL_CONFIG_PATH_JSONC });
|
|
244
173
|
}
|
|
245
|
-
// 2. Load project config (overrides global)
|
|
246
174
|
if (configPaths.project) {
|
|
247
175
|
const projectConfig = loadConfigFile(configPaths.project);
|
|
248
176
|
if (projectConfig) {
|
|
249
|
-
// Check for invalid keys
|
|
250
177
|
const invalidKeys = getInvalidKeys(projectConfig);
|
|
251
178
|
if (invalidKeys.length > 0) {
|
|
252
|
-
// Project config has deprecated/unknown keys - just warn, don't reset project configs
|
|
253
179
|
logger.warn('config', 'Project config has invalid keys (ignored)', {
|
|
254
180
|
path: configPaths.project,
|
|
255
181
|
keys: invalidKeys
|
|
256
182
|
});
|
|
183
|
+
migrations.push(`Project config has invalid keys: ${invalidKeys.join(', ')}`);
|
|
257
184
|
}
|
|
258
185
|
else {
|
|
259
|
-
// Valid config - merge with current config
|
|
260
186
|
config = {
|
|
261
187
|
enabled: projectConfig.enabled ?? config.enabled,
|
|
262
188
|
debug: projectConfig.debug ?? config.debug,
|
|
263
189
|
protectedTools: projectConfig.protectedTools ?? config.protectedTools,
|
|
264
190
|
model: projectConfig.model ?? config.model,
|
|
265
191
|
showModelErrorToasts: projectConfig.showModelErrorToasts ?? config.showModelErrorToasts,
|
|
192
|
+
strictModelSelection: projectConfig.strictModelSelection ?? config.strictModelSelection,
|
|
266
193
|
strategies: mergeStrategies(config.strategies, projectConfig.strategies),
|
|
267
194
|
pruning_summary: projectConfig.pruning_summary ?? config.pruning_summary
|
|
268
195
|
};
|
package/dist/lib/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../lib/config.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../lib/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,IAAI,CAAA;AAC/F,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAwBjC,MAAM,aAAa,GAAiB;IAChC,OAAO,EAAE,IAAI;IACb,KAAK,EAAE,KAAK;IACZ,cAAc,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,iBAAiB,CAAC;IACpE,oBAAoB,EAAE,IAAI;IAC1B,oBAAoB,EAAE,KAAK;IAC3B,eAAe,EAAE,UAAU;IA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EAAE,aAAa,CAAC,oBAAoB,IAAI,MAAM,CAAC,oBAAoB;oBACvF,UAAU,EAAE,eAAe,CAAC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,UAAiB,CAAC;oBAC/E,eAAe,EAAE,aAAa,CAAC,eAAe,IAAI,MAAM,CAAC,eAAe;iBAC3E,CAAA;gBACD,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,0CAA0C,EAAE,EAAE,IAAI,EAAE,WAAW,CAAC,OAAO,EAAE,CAAC,CAAA;YACpG,CAAC;QACL,CAAC;IACL,CAAC;SAAM,IAAI,GAAG,EAAE,SAAS,EAAE,CAAC;QACxB,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,yBAAyB,EAAE,EAAE,YAAY,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,CAAA;IACtF,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAA;AACjC,CAAC"}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Deduplicator Module
|
|
3
|
-
*
|
|
4
|
-
* Handles automatic detection and removal of duplicate tool calls based on
|
|
5
|
-
* tool name + parameter signature matching.
|
|
6
|
-
*/
|
|
7
1
|
export interface DuplicateDetectionResult {
|
|
8
2
|
duplicateIds: string[];
|
|
9
3
|
deduplicationDetails: Map<string, {
|
|
@@ -14,35 +8,11 @@ export interface DuplicateDetectionResult {
|
|
|
14
8
|
keptId: string;
|
|
15
9
|
}>;
|
|
16
10
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Detects duplicate tool calls based on tool name + parameter signature
|
|
19
|
-
* Keeps only the most recent occurrence of each duplicate set
|
|
20
|
-
* Respects protected tools - they are never deduplicated
|
|
21
|
-
*/
|
|
22
11
|
export declare function detectDuplicates(toolMetadata: Map<string, {
|
|
23
12
|
tool: string;
|
|
24
13
|
parameters?: any;
|
|
25
14
|
}>, unprunedToolCallIds: string[], // In chronological order
|
|
26
15
|
protectedTools: string[]): DuplicateDetectionResult;
|
|
27
|
-
/**
|
|
28
|
-
* Extract human-readable parameter key for notifications
|
|
29
|
-
* Supports all ACTIVE OpenCode tools with appropriate parameter extraction
|
|
30
|
-
*
|
|
31
|
-
* ACTIVE Tools (always available):
|
|
32
|
-
* - File: read, write, edit
|
|
33
|
-
* - Search: list, glob, grep
|
|
34
|
-
* - Execution: bash
|
|
35
|
-
* - Agent: task
|
|
36
|
-
* - Web: webfetch
|
|
37
|
-
* - Todo: todowrite, todoread
|
|
38
|
-
*
|
|
39
|
-
* CONDITIONAL Tools (may be disabled):
|
|
40
|
-
* - batch (experimental.batch_tool flag)
|
|
41
|
-
* - websearch, codesearch (OPENCODE_EXPERIMENTAL_EXA flag)
|
|
42
|
-
*
|
|
43
|
-
* INACTIVE Tools (exist but not registered, skip):
|
|
44
|
-
* - multiedit, patch, lsp_diagnostics, lsp_hover
|
|
45
|
-
*/
|
|
46
16
|
export declare function extractParameterKey(metadata: {
|
|
47
17
|
tool: string;
|
|
48
18
|
parameters?: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deduplicator.d.ts","sourceRoot":"","sources":["../../lib/deduplicator.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"deduplicator.d.ts","sourceRoot":"","sources":["../../lib/deduplicator.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB;IACrC,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE;QAC9B,QAAQ,EAAE,MAAM,CAAA;QAChB,YAAY,EAAE,MAAM,CAAA;QACpB,cAAc,EAAE,MAAM,CAAA;QACtB,SAAS,EAAE,MAAM,EAAE,CAAA;QACnB,MAAM,EAAE,MAAM,CAAA;KACjB,CAAC,CAAA;CACL;AAED,wBAAgB,gBAAgB,CAC5B,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,GAAG,CAAA;CAAE,CAAC,EAC7D,mBAAmB,EAAE,MAAM,EAAE,EAAG,yBAAyB;AACzD,cAAc,EAAE,MAAM,EAAE,GACzB,wBAAwB,CAuC1B;AAkCD,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,GAAG,CAAA;CAAE,GAAG,MAAM,CAuExF"}
|
package/dist/lib/deduplicator.js
CHANGED
|
@@ -1,23 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Deduplicator Module
|
|
3
|
-
*
|
|
4
|
-
* Handles automatic detection and removal of duplicate tool calls based on
|
|
5
|
-
* tool name + parameter signature matching.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Detects duplicate tool calls based on tool name + parameter signature
|
|
9
|
-
* Keeps only the most recent occurrence of each duplicate set
|
|
10
|
-
* Respects protected tools - they are never deduplicated
|
|
11
|
-
*/
|
|
12
1
|
export function detectDuplicates(toolMetadata, unprunedToolCallIds, // In chronological order
|
|
13
2
|
protectedTools) {
|
|
14
3
|
const signatureMap = new Map();
|
|
15
|
-
// Filter out protected tools before processing
|
|
16
4
|
const deduplicatableIds = unprunedToolCallIds.filter(id => {
|
|
17
5
|
const metadata = toolMetadata.get(id);
|
|
18
6
|
return !metadata || !protectedTools.includes(metadata.tool);
|
|
19
7
|
});
|
|
20
|
-
// Build map of signature -> [ids in chronological order]
|
|
21
8
|
for (const id of deduplicatableIds) {
|
|
22
9
|
const metadata = toolMetadata.get(id);
|
|
23
10
|
if (!metadata)
|
|
@@ -28,7 +15,6 @@ protectedTools) {
|
|
|
28
15
|
}
|
|
29
16
|
signatureMap.get(signature).push(id);
|
|
30
17
|
}
|
|
31
|
-
// Identify duplicates (keep only last occurrence)
|
|
32
18
|
const duplicateIds = [];
|
|
33
19
|
const deduplicationDetails = new Map();
|
|
34
20
|
for (const [signature, ids] of signatureMap.entries()) {
|
|
@@ -47,24 +33,13 @@ protectedTools) {
|
|
|
47
33
|
}
|
|
48
34
|
return { duplicateIds, deduplicationDetails };
|
|
49
35
|
}
|
|
50
|
-
/**
|
|
51
|
-
* Creates a deterministic signature for a tool call
|
|
52
|
-
* Format: "toolName::JSON(sortedParameters)"
|
|
53
|
-
*/
|
|
54
36
|
function createToolSignature(tool, parameters) {
|
|
55
37
|
if (!parameters)
|
|
56
38
|
return tool;
|
|
57
|
-
// Normalize parameters for consistent comparison
|
|
58
39
|
const normalized = normalizeParameters(parameters);
|
|
59
40
|
const sorted = sortObjectKeys(normalized);
|
|
60
41
|
return `${tool}::${JSON.stringify(sorted)}`;
|
|
61
42
|
}
|
|
62
|
-
/**
|
|
63
|
-
* Normalize parameters to handle edge cases:
|
|
64
|
-
* - Remove undefined/null values
|
|
65
|
-
* - Resolve relative paths to absolute (future enhancement)
|
|
66
|
-
* - Sort arrays if order doesn't matter (future enhancement)
|
|
67
|
-
*/
|
|
68
43
|
function normalizeParameters(params) {
|
|
69
44
|
if (typeof params !== 'object' || params === null)
|
|
70
45
|
return params;
|
|
@@ -78,9 +53,6 @@ function normalizeParameters(params) {
|
|
|
78
53
|
}
|
|
79
54
|
return normalized;
|
|
80
55
|
}
|
|
81
|
-
/**
|
|
82
|
-
* Recursively sort object keys for deterministic comparison
|
|
83
|
-
*/
|
|
84
56
|
function sortObjectKeys(obj) {
|
|
85
57
|
if (typeof obj !== 'object' || obj === null)
|
|
86
58
|
return obj;
|
|
@@ -92,30 +64,10 @@ function sortObjectKeys(obj) {
|
|
|
92
64
|
}
|
|
93
65
|
return sorted;
|
|
94
66
|
}
|
|
95
|
-
/**
|
|
96
|
-
* Extract human-readable parameter key for notifications
|
|
97
|
-
* Supports all ACTIVE OpenCode tools with appropriate parameter extraction
|
|
98
|
-
*
|
|
99
|
-
* ACTIVE Tools (always available):
|
|
100
|
-
* - File: read, write, edit
|
|
101
|
-
* - Search: list, glob, grep
|
|
102
|
-
* - Execution: bash
|
|
103
|
-
* - Agent: task
|
|
104
|
-
* - Web: webfetch
|
|
105
|
-
* - Todo: todowrite, todoread
|
|
106
|
-
*
|
|
107
|
-
* CONDITIONAL Tools (may be disabled):
|
|
108
|
-
* - batch (experimental.batch_tool flag)
|
|
109
|
-
* - websearch, codesearch (OPENCODE_EXPERIMENTAL_EXA flag)
|
|
110
|
-
*
|
|
111
|
-
* INACTIVE Tools (exist but not registered, skip):
|
|
112
|
-
* - multiedit, patch, lsp_diagnostics, lsp_hover
|
|
113
|
-
*/
|
|
114
67
|
export function extractParameterKey(metadata) {
|
|
115
68
|
if (!metadata.parameters)
|
|
116
69
|
return '';
|
|
117
70
|
const { tool, parameters } = metadata;
|
|
118
|
-
// ===== File Operation Tools =====
|
|
119
71
|
if (tool === "read" && parameters.filePath) {
|
|
120
72
|
return parameters.filePath;
|
|
121
73
|
}
|
|
@@ -125,13 +77,10 @@ export function extractParameterKey(metadata) {
|
|
|
125
77
|
if (tool === "edit" && parameters.filePath) {
|
|
126
78
|
return parameters.filePath;
|
|
127
79
|
}
|
|
128
|
-
// ===== Directory/Search Tools =====
|
|
129
80
|
if (tool === "list") {
|
|
130
|
-
// path is optional, defaults to current directory
|
|
131
81
|
return parameters.path || '(current directory)';
|
|
132
82
|
}
|
|
133
83
|
if (tool === "glob") {
|
|
134
|
-
// pattern is required for glob
|
|
135
84
|
if (parameters.pattern) {
|
|
136
85
|
const pathInfo = parameters.path ? ` in ${parameters.path}` : "";
|
|
137
86
|
return `"${parameters.pattern}"${pathInfo}`;
|
|
@@ -145,7 +94,6 @@ export function extractParameterKey(metadata) {
|
|
|
145
94
|
}
|
|
146
95
|
return '(unknown pattern)';
|
|
147
96
|
}
|
|
148
|
-
// ===== Execution Tools =====
|
|
149
97
|
if (tool === "bash") {
|
|
150
98
|
if (parameters.description)
|
|
151
99
|
return parameters.description;
|
|
@@ -155,7 +103,6 @@ export function extractParameterKey(metadata) {
|
|
|
155
103
|
: parameters.command;
|
|
156
104
|
}
|
|
157
105
|
}
|
|
158
|
-
// ===== Web Tools =====
|
|
159
106
|
if (tool === "webfetch" && parameters.url) {
|
|
160
107
|
return parameters.url;
|
|
161
108
|
}
|
|
@@ -165,29 +112,21 @@ export function extractParameterKey(metadata) {
|
|
|
165
112
|
if (tool === "codesearch" && parameters.query) {
|
|
166
113
|
return `"${parameters.query}"`;
|
|
167
114
|
}
|
|
168
|
-
// ===== Todo Tools =====
|
|
169
|
-
// Note: Todo tools are stateful and in protectedTools by default
|
|
170
115
|
if (tool === "todowrite") {
|
|
171
116
|
return `${parameters.todos?.length || 0} todos`;
|
|
172
117
|
}
|
|
173
118
|
if (tool === "todoread") {
|
|
174
119
|
return "read todo list";
|
|
175
120
|
}
|
|
176
|
-
// ===== Agent/Task Tools =====
|
|
177
|
-
// Note: task is in protectedTools by default
|
|
178
121
|
if (tool === "task" && parameters.description) {
|
|
179
122
|
return parameters.description;
|
|
180
123
|
}
|
|
181
|
-
// Note: batch is experimental and needs special handling
|
|
182
124
|
if (tool === "batch") {
|
|
183
125
|
return `${parameters.tool_calls?.length || 0} parallel tools`;
|
|
184
126
|
}
|
|
185
|
-
// ===== Fallback =====
|
|
186
|
-
// For unknown tools, custom tools, or tools without extractable keys
|
|
187
|
-
// Check if parameters is empty or only has empty values
|
|
188
127
|
const paramStr = JSON.stringify(parameters);
|
|
189
128
|
if (paramStr === '{}' || paramStr === '[]' || paramStr === 'null') {
|
|
190
|
-
return '';
|
|
129
|
+
return '';
|
|
191
130
|
}
|
|
192
131
|
return paramStr.substring(0, 50);
|
|
193
132
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deduplicator.js","sourceRoot":"","sources":["../../lib/deduplicator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deduplicator.js","sourceRoot":"","sources":["../../lib/deduplicator.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,gBAAgB,CAC5B,YAA6D,EAC7D,mBAA6B,EAAG,yBAAyB;AACzD,cAAwB;IAExB,MAAM,YAAY,GA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GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC,QAAQ,CAAA;IACnD,CAAC;IACD,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;QACtB,OAAO,gBAAgB,CAAA;IAC3B,CAAC;IAED,IAAI,IAAI,KAAK,MAAM,IAAI,UAAU,CAAC,WAAW,EAAE,CAAC;QAC5C,OAAO,UAAU,CAAC,WAAW,CAAA;IACjC,CAAC;IACD,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACnB,OAAO,GAAG,UAAU,CAAC,UAAU,EAAE,MAAM,IAAI,CAAC,iBAAiB,CAAA;IACjE,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;IAC3C,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;QAChE,OAAO,EAAE,CAAA;IACb,CAAC;IACD,OAAO,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;AACpC,CAAC"}
|
package/dist/lib/janitor.d.ts
CHANGED
|
@@ -30,87 +30,28 @@ export declare class Janitor {
|
|
|
30
30
|
private modelCache;
|
|
31
31
|
private configModel?;
|
|
32
32
|
private showModelErrorToasts;
|
|
33
|
+
private strictModelSelection;
|
|
33
34
|
private pruningSummary;
|
|
34
35
|
private workingDirectory?;
|
|
35
36
|
constructor(client: any, prunedIdsState: Map<string, string[]>, statsState: Map<string, SessionStats>, logger: Logger, toolParametersCache: Map<string, any>, protectedTools: string[], modelCache: Map<string, {
|
|
36
37
|
providerID: string;
|
|
37
38
|
modelID: string;
|
|
38
|
-
}>, configModel?: string | undefined,
|
|
39
|
-
showModelErrorToasts?: boolean, // Whether to show toast for model errors
|
|
40
|
-
pruningSummary?: "off" | "minimal" | "detailed", // UI summary display mode
|
|
41
|
-
workingDirectory?: string | undefined);
|
|
42
|
-
/**
|
|
43
|
-
* Sends an ignored message to the session UI (user sees it, AI doesn't)
|
|
44
|
-
*/
|
|
39
|
+
}>, configModel?: string | undefined, showModelErrorToasts?: boolean, strictModelSelection?: boolean, pruningSummary?: "off" | "minimal" | "detailed", workingDirectory?: string | undefined);
|
|
45
40
|
private sendIgnoredMessage;
|
|
46
|
-
/**
|
|
47
|
-
* Convenience method for idle-triggered pruning (sends notification automatically)
|
|
48
|
-
*/
|
|
49
41
|
runOnIdle(sessionID: string, strategies: PruningStrategy[]): Promise<void>;
|
|
50
|
-
/**
|
|
51
|
-
* Convenience method for tool-triggered pruning (returns result for tool output)
|
|
52
|
-
*/
|
|
53
42
|
runForTool(sessionID: string, strategies: PruningStrategy[], reason?: string): Promise<PruningResult | null>;
|
|
54
|
-
/**
|
|
55
|
-
* Core pruning method that accepts strategies and options
|
|
56
|
-
*/
|
|
57
43
|
runWithStrategies(sessionID: string, strategies: PruningStrategy[], options: PruningOptions): Promise<PruningResult | null>;
|
|
58
|
-
/**
|
|
59
|
-
* Helper function to shorten paths for display
|
|
60
|
-
*/
|
|
61
44
|
private shortenPath;
|
|
62
|
-
/**
|
|
63
|
-
* Shorten a single path string
|
|
64
|
-
*/
|
|
65
45
|
private shortenSinglePath;
|
|
66
|
-
/**
|
|
67
|
-
* Replace pruned tool outputs with placeholder text to save tokens in janitor context
|
|
68
|
-
* This applies the same replacement logic as the global fetch wrapper, but for the
|
|
69
|
-
* janitor's shadow inference to avoid sending already-pruned content to the LLM
|
|
70
|
-
*/
|
|
71
46
|
private replacePrunedToolOutputs;
|
|
72
|
-
/**
|
|
73
|
-
* Helper function to calculate token savings from tool outputs
|
|
74
|
-
*/
|
|
75
47
|
private calculateTokensSaved;
|
|
76
|
-
/**
|
|
77
|
-
* Build a summary of tools by grouping them
|
|
78
|
-
* Uses shared extractParameterKey logic for consistent parameter extraction
|
|
79
|
-
*
|
|
80
|
-
* Note: prunedIds may be in original case (from LLM) but toolMetadata uses lowercase keys
|
|
81
|
-
*/
|
|
82
48
|
private buildToolsSummary;
|
|
83
|
-
/**
|
|
84
|
-
* Group deduplication details by tool type
|
|
85
|
-
* Shared helper used by notifications and tool output formatting
|
|
86
|
-
*/
|
|
87
49
|
private groupDeduplicationDetails;
|
|
88
|
-
/**
|
|
89
|
-
* Format grouped deduplication results as lines
|
|
90
|
-
* Shared helper for building deduplication summaries
|
|
91
|
-
*/
|
|
92
50
|
private formatDeduplicationLines;
|
|
93
|
-
/**
|
|
94
|
-
* Format tool summary (from buildToolsSummary) as lines
|
|
95
|
-
* Shared helper for building LLM-pruned summaries
|
|
96
|
-
*/
|
|
97
51
|
private formatToolSummaryLines;
|
|
98
|
-
/**
|
|
99
|
-
* Send minimal summary notification (just tokens saved and count)
|
|
100
|
-
*/
|
|
101
52
|
private sendMinimalNotification;
|
|
102
|
-
/**
|
|
103
|
-
* Auto mode notification - shows only deduplication results
|
|
104
|
-
*/
|
|
105
53
|
private sendAutoModeNotification;
|
|
106
|
-
/**
|
|
107
|
-
* Format pruning result for tool output (returned to AI)
|
|
108
|
-
* Uses shared helpers for consistency with UI notifications
|
|
109
|
-
*/
|
|
110
54
|
formatPruningResultForTool(result: PruningResult): string;
|
|
111
|
-
/**
|
|
112
|
-
* Smart mode notification - shows both deduplication and LLM analysis results
|
|
113
|
-
*/
|
|
114
55
|
private sendSmartModeNotification;
|
|
115
56
|
}
|
|
116
57
|
//# sourceMappingURL=janitor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"janitor.d.ts","sourceRoot":"","sources":["../../lib/janitor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAM/C,MAAM,WAAW,YAAY;IACzB,gBAAgB,EAAE,MAAM,CAAA;IACxB,gBAAgB,EAAE,MAAM,CAAA;CAC3B;AAED,MAAM,WAAW,aAAa;IAC1B,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAA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