import { rmdir } from "node:fs/promises"; import type { AssetCatalogEntry, AssetHostNativeConfigMap, AssetKind, ManagedTextFileSnapshot, NativeConfigOperation, WirePlanManifest } from "../types.js"; /** * JSON object type alias. */ export type JsonObject = Record; /** * Activation lifecycle host identifier. */ export type LifecycleActivationHost = "copilot-vscode" | "opencode"; /** * Native wiring spec for a single AI coding host. */ export type NativeHost = "cursor" | "zed" | "claude-code" | "pi" | "codex"; /** Specifies the runtime configuration for a native host adapter. */ export interface NativeHostSpec { host: NativeHost; displayName: string; activationHost: LifecycleActivationHost; previewHost: string; managedRootSegments: string[]; targetPathSegments: string[][]; notes: string[]; } /** * Materialized native asset held in activation state. */ export interface NativeAsset { assetId: string; assetKind: AssetKind; displayName: string; compatibilityMode: AssetCatalogEntry["compatibilityMode"]; content: string; extensionId?: string; hostNativeConfig?: AssetHostNativeConfigMap; } /** * Materialized native asset buckets keyed by kind. */ export interface MaterializedNativeAssets { instructionFiles: string[]; agentFiles: string[]; skillDirs: string[]; pluginDirs: string[]; hookFiles: string[]; /** Maps assetId to its materialized content path for hook manifest resolution. */ hookContentPathByAssetId: Record; workflowFiles: string[]; referenceFiles: string[]; extensionIds: string[]; mcpServers: string[]; } /** * Shared options for per-host native file write functions. */ export interface WireNativeFilesOptions { workspaceRoot: string; managedRoot: string; nativeAssets: NativeAsset[]; materializedAssets: MaterializedNativeAssets; mcpServers: string[]; } /** * Applies host-native structured file payloads. */ export declare function applyStructuredNativeConfig(workspaceRoot: string, host: NativeHost, options: { nativeAssets: NativeAsset[]; }): Promise; /** * Exposes text-file snapshot restore for per-host adapter use. */ export declare function restoreManagedTextFileSnapshot(filePath: string, snapshots: ManagedTextFileSnapshot[] | undefined, fallbackRestore: () => Promise): Promise; /** * Captures pre-apply text-file snapshots for the given paths: each entry * records the file's content, or null when the file did not exist. Reset * paths use the null marker to distinguish adapter-created files (removed) * from pre-existing ones (restored/stripped) (#447). */ export declare function captureManagedTextFileSnapshots(paths: string[]): Promise; /** * Restores a managed section from a text-file snapshot, scoped to a single * markerId. Other managed sections in the file are preserved. * * - If a snapshot with non-null content exists: extract the managed section * from the snapshot and apply only that section to the current file. * - If the snapshot content is null or no snapshot exists: remove the * managed section from the current file via the fallback. */ export declare function restoreManagedSectionFromSnapshot(filePath: string, snapshots: ManagedTextFileSnapshot[] | undefined, markerId: string, fallbackRemove: () => Promise): Promise; /** * Validates wire-plan text snapshots are within the managed restore set. */ export declare function validateManagedTextFileSnapshots(wirePlan: WirePlanManifest | null, allowedPaths: string[], context: string): WirePlanManifest | null; /** * Exposes managed-section upsert for per-host adapter use. */ export declare function upsertManagedSectionFile(filePath: string, markerId: string, bodyLines: string[]): Promise; /** * Exposes managed-section removal for per-host adapter use. */ export declare function removeManagedSectionFile(filePath: string, markerId: string): Promise; /** * Exposes JSON-file merge for per-host adapter use. */ export declare function mergeJsonFile(filePath: string, patch: JsonObject): Promise; /** * Ensures an existing host settings file can be safely object-merged. */ export declare function assertJsonObject(value: unknown, filePath: string): JsonObject; /** * Describes a JSON value's runtime type for error messages. */ export declare function describeJsonValue(value: unknown): string; /** * Exposes managed Zed settings removal for per-host adapter use. * * Tolerates malformed (non-object) settings files by returning without * modification — safe for reset/cleanup paths. The corresponding upsert * path (writeZedNativeFiles) uses mergeJsonFile which rejects non-object * payloads via assertJsonObject. */ export declare function removeManagedZedSettings(filePath: string, workspaceRoot: string): Promise; /** * Exposes managed Pi settings upsert for per-host adapter use. */ export declare function upsertManagedPiSettings(filePath: string): Promise; /** * Exposes managed Pi settings removal for per-host adapter use. * * Tolerates malformed (non-object) settings files by returning without * modification — safe for reset/cleanup paths. See * removeManagedZedSettings above for the rationale behind the * reset-vs-wiring asymmetry. */ export declare function removeManagedPiSettings(filePath: string, workspaceRoot: string): Promise; /** * Exposes write-or-remove JSON helper for per-host adapter use. */ export declare function writeOrRemoveJsonFile(filePath: string, value: JsonObject, cleanupRoot?: string): Promise; /** * Exposes empty-directory cleanup for per-host adapter use. */ export declare function removeEmptyParentDirectories(startDirectory: string, stopDirectory: string, removeDirectory?: typeof rmdir): Promise; /** * Exposes benign race detection for per-host adapter use. */ export declare function isBenignRemoveDirectoryRace(error: unknown): boolean; /** * Exposes managed instruction line builder for per-host adapter use. */ export declare function buildManagedInstructionLines(options: { hostName: string; managedRoot: string; nativeAssets: NativeAsset[]; materializedAssets: MaterializedNativeAssets; mcpServers: string[]; }): string[]; /** * Exposes asset content section builder for per-host adapter use. */ export declare function buildNativeAssetContentSections(nativeAssets: NativeAsset[], assetKinds: AssetKind[]): string[]; /** * Exposes asset markdown builder for per-host adapter use. */ export declare function buildAssetMarkdown(nativeAsset: NativeAsset): string; /** * Exposes agent-file builder for per-host adapter use. */ export declare function buildAgentFile(name: string, description: string, bodyLines: string[]): string; /** * Exposes skill-file builder for per-host adapter use. */ export declare function buildSkillFile(name: string, description: string, bodyLines: string[]): string; /** * Exposes prompt-template builder for per-host adapter use. */ export declare function buildPromptTemplate(description: string, bodyLines: string[]): string; /** * Exposes asset-kind directory-name resolver for per-host adapter use. */ export declare function directoryNameForAssetKind(assetKind: AssetKind): string; /** * Returns a sorted deduplicated array of strings. */ export declare function uniqueStrings(values: string[]): string[]; /** * Exposes JSON-object merge helper for per-host adapter use. */ export declare function mergeJsonObjects(base: JsonObject, patch: JsonObject): JsonObject; /** * Exposes JSON-object guard for per-host adapter use. */ export declare function isJsonObject(value: unknown): value is JsonObject; /** * Exposes managed string-array removal for per-host adapter use. */ export declare function removeManagedStringArrayEntries(settings: JsonObject, key: string, entriesToRemove: readonly string[]): void; /** * Exposes string-array merge with order preservation for per-host adapter use. */ export declare function mergeStringArraysPreservingOrder(existingValues: readonly string[], additionalValues: readonly string[]): string[];