@osd-project/osd-cli 0.0.0-stage → 0.8.3

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 (52) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +585 -2
  3. package/THIRD_PARTY_NOTICES.md +96 -0
  4. package/dist/auth-store.d.ts +38 -0
  5. package/dist/auth-store.js +239 -0
  6. package/dist/brand-catalog.d.ts +65 -0
  7. package/dist/brand-catalog.js +175 -0
  8. package/dist/connect-gate.d.ts +31 -0
  9. package/dist/connect-gate.js +82 -0
  10. package/dist/contracts.d.ts +61 -0
  11. package/dist/contracts.js +145 -0
  12. package/dist/exit-codes.d.ts +32 -0
  13. package/dist/exit-codes.js +40 -0
  14. package/dist/format.d.ts +71 -0
  15. package/dist/format.js +99 -0
  16. package/dist/generated/schemas.d.ts +2 -0
  17. package/dist/generated/schemas.js +1781 -0
  18. package/dist/guarded-fetch.d.ts +28 -0
  19. package/dist/guarded-fetch.js +252 -0
  20. package/dist/help.d.ts +27 -0
  21. package/dist/help.js +32 -0
  22. package/dist/http-fetch.d.ts +1 -0
  23. package/dist/http-fetch.js +17 -0
  24. package/dist/index.d.ts +2 -0
  25. package/dist/index.js +821 -0
  26. package/dist/logout.d.ts +16 -0
  27. package/dist/logout.js +82 -0
  28. package/dist/mcp-auth.d.ts +70 -0
  29. package/dist/mcp-auth.js +603 -0
  30. package/dist/mcp-card.d.ts +23 -0
  31. package/dist/mcp-card.js +18 -0
  32. package/dist/mcp-client.d.ts +77 -0
  33. package/dist/mcp-client.js +193 -0
  34. package/dist/net-guard.d.ts +66 -0
  35. package/dist/net-guard.js +152 -0
  36. package/dist/proxy-config.d.ts +51 -0
  37. package/dist/proxy-config.js +147 -0
  38. package/dist/request.d.ts +32 -0
  39. package/dist/request.js +62 -0
  40. package/dist/resolve-endpoint.d.ts +62 -0
  41. package/dist/resolve-endpoint.js +172 -0
  42. package/dist/search.d.ts +39 -0
  43. package/dist/search.js +69 -0
  44. package/dist/skill.d.ts +155 -0
  45. package/dist/skill.js +320 -0
  46. package/dist/updates.d.ts +101 -0
  47. package/dist/updates.js +541 -0
  48. package/dist/verify.d.ts +92 -0
  49. package/dist/verify.js +379 -0
  50. package/package.json +55 -3
  51. package/skill/osd/SKILL.md +400 -0
  52. package/skill/osd/references/connect-mcp.md +48 -0
@@ -0,0 +1,155 @@
1
+ export declare const SKILL_SOURCE = "npm:@osd-project/osd-cli";
2
+ export interface Frontmatter {
3
+ name: string;
4
+ description: string;
5
+ metadata: Record<string, string>;
6
+ }
7
+ /**
8
+ * Parses the subset of YAML frontmatter this package writes: top-level
9
+ * scalar fields and a flat string `metadata` map. Returns null when the
10
+ * block is absent or does not carry at least `name` and `description`
11
+ * (the Agent Skills required fields).
12
+ */
13
+ export declare function parseFrontmatter(markdown: string): Frontmatter | null;
14
+ export interface BundledSkill {
15
+ name: string;
16
+ description: string;
17
+ version: string;
18
+ source: string;
19
+ }
20
+ /** The packaged skill source directory (`<package>/skill`), populated at build time. */
21
+ export declare function bundledSkillRoot(): string;
22
+ export declare function listBundledSkills(): BundledSkill[];
23
+ export type DirBasis = "flag" | "env" | "detected" | "fallback";
24
+ export interface SkillsDirResolution {
25
+ dir: string;
26
+ basis: DirBasis;
27
+ }
28
+ export type SkillsDirOutcome = {
29
+ ok: true;
30
+ resolution: SkillsDirResolution;
31
+ } | {
32
+ ok: false;
33
+ error: string;
34
+ existing: {
35
+ label: string;
36
+ dir: string;
37
+ }[];
38
+ };
39
+ /**
40
+ * Resolution order: `--dir` flag, then `OSD_SKILL_DIR` (the env var is the
41
+ * whole mechanism, like `OSD_REGISTRY_URL`), then the one well-known skills
42
+ * directory that exists, then the neutral `~/.agents/skills` fallback.
43
+ * Two or more existing well-known directories are an error — never a
44
+ * silent choice.
45
+ */
46
+ export declare function resolveSkillsDir(opts: {
47
+ flag?: string;
48
+ env?: NodeJS.ProcessEnv;
49
+ home?: string;
50
+ }): SkillsDirOutcome;
51
+ export type InstalledSkill = {
52
+ state: "absent";
53
+ } | {
54
+ state: "no-manifest";
55
+ dir: string;
56
+ } | {
57
+ state: "unreadable";
58
+ file: string;
59
+ message: string;
60
+ } | {
61
+ state: "unparsable";
62
+ file: string;
63
+ } | {
64
+ state: "present";
65
+ frontmatter: Frontmatter;
66
+ file: string;
67
+ };
68
+ export declare function readInstalledSkill(skillsDir: string, name: string): InstalledSkill;
69
+ export type InstallOutcome = {
70
+ kind: "print";
71
+ markdown: string;
72
+ } | {
73
+ kind: "installed";
74
+ name: string;
75
+ version: string;
76
+ dir: string;
77
+ basis: DirBasis;
78
+ replacedFrom: string | null;
79
+ } | {
80
+ kind: "already-installed";
81
+ name: string;
82
+ version: string;
83
+ dir: string;
84
+ basis: DirBasis;
85
+ } | {
86
+ kind: "refused";
87
+ reason: string;
88
+ } | {
89
+ kind: "ambiguous";
90
+ error: string;
91
+ } | {
92
+ kind: "error";
93
+ message: string;
94
+ };
95
+ export declare function installSkill(opts: {
96
+ flagDir?: string;
97
+ force: boolean;
98
+ print: boolean;
99
+ env?: NodeJS.ProcessEnv;
100
+ home?: string;
101
+ }): InstallOutcome;
102
+ export type UninstallOutcome = {
103
+ kind: "removed";
104
+ name: string;
105
+ dir: string;
106
+ } | {
107
+ kind: "not-installed";
108
+ name: string;
109
+ dir: string;
110
+ } | {
111
+ kind: "refused";
112
+ reason: string;
113
+ } | {
114
+ kind: "ambiguous";
115
+ error: string;
116
+ } | {
117
+ kind: "error";
118
+ message: string;
119
+ };
120
+ export declare function uninstallSkill(opts: {
121
+ flagDir?: string;
122
+ env?: NodeJS.ProcessEnv;
123
+ home?: string;
124
+ }): UninstallOutcome;
125
+ export type StatusOutcome = {
126
+ kind: "current";
127
+ name: string;
128
+ version: string;
129
+ dir: string;
130
+ } | {
131
+ kind: "stale";
132
+ name: string;
133
+ installedVersion: string;
134
+ cliVersion: string;
135
+ dir: string;
136
+ } | {
137
+ kind: "missing";
138
+ name: string;
139
+ dir: string;
140
+ } | {
141
+ kind: "foreign";
142
+ dir: string;
143
+ reason: string;
144
+ } | {
145
+ kind: "ambiguous";
146
+ error: string;
147
+ } | {
148
+ kind: "error";
149
+ message: string;
150
+ };
151
+ export declare function skillStatus(opts: {
152
+ flagDir?: string;
153
+ env?: NodeJS.ProcessEnv;
154
+ home?: string;
155
+ }): StatusOutcome;
package/dist/skill.js ADDED
@@ -0,0 +1,320 @@
1
+ /**
2
+ * The `osd skill` subcommand: installs, prints, checks, and removes the
3
+ * agent skill bundled in this package.
4
+ *
5
+ * Design constraints, on purpose:
6
+ *
7
+ * - No harness knowledge. The CLI holds no per-client directory table
8
+ * (the lesson of the retired per-client adapters): the caller passes `--dir`,
9
+ * or the command resolves a default by *evidence* — the one well-known
10
+ * skills directory that already exists — and falls back to a neutral
11
+ * `~/.agents/skills` when none does (fresh machines, consumer personal
12
+ * agents whose layouts are unknowable from outside). Ambiguity is
13
+ * refused, never silently chosen.
14
+ * - No network. Everything ships in the package under `skill/`,
15
+ * populated at build time by scripts/gen-skill.mjs.
16
+ * - Ownership. Installed skills carry `metadata.source: npm:@osd-project/osd-cli`;
17
+ * uninstall removes only what this package wrote, and install refuses to
18
+ * clobber a foreign skill directory without `--force`.
19
+ */
20
+ import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync } from "node:fs";
21
+ import os from "node:os";
22
+ import path from "node:path";
23
+ import { CLI_VERSION, packageRoot } from "./updates.js";
24
+ export const SKILL_SOURCE = "npm:@osd-project/osd-cli";
25
+ function stripQuotes(value) {
26
+ const trimmed = value.trim();
27
+ if (trimmed.length >= 2 &&
28
+ ((trimmed.startsWith('"') && trimmed.endsWith('"')) || (trimmed.startsWith("'") && trimmed.endsWith("'")))) {
29
+ return trimmed.slice(1, -1);
30
+ }
31
+ return trimmed;
32
+ }
33
+ /**
34
+ * Parses the subset of YAML frontmatter this package writes: top-level
35
+ * scalar fields and a flat string `metadata` map. Returns null when the
36
+ * block is absent or does not carry at least `name` and `description`
37
+ * (the Agent Skills required fields).
38
+ */
39
+ export function parseFrontmatter(markdown) {
40
+ const block = markdown.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n/)?.[1];
41
+ if (block === undefined)
42
+ return null;
43
+ const top = {};
44
+ const metadata = {};
45
+ let inMetadata = false;
46
+ for (const line of block.split(/\r?\n/)) {
47
+ if (!line.trim())
48
+ continue;
49
+ if (/^\s+/.test(line)) {
50
+ const pair = line.trim().match(/^([\w-]+):\s*(.*)$/);
51
+ if (pair === null || !inMetadata)
52
+ return null;
53
+ metadata[pair[1]] = stripQuotes(pair[2]);
54
+ continue;
55
+ }
56
+ const pair = line.match(/^([\w-]+):\s*(.*)$/);
57
+ if (pair === null)
58
+ return null;
59
+ inMetadata = pair[1] === "metadata";
60
+ if (!inMetadata)
61
+ top[pair[1]] = stripQuotes(pair[2]);
62
+ }
63
+ if (top.name === undefined || top.description === undefined)
64
+ return null;
65
+ return { name: top.name, description: top.description, metadata };
66
+ }
67
+ /** The packaged skill source directory (`<package>/skill`), populated at build time. */
68
+ export function bundledSkillRoot() {
69
+ return path.join(packageRoot(), "skill");
70
+ }
71
+ export function listBundledSkills() {
72
+ const root = bundledSkillRoot();
73
+ if (!existsSync(root))
74
+ return [];
75
+ const skills = [];
76
+ for (const entry of readdirSync(root, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
77
+ if (!entry.isDirectory())
78
+ continue;
79
+ const file = path.join(root, entry.name, "SKILL.md");
80
+ if (!existsSync(file))
81
+ continue;
82
+ const frontmatter = parseFrontmatter(readFileSync(file, "utf8"));
83
+ if (frontmatter === null)
84
+ continue;
85
+ skills.push({
86
+ name: frontmatter.name,
87
+ description: frontmatter.description,
88
+ version: frontmatter.metadata.version ?? "",
89
+ source: frontmatter.metadata.source ?? "",
90
+ });
91
+ }
92
+ return skills;
93
+ }
94
+ /**
95
+ * Well-known skills directories, consulted by *evidence only*: a candidate
96
+ * is used only when it already exists on the machine. No guesses, no
97
+ * writes into a directory a harness did not create. New harnesses join
98
+ * this list only after their path is documented, and a wrong entry is
99
+ * harmless — it never matches.
100
+ */
101
+ const CANDIDATES = [
102
+ { label: "claude", dir: (home) => path.join(home, ".claude", "skills") },
103
+ { label: "codex", dir: (home) => path.join(home, ".codex", "skills") },
104
+ { label: "cursor", dir: (home) => path.join(home, ".cursor", "skills") },
105
+ { label: "opencode", dir: (home) => path.join(home, ".config", "opencode", "skills") },
106
+ { label: "pi", dir: (home) => path.join(home, ".pi", "agent", "skills") },
107
+ ];
108
+ function expandHome(value, home) {
109
+ if (value === "~")
110
+ return home;
111
+ if (value.startsWith("~/"))
112
+ return path.join(home, value.slice(2));
113
+ return value;
114
+ }
115
+ /**
116
+ * Resolution order: `--dir` flag, then `OSD_SKILL_DIR` (the env var is the
117
+ * whole mechanism, like `OSD_REGISTRY_URL`), then the one well-known skills
118
+ * directory that exists, then the neutral `~/.agents/skills` fallback.
119
+ * Two or more existing well-known directories are an error — never a
120
+ * silent choice.
121
+ */
122
+ export function resolveSkillsDir(opts) {
123
+ const env = opts.env ?? process.env;
124
+ const home = opts.home ?? os.homedir();
125
+ if (opts.flag !== undefined && opts.flag !== "") {
126
+ return { ok: true, resolution: { dir: path.resolve(expandHome(opts.flag, home)), basis: "flag" } };
127
+ }
128
+ const fromEnv = env.OSD_SKILL_DIR;
129
+ if (fromEnv !== undefined && fromEnv !== "") {
130
+ return { ok: true, resolution: { dir: path.resolve(expandHome(fromEnv, home)), basis: "env" } };
131
+ }
132
+ const existing = CANDIDATES.map((candidate) => ({ label: candidate.label, dir: candidate.dir(home) })).filter((candidate) => {
133
+ try {
134
+ return statSync(candidate.dir).isDirectory();
135
+ }
136
+ catch {
137
+ return false;
138
+ }
139
+ });
140
+ if (existing.length === 1) {
141
+ return { ok: true, resolution: { dir: existing[0].dir, basis: "detected" } };
142
+ }
143
+ if (existing.length >= 2) {
144
+ const list = existing.map((candidate) => ` --dir ${candidate.dir} (${candidate.label})`).join("\n");
145
+ return {
146
+ ok: false,
147
+ error: `more than one skills directory exists; pass --dir (or set OSD_SKILL_DIR) to choose one:\n${list}`,
148
+ existing,
149
+ };
150
+ }
151
+ return { ok: true, resolution: { dir: path.join(home, ".agents", "skills"), basis: "fallback" } };
152
+ }
153
+ export function readInstalledSkill(skillsDir, name) {
154
+ const dir = path.join(skillsDir, name);
155
+ const file = path.join(dir, "SKILL.md");
156
+ let markdown;
157
+ try {
158
+ markdown = readFileSync(file, "utf8");
159
+ }
160
+ catch (error) {
161
+ const code = error?.code;
162
+ // Distinguish "nothing there" from "a directory exists but has no
163
+ // readable SKILL.md": foreign content must never be deleted or
164
+ // reported as missing without an explicit override.
165
+ if (code === "ENOENT" || code === "ENOTDIR") {
166
+ return existsSync(dir) ? { state: "no-manifest", dir } : { state: "absent" };
167
+ }
168
+ return { state: "unreadable", file, message: error instanceof Error ? error.message : String(error) };
169
+ }
170
+ const frontmatter = parseFrontmatter(markdown);
171
+ if (frontmatter === null)
172
+ return { state: "unparsable", file };
173
+ return { state: "present", frontmatter, file };
174
+ }
175
+ function bundledSingle() {
176
+ const skills = listBundledSkills();
177
+ if (skills.length === 0) {
178
+ return {
179
+ ok: false,
180
+ message: "this osd package is missing its bundled skill directory (skill/); reinstall it: npm install -g @osd-project/osd-cli@latest",
181
+ };
182
+ }
183
+ if (skills.length > 1) {
184
+ return { ok: false, message: "this package bundles more than one skill, which `osd skill` does not support yet" };
185
+ }
186
+ return { ok: true, skill: skills[0] };
187
+ }
188
+ export function installSkill(opts) {
189
+ const bundled = bundledSingle();
190
+ if (!bundled.ok)
191
+ return { kind: "error", message: bundled.message };
192
+ const skill = bundled.skill;
193
+ if (opts.print) {
194
+ return { kind: "print", markdown: readFileSync(path.join(bundledSkillRoot(), skill.name, "SKILL.md"), "utf8") };
195
+ }
196
+ const resolved = resolveSkillsDir({ flag: opts.flagDir, env: opts.env, home: opts.home });
197
+ if (!resolved.ok)
198
+ return { kind: "ambiguous", error: resolved.error };
199
+ const skillsDir = resolved.resolution.dir;
200
+ const target = path.join(skillsDir, skill.name);
201
+ const installed = readInstalledSkill(skillsDir, skill.name);
202
+ if (installed.state === "no-manifest") {
203
+ if (!opts.force) {
204
+ return {
205
+ kind: "refused",
206
+ reason: `${installed.dir} exists but has no SKILL.md, so it was not installed by this package; pass --force to replace it`,
207
+ };
208
+ }
209
+ }
210
+ else if (installed.state === "unreadable") {
211
+ if (!opts.force) {
212
+ return {
213
+ kind: "refused",
214
+ reason: `${installed.file} exists but could not be read (${installed.message}); pass --force to replace it`,
215
+ };
216
+ }
217
+ }
218
+ else if (installed.state === "unparsable") {
219
+ if (!opts.force) {
220
+ return {
221
+ kind: "refused",
222
+ reason: `${installed.file} exists but has no parsable frontmatter, so it was not installed by this package; pass --force to replace it`,
223
+ };
224
+ }
225
+ }
226
+ else if (installed.state === "present") {
227
+ const source = installed.frontmatter.metadata.source ?? "";
228
+ if (source !== SKILL_SOURCE) {
229
+ if (!opts.force) {
230
+ return {
231
+ kind: "refused",
232
+ reason: `${installed.file} was not installed by this package (metadata.source: ${source || "absent"}); pass --force to replace it`,
233
+ };
234
+ }
235
+ }
236
+ else if ((installed.frontmatter.metadata.version ?? "") === skill.version) {
237
+ return { kind: "already-installed", name: skill.name, version: skill.version, dir: target, basis: resolved.resolution.basis };
238
+ }
239
+ }
240
+ const replacedFrom = installed.state === "present" ? installed.frontmatter.metadata.version ?? null : null;
241
+ rmSync(target, { recursive: true, force: true });
242
+ mkdirSync(target, { recursive: true });
243
+ cpSync(path.join(bundledSkillRoot(), skill.name), target, { recursive: true });
244
+ return { kind: "installed", name: skill.name, version: skill.version, dir: target, basis: resolved.resolution.basis, replacedFrom };
245
+ }
246
+ export function uninstallSkill(opts) {
247
+ const bundled = bundledSingle();
248
+ const name = bundled.ok ? bundled.skill.name : "osd";
249
+ const resolved = resolveSkillsDir({ flag: opts.flagDir, env: opts.env, home: opts.home });
250
+ if (!resolved.ok)
251
+ return { kind: "ambiguous", error: resolved.error };
252
+ const skillsDir = resolved.resolution.dir;
253
+ const target = path.join(skillsDir, name);
254
+ const installed = readInstalledSkill(skillsDir, name);
255
+ if (installed.state === "absent")
256
+ return { kind: "not-installed", name, dir: target };
257
+ if (installed.state === "no-manifest") {
258
+ return {
259
+ kind: "refused",
260
+ reason: `${installed.dir} exists but has no SKILL.md, so it was not installed by this package; remove it by hand if you are sure`,
261
+ };
262
+ }
263
+ if (installed.state === "unreadable") {
264
+ return {
265
+ kind: "refused",
266
+ reason: `${installed.file} exists but could not be read (${installed.message}); remove it by hand if you are sure`,
267
+ };
268
+ }
269
+ if (installed.state === "unparsable") {
270
+ return {
271
+ kind: "refused",
272
+ reason: `${installed.file} exists but has no parsable frontmatter, so it was not installed by this package; remove it by hand if you are sure`,
273
+ };
274
+ }
275
+ const source = installed.frontmatter.metadata.source ?? "";
276
+ if (source !== SKILL_SOURCE) {
277
+ return {
278
+ kind: "refused",
279
+ reason: `${installed.file} was not installed by this package (metadata.source: ${source || "absent"}); refusing to remove it`,
280
+ };
281
+ }
282
+ rmSync(target, { recursive: true, force: true });
283
+ return { kind: "removed", name, dir: target };
284
+ }
285
+ export function skillStatus(opts) {
286
+ const bundled = bundledSingle();
287
+ if (!bundled.ok)
288
+ return { kind: "error", message: bundled.message };
289
+ const skill = bundled.skill;
290
+ const resolved = resolveSkillsDir({ flag: opts.flagDir, env: opts.env, home: opts.home });
291
+ if (!resolved.ok)
292
+ return { kind: "ambiguous", error: resolved.error };
293
+ const skillsDir = resolved.resolution.dir;
294
+ const target = path.join(skillsDir, skill.name);
295
+ const installed = readInstalledSkill(skillsDir, skill.name);
296
+ if (installed.state === "absent")
297
+ return { kind: "missing", name: skill.name, dir: target };
298
+ if (installed.state === "no-manifest") {
299
+ return { kind: "foreign", dir: target, reason: `${installed.dir} exists but has no SKILL.md` };
300
+ }
301
+ if (installed.state === "unreadable") {
302
+ return { kind: "foreign", dir: target, reason: `${installed.file} exists but could not be read (${installed.message})` };
303
+ }
304
+ if (installed.state === "unparsable") {
305
+ return { kind: "foreign", dir: target, reason: `${installed.file} exists but has no parsable frontmatter` };
306
+ }
307
+ const source = installed.frontmatter.metadata.source ?? "";
308
+ if (source !== SKILL_SOURCE) {
309
+ return {
310
+ kind: "foreign",
311
+ dir: target,
312
+ reason: `${installed.file} was not installed by this package (metadata.source: ${source || "absent"})`,
313
+ };
314
+ }
315
+ const installedVersion = installed.frontmatter.metadata.version ?? "";
316
+ if (installedVersion === CLI_VERSION) {
317
+ return { kind: "current", name: skill.name, version: installedVersion, dir: target };
318
+ }
319
+ return { kind: "stale", name: skill.name, installedVersion, cliVersion: CLI_VERSION, dir: target };
320
+ }
@@ -0,0 +1,101 @@
1
+ export declare const PACKAGE_NAME = "@osd-project/osd-cli";
2
+ export declare const REFRESH_COMMAND = "__refresh-update-cache";
3
+ export declare const CHECK_TTL_MS: number;
4
+ export declare const CLI_VERSION: string;
5
+ export interface UpdateCache {
6
+ checkedAt: string;
7
+ installedVersion: string;
8
+ latestVersion: string | null;
9
+ distTag?: string;
10
+ lastError?: string;
11
+ /** Whether this copy is a global npm install; only those get notices and updates. */
12
+ global?: boolean;
13
+ /** Set by the background applier; announced once, then cleared. */
14
+ autoApplied?: {
15
+ from: string;
16
+ to: string;
17
+ };
18
+ }
19
+ export declare function compareVersions(a: string, b: string): number | null;
20
+ /** Strictly newer only, so a stale dist-tag can never suggest a downgrade. */
21
+ export declare function isNewer(latest: string | null | undefined, current: string): boolean;
22
+ export declare function packageRoot(moduleUrl?: string): string;
23
+ /** Pure path check (no subprocess) so it's free on every startup. Workspace builds and `pnpm link` return false. */
24
+ export declare function isPackageInstall(root?: string): boolean;
25
+ /** Prefer the npm next to the running node, so nvm/fnm users hit the prefix `osd` is installed in. */
26
+ export declare function npmCommand(): string;
27
+ export interface RunResult {
28
+ status: number | null;
29
+ stdout: string;
30
+ stderr: string;
31
+ error?: Error;
32
+ }
33
+ export declare function runNpm(args: string[], timeoutMs: number): RunResult;
34
+ export declare function npmEnv(): NodeJS.ProcessEnv;
35
+ export declare function distTag(env?: NodeJS.ProcessEnv): string;
36
+ export interface RegistryState {
37
+ /** Version under the followed dist-tag. */
38
+ latest: string;
39
+ /** Deprecation message on the running version, if any. */
40
+ installedDeprecated: string | null;
41
+ }
42
+ export type RegistryLookup = {
43
+ ok: true;
44
+ state: RegistryState;
45
+ } | {
46
+ ok: false;
47
+ error: string;
48
+ };
49
+ /** Parse `npm view <pkg> dist-tags --json`. */
50
+ export declare function parseRegistryView(stdout: string, tag: string): {
51
+ latest: string;
52
+ } | {
53
+ error: string;
54
+ };
55
+ /** `npm view <pkg>@<v> deprecated --json` prints a JSON string when deprecated, nothing otherwise. */
56
+ export declare function parseDeprecated(stdout: string): string | null;
57
+ export declare function fetchRegistryState(timeoutMs?: number, run?: typeof runNpm): RegistryLookup;
58
+ export declare function configDir(): string;
59
+ export declare function cachePath(): string;
60
+ export declare function readCache(): UpdateCache | null;
61
+ export declare function writeCache(cache: UpdateCache): void;
62
+ export declare function isStale(cache: UpdateCache | null, currentVersion: string, now?: number, tag?: string): boolean;
63
+ /** Only the platforms the staged swap has been tested on. */
64
+ export declare function updatesSupported(platform?: NodeJS.Platform): boolean;
65
+ export declare function checksDisabled(env?: NodeJS.ProcessEnv): boolean;
66
+ export declare function autoUpdateDisabled(env?: NodeJS.ProcessEnv): boolean;
67
+ export type ApplyDecision = {
68
+ apply: true;
69
+ version: string;
70
+ reason: "update" | "rollback";
71
+ } | {
72
+ apply: false;
73
+ reason: string;
74
+ };
75
+ export declare function decideAutoApply(state: RegistryState, current: string, tag?: string): ApplyDecision;
76
+ export declare function formatNotice(current: string, latest: string): string;
77
+ export declare function cachedNotice(currentVersion?: string): string | null;
78
+ export declare function notifyAndRefresh(scriptPath?: string): void;
79
+ /** Body of the detached refresher. Never throws. */
80
+ export declare function refreshCacheNow(options?: {
81
+ apply?: boolean;
82
+ lookup?: () => RegistryLookup;
83
+ }): void;
84
+ export declare function lockPath(): string;
85
+ /** Exclusive create; a lock older than 15 minutes is treated as abandoned. Returns the fd, or null if held. */
86
+ export declare function acquireLock(now?: number): number | null;
87
+ export declare function releaseLock(fd: number): void;
88
+ export declare function installedVersionOnDisk(root: string): string | null;
89
+ /** Run the freshly installed CLI; it must start and report the expected version. */
90
+ export declare function verifyInstall(root: string, expected: string): boolean;
91
+ export declare function npmGlobalRoot(run?: typeof runNpm): string | null;
92
+ export declare function isInGlobalRoot(root: string, globalRoot: string): boolean;
93
+ /** Interactive installs stream npm's output to stderr so stdout stays clean; background ones discard it. */
94
+ export declare function installVersion(version: string, opts?: {
95
+ quiet?: boolean;
96
+ timeoutMs?: number;
97
+ }): {
98
+ ok: boolean;
99
+ status: number | null;
100
+ error?: string;
101
+ };