* feat(release): publish package source, declaration maps, and documentation Every release member publishes its TypeScript source and the declaration maps that resolve into it, and @deepseek-ai/dsh publishes the repository Markdown documentation staged from docs/ at prepack time. The ./src/* export most members already declared now resolves for an installed consumer, and a consumer editor follows a declaration to the implementation. Bundled JavaScript maps stay unpublished; the vendored family and the Desktop runtime file policy are unchanged. Rationale: .agents/notes/implemented/process/2026-10-08-published-source-and-docs.md * feat(release): publish JavaScript maps and compress bundles Every emitted JavaScript map ships beside the bundle it describes, and the workspace build and the client preset compress bundles without mangling identifiers. The documentation payload now mirrors the website publication manifest and is removed again by `postpack`; Desktop and the Python executable exclude the published source, documentation, and maps; `clean` removes a staged copy. Typert's publication contract gains the Remote declaration map. * fix(release): keep node bundles readable for the worker image The browser worker image lowers `yield*` only as a whole statement and rewrites `for await` loops by their source layout, so compressed node-side entries either fail that lowering or lower to unparseable code. Only the browser bundles keep compression, which removes about a third of their text. The bundle-purity assertion now matches the module-loader call regardless of the quote style compression picks, and the release-pack fixture exercises the installed package's new documentation requirement. * feat(release): publish the whole documentation tree `@deepseek-ai/dsh` copies `docs/` in full instead of the website's page set: the maintainer documents, the generated migration records, the translation guidelines, and the `*.i18n.yaml` consistency records ship with the installed package, so the documentation's own links resolve without a checkout. * feat(release): publish the upgrade guides with the documentation The staged documentation keeps the website's page set and adds every `docs/upgrade-guide/` document, which is what an installed reader consults when a released change breaks something. The rest of the maintainer tree stays out. * test(release): expect source and maps in master's new payload cases * feat(release): keep installed docs and source readable in Desktop Desktop keeps the published src/ and docs/ trees inside app.asar, and every model shell call receives DSH_INSTALL_DIR and DSH_NODE_EXECUTABLE so an agent can read them through Electron's Node mode. Staging also generates docs/upgrade-guide/README.md, an index of the upgrade guides grouped by the release they upgrade from. Minified client bundles print string literals with backticks: the worker image packer now recognizes those chunk requests, client license banners are prepended after minification so their text survives, and the affected artifact tests accept either quote. * test(desktop): read archived docs through the Windows PowerShell form Regenerate the config catalog for the shifted shell-env source line. * test(desktop): wait for the GUI-subsystem Electron process from PowerShell * build(release): publish source and maps from the message-quotes package * build(release): publish source and maps from packages new on master * build(release): publish source and maps from the tool-office package
222 lines
9.2 KiB
TypeScript
222 lines
9.2 KiB
TypeScript
/**
|
|
* Tool-independent shell environment plugin: owns the `ctx.shellEnv` registry of
|
|
* trusted, per-execution `DSH_*` variables consumed by the model-facing shell
|
|
* tools (`dsh-tool-bash`, `dsh-tool-pwsh`). Built-in shell facts are owned by
|
|
* the registry itself while plugins can register additional, enumerable facts
|
|
* with effect-scoped disposal.
|
|
*
|
|
* @module @deepseek-ai/dsh-shell-env
|
|
*/
|
|
|
|
import { dirname } from 'node:path'
|
|
import { Service, type Context } from '@deepseek-ai/cordis'
|
|
import z from '@deepseek-ai/schemastery'
|
|
import { DSH_ENV_PREFIX } from '@deepseek-ai/dsh-shell'
|
|
import type { DshEnvironment, DshEnvironmentKey } from '@deepseek-ai/dsh-shell'
|
|
import { DSH_HOME_ENV, resolveDshHome } from '@deepseek-ai/dsh-home-paths'
|
|
import type { ToolExecution } from '@deepseek-ai/dsh-tools'
|
|
// Declares `Context.profileContext`, the launcher-provided profile the built-ins read.
|
|
import type {} from '@deepseek-ai/dsh-app-boot'
|
|
|
|
declare module '@deepseek-ai/cordis' {
|
|
interface Context {
|
|
shellEnv: ShellEnvRegistry
|
|
}
|
|
}
|
|
|
|
export const name = 'shell-env'
|
|
export const inject: string[] = []
|
|
|
|
/** Plugin config (all optional — the built-in facts resolve without defaults). */
|
|
export interface Config {
|
|
/** DeepSeek Harness home directory exposed as `DSH_HOME`; defaults to `$DSH_HOME` or `~/.dsh`. */
|
|
dshHome?: string
|
|
}
|
|
|
|
/** Runtime configuration schema for the shell-env plugin. */
|
|
export const Config: z<Config> = z.object({
|
|
dshHome: z.string(),
|
|
})
|
|
|
|
/** Model-visible metadata for one managed `DSH_*` environment variable. */
|
|
export interface BashEnvVariable {
|
|
/** Concise description of the environment fact represented by the variable. */
|
|
description: string
|
|
}
|
|
|
|
/**
|
|
* A plugin contribution to the managed environment of each model shell call.
|
|
* Declared keys make ownership conflicts detectable before the first command;
|
|
* `resolve` computes only the values available for the current execution.
|
|
*/
|
|
export interface BashEnvContributor {
|
|
/** Stable contributor name used in diagnostics and duplicate detection. */
|
|
name: string
|
|
/** Complete set of `DSH_*` keys this contributor may return. */
|
|
variables: Readonly<Record<DshEnvironmentKey, BashEnvVariable>>
|
|
/**
|
|
* Resolve this contributor's available values for one tool execution.
|
|
* @param execution - the shell tool execution and its optional calling agent.
|
|
* @returns a partial map containing only keys declared in {@link variables}.
|
|
*/
|
|
resolve(execution: ToolExecution): Readonly<Partial<Record<DshEnvironmentKey, string>>>
|
|
}
|
|
|
|
/** An enumerable declaration returned by {@link ShellEnvRegistry.list}. */
|
|
export interface BashEnvVariableInfo extends BashEnvVariable {
|
|
/** Contributor that owns the variable. */
|
|
contributor: string
|
|
/** Declared `DSH_*` environment variable name. */
|
|
key: DshEnvironmentKey
|
|
}
|
|
|
|
const DSH_SHELL_KEY = `${DSH_ENV_PREFIX}SHELL` as const
|
|
const DSH_SESSION_ID_KEY = `${DSH_ENV_PREFIX}SESSION_ID` as const
|
|
const DSH_PROFILE_KEY = `${DSH_ENV_PREFIX}PROFILE` as const
|
|
const DSH_PROFILE_DIR_KEY = `${DSH_ENV_PREFIX}PROFILE_DIR` as const
|
|
const DSH_INSTALL_DIR_KEY = `${DSH_ENV_PREFIX}INSTALL_DIR` as const
|
|
const DSH_NODE_EXECUTABLE_KEY = `${DSH_ENV_PREFIX}NODE_EXECUTABLE` as const
|
|
const RESERVED_BASH_ENV_KEYS = new Set<DshEnvironmentKey>([
|
|
DSH_HOME_ENV,
|
|
DSH_SHELL_KEY,
|
|
DSH_SESSION_ID_KEY,
|
|
DSH_PROFILE_KEY,
|
|
DSH_PROFILE_DIR_KEY,
|
|
DSH_INSTALL_DIR_KEY,
|
|
DSH_NODE_EXECUTABLE_KEY,
|
|
])
|
|
const BASH_ENV_KEY_SUFFIX = /^[A-Z][A-Z0-9_]*$/
|
|
|
|
/**
|
|
* Registry (`ctx.shellEnv`) for trusted, per-execution `DSH_*` variables.
|
|
* The namespace is rebuilt for every model shell call: ambient `DSH_*` values
|
|
* are discarded by the executor, then the registry's current snapshot is
|
|
* injected. Built-in shell facts remain owned by the registry itself while
|
|
* plugins can register additional, enumerable facts with effect-scoped
|
|
* disposal.
|
|
*/
|
|
export class ShellEnvRegistry extends Service {
|
|
private readonly contributors = new Map<string, BashEnvContributor>()
|
|
private readonly keyOwners = new Map<DshEnvironmentKey, string>()
|
|
private readonly dshHome: string
|
|
|
|
/**
|
|
* Create and install the `ctx.shellEnv` service.
|
|
* @param ctx - Cordis context that owns the service and registrations.
|
|
* @param config - home-directory configuration for the built-in variables.
|
|
*/
|
|
constructor(ctx: Context, config: Config = {}) {
|
|
super(ctx, 'shellEnv')
|
|
this.dshHome = resolveDshHome(config.dshHome)
|
|
}
|
|
|
|
/**
|
|
* Register one environment contributor. Names and keys are unique; built-in
|
|
* keys are reserved. Registration is disposed with the calling plugin fiber.
|
|
* @param contributor - declared key ownership and per-execution resolver.
|
|
* @returns the disposer that unregisters the contribution.
|
|
*/
|
|
register(contributor: BashEnvContributor): () => void {
|
|
const dispose = this.ctx.effect(function* (this: ShellEnvRegistry) {
|
|
if (contributor.name.trim().length === 0) {
|
|
throw new Error('bash env contributor name must be non-empty')
|
|
}
|
|
if (this.contributors.has(contributor.name)) {
|
|
throw new Error(`bash env contributor "${contributor.name}" is already registered`)
|
|
}
|
|
|
|
const variables = Object.entries(contributor.variables) as [DshEnvironmentKey, BashEnvVariable][]
|
|
for (const [key, variable] of variables) {
|
|
if (!key.startsWith(DSH_ENV_PREFIX)
|
|
|| !BASH_ENV_KEY_SUFFIX.test(key.slice(DSH_ENV_PREFIX.length))) {
|
|
throw new Error(`bash env contributor "${contributor.name}" declared invalid key "${key}"`)
|
|
}
|
|
if (RESERVED_BASH_ENV_KEYS.has(key)) {
|
|
throw new Error(`bash env contributor "${contributor.name}" cannot own reserved key "${key}"`)
|
|
}
|
|
if (variable.description.trim().length === 0) {
|
|
throw new Error(`bash env contributor "${contributor.name}" must describe "${key}"`)
|
|
}
|
|
const owner = this.keyOwners.get(key)
|
|
if (owner !== undefined) {
|
|
throw new Error(`bash env key "${key}" is already owned by contributor "${owner}"; contributor "${contributor.name}" cannot also own it`)
|
|
}
|
|
}
|
|
|
|
this.contributors.set(contributor.name, contributor)
|
|
for (const [key] of variables) this.keyOwners.set(key, contributor.name)
|
|
yield () => {
|
|
this.contributors.delete(contributor.name)
|
|
for (const [key] of variables) this.keyOwners.delete(key)
|
|
}
|
|
}.bind(this), 'bashEnv.register()')
|
|
return () => void dispose()
|
|
}
|
|
|
|
/**
|
|
* Build the trusted `DSH_*` snapshot for one shell tool execution.
|
|
* @param execution - the current tool execution.
|
|
* @returns an immutable environment overlay containing built-ins and current contributions.
|
|
*/
|
|
collect(execution: ToolExecution): DshEnvironment {
|
|
const values: Record<DshEnvironmentKey, string> = {
|
|
[DSH_HOME_ENV]: this.dshHome,
|
|
[DSH_SHELL_KEY]: '1',
|
|
}
|
|
// A single-executable application runs its embedded entry instead of a script argument. The
|
|
// browser worker image answers no `node:sea`, so the module is looked up at run time.
|
|
const sea = process.getBuiltinModule('node:sea') as typeof import('node:sea') | undefined
|
|
if (sea === undefined || !sea.isSea()) values[DSH_NODE_EXECUTABLE_KEY] = process.execPath
|
|
if (execution.agent !== undefined) {
|
|
values[DSH_SESSION_ID_KEY] = execution.agent.session.header.id
|
|
}
|
|
const profile = this.ctx.get('profileContext')
|
|
if (profile !== undefined) {
|
|
values[DSH_PROFILE_KEY] = profile.name
|
|
values[DSH_PROFILE_DIR_KEY] = profile.dir
|
|
values[DSH_INSTALL_DIR_KEY] = dirname(profile.installAnchor)
|
|
}
|
|
|
|
for (const contributor of [...this.contributors.values()].sort((left, right) => left.name.localeCompare(right.name))) {
|
|
const resolved = contributor.resolve(execution)
|
|
for (const [rawKey, value] of Object.entries(resolved)) {
|
|
const key = rawKey as DshEnvironmentKey
|
|
if (!Object.hasOwn(contributor.variables, key)) {
|
|
throw new Error(`bash env contributor "${contributor.name}" returned undeclared key "${key}"`)
|
|
}
|
|
if (typeof value !== 'string') {
|
|
throw new Error(`bash env contributor "${contributor.name}" returned a non-string value for "${key}"`)
|
|
}
|
|
values[key] = value
|
|
}
|
|
}
|
|
|
|
return Object.freeze(Object.fromEntries(Object.entries(values).sort(([left], [right]) => left.localeCompare(right))))
|
|
}
|
|
|
|
// TODO(bash-env-list-builtins): Include registry-owned built-ins before diagnostics,
|
|
// prompt, or UI code treats list() as an exhaustive environment catalog.
|
|
/**
|
|
* Enumerate plugin-contributed variables without executing their resolvers.
|
|
* @returns declarations sorted by environment variable name.
|
|
*/
|
|
list(): BashEnvVariableInfo[] {
|
|
return [...this.contributors.values()]
|
|
.flatMap(contributor => Object.entries(contributor.variables).map(([key, variable]) => ({
|
|
contributor: contributor.name,
|
|
description: variable.description,
|
|
key: key as DshEnvironmentKey,
|
|
})))
|
|
.sort((left, right) => left.key.localeCompare(right.key))
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Load the shell-env plugin: register the `ctx.shellEnv` registry service.
|
|
* @param ctx - Cordis context that owns the service and registrations.
|
|
* @param config - home-directory configuration for the built-in variables.
|
|
*/
|
|
export function apply(ctx: Context, config: Config = {}): void {
|
|
new ShellEnvRegistry(ctx, config)
|
|
}
|