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.
- package/README.md +256 -57
- 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 -1157
- 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 -248
- package/dist/esm/runner.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/agent-plugin-lifecycle/src/lib/store.ts"],"sourcesContent":["import { mkdir, readFile, stat } from 'node:fs/promises';\nimport { dirname, join } from 'node:path';\nimport lockfile from 'proper-lockfile';\nimport writeFileAtomic from 'write-file-atomic';\nimport { FILE_VERSION, LOCK_NAME, LOCK_RETRIES } from '../constants.ts';\nimport { message, missing, withoutBom } from './errors.ts';\nimport { isRecord } from './object.ts';\n\n/** Checks the content of one store file (without its `version`), throwing when it is not the expected shape. */\nexport type Parse<T> = (value: Record<string, unknown>) => T;\n\nfunction check<T>(path: string, value: unknown, parse: Parse<T>): T {\n if (!isRecord(value)) throw new Error(`${path} must be an object`);\n if (value.version !== FILE_VERSION) throw new Error(`${path} has unsupported version ${JSON.stringify(value.version)}`);\n try {\n return parse(value);\n } catch (error) {\n throw new Error(`${path}: ${message(error)}`);\n }\n}\n\n/** On macOS and Linux, `path` (when it exists) must be the user's and not writable by group or others, as OpenSSH requires of `~/.ssh`. */\nasync function checkPrivate(path: string): Promise<void> {\n if (process.platform === 'win32') return;\n let info: Awaited<ReturnType<typeof stat>>;\n try {\n info = await stat(path);\n } catch (error) {\n if (missing(error)) return;\n throw error;\n }\n if (info.uid !== process.getuid?.()) throw new Error(`${path} is not owned by you`);\n if (info.mode & 0o022) throw new Error(`${path} is writable by group or others: run chmod go-w ${path}`);\n}\n\n/** Reads a store file; a file that does not exist reads as `empty()`. The folder and the file must be private (`checkPrivate`). */\nexport async function readStore<T>(path: string, parse: Parse<T>, empty: () => T): Promise<T> {\n await checkPrivate(dirname(path));\n await checkPrivate(path);\n let text: string;\n try {\n text = await readFile(path, 'utf8');\n } catch (error) {\n if (missing(error)) return empty();\n throw error;\n }\n let value: unknown;\n try {\n value = JSON.parse(withoutBom(text));\n } catch (error) {\n throw new Error(`${path} is not valid JSON: ${message(error)}`);\n }\n return check(path, value, parse);\n}\n\n/**\n * Changes one store file in `dir` while holding the folder's lock: reads the current content, lets `change` edit it, and writes it\n * under a temporary name renamed into place. Any failure to create or write `dir` names the folder.\n */\nexport async function updateStore<T>(dir: string, file: string, parse: Parse<T>, empty: () => T, change: (value: T) => void): Promise<T> {\n const path = join(dir, file);\n let release: () => Promise<void>;\n try {\n await mkdir(dir, { recursive: true, mode: 0o700 });\n } catch (error) {\n throw new Error(`cannot write ${dir}: ${message(error)}`);\n }\n // before the lock, which proper-lockfile creates inside the folder\n await checkPrivate(dir);\n try {\n release = await lockfile.lock(dir, { realpath: false, lockfilePath: join(dir, LOCK_NAME), retries: LOCK_RETRIES });\n } catch (error) {\n throw new Error(`cannot write ${dir}: ${message(error)}`);\n }\n try {\n const value = await readStore(path, parse, empty);\n change(value);\n try {\n // written under a temporary name and renamed into place, private to the user\n await writeFileAtomic(path, `${JSON.stringify({ version: FILE_VERSION, ...value }, null, 2)}\\n`, { mode: 0o600 });\n } catch (error) {\n throw new Error(`cannot write ${dir}: ${message(error)}`);\n }\n return value;\n } finally {\n await release();\n }\n}\n"],"names":["mkdir","readFile","stat","dirname","join","lockfile","writeFileAtomic","FILE_VERSION","LOCK_NAME","LOCK_RETRIES","message","missing","withoutBom","isRecord","check","path","value","parse","Error","version","JSON","stringify","error","checkPrivate","process","platform","info","uid","getuid","mode","readStore","empty","text","updateStore","dir","file","change","release","recursive","lock","realpath","lockfilePath","retries"],"mappings":"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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface VisibleOptions {
|
|
2
|
+
/** The value is one space-separated field of a result line, so a value with a space also takes the JSON-string form. */
|
|
3
|
+
field?: boolean;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* `value` as it is when it is printable ASCII with no leading or trailing space, does not start with `"` (and, for a `field`, has no space);
|
|
7
|
+
* otherwise as a JSON string (`jsesc`). Only a JSON string starts with `"`, so the terminal shows exactly the text that is approved and run.
|
|
8
|
+
*/
|
|
9
|
+
export declare function visible(value: string, options?: VisibleOptions): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import jsesc from 'jsesc';
|
|
2
|
+
// printable ASCII only: U+0020 to U+007E
|
|
3
|
+
const PRINTABLE = /^[ -~]*$/;
|
|
4
|
+
/**
|
|
5
|
+
* `value` as it is when it is printable ASCII with no leading or trailing space, does not start with `"` (and, for a `field`, has no space);
|
|
6
|
+
* otherwise as a JSON string (`jsesc`). Only a JSON string starts with `"`, so the terminal shows exactly the text that is approved and run.
|
|
7
|
+
*/ export function visible(value, options = {}) {
|
|
8
|
+
const plain = PRINTABLE.test(value) && value.trim() === value && !value.startsWith('"') && !(options.field && value.includes(' '));
|
|
9
|
+
return plain ? value : jsesc(value, {
|
|
10
|
+
json: true
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/agent-plugin-lifecycle/src/lib/visible.ts"],"sourcesContent":["import jsesc from 'jsesc';\n\n// printable ASCII only: U+0020 to U+007E\nconst PRINTABLE = /^[ -~]*$/;\n\nexport interface VisibleOptions {\n /** The value is one space-separated field of a result line, so a value with a space also takes the JSON-string form. */\n field?: boolean;\n}\n\n/**\n * `value` as it is when it is printable ASCII with no leading or trailing space, does not start with `\"` (and, for a `field`, has no space);\n * otherwise as a JSON string (`jsesc`). Only a JSON string starts with `\"`, so the terminal shows exactly the text that is approved and run.\n */\nexport function visible(value: string, options: VisibleOptions = {}): string {\n const plain = PRINTABLE.test(value) && value.trim() === value && !value.startsWith('\"') && !(options.field && value.includes(' '));\n return plain ? value : jsesc(value, { json: true });\n}\n"],"names":["jsesc","PRINTABLE","visible","value","options","plain","test","trim","startsWith","field","includes","json"],"mappings":"AAAA,OAAOA,WAAW,QAAQ;AAE1B,yCAAyC;AACzC,MAAMC,YAAY;AAOlB;;;CAGC,GACD,OAAO,SAASC,QAAQC,KAAa,EAAEC,UAA0B,CAAC,CAAC;IACjE,MAAMC,QAAQJ,UAAUK,IAAI,CAACH,UAAUA,MAAMI,IAAI,OAAOJ,SAAS,CAACA,MAAMK,UAAU,CAAC,QAAQ,CAAEJ,CAAAA,QAAQK,KAAK,IAAIN,MAAMO,QAAQ,CAAC,IAAG;IAChI,OAAOL,QAAQF,QAAQH,MAAMG,OAAO;QAAEQ,MAAM;IAAK;AACnD"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The `install` command of a parsed `apl.json`, or undefined when it has none. Unknown fields are ignored. */
|
|
2
|
+
export declare function parseManifest(value: unknown): string | undefined;
|
|
3
|
+
/** Reads `<folder>/apl.json`. A missing file rejects with the `ENOENT` error; an invalid one with a message naming the problem. */
|
|
4
|
+
export declare function readManifest(folder: string): Promise<string | undefined>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { INSTALL, MANIFEST } from './constants.js';
|
|
4
|
+
import { withoutBom } from './lib/errors.js';
|
|
5
|
+
import { isRecord } from './lib/object.js';
|
|
6
|
+
/** The `install` command of a parsed `apl.json`, or undefined when it has none. Unknown fields are ignored. */ export function parseManifest(value) {
|
|
7
|
+
if (!isRecord(value)) throw new Error(`${MANIFEST} must be an object`);
|
|
8
|
+
const { scripts } = value;
|
|
9
|
+
if (scripts === undefined) return undefined;
|
|
10
|
+
if (!isRecord(scripts)) throw new Error(`${MANIFEST} scripts must be an object`);
|
|
11
|
+
const install = scripts[INSTALL];
|
|
12
|
+
if (install === undefined) return undefined;
|
|
13
|
+
if (typeof install !== 'string' || !install.trim()) throw new Error(`${MANIFEST} scripts.${INSTALL} must be a nonempty string`);
|
|
14
|
+
return install;
|
|
15
|
+
}
|
|
16
|
+
/** Reads `<folder>/apl.json`. A missing file rejects with the `ENOENT` error; an invalid one with a message naming the problem. */ export async function readManifest(folder) {
|
|
17
|
+
const text = await readFile(join(folder, MANIFEST), 'utf8');
|
|
18
|
+
let value;
|
|
19
|
+
try {
|
|
20
|
+
value = JSON.parse(withoutBom(text));
|
|
21
|
+
} catch (error) {
|
|
22
|
+
throw new Error(`${MANIFEST} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
23
|
+
}
|
|
24
|
+
return parseManifest(value);
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/agent-plugin-lifecycle/src/manifest.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { INSTALL, MANIFEST } from './constants.ts';\nimport { withoutBom } from './lib/errors.ts';\nimport { isRecord } from './lib/object.ts';\n\n/** The `install` command of a parsed `apl.json`, or undefined when it has none. Unknown fields are ignored. */\nexport function parseManifest(value: unknown): string | undefined {\n if (!isRecord(value)) throw new Error(`${MANIFEST} must be an object`);\n const { scripts } = value;\n if (scripts === undefined) return undefined;\n if (!isRecord(scripts)) throw new Error(`${MANIFEST} scripts must be an object`);\n const install = scripts[INSTALL];\n if (install === undefined) return undefined;\n if (typeof install !== 'string' || !install.trim()) throw new Error(`${MANIFEST} scripts.${INSTALL} must be a nonempty string`);\n return install;\n}\n\n/** Reads `<folder>/apl.json`. A missing file rejects with the `ENOENT` error; an invalid one with a message naming the problem. */\nexport async function readManifest(folder: string): Promise<string | undefined> {\n const text = await readFile(join(folder, MANIFEST), 'utf8');\n let value: unknown;\n try {\n value = JSON.parse(withoutBom(text));\n } catch (error) {\n throw new Error(`${MANIFEST} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);\n }\n return parseManifest(value);\n}\n"],"names":["readFile","join","INSTALL","MANIFEST","withoutBom","isRecord","parseManifest","value","Error","scripts","undefined","install","trim","readManifest","folder","text","JSON","parse","error","message","String"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,mBAAmB;AAC5C,SAASC,IAAI,QAAQ,YAAY;AACjC,SAASC,OAAO,EAAEC,QAAQ,QAAQ,iBAAiB;AACnD,SAASC,UAAU,QAAQ,kBAAkB;AAC7C,SAASC,QAAQ,QAAQ,kBAAkB;AAE3C,6GAA6G,GAC7G,OAAO,SAASC,cAAcC,KAAc;IAC1C,IAAI,CAACF,SAASE,QAAQ,MAAM,IAAIC,MAAM,GAAGL,SAAS,kBAAkB,CAAC;IACrE,MAAM,EAAEM,OAAO,EAAE,GAAGF;IACpB,IAAIE,YAAYC,WAAW,OAAOA;IAClC,IAAI,CAACL,SAASI,UAAU,MAAM,IAAID,MAAM,GAAGL,SAAS,0BAA0B,CAAC;IAC/E,MAAMQ,UAAUF,OAAO,CAACP,QAAQ;IAChC,IAAIS,YAAYD,WAAW,OAAOA;IAClC,IAAI,OAAOC,YAAY,YAAY,CAACA,QAAQC,IAAI,IAAI,MAAM,IAAIJ,MAAM,GAAGL,SAAS,SAAS,EAAED,QAAQ,0BAA0B,CAAC;IAC9H,OAAOS;AACT;AAEA,iIAAiI,GACjI,OAAO,eAAeE,aAAaC,MAAc;IAC/C,MAAMC,OAAO,MAAMf,SAASC,KAAKa,QAAQX,WAAW;IACpD,IAAII;IACJ,IAAI;QACFA,QAAQS,KAAKC,KAAK,CAACb,WAAWW;IAChC,EAAE,OAAOG,OAAO;QACd,MAAM,IAAIV,MAAM,GAAGL,SAAS,oBAAoB,EAAEe,iBAAiBV,QAAQU,MAAMC,OAAO,GAAGC,OAAOF,QAAQ;IAC5G;IACA,OAAOZ,cAAcC;AACvB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** The last successful run of `install` in one copy. `revision` and `lock` come from APM's lock and are absent for a named folder. */
|
|
2
|
+
export interface Run {
|
|
3
|
+
id: string;
|
|
4
|
+
install: string;
|
|
5
|
+
revision?: string;
|
|
6
|
+
lock?: string;
|
|
7
|
+
}
|
|
8
|
+
/** `~/.apl/state.json` without its `version`: one record per copy folder. */
|
|
9
|
+
export interface State {
|
|
10
|
+
runs: Record<string, Run>;
|
|
11
|
+
}
|
|
12
|
+
export declare function parseState(value: Record<string, unknown>): State;
|
|
13
|
+
/** The copy's record matches its command and revision; a named folder has no revision on either side. */
|
|
14
|
+
export declare function isCurrent(run: Run | undefined, install: string, revision: string | undefined): boolean;
|
|
15
|
+
export declare function readState(home: string): Promise<State>;
|
|
16
|
+
/** Changes the run records; records whose folder no longer exists are dropped in the same write. */
|
|
17
|
+
export declare function updateState(home: string, change: (state: State) => void): Promise<State>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { APL_DIR, STATE_FILE } from './constants.js';
|
|
4
|
+
import { isRecord } from './lib/object.js';
|
|
5
|
+
import { readStore, updateStore } from './lib/store.js';
|
|
6
|
+
export function parseState(value) {
|
|
7
|
+
const { runs } = value;
|
|
8
|
+
if (!isRecord(runs)) throw new Error('runs must be an object');
|
|
9
|
+
for (const [folder, entry] of Object.entries(runs)){
|
|
10
|
+
const run = entry;
|
|
11
|
+
const optional = (field)=>field === undefined || typeof field === 'string';
|
|
12
|
+
if (!isRecord(run) || typeof run.id !== 'string' || typeof run.install !== 'string' || !optional(run.revision) || !optional(run.lock)) throw new Error(`run record for ${folder} must have id and install strings`);
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
runs: runs
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const empty = ()=>({
|
|
19
|
+
runs: {}
|
|
20
|
+
});
|
|
21
|
+
/** The copy's record matches its command and revision; a named folder has no revision on either side. */ export function isCurrent(run, install, revision) {
|
|
22
|
+
return !!run && run.install === install && run.revision === revision;
|
|
23
|
+
}
|
|
24
|
+
export function readState(home) {
|
|
25
|
+
return readStore(join(home, APL_DIR, STATE_FILE), parseState, empty);
|
|
26
|
+
}
|
|
27
|
+
/** Changes the run records; records whose folder no longer exists are dropped in the same write. */ export function updateState(home, change) {
|
|
28
|
+
return updateStore(join(home, APL_DIR), STATE_FILE, parseState, empty, (state)=>{
|
|
29
|
+
change(state);
|
|
30
|
+
for (const folder of Object.keys(state.runs))if (!existsSync(folder)) delete state.runs[folder];
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/agent-plugin-lifecycle/src/state.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { APL_DIR, STATE_FILE } from './constants.ts';\nimport { isRecord } from './lib/object.ts';\nimport { readStore, updateStore } from './lib/store.ts';\n\n/** The last successful run of `install` in one copy. `revision` and `lock` come from APM's lock and are absent for a named folder. */\nexport interface Run {\n id: string;\n install: string;\n revision?: string;\n lock?: string;\n}\n/** `~/.apl/state.json` without its `version`: one record per copy folder. */\nexport interface State {\n runs: Record<string, Run>;\n}\n\nexport function parseState(value: Record<string, unknown>): State {\n const { runs } = value;\n if (!isRecord(runs)) throw new Error('runs must be an object');\n for (const [folder, entry] of Object.entries(runs)) {\n const run = entry as Partial<Run> | null;\n const optional = (field: unknown) => field === undefined || typeof field === 'string';\n if (!isRecord(run) || typeof run.id !== 'string' || typeof run.install !== 'string' || !optional(run.revision) || !optional(run.lock)) throw new Error(`run record for ${folder} must have id and install strings`);\n }\n return { runs: runs as Record<string, Run> };\n}\nconst empty = (): State => ({ runs: {} });\n\n/** The copy's record matches its command and revision; a named folder has no revision on either side. */\nexport function isCurrent(run: Run | undefined, install: string, revision: string | undefined): boolean {\n return !!run && run.install === install && run.revision === revision;\n}\n\nexport function readState(home: string): Promise<State> {\n return readStore(join(home, APL_DIR, STATE_FILE), parseState, empty);\n}\n\n/** Changes the run records; records whose folder no longer exists are dropped in the same write. */\nexport function updateState(home: string, change: (state: State) => void): Promise<State> {\n return updateStore(join(home, APL_DIR), STATE_FILE, parseState, empty, (state) => {\n change(state);\n for (const folder of Object.keys(state.runs)) if (!existsSync(folder)) delete state.runs[folder];\n });\n}\n"],"names":["existsSync","join","APL_DIR","STATE_FILE","isRecord","readStore","updateStore","parseState","value","runs","Error","folder","entry","Object","entries","run","optional","field","undefined","id","install","revision","lock","empty","isCurrent","readState","home","updateState","change","state","keys"],"mappings":"AAAA,SAASA,UAAU,QAAQ,UAAU;AACrC,SAASC,IAAI,QAAQ,YAAY;AACjC,SAASC,OAAO,EAAEC,UAAU,QAAQ,iBAAiB;AACrD,SAASC,QAAQ,QAAQ,kBAAkB;AAC3C,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AAcxD,OAAO,SAASC,WAAWC,KAA8B;IACvD,MAAM,EAAEC,IAAI,EAAE,GAAGD;IACjB,IAAI,CAACJ,SAASK,OAAO,MAAM,IAAIC,MAAM;IACrC,KAAK,MAAM,CAACC,QAAQC,MAAM,IAAIC,OAAOC,OAAO,CAACL,MAAO;QAClD,MAAMM,MAAMH;QACZ,MAAMI,WAAW,CAACC,QAAmBA,UAAUC,aAAa,OAAOD,UAAU;QAC7E,IAAI,CAACb,SAASW,QAAQ,OAAOA,IAAII,EAAE,KAAK,YAAY,OAAOJ,IAAIK,OAAO,KAAK,YAAY,CAACJ,SAASD,IAAIM,QAAQ,KAAK,CAACL,SAASD,IAAIO,IAAI,GAAG,MAAM,IAAIZ,MAAM,CAAC,eAAe,EAAEC,OAAO,iCAAiC,CAAC;IACpN;IACA,OAAO;QAAEF,MAAMA;IAA4B;AAC7C;AACA,MAAMc,QAAQ,IAAc,CAAA;QAAEd,MAAM,CAAC;IAAE,CAAA;AAEvC,uGAAuG,GACvG,OAAO,SAASe,UAAUT,GAAoB,EAAEK,OAAe,EAAEC,QAA4B;IAC3F,OAAO,CAAC,CAACN,OAAOA,IAAIK,OAAO,KAAKA,WAAWL,IAAIM,QAAQ,KAAKA;AAC9D;AAEA,OAAO,SAASI,UAAUC,IAAY;IACpC,OAAOrB,UAAUJ,KAAKyB,MAAMxB,SAASC,aAAaI,YAAYgB;AAChE;AAEA,kGAAkG,GAClG,OAAO,SAASI,YAAYD,IAAY,EAAEE,MAA8B;IACtE,OAAOtB,YAAYL,KAAKyB,MAAMxB,UAAUC,YAAYI,YAAYgB,OAAO,CAACM;QACtED,OAAOC;QACP,KAAK,MAAMlB,UAAUE,OAAOiB,IAAI,CAACD,MAAMpB,IAAI,EAAG,IAAI,CAACT,WAAWW,SAAS,OAAOkB,MAAMpB,IAAI,CAACE,OAAO;IAClG;AACF"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { CopyResult, StatusOptions } from './types.js';
|
|
2
|
+
/** Reports each copy without changing anything; for an APM scope, also each folder a script ran in whose package APM has since removed (`left`). */
|
|
3
|
+
export declare function status(options?: StatusOptions): Promise<CopyResult[]>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { isApproved, readApprovals } from './approvals.js';
|
|
3
|
+
import { cannotRun, findCopies } from './copies.js';
|
|
4
|
+
import { resolveOptions } from './lib/options.js';
|
|
5
|
+
import { isCurrent, readState } from './state.js';
|
|
6
|
+
/** Reports each copy without changing anything; for an APM scope, also each folder a script ran in whose package APM has since removed (`left`). */ export async function status(options = {}) {
|
|
7
|
+
const { home, apmHome, cwd, global, folders } = resolveOptions(options);
|
|
8
|
+
const { copies, scope, named } = await findCopies({
|
|
9
|
+
home,
|
|
10
|
+
apmHome,
|
|
11
|
+
cwd,
|
|
12
|
+
global,
|
|
13
|
+
folders
|
|
14
|
+
});
|
|
15
|
+
const approvals = await readApprovals(home);
|
|
16
|
+
const state = await readState(home);
|
|
17
|
+
const results = copies.map((copy)=>{
|
|
18
|
+
const { id, folder, place, install, revision } = copy;
|
|
19
|
+
if (install === undefined) return cannotRun(copy);
|
|
20
|
+
if (!isApproved(approvals, place, id, install)) return {
|
|
21
|
+
status: 'unapproved',
|
|
22
|
+
id,
|
|
23
|
+
folder
|
|
24
|
+
};
|
|
25
|
+
const run = state.runs[folder];
|
|
26
|
+
if (!run) return {
|
|
27
|
+
status: 'missing',
|
|
28
|
+
id,
|
|
29
|
+
folder
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
status: isCurrent(run, install, revision) ? 'ok' : 'stale',
|
|
33
|
+
id,
|
|
34
|
+
folder
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
if (scope) {
|
|
38
|
+
for (const [folder, run] of Object.entries(state.runs))if (run.lock === scope.lock && !named.has(folder) && existsSync(folder)) results.push({
|
|
39
|
+
status: 'left',
|
|
40
|
+
folder
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return results;
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/agent-plugin-lifecycle/src/status.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { isApproved, readApprovals } from './approvals.ts';\nimport { cannotRun, findCopies } from './copies.ts';\nimport { resolveOptions } from './lib/options.ts';\nimport { isCurrent, readState } from './state.ts';\nimport type { CopyResult, StatusOptions } from './types.ts';\n\n/** Reports each copy without changing anything; for an APM scope, also each folder a script ran in whose package APM has since removed (`left`). */\nexport async function status(options: StatusOptions = {}): Promise<CopyResult[]> {\n const { home, apmHome, cwd, global, folders } = resolveOptions(options);\n const { copies, scope, named } = await findCopies({ home, apmHome, cwd, global, folders });\n const approvals = await readApprovals(home);\n const state = await readState(home);\n const results: CopyResult[] = copies.map((copy): CopyResult => {\n const { id, folder, place, install, revision } = copy;\n if (install === undefined) return cannotRun(copy);\n if (!isApproved(approvals, place, id, install)) return { status: 'unapproved', id, folder };\n const run = state.runs[folder];\n if (!run) return { status: 'missing', id, folder };\n return { status: isCurrent(run, install, revision) ? 'ok' : 'stale', id, folder };\n });\n if (scope) {\n for (const [folder, run] of Object.entries(state.runs)) if (run.lock === scope.lock && !named.has(folder) && existsSync(folder)) results.push({ status: 'left', folder });\n }\n return results;\n}\n"],"names":["existsSync","isApproved","readApprovals","cannotRun","findCopies","resolveOptions","isCurrent","readState","status","options","home","apmHome","cwd","global","folders","copies","scope","named","approvals","state","results","map","copy","id","folder","place","install","revision","undefined","run","runs","Object","entries","lock","has","push"],"mappings":"AAAA,SAASA,UAAU,QAAQ,UAAU;AACrC,SAASC,UAAU,EAAEC,aAAa,QAAQ,iBAAiB;AAC3D,SAASC,SAAS,EAAEC,UAAU,QAAQ,cAAc;AACpD,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,SAAS,EAAEC,SAAS,QAAQ,aAAa;AAGlD,kJAAkJ,GAClJ,OAAO,eAAeC,OAAOC,UAAyB,CAAC,CAAC;IACtD,MAAM,EAAEC,IAAI,EAAEC,OAAO,EAAEC,GAAG,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAGT,eAAeI;IAC/D,MAAM,EAAEM,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAG,MAAMb,WAAW;QAAEM;QAAMC;QAASC;QAAKC;QAAQC;IAAQ;IACxF,MAAMI,YAAY,MAAMhB,cAAcQ;IACtC,MAAMS,QAAQ,MAAMZ,UAAUG;IAC9B,MAAMU,UAAwBL,OAAOM,GAAG,CAAC,CAACC;QACxC,MAAM,EAAEC,EAAE,EAAEC,MAAM,EAAEC,KAAK,EAAEC,OAAO,EAAEC,QAAQ,EAAE,GAAGL;QACjD,IAAII,YAAYE,WAAW,OAAOzB,UAAUmB;QAC5C,IAAI,CAACrB,WAAWiB,WAAWO,OAAOF,IAAIG,UAAU,OAAO;YAAElB,QAAQ;YAAce;YAAIC;QAAO;QAC1F,MAAMK,MAAMV,MAAMW,IAAI,CAACN,OAAO;QAC9B,IAAI,CAACK,KAAK,OAAO;YAAErB,QAAQ;YAAWe;YAAIC;QAAO;QACjD,OAAO;YAAEhB,QAAQF,UAAUuB,KAAKH,SAASC,YAAY,OAAO;YAASJ;YAAIC;QAAO;IAClF;IACA,IAAIR,OAAO;QACT,KAAK,MAAM,CAACQ,QAAQK,IAAI,IAAIE,OAAOC,OAAO,CAACb,MAAMW,IAAI,EAAG,IAAID,IAAII,IAAI,KAAKjB,MAAMiB,IAAI,IAAI,CAAChB,MAAMiB,GAAG,CAACV,WAAWxB,WAAWwB,SAASJ,QAAQe,IAAI,CAAC;YAAE3B,QAAQ;YAAQgB;QAAO;IACzK;IACA,OAAOJ;AACT"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** What `install` (`ran`, `current`, `unapproved`, `failed`, `skipped`) or `status` (`ok`, `missing`, `stale`, `unapproved`, `failed`, `skipped`, `left`) reports for one copy; `left` is a folder. */
|
|
2
|
+
export type Status = 'ran' | 'current' | 'unapproved' | 'failed' | 'skipped' | 'ok' | 'missing' | 'stale' | 'left';
|
|
3
|
+
export interface Options {
|
|
4
|
+
/** Default `os.homedir()`; `~/.apl` and user-scope copies live under it. */
|
|
5
|
+
home?: string;
|
|
6
|
+
/** Default `<home>/.apm`. */
|
|
7
|
+
apmHome?: string;
|
|
8
|
+
/** Default `process.cwd()`; the project root. */
|
|
9
|
+
cwd?: string;
|
|
10
|
+
/** The environment scripts run with. Default `process.env`. */
|
|
11
|
+
environment?: NodeJS.ProcessEnv;
|
|
12
|
+
}
|
|
13
|
+
export interface StatusOptions extends Options {
|
|
14
|
+
/** Use the user scope (`apmHome`) instead of the project in `cwd`. Not allowed with `folders`. */
|
|
15
|
+
global?: boolean;
|
|
16
|
+
/** Named folders, each holding an `apl.json`, instead of the copies APM's lock names. */
|
|
17
|
+
folders?: string[];
|
|
18
|
+
}
|
|
19
|
+
export interface InstallOptions extends StatusOptions {
|
|
20
|
+
/** Asked once per id whose command is not approved, before any script runs; the approvals are saved after the last answer. Absent: unapproved copies are not run. */
|
|
21
|
+
approve?: (request: ApprovalRequest) => Promise<boolean>;
|
|
22
|
+
/** Called with each result as soon as it is known, before the next script starts. */
|
|
23
|
+
onResult?: (result: CopyResult) => void;
|
|
24
|
+
}
|
|
25
|
+
export interface ApprovalRequest {
|
|
26
|
+
id: string;
|
|
27
|
+
scripts: {
|
|
28
|
+
install: string;
|
|
29
|
+
};
|
|
30
|
+
folders: string[];
|
|
31
|
+
}
|
|
32
|
+
export interface CopyResult {
|
|
33
|
+
status: Status;
|
|
34
|
+
/** Absent only for `left`. */
|
|
35
|
+
id?: string;
|
|
36
|
+
folder: string;
|
|
37
|
+
/** Why a copy `failed` or was `skipped`. */
|
|
38
|
+
reason?: string;
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/** What `install` (`ran`, `current`, `unapproved`, `failed`, `skipped`) or `status` (`ok`, `missing`, `stale`, `unapproved`, `failed`, `skipped`, `left`) reports for one copy; `left` is a folder. */ export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/agent-plugin-lifecycle/src/types.ts"],"sourcesContent":["/** What `install` (`ran`, `current`, `unapproved`, `failed`, `skipped`) or `status` (`ok`, `missing`, `stale`, `unapproved`, `failed`, `skipped`, `left`) reports for one copy; `left` is a folder. */\nexport type Status = 'ran' | 'current' | 'unapproved' | 'failed' | 'skipped' | 'ok' | 'missing' | 'stale' | 'left';\n\nexport interface Options {\n /** Default `os.homedir()`; `~/.apl` and user-scope copies live under it. */\n home?: string;\n /** Default `<home>/.apm`. */\n apmHome?: string;\n /** Default `process.cwd()`; the project root. */\n cwd?: string;\n /** The environment scripts run with. Default `process.env`. */\n environment?: NodeJS.ProcessEnv;\n}\nexport interface StatusOptions extends Options {\n /** Use the user scope (`apmHome`) instead of the project in `cwd`. Not allowed with `folders`. */\n global?: boolean;\n /** Named folders, each holding an `apl.json`, instead of the copies APM's lock names. */\n folders?: string[];\n}\nexport interface InstallOptions extends StatusOptions {\n /** Asked once per id whose command is not approved, before any script runs; the approvals are saved after the last answer. Absent: unapproved copies are not run. */\n approve?: (request: ApprovalRequest) => Promise<boolean>;\n /** Called with each result as soon as it is known, before the next script starts. */\n onResult?: (result: CopyResult) => void;\n}\nexport interface ApprovalRequest {\n id: string;\n scripts: { install: string };\n folders: string[];\n}\nexport interface CopyResult {\n status: Status;\n /** Absent only for `left`. */\n id?: string;\n folder: string;\n /** Why a copy `failed` or was `skipped`. */\n reason?: string;\n}\n"],"names":[],"mappings":"AAAA,qMAAqM,GA8BrM,WAOC"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-plugin-lifecycle",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Run
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Run the install scripts that agent plugins and skills ship in apl.json, after you approve them: for Agent Package Manager (APM), npx skills and any other installer",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"apm",
|
|
7
7
|
"agent",
|
|
8
|
-
"
|
|
9
|
-
"manager",
|
|
8
|
+
"skills",
|
|
10
9
|
"plugin",
|
|
11
|
-
"
|
|
10
|
+
"install",
|
|
11
|
+
"scripts",
|
|
12
|
+
"lifecycle",
|
|
13
|
+
"approval",
|
|
14
|
+
"agent-package-manager",
|
|
15
|
+
"agent-skills",
|
|
16
|
+
"agent-plugins",
|
|
17
|
+
"npx-skills",
|
|
18
|
+
"install-scripts",
|
|
19
|
+
"postinstall",
|
|
20
|
+
"allow-scripts",
|
|
21
|
+
"apl"
|
|
12
22
|
],
|
|
13
23
|
"repository": {
|
|
14
24
|
"type": "git",
|
|
@@ -28,11 +38,11 @@
|
|
|
28
38
|
"source": "src/index.ts",
|
|
29
39
|
"types": "dist/cjs/index.d.ts",
|
|
30
40
|
"bin": {
|
|
31
|
-
"agent-plugin-lifecycle": "bin/cli.js"
|
|
41
|
+
"agent-plugin-lifecycle": "bin/cli.js",
|
|
42
|
+
"apl": "bin/cli.js"
|
|
32
43
|
},
|
|
33
44
|
"files": [
|
|
34
|
-
"dist"
|
|
35
|
-
"config"
|
|
45
|
+
"dist"
|
|
36
46
|
],
|
|
37
47
|
"scripts": {
|
|
38
48
|
"build": "tsds build",
|
|
@@ -42,17 +52,23 @@
|
|
|
42
52
|
"test": "tsds test:node --no-timeouts",
|
|
43
53
|
"test:apm": "tsds test:node --no-timeouts test/integration/apm-live.test.ts",
|
|
44
54
|
"test:engines": "nvu engines tsds test:node --no-timeouts",
|
|
55
|
+
"test:skills": "tsds test:node --no-timeouts test/integration/skills-cli.test.ts",
|
|
45
56
|
"version": "tsds version"
|
|
46
57
|
},
|
|
47
58
|
"dependencies": {
|
|
48
|
-
"
|
|
59
|
+
"is-path-inside": "^4.0.0",
|
|
60
|
+
"jsesc": "^3.1.0",
|
|
49
61
|
"proper-lockfile": "^4.1.2",
|
|
62
|
+
"write-file-atomic": "^7.0.1",
|
|
50
63
|
"yaml": "^2.9.1"
|
|
51
64
|
},
|
|
52
65
|
"devDependencies": {
|
|
66
|
+
"@types/jsesc": "^3.0.3",
|
|
53
67
|
"@types/mocha": "*",
|
|
54
68
|
"@types/node": "^22",
|
|
55
69
|
"@types/proper-lockfile": "^4.1.4",
|
|
70
|
+
"@types/write-file-atomic": "^4.0.3",
|
|
71
|
+
"cross-spawn-cb": "^3.3.1",
|
|
56
72
|
"fs-remove-compat": "^1.1.1",
|
|
57
73
|
"node-version-use": "*",
|
|
58
74
|
"ts-dev-stack": "*",
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 1,
|
|
3
|
-
"plugins": [
|
|
4
|
-
{
|
|
5
|
-
"source": "git@bitbucket.org:team/plugins.git",
|
|
6
|
-
"path": "plugins/example",
|
|
7
|
-
"post-install": "npm ci --prefix server --no-bin-links",
|
|
8
|
-
"post-update": "npm ci --prefix server --no-bin-links",
|
|
9
|
-
"post-uninstall": "node .config/agent-plugin-lifecycle/cleanup-example.js"
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
"source": "git@bitbucket.org:team/plugins.git",
|
|
13
|
-
"path": "plugins/example",
|
|
14
|
-
"skill": "hello-node",
|
|
15
|
-
"post-install": "npm ci --no-bin-links"
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"source": "/absolute/path/to/local-plugin",
|
|
19
|
-
"post-install": "npm ci --no-bin-links"
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
}
|
package/dist/cjs/config.d.cts
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/cjs/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/cjs/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":["loadConfig","parseConfig","recordId","object","value","label","allowed","Array","isArray","Error","result","unknown","Object","keys","find","key","includes","nonempty","trim","relativePath","path","startsWith","test","split","some","part","plugin","JSON","stringify","source","skill","root","version","plugins","seen","Set","map","raw","index","item","undefined","event","id","has","add","parse","readFile"],"mappings":"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"}
|
package/dist/cjs/runner.d.cts
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/cjs/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>;
|