@linxin666/dsh-liangshen 0.4.15 → 0.4.17
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.i18n.yaml +2 -2
- package/README.md +19 -18
- package/README.zh.md +19 -18
- package/lib/client.js +286 -2
- package/lib/client.js.map +1 -1
- package/lib/index.js +31 -6
- package/lib/types/client/LiangShenSettingsCard.d.ts +10 -1
- package/lib/types/client/locales.d.ts +3 -0
- package/lib/types/composition.d.ts +13 -0
- package/lib/types/index.d.ts +14 -2
- package/package.json +16 -16
- package/presets/liangshen/agent.cordis.yml +60 -28
- package/presets/liangshen/dispatch-guard.mjs +24 -8
- package/presets/liangshen/fact-ledger.mjs +47 -11
- package/presets/liangshen/paging.mjs +44 -18
- package/presets/liangshen/tool-activate.mjs +10 -7
- package/presets/liangshen/tool-catalog.mjs +163 -335
- package/src/client/LiangShenSettingsCard.tsx +38 -2
- package/src/client/locales.ts +6 -0
- package/src/composition.test.ts +52 -1
- package/src/composition.ts +33 -1
- package/src/index.test.ts +1 -0
- package/src/index.ts +15 -2
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* paging — pure helpers for the LiangShen preset's gentle tool paging.
|
|
3
3
|
*
|
|
4
|
-
* Paging keeps high-fan-out tool families (MCP servers and
|
|
5
|
-
* off the wire until the session actually needs them: a tool whose
|
|
6
|
-
* matches one of the configured prefix patterns is PAGED, everything else
|
|
7
|
-
* RESIDENT and stays on the wire. A paged tool returns to the wire once its
|
|
4
|
+
* Paging keeps high-fan-out tool families (MCP servers and plugin tool
|
|
5
|
+
* families) off the wire until the session actually needs them: a tool whose
|
|
6
|
+
* name matches one of the configured prefix patterns is PAGED, everything else
|
|
7
|
+
* is RESIDENT and stays on the wire. A paged tool returns to the wire once its
|
|
8
8
|
* namespace is activated through the `tool_activate` tool.
|
|
9
9
|
*
|
|
10
10
|
* The activation state is derived from the durable session event stream, never
|
|
@@ -18,8 +18,14 @@
|
|
|
18
18
|
* oldest, returning its tools to the paged summary.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
/**
|
|
22
|
-
|
|
21
|
+
/**
|
|
22
|
+
* The default paging patterns: the MCP bridge (`mcp__<server>__<fn>`, one
|
|
23
|
+
* namespace per server) plus the plugin tool families this preset mounts and
|
|
24
|
+
* would otherwise carry resident for the whole session — the browser view, the
|
|
25
|
+
* task board, the team issue channel, the squad roster, the client presentation
|
|
26
|
+
* tool and the SSH host tools.
|
|
27
|
+
*/
|
|
28
|
+
export const DEFAULT_PAGED_TOOL_PATTERNS = ['mcp__*', 'browser_*', 'task_board_*', 'team_*', 'squad*', 'ui_*', 'ssh_*']
|
|
23
29
|
|
|
24
30
|
/** The LRU cap on simultaneously active paged namespaces. */
|
|
25
31
|
export const DEFAULT_MAX_ACTIVE_NAMESPACES = 3
|
|
@@ -38,7 +44,9 @@ export function integerAtLeast(plugin, value, field, minimum, fallback) {
|
|
|
38
44
|
|
|
39
45
|
/**
|
|
40
46
|
* Validate the pagedToolPatterns config: an array of prefix globs, each a
|
|
41
|
-
* non-empty literal
|
|
47
|
+
* non-empty literal head ending in exactly one trailing `*`. A head-less `*`
|
|
48
|
+
* is refused rather than accepted and inert: the family derivation reads the
|
|
49
|
+
* head, so a bare wildcard would claim every tool and page none of them.
|
|
42
50
|
*/
|
|
43
51
|
export function validatePagedToolPatterns(plugin, value, fallback = DEFAULT_PAGED_TOOL_PATTERNS) {
|
|
44
52
|
if (value === undefined) return fallback
|
|
@@ -49,7 +57,7 @@ export function validatePagedToolPatterns(plugin, value, fallback = DEFAULT_PAGE
|
|
|
49
57
|
if (typeof entry !== 'string' || entry.trim() === '') {
|
|
50
58
|
throw new TypeError(`${plugin}: pagedToolPatterns entries must be non-empty strings`)
|
|
51
59
|
}
|
|
52
|
-
if (!entry.endsWith('*') || entry.slice(0, -1).includes('*')) {
|
|
60
|
+
if (!entry.endsWith('*') || entry.slice(0, -1).includes('*') || entry.slice(0, -1).trim() === '') {
|
|
53
61
|
throw new TypeError(`${plugin}: pagedToolPatterns entries must be prefix patterns ending in one trailing "*"`)
|
|
54
62
|
}
|
|
55
63
|
return entry
|
|
@@ -58,10 +66,17 @@ export function validatePagedToolPatterns(plugin, value, fallback = DEFAULT_PAGE
|
|
|
58
66
|
|
|
59
67
|
/**
|
|
60
68
|
* The namespace one tool name belongs to under one pattern, or undefined when
|
|
61
|
-
* the pattern does not match. The
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
69
|
+
* the pattern does not match. The pattern's own head decides how the namespace
|
|
70
|
+
* is derived:
|
|
71
|
+
* - a head ending in `__` is an MCP bridge, whose namespace lives in the tool
|
|
72
|
+
* name: the first `__`-delimited segment of the remainder
|
|
73
|
+
* (`mcp__codegraph__codegraph_explore` under `mcp__*` is `codegraph`);
|
|
74
|
+
* - any other head names the family literally, with one trailing `_` dropped
|
|
75
|
+
* (`task_board_*` is `task_board`, `squad*` is `squad`), so a plugin whose
|
|
76
|
+
* tools share a literal prefix shares one namespace — and `squad*` covers
|
|
77
|
+
* `squads_*` and `squad_member_*` alike.
|
|
78
|
+
* An empty remainder, or a head that leaves no family name at all, means the
|
|
79
|
+
* tool is not paged.
|
|
65
80
|
*/
|
|
66
81
|
export function patternNamespace(name, pattern) {
|
|
67
82
|
if (typeof name !== 'string' || typeof pattern !== 'string' || !pattern.endsWith('*')) return undefined
|
|
@@ -69,7 +84,9 @@ export function patternNamespace(name, pattern) {
|
|
|
69
84
|
if (!name.startsWith(prefix)) return undefined
|
|
70
85
|
const rest = name.slice(prefix.length)
|
|
71
86
|
if (rest === '') return undefined
|
|
72
|
-
const namespace =
|
|
87
|
+
const namespace = prefix.endsWith('__')
|
|
88
|
+
? rest.split('__')[0]
|
|
89
|
+
: prefix.endsWith('_') ? prefix.slice(0, -1) : prefix
|
|
73
90
|
return namespace === '' ? undefined : namespace
|
|
74
91
|
}
|
|
75
92
|
|
|
@@ -198,17 +215,26 @@ export function replayActivations(events, capacity = DEFAULT_MAX_ACTIVE_NAMESPAC
|
|
|
198
215
|
}
|
|
199
216
|
for (const event of list) {
|
|
200
217
|
// Under the `ptc` presentation the wire carries `run_code` alone, so the model
|
|
201
|
-
// reaches
|
|
218
|
+
// reaches EVERY tool from inside a program and the harness records each call as
|
|
202
219
|
// a `tool/ptc-dispatch` event — never as a top-level `tool/call`. Reading only
|
|
203
220
|
// `tool/call` therefore found no activation at all: every activation reported
|
|
204
221
|
// success, the page never lifted, and the same namespace could be activated
|
|
205
222
|
// again for ever. Both event shapes feed the same recency list, in the order
|
|
206
|
-
// the session recorded them
|
|
223
|
+
// the session recorded them, and the dispatch branch repeats BOTH rules the
|
|
224
|
+
// top-level branch applies: an activation activates, and any other call into
|
|
225
|
+
// an already-active family refreshes it. Without the second rule the LRU
|
|
226
|
+
// silently degraded to activation order — the only shape a real tool call
|
|
227
|
+
// takes under the default presentation refreshed nothing.
|
|
207
228
|
if (event?.type === 'tool/ptc-dispatch') {
|
|
208
229
|
const dispatch = event.data
|
|
209
|
-
if (dispatch?.
|
|
210
|
-
|
|
211
|
-
|
|
230
|
+
if (dispatch?.isError === true) continue
|
|
231
|
+
if (dispatch?.name === TOOL_ACTIVATE_NAME) {
|
|
232
|
+
const namespace = callArguments(dispatch)?.namespace
|
|
233
|
+
if (typeof namespace === 'string' && namespace !== '') touch(namespace)
|
|
234
|
+
continue
|
|
235
|
+
}
|
|
236
|
+
const namespace = namespaceOf(dispatch?.name, patterns)
|
|
237
|
+
if (namespace !== undefined && active.includes(namespace)) touch(namespace)
|
|
212
238
|
continue
|
|
213
239
|
}
|
|
214
240
|
if (event?.type !== 'tool/call') continue
|
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
* tool-activate — the LiangShen preset's `tool_activate` tool: the activation
|
|
3
3
|
* handle for the gentle tool paging the sibling tool-catalog plugin applies.
|
|
4
4
|
*
|
|
5
|
-
* Tools whose names match the paging patterns
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
5
|
+
* Tools whose names match the paging patterns — by default the MCP bridge plus
|
|
6
|
+
* the plugin families `browser_*`, `task_board_*`, `team_*`, `squad*`, `ui_*`
|
|
7
|
+
* and `ssh_*` — stay out of reach until their namespace is activated here: off
|
|
8
|
+
* the wire, and, under a presentation whose wire has already collapsed to the
|
|
9
|
+
* single `run_code` transport where the wire carries nothing left to filter,
|
|
10
|
+
* also out of the scope's registry view, which is what the generated SDK and
|
|
11
|
+
* every program dispatch resolve against.
|
|
12
|
+
*
|
|
13
|
+
* The activation itself is the durable `tool/call`
|
|
11
14
|
* event this call appends to the session log: the catalog plugin re-pages the
|
|
12
15
|
* scope at the end of the call (its `tools/post-execute` hook) and the wire
|
|
13
16
|
* partition replays the same event stream at the next assembly, so both halves
|
|
@@ -131,7 +134,7 @@ export function apply(ctx, config) {
|
|
|
131
134
|
properties: {
|
|
132
135
|
namespace: {
|
|
133
136
|
type: 'string',
|
|
134
|
-
description: 'The paged namespace to activate, exactly as the catalog names it (for example "codegraph" for mcp__codegraph__* tools).',
|
|
137
|
+
description: 'The paged namespace to activate, exactly as the catalog names it (for example "codegraph" for mcp__codegraph__* tools, or "task_board" for task_board_* tools).',
|
|
135
138
|
},
|
|
136
139
|
},
|
|
137
140
|
required: ['namespace'],
|