agent-plugin-lifecycle 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +243 -90
- package/bin/cli.js +8 -1
- package/dist/cjs/apm.d.cts +62 -13
- package/dist/cjs/apm.d.ts +62 -13
- package/dist/cjs/apm.js +534 -115
- package/dist/cjs/apm.js.map +1 -1
- package/dist/cjs/approvals.d.cts +26 -0
- package/dist/cjs/approvals.d.ts +26 -0
- package/dist/cjs/approvals.js +302 -0
- package/dist/cjs/approvals.js.map +1 -0
- package/dist/cjs/cli/index.d.cts +5 -0
- package/dist/cjs/cli/index.d.ts +5 -0
- package/dist/cjs/cli/index.js +53 -0
- package/dist/cjs/cli/index.js.map +1 -0
- package/dist/cjs/cli/install.d.cts +17 -0
- package/dist/cjs/cli/install.d.ts +17 -0
- package/dist/cjs/cli/install.js +308 -0
- package/dist/cjs/cli/install.js.map +1 -0
- package/dist/cjs/cli/report.d.cts +6 -0
- package/dist/cjs/cli/report.d.ts +6 -0
- package/dist/cjs/cli/report.js +47 -0
- package/dist/cjs/cli/report.js.map +1 -0
- package/dist/cjs/cli/status.d.cts +2 -0
- package/dist/cjs/cli/status.d.ts +2 -0
- package/dist/cjs/cli/status.js +222 -0
- package/dist/cjs/cli/status.js.map +1 -0
- package/dist/cjs/cli/types.d.cts +10 -0
- package/dist/cjs/cli/types.d.ts +10 -0
- package/dist/cjs/cli/types.js +6 -0
- package/dist/cjs/cli/types.js.map +1 -0
- package/dist/cjs/cli/usage.d.cts +2 -0
- package/dist/cjs/cli/usage.d.ts +2 -0
- package/dist/cjs/cli/usage.js +21 -0
- package/dist/cjs/cli/usage.js.map +1 -0
- package/dist/cjs/cli.d.cts +2 -1
- package/dist/cjs/cli.d.ts +2 -1
- package/dist/cjs/cli.js +65 -204
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/constants.d.cts +35 -0
- package/dist/cjs/constants.d.ts +35 -0
- package/dist/cjs/constants.js +115 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/copies.d.cts +40 -0
- package/dist/cjs/copies.d.ts +40 -0
- package/dist/cjs/copies.js +937 -0
- package/dist/cjs/copies.js.map +1 -0
- package/dist/cjs/index.d.cts +3 -6
- package/dist/cjs/index.d.ts +3 -6
- package/dist/cjs/index.js +20 -19
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/install.d.cts +6 -0
- package/dist/cjs/install.d.ts +6 -0
- package/dist/cjs/install.js +511 -0
- package/dist/cjs/install.js.map +1 -0
- package/dist/cjs/lib/errors.d.cts +5 -0
- package/dist/cjs/lib/errors.d.ts +5 -0
- package/dist/cjs/lib/errors.js +41 -0
- package/dist/cjs/lib/errors.js.map +1 -0
- package/dist/cjs/lib/object.d.cts +2 -0
- package/dist/cjs/lib/object.d.ts +2 -0
- package/dist/cjs/lib/object.js +18 -0
- package/dist/cjs/lib/object.js.map +1 -0
- package/dist/cjs/lib/options.d.cts +10 -0
- package/dist/cjs/lib/options.d.ts +10 -0
- package/dist/cjs/lib/options.js +26 -0
- package/dist/cjs/lib/options.js.map +1 -0
- package/dist/cjs/lib/run.d.cts +2 -0
- package/dist/cjs/lib/run.d.ts +2 -0
- package/dist/cjs/lib/run.js +40 -0
- package/dist/cjs/lib/run.js.map +1 -0
- package/dist/cjs/lib/store.d.cts +9 -0
- package/dist/cjs/lib/store.d.ts +9 -0
- package/dist/cjs/lib/store.js +418 -0
- package/dist/cjs/lib/store.js.map +1 -0
- package/dist/cjs/lib/visible.d.cts +9 -0
- package/dist/cjs/lib/visible.d.ts +9 -0
- package/dist/cjs/lib/visible.js +26 -0
- package/dist/cjs/lib/visible.js.map +1 -0
- package/dist/cjs/manifest.d.cts +4 -0
- package/dist/cjs/manifest.d.ts +4 -0
- package/dist/cjs/{config.js → manifest.js} +33 -94
- package/dist/cjs/manifest.js.map +1 -0
- package/dist/cjs/state.d.cts +17 -0
- package/dist/cjs/state.d.ts +17 -0
- package/dist/cjs/state.js +143 -0
- package/dist/cjs/state.js.map +1 -0
- package/dist/cjs/status.d.cts +3 -0
- package/dist/cjs/status.d.ts +3 -0
- package/dist/cjs/status.js +273 -0
- package/dist/cjs/status.js.map +1 -0
- package/dist/cjs/types.d.cts +39 -0
- package/dist/cjs/types.d.ts +39 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/apm.d.ts +62 -13
- package/dist/esm/apm.js +208 -96
- package/dist/esm/apm.js.map +1 -1
- package/dist/esm/approvals.d.ts +26 -0
- package/dist/esm/approvals.js +43 -0
- package/dist/esm/approvals.js.map +1 -0
- package/dist/esm/cli/index.d.ts +5 -0
- package/dist/esm/cli/index.js +5 -0
- package/dist/esm/cli/index.js.map +1 -0
- package/dist/esm/cli/install.d.ts +17 -0
- package/dist/esm/cli/install.js +89 -0
- package/dist/esm/cli/install.js.map +1 -0
- package/dist/esm/cli/report.d.ts +6 -0
- package/dist/esm/cli/report.js +21 -0
- package/dist/esm/cli/report.js.map +1 -0
- package/dist/esm/cli/status.d.ts +2 -0
- package/dist/esm/cli/status.js +41 -0
- package/dist/esm/cli/status.js.map +1 -0
- package/dist/esm/cli/types.d.ts +10 -0
- package/dist/esm/cli/types.js +2 -0
- package/dist/esm/cli/types.js.map +1 -0
- package/dist/esm/cli/usage.d.ts +2 -0
- package/dist/esm/cli/usage.js +2 -0
- package/dist/esm/cli/usage.js.map +1 -0
- package/dist/esm/cli.d.ts +2 -1
- package/dist/esm/cli.js +46 -65
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/constants.d.ts +35 -0
- package/dist/esm/constants.js +37 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/copies.d.ts +40 -0
- package/dist/esm/copies.js +226 -0
- package/dist/esm/copies.js.map +1 -0
- package/dist/esm/index.d.ts +3 -6
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/install.d.ts +6 -0
- package/dist/esm/install.js +116 -0
- package/dist/esm/install.js.map +1 -0
- package/dist/esm/lib/errors.d.ts +5 -0
- package/dist/esm/lib/errors.js +9 -0
- package/dist/esm/lib/errors.js.map +1 -0
- package/dist/esm/lib/object.d.ts +2 -0
- package/dist/esm/lib/object.js +3 -0
- package/dist/esm/lib/object.js.map +1 -0
- package/dist/esm/lib/options.d.ts +10 -0
- package/dist/esm/lib/options.js +15 -0
- package/dist/esm/lib/options.js.map +1 -0
- package/dist/esm/lib/run.d.ts +2 -0
- package/dist/esm/lib/run.js +29 -0
- package/dist/esm/lib/run.js.map +1 -0
- package/dist/esm/lib/store.d.ts +9 -0
- package/dist/esm/lib/store.js +91 -0
- package/dist/esm/lib/store.js.map +1 -0
- package/dist/esm/lib/visible.d.ts +9 -0
- package/dist/esm/lib/visible.js +12 -0
- package/dist/esm/lib/visible.js.map +1 -0
- package/dist/esm/manifest.d.ts +4 -0
- package/dist/esm/manifest.js +25 -0
- package/dist/esm/manifest.js.map +1 -0
- package/dist/esm/state.d.ts +17 -0
- package/dist/esm/state.js +32 -0
- package/dist/esm/state.js.map +1 -0
- package/dist/esm/status.d.ts +3 -0
- package/dist/esm/status.js +44 -0
- package/dist/esm/status.js.map +1 -0
- package/dist/esm/types.d.ts +39 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +25 -9
- package/config/config.example.json +0 -22
- package/dist/cjs/config.d.cts +0 -16
- package/dist/cjs/config.d.ts +0 -16
- package/dist/cjs/config.js.map +0 -1
- package/dist/cjs/runner.d.cts +0 -19
- package/dist/cjs/runner.d.ts +0 -19
- package/dist/cjs/runner.js +0 -1391
- package/dist/cjs/runner.js.map +0 -1
- package/dist/esm/config.d.ts +0 -16
- package/dist/esm/config.js +0 -74
- package/dist/esm/config.js.map +0 -1
- package/dist/esm/runner.d.ts +0 -19
- package/dist/esm/runner.js +0 -335
- package/dist/esm/runner.js.map +0 -1
package/dist/cjs/runner.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/agent-plugin-lifecycle/src/runner.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport { existsSync } from 'node:fs';\nimport { mkdir, readFile, realpath, rename, stat, unlink, writeFile } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';\nimport spawn from 'cross-spawn-cb';\nimport lockfile from 'proper-lockfile';\nimport { type LockedPlugin, loadLock, localEventName, matchesSource, samePath, sourceParts } from './apm.js';\nimport { loadConfig, type PluginPolicy, recordId } from './config.js';\n\nexport type Mode = 'run' | 'check';\nexport interface LifecycleEvent {\n schema_version: 1;\n event: 'post-install' | 'post-update' | 'post-uninstall';\n scope: 'user';\n packages: { name: string; reference: string | null }[];\n}\n// `revision` is the locked revision the command last ran against; '' is a version 1 receipt, whose revision was never recorded.\ninterface Receipt {\n digest: string;\n revision: string;\n}\ninterface State {\n version: 2;\n receipts: Record<string, Receipt>;\n}\nexport interface RunOptions {\n home?: string;\n apmHome?: string;\n configPath?: string;\n environment?: NodeJS.ProcessEnv;\n output?: (line: string) => void;\n event?: LifecycleEvent;\n}\nfunction inside(root: string, child: string): boolean {\n const subpath = relative(root, child);\n return subpath === '' || (subpath !== '..' && !subpath.startsWith(`..${sep}`) && !isAbsolute(subpath));\n}\nasync function existingWithin(root: string, path: string, label: string): Promise<string> {\n const rootReal = await realpath(root);\n const candidate = resolve(rootReal, path);\n if (!inside(rootReal, candidate)) throw new Error(`${label} escapes ${root}`);\n const candidateReal = await realpath(candidate);\n if (!inside(rootReal, candidateReal)) throw new Error(`${label} resolves outside ${root}`);\n return candidateReal;\n}\nfunction pluginRoot(plugin: LockedPlugin, apmHome: string): string {\n return join(apmHome, 'apm_modules', plugin.repo, plugin.path);\n}\nfunction missing(error: unknown): boolean {\n return !!error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT';\n}\nasync function existingOrNone(root: string, path: string, label: string): Promise<string | undefined> {\n try {\n return await existingWithin(root, path, label);\n } catch (error) {\n if (missing(error)) return undefined;\n throw error;\n }\n}\nconst SKILL_ROOTS = ['.agents/skills/', '.hermes/skills/', '.claude/skills/'];\nfunction deployedSkillFolders(plugin: LockedPlugin, skill: string): string[] {\n const folders = new Set<string>();\n for (const file of plugin.deployedFiles) {\n const parts = file.split('/');\n const index = parts.lastIndexOf('skills');\n if (index < 0 || parts[index + 1] !== skill) continue;\n const deployment = parts.slice(0, index + 2).join('/');\n if (SKILL_ROOTS.some((candidate) => deployment.startsWith(candidate))) folders.add(deployment);\n }\n return [...folders];\n}\n// APM's kept copy (`apm_modules/...`) is a destination only when the lock names no other copy: a target such as copilot reads it in place.\n// When the lock names a native plugin root or deployed skill copies, the kept copy is APM's cache and is never used, even if the listed copies are missing on disk (they are skipped, and check reports them).\nasync function destinations(plugin: LockedPlugin, policy: PluginPolicy, home: string, apmHome: string): Promise<string[]> {\n const found = new Set<string>();\n const add = (path: string | undefined) => {\n if (path) found.add(path);\n };\n const nativeRoot = plugin.nativePluginRoot?.startsWith('.agents/plugins/') ? plugin.nativePluginRoot.slice('.agents/plugins/'.length) : undefined;\n if (!policy.skill) {\n if (!nativeRoot) return [await existingWithin(join(apmHome, 'apm_modules'), join(plugin.repo, plugin.path), 'kept plugin')];\n add(await existingOrNone(join(home, '.agents', 'plugins'), nativeRoot, 'native plugin'));\n if (!found.size) throw new Error(`no native plugin copy found for ${plugin.repo}`);\n return [...found];\n }\n const deployed = deployedSkillFolders(plugin, policy.skill);\n if (!nativeRoot && !deployed.length) {\n const kept = await existingOrNone(pluginRoot(plugin, apmHome), `skills/${policy.skill}`, `kept skill ${policy.skill}`);\n if (!kept) throw new Error(`no deployed copy found for skill ${policy.skill}`);\n return [kept];\n }\n if (nativeRoot) add(await existingOrNone(join(home, '.agents', 'plugins'), `${nativeRoot}/skills/${policy.skill}`, `native skill ${policy.skill}`));\n for (const deployment of deployed) add(await existingOrNone(home, deployment, `skill ${policy.skill}`));\n if (!found.size) throw new Error(`no deployed copy found for skill ${policy.skill}`);\n return [...found];\n}\nasync function readState(path: string): Promise<State> {\n if (!existsSync(path)) return { version: 2, receipts: {} };\n const value: unknown = JSON.parse(await readFile(path, 'utf8'));\n if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('state must be an object');\n const item = value as Record<string, unknown>;\n if ((item.version !== 1 && item.version !== 2) || !item.receipts || typeof item.receipts !== 'object' || Array.isArray(item.receipts)) throw new Error('unsupported state format');\n const receipts: Record<string, Receipt> = {};\n for (const [key, receipt] of Object.entries(item.receipts)) {\n if (item.version === 1 && typeof receipt === 'string') receipts[key] = { digest: receipt, revision: '' };\n else if (item.version === 2 && receipt && typeof receipt === 'object' && typeof (receipt as Receipt).digest === 'string' && typeof (receipt as Receipt).revision === 'string') receipts[key] = receipt as Receipt;\n else throw new Error('invalid state receipt');\n }\n return { version: 2, receipts };\n}\nasync function saveState(path: string, state: State): Promise<void> {\n const temp = join(dirname(path), `.state-${process.pid}-${Date.now()}.tmp`);\n try {\n await writeFile(temp, `${JSON.stringify(state, null, 2)}\\n`, { mode: 0o600, flag: 'wx' });\n await rename(temp, path);\n } catch (error) {\n try {\n await unlink(temp);\n } catch {\n /* preserve original error */\n }\n throw error;\n }\n}\nfunction receiptKey(policy: PluginPolicy, destination: string): string {\n return JSON.stringify([recordId(policy), destination]);\n}\nfunction digest(policy: PluginPolicy, command: string): string {\n return createHash('sha256')\n .update(JSON.stringify([recordId(policy), command]))\n .digest('hex');\n}\n// The platform shell runs the configured string as written, as with npm and Node's `shell` option.\nasync function execute(command: string, cwd: string, environment: NodeJS.ProcessEnv): Promise<void> {\n await spawn(command, [], { cwd, env: environment, stdio: ['ignore', 'inherit', 'inherit'], shell: true });\n}\nfunction receiptRecord(key: string): string | undefined {\n try {\n return JSON.parse(key)[0];\n } catch {\n return undefined;\n }\n}\nfunction lockLoadError(error: unknown): boolean {\n return !!error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT';\n}\nexport async function runLifecycle(mode: Mode, options: RunOptions = {}): Promise<number> {\n const home = resolve(options.home ?? homedir());\n const apmHome = resolve(options.apmHome ?? join(home, '.apm'));\n const configPath = options.configPath ?? join(home, '.config', 'agent-plugin-lifecycle', 'config.json');\n const environment = options.environment ?? process.env;\n const output = options.output ?? console.log;\n const config = await loadConfig(configPath);\n let locked: LockedPlugin[];\n try {\n locked = await loadLock(join(apmHome, 'apm.lock.yaml'));\n } catch (error) {\n if (mode === 'run' && options.event?.event === 'post-uninstall' && lockLoadError(error)) {\n const apmDirectory = await stat(apmHome);\n if (!apmDirectory.isDirectory()) throw error;\n locked = [];\n } else if (mode === 'check' && lockLoadError(error)) {\n output('nothing installed');\n return 0;\n } else throw error;\n }\n const statePath = join(dirname(configPath), 'state.json');\n if (mode === 'run') await mkdir(dirname(statePath), { recursive: true, mode: 0o700 });\n const release = mode === 'run' ? await lockfile.lock(dirname(statePath), { realpath: false }) : undefined;\n try {\n const state = await readState(statePath);\n let failed = 0;\n if (mode === 'run' && options.event?.event === 'post-uninstall') {\n const eventNames = new Set(options.event.packages.map(({ name }) => name));\n for (const policy of config.plugins) {\n const id = recordId(policy);\n const receiptKeys = Object.keys(state.receipts).filter((key) => {\n try {\n return JSON.parse(key)[0] === id;\n } catch {\n return false;\n }\n });\n if (!receiptKeys.length) continue;\n const sourceCandidate =\n policy.source.startsWith('.') || isAbsolute(policy.source) ? locked.find((plugin) => plugin.localPath !== undefined && samePath(policy.source, plugin.localPath)) : locked.find((plugin) => matchesSource(policy.source, plugin) && (plugin.path === (policy.path ?? '.') || plugin.localPath !== undefined));\n const sourcePartsValue = sourceParts(policy.source);\n const removedNameMatch =\n eventNames.has(sourceCandidate?.repo ?? '') ||\n eventNames.has(sourceCandidate ? `${sourceCandidate.host}/${sourceCandidate.repo}` : '') ||\n eventNames.has(sourcePartsValue?.repo ?? '') ||\n eventNames.has(sourcePartsValue ? `${sourcePartsValue.host}/${sourcePartsValue.repo}` : '') ||\n // APM names a removed subfolder plugin `owner/repo/<folder>` (install and update events name it `owner/repo`); exact match only, so removing one folder never matches another plugin of the repository\n (!!sourcePartsValue && !!policy.path && policy.path !== '.' && (eventNames.has(`${sourcePartsValue.repo}/${policy.path}`) || eventNames.has(`${sourcePartsValue.host}/${sourcePartsValue.repo}/${policy.path}`))) ||\n eventNames.has(localEventName(policy.source)) ||\n eventNames.has(policy.source);\n const anyStillInstalled = locked.some((plugin) => matchesSource(policy.source, plugin) && plugin.path === (policy.path ?? '.'));\n if (anyStillInstalled || !removedNameMatch) continue;\n // APM keeps a folder holding files it did not write; report it, delete nothing\n for (const key of receiptKeys) {\n const destination: string = JSON.parse(key)[1];\n if (existsSync(destination)) output(`left ${destination}`);\n }\n const command = policy['post-uninstall'];\n if (!command) {\n for (const key of receiptKeys) delete state.receipts[key];\n await saveState(statePath, state);\n continue;\n }\n try {\n await execute(command, home, environment);\n for (const key of receiptKeys) delete state.receipts[key];\n await saveState(statePath, state);\n output(`cleaned ${id}`);\n } catch (error) {\n output(`failed cleanup ${id}: ${error instanceof Error ? error.message : String(error)}`);\n failed++;\n }\n }\n return failed ? 1 : 0;\n }\n if (mode === 'run' && !options.event) throw new Error('run requires an APM event');\n const event = options.event?.event ?? 'post-install';\n let installed = 0;\n for (const policy of config.plugins) {\n const command = event === 'post-update' ? (policy['post-update'] ?? policy['post-install']) : policy['post-install'];\n if (!command) continue;\n const matches = locked.filter((plugin) => matchesSource(policy.source, plugin) && plugin.path === (policy.path ?? '.'));\n if (matches.length > 1) {\n output(`failed ambiguous source/path record ${recordId(policy)}`);\n failed++;\n continue;\n }\n if (!matches.length) {\n if (mode === 'run') output(`skipped source not installed ${recordId(policy)}`);\n continue;\n }\n installed++;\n const plugin = matches[0];\n const id = recordId(policy);\n try {\n const recorded = Object.keys(state.receipts).filter((key) => receiptRecord(key) === id);\n let found: string[];\n try {\n found = await destinations(plugin, policy, home, apmHome);\n } catch (error) {\n // check still reports a copy that was recorded and is now gone\n if (mode === 'check' && recorded.length && (missing(error) || (error instanceof Error && error.message.startsWith('no ')))) found = [];\n else throw error;\n }\n const gone = recorded.filter((key) => !existsSync(JSON.parse(key)[1]));\n if (mode === 'run') {\n // a copy that no longer exists loses its receipt, so the copy APM recreates in its place runs again\n for (const key of gone) delete state.receipts[key];\n if (gone.length) await saveState(statePath, state);\n } else {\n const validDigests = [policy['post-install'], policy['post-update']].filter((item): item is string => !!item).map((item) => digest(policy, item));\n for (const key of gone) {\n const receipt = state.receipts[key];\n if (validDigests.includes(receipt.digest) && receipt.revision === plugin.revision) {\n output(`broken ${id} ${JSON.parse(key)[1]}`);\n failed++;\n }\n }\n for (const destination of found) {\n const receipt = state.receipts[receiptKey(policy, destination)];\n let status = 'missing';\n if (receipt) {\n const current = validDigests.includes(receipt.digest) && receipt.revision === plugin.revision;\n status = current ? 'ok' : 'stale';\n }\n output(`${status} ${id} ${destination}`);\n if (status !== 'ok') failed++;\n }\n continue;\n }\n for (const destination of found) {\n const key = receiptKey(policy, destination);\n const wanted = digest(policy, command);\n const receipt = state.receipts[key];\n if (receipt && receipt.digest === wanted && receipt.revision === plugin.revision) {\n output(`current ${id} ${destination}`);\n continue;\n }\n delete state.receipts[key];\n await saveState(statePath, state);\n await execute(command, destination, environment);\n state.receipts[key] = { digest: wanted, revision: plugin.revision };\n await saveState(statePath, state);\n output(`ran ${id} ${destination}`);\n }\n } catch (error) {\n output(`failed ${id}: ${error instanceof Error ? error.message : String(error)}`);\n failed++;\n }\n }\n if (mode === 'check' && !installed && !failed) output('nothing installed');\n return failed ? 1 : 0;\n } finally {\n await release?.();\n }\n}\n"],"names":["runLifecycle","inside","root","child","subpath","relative","startsWith","sep","isAbsolute","existingWithin","path","label","rootReal","candidate","candidateReal","realpath","resolve","Error","pluginRoot","plugin","apmHome","join","repo","missing","error","code","existingOrNone","undefined","SKILL_ROOTS","deployedSkillFolders","skill","folders","Set","file","parts","split","index","lastIndexOf","deployment","slice","some","add","deployedFiles","destinations","policy","home","found","nativeRoot","deployed","kept","nativePluginRoot","length","size","readState","value","item","receipts","key","receipt","existsSync","version","JSON","parse","readFile","Array","isArray","Object","entries","digest","revision","saveState","state","temp","dirname","Date","process","pid","now","writeFile","stringify","mode","flag","rename","unlink","receiptKey","destination","recordId","command","createHash","update","execute","cwd","environment","spawn","env","stdio","shell","receiptRecord","lockLoadError","options","configPath","output","config","locked","apmDirectory","statePath","release","failed","eventNames","event","installed","homedir","console","log","loadConfig","loadLock","stat","isDirectory","mkdir","recursive","lockfile","lock","packages","map","name","id","receiptKeys","sourceCandidate","sourcePartsValue","removedNameMatch","anyStillInstalled","keys","filter","source","find","localPath","samePath","matchesSource","sourceParts","has","host","localEventName","message","String","plugins","matches","recorded","gone","validDigests","status","current","wanted","includes"],"mappings":";;;;+BAmJsBA;;;eAAAA;;;0BAnJK;sBACA;wBACgD;sBACnD;wBAC0C;mEAChD;qEACG;mBAC6E;sBAC1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BxD,SAASC,OAAOC,IAAY,EAAEC,KAAa;IACzC,IAAMC,UAAUC,IAAAA,kBAAQ,EAACH,MAAMC;IAC/B,OAAOC,YAAY,MAAOA,YAAY,QAAQ,CAACA,QAAQE,UAAU,CAAC,AAAC,KAAQ,OAAJC,aAAG,MAAO,CAACC,IAAAA,oBAAU,EAACJ;AAC/F;AACA,SAAeK,eAAeP,IAAY,EAAEQ,IAAY,EAAEC,KAAa;;YAC/DC,UACAC,WAEAC;;;;oBAHW;;wBAAMC,IAAAA,kBAAQ,EAACb;;;oBAA1BU,WAAW;oBACXC,YAAYG,IAAAA,iBAAO,EAACJ,UAAUF;oBACpC,IAAI,CAACT,OAAOW,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AQU,MAAM,KAAKmF,UAAU7F,SAAQW,QAAQ,KAAKlD,OAAOkD,QAAQ,EAAE;wCAChFgC,OAAO,AAAC,WAAgBhB,OAANwC,IAAG,KAAe,OAAZxC;wCACxB;;;;oCACF;oCACA,OAAOd,MAAMf,QAAQ,CAACC,KAAI;oCAC1B;;wCAAMa,UAAUmC,WAAWlC;;;oCAA3B;oCACA;;wCAAMmB,QAAQH,SAASF,cAAaO;;;oCAApC;oCACArB,MAAMf,QAAQ,CAACC,KAAI,GAAG;wCAAEW,QAAQmF;wCAAQlF,UAAUlD,OAAOkD,QAAQ;oCAAC;oCAClE;;wCAAMC,UAAUmC,WAAWlC;;;oCAA3B;oCACA8B,OAAO,AAAC,OAAYhB,OAANwC,IAAG,KAAe,OAAZxC;;;oCAbjB;;;;;;;;;;;;oCAAA;oCAAA;;;;;;;6CAAA,8BAAA;4CAAA;;;4CAAA;kDAAA;;;;;;;;;;;;oCAeE7D;oCACP6E,OAAO,AAAC,UAAgB7E,OAAPqG,IAAG,MAA2D,OAAvDrG,AAAK,YAALA,QAAiBP,SAAQO,OAAMsH,OAAO,GAAGC,OAAOvH;oCACxEmF;;;;;;;;;;;oBAEJ;oBAvEK,aAAgBL,OAAO0C,OAAO;;;2BAA9B,8BAAA,SAAA;;;;;;;;;;;;oBAAA;;;;;;;;;;;;oBAAA;oBAAA;;;;;;;6BAAA,8BAAA;4BAAA;;;4BAAA;kCAAA;;;;;;;oBAwEL,IAAIhE,SAAS,WAAW,CAAC8B,aAAa,CAACH,QAAQN,OAAO;oBACtD;;wBAAOM,SAAS,IAAI;;;oBAEpB;;wBAAMD,oBAAAA,8BAAAA;;;oBAAN;;;;;;;;;;IAEJ"}
|
package/dist/esm/config.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export type Platform = 'darwin' | 'linux' | 'win32';
|
|
2
|
-
export interface PluginPolicy {
|
|
3
|
-
source: string;
|
|
4
|
-
path?: string;
|
|
5
|
-
skill?: string;
|
|
6
|
-
'post-install'?: string;
|
|
7
|
-
'post-update'?: string;
|
|
8
|
-
'post-uninstall'?: string;
|
|
9
|
-
}
|
|
10
|
-
export interface Config {
|
|
11
|
-
version: 1;
|
|
12
|
-
plugins: PluginPolicy[];
|
|
13
|
-
}
|
|
14
|
-
export declare function recordId(plugin: PluginPolicy): string;
|
|
15
|
-
export declare function parseConfig(value: unknown): Config;
|
|
16
|
-
export declare function loadConfig(path: string): Promise<Config>;
|
package/dist/esm/config.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises';
|
|
2
|
-
function object(value, label, allowed) {
|
|
3
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error(`${label} must be an object`);
|
|
4
|
-
const result = value;
|
|
5
|
-
const unknown = Object.keys(result).find((key)=>!allowed.includes(key));
|
|
6
|
-
if (unknown) throw new Error(`${label} has unknown field: ${unknown}`);
|
|
7
|
-
return result;
|
|
8
|
-
}
|
|
9
|
-
function nonempty(value, label) {
|
|
10
|
-
if (typeof value !== 'string' || !value.trim()) throw new Error(`${label} must be a nonempty string`);
|
|
11
|
-
return value;
|
|
12
|
-
}
|
|
13
|
-
function relativePath(value, label) {
|
|
14
|
-
const path = nonempty(value, label);
|
|
15
|
-
if (path === '.') return path;
|
|
16
|
-
if (path.startsWith('/') || path.startsWith('\\') || /^[A-Za-z]:/.test(path) || path.includes('\\') || path.split('/').some((part)=>!part || part === '.' || part === '..')) {
|
|
17
|
-
throw new Error(`${label} must be a safe relative POSIX path`);
|
|
18
|
-
}
|
|
19
|
-
return path;
|
|
20
|
-
}
|
|
21
|
-
export function recordId(plugin) {
|
|
22
|
-
var _plugin_path, _plugin_skill;
|
|
23
|
-
return JSON.stringify([
|
|
24
|
-
plugin.source,
|
|
25
|
-
(_plugin_path = plugin.path) !== null && _plugin_path !== void 0 ? _plugin_path : '.',
|
|
26
|
-
(_plugin_skill = plugin.skill) !== null && _plugin_skill !== void 0 ? _plugin_skill : null
|
|
27
|
-
]);
|
|
28
|
-
}
|
|
29
|
-
export function parseConfig(value) {
|
|
30
|
-
const root = object(value, 'config', [
|
|
31
|
-
'version',
|
|
32
|
-
'plugins'
|
|
33
|
-
]);
|
|
34
|
-
if (root.version !== 1 || !Array.isArray(root.plugins)) throw new Error('config must have version 1 and a plugins array');
|
|
35
|
-
const seen = new Set();
|
|
36
|
-
const plugins = root.plugins.map((raw, index)=>{
|
|
37
|
-
const label = `plugins[${index}]`;
|
|
38
|
-
const item = object(raw, label, [
|
|
39
|
-
'source',
|
|
40
|
-
'path',
|
|
41
|
-
'skill',
|
|
42
|
-
'post-install',
|
|
43
|
-
'post-update',
|
|
44
|
-
'post-uninstall'
|
|
45
|
-
]);
|
|
46
|
-
const source = nonempty(item.source, `${label}.source`);
|
|
47
|
-
const path = item.path === undefined ? undefined : relativePath(item.path, `${label}.path`);
|
|
48
|
-
const skill = item.skill === undefined ? undefined : nonempty(item.skill, `${label}.skill`);
|
|
49
|
-
if (skill && (skill.includes('/') || skill.includes('\\') || skill === '.' || skill === '..')) throw new Error(`${label}.skill must be one directory name`);
|
|
50
|
-
const plugin = {
|
|
51
|
-
source,
|
|
52
|
-
path,
|
|
53
|
-
skill
|
|
54
|
-
};
|
|
55
|
-
for (const event of [
|
|
56
|
-
'post-install',
|
|
57
|
-
'post-update',
|
|
58
|
-
'post-uninstall'
|
|
59
|
-
]){
|
|
60
|
-
if (item[event] !== undefined) plugin[event] = nonempty(item[event], `${label}.${event}`);
|
|
61
|
-
}
|
|
62
|
-
const id = recordId(plugin);
|
|
63
|
-
if (seen.has(id)) throw new Error(`${label} duplicates another source/path/skill record`);
|
|
64
|
-
seen.add(id);
|
|
65
|
-
return plugin;
|
|
66
|
-
});
|
|
67
|
-
return {
|
|
68
|
-
version: 1,
|
|
69
|
-
plugins
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
export async function loadConfig(path) {
|
|
73
|
-
return parseConfig(JSON.parse(await readFile(path, 'utf8')));
|
|
74
|
-
}
|
package/dist/esm/config.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/agent-plugin-lifecycle/src/config.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\n\nexport type Platform = 'darwin' | 'linux' | 'win32';\nexport interface PluginPolicy {\n source: string;\n path?: string;\n skill?: string;\n 'post-install'?: string;\n 'post-update'?: string;\n 'post-uninstall'?: string;\n}\nexport interface Config {\n version: 1;\n plugins: PluginPolicy[];\n}\n\nfunction object(value: unknown, label: string, allowed: string[]): Record<string, unknown> {\n if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error(`${label} must be an object`);\n const result = value as Record<string, unknown>;\n const unknown = Object.keys(result).find((key) => !allowed.includes(key));\n if (unknown) throw new Error(`${label} has unknown field: ${unknown}`);\n return result;\n}\nfunction nonempty(value: unknown, label: string): string {\n if (typeof value !== 'string' || !value.trim()) throw new Error(`${label} must be a nonempty string`);\n return value;\n}\nfunction relativePath(value: unknown, label: string): string {\n const path = nonempty(value, label);\n if (path === '.') return path;\n if (path.startsWith('/') || path.startsWith('\\\\') || /^[A-Za-z]:/.test(path) || path.includes('\\\\') || path.split('/').some((part) => !part || part === '.' || part === '..')) {\n throw new Error(`${label} must be a safe relative POSIX path`);\n }\n return path;\n}\nexport function recordId(plugin: PluginPolicy): string {\n return JSON.stringify([plugin.source, plugin.path ?? '.', plugin.skill ?? null]);\n}\nexport function parseConfig(value: unknown): Config {\n const root = object(value, 'config', ['version', 'plugins']);\n if (root.version !== 1 || !Array.isArray(root.plugins)) throw new Error('config must have version 1 and a plugins array');\n const seen = new Set<string>();\n const plugins = root.plugins.map((raw, index): PluginPolicy => {\n const label = `plugins[${index}]`;\n const item = object(raw, label, ['source', 'path', 'skill', 'post-install', 'post-update', 'post-uninstall']);\n const source = nonempty(item.source, `${label}.source`);\n const path = item.path === undefined ? undefined : relativePath(item.path, `${label}.path`);\n const skill = item.skill === undefined ? undefined : nonempty(item.skill, `${label}.skill`);\n if (skill && (skill.includes('/') || skill.includes('\\\\') || skill === '.' || skill === '..')) throw new Error(`${label}.skill must be one directory name`);\n const plugin: PluginPolicy = { source, path, skill };\n for (const event of ['post-install', 'post-update', 'post-uninstall'] as const) {\n if (item[event] !== undefined) plugin[event] = nonempty(item[event], `${label}.${event}`);\n }\n const id = recordId(plugin);\n if (seen.has(id)) throw new Error(`${label} duplicates another source/path/skill record`);\n seen.add(id);\n return plugin;\n });\n return { version: 1, plugins };\n}\nexport async function loadConfig(path: string): Promise<Config> {\n return parseConfig(JSON.parse(await readFile(path, 'utf8')));\n}\n"],"names":["readFile","object","value","label","allowed","Array","isArray","Error","result","unknown","Object","keys","find","key","includes","nonempty","trim","relativePath","path","startsWith","test","split","some","part","recordId","plugin","JSON","stringify","source","skill","parseConfig","root","version","plugins","seen","Set","map","raw","index","item","undefined","event","id","has","add","loadConfig","parse"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,mBAAmB;AAgB5C,SAASC,OAAOC,KAAc,EAAEC,KAAa,EAAEC,OAAiB;IAC9D,IAAI,CAACF,SAAS,OAAOA,UAAU,YAAYG,MAAMC,OAAO,CAACJ,QAAQ,MAAM,IAAIK,MAAM,GAAGJ,MAAM,kBAAkB,CAAC;IAC7G,MAAMK,SAASN;IACf,MAAMO,UAAUC,OAAOC,IAAI,CAACH,QAAQI,IAAI,CAAC,CAACC,MAAQ,CAACT,QAAQU,QAAQ,CAACD;IACpE,IAAIJ,SAAS,MAAM,IAAIF,MAAM,GAAGJ,MAAM,oBAAoB,EAAEM,SAAS;IACrE,OAAOD;AACT;AACA,SAASO,SAASb,KAAc,EAAEC,KAAa;IAC7C,IAAI,OAAOD,UAAU,YAAY,CAACA,MAAMc,IAAI,IAAI,MAAM,IAAIT,MAAM,GAAGJ,MAAM,0BAA0B,CAAC;IACpG,OAAOD;AACT;AACA,SAASe,aAAaf,KAAc,EAAEC,KAAa;IACjD,MAAMe,OAAOH,SAASb,OAAOC;IA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AAKV,KAAK,EAAE,GAAG1B,MAAM,MAAM,CAAC;QAC1F,IAAI0B,SAAUA,CAAAA,MAAMf,QAAQ,CAAC,QAAQe,MAAMf,QAAQ,CAAC,SAASe,UAAU,OAAOA,UAAU,IAAG,GAAI,MAAM,IAAItB,MAAM,GAAGJ,MAAM,iCAAiC,CAAC;QAC1J,MAAMsB,SAAuB;YAAEG;YAAQV;YAAMW;QAAM;QACnD,KAAK,MAAMY,SAAS;YAAC;YAAgB;YAAe;SAAiB,CAAW;YAC9E,IAAIF,IAAI,CAACE,MAAM,KAAKD,WAAWf,MAAM,CAACgB,MAAM,GAAG1B,SAASwB,IAAI,CAACE,MAAM,EAAE,GAAGtC,MAAM,CAAC,EAAEsC,OAAO;QAC1F;QACA,MAAMC,KAAKlB,SAASC;QACpB,IAAIS,KAAKS,GAAG,CAACD,KAAK,MAAM,IAAInC,MAAM,GAAGJ,MAAM,4CAA4C,CAAC;QACxF+B,KAAKU,GAAG,CAACF;QACT,OAAOjB;IACT;IACA,OAAO;QAAEO,SAAS;QAAGC;IAAQ;AAC/B;AACA,OAAO,eAAeY,WAAW3B,IAAY;IAC3C,OAAOY,YAAYJ,KAAKoB,KAAK,CAAC,MAAM9C,SAASkB,MAAM;AACrD"}
|
package/dist/esm/runner.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export type Mode = 'run' | 'check';
|
|
2
|
-
export interface LifecycleEvent {
|
|
3
|
-
schema_version: 1;
|
|
4
|
-
event: 'post-install' | 'post-update' | 'post-uninstall';
|
|
5
|
-
scope: 'user';
|
|
6
|
-
packages: {
|
|
7
|
-
name: string;
|
|
8
|
-
reference: string | null;
|
|
9
|
-
}[];
|
|
10
|
-
}
|
|
11
|
-
export interface RunOptions {
|
|
12
|
-
home?: string;
|
|
13
|
-
apmHome?: string;
|
|
14
|
-
configPath?: string;
|
|
15
|
-
environment?: NodeJS.ProcessEnv;
|
|
16
|
-
output?: (line: string) => void;
|
|
17
|
-
event?: LifecycleEvent;
|
|
18
|
-
}
|
|
19
|
-
export declare function runLifecycle(mode: Mode, options?: RunOptions): Promise<number>;
|
package/dist/esm/runner.js
DELETED
|
@@ -1,335 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
3
|
-
import { mkdir, readFile, realpath, rename, stat, unlink, writeFile } from 'node:fs/promises';
|
|
4
|
-
import { homedir } from 'node:os';
|
|
5
|
-
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
6
|
-
import spawn from 'cross-spawn-cb';
|
|
7
|
-
import lockfile from 'proper-lockfile';
|
|
8
|
-
import { loadLock, localEventName, matchesSource, samePath, sourceParts } from './apm.js';
|
|
9
|
-
import { loadConfig, recordId } from './config.js';
|
|
10
|
-
function inside(root, child) {
|
|
11
|
-
const subpath = relative(root, child);
|
|
12
|
-
return subpath === '' || subpath !== '..' && !subpath.startsWith(`..${sep}`) && !isAbsolute(subpath);
|
|
13
|
-
}
|
|
14
|
-
async function existingWithin(root, path, label) {
|
|
15
|
-
const rootReal = await realpath(root);
|
|
16
|
-
const candidate = resolve(rootReal, path);
|
|
17
|
-
if (!inside(rootReal, candidate)) throw new Error(`${label} escapes ${root}`);
|
|
18
|
-
const candidateReal = await realpath(candidate);
|
|
19
|
-
if (!inside(rootReal, candidateReal)) throw new Error(`${label} resolves outside ${root}`);
|
|
20
|
-
return candidateReal;
|
|
21
|
-
}
|
|
22
|
-
function pluginRoot(plugin, apmHome) {
|
|
23
|
-
return join(apmHome, 'apm_modules', plugin.repo, plugin.path);
|
|
24
|
-
}
|
|
25
|
-
function missing(error) {
|
|
26
|
-
return !!error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT';
|
|
27
|
-
}
|
|
28
|
-
async function existingOrNone(root, path, label) {
|
|
29
|
-
try {
|
|
30
|
-
return await existingWithin(root, path, label);
|
|
31
|
-
} catch (error) {
|
|
32
|
-
if (missing(error)) return undefined;
|
|
33
|
-
throw error;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
const SKILL_ROOTS = [
|
|
37
|
-
'.agents/skills/',
|
|
38
|
-
'.hermes/skills/',
|
|
39
|
-
'.claude/skills/'
|
|
40
|
-
];
|
|
41
|
-
function deployedSkillFolders(plugin, skill) {
|
|
42
|
-
const folders = new Set();
|
|
43
|
-
for (const file of plugin.deployedFiles){
|
|
44
|
-
const parts = file.split('/');
|
|
45
|
-
const index = parts.lastIndexOf('skills');
|
|
46
|
-
if (index < 0 || parts[index + 1] !== skill) continue;
|
|
47
|
-
const deployment = parts.slice(0, index + 2).join('/');
|
|
48
|
-
if (SKILL_ROOTS.some((candidate)=>deployment.startsWith(candidate))) folders.add(deployment);
|
|
49
|
-
}
|
|
50
|
-
return [
|
|
51
|
-
...folders
|
|
52
|
-
];
|
|
53
|
-
}
|
|
54
|
-
// APM's kept copy (`apm_modules/...`) is a destination only when the lock names no other copy: a target such as copilot reads it in place.
|
|
55
|
-
// When the lock names a native plugin root or deployed skill copies, the kept copy is APM's cache and is never used, even if the listed copies are missing on disk (they are skipped, and check reports them).
|
|
56
|
-
async function destinations(plugin, policy, home, apmHome) {
|
|
57
|
-
var _plugin_nativePluginRoot;
|
|
58
|
-
const found = new Set();
|
|
59
|
-
const add = (path)=>{
|
|
60
|
-
if (path) found.add(path);
|
|
61
|
-
};
|
|
62
|
-
const nativeRoot = ((_plugin_nativePluginRoot = plugin.nativePluginRoot) === null || _plugin_nativePluginRoot === void 0 ? void 0 : _plugin_nativePluginRoot.startsWith('.agents/plugins/')) ? plugin.nativePluginRoot.slice('.agents/plugins/'.length) : undefined;
|
|
63
|
-
if (!policy.skill) {
|
|
64
|
-
if (!nativeRoot) return [
|
|
65
|
-
await existingWithin(join(apmHome, 'apm_modules'), join(plugin.repo, plugin.path), 'kept plugin')
|
|
66
|
-
];
|
|
67
|
-
add(await existingOrNone(join(home, '.agents', 'plugins'), nativeRoot, 'native plugin'));
|
|
68
|
-
if (!found.size) throw new Error(`no native plugin copy found for ${plugin.repo}`);
|
|
69
|
-
return [
|
|
70
|
-
...found
|
|
71
|
-
];
|
|
72
|
-
}
|
|
73
|
-
const deployed = deployedSkillFolders(plugin, policy.skill);
|
|
74
|
-
if (!nativeRoot && !deployed.length) {
|
|
75
|
-
const kept = await existingOrNone(pluginRoot(plugin, apmHome), `skills/${policy.skill}`, `kept skill ${policy.skill}`);
|
|
76
|
-
if (!kept) throw new Error(`no deployed copy found for skill ${policy.skill}`);
|
|
77
|
-
return [
|
|
78
|
-
kept
|
|
79
|
-
];
|
|
80
|
-
}
|
|
81
|
-
if (nativeRoot) add(await existingOrNone(join(home, '.agents', 'plugins'), `${nativeRoot}/skills/${policy.skill}`, `native skill ${policy.skill}`));
|
|
82
|
-
for (const deployment of deployed)add(await existingOrNone(home, deployment, `skill ${policy.skill}`));
|
|
83
|
-
if (!found.size) throw new Error(`no deployed copy found for skill ${policy.skill}`);
|
|
84
|
-
return [
|
|
85
|
-
...found
|
|
86
|
-
];
|
|
87
|
-
}
|
|
88
|
-
async function readState(path) {
|
|
89
|
-
if (!existsSync(path)) return {
|
|
90
|
-
version: 2,
|
|
91
|
-
receipts: {}
|
|
92
|
-
};
|
|
93
|
-
const value = JSON.parse(await readFile(path, 'utf8'));
|
|
94
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('state must be an object');
|
|
95
|
-
const item = value;
|
|
96
|
-
if (item.version !== 1 && item.version !== 2 || !item.receipts || typeof item.receipts !== 'object' || Array.isArray(item.receipts)) throw new Error('unsupported state format');
|
|
97
|
-
const receipts = {};
|
|
98
|
-
for (const [key, receipt] of Object.entries(item.receipts)){
|
|
99
|
-
if (item.version === 1 && typeof receipt === 'string') receipts[key] = {
|
|
100
|
-
digest: receipt,
|
|
101
|
-
revision: ''
|
|
102
|
-
};
|
|
103
|
-
else if (item.version === 2 && receipt && typeof receipt === 'object' && typeof receipt.digest === 'string' && typeof receipt.revision === 'string') receipts[key] = receipt;
|
|
104
|
-
else throw new Error('invalid state receipt');
|
|
105
|
-
}
|
|
106
|
-
return {
|
|
107
|
-
version: 2,
|
|
108
|
-
receipts
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
async function saveState(path, state) {
|
|
112
|
-
const temp = join(dirname(path), `.state-${process.pid}-${Date.now()}.tmp`);
|
|
113
|
-
try {
|
|
114
|
-
await writeFile(temp, `${JSON.stringify(state, null, 2)}\n`, {
|
|
115
|
-
mode: 0o600,
|
|
116
|
-
flag: 'wx'
|
|
117
|
-
});
|
|
118
|
-
await rename(temp, path);
|
|
119
|
-
} catch (error) {
|
|
120
|
-
try {
|
|
121
|
-
await unlink(temp);
|
|
122
|
-
} catch {
|
|
123
|
-
/* preserve original error */ }
|
|
124
|
-
throw error;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
function receiptKey(policy, destination) {
|
|
128
|
-
return JSON.stringify([
|
|
129
|
-
recordId(policy),
|
|
130
|
-
destination
|
|
131
|
-
]);
|
|
132
|
-
}
|
|
133
|
-
function digest(policy, command) {
|
|
134
|
-
return createHash('sha256').update(JSON.stringify([
|
|
135
|
-
recordId(policy),
|
|
136
|
-
command
|
|
137
|
-
])).digest('hex');
|
|
138
|
-
}
|
|
139
|
-
// The platform shell runs the configured string as written, as with npm and Node's `shell` option.
|
|
140
|
-
async function execute(command, cwd, environment) {
|
|
141
|
-
await spawn(command, [], {
|
|
142
|
-
cwd,
|
|
143
|
-
env: environment,
|
|
144
|
-
stdio: [
|
|
145
|
-
'ignore',
|
|
146
|
-
'inherit',
|
|
147
|
-
'inherit'
|
|
148
|
-
],
|
|
149
|
-
shell: true
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
function receiptRecord(key) {
|
|
153
|
-
try {
|
|
154
|
-
return JSON.parse(key)[0];
|
|
155
|
-
} catch {
|
|
156
|
-
return undefined;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
function lockLoadError(error) {
|
|
160
|
-
return !!error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT';
|
|
161
|
-
}
|
|
162
|
-
export async function runLifecycle(mode, options = {}) {
|
|
163
|
-
var _options_home, _options_apmHome, _options_configPath, _options_environment, _options_output;
|
|
164
|
-
const home = resolve((_options_home = options.home) !== null && _options_home !== void 0 ? _options_home : homedir());
|
|
165
|
-
const apmHome = resolve((_options_apmHome = options.apmHome) !== null && _options_apmHome !== void 0 ? _options_apmHome : join(home, '.apm'));
|
|
166
|
-
const configPath = (_options_configPath = options.configPath) !== null && _options_configPath !== void 0 ? _options_configPath : join(home, '.config', 'agent-plugin-lifecycle', 'config.json');
|
|
167
|
-
const environment = (_options_environment = options.environment) !== null && _options_environment !== void 0 ? _options_environment : process.env;
|
|
168
|
-
const output = (_options_output = options.output) !== null && _options_output !== void 0 ? _options_output : console.log;
|
|
169
|
-
const config = await loadConfig(configPath);
|
|
170
|
-
let locked;
|
|
171
|
-
try {
|
|
172
|
-
locked = await loadLock(join(apmHome, 'apm.lock.yaml'));
|
|
173
|
-
} catch (error) {
|
|
174
|
-
var _options_event;
|
|
175
|
-
if (mode === 'run' && ((_options_event = options.event) === null || _options_event === void 0 ? void 0 : _options_event.event) === 'post-uninstall' && lockLoadError(error)) {
|
|
176
|
-
const apmDirectory = await stat(apmHome);
|
|
177
|
-
if (!apmDirectory.isDirectory()) throw error;
|
|
178
|
-
locked = [];
|
|
179
|
-
} else if (mode === 'check' && lockLoadError(error)) {
|
|
180
|
-
output('nothing installed');
|
|
181
|
-
return 0;
|
|
182
|
-
} else throw error;
|
|
183
|
-
}
|
|
184
|
-
const statePath = join(dirname(configPath), 'state.json');
|
|
185
|
-
if (mode === 'run') await mkdir(dirname(statePath), {
|
|
186
|
-
recursive: true,
|
|
187
|
-
mode: 0o700
|
|
188
|
-
});
|
|
189
|
-
const release = mode === 'run' ? await lockfile.lock(dirname(statePath), {
|
|
190
|
-
realpath: false
|
|
191
|
-
}) : undefined;
|
|
192
|
-
try {
|
|
193
|
-
var _ref;
|
|
194
|
-
var _options_event1, _options_event2;
|
|
195
|
-
const state = await readState(statePath);
|
|
196
|
-
let failed = 0;
|
|
197
|
-
if (mode === 'run' && ((_options_event1 = options.event) === null || _options_event1 === void 0 ? void 0 : _options_event1.event) === 'post-uninstall') {
|
|
198
|
-
const eventNames = new Set(options.event.packages.map(({ name })=>name));
|
|
199
|
-
for (const policy of config.plugins){
|
|
200
|
-
var _ref1, _ref2;
|
|
201
|
-
const id = recordId(policy);
|
|
202
|
-
const receiptKeys = Object.keys(state.receipts).filter((key)=>{
|
|
203
|
-
try {
|
|
204
|
-
return JSON.parse(key)[0] === id;
|
|
205
|
-
} catch {
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
if (!receiptKeys.length) continue;
|
|
210
|
-
const sourceCandidate = policy.source.startsWith('.') || isAbsolute(policy.source) ? locked.find((plugin)=>plugin.localPath !== undefined && samePath(policy.source, plugin.localPath)) : locked.find((plugin)=>{
|
|
211
|
-
var _policy_path;
|
|
212
|
-
return matchesSource(policy.source, plugin) && (plugin.path === ((_policy_path = policy.path) !== null && _policy_path !== void 0 ? _policy_path : '.') || plugin.localPath !== undefined);
|
|
213
|
-
});
|
|
214
|
-
const sourcePartsValue = sourceParts(policy.source);
|
|
215
|
-
const removedNameMatch = eventNames.has((_ref1 = sourceCandidate === null || sourceCandidate === void 0 ? void 0 : sourceCandidate.repo) !== null && _ref1 !== void 0 ? _ref1 : '') || eventNames.has(sourceCandidate ? `${sourceCandidate.host}/${sourceCandidate.repo}` : '') || eventNames.has((_ref2 = sourcePartsValue === null || sourcePartsValue === void 0 ? void 0 : sourcePartsValue.repo) !== null && _ref2 !== void 0 ? _ref2 : '') || eventNames.has(sourcePartsValue ? `${sourcePartsValue.host}/${sourcePartsValue.repo}` : '') || // APM names a removed subfolder plugin `owner/repo/<folder>` (install and update events name it `owner/repo`); exact match only, so removing one folder never matches another plugin of the repository
|
|
216
|
-
!!sourcePartsValue && !!policy.path && policy.path !== '.' && (eventNames.has(`${sourcePartsValue.repo}/${policy.path}`) || eventNames.has(`${sourcePartsValue.host}/${sourcePartsValue.repo}/${policy.path}`)) || eventNames.has(localEventName(policy.source)) || eventNames.has(policy.source);
|
|
217
|
-
const anyStillInstalled = locked.some((plugin)=>{
|
|
218
|
-
var _policy_path;
|
|
219
|
-
return matchesSource(policy.source, plugin) && plugin.path === ((_policy_path = policy.path) !== null && _policy_path !== void 0 ? _policy_path : '.');
|
|
220
|
-
});
|
|
221
|
-
if (anyStillInstalled || !removedNameMatch) continue;
|
|
222
|
-
// APM keeps a folder holding files it did not write; report it, delete nothing
|
|
223
|
-
for (const key of receiptKeys){
|
|
224
|
-
const destination = JSON.parse(key)[1];
|
|
225
|
-
if (existsSync(destination)) output(`left ${destination}`);
|
|
226
|
-
}
|
|
227
|
-
const command = policy['post-uninstall'];
|
|
228
|
-
if (!command) {
|
|
229
|
-
for (const key of receiptKeys)delete state.receipts[key];
|
|
230
|
-
await saveState(statePath, state);
|
|
231
|
-
continue;
|
|
232
|
-
}
|
|
233
|
-
try {
|
|
234
|
-
await execute(command, home, environment);
|
|
235
|
-
for (const key of receiptKeys)delete state.receipts[key];
|
|
236
|
-
await saveState(statePath, state);
|
|
237
|
-
output(`cleaned ${id}`);
|
|
238
|
-
} catch (error) {
|
|
239
|
-
output(`failed cleanup ${id}: ${error instanceof Error ? error.message : String(error)}`);
|
|
240
|
-
failed++;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return failed ? 1 : 0;
|
|
244
|
-
}
|
|
245
|
-
if (mode === 'run' && !options.event) throw new Error('run requires an APM event');
|
|
246
|
-
const event = (_ref = (_options_event2 = options.event) === null || _options_event2 === void 0 ? void 0 : _options_event2.event) !== null && _ref !== void 0 ? _ref : 'post-install';
|
|
247
|
-
let installed = 0;
|
|
248
|
-
for (const policy of config.plugins){
|
|
249
|
-
var _policy_postupdate;
|
|
250
|
-
const command = event === 'post-update' ? (_policy_postupdate = policy['post-update']) !== null && _policy_postupdate !== void 0 ? _policy_postupdate : policy['post-install'] : policy['post-install'];
|
|
251
|
-
if (!command) continue;
|
|
252
|
-
const matches = locked.filter((plugin)=>{
|
|
253
|
-
var _policy_path;
|
|
254
|
-
return matchesSource(policy.source, plugin) && plugin.path === ((_policy_path = policy.path) !== null && _policy_path !== void 0 ? _policy_path : '.');
|
|
255
|
-
});
|
|
256
|
-
if (matches.length > 1) {
|
|
257
|
-
output(`failed ambiguous source/path record ${recordId(policy)}`);
|
|
258
|
-
failed++;
|
|
259
|
-
continue;
|
|
260
|
-
}
|
|
261
|
-
if (!matches.length) {
|
|
262
|
-
if (mode === 'run') output(`skipped source not installed ${recordId(policy)}`);
|
|
263
|
-
continue;
|
|
264
|
-
}
|
|
265
|
-
installed++;
|
|
266
|
-
const plugin = matches[0];
|
|
267
|
-
const id = recordId(policy);
|
|
268
|
-
try {
|
|
269
|
-
const recorded = Object.keys(state.receipts).filter((key)=>receiptRecord(key) === id);
|
|
270
|
-
let found;
|
|
271
|
-
try {
|
|
272
|
-
found = await destinations(plugin, policy, home, apmHome);
|
|
273
|
-
} catch (error) {
|
|
274
|
-
// check still reports a copy that was recorded and is now gone
|
|
275
|
-
if (mode === 'check' && recorded.length && (missing(error) || error instanceof Error && error.message.startsWith('no '))) found = [];
|
|
276
|
-
else throw error;
|
|
277
|
-
}
|
|
278
|
-
const gone = recorded.filter((key)=>!existsSync(JSON.parse(key)[1]));
|
|
279
|
-
if (mode === 'run') {
|
|
280
|
-
// a copy that no longer exists loses its receipt, so the copy APM recreates in its place runs again
|
|
281
|
-
for (const key of gone)delete state.receipts[key];
|
|
282
|
-
if (gone.length) await saveState(statePath, state);
|
|
283
|
-
} else {
|
|
284
|
-
const validDigests = [
|
|
285
|
-
policy['post-install'],
|
|
286
|
-
policy['post-update']
|
|
287
|
-
].filter((item)=>!!item).map((item)=>digest(policy, item));
|
|
288
|
-
for (const key of gone){
|
|
289
|
-
const receipt = state.receipts[key];
|
|
290
|
-
if (validDigests.includes(receipt.digest) && receipt.revision === plugin.revision) {
|
|
291
|
-
output(`broken ${id} ${JSON.parse(key)[1]}`);
|
|
292
|
-
failed++;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
for (const destination of found){
|
|
296
|
-
const receipt = state.receipts[receiptKey(policy, destination)];
|
|
297
|
-
let status = 'missing';
|
|
298
|
-
if (receipt) {
|
|
299
|
-
const current = validDigests.includes(receipt.digest) && receipt.revision === plugin.revision;
|
|
300
|
-
status = current ? 'ok' : 'stale';
|
|
301
|
-
}
|
|
302
|
-
output(`${status} ${id} ${destination}`);
|
|
303
|
-
if (status !== 'ok') failed++;
|
|
304
|
-
}
|
|
305
|
-
continue;
|
|
306
|
-
}
|
|
307
|
-
for (const destination of found){
|
|
308
|
-
const key = receiptKey(policy, destination);
|
|
309
|
-
const wanted = digest(policy, command);
|
|
310
|
-
const receipt = state.receipts[key];
|
|
311
|
-
if (receipt && receipt.digest === wanted && receipt.revision === plugin.revision) {
|
|
312
|
-
output(`current ${id} ${destination}`);
|
|
313
|
-
continue;
|
|
314
|
-
}
|
|
315
|
-
delete state.receipts[key];
|
|
316
|
-
await saveState(statePath, state);
|
|
317
|
-
await execute(command, destination, environment);
|
|
318
|
-
state.receipts[key] = {
|
|
319
|
-
digest: wanted,
|
|
320
|
-
revision: plugin.revision
|
|
321
|
-
};
|
|
322
|
-
await saveState(statePath, state);
|
|
323
|
-
output(`ran ${id} ${destination}`);
|
|
324
|
-
}
|
|
325
|
-
} catch (error) {
|
|
326
|
-
output(`failed ${id}: ${error instanceof Error ? error.message : String(error)}`);
|
|
327
|
-
failed++;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
if (mode === 'check' && !installed && !failed) output('nothing installed');
|
|
331
|
-
return failed ? 1 : 0;
|
|
332
|
-
} finally{
|
|
333
|
-
await (release === null || release === void 0 ? void 0 : release());
|
|
334
|
-
}
|
|
335
|
-
}
|
package/dist/esm/runner.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/agent-plugin-lifecycle/src/runner.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport { existsSync } from 'node:fs';\nimport { mkdir, readFile, realpath, rename, stat, unlink, writeFile } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';\nimport spawn from 'cross-spawn-cb';\nimport lockfile from 'proper-lockfile';\nimport { type LockedPlugin, loadLock, localEventName, matchesSource, samePath, sourceParts } from './apm.js';\nimport { loadConfig, type PluginPolicy, recordId } from './config.js';\n\nexport type Mode = 'run' | 'check';\nexport interface LifecycleEvent {\n schema_version: 1;\n event: 'post-install' | 'post-update' | 'post-uninstall';\n scope: 'user';\n packages: { name: string; reference: string | null }[];\n}\n// `revision` is the locked revision the command last ran against; '' is a version 1 receipt, whose revision was never recorded.\ninterface Receipt {\n digest: string;\n revision: string;\n}\ninterface State {\n version: 2;\n receipts: Record<string, Receipt>;\n}\nexport interface RunOptions {\n home?: string;\n apmHome?: string;\n configPath?: string;\n environment?: NodeJS.ProcessEnv;\n output?: (line: string) => void;\n event?: LifecycleEvent;\n}\nfunction inside(root: string, child: string): boolean {\n const subpath = relative(root, child);\n return subpath === '' || (subpath !== '..' && !subpath.startsWith(`..${sep}`) && !isAbsolute(subpath));\n}\nasync function existingWithin(root: string, path: string, label: string): Promise<string> {\n const rootReal = await realpath(root);\n const candidate = resolve(rootReal, path);\n if (!inside(rootReal, candidate)) throw new Error(`${label} escapes ${root}`);\n const candidateReal = await realpath(candidate);\n if (!inside(rootReal, candidateReal)) throw new Error(`${label} resolves outside ${root}`);\n return candidateReal;\n}\nfunction pluginRoot(plugin: LockedPlugin, apmHome: string): string {\n return join(apmHome, 'apm_modules', plugin.repo, plugin.path);\n}\nfunction missing(error: unknown): boolean {\n return !!error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT';\n}\nasync function existingOrNone(root: string, path: string, label: string): Promise<string | undefined> {\n try {\n return await existingWithin(root, path, label);\n } catch (error) {\n if (missing(error)) return undefined;\n throw error;\n }\n}\nconst SKILL_ROOTS = ['.agents/skills/', '.hermes/skills/', '.claude/skills/'];\nfunction deployedSkillFolders(plugin: LockedPlugin, skill: string): string[] {\n const folders = new Set<string>();\n for (const file of plugin.deployedFiles) {\n const parts = file.split('/');\n const index = parts.lastIndexOf('skills');\n if (index < 0 || parts[index + 1] !== skill) continue;\n const deployment = parts.slice(0, index + 2).join('/');\n if (SKILL_ROOTS.some((candidate) => deployment.startsWith(candidate))) folders.add(deployment);\n }\n return [...folders];\n}\n// APM's kept copy (`apm_modules/...`) is a destination only when the lock names no other copy: a target such as copilot reads it in place.\n// When the lock names a native plugin root or deployed skill copies, the kept copy is APM's cache and is never used, even if the listed copies are missing on disk (they are skipped, and check reports them).\nasync function destinations(plugin: LockedPlugin, policy: PluginPolicy, home: string, apmHome: string): Promise<string[]> {\n const found = new Set<string>();\n const add = (path: string | undefined) => {\n if (path) found.add(path);\n };\n const nativeRoot = plugin.nativePluginRoot?.startsWith('.agents/plugins/') ? plugin.nativePluginRoot.slice('.agents/plugins/'.length) : undefined;\n if (!policy.skill) {\n if (!nativeRoot) return [await existingWithin(join(apmHome, 'apm_modules'), join(plugin.repo, plugin.path), 'kept plugin')];\n add(await existingOrNone(join(home, '.agents', 'plugins'), nativeRoot, 'native plugin'));\n if (!found.size) throw new Error(`no native plugin copy found for ${plugin.repo}`);\n return [...found];\n }\n const deployed = deployedSkillFolders(plugin, policy.skill);\n if (!nativeRoot && !deployed.length) {\n const kept = await existingOrNone(pluginRoot(plugin, apmHome), `skills/${policy.skill}`, `kept skill ${policy.skill}`);\n if (!kept) throw new Error(`no deployed copy found for skill ${policy.skill}`);\n return [kept];\n }\n if (nativeRoot) add(await existingOrNone(join(home, '.agents', 'plugins'), `${nativeRoot}/skills/${policy.skill}`, `native skill ${policy.skill}`));\n for (const deployment of deployed) add(await existingOrNone(home, deployment, `skill ${policy.skill}`));\n if (!found.size) throw new Error(`no deployed copy found for skill ${policy.skill}`);\n return [...found];\n}\nasync function readState(path: string): Promise<State> {\n if (!existsSync(path)) return { version: 2, receipts: {} };\n const value: unknown = JSON.parse(await readFile(path, 'utf8'));\n if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('state must be an object');\n const item = value as Record<string, unknown>;\n if ((item.version !== 1 && item.version !== 2) || !item.receipts || typeof item.receipts !== 'object' || Array.isArray(item.receipts)) throw new Error('unsupported state format');\n const receipts: Record<string, Receipt> = {};\n for (const [key, receipt] of Object.entries(item.receipts)) {\n if (item.version === 1 && typeof receipt === 'string') receipts[key] = { digest: receipt, revision: '' };\n else if (item.version === 2 && receipt && typeof receipt === 'object' && typeof (receipt as Receipt).digest === 'string' && typeof (receipt as Receipt).revision === 'string') receipts[key] = receipt as Receipt;\n else throw new Error('invalid state receipt');\n }\n return { version: 2, receipts };\n}\nasync function saveState(path: string, state: State): Promise<void> {\n const temp = join(dirname(path), `.state-${process.pid}-${Date.now()}.tmp`);\n try {\n await writeFile(temp, `${JSON.stringify(state, null, 2)}\\n`, { mode: 0o600, flag: 'wx' });\n await rename(temp, path);\n } catch (error) {\n try {\n await unlink(temp);\n } catch {\n /* preserve original error */\n }\n throw error;\n }\n}\nfunction receiptKey(policy: PluginPolicy, destination: string): string {\n return JSON.stringify([recordId(policy), destination]);\n}\nfunction digest(policy: PluginPolicy, command: string): string {\n return createHash('sha256')\n .update(JSON.stringify([recordId(policy), command]))\n .digest('hex');\n}\n// The platform shell runs the configured string as written, as with npm and Node's `shell` option.\nasync function execute(command: string, cwd: string, environment: NodeJS.ProcessEnv): Promise<void> {\n await spawn(command, [], { cwd, env: environment, stdio: ['ignore', 'inherit', 'inherit'], shell: true });\n}\nfunction receiptRecord(key: string): string | undefined {\n try {\n return JSON.parse(key)[0];\n } catch {\n return undefined;\n }\n}\nfunction lockLoadError(error: unknown): boolean {\n return !!error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT';\n}\nexport async function runLifecycle(mode: Mode, options: RunOptions = {}): Promise<number> {\n const home = resolve(options.home ?? homedir());\n const apmHome = resolve(options.apmHome ?? join(home, '.apm'));\n const configPath = options.configPath ?? join(home, '.config', 'agent-plugin-lifecycle', 'config.json');\n const environment = options.environment ?? process.env;\n const output = options.output ?? console.log;\n const config = await loadConfig(configPath);\n let locked: LockedPlugin[];\n try {\n locked = await loadLock(join(apmHome, 'apm.lock.yaml'));\n } catch (error) {\n if (mode === 'run' && options.event?.event === 'post-uninstall' && lockLoadError(error)) {\n const apmDirectory = await stat(apmHome);\n if (!apmDirectory.isDirectory()) throw error;\n locked = [];\n } else if (mode === 'check' && lockLoadError(error)) {\n output('nothing installed');\n return 0;\n } else throw error;\n }\n const statePath = join(dirname(configPath), 'state.json');\n if (mode === 'run') await mkdir(dirname(statePath), { recursive: true, mode: 0o700 });\n const release = mode === 'run' ? await lockfile.lock(dirname(statePath), { realpath: false }) : undefined;\n try {\n const state = await readState(statePath);\n let failed = 0;\n if (mode === 'run' && options.event?.event === 'post-uninstall') {\n const eventNames = new Set(options.event.packages.map(({ name }) => name));\n for (const policy of config.plugins) {\n const id = recordId(policy);\n const receiptKeys = Object.keys(state.receipts).filter((key) => {\n try {\n return JSON.parse(key)[0] === id;\n } catch {\n return false;\n }\n });\n if (!receiptKeys.length) continue;\n const sourceCandidate =\n policy.source.startsWith('.') || isAbsolute(policy.source) ? locked.find((plugin) => plugin.localPath !== undefined && samePath(policy.source, plugin.localPath)) : locked.find((plugin) => matchesSource(policy.source, plugin) && (plugin.path === (policy.path ?? '.') || plugin.localPath !== undefined));\n const sourcePartsValue = sourceParts(policy.source);\n const removedNameMatch =\n eventNames.has(sourceCandidate?.repo ?? '') ||\n eventNames.has(sourceCandidate ? `${sourceCandidate.host}/${sourceCandidate.repo}` : '') ||\n eventNames.has(sourcePartsValue?.repo ?? '') ||\n eventNames.has(sourcePartsValue ? `${sourcePartsValue.host}/${sourcePartsValue.repo}` : '') ||\n // APM names a removed subfolder plugin `owner/repo/<folder>` (install and update events name it `owner/repo`); exact match only, so removing one folder never matches another plugin of the repository\n (!!sourcePartsValue && !!policy.path && policy.path !== '.' && (eventNames.has(`${sourcePartsValue.repo}/${policy.path}`) || eventNames.has(`${sourcePartsValue.host}/${sourcePartsValue.repo}/${policy.path}`))) ||\n eventNames.has(localEventName(policy.source)) ||\n eventNames.has(policy.source);\n const anyStillInstalled = locked.some((plugin) => matchesSource(policy.source, plugin) && plugin.path === (policy.path ?? '.'));\n if (anyStillInstalled || !removedNameMatch) continue;\n // APM keeps a folder holding files it did not write; report it, delete nothing\n for (const key of receiptKeys) {\n const destination: string = JSON.parse(key)[1];\n if (existsSync(destination)) output(`left ${destination}`);\n }\n const command = policy['post-uninstall'];\n if (!command) {\n for (const key of receiptKeys) delete state.receipts[key];\n await saveState(statePath, state);\n continue;\n }\n try {\n await execute(command, home, environment);\n for (const key of receiptKeys) delete state.receipts[key];\n await saveState(statePath, state);\n output(`cleaned ${id}`);\n } catch (error) {\n output(`failed cleanup ${id}: ${error instanceof Error ? error.message : String(error)}`);\n failed++;\n }\n }\n return failed ? 1 : 0;\n }\n if (mode === 'run' && !options.event) throw new Error('run requires an APM event');\n const event = options.event?.event ?? 'post-install';\n let installed = 0;\n for (const policy of config.plugins) {\n const command = event === 'post-update' ? (policy['post-update'] ?? policy['post-install']) : policy['post-install'];\n if (!command) continue;\n const matches = locked.filter((plugin) => matchesSource(policy.source, plugin) && plugin.path === (policy.path ?? '.'));\n if (matches.length > 1) {\n output(`failed ambiguous source/path record ${recordId(policy)}`);\n failed++;\n continue;\n }\n if (!matches.length) {\n if (mode === 'run') output(`skipped source not installed ${recordId(policy)}`);\n continue;\n }\n installed++;\n const plugin = matches[0];\n const id = recordId(policy);\n try {\n const recorded = Object.keys(state.receipts).filter((key) => receiptRecord(key) === id);\n let found: string[];\n try {\n found = await destinations(plugin, policy, home, apmHome);\n } catch (error) {\n // check still reports a copy that was recorded and is now gone\n if (mode === 'check' && recorded.length && (missing(error) || (error instanceof Error && error.message.startsWith('no ')))) found = [];\n else throw error;\n }\n const gone = recorded.filter((key) => !existsSync(JSON.parse(key)[1]));\n if (mode === 'run') {\n // a copy that no longer exists loses its receipt, so the copy APM recreates in its place runs again\n for (const key of gone) delete state.receipts[key];\n if (gone.length) await saveState(statePath, state);\n } else {\n const validDigests = [policy['post-install'], policy['post-update']].filter((item): item is string => !!item).map((item) => digest(policy, item));\n for (const key of gone) {\n const receipt = state.receipts[key];\n if (validDigests.includes(receipt.digest) && receipt.revision === plugin.revision) {\n output(`broken ${id} ${JSON.parse(key)[1]}`);\n failed++;\n }\n }\n for (const destination of found) {\n const receipt = state.receipts[receiptKey(policy, destination)];\n let status = 'missing';\n if (receipt) {\n const current = validDigests.includes(receipt.digest) && receipt.revision === plugin.revision;\n status = current ? 'ok' : 'stale';\n }\n output(`${status} ${id} ${destination}`);\n if (status !== 'ok') failed++;\n }\n continue;\n }\n for (const destination of found) {\n const key = receiptKey(policy, destination);\n const wanted = digest(policy, command);\n const receipt = state.receipts[key];\n if (receipt && receipt.digest === wanted && receipt.revision === plugin.revision) {\n output(`current ${id} ${destination}`);\n continue;\n }\n delete state.receipts[key];\n await saveState(statePath, state);\n await execute(command, destination, environment);\n state.receipts[key] = { digest: wanted, revision: plugin.revision };\n await saveState(statePath, state);\n output(`ran ${id} ${destination}`);\n }\n } catch (error) {\n output(`failed ${id}: ${error instanceof Error ? error.message : String(error)}`);\n failed++;\n }\n }\n if (mode === 'check' && !installed && !failed) output('nothing installed');\n return failed ? 1 : 0;\n } finally {\n await release?.();\n }\n}\n"],"names":["createHash","existsSync","mkdir","readFile","realpath","rename","stat","unlink","writeFile","homedir","dirname","isAbsolute","join","relative","resolve","sep","spawn","lockfile","loadLock","localEventName","matchesSource","samePath","sourceParts","loadConfig","recordId","inside","root","child","subpath","startsWith","existingWithin","path","label","rootReal","candidate","Error","candidateReal","pluginRoot","plugin","apmHome","repo","missing","error","code","existingOrNone","undefined","SKILL_ROOTS","deployedSkillFolders","skill","folders","Set","file","deployedFiles","parts","split","index","lastIndexOf","deployment","slice","some","add","destinations","policy","home","found","nativeRoot","nativePluginRoot","length","size","deployed","kept","readState","version","receipts","value","JSON","parse","Array","isArray","item","key","receipt","Object","entries","digest","revision","saveState","state","temp","process","pid","Date","now","stringify","mode","flag","receiptKey","destination","command","update","execute","cwd","environment","env","stdio","shell","receiptRecord","lockLoadError","runLifecycle","options","configPath","output","console","log","config","locked","event","apmDirectory","isDirectory","statePath","recursive","release","lock","failed","eventNames","packages","map","name","plugins","id","receiptKeys","keys","filter","sourceCandidate","source","find","localPath","sourcePartsValue","removedNameMatch","has","host","anyStillInstalled","message","String","installed","matches","recorded","gone","validDigests","includes","status","current","wanted"],"mappings":"AAAA,SAASA,UAAU,QAAQ,cAAc;AACzC,SAASC,UAAU,QAAQ,UAAU;AACrC,SAASC,KAAK,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,IAAI,EAAEC,MAAM,EAAEC,SAAS,QAAQ,mBAAmB;AAC9F,SAASC,OAAO,QAAQ,UAAU;AAClC,SAASC,OAAO,EAAEC,UAAU,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,GAAG,QAAQ,YAAY;AAC9E,OAAOC,WAAW,iBAAiB;AACnC,OAAOC,cAAc,kBAAkB;AACvC,SAA4BC,QAAQ,EAAEC,cAAc,EAAEC,aAAa,EAAEC,QAAQ,EAAEC,WAAW,QAAQ,WAAW;AAC7G,SAASC,UAAU,EAAqBC,QAAQ,QAAQ,cAAc;AA0BtE,SAASC,OAAOC,IAAY,EAAEC,KAAa;IACzC,MAAMC,UAAUf,SAASa,MAAMC;IAC/B,OAAOC,YAAY,MAAOA,YAAY,QAAQ,CAACA,QAAQC,UAAU,CAAC,CAAC,EAAE,EAAEd,KAAK,KAAK,CAACJ,WAAWiB;AAC/F;AACA,eAAeE,eAAeJ,IAAY,EAAEK,IAAY,EAAEC,KAAa;IACrE,MAAMC,WAAW,MAAM7B,SAASsB;IAChC,MAAMQ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