dsh-harness-reflex 0.1.0 → 0.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.
- package/README.md +20 -6
- package/client.js +3511 -185
- package/dist/attribution.d.ts +266 -0
- package/dist/attribution.js +238 -0
- package/dist/attribution.js.map +1 -0
- package/dist/bridge.d.ts +311 -13
- package/dist/bridge.js +714 -42
- package/dist/bridge.js.map +1 -1
- package/dist/client-bundle.js +4 -1
- package/dist/client-bundle.js.map +1 -1
- package/dist/command.js +10 -0
- package/dist/command.js.map +1 -1
- package/dist/config.d.ts +530 -22
- package/dist/config.js +808 -27
- package/dist/config.js.map +1 -1
- package/dist/delegation-dispatch.d.ts +132 -0
- package/dist/delegation-dispatch.js +186 -0
- package/dist/delegation-dispatch.js.map +1 -0
- package/dist/delegation-health.d.ts +131 -0
- package/dist/delegation-health.js +97 -0
- package/dist/delegation-health.js.map +1 -0
- package/dist/delegation.d.ts +148 -0
- package/dist/delegation.js +186 -0
- package/dist/delegation.js.map +1 -0
- package/dist/effort-delegation.d.ts +144 -0
- package/dist/effort-delegation.js +280 -0
- package/dist/effort-delegation.js.map +1 -0
- package/dist/effort.d.ts +141 -0
- package/dist/effort.js +251 -9
- package/dist/effort.js.map +1 -1
- package/dist/host-patch.d.ts +156 -0
- package/dist/host-patch.js +534 -0
- package/dist/host-patch.js.map +1 -0
- package/dist/index.d.ts +12 -3
- package/dist/index.js +99 -7
- package/dist/index.js.map +1 -1
- package/dist/interventions.d.ts +98 -373
- package/dist/interventions.js +442 -1702
- package/dist/interventions.js.map +1 -1
- package/dist/panel-api.d.ts +328 -4
- package/dist/panel-api.js +322 -15
- package/dist/panel-api.js.map +1 -1
- package/dist/panel-mount.d.ts +81 -22
- package/dist/panel-mount.js +228 -7
- package/dist/panel-mount.js.map +1 -1
- package/dist/routing.d.ts +23 -18
- package/dist/routing.js +471 -153
- package/dist/routing.js.map +1 -1
- package/dist/session-audit.d.ts +70 -0
- package/dist/session-audit.js +73 -0
- package/dist/session-audit.js.map +1 -1
- package/dist/systemone-probe.d.ts +114 -0
- package/dist/systemone-probe.js +383 -0
- package/dist/systemone-probe.js.map +1 -0
- package/dist/testing.d.ts +212 -7
- package/dist/testing.js +333 -27
- package/dist/testing.js.map +1 -1
- package/dist/tools.d.ts +109 -3
- package/dist/tools.js +103 -4
- package/dist/tools.js.map +1 -1
- package/dist/unconfigured-backend.d.ts +72 -0
- package/dist/unconfigured-backend.js +94 -0
- package/dist/unconfigured-backend.js.map +1 -0
- package/dist/vendor/harness-reflex/backend/factory.d.ts +31 -1
- package/dist/vendor/harness-reflex/backend/factory.js +18 -3
- package/dist/vendor/harness-reflex/backend/factory.js.map +1 -1
- package/dist/vendor/harness-reflex/backend/jev.d.ts +20 -0
- package/dist/vendor/harness-reflex/backend/jev.js +11 -4
- package/dist/vendor/harness-reflex/backend/jev.js.map +1 -1
- package/dist/vendor/harness-reflex/backend/simple-jev.d.ts +16 -0
- package/dist/vendor/harness-reflex/backend/simple-jev.js +17 -6
- package/dist/vendor/harness-reflex/backend/simple-jev.js.map +1 -1
- package/dist/vendor/harness-reflex/core/closing.d.ts +90 -0
- package/dist/vendor/harness-reflex/core/closing.js +111 -0
- package/dist/vendor/harness-reflex/core/closing.js.map +1 -0
- package/dist/vendor/harness-reflex/core/evidence.d.ts +119 -0
- package/dist/vendor/harness-reflex/core/evidence.js +209 -0
- package/dist/vendor/harness-reflex/core/evidence.js.map +1 -0
- package/dist/vendor/harness-reflex/core/judge.d.ts +221 -0
- package/dist/vendor/harness-reflex/core/judge.js +251 -0
- package/dist/vendor/harness-reflex/core/judge.js.map +1 -0
- package/dist/vendor/harness-reflex/core/orchestrate-closing.d.ts +237 -0
- package/dist/vendor/harness-reflex/core/orchestrate-closing.js +250 -0
- package/dist/vendor/harness-reflex/core/orchestrate-closing.js.map +1 -0
- package/dist/vendor/harness-reflex/core/orchestrate-correction.d.ts +209 -0
- package/dist/vendor/harness-reflex/core/orchestrate-correction.js +141 -0
- package/dist/vendor/harness-reflex/core/orchestrate-correction.js.map +1 -0
- package/dist/vendor/harness-reflex/core/orchestrate-host.d.ts +225 -0
- package/dist/vendor/harness-reflex/core/orchestrate-host.js +80 -0
- package/dist/vendor/harness-reflex/core/orchestrate-host.js.map +1 -0
- package/dist/vendor/harness-reflex/core/orchestrate-stagnation.d.ts +259 -0
- package/dist/vendor/harness-reflex/core/orchestrate-stagnation.js +270 -0
- package/dist/vendor/harness-reflex/core/orchestrate-stagnation.js.map +1 -0
- package/dist/vendor/harness-reflex/core/orchestrate.d.ts +357 -0
- package/dist/vendor/harness-reflex/core/orchestrate.js +418 -0
- package/dist/vendor/harness-reflex/core/orchestrate.js.map +1 -0
- package/dist/vendor/harness-reflex/core/policy.d.ts +122 -0
- package/dist/vendor/harness-reflex/core/policy.js +102 -0
- package/dist/vendor/harness-reflex/core/policy.js.map +1 -0
- package/dist/vendor/harness-reflex/core/prune-plan.d.ts +141 -0
- package/dist/vendor/harness-reflex/core/prune-plan.js +390 -0
- package/dist/vendor/harness-reflex/core/prune-plan.js.map +1 -0
- package/dist/vendor/harness-reflex/core/text.d.ts +36 -0
- package/dist/vendor/harness-reflex/core/text.js +66 -0
- package/dist/vendor/harness-reflex/core/text.js.map +1 -0
- package/dist/vendor/harness-reflex/ports/audit.d.ts +18 -0
- package/dist/vendor/harness-reflex/ports/audit.js +11 -0
- package/dist/vendor/harness-reflex/ports/audit.js.map +1 -0
- package/dist/vendor/harness-reflex/ports/clock.d.ts +14 -0
- package/dist/vendor/harness-reflex/ports/clock.js +11 -0
- package/dist/vendor/harness-reflex/ports/clock.js.map +1 -0
- package/dist/vendor/harness-reflex/ports/decision.d.ts +75 -0
- package/dist/vendor/harness-reflex/ports/decision.js +2 -0
- package/dist/vendor/harness-reflex/ports/decision.js.map +1 -0
- package/dist/vendor/harness-reflex/ports/index.d.ts +14 -0
- package/dist/vendor/harness-reflex/ports/index.js +2 -0
- package/dist/vendor/harness-reflex/ports/index.js.map +1 -0
- package/dist/vendor/harness-reflex/ports/log.d.ts +22 -0
- package/dist/vendor/harness-reflex/ports/log.js +12 -0
- package/dist/vendor/harness-reflex/ports/log.js.map +1 -0
- package/dist/vendor/harness-reflex/ports/state.d.ts +46 -0
- package/dist/vendor/harness-reflex/ports/state.js +13 -0
- package/dist/vendor/harness-reflex/ports/state.js.map +1 -0
- package/package.json +25 -13
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
-
import { Config, resolveConfig, resolveEffortSetting, resolveApiKey, resolveSystemOneConfig, resolveToolsConfig, routingActive, volatileSnapshots, type ReflexConfig } from './config.js';
|
|
2
|
+
import { Config, resolveConfig, resolveDelegationConfig, resolveEffortSetting, resolveApiKey, resolveSystemOneConfig, resolveToolsConfig, routingActive, volatileSnapshots, type ReflexConfig } from './config.js';
|
|
3
3
|
import { createReflexRuntime, type ReflexRuntime } from './bridge.js';
|
|
4
4
|
import { defineReflexTools, enabledReflexToolSuffixes, reflexToolNames } from './tools.js';
|
|
5
5
|
/**
|
|
@@ -39,8 +39,8 @@ export declare const name = "dsh-reflex";
|
|
|
39
39
|
* that never reaches the model.
|
|
40
40
|
*/
|
|
41
41
|
export declare const inject: string[];
|
|
42
|
-
export { Config, resolveConfig, resolveEffortSetting, resolveApiKey, resolveSystemOneConfig, resolveToolsConfig, routingActive, volatileSnapshots, createReflexRuntime, defineReflexTools, enabledReflexToolSuffixes, reflexToolNames };
|
|
43
|
-
export type { ReflexToolsConfig, ResolvedToolsConfig } from './config.js';
|
|
42
|
+
export { Config, resolveConfig, resolveDelegationConfig, resolveEffortSetting, resolveApiKey, resolveSystemOneConfig, resolveToolsConfig, routingActive, volatileSnapshots, createReflexRuntime, defineReflexTools, enabledReflexToolSuffixes, reflexToolNames };
|
|
43
|
+
export type { ReflexDelegationConfig, ReflexToolsConfig, ResolvedDelegationConfig, ResolvedToolsConfig } from './config.js';
|
|
44
44
|
export { INTERVENTION_CAPABILITIES, INTERVENTION_MODES, INTERVENTION_SETTINGS, resolveInterventionSetting, resolveInterventionsConfig } from './config.js';
|
|
45
45
|
export type { InterventionCapability, InterventionMode, InterventionSetting, ReflexInterventionsConfig, ResolvedInterventionsConfig } from './config.js';
|
|
46
46
|
export { INTERVENTION_SOURCE_KIND, InterventionEngine, WAIT_QUERY_TOOLS, installInterventions, isWaitQuery } from './interventions.js';
|
|
@@ -54,9 +54,18 @@ export { mountReflexPanel } from './panel-mount.js';
|
|
|
54
54
|
export { createPanelSource, panelFacts, panelPools } from './panel-mount.js';
|
|
55
55
|
export { ReflexRuntime } from './bridge.js';
|
|
56
56
|
export { REFLEX_TOOL_SUFFIXES } from './tools.js';
|
|
57
|
+
export { delegateServable, delegationExecutables } from './tools.js';
|
|
58
|
+
export { DELEGATION_BROKEN_WARNING, DELEGATION_MODEL_SELECTION_OFF_REASON, DELEGATION_TOOL_MISSING_REASON, readDelegationHealth, watchDelegationHealth } from './delegation-health.js';
|
|
59
|
+
export type { DelegationHealth, DelegationHealthState, DelegationHealthWatch, DelegationHealthWatchOptions } from './delegation-health.js';
|
|
60
|
+
export { DELEGATION_ROW_ID, MODEL_SELECTION_FIELD, OWNERSHIP_MARKER, PROFILE_PATCH_FILENAME, enableHostModelSelection, inspectHostModelSelection, planModelSelectionEdit, resolveProfilePatchPath } from './host-patch.js';
|
|
61
|
+
export type { HostPatchOutcome, HostPatchResult, PatchEditResult, PatchPathResolution } from './host-patch.js';
|
|
57
62
|
export { installModelRouting } from './routing.js';
|
|
58
63
|
export { ADAPTIVE_EFFORT_LEVELS, EFFORT_CHOICE_OPTIONS, EFFORT_LEVELS, EFFORT_TRIGGERS, EffortInterceptor, EffortStatusFeed, buildEffortChoice, classifyByCues, effortRank, formatEffortStatusLine, isAdaptiveEffortLevel, isEffortTrigger, levelOfChoiceOption, projectEffort, readEffortCues, snapEffort } from './effort.js';
|
|
59
64
|
export { EFFORT_RECORD_TYPE, appendEffortRecord, effortRecordsOf, toEffortAuditRecord } from './session-audit.js';
|
|
65
|
+
export { EFFORT_INHERIT_RECORD_TYPE, appendEffortInheritRecord, effortInheritRecordsOf, isEffortInheritAuditRecord } from './session-audit.js';
|
|
66
|
+
export type { EffortInheritAuditRecord } from './session-audit.js';
|
|
67
|
+
export { DELEGATION_EFFORT_REASON, currentSelectionOf, installDelegatedEffortInheritance, isDelegatedSession } from './effort-delegation.js';
|
|
68
|
+
export type { DelegatedEffortInheritance, DelegatedEffortInheritanceOptions } from './effort-delegation.js';
|
|
60
69
|
export { PRUNED_ORIGINAL_RECORD_TYPE, pruneLocator, readPrunedOriginal } from './session-audit.js';
|
|
61
70
|
export type { PrunedOriginalRecord } from './session-audit.js';
|
|
62
71
|
export { ReflexVirtualAdapter } from './virtual-adapter.js';
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { Config, resolveConfig, resolveEffortSetting, resolveApiKey, resolveSystemOneConfig, resolveToolsConfig, routingActive, volatileSnapshots } from './config.js';
|
|
1
|
+
import { Config, resolveConfig, resolveDelegationConfig, resolveEffortSetting, resolveApiKey, resolveSystemOneConfig, resolveToolsConfig, routingActive, volatileSnapshots } from './config.js';
|
|
2
2
|
import { createReflexRuntime } from './bridge.js';
|
|
3
3
|
import { installModelRouting } from './routing.js';
|
|
4
|
-
import { defineReflexTools, enabledReflexToolSuffixes, reflexToolNames } from './tools.js';
|
|
4
|
+
import { defineReflexTools, delegationExecutables, enabledReflexToolSuffixes, reflexToolNames, resolveReflexToolExecutables } from './tools.js';
|
|
5
|
+
import { DELEGATION_TOOL_NAME, createReflexDelegation } from './delegation-dispatch.js';
|
|
6
|
+
import { readDelegationHealth, watchDelegationHealth } from './delegation-health.js';
|
|
5
7
|
import { installLedgerCommand } from './command.js';
|
|
6
8
|
import { mountReflexPanel } from './panel-mount.js';
|
|
7
9
|
import { installInterventions } from './interventions.js';
|
|
8
10
|
import { appendInterventionRecord, appendPrunedOriginal } from './session-audit.js';
|
|
9
11
|
import { installActualProjection } from './actual-projection.js';
|
|
12
|
+
import { installDelegatedEffortInheritance } from './effort-delegation.js';
|
|
10
13
|
/** Cordis plugin name. */
|
|
11
14
|
export const name = 'dsh-reflex';
|
|
12
15
|
/**
|
|
@@ -16,7 +19,7 @@ export const name = 'dsh-reflex';
|
|
|
16
19
|
* that never reaches the model.
|
|
17
20
|
*/
|
|
18
21
|
export const inject = ['tools', 'llm', 'commands'];
|
|
19
|
-
export { Config, resolveConfig, resolveEffortSetting, resolveApiKey, resolveSystemOneConfig, resolveToolsConfig, routingActive, volatileSnapshots, createReflexRuntime, defineReflexTools, enabledReflexToolSuffixes, reflexToolNames };
|
|
22
|
+
export { Config, resolveConfig, resolveDelegationConfig, resolveEffortSetting, resolveApiKey, resolveSystemOneConfig, resolveToolsConfig, routingActive, volatileSnapshots, createReflexRuntime, defineReflexTools, enabledReflexToolSuffixes, reflexToolNames };
|
|
20
23
|
export { INTERVENTION_CAPABILITIES, INTERVENTION_MODES, INTERVENTION_SETTINGS, resolveInterventionSetting, resolveInterventionsConfig } from './config.js';
|
|
21
24
|
export { INTERVENTION_SOURCE_KIND, InterventionEngine, WAIT_QUERY_TOOLS, installInterventions, isWaitQuery } from './interventions.js';
|
|
22
25
|
export { createBackend } from './bridge.js';
|
|
@@ -26,9 +29,14 @@ export { mountReflexPanel } from './panel-mount.js';
|
|
|
26
29
|
export { createPanelSource, panelFacts, panelPools } from './panel-mount.js';
|
|
27
30
|
export { ReflexRuntime } from './bridge.js';
|
|
28
31
|
export { REFLEX_TOOL_SUFFIXES } from './tools.js';
|
|
32
|
+
export { delegateServable, delegationExecutables } from './tools.js';
|
|
33
|
+
export { DELEGATION_BROKEN_WARNING, DELEGATION_MODEL_SELECTION_OFF_REASON, DELEGATION_TOOL_MISSING_REASON, readDelegationHealth, watchDelegationHealth } from './delegation-health.js';
|
|
34
|
+
export { DELEGATION_ROW_ID, MODEL_SELECTION_FIELD, OWNERSHIP_MARKER, PROFILE_PATCH_FILENAME, enableHostModelSelection, inspectHostModelSelection, planModelSelectionEdit, resolveProfilePatchPath } from './host-patch.js';
|
|
29
35
|
export { installModelRouting } from './routing.js';
|
|
30
36
|
export { ADAPTIVE_EFFORT_LEVELS, EFFORT_CHOICE_OPTIONS, EFFORT_LEVELS, EFFORT_TRIGGERS, EffortInterceptor, EffortStatusFeed, buildEffortChoice, classifyByCues, effortRank, formatEffortStatusLine, isAdaptiveEffortLevel, isEffortTrigger, levelOfChoiceOption, projectEffort, readEffortCues, snapEffort } from './effort.js';
|
|
31
37
|
export { EFFORT_RECORD_TYPE, appendEffortRecord, effortRecordsOf, toEffortAuditRecord } from './session-audit.js';
|
|
38
|
+
export { EFFORT_INHERIT_RECORD_TYPE, appendEffortInheritRecord, effortInheritRecordsOf, isEffortInheritAuditRecord } from './session-audit.js';
|
|
39
|
+
export { DELEGATION_EFFORT_REASON, currentSelectionOf, installDelegatedEffortInheritance, isDelegatedSession } from './effort-delegation.js';
|
|
32
40
|
// Retrieval of a pruned original is a public API, not an internal detail: the guide
|
|
33
41
|
// tells a reader to import the function from the package root, so the root entry has
|
|
34
42
|
// to export it together with the two names a caller needs to use it — the record's
|
|
@@ -56,17 +64,44 @@ function installReflexToolSurface(ctx, runtime) {
|
|
|
56
64
|
const owned = new Map();
|
|
57
65
|
let registrationEvents = 0;
|
|
58
66
|
let disposed = false;
|
|
67
|
+
// Resolved live from configuration only. The honest capability check cannot
|
|
68
|
+
// happen here: this runs during `apply()`, where the plugin has no agent
|
|
69
|
+
// scope, and `dsh-tools` is a *scoped* registry whose global view does not
|
|
70
|
+
// contain a tool attached inside an agent preset — which is exactly where a
|
|
71
|
+
// real deployment puts `tool-subagent`. Probing the global view at mount is
|
|
72
|
+
// what made a correctly configured Host register nothing at all (g-054).
|
|
73
|
+
// Whether the Host can carry a level is judged at call time, by the Host.
|
|
74
|
+
const delegation = () => createReflexDelegation({
|
|
75
|
+
ctx,
|
|
76
|
+
ledger: runtime.ledger,
|
|
77
|
+
decide: (request) => runtime.choice(request),
|
|
78
|
+
minConfidence: runtime.effort.minConfidence,
|
|
79
|
+
warn: (message) => ctx.logger?.('dsh-reflex')?.warn(message)
|
|
80
|
+
});
|
|
81
|
+
/**
|
|
82
|
+
* Suffixes enabled by config *and* consented to by the operator.
|
|
83
|
+
*
|
|
84
|
+
* Registering the delegate is a **configuration** decision: `delegation.enabled`
|
|
85
|
+
* is the consent that writes the Host's `modelSelection` switch, and once it is
|
|
86
|
+
* given the wrapper is registered unconditionally. It deliberately does not
|
|
87
|
+
* consult the registry — at this point in the lifecycle there is no agent scope
|
|
88
|
+
* to read as, so any registry answer would describe a view no session uses.
|
|
89
|
+
* `delegationExecutables` still withholds the target when consent is off, which
|
|
90
|
+
* is the one gate registration keeps.
|
|
91
|
+
*/
|
|
92
|
+
const executableSuffixes = (config) => resolveReflexToolExecutables(enabledReflexToolSuffixes(config), delegationExecutables(config, DELEGATION_TOOL_NAME));
|
|
59
93
|
const publish = () => {
|
|
60
94
|
// Vocabulary order, not registration order: the panel and the runtime
|
|
61
95
|
// surface must not reshuffle just because a tool was toggled later.
|
|
62
|
-
runtime.noteToolSurface(
|
|
96
|
+
runtime.noteToolSurface(executableSuffixes(runtime.effectiveConfig)
|
|
97
|
+
.map((suffix) => `${runtime.effectiveConfig.toolPrefix}${suffix}`)
|
|
98
|
+
.filter((name) => owned.has(name) && ctx.tools.get(name) !== undefined));
|
|
63
99
|
};
|
|
64
100
|
return {
|
|
65
101
|
refresh(config) {
|
|
66
102
|
if (disposed)
|
|
67
103
|
return;
|
|
68
|
-
const
|
|
69
|
-
const wanted = new Set(desired);
|
|
104
|
+
const wanted = new Set(executableSuffixes(config).map((suffix) => `${config.toolPrefix}${suffix}`));
|
|
70
105
|
// Remove first: a duplicate registration throws, and a prefix rename has
|
|
71
106
|
// no name in common with the old surface. A name we still want but that
|
|
72
107
|
// the registry no longer answers for is dropped too, so a stray removal
|
|
@@ -77,7 +112,10 @@ function installReflexToolSurface(ctx, runtime) {
|
|
|
77
112
|
owned.delete(name);
|
|
78
113
|
unregister();
|
|
79
114
|
}
|
|
80
|
-
|
|
115
|
+
const seam = delegation();
|
|
116
|
+
for (const definition of defineReflexTools(runtime, config, seam)) {
|
|
117
|
+
if (!wanted.has(definition.name))
|
|
118
|
+
continue;
|
|
81
119
|
if (owned.has(definition.name))
|
|
82
120
|
continue;
|
|
83
121
|
try {
|
|
@@ -153,6 +191,42 @@ export function applyReflex(ctx, config) {
|
|
|
153
191
|
const tools = installReflexToolSurface(ctx, runtime);
|
|
154
192
|
runtime.attachToolSurface((next) => tools.refresh(next), () => tools.registrationCount, () => tools.registrationEvents);
|
|
155
193
|
tools.refresh(resolved);
|
|
194
|
+
// The Host capability the delegate needs is read from the live registry, so
|
|
195
|
+
// a broken one is reported and warned about. The read is **scoped**: a preset
|
|
196
|
+
// deployment attaches `tool-subagent` to an agent, not to the global view, so
|
|
197
|
+
// reading globally would call a working Host "off" (g-054). Until an agent
|
|
198
|
+
// registers here the reading is `unknown` — which the panel shows as "not
|
|
199
|
+
// probed", never as a fault. It never writes a configuration file: a switch
|
|
200
|
+
// that went off might be a person's own decision, and turning it back on is
|
|
201
|
+
// theirs to make.
|
|
202
|
+
//
|
|
203
|
+
// Registration is *not* a reaction of this watch any more (see
|
|
204
|
+
// `executableSuffixes`): a tool must not appear or vanish because a scope
|
|
205
|
+
// happened to become readable. The watch only reports.
|
|
206
|
+
let observedAgent;
|
|
207
|
+
const readHealth = () => readDelegationHealth(ctx, observedAgent);
|
|
208
|
+
const delegationHealth = watchDelegationHealth({
|
|
209
|
+
read: readHealth,
|
|
210
|
+
warn: (message) => ctx.logger?.('dsh-reflex')?.warn(message),
|
|
211
|
+
onChange: () => {
|
|
212
|
+
if (runtime.disposed)
|
|
213
|
+
return;
|
|
214
|
+
tools.publish();
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
runtime.attachDelegationHealth(() => delegationHealth.health, () => {
|
|
218
|
+
tools.refresh(runtime.effectiveConfig);
|
|
219
|
+
});
|
|
220
|
+
// No listener is installed for the tool registry: the reading is taken on
|
|
221
|
+
// the panel's own poll (see `panel-mount.ts`), with whatever agent scope is
|
|
222
|
+
// known by then. Re-reading on every registry change proved nothing — the
|
|
223
|
+
// global view cannot resolve a preset-hosted tool — and cost a probe per
|
|
224
|
+
// change.
|
|
225
|
+
runtime.attachDelegationScope((agent) => {
|
|
226
|
+
observedAgent = agent;
|
|
227
|
+
// A new scope is a genuinely new view, so the reading is taken again in it.
|
|
228
|
+
delegationHealth.check();
|
|
229
|
+
});
|
|
156
230
|
// A config-only settings save does not remount this plugin: the loader
|
|
157
231
|
// commits the new values into the volatile references and dispatches this
|
|
158
232
|
// event to the owning fiber. Re-resolving here makes the edited routing,
|
|
@@ -168,9 +242,22 @@ export function applyReflex(ctx, config) {
|
|
|
168
242
|
const stopObserving = ctx.on('tools/change', () => {
|
|
169
243
|
if (runtime.disposed)
|
|
170
244
|
return;
|
|
245
|
+
// The published surface is re-derived, not the delegation *reading*: the
|
|
246
|
+
// registry's global view cannot resolve a preset-hosted delegation tool, so
|
|
247
|
+
// a probe on every change would only ever answer "unknown" — and an
|
|
248
|
+
// "unknown" that triggered a refresh would be churn without information.
|
|
171
249
|
tools.publish();
|
|
172
250
|
});
|
|
173
251
|
const stopRouting = installRouting(ctx, runtime);
|
|
252
|
+
// A delegated agent cannot decide its own effort: the loop fixes the step's
|
|
253
|
+
// selection before the request waterfall, so the marker is replaced with the
|
|
254
|
+
// parent's level *on the selection itself* — before the next step reads it.
|
|
255
|
+
const inheritance = installDelegatedEffortInheritance(ctx, {
|
|
256
|
+
enabled: () => runtime.effort.enabled,
|
|
257
|
+
sessionById: (id) => ctx.sessions?.get?.(id),
|
|
258
|
+
warn: (message) => ctx.logger?.('dsh-reflex')?.warn(message)
|
|
259
|
+
});
|
|
260
|
+
runtime.attachEffortInheritance(inheritance);
|
|
174
261
|
// The ledger is an audit question a person asks, not a decision the model
|
|
175
262
|
// makes, so it is a Host command instead of a tool: `/reflex-ledger` reads
|
|
176
263
|
// the same runtime and never opens a turn.
|
|
@@ -188,6 +275,10 @@ export function applyReflex(ctx, config) {
|
|
|
188
275
|
stagnation: runtime.stagnationService,
|
|
189
276
|
prune: runtime.pruneService,
|
|
190
277
|
gate: runtime.gateService,
|
|
278
|
+
// Every judgment this engine spends is attributed like a tool call: the
|
|
279
|
+
// ledger records the connection, the requested model and the source, so a
|
|
280
|
+
// decision made at a Host hook point is no longer anonymous (g-068).
|
|
281
|
+
attribute: (run, options) => runtime.attribute(run, options),
|
|
191
282
|
audit: (record, session) => {
|
|
192
283
|
// The session log is the one place a decision is durable; an agent without
|
|
193
284
|
// a session simply records nothing, which is why this is guarded.
|
|
@@ -220,6 +311,7 @@ export function applyReflex(ctx, config) {
|
|
|
220
311
|
stopConfigWatch();
|
|
221
312
|
stopObserving();
|
|
222
313
|
stopRouting();
|
|
314
|
+
inheritance.dispose();
|
|
223
315
|
unregisterLedger();
|
|
224
316
|
interventions.dispose();
|
|
225
317
|
unmountPanel();
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,oBAAoB,EAAE,aAAa,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,aAAa,EAAE,iBAAiB,EAAgD,MAAM,aAAa,CAAC;AACrN,OAAO,EAAE,mBAAmB,EAAsB,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AA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GAAG,EAAE,CAAC,OAAO,CAAC,gBAAgB,EAAE;QAC/C,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC;KAC7D,CAAC,CAAC;IACH,4EAA4E;IAC5E,4EAA4E;IAC5E,2CAA2C;IAC3C,OAAO,CAAC,gBAAgB,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAC9C,wEAAwE;IACxE,4EAA4E;IAC5E,kEAAkE;IAClE,OAAO,CAAC,aAAa,CACnB,CAAC,OAAO,EAAE,EAAE;QACV,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC9B,OAAO,CAAC,gBAAgB,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC,EACD,GAAG,EAAE,CAAC,YAAY,CAAC,kBAAkB,CACtC,CAAC;IAEF,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;AACtC,CAAC","sourcesContent":["import type { Context } from '@deepseek-ai/cordis';\nimport type { LlmRuntime } from '@deepseek-ai/dsh-llm';\n\nimport { Config, resolveConfig, resolveEffortSetting, resolveApiKey, resolveSystemOneConfig, resolveToolsConfig, routingActive, volatileSnapshots, type ReflexConfig, type ResolvedReflexConfig } from './config.js';\nimport { createReflexRuntime, type ReflexRuntime } from './bridge.js';\nimport { installModelRouting } from './routing.js';\nimport { defineReflexTools, enabledReflexToolSuffixes, reflexToolNames } from './tools.js';\nimport { installLedgerCommand } from './command.js';\nimport { mountReflexPanel } from './panel-mount.js';\nimport { installInterventions } from './interventions.js';\nimport { appendInterventionRecord, appendPrunedOriginal } from './session-audit.js';\nimport { installActualProjection } from './actual-projection.js';\n\n/**\n * DSH Host plugin that exposes the `harness-reflex` System One decision runtime\n * as in-process tools and as a System 1 model router.\n *\n * One activation owns one {@link ReflexRuntime} — its backend, ledger, the five\n * decision services, and the virtual→physical model router — and registers the\n * `reflex_*` tools on `ctx.tools`. Everything is created inside a single\n * `ctx.effect`, so unloading the plugin (or disposing the context) unregisters\n * every tool, detaches the `tools/change` observer, releases the virtual\n * provider route, unregisters `/reflex-ledger`, and drops the runtime whole.\n *\n * @module dsh-reflex\n */\n\ndeclare module '@deepseek-ai/cordis' {\n interface Events {\n /**\n * The loader committed new values into this activation's volatile config\n * references without remounting the plugin.\n *\n * Routing pools and the fallback are read per request, so the activation\n * only has to re-resolve them to make a settings edit effective; nothing\n * else about the running activation is re-created.\n * @param paths - changed config paths as key arrays.\n * @mode emit\n */\n 'loader/volatile-update'(paths: readonly (readonly string[])[]): void;\n }\n}\n\n/** Cordis plugin name. */\nexport const name = 'dsh-reflex';\n\n/**\n * The runtime needs the tool registry, the LLM service for model routing, and\n * the command registry for `/reflex-ledger`: the virtual provider is a real\n * provider route on `ctx.llm`, and the ledger command is a Host-rendered command\n * that never reaches the model.\n */\nexport const inject = ['tools', 'llm', 'commands'];\n\nexport { Config, resolveConfig, resolveEffortSetting, resolveApiKey, resolveSystemOneConfig, resolveToolsConfig, routingActive, volatileSnapshots, createReflexRuntime, defineReflexTools, enabledReflexToolSuffixes, reflexToolNames };\nexport type { ReflexToolsConfig, ResolvedToolsConfig } from './config.js';\nexport {\n INTERVENTION_CAPABILITIES,\n INTERVENTION_MODES,\n INTERVENTION_SETTINGS,\n resolveInterventionSetting,\n resolveInterventionsConfig\n} from './config.js';\nexport type { InterventionCapability, InterventionMode, InterventionSetting, ReflexInterventionsConfig, ResolvedInterventionsConfig } from './config.js';\nexport { INTERVENTION_SOURCE_KIND, InterventionEngine, WAIT_QUERY_TOOLS, installInterventions, isWaitQuery } from './interventions.js';\nexport type {\n InterventionAction,\n InterventionBaseline,\n InterventionCostBucket,\n InterventionInstallation,\n InterventionPlan,\n InterventionReport\n} from './interventions.js';\nexport type { InterventionAuditRecord } from './session-audit.js';\nexport { createBackend } from './bridge.js';\nexport {\n LEDGER_COMMAND_ENTRIES,\n REFLEX_LEDGER_COMMAND,\n REFLEX_LEDGER_COMMAND_DESCRIPTION,\n formatLedgerReport,\n installLedgerCommand\n} from './command.js';\nexport {\n PANEL_BASE,\n PANEL_LEDGER_WINDOW,\n PANEL_LEDGER_WINDOW_MAX,\n PANEL_PATHS,\n PANEL_ROUTES,\n REFLEX_PLUGIN_VERSION,\n answerPanelRequest,\n buildPanelSnapshot,\n clampLimit,\n isLoopbackAddress,\n isLoopbackIPv4,\n isPanelRequestAllowed,\n makePanelRoutes,\n projectEffortDecision,\n readLimit,\n readQuery,\n sendPanelAnswer\n} from './panel-api.js';\nexport type {\n PanelAnswer,\n PanelEffortDecision,\n PanelEffortView,\n PanelLedgerRow,\n PanelLedgerSummary,\n PanelLedgerView,\n PanelPluginView,\n PanelPoolEntry,\n PanelPoolView,\n PanelResponse,\n PanelRoutingView,\n PanelRuntimeFacts,\n PanelSnapshot,\n PanelSource,\n PanelSystemOneHealth,\n PanelSystemOneView\n} from './panel-api.js';\nexport { mountReflexPanel } from './panel-mount.js';\nexport { createPanelSource, panelFacts, panelPools } from './panel-mount.js';\nexport { ReflexRuntime } from './bridge.js';\nexport { REFLEX_TOOL_SUFFIXES } from './tools.js';\nexport { installModelRouting } from './routing.js';\nexport {\n ADAPTIVE_EFFORT_LEVELS,\n EFFORT_CHOICE_OPTIONS,\n EFFORT_LEVELS,\n EFFORT_TRIGGERS,\n EffortInterceptor,\n EffortStatusFeed,\n buildEffortChoice,\n classifyByCues,\n effortRank,\n formatEffortStatusLine,\n isAdaptiveEffortLevel,\n isEffortTrigger,\n levelOfChoiceOption,\n projectEffort,\n readEffortCues,\n snapEffort\n} from './effort.js';\nexport { EFFORT_RECORD_TYPE, appendEffortRecord, effortRecordsOf, toEffortAuditRecord } from './session-audit.js';\n// Retrieval of a pruned original is a public API, not an internal detail: the guide\n// tells a reader to import the function from the package root, so the root entry has\n// to export it together with the two names a caller needs to use it — the record's\n// own type, and the locator builder for the digest a decision record carries.\n// Exporting it only from `session-audit.js` would leave the documented example\n// unrunnable for an installed package.\nexport { PRUNED_ORIGINAL_RECORD_TYPE, pruneLocator, readPrunedOriginal } from './session-audit.js';\nexport type { PrunedOriginalRecord } from './session-audit.js';\nexport { ReflexVirtualAdapter } from './virtual-adapter.js';\nexport {\n ReflexRoutingError,\n VirtualModelRouter,\n alignReasoningEffort,\n formatTargetName,\n parseFallback,\n parseTargetName\n} from './router.js';\nexport type {\n ReflexConfig,\n ReflexEffortConfig,\n ReflexRoutingConfig,\n ReflexSystemOneConfig,\n ResolvedEffortConfig,\n ResolvedReflexConfig,\n ResolvedRoutingConfig,\n ResolvedSystemOneConfig\n} from './config.js';\nexport type { ReflexChoiceResult, ReflexLedgerResult, ReflexPruneResult } from './bridge.js';\nexport type { ReflexToolSuffix } from './tools.js';\nexport type { ModelRoutingInstallation, ModelRoutingOptions } from './routing.js';\nexport type {\n AdaptiveEffortLevel,\n EffortAgentFacts,\n EffortCues,\n EffortDecider,\n EffortDecision,\n EffortInterceptorOptions,\n EffortLevel,\n EffortOutcome,\n EffortRequestContext,\n EffortResolution,\n EffortSource,\n EffortTrigger,\n EffortTriggerKind,\n ReasoningEffortSetting,\n ReflexEffortStatus\n} from './effort.js';\nexport type { EffortAuditRecord } from './session-audit.js';\nexport type { ReflexVirtualAdapterOptions } from './virtual-adapter.js';\nexport type {\n ModelPoolEntry,\n ModelPools,\n PhysicalTarget,\n ReasoningProbe,\n ReasoningSupport,\n RouteContext,\n RouteDecision,\n RoutingFailureCode,\n RoutingReason,\n VirtualModelRouterOptions\n} from './router.js';\n\n/** The registry reconciler of one activation. */\ninterface ToolSurfaceInstallation {\n /**\n * Make the registry answer for exactly the tools `config` enables.\n *\n * Idempotent: when the enabled suffixes and the prefix are unchanged, no\n * registration is touched. A prefix edit unregisters the old names *before*\n * registering the new ones — the registry refuses a name that is already\n * taken, and a caller still holding an old name then gets \"unknown tool\"\n * instead of silently reaching an old body.\n * @param config - the resolved configuration currently in force.\n */\n refresh(config: ResolvedReflexConfig): void;\n /** Republish the surface from the names this activation really owns. */\n publish(): void;\n /** How many tools this activation currently owns. */\n readonly registrationCount: number;\n /** How many `tools.register` calls this activation has made in total. */\n readonly registrationEvents: number;\n /** Unregister every owned tool; idempotent. */\n dispose(): void;\n}\n\n/**\n * Register this activation's reflex tools, and keep the registry in step with\n * config-only saves.\n *\n * The registry is process-wide, so it is not enough to resolve the config on\n * every save: the *registrations* have to change with it. This installer owns\n * those registrations (one disposer per currently-owned name) and reconciles\n * them only when the effective surface actually differs, which is what keeps a\n * same-value save from churning the registry.\n * @param ctx - registrant context carrying `tools`.\n * @param runtime - the activation's runtime, for the definitions and surface.\n * @returns the reconciler and its diagnostics.\n */\nfunction installReflexToolSurface(ctx: Context, runtime: ReflexRuntime): ToolSurfaceInstallation {\n /** Unregister functions of the names this activation currently owns. */\n const owned = new Map<string, () => void>();\n let registrationEvents = 0;\n let disposed = false;\n\n const publish = (): void => {\n // Vocabulary order, not registration order: the panel and the runtime\n // surface must not reshuffle just because a tool was toggled later.\n runtime.noteToolSurface(\n reflexToolNames(runtime.effectiveConfig).filter((name) => owned.has(name) && ctx.tools.get(name) !== undefined)\n );\n };\n\n return {\n refresh(config: ResolvedReflexConfig): void {\n if (disposed) return;\n const desired = reflexToolNames(config);\n const wanted = new Set(desired);\n // Remove first: a duplicate registration throws, and a prefix rename has\n // no name in common with the old surface. A name we still want but that\n // the registry no longer answers for is dropped too, so a stray removal\n // is repaired on the next commit instead of leaving a permanent hole.\n for (const [name, unregister] of [...owned]) {\n if (wanted.has(name) && ctx.tools.get(name) !== undefined) continue;\n owned.delete(name);\n unregister();\n }\n for (const definition of defineReflexTools(runtime, config)) {\n if (owned.has(definition.name)) continue;\n try {\n owned.set(definition.name, ctx.tools.register(definition));\n registrationEvents += 1;\n } catch (error) {\n // A foreign registration of the same name is not ours to take over:\n // leave it absent and let the panel report the surface that is real.\n ctx.logger?.('dsh-reflex')?.warn(\n `dsh-reflex: tool \"${definition.name}\" could not be registered (${(error as Error).message})`\n );\n }\n }\n publish();\n },\n publish,\n get registrationCount(): number {\n return owned.size;\n },\n get registrationEvents(): number {\n return registrationEvents;\n },\n dispose(): void {\n if (disposed) return;\n disposed = true;\n for (const unregister of [...owned.values()].reverse()) unregister();\n owned.clear();\n }\n };\n}\n\n/**\n * Cordis plugin entry point: register the reflex tool set for one activation.\n *\n * Returns nothing on purpose — Cordis interprets a plugin callback's return\n * value as an effect (a disposer, or an iterable/promise of disposers), so the\n * runtime is published through {@link applyReflex} instead.\n * @param ctx - registrant context carrying the tool and LLM services.\n * @param config - deployment configuration.\n */\nexport function apply(ctx: Context, config?: ReflexConfig): void {\n applyReflex(ctx, config);\n}\n\n/**\n * Same activation as {@link apply}, but hands the caller the runtime it built.\n *\n * Useful for tests, diagnostics, and Hosts that want to audit the ledger\n * directly. The runtime is deliberately *not* registered as a context service:\n * one deployment may activate the plugin more than once (say, with different\n * tool prefixes), which a single fixed service name could not represent.\n * @param ctx - registrant context carrying the tool and LLM services.\n * @param config - deployment configuration; defaults are resolved here, so a\n * raw or already-resolved config both work.\n * @returns the activation's runtime, disposed when the plugin unloads.\n */\nexport function applyReflex(ctx: Context, config?: ReflexConfig): ReflexRuntime {\n const resolved = resolveConfig(config);\n // `config` is kept as passed: when the Host is the Cordis loader it carries\n // schema-declared volatile references, and those are the only place a\n // config-only update (no remount) can be observed at all.\n const runtime = createReflexRuntime(resolved, {\n configSource: config,\n warn: (message) => ctx.logger?.('dsh-reflex')?.warn(message)\n });\n installActualProjection(ctx);\n\n ctx.effect(() => {\n // The tool surface is owned by a reconciler rather than registered once:\n // the loader commits `tools.enabled`/`toolPrefix` changes into the running\n // activation without remounting it, and the registry is what the model\n // actually sees. `refresh` is called once per actual commit and never on\n // the step/tool hot path, so the tool schemas are still built once per\n // change rather than once per call.\n const tools = installReflexToolSurface(ctx, runtime);\n runtime.attachToolSurface(\n (next) => tools.refresh(next),\n () => tools.registrationCount,\n () => tools.registrationEvents\n );\n tools.refresh(resolved);\n\n // A config-only settings save does not remount this plugin: the loader\n // commits the new values into the volatile references and dispatches this\n // event to the owning fiber. Re-resolving here makes the edited routing,\n // effort, intervention, and tool policies effective on the next\n // request/tool call instead of after a restart.\n const stopConfigWatch = ctx.on('loader/volatile-update', () => {\n if (runtime.disposed) return;\n runtime.refresh();\n });\n\n // The registry is process-wide, so the published surface is re-derived on\n // every change instead of assumed static.\n const stopObserving = ctx.on('tools/change', () => {\n if (runtime.disposed) return;\n tools.publish();\n });\n\n const stopRouting = installRouting(ctx, runtime);\n // The ledger is an audit question a person asks, not a decision the model\n // makes, so it is a Host command instead of a tool: `/reflex-ledger` reads\n // the same runtime and never opens a turn.\n const unregisterLedger = installLedgerCommand(ctx, runtime);\n // The automatic half of the plugin: the same System 1 judgments, spent at the\n // Host's own hook points instead of waiting for the model to call a tool. The\n // installer registers nothing when every capability is `off`, so an inactive\n // deployment pays for no listener and no state.\n const interventions = installInterventions(ctx, {\n config: resolved.interventions,\n pruneThreshold: resolved.pruneThreshold,\n // The tools of this plugin are already the optimizer's own output: judging\n // them again would spend a second judgment on the same payload.\n ownTools: reflexToolNames(resolved),\n stagnation: runtime.stagnationService,\n prune: runtime.pruneService,\n gate: runtime.gateService,\n audit: (record, session) => {\n // The session log is the one place a decision is durable; an agent without\n // a session simply records nothing, which is why this is guarded.\n if (session) appendInterventionRecord(session, record);\n },\n // Pruning is only allowed to replace a result when the original has really\n // been retained in a place that survives the replacement. The session log is\n // that place: a plugin record is ignorable by the model, carried by resume\n // and fork, and readable back — which the retention verifies before it\n // reports a locator. No verified retention, no reduction.\n retain: (session, request) => appendPrunedOriginal(session, request)\n });\n runtime.attachInterventions(\n interventions.engine,\n (next, pruneThreshold) => {\n // The prefix may have changed in the same commit: the engine's own-tool\n // exemption must name the tools that are registered *now*.\n interventions.reconfigure(next, pruneThreshold, reflexToolNames(runtime.effectiveConfig));\n },\n () => interventions.listenerCount\n );\n const unmountPanel = mountReflexPanel(ctx, runtime);\n\n const injectSettings = (ctx as { inject?: (deps: string[], cb: (scope: any) => void) => void }).inject;\n if (typeof injectSettings === 'function') {\n injectSettings(['settings'], (sctx) => {\n const svc = sctx?.settings;\n if (typeof svc?.configure === 'function') {\n sctx.effect(() => svc.configure({ auto: false }, (ctx as any).fiber));\n }\n });\n }\n\n return () => {\n stopConfigWatch();\n stopObserving();\n stopRouting();\n unregisterLedger();\n interventions.dispose();\n unmountPanel();\n tools.dispose();\n runtime.dispose();\n };\n }, 'reflex tools');\n\n return runtime;\n}\n\n/**\n * Install the request interception layers of this activation.\n *\n * The listeners are installed whenever the LLM service is present, because the\n * adaptive-effort layer is not tied to a virtual route: a deployment may enable\n * per-turn effort while routing is off, and a request may carry the `reflex`\n * marker on its own. Registering the virtual *route* stays opt-in — without a\n * single non-empty candidate pool (or with `routing.enabled: false`) nothing is\n * registered, so a `reflex` selection can never silently resolve to an\n * unconfigured provider. The absence of the LLM service is tolerated as well:\n * `inject` makes the Host wait for it, and this guard keeps direct embedders\n * (tests, `applyReflex` callers) working without one.\n * @param ctx - registrant context.\n * @param runtime - the activation's runtime.\n * @returns a disposer that releases the route and its listeners.\n */\nfunction installRouting(ctx: Context, runtime: ReflexRuntime): () => void {\n const llm = (ctx as { llm?: LlmRuntime }).llm;\n if (!llm) {\n ctx.logger?.('dsh-reflex')?.warn('LLM service is unavailable; request interception stays off for this activation');\n return () => {};\n }\n\n const installation = installModelRouting(ctx, {\n llm,\n router: runtime.modelRouter,\n effort: runtime.effort,\n route: routingActive(runtime.effectiveConfig),\n // Both are getters: a config-only save changes `maxTaskChars` and the router\n // provider between steps, and the next step must see the new value without\n // re-resolving the schema.\n maxTaskChars: () => runtime.effectiveConfig.routing.maxTaskChars,\n liveRouting: () => {\n const routing = runtime.effectiveConfig.routing;\n return {\n enabled: routing.enabled,\n virtualProvider: routing.virtualProvider,\n maxTaskChars: routing.maxTaskChars,\n models: routing.models\n };\n },\n // Live config, pulled once per step: identity comparison, no schema run\n // unless the loader actually committed a change.\n refreshConfig: () => runtime.refreshIfChanged(),\n warn: (message) => ctx.logger?.('dsh-reflex')?.warn(message)\n });\n // A second activation of this plugin joins the process-wide route; its live\n // policy is then the shared router's, so the panel and the dispatch path of\n // this activation must both read that one.\n runtime.adoptModelRouter(installation.router);\n // A config-only save can enable/disable the route or rename the virtual\n // provider. The registration lives on the LLM runtime, so the runtime calls\n // back here once per actual commit; the reconciler is idempotent.\n runtime.attachRouting(\n (routing) => {\n installation.refresh(routing);\n runtime.adoptModelRouter(installation.router);\n },\n () => installation.registrationEvents\n );\n\n return () => installation.dispose();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,aAAa,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,aAAa,EAAE,iBAAiB,EAAgD,MAAM,aAAa,CAAC;AAC9O,OAAO,EAAE,mBAAmB,EAAsB,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,eAAe,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAEhJ,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACxF,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAyB,MAAM,wBAAwB,CAAC;AAC5G,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACpF,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,iCAAiC,EAAE,MAAM,wBAAwB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,CAAC,kBAAkB,CACtC,CAAC;IAEF,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;AACtC,CAAC","sourcesContent":["import type { Agent } from '@deepseek-ai/dsh-agent';\nimport type { Context } from '@deepseek-ai/cordis';\nimport type { LlmRuntime } from '@deepseek-ai/dsh-llm';\n\nimport { Config, resolveConfig, resolveDelegationConfig, resolveEffortSetting, resolveApiKey, resolveSystemOneConfig, resolveToolsConfig, routingActive, volatileSnapshots, type ReflexConfig, type ResolvedReflexConfig } from './config.js';\nimport { createReflexRuntime, type ReflexRuntime } from './bridge.js';\nimport { installModelRouting } from './routing.js';\nimport { defineReflexTools, delegationExecutables, enabledReflexToolSuffixes, reflexToolNames, resolveReflexToolExecutables } from './tools.js';\nimport type { ReflexDelegationSeam, ReflexToolSuffix } from './tools.js';\nimport { DELEGATION_TOOL_NAME, createReflexDelegation } from './delegation-dispatch.js';\nimport { readDelegationHealth, watchDelegationHealth, type DelegationHealth } from './delegation-health.js';\nimport { installLedgerCommand } from './command.js';\nimport { mountReflexPanel } from './panel-mount.js';\nimport { installInterventions } from './interventions.js';\nimport { appendInterventionRecord, appendPrunedOriginal } from './session-audit.js';\nimport { installActualProjection } from './actual-projection.js';\nimport { installDelegatedEffortInheritance } from './effort-delegation.js';\n\n/**\n * DSH Host plugin that exposes the `harness-reflex` System One decision runtime\n * as in-process tools and as a System 1 model router.\n *\n * One activation owns one {@link ReflexRuntime} — its backend, ledger, the five\n * decision services, and the virtual→physical model router — and registers the\n * `reflex_*` tools on `ctx.tools`. Everything is created inside a single\n * `ctx.effect`, so unloading the plugin (or disposing the context) unregisters\n * every tool, detaches the `tools/change` observer, releases the virtual\n * provider route, unregisters `/reflex-ledger`, and drops the runtime whole.\n *\n * @module dsh-reflex\n */\n\ndeclare module '@deepseek-ai/cordis' {\n interface Events {\n /**\n * The loader committed new values into this activation's volatile config\n * references without remounting the plugin.\n *\n * Routing pools and the fallback are read per request, so the activation\n * only has to re-resolve them to make a settings edit effective; nothing\n * else about the running activation is re-created.\n * @param paths - changed config paths as key arrays.\n * @mode emit\n */\n 'loader/volatile-update'(paths: readonly (readonly string[])[]): void;\n }\n}\n\n/** Cordis plugin name. */\nexport const name = 'dsh-reflex';\n\n/**\n * The runtime needs the tool registry, the LLM service for model routing, and\n * the command registry for `/reflex-ledger`: the virtual provider is a real\n * provider route on `ctx.llm`, and the ledger command is a Host-rendered command\n * that never reaches the model.\n */\nexport const inject = ['tools', 'llm', 'commands'];\n\nexport { Config, resolveConfig, resolveDelegationConfig, resolveEffortSetting, resolveApiKey, resolveSystemOneConfig, resolveToolsConfig, routingActive, volatileSnapshots, createReflexRuntime, defineReflexTools, enabledReflexToolSuffixes, reflexToolNames };\nexport type { ReflexDelegationConfig, ReflexToolsConfig, ResolvedDelegationConfig, ResolvedToolsConfig } from './config.js';\nexport {\n INTERVENTION_CAPABILITIES,\n INTERVENTION_MODES,\n INTERVENTION_SETTINGS,\n resolveInterventionSetting,\n resolveInterventionsConfig\n} from './config.js';\nexport type { InterventionCapability, InterventionMode, InterventionSetting, ReflexInterventionsConfig, ResolvedInterventionsConfig } from './config.js';\nexport { INTERVENTION_SOURCE_KIND, InterventionEngine, WAIT_QUERY_TOOLS, installInterventions, isWaitQuery } from './interventions.js';\nexport type {\n InterventionAction,\n InterventionBaseline,\n InterventionCostBucket,\n InterventionInstallation,\n InterventionPlan,\n InterventionReport\n} from './interventions.js';\nexport type { InterventionAuditRecord } from './session-audit.js';\nexport { createBackend } from './bridge.js';\nexport {\n LEDGER_COMMAND_ENTRIES,\n REFLEX_LEDGER_COMMAND,\n REFLEX_LEDGER_COMMAND_DESCRIPTION,\n formatLedgerReport,\n installLedgerCommand\n} from './command.js';\nexport {\n PANEL_BASE,\n PANEL_LEDGER_WINDOW,\n PANEL_LEDGER_WINDOW_MAX,\n PANEL_PATHS,\n PANEL_ROUTES,\n REFLEX_PLUGIN_VERSION,\n answerPanelRequest,\n buildPanelSnapshot,\n clampLimit,\n isLoopbackAddress,\n isLoopbackIPv4,\n isPanelRequestAllowed,\n makePanelRoutes,\n projectEffortDecision,\n readLimit,\n readQuery,\n sendPanelAnswer\n} from './panel-api.js';\nexport type {\n PanelAnswer,\n PanelEffortDecision,\n PanelEffortView,\n PanelLedgerRow,\n PanelLedgerSummary,\n PanelLedgerView,\n PanelPluginView,\n PanelPoolEntry,\n PanelPoolView,\n PanelResponse,\n PanelRoutingView,\n PanelRuntimeFacts,\n PanelSnapshot,\n PanelSource,\n PanelSystemOneHealth,\n PanelSystemOneView\n} from './panel-api.js';\nexport { mountReflexPanel } from './panel-mount.js';\nexport { createPanelSource, panelFacts, panelPools } from './panel-mount.js';\nexport { ReflexRuntime } from './bridge.js';\nexport { REFLEX_TOOL_SUFFIXES } from './tools.js';\nexport { delegateServable, delegationExecutables } from './tools.js';\nexport {\n DELEGATION_BROKEN_WARNING,\n DELEGATION_MODEL_SELECTION_OFF_REASON,\n DELEGATION_TOOL_MISSING_REASON,\n readDelegationHealth,\n watchDelegationHealth\n} from './delegation-health.js';\nexport type { DelegationHealth, DelegationHealthState, DelegationHealthWatch, DelegationHealthWatchOptions } from './delegation-health.js';\nexport {\n DELEGATION_ROW_ID,\n MODEL_SELECTION_FIELD,\n OWNERSHIP_MARKER,\n PROFILE_PATCH_FILENAME,\n enableHostModelSelection,\n inspectHostModelSelection,\n planModelSelectionEdit,\n resolveProfilePatchPath\n} from './host-patch.js';\nexport type { HostPatchOutcome, HostPatchResult, PatchEditResult, PatchPathResolution } from './host-patch.js';\nexport { installModelRouting } from './routing.js';\nexport {\n ADAPTIVE_EFFORT_LEVELS,\n EFFORT_CHOICE_OPTIONS,\n EFFORT_LEVELS,\n EFFORT_TRIGGERS,\n EffortInterceptor,\n EffortStatusFeed,\n buildEffortChoice,\n classifyByCues,\n effortRank,\n formatEffortStatusLine,\n isAdaptiveEffortLevel,\n isEffortTrigger,\n levelOfChoiceOption,\n projectEffort,\n readEffortCues,\n snapEffort\n} from './effort.js';\nexport { EFFORT_RECORD_TYPE, appendEffortRecord, effortRecordsOf, toEffortAuditRecord } from './session-audit.js';\nexport {\n EFFORT_INHERIT_RECORD_TYPE,\n appendEffortInheritRecord,\n effortInheritRecordsOf,\n isEffortInheritAuditRecord\n} from './session-audit.js';\nexport type { EffortInheritAuditRecord } from './session-audit.js';\nexport {\n DELEGATION_EFFORT_REASON,\n currentSelectionOf,\n installDelegatedEffortInheritance,\n isDelegatedSession\n} from './effort-delegation.js';\nexport type {\n DelegatedEffortInheritance,\n DelegatedEffortInheritanceOptions\n} from './effort-delegation.js';\n// Retrieval of a pruned original is a public API, not an internal detail: the guide\n// tells a reader to import the function from the package root, so the root entry has\n// to export it together with the two names a caller needs to use it — the record's\n// own type, and the locator builder for the digest a decision record carries.\n// Exporting it only from `session-audit.js` would leave the documented example\n// unrunnable for an installed package.\nexport { PRUNED_ORIGINAL_RECORD_TYPE, pruneLocator, readPrunedOriginal } from './session-audit.js';\nexport type { PrunedOriginalRecord } from './session-audit.js';\nexport { ReflexVirtualAdapter } from './virtual-adapter.js';\nexport {\n ReflexRoutingError,\n VirtualModelRouter,\n alignReasoningEffort,\n formatTargetName,\n parseFallback,\n parseTargetName\n} from './router.js';\nexport type {\n ReflexConfig,\n ReflexEffortConfig,\n ReflexRoutingConfig,\n ReflexSystemOneConfig,\n ResolvedEffortConfig,\n ResolvedReflexConfig,\n ResolvedRoutingConfig,\n ResolvedSystemOneConfig\n} from './config.js';\nexport type { ReflexChoiceResult, ReflexLedgerResult, ReflexPruneResult } from './bridge.js';\nexport type { ReflexToolSuffix } from './tools.js';\nexport type { ModelRoutingInstallation, ModelRoutingOptions } from './routing.js';\nexport type {\n AdaptiveEffortLevel,\n EffortAgentFacts,\n EffortCues,\n EffortDecider,\n EffortDecision,\n EffortInterceptorOptions,\n EffortLevel,\n EffortOutcome,\n EffortRequestContext,\n EffortResolution,\n EffortSource,\n EffortTrigger,\n EffortTriggerKind,\n ReasoningEffortSetting,\n ReflexEffortStatus\n} from './effort.js';\nexport type { EffortAuditRecord } from './session-audit.js';\nexport type { ReflexVirtualAdapterOptions } from './virtual-adapter.js';\nexport type {\n ModelPoolEntry,\n ModelPools,\n PhysicalTarget,\n ReasoningProbe,\n ReasoningSupport,\n RouteContext,\n RouteDecision,\n RoutingFailureCode,\n RoutingReason,\n VirtualModelRouterOptions\n} from './router.js';\n\n/** The registry reconciler of one activation. */\ninterface ToolSurfaceInstallation {\n /**\n * Make the registry answer for exactly the tools `config` enables.\n *\n * Idempotent: when the enabled suffixes and the prefix are unchanged, no\n * registration is touched. A prefix edit unregisters the old names *before*\n * registering the new ones — the registry refuses a name that is already\n * taken, and a caller still holding an old name then gets \"unknown tool\"\n * instead of silently reaching an old body.\n * @param config - the resolved configuration currently in force.\n */\n refresh(config: ResolvedReflexConfig): void;\n /** Republish the surface from the names this activation really owns. */\n publish(): void;\n /** How many tools this activation currently owns. */\n readonly registrationCount: number;\n /** How many `tools.register` calls this activation has made in total. */\n readonly registrationEvents: number;\n /** Unregister every owned tool; idempotent. */\n dispose(): void;\n}\n\n/**\n * Register this activation's reflex tools, and keep the registry in step with\n * config-only saves.\n *\n * The registry is process-wide, so it is not enough to resolve the config on\n * every save: the *registrations* have to change with it. This installer owns\n * those registrations (one disposer per currently-owned name) and reconciles\n * them only when the effective surface actually differs, which is what keeps a\n * same-value save from churning the registry.\n * @param ctx - registrant context carrying `tools`.\n * @param runtime - the activation's runtime, for the definitions and surface.\n * @returns the reconciler and its diagnostics.\n */\nfunction installReflexToolSurface(ctx: Context, runtime: ReflexRuntime): ToolSurfaceInstallation {\n /** Unregister functions of the names this activation currently owns. */\n const owned = new Map<string, () => void>();\n let registrationEvents = 0;\n let disposed = false;\n\n // Resolved live from configuration only. The honest capability check cannot\n // happen here: this runs during `apply()`, where the plugin has no agent\n // scope, and `dsh-tools` is a *scoped* registry whose global view does not\n // contain a tool attached inside an agent preset — which is exactly where a\n // real deployment puts `tool-subagent`. Probing the global view at mount is\n // what made a correctly configured Host register nothing at all (g-054).\n // Whether the Host can carry a level is judged at call time, by the Host.\n const delegation = (): ReflexDelegationSeam | undefined =>\n createReflexDelegation({\n ctx,\n ledger: runtime.ledger,\n decide: (request) => runtime.choice(request),\n minConfidence: runtime.effort.minConfidence,\n warn: (message) => ctx.logger?.('dsh-reflex')?.warn(message)\n });\n\n /**\n * Suffixes enabled by config *and* consented to by the operator.\n *\n * Registering the delegate is a **configuration** decision: `delegation.enabled`\n * is the consent that writes the Host's `modelSelection` switch, and once it is\n * given the wrapper is registered unconditionally. It deliberately does not\n * consult the registry — at this point in the lifecycle there is no agent scope\n * to read as, so any registry answer would describe a view no session uses.\n * `delegationExecutables` still withholds the target when consent is off, which\n * is the one gate registration keeps.\n */\n const executableSuffixes = (config: ResolvedReflexConfig): ReflexToolSuffix[] =>\n resolveReflexToolExecutables(\n enabledReflexToolSuffixes(config),\n delegationExecutables(config, DELEGATION_TOOL_NAME)\n );\n\n const publish = (): void => {\n // Vocabulary order, not registration order: the panel and the runtime\n // surface must not reshuffle just because a tool was toggled later.\n runtime.noteToolSurface(\n executableSuffixes(runtime.effectiveConfig)\n .map((suffix) => `${runtime.effectiveConfig.toolPrefix}${suffix}`)\n .filter((name) => owned.has(name) && ctx.tools.get(name) !== undefined)\n );\n };\n\n return {\n refresh(config: ResolvedReflexConfig): void {\n if (disposed) return;\n const wanted = new Set(\n executableSuffixes(config).map((suffix) => `${config.toolPrefix}${suffix}`)\n );\n // Remove first: a duplicate registration throws, and a prefix rename has\n // no name in common with the old surface. A name we still want but that\n // the registry no longer answers for is dropped too, so a stray removal\n // is repaired on the next commit instead of leaving a permanent hole.\n for (const [name, unregister] of [...owned]) {\n if (wanted.has(name) && ctx.tools.get(name) !== undefined) continue;\n owned.delete(name);\n unregister();\n }\n const seam = delegation();\n for (const definition of defineReflexTools(runtime, config, seam)) {\n if (!wanted.has(definition.name)) continue;\n if (owned.has(definition.name)) continue;\n try {\n owned.set(definition.name, ctx.tools.register(definition));\n registrationEvents += 1;\n } catch (error) {\n // A foreign registration of the same name is not ours to take over:\n // leave it absent and let the panel report the surface that is real.\n ctx.logger?.('dsh-reflex')?.warn(\n `dsh-reflex: tool \"${definition.name}\" could not be registered (${(error as Error).message})`\n );\n }\n }\n publish();\n },\n publish,\n get registrationCount(): number {\n return owned.size;\n },\n get registrationEvents(): number {\n return registrationEvents;\n },\n dispose(): void {\n if (disposed) return;\n disposed = true;\n for (const unregister of [...owned.values()].reverse()) unregister();\n owned.clear();\n }\n };\n}\n\n/**\n * Cordis plugin entry point: register the reflex tool set for one activation.\n *\n * Returns nothing on purpose — Cordis interprets a plugin callback's return\n * value as an effect (a disposer, or an iterable/promise of disposers), so the\n * runtime is published through {@link applyReflex} instead.\n * @param ctx - registrant context carrying the tool and LLM services.\n * @param config - deployment configuration.\n */\nexport function apply(ctx: Context, config?: ReflexConfig): void {\n applyReflex(ctx, config);\n}\n\n/**\n * Same activation as {@link apply}, but hands the caller the runtime it built.\n *\n * Useful for tests, diagnostics, and Hosts that want to audit the ledger\n * directly. The runtime is deliberately *not* registered as a context service:\n * one deployment may activate the plugin more than once (say, with different\n * tool prefixes), which a single fixed service name could not represent.\n * @param ctx - registrant context carrying the tool and LLM services.\n * @param config - deployment configuration; defaults are resolved here, so a\n * raw or already-resolved config both work.\n * @returns the activation's runtime, disposed when the plugin unloads.\n */\nexport function applyReflex(ctx: Context, config?: ReflexConfig): ReflexRuntime {\n const resolved = resolveConfig(config);\n // `config` is kept as passed: when the Host is the Cordis loader it carries\n // schema-declared volatile references, and those are the only place a\n // config-only update (no remount) can be observed at all.\n const runtime = createReflexRuntime(resolved, {\n configSource: config,\n warn: (message) => ctx.logger?.('dsh-reflex')?.warn(message)\n });\n installActualProjection(ctx);\n\n ctx.effect(() => {\n // The tool surface is owned by a reconciler rather than registered once:\n // the loader commits `tools.enabled`/`toolPrefix` changes into the running\n // activation without remounting it, and the registry is what the model\n // actually sees. `refresh` is called once per actual commit and never on\n // the step/tool hot path, so the tool schemas are still built once per\n // change rather than once per call.\n const tools = installReflexToolSurface(ctx, runtime);\n runtime.attachToolSurface(\n (next) => tools.refresh(next),\n () => tools.registrationCount,\n () => tools.registrationEvents\n );\n tools.refresh(resolved);\n\n // The Host capability the delegate needs is read from the live registry, so\n // a broken one is reported and warned about. The read is **scoped**: a preset\n // deployment attaches `tool-subagent` to an agent, not to the global view, so\n // reading globally would call a working Host \"off\" (g-054). Until an agent\n // registers here the reading is `unknown` — which the panel shows as \"not\n // probed\", never as a fault. It never writes a configuration file: a switch\n // that went off might be a person's own decision, and turning it back on is\n // theirs to make.\n //\n // Registration is *not* a reaction of this watch any more (see\n // `executableSuffixes`): a tool must not appear or vanish because a scope\n // happened to become readable. The watch only reports.\n let observedAgent: Agent | undefined;\n const readHealth = (): DelegationHealth => readDelegationHealth(ctx, observedAgent);\n const delegationHealth = watchDelegationHealth({\n read: readHealth,\n warn: (message) => ctx.logger?.('dsh-reflex')?.warn(message),\n onChange: () => {\n if (runtime.disposed) return;\n tools.publish();\n }\n });\n runtime.attachDelegationHealth(\n () => delegationHealth.health,\n () => {\n tools.refresh(runtime.effectiveConfig);\n }\n );\n\n // No listener is installed for the tool registry: the reading is taken on\n // the panel's own poll (see `panel-mount.ts`), with whatever agent scope is\n // known by then. Re-reading on every registry change proved nothing — the\n // global view cannot resolve a preset-hosted tool — and cost a probe per\n // change.\n runtime.attachDelegationScope((agent) => {\n observedAgent = agent;\n // A new scope is a genuinely new view, so the reading is taken again in it.\n delegationHealth.check();\n });\n\n // A config-only settings save does not remount this plugin: the loader\n // commits the new values into the volatile references and dispatches this\n // event to the owning fiber. Re-resolving here makes the edited routing,\n // effort, intervention, and tool policies effective on the next\n // request/tool call instead of after a restart.\n const stopConfigWatch = ctx.on('loader/volatile-update', () => {\n if (runtime.disposed) return;\n runtime.refresh();\n });\n\n // The registry is process-wide, so the published surface is re-derived on\n // every change instead of assumed static.\n const stopObserving = ctx.on('tools/change', () => {\n if (runtime.disposed) return;\n // The published surface is re-derived, not the delegation *reading*: the\n // registry's global view cannot resolve a preset-hosted delegation tool, so\n // a probe on every change would only ever answer \"unknown\" — and an\n // \"unknown\" that triggered a refresh would be churn without information.\n tools.publish();\n });\n\n const stopRouting = installRouting(ctx, runtime);\n // A delegated agent cannot decide its own effort: the loop fixes the step's\n // selection before the request waterfall, so the marker is replaced with the\n // parent's level *on the selection itself* — before the next step reads it.\n const inheritance = installDelegatedEffortInheritance(ctx, {\n enabled: () => runtime.effort.enabled,\n sessionById: (id) => (ctx as any).sessions?.get?.(id),\n warn: (message) => ctx.logger?.('dsh-reflex')?.warn(message)\n });\n runtime.attachEffortInheritance(inheritance);\n // The ledger is an audit question a person asks, not a decision the model\n // makes, so it is a Host command instead of a tool: `/reflex-ledger` reads\n // the same runtime and never opens a turn.\n const unregisterLedger = installLedgerCommand(ctx, runtime);\n // The automatic half of the plugin: the same System 1 judgments, spent at the\n // Host's own hook points instead of waiting for the model to call a tool. The\n // installer registers nothing when every capability is `off`, so an inactive\n // deployment pays for no listener and no state.\n const interventions = installInterventions(ctx, {\n config: resolved.interventions,\n pruneThreshold: resolved.pruneThreshold,\n // The tools of this plugin are already the optimizer's own output: judging\n // them again would spend a second judgment on the same payload.\n ownTools: reflexToolNames(resolved),\n stagnation: runtime.stagnationService,\n prune: runtime.pruneService,\n gate: runtime.gateService,\n // Every judgment this engine spends is attributed like a tool call: the\n // ledger records the connection, the requested model and the source, so a\n // decision made at a Host hook point is no longer anonymous (g-068).\n attribute: (run, options) => runtime.attribute(run, options),\n audit: (record, session) => {\n // The session log is the one place a decision is durable; an agent without\n // a session simply records nothing, which is why this is guarded.\n if (session) appendInterventionRecord(session, record);\n },\n // Pruning is only allowed to replace a result when the original has really\n // been retained in a place that survives the replacement. The session log is\n // that place: a plugin record is ignorable by the model, carried by resume\n // and fork, and readable back — which the retention verifies before it\n // reports a locator. No verified retention, no reduction.\n retain: (session, request) => appendPrunedOriginal(session, request)\n });\n runtime.attachInterventions(\n interventions.engine,\n (next, pruneThreshold) => {\n // The prefix may have changed in the same commit: the engine's own-tool\n // exemption must name the tools that are registered *now*.\n interventions.reconfigure(next, pruneThreshold, reflexToolNames(runtime.effectiveConfig));\n },\n () => interventions.listenerCount\n );\n const unmountPanel = mountReflexPanel(ctx, runtime);\n\n const injectSettings = (ctx as { inject?: (deps: string[], cb: (scope: any) => void) => void }).inject;\n if (typeof injectSettings === 'function') {\n injectSettings(['settings'], (sctx) => {\n const svc = sctx?.settings;\n if (typeof svc?.configure === 'function') {\n sctx.effect(() => svc.configure({ auto: false }, (ctx as any).fiber));\n }\n });\n }\n\n return () => {\n stopConfigWatch();\n stopObserving();\n stopRouting();\n inheritance.dispose();\n unregisterLedger();\n interventions.dispose();\n unmountPanel();\n tools.dispose();\n runtime.dispose();\n };\n }, 'reflex tools');\n\n return runtime;\n}\n\n/**\n * Install the request interception layers of this activation.\n *\n * The listeners are installed whenever the LLM service is present, because the\n * adaptive-effort layer is not tied to a virtual route: a deployment may enable\n * per-turn effort while routing is off, and a request may carry the `reflex`\n * marker on its own. Registering the virtual *route* stays opt-in — without a\n * single non-empty candidate pool (or with `routing.enabled: false`) nothing is\n * registered, so a `reflex` selection can never silently resolve to an\n * unconfigured provider. The absence of the LLM service is tolerated as well:\n * `inject` makes the Host wait for it, and this guard keeps direct embedders\n * (tests, `applyReflex` callers) working without one.\n * @param ctx - registrant context.\n * @param runtime - the activation's runtime.\n * @returns a disposer that releases the route and its listeners.\n */\nfunction installRouting(ctx: Context, runtime: ReflexRuntime): () => void {\n const llm = (ctx as { llm?: LlmRuntime }).llm;\n if (!llm) {\n ctx.logger?.('dsh-reflex')?.warn('LLM service is unavailable; request interception stays off for this activation');\n return () => {};\n }\n\n const installation = installModelRouting(ctx, {\n llm,\n router: runtime.modelRouter,\n effort: runtime.effort,\n route: routingActive(runtime.effectiveConfig),\n // Both are getters: a config-only save changes `maxTaskChars` and the router\n // provider between steps, and the next step must see the new value without\n // re-resolving the schema.\n maxTaskChars: () => runtime.effectiveConfig.routing.maxTaskChars,\n liveRouting: () => {\n const routing = runtime.effectiveConfig.routing;\n return {\n enabled: routing.enabled,\n virtualProvider: routing.virtualProvider,\n maxTaskChars: routing.maxTaskChars,\n models: routing.models\n };\n },\n // Live config, pulled once per step: identity comparison, no schema run\n // unless the loader actually committed a change.\n refreshConfig: () => runtime.refreshIfChanged(),\n warn: (message) => ctx.logger?.('dsh-reflex')?.warn(message)\n });\n // A second activation of this plugin joins the process-wide route; its live\n // policy is then the shared router's, so the panel and the dispatch path of\n // this activation must both read that one.\n runtime.adoptModelRouter(installation.router);\n // A config-only save can enable/disable the route or rename the virtual\n // provider. The registration lives on the LLM runtime, so the runtime calls\n // back here once per actual commit; the reconciler is idempotent.\n runtime.attachRouting(\n (routing) => {\n installation.refresh(routing);\n runtime.adoptModelRouter(installation.router);\n },\n () => installation.registrationEvents\n );\n\n return () => installation.dispose();\n}\n"]}
|