@linxin666/dsh-liangshen 0.3.3 → 0.3.4

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/lib/index.js CHANGED
@@ -4,6 +4,7 @@ import { fileURLToPath } from "node:url";
4
4
  import { Service } from "@deepseek-ai/cordis";
5
5
  import z from "schemastery";
6
6
  import { homedir } from "node:os";
7
+ import { isAbsolute as isAbsolute$1, join as join$1 } from "node:path/posix";
7
8
  //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-settings@0.1.1-rc.2_@deepseek-ai+cordis@4.0.1_@deepseek-ai+dsh-brand@0_02aaf429ec98c58247037e2222c17a8f/node_modules/@deepseek-ai/dsh-settings/lib/index.js
8
9
  /**
9
10
  * Structural secret redaction for settings values. `role('secret')` fields are
@@ -209,8 +210,9 @@ function installSettingsSection(ctx, ns, schema, entry, hooks) {
209
210
  */
210
211
  /** Expand a leading ~ (or ~user) in a path, platform-style. */
211
212
  function expandHome(path, home = homedir()) {
213
+ const j = home.startsWith("/") ? join$1 : join;
212
214
  if (path === "~") return home;
213
- if (path.startsWith("~/") || path.startsWith("~\\")) return join(home, path.slice(2));
215
+ if (path.startsWith("~/") || path.startsWith("~\\")) return j(home, path.slice(2));
214
216
  return path;
215
217
  }
216
218
  /**
@@ -220,12 +222,15 @@ function expandHome(path, home = homedir()) {
220
222
  * @returns the absolute DSH home path.
221
223
  */
222
224
  function resolveDshHome(env = process.env, home = homedir()) {
225
+ const isPosix = home.startsWith("/");
226
+ const j = isPosix ? join$1 : join;
227
+ const isAbs = isPosix ? isAbsolute$1 : isAbsolute;
223
228
  const raw = env.DSH_HOME;
224
229
  if (raw !== void 0 && raw.trim() !== "") {
225
230
  const expanded = expandHome(raw.trim(), home);
226
- return isAbsolute(expanded) ? expanded : join(process.cwd(), expanded);
231
+ return isAbs(expanded) ? expanded : j(process.cwd(), expanded);
227
232
  }
228
- return join(home, ".dsh");
233
+ return j(home, ".dsh");
229
234
  }
230
235
  /** Resolve the DSH home directory from the live environment. */
231
236
  function dshHome() {
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 PTC Mode (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.3.3",
4
+ "version": "0.3.4",
5
5
  "type": "module",
6
6
  "engines": {
7
7
  "node": "^22.19.0 || >=24.0.0"
@@ -273,7 +273,7 @@ function stateFor(session) {
273
273
  * PTC Mode presentation is disposed so the next assembly sees the native
274
274
  * catalog and the phase-1 filter can narrow it again.
275
275
  */
276
- function resetToControlled(state) {
276
+ function resetToControlled(state, session) {
277
277
  if (typeof state.presentationDisposer === 'function') {
278
278
  try {
279
279
  state.presentationDisposer()
@@ -282,6 +282,10 @@ function resetToControlled(state) {
282
282
  // next promotion re-declares PTC Mode anyway.
283
283
  }
284
284
  state.presentationDisposer = undefined
285
+ const agent = session !== undefined ? agentBySession.get(session) : undefined
286
+ if (agent?.ctx && typeof agent.ctx.emit === 'function') {
287
+ agent.ctx.emit('tools/presentation-changed', { mode: 'native', session: session?.id })
288
+ }
285
289
  }
286
290
  state.promoted = false
287
291
  state.toolCalled = false
@@ -302,7 +306,7 @@ function resetToControlled(state) {
302
306
  */
303
307
  function applyPresentation(agent, state, policy) {
304
308
  if (state.presentationApplied || policy.promotedPresentation !== 'code') return
305
- const tools = agent.ctx.tools
309
+ const tools = agent?.ctx?.tools
306
310
  // Latch only after the switch really happened: without a tools view there
307
311
  // is nothing to present, and latching early would skip PTC Mode forever.
308
312
  if (tools === undefined) return
@@ -311,6 +315,11 @@ function applyPresentation(agent, state, policy) {
311
315
  // let the phase-1 catalog filter see the native tool list again.
312
316
  state.presentationDisposer = tools.presentAs('code')
313
317
  state.presentationApplied = true
318
+ // #1128: Broadcast presentation switch so external discipline / analysis
319
+ // plugins decouple presentation mode from tool failure detection.
320
+ if (typeof agent?.ctx?.emit === 'function') {
321
+ agent.ctx.emit('tools/presentation-changed', { mode: 'code', session: agent.session?.id })
322
+ }
314
323
  }
315
324
 
316
325
  /**
@@ -342,7 +351,7 @@ function scanEvents(state, session) {
342
351
  // past this boundary (the `next` pointer stays, so events before the
343
352
  // boundary never re-promote). Handled inside the scan so cold starts
344
353
  // reconstruct the same phase from the durable log.
345
- resetToControlled(state)
354
+ resetToControlled(state, session)
346
355
  } else if (event.type === 'tool/call') {
347
356
  state.toolCalled = true
348
357
  } else if (event.type === 'step/start') {
@@ -370,6 +379,8 @@ function refresh(agent, policy) {
370
379
  return state
371
380
  }
372
381
 
382
+ const PTC_INSTRUCTION = '\n\nNote: You are in Programmatic Tool Calling (PTC) mode. All actions (running shell commands, file operations, web tools) MUST be performed via the `run_code` tool by writing and executing TypeScript/JavaScript programs. Do not attempt to invoke tools like `bash` or `str_replace_editor` directly on the wire.'
383
+
373
384
  /**
374
385
  * Append the session's working directory to the persona section of a promoted
375
386
  * assembly. Returns the assembly unchanged when there is no persona section,
@@ -393,6 +404,25 @@ function withWorkspaceLine(assembly, agent) {
393
404
  }
394
405
  }
395
406
 
407
+ /**
408
+ * Append PTC mode instructions to the persona section when promoted to code presentation.
409
+ */
410
+ function withPtcInstruction(assembly, policy) {
411
+ if (policy?.promotedPresentation !== 'code') return assembly
412
+ if (!Array.isArray(assembly.sections)) return assembly
413
+ const persona = assembly.sections.find(section =>
414
+ PERSONA_SECTION_NAMES.has(section?.name)
415
+ && typeof section?.text === 'string'
416
+ && !section.text.includes('PTC) mode'))
417
+ if (persona === undefined) return assembly
418
+ return {
419
+ ...assembly,
420
+ sections: assembly.sections.map(section => section === persona
421
+ ? { ...section, text: `${persona.text}${PTC_INSTRUCTION}` }
422
+ : section),
423
+ }
424
+ }
425
+
396
426
  /** Register the per-session bootstrap quarantine and promotion policy. */
397
427
  export function apply(ctx, config) {
398
428
  const commonTools = stringList(config.commonTools, 'commonTools')
@@ -451,7 +481,7 @@ export function apply(ctx, config) {
451
481
  // start reconstructs the same controlled phase from the durable log.
452
482
  ctx.on('session/event', (session, event) => {
453
483
  if (event.type === 'compaction/end') {
454
- resetToControlled(stateFor(session))
484
+ resetToControlled(stateFor(session), session)
455
485
  return
456
486
  }
457
487
  if (event.type !== 'step/end' && event.type !== 'turn/end') return
@@ -477,7 +507,7 @@ export function apply(ctx, config) {
477
507
  const agent = context.agent
478
508
  if (agent === undefined) return assembled
479
509
  const state = refresh(agent, policy)
480
- if (state.promoted) return withWorkspaceLine(assembled, agent)
510
+ if (state.promoted) return withPtcInstruction(withWorkspaceLine(assembled, agent), policy)
481
511
 
482
512
  const available = new Set(assembled.tools.map(tool => tool.name))
483
513
  const selectedShells = shellTools.filter(toolName => available.has(toolName))
package/src/dsh-home.ts CHANGED
@@ -7,11 +7,14 @@
7
7
 
8
8
  import { homedir } from 'node:os'
9
9
  import { isAbsolute, join } from 'node:path'
10
+ import { isAbsolute as posixIsAbsolute, join as posixJoin } from 'node:path/posix'
10
11
 
11
12
  /** Expand a leading ~ (or ~user) in a path, platform-style. */
12
13
  export function expandHome(path: string, home: string = homedir()): string {
14
+ const isPosix = home.startsWith('/')
15
+ const j = isPosix ? posixJoin : join
13
16
  if (path === '~') return home
14
- if (path.startsWith('~/') || path.startsWith('~\\')) return join(home, path.slice(2))
17
+ if (path.startsWith('~/') || path.startsWith('~\\')) return j(home, path.slice(2))
15
18
  return path
16
19
  }
17
20
 
@@ -22,12 +25,15 @@ export function expandHome(path: string, home: string = homedir()): string {
22
25
  * @returns the absolute DSH home path.
23
26
  */
24
27
  export function resolveDshHome(env: NodeJS.ProcessEnv = process.env, home: string = homedir()): string {
28
+ const isPosix = home.startsWith('/')
29
+ const j = isPosix ? posixJoin : join
30
+ const isAbs = isPosix ? posixIsAbsolute : isAbsolute
25
31
  const raw = env.DSH_HOME
26
32
  if (raw !== undefined && raw.trim() !== '') {
27
33
  const expanded = expandHome(raw.trim(), home)
28
- return isAbsolute(expanded) ? expanded : join(process.cwd(), expanded)
34
+ return isAbs(expanded) ? expanded : j(process.cwd(), expanded)
29
35
  }
30
- return join(home, '.dsh')
36
+ return j(home, '.dsh')
31
37
  }
32
38
 
33
39
  /** Resolve the DSH home directory from the live environment. */