dsh-project-mcp 0.3.1 → 0.4.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 +38 -23
- package/lib/client.js +15 -15
- package/lib/client.js.map +1 -1
- package/lib/index.d.ts +98 -23
- package/lib/index.js +148 -46
- package/lib/index.js.map +1 -1
- package/package.json +18 -17
- package/src/activation.ts +164 -43
- package/src/client/locales/ui.ts +6 -6
- package/src/client/plugin-config.ts +9 -9
- package/src/runtime.ts +23 -7
package/lib/index.d.ts
CHANGED
|
@@ -964,12 +964,28 @@ interface SnapshotChange {
|
|
|
964
964
|
//#region src/activation.d.ts
|
|
965
965
|
/** `true` while the session may offer MCP tools through search + activation. */
|
|
966
966
|
export declare const DEFAULT_ACTIVATION_ENABLED = true;
|
|
967
|
-
/**
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
export declare const
|
|
967
|
+
/**
|
|
968
|
+
* Tools seeded into the baseline from the durable counters. A project with a
|
|
969
|
+
* few dozen mounted tools calls more than a handful of them, so the cap sits
|
|
970
|
+
* above the narrow window that used to evict a tool the project really uses.
|
|
971
|
+
*/
|
|
972
|
+
export declare const DEFAULT_ACTIVATION_SEEDED = 16;
|
|
973
|
+
/**
|
|
974
|
+
* Calls one tool needs in the counters before it is seeded. One call is enough:
|
|
975
|
+
* a tool the project actually uses enters the durable baseline the first time it
|
|
976
|
+
* is called, so the baseline grows from real usage instead of waiting for the
|
|
977
|
+
* counters to reach an arbitrary threshold.
|
|
978
|
+
*/
|
|
979
|
+
export declare const DEFAULT_ACTIVATION_MIN_CALLS = 1;
|
|
980
|
+
/**
|
|
981
|
+
* How long a session-activated tool survives without a call (`0` disables).
|
|
982
|
+
*
|
|
983
|
+
* The shipped `0` keeps a searched tool offered for the rest of the session:
|
|
984
|
+
* dropping it mid-session shrinks the request and rewrites the prompt prefix,
|
|
985
|
+
* which invalidates the provider's prefix cache, so time-based removal stays an
|
|
986
|
+
* explicit opt-in.
|
|
987
|
+
*/
|
|
988
|
+
export declare const DEFAULT_TOOL_IDLE_MS = 0;
|
|
973
989
|
/** Matches one `mcp_search_tools` call activates when it omits `limit`. */
|
|
974
990
|
export declare const DEFAULT_SEARCH_LIMIT = 8;
|
|
975
991
|
/** Hard cap on matches one `mcp_search_tools` call may activate. */
|
|
@@ -1083,20 +1099,35 @@ interface SessionEventLike {
|
|
|
1083
1099
|
* One session's activation state.
|
|
1084
1100
|
*
|
|
1085
1101
|
* `baseline` is the counter-seeded set and outlives a compaction; `active` holds
|
|
1086
|
-
* the names this session activated through search, each with
|
|
1087
|
-
* milliseconds of its last touch, and is what idle pruning and
|
|
1088
|
-
*
|
|
1102
|
+
* the names this session activated through search or the context tier, each with
|
|
1103
|
+
* the epoch milliseconds of its last touch, and is what idle pruning and
|
|
1104
|
+
* compaction trim. `used` records the calls the session made for this plugin's
|
|
1105
|
+
* own namespace — the evidence a compaction keeps an activation by, because a
|
|
1106
|
+
* tool the model called is one the session really uses. It is cumulative for the
|
|
1107
|
+
* session and never bounded, so the compaction boundary shrinks the offers no
|
|
1108
|
+
* call backs and never shrinks a used tool again.
|
|
1109
|
+
*
|
|
1110
|
+
* Every field is read-only because every transition returns a new state.
|
|
1089
1111
|
*/
|
|
1090
1112
|
interface ActivationState {
|
|
1091
1113
|
/** Public names the durable counters proved hot; always offered. */
|
|
1092
1114
|
readonly baseline: ReadonlySet<string>;
|
|
1093
1115
|
/** Session-activated public names mapped to their last touch. */
|
|
1094
1116
|
readonly active: ReadonlyMap<string, number>;
|
|
1117
|
+
/**
|
|
1118
|
+
* `mcp__` names this session called at least once and the durable baseline
|
|
1119
|
+
* does not already keep. Read by nothing but {@link onCompaction}, and
|
|
1120
|
+
* cumulative for the session: it is deliberately never bounded, so with the
|
|
1121
|
+
* shipped `DEFAULT_TOOL_IDLE_MS` of `0` nothing else removes a name and a tool
|
|
1122
|
+
* the session used stays offered for the rest of the session, across every
|
|
1123
|
+
* further compaction.
|
|
1124
|
+
*/
|
|
1125
|
+
readonly used: ReadonlySet<string>;
|
|
1095
1126
|
}
|
|
1096
1127
|
/**
|
|
1097
1128
|
* Build one session's state.
|
|
1098
1129
|
* @param baseline - counter-seeded public names; defaults to none.
|
|
1099
|
-
* @returns an empty active set over that baseline.
|
|
1130
|
+
* @returns an empty active set and an empty used record over that baseline.
|
|
1100
1131
|
*/
|
|
1101
1132
|
export declare function createActivationState(baseline?: Iterable<string>): ActivationState;
|
|
1102
1133
|
/** How {@link seedFromUsage} reads the durable counters. */
|
|
@@ -1134,9 +1165,16 @@ export declare function seedFromUsage(usage: Record<string, ServerUsage> | undef
|
|
|
1134
1165
|
*/
|
|
1135
1166
|
export declare function activate(state: ActivationState, names: Iterable<string>, at: number): ActivationState;
|
|
1136
1167
|
/**
|
|
1137
|
-
*
|
|
1138
|
-
* keeps
|
|
1139
|
-
*
|
|
1168
|
+
* Record a call — the freshness of a session-activated tool and the evidence a
|
|
1169
|
+
* compaction keeps it by.
|
|
1170
|
+
*
|
|
1171
|
+
* `active` is refreshed exactly as before: a call is what keeps a
|
|
1172
|
+
* session-activated tool offered. `used` records the call itself, but only for
|
|
1173
|
+
* this plugin's own namespace: the core tools (`read`, `bash`, …) ride the same
|
|
1174
|
+
* `tools/result` hook, and they are no part of a session's MCP activation state.
|
|
1175
|
+
* A baseline name is not recorded either — the durable baseline already keeps it
|
|
1176
|
+
* offered, so recording the call would only make a compaction look like it
|
|
1177
|
+
* changed something.
|
|
1140
1178
|
*
|
|
1141
1179
|
* @param state - activation state before the call.
|
|
1142
1180
|
* @param name - public name of the called tool.
|
|
@@ -1149,6 +1187,13 @@ export declare function noteUse(state: ActivationState, name: string, at: number
|
|
|
1149
1187
|
* The baseline is never pruned: it comes from the durable counters, not from the
|
|
1150
1188
|
* session. `idleMs <= 0` disables pruning.
|
|
1151
1189
|
*
|
|
1190
|
+
* A positive `idleMs` is an explicit opt-in to *forgetting*: an evicted name
|
|
1191
|
+
* leaves the used record with the offer it was about, so the sweep is final —
|
|
1192
|
+
* a later compaction cannot read the call back and resurrect what time already
|
|
1193
|
+
* dropped. A name the model needs again is activated again through search. The
|
|
1194
|
+
* names still inside the window keep their record, and a sweep that evicts
|
|
1195
|
+
* nothing returns its input.
|
|
1196
|
+
*
|
|
1152
1197
|
* @param state - activation state at `now`.
|
|
1153
1198
|
* @param now - epoch milliseconds of the sweep.
|
|
1154
1199
|
* @param idleMs - age at which a tool falls out.
|
|
@@ -1156,12 +1201,31 @@ export declare function noteUse(state: ActivationState, name: string, at: number
|
|
|
1156
1201
|
*/
|
|
1157
1202
|
export declare function pruneIdle(state: ActivationState, now: number, idleMs: number): ActivationState;
|
|
1158
1203
|
/**
|
|
1159
|
-
* End the session's activations
|
|
1160
|
-
*
|
|
1204
|
+
* End the session's activations that no call backs, at the compaction boundary.
|
|
1205
|
+
*
|
|
1206
|
+
* A compaction rewrites the conversation, so the provider's prompt prefix is
|
|
1207
|
+
* recomputed anyway: this is the one boundary where dropping a tool costs no
|
|
1208
|
+
* cache, which is why idle time is off by default and why this is the only place
|
|
1209
|
+
* the offered set shrinks. Only the part the session never used goes — an offer
|
|
1210
|
+
* from a context match or a search that the model did not act on. A tool this
|
|
1211
|
+
* session did call is one it really uses, so it stays active, stamped with its
|
|
1212
|
+
* last touch; evicting it would charge a re-discovery step for a tool the
|
|
1213
|
+
* session demonstrably needs. A used name that was never activated falls back to
|
|
1214
|
+
* the compaction's own clock. The counter baseline is never pruned.
|
|
1215
|
+
*
|
|
1216
|
+
* The used record is cumulative for the session and deliberately never bounded:
|
|
1217
|
+
* with the shipped `DEFAULT_TOOL_IDLE_MS` of `0` nothing else removes a name, so
|
|
1218
|
+
* a tool the session used stays offered for the rest of the session, across every
|
|
1219
|
+
* further compaction. This boundary shrinks the offers no call backs — it never
|
|
1220
|
+
* shrinks one the session used again.
|
|
1221
|
+
*
|
|
1161
1222
|
* @param state - activation state before the compaction.
|
|
1162
|
-
* @
|
|
1223
|
+
* @param at - epoch milliseconds of the compaction.
|
|
1224
|
+
* @returns the updated state, or the input when nothing was active or used, or
|
|
1225
|
+
* when the rebuild is equivalent to what is already there — a caller compares
|
|
1226
|
+
* by identity to tell a real change from a boundary that changed nothing.
|
|
1163
1227
|
*/
|
|
1164
|
-
export declare function onCompaction(state: ActivationState): ActivationState;
|
|
1228
|
+
export declare function onCompaction(state: ActivationState, at: number): ActivationState;
|
|
1165
1229
|
/**
|
|
1166
1230
|
* Every name this session currently offers: the baseline plus the session's own
|
|
1167
1231
|
* activations.
|
|
@@ -1288,10 +1352,10 @@ interface ActivationWiringOptions {
|
|
|
1288
1352
|
*/
|
|
1289
1353
|
readonly onActivated?: (names: readonly string[], step: number) => void;
|
|
1290
1354
|
/**
|
|
1291
|
-
* Told that a compaction ended the session's activations, so the
|
|
1292
|
-
* drop the step records that
|
|
1293
|
-
* place, which only means a later activation of
|
|
1294
|
-
* step of the offer the compaction removed.
|
|
1355
|
+
* Told that a compaction ended some of the session's activations, so the
|
|
1356
|
+
* caller can drop the step records that belonged to the ones it removed.
|
|
1357
|
+
* Absent leaves the records in place, which only means a later activation of
|
|
1358
|
+
* the same name may carry the step of the offer the compaction removed.
|
|
1295
1359
|
*/
|
|
1296
1360
|
readonly onCompaction?: () => void;
|
|
1297
1361
|
/** Context-driven state to start from; defaults to an empty state. */
|
|
@@ -2657,14 +2721,25 @@ export declare class ProjectMcpRuntime {
|
|
|
2657
2721
|
*/
|
|
2658
2722
|
private guidanceText;
|
|
2659
2723
|
/**
|
|
2660
|
-
*
|
|
2661
|
-
*
|
|
2724
|
+
* Record a call against the session's activation state: it refreshes the
|
|
2725
|
+
* freshness of a session-activated tool, and it is the evidence a later
|
|
2726
|
+
* compaction keeps that activation by. It rides the same `tools/result`
|
|
2727
|
+
* subscription the counters use, so no second observer exists.
|
|
2662
2728
|
* @param agentId - calling agent, when the call was agent-scoped.
|
|
2663
2729
|
* @param toolName - public registry name of the call.
|
|
2664
2730
|
*/
|
|
2665
2731
|
noteToolUse(agentId: string | undefined, toolName: string): void;
|
|
2666
2732
|
/** Drop the session-activated tools that outlived `toolIdleMs` without a call. */
|
|
2667
2733
|
private pruneActivation;
|
|
2734
|
+
/**
|
|
2735
|
+
* Drop the step records whose activation the session no longer holds.
|
|
2736
|
+
*
|
|
2737
|
+
* Called wherever activations end — the idle sweep and a compaction — so a
|
|
2738
|
+
* record never outlives the offer it was made for, and a name the session
|
|
2739
|
+
* still offers keeps the step its offer happened on.
|
|
2740
|
+
* @param state - the session whose records are reconciled.
|
|
2741
|
+
*/
|
|
2742
|
+
private pruneStepRecords;
|
|
2668
2743
|
private unmount;
|
|
2669
2744
|
/**
|
|
2670
2745
|
* The line that closes a mount's life, the pair of the `mounting` line.
|
package/lib/index.js
CHANGED
|
@@ -21,17 +21,20 @@ const DEFAULT_TOOL_POLICY = {
|
|
|
21
21
|
* every tool the project owns. This module keeps the *presentation* list small
|
|
22
22
|
* without touching the registry:
|
|
23
23
|
*
|
|
24
|
-
* - the usage counters seed a **baseline** of tools the project
|
|
25
|
-
* ({@link seedFromUsage}) — they are offered directly from
|
|
24
|
+
* - the usage counters seed a **baseline** of tools the project has called — one
|
|
25
|
+
* call is enough ({@link seedFromUsage}) — and they are offered directly from
|
|
26
|
+
* the first step on;
|
|
26
27
|
* - the newest task text ranks the project's mounted tools with BM25, and the
|
|
27
28
|
* best matches are offered through a **sticky window** that holds one offered
|
|
28
|
-
* set across
|
|
29
|
+
* set across the session's steps ({@link advanceAutoOffer});
|
|
29
30
|
* - the rest are discovered through the `mcp_search_tools` tool this module
|
|
30
31
|
* registers in the agent scope, which **activates** the matches for the next
|
|
31
32
|
* step ({@link activate});
|
|
32
|
-
* - a
|
|
33
|
-
*
|
|
34
|
-
* ({@link onCompaction});
|
|
33
|
+
* - a compaction ends the session's activations that no call backs, while the
|
|
34
|
+
* ones the model really called and the counter baseline stay
|
|
35
|
+
* ({@link onCompaction}); idle pruning ({@link pruneIdle}) stays available
|
|
36
|
+
* through a positive `toolIdleMs`, and the shipped `0` leaves it off, so the
|
|
37
|
+
* compaction boundary is the one place that shrinks the offered set;
|
|
35
38
|
* - the agent's own `system-prompt/assemble` listener puts the active schemas
|
|
36
39
|
* back into the assembled request ({@link withActiveTools}).
|
|
37
40
|
*
|
|
@@ -50,12 +53,28 @@ const DEFAULT_TOOL_POLICY = {
|
|
|
50
53
|
*/
|
|
51
54
|
/** `true` while the session may offer MCP tools through search + activation. */
|
|
52
55
|
const DEFAULT_ACTIVATION_ENABLED = true;
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
56
|
+
/**
|
|
57
|
+
* Tools seeded into the baseline from the durable counters. A project with a
|
|
58
|
+
* few dozen mounted tools calls more than a handful of them, so the cap sits
|
|
59
|
+
* above the narrow window that used to evict a tool the project really uses.
|
|
60
|
+
*/
|
|
61
|
+
const DEFAULT_ACTIVATION_SEEDED = 16;
|
|
62
|
+
/**
|
|
63
|
+
* Calls one tool needs in the counters before it is seeded. One call is enough:
|
|
64
|
+
* a tool the project actually uses enters the durable baseline the first time it
|
|
65
|
+
* is called, so the baseline grows from real usage instead of waiting for the
|
|
66
|
+
* counters to reach an arbitrary threshold.
|
|
67
|
+
*/
|
|
68
|
+
const DEFAULT_ACTIVATION_MIN_CALLS = 1;
|
|
69
|
+
/**
|
|
70
|
+
* How long a session-activated tool survives without a call (`0` disables).
|
|
71
|
+
*
|
|
72
|
+
* The shipped `0` keeps a searched tool offered for the rest of the session:
|
|
73
|
+
* dropping it mid-session shrinks the request and rewrites the prompt prefix,
|
|
74
|
+
* which invalidates the provider's prefix cache, so time-based removal stays an
|
|
75
|
+
* explicit opt-in.
|
|
76
|
+
*/
|
|
77
|
+
const DEFAULT_TOOL_IDLE_MS = 0;
|
|
59
78
|
/** Matches one `mcp_search_tools` call activates when it omits `limit`. */
|
|
60
79
|
const DEFAULT_SEARCH_LIMIT = 8;
|
|
61
80
|
/** Hard cap on matches one `mcp_search_tools` call may activate. */
|
|
@@ -70,6 +89,8 @@ const MAX_SEARCH_TOKENS = 8;
|
|
|
70
89
|
const SEARCH_TOOL_NAME = "mcp_search_tools";
|
|
71
90
|
/** Empty foreign set: what the containment reads when nothing is wired or foreign. */
|
|
72
91
|
const NO_FOREIGN = /* @__PURE__ */ new Set();
|
|
92
|
+
/** Hard cap on the sticky window, however the config asks for more. */
|
|
93
|
+
const MAX_AUTO_ACTIVATION_STICKY_STEPS = 1e3;
|
|
73
94
|
/**
|
|
74
95
|
* Serialized size of the MCP surface a session may offer directly before this
|
|
75
96
|
* module defers anything, in characters. Roughly four characters per token, so
|
|
@@ -95,12 +116,13 @@ const MAX_AUTO_QUERY_CHARS = 2e3;
|
|
|
95
116
|
/**
|
|
96
117
|
* Build one session's state.
|
|
97
118
|
* @param baseline - counter-seeded public names; defaults to none.
|
|
98
|
-
* @returns an empty active set over that baseline.
|
|
119
|
+
* @returns an empty active set and an empty used record over that baseline.
|
|
99
120
|
*/
|
|
100
121
|
function createActivationState(baseline = []) {
|
|
101
122
|
return {
|
|
102
123
|
baseline: new Set(baseline),
|
|
103
|
-
active: /* @__PURE__ */ new Map()
|
|
124
|
+
active: /* @__PURE__ */ new Map(),
|
|
125
|
+
used: /* @__PURE__ */ new Set()
|
|
104
126
|
};
|
|
105
127
|
}
|
|
106
128
|
/**
|
|
@@ -153,13 +175,21 @@ function activate(state, names, at) {
|
|
|
153
175
|
}
|
|
154
176
|
return active === void 0 ? state : {
|
|
155
177
|
baseline: state.baseline,
|
|
156
|
-
active
|
|
178
|
+
active,
|
|
179
|
+
used: state.used
|
|
157
180
|
};
|
|
158
181
|
}
|
|
159
182
|
/**
|
|
160
|
-
*
|
|
161
|
-
* keeps
|
|
162
|
-
*
|
|
183
|
+
* Record a call — the freshness of a session-activated tool and the evidence a
|
|
184
|
+
* compaction keeps it by.
|
|
185
|
+
*
|
|
186
|
+
* `active` is refreshed exactly as before: a call is what keeps a
|
|
187
|
+
* session-activated tool offered. `used` records the call itself, but only for
|
|
188
|
+
* this plugin's own namespace: the core tools (`read`, `bash`, …) ride the same
|
|
189
|
+
* `tools/result` hook, and they are no part of a session's MCP activation state.
|
|
190
|
+
* A baseline name is not recorded either — the durable baseline already keeps it
|
|
191
|
+
* offered, so recording the call would only make a compaction look like it
|
|
192
|
+
* changed something.
|
|
163
193
|
*
|
|
164
194
|
* @param state - activation state before the call.
|
|
165
195
|
* @param name - public name of the called tool.
|
|
@@ -168,12 +198,18 @@ function activate(state, names, at) {
|
|
|
168
198
|
*/
|
|
169
199
|
function noteUse(state, name, at) {
|
|
170
200
|
const previous = state.active.get(name);
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
|
|
201
|
+
const refresh = previous !== void 0 && previous !== at;
|
|
202
|
+
const already = state.used?.has(name) === true;
|
|
203
|
+
const record = name.startsWith("mcp__") && !state.baseline.has(name) && !already;
|
|
204
|
+
if (!refresh && !record) return state;
|
|
205
|
+
const active = refresh ? new Map(state.active) : void 0;
|
|
206
|
+
active?.set(name, at);
|
|
207
|
+
const used = record ? new Set(state.used ?? []) : void 0;
|
|
208
|
+
used?.add(name);
|
|
174
209
|
return {
|
|
175
210
|
baseline: state.baseline,
|
|
176
|
-
active
|
|
211
|
+
active: active ?? state.active,
|
|
212
|
+
used: used ?? state.used ?? /* @__PURE__ */ new Set()
|
|
177
213
|
};
|
|
178
214
|
}
|
|
179
215
|
/**
|
|
@@ -181,6 +217,13 @@ function noteUse(state, name, at) {
|
|
|
181
217
|
* The baseline is never pruned: it comes from the durable counters, not from the
|
|
182
218
|
* session. `idleMs <= 0` disables pruning.
|
|
183
219
|
*
|
|
220
|
+
* A positive `idleMs` is an explicit opt-in to *forgetting*: an evicted name
|
|
221
|
+
* leaves the used record with the offer it was about, so the sweep is final —
|
|
222
|
+
* a later compaction cannot read the call back and resurrect what time already
|
|
223
|
+
* dropped. A name the model needs again is activated again through search. The
|
|
224
|
+
* names still inside the window keep their record, and a sweep that evicts
|
|
225
|
+
* nothing returns its input.
|
|
226
|
+
*
|
|
184
227
|
* @param state - activation state at `now`.
|
|
185
228
|
* @param now - epoch milliseconds of the sweep.
|
|
186
229
|
* @param idleMs - age at which a tool falls out.
|
|
@@ -189,27 +232,63 @@ function noteUse(state, name, at) {
|
|
|
189
232
|
function pruneIdle(state, now, idleMs) {
|
|
190
233
|
if (idleMs <= 0 || state.active.size === 0) return state;
|
|
191
234
|
let active;
|
|
235
|
+
let used;
|
|
192
236
|
for (const [name, at] of state.active) {
|
|
193
237
|
if (now - at < idleMs) continue;
|
|
194
238
|
active ??= new Map(state.active);
|
|
195
239
|
active.delete(name);
|
|
240
|
+
if (state.used?.has(name) !== true) continue;
|
|
241
|
+
used ??= new Set(state.used ?? []);
|
|
242
|
+
used.delete(name);
|
|
196
243
|
}
|
|
197
244
|
return active === void 0 ? state : {
|
|
198
245
|
baseline: state.baseline,
|
|
199
|
-
active
|
|
246
|
+
active,
|
|
247
|
+
used: used ?? state.used ?? /* @__PURE__ */ new Set()
|
|
200
248
|
};
|
|
201
249
|
}
|
|
202
250
|
/**
|
|
203
|
-
* End the session's activations
|
|
204
|
-
*
|
|
251
|
+
* End the session's activations that no call backs, at the compaction boundary.
|
|
252
|
+
*
|
|
253
|
+
* A compaction rewrites the conversation, so the provider's prompt prefix is
|
|
254
|
+
* recomputed anyway: this is the one boundary where dropping a tool costs no
|
|
255
|
+
* cache, which is why idle time is off by default and why this is the only place
|
|
256
|
+
* the offered set shrinks. Only the part the session never used goes — an offer
|
|
257
|
+
* from a context match or a search that the model did not act on. A tool this
|
|
258
|
+
* session did call is one it really uses, so it stays active, stamped with its
|
|
259
|
+
* last touch; evicting it would charge a re-discovery step for a tool the
|
|
260
|
+
* session demonstrably needs. A used name that was never activated falls back to
|
|
261
|
+
* the compaction's own clock. The counter baseline is never pruned.
|
|
262
|
+
*
|
|
263
|
+
* The used record is cumulative for the session and deliberately never bounded:
|
|
264
|
+
* with the shipped `DEFAULT_TOOL_IDLE_MS` of `0` nothing else removes a name, so
|
|
265
|
+
* a tool the session used stays offered for the rest of the session, across every
|
|
266
|
+
* further compaction. This boundary shrinks the offers no call backs — it never
|
|
267
|
+
* shrinks one the session used again.
|
|
268
|
+
*
|
|
205
269
|
* @param state - activation state before the compaction.
|
|
206
|
-
* @
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
270
|
+
* @param at - epoch milliseconds of the compaction.
|
|
271
|
+
* @returns the updated state, or the input when nothing was active or used, or
|
|
272
|
+
* when the rebuild is equivalent to what is already there — a caller compares
|
|
273
|
+
* by identity to tell a real change from a boundary that changed nothing.
|
|
274
|
+
*/
|
|
275
|
+
function onCompaction(state, at) {
|
|
276
|
+
const used = state.used ?? /* @__PURE__ */ new Set();
|
|
277
|
+
if (state.active.size === 0 && used.size === 0) return state;
|
|
278
|
+
const active = /* @__PURE__ */ new Map();
|
|
279
|
+
for (const name of used) active.set(name, state.active.get(name) ?? at);
|
|
280
|
+
if (active.size === state.active.size) {
|
|
281
|
+
let equivalent = true;
|
|
282
|
+
for (const [name, stamp] of active) if (state.active.get(name) !== stamp) {
|
|
283
|
+
equivalent = false;
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
if (equivalent) return state;
|
|
287
|
+
}
|
|
210
288
|
return {
|
|
211
289
|
baseline: state.baseline,
|
|
212
|
-
active
|
|
290
|
+
active,
|
|
291
|
+
used: state.used ?? /* @__PURE__ */ new Set()
|
|
213
292
|
};
|
|
214
293
|
}
|
|
215
294
|
/**
|
|
@@ -567,7 +646,18 @@ function autoOffers(state) {
|
|
|
567
646
|
entries.sort((left, right) => left.advance - right.advance || compareNames$1(left.name, right.name));
|
|
568
647
|
return entries.map((entry) => entry.name);
|
|
569
648
|
}
|
|
570
|
-
/**
|
|
649
|
+
/**
|
|
650
|
+
* Whether two context-driven states offer the same names.
|
|
651
|
+
*
|
|
652
|
+
* Only the presented names are compared, never the advance stamp and never the
|
|
653
|
+
* per-name window stamps, so an advance that changes nothing hands back the
|
|
654
|
+
* previous state without ticking the advance counter: the sticky window ages by
|
|
655
|
+
* changes of the offered set, not by input count. This was reviewed as a
|
|
656
|
+
* possible stickiness off-by-one and cannot produce a wrong offered set — a
|
|
657
|
+
* stall can only hold names the ranking has just chosen again, and it ends at
|
|
658
|
+
* the first advance whose set differs — so do not re-chase an age here before
|
|
659
|
+
* reading `advanceAutoOffer`.
|
|
660
|
+
*/
|
|
571
661
|
function sameAutoOffer(left, right) {
|
|
572
662
|
const leftNames = autoPresentedNames(left);
|
|
573
663
|
const rightNames = autoPresentedNames(right);
|
|
@@ -589,7 +679,7 @@ function autoOfferLimit(value) {
|
|
|
589
679
|
* @returns the effective extra advances; `0` keeps only the current advance.
|
|
590
680
|
*/
|
|
591
681
|
function autoOfferStickySteps(value) {
|
|
592
|
-
return Math.min(Math.max(value ??
|
|
682
|
+
return Math.min(Math.max(value ?? 100, 0), MAX_AUTO_ACTIVATION_STICKY_STEPS);
|
|
593
683
|
}
|
|
594
684
|
/**
|
|
595
685
|
* Derive what one session offers the model right now from its live state.
|
|
@@ -903,7 +993,7 @@ function installActivation(options) {
|
|
|
903
993
|
const observe = (_session, event) => {
|
|
904
994
|
try {
|
|
905
995
|
if (event?.type === "compaction/end") {
|
|
906
|
-
options.setState(onCompaction(options.state()));
|
|
996
|
+
options.setState(onCompaction(options.state(), Date.now()));
|
|
907
997
|
options.onCompaction?.();
|
|
908
998
|
tracker.state = resetAutoOffer(tracker.state);
|
|
909
999
|
tracker.calls = [];
|
|
@@ -5505,7 +5595,7 @@ var ProjectMcpRuntime = class {
|
|
|
5505
5595
|
for (const name of names) state.steps.set(name, step);
|
|
5506
5596
|
},
|
|
5507
5597
|
onCompaction: () => {
|
|
5508
|
-
|
|
5598
|
+
this.pruneStepRecords(state);
|
|
5509
5599
|
},
|
|
5510
5600
|
autoState: state.auto ?? createAutoOfferState(),
|
|
5511
5601
|
setAutoState: (next) => {
|
|
@@ -5532,8 +5622,8 @@ var ProjectMcpRuntime = class {
|
|
|
5532
5622
|
if (existing !== void 0) return existing;
|
|
5533
5623
|
const projectRoot = state.projectRoot;
|
|
5534
5624
|
const seeded = createActivationState(seedFromUsage(projectRoot === void 0 ? void 0 : this.options.usage?.forProject(projectRoot), {
|
|
5535
|
-
count: this.config.activationSeeded ??
|
|
5536
|
-
minCalls: this.config.activationMinCalls ??
|
|
5625
|
+
count: this.config.activationSeeded ?? 16,
|
|
5626
|
+
minCalls: this.config.activationMinCalls ?? 1
|
|
5537
5627
|
}));
|
|
5538
5628
|
state.activation = seeded;
|
|
5539
5629
|
return seeded;
|
|
@@ -5698,8 +5788,10 @@ var ProjectMcpRuntime = class {
|
|
|
5698
5788
|
}
|
|
5699
5789
|
}
|
|
5700
5790
|
/**
|
|
5701
|
-
*
|
|
5702
|
-
*
|
|
5791
|
+
* Record a call against the session's activation state: it refreshes the
|
|
5792
|
+
* freshness of a session-activated tool, and it is the evidence a later
|
|
5793
|
+
* compaction keeps that activation by. It rides the same `tools/result`
|
|
5794
|
+
* subscription the counters use, so no second observer exists.
|
|
5703
5795
|
* @param agentId - calling agent, when the call was agent-scoped.
|
|
5704
5796
|
* @param toolName - public registry name of the call.
|
|
5705
5797
|
*/
|
|
@@ -5713,10 +5805,20 @@ var ProjectMcpRuntime = class {
|
|
|
5713
5805
|
pruneActivation(state) {
|
|
5714
5806
|
const current = state.activation;
|
|
5715
5807
|
if (current === void 0) return;
|
|
5716
|
-
state.activation = pruneIdle(current, Date.now(), this.config.toolIdleMs ??
|
|
5717
|
-
if (state.activation !== current)
|
|
5718
|
-
|
|
5719
|
-
|
|
5808
|
+
state.activation = pruneIdle(current, Date.now(), this.config.toolIdleMs ?? 0);
|
|
5809
|
+
if (state.activation !== current) this.pruneStepRecords(state);
|
|
5810
|
+
}
|
|
5811
|
+
/**
|
|
5812
|
+
* Drop the step records whose activation the session no longer holds.
|
|
5813
|
+
*
|
|
5814
|
+
* Called wherever activations end — the idle sweep and a compaction — so a
|
|
5815
|
+
* record never outlives the offer it was made for, and a name the session
|
|
5816
|
+
* still offers keeps the step its offer happened on.
|
|
5817
|
+
* @param state - the session whose records are reconciled.
|
|
5818
|
+
*/
|
|
5819
|
+
pruneStepRecords(state) {
|
|
5820
|
+
const active = state.activation?.active;
|
|
5821
|
+
for (const name of [...state.steps.keys()]) if (active === void 0 || !active.has(name)) state.steps.delete(name);
|
|
5720
5822
|
}
|
|
5721
5823
|
async unmount(home, name, reason) {
|
|
5722
5824
|
const mount = home.mounts.get(name);
|
|
@@ -7230,12 +7332,12 @@ const DEFAULTS = {
|
|
|
7230
7332
|
debounceMs: 300,
|
|
7231
7333
|
rescanIntervalMs: 1e4,
|
|
7232
7334
|
activationEnabled: true,
|
|
7233
|
-
activationSeeded:
|
|
7234
|
-
activationMinCalls:
|
|
7235
|
-
toolIdleMs:
|
|
7335
|
+
activationSeeded: 16,
|
|
7336
|
+
activationMinCalls: 1,
|
|
7337
|
+
toolIdleMs: 0,
|
|
7236
7338
|
guidanceEnabled: true,
|
|
7237
7339
|
activationAutoLimit: 12,
|
|
7238
|
-
activationAutoStickySteps:
|
|
7340
|
+
activationAutoStickySteps: 100,
|
|
7239
7341
|
activationToolBudgetChars: DEFAULT_TOOL_BUDGET_CHARS,
|
|
7240
7342
|
allowGlobalWrite: false
|
|
7241
7343
|
};
|