@termwire/cli 0.2.2 → 0.3.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,43 @@
1
1
  # @termwire/cli
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - f57c480: Run on Node instead of requiring Bun. Every package now spawns through
8
+ `node:child_process`, emits explicit `.js` extensions on relative imports, and
9
+ ships a `#!/usr/bin/env node` entry point. `engines` declares `node >=22.12.0`,
10
+ the floor set by Commander 15.
11
+
12
+ The published CLI and MCP server previously failed under Node with
13
+ `ERR_MODULE_NOT_FOUND` and had no test covering it. `bun run verify:node`
14
+ executes both built artifacts under Node, and CI runs it on every push.
15
+
16
+ This makes `npx -y @termwire/mcp` the recommended MCP registration. Unlike
17
+ `bunx`, the `npx` cache lives under `~/.npm` and is not swept by the nightly
18
+ macOS temporary-directory cleanup that silently broke the server.
19
+
20
+ Emitted type declarations are now typed against `@types/node` alone and no
21
+ longer reference Bun types.
22
+
23
+ The repository is still developed with Bun. Only the published output changed.
24
+
25
+ - f57c480: Add the `termwire open <target>` command, which opens a file in the workspace
26
+ Neovim and focuses the editor pane. A trailing `:<line>` selects a line, and
27
+ `--line` keeps the target verbatim for filenames that end in a colon and
28
+ digits. This gives any agent that can run a shell command the same capability
29
+ as the MCP server and the OpenCode plugin, with nothing to configure.
30
+
31
+ Correct the OpenCode plugin's out-of-workspace error to `not inside a termwire
32
+ workspace`, matching the CLI and the MCP server.
33
+
34
+ ### Patch Changes
35
+
36
+ - Updated dependencies [f57c480]
37
+ - Updated dependencies [f57c480]
38
+ - @termwire/nvim@0.3.0
39
+ - @termwire/tmux@0.3.0
40
+
3
41
  ## 0.2.2
4
42
 
5
43
  ### Patch Changes
package/README.md CHANGED
@@ -1,25 +1,23 @@
1
1
  # @termwire/cli
2
2
 
3
- Requires Bun >=1.3.14, tmux >=3.2, and Neovim >=0.9.
3
+ The `termwire` command. It creates tmux workspaces with a Neovim RPC socket and
4
+ opens files in the workspace editor.
5
+
6
+ Requires Node >=22.12, tmux >=3.2, and Neovim >=0.9. It runs on Bun as well.
4
7
 
5
8
  ```bash
6
- bun add --global @termwire/cli
9
+ npm install -g @termwire/cli
7
10
  termwire --help
8
11
  termwire up dev
12
+ termwire open src/app.ts:42
9
13
  ```
10
14
 
11
- The project's main entry point — the `termwire` command. It orchestrates the
12
- other packages. Runtime workspace identity is stateless and lives in the
13
- environment variables set by `termwire up <name>`; layout configuration is
14
- optional JSONC, not persistent workspace state.
15
-
16
- ## Why it exists
15
+ Workspace identity is stateless. It lives in the environment variables that
16
+ `termwire up <name>` exports into every pane, never in a file on disk. Layout
17
+ configuration is optional JSONC read when a session is created; it is not
18
+ workspace state.
17
19
 
18
- This is the tool that removes manual tmux/editor setup: bring up a stateless
19
- workspace with a single command. The CLI owns `up <name>` only; file opening is
20
- the explicit `termwire_open({ path, line? })` OpenCode plugin tool.
21
-
22
- ## Commands
20
+ ## `up`
23
21
 
24
22
  | Command | Workspace | Branch |
25
23
  | --- | --- | --- |
@@ -37,6 +35,39 @@ Git branch names and replaced only in filesystem-safe worktree directory names.
37
35
  is changed only when `--branch` is present. Existing tmux sessions attach without Git mutations or
38
36
  rereading/reconciling configuration.
39
37
 
38
+ ## `open`
39
+
40
+ ```bash
41
+ termwire open <target>
42
+ termwire open <target> --line <number>
43
+ ```
44
+
45
+ Opens a file in the Neovim of the current workspace and focuses the editor
46
+ pane. A trailing `:<line>` in the target selects a line, so `src/app.ts:42`
47
+ opens line 42. With `--line`, the target is used verbatim, which is the way to
48
+ open a file whose name ends in a colon and digits. Relative paths resolve from
49
+ the current directory. On success the command prints the absolute path it
50
+ opened.
51
+
52
+ | Invocation | Opens |
53
+ | --- | --- |
54
+ | `termwire open src/app.ts` | `src/app.ts`, no line jump |
55
+ | `termwire open src/app.ts:42` | `src/app.ts` at line 42 |
56
+ | `termwire open src/app.ts -l 42` | `src/app.ts` at line 42 |
57
+ | `termwire open weird:42 -l 7` | the file named `weird:42`, at line 7 |
58
+
59
+ The command reads `TERMWIRE_SOCKET` and `TERMWIRE_EDITOR_PANE` from its
60
+ environment, so it works only in a shell created by `termwire up`. Errors are
61
+ reported without a stack trace:
62
+
63
+ - `not inside a termwire workspace`: `TERMWIRE_SOCKET` is missing.
64
+ - `nvim is not responding on socket ...`: the workspace Neovim is gone.
65
+ - `line must be a positive integer`, `path must not be empty`: bad target.
66
+
67
+ Pane focus is skipped when `TERMWIRE_EDITOR_PANE` is absent; opening still
68
+ succeeds. This is what makes the command useful to a coding agent: it needs no
69
+ integration beyond permission to run a shell command.
70
+
40
71
  ## Layout configuration
41
72
 
42
73
  TermWire discovers optional JSONC files in this order:
@@ -308,8 +339,10 @@ while preserving the original failure.
308
339
  - The default layout does not start OpenCode automatically. Users may start it manually in an
309
340
  ordinary shell pane, or configure `["opencode"]` as a pane command. They may also reshape the
310
341
  workspace with tmux after creation.
311
- - The CLI has no shell-facing `open` command and does not need to be in `PATH`
312
- for the plugin: the plugin composes the nvim and tmux adapters directly.
342
+ - `open <target>` resolves the path, checks that Neovim answers on the socket,
343
+ opens the file, then focuses the editor pane when one is known.
344
+ - The CLI does not need to be in `PATH` for the MCP server or the OpenCode
345
+ plugin. Both compose the nvim and tmux adapters directly.
313
346
 
314
347
  ## Dependencies
315
348
 
@@ -318,3 +351,9 @@ Zod 4 provides strict structural config validation. All three are direct runtime
318
351
  dependencies.
319
352
  `@termwire/tmux` and `@termwire/nvim` are thin adapters over their binaries;
320
353
  the CLI owns workspace policy and orchestration.
354
+
355
+ ## Alternatives for opening files
356
+
357
+ `@termwire/mcp` exposes the same open operation as an MCP tool and
358
+ `@termwire/opencode-plugin` as a native OpenCode tool. They exist for agents
359
+ that should not run shell commands. Configure one of the three, not several.
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env bun
1
+ #!/usr/bin/env node
2
2
  export {};
@@ -1,3 +1,3 @@
1
- #!/usr/bin/env bun
2
- import { run } from "../index";
3
- process.exitCode = await run(Bun.argv.slice(2));
1
+ #!/usr/bin/env node
2
+ import { run } from "../index.js";
3
+ process.exitCode = await run(process.argv.slice(2));
package/dist/branch.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import type { GitExec } from "./worktree";
1
+ import type { GitExec } from "./worktree.js";
2
2
  export declare function prepareBranch(exec: GitExec, cwd: string, name: string): Promise<void>;
@@ -1,4 +1,4 @@
1
- import type { LoadedConfig } from "./config-types";
1
+ import type { LoadedConfig } from "./config-types.js";
2
2
  export interface ConfigLoaderDependencies {
3
3
  env: Record<string, string | undefined>;
4
4
  homedir: () => string;
@@ -1,3 +1,3 @@
1
- import { type LayoutConfig } from "./config-schema";
2
- import type { LoadedConfig } from "./config-types";
1
+ import { type LayoutConfig } from "./config-schema.js";
2
+ import type { LoadedConfig } from "./config-types.js";
3
3
  export declare function resolveLayout(globalConfig?: LoadedConfig, projectConfig?: LoadedConfig): LayoutConfig;
@@ -1,4 +1,4 @@
1
- import { configV1Schema, } from "./config-schema";
1
+ import { configV1Schema, } from "./config-schema.js";
2
2
  const defaultLayout = {
3
3
  windows: [
4
4
  { name: "editor", panes: [{ id: "editor", role: "editor" }] },
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- export { prepareBranch } from "./branch";
2
- export type { ProgramDependencies, RuntimeDependencies } from "./program";
3
- export { createProgram, createRuntimeUp, executeGit, removeStaleSocket, run } from "./program";
4
- export type { UpDependencies, UpRequest } from "./up";
5
- export { up } from "./up";
6
- export type { GitExec, WorktreeEntry } from "./worktree";
7
- export { findGitRoot, parseWorktreeList, prepareWorktree } from "./worktree";
1
+ export { prepareBranch } from "./branch.js";
2
+ export type { NvimClient, OpenDependencies, OpenRequest, OpenResult, TmuxClient, } from "./open.js";
3
+ export { open, parseTarget } from "./open.js";
4
+ export type { ProgramDependencies, RuntimeDependencies, RuntimeOpenDependencies, } from "./program.js";
5
+ export { createProgram, createRuntimeOpen, createRuntimeUp, executeGit, removeStaleSocket, run, } from "./program.js";
6
+ export type { UpDependencies, UpRequest } from "./up.js";
7
+ export { up } from "./up.js";
8
+ export type { GitExec, WorktreeEntry } from "./worktree.js";
9
+ export { findGitRoot, parseWorktreeList, prepareWorktree } from "./worktree.js";
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
- export { prepareBranch } from "./branch";
2
- export { createProgram, createRuntimeUp, executeGit, removeStaleSocket, run } from "./program";
3
- export { up } from "./up";
4
- export { findGitRoot, parseWorktreeList, prepareWorktree } from "./worktree";
1
+ export { prepareBranch } from "./branch.js";
2
+ export { open, parseTarget } from "./open.js";
3
+ export { createProgram, createRuntimeOpen, createRuntimeUp, executeGit, removeStaleSocket, run, } from "./program.js";
4
+ export { up } from "./up.js";
5
+ export { findGitRoot, parseWorktreeList, prepareWorktree } from "./worktree.js";
package/dist/layout.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { createTmux } from "@termwire/tmux";
2
- import type { LayoutConfig } from "./config-schema";
2
+ import type { LayoutConfig } from "./config-schema.js";
3
3
  export declare function createLayout(options: {
4
4
  tmux: ReturnType<typeof createTmux>;
5
5
  session: string;
package/dist/open.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ export interface OpenRequest {
2
+ target: string;
3
+ line?: string;
4
+ }
5
+ export interface OpenResult {
6
+ path: string;
7
+ line?: number;
8
+ }
9
+ export interface NvimClient {
10
+ isRunning(socket: string): Promise<boolean>;
11
+ openFile(socket: string, path: string, line?: number): Promise<void>;
12
+ }
13
+ export interface TmuxClient {
14
+ selectWindow(target: string): Promise<void>;
15
+ selectPane(pane: string): Promise<void>;
16
+ }
17
+ export interface OpenDependencies {
18
+ cwd: () => string;
19
+ env: Record<string, string | undefined>;
20
+ nvim: NvimClient;
21
+ tmux: TmuxClient;
22
+ }
23
+ export declare function parseTarget(target: string, line?: string): {
24
+ path: string;
25
+ line?: number;
26
+ };
27
+ export declare function open(request: OpenRequest, dependencies: OpenDependencies): Promise<OpenResult>;
package/dist/open.js ADDED
@@ -0,0 +1,45 @@
1
+ import { resolve } from "node:path";
2
+ const lineSuffix = /^(.+):(\d+)$/;
3
+ function parseLine(value) {
4
+ const trimmed = value.trim();
5
+ if (!/^\d+$/.test(trimmed) || Number(trimmed) < 1) {
6
+ throw new Error("line must be a positive integer");
7
+ }
8
+ return Number(trimmed);
9
+ }
10
+ export function parseTarget(target, line) {
11
+ const trimmed = target.trim();
12
+ if (trimmed === "") {
13
+ throw new Error("path must not be empty");
14
+ }
15
+ if (line !== undefined) {
16
+ return { path: trimmed, line: parseLine(line) };
17
+ }
18
+ const match = lineSuffix.exec(trimmed);
19
+ if (!match) {
20
+ return { path: trimmed };
21
+ }
22
+ const [, path, suffix] = match;
23
+ if (path === undefined || suffix === undefined) {
24
+ return { path: trimmed };
25
+ }
26
+ return { path, line: parseLine(suffix) };
27
+ }
28
+ export async function open(request, dependencies) {
29
+ const parsed = parseTarget(request.target, request.line);
30
+ const socket = dependencies.env.TERMWIRE_SOCKET?.trim();
31
+ const editorPane = dependencies.env.TERMWIRE_EDITOR_PANE?.trim();
32
+ if (!socket) {
33
+ throw new Error("not inside a termwire workspace");
34
+ }
35
+ const path = resolve(dependencies.cwd(), parsed.path);
36
+ if (!(await dependencies.nvim.isRunning(socket))) {
37
+ throw new Error(`nvim is not responding on socket ${socket}`);
38
+ }
39
+ await dependencies.nvim.openFile(socket, path, parsed.line);
40
+ if (editorPane) {
41
+ await dependencies.tmux.selectWindow(editorPane);
42
+ await dependencies.tmux.selectPane(editorPane);
43
+ }
44
+ return { path, ...(parsed.line === undefined ? {} : { line: parsed.line }) };
45
+ }
package/dist/program.d.ts CHANGED
@@ -1,9 +1,12 @@
1
+ import { createNvim } from "@termwire/nvim";
1
2
  import { createTmux } from "@termwire/tmux";
2
3
  import { Command } from "commander";
3
- import { type UpRequest } from "./up";
4
- import { type GitExec } from "./worktree";
4
+ import { type OpenRequest, type OpenResult } from "./open.js";
5
+ import { type UpRequest } from "./up.js";
6
+ import { type GitExec } from "./worktree.js";
5
7
  export interface ProgramDependencies {
6
8
  up: (request: UpRequest) => Promise<void>;
9
+ open: (request: OpenRequest) => Promise<OpenResult>;
7
10
  writeError: (message: string) => void;
8
11
  writeOutput: (message: string) => void;
9
12
  }
@@ -20,8 +23,15 @@ export interface RuntimeDependencies {
20
23
  pathExists: (path: string) => Promise<boolean>;
21
24
  unlink: (path: string) => Promise<void>;
22
25
  }
26
+ export interface RuntimeOpenDependencies {
27
+ createNvim: () => ReturnType<typeof createNvim>;
28
+ createTmux: () => ReturnType<typeof createTmux>;
29
+ cwd: () => string;
30
+ env: Record<string, string | undefined>;
31
+ }
23
32
  export declare const executeGit: GitExec;
24
33
  export declare function removeStaleSocket(path: string, unlink: (path: string) => Promise<void>): Promise<void>;
25
34
  export declare function createRuntimeUp(dependencies?: Partial<RuntimeDependencies>): (request: UpRequest) => Promise<void>;
35
+ export declare function createRuntimeOpen(dependencies?: Partial<RuntimeOpenDependencies>): (request: OpenRequest) => Promise<OpenResult>;
26
36
  export declare function createProgram(dependencies: ProgramDependencies): Command;
27
37
  export declare function run(argv: readonly string[], dependencies?: Partial<ProgramDependencies>): Promise<number>;
package/dist/program.js CHANGED
@@ -1,28 +1,41 @@
1
+ import { spawn } from "node:child_process";
1
2
  import { mkdir as mkdirDirectory, readFile as readFileFromDisk, stat, unlink as unlinkFile, } from "node:fs/promises";
2
3
  import { homedir as getHomeDirectory } from "node:os";
4
+ import { createNvim } from "@termwire/nvim";
3
5
  import { createTmux } from "@termwire/tmux";
4
6
  import { Command, CommanderError } from "commander";
5
- import { prepareBranch } from "./branch";
6
- import { createConfigLoader } from "./config-loader";
7
- import { resolveLayout } from "./config-validation";
8
- import { createLayout } from "./layout";
9
- import { up } from "./up";
10
- import { findGitRoot, prepareWorktree } from "./worktree";
7
+ import { prepareBranch } from "./branch.js";
8
+ import { createConfigLoader } from "./config-loader.js";
9
+ import { resolveLayout } from "./config-validation.js";
10
+ import { createLayout } from "./layout.js";
11
+ import { open } from "./open.js";
12
+ import { up } from "./up.js";
13
+ import { findGitRoot, prepareWorktree } from "./worktree.js";
11
14
  export const executeGit = async (argv, options) => {
12
- const spawn = () => Bun.spawn([...argv], { cwd: options?.cwd, stdout: "pipe", stderr: "pipe" });
13
- let child;
14
- try {
15
- child = spawn();
16
- }
17
- catch (error) {
18
- throw new Error(`git execution failed: ${argv.join(" ")}`, { cause: error });
15
+ const [command, ...args] = argv;
16
+ if (command === undefined) {
17
+ throw new Error("git execution failed: empty command");
19
18
  }
20
- const [stdout, stderr, exitCode] = await Promise.all([
21
- new Response(child.stdout).text(),
22
- new Response(child.stderr).text(),
23
- child.exited,
24
- ]);
25
- return { exitCode, stdout, stderr };
19
+ return await new Promise((resolve, reject) => {
20
+ const child = spawn(command, args, {
21
+ cwd: options?.cwd,
22
+ stdio: ["ignore", "pipe", "pipe"],
23
+ });
24
+ let stdout = "";
25
+ let stderr = "";
26
+ child.stdout.setEncoding("utf8").on("data", (chunk) => {
27
+ stdout += chunk;
28
+ });
29
+ child.stderr.setEncoding("utf8").on("data", (chunk) => {
30
+ stderr += chunk;
31
+ });
32
+ child.once("error", (cause) => {
33
+ reject(new Error(`git execution failed: ${argv.join(" ")}`, { cause }));
34
+ });
35
+ child.once("close", (code) => {
36
+ resolve({ exitCode: code ?? 1, stdout, stderr });
37
+ });
38
+ });
26
39
  };
27
40
  export async function removeStaleSocket(path, unlink) {
28
41
  try {
@@ -74,6 +87,13 @@ export function createRuntimeUp(dependencies = {}) {
74
87
  createLayout,
75
88
  });
76
89
  }
90
+ export function createRuntimeOpen(dependencies = {}) {
91
+ const nvim = (dependencies.createNvim ?? (() => createNvim()))();
92
+ const tmux = (dependencies.createTmux ?? (() => createTmux()))();
93
+ const cwd = dependencies.cwd ?? (() => process.cwd());
94
+ const env = dependencies.env ?? process.env;
95
+ return (request) => open(request, { cwd, env, nvim, tmux });
96
+ }
77
97
  export function createProgram(dependencies) {
78
98
  const program = new Command().name("termwire").configureOutput({
79
99
  writeErr: dependencies.writeError,
@@ -83,6 +103,7 @@ export function createProgram(dependencies) {
83
103
  program.showHelpAfterError();
84
104
  program
85
105
  .command("up <name>")
106
+ .description("create or attach to the workspace tmux session <project>-<name>")
86
107
  .option("-w, --worktree [wt-name]", "create or reuse a Git worktree")
87
108
  .option("-b, --branch <name>", "select the exact Git branch")
88
109
  .addHelpText("after", `
@@ -106,12 +127,32 @@ Branch and worktree selection:
106
127
  ...(options.branch === undefined ? {} : { branch: options.branch }),
107
128
  });
108
129
  });
130
+ program
131
+ .command("open <target>")
132
+ .description("open a file in this workspace's editor and focus it")
133
+ .option("-l, --line <number>", "line to jump to, instead of a path:line suffix")
134
+ .addHelpText("after", `
135
+ Target syntax:
136
+ A trailing :<line> selects the line, so src/app.ts:42 opens line 42.
137
+ With --line, the target is used verbatim, which keeps a literal colon in a name.
138
+ Relative paths resolve from the current directory.
139
+ Requires a shell created by termwire up, which exports TERMWIRE_SOCKET.
140
+ `)
141
+ .action(async (target, options) => {
142
+ const result = await dependencies.open({
143
+ target,
144
+ ...(options.line === undefined ? {} : { line: options.line }),
145
+ });
146
+ const suffix = result.line === undefined ? "" : ` at line ${result.line}`;
147
+ dependencies.writeOutput(`Opened ${result.path}${suffix}\n`);
148
+ });
109
149
  return program;
110
150
  }
111
151
  export async function run(argv, dependencies = {}) {
112
152
  const writeError = dependencies.writeError ?? ((message) => process.stderr.write(message));
113
153
  const program = createProgram({
114
154
  up: dependencies.up ?? createRuntimeUp(),
155
+ open: dependencies.open ?? createRuntimeOpen(),
115
156
  writeError,
116
157
  writeOutput: dependencies.writeOutput ?? ((message) => process.stdout.write(message)),
117
158
  });
package/dist/up.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { createTmux } from "@termwire/tmux";
2
- import type { LayoutConfig } from "./config-schema";
3
- import type { LoadedConfig } from "./config-types";
4
- import type { createLayout } from "./layout";
2
+ import type { LayoutConfig } from "./config-schema.js";
3
+ import type { LoadedConfig } from "./config-types.js";
4
+ import type { createLayout } from "./layout.js";
5
5
  export interface UpRequest {
6
6
  name: string;
7
7
  worktree?: true | string;
package/dist/up.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createIdentity } from "./identity";
1
+ import { createIdentity } from "./identity.js";
2
2
  export async function up(request, dependencies) {
3
3
  if (request.worktree === "") {
4
4
  throw new Error("worktree name must not be empty");
package/dist/worktree.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { realpath as resolveRealpath } from "node:fs/promises";
2
2
  import { dirname, isAbsolute, join, resolve } from "node:path";
3
- import { sanitizeComponent } from "./identity";
3
+ import { sanitizeComponent } from "./identity.js";
4
4
  export async function findGitRoot(exec, cwd) {
5
5
  const result = await exec(["git", "rev-parse", "--show-toplevel"], { cwd });
6
6
  if (result.exitCode === 128 && /not a git repository/i.test(result.stderr)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@termwire/cli",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "license": "MIT",
27
27
  "engines": {
28
- "bun": ">=1.3.14"
28
+ "node": ">=22.12.0"
29
29
  },
30
30
  "repository": {
31
31
  "type": "git",
@@ -37,8 +37,8 @@
37
37
  "url": "https://github.com/max-konin/termwire/issues"
38
38
  },
39
39
  "dependencies": {
40
- "@termwire/nvim": "^0.2.2",
41
- "@termwire/tmux": "^0.2.2",
40
+ "@termwire/nvim": "^0.3.0",
41
+ "@termwire/tmux": "^0.3.0",
42
42
  "commander": "^15.0.0",
43
43
  "jsonc-parser": "^3.3.1",
44
44
  "zod": "^4.0.0"