@linxin666/dsh-win-bash 0.4.18 → 0.4.20
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 +8 -30
- package/README.zh.md +8 -20
- package/lib/index.js +11 -266
- package/lib/types/config.d.ts +0 -12
- package/lib/types/index.d.ts +16 -43
- package/package.json +7 -7
- package/src/config.ts +0 -18
- package/src/index.ts +25 -130
- package/lib/types/gate.d.ts +0 -179
- package/src/gate.ts +0 -308
package/src/config.ts
CHANGED
|
@@ -33,15 +33,6 @@ export const STDERR_MIN_BYTES = 1024
|
|
|
33
33
|
/** Visible stderr budget ceiling, in bytes. */
|
|
34
34
|
export const STDERR_MAX_BYTES = 512 * 1024
|
|
35
35
|
|
|
36
|
-
/**
|
|
37
|
-
* Whether win_bash follows the LiangShen agent preset's declaration by
|
|
38
|
-
* default. When true (the shipped setting) the tool registers only for a
|
|
39
|
-
* deployment that declares the `liangshen` preset; false skips the gate and
|
|
40
|
-
* always registers, which is the escape hatch for a session that wants this
|
|
41
|
-
* shell without the preset.
|
|
42
|
-
*/
|
|
43
|
-
export const DEFAULT_SYNC_WITH_LIANGSHEN = true
|
|
44
|
-
|
|
45
36
|
/**
|
|
46
37
|
* Model-facing tool description. Active voice; states the shell preference and
|
|
47
38
|
* the persistence guarantee, so a model knows which shell to reach for before
|
|
@@ -97,8 +88,6 @@ export interface WinBashConfigInput {
|
|
|
97
88
|
maxStderrBytes?: number
|
|
98
89
|
/** Model-facing tool description override. */
|
|
99
90
|
description?: string
|
|
100
|
-
/** Whether the tool's availability follows the LiangShen preset declaration. */
|
|
101
|
-
syncWithLiangShen?: boolean
|
|
102
91
|
/** Whether the host's pwsh tool is hidden while win_bash is registered. */
|
|
103
92
|
replacePwsh?: boolean
|
|
104
93
|
/** Whether run_in_background is available (also requires a job registry). */
|
|
@@ -115,8 +104,6 @@ export interface WinBashConfig {
|
|
|
115
104
|
maxStderrBytes: number
|
|
116
105
|
/** Model-facing tool description. */
|
|
117
106
|
description: string
|
|
118
|
-
/** Whether the tool's availability follows the LiangShen preset declaration. */
|
|
119
|
-
syncWithLiangShen: boolean
|
|
120
107
|
/** Whether the host's pwsh tool is hidden while win_bash is registered. */
|
|
121
108
|
replacePwsh: boolean
|
|
122
109
|
/** Whether run_in_background is available (also requires a job registry). */
|
|
@@ -129,7 +116,6 @@ export const Config: z<WinBashConfigInput, WinBashConfig> = z.object({
|
|
|
129
116
|
maxStdoutBytes: z.number().min(STDOUT_MIN_BYTES).max(STDOUT_MAX_BYTES).default(DEFAULT_MAX_STDOUT_BYTES),
|
|
130
117
|
maxStderrBytes: z.number().min(STDERR_MIN_BYTES).max(STDERR_MAX_BYTES).default(DEFAULT_MAX_STDERR_BYTES),
|
|
131
118
|
description: z.string().default(DEFAULT_DESCRIPTION),
|
|
132
|
-
syncWithLiangShen: z.boolean().default(DEFAULT_SYNC_WITH_LIANGSHEN),
|
|
133
119
|
replacePwsh: z.boolean().default(DEFAULT_REPLACE_PWSH),
|
|
134
120
|
enableRunInBackground: z.boolean().default(DEFAULT_ENABLE_RUN_IN_BACKGROUND),
|
|
135
121
|
})
|
|
@@ -140,7 +126,6 @@ export const CONFIG_DEFAULTS: WinBashConfig = {
|
|
|
140
126
|
maxStdoutBytes: DEFAULT_MAX_STDOUT_BYTES,
|
|
141
127
|
maxStderrBytes: DEFAULT_MAX_STDERR_BYTES,
|
|
142
128
|
description: DEFAULT_DESCRIPTION,
|
|
143
|
-
syncWithLiangShen: DEFAULT_SYNC_WITH_LIANGSHEN,
|
|
144
129
|
replacePwsh: DEFAULT_REPLACE_PWSH,
|
|
145
130
|
enableRunInBackground: DEFAULT_ENABLE_RUN_IN_BACKGROUND,
|
|
146
131
|
}
|
|
@@ -196,9 +181,6 @@ export function validateConfig(config: WinBashConfig): ConfigViolation[] {
|
|
|
196
181
|
if (typeof config.description !== 'string' || config.description.trim() === '') {
|
|
197
182
|
violations.push({ field: 'description', message: 'must be a non-empty string' })
|
|
198
183
|
}
|
|
199
|
-
if (typeof config.syncWithLiangShen !== 'boolean') {
|
|
200
|
-
violations.push({ field: 'syncWithLiangShen', message: 'must be a boolean' })
|
|
201
|
-
}
|
|
202
184
|
if (typeof config.replacePwsh !== 'boolean') {
|
|
203
185
|
violations.push({ field: 'replacePwsh', message: 'must be a boolean' })
|
|
204
186
|
}
|
package/src/index.ts
CHANGED
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
* or no safe root at all, keeps the tool working from the packaged tree and
|
|
26
26
|
* logs that updates will need this host stopped.
|
|
27
27
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* config
|
|
33
|
-
*
|
|
34
|
-
*
|
|
28
|
+
* Registration: on a supported Windows x64 host the tool registers as soon as
|
|
29
|
+
* the payload verifies and the config resolves — availability follows the
|
|
30
|
+
* platform, the shipped payload and the configuration alone, with no preset
|
|
31
|
+
* registry read. apply() registers synchronously; a failed payload check
|
|
32
|
+
* refuses the mount, a config error is thrown, and a tool-registry refusal is
|
|
33
|
+
* caught and logged so it never escapes apply as an unhandled rejection.
|
|
34
|
+
* A retired availability key left in an old profile row is ignored, not rejected.
|
|
35
35
|
*
|
|
36
36
|
* Host shell replacement: once win_bash is registered, the host's own pwsh
|
|
37
37
|
* tool is withdrawn from each session win_bash can actually SERVE - the
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
*
|
|
45
45
|
* Lifecycle: one shell process per calling agent, released when that agent is
|
|
46
46
|
* disposed and when the plugin fiber unloads. The pwsh restriction follows the
|
|
47
|
-
* same lifecycle, lifted with the agent and with the fiber. apply()
|
|
48
|
-
*
|
|
49
|
-
*
|
|
47
|
+
* same lifecycle, lifted with the agent and with the fiber. apply() registers
|
|
48
|
+
* the tool directly once the payload and config check out; a tool-registry
|
|
49
|
+
* failure is logged rather than escaping as an unhandled rejection.
|
|
50
50
|
* @module @linxin666/dsh-win-bash
|
|
51
51
|
*/
|
|
52
52
|
|
|
@@ -56,7 +56,6 @@ import type {} from '@deepseek-ai/dsh-sandbox'
|
|
|
56
56
|
import type {} from '@deepseek-ai/dsh-subprocess'
|
|
57
57
|
import type {} from '@deepseek-ai/dsh-tools'
|
|
58
58
|
import { Config, resolveConfig, type WinBashConfig, type WinBashConfigInput } from './config.ts'
|
|
59
|
-
import { startLiangShenGate, LIANGSHEN_PRESET_ID, type GateOptions, type GateOutcome } from './gate.ts'
|
|
60
59
|
import { installPwshReplacement } from './pwsh-replacement.ts'
|
|
61
60
|
import { prepareRuntime, type RuntimeReady, type HostPlatform } from './runtime.ts'
|
|
62
61
|
import { ShellRegistry, sweepOrphanShellTempDirs } from './shell.ts'
|
|
@@ -80,7 +79,6 @@ export {
|
|
|
80
79
|
DEFAULT_DESCRIPTION,
|
|
81
80
|
DEFAULT_ENABLE_RUN_IN_BACKGROUND,
|
|
82
81
|
DEFAULT_REPLACE_PWSH,
|
|
83
|
-
DEFAULT_SYNC_WITH_LIANGSHEN,
|
|
84
82
|
validateConfig,
|
|
85
83
|
} from './config.ts'
|
|
86
84
|
export {
|
|
@@ -106,23 +104,6 @@ export {
|
|
|
106
104
|
type ShellTempSweepOptions,
|
|
107
105
|
} from './shell.ts'
|
|
108
106
|
export { buildFrame, markerFor, parseFrame } from './protocol.ts'
|
|
109
|
-
export {
|
|
110
|
-
GATE_DECLARATION_WAIT_MS,
|
|
111
|
-
GATE_POLL_INTERVAL_MS,
|
|
112
|
-
GATE_READ_TIMEOUT_MS,
|
|
113
|
-
GATE_SETTLE_TIMEOUT_MS,
|
|
114
|
-
LIANGSHEN_PRESET_ID,
|
|
115
|
-
declaresLiangShen,
|
|
116
|
-
readPresetRegistry,
|
|
117
|
-
settleHostTree,
|
|
118
|
-
startLiangShenGate,
|
|
119
|
-
type GateOptions,
|
|
120
|
-
type GateOutcome,
|
|
121
|
-
type GateReason,
|
|
122
|
-
type PresetRosterReader,
|
|
123
|
-
type PresetRosterRow,
|
|
124
|
-
type SettleStatus,
|
|
125
|
-
} from './gate.ts'
|
|
126
107
|
export {
|
|
127
108
|
CACHE_DIR_PARTS,
|
|
128
109
|
CACHE_STAGING_PREFIX,
|
|
@@ -152,37 +133,15 @@ export const name = 'dsh-win-bash'
|
|
|
152
133
|
/** Required services: the tool registry and the managed subprocess seam. */
|
|
153
134
|
export const inject = ['tools', 'subprocess']
|
|
154
135
|
|
|
155
|
-
/**
|
|
156
|
-
* One human-readable line explaining a refused gate verdict.
|
|
157
|
-
* @param outcome - the gate's verdict.
|
|
158
|
-
* @returns the message the entry logs.
|
|
159
|
-
*/
|
|
160
|
-
export function gateRefusalMessage(outcome: GateOutcome): string {
|
|
161
|
-
const settleNote = outcome.settled === 'timed-out'
|
|
162
|
-
? '; the host plugin tree did not settle in time, so the roster was read during boot'
|
|
163
|
-
: ''
|
|
164
|
-
if (outcome.reason === 'registry-absent') {
|
|
165
|
-
return 'win_bash was not registered (syncWithLiangShen is on and this deployment publishes no agent-preset registry,'
|
|
166
|
-
+ ' so a preset with id ' + LIANGSHEN_PRESET_ID + ' cannot be declared)' + settleNote
|
|
167
|
-
}
|
|
168
|
-
if (outcome.reason === 'registry-unreadable') {
|
|
169
|
-
return 'win_bash was not registered (syncWithLiangShen is on and the agent-preset registry roster could not be read)'
|
|
170
|
-
+ settleNote
|
|
171
|
-
}
|
|
172
|
-
return 'win_bash was not registered (syncWithLiangShen is on and no preset with id '
|
|
173
|
-
+ LIANGSHEN_PRESET_ID + ' is declared; enable the dsh-liangshen plugin row, or set syncWithLiangShen to false to'
|
|
174
|
-
+ ' register this shell without the preset)' + settleNote
|
|
175
|
-
}
|
|
176
|
-
|
|
177
136
|
/**
|
|
178
137
|
* Register the win_bash tool and its per-session shell registry on the calling
|
|
179
138
|
* fiber. Called only once per fiber: the caller decides whether to call at all.
|
|
180
139
|
*
|
|
181
|
-
* The host pwsh replacement is installed from HERE and not from
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
140
|
+
* The host pwsh replacement is installed from HERE and not from apply, because
|
|
141
|
+
* its precondition is exactly "win_bash is now on the wire": a deployment whose
|
|
142
|
+
* payload failed verification, whose config was rejected, or that runs on a
|
|
143
|
+
* POSIX host never reaches this function and therefore never touches the host's
|
|
144
|
+
* shell.
|
|
186
145
|
* @param ctx - context carrying tools and subprocess.
|
|
187
146
|
* @param config - the resolved configuration.
|
|
188
147
|
* @param runtime - the verified payload paths.
|
|
@@ -211,73 +170,6 @@ export function registerWinBash(ctx: Context, config: WinBashConfig, runtime: Ru
|
|
|
211
170
|
if (config.replacePwsh) installPwshReplacement(ctx)
|
|
212
171
|
}
|
|
213
172
|
|
|
214
|
-
/**
|
|
215
|
-
* Apply the availability gate, then register the tool when it allows it.
|
|
216
|
-
*
|
|
217
|
-
* The returned promise is deliberately NOT awaited by apply: the gate's roster
|
|
218
|
-
* read audits every declared preset and can await the Host loader tree, which
|
|
219
|
-
* still counts this very activation among its pending tasks — awaiting it from
|
|
220
|
-
* inside the activation would make the two waits depend on each other and
|
|
221
|
-
* neither would settle. Keeping the decision off the activation path also
|
|
222
|
-
* keeps the loader entry's own inertia free of it, so the tree can settle.
|
|
223
|
-
*
|
|
224
|
-
* A fiber disposed while the gate was deciding registers nothing: its tool
|
|
225
|
-
* effect would be refused anyway, and its shells would outlive it.
|
|
226
|
-
* @param ctx - context carrying tools and subprocess.
|
|
227
|
-
* @param config - the resolved configuration.
|
|
228
|
-
* @param runtime - the verified payload paths.
|
|
229
|
-
* @param options - gate deadlines; the defaults are the shipped bounds.
|
|
230
|
-
* @returns the decision, for the caller to observe (never rejects).
|
|
231
|
-
*/
|
|
232
|
-
export async function mountWithGate(
|
|
233
|
-
ctx: Context,
|
|
234
|
-
config: WinBashConfig,
|
|
235
|
-
runtime: RuntimeReady,
|
|
236
|
-
options: GateOptions = {},
|
|
237
|
-
): Promise<void> {
|
|
238
|
-
let closed = false
|
|
239
|
-
ctx.effect(() => () => { closed = true }, 'dsh-win-bash: gate continuation lifetime')
|
|
240
|
-
|
|
241
|
-
const mount = (announcement?: string): void => {
|
|
242
|
-
if (announcement !== undefined) ctx.logger?.info?.(announcement)
|
|
243
|
-
// Registration is deliberately OUTSIDE the gate's try: a tool registry that
|
|
244
|
-
// refuses the registration is not a gate defect, and reporting it as one
|
|
245
|
-
// would send an operator to the wrong place. It must also not escape as a
|
|
246
|
-
// rejection, because this continuation is not awaited by the loader's own
|
|
247
|
-
// activation and an unhandled rejection here kills the whole process.
|
|
248
|
-
try {
|
|
249
|
-
registerWinBash(ctx, config, runtime)
|
|
250
|
-
} catch (error) {
|
|
251
|
-
ctx.logger?.error?.('dsh-win-bash: win_bash could not be registered: '
|
|
252
|
-
+ (error instanceof Error ? error.message : String(error)))
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if (!config.syncWithLiangShen) {
|
|
257
|
-
mount()
|
|
258
|
-
return
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
let outcome: GateOutcome
|
|
262
|
-
try {
|
|
263
|
-
outcome = await startLiangShenGate(ctx, options)
|
|
264
|
-
} catch (error) {
|
|
265
|
-
// The gate contains its own failures; this arm keeps a defect in it from
|
|
266
|
-
// escaping as an unhandled rejection, which the host's fail-loud guard
|
|
267
|
-
// turns into a whole-process kill.
|
|
268
|
-
if (closed) return
|
|
269
|
-
ctx.logger?.warn?.('dsh-win-bash: win_bash was not registered (the LiangShen availability gate failed: '
|
|
270
|
-
+ (error instanceof Error ? error.message : String(error)) + ')')
|
|
271
|
-
return
|
|
272
|
-
}
|
|
273
|
-
if (closed) return
|
|
274
|
-
if (!outcome.allowed) {
|
|
275
|
-
ctx.logger?.info?.('dsh-win-bash: ' + gateRefusalMessage(outcome))
|
|
276
|
-
return
|
|
277
|
-
}
|
|
278
|
-
mount('dsh-win-bash: win_bash registered (the ' + LIANGSHEN_PRESET_ID + ' preset is declared)')
|
|
279
|
-
}
|
|
280
|
-
|
|
281
173
|
/**
|
|
282
174
|
* Mount the plugin.
|
|
283
175
|
* @param ctx - context carrying tools and subprocess.
|
|
@@ -311,8 +203,8 @@ export function apply(ctx: Context, config?: WinBashConfigInput): void {
|
|
|
311
203
|
// those directories are not small - whatever the commands wrote under TMP/TEMP
|
|
312
204
|
// is still in them. Their names carry the owning pid, so this start can tell
|
|
313
205
|
// which ones nobody owns any more; the sweep keeps the ones whose pid still
|
|
314
|
-
// runs. Detached
|
|
315
|
-
//
|
|
206
|
+
// runs. Detached and self-contained, because an unreclaimed directory must
|
|
207
|
+
// never keep the plugin from mounting.
|
|
316
208
|
void sweepOrphanShellTempDirs().then((sweep) => {
|
|
317
209
|
if (sweep.removed.length > 0) {
|
|
318
210
|
ctx.logger?.info?.('dsh-win-bash: reclaimed ' + sweep.removed.length.toString()
|
|
@@ -327,10 +219,13 @@ export function apply(ctx: Context, config?: WinBashConfigInput): void {
|
|
|
327
219
|
ctx.logger?.warn?.('dsh-win-bash: the orphaned shell temp directory sweep failed: '
|
|
328
220
|
+ (error instanceof Error ? error.message : String(error)))
|
|
329
221
|
})
|
|
330
|
-
//
|
|
331
|
-
//
|
|
332
|
-
|
|
333
|
-
|
|
222
|
+
// Registration is caught here rather than left to escape: apply runs on the
|
|
223
|
+
// loader's activation path, and a registration refusal that surfaced as a
|
|
224
|
+
// rejection would fail the whole web boot instead of this one tool.
|
|
225
|
+
try {
|
|
226
|
+
registerWinBash(ctx, resolved, runtime)
|
|
227
|
+
} catch (error) {
|
|
228
|
+
ctx.logger?.error?.('dsh-win-bash: win_bash could not be registered: '
|
|
334
229
|
+ (error instanceof Error ? error.message : String(error)))
|
|
335
|
-
}
|
|
230
|
+
}
|
|
336
231
|
}
|
package/lib/types/gate.d.ts
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LiangShen availability gate for the win_bash tool.
|
|
3
|
-
*
|
|
4
|
-
* win_bash serves sessions that run the LiangShen (梁神) preset, so its
|
|
5
|
-
* availability follows that preset's DECLARATION: this gate asks the harness's
|
|
6
|
-
* agent-preset registry whether a preset with id liangshen is declared, and the
|
|
7
|
-
* entry registers no tool at all when it is not. The alternative — mounting a
|
|
8
|
-
* tool whose every call refuses — teaches the model a capability the session
|
|
9
|
-
* does not have, which is worse than an honest absence.
|
|
10
|
-
*
|
|
11
|
-
* The registry read is STRUCTURAL, not an import: this package does not depend
|
|
12
|
-
* on @deepseek-ai/dsh-agent-preset-registry (a leaf plugin takes no SDK
|
|
13
|
-
* dependency to read one optional service), so the single method consumed is
|
|
14
|
-
* mirrored from the published declaration of
|
|
15
|
-
* @deepseek-ai/dsh-agent-preset-registry@0.2.2-rc.1, lib/types/index.d.ts:
|
|
16
|
-
*
|
|
17
|
-
* export declare class AgentPresetRegistry {
|
|
18
|
-
* list(): Promise<AgentPreset[]>
|
|
19
|
-
* }
|
|
20
|
-
* export interface AgentPreset {
|
|
21
|
-
* readonly id: string
|
|
22
|
-
* readonly name?: string
|
|
23
|
-
* readonly broken?: string
|
|
24
|
-
* }
|
|
25
|
-
*
|
|
26
|
-
* list() is the registry's public DEFINITION roster: it resolves every declared
|
|
27
|
-
* definition, including activation failures (which each row reports), so it
|
|
28
|
-
* answers exactly the "is this preset declared here" question. The narrower
|
|
29
|
-
* resolve(id) cannot: it REJECTS for an undeclared id, so a probe built on it
|
|
30
|
-
* would have to read a rejection as "absent" and could not tell that apart from
|
|
31
|
-
* a real failure of a preset that IS declared.
|
|
32
|
-
*
|
|
33
|
-
* The service is read with ctx.get, never a hard inject: a deployment may
|
|
34
|
-
* compose no preset registry at all, and waiting on one would pend this row
|
|
35
|
-
* forever — which under the Host's boot gate fails the whole web boot rather
|
|
36
|
-
* than this one plugin (the trap dsh-liangshen documents as issue #1712).
|
|
37
|
-
*
|
|
38
|
-
* Timing. Two facts about the pieces this talks to shape the verdict:
|
|
39
|
-
*
|
|
40
|
-
* 1. Rows in one loader group mount concurrently (the loader starts every entry
|
|
41
|
-
* of a group in the same tick), so this row cannot assume the LiangShen row
|
|
42
|
-
* ran first. The verdict therefore waits for the Host plugin tree to settle
|
|
43
|
-
* before its first read, rather than reading during the boot race.
|
|
44
|
-
* 2. The declaration does not arrive with that row's activation return: the
|
|
45
|
-
* declaring plugin schedules it on its own detached promise chain (it
|
|
46
|
-
* persists module rows, so it cannot block activation on the mount). The
|
|
47
|
-
* tree can therefore settle one or more turns BEFORE the registry holds the
|
|
48
|
-
* definition, and a single read would answer "not declared" for a
|
|
49
|
-
* deployment that is about to declare it.
|
|
50
|
-
*
|
|
51
|
-
* So a read that already sees the declaration decides immediately and costs
|
|
52
|
-
* nothing; a read that does not re-reads on a bounded schedule until the
|
|
53
|
-
* declaration appears or the deadline passes. The wait is never paid in the
|
|
54
|
-
* common case, and it never turns a late declaration into a refusal. It runs
|
|
55
|
-
* entirely off the plugin's activation path (see the entry), so it delays no
|
|
56
|
-
* boot work; it only decides when win_bash becomes available.
|
|
57
|
-
*
|
|
58
|
-
* The registry exposes NO declaration-change event. Its only declared preset
|
|
59
|
-
* event is agent-preset/selected, which records one SESSION's committed preset
|
|
60
|
-
* to that session's durable log (lib/types/types.d.ts) and says nothing about
|
|
61
|
-
* the roster. The verdict is therefore decided once per mount, and a switch
|
|
62
|
-
* toggle takes effect through the plugin manager's row refresh, which remounts
|
|
63
|
-
* this row and re-runs the gate — the same freshness model the family's row
|
|
64
|
-
* ledger uses.
|
|
65
|
-
* @module @linxin666/dsh-win-bash/gate
|
|
66
|
-
*/
|
|
67
|
-
import type { Context } from '@deepseek-ai/cordis';
|
|
68
|
-
/** Preset id whose declaration makes win_bash available. */
|
|
69
|
-
export declare const LIANGSHEN_PRESET_ID = "liangshen";
|
|
70
|
-
/** Upper bound on the wait for the Host plugin tree to settle, in milliseconds. */
|
|
71
|
-
export declare const GATE_SETTLE_TIMEOUT_MS = 10000;
|
|
72
|
-
/** Upper bound on one registry roster read, in milliseconds. */
|
|
73
|
-
export declare const GATE_READ_TIMEOUT_MS = 10000;
|
|
74
|
-
/**
|
|
75
|
-
* How long a roster that does not yet declare LiangShen keeps being re-read,
|
|
76
|
-
* in milliseconds. See the module header: the declaring plugin publishes the
|
|
77
|
-
* definition on a detached chain, so the tree can settle first. Only paid when
|
|
78
|
-
* the declaration is genuinely absent, since a visible one returns at once.
|
|
79
|
-
*/
|
|
80
|
-
export declare const GATE_DECLARATION_WAIT_MS = 5000;
|
|
81
|
-
/** Re-read cadence during {@link GATE_DECLARATION_WAIT_MS}, in milliseconds. */
|
|
82
|
-
export declare const GATE_POLL_INTERVAL_MS = 250;
|
|
83
|
-
/**
|
|
84
|
-
* The deadlines and cadence one gate run uses. The defaults are the shipped
|
|
85
|
-
* values; tests pass small ones so a bounded wait is exercised without a slow
|
|
86
|
-
* suite.
|
|
87
|
-
*/
|
|
88
|
-
export interface GateOptions {
|
|
89
|
-
/** Bound on the Host plugin-tree settle wait, in milliseconds. */
|
|
90
|
-
settleTimeoutMs?: number;
|
|
91
|
-
/** Bound on one registry roster read, in milliseconds. */
|
|
92
|
-
readTimeoutMs?: number;
|
|
93
|
-
/** Total time a late declaration may take to appear, in milliseconds. */
|
|
94
|
-
declarationWaitMs?: number;
|
|
95
|
-
/** Re-read cadence during that wait, in milliseconds. */
|
|
96
|
-
pollIntervalMs?: number;
|
|
97
|
-
}
|
|
98
|
-
/** One roster row, as much of it as this gate reads. */
|
|
99
|
-
export interface PresetRosterRow {
|
|
100
|
-
/** Stable preset identifier. */
|
|
101
|
-
readonly id: string;
|
|
102
|
-
}
|
|
103
|
-
/** The one registry method this gate consumes. */
|
|
104
|
-
export interface PresetRosterReader {
|
|
105
|
-
/** Read every declared preset, including activation failures. */
|
|
106
|
-
list(): Promise<readonly PresetRosterRow[]>;
|
|
107
|
-
}
|
|
108
|
-
/** Why the gate reached its verdict. */
|
|
109
|
-
export type GateReason =
|
|
110
|
-
/** The registry declares the LiangShen preset. */
|
|
111
|
-
'declared'
|
|
112
|
-
/** The registry answered and declares no preset with the LiangShen id. */
|
|
113
|
-
| 'not-declared'
|
|
114
|
-
/** No agent-preset registry usable for this read is published. */
|
|
115
|
-
| 'registry-absent'
|
|
116
|
-
/** A registry is published, but its roster never answered. */
|
|
117
|
-
| 'registry-unreadable';
|
|
118
|
-
/** How far the Host plugin-tree settle got before the roster was read. */
|
|
119
|
-
export type SettleStatus =
|
|
120
|
-
/** Every Host loader entry and plugin lifecycle task finished. */
|
|
121
|
-
'settled'
|
|
122
|
-
/** No loader service is published, so there was nothing to settle. */
|
|
123
|
-
| 'unavailable'
|
|
124
|
-
/** The tree did not settle within the settle bound. */
|
|
125
|
-
| 'timed-out';
|
|
126
|
-
/** The gate's verdict: whether win_bash may register, and why. */
|
|
127
|
-
export interface GateOutcome {
|
|
128
|
-
/** True only for {@link GateReason} declared. */
|
|
129
|
-
readonly allowed: boolean;
|
|
130
|
-
/** The reason, for the caller's log line. */
|
|
131
|
-
readonly reason: GateReason;
|
|
132
|
-
/** Whether the Host tree settled before the roster was read. */
|
|
133
|
-
readonly settled: SettleStatus;
|
|
134
|
-
/** How many roster reads the verdict cost. */
|
|
135
|
-
readonly reads: number;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Whether a roster declares the preset this tool follows.
|
|
139
|
-
* @param presets - rows as {@link PresetRosterReader.list} returns them.
|
|
140
|
-
* @returns true when one row carries the LiangShen id.
|
|
141
|
-
*/
|
|
142
|
-
export declare function declaresLiangShen(presets: readonly PresetRosterRow[]): boolean;
|
|
143
|
-
/**
|
|
144
|
-
* The published registry, when this deployment has one shaped like the one this
|
|
145
|
-
* gate consumes.
|
|
146
|
-
* @param ctx - the plugin context.
|
|
147
|
-
* @returns the reader, or undefined when no usable registry is published.
|
|
148
|
-
*/
|
|
149
|
-
export declare function readPresetRegistry(ctx: Context): PresetRosterReader | undefined;
|
|
150
|
-
/**
|
|
151
|
-
* Wait until the Host loader tree has no pending import or lifecycle work.
|
|
152
|
-
*
|
|
153
|
-
* Waiting for the whole tree rather than this row's neighbours is deliberate:
|
|
154
|
-
* the roster belongs to the deployment, not to one group, and the loader's own
|
|
155
|
-
* await() is the only predicate that means "every row has been applied". A row
|
|
156
|
-
* merely waiting for a service it will never get carries no pending task, so it
|
|
157
|
-
* cannot hold this wait open; one that is genuinely mid-activation can, which is
|
|
158
|
-
* exactly the case the bound covers.
|
|
159
|
-
* @param ctx - the plugin context.
|
|
160
|
-
* @param options - the deadlines for this run.
|
|
161
|
-
* @returns how far the settle got.
|
|
162
|
-
*/
|
|
163
|
-
export declare function settleHostTree(ctx: Context, options?: GateOptions): Promise<SettleStatus>;
|
|
164
|
-
/**
|
|
165
|
-
* Decide whether the LiangShen preset is declared in this deployment.
|
|
166
|
-
*
|
|
167
|
-
* Call this OFF the plugin's activation path — never awaited from a plugin
|
|
168
|
-
* apply. list() is not a leaf read: it audits every declared preset and, for one
|
|
169
|
-
* whose mounted subtree still has pending rows, awaits the Host loader tree
|
|
170
|
-
* (agent-preset-registry lib/index.js diagnostic). A plugin whose activation
|
|
171
|
-
* awaited this would wait on the loader tree while its OWN activation is among
|
|
172
|
-
* the tasks that tree is waiting for, and neither wait would ever settle. The
|
|
173
|
-
* entry calls this after its synchronous activation returned, which is what
|
|
174
|
-
* keeps this a wait and not a deadlock.
|
|
175
|
-
* @param ctx - the plugin context.
|
|
176
|
-
* @param options - the deadlines and cadence for this run.
|
|
177
|
-
* @returns the verdict, with the reason for the caller's log line.
|
|
178
|
-
*/
|
|
179
|
-
export declare function startLiangShenGate(ctx: Context, options?: GateOptions): Promise<GateOutcome>;
|