@octen.ai/cli 0.1.10 → 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 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>` prints a completion script for `bash`, `zsh`, or `fish`. It completes subcommand names and each subcommand's flags.
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
- # zsh — add to ~/.zshrc
191
- eval "$(octen completion zsh)"
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
- # bash — add to ~/.bashrc
194
- eval "$(octen completion bash)"
197
+ Then `source ~/.zshrc` (or open a new terminal) to activate it in the current session.
195
198
 
196
- # fish — write to the completions dir
197
- octen completion fish > ~/.config/fish/completions/octen.fish
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
- export declare function registerCompletion(program: Command): void;
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
- export function registerCompletion(program) {
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
- .action((shell) => {
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
- process.stdout.write(script);
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octen.ai/cli",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "Command-line tool for Octen — web search, extract, chat, embeddings, and one-command MCP/Skills setup.",
5
5
  "type": "module",
6
6
  "license": "MIT",