@dsh-cc/compaction-cost-gate 0.8.0-rc.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 +201 -0
- package/README.i18n.yaml +6 -0
- package/README.md +46 -0
- package/README.zh.md +46 -0
- package/lib/fold-counters.d.ts +33 -0
- package/lib/fold-counters.d.ts.map +1 -0
- package/lib/fold-counters.js +62 -0
- package/lib/fold-counters.js.map +1 -0
- package/lib/gate.d.ts +15 -0
- package/lib/gate.d.ts.map +1 -0
- package/lib/gate.js +60 -0
- package/lib/gate.js.map +1 -0
- package/lib/index.d.ts +124 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +368 -0
- package/lib/index.js.map +1 -0
- package/lib/invariant.d.ts +16 -0
- package/lib/invariant.d.ts.map +1 -0
- package/lib/invariant.js +24 -0
- package/lib/invariant.js.map +1 -0
- package/lib/ledger.d.ts +60 -0
- package/lib/ledger.d.ts.map +1 -0
- package/lib/ledger.js +55 -0
- package/lib/ledger.js.map +1 -0
- package/lib/settings.d.ts +26 -0
- package/lib/settings.d.ts.map +1 -0
- package/lib/settings.js +57 -0
- package/lib/settings.js.map +1 -0
- package/lib/todo-diff.d.ts +29 -0
- package/lib/todo-diff.d.ts.map +1 -0
- package/lib/todo-diff.js +40 -0
- package/lib/todo-diff.js.map +1 -0
- package/lib/types.d.ts +103 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +13 -0
- package/lib/types.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAIxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAG3D,8DAA8D;AAC9D,MAAM,CAAC,MAAM,kBAAkB,GAAG,yBAA8C,CAAA;AAEhF,MAAM,C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,aAAa,CAAC,KAAK,QAAQ;gBAChD,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC;gBACpB,CAAC,CAAC,gBAAgB,CAAC,UAAU;YAC/B,GAAG,CAAC,OAAO,GAAG,CAAC,wBAAwB,CAAC,KAAK,QAAQ;gBACnD,CAAC,CAAC,EAAE,oBAAoB,EAAE,GAAG,CAAC,wBAAwB,CAAW,EAAE;gBACnE,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;gBACnC,CAAC,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,aAAa,CAAiB,EAAE;gBACpD,CAAC,CAAC,EAAE,CAAC;SACR,CAAA;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure `todo_write` snapshot differ. Detection-side only: on any transition
|
|
3
|
+
* of a todo to `completed` (against the previous snapshot) the boundary arms.
|
|
4
|
+
* Identity is the todo's `content` string — the content hash — so rewrites,
|
|
5
|
+
* reorders, and status-only churn are distinguished correctly.
|
|
6
|
+
* @module @dsh-cc/compaction-cost-gate/todo-diff
|
|
7
|
+
*/
|
|
8
|
+
import type { TodoItem } from './types.ts';
|
|
9
|
+
/** Result of diffing one `todo_write` arguments array against the previous snapshot. */
|
|
10
|
+
export interface TodoDiff {
|
|
11
|
+
/** True when at least one todo newly transitioned to completed. */
|
|
12
|
+
readonly armed: boolean;
|
|
13
|
+
/** Content of the newly completed todos, in snapshot order. */
|
|
14
|
+
readonly newlyCompleted: readonly string[];
|
|
15
|
+
/** Cumulative completed count after applying this snapshot. */
|
|
16
|
+
readonly completedSteps: number;
|
|
17
|
+
/** Non-completed todo count after applying this snapshot. */
|
|
18
|
+
readonly pendingSteps: number;
|
|
19
|
+
/** The new content → status snapshot to store. */
|
|
20
|
+
readonly snapshot: ReadonlyMap<string, string>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Diff one new todos array against the previous snapshot.
|
|
24
|
+
* @param prev - the stored content → status map (empty on cold start).
|
|
25
|
+
* @param todos - the parsed `todos` array from the tool arguments.
|
|
26
|
+
* @returns the arm decision, counts, and the snapshot to persist in state.
|
|
27
|
+
*/
|
|
28
|
+
export declare function diffTodos(prev: ReadonlyMap<string, string>, todos: readonly TodoItem[]): TodoDiff;
|
|
29
|
+
//# sourceMappingURL=todo-diff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"todo-diff.d.ts","sourceRoot":"","sources":["../src/todo-diff.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C,wFAAwF;AACxF,MAAM,WAAW,QAAQ;IACvB,mEAAmE;IACnE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;IACvB,+DAA+D;IAC/D,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAA;IAC1C,+DAA+D;IAC/D,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,6DAA6D;IAC7D,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,kDAAkD;IAClD,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/C;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EACjC,KAAK,EAAE,SAAS,QAAQ,EAAE,GACzB,QAAQ,CAsBV"}
|
package/lib/todo-diff.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure `todo_write` snapshot differ. Detection-side only: on any transition
|
|
3
|
+
* of a todo to `completed` (against the previous snapshot) the boundary arms.
|
|
4
|
+
* Identity is the todo's `content` string — the content hash — so rewrites,
|
|
5
|
+
* reorders, and status-only churn are distinguished correctly.
|
|
6
|
+
* @module @dsh-cc/compaction-cost-gate/todo-diff
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Diff one new todos array against the previous snapshot.
|
|
10
|
+
* @param prev - the stored content → status map (empty on cold start).
|
|
11
|
+
* @param todos - the parsed `todos` array from the tool arguments.
|
|
12
|
+
* @returns the arm decision, counts, and the snapshot to persist in state.
|
|
13
|
+
*/
|
|
14
|
+
export function diffTodos(prev, todos) {
|
|
15
|
+
const snapshot = new Map();
|
|
16
|
+
for (const todo of todos)
|
|
17
|
+
snapshot.set(todo.content, todo.status);
|
|
18
|
+
const newlyCompleted = [];
|
|
19
|
+
for (const todo of todos) {
|
|
20
|
+
if (todo.status === 'completed' && prev.get(todo.content) !== 'completed') {
|
|
21
|
+
newlyCompleted.push(todo.content);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
let completedSteps = 0;
|
|
25
|
+
let pendingSteps = 0;
|
|
26
|
+
for (const status of snapshot.values()) {
|
|
27
|
+
if (status === 'completed')
|
|
28
|
+
completedSteps += 1;
|
|
29
|
+
else
|
|
30
|
+
pendingSteps += 1;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
armed: newlyCompleted.length > 0,
|
|
34
|
+
newlyCompleted,
|
|
35
|
+
completedSteps,
|
|
36
|
+
pendingSteps,
|
|
37
|
+
snapshot,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=todo-diff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"todo-diff.js","sourceRoot":"","sources":["../src/todo-diff.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAkBH;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CACvB,IAAiC,EACjC,KAA0B;IAE1B,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAA;IAC1C,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IACjE,MAAM,cAAc,GAAa,EAAE,CAAA;IACnC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,MAAM,KAAK,WAAW,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,WAAW,EAAE,CAAC;YAC1E,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACnC,CAAC;IACH,CAAC;IACD,IAAI,cAAc,GAAG,CAAC,CAAA;IACtB,IAAI,YAAY,GAAG,CAAC,CAAA;IACpB,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;QACvC,IAAI,MAAM,KAAK,WAAW;YAAE,cAAc,IAAI,CAAC,CAAA;;YAC1C,YAAY,IAAI,CAAC,CAAA;IACxB,CAAC;IACD,OAAO;QACL,KAAK,EAAE,cAAc,CAAC,MAAM,GAAG,CAAC;QAChC,cAAc;QACd,cAAc;QACd,YAAY;QACZ,QAAQ;KACT,CAAA;AACH,CAAC"}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared state, config, and gate types for the cost-gated plan-step
|
|
3
|
+
* compaction service. Nothing here is durable: per-root-session stats live
|
|
4
|
+
* in memory only; the ledger is the sole on-disk record.
|
|
5
|
+
* @module @dsh-cc/compaction-cost-gate/types
|
|
6
|
+
*/
|
|
7
|
+
import type { ModelPrice } from '@dsh-cc/command-cost';
|
|
8
|
+
/** One todos-array entry as delivered in the `todo_write` tool arguments. */
|
|
9
|
+
export interface TodoItem {
|
|
10
|
+
/** Step text; content-hash identity for the snapshot differ. */
|
|
11
|
+
readonly content: string;
|
|
12
|
+
readonly status: 'pending' | 'in_progress' | 'completed';
|
|
13
|
+
}
|
|
14
|
+
/** In-memory per-root-session state (design §3.2). */
|
|
15
|
+
export interface SessionStats {
|
|
16
|
+
/** A todo completed since the last idle evaluation. */
|
|
17
|
+
boundaryArmed: boolean;
|
|
18
|
+
/** Main-loop provider requests observed for this session. */
|
|
19
|
+
streamRequestCount: number;
|
|
20
|
+
/** Todos transitioned to completed, cumulative. */
|
|
21
|
+
completedSteps: number;
|
|
22
|
+
/** Content hash → status of the latest todos snapshot. */
|
|
23
|
+
lastTodoSnapshot: Map<string, string>;
|
|
24
|
+
/** Unamortized rewrite debt from past compactions. */
|
|
25
|
+
rewriteDebt: {
|
|
26
|
+
tokens: number;
|
|
27
|
+
requestsSince: number;
|
|
28
|
+
}[];
|
|
29
|
+
/** Epoch ms until which the gate stays silent after a compaction. */
|
|
30
|
+
cooldownUntil: number;
|
|
31
|
+
/** Consecutive REAL defect-class failures (§3.5); busy/cancelled excluded. */
|
|
32
|
+
consecutiveFailures: number;
|
|
33
|
+
/** Pause latch after the failure fuse trips. */
|
|
34
|
+
paused: boolean;
|
|
35
|
+
/** Title of the todo whose completion armed the current boundary. */
|
|
36
|
+
lastCompletedTitle?: string;
|
|
37
|
+
/** Measured context reduction of the last compaction; undefined until measured. */
|
|
38
|
+
lastShrink?: number;
|
|
39
|
+
/** Context tokens observed immediately before the last fired compaction. */
|
|
40
|
+
preCompactContextTokens?: number;
|
|
41
|
+
/** Last observed provider/model route (main-loop requests only). */
|
|
42
|
+
lastProvider?: string;
|
|
43
|
+
lastModel?: string;
|
|
44
|
+
}
|
|
45
|
+
/** Resolved settings namespace value (`cc-compaction-cost-gate`). */
|
|
46
|
+
export interface CostGateSettings {
|
|
47
|
+
enabled: boolean;
|
|
48
|
+
mode: 'dry-run' | 'on';
|
|
49
|
+
margin: number;
|
|
50
|
+
cooldownMs: number;
|
|
51
|
+
windowPressureTokens?: number;
|
|
52
|
+
modelTable?: ModelPrice[];
|
|
53
|
+
}
|
|
54
|
+
/** Inputs of the pure gate arithmetic (§3.3). */
|
|
55
|
+
export interface GateInput {
|
|
56
|
+
/** Σ tokenMeter.estimateMessage over message-carrying surface nodes. */
|
|
57
|
+
contextTokens: number;
|
|
58
|
+
streamRequestCount: number;
|
|
59
|
+
completedSteps: number;
|
|
60
|
+
/** Non-completed todos in the latest snapshot; 0 never fires. */
|
|
61
|
+
pendingSteps: number;
|
|
62
|
+
/** Measured reduction of the last compaction; cold prior 0.5. */
|
|
63
|
+
lastShrink?: number;
|
|
64
|
+
/** Unamortized debt entries (tokens, requests seen since the compact). */
|
|
65
|
+
rewriteDebt: readonly {
|
|
66
|
+
tokens: number;
|
|
67
|
+
requestsSince: number;
|
|
68
|
+
}[];
|
|
69
|
+
/** Required savings multiple (default 1.0). */
|
|
70
|
+
margin: number;
|
|
71
|
+
/** When set, prices savings at the cache-read and rewrite at the cache-write rate. */
|
|
72
|
+
price?: {
|
|
73
|
+
cacheReadPerMTok: number;
|
|
74
|
+
cacheWritePerMTok: number;
|
|
75
|
+
};
|
|
76
|
+
/** Window-pressure bypass (cooldown and fuse are the caller's concern). */
|
|
77
|
+
windowPressureTokens?: number;
|
|
78
|
+
}
|
|
79
|
+
/** Outcome of the pure gate arithmetic. */
|
|
80
|
+
export interface GateOutcome {
|
|
81
|
+
pass: boolean;
|
|
82
|
+
/** Non-completed todos considered (0 forces pass=false). */
|
|
83
|
+
pendingSteps: number;
|
|
84
|
+
/** streamRequestCount / max(completedSteps, 1), floored at 1. */
|
|
85
|
+
requestsPerStep: number;
|
|
86
|
+
/** The shrink factor actually used (measured value or the 0.5 cold prior). */
|
|
87
|
+
shrink: number;
|
|
88
|
+
/** contextTokens × shrink × requestsPerStep × pendingSteps. */
|
|
89
|
+
projectedSavedInput: number;
|
|
90
|
+
/** Rewritten prefix (contextTokens) plus unamortized debt tokens. */
|
|
91
|
+
rewriteCost: number;
|
|
92
|
+
/** Sum of debt entries still inside the amortization window. */
|
|
93
|
+
debtTokens: number;
|
|
94
|
+
/** True when the window-pressure threshold bypassed the margin comparison. */
|
|
95
|
+
windowPressureOverride: boolean;
|
|
96
|
+
}
|
|
97
|
+
/** Compaction requests observed per root session (main-loop only). */
|
|
98
|
+
export declare const DEBT_AMORTIZE_REQUESTS = 5;
|
|
99
|
+
/** Default shrink prior before the first measured compaction. */
|
|
100
|
+
export declare const COLD_SHRINK_PRIOR = 0.5;
|
|
101
|
+
/** Consecutive real-failure threshold that pauses the feature per session. */
|
|
102
|
+
export declare const FAILURE_FUSE = 3;
|
|
103
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEtD,6EAA6E;AAC7E,MAAM,WAAW,QAAQ;IACvB,gEAAgE;IAChE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,aAAa,GAAG,WAAW,CAAA;CACzD;AAED,sDAAsD;AACtD,MAAM,WAAW,YAAY;IAC3B,uDAAuD;IACvD,aAAa,EAAE,OAAO,CAAA;IACtB,6DAA6D;IAC7D,kBAAkB,EAAE,MAAM,CAAA;IAC1B,mDAAmD;IACnD,cAAc,EAAE,MAAM,CAAA;IACtB,0DAA0D;IAC1D,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACrC,sDAAsD;IACtD,WAAW,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IACxD,qEAAqE;IACrE,aAAa,EAAE,MAAM,CAAA;IACrB,8EAA8E;IAC9E,mBAAmB,EAAE,MAAM,CAAA;IAC3B,gDAAgD;IAChD,MAAM,EAAE,OAAO,CAAA;IACf,qEAAqE;IACrE,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,mFAAmF;IACnF,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,4EAA4E;I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qEAAqE;IACrE,WAAW,EAAE,MAAM,CAAA;IACnB,gEAAgE;IAChE,UAAU,EAAE,MAAM,CAAA;IAClB,8EAA8E;IAC9E,sBAAsB,EAAE,OAAO,CAAA;CAChC;AAED,sEAAsE;AACtE,eAAO,MAAM,sBAAsB,IAAI,CAAA;AAEvC,iEAAiE;AACjE,eAAO,MAAM,iBAAiB,MAAM,CAAA;AAEpC,8EAA8E;AAC9E,eAAO,MAAM,YAAY,IAAI,CAAA"}
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared state, config, and gate types for the cost-gated plan-step
|
|
3
|
+
* compaction service. Nothing here is durable: per-root-session stats live
|
|
4
|
+
* in memory only; the ledger is the sole on-disk record.
|
|
5
|
+
* @module @dsh-cc/compaction-cost-gate/types
|
|
6
|
+
*/
|
|
7
|
+
/** Compaction requests observed per root session (main-loop only). */
|
|
8
|
+
export const DEBT_AMORTIZE_REQUESTS = 5;
|
|
9
|
+
/** Default shrink prior before the first measured compaction. */
|
|
10
|
+
export const COLD_SHRINK_PRIOR = 0.5;
|
|
11
|
+
/** Consecutive real-failure threshold that pauses the feature per session. */
|
|
12
|
+
export const FAILURE_FUSE = 3;
|
|
13
|
+
//# sourceMappingURL=types.js.map
|
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAyFH,sEAAsE;AACtE,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAA;AAEvC,iEAAiE;AACjE,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAA;AAEpC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dsh-cc/compaction-cost-gate",
|
|
3
|
+
"description": "Cost-gated plan-step compaction: fire compactNow at todo boundaries only when projected input-token savings beat the prompt-cache rewrite price plus unamortized debt",
|
|
4
|
+
"version": "0.8.0-rc.1",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/dsh-cc/dsh-cc.git",
|
|
8
|
+
"directory": "packages/compaction/compaction-cost-gate"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/index.d.ts",
|
|
14
|
+
"default": "./lib/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./invariant": {
|
|
17
|
+
"types": "./lib/invariant.d.ts",
|
|
18
|
+
"default": "./lib/invariant.js"
|
|
19
|
+
},
|
|
20
|
+
"./src/*": "./src/*",
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"lib"
|
|
25
|
+
],
|
|
26
|
+
"license": "Apache-2.0",
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@deepseek-ai/dsh-commands": ">=0.1.5-rc.1",
|
|
29
|
+
"@deepseek-ai/dsh-compaction": ">=0.1.5-rc.1",
|
|
30
|
+
"@deepseek-ai/dsh-invariants": ">=0.1.5-rc.1",
|
|
31
|
+
"@deepseek-ai/dsh-llm": ">=0.1.5-rc.1",
|
|
32
|
+
"@deepseek-ai/dsh-session": ">=0.1.5-rc.1",
|
|
33
|
+
"@deepseek-ai/dsh-token-meter": ">=0.1.5-rc.1",
|
|
34
|
+
"@deepseek-ai/cordis": ">=0.1.5-rc.1",
|
|
35
|
+
"@deepseek-ai/schemastery": "^3.18.1",
|
|
36
|
+
"@dsh-cc/compaction-basic": "^0.8.0-rc.1",
|
|
37
|
+
"@dsh-cc/command-cost": "^0.8.0-rc.1",
|
|
38
|
+
"@dsh-cc/settings-ns": "^0.8.0-rc.1"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@deepseek-ai/cordis": "link:../../../../deepseek-harness/vendor/cordis",
|
|
42
|
+
"@deepseek-ai/dsh-agent": "link:../../../../deepseek-harness/packages/core/agent",
|
|
43
|
+
"@deepseek-ai/dsh-agent-loop": "link:../../../../deepseek-harness/packages/core/agent-loop",
|
|
44
|
+
"@deepseek-ai/dsh-agent-loop-testkit": "link:../../../../deepseek-harness/packages/test-support/agent-loop-testkit",
|
|
45
|
+
"@deepseek-ai/cordis-plugin-include": "link:../../../../deepseek-harness/vendor/include",
|
|
46
|
+
"@deepseek-ai/cordis-plugin-loader": "link:../../../../deepseek-harness/vendor/loader",
|
|
47
|
+
"@deepseek-ai/dsh-commands": "link:../../../../deepseek-harness/packages/interaction/commands",
|
|
48
|
+
"@deepseek-ai/dsh-compaction": "link:../../../../deepseek-harness/packages/compaction/compaction",
|
|
49
|
+
"@deepseek-ai/dsh-invariants": "link:../../../../deepseek-harness/packages/runtime-diagnostics/invariants",
|
|
50
|
+
"@deepseek-ai/dsh-llm": "link:../../../../deepseek-harness/packages/llm/llm",
|
|
51
|
+
"@deepseek-ai/dsh-session": "link:../../../../deepseek-harness/packages/core/session",
|
|
52
|
+
"@deepseek-ai/dsh-subprocess-local": "link:../../../../deepseek-harness/packages/subprocess/subprocess-local",
|
|
53
|
+
"@deepseek-ai/dsh-settings": "link:../../../../deepseek-harness/packages/settings/settings",
|
|
54
|
+
"@deepseek-ai/schemastery": "link:../../../../deepseek-harness/vendor/schemastery",
|
|
55
|
+
"@deepseek-ai/dsh-token-meter": "link:../../../../deepseek-harness/packages/llm/token-meter",
|
|
56
|
+
"@dsh-cc/compaction-basic": "^0.8.0-rc.1",
|
|
57
|
+
"@dsh-cc/command-cost": "^0.8.0-rc.1",
|
|
58
|
+
"@dsh-cc/settings-ns": "^0.8.0-rc.1"
|
|
59
|
+
},
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public"
|
|
62
|
+
}
|
|
63
|
+
}
|