@tuanhung303/opencode-acp 0.0.1
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/LICENSE +21 -0
- package/README.md +166 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +79 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/commands/budget.d.ts +15 -0
- package/dist/lib/commands/budget.d.ts.map +1 -0
- package/dist/lib/commands/budget.js +120 -0
- package/dist/lib/commands/budget.js.map +1 -0
- package/dist/lib/commands/context.d.ts +49 -0
- package/dist/lib/commands/context.d.ts.map +1 -0
- package/dist/lib/commands/context.js +191 -0
- package/dist/lib/commands/context.js.map +1 -0
- package/dist/lib/commands/help.d.ts +15 -0
- package/dist/lib/commands/help.d.ts.map +1 -0
- package/dist/lib/commands/help.js +28 -0
- package/dist/lib/commands/help.js.map +1 -0
- package/dist/lib/commands/protected.d.ts +17 -0
- package/dist/lib/commands/protected.d.ts.map +1 -0
- package/dist/lib/commands/protected.js +50 -0
- package/dist/lib/commands/protected.js.map +1 -0
- package/dist/lib/commands/stats.d.ts +15 -0
- package/dist/lib/commands/stats.d.ts.map +1 -0
- package/dist/lib/commands/stats.js +64 -0
- package/dist/lib/commands/stats.js.map +1 -0
- package/dist/lib/commands/sweep.d.ts +23 -0
- package/dist/lib/commands/sweep.d.ts.map +1 -0
- package/dist/lib/commands/sweep.js +194 -0
- package/dist/lib/commands/sweep.js.map +1 -0
- package/dist/lib/config-schema.d.ts +119 -0
- package/dist/lib/config-schema.d.ts.map +1 -0
- package/dist/lib/config-schema.js +97 -0
- package/dist/lib/config-schema.js.map +1 -0
- package/dist/lib/config.d.ts +59 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +426 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/hooks.d.ts +31 -0
- package/dist/lib/hooks.d.ts.map +1 -0
- package/dist/lib/hooks.js +230 -0
- package/dist/lib/hooks.js.map +1 -0
- package/dist/lib/logger.d.ts +55 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +230 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/messages/index.d.ts +3 -0
- package/dist/lib/messages/index.d.ts.map +1 -0
- package/dist/lib/messages/index.js +3 -0
- package/dist/lib/messages/index.js.map +1 -0
- package/dist/lib/messages/inject.d.ts +10 -0
- package/dist/lib/messages/inject.d.ts.map +1 -0
- package/dist/lib/messages/inject.js +10 -0
- package/dist/lib/messages/inject.js.map +1 -0
- package/dist/lib/messages/prune.d.ts +13 -0
- package/dist/lib/messages/prune.d.ts.map +1 -0
- package/dist/lib/messages/prune.js +173 -0
- package/dist/lib/messages/prune.js.map +1 -0
- package/dist/lib/messages/utils.d.ts +43 -0
- package/dist/lib/messages/utils.d.ts.map +1 -0
- package/dist/lib/messages/utils.js +262 -0
- package/dist/lib/messages/utils.js.map +1 -0
- package/dist/lib/prompts/discard-tool-spec.d.ts +2 -0
- package/dist/lib/prompts/discard-tool-spec.d.ts.map +1 -0
- package/dist/lib/prompts/discard-tool-spec.js +54 -0
- package/dist/lib/prompts/discard-tool-spec.js.map +1 -0
- package/dist/lib/prompts/extract-tool-spec.d.ts +2 -0
- package/dist/lib/prompts/extract-tool-spec.d.ts.map +1 -0
- package/dist/lib/prompts/extract-tool-spec.js +56 -0
- package/dist/lib/prompts/extract-tool-spec.js.map +1 -0
- package/dist/lib/prompts/index.d.ts +2 -0
- package/dist/lib/prompts/index.d.ts.map +1 -0
- package/dist/lib/prompts/index.js +29 -0
- package/dist/lib/prompts/index.js.map +1 -0
- package/dist/lib/prompts/restore-tool-spec.d.ts +2 -0
- package/dist/lib/prompts/restore-tool-spec.d.ts.map +1 -0
- package/dist/lib/prompts/restore-tool-spec.js +37 -0
- package/dist/lib/prompts/restore-tool-spec.js.map +1 -0
- package/dist/lib/prompts/system/both.d.ts +2 -0
- package/dist/lib/prompts/system/both.d.ts.map +1 -0
- package/dist/lib/prompts/system/both.js +65 -0
- package/dist/lib/prompts/system/both.js.map +1 -0
- package/dist/lib/prompts/system/discard.d.ts +2 -0
- package/dist/lib/prompts/system/discard.d.ts.map +1 -0
- package/dist/lib/prompts/system/discard.js +55 -0
- package/dist/lib/prompts/system/discard.js.map +1 -0
- package/dist/lib/prompts/system/extract.d.ts +2 -0
- package/dist/lib/prompts/system/extract.d.ts.map +1 -0
- package/dist/lib/prompts/system/extract.js +55 -0
- package/dist/lib/prompts/system/extract.js.map +1 -0
- package/dist/lib/protected-file-patterns.d.ts +12 -0
- package/dist/lib/protected-file-patterns.d.ts.map +1 -0
- package/dist/lib/protected-file-patterns.js +69 -0
- package/dist/lib/protected-file-patterns.js.map +1 -0
- package/dist/lib/safe-execute.d.ts +20 -0
- package/dist/lib/safe-execute.d.ts.map +1 -0
- package/dist/lib/safe-execute.js +38 -0
- package/dist/lib/safe-execute.js.map +1 -0
- package/dist/lib/shared-utils.d.ts +4 -0
- package/dist/lib/shared-utils.d.ts.map +1 -0
- package/dist/lib/shared-utils.js +14 -0
- package/dist/lib/shared-utils.js.map +1 -0
- package/dist/lib/state/index.d.ts +4 -0
- package/dist/lib/state/index.d.ts.map +1 -0
- package/dist/lib/state/index.js +4 -0
- package/dist/lib/state/index.js.map +1 -0
- package/dist/lib/state/persistence.d.ts +27 -0
- package/dist/lib/state/persistence.d.ts.map +1 -0
- package/dist/lib/state/persistence.js +165 -0
- package/dist/lib/state/persistence.js.map +1 -0
- package/dist/lib/state/state.d.ts +8 -0
- package/dist/lib/state/state.d.ts.map +1 -0
- package/dist/lib/state/state.js +166 -0
- package/dist/lib/state/state.js.map +1 -0
- package/dist/lib/state/tool-cache.d.ts +15 -0
- package/dist/lib/state/tool-cache.d.ts.map +1 -0
- package/dist/lib/state/tool-cache.js +99 -0
- package/dist/lib/state/tool-cache.js.map +1 -0
- package/dist/lib/state/types.d.ts +83 -0
- package/dist/lib/state/types.d.ts.map +1 -0
- package/dist/lib/state/types.js +2 -0
- package/dist/lib/state/types.js.map +1 -0
- package/dist/lib/state/utils.d.ts +2 -0
- package/dist/lib/state/utils.d.ts.map +1 -0
- package/dist/lib/state/utils.js +10 -0
- package/dist/lib/state/utils.js.map +1 -0
- package/dist/lib/strategies/deduplication.d.ts +11 -0
- package/dist/lib/strategies/deduplication.d.ts.map +1 -0
- package/dist/lib/strategies/deduplication.js +178 -0
- package/dist/lib/strategies/deduplication.js.map +1 -0
- package/dist/lib/strategies/index.d.ts +5 -0
- package/dist/lib/strategies/index.d.ts.map +1 -0
- package/dist/lib/strategies/index.js +5 -0
- package/dist/lib/strategies/index.js.map +1 -0
- package/dist/lib/strategies/purge-errors.d.ts +13 -0
- package/dist/lib/strategies/purge-errors.d.ts.map +1 -0
- package/dist/lib/strategies/purge-errors.js +62 -0
- package/dist/lib/strategies/purge-errors.js.map +1 -0
- package/dist/lib/strategies/supersede-writes.d.ts +13 -0
- package/dist/lib/strategies/supersede-writes.d.ts.map +1 -0
- package/dist/lib/strategies/supersede-writes.js +90 -0
- package/dist/lib/strategies/supersede-writes.js.map +1 -0
- package/dist/lib/strategies/tools.d.ts +15 -0
- package/dist/lib/strategies/tools.d.ts.map +1 -0
- package/dist/lib/strategies/tools.js +288 -0
- package/dist/lib/strategies/tools.js.map +1 -0
- package/dist/lib/strategies/utils.d.ts +11 -0
- package/dist/lib/strategies/utils.d.ts.map +1 -0
- package/dist/lib/strategies/utils.js +75 -0
- package/dist/lib/strategies/utils.js.map +1 -0
- package/dist/lib/ui/notification.d.ts +12 -0
- package/dist/lib/ui/notification.d.ts.map +1 -0
- package/dist/lib/ui/notification.js +81 -0
- package/dist/lib/ui/notification.js.map +1 -0
- package/dist/lib/ui/utils.d.ts +10 -0
- package/dist/lib/ui/utils.d.ts.map +1 -0
- package/dist/lib/ui/utils.js +113 -0
- package/dist/lib/ui/utils.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { tool } from "@opencode-ai/plugin";
|
|
2
|
+
import { sendUnifiedNotification } from "../ui/notification";
|
|
3
|
+
import { formatPruningResultForTool } from "../ui/utils";
|
|
4
|
+
import { ensureSessionInitialized } from "../state";
|
|
5
|
+
import { saveSessionState } from "../state/persistence";
|
|
6
|
+
import { loadPrompt } from "../prompts";
|
|
7
|
+
import { calculateTokensSaved, getCurrentParams } from "./utils";
|
|
8
|
+
import { getFilePathFromParameters, isProtectedFilePath } from "../protected-file-patterns";
|
|
9
|
+
const DISCARD_TOOL_DESCRIPTION = loadPrompt("discard-tool-spec");
|
|
10
|
+
const EXTRACT_TOOL_DESCRIPTION = loadPrompt("extract-tool-spec");
|
|
11
|
+
const RESTORE_TOOL_DESCRIPTION = loadPrompt("restore-tool-spec");
|
|
12
|
+
/**
|
|
13
|
+
* Execute a prune operation using call IDs directly.
|
|
14
|
+
* This is the hash-based version that works with resolved call IDs.
|
|
15
|
+
*/
|
|
16
|
+
async function executePruneOperationByCallIds(ctx, toolCtx, callIds, hashes, reason, toolName, distillation) {
|
|
17
|
+
const { client, state, logger, config, workingDirectory } = ctx;
|
|
18
|
+
const sessionId = toolCtx.sessionID;
|
|
19
|
+
logger.info(`${toolName} tool invoked`);
|
|
20
|
+
logger.info(JSON.stringify({ hashes, reason }));
|
|
21
|
+
if (!callIds || callIds.length === 0) {
|
|
22
|
+
logger.debug(`${toolName} tool called but no valid call IDs resolved`);
|
|
23
|
+
throw new Error(`No valid hashes provided. Use hashes from tool outputs (e.g., #r_a1b2c#).`);
|
|
24
|
+
}
|
|
25
|
+
// Fetch messages to calculate tokens
|
|
26
|
+
const messagesResponse = await client.session.messages({
|
|
27
|
+
path: { id: sessionId },
|
|
28
|
+
});
|
|
29
|
+
const messages = messagesResponse.data || messagesResponse;
|
|
30
|
+
await ensureSessionInitialized(ctx.client, state, sessionId, logger, messages);
|
|
31
|
+
const currentParams = getCurrentParams(state, messages, logger);
|
|
32
|
+
// Validate that all call IDs exist in cache and aren't protected
|
|
33
|
+
for (const callId of callIds) {
|
|
34
|
+
const metadata = state.toolParameters.get(callId);
|
|
35
|
+
if (!metadata) {
|
|
36
|
+
const hash = state.callIdToHash.get(callId) || "unknown";
|
|
37
|
+
logger.debug("Rejecting prune request - call ID not in cache", { callId, hash });
|
|
38
|
+
throw new Error(`Invalid hash provided. The tool may have already been discarded.`);
|
|
39
|
+
}
|
|
40
|
+
const allProtectedTools = config.tools.settings.protectedTools;
|
|
41
|
+
if (allProtectedTools.includes(metadata.tool)) {
|
|
42
|
+
const hash = state.callIdToHash.get(callId) || "unknown";
|
|
43
|
+
logger.debug("Rejecting prune request - protected tool", {
|
|
44
|
+
callId,
|
|
45
|
+
hash,
|
|
46
|
+
tool: metadata.tool,
|
|
47
|
+
});
|
|
48
|
+
throw new Error(`Cannot discard: '${metadata.tool}' is a protected tool.\n` +
|
|
49
|
+
`Protected tools: ${allProtectedTools.join(", ")}\n` +
|
|
50
|
+
`To modify protection, update 'tools.settings.protectedTools' in your ACP config.`);
|
|
51
|
+
}
|
|
52
|
+
const filePath = getFilePathFromParameters(metadata.parameters);
|
|
53
|
+
if (isProtectedFilePath(filePath, config.protectedFilePatterns)) {
|
|
54
|
+
const hash = state.callIdToHash.get(callId) || "unknown";
|
|
55
|
+
logger.debug("Rejecting prune request - protected file path", {
|
|
56
|
+
callId,
|
|
57
|
+
hash,
|
|
58
|
+
tool: metadata.tool,
|
|
59
|
+
filePath,
|
|
60
|
+
});
|
|
61
|
+
const protectedPatterns = config.protectedFilePatterns.length > 0
|
|
62
|
+
? `\nProtected patterns: ${config.protectedFilePatterns.join(", ")}`
|
|
63
|
+
: "";
|
|
64
|
+
throw new Error(`Cannot discard: ${filePath} is a protected file path.${protectedPatterns}\n` +
|
|
65
|
+
`To modify protection, update 'protectedFilePatterns' in your ACP config.`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Add to prune list
|
|
69
|
+
state.prune.toolIds.push(...callIds);
|
|
70
|
+
// Collect metadata for notification
|
|
71
|
+
const toolMetadata = new Map();
|
|
72
|
+
for (const callId of callIds) {
|
|
73
|
+
const toolParameters = state.toolParameters.get(callId);
|
|
74
|
+
if (toolParameters) {
|
|
75
|
+
toolMetadata.set(callId, toolParameters);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
logger.debug("No metadata found for call ID", { callId });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Calculate token savings
|
|
82
|
+
const tokensSaved = calculateTokensSaved(state, messages, callIds);
|
|
83
|
+
state.stats.pruneTokenCounter += tokensSaved;
|
|
84
|
+
state.stats.pruneMessageCounter += callIds.length;
|
|
85
|
+
// Track strategy effectiveness
|
|
86
|
+
if (toolName === "Discard") {
|
|
87
|
+
state.stats.strategyStats.manualDiscard.count += callIds.length;
|
|
88
|
+
state.stats.strategyStats.manualDiscard.tokens += tokensSaved;
|
|
89
|
+
}
|
|
90
|
+
else if (toolName === "Extract") {
|
|
91
|
+
state.stats.strategyStats.extraction.count += callIds.length;
|
|
92
|
+
state.stats.strategyStats.extraction.tokens += tokensSaved;
|
|
93
|
+
}
|
|
94
|
+
// Store stats for display
|
|
95
|
+
state.lastDiscardStats = {
|
|
96
|
+
itemCount: callIds.length,
|
|
97
|
+
tokensSaved: state.stats.pruneTokenCounter,
|
|
98
|
+
};
|
|
99
|
+
// Record in discard history
|
|
100
|
+
state.discardHistory.push({
|
|
101
|
+
timestamp: Date.now(),
|
|
102
|
+
hashes,
|
|
103
|
+
tokensSaved,
|
|
104
|
+
reason,
|
|
105
|
+
});
|
|
106
|
+
await sendUnifiedNotification(client, logger, config, state, sessionId, callIds, toolMetadata, reason, currentParams, workingDirectory, distillation);
|
|
107
|
+
state.stats.totalPruneTokens += state.stats.pruneTokenCounter;
|
|
108
|
+
state.stats.pruneTokenCounter = 0;
|
|
109
|
+
state.stats.totalPruneMessages += state.stats.pruneMessageCounter;
|
|
110
|
+
state.stats.pruneMessageCounter = 0;
|
|
111
|
+
saveSessionState(state, logger).catch((err) => logger.error("Failed to persist state", { error: err.message }));
|
|
112
|
+
return formatPruningResultForTool(callIds, toolMetadata, workingDirectory);
|
|
113
|
+
}
|
|
114
|
+
export function createDiscardTool(ctx) {
|
|
115
|
+
return tool({
|
|
116
|
+
description: DISCARD_TOOL_DESCRIPTION,
|
|
117
|
+
args: {
|
|
118
|
+
reason: tool.schema
|
|
119
|
+
.string()
|
|
120
|
+
.describe("Why you're discarding: 'noise' | 'completion' | 'superseded' | 'exploration' | 'duplicate'"),
|
|
121
|
+
hashes: tool.schema
|
|
122
|
+
.array(tool.schema.string())
|
|
123
|
+
.describe("Hash identifiers from tool outputs (e.g., ['#r_a1b2c#', '#g_d4e5f#'])"),
|
|
124
|
+
},
|
|
125
|
+
async execute(args, toolCtx) {
|
|
126
|
+
const { state, logger } = ctx;
|
|
127
|
+
// Validate reason
|
|
128
|
+
const validReasons = [
|
|
129
|
+
"completion",
|
|
130
|
+
"noise",
|
|
131
|
+
"superseded",
|
|
132
|
+
"exploration",
|
|
133
|
+
"duplicate",
|
|
134
|
+
];
|
|
135
|
+
if (!args.reason || !validReasons.includes(args.reason)) {
|
|
136
|
+
logger.debug("Invalid discard reason provided: " + args.reason);
|
|
137
|
+
throw new Error(`Invalid reason '${args.reason}'. Use one of: ${validReasons.join(", ")}`);
|
|
138
|
+
}
|
|
139
|
+
// Validate hashes provided
|
|
140
|
+
if (!args.hashes || args.hashes.length === 0) {
|
|
141
|
+
throw new Error("No hashes provided. Use hash identifiers from tool outputs (e.g., #r_a1b2c#).");
|
|
142
|
+
}
|
|
143
|
+
// Resolve hashes to call IDs
|
|
144
|
+
const callIds = [];
|
|
145
|
+
const validHashes = [];
|
|
146
|
+
const unknownHashes = [];
|
|
147
|
+
for (const hash of args.hashes) {
|
|
148
|
+
const callId = state.hashToCallId.get(hash);
|
|
149
|
+
if (callId) {
|
|
150
|
+
// Skip if already pruned
|
|
151
|
+
if (!state.prune.toolIds.includes(callId)) {
|
|
152
|
+
callIds.push(callId);
|
|
153
|
+
validHashes.push(hash);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
logger.debug(`Hash ${hash} already pruned, skipping`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
unknownHashes.push(hash);
|
|
161
|
+
logger.warn(`Unknown hash: ${hash}`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (unknownHashes.length > 0 && callIds.length === 0) {
|
|
165
|
+
throw new Error(`Unknown hashes: ${unknownHashes.join(", ")}. Use hash identifiers from tool outputs.`);
|
|
166
|
+
}
|
|
167
|
+
if (callIds.length === 0) {
|
|
168
|
+
throw new Error("No valid hashes to discard. Tools may have already been discarded.");
|
|
169
|
+
}
|
|
170
|
+
logger.info(`Discard: ${validHashes.length} hashes resolved to ${callIds.length} call IDs`);
|
|
171
|
+
return executePruneOperationByCallIds(ctx, toolCtx, callIds, validHashes, args.reason, "Discard");
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
export function createExtractTool(ctx) {
|
|
176
|
+
return tool({
|
|
177
|
+
description: EXTRACT_TOOL_DESCRIPTION,
|
|
178
|
+
args: {
|
|
179
|
+
hashes: tool.schema
|
|
180
|
+
.array(tool.schema.string())
|
|
181
|
+
.describe("Hash identifiers from tool outputs (e.g., ['#r_a1b2c#', '#g_d4e5f#'])"),
|
|
182
|
+
distillation: tool.schema
|
|
183
|
+
.array(tool.schema.string())
|
|
184
|
+
.describe("REQUIRED. Array of strings, one per hash (positional: distillation[0] is for hashes[0], etc.)"),
|
|
185
|
+
preserve: tool.schema
|
|
186
|
+
.boolean()
|
|
187
|
+
.optional()
|
|
188
|
+
.describe("Set to true to keep original tool output after extraction. Default: false"),
|
|
189
|
+
},
|
|
190
|
+
async execute(args, toolCtx) {
|
|
191
|
+
const { state, logger } = ctx;
|
|
192
|
+
if (!args.distillation || args.distillation.length === 0) {
|
|
193
|
+
logger.debug("Extract tool called without distillation: " + JSON.stringify(args));
|
|
194
|
+
throw new Error("Missing distillation. You must provide a distillation string for each hash.");
|
|
195
|
+
}
|
|
196
|
+
if (!args.hashes || args.hashes.length === 0) {
|
|
197
|
+
throw new Error("No hashes provided. Use hash identifiers from tool outputs (e.g., #r_a1b2c#).");
|
|
198
|
+
}
|
|
199
|
+
// Resolve hashes to call IDs
|
|
200
|
+
const callIds = [];
|
|
201
|
+
const validHashes = [];
|
|
202
|
+
for (const hash of args.hashes) {
|
|
203
|
+
const callId = state.hashToCallId.get(hash);
|
|
204
|
+
if (callId && !state.prune.toolIds.includes(callId)) {
|
|
205
|
+
callIds.push(callId);
|
|
206
|
+
validHashes.push(hash);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
logger.warn(`Unknown or already pruned hash: ${hash}`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (callIds.length === 0) {
|
|
213
|
+
throw new Error("No valid hashes to extract. Tools may have already been discarded.");
|
|
214
|
+
}
|
|
215
|
+
// Log the distillation for debugging/analysis
|
|
216
|
+
logger.info("Distillation data received:");
|
|
217
|
+
logger.info(JSON.stringify(args.distillation, null, 2));
|
|
218
|
+
// If preserve is true, don't prune - just return success with distillation
|
|
219
|
+
if (args.preserve) {
|
|
220
|
+
logger.info(`Extract with preserve=true - not pruning ${callIds.length} tools`);
|
|
221
|
+
return `Extracted knowledge from ${callIds.length} tool(s). Original outputs preserved.\n\nDistilled knowledge:\n${args.distillation.map((d, i) => `${i + 1}. ${d}`).join("\n")}`;
|
|
222
|
+
}
|
|
223
|
+
return executePruneOperationByCallIds(ctx, toolCtx, callIds, validHashes, "extraction", "Extract", args.distillation);
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
export function createRestoreTool(ctx) {
|
|
228
|
+
return tool({
|
|
229
|
+
description: RESTORE_TOOL_DESCRIPTION,
|
|
230
|
+
args: {
|
|
231
|
+
hashes: tool.schema
|
|
232
|
+
.array(tool.schema.string())
|
|
233
|
+
.describe("Hash identifiers of pruned tools to restore (e.g., ['#r_a1b2c#', '#g_d4e5f#'])"),
|
|
234
|
+
},
|
|
235
|
+
async execute(args, toolCtx) {
|
|
236
|
+
const { state, logger } = ctx;
|
|
237
|
+
const sessionId = toolCtx.sessionID;
|
|
238
|
+
if (!args.hashes || args.hashes.length === 0) {
|
|
239
|
+
throw new Error("No hashes provided. Use hash identifiers from pruned tool outputs (e.g., #r_a1b2c#).");
|
|
240
|
+
}
|
|
241
|
+
// Resolve hashes to call IDs and restore
|
|
242
|
+
const restored = [];
|
|
243
|
+
const notFound = [];
|
|
244
|
+
const notPruned = [];
|
|
245
|
+
for (const hash of args.hashes) {
|
|
246
|
+
const callId = state.hashToCallId.get(hash);
|
|
247
|
+
if (!callId) {
|
|
248
|
+
notFound.push(hash);
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
// Check if it's in the prune list
|
|
252
|
+
const pruneIndex = state.prune.toolIds.indexOf(callId);
|
|
253
|
+
if (pruneIndex === -1) {
|
|
254
|
+
notPruned.push(hash);
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
// Remove from prune list (restore)
|
|
258
|
+
state.prune.toolIds.splice(pruneIndex, 1);
|
|
259
|
+
restored.push(hash);
|
|
260
|
+
logger.info(`Restored tool with hash ${hash} (callId: ${callId})`);
|
|
261
|
+
}
|
|
262
|
+
// Build result message
|
|
263
|
+
const lines = [];
|
|
264
|
+
if (restored.length > 0) {
|
|
265
|
+
lines.push(`Restored ${restored.length} tool(s):`);
|
|
266
|
+
for (const hash of restored) {
|
|
267
|
+
lines.push(` โ ${hash}`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (notFound.length > 0) {
|
|
271
|
+
lines.push(`\nNot found (unknown hash):`);
|
|
272
|
+
for (const hash of notFound) {
|
|
273
|
+
lines.push(` โ ${hash}`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (notPruned.length > 0) {
|
|
277
|
+
lines.push(`\nNot pruned (already active):`);
|
|
278
|
+
for (const hash of notPruned) {
|
|
279
|
+
lines.push(` โ ${hash}`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
// Save state
|
|
283
|
+
saveSessionState(state, logger).catch((err) => logger.error("Failed to persist state", { error: err.message }));
|
|
284
|
+
return lines.join("\n");
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../lib/strategies/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAG1C,OAAO,EAAe,uBAAuB,EAAE,MAAM,oBAAoB,CAAA;AACzE,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAChE,OAAO,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAE3F,MAAM,wBAAwB,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAA;AAChE,MAAM,wBAAwB,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAA;AAChE,MAAM,wBAAwB,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAA;AAUhE;;;GAGG;AACH,KAAK,UAAU,8BAA8B,CACzC,GAAqB,EACrB,OAA8B,EAC9B,OAAiB,EACjB,MAAgB,EAChB,MAAmB,EACnB,QAAgB,EAChB,YAAuB;IAEvB,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,GAAG,CAAA;IAC/D,MAAM,SAAS,GAAG,OAAO,C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C;YACL,CAAC;YACD,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACtB,KAAK,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAA;gBACzC,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;oBAC1B,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAA;gBAC7B,CAAC;YACL,CAAC;YACD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACvB,KAAK,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAA;gBAC5C,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;oBAC3B,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAA;gBAC7B,CAAC;YACL,CAAC;YAED,aAAa;YACb,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAC1C,MAAM,CAAC,KAAK,CAAC,yBAAyB,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAClE,CAAA;YAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC3B,CAAC;KACJ,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SessionState, WithParts } from "../state";
|
|
2
|
+
import { Logger } from "../logger";
|
|
3
|
+
export declare function getCurrentParams(state: SessionState, messages: WithParts[], logger: Logger): {
|
|
4
|
+
providerId: string | undefined;
|
|
5
|
+
modelId: string | undefined;
|
|
6
|
+
agent: string | undefined;
|
|
7
|
+
variant: string | undefined;
|
|
8
|
+
};
|
|
9
|
+
export declare function countTokens(text: string): number;
|
|
10
|
+
export declare const calculateTokensSaved: (state: SessionState, messages: WithParts[], pruneToolIds: string[]) => number;
|
|
11
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../lib/strategies/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAIlC,wBAAgB,gBAAgB,CAC5B,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,SAAS,EAAE,EACrB,MAAM,EAAE,MAAM,GACf;IACC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;CAC9B,CAkBA;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOhD;AAMD,eAAO,MAAM,oBAAoB,GAC7B,OAAO,YAAY,EACnB,UAAU,SAAS,EAAE,EACrB,cAAc,MAAM,EAAE,KACvB,MAyCF,CAAA"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { countTokens as anthropicCountTokens } from "@anthropic-ai/tokenizer";
|
|
2
|
+
import { getLastUserMessage, isMessageCompacted } from "../shared-utils";
|
|
3
|
+
export function getCurrentParams(state, messages, logger) {
|
|
4
|
+
const userMsg = getLastUserMessage(messages);
|
|
5
|
+
if (!userMsg) {
|
|
6
|
+
logger.debug("No user message found when determining current params");
|
|
7
|
+
return {
|
|
8
|
+
providerId: undefined,
|
|
9
|
+
modelId: undefined,
|
|
10
|
+
agent: undefined,
|
|
11
|
+
variant: state.variant,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const userInfo = userMsg.info;
|
|
15
|
+
const agent = userInfo.agent;
|
|
16
|
+
const providerId = userInfo.model.providerID;
|
|
17
|
+
const modelId = userInfo.model.modelID;
|
|
18
|
+
const variant = state.variant ?? userInfo.variant;
|
|
19
|
+
return { providerId, modelId, agent, variant };
|
|
20
|
+
}
|
|
21
|
+
export function countTokens(text) {
|
|
22
|
+
if (!text)
|
|
23
|
+
return 0;
|
|
24
|
+
try {
|
|
25
|
+
return anthropicCountTokens(text);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return Math.round(text.length / 4);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function estimateTokensBatch(texts) {
|
|
32
|
+
return texts.map(countTokens);
|
|
33
|
+
}
|
|
34
|
+
export const calculateTokensSaved = (state, messages, pruneToolIds) => {
|
|
35
|
+
try {
|
|
36
|
+
const contents = [];
|
|
37
|
+
for (const msg of messages) {
|
|
38
|
+
if (isMessageCompacted(state, msg)) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const parts = Array.isArray(msg.parts) ? msg.parts : [];
|
|
42
|
+
for (const part of parts) {
|
|
43
|
+
if (part.type !== "tool" || !pruneToolIds.includes(part.callID)) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (part.tool === "question") {
|
|
47
|
+
const questions = part.state.input?.questions;
|
|
48
|
+
if (questions !== undefined) {
|
|
49
|
+
const content = typeof questions === "string" ? questions : JSON.stringify(questions);
|
|
50
|
+
contents.push(content);
|
|
51
|
+
}
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (part.state.status === "completed") {
|
|
55
|
+
const content = typeof part.state.output === "string"
|
|
56
|
+
? part.state.output
|
|
57
|
+
: JSON.stringify(part.state.output);
|
|
58
|
+
contents.push(content);
|
|
59
|
+
}
|
|
60
|
+
else if (part.state.status === "error") {
|
|
61
|
+
const content = typeof part.state.error === "string"
|
|
62
|
+
? part.state.error
|
|
63
|
+
: JSON.stringify(part.state.error);
|
|
64
|
+
contents.push(content);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const tokenCounts = estimateTokensBatch(contents);
|
|
69
|
+
return tokenCounts.reduce((sum, count) => sum + count, 0);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
return 0;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../lib/strategies/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC7E,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAExE,MAAM,UAAU,gBAAgB,CAC5B,KAAmB,EACnB,QAAqB,EACrB,MAAc;IAOd,MAAM,OAAO,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAA;IAC5C,IAAI,CAAC,OAAO,EAAE,CAAC;QACX,MAAM,CAAC,KAAK,CAAC,uDAAuD,CAAC,CAAA;QACrE,OAAO;YACH,UAAU,EAAE,SAAS;YACrB,OAAO,EAAE,SAAS;YAClB,KAAK,EAAE,SAAS;YAChB,OAAO,EAAE,KAAK,CAAC,OAAO;SACzB,CAAA;IACL,CAAC;IACD,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAmB,CAAA;IAC5C,MAAM,KAAK,GAAW,QAAQ,CAAC,KAAK,CAAA;IACpC,MAAM,UAAU,GAAuB,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAA;IAChE,MAAM,OAAO,GAAuB,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAA;IAC1D,MAAM,OAAO,GAAuB,KAAK,CAAC,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAA;IAErE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAA;AAClD,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY;IACpC,IAAI,CAAC,IAAI;QAAE,OAAO,CAAC,CAAA;IACnB,IAAI,CAAC;QACD,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAA;IACrC,CAAC;IAAC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I,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;oBACpC,MAAM,OAAO,GACT,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,QAAQ;wBACjC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM;wBACnB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;oBAC3C,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;gBAC1B,CAAC;qBAAM,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;oBACvC,MAAM,OAAO,GACT,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,QAAQ;wBAChC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK;wBAClB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;oBAC1C,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;gBAC1B,CAAC;YACL,CAAC;QACL,CAAC;QACD,MAAM,WAAW,GAAa,mBAAmB,CAAC,QAAQ,CAAC,CAAA;QAC3D,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,EAAE,CAAC,CAAC,CAAA;IAC7D,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QAClB,OAAO,CAAC,CAAA;IACZ,CAAC;AACL,CAAC,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Logger } from "../logger";
|
|
2
|
+
import type { SessionState } from "../state";
|
|
3
|
+
import { ToolParameterEntry } from "../state";
|
|
4
|
+
import { PluginConfig } from "../config";
|
|
5
|
+
export type PruneReason = "completion" | "noise" | "superseded" | "exploration" | "duplicate" | "extraction";
|
|
6
|
+
export declare const PRUNE_REASON_LABELS: Record<PruneReason, string>;
|
|
7
|
+
export interface NotifyOptions {
|
|
8
|
+
simplified?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function sendUnifiedNotification(client: any, logger: Logger, config: PluginConfig, state: SessionState, sessionId: string, pruneToolIds: string[], toolMetadata: Map<string, ToolParameterEntry>, reason: PruneReason | undefined, params: any, workingDirectory: string, distillation?: string[], options?: NotifyOptions): Promise<boolean>;
|
|
11
|
+
export declare function sendIgnoredMessage(client: any, sessionID: string, text: string, params: any, logger: Logger): Promise<void>;
|
|
12
|
+
//# sourceMappingURL=notification.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification.d.ts","sourceRoot":"","sources":["../../../lib/ui/notification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAQ5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC,MAAM,MAAM,WAAW,GACjB,YAAY,GACZ,OAAO,GACP,YAAY,GACZ,aAAa,GACb,WAAW,GACX,YAAY,CAAA;AAClB,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAO3D,CAAA;AA+DD,MAAM,WAAW,aAAa;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAA;CACvB;AAED,wBAAsB,uBAAuB,CACzC,MAAM,EAAE,GAAG,EACX,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EAAE,EACtB,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,EAC7C,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,MAAM,EAAE,GAAG,EACX,gBAAgB,EAAE,MAAM,EACxB,YAAY,CAAC,EAAE,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,aAAa,GACxB,OAAO,CAAC,OAAO,CAAC,CA6BlB;AAED,wBAAsB,kBAAkB,CACpC,MAAM,EAAE,GAAG,EACX,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,GAAG,EACX,MAAM,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAiCf"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { countDistillationTokens, formatExtracted, formatPrunedItemsList, formatStatsHeader, formatTokenCount, } from "./utils";
|
|
2
|
+
export const PRUNE_REASON_LABELS = {
|
|
3
|
+
completion: "Task Complete",
|
|
4
|
+
noise: "Noise Removal",
|
|
5
|
+
superseded: "Superseded",
|
|
6
|
+
exploration: "Dead-end Exploration",
|
|
7
|
+
duplicate: "Duplicate Content",
|
|
8
|
+
extraction: "Extraction",
|
|
9
|
+
};
|
|
10
|
+
function buildMinimalMessage(state, reason, distillation, showDistillation) {
|
|
11
|
+
const extractedTokens = countDistillationTokens(distillation);
|
|
12
|
+
const extractedSuffix = extractedTokens > 0 ? ` (extracted ${formatTokenCount(extractedTokens)})` : "";
|
|
13
|
+
const reasonSuffix = reason && extractedTokens === 0 ? ` โ ${PRUNE_REASON_LABELS[reason]}` : "";
|
|
14
|
+
let message = formatStatsHeader(state.stats.totalPruneTokens, state.stats.pruneTokenCounter, state.stats.totalPruneMessages, state.stats.pruneMessageCounter) +
|
|
15
|
+
reasonSuffix +
|
|
16
|
+
extractedSuffix;
|
|
17
|
+
return message + formatExtracted(showDistillation ? distillation : undefined);
|
|
18
|
+
}
|
|
19
|
+
function buildDetailedMessage(state, reason, pruneToolIds, toolMetadata, workingDirectory, distillation, showDistillation, simplified = false) {
|
|
20
|
+
let message = formatStatsHeader(state.stats.totalPruneTokens, state.stats.pruneTokenCounter, state.stats.totalPruneMessages, state.stats.pruneMessageCounter);
|
|
21
|
+
if (pruneToolIds.length > 0) {
|
|
22
|
+
const pruneTokenCounterStr = `~${formatTokenCount(state.stats.pruneTokenCounter)}`;
|
|
23
|
+
const extractedTokens = countDistillationTokens(distillation);
|
|
24
|
+
const extractedSuffix = extractedTokens > 0 ? `, extracted ${formatTokenCount(extractedTokens)}` : "";
|
|
25
|
+
const reasonLabel = reason && extractedTokens === 0 ? ` โ ${PRUNE_REASON_LABELS[reason]}` : "";
|
|
26
|
+
message += `\n\nโฃ Pruning (${pruneTokenCounterStr}${extractedSuffix})${reasonLabel}`;
|
|
27
|
+
const itemLines = formatPrunedItemsList(pruneToolIds, toolMetadata, workingDirectory, simplified);
|
|
28
|
+
message += "\n" + itemLines.join("\n");
|
|
29
|
+
}
|
|
30
|
+
return (message + formatExtracted(showDistillation ? distillation : undefined)).trim();
|
|
31
|
+
}
|
|
32
|
+
export async function sendUnifiedNotification(client, logger, config, state, sessionId, pruneToolIds, toolMetadata, reason, params, workingDirectory, distillation, options) {
|
|
33
|
+
const hasPruned = pruneToolIds.length > 0;
|
|
34
|
+
if (!hasPruned) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (config.pruneNotification === "off") {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const showDistillation = config.tools.extract.showDistillation;
|
|
41
|
+
const simplified = options?.simplified ?? false;
|
|
42
|
+
const message = config.pruneNotification === "minimal"
|
|
43
|
+
? buildMinimalMessage(state, reason, distillation, showDistillation)
|
|
44
|
+
: buildDetailedMessage(state, reason, pruneToolIds, toolMetadata, workingDirectory, distillation, showDistillation, simplified);
|
|
45
|
+
await sendIgnoredMessage(client, sessionId, message, params, logger);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
export async function sendIgnoredMessage(client, sessionID, text, params, logger) {
|
|
49
|
+
const agent = params.agent || undefined;
|
|
50
|
+
const variant = params.variant || undefined;
|
|
51
|
+
const model = params.providerId && params.modelId
|
|
52
|
+
? {
|
|
53
|
+
providerID: params.providerId,
|
|
54
|
+
modelID: params.modelId,
|
|
55
|
+
}
|
|
56
|
+
: undefined;
|
|
57
|
+
try {
|
|
58
|
+
await client.session.prompt({
|
|
59
|
+
path: {
|
|
60
|
+
id: sessionID,
|
|
61
|
+
},
|
|
62
|
+
body: {
|
|
63
|
+
noReply: true,
|
|
64
|
+
agent: agent,
|
|
65
|
+
model: model,
|
|
66
|
+
variant: variant,
|
|
67
|
+
parts: [
|
|
68
|
+
{
|
|
69
|
+
type: "text",
|
|
70
|
+
text: text,
|
|
71
|
+
ignored: true,
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
logger.error("Failed to send notification", { error: error.message });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=notification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification.js","sourceRoot":"","sources":["../../../lib/ui/notification.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,uBAAuB,EACvB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,GACnB,MAAM,SAAS,CAAA;AAWhB,MAAM,CAAC,MAAM,mBAAmB,GAAgC;IAC5D,UAAU,EAAE,eAAe;IAC3B,KAAK,EAAE,eAAe;IACtB,UAAU,EAAE,YAAY;IACxB,WAAW,EAAE,sBAAsB;IACnC,SAAS,EAAE,mBAAmB;IAC9B,UAAU,EAAE,YAAY;CAC3B,CAAA;AAED,SAAS,mBAAmB,CACxB,KAAmB,EACnB,MAA+B,EAC/B,YAAkC,EAClC,gBAAyB;IAEzB,MAAM,eAAe,GAAG,uBAAuB,CAAC,YAAY,CAAC,CAAA;IAC7D,MAAM,eAAe,GACjB,eAAe,GAAG,CAAC,CAAC,CAAC,CAAC,eAAe,gBAAgB,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;IAClF,MAAM,YAAY,GAAG,MAAM,IAA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gBAAgB,EAChB,UAAU,CACb,CAAA;IAEX,MAAM,kBAAkB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;IACpE,OAAO,IAAI,CAAA;AACf,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACpC,MAAW,EACX,SAAiB,EACjB,IAAY,EACZ,MAAW,EACX,MAAc;IAEd,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,SAAS,CAAA;IACvC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,SAAS,CAAA;IAC3C,MAAM,KAAK,GACP,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,OAAO;QAC/B,CAAC,CAAC;YACI,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,OAAO,EAAE,MAAM,CAAC,OAAO;SAC1B;QACH,CAAC,CAAC,SAAS,CAAA;IAEnB,IAAI,CAAC;QACD,MAAM,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;YACxB,IAAI,EAAE;gBACF,EAAE,EAAE,SAAS;aAChB;YACD,IAAI,EAAE;gBACF,OAAO,EAAE,IAAI;gBACb,KAAK,EAAE,KAAK;gBACZ,KAAK,EAAE,KAAK;gBACZ,OAAO,EAAE,OAAO;gBAChB,KAAK,EAAE;oBACH;wBACI,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,IAAI;wBACV,OAAO,EAAE,IAAI;qBAChB;iBACJ;aACJ;SACJ,CAAC,CAAA;IACN,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QAClB,MAAM,CAAC,KAAK,CAAC,6BAA6B,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;IACzE,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ToolParameterEntry } from "../state";
|
|
2
|
+
export declare function countDistillationTokens(distillation?: string[]): number;
|
|
3
|
+
export declare function formatExtracted(distillation?: string[]): string;
|
|
4
|
+
export declare function formatStatsHeader(totalTokensSaved: number, pruneTokenCounter: number, totalMessagesPruned: number, messagesPruned: number): string;
|
|
5
|
+
export declare function formatTokenCount(tokens: number): string;
|
|
6
|
+
export declare function truncate(str: string, maxLen?: number): string;
|
|
7
|
+
export declare function shortenPath(input: string, workingDirectory?: string): string;
|
|
8
|
+
export declare function formatPrunedItemsList(pruneToolIds: string[], toolMetadata: Map<string, ToolParameterEntry>, workingDirectory?: string, simplified?: boolean): string[];
|
|
9
|
+
export declare function formatPruningResultForTool(prunedIds: string[], toolMetadata: Map<string, ToolParameterEntry>, workingDirectory?: string, simplified?: boolean): string;
|
|
10
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../lib/ui/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAI7C,wBAAgB,uBAAuB,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAGvE;AAED,wBAAgB,eAAe,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAS/D;AAED,wBAAgB,iBAAiB,CAC7B,gBAAgB,EAAE,MAAM,EACxB,iBAAiB,EAAE,MAAM,EACzB,mBAAmB,EAAE,MAAM,EAC3B,cAAc,EAAE,MAAM,GACvB,MAAM,CAgBR;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKvD;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,MAAW,GAAG,MAAM,CAGjE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,CAU5E;AAeD,wBAAgB,qBAAqB,CACjC,YAAY,EAAE,MAAM,EAAE,EACtB,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,EAC7C,gBAAgB,CAAC,EAAE,MAAM,EACzB,UAAU,GAAE,OAAe,GAC5B,MAAM,EAAE,CAwCV;AAED,wBAAgB,0BAA0B,CACtC,SAAS,EAAE,MAAM,EAAE,EACnB,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,EAC7C,gBAAgB,CAAC,EAAE,MAAM,EACzB,UAAU,GAAE,OAAe,GAC5B,MAAM,CAWR"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { extractParameterKey } from "../messages/utils";
|
|
2
|
+
import { countTokens } from "../strategies/utils";
|
|
3
|
+
export function countDistillationTokens(distillation) {
|
|
4
|
+
if (!distillation || distillation.length === 0)
|
|
5
|
+
return 0;
|
|
6
|
+
return countTokens(distillation.join("\n"));
|
|
7
|
+
}
|
|
8
|
+
export function formatExtracted(distillation) {
|
|
9
|
+
if (!distillation || distillation.length === 0) {
|
|
10
|
+
return "";
|
|
11
|
+
}
|
|
12
|
+
let result = `\n\nโฃ Extracted`;
|
|
13
|
+
for (const finding of distillation) {
|
|
14
|
+
result += `\nโโโ\n${finding}`;
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
export function formatStatsHeader(totalTokensSaved, pruneTokenCounter, totalMessagesPruned, messagesPruned) {
|
|
19
|
+
const totalMessages = totalMessagesPruned + messagesPruned;
|
|
20
|
+
const totalTokens = totalTokensSaved + pruneTokenCounter;
|
|
21
|
+
const totalTokensStr = `~${formatTokenCount(totalTokens)}`;
|
|
22
|
+
// Show addition indicator for current operation
|
|
23
|
+
const additionParts = [];
|
|
24
|
+
if (messagesPruned > 0) {
|
|
25
|
+
additionParts.push(`+${messagesPruned} ๐ฌ`);
|
|
26
|
+
}
|
|
27
|
+
if (pruneTokenCounter > 0) {
|
|
28
|
+
additionParts.push(`+${formatTokenCount(pruneTokenCounter)} ๐ช`);
|
|
29
|
+
}
|
|
30
|
+
const additionSuffix = additionParts.length > 0 ? ` (${additionParts.join(", ")})` : "";
|
|
31
|
+
return `acp - ${totalMessages} ๐ฌ ยท ${totalTokensStr} ๐ช${additionSuffix}`;
|
|
32
|
+
}
|
|
33
|
+
export function formatTokenCount(tokens) {
|
|
34
|
+
if (tokens >= 1000) {
|
|
35
|
+
return `${(tokens / 1000).toFixed(1)}K`.replace(".0K", "K");
|
|
36
|
+
}
|
|
37
|
+
return tokens.toString();
|
|
38
|
+
}
|
|
39
|
+
export function truncate(str, maxLen = 60) {
|
|
40
|
+
if (str.length <= maxLen)
|
|
41
|
+
return str;
|
|
42
|
+
return str.slice(0, maxLen - 3) + "...";
|
|
43
|
+
}
|
|
44
|
+
export function shortenPath(input, workingDirectory) {
|
|
45
|
+
const inPathMatch = input.match(/^(.+) in (.+)$/);
|
|
46
|
+
if (inPathMatch?.[1] && inPathMatch[2]) {
|
|
47
|
+
const prefix = inPathMatch[1];
|
|
48
|
+
const pathPart = inPathMatch[2];
|
|
49
|
+
const shortenedPath = shortenSinglePath(pathPart, workingDirectory);
|
|
50
|
+
return `${prefix} in ${shortenedPath}`;
|
|
51
|
+
}
|
|
52
|
+
return shortenSinglePath(input, workingDirectory);
|
|
53
|
+
}
|
|
54
|
+
function shortenSinglePath(path, workingDirectory) {
|
|
55
|
+
if (workingDirectory) {
|
|
56
|
+
if (path.startsWith(workingDirectory + "/")) {
|
|
57
|
+
return path.slice(workingDirectory.length + 1);
|
|
58
|
+
}
|
|
59
|
+
if (path === workingDirectory) {
|
|
60
|
+
return ".";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return path;
|
|
64
|
+
}
|
|
65
|
+
export function formatPrunedItemsList(pruneToolIds, toolMetadata, workingDirectory, simplified = false) {
|
|
66
|
+
const lines = [];
|
|
67
|
+
for (const id of pruneToolIds) {
|
|
68
|
+
const metadata = toolMetadata.get(id);
|
|
69
|
+
if (metadata) {
|
|
70
|
+
const paramKey = extractParameterKey(metadata.tool, metadata.parameters);
|
|
71
|
+
if (paramKey) {
|
|
72
|
+
// Use 60 char limit to match notification style
|
|
73
|
+
const displayKey = truncate(shortenPath(paramKey, workingDirectory), 60);
|
|
74
|
+
if (simplified) {
|
|
75
|
+
lines.push(displayKey);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
lines.push(`โ ${metadata.tool}: ${displayKey}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
if (simplified) {
|
|
83
|
+
lines.push(metadata.tool);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
lines.push(`โ ${metadata.tool}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const knownCount = pruneToolIds.filter((id) => toolMetadata.has(id)).length;
|
|
92
|
+
const unknownCount = pruneToolIds.length - knownCount;
|
|
93
|
+
if (unknownCount > 0) {
|
|
94
|
+
if (simplified) {
|
|
95
|
+
lines.push(`(${unknownCount} tool${unknownCount > 1 ? "s" : ""} with unknown metadata)`);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
lines.push(`โ (${unknownCount} tool${unknownCount > 1 ? "s" : ""} with unknown metadata)`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return lines;
|
|
102
|
+
}
|
|
103
|
+
export function formatPruningResultForTool(prunedIds, toolMetadata, workingDirectory, simplified = false) {
|
|
104
|
+
const lines = [];
|
|
105
|
+
lines.push(`Context pruning complete. Pruned ${prunedIds.length} tool outputs.`);
|
|
106
|
+
lines.push("");
|
|
107
|
+
if (prunedIds.length > 0) {
|
|
108
|
+
lines.push(`Semantically pruned (${prunedIds.length}):`);
|
|
109
|
+
lines.push(...formatPrunedItemsList(prunedIds, toolMetadata, workingDirectory, simplified));
|
|
110
|
+
}
|
|
111
|
+
return lines.join("\n").trim();
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=utils.js.map
|