feat(loader): interpolate the entry disabled field

The Windows platform layer disables tool-bash and inserts the pwsh stack, but the shipped presets each mount a tool-bash row that re-enabled the tool on win32 — the session had both a PowerShell-backed bash tool and tool-pwsh, silently, because no spec pinned the composed preset layer.

The Loader now evaluates a disabled: !!js expression against the loader context at every mount decision; disabled is the only interpolated metadata field, and the raw node stays in the options so write-back keeps the !!js form. The standard/code/cordis presets gate tool-bash with process.platform === 'win32', verify-cordis-config allows expressions in disabled only, and the windows-shell spec pins the preset-level invariant.
This commit is contained in:
Huanqi Cao
2026-08-11 11:33:53 +08:00
parent db1028a84d
commit 6fb226ea24
16 changed files with 261 additions and 43 deletions

View File

@@ -3,7 +3,7 @@ import { deepEqual, isNullable } from '@deepseek-ai/cosmokit'
import { Loader } from '../index.ts'
import { EntryGroup } from './group.ts'
import { EntryTree } from './tree.ts'
import { evaluate } from './utils.ts'
import { evaluate, isJsExpr } from './utils.ts'
/** Static plugin hook for resolving a container config while preserving nested entry configs. */
export const EntryConfigResolver = Symbol.for('cordis.loader.entry-config-resolver')
@@ -101,15 +101,25 @@ export class Entry {
private _disabled(options: EntryOptions) {
// group is always enabled
if (options.group) return false
if (options.disabled && !this.runtimeEnabled) return true
if (this.disabledOf(options) && !this.runtimeEnabled) return true
let entry = this.parent.ctx.fiber.entry
while (entry) {
if (entry.options.disabled && !entry.runtimeEnabled) return true
if (this.disabledOf(entry.options) && !entry.runtimeEnabled) return true
entry = entry.parent.ctx.fiber.entry
}
return false
}
/**
* Effective disabled state: a `!!js` expression evaluates against the loader
* context. The raw node stays in the options, so write-back keeps the form.
*/
private disabledOf(options: EntryOptions): boolean {
return isJsExpr(options.disabled)
? Boolean(this.evaluate(options.disabled.__jsExpr))
: Boolean(options.disabled)
}
/**
* Enable this in-memory entry without rewriting its configured `disabled`
* value; the override survives config reapplication for this entry object.