返回 CodeWhale
gen-inspect-catalog.mjs
根目录 / crates / engine / extension-host / scripts / gen-inspect-catalog.mjs
1 import { readFileSync, writeFileSync } from 'node:fs'
2 import { dirname, join } from 'node:path'
3 import { fileURLToPath, pathToFileURL } from 'node:url'
4
5 const here = dirname(fileURLToPath(import.meta.url))
6 const root = join(here, '..')
7 const SOURCES = {
8 compatibility: join(root, 'src/dsh/compatibility.json'),
9 hostRoot: join(root, 'src/root.ts'),
10 shellHooks: join(root, 'src/dsh/shell-hooks.ts'),
11 seatTable: join(root, '../../app-server/src/runtime_api/plugins.rs'),
12 catalog: join(root, 'src/dsh/inspect-catalog.json'),
13 }
14
15 const read = (path) => readFileSync(path, 'utf8').replace(/\r\n/g, '\n')
16
17 const SERVICES = {
18 tools: {
19 summary: 'The tool registry: a plugin adds model-callable tools. The Engine owns calling, approval and results.',
20 availability: 'always',
21 methods: [
22 { name: 'register', signature: 'register(definition: ToolDefinition): () => void', summary: 'Register one tool built with defineTool from @deepseek-ai/dsh-tools. The definition must stay inside the supported JSON Schema subset (type, oneOf, properties, required, additionalProperties, items, enum, const). A second argument is refused. Returns an idempotent disposer.' },
23 { name: 'get', signature: 'get(name: string, agent: Agent): { name: string } | undefined', summary: 'Whether the calling agent has a tool by this name. Answers only inside a live tool call, for that call\'s own agent.' },
24 { name: 'guard', signature: 'guard(fn: (exec: ToolExec) => string | { kind?: \'deny\', reason: string } | undefined): () => void', summary: 'Register a deny-only tool guard through the tools/pre-execute admission path. Can deny or abstain, never auto-approve.' },
25 ],
26 },
27 commands: {
28 summary: 'Slash commands a person types. A handler runs only when the person types the command.',
29 availability: 'always',
30 methods: [
31 { name: 'register', signature: 'register(definition: { name: string, description: string, argumentHint?: string, handler(call: { args: string, signal: AbortSignal }): CommandResult }): () => void', summary: 'Register one slash command. Names start with a lower case letter, then lower case letters, digits, _ and -, at most 64 characters; at most 64 commands per plugin. A name that clashes with a built-in command gets the alias plugin-<plugin-slug>-<command>, and is refused if that alias is invalid or also taken. A name another plugin already registered is refused, so pick a plugin-specific name. Returns an idempotent disposer.' },
32 ],
33 },
34 storage: {
35 summary: 'Owner-local JSON persistence under the data folder the Engine assigned. It holds no session history and no secrets.',
36 availability: 'always',
37 methods: [
38 { name: 'get', signature: 'get(key: string): Promise<Json | undefined>', summary: 'Read one stored value.' },
39 { name: 'set', signature: 'set(key: string, value: Json): Promise<void>', summary: 'Store one JSON value, within the bounded key, value and owner limits.' },
40 { name: 'delete', signature: 'delete(key: string): Promise<void>', summary: 'Remove one stored value.' },
41 ],
42 },
43 skills: {
44 summary: 'Skill roots: reviewed folders of skills added to the Engine\'s skill catalog.',
45 availability: 'always',
46 methods: [
47 { name: 'registerRoot', signature: 'registerRoot(definition: { path: string }): () => void', summary: 'Add a bundle-relative folder of SKILL.md packages. At most 8 roots per plugin. Absolute paths, links, empty components, . and .. are refused.' },
48 ],
49 },
50 sessions: {
51 summary: 'The session of the calling tool invocation.',
52 availability: 'tool-invocation',
53 methods: [
54 { name: 'flush', signature: 'flush(session: Session): Promise<boolean>', summary: 'Ask the Engine to persist the committed prefix of the exact session of this tool call. Nothing else on sessions is available.' },
55 ],
56 },
57 userQuestions: {
58 summary: 'Questions put to the person through the Engine\'s own question card.',
59 availability: 'tool-invocation',
60 methods: [
61 { name: 'ask', signature: 'ask(request: { agent: Agent, questions: Question[], signal?: AbortSignal }): Promise<Answers>', summary: 'Ask the person typed questions during a live root tool call. Timed or continued questions (wait) are not supported.' },
62 ],
63 },
64 subagents: {
65 summary: 'One independent child agent a root tool call may start.',
66 availability: 'tool-invocation',
67 methods: [
68 { name: 'getProvider', signature: 'getProvider(id: \'spawn\'): Provider', summary: 'Describe the one provider: a fresh child with no inherited conversation.' },
69 { name: 'startActivation', signature: 'startActivation(options: { provider: \'spawn\', childId: string, request: { parent: Agent, prompt: TextBlock[], agentOptions?: { model?: string } }, signal?: AbortSignal, delivery?: \'caller\' | \'parent\' }): Promise<{ childId: string, messageId: string, result: Promise<ChildResult>, dispose(): Promise<void> }>', summary: 'Start the child through the Engine\'s approval gate. Resolves to the activation handle { childId, messageId, result, dispose }. Prompts are text only; only the model option is accepted. Needs the live calling agent as parent and is not available inside a child.' },
70 { name: 'result', signature: 'activation.result: Promise<{ stopReason: string, output: { type: \'text\', text: string }[], diagnostic?: string }>', summary: 'A getter, not a method: read the property, do not call it. Resolves when the child finishes, with its stop reason and its text output blocks; diagnostic notes dropped non-text blocks.' },
71 { name: 'dispose', signature: 'activation.dispose(): Promise<void>', summary: 'Stop that exact child and its own descendants.' },
72 ],
73 },
74 agents: {
75 summary: 'Reserved. The host offers no methods on agents.',
76 availability: 'none',
77 methods: [],
78 },
79 systemPrompt: {
80 summary: 'The child agent\'s persona slot, reachable only inside an agent/created listener.',
81 availability: 'child-agent-hook',
82 methods: [
83 { name: 'section', signature: 'agent.ctx.systemPrompt.section({ name: \'deployment:persona-prefix\', order: agent.ctx.systemPrompt.getSectionOrder(\'DEPLOYMENT_PERSONA_PREFIX\'), text: string }): () => void', summary: 'Set the child\'s persona text, at most 32 KiB, once. name must be the string deployment:persona-prefix (the PERSONA_PREFIX_SECTION value) and order must be what getSectionOrder(\'DEPLOYMENT_PERSONA_PREFIX\') returns, which is 0. Anything else is refused. Called anywhere else it fails. The Engine\'s own system prompt cannot be replaced.' },
84 ],
85 },
86 logger: {
87 summary: 'Cordis logging. Every line becomes a host log notification attributed to the plugin.',
88 availability: 'always',
89 cordis: true,
90 methods: [
91 { name: 'logger', signature: 'ctx.logger(name?: string): Logger', summary: 'A named logger with debug, info, warn and error. The host reports error and warn as such and everything else as info.' },
92 ],
93 },
94 events: {
95 summary: 'Cordis event dispatch. Query the host Event provider for the events this host fires.',
96 availability: 'always',
97 cordis: true,
98 methods: [
99 { name: 'on', signature: 'ctx.on(name: string, listener: Function, options?: boolean | { prepend?: boolean, global?: boolean }): () => boolean', summary: 'Listen to an event. The host refuses five lifecycle events and limits the options of two (see the Event provider).' },
100 { name: 'once', signature: 'ctx.once(name: string, listener: Function, options?: boolean | { prepend?: boolean, global?: boolean }): () => boolean', summary: 'Listen to an event once.' },
101 { name: 'emit', signature: 'ctx.emit(name: string, ...args: any[]): void', summary: 'Dispatch an event to its listeners.' },
102 ],
103 },
104 reflect: {
105 summary: 'Cordis service reflection. A plugin may provide its own services but not the Engine\'s.',
106 availability: 'always',
107 cordis: true,
108 methods: [
109 { name: 'provide', signature: 'ctx.reflect.provide(name: string, value?: any): () => void', summary: 'Provide a service under a name. Names in refusedServices are refused: the Engine owns them.' },
110 { name: 'get', signature: 'ctx.reflect.get(name: string, strict?: boolean): any', summary: 'Read a provided service.' },
111 ],
112 },
113 registry: {
114 summary: 'Cordis plugin registry.',
115 availability: 'always',
116 cordis: true,
117 methods: [
118 { name: 'get', signature: 'ctx.registry.get(plugin: Plugin): Runtime | undefined', summary: 'Look up the runtime record of a plugin.' },
119 { name: 'resolve', signature: 'ctx.registry.resolve(plugin: Plugin): Function | undefined', summary: 'Resolve a plugin shape to its callback.' },
120 ],
121 },
122 prompt: {
123 summary: 'Attributed sections of the Engine\'s runtime prompt. A plugin cannot replace the system prompt.',
124 availability: 'always',
125 methods: [
126 { name: 'registerSection', signature: 'registerSection(definition: { id: string, text: string, interpolate?: \'model-cwd\' }): () => void', summary: 'Contribute a plain-text section of at most 4 KiB; at most 128 sections per plugin. The id is lower case letters, digits, _ and -, starts with a letter, at most 64 characters. With interpolate set, only {{model}} and {{cwd}} are expanded.' },
127 ],
128 },
129 avatars: {
130 summary: 'Avatar packs for the terminal.',
131 availability: 'always',
132 methods: [
133 { name: 'registerPack', signature: 'registerPack(definition: { path: string }): () => void', summary: 'Register a reviewed bundle-relative avatar pack: a path ending in .json, at most 4 packs per plugin.' },
134 ],
135 },
136 mcp: {
137 summary: 'Proposals of MCP servers. The Engine owns connection, credentials and tool calls.',
138 availability: 'native-review',
139 methods: [
140 { name: 'registerServer', signature: 'registerServer(definition: { serverName: string, server: Record<string, unknown> }): () => void', summary: 'Propose one server. serverName is a letter or digit followed by up to 31 letters, digits, _ or -. headers and env must stay empty and the url may carry no credentials, query or fragment. At most 64 servers per plugin; at most 64 KiB per definition.' },
141 ],
142 },
143 shellHooks: {
144 summary: 'Claude Code and Codex style command hooks, run by the Engine.',
145 availability: 'native-review',
146 methods: [
147 { name: 'register', signature: 'register(definition: { dialect: \'claude-code\' | \'codex\', point: string, matcher?: string, hook: { event: string, command: string, timeout_secs: number, background: false, continue_on_error: false, name: string } }): () => void', summary: 'Register one command hook for a reviewed native plugin. Forced continuation, observer steering, non-command and asynchronous hooks are not supported.' },
148 ],
149 },
150 remote: {
151 summary: 'Remote pairing, served by the Engine.',
152 availability: 'review-grant',
153 methods: [
154 { name: 'status', signature: 'status(): Promise<Status>', summary: 'Whether remote access is on.' },
155 { name: 'pair', signature: 'pair(options?: { label?: string }): Promise<Pairing>', summary: 'Start a pairing.' },
156 { name: 'clients', signature: 'clients(): Promise<Client[]>', summary: 'List paired clients.' },
157 { name: 'revoke', signature: 'revoke(id: string): Promise<void>', summary: 'Revoke one grant by the id pair returned.' },
158 ],
159 },
160 workspace: {
161 summary: 'Bounded workspace file reads, writes, directory listings, and approved command execution.',
162 availability: 'review-grant',
163 methods: [
164 { name: 'read', signature: 'read(path: string, options?: { startLine?: number, maxLines?: number }): Promise<string>', summary: 'Read a file inside the reviewed workspace root.' },
165 { name: 'list', signature: 'list(path?: string): Promise<WorkspaceEntry[]>', summary: 'List entries under a workspace directory.' },
166 { name: 'write', signature: 'write(path: string, content: string): Promise<void>', summary: 'Write a file inside the reviewed workspace root.' },
167 { name: 'exec', signature: 'exec(argv: string[], options?: { cwd?: string, timeoutMs?: number }): Promise<ExecResult>', summary: 'Run a reviewed command inside the workspace.' },
168 ],
169 },
170 llm: {
171 summary: 'Host-mediated model catalog lookup, completions, and streaming.',
172 availability: 'review-grant',
173 methods: [
174 { name: 'catalog', signature: 'catalog(options?: { provider?: string }): Promise<ModelCatalog>', summary: 'List available providers and models.' },
175 { name: 'complete', signature: 'complete(request: LlmRequest): Promise<LlmResponse>', summary: 'Run a single non-streaming completion through Core.' },
176 { name: 'listModels', signature: 'listModels(provider?: string): Promise<ModelSummary[]>', summary: 'List model entries with context and modality metadata.' },
177 { name: 'resolveModelInfo', signature: 'resolveModelInfo(modelId: string): Promise<ModelSummary | null>', summary: 'Look up metadata for one model identifier.' },
178 { name: 'stream', signature: 'stream(request: LlmRequest): AsyncIterable<LlmChunk>', summary: 'Stream completion chunks through Core.' },
179 ],
180 },
181 credentials: {
182 summary: 'Reviewed credential resolution and host-guarded HTTP fetch.',
183 availability: 'review-grant',
184 methods: [
185 { name: 'resolve', signature: 'resolve(key: string, options?: Record<string, unknown>): Promise<CredentialValue>', summary: 'Resolve an approved credential key.' },
186 { name: 'describe', signature: 'describe(key: string): Promise<CredentialMeta>', summary: 'Inspect metadata for a credential key.' },
187 { name: 'set', signature: 'set(key: string, secret: string, options?: Record<string, unknown>): Promise<void>', summary: 'Store a secret in Codewhale credential storage.' },
188 { name: 'fetch', signature: 'fetch(input: string, init?: FetchInit): Promise<FetchResponse>', summary: 'Perform a policy-checked outbound HTTP request.' },
189 ],
190 },
191 settings: {
192 summary: 'Reviewed read/write access to declared Codewhale plugin settings.',
193 availability: 'review-grant',
194 methods: [
195 { name: 'describe', signature: 'describe(keys?: string[]): Promise<Record<string, unknown>>', summary: 'Read reviewed setting values and schemas.' },
196 { name: 'update', signature: 'update(patch: Record<string, unknown>, options?: Record<string, unknown>): Promise<void>', summary: 'Merge partial updates into allowed settings.' },
197 { name: 'replace', signature: 'replace(patch: Record<string, unknown>, options?: Record<string, unknown>): Promise<void>', summary: 'Replace reviewed setting keys atomically.' },
198 { name: 'mutate', signature: 'mutate(fn: (current: Record<string, unknown>) => Record<string, unknown>): Promise<void>', summary: 'Apply a synchronous transform to reviewed settings.' },
199 ],
200 },
201 pluginManager: {
202 summary: 'Reviewed plugin installation and removal requests through Core.',
203 availability: 'review-grant',
204 methods: [
205 { name: 'installBundle', signature: 'installBundle(packageName: string, options?: Record<string, unknown>): Promise<unknown>', summary: 'Request Core to preview or install a plugin bundle.' },
206 { name: 'removeBundle', signature: 'removeBundle(packageName: string): Promise<void>', summary: 'Request Core to remove an installed plugin bundle.' },
207 { name: 'cancelInstall', signature: 'cancelInstall(): Promise<void>', summary: 'Cancel an active plugin installation request.' },
208 ],
209 },
210 deepseekAccount: {
211 summary: 'DeepSeek account balance queries through the authenticated provider.',
212 availability: 'review-grant',
213 methods: [
214 { name: 'getBalance', signature: 'getBalance(options?: Record<string, unknown>): Promise<AccountBalance>', summary: 'Fetch the active DeepSeek account balance.' },
215 ],
216 },
217 terminal: {
218 summary: 'Reviewed interactive terminal sessions inside the workspace.',
219 availability: 'review-grant',
220 methods: [
221 { name: 'list', signature: 'list(): Promise<TerminalSession[]>', summary: 'List active terminal sessions for this owner.' },
222 { name: 'run', signature: 'run(options?: { argv?: string[], cwd?: string }): Promise<TerminalSession>', summary: 'Start a terminal session in the workspace.' },
223 { name: 'send', signature: 'send(id: string, data: string): Promise<void>', summary: 'Write input to a running terminal session.' },
224 { name: 'wait', signature: 'wait(id: string, options?: { timeoutMs?: number }): Promise<TerminalExit>', summary: 'Wait for output or completion from a terminal session.' },
225 { name: 'cancel', signature: 'cancel(id: string): Promise<void>', summary: 'Terminate a running terminal session.' },
226 { name: 'reset', signature: 'reset(id: string): Promise<void>', summary: 'Reset a terminal session buffer.' },
227 ],
228 },
229 attachments: {
230 summary: 'Conversation image validation, storage, and bounded read/resize through the Engine.',
231 availability: 'review-grant',
232 methods: [
233 { name: 'validateImage', signature: 'validateImage(input: ImageBytesInput, signal?: AbortSignal): Promise<ValidateImageResult>', summary: 'Validate an image payload against Codewhale image limits.' },
234 { name: 'saveImage', signature: 'saveImage(input: ImageBytesInput, signal?: AbortSignal): Promise<StoredImageAttachmentRef>', summary: 'Store a validated conversation image attachment for the active tool result.' },
235 { name: 'readImage', signature: 'readImage(ref: ImageAttachmentRef, signal?: AbortSignal): Promise<ReadImageResult>', summary: 'Read a stored conversation image by attachment reference.' },
236 { name: 'readImageRequest', signature: 'readImageRequest(ref: ImageAttachmentRef, target?: ReadImageRequestTarget, signal?: AbortSignal): Promise<ReadImageRequestResult>', summary: 'Read a resized/fitted variant of a stored conversation image.' },
237 ],
238 },
239 agentPresets: {
240 summary: 'Reviewed read-only agent preset catalog scoped to the owning plugin.',
241 availability: 'always',
242 methods: [
243 { name: 'list', signature: 'list(): Promise<AgentPreset[]>', summary: 'List reviewed presets visible to this owner.' },
244 { name: 'get', signature: 'get(id: string): Promise<AgentPreset | undefined>', summary: 'Look up one reviewed preset by id.' },
245 { name: 'register', signature: 'register(preset: AgentPreset): () => void', summary: 'Register an owner-scoped preset metadata entry.' },
246 ],
247 },
248 agentDefaultModel: {
249 summary: 'Read-only view of the active invocation default model selection.',
250 availability: 'tool-invocation',
251 methods: [
252 { name: 'currentSelection', signature: 'currentSelection(): { provider: string, model: string } | undefined', summary: 'Return the read-only default provider/model for the live invocation.' },
253 ],
254 },
255 sessionProjections: {
256 summary: 'Read-only projection of active session messages and events.',
257 availability: 'tool-invocation',
258 methods: [
259 { name: 'get', signature: 'get(sessionId?: string): SessionProjection | undefined', summary: 'Return the read-only projection for the active session.' },
260 { name: 'list', signature: 'list(): SessionProjection[]', summary: 'List read-only session projections visible to the live invocation.' },
261 ],
262 },
263 workspaceRegistry: {
264 summary: 'Read-only workspace metadata for the active invocation.',
265 availability: 'tool-invocation',
266 methods: [
267 { name: 'list', signature: 'list(): WorkspaceMeta[]', summary: 'List read-only workspace metadata visible to the live invocation.' },
268 { name: 'get', signature: 'get(id: string): WorkspaceMeta | undefined', summary: 'Look up read-only workspace metadata by id or path.' },
269 { name: 'resolveByPath', signature: 'resolveByPath(path: string): WorkspaceMeta | undefined', summary: 'Resolve read-only workspace metadata by filesystem path.' },
270 ],
271 },
272 typertGateway: {
273 summary: 'Owner-scoped Typert service descriptor registry.',
274 availability: 'always',
275 methods: [
276 { name: 'register', signature: 'register(name: string, service: unknown, descriptors?: unknown[]): () => void', summary: 'Register an owner-scoped Typert service and its descriptors.' },
277 { name: 'list', signature: 'list(): string[]', summary: 'List Typert service names registered by this owner.' },
278 { name: 'get', signature: 'get(name: string): { service: unknown, descriptors: unknown[] } | undefined', summary: 'Look up a registered Typert service by name.' },
279 ],
280 },
281 web: {
282 summary: 'Network-policy-guarded web fetch and owner-scoped search provider registration.',
283 availability: 'review-grant',
284 methods: [
285 { name: 'fetch', signature: 'fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>', summary: 'Perform a policy-checked outbound HTTP request through the Engine network broker.' },
286 { name: 'registerSearchProvider', signature: 'registerSearchProvider(provider: SearchProvider): () => void', summary: 'Register an owner-scoped web search provider.' },
287 ],
288 },
289 webServer: {
290 summary: 'Sandboxed Engine-brokered in-memory HTTP route registry (no raw sockets).',
291 availability: 'always',
292 methods: [
293 { name: 'register', signature: 'register(route: { kind?: \'exact\' | \'prefix\', path: string, method?: string, methods?: string[], handler: (req, res) => void | Promise<void> }): () => void', summary: 'Register an owner-scoped HTTP route dispatched through Engine plugin_route/dispatch.' },
294 { name: 'getOrigin', signature: 'getOrigin(): string', summary: 'Return the loopback origin advertised to the plugin.' },
295 ],
296 },
297 connection: {
298 summary: 'Scoped loopback connection status, trust fence, Fetch route registry, and RPC channel registry.',
299 availability: 'always',
300 methods: [
301 { name: 'requestRejection', signature: 'requestRejection(req?: { headers?: Record<string, string | string[] | undefined> }): { status: number, message: string } | null', summary: 'Verify loopback Host and non-cross-site Fetch metadata.' },
302 { name: 'fetch.register', signature: 'fetch.register(route: { path: string, methods?: string[], fetch: (req: Request) => Response | Promise<Response> }): () => void', summary: 'Register an owner-scoped Fetch-style route handler.' },
303 { name: 'rpc.handle', signature: 'rpc.handle(channel: string, handler: (endpoint: string, payload: unknown) => unknown | Promise<unknown>): () => void', summary: 'Register an owner-scoped JSON RPC channel handler.' },
304 ],
305 },
306 sessionTitle: {
307 summary: 'Owner-scoped in-memory session title store and rename observer.',
308 availability: 'always',
309 methods: [
310 { name: 'get', signature: 'get(session: unknown): string | undefined', summary: 'Read a session title stored by this owner.' },
311 { name: 'rename', signature: 'rename(session: unknown, title: string): string', summary: 'Store a bounded single-line title for a session under this owner.' },
312 { name: 'register', signature: 'register(listener: (sessionId: string, title: string) => void): () => void', summary: 'Observe session title updates within this owner.' },
313 ],
314 },
315 profileContext: {
316 summary: 'Read-only owner-scoped profile directory metadata.',
317 availability: 'always',
318 methods: [
319 { name: 'dir', signature: 'get dir(): string', summary: 'Return the owner\'s scoped data directory (fails closed when absent).' },
320 { name: 'installAnchor', signature: 'get installAnchor(): string', summary: 'Return the owner\'s scoped install anchor directory.' },
321 ],
322 },
323 sessionPersistence: {
324 summary: 'Read-only session log lookup surface; Core owns durable session logs and refuses plugin mutations.',
325 availability: 'always',
326 methods: [
327 { name: 'findLog', signature: 'findLog(id?: unknown): Promise<undefined>', summary: 'Resolve undefined; host session logs are not exposed on disk to plugins.' },
328 { name: 'listLogs', signature: 'listLogs(): Promise<readonly unknown[]>', summary: 'Return an empty frozen list.' },
329 { name: 'readLog', signature: 'readLog(id?: unknown): Promise<undefined>', summary: 'Resolve undefined; host session logs are private to Core.' },
330 { name: 'artifactDirectory', signature: 'artifactDirectory(headerOrId?: unknown): undefined', summary: 'Return undefined; host session directories are private to Core.' },
331 ],
332 },
333 storageDomain: {
334 summary: 'Owner-scoped, bounded in-memory structured storage domains isolated per plugin.',
335 availability: 'always',
336 methods: [
337 { name: 'open', signature: 'open(spec: { name: string } | string): Promise<ScopedStorageDomainHandle>', summary: 'Open an owner-scoped in-memory storage domain with bounded tables and entries.' },
338 { name: 'get', signature: 'get(name: string): ScopedStorageDomainHandle | undefined', summary: 'Look up an already-opened domain for this owner.' },
339 { name: 'list', signature: 'list(): readonly string[]', summary: 'List domains currently opened by this owner.' },
340 ],
341 },
342 invariants: {
343 summary: 'Owner-scoped invariant registration table cleaned up on plugin disposal.',
344 availability: 'always',
345 methods: [
346 { name: 'register', signature: 'register(name: string, install?: unknown): () => void', summary: 'Register a named invariant under this owner and return a disposer.' },
347 { name: 'list', signature: 'list(): readonly string[]', summary: 'List invariant names registered by this owner.' },
348 ],
349 },
350 permissionPresets: {
351 summary: 'Read-only catalog of Codewhale permission posture names; Core owns approval authority.',
352 availability: 'always',
353 methods: [
354 { name: 'availability', signature: 'get availability(): \'readonly\'', summary: 'Report that permission presets are read-only.' },
355 { name: 'defaultPreset', signature: 'get defaultPreset(): string', summary: 'Return the default posture name (\'ask\').' },
356 { name: 'names', signature: 'get names(): readonly string[]', summary: 'List Codewhale permission posture names.' },
357 { name: 'list', signature: 'list(): readonly { name: string, readonly: boolean }[]', summary: 'List read-only permission preset descriptors.' },
358 { name: 'get', signature: 'get(name: string): { name: string, readonly: boolean } | undefined', summary: 'Look up one permission preset descriptor by name.' },
359 ],
360 },
361 }
362
363 const AVAILABILITY = {
364 always: 'Available to every plugin that injects it.',
365 'tool-invocation': 'Answers only inside a live tool call of the plugin.',
366 'child-agent-hook': 'Answers only inside an agent/created listener, on the child agent.',
367 'native-review': 'Available to a reviewed native plugin.',
368 'review-grant': 'Served by the Engine only when the plugin\'s review granted it.',
369 none: 'No methods.',
370 }
371
372 const EVENTS_SUPPORTED = [
373 {
374 name: 'tools/pre-execute',
375 status: 'supported',
376 mode: 'ordered listeners, native hooks first, then plugin listeners in registration order',
377 signature: 'ctx.on(\'tools/pre-execute\', async (exec: { name: string, callId: string, arguments: object, signal: AbortSignal, workspace: string, mode: string, model: string }, next: () => Promise<Abstention>) => Verdict | undefined)',
378 summary: 'Programmable tool admission for a reviewed native plugin. The frozen call view has no session, agent, tool or approval handle. Return { kind: \'deny\', reason }, { kind: \'ask\', reason? }, { kind: \'revise\', input }, { kind: \'annotate\', text } or { kind: \'abstain\' }; undefined abstains. A malformed answer, error or timeout fails the call closed. The listener batch has a five second deadline.',
379 options: 'prepend and global are refused.',
380 },
381 {
382 name: 'tools/post-execute',
383 status: 'supported',
384 mode: 'read-only observers in registration order, after the tool finishes',
385 signature: 'ctx.on(\'tools/post-execute\', async (exec: { name: string, callId: string, arguments: { is_error: boolean, duration_ms: number }, signal: AbortSignal, workspace: string, mode: string, model: string }, next: () => Promise<Abstention>) => void)',
386 summary: 'Observes a finished tool call for a reviewed native plugin. The view carries only whether the call failed and how long it took, never its output, session or agent. The return value is ignored and an error is logged, so an observer cannot change or fail the call. The listener batch has a five second deadline.',
387 options: 'prepend and global are refused.',
388 },
389 {
390 name: 'tools/result',
391 status: 'supported',
392 mode: 'read-only observers in registration order, after the tool finishes',
393 signature: 'ctx.on(\'tools/result\', async (exec: { name: string, callId: string, arguments: { is_error: boolean, duration_ms: number }, signal: AbortSignal, workspace: string, mode: string, model: string }, next: () => Promise<Abstention>) => void)',
394 summary: 'Alias for read-only tool outcome observation backed by tools/post-execute. Cannot mutate or veto execution.',
395 options: 'prepend and global are refused.',
396 },
397 {
398 name: 'agent/created',
399 status: 'supported',
400 mode: 'listeners of the owning plugin only',
401 signature: 'ctx.on(\'agent/created\', async ({ agent }: { agent: { id: string, ctx: { systemPrompt: { getSectionOrder(name), section(section) }, tools: { restrict(filter: { deny: string[] }) } } } }) => void)',
402 summary: 'Fires for a child agent that this plugin\'s own subagents.startActivation creates, before the child starts. The listener may set the child\'s persona and deny tools to it; the window closes when the listeners return.',
403 options: 'global is refused.',
404 },
405 ]
406
407 const REFUSED_EVENT_REASON = 'Not projected by this host: no core projection exists, so a listener would never fire.'
408
409 const ROW_PACKAGES = {
410 '@deepseek-ai/dsh-mcp-client': {
411 summary: 'An MCP server row. The Engine proposes the server and owns the connection.',
412 schema: {
413 type: 'object',
414 additionalProperties: false,
415 required: ['transport', 'serverName'],
416 properties: {
417 transport: { type: 'string', enum: ['stdio', 'streamable-http', 'sse'] },
418 serverName: { type: 'string', pattern: '^[A-Za-z0-9][A-Za-z0-9_-]{0,31}$' },
419 command: { type: 'string', description: 'stdio only: the program to run.' },
420 args: { type: 'array', items: { type: 'string' }, description: 'stdio only.' },
421 env: { type: 'object', maxProperties: 0, description: 'Must be empty or absent: credentials stay with the Engine.' },
422 cwd: { type: 'string', description: 'stdio only: a bundle-relative directory, no .. components.' },
423 url: { type: 'string', description: 'streamable-http and sse: the endpoint, with no credentials, query or fragment.' },
424 headers: { type: 'object', maxProperties: 0, description: 'Must be empty or absent: credentials stay with the Engine.' },
425 toolCallTimeoutMs: { type: 'integer', minimum: 1000, maximum: 86400000, multipleOf: 1000 },
426 failOnStartupError: { type: 'boolean', description: 'When true, install and enable connect the server first and report failure if it cannot start; when false or absent, the Engine connects lazily and reports failures through /mcp.' },
427 },
428 },
429 limits: ['stdio rows name a command; streamable-http and sse rows name a url.', 'Reconnect and instruction bounds belong to the Engine and are not configurable here.'],
430 example: { transport: 'stdio', serverName: 'docs', command: 'node', args: ['server.js'], cwd: '.' },
431 },
432 '@deepseek-ai/dsh-skill-filesystem': {
433 summary: 'A skill folder row, limited to reviewed roots inside the bundle.',
434 schema: {
435 type: 'object',
436 additionalProperties: false,
437 required: ['includeDefaultRoots', 'watch', 'customSkillDirs'],
438 properties: {
439 providerName: { type: 'string', maxLength: 64 },
440 includeDefaultRoots: { type: 'boolean', const: false, description: 'Must be false: ambient roots are not read.' },
441 watch: { type: 'boolean', const: false, description: 'Must be false: there is no file watcher.' },
442 customSkillDirs: { type: 'array', minItems: 1, maxItems: 8, items: { type: 'string' }, description: 'Bundle-relative skill roots, no duplicates.' },
443 },
444 },
445 limits: ['Both includeDefaultRoots and watch must be written out as false.'],
446 example: { includeDefaultRoots: false, watch: false, customSkillDirs: ['skills'] },
447 },
448 '@deepseek-ai/dsh-hooks-claude-code': {
449 summary: 'Claude Code style command hooks read from a reviewed file in the bundle.',
450 schema: {
451 type: 'object',
452 additionalProperties: true,
453 required: ['configPath'],
454 properties: {
455 configPath: { type: 'string', description: 'A regular file inside the bundle, at most 1 MiB, unchanged since review.' },
456 pluginRoot: { type: 'string', description: 'Absent, ".", or this reviewed bundle root.' },
457 defaultTimeoutMs: { type: 'integer', minimum: 1000, maximum: 86400000, multipleOf: 1000, description: 'Whole seconds, used when a hook sets none; default 600000.' },
458 },
459 },
460 limits: ['projectDir is refused: each process uses the current workspace.', 'Only command hooks run; non-command and asynchronous hooks fail the row.', 'At most 128 commands per row.'],
461 example: { configPath: 'hooks/hooks.json' },
462 },
463 '@deepseek-ai/dsh-hooks-codex': {
464 summary: 'Codex style command hooks read from a reviewed file in the bundle.',
465 schema: {
466 type: 'object',
467 additionalProperties: true,
468 required: ['configPath'],
469 properties: {
470 configPath: { type: 'string', description: 'A regular file inside the bundle, at most 1 MiB, unchanged since review.' },
471 pluginRoot: { type: 'string', description: 'Absent, ".", or this reviewed bundle root.' },
472 defaultTimeoutMs: { type: 'integer', minimum: 1000, maximum: 86400000, multipleOf: 1000, description: 'Whole seconds, used when a hook sets none; default 600000.' },
473 },
474 },
475 limits: ['projectDir is refused: each process uses the current workspace.', 'Only command hooks run; non-command and asynchronous hooks fail the row.', 'At most 128 commands per row.'],
476 example: { configPath: 'hooks/hooks.json' },
477 },
478 '@deepseek-ai/dsh-persona': {
479 summary: 'Text added before and after the Engine\'s own prompt for this plugin\'s entry.',
480 schema: {
481 type: 'object',
482 additionalProperties: false,
483 required: ['prefix'],
484 properties: {
485 prefix: { type: 'string', description: 'At most 4096 UTF-8 bytes, no control characters. Only {{model}} and {{cwd}} are expanded.' },
486 suffix: { type: 'string', description: 'Same limits as prefix.' },
487 complete: { type: 'boolean', const: false, description: 'Replacing the whole prompt belongs to the Engine.' },
488 includeRuntimeContext: { type: 'boolean', const: true, description: 'Suppressing the runtime context belongs to the Engine.' },
489 },
490 },
491 limits: ['Needs an exact Engine-selected entry scope.'],
492 example: { prefix: 'Answer in short sentences.' },
493 },
494 '@deepseek-ai/dsh-storage': {
495 summary: 'Storage row bridge satisfied natively by the Engine spine.',
496 schema: { type: 'object', additionalProperties: true },
497 limits: ['Served natively by the Codewhale Engine spine; row configuration is inert.'],
498 example: {},
499 },
500 '@deepseek-ai/dsh-storage-json': {
501 summary: 'JSON storage row bridge satisfied natively by the Engine spine.',
502 schema: { type: 'object', additionalProperties: true },
503 limits: ['Served natively by the Codewhale Engine spine; row configuration is inert.'],
504 example: {},
505 },
506 '@deepseek-ai/dsh-storage-domain': {
507 summary: 'Domain storage row bridge satisfied natively by the Engine spine.',
508 schema: { type: 'object', additionalProperties: true },
509 limits: ['Served natively by the Codewhale Engine spine; row configuration is inert.'],
510 example: {},
511 },
512 '@deepseek-ai/dsh-workspace': {
513 summary: 'Workspace row bridge satisfied natively by the Engine spine.',
514 schema: { type: 'object', additionalProperties: true },
515 limits: ['Served natively by the Codewhale Engine spine; row configuration is inert.'],
516 example: {},
517 },
518 '@deepseek-ai/dsh-code-runtime-worker-thread': {
519 summary: 'Worker-thread runtime row bridge satisfied natively by the Engine spine.',
520 schema: { type: 'object', additionalProperties: true },
521 limits: ['Served natively by the Codewhale Engine spine; row configuration is inert.'],
522 example: {},
523 },
524 '@deepseek-ai/dsh-tool-subagent/model-selection-settings': {
525 summary: 'Subagent model-selection settings row bridge satisfied natively by the Engine spine.',
526 schema: { type: 'object', additionalProperties: true },
527 limits: ['Served natively by the Codewhale Engine spine; row configuration is inert.'],
528 example: {},
529 },
530 '@deepseek-ai/dsh-agent-preset-registry': {
531 summary: 'Agent-preset registry row bridge satisfied natively by the Engine spine.',
532 schema: { type: 'object', additionalProperties: true },
533 limits: ['Served natively by the Codewhale Engine spine; row configuration is inert.'],
534 example: {},
535 },
536 '@deepseek-ai/dsh-cordis-host-runner': {
537 summary: 'Host-runner row bridge satisfied natively by the Engine spine.',
538 schema: { type: 'object', additionalProperties: true },
539 limits: ['Served natively by the Codewhale Engine spine; row configuration is inert.'],
540 example: {},
541 },
542 '@deepseek-ai/dsh-host-webserver': {
543 summary: 'Host webserver row bridge satisfied natively by the Engine spine.',
544 schema: { type: 'object', additionalProperties: true },
545 limits: ['Served natively by the Codewhale Engine spine; row configuration is inert.'],
546 example: {},
547 },
548 }
549
550 const THEME = {
551 tokens: [],
552 colorSchemes: ['light', 'dark'],
553 scheme: 'The frame sets data-theme and color-scheme on its document to the app\'s current scheme and follows changes.',
554 api: [
555 { name: 'ctx.theme.getTheme', signature: 'getTheme(): { active: { colorScheme: \'light\' | \'dark\' } }', summary: 'The scheme in use now.' },
556 { name: 'ctx.theme.overrideTokens', signature: 'overrideTokens(source: string, tokens: Record<string, { light: string, dark: string }>): () => void', summary: 'Set custom properties on the frame\'s document for each scheme. source is at most 256 characters; each name starts with -- and is at most 128 characters; each value is at most 512 characters. Returns a disposer.' },
557 ],
558 notes: [
559 'The frame defines no named design tokens of its own. There are no --dsw-* tokens to read: a plugin that wants tokens defines them with overrideTokens and uses them in its own styles.',
560 'The frame\'s background is transparent and its margin is zero, so the plugin sits on the app\'s own surface.',
561 ],
562 }
563
564 const SEAT_NOTES = {
565 'customize.plugins.detail': { drawn: true, where: 'The plugin\'s own page under Customize, Plugins.' },
566 'conversation.composer.dock': { drawn: false, where: 'Under the composer. The desktop app does not place it yet.' },
567 'conversation.chat.node': { drawn: false, where: 'Inside the conversation. The desktop app does not place it yet.' },
568 'workpane.panel': { drawn: false, where: 'The work pane. The desktop app does not place it yet.' },
569 'sidebar.section': { drawn: false, where: 'The sidebar. The desktop app does not place it yet.' },
570 'command.row': { drawn: false, where: 'The command list. The desktop app does not place it yet.' },
571 }
572
573 function between(text, open, close, what) {
574 const start = text.indexOf(open)
575 if (start < 0) throw new Error(`${what}: cannot find ${open}`)
576 const end = text.indexOf(close, start + open.length)
577 if (end < 0) throw new Error(`${what}: cannot find the end of ${open}`)
578 return text.slice(start + open.length, end)
579 }
580
581 export function parseSeatTable(source) {
582 const text = source.replace(/\r\n/g, '\n')
583 const constants = Object.fromEntries([...text.matchAll(/const ([A-Z_]+): &str = "([^"]+)";/g)].map((m) => [m[1], m[2]]))
584 const resolve = (literal, name) => literal !== undefined ? literal : constants[name]
585 const seatBlock = between(text, 'const PLUGIN_UI_SEATS: [&str; ', '];', 'seat list')
586 const declaredSeats = Number(seatBlock.slice(0, seatBlock.indexOf(']')))
587 const seatBody = seatBlock.slice(seatBlock.indexOf('= [') + 3)
588 const seats = [...seatBody.matchAll(/"([^"]+)"|([A-Z_]+)/g)].map((m) => resolve(m[1], m[2]))
589 if (seats.length !== declaredSeats || seats.some((seat) => seat === undefined)) throw new Error('the seat list does not match its declared length')
590 const tableBlock = between(text, 'const DSH_SEAT_TABLE: [(&str, DshSeat); ', '];\n', 'slot table')
591 const declaredSlots = Number(tableBlock.slice(0, tableBlock.indexOf(']')))
592 const tableBody = tableBlock.slice(tableBlock.indexOf('= [') + 3)
593 const slots = [...tableBody.matchAll(/\(\s*"([^"]+)",\s*DshSeat::(Seat|Unsupported)\(\s*(?:"([^"]*)"|([A-Z_]+))\s*\)\s*,?\s*\)/g)].map((m) => {
594 const value = resolve(m[3], m[4])
595 return m[2] === 'Seat' ? { slot: m[1], seat: value, supported: true } : { slot: m[1], seat: null, supported: false, reason: value }
596 })
597 if (slots.length !== declaredSlots) throw new Error(`the slot table declares ${declaredSlots} rows and ${slots.length} were read`)
598 for (const slot of slots) if (slot.supported && !seats.includes(slot.seat)) throw new Error(`slot ${slot.slot} maps to ${slot.seat}, which is not a seat`)
599 return { seats, slots }
600 }
601
602 export function parseRefusedEvents(source) {
603 const text = source.replace(/\r\n/g, '\n')
604 const body = between(text, 'const unsupportedDshLifecycle = new Set([', '])', 'refused events')
605 return [...body.matchAll(/'([^']+)'/g)].map((m) => m[1])
606 }
607
608 export function parseHookEvents(source) {
609 const text = source.replace(/\r\n/g, '\n')
610 const body = between(text, 'const EVENTS:Record<string,string>={', '}', 'hook events')
611 return [...body.matchAll(/([A-Za-z]+):'([a-z_]+)'/g)].map((m) => ({ event: m[1], point: m[2] }))
612 }
613
614 export function buildCatalog(paths = SOURCES) {
615 const compatibility = JSON.parse(read(paths.compatibility))
616 const provided = Object.entries(compatibility.provided_services).flatMap(([group, names]) => names.map((name) => ({ group, name })))
617 const known = new Set(Object.keys(SERVICES))
618 const missing = provided.filter(({ name }) => !known.has(name)).map(({ name }) => name)
619 if (missing.length) throw new Error(`compatibility.json provides services with no entry in the method table: ${missing.join(', ')}`)
620 const extra = [...known].filter((name) => !provided.some((entry) => entry.name === name))
621 if (extra.length) throw new Error(`the method table names services the host does not provide: ${extra.join(', ')}`)
622
623 const services = provided.map(({ group, name }) => {
624 const entry = SERVICES[name]
625 return {
626 key: name,
627 group,
628 summary: entry.summary,
629 availability: entry.availability,
630 availabilityText: AVAILABILITY[entry.availability],
631 methods: entry.methods,
632 }
633 })
634
635 const refusedEvents = parseRefusedEvents(read(paths.hostRoot))
636 const hookEvents = parseHookEvents(read(paths.shellHooks))
637 const events = [
638 ...EVENTS_SUPPORTED,
639 ...refusedEvents.map((name) => ({ name, status: 'refused', summary: REFUSED_EVENT_REASON })),
640 ]
641
642 const rowPackages = Object.keys(compatibility.row_bridges)
643 const unknownRows = rowPackages.filter((name) => !ROW_PACKAGES[name])
644 const staleRows = Object.keys(ROW_PACKAGES).filter((name) => !rowPackages.includes(name))
645 if (unknownRows.length || staleRows.length) throw new Error(`row packages differ from compatibility.json: missing ${unknownRows.join(', ')}; stale ${staleRows.join(', ')}`)
646 const rows = rowPackages.map((name) => ({
647 id: `row:${name}`,
648 name,
649 bridge: compatibility.row_bridges[name],
650 summary: ROW_PACKAGES[name].summary,
651 limits: ROW_PACKAGES[name].limits,
652 example: ROW_PACKAGES[name].example,
653 ...(name.includes('hooks-') ? { hookEvents } : {}),
654 schema: { $schema: 'https://json-schema.org/draft/2020-12/schema', title: name, ...ROW_PACKAGES[name].schema },
655 }))
656
657 const table = parseSeatTable(read(paths.seatTable))
658 const unknownSeatNotes = table.seats.filter((seat) => !SEAT_NOTES[seat])
659 const staleSeatNotes = Object.keys(SEAT_NOTES).filter((seat) => !table.seats.includes(seat))
660 if (unknownSeatNotes.length || staleSeatNotes.length) throw new Error(`seat notes differ from the Engine seat list: missing ${unknownSeatNotes.join(', ')}; stale ${staleSeatNotes.join(', ')}`)
661 const seats = table.seats.map((seat) => ({ seat, drawn: SEAT_NOTES[seat].drawn, where: SEAT_NOTES[seat].where }))
662
663 return {
664 version: 1,
665 targetDshVersion: compatibility.target_dsh_version,
666 host: {
667 services,
668 refusedServices: compatibility.refused_services,
669 events,
670 cordisInternalEvents: 'Cordis fires its own internal/* lifecycle events. They are not part of this host\'s supported contract and are not listed.',
671 config: rows,
672 },
673 client: {
674 seats,
675 slots: table.slots,
676 theme: THEME,
677 },
678 }
679 }
680
681 export function renderCatalog(catalog) {
682 return `${JSON.stringify(catalog, null, 2)}\n`
683 }
684
685 if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
686 const text = renderCatalog(buildCatalog())
687 if (process.argv.includes('--check')) {
688 const current = existsOrEmpty(SOURCES.catalog)
689 if (current !== text) {
690 process.stderr.write('inspect-catalog.json is out of date: run node scripts/gen-inspect-catalog.mjs\n')
691 process.exit(1)
692 }
693 } else {
694 writeFileSync(SOURCES.catalog, text)
695 }
696 }
697
698 function existsOrEmpty(path) {
699 try {
700 return read(path)
701 } catch {
702 return ''
703 }
704 }
705
705 lines Plain Text