dsh-tool-manager 1.2.13 → 1.3.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.
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Which tools a `tool:*` prompt section introduces, learned from registration.
3
+ *
4
+ * DSH's prompt sections carry no "this section describes these tools"
5
+ * metadata (`PromptSection` is name/order/text/interpolate/complete), and
6
+ * `ToolDefinition` has no owner or source field. The structural signal is
7
+ * registration identity: a Cordis service method runs with `this.ctx` bound to
8
+ * the *calling* context, so `systemPrompt.section()` and `tools.register()` can
9
+ * both name the plugin fiber that made the call.
10
+ *
11
+ * Most registrations happen after this plugin starts on a profile, and are
12
+ * recorded directly by the method wrappers below. The built-in
13
+ * `preset-standard` definition, however, lives in the web-app bundle and may
14
+ * be mounted before the profile bundle that contains this plugin, or may be
15
+ * composed by DSH after the profile plugin starts. Sections that already exist
16
+ * when the observer is installed are recovered immediately; when the Preset's
17
+ * scoped layers appear later, the first prompt assembly re-runs the recovery.
18
+ * For both paths this module reads the live Cordis fiber registry: each fiber
19
+ * retains the plugin callback whose source declares its section names and tool
20
+ * definitions, and the fiber's effect sequence records the exact order in
21
+ * which it called `systemPrompt.section()` and `tools.register()`. Matching
22
+ * those two ordered lists recovers exact ownership without inspecting prompt
23
+ * text or guessing a package-to-tool table.
24
+ *
25
+ * The store lives on `globalThis` because DSH reloads a plugin node by
26
+ * re-applying it on the same Fiber: a fresh module instance must keep the
27
+ * registrations learned before the reload. Prototype wrappers are installed
28
+ * once per prototype and only observe; they delegate every call unchanged.
29
+ */
30
+ /** The tool family a prompt section introduces, when its author is known. */
31
+ export interface PromptToolFamily {
32
+ /** Whether a registering fiber was observed for this section name. */
33
+ readonly owned: boolean;
34
+ /** Every tool name those fibers registered, across the process. */
35
+ readonly tools: readonly string[];
36
+ }
37
+ /**
38
+ * Registration-identity view of prompt sections and tool families.
39
+ *
40
+ * One instance is enough per process; {@link PromptToolAffinity.shared}
41
+ * returns it. Instances are stateless themselves — every observation is kept
42
+ * in the process-wide store so a plugin reload cannot lose it.
43
+ */
44
+ export declare class PromptToolAffinity {
45
+ /** The process-wide instance shared by every plugin reload. */
46
+ static shared(): PromptToolAffinity;
47
+ /**
48
+ * Start observing section and tool registrations, then recover sections
49
+ * that were already mounted before this plugin loaded.
50
+ *
51
+ * @param systemPrompt - the live `systemPrompt` service, or `undefined`.
52
+ * @param tools - the live global `tools` service, or `undefined`.
53
+ * @param registry - the live Cordis registry, or `undefined`.
54
+ */
55
+ install(systemPrompt: unknown, tools: unknown, registry?: unknown): void;
56
+ /**
57
+ * Recover ownership for sections that were registered before `install()`.
58
+ *
59
+ * This is intentionally structural: it uses the live fiber's callback source
60
+ * and effect order, not the prompt section's prose. A section is learned only
61
+ * when both its declaration and its tool definitions are found in the same
62
+ * plugin callback (or in the same entry's module when a helper is involved).
63
+ */
64
+ learnExisting(registry: unknown, systemPrompt: unknown, tools: unknown): void;
65
+ /**
66
+ * Recover sections that were mounted after the initial {@link install}, as
67
+ * happens when DSH composes the default Preset after this profile plugin
68
+ * starts. A lookup runs during prompt assembly, at which point the Preset's
69
+ * scoped layers exist; only rerun the scan when the layer names changed.
70
+ */
71
+ private ensureLearnedForCurrentLayers;
72
+ /**
73
+ * The tools registered by the fibers that registered `sectionName`, plus any
74
+ * exact tool family recovered from that section's pre-mounted plugin.
75
+ *
76
+ * @param sectionName - full prompt-section name, e.g. `tool:jobs`.
77
+ * @returns `owned: false` when no registering fiber or tool declaration was
78
+ * observed, which the caller must treat as "not a tool family" rather than
79
+ * "empty family".
80
+ */
81
+ lookup(sectionName: string): PromptToolFamily;
82
+ }
83
+ /**
84
+ * Clear the process-wide store. Intended for tests that need a clean process.
85
+ */
86
+ export declare function resetPromptAffinity(): void;
87
+ //# sourceMappingURL=prompt-affinity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-affinity.d.ts","sourceRoot":"","sources":["../src/prompt-affinity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AA4FH,6EAA6E;AAC7E,MAAM,WAAW,gBAAgB;IAC/B,sEAAsE;IACtE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,mEAAmE;IACnE,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAED;;;;;;GAMG;AACH,qBAAa,kBAAkB;IAC7B,+DAA+D;IAC/D,MAAM,CAAC,MAAM,IAAI,kBAAkB;IAInC;;;;;;;OAOG;IACH,OAAO,CAAC,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI;IAYxE;;;;;;;OAOG;IACH,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAmD7E;;;;;OAKG;IACH,OAAO,CAAC,6BAA6B;IAUrC;;;;;;;;OAQG;IACH,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,gBAAgB;CAoB9C;AA0YD;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAG1C"}