@octen.ai/cli 0.1.6 → 0.1.8
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 +11 -2
- package/dist/api/client.js +12 -2
- package/dist/api/errors.d.ts +2 -0
- package/dist/api/errors.js +2 -0
- package/dist/commands/configureMcp.d.ts +2 -0
- package/dist/commands/configureMcp.js +32 -4
- package/dist/commands/configureSkills.d.ts +2 -0
- package/dist/commands/configureSkills.js +55 -6
- package/dist/skills/setkey.d.ts +13 -0
- package/dist/skills/setkey.js +86 -0
- package/dist/skills/source.js +52 -34
- package/dist/util/detectClient.d.ts +16 -0
- package/dist/util/detectClient.js +57 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -123,7 +123,9 @@ octen configure-mcp --all --pin 0.2.1
|
|
|
123
123
|
|
|
124
124
|
Supported clients: Claude Code, Claude Desktop, Cursor, Windsurf, VS Code, Codex.
|
|
125
125
|
|
|
126
|
-
|
|
126
|
+
Only clients detected as installed are configured; `--all` skips the rest, and an explicitly-named client that isn't detected is skipped unless you pass `--force`.
|
|
127
|
+
|
|
128
|
+
Options: `--all`, `--claude-code`, `--cursor`, `--claude-desktop`, `--windsurf`, `--vscode`, `--codex`, `--scope` (user|project), `--pin <version>`, `--force` (configure even if the client is not detected).
|
|
127
129
|
|
|
128
130
|
Run without flags to print current status for each client.
|
|
129
131
|
|
|
@@ -142,11 +144,18 @@ octen configure-skills --all --offline
|
|
|
142
144
|
|
|
143
145
|
# Fetch from a specific git ref
|
|
144
146
|
octen configure-skills --claude-code --ref v0.3.0
|
|
147
|
+
|
|
148
|
+
# Also write OCTEN_API_KEY into the client's env config
|
|
149
|
+
octen configure-skills --claude-code --set-key --api-key <key>
|
|
145
150
|
```
|
|
146
151
|
|
|
147
152
|
Supported clients: Claude Code, Cursor, Codex, OpenClaw, Hermes.
|
|
148
153
|
|
|
149
|
-
|
|
154
|
+
`--set-key` also writes OCTEN_API_KEY into the client's env config (Claude Code `~/.claude/settings.json`, Codex `config.toml`, OpenClaw `.env`); Cursor/Hermes print a shell-profile hint. The key comes from `--api-key` or the `OCTEN_API_KEY` environment variable.
|
|
155
|
+
|
|
156
|
+
Only clients detected as installed are configured; `--all` skips the rest, and an explicitly-named client that isn't detected is skipped unless you pass `--force`.
|
|
157
|
+
|
|
158
|
+
Options: `--all`, `--claude-code`, `--cursor`, `--codex`, `--openclaw`, `--hermes`, `--scope` (user|project), `--ref <ref>` (default: main), `--bundled`/`--offline` (use vendored skills), `--only <names>` (comma-separated skill names), `--skills-dir <path>` (custom source directory), `--set-key` (write OCTEN_API_KEY into the client's env config), `--force` (configure even if the client is not detected).
|
|
150
159
|
|
|
151
160
|
Run without flags to show installed skills per client.
|
|
152
161
|
|
package/dist/api/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_BASE_URL, DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT_MS, ENDPOINTS } from "./constants.js";
|
|
2
|
-
import { OctenAPIError, OctenAuthError, OctenTimeoutError } from "./errors.js";
|
|
2
|
+
import { OctenAPIError, OctenAuthError, OctenNetworkError, OctenTimeoutError } from "./errors.js";
|
|
3
3
|
const RETRYABLE = new Set([429, 500, 502, 503, 504]);
|
|
4
4
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
5
5
|
export class OctenClient {
|
|
@@ -72,7 +72,9 @@ export class OctenClient {
|
|
|
72
72
|
await sleep(this.retryBaseMs * 2 ** attempt);
|
|
73
73
|
continue;
|
|
74
74
|
}
|
|
75
|
-
|
|
75
|
+
// Out of retries on a non-Octen, non-abort error: surface the underlying network cause.
|
|
76
|
+
const cause = e?.cause?.code ?? e?.cause?.message ?? e.message;
|
|
77
|
+
throw new OctenNetworkError(`network error reaching ${this.baseUrl}: ${cause}`);
|
|
76
78
|
}
|
|
77
79
|
finally {
|
|
78
80
|
clearTimeout(t);
|
|
@@ -104,6 +106,14 @@ export class OctenClient {
|
|
|
104
106
|
}
|
|
105
107
|
return res;
|
|
106
108
|
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
if (e instanceof OctenAPIError || e instanceof OctenAuthError)
|
|
111
|
+
throw e;
|
|
112
|
+
if (e.name === "AbortError")
|
|
113
|
+
throw new OctenTimeoutError("request timed out");
|
|
114
|
+
const cause = e?.cause?.code ?? e?.cause?.message ?? e.message;
|
|
115
|
+
throw new OctenNetworkError(`network error reaching ${this.baseUrl}: ${cause}`);
|
|
116
|
+
}
|
|
107
117
|
finally {
|
|
108
118
|
clearTimeout(t);
|
|
109
119
|
}
|
package/dist/api/errors.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export declare class OctenValidationError extends OctenError {
|
|
|
6
6
|
}
|
|
7
7
|
export declare class OctenTimeoutError extends OctenError {
|
|
8
8
|
}
|
|
9
|
+
export declare class OctenNetworkError extends OctenError {
|
|
10
|
+
}
|
|
9
11
|
export declare class OctenAPIError extends OctenError {
|
|
10
12
|
status: number;
|
|
11
13
|
body?: unknown | undefined;
|
package/dist/api/errors.js
CHANGED
|
@@ -6,6 +6,8 @@ interface ConfigureMcpInternalOpts {
|
|
|
6
6
|
cwd?: string;
|
|
7
7
|
/** Override claude CLI detection (for testing) */
|
|
8
8
|
hasClaudeCli?: boolean;
|
|
9
|
+
/** Override client-installed detection (for testing) */
|
|
10
|
+
isInstalled?: (id: string) => boolean;
|
|
9
11
|
}
|
|
10
12
|
export declare function registerConfigureMcp(program: Command, internal?: ConfigureMcpInternalOpts): void;
|
|
11
13
|
export {};
|
|
@@ -4,6 +4,7 @@ import { MCP_CLIENTS } from "../mcp/clients.js";
|
|
|
4
4
|
import { installMcp } from "../mcp/install.js";
|
|
5
5
|
import { mcpStatus } from "../mcp/detect.js";
|
|
6
6
|
import { resolveApiKey } from "../config/resolve.js";
|
|
7
|
+
import { isClientInstalled } from "../util/detectClient.js";
|
|
7
8
|
// Exported so tests can call with injected dirs
|
|
8
9
|
export function registerConfigureMcp(program, internal = {}) {
|
|
9
10
|
program
|
|
@@ -18,6 +19,7 @@ export function registerConfigureMcp(program, internal = {}) {
|
|
|
18
19
|
.option("--codex", "configure Codex")
|
|
19
20
|
.option("--scope <s>", "config scope: user | project (default: user)", "user")
|
|
20
21
|
.option("--pin <ver>", "pin octen-mcp to a specific version, e.g. 0.2.1")
|
|
22
|
+
.option("--force", "configure even if the client is not detected")
|
|
21
23
|
.action(async (_opts, command) => {
|
|
22
24
|
const g = command.optsWithGlobals();
|
|
23
25
|
const opts = command.opts();
|
|
@@ -42,6 +44,7 @@ export function registerConfigureMcp(program, internal = {}) {
|
|
|
42
44
|
// Determine the effective home/cwd
|
|
43
45
|
const home = internal.home ?? os.homedir();
|
|
44
46
|
const cwd = internal.cwd ?? process.cwd();
|
|
47
|
+
const isInstalled = internal.isInstalled ?? ((id) => isClientInstalled(id, { home }));
|
|
45
48
|
const installOpts = { hasClaudeCli: internal.hasClaudeCli };
|
|
46
49
|
// Determine selected clients
|
|
47
50
|
const clientFlagMap = {
|
|
@@ -67,13 +70,38 @@ export function registerConfigureMcp(program, internal = {}) {
|
|
|
67
70
|
}
|
|
68
71
|
return;
|
|
69
72
|
}
|
|
70
|
-
// INSTALL MODE
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
// INSTALL MODE — determine which clients to act on, gated by detection.
|
|
74
|
+
let selected;
|
|
75
|
+
if (opts.all) {
|
|
76
|
+
// Start from the full registry, then filter to installed ones.
|
|
77
|
+
const skipped = [];
|
|
78
|
+
selected = MCP_CLIENTS.filter((c) => {
|
|
79
|
+
if (isInstalled(c.id))
|
|
80
|
+
return true;
|
|
81
|
+
skipped.push(c.label);
|
|
82
|
+
return false;
|
|
83
|
+
});
|
|
84
|
+
if (skipped.length > 0) {
|
|
85
|
+
process.stdout.write(`skipped (not installed): ${skipped.join(", ")}\n`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// Explicit per-client flags: warn + skip not-installed unless --force.
|
|
90
|
+
const requested = MCP_CLIENTS.filter((c) => {
|
|
74
91
|
const flagName = clientFlagMap[c.id];
|
|
75
92
|
return flagName ? Boolean(opts[flagName]) : false;
|
|
76
93
|
});
|
|
94
|
+
selected = requested.filter((c) => {
|
|
95
|
+
if (opts.force || isInstalled(c.id))
|
|
96
|
+
return true;
|
|
97
|
+
process.stderr.write(`warning: ${c.label} not detected — skipping (use --force to configure anyway)\n`);
|
|
98
|
+
return false;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (selected.length === 0) {
|
|
102
|
+
process.stdout.write("no installed clients to configure\n");
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
77
105
|
let anyFailed = false;
|
|
78
106
|
for (const client of selected) {
|
|
79
107
|
try {
|
|
@@ -6,6 +6,8 @@ interface ConfigureSkillsInternalOpts {
|
|
|
6
6
|
cwd?: string;
|
|
7
7
|
/** Injected fetch implementation (for testing); defaults to global fetch */
|
|
8
8
|
fetchImpl?: typeof fetch;
|
|
9
|
+
/** Override client-installed detection (for testing) */
|
|
10
|
+
isInstalled?: (id: string) => boolean;
|
|
9
11
|
}
|
|
10
12
|
export declare function registerConfigureSkills(program: Command, internal?: ConfigureSkillsInternalOpts): void;
|
|
11
13
|
export {};
|
|
@@ -5,6 +5,9 @@ import pc from "picocolors";
|
|
|
5
5
|
import { SKILL_CLIENTS } from "../skills/clients.js";
|
|
6
6
|
import { resolveSkillsDir } from "../skills/source.js";
|
|
7
7
|
import { installSkills, skillStatus } from "../skills/install.js";
|
|
8
|
+
import { setClientEnvKey } from "../skills/setkey.js";
|
|
9
|
+
import { OctenValidationError } from "../api/errors.js";
|
|
10
|
+
import { isClientInstalled } from "../util/detectClient.js";
|
|
8
11
|
// Exported so tests can call with injected dirs
|
|
9
12
|
export function registerConfigureSkills(program, internal = {}) {
|
|
10
13
|
program
|
|
@@ -22,6 +25,8 @@ export function registerConfigureSkills(program, internal = {}) {
|
|
|
22
25
|
.option("--ref <ref>", "upstream git ref to fetch skills from", "main")
|
|
23
26
|
.option("--bundled", "force use of bundled (vendored) skills — no network")
|
|
24
27
|
.option("--offline", "alias for --bundled")
|
|
28
|
+
.option("--set-key", "also write OCTEN_API_KEY into each selected client's env config")
|
|
29
|
+
.option("--force", "configure even if the client is not detected")
|
|
25
30
|
.action(async (_opts, command) => {
|
|
26
31
|
const opts = command.opts();
|
|
27
32
|
const scope = (opts.scope === "project" ? "project" : "user");
|
|
@@ -32,6 +37,7 @@ export function registerConfigureSkills(program, internal = {}) {
|
|
|
32
37
|
: undefined;
|
|
33
38
|
const home = internal.home ?? os.homedir();
|
|
34
39
|
const cwd = internal.cwd ?? process.cwd();
|
|
40
|
+
const isInstalled = internal.isInstalled ?? ((id) => isClientInstalled(id, { home }));
|
|
35
41
|
// Both dist/commands/ (published) and src/commands/ (tsx tests) are two levels below the
|
|
36
42
|
// package root, so ../../skills resolves to the package-root skills/ dir in both.
|
|
37
43
|
const bundledDir = fileURLToPath(new URL("../../skills", import.meta.url));
|
|
@@ -68,15 +74,40 @@ export function registerConfigureSkills(program, internal = {}) {
|
|
|
68
74
|
}
|
|
69
75
|
return;
|
|
70
76
|
}
|
|
71
|
-
// INSTALL MODE
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
77
|
+
// INSTALL MODE — determine which clients to act on, gated by detection.
|
|
78
|
+
let selected;
|
|
79
|
+
if (opts.all) {
|
|
80
|
+
// Start from the full registry, then filter to installed ones.
|
|
81
|
+
const skipped = [];
|
|
82
|
+
selected = SKILL_CLIENTS.filter((c) => {
|
|
83
|
+
if (isInstalled(c.id))
|
|
84
|
+
return true;
|
|
85
|
+
skipped.push(c.label);
|
|
86
|
+
return false;
|
|
87
|
+
});
|
|
88
|
+
if (skipped.length > 0) {
|
|
89
|
+
process.stdout.write(`skipped (not installed): ${skipped.join(", ")}\n`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// Explicit per-client flags: warn + skip not-installed unless --force.
|
|
94
|
+
const requested = SKILL_CLIENTS.filter((c) => {
|
|
75
95
|
const flagName = clientFlagMap[c.id];
|
|
76
96
|
return flagName
|
|
77
97
|
? Boolean(opts[flagName])
|
|
78
98
|
: false;
|
|
79
99
|
});
|
|
100
|
+
selected = requested.filter((c) => {
|
|
101
|
+
if (opts.force || isInstalled(c.id))
|
|
102
|
+
return true;
|
|
103
|
+
process.stderr.write(`warning: ${c.label} not detected — skipping (use --force to configure anyway)\n`);
|
|
104
|
+
return false;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (selected.length === 0) {
|
|
108
|
+
process.stdout.write("no installed clients to configure\n");
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
80
111
|
// Resolve skills source (custom dir, or remote/bundled)
|
|
81
112
|
let srcDir;
|
|
82
113
|
let source;
|
|
@@ -112,7 +143,25 @@ export function registerConfigureSkills(program, internal = {}) {
|
|
|
112
143
|
if (anyFailed) {
|
|
113
144
|
process.exitCode = 1;
|
|
114
145
|
}
|
|
115
|
-
|
|
116
|
-
|
|
146
|
+
if (opts.setKey) {
|
|
147
|
+
const g = command.optsWithGlobals();
|
|
148
|
+
const key = g.apiKey || process.env.OCTEN_API_KEY;
|
|
149
|
+
if (!key) {
|
|
150
|
+
throw new OctenValidationError("--set-key needs a key: pass --api-key or set OCTEN_API_KEY");
|
|
151
|
+
}
|
|
152
|
+
for (const client of selected) {
|
|
153
|
+
const result = setClientEnvKey(client.id, key, scope, home, cwd);
|
|
154
|
+
if (result.written) {
|
|
155
|
+
process.stdout.write(`set OCTEN_API_KEY in ${client.label} (${result.path})\n`);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
process.stdout.write(`${client.label}: ${result.hint}\n`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
// Print API key setup reminder
|
|
164
|
+
process.stdout.write("\nSet OCTEN_API_KEY in each client's environment — see https://octen.ai\n");
|
|
165
|
+
}
|
|
117
166
|
});
|
|
118
167
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type SetKeyResult = {
|
|
2
|
+
clientId: string;
|
|
3
|
+
written: boolean;
|
|
4
|
+
path?: string;
|
|
5
|
+
hint?: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Write OCTEN_API_KEY into a client's env configuration, merging with any
|
|
9
|
+
* existing content (never clobbering unrelated keys). Returns whether a file
|
|
10
|
+
* was written; for clients without an env config file, returns a shell-profile
|
|
11
|
+
* hint instead of editing rc files.
|
|
12
|
+
*/
|
|
13
|
+
export declare function setClientEnvKey(clientId: string, key: string, scope: "user" | "project", home: string, cwd: string): SetKeyResult;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, writeFileSync, existsSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { parse, stringify } from "smol-toml";
|
|
4
|
+
import { OctenValidationError } from "../api/errors.js";
|
|
5
|
+
const SHELL_PROFILE_HINT = "Set OCTEN_API_KEY in your shell profile (e.g. ~/.zshrc: export OCTEN_API_KEY=...) or use direnv";
|
|
6
|
+
function readJsonFile(filePath) {
|
|
7
|
+
if (!existsSync(filePath))
|
|
8
|
+
return {};
|
|
9
|
+
const raw = readFileSync(filePath, "utf8").trim();
|
|
10
|
+
if (!raw)
|
|
11
|
+
return {};
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(raw);
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
throw new OctenValidationError(`Config file ${filePath} contains invalid JSON and cannot be edited safely. Fix or remove it, then retry. (${e.message})`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function readTomlFile(filePath) {
|
|
20
|
+
if (!existsSync(filePath))
|
|
21
|
+
return {};
|
|
22
|
+
const raw = readFileSync(filePath, "utf8").trim();
|
|
23
|
+
if (!raw)
|
|
24
|
+
return {};
|
|
25
|
+
try {
|
|
26
|
+
return parse(raw);
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
throw new OctenValidationError(`Config file ${filePath} contains invalid TOML and cannot be edited safely. Fix or remove it, then retry. (${e.message})`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Write OCTEN_API_KEY into a client's env configuration, merging with any
|
|
34
|
+
* existing content (never clobbering unrelated keys). Returns whether a file
|
|
35
|
+
* was written; for clients without an env config file, returns a shell-profile
|
|
36
|
+
* hint instead of editing rc files.
|
|
37
|
+
*/
|
|
38
|
+
export function setClientEnvKey(clientId, key, scope, home, cwd) {
|
|
39
|
+
switch (clientId) {
|
|
40
|
+
case "claude-code": {
|
|
41
|
+
const path = scope === "project"
|
|
42
|
+
? join(cwd, ".claude/settings.json")
|
|
43
|
+
: join(home, ".claude/settings.json");
|
|
44
|
+
const obj = readJsonFile(path);
|
|
45
|
+
obj.env = {
|
|
46
|
+
...(obj.env ?? {}),
|
|
47
|
+
OCTEN_API_KEY: key,
|
|
48
|
+
};
|
|
49
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
50
|
+
writeFileSync(path, JSON.stringify(obj, null, 2) + "\n", "utf8");
|
|
51
|
+
return { clientId, written: true, path };
|
|
52
|
+
}
|
|
53
|
+
case "codex": {
|
|
54
|
+
const path = join(home, ".codex/config.toml");
|
|
55
|
+
const obj = readTomlFile(path);
|
|
56
|
+
const policy = (obj.shell_environment_policy ??= {});
|
|
57
|
+
policy.set = {
|
|
58
|
+
...(policy.set ?? {}),
|
|
59
|
+
OCTEN_API_KEY: key,
|
|
60
|
+
};
|
|
61
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
62
|
+
writeFileSync(path, stringify(obj), "utf8");
|
|
63
|
+
return { clientId, written: true, path };
|
|
64
|
+
}
|
|
65
|
+
case "openclaw": {
|
|
66
|
+
const path = join(home, ".openclaw/.env");
|
|
67
|
+
const raw = existsSync(path) ? readFileSync(path, "utf8") : "";
|
|
68
|
+
const lines = raw === "" ? [] : raw.replace(/\n+$/, "").split("\n");
|
|
69
|
+
let replaced = false;
|
|
70
|
+
for (let i = 0; i < lines.length; i++) {
|
|
71
|
+
if (/^OCTEN_API_KEY=/.test(lines[i])) {
|
|
72
|
+
lines[i] = `OCTEN_API_KEY=${key}`;
|
|
73
|
+
replaced = true;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (!replaced)
|
|
78
|
+
lines.push(`OCTEN_API_KEY=${key}`);
|
|
79
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
80
|
+
writeFileSync(path, lines.join("\n") + "\n", "utf8");
|
|
81
|
+
return { clientId, written: true, path };
|
|
82
|
+
}
|
|
83
|
+
default:
|
|
84
|
+
return { clientId, written: false, hint: SHELL_PROFILE_HINT };
|
|
85
|
+
}
|
|
86
|
+
}
|
package/dist/skills/source.js
CHANGED
|
@@ -11,46 +11,64 @@ export async function resolveSkillsDir(o) {
|
|
|
11
11
|
}
|
|
12
12
|
// Validate ref before use in paths/URLs to prevent traversal or malformed URLs.
|
|
13
13
|
// Must match /^[\w.\/-]+$/ AND must not contain the ".." sequence.
|
|
14
|
+
// (Validated once up-front; a bad ref is a hard error, never retried/fallback.)
|
|
14
15
|
if (!/^[\w.\/-]+$/.test(o.ref) || o.ref.includes("..")) {
|
|
15
16
|
throw new OctenValidationError(`invalid ref: ${o.ref}`);
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
throw new Error(`HTTP ${response.status} fetching ${url}`);
|
|
23
|
-
}
|
|
24
|
-
const buffer = Buffer.from(await response.arrayBuffer());
|
|
25
|
-
// Write tarball to a collision-resistant temp file for tar.extract (which needs a file path)
|
|
26
|
-
const tmpTar = join(tmpdir(), `octen-skills-${randomUUID()}.tar.gz`);
|
|
27
|
-
writeFileSync(tmpTar, buffer);
|
|
28
|
-
// Extract into a clean cacheDir/<ref>/ (clean so a prior run, possibly from a
|
|
29
|
-
// differently-named archive root, can't leave a stale dir behind).
|
|
30
|
-
const extractDir = join(o.cacheDir, o.ref);
|
|
31
|
-
rmSync(extractDir, { recursive: true, force: true });
|
|
32
|
-
mkdirSync(extractDir, { recursive: true });
|
|
18
|
+
// Retry transient fetch/extract failures (e.g. a single "fetch failed" blip)
|
|
19
|
+
// a few times before falling back to bundled skills.
|
|
20
|
+
const MAX_ATTEMPTS = 3;
|
|
21
|
+
let lastErr;
|
|
22
|
+
for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
|
|
33
23
|
try {
|
|
34
|
-
await
|
|
35
|
-
}
|
|
36
|
-
finally {
|
|
37
|
-
rmSync(tmpTar, { force: true });
|
|
24
|
+
return await fetchRemoteSkills(o);
|
|
38
25
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
throw new Error(`unexpected archive layout: ${roots.length} top-level dirs`);
|
|
26
|
+
catch (err) {
|
|
27
|
+
lastErr = err;
|
|
28
|
+
if (attempt < MAX_ATTEMPTS) {
|
|
29
|
+
await sleep(500 * attempt);
|
|
30
|
+
}
|
|
45
31
|
}
|
|
46
|
-
const skillsDir = join(extractDir, roots[0].name, "skills");
|
|
47
|
-
// Verify the skills/ subdir exists
|
|
48
|
-
readdirSync(skillsDir);
|
|
49
|
-
return { dir: skillsDir, source: "remote" };
|
|
50
32
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
33
|
+
const cause = lastErr?.cause?.code ??
|
|
34
|
+
lastErr?.cause?.message ??
|
|
35
|
+
(lastErr instanceof Error ? lastErr.message : String(lastErr));
|
|
36
|
+
process.stderr.write(`warning: failed to fetch skills from GitHub (${cause}) — using bundled fallback\n`);
|
|
37
|
+
return { dir: o.bundledDir, source: "bundled" };
|
|
38
|
+
}
|
|
39
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
40
|
+
/** One attempt: fetch the tarball, extract it, and locate the skills/ dir. */
|
|
41
|
+
async function fetchRemoteSkills(o) {
|
|
42
|
+
const fetcher = o.fetchImpl ?? fetch;
|
|
43
|
+
const url = SKILLS_REPO_TARBALL(o.ref);
|
|
44
|
+
const response = await fetcher(url);
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
throw new Error(`HTTP ${response.status} fetching ${url}`);
|
|
47
|
+
}
|
|
48
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
49
|
+
// Write tarball to a collision-resistant temp file for tar.extract (which needs a file path)
|
|
50
|
+
const tmpTar = join(tmpdir(), `octen-skills-${randomUUID()}.tar.gz`);
|
|
51
|
+
writeFileSync(tmpTar, buffer);
|
|
52
|
+
// Extract into a clean cacheDir/<ref>/ (clean so a prior run, possibly from a
|
|
53
|
+
// differently-named archive root, can't leave a stale dir behind).
|
|
54
|
+
const extractDir = join(o.cacheDir, o.ref);
|
|
55
|
+
rmSync(extractDir, { recursive: true, force: true });
|
|
56
|
+
mkdirSync(extractDir, { recursive: true });
|
|
57
|
+
try {
|
|
58
|
+
await tar.extract({ file: tmpTar, cwd: extractDir });
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
rmSync(tmpTar, { force: true });
|
|
62
|
+
}
|
|
63
|
+
// GitHub archive tarballs nest everything under a single top-level dir named
|
|
64
|
+
// <repo>-<ref>. The repo can be renamed (the download follows GitHub's
|
|
65
|
+
// redirect), so DISCOVER that root dir rather than hardcoding the repo name.
|
|
66
|
+
const roots = readdirSync(extractDir, { withFileTypes: true }).filter((e) => e.isDirectory());
|
|
67
|
+
if (roots.length !== 1) {
|
|
68
|
+
throw new Error(`unexpected archive layout: ${roots.length} top-level dirs`);
|
|
55
69
|
}
|
|
70
|
+
const skillsDir = join(extractDir, roots[0].name, "skills");
|
|
71
|
+
// Verify the skills/ subdir exists
|
|
72
|
+
readdirSync(skillsDir);
|
|
73
|
+
return { dir: skillsDir, source: "remote" };
|
|
56
74
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface DetectOpts {
|
|
2
|
+
/** Test injection: explicit installed map keyed by client id */
|
|
3
|
+
installed?: Record<string, boolean>;
|
|
4
|
+
/** Injected home dir (for testing); defaults to os.homedir() */
|
|
5
|
+
home?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Detect whether a given client is installed on this machine.
|
|
9
|
+
*
|
|
10
|
+
* Detection deliberately relies on the client's own binary, app bundle, or a
|
|
11
|
+
* config file the client itself creates — never on directories that octen-cli
|
|
12
|
+
* creates (e.g. ~/.cursor/skills), which would produce false positives.
|
|
13
|
+
*
|
|
14
|
+
* Unknown ids return true so we never block clients we don't have a signal for.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isClientInstalled(id: string, opts?: DetectOpts): boolean;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
/** Returns true if `bin` is resolvable on PATH (via `which`). */
|
|
6
|
+
function binOnPath(bin) {
|
|
7
|
+
try {
|
|
8
|
+
execFileSync("which", [bin], { stdio: "ignore" });
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** Returns true if a macOS app bundle named `<name>.app` exists in /Applications. */
|
|
16
|
+
function appExists(name) {
|
|
17
|
+
return existsSync(`/Applications/${name}.app`);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Detect whether a given client is installed on this machine.
|
|
21
|
+
*
|
|
22
|
+
* Detection deliberately relies on the client's own binary, app bundle, or a
|
|
23
|
+
* config file the client itself creates — never on directories that octen-cli
|
|
24
|
+
* creates (e.g. ~/.cursor/skills), which would produce false positives.
|
|
25
|
+
*
|
|
26
|
+
* Unknown ids return true so we never block clients we don't have a signal for.
|
|
27
|
+
*/
|
|
28
|
+
export function isClientInstalled(id, opts) {
|
|
29
|
+
if (opts?.installed && Object.prototype.hasOwnProperty.call(opts.installed, id)) {
|
|
30
|
+
return opts.installed[id];
|
|
31
|
+
}
|
|
32
|
+
const home = opts?.home ?? os.homedir();
|
|
33
|
+
switch (id) {
|
|
34
|
+
case "claude-code":
|
|
35
|
+
return binOnPath("claude") || existsSync(join(home, ".claude.json"));
|
|
36
|
+
case "cursor":
|
|
37
|
+
return binOnPath("cursor") || appExists("Cursor");
|
|
38
|
+
case "codex":
|
|
39
|
+
return binOnPath("codex") || existsSync(join(home, ".codex/config.toml"));
|
|
40
|
+
case "openclaw":
|
|
41
|
+
return binOnPath("openclaw") || binOnPath("claw");
|
|
42
|
+
case "hermes":
|
|
43
|
+
return binOnPath("hermes");
|
|
44
|
+
case "claude-desktop":
|
|
45
|
+
return (appExists("Claude") ||
|
|
46
|
+
existsSync(join(home, "Library/Application Support/Claude")));
|
|
47
|
+
case "windsurf":
|
|
48
|
+
return (binOnPath("windsurf") ||
|
|
49
|
+
appExists("Windsurf") ||
|
|
50
|
+
existsSync(join(home, ".codeium/windsurf")));
|
|
51
|
+
case "vscode":
|
|
52
|
+
return binOnPath("code") || appExists("Visual Studio Code");
|
|
53
|
+
default:
|
|
54
|
+
// Unknown id — don't block.
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
}
|