@termwire/cli 0.6.0 → 0.7.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 +12 -0
- package/README.md +59 -4
- package/dist/click.d.ts +52 -0
- package/dist/click.js +138 -0
- package/dist/config-schema.d.ts +7 -0
- package/dist/config-schema.js +19 -0
- package/dist/config-validation.d.ts +2 -0
- package/dist/config-validation.js +14 -0
- package/dist/config-writer.d.ts +4 -2
- package/dist/config-writer.js +15 -3
- package/dist/identity.js +4 -1
- package/dist/install-prompt.js +7 -0
- package/dist/install.d.ts +6 -0
- package/dist/install.js +101 -25
- package/dist/mouse-binding.d.ts +60 -0
- package/dist/mouse-binding.js +91 -0
- package/dist/mouse-config.d.ts +17 -0
- package/dist/mouse-config.js +63 -0
- package/dist/program.d.ts +5 -0
- package/dist/program.js +98 -28
- package/dist/reap-hook.js +1 -19
- package/dist/reap.d.ts +0 -5
- package/dist/reap.js +3 -10
- package/dist/runtime.d.ts +5 -0
- package/dist/runtime.js +22 -1
- package/dist/shell-quote.d.ts +6 -0
- package/dist/shell-quote.js +19 -0
- package/dist/state-log.d.ts +8 -0
- package/dist/state-log.js +12 -0
- package/dist/up.d.ts +5 -2
- package/dist/up.js +5 -5
- package/dist/worktree.d.ts +1 -1
- package/dist/worktree.js +1 -2
- package/package.json +21 -7
package/dist/reap-hook.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { shellQuote } from "./shell-quote.js";
|
|
2
2
|
export const reapHookName = "session-closed";
|
|
3
3
|
/**
|
|
4
4
|
* Identifies our entry among the user's own `session-closed` hooks, and doubles as
|
|
@@ -56,21 +56,3 @@ export async function ensureReapHook(options) {
|
|
|
56
56
|
function hookTarget(entry) {
|
|
57
57
|
return entry.index === undefined ? entry.name : `${entry.name}[${entry.index}]`;
|
|
58
58
|
}
|
|
59
|
-
/**
|
|
60
|
-
* The path is read by two parsers: tmux, which expands `#{...}` and backslash
|
|
61
|
-
* escapes inside double quotes, and then `sh`. Quoting characters would have to
|
|
62
|
-
* survive both, so they are rejected instead of escaped twice.
|
|
63
|
-
*/
|
|
64
|
-
function shellQuote(value, label) {
|
|
65
|
-
if (value.trim().length === 0) {
|
|
66
|
-
throw new Error(`${label} must not be empty`);
|
|
67
|
-
}
|
|
68
|
-
if (!isAbsolute(value)) {
|
|
69
|
-
throw new Error(`${label} must be absolute: ${value}`);
|
|
70
|
-
}
|
|
71
|
-
// biome-ignore lint/suspicious/noControlCharactersInRegex: control characters break both parsers
|
|
72
|
-
if (/['"\\#\n\r\t\u0000-\u001f]/.test(value)) {
|
|
73
|
-
throw new Error(`${label} contains characters a tmux hook cannot carry: ${value}`);
|
|
74
|
-
}
|
|
75
|
-
return `'${value}'`;
|
|
76
|
-
}
|
package/dist/reap.d.ts
CHANGED
|
@@ -40,8 +40,3 @@ export declare function parseTmuxServerPid(tmux: string | undefined): number | u
|
|
|
40
40
|
export declare function reapSession(session: string, dependencies: ReapDependencies): Promise<ReapReport>;
|
|
41
41
|
export declare function formatReapReport(report: ReapReport, timestamp: string): string;
|
|
42
42
|
export declare function formatReapFailure(session: string, error: unknown, timestamp: string): string;
|
|
43
|
-
/** `run-shell` output goes nowhere, so every reap records what it did here. */
|
|
44
|
-
export declare function reapLogPath(dependencies: {
|
|
45
|
-
env: Record<string, string | undefined>;
|
|
46
|
-
homedir: () => string;
|
|
47
|
-
}): string;
|
package/dist/reap.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { isAbsolute, join } from "node:path";
|
|
2
1
|
export const defaultGraceMs = 2000;
|
|
3
2
|
export const defaultSettleMs = 250;
|
|
4
3
|
const killRounds = 2;
|
|
@@ -100,17 +99,11 @@ export function formatReapReport(report, timestamp) {
|
|
|
100
99
|
];
|
|
101
100
|
return `${timestamp} ${fields.join(" ")}\n`;
|
|
102
101
|
}
|
|
102
|
+
/** A log record is one line, so a multi-line error message is flattened into it. */
|
|
103
|
+
const whitespaceRun = /\s+/g;
|
|
103
104
|
export function formatReapFailure(session, error, timestamp) {
|
|
104
105
|
const message = error instanceof Error ? error.message : String(error);
|
|
105
|
-
return `${timestamp} session=${session} error=${message.replace(
|
|
106
|
-
}
|
|
107
|
-
/** `run-shell` output goes nowhere, so every reap records what it did here. */
|
|
108
|
-
export function reapLogPath(dependencies) {
|
|
109
|
-
const xdgStateHome = dependencies.env.XDG_STATE_HOME;
|
|
110
|
-
const stateHome = xdgStateHome && isAbsolute(xdgStateHome)
|
|
111
|
-
? xdgStateHome
|
|
112
|
-
: join(dependencies.homedir(), ".local", "state");
|
|
113
|
-
return join(stateHome, "termwire", "reap.log");
|
|
106
|
+
return `${timestamp} session=${session} error=${message.replace(whitespaceRun, " ")}\n`;
|
|
114
107
|
}
|
|
115
108
|
function formatPids(pids) {
|
|
116
109
|
return pids.length === 0 ? "-" : pids.join(",");
|
package/dist/runtime.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ import type { GitExec } from "./worktree.js";
|
|
|
8
8
|
export interface RuntimeFileSystem {
|
|
9
9
|
readFile: (path: string) => Promise<string>;
|
|
10
10
|
exists: (path: string) => Promise<boolean>;
|
|
11
|
+
/** False for anything that cannot be stat'ed, not only for a missing path. */
|
|
12
|
+
isFile: (path: string) => Promise<boolean>;
|
|
11
13
|
mkdir: (path: string) => Promise<void>;
|
|
12
14
|
/** `flag: "wx"` fails on an existing file instead of replacing it. */
|
|
13
15
|
writeFile: (path: string, contents: string, options?: {
|
|
@@ -16,6 +18,7 @@ export interface RuntimeFileSystem {
|
|
|
16
18
|
rename: (from: string, to: string) => Promise<void>;
|
|
17
19
|
appendFile: (path: string, contents: string) => Promise<void>;
|
|
18
20
|
unlink: (path: string) => Promise<void>;
|
|
21
|
+
realpath: (path: string) => Promise<string>;
|
|
19
22
|
}
|
|
20
23
|
export interface RuntimeHost {
|
|
21
24
|
env: Record<string, string | undefined>;
|
|
@@ -27,6 +30,8 @@ export interface RuntimeHost {
|
|
|
27
30
|
execPath: string;
|
|
28
31
|
/** The launched script, which the tmux hook has to name by absolute path. */
|
|
29
32
|
scriptPath: string | undefined;
|
|
33
|
+
/** The installed `@termwire/cli` version, for `--version`. */
|
|
34
|
+
version: string;
|
|
30
35
|
now: () => Date;
|
|
31
36
|
/** A unique name for a temporary file, so two writers cannot collide. */
|
|
32
37
|
randomId: () => string;
|
package/dist/runtime.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
-
import {
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { appendFile as appendFileToDisk, mkdir as mkdirDirectory, readdir as readDirectory, readFile as readFileFromDisk, rename as renameFile, realpath as resolveRealpath, stat, unlink as unlinkFile, writeFile as writeFileToDisk, } from "node:fs/promises";
|
|
4
5
|
import { homedir as getHomeDirectory } from "node:os";
|
|
5
6
|
import { createNvim } from "@termwire/nvim";
|
|
6
7
|
import { createTmux } from "@termwire/tmux";
|
|
@@ -22,6 +23,14 @@ export function createNodeRuntime() {
|
|
|
22
23
|
fs: {
|
|
23
24
|
readFile: (path) => readFileFromDisk(path, "utf8"),
|
|
24
25
|
exists: fileExists,
|
|
26
|
+
isFile: async (path) => {
|
|
27
|
+
try {
|
|
28
|
+
return (await stat(path)).isFile();
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
},
|
|
25
34
|
mkdir: async (path) => {
|
|
26
35
|
await mkdirDirectory(path, { recursive: true });
|
|
27
36
|
},
|
|
@@ -29,6 +38,7 @@ export function createNodeRuntime() {
|
|
|
29
38
|
rename: renameFile,
|
|
30
39
|
appendFile: appendFileToDisk,
|
|
31
40
|
unlink: unlinkFile,
|
|
41
|
+
realpath: resolveRealpath,
|
|
32
42
|
},
|
|
33
43
|
host: {
|
|
34
44
|
env,
|
|
@@ -38,6 +48,7 @@ export function createNodeRuntime() {
|
|
|
38
48
|
pid: process.pid,
|
|
39
49
|
execPath: process.execPath,
|
|
40
50
|
scriptPath: process.argv[1],
|
|
51
|
+
version: readPackageVersion(),
|
|
41
52
|
now: () => new Date(),
|
|
42
53
|
randomId: randomUUID,
|
|
43
54
|
isTerminal: process.stdin.isTTY === true && process.stdout.isTTY === true,
|
|
@@ -55,6 +66,16 @@ export function createNodeRuntime() {
|
|
|
55
66
|
}),
|
|
56
67
|
};
|
|
57
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Read at runtime rather than baked in at build time, the way `@termwire/mcp`
|
|
71
|
+
* reports its own version. `dist/runtime.js` and `src/runtime.ts` both sit one
|
|
72
|
+
* level below the package root, so the same specifier resolves in a published
|
|
73
|
+
* install and from a checkout.
|
|
74
|
+
*/
|
|
75
|
+
function readPackageVersion() {
|
|
76
|
+
const manifest = readFileSync(new URL("../package.json", import.meta.url), "utf8");
|
|
77
|
+
return JSON.parse(manifest).version;
|
|
78
|
+
}
|
|
58
79
|
/**
|
|
59
80
|
* The one place that knows which platforms can be scanned. A platform module takes
|
|
60
81
|
* only its own dependencies, which a registry keyed by platform could not express:
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The path is read by two parsers: tmux, which expands `#{...}` and backslash
|
|
3
|
+
* escapes inside double quotes, and then `sh`. Quoting characters would have to
|
|
4
|
+
* survive both, so they are rejected instead of escaped twice.
|
|
5
|
+
*/
|
|
6
|
+
export declare function shellQuote(value: string, label: string): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { isAbsolute } from "node:path";
|
|
2
|
+
/**
|
|
3
|
+
* The path is read by two parsers: tmux, which expands `#{...}` and backslash
|
|
4
|
+
* escapes inside double quotes, and then `sh`. Quoting characters would have to
|
|
5
|
+
* survive both, so they are rejected instead of escaped twice.
|
|
6
|
+
*/
|
|
7
|
+
export function shellQuote(value, label) {
|
|
8
|
+
if (value.trim().length === 0) {
|
|
9
|
+
throw new Error(`${label} must not be empty`);
|
|
10
|
+
}
|
|
11
|
+
if (!isAbsolute(value)) {
|
|
12
|
+
throw new Error(`${label} must be absolute: ${value}`);
|
|
13
|
+
}
|
|
14
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: control characters break both parsers
|
|
15
|
+
if (/['"\\#\n\r\t\u0000-\u001f]/.test(value)) {
|
|
16
|
+
throw new Error(`${label} contains characters a tmux command cannot carry: ${value}`);
|
|
17
|
+
}
|
|
18
|
+
return `'${value}'`;
|
|
19
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a command run by tmux records what it did: `run-shell` output goes nowhere.
|
|
3
|
+
* The path is resolved the way the tmux server's environment sees it.
|
|
4
|
+
*/
|
|
5
|
+
export declare function stateLogPath(dependencies: {
|
|
6
|
+
env: Record<string, string | undefined>;
|
|
7
|
+
homedir: () => string;
|
|
8
|
+
}, file: string): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isAbsolute, join } from "node:path";
|
|
2
|
+
/**
|
|
3
|
+
* Where a command run by tmux records what it did: `run-shell` output goes nowhere.
|
|
4
|
+
* The path is resolved the way the tmux server's environment sees it.
|
|
5
|
+
*/
|
|
6
|
+
export function stateLogPath(dependencies, file) {
|
|
7
|
+
const xdgStateHome = dependencies.env.XDG_STATE_HOME;
|
|
8
|
+
const stateHome = xdgStateHome && isAbsolute(xdgStateHome)
|
|
9
|
+
? xdgStateHome
|
|
10
|
+
: join(dependencies.homedir(), ".local", "state");
|
|
11
|
+
return join(stateHome, "termwire", file);
|
|
12
|
+
}
|
package/dist/up.d.ts
CHANGED
|
@@ -23,8 +23,11 @@ export interface UpDependencies {
|
|
|
23
23
|
mkdir: (path: string) => Promise<void>;
|
|
24
24
|
removeFile: (path: string) => Promise<void>;
|
|
25
25
|
tmux: ReturnType<typeof createTmux>;
|
|
26
|
-
/**
|
|
27
|
-
|
|
26
|
+
/**
|
|
27
|
+
* The server-wide reap hook and mouse binding, and the mark on `session` that lets
|
|
28
|
+
* the binding act there. Best effort: a workspace is worth having without them.
|
|
29
|
+
*/
|
|
30
|
+
installServerHooks: (session: string) => Promise<void>;
|
|
28
31
|
loadGlobalConfig: () => Promise<LoadedConfig | undefined>;
|
|
29
32
|
loadProjectConfig: (gitRoot: string) => Promise<LoadedConfig | undefined>;
|
|
30
33
|
resolveLayout: (globalConfig: LoadedConfig | undefined, projectConfig: LoadedConfig | undefined) => LayoutConfig;
|
package/dist/up.js
CHANGED
|
@@ -10,7 +10,7 @@ export async function up(request, dependencies) {
|
|
|
10
10
|
const gitRoot = await dependencies.findGitRoot(cwd);
|
|
11
11
|
const identity = createIdentity({ cwd, gitRoot, name: request.name });
|
|
12
12
|
if (await dependencies.tmux.hasSession(identity.session)) {
|
|
13
|
-
await
|
|
13
|
+
await bestEffortInstallServerHooks(dependencies, identity.session);
|
|
14
14
|
await dependencies.tmux.attach(identity.session);
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
@@ -24,7 +24,7 @@ export async function up(request, dependencies) {
|
|
|
24
24
|
cwd: workspace,
|
|
25
25
|
});
|
|
26
26
|
try {
|
|
27
|
-
await
|
|
27
|
+
await bestEffortInstallServerHooks(dependencies, identity.session);
|
|
28
28
|
await dependencies.tmux.setSessionTitle(identity.session);
|
|
29
29
|
await dependencies.createLayout({
|
|
30
30
|
tmux: dependencies.tmux,
|
|
@@ -68,12 +68,12 @@ async function resolveWorkspace(request, dependencies, identity, gitRoot, cwd) {
|
|
|
68
68
|
branch: request.branch ?? name,
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
-
async function
|
|
71
|
+
async function bestEffortInstallServerHooks(dependencies, session) {
|
|
72
72
|
try {
|
|
73
|
-
await dependencies.
|
|
73
|
+
await dependencies.installServerHooks(session);
|
|
74
74
|
}
|
|
75
75
|
catch {
|
|
76
|
-
// Never trade the workspace for
|
|
76
|
+
// Never trade the workspace for a hook: an implementation that
|
|
77
77
|
// reports failures does so itself, before throwing.
|
|
78
78
|
}
|
|
79
79
|
}
|
package/dist/worktree.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare function parseWorktreeList(output: string): WorktreeEntry[];
|
|
|
18
18
|
export declare function prepareWorktree(options: {
|
|
19
19
|
exec: GitExec;
|
|
20
20
|
pathExists: (path: string) => Promise<boolean>;
|
|
21
|
-
realpath
|
|
21
|
+
realpath: (path: string) => Promise<string>;
|
|
22
22
|
gitRoot: string;
|
|
23
23
|
project: string;
|
|
24
24
|
name: string;
|
package/dist/worktree.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { realpath as resolveRealpath } from "node:fs/promises";
|
|
2
1
|
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
3
2
|
import { sanitizeComponent } from "./identity.js";
|
|
4
3
|
/** Git's own words when the directory is outside a repository, next to exit 128. */
|
|
@@ -67,7 +66,7 @@ export async function prepareWorktree(options) {
|
|
|
67
66
|
gitRoot: options.gitRoot,
|
|
68
67
|
exec: options.exec,
|
|
69
68
|
pathExists: options.pathExists,
|
|
70
|
-
realpath: options.realpath
|
|
69
|
+
realpath: options.realpath,
|
|
71
70
|
});
|
|
72
71
|
}
|
|
73
72
|
if (await options.pathExists(target)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@termwire/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "Creates tmux workspaces where a coding agent and Neovim run side by side, and opens files in the workspace editor.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"tmux",
|
|
7
|
+
"neovim",
|
|
8
|
+
"nvim",
|
|
9
|
+
"coding-agent",
|
|
10
|
+
"ai-agent",
|
|
11
|
+
"claude-code",
|
|
12
|
+
"opencode",
|
|
13
|
+
"git-worktree",
|
|
14
|
+
"workspace",
|
|
15
|
+
"cli",
|
|
16
|
+
"developer-tools"
|
|
17
|
+
],
|
|
4
18
|
"type": "module",
|
|
5
19
|
"main": "./dist/index.js",
|
|
6
20
|
"types": "./dist/index.d.ts",
|
|
@@ -38,12 +52,12 @@
|
|
|
38
52
|
"url": "https://github.com/max-konin/termwire/issues"
|
|
39
53
|
},
|
|
40
54
|
"dependencies": {
|
|
41
|
-
"@clack/core": "^1.
|
|
42
|
-
"@clack/prompts": "^1.
|
|
43
|
-
"@termwire/nvim": "^0.
|
|
44
|
-
"@termwire/tmux": "^0.
|
|
45
|
-
"commander": "^15.
|
|
55
|
+
"@clack/core": "^1.6.0",
|
|
56
|
+
"@clack/prompts": "^1.9.0",
|
|
57
|
+
"@termwire/nvim": "^0.7.0",
|
|
58
|
+
"@termwire/tmux": "^0.7.0",
|
|
59
|
+
"commander": "^15.1.0",
|
|
46
60
|
"jsonc-parser": "^3.3.1",
|
|
47
|
-
"zod": "^4.
|
|
61
|
+
"zod": "^4.6.6"
|
|
48
62
|
}
|
|
49
63
|
}
|