@termwire/cli 0.1.0 → 0.1.2
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 +17 -0
- package/README.md +15 -8
- package/dist/branch.d.ts +2 -0
- package/dist/branch.js +13 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/program.js +15 -0
- package/dist/up.d.ts +6 -0
- package/dist/up.js +12 -1
- package/dist/worktree.d.ts +1 -0
- package/dist/worktree.js +23 -22
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @termwire/cli
|
|
2
2
|
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add explicit Git branch selection to `termwire up`, preserve slashes in branch names, and document
|
|
8
|
+
the default branch and worktree derivation rules.
|
|
9
|
+
- @termwire/tmux@0.1.2
|
|
10
|
+
- @termwire/nvim@0.1.2
|
|
11
|
+
|
|
12
|
+
## 0.1.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Correct published internal dependency ranges so external Bun installs resolve Termwire packages.
|
|
17
|
+
- @termwire/tmux@0.1.1
|
|
18
|
+
- @termwire/nvim@0.1.1
|
|
19
|
+
|
|
3
20
|
## 0.1.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -20,11 +20,20 @@ the explicit `termwire_open({ path, line? })` OpenCode plugin tool.
|
|
|
20
20
|
|
|
21
21
|
## Commands
|
|
22
22
|
|
|
23
|
-
| Command
|
|
24
|
-
|
|
|
25
|
-
| `termwire up
|
|
26
|
-
| `termwire up
|
|
27
|
-
| `termwire up
|
|
23
|
+
| Command | Workspace | Branch |
|
|
24
|
+
| --- | --- | --- |
|
|
25
|
+
| `termwire up chore/improve` | current directory | unchanged |
|
|
26
|
+
| `termwire up chore/improve -w` | sibling `<project>-chore-improve` | `chore/improve` |
|
|
27
|
+
| `termwire up session -w -b feature/api` | sibling `<project>-session` | `feature/api` |
|
|
28
|
+
| `termwire up session -b feature/api` | current directory | switch to it, or create it from current `HEAD` |
|
|
29
|
+
| `termwire up session -w legacy-name` | sibling `<project>-legacy-name` | `legacy-name` |
|
|
30
|
+
| `termwire up session -w legacy-name -b feature/api` | sibling `<project>-legacy-name` | `feature/api` |
|
|
31
|
+
|
|
32
|
+
`<name>` always determines the tmux identity. With `-w`, an explicit optional worktree value
|
|
33
|
+
selects the directory key; otherwise `<name>` does. `--branch` selects the exact Git branch when
|
|
34
|
+
present; otherwise the worktree directory key is also the branch name. Slashes are preserved in
|
|
35
|
+
Git branch names and replaced only in filesystem-safe worktree directory names. Without `-w`, Git
|
|
36
|
+
is changed only when `--branch` is present. Existing tmux sessions attach without Git mutations.
|
|
28
37
|
|
|
29
38
|
## How it works
|
|
30
39
|
|
|
@@ -33,9 +42,7 @@ the explicit `termwire_open({ path, line? })` OpenCode plugin tool.
|
|
|
33
42
|
and `TERMWIRE_EDITOR_PANE`.
|
|
34
43
|
- OpenCode is not started automatically. Users may start it in the shell and
|
|
35
44
|
reshape the workspace with tmux.
|
|
36
|
-
- Existing sessions attach immediately without worktree mutation.
|
|
37
|
-
`-w` uses the workspace name; an explicit worktree value selects its branch
|
|
38
|
-
and sibling directory while the session name stays `<project>-<name>`.
|
|
45
|
+
- Existing sessions attach immediately without branch or worktree mutation.
|
|
39
46
|
- There are no config files or persistent state.
|
|
40
47
|
- The CLI has no shell-facing `open` command and does not need to be in `PATH`
|
|
41
48
|
for the plugin: the plugin composes the nvim and tmux adapters directly.
|
package/dist/branch.d.ts
ADDED
package/dist/branch.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export async function prepareBranch(exec, cwd, name) {
|
|
2
|
+
const existing = await exec(["git", "show-ref", "--verify", "--quiet", `refs/heads/${name}`], {
|
|
3
|
+
cwd,
|
|
4
|
+
});
|
|
5
|
+
if (existing.exitCode !== 0 && existing.exitCode !== 1) {
|
|
6
|
+
throw new Error(`git show-ref failed: ${existing.stderr}`);
|
|
7
|
+
}
|
|
8
|
+
const command = existing.exitCode === 0 ? ["git", "switch", name] : ["git", "switch", "-c", name];
|
|
9
|
+
const switched = await exec(command, { cwd });
|
|
10
|
+
if (switched.exitCode !== 0) {
|
|
11
|
+
throw new Error(`git switch failed: ${switched.stderr}`);
|
|
12
|
+
}
|
|
13
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/program.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mkdir as mkdirDirectory, stat, unlink as unlinkFile } from "node:fs/promises";
|
|
2
2
|
import { createTmux } from "@termwire/tmux";
|
|
3
3
|
import { Command, CommanderError } from "commander";
|
|
4
|
+
import { prepareBranch } from "./branch";
|
|
4
5
|
import { up } from "./up";
|
|
5
6
|
import { findGitRoot, prepareWorktree } from "./worktree";
|
|
6
7
|
export const executeGit = async (argv, options) => {
|
|
@@ -50,6 +51,7 @@ export function createRuntimeUp(dependencies = {}) {
|
|
|
50
51
|
return (request) => up(request, {
|
|
51
52
|
cwd,
|
|
52
53
|
findGitRoot: (directory) => findGitRoot(gitExec, directory),
|
|
54
|
+
prepareBranch: ({ cwd: directory, name }) => prepareBranch(gitExec, directory, name),
|
|
53
55
|
prepareWorktree: (options) => prepareWorktree({ ...options, exec: gitExec, pathExists }),
|
|
54
56
|
mkdir: async (path) => {
|
|
55
57
|
await mkdir(path, { recursive: true });
|
|
@@ -68,13 +70,26 @@ export function createProgram(dependencies) {
|
|
|
68
70
|
program
|
|
69
71
|
.command("up <name>")
|
|
70
72
|
.option("-w, --worktree [wt-name]", "create or reuse a Git worktree")
|
|
73
|
+
.option("-b, --branch <name>", "select the exact Git branch")
|
|
74
|
+
.addHelpText("after", `
|
|
75
|
+
Branch and worktree selection:
|
|
76
|
+
Without -w, --branch switches the current checkout, creating the branch when absent.
|
|
77
|
+
With -w, the optional worktree name selects the directory; otherwise <name> is used.
|
|
78
|
+
--branch selects the branch; otherwise the worktree directory key is also the branch.
|
|
79
|
+
Slashes are preserved in Git branch names and sanitized only in worktree directory names.
|
|
80
|
+
Existing sessions attach without Git changes.
|
|
81
|
+
`)
|
|
71
82
|
.action(async (name, options) => {
|
|
72
83
|
if (options.worktree === "") {
|
|
73
84
|
throw new Error("worktree name must not be empty");
|
|
74
85
|
}
|
|
86
|
+
if (options.branch === "") {
|
|
87
|
+
throw new Error("branch name must not be empty");
|
|
88
|
+
}
|
|
75
89
|
await dependencies.up({
|
|
76
90
|
name,
|
|
77
91
|
...(options.worktree === undefined ? {} : { worktree: options.worktree }),
|
|
92
|
+
...(options.branch === undefined ? {} : { branch: options.branch }),
|
|
78
93
|
});
|
|
79
94
|
});
|
|
80
95
|
return program;
|
package/dist/up.d.ts
CHANGED
|
@@ -2,14 +2,20 @@ import type { createTmux } from "@termwire/tmux";
|
|
|
2
2
|
export interface UpRequest {
|
|
3
3
|
name: string;
|
|
4
4
|
worktree?: true | string;
|
|
5
|
+
branch?: string;
|
|
5
6
|
}
|
|
6
7
|
export interface UpDependencies {
|
|
7
8
|
cwd: () => string;
|
|
8
9
|
findGitRoot: (cwd: string) => Promise<string | undefined>;
|
|
10
|
+
prepareBranch: (options: {
|
|
11
|
+
cwd: string;
|
|
12
|
+
name: string;
|
|
13
|
+
}) => Promise<void>;
|
|
9
14
|
prepareWorktree: (options: {
|
|
10
15
|
gitRoot: string;
|
|
11
16
|
project: string;
|
|
12
17
|
name: string;
|
|
18
|
+
branch: string;
|
|
13
19
|
}) => Promise<string>;
|
|
14
20
|
mkdir: (path: string) => Promise<void>;
|
|
15
21
|
removeFile: (path: string) => Promise<void>;
|
package/dist/up.js
CHANGED
|
@@ -3,6 +3,9 @@ export async function up(request, dependencies) {
|
|
|
3
3
|
if (request.worktree === "") {
|
|
4
4
|
throw new Error("worktree name must not be empty");
|
|
5
5
|
}
|
|
6
|
+
if (request.branch === "") {
|
|
7
|
+
throw new Error("branch name must not be empty");
|
|
8
|
+
}
|
|
6
9
|
const cwd = dependencies.cwd();
|
|
7
10
|
const gitRoot = await dependencies.findGitRoot(cwd);
|
|
8
11
|
const identity = createIdentity({ cwd, gitRoot, name: request.name });
|
|
@@ -36,15 +39,23 @@ export async function up(request, dependencies) {
|
|
|
36
39
|
}
|
|
37
40
|
async function resolveWorkspace(request, dependencies, identity, gitRoot, cwd) {
|
|
38
41
|
if (request.worktree === undefined) {
|
|
42
|
+
if (request.branch !== undefined) {
|
|
43
|
+
if (!gitRoot) {
|
|
44
|
+
throw new Error("branch requires a Git repository");
|
|
45
|
+
}
|
|
46
|
+
await dependencies.prepareBranch({ cwd, name: request.branch });
|
|
47
|
+
}
|
|
39
48
|
return cwd;
|
|
40
49
|
}
|
|
41
50
|
if (!gitRoot) {
|
|
42
51
|
throw new Error("worktree requires a Git repository");
|
|
43
52
|
}
|
|
53
|
+
const name = request.worktree === true ? request.name : request.worktree;
|
|
44
54
|
return dependencies.prepareWorktree({
|
|
45
55
|
gitRoot,
|
|
46
56
|
project: identity.project,
|
|
47
|
-
name
|
|
57
|
+
name,
|
|
58
|
+
branch: request.branch ?? name,
|
|
48
59
|
});
|
|
49
60
|
}
|
|
50
61
|
function createWorkspaceEnvironment(identity, editorPane) {
|
package/dist/worktree.d.ts
CHANGED
package/dist/worktree.js
CHANGED
|
@@ -38,14 +38,15 @@ export function parseWorktreeList(output) {
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
export async function prepareWorktree(options) {
|
|
41
|
-
const
|
|
42
|
-
const
|
|
41
|
+
const pathName = sanitizeComponent(options.name, "name");
|
|
42
|
+
const branch = options.branch ?? options.name;
|
|
43
|
+
const target = join(dirname(options.gitRoot), `${options.project}-${pathName}`);
|
|
43
44
|
const entries = await listWorktrees(options.exec, options.gitRoot);
|
|
44
45
|
const registered = findWorktreeAt(entries, target);
|
|
45
46
|
if (registered) {
|
|
46
47
|
return reuseRegisteredWorktree({
|
|
47
48
|
entry: registered,
|
|
48
|
-
|
|
49
|
+
branch,
|
|
49
50
|
target,
|
|
50
51
|
gitRoot: options.gitRoot,
|
|
51
52
|
exec: options.exec,
|
|
@@ -56,11 +57,11 @@ export async function prepareWorktree(options) {
|
|
|
56
57
|
if (await options.pathExists(target)) {
|
|
57
58
|
throw new Error(`Worktree conflict: target path is occupied: ${target}`);
|
|
58
59
|
}
|
|
59
|
-
const branchAt = findBranchCheckout(entries,
|
|
60
|
+
const branchAt = findBranchCheckout(entries, branch);
|
|
60
61
|
if (branchAt) {
|
|
61
|
-
throw new Error(`Worktree conflict: branch ${
|
|
62
|
+
throw new Error(`Worktree conflict: branch ${branch} is already checked out at ${branchAt.path}`);
|
|
62
63
|
}
|
|
63
|
-
await addWorktree(options.exec, options.gitRoot, target,
|
|
64
|
+
await addWorktree(options.exec, options.gitRoot, target, branch);
|
|
64
65
|
return target;
|
|
65
66
|
}
|
|
66
67
|
async function listWorktrees(exec, gitRoot) {
|
|
@@ -75,7 +76,7 @@ async function listWorktrees(exec, gitRoot) {
|
|
|
75
76
|
function findWorktreeAt(entries, target) {
|
|
76
77
|
return entries.find((entry) => resolve(entry.path) === resolve(target));
|
|
77
78
|
}
|
|
78
|
-
function validateRegistrationMetadata(entry,
|
|
79
|
+
function validateRegistrationMetadata(entry, branch) {
|
|
79
80
|
if (entry.prunable) {
|
|
80
81
|
throw new Error(`Worktree conflict: registered target is prunable${typeof entry.prunable === "string" ? `: ${entry.prunable}` : ""}`);
|
|
81
82
|
}
|
|
@@ -85,12 +86,12 @@ function validateRegistrationMetadata(entry, name) {
|
|
|
85
86
|
if (entry.detached) {
|
|
86
87
|
throw new Error("Worktree conflict: registered target is detached");
|
|
87
88
|
}
|
|
88
|
-
if (entry.branch !==
|
|
89
|
-
throw new Error(`Worktree conflict: expected ${
|
|
89
|
+
if (entry.branch !== branch) {
|
|
90
|
+
throw new Error(`Worktree conflict: expected ${branch}, found ${entry.branch ?? "detached HEAD"}`);
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
async function reuseRegisteredWorktree(options) {
|
|
93
|
-
validateRegistrationMetadata(options.entry, options.
|
|
94
|
+
validateRegistrationMetadata(options.entry, options.branch);
|
|
94
95
|
if (!(await options.pathExists(options.target))) {
|
|
95
96
|
throw new Error(`Worktree conflict: registered target path is missing: ${options.target}`);
|
|
96
97
|
}
|
|
@@ -99,23 +100,23 @@ async function reuseRegisteredWorktree(options) {
|
|
|
99
100
|
realpath: options.realpath,
|
|
100
101
|
target: options.target,
|
|
101
102
|
gitRoot: options.gitRoot,
|
|
102
|
-
|
|
103
|
+
branch: options.branch,
|
|
103
104
|
});
|
|
104
105
|
return options.target;
|
|
105
106
|
}
|
|
106
|
-
function findBranchCheckout(entries,
|
|
107
|
-
return entries.find((entry) => entry.branch ===
|
|
107
|
+
function findBranchCheckout(entries, branch) {
|
|
108
|
+
return entries.find((entry) => entry.branch === branch);
|
|
108
109
|
}
|
|
109
|
-
async function addWorktree(exec, gitRoot, target,
|
|
110
|
-
const
|
|
110
|
+
async function addWorktree(exec, gitRoot, target, branch) {
|
|
111
|
+
const existing = await exec(["git", "show-ref", "--verify", "--quiet", `refs/heads/${branch}`], {
|
|
111
112
|
cwd: gitRoot,
|
|
112
113
|
});
|
|
113
|
-
if (
|
|
114
|
-
throw new Error(`git show-ref failed: ${
|
|
114
|
+
if (existing.exitCode !== 0 && existing.exitCode !== 1) {
|
|
115
|
+
throw new Error(`git show-ref failed: ${existing.stderr}`);
|
|
115
116
|
}
|
|
116
|
-
const command =
|
|
117
|
-
? ["git", "worktree", "add", target,
|
|
118
|
-
: ["git", "worktree", "add", "-b",
|
|
117
|
+
const command = existing.exitCode === 0
|
|
118
|
+
? ["git", "worktree", "add", target, branch]
|
|
119
|
+
: ["git", "worktree", "add", "-b", branch, target];
|
|
119
120
|
const added = await exec(command, { cwd: gitRoot });
|
|
120
121
|
if (added.exitCode !== 0) {
|
|
121
122
|
throw new Error(`git worktree add failed: ${added.stderr}`);
|
|
@@ -156,8 +157,8 @@ async function validateRegisteredWorktree(options) {
|
|
|
156
157
|
if (liveBranch.exitCode !== 0) {
|
|
157
158
|
throw new Error(`Worktree conflict: registered target has no symbolic HEAD: ${liveBranch.stderr}`);
|
|
158
159
|
}
|
|
159
|
-
if (liveBranch.stdout.trim() !== `refs/heads/${options.
|
|
160
|
-
throw new Error(`Worktree conflict: registered target live branch is ${liveBranch.stdout.trim()}, expected refs/heads/${options.
|
|
160
|
+
if (liveBranch.stdout.trim() !== `refs/heads/${options.branch}`) {
|
|
161
|
+
throw new Error(`Worktree conflict: registered target live branch is ${liveBranch.stdout.trim()}, expected refs/heads/${options.branch}`);
|
|
161
162
|
}
|
|
162
163
|
}
|
|
163
164
|
function resolveGitPath(path, cwd) {
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@termwire/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"bin": {
|
|
8
|
-
"termwire": "
|
|
8
|
+
"termwire": "dist/bin/termwire.js"
|
|
9
9
|
},
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"url": "https://github.com/max-konin/termwire/issues"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@termwire/nvim": "
|
|
41
|
-
"@termwire/tmux": "
|
|
40
|
+
"@termwire/nvim": "^0.1.2",
|
|
41
|
+
"@termwire/tmux": "^0.1.2",
|
|
42
42
|
"commander": "^15.0.0"
|
|
43
43
|
}
|
|
44
44
|
}
|