@linxin666/dsh-liangshen 0.1.17 → 0.1.19

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 CHANGED
@@ -2,5 +2,5 @@
2
2
  # side as of the last confirmed-consistent state. Both languages carry equal authority;
3
3
  # after editing either side, bring the other along and re-record with:
4
4
  # node scripts/verify-docs.mjs --write <dir>
5
- README.md: b7f13d1e7027a3f9fdf40f53d15bb96a736f8cf2
6
- README.zh.md: 27da5569dd9068c83f7a64f8faa5f46683b8c3ad
5
+ README.md: ae227ee20159760120c4b9b6a939be7a86630083
6
+ README.zh.md: f801f176e5fa64c68982425b040cd5bd424d5210
package/README.md CHANGED
@@ -23,7 +23,8 @@ The preset ships with extra safeguards on top of the reference mechanism, all co
23
23
  - `promoteAfterFirstResponse` — a tool-less first response promotes once it has responded; an anchor-gated session also releases when its first turn ends (`turn/end`), so the next user turn already sees the promoted catalog;
24
24
  - `promotedPresentation: code` — after promotion the wire is Code Mode (PTC): one `run_code` tool with the full registry available through the generated SDK, switched at the step boundary so the current step's native calls are never interrupted;
25
25
  - `deferredSources` + `deferredGraceSteps` — workspace instructions and the skill catalog wait one extra step after promotion, so the tool-catalog switch and the injection shock do not land in the same step;
26
- - `bootstrapMaxTokens` — caps the phase-1 request output budget (community measurements put `max_tokens=1024` in the high-hit "We need" window, versus 0/5 at the 256k DSH default), and the cap is stripped again after promotion so `requestProposal` never solders 1024 into every later request.
26
+ - `bootstrapMaxTokens` — caps the phase-1 request output budget (community measurements put `max_tokens=1024` in the high-hit "We need" window, versus 0/5 at the 256k DSH default), and the cap is stripped again after promotion so `requestProposal` never solders 1024 into every later request;
27
+ - `phase1FirstCallInstruction` — an opt-in extra line appended to the phase-1 persona, off by default: test builds use it to ask the model to ground its first answer with one Minimal-native tool call before responding, so first-turn capability questions are answered from the promoted registry instead of the cropped two-tool view. It deviates from the byte-exact Minimal surface, which is why it ships unset.
27
28
 
28
29
  Plan mode is supported: phase 1 filters the assembled prompt sections down to the one-line `deployment:persona`, and promotion restores all sections and appends the session's working directory to the persona, so the agent knows its workspace and the plan-mode `plan:policy` section takes effect for every step after promotion.
29
30
 
@@ -68,6 +69,7 @@ node tools/analyze-session.mjs ~/.dsh/sessions/<workspace>/<session>/session.jso
68
69
  - Workspace instructions, the skill catalog, and the runtime snapshot stay out of phase 1; the snapshot returns with the catalog and the other two arrive one step later;
69
70
  - Phase-1 file tools inherit the host file sandbox (no bare `dsh-fs-local` filesystem);
70
71
  - The phase-1 persistent `bash` replaces the Standard ephemeral shell for the whole session (both tools register the name `bash`);
72
+ - Phase 1 shows the two Minimal tools by design, so a first-turn capability question (for example "can you browse the web") can be answered from the cropped view and then corrected after promotion; the opt-in `phase1FirstCallInstruction` (see Stabilization controls) asks for a grounding tool call first, and otherwise task-style first turns avoid the mismatch;
71
73
  - The catalog changes exactly once, so a prefix-cache change happens between the first and second request;
72
74
  - The preset carries the same trust level as shell access — review `presets/liangshen/` before installing;
73
75
  - The plugin makes no network requests and adds no telemetry;
package/README.zh.md CHANGED
@@ -23,7 +23,8 @@ preset 在参考机制之上内置了额外保护,全部在 `agent.cordis.yml`
23
23
  - `promoteAfterFirstResponse`:首轮无工具调用的回答在响应后自动晋升;锚定门控中的会话也会在首轮结束时(`turn/end`)释放,因此新用户轮次一开始就拿到晋升后的目录;
24
24
  - `promotedPresentation: code`:晋升后 wire 为 Code Mode(PTC)——一个 `run_code` 工具、完整注册表通过生成 SDK 调用;切换发生在 step 边界,不会打断当前步的原生工具调用;
25
25
  - `deferredSources` + `deferredGraceSteps`:workspace 指令与 skill 目录在晋升后再等一步注入,工具目录切换和注入冲击不同时落地;
26
- - `bootstrapMaxTokens`:phase 1 请求的输出预算封顶(社区实测 `max_tokens=1024` 是 "We need" 轨迹的高命中窗口,DSH 默认 256k 命中率为 0),晋升后自动剥离该封顶,避免 `requestProposal` 把 1024 焊进后续每个请求。
26
+ - `bootstrapMaxTokens`:phase 1 请求的输出预算封顶(社区实测 `max_tokens=1024` 是 "We need" 轨迹的高命中窗口,DSH 默认 256k 命中率为 0),晋升后自动剥离该封顶,避免 `requestProposal` 把 1024 焊进后续每个请求;
27
+ - `phase1FirstCallInstruction`:追加到 phase-1 persona 的可选一行指令,默认关闭:测试版本用它要求模型在正式作答前先做一次 Minimal 原生工具调用,让首轮能力类提问在晋升后的完整目录下作答,而不是基于被裁剪的双工具视图回答。因为它偏离了逐字节一致的 Minimal 表面,所以默认不开启。
27
28
 
28
29
  已支持 plan mode:phase 1 会把 prompt sections 过滤为仅剩一行 `deployment:persona`,晋升后恢复全部 sections 并在 persona 末尾追加所选工作区路径,因此 Agent 明确自己的工作目录,plan-mode 的 `plan:policy` 也在晋升后的每一步都生效。
29
30
 
@@ -68,6 +69,7 @@ node tools/analyze-session.mjs <导出的 session.jsonl>
68
69
  - workspace 指令、skill 目录与运行时快照在首轮不注入;快照随 PTC 目录出现,前两者再晚一步出现;
69
70
  - phase 1 文件工具继承宿主文件沙箱(不挂载裸 `dsh-fs-local`);
70
71
  - phase 1 的持久 `bash` 会替代 Standard 的一次性 shell 直到会话结束(两个工具都注册 `bash` 名字);
72
+ - phase 1 有意只显示 Minimal 双工具,因此首轮能力类提问(如「你能联网吗」)可能基于被裁剪的视图作答、晋升后再被纠正;可开启 `phase1FirstCallInstruction`(见稳定化控制)要求先做一次 grounding 工具调用,或首轮直接问任务类问题避免该错位;
71
73
  - 工具目录只变化一次,因此第一、二次请求之间会发生一次前缀缓存变化;
72
74
  - preset 与 shell 访问具有相同信任等级,安装前可自行审阅 `presets/`;
73
75
  - 插件不发起网络请求,也不增加遥测;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@linxin666/dsh-liangshen",
3
3
  "description": "LiangShen (梁神) agent preset for the dsh web GUI: a two-phase anchored-standard preset — the first model request exposes only the builtin Minimal exact two-tool surface (persistent bash plus str_replace_editor) with no runtime contexts or injected instructions (Minimal-aligned trajectory anchor), promotion is gated on the first minimal-like reasoning block with a fallback, and the wire then switches to Code Mode (PTC, a single run_code tool over the full registry) with the ordinary injections returning afterwards. The preset files are synced into ~/.dsh/.agent-presets on host startup. Hot-pluggable — mounted via cordis.patch.yml + a profile node_modules symlink, no dsh source changes.",
4
- "version": "0.1.17",
4
+ "version": "0.1.19",
5
5
  "type": "module",
6
6
  "engines": {
7
7
  "node": "^22.19.0 || >=24.0.0"
@@ -55,6 +55,16 @@
55
55
  # step after promotion. `bootstrapMaxTokens` caps the phase-1 request output
56
56
  # budget (community-observed "We need" trigger window, 1024) and is stripped
57
57
  # again after promotion so the cap never solders into later requests.
58
+ # After a compaction the session falls back to the controlled phase — the
59
+ # bootstrap pair plus `compactionTools` (a core work set) — until a NEW
60
+ # promotion signal exists past the boundary, and Code Mode is released until
61
+ # the session re-promotes.
62
+ # `phase1FirstCallInstruction` is an opt-in extra line appended to the
63
+ # phase-1 persona for test builds (issue #274): the model is asked to ground
64
+ # its first answer with one Minimal-native tool call before responding, so
65
+ # first-turn capability questions are answered from the promoted registry
66
+ # instead of the cropped two-tool view. It deviates from the byte-exact
67
+ # Minimal surface and is therefore left unset (off) by default.
58
68
  - id: tool-bootstrap
59
69
  name: ./tool-bootstrap.mjs
60
70
  config:
@@ -65,9 +75,11 @@
65
75
  maxBootstrapSteps: 4
66
76
  promoteAfterFirstResponse: true
67
77
  bootstrapMaxTokens: 1024
78
+ compactionTools: [read, write, edit, glob, grep, todo_write, ask_user_question]
68
79
  deferredSources: [agent-instructions, skill-catalog]
69
80
  deferredGraceSteps: 1
70
81
  promotedPresentation: code
82
+ # phase1FirstCallInstruction: After your first reasoning block, before answering, make one tool call (for example run `pwd` through the shell or view a workspace file) and base your answer on its result.
71
83
 
72
84
  # Workspace instructions are quarantined by `tool-bootstrap` during phase 1
73
85
  # and deferred one step after promotion, then stay current.
@@ -22,6 +22,27 @@
22
22
  * `deferredGraceSteps` delay selected injected message kinds (workspace
23
23
  * instructions, skill catalog) for a few steps after promotion.
24
24
  *
25
+ * COMPACTION (local addition, ported from the upstream compaction-epoch
26
+ * semantics): a compaction rewrites the whole model-visible surface, so the
27
+ * first post-compaction request is a "second first request". A
28
+ * `compaction/end` event releases Code Mode (the presentation disposer) and
29
+ * resets the promotion state to the CONTROLLED phase — bootstrap pair plus
30
+ * `compactionTools` (a core work set, default none) — until a NEW durable
31
+ * promotion signal exists past that boundary. The reset lives both in the
32
+ * live `session/event` path and inside the durable-log scan, so resume and
33
+ * reload reconstruct the same phase.
34
+ *
35
+ * ROBUSTNESS: composition drift (a missing bootstrap shell or common tool)
36
+ * degrades to the full catalog with a one-time warning instead of throwing,
37
+ * so a broken composition can never lock a session out of every request.
38
+ *
39
+ * OPT-IN PHASE-1 INSTRUCTION (issue #274): `phase1FirstCallInstruction` is
40
+ * an optional string appended to the phase-1 persona; unset (the default)
41
+ * keeps the phase-1 persona the exact one-line Minimal anchor. Test builds
42
+ * use it to ask the model to ground its first answer with one Minimal-native
43
+ * tool call before responding, so first-turn capability questions are
44
+ * answered from the promoted registry instead of the cropped two-tool view.
45
+ *
25
46
  * Source: https://github.com/xiaobright/dsh-anchored-standard (MIT), extended
26
47
  * with the phase-1 quarantine and the stabilization controls above.
27
48
  */
@@ -74,6 +95,14 @@ function stringListOrEmpty(value, field) {
74
95
  return [...new Set(value)]
75
96
  }
76
97
 
98
+ function optionalString(value, field) {
99
+ if (value === undefined) return ''
100
+ if (typeof value !== 'string') {
101
+ throw new TypeError(`${name}: ${field} must be a string`)
102
+ }
103
+ return value
104
+ }
105
+
77
106
  function integerAtLeast(value, field, minimum) {
78
107
  if (!Number.isInteger(value) || value < minimum) {
79
108
  throw new TypeError(`${name}: ${field} must be an integer >= ${minimum}`)
@@ -151,12 +180,45 @@ function stateFor(session) {
151
180
  steps: 0,
152
181
  deferredSteps: 0,
153
182
  presentationApplied: false,
183
+ hasCompacted: false,
184
+ presentationDisposer: undefined,
154
185
  }
155
186
  promotionBySession.set(session, state)
156
187
  }
157
188
  return state
158
189
  }
159
190
 
191
+ /**
192
+ * Reset one session back to the CONTROLLED phase after a compaction. A
193
+ * compaction rewrites the whole model-visible surface — the first
194
+ * post-compaction request is a "second first request" with the same
195
+ * first-token conditions the bootstrap exists to control — so the session
196
+ * re-anchors: promotion state is cleared (the durable `next` scan pointer is
197
+ * kept, so events recorded BEFORE the boundary never re-promote), and the
198
+ * Code Mode presentation is disposed so the next assembly sees the native
199
+ * catalog and the phase-1 filter can narrow it again.
200
+ */
201
+ function resetToControlled(state) {
202
+ if (typeof state.presentationDisposer === 'function') {
203
+ try {
204
+ state.presentationDisposer()
205
+ } catch {
206
+ // A failed presentation reset must never break the session; the
207
+ // next promotion re-declares Code Mode anyway.
208
+ }
209
+ state.presentationDisposer = undefined
210
+ }
211
+ state.promoted = false
212
+ state.toolCalled = false
213
+ state.responded = false
214
+ state.anchored = false
215
+ state.turnEnded = false
216
+ state.steps = 0
217
+ state.deferredSteps = 0
218
+ state.presentationApplied = false
219
+ state.hasCompacted = true
220
+ }
221
+
160
222
  /**
161
223
  * Switch one agent's wire presentation to Code Mode (PTC: a single `run_code`
162
224
  * tool backed by the generated SDK) after promotion. `agent.ctx.tools` is the
@@ -167,7 +229,10 @@ function applyPresentation(agent, state, policy) {
167
229
  state.presentationApplied = true
168
230
  const tools = agent.ctx.tools
169
231
  if (tools === undefined) return
170
- tools.presentAs('code')
232
+ // The disposer restores the deployment-default (native) presentation; it is
233
+ // kept on the state so a post-compaction reset can release Code Mode and
234
+ // let the phase-1 catalog filter see the native tool list again.
235
+ state.presentationDisposer = tools.presentAs('code')
171
236
  }
172
237
 
173
238
  /**
@@ -193,7 +258,14 @@ function scanEvents(state, session) {
193
258
  for (; state.next < events.length; state.next += 1) {
194
259
  const event = events[state.next]
195
260
  if (event === undefined) continue
196
- if (event.type === 'tool/call') {
261
+ if (event.type === 'compaction/end') {
262
+ // A compaction rewrites the model-visible surface: the session falls
263
+ // back to the controlled phase until a NEW promotion signal exists
264
+ // past this boundary (the `next` pointer stays, so events before the
265
+ // boundary never re-promote). Handled inside the scan so cold starts
266
+ // reconstruct the same phase from the durable log.
267
+ resetToControlled(state)
268
+ } else if (event.type === 'tool/call') {
197
269
  state.toolCalled = true
198
270
  } else if (event.type === 'step/start') {
199
271
  state.steps += 1
@@ -253,9 +325,29 @@ export function apply(ctx, config) {
253
325
  if (presentation !== 'native' && presentation !== 'code') {
254
326
  throw new TypeError(`${name}: promotedPresentation must be "native" or "code"`)
255
327
  }
328
+
329
+ let warned = false
330
+ const warnOnce = (message) => {
331
+ if (warned) return
332
+ warned = true
333
+ try {
334
+ ctx.logger.warn(message)
335
+ } catch {
336
+ // Logger unavailable — the guard exists only to avoid spamming.
337
+ }
338
+ }
256
339
  const bootstrapMaxTokens = config.bootstrapMaxTokens === undefined
257
340
  ? undefined
258
341
  : integerAtLeast(config.bootstrapMaxTokens, 'bootstrapMaxTokens', 1)
342
+ // Core work set exposed during the post-compaction controlled phase, so a
343
+ // mid-task model keeps working with a small catalog instead of the full
344
+ // Standard set. Defaults to none: the session stays on the bootstrap pair
345
+ // until a new promotion signal (the composition may widen it via config).
346
+ const compactionTools = stringListOrEmpty(config.compactionTools, 'compactionTools')
347
+ // Opt-in extra line for the phase-1 persona (test builds, issue #274):
348
+ // asks the model to ground its first answer with a Minimal-native tool
349
+ // call before responding. Unset keeps the exact one-line persona.
350
+ const phase1FirstCallInstruction = optionalString(config.phase1FirstCallInstruction, 'phase1FirstCallInstruction')
259
351
  const policy = {
260
352
  anchorGate: config.anchorGate === true,
261
353
  promoteAfterFirstResponse: config.promoteAfterFirstResponse === true,
@@ -263,14 +355,23 @@ export function apply(ctx, config) {
263
355
  deferredGraceSteps: integerAtLeast(config.deferredGraceSteps ?? 0, 'deferredGraceSteps', 0),
264
356
  promotedPresentation: presentation,
265
357
  bootstrapMaxTokens,
358
+ compactionTools,
359
+ phase1FirstCallInstruction,
266
360
  }
267
361
 
268
362
  // Promotion is applied at step/turn boundaries, never while a step is still
269
363
  // executing tools: switching the presentation mid-step would collapse the
270
364
  // native calls that step already planned. By `step/end` the tool-call and
271
365
  // reasoning events are durable, so the NEXT prompt assembly already sees
272
- // Code Mode with its generated SDK section.
366
+ // Code Mode with its generated SDK section. A `compaction/end` event
367
+ // releases Code Mode and resets the promotion state (see
368
+ // resetToControlled); the reset also runs inside scanEvents, so a cold
369
+ // start reconstructs the same controlled phase from the durable log.
273
370
  ctx.on('session/event', (session, event) => {
371
+ if (event.type === 'compaction/end') {
372
+ resetToControlled(stateFor(session))
373
+ return
374
+ }
274
375
  if (event.type !== 'step/end' && event.type !== 'turn/end') return
275
376
  const state = stateFor(session)
276
377
  if (!state.promoted) {
@@ -288,6 +389,8 @@ export function apply(ctx, config) {
288
389
  // result (including messages appended by listener order, not row order)
289
390
  // before the quarantine strips it.
290
391
  ctx.on('system-prompt/assemble', async (_assembly, context, next) => {
392
+ // Downstream errors propagate untouched; only this filter's own logic is
393
+ // guarded (a filter bug must never brick every request of a session).
291
394
  const assembled = await next()
292
395
  const agent = context.agent
293
396
  if (agent === undefined) return assembled
@@ -298,20 +401,38 @@ export function apply(ctx, config) {
298
401
  const selectedShells = shellTools.filter(toolName => available.has(toolName))
299
402
  const missingCommon = commonTools.filter(toolName => !available.has(toolName))
300
403
  if (selectedShells.length !== 1 || missingCommon.length > 0) {
301
- throw new Error(
404
+ // Composition drift must not lock a session out: degrade to the full
405
+ // catalog with a one-time warning instead of throwing (the bootstrap
406
+ // phase surfaces will simply not apply).
407
+ warnOnce(
302
408
  `${name}: expected exactly one bootstrap shell and every common tool; `
303
- + `shells=${JSON.stringify(selectedShells)}, missing=${JSON.stringify(missingCommon)}`,
409
+ + `shells=${JSON.stringify(selectedShells)}, missing=${JSON.stringify(missingCommon)} — `
410
+ + 'bootstrap disabled, full catalog exposed',
304
411
  )
412
+ return assembled
305
413
  }
306
414
 
307
415
  const bootstrap = new Set([...selectedShells, ...commonTools])
416
+ // After a compaction the controlled phase widens with the core work set
417
+ // so mid-task work can continue before re-promotion.
418
+ if (state.hasCompacted) for (const toolName of compactionTools) bootstrap.add(toolName)
419
+ const sections = Array.isArray(assembled.sections)
420
+ ? assembled.sections.filter(section => PERSONA_SECTION_NAMES.has(section?.name))
421
+ : undefined
422
+ // Opt-in phase-1 instruction: appended once to the persona section so
423
+ // test builds can shift the first answer behind a Minimal-native tool
424
+ // call (issue #274). Unset leaves the exact one-line persona.
425
+ const phase1Sections = sections === undefined || phase1FirstCallInstruction === ''
426
+ ? sections
427
+ : sections.map(section => {
428
+ if (typeof section?.text !== 'string' || section.text.includes(phase1FirstCallInstruction)) return section
429
+ return { ...section, text: `${section.text}${phase1FirstCallInstruction}` }
430
+ })
308
431
  return {
309
432
  ...assembled,
310
433
  tools: assembled.tools.filter(tool => bootstrap.has(tool.name)),
311
434
  contexts: [],
312
- ...(Array.isArray(assembled.sections)
313
- ? { sections: assembled.sections.filter(section => PERSONA_SECTION_NAMES.has(section?.name)) }
314
- : {}),
435
+ ...(phase1Sections !== undefined ? { sections: phase1Sections } : {}),
315
436
  }
316
437
  }, { prepend: true })
317
438