dsh-awesome-optimizer 2.1.0 → 3.3.0
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 +29 -35
- package/README.zh.md +29 -35
- package/cache-diagnostics.md +19 -0
- package/cordis.patch.yml +14 -2
- package/outline-benchmark.md +37 -0
- package/outline-benchmark.windows.json +184 -0
- package/package.json +15 -2
- package/scripts/benchmark-outline.mjs +100 -0
- package/scripts/benchmark.mjs +33 -26
- package/scripts/typecheck.mjs +37 -18
- package/src/ast-outline-config.yml +1 -0
- package/src/ast-outline.js +143 -0
- package/src/cache-diagnostics.js +218 -0
- package/src/code-lexical.js +131 -0
- package/src/code-outline.js +171 -0
- package/src/composite-tools.d.ts +36 -8
- package/src/composite-tools.js +538 -194
- package/src/convergence.js +3 -3
- package/src/custom-prompt.d.ts +7 -1
- package/src/custom-prompt.js +53 -18
- package/src/edit-recovery.d.ts +59 -0
- package/src/edit-recovery.js +524 -0
- package/src/failure-recovery.js +1 -1
- package/src/file-mutation-policy.js +0 -8
- package/src/find-read-output.js +175 -0
- package/src/find-read-ranking.js +63 -0
- package/src/index.d.ts +34 -2
- package/src/index.js +29 -5
- package/src/outline-cache.js +36 -0
- package/src/persistent-eval/daemon-pool.js +3 -2
- package/src/persistent-eval/index.d.ts +35 -8
- package/src/persistent-eval/index.js +51 -16
- package/src/persistent-eval/stdio-runner.js +209 -30
- package/src/persistent-eval/workers/node_worker.mjs +42 -31
- package/src/persistent-eval/workers/py_worker.py +47 -24
- package/src/prompt-linter.js +43 -26
- package/src/read-guard.d.ts +80 -0
- package/src/read-guard.js +336 -0
- package/src/runtime-policy.d.ts +1 -0
- package/src/runtime-policy.js +35 -15
- package/src/telemetry.d.ts +4 -0
- package/src/telemetry.js +27 -8
package/src/telemetry.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { CacheDiagnostics } from './cache-diagnostics.js';
|
|
1
3
|
import z from '@deepseek-ai/schemastery';
|
|
2
4
|
import { SOURCE as CONVERGENCE_SOURCE } from './convergence.js';
|
|
3
5
|
import { RECOVERY_SOURCE } from './failure-recovery.js';
|
|
4
|
-
|
|
5
6
|
export const TelemetryConfig = z.object({
|
|
6
7
|
enabled: z.boolean().default(true),
|
|
7
8
|
trackStreams: z.boolean().default(true),
|
|
8
|
-
onTurnSummary: z.any()
|
|
9
|
+
onTurnSummary: z.any(),
|
|
10
|
+
cacheDiagnosticsPath: z.string()
|
|
9
11
|
});
|
|
10
12
|
|
|
11
13
|
function computeQuantile(sortedNumbers, p) {
|
|
@@ -85,8 +87,15 @@ export class AgentTelemetryManager {
|
|
|
85
87
|
this.sessionStates = new WeakMap();
|
|
86
88
|
this.sessionsById = new Map();
|
|
87
89
|
this.activeSession = null;
|
|
90
|
+
this.previousHistories = new WeakMap();
|
|
88
91
|
}
|
|
89
92
|
|
|
93
|
+
#digestMessage(message) {
|
|
94
|
+
if (message && typeof message === 'object') {
|
|
95
|
+
return createHash('sha256').update(JSON.stringify(message)).digest('hex');
|
|
96
|
+
}
|
|
97
|
+
return createHash('sha256').update(String(message)).digest('hex');
|
|
98
|
+
}
|
|
90
99
|
#createTurnState(turn) {
|
|
91
100
|
return {
|
|
92
101
|
turn,
|
|
@@ -103,7 +112,6 @@ export class AgentTelemetryManager {
|
|
|
103
112
|
recoveryNotices: 0,
|
|
104
113
|
turnOutcome: null,
|
|
105
114
|
streamAttempts: [],
|
|
106
|
-
previousHistory: null,
|
|
107
115
|
prefixChanges: 0
|
|
108
116
|
};
|
|
109
117
|
}
|
|
@@ -166,6 +174,7 @@ export class AgentTelemetryManager {
|
|
|
166
174
|
}
|
|
167
175
|
|
|
168
176
|
onSessionDisposed(session) {
|
|
177
|
+
if (session) this.previousHistories.delete(session);
|
|
169
178
|
if (session?.id !== undefined && this.sessionsById.get(session.id) === session) {
|
|
170
179
|
this.sessionsById.delete(session.id);
|
|
171
180
|
}
|
|
@@ -180,11 +189,11 @@ export class AgentTelemetryManager {
|
|
|
180
189
|
if (!state) return next();
|
|
181
190
|
|
|
182
191
|
if (Array.isArray(options?.messages)) {
|
|
183
|
-
const history = options.messages.map(message =>
|
|
184
|
-
if (
|
|
192
|
+
const history = options.messages.map(message => this.#digestMessage(message));
|
|
193
|
+
if (this.previousHistories.get(session)?.some((msg, idx) => history[idx] !== msg)) {
|
|
185
194
|
state.prefixChanges++;
|
|
186
195
|
}
|
|
187
|
-
|
|
196
|
+
this.previousHistories.set(session, history);
|
|
188
197
|
}
|
|
189
198
|
|
|
190
199
|
const attempt = {
|
|
@@ -241,7 +250,8 @@ export class AgentTelemetryManager {
|
|
|
241
250
|
runtimePolicy: null,
|
|
242
251
|
fileMutationPolicy: null,
|
|
243
252
|
failureRecovery: null,
|
|
244
|
-
compositeTools: null
|
|
253
|
+
compositeTools: null,
|
|
254
|
+
readGuard: null
|
|
245
255
|
};
|
|
246
256
|
}
|
|
247
257
|
|
|
@@ -299,7 +309,8 @@ export class AgentTelemetryManager {
|
|
|
299
309
|
runtimePolicy: this.ctx?.get?.('runtimePolicy')?.getSummary(targetSession, state.turn) ?? null,
|
|
300
310
|
fileMutationPolicy: this.ctx?.get?.('fileMutationPolicy')?.getSummary(targetSession, state.turn) ?? null,
|
|
301
311
|
failureRecovery: this.ctx?.get?.('failureRecovery')?.getStats(targetSession) ?? null,
|
|
302
|
-
compositeTools: this.ctx?.get?.('compositeTools')?.getStats(targetSession) ?? null
|
|
312
|
+
compositeTools: this.ctx?.get?.('compositeTools')?.getStats(targetSession) ?? null,
|
|
313
|
+
readGuard: this.ctx?.get?.('readGuard')?.getStats(targetSession) ?? null
|
|
303
314
|
};
|
|
304
315
|
}
|
|
305
316
|
}
|
|
@@ -309,6 +320,14 @@ export function applyTelemetry(ctx, rawConfig = {}) {
|
|
|
309
320
|
if (!config.enabled) return null;
|
|
310
321
|
|
|
311
322
|
const manager = new AgentTelemetryManager(ctx, config);
|
|
323
|
+
if (config.cacheDiagnosticsPath) {
|
|
324
|
+
const warn = reason => { try { ctx.logger?.warn?.(`Cache diagnostics disabled: ${reason}`); } catch {} };
|
|
325
|
+
try {
|
|
326
|
+
const diagnostics = new CacheDiagnostics(config.cacheDiagnosticsPath, { onStop: warn });
|
|
327
|
+
ctx.on('llm/stream', (options, next) => diagnostics.wrap(options?.sessionId, next));
|
|
328
|
+
ctx.on('dispose', () => diagnostics.dispose());
|
|
329
|
+
} catch { warn('initialization-failed'); }
|
|
330
|
+
}
|
|
312
331
|
|
|
313
332
|
ctx.on('session/event', (session, event) => {
|
|
314
333
|
manager.onSessionEvent(session, event);
|