@linxin666/dsh-liangshen 0.3.6 → 0.3.10

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
@@ -1,207 +1,9 @@
1
1
  import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, utimesSync } from "node:fs";
2
2
  import { basename, dirname, isAbsolute, join, relative } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
- import { Service } from "@deepseek-ai/cordis";
5
4
  import z from "schemastery";
6
5
  import { homedir } from "node:os";
7
6
  import { isAbsolute as isAbsolute$1, join as join$1 } from "node:path/posix";
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
9
- /**
10
- * Structural secret redaction for settings values. `role('secret')` fields are
11
- * removed from a value before it crosses a wire boundary; a sidecar records
12
- * each schema-declared secret position and whether it currently holds a value,
13
- * so a configuration surface can render a write-only input without ever
14
- * receiving the secret itself.
15
- * @module @deepseek-ai/dsh-settings/redact
16
- */
17
- /** Whether a value is a plain data object the walker may recurse into. */
18
- function isRecord(value) {
19
- return typeof value === "object" && value !== null && !Array.isArray(value);
20
- }
21
- function walk(node, value, path, secrets) {
22
- if (node === void 0) return value;
23
- if (node.meta?.role === "secret") {
24
- secrets.push({
25
- path,
26
- set: value !== void 0
27
- });
28
- return;
29
- }
30
- switch (node.type) {
31
- case "object": {
32
- const properties = node.dict ?? {};
33
- const source = isRecord(value) ? value : void 0;
34
- const rebuilt = {};
35
- if (source !== void 0) for (const [key, entry] of Object.entries(source)) {
36
- if (key in properties) continue;
37
- rebuilt[key] = entry;
38
- }
39
- for (const [key, child] of Object.entries(properties)) {
40
- const stripped = walk(child, source?.[key], [...path, key], secrets);
41
- if (stripped !== void 0) rebuilt[key] = stripped;
42
- }
43
- return source === void 0 && Object.keys(rebuilt).length === 0 ? value : rebuilt;
44
- }
45
- case "dict": {
46
- if (!isRecord(value)) return value;
47
- const rebuilt = {};
48
- for (const [key, entry] of Object.entries(value)) {
49
- const stripped = walk(node.inner, entry, [...path, key], secrets);
50
- if (stripped !== void 0) rebuilt[key] = stripped;
51
- }
52
- return rebuilt;
53
- }
54
- case "array":
55
- if (!Array.isArray(value)) return value;
56
- return value.map((entry, index) => walk(node.inner, entry, [...path, String(index)], secrets));
57
- default: return value;
58
- }
59
- }
60
- /**
61
- * Service Definition for the user-settings capability seam (`ctx.settings`). Providers store one raw document of
62
- * per-namespace sections; plugins register a namespace schema and read the
63
- * resolved value, which layers schema defaults, the registrant's composition
64
- * `base`, and the user document section, in that order.
65
- * @module @deepseek-ai/dsh-settings
66
- */
67
- const NAMESPACE_PATTERN = /^[a-z][a-z0-9-]*$/;
68
- /**
69
- * Brand a raw string as a {@link SettingsNamespace}.
70
- * @param value - candidate namespace; lowercase kebab-case, as in plugin short names.
71
- * @returns the branded namespace.
72
- */
73
- function settingsNamespace(value) {
74
- if (!NAMESPACE_PATTERN.test(value)) throw new TypeError(`settings namespace "${value}" must match ${String(NAMESPACE_PATTERN)}`);
75
- return value;
76
- }
77
- /**
78
- * Deep equality over JSON-compatible data (objects, arrays, primitives) — the
79
- * Service Definition's single change-detection predicate, exported so the invariant
80
- * companion checks exactly the implementation's relation.
81
- * @param a - one JSON-compatible value.
82
- * @param b - the other JSON-compatible value.
83
- * @returns whether the two values are structurally equal.
84
- */
85
- function deepEqualJson(a, b) {
86
- if (a === b) return true;
87
- if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
88
- if (Array.isArray(a) || Array.isArray(b)) {
89
- if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;
90
- return a.every((entry, index) => deepEqualJson(entry, b[index]));
91
- }
92
- const left = a;
93
- const right = b;
94
- const keys = Object.keys(left);
95
- if (keys.length !== Object.keys(right).length) return false;
96
- return keys.every((key) => key in right && deepEqualJson(left[key], right[key]));
97
- }
98
- /** Whether a value is a plain data object (not an array, null, or class instance). */
99
- function isPlainObject(value) {
100
- if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
101
- const proto = Object.getPrototypeOf(value);
102
- return proto === Object.prototype || proto === null;
103
- }
104
- /** Apply one path op to a detached section, returning the next section. */
105
- function applyPathOp(section, op) {
106
- const [head, ...rest] = op.path;
107
- if (head === void 0) {
108
- if (op.op === "unset") return {};
109
- if (!isPlainObject(op.value)) throw new TypeError("settings mutate: setting the section root requires a plain object");
110
- return { ...op.value };
111
- }
112
- if (rest.length === 0) {
113
- if (op.op === "set") return {
114
- ...section,
115
- [head]: op.value
116
- };
117
- const { [head]: _removed, ...kept } = section;
118
- return kept;
119
- }
120
- const child = section[head];
121
- if (!isPlainObject(child)) {
122
- if (op.op === "unset") return section;
123
- return {
124
- ...section,
125
- [head]: applyPathOp({}, {
126
- ...op,
127
- path: rest
128
- })
129
- };
130
- }
131
- return {
132
- ...section,
133
- [head]: applyPathOp(child, {
134
- ...op,
135
- path: rest
136
- })
137
- };
138
- }
139
- /**
140
- * Layer `over` onto `under`: plain objects merge recursively, every other
141
- * value (arrays included) replaces the lower layer wholesale. `over` never
142
- * carries `undefined` entries — sections come from parsed documents and write
143
- * snapshots pass {@link cloneJsonShaped}, which strips them so a sparse patch
144
- * cannot erase lower keys.
145
- */
146
- function mergeLayers(under, over) {
147
- if (over === void 0) return under;
148
- if (!isPlainObject(under) || !isPlainObject(over)) return over;
149
- const merged = { ...under };
150
- for (const [key, value] of Object.entries(over)) merged[key] = key in merged ? mergeLayers(merged[key], value) : value;
151
- return merged;
152
- }
153
- /** Recursively freeze one resolved value so handed-out snapshots stay immutable. */
154
- function deepFreeze(value) {
155
- if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
156
- for (const entry of Object.values(value)) deepFreeze(entry);
157
- return Object.freeze(value);
158
- }
159
- Service.init;
160
- /**
161
- * Value mirror of the `FiberState` members {@link isUnloading} compares
162
- * against: a const enum has no runtime object to import, and the value is
163
- * needed at runtime (same rationale as the CLI boot driver's mirror).
164
- */
165
- const FIBER_DISPOSED = 4;
166
- const FIBER_UNLOADING = 5;
167
- /** Whether the consumer's own fiber is tearing down (not just losing the settings service). */
168
- function isUnloading(ctx) {
169
- const state = ctx.fiber.state;
170
- return state === FIBER_UNLOADING || state === FIBER_DISPOSED;
171
- }
172
- /**
173
- * Install the canonical optional-settings consumer wiring: while a settings
174
- * service exists, register `ns` with the consumer's composition entry as the
175
- * `base` layer and point the source thunk at the resolved scope; when the
176
- * service goes away (disposal, provider reload), fall back to the entry so
177
- * the consumer keeps working exactly as composed. The registration rides the
178
- * scoped fiber, so no settings service ever mounted means none of this runs.
179
- * @param ctx - consumer plugin context owning the wiring.
180
- * @param ns - the consumer-owned settings namespace.
181
- * @param schema - schema resolving the namespace (typically the plugin Config).
182
- * @param entry - the consumer's composition entry config, used as `base`.
183
- * @param hooks - source sink and change notification.
184
- */
185
- function installSettingsSection(ctx, ns, schema, entry, hooks) {
186
- ctx.inject(["settings"], (sctx) => {
187
- const scope = sctx.settings.register(ns, schema, {
188
- base: entry,
189
- ...hooks.validate === void 0 ? {} : { validate: hooks.validate }
190
- });
191
- hooks.setSource(() => scope.get());
192
- sctx.effect(() => () => {
193
- if (isUnloading(ctx)) return;
194
- hooks.setSource(() => entry);
195
- hooks.onChange();
196
- });
197
- hooks.onChange();
198
- scope.watch(() => {
199
- if (isUnloading(ctx)) return;
200
- hooks.onChange();
201
- });
202
- });
203
- }
204
- //#endregion
205
7
  //#region src/dsh-home.ts
206
8
  /**
207
9
  * DSH_HOME resolution shared by the plugin family's Host halves: the
@@ -594,7 +396,7 @@ function mountOnce(packageName, fn) {
594
396
  /** Stable cordis plugin name. */
595
397
  const name = "liangshen";
596
398
  /** Settings namespace of the plugin (the web settings surface edits it). */
597
- const LIANGSHEN_SETTINGS_NAMESPACE = settingsNamespace("dsh-liangshen");
399
+ const LIANGSHEN_SETTINGS_NAMESPACE = "dsh-liangshen";
598
400
  /** Prompt assembly must exist before the announcement section can register. */
599
401
  const inject = ["systemPrompt"];
600
402
  const Config = z.object({
@@ -650,12 +452,14 @@ function applyImpl(ctx, config) {
650
452
  text: LIANGSHEN_GUIDANCE
651
453
  });
652
454
  };
653
- installSettingsSection(ctx, LIANGSHEN_SETTINGS_NAMESPACE, Config, config ?? {}, {
654
- setSource: (source) => {
655
- current = source;
656
- refresh();
657
- },
658
- onChange: refresh
455
+ ctx.inject(["settings"], (settingsCtx) => {
456
+ settingsCtx.settings.installSection(ctx, LIANGSHEN_SETTINGS_NAMESPACE, Config, config ?? {}, {
457
+ setSource: (source) => {
458
+ current = source;
459
+ refresh();
460
+ },
461
+ onChange: refresh
462
+ });
659
463
  });
660
464
  refresh();
661
465
  ctx.effect(() => () => {
@@ -16,11 +16,12 @@
16
16
  * https://github.com/xiaobright/dsh-anchored-standard (MIT).
17
17
  */
18
18
  import type { Context } from '@deepseek-ai/cordis';
19
+ import type { SettingsNamespace } from '@deepseek-ai/dsh-settings';
19
20
  import z from 'schemastery';
20
21
  /** Stable cordis plugin name. */
21
22
  export declare const name = "liangshen";
22
23
  /** Settings namespace of the plugin (the web settings surface edits it). */
23
- export declare const LIANGSHEN_SETTINGS_NAMESPACE: import("@deepseek-ai/dsh-settings").SettingsNamespace;
24
+ export declare const LIANGSHEN_SETTINGS_NAMESPACE: SettingsNamespace;
24
25
  /** Prompt assembly must exist before the announcement section can register. */
25
26
  export declare const inject: string[];
26
27
  /** Plugin config, validated by the same-named schemastery schema. */
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.6",
4
+ "version": "0.3.10",
5
5
  "type": "module",
6
6
  "engines": {
7
7
  "node": "^22.19.0 || >=24.0.0"
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "dsh": {
20
20
  "engines": {
21
- "dsh": ">=0.1.1-rc.1"
21
+ "dsh": ">=0.1.2-alpha.1"
22
22
  },
23
23
  "bundle": {
24
24
  "patch": "./cordis.patch.yml"
@@ -28,9 +28,9 @@
28
28
  "schemastery": "^3.18.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@deepseek-ai/cordis": "^4.0.1",
32
- "@deepseek-ai/dsh-settings": "^0.1.1-rc.2",
33
- "@deepseek-ai/dsh-system-prompt": "^0.1.1-rc.2",
31
+ "@deepseek-ai/cordis": "^4.0.2",
32
+ "@deepseek-ai/dsh-settings": "^0.1.2-alpha.2",
33
+ "@deepseek-ai/dsh-system-prompt": "^0.1.2-alpha.2",
34
34
  "@types/node": "^22.20.0",
35
35
  "tsdown": "0.22.2",
36
36
  "typescript": "~5.7.2",
package/src/dsh-home.ts CHANGED
@@ -39,4 +39,4 @@ export function resolveDshHome(env: NodeJS.ProcessEnv = process.env, home: strin
39
39
  /** Resolve the DSH home directory from the live environment. */
40
40
  export function dshHome(): string {
41
41
  return resolveDshHome()
42
- }
42
+ }
package/src/index.ts CHANGED
@@ -20,7 +20,7 @@ import { mkdirSync } from 'node:fs'
20
20
  import { join } from 'node:path'
21
21
  import { fileURLToPath } from 'node:url'
22
22
  import type { Context } from '@deepseek-ai/cordis'
23
- import { installSettingsSection, settingsNamespace } from '@deepseek-ai/dsh-settings'
23
+ import type { SettingsNamespace } from '@deepseek-ai/dsh-settings'
24
24
  import type {} from '@deepseek-ai/dsh-system-prompt'
25
25
  import z from 'schemastery'
26
26
  import { dshHome } from './dsh-home.ts'
@@ -31,7 +31,7 @@ import { mountOnce } from './mount-once.ts'
31
31
  export const name = 'liangshen'
32
32
 
33
33
  /** Settings namespace of the plugin (the web settings surface edits it). */
34
- export const LIANGSHEN_SETTINGS_NAMESPACE = settingsNamespace('dsh-liangshen')
34
+ export const LIANGSHEN_SETTINGS_NAMESPACE = 'dsh-liangshen' as SettingsNamespace
35
35
 
36
36
  /** Prompt assembly must exist before the announcement section can register. */
37
37
  export const inject = ['systemPrompt']
@@ -82,7 +82,7 @@ export const apply = mountOnce('@linxin666/dsh-liangshen', applyImpl)
82
82
  function applyImpl(ctx: Context, config?: Config): void {
83
83
  // The live source the announcement reads: the settings section once the web
84
84
  // settings surface is served, the composition entry otherwise
85
- // (installSettingsSection swaps it when the namespace registers).
85
+ // (installSection swaps it when the namespace registers).
86
86
  let current: () => Config = () => config ?? {}
87
87
  const resolve = (): Config => ({
88
88
  announceToAgent: current().announceToAgent ?? DEFAULT_ANNOUNCE,
@@ -126,12 +126,14 @@ function applyImpl(ctx: Context, config?: Config): void {
126
126
  // The web settings surface gets the plugin's enabled / announceToAgent
127
127
  // fields from this namespace; a settings edit re-runs refresh live, and
128
128
  // deployments without a settings service keep the composition entry.
129
- installSettingsSection(ctx, LIANGSHEN_SETTINGS_NAMESPACE, Config, config ?? {}, {
130
- setSource: (source) => {
131
- current = source
132
- refresh()
133
- },
134
- onChange: refresh,
129
+ ctx.inject(['settings'], (settingsCtx) => {
130
+ settingsCtx.settings.installSection(ctx, LIANGSHEN_SETTINGS_NAMESPACE, Config, config ?? {}, {
131
+ setSource: (source) => {
132
+ current = source
133
+ refresh()
134
+ },
135
+ onChange: refresh,
136
+ })
135
137
  })
136
138
 
137
139
  refresh()