import type { Config } from "../config.js"; import { type SkillDefinition } from "../definitions.js"; import type { Secrets } from "../env.js"; import type { Events } from "../events.js"; import type { Logger } from "../logger.js"; import { type ManagedState } from "../managed-state.js"; import type { Paths } from "../paths.js"; import type { SkillRegistry } from "../registry.js"; import { type CommandErrorCode, type Definition } from "./protocol.js"; /** Why an install was refused, with the command error code it maps to. */ export declare class ManagedError extends Error { readonly code: CommandErrorCode; constructor(code: CommandErrorCode, message: string); } export type SyncReason = "connect" | "interval" | "command" | "cli"; /** What one reconciliation did (the `skills.synced` event and the `skills.sync` result). */ export interface SkillsSyncReport { at: string; reason: SyncReason; /** Names newly served. */ installed: string[]; /** Names whose definition changed. */ updated: string[]; /** Names no longer assigned, removed here. */ removed: string[]; unchanged: number; errors: { name: string; error: string; }[]; } /** The answer of the pre-run check. */ export interface FreshenResult { /** The cloud confirmed (or replaced) the definition just now. */ fresh: boolean; /** A new definition was installed and the job should resolve the skill again. */ changed: boolean; /** The definition that will run. */ sha256?: string; /** The cloud no longer assigns this skill to the machine; it was removed. */ unassigned?: boolean; /** Why the cloud could not be asked (the copy on disk runs). */ error?: string; } export interface ManagedSkillsDeps { paths: Paths; /** The live config: `cloud.*` is read at use time. */ config: Config; secrets: () => Secrets; logger: Logger; events?: Events; /** For `adopt`: the registry that knows the home skill. */ registry?: SkillRegistry; env?: NodeJS.ProcessEnv; fetchImpl?: typeof fetch; /** The pre-run check's timeout (default 5 s) and the reconciliation's (default 20 s). */ timing?: { freshenMs?: number; syncMs?: number; }; } export interface InstallOptions { by?: string; allowUnauthenticated?: boolean; /** Where the home directory of an adopted skill was moved. */ adoptedFrom?: string; } export interface InstallResult { name: string; sha256: string; /** False when the same definition was already current. */ changed: boolean; previous?: string; created: boolean; } /** * Checks a definition before anything is written: a `skill` with every file's text present, every hash right, the * digest right, a SKILL.md at the root that parses with `name`, and `auth: none` only when a person allowed it. */ export declare function checkDefinition(definition: Definition | SkillDefinition, name: string, options: { allowUnauthenticated?: boolean; dir: string; }): { files: { path: string; text: string; }[]; webhookUnauthenticated: boolean; }; export declare class ManagedSkills { private readonly deps; private lastSyncAt; /** One reconciliation at a time; a second call joins the one in flight. */ private syncing?; constructor(deps: ManagedSkillsDeps); private get dir(); private env; /** Whether this machine pulls at all, and why not. */ gate(): { ok: true; } | { ok: false; reason: string; }; state(): ManagedState; /** What the snapshot says about the managed skills. */ status(): { enabled: boolean; allowed: boolean; last_sync_at: string | null; skills: { name: string; sha256: string; installed_at: string; by?: string; }[]; }; /** Installs a definition as the current version of `name`: files first, the state pointer last; old versions beyond two are pruned. */ install(name: string, definition: Definition | SkillDefinition, options?: InstallOptions): InstallResult; /** Removes version directories of `name` that are neither current nor kept, and leftover temporary directories. */ private prune; /** Stops serving `name`: the pointer goes, the files move under `jobs/.removed-skills/` where a person can find them. */ remove(name: string, options?: { by?: string; }): { removed: boolean; kept_at?: string; }; /** Has the registry look the skill up now, so its `skill.changed` (added, changed, removed) goes out at once rather than at the next listing. */ private poke; /** * Makes a skill of `/skills` cloud-managed: its definition must hash to what the cloud holds (`sha256`), the * files become the first cloud version and the home directory moves under `jobs/.removed-skills/`, so it no longer * shadows the cloud copy. The cloud marks the skill as its own before it asks. */ adopt(name: string, sha256: string, options?: { by?: string; }): InstallResult & { kept_at: string; }; private request; /** Fetches and installs one assigned skill; errors become a line of the report. */ private pull; /** * Makes the served set equal to what the cloud assigns: installs what is new or changed, removes what is no longer * listed, leaves the rest. Undefined when the gate says no. Never throws: a cloud that cannot be reached is a report * with one error and nothing changed. */ reconcile(reason: SyncReason, options?: { by?: string; }): Promise; private reconcileNow; private finish; /** * Right before a job of a cloud-managed skill runs: asks the cloud whether the installed definition is still the one * it assigns (`If-None-Match`), installs the new one when not, and says whether the answer came. A cloud that cannot be * reached leaves the copy on disk, flagged `fresh: false`; a `404` means the skill is no longer assigned here. */ freshen(name: string): Promise; } /** Validates a definition the way an install would, for callers that want the error without writing anything. */ export declare function validateDefinition(value: unknown): Definition;