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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-project-mcp",
3
3
  "description": "Per-project MCP servers for DeepSeek Harness: mounts the MCP servers a project declares into the sessions working in it",
4
- "version": "0.3.1",
4
+ "version": "0.4.0",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -43,6 +43,22 @@
43
43
  "./cordis.patch.yml": "./cordis.patch.yml",
44
44
  "./package.json": "./package.json"
45
45
  },
46
+ "scripts": {
47
+ "build": "tsc -p tsconfig.json && tsdown && node scripts/wrap-client.mjs",
48
+ "prepack": "pnpm build",
49
+ "typecheck": "tsc -p tsconfig.json",
50
+ "test": "vitest run",
51
+ "coverage": "vitest run --coverage",
52
+ "e2e": "node scripts/e2e-boot.mjs",
53
+ "check": "tsc -p tsconfig.json && tsdown && node scripts/wrap-client.mjs && vitest run --coverage && node scripts/audit.mjs",
54
+ "smoke": "node scripts/live-smoke.mjs",
55
+ "design:parity": "node scripts/design-parity.mjs",
56
+ "test:bun": "bun test tests",
57
+ "smoke:bun": "bun scripts/live-smoke.mjs",
58
+ "audit": "node scripts/audit.mjs",
59
+ "audit:bun": "bun scripts/audit.mjs",
60
+ "check:config": "node scripts/check-config.mjs"
61
+ },
46
62
  "dsh": {
47
63
  "bundle": {
48
64
  "patch": "./cordis.patch.yml"
@@ -83,20 +99,5 @@
83
99
  "typescript": "^7.0.2",
84
100
  "unrun": "^0.3.1",
85
101
  "vitest": "^5.0.2"
86
- },
87
- "scripts": {
88
- "build": "tsc -p tsconfig.json && tsdown && node scripts/wrap-client.mjs",
89
- "typecheck": "tsc -p tsconfig.json",
90
- "test": "vitest run",
91
- "coverage": "vitest run --coverage",
92
- "e2e": "node scripts/e2e-boot.mjs",
93
- "check": "tsc -p tsconfig.json && tsdown && node scripts/wrap-client.mjs && vitest run --coverage && node scripts/audit.mjs",
94
- "smoke": "node scripts/live-smoke.mjs",
95
- "design:parity": "node scripts/design-parity.mjs",
96
- "test:bun": "bun test tests",
97
- "smoke:bun": "bun scripts/live-smoke.mjs",
98
- "audit": "node scripts/audit.mjs",
99
- "audit:bun": "bun scripts/audit.mjs",
100
- "check:config": "node scripts/check-config.mjs"
101
102
  }
102
- }
103
+ }
package/src/activation.ts CHANGED
@@ -5,17 +5,20 @@
5
5
  * every tool the project owns. This module keeps the *presentation* list small
6
6
  * without touching the registry:
7
7
  *
8
- * - the usage counters seed a **baseline** of tools the project actually calls
9
- * ({@link seedFromUsage}) — they are offered directly from the first step on;
8
+ * - the usage counters seed a **baseline** of tools the project has called — one
9
+ * call is enough ({@link seedFromUsage}) — and they are offered directly from
10
+ * the first step on;
10
11
  * - the newest task text ranks the project's mounted tools with BM25, and the
11
12
  * best matches are offered through a **sticky window** that holds one offered
12
- * set across several steps ({@link advanceAutoOffer});
13
+ * set across the session's steps ({@link advanceAutoOffer});
13
14
  * - the rest are discovered through the `mcp_search_tools` tool this module
14
15
  * registers in the agent scope, which **activates** the matches for the next
15
16
  * step ({@link activate});
16
- * - a tool that is never called falls out again ({@link pruneIdle}), and a
17
- * compaction ends the session's activations while the counter baseline stays
18
- * ({@link onCompaction});
17
+ * - a compaction ends the session's activations that no call backs, while the
18
+ * ones the model really called and the counter baseline stay
19
+ * ({@link onCompaction}); idle pruning ({@link pruneIdle}) stays available
20
+ * through a positive `toolIdleMs`, and the shipped `0` leaves it off, so the
21
+ * compaction boundary is the one place that shrinks the offered set;
19
22
  * - the agent's own `system-prompt/assemble` listener puts the active schemas
20
23
  * back into the assembled request ({@link withActiveTools}).
21
24
  *
@@ -39,14 +42,30 @@ import type { OfferedTool, ServerUsage, SessionTools, ToolPolicy } from './types
39
42
  /** `true` while the session may offer MCP tools through search + activation. */
40
43
  export const DEFAULT_ACTIVATION_ENABLED = true
41
44
 
42
- /** Tools seeded into the baseline from the durable counters. */
43
- export const DEFAULT_ACTIVATION_SEEDED = 8
45
+ /**
46
+ * Tools seeded into the baseline from the durable counters. A project with a
47
+ * few dozen mounted tools calls more than a handful of them, so the cap sits
48
+ * above the narrow window that used to evict a tool the project really uses.
49
+ */
50
+ export const DEFAULT_ACTIVATION_SEEDED = 16
44
51
 
45
- /** Calls one tool needs in the counters before it is seeded. */
46
- export const DEFAULT_ACTIVATION_MIN_CALLS = 5
52
+ /**
53
+ * Calls one tool needs in the counters before it is seeded. One call is enough:
54
+ * a tool the project actually uses enters the durable baseline the first time it
55
+ * is called, so the baseline grows from real usage instead of waiting for the
56
+ * counters to reach an arbitrary threshold.
57
+ */
58
+ export const DEFAULT_ACTIVATION_MIN_CALLS = 1
47
59
 
48
- /** How long a session-activated tool survives without a call (`0` disables). */
49
- export const DEFAULT_TOOL_IDLE_MS = 1_800_000
60
+ /**
61
+ * How long a session-activated tool survives without a call (`0` disables).
62
+ *
63
+ * The shipped `0` keeps a searched tool offered for the rest of the session:
64
+ * dropping it mid-session shrinks the request and rewrites the prompt prefix,
65
+ * which invalidates the provider's prefix cache, so time-based removal stays an
66
+ * explicit opt-in.
67
+ */
68
+ export const DEFAULT_TOOL_IDLE_MS = 0
50
69
 
51
70
  /** Matches one `mcp_search_tools` call activates when it omits `limit`. */
52
71
  export const DEFAULT_SEARCH_LIMIT = 8
@@ -80,11 +99,15 @@ export const MAX_AUTO_ACTIVATION_LIMIT = 50
80
99
  * Extra user messages a context-driven offer survives after the one that ranked
81
100
  * it; `0` keeps only that message. The offering set is recomputed when the task
82
101
  * context moves, so this is what holds one tool list across several steps.
102
+ *
103
+ * The shipped window spans a whole session: dropping an offer mid-session
104
+ * rewrites the prompt prefix and invalidates the provider's prefix cache, so the
105
+ * context tier grows and only resets at a compaction.
83
106
  */
84
- export const DEFAULT_AUTO_ACTIVATION_STICKY_STEPS = 2
107
+ export const DEFAULT_AUTO_ACTIVATION_STICKY_STEPS = 100
85
108
 
86
109
  /** Hard cap on the sticky window, however the config asks for more. */
87
- export const MAX_AUTO_ACTIVATION_STICKY_STEPS = 20
110
+ export const MAX_AUTO_ACTIVATION_STICKY_STEPS = 1000
88
111
 
89
112
  /**
90
113
  * Serialized size of the MCP surface a session may offer directly before this
@@ -241,24 +264,39 @@ export interface SessionEventLike {
241
264
  * One session's activation state.
242
265
  *
243
266
  * `baseline` is the counter-seeded set and outlives a compaction; `active` holds
244
- * the names this session activated through search, each with the epoch
245
- * milliseconds of its last touch, and is what idle pruning and compaction clear.
246
- * Both are read-only because every transition returns a new state.
267
+ * the names this session activated through search or the context tier, each with
268
+ * the epoch milliseconds of its last touch, and is what idle pruning and
269
+ * compaction trim. `used` records the calls the session made for this plugin's
270
+ * own namespace — the evidence a compaction keeps an activation by, because a
271
+ * tool the model called is one the session really uses. It is cumulative for the
272
+ * session and never bounded, so the compaction boundary shrinks the offers no
273
+ * call backs and never shrinks a used tool again.
274
+ *
275
+ * Every field is read-only because every transition returns a new state.
247
276
  */
248
277
  export interface ActivationState {
249
278
  /** Public names the durable counters proved hot; always offered. */
250
279
  readonly baseline: ReadonlySet<string>
251
280
  /** Session-activated public names mapped to their last touch. */
252
281
  readonly active: ReadonlyMap<string, number>
282
+ /**
283
+ * `mcp__` names this session called at least once and the durable baseline
284
+ * does not already keep. Read by nothing but {@link onCompaction}, and
285
+ * cumulative for the session: it is deliberately never bounded, so with the
286
+ * shipped `DEFAULT_TOOL_IDLE_MS` of `0` nothing else removes a name and a tool
287
+ * the session used stays offered for the rest of the session, across every
288
+ * further compaction.
289
+ */
290
+ readonly used: ReadonlySet<string>
253
291
  }
254
292
 
255
293
  /**
256
294
  * Build one session's state.
257
295
  * @param baseline - counter-seeded public names; defaults to none.
258
- * @returns an empty active set over that baseline.
296
+ * @returns an empty active set and an empty used record over that baseline.
259
297
  */
260
298
  export function createActivationState(baseline: Iterable<string> = []): ActivationState {
261
- return { baseline: new Set(baseline), active: new Map() }
299
+ return { baseline: new Set(baseline), active: new Map(), used: new Set() }
262
300
  }
263
301
 
264
302
  /** How {@link seedFromUsage} reads the durable counters. */
@@ -324,13 +362,20 @@ export function activate(
324
362
  active ??= new Map(state.active)
325
363
  active.set(name, at)
326
364
  }
327
- return active === undefined ? state : { baseline: state.baseline, active }
365
+ return active === undefined ? state : { baseline: state.baseline, active, used: state.used }
328
366
  }
329
367
 
330
368
  /**
331
- * Refresh the freshness of a tool the session actually called. A call is what
332
- * keeps a session-activated tool offered; a name that is not active (a baseline
333
- * tool, or a tool the model called by name without activating it) is untouched.
369
+ * Record a call — the freshness of a session-activated tool and the evidence a
370
+ * compaction keeps it by.
371
+ *
372
+ * `active` is refreshed exactly as before: a call is what keeps a
373
+ * session-activated tool offered. `used` records the call itself, but only for
374
+ * this plugin's own namespace: the core tools (`read`, `bash`, …) ride the same
375
+ * `tools/result` hook, and they are no part of a session's MCP activation state.
376
+ * A baseline name is not recorded either — the durable baseline already keeps it
377
+ * offered, so recording the call would only make a compaction look like it
378
+ * changed something.
334
379
  *
335
380
  * @param state - activation state before the call.
336
381
  * @param name - public name of the called tool.
@@ -339,10 +384,22 @@ export function activate(
339
384
  */
340
385
  export function noteUse(state: ActivationState, name: string, at: number): ActivationState {
341
386
  const previous = state.active.get(name)
342
- if (previous === undefined || previous === at) return state
343
- const active = new Map(state.active)
344
- active.set(name, at)
345
- return { baseline: state.baseline, active }
387
+ const refresh = previous !== undefined && previous !== at
388
+ // `used` post-dates the interface: a state an embedder built before the field
389
+ // existed reads as a session that has used nothing, so the read is optional
390
+ // and the write coalesces an empty record instead of throwing.
391
+ const already = state.used?.has(name) === true
392
+ const record = name.startsWith('mcp__') && !state.baseline.has(name) && !already
393
+ if (!refresh && !record) return state
394
+ const active = refresh ? new Map(state.active) : undefined
395
+ active?.set(name, at)
396
+ const used = record ? new Set(state.used ?? []) : undefined
397
+ used?.add(name)
398
+ return {
399
+ baseline: state.baseline,
400
+ active: active ?? state.active,
401
+ used: used ?? state.used ?? new Set(),
402
+ }
346
403
  }
347
404
 
348
405
  /**
@@ -350,6 +407,13 @@ export function noteUse(state: ActivationState, name: string, at: number): Activ
350
407
  * The baseline is never pruned: it comes from the durable counters, not from the
351
408
  * session. `idleMs <= 0` disables pruning.
352
409
  *
410
+ * A positive `idleMs` is an explicit opt-in to *forgetting*: an evicted name
411
+ * leaves the used record with the offer it was about, so the sweep is final —
412
+ * a later compaction cannot read the call back and resurrect what time already
413
+ * dropped. A name the model needs again is activated again through search. The
414
+ * names still inside the window keep their record, and a sweep that evicts
415
+ * nothing returns its input.
416
+ *
353
417
  * @param state - activation state at `now`.
354
418
  * @param now - epoch milliseconds of the sweep.
355
419
  * @param idleMs - age at which a tool falls out.
@@ -358,23 +422,68 @@ export function noteUse(state: ActivationState, name: string, at: number): Activ
358
422
  export function pruneIdle(state: ActivationState, now: number, idleMs: number): ActivationState {
359
423
  if (idleMs <= 0 || state.active.size === 0) return state
360
424
  let active: Map<string, number> | undefined
425
+ let used: Set<string> | undefined
361
426
  for (const [name, at] of state.active) {
362
427
  if (now - at < idleMs) continue
363
428
  active ??= new Map(state.active)
364
429
  active.delete(name)
430
+ // `used` post-dates the interface, so a legacy state simply has no record to
431
+ // forget; a record that is there is copied before it is dropped.
432
+ if (state.used?.has(name) !== true) continue
433
+ used ??= new Set(state.used ?? [])
434
+ used.delete(name)
365
435
  }
366
- return active === undefined ? state : { baseline: state.baseline, active }
436
+ return active === undefined
437
+ ? state
438
+ : { baseline: state.baseline, active, used: used ?? state.used ?? new Set() }
367
439
  }
368
440
 
369
441
  /**
370
- * End the session's activations — a compaction rewrote the conversation they
371
- * belonged to — while keeping the counter baseline.
442
+ * End the session's activations that no call backs, at the compaction boundary.
443
+ *
444
+ * A compaction rewrites the conversation, so the provider's prompt prefix is
445
+ * recomputed anyway: this is the one boundary where dropping a tool costs no
446
+ * cache, which is why idle time is off by default and why this is the only place
447
+ * the offered set shrinks. Only the part the session never used goes — an offer
448
+ * from a context match or a search that the model did not act on. A tool this
449
+ * session did call is one it really uses, so it stays active, stamped with its
450
+ * last touch; evicting it would charge a re-discovery step for a tool the
451
+ * session demonstrably needs. A used name that was never activated falls back to
452
+ * the compaction's own clock. The counter baseline is never pruned.
453
+ *
454
+ * The used record is cumulative for the session and deliberately never bounded:
455
+ * with the shipped `DEFAULT_TOOL_IDLE_MS` of `0` nothing else removes a name, so
456
+ * a tool the session used stays offered for the rest of the session, across every
457
+ * further compaction. This boundary shrinks the offers no call backs — it never
458
+ * shrinks one the session used again.
459
+ *
372
460
  * @param state - activation state before the compaction.
373
- * @returns the updated state, or the input when no session tool was active.
461
+ * @param at - epoch milliseconds of the compaction.
462
+ * @returns the updated state, or the input when nothing was active or used, or
463
+ * when the rebuild is equivalent to what is already there — a caller compares
464
+ * by identity to tell a real change from a boundary that changed nothing.
374
465
  */
375
- export function onCompaction(state: ActivationState): ActivationState {
376
- if (state.active.size === 0) return state
377
- return { baseline: state.baseline, active: new Map() }
466
+ export function onCompaction(state: ActivationState, at: number): ActivationState {
467
+ // `used` post-dates the interface: a state an embedder built before the field
468
+ // existed reads as a session that has used nothing.
469
+ const used = state.used ?? new Set<string>()
470
+ if (state.active.size === 0 && used.size === 0) return state
471
+ const active = new Map<string, number>()
472
+ for (const name of used) active.set(name, state.active.get(name) ?? at)
473
+ // A second compaction with no new call rebuilds exactly the map already there,
474
+ // and an equal-but-different object would read as a change to every caller
475
+ // that compares by identity. Same names and same stamps: the input comes back.
476
+ if (active.size === state.active.size) {
477
+ let equivalent = true
478
+ for (const [name, stamp] of active) {
479
+ if (state.active.get(name) !== stamp) {
480
+ equivalent = false
481
+ break
482
+ }
483
+ }
484
+ if (equivalent) return state
485
+ }
486
+ return { baseline: state.baseline, active, used: state.used ?? new Set() }
378
487
  }
379
488
 
380
489
  /**
@@ -858,7 +967,18 @@ export function autoOffers(state: AutoOfferState): readonly string[] {
858
967
  return entries.map((entry) => entry.name)
859
968
  }
860
969
 
861
- /** Whether two context-driven states describe the same offered set and history. */
970
+ /**
971
+ * Whether two context-driven states offer the same names.
972
+ *
973
+ * Only the presented names are compared, never the advance stamp and never the
974
+ * per-name window stamps, so an advance that changes nothing hands back the
975
+ * previous state without ticking the advance counter: the sticky window ages by
976
+ * changes of the offered set, not by input count. This was reviewed as a
977
+ * possible stickiness off-by-one and cannot produce a wrong offered set — a
978
+ * stall can only hold names the ranking has just chosen again, and it ends at
979
+ * the first advance whose set differs — so do not re-chase an age here before
980
+ * reading `advanceAutoOffer`.
981
+ */
862
982
  function sameAutoOffer(left: AutoOfferState, right: AutoOfferState): boolean {
863
983
  const leftNames = autoPresentedNames(left)
864
984
  const rightNames = autoPresentedNames(right)
@@ -1207,10 +1327,10 @@ export interface ActivationWiringOptions {
1207
1327
  */
1208
1328
  readonly onActivated?: (names: readonly string[], step: number) => void
1209
1329
  /**
1210
- * Told that a compaction ended the session's activations, so the caller can
1211
- * drop the step records that belong to them. Absent leaves the records in
1212
- * place, which only means a later activation of the same name may carry the
1213
- * step of the offer the compaction removed.
1330
+ * Told that a compaction ended some of the session's activations, so the
1331
+ * caller can drop the step records that belonged to the ones it removed.
1332
+ * Absent leaves the records in place, which only means a later activation of
1333
+ * the same name may carry the step of the offer the compaction removed.
1214
1334
  */
1215
1335
  readonly onCompaction?: () => void
1216
1336
  /** Context-driven state to start from; defaults to an empty state. */
@@ -1463,10 +1583,11 @@ export function installActivation(options: ActivationWiringOptions): () => void
1463
1583
  const observe = (_session: unknown, event: SessionEventLike): void => {
1464
1584
  try {
1465
1585
  if (event?.type === 'compaction/end') {
1466
- options.setState(onCompaction(options.state()))
1467
- // The step records belong to activations a compaction has just dropped,
1468
- // so they go with them: a name activated again after this is stamped
1469
- // with the step it returns on, not with the one it left on.
1586
+ options.setState(onCompaction(options.state(), Date.now()))
1587
+ // The step records of the activations the compaction just dropped go
1588
+ // with them: a name activated again after this is stamped with the step
1589
+ // it returns on, not with the one it left on, while a tool the session
1590
+ // really used keeps the step its offer happened on.
1470
1591
  options.onCompaction?.()
1471
1592
  // A compaction rewrote the conversation the offers belonged to, so the
1472
1593
  // context tier starts over; the counter baseline is untouched.
@@ -456,15 +456,15 @@ export const zh: Record<UiKey, string> = {
456
456
  configActivationSeeded: '预置工具数',
457
457
  configActivationSeededHint: '在计数累计之前,从第一步就提供的工具数;0 表示不预置',
458
458
  configActivationMinCalls: '固定所需调用次数',
459
- configActivationMinCallsHint: '计数器在调用达到此次数后直接固定该工具',
459
+ configActivationMinCallsHint: '调用达到此次数后,计数器会直接固定该工具;0 表示只要有过调用就固定',
460
460
  configToolIdleMs: '工具闲置超时(毫秒)',
461
- configToolIdleMsHint: '工具超过此时长未使用将从请求中移除',
461
+ configToolIdleMsHint: '工具超过此时长未使用将从请求中移除;0 表示整个会话都保留',
462
462
  configGuidanceEnabled: '系统提示指引',
463
463
  configGuidanceEnabledHint: '将本插件的使用说明注入会话提示',
464
464
  configActivationAutoLimit: '自动激活上限',
465
465
  configActivationAutoLimitHint: '计数器最多可自行加入的工具数(0–50)',
466
466
  configActivationAutoStickySteps: '黏滞步数',
467
- configActivationAutoStickyStepsHint: '刚使用过的工具无论计数如何都保持固定的步数(0–20)',
467
+ configActivationAutoStickyStepsHint: '按任务上下文提供的工具额外保留多少条用户消息;0 表示仅保留当前消息(0–1000)',
468
468
  configActivationToolBudgetChars: '工具预算(字符)',
469
469
  configActivationToolBudgetCharsHint: '单次请求携带的工具模式字符预算(≥ 1000)',
470
470
  configAllowGlobalWrite: '允许全局写入',
@@ -876,15 +876,15 @@ export const ru: Record<UiKey, string> = {
876
876
  configActivationSeeded: 'Предустановленные инструменты',
877
877
  configActivationSeededHint: 'Инструменты, предлагаемые с первого шага, до накопления счётчиков; 0 — не предлагать',
878
878
  configActivationMinCalls: 'Вызовов до закрепления',
879
- configActivationMinCallsHint: 'После стольких вызовов счётчики закрепляют инструмент напрямую',
879
+ configActivationMinCallsHint: 'После стольких вызовов счётчики закрепляют инструмент напрямую; 0 — закрепить любой инструмент с записанным вызовом',
880
880
  configToolIdleMs: 'Тайм-аут простоя инструмента (мс)',
881
- configToolIdleMsHint: 'Инструмент, не использованный за это время, исключается из запроса',
881
+ configToolIdleMsHint: 'Инструмент, не использованный за это время, исключается из запроса; 0 — оставить его на всю сессию',
882
882
  configGuidanceEnabled: 'Подсказки в системном промпте',
883
883
  configGuidanceEnabledHint: 'Добавлять рабочие заметки плагина в промпт сессии',
884
884
  configActivationAutoLimit: 'Лимит автоактивации',
885
885
  configActivationAutoLimitHint: 'Максимум инструментов, которые счётчики могут добавить сами (0–50)',
886
886
  configActivationAutoStickySteps: 'Шагов закрепления',
887
- configActivationAutoStickyStepsHint: 'Сколько шагов только что использованный инструмент остаётся закреплённым независимо от счётчиков (0–20)',
887
+ configActivationAutoStickyStepsHint: 'Сколько пользовательских сообщений предложенный по контексту инструмент остаётся предложенным; 0 — только для этого сообщения (0–1000)',
888
888
  configActivationToolBudgetChars: 'Бюджет инструментов (символы)',
889
889
  configActivationToolBudgetCharsHint: 'Бюджет в символах на схемы инструментов в одном запросе (≥ 1000)',
890
890
  configAllowGlobalWrite: 'Глобальная запись',
@@ -88,15 +88,15 @@ export const EN = {
88
88
  configActivationSeeded: 'Seeded tools',
89
89
  configActivationSeededHint: 'Tools offered from the first step, before any counter accrues; 0 seeds none',
90
90
  configActivationMinCalls: 'Calls to pin',
91
- configActivationMinCallsHint: 'Calls after which the counters pin a tool directly',
91
+ configActivationMinCallsHint: 'Calls after which the counters pin a tool directly; 0 pins any tool with a recorded call',
92
92
  configToolIdleMs: 'Tool idle timeout (ms)',
93
- configToolIdleMsHint: 'A tool unused for this long drops back out of the request',
93
+ configToolIdleMsHint: 'A tool unused for this long drops back out of the request; 0 keeps it for the whole session',
94
94
  configGuidanceEnabled: 'System-prompt guidance',
95
95
  configGuidanceEnabledHint: 'Inject the plugin’s operating notes into the session prompt',
96
96
  configActivationAutoLimit: 'Auto-activation limit',
97
97
  configActivationAutoLimitHint: 'Most tools the counters may add on their own (0–50)',
98
98
  configActivationAutoStickySteps: 'Sticky steps',
99
- configActivationAutoStickyStepsHint: 'Steps a just-used tool stays pinned regardless of counters (0–20)',
99
+ configActivationAutoStickyStepsHint: 'Extra user messages a context offer stays offered; 0 keeps it for that message only (0–1000)',
100
100
  configActivationToolBudgetChars: 'Tool budget (chars)',
101
101
  configActivationToolBudgetCharsHint: 'Character budget for the tool schemas one request carries (≥ 1000)',
102
102
  // The Runtime group: mounting, precedence and timeouts.
@@ -181,12 +181,12 @@ export type VolatileConfigKey =
181
181
  */
182
182
  export const CONFIG_DEFAULTS: Record<VolatileConfigKey, boolean | number | string> = {
183
183
  activationEnabled: true,
184
- activationSeeded: 8,
185
- activationMinCalls: 5,
186
- toolIdleMs: 1_800_000,
184
+ activationSeeded: 16,
185
+ activationMinCalls: 1,
186
+ toolIdleMs: 0,
187
187
  guidanceEnabled: true,
188
188
  activationAutoLimit: 12,
189
- activationAutoStickySteps: 2,
189
+ activationAutoStickySteps: 100,
190
190
  activationToolBudgetChars: 40_000,
191
191
  allowGlobalWrite: false,
192
192
  envFiles: true,
@@ -227,11 +227,11 @@ interface FieldDef {
227
227
  const ACTIVATION_FIELDS: readonly FieldDef[] = [
228
228
  { key: 'activationEnabled', kind: 'boolean', label: 'configActivationEnabled', hint: 'configActivationEnabledHint' },
229
229
  { key: 'activationSeeded', kind: 'integer', min: 0, label: 'configActivationSeeded', hint: 'configActivationSeededHint' },
230
- { key: 'activationMinCalls', kind: 'integer', min: 1, label: 'configActivationMinCalls', hint: 'configActivationMinCallsHint' },
230
+ { key: 'activationMinCalls', kind: 'integer', min: 0, label: 'configActivationMinCalls', hint: 'configActivationMinCallsHint' },
231
231
  { key: 'toolIdleMs', kind: 'integer', min: 0, label: 'configToolIdleMs', hint: 'configToolIdleMsHint' },
232
232
  { key: 'guidanceEnabled', kind: 'boolean', label: 'configGuidanceEnabled', hint: 'configGuidanceEnabledHint' },
233
233
  { key: 'activationAutoLimit', kind: 'integer', min: 0, max: 50, label: 'configActivationAutoLimit', hint: 'configActivationAutoLimitHint' },
234
- { key: 'activationAutoStickySteps', kind: 'integer', min: 0, max: 20, label: 'configActivationAutoStickySteps', hint: 'configActivationAutoStickyStepsHint' },
234
+ { key: 'activationAutoStickySteps', kind: 'integer', min: 0, max: 1000, label: 'configActivationAutoStickySteps', hint: 'configActivationAutoStickyStepsHint' },
235
235
  { key: 'activationToolBudgetChars', kind: 'integer', min: 1000, label: 'configActivationToolBudgetChars', hint: 'configActivationToolBudgetCharsHint' },
236
236
  ]
237
237
 
package/src/runtime.ts CHANGED
@@ -3083,7 +3083,10 @@ export class ProjectMcpRuntime {
3083
3083
  for (const name of names) state.steps.set(name, step)
3084
3084
  },
3085
3085
  onCompaction: () => {
3086
- state.steps.clear()
3086
+ // A step record belongs to the activation it was made for, so the ones
3087
+ // a compaction just dropped go with them — while a tool the session
3088
+ // really used keeps the step its offer happened on.
3089
+ this.pruneStepRecords(state)
3087
3090
  },
3088
3091
  autoState: state.auto ?? createAutoOfferState(),
3089
3092
  setAutoState: (next) => {
@@ -3322,8 +3325,10 @@ export class ProjectMcpRuntime {
3322
3325
  }
3323
3326
 
3324
3327
  /**
3325
- * Refresh the freshness of a tool a session actually called. It rides the same
3326
- * `tools/result` subscription the counters use, so no second observer exists.
3328
+ * Record a call against the session's activation state: it refreshes the
3329
+ * freshness of a session-activated tool, and it is the evidence a later
3330
+ * compaction keeps that activation by. It rides the same `tools/result`
3331
+ * subscription the counters use, so no second observer exists.
3327
3332
  * @param agentId - calling agent, when the call was agent-scoped.
3328
3333
  * @param toolName - public registry name of the call.
3329
3334
  */
@@ -3342,10 +3347,21 @@ export class ProjectMcpRuntime {
3342
3347
  // A step record belongs to the activation it was made for, so a name that
3343
3348
  // fell out of the window takes its record with it; one that returns is
3344
3349
  // stamped again with the step it returns on.
3345
- if (state.activation !== current) {
3346
- for (const name of [...state.steps.keys()]) {
3347
- if (!state.activation.active.has(name)) state.steps.delete(name)
3348
- }
3350
+ if (state.activation !== current) this.pruneStepRecords(state)
3351
+ }
3352
+
3353
+ /**
3354
+ * Drop the step records whose activation the session no longer holds.
3355
+ *
3356
+ * Called wherever activations end — the idle sweep and a compaction — so a
3357
+ * record never outlives the offer it was made for, and a name the session
3358
+ * still offers keeps the step its offer happened on.
3359
+ * @param state - the session whose records are reconciled.
3360
+ */
3361
+ private pruneStepRecords(state: AgentState): void {
3362
+ const active = state.activation?.active
3363
+ for (const name of [...state.steps.keys()]) {
3364
+ if (active === undefined || !active.has(name)) state.steps.delete(name)
3349
3365
  }
3350
3366
  }
3351
3367