@linxin666/dsh-liangshen 0.3.20 → 0.3.21

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.
@@ -0,0 +1,331 @@
1
+ /**
2
+ * Lever controller: the business face behind the homepage lever.
3
+ *
4
+ * The view stays pure; every fact and verb comes from here. The roster arrives
5
+ * over the agent-preset Remote namespace (the same one the official surfaces
6
+ * read), the current session comes from the browser sessions service, and the
7
+ * switch goes through `agentPresets.select`, which the host accepts only while
8
+ * the session is still blank.
9
+ *
10
+ * Nothing is cached across reloads except in memory: the lever reads the
11
+ * session's `agentPreset` projection, so a page reload still shows the true
12
+ * state, while `previous` (the preset a push-up restores) is remembered for
13
+ * the length of the page visit and otherwise falls back to the deployment
14
+ * default.
15
+ */
16
+
17
+ import type { Context as ClientContext } from '@deepseek-ai/cordis'
18
+ import type { AgentPresetRoster } from '@deepseek-ai/dsh-agent-presets/types'
19
+ import type { ISessions } from '@deepseek-ai/dsh-api-session-controller/client'
20
+ import type { RemoteResult } from '@deepseek-ai/dsh-api-remotes/client'
21
+ import { createSnapshotStore, type SnapshotStore } from '@deepseek-ai/dsh-client-store'
22
+ import { LIANGSHEN_PRESET_ID, isActionable, leverState, restoreTarget, type LeverFacts, type LeverState } from '../core/lever.ts'
23
+ import type { LiangShenKey } from './locales.ts'
24
+
25
+ /**
26
+ * Why the last switch was refused, mapped from the Remote failure code so the
27
+ * view can render localized copy instead of a host message.
28
+ */
29
+ export type LeverError =
30
+ /** The session already started; its composition is fixed. */
31
+ | { kind: 'locked' }
32
+ /** The deployment supplies no such preset. */
33
+ | { kind: 'missing' }
34
+ /**
35
+ * The switch outlived its ceiling. A Remote answer can be lost on the way
36
+ * back even though the host committed the change, so the lever must stop
37
+ * claiming to be busy and let the next session read report the truth.
38
+ */
39
+ | { kind: 'timeout' }
40
+ /** Anything else, carrying the host's own reason. */
41
+ | { kind: 'failed'; reason: string }
42
+
43
+ /** How long one preset switch may stay in flight before it is reported as timed out. */
44
+ export const SELECT_TIMEOUT_MS = 10_000
45
+
46
+ /** What the lever view renders. */
47
+ export interface LeverSnapshot {
48
+ /** Resolved lever state. */
49
+ state: LeverState
50
+ /** Display name of the preset a push-up restores; empty when there is none. */
51
+ restoreLabel: string
52
+ /** A switch is in flight. */
53
+ busy: boolean
54
+ /** The last refusal, cleared by the next attempt. */
55
+ error?: LeverError
56
+ /** Increments when a pull-down landed, so the view replays the burst once. */
57
+ burst: number
58
+ }
59
+
60
+ /**
61
+ * The two agent-preset Remote calls this plugin makes. Spelled locally: the
62
+ * generated namespace merge belongs to the SDK's own client packages, and this
63
+ * browser bundle only needs the two members it calls.
64
+ */
65
+ export interface AgentPresetRemote {
66
+ list(): Promise<RemoteResult<AgentPresetRoster>>
67
+ select(sessionId: string, agentPreset: string): Promise<RemoteResult<string>>
68
+ }
69
+
70
+ /** The injected face the lever view consumes. */
71
+ export interface LeverFace {
72
+ /** The snapshot store the view subscribes to. */
73
+ store: SnapshotStore<LeverSnapshot>
74
+ /** Pull the lever down: turn LiangShen mode on. */
75
+ pull: () => void
76
+ /** Push the lever up: restore the previous preset. */
77
+ push: () => void
78
+ /** Translate one lever key. */
79
+ t: (key: LiangShenKey, vars?: Record<string, string | number>) => string
80
+ }
81
+
82
+ /** Read the preset a session summary reports, when it reports one. */
83
+ function presetOf(session: { projectionValues?: Record<string, unknown> } | undefined): string | undefined {
84
+ const value = session?.projectionValues?.['agentPreset']
85
+ return typeof value === 'string' ? value : undefined
86
+ }
87
+
88
+ /** The lever controller: roster read, session facts, and the preset switch. */
89
+ export class LeverController {
90
+ private readonly store: SnapshotStore<LeverSnapshot>
91
+
92
+ /**
93
+ * The browser services this controller reads, resolved defensively: the
94
+ * context proxy throws on any service the fiber did not inject, so a
95
+ * deployment that cannot answer one of them must leave the lever inert
96
+ * rather than take the plugin (and the composer row) down with it.
97
+ */
98
+ private readonly sessions: ISessions | undefined
99
+
100
+ private readonly remote: AgentPresetRemote | undefined
101
+
102
+ /** Roster rows as last read; empty until the first read lands. */
103
+ private rows: AgentPresetRoster['presets'] = []
104
+
105
+ /** The preset the user was on before the last pull-down. */
106
+ private previous: string | undefined
107
+
108
+ private loading = false
109
+
110
+ /** Ceiling on one in-flight switch, so a lost Remote answer cannot hang the row. */
111
+ private readonly selectTimeoutMs: number
112
+
113
+ private readonly disposers: (() => void)[] = []
114
+
115
+ constructor(private readonly ctx: ClientContext, options: LeverControllerOptions = {}) {
116
+ this.selectTimeoutMs = options.selectTimeoutMs ?? SELECT_TIMEOUT_MS
117
+ this.sessions = readService<ISessions>(() => (ctx as unknown as { sessions: ISessions }).sessions)
118
+ this.remote = readService<AgentPresetRemote>(
119
+ () => (ctx as unknown as { remote: { agentPresets: AgentPresetRemote } }).remote.agentPresets,
120
+ )
121
+ this.store = createSnapshotStore<LeverSnapshot>({
122
+ state: 'off',
123
+ restoreLabel: '',
124
+ busy: false,
125
+ burst: 0,
126
+ })
127
+ }
128
+
129
+ /** The snapshot store the view subscribes to. */
130
+ snapshot(): SnapshotStore<LeverSnapshot> {
131
+ return this.store
132
+ }
133
+
134
+ /** Follow the roster and the current session, then read the roster once. */
135
+ start(): void {
136
+ const list = this.sessions?.list
137
+ if (list !== undefined) {
138
+ this.disposers.push(list.subscribe(() => { this.refresh() }))
139
+ }
140
+ const remote = readService<{ $on?: (event: string, listener: (ns: string) => void) => () => void }>(
141
+ () => (this.ctx as unknown as { remote: { $on: (event: string, listener: (ns: string) => void) => () => void } }).remote,
142
+ )
143
+ if (typeof remote?.$on === 'function') {
144
+ this.disposers.push(remote.$on('settings/document-updated', (ns: string) => {
145
+ if (ns === 'agent-presets') void this.load()
146
+ }))
147
+ }
148
+ this.refresh()
149
+ if (this.remote !== undefined) void this.load()
150
+ }
151
+
152
+ /** Release every subscription. Idempotent. */
153
+ dispose(): void {
154
+ for (const dispose of this.disposers.splice(0)) dispose()
155
+ }
156
+
157
+ /** The inject face handed to the slot entry. */
158
+ face(): LeverFace {
159
+ return {
160
+ store: this.store,
161
+ pull: () => { void this.toggle('down') },
162
+ push: () => { void this.toggle('up') },
163
+ t: (key, vars) => {
164
+ const translate = readService<(key: LiangShenKey, vars?: Record<string, string | number>) => string>(
165
+ () => this.ctx.locale.bind('liangshen'),
166
+ )
167
+ return translate === undefined ? key : translate(key, vars)
168
+ },
169
+ }
170
+ }
171
+
172
+ /** Read the roster; a refusal leaves the lever as it was. */
173
+ async load(): Promise<void> {
174
+ if (this.loading) return
175
+ const remote = this.remote
176
+ if (remote === undefined) return
177
+ this.loading = true
178
+ try {
179
+ const result = await remote.list()
180
+ if (result.ok) this.rows = result.value.presets
181
+ } catch {
182
+ // A carrier failure leaves the roster empty; the view reports `missing`.
183
+ } finally {
184
+ this.loading = false
185
+ this.refresh()
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Recompute the snapshot from the current session and the last roster read.
191
+ * Only the derived fields are written: an in-flight switch, the last refusal,
192
+ * and the burst counter belong to the gesture, not to a session refresh.
193
+ */
194
+ refresh(): void {
195
+ const facts = this.facts()
196
+ const snapshot = this.store.getSnapshot()
197
+ const state = leverState(facts)
198
+ const target = restoreTarget(facts)
199
+ const restoreLabel = target === undefined ? '' : this.labelOf(target)
200
+ if (snapshot.state === state && snapshot.restoreLabel === restoreLabel) return
201
+ this.store.set({ ...snapshot, state, restoreLabel })
202
+ }
203
+
204
+ /** The verb behind one gesture direction. */
205
+ private async toggle(direction: 'down' | 'up'): Promise<void> {
206
+ const snapshot = this.store.getSnapshot()
207
+ if (snapshot.busy) return
208
+ const remote = this.remote
209
+ if (remote === undefined) return
210
+ const facts = this.facts()
211
+ if (!isActionable(leverState(facts))) return
212
+ const target = direction === 'down' ? LIANGSHEN_PRESET_ID : restoreTarget(facts)
213
+ const sessionId = this.currentSessionId()
214
+ if (target === undefined || sessionId === undefined) return
215
+ if (facts.agentPreset === target) {
216
+ // Already there: a gesture on the current state is a no-op, not a switch.
217
+ this.refresh()
218
+ return
219
+ }
220
+ this.store.set({ ...snapshot, busy: true, error: undefined })
221
+ let result: RemoteResult<string>
222
+ try {
223
+ result = await withTimeout(remote.select(sessionId, target), this.selectTimeoutMs)
224
+ } catch (error) {
225
+ // A timeout is its own copy: the host may well have committed the change
226
+ // even though its answer never arrived, so this reports the wait, and the
227
+ // next session read (or the next gesture) shows what actually happened.
228
+ const mapped: LeverError = error instanceof SwitchTimeout
229
+ ? { kind: 'timeout' }
230
+ : { kind: 'failed', reason: message(error) }
231
+ this.store.set({ ...this.store.getSnapshot(), busy: false, error: mapped })
232
+ this.refresh()
233
+ return
234
+ }
235
+ if (!result.ok) {
236
+ this.store.set({ ...this.store.getSnapshot(), busy: false, error: refusal(result.error) })
237
+ this.refresh()
238
+ return
239
+ }
240
+ // The switch landed: remember where to return, then celebrate only the
241
+ // pull that turned the mode on.
242
+ this.previous = direction === 'down' ? facts.agentPreset : undefined
243
+ const next = this.store.getSnapshot()
244
+ this.store.set({ ...next, busy: false, error: undefined, burst: direction === 'down' ? next.burst + 1 : next.burst })
245
+ this.refresh()
246
+ }
247
+
248
+ /** The facts one decision reads, from the live session and the roster. */
249
+ private facts(): LeverFacts {
250
+ const summary = this.currentSession()
251
+ const available = this.rows.filter(row => row.broken === undefined).map(row => row.id)
252
+ const fallback = this.rows.find(row => row.isDefault)?.id
253
+ return {
254
+ blank: summary?.blank === true,
255
+ agentPreset: presetOf(summary),
256
+ available,
257
+ fallback,
258
+ previous: this.previous,
259
+ }
260
+ }
261
+
262
+ private currentSessionId(): string | undefined {
263
+ const current = this.sessions?.list.getSnapshot().current
264
+ return current === undefined ? undefined : String(current)
265
+ }
266
+
267
+ private currentSession(): { blank?: boolean, projectionValues?: Record<string, unknown> } | undefined {
268
+ const state = this.sessions?.list.getSnapshot()
269
+ const current = state?.current
270
+ if (state === undefined || current === undefined) return undefined
271
+ return state.byId[current] as unknown as { blank?: boolean, projectionValues?: Record<string, unknown> } | undefined
272
+ }
273
+
274
+ /** Display name of one preset id, falling back to the id itself. */
275
+ private labelOf(id: string): string {
276
+ const row = this.rows.find(candidate => candidate.id === id)
277
+ return row?.name ?? id
278
+ }
279
+ }
280
+
281
+ /** The face constructor options; tests narrow the switch ceiling. */
282
+ export interface LeverControllerOptions {
283
+ /** Override {@link SELECT_TIMEOUT_MS}. */
284
+ selectTimeoutMs?: number
285
+ }
286
+
287
+ /** Raised when one switch outlives {@link SELECT_TIMEOUT_MS}. */
288
+ class SwitchTimeout extends Error {
289
+ constructor() {
290
+ super('the preset switch did not answer in time')
291
+ this.name = 'SwitchTimeout'
292
+ }
293
+ }
294
+
295
+ /** Resolve with `work`, or reject with a {@link SwitchTimeout} after `ms`. */
296
+ function withTimeout<T>(work: Promise<T>, ms: number): Promise<T> {
297
+ return new Promise<T>((resolve, reject) => {
298
+ const timer = setTimeout(() => { reject(new SwitchTimeout()) }, ms)
299
+ work.then(
300
+ (value) => { clearTimeout(timer); resolve(value) },
301
+ (error: unknown) => { clearTimeout(timer); reject(error instanceof Error ? error : new Error(String(error))) },
302
+ )
303
+ })
304
+ }
305
+
306
+ /**
307
+ * Read one context service, treating the proxy's "without inject" refusal (and
308
+ * any other resolution fault) as the service being absent.
309
+ */
310
+ function readService<T>(read: () => T): T | undefined {
311
+ try {
312
+ return read()
313
+ } catch {
314
+ return undefined
315
+ }
316
+ }
317
+
318
+ /** The host's own reason for a refusal, mapped to lever copy. */
319
+ function refusal(error: { code?: string, message?: string, details?: unknown }): LeverError {
320
+ if (error.code === 'agent-preset/locked') return { kind: 'locked' }
321
+ if (error.code === 'agent-preset/not-found') return { kind: 'missing' }
322
+ const details = error.details
323
+ if (typeof details === 'object' && details !== null && typeof (details as { reason?: unknown }).reason === 'string') {
324
+ return { kind: 'failed', reason: (details as { reason: string }).reason }
325
+ }
326
+ return { kind: 'failed', reason: error.message ?? error.code ?? 'unknown' }
327
+ }
328
+
329
+ function message(error: unknown): string {
330
+ return error instanceof Error ? error.message : String(error)
331
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Lever copy: zh-first dictionary with an English counterpart. The zh side is
3
+ * the key-set source of truth; `packages/dsh-i18n` mirrors the keys into the
4
+ * centralized ru dictionary and `pnpm i18n:check` enforces the parity.
5
+ */
6
+
7
+ /** Lever copy, key source of truth. */
8
+ export const zh = {
9
+ 'lever.a11y': '梁神模式拨杆',
10
+ 'lever.name': '梁神模式',
11
+ 'lever.hint.pull': '拨下拨杆:开启「梁神模式」',
12
+ 'lever.hint.push': '上拨拨杆:返回「{preset}」',
13
+ 'lever.hint.locked': '会话已开始,模式不可再更改',
14
+ 'lever.hint.missing': '未找到「梁神模式」预设,请先启用该插件行',
15
+ 'lever.state.on': '梁神模式',
16
+ 'lever.state.off': '普通模式',
17
+ 'lever.busy': '正在切换…',
18
+ 'lever.failed.locked': '会话已经开始,模式已锁定',
19
+ 'lever.failed.missing': '没有找到「梁神模式」预设',
20
+ 'lever.failed.timeout': '切换超时,请重试',
21
+ 'lever.failed.failed': '切换失败:{reason}',
22
+ 'burst.line1': '三秒,三辈子的代码',
23
+ 'burst.line2': '文言文 · 二进制 · 摩斯电码',
24
+ }
25
+
26
+ /** English counterpart; the key set mirrors {@link zh} exactly. */
27
+ export const en: Record<keyof typeof zh, string> = {
28
+ 'lever.a11y': 'LiangShen mode lever',
29
+ 'lever.name': 'LiangShen mode',
30
+ 'lever.hint.pull': 'Pull the lever down to turn on LiangShen mode',
31
+ 'lever.hint.push': 'Push the lever up to return to "{preset}"',
32
+ 'lever.hint.locked': 'The session has started, so its mode can no longer change',
33
+ 'lever.hint.missing': 'The LiangShen preset is not installed; enable that plugin row first',
34
+ 'lever.state.on': 'LiangShen',
35
+ 'lever.state.off': 'Standard',
36
+ 'lever.busy': 'Switching…',
37
+ 'lever.failed.locked': 'The session already started, so the mode is locked',
38
+ 'lever.failed.missing': 'The LiangShen preset was not found',
39
+ 'lever.failed.timeout': 'The switch timed out; try again',
40
+ 'lever.failed.failed': 'Switch failed: {reason}',
41
+ 'burst.line1': 'Three seconds, three lifetimes of code',
42
+ 'burst.line2': 'Classical Chinese · Binary · Morse code',
43
+ }
44
+
45
+ /** One lever copy key. */
46
+ export type LiangShenKey = keyof typeof zh
@@ -0,0 +1,68 @@
1
+ /**
2
+ * LiangShen lever logic — framework-free, no DOM, compiled by both programs.
3
+ *
4
+ * The lever is a homepage control beside the model selector: pulling it down
5
+ * turns the current session's preset into LiangShen mode, pushing it up
6
+ * restores the preset the user was on before. The facts it needs are the
7
+ * current session's preset, whether that session may still change preset at
8
+ * all, and the preset roster; the decisions are pure so they can be tested
9
+ * without the browser runtime.
10
+ *
11
+ * A preset is fixed once a session starts (the host refuses the switch with
12
+ * `agent-preset/locked`), so the lever is only meaningful while the session is
13
+ * blank — which is exactly the new-session screen it renders on.
14
+ */
15
+
16
+ /** The preset id this lever turns on; also the preset directory name. */
17
+ export const LIANGSHEN_PRESET_ID = 'liangshen'
18
+
19
+ /** What the lever currently reports. */
20
+ export type LeverState =
21
+ /** LiangShen mode is the current preset. */
22
+ | 'on'
23
+ /** Another preset is current and the session may still switch. */
24
+ | 'off'
25
+ /** The session has started; the preset can no longer change. */
26
+ | 'locked'
27
+ /** The deployment does not supply the LiangShen preset. */
28
+ | 'missing'
29
+
30
+ /** The facts one lever decision reads. */
31
+ export interface LeverFacts {
32
+ /** Whether the current session may still change preset (blank). */
33
+ blank: boolean
34
+ /** The preset the current session runs, when the session reports one. */
35
+ agentPreset?: string
36
+ /** Ids every usable roster row supplies, in roster order. */
37
+ available: readonly string[]
38
+ /** The deployment default preset id, when the roster names one. */
39
+ fallback?: string
40
+ /** The preset the user ran before the last pull-down, remembered by the client. */
41
+ previous?: string
42
+ }
43
+
44
+ /** Resolve what the lever shows for one set of facts. */
45
+ export function leverState(facts: LeverFacts): LeverState {
46
+ if (!facts.available.includes(LIANGSHEN_PRESET_ID)) return 'missing'
47
+ if (!facts.blank) return 'locked'
48
+ return facts.agentPreset === LIANGSHEN_PRESET_ID ? 'on' : 'off'
49
+ }
50
+
51
+ /**
52
+ * The preset a push-up restores: the preset the user was on before pulling the
53
+ * lever, else the deployment default. A candidate is skipped when it is the
54
+ * LiangShen preset itself (restoring it would be a no-op) or when the roster
55
+ * no longer supplies it.
56
+ */
57
+ export function restoreTarget(facts: LeverFacts): string | undefined {
58
+ for (const candidate of [facts.previous, facts.fallback]) {
59
+ if (candidate === undefined || candidate === LIANGSHEN_PRESET_ID) continue
60
+ if (facts.available.includes(candidate)) return candidate
61
+ }
62
+ return undefined
63
+ }
64
+
65
+ /** Whether the lever can act at all in its current state. */
66
+ export function isActionable(state: LeverState): boolean {
67
+ return state === 'on' || state === 'off'
68
+ }
package/src/index.ts CHANGED
@@ -9,11 +9,15 @@
9
9
  * surface (plugin config) or the profile patch. No browser half, no routes,
10
10
  * no agent tools — the preset itself provides the tools.
11
11
  *
12
- * The preset is the "anchored-standard" idea shipped as a named mode: the
13
- * first model request sees only the builtin Minimal preset's exact two tools
14
- * (persistent `bash` plus `str_replace_editor`), and after the anchor the
15
- * wire switches to PTC Mode. Derived from
16
- * https://github.com/xiaobright/dsh-anchored-standard (MIT).
12
+ * The preset is the "minimal persona + promoted tool surface" idea shipped as
13
+ * a named mode: the system prompt stays the builtin Minimal preset's exact
14
+ * one-line persona for the whole session, the session's first (anchor) turn
15
+ * runs the builtin Minimal surface exactly — `bash` alone, natively presented —
16
+ * and from the second turn this session presents its tools in PTC mode, so the
17
+ * wire carries the single `run_code` transport while the generated SDK
18
+ * bindings and the collapse rule travel in the tool list injected as a durable
19
+ * message after the user's own message, the way the skill catalog is. The one
20
+ * transition is the deterministic turn boundary.
17
21
  */
18
22
 
19
23
  import { mkdirSync } from 'node:fs'
@@ -56,7 +60,7 @@ const DEFAULT_ANNOUNCE = false
56
60
  const SECTION_ORDER = 150
57
61
 
58
62
  /** Model-facing announcement: plugin presence, principle, and limits. */
59
- export const LIANGSHEN_GUIDANCE = '本机已安装 dsh-liangshen 插件(梁神模式 agent preset):新建会话的预设选择器中可选「梁神模式」。原理:两阶段锚定——首轮模型请求仅暴露官方 Minimal 精确双工具(持久 bash 与 str_replace_editor,文件工具继承宿主沙箱),只保留一行 persona,清空运行时上下文并只放行白名单消息(用户直接消息与 /goal 自动轮次),锚定 Minimal 推理轨迹;晋升受首块锚定门控(首块包含 we 且无 let me,四步兜底),无工具首轮会在响应后自动晋升,晋升后 wire 切换为 PTC Mode(单一 run_code)并在 persona 追加所选工作区路径,workspace 指令与 skill 目录在晋升后再延迟一步注入。preset 文件由插件维护于 ~/.dsh/.agent-presets,升级插件时自动更新;默认预设由用户自行选择。用户提到「梁神模式 / 锚定模式 / anchored standard」时即指本插件,请据此协作。'
63
+ export const LIANGSHEN_GUIDANCE = '本机已安装 dsh-liangshen 插件(梁神模式 agent preset):新建会话的预设选择器中可选「梁神模式」。原理:系统提示词永久保持官方 Minimal 的一行 persona(minimal-prompt 只放行该段与 plan 模式的 plan:policy),persona 内置本模式的工作纪律(思维循环即断、先理解需求与方案再实现、YAGNI/PDCA、代码不加注释),并在组装时追加一行工作区目录 Your working directory is <cwd>.;工具清单(工具名 + 参数签名 + 一行摘要,取自注册表的 PTC 面 ctx.tools.sdkSchemas)由 tool-catalog 从第一条用户消息起以 user 消息注入在用户消息之后,形如 skill catalog,仅当工具集变化或该消息离开可见面(压缩、恢复)时重发;wire 上的 schema 按回合分层:首个回合原生呈现且只保留 bash 一个 schema(官方 Minimal 的锚定面),第二个回合起该会话切换为 PTC 呈现(wire 上只有 run_code,其余工具在程序里以 await tools.<name>({...}) 调用)——因为 minimal-prompt 会连同 tools:sdk 与 tools:ptc-only 段一起裁掉,注入消息是模型了解 SDK、程序契约(一段程序编排多步:独立只读调用用 Promise.all 并发、ToolCallError 处理、输出自己挑选)与「只有 run_code 可直接调用」这条规则的唯一来源;没有输出预算上限。AGENTS.md 类工作区指令($DSH_HOME/AGENTS.md 与项目根到 cwd 的祖先链)在组装时读取并作为 workspace-instructions 段注入系统提示词尾部(instructionSource: system-prompt,65536 字节预算,每次组装重读),宿主的 agent-instructions 全文注入被丢弃。preset 文件由插件维护于 ~/.dsh/.agent-presets,升级插件时自动更新;默认预设由用户自行选择。用户提到「梁神模式 / 锚定模式 / anchored standard」时即指本插件,请据此协作。'
60
64
  // The harness-home resolution (DSH_HOME override with the platform-home
61
65
  // fallback and ~ expansion) lives in the family-shared copy ./dsh-home.ts.
62
66
  // Re-export it so the plugin surface stays stable while the implementation is
@@ -5,7 +5,7 @@ const VALID = [
5
5
  "- id: persona",
6
6
  " name: '@deepseek-ai/dsh-persona'",
7
7
  "- id: bootstrap",
8
- " name: ./tool-bootstrap.mjs",
8
+ " name: ./tool-catalog.mjs",
9
9
  "- id: shell-group",
10
10
  " name: cordis:group",
11
11
  " group: true",
package/src/sync.test.ts CHANGED
@@ -13,7 +13,7 @@ function fixture(): { source: string; target: string; dispose: () => void } {
13
13
  const target = join(base, 'agent-presets')
14
14
  mkdirSync(join(source, 'liangshen'), { recursive: true })
15
15
  writeFileSync(join(source, 'liangshen', 'agent.cordis.yml'), VALID_AGENT_YAML)
16
- writeFileSync(join(source, 'liangshen', 'tool-bootstrap.mjs'), 'export const name = "x"\n')
16
+ writeFileSync(join(source, 'liangshen', 'tool-catalog.mjs'), 'export const name = "x"\n')
17
17
  writeFileSync(join(source, 'liangshen', 'preset.yml'), 'name: 梁神模式\n')
18
18
  return { source, target, dispose: () => rmSync(base, { recursive: true, force: true }) }
19
19
  }
@@ -27,7 +27,7 @@ describe('syncPresetTrees', () => {
27
27
  expect(result.current).toEqual([])
28
28
  expect(result.failed).toEqual([])
29
29
  expect(readFileSync(join(f.target, 'liangshen', 'preset.yml'), 'utf8')).toContain('梁神模式')
30
- expect(readFileSync(join(f.target, 'liangshen', 'tool-bootstrap.mjs'), 'utf8')).toContain('x')
30
+ expect(readFileSync(join(f.target, 'liangshen', 'tool-catalog.mjs'), 'utf8')).toContain('x')
31
31
  } finally { f.dispose() }
32
32
  })
33
33
 
@@ -98,10 +98,10 @@ describe('syncPresetTrees', () => {
98
98
  const f = fixture()
99
99
  try {
100
100
  syncPresetTrees(f.source, f.target)
101
- rmSync(join(f.source, 'liangshen', 'tool-bootstrap.mjs'))
101
+ rmSync(join(f.source, 'liangshen', 'tool-catalog.mjs'))
102
102
  const second = syncPresetTrees(f.source, f.target)
103
103
  expect(second.synced).toEqual(['liangshen'])
104
- expect(existsSync(join(f.target, 'liangshen', 'tool-bootstrap.mjs'))).toBe(false)
104
+ expect(existsSync(join(f.target, 'liangshen', 'tool-catalog.mjs'))).toBe(false)
105
105
  expect(readFileSync(join(f.target, 'liangshen', 'agent.cordis.yml'), 'utf8')).toBe(VALID_AGENT_YAML)
106
106
  } finally { f.dispose() }
107
107
  })
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Analyze one or more DSH session JSONL exports and report the LiangShen
3
- * trajectory markers: first-turn surface, promotion boundary, reasoning-block
4
- * word markers (`we` / `let me` / `let's` / `I`), the first reasoning line,
5
- * and per-step drift points.
3
+ * trajectory markers: first-turn surface, request-header catalog changes,
4
+ * reasoning-block word markers (`we` / `let me` / `let's` / `I`), the first
5
+ * reasoning line, and per-step drift points.
6
6
  *
7
7
  * Usage:
8
8
  * node tools/analyze-session.mjs <session.jsonl> [more.jsonl ...]
@@ -11,8 +11,6 @@
11
11
  import { createReadStream } from 'node:fs'
12
12
  import readline from 'node:readline'
13
13
 
14
- import { classifyReasoning, countWord } from '../presets/liangshen/tool-bootstrap.mjs'
15
-
16
14
  const WORD = {
17
15
  we: /\bwe\b/gi,
18
16
  letMe: /\blet me\b/gi,
@@ -20,6 +18,28 @@ const WORD = {
20
18
  i: /\bi\b/gi,
21
19
  }
22
20
 
21
+ /** Count non-overlapping matches of one marker regex. */
22
+ export function countWord(text, regex) {
23
+ return [...String(text ?? '').matchAll(regex)].length
24
+ }
25
+
26
+ /**
27
+ * Anchor classifier for trajectory reporting. A reasoning block counts as
28
+ * minimal-like when it contains `we` and no `let me`; a block with any
29
+ * `let me` is standard-like; everything else is ambiguous. The preset no
30
+ * longer gates anything on this label — it is the measurement this analyzer
31
+ * reports, so the anchored surface can be compared across runs.
32
+ */
33
+ export function classifyReasoning(text) {
34
+ const trimmed = String(text ?? '').trim()
35
+ const we = countWord(trimmed, WORD.we)
36
+ const letMe = countWord(trimmed, WORD.letMe)
37
+ const metrics = { we, letMe }
38
+ if (we > 0 && letMe === 0) return { label: 'minimal-like', score: 4, metrics }
39
+ if (letMe > 0) return { label: 'standard-like', score: -4, metrics }
40
+ return { label: 'ambiguous', score: 0, metrics }
41
+ }
42
+
23
43
  export function countMarkers(text) {
24
44
  return {
25
45
  we: countWord(text, WORD.we),