@hcstar/dsh-tool-manage 0.0.0-stage → 0.1.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/lib/index.d.ts ADDED
@@ -0,0 +1,847 @@
1
+ import { IncomingMessage, ServerResponse } from 'node:http';
2
+
3
+ /**
4
+ * Shared wire contracts for the tool manager's Host routes and browser bundle.
5
+ *
6
+ * The Host owns the only authoritative view of the filesystem and of the tool
7
+ * registry; the browser renders these shapes without re-deriving them.
8
+ */
9
+ /** One directory the skill manager scans. */
10
+ interface SkillRootInfo {
11
+ /** Stable key used when creating a skill into this root. */
12
+ key: string;
13
+ /** Display label resolved on the Host so every client locale sees one name. */
14
+ label: string;
15
+ /** Absolute directory path. */
16
+ path: string;
17
+ /** Whether the manager may write here. */
18
+ writable: boolean;
19
+ /** Whether the directory exists right now. */
20
+ exists: boolean;
21
+ /** True for a user-configured scan directory, not a built-in root. */
22
+ custom?: boolean;
23
+ }
24
+ /** One file or directory shipped beside a SKILL.md. */
25
+ interface SkillResourceInfo {
26
+ /** Display name (a directory keeps no trailing slash). */
27
+ name: string;
28
+ /** Path relative to the skill directory, using `/` separators. */
29
+ path: string;
30
+ bytes: number;
31
+ /** Whether this entry is a directory. */
32
+ directory: boolean;
33
+ }
34
+ /** One skill as a list row. */
35
+ interface SkillSummaryInfo {
36
+ /** Frontmatter name, or the directory / file stem when the file is invalid. */
37
+ name: string;
38
+ description: string;
39
+ whenToUse?: string;
40
+ /** Absolute SKILL.md (or flat `.md`) path; absent for virtual runtime skills. */
41
+ path?: string;
42
+ /** Absolute skill directory, present for directory bundles. */
43
+ dir?: string;
44
+ /** Discovery source key (`user-dsh`, `user-agents`, `bundled`, …). */
45
+ source: string;
46
+ /** Human-readable source group. */
47
+ sourceLabel: string;
48
+ /** Owning scanned root key, absent for runtime-provided skills. */
49
+ rootKey?: string;
50
+ /** Whether the file may be edited or deleted. */
51
+ writable: boolean;
52
+ /** Whether the provider would accept this file as a skill. */
53
+ valid: boolean;
54
+ /** Why an invalid file is not loaded. */
55
+ issue?: string;
56
+ /** Whether the model catalog exposes it. */
57
+ modelInvocable: boolean;
58
+ /** Whether the human `/` command exposes it. */
59
+ userInvocable: boolean;
60
+ /** Instruction file size in bytes. */
61
+ bytes: number;
62
+ /** Files beside SKILL.md, not counting SKILL.md itself. */
63
+ resources: SkillResourceInfo[];
64
+ }
65
+ /** A skill with its complete instruction file. */
66
+ interface SkillDocumentInfo extends SkillSummaryInfo {
67
+ /** Full file content as stored. */
68
+ content: string;
69
+ /** Instruction body after the frontmatter, leading blank lines stripped. */
70
+ body: string;
71
+ }
72
+ /** `GET /dsh-tool-manage/skills` answer. */
73
+ interface SkillListResult {
74
+ roots: SkillRootInfo[];
75
+ skills: SkillSummaryInfo[];
76
+ /** Non-fatal discovery problems (unreadable roots, provider failures). */
77
+ warnings: string[];
78
+ }
79
+ /** Fields the form editor may change while preserving unknown frontmatter. */
80
+ interface SkillFieldsInput {
81
+ /** Frontmatter skill name; the UI only edits it for files that never loaded. */
82
+ name: string;
83
+ description: string;
84
+ whenToUse: string;
85
+ disableModelInvocation: boolean;
86
+ userInvocable: boolean;
87
+ }
88
+ /** `POST /dsh-tool-manage/skill/save` request. */
89
+ interface SkillSaveRequest {
90
+ path: string;
91
+ /** Form-mode edit: rewrite only these fields plus the body. */
92
+ fields?: SkillFieldsInput;
93
+ body?: string;
94
+ /** Raw-mode edit: replace the whole file after validating the envelope. */
95
+ content?: string;
96
+ }
97
+ /** `POST /dsh-tool-manage/skill/create` request. */
98
+ interface SkillCreateRequest {
99
+ rootKey: string;
100
+ name: string;
101
+ description: string;
102
+ whenToUse?: string;
103
+ body?: string;
104
+ disableModelInvocation?: boolean;
105
+ userInvocable?: boolean;
106
+ }
107
+ /** One MCP tool as the host registry exposes it. */
108
+ interface McpToolInfo {
109
+ /** Raw tool name without the `mcp__<server>__` prefix. */
110
+ name: string;
111
+ description: string;
112
+ parameters: Record<string, unknown>;
113
+ }
114
+ /** `GET /dsh-tool-manage/mcp/tools` answer, grouped by server key. */
115
+ interface McpToolsResult {
116
+ servers: Record<string, McpToolInfo[]>;
117
+ }
118
+ /** MCP transports the manager supports. */
119
+ type McpTransport = 'stdio' | 'streamable-http';
120
+ /** Reconnect policy carried by every managed entry. */
121
+ interface McpReconnectConfig {
122
+ enabled: boolean;
123
+ initialDelayMs: number;
124
+ maxDelayMs: number;
125
+ maxAttempts: number;
126
+ }
127
+ /** One managed MCP server entry, mirroring `dsh-mcp-manager`'s resolved shape. */
128
+ interface McpServerEntry {
129
+ transport: McpTransport;
130
+ command: string;
131
+ args: string[];
132
+ env: Record<string, string>;
133
+ cwd: string;
134
+ url: string;
135
+ headers: Record<string, string>;
136
+ enabled: boolean;
137
+ toolCallTimeoutMs?: number;
138
+ startupTimeoutMs: number;
139
+ closeTimeoutMs?: number;
140
+ reconnect: McpReconnectConfig;
141
+ /** Whether the server's tools join every list eagerly or load on demand. */
142
+ toolLoading?: 'eager' | 'on-demand';
143
+ /** OAuth settings owned by the MCP client host; preserved across panel saves. */
144
+ oauth?: Record<string, unknown>;
145
+ }
146
+ /** The complete configured server map stored in the `mcp-manager` row. */
147
+ type McpServerMap = Record<string, McpServerEntry>;
148
+ /** One MCP server's injection rule: a default plus per-preset overrides. */
149
+ interface McpInjectionRule {
150
+ /** Used when a preset has no explicit entry. */
151
+ default: boolean;
152
+ /** Explicit overrides; an absent key follows `default`. */
153
+ presets: Record<string, boolean>;
154
+ }
155
+ /**
156
+ * Injection policy, stored by the Host beside the profile.
157
+ *
158
+ * Version 5 drops the per-preset tool/skill masks: the panel no longer has a
159
+ * preset page, and MCP servers and skills each carry their own injection rule
160
+ * instead of one preset-wide mask list.
161
+ */
162
+ interface InjectionPolicy {
163
+ version: 5;
164
+ /** Per-MCP-server injection across Agent presets. */
165
+ mcp: Record<string, McpInjectionRule>;
166
+ /** Per-skill injection across Agent presets, keyed by skill name. */
167
+ skillInjection: Record<string, McpInjectionRule>;
168
+ /**
169
+ * Optional per-server text glyphs. A missing key falls back to the server's
170
+ * first character; values may be one or two letters or an emoji.
171
+ */
172
+ icons: Record<string, string>;
173
+ }
174
+ /** One Agent preset the policy editor can target. */
175
+ interface AgentPresetInfo {
176
+ id: string;
177
+ name?: string;
178
+ description?: string;
179
+ isDefault?: boolean;
180
+ }
181
+ /** One tool the Host registry exposes outside the MCP namespace. */
182
+ interface OtherToolInfo {
183
+ /** Public tool name exactly as the model sees it. */
184
+ name: string;
185
+ description: string;
186
+ /** JSON Schema for the arguments. */
187
+ parameters: Record<string, unknown>;
188
+ /** Whether the Host global registry defines it, independent of any preset. */
189
+ global: boolean;
190
+ /** Presets whose live Agents can see it; empty without a live Agent. */
191
+ presets: string[];
192
+ }
193
+ /** `GET /dsh-tool-manage/tools` answer. */
194
+ interface OtherToolsResult {
195
+ tools: OtherToolInfo[];
196
+ /** Non-fatal problems while reading agent scopes. */
197
+ warnings: string[];
198
+ }
199
+ /** One actor a variable's permission applies to: the human at the panel, or the model. */
200
+ type VariableActor = 'human' | 'ai';
201
+ /** What one actor may do with one variable. */
202
+ interface VariablePermissions {
203
+ /** Whether the value may be read; while false the wire carries a mask instead. */
204
+ read: boolean;
205
+ /** Whether the label, description, value, or permissions may be changed. */
206
+ write: boolean;
207
+ /** Whether the variable may be removed. */
208
+ delete: boolean;
209
+ }
210
+ /** Who created the variable. */
211
+ type VariableSource = 'plugin' | 'manual' | 'ai';
212
+ /** One variable as a list row, already filtered for the asking actor. */
213
+ interface VariableSummaryInfo {
214
+ /** POSIX-style name; also the `{{name}}` token and the credential reference. */
215
+ name: string;
216
+ label: string;
217
+ description: string;
218
+ source: VariableSource;
219
+ /** Whether the credential store currently holds a value. */
220
+ configured: boolean;
221
+ /** Provider-masked preview, safe for every actor. */
222
+ masked: string;
223
+ /** The value, only when the asking actor may read it. */
224
+ value?: string;
225
+ /** Both permission sets, so the editor can show and change them. */
226
+ permissions: Record<VariableActor, VariablePermissions>;
227
+ /** The asking actor's own effective permissions. */
228
+ can: VariablePermissions;
229
+ createdAt: string;
230
+ updatedAt: string;
231
+ }
232
+ /** `POST /dsh-tool-manage/variable/save` request. */
233
+ interface VariableSaveRequest {
234
+ /** The variable's name; a new name creates a variable, an existing one edits it. */
235
+ name: string;
236
+ label?: string;
237
+ description?: string;
238
+ /** New value; absent leaves the stored value alone, an empty string clears it. */
239
+ value?: string;
240
+ permissions?: {
241
+ human?: Partial<VariablePermissions>;
242
+ ai?: Partial<VariablePermissions>;
243
+ };
244
+ }
245
+
246
+ /** The one policy document version this build writes. */
247
+ declare const POLICY_VERSION = 5;
248
+ /** The skill surface one Agent exposes to the mask. */
249
+ interface PolicySkill {
250
+ name: string;
251
+ description: string;
252
+ invocation?: {
253
+ modelInvocable?: boolean;
254
+ };
255
+ }
256
+ /** The Agent surface the policy reads and narrows. */
257
+ interface PolicyAgent {
258
+ id: string;
259
+ session: {
260
+ header: {
261
+ agentPreset?: string;
262
+ };
263
+ };
264
+ ctx: {
265
+ tools?: {
266
+ restrict(filter: {
267
+ deny?: readonly string[];
268
+ }): () => void;
269
+ };
270
+ skills?: {
271
+ list(options: {
272
+ scope?: unknown;
273
+ cwd?: string;
274
+ }): Promise<readonly PolicySkill[]>;
275
+ register(skill: {
276
+ name: string;
277
+ description: string;
278
+ content: string;
279
+ source: string;
280
+ invocation: {
281
+ modelInvocable: boolean;
282
+ userInvocable: boolean;
283
+ };
284
+ }): () => void;
285
+ };
286
+ };
287
+ }
288
+ /** The Host services the policy uses. */
289
+ interface PolicyHost {
290
+ on(event: string, listener: (...args: unknown[]) => void): () => void;
291
+ get(name: string): unknown;
292
+ }
293
+ /** Resolve the policy file under `$DSH_HOME`. */
294
+ declare function policyPath(environment?: NodeJS.ProcessEnv, home?: string): string;
295
+ /** A document with no narrowing: every preset sees everything. */
296
+ declare function emptyPolicy(): InjectionPolicy;
297
+ /** Validate and copy a whole policy document, accepting every shipped version. */
298
+ declare function normalizePolicy(input: unknown): InjectionPolicy;
299
+ /** Compute the global tool names one preset must not see. */
300
+ declare function compileToolDeny(policy: InjectionPolicy, presetId: string | undefined, toolNames: readonly string[]): string[];
301
+ /** One skill the policy hides: enough to shadow it in the Agent's catalog. */
302
+ interface HiddenSkill {
303
+ name: string;
304
+ description: string;
305
+ source: string;
306
+ modelInvocable: boolean;
307
+ }
308
+ /**
309
+ * Compute the skills one preset must keep out of its model catalog. Every
310
+ * visible name participates, including a skill this controller already
311
+ * shadowed: excluding shadows would flip the desired set on every re-apply and
312
+ * loop through `skills/change`.
313
+ */
314
+ declare function compileSkillHides(policy: InjectionPolicy, presetId: string | undefined, skills: readonly PolicySkill[]): HiddenSkill[];
315
+ /** Live narrowing of the tool registry and skill catalog, one set per Agent. */
316
+ declare class McpPolicyController {
317
+ private readonly host;
318
+ private readonly path;
319
+ private policy;
320
+ private readonly toolMasks;
321
+ private readonly toolSignatures;
322
+ private readonly skillMasks;
323
+ private readonly skillSignatures;
324
+ private timer;
325
+ private defaultId;
326
+ constructor(host: PolicyHost, path: string);
327
+ /** Load the document and start watching agents, presets, tools, and skills. */
328
+ start(): Promise<void>;
329
+ /** The current document, for the panel. */
330
+ current(): InjectionPolicy;
331
+ /** Persist a complete document and re-apply it to every live Agent. */
332
+ save(input: unknown): Promise<InjectionPolicy>;
333
+ /** Stop the debounce timer (the Host owns the rest through effect scopes). */
334
+ dispose(): void;
335
+ private schedule;
336
+ private agentById;
337
+ /**
338
+ * The preset the Agent currently runs under. A Session's creation header is
339
+ * only the initial fact: a switch writes `agent-preset/selected`, which the
340
+ * presets registry projects. Read that projection first.
341
+ */
342
+ private presetOf;
343
+ private globalToolNames;
344
+ private applyAll;
345
+ private applyAgent;
346
+ private applyTools;
347
+ private applySkills;
348
+ private release;
349
+ private releaseTools;
350
+ private releaseSkills;
351
+ }
352
+
353
+ /** One HTTP route registered on the Host web server. */
354
+ interface WebRoute {
355
+ kind: 'exact';
356
+ path: string;
357
+ /** Admission policy owned by the web server; `required` demands the browser token. */
358
+ auth?: 'anonymous' | 'required' | 'deny';
359
+ handler(req: IncomingMessage, res: ServerResponse): void | Promise<void>;
360
+ }
361
+ /** Services the plugin reaches through `ctx.inject([...])`. */
362
+ interface ChildContext {
363
+ effect(callback: () => void | (() => void), name?: string): void;
364
+ webServer: {
365
+ register(route: WebRoute): () => void;
366
+ };
367
+ /** Present when the plugin injected the `mcpManager` service. */
368
+ mcpManager?: McpManagerFace;
369
+ }
370
+ /** One server a plugin contributes to the MCP manager for its own lifetime. */
371
+ interface McpManagerRegistrationEntry {
372
+ transport: 'stdio' | 'streamable-http';
373
+ command?: string;
374
+ args?: string[];
375
+ env?: Record<string, string>;
376
+ cwd?: string;
377
+ url?: string;
378
+ headers?: Record<string, string>;
379
+ toolCallTimeoutMs?: number;
380
+ startupTimeoutMs?: number;
381
+ closeTimeoutMs?: number;
382
+ reconnect?: Record<string, unknown>;
383
+ toolLoading?: 'eager' | 'on-demand';
384
+ }
385
+ /** The MCP manager surface the plugin uses to publish its own server. */
386
+ interface McpManagerFace {
387
+ register(name: string, entry: McpManagerRegistrationEntry): () => void;
388
+ }
389
+ /** The Cordis plugin context surface this Host half uses. */
390
+ interface HostContext {
391
+ effect(callback: () => void | (() => void), name?: string): void;
392
+ get(name: string): unknown;
393
+ inject(names: string[], callback: (child: ChildContext) => void): void;
394
+ on(event: string, listener: (...args: unknown[]) => void): () => void;
395
+ logger?: {
396
+ warn(message: string): void;
397
+ };
398
+ agents?: {
399
+ list(): readonly PolicyAgent[];
400
+ };
401
+ tools?: {
402
+ definitions(scope?: unknown): readonly {
403
+ name: string;
404
+ description: string;
405
+ parameters: Record<string, unknown>;
406
+ }[];
407
+ };
408
+ skills?: {
409
+ list(options: {
410
+ scope?: unknown;
411
+ cwd?: string;
412
+ }): Promise<readonly {
413
+ name: string;
414
+ description: string;
415
+ invocation?: {
416
+ modelInvocable?: boolean;
417
+ };
418
+ }[]>;
419
+ };
420
+ agentPresets?: {
421
+ list(): Promise<AgentPresetInfo[]>;
422
+ readonly defaultId?: string;
423
+ acquireScope?(id?: string): Promise<{
424
+ key: unknown;
425
+ [Symbol.asyncDispose]?(): Promise<void>;
426
+ }>;
427
+ };
428
+ }
429
+
430
+ /**
431
+ * Skill file envelope handling.
432
+ *
433
+ * A skill file is YAML frontmatter plus a Markdown body. The manager edits a
434
+ * handful of routing fields, so it parses the small scalar subset those fields
435
+ * use and rewrites only the keys it owns; unrelated frontmatter (metadata,
436
+ * license, unknown plugin keys) survives a form save byte-for-byte.
437
+ *
438
+ * This module is deliberately dependency-free: the browser-side tests import
439
+ * the built artifact, and the Host half must not pull a YAML package into the
440
+ * plugin bundle just to read four keys.
441
+ */
442
+
443
+ /** Parsed view of one skill file. */
444
+ interface ParsedSkillDocument {
445
+ name: string;
446
+ description: string;
447
+ whenToUse?: string;
448
+ disableModelInvocation: boolean;
449
+ userInvocable: boolean;
450
+ body: string;
451
+ valid: boolean;
452
+ issue?: string;
453
+ }
454
+ /** A frontmatter document split at its closing delimiter. */
455
+ interface SplitDocument {
456
+ yamlLines: string[];
457
+ body: string;
458
+ }
459
+ /**
460
+ * Split a skill file into its frontmatter lines and body.
461
+ * @param raw - complete file text.
462
+ * @returns the split document, or undefined when the envelope is absent.
463
+ */
464
+ declare function splitDocument(raw: string): SplitDocument | undefined;
465
+ /** Parse the top-level scalar entries used by the form editor. */
466
+ declare function parseYamlScalars(lines: readonly string[]): Record<string, unknown>;
467
+ /**
468
+ * Parse a complete skill file into the view the manager renders.
469
+ * @param raw - file text.
470
+ * @param fallbackName - directory or file stem used when the frontmatter lacks a name.
471
+ * @returns parsed fields plus a validity verdict the manager surfaces instead of hiding bad files.
472
+ */
473
+ declare function parseSkillDocument(raw: string, fallbackName: string): ParsedSkillDocument;
474
+ /**
475
+ * Rewrite the manager-owned frontmatter fields and the body.
476
+ *
477
+ * Unknown keys and their indented blocks survive; an owned key that becomes
478
+ * empty is removed, which keeps files in the shape the provider documents.
479
+ * @param raw - current file text.
480
+ * @param fields - form values.
481
+ * @param body - new Markdown body.
482
+ * @returns complete replacement file text.
483
+ */
484
+ declare function applySkillFields(raw: string, fields: SkillFieldsInput, body: string): string;
485
+ /** Build a canonical skill file from scratch. */
486
+ declare function createSkillContent(input: SkillFieldsInput & {
487
+ body: string;
488
+ }): string;
489
+
490
+ /** The skill registry face this plugin reads; declared locally to stay runtime-free. */
491
+ interface SkillRegistryFace {
492
+ list(options?: {
493
+ cwd?: string;
494
+ signal?: AbortSignal;
495
+ }): Promise<readonly RuntimeSkillSummary[]>;
496
+ }
497
+ /** One runtime skill summary, matching `@deepseek-ai/dsh-skill`'s public shape. */
498
+ interface RuntimeSkillSummary {
499
+ name: string;
500
+ description: string;
501
+ whenToUse?: string;
502
+ path?: string;
503
+ source: string;
504
+ provider: string;
505
+ invocation: {
506
+ modelInvocable: boolean;
507
+ userInvocable: boolean;
508
+ };
509
+ }
510
+ /** Where the manager looks for skills, in display order. */
511
+ declare function defaultSkillRoots(environment?: NodeJS.ProcessEnv, home?: string): SkillRootInfo[];
512
+ /** Build a summary from one instruction file plus its owning root. */
513
+ declare function summarizeSkillFile(filePath: string, root: SkillRootInfo, fallbackName: string, directory?: string): Promise<SkillSummaryInfo>;
514
+ /** Whether `candidate` is inside `root` (both already resolved). */
515
+ declare function isInside(root: string, candidate: string): boolean;
516
+ /**
517
+ * List every skill found in the writable roots, without merging runtime
518
+ * providers. The skill tools address files, so they need this projection even
519
+ * when a runtime provider would shadow a same-name file in the panel list.
520
+ */
521
+ declare function listLocalSkills(roots?: SkillRootInfo[]): Promise<SkillListResult>;
522
+ /**
523
+ * List every skill the manager can show.
524
+ * @param registry - the runtime skill registry when the Host composition provides one.
525
+ */
526
+ declare function listSkills(registry: SkillRegistryFace | undefined, roots?: SkillRootInfo[]): Promise<SkillListResult>;
527
+ /** Read one skill file, including its complete content. */
528
+ declare function readSkillDocument(registry: SkillRegistryFace | undefined, path: string, roots?: SkillRootInfo[]): Promise<SkillDocumentInfo>;
529
+ /**
530
+ * Save one skill file in form mode or raw mode.
531
+ * @param registry - runtime registry for read-back.
532
+ * @param request - path plus either form fields or complete content.
533
+ */
534
+ declare function saveSkillDocument(registry: SkillRegistryFace | undefined, request: SkillSaveRequest, roots?: SkillRootInfo[]): Promise<SkillDocumentInfo>;
535
+ /** Create a directory-bundle skill in one writable root. */
536
+ declare function createSkillDocument(registry: SkillRegistryFace | undefined, request: SkillCreateRequest, roots?: SkillRootInfo[]): Promise<SkillDocumentInfo>;
537
+ /** Delete a skill directory bundle or flat skill file. */
538
+ declare function deleteSkillDocument(path: string, roots?: SkillRootInfo[]): Promise<void>;
539
+
540
+ /**
541
+ * Minimal model-facing tool scaffolding for the Host half.
542
+ *
543
+ * The plugin ships no `@deepseek-ai/*` runtime import: a profile install
544
+ * resolves the plugin from the profile directory, where the Harness packages
545
+ * are not necessarily visible. These definitions therefore speak the registry's
546
+ * plain `ToolDefinition` shape directly. The helpers only narrow arguments and
547
+ * render canonical JSON; the registry and the executor pipeline own the rest.
548
+ */
549
+ /** One model-facing text block. */
550
+ interface ToolTextBlock {
551
+ type: 'text';
552
+ text: string;
553
+ }
554
+ /** The execution facts the tool bodies use. */
555
+ interface ToolRunContextFace {
556
+ /** Caller-owned cancellation. */
557
+ signal: AbortSignal;
558
+ /** The Agent on whose behalf the call runs, when the executor supplies one. */
559
+ agent?: unknown;
560
+ }
561
+ /** The subset of `ToolDefinition` this plugin builds. */
562
+ interface ToolDefinitionFace {
563
+ name: string;
564
+ description: string;
565
+ parameters: Record<string, unknown>;
566
+ output: {
567
+ schema: Record<string, unknown>;
568
+ render(args: unknown, value: unknown): ToolTextBlock[];
569
+ };
570
+ execute(args: unknown, exec: ToolRunContextFace): Promise<unknown>;
571
+ }
572
+
573
+ /** The six model-facing tool definitions this plugin exposes. */
574
+ declare function createToolManagerTools(ctx: HostContext, policy: McpPolicyController): ToolDefinitionFace[];
575
+
576
+ /** The Host-internal MCP server for the tool manager. */
577
+ declare class ToolManagerMcpServer {
578
+ private readonly ctx;
579
+ private server;
580
+ private readonly token;
581
+ private readonly tools;
582
+ private readonly streams;
583
+ private protocolVersion;
584
+ private sessionId;
585
+ constructor(ctx: HostContext, policy: McpPolicyController);
586
+ /** The path the MCP client must use; it contains the per-process token. */
587
+ get path(): string;
588
+ /** Start on a random loopback port; returns the URL registered with the manager. */
589
+ start(): Promise<{
590
+ port: number;
591
+ url: string;
592
+ }>;
593
+ /** End open streams and close the listener. */
594
+ close(): Promise<void>;
595
+ /** Dispatch one HTTP request. */
596
+ private handle;
597
+ /** Keep a Streamable HTTP GET channel open for server-initiated messages. */
598
+ private openStream;
599
+ /** Answer one JSON-RPC message; notifications produce no response. */
600
+ private handleMessage;
601
+ /** Answer the MCP handshake and retain the negotiated protocol version. */
602
+ private initialize;
603
+ /** Project the management tools onto the MCP tools/list shape. */
604
+ private toolList;
605
+ /** Execute one management tool and map its result to MCP content. */
606
+ private callTool;
607
+ }
608
+ /**
609
+ * Start the in-Host MCP server and register it with the MCP manager.
610
+ *
611
+ * Registration makes the server visible on the MCP page as a plugin-provided
612
+ * entry and publishes its tools as `mcp__<serverName>__*`. A profile that has
613
+ * no MCP manager simply gets no server: the panel's routes still work.
614
+ */
615
+ declare function attachMcpServer(ctx: HostContext, policy: McpPolicyController): void;
616
+
617
+ /** Resolve `$DSH_HOME` the same way every state file does. */
618
+ declare function dshHome(environment?: NodeJS.ProcessEnv, home?: string): string;
619
+ /** Resolve the state directory, migrating the pre-rename name once. */
620
+ declare function stateDir(environment?: NodeJS.ProcessEnv, home?: string): string;
621
+ /** Resolve one file inside the state directory. */
622
+ declare function statePath(name: string, environment?: NodeJS.ProcessEnv, home?: string): string;
623
+
624
+ /**
625
+ * Host-side administration of the `mcp-manager` server fleet.
626
+ *
627
+ * The browser edits the same entries through the settings form service; this
628
+ * module reads and writes the one stored copy in the profile patch. It never
629
+ * keeps its own list: a write goes through `ctx.settings.replace`, so the
630
+ * manager validates the entry and rebuilds the connection, and a concurrent
631
+ * edit surfaces as a revision conflict rather than a lost update.
632
+ */
633
+
634
+ /** One configured server plus the runtime facts the tools can prove. */
635
+ interface McpServerSummary {
636
+ name: string;
637
+ /** Whether the entry belongs to the stored `mcp-manager` config. */
638
+ configured: boolean;
639
+ /** Whether a plugin registered the entry for its own lifetime. */
640
+ registered: boolean;
641
+ enabled: boolean;
642
+ transport: string;
643
+ /** `command` for stdio, `url` for streamable-http. */
644
+ endpoint: string;
645
+ status?: unknown;
646
+ tools: string[];
647
+ }
648
+ /** The stored `mcp-manager` config plus the revision a later write must match. */
649
+ interface McpConfigSnapshot {
650
+ ns: string;
651
+ revision: number;
652
+ servers: McpServerMap;
653
+ }
654
+ /**
655
+ * Read the stored server map and its revision.
656
+ *
657
+ * The row id is `mcp-manager` in every shipped profile; a renamed row is found
658
+ * by the shape of its projected value instead.
659
+ */
660
+ declare function readMcpConfig(ctx: HostContext): McpConfigSnapshot | undefined;
661
+ /** List configured, registered, and retained servers with their tool names. */
662
+ declare function listMcpServers(ctx: HostContext): {
663
+ servers: McpServerSummary[];
664
+ warnings: string[];
665
+ };
666
+ /** Read one server's stored entry, or undefined when it is only registered. */
667
+ declare function findMcpEntry(ctx: HostContext, name: string): McpServerEntry | undefined;
668
+ /** Drop cross-transport fields, fill defaults, and validate the name. */
669
+ declare function mergeMcpEntry(base: McpServerEntry | undefined, patch: Record<string, unknown>): McpServerEntry;
670
+ /** Create or update one configured server; registered servers are read-only. */
671
+ declare function upsertMcpServer(ctx: HostContext, name: string, patch: Record<string, unknown>): Promise<McpServerEntry>;
672
+ /** Remove one configured server. */
673
+ declare function removeMcpServer(ctx: HostContext, name: string): Promise<void>;
674
+ /** Probe one configured or registered server without touching its live instance. */
675
+ declare function probeMcpServer(ctx: HostContext, name: string, options: {
676
+ signal?: AbortSignal;
677
+ timeoutMs?: number;
678
+ }): Promise<unknown>;
679
+ /** Rebuild one server from its current entry. */
680
+ declare function restartMcpServer(ctx: HostContext, name: string): Promise<void>;
681
+
682
+ /**
683
+ * MCP server entry rules shared by the browser form and the Host tools.
684
+ *
685
+ * The panel and the agent tools edit the same `mcp-manager` config, so the
686
+ * default entry and the cross-transport cleanup must not drift apart. Both
687
+ * callers import this module; the manager still owns the final validation.
688
+ */
689
+
690
+ /** A fresh stdio entry with the manager's schema defaults. */
691
+ declare function defaultMcpEntry(): McpServerEntry;
692
+ /** Drop cross-transport fields and empty optional numbers before writing. */
693
+ declare function normalizeMcpEntry(entry: McpServerEntry): McpServerEntry;
694
+
695
+ /**
696
+ * MCP tool-name helpers shared by the tool route and the injection policy.
697
+ *
698
+ * A public MCP tool is `mcp__<server>__<tool>`; the server segment is the
699
+ * manager's `serverName`, which may itself contain underscores, so parsing and
700
+ * formatting stay in one place.
701
+ */
702
+
703
+ /** Split one public MCP tool name into its server and raw tool segments. */
704
+ declare function splitMcpToolName(name: string): {
705
+ server: string;
706
+ tool: string;
707
+ } | undefined;
708
+ /** Build the public tool name for one server and raw tool. */
709
+ declare function mcpToolName(server: string, tool: string): string;
710
+ /** Group the host's MCP tool definitions by server name. */
711
+ declare function groupMcpTools(definitions: readonly {
712
+ name: string;
713
+ description: string;
714
+ parameters: Record<string, unknown>;
715
+ }[]): McpToolsResult;
716
+
717
+ /**
718
+ * Read every non-MCP tool the Host currently exposes.
719
+ *
720
+ * The registry has no owner metadata per definition, so the collector reports
721
+ * what it can prove: the name, the model-facing description and schema, whether
722
+ * the Host global plane defines it, and which live preset scopes can see it.
723
+ * MCP tools belong to the MCP tab and are filtered out here.
724
+ */
725
+
726
+ /** The Host services this collector reads. */
727
+ interface OtherToolsHost {
728
+ get(name: string): unknown;
729
+ on?(event: string, listener: (payload: unknown) => void): () => void;
730
+ }
731
+ /**
732
+ * Collect the non-MCP tool catalog.
733
+ * @param host - the plugin Host context.
734
+ * @returns sorted tools plus non-fatal read problems.
735
+ */
736
+ declare function collectOtherTools(host: OtherToolsHost): OtherToolsResult;
737
+
738
+ /**
739
+ * `{{name}}` tokens and their `${credential:NAME}` translation.
740
+ *
741
+ * The panel and the model speak `{{name}}`: short, readable, and safe to embed
742
+ * inside a longer string such as `Bearer {{token}}`. The MCP client resolves
743
+ * only `${credential:NAME}` at connection time, so the Host rewrites one form
744
+ * into the other at the storage boundary. Rewriting is per token and
745
+ * conditional: a token whose name no variable declares stays literal text,
746
+ * which makes a half-typed template harmless and keeps `Bearer {{x}}` working
747
+ * once `x` exists.
748
+ */
749
+ /** Whether a raw string could name a variable at all (and thus a credential ref). */
750
+ declare function isVariableName(value: string): boolean;
751
+ /** The fields of an MCP entry whose strings the MCP client expands at connect time. */
752
+ interface TemplatedEntry {
753
+ command?: string;
754
+ args?: string[];
755
+ cwd?: string;
756
+ url?: string;
757
+ env?: Record<string, string>;
758
+ headers?: Record<string, string>;
759
+ }
760
+ /**
761
+ * Rewrite every `{{name}}` the store knows into `${credential:NAME}`.
762
+ * @param value - any configuration string, possibly with tokens inside a longer text.
763
+ * @param known - whether the store declares that variable.
764
+ * @returns the native template string; unknown tokens are preserved verbatim.
765
+ */
766
+ declare function toNativeToken(value: string, known: (name: string) => boolean): string;
767
+ /**
768
+ * Rewrite every `${credential:NAME}` that a variable declares back into `{{NAME}}` for display.
769
+ * @param value - stored configuration string.
770
+ * @param known - whether the store declares that variable.
771
+ * @returns the readable form; native templates this plugin does not own stay as they are.
772
+ */
773
+ declare function toSugarToken(value: string, known: (name: string) => boolean): string;
774
+
775
+ /** Services this module reaches. */
776
+ interface VariableHost {
777
+ get(name: string): unknown;
778
+ }
779
+ /** Resolve the metadata file under `$DSH_HOME`. */
780
+ declare function variablesPath(environment?: NodeJS.ProcessEnv, home?: string): string;
781
+ /** What a newly created variable allows: the owner keeps everything, the model may rotate but not read or delete. */
782
+ declare function defaultPermissions(): Record<VariableActor, VariablePermissions>;
783
+ /** The names the document declares, for token rewriting. */
784
+ declare function variableNames(): Promise<(name: string) => boolean>;
785
+ /**
786
+ * Rewrite `{{name}}` tokens a variable declares into native templates.
787
+ * @param entry - an MCP entry's template-capable fields.
788
+ * @returns the same shape with native templates; unknown tokens are untouched.
789
+ */
790
+ declare function entryToNative<T extends TemplatedEntry>(entry: T): Promise<T>;
791
+ /**
792
+ * Rewrite native templates this plugin owns back into `{{name}}` for display.
793
+ * @param entry - a stored MCP entry.
794
+ */
795
+ declare function entryToSugar<T extends TemplatedEntry>(entry: T): Promise<T>;
796
+ /**
797
+ * List every variable for one actor.
798
+ * @param host - services the module reaches.
799
+ * @param actor - who is asking; decides the value and the effective permissions.
800
+ */
801
+ declare function listVariables(host: VariableHost, actor: VariableActor): Promise<{
802
+ variables: VariableSummaryInfo[];
803
+ warnings: string[];
804
+ }>;
805
+ /**
806
+ * Read one variable for one actor, requiring only that it exists.
807
+ * @param host - services the module reaches.
808
+ * @param name - the variable name.
809
+ * @param actor - who is asking.
810
+ */
811
+ declare function getVariable(host: VariableHost, name: string, actor: VariableActor): Promise<VariableSummaryInfo>;
812
+ /**
813
+ * Create or update one variable.
814
+ *
815
+ * Creating requires the credential reference to be free: silently overwriting a
816
+ * reference another surface already stores would change that surface's
817
+ * credentials. Editing changes only what was sent and never resurrects a value.
818
+ * @param host - services the module reaches.
819
+ * @param input - the requested fields.
820
+ * @param actor - who is writing; decides the permission checks and the source.
821
+ */
822
+ declare function saveVariable(host: VariableHost, input: VariableSaveRequest, actor: VariableActor): Promise<VariableSummaryInfo>;
823
+ /**
824
+ * Remove one variable and its stored value.
825
+ * @param host - services the module reaches.
826
+ * @param name - the variable name.
827
+ * @param actor - who is deleting; requires the delete permission.
828
+ */
829
+ declare function deleteVariable(host: VariableHost, name: string, actor: VariableActor): Promise<void>;
830
+
831
+ /**
832
+ * dsh-tool-manage — Host half.
833
+ *
834
+ * One Loader row with no configuration of its own. It adds the management
835
+ * routes the browser panel calls: skill discovery/read/save/create/delete on
836
+ * the global skill roots, MCP tool metadata, variables, the preset roster, and
837
+ * the MCP/skill injection policy. MCP server entries themselves stay in the
838
+ * `mcp-manager` row's volatile Config, which the panel edits through the
839
+ * settings service — this plugin never keeps a second copy.
840
+ *
841
+ * @module @hcstar/dsh-tool-manage
842
+ */
843
+
844
+ /** Register the management routes; headless compositions without a web server simply get none. */
845
+ declare function apply(ctx: HostContext): void;
846
+
847
+ export { McpPolicyController, POLICY_VERSION, ToolManagerMcpServer, apply, applySkillFields, attachMcpServer, collectOtherTools, compileSkillHides, compileToolDeny, createSkillContent, createSkillDocument, createToolManagerTools, defaultMcpEntry, defaultPermissions, defaultSkillRoots, deleteSkillDocument, deleteVariable, dshHome, emptyPolicy, entryToNative, entryToSugar, findMcpEntry, getVariable, groupMcpTools, isInside, isVariableName, listLocalSkills, listMcpServers, listSkills, listVariables, mcpToolName, mergeMcpEntry, normalizeMcpEntry, normalizePolicy, parseSkillDocument, parseYamlScalars, policyPath, probeMcpServer, readMcpConfig, readSkillDocument, removeMcpServer, restartMcpServer, saveSkillDocument, saveVariable, splitDocument, splitMcpToolName, stateDir, statePath, summarizeSkillFile, toNativeToken, toSugarToken, upsertMcpServer, variableNames, variablesPath };