@linxin666/dsh-liangshen 0.4.18 → 0.4.20
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 +11 -7
- package/README.zh.md +11 -7
- package/lib/client.js +118 -12
- package/lib/client.js.map +1 -1
- package/lib/index.js +46 -13
- package/lib/types/client/LiangShenSettingsCard.d.ts +3 -0
- package/lib/types/client/lever-controller.d.ts +26 -2
- package/lib/types/client/locales.d.ts +3 -0
- package/lib/types/client/settings-form.d.ts +2 -0
- package/lib/types/composition.d.ts +6 -0
- package/lib/types/index.d.ts +14 -1
- package/package.json +15 -15
- package/presets/liangshen/agent.cordis.yml +16 -3
- package/presets/liangshen/dispatcher-rules.mjs +87 -62
- package/presets/liangshen/fact-ledger.mjs +41 -25
- package/presets/liangshen/minimal-prompt.mjs +72 -25
- package/presets/liangshen/paging.mjs +269 -26
- package/presets/liangshen/subagent-routes.mjs +11 -22
- package/presets/liangshen/tool-activate.mjs +21 -13
- package/presets/liangshen/tool-catalog.mjs +162 -101
- package/presets/liangshen/wire-presentation.mjs +33 -0
- package/presets/liangshen/working-context.mjs +94 -96
- package/src/announce.test.ts +58 -0
- package/src/client/LiangShenSettingsCard.tsx +17 -1
- package/src/client/lever-controller.ts +57 -15
- package/src/client/locales.ts +6 -0
- package/src/client/settings-form.ts +21 -2
- package/src/composition.test.ts +33 -0
- package/src/composition.ts +22 -3
- package/src/index.test.ts +1 -0
- package/src/index.ts +37 -5
|
@@ -25,6 +25,17 @@
|
|
|
25
25
|
* planned direct execution, and the R0.5 rewrite for the CURRENT built-in team
|
|
26
26
|
* runtime, whose only addition over plain subagents is a shared task board.
|
|
27
27
|
*
|
|
28
|
+
* RE-SYNCED at 2026-11-13 against 0.72.0 (`64cf068`, reading `f1121c8` at 0.71.0
|
|
29
|
+
* and `75aeea2` first). That pass DELETED the R0.5 compatibility gate
|
|
30
|
+
* (`c182e68`): harness 0.2.1-rc.2 removed the legacy Agent Teams runtime, so the
|
|
31
|
+
* criterion can only ever answer "absent", and this deployment runs a newer
|
|
32
|
+
* harness still—its surviving task-board contract became the `[Agent Teams Board]`
|
|
33
|
+
* paragraph. It also narrowed the UI visual evidence gate to regression-risk
|
|
34
|
+
* changes, folded external prior-art lookup into G4, added the
|
|
35
|
+
* L2-Clear/L2-Governed split and `[Execution Economy]`, and adopted upstream's
|
|
36
|
+
* one-decision-per-rule rewrite. R9 still stays adapted: the enter_plan_mode row
|
|
37
|
+
* upstream drives does not exist here.
|
|
38
|
+
*
|
|
28
39
|
* Two upstream entries are deliberately NOT carried, recorded under
|
|
29
40
|
* `provenance.omissions` with the reason: `[Dispatch Ledger]` names a
|
|
30
41
|
* `dispatch_ledger` tool this preset does not mount, and upstream's R9 drives
|
|
@@ -84,12 +95,12 @@
|
|
|
84
95
|
/** Where the rule text came from, and every correction folded into it. */
|
|
85
96
|
export const DISPATCHER_RULES_PROVENANCE = {
|
|
86
97
|
package: '@eddyskywalker/dsh-chatgpt-subscription',
|
|
87
|
-
inheritedVersion: '0.
|
|
88
|
-
/** The upstream
|
|
89
|
-
inheritedRevision: '
|
|
90
|
-
reExtractedAt: '2026-11-
|
|
91
|
-
/** The rule sections the block carries, in order: a section added upstream means a re-extraction. */
|
|
92
|
-
sections: ['R0
|
|
98
|
+
inheritedVersion: '0.72.0',
|
|
99
|
+
/** The upstream revisions the 2026-11-13 pass read: the governance/execution streamline, the verification-pressure cut, and the prompt/prior-art rewrite. */
|
|
100
|
+
inheritedRevision: 'f1121c8 (0.71.0) + 75aeea2 + 64cf068 (0.72.0); R0.5 removed upstream in c182e68',
|
|
101
|
+
reExtractedAt: '2026-11-13',
|
|
102
|
+
/** The rule sections the block carries, in order: a section added upstream means a re-extraction. R0.5 is gone because upstream deleted it (c182e68). */
|
|
103
|
+
sections: ['R0', 'R-G', 'R1', 'R2', 'R3', 'R4', 'R5', 'R6', 'R-W', 'R7', 'R8', 'R9'],
|
|
93
104
|
/**
|
|
94
105
|
* What the 2026-11-02 re-sync folded in from upstream, section by section.
|
|
95
106
|
*
|
|
@@ -190,10 +201,16 @@ export const DISPATCHER_RULES_PROVENANCE = {
|
|
|
190
201
|
why: 'With R1 allowing direct execution, "execute it yourself" stopped being evidence of a fallback; the rule had to say which direct work is planned and which is the exception.',
|
|
191
202
|
},
|
|
192
203
|
{
|
|
193
|
-
rule: '
|
|
194
|
-
upstreamCommit: '
|
|
195
|
-
now: '
|
|
196
|
-
why: '
|
|
204
|
+
rule: '[Execution Economy]',
|
|
205
|
+
upstreamCommit: 'f1121c8',
|
|
206
|
+
now: 'L0/L1 and every implementation phase spend one cheap probe and the smallest complete change, stop after at most 2 consecutive model steps without new evidence or a verified criterion, and re-triage if complexity grows mid-task.',
|
|
207
|
+
why: 'A per-step brake that names what counts as progress keeps a session from grinding through equivalent probes; it is the same rule R0.5 used to carry once the compatibility check itself stopped existing.',
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
rule: '[Agent Teams Board]',
|
|
211
|
+
upstreamCommit: 'c182e68',
|
|
212
|
+
now: 'The shared task board is bookkeeping, not a second dispatcher: the R5 brief stays the task contract, the board tools stay declared whether or not the board is on, and a ready task never starts work or skips R6.',
|
|
213
|
+
why: 'Replaces the R0.5 compatibility gate, which upstream deleted once harness 0.2.1-rc.2 removed the legacy Agent Teams runtime: the generation that gate told apart no longer exists, so only the board contract is left to state.',
|
|
197
214
|
},
|
|
198
215
|
],
|
|
199
216
|
/**
|
|
@@ -213,6 +230,18 @@ export const DISPATCHER_RULES_PROVENANCE = {
|
|
|
213
230
|
why: 'Upstream R9 enters plan mode itself once the interview converges, using rows this preset does not mount; R9 stays adapted to plan mode as the user\'s switch, which is recorded under additions.',
|
|
214
231
|
},
|
|
215
232
|
],
|
|
233
|
+
/**
|
|
234
|
+
* Upstream entries this block carried until they were deleted upstream. A
|
|
235
|
+
* removal is its own category: unlike an omission it once ran here, and unlike
|
|
236
|
+
* a correction nothing replaced it—the situation it described stopped existing.
|
|
237
|
+
*/
|
|
238
|
+
removals: [
|
|
239
|
+
{
|
|
240
|
+
rule: 'R0.5 · Compatibility Gate',
|
|
241
|
+
upstreamCommit: 'c182e68',
|
|
242
|
+
why: 'Upstream deleted the gate once harness 0.2.1-rc.2 removed the legacy Agent Teams runtime (spawn_teammate plus the team-scoped send_message/list_agents/interrupt_agent): the criterion can only ever answer "absent" now, so every new session would pay one tool-enumeration just to learn that. This deployment runs a newer harness still, so the gate is unconditionally dead weight here too. The block had carried it since the 2026-11-03 sync, where it was added as the fixed criterion for that generation pair; the task-board contract that outlived it is kept as a [Agent Teams Board] paragraph, recorded under additions.',
|
|
243
|
+
},
|
|
244
|
+
],
|
|
216
245
|
/** Corrections that are NOT appendix entries, because an appended contradiction is worse than a rewrite. */
|
|
217
246
|
corrections: [
|
|
218
247
|
{
|
|
@@ -245,50 +274,50 @@ export const DISPATCHER_RULES_PROVENANCE = {
|
|
|
245
274
|
now: 'A fork carries the conversation and inherits your route, which makes it the cheapest same-route child (no route: line owed, prefix and KV cache kept) as long as your own route is one the allowlist returned; the built-in assertion skips an inherited route, so that check is the model\'s to make. A deployment may police inherit-only tools from the host plane and refuse such a fork outright. The same reading applies to any delegation tool mounted without route fields: it cannot be given a route, so an explicit-pair demand on it is a denial no call can satisfy.',
|
|
246
275
|
why: 'Read off the current cohort: the route assertion returns early unless the call names a route, and the subagent runtime never consults the policy, so the promised built-in rejection does not exist; where a host guard does police the inherited route, its refusal names the authorized routes and cannot be repaired by any argument. The old text also banned a legitimate, cheaper form for every task that did not need the conversation.',
|
|
247
276
|
},
|
|
277
|
+
{
|
|
278
|
+
rule: 'R6 [UI Visual Evidence Gate]',
|
|
279
|
+
superseded: 'Any task that changes visible UI, layout, styling or a client component is not accepted on After evidence alone; After-only evidence fails review.',
|
|
280
|
+
now: 'Only a regression-risk change to existing layout, styling or components owes Before and After captures; pure copy, logic-only or additive work owes none, and with no reliable Before an After plus a note suffices.',
|
|
281
|
+
why: 'Measured against what the gate protects, a wording or logic change cannot regress a layout, so demanding a Before capture for it charges a screenshot that proves nothing and hides the captures that do matter in noise; upstream reached the same narrowed form (75aeea2).',
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
rule: 'G4 [Facts & Prior Art]',
|
|
285
|
+
superseded: 'Never ask for a repository fact or a technical, naming, layout or styling choice an established reference or AGENTS.md already settles.',
|
|
286
|
+
now: 'External prior art is a fact too: search the web (GitHub docs/repos, official docs, research papers, specs) or dispatch a read-only subagent before asking, and treat an established external standard as a fact (target_basis: existing-standard).',
|
|
287
|
+
why: 'The old reading sent the model to the user for anything the repository did not settle, so a well-documented external standard became a question the user had to answer; upstream folded prior-art lookup into G4 and the plan-mode section (64cf068).',
|
|
288
|
+
},
|
|
248
289
|
],
|
|
249
290
|
}
|
|
250
291
|
|
|
251
|
-
/** The dispatcher rule block: entry paragraphs, R0
|
|
252
|
-
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,
|
|
292
|
+
/** The dispatcher rule block: entry paragraphs, the Agent Teams board contract, R0 through R9, R-W, and the anti-patterns, without a trailing newline. */
|
|
293
|
+
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, 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.
|
|
253
294
|
- [Standing Subagent Contract] Every subagent inherits these limits unless the brief overrides them: at most 3 attempts per brief; edits only inside the declared Boundary; reads, searches, verifications and test runs unlimited inside it; no banking (every limit is a single-run total).
|
|
254
295
|
- [Subagent Report Protocol] Every report states status: ready | hand_back | blocked | failed | dropped, a summary, and evidence (diffs, test output, before/after captures for UI). A status: hand_back report adds a one-sentence hand_back_reason naming the out-of-boundary file or interface or the broken premise, and mutates no file outside Boundary.
|
|
255
296
|
- [Coordinator-Only Tools] ask_user_question, enter_plan_mode, leave_plan_mode, exit_plan_mode, create_goal, update_goal, and present are coordinator-only: the dispatch-guard row refuses them from a delegated caller with DELEGATED_CALLER (four are mounted here; the rest stay listed so the rule survives a roster change). The refusal is a backstop, not the rule—a deployment may unmount that row—so a subagent reports the open question or decision back and the dispatcher acts on it.
|
|
256
297
|
|
|
257
298
|
[Coordinator Identity] You are the Lead & Dispatch Agent: converge the requirements, plan the architecture, choose the R1 execution topology, orchestrate subagents where the ROI is positive, and own the final acceptance. Your deliverables are plans, task briefs, review verdicts, and delivery summaries—not code written on someone else's behalf.
|
|
258
|
-
[Execution Pipeline] R0
|
|
259
|
-
|
|
260
|
-
## R0.5 · Compatibility Gate (Once per New Session, Before R0)
|
|
261
|
-
|
|
262
|
-
Agent Teams has two generations and only one of them blocks orchestration. A legacy runtime (pre-#7519) registers spawn_teammate and replaces send_message, list_agents and interrupt_agent with team-scoped variants, so children exist but are unreachable—and review, rework and follow-up all run through those three tools. The current runtime adds nothing but a shared task board (team_task_create plus its list/get/update siblings) and reuses this mode's own coordination tools.
|
|
263
|
-
|
|
264
|
-
Criterion: does spawn_teammate exist (under PTC: tools.spawn_teammate)? Never gate on wait_agent, send_message, list_agents or interrupt_agent—this mode mounts those itself.
|
|
299
|
+
[Execution Pipeline] R0 Triage -> [L2-Governed only: R-G Interview -> R9 Plan Approval] -> R1 Topology -> (if delegating: R2 Routing -> R5 Brief -> R-W Wait) -> R6 Lead Acceptance.
|
|
265
300
|
|
|
266
|
-
|
|
267
|
-
- Present -> **Not orchestratable**. Do these three things and nothing else:
|
|
268
|
-
1. State it in one sentence: the legacy runtime shadows the coordination tools and this mode has no degraded path.
|
|
269
|
-
2. Call ask_user_question once with the exit paths: (1) disable the legacy runtime, restart the Host, start a new session; (2) switch preset and do not orchestrate here; (3) execute this task directly.
|
|
270
|
-
3. **Do nothing else** until the user replies.
|
|
271
|
-
- A settings change takes effect only in a **new session**; this session's tool surface was fixed at startup.
|
|
272
|
-
- "Execute this task directly" means standalone work with no side-spawned children, for this task only.
|
|
301
|
+
[Agent Teams Board] The shared task board (team_task_create and its list/get/update siblings) is bookkeeping, not a second dispatcher (frozen declaration, not availability—confirm with team_task_list before relying on it). When on, the R5 brief stays the task contract: one task per brief publishes blocked_by/write scopes, claimed and completed by its owning child; never start work because a task is ready, and never reassign a task to skip R6.
|
|
273
302
|
|
|
274
|
-
## R0 · Complexity Triage
|
|
275
|
-
Determine
|
|
276
|
-
- L0 Simple:
|
|
277
|
-
- L1 Moderate: edits at most 5 files (5 is a cap, not a range and not a target), at most 2 open points
|
|
278
|
-
- L2 Complex / Multi-step: cross-module
|
|
303
|
+
## R0 · Complexity Triage
|
|
304
|
+
Determine tier by semantic impact and uncertainty (write a brief "Tier + Rationale" line for L1/L2; skip for L0):
|
|
305
|
+
- L0 Simple / Single-point: single-file/point edit, unambiguous, reversible, no parallelism value. -> Execute directly and report; no interview or subagents.
|
|
306
|
+
- L1 Moderate: unambiguous module-local or mechanical multi-file work; edits at most 5 files (5 is a cap, not a range and not a target), no external contract break or unsettled product/UI decision, at most 2 open points. -> Ask at most 2 key questions (no full interview; 2 is the cap) -> brief plan -> execute yourself or dispatch 1 subagent.
|
|
307
|
+
- L2 Complex / Multi-step: cross-module/contract changes, multi-part work, unsettled decisions, or major irreversible risk. -> L2-Clear (settled, reversible): brief decision-complete plan -> R1 -> R6, without full interview/Plan Mode. L2-Governed (unsettled product/UI/external contract or major irreversible risk): R-G Interview -> R9 Plan & Approval -> R1 -> R6.
|
|
279
308
|
When in doubt, clarify; if the task grows mid-way, stop, re-triage and say so. Never interview or orchestrate for L0/L1.
|
|
280
309
|
- [Stop by Impact, Not by Effort] A subagent fixes every call site, type and test inside its boundary for a self-contained result, and reports status: hand_back the moment a change would break an external contract, move a responsibility across modules, or need an unsettled product decision—even on a single line. Effort spent is not the yardstick; blast radius is.
|
|
310
|
+
- [Execution Economy] Use one cheap probe, the smallest complete change, batched independent reads/searches, and incremental edits. Stop after at most 2 consecutive model steps without progress to change approach or escalate; re-triage if complexity grows mid-task.
|
|
281
311
|
|
|
282
|
-
## R-G · Clarification Interview (L2 Only,
|
|
283
|
-
- G1 Design Tree: requirements are a dependency tree
|
|
284
|
-
-
|
|
285
|
-
-
|
|
286
|
-
-
|
|
287
|
-
- G5 Convergence: the interview ends only when the frontier is empty and the user has explicitly confirmed shared understanding. Until then: no plan, no edits, no implementation dispatches.
|
|
312
|
+
## R-G · Clarification Interview (L2-Governed Only, Before R9)
|
|
313
|
+
- G1 Design Tree & G2 Frontier: requirements are a decision dependency tree; ask the entire current frontier (decisions whose prerequisites are settled) in one round, wait for answers, and recompute. Never ask one question per round or dependent questions together.
|
|
314
|
+
- G3 Execution via Tool: each round is ONE tools.ask_user_question(...) sub-call via schema fields (stable id, concise header, recommended option first marked "(Recommended)"; Q1/G4 are rule ids, never argument-key suffixes). The same rule covers every decision stop outside the interview (R-W).
|
|
315
|
+
- G4 Facts & Prior Art Are Yours, Decisions Are the User's: never ask for a repository fact, a technical/naming/layout/styling choice settled by code or AGENTS.md, or external prior art—inspect read-only yourself, search the web (GitHub docs/repos, official docs, research papers, specs) to avoid reinventing the wheel, or dispatch a read-only subagent per R2 without blocking unrelated frontier questions. Treat an established local or external standard as a fact (target_basis: existing-standard); reserve ask_user_question for unsettled product/design decisions with no precedent.
|
|
316
|
+
- G5 Convergence: converge once the frontier is empty (all open decisions answered; no extra confirmation round before R9). Until then: no plan, no edits, no implementation dispatches.
|
|
288
317
|
- G6 Prohibited: answering your own questions, deciding for the user, skipping the interview, or reading a casual remark as sign-off.
|
|
289
318
|
|
|
290
319
|
## R1 · Execution Topology & Boundary (Coupling × Fan-out ROI)
|
|
291
|
-
|
|
320
|
+
Pick topology by coupling vs. parallel ROI; all tiers end at R6 Lead Acceptance. L2-Clear uses a brief plan; L2-Governed completes R-G and R9 first, and tightly coupled work is never barred from direct execution.
|
|
292
321
|
- Lead-Core: a tightly coupled cross-module or contract change, or a sequential chain where splitting duplicates the reads and produces hand_back loops. -> Implement it yourself in continuous steps (tracked in todo_write, no self-brief) and run the R6 verification.
|
|
293
322
|
- Hybrid: an unsettled shared contract or seam plus orthogonal downstream work. -> Implement and freeze the core seam yourself first, then delegate the orthogonal adapters, tests and noisy exploration per R2/R5, or use subagent_fork when the child needs this conversation.
|
|
294
323
|
- Fan-out: at least 3 orthogonal subtasks with disjoint files, settled interfaces and a real parallel or routing gain. -> Coordinate: plan, dispatch per R2/R5, review and accept per R6, own the documentation and any module that is not delegable. Never edit an active child's Boundary.
|
|
@@ -324,17 +353,15 @@ Subagents run on DSH's default subagent role and environment—never inject a cu
|
|
|
324
353
|
## R5 · Dispatch Discipline
|
|
325
354
|
Every brief carries six elements: Goal / Boundary (files or modules it may touch) / Constraints / Limits / Acceptance Criteria / Required Evidence.
|
|
326
355
|
- [Compact Delta Brief] The standing limits and the report schema already live in [Role Identification], so the default brief states only the delta: goal, source pointers (file:line, never a paraphrase of the code), module/interface boundary, constraints, acceptance criteria, required evidence. Restate a standing limit only to override it.
|
|
327
|
-
- [Limits] One line per limit, each naming **what it bounds, in what unit, the cap, and whether it accumulates**. A child reads an ambiguous limit at its strictest end and never checks, so write "at most 3
|
|
356
|
+
- [Limits] One line per limit, each naming **what it bounds, in what unit, the cap, and whether it accumulates**. A child reads an ambiguous limit at its strictest end and never checks, so write "at most 3 runs", not "a few attempts"; "edits at most 5 files", not "2-5". Say "test runs: unlimited" when a dimension is genuinely open—silence is read as zero. Cover at minimum attempts, files edited, commands run, and any per-cycle quota with its reset rule (a per-cycle quota is lost, not banked—say so).
|
|
328
357
|
- Never ask a child to restate your rules as a correctness check: restatement reproduces the misreading. If a limit is truly unclear, let it spend one minimal tool call to verify, and write that escape into the brief.
|
|
329
358
|
Dispatch independent tasks in parallel in one message. A subagent's report is evidence, not a verdict. Never dispatch implementation work before the interview has converged. Under PTC, dispatch through tools.subagent(...) inside run_code with Promise.all.
|
|
330
359
|
|
|
331
|
-
## R6 ·
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
[Non-Penalized hand_back] A child that stops cleanly before mutating anything outside Boundary, with a valid hand_back_reason, is a scope routing event rather than a failure: it does not increment the brief's 3-run counter. Answer it, and any blocked report, by continuing the existing child with send_message({ agent_id }) instead of spawning a cold replacement—the warm child keeps its provider-side prefix cache.
|
|
337
|
-
[UI Visual Evidence Gate] A task that changes visible UI, layout, styling or a client component is not accepted on After evidence alone: deliver Before and After captures under the same scenario, viewport and theme. After-only evidence fails review.
|
|
360
|
+
## R6 · Lead Acceptance
|
|
361
|
+
One acceptance layer owned by Lead: subagents supply implementation/evidence; Lead reads the final diff, checks every criterion, and runs risk-relevant verification. The completion notification is a post-hoc signal: a child stopped, not that the work passed.
|
|
362
|
+
Re-dispatch budget per brief: 1 first attempt + at most 2 re-dispatches = at most 3 runs total. Count runs, not failures, and keep the number on the task item (R7) rather than in your memory. Only after the third run ends without acceptance, transition to R8 Fallback.
|
|
363
|
+
[Non-Penalized hand_back] Clean status: hand_back with a valid hand_back_reason and no out-of-boundary mutation does not increment a failure count or trigger R8 by itself (each run still counts toward the 3-run cap). Re-scope or answer via send_message({ agent }) on the existing child to preserve its warm prefix cache.
|
|
364
|
+
[UI Visual Evidence Gate] Regression-risk visual layout/styling changes require Before and After captures (same scenario, viewport, theme); with no reliable Before, an After plus a note suffices. Pure copy, logic-only, or additive changes need neither.
|
|
338
365
|
[Noticed but not handled] Every defect found in review ends one of two ways: back out on a re-dispatch with evidence, or to the user through ask_user_question as a scoping decision (R-W). Recording it in the delivery summary and shipping anyway is not an outcome—an unrouted risk is exactly what this rule exists to stop. On a Lead-Core or Hybrid core the fix and its re-verification happen before delivery. The summary lists the risks you noticed and routed with what you did about each; an empty list says you found none, which is a claim in its own right.
|
|
339
366
|
|
|
340
367
|
## R-W · Turn Boundary (Waiting / Goals / Questions)
|
|
@@ -357,7 +384,7 @@ Re-dispatch budget per brief: 1 first attempt + at most 2 re-dispatches = at mos
|
|
|
357
384
|
|
|
358
385
|
## R7 · Documentation
|
|
359
386
|
Keep the task list (todo_write, never create_goal), the decision log, and what the interview settled. Each item carries its run count (R6), so the budget is read rather than remembered. Children never report to the user.
|
|
360
|
-
[Before every turn]
|
|
387
|
+
[Before every turn] Prioritize items that will escalate, expire, or time out before items that are merely large—a result back but unreviewed, a failed acceptance whose rework is unscoped, a blocking question still unanswered, a brief sitting at its run count. Waiting is not the same as an item that is fine; do not list per-turn item ages in user replies.
|
|
361
388
|
[Clause Deletion Test] Keep the full evidence in the internal review, but before sending the user-facing summary ask of each clause whether deleting it would stop the user from understanding the outcome, the risk, or the action it requires. If not, omit it.
|
|
362
389
|
|
|
363
390
|
## R8 · Fallback
|
|
@@ -386,21 +413,19 @@ Plan mode is the user's switch, not a stop this mode manufactures. The official
|
|
|
386
413
|
8. Letting a subagent choose its own model.
|
|
387
414
|
9. Carrying a one-off fallback forward—R8 is a task-scoped permit.
|
|
388
415
|
10. Treating a hard rejection as a fallback excuse instead of fixing its trigger.
|
|
389
|
-
11.
|
|
390
|
-
12.
|
|
391
|
-
13.
|
|
392
|
-
14.
|
|
393
|
-
15.
|
|
394
|
-
16.
|
|
395
|
-
17.
|
|
396
|
-
18.
|
|
397
|
-
19. Asking
|
|
398
|
-
20.
|
|
399
|
-
21. Asking the user
|
|
400
|
-
22.
|
|
401
|
-
23.
|
|
402
|
-
24. Penalising a clean hand_back as a failed run, or cold-replacing a child send_message could continue (R6).
|
|
403
|
-
25. Accepting a visible UI change without Before and After comparison evidence taken under the same scenario, viewport, and theme (R6).`
|
|
416
|
+
11. Treating the team task board as a substitute for the R1 topology, R2 routing, R5 briefs, R6 acceptance or the R-W wait ([Agent Teams Board]).
|
|
417
|
+
12. Sleep, polling or a placeholder command to wait after dispatching (R-W).
|
|
418
|
+
13. Creating a goal at task start (R-W).
|
|
419
|
+
14. Ending with prose to wait for user sign-off instead of asking (R-W).
|
|
420
|
+
15. Second-guessing list_subagent_models by hunting local config or source files for which subagent models are allowed—its output already is this session's runtime allowlist (R2).
|
|
421
|
+
16. Shipping a defect already named in review because the summary records it (R6).
|
|
422
|
+
17. A brief that states a range where a cap belongs ("2-5 files", "a few attempts"); or asking a child to restate its rules instead of verifying the ambiguous one with a tool call (R0, R5).
|
|
423
|
+
18. Reporting a route as "authorized", or claiming per-task routing is in force, when the session recorded no allowlist (R2).
|
|
424
|
+
19. Asking the user to switch into plan mode, or gating ordinary planning on a mode nobody requested (R9).
|
|
425
|
+
20. Inside plan mode, pasting the plan into a reply or asking "should I proceed?" instead of exit_plan_mode (R9).
|
|
426
|
+
21. Asking the user a detail an established standard, AGENTS.md or external prior art already settles (G4).
|
|
427
|
+
22. Penalising a clean hand_back as a failed run, or cold-replacing a child send_message could continue (R6).
|
|
428
|
+
23. Accepting a regression-risk visual change without Before and After captures or an After-only note (R6).`
|
|
404
429
|
|
|
405
430
|
/**
|
|
406
431
|
* The local additions, appended after the reference block. They fall into
|
|
@@ -87,37 +87,53 @@ function factRegisterCall(event) {
|
|
|
87
87
|
return event.data
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Fold ONE event into one register: a successful `fact_register` call appends
|
|
92
|
+
* its fact (or revokes by tag), whichever wire shape recorded it. Facts carry no
|
|
93
|
+
* ids — revocation matches on the optional `tag`, and an untagged fact can only
|
|
94
|
+
* be revoked by revoking its exact text as the tag of last resort.
|
|
95
|
+
*
|
|
96
|
+
* Exported because the register is folded from the same event stream as the rest
|
|
97
|
+
* of the working-context line: that projection folds every field in one pass, so
|
|
98
|
+
* the pin/revoke rule has to be applicable per event instead of per stream.
|
|
99
|
+
* @param facts - the register to fold into; left untouched by an unrelated event.
|
|
100
|
+
* @param event - one durable session event.
|
|
101
|
+
* @returns the same array, so a stream fold can thread it through the pass.
|
|
102
|
+
*/
|
|
103
|
+
export function applyFactLedgerEvent(facts, event) {
|
|
104
|
+
const register = Array.isArray(facts) ? facts : []
|
|
105
|
+
const data = factRegisterCall(event)
|
|
106
|
+
if (data === undefined) return register
|
|
107
|
+
let args = data.arguments
|
|
108
|
+
if (typeof args === 'string') {
|
|
109
|
+
try { args = JSON.parse(args) } catch { args = undefined }
|
|
110
|
+
}
|
|
111
|
+
if (args === undefined || args === null) return register
|
|
112
|
+
if (typeof args.revoke === 'string' && args.revoke.trim() !== '') {
|
|
113
|
+
const tag = args.revoke.trim()
|
|
114
|
+
for (let index = register.length - 1; index >= 0; index -= 1) {
|
|
115
|
+
if (register[index].tag === tag || register[index].text === tag) register.splice(index, 1)
|
|
116
|
+
}
|
|
117
|
+
return register
|
|
118
|
+
}
|
|
119
|
+
if (typeof args.fact !== 'string' || args.fact.trim() === '') return register
|
|
120
|
+
const text = args.fact.trim().slice(0, MAX_FACT_CHARS)
|
|
121
|
+
if (register.some(entry => entry.text === text)) return register
|
|
122
|
+
const tag = typeof args.tag === 'string' && args.tag.trim() !== '' ? args.tag.trim() : undefined
|
|
123
|
+
register.push({ text, tag })
|
|
124
|
+
if (register.length > MAX_FACTS) register.splice(0, register.length - MAX_FACTS)
|
|
125
|
+
return register
|
|
126
|
+
}
|
|
127
|
+
|
|
90
128
|
/**
|
|
91
129
|
* Fold the current fact register from the event stream: every successful
|
|
92
130
|
* `fact_register` call appends its fact (or revokes by tag), whichever wire
|
|
93
|
-
* shape recorded it.
|
|
94
|
-
*
|
|
95
|
-
* the tag of last resort.
|
|
131
|
+
* shape recorded it. The per-event rule lives in {@link applyFactLedgerEvent} so
|
|
132
|
+
* a single-pass projection folds the same register without a second walk.
|
|
96
133
|
*/
|
|
97
134
|
export function foldFactLedger(events) {
|
|
98
135
|
const facts = []
|
|
99
|
-
for (const event of Array.isArray(events) ? events : [])
|
|
100
|
-
const data = factRegisterCall(event)
|
|
101
|
-
if (data === undefined) continue
|
|
102
|
-
let args = data.arguments
|
|
103
|
-
if (typeof args === 'string') {
|
|
104
|
-
try { args = JSON.parse(args) } catch { args = undefined }
|
|
105
|
-
}
|
|
106
|
-
if (args === undefined || args === null) continue
|
|
107
|
-
if (typeof args.revoke === 'string' && args.revoke.trim() !== '') {
|
|
108
|
-
const tag = args.revoke.trim()
|
|
109
|
-
for (let index = facts.length - 1; index >= 0; index -= 1) {
|
|
110
|
-
if (facts[index].tag === tag || facts[index].text === tag) facts.splice(index, 1)
|
|
111
|
-
}
|
|
112
|
-
continue
|
|
113
|
-
}
|
|
114
|
-
if (typeof args.fact !== 'string' || args.fact.trim() === '') continue
|
|
115
|
-
const text = args.fact.trim().slice(0, MAX_FACT_CHARS)
|
|
116
|
-
if (facts.some(entry => entry.text === text)) continue
|
|
117
|
-
const tag = typeof args.tag === 'string' && args.tag.trim() !== '' ? args.tag.trim() : undefined
|
|
118
|
-
facts.push({ text, tag })
|
|
119
|
-
if (facts.length > MAX_FACTS) facts.splice(0, facts.length - MAX_FACTS)
|
|
120
|
-
}
|
|
136
|
+
for (const event of Array.isArray(events) ? events : []) applyFactLedgerEvent(facts, event)
|
|
121
137
|
return facts
|
|
122
138
|
}
|
|
123
139
|
|
|
@@ -7,9 +7,10 @@
|
|
|
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
|
-
* (`tools:sdk` and `tools:ptc-only`) exactly when the
|
|
11
|
-
* the `run_code` transport (presentation 'ptc'
|
|
12
|
-
*
|
|
10
|
+
* (`tools:sdk` and `tools:ptc-only`) exactly when the effective wire carries
|
|
11
|
+
* the `run_code` transport (presentation 'ptc'). Legacy hosts expose the final
|
|
12
|
+
* tools array; current hosts use the sibling-published transport, while a
|
|
13
|
+
* standalone assembly with neither signal keeps the historical fallback. The harness
|
|
13
14
|
* identity, web-surface, tool-guidance, file-reference, and structured-output
|
|
14
15
|
* sections never reach the model. Keeping the official SDK sections when the
|
|
15
16
|
* transport is present ensures the model receives the complete generated tool
|
|
@@ -82,7 +83,8 @@
|
|
|
82
83
|
*
|
|
83
84
|
* PLAN MODE is kept by default. `dsh-plan-mode` enforces its rules through
|
|
84
85
|
* the `plan:policy` prompt section alone. `keepPlanPolicy: false` restores the
|
|
85
|
-
* strict one-line surface.
|
|
86
|
+
* strict one-line surface. `keepSections` (default []) explicitly appends
|
|
87
|
+
* third-party section names to the allowlist and warns once for an unmatched name.
|
|
86
88
|
*
|
|
87
89
|
* DISPATCHER RULES (`dispatcher`, default `true`): the switch appends
|
|
88
90
|
* `./dispatcher-rules.mjs` to the persona text, after the workspace line, under
|
|
@@ -98,6 +100,7 @@ import { readFile, stat } from 'node:fs/promises'
|
|
|
98
100
|
import { homedir } from 'node:os'
|
|
99
101
|
import { dirname, join, relative, resolve } from 'node:path'
|
|
100
102
|
import { DISPATCHER_RULES, DISPATCHER_RULES_APPENDIX, DISPATCHER_RULES_WITH_APPENDIX } from './dispatcher-rules.mjs'
|
|
103
|
+
import { wirePresentationFor } from './wire-presentation.mjs'
|
|
101
104
|
|
|
102
105
|
/** Cordis plugin name used by loader diagnostics. */
|
|
103
106
|
export const name = 'liangshen-minimal-prompt'
|
|
@@ -178,6 +181,14 @@ function optionalBoolean(value, field, fallback) {
|
|
|
178
181
|
return value
|
|
179
182
|
}
|
|
180
183
|
|
|
184
|
+
function optionalKeepSections(value) {
|
|
185
|
+
if (value === undefined) return []
|
|
186
|
+
if (!Array.isArray(value) || value.some(sectionName => typeof sectionName !== 'string' || sectionName.length === 0)) {
|
|
187
|
+
throw new TypeError(`${name}: keepSections must be an array of non-empty strings`)
|
|
188
|
+
}
|
|
189
|
+
return [...new Set(value)]
|
|
190
|
+
}
|
|
191
|
+
|
|
181
192
|
function optionalSource(value, field, fallback) {
|
|
182
193
|
if (value === undefined) return fallback
|
|
183
194
|
if (!INSTRUCTION_SOURCES.includes(value)) {
|
|
@@ -747,6 +758,7 @@ export function withWorkspaceLine(sections, agent, dispatcher = false) {
|
|
|
747
758
|
/** Register the section filter, workspace-instruction source, and dynamic discovery hooks. */
|
|
748
759
|
export function apply(ctx, config) {
|
|
749
760
|
const keepPlanPolicy = optionalBoolean(config?.keepPlanPolicy, 'keepPlanPolicy', true)
|
|
761
|
+
const keepSections = optionalKeepSections(config?.keepSections)
|
|
750
762
|
const dispatcher = optionalBoolean(config?.dispatcher, 'dispatcher', true)
|
|
751
763
|
const instructionSource = optionalSource(config?.instructionSource, 'instructionSource', 'host')
|
|
752
764
|
const instructionMaxBytes = optionalByteSize(config?.instructionMaxBytes, 'instructionMaxBytes', DEFAULT_INSTRUCTION_MAX_BYTES)
|
|
@@ -765,20 +777,26 @@ export function apply(ctx, config) {
|
|
|
765
777
|
}
|
|
766
778
|
sessionStateMap.set(session, state)
|
|
767
779
|
|
|
768
|
-
// Reconstruct touched directories from durable history
|
|
769
|
-
|
|
780
|
+
// Reconstruct touched directories from the durable history, but ONLY in
|
|
781
|
+
// system-prompt mode: that is the one mode that discovers subdirectory
|
|
782
|
+
// instructions itself, so the other two never pay for a log read they
|
|
783
|
+
// cannot use (the harness's own row, or the hint, owns the channel there).
|
|
784
|
+
if (instructionSource === 'system-prompt' && typeof session?.snapshotEvents === 'function') {
|
|
770
785
|
try {
|
|
771
786
|
const events = session.snapshotEvents()
|
|
772
787
|
const cwd = session.header?.cwd ?? process.cwd()
|
|
773
788
|
for (const ev of events) {
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
789
|
+
// Both wire shapes count: a top-level call, and the program dispatch
|
|
790
|
+
// a PTC session records for the same tool. A dispatch that reported
|
|
791
|
+
// an error touched nothing.
|
|
792
|
+
if (ev?.type !== 'tool/call' && ev?.type !== 'tool/ptc-dispatch') continue
|
|
793
|
+
if (!ev.data || ev.data.isError === true) continue
|
|
794
|
+
let args = ev.data.arguments
|
|
795
|
+
if (typeof args === 'string') {
|
|
796
|
+
try { args = JSON.parse(args) } catch {}
|
|
781
797
|
}
|
|
798
|
+
const p = filePathFromExecution({ name: ev.data.name, arguments: args })
|
|
799
|
+
if (p) state.touchedDirs.add(dirname(resolve(cwd, p)))
|
|
782
800
|
}
|
|
783
801
|
} catch {
|
|
784
802
|
// Replay reconstruction fallback
|
|
@@ -788,6 +806,8 @@ export function apply(ctx, config) {
|
|
|
788
806
|
return state
|
|
789
807
|
}
|
|
790
808
|
|
|
809
|
+
const warnedKeepSections = new Set()
|
|
810
|
+
|
|
791
811
|
let warned = false
|
|
792
812
|
const warnOnce = (message) => {
|
|
793
813
|
if (warned) return
|
|
@@ -803,17 +823,31 @@ export function apply(ctx, config) {
|
|
|
803
823
|
ctx.on('system-prompt/assemble', async (_assembly, context, next) => {
|
|
804
824
|
const assembled = await next()
|
|
805
825
|
if (!Array.isArray(assembled.sections)) return assembled
|
|
806
|
-
//
|
|
807
|
-
//
|
|
808
|
-
//
|
|
809
|
-
//
|
|
826
|
+
// Old hosts exposed the final tool array here; current hosts expose only
|
|
827
|
+
// sections, so the sibling tool-catalog publishes the effective transport
|
|
828
|
+
// before this waterfall continues. Standalone use with neither signal keeps
|
|
829
|
+
// the historical fail-open behavior for these two SDK sections.
|
|
810
830
|
const wire = Array.isArray(assembled?.tools) ? assembled.tools : undefined
|
|
811
|
-
const
|
|
831
|
+
const presentation = wirePresentationFor(context?.agent)
|
|
832
|
+
const wireHasRunCode = wire !== undefined
|
|
833
|
+
? wire.some(tool => tool?.name === 'run_code')
|
|
834
|
+
: presentation === undefined ? true : presentation === 'ptc'
|
|
812
835
|
const keep = new Set([
|
|
813
836
|
...PERSONA_SECTION_NAMES,
|
|
814
837
|
...(keepPlanPolicy ? [PLAN_POLICY_SECTION_NAME] : []),
|
|
815
838
|
...(wireHasRunCode ? PTC_SECTION_NAMES : []),
|
|
839
|
+
...keepSections,
|
|
816
840
|
])
|
|
841
|
+
const availableNames = new Set(assembled.sections.map(section => section?.name))
|
|
842
|
+
for (const sectionName of keepSections) {
|
|
843
|
+
if (availableNames.has(sectionName) || warnedKeepSections.has(sectionName)) continue
|
|
844
|
+
warnedKeepSections.add(sectionName)
|
|
845
|
+
try {
|
|
846
|
+
ctx.logger?.warn?.(`${name}: keepSections entry ${JSON.stringify(sectionName)} never matched any assembled section`)
|
|
847
|
+
} catch {
|
|
848
|
+
// Logger unavailable
|
|
849
|
+
}
|
|
850
|
+
}
|
|
817
851
|
const sections = assembled.sections.filter(section => keep.has(section?.name))
|
|
818
852
|
if (sections.length === 0) {
|
|
819
853
|
warnOnce(`${name}: no section matched ${JSON.stringify([...keep])} — `
|
|
@@ -852,8 +886,15 @@ export function apply(ctx, config) {
|
|
|
852
886
|
}
|
|
853
887
|
}, { prepend: true })
|
|
854
888
|
|
|
855
|
-
// 2. Synchronous tool result tracking (no fake emit, no async work in emit listener)
|
|
889
|
+
// 2. Synchronous tool result tracking (no fake emit, no async work in emit listener).
|
|
890
|
+
//
|
|
891
|
+
// Tracking exists for the dynamic subdirectory discovery of system-prompt mode,
|
|
892
|
+
// so the other two modes return before touching the session at all: host mode
|
|
893
|
+
// hands the channel to the harness's own row, and hint mode never reads the log.
|
|
894
|
+
// The listener stays registered in every mode, because the hook surface is part
|
|
895
|
+
// of this preset's contract whatever a mode does with it.
|
|
856
896
|
ctx.on('tools/result', (exec, result) => {
|
|
897
|
+
if (instructionSource !== 'system-prompt') return
|
|
857
898
|
if (result?.isError || !exec?.agent || exec?.signal?.aborted) return
|
|
858
899
|
const path = filePathFromExecution(exec)
|
|
859
900
|
if (!path) return
|
|
@@ -873,6 +914,14 @@ export function apply(ctx, config) {
|
|
|
873
914
|
|
|
874
915
|
const agent = payload?.agent
|
|
875
916
|
const session = agent?.session
|
|
917
|
+
|
|
918
|
+
// Host mode: the harness's agent-instructions row owns the channel, so every
|
|
919
|
+
// message it queued — baseline and dynamic alike — passes through verbatim:
|
|
920
|
+
// no filterInstructionMessages, no dynamic subdirectory discovery, no
|
|
921
|
+
// plugin-authored message, and no per-session state to build. Handing the
|
|
922
|
+
// decision back unchanged is the point.
|
|
923
|
+
if (instructionSource === 'host') return decision
|
|
924
|
+
|
|
876
925
|
const state = session ? getSessionState(session) : undefined
|
|
877
926
|
|
|
878
927
|
if (instructionSource === 'hint') {
|
|
@@ -880,12 +929,6 @@ export function apply(ctx, config) {
|
|
|
880
929
|
return { ...decision, messages: instructionHintMessages(decision.messages, state) }
|
|
881
930
|
}
|
|
882
931
|
|
|
883
|
-
// Host mode: the harness's agent-instructions row owns the channel, so every
|
|
884
|
-
// message it queued — baseline and dynamic alike — passes through verbatim:
|
|
885
|
-
// no filterInstructionMessages, no dynamic subdirectory discovery, no
|
|
886
|
-
// plugin-authored message. Handing the decision back unchanged is the point.
|
|
887
|
-
if (instructionSource === 'host') return decision
|
|
888
|
-
|
|
889
932
|
// System-prompt mode:
|
|
890
933
|
const cwd = session?.header?.cwd
|
|
891
934
|
const baselineLoaded = state?.baselineLoaded ?? false
|
|
@@ -921,8 +964,12 @@ export function apply(ctx, config) {
|
|
|
921
964
|
}, { prepend: true })
|
|
922
965
|
|
|
923
966
|
// 4. Session lifecycle / compaction recovery
|
|
967
|
+
//
|
|
968
|
+
// Host mode writes no per-session state (the harness's own row owns the
|
|
969
|
+
// channel), so it has nothing to reset and the map is never consulted there.
|
|
924
970
|
ctx.on('session/event', (session, event) => {
|
|
925
971
|
if (event?.type === 'compaction/end') {
|
|
972
|
+
if (instructionSource === 'host') return
|
|
926
973
|
const state = sessionStateMap.get(session)
|
|
927
974
|
if (state) {
|
|
928
975
|
state.hinted = false
|