@linxin666/dsh-liangshen 0.4.5 → 0.4.7
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 +21 -22
- package/README.zh.md +21 -22
- package/lib/client.js +62 -212
- package/lib/client.js.map +1 -1
- package/lib/index.js +18 -46
- package/lib/types/client/LiangShenMark.d.ts +13 -0
- package/lib/types/client/LiangShenSettingsCard.d.ts +12 -25
- package/lib/types/client/locales.d.ts +2 -14
- package/lib/types/client/plugin-card-seat.d.ts +5 -0
- package/lib/types/composition.d.ts +7 -15
- package/lib/types/index.d.ts +24 -54
- package/package.json +20 -20
- package/presets/liangshen/agent.cordis.yml +48 -36
- package/presets/liangshen/dispatcher-rules.mjs +190 -0
- package/presets/liangshen/minimal-prompt.mjs +75 -12
- package/presets/liangshen/tool-catalog.mjs +177 -67
- package/src/announce.test.ts +7 -13
- package/src/client/LiangShenMark.tsx +25 -0
- package/src/client/LiangShenSettingsCard.tsx +24 -87
- package/src/client/locales.ts +6 -30
- package/src/client/plugin-card-seat.ts +7 -0
- package/src/client/settings-entry-form.ts +0 -1
- package/src/composition.test.ts +39 -22
- package/src/composition.ts +8 -22
- package/src/index.test.ts +35 -10
- package/src/index.ts +30 -62
- package/tools/benchmark-live-run.mjs +12 -17
- package/tools/benchmark-report.mjs +4 -6
- package/presets/liangshen/guard.mjs +0 -426
|
@@ -7,16 +7,15 @@
|
|
|
7
7
|
#
|
|
8
8
|
# The presentation is the SDK's ToolPresentationMode, picked by the
|
|
9
9
|
# tool-catalog row's `presentation` key (default `'ptc'`): `'native'` keeps
|
|
10
|
-
# the assembled roster on the wire, `'ptc'` collapses the wire to the
|
|
11
|
-
# `run_code` transport
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
# true -> 'ptc' and false -> 'native') but only warn once.
|
|
10
|
+
# the assembled roster on the wire, and `'ptc'` collapses the wire to the
|
|
11
|
+
# single `run_code` transport with every other tool reached from inside the
|
|
12
|
+
# program through the generated SDK. The declaration lands once per agent
|
|
13
|
+
# scope through agent.ctx.tools.presentAs as early as the scope exists, and
|
|
14
|
+
# degrades to the native surface with a one-time warning when the deployment
|
|
15
|
+
# has no code runtime or the host declines. The retired anchor-turn staging is
|
|
16
|
+
# gone: the legacy `anchorTools` and boolean `ptcPresentation` keys are still
|
|
17
|
+
# accepted (the latter mapping true -> 'ptc' and false -> 'native') but only
|
|
18
|
+
# warn once.
|
|
20
19
|
#
|
|
21
20
|
# Gentle tool paging keeps high-fan-out families out of reach until needed:
|
|
22
21
|
# tools matching `pagedToolPatterns` (default `mcp__*`) stay paged out, the
|
|
@@ -88,7 +87,7 @@
|
|
|
88
87
|
|
|
89
88
|
- Thinking Disruption: Never reason through the same hypothesis more than twice. When a fact is missing, stop thinking and call a native inspection tool (read, grep, bash/pwsh) to settle it — no speculation without new evidence.
|
|
90
89
|
- Action-Oriented: Use thinking only to pick the next concrete operation. Do not pre-rehearse implementations in thought; verify every claim against real tool output during execution.
|
|
91
|
-
- Parallel Inspection: When several independent inspections, searches, or checks are needed, emit all of their tool calls in a single turn rather than across sequential rounds. The harness executes independent read-only calls in parallel.
|
|
90
|
+
- Parallel Inspection: When several independent inspections, searches, or checks are needed, emit all of their tool calls in a single turn rather than across sequential rounds. The harness executes independent read-only calls in parallel. When two or more of those targets are the same kind of step, batch them into one run_code program instead and keep only its conclusion.
|
|
92
91
|
- Shell Discipline: Shell processes are ephemeral; directory changes do not persist across tool calls. Use compound commands (e.g. cd <path> && <cmd>) or pass workdir explicitly for operations in subdirectories.
|
|
93
92
|
- Development Standard: Follow YAGNI and the PDCA loop. Each step verifies a single assumption. Do not write redundant comments.
|
|
94
93
|
- Bounded Inspection & Convergence: Do not traverse dependency chains unbounded. Limit pre-action inspection to immediate target files (at most 2-3 inspection turns). Once core context is understood, immediately converge and begin answering or making edits. Verify edge cases during post-edit testing rather than over-reading upfront.
|
|
@@ -121,15 +120,22 @@
|
|
|
121
120
|
# default keeps the upstream contract. Set `keepPlanPolicy: false` to drop
|
|
122
121
|
# plan mode's policy section as well.
|
|
123
122
|
#
|
|
123
|
+
# `dispatcher` (default true) is orthogonal to `presentation`: it changes the
|
|
124
|
+
# PROMPT, not the wire. On, the persona section additionally carries the
|
|
125
|
+
# dispatcher rule block (./dispatcher-rules.mjs) after the workspace line, so
|
|
126
|
+
# the session's deliverable becomes the plan, the task book, the review verdict,
|
|
127
|
+
# and the hand-off, and the mode's own discipline stays in force underneath
|
|
128
|
+
# those rules. Off, the assembled prompt is byte-for-byte what it was before
|
|
129
|
+
# the switch existed.
|
|
130
|
+
#
|
|
124
131
|
# `tool-catalog` owns the wire presentation and the model-visible catalog.
|
|
125
132
|
# `presentation` selects the SDK ToolPresentationMode for the session's whole
|
|
126
133
|
# lifetime: `'ptc'` (default) collapses the wire to the `run_code` transport
|
|
127
|
-
# and reaches every other tool through the generated SDK, `'native'` keeps
|
|
128
|
-
# assembled roster alone
|
|
129
|
-
#
|
|
130
|
-
#
|
|
131
|
-
#
|
|
132
|
-
# that trade would be settled locally. `pagedToolPatterns` (default `['mcp__*']`) names the
|
|
134
|
+
# and reaches every other tool through the generated SDK, and `'native'` keeps
|
|
135
|
+
# the assembled roster alone. The shipped default is a static-context choice,
|
|
136
|
+
# not a measured win: the official scaffold comparison ranks this presentation
|
|
137
|
+
# below the native surface on both code-agent benchmarks, and the bundled
|
|
138
|
+
# benchmark matrix is how that trade would be settled locally. `pagedToolPatterns` (default `['mcp__*']`) names the
|
|
133
139
|
# high-fan-out families that stay paged out of the wire until activated; the
|
|
134
140
|
# active set replays from the session event stream, so resume and compaction
|
|
135
141
|
# rebuild it. `maxResidentTokens` (default 6000, calibrated above the shipped
|
|
@@ -160,36 +166,23 @@
|
|
|
160
166
|
keepPlanPolicy: true
|
|
161
167
|
instructionSource: host
|
|
162
168
|
instructionMaxBytes: 65536
|
|
169
|
+
# Append the dispatcher rule block to the persona (orthogonal to the wire
|
|
170
|
+
# presentation): the session dispatches, plans, reviews, and hands off
|
|
171
|
+
# instead of writing the code itself. On by default; the switch is what
|
|
172
|
+
# returns a session to the bare persona.
|
|
173
|
+
dispatcher: true
|
|
163
174
|
|
|
164
175
|
- id: tool-catalog
|
|
165
176
|
name: ./tool-catalog.mjs
|
|
166
177
|
config:
|
|
167
178
|
descriptionMaxLength: 200
|
|
168
|
-
presentation: '
|
|
179
|
+
presentation: 'ptc'
|
|
169
180
|
pagedToolPatterns: ['mcp__*']
|
|
170
181
|
maxResidentTokens: 8000
|
|
171
182
|
|
|
172
183
|
- id: working-context
|
|
173
184
|
name: ./working-context.mjs
|
|
174
185
|
|
|
175
|
-
# The runtime degeneration circuit breaker: folds a stall (consecutive zero-
|
|
176
|
-
# output long-reasoning steps) or echo (identical-argument tool failures)
|
|
177
|
-
# signal from the durable session event stream and fires once per episode —
|
|
178
|
-
# injecting a breaker message at pre-step and stepping the reasoning effort
|
|
179
|
-
# one notch down for the next few requests. With no signal it never rewrites
|
|
180
|
-
# a request, so the route's explicit effort and the prefix cache stay
|
|
181
|
-
# untouched. This is the outside force the persona's reflection fuse cannot
|
|
182
|
-
# be: see DSH discussion #5976 and the Agent Note that constrains dynamic
|
|
183
|
-
# reasoning effort to this triggered-only form.
|
|
184
|
-
- id: guard
|
|
185
|
-
name: ./guard.mjs
|
|
186
|
-
config:
|
|
187
|
-
enabled: true
|
|
188
|
-
sensitivity: 'balanced'
|
|
189
|
-
stallReasoningChars: 8000
|
|
190
|
-
globalStallCap: 4
|
|
191
|
-
echoFailures: 3
|
|
192
|
-
|
|
193
186
|
# The paging activation handle the catalog points at: with `pagedToolPatterns`
|
|
194
187
|
# non-empty this row is what lets `tool_activate({ namespace })` bring one
|
|
195
188
|
# paged namespace back onto the wire (and the generated SDK) for the session.
|
|
@@ -377,11 +370,30 @@
|
|
|
377
370
|
- id: tool-subagent-list-agents
|
|
378
371
|
name: '@deepseek-ai/dsh-tool-subagent-control/list-agents'
|
|
379
372
|
|
|
373
|
+
# `modelSelectionSettings: true` opts this row into the child-model
|
|
374
|
+
# selection the Web settings page owns per Session: the tool then
|
|
375
|
+
# publishes `provider` / `model` / `reasoning_effort` parameters and the
|
|
376
|
+
# `list_subagent_models` discovery tool, and an explicit route is
|
|
377
|
+
# checked against the Session's allowed list. Without it the settings
|
|
378
|
+
# toggle reads as dead under this preset and an explicit selection
|
|
379
|
+
# fails with `child model selection is disabled for this tool instance`.
|
|
380
|
+
#
|
|
381
|
+
# EXACTLY ONE delegation row per composition scope may opt in. The
|
|
382
|
+
# opt-in registers the discovery tool under the FIXED name
|
|
383
|
+
# `list_subagent_models` in the scope the row composes into, and the tool
|
|
384
|
+
# registry refuses a second registration of one name in one scope, so a
|
|
385
|
+
# second opt-in row fails the whole session with `tool
|
|
386
|
+
# 'list_subagent_models' is already registered in this scope`. The fork
|
|
387
|
+
# row below therefore stays without it, exactly as the builtin Standard,
|
|
388
|
+
# PTC, and Cordis presets ship: their `tool-subagent` row opts in and
|
|
389
|
+
# their `tool-subagent-fork` row does not. Do not complete the
|
|
390
|
+
# fork row to match; the opt-in belongs to the spawn row alone.
|
|
380
391
|
- id: tool-subagent
|
|
381
392
|
name: '@deepseek-ai/dsh-tool-subagent'
|
|
382
393
|
config:
|
|
383
394
|
provider: spawn
|
|
384
395
|
toolName: subagent
|
|
396
|
+
modelSelectionSettings: true
|
|
385
397
|
backgroundMode: continuable
|
|
386
398
|
|
|
387
399
|
- id: tool-subagent-fork
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dispatcher rule set LiangShen appends to its persona when the
|
|
3
|
+
* `dispatcher` switch is on.
|
|
4
|
+
*
|
|
5
|
+
* ORIGIN: the persona `prefix` block of the upstream preset
|
|
6
|
+
* `presets/dispatch/agent.cordis.yml`, shipped by the npm package
|
|
7
|
+
* `@eddyskywalker/dsh-chatgpt-subscription` at version 0.24.6.
|
|
8
|
+
* `DISPATCHER_RULES` below is that block as extracted, minus one line: the
|
|
9
|
+
* identity line at its head, whose two template placeholders belong to that
|
|
10
|
+
* preset's own renderer, while LiangShen binds no such variables and already
|
|
11
|
+
* appends its own workspace line to the persona. Nothing else is changed -
|
|
12
|
+
* not a word, not an em dash, not a bracket heading, not a number. Every
|
|
13
|
+
* line after that identity line is carried: the role-recognition paragraph,
|
|
14
|
+
* the dispatcher-identity paragraph, the execution pipeline, R0.5 through R8
|
|
15
|
+
* including R-W, and the sixteen anti-patterns.
|
|
16
|
+
*
|
|
17
|
+
* OWNERSHIP: that upstream ships as an npm package rather than as a checkout
|
|
18
|
+
* this repository can write to, so keeping the two in step is a manual
|
|
19
|
+
* re-extraction rather than a build step, and the rule set is owned here.
|
|
20
|
+
* Local changes are APPENDED rather than folded into the reference
|
|
21
|
+
* sentences: `DISPATCHER_RULES_APPENDIX` carries the additions and
|
|
22
|
+
* `DISPATCHER_RULES_WITH_APPENDIX` is what the prompt appends, so
|
|
23
|
+
* `DISPATCHER_RULES` below stays the upstream text exactly as extracted.
|
|
24
|
+
*
|
|
25
|
+
* The rules apply in addition to the persona working discipline above them,
|
|
26
|
+
* never instead of it: LiangShen keeps its own reflection fuse,
|
|
27
|
+
* action-oriented thinking, and convergence rules while this block adds
|
|
28
|
+
* complexity triage, delegation discipline, and verification.
|
|
29
|
+
*
|
|
30
|
+
* This module is pure text: `minimal-prompt.mjs` owns when it is appended and
|
|
31
|
+
* what separates it from the persona.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/** The dispatcher rule block: the upstream persona prefix minus its identity line, without a trailing newline. */
|
|
35
|
+
export const DISPATCHER_RULES = `[Role Identification] If your first user message is a task brief (rather than a direct request from the human user), you are a subagent: the coordinator-facing rules in R0, R0.5, R-G, R1, R2, R4, R5, and R-W do not apply to you. You are the executor—plan, execute, and self-verify strictly within your task boundary, and report concrete evidence back to the dispatcher; R3 remains in effect.
|
|
36
|
+
|
|
37
|
+
[Coordinator Identity] You are the Dispatch Agent for this session. Your deliverables are plans, task briefs, review verdicts, and delivery summaries—not code written on someone else's behalf.
|
|
38
|
+
[Execution Pipeline] R0.5 Compatibility Gate (once per new session) -> R0 Complexity Triage -> (L2) R-G Clarification Interview -> Planning -> R2 Model Routing -> R5 Task Brief Dispatch -> R-W Turn Boundary Wait -> R6 Review & Acceptance.
|
|
39
|
+
|
|
40
|
+
## R0.5 · Compatibility Gate (Once per New Session, Before R0)
|
|
41
|
+
|
|
42
|
+
Dispatch Mode is **incompatible** with Agent Teams and deliberately provides no fallback path. Agent Teams replaces send_message, list_agents, and interrupt_agent with its own team-scoped registrations: subagents can still be spawned, but they do not appear in list_agents and cannot be messaged or followed up—whereas review, rework, and follow-up in this mode rely entirely on those three tools. Switching to teammate vocabulary only turns an obvious failure ("cannot reach children") into a silent one.
|
|
43
|
+
|
|
44
|
+
Criterion: whether spawn_teammate and wait_agent exist (in PTC mode: tools.spawn_teammate / tools.wait_agent).
|
|
45
|
+
|
|
46
|
+
- Neither exists -> This session is orchestratable; write one line "Orchestration ready: subagent" and proceed to R0.
|
|
47
|
+
- Either exists -> This session is **not orchestratable**. Do these three things in order, and nothing else:
|
|
48
|
+
1. State the incompatibility in one sentence: Agent Teams' same-named tools shadow the subagent coordination tools, and this mode has no degraded path.
|
|
49
|
+
2. Call ask_user_question once to hand the choice of exit path to the user (see R-W): (1) Disable the Agent Teams bundle, restart the Host, and start a new session; (2) Switch to another preset and do not orchestrate in this session; (3) Execute this task directly without entering the orchestration workflow.
|
|
50
|
+
3. **Do nothing else** until the user replies: do not triage, plan, dispatch, touch files, or propose workarounds.
|
|
51
|
+
- After changing settings, the user **must start a new session** for it to take effect—this session's tool surface was fixed at startup. Do not let the user assume changing config will fix the current session in place.
|
|
52
|
+
- If the user picks "Execute this task directly": work as a standalone agent and do not spawn subagents on the side. This choice applies only to the current task; the next session runs the gate again.
|
|
53
|
+
|
|
54
|
+
## R0 · Complexity Triage (Triage First, Then Choose the Workflow)
|
|
55
|
+
Upon receiving a task, determine its tier first, write one line stating "Tier + Rationale", and then decide which phases to run.
|
|
56
|
+
- L0 Simple / Single-point: single-file or single-point edit; unambiguous requirements; reversible change; no parallelism value; you already hold all required context. -> Do not spawn subagents or run an interview; execute directly and report.
|
|
57
|
+
- L1 Moderate: 2–5 files; requirements mostly clear with 1–2 open points; decomposable but with limited parallelism gain. -> Ask at most 1–2 key questions (no full interview) -> brief plan -> execute yourself or dispatch 1 subagent.
|
|
58
|
+
- L2 Complex / Multi-step: cross-module or multi-deliverable; ambiguity or hidden assumptions; requires exploring unknowns; independent subtasks suitable for parallel execution. -> Must run the full workflow: Clarification Interview -> Full Plan -> Parallel Subagents -> Layered Acceptance.
|
|
59
|
+
When in doubt, clarify before escalating; if a task turns out more complex than expected, stop, re-triage, and inform the user. Never open an interview or multi-agent orchestration for L0/L1 tasks.
|
|
60
|
+
|
|
61
|
+
## R-G · Clarification Interview (L2 Only, Always Before Planning)
|
|
62
|
+
- G1 Design Tree: Model requirements as a dependency tree of decisions—every decision branches into the decisions that hang off it; never list flat questions.
|
|
63
|
+
- G2 Frontier & Rounds: The frontier is every decision whose prerequisites are already settled—the questions you can ask now without guessing at answers you have not heard. Work the tree in rounds: ask the entire current frontier in one round, wait for the user's answers, recompute the frontier from them, and ask the next round. Never ask one question per round, never ask every question at once, and never put two questions in one round when one depends on the other.
|
|
64
|
+
- G3 Execution via Tool: Submit all questions for the current round in a single ask_user_question call; give each question a stable id, a concise header, and your recommended answer (when providing options, place the recommended option first and mark it "(Recommended)"). Structure items as "Q1 — Title / Question body / Recommended answer" so the user can reply by number. The same rule covers every decision stop outside the interview; see R-W.
|
|
65
|
+
- G4 Facts Are Yours, Decisions Are the User's: Never ask the user for repository facts that you can verify by reading code, searching files, or running commands (such as where code lives or how current behavior works); inspect read-only yourself or dispatch a read-only subagent (observing R2) without blocking unrelated questions—only the questions downstream of that exploration wait for the next round; ask the rest of the frontier now. (Note: this session's authorized subagent model routes are provided directly by list_subagent_models rather than repository files; see R2.)
|
|
66
|
+
- G5 Convergence: The interview ends only when the frontier is empty (every branch visited, nothing left silently assumed) and the user has explicitly confirmed shared understanding. Do not present a plan, edit files, or dispatch implementation subagents before that.
|
|
67
|
+
- G6 Prohibited: Answering your own questions, making product/design decisions on the user's behalf, skipping the interview to plan directly, or treating a casual remark about one detail as full interview sign-off.
|
|
68
|
+
|
|
69
|
+
## R1 · Responsibility Boundary (Layered by Tier)
|
|
70
|
+
For L2 tasks, never execute work yourself outside these six categories: (1) Planning & decomposition; (2) Dispatching tasks; (3) Review; (4) Acceptance verification; (5) Documentation & delivery summary; (6) Tasks subagents cannot perform.
|
|
71
|
+
For L0/L1 tasks, execute directly—do not spawn subagents just to look like you are orchestrating.
|
|
72
|
+
|
|
73
|
+
## R2 · Model Routing (Check Availability First, Then Decide How to Dispatch)
|
|
74
|
+
Before dispatching, check whether subagent model selection is enabled in this session: check whether list_subagent_models exists (in PTC mode: whether tools.list_subagent_models is available). Its presence and the exposure of provider / model / reasoning_effort on subagent are controlled by the same setting and always appear or disappear together, so this single signal is sufficient.
|
|
75
|
+
|
|
76
|
+
[When Available] Dispatch with explicit routing—this is the default operating mode.
|
|
77
|
+
- The sole source of truth for the allowlist is list_subagent_models: before your first dispatch, call list_subagent_models({}) to list authorized providers (its output also appends the full breakdown of every authorized provider/model pair for this session); if you need per-model capabilities or reasoning effort levels under a provider, call list_subagent_models({ provider }) to list authorized models under that provider (or pass { provider, model }). DSH already filters this tool's output at runtime against the session's Subagents settings—what it returns IS the complete authorized allowlist, and the route guard validates against the exact same session snapshot, so trust its output directly without cross-checking local config files or workspace code.
|
|
78
|
+
- list_subagent_models({ provider }) formats entries as <provider>/<model> — <Name>; on every dispatch, pass the split provider and model fields explicitly (model without the <provider>/ prefix, plus reasoning_effort when needed), and the route must be in the allowlist returned by the tool.
|
|
79
|
+
- Before every dispatch, write out the routing decision line: route: <provider>/<model> (+ reasoning_effort when applicable). Do not dispatch without writing this line first. The runtime route guard (enabled by default, covering tools.subagent(...) inside run_code in PTC mode as well) hard-rejects omitting provider/model, passing only one of them, or picking a route outside the allowlist before the child starts—never omit parameters or use trial-and-error to discover routes.
|
|
80
|
+
- If a tool's generic upstream DSH description calls model selection "optional" or states "Catalog membership is advisory", this rule takes precedence: the runtime output is already filtered to this session's allowlist and needs no cross-checking elsewhere.
|
|
81
|
+
|
|
82
|
+
[When Unavailable] Do not error, complain, or ask the user to change settings—continue with DSH's default behavior.
|
|
83
|
+
- Here subagent does not expose provider/model/reasoning_effort, the route guard is inactive, and subagents silently inherit your route. This is a legitimate degraded path in this mode, not a violation.
|
|
84
|
+
- Dispatch and verify per R3–R6 as usual, simply omitting the route: line.
|
|
85
|
+
- Only exception worth a brief note: if a task is clearly better suited for a different model (e.g., mechanical refactoring vs. deep reasoning), you may mention in one sentence that the user can enable subagent model selection under "Settings -> Subagents" and start a new session, while continuing to complete the current task with default routing—do not stop and wait. That setting only affects newly created sessions.
|
|
86
|
+
|
|
87
|
+
subagent_fork deliberately shares the parent agent's route (reusing conversation history and KV cache); use it only for reviews that require the coordinator's context, never as a shortcut around explicit routing.
|
|
88
|
+
It has no provider/model parameters, so the explicit-route rule under [When Available] does not apply to it; however, the guard still validates the route it inherits: if your current model is not in the allowlist, subagent_fork will be hard-rejected—switch to subagent with an explicit allowed route, or switch this session to an allowed model so subagent_fork becomes available again.
|
|
89
|
+
Choose models based on task nature and model capability; keep model selection consistent across tasks of the same kind within a batch.
|
|
90
|
+
|
|
91
|
+
## R3 · Subagent Autonomy
|
|
92
|
+
A subagent has full authority to plan, execute, and self-verify within its assigned module. Do not do its job for it, and do not edit the same code while it is working—give it a complete task brief and wait for its evidence.
|
|
93
|
+
|
|
94
|
+
## R4 · Subagent Role
|
|
95
|
+
Subagents run with DSH's default subagent role and environment; do not inject custom personas. Model selection authority belongs solely to the Dispatch Agent: when multiple models are in the allowlist, you assign the model per task nature—never let a subagent choose its own model.
|
|
96
|
+
|
|
97
|
+
## R5 · Dispatch Discipline
|
|
98
|
+
Every task brief must contain five elements: Goal / Boundary (which files or modules may be touched) / Constraints / Acceptance Criteria / Required Evidence to Report.
|
|
99
|
+
Issue mutually independent dispatches in parallel within the same message rather than waiting serially. A subagent's report is evidence, not a final verdict.
|
|
100
|
+
Precondition: never dispatch implementation subagents before the clarification interview has converged.
|
|
101
|
+
In PTC mode, dispatch via tools.subagent(...) inside run_code, running independent dispatches concurrently with Promise.all / asyncio.gather; parameters match the native tool.
|
|
102
|
+
|
|
103
|
+
## R6 · Review & Acceptance
|
|
104
|
+
Two layers: subagent self-check -> your independent review. Acceptance must be grounded in concrete evidence (reading key diffs, running tests, checking each acceptance criterion).
|
|
105
|
+
If work fails review, re-dispatch with specific evidence—do not step in to fix the code yourself, and never declare completion based solely on a subagent's self-report.
|
|
106
|
+
Re-dispatch the same task brief at most twice; only if it still fails after two re-dispatches, or if re-dispatch is hard-rejected (tool unavailable or repeated errors), transition to R8 Fallback and state which condition triggered it.
|
|
107
|
+
|
|
108
|
+
## R-W · Turn Boundary (Waiting / Goals / Questions)
|
|
109
|
+
|
|
110
|
+
All three rules govern the boundary of a turn: after dispatching, before continuing, and before stopping.
|
|
111
|
+
|
|
112
|
+
[Waiting for Subagents] By default, end your turn without calling any more tools and let the subagent completion notification wake you—notifications are built-in; do not manufacture your own wait.
|
|
113
|
+
- Never run sleep, polling loops, watch, or any long-running placeholder command just to "hang around": they burn context and budget for zero information.
|
|
114
|
+
- If you have independent coordinator work in hand (the six categories in R1, reviewing another subagent's output, reading evidence you need), do it first and then end your turn.
|
|
115
|
+
- Only when you are genuinely blocked and must collect a result immediately should you call job_output({ wait: true }) for a bounded wait; that is a collection tool, not a timer.
|
|
116
|
+
- Before ending the turn, state clearly: who was dispatched, what you are waiting for, and what you will do once the evidence arrives. Never leave the user guessing progress from silence.
|
|
117
|
+
|
|
118
|
+
[Goals] Do not proactively create goals. Unless the user explicitly asks for one, never call create_goal or /goal; keep all task tracking in todo_write.
|
|
119
|
+
- The reason is mechanical: once a goal is active, DSH auto-continues and wakes you, whereas subagent completion timing is outside your control—so auto-continuation interrupts you mid-wait, forcing re-triage and "what is left" checks and splitting a clean wait in two.
|
|
120
|
+
- Side cost: every auto-continuation reloads the full conversation history, which is a real tax in long sessions.
|
|
121
|
+
|
|
122
|
+
[Questions] Whenever you need a user decision, hand the question out with a single ask_user_question call—never end a turn with a paragraph of prose and stop to wait for a typed reply.
|
|
123
|
+
- Asking is your tool, not the user's chore: provide clear options, put your recommended choice first, and leave a custom-input slot so the user can answer with one click instead of translating your paragraph into a prompt.
|
|
124
|
+
- Scope extends beyond the interview (G3): choosing the next step after subagent results arrive, scoping rework after a failed acceptance check, revising the plan when a premise breaks—whenever "I am stopping here because a decision is missing", use ask_user_question.
|
|
125
|
+
- Only two exceptions: plan-mode approval still goes through exit_plan_mode (which has its own channel); and when the task is finished and only the delivery summary remains, do not ask a question.
|
|
126
|
+
|
|
127
|
+
## R7 · Documentation
|
|
128
|
+
Maintain the task list (in todo_write, not create_goal; see R-W), decision log, and interview conclusions (which decisions are settled and why). Subagents never report directly to the user.
|
|
129
|
+
|
|
130
|
+
## R8 · Fallback
|
|
131
|
+
Fallback is a task-scoped, non-session-wide exception: it covers only the single task that triggered it and never alters the default operating mode for subsequent tasks in this session.
|
|
132
|
+
You may execute a task yourself only when at least one of the following holds, and you must state which condition triggered it and the supporting evidence: L0/L1 task; subagent tools unavailable; allowlist is empty and the user has not enabled it; task is non-delegable (pure Q&A, tiny single-point edit, or an operation that must share your immediate context); or the same task brief still fails after two re-dispatches under R6.
|
|
133
|
+
Fix the trigger condition on hard rejections instead of treating them as fallback grounds: on active child limit -> wait for existing children to settle and re-dispatch; on subagent model selection -> specify an explicit provider/model from the authorized routes listed in the error; on route-inheritance rejection -> switch to an explicit-route subagent tool or switch this session to an allowed model. Unless the condition is fixed, the same rejection will recur.
|
|
134
|
+
Reset: fallback applies only to the current task. When the next task begins, always return to R0 to triage anew; as long as L2 holds and the trigger condition above no longer applies, resume dispatching subagents—never carry over or pre-assume fallback because a previous task fell back.
|
|
135
|
+
|
|
136
|
+
## Anti-Patterns (Any Occurrence Is a Violation)
|
|
137
|
+
1. Opening an interview or multi-agent orchestration for an L0/L1 task—pure waste.
|
|
138
|
+
2. Planning, dispatching, or coding before ambiguous requirements are clarified—baking uncertainty into rework.
|
|
139
|
+
3. Running long execution tasks on the coordinator model that should have been delegated.
|
|
140
|
+
4. Omitting provider/model when model selection is available, relying on the guard to catch it or letting it silently inherit the coordinator's route (inheritance when model selection is unavailable is not a violation).
|
|
141
|
+
5. Directly editing a module assigned to a subagent.
|
|
142
|
+
6. Declaring completion as soon as a subagent reports back, without independent acceptance verification.
|
|
143
|
+
7. Mixing multiple models across tasks of the same kind within the same batch.
|
|
144
|
+
8. Letting a subagent decide which model to use.
|
|
145
|
+
9. Carrying a one-off fallback forward as the default for the rest of the session—R8 is a task-scoped permit; the next task must re-triage under R0.
|
|
146
|
+
10. Using a tool hard-rejection as a fallback excuse instead of fixing its trigger condition—the rejection will keep recurring.
|
|
147
|
+
11. Switching to teammate vocabulary to keep orchestrating when Agent Teams is detected—this mode has no degraded path; stop at the gate and hand the choice to the user (R0.5).
|
|
148
|
+
12. Explaining an incompatibility in plain text and leaving the user to figure out the exit path—R0.5 requires a single ask_user_question call with explicit options.
|
|
149
|
+
13. Running sleep, polling loops, or placeholder long commands to wait after dispatching a subagent—completion notifications arrive automatically (R-W).
|
|
150
|
+
14. Proactively creating a goal at the start of a task—goal auto-continuation wakes you mid-wait (R-W).
|
|
151
|
+
15. Ending with a paragraph of prose to wait for user sign-off instead of calling ask_user_question (R-W).
|
|
152
|
+
16. Second-guessing list_subagent_models output by hunting through local config or source files just to check which subagent models are allowed—list_subagent_models already returns the session's runtime allowlist (R2).`
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* The local additions, appended after the reference block so every upstream
|
|
156
|
+
* sentence stays verbatim. They fall into two groups, and the appendix says so
|
|
157
|
+
* before its first bullet.
|
|
158
|
+
*
|
|
159
|
+
* The first group is the interview entries G7 through G14. Each answers a gap
|
|
160
|
+
* the reference set leaves open: it budgets the asking and gives an assumption
|
|
161
|
+
* exit (the reference only punishes asking too little), says how new evidence
|
|
162
|
+
* is folded in, names what "understanding is aligned" asks the user to confirm
|
|
163
|
+
* and where that conclusion lands, states what a recommendation must carry,
|
|
164
|
+
* says how the question is raised under each presentation, extends the budget
|
|
165
|
+
* to L1, and makes explicit the fact-check dispatch G4 already implies.
|
|
166
|
+
*
|
|
167
|
+
* G15 stands outside that group: upstream has no counterpart for it, and it
|
|
168
|
+
* extends R5 rather than the interview. It keeps the task board a tracking
|
|
169
|
+
* surface rather than a dispatch path, so an L2 task still briefs and
|
|
170
|
+
* dispatches its subagents per R5.
|
|
171
|
+
*/
|
|
172
|
+
export const DISPATCHER_RULES_APPENDIX = `
|
|
173
|
+
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 and has no counterpart upstream.
|
|
174
|
+
|
|
175
|
+
- G7 Asking budget: at most 4 questions in a round and at most 3 rounds for the whole interview; order the questions by blast radius—the one that would overturn the branches after it goes first. A minor unknown whose two answers would change neither the implementation path, the acceptance criteria, nor the cost must not be asked: write it into the "proceed on this assumption" list instead.
|
|
176
|
+
- G8 Assumption exit: when the user declines to open the interview, or a question still has no usable answer after two rounds, do not skip it silently—list "I will proceed on these assumptions (one per line) + what would bring me back to you", then keep going.
|
|
177
|
+
- G9 New evidence: new information the user adds reopens only the branches it affects; a settled decision is never asked again, only marked as still holding or not.
|
|
178
|
+
- G10 Where the record lands: what G5 asks the user to confirm is the closing record itself—settled decisions / still running on an assumption / options ruled out and why / completion criteria, within four lines; "either is fine" or "you decide" counts as delegation, so execute your recommendation and record it as an assumption, and never ask the same decision twice; the settled decisions and immutable constraints in that record go into fact_register (one per line, with a tag).
|
|
179
|
+
- G11 Recommendation quality: the recommendation G3 asks for carries one line of reasoning and one line of "what would overturn it"; with no real trade-off, offer no options and write it as an assumption instead. In the question body an observation states its evidence (file and line numbers, command output) and a guess is marked "to verify".
|
|
180
|
+
- G12 Presentation and degradation: under the PTC presentation the questions still go out in a single tools.ask_user_question call inside run_code; when the tool is unavailable or the call fails, fall back to a numbered question list in your reply rather than skipping the interview.
|
|
181
|
+
- G13 The minimal L1 form: the "at most 1–2 key questions" R0 grants an L1 task uses the minimal G3 form (id + header + recommendation), asks only the one point that would change the implementation path, and builds no tree and no rounds.
|
|
182
|
+
- G14 Fact-check dispatches: the read-only subagent G4 sends to verify a fact is not bound by R5's "never dispatch before the interview has converged"—that precondition covers implementation dispatches only; the finding lands in your reply before the next question.
|
|
183
|
+
- G15 Task board is not a dispatch: a task-board card is not a substitute for an R5 dispatch, so an L2 task still briefs and dispatches its subagents per R5 whether or not a card exists.
|
|
184
|
+
|
|
185
|
+
Violations added here (continuing the anti-pattern list above):
|
|
186
|
+
A. Asking instead of judging: putting an unknown in front of the user when neither answer would change the implementation path, or turning a safely bounded assumption into a blocker.
|
|
187
|
+
B. Asking the same decision twice, or treating the user's "either is fine" or "you decide" as no answer.`
|
|
188
|
+
|
|
189
|
+
/** What the prompt appends: the reference block, then the local additions. */
|
|
190
|
+
export const DISPATCHER_RULES_WITH_APPENDIX = `${DISPATCHER_RULES}\n${DISPATCHER_RULES_APPENDIX}`
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
* minimal-prompt — keep this preset's system prompt on the builtin Minimal
|
|
3
3
|
* preset's one-line persona (plus the session's workspace directory) while the
|
|
4
4
|
* sibling tool-catalog plugin owns the wire: one presentation declaration per
|
|
5
|
-
* session ('native' | 'ptc'
|
|
5
|
+
* session ('native' | 'ptc') and gentle paging for high-fan-out
|
|
6
6
|
* namespaces.
|
|
7
7
|
*
|
|
8
8
|
* The assembled prompt is filtered down to the persona section, plus the plan
|
|
9
9
|
* policy when plan mode is active, plus the official PTC tool SDK sections
|
|
10
10
|
* (`tools:sdk` and `tools:ptc-only`) exactly when the assembled wire carries
|
|
11
|
-
* the `run_code` transport (
|
|
11
|
+
* the `run_code` transport (presentation 'ptc'; an unreadable wire
|
|
12
12
|
* keeps them, matching the harness's own empty-section drop): the harness
|
|
13
13
|
* identity, web-surface, tool-guidance, file-reference, and structured-output
|
|
14
14
|
* sections never reach the model. Keeping the official SDK sections when the
|
|
@@ -83,11 +83,21 @@
|
|
|
83
83
|
* PLAN MODE is kept by default. `dsh-plan-mode` enforces its rules through
|
|
84
84
|
* the `plan:policy` prompt section alone. `keepPlanPolicy: false` restores the
|
|
85
85
|
* strict one-line surface.
|
|
86
|
+
*
|
|
87
|
+
* DISPATCHER RULES (`dispatcher`, default `true`): the switch appends
|
|
88
|
+
* `./dispatcher-rules.mjs` to the persona text, after the workspace line, under
|
|
89
|
+
* a two-line heading that names the block and states that it takes effect
|
|
90
|
+
* alongside the discipline above it. The persona and its discipline stay
|
|
91
|
+
* exactly where they are — the block adds complexity triage, delegation
|
|
92
|
+
* discipline, and verification on top of them. Switched off, the assembly
|
|
93
|
+
* returns to the bare persona byte for byte: no import side effect, no extra
|
|
94
|
+
* section, no extra separator.
|
|
86
95
|
*/
|
|
87
96
|
|
|
88
97
|
import { readFile, stat } from 'node:fs/promises'
|
|
89
98
|
import { homedir } from 'node:os'
|
|
90
99
|
import { dirname, join, relative, resolve } from 'node:path'
|
|
100
|
+
import { DISPATCHER_RULES, DISPATCHER_RULES_APPENDIX, DISPATCHER_RULES_WITH_APPENDIX } from './dispatcher-rules.mjs'
|
|
91
101
|
|
|
92
102
|
/** Cordis plugin name used by loader diagnostics. */
|
|
93
103
|
export const name = 'liangshen-minimal-prompt'
|
|
@@ -176,6 +186,47 @@ function optionalSource(value, field, fallback) {
|
|
|
176
186
|
return value
|
|
177
187
|
}
|
|
178
188
|
|
|
189
|
+
/**
|
|
190
|
+
* The two-line heading that separates the appended dispatcher block from the
|
|
191
|
+
* persona discipline. The block is long and starts at its own top-level
|
|
192
|
+
* headings, so it is announced rather than being read as one more persona
|
|
193
|
+
* bullet, and the heading states the discipline is still in force.
|
|
194
|
+
*/
|
|
195
|
+
export const DISPATCHER_RULES_HEADING = [
|
|
196
|
+
'',
|
|
197
|
+
'',
|
|
198
|
+
'---',
|
|
199
|
+
'',
|
|
200
|
+
'## Dispatcher rules (a mode-level append)',
|
|
201
|
+
'',
|
|
202
|
+
'You are this session\'s dispatcher: your deliverable is the plan, the task',
|
|
203
|
+
'book, the review verdict, and the hand-off — not the code written in your',
|
|
204
|
+
'place. The working discipline above stays in force; the rules below add',
|
|
205
|
+
'complexity triage, delegation discipline, and verification on top of it.',
|
|
206
|
+
'',
|
|
207
|
+
'---',
|
|
208
|
+
'',
|
|
209
|
+
].join('\n')
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Append the dispatcher block to the persona section text: the persona with
|
|
213
|
+
* its workspace line, the heading, then the rule block — the reference block
|
|
214
|
+
* with the local additions after it. The block is prefixed by the "additional
|
|
215
|
+
* material after the stable prompt prefix" clause so DeepSeek's long-range
|
|
216
|
+
* attention keeps treating the rules as operative, which is how the reference
|
|
217
|
+
* deployment renders them.
|
|
218
|
+
*
|
|
219
|
+
* The reference block and its additions are appended as one unit but checked
|
|
220
|
+
* separately, so a persona that already carries the reference text from
|
|
221
|
+
* somewhere else still gains the additions, and neither half is appended
|
|
222
|
+
* twice.
|
|
223
|
+
*/
|
|
224
|
+
export function withDispatcherRules(text) {
|
|
225
|
+
if (text.includes(DISPATCHER_RULES_WITH_APPENDIX)) return text
|
|
226
|
+
if (text.includes(DISPATCHER_RULES)) return `${text}\n${DISPATCHER_RULES_APPENDIX}`
|
|
227
|
+
return `${text}${DISPATCHER_RULES_HEADING}${DISPATCHER_RULES_WITH_APPENDIX}`
|
|
228
|
+
}
|
|
229
|
+
|
|
179
230
|
function optionalByteSize(value, field, fallback) {
|
|
180
231
|
if (value === undefined) return fallback
|
|
181
232
|
if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0) {
|
|
@@ -664,27 +715,39 @@ export function dropInstructionMessages(messages, baselineFiles = [], baselineLo
|
|
|
664
715
|
* to the persona section at assembly time. The literal cwd comes from the
|
|
665
716
|
* session header, so the line stays correct after a workspace switch, and a
|
|
666
717
|
* session without a readable cwd keeps the bare persona rather than failing.
|
|
718
|
+
*
|
|
719
|
+
* `dispatcher` appends the dispatcher block to the SAME persona section, after
|
|
720
|
+
* the workspace line, so the order is fixed: orientation, then the rules. With
|
|
721
|
+
* the switch off this function is the one it always was — same array identity
|
|
722
|
+
* when there is nothing to append, byte-identical text when there is.
|
|
723
|
+
*
|
|
724
|
+
* Nothing is escaped on the way in: a personality section is prompt text the
|
|
725
|
+
* assembler emits, not section text the renderer interpolates, so a literal
|
|
726
|
+
* `{{name}}` inside the appended rules reaches the model as written instead of
|
|
727
|
+
* throwing on an unknown variable. The append is idempotent, like the workspace
|
|
728
|
+
* line: a persona that already carries the block is left alone.
|
|
667
729
|
*/
|
|
668
730
|
const WORKSPACE_LINE_PREFIX = '\n\nYour working directory is '
|
|
669
731
|
|
|
670
|
-
/** Append the workspace line to the persona section
|
|
671
|
-
export function withWorkspaceLine(sections, agent) {
|
|
732
|
+
/** Append the workspace line, and the dispatcher block when the switch is on, to the persona section. */
|
|
733
|
+
export function withWorkspaceLine(sections, agent, dispatcher = false) {
|
|
672
734
|
const cwd = agent?.session?.header?.cwd
|
|
673
|
-
|
|
674
|
-
|
|
735
|
+
const line = (typeof cwd === 'string' && cwd.length > 0) ? `${WORKSPACE_LINE_PREFIX}${cwd}.` : ''
|
|
736
|
+
if (line === '' && !dispatcher) return sections
|
|
675
737
|
const persona = sections.find(section =>
|
|
676
|
-
PERSONA_SECTION_NAMES.includes(section?.name)
|
|
677
|
-
&& typeof section?.text === 'string'
|
|
678
|
-
&& !section.text.includes(line))
|
|
738
|
+
PERSONA_SECTION_NAMES.includes(section?.name) && typeof section?.text === 'string')
|
|
679
739
|
if (persona === undefined) return sections
|
|
740
|
+
const text = line !== '' && !persona.text.includes(line) ? `${persona.text}${line}` : persona.text
|
|
741
|
+
if (text === persona.text && !dispatcher) return sections
|
|
680
742
|
return sections.map(section => section === persona
|
|
681
|
-
? { ...section, text:
|
|
743
|
+
? { ...section, text: dispatcher ? withDispatcherRules(text) : text }
|
|
682
744
|
: section)
|
|
683
745
|
}
|
|
684
746
|
|
|
685
747
|
/** Register the section filter, workspace-instruction source, and dynamic discovery hooks. */
|
|
686
748
|
export function apply(ctx, config) {
|
|
687
749
|
const keepPlanPolicy = optionalBoolean(config?.keepPlanPolicy, 'keepPlanPolicy', true)
|
|
750
|
+
const dispatcher = optionalBoolean(config?.dispatcher, 'dispatcher', true)
|
|
688
751
|
const instructionSource = optionalSource(config?.instructionSource, 'instructionSource', 'host')
|
|
689
752
|
const instructionMaxBytes = optionalByteSize(config?.instructionMaxBytes, 'instructionMaxBytes', DEFAULT_INSTRUCTION_MAX_BYTES)
|
|
690
753
|
|
|
@@ -741,7 +804,7 @@ export function apply(ctx, config) {
|
|
|
741
804
|
const assembled = await next()
|
|
742
805
|
if (!Array.isArray(assembled.sections)) return assembled
|
|
743
806
|
// The official SDK sections belong to the run_code transport: keep them
|
|
744
|
-
// exactly when this assembly's wire carries it ('ptc'
|
|
807
|
+
// exactly when this assembly's wire carries it ('ptc'), drop
|
|
745
808
|
// them from a native wire they would only confuse. An unreadable wire keeps
|
|
746
809
|
// them, matching the harness's own empty-section drop under 'native'.
|
|
747
810
|
const wire = Array.isArray(assembled?.tools) ? assembled.tools : undefined
|
|
@@ -757,7 +820,7 @@ export function apply(ctx, config) {
|
|
|
757
820
|
+ 'keeping the assembled prompt instead of sending an empty one')
|
|
758
821
|
return assembled
|
|
759
822
|
}
|
|
760
|
-
const narrowed = withWorkspaceLine(sections, context?.agent)
|
|
823
|
+
const narrowed = withWorkspaceLine(sections, context?.agent, dispatcher)
|
|
761
824
|
// 'host' and 'hint' append no workspace-instructions section: the harness's
|
|
762
825
|
// own agent-instructions row carries the content (or the hint replaces it).
|
|
763
826
|
if (instructionSource !== 'system-prompt') return { ...assembled, sections: narrowed }
|