dsh-awesome-optimizer 0.0.0-stage → 1.7.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/package.json CHANGED
@@ -1,6 +1,114 @@
1
1
  {
2
2
  "name": "dsh-awesome-optimizer",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.7.0",
4
+ "description": "Runtime policy guards, composite batch tooling, soft convergence guidance, reactive custom prompt engine, and A/B telemetry plugin for the official DeepSeek Harness (dsh) agent loop.",
5
+ "type": "module",
6
+ "main": "src/index.js",
7
+ "types": "src/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./src/index.d.ts",
11
+ "default": "./src/index.js"
12
+ },
13
+ "./policy": {
14
+ "types": "./src/runtime-policy.d.ts",
15
+ "default": "./src/runtime-policy.js"
16
+ },
17
+ "./mutation-policy": {
18
+ "types": "./src/file-mutation-policy.d.ts",
19
+ "default": "./src/file-mutation-policy.js"
20
+ },
21
+ "./recovery": {
22
+ "types": "./src/failure-recovery.d.ts",
23
+ "default": "./src/failure-recovery.js"
24
+ },
25
+ "./composite-tools": {
26
+ "types": "./src/composite-tools.d.ts",
27
+ "default": "./src/composite-tools.js"
28
+ },
29
+ "./convergence": {
30
+ "types": "./src/convergence.d.ts",
31
+ "default": "./src/convergence.js"
32
+ },
33
+ "./custom-prompt": {
34
+ "types": "./src/custom-prompt.d.ts",
35
+ "default": "./src/custom-prompt.js"
36
+ },
37
+ "./telemetry": {
38
+ "types": "./src/telemetry.d.ts",
39
+ "default": "./src/telemetry.js"
40
+ },
41
+ "./locale/*.json": "./locale/*.json",
42
+ "./package.json": "./package.json"
43
+ },
44
+ "files": [
45
+ "src",
46
+ "cordis.patch.yml",
47
+ "locale/*.json",
48
+ "scripts/typecheck.mjs",
49
+ "scripts/benchmark.mjs",
50
+ "README.md",
51
+ "README.zh.md",
52
+ "LICENSE"
53
+ ],
54
+ "dsh": {
55
+ "bundle": {
56
+ "patch": "./cordis.patch.yml"
57
+ }
58
+ },
59
+ "engines": {
60
+ "node": ">=22.0.0",
61
+ "dsh": ">=0.2.2-rc.1"
62
+ },
63
+ "scripts": {
64
+ "setup:local": "node scripts/setup-local.mjs",
65
+ "test": "node --test --test-timeout=15000 test/*.test.js",
66
+ "typecheck": "node scripts/typecheck.mjs",
67
+ "benchmark": "node scripts/benchmark.mjs"
68
+ },
69
+ "author": "Jaylor-Wang",
70
+ "license": "MIT",
71
+ "homepage": "https://github.com/Jaylor-Wang/dsh-awesome-optimizer#readme",
72
+ "repository": {
73
+ "type": "git",
74
+ "url": "git+https://github.com/Jaylor-Wang/dsh-awesome-optimizer.git"
75
+ },
76
+ "bugs": {
77
+ "url": "https://github.com/Jaylor-Wang/dsh-awesome-optimizer/issues"
78
+ },
79
+ "keywords": [
80
+ "deepseek-harness",
81
+ "dsh",
82
+ "dsh-plugin",
83
+ "cordis",
84
+ "agent-loop",
85
+ "runtime-policy",
86
+ "convergence",
87
+ "telemetry",
88
+ "composite-tools"
89
+ ],
90
+ "peerDependencies": {
91
+ "@deepseek-ai/cordis": ">=4.0.0",
92
+ "@deepseek-ai/dsh-agent": "*",
93
+ "@deepseek-ai/dsh-agent-loop": "*",
94
+ "@deepseek-ai/dsh-llm": "*",
95
+ "@deepseek-ai/dsh-session": "*",
96
+ "@deepseek-ai/dsh-system-prompt": "*",
97
+ "@deepseek-ai/dsh-tools": "*",
98
+ "@deepseek-ai/schemastery": ">=3.0.0"
99
+ },
100
+ "peerDependenciesMeta": {
101
+ "@deepseek-ai/dsh-agent": {
102
+ "optional": true
103
+ },
104
+ "@deepseek-ai/dsh-agent-loop": {
105
+ "optional": true
106
+ },
107
+ "@deepseek-ai/dsh-session": {
108
+ "optional": true
109
+ },
110
+ "@deepseek-ai/schemastery": {
111
+ "optional": true
112
+ }
113
+ }
114
+ }
@@ -0,0 +1,113 @@
1
+ import assert from 'node:assert/strict';
2
+ import { createTestRuntime, call } from '../test/support/runtime.js';
3
+ import { compareTurnSummaries, PAIRING_ERROR } from '../src/index.js';
4
+
5
+ // Run deterministic A/B verification scenarios over the unchanged official @deepseek-ai/dsh-agent-loop.
6
+ async function runBatchReadScenario() {
7
+ const files = {
8
+ 'a.txt': 'Alpha content line 1\nAlpha content line 2',
9
+ 'b.txt': 'Beta content line 1\nBeta content line 2',
10
+ 'c.txt': 'Gamma content line 1\nGamma content line 2'
11
+ };
12
+
13
+ // Baseline: sequential single-file reads across 3 steps + final answer (4 model requests)
14
+ const baselineHost = await createTestRuntime({
15
+ optimizerEnabled: true,
16
+ optimizerConfig: {
17
+ compositeTools: { enabled: false },
18
+ convergence: { enabled: false }
19
+ },
20
+ files,
21
+ script: [
22
+ [call('r1', 'read', { file_path: 'a.txt' })],
23
+ [call('r2', 'read', { file_path: 'b.txt' })],
24
+ [call('r3', 'read', { file_path: 'c.txt' })],
25
+ [{ type: 'text', text: 'Synthesized alpha, beta, gamma.' }]
26
+ ]
27
+ });
28
+
29
+ // Candidate: read_batch collapses 3 file reads into 1 round-trip + final answer (2 model requests)
30
+ const candidateHost = await createTestRuntime({
31
+ optimizerEnabled: true,
32
+ files,
33
+ script: [
34
+ [call('rb1', 'read_batch', {
35
+ files: [
36
+ { file_path: 'a.txt' },
37
+ { file_path: 'b.txt' },
38
+ { file_path: 'c.txt' }
39
+ ]
40
+ })],
41
+ [{ type: 'text', text: 'Synthesized alpha, beta, gamma.' }]
42
+ ]
43
+ });
44
+
45
+ try {
46
+ await baselineHost.run('Read a.txt, b.txt, and c.txt and summarize.');
47
+ await candidateHost.run('Read a.txt, b.txt, and c.txt and summarize.');
48
+
49
+ const baseSummary = baselineHost.telemetry.getSummary(baselineHost.agent.session);
50
+ const candSummary = candidateHost.telemetry.getSummary(candidateHost.agent.session);
51
+ const comparison = compareTurnSummaries(baseSummary, candSummary);
52
+
53
+ assert.equal(baseSummary.modelRequests, 4);
54
+ assert.equal(candSummary.modelRequests, 2);
55
+ assert.equal(candSummary.ptcSubCalls, 3);
56
+ assert.equal(comparison.modelRequests.delta, -2);
57
+
58
+ return {
59
+ scenario: 'multi-file-read-collapse',
60
+ baseline: baseSummary,
61
+ candidate: candSummary,
62
+ comparison
63
+ };
64
+ } finally {
65
+ await baselineHost.dispose();
66
+ await candidateHost.dispose();
67
+ }
68
+ }
69
+
70
+ async function runWriteRecoveryScenario() {
71
+ const largePayload = 'x'.repeat(9000);
72
+ const host = await createTestRuntime({
73
+ optimizerEnabled: true,
74
+ script: [
75
+ [call('w1', 'write', {
76
+ file_path: 'deliverable.txt',
77
+ content: largePayload,
78
+ justification: 'Unpaired justification rejected when approval prompts are disabled'
79
+ })],
80
+ [call('rw1', 'retry_failed_write', { call_id: 'w1' })],
81
+ [{ type: 'text', text: 'Recovered large write without regenerating 9KB content.' }]
82
+ ],
83
+ writeHandler(args) {
84
+ if (args.justification && !args.sandbox_permissions) {
85
+ throw new Error(PAIRING_ERROR);
86
+ }
87
+ return `Wrote ${args.file_path} (${args.content.length} bytes)`;
88
+ }
89
+ });
90
+
91
+ try {
92
+ await host.run('Write deliverable.txt.');
93
+ const summary = host.telemetry.getSummary(host.agent.session);
94
+ assert.equal(summary.failureRecovery?.succeeded, 1);
95
+ return {
96
+ scenario: 'failed-large-write-recovery',
97
+ summary
98
+ };
99
+ } finally {
100
+ await host.dispose();
101
+ }
102
+ }
103
+
104
+ const batchScenario = await runBatchReadScenario();
105
+ const recoveryScenario = await runWriteRecoveryScenario();
106
+
107
+ console.log(JSON.stringify({
108
+ mode: 'official-loop-ab-verification',
109
+ officialLoopReplaced: false,
110
+ networkRequests: 0,
111
+ note: 'Offline scripted verification proves mechanism and telemetry fidelity. Run identical live tasks to evaluate model-specific round-trip reductions.',
112
+ scenarios: [batchScenario, recoveryScenario]
113
+ }, null, 2));
@@ -0,0 +1,57 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { spawnSync } from 'node:child_process';
4
+ import { createRequire } from 'node:module';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const root = fileURLToPath(new URL('../', import.meta.url));
8
+ const require = createRequire(import.meta.url);
9
+
10
+ function findTsc() {
11
+ const searchBases = [
12
+ root,
13
+ path.resolve(root, '../Awesome-Canvas/web'),
14
+ path.resolve(root, '../threejs-projects'),
15
+ 'D:/nodejs/node_global/node_modules/@deepseek-ai/dsh',
16
+ 'D:/nodejs/node_global'
17
+ ];
18
+ for (const base of searchBases) {
19
+ try {
20
+ const baseReq = createRequire(path.join(base, 'package.json'));
21
+ const pkgFile = baseReq.resolve('typescript/package.json');
22
+ const pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf8'));
23
+ const binRel = typeof pkg.bin === 'string' ? pkg.bin : pkg.bin?.tsc;
24
+ if (binRel) {
25
+ return path.resolve(path.dirname(pkgFile), binRel);
26
+ }
27
+ } catch {
28
+ // Try next candidate
29
+ }
30
+ }
31
+ return null;
32
+ }
33
+
34
+ const tscBin = findTsc();
35
+ if (tscBin) {
36
+ const res = spawnSync(process.execPath, [tscBin, '--project', path.join(root, 'tsconfig.json'), '--noEmit'], {
37
+ cwd: root,
38
+ stdio: 'inherit'
39
+ });
40
+ if (res.error) throw res.error;
41
+ process.exitCode = res.status ?? 1;
42
+ } else {
43
+ // Verify all declared .d.ts files exist and match package.json exports
44
+ const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
45
+ for (const [subpath, entry] of Object.entries(pkg.exports)) {
46
+ if (typeof entry === 'object' && entry !== null && entry.types) {
47
+ const resolved = path.resolve(root, entry.types);
48
+ if (!fs.existsSync(resolved)) {
49
+ console.error(`Missing declaration file for export "${subpath}": ${entry.types}`);
50
+ process.exitCode = 1;
51
+ }
52
+ }
53
+ }
54
+ if (!process.exitCode) {
55
+ console.log('Verified all package.json TypeScript declaration entrypoints exist.');
56
+ }
57
+ }
@@ -0,0 +1,37 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import type z from '@deepseek-ai/schemastery';
3
+
4
+ export interface CompositeToolsOptions {
5
+ enabled?: boolean;
6
+ readBatch?: boolean;
7
+ editBatch?: boolean;
8
+ maxBatchFiles?: number;
9
+ maxBatchEdits?: number;
10
+ defaultLimitPerFile?: number;
11
+ }
12
+
13
+ export interface CompositeToolsStats {
14
+ batchesExecuted: number;
15
+ filesRequested: number;
16
+ filesSucceeded: number;
17
+ filesFailed: number;
18
+ editBatchesExecuted: number;
19
+ editsRequested: number;
20
+ editsSucceeded: number;
21
+ editsFailed: number;
22
+ }
23
+
24
+ export interface CompositeToolsService {
25
+ getStats(session: unknown): CompositeToolsStats;
26
+ }
27
+
28
+ export declare const READ_BATCH_TOOL: 'read_batch';
29
+ export declare const EDIT_BATCH_TOOL: 'edit_batch';
30
+ export declare const CompositeToolsConfig: z<CompositeToolsOptions>;
31
+ export declare function applyCompositeTools(ctx: Context, rawConfig?: CompositeToolsOptions): CompositeToolsService | null;
32
+ export declare const name: string;
33
+ export declare const inject: string[];
34
+ export declare const Config: z<CompositeToolsOptions>;
35
+ export declare function apply(ctx: Context, config?: CompositeToolsOptions): void;
36
+ declare const plugin: { name: typeof name; inject: typeof inject; Config: typeof Config; apply: typeof apply };
37
+ export default plugin;