/** * Running one `dsh plugin --profile …` invocation from the terminal. * * This is the whole mutation surface of `/profiles`, and it is deliberately a * forwarder rather than an implementation. Harness owns profile package * lifecycle in one place — `apps/cli/src/plugin.ts` — which initializes the * profile directory if it is new, runs pnpm inside it, and then reconciles * `dsh.profile.bundles` against the INSTALLED state (so a package that gained * its `dsh.bundle` declaration in a newer version joins the layer stack on * update). Reproducing any part of that here would be a second installer whose * idea of the bundle list drifts from the real one the moment either changes. * * There is no Harness service for profile mutation: `runPlugin` lives in the * CLI app, not in a mounted plugin, and nothing publishes it into a context. * So the operation still goes through Harness's own `dsh` executable, resolved * by `../launcher.ts` the same four ways `bin/dshline.mjs` resolves it. Process * ownership is a separate concern, though, and belongs to `ctx.subprocess`: * that seam owns executable lookup, environment policy, process trees, and * cross-platform termination for every Harness consumer. Its credential scrub * is narrowed here rather than undone — the child keeps what was set inside * the package managers' own namespaces plus the Host-resolved home, because * pnpm authenticates from the child's environment (`_authToken=${NPM_TOKEN}`), * while harness secrets stay scrubbed away from install scripts. * * Four things this module does that the CLI does not, all because a TUI owns * the terminal and a person is waiting: * * ``` * stdio is PIPED, never inherited `dsh plugin` uses stdio:'inherit'; a child * writing pnpm progress straight into a * screen this process is painting would * corrupt the live region * output is a ROLLING tail pnpm can emit megabytes; only the last few * lines are ever held, so a long install * cannot grow this process's memory with * text nobody will read * the timeout SETTLES the subprocess seam escalates termination; * this caller still classifies its own * deadline and stops waiting at a hard bound * specs are REDACTED for display a package spec can carry a token in a URL; * it is passed to the launcher verbatim and * never written to the transcript as-is * ``` * @module dshline/profiles/actions */ import type { SubprocessRuntime } from '@deepseek-ai/dsh-subprocess'; import { resolveLauncher } from '../launcher.ts'; import type { Launcher } from '../launcher.ts'; import type { ResolvedOperation } from './model.ts'; /** How one invocation ended, in words the transcript can carry. */ export interface ProfileActionOutcome { /** Whether the invocation succeeded. */ readonly kind: 'done' | 'failed'; /** What happened, already worded for a reader. */ readonly message: string; /** The tail of the child's own output, when it produced any. */ readonly output: readonly string[]; } /** What one child invocation answered. */ export interface ChildResult { /** The exit code, or a stand-in when the child never reported one. */ readonly code: number; /** The retained tail of its combined output. */ readonly output: string; } /** What {@link runProfileOperation} needs to run one invocation. */ export interface ProfileOperationSpec { /** The profile name the operation is addressed to. */ readonly profile: string; /** The resolved operation, from `model.ts`. */ readonly resolved: ResolvedOperation; /** Harness's process owner; absent only on an older or incomplete Host. */ readonly subprocess?: Pick; /** Resolved Harness home, explicitly restored after subprocess env scrubbing. */ readonly dshHome?: string; /** * Resolve the launcher; injected so a test drives the whole chain without a * launcher installed. */ readonly launcher?: () => ReturnType; /** * Spawn one child; injected for the same reason. Resolves with the child's * exit code and retained output, and never rejects. */ readonly run?: (launcher: Launcher, args: readonly string[]) => Promise; } /** * One line of child output, safe to commit. * * pnpm echoes the spec it was given, so a token that reached the launcher in a * URL reaches the transcript through the child's own output unless it is taken * out here. The transcript outlives the overlay and is the durable copy, which * is precisely why this is the place to do it. * @param line - one line as the child wrote it. * @returns the line with any embedded credential replaced. */ export declare function redactOutputLine(line: string): string; /** * The command line a reader could run themselves, quoted so it is true. * * A package spec may hold characters a shell would act on, so an argv list * pasted together with spaces is not the command that ran. Each argument that * needs it is single-quoted, which is what makes this safe to copy rather than * merely readable. * @param profile - the profile name. * @param args - the arguments after `--profile `. * @returns the command, safe to show and to paste. */ export declare function pluginCommand(profile: string, args: readonly string[]): string; /** Timings for one child, overridable so the bound itself can be tested. */ export interface ChildTimings { /** How long the child may run before it is stopped. */ readonly timeoutMs?: number; /** How long a stopped child is given to exit before it is killed outright. */ readonly killGraceMs?: number; } /** * Spawn one managed child with piped stdio, returning its code and retained output. * * Harness owns executable resolution, the isolated process tree, platform * signalling, and TERM-to-KILL escalation. This caller owns its deadline and * result vocabulary: after asking the handle to terminate it still resolves * independently if the provider cannot prove closure, because the profile lock * must not become an indefinite wait. * @param subprocess - Harness's process capability. * @param launcher - how to run the launcher. * @param args - the arguments after the launcher's own prefix. * @param timings - overrides for the bound; defaults are the module constants. * @param dshHome - resolved Harness home to restore after managed env scrubbing. * @returns the exit code and retained output; never rejects. */ export declare function spawnCaptured(subprocess: Pick, launcher: Launcher, args: readonly string[], timings?: ChildTimings, dshHome?: string): Promise; /** * The one line worth putting in the headline of a failure. * * "exited 1" is true and useless: a mistyped package name and an unreachable * git remote both exit 1, and the reader has to act differently on each. The * child already said which, so the headline says it too instead of making the * reader read the tail to find out what happened. * @param output - the child's retained output. * @returns the reason, or undefined when the child named none. */ export declare function failureReason(output: string): string | undefined; /** * The pending-decision note for a failure, when its reason names one. * @param reason - the failure reason, as {@link failureReason} found it. * @returns what the reader has to decide, or undefined. */ export declare function pendingDecision(reason: string | undefined): string | undefined; /** * Run one `dsh plugin` invocation against one profile. * * Never throws: a launcher that is not installed, one the user pointed * somewhere wrong, a child that fails, and a child that never answers are all * facts about the machine rather than defects in this browser, and each has to * reach the reader as an outcome. * @param spec - the profile, the operation, and the injectable seams. * @returns what happened. */ export declare function runProfileOperation(spec: ProfileOperationSpec): Promise; //# sourceMappingURL=actions.d.ts.map