@octen.ai/cli 0.1.10 → 0.1.12
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 +18 -7
- package/dist/commands/completion.d.ts +6 -1
- package/dist/commands/completion.js +64 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,6 +8,12 @@ Command-line tool for Octen — web search, extract, chat, embeddings, and one-c
|
|
|
8
8
|
npm i -g @octen.ai/cli
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
Then enable tab-completion (one-time; `bash` / `zsh` / `fish`):
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
octen completion zsh --install # writes to ~/.zshrc — then: source ~/.zshrc
|
|
15
|
+
```
|
|
16
|
+
|
|
11
17
|
Or run without installing:
|
|
12
18
|
|
|
13
19
|
```sh
|
|
@@ -184,17 +190,22 @@ Options: `--all` (both surfaces, all clients), `--mcp`, `--skills`, plus per-cli
|
|
|
184
190
|
|
|
185
191
|
## Shell completion
|
|
186
192
|
|
|
187
|
-
`octen completion <shell>`
|
|
193
|
+
`octen completion <shell>` (bash | zsh | fish) sets up tab-completion for subcommands and flags.
|
|
194
|
+
|
|
195
|
+
**Easiest — `--install`** writes it into your shell config for you (idempotent):
|
|
188
196
|
|
|
189
197
|
```sh
|
|
190
|
-
|
|
191
|
-
|
|
198
|
+
octen completion zsh --install # appends to ~/.zshrc
|
|
199
|
+
octen completion bash --install # appends to ~/.bashrc
|
|
200
|
+
octen completion fish --install # writes ~/.config/fish/completions/octen.fish
|
|
201
|
+
```
|
|
192
202
|
|
|
193
|
-
|
|
194
|
-
eval "$(octen completion bash)"
|
|
203
|
+
Then `source ~/.zshrc` (or open a new terminal) to activate it in the current session.
|
|
195
204
|
|
|
196
|
-
|
|
197
|
-
|
|
205
|
+
**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):
|
|
206
|
+
|
|
207
|
+
```sh
|
|
208
|
+
eval "$(octen completion zsh)" # add this line to ~/.zshrc to persist
|
|
198
209
|
```
|
|
199
210
|
|
|
200
211
|
---
|
|
@@ -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) {
|
|
@@ -65,8 +69,18 @@ function bashScript(model) {
|
|
|
65
69
|
}
|
|
66
70
|
function zshScript(model) {
|
|
67
71
|
// Reuse the bash function through zsh's bashcompinit shim. This is reliable
|
|
68
|
-
// and stays in sync with the bash implementation.
|
|
69
|
-
|
|
72
|
+
// and stays in sync with the bash implementation. bashcompinit depends on the
|
|
73
|
+
// zsh completion system, so initialize compinit first if the user's shell
|
|
74
|
+
// hasn't already (makes a bare `source`/`eval` work without extra setup).
|
|
75
|
+
const preamble = [
|
|
76
|
+
"#compdef octen",
|
|
77
|
+
'# octen zsh completion. Source via: eval "$(octen completion zsh)"',
|
|
78
|
+
"if ! whence compdef >/dev/null 2>&1; then",
|
|
79
|
+
" autoload -Uz compinit && compinit -u",
|
|
80
|
+
"fi",
|
|
81
|
+
"autoload -Uz bashcompinit && bashcompinit",
|
|
82
|
+
].join("\n");
|
|
83
|
+
return `${preamble}\n${bashFunction(model)}\n`;
|
|
70
84
|
}
|
|
71
85
|
/** Strip leading dashes for fish's `-l`/`-s` which want bare names. */
|
|
72
86
|
function fishFlagArgs(flags) {
|
|
@@ -113,13 +127,57 @@ export function buildCompletionScript(program, shell) {
|
|
|
113
127
|
throw new OctenValidationError(`unsupported shell: ${shell} (supported: ${SUPPORTED_SHELLS.join(", ")})`);
|
|
114
128
|
}
|
|
115
129
|
}
|
|
116
|
-
|
|
130
|
+
/**
|
|
131
|
+
* Persist completion into the user's shell config.
|
|
132
|
+
* - bash/zsh: append an idempotent `eval "$(octen completion <shell>)"` line to
|
|
133
|
+
* the rc file, so it stays in sync with the CLI and loads in new shells.
|
|
134
|
+
* - fish: write the generated script into the auto-loaded completions dir.
|
|
135
|
+
*/
|
|
136
|
+
function installCompletion(shell, program, home) {
|
|
137
|
+
if (shell === "fish") {
|
|
138
|
+
const dir = join(home, ".config/fish/completions");
|
|
139
|
+
mkdirSync(dir, { recursive: true });
|
|
140
|
+
const file = join(dir, "octen.fish");
|
|
141
|
+
writeFileSync(file, buildCompletionScript(program, "fish"), "utf8");
|
|
142
|
+
return { action: "written", path: file };
|
|
143
|
+
}
|
|
144
|
+
const rc = shell === "zsh" ? join(home, ".zshrc") : join(home, ".bashrc");
|
|
145
|
+
const line = `eval "$(octen completion ${shell})"`;
|
|
146
|
+
const existing = existsSync(rc) ? readFileSync(rc, "utf8") : "";
|
|
147
|
+
if (existing.includes(line)) {
|
|
148
|
+
return { action: "already", path: rc };
|
|
149
|
+
}
|
|
150
|
+
const prefix = existing === "" || existing.endsWith("\n") ? "" : "\n";
|
|
151
|
+
appendFileSync(rc, `${prefix}\n# octen CLI completion\n${line}\n`, "utf8");
|
|
152
|
+
return { action: "installed", path: rc };
|
|
153
|
+
}
|
|
154
|
+
export function registerCompletion(program, internal = {}) {
|
|
117
155
|
program
|
|
118
156
|
.command("completion")
|
|
119
157
|
.argument("<shell>", "bash | zsh | fish")
|
|
120
|
-
.description("Output a shell completion script")
|
|
121
|
-
.
|
|
158
|
+
.description("Output a shell completion script (or --install it into your shell config)")
|
|
159
|
+
.option("--install", "write the completion into your shell config instead of printing")
|
|
160
|
+
.action((shell, opts) => {
|
|
161
|
+
// Validates the shell (throws OctenValidationError for unknown shells).
|
|
122
162
|
const script = buildCompletionScript(program, shell);
|
|
123
|
-
|
|
163
|
+
if (!opts.install) {
|
|
164
|
+
process.stdout.write(script);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const home = internal.home ?? os.homedir();
|
|
168
|
+
const result = installCompletion(shell, program, home);
|
|
169
|
+
if (result.action === "already") {
|
|
170
|
+
process.stdout.write(`completion already installed in ${quotePath(result.path)}\n`);
|
|
171
|
+
}
|
|
172
|
+
else if (result.action === "written") {
|
|
173
|
+
process.stdout.write(`wrote fish completion to ${quotePath(result.path)} (new shells pick it up automatically)\n`);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
process.stdout.write(`added octen completion to ${quotePath(result.path)}\n`);
|
|
177
|
+
}
|
|
178
|
+
if (shell !== "fish") {
|
|
179
|
+
const rc = shell === "zsh" ? "~/.zshrc" : "~/.bashrc";
|
|
180
|
+
process.stdout.write(`run \`source ${rc}\` (or open a new terminal) to activate it now\n`);
|
|
181
|
+
}
|
|
124
182
|
});
|
|
125
183
|
}
|