@octen.ai/cli 0.1.9 → 0.1.11
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 +12 -7
- package/dist/commands/completion.d.ts +6 -1
- package/dist/commands/completion.js +52 -4
- package/dist/commands/configureMcp.js +2 -1
- package/dist/commands/configureSkills.js +3 -2
- package/dist/commands/reset.js +11 -3
- package/dist/util/quotePath.d.ts +9 -0
- package/dist/util/quotePath.js +13 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -184,17 +184,22 @@ Options: `--all` (both surfaces, all clients), `--mcp`, `--skills`, plus per-cli
|
|
|
184
184
|
|
|
185
185
|
## Shell completion
|
|
186
186
|
|
|
187
|
-
`octen completion <shell>`
|
|
187
|
+
`octen completion <shell>` (bash | zsh | fish) sets up tab-completion for subcommands and flags.
|
|
188
|
+
|
|
189
|
+
**Easiest — `--install`** writes it into your shell config for you (idempotent):
|
|
188
190
|
|
|
189
191
|
```sh
|
|
190
|
-
|
|
191
|
-
|
|
192
|
+
octen completion zsh --install # appends to ~/.zshrc
|
|
193
|
+
octen completion bash --install # appends to ~/.bashrc
|
|
194
|
+
octen completion fish --install # writes ~/.config/fish/completions/octen.fish
|
|
195
|
+
```
|
|
192
196
|
|
|
193
|
-
|
|
194
|
-
eval "$(octen completion bash)"
|
|
197
|
+
Then `source ~/.zshrc` (or open a new terminal) to activate it in the current session.
|
|
195
198
|
|
|
196
|
-
|
|
197
|
-
|
|
199
|
+
**Manual** — print the script and source it yourself (a subprocess can't change your running shell, so this is how to activate it immediately in the current shell):
|
|
200
|
+
|
|
201
|
+
```sh
|
|
202
|
+
eval "$(octen completion zsh)" # add this line to ~/.zshrc to persist
|
|
198
203
|
```
|
|
199
204
|
|
|
200
205
|
---
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import type { Command } from "commander";
|
|
2
2
|
export declare function buildCompletionScript(program: Command, shell: string): string;
|
|
3
|
-
|
|
3
|
+
interface CompletionInternalOpts {
|
|
4
|
+
/** Injected home dir (for testing); defaults to os.homedir() */
|
|
5
|
+
home?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function registerCompletion(program: Command, internal?: CompletionInternalOpts): void;
|
|
8
|
+
export {};
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import { existsSync, readFileSync, appendFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
1
4
|
import { OctenValidationError } from "../api/errors.js";
|
|
5
|
+
import { quotePath } from "../util/quotePath.js";
|
|
2
6
|
const SUPPORTED_SHELLS = ["bash", "zsh", "fish"];
|
|
3
7
|
/** Collect long/short flag tokens (e.g. "--count", "-n") from a list of options. */
|
|
4
8
|
function flagsFor(options) {
|
|
@@ -113,13 +117,57 @@ export function buildCompletionScript(program, shell) {
|
|
|
113
117
|
throw new OctenValidationError(`unsupported shell: ${shell} (supported: ${SUPPORTED_SHELLS.join(", ")})`);
|
|
114
118
|
}
|
|
115
119
|
}
|
|
116
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Persist completion into the user's shell config.
|
|
122
|
+
* - bash/zsh: append an idempotent `eval "$(octen completion <shell>)"` line to
|
|
123
|
+
* the rc file, so it stays in sync with the CLI and loads in new shells.
|
|
124
|
+
* - fish: write the generated script into the auto-loaded completions dir.
|
|
125
|
+
*/
|
|
126
|
+
function installCompletion(shell, program, home) {
|
|
127
|
+
if (shell === "fish") {
|
|
128
|
+
const dir = join(home, ".config/fish/completions");
|
|
129
|
+
mkdirSync(dir, { recursive: true });
|
|
130
|
+
const file = join(dir, "octen.fish");
|
|
131
|
+
writeFileSync(file, buildCompletionScript(program, "fish"), "utf8");
|
|
132
|
+
return { action: "written", path: file };
|
|
133
|
+
}
|
|
134
|
+
const rc = shell === "zsh" ? join(home, ".zshrc") : join(home, ".bashrc");
|
|
135
|
+
const line = `eval "$(octen completion ${shell})"`;
|
|
136
|
+
const existing = existsSync(rc) ? readFileSync(rc, "utf8") : "";
|
|
137
|
+
if (existing.includes(line)) {
|
|
138
|
+
return { action: "already", path: rc };
|
|
139
|
+
}
|
|
140
|
+
const prefix = existing === "" || existing.endsWith("\n") ? "" : "\n";
|
|
141
|
+
appendFileSync(rc, `${prefix}\n# octen CLI completion\n${line}\n`, "utf8");
|
|
142
|
+
return { action: "installed", path: rc };
|
|
143
|
+
}
|
|
144
|
+
export function registerCompletion(program, internal = {}) {
|
|
117
145
|
program
|
|
118
146
|
.command("completion")
|
|
119
147
|
.argument("<shell>", "bash | zsh | fish")
|
|
120
|
-
.description("Output a shell completion script")
|
|
121
|
-
.
|
|
148
|
+
.description("Output a shell completion script (or --install it into your shell config)")
|
|
149
|
+
.option("--install", "write the completion into your shell config instead of printing")
|
|
150
|
+
.action((shell, opts) => {
|
|
151
|
+
// Validates the shell (throws OctenValidationError for unknown shells).
|
|
122
152
|
const script = buildCompletionScript(program, shell);
|
|
123
|
-
|
|
153
|
+
if (!opts.install) {
|
|
154
|
+
process.stdout.write(script);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const home = internal.home ?? os.homedir();
|
|
158
|
+
const result = installCompletion(shell, program, home);
|
|
159
|
+
if (result.action === "already") {
|
|
160
|
+
process.stdout.write(`completion already installed in ${quotePath(result.path)}\n`);
|
|
161
|
+
}
|
|
162
|
+
else if (result.action === "written") {
|
|
163
|
+
process.stdout.write(`wrote fish completion to ${quotePath(result.path)} (new shells pick it up automatically)\n`);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
process.stdout.write(`added octen completion to ${quotePath(result.path)}\n`);
|
|
167
|
+
}
|
|
168
|
+
if (shell !== "fish") {
|
|
169
|
+
const rc = shell === "zsh" ? "~/.zshrc" : "~/.bashrc";
|
|
170
|
+
process.stdout.write(`run \`source ${rc}\` (or open a new terminal) to activate it now\n`);
|
|
171
|
+
}
|
|
124
172
|
});
|
|
125
173
|
}
|
|
@@ -5,6 +5,7 @@ import { installMcp } from "../mcp/install.js";
|
|
|
5
5
|
import { mcpStatus } from "../mcp/detect.js";
|
|
6
6
|
import { resolveApiKey } from "../config/resolve.js";
|
|
7
7
|
import { isClientInstalled } from "../util/detectClient.js";
|
|
8
|
+
import { quotePath } from "../util/quotePath.js";
|
|
8
9
|
// Exported so tests can call with injected dirs
|
|
9
10
|
export function registerConfigureMcp(program, internal = {}) {
|
|
10
11
|
program
|
|
@@ -110,7 +111,7 @@ export function registerConfigureMcp(program, internal = {}) {
|
|
|
110
111
|
process.stdout.write(`${client.label}: configured via claude CLI\n`);
|
|
111
112
|
}
|
|
112
113
|
else {
|
|
113
|
-
process.stdout.write(`${client.label}: configured → ${result.path}\n`);
|
|
114
|
+
process.stdout.write(`${client.label}: configured → ${quotePath(result.path)}\n`);
|
|
114
115
|
}
|
|
115
116
|
}
|
|
116
117
|
catch (err) {
|
|
@@ -8,6 +8,7 @@ import { installSkills, skillStatus } from "../skills/install.js";
|
|
|
8
8
|
import { setClientEnvKey } from "../skills/setkey.js";
|
|
9
9
|
import { OctenValidationError } from "../api/errors.js";
|
|
10
10
|
import { isClientInstalled } from "../util/detectClient.js";
|
|
11
|
+
import { quotePath } from "../util/quotePath.js";
|
|
11
12
|
// Exported so tests can call with injected dirs
|
|
12
13
|
export function registerConfigureSkills(program, internal = {}) {
|
|
13
14
|
program
|
|
@@ -134,7 +135,7 @@ export function registerConfigureSkills(program, internal = {}) {
|
|
|
134
135
|
try {
|
|
135
136
|
const installed = installSkills(srcDir, targetDir, ref, only);
|
|
136
137
|
const skillList = installed.length > 0 ? installed.join(", ") : "(none)";
|
|
137
|
-
process.stdout.write(`${client.label}: installed [${skillList}] → ${targetDir} (source: ${source})\n`);
|
|
138
|
+
process.stdout.write(`${client.label}: installed [${skillList}] → ${quotePath(targetDir)} (source: ${source})\n`);
|
|
138
139
|
}
|
|
139
140
|
catch (err) {
|
|
140
141
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -157,7 +158,7 @@ export function registerConfigureSkills(program, internal = {}) {
|
|
|
157
158
|
for (const client of selected) {
|
|
158
159
|
const result = setClientEnvKey(client.id, key, scope, home, cwd);
|
|
159
160
|
if (result.written) {
|
|
160
|
-
process.stdout.write(`set OCTEN_API_KEY in ${client.label} (${result.path})\n`);
|
|
161
|
+
process.stdout.write(`set OCTEN_API_KEY in ${client.label} (${quotePath(result.path)})\n`);
|
|
161
162
|
}
|
|
162
163
|
else {
|
|
163
164
|
process.stdout.write(`${client.label}: ${result.hint}\n`);
|
package/dist/commands/reset.js
CHANGED
|
@@ -4,6 +4,7 @@ import { MCP_CLIENTS } from "../mcp/clients.js";
|
|
|
4
4
|
import { SKILL_CLIENTS } from "../skills/clients.js";
|
|
5
5
|
import { removeMcp } from "../mcp/install.js";
|
|
6
6
|
import { removeSkills } from "../skills/install.js";
|
|
7
|
+
import { quotePath } from "../util/quotePath.js";
|
|
7
8
|
// Maps CLI flag name → client id (shared across both registries)
|
|
8
9
|
const CLIENT_FLAG_MAP = {
|
|
9
10
|
claudeCode: "claude-code",
|
|
@@ -71,7 +72,7 @@ export function registerReset(program, internal = {}) {
|
|
|
71
72
|
try {
|
|
72
73
|
const result = removeMcp(client, scope, home, cwd, installOpts);
|
|
73
74
|
if (result.removed) {
|
|
74
|
-
process.stdout.write(`removed octen from ${client.label} (${result.path})\n`);
|
|
75
|
+
process.stdout.write(`removed octen from ${client.label} (${quotePath(result.path)})\n`);
|
|
75
76
|
}
|
|
76
77
|
else {
|
|
77
78
|
process.stdout.write(`octen not present in ${client.label}\n`);
|
|
@@ -86,13 +87,20 @@ export function registerReset(program, internal = {}) {
|
|
|
86
87
|
}
|
|
87
88
|
// --- Skills surface ---
|
|
88
89
|
if (doSkills) {
|
|
89
|
-
|
|
90
|
+
// Claude Desktop shares Claude Code's ~/.claude/skills, so for the skills
|
|
91
|
+
// surface treat --claude-desktop as --claude-code (consistent with configure-skills).
|
|
92
|
+
const skillRequestedIds = new Set(requestedIds);
|
|
93
|
+
if (skillRequestedIds.has("claude-desktop"))
|
|
94
|
+
skillRequestedIds.add("claude-code");
|
|
95
|
+
const selectedSkillClients = opts.all || !anyPerClientFlag
|
|
96
|
+
? SKILL_CLIENTS
|
|
97
|
+
: SKILL_CLIENTS.filter((c) => skillRequestedIds.has(c.id));
|
|
90
98
|
for (const client of selectedSkillClients) {
|
|
91
99
|
try {
|
|
92
100
|
const skillsDir = client.dirFor(scope, home, cwd);
|
|
93
101
|
const removed = removeSkills(skillsDir);
|
|
94
102
|
if (removed.length > 0) {
|
|
95
|
-
process.stdout.write(`removed [${removed.join(", ")}] from ${client.label} (${skillsDir})\n`);
|
|
103
|
+
process.stdout.write(`removed [${removed.join(", ")}] from ${client.label} (${quotePath(skillsDir)})\n`);
|
|
96
104
|
}
|
|
97
105
|
else {
|
|
98
106
|
process.stdout.write(`no octen skills in ${client.label}\n`);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make a filesystem path safe to copy-paste into a shell command.
|
|
3
|
+
*
|
|
4
|
+
* macOS config paths often contain spaces (e.g. "Application Support"), and a
|
|
5
|
+
* bare path printed to the console breaks when pasted into `cat <path>`. If the
|
|
6
|
+
* path contains whitespace or shell-special characters, wrap it in single
|
|
7
|
+
* quotes (escaping any embedded single quote); otherwise return it unchanged.
|
|
8
|
+
*/
|
|
9
|
+
export declare function quotePath(p: string): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make a filesystem path safe to copy-paste into a shell command.
|
|
3
|
+
*
|
|
4
|
+
* macOS config paths often contain spaces (e.g. "Application Support"), and a
|
|
5
|
+
* bare path printed to the console breaks when pasted into `cat <path>`. If the
|
|
6
|
+
* path contains whitespace or shell-special characters, wrap it in single
|
|
7
|
+
* quotes (escaping any embedded single quote); otherwise return it unchanged.
|
|
8
|
+
*/
|
|
9
|
+
export function quotePath(p) {
|
|
10
|
+
if (!/[\s'"$`\\!*?(){}\[\]|&;<>~#]/.test(p))
|
|
11
|
+
return p;
|
|
12
|
+
return `'${p.replace(/'/g, "'\\''")}'`;
|
|
13
|
+
}
|