@octen.ai/cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +184 -0
  3. package/dist/api/chat.d.ts +33 -0
  4. package/dist/api/chat.js +23 -0
  5. package/dist/api/client.d.ts +19 -0
  6. package/dist/api/client.js +111 -0
  7. package/dist/api/constants.d.ts +38 -0
  8. package/dist/api/constants.js +32 -0
  9. package/dist/api/embedding.d.ts +18 -0
  10. package/dist/api/embedding.js +27 -0
  11. package/dist/api/errors.d.ts +14 -0
  12. package/dist/api/errors.js +22 -0
  13. package/dist/api/extract.d.ts +34 -0
  14. package/dist/api/extract.js +26 -0
  15. package/dist/api/search.d.ts +33 -0
  16. package/dist/api/search.js +34 -0
  17. package/dist/api/sse.d.ts +6 -0
  18. package/dist/api/sse.js +53 -0
  19. package/dist/api/vlEmbedding.d.ts +39 -0
  20. package/dist/api/vlEmbedding.js +68 -0
  21. package/dist/cli.d.ts +2 -0
  22. package/dist/cli.js +39 -0
  23. package/dist/commands/chat.d.ts +2 -0
  24. package/dist/commands/chat.js +122 -0
  25. package/dist/commands/configureMcp.d.ts +11 -0
  26. package/dist/commands/configureMcp.js +101 -0
  27. package/dist/commands/configureSkills.d.ts +11 -0
  28. package/dist/commands/configureSkills.js +118 -0
  29. package/dist/commands/embed.d.ts +2 -0
  30. package/dist/commands/embed.js +69 -0
  31. package/dist/commands/fetch.d.ts +2 -0
  32. package/dist/commands/fetch.js +26 -0
  33. package/dist/commands/reset.d.ts +11 -0
  34. package/dist/commands/reset.js +112 -0
  35. package/dist/commands/search.d.ts +2 -0
  36. package/dist/commands/search.js +31 -0
  37. package/dist/commands/utils.d.ts +10 -0
  38. package/dist/commands/utils.js +24 -0
  39. package/dist/commands/vlEmbed.d.ts +2 -0
  40. package/dist/commands/vlEmbed.js +98 -0
  41. package/dist/config/resolve.d.ts +2 -0
  42. package/dist/config/resolve.js +12 -0
  43. package/dist/mcp/clients.d.ts +9 -0
  44. package/dist/mcp/clients.js +58 -0
  45. package/dist/mcp/detect.d.ts +2 -0
  46. package/dist/mcp/detect.js +35 -0
  47. package/dist/mcp/install.d.ts +20 -0
  48. package/dist/mcp/install.js +56 -0
  49. package/dist/mcp/write.d.ts +3 -0
  50. package/dist/mcp/write.js +104 -0
  51. package/dist/output/pretty/chat.d.ts +2 -0
  52. package/dist/output/pretty/chat.js +9 -0
  53. package/dist/output/pretty/embedding.d.ts +11 -0
  54. package/dist/output/pretty/embedding.js +43 -0
  55. package/dist/output/pretty/extract.d.ts +2 -0
  56. package/dist/output/pretty/extract.js +41 -0
  57. package/dist/output/pretty/search.d.ts +2 -0
  58. package/dist/output/pretty/search.js +28 -0
  59. package/dist/output/pretty/vlEmbedding.d.ts +13 -0
  60. package/dist/output/pretty/vlEmbedding.js +47 -0
  61. package/dist/output/render.d.ts +6 -0
  62. package/dist/output/render.js +13 -0
  63. package/dist/skills/clients.d.ts +7 -0
  64. package/dist/skills/clients.js +47 -0
  65. package/dist/skills/install.d.ts +18 -0
  66. package/dist/skills/install.js +77 -0
  67. package/dist/skills/source.d.ts +12 -0
  68. package/dist/skills/source.js +56 -0
  69. package/dist/util/preflightColor.d.ts +1 -0
  70. package/dist/util/preflightColor.js +7 -0
  71. package/package.json +44 -0
  72. package/skills/manifest.json +8 -0
  73. package/skills/octen-design/SKILL.md +218 -0
  74. package/skills/octen-design/scripts/search.py +304 -0
  75. package/skills/octen-search/SKILL.md +199 -0
@@ -0,0 +1,104 @@
1
+ import { mkdirSync, readFileSync, writeFileSync, existsSync } from "node:fs";
2
+ import { dirname } from "node:path";
3
+ import { parse as tomlParse, stringify as tomlStringify } from "smol-toml";
4
+ import { OctenValidationError } from "../api/errors.js";
5
+ function assertNever(x) {
6
+ throw new Error(`unhandled McpFormat: ${String(x)}`);
7
+ }
8
+ function readJsonFile(filePath) {
9
+ if (!existsSync(filePath))
10
+ return {};
11
+ const raw = readFileSync(filePath, "utf8").trim();
12
+ if (!raw)
13
+ return {};
14
+ try {
15
+ return JSON.parse(raw);
16
+ }
17
+ catch (e) {
18
+ throw new OctenValidationError(`Config file ${filePath} contains invalid JSON and cannot be edited safely. Fix or remove it, then retry. (${e.message})`);
19
+ }
20
+ }
21
+ function readTomlFile(filePath) {
22
+ if (!existsSync(filePath))
23
+ return {};
24
+ const raw = readFileSync(filePath, "utf8").trim();
25
+ if (!raw)
26
+ return {};
27
+ try {
28
+ return tomlParse(raw);
29
+ }
30
+ catch (e) {
31
+ throw new OctenValidationError(`Config file ${filePath} contains invalid TOML and cannot be edited safely. Fix or remove it, then retry. (${e.message})`);
32
+ }
33
+ }
34
+ export function upsertMcpServer(filePath, format, entry) {
35
+ mkdirSync(dirname(filePath), { recursive: true });
36
+ switch (format) {
37
+ case "json-mcpServers":
38
+ case "claude-code": {
39
+ const obj = readJsonFile(filePath);
40
+ if (!obj.mcpServers || typeof obj.mcpServers !== "object") {
41
+ obj.mcpServers = {};
42
+ }
43
+ obj.mcpServers["octen"] = entry;
44
+ writeFileSync(filePath, JSON.stringify(obj, null, 2), "utf8");
45
+ return;
46
+ }
47
+ case "json-servers": {
48
+ const obj = readJsonFile(filePath);
49
+ if (!obj.servers || typeof obj.servers !== "object") {
50
+ obj.servers = {};
51
+ }
52
+ obj.servers["octen"] = entry;
53
+ writeFileSync(filePath, JSON.stringify(obj, null, 2), "utf8");
54
+ return;
55
+ }
56
+ case "toml": {
57
+ const obj = readTomlFile(filePath);
58
+ if (!obj.mcp_servers || typeof obj.mcp_servers !== "object") {
59
+ obj.mcp_servers = {};
60
+ }
61
+ obj.mcp_servers["octen"] = entry;
62
+ writeFileSync(filePath, tomlStringify(obj), "utf8");
63
+ return;
64
+ }
65
+ default:
66
+ assertNever(format);
67
+ }
68
+ }
69
+ export function removeMcpServer(filePath, format) {
70
+ if (!existsSync(filePath))
71
+ return false;
72
+ switch (format) {
73
+ case "json-mcpServers":
74
+ case "claude-code": {
75
+ const obj = readJsonFile(filePath);
76
+ const servers = obj.mcpServers;
77
+ if (!servers || !("octen" in servers))
78
+ return false;
79
+ delete servers["octen"];
80
+ writeFileSync(filePath, JSON.stringify(obj, null, 2), "utf8");
81
+ return true;
82
+ }
83
+ case "json-servers": {
84
+ const obj = readJsonFile(filePath);
85
+ const servers = obj.servers;
86
+ if (!servers || !("octen" in servers))
87
+ return false;
88
+ delete servers["octen"];
89
+ writeFileSync(filePath, JSON.stringify(obj, null, 2), "utf8");
90
+ return true;
91
+ }
92
+ case "toml": {
93
+ const obj = readTomlFile(filePath);
94
+ const servers = obj.mcp_servers;
95
+ if (!servers || !("octen" in servers))
96
+ return false;
97
+ delete servers["octen"];
98
+ writeFileSync(filePath, tomlStringify(obj), "utf8");
99
+ return true;
100
+ }
101
+ default:
102
+ return assertNever(format);
103
+ }
104
+ }
@@ -0,0 +1,2 @@
1
+ import type { ChatCompletion } from "../../api/chat.js";
2
+ export declare function renderChat(data: ChatCompletion): string;
@@ -0,0 +1,9 @@
1
+ import pc from "picocolors";
2
+ export function renderChat(data) {
3
+ const content = data?.choices?.[0]?.message?.content ?? "";
4
+ const usage = data?.usage;
5
+ if (!usage)
6
+ return content;
7
+ const footer = pc.dim(`[tokens: prompt=${usage.prompt_tokens ?? "?"}, completion=${usage.completion_tokens ?? "?"}, total=${usage.total_tokens ?? "?"}]`);
8
+ return `${content}\n\n${footer}`;
9
+ }
@@ -0,0 +1,11 @@
1
+ import type { EmbeddingResponse } from "../../api/embedding.js";
2
+ /**
3
+ * Render an OpenAI-style /embedding response in a compact table.
4
+ * The response shape is handled robustly:
5
+ * - vectors at data.data ?? data.embeddings ?? []
6
+ * - each item's vector at item.embedding ?? item.vector ?? item (item may itself be the array)
7
+ * - model at data.model
8
+ *
9
+ * Raw float arrays are never printed in pretty mode.
10
+ */
11
+ export declare function renderEmbedding(data: EmbeddingResponse): string;
@@ -0,0 +1,43 @@
1
+ import pc from "picocolors";
2
+ /**
3
+ * Render an OpenAI-style /embedding response in a compact table.
4
+ * The response shape is handled robustly:
5
+ * - vectors at data.data ?? data.embeddings ?? []
6
+ * - each item's vector at item.embedding ?? item.vector ?? item (item may itself be the array)
7
+ * - model at data.model
8
+ *
9
+ * Raw float arrays are never printed in pretty mode.
10
+ */
11
+ export function renderEmbedding(data) {
12
+ const items = (data?.data ?? data?.embeddings ?? []);
13
+ if (!items.length) {
14
+ return pc.dim("No embeddings returned.");
15
+ }
16
+ const model = data?.model;
17
+ const lines = [];
18
+ // Header
19
+ const modelLabel = model ? pc.dim(` (${model})`) : "";
20
+ lines.push(pc.bold(`Embeddings${modelLabel}`));
21
+ // Column header
22
+ lines.push(pc.dim(" # dims"));
23
+ lines.push(pc.dim(" ─────────"));
24
+ // Rows
25
+ items.forEach((item, i) => {
26
+ // Resolve the actual vector from the item
27
+ const vec = Array.isArray(item)
28
+ ? item
29
+ : Array.isArray(item?.embedding)
30
+ ? item.embedding
31
+ : Array.isArray(item?.vector)
32
+ ? item.vector
33
+ : [];
34
+ const dims = vec.length;
35
+ const idx = String(i + 1).padStart(3);
36
+ const dimsStr = String(dims).padStart(6);
37
+ lines.push(` ${idx} ${dimsStr}`);
38
+ });
39
+ // Footer hint: remind users to use --json for raw vectors
40
+ lines.push("");
41
+ lines.push(pc.dim(" use --json for raw vectors"));
42
+ return lines.join("\n");
43
+ }
@@ -0,0 +1,2 @@
1
+ import type { ExtractResponse } from "../../api/extract.js";
2
+ export declare function renderExtract(data: ExtractResponse): string;
@@ -0,0 +1,41 @@
1
+ import pc from "picocolors";
2
+ const MAX_CONTENT = 500;
3
+ export function renderExtract(data) {
4
+ const items = data?.items ??
5
+ data?.results ??
6
+ [];
7
+ if (!items.length)
8
+ return pc.dim("No results.");
9
+ return items
10
+ .map((item) => {
11
+ const lines = [];
12
+ // Bold URL header
13
+ lines.push(pc.bold(item.url));
14
+ if (item.status === "failed") {
15
+ lines.push(pc.red(` failed: ${item.error_message ?? "(unknown error)"}`));
16
+ }
17
+ else {
18
+ // Dim metadata line: category / page_structure
19
+ const catPrimary = item.category?.primary;
20
+ const structPrimary = item.page_structure?.primary;
21
+ if (catPrimary || structPrimary) {
22
+ const parts = [catPrimary, structPrimary].filter(Boolean).join(" / ");
23
+ lines.push(pc.dim(` ${parts}`));
24
+ }
25
+ // Title
26
+ if (item.title)
27
+ lines.push(` ${item.title}`);
28
+ // Snippet: prefer joined highlights, else truncated full_content
29
+ if (item.highlights && item.highlights.length > 0) {
30
+ lines.push(` ${item.highlights.join(" ")}`);
31
+ }
32
+ else if (item.full_content) {
33
+ const raw = item.full_content;
34
+ const snippet = raw.length > MAX_CONTENT ? raw.slice(0, MAX_CONTENT) + "…" : raw;
35
+ lines.push(` ${snippet}`);
36
+ }
37
+ }
38
+ return lines.join("\n");
39
+ })
40
+ .join("\n\n");
41
+ }
@@ -0,0 +1,2 @@
1
+ import type { SearchResponse } from "../../api/search.js";
2
+ export declare function renderSearch(data: SearchResponse): string;
@@ -0,0 +1,28 @@
1
+ import pc from "picocolors";
2
+ const MAX_SNIPPET = 300;
3
+ export function renderSearch(data) {
4
+ const res = data?.results ?? [];
5
+ if (!res.length)
6
+ return pc.dim("No results.");
7
+ return res
8
+ .map((r, i) => {
9
+ const lines = [];
10
+ // Numbered + bold title
11
+ const title = r.title ?? "(no title)";
12
+ lines.push(`${i + 1}. ${pc.bold(title)}`);
13
+ // Dim URL
14
+ if (r.url)
15
+ lines.push(` ${pc.dim(r.url)}`);
16
+ // Dim publication time
17
+ if (r.time_published)
18
+ lines.push(` ${pc.dim(r.time_published)}`);
19
+ // Snippet from highlight or full_content (truncated)
20
+ const raw = r.highlight ?? r.full_content ?? "";
21
+ if (raw) {
22
+ const snippet = raw.length > MAX_SNIPPET ? raw.slice(0, MAX_SNIPPET) + "…" : raw;
23
+ lines.push(` ${snippet}`);
24
+ }
25
+ return lines.join("\n");
26
+ })
27
+ .join("\n\n");
28
+ }
@@ -0,0 +1,13 @@
1
+ import type { VLEmbeddingResponse } from "../../api/vlEmbedding.js";
2
+ /**
3
+ * Render an Octen /vl-embedding response in a compact table.
4
+ *
5
+ * Response shape is handled robustly:
6
+ * - item list at data.data ?? data.embeddings ?? data.items ?? []
7
+ * - each item's vector at item.embedding ?? item.vector ?? item (bare array)
8
+ * - item type label at item.type (e.g. "fusion" | "vl") when present
9
+ * - model from data.model
10
+ *
11
+ * Raw float arrays are never printed — use --json for those.
12
+ */
13
+ export declare function renderVlEmbedding(data: VLEmbeddingResponse): string;
@@ -0,0 +1,47 @@
1
+ import pc from "picocolors";
2
+ /**
3
+ * Render an Octen /vl-embedding response in a compact table.
4
+ *
5
+ * Response shape is handled robustly:
6
+ * - item list at data.data ?? data.embeddings ?? data.items ?? []
7
+ * - each item's vector at item.embedding ?? item.vector ?? item (bare array)
8
+ * - item type label at item.type (e.g. "fusion" | "vl") when present
9
+ * - model from data.model
10
+ *
11
+ * Raw float arrays are never printed — use --json for those.
12
+ */
13
+ export function renderVlEmbedding(data) {
14
+ const items = (data?.data ?? data?.embeddings ?? data?.items ?? []);
15
+ if (!items.length) {
16
+ return pc.dim("No embeddings returned.");
17
+ }
18
+ const model = data?.model;
19
+ const modelLabel = model ? pc.dim(` (${model})`) : "";
20
+ const lines = [];
21
+ // Header
22
+ lines.push(pc.bold(`VL Embeddings${modelLabel}`));
23
+ // Column header
24
+ lines.push(pc.dim(" # dims type"));
25
+ lines.push(pc.dim(" ───────────────────"));
26
+ // Rows
27
+ items.forEach((item, i) => {
28
+ // Resolve actual vector
29
+ const vec = Array.isArray(item)
30
+ ? item
31
+ : Array.isArray(item?.embedding)
32
+ ? item.embedding
33
+ : Array.isArray(item?.vector)
34
+ ? item.vector
35
+ : [];
36
+ const dims = vec.length;
37
+ const typeLabel = item?.type ?? "";
38
+ const idx = String(i + 1).padStart(3);
39
+ const dimsStr = String(dims).padStart(6);
40
+ const typePart = typeLabel ? ` ${typeLabel}` : "";
41
+ lines.push(` ${idx} ${dimsStr}${typePart}`);
42
+ });
43
+ // Footer hint
44
+ lines.push("");
45
+ lines.push(pc.dim(" use --json for raw vectors"));
46
+ return lines.join("\n");
47
+ }
@@ -0,0 +1,6 @@
1
+ export type OutputMode = "pretty" | "json";
2
+ export declare function chooseMode(opts: {
3
+ json?: boolean;
4
+ pretty?: boolean;
5
+ }, isTty: boolean): OutputMode;
6
+ export declare function emit(data: unknown, mode: OutputMode, prettyFn: (d: any) => string): void;
@@ -0,0 +1,13 @@
1
+ export function chooseMode(opts, isTty) {
2
+ if (opts.json)
3
+ return "json";
4
+ if (opts.pretty)
5
+ return "pretty";
6
+ return isTty ? "pretty" : "json";
7
+ }
8
+ export function emit(data, mode, prettyFn) {
9
+ if (mode === "json")
10
+ process.stdout.write(JSON.stringify(data, null, 2) + "\n");
11
+ else
12
+ process.stdout.write(prettyFn(data) + "\n");
13
+ }
@@ -0,0 +1,7 @@
1
+ export interface SkillClient {
2
+ id: "claude-code" | "cursor" | "codex" | "openclaw" | "hermes";
3
+ label: string;
4
+ supportsProject: boolean;
5
+ dirFor(scope: "user" | "project", home: string, cwd: string): string;
6
+ }
7
+ export declare const SKILL_CLIENTS: SkillClient[];
@@ -0,0 +1,47 @@
1
+ import { join } from "node:path";
2
+ export const SKILL_CLIENTS = [
3
+ {
4
+ id: "claude-code",
5
+ label: "Claude Code",
6
+ supportsProject: true,
7
+ dirFor(scope, home, cwd) {
8
+ return scope === "project"
9
+ ? join(cwd, ".claude/skills")
10
+ : join(home, ".claude/skills");
11
+ },
12
+ },
13
+ {
14
+ id: "cursor",
15
+ label: "Cursor",
16
+ supportsProject: true,
17
+ dirFor(scope, home, cwd) {
18
+ return scope === "project"
19
+ ? join(cwd, ".cursor/skills")
20
+ : join(home, ".cursor/skills");
21
+ },
22
+ },
23
+ {
24
+ id: "codex",
25
+ label: "Codex",
26
+ supportsProject: false,
27
+ dirFor(_scope, home, _cwd) {
28
+ return join(home, ".codex/skills");
29
+ },
30
+ },
31
+ {
32
+ id: "openclaw",
33
+ label: "OpenClaw",
34
+ supportsProject: false,
35
+ dirFor(_scope, home, _cwd) {
36
+ return join(home, ".openclaw/skills");
37
+ },
38
+ },
39
+ {
40
+ id: "hermes",
41
+ label: "Hermes",
42
+ supportsProject: false,
43
+ dirFor(_scope, home, _cwd) {
44
+ return join(home, ".hermes/skills");
45
+ },
46
+ },
47
+ ];
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Remove every octen-* subdirectory from targetSkillsDir.
3
+ * Returns the list of removed skill names.
4
+ * Non-octen-* entries and the parent dir itself are never touched.
5
+ * If targetSkillsDir does not exist, returns [] without throwing.
6
+ */
7
+ export declare function removeSkills(targetSkillsDir: string): string[];
8
+ /**
9
+ * Install octen-* skills from srcDir into targetSkillsDir.
10
+ * If `only` is given, only those skill names are installed.
11
+ * Returns the list of installed skill names.
12
+ */
13
+ export declare function installSkills(srcDir: string, targetSkillsDir: string, ref: string, only?: string[]): string[];
14
+ /**
15
+ * Returns a map of installed octen-* skill names to their .octen-version
16
+ * content (or null if the marker file is absent).
17
+ */
18
+ export declare function skillStatus(targetSkillsDir: string): Record<string, string | null>;
@@ -0,0 +1,77 @@
1
+ import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync, } from "node:fs";
2
+ import { join } from "node:path";
3
+ /**
4
+ * Remove every octen-* subdirectory from targetSkillsDir.
5
+ * Returns the list of removed skill names.
6
+ * Non-octen-* entries and the parent dir itself are never touched.
7
+ * If targetSkillsDir does not exist, returns [] without throwing.
8
+ */
9
+ export function removeSkills(targetSkillsDir) {
10
+ if (!existsSync(targetSkillsDir))
11
+ return [];
12
+ const entries = readdirSync(targetSkillsDir, { withFileTypes: true });
13
+ const removed = [];
14
+ for (const entry of entries) {
15
+ if (!entry.isDirectory())
16
+ continue;
17
+ const name = entry.name;
18
+ if (!name.startsWith("octen-"))
19
+ continue;
20
+ rmSync(join(targetSkillsDir, name), { recursive: true, force: true });
21
+ removed.push(name);
22
+ }
23
+ return removed;
24
+ }
25
+ /**
26
+ * Install octen-* skills from srcDir into targetSkillsDir.
27
+ * If `only` is given, only those skill names are installed.
28
+ * Returns the list of installed skill names.
29
+ */
30
+ export function installSkills(srcDir, targetSkillsDir, ref, only) {
31
+ mkdirSync(targetSkillsDir, { recursive: true });
32
+ const entries = readdirSync(srcDir, { withFileTypes: true });
33
+ const installed = [];
34
+ for (const entry of entries) {
35
+ if (!entry.isDirectory())
36
+ continue;
37
+ const name = entry.name;
38
+ if (!name.startsWith("octen-"))
39
+ continue;
40
+ if (only && !only.includes(name))
41
+ continue;
42
+ const src = join(srcDir, name);
43
+ const dest = join(targetSkillsDir, name);
44
+ // Remove existing skill dir so the install is clean (no stale files linger)
45
+ rmSync(dest, { recursive: true, force: true });
46
+ cpSync(src, dest, { recursive: true });
47
+ // Write version marker
48
+ writeFileSync(join(dest, ".octen-version"), ref, "utf8");
49
+ installed.push(name);
50
+ }
51
+ return installed;
52
+ }
53
+ /**
54
+ * Returns a map of installed octen-* skill names to their .octen-version
55
+ * content (or null if the marker file is absent).
56
+ */
57
+ export function skillStatus(targetSkillsDir) {
58
+ if (!existsSync(targetSkillsDir))
59
+ return {};
60
+ const entries = readdirSync(targetSkillsDir, { withFileTypes: true });
61
+ const result = {};
62
+ for (const entry of entries) {
63
+ if (!entry.isDirectory())
64
+ continue;
65
+ const name = entry.name;
66
+ if (!name.startsWith("octen-"))
67
+ continue;
68
+ const versionFile = join(targetSkillsDir, name, ".octen-version");
69
+ if (existsSync(versionFile)) {
70
+ result[name] = readFileSync(versionFile, "utf8").trim();
71
+ }
72
+ else {
73
+ result[name] = null;
74
+ }
75
+ }
76
+ return result;
77
+ }
@@ -0,0 +1,12 @@
1
+ export interface ResolveOpts {
2
+ ref: string;
3
+ offline: boolean;
4
+ cacheDir: string;
5
+ bundledDir: string;
6
+ fetchImpl?: typeof fetch;
7
+ }
8
+ export interface ResolveResult {
9
+ dir: string;
10
+ source: "remote" | "bundled";
11
+ }
12
+ export declare function resolveSkillsDir(o: ResolveOpts): Promise<ResolveResult>;
@@ -0,0 +1,56 @@
1
+ import { mkdirSync, readdirSync, rmSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { tmpdir } from "node:os";
4
+ import { randomUUID } from "node:crypto";
5
+ import * as tar from "tar";
6
+ import { SKILLS_REPO_TARBALL } from "../api/constants.js";
7
+ import { OctenValidationError } from "../api/errors.js";
8
+ export async function resolveSkillsDir(o) {
9
+ if (o.offline) {
10
+ return { dir: o.bundledDir, source: "bundled" };
11
+ }
12
+ // Validate ref before use in paths/URLs to prevent traversal or malformed URLs.
13
+ // Must match /^[\w.\/-]+$/ AND must not contain the ".." sequence.
14
+ if (!/^[\w.\/-]+$/.test(o.ref) || o.ref.includes("..")) {
15
+ throw new OctenValidationError(`invalid ref: ${o.ref}`);
16
+ }
17
+ try {
18
+ const fetcher = o.fetchImpl ?? fetch;
19
+ const url = SKILLS_REPO_TARBALL(o.ref);
20
+ const response = await fetcher(url);
21
+ if (!response.ok) {
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 });
33
+ try {
34
+ await tar.extract({ file: tmpTar, cwd: extractDir });
35
+ }
36
+ finally {
37
+ rmSync(tmpTar, { force: true });
38
+ }
39
+ // GitHub archive tarballs nest everything under a single top-level dir named
40
+ // <repo>-<ref>. The repo can be renamed (the download follows GitHub's
41
+ // redirect), so DISCOVER that root dir rather than hardcoding the repo name.
42
+ const roots = readdirSync(extractDir, { withFileTypes: true }).filter((e) => e.isDirectory());
43
+ if (roots.length !== 1) {
44
+ throw new Error(`unexpected archive layout: ${roots.length} top-level dirs`);
45
+ }
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
+ }
51
+ catch (err) {
52
+ const msg = err instanceof Error ? err.message : String(err);
53
+ process.stderr.write(`warning: failed to fetch skills from GitHub (${msg}) — using bundled fallback\n`);
54
+ return { dir: o.bundledDir, source: "bundled" };
55
+ }
56
+ }
@@ -0,0 +1 @@
1
+ export declare function applyNoColor(argv: string[], env: NodeJS.ProcessEnv): void;
@@ -0,0 +1,7 @@
1
+ // Honor --no-color before picocolors is imported anywhere (it reads NO_COLOR at module-eval time).
2
+ export function applyNoColor(argv, env) {
3
+ if (argv.includes("--no-color")) {
4
+ env.NO_COLOR = "1";
5
+ }
6
+ }
7
+ applyNoColor(process.argv, process.env);
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@octen.ai/cli",
3
+ "version": "0.1.0",
4
+ "description": "Command-line tool for Octen — web search, extract, chat, embeddings, and one-command MCP/Skills setup.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Octen <hello@octen.ai>",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "bin": {
12
+ "octen": "dist/cli.js"
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "skills",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "engines": {
21
+ "node": ">=18"
22
+ },
23
+ "scripts": {
24
+ "build": "tsc && chmod +x dist/cli.js",
25
+ "dev": "tsc --watch",
26
+ "test": "vitest run",
27
+ "test:watch": "vitest",
28
+ "sync-skills": "tsx scripts/sync-skills.ts",
29
+ "prepublishOnly": "npm run build"
30
+ },
31
+ "dependencies": {
32
+ "commander": "^12.1.0",
33
+ "picocolors": "^1.0.1",
34
+ "smol-toml": "^1.7.0",
35
+ "tar": "^7.5.16"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "^22.0.0",
39
+ "@types/tar": "^6.1.13",
40
+ "tsx": "^4.0.0",
41
+ "typescript": "^5.5.0",
42
+ "vitest": "^2.0.0"
43
+ }
44
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "source": "Octen-Team/octen-skills",
3
+ "ref": "main",
4
+ "skills": [
5
+ "octen-design",
6
+ "octen-search"
7
+ ]
8
+ }