dsh-embedded-workbench 0.8.0 → 0.8.2
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/LICENSE +21 -21
- package/lib/index.js +197 -197
- package/lib/types/index.d.ts +43 -43
- package/package.json +5 -3
- package/skills/c-cpp-dev/SKILL.md +121 -121
- package/skills/debug-methodology/SKILL.md +83 -83
- package/skills/debug-methodology/references/iterative-debug-case-study.md +103 -103
- package/skills/embedded-firmware-dev/SKILL.md +133 -133
- package/skills/embedded-firmware-dev/references/architecture-principles.md +204 -204
- package/skills/embedded-firmware-dev/references/embedded-patterns.md +95 -95
- package/skills/embedded-firmware-dev/references/lvgl-pitfalls.md +68 -68
- package/skills/embedded-workbench/SKILL.md +242 -242
- package/skills/embedded-workbench/references/final-qc.md +40 -40
- package/skills/embedded-workbench/references/platform-tool-mapping.md +88 -88
- package/skills/fact-check/SKILL.md +57 -57
- package/skills/hardfault-triage/SKILL.md +237 -237
- package/skills/keil-mdk-build/SKILL.md +237 -237
- package/skills/state-machine-design/SKILL.md +190 -190
- package/src/index.ts +209 -209
package/src/index.ts
CHANGED
|
@@ -1,209 +1,209 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* embedded-workbench — DeepSeek Harness native plugin for the Embedded
|
|
3
|
-
* Workbench toolbox. Injects the session-start gate text (1% Rule, Red
|
|
4
|
-
* Flags, Plan Verification Gate, skills roster) into the first model step
|
|
5
|
-
* of every agent session, mirroring the SessionStart hook the Claude Code
|
|
6
|
-
* plugin installs. The 8 skills ship in this package's `skills/` directory
|
|
7
|
-
* and are registered at apply time into dsh's `ctx.skills` registry through
|
|
8
|
-
* the standard filesystem provider, so they appear in every session catalog
|
|
9
|
-
* without a manual copy step.
|
|
10
|
-
*
|
|
11
|
-
* Injection listens on agent/pre-step and appends the gate to the FIRST
|
|
12
|
-
* model step that runs, once per session (guarded by the session's durable
|
|
13
|
-
* history). Session-start inbox injection was dropped: a blank-session preset
|
|
14
|
-
* switch (agentPreset.select -> recompose) can clear the inbox before the
|
|
15
|
-
* first step, losing the gate for the whole session. The pre-step decision is
|
|
16
|
-
* the durable path - anchored/bootstrap presets that strip first-step injected
|
|
17
|
-
* reminders (skill catalog, AGENTS.md, gate plugins) simply defer this message
|
|
18
|
-
* to the first step after their promotion, and the history guard re-injects it
|
|
19
|
-
* there. The default gate text is the dsh-native adaptation of
|
|
20
|
-
* `hooks/session-start-content.md`: behavior rules
|
|
21
|
-
* (1% Rule / Red Flags / Plan Verification Gate) stay in sync, while
|
|
22
|
-
* presentation is adapted to dsh's native skill catalog — no roster table
|
|
23
|
-
* (the model sees skills in its catalog) and no install instructions (those
|
|
24
|
-
* live in `.dsh/INSTALL.md`). Deployments override via Config.
|
|
25
|
-
*
|
|
26
|
-
* @module embedded-workbench-dsh
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
import { fileURLToPath } from 'node:url'
|
|
30
|
-
import type { Context } from '@deepseek-ai/cordis'
|
|
31
|
-
import z from '@deepseek-ai/schemastery'
|
|
32
|
-
import { createUserMessage } from '@deepseek-ai/dsh-llm'
|
|
33
|
-
import type { Session, UserMessage } from '@deepseek-ai/dsh-session'
|
|
34
|
-
import type { HostCordisInspectProviderRegistration } from '@deepseek-ai/dsh-cordis-host-runner'
|
|
35
|
-
import { FileSystemSkillProvider } from '@deepseek-ai/dsh-skill-filesystem'
|
|
36
|
-
|
|
37
|
-
export const name = 'embedded-workbench'
|
|
38
|
-
|
|
39
|
-
// Skills are contributed through the registry service, which dsh-base always
|
|
40
|
-
// mounts before bundle rows such as this one apply.
|
|
41
|
-
export const inject = ['skills']
|
|
42
|
-
|
|
43
|
-
// Absolute path of the package's shipped skills directory. `lib/index.js`
|
|
44
|
-
// lives one level below the package root, so `../skills` from the module URL
|
|
45
|
-
// lands on `<package>/skills` regardless of where the package was installed.
|
|
46
|
-
const SKILLS_DIR = fileURLToPath(new URL('../skills', import.meta.url))
|
|
47
|
-
|
|
48
|
-
const GATE_PLUGIN_ID = 'embedded-workbench'
|
|
49
|
-
|
|
50
|
-
const DEFAULT_GATE_CONTENT = `<EXTREMELY_IMPORTANT>
|
|
51
|
-
Plugin embedded-workbench is active. You have embedded C/C++ firmware development skills — names and "Use when" triggers are in your skill catalog; load them with the skill tool. No custom agents in dsh: use the native subagent tooling for parallel work.
|
|
52
|
-
|
|
53
|
-
**1% Rule**: If there is even a 1% chance a skill applies to your task, invoke it before responding. If the skill turns out to be wrong for the situation, discard it and move on. The cost of loading a skill is trivial compared to the cost of a preventable mistake.
|
|
54
|
-
|
|
55
|
-
**Red Flags** — if you think any of these, STOP. You are rationalizing:
|
|
56
|
-
|
|
57
|
-
| You think | Reality |
|
|
58
|
-
|-----------|---------|
|
|
59
|
-
| "This is just a quick fix" | Quick fixes break things. A 3-line design check costs 30 seconds. |
|
|
60
|
-
| "I already understand this code" | You are looking at one file. The blast radius may span 5 modules. |
|
|
61
|
-
| "The skill is overkill for this" | Simple things become complex. Check for skills. |
|
|
62
|
-
| "Let me explore the codebase first" | Skills tell you HOW to explore. Check first. |
|
|
63
|
-
| "I can just read the file directly" | Skills have patterns and pitfalls you will not discover by reading. |
|
|
64
|
-
| "I remember this skill content" | Skills evolve. Always load the current version. |
|
|
65
|
-
| "I've explored enough, time to exit plan mode" | The exit_plan_mode tool is the verification gate. Have you loaded the logicprobe skill — or, if it is not installed, the built-in fallback fact-check skill? Every plan must pass this gate before exit. |
|
|
66
|
-
| "This plan is too simple for logicprobe" | logicprobe auto-classifies depth; the fallback fact-check verifies every claim regardless. You don't decide. |
|
|
67
|
-
| "I already read the code, I know the file paths are correct" | Load the logicprobe skill or the fallback fact-check skill, verify each claim, append the "## Plan Verification" block. |
|
|
68
|
-
|
|
69
|
-
**Plan Verification Gate**: Before calling exit_plan_mode (or presenting a plan for approval), load the logicprobe skill (a separate plugin) — or, if it is missing from your skill catalog, load the built-in fallback fact-check skill for claim-by-claim verification, tell the user that behavioral/model claims degrade to manual confirmation, and recommend installing logicprobe. If neither is loaded, inform the user "此计划未经核查,是否需要我先做事实核查?" Silent skip is not an option.
|
|
70
|
-
|
|
71
|
-
To load workflows and engineering policies: load the embedded-workbench skill.
|
|
72
|
-
|
|
73
|
-
**Proactive features**: When you see state machines, protocol refactoring, behavioral claims ("always"/"never"), or multi-module tasks — suggest verification (logicprobe, or the built-in fact-check fallback if logicprobe is not installed), adversarial probing, or parallel subagents BEFORE the user asks. Most users do not know these exist.
|
|
74
|
-
</EXTREMELY_IMPORTANT>`
|
|
75
|
-
|
|
76
|
-
export interface Config {
|
|
77
|
-
enabled: boolean
|
|
78
|
-
gateContent: string
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export const Config = z.object({
|
|
82
|
-
enabled: z.boolean().default(true),
|
|
83
|
-
gateContent: z.string().default(DEFAULT_GATE_CONTENT),
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
function gateMessage(text: string): UserMessage {
|
|
87
|
-
return createUserMessage({
|
|
88
|
-
content: [{ type: 'text', text }],
|
|
89
|
-
// `form` omitted — an undeclared context is the documented default.
|
|
90
|
-
source: { kind: 'plugin', plugin: GATE_PLUGIN_ID },
|
|
91
|
-
})
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Model-visible catalog entry (cordis_inspect_list / cordis_inspect_query):
|
|
96
|
-
* lets the model read this plugin's runtime status without guessing. Mirrors
|
|
97
|
-
* the registration pattern of the official dsh-tool-cordis host providers.
|
|
98
|
-
*/
|
|
99
|
-
function inspectProvider(config: Config): HostCordisInspectProviderRegistration {
|
|
100
|
-
return {
|
|
101
|
-
manifest: {
|
|
102
|
-
id: 'embedded-workbench',
|
|
103
|
-
description: 'Session-start gate injection for the Embedded Workbench toolbox — folds the 1% Rule / Red Flags / Plan Verification Gate text into the first model step of every agent session.',
|
|
104
|
-
methods: [
|
|
105
|
-
{
|
|
106
|
-
name: 'status',
|
|
107
|
-
description: 'Read whether the gate injection is active and how large the injected gate text is.',
|
|
108
|
-
inputSchema: {
|
|
109
|
-
type: 'object',
|
|
110
|
-
properties: {},
|
|
111
|
-
additionalProperties: false,
|
|
112
|
-
},
|
|
113
|
-
outputSchema: {
|
|
114
|
-
type: 'object',
|
|
115
|
-
description: 'Gate-injection plugin status.',
|
|
116
|
-
properties: {
|
|
117
|
-
enabled: { type: 'boolean', description: 'Whether the gate folds into the first model step.' },
|
|
118
|
-
gateContentLength: { type: 'integer', description: 'Length in characters of the injected gate text.' },
|
|
119
|
-
},
|
|
120
|
-
required: ['enabled', 'gateContentLength'],
|
|
121
|
-
additionalProperties: false,
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
],
|
|
125
|
-
},
|
|
126
|
-
query: async (method) => {
|
|
127
|
-
if (method === 'status') {
|
|
128
|
-
return {
|
|
129
|
-
enabled: config.enabled,
|
|
130
|
-
gateContentLength: config.gateContent.length,
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return null
|
|
134
|
-
},
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export function apply(ctx: Context, config: Config): void {
|
|
139
|
-
// Catalog visibility is optional: register only when the inspect registry
|
|
140
|
-
// service is mounted, so headless assemblies without it keep the gate
|
|
141
|
-
// injection working. The registry may be provided AFTER this row applies
|
|
142
|
-
// (base-bundle rows can mount later), so registration is retried on the
|
|
143
|
-
// first agent/session-start — by then the app is fully booted.
|
|
144
|
-
let providerRegistered = false
|
|
145
|
-
const registerProvider = (): void => {
|
|
146
|
-
if (providerRegistered) return
|
|
147
|
-
const inspect = ctx.get('cordisInspect')
|
|
148
|
-
if (inspect === undefined) return
|
|
149
|
-
try {
|
|
150
|
-
ctx.effect(() => inspect.register(inspectProvider(config)), 'embedded-workbench: inspect provider')
|
|
151
|
-
providerRegistered = true
|
|
152
|
-
} catch (err) {
|
|
153
|
-
console.warn('[embedded-workbench] inspect provider registration failed', err)
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
registerProvider()
|
|
157
|
-
// Ship the bundled skills through the registry: reuse the standard
|
|
158
|
-
// filesystem provider over this package's own `skills/` directory, so
|
|
159
|
-
// catalog discovery, frontmatter parsing, and SKILL.md loading behave
|
|
160
|
-
// exactly like project/user skills while the plugin stays self-contained.
|
|
161
|
-
// Registration lands in the global registry layer (this row mounts at the
|
|
162
|
-
// profile root), so every agent preset sees the skills. `registerProvider`
|
|
163
|
-
// returns the effect disposer; its teardown unregisters and invalidates.
|
|
164
|
-
ctx.skills.registerProvider((control) => {
|
|
165
|
-
return new FileSystemSkillProvider(ctx, control, {
|
|
166
|
-
providerName: 'embedded-workbench',
|
|
167
|
-
includeDefaultRoots: false,
|
|
168
|
-
customSkillDirs: [SKILLS_DIR],
|
|
169
|
-
})
|
|
170
|
-
})
|
|
171
|
-
if (!config.enabled) return
|
|
172
|
-
// Inject the gate once per session on the FIRST model step that runs,
|
|
173
|
-
// instead of at session-start: session-start injection lands in the agent's
|
|
174
|
-
// inbox, which a blank-session preset switch (agentPreset.select ->
|
|
175
|
-
// recompose) can clear before the first step - the gate would then be lost
|
|
176
|
-
// for the whole session. The pre-step decision is the durable path a
|
|
177
|
-
// first-step injection takes: the gate is appended to the first step's
|
|
178
|
-
// decision and enters session history there, so every later step (and a
|
|
179
|
-
// resume) skips it. Anchored/bootstrap presets that strip first-step
|
|
180
|
-
// injected reminders (skill catalog, AGENTS.md, gate plugins) simply defer
|
|
181
|
-
// this message to the first step after their promotion - the history guard
|
|
182
|
-
// re-injects it there, so the gate still lands exactly once per session.
|
|
183
|
-
ctx.on('agent/pre-step', async ({ agent }, next) => {
|
|
184
|
-
const decision = await next()
|
|
185
|
-
if (decision.kind === 'reject') return decision
|
|
186
|
-
registerProvider()
|
|
187
|
-
if (gateInHistory(agent.session)) return decision
|
|
188
|
-
return {
|
|
189
|
-
kind: 'enter',
|
|
190
|
-
messages: [...decision.messages, gateMessage(config.gateContent)],
|
|
191
|
-
}
|
|
192
|
-
})
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Whether the gate already entered this session's durable history. The
|
|
197
|
-
* pre-step listener re-appends the gate until it does; once a step committed
|
|
198
|
-
* it, every later step (and a resume of a session that kept it) skips the
|
|
199
|
-
* injection. A session whose gate was dropped before any step ran (e.g. an
|
|
200
|
-
* inbox cleared by a blank-session preset switch) simply re-injects on the
|
|
201
|
-
* first step that runs.
|
|
202
|
-
*/
|
|
203
|
-
function gateInHistory(session: Session): boolean {
|
|
204
|
-
return session.events.some((event) => {
|
|
205
|
-
if (event.type !== 'user/message') return false
|
|
206
|
-
const source = event.data.source
|
|
207
|
-
return source.kind === 'plugin' && source.plugin === GATE_PLUGIN_ID
|
|
208
|
-
})
|
|
209
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* embedded-workbench — DeepSeek Harness native plugin for the Embedded
|
|
3
|
+
* Workbench toolbox. Injects the session-start gate text (1% Rule, Red
|
|
4
|
+
* Flags, Plan Verification Gate, skills roster) into the first model step
|
|
5
|
+
* of every agent session, mirroring the SessionStart hook the Claude Code
|
|
6
|
+
* plugin installs. The 8 skills ship in this package's `skills/` directory
|
|
7
|
+
* and are registered at apply time into dsh's `ctx.skills` registry through
|
|
8
|
+
* the standard filesystem provider, so they appear in every session catalog
|
|
9
|
+
* without a manual copy step.
|
|
10
|
+
*
|
|
11
|
+
* Injection listens on agent/pre-step and appends the gate to the FIRST
|
|
12
|
+
* model step that runs, once per session (guarded by the session's durable
|
|
13
|
+
* history). Session-start inbox injection was dropped: a blank-session preset
|
|
14
|
+
* switch (agentPreset.select -> recompose) can clear the inbox before the
|
|
15
|
+
* first step, losing the gate for the whole session. The pre-step decision is
|
|
16
|
+
* the durable path - anchored/bootstrap presets that strip first-step injected
|
|
17
|
+
* reminders (skill catalog, AGENTS.md, gate plugins) simply defer this message
|
|
18
|
+
* to the first step after their promotion, and the history guard re-injects it
|
|
19
|
+
* there. The default gate text is the dsh-native adaptation of
|
|
20
|
+
* `hooks/session-start-content.md`: behavior rules
|
|
21
|
+
* (1% Rule / Red Flags / Plan Verification Gate) stay in sync, while
|
|
22
|
+
* presentation is adapted to dsh's native skill catalog — no roster table
|
|
23
|
+
* (the model sees skills in its catalog) and no install instructions (those
|
|
24
|
+
* live in `.dsh/INSTALL.md`). Deployments override via Config.
|
|
25
|
+
*
|
|
26
|
+
* @module embedded-workbench-dsh
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { fileURLToPath } from 'node:url'
|
|
30
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
31
|
+
import z from '@deepseek-ai/schemastery'
|
|
32
|
+
import { createUserMessage } from '@deepseek-ai/dsh-llm'
|
|
33
|
+
import type { Session, UserMessage } from '@deepseek-ai/dsh-session'
|
|
34
|
+
import type { HostCordisInspectProviderRegistration } from '@deepseek-ai/dsh-cordis-host-runner'
|
|
35
|
+
import { FileSystemSkillProvider } from '@deepseek-ai/dsh-skill-filesystem'
|
|
36
|
+
|
|
37
|
+
export const name = 'embedded-workbench'
|
|
38
|
+
|
|
39
|
+
// Skills are contributed through the registry service, which dsh-base always
|
|
40
|
+
// mounts before bundle rows such as this one apply.
|
|
41
|
+
export const inject = ['skills']
|
|
42
|
+
|
|
43
|
+
// Absolute path of the package's shipped skills directory. `lib/index.js`
|
|
44
|
+
// lives one level below the package root, so `../skills` from the module URL
|
|
45
|
+
// lands on `<package>/skills` regardless of where the package was installed.
|
|
46
|
+
const SKILLS_DIR = fileURLToPath(new URL('../skills', import.meta.url))
|
|
47
|
+
|
|
48
|
+
const GATE_PLUGIN_ID = 'embedded-workbench'
|
|
49
|
+
|
|
50
|
+
const DEFAULT_GATE_CONTENT = `<EXTREMELY_IMPORTANT>
|
|
51
|
+
Plugin embedded-workbench is active. You have embedded C/C++ firmware development skills — names and "Use when" triggers are in your skill catalog; load them with the skill tool. No custom agents in dsh: use the native subagent tooling for parallel work.
|
|
52
|
+
|
|
53
|
+
**1% Rule**: If there is even a 1% chance a skill applies to your task, invoke it before responding. If the skill turns out to be wrong for the situation, discard it and move on. The cost of loading a skill is trivial compared to the cost of a preventable mistake.
|
|
54
|
+
|
|
55
|
+
**Red Flags** — if you think any of these, STOP. You are rationalizing:
|
|
56
|
+
|
|
57
|
+
| You think | Reality |
|
|
58
|
+
|-----------|---------|
|
|
59
|
+
| "This is just a quick fix" | Quick fixes break things. A 3-line design check costs 30 seconds. |
|
|
60
|
+
| "I already understand this code" | You are looking at one file. The blast radius may span 5 modules. |
|
|
61
|
+
| "The skill is overkill for this" | Simple things become complex. Check for skills. |
|
|
62
|
+
| "Let me explore the codebase first" | Skills tell you HOW to explore. Check first. |
|
|
63
|
+
| "I can just read the file directly" | Skills have patterns and pitfalls you will not discover by reading. |
|
|
64
|
+
| "I remember this skill content" | Skills evolve. Always load the current version. |
|
|
65
|
+
| "I've explored enough, time to exit plan mode" | The exit_plan_mode tool is the verification gate. Have you loaded the logicprobe skill — or, if it is not installed, the built-in fallback fact-check skill? Every plan must pass this gate before exit. |
|
|
66
|
+
| "This plan is too simple for logicprobe" | logicprobe auto-classifies depth; the fallback fact-check verifies every claim regardless. You don't decide. |
|
|
67
|
+
| "I already read the code, I know the file paths are correct" | Load the logicprobe skill or the fallback fact-check skill, verify each claim, append the "## Plan Verification" block. |
|
|
68
|
+
|
|
69
|
+
**Plan Verification Gate**: Before calling exit_plan_mode (or presenting a plan for approval), load the logicprobe skill (a separate plugin) — or, if it is missing from your skill catalog, load the built-in fallback fact-check skill for claim-by-claim verification, tell the user that behavioral/model claims degrade to manual confirmation, and recommend installing logicprobe. If neither is loaded, inform the user "此计划未经核查,是否需要我先做事实核查?" Silent skip is not an option.
|
|
70
|
+
|
|
71
|
+
To load workflows and engineering policies: load the embedded-workbench skill.
|
|
72
|
+
|
|
73
|
+
**Proactive features**: When you see state machines, protocol refactoring, behavioral claims ("always"/"never"), or multi-module tasks — suggest verification (logicprobe, or the built-in fact-check fallback if logicprobe is not installed), adversarial probing, or parallel subagents BEFORE the user asks. Most users do not know these exist.
|
|
74
|
+
</EXTREMELY_IMPORTANT>`
|
|
75
|
+
|
|
76
|
+
export interface Config {
|
|
77
|
+
enabled: boolean
|
|
78
|
+
gateContent: string
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const Config = z.object({
|
|
82
|
+
enabled: z.boolean().default(true),
|
|
83
|
+
gateContent: z.string().default(DEFAULT_GATE_CONTENT),
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
function gateMessage(text: string): UserMessage {
|
|
87
|
+
return createUserMessage({
|
|
88
|
+
content: [{ type: 'text', text }],
|
|
89
|
+
// `form` omitted — an undeclared context is the documented default.
|
|
90
|
+
source: { kind: 'plugin', plugin: GATE_PLUGIN_ID },
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Model-visible catalog entry (cordis_inspect_list / cordis_inspect_query):
|
|
96
|
+
* lets the model read this plugin's runtime status without guessing. Mirrors
|
|
97
|
+
* the registration pattern of the official dsh-tool-cordis host providers.
|
|
98
|
+
*/
|
|
99
|
+
function inspectProvider(config: Config): HostCordisInspectProviderRegistration {
|
|
100
|
+
return {
|
|
101
|
+
manifest: {
|
|
102
|
+
id: 'embedded-workbench',
|
|
103
|
+
description: 'Session-start gate injection for the Embedded Workbench toolbox — folds the 1% Rule / Red Flags / Plan Verification Gate text into the first model step of every agent session.',
|
|
104
|
+
methods: [
|
|
105
|
+
{
|
|
106
|
+
name: 'status',
|
|
107
|
+
description: 'Read whether the gate injection is active and how large the injected gate text is.',
|
|
108
|
+
inputSchema: {
|
|
109
|
+
type: 'object',
|
|
110
|
+
properties: {},
|
|
111
|
+
additionalProperties: false,
|
|
112
|
+
},
|
|
113
|
+
outputSchema: {
|
|
114
|
+
type: 'object',
|
|
115
|
+
description: 'Gate-injection plugin status.',
|
|
116
|
+
properties: {
|
|
117
|
+
enabled: { type: 'boolean', description: 'Whether the gate folds into the first model step.' },
|
|
118
|
+
gateContentLength: { type: 'integer', description: 'Length in characters of the injected gate text.' },
|
|
119
|
+
},
|
|
120
|
+
required: ['enabled', 'gateContentLength'],
|
|
121
|
+
additionalProperties: false,
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
query: async (method) => {
|
|
127
|
+
if (method === 'status') {
|
|
128
|
+
return {
|
|
129
|
+
enabled: config.enabled,
|
|
130
|
+
gateContentLength: config.gateContent.length,
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return null
|
|
134
|
+
},
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function apply(ctx: Context, config: Config): void {
|
|
139
|
+
// Catalog visibility is optional: register only when the inspect registry
|
|
140
|
+
// service is mounted, so headless assemblies without it keep the gate
|
|
141
|
+
// injection working. The registry may be provided AFTER this row applies
|
|
142
|
+
// (base-bundle rows can mount later), so registration is retried on the
|
|
143
|
+
// first agent/session-start — by then the app is fully booted.
|
|
144
|
+
let providerRegistered = false
|
|
145
|
+
const registerProvider = (): void => {
|
|
146
|
+
if (providerRegistered) return
|
|
147
|
+
const inspect = ctx.get('cordisInspect')
|
|
148
|
+
if (inspect === undefined) return
|
|
149
|
+
try {
|
|
150
|
+
ctx.effect(() => inspect.register(inspectProvider(config)), 'embedded-workbench: inspect provider')
|
|
151
|
+
providerRegistered = true
|
|
152
|
+
} catch (err) {
|
|
153
|
+
console.warn('[embedded-workbench] inspect provider registration failed', err)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
registerProvider()
|
|
157
|
+
// Ship the bundled skills through the registry: reuse the standard
|
|
158
|
+
// filesystem provider over this package's own `skills/` directory, so
|
|
159
|
+
// catalog discovery, frontmatter parsing, and SKILL.md loading behave
|
|
160
|
+
// exactly like project/user skills while the plugin stays self-contained.
|
|
161
|
+
// Registration lands in the global registry layer (this row mounts at the
|
|
162
|
+
// profile root), so every agent preset sees the skills. `registerProvider`
|
|
163
|
+
// returns the effect disposer; its teardown unregisters and invalidates.
|
|
164
|
+
ctx.skills.registerProvider((control) => {
|
|
165
|
+
return new FileSystemSkillProvider(ctx, control, {
|
|
166
|
+
providerName: 'embedded-workbench',
|
|
167
|
+
includeDefaultRoots: false,
|
|
168
|
+
customSkillDirs: [SKILLS_DIR],
|
|
169
|
+
})
|
|
170
|
+
})
|
|
171
|
+
if (!config.enabled) return
|
|
172
|
+
// Inject the gate once per session on the FIRST model step that runs,
|
|
173
|
+
// instead of at session-start: session-start injection lands in the agent's
|
|
174
|
+
// inbox, which a blank-session preset switch (agentPreset.select ->
|
|
175
|
+
// recompose) can clear before the first step - the gate would then be lost
|
|
176
|
+
// for the whole session. The pre-step decision is the durable path a
|
|
177
|
+
// first-step injection takes: the gate is appended to the first step's
|
|
178
|
+
// decision and enters session history there, so every later step (and a
|
|
179
|
+
// resume) skips it. Anchored/bootstrap presets that strip first-step
|
|
180
|
+
// injected reminders (skill catalog, AGENTS.md, gate plugins) simply defer
|
|
181
|
+
// this message to the first step after their promotion - the history guard
|
|
182
|
+
// re-injects it there, so the gate still lands exactly once per session.
|
|
183
|
+
ctx.on('agent/pre-step', async ({ agent }, next) => {
|
|
184
|
+
const decision = await next()
|
|
185
|
+
if (decision.kind === 'reject') return decision
|
|
186
|
+
registerProvider()
|
|
187
|
+
if (gateInHistory(agent.session)) return decision
|
|
188
|
+
return {
|
|
189
|
+
kind: 'enter',
|
|
190
|
+
messages: [...decision.messages, gateMessage(config.gateContent)],
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Whether the gate already entered this session's durable history. The
|
|
197
|
+
* pre-step listener re-appends the gate until it does; once a step committed
|
|
198
|
+
* it, every later step (and a resume of a session that kept it) skips the
|
|
199
|
+
* injection. A session whose gate was dropped before any step ran (e.g. an
|
|
200
|
+
* inbox cleared by a blank-session preset switch) simply re-injects on the
|
|
201
|
+
* first step that runs.
|
|
202
|
+
*/
|
|
203
|
+
function gateInHistory(session: Session): boolean {
|
|
204
|
+
return session.events.some((event) => {
|
|
205
|
+
if (event.type !== 'user/message') return false
|
|
206
|
+
const source = event.data.source
|
|
207
|
+
return source.kind === 'plugin' && source.plugin === GATE_PLUGIN_ID
|
|
208
|
+
})
|
|
209
|
+
}
|