dsh-tool-manager 1.2.12 → 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,617 @@
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
+ import { readFileSync } from "node:fs";
31
+ import { createRequire } from "node:module";
32
+ const STORE_KEY = Symbol.for("dsh-tool-manager.prompt-affinity");
33
+ function store() {
34
+ const holder = globalThis;
35
+ let current = holder[STORE_KEY];
36
+ if (current === undefined) {
37
+ current = {
38
+ toolsByFiber: new WeakMap(),
39
+ sectionFibers: new Map(),
40
+ learnedSectionTools: new Map(),
41
+ patched: new WeakSet(),
42
+ moduleSources: new Map(),
43
+ };
44
+ holder[STORE_KEY] = current;
45
+ }
46
+ // A plugin reload can find a store created by an older module version.
47
+ current.learnedSectionTools ??= new Map();
48
+ current.moduleSources ??= new Map();
49
+ return current;
50
+ }
51
+ /**
52
+ * Registration-identity view of prompt sections and tool families.
53
+ *
54
+ * One instance is enough per process; {@link PromptToolAffinity.shared}
55
+ * returns it. Instances are stateless themselves — every observation is kept
56
+ * in the process-wide store so a plugin reload cannot lose it.
57
+ */
58
+ export class PromptToolAffinity {
59
+ /** The process-wide instance shared by every plugin reload. */
60
+ static shared() {
61
+ return SHARED;
62
+ }
63
+ /**
64
+ * Start observing section and tool registrations, then recover sections
65
+ * that were already mounted before this plugin loaded.
66
+ *
67
+ * @param systemPrompt - the live `systemPrompt` service, or `undefined`.
68
+ * @param tools - the live global `tools` service, or `undefined`.
69
+ * @param registry - the live Cordis registry, or `undefined`.
70
+ */
71
+ install(systemPrompt, tools, registry) {
72
+ const state = store();
73
+ state.live = { systemPrompt, tools, registry };
74
+ state.learnedSectionSignature = undefined;
75
+ state.learnedToolSignature = undefined;
76
+ const sectionProto = prototypeOf(systemPrompt);
77
+ if (sectionProto !== undefined)
78
+ wrapSection(sectionProto);
79
+ const toolProto = prototypeOf(tools);
80
+ if (toolProto !== undefined)
81
+ wrapRegister(toolProto);
82
+ if (registry !== undefined)
83
+ this.learnExisting(registry, systemPrompt, tools);
84
+ }
85
+ /**
86
+ * Recover ownership for sections that were registered before `install()`.
87
+ *
88
+ * This is intentionally structural: it uses the live fiber's callback source
89
+ * and effect order, not the prompt section's prose. A section is learned only
90
+ * when both its declaration and its tool definitions are found in the same
91
+ * plugin callback (or in the same entry's module when a helper is involved).
92
+ */
93
+ learnExisting(registry, systemPrompt, tools) {
94
+ const sectionNames = collectSectionNames(systemPrompt);
95
+ const toolNames = collectToolNames(tools);
96
+ const state = store();
97
+ state.learnedSectionSignature = signatureOf(sectionNames);
98
+ state.learnedToolSignature = signatureOf(toolNames);
99
+ if (sectionNames.length === 0 || toolNames.length === 0)
100
+ return;
101
+ const groups = groupFibers(registry);
102
+ for (const fibers of groups) {
103
+ const declaredSections = new Set();
104
+ const declaredTools = new Set();
105
+ let paired = false;
106
+ for (const fiber of fibers) {
107
+ const source = callbackSource(fiber);
108
+ if (source.length === 0)
109
+ continue;
110
+ const events = registrationEvents(source, sectionNames, toolNames);
111
+ for (const event of events) {
112
+ if (event.kind === "section")
113
+ declaredSections.add(event.name);
114
+ else
115
+ declaredTools.add(event.name);
116
+ }
117
+ const kinds = effectKinds(fiber);
118
+ const pairs = pairEvents(events, kinds);
119
+ if (pairs === undefined)
120
+ continue;
121
+ paired = true;
122
+ for (const [section, members] of pairs)
123
+ rememberLearned(section, members);
124
+ }
125
+ // `tool-terminal-panel` registers its section in apply() but its tools in
126
+ // a module-level helper called directly from apply(), so the callback
127
+ // source has no tool declarations. Read the entry's module source in that
128
+ // case; only a single-section module is safe to attribute wholesale.
129
+ const entry = fibers.map((fiber) => fiber.entry).find((value) => value !== undefined);
130
+ const moduleSource = entry === undefined ? undefined : moduleSourceOf(entry);
131
+ if (moduleSource !== undefined) {
132
+ for (const event of registrationEvents(moduleSource, sectionNames, toolNames)) {
133
+ if (event.kind === "section")
134
+ declaredSections.add(event.name);
135
+ else
136
+ declaredTools.add(event.name);
137
+ }
138
+ for (const [section, members] of modulePairs(moduleSource, sectionNames, toolNames)) {
139
+ rememberLearned(section, members);
140
+ paired = true;
141
+ }
142
+ }
143
+ if (!paired && declaredSections.size === 1 && declaredTools.size > 0) {
144
+ rememberLearned([...declaredSections][0], [...declaredTools]);
145
+ }
146
+ }
147
+ }
148
+ /**
149
+ * Recover sections that were mounted after the initial {@link install}, as
150
+ * happens when DSH composes the default Preset after this profile plugin
151
+ * starts. A lookup runs during prompt assembly, at which point the Preset's
152
+ * scoped layers exist; only rerun the scan when the layer names changed.
153
+ */
154
+ ensureLearnedForCurrentLayers() {
155
+ const state = store();
156
+ const live = state.live;
157
+ if (live === undefined)
158
+ return;
159
+ const sections = collectSectionNames(live.systemPrompt);
160
+ const tools = collectToolNames(live.tools);
161
+ if (signatureOf(sections) === state.learnedSectionSignature && signatureOf(tools) === state.learnedToolSignature)
162
+ return;
163
+ this.learnExisting(live.registry, live.systemPrompt, live.tools);
164
+ }
165
+ /**
166
+ * The tools registered by the fibers that registered `sectionName`, plus any
167
+ * exact tool family recovered from that section's pre-mounted plugin.
168
+ *
169
+ * @param sectionName - full prompt-section name, e.g. `tool:jobs`.
170
+ * @returns `owned: false` when no registering fiber or tool declaration was
171
+ * observed, which the caller must treat as "not a tool family" rather than
172
+ * "empty family".
173
+ */
174
+ lookup(sectionName) {
175
+ this.ensureLearnedForCurrentLayers();
176
+ const names = new Set(store().learnedSectionTools.get(sectionName) ?? []);
177
+ const refs = store().sectionFibers.get(sectionName);
178
+ let sawLive = false;
179
+ if (refs !== undefined) {
180
+ const live = [];
181
+ for (const ref of refs) {
182
+ const fiber = ref.deref();
183
+ if (fiber === undefined)
184
+ continue;
185
+ sawLive = true;
186
+ live.push(ref);
187
+ for (const name of store().toolsByFiber.get(fiber) ?? [])
188
+ names.add(name);
189
+ }
190
+ if (!sawLive)
191
+ store().sectionFibers.delete(sectionName);
192
+ else if (live.length !== refs.length)
193
+ store().sectionFibers.set(sectionName, live);
194
+ }
195
+ if (names.size === 0 && !sawLive)
196
+ return { owned: false, tools: [] };
197
+ return { owned: true, tools: [...names] };
198
+ }
199
+ }
200
+ const SHARED = new PromptToolAffinity();
201
+ /** The object that owns a service instance's methods. */
202
+ function prototypeOf(value) {
203
+ if (value === null || (typeof value !== "object" && typeof value !== "function"))
204
+ return undefined;
205
+ const proto = Object.getPrototypeOf(value);
206
+ return proto !== null && typeof proto === "object" ? proto : undefined;
207
+ }
208
+ /** The plugin fiber a service call is made from, if the context still carries one. */
209
+ function fiberOf(serviceInstance) {
210
+ if (serviceInstance === null || typeof serviceInstance !== "object")
211
+ return undefined;
212
+ const ctx = serviceInstance.ctx;
213
+ if (ctx === null || typeof ctx !== "object")
214
+ return undefined;
215
+ const fiber = ctx.fiber;
216
+ return fiber !== null && typeof fiber === "object" ? fiber : undefined;
217
+ }
218
+ /** The section name of a `section()` argument. */
219
+ function sectionNameOf(section) {
220
+ if (section === null || typeof section !== "object")
221
+ return undefined;
222
+ const name = section.name;
223
+ return typeof name === "string" && name.length > 0 ? name : undefined;
224
+ }
225
+ /** The tool name of a `register()` argument. */
226
+ function toolNameOf(definition) {
227
+ if (definition === null || typeof definition !== "object")
228
+ return undefined;
229
+ const name = definition.name;
230
+ return typeof name === "string" && name.length > 0 ? name : undefined;
231
+ }
232
+ /** Replace `proto.section` with an observing wrapper, once. */
233
+ function wrapSection(proto) {
234
+ const state = store();
235
+ if (state.patched.has(proto))
236
+ return;
237
+ const target = proto;
238
+ const original = target.section;
239
+ if (typeof original !== "function")
240
+ return;
241
+ state.patched.add(proto);
242
+ target.section = function observedSection(section) {
243
+ const fiber = fiberOf(this);
244
+ const name = sectionNameOf(section);
245
+ const disposer = Reflect.apply(original, this, [section]);
246
+ if (fiber === undefined || name === undefined)
247
+ return disposer;
248
+ rememberSection(name, fiber);
249
+ return observeDisposal(disposer, () => forgetSection(name, fiber));
250
+ };
251
+ }
252
+ /** Replace `proto.register` with an observing wrapper, once. */
253
+ function wrapRegister(proto) {
254
+ const state = store();
255
+ if (state.patched.has(proto))
256
+ return;
257
+ const target = proto;
258
+ const original = target.register;
259
+ if (typeof original !== "function")
260
+ return;
261
+ state.patched.add(proto);
262
+ target.register = function observedRegister(definition, ...rest) {
263
+ const fiber = fiberOf(this);
264
+ const name = toolNameOf(definition);
265
+ const disposer = Reflect.apply(original, this, [definition, ...rest]);
266
+ if (fiber === undefined || name === undefined)
267
+ return disposer;
268
+ rememberTool(name, fiber);
269
+ return observeDisposal(disposer, () => forgetTool(name, fiber));
270
+ };
271
+ }
272
+ /** Recover all live fibers from Cordis's registry service. */
273
+ function groupFibers(registry) {
274
+ const groups = new Map();
275
+ const values = registry?.values;
276
+ if (typeof values !== "function")
277
+ return [];
278
+ for (const runtime of values.call(registry)) {
279
+ const fibers = runtime?.fibers;
280
+ if (fibers === undefined)
281
+ continue;
282
+ for (const fiber of fibers) {
283
+ if (fiber === null || typeof fiber !== "object")
284
+ continue;
285
+ const key = fiber.entry ?? fiber;
286
+ const group = groups.get(key);
287
+ if (group === undefined)
288
+ groups.set(key, [fiber]);
289
+ else
290
+ group.push(fiber);
291
+ }
292
+ }
293
+ return [...groups.values()];
294
+ }
295
+ /** Names of every prompt section in the global and scoped prompt layers. */
296
+ function collectSectionNames(systemPrompt) {
297
+ const layers = systemPrompt?.layers;
298
+ const names = new Set();
299
+ addNames(names, layers?.global?.sections);
300
+ if (layers?.scoped !== undefined) {
301
+ for (const layer of layers.scoped.values())
302
+ addNames(names, layer.sections);
303
+ }
304
+ return [...names];
305
+ }
306
+ /** A stable identity for the exact set of names currently in a layer. */
307
+ function signatureOf(names) {
308
+ return [...names].sort().join("\0");
309
+ }
310
+ /** Names of every tool in the global and scoped tool layers. */
311
+ function collectToolNames(tools) {
312
+ const layers = tools?.layers;
313
+ const names = new Set();
314
+ addNames(names, layers?.global?.tools);
315
+ if (layers?.scoped !== undefined) {
316
+ for (const layer of layers.scoped.values())
317
+ addNames(names, layer.tools);
318
+ }
319
+ return [...names];
320
+ }
321
+ function addNames(target, entries) {
322
+ if (entries === undefined)
323
+ return;
324
+ for (const name of entries.keys())
325
+ target.add(name);
326
+ }
327
+ /** `Function.prototype.toString` of the fiber's plugin callback. */
328
+ function callbackSource(fiber) {
329
+ const callback = fiber.runtime?.callback;
330
+ if (typeof callback !== "function")
331
+ return "";
332
+ try {
333
+ return Function.prototype.toString.call(callback);
334
+ }
335
+ catch {
336
+ return "";
337
+ }
338
+ }
339
+ /** Section/tool effects in the order the fiber created them. */
340
+ function effectKinds(fiber) {
341
+ if (typeof fiber.getEffects !== "function")
342
+ return undefined;
343
+ let effects;
344
+ try {
345
+ effects = fiber.getEffects();
346
+ }
347
+ catch {
348
+ return undefined;
349
+ }
350
+ const kinds = [];
351
+ for (const effect of effects) {
352
+ if (effect.label === "systemPrompt.section()")
353
+ kinds.push("section");
354
+ else if (effect.label === "tools.register()")
355
+ kinds.push("tool");
356
+ }
357
+ return kinds;
358
+ }
359
+ /** Declarations of known sections and tools in a source string, in source order. */
360
+ function registrationEvents(source, sectionNames, toolNames) {
361
+ const events = [];
362
+ for (const name of sectionNames) {
363
+ const pattern = new RegExp(`\\.systemPrompt\\.section\\(\\s*\\{[^{}]{0,400}?\\bname\\s*:\\s*["'\`]${escapeRegExp(name)}["'\`]`, "g");
364
+ for (const match of source.matchAll(pattern)) {
365
+ if (match.index !== undefined)
366
+ events.push({ kind: "section", name, index: match.index });
367
+ }
368
+ }
369
+ for (const name of toolNames) {
370
+ const pattern = new RegExp(`defineTool\\(\\s*\\{[^{}]{0,400}?\\bname\\s*:\\s*["'\`]${escapeRegExp(name)}["'\`]`, "g");
371
+ for (const match of source.matchAll(pattern)) {
372
+ if (match.index !== undefined)
373
+ events.push({ kind: "tool", name, index: match.index });
374
+ }
375
+ }
376
+ return events.sort((left, right) => left.index - right.index);
377
+ }
378
+ /** Match one source event to each section/tool effect of a fiber. */
379
+ function pairEvents(events, kinds) {
380
+ if (kinds === undefined || kinds.length === 0 || events.length !== kinds.length)
381
+ return undefined;
382
+ const pairs = new Map();
383
+ let current;
384
+ for (let index = 0; index < kinds.length; index += 1) {
385
+ const event = events[index];
386
+ if (event.kind !== kinds[index])
387
+ return undefined;
388
+ if (event.kind === "section") {
389
+ current = event.name;
390
+ if (!pairs.has(current))
391
+ pairs.set(current, new Set());
392
+ }
393
+ else {
394
+ if (current === undefined)
395
+ return undefined;
396
+ pairs.get(current).add(event.name);
397
+ }
398
+ }
399
+ return pairs;
400
+ }
401
+ /**
402
+ * Pair sections and tools inside a module's function declarations.
403
+ *
404
+ * A plugin can delegate `apply()` to module-level helpers
405
+ * (`applyReadTool`, `registerUserTerminalTools`, ...); those helpers are not
406
+ * Cordis fibers of their own, so their registration order is not available
407
+ * from `getEffects()`. Function-local declaration order is the exact authoring
408
+ * order in that case. A helper with one section and several tools owns all of
409
+ * them; a module with only one section and several tool helpers (the terminal
410
+ * panel shape) owns all module tools.
411
+ */
412
+ function modulePairs(source, sectionNames, toolNames) {
413
+ const result = new Map();
414
+ const moduleSections = new Set();
415
+ const moduleTools = new Set();
416
+ for (const block of functionBodies(source)) {
417
+ const events = registrationEvents(block, sectionNames, toolNames);
418
+ const sections = events.filter((event) => event.kind === "section");
419
+ const tools = events.filter((event) => event.kind === "tool");
420
+ for (const event of sections)
421
+ moduleSections.add(event.name);
422
+ for (const event of tools)
423
+ moduleTools.add(event.name);
424
+ if (sections.length === 0 || tools.length === 0)
425
+ continue;
426
+ if (sections.length === 1) {
427
+ let members = result.get(sections[0].name);
428
+ if (members === undefined) {
429
+ members = new Set();
430
+ result.set(sections[0].name, members);
431
+ }
432
+ for (const event of tools)
433
+ members.add(event.name);
434
+ continue;
435
+ }
436
+ // Multiple section/tool declarations in one function: use their source order.
437
+ const pairs = pairEvents(events, events.map((event) => event.kind));
438
+ if (pairs !== undefined) {
439
+ for (const [section, members] of pairs) {
440
+ let existing = result.get(section);
441
+ if (existing === undefined) {
442
+ existing = new Set();
443
+ result.set(section, existing);
444
+ }
445
+ for (const tool of members)
446
+ existing.add(tool);
447
+ }
448
+ }
449
+ }
450
+ if (result.size === 0 && moduleSections.size === 1 && moduleTools.size > 0) {
451
+ result.set([...moduleSections][0], new Set(moduleTools));
452
+ }
453
+ return result;
454
+ }
455
+ /** Function bodies in a module, with nested braces tracked outside strings. */
456
+ function functionBodies(source) {
457
+ const bodies = [];
458
+ const pattern = /function\s+[A-Za-z0-9_$]+\s*\([^)]*\)\s*\{/g;
459
+ for (const match of source.matchAll(pattern)) {
460
+ if (match.index === undefined)
461
+ continue;
462
+ const start = match.index + match[0].length;
463
+ const end = matchingBrace(source, start);
464
+ if (end !== undefined)
465
+ bodies.push(source.slice(start, end));
466
+ }
467
+ return bodies;
468
+ }
469
+ /** Index of the brace closing a block that starts just after `{`. */
470
+ function matchingBrace(source, start) {
471
+ let depth = 1;
472
+ let quote;
473
+ let escaped = false;
474
+ for (let index = start; index < source.length; index += 1) {
475
+ const character = source[index];
476
+ if (quote !== undefined) {
477
+ if (escaped)
478
+ escaped = false;
479
+ else if (character === "\\")
480
+ escaped = true;
481
+ else if (character === quote)
482
+ quote = undefined;
483
+ continue;
484
+ }
485
+ if (character === "'" || character === '"' || character === "`") {
486
+ quote = character;
487
+ continue;
488
+ }
489
+ if (character === "{")
490
+ depth += 1;
491
+ else if (character === "}") {
492
+ depth -= 1;
493
+ if (depth === 0)
494
+ return index;
495
+ }
496
+ }
497
+ return undefined;
498
+ }
499
+ /** Read the entry's module source when the callback delegates to a module helper. */
500
+ function moduleSourceOf(entry) {
501
+ const name = entry.options?.name;
502
+ const baseUrl = entry.parent?.tree?.ctx?.baseUrl;
503
+ if (typeof name !== "string" || name.startsWith("cordis:") || baseUrl === undefined)
504
+ return undefined;
505
+ const key = `${String(baseUrl)}\0${name}`;
506
+ const state = store();
507
+ if (state.moduleSources.has(key))
508
+ return state.moduleSources.get(key);
509
+ let source;
510
+ try {
511
+ const base = typeof baseUrl === "string" || baseUrl instanceof URL
512
+ ? String(baseUrl)
513
+ : undefined;
514
+ if (base !== undefined) {
515
+ const requireFrom = createRequire(requesterPath(base));
516
+ const file = requireFrom.resolve(name);
517
+ source = readFileSync(file, "utf8");
518
+ }
519
+ }
520
+ catch {
521
+ source = undefined;
522
+ }
523
+ state.moduleSources.set(key, source);
524
+ return source;
525
+ }
526
+ /** A file-like anchor for `createRequire`, including directory base URLs. */
527
+ function requesterPath(base) {
528
+ if (/^file:/i.test(base)) {
529
+ try {
530
+ return new URL("__dsh_tool_manager__.js", base).href;
531
+ }
532
+ catch {
533
+ return base;
534
+ }
535
+ }
536
+ if (/[\\/]$/.test(base))
537
+ return `${base}__dsh_tool_manager__.js`;
538
+ return base;
539
+ }
540
+ function escapeRegExp(value) {
541
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
542
+ }
543
+ /** Record an exact set of members recovered from a pre-mounted plugin. */
544
+ function rememberLearned(sectionName, tools) {
545
+ if (!sectionName.startsWith("tool:"))
546
+ return;
547
+ const state = store();
548
+ let members = state.learnedSectionTools.get(sectionName);
549
+ if (members === undefined) {
550
+ members = new Set();
551
+ state.learnedSectionTools.set(sectionName, members);
552
+ }
553
+ for (const tool of tools)
554
+ if (tool.length > 0)
555
+ members.add(tool);
556
+ }
557
+ /** Keep a section's registering fiber without holding a dead plugin alive. */
558
+ function rememberSection(name, fiber) {
559
+ const refs = store().sectionFibers.get(name) ?? [];
560
+ const kept = refs.filter((ref) => {
561
+ const current = ref.deref();
562
+ return current !== undefined && current !== fiber;
563
+ });
564
+ kept.push(new WeakRef(fiber));
565
+ store().sectionFibers.set(name, kept);
566
+ }
567
+ /** Drop one fiber from a section's owners, leaving any other scope's mount. */
568
+ function forgetSection(name, fiber) {
569
+ const refs = store().sectionFibers.get(name);
570
+ if (refs === undefined)
571
+ return;
572
+ const kept = refs.filter((ref) => {
573
+ const current = ref.deref();
574
+ return current !== undefined && current !== fiber;
575
+ });
576
+ if (kept.length === 0)
577
+ store().sectionFibers.delete(name);
578
+ else
579
+ store().sectionFibers.set(name, kept);
580
+ }
581
+ /** Record one tool under its registering fiber. */
582
+ function rememberTool(name, fiber) {
583
+ const state = store();
584
+ let names = state.toolsByFiber.get(fiber);
585
+ if (names === undefined) {
586
+ names = new Set();
587
+ state.toolsByFiber.set(fiber, names);
588
+ }
589
+ names.add(name);
590
+ }
591
+ /** Drop one tool from its registering fiber. */
592
+ function forgetTool(name, fiber) {
593
+ const names = store().toolsByFiber.get(fiber);
594
+ if (names === undefined)
595
+ return;
596
+ names.delete(name);
597
+ if (names.size === 0)
598
+ store().toolsByFiber.delete(fiber);
599
+ }
600
+ /** Run `callback` when a disposer is called, preserving the disposer's return. */
601
+ function observeDisposal(disposer, callback) {
602
+ if (typeof disposer !== "function")
603
+ return disposer;
604
+ return function observedDisposal(...args) {
605
+ const result = Reflect.apply(disposer, this, args);
606
+ callback();
607
+ return result;
608
+ };
609
+ }
610
+ /**
611
+ * Clear the process-wide store. Intended for tests that need a clean process.
612
+ */
613
+ export function resetPromptAffinity() {
614
+ const holder = globalThis;
615
+ delete holder[STORE_KEY];
616
+ }
617
+ //# sourceMappingURL=prompt-affinity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-affinity.js","sourceRoot":"","sources":["../src/prompt-affinity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAoE5C,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;AAEjE,SAAS,KAAK;IACZ,MAAM,MAAM,GAAG,UAAwE,CAAC;IACxF,IAAI,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IAChC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,GAAG;YACR,YAAY,EAAE,IAAI,OAAO,EAAE;YAC3B,aAAa,EAAE,IAAI,GAAG,EAAE;YACxB,mBAAmB,EAAE,IAAI,GAAG,EAAE;YAC9B,OAAO,EAAE,IAAI,OAAO,EAAE;YACtB,aAAa,EAAE,IAAI,GAAG,EAAE;SACzB,CAAC;QACF,MAAM,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC;IAC9B,CAAC;IACD,uEAAuE;IACvE,OAAO,CAAC,mBAAmB,KAAK,IAAI,GAAG,EAAE,CAAC;IAC1C,OAAO,CAAC,aAAa,KAAK,IAAI,GAAG,EAAE,CAAC;IACpC,OAAO,OAAO,CAAC;AACjB,CAAC;AAUD;;;;;;GAMG;AACH,MAAM,OAAO,kBAAkB;IAC7B,+DAA+D;IAC/D,MAAM,CAAC,MAAM;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