dsh-project-mcp 0.3.1 → 0.4.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/README.md +38 -23
- package/lib/client.js +15 -15
- package/lib/client.js.map +1 -1
- package/lib/index.d.ts +181 -27
- package/lib/index.js +273 -61
- package/lib/index.js.map +1 -1
- package/package.json +18 -17
- package/src/activation.ts +164 -43
- package/src/bridge.ts +114 -7
- package/src/client/locales/ui.ts +6 -6
- package/src/client/plugin-config.ts +9 -9
- package/src/runtime.ts +77 -19
|
@@ -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: '
|
|
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:
|
|
185
|
-
activationMinCalls:
|
|
186
|
-
toolIdleMs:
|
|
184
|
+
activationSeeded: 16,
|
|
185
|
+
activationMinCalls: 1,
|
|
186
|
+
toolIdleMs: 0,
|
|
187
187
|
guidanceEnabled: true,
|
|
188
188
|
activationAutoLimit: 12,
|
|
189
|
-
activationAutoStickySteps:
|
|
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:
|
|
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:
|
|
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
|
@@ -2864,9 +2864,14 @@ export class ProjectMcpRuntime {
|
|
|
2864
2864
|
const servers = (): ReadonlySet<string> => this.runtimeNamesOf(state)
|
|
2865
2865
|
const batch = new ForwardBatch({
|
|
2866
2866
|
names: () => {
|
|
2867
|
+
const project = state.project
|
|
2868
|
+
// No project, nothing to probe. An empty key here would read the
|
|
2869
|
+
// *global* view instead — every tool any scope registered — and each
|
|
2870
|
+
// pass would forward names this session's project never published.
|
|
2871
|
+
if (project === undefined) return undefined
|
|
2867
2872
|
try {
|
|
2868
2873
|
return projectToolNames(
|
|
2869
|
-
|
|
2874
|
+
project.key,
|
|
2870
2875
|
(scope) => this.bridgeSchemas(scope),
|
|
2871
2876
|
servers(),
|
|
2872
2877
|
)
|
|
@@ -2879,20 +2884,27 @@ export class ProjectMcpRuntime {
|
|
|
2879
2884
|
return undefined
|
|
2880
2885
|
}
|
|
2881
2886
|
},
|
|
2882
|
-
register: (names) =>
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2887
|
+
register: (names) => {
|
|
2888
|
+
const project = state.project
|
|
2889
|
+
if (project === undefined) return () => undefined
|
|
2890
|
+
return forwardProjectTools({
|
|
2891
|
+
ctx: context,
|
|
2892
|
+
project: project.key,
|
|
2893
|
+
names,
|
|
2894
|
+
registry,
|
|
2895
|
+
})
|
|
2896
|
+
},
|
|
2897
|
+
onError: (error) => this.reportBridgeFailure(state, error),
|
|
2888
2898
|
})
|
|
2889
2899
|
const bridge: BridgeForwarders = {
|
|
2890
2900
|
batch,
|
|
2891
2901
|
detach: () => undefined,
|
|
2892
2902
|
}
|
|
2893
2903
|
// The listener lives on the session scope and is dropped with it, so a
|
|
2894
|
-
// released session never keeps syncing against a project it left.
|
|
2895
|
-
|
|
2904
|
+
// released session never keeps syncing against a project it left. It only
|
|
2905
|
+
// *notes* the change: the registry emits this once per entry registered and
|
|
2906
|
+
// once per entry disposed, and a pass per event is what held the event loop.
|
|
2907
|
+
const detach = state.scope.ctx.on('tools/change', () => this.noteBridge(state))
|
|
2896
2908
|
bridge.detach = typeof detach === 'function' ? (detach as () => void) : () => undefined
|
|
2897
2909
|
state.bridge = bridge
|
|
2898
2910
|
this.syncBridge(state)
|
|
@@ -2914,12 +2926,42 @@ export class ProjectMcpRuntime {
|
|
|
2914
2926
|
try {
|
|
2915
2927
|
bridge.batch.sync()
|
|
2916
2928
|
} catch (error) {
|
|
2917
|
-
this.
|
|
2918
|
-
`project-mcp: forwarding the tools of ${state.project?.projectRoot ?? 'the project'} into session ${state.agent.id} failed: ${errorText(error)}`,
|
|
2919
|
-
)
|
|
2929
|
+
this.reportBridgeFailure(state, error)
|
|
2920
2930
|
}
|
|
2921
2931
|
}
|
|
2922
2932
|
|
|
2933
|
+
/**
|
|
2934
|
+
* Note one registry change for one session's bridge, off the emitter's stack.
|
|
2935
|
+
*
|
|
2936
|
+
* The event this answers is emitted synchronously from inside the registry's
|
|
2937
|
+
* own insertion and removal — once per entry in, once per entry out — so one
|
|
2938
|
+
* MCP generation swap is a burst of thousands. Running the pass here would
|
|
2939
|
+
* make whoever registered a tool pay for every session watching the project,
|
|
2940
|
+
* and each pass projects the project's whole catalog. The batch folds the
|
|
2941
|
+
* burst into one queued pass instead, which is also why this is not
|
|
2942
|
+
* {@link syncBridge}: the read paths, the mount settle and the scope wiring
|
|
2943
|
+
* all bring the batch level synchronously, before anything reads the layer.
|
|
2944
|
+
* @param state - the session whose bridge noticed the change.
|
|
2945
|
+
*/
|
|
2946
|
+
private noteBridge(state: AgentState): void {
|
|
2947
|
+
state.bridge?.batch.note()
|
|
2948
|
+
}
|
|
2949
|
+
|
|
2950
|
+
/**
|
|
2951
|
+
* Write the one warning line a failed bridge pass is allowed.
|
|
2952
|
+
*
|
|
2953
|
+
* Shared by the synchronous pass and by the one a batch runs on its own: a
|
|
2954
|
+
* scheduled pass has no caller left to propagate its failure to, so the batch
|
|
2955
|
+
* hands it here through `onError` rather than swallowing it.
|
|
2956
|
+
* @param state - the session whose bridge failed.
|
|
2957
|
+
* @param error - what the pass threw.
|
|
2958
|
+
*/
|
|
2959
|
+
private reportBridgeFailure(state: AgentState, error: unknown): void {
|
|
2960
|
+
this.ctx.logger.warn(
|
|
2961
|
+
`project-mcp: forwarding the tools of ${state.project?.projectRoot ?? 'the project'} into session ${state.agent.id} failed: ${errorText(error)}`,
|
|
2962
|
+
)
|
|
2963
|
+
}
|
|
2964
|
+
|
|
2923
2965
|
/** The project scope's visible schemas, as {@link projectToolNames} reads them. */
|
|
2924
2966
|
private bridgeSchemas(scope: object): ReturnType<BridgeRegistryLike['schemas']> {
|
|
2925
2967
|
return this.bridgeRegistry().schemas(scope)
|
|
@@ -3083,7 +3125,10 @@ export class ProjectMcpRuntime {
|
|
|
3083
3125
|
for (const name of names) state.steps.set(name, step)
|
|
3084
3126
|
},
|
|
3085
3127
|
onCompaction: () => {
|
|
3086
|
-
|
|
3128
|
+
// A step record belongs to the activation it was made for, so the ones
|
|
3129
|
+
// a compaction just dropped go with them — while a tool the session
|
|
3130
|
+
// really used keeps the step its offer happened on.
|
|
3131
|
+
this.pruneStepRecords(state)
|
|
3087
3132
|
},
|
|
3088
3133
|
autoState: state.auto ?? createAutoOfferState(),
|
|
3089
3134
|
setAutoState: (next) => {
|
|
@@ -3322,8 +3367,10 @@ export class ProjectMcpRuntime {
|
|
|
3322
3367
|
}
|
|
3323
3368
|
|
|
3324
3369
|
/**
|
|
3325
|
-
*
|
|
3326
|
-
*
|
|
3370
|
+
* Record a call against the session's activation state: it refreshes the
|
|
3371
|
+
* freshness of a session-activated tool, and it is the evidence a later
|
|
3372
|
+
* compaction keeps that activation by. It rides the same `tools/result`
|
|
3373
|
+
* subscription the counters use, so no second observer exists.
|
|
3327
3374
|
* @param agentId - calling agent, when the call was agent-scoped.
|
|
3328
3375
|
* @param toolName - public registry name of the call.
|
|
3329
3376
|
*/
|
|
@@ -3342,10 +3389,21 @@ export class ProjectMcpRuntime {
|
|
|
3342
3389
|
// A step record belongs to the activation it was made for, so a name that
|
|
3343
3390
|
// fell out of the window takes its record with it; one that returns is
|
|
3344
3391
|
// stamped again with the step it returns on.
|
|
3345
|
-
if (state.activation !== current)
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3392
|
+
if (state.activation !== current) this.pruneStepRecords(state)
|
|
3393
|
+
}
|
|
3394
|
+
|
|
3395
|
+
/**
|
|
3396
|
+
* Drop the step records whose activation the session no longer holds.
|
|
3397
|
+
*
|
|
3398
|
+
* Called wherever activations end — the idle sweep and a compaction — so a
|
|
3399
|
+
* record never outlives the offer it was made for, and a name the session
|
|
3400
|
+
* still offers keeps the step its offer happened on.
|
|
3401
|
+
* @param state - the session whose records are reconciled.
|
|
3402
|
+
*/
|
|
3403
|
+
private pruneStepRecords(state: AgentState): void {
|
|
3404
|
+
const active = state.activation?.active
|
|
3405
|
+
for (const name of [...state.steps.keys()]) {
|
|
3406
|
+
if (active === undefined || !active.has(name)) state.steps.delete(name)
|
|
3349
3407
|
}
|
|
3350
3408
|
}
|
|
3351
3409
|
|