@termwire/tmux 0.4.1 → 0.6.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 +120 -0
- package/dist/create-tmux.d.ts +2 -0
- package/dist/create-tmux.js +3 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -4
- package/dist/session.d.ts +10 -0
- package/dist/session.js +56 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,125 @@
|
|
|
1
1
|
# @termwire/tmux
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- cfdcc19: `termwire ls` and `termwire down`: the workspaces you have, and a way to put one away.
|
|
8
|
+
|
|
9
|
+
A tool that creates workspaces owes you a way to see them and a way to remove them.
|
|
10
|
+
Until now tearing one down was `tmux kill-session` plus `git worktree remove`, typed
|
|
11
|
+
by hand, and there was nothing at all that answered "what is running where".
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
$ termwire ls
|
|
15
|
+
SESSION A BRANCH DIRECTORY PROCS RSS
|
|
16
|
+
termwire-dev * master ~/projects/termwire 7 1.2G
|
|
17
|
+
termwire-demo demo ~/projects/termwire-demo 4 780M
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
One row per workspace, printed once and then done: `ls` is not a monitor. `A` marks an
|
|
21
|
+
attached session, `BRANCH` is the Git branch of the session directory — a short sha on a
|
|
22
|
+
detached `HEAD`, `-` outside a repository — and `PROCS` and `RSS` count the processes
|
|
23
|
+
still carrying `TERMWIRE_SESSION=<session>`, from the same scan the reap uses, so a
|
|
24
|
+
background agent job is counted as well as a pane. A session whose directory is gone is
|
|
25
|
+
listed and marked `(missing)` rather than crashing the command, and no workspaces prints
|
|
26
|
+
`no termwire workspaces` and exits 0. `--json` prints the same rows for machines, with
|
|
27
|
+
absolute directories.
|
|
28
|
+
|
|
29
|
+
A session counts as a workspace when its tmux session environment carries
|
|
30
|
+
`TERMWIRE_SESSION`, never because its name looks like `<project>-<name>`: you pick the
|
|
31
|
+
name and `up` sets the label, so a session of your own is never listed by its name alone.
|
|
32
|
+
Nothing is read from disk — the list is derived from tmux and Git, so identity stays
|
|
33
|
+
stateless and there is no file to go stale.
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
termwire down dev # kill the workspace session
|
|
37
|
+
termwire down # kill the workspace this shell is in
|
|
38
|
+
termwire down dev -w # and remove the worktree it sits in
|
|
39
|
+
termwire down dev -w --force # even with uncommitted changes
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`down` resolves `[name]` exactly as `up` does, so `up dev` and `down dev` always mean one
|
|
43
|
+
session, and it hunts no processes: the `session-closed` hook already reaps that session.
|
|
44
|
+
|
|
45
|
+
Without a name the target is the workspace the command runs in, read from the inherited
|
|
46
|
+
`TERMWIRE_SESSION` — the same environment-based identity `open` uses. Inside a worktree
|
|
47
|
+
workspace that bare form is the only one that works, because there the Git root is the
|
|
48
|
+
worktree, so `down feat` would look for `<worktree>-feat` and find nothing. Outside a
|
|
49
|
+
workspace a bare `down` fails with `not inside a termwire workspace`.
|
|
50
|
+
|
|
51
|
+
`-w` removes the worktree the session was created in, and refuses the main checkout, the
|
|
52
|
+
directory the command is running in, and a worktree holding uncommitted changes unless
|
|
53
|
+
`--force` is given. A refusal removes nothing at all, the session included. The branch is
|
|
54
|
+
never deleted: a branch outlives its workspace. Ignored files are not uncommitted
|
|
55
|
+
changes, so a worktree carrying only `.env` or `node_modules` counts as clean and is
|
|
56
|
+
removed with them.
|
|
57
|
+
|
|
58
|
+
Tearing down your _own_ workspace with `-w` inverts the order: the worktree is removed
|
|
59
|
+
first and the session killed last, because the kill ends the process that would otherwise
|
|
60
|
+
do the removal — and the command steps out of the worktree before removing it, since a
|
|
61
|
+
spawn from a deleted working directory fails with ENOENT. The refusal to remove the
|
|
62
|
+
directory it runs in does not apply there: the shell standing in it dies with the session
|
|
63
|
+
a moment later.
|
|
64
|
+
|
|
65
|
+
The tmux adapter gained `listSessions` and `showEnvironment` on `createTmux`, and the
|
|
66
|
+
process scan now reports resident memory, so `ProcessEntry` carries `rss` in KiB and one
|
|
67
|
+
walk over the process table answers for every workspace at once.
|
|
68
|
+
|
|
69
|
+
Process scanning also became platform-agnostic above the seam. `process-scan.ts` keeps
|
|
70
|
+
only the `SessionScanner` type and the contract a platform has to honour, while
|
|
71
|
+
`process-scan-darwin.ts` and `process-scan-linux.ts` each take their own dependencies;
|
|
72
|
+
`runtime.ts` picks one. Supporting another platform is a new module plus a branch there,
|
|
73
|
+
and `reap` and `ls` do not change, because they depend on the type.
|
|
74
|
+
|
|
75
|
+
Moving the scanner reshapes `CliRuntime`: it gained `createScanner`, a lazy factory so an
|
|
76
|
+
unsupported platform fails the commands that scan instead of every command, and lost
|
|
77
|
+
`exec`, `host.platform`, `host.uid` and `fs.readdir`, which existed only to feed it. It also
|
|
78
|
+
gained `host.chdir`, and `ProgramDependencies` gained `ls`, `down` and `homedir` — so
|
|
79
|
+
anything that builds a runtime or the command set by hand has to follow.
|
|
80
|
+
|
|
81
|
+
## 0.5.0
|
|
82
|
+
|
|
83
|
+
### Minor Changes
|
|
84
|
+
|
|
85
|
+
- 29af197: Package entries export their API instead of every internal, and `run` takes a runtime.
|
|
86
|
+
|
|
87
|
+
Each `index.ts` had grown by reflex: a new module meant a new re-export. Counted against
|
|
88
|
+
real imports, `@termwire/cli` exported 48 names of which exactly one was used, and
|
|
89
|
+
`@termwire/mcp` exported twelve that nothing imported at all. The barrel was a promise
|
|
90
|
+
nobody asked for, and it made every rename a breaking change.
|
|
91
|
+
|
|
92
|
+
**`@termwire/cli` has one breaking change beyond the exports.** `run(argv)` is now
|
|
93
|
+
`run(argv, runtime)`, and the runtime is required — the CLI no longer builds real
|
|
94
|
+
filesystem and process bindings behind the caller's back. A caller does what
|
|
95
|
+
`bin/termwire.ts` does:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { createNodeRuntime, run } from "@termwire/cli";
|
|
99
|
+
|
|
100
|
+
process.exitCode = await run(process.argv.slice(2), createNodeRuntime());
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Calling `run(argv)` with nothing else now throws `run needs a runtime: pass
|
|
104
|
+
createNodeRuntime()`. The `termwire` binary itself is unaffected.
|
|
105
|
+
|
|
106
|
+
The entries now carry the factories, the types naming their arguments and results, and
|
|
107
|
+
the error classes a caller catches:
|
|
108
|
+
|
|
109
|
+
- `@termwire/cli`: `run`, `createNodeRuntime`, `createAdapters`, and the `CliRuntime`,
|
|
110
|
+
`RuntimeHost`, `RuntimeFileSystem`, `ProgramDependencies`, `Exec`, `ExecOptions`,
|
|
111
|
+
`ExecResult`, `GitExec`, `ReapSignal` and `KillOutcome` types.
|
|
112
|
+
- `@termwire/tmux` and `@termwire/nvim`: `createTmux` / `createNvim`, their option and
|
|
113
|
+
result types, and `CommandError` / `ValidationError`.
|
|
114
|
+
- `@termwire/mcp`: `createTermwireMcpServer`, `createOpenFileHandler`, and the types those
|
|
115
|
+
two name.
|
|
116
|
+
|
|
117
|
+
What is gone is the per-command functions the factories already expose as methods
|
|
118
|
+
(`killSession`, `respawnPane`, `setEnvironment`, `setHook`, `showHooks`, `unsetHook`,
|
|
119
|
+
`selectLayout`, `openFile`), plus three things that were never methods: `parseHooks`, the
|
|
120
|
+
`tmuxLayouts` constant, and the MCP tool's Zod schemas. Those move to `@termwire/tmux`
|
|
121
|
+
and `@termwire/mcp` internals; if you depended on one, open an issue and say what for.
|
|
122
|
+
|
|
3
123
|
## 0.4.1
|
|
4
124
|
|
|
5
125
|
## 0.4.0
|
package/dist/create-tmux.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface CreateTmuxOptions {
|
|
|
9
9
|
}
|
|
10
10
|
export declare function createTmux({ exec, env }?: CreateTmuxOptions): {
|
|
11
11
|
hasSession: (session: string) => Promise<boolean>;
|
|
12
|
+
listSessions: () => Promise<import("./session.js").SessionSummary[]>;
|
|
13
|
+
showEnvironment: (session: string) => Promise<Record<string, string>>;
|
|
12
14
|
newSession: (options: Parameters<typeof newSession>[1]) => Promise<import("./command.js").WindowPaneIds>;
|
|
13
15
|
newWindow: (options: Parameters<typeof newWindow>[1]) => Promise<import("./command.js").WindowPaneIds>;
|
|
14
16
|
setEnvironment: (session: string, key: string, value: string) => Promise<void>;
|
package/dist/create-tmux.js
CHANGED
|
@@ -2,11 +2,13 @@ import { attach } from "./client.js";
|
|
|
2
2
|
import { setHook, showHooks, unsetHook } from "./hook.js";
|
|
3
3
|
import { respawnPane, selectPane, sendKeys, splitPane } from "./pane.js";
|
|
4
4
|
import { spawnExec } from "./process.js";
|
|
5
|
-
import { hasSession, killSession, newSession, setEnvironment, setSessionTitle } from "./session.js";
|
|
5
|
+
import { hasSession, killSession, listSessions, newSession, setEnvironment, setSessionTitle, showEnvironment, } from "./session.js";
|
|
6
6
|
import { newWindow, selectLayout, selectWindow } from "./window.js";
|
|
7
7
|
export function createTmux({ exec = spawnExec, env = process.env } = {}) {
|
|
8
8
|
return {
|
|
9
9
|
hasSession: (session) => hasSession(exec, session),
|
|
10
|
+
listSessions: () => listSessions(exec),
|
|
11
|
+
showEnvironment: (session) => showEnvironment(exec, session),
|
|
10
12
|
newSession: (options) => newSession(exec, options),
|
|
11
13
|
newWindow: (options) => newWindow(exec, options),
|
|
12
14
|
setEnvironment: (session, key, value) => setEnvironment(exec, session, key, value),
|
package/dist/index.d.ts
CHANGED
|
@@ -2,13 +2,9 @@ export type { WindowPaneIds } from "./command.js";
|
|
|
2
2
|
export type { CreateTmuxOptions } from "./create-tmux.js";
|
|
3
3
|
export { createTmux } from "./create-tmux.js";
|
|
4
4
|
export type { HookEntry, SetHookOptions, ShowHooksOptions, UnsetHookOptions } from "./hook.js";
|
|
5
|
-
export { parseHooks, setHook, showHooks, unsetHook } from "./hook.js";
|
|
6
5
|
export type { RespawnPaneOptions, SplitPaneOptions } from "./pane.js";
|
|
7
|
-
export { respawnPane } from "./pane.js";
|
|
8
6
|
export type { Exec, ExecOptions, ExecResult } from "./process.js";
|
|
9
7
|
export { CommandError } from "./process.js";
|
|
10
8
|
export type { NewSessionOptions } from "./session.js";
|
|
11
|
-
export { killSession, setEnvironment } from "./session.js";
|
|
12
9
|
export { ValidationError } from "./validation.js";
|
|
13
10
|
export type { NewWindowOptions, TmuxLayout } from "./window.js";
|
|
14
|
-
export { selectLayout, tmuxLayouts } from "./window.js";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
export { createTmux } from "./create-tmux.js";
|
|
2
|
-
export { parseHooks, setHook, showHooks, unsetHook } from "./hook.js";
|
|
3
|
-
export { respawnPane } from "./pane.js";
|
|
4
2
|
export { CommandError } from "./process.js";
|
|
5
|
-
export { killSession, setEnvironment } from "./session.js";
|
|
6
3
|
export { ValidationError } from "./validation.js";
|
|
7
|
-
export { selectLayout, tmuxLayouts } from "./window.js";
|
package/dist/session.d.ts
CHANGED
|
@@ -12,3 +12,13 @@ export declare function setEnvironment(exec: Exec, session: string, key: string,
|
|
|
12
12
|
export declare function setSessionTitle(exec: Exec, session: string): Promise<void>;
|
|
13
13
|
export declare function killSession(exec: Exec, session: string): Promise<void>;
|
|
14
14
|
export declare function newSession(exec: Exec, options: NewSessionOptions): Promise<WindowPaneIds>;
|
|
15
|
+
export interface SessionSummary {
|
|
16
|
+
name: string;
|
|
17
|
+
attached: boolean;
|
|
18
|
+
path: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function parseSessionList(stdout: string): SessionSummary[];
|
|
21
|
+
export declare function listSessions(exec: Exec): Promise<SessionSummary[]>;
|
|
22
|
+
/** `show-environment` prints `NAME=value` per line, and `-NAME` for a removed one. */
|
|
23
|
+
export declare function parseEnvironment(stdout: string): Record<string, string>;
|
|
24
|
+
export declare function showEnvironment(exec: Exec, session: string): Promise<Record<string, string>>;
|
package/dist/session.js
CHANGED
|
@@ -87,3 +87,59 @@ export async function newSession(exec, options) {
|
|
|
87
87
|
throw error;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
+
/** The session path comes last, so a tab inside it cannot shift the other fields. */
|
|
91
|
+
const sessionFormat = "#{session_name}\t#{session_attached}\t#{session_path}";
|
|
92
|
+
export function parseSessionList(stdout) {
|
|
93
|
+
const sessions = [];
|
|
94
|
+
for (const line of stdout.split("\n")) {
|
|
95
|
+
const fields = line.split("\t");
|
|
96
|
+
// Three fields or it is not a session row; the path keeps any tab of its own.
|
|
97
|
+
if (fields.length < 3)
|
|
98
|
+
continue;
|
|
99
|
+
const [name, attached, ...path] = fields;
|
|
100
|
+
if (name.length === 0)
|
|
101
|
+
continue;
|
|
102
|
+
sessions.push({ name, attached: Number(attached) > 0, path: path.join("\t") });
|
|
103
|
+
}
|
|
104
|
+
return sessions;
|
|
105
|
+
}
|
|
106
|
+
export async function listSessions(exec) {
|
|
107
|
+
const command = ["tmux", "list-sessions", "-F", sessionFormat];
|
|
108
|
+
const execution = await execute(exec, command);
|
|
109
|
+
// No server is no sessions, not a failure. The message differs by version — "no
|
|
110
|
+
// server running on <socket>" on older tmux, "error connecting to <socket> (No such
|
|
111
|
+
// file or directory)" on 3.6 — so the exit code decides. The cost is that an
|
|
112
|
+
// unreadable socket exits 1 the same way and reads as an empty list.
|
|
113
|
+
if (execution.exitCode === 1)
|
|
114
|
+
return [];
|
|
115
|
+
if (execution.exitCode !== 0) {
|
|
116
|
+
throw CommandError.from(command, execution);
|
|
117
|
+
}
|
|
118
|
+
return parseSessionList(execution.stdout);
|
|
119
|
+
}
|
|
120
|
+
/** `show-environment` prints `NAME=value` per line, and `-NAME` for a removed one. */
|
|
121
|
+
export function parseEnvironment(stdout) {
|
|
122
|
+
const environment = {};
|
|
123
|
+
for (const line of stdout.split("\n")) {
|
|
124
|
+
if (line.startsWith("-"))
|
|
125
|
+
continue;
|
|
126
|
+
const separator = line.indexOf("=");
|
|
127
|
+
if (separator <= 0)
|
|
128
|
+
continue;
|
|
129
|
+
environment[line.slice(0, separator)] = line.slice(separator + 1);
|
|
130
|
+
}
|
|
131
|
+
return environment;
|
|
132
|
+
}
|
|
133
|
+
export async function showEnvironment(exec, session) {
|
|
134
|
+
assertNotEmpty("session", session);
|
|
135
|
+
const command = ["tmux", "show-environment", "-t", `=${session}`];
|
|
136
|
+
const execution = await execute(exec, command);
|
|
137
|
+
// Exit 1 is "no such session": it closed between being listed and being read, and a
|
|
138
|
+
// session that no longer exists has no environment rather than an error.
|
|
139
|
+
if (execution.exitCode === 1)
|
|
140
|
+
return {};
|
|
141
|
+
if (execution.exitCode !== 0) {
|
|
142
|
+
throw CommandError.from(command, execution);
|
|
143
|
+
}
|
|
144
|
+
return parseEnvironment(execution.stdout);
|
|
145
|
+
}
|