@linxin666/dsh-liangshen 0.4.8 → 0.4.10
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.i18n.yaml +2 -2
- package/README.md +10 -8
- package/README.zh.md +10 -8
- package/lib/client.js +87 -54
- package/lib/client.js.map +1 -1
- package/lib/index.js +9 -1
- package/lib/types/client/PluginSettingsCard.d.ts +21 -0
- package/package.json +15 -15
- package/presets/liangshen/agent.cordis.yml +76 -18
- package/presets/liangshen/dispatcher-rules.mjs +128 -47
- package/presets/liangshen/fact-ledger.mjs +14 -0
- package/presets/liangshen/subagent-routes.mjs +396 -0
- package/presets/liangshen/tool-catalog.mjs +7 -4
- package/src/client/PluginSettingsCard.tsx +78 -18
- package/src/client/settings-card.module.css +71 -10
- package/src/composition.test.ts +20 -0
- package/src/composition.ts +10 -2
- package/tools/benchmark-live-run.mjs +116 -14
- package/tools/benchmark-report.mjs +44 -0
- package/tools/check-dispatcher-rules.mjs +130 -0
- package/tools/probe-selftest.mjs +130 -0
- package/tools/probes/budget-ledger/env.mjs +103 -0
- package/tools/probes/budget-ledger/grade.mjs +31 -0
- package/tools/probes/budget-ledger/strategies.mjs +25 -0
- package/tools/probes/oncall-backlog/env.mjs +141 -0
- package/tools/probes/oncall-backlog/grade.mjs +28 -0
- package/tools/probes/oncall-backlog/strategies.mjs +37 -0
- package/tools/probes/prior-override/env.mjs +153 -0
- package/tools/probes/prior-override/grade.mjs +31 -0
- package/tools/probes/prior-override/strategies.mjs +30 -0
- package/tools/probes/refresh-quota/env.mjs +140 -0
- package/tools/probes/refresh-quota/grade.mjs +30 -0
- package/tools/probes/refresh-quota/strategies.mjs +29 -0
- package/tools/probes/shared.mjs +75 -0
- package/tools/tasks/liangshen-v41-probes.json +59 -0
|
@@ -23,6 +23,19 @@
|
|
|
23
23
|
* The tool is deliberately small: it validates and reports, it does not edit
|
|
24
24
|
* the context itself. The projection the model sees next step is the fold of
|
|
25
25
|
* the log the runtime appended for this call.
|
|
26
|
+
*
|
|
27
|
+
* AN ANCHOR, NOT A SOURCE OF TRUTH (2026-10-18): a pinned fact is a reading
|
|
28
|
+
* taken when it was registered, and the projection re-publishes it verbatim
|
|
29
|
+
* afterwards, so a fact whose subject changed is stale the moment it is read
|
|
30
|
+
* again while looking exactly as fresh as it did the first time. That is the
|
|
31
|
+
* one failure this register can introduce on its own, and it is the expensive
|
|
32
|
+
* kind: nothing downstream questions a fact the model supplied. The register
|
|
33
|
+
* therefore stays a pointer with an expiry the model manages -- the tool
|
|
34
|
+
* description tells it to re-read the subject before planning on a fact whose
|
|
35
|
+
* subject moved, and to revoke the entry once the subject is settled -- rather
|
|
36
|
+
* than pretending the projection can detect the change itself. Detecting it
|
|
37
|
+
* would need a reverse index from every fact to every file it names, which is
|
|
38
|
+
* exactly the guessing this preset exists to avoid.
|
|
26
39
|
*/
|
|
27
40
|
|
|
28
41
|
/** Cordis plugin name used by loader diagnostics. */
|
|
@@ -90,6 +103,7 @@ export function apply(ctx) {
|
|
|
90
103
|
'Pin one key fact into this session working context — the line the runtime projects next to the newest message every step. Use it for the facts a long session must not lose: a hard user constraint, a confirmed architecture decision, a path that already failed.',
|
|
91
104
|
`A fact is one short line (<= ${MAX_FACT_CHARS} chars); at most ${MAX_FACTS} stay pinned, the oldest dropping off. Pass the same text again to no-op; pass the revoke field with a fact tag (or its exact text) to unpin everything under it.`,
|
|
92
105
|
'Pin sparingly: the register rides the guaranteed-attention window, and flooding it dilutes every other fact.',
|
|
106
|
+
'A pinned fact is an anchor, not current state: it is republished verbatim, so a fact whose subject later changed reads exactly as fresh as it did when pinned. Before planning on a fact, re-read its subject if that subject moved; once the subject is settled, revoke the entry instead of leaving a stale line pinned.',
|
|
93
107
|
].join('\n'),
|
|
94
108
|
parameters: {
|
|
95
109
|
type: 'object',
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* subagent-routes — the LiangShen preset's authorization guard for delegated
|
|
3
|
+
* child routes.
|
|
4
|
+
*
|
|
5
|
+
* The harness records a Session's authorized child routes as a durable
|
|
6
|
+
* `subagent/model-selection-policy` event, but its own delegation tool only
|
|
7
|
+
* rejects an EXPLICIT route outside that list: a call that names no
|
|
8
|
+
* `provider`/`model` falls back to the configured child defaults or to the
|
|
9
|
+
* parent's own route. A session whose allowlist authorizes only one family
|
|
10
|
+
* would therefore still spawn children on the parent's route simply because
|
|
11
|
+
* nobody named one — or, for `subagent_fork`, because the tool cannot name one
|
|
12
|
+
* at all.
|
|
13
|
+
*
|
|
14
|
+
* This row closes that gap from the preset plane. Whenever the calling Session
|
|
15
|
+
* (or the nearest ancestor that recorded one) carries an allowlist, every
|
|
16
|
+
* delegation the row polices must resolve to an authorized route:
|
|
17
|
+
*
|
|
18
|
+
* - `explicit` tools publish `provider`/`model`; the call must name a complete
|
|
19
|
+
* pair, and that pair must be on the list;
|
|
20
|
+
* - `inherit` tools publish neither and start the child on the caller's own
|
|
21
|
+
* route; the guard forbids a route override there and checks the inherited
|
|
22
|
+
* route against the same list, because "the tool cannot choose" is not the
|
|
23
|
+
* same as "the choice is authorized".
|
|
24
|
+
*
|
|
25
|
+
* The mode a tool is policed in is configuration, but its PARAMETERS are a
|
|
26
|
+
* runtime fact: a composition written for an older cohort mounts the tool with
|
|
27
|
+
* neither route field, and demanding a pair from it would be a denial no call
|
|
28
|
+
* could satisfy. The guard therefore asks the registry which fields the tool
|
|
29
|
+
* actually declares, and enforces such a tool through the route its child
|
|
30
|
+
* would inherit.
|
|
31
|
+
*
|
|
32
|
+
* The guard is deliberately fail-open on every fact it cannot read (no policy
|
|
33
|
+
* event, no session registry, no registry probe): a delegation the harness can
|
|
34
|
+
* resolve is never blocked by a missing observation, and the row only ever
|
|
35
|
+
* adds a denial it can justify from the durable log.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/** Cordis plugin name used by loader diagnostics. */
|
|
39
|
+
export const name = 'liangshen-subagent-routes'
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Services this row reads.
|
|
43
|
+
*
|
|
44
|
+
* A preset row runs in its own fiber, where a service it does not declare is
|
|
45
|
+
* not readable at all: `ctx.tools` against an undeclared `tools` throws
|
|
46
|
+
* "cannot get property \"tools\" without inject" and fails the preset's load
|
|
47
|
+
* audit. The guard reads the registry for its `guard` seam and its `definitions`
|
|
48
|
+
* probe, so declaring it is what lets the row mount and stay mounted.
|
|
49
|
+
*/
|
|
50
|
+
export const inject = ['tools']
|
|
51
|
+
|
|
52
|
+
/** Durable event carrying a Session's authorized child routes. */
|
|
53
|
+
export const POLICY_EVENT = 'subagent/model-selection-policy'
|
|
54
|
+
|
|
55
|
+
/** Delegation tools whose calls must name an authorized route pair. */
|
|
56
|
+
export const DEFAULT_EXPLICIT_TOOLS = ['subagent']
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Delegation tools that start their child on the caller's own route.
|
|
60
|
+
* `subagent_fork` is the shipped one; `spawn_teammate` belongs here for the
|
|
61
|
+
* same reason at one remove — it creates its child with no `agentOptions`, so
|
|
62
|
+
* policing it as an explicit tool would deny every creation.
|
|
63
|
+
*/
|
|
64
|
+
export const DEFAULT_INHERIT_TOOLS = ['subagent_fork', 'spawn_teammate']
|
|
65
|
+
|
|
66
|
+
/** How far the policy lookup follows the Session chain before giving up. */
|
|
67
|
+
export const MAX_ANCESTOR_DEPTH = 8
|
|
68
|
+
|
|
69
|
+
/** How many early events one Session is scanned for its policy event. */
|
|
70
|
+
export const MAX_POLICY_SCAN = 256
|
|
71
|
+
|
|
72
|
+
/** Read one value as a non-empty string. */
|
|
73
|
+
function asString(value) {
|
|
74
|
+
return typeof value === 'string' && value.length > 0 ? value : undefined
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Read one value as a plain record. */
|
|
78
|
+
function asRecord(value) {
|
|
79
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : undefined
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Parse the `allowedModels` payload of one policy event.
|
|
84
|
+
* @param data - Raw event payload.
|
|
85
|
+
* @returns the authorized routes, or undefined when the payload is malformed.
|
|
86
|
+
*/
|
|
87
|
+
export function parseAllowedRoutes(data) {
|
|
88
|
+
const record = asRecord(data)
|
|
89
|
+
if (record === undefined) return undefined
|
|
90
|
+
const entries = record['allowedModels']
|
|
91
|
+
if (!Array.isArray(entries)) return undefined
|
|
92
|
+
const routes = []
|
|
93
|
+
for (const entry of entries) {
|
|
94
|
+
const route = asRecord(entry)
|
|
95
|
+
const provider = asString(route?.['provider'])
|
|
96
|
+
const model = asString(route?.['model'])
|
|
97
|
+
if (provider === undefined || model === undefined) return undefined
|
|
98
|
+
routes.push({ provider, model })
|
|
99
|
+
}
|
|
100
|
+
return routes
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The events of one session, tolerating both snapshot shapes. */
|
|
104
|
+
function sessionEvents(session) {
|
|
105
|
+
if (Array.isArray(session?.events)) return session.events
|
|
106
|
+
if (typeof session?.snapshotEvents === 'function') {
|
|
107
|
+
try {
|
|
108
|
+
const snapshot = session.snapshotEvents()
|
|
109
|
+
if (Array.isArray(snapshot)) return snapshot
|
|
110
|
+
} catch {
|
|
111
|
+
return undefined
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return undefined
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The authorized routes a session recorded, if any.
|
|
119
|
+
*
|
|
120
|
+
* The policy is appended before the Session's first model request, so the scan
|
|
121
|
+
* stays short; the bound keeps a Session without one from walking its whole
|
|
122
|
+
* log. Both the durable `eventAt(seq)` reader and a plain events array are
|
|
123
|
+
* accepted, because the row may run against a Host that exposes only one.
|
|
124
|
+
* @param session - Session-like record.
|
|
125
|
+
* @returns the recorded routes, or undefined when this Session recorded none.
|
|
126
|
+
*/
|
|
127
|
+
export function policyRoutesOf(session) {
|
|
128
|
+
if (session === undefined || session === null) return undefined
|
|
129
|
+
if (typeof session.eventAt === 'function') {
|
|
130
|
+
for (let seq = 0; seq < MAX_POLICY_SCAN; seq += 1) {
|
|
131
|
+
let event
|
|
132
|
+
try {
|
|
133
|
+
event = session.eventAt(seq)
|
|
134
|
+
} catch {
|
|
135
|
+
return undefined
|
|
136
|
+
}
|
|
137
|
+
if (event === undefined) return undefined
|
|
138
|
+
if (event?.type !== POLICY_EVENT) continue
|
|
139
|
+
const routes = parseAllowedRoutes(event.data)
|
|
140
|
+
if (routes !== undefined) return routes
|
|
141
|
+
}
|
|
142
|
+
return undefined
|
|
143
|
+
}
|
|
144
|
+
const events = sessionEvents(session)
|
|
145
|
+
if (events === undefined) return undefined
|
|
146
|
+
for (const event of events.slice(0, MAX_POLICY_SCAN)) {
|
|
147
|
+
if (event?.type !== POLICY_EVENT) continue
|
|
148
|
+
const routes = parseAllowedRoutes(event.data)
|
|
149
|
+
if (routes !== undefined) return routes
|
|
150
|
+
}
|
|
151
|
+
return undefined
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Resolve the allowlist a delegation from this agent must respect: the agent's
|
|
156
|
+
* own recorded policy, else the nearest ancestor Session that recorded one.
|
|
157
|
+
*
|
|
158
|
+
* The walk only crosses parent links that the delegation seam itself created
|
|
159
|
+
* (`origin: subagent`), so an unrelated parent Session cannot impose a list on
|
|
160
|
+
* a delegation it does not own.
|
|
161
|
+
* @param agent - Calling agent.
|
|
162
|
+
* @param sessions - Session registry, when the Host exposes one.
|
|
163
|
+
* @returns the authorized routes, or undefined when no Session recorded any.
|
|
164
|
+
*/
|
|
165
|
+
export function authorizedRoutesFor(agent, sessions) {
|
|
166
|
+
let session = agent?.session
|
|
167
|
+
for (let depth = 0; depth < MAX_ANCESTOR_DEPTH && session !== undefined; depth += 1) {
|
|
168
|
+
const recorded = policyRoutesOf(session)
|
|
169
|
+
if (recorded !== undefined) return recorded
|
|
170
|
+
const header = asRecord(session?.header)
|
|
171
|
+
if (header?.['origin'] !== 'subagent') return undefined
|
|
172
|
+
const parentId = asString(header['parentSession'])
|
|
173
|
+
if (parentId === undefined || typeof sessions?.get !== 'function') return undefined
|
|
174
|
+
try {
|
|
175
|
+
session = sessions.get(parentId)
|
|
176
|
+
} catch {
|
|
177
|
+
return undefined
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return undefined
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* The route an inherit-mode child would run on: the caller's own effective
|
|
185
|
+
* request route. The latest request header owns it after a mid-session model
|
|
186
|
+
* switch, with the creation options as the fallback before the first request.
|
|
187
|
+
* @param agent - Calling agent.
|
|
188
|
+
* @returns the inherited route fields, each absent when its source omitted it.
|
|
189
|
+
*/
|
|
190
|
+
export function inheritedRouteOf(agent) {
|
|
191
|
+
let header
|
|
192
|
+
try {
|
|
193
|
+
header = typeof agent?.session?.requestHeader === 'function' ? agent.session.requestHeader() : undefined
|
|
194
|
+
} catch {
|
|
195
|
+
header = undefined
|
|
196
|
+
}
|
|
197
|
+
const config = asRecord(header?.config)
|
|
198
|
+
const provider = asString(config?.['provider'])
|
|
199
|
+
const model = asString(config?.['model'])
|
|
200
|
+
if (provider !== undefined || model !== undefined) {
|
|
201
|
+
return { provider, model, reasoningEffort: asString(config?.['reasoningEffort']) }
|
|
202
|
+
}
|
|
203
|
+
return { provider: asString(agent?.options?.provider), model: asString(agent?.options?.model) }
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Whether one route is on an allowlist. */
|
|
207
|
+
export function routesInclude(routes, provider, model) {
|
|
208
|
+
return (Array.isArray(routes) ? routes : [])
|
|
209
|
+
.some(route => route.provider === provider && route.model === model)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Render an allowlist for a denial reason. */
|
|
213
|
+
export function authorizedRoutesText(routes) {
|
|
214
|
+
const list = Array.isArray(routes) ? routes : []
|
|
215
|
+
if (list.length === 0) return 'no route is authorized (the Session allowlist is empty)'
|
|
216
|
+
return list.map(route => `"${route.provider}/${route.model}"`).join(', ')
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** The route pair one delegation call named, each half possibly absent. */
|
|
220
|
+
export function namedRouteOf(args) {
|
|
221
|
+
const record = asRecord(args) ?? {}
|
|
222
|
+
return { provider: asString(record['provider']), model: asString(record['model']) }
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** How one delegation tool resolves the child route this guard authorizes. */
|
|
226
|
+
export function delegationModeOf(toolName, explicitToolNames, inheritToolNames) {
|
|
227
|
+
if ((Array.isArray(inheritToolNames) ? inheritToolNames : []).includes(toolName)) return 'inherit'
|
|
228
|
+
if ((Array.isArray(explicitToolNames) ? explicitToolNames : DEFAULT_EXPLICIT_TOOLS).includes(toolName)) return 'explicit'
|
|
229
|
+
return undefined
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Ask the tool registry whether one delegation tool currently declares the
|
|
234
|
+
* route fields. The answer is read per call: an HMR replacement or a preset
|
|
235
|
+
* change can remount the tool, and a stale answer would put the guard back on
|
|
236
|
+
* the branch no call can satisfy.
|
|
237
|
+
* @param tools - Tool registry from the Host context.
|
|
238
|
+
* @param agent - Calling agent, whose scope selects the visible definitions.
|
|
239
|
+
* @param toolName - Tool being dispatched.
|
|
240
|
+
* @returns whether the tool declares a route field, or undefined when the
|
|
241
|
+
* registry cannot answer (which keeps the configured mode in charge).
|
|
242
|
+
*/
|
|
243
|
+
export function routeParameterProbe(tools, agent, toolName) {
|
|
244
|
+
if (typeof tools?.definitions !== 'function') return undefined
|
|
245
|
+
let definitions
|
|
246
|
+
try {
|
|
247
|
+
definitions = tools.definitions(agent)
|
|
248
|
+
} catch {
|
|
249
|
+
return undefined
|
|
250
|
+
}
|
|
251
|
+
const definition = (Array.isArray(definitions) ? definitions : []).find(entry => entry?.name === toolName)
|
|
252
|
+
const parameters = asRecord(definition?.parameters)
|
|
253
|
+
if (parameters === undefined) return undefined
|
|
254
|
+
return parameters['provider'] !== undefined || parameters['model'] !== undefined
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** Denial reason for a delegation that named a route on an inherit-only tool. */
|
|
258
|
+
export function overrideReason(toolName, provider, model, allowed) {
|
|
259
|
+
return `subagent model selection: "${toolName}" keeps its child on the calling agent's route and has no provider/model fields, `
|
|
260
|
+
+ `so the route "${provider}/${model}" cannot be selected through it. Use a delegation tool that exposes `
|
|
261
|
+
+ `provider and model and pass one of ${authorizedRoutesText(allowed)}.`
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Denial reason for a delegation whose inherited route is unauthorized. */
|
|
265
|
+
export function inheritedReason(toolName, inherited, allowed) {
|
|
266
|
+
const route = inherited.provider === undefined || inherited.model === undefined
|
|
267
|
+
? 'the calling agent\'s route'
|
|
268
|
+
: `"${inherited.provider}/${inherited.model}"`
|
|
269
|
+
return `subagent model selection: "${toolName}" keeps its child on ${route}, which this Session's allowlist `
|
|
270
|
+
+ `does not authorize, so it is unavailable for now. Its child cannot be re-routed, so either delegate through a `
|
|
271
|
+
+ `tool that exposes provider and model — passing one of ${authorizedRoutesText(allowed)} — or continue on an `
|
|
272
|
+
+ `authorized model for this Session, after which "${toolName}" works again.`
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* The denial for a delegation that would inherit the caller's route, or
|
|
277
|
+
* undefined when that route is authorized (or cannot be read at all — a route
|
|
278
|
+
* the guard cannot resolve is left to the harness rather than guessed).
|
|
279
|
+
* @param agent - Calling agent whose route the child inherits.
|
|
280
|
+
* @param toolName - Tool being dispatched.
|
|
281
|
+
* @param allowed - Routes the calling Session authorizes.
|
|
282
|
+
* @returns a denial reason, or undefined when the inherited route is allowed.
|
|
283
|
+
*/
|
|
284
|
+
export function inheritedRouteDenial(agent, toolName, allowed) {
|
|
285
|
+
const inherited = inheritedRouteOf(agent)
|
|
286
|
+
if (inherited.provider !== undefined && inherited.model !== undefined
|
|
287
|
+
&& routesInclude(allowed, inherited.provider, inherited.model)) return undefined
|
|
288
|
+
return inheritedReason(toolName, inherited, allowed)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Denial reason for an explicit tool whose call named no complete pair. */
|
|
292
|
+
export function missingPairReason(toolName, named, inherited, allowed) {
|
|
293
|
+
const half = named.provider === undefined && named.model === undefined
|
|
294
|
+
? 'names no provider or model'
|
|
295
|
+
: `names only ${named.provider === undefined ? 'model' : 'provider'}`
|
|
296
|
+
return `subagent model selection: the call to "${toolName}" ${half}, so the child would run on `
|
|
297
|
+
+ `${inherited.provider === undefined || inherited.model === undefined ? 'the parent route' : `"${inherited.provider}/${inherited.model}"`}, `
|
|
298
|
+
+ `which this Session's allowlist does not authorize. Pass an authorized provider and model — ${authorizedRoutesText(allowed)} — `
|
|
299
|
+
+ `with an optional reasoning_effort.`
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** Denial reason for a call that named a route outside the allowlist. */
|
|
303
|
+
export function unauthorizedReason(toolName, provider, model, allowed) {
|
|
304
|
+
return `subagent model selection: the model this call to "${toolName}" selected ("${provider}/${model}") is not on the `
|
|
305
|
+
+ `Session allowlist. Pass an authorized provider and model — ${authorizedRoutesText(allowed)} — with an optional reasoning_effort.`
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Decide whether one delegation call must be refused.
|
|
310
|
+
*
|
|
311
|
+
* Every unreadable fact resolves to "no opinion": an absent policy event, an
|
|
312
|
+
* absent session registry, or a registry that cannot name the tool's fields all
|
|
313
|
+
* leave the call to the harness.
|
|
314
|
+
* @param input - Calling agent, tool name, arguments, and policy sources.
|
|
315
|
+
* @returns a denial reason, or undefined to leave the call untouched.
|
|
316
|
+
*/
|
|
317
|
+
export function delegationDenialReason(input) {
|
|
318
|
+
const {
|
|
319
|
+
agent, toolName, args, sessions,
|
|
320
|
+
explicitToolNames = DEFAULT_EXPLICIT_TOOLS,
|
|
321
|
+
inheritToolNames = DEFAULT_INHERIT_TOOLS,
|
|
322
|
+
probe,
|
|
323
|
+
} = input ?? {}
|
|
324
|
+
const mode = delegationModeOf(toolName, explicitToolNames, inheritToolNames)
|
|
325
|
+
if (mode === undefined) return undefined
|
|
326
|
+
const allowed = authorizedRoutesFor(agent, sessions)
|
|
327
|
+
if (allowed === undefined) return undefined
|
|
328
|
+
const named = namedRouteOf(args)
|
|
329
|
+
const complete = named.provider !== undefined && named.model !== undefined
|
|
330
|
+
if (mode === 'inherit') {
|
|
331
|
+
// A named pair can only be an attempt to re-route the child away from the
|
|
332
|
+
// route the tool exists to preserve: the more precise diagnostic comes first.
|
|
333
|
+
if (complete) return overrideReason(toolName, named.provider, named.model, allowed)
|
|
334
|
+
return inheritedRouteDenial(agent, toolName, allowed)
|
|
335
|
+
}
|
|
336
|
+
// A tool mounted without route fields cannot be handed the pair a policy
|
|
337
|
+
// expects, so it is policed through the route its child would inherit.
|
|
338
|
+
//
|
|
339
|
+
// A COMPLETE pair is never reclassified here. The probe resolves the registry
|
|
340
|
+
// view from the call, which can be a scope that does not carry this preset's
|
|
341
|
+
// delegation registration, so it can answer "no route fields" for a tool the
|
|
342
|
+
// model was in fact shown WITH them. Denying the pair there produced a denial
|
|
343
|
+
// no call could satisfy and made every routed dispatch impossible. The pair
|
|
344
|
+
// still faces the allowlist check below, so this branch can only soften an
|
|
345
|
+
// impossible denial — never an authorization.
|
|
346
|
+
const declares = probe?.(agent, toolName)
|
|
347
|
+
if (declares === false) {
|
|
348
|
+
// A bare or half-named call keeps the old behaviour: police the route the
|
|
349
|
+
// child would inherit. Only the COMPLETE pair falls through.
|
|
350
|
+
if (!complete) return inheritedRouteDenial(agent, toolName, allowed)
|
|
351
|
+
}
|
|
352
|
+
if (!complete) return missingPairReason(toolName, named, inheritedRouteOf(agent), allowed)
|
|
353
|
+
if (!routesInclude(allowed, named.provider, named.model)) {
|
|
354
|
+
return unauthorizedReason(toolName, named.provider, named.model, allowed)
|
|
355
|
+
}
|
|
356
|
+
return undefined
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Install the guard for the calling scope.
|
|
361
|
+
* @param ctx - Host context carrying the tool registry (and optionally sessions).
|
|
362
|
+
* @param config - Row configuration.
|
|
363
|
+
* @returns a disposer that removes the guard, or undefined when the scope has
|
|
364
|
+
* no tool registry to guard.
|
|
365
|
+
*/
|
|
366
|
+
export function installSubagentRoutes(ctx, config = {}) {
|
|
367
|
+
const tools = ctx?.tools
|
|
368
|
+
if (typeof tools?.guard !== 'function') return undefined
|
|
369
|
+
const explicitToolNames = Array.isArray(config.explicitTools) ? config.explicitTools : DEFAULT_EXPLICIT_TOOLS
|
|
370
|
+
const inheritToolNames = Array.isArray(config.inheritTools) ? config.inheritTools : DEFAULT_INHERIT_TOOLS
|
|
371
|
+
const sessions = typeof ctx?.get === 'function' ? ctx.get('sessions') : undefined
|
|
372
|
+
return tools.guard(execution => delegationDenialReason({
|
|
373
|
+
agent: execution?.agent,
|
|
374
|
+
toolName: execution?.name,
|
|
375
|
+
args: execution?.arguments,
|
|
376
|
+
sessions,
|
|
377
|
+
explicitToolNames,
|
|
378
|
+
inheritToolNames,
|
|
379
|
+
probe: (agent, toolName) => routeParameterProbe(tools, agent, toolName),
|
|
380
|
+
}))
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Mount the row: register the guard for this scope, with an off switch.
|
|
385
|
+
* @param ctx - Cordis context of the composing scope.
|
|
386
|
+
* @param config - Row configuration; omitted fields select the shipped names.
|
|
387
|
+
*/
|
|
388
|
+
export function apply(ctx, config = {}) {
|
|
389
|
+
if (config.enabled === false) return
|
|
390
|
+
ctx.effect(() => {
|
|
391
|
+
const dispose = installSubagentRoutes(ctx, config)
|
|
392
|
+
// A Host without the guard seam keeps the harness's own delegation behavior
|
|
393
|
+
// instead of failing the preset's load.
|
|
394
|
+
return dispose ?? (() => undefined)
|
|
395
|
+
}, 'liangshen: subagent route guard')
|
|
396
|
+
}
|
|
@@ -793,6 +793,10 @@ export function apply(ctx, config) {
|
|
|
793
793
|
|
|
794
794
|
const tools = agent?.ctx?.tools
|
|
795
795
|
if (tools === undefined || typeof tools.presentAs !== 'function') {
|
|
796
|
+
// No composition row replaces this declaration: `presentAs` is how a
|
|
797
|
+
// preset selects its wire, so a scope that cannot reach it runs the
|
|
798
|
+
// native surface no matter what `presentation` says. Report it once
|
|
799
|
+
// instead of leaving the operator's setting silently unapplied.
|
|
796
800
|
agentDeclareFailed.add(agent)
|
|
797
801
|
warnOnce('runtime', 'no scoped tools view to declare the presentation through — keeping the native tool surface')
|
|
798
802
|
return false
|
|
@@ -958,9 +962,9 @@ export function apply(ctx, config) {
|
|
|
958
962
|
if (agent !== undefined && !agentDeclared.has(agent) && transportReady()) {
|
|
959
963
|
// Under 'ptc' a declaration collapses the wire to the single `run_code`
|
|
960
964
|
// transport and lists the tools from their SDK projection. Where no
|
|
961
|
-
// projection can be read at all, declaring would collapse the
|
|
962
|
-
// then have to undo it, losing the native
|
|
963
|
-
// instead.
|
|
965
|
+
// projection can be read at all, declaring would collapse the wire and
|
|
966
|
+
// then have to undo it, losing the native surface on the way out. Stay
|
|
967
|
+
// native instead.
|
|
964
968
|
const projectable = publicSchemas(agent)
|
|
965
969
|
if (presentation === 'ptc' && (projectable === undefined || projectable.length === 0)) {
|
|
966
970
|
warnOnce('runtime', 'no tool schema projection available — keeping the native tool surface')
|
|
@@ -1001,7 +1005,6 @@ export function apply(ctx, config) {
|
|
|
1001
1005
|
const assembled = await next()
|
|
1002
1006
|
|
|
1003
1007
|
const assembledTools = Array.isArray(assembled?.tools) ? assembled.tools : undefined
|
|
1004
|
-
const wireHasRunCode = (assembledTools ?? []).some(t => t?.name === 'run_code')
|
|
1005
1008
|
const wireOnlyRunCode = assembledTools !== undefined && assembledTools.length > 0 && assembledTools.every(t => t?.name === 'run_code')
|
|
1006
1009
|
|
|
1007
1010
|
// The paging restriction was installed OUTSIDE this waterfall (see
|
|
@@ -41,6 +41,14 @@ export interface PluginSettingsCardProps<TKey extends string = string> {
|
|
|
41
41
|
descriptionKey: TKey
|
|
42
42
|
/** Optional rich header description rendered instead of the plain t(descriptionKey) text (the plain text stays as the tooltip). */
|
|
43
43
|
descriptionNode?: ReactNode
|
|
44
|
+
/**
|
|
45
|
+
* Locale key of the full sentence behind a shortened description: when
|
|
46
|
+
* present, the header's native `title` takes this text while the visible
|
|
47
|
+
* line keeps `descriptionKey`/`descriptionNode`, so a compact card can
|
|
48
|
+
* compress the sentence without keeping a second visible copy of it.
|
|
49
|
+
* Defaults to the description key.
|
|
50
|
+
*/
|
|
51
|
+
descriptionTitleKey?: TKey
|
|
44
52
|
/**
|
|
45
53
|
* Optional leading mark identifying the plugin. A card without one keeps the
|
|
46
54
|
* plain official header shape, so the chrome stays a readable sibling of the
|
|
@@ -95,10 +103,27 @@ export interface PluginSettingsCardProps<TKey extends string = string> {
|
|
|
95
103
|
renderChildrenWhenNotExposed?: boolean
|
|
96
104
|
/** Hide the 'not exposed' warning banner when the settings namespace is not exposed. */
|
|
97
105
|
hideNotExposedNotice?: boolean
|
|
106
|
+
/**
|
|
107
|
+
* Compact chrome for a topic card rendered inside another card's body: a
|
|
108
|
+
* smaller title, a tighter header and body inset, and a one-line description
|
|
109
|
+
* whose full text stays on the header's own title. Defaults to the
|
|
110
|
+
* first-level chrome, which is unchanged.
|
|
111
|
+
*/
|
|
112
|
+
density?: 'nested'
|
|
98
113
|
/** The plugin's controls. */
|
|
99
114
|
children: ReactNode
|
|
100
115
|
}
|
|
101
116
|
|
|
117
|
+
/** Length of the body's disclosure motion; it matches `--settings-card-motion` on the card root. */
|
|
118
|
+
const BODY_MOTION_MS = 180
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Lifecycle of one card body. `collapsed` is the mounted-but-closed frame the
|
|
122
|
+
* enter leg starts from, `entering` and `closing` are the two moving legs, and
|
|
123
|
+
* `shown` is the settled open body, which releases its clipping box.
|
|
124
|
+
*/
|
|
125
|
+
type BodyPhase = 'hidden' | 'collapsed' | 'entering' | 'shown' | 'closing'
|
|
126
|
+
|
|
102
127
|
/**
|
|
103
128
|
* Render one plugin settings card.
|
|
104
129
|
* @param props - the plugin's copy keys, its form state, and its controls.
|
|
@@ -107,12 +132,47 @@ export interface PluginSettingsCardProps<TKey extends string = string> {
|
|
|
107
132
|
export function PluginSettingsCard<TKey extends string = string>(props: PluginSettingsCardProps<TKey>) {
|
|
108
133
|
const [open, setOpen] = useState(props.defaultOpen ?? true)
|
|
109
134
|
const { state, alwaysOpen } = props
|
|
135
|
+
const expanded = alwaysOpen === true || open
|
|
136
|
+
const [bodyPhase, setBodyPhase] = useState<BodyPhase>(expanded ? 'shown' : 'hidden')
|
|
137
|
+
const bodyRef = useRef<HTMLDivElement | null>(null)
|
|
138
|
+
// Enter and leave run the same pair: a body that should open is mounted
|
|
139
|
+
// closed for one frame so its transition has a state to leave, and a closing
|
|
140
|
+
// one stays mounted until its leg has run.
|
|
141
|
+
useLayoutEffect(() => {
|
|
142
|
+
if (expanded) {
|
|
143
|
+
if (bodyPhase === 'hidden') setBodyPhase('collapsed')
|
|
144
|
+
else if (bodyPhase === 'collapsed') {
|
|
145
|
+
const node = bodyRef.current
|
|
146
|
+
if (node !== null) void node.offsetHeight
|
|
147
|
+
setBodyPhase('entering')
|
|
148
|
+
} else if (bodyPhase === 'closing') setBodyPhase('entering')
|
|
149
|
+
return
|
|
150
|
+
}
|
|
151
|
+
if (bodyPhase === 'collapsed') setBodyPhase('hidden')
|
|
152
|
+
else if (bodyPhase === 'entering' || bodyPhase === 'shown') setBodyPhase('closing')
|
|
153
|
+
}, [expanded, bodyPhase])
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
if (bodyPhase !== 'entering' && bodyPhase !== 'closing') return
|
|
156
|
+
const timer = setTimeout(() => {
|
|
157
|
+
setBodyPhase(bodyPhase === 'entering' ? 'shown' : 'hidden')
|
|
158
|
+
}, BODY_MOTION_MS)
|
|
159
|
+
return () => { clearTimeout(timer) }
|
|
160
|
+
}, [bodyPhase])
|
|
110
161
|
if (!state.available) return null
|
|
111
162
|
const title = props.t(props.titleKey)
|
|
112
163
|
const description = props.t(props.descriptionKey)
|
|
164
|
+
const descriptionTitle = props.descriptionTitleKey === undefined ? description : props.t(props.descriptionTitleKey)
|
|
113
165
|
const blocked = !state.dirty || state.invalid || state.saving
|
|
114
|
-
const
|
|
115
|
-
const cardClass =
|
|
166
|
+
const baseClass = expanded ? `${css.cardOpen} ${css.card}` : css.card
|
|
167
|
+
const cardClass = props.density === 'nested' ? `${baseClass} ${css.cardNested}` : baseClass
|
|
168
|
+
/** The body region both legs share; a hidden phase renders nothing at all. */
|
|
169
|
+
const bodyRegion = (content: ReactNode) => bodyPhase === 'hidden'
|
|
170
|
+
? null
|
|
171
|
+
: (
|
|
172
|
+
<div className={css.disclosure} data-state={bodyPhase} ref={bodyRef}>
|
|
173
|
+
<div className={css.body}>{content}</div>
|
|
174
|
+
</div>
|
|
175
|
+
)
|
|
116
176
|
// With alwaysOpen the nav entry already provides the selection, so the
|
|
117
177
|
// header is a static title row instead of a disclosure button.
|
|
118
178
|
const header = alwaysOpen === true
|
|
@@ -121,7 +181,7 @@ export function PluginSettingsCard<TKey extends string = string>(props: PluginSe
|
|
|
121
181
|
{props.icon !== undefined ? <span className={css.mark} aria-hidden="true">{props.icon}</span> : null}
|
|
122
182
|
<span className={css.headText}>
|
|
123
183
|
<span className={css.name} id={props.titleId} title={title}>{title}</span>
|
|
124
|
-
<span className={css.description} title={
|
|
184
|
+
<span className={css.description} title={descriptionTitle}>{props.descriptionNode ?? description}</span>
|
|
125
185
|
</span>
|
|
126
186
|
{props.headerAction !== undefined ? <span className={css.headerAction}>{props.headerAction}</span> : null}
|
|
127
187
|
{state.dirty ? <span className={css.pending} title={props.t('settings.unsaved')}>{props.t('settings.unsaved')}</span> : null}
|
|
@@ -138,7 +198,7 @@ export function PluginSettingsCard<TKey extends string = string>(props: PluginSe
|
|
|
138
198
|
{props.icon !== undefined ? <span className={css.mark} aria-hidden="true">{props.icon}</span> : null}
|
|
139
199
|
<span className={css.headText}>
|
|
140
200
|
<span className={css.name} id={props.titleId} title={title}>{title}</span>
|
|
141
|
-
<span className={css.description} title={
|
|
201
|
+
<span className={css.description} title={descriptionTitle}>{props.descriptionNode ?? description}</span>
|
|
142
202
|
</span>
|
|
143
203
|
{props.headerAction !== undefined ? <span className={css.headerAction}>{props.headerAction}</span> : null}
|
|
144
204
|
{state.dirty ? <span className={css.pending} title={props.t('settings.unsaved')}>{props.t('settings.unsaved')}</span> : null}
|
|
@@ -166,25 +226,19 @@ export function PluginSettingsCard<TKey extends string = string>(props: PluginSe
|
|
|
166
226
|
return (
|
|
167
227
|
<li className={cardClass}>
|
|
168
228
|
{header}
|
|
169
|
-
{
|
|
170
|
-
? (
|
|
171
|
-
<div className={css.body}>
|
|
172
|
-
{showNotice ? <p className={css.notExposed} role="status">{props.t('settings.notExposed')}</p> : null}
|
|
173
|
-
</div>
|
|
174
|
-
)
|
|
175
|
-
: null}
|
|
229
|
+
{bodyRegion(showNotice ? <p className={css.notExposed} role="status">{props.t('settings.notExposed')}</p> : null)}
|
|
176
230
|
</li>
|
|
177
231
|
)
|
|
178
232
|
}
|
|
179
233
|
// A header-only card has no body region at all: the divider would otherwise
|
|
180
234
|
// sit above an empty box.
|
|
181
|
-
const bodyVisible =
|
|
235
|
+
const bodyVisible = props.headerOnly !== true
|
|
182
236
|
return (
|
|
183
237
|
<li className={cardClass}>
|
|
184
238
|
{header}
|
|
185
239
|
{bodyVisible
|
|
186
|
-
? (
|
|
187
|
-
|
|
240
|
+
? bodyRegion(
|
|
241
|
+
<>
|
|
188
242
|
{!state.writable ? <p className={css.readOnly} role="status">{props.t('settings.readOnly')}</p> : null}
|
|
189
243
|
{props.children}
|
|
190
244
|
{props.hideFooter === true
|
|
@@ -216,7 +270,7 @@ export function PluginSettingsCard<TKey extends string = string>(props: PluginSe
|
|
|
216
270
|
</button>
|
|
217
271
|
</div>
|
|
218
272
|
)}
|
|
219
|
-
|
|
273
|
+
</>,
|
|
220
274
|
)
|
|
221
275
|
: null}
|
|
222
276
|
</li>
|
|
@@ -231,6 +285,12 @@ export interface FieldProps {
|
|
|
231
285
|
label: string
|
|
232
286
|
/** One-line explanation rendered under the control. */
|
|
233
287
|
hint: string
|
|
288
|
+
/**
|
|
289
|
+
* Full sentence behind the visible hint, exposed as the paragraph's native
|
|
290
|
+
* `title` so a card can shorten the line without losing the text. Omitted:
|
|
291
|
+
* the paragraph carries no title attribute at all.
|
|
292
|
+
*/
|
|
293
|
+
hintTitle?: string
|
|
234
294
|
/** Draft text this control renders. */
|
|
235
295
|
text: string
|
|
236
296
|
/** True when saving would leave a user-layer entry for this field. */
|
|
@@ -289,7 +349,7 @@ export function ValueField(props: FieldProps & {
|
|
|
289
349
|
disabled={props.disabled}
|
|
290
350
|
onChange={(event) => { props.onEdit(event.target.value) }}
|
|
291
351
|
/>
|
|
292
|
-
<p className={props.invalid ? css.invalid : css.hint}>
|
|
352
|
+
<p className={props.invalid ? css.invalid : css.hint} title={props.hintTitle}>
|
|
293
353
|
{props.invalid ? props.invalidLabel : props.hint}
|
|
294
354
|
</p>
|
|
295
355
|
</div>
|
|
@@ -541,7 +601,7 @@ export function BooleanField(props: FieldProps & {
|
|
|
541
601
|
invalid={props.invalid}
|
|
542
602
|
onEdit={props.onEdit}
|
|
543
603
|
/>
|
|
544
|
-
<p className={css.hint}>{props.hint}</p>
|
|
604
|
+
<p className={css.hint} title={props.hintTitle}>{props.hint}</p>
|
|
545
605
|
</div>
|
|
546
606
|
)
|
|
547
607
|
}
|
|
@@ -581,7 +641,7 @@ export function ChoiceField(props: FieldProps & {
|
|
|
581
641
|
invalid={props.invalid}
|
|
582
642
|
onEdit={props.onEdit}
|
|
583
643
|
/>
|
|
584
|
-
<p className={props.invalid ? css.invalid : css.hint}>
|
|
644
|
+
<p className={props.invalid ? css.invalid : css.hint} title={props.hintTitle}>
|
|
585
645
|
{props.invalid ? props.invalidLabel : props.hint}
|
|
586
646
|
</p>
|
|
587
647
|
</div>
|