dsh-skill-pool 0.3.7 → 0.4.0

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/index.js CHANGED
@@ -21,7 +21,7 @@ import { createRequire } from 'node:module'
21
21
  import { defineTool } from '@deepseek-ai/dsh-tools'
22
22
  import z from '@deepseek-ai/schemastery'
23
23
 
24
- import { StateStore, statePath } from './src/store.js'
24
+ import { StateReadError, StateStore, defaultState, statePath } from './src/store.js'
25
25
  import { registerWebApi } from './src/web-api.js'
26
26
  import { createActivation, modeOf, workspaceOf } from './src/activation.js'
27
27
  import { createMountTracker } from './src/uploads.js'
@@ -52,32 +52,48 @@ const VERSION = (() => {
52
52
  /** Schemastery schema surfaced by `Config.listConfigs` and the profile patch. */
53
53
  export const Config = z.object({
54
54
  file: z.string().default('').description('Absolute state file path; empty uses $DSH_HOME/resource-pool/state.json.'),
55
- promptLanguage: z.string().default('zh').description("Language of the injected pool summary: 'zh' | 'en'."),
56
55
  enabled: z.boolean().default(true).description('Master switch; false keeps the panel but never gates a session.'),
57
56
  })
58
57
 
59
58
  /**
60
59
  * Mount the plugin.
61
60
  * @param {import('@deepseek-ai/cordis').Context} ctx - plugin context.
62
- * @param {{ file?: string, promptLanguage?: string, enabled?: boolean }} [config] - validated configuration.
61
+ * @param {{ file?: string, enabled?: boolean }} [config] - validated configuration.
63
62
  */
64
63
  export function apply(ctx, config = {}) {
65
64
  const logger = ctx.logger ?? undefined
66
65
  const file = typeof config.file === 'string' && config.file.trim().length > 0 ? config.file.trim() : statePath()
67
66
  const store = new StateStore({ file, logger, version: VERSION })
68
- const promptLanguage = config.promptLanguage === 'en' ? 'en' : 'zh'
69
67
  const masterEnabled = config.enabled !== false
70
68
 
69
+ /** Read the stored document with fail-closed validation (diagnostics too). */
70
+ const readStoredState = () => store.read({ fresh: true })
71
+
71
72
  /** Effective document: the profile's master switch wins over the stored one. */
72
73
  const getState = async () => {
73
- const state = await store.read({ fresh: true })
74
- if (masterEnabled) return state
75
- return { ...state, settings: { ...state.settings, enabled: false } }
74
+ if (!masterEnabled) {
75
+ // A deliberately disabled plugin never gates a session, so a corrupt file
76
+ // must not turn into a creation failure. Keep the panel/status diagnostic
77
+ // path (which reads the store directly) intact and fall back to an empty,
78
+ // ungated document. Nothing is written.
79
+ try {
80
+ const state = await readStoredState()
81
+ return { ...state, settings: { ...state.settings, enabled: false } }
82
+ } catch (error) {
83
+ // Only a state-reader failure is expected here; anything else is a bug
84
+ // and must not be turned into a silent "ungated" answer.
85
+ if (!(error instanceof StateReadError)) throw error
86
+ logger?.warn?.(`[skill-pool] plugin disabled; ignoring unreadable state: ${error.message}`)
87
+ const state = defaultState()
88
+ return { ...state, settings: { ...state.settings, enabled: false } }
89
+ }
90
+ }
91
+ return readStoredState()
76
92
  }
77
93
 
78
- const activation = createActivation({ ctx, getState, logger, promptLanguage: () => promptLanguage })
94
+ const activation = createActivation({ ctx, getState, logger })
79
95
 
80
- const meta = { version: VERSION, file, pluginName: 'dsh-skill-pool', promptLanguage }
96
+ const meta = { version: VERSION, file, pluginName: 'dsh-skill-pool' }
81
97
 
82
98
  // Apply to existing Agents too: a plugin reload must not leave live sessions
83
99
  // ungated until they are recreated.
@@ -87,7 +103,9 @@ export function apply(ctx, config = {}) {
87
103
 
88
104
  ctx.on('agent/created', async ({ agent }) => {
89
105
  // Listeners are awaited before creation resolves and before the Agent may
90
- // assemble its first request; `applyToAgent` contains its own failures.
106
+ // assemble its first request. If the state file cannot be read safely and
107
+ // this Agent has no previous gate, `applyToAgent` rejects: letting creation
108
+ // continue would publish an Agent with no MCP restriction (fail-open).
91
109
  await activation.applyToAgent(agent)
92
110
  })
93
111
 
@@ -104,7 +122,9 @@ export function apply(ctx, config = {}) {
104
122
  const live = typeof registry?.list === 'function' ? registry.list() : []
105
123
  const agent = live.find((candidate) => candidate?.session?.id === sessionId || candidate?.id === sessionId)
106
124
  if (agent === undefined) return
107
- void activation.applyToAgent(agent, { force: true })
125
+ void activation.applyToAgent(agent, { force: true, conservative: true }).catch((error) => {
126
+ logger?.warn?.(`[skill-pool] preset re-apply failed: ${error instanceof Error ? error.message : String(error)}`)
127
+ })
108
128
  })
109
129
 
110
130
  // Registrations live on each Agent's context; release them when the plugin
@@ -119,9 +139,7 @@ export function apply(ctx, config = {}) {
119
139
  mounts,
120
140
  meta,
121
141
  logger,
122
- onChanged: async () => {
123
- await activation.reapplyAll()
124
- },
142
+ onChanged: () => activation.reapplyAll(),
125
143
  })
126
144
 
127
145
  // Storage keeps each MCP member's connection definition precisely so this
@@ -150,7 +168,31 @@ export function apply(ctx, config = {}) {
150
168
  render: (_args, value) => [{ type: 'text', text: JSON.stringify(value, null, 2) }],
151
169
  },
152
170
  async execute(_args, exec) {
153
- const state = await getState()
171
+ let state
172
+ try {
173
+ const stored = await readStoredState()
174
+ state = masterEnabled ? stored : { ...stored, settings: { ...stored.settings, enabled: false } }
175
+ } catch (error) {
176
+ // A status call must stay answerable precisely when the pool is
177
+ // degraded, so the Agent can explain why resources are unavailable.
178
+ const expected = error instanceof StateReadError
179
+ const code = expected ? error.code : 'resource-pool/state-unavailable'
180
+ const message = expected ? error.message : 'resource-pool state is unavailable'
181
+ return {
182
+ plugin: 'dsh-skill-pool',
183
+ version: VERSION,
184
+ stateFile: file,
185
+ masterEnabled,
186
+ stateStatus: {
187
+ ok: false,
188
+ code,
189
+ message,
190
+ recovery:
191
+ 'No pool was applied from the unreadable document. Existing Agents keep their previous gate; new Agents are refused. Back up state.json, repair or restore it, then retry.',
192
+ },
193
+ pool: null,
194
+ }
195
+ }
154
196
  const agent = exec?.agent
155
197
  const mode = agent === undefined ? '' : modeOf(ctx, agent)
156
198
  const cwd = agent === undefined ? '' : workspaceOf(agent)
@@ -159,8 +201,8 @@ export function apply(ctx, config = {}) {
159
201
  plugin: 'dsh-skill-pool',
160
202
  version: VERSION,
161
203
  stateFile: file,
162
- promptLanguage,
163
204
  masterEnabled,
205
+ stateStatus: { ok: true },
164
206
  mode,
165
207
  cwd,
166
208
  ...pool,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-skill-pool",
3
- "version": "0.3.7",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "description": "One pool for all your DSH skills: import from files, ZIP, GitHub or GitLab, then scope each skill to Agent modes and workspaces from the Settings panel — no code editing required.",
6
6
  "license": "MIT",
@@ -44,7 +44,13 @@
44
44
  ],
45
45
  "scripts": {
46
46
  "test": "node --test test/*.test.mjs",
47
- "lint": "node --check index.js && node --check client.js && node --check src/store.js && node --check src/rules.js && node --check src/inventory.js && node --check src/activation.js && node --check src/provider.js && node --check src/skill-content.js && node --check src/web-api.js && node --check src/uploads.js && node --check src/mount.js && node --check src/remount.js && node --check src/library.js"
47
+ "lint": "node --check index.js && node --check client.js && node --check src/store.js && node --check src/rules.js && node --check src/inventory.js && node --check src/activation.js && node --check src/provider.js && node --check src/skill-content.js && node --check src/web-api.js && node --check src/uploads.js && node --check src/mount.js && node --check src/remount.js && node --check src/library.js",
48
+ "test:feasibility": "node --test test/mcp-feasibility.probe.mjs",
49
+ "test:lifecycle": "node --test test/plugin-lifecycle.probe.mjs",
50
+ "test:naming": "node --test test/mcp-naming.probe.mjs",
51
+ "test:restrict": "node --test test/restrict-lifecycle.probe.mjs",
52
+ "test:activation": "node --test test/activation-restrict.probe.mjs",
53
+ "verify:feasibility": "node test/verify-feasibility.mjs"
48
54
  },
49
55
  "dsh": {
50
56
  "bundle": {