agent-plugin-lifecycle 0.1.1 → 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.
Files changed (178) hide show
  1. package/README.md +256 -57
  2. package/bin/cli.js +8 -1
  3. package/dist/cjs/apm.d.cts +62 -13
  4. package/dist/cjs/apm.d.ts +62 -13
  5. package/dist/cjs/apm.js +534 -115
  6. package/dist/cjs/apm.js.map +1 -1
  7. package/dist/cjs/approvals.d.cts +26 -0
  8. package/dist/cjs/approvals.d.ts +26 -0
  9. package/dist/cjs/approvals.js +302 -0
  10. package/dist/cjs/approvals.js.map +1 -0
  11. package/dist/cjs/cli/index.d.cts +5 -0
  12. package/dist/cjs/cli/index.d.ts +5 -0
  13. package/dist/cjs/cli/index.js +53 -0
  14. package/dist/cjs/cli/index.js.map +1 -0
  15. package/dist/cjs/cli/install.d.cts +17 -0
  16. package/dist/cjs/cli/install.d.ts +17 -0
  17. package/dist/cjs/cli/install.js +308 -0
  18. package/dist/cjs/cli/install.js.map +1 -0
  19. package/dist/cjs/cli/report.d.cts +6 -0
  20. package/dist/cjs/cli/report.d.ts +6 -0
  21. package/dist/cjs/cli/report.js +47 -0
  22. package/dist/cjs/cli/report.js.map +1 -0
  23. package/dist/cjs/cli/status.d.cts +2 -0
  24. package/dist/cjs/cli/status.d.ts +2 -0
  25. package/dist/cjs/cli/status.js +222 -0
  26. package/dist/cjs/cli/status.js.map +1 -0
  27. package/dist/cjs/cli/types.d.cts +10 -0
  28. package/dist/cjs/cli/types.d.ts +10 -0
  29. package/dist/cjs/cli/types.js +6 -0
  30. package/dist/cjs/cli/types.js.map +1 -0
  31. package/dist/cjs/cli/usage.d.cts +2 -0
  32. package/dist/cjs/cli/usage.d.ts +2 -0
  33. package/dist/cjs/cli/usage.js +21 -0
  34. package/dist/cjs/cli/usage.js.map +1 -0
  35. package/dist/cjs/cli.d.cts +2 -1
  36. package/dist/cjs/cli.d.ts +2 -1
  37. package/dist/cjs/cli.js +65 -204
  38. package/dist/cjs/cli.js.map +1 -1
  39. package/dist/cjs/constants.d.cts +35 -0
  40. package/dist/cjs/constants.d.ts +35 -0
  41. package/dist/cjs/constants.js +115 -0
  42. package/dist/cjs/constants.js.map +1 -0
  43. package/dist/cjs/copies.d.cts +40 -0
  44. package/dist/cjs/copies.d.ts +40 -0
  45. package/dist/cjs/copies.js +937 -0
  46. package/dist/cjs/copies.js.map +1 -0
  47. package/dist/cjs/index.d.cts +3 -6
  48. package/dist/cjs/index.d.ts +3 -6
  49. package/dist/cjs/index.js +20 -19
  50. package/dist/cjs/index.js.map +1 -1
  51. package/dist/cjs/install.d.cts +6 -0
  52. package/dist/cjs/install.d.ts +6 -0
  53. package/dist/cjs/install.js +511 -0
  54. package/dist/cjs/install.js.map +1 -0
  55. package/dist/cjs/lib/errors.d.cts +5 -0
  56. package/dist/cjs/lib/errors.d.ts +5 -0
  57. package/dist/cjs/lib/errors.js +41 -0
  58. package/dist/cjs/lib/errors.js.map +1 -0
  59. package/dist/cjs/lib/object.d.cts +2 -0
  60. package/dist/cjs/lib/object.d.ts +2 -0
  61. package/dist/cjs/lib/object.js +18 -0
  62. package/dist/cjs/lib/object.js.map +1 -0
  63. package/dist/cjs/lib/options.d.cts +10 -0
  64. package/dist/cjs/lib/options.d.ts +10 -0
  65. package/dist/cjs/lib/options.js +26 -0
  66. package/dist/cjs/lib/options.js.map +1 -0
  67. package/dist/cjs/lib/run.d.cts +2 -0
  68. package/dist/cjs/lib/run.d.ts +2 -0
  69. package/dist/cjs/lib/run.js +40 -0
  70. package/dist/cjs/lib/run.js.map +1 -0
  71. package/dist/cjs/lib/store.d.cts +9 -0
  72. package/dist/cjs/lib/store.d.ts +9 -0
  73. package/dist/cjs/lib/store.js +418 -0
  74. package/dist/cjs/lib/store.js.map +1 -0
  75. package/dist/cjs/lib/visible.d.cts +9 -0
  76. package/dist/cjs/lib/visible.d.ts +9 -0
  77. package/dist/cjs/lib/visible.js +26 -0
  78. package/dist/cjs/lib/visible.js.map +1 -0
  79. package/dist/cjs/manifest.d.cts +4 -0
  80. package/dist/cjs/manifest.d.ts +4 -0
  81. package/dist/cjs/{config.js → manifest.js} +33 -94
  82. package/dist/cjs/manifest.js.map +1 -0
  83. package/dist/cjs/state.d.cts +17 -0
  84. package/dist/cjs/state.d.ts +17 -0
  85. package/dist/cjs/state.js +143 -0
  86. package/dist/cjs/state.js.map +1 -0
  87. package/dist/cjs/status.d.cts +3 -0
  88. package/dist/cjs/status.d.ts +3 -0
  89. package/dist/cjs/status.js +273 -0
  90. package/dist/cjs/status.js.map +1 -0
  91. package/dist/cjs/types.d.cts +39 -0
  92. package/dist/cjs/types.d.ts +39 -0
  93. package/dist/cjs/types.js +5 -0
  94. package/dist/cjs/types.js.map +1 -0
  95. package/dist/esm/apm.d.ts +62 -13
  96. package/dist/esm/apm.js +208 -96
  97. package/dist/esm/apm.js.map +1 -1
  98. package/dist/esm/approvals.d.ts +26 -0
  99. package/dist/esm/approvals.js +43 -0
  100. package/dist/esm/approvals.js.map +1 -0
  101. package/dist/esm/cli/index.d.ts +5 -0
  102. package/dist/esm/cli/index.js +5 -0
  103. package/dist/esm/cli/index.js.map +1 -0
  104. package/dist/esm/cli/install.d.ts +17 -0
  105. package/dist/esm/cli/install.js +89 -0
  106. package/dist/esm/cli/install.js.map +1 -0
  107. package/dist/esm/cli/report.d.ts +6 -0
  108. package/dist/esm/cli/report.js +21 -0
  109. package/dist/esm/cli/report.js.map +1 -0
  110. package/dist/esm/cli/status.d.ts +2 -0
  111. package/dist/esm/cli/status.js +41 -0
  112. package/dist/esm/cli/status.js.map +1 -0
  113. package/dist/esm/cli/types.d.ts +10 -0
  114. package/dist/esm/cli/types.js +2 -0
  115. package/dist/esm/cli/types.js.map +1 -0
  116. package/dist/esm/cli/usage.d.ts +2 -0
  117. package/dist/esm/cli/usage.js +2 -0
  118. package/dist/esm/cli/usage.js.map +1 -0
  119. package/dist/esm/cli.d.ts +2 -1
  120. package/dist/esm/cli.js +46 -65
  121. package/dist/esm/cli.js.map +1 -1
  122. package/dist/esm/constants.d.ts +35 -0
  123. package/dist/esm/constants.js +37 -0
  124. package/dist/esm/constants.js.map +1 -0
  125. package/dist/esm/copies.d.ts +40 -0
  126. package/dist/esm/copies.js +226 -0
  127. package/dist/esm/copies.js.map +1 -0
  128. package/dist/esm/index.d.ts +3 -6
  129. package/dist/esm/index.js +3 -3
  130. package/dist/esm/index.js.map +1 -1
  131. package/dist/esm/install.d.ts +6 -0
  132. package/dist/esm/install.js +116 -0
  133. package/dist/esm/install.js.map +1 -0
  134. package/dist/esm/lib/errors.d.ts +5 -0
  135. package/dist/esm/lib/errors.js +9 -0
  136. package/dist/esm/lib/errors.js.map +1 -0
  137. package/dist/esm/lib/object.d.ts +2 -0
  138. package/dist/esm/lib/object.js +3 -0
  139. package/dist/esm/lib/object.js.map +1 -0
  140. package/dist/esm/lib/options.d.ts +10 -0
  141. package/dist/esm/lib/options.js +15 -0
  142. package/dist/esm/lib/options.js.map +1 -0
  143. package/dist/esm/lib/run.d.ts +2 -0
  144. package/dist/esm/lib/run.js +29 -0
  145. package/dist/esm/lib/run.js.map +1 -0
  146. package/dist/esm/lib/store.d.ts +9 -0
  147. package/dist/esm/lib/store.js +91 -0
  148. package/dist/esm/lib/store.js.map +1 -0
  149. package/dist/esm/lib/visible.d.ts +9 -0
  150. package/dist/esm/lib/visible.js +12 -0
  151. package/dist/esm/lib/visible.js.map +1 -0
  152. package/dist/esm/manifest.d.ts +4 -0
  153. package/dist/esm/manifest.js +25 -0
  154. package/dist/esm/manifest.js.map +1 -0
  155. package/dist/esm/state.d.ts +17 -0
  156. package/dist/esm/state.js +32 -0
  157. package/dist/esm/state.js.map +1 -0
  158. package/dist/esm/status.d.ts +3 -0
  159. package/dist/esm/status.js +44 -0
  160. package/dist/esm/status.js.map +1 -0
  161. package/dist/esm/types.d.ts +39 -0
  162. package/dist/esm/types.js +1 -0
  163. package/dist/esm/types.js.map +1 -0
  164. package/package.json +25 -9
  165. package/config/config.example.json +0 -22
  166. package/dist/cjs/config.d.cts +0 -16
  167. package/dist/cjs/config.d.ts +0 -16
  168. package/dist/cjs/config.js.map +0 -1
  169. package/dist/cjs/runner.d.cts +0 -19
  170. package/dist/cjs/runner.d.ts +0 -19
  171. package/dist/cjs/runner.js +0 -1157
  172. package/dist/cjs/runner.js.map +0 -1
  173. package/dist/esm/config.d.ts +0 -16
  174. package/dist/esm/config.js +0 -74
  175. package/dist/esm/config.js.map +0 -1
  176. package/dist/esm/runner.d.ts +0 -19
  177. package/dist/esm/runner.js +0 -248
  178. package/dist/esm/runner.js.map +0 -1
@@ -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}\ninterface State {\n version: 1;\n receipts: Record<string, string>;\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}\nasync function destinations(plugin: LockedPlugin, policy: PluginPolicy, home: string, apmHome: string): Promise<string[]> {\n const output = new Set<string>();\n const root = pluginRoot(plugin, apmHome);\n if (!policy.skill) {\n output.add(await existingWithin(join(apmHome, 'apm_modules'), join(plugin.repo, plugin.path), 'kept plugin'));\n if (plugin.nativePluginRoot) {\n const nativeBase = join(home, '.agents', 'plugins');\n if (plugin.nativePluginRoot.startsWith('.agents/plugins/')) output.add(await existingWithin(nativeBase, plugin.nativePluginRoot.slice('.agents/plugins/'.length), 'native plugin'));\n }\n } else {\n try {\n output.add(await existingWithin(root, `skills/${policy.skill}`, `kept skill ${policy.skill}`));\n } catch (error) {\n if (!(error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT')) throw error;\n }\n if (plugin.nativePluginRoot?.startsWith('.agents/plugins/')) {\n const nativeRoot = plugin.nativePluginRoot.slice('.agents/plugins/'.length);\n try {\n output.add(await existingWithin(join(home, '.agents', 'plugins'), `${nativeRoot}/skills/${policy.skill}`, `native skill ${policy.skill}`));\n } catch (error) {\n if (!(error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT')) throw error;\n }\n }\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] !== policy.skill) continue;\n const deployment = parts.slice(0, index + 2).join('/');\n const prefix = ['.agents/skills/', '.hermes/skills/', '.claude/skills/'].find((candidate) => deployment.startsWith(candidate));\n if (prefix) output.add(await existingWithin(home, deployment, `skill ${policy.skill}`));\n }\n if (output.size === 0) throw new Error(`no deployed copy found for skill ${policy.skill}`);\n }\n return [...output];\n}\nasync function readState(path: string): Promise<State> {\n if (!existsSync(path)) return { version: 1, 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.receipts || typeof item.receipts !== 'object' || Array.isArray(item.receipts)) throw new Error('unsupported state format');\n if (Object.values(item.receipts).some((receipt) => typeof receipt !== 'string')) throw new Error('invalid state receipt');\n return item as unknown as State;\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 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 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 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 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 output(`skipped source not installed ${recordId(policy)}`);\n continue;\n }\n const plugin = matches[0];\n try {\n const found = await destinations(plugin, policy, home, apmHome);\n for (const destination of found) {\n const key = receiptKey(policy, destination);\n if (mode === 'check') {\n const validDigests = [policy['post-install'], policy['post-update']].filter((item): item is string => !!item).map((item) => digest(policy, item));\n const ready = validDigests.includes(state.receipts[key]);\n output(`${ready ? 'ok' : 'missing'} ${recordId(policy)} ${destination}`);\n if (!ready) failed++;\n } else {\n delete state.receipts[key];\n await saveState(statePath, state);\n await execute(command, destination, environment);\n state.receipts[key] = digest(policy, command);\n await saveState(statePath, state);\n output(`ran ${recordId(policy)} ${destination}`);\n }\n }\n } catch (error) {\n output(`failed ${recordId(policy)}: ${error instanceof Error ? error.message : String(error)}`);\n failed++;\n }\n }\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","destinations","policy","home","output","nativeBase","error","nativeRoot","Set","skill","add","nativePluginRoot","slice","length","code","file","parts","index","deployment","prefix","split","lastIndexOf","find","deployedFiles","size","readState","value","item","existsSync","version","receipts","JSON","parse","readFile","Array","isArray","Object","values","some","receipt","saveState","state","temp","dirname","Date","process","pid","now","writeFile","stringify","mode","flag","rename","unlink","receiptKey","destination","recordId","digest","command","createHash","update","execute","cwd","environment","spawn","env","stdio","shell","lockLoadError","options","configPath","config","locked","apmDirectory","statePath","release","failed","eventNames","event","homedir","console","log","loadConfig","loadLock","stat","isDirectory","mkdir","recursive","lockfile","lock","undefined","packages","map","name","id","receiptKeys","sourceCandidate","sourcePartsValue","removedNameMatch","anyStillInstalled","key","keys","filter","source","localPath","samePath","matchesSource","sourceParts","has","host","localEventName","message","String","plugins","matches","found","validDigests","ready","includes"],"mappings":";;;;+BAqHsBA;;;eAAAA;;;0BArHK;sBACA;wBACgD;sBACnD;wBAC0C;mEAChD;qEACG;mBAC6E;sBAC1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBxD,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,UAAUC,YAAY,MAAM,IAAII,MAAM,AAAC,GAAmBf,OAAjBS,OAAM,aAAgB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ACsE,IAAI;oCACvDhG,OAAO,AAAC,GAA8BoD,OAA5B6D,QAAQ,OAAO,WAAU,KAAuB9D,OAApBC,IAAAA,gBAAQ,EAACtD,SAAQ,KAAe,OAAZqD;oCAC1D,IAAI,CAAC8D,OAAOzC;;;;;;oCAEZ,OAAOnC,MAAMX,QAAQ,CAACsE,IAAI;oCAC1B;;wCAAM5D,UAAUkC,WAAWjC;;;oCAA3B;oCACA;;wCAAMoB,QAAQH,SAASH,aAAaQ;;;oCAApC;oCACAtB,MAAMX,QAAQ,CAACsE,IAAI,GAAG3C,OAAOvD,QAAQwD;oCACrC;;wCAAMlB,UAAUkC,WAAWjC;;;oCAA3B;oCACArC,OAAO,AAAC,OAA0BmD,OAApBC,IAAAA,gBAAQ,EAACtD,SAAQ,KAAe,OAAZqD;;;oCAbjC;;;;;;;;;;;;oCAAA;oCAAA;;;;;;;6CAAA,6BAAA;4CAAA;;;4CAAA;kDAAA;;;;;;;;;;;;oCAgBEjD;oCACPF,OAAO,AAAC,UAA8BE,OAArBkD,IAAAA,gBAAQ,EAACtD,SAAQ,MAA2D,OAAvDI,AAAK,YAALA,OAAiBX,SAAQW,MAAMyG,OAAO,GAAGC,OAAO1G;oCACtFsE;;;;;;;;;;;oBAEJ;oBApCK,aAAgBL,OAAO0C,OAAO;;;2BAA9B,8BAAA,SAAA;;;;;;;;;;;;oBAAA;;;;;;;;;;;;oBAAA;oBAAA;;;;;;;6BAAA,8BAAA;4BAAA;;;4BAAA;kCAAA;;;;;;;oBAqCL;;wBAAOrC,SAAS,IAAI;;;oBAEpB;;wBAAMD,oBAAAA,8BAAAA;;;oBAAN;;;;;;;;;;IAEJ"}
@@ -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>;
@@ -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
- }
@@ -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,IA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: '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>;
@@ -1,248 +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
- async function destinations(plugin, policy, home, apmHome) {
26
- const output = new Set();
27
- const root = pluginRoot(plugin, apmHome);
28
- if (!policy.skill) {
29
- output.add(await existingWithin(join(apmHome, 'apm_modules'), join(plugin.repo, plugin.path), 'kept plugin'));
30
- if (plugin.nativePluginRoot) {
31
- const nativeBase = join(home, '.agents', 'plugins');
32
- if (plugin.nativePluginRoot.startsWith('.agents/plugins/')) output.add(await existingWithin(nativeBase, plugin.nativePluginRoot.slice('.agents/plugins/'.length), 'native plugin'));
33
- }
34
- } else {
35
- var _plugin_nativePluginRoot;
36
- try {
37
- output.add(await existingWithin(root, `skills/${policy.skill}`, `kept skill ${policy.skill}`));
38
- } catch (error) {
39
- if (!(error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT')) throw error;
40
- }
41
- if ((_plugin_nativePluginRoot = plugin.nativePluginRoot) === null || _plugin_nativePluginRoot === void 0 ? void 0 : _plugin_nativePluginRoot.startsWith('.agents/plugins/')) {
42
- const nativeRoot = plugin.nativePluginRoot.slice('.agents/plugins/'.length);
43
- try {
44
- output.add(await existingWithin(join(home, '.agents', 'plugins'), `${nativeRoot}/skills/${policy.skill}`, `native skill ${policy.skill}`));
45
- } catch (error) {
46
- if (!(error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT')) throw error;
47
- }
48
- }
49
- for (const file of plugin.deployedFiles){
50
- const parts = file.split('/');
51
- const index = parts.lastIndexOf('skills');
52
- if (index < 0 || parts[index + 1] !== policy.skill) continue;
53
- const deployment = parts.slice(0, index + 2).join('/');
54
- const prefix = [
55
- '.agents/skills/',
56
- '.hermes/skills/',
57
- '.claude/skills/'
58
- ].find((candidate)=>deployment.startsWith(candidate));
59
- if (prefix) output.add(await existingWithin(home, deployment, `skill ${policy.skill}`));
60
- }
61
- if (output.size === 0) throw new Error(`no deployed copy found for skill ${policy.skill}`);
62
- }
63
- return [
64
- ...output
65
- ];
66
- }
67
- async function readState(path) {
68
- if (!existsSync(path)) return {
69
- version: 1,
70
- receipts: {}
71
- };
72
- const value = JSON.parse(await readFile(path, 'utf8'));
73
- if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('state must be an object');
74
- const item = value;
75
- if (item.version !== 1 || !item.receipts || typeof item.receipts !== 'object' || Array.isArray(item.receipts)) throw new Error('unsupported state format');
76
- if (Object.values(item.receipts).some((receipt)=>typeof receipt !== 'string')) throw new Error('invalid state receipt');
77
- return item;
78
- }
79
- async function saveState(path, state) {
80
- const temp = join(dirname(path), `.state-${process.pid}-${Date.now()}.tmp`);
81
- try {
82
- await writeFile(temp, `${JSON.stringify(state, null, 2)}\n`, {
83
- mode: 0o600,
84
- flag: 'wx'
85
- });
86
- await rename(temp, path);
87
- } catch (error) {
88
- try {
89
- await unlink(temp);
90
- } catch {
91
- /* preserve original error */ }
92
- throw error;
93
- }
94
- }
95
- function receiptKey(policy, destination) {
96
- return JSON.stringify([
97
- recordId(policy),
98
- destination
99
- ]);
100
- }
101
- function digest(policy, command) {
102
- return createHash('sha256').update(JSON.stringify([
103
- recordId(policy),
104
- command
105
- ])).digest('hex');
106
- }
107
- // The platform shell runs the configured string as written, as with npm and Node's `shell` option.
108
- async function execute(command, cwd, environment) {
109
- await spawn(command, [], {
110
- cwd,
111
- env: environment,
112
- stdio: [
113
- 'ignore',
114
- 'inherit',
115
- 'inherit'
116
- ],
117
- shell: true
118
- });
119
- }
120
- function lockLoadError(error) {
121
- return !!error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT';
122
- }
123
- export async function runLifecycle(mode, options = {}) {
124
- var _options_home, _options_apmHome, _options_configPath, _options_environment, _options_output;
125
- const home = resolve((_options_home = options.home) !== null && _options_home !== void 0 ? _options_home : homedir());
126
- const apmHome = resolve((_options_apmHome = options.apmHome) !== null && _options_apmHome !== void 0 ? _options_apmHome : join(home, '.apm'));
127
- const configPath = (_options_configPath = options.configPath) !== null && _options_configPath !== void 0 ? _options_configPath : join(home, '.config', 'agent-plugin-lifecycle', 'config.json');
128
- const environment = (_options_environment = options.environment) !== null && _options_environment !== void 0 ? _options_environment : process.env;
129
- const output = (_options_output = options.output) !== null && _options_output !== void 0 ? _options_output : console.log;
130
- const config = await loadConfig(configPath);
131
- let locked;
132
- try {
133
- locked = await loadLock(join(apmHome, 'apm.lock.yaml'));
134
- } catch (error) {
135
- var _options_event;
136
- if (mode === 'run' && ((_options_event = options.event) === null || _options_event === void 0 ? void 0 : _options_event.event) === 'post-uninstall' && lockLoadError(error)) {
137
- const apmDirectory = await stat(apmHome);
138
- if (!apmDirectory.isDirectory()) throw error;
139
- locked = [];
140
- } else throw error;
141
- }
142
- const statePath = join(dirname(configPath), 'state.json');
143
- if (mode === 'run') await mkdir(dirname(statePath), {
144
- recursive: true,
145
- mode: 0o700
146
- });
147
- const release = mode === 'run' ? await lockfile.lock(dirname(statePath), {
148
- realpath: false
149
- }) : undefined;
150
- try {
151
- var _ref;
152
- var _options_event1, _options_event2;
153
- const state = await readState(statePath);
154
- let failed = 0;
155
- if (mode === 'run' && ((_options_event1 = options.event) === null || _options_event1 === void 0 ? void 0 : _options_event1.event) === 'post-uninstall') {
156
- const eventNames = new Set(options.event.packages.map(({ name })=>name));
157
- for (const policy of config.plugins){
158
- var _ref1, _ref2;
159
- const id = recordId(policy);
160
- const receiptKeys = Object.keys(state.receipts).filter((key)=>{
161
- try {
162
- return JSON.parse(key)[0] === id;
163
- } catch {
164
- return false;
165
- }
166
- });
167
- if (!receiptKeys.length) continue;
168
- const sourceCandidate = policy.source.startsWith('.') || isAbsolute(policy.source) ? locked.find((plugin)=>plugin.localPath !== undefined && samePath(policy.source, plugin.localPath)) : locked.find((plugin)=>{
169
- var _policy_path;
170
- return matchesSource(policy.source, plugin) && (plugin.path === ((_policy_path = policy.path) !== null && _policy_path !== void 0 ? _policy_path : '.') || plugin.localPath !== undefined);
171
- });
172
- const sourcePartsValue = sourceParts(policy.source);
173
- 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
174
- !!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);
175
- const anyStillInstalled = locked.some((plugin)=>{
176
- var _policy_path;
177
- return matchesSource(policy.source, plugin) && plugin.path === ((_policy_path = policy.path) !== null && _policy_path !== void 0 ? _policy_path : '.');
178
- });
179
- if (anyStillInstalled || !removedNameMatch) continue;
180
- const command = policy['post-uninstall'];
181
- if (!command) {
182
- for (const key of receiptKeys)delete state.receipts[key];
183
- await saveState(statePath, state);
184
- continue;
185
- }
186
- try {
187
- await execute(command, home, environment);
188
- for (const key of receiptKeys)delete state.receipts[key];
189
- await saveState(statePath, state);
190
- output(`cleaned ${id}`);
191
- } catch (error) {
192
- output(`failed cleanup ${id}: ${error instanceof Error ? error.message : String(error)}`);
193
- failed++;
194
- }
195
- }
196
- return failed ? 1 : 0;
197
- }
198
- if (mode === 'run' && !options.event) throw new Error('run requires an APM event');
199
- const event = (_ref = (_options_event2 = options.event) === null || _options_event2 === void 0 ? void 0 : _options_event2.event) !== null && _ref !== void 0 ? _ref : 'post-install';
200
- for (const policy of config.plugins){
201
- var _policy_postupdate;
202
- const command = event === 'post-update' ? (_policy_postupdate = policy['post-update']) !== null && _policy_postupdate !== void 0 ? _policy_postupdate : policy['post-install'] : policy['post-install'];
203
- if (!command) continue;
204
- const matches = locked.filter((plugin)=>{
205
- var _policy_path;
206
- return matchesSource(policy.source, plugin) && plugin.path === ((_policy_path = policy.path) !== null && _policy_path !== void 0 ? _policy_path : '.');
207
- });
208
- if (matches.length > 1) {
209
- output(`failed ambiguous source/path record ${recordId(policy)}`);
210
- failed++;
211
- continue;
212
- }
213
- if (!matches.length) {
214
- output(`skipped source not installed ${recordId(policy)}`);
215
- continue;
216
- }
217
- const plugin = matches[0];
218
- try {
219
- const found = await destinations(plugin, policy, home, apmHome);
220
- for (const destination of found){
221
- const key = receiptKey(policy, destination);
222
- if (mode === 'check') {
223
- const validDigests = [
224
- policy['post-install'],
225
- policy['post-update']
226
- ].filter((item)=>!!item).map((item)=>digest(policy, item));
227
- const ready = validDigests.includes(state.receipts[key]);
228
- output(`${ready ? 'ok' : 'missing'} ${recordId(policy)} ${destination}`);
229
- if (!ready) failed++;
230
- } else {
231
- delete state.receipts[key];
232
- await saveState(statePath, state);
233
- await execute(command, destination, environment);
234
- state.receipts[key] = digest(policy, command);
235
- await saveState(statePath, state);
236
- output(`ran ${recordId(policy)} ${destination}`);
237
- }
238
- }
239
- } catch (error) {
240
- output(`failed ${recordId(policy)}: ${error instanceof Error ? error.message : String(error)}`);
241
- failed++;
242
- }
243
- }
244
- return failed ? 1 : 0;
245
- } finally{
246
- await (release === null || release === void 0 ? void 0 : release());
247
- }
248
- }
@@ -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}\ninterface State {\n version: 1;\n receipts: Record<string, string>;\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}\nasync function destinations(plugin: LockedPlugin, policy: PluginPolicy, home: string, apmHome: string): Promise<string[]> {\n const output = new Set<string>();\n const root = pluginRoot(plugin, apmHome);\n if (!policy.skill) {\n output.add(await existingWithin(join(apmHome, 'apm_modules'), join(plugin.repo, plugin.path), 'kept plugin'));\n if (plugin.nativePluginRoot) {\n const nativeBase = join(home, '.agents', 'plugins');\n if (plugin.nativePluginRoot.startsWith('.agents/plugins/')) output.add(await existingWithin(nativeBase, plugin.nativePluginRoot.slice('.agents/plugins/'.length), 'native plugin'));\n }\n } else {\n try {\n output.add(await existingWithin(root, `skills/${policy.skill}`, `kept skill ${policy.skill}`));\n } catch (error) {\n if (!(error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT')) throw error;\n }\n if (plugin.nativePluginRoot?.startsWith('.agents/plugins/')) {\n const nativeRoot = plugin.nativePluginRoot.slice('.agents/plugins/'.length);\n try {\n output.add(await existingWithin(join(home, '.agents', 'plugins'), `${nativeRoot}/skills/${policy.skill}`, `native skill ${policy.skill}`));\n } catch (error) {\n if (!(error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT')) throw error;\n }\n }\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] !== policy.skill) continue;\n const deployment = parts.slice(0, index + 2).join('/');\n const prefix = ['.agents/skills/', '.hermes/skills/', '.claude/skills/'].find((candidate) => deployment.startsWith(candidate));\n if (prefix) output.add(await existingWithin(home, deployment, `skill ${policy.skill}`));\n }\n if (output.size === 0) throw new Error(`no deployed copy found for skill ${policy.skill}`);\n }\n return [...output];\n}\nasync function readState(path: string): Promise<State> {\n if (!existsSync(path)) return { version: 1, 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.receipts || typeof item.receipts !== 'object' || Array.isArray(item.receipts)) throw new Error('unsupported state format');\n if (Object.values(item.receipts).some((receipt) => typeof receipt !== 'string')) throw new Error('invalid state receipt');\n return item as unknown as State;\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 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 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 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 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 output(`skipped source not installed ${recordId(policy)}`);\n continue;\n }\n const plugin = matches[0];\n try {\n const found = await destinations(plugin, policy, home, apmHome);\n for (const destination of found) {\n const key = receiptKey(policy, destination);\n if (mode === 'check') {\n const validDigests = [policy['post-install'], policy['post-update']].filter((item): item is string => !!item).map((item) => digest(policy, item));\n const ready = validDigests.includes(state.receipts[key]);\n output(`${ready ? 'ok' : 'missing'} ${recordId(policy)} ${destination}`);\n if (!ready) failed++;\n } else {\n delete state.receipts[key];\n await saveState(statePath, state);\n await execute(command, destination, environment);\n state.receipts[key] = digest(policy, command);\n await saveState(statePath, state);\n output(`ran ${recordId(policy)} ${destination}`);\n }\n }\n } catch (error) {\n output(`failed ${recordId(policy)}: ${error instanceof Error ? error.message : String(error)}`);\n failed++;\n }\n }\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","destinations","policy","home","output","Set","skill","add","nativePluginRoot","nativeBase","slice","length","error","code","nativeRoot","file","deployedFiles","parts","split","index","lastIndexOf","deployment","prefix","find","size","readState","version","receipts","value","JSON","parse","Array","isArray","item","Object","values","some","receipt","saveState","state","temp","process","pid","Date","now","stringify","mode","flag","receiptKey","destination","digest","command","update","execute","cwd","environment","env","stdio","shell","lockLoadError","runLifecycle","options","configPath","console","log","config","locked","event","apmDirectory","isDirectory","statePath","recursive","release","lock","undefined","failed","eventNames","packages","map","name","plugins","id","receiptKeys","keys","filter","key","sourceCandidate","source","localPath","sourcePartsValue","removedNameMatch","has","host","anyStillInstalled","message","String","matches","found","validDigests","ready","includes"],"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;AAqBtE,SAASC,OAAOC,IAAY,EAAEC,KAAa;IACzC,MAAMC,UAAUf,SAASa,MAAMC;IAC/B,OAAOC,YAAY,MAAOA,YAAY,QAAQ,CAACA,QAAQC,UAAU,C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