@linxin666/dsh-liangshen 0.4.19 → 0.4.21
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 +7 -3
- package/README.zh.md +7 -3
- package/lib/client.js +66 -3
- package/lib/client.js.map +1 -1
- package/lib/index.js +18 -7
- package/lib/types/client/LiangShenSettingsCard.d.ts +3 -0
- package/lib/types/client/locales.d.ts +3 -0
- package/lib/types/client/settings-form.d.ts +2 -0
- package/lib/types/composition.d.ts +6 -0
- package/lib/types/index.d.ts +14 -1
- package/package.json +1 -1
- package/presets/liangshen/agent.cordis.yml +16 -3
- package/presets/liangshen/minimal-prompt.mjs +37 -9
- package/presets/liangshen/paging.mjs +140 -30
- package/presets/liangshen/tool-activate.mjs +20 -6
- package/presets/liangshen/tool-catalog.mjs +21 -2
- package/presets/liangshen/wire-presentation.mjs +33 -0
- package/presets/liangshen/working-context.mjs +14 -2
- package/src/client/LiangShenSettingsCard.tsx +17 -1
- package/src/client/locales.ts +6 -0
- package/src/client/settings-form.ts +21 -2
- package/src/composition.test.ts +7 -0
- package/src/composition.ts +13 -2
- package/src/index.test.ts +1 -0
- package/src/index.ts +15 -1
|
@@ -23,16 +23,21 @@
|
|
|
23
23
|
* eviction is named in this tool's result so the catalog's next publication
|
|
24
24
|
* reflects it.
|
|
25
25
|
*
|
|
26
|
+
* With `idleReclaimSteps` enabled, the same projection also applies expired
|
|
27
|
+
* namespaces at this activation and names them in the result; the report comes
|
|
28
|
+
* from `projectActivation`, the same fold transition the next replay applies.
|
|
29
|
+
*
|
|
26
30
|
* Validation: the target must name a namespace that currently has paged,
|
|
27
31
|
* inactive tools — an unknown namespace fails with the list of available ones,
|
|
28
32
|
* and an already-active namespace is a no-op error instead of a silent success.
|
|
29
33
|
*/
|
|
30
34
|
|
|
31
35
|
import {
|
|
36
|
+
DEFAULT_IDLE_RECLAIM_STEPS,
|
|
32
37
|
DEFAULT_MAX_ACTIVE_NAMESPACES,
|
|
33
38
|
integerAtLeast,
|
|
34
39
|
namespaceOf,
|
|
35
|
-
|
|
40
|
+
projectActivation,
|
|
36
41
|
sessionEvents,
|
|
37
42
|
validatePagedToolPatterns,
|
|
38
43
|
} from './paging.mjs'
|
|
@@ -54,6 +59,13 @@ export function apply(ctx, config) {
|
|
|
54
59
|
1,
|
|
55
60
|
DEFAULT_MAX_ACTIVE_NAMESPACES,
|
|
56
61
|
)
|
|
62
|
+
const idleReclaimSteps = integerAtLeast(
|
|
63
|
+
name,
|
|
64
|
+
config?.idleReclaimSteps,
|
|
65
|
+
'idleReclaimSteps',
|
|
66
|
+
0,
|
|
67
|
+
DEFAULT_IDLE_RECLAIM_STEPS,
|
|
68
|
+
)
|
|
57
69
|
|
|
58
70
|
/**
|
|
59
71
|
* Read the session's visible tool schemas from the public API, tolerating
|
|
@@ -120,6 +132,7 @@ export function apply(ctx, config) {
|
|
|
120
132
|
description: [
|
|
121
133
|
`Load one paged tool namespace back into this session's reach — onto the wire, and the generated SDK along with it. The session catalog summarizes the paged namespaces; activating one makes its tools callable from the next request on.`,
|
|
122
134
|
`At most ${maxActiveNamespaces} namespaces stay active at once: activating beyond the cap evicts the least recently used namespace back to the catalog summary.`,
|
|
135
|
+
...(idleReclaimSteps > 0 ? [`Idle namespaces (no successful call for ${idleReclaimSteps} steps) are reclaimed at the next activation or compaction, never mid-turn; a reclaimed namespace returns to the catalog summary and can be activated again.`] : []),
|
|
123
136
|
'The target must be a paged, currently inactive namespace exactly as the catalog names it.',
|
|
124
137
|
].join('\n'),
|
|
125
138
|
parameters: {
|
|
@@ -177,21 +190,22 @@ export function apply(ctx, config) {
|
|
|
177
190
|
&& event.data?.name === 'tool_activate'
|
|
178
191
|
&& String(event.data?.callId) === String(selfCallId)
|
|
179
192
|
))
|
|
180
|
-
const
|
|
181
|
-
if (
|
|
193
|
+
const projection = projectActivation(events, maxActiveNamespaces, pagedToolPatterns, namespace, idleReclaimSteps)
|
|
194
|
+
if (projection.wasActive) {
|
|
182
195
|
throw new Error(`namespace "${namespace}" is already active; its tools are on the wire`)
|
|
183
196
|
}
|
|
184
197
|
|
|
185
|
-
const next = [...active, namespace]
|
|
186
|
-
const evicted = next.length > maxActiveNamespaces ? next.shift() : undefined
|
|
187
198
|
const tools = paged.get(namespace)
|
|
188
199
|
const lines = [
|
|
189
200
|
`Activated namespace "${namespace}" (${tools.length} tool${tools.length === 1 ? '' : 's'}): ${tools.join(', ')}.`,
|
|
190
201
|
'Its tools are on the wire from the next request; call them directly by name.',
|
|
191
202
|
]
|
|
192
|
-
|
|
203
|
+
for (const evicted of projection.evicted) {
|
|
193
204
|
lines.push(`Least recently used namespace "${evicted}" was paged out (capacity ${maxActiveNamespaces}); its summary stays in the catalog and tool_activate can reload it.`)
|
|
194
205
|
}
|
|
206
|
+
for (const reclaimed of projection.reclaimed) {
|
|
207
|
+
lines.push(`Idle namespace "${reclaimed}" was reclaimed (no successful call for ${idleReclaimSteps} steps); its summary stays in the catalog and tool_activate can reload it.`)
|
|
208
|
+
}
|
|
195
209
|
return { text: lines.join(' ') }
|
|
196
210
|
},
|
|
197
211
|
})
|
|
@@ -33,6 +33,11 @@
|
|
|
33
33
|
* process-memory state. At most a few namespaces stay active; the LRU
|
|
34
34
|
* eviction falls out of the same replay.
|
|
35
35
|
*
|
|
36
|
+
* `idleReclaimSteps` (default 0 = off) adds deferred idle reclaim: a namespace
|
|
37
|
+
* idle for N steps expires, but the replay applies the expiry only at the next
|
|
38
|
+
* activation touch or a `compaction/end` boundary — moments the prompt prefix
|
|
39
|
+
* changes anyway — so reclaim adds no prefix-cache rebuild (issue #2066).
|
|
40
|
+
*
|
|
36
41
|
* Paging is enforced in ONE place: a per-scope registry restriction
|
|
37
42
|
* (agent.ctx.tools.restrict) that removes the paged names from every scoped
|
|
38
43
|
* reader, the request's own wire included.
|
|
@@ -87,6 +92,7 @@
|
|
|
87
92
|
*/
|
|
88
93
|
|
|
89
94
|
import {
|
|
95
|
+
DEFAULT_IDLE_RECLAIM_STEPS,
|
|
90
96
|
DEFAULT_MAX_ACTIVE_NAMESPACES,
|
|
91
97
|
TOOL_ACTIVATE_NAME,
|
|
92
98
|
integerAtLeast,
|
|
@@ -99,6 +105,7 @@ import {
|
|
|
99
105
|
summarizeInactive,
|
|
100
106
|
validatePagedToolPatterns,
|
|
101
107
|
} from './paging.mjs'
|
|
108
|
+
import { publishWirePresentation } from './wire-presentation.mjs'
|
|
102
109
|
|
|
103
110
|
/** Cordis plugin name used by loader diagnostics. */
|
|
104
111
|
export const name = 'liangshen-tool-catalog'
|
|
@@ -666,6 +673,13 @@ export function apply(ctx, config) {
|
|
|
666
673
|
1,
|
|
667
674
|
DEFAULT_MAX_RESIDENT_TOKENS,
|
|
668
675
|
)
|
|
676
|
+
const idleReclaimSteps = integerAtLeast(
|
|
677
|
+
name,
|
|
678
|
+
config?.idleReclaimSteps,
|
|
679
|
+
'idleReclaimSteps',
|
|
680
|
+
0,
|
|
681
|
+
DEFAULT_IDLE_RECLAIM_STEPS,
|
|
682
|
+
)
|
|
669
683
|
|
|
670
684
|
// One-time warnings, per concern so each retired/legacy key reports itself.
|
|
671
685
|
const warned = new Set()
|
|
@@ -760,7 +774,7 @@ export function apply(ctx, config) {
|
|
|
760
774
|
// there is nothing to restrict, and the activation tool must still know the
|
|
761
775
|
// namespace exists to report it as active instead of unknown.
|
|
762
776
|
publishPagedSurface(agent, allPaged.inactive)
|
|
763
|
-
const active = replayActivations(sessionEvents(agent?.session), maxActiveNamespaces, pagedToolPatterns).active
|
|
777
|
+
const active = replayActivations(sessionEvents(agent?.session), maxActiveNamespaces, pagedToolPatterns, undefined, idleReclaimSteps).active
|
|
764
778
|
const activeNames = new Set(active)
|
|
765
779
|
const withheld = []
|
|
766
780
|
const inactive = new Map()
|
|
@@ -968,6 +982,12 @@ export function apply(ctx, config) {
|
|
|
968
982
|
agentBySession.set(agent.session, agent)
|
|
969
983
|
}
|
|
970
984
|
|
|
985
|
+
// The presentation is knowable before the rest of the waterfall runs. Publish
|
|
986
|
+
// it now so minimal-prompt reads THIS request's transport after its own next()
|
|
987
|
+
// regardless of which prepended listener wraps the other.
|
|
988
|
+
const effectivePresentation = collapsedTransport() ? 'ptc' : 'native'
|
|
989
|
+
publishWirePresentation(agent, effectivePresentation)
|
|
990
|
+
|
|
971
991
|
// Page the scope before the providers are collected; a scope the lifecycle
|
|
972
992
|
// hooks already paged re-derives the same state, so this is idempotent.
|
|
973
993
|
syncBeforeAssembly(agent)
|
|
@@ -989,7 +1009,6 @@ export function apply(ctx, config) {
|
|
|
989
1009
|
// under both, so the configured mode plus a mounted runtime is the answer -
|
|
990
1010
|
// and a mode whose runtime is missing keeps the native wording, because
|
|
991
1011
|
// that is the wire an executor-less deployment renders.
|
|
992
|
-
const effectivePresentation = collapsedTransport() ? 'ptc' : 'native'
|
|
993
1012
|
|
|
994
1013
|
// An unreadable projection is NOT an empty one. Keep the catalog this scope
|
|
995
1014
|
// last published instead of rewriting it: recording "this session has no
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-session wire presentation shared by the sibling tool-catalog and
|
|
3
|
+
* minimal-prompt rows. The Host's assembly waterfall carries sections only;
|
|
4
|
+
* tool-catalog owns the configured mode plus runtime probe and publishes it
|
|
5
|
+
* before calling the next assembly listener.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const presentationByAgent = new WeakMap()
|
|
9
|
+
const presentationBySession = new WeakMap()
|
|
10
|
+
|
|
11
|
+
/** Publish or retract the effective native/ptc transport for one agent scope. */
|
|
12
|
+
export function publishWirePresentation(agent, presentation) {
|
|
13
|
+
if (agent === undefined || agent === null || (typeof agent !== 'object' && typeof agent !== 'function')) return
|
|
14
|
+
const session = agent.session
|
|
15
|
+
const sessionKey = session !== null && (typeof session === 'object' || typeof session === 'function') ? session : undefined
|
|
16
|
+
if (presentation === undefined) {
|
|
17
|
+
presentationByAgent.delete(agent)
|
|
18
|
+
if (sessionKey !== undefined) presentationBySession.delete(sessionKey)
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
presentationByAgent.set(agent, presentation)
|
|
22
|
+
if (sessionKey !== undefined) presentationBySession.set(sessionKey, presentation)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Read the transport published for this scope, or undefined when unavailable. */
|
|
26
|
+
export function wirePresentationFor(agent) {
|
|
27
|
+
if (agent === undefined || agent === null || (typeof agent !== 'object' && typeof agent !== 'function')) return undefined
|
|
28
|
+
const direct = presentationByAgent.get(agent)
|
|
29
|
+
if (direct !== undefined) return direct
|
|
30
|
+
const session = agent.session
|
|
31
|
+
if (session === null || (typeof session !== 'object' && typeof session !== 'function')) return undefined
|
|
32
|
+
return presentationBySession.get(session)
|
|
33
|
+
}
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
* not depend on.
|
|
15
15
|
* - `active namespaces: ...` — the paged tool namespaces currently on the
|
|
16
16
|
* wire, replayed from `tool_activate` calls exactly the way the wire
|
|
17
|
-
* partition in tool-catalog replays them.
|
|
17
|
+
* partition in tool-catalog replays them. Deferred idle reclaim
|
|
18
|
+
* (`idleReclaimSteps`) is applied by the same replay, so the line names
|
|
19
|
+
* exactly the applied active set.
|
|
18
20
|
* - `in progress: ...` — the in-progress todo titles from the latest
|
|
19
21
|
* `todo/write` event, cleared by the next `turn/start`, mirroring the host's
|
|
20
22
|
* todos projection.
|
|
@@ -32,6 +34,7 @@
|
|
|
32
34
|
*/
|
|
33
35
|
|
|
34
36
|
import {
|
|
37
|
+
DEFAULT_IDLE_RECLAIM_STEPS,
|
|
35
38
|
DEFAULT_MAX_ACTIVE_NAMESPACES,
|
|
36
39
|
DEFAULT_PAGED_TOOL_PATTERNS,
|
|
37
40
|
TOOL_ACTIVATE_NAME,
|
|
@@ -114,6 +117,7 @@ function clipTitle(title) {
|
|
|
114
117
|
export function renderWorkingContext(events, options) {
|
|
115
118
|
const patterns = options?.pagedToolPatterns ?? DEFAULT_PAGED_TOOL_PATTERNS
|
|
116
119
|
const maxActive = options?.maxActiveNamespaces ?? DEFAULT_MAX_ACTIVE_NAMESPACES
|
|
120
|
+
const idleReclaim = options?.idleReclaimSteps ?? DEFAULT_IDLE_RECLAIM_STEPS
|
|
117
121
|
const list = Array.isArray(events) ? events : []
|
|
118
122
|
const plan = { seen: false, active: false }
|
|
119
123
|
const facts = []
|
|
@@ -135,7 +139,7 @@ export function renderWorkingContext(events, options) {
|
|
|
135
139
|
if (plan.seen) fields.push(`plan mode: ${plan.active ? 'on' : 'off'}`)
|
|
136
140
|
|
|
137
141
|
if (sawActivation) {
|
|
138
|
-
const { active } = replayActivations(list, maxActive, patterns, errored)
|
|
142
|
+
const { active } = replayActivations(list, maxActive, patterns, errored, idleReclaim)
|
|
139
143
|
if (active.length > 0) fields.push(`active namespaces: ${[...active].sort().join(', ')}`)
|
|
140
144
|
}
|
|
141
145
|
|
|
@@ -181,6 +185,13 @@ export function apply(ctx, config) {
|
|
|
181
185
|
1,
|
|
182
186
|
DEFAULT_MAX_ACTIVE_NAMESPACES,
|
|
183
187
|
)
|
|
188
|
+
const idleReclaimSteps = integerAtLeast(
|
|
189
|
+
name,
|
|
190
|
+
config?.idleReclaimSteps,
|
|
191
|
+
'idleReclaimSteps',
|
|
192
|
+
0,
|
|
193
|
+
DEFAULT_IDLE_RECLAIM_STEPS,
|
|
194
|
+
)
|
|
184
195
|
|
|
185
196
|
ctx.on('agent/pre-step', async (payload, next) => {
|
|
186
197
|
const decision = await next()
|
|
@@ -191,6 +202,7 @@ export function apply(ctx, config) {
|
|
|
191
202
|
const line = renderWorkingContext(sessionEvents(agent.session), {
|
|
192
203
|
pagedToolPatterns,
|
|
193
204
|
maxActiveNamespaces,
|
|
205
|
+
idleReclaimSteps,
|
|
194
206
|
})
|
|
195
207
|
|
|
196
208
|
// Nothing objective to say: inject nothing (a stale published line is left
|
|
@@ -15,7 +15,7 @@ import type { SnapshotStore } from '@deepseek-ai/dsh-client-store'
|
|
|
15
15
|
import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
16
16
|
import { LiangShenMark } from './LiangShenMark.tsx'
|
|
17
17
|
import { BooleanField, ChoiceField, PluginSettingsCard, ValueField } from './PluginSettingsCard.tsx'
|
|
18
|
-
import { CardForm, booleanField, choiceField, textField, type CardActions, type CardShell, type FieldSpec, type FieldState as CardFieldState } from './settings-form.ts'
|
|
18
|
+
import { CardForm, booleanField, choiceField, numberField, textField, type CardActions, type CardShell, type FieldSpec, type FieldState as CardFieldState } from './settings-form.ts'
|
|
19
19
|
|
|
20
20
|
/** A tool family entry: a prefix ending in exactly one trailing star. */
|
|
21
21
|
const FAMILY_ENTRY_RE = /^[^*]+\*$/
|
|
@@ -52,6 +52,8 @@ export interface LiangShenSettings {
|
|
|
52
52
|
dispatcher?: boolean
|
|
53
53
|
/** Comma-separated on-demand tool families the Host writes to the tool-catalog row. */
|
|
54
54
|
pagedToolPatterns?: string
|
|
55
|
+
/** Deferred idle-reclaim threshold in steps the Host writes to every paging row. */
|
|
56
|
+
idleReclaimSteps?: number
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
/** What the LiangShen card renders. */
|
|
@@ -61,6 +63,7 @@ export interface LiangShenSettingsCardState extends CardShell {
|
|
|
61
63
|
presentation: CardFieldState
|
|
62
64
|
dispatcher: CardFieldState
|
|
63
65
|
pagedToolPatterns: CardFieldState
|
|
66
|
+
idleReclaimSteps: CardFieldState
|
|
64
67
|
}
|
|
65
68
|
|
|
66
69
|
/** The registration-side face the card's slot entry injects. */
|
|
@@ -84,6 +87,7 @@ export class LiangShenSettingsCardController {
|
|
|
84
87
|
choiceField('presentation', PRESENTATION_CHOICES),
|
|
85
88
|
booleanField('dispatcher'),
|
|
86
89
|
pagedToolPatternsField('pagedToolPatterns'),
|
|
90
|
+
numberField('idleReclaimSteps', { integer: true, min: 0 }),
|
|
87
91
|
])
|
|
88
92
|
this.store = this.form.bind(() => this.projection())
|
|
89
93
|
}
|
|
@@ -96,6 +100,7 @@ export class LiangShenSettingsCardController {
|
|
|
96
100
|
presentation: this.form.field('presentation'),
|
|
97
101
|
dispatcher: this.form.field('dispatcher'),
|
|
98
102
|
pagedToolPatterns: this.form.field('pagedToolPatterns'),
|
|
103
|
+
idleReclaimSteps: this.form.field('idleReclaimSteps'),
|
|
99
104
|
}
|
|
100
105
|
}
|
|
101
106
|
|
|
@@ -202,6 +207,17 @@ export function LiangShenSettingsCard(props: LiangShenSettingsCardProps) {
|
|
|
202
207
|
onEdit={(text) => { props.edit('pagedToolPatterns', text) }}
|
|
203
208
|
onReset={() => { props.resetField('pagedToolPatterns') }}
|
|
204
209
|
/>
|
|
210
|
+
<ValueField
|
|
211
|
+
id="settings-liangshen-idle-reclaim-steps"
|
|
212
|
+
label={t('settings.idleReclaimSteps')}
|
|
213
|
+
hint={t('settings.idleReclaimStepsHint')}
|
|
214
|
+
placeholder="0"
|
|
215
|
+
{...fieldProps}
|
|
216
|
+
invalidLabel={t('settings.idleReclaimStepsInvalid')}
|
|
217
|
+
{...state.idleReclaimSteps}
|
|
218
|
+
onEdit={(text) => { props.edit('idleReclaimSteps', text) }}
|
|
219
|
+
onReset={() => { props.resetField('idleReclaimSteps') }}
|
|
220
|
+
/>
|
|
205
221
|
</PluginSettingsCard>
|
|
206
222
|
)
|
|
207
223
|
}
|
package/src/client/locales.ts
CHANGED
|
@@ -34,6 +34,9 @@ export const zh = {
|
|
|
34
34
|
'settings.pagedToolPatterns': '按需工具族',
|
|
35
35
|
'settings.pagedToolPatternsHint': '逗号分隔,每项以单个 * 结尾。命中这些前缀的工具默认不进上下文,需要时用 tool_activate 按需加载。留空继承出厂 7 项:mcp__*, browser_*, task_board_*, team_*, squad*, ui_*, ssh_*。',
|
|
36
36
|
'settings.pagedToolPatternsInvalid': '每项须是非空前缀并以单个 * 结尾,逗号分隔,例如 task_board_*。',
|
|
37
|
+
'settings.idleReclaimSteps': '空闲收回步数',
|
|
38
|
+
'settings.idleReclaimStepsHint': '连续 N 步没有成功调用的已激活工具族会过期,但只在下次激活或压缩时收回——这些时机前缀缓存本就要重建,因此不新增缓存重建;收回前仍常驻可用,再次调用即续命。0 或留空 = 不收回(出厂行为)。',
|
|
39
|
+
'settings.idleReclaimStepsInvalid': '填一个非负整数(步数),例如 30;0 或留空表示不收回。',
|
|
37
40
|
'settings.on': '开',
|
|
38
41
|
'settings.off': '关',
|
|
39
42
|
'settings.inherit': '继承',
|
|
@@ -79,6 +82,9 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
79
82
|
'settings.pagedToolPatterns': 'On-demand tool families',
|
|
80
83
|
'settings.pagedToolPatternsHint': 'Comma separated, each entry ending in a single *. Tools matching these prefixes stay out of context by default; load them with tool_activate when needed. Leave empty to inherit the 7 factory entries: mcp__*, browser_*, task_board_*, team_*, squad*, ui_*, ssh_*.',
|
|
81
84
|
'settings.pagedToolPatternsInvalid': 'Each entry must be a non-empty prefix ending in a single *, comma separated, for example task_board_*.',
|
|
85
|
+
'settings.idleReclaimSteps': 'Idle reclaim steps',
|
|
86
|
+
'settings.idleReclaimStepsHint': 'An activated tool family with no successful call for N steps expires, but is reclaimed only at the next activation or compaction — moments the prefix cache rebuilds anyway, so no extra rebuild is paid. It stays resident and callable until then; any call refreshes it. 0 or empty = no reclaim (factory behavior).',
|
|
87
|
+
'settings.idleReclaimStepsInvalid': 'Enter a non-negative integer number of steps, for example 30; 0 or empty means no reclaim.',
|
|
82
88
|
'settings.on': 'On',
|
|
83
89
|
'settings.off': 'Off',
|
|
84
90
|
'settings.inherit': 'Inherit',
|
|
@@ -141,11 +141,13 @@ export interface NumberConstraints {
|
|
|
141
141
|
integer?: boolean
|
|
142
142
|
/** The accepted value must be at least this. */
|
|
143
143
|
min?: number
|
|
144
|
+
/** The accepted value must be at most this. */
|
|
145
|
+
max?: number
|
|
144
146
|
}
|
|
145
147
|
|
|
146
148
|
/** A whole- or decimal-number field. An empty draft clears the field; any other draft that is not a finite number within the constraints stays unwritten. */
|
|
147
149
|
export function numberField(field: string, constraints: NumberConstraints = {}): FieldSpec {
|
|
148
|
-
const { integer = false, min } = constraints
|
|
150
|
+
const { integer = false, min, max } = constraints
|
|
149
151
|
return {
|
|
150
152
|
field,
|
|
151
153
|
entry: 'type',
|
|
@@ -157,6 +159,7 @@ export function numberField(field: string, constraints: NumberConstraints = {}):
|
|
|
157
159
|
if (!Number.isFinite(parsed)) return undefined
|
|
158
160
|
if (integer && !Number.isInteger(parsed)) return undefined
|
|
159
161
|
if (min !== undefined && parsed < min) return undefined
|
|
162
|
+
if (max !== undefined && parsed > max) return undefined
|
|
160
163
|
return { kind: 'set', value: parsed }
|
|
161
164
|
},
|
|
162
165
|
}
|
|
@@ -439,7 +442,7 @@ export class CardForm<T> {
|
|
|
439
442
|
// against. Settling is the only signal the form has; the rest of the
|
|
440
443
|
// batch, when one exists, still carries the atomic verdict by read-back.
|
|
441
444
|
if (this.specOf(field).secret) return true
|
|
442
|
-
return this.userLayer()?.[field]
|
|
445
|
+
return jsonValuesEqual(this.userLayer()?.[field], value)
|
|
443
446
|
}
|
|
444
447
|
|
|
445
448
|
/**
|
|
@@ -508,3 +511,19 @@ export class CardForm<T> {
|
|
|
508
511
|
for (const listener of this.listeners) listener()
|
|
509
512
|
}
|
|
510
513
|
}
|
|
514
|
+
|
|
515
|
+
/** Structural equality for JSON settings values (primitives, arrays, plain objects). */
|
|
516
|
+
function jsonValuesEqual(left: unknown, right: unknown): boolean {
|
|
517
|
+
if (Object.is(left, right)) return true
|
|
518
|
+
if (typeof left !== 'object' || left === null || typeof right !== 'object' || right === null) return false
|
|
519
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
520
|
+
if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false
|
|
521
|
+
return left.every((item, index) => jsonValuesEqual(item, right[index]))
|
|
522
|
+
}
|
|
523
|
+
const a = left as Record<string, unknown>
|
|
524
|
+
const b = right as Record<string, unknown>
|
|
525
|
+
const keysA = Object.keys(a).filter(key => a[key] !== undefined)
|
|
526
|
+
const keysB = Object.keys(b).filter(key => b[key] !== undefined)
|
|
527
|
+
if (keysA.length !== keysB.length) return false
|
|
528
|
+
return keysA.every(key => Object.hasOwn(b, key) && jsonValuesEqual(a[key], b[key]))
|
|
529
|
+
}
|
package/src/composition.test.ts
CHANGED
|
@@ -93,6 +93,13 @@ describe('readCompositionRows', () => {
|
|
|
93
93
|
expect(configOf(rowOf(rows(), 'minimal-prompt'))['dispatcher']).toBe(true)
|
|
94
94
|
})
|
|
95
95
|
|
|
96
|
+
it('operator reads an empty third-party section allowlist by default', () => {
|
|
97
|
+
// Given the factory composition
|
|
98
|
+
// When the operator reads the minimal-prompt row
|
|
99
|
+
// Then the opt-in extension point is present but changes no default selection
|
|
100
|
+
expect(configOf(rowOf(rows(), 'minimal-prompt'))['keepSections']).toEqual([])
|
|
101
|
+
})
|
|
102
|
+
|
|
96
103
|
it('operator keeps a literal block scalar verbatim', () => {
|
|
97
104
|
// Given the persona row's `prefix: |-` scalar, When the operator reads it,
|
|
98
105
|
// Then the prose is content and the next composition row ends it.
|
package/src/composition.ts
CHANGED
|
@@ -512,6 +512,12 @@ export interface PresetOverrides {
|
|
|
512
512
|
* when blank or malformed.
|
|
513
513
|
*/
|
|
514
514
|
pagedToolPatterns?: string
|
|
515
|
+
/**
|
|
516
|
+
* Deferred idle-reclaim threshold in steps; written to every row that pages
|
|
517
|
+
* from the list (tool-catalog, tool-activate, working-context), skipped when
|
|
518
|
+
* absent.
|
|
519
|
+
*/
|
|
520
|
+
idleReclaimSteps?: number
|
|
515
521
|
}
|
|
516
522
|
|
|
517
523
|
/**
|
|
@@ -546,13 +552,18 @@ function overrideTargets(overrides: PresetOverrides): OverrideTarget[] {
|
|
|
546
552
|
// working-context renders it — so a row left on its own default would
|
|
547
553
|
// disagree about what is active and could strand a withheld namespace.
|
|
548
554
|
const pagedPatch = () => (paged === undefined ? {} : { pagedToolPatterns: [...paged] })
|
|
555
|
+
// The reclaim threshold is the same kind of three-row fact: all three rows
|
|
556
|
+
// replay the log with it, so a row left on its own default would disagree
|
|
557
|
+
// about which namespaces are still active.
|
|
558
|
+
const idlePatch = () => (overrides.idleReclaimSteps === undefined ? {} : { idleReclaimSteps: overrides.idleReclaimSteps })
|
|
549
559
|
return [
|
|
550
560
|
['tool-catalog', {
|
|
551
561
|
...overrides.presentation === undefined ? {} : { presentation: overrides.presentation },
|
|
552
562
|
...pagedPatch(),
|
|
563
|
+
...idlePatch(),
|
|
553
564
|
}],
|
|
554
|
-
['tool-activate', pagedPatch()],
|
|
555
|
-
['working-context', pagedPatch()],
|
|
565
|
+
['tool-activate', { ...pagedPatch(), ...idlePatch() }],
|
|
566
|
+
['working-context', { ...pagedPatch(), ...idlePatch() }],
|
|
556
567
|
['minimal-prompt', { ...overrides.dispatcher === undefined ? {} : { dispatcher: overrides.dispatcher } }],
|
|
557
568
|
]
|
|
558
569
|
}
|
package/src/index.test.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -111,6 +111,15 @@ export interface Config {
|
|
|
111
111
|
* malformed text is ignored.
|
|
112
112
|
*/
|
|
113
113
|
pagedToolPatterns?: ConfigField<string>
|
|
114
|
+
/**
|
|
115
|
+
* Deferred idle-reclaim threshold in steps, written to every row that replays
|
|
116
|
+
* the page (tool-catalog, tool-activate, working-context). 0 (the default)
|
|
117
|
+
* keeps every activation resident until LRU eviction — the shipped behavior.
|
|
118
|
+
* A positive N expires a namespace with no successful call for N steps, but
|
|
119
|
+
* the replay applies the expiry only at the next activation or compaction,
|
|
120
|
+
* so reclaim never adds a prefix-cache rebuild (issue #2066).
|
|
121
|
+
*/
|
|
122
|
+
idleReclaimSteps?: ConfigField<number>
|
|
114
123
|
}
|
|
115
124
|
|
|
116
125
|
export const Config = z.object({
|
|
@@ -122,6 +131,7 @@ export const Config = z.object({
|
|
|
122
131
|
]).default('ptc').volatile(),
|
|
123
132
|
dispatcher: z.boolean().default(true).volatile(),
|
|
124
133
|
pagedToolPatterns: z.string().default('').volatile(),
|
|
134
|
+
idleReclaimSteps: z.number().min(0).default(0).volatile(),
|
|
125
135
|
})
|
|
126
136
|
|
|
127
137
|
/** The settings the runtime acts on, every field read at its use site. */
|
|
@@ -136,6 +146,8 @@ export interface ResolvedConfig {
|
|
|
136
146
|
dispatcher: boolean
|
|
137
147
|
/** On-demand tool family text; empty inherits the preset's shipped list. */
|
|
138
148
|
pagedToolPatterns: string
|
|
149
|
+
/** Deferred idle-reclaim threshold in steps; 0 keeps the shipped resident behavior. */
|
|
150
|
+
idleReclaimSteps: number
|
|
139
151
|
}
|
|
140
152
|
|
|
141
153
|
/** Schema defaults, re-read for hand-built test contexts. */
|
|
@@ -145,6 +157,7 @@ export const DEFAULT_CONFIG: ResolvedConfig = {
|
|
|
145
157
|
presentation: 'ptc',
|
|
146
158
|
dispatcher: true,
|
|
147
159
|
pagedToolPatterns: '',
|
|
160
|
+
idleReclaimSteps: 0,
|
|
148
161
|
}
|
|
149
162
|
|
|
150
163
|
/**
|
|
@@ -173,11 +186,12 @@ export function resolveConfig(config?: Config): ResolvedConfig {
|
|
|
173
186
|
presentation: rawPresentation === 'both' ? 'ptc' : rawPresentation,
|
|
174
187
|
dispatcher: readField(config?.dispatcher, DEFAULT_CONFIG.dispatcher),
|
|
175
188
|
pagedToolPatterns: readField(config?.pagedToolPatterns, DEFAULT_CONFIG.pagedToolPatterns),
|
|
189
|
+
idleReclaimSteps: readField(config?.idleReclaimSteps, DEFAULT_CONFIG.idleReclaimSteps),
|
|
176
190
|
}
|
|
177
191
|
}
|
|
178
192
|
|
|
179
193
|
/** Model-facing announcement: plugin presence, principle, and limits. */
|
|
180
|
-
export const LIANGSHEN_GUIDANCE = '本机已安装 dsh-liangshen 插件(梁神模式 agent preset):新建会话的预设选择器中可选「梁神模式」。原理:系统提示词保持极简 persona(minimal-prompt 放行该段与 plan 模式的 plan:policy),persona 内置本模式工作纪律(反思熔断——同一假设推演不超过两轮、缺事实立即闭合思考并调用原生检测工具;行动导向——思考只决定下一步具体操作、不在思考中预演代码实现;并发探索——多处独立检查或搜索在单轮内并发发射多个工具调用;YAGNI/PDCA——单步验证单一假设、不写冗余注释;有界收敛——不无限下钻依赖链、前置检查最多2-3轮后立即收敛并作答或编辑),并在组装时追加工作区目录行 Your working directory is <cwd>.。AGENTS.md 工作区指令默认交还宿主自身的 agent-instructions 行,以 user 角色注入,本插件不追加任何系统提示词段、也不改动 pre-step 的消息批次;可选 instructionSource: system-prompt 才由本插件在组装时读取 AGENTS.md 链并追加 workspace-instructions 段(65536 字节预算,每次组装重读)。wire 呈现由 tool-catalog 按会话一次声明,取值 \'ptc\'(默认:wire 收拢为唯一的 run_code,其余工具经生成的 SDK 调用)或 \'native\'(组装出的原生清单,无程序化传输),并可在插件设置界面切换(写入所声明预设的 tool-catalog 行);未挂载 code runtime 时不做声明,会话运行原生工具面。按需工具族出厂开启(pagedToolPatterns 默认 [\'mcp__*\', \'browser_*\', \'task_board_*\', \'team_*\', \'squad*\', \'ui_*\', \'ssh_*\'],可在插件设置的「按需工具族」中用逗号分隔的前缀改写):匹配工具在激活前被作用域级工具限制移出可见面(既不在 wire,也不在生成的 SDK 声明中),目录消息列出常驻工具签名与未激活命名空间摘要,调用 tool_activate({ namespace }) 按需激活(LRU 上限 3 个活跃命名空间,驱逐最久未用);激活状态从持久会话事件流重建,resume
|
|
194
|
+
export const LIANGSHEN_GUIDANCE = '本机已安装 dsh-liangshen 插件(梁神模式 agent preset):新建会话的预设选择器中可选「梁神模式」。原理:系统提示词保持极简 persona(minimal-prompt 放行该段与 plan 模式的 plan:policy),persona 内置本模式工作纪律(反思熔断——同一假设推演不超过两轮、缺事实立即闭合思考并调用原生检测工具;行动导向——思考只决定下一步具体操作、不在思考中预演代码实现;并发探索——多处独立检查或搜索在单轮内并发发射多个工具调用;YAGNI/PDCA——单步验证单一假设、不写冗余注释;有界收敛——不无限下钻依赖链、前置检查最多2-3轮后立即收敛并作答或编辑),并在组装时追加工作区目录行 Your working directory is <cwd>.。AGENTS.md 工作区指令默认交还宿主自身的 agent-instructions 行,以 user 角色注入,本插件不追加任何系统提示词段、也不改动 pre-step 的消息批次;可选 instructionSource: system-prompt 才由本插件在组装时读取 AGENTS.md 链并追加 workspace-instructions 段(65536 字节预算,每次组装重读)。wire 呈现由 tool-catalog 按会话一次声明,取值 \'ptc\'(默认:wire 收拢为唯一的 run_code,其余工具经生成的 SDK 调用)或 \'native\'(组装出的原生清单,无程序化传输),并可在插件设置界面切换(写入所声明预设的 tool-catalog 行);未挂载 code runtime 时不做声明,会话运行原生工具面。按需工具族出厂开启(pagedToolPatterns 默认 [\'mcp__*\', \'browser_*\', \'task_board_*\', \'team_*\', \'squad*\', \'ui_*\', \'ssh_*\'],可在插件设置的「按需工具族」中用逗号分隔的前缀改写):匹配工具在激活前被作用域级工具限制移出可见面(既不在 wire,也不在生成的 SDK 声明中),目录消息列出常驻工具签名与未激活命名空间摘要,调用 tool_activate({ namespace }) 按需激活(LRU 上限 3 个活跃命名空间,驱逐最久未用);激活状态从持久会话事件流重建,resume/压缩后自然恢复。可选 idleReclaimSteps(设置「空闲收回步数」,默认 0=不收回)让连续 N 步无成功调用的已激活命名空间过期,但只在下次激活或压缩时延迟收回——这些时机前缀缓存本就要重建,因此不新增任何全量重建;应用前命名空间仍常驻可达,再次调用即续命。关键事实登记簿(fact_register)让模型把硬约束/已确认决策/失败路径登记为单行事实,随 working-context 行每步投射进局部注意力窗口。working-context 插件在 pre-step 注入单行 [Working Context: ...] 就近状态投射(plan 模式、活跃命名空间、进行中 todo、登记事实,全部从事件流折叠,读不到则省略,全部为空则不注入)。历史工具结果修剪为 4096 字符阈值(head 2048 / tail 1024)。文件操作受宿主沙箱约束;shell 在每个平台都挂上游标准 Stdio 栈(POSIX 为 bash,Windows 为 pwsh),带简短描述标题卡片与确定性退出码。真实推理探针通过不等于模式集成通过,更不等于统计效果提升。预设由插件在激活时向 agent-preset registry 直接注册(不写任何预设目录),插件停用即注销;默认预设由用户自行选择。用户提到「梁神模式 / 锚定模式 / anchored standard」时即指本插件,请据此协作。'
|
|
181
195
|
|
|
182
196
|
/** Order of the announcement section within the tool-guidance band. */
|
|
183
197
|
const SECTION_ORDER = 150
|