cbs-4px-merchant-cli 0.0.2 → 0.0.4

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.
@@ -0,0 +1,174 @@
1
+ /**
2
+ * Skill installer — the single source of truth for *where* skills live, *how*
3
+ * they are laid down, and *which* stale files get removed.
4
+ *
5
+ * Design rules (do not break these):
6
+ * 1. This module never prints and never calls `process.exit`. All IO belongs
7
+ * to the command layer (`src/commands/skill.ts`).
8
+ * 2. The skill version comes from the bundled `skill/package.json`, never
9
+ * from the root `package.json`. Today the two values are identical; the
10
+ * indirection keeps them separable if the skill is ever published to a
11
+ * skill marketplace on its own release cadence.
12
+ * 3. Deletion is driven exclusively by the `files` list of the *previous*
13
+ * manifest. No manifest ⇒ nothing is deleted. A missing/empty list must
14
+ * never widen into "remove the whole directory".
15
+ * 4. Nothing machine-specific may be written into SKILL.md or reference/*.
16
+ * Host state (which dirs were touched, whether an API Key is configured)
17
+ * belongs in terminal output only.
18
+ */
19
+ /**
20
+ * Skill install dir name — the package name with any npm scope stripped
21
+ * (e.g. `cbs-4px-merchant-cli`). Previously duplicated in scripts/build.js,
22
+ * scripts/postinstall.js and src/cli.ts; this is now the only copy.
23
+ */
24
+ export declare const SKILL_DIR_NAME: string;
25
+ /** Legacy version marker written by <= 0.0.2 postinstall. Still written. */
26
+ export declare const VERSION_MARKER = ".skill-version";
27
+ /** npm-style manifest, doubling as the install receipt. */
28
+ export declare const MANIFEST_FILE = "package.json";
29
+ /** Stamp identifying this CLI as the installer of a target directory. */
30
+ export declare const INSTALL_METHOD = "cli";
31
+ export interface AgentDef {
32
+ /** Stable id accepted by `--agent`. */
33
+ id: string;
34
+ label: string;
35
+ /** Path segments under $HOME that contain the tool's `skills` dir. */
36
+ segments: string[];
37
+ }
38
+ /** Whitelisted agent ids, for `--agent` validation and error messages. */
39
+ export declare function knownAgentIds(): string[];
40
+ export interface SkillManifest {
41
+ name: string;
42
+ version: string;
43
+ description?: string;
44
+ /** Relative paths owned by this install — the only paths ever deleted. */
45
+ files: string[];
46
+ installSource?: string;
47
+ installMethod?: string;
48
+ installedAt?: string;
49
+ }
50
+ export type TargetState =
51
+ /** Directory absent or empty — clean install. */
52
+ 'fresh'
53
+ /** Manifest present and `installSource` is us — normal upgrade. */
54
+ | 'owned'
55
+ /** No manifest but a legacy `.skill-version` — ours, from <= 0.0.2. */
56
+ | 'legacy'
57
+ /** Manifest present but installed by someone else (e.g. aone-kit). */
58
+ | 'foreign'
59
+ /** Non-empty, no manifest, no legacy marker — provenance unknown. */
60
+ | 'unknown';
61
+ export interface TargetPlan {
62
+ agent: string;
63
+ label: string;
64
+ dir: string;
65
+ state: TargetState;
66
+ installed_version: string | null;
67
+ /** Present when `state === 'foreign'`. */
68
+ installed_source?: string;
69
+ /** Stale paths to delete = previous manifest `files` minus the new list. */
70
+ remove: string[];
71
+ /** True when the target is skipped unless `--force` is given. */
72
+ blocked: boolean;
73
+ }
74
+ export interface SkillSource {
75
+ name: string;
76
+ version: string;
77
+ description?: string;
78
+ root: string;
79
+ /** Relative paths that will be written into every target. */
80
+ files: string[];
81
+ }
82
+ export interface InstallPlan {
83
+ skill: SkillSource;
84
+ targets: TargetPlan[];
85
+ }
86
+ export type TargetOutcome = 'installed' | 'updated' | 'skipped' | 'failed';
87
+ export interface TargetResult {
88
+ agent: string;
89
+ label: string;
90
+ dir: string;
91
+ outcome: TargetOutcome;
92
+ /** Version that was there before this run. */
93
+ previous_version: string | null;
94
+ removed: string[];
95
+ reason?: string;
96
+ }
97
+ export interface ResolveOptions {
98
+ home?: string;
99
+ /** Restrict to these agent ids; empty/undefined means every target. */
100
+ agents?: string[];
101
+ /** Override the bundled skill dir (tests only). */
102
+ skillRoot?: string;
103
+ }
104
+ /** Thrown for caller mistakes the command layer must render as a clean error. */
105
+ export declare class SkillInstallerError extends Error {
106
+ readonly code: string;
107
+ readonly hint?: string | undefined;
108
+ constructor(message: string, code: string, hint?: string | undefined);
109
+ }
110
+ /** Bundled skill dir: `<pkg>/skill`, from both `dist/` and `src/` layouts. */
111
+ export declare function resolveSkillRoot(override?: string): string;
112
+ /**
113
+ * Read the bundled skill and enumerate what will be written.
114
+ *
115
+ * The file list is walked from disk rather than taken from the manifest's
116
+ * `files` field: disk is what actually gets copied, so deriving the receipt
117
+ * from it keeps the manifest from ever describing files that aren't there.
118
+ */
119
+ export declare function readSkillSource(override?: string): SkillSource;
120
+ /**
121
+ * Whitelist ∪ discovery, both gated on the directory looking actually used.
122
+ *
123
+ * An explicit `--agent` bypasses the in-use heuristic: naming a tool is a
124
+ * direct instruction, and the heuristic exists only to guess for the user.
125
+ */
126
+ export declare function resolveTargets(opts?: ResolveOptions): AgentDef[];
127
+ /** Absolute install dir of the skill for one agent. */
128
+ export declare function targetDirFor(home: string, agent: AgentDef): string;
129
+ /**
130
+ * All candidate install dirs, used by the CLI's drift check. Includes
131
+ * whitelisted tools whose root exists plus discovered ones — so a tool that is
132
+ * only reachable via discovery (e.g. OpenCode) can no longer be invisible to
133
+ * drift detection.
134
+ */
135
+ export declare function listSkillDirs(home?: string): string[];
136
+ /** Validate `--agent` values against the whitelist, a1-style. */
137
+ export declare function validateAgentIds(ids: string[]): void;
138
+ /** Read a target's manifest. Returns null when absent or unparsable. */
139
+ export declare function readTargetManifest(dir: string): SkillManifest | null;
140
+ /** Legacy plain-text version marker written by <= 0.0.2 postinstall. */
141
+ export declare function readLegacyVersion(dir: string): string | null;
142
+ /** Installed version of a target, manifest first then legacy marker. */
143
+ export declare function readInstalledVersion(dir: string): string | null;
144
+ /** Classify a target directory before touching it. */
145
+ export declare function inspectTarget(dir: string, source: SkillSource): TargetPlan['state'];
146
+ export declare function buildPlan(source: SkillSource, opts?: ResolveOptions): InstallPlan;
147
+ /**
148
+ * Reject anything that could escape the target dir. Manifests are read from
149
+ * disk and may have been edited by hand, so their paths are untrusted input.
150
+ */
151
+ export declare function isSafeRelativePath(p: string): boolean;
152
+ export interface ApplyOptions {
153
+ /** Overwrite targets owned by someone else / of unknown provenance. */
154
+ force?: boolean;
155
+ }
156
+ /** Lay the skill down on every planned target. Never throws per target. */
157
+ export declare function applyPlan(plan: InstallPlan, opts?: ApplyOptions): TargetResult[];
158
+ export interface UninstallPlan {
159
+ agent: string;
160
+ label: string;
161
+ dir: string;
162
+ state: TargetState;
163
+ installed_version: string | null;
164
+ installed_source?: string;
165
+ /** Paths that will be removed — manifest `files` plus the legacy marker. */
166
+ remove: string[];
167
+ blocked: boolean;
168
+ }
169
+ /**
170
+ * Plan removal. Deletion is still manifest-bounded: without a receipt we only
171
+ * remove the files this CLI is known to write, never the directory wholesale.
172
+ */
173
+ export declare function buildUninstallPlan(source: SkillSource, opts?: ResolveOptions): UninstallPlan[];
174
+ export declare function applyUninstall(plans: UninstallPlan[], opts?: ApplyOptions): TargetResult[];