dsh-boost 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +97 -33
- package/README.md +85 -32
- package/dist/gate/decide.js +33 -2
- package/dist/gate/decide.js.map +1 -1
- package/dist/hooks/llm-stream.js +129 -54
- package/dist/hooks/llm-stream.js.map +1 -1
- package/dist/hooks/post-execute.js +104 -21
- package/dist/hooks/post-execute.js.map +1 -1
- package/dist/hooks/session-state.js +18 -8
- package/dist/hooks/session-state.js.map +1 -1
- package/dist/index.js +371 -67
- package/dist/index.js.map +1 -1
- package/dist/scope/doc.js.map +1 -1
- package/dist/scope/store.js +24 -9
- package/dist/scope/store.js.map +1 -1
- package/package.json +8 -4
- package/dist/admission/fixed-cost.d.ts +0 -23
- package/dist/admission/ledger.d.ts +0 -113
- package/dist/admission/retrieval.d.ts +0 -65
- package/dist/admission/usage.d.ts +0 -75
- package/dist/config.d.ts +0 -43
- package/dist/gate/binding.d.ts +0 -113
- package/dist/gate/decide.d.ts +0 -82
- package/dist/gate/guard.d.ts +0 -69
- package/dist/gate/invalidate.d.ts +0 -112
- package/dist/gate/plan.d.ts +0 -86
- package/dist/hooks/clock.d.ts +0 -68
- package/dist/hooks/execute.d.ts +0 -79
- package/dist/hooks/llm-stream.d.ts +0 -283
- package/dist/hooks/pending.d.ts +0 -89
- package/dist/hooks/post-execute.d.ts +0 -257
- package/dist/hooks/session-state.d.ts +0 -158
- package/dist/hooks/synthesize.d.ts +0 -74
- package/dist/host/loader.d.ts +0 -23
- package/dist/host/platform.d.ts +0 -18
- package/dist/host/root.d.ts +0 -25
- package/dist/projection/apply.d.ts +0 -174
- package/dist/projection/canonicalise.d.ts +0 -43
- package/dist/projection/counters.d.ts +0 -65
- package/dist/projection/truncate.d.ts +0 -47
- package/dist/prompt/protocol.d.ts +0 -45
- package/dist/receipts/store.d.ts +0 -198
- package/dist/scope/doc.d.ts +0 -117
- package/dist/scope/resolve.d.ts +0 -91
- package/dist/scope/store.d.ts +0 -135
- package/dist/selector/jev.d.ts +0 -93
- package/dist/tools/boost.d.ts +0 -380
- package/dist/tools/family.d.ts +0 -26
package/dist/index.js
CHANGED
|
@@ -92,6 +92,42 @@ function isVerifiedHostVersion(version) {
|
|
|
92
92
|
* `ERR_HOST_COMPLETE_SECTION`).
|
|
93
93
|
*/
|
|
94
94
|
const ERR_HOST_VERSION_MISMATCH = 'ERR_HOST_VERSION_MISMATCH';
|
|
95
|
+
/**
|
|
96
|
+
* Stable host code: `system-prompt/assemble` was never observed.
|
|
97
|
+
*
|
|
98
|
+
* `ctx.on` accepts any string, so a renamed event registers successfully and
|
|
99
|
+
* then never fires. This module needs assemble to warm the visibility cache
|
|
100
|
+
* before section text resolves (design D4). The host runs assemble before
|
|
101
|
+
* `agent/pre-step`, so the first pre-step without a single observed assemble is
|
|
102
|
+
* proof the seam is gone. Raised once per process, on the first step that
|
|
103
|
+
* needed it; the only signal is "never fired", so the event name also joins
|
|
104
|
+
* `missingMounts`, and `status.degraded` reports `ERR_BOOST_PARTIAL_MOUNT`
|
|
105
|
+
* (the per-event code is carried by the warning and the mount list, which is
|
|
106
|
+
* the reachable status channel without a new status-side mapping).
|
|
107
|
+
*/
|
|
108
|
+
const ERR_HOST_NO_SYSTEM_PROMPT_ASSEMBLE = 'ERR_HOST_NO_SYSTEM_PROMPT_ASSEMBLE';
|
|
109
|
+
/**
|
|
110
|
+
* Stable host code: `agent/pre-step` was never observed.
|
|
111
|
+
*
|
|
112
|
+
* Raised once, on the first main `llm/stream` request for a session whose step
|
|
113
|
+
* clock was never driven. Without pre-step the turn is unknown, so every
|
|
114
|
+
* pending substitution is abandoned; the warning says why instead of leaving
|
|
115
|
+
* `status` healthy. Auxiliary (`purpose`-tagged) streams do not need the clock
|
|
116
|
+
* and do not raise it. As with assemble, the event name joins `missingMounts`
|
|
117
|
+
* and the per-event code is carried by the one-shot warning.
|
|
118
|
+
*/
|
|
119
|
+
const ERR_HOST_NO_AGENT_PRE_STEP = 'ERR_HOST_NO_AGENT_PRE_STEP';
|
|
120
|
+
/**
|
|
121
|
+
* Stable host code: the selector route had to come from `agent/request`.
|
|
122
|
+
*
|
|
123
|
+
* `agent/pre-step` carries `modelSelection` and is the non-deprecated source.
|
|
124
|
+
* When a host leaves it empty, the deprecated `agent/request` resolved config
|
|
125
|
+
* is the only route left; the selector can still run, but the dependency is
|
|
126
|
+
* reported once because that event is marked `@deprecated`. Absence of
|
|
127
|
+
* `agent/request` itself is non-fatal and is reported separately by
|
|
128
|
+
* `ERR_HOST_NO_AGENT_REQUEST`.
|
|
129
|
+
*/
|
|
130
|
+
const ERR_HOST_NO_MODEL_SELECTION = 'ERR_HOST_NO_MODEL_SELECTION';
|
|
95
131
|
/** The app-boot package whose version IS the dsh runtime version. */
|
|
96
132
|
const HOST_VERSION_PACKAGE = '@deepseek-ai/dsh-app-boot';
|
|
97
133
|
/** Node's resolver, used only when the host service is unavailable. */
|
|
@@ -167,10 +203,12 @@ let duplicateMountAttempts = 0;
|
|
|
167
203
|
*
|
|
168
204
|
* `dsh-system-prompt` builds a plain `Error` whose message starts with
|
|
169
205
|
* `prompt section "<name>" is already registered` (global and scoped variants
|
|
170
|
-
* both start that way) and exposes no code.
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
206
|
+
* both start that way) and exposes no code. The message alone proves only that
|
|
207
|
+
* *some* plugin owns the name — another plugin using `dsh-boost` produces the
|
|
208
|
+
* same text — so it is combined with {@link ownSectionRegistries}, the mount
|
|
209
|
+
* marker this module owns (review row 32). A duplicate from a foreign owner is
|
|
210
|
+
* a section-mount failure, not "this plugin is already wired": the remaining
|
|
211
|
+
* hooks and the control tool must still mount.
|
|
174
212
|
*/
|
|
175
213
|
function isDuplicateSectionError(error) {
|
|
176
214
|
return (error instanceof Error &&
|
|
@@ -206,8 +244,31 @@ function lazyService(ctx, name) {
|
|
|
206
244
|
get.reset = () => {
|
|
207
245
|
resolved = undefined;
|
|
208
246
|
};
|
|
247
|
+
get.refresh = () => {
|
|
248
|
+
resolved = serviceOf(ctx, name);
|
|
249
|
+
return resolved;
|
|
250
|
+
};
|
|
209
251
|
return get;
|
|
210
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* Run `invalidate` when the owning fiber unloads.
|
|
255
|
+
*
|
|
256
|
+
* Used for the three soft-service memos: a disposed provider must not leave a
|
|
257
|
+
* stale binding behind for a later provider that reuses the same name (review
|
|
258
|
+
* row 6). A host without the effect seam is not a failure: the point-of-use
|
|
259
|
+
* resets still recover, only the disposal edge is missed.
|
|
260
|
+
*/
|
|
261
|
+
function onDispose(ctx, invalidate) {
|
|
262
|
+
try {
|
|
263
|
+
const effect = ctx.effect;
|
|
264
|
+
if (typeof effect !== 'function')
|
|
265
|
+
return;
|
|
266
|
+
effect.call(ctx, () => invalidate, 'dsh-boost: soft service bindings');
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
// A host that rejects the effect still gets the per-use resets.
|
|
270
|
+
}
|
|
271
|
+
}
|
|
211
272
|
/**
|
|
212
273
|
* The session id behind an agent or a `Session`.
|
|
213
274
|
*
|
|
@@ -467,26 +528,78 @@ function systemTextOf(options) {
|
|
|
467
528
|
*
|
|
468
529
|
* `agent/pre-step` is the non-deprecated clock seam (`agent/request` is
|
|
469
530
|
* marked `@deprecated`); it fires once per proposed step with the host
|
|
470
|
-
* `turn`/`step
|
|
471
|
-
*
|
|
531
|
+
* `turn`/`step`, and it already carries the captured `modelSelection`. The
|
|
532
|
+
* selector route is read from there first; `agent/request`'s resolved config
|
|
533
|
+
* is only the compatibility path for a host whose pre-step does not populate
|
|
534
|
+
* `modelSelection`, and it warns once when it is used. The visibility warm
|
|
535
|
+
* stays at `assemble` (D4); `agent/pre-step` warms only when `assemble` never
|
|
536
|
+
* fired, so no session's visibility depends on the deprecated event. A model
|
|
472
537
|
* request that reaches `llm/stream` without any observed `agent/request` is
|
|
473
|
-
* reported once with `ERR_HOST_NO_AGENT_REQUEST
|
|
474
|
-
*
|
|
538
|
+
* still reported once with `ERR_HOST_NO_AGENT_REQUEST`; the route itself does
|
|
539
|
+
* not depend on it.
|
|
540
|
+
*
|
|
541
|
+
* ## Every mount is attributed
|
|
542
|
+
*
|
|
543
|
+
* `ctx.on` accepts any string (`cordis/src/events.ts`), so a renamed host
|
|
544
|
+
* event registers successfully and then never fires. Registration failures and
|
|
545
|
+
* "never observed" are therefore different signals, and both must reach the
|
|
546
|
+
* operator:
|
|
547
|
+
*
|
|
548
|
+
* - Each listener is mounted in its own try/catch. A throw names that event in
|
|
549
|
+
* `missingMounts`, and the remaining listeners still mount. Before this, one
|
|
550
|
+
* bare catch around the whole wiring left `status.degraded` empty and lost
|
|
551
|
+
* `session/disposed` (per-session state leaked for the process lifetime).
|
|
552
|
+
* - `ERR_HOST_NO_SYSTEM_PROMPT_ASSEMBLE` is raised once when the first
|
|
553
|
+
* `agent/pre-step` arrives without a single observed assemble. The host
|
|
554
|
+
* order guarantees assemble first, so its absence is a renamed/removed
|
|
555
|
+
* event. Its only evidence is "never observed"; the event name also joins
|
|
556
|
+
* `missingMounts`, so `status.degraded` reports `ERR_BOOST_PARTIAL_MOUNT`
|
|
557
|
+
* (the per-event code exists in the warning and the mount list).
|
|
558
|
+
* - `ERR_HOST_NO_AGENT_PRE_STEP` is raised once when the first main
|
|
559
|
+
* `llm/stream` request arrives without any observed pre-step for that
|
|
560
|
+
* session. The step clock cannot advance without it, so substitution is
|
|
561
|
+
* impossible; auxiliary (`purpose`-tagged) streams do not need it and do not
|
|
562
|
+
* raise the warning.
|
|
475
563
|
*
|
|
476
564
|
* `session/event` (`turn/end`), `session/flush` and `session/disposed` call
|
|
477
565
|
* `ReceiptStore.flush()` so the turn-end durability the design promises is
|
|
478
566
|
* real. `session/disposed` also drops every per-session map the assembly owns
|
|
479
567
|
* and tells the stores to evict their state.
|
|
480
568
|
*/
|
|
481
|
-
function wireSessionEvents(ctx, deps, scope, registry, sessions, horizon, workspaces, routes, counters) {
|
|
569
|
+
function wireSessionEvents(ctx, deps, scope, registry, sessions, horizon, workspaces, routes, counters, missing, ownsSection) {
|
|
482
570
|
/** Session ids seen at `agent/pre-step`; a `llm/stream` without a request is drift. */
|
|
483
571
|
const preStepSeen = new Set();
|
|
484
572
|
/** Session ids observed on `agent/request`. */
|
|
485
573
|
const requestSeen = new Set();
|
|
574
|
+
let assembleSeen = false;
|
|
486
575
|
let warnedMissingRequest = false;
|
|
487
|
-
/** Warn once per process about a prompt that swallowed the protocol section. */
|
|
488
576
|
let warnedCompleteSection = false;
|
|
489
|
-
|
|
577
|
+
let warnedNoAssemble = false;
|
|
578
|
+
let warnedNoPreStep = false;
|
|
579
|
+
let warnedRouteFallback = false;
|
|
580
|
+
/**
|
|
581
|
+
* Mount one listener in its own try/catch.
|
|
582
|
+
*
|
|
583
|
+
* A failure names the event and is recorded in `missingMounts`; it never
|
|
584
|
+
* stops the next listener. `true` means the registration itself succeeded,
|
|
585
|
+
* which is not proof the host ever emits the event (see the never-observed
|
|
586
|
+
* warnings below).
|
|
587
|
+
*/
|
|
588
|
+
const mount = (event, handler, options) => {
|
|
589
|
+
try {
|
|
590
|
+
ctx.on(event, handler, options);
|
|
591
|
+
return true;
|
|
592
|
+
}
|
|
593
|
+
catch (error) {
|
|
594
|
+
missing.add(event);
|
|
595
|
+
ctx.logger?.warn?.(`dsh-boost: ERR_BOOST_PARTIAL_MOUNT: ${event} mount failed (${messageOf(error)})`);
|
|
596
|
+
return false;
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
// `system-prompt/assemble` stays first: it is the seam that resolves the
|
|
600
|
+
// section text every later step sees (design D4).
|
|
601
|
+
const assembleMounted = mount('system-prompt/assemble', async (_assembly, context, next) => {
|
|
602
|
+
assembleSeen = true;
|
|
490
603
|
const resolved = await next();
|
|
491
604
|
try {
|
|
492
605
|
// `dsh-agent` augments `AssembleContext` with the real `Agent`; `scope`
|
|
@@ -502,10 +615,15 @@ function wireSessionEvents(ctx, deps, scope, registry, sessions, horizon, worksp
|
|
|
502
615
|
// into an assembly with no agent. Count the decision, not the
|
|
503
616
|
// section's presence — design §5.5:378 asks for every assembly to be
|
|
504
617
|
// judged.
|
|
505
|
-
|
|
506
|
-
|
|
618
|
+
if (ownsSection)
|
|
619
|
+
counters.protocolSuppressed();
|
|
620
|
+
return ownsSection ? patchProtocolSection(resolved, false) : resolved;
|
|
507
621
|
}
|
|
508
622
|
const visible = await warmVisibility(scope, registry, agent, sessionId, workspaces);
|
|
623
|
+
// A foreign plugin owns the section name (row 32): warm the judgement the
|
|
624
|
+
// decision path needs, but never rewrite another plugin's text.
|
|
625
|
+
if (!ownsSection)
|
|
626
|
+
return resolved;
|
|
509
627
|
// Same rule for an invisible workspace: the section is suppressed for
|
|
510
628
|
// this assembly, so the operator gets a live signal in `boost status`.
|
|
511
629
|
// A visible one never increments, so the count stays a failure count.
|
|
@@ -517,11 +635,19 @@ function wireSessionEvents(ctx, deps, scope, registry, sessions, horizon, worksp
|
|
|
517
635
|
return resolved;
|
|
518
636
|
}
|
|
519
637
|
});
|
|
520
|
-
|
|
638
|
+
const preStepMounted = mount('agent/pre-step', async (payload, next) => {
|
|
521
639
|
const request = (payload ?? {});
|
|
522
640
|
const sessionId = sessionIdOf(request.agent);
|
|
523
641
|
if (sessionId !== undefined) {
|
|
524
642
|
preStepSeen.add(sessionId);
|
|
643
|
+
// Row 8: assemble runs before pre-step in the host's own order. If it
|
|
644
|
+
// has never run by the first step, the event was renamed or removed and
|
|
645
|
+
// the protocol section cannot be warmed or patched.
|
|
646
|
+
if (!assembleSeen && !warnedNoAssemble && assembleMounted) {
|
|
647
|
+
warnedNoAssemble = true;
|
|
648
|
+
missing.add('system-prompt/assemble');
|
|
649
|
+
ctx.logger?.warn?.(`${ERR_HOST_NO_SYSTEM_PROMPT_ASSEMBLE}: system-prompt/assemble was not observed before the first agent/pre-step; the protocol section cannot be warmed or patched (the event may have been renamed or removed)`);
|
|
650
|
+
}
|
|
525
651
|
try {
|
|
526
652
|
sessions.onModelRequest(sessionId, typeof request.turn === 'number' ? request.turn : Number(request.turn), typeof request.step === 'number' ? request.step : undefined);
|
|
527
653
|
}
|
|
@@ -536,40 +662,64 @@ function wireSessionEvents(ctx, deps, scope, registry, sessions, horizon, worksp
|
|
|
536
662
|
}
|
|
537
663
|
// `agent/pre-step` already carries the captured step selection. It is
|
|
538
664
|
// the non-deprecated source for the selector route; `agent/request`'s
|
|
539
|
-
// resolved config remains a fallback for hosts that only
|
|
540
|
-
//
|
|
665
|
+
// resolved config remains a compatibility fallback for hosts that only
|
|
666
|
+
// populate it there. A later request overwrites with the same route.
|
|
541
667
|
rememberRoute(routes, sessionId, request.modelSelection);
|
|
668
|
+
// The warm belongs to `system-prompt/assemble` (D4). This is the
|
|
669
|
+
// fallback for a host that skipped or renamed assemble: pre-step is the
|
|
670
|
+
// non-deprecated seam, so visibility no longer depends on the
|
|
671
|
+
// deprecated `agent/request` event.
|
|
672
|
+
if (!assembleSeen) {
|
|
673
|
+
await warmVisibility(scope, registry, request.agent, sessionId, workspaces);
|
|
674
|
+
}
|
|
542
675
|
}
|
|
543
676
|
return next();
|
|
544
677
|
});
|
|
545
|
-
|
|
678
|
+
mount('agent/request', async (payload, next) => {
|
|
546
679
|
const request = (payload ?? {});
|
|
547
680
|
const sessionId = sessionIdOf(request.agent);
|
|
548
681
|
if (sessionId !== undefined) {
|
|
549
682
|
requestSeen.add(sessionId);
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
683
|
+
// Compatibility only: when pre-step is present it already drove the
|
|
684
|
+
// clock and the horizon. This branch exists for a host that still emits
|
|
685
|
+
// the deprecated event but not the non-deprecated one.
|
|
686
|
+
if (!preStepSeen.has(sessionId)) {
|
|
687
|
+
try {
|
|
688
|
+
sessions.onModelRequest(sessionId, typeof request.turn === 'number' ? request.turn : Number(request.turn), typeof request.step === 'number' ? request.step : undefined);
|
|
689
|
+
}
|
|
690
|
+
catch {
|
|
691
|
+
// A clock that cannot be driven must not break the model request.
|
|
692
|
+
}
|
|
693
|
+
try {
|
|
694
|
+
horizon.observe(sessionId, typeof request.turn === 'number' ? request.turn : Number(request.turn), typeof request.step === 'number' ? request.step : Number(request.step));
|
|
695
|
+
}
|
|
696
|
+
catch {
|
|
697
|
+
// Same as the pre-step observation: history is an estimate.
|
|
698
|
+
}
|
|
699
|
+
if (!assembleSeen) {
|
|
700
|
+
await warmVisibility(scope, registry, request.agent, sessionId, workspaces);
|
|
701
|
+
}
|
|
561
702
|
}
|
|
562
|
-
await warmVisibility(scope, registry, request.agent, sessionId, workspaces);
|
|
563
703
|
}
|
|
564
704
|
const config = await next();
|
|
565
|
-
|
|
705
|
+
// Capability check (row 22): the non-deprecated pre-step carries
|
|
706
|
+
// `modelSelection`; when it did, this event must not overwrite the route.
|
|
707
|
+
// When it did not, the resolved config is the only source left, and the
|
|
708
|
+
// deprecated path warns once.
|
|
709
|
+
if (sessionId !== undefined && routes.get(sessionId) === undefined) {
|
|
566
710
|
rememberRoute(routes, sessionId, config);
|
|
711
|
+
if (routes.get(sessionId) !== undefined && !warnedRouteFallback) {
|
|
712
|
+
warnedRouteFallback = true;
|
|
713
|
+
ctx.logger?.warn?.(`${ERR_HOST_NO_MODEL_SELECTION}: agent/pre-step carried no modelSelection; the selector route came from the deprecated agent/request event, which may be removed`);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
567
716
|
return config;
|
|
568
717
|
});
|
|
569
718
|
// The deprecated event's disappearance would otherwise disable the selector
|
|
570
719
|
// route silently. A session that reached `llm/stream` after a pre-step but
|
|
571
720
|
// never saw `agent/request` is proof enough; the model request itself is
|
|
572
|
-
// passed through untouched.
|
|
721
|
+
// passed through untouched. The route now comes from pre-step, so this is a
|
|
722
|
+
// compatibility warning, not a correctness dependency.
|
|
573
723
|
//
|
|
574
724
|
// This listener is also the complete-section detector, and it MUST be
|
|
575
725
|
// outermost: the synthesizer mounted by `registerHooks` consumes a queued
|
|
@@ -578,16 +728,28 @@ function wireSessionEvents(ctx, deps, scope, registry, sessions, horizon, worksp
|
|
|
578
728
|
// substituted. Cordis runs the first-registered listener outermost
|
|
579
729
|
// (`events.ts` unshifts on `prepend`), so `prepend: true` is what puts the
|
|
580
730
|
// detector before the synthesizer regardless of mount order (finding 4).
|
|
581
|
-
|
|
731
|
+
mount('llm/stream', (options, next) => {
|
|
582
732
|
try {
|
|
583
733
|
const request = (options ?? {});
|
|
584
734
|
const sessionId = request.sessionId;
|
|
735
|
+
// Row 8: a main request needs the step clock, which only pre-step
|
|
736
|
+
// drives. An auxiliary (`purpose`) stream carries its own prompt and
|
|
737
|
+
// never needs it, so it is not evidence the seam is missing.
|
|
738
|
+
if (!warnedNoPreStep &&
|
|
739
|
+
preStepMounted &&
|
|
740
|
+
request.purpose === undefined &&
|
|
741
|
+
typeof sessionId === 'string' &&
|
|
742
|
+
!preStepSeen.has(sessionId)) {
|
|
743
|
+
warnedNoPreStep = true;
|
|
744
|
+
missing.add('agent/pre-step');
|
|
745
|
+
ctx.logger?.warn?.(`${ERR_HOST_NO_AGENT_PRE_STEP}: agent/pre-step was not observed before the first main llm/stream request; the step clock cannot advance (the event may have been renamed or removed)`);
|
|
746
|
+
}
|
|
585
747
|
if (!warnedMissingRequest &&
|
|
586
748
|
typeof sessionId === 'string' &&
|
|
587
749
|
preStepSeen.has(sessionId) &&
|
|
588
750
|
!requestSeen.has(sessionId)) {
|
|
589
751
|
warnedMissingRequest = true;
|
|
590
|
-
ctx.logger?.warn?.('ERR_HOST_NO_AGENT_REQUEST: agent/request was not observed before llm/stream; the
|
|
752
|
+
ctx.logger?.warn?.('ERR_HOST_NO_AGENT_REQUEST: agent/request was not observed before llm/stream; the deprecated event may have been removed (the selector route is captured from agent/pre-step modelSelection)');
|
|
591
753
|
}
|
|
592
754
|
// A `complete: true` prompt section replaces every other section after
|
|
593
755
|
// the assembly waterfall, so the protocol text
|
|
@@ -635,7 +797,7 @@ function wireSessionEvents(ctx, deps, scope, registry, sessions, horizon, worksp
|
|
|
635
797
|
// persistence contract rests on, and `session/disposed` flushes again after
|
|
636
798
|
// the last hook for the id. Receipts are evidence, so an early flush that
|
|
637
799
|
// does not happen costs latency, never correctness.
|
|
638
|
-
|
|
800
|
+
mount('session/event', (_session, event) => {
|
|
639
801
|
const type = event?.type;
|
|
640
802
|
if (type === 'turn/end') {
|
|
641
803
|
// Fire-and-forget on the real host; `flush()` never rejects.
|
|
@@ -643,8 +805,8 @@ function wireSessionEvents(ctx, deps, scope, registry, sessions, horizon, worksp
|
|
|
643
805
|
}
|
|
644
806
|
return undefined;
|
|
645
807
|
});
|
|
646
|
-
|
|
647
|
-
|
|
808
|
+
mount('session/flush', () => deps.receipts.flush());
|
|
809
|
+
mount('session/disposed', async (session) => {
|
|
648
810
|
const sessionId = sessionIdOf(session);
|
|
649
811
|
if (sessionId === undefined)
|
|
650
812
|
return;
|
|
@@ -671,6 +833,9 @@ function wireSessionEvents(ctx, deps, scope, registry, sessions, horizon, worksp
|
|
|
671
833
|
}
|
|
672
834
|
deps.receipts.disposeSession(sessionId);
|
|
673
835
|
});
|
|
836
|
+
if (missing.size > 0) {
|
|
837
|
+
ctx.logger?.warn?.(`dsh-boost: ERR_BOOST_PARTIAL_MOUNT: missing mount(s): ${[...missing].join(', ')}; the plugin is partially wired and boost status reports this code`);
|
|
838
|
+
}
|
|
674
839
|
}
|
|
675
840
|
/**
|
|
676
841
|
* Register the `boost` tool family.
|
|
@@ -696,6 +861,27 @@ function registerBoostTool(ctx, deps) {
|
|
|
696
861
|
const definition = boostTool(deps);
|
|
697
862
|
ctx.tools.register(definition, { when: () => true });
|
|
698
863
|
}
|
|
864
|
+
/**
|
|
865
|
+
* Section registries this module successfully registered into.
|
|
866
|
+
*
|
|
867
|
+
* The mount marker this module owns (review row 32). The host's duplicate
|
|
868
|
+
* message is generic: another plugin registering `dsh-boost` produces exactly
|
|
869
|
+
* the same text. A duplicate therefore counts as "this plugin is already
|
|
870
|
+
* wired" only when the same prompt registry object received this module's
|
|
871
|
+
* section earlier in the process. A foreign owner is a section-mount failure:
|
|
872
|
+
* the remaining hooks and the control tool still mount, and the foreign text
|
|
873
|
+
* is never rewritten.
|
|
874
|
+
*/
|
|
875
|
+
const ownSectionRegistries = new WeakSet();
|
|
876
|
+
/**
|
|
877
|
+
* Prompt registries this module already mounted its hooks and tool against.
|
|
878
|
+
*
|
|
879
|
+
* Separate from {@link ownSectionRegistries}: a foreign section owner means
|
|
880
|
+
* this module does not own the section text, but a second apply over the same
|
|
881
|
+
* registry must still not mount the hooks twice. Marked once a non-duplicate
|
|
882
|
+
* apply has finished mounting, and consulted only for the duplicate decision.
|
|
883
|
+
*/
|
|
884
|
+
const mountedRegistries = new WeakSet();
|
|
699
885
|
/** The mount label the prompt section reports when it cannot be registered. */
|
|
700
886
|
const MOUNT_SECTION = 'systemPrompt.section';
|
|
701
887
|
/**
|
|
@@ -711,8 +897,11 @@ const MOUNT_SECTION = 'systemPrompt.section';
|
|
|
711
897
|
* still describes the three event mounts, and those are then mounted one by one
|
|
712
898
|
* so a failure names the mount that failed and lands in `missing`.
|
|
713
899
|
*
|
|
714
|
-
* Returns `
|
|
715
|
-
* error
|
|
900
|
+
* Returns `alreadyMounted` only when the section error is the host's
|
|
901
|
+
* duplicate-registration error AND this module registered that same registry
|
|
902
|
+
* earlier (the mount marker): a previous apply owns every mount and this one
|
|
903
|
+
* must register nothing. A duplicate from another plugin is a section-mount
|
|
904
|
+
* failure, so the remaining mounts still happen (review row 32).
|
|
716
905
|
*/
|
|
717
906
|
function mountHooks(ctx, deps, missing) {
|
|
718
907
|
const deferred = [];
|
|
@@ -742,20 +931,39 @@ function mountHooks(ctx, deps, missing) {
|
|
|
742
931
|
catch (error) {
|
|
743
932
|
registrationError = error;
|
|
744
933
|
}
|
|
934
|
+
let ownsSection = false;
|
|
935
|
+
const registry = ctx.systemPrompt;
|
|
745
936
|
if (sectionError !== undefined && isDuplicateSectionError(sectionError)) {
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
937
|
+
if (registry !== undefined && mountedRegistries.has(registry)) {
|
|
938
|
+
duplicateMountAttempts += 1;
|
|
939
|
+
ctx.logger?.warn?.(`dsh-boost: ERR_BOOST_ALREADY_MOUNTED: duplicate apply #${duplicateMountAttempts} found an existing mount; registration skipped (${messageOf(sectionError)})`);
|
|
940
|
+
return {
|
|
941
|
+
alreadyMounted: true,
|
|
942
|
+
ownsSection: registry !== undefined && ownSectionRegistries.has(registry),
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
// The name is taken, but not by this module: the message alone cannot tell
|
|
946
|
+
// our previous apply from another plugin using the same section name.
|
|
947
|
+
missing.add(MOUNT_SECTION);
|
|
948
|
+
ctx.logger?.warn?.(`dsh-boost: ERR_BOOST_SECTION_REGISTER_FAILED: prompt section "${PROTOCOL_NAME}" is registered by another plugin; mounting the remaining hooks independently (${messageOf(sectionError)})`);
|
|
749
949
|
}
|
|
750
|
-
if (sectionError !== undefined) {
|
|
950
|
+
else if (sectionError !== undefined) {
|
|
751
951
|
missing.add(MOUNT_SECTION);
|
|
752
952
|
ctx.logger?.warn?.(`dsh-boost: ERR_BOOST_SECTION_REGISTER_FAILED: prompt section registration failed; mounting the remaining hooks independently (${messageOf(sectionError)})`);
|
|
753
953
|
}
|
|
754
|
-
else
|
|
755
|
-
|
|
756
|
-
//
|
|
757
|
-
|
|
758
|
-
ctx.
|
|
954
|
+
else {
|
|
955
|
+
ownsSection = true;
|
|
956
|
+
// Record the marker only after the host accepted the section: this is the
|
|
957
|
+
// one registry object a later duplicate may be attributed to.
|
|
958
|
+
if (ctx.systemPrompt !== undefined && typeof ctx.systemPrompt === 'object') {
|
|
959
|
+
ownSectionRegistries.add(ctx.systemPrompt);
|
|
960
|
+
}
|
|
961
|
+
if (registrationError !== undefined) {
|
|
962
|
+
// The section did not throw, so this is an assembly bug: an unknown mount
|
|
963
|
+
// is missing even though no specific one can be named.
|
|
964
|
+
missing.add('hooks');
|
|
965
|
+
ctx.logger?.warn?.(`dsh-boost: ERR_BOOST_PARTIAL_MOUNT: hook assembly failed (${messageOf(registrationError)})`);
|
|
966
|
+
}
|
|
759
967
|
}
|
|
760
968
|
for (const mount of deferred) {
|
|
761
969
|
try {
|
|
@@ -769,7 +977,11 @@ function mountHooks(ctx, deps, missing) {
|
|
|
769
977
|
if (missing.size > 0) {
|
|
770
978
|
ctx.logger?.warn?.(`dsh-boost: ERR_BOOST_PARTIAL_MOUNT: missing mount(s): ${[...missing].join(', ')}; the plugin is partially wired and boost status reports this code`);
|
|
771
979
|
}
|
|
772
|
-
|
|
980
|
+
// A later apply over this registry is a duplicate even when the section name
|
|
981
|
+
// belonged to another plugin: the hooks and the tool are ours either way.
|
|
982
|
+
if (registry !== undefined)
|
|
983
|
+
mountedRegistries.add(registry);
|
|
984
|
+
return { alreadyMounted: false, ownsSection };
|
|
773
985
|
}
|
|
774
986
|
export function apply(ctx, config) {
|
|
775
987
|
const repairs = [];
|
|
@@ -823,27 +1035,75 @@ export function apply(ctx, config) {
|
|
|
823
1035
|
// these getters retry until the provider fiber is ACTIVE; an absence is
|
|
824
1036
|
// never memoised. The workspace registry is the `resolveByPath`/`list()`
|
|
825
1037
|
// seam; the spill store is the projection backend; the token meter prices
|
|
826
|
-
// projections and admission.
|
|
1038
|
+
// projections and admission. A first success is not a permanent binding:
|
|
1039
|
+
// each point of use resets the memo on failure, and the plugin's fiber
|
|
1040
|
+
// disposal drops all three (review row 6).
|
|
827
1041
|
const registry = lazyService(ctx, 'workspaceRegistry');
|
|
828
1042
|
const spillService = lazyService(ctx, 'spillStore');
|
|
1043
|
+
// `llm` is soft (see `inject`): projection and admission never need it, and
|
|
1044
|
+
// the selector checks it at call time. A getter keeps a provider that
|
|
1045
|
+
// becomes active after `apply` reachable on the next decision.
|
|
1046
|
+
const llm = lazyService(ctx, 'llm');
|
|
829
1047
|
/**
|
|
830
|
-
* The
|
|
1048
|
+
* The workspace registry the visibility warm uses, with a failure re-probe.
|
|
831
1049
|
*
|
|
832
|
-
*
|
|
833
|
-
*
|
|
834
|
-
*
|
|
835
|
-
*
|
|
836
|
-
* rejection therefore drops the memo; the next decision asks `ctx.get`
|
|
837
|
-
* again, which cordis answers from the provider fiber's live state.
|
|
1050
|
+
* `list()` and `resolveByPath()` are total in the resolver (they swallow
|
|
1051
|
+
* their own throws), so this wrapper is the only place a replaced or
|
|
1052
|
+
* disposed provider is observable. A throw drops the memo; the next warm
|
|
1053
|
+
* asks `ctx.get` again and picks up the live binding.
|
|
838
1054
|
*/
|
|
839
|
-
const
|
|
840
|
-
const backend =
|
|
1055
|
+
const registryBackend = () => {
|
|
1056
|
+
const backend = registry();
|
|
841
1057
|
if (backend === undefined)
|
|
842
1058
|
return undefined;
|
|
1059
|
+
const resolveByPath = backend.resolveByPath;
|
|
1060
|
+
const wrapper = {
|
|
1061
|
+
list: () => {
|
|
1062
|
+
try {
|
|
1063
|
+
return backend.list();
|
|
1064
|
+
}
|
|
1065
|
+
catch (error) {
|
|
1066
|
+
registry.reset();
|
|
1067
|
+
throw error;
|
|
1068
|
+
}
|
|
1069
|
+
},
|
|
1070
|
+
};
|
|
1071
|
+
if (typeof resolveByPath === 'function') {
|
|
1072
|
+
wrapper.resolveByPath = async (path) => {
|
|
1073
|
+
try {
|
|
1074
|
+
return await resolveByPath.call(backend, path);
|
|
1075
|
+
}
|
|
1076
|
+
catch (error) {
|
|
1077
|
+
registry.reset();
|
|
1078
|
+
throw error;
|
|
1079
|
+
}
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
return wrapper;
|
|
1083
|
+
};
|
|
1084
|
+
/**
|
|
1085
|
+
* The spill backend the decision path uses, with a pre-write re-confirmation.
|
|
1086
|
+
*
|
|
1087
|
+
* A store that resolved is not a store that still exists: the provider may
|
|
1088
|
+
* be replaced or disposed between the decision that resolved it and the
|
|
1089
|
+
* write. Every write re-reads `ctx.get` through `refresh()` and uses the
|
|
1090
|
+
* current binding. A rejection drops the memo too, so a dead backend cannot
|
|
1091
|
+
* keep every later projection pointed at it while `hasSpill` stays true
|
|
1092
|
+
* (review rows 6 and 31).
|
|
1093
|
+
*/
|
|
1094
|
+
const spillBackend = () => {
|
|
1095
|
+
if (spillService() === undefined)
|
|
1096
|
+
return undefined;
|
|
843
1097
|
return {
|
|
844
1098
|
saveText: async (input) => {
|
|
1099
|
+
const current = spillService.refresh();
|
|
1100
|
+
if (current === undefined) {
|
|
1101
|
+
// The store disappeared mid-turn: the projection path records this
|
|
1102
|
+
// as `projection-skipped:spill-failed`, not as a crash.
|
|
1103
|
+
throw new Error('spillStore disappeared before the write');
|
|
1104
|
+
}
|
|
845
1105
|
try {
|
|
846
|
-
return await
|
|
1106
|
+
return await current.saveText(input);
|
|
847
1107
|
}
|
|
848
1108
|
catch (error) {
|
|
849
1109
|
spillService.reset();
|
|
@@ -852,10 +1112,47 @@ export function apply(ctx, config) {
|
|
|
852
1112
|
},
|
|
853
1113
|
};
|
|
854
1114
|
};
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
1115
|
+
/**
|
|
1116
|
+
* The LLM seam the selector uses, with a failure re-probe.
|
|
1117
|
+
*
|
|
1118
|
+
* The selector turns any failure into an abstention, so a provider that is
|
|
1119
|
+
* replaced after one successful call would otherwise be used for the rest
|
|
1120
|
+
* of the process. A synchronous throw or a throw while the stream is
|
|
1121
|
+
* consumed drops the memo; the next selection asks `ctx.get` again.
|
|
1122
|
+
*/
|
|
1123
|
+
const llmBackend = () => {
|
|
1124
|
+
const backend = llm();
|
|
1125
|
+
if (backend === undefined)
|
|
1126
|
+
return undefined;
|
|
1127
|
+
return {
|
|
1128
|
+
stream: (options) => {
|
|
1129
|
+
try {
|
|
1130
|
+
const stream = backend.stream(options);
|
|
1131
|
+
return (async function* () {
|
|
1132
|
+
try {
|
|
1133
|
+
yield* stream;
|
|
1134
|
+
}
|
|
1135
|
+
catch (error) {
|
|
1136
|
+
llm.reset();
|
|
1137
|
+
throw error;
|
|
1138
|
+
}
|
|
1139
|
+
})();
|
|
1140
|
+
}
|
|
1141
|
+
catch (error) {
|
|
1142
|
+
llm.reset();
|
|
1143
|
+
throw error;
|
|
1144
|
+
}
|
|
1145
|
+
},
|
|
1146
|
+
};
|
|
1147
|
+
};
|
|
1148
|
+
// A disposed provider must not leave a stale binding behind for a later
|
|
1149
|
+
// provider that reuses the name. Cordis has no `dispose` event; the effect
|
|
1150
|
+
// seam is the fiber-unload hook (see `onDispose`).
|
|
1151
|
+
onDispose(ctx, () => {
|
|
1152
|
+
registry.reset();
|
|
1153
|
+
spillService.reset();
|
|
1154
|
+
llm.reset();
|
|
1155
|
+
});
|
|
859
1156
|
const meter = meterSeamOf(ctx);
|
|
860
1157
|
const projectionCounters = new ProjectionCounters();
|
|
861
1158
|
// Host capabilities `status` renders as stable codes. Getters keep them
|
|
@@ -922,7 +1219,7 @@ export function apply(ctx, config) {
|
|
|
922
1219
|
// the mirror instead of leaking one entry per disposed session.
|
|
923
1220
|
clearAcceptedDispatch: (sessionId) => clearAcceptedDispatch(deps, sessionId),
|
|
924
1221
|
get llm() {
|
|
925
|
-
return
|
|
1222
|
+
return llmBackend();
|
|
926
1223
|
},
|
|
927
1224
|
selectorRoute: (sessionId) => routes.get(sessionId),
|
|
928
1225
|
};
|
|
@@ -932,15 +1229,22 @@ export function apply(ctx, config) {
|
|
|
932
1229
|
// not take the other three mounts (or the control tool) down with it, and
|
|
933
1230
|
// must be visible in `status` as `ERR_BOOST_PARTIAL_MOUNT` (review row 2).
|
|
934
1231
|
const missingMounts = new Set();
|
|
935
|
-
|
|
1232
|
+
const mounts = mountHooks(ctx, deps, missingMounts);
|
|
1233
|
+
if (mounts.alreadyMounted)
|
|
936
1234
|
return;
|
|
937
1235
|
// The clock/visibility warm and the session-end cleanup. Wired separately
|
|
938
1236
|
// so a host that cannot accept these events still gets the tool below.
|
|
1237
|
+
// `wireSessionEvents` mounts each listener in its own try/catch: a throw at
|
|
1238
|
+
// the first one cannot drop the other six (in particular
|
|
1239
|
+
// `session/disposed`, whose loss leaks per-session state for the process
|
|
1240
|
+
// lifetime), and every failure is named in `missingMounts`.
|
|
939
1241
|
try {
|
|
940
|
-
wireSessionEvents(ctx, deps, scope,
|
|
1242
|
+
wireSessionEvents(ctx, deps, scope, registryBackend, sessions, horizon, workspaces, routes, projectionCounters, missingMounts, mounts.ownsSection);
|
|
941
1243
|
}
|
|
942
1244
|
catch (error) {
|
|
943
|
-
|
|
1245
|
+
// Only an assembly bug reaches here; each listener mount is contained.
|
|
1246
|
+
missingMounts.add('session-events');
|
|
1247
|
+
ctx.logger?.warn?.(`dsh-boost: ERR_BOOST_PARTIAL_MOUNT: session wiring failed (${messageOf(error)})`);
|
|
944
1248
|
}
|
|
945
1249
|
// After the hooks: a genuine duplicate aborts above before it can register
|
|
946
1250
|
// the tool twice. A different section failure still reaches here, and so
|