@linxin666/dsh-liangshen 0.3.22 → 0.3.24

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.
Files changed (37) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +45 -38
  3. package/README.zh.md +44 -37
  4. package/lib/client.js +1058 -11
  5. package/lib/client.js.map +1 -1
  6. package/lib/index.js +105 -22
  7. package/lib/types/client/LiangShenSettingsCard.d.ts +61 -0
  8. package/lib/types/client/PluginSettingsCard.d.ts +133 -0
  9. package/lib/types/client/index.d.ts +34 -0
  10. package/lib/types/client/locales.d.ts +27 -1
  11. package/lib/types/client/plugin-card-seat.d.ts +96 -0
  12. package/lib/types/client/settings-form.d.ts +197 -0
  13. package/lib/types/core/lever.d.ts +6 -3
  14. package/lib/types/index.d.ts +23 -11
  15. package/lib/types/sync.d.ts +29 -2
  16. package/package.json +6 -2
  17. package/presets/liangshen/NOTICE +4 -4
  18. package/presets/liangshen/agent.cordis.yml +130 -119
  19. package/presets/liangshen/minimal-prompt.mjs +71 -36
  20. package/presets/liangshen/paging.mjs +232 -0
  21. package/presets/liangshen/tool-activate.mjs +176 -0
  22. package/presets/liangshen/tool-catalog.mjs +610 -218
  23. package/presets/liangshen/working-context.mjs +214 -0
  24. package/src/client/LiangShenLever.tsx +4 -1
  25. package/src/client/LiangShenSettingsCard.tsx +149 -0
  26. package/src/client/PluginSettingsCard.tsx +550 -0
  27. package/src/client/index.ts +60 -1
  28. package/src/client/locales.ts +53 -1
  29. package/src/client/plugin-card-seat.ts +185 -0
  30. package/src/client/settings-card.module.css +418 -0
  31. package/src/client/settings-form.ts +439 -0
  32. package/src/core/lever.ts +7 -4
  33. package/src/index.ts +35 -14
  34. package/src/sync.test.ts +86 -7
  35. package/src/sync.ts +108 -6
  36. package/tools/benchmark-live-run.mjs +24 -33
  37. package/presets/liangshen/custom-bash.mjs +0 -213
@@ -0,0 +1,439 @@
1
+ // Generated by scripts/sync-shared.mjs from shared/client/settings/settings-form.ts. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
2
+ /**
3
+ * Staged form model behind the plugin settings card. A card stages what the
4
+ * user types and writes it only when they save — the settings write is a
5
+ * durable, revision-fenced document mutation, so staging keeps what is on
6
+ * screen exactly what a save would store. Family-shared slice inlined into
7
+ * each plugin's client bundle; mirrors the official ui-plugin-config
8
+ * card-store pattern.
9
+ */
10
+
11
+ import type { SettingsScope, SettingsScopeSnapshot } from '@deepseek-ai/dsh-client-ui-settings/client'
12
+ import type { SnapshotStore } from '@deepseek-ai/dsh-client-store'
13
+ import { createSnapshotStore } from '@deepseek-ai/dsh-client-store'
14
+
15
+ /** The write one field's staged text performs when the card is saved. */
16
+ export type FieldWrite =
17
+ | { kind: 'set'; value: unknown }
18
+ | { kind: 'clear' }
19
+
20
+ /** How one field converts between its stored value and its draft text. */
21
+ export interface FieldSpec {
22
+ /** Field name inside the namespace section. */
23
+ field: string
24
+ /**
25
+ * Whether the Host treats this field as a secret and redacts its value from
26
+ * the read-back (role('secret') in the section schema). Redacted secrets are
27
+ * never compared against the draft on save: the Host strips them from every
28
+ * wire view layer, so the settled snapshot carries nothing to read back. A
29
+ * staged secret set is judged by the mutation settling; the rest of its
30
+ * batch, when one exists, is still judged by read-back, and the atomic
31
+ * mutation lands every write or none.
32
+ */
33
+ secret?: boolean
34
+ /** Render a stored value as draft text; the empty string when the section carries none. */
35
+ format: (value: unknown) => string
36
+ /**
37
+ * The write this draft text stages, or undefined when the text is not a
38
+ * value this field accepts — which blocks the save rather than discarding it.
39
+ */
40
+ parse: (text: string) => FieldWrite | undefined
41
+ }
42
+
43
+ /** One field as the card renders it. */
44
+ export interface FieldState {
45
+ /** Draft text the control renders. */
46
+ text: string
47
+ /** Whether saving would leave a user-layer entry for this field. */
48
+ overridden: boolean
49
+ /** Whether the draft is not a value this field accepts, which blocks saving. */
50
+ invalid: boolean
51
+ }
52
+
53
+ /** Form state every plugin settings card shares. */
54
+ export interface CardShell {
55
+ /** False while the namespace is still loading; the card renders nothing. */
56
+ available: boolean
57
+ /**
58
+ * Whether the namespace is actually served to this client. False when the
59
+ * Host deployment does not expose it (e.g. the owning plugin's settings
60
+ * domain is not mounted): the card renders an explanation
61
+ * instead of its form, so a missing namespace never looks like a missing
62
+ * plugin.
63
+ */
64
+ exposed: boolean
65
+ /** Whether the Host document accepts writes. */
66
+ writable: boolean
67
+ /** Whether the form holds edits that a save would write. */
68
+ dirty: boolean
69
+ /** Whether any staged draft is invalid, which blocks the save. */
70
+ invalid: boolean
71
+ /** Whether a save is crossing the wire. */
72
+ saving: boolean
73
+ /** Whether the last save did not land as staged; cleared by the next edit or save. */
74
+ failed: boolean
75
+ /**
76
+ * The rejection code/message the Host returned for the last failed save,
77
+ * surfaced next to the generic failure text. Undefined while no save has
78
+ * failed (or the failure carried no server reason).
79
+ */
80
+ failedReason?: string
81
+ }
82
+
83
+ /** The write actions the card's slot entry injects. */
84
+ export interface CardActions {
85
+ /** Stage draft text for one field. */
86
+ edit: (field: string, text: string) => void
87
+ /** Stage a clear, so saving lets the field re-inherit the composition layer. */
88
+ resetField: (field: string) => void
89
+ /** Write every staged edit, then re-seed from what the Host accepted. */
90
+ save: () => void
91
+ /** Drop every staged edit. */
92
+ discard: () => void
93
+ }
94
+
95
+ /** One field's staged edit. */
96
+ interface StagedEdit {
97
+ /** Draft text the control renders. */
98
+ text: string
99
+ /** True when this edit clears the field whatever text it shows. */
100
+ clear: boolean
101
+ }
102
+
103
+ /** One staged edit resolved into the write a save performs. */
104
+ interface PlannedWrite {
105
+ /** Field this entry writes. */
106
+ field: string
107
+ /** The durable write this entry performs, inside the save's one atomic mutation. */
108
+ op: BatchedWrite
109
+ /**
110
+ * Read the settled snapshot back and report whether the Host holds this
111
+ * write's effect. Undefined when the draft is not a value the field
112
+ * accepts: there is nothing to write, and the entry blocks the save.
113
+ */
114
+ judge: (() => boolean) | undefined
115
+ }
116
+
117
+ /** One durable write inside the save's atomic scope mutation. */
118
+ export interface BatchedWrite {
119
+ /** Field this entry writes. */
120
+ field: string
121
+ /** set stores a value; unset drops the leaf. */
122
+ op: 'set' | 'unset'
123
+ /** Value for op set (absent for unset). */
124
+ value?: unknown
125
+ }
126
+
127
+ /** Constraints a numeric field's accepted drafts must satisfy, mirroring the host schema. */
128
+ export interface NumberConstraints {
129
+ /** The accepted value must be a whole number. */
130
+ integer?: boolean
131
+ /** The accepted value must be at least this. */
132
+ min?: number
133
+ }
134
+
135
+ /** A whole- or decimal-number field. An empty draft clears the field; any other draft that is not a finite number within the constraints blocks the save. */
136
+ export function numberField(field: string, constraints: NumberConstraints = {}): FieldSpec {
137
+ const { integer = false, min } = constraints
138
+ return {
139
+ field,
140
+ format: value => typeof value === 'number' ? String(value) : '',
141
+ parse: (text) => {
142
+ const trimmed = text.trim()
143
+ if (trimmed === '') return { kind: 'clear' }
144
+ const parsed = Number(trimmed)
145
+ if (!Number.isFinite(parsed)) return undefined
146
+ if (integer && !Number.isInteger(parsed)) return undefined
147
+ if (min !== undefined && parsed < min) return undefined
148
+ return { kind: 'set', value: parsed }
149
+ },
150
+ }
151
+ }
152
+
153
+ /** A free-text field. An empty draft clears the field. */
154
+ export function textField(field: string): FieldSpec {
155
+ return {
156
+ field,
157
+ format: value => typeof value === 'string' ? value : '',
158
+ parse: (text) => {
159
+ const trimmed = text.trim()
160
+ return trimmed === '' ? { kind: 'clear' } : { kind: 'set', value: trimmed }
161
+ },
162
+ }
163
+ }
164
+
165
+ /**
166
+ * A free-text field the Host treats as a secret and redacts from the read-back
167
+ * (role('secret') in the section schema). The card still edits it like text,
168
+ * but a save never compares the redacted value back: the staged set is judged
169
+ * by the mutation settling (see {@link FieldSpec.secret}).
170
+ */
171
+ export function secretField(field: string): FieldSpec {
172
+ return { ...textField(field), secret: true }
173
+ }
174
+
175
+ /** A boolean field, edited through true/false draft text. */
176
+ export function booleanField(field: string): FieldSpec {
177
+ return {
178
+ field,
179
+ format: value => typeof value === 'boolean' ? String(value) : '',
180
+ parse: (text) => {
181
+ const trimmed = text.trim()
182
+ if (trimmed === '') return { kind: 'clear' }
183
+ if (trimmed === 'true') return { kind: 'set', value: true }
184
+ if (trimmed === 'false') return { kind: 'set', value: false }
185
+ return undefined
186
+ },
187
+ }
188
+ }
189
+
190
+ /** An enumerated string field; only the listed choices are accepted. An empty draft clears the field. */
191
+ export function choiceField(field: string, choices: readonly string[]): FieldSpec {
192
+ return {
193
+ field,
194
+ format: value => typeof value === 'string' && choices.includes(value) ? value : '',
195
+ parse: (text) => {
196
+ if (text === '') return { kind: 'clear' }
197
+ return choices.includes(text) ? { kind: 'set', value: text } : undefined
198
+ },
199
+ }
200
+ }
201
+
202
+ /**
203
+ * Stages one card's edits over one settings namespace and writes them on save.
204
+ *
205
+ * The Host is the only authority on whether a value was accepted — its
206
+ * validators own the constraints no schema can express — so the outcome is
207
+ * read back from the section rather than predicted here. A save that did not
208
+ * land keeps its drafts, so the user can correct them instead of retyping.
209
+ */
210
+ export class CardForm<T> {
211
+ private readonly specs: Map<string, FieldSpec>
212
+ private readonly staged = new Map<string, StagedEdit>()
213
+ private readonly listeners = new Set<() => void>()
214
+ /** The scope subscription installed in the constructor; released by dispose(). */
215
+ private readonly disposeScope: () => void
216
+ private disposed = false
217
+ private saving = false
218
+ private failed = false
219
+ private failedReason: string | undefined
220
+
221
+ /** @param scope - the bound settings scope for this card's namespace. */
222
+ constructor(
223
+ private readonly scope: SettingsScope<T>,
224
+ specs: FieldSpec[],
225
+ ) {
226
+ this.specs = new Map(specs.map(spec => [spec.field, spec]))
227
+ this.disposeScope = scope.subscribe(() => { this.publish() })
228
+ }
229
+
230
+ /**
231
+ * Release the scope subscription and every bound store listener. The card
232
+ * must call this on teardown; later calls are no-ops.
233
+ */
234
+ dispose(): void {
235
+ if (this.disposed) return
236
+ this.disposed = true
237
+ this.disposeScope()
238
+ this.listeners.clear()
239
+ }
240
+
241
+ /** Publish a projection of this form, rebuilt whenever the scope or a draft changes. */
242
+ bind<S>(project: () => S): SnapshotStore<S> {
243
+ const store = createSnapshotStore(project())
244
+ this.listeners.add(() => { store.set(project()) })
245
+ return store
246
+ }
247
+
248
+ /** Read the card-level state: what the Host serves, and what a save would do. */
249
+ shell(): CardShell {
250
+ const snapshot = this.scope.getSnapshot()
251
+ const plan = this.plan()
252
+ return {
253
+ available: snapshot.status !== 'loading',
254
+ exposed: snapshot.status === 'ready',
255
+ writable: snapshot.writable,
256
+ dirty: plan.length > 0,
257
+ invalid: plan.some(item => item.judge === undefined),
258
+ saving: this.saving,
259
+ failed: this.failed,
260
+ ...this.failedReason === undefined ? {} : { failedReason: this.failedReason },
261
+ }
262
+ }
263
+
264
+ /** Read one field's state from the effective section and its staged draft. */
265
+ field(field: string): FieldState {
266
+ const spec = this.specOf(field)
267
+ const staged = this.staged.get(field)
268
+ if (staged === undefined) {
269
+ return { text: spec.format(this.sectionValue(field)), overridden: this.stored(field), invalid: false }
270
+ }
271
+ const write = staged.clear ? { kind: 'clear' as const } : spec.parse(staged.text)
272
+ return {
273
+ text: staged.text,
274
+ overridden: write?.kind === 'set',
275
+ invalid: write === undefined,
276
+ }
277
+ }
278
+
279
+ /** The actions the card's slot registration injects. */
280
+ actions(): CardActions {
281
+ return {
282
+ edit: (field, text) => { this.stage(field, { text, clear: false }) },
283
+ resetField: (field) => {
284
+ this.stage(field, { text: this.specOf(field).format(this.baseValue(field)), clear: true })
285
+ },
286
+ save: () => { void this.save() },
287
+ discard: () => {
288
+ if (this.staged.size === 0 && !this.failed) return
289
+ this.staged.clear()
290
+ this.failed = false
291
+ this.failedReason = undefined
292
+ this.publish()
293
+ },
294
+ }
295
+ }
296
+
297
+ /**
298
+ * Write every staged edit in one atomic scope mutation, then re-seed from
299
+ * what the Host accepted.
300
+ *
301
+ * The whole batch rides one mutate, so cross-field validate hooks
302
+ * (baseURL+model) judge it as a unit: the Host either applies every write
303
+ * or refuses the batch. The 0.1.2 scope contract never rejects a refused
304
+ * mutation — the scope recovers with a fresh Host view and resolves — so
305
+ * resolution alone proves nothing: the outcome is judged by reading the
306
+ * settled snapshot back, one planned write at a time, and one missed write
307
+ * fails the whole save. A scope that still rejects on refusal (the dsh-web
308
+ * bridge scope) reports through the same failure path with its rejection
309
+ * message. A save that did not land keeps its drafts, so the user can
310
+ * correct them instead of retyping.
311
+ * @returns settlement after the mutation and the read-back.
312
+ */
313
+ async save(): Promise<void> {
314
+ const plan = this.plan()
315
+ const valid = plan.filter((item): item is PlannedWrite & { judge: () => boolean } => item.judge !== undefined)
316
+ if (plan.length === 0 || this.saving || valid.length !== plan.length) return
317
+ // Snapshot the staged entries this save writes, so an edit staged while it
318
+ // is in flight (which replaces the same key) survives: only delete the key
319
+ // when the entry is still the one this save started from.
320
+ const pending = new Map<string, StagedEdit | undefined>()
321
+ for (const item of plan) pending.set(item.field, this.staged.get(item.field))
322
+ this.saving = true
323
+ this.failed = false
324
+ this.failedReason = undefined
325
+ this.publish()
326
+ // One atomic namespace mutation: the 0.1.2 scope contract takes ordered
327
+ // path operations, so the whole staged batch is validated, persisted, and
328
+ // recovered together — either every write lands or none does.
329
+ const ops: Array<{ op: 'set'; path: string[]; value: string | number | boolean } | { op: 'unset'; path: string[] }> = valid.map(item => item.op.op === 'set'
330
+ ? { op: 'set', path: [item.field], value: (item.op as { value: string | number | boolean }).value }
331
+ : { op: 'unset', path: [item.field] })
332
+ let failedReason: string | undefined
333
+ try {
334
+ await this.scope.mutate(ops)
335
+ } catch (error) {
336
+ failedReason = error instanceof Error ? error.message : String(error)
337
+ }
338
+ // The 0.1.2 scope resolves even a refused mutation (it recovers with a
339
+ // fresh view instead of throwing), so resolution alone proves nothing:
340
+ // judge every planned write against the settled snapshot. The mutation is
341
+ // atomic, so one missed write fails the whole save and keeps the drafts.
342
+ const landed = failedReason === undefined && valid.every(item => item.judge())
343
+ for (const [field, before] of pending) {
344
+ if (landed && this.staged.get(field) === before) this.staged.delete(field)
345
+ }
346
+ this.saving = false
347
+ this.failed = !landed
348
+ // A read-back failure carries no server reason: the card surfaces its
349
+ // generic failure copy; a rejecting scope (the bridge) adds its message.
350
+ this.failedReason = failedReason
351
+ this.publish()
352
+ }
353
+
354
+ /**
355
+ * Every staged edit a save would write. An entry whose draft is not a value
356
+ * its field accepts carries no write: the form is still dirty, and the save
357
+ * refuses rather than dropping the edit. A staged edit that matches the
358
+ * effective section is not a write at all.
359
+ * @returns the planned writes, in the order the fields were staged.
360
+ */
361
+ private plan(): PlannedWrite[] {
362
+ const plan: PlannedWrite[] = []
363
+ for (const [field, staged] of this.staged) {
364
+ const spec = this.specOf(field)
365
+ if (staged.clear) {
366
+ if (this.stored(field)) plan.push({ field, op: { field, op: 'unset' }, judge: () => this.landedUnset(field) })
367
+ continue
368
+ }
369
+ if (staged.text === spec.format(this.sectionValue(field))) continue
370
+ const write = spec.parse(staged.text)
371
+ if (write === undefined) plan.push({ field, op: { field, op: 'unset' }, judge: undefined })
372
+ else if (write.kind === 'clear') plan.push({ field, op: { field, op: 'unset' }, judge: () => this.landedUnset(field) })
373
+ else plan.push({ field, op: { field, op: 'set', value: write.value }, judge: () => this.landedSet(field, write.value) })
374
+ }
375
+ return plan
376
+ }
377
+
378
+ /**
379
+ * Read-back judgment for a planned set: the user layer must hold the
380
+ * intended value once the mutation has settled.
381
+ */
382
+ private landedSet(field: string, value: unknown): boolean {
383
+ // A redacted secret never appears in any wire view layer: the Host strips
384
+ // role('secret') fields and reports them through a sidecar the scope
385
+ // snapshot does not expose, so there is nothing to compare the draft
386
+ // against. Settling is the only signal the form has; the rest of the
387
+ // batch, when one exists, still carries the atomic verdict by read-back.
388
+ if (this.specOf(field).secret) return true
389
+ return this.userLayer()?.[field] === value
390
+ }
391
+
392
+ /**
393
+ * Read-back judgment for a planned unset: the field must be gone from the
394
+ * user layer once the mutation has settled.
395
+ */
396
+ private landedUnset(field: string): boolean {
397
+ return !this.stored(field)
398
+ }
399
+
400
+ private stage(field: string, edit: StagedEdit): void {
401
+ this.staged.set(field, edit)
402
+ this.failed = false
403
+ this.failedReason = undefined
404
+ this.publish()
405
+ }
406
+
407
+ private specOf(field: string): FieldSpec {
408
+ const spec = this.specs.get(field)
409
+ // Every call site names a field this card declared; a missing one is a
410
+ // wiring mistake that must not degrade into a silently inert control.
411
+ if (spec === undefined) throw new Error(`settings card has no field ${field}`)
412
+ return spec
413
+ }
414
+
415
+ private snapshotOf(): SettingsScopeSnapshot<T> {
416
+ return this.scope.getSnapshot()
417
+ }
418
+
419
+ private sectionValue(field: string): unknown {
420
+ return (this.snapshotOf().value as Record<string, unknown> | undefined)?.[field]
421
+ }
422
+
423
+ private baseValue(field: string): unknown {
424
+ return (this.snapshotOf().base as Record<string, unknown> | undefined)?.[field]
425
+ }
426
+
427
+ private userLayer(): Record<string, unknown> | undefined {
428
+ return this.snapshotOf().user as Record<string, unknown> | undefined
429
+ }
430
+
431
+ private stored(field: string): boolean {
432
+ const user = this.userLayer()
433
+ return user !== undefined && Object.hasOwn(user, field)
434
+ }
435
+
436
+ private publish(): void {
437
+ for (const listener of this.listeners) listener()
438
+ }
439
+ }
package/src/core/lever.ts CHANGED
@@ -50,16 +50,19 @@ export function leverState(facts: LeverFacts): LeverState {
50
50
 
51
51
  /**
52
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.
53
+ * lever, else the deployment default, else the first usable roster row that is
54
+ * not the LiangShen preset. A candidate is skipped when it is the LiangShen
55
+ * preset itself (restoring it would be a no-op) or when the roster no longer
56
+ * supplies it. That last resort is what keeps the push direction alive when the
57
+ * deployment default IS LiangShen mode: `fallback` is skipped then, and after a
58
+ * reload `previous` is gone, so without it the gesture would have no target.
56
59
  */
57
60
  export function restoreTarget(facts: LeverFacts): string | undefined {
58
61
  for (const candidate of [facts.previous, facts.fallback]) {
59
62
  if (candidate === undefined || candidate === LIANGSHEN_PRESET_ID) continue
60
63
  if (facts.available.includes(candidate)) return candidate
61
64
  }
62
- return undefined
65
+ return facts.available.find(candidate => candidate !== LIANGSHEN_PRESET_ID)
63
66
  }
64
67
 
65
68
  /** Whether the lever can act at all in its current state. */
package/src/index.ts CHANGED
@@ -9,16 +9,20 @@
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 combines a minimal persona with a staged, promoted tool surface:
13
- * the system prompt keeps a minimal persona with standing working discipline
14
- * and workspace instructions, the session's entire first user turn runs a native
15
- * foundational tool surface ([bash, str_replace_editor, exit_plan_mode, skill],
16
- * with bash-only preserved as a configuration experiment), and from the second
17
- * turn this session presents its tools in PTC mode upon successful activation,
18
- * so the wire carries the single `run_code` transport while the generated SDK
19
- * bindings and collapse rule travel in the tool list injected as a durable
20
- * message after the user's message, preserving full input and output key
21
- * parameter semantics.
12
+ * The preset combines a minimal persona with a lifetime-declared tool
13
+ * presentation: the system prompt keeps a minimal persona with standing
14
+ * working discipline and workspace instructions, and the wire runs the SDK's
15
+ * 'ptc' presentation by default — the wire collapses to the `run_code`
16
+ * transport and every other tool is reached through the generated SDK,
17
+ * declared once per session instead of staged across a turn boundary
18
+ * ('native' and 'both' are one-line opt-outs). High-fan-out tool families
19
+ * (default `mcp__*`) stay paged out of the executed surface through the
20
+ * host's scoped tool restriction until the preset's own `tool_activate` tool
21
+ * loads their namespace (LRU cap three), with the activation state replayed
22
+ * from the durable session event stream. The tool catalog — listing exactly
23
+ * the tools the request carries plus the paged-out namespace summaries — and a
24
+ * one-line working-context projection travel as durable user messages,
25
+ * republished only on change.
22
26
  */
23
27
 
24
28
  import { mkdirSync } from 'node:fs'
@@ -41,27 +45,38 @@ export const LIANGSHEN_SETTINGS_NAMESPACE = 'dsh-liangshen' as SettingsNamespace
41
45
  /** Prompt assembly must exist before the announcement section can register. */
42
46
  export const inject = ['systemPrompt']
43
47
 
48
+ /** The wire presentations the preset's tool catalog accepts. */
49
+ export const PRESENTATION_OPTIONS = ['ptc', 'native', 'both'] as const
50
+
44
51
  /** Plugin config, validated by the same-named schemastery schema. */
45
52
  export interface Config {
46
53
  /** Master switch: when false, neither sync nor announcement runs. */
47
54
  enabled?: boolean
48
55
  /** When true, a system-prompt section announces the plugin (default false — keep prompts clean unless the user opts in). */
49
56
  announceToAgent?: boolean
57
+ /**
58
+ * Wire presentation written into the synced preset's tool-catalog row.
59
+ * `ptc` (default) collapses the wire to the `run_code` transport; `native`
60
+ * keeps the assembled roster; `both` keeps the roster and the transport.
61
+ */
62
+ presentation?: (typeof PRESENTATION_OPTIONS)[number]
50
63
  }
51
64
 
52
65
  export const Config: z<Config> = z.object({
53
66
  enabled: z.boolean().default(true),
54
67
  announceToAgent: z.boolean().default(false),
68
+ presentation: z.union([...PRESENTATION_OPTIONS]).default('ptc'),
55
69
  })
56
70
 
57
- /** Schema default, re-read for hand-built test contexts. */
71
+ /** Schema defaults, re-read for hand-built test contexts. */
58
72
  const DEFAULT_ANNOUNCE = false
73
+ const DEFAULT_PRESENTATION = 'ptc'
59
74
 
60
75
  /** Order of the announcement section within the tool-guidance band. */
61
76
  const SECTION_ORDER = 150
62
77
 
63
78
  /** Model-facing announcement: plugin presence, principle, and limits. */
64
- export const LIANGSHEN_GUIDANCE = '本机已安装 dsh-liangshen 插件(梁神模式 agent preset):新建会话的预设选择器中可选「梁神模式」。原理:系统提示词保持极简 persona(minimal-prompt 放行该段与 plan 模式的 plan:policy),persona 内置本模式工作纪律(思维循环即断、先理解需求与方案再实现验证、YAGNI/PDCA、代码不加冗余注释),并在组装时追加工作区目录 Your working directory is <cwd>. 与 AGENTS.md 工作区指令(workspace-instructions 段,65536 字节预算,每次组装重读);工具清单由 tool-catalog 从第一条用户消息起以 user 消息注入在用户消息之后,形如 skill catalog,仅当工具集变化或该消息离开可见面(压缩、恢复)时重发;wire 上的 schema 按回合分层:首轮整个 user turn 原生呈现基础锚定工具集(默认 [bash, str_replace_editor, exit_plan_mode, skill],且保留 bash-only 配置实验),第二个回合起在 PTC 成功激活后切换为 PTC 呈现(wire 上只有 run_code,其余工具在程序里以 await tools.<name>({...}) 调用,保留完整输入输出关键参数语义而非 200 字唯一契约;缺失 code runtime 时优雅回退至原生呈现);注入消息承载 SDK 绑定、程序契约(一段程序编排多步:独立只读调用用 Promise.all 并发、ToolCallError 处理、输出自选)与「激活后只有 run_code 可直接调用」的规则。工作区子目录动态指令支持注册文件工具含 str_replace_editor 及 PTC 内子调用触达的目录(不解析任意 bash/program 代码)。文件操作受宿主沙箱约束,Windows 下 bash 为 Git Bash 子进程且状态不跨调用保留。真实推理探针通过不等于模式集成通过,更不等于统计效果提升。preset 文件由插件维护于 ~/.dsh/.agent-presets,升级插件时自动更新;默认预设由用户自行选择。用户提到「梁神模式 / 锚定模式 / anchored standard」时即指本插件,请据此协作。'
79
+ export const LIANGSHEN_GUIDANCE = '本机已安装 dsh-liangshen 插件(梁神模式 agent preset):新建会话的预设选择器中可选「梁神模式」。原理:系统提示词保持极简 persona(minimal-prompt 放行该段与 plan 模式的 plan:policy),persona 内置本模式工作纪律(反思熔断——同一假设推演不超过两轮、缺事实立即闭合思考并调用原生检测工具;行动导向——思考只决定下一步具体操作、不在思考中预演代码实现;并发探索——多处独立检查或搜索在单轮内并发发射多个工具调用;YAGNI/PDCA——单步验证单一假设、不写冗余注释),并在组装时追加工作区目录行 Your working directory is <cwd>.。AGENTS.md 工作区指令默认交还宿主自身的 agent-instructions 行,以 user 角色注入,本插件不追加任何系统提示词段、也不改动 pre-step 的消息批次;可选 instructionSource: system-prompt 才由本插件在组装时读取 AGENTS.md 链并追加 workspace-instructions 段(65536 字节预算,每次组装重读)。wire 呈现由 tool-catalog 按会话一次声明,取值 \'ptc\'(默认:wire 收拢为唯一的 run_code,其余工具经生成的 SDK 触达)、\'native\'(组装出的原生清单)或 \'both\'(两者同驻),并可在插件设置界面切换(同步 preset 时写入 tool-catalog 行);未挂载 code runtime 时不做声明,会话运行原生工具面。温和工具分页:匹配 pagedToolPatterns(默认 mcp__*)的工具在激活前被作用域级工具限制移出可见面(既不在 wire,也不在生成的 SDK 声明中),目录消息列出常驻工具签名与未激活命名空间摘要,调用 tool_activate({ namespace }) 按需激活(LRU 上限 3 个活跃命名空间,驱逐最久未用);激活状态从持久会话事件流重建,resume/压缩后自然恢复。working-context 插件在 pre-step 注入单行 [Working Context: ...] 就近状态投射(plan 模式、活跃命名空间、进行中 todo 标题,全部从事件流折叠,读不到则省略,全部为空则不注入)。历史工具结果修剪为 4096 字符阈值(head 1500 / tail 500)。文件操作受宿主沙箱约束;shell 在每个平台都挂上游标准 Stdio 栈(POSIX 为 bash,Windows 为 pwsh),带简短描述标题卡片与确定性退出码。真实推理探针通过不等于模式集成通过,更不等于统计效果提升。preset 文件由插件维护于 ~/.dsh/.agent-presets,升级插件时自动更新;默认预设由用户自行选择。用户提到「梁神模式 / 锚定模式 / anchored standard」时即指本插件,请据此协作。'
65
80
  // The harness-home resolution (DSH_HOME override with the platform-home
66
81
  // fallback and ~ expansion) lives in the family-shared copy ./dsh-home.ts.
67
82
  // Re-export it so the plugin surface stays stable while the implementation is
@@ -92,13 +107,19 @@ function applyImpl(ctx: Context, config?: Config): void {
92
107
  const resolve = (): Config => ({
93
108
  announceToAgent: current().announceToAgent ?? DEFAULT_ANNOUNCE,
94
109
  enabled: current().enabled ?? true,
110
+ presentation: current().presentation ?? DEFAULT_PRESENTATION,
95
111
  })
96
112
 
97
113
  const sync = (): void => {
98
114
  const targetRoot = join(dshHome(), '.agent-presets')
99
115
  try {
100
116
  mkdirSync(targetRoot, { recursive: true })
101
- const result = syncPresetTrees(bundledPresetsRoot(), targetRoot, ['liangshen-exact'])
117
+ const settings = resolve()
118
+ // The settings surface edits this plugin's namespace, while the values that
119
+ // shape a session live in the preset's rows; the sync is where the two meet.
120
+ const result = syncPresetTrees(bundledPresetsRoot(), targetRoot, ['liangshen-exact'], {
121
+ presentation: settings.presentation,
122
+ })
102
123
  for (const { id, error } of result.failed) {
103
124
  ctx.logger?.warn?.(`dsh-liangshen: preset ${id} sync failed: ${error}`)
104
125
  }
@@ -154,4 +175,4 @@ function applyImpl(ctx: Context, config?: Config): void {
154
175
 
155
176
  refresh()
156
177
  ctx.effect(() => () => { disposeSection?.(); disposeSection = undefined }, 'dsh-liangshen: announcement')
157
- }
178
+ }