Files
rea/src/ports/DesktopBuildHost.ts
T
Harsh Asalkarandmorluto 63c50ecfc0 feat(setup): discover project-scoped MCP registrations in doctor and … (#7283)
* feat(setup): discover project-scoped MCP registrations in doctor and uninstall

* fix(setup): preserve OpenCode layer fields, user launcher provenance, and user fallback

* fix(setup): restore working directory in tests and refine replacement and launcher provenance

* fix(setup): bound OpenCode discovery to worktree and enforce Pi project trust

* fix(setup): preserve Pi project trust failures in doctor and prevent skipping project registrations in uninstall

* fix(setup): defer cross-setting environment validation and decouple OpenCode launcher ownership

* fix(setup): separate OpenCode readiness schema from launcher ownership and fix cross-setting test

* fix(doctor): include project remediation when disabled project registration inherits outdated user launcher

* fix(setup): scope status properties to project-scoped registrations

Omit scope and launcher_scope when no project-level configuration was discovered or evaluated, ensuring user-level registrations retain their exact unextended status contract in isolated environments without project files.

* fix(setup): prevent activating unowned launchers during uninstall and align array normalization

Prevent activating unowned or foreign launchers hidden in lower-precedence configurations during project-scoped uninstall, normalize array command arguments uniformly in OpenCode ownership parsing without appending separate args, and clarify field inheritance in client configuration documentation.

* fix(setup): check effective remaining launcher on uninstall and preserve cleanup failure

* fix(uninstall): preserve user configuration path in project client to check fallback ownership

* fix(uninstall): scope fallback configuration paths only to project-scoped clients

* fix(doctor): validate effective merged Pi flags and preserve MSIX selection during uninstall

* fix(uninstall): preserve surviving OpenCode project registrations across complete configuration layers

* fix(uninstall): require surviving OpenCode server to carry a launcher when checking layered activation

* fix(uninstall): rely on full layered check for OpenCode instead of lower-only fallback

* fix(doctor): preserve source paths for inherited environment failures

When a trusted Pi project partial override or an OpenCode project registration inherits an invalid REA environment value from user configuration (or an ancestor configuration), attribute the resulting doctor invalid registration error to the contributing configuration source rather than the winning project file. Preserves source evidence provenance across merged configuration layers so doctor remediation points the user to the file that actually requires repair.

* test(doctor): exercise effective cross-setting merge failure in inherited environment tests

Replace scalar validation errors with cross-setting constraints (REA_GHIDRA_PROGRAM_NAME without REA_GHIDRA_PROJECT_PATH) in inherited environment regression tests so individual fragments pass and the failure is only triggered during effective layer merge, directly protecting contributingEnvironmentSource provenance lookup.

* fix(uninstall): allow cleaning up owned entries in untrusted Pi projects

Evaluate Pi project trust in unownedLowerLayerFallback so owned entries in untrusted Pi projects can be cleanly removed without falsely claiming that removal would activate an unowned user launcher.

* fix(uninstall): require confirmed untrusted decision to skip Pi fallback check

Only skip the unowned lower-layer fallback check when Pi project trust is confirmed untrusted (trust.ok && !trust.value). When Pi trust reading or parsing fails (!trust.ok), preserve the unresolved state and conservatively inspect the lower layer so that an unowned user launcher is not inadvertently exposed if the project was trusted.

* fix(doctor): track activation provenance across layers and normalize platform path identity

- Track activation source provenance (activationScope, activationConfigPath) across Pi and OpenCode configuration layers so activation drift remediation points to the exact file contributing the disable/enable flag rather than nearest fragment.
- Normalize path identity case-insensitively on Windows and macOS when deduplicating user configuration from OpenCode hierarchy and Pi project candidates.
- Qualify Pi project registration docs with trusted projects prerequisite and fallback semantics.

* fix(doctor): isolate platform casing tests and restore cwd mocks

* fix(doctor): use filesystem identity for path normalization and verify present files in case tests

* fix(doctor): preserve inherited schema provenance and include activation in project package remediation

* fix(doctor): report the contributing registration and activation sources

* test(doctor): exercise combined Pi activation and launcher repairs

* fix(doctor): honor OpenCode activation by config dialect

* fix(doctor): share project registration activation and provenance

* fix(setup): plan project removals before writes and isolate provider probes

* fix(doctor): preserve OpenCode registration and launcher provenance

* fix(doctor): use shared registration error and path provenance

* fix(doctor): gate desktop probes on registration authority

* fix(uninstall): skip absent project configuration candidates

* fix(uninstall): compare effective project registration before removal

* fix(doctor): guide project package launcher migration

* test(doctor): verify OpenCode project launcher migration advice

* fix(uninstall): separate project load order from write targets

* fix(doctor): preserve OpenCode directory alias precedence

* fix(uninstall): preserve unchanged remote project registrations

---------

Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
2026-11-21 22:19:56 +00:00

147 lines
6.2 KiB
TypeScript

import type { execFileOutput } from "../process/ExecFileOutput.js";
import type { ArtifactResourceScope } from "../resources/index.js";
/**
* The desktop build host contract: what doctor and `rea setup --desktop-build`
* read from, and ask of, the host that runs Docker, uv and agentenv. The
* desktop provider implements it; application workflows consume it.
*/
/** Setting names a registration does not carry as the value selected here. */
export interface RecordedProviderSettings {
/** Selected here and absent from the registration's recorded environment. */
readonly unrecorded: readonly string[];
/** Recorded with text other than the value selected here. */
readonly differing: readonly string[];
/** Recorded as an expression, or in a map REA could not read. */
readonly unresolved: readonly string[];
/** Recorded with a value the caller owns, as an archive setup packed for another version. */
readonly owned?: readonly string[];
}
/** Whether a recorded value is the caller's own, which it may replace; the value never leaves the reader. */
export type OwnedProviderSetting = (name: string, value: string) => boolean;
/**
* The registration facts a desktop build host reads for one client: setting
* names only, never recorded values. Client registration status satisfies it.
*/
export interface DesktopBuildRegistration {
readonly client: string;
/** Empty when the client has no usable registration. */
readonly command: readonly string[];
readonly provider_settings?: RecordedProviderSettings;
}
/** Reads each selected client's registration against the settings selected here. */
export type DesktopBuildRegistrationReader = (
selectedClientIds?: readonly string[],
providerSettings?: Readonly<Record<string, string>>,
ownedProviderSetting?: OwnedProviderSetting,
observeProbeSetting?: (client: string, name: string, value: string) => void,
) => Promise<readonly DesktopBuildRegistration[]>;
/** How a build setting's program was found: set in the environment, or on PATH. */
export type DesktopBuildCommand =
| {
readonly status: "found";
readonly path: string;
readonly source: "environment" | "path";
}
| { readonly status: "missing" }
| { readonly status: "invalid"; readonly value: string };
/** What a desktop build host has, read without changing anything. */
export interface DesktopBuildFacts {
readonly ps: { readonly found: boolean; readonly detail: string };
readonly docker: DesktopBuildCommand;
readonly daemon:
| { readonly status: "reachable"; readonly rootDirectory: string }
| {
readonly status: "permission_denied" | "unreachable";
readonly detail: string;
}
| { readonly status: "unchecked" };
readonly disk:
| { readonly path: string; readonly freeBytes: number }
| { readonly path: string; readonly error: string };
readonly agentEnv: DesktopBuildCommand & {
readonly version?: string | undefined;
};
readonly archive: {
readonly path: string;
readonly source: "environment" | "cache";
readonly status: "current" | "missing" | "stale" | "invalid" | "unknown";
readonly detail?: string;
};
/** Each considered client's registration, by setting names only. */
readonly registrations: readonly {
readonly client: string;
readonly registered: boolean;
readonly unrecorded: readonly string[];
readonly unresolved: readonly string[];
readonly differing?: readonly string[];
readonly unchecked?: readonly string[];
/** Version check of this client's recorded runner, without the recorded path. */
readonly runner?: {
readonly status: "current" | "stale" | "invalid" | "unknown";
readonly version?: string;
};
}[];
/** Build settings this terminal's environment sets. */
readonly environmentSettings: readonly string[];
/** Where a solve endpoint is configured; null means its configuration is unknown. */
readonly solveEndpoint: string | null | undefined;
/** Names of agentenv sandbox containers; undefined when Docker was not reachable. */
readonly leftoverContainers: readonly string[] | undefined;
}
/** What a facts reader gets from doctor: its environment, bounded runner and registration reader. */
export interface DesktopBuildFactsInput {
readonly signal: AbortSignal;
readonly resources: ArtifactResourceScope;
readonly environment: Readonly<NodeJS.ProcessEnv>;
readonly platform: NodeJS.Platform;
readonly run: typeof execFileOutput;
readonly clientIds: readonly string[];
readonly registrations: (
clientIds: readonly string[] | undefined,
settings: Readonly<Record<string, string>>,
owned?: undefined,
/** Receives only settings admitted to probes by the registration reader. */
observeProbeSetting?: (client: string, name: string, value: string) => void,
) => Promise<readonly DesktopBuildRegistration[]>;
}
/** What setup reads from a host before it plans a desktop build setup. */
export interface DesktopBuildSetupFacts {
/** Each build setting resolved to an absolute path; absent when none resolves. */
readonly settings: Readonly<Record<string, string>>;
/** Settings the caller's environment selected, which setup records as they are. */
readonly selected: readonly string[];
readonly archive: string;
readonly archivePacked: boolean;
/** Why this REA cannot pack its runtime, when it cannot. */
readonly packBlocker?: string;
readonly agentEnvVersion?: string | undefined;
/** uv on PATH and the agent-env its tool install places. */
readonly uv?: { readonly path: string; readonly agentEnv: string };
/** Per client, the build settings its registration already records with a value of its own. */
readonly recorded: Readonly<Record<string, readonly string[]>>;
}
/** Effects `rea setup --desktop-build` needs from its host. */
export interface DesktopBuildSetupHost {
facts(clientIds: readonly string[]): Promise<DesktopBuildSetupFacts>;
/** Pack this REA as the build-computer runtime; the reason when it failed. */
packRuntime(
archive: string,
signal?: AbortSignal,
): Promise<string | undefined>;
/** Install the pinned agentenv-framework with uv; the reason when it failed. */
installAgentenv(
uv: string,
signal?: AbortSignal,
): Promise<string | undefined>;
}