@linxin666/dsh-liangshen 0.4.21 → 0.4.23
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 +6 -8
- package/README.zh.md +6 -8
- package/lib/client.js +5 -19
- package/lib/client.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/types/client/LiangShenSettingsCard.d.ts +1 -1
- package/lib/types/client/index.d.ts +2 -2
- package/lib/types/dsh-home.d.ts +13 -3
- package/package.json +28 -23
- package/presets/liangshen/agent.cordis.yml +16 -14
- package/presets/liangshen/dispatcher-rules.mjs +8 -1
- package/presets/liangshen/fact-ledger.mjs +3 -0
- package/presets/liangshen/minimal-prompt.mjs +103 -16
- package/presets/liangshen/paging.mjs +43 -4
- package/presets/liangshen/subagent-routes.mjs +121 -12
- package/presets/liangshen/tool-activate.mjs +43 -3
- package/presets/liangshen/tool-catalog.mjs +266 -44
- package/src/announce.test.ts +2 -2
- package/src/client/LiangShenSettingsCard.tsx +1 -1
- package/src/client/index.ts +3 -3
- package/src/composition.test.ts +2 -2
- package/src/composition.ts +1 -1
- package/src/dsh-home.ts +35 -12
package/lib/index.js
CHANGED
|
@@ -458,7 +458,7 @@ function applyPresetOverrides(rows, overrides) {
|
|
|
458
458
|
const table = overrideTargets(overrides);
|
|
459
459
|
return rows.map((row) => {
|
|
460
460
|
const id = row.id;
|
|
461
|
-
if (id === "tool-executor-ptc" && overrides.presentation !== void 0) return {
|
|
461
|
+
if ((id === "tool-registry-ptc" || id === "tool-executor-ptc") && overrides.presentation !== void 0) return {
|
|
462
462
|
...row,
|
|
463
463
|
disabled: overrides.presentation !== "ptc"
|
|
464
464
|
};
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* a session reads both from its preset. The card is the operator's only handle
|
|
10
10
|
* on them, which is why every field the Host schema carries appears here.
|
|
11
11
|
*/
|
|
12
|
-
import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
|
|
12
|
+
import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots/client';
|
|
13
13
|
import type { SnapshotStore } from '@deepseek-ai/dsh-client-store';
|
|
14
14
|
import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client';
|
|
15
15
|
import { type CardActions, type CardShell, type FieldSpec, type FieldState as CardFieldState } from './settings-form.ts';
|
|
@@ -67,7 +67,7 @@ export interface SettingsPluginItemOwnerProps {
|
|
|
67
67
|
/** Marker field: card owner props are intentionally empty. */
|
|
68
68
|
children?: never;
|
|
69
69
|
}
|
|
70
|
-
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
70
|
+
declare module '@deepseek-ai/dsh-client-ui-slots/client' {
|
|
71
71
|
interface SlotMap {
|
|
72
72
|
/**
|
|
73
73
|
* The child slot the Web UI plugin group declares; this card registers into
|
|
@@ -113,7 +113,7 @@ export interface LiangShenFormSpec<T> {
|
|
|
113
113
|
* `ctx.remote.agentPresets` needs `remote` as well.
|
|
114
114
|
*/
|
|
115
115
|
export declare const inject: string[];
|
|
116
|
-
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
116
|
+
declare module '@deepseek-ai/dsh-client-ui-slots/client' {
|
|
117
117
|
interface LocaleNamespaceMap {
|
|
118
118
|
/** The LiangShen lever copy. */
|
|
119
119
|
'liangshen': LiangShenKey;
|
package/lib/types/dsh-home.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* DSH_HOME resolution shared by the plugin family's Host
|
|
3
|
-
* environment
|
|
4
|
-
*
|
|
2
|
+
* DSH_HOME and DSH_AGENTS_HOME resolution shared by the plugin family's Host
|
|
3
|
+
* halves: environment overrides win (blank values treated as unset), then the
|
|
4
|
+
* platform home fallbacks follow — mirroring `@deepseek-ai/dsh-home-paths`.
|
|
5
5
|
*/
|
|
6
6
|
/** Expand a leading ~ (or ~user) in a path, platform-style. */
|
|
7
7
|
export declare function expandHome(path: string, home?: string): string;
|
|
@@ -14,3 +14,13 @@ export declare function expandHome(path: string, home?: string): string;
|
|
|
14
14
|
export declare function resolveDshHome(env?: NodeJS.ProcessEnv, home?: string): string;
|
|
15
15
|
/** Resolve the DSH home directory from the live environment. */
|
|
16
16
|
export declare function dshHome(): string;
|
|
17
|
+
/**
|
|
18
|
+
* Resolve the shared agent configuration root (`$DSH_AGENTS_HOME`, defaulting
|
|
19
|
+
* to `<home>/.agents`), matching `@deepseek-ai/dsh-home-paths`'s `resolveAgentsHome`.
|
|
20
|
+
* @param env - process environment to read DSH_AGENTS_HOME from.
|
|
21
|
+
* @param home - platform home directory fallback (test seam).
|
|
22
|
+
* @returns the absolute shared agents home path.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveAgentsHome(env?: NodeJS.ProcessEnv, home?: string): string;
|
|
25
|
+
/** Resolve the shared agent configuration root from the live environment. */
|
|
26
|
+
export declare function agentsHome(): string;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linxin666/dsh-liangshen",
|
|
3
3
|
"description": "LiangShen (梁神) agent preset plus its composer lever for the dsh web GUI. The host half declares the bundled preset to the harness's agent-preset registry at activation (declare = enabled), so the preset is selectable for new sessions without writing anything into the harness home; the preset keeps a minimal persona with standing working discipline while the harness's own user-role agent-instructions injection delivers the workspace instructions (the optional `instructionSource: system-prompt` mode lifts them into the prompt instead), and declares one tool presentation for the session's whole lifetime: `ptc` by default (the wire collapses to `run_code` and every other tool is reached through the generated SDK), with `native` as the explicit assembled-roster option. High-fan-out tool families (default `['mcp__*', 'browser_*', 'task_board_*', 'team_*', 'squad*', 'ui_*', 'ssh_*']`, while every host builtin stays resident; customizable via `pagedToolPatterns`) stay paged out of the wire and generated SDK until the preset's own `tool_activate` tool loads their namespace (LRU cap three, state replayed from the durable session event stream), and the tool catalog — exactly the reachable tools plus paged-out namespace summaries — and a one-line working-context projection travel as durable user messages republished only on change. The browser half adds a slot-machine lever left of the model selector on the new-session screen to toggle the mode. Hot-pluggable via cordis.patch.yml + profile symlink, no dsh source changes.",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.23",
|
|
5
5
|
"icon": "icon.svg",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": "
|
|
8
|
+
"node": "^24.22.3 || >=26.13.1"
|
|
9
9
|
},
|
|
10
10
|
"main": "lib/index.js",
|
|
11
11
|
"types": "lib/types/index.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dsh": {
|
|
27
27
|
"engines": {
|
|
28
|
-
"dsh": ">=0.2.
|
|
28
|
+
"dsh": ">=0.2.3-alpha.4"
|
|
29
29
|
},
|
|
30
30
|
"bundle": {
|
|
31
31
|
"patch": "./cordis.patch.yml"
|
|
@@ -42,33 +42,38 @@
|
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@deepseek-ai/dsh": ">=0.2.
|
|
45
|
+
"@deepseek-ai/dsh": ">=0.2.3-alpha.4"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@deepseek-ai/schemastery": "
|
|
48
|
+
"@deepseek-ai/schemastery": "~3.20.0-alpha.3"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@deepseek-ai/cordis": "
|
|
52
|
-
"@deepseek-ai/dsh-agent-preset-registry": "^0.2.
|
|
53
|
-
"@deepseek-ai/dsh-api-remotes": "^0.2.
|
|
54
|
-
"@deepseek-ai/dsh-api-session-controller": "^0.2.
|
|
55
|
-
"@deepseek-ai/dsh-client-connection": "^0.2.
|
|
56
|
-
"@deepseek-ai/dsh-client-locale": "^0.2.
|
|
57
|
-
"@deepseek-ai/dsh-client-store": "^0.2.
|
|
58
|
-
"@deepseek-ai/dsh-client-ui-conversation": "^0.2.
|
|
59
|
-
"@deepseek-ai/dsh-client-ui-renderer": "^0.2.
|
|
60
|
-
"@deepseek-ai/dsh-client-ui-settings": "^0.2.
|
|
61
|
-
"@deepseek-ai/dsh-client-ui-slots": "^0.2.
|
|
62
|
-
"@deepseek-ai/dsh-
|
|
63
|
-
"@deepseek-ai/dsh-
|
|
64
|
-
"@
|
|
51
|
+
"@deepseek-ai/cordis": "~4.2.0-alpha.3",
|
|
52
|
+
"@deepseek-ai/dsh-agent-preset-registry": "^0.2.3-alpha.4",
|
|
53
|
+
"@deepseek-ai/dsh-api-remotes": "^0.2.3-alpha.4",
|
|
54
|
+
"@deepseek-ai/dsh-api-session-controller": "^0.2.3-alpha.4",
|
|
55
|
+
"@deepseek-ai/dsh-client-connection": "^0.2.3-alpha.4",
|
|
56
|
+
"@deepseek-ai/dsh-client-locale": "^0.2.3-alpha.4",
|
|
57
|
+
"@deepseek-ai/dsh-client-store": "^0.2.3-alpha.4",
|
|
58
|
+
"@deepseek-ai/dsh-client-ui-conversation": "^0.2.3-alpha.4",
|
|
59
|
+
"@deepseek-ai/dsh-client-ui-renderer": "^0.2.3-alpha.4",
|
|
60
|
+
"@deepseek-ai/dsh-client-ui-settings": "^0.2.3-alpha.4",
|
|
61
|
+
"@deepseek-ai/dsh-client-ui-slots": "^0.2.3-alpha.4",
|
|
62
|
+
"@deepseek-ai/dsh-ptc-runtime": "^0.2.3-alpha.4",
|
|
63
|
+
"@deepseek-ai/dsh-scope": "^0.2.3-alpha.4",
|
|
64
|
+
"@deepseek-ai/dsh-settings": "^0.2.3-alpha.4",
|
|
65
|
+
"@deepseek-ai/dsh-system-prompt": "^0.2.3-alpha.4",
|
|
66
|
+
"@deepseek-ai/dsh-tool-registry-native": "^0.2.3-alpha.4",
|
|
67
|
+
"@deepseek-ai/dsh-tool-registry-ptc": "^0.2.3-alpha.4",
|
|
68
|
+
"@deepseek-ai/dsh-tools": "^0.2.3-alpha.4",
|
|
69
|
+
"@testing-library/react": "^16.3.3",
|
|
65
70
|
"@types/node": "^22.20.0",
|
|
66
|
-
"@types/react": "~
|
|
67
|
-
"@types/react-dom": "~
|
|
71
|
+
"@types/react": "~19.3.2",
|
|
72
|
+
"@types/react-dom": "~19.3.0",
|
|
68
73
|
"@vitest/coverage-v8": "^4.1.11",
|
|
69
74
|
"jsdom": "^25.0.0",
|
|
70
|
-
"react": "^
|
|
71
|
-
"react-dom": "^
|
|
75
|
+
"react": "^19.3.1",
|
|
76
|
+
"react-dom": "^19.3.1",
|
|
72
77
|
"tsdown": "0.22.2",
|
|
73
78
|
"typescript": "~5.7.2",
|
|
74
79
|
"vitest": "^4.1.11"
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
# the roster on the wire, and `'ptc'` collapses the wire to the single
|
|
11
11
|
# `run_code` transport with every other tool reached from inside the program
|
|
12
12
|
# through the generated SDK. The settings overlay turns that key into the
|
|
13
|
-
# `tool-
|
|
13
|
+
# `tool-registry-ptc` row below, which is what actually decides the wire:
|
|
14
14
|
# 0.2.2 retired `agent.ctx.tools.presentAs`, so no plugin declares it per
|
|
15
15
|
# scope any more, and a deployment with no code runtime keeps the native
|
|
16
16
|
# surface. The retired anchor-turn staging is gone: the legacy `anchorTools`
|
|
@@ -218,8 +218,8 @@
|
|
|
218
218
|
# ── the wire ────────────────────────────────────────────────────────────────
|
|
219
219
|
#
|
|
220
220
|
# `presentation` on the `tool-catalog` row above IS the wire, because the
|
|
221
|
-
# settings overlay turns it into the `tool-
|
|
222
|
-
# ptc
|
|
221
|
+
# settings overlay turns it into the `tool-registry-ptc` row below: a mounted
|
|
222
|
+
# ptc root registry collapses the wire to the single `run_code` transport, and the
|
|
223
223
|
# `native` value disables that row so the roster is what the request carries.
|
|
224
224
|
# The catalog reads the same fact back (a `ptc` setting plus a mounted
|
|
225
225
|
# runtime) because no reader can observe the collapse itself: the ptc
|
|
@@ -266,16 +266,18 @@
|
|
|
266
266
|
- id: fact-ledger
|
|
267
267
|
name: ./fact-ledger.mjs
|
|
268
268
|
|
|
269
|
-
# The child-route guard. The harness
|
|
270
|
-
#
|
|
269
|
+
# The child-route guard. The harness exposes a live `subagentModelSelection`
|
|
270
|
+
# service (`allowedRoutes()`) starting in 0.2.3-alpha.2 (and on older cohorts
|
|
271
|
+
# records `subagent/model-selection-policy` Session events), while its own
|
|
271
272
|
# delegation tool only rejects an EXPLICIT route outside that list: a call that
|
|
272
273
|
# names no `provider`/`model` inherits the parent route unchecked, and an
|
|
273
274
|
# inherit-only tool such as `subagent_fork` cannot name one at all. This row
|
|
274
|
-
# closes that gap on the preset plane — an allowlist
|
|
275
|
-
#
|
|
276
|
-
#
|
|
277
|
-
# policy event,
|
|
278
|
-
# answer keeps the harness's own
|
|
275
|
+
# closes that gap on the preset plane — whenever an allowlist is active, every
|
|
276
|
+
# policed delegation must resolve to an authorized route, and a refusal names the
|
|
277
|
+
# routes that would work. It fails open on every fact it cannot read (no live
|
|
278
|
+
# service / policy event, invalid settings error, no session registry, no
|
|
279
|
+
# registry probe), so a Host that cannot answer keeps the harness's own
|
|
280
|
+
# delegation behavior.
|
|
279
281
|
- id: subagent-routes
|
|
280
282
|
name: ./subagent-routes.mjs
|
|
281
283
|
|
|
@@ -575,8 +577,8 @@
|
|
|
575
577
|
fetch: false
|
|
576
578
|
searchTimeoutMs: 60000
|
|
577
579
|
|
|
578
|
-
# PTC execution is an agent-scoped
|
|
580
|
+
# PTC execution is an agent-scoped root registry in 0.2.3-alpha.3+, and this row IS the
|
|
579
581
|
# presentation: the settings overlay disables it for the native presentation.
|
|
580
|
-
# Without that
|
|
581
|
-
- id: tool-
|
|
582
|
-
name: '@deepseek-ai/dsh-tool-
|
|
582
|
+
# Without that root registry the wire has no `run_code` to carry a program.
|
|
583
|
+
- id: tool-registry-ptc
|
|
584
|
+
name: '@deepseek-ai/dsh-tool-registry-ptc'
|
|
@@ -448,9 +448,13 @@ Plan mode is the user's switch, not a stop this mode manufactures. The official
|
|
|
448
448
|
* pinned fact is read as current state when it is really a reading taken when
|
|
449
449
|
* it was registered: the register is an anchor, and a stale anchor is worse
|
|
450
450
|
* than no anchor because nothing downstream questions it.
|
|
451
|
+
*
|
|
452
|
+
* G17 amends R6/R-W for DSH 0.2.3-alpha.4 subagent settlement notifications
|
|
453
|
+
* carrying error code, HTTP status, or user-stop details. G18 documents that
|
|
454
|
+
* workspace directory Markdown links open the directory in the web sidebar.
|
|
451
455
|
*/
|
|
452
456
|
export const DISPATCHER_RULES_APPENDIX = `
|
|
453
|
-
G7 to G14 below are the local additions to G1 to G6 above: where they conflict with G1 to G6, those entries win. G15 below is a separate addition to R5,
|
|
457
|
+
G7 to G14 below are the local additions to G1 to G6 above: where they conflict with G1 to G6, those entries win. G15 below is a separate addition to R5, G16 governs the fact register this preset injects, G17 amends R6/R-W settlement diagnostics, and G18 covers directory links in replies; none has a counterpart upstream.
|
|
454
458
|
|
|
455
459
|
- G7 Asking budget: at most 4 questions a round, at most 3 rounds, ordered by blast radius—the branch-overturning one first. An unknown whose answers would change neither the path, the acceptance criteria nor the cost is not asked: put it on the assumption list.
|
|
456
460
|
- G8 Assumption exit: if the user declines the interview, or a question is still unanswerable after two rounds, list "I will proceed on these assumptions" (one per line) plus what would bring you back, then continue.
|
|
@@ -462,11 +466,14 @@ G7 to G14 below are the local additions to G1 to G6 above: where they conflict w
|
|
|
462
466
|
- G14 Fact-check dispatches: the read-only check G4 sends is not bound by R5's interview precondition, which covers implementation only; its finding lands in your reply before the next question.
|
|
463
467
|
- G15 Task board is not a dispatch: neither a project card nor a built-in team task (team_task_create and its siblings) substitutes for an R5 dispatch, so an L2 task briefs and dispatches its subagents per R5 whether the card exists or not.
|
|
464
468
|
- G16 Facts are anchors, not sources of truth: a pinned fact records the state when it was registered, so once its subject changes re-read it with a tool before planning on it, and revoke the entry through fact_register once settled. A stale anchor is worse than none: it reads as current, costs a turn to disprove, and is never questioned because you supplied it.
|
|
469
|
+
- G17 Subagent settlement diagnostics: local subagent failure or stop notifications include error codes, HTTP statuses, or user-stop details; use them to separate retryable faults from user-initiated stops, and never auto-re-dispatch a child the user stopped.
|
|
470
|
+
- G18 Directory links in replies: a Markdown link pointing to a workspace directory opens that folder directly in the sidebar, so prefer linking it over pasting a raw directory listing.
|
|
465
471
|
|
|
466
472
|
Violations added here (continuing the anti-pattern list above):
|
|
467
473
|
A. Asking instead of judging: handing over an unknown whose answers change nothing, or inflating a bounded assumption into a blocker.
|
|
468
474
|
B. Asking one decision twice, or reading "either is fine" as no answer.
|
|
469
475
|
C. Planning on a pinned fact whose subject changed, without re-reading it.
|
|
476
|
+
D. Auto-re-dispatching a subagent whose settlement notification reports a user-initiated stop.
|
|
470
477
|
`
|
|
471
478
|
|
|
472
479
|
/** What the prompt appends: the reference block, then the local additions. */
|
|
@@ -151,6 +151,9 @@ export function renderLedgerField(facts) {
|
|
|
151
151
|
export function apply(ctx) {
|
|
152
152
|
ctx.tools.register({
|
|
153
153
|
name: FACT_LEDGER_TOOL,
|
|
154
|
+
// Session-log-only register: never touches the execution machine, so it
|
|
155
|
+
// stays callable inside remote SSH execution environments (DSH 0.2.3-alpha.4+).
|
|
156
|
+
environment: 'independent',
|
|
154
157
|
description: [
|
|
155
158
|
'Pin one key fact into this session working context — the line the runtime projects next to the newest message every step. Use it for the facts a long session must not lose: a hard user constraint, a confirmed architecture decision, a path that already failed.',
|
|
156
159
|
`A fact is one short line (<= ${MAX_FACT_CHARS} chars); at most ${MAX_FACTS} stay pinned, the oldest dropping off. Pass the same text again to no-op; pass the revoke field with a fact tag (or its exact text) to unpin everything under it.`,
|
|
@@ -125,6 +125,19 @@ export const PLAN_POLICY_SECTION_NAME = 'plan:policy'
|
|
|
125
125
|
*/
|
|
126
126
|
export const PTC_SECTION_NAMES = ['tools:ptc-only', 'tools:sdk']
|
|
127
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Official `@deepseek-ai/dsh-mcp-client` on-demand tool catalog sections
|
|
130
|
+
* (`mcp:<serverName>:tools`). Retained automatically so servers configured with
|
|
131
|
+
* `toolLoading: 'on-demand'` remain discoverable alongside LiangShen's compact
|
|
132
|
+
* system prompt.
|
|
133
|
+
*/
|
|
134
|
+
export const MCP_ON_DEMAND_TOOLS_SECTION_RE = /^mcp:.+:tools$/
|
|
135
|
+
|
|
136
|
+
/** Whether a prompt section name is an official on-demand MCP tool catalog section. */
|
|
137
|
+
export function isMcpOnDemandToolsSection(sectionName) {
|
|
138
|
+
return typeof sectionName === 'string' && MCP_ON_DEMAND_TOOLS_SECTION_RE.test(sectionName)
|
|
139
|
+
}
|
|
140
|
+
|
|
128
141
|
/**
|
|
129
142
|
* The section this plugin appends to the prompt with the workspace
|
|
130
143
|
* instructions, and the assembly variable whose value carries the rendered
|
|
@@ -144,7 +157,7 @@ export const WORKSPACE_INSTRUCTIONS_VARIABLE = 'workspace_instructions'
|
|
|
144
157
|
export const INSTRUCTION_SOURCES = ['host', 'system-prompt', 'hint']
|
|
145
158
|
|
|
146
159
|
/** Tools whose executions touch workspace files and may trigger dynamic instruction discovery. */
|
|
147
|
-
export const FILE_TOUCH_TOOL_NAMES = new Set(['read', 'write', 'edit', 'str_replace_editor'])
|
|
160
|
+
export const FILE_TOUCH_TOOL_NAMES = new Set(['read', 'write', 'edit', 'apply_patch', 'str_replace_editor'])
|
|
148
161
|
|
|
149
162
|
/**
|
|
150
163
|
* Instruction file candidates per directory, in the harness's order: the
|
|
@@ -503,31 +516,99 @@ export function instructionHintMessages(messages, state) {
|
|
|
503
516
|
return kept
|
|
504
517
|
}
|
|
505
518
|
|
|
519
|
+
const APPLY_PATCH_FILE_PREFIXES = [
|
|
520
|
+
'*** Add File: ',
|
|
521
|
+
'*** Update File: ',
|
|
522
|
+
'*** Delete File: ',
|
|
523
|
+
'*** Move to: ',
|
|
524
|
+
]
|
|
525
|
+
|
|
526
|
+
function extractApplyPatchPaths(input) {
|
|
527
|
+
if (typeof input !== 'string' || input.length === 0) return []
|
|
528
|
+
const paths = []
|
|
529
|
+
const seen = new Set()
|
|
530
|
+
const record = (raw) => {
|
|
531
|
+
const trimmed = raw.trim()
|
|
532
|
+
if (trimmed.length === 0 || seen.has(trimmed)) return
|
|
533
|
+
seen.add(trimmed)
|
|
534
|
+
paths.push(trimmed)
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
let mode = 'header'
|
|
538
|
+
for (const line of input.split(/\r?\n/)) {
|
|
539
|
+
if (mode === 'add') {
|
|
540
|
+
if (line.startsWith('+')) continue
|
|
541
|
+
mode = 'header'
|
|
542
|
+
} else if (mode === 'hunk') {
|
|
543
|
+
if (line.startsWith('+') || line.startsWith('-') || line.startsWith(' ')) continue
|
|
544
|
+
if (line === '@@' || line.startsWith('@@ ') || line.trim() === '*** End of File') continue
|
|
545
|
+
mode = 'header'
|
|
546
|
+
} else if (mode === 'update') {
|
|
547
|
+
if (line === '@@' || line.startsWith('@@ ')) {
|
|
548
|
+
mode = 'hunk'
|
|
549
|
+
continue
|
|
550
|
+
}
|
|
551
|
+
if (line.startsWith('+') || line.startsWith('-') || line.startsWith(' ')) {
|
|
552
|
+
mode = 'hunk'
|
|
553
|
+
continue
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
const trimmed = line.trim()
|
|
558
|
+
if (trimmed === '*** End Patch') break
|
|
559
|
+
let matched = false
|
|
560
|
+
for (const prefix of APPLY_PATCH_FILE_PREFIXES) {
|
|
561
|
+
if (!trimmed.startsWith(prefix)) continue
|
|
562
|
+
record(trimmed.slice(prefix.length))
|
|
563
|
+
if (prefix === '*** Add File: ') mode = 'add'
|
|
564
|
+
else if (prefix === '*** Update File: ' || prefix === '*** Move to: ') mode = 'update'
|
|
565
|
+
else mode = 'header'
|
|
566
|
+
matched = true
|
|
567
|
+
break
|
|
568
|
+
}
|
|
569
|
+
if (!matched && mode === 'update') mode = 'header'
|
|
570
|
+
}
|
|
571
|
+
return paths
|
|
572
|
+
}
|
|
573
|
+
|
|
506
574
|
/**
|
|
507
|
-
* Extract touched file
|
|
508
|
-
* Synchronously extracts
|
|
575
|
+
* Extract all touched file paths from a ToolExecution object.
|
|
576
|
+
* Synchronously extracts paths from:
|
|
509
577
|
* - `read`, `write`, `edit` via `exec.arguments.file_path`
|
|
578
|
+
* - `apply_patch` via patch headers in `exec.arguments.input`
|
|
510
579
|
* - `str_replace_editor` via `exec.arguments.path`
|
|
511
580
|
* Supports both top-level and PTC nested executions without guessing code strings.
|
|
512
581
|
*/
|
|
513
|
-
export function
|
|
514
|
-
if (!exec || typeof exec !== 'object') return
|
|
515
|
-
if (typeof exec.name !== 'string') return
|
|
516
|
-
if (typeof exec.arguments !== 'object' || exec.arguments === null) return
|
|
582
|
+
export function filePathsFromExecution(exec) {
|
|
583
|
+
if (!exec || typeof exec !== 'object') return []
|
|
584
|
+
if (typeof exec.name !== 'string') return []
|
|
585
|
+
if (typeof exec.arguments !== 'object' || exec.arguments === null) return []
|
|
586
|
+
|
|
587
|
+
if (exec.name === 'apply_patch') {
|
|
588
|
+
return extractApplyPatchPaths(exec.arguments.input)
|
|
589
|
+
}
|
|
517
590
|
|
|
518
591
|
if (exec.name === 'str_replace_editor') {
|
|
519
592
|
if ('path' in exec.arguments && typeof exec.arguments.path === 'string') {
|
|
520
593
|
const p = exec.arguments.path.trim()
|
|
521
|
-
return p.length > 0 ? p :
|
|
594
|
+
return p.length > 0 ? [p] : []
|
|
522
595
|
}
|
|
523
596
|
}
|
|
524
597
|
|
|
525
598
|
if ('file_path' in exec.arguments && typeof exec.arguments.file_path === 'string') {
|
|
526
599
|
const p = exec.arguments.file_path.trim()
|
|
527
|
-
return p.length > 0 ? p :
|
|
600
|
+
return p.length > 0 ? [p] : []
|
|
528
601
|
}
|
|
529
602
|
|
|
530
|
-
return
|
|
603
|
+
return []
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Extract the first touched file path from a ToolExecution object.
|
|
608
|
+
* Kept for compatibility alongside {@link filePathsFromExecution}.
|
|
609
|
+
*/
|
|
610
|
+
export function filePathFromExecution(exec) {
|
|
611
|
+
return filePathsFromExecution(exec)[0]
|
|
531
612
|
}
|
|
532
613
|
|
|
533
614
|
/**
|
|
@@ -791,12 +872,14 @@ export function apply(ctx, config) {
|
|
|
791
872
|
// an error touched nothing.
|
|
792
873
|
if (ev?.type !== 'tool/call' && ev?.type !== 'tool/ptc-dispatch') continue
|
|
793
874
|
if (!ev.data || ev.data.isError === true) continue
|
|
875
|
+
if (ev.data.environment !== undefined) continue
|
|
794
876
|
let args = ev.data.arguments
|
|
795
877
|
if (typeof args === 'string') {
|
|
796
878
|
try { args = JSON.parse(args) } catch {}
|
|
797
879
|
}
|
|
798
|
-
const p
|
|
799
|
-
|
|
880
|
+
for (const p of filePathsFromExecution({ name: ev.data.name, arguments: args })) {
|
|
881
|
+
state.touchedDirs.add(dirname(resolve(cwd, p)))
|
|
882
|
+
}
|
|
800
883
|
}
|
|
801
884
|
} catch {
|
|
802
885
|
// Replay reconstruction fallback
|
|
@@ -848,7 +931,7 @@ export function apply(ctx, config) {
|
|
|
848
931
|
// Logger unavailable
|
|
849
932
|
}
|
|
850
933
|
}
|
|
851
|
-
const sections = assembled.sections.filter(section => keep.has(section?.name))
|
|
934
|
+
const sections = assembled.sections.filter(section => keep.has(section?.name) || isMcpOnDemandToolsSection(section?.name))
|
|
852
935
|
if (sections.length === 0) {
|
|
853
936
|
warnOnce(`${name}: no section matched ${JSON.stringify([...keep])} — `
|
|
854
937
|
+ 'keeping the assembled prompt instead of sending an empty one')
|
|
@@ -896,15 +979,19 @@ export function apply(ctx, config) {
|
|
|
896
979
|
ctx.on('tools/result', (exec, result) => {
|
|
897
980
|
if (instructionSource !== 'system-prompt') return
|
|
898
981
|
if (result?.isError || !exec?.agent || exec?.signal?.aborted) return
|
|
899
|
-
|
|
900
|
-
if (
|
|
982
|
+
// Remote execution environment paths belong to the remote host, not this machine's cwd.
|
|
983
|
+
if (exec.environment !== undefined) return
|
|
984
|
+
const paths = filePathsFromExecution(exec)
|
|
985
|
+
if (paths.length === 0) return
|
|
901
986
|
|
|
902
987
|
const session = exec.agent.session
|
|
903
988
|
if (!session) return
|
|
904
989
|
|
|
905
990
|
const cwd = session.header?.cwd ?? process.cwd()
|
|
906
991
|
const state = getSessionState(session)
|
|
907
|
-
|
|
992
|
+
for (const path of paths) {
|
|
993
|
+
state.touchedDirs.add(dirname(resolve(cwd, path)))
|
|
994
|
+
}
|
|
908
995
|
})
|
|
909
996
|
|
|
910
997
|
// 3. Agent pre-step message filter & dynamic discovery
|
|
@@ -55,6 +55,27 @@ export const DEFAULT_IDLE_RECLAIM_STEPS = 0
|
|
|
55
55
|
/** The activation tool this preset registers. */
|
|
56
56
|
export const TOOL_ACTIVATE_NAME = 'tool_activate'
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Official `@deepseek-ai/dsh-mcp-client` on-demand loader tool name
|
|
60
|
+
* (`mcp__<serverName>__load_tools`). A server configured with
|
|
61
|
+
* `toolLoading: 'on-demand'` already manages its own progressive loading, so
|
|
62
|
+
* its loader — and any tools the agent explicitly loads from that server —
|
|
63
|
+
* must stay resident rather than being paged out a second time by `mcp__*`.
|
|
64
|
+
*/
|
|
65
|
+
export const MCP_ON_DEMAND_LOADER_RE = /^mcp__(.+)__load_tools$/
|
|
66
|
+
|
|
67
|
+
/** Extract the MCP server name from an official on-demand loader tool name, or undefined. */
|
|
68
|
+
export function mcpOnDemandServerOf(name) {
|
|
69
|
+
if (typeof name !== 'string') return undefined
|
|
70
|
+
const match = MCP_ON_DEMAND_LOADER_RE.exec(name)
|
|
71
|
+
return match !== null && match[1].length > 0 ? match[1] : undefined
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Whether a tool name is an official MCP `on-demand` loader (`mcp__<server>__load_tools`). */
|
|
75
|
+
export function isMcpOnDemandLoader(name) {
|
|
76
|
+
return mcpOnDemandServerOf(name) !== undefined
|
|
77
|
+
}
|
|
78
|
+
|
|
58
79
|
/** Validate a positive-integer config value, or fall back when absent. */
|
|
59
80
|
export function integerAtLeast(plugin, value, field, minimum, fallback) {
|
|
60
81
|
if (value === undefined) return fallback
|
|
@@ -102,6 +123,7 @@ export function validatePagedToolPatterns(plugin, value, fallback = DEFAULT_PAGE
|
|
|
102
123
|
*/
|
|
103
124
|
export function patternNamespace(name, pattern) {
|
|
104
125
|
if (typeof name !== 'string' || typeof pattern !== 'string' || !pattern.endsWith('*')) return undefined
|
|
126
|
+
if (isMcpOnDemandLoader(name)) return undefined
|
|
105
127
|
const prefix = pattern.slice(0, -1)
|
|
106
128
|
if (!name.startsWith(prefix)) return undefined
|
|
107
129
|
const rest = name.slice(prefix.length)
|
|
@@ -123,16 +145,33 @@ export function namespaceOf(name, patterns) {
|
|
|
123
145
|
|
|
124
146
|
/**
|
|
125
147
|
* Partition one wire tool list into resident tools and paged-but-inactive
|
|
126
|
-
* namespaces. A paged tool whose namespace is active stays resident.
|
|
127
|
-
*
|
|
148
|
+
* namespaces. A paged tool whose namespace is active stays resident. Official
|
|
149
|
+
* on-demand MCP servers (identified by the presence of
|
|
150
|
+
* `mcp__<server>__load_tools`) keep both their loader and any already-loaded
|
|
151
|
+
* tools resident so two progressive-loading layers do not fight each other.
|
|
152
|
+
* The inactive map is keyed by namespace in sorted order so one surface renders
|
|
128
153
|
* byte-identical text across assemblies.
|
|
129
154
|
*/
|
|
130
155
|
export function partitionWireTools(tools, patterns, activeNamespaces) {
|
|
131
156
|
const resident = []
|
|
132
157
|
const inactive = new Map()
|
|
133
158
|
const active = activeNamespaces instanceof Set ? activeNamespaces : new Set(activeNamespaces ?? [])
|
|
134
|
-
|
|
135
|
-
|
|
159
|
+
const list = Array.isArray(tools) ? tools : []
|
|
160
|
+
const onDemandMcpServers = new Set()
|
|
161
|
+
for (const tool of list) {
|
|
162
|
+
const server = mcpOnDemandServerOf(tool?.name)
|
|
163
|
+
if (server !== undefined) onDemandMcpServers.add(server)
|
|
164
|
+
}
|
|
165
|
+
for (const tool of list) {
|
|
166
|
+
const toolName = tool?.name
|
|
167
|
+
if (typeof toolName === 'string' && toolName.startsWith('mcp__')) {
|
|
168
|
+
const server = toolName.slice('mcp__'.length).split('__')[0]
|
|
169
|
+
if (server !== '' && onDemandMcpServers.has(server)) {
|
|
170
|
+
resident.push(tool)
|
|
171
|
+
continue
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const namespace = namespaceOf(toolName, patterns)
|
|
136
175
|
if (namespace === undefined || active.has(namespace)) {
|
|
137
176
|
resident.push(tool)
|
|
138
177
|
continue
|