@termwire/tmux 0.2.2 → 0.4.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,64 @@
1
1
  # @termwire/tmux
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 7e73a29: Closing a workspace session now kills the processes started in it.
8
+
9
+ `tmux kill-session` only sends `SIGHUP` to the foreground process group of each
10
+ pane, so background agent jobs detached from the terminal survived it and were
11
+ adopted by `init`. They accumulated for weeks, in one case 158 processes across
12
+ nine abandoned sessions, five of whose worktrees no longer existed on disk.
13
+
14
+ `up` now installs one global tmux `session-closed` hook that runs a hidden
15
+ `termwire _reap <session>` subcommand. The reap collects the processes of the
16
+ current user whose environment still carries `TERMWIRE_SESSION=<session>`, sends
17
+ `SIGTERM`, then confirms the survivors still carry the label before escalating
18
+ them to `SIGKILL`. It signals exactly that list of pids and never a pattern
19
+ match, and never the tmux server or anything it descends from. Each run appends
20
+ one line to `$XDG_STATE_HOME/termwire/reap.log`, because a tmux hook's output is
21
+ shown nowhere.
22
+
23
+ Installing the hook is idempotent. A repeated `up` updates our entry when the
24
+ interpreter or script path changed, drops duplicates of ours, and leaves a
25
+ `session-closed` hook of your own untouched. A tmux server that refuses the hook
26
+ only produces a warning; the workspace still comes up.
27
+
28
+ `@termwire/tmux` gains `showHooks`, `setHook`, and `unsetHook`. It keeps no
29
+ knowledge of what the hooks are for.
30
+
31
+ ## 0.3.0
32
+
33
+ ### Minor Changes
34
+
35
+ - f57c480: Run on Node instead of requiring Bun. Every package now spawns through
36
+ `node:child_process`, emits explicit `.js` extensions on relative imports, and
37
+ ships a `#!/usr/bin/env node` entry point. `engines` declares `node >=22.12.0`,
38
+ the floor set by Commander 15.
39
+
40
+ The published CLI and MCP server previously failed under Node with
41
+ `ERR_MODULE_NOT_FOUND` and had no test covering it. `bun run verify:node`
42
+ executes both built artifacts under Node, and CI runs it on every push.
43
+
44
+ This makes `npx -y @termwire/mcp` the recommended MCP registration. Unlike
45
+ `bunx`, the `npx` cache lives under `~/.npm` and is not swept by the nightly
46
+ macOS temporary-directory cleanup that silently broke the server.
47
+
48
+ Emitted type declarations are now typed against `@types/node` alone and no
49
+ longer reference Bun types.
50
+
51
+ The repository is still developed with Bun. Only the published output changed.
52
+
53
+ - f57c480: Add the `termwire open <target>` command, which opens a file in the workspace
54
+ Neovim and focuses the editor pane. A trailing `:<line>` selects a line, and
55
+ `--line` keeps the target verbatim for filenames that end in a colon and
56
+ digits. This gives any agent that can run a shell command the same capability
57
+ as the MCP server and the OpenCode plugin, with nothing to configure.
58
+
59
+ Correct the OpenCode plugin's out-of-workspace error to `not inside a termwire
60
+ workspace`, matching the CLI and the MCP server.
61
+
3
62
  ## 0.2.2
4
63
 
5
64
  ### Patch Changes
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @termwire/tmux
2
2
 
3
+ A thin, typed adapter for tmux 3.2 or newer.
4
+
3
5
  ```bash
4
6
  bun add @termwire/tmux
5
7
  ```
@@ -8,18 +10,37 @@ bun add @termwire/tmux
8
10
  import { createTmux } from "@termwire/tmux";
9
11
 
10
12
  const tmux = createTmux();
13
+
14
+ if (!(await tmux.hasSession("repo-dev"))) {
15
+ await tmux.newSession({ session: "repo-dev", name: "editor", cwd: "/repo" });
16
+ }
11
17
  ```
12
18
 
13
- A thin, typed adapter for tmux 3.2. Create it with `createTmux({ exec, env })`; production uses
14
- `Bun.spawn`, while tests can inject a fake `exec` without requiring a tmux binary.
19
+ `createTmux({ exec, env })` spawns through `node:child_process` in production,
20
+ so it runs on Node and on Bun alike. Tests inject a fake `exec` and need no
21
+ tmux binary.
15
22
 
16
23
  ## API
17
24
 
18
- The factory exposes `hasSession`, `newSession`, `newWindow`, `splitPane`, `sendKeys`,
19
- `selectWindow`, `selectPane`, and `attach`. Attach uses `attach-session` outside tmux and
20
- `switch-client` when `TMUX` is set.
25
+ - Sessions: `hasSession`, `newSession`, `killSession`, `setSessionTitle`,
26
+ `setEnvironment`, `attach`.
27
+ - Windows: `newWindow`, `selectWindow`, `selectLayout`.
28
+ - Panes: `splitPane`, `respawnPane`, `selectPane`, `sendKeys`.
29
+ - Hooks: `showHooks`, `setHook`, `unsetHook`.
30
+
31
+ `attach` uses `attach-session` outside tmux and `switch-client` when `TMUX` is
32
+ set, so attaching works the same from a plain terminal and from inside another
33
+ session.
34
+
35
+ `newSession` and `newWindow` return the created window and pane ids. Termwire
36
+ uses those ids to place panes and to record the editor pane in
37
+ `TERMWIRE_EDITOR_PANE`.
38
+
39
+ `showHooks` returns the parsed entries, including the array index tmux stores
40
+ each hook under, which is what a caller needs to replace or remove one in place.
41
+ Deciding which hook belongs to whom is not this package's business.
21
42
 
22
43
  ## Boundary
23
44
 
24
- This package owns tmux commands only. The CLI owns runtime layout interpretation and editor roles;
25
- no OpenCode, workspace orchestration, or Neovim logic belongs here.
45
+ This package owns tmux commands only. Layout interpretation, editor roles,
46
+ Neovim, and workspace orchestration belong to the CLI.
package/dist/client.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { type Exec } from "./process";
1
+ import { type Exec } from "./process.js";
2
2
  export declare function attach(exec: Exec, env: Record<string, string | undefined>, session: string): Promise<void>;
package/dist/client.js CHANGED
@@ -1,5 +1,5 @@
1
- import { CommandError, execute } from "./process";
2
- import { assertNotEmpty } from "./validation";
1
+ import { CommandError, execute } from "./process.js";
2
+ import { assertNotEmpty } from "./validation.js";
3
3
  export async function attach(exec, env, session) {
4
4
  assertNotEmpty("session", session);
5
5
  const internal = env.TMUX !== undefined && env.TMUX.length > 0;
package/dist/command.js CHANGED
@@ -1,4 +1,4 @@
1
- import { assertNotEmpty, ValidationError } from "./validation";
1
+ import { assertNotEmpty, ValidationError } from "./validation.js";
2
2
  export function appendEnvironment(argv, environment) {
3
3
  if (!environment)
4
4
  return;
@@ -1,15 +1,16 @@
1
- import { respawnPane, sendKeys, splitPane } from "./pane";
2
- import { type Exec } from "./process";
3
- import { newSession } from "./session";
4
- import { newWindow, selectLayout } from "./window";
1
+ import { setHook, showHooks, unsetHook } from "./hook.js";
2
+ import { respawnPane, sendKeys, splitPane } from "./pane.js";
3
+ import { type Exec } from "./process.js";
4
+ import { newSession } from "./session.js";
5
+ import { newWindow, selectLayout } from "./window.js";
5
6
  export interface CreateTmuxOptions {
6
7
  exec?: Exec;
7
8
  env?: Record<string, string | undefined>;
8
9
  }
9
10
  export declare function createTmux({ exec, env }?: CreateTmuxOptions): {
10
11
  hasSession: (session: string) => Promise<boolean>;
11
- newSession: (options: Parameters<typeof newSession>[1]) => Promise<import("./command").WindowPaneIds>;
12
- newWindow: (options: Parameters<typeof newWindow>[1]) => Promise<import("./command").WindowPaneIds>;
12
+ newSession: (options: Parameters<typeof newSession>[1]) => Promise<import("./command.js").WindowPaneIds>;
13
+ newWindow: (options: Parameters<typeof newWindow>[1]) => Promise<import("./command.js").WindowPaneIds>;
13
14
  setEnvironment: (session: string, key: string, value: string) => Promise<void>;
14
15
  setSessionTitle: (session: string) => Promise<void>;
15
16
  killSession: (session: string) => Promise<void>;
@@ -20,4 +21,7 @@ export declare function createTmux({ exec, env }?: CreateTmuxOptions): {
20
21
  selectLayout: (target: string, layout: Parameters<typeof selectLayout>[2]) => Promise<void>;
21
22
  selectPane: (target: string) => Promise<void>;
22
23
  attach: (session: string) => Promise<void>;
24
+ showHooks: (options?: Parameters<typeof showHooks>[1]) => Promise<import("./hook.js").HookEntry[]>;
25
+ setHook: (options: Parameters<typeof setHook>[1]) => Promise<void>;
26
+ unsetHook: (options: Parameters<typeof unsetHook>[1]) => Promise<void>;
23
27
  };
@@ -1,9 +1,10 @@
1
- import { attach } from "./client";
2
- import { respawnPane, selectPane, sendKeys, splitPane } from "./pane";
3
- import { bunExec } from "./process";
4
- import { hasSession, killSession, newSession, setEnvironment, setSessionTitle } from "./session";
5
- import { newWindow, selectLayout, selectWindow } from "./window";
6
- export function createTmux({ exec = bunExec, env = process.env } = {}) {
1
+ import { attach } from "./client.js";
2
+ import { setHook, showHooks, unsetHook } from "./hook.js";
3
+ import { respawnPane, selectPane, sendKeys, splitPane } from "./pane.js";
4
+ import { spawnExec } from "./process.js";
5
+ import { hasSession, killSession, newSession, setEnvironment, setSessionTitle } from "./session.js";
6
+ import { newWindow, selectLayout, selectWindow } from "./window.js";
7
+ export function createTmux({ exec = spawnExec, env = process.env } = {}) {
7
8
  return {
8
9
  hasSession: (session) => hasSession(exec, session),
9
10
  newSession: (options) => newSession(exec, options),
@@ -18,5 +19,8 @@ export function createTmux({ exec = bunExec, env = process.env } = {}) {
18
19
  selectLayout: (target, layout) => selectLayout(exec, target, layout),
19
20
  selectPane: (target) => selectPane(exec, target),
20
21
  attach: (session) => attach(exec, env, session),
22
+ showHooks: (options) => showHooks(exec, options),
23
+ setHook: (options) => setHook(exec, options),
24
+ unsetHook: (options) => unsetHook(exec, options),
21
25
  };
22
26
  }
package/dist/hook.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { type Exec } from "./process.js";
2
+ export interface HookEntry {
3
+ name: string;
4
+ index?: number;
5
+ command: string;
6
+ }
7
+ export interface ShowHooksOptions {
8
+ global?: boolean;
9
+ }
10
+ export interface SetHookOptions {
11
+ name: string;
12
+ command: string;
13
+ global?: boolean;
14
+ append?: boolean;
15
+ }
16
+ export interface UnsetHookOptions {
17
+ name: string;
18
+ global?: boolean;
19
+ }
20
+ export declare function parseHooks(stdout: string): HookEntry[];
21
+ export declare function showHooks(exec: Exec, options?: ShowHooksOptions): Promise<HookEntry[]>;
22
+ export declare function setHook(exec: Exec, options: SetHookOptions): Promise<void>;
23
+ export declare function unsetHook(exec: Exec, options: UnsetHookOptions): Promise<void>;
package/dist/hook.js ADDED
@@ -0,0 +1,58 @@
1
+ import { CommandError, execute } from "./process.js";
2
+ import { assertNotEmpty } from "./validation.js";
3
+ export function parseHooks(stdout) {
4
+ const entries = [];
5
+ for (const line of stdout.split("\n")) {
6
+ const trimmed = line.trim();
7
+ if (trimmed.length === 0)
8
+ continue;
9
+ const separator = trimmed.indexOf(" ");
10
+ const key = separator === -1 ? trimmed : trimmed.slice(0, separator);
11
+ const command = separator === -1 ? "" : trimmed.slice(separator + 1);
12
+ const parsed = /^([A-Za-z0-9_-]+)(?:\[(\d+)\])?$/.exec(key);
13
+ if (!parsed)
14
+ continue;
15
+ const index = parsed[2];
16
+ entries.push({
17
+ name: parsed[1],
18
+ ...(index === undefined ? {} : { index: Number(index) }),
19
+ command,
20
+ });
21
+ }
22
+ return entries;
23
+ }
24
+ export async function showHooks(exec, options = {}) {
25
+ const command = ["tmux", "show-hooks", ...(options.global ? ["-g"] : [])];
26
+ const execution = await execute(exec, command);
27
+ if (execution.exitCode !== 0) {
28
+ throw CommandError.from(command, execution);
29
+ }
30
+ return parseHooks(execution.stdout);
31
+ }
32
+ export async function setHook(exec, options) {
33
+ assertNotEmpty("name", options.name);
34
+ assertNotEmpty("command", options.command);
35
+ const command = [
36
+ "tmux",
37
+ "set-hook",
38
+ ...hookFlags(options.global, options.append),
39
+ options.name,
40
+ options.command,
41
+ ];
42
+ const execution = await execute(exec, command);
43
+ if (execution.exitCode !== 0) {
44
+ throw CommandError.from(command, execution);
45
+ }
46
+ }
47
+ export async function unsetHook(exec, options) {
48
+ assertNotEmpty("name", options.name);
49
+ const command = ["tmux", "set-hook", options.global ? "-gu" : "-u", options.name];
50
+ const execution = await execute(exec, command);
51
+ if (execution.exitCode !== 0) {
52
+ throw CommandError.from(command, execution);
53
+ }
54
+ }
55
+ function hookFlags(global, append) {
56
+ const flags = `${global ? "g" : ""}${append ? "a" : ""}`;
57
+ return flags.length === 0 ? [] : [`-${flags}`];
58
+ }
package/dist/index.d.ts CHANGED
@@ -1,12 +1,14 @@
1
- export type { WindowPaneIds } from "./command";
2
- export type { CreateTmuxOptions } from "./create-tmux";
3
- export { createTmux } from "./create-tmux";
4
- export type { RespawnPaneOptions, SplitPaneOptions } from "./pane";
5
- export { respawnPane } from "./pane";
6
- export type { Exec, ExecOptions, ExecResult } from "./process";
7
- export { CommandError } from "./process";
8
- export type { NewSessionOptions } from "./session";
9
- export { killSession, setEnvironment } from "./session";
10
- export { ValidationError } from "./validation";
11
- export type { NewWindowOptions, TmuxLayout } from "./window";
12
- export { selectLayout, tmuxLayouts } from "./window";
1
+ export type { WindowPaneIds } from "./command.js";
2
+ export type { CreateTmuxOptions } from "./create-tmux.js";
3
+ export { createTmux } from "./create-tmux.js";
4
+ export type { HookEntry, SetHookOptions, ShowHooksOptions, UnsetHookOptions } from "./hook.js";
5
+ export { parseHooks, setHook, showHooks, unsetHook } from "./hook.js";
6
+ export type { RespawnPaneOptions, SplitPaneOptions } from "./pane.js";
7
+ export { respawnPane } from "./pane.js";
8
+ export type { Exec, ExecOptions, ExecResult } from "./process.js";
9
+ export { CommandError } from "./process.js";
10
+ export type { NewSessionOptions } from "./session.js";
11
+ export { killSession, setEnvironment } from "./session.js";
12
+ export { ValidationError } from "./validation.js";
13
+ export type { NewWindowOptions, TmuxLayout } from "./window.js";
14
+ export { selectLayout, tmuxLayouts } from "./window.js";
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
- export { createTmux } from "./create-tmux";
2
- export { respawnPane } from "./pane";
3
- export { CommandError } from "./process";
4
- export { killSession, setEnvironment } from "./session";
5
- export { ValidationError } from "./validation";
6
- export { selectLayout, tmuxLayouts } from "./window";
1
+ export { createTmux } from "./create-tmux.js";
2
+ export { parseHooks, setHook, showHooks, unsetHook } from "./hook.js";
3
+ export { respawnPane } from "./pane.js";
4
+ export { CommandError } from "./process.js";
5
+ export { killSession, setEnvironment } from "./session.js";
6
+ export { ValidationError } from "./validation.js";
7
+ export { selectLayout, tmuxLayouts } from "./window.js";
package/dist/pane.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type Exec } from "./process";
1
+ import { type Exec } from "./process.js";
2
2
  export interface SplitPaneOptions {
3
3
  target: string;
4
4
  direction: "horizontal" | "vertical";
package/dist/pane.js CHANGED
@@ -1,6 +1,6 @@
1
- import { appendCommand, appendEnvironment, readPaneId } from "./command";
2
- import { CommandError, execute } from "./process";
3
- import { assertNotEmpty, ValidationError } from "./validation";
1
+ import { appendCommand, appendEnvironment, readPaneId } from "./command.js";
2
+ import { CommandError, execute } from "./process.js";
3
+ import { assertNotEmpty, ValidationError } from "./validation.js";
4
4
  export async function respawnPane(exec, options) {
5
5
  assertNotEmpty("target", options.target);
6
6
  if (options.cwd !== undefined)
package/dist/process.d.ts CHANGED
@@ -15,4 +15,4 @@ export declare class CommandError extends Error {
15
15
  static from(argv: readonly string[], result: ExecResult): CommandError;
16
16
  }
17
17
  export declare function execute(exec: Exec, argv: readonly string[], options?: ExecOptions): Promise<ExecResult>;
18
- export declare function bunExec(argv: readonly string[], options?: ExecOptions): Promise<ExecResult>;
18
+ export declare function spawnExec(argv: readonly string[], options?: ExecOptions): Promise<ExecResult>;
package/dist/process.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { spawn } from "node:child_process";
1
2
  export class CommandError extends Error {
2
3
  argv;
3
4
  exitCode;
@@ -23,18 +24,27 @@ export async function execute(exec, argv, options) {
23
24
  throw new CommandError(argv, null, "", { cause });
24
25
  }
25
26
  }
26
- export async function bunExec(argv, options) {
27
- const inherited = options?.stdio === "inherit";
28
- const proc = Bun.spawn([...argv], inherited
29
- ? { stdin: "inherit", stdout: "inherit", stderr: "inherit" }
30
- : { stdout: "pipe", stderr: "pipe" });
31
- const exitCode = await proc.exited;
32
- if (inherited) {
33
- return { exitCode, stdout: "", stderr: "" };
27
+ export async function spawnExec(argv, options = {}) {
28
+ const [command, ...args] = argv;
29
+ if (command === undefined) {
30
+ throw new Error("command must not be empty");
34
31
  }
35
- const [stdout, stderr] = await Promise.all([
36
- new Response(proc.stdout).text(),
37
- new Response(proc.stderr).text(),
38
- ]);
39
- return { exitCode, stdout, stderr };
32
+ const inherited = options.stdio === "inherit";
33
+ return await new Promise((resolve, reject) => {
34
+ const child = spawn(command, args, {
35
+ stdio: inherited ? "inherit" : ["ignore", "pipe", "pipe"],
36
+ });
37
+ let stdout = "";
38
+ let stderr = "";
39
+ child.stdout?.setEncoding("utf8").on("data", (chunk) => {
40
+ stdout += chunk;
41
+ });
42
+ child.stderr?.setEncoding("utf8").on("data", (chunk) => {
43
+ stderr += chunk;
44
+ });
45
+ child.once("error", reject);
46
+ child.once("close", (code) => {
47
+ resolve({ exitCode: code ?? 1, stdout, stderr });
48
+ });
49
+ });
40
50
  }
package/dist/session.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { type WindowPaneIds } from "./command";
2
- import { type Exec } from "./process";
1
+ import { type WindowPaneIds } from "./command.js";
2
+ import { type Exec } from "./process.js";
3
3
  export interface NewSessionOptions {
4
4
  session: string;
5
5
  name?: string;
package/dist/session.js CHANGED
@@ -1,6 +1,6 @@
1
- import { appendCommand, appendEnvironment, readWindowPaneIds } from "./command";
2
- import { CommandError, execute } from "./process";
3
- import { assertNotEmpty } from "./validation";
1
+ import { appendCommand, appendEnvironment, readWindowPaneIds, } from "./command.js";
2
+ import { CommandError, execute } from "./process.js";
3
+ import { assertNotEmpty } from "./validation.js";
4
4
  export async function hasSession(exec, session) {
5
5
  assertNotEmpty("session", session);
6
6
  const command = ["tmux", "has-session", "-t", `=${session}`];
package/dist/window.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { type WindowPaneIds } from "./command";
2
- import { type Exec } from "./process";
1
+ import { type WindowPaneIds } from "./command.js";
2
+ import { type Exec } from "./process.js";
3
3
  export interface NewWindowOptions {
4
4
  target: string;
5
5
  name?: string;
package/dist/window.js CHANGED
@@ -1,6 +1,6 @@
1
- import { appendCommand, appendEnvironment, readWindowPaneIds } from "./command";
2
- import { CommandError, execute } from "./process";
3
- import { assertNotEmpty } from "./validation";
1
+ import { appendCommand, appendEnvironment, readWindowPaneIds, } from "./command.js";
2
+ import { CommandError, execute } from "./process.js";
3
+ import { assertNotEmpty } from "./validation.js";
4
4
  export const tmuxLayouts = [
5
5
  "even-horizontal",
6
6
  "even-vertical",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@termwire/tmux",
3
- "version": "0.2.2",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "license": "MIT",
24
24
  "engines": {
25
- "bun": ">=1.3.14"
25
+ "node": ">=22.12.0"
26
26
  },
27
27
  "repository": {
28
28
  "type": "git",