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
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { decideDelegationEffort, recordDelegationDecision } from './delegation.js';
|
|
2
|
+
/**
|
|
3
|
+
* Find the Host's delegation tool in the registry, when it can carry a level.
|
|
4
|
+
*
|
|
5
|
+
* Two facts have to hold, and both are read from the live registry rather than
|
|
6
|
+
* assumed:
|
|
7
|
+
*
|
|
8
|
+
* 1. the tool is registered — the Host owns its name as configuration
|
|
9
|
+
* (`toolName`, default `subagent`), so candidate names are tried in order;
|
|
10
|
+
* 2. the tool *declares* `reasoning_effort`. The Host only adds that parameter
|
|
11
|
+
* to its schema when the deployment sets `modelSelection: true`; with the
|
|
12
|
+
* switch off the tool accepts no level at all.
|
|
13
|
+
*
|
|
14
|
+
* The parameter list is the model-facing schema the Host publishes, so this is
|
|
15
|
+
* an observable contract, not internals.
|
|
16
|
+
*
|
|
17
|
+
* ## Why the scope argument is not optional decoration
|
|
18
|
+
*
|
|
19
|
+
* `dsh-tools` is a *scoped* registry: `get(name)` with no scope reads the
|
|
20
|
+
* **global** view, and a tool mounted inside an **agent preset** — which is
|
|
21
|
+
* where a real deployment attaches `tool-subagent` — is not in that view at
|
|
22
|
+
* all. Reading the global view to decide whether this Host can delegate
|
|
23
|
+
* therefore answers "no tool" on every preset-hosted deployment, however
|
|
24
|
+
* correctly `modelSelection` is configured. Passing the calling agent reads the
|
|
25
|
+
* view that deployment actually serves, and is the only reading that can tell
|
|
26
|
+
* "the capability is off" from "this scope does not show it".
|
|
27
|
+
* @param ctx - context whose `tools` service is live.
|
|
28
|
+
* @param agent - the scope to read as; omitted selects the global view.
|
|
29
|
+
* @returns the registered name and whether it accepts a level, or `undefined`
|
|
30
|
+
* when that scope exposes no delegation tool at all.
|
|
31
|
+
*/
|
|
32
|
+
export function inspectDelegationTool(ctx, agent) {
|
|
33
|
+
for (const candidate of DELEGATION_TARGET_CANDIDATES) {
|
|
34
|
+
const definition = ctx.tools.get(candidate, agent);
|
|
35
|
+
if (definition === undefined)
|
|
36
|
+
continue;
|
|
37
|
+
const properties = definition.parameters?.properties;
|
|
38
|
+
return { toolName: candidate, acceptsReasoningEffort: properties !== undefined && 'reasoning_effort' in properties };
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
/** Candidate names of the Host delegation tool, in lookup order. */
|
|
43
|
+
const DELEGATION_TARGET_CANDIDATES = ['subagent', 'reflex_subagent'];
|
|
44
|
+
/**
|
|
45
|
+
* The name the seam dispatches to when no scope is available to confirm it.
|
|
46
|
+
*
|
|
47
|
+
* This is the Host tool's documented default (`toolName`, default `subagent`).
|
|
48
|
+
* Naming it here rather than reading it at mount is the whole point of the
|
|
49
|
+
* registration fix: at mount there is no agent scope, so the registry cannot
|
|
50
|
+
* answer, and "cannot answer" must not read as "cannot delegate".
|
|
51
|
+
*/
|
|
52
|
+
export const DELEGATION_TOOL_NAME = DELEGATION_TARGET_CANDIDATES[0];
|
|
53
|
+
/** The log line emitted when the Host tool exists but cannot carry a level. */
|
|
54
|
+
export const DELEGATION_MODEL_SELECTION_DISABLED = 'dsh-reflex: the subagent tool does not declare reasoning_effort (modelSelection is off), so a delegated call that carries a level will be refused by the Host; ' +
|
|
55
|
+
'enable modelSelection to let System 1 choose the child\'s reasoning level';
|
|
56
|
+
/**
|
|
57
|
+
* Read the parent's own effort and model from its composed options.
|
|
58
|
+
*
|
|
59
|
+
* Read live on every call rather than captured at mount: a session's selection
|
|
60
|
+
* changes between steps, and the fallback must inherit what the parent is using
|
|
61
|
+
* *now*.
|
|
62
|
+
* @param agent - the calling agent, when one is known.
|
|
63
|
+
* @returns the parent facts, with unknown fields omitted.
|
|
64
|
+
*/
|
|
65
|
+
export function parentDelegationFacts(agent) {
|
|
66
|
+
const options = agent?.options;
|
|
67
|
+
const effort = options?.reasoningEffort;
|
|
68
|
+
return {
|
|
69
|
+
...(typeof effort === 'string' ? { reasoningEffort: effort } : {}),
|
|
70
|
+
...(typeof options?.model === 'string' ? { model: options.model } : {})
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Rebuild the Host's refusal as the wrapper's own error.
|
|
75
|
+
*
|
|
76
|
+
* A failed tool call comes back as a settled failure, not as a thrown value.
|
|
77
|
+
* The message is passed through untouched — the assertions that prove "the Host
|
|
78
|
+
* refused, not this plugin" match on the Host's own wording — while the error
|
|
79
|
+
* identity is kept on the boxed `info` so a caller can tell a policy denial from
|
|
80
|
+
* a crash.
|
|
81
|
+
* @param result - the settled failure.
|
|
82
|
+
* @returns the error to throw.
|
|
83
|
+
*/
|
|
84
|
+
function delegationFailure(result) {
|
|
85
|
+
const error = new Error(result.error?.message ?? 'the delegation tool failed');
|
|
86
|
+
error.name = result.error?.info?.name ?? 'DelegationToolError';
|
|
87
|
+
if (result.error?.info?.code !== undefined)
|
|
88
|
+
error.cause = result.error.info;
|
|
89
|
+
return error;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Build the seam `reflex_delegate` dispatches through.
|
|
93
|
+
*
|
|
94
|
+
* ## Why this does not inspect the registry
|
|
95
|
+
*
|
|
96
|
+
* It used to refuse to build unless the live registry showed a delegation tool
|
|
97
|
+
* that *declares* `reasoning_effort`. That probe ran during `apply()`, where the
|
|
98
|
+
* plugin has no agent scope — and `dsh-tools` is scoped, so the probe read the
|
|
99
|
+
* **global** view. A real deployment attaches `tool-subagent` inside an **agent
|
|
100
|
+
* preset**, which the global view does not contain. The consequence was the bug
|
|
101
|
+
* this seam now avoids: a correctly configured Host (patch written,
|
|
102
|
+
* `modelSelection: true` dumped from the running config, the panel switch on)
|
|
103
|
+
* still got no `reflex_delegate`, because the one place the plugin looked for
|
|
104
|
+
* the capability is the one place a preset can never appear.
|
|
105
|
+
*
|
|
106
|
+
* So the capability question is not answered here at all. What this Host can
|
|
107
|
+
* serve is judged at **call time**, in the caller's own scope, by the Host's own
|
|
108
|
+
* argument validation: a `subagent` that does not accept `reasoning_effort`
|
|
109
|
+
* rejects the call, and {@link delegationFailure} rethrows that refusal verbatim.
|
|
110
|
+
* That refusal is strictly better evidence than a schema probe taken at mount —
|
|
111
|
+
* it comes from the very scope that would serve the call.
|
|
112
|
+
*
|
|
113
|
+
* Whether the *user* consented is a separate question, and it is not answered
|
|
114
|
+
* here either: `delegationExecutables` withholds the target unless
|
|
115
|
+
* `delegation.enabled` is true, so the registry only ever asks for a seam that
|
|
116
|
+
* configuration already asked for.
|
|
117
|
+
*
|
|
118
|
+
* @param options - the registry, the ledger, System One, and the confidence floor.
|
|
119
|
+
* @returns the seam. Never `undefined` for a capability reason: registration is
|
|
120
|
+
* decided by configuration, not by a registry view taken at mount.
|
|
121
|
+
*/
|
|
122
|
+
export function createReflexDelegation(options) {
|
|
123
|
+
// The Host tool's own default name. It is not read from the registry because
|
|
124
|
+
// no scope is available at mount (see above); the Host still owns the name, so
|
|
125
|
+
// a deployment that renamed it gets an honest "unknown tool" from dispatch
|
|
126
|
+
// rather than a wrapper that silently fails to appear.
|
|
127
|
+
const toolName = DELEGATION_TOOL_NAME;
|
|
128
|
+
const { ctx, ledger } = options;
|
|
129
|
+
return {
|
|
130
|
+
toolName,
|
|
131
|
+
async decide(args, agent) {
|
|
132
|
+
const parent = parentDelegationFacts(agent ?? options.agent?.());
|
|
133
|
+
const decision = await decideDelegationEffort({
|
|
134
|
+
description: args.description,
|
|
135
|
+
prompt: args.prompt,
|
|
136
|
+
decide: options.decide,
|
|
137
|
+
minConfidence: options.minConfidence,
|
|
138
|
+
parent
|
|
139
|
+
});
|
|
140
|
+
recordDelegationDecision(ledger, decision, args, parent);
|
|
141
|
+
return decision;
|
|
142
|
+
},
|
|
143
|
+
async dispatch(args, effort, signal, callingAgent) {
|
|
144
|
+
const arguments_ = {
|
|
145
|
+
prompt: args.prompt,
|
|
146
|
+
description: args.description,
|
|
147
|
+
reasoning_effort: effort,
|
|
148
|
+
...(args.provider === undefined ? {} : { provider: args.provider }),
|
|
149
|
+
...(args.model === undefined ? {} : { model: args.model }),
|
|
150
|
+
...(args.cwd === undefined ? {} : { cwd: args.cwd })
|
|
151
|
+
};
|
|
152
|
+
const agent = callingAgent ?? options.agent?.();
|
|
153
|
+
// Resolved per call, in the caller's own scope. This is where the registry
|
|
154
|
+
// *can* answer — unlike at mount — so a Host that renamed its delegation
|
|
155
|
+
// tool (`toolName`) is still reached. When the scope exposes none of the
|
|
156
|
+
// candidate names, the default is used and the dispatcher's own "unknown
|
|
157
|
+
// tool" is the answer, which is the honest one: this plugin must not
|
|
158
|
+
// report a Host capability it cannot see.
|
|
159
|
+
const target = agent === undefined ? undefined : inspectDelegationTool(ctx, agent);
|
|
160
|
+
const name = target === undefined ? toolName : target.toolName;
|
|
161
|
+
const batch = await ctx.tools.execute({
|
|
162
|
+
calls: [
|
|
163
|
+
{
|
|
164
|
+
type: 'tool-call',
|
|
165
|
+
id: `reflex-delegate-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
166
|
+
name,
|
|
167
|
+
arguments: JSON.stringify(arguments_)
|
|
168
|
+
}
|
|
169
|
+
],
|
|
170
|
+
signal,
|
|
171
|
+
...(agent === undefined ? {} : { agent })
|
|
172
|
+
});
|
|
173
|
+
const entry = batch.results[0];
|
|
174
|
+
if (entry === undefined)
|
|
175
|
+
throw new Error(`the delegation tool ${name} settled no result`);
|
|
176
|
+
if (entry.result.isError)
|
|
177
|
+
throw delegationFailure(entry.result);
|
|
178
|
+
const value = entry.result.value;
|
|
179
|
+
if (typeof value?.subagentId !== 'string' || value.subagentId.length === 0) {
|
|
180
|
+
throw new Error(`the delegation tool ${name} returned no subagentId`);
|
|
181
|
+
}
|
|
182
|
+
return { subagentId: value.subagentId };
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=delegation-dispatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegation-dispatch.js","sourceRoot":"","sources":["../src/delegation-dispatch.ts"],"names":[],"mappings":"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","sourcesContent":["import type { Context } from '@deepseek-ai/cordis';\nimport type { Agent } from '@deepseek-ai/dsh-agent';\n\nimport type { ChoiceRequest, ChoiceResponse } from './vendor/harness-reflex/backend/types.js';\nimport type { DecisionLedger } from './vendor/harness-reflex/core/ledger.js';\nimport {\n decideDelegationEffort,\n recordDelegationDecision,\n type DelegationDecision,\n type DelegationEffort,\n type DelegationParentFacts,\n type ReflexDelegateArgs\n} from './delegation.js';\nimport type { ReflexDelegationSeam } from './tools.js';\n\n/**\n * Bind `reflex_delegate` to the Host's own delegation tool.\n *\n * The whole point of this adapter is that it *adds no authority of its own*. It\n * decides one reasoning level, and then hands the call to the registry through\n * `ctx.tools.execute()` — the same public pipeline a model-issued call takes, so\n * the pre-execute policy, approvals, guards, the Host tool's own route policy\n * (`assertAllowedModelSelection`), its route preflight, and its recursion limit\n * all run exactly as they would for a direct call. When the Host refuses, its\n * refusal is rethrown verbatim; this layer never turns \"not allowed\" into a\n * different answer, and never checks a route itself.\n *\n * @module dsh-reflex/delegation-dispatch\n */\n\n/** Facts one activation needs to expose `reflex_delegate`, so a single descriptor covers them all. */\nexport interface ReflexDelegationOptions {\n /** The registry the delegation tool is registered in. */\n readonly ctx: Context;\n /** The activation's audit ledger. */\n readonly ledger: DecisionLedger;\n /** System One choice execution; the runtime's backend. */\n readonly decide: (request: ChoiceRequest) => Promise<ChoiceResponse>;\n /** Minimum System One confidence for its answer to be trusted. */\n readonly minConfidence: number;\n /** Agent the delegated call is attributed to; resolved per call when possible. */\n readonly agent?: () => Agent | undefined;\n /** Sink for the one deployment warning this module can raise. */\n readonly warn?: (message: string) => void;\n}\n\n/**\n * The `subagent` tool's model-facing route fields, spelled the way the Host\n * declares them.\n *\n * `reasoning_effort` is snake_case here because that *is* the Host tool's\n * parameter name; the camelCase id is what the Host maps it onto internally.\n */\ninterface DelegationToolArguments {\n prompt: string;\n description: string;\n reasoning_effort: DelegationEffort;\n provider?: string;\n model?: string;\n cwd?: string;\n}\n\n/**\n * Find the Host's delegation tool in the registry, when it can carry a level.\n *\n * Two facts have to hold, and both are read from the live registry rather than\n * assumed:\n *\n * 1. the tool is registered — the Host owns its name as configuration\n * (`toolName`, default `subagent`), so candidate names are tried in order;\n * 2. the tool *declares* `reasoning_effort`. The Host only adds that parameter\n * to its schema when the deployment sets `modelSelection: true`; with the\n * switch off the tool accepts no level at all.\n *\n * The parameter list is the model-facing schema the Host publishes, so this is\n * an observable contract, not internals.\n *\n * ## Why the scope argument is not optional decoration\n *\n * `dsh-tools` is a *scoped* registry: `get(name)` with no scope reads the\n * **global** view, and a tool mounted inside an **agent preset** — which is\n * where a real deployment attaches `tool-subagent` — is not in that view at\n * all. Reading the global view to decide whether this Host can delegate\n * therefore answers \"no tool\" on every preset-hosted deployment, however\n * correctly `modelSelection` is configured. Passing the calling agent reads the\n * view that deployment actually serves, and is the only reading that can tell\n * \"the capability is off\" from \"this scope does not show it\".\n * @param ctx - context whose `tools` service is live.\n * @param agent - the scope to read as; omitted selects the global view.\n * @returns the registered name and whether it accepts a level, or `undefined`\n * when that scope exposes no delegation tool at all.\n */\nexport function inspectDelegationTool(ctx: Context, agent?: Agent): DelegationTarget | undefined {\n for (const candidate of DELEGATION_TARGET_CANDIDATES) {\n const definition = ctx.tools.get(candidate, agent);\n if (definition === undefined) continue;\n const properties = (definition.parameters as { properties?: Record<string, unknown> } | undefined)?.properties;\n return { toolName: candidate, acceptsReasoningEffort: properties !== undefined && 'reasoning_effort' in properties };\n }\n return undefined;\n}\n\n/** Candidate names of the Host delegation tool, in lookup order. */\nconst DELEGATION_TARGET_CANDIDATES = ['subagent', 'reflex_subagent'] as const;\n\n/**\n * The name the seam dispatches to when no scope is available to confirm it.\n *\n * This is the Host tool's documented default (`toolName`, default `subagent`).\n * Naming it here rather than reading it at mount is the whole point of the\n * registration fix: at mount there is no agent scope, so the registry cannot\n * answer, and \"cannot answer\" must not read as \"cannot delegate\".\n */\nexport const DELEGATION_TOOL_NAME: string = DELEGATION_TARGET_CANDIDATES[0];\n\n/**\n * The Host delegation tool as this activation can use it.\n *\n * Separates \"there is no such tool\" from \"there is one, but it cannot carry a\n * reasoning level\", because the two need different answers: the first is silent,\n * the second is a loud deployment problem the operator has to hear about.\n */\nexport interface DelegationTarget {\n /** Registered tool name. */\n readonly toolName: string;\n /** Whether the tool declares `reasoning_effort` (Host `modelSelection: true`). */\n readonly acceptsReasoningEffort: boolean;\n}\n\n/** The log line emitted when the Host tool exists but cannot carry a level. */\nexport const DELEGATION_MODEL_SELECTION_DISABLED =\n 'dsh-reflex: the subagent tool does not declare reasoning_effort (modelSelection is off), so a delegated call that carries a level will be refused by the Host; ' +\n 'enable modelSelection to let System 1 choose the child\\'s reasoning level';\n\n/**\n * Read the parent's own effort and model from its composed options.\n *\n * Read live on every call rather than captured at mount: a session's selection\n * changes between steps, and the fallback must inherit what the parent is using\n * *now*.\n * @param agent - the calling agent, when one is known.\n * @returns the parent facts, with unknown fields omitted.\n */\nexport function parentDelegationFacts(agent: Agent | undefined): DelegationParentFacts {\n const options = (agent as { options?: { model?: string; reasoningEffort?: unknown } } | undefined)?.options;\n const effort = options?.reasoningEffort;\n return {\n ...(typeof effort === 'string' ? { reasoningEffort: effort } : {}),\n ...(typeof options?.model === 'string' ? { model: options.model } : {})\n };\n}\n\n/**\n * Rebuild the Host's refusal as the wrapper's own error.\n *\n * A failed tool call comes back as a settled failure, not as a thrown value.\n * The message is passed through untouched — the assertions that prove \"the Host\n * refused, not this plugin\" match on the Host's own wording — while the error\n * identity is kept on the boxed `info` so a caller can tell a policy denial from\n * a crash.\n * @param result - the settled failure.\n * @returns the error to throw.\n */\nfunction delegationFailure(result: { error?: { message?: string; info?: { name?: string; code?: string } } }): Error {\n const error = new Error(result.error?.message ?? 'the delegation tool failed');\n error.name = result.error?.info?.name ?? 'DelegationToolError';\n if (result.error?.info?.code !== undefined) error.cause = result.error.info;\n return error;\n}\n\n/**\n * Build the seam `reflex_delegate` dispatches through.\n *\n * ## Why this does not inspect the registry\n *\n * It used to refuse to build unless the live registry showed a delegation tool\n * that *declares* `reasoning_effort`. That probe ran during `apply()`, where the\n * plugin has no agent scope — and `dsh-tools` is scoped, so the probe read the\n * **global** view. A real deployment attaches `tool-subagent` inside an **agent\n * preset**, which the global view does not contain. The consequence was the bug\n * this seam now avoids: a correctly configured Host (patch written,\n * `modelSelection: true` dumped from the running config, the panel switch on)\n * still got no `reflex_delegate`, because the one place the plugin looked for\n * the capability is the one place a preset can never appear.\n *\n * So the capability question is not answered here at all. What this Host can\n * serve is judged at **call time**, in the caller's own scope, by the Host's own\n * argument validation: a `subagent` that does not accept `reasoning_effort`\n * rejects the call, and {@link delegationFailure} rethrows that refusal verbatim.\n * That refusal is strictly better evidence than a schema probe taken at mount —\n * it comes from the very scope that would serve the call.\n *\n * Whether the *user* consented is a separate question, and it is not answered\n * here either: `delegationExecutables` withholds the target unless\n * `delegation.enabled` is true, so the registry only ever asks for a seam that\n * configuration already asked for.\n *\n * @param options - the registry, the ledger, System One, and the confidence floor.\n * @returns the seam. Never `undefined` for a capability reason: registration is\n * decided by configuration, not by a registry view taken at mount.\n */\nexport function createReflexDelegation(options: ReflexDelegationOptions): ReflexDelegationSeam | undefined {\n // The Host tool's own default name. It is not read from the registry because\n // no scope is available at mount (see above); the Host still owns the name, so\n // a deployment that renamed it gets an honest \"unknown tool\" from dispatch\n // rather than a wrapper that silently fails to appear.\n const toolName = DELEGATION_TOOL_NAME;\n\n const { ctx, ledger } = options;\n\n return {\n toolName,\n\n async decide(args: ReflexDelegateArgs, agent?: Agent): Promise<DelegationDecision> {\n const parent = parentDelegationFacts(agent ?? options.agent?.());\n const decision = await decideDelegationEffort({\n description: args.description,\n prompt: args.prompt,\n decide: options.decide,\n minConfidence: options.minConfidence,\n parent\n });\n recordDelegationDecision(ledger, decision, args, parent);\n return decision;\n },\n\n async dispatch(\n args: ReflexDelegateArgs,\n effort: DelegationEffort,\n signal: AbortSignal,\n callingAgent?: Agent\n ): Promise<{ subagentId: string }> {\n const arguments_: DelegationToolArguments = {\n prompt: args.prompt,\n description: args.description,\n reasoning_effort: effort,\n ...(args.provider === undefined ? {} : { provider: args.provider }),\n ...(args.model === undefined ? {} : { model: args.model }),\n ...(args.cwd === undefined ? {} : { cwd: args.cwd })\n };\n\n const agent = callingAgent ?? options.agent?.();\n // Resolved per call, in the caller's own scope. This is where the registry\n // *can* answer — unlike at mount — so a Host that renamed its delegation\n // tool (`toolName`) is still reached. When the scope exposes none of the\n // candidate names, the default is used and the dispatcher's own \"unknown\n // tool\" is the answer, which is the honest one: this plugin must not\n // report a Host capability it cannot see.\n const target = agent === undefined ? undefined : inspectDelegationTool(ctx, agent);\n const name = target === undefined ? toolName : target.toolName;\n const batch = await ctx.tools.execute({\n calls: [\n {\n type: 'tool-call',\n id: `reflex-delegate-${Date.now()}-${Math.random().toString(36).slice(2, 8)}` as never,\n name,\n arguments: JSON.stringify(arguments_)\n }\n ],\n signal,\n ...(agent === undefined ? {} : { agent })\n });\n\n const entry = batch.results[0];\n if (entry === undefined) throw new Error(`the delegation tool ${name} settled no result`);\n if (entry.result.isError) throw delegationFailure(entry.result);\n const value = entry.result.value as { subagentId?: unknown } | undefined;\n if (typeof value?.subagentId !== 'string' || value.subagentId.length === 0) {\n throw new Error(`the delegation tool ${name} returned no subagentId`);\n }\n return { subagentId: value.subagentId };\n }\n };\n}\n"]}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
2
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
+
/**
|
|
4
|
+
* Runtime detection of a *broken* delegation capability.
|
|
5
|
+
*
|
|
6
|
+
* `reflex_delegate` hands the DSH delegation tool a System One reasoning level,
|
|
7
|
+
* which only a Host with `modelSelection: true` accepts. What this module
|
|
8
|
+
* reports is deliberately restricted to what it can actually **observe**, and
|
|
9
|
+
* the restriction is the point:
|
|
10
|
+
*
|
|
11
|
+
* - a reading is taken in a **scope** that can be read; without one the answer
|
|
12
|
+
* is `unknown`, never a guess (see below);
|
|
13
|
+
* - `missing-tool` and `model-selection-off` are reported only when the tool is
|
|
14
|
+
* genuinely absent from, or genuinely bare in, that scope;
|
|
15
|
+
* - it never writes configuration in response. A patch that stops asking for
|
|
16
|
+
* `modelSelection` is indistinguishable from a user who deliberately turned it
|
|
17
|
+
* back off, and turning a user's switch back on is exactly the boundary the
|
|
18
|
+
* goal forbids. Re-enabling is a user action: tick the switch again, which is
|
|
19
|
+
* a fresh consent and a fresh write.
|
|
20
|
+
*
|
|
21
|
+
* ## Why "unknown" exists (and why it is not "off")
|
|
22
|
+
*
|
|
23
|
+
* `dsh-tools` is a scoped registry: `get(name)` with no scope reads the **global**
|
|
24
|
+
* view, and a tool attached inside an **agent preset** — where a real deployment
|
|
25
|
+
* puts `tool-subagent` — is not in it. Asking the global view therefore answers
|
|
26
|
+
* "no such tool" on *every* preset-hosted deployment, however correctly
|
|
27
|
+
* `modelSelection` is configured.
|
|
28
|
+
*
|
|
29
|
+
* Reporting that as `model-selection-off` was actively misleading: the panel said
|
|
30
|
+
* a working capability was switched off, and the registration path (which read
|
|
31
|
+
* the same view) refused to register the tool. "This scope does not show the
|
|
32
|
+
* tool" is not evidence that "the capability is off". So an unreadable scope is
|
|
33
|
+
* reported as `unknown`, which is the honest answer and the one the panel shows
|
|
34
|
+
* as "not probed yet" rather than as a fault.
|
|
35
|
+
*
|
|
36
|
+
* @module dsh-reflex/delegation-health
|
|
37
|
+
*/
|
|
38
|
+
/** Why the delegate capability is (or is not) usable right now. */
|
|
39
|
+
export type DelegationHealthState =
|
|
40
|
+
/** The Host delegation tool, read in a readable scope, declares `reasoning_effort`. */
|
|
41
|
+
'ready'
|
|
42
|
+
/** The scope that was read genuinely exposes no delegation tool. */
|
|
43
|
+
| 'missing-tool'
|
|
44
|
+
/** The scope that was read exposes a delegation tool without the level parameter. */
|
|
45
|
+
| 'model-selection-off'
|
|
46
|
+
/**
|
|
47
|
+
* Nothing was observed, so nothing is claimed.
|
|
48
|
+
*
|
|
49
|
+
* No scope was available to read (the mount path has none), so neither
|
|
50
|
+
* "ready" nor "broken" is known. This is a *reporting* state, never a reason
|
|
51
|
+
* to withdraw anything.
|
|
52
|
+
*/
|
|
53
|
+
| 'unknown';
|
|
54
|
+
/** One reading of the live Host, plus the consequence for this activation. */
|
|
55
|
+
export interface DelegationHealth {
|
|
56
|
+
/** What the live registry says, or `unknown` when no scope could be read. */
|
|
57
|
+
state: DelegationHealthState;
|
|
58
|
+
/** Registered name of the Host delegation tool, when one was observed. */
|
|
59
|
+
toolName?: string;
|
|
60
|
+
/** One-line reason, present whenever the state is not `ready`. */
|
|
61
|
+
reason?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Whether a *broken* capability was observed.
|
|
64
|
+
*
|
|
65
|
+
* `false` for `unknown`: nothing observed is nothing withdrawn. Registration is
|
|
66
|
+
* decided by configuration, so this flag never gates the wrapper.
|
|
67
|
+
*/
|
|
68
|
+
delegateAvailable: boolean;
|
|
69
|
+
}
|
|
70
|
+
/** The log line emitted when a previously working delegation stops working. */
|
|
71
|
+
export declare const DELEGATION_BROKEN_WARNING: string;
|
|
72
|
+
/** The reason shown on the panel when a read scope genuinely lacks the parameter. */
|
|
73
|
+
export declare const DELEGATION_MODEL_SELECTION_OFF_REASON = "The host subagent tool does not declare reasoning_effort, so a decided level cannot reach the child. Tick Delegation again to write the host modelSelection switch (takes effect after a DSH restart).";
|
|
74
|
+
/** The panel reason when the read scope genuinely has no delegation tool. */
|
|
75
|
+
export declare const DELEGATION_TOOL_MISSING_REASON = "This host exposes no subagent tool in the scope that was read, so there is nothing for reflex_delegate to wrap.";
|
|
76
|
+
/** The panel reason when no scope could be read, so no claim is made. */
|
|
77
|
+
export declare const DELEGATION_UNPROBED_REASON = "The host capability was not probed: no agent scope was available to read, and a preset-hosted subagent tool is not visible from the global view. reflex_delegate is registered from configuration; whether a level can be carried is settled by the Host when a delegation is called.";
|
|
78
|
+
/**
|
|
79
|
+
* Read the live delegation capability of one Host context.
|
|
80
|
+
*
|
|
81
|
+
* Without `agent` this reads the global view, which cannot see a preset-hosted
|
|
82
|
+
* tool; the reading is then only trusted when it finds the tool (a tool that *is*
|
|
83
|
+
* visible globally is genuinely there). Finding nothing proves nothing, and is
|
|
84
|
+
* reported as `unknown`.
|
|
85
|
+
* @param ctx - a context whose `tools` registry is live.
|
|
86
|
+
* @param agent - the scope to read as (the calling agent, or a preset); omitted
|
|
87
|
+
* selects the global view.
|
|
88
|
+
* @returns the state, its reason, and whether a *broken* capability was observed.
|
|
89
|
+
*/
|
|
90
|
+
export declare function readDelegationHealth(ctx: Context, agent?: Agent): DelegationHealth;
|
|
91
|
+
/** What one detection pass observed and did. */
|
|
92
|
+
export interface DelegationHealthWatch {
|
|
93
|
+
/** The current reading. */
|
|
94
|
+
readonly health: DelegationHealth;
|
|
95
|
+
/**
|
|
96
|
+
* Re-read the live registry, warning once on a ready → broken transition.
|
|
97
|
+
* @returns the new reading.
|
|
98
|
+
*/
|
|
99
|
+
check(): DelegationHealth;
|
|
100
|
+
/**
|
|
101
|
+
* Forget that a tool was ever usable.
|
|
102
|
+
*
|
|
103
|
+
* Called when the deployment itself turned the capability off (the user
|
|
104
|
+
* unticked the switch): the next activation of the tool must not be reported
|
|
105
|
+
* as "it broke".
|
|
106
|
+
*/
|
|
107
|
+
forget(): void;
|
|
108
|
+
}
|
|
109
|
+
/** Options of {@link watchDelegationHealth}. */
|
|
110
|
+
export interface DelegationHealthWatchOptions {
|
|
111
|
+
/** Live registry read. */
|
|
112
|
+
readonly read: () => DelegationHealth;
|
|
113
|
+
/** Warning sink; called at most once per ready → broken transition. */
|
|
114
|
+
readonly warn?: (message: string) => void;
|
|
115
|
+
/** Called after a reading that changed the answer the surface should show. */
|
|
116
|
+
readonly onChange?: (health: DelegationHealth) => void;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Build the watch a tool surface keeps beside its reconcile callback.
|
|
120
|
+
*
|
|
121
|
+
* The transition discipline is the whole behaviour: a Host that *never* exposed
|
|
122
|
+
* the capability (a headless embedder, a deployment with `modelSelection` off
|
|
123
|
+
* from the start) is not an error and must not warn — it is simply not offered.
|
|
124
|
+
* Only a capability that was observably working and then stopped is reported.
|
|
125
|
+
*
|
|
126
|
+
* An `unknown` reading neither warns nor counts as an episode: it is the absence
|
|
127
|
+
* of evidence, and "we did not look" must not read as "it broke".
|
|
128
|
+
* @param options - the live read, a warning sink, and a change observer.
|
|
129
|
+
* @returns the watch, with its current reading.
|
|
130
|
+
*/
|
|
131
|
+
export declare function watchDelegationHealth(options: DelegationHealthWatchOptions): DelegationHealthWatch;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { inspectDelegationTool } from './delegation-dispatch.js';
|
|
2
|
+
/** The log line emitted when a previously working delegation stops working. */
|
|
3
|
+
export const DELEGATION_BROKEN_WARNING = 'dsh-reflex: the subagent tool no longer declares reasoning_effort (modelSelection is off again), so a delegated call carrying a reasoning level will be refused by the Host. ' +
|
|
4
|
+
'Nothing in your configuration was changed: re-tick "Delegation" in the Reflex settings after restarting DSH, and the level is passed again.';
|
|
5
|
+
/** The reason shown on the panel when a read scope genuinely lacks the parameter. */
|
|
6
|
+
export const DELEGATION_MODEL_SELECTION_OFF_REASON = 'The host subagent tool does not declare reasoning_effort, so a decided level cannot reach the child. Tick Delegation again to write the host modelSelection switch (takes effect after a DSH restart).';
|
|
7
|
+
/** The panel reason when the read scope genuinely has no delegation tool. */
|
|
8
|
+
export const DELEGATION_TOOL_MISSING_REASON = 'This host exposes no subagent tool in the scope that was read, so there is nothing for reflex_delegate to wrap.';
|
|
9
|
+
/** The panel reason when no scope could be read, so no claim is made. */
|
|
10
|
+
export const DELEGATION_UNPROBED_REASON = 'The host capability was not probed: no agent scope was available to read, and a preset-hosted subagent tool is not visible from the global view. reflex_delegate is registered from configuration; whether a level can be carried is settled by the Host when a delegation is called.';
|
|
11
|
+
/**
|
|
12
|
+
* Read the live delegation capability of one Host context.
|
|
13
|
+
*
|
|
14
|
+
* Without `agent` this reads the global view, which cannot see a preset-hosted
|
|
15
|
+
* tool; the reading is then only trusted when it finds the tool (a tool that *is*
|
|
16
|
+
* visible globally is genuinely there). Finding nothing proves nothing, and is
|
|
17
|
+
* reported as `unknown`.
|
|
18
|
+
* @param ctx - a context whose `tools` registry is live.
|
|
19
|
+
* @param agent - the scope to read as (the calling agent, or a preset); omitted
|
|
20
|
+
* selects the global view.
|
|
21
|
+
* @returns the state, its reason, and whether a *broken* capability was observed.
|
|
22
|
+
*/
|
|
23
|
+
export function readDelegationHealth(ctx, agent) {
|
|
24
|
+
const target = inspectDelegationTool(ctx, agent);
|
|
25
|
+
if (target === undefined) {
|
|
26
|
+
// A global view that shows no tool proves nothing: the tool may simply live
|
|
27
|
+
// in a preset scope this view cannot see. Only a readable scope that lacks
|
|
28
|
+
// it is evidence. "Cannot see" must never be reported as "is off".
|
|
29
|
+
if (agent === undefined) {
|
|
30
|
+
return { state: 'unknown', reason: DELEGATION_UNPROBED_REASON, delegateAvailable: false };
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
state: 'missing-tool',
|
|
34
|
+
reason: DELEGATION_TOOL_MISSING_REASON,
|
|
35
|
+
delegateAvailable: false
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (!target.acceptsReasoningEffort) {
|
|
39
|
+
return {
|
|
40
|
+
state: 'model-selection-off',
|
|
41
|
+
toolName: target.toolName,
|
|
42
|
+
reason: DELEGATION_MODEL_SELECTION_OFF_REASON,
|
|
43
|
+
delegateAvailable: false
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return { state: 'ready', toolName: target.toolName, delegateAvailable: true };
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Build the watch a tool surface keeps beside its reconcile callback.
|
|
50
|
+
*
|
|
51
|
+
* The transition discipline is the whole behaviour: a Host that *never* exposed
|
|
52
|
+
* the capability (a headless embedder, a deployment with `modelSelection` off
|
|
53
|
+
* from the start) is not an error and must not warn — it is simply not offered.
|
|
54
|
+
* Only a capability that was observably working and then stopped is reported.
|
|
55
|
+
*
|
|
56
|
+
* An `unknown` reading neither warns nor counts as an episode: it is the absence
|
|
57
|
+
* of evidence, and "we did not look" must not read as "it broke".
|
|
58
|
+
* @param options - the live read, a warning sink, and a change observer.
|
|
59
|
+
* @returns the watch, with its current reading.
|
|
60
|
+
*/
|
|
61
|
+
export function watchDelegationHealth(options) {
|
|
62
|
+
let current = options.read();
|
|
63
|
+
/** Whether this watch has ever seen the wrapper usable. */
|
|
64
|
+
let wasAvailable = current.delegateAvailable;
|
|
65
|
+
/** Whether the withdrawal has already been reported for this episode. */
|
|
66
|
+
let reported = false;
|
|
67
|
+
const observe = (next) => {
|
|
68
|
+
const changed = next.state !== current.state;
|
|
69
|
+
current = next;
|
|
70
|
+
if (next.delegateAvailable) {
|
|
71
|
+
wasAvailable = true;
|
|
72
|
+
reported = false;
|
|
73
|
+
}
|
|
74
|
+
else if (wasAvailable && !reported && next.state === 'model-selection-off') {
|
|
75
|
+
// One warning per episode: a registry that churns must not flood the log,
|
|
76
|
+
// which is what makes the single line worth reading.
|
|
77
|
+
reported = true;
|
|
78
|
+
options.warn?.(DELEGATION_BROKEN_WARNING);
|
|
79
|
+
}
|
|
80
|
+
if (changed)
|
|
81
|
+
options.onChange?.(next);
|
|
82
|
+
return next;
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
get health() {
|
|
86
|
+
return current;
|
|
87
|
+
},
|
|
88
|
+
check() {
|
|
89
|
+
return observe(options.read());
|
|
90
|
+
},
|
|
91
|
+
forget() {
|
|
92
|
+
wasAvailable = false;
|
|
93
|
+
reported = false;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=delegation-health.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegation-health.js","sourceRoot":"","sources":["../src/delegation-health.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAwEjE,+EAA+E;AAC/E,MAAM,CAAC,MAAM,yBAAyB,GACpC,+KAA+K;IAC/K,6IAA6I,CAAC;AAEhJ,qFAAqF;AACrF,MAAM,CAAC,MAAM,qCAAqC,GAChD,wMAAwM,CAAC;AAE3M,6EAA6E;AAC7E,MAAM,CAAC,MAAM,8BAA8B,GACzC,iHAAiH,CAAC;AAEpH,yEAAyE;AACzE,MAAM,CAAC,MAAM,0BAA0B,GACrC,uRAAuR,CAAC;AAE1R;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAY,EAAE,KAAa;IAC9D,MAAM,MAAM,GAAG,qBAAqB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACjD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,4EAA4E;QAC5E,2EAA2E;QAC3E,mEAAmE;QACnE,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC;QAC5F,CAAC;QACD,OAAO;YACL,KAAK,EAAE,cAAc;YACrB,MAAM,EAAE,8BAA8B;YACtC,iBAAiB,EAAE,KAAK;SACzB,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,sBAAsB,EAAE,CAAC;QACnC,OAAO;YACL,KAAK,EAAE,qBAAqB;YAC5B,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,qCAAqC;YAC7C,iBAAiB,EAAE,KAAK;SACzB,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC;AAChF,CAAC;AA+BD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAqC;IACzE,IAAI,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC7B,2DAA2D;IAC3D,IAAI,YAAY,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAC7C,yEAAyE;IACzE,IAAI,QAAQ,GAAG,KAAK,CAAC;IAErB,MAAM,OAAO,GAAG,CAAC,IAAsB,EAAoB,EAAE;QAC3D,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK,CAAC;QAC7C,OAAO,GAAG,IAAI,CAAC;QACf,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC3B,YAAY,GAAG,IAAI,CAAC;YACpB,QAAQ,GAAG,KAAK,CAAC;QACnB,CAAC;aAAM,IAAI,YAAY,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,KAAK,KAAK,qBAAqB,EAAE,CAAC;YAC7E,0EAA0E;YAC1E,qDAAqD;YACrD,QAAQ,GAAG,IAAI,CAAC;YAChB,OAAO,CAAC,IAAI,EAAE,CAAC,yBAAyB,CAAC,CAAC;QAC5C,CAAC;QACD,IAAI,OAAO;YAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IAEF,OAAO;QACL,IAAI,MAAM;YACR,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,KAAK;YACH,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QACjC,CAAC;QACD,MAAM;YACJ,YAAY,GAAG,KAAK,CAAC;YACrB,QAAQ,GAAG,KAAK,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { Agent } from '@deepseek-ai/dsh-agent';\nimport type { Context } from '@deepseek-ai/cordis';\n\nimport { inspectDelegationTool } from './delegation-dispatch.js';\n\n/**\n * Runtime detection of a *broken* delegation capability.\n *\n * `reflex_delegate` hands the DSH delegation tool a System One reasoning level,\n * which only a Host with `modelSelection: true` accepts. What this module\n * reports is deliberately restricted to what it can actually **observe**, and\n * the restriction is the point:\n *\n * - a reading is taken in a **scope** that can be read; without one the answer\n * is `unknown`, never a guess (see below);\n * - `missing-tool` and `model-selection-off` are reported only when the tool is\n * genuinely absent from, or genuinely bare in, that scope;\n * - it never writes configuration in response. A patch that stops asking for\n * `modelSelection` is indistinguishable from a user who deliberately turned it\n * back off, and turning a user's switch back on is exactly the boundary the\n * goal forbids. Re-enabling is a user action: tick the switch again, which is\n * a fresh consent and a fresh write.\n *\n * ## Why \"unknown\" exists (and why it is not \"off\")\n *\n * `dsh-tools` is a scoped registry: `get(name)` with no scope reads the **global**\n * view, and a tool attached inside an **agent preset** — where a real deployment\n * puts `tool-subagent` — is not in it. Asking the global view therefore answers\n * \"no such tool\" on *every* preset-hosted deployment, however correctly\n * `modelSelection` is configured.\n *\n * Reporting that as `model-selection-off` was actively misleading: the panel said\n * a working capability was switched off, and the registration path (which read\n * the same view) refused to register the tool. \"This scope does not show the\n * tool\" is not evidence that \"the capability is off\". So an unreadable scope is\n * reported as `unknown`, which is the honest answer and the one the panel shows\n * as \"not probed yet\" rather than as a fault.\n *\n * @module dsh-reflex/delegation-health\n */\n\n/** Why the delegate capability is (or is not) usable right now. */\nexport type DelegationHealthState =\n /** The Host delegation tool, read in a readable scope, declares `reasoning_effort`. */\n | 'ready'\n /** The scope that was read genuinely exposes no delegation tool. */\n | 'missing-tool'\n /** The scope that was read exposes a delegation tool without the level parameter. */\n | 'model-selection-off'\n /**\n * Nothing was observed, so nothing is claimed.\n *\n * No scope was available to read (the mount path has none), so neither\n * \"ready\" nor \"broken\" is known. This is a *reporting* state, never a reason\n * to withdraw anything.\n */\n | 'unknown';\n\n/** One reading of the live Host, plus the consequence for this activation. */\nexport interface DelegationHealth {\n /** What the live registry says, or `unknown` when no scope could be read. */\n state: DelegationHealthState;\n /** Registered name of the Host delegation tool, when one was observed. */\n toolName?: string;\n /** One-line reason, present whenever the state is not `ready`. */\n reason?: string;\n /**\n * Whether a *broken* capability was observed.\n *\n * `false` for `unknown`: nothing observed is nothing withdrawn. Registration is\n * decided by configuration, so this flag never gates the wrapper.\n */\n delegateAvailable: boolean;\n}\n\n/** The log line emitted when a previously working delegation stops working. */\nexport const DELEGATION_BROKEN_WARNING =\n 'dsh-reflex: the subagent tool no longer declares reasoning_effort (modelSelection is off again), so a delegated call carrying a reasoning level will be refused by the Host. ' +\n 'Nothing in your configuration was changed: re-tick \"Delegation\" in the Reflex settings after restarting DSH, and the level is passed again.';\n\n/** The reason shown on the panel when a read scope genuinely lacks the parameter. */\nexport const DELEGATION_MODEL_SELECTION_OFF_REASON =\n 'The host subagent tool does not declare reasoning_effort, so a decided level cannot reach the child. Tick Delegation again to write the host modelSelection switch (takes effect after a DSH restart).';\n\n/** The panel reason when the read scope genuinely has no delegation tool. */\nexport const DELEGATION_TOOL_MISSING_REASON =\n 'This host exposes no subagent tool in the scope that was read, so there is nothing for reflex_delegate to wrap.';\n\n/** The panel reason when no scope could be read, so no claim is made. */\nexport const DELEGATION_UNPROBED_REASON =\n 'The host capability was not probed: no agent scope was available to read, and a preset-hosted subagent tool is not visible from the global view. reflex_delegate is registered from configuration; whether a level can be carried is settled by the Host when a delegation is called.';\n\n/**\n * Read the live delegation capability of one Host context.\n *\n * Without `agent` this reads the global view, which cannot see a preset-hosted\n * tool; the reading is then only trusted when it finds the tool (a tool that *is*\n * visible globally is genuinely there). Finding nothing proves nothing, and is\n * reported as `unknown`.\n * @param ctx - a context whose `tools` registry is live.\n * @param agent - the scope to read as (the calling agent, or a preset); omitted\n * selects the global view.\n * @returns the state, its reason, and whether a *broken* capability was observed.\n */\nexport function readDelegationHealth(ctx: Context, agent?: Agent): DelegationHealth {\n const target = inspectDelegationTool(ctx, agent);\n if (target === undefined) {\n // A global view that shows no tool proves nothing: the tool may simply live\n // in a preset scope this view cannot see. Only a readable scope that lacks\n // it is evidence. \"Cannot see\" must never be reported as \"is off\".\n if (agent === undefined) {\n return { state: 'unknown', reason: DELEGATION_UNPROBED_REASON, delegateAvailable: false };\n }\n return {\n state: 'missing-tool',\n reason: DELEGATION_TOOL_MISSING_REASON,\n delegateAvailable: false\n };\n }\n if (!target.acceptsReasoningEffort) {\n return {\n state: 'model-selection-off',\n toolName: target.toolName,\n reason: DELEGATION_MODEL_SELECTION_OFF_REASON,\n delegateAvailable: false\n };\n }\n return { state: 'ready', toolName: target.toolName, delegateAvailable: true };\n}\n\n/** What one detection pass observed and did. */\nexport interface DelegationHealthWatch {\n /** The current reading. */\n readonly health: DelegationHealth;\n /**\n * Re-read the live registry, warning once on a ready → broken transition.\n * @returns the new reading.\n */\n check(): DelegationHealth;\n /**\n * Forget that a tool was ever usable.\n *\n * Called when the deployment itself turned the capability off (the user\n * unticked the switch): the next activation of the tool must not be reported\n * as \"it broke\".\n */\n forget(): void;\n}\n\n/** Options of {@link watchDelegationHealth}. */\nexport interface DelegationHealthWatchOptions {\n /** Live registry read. */\n readonly read: () => DelegationHealth;\n /** Warning sink; called at most once per ready → broken transition. */\n readonly warn?: (message: string) => void;\n /** Called after a reading that changed the answer the surface should show. */\n readonly onChange?: (health: DelegationHealth) => void;\n}\n\n/**\n * Build the watch a tool surface keeps beside its reconcile callback.\n *\n * The transition discipline is the whole behaviour: a Host that *never* exposed\n * the capability (a headless embedder, a deployment with `modelSelection` off\n * from the start) is not an error and must not warn — it is simply not offered.\n * Only a capability that was observably working and then stopped is reported.\n *\n * An `unknown` reading neither warns nor counts as an episode: it is the absence\n * of evidence, and \"we did not look\" must not read as \"it broke\".\n * @param options - the live read, a warning sink, and a change observer.\n * @returns the watch, with its current reading.\n */\nexport function watchDelegationHealth(options: DelegationHealthWatchOptions): DelegationHealthWatch {\n let current = options.read();\n /** Whether this watch has ever seen the wrapper usable. */\n let wasAvailable = current.delegateAvailable;\n /** Whether the withdrawal has already been reported for this episode. */\n let reported = false;\n\n const observe = (next: DelegationHealth): DelegationHealth => {\n const changed = next.state !== current.state;\n current = next;\n if (next.delegateAvailable) {\n wasAvailable = true;\n reported = false;\n } else if (wasAvailable && !reported && next.state === 'model-selection-off') {\n // One warning per episode: a registry that churns must not flood the log,\n // which is what makes the single line worth reading.\n reported = true;\n options.warn?.(DELEGATION_BROKEN_WARNING);\n }\n if (changed) options.onChange?.(next);\n return next;\n };\n\n return {\n get health(): DelegationHealth {\n return current;\n },\n check(): DelegationHealth {\n return observe(options.read());\n },\n forget(): void {\n wasAvailable = false;\n reported = false;\n }\n };\n}\n"]}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type { ChoiceRequest } from './vendor/harness-reflex/backend/types.js';
|
|
2
|
+
import type { DecisionLedger } from './vendor/harness-reflex/core/ledger.js';
|
|
3
|
+
/**
|
|
4
|
+
* One System One judgement spent on "how deep should this delegated task be
|
|
5
|
+
* thought through", before the task is handed to the DSH `subagent` tool.
|
|
6
|
+
*
|
|
7
|
+
* Only the reasoning level is decided here. The caller's `provider`/`model` are
|
|
8
|
+
* passed straight through to the Host tool and are *not* validated in this
|
|
9
|
+
* module: the Host's `assertAllowedModelSelection` owns that policy, and
|
|
10
|
+
* duplicating it would be the second decision layer the goal forbids.
|
|
11
|
+
*
|
|
12
|
+
* @module dsh-reflex/delegation
|
|
13
|
+
*/
|
|
14
|
+
/** The model-facing arguments of `reflex_delegate`, in declaration order. */
|
|
15
|
+
export interface ReflexDelegateArgs {
|
|
16
|
+
/** The task handed to the child agent. */
|
|
17
|
+
prompt: string;
|
|
18
|
+
/** Short display label for the delegated task. */
|
|
19
|
+
description: string;
|
|
20
|
+
/** Child LLM provider id; passed straight through to the DSH tool. */
|
|
21
|
+
provider?: string;
|
|
22
|
+
/** Exact model id within that provider; passed straight through. */
|
|
23
|
+
model?: string;
|
|
24
|
+
/** Initial child working directory; passed straight through. */
|
|
25
|
+
cwd?: string;
|
|
26
|
+
}
|
|
27
|
+
/** The `reasoning_effort` vocabulary the DSH `subagent` tool declares. */
|
|
28
|
+
export type DelegationEffort = 'low' | 'medium' | 'high';
|
|
29
|
+
/**
|
|
30
|
+
* The levels a delegation may carry.
|
|
31
|
+
*
|
|
32
|
+
* `off`, `minimal`, and `max` are intentionally absent: the DSH tool's own
|
|
33
|
+
* `reasoning_effort` accepts a `low`/`medium`/`high` vocabulary, and accepting a
|
|
34
|
+
* level the transport cannot express would force this layer to silently invent
|
|
35
|
+
* a replacement — the second decision layer the goal forbids.
|
|
36
|
+
*/
|
|
37
|
+
export declare const DELEGATION_EFFORT_LEVELS: readonly DelegationEffort[];
|
|
38
|
+
/**
|
|
39
|
+
* Levels offered to System One, narrowest first.
|
|
40
|
+
*
|
|
41
|
+
* Three candidates is what makes the confidence floor meaningful: with two, a
|
|
42
|
+
* uniform backend would answer `0.5`, which no simple "above one half" rule
|
|
43
|
+
* separates from a real lean. The vendor descriptions (see
|
|
44
|
+
* {@link EFFORT_CHOICE_OPTIONS}) are kept verbatim so the delegated decision
|
|
45
|
+
* speaks the same scenario vocabulary as the per-turn one.
|
|
46
|
+
*/
|
|
47
|
+
export declare const DELEGATION_CHOICE_OPTIONS: readonly string[];
|
|
48
|
+
/** How one delegation's level was reached, for the audit record. */
|
|
49
|
+
export type DelegationSource = 'system-one' | 'inherited';
|
|
50
|
+
/** Facts about the parent session that the fallback inherits from. */
|
|
51
|
+
export interface DelegationParentFacts {
|
|
52
|
+
/** Parent's negotiated reasoning effort, when it has one. */
|
|
53
|
+
readonly reasoningEffort?: string;
|
|
54
|
+
/** Parent's model id, when it has one. */
|
|
55
|
+
readonly model?: string;
|
|
56
|
+
}
|
|
57
|
+
/** The resolved delegation level plus everything needed to audit it. */
|
|
58
|
+
export interface DelegationDecision {
|
|
59
|
+
/** The `low`/`medium`/`high` value handed to the DSH tool. */
|
|
60
|
+
level: DelegationEffort;
|
|
61
|
+
/** Whether System One decided it, or the parent's own effort was inherited. */
|
|
62
|
+
source: DelegationSource;
|
|
63
|
+
/** Confidence of the winning option; `0` for an inherited level. */
|
|
64
|
+
confidence: number;
|
|
65
|
+
/** Wall-clock milliseconds spent deciding. */
|
|
66
|
+
latencyMs: number;
|
|
67
|
+
/** Verbatim evidence the decision rested on. */
|
|
68
|
+
basis: string[];
|
|
69
|
+
/** Set when System One was unavailable, untrusted, or disagreed with itself. */
|
|
70
|
+
degradedReason?: string;
|
|
71
|
+
}
|
|
72
|
+
/** Options of {@link decideDelegationEffort}. */
|
|
73
|
+
export interface DelegationDecisionOptions {
|
|
74
|
+
/** Model-facing task text; the judgement's question. */
|
|
75
|
+
readonly description: string;
|
|
76
|
+
/** Model-facing task body; appended to the question. */
|
|
77
|
+
readonly prompt: string;
|
|
78
|
+
/** System One choice execution. */
|
|
79
|
+
readonly decide: (request: ChoiceRequest) => Promise<{
|
|
80
|
+
bestOption?: unknown;
|
|
81
|
+
confidence?: unknown;
|
|
82
|
+
}>;
|
|
83
|
+
/** Minimum confidence for a System One answer to be trusted. */
|
|
84
|
+
readonly minConfidence: number;
|
|
85
|
+
/** Parent facts the fallback inherits from. */
|
|
86
|
+
readonly parent: DelegationParentFacts;
|
|
87
|
+
/** Monotonic clock, injectable for tests. */
|
|
88
|
+
readonly now?: () => number;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Build the System One question for one delegation.
|
|
92
|
+
*
|
|
93
|
+
* The description leads because it is the caller's own summary of the task, and
|
|
94
|
+
* the prompt body follows, truncated. Neither is rewritten: unlike a turn input,
|
|
95
|
+
* a delegated task is work to be done, not an instruction that might be quoted
|
|
96
|
+
* back, so the P9 restatement cleanup does not apply here.
|
|
97
|
+
* @param description - short task label.
|
|
98
|
+
* @param prompt - task body.
|
|
99
|
+
* @returns the question text.
|
|
100
|
+
*/
|
|
101
|
+
export declare function buildDelegationQuestion(description: string, prompt: string): string;
|
|
102
|
+
/**
|
|
103
|
+
* Map any effort id onto the delegation vocabulary by rank.
|
|
104
|
+
* @param effort - an effort id the parent may carry (`low`, `minimal`, `xhigh`, …).
|
|
105
|
+
* @returns the nearest delegation level, or `undefined` when it names none.
|
|
106
|
+
*/
|
|
107
|
+
export declare function toDelegationEffort(effort: string | undefined): DelegationEffort | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* Decide the reasoning level for one delegation.
|
|
110
|
+
*
|
|
111
|
+
* The chain is: System One → trust check → fallback. It never throws, because a
|
|
112
|
+
* delegation whose level could not be decided must still be delegatable.
|
|
113
|
+
*
|
|
114
|
+
* The trust check has two parts, and both are needed for the same reason: a
|
|
115
|
+
* confidence number alone is not evidence. An answer that merely ties the
|
|
116
|
+
* uniform baseline (`1 / candidates`) carries no information at all — the
|
|
117
|
+
* winner is then whichever option came first — and an answer below the
|
|
118
|
+
* deployment's floor is too weak to act on. Either way the parent's own level
|
|
119
|
+
* is inherited instead of invented, so a weak signal can never silently change
|
|
120
|
+
* how deeply a child thinks.
|
|
121
|
+
* @param options - task text, System One seam, floor, and parent facts.
|
|
122
|
+
* @returns the decision, with the reason recorded when it degraded.
|
|
123
|
+
*/
|
|
124
|
+
export declare function decideDelegationEffort(options: DelegationDecisionOptions): Promise<DelegationDecision>;
|
|
125
|
+
/**
|
|
126
|
+
* The level a delegation inherits when System One cannot be trusted.
|
|
127
|
+
*
|
|
128
|
+
* The parent's own effort is honoured rather than reset: a parent already
|
|
129
|
+
* thinking at `high` does not hand a `medium` child the work it was made for.
|
|
130
|
+
* A parent with no reasoning at all (or one at `off`) falls to `medium`, the
|
|
131
|
+
* vendor default for "no evidence either way".
|
|
132
|
+
* @param parent - parent facts.
|
|
133
|
+
* @returns the inherited level.
|
|
134
|
+
*/
|
|
135
|
+
export declare function inheritParentEffort(parent: DelegationParentFacts): DelegationEffort;
|
|
136
|
+
/**
|
|
137
|
+
* Record one delegation level in the audit ledger.
|
|
138
|
+
*
|
|
139
|
+
* It lands in the same ledger as the per-turn decisions, tagged `kind:
|
|
140
|
+
* 'delegation'` and attributed to the `reflex-delegate` backend, so
|
|
141
|
+
* `/reflex-ledger` and the ledger summary separate the two without a second
|
|
142
|
+
* sink to configure.
|
|
143
|
+
* @param ledger - the activation's ledger.
|
|
144
|
+
* @param decision - the decided level.
|
|
145
|
+
* @param args - the model-facing arguments, for attribution.
|
|
146
|
+
* @param parent - parent facts, for attribution.
|
|
147
|
+
*/
|
|
148
|
+
export declare function recordDelegationDecision(ledger: DecisionLedger, decision: DelegationDecision, args: ReflexDelegateArgs, parent: DelegationParentFacts): void;
|