opencode-gitwt 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.
Files changed (3) hide show
  1. package/README.md +26 -3
  2. package/package.json +2 -2
  3. package/src/index.js +26 -1
package/README.md CHANGED
@@ -3,19 +3,22 @@
3
3
  OpenCode adapter for `gitwt`. It exposes the shared worktree core as agent tools:
4
4
  https://github.com/voischev/gitwt
5
5
 
6
- Requires Node.js 22.14+ and Git. Supports OpenCode 1.19.3–<2.
6
+ Requires Node.js 22.14+ and Git. Supports OpenCode V1 (1.19.3+) and V2 (2.2.5+).
7
7
 
8
8
  ## Use in OpenCode
9
9
 
10
- Add the plugin to your project's `opencode.json`, then restart OpenCode:
10
+ For **OpenCode V2**, add to your project's `opencode.json`:
11
11
 
12
12
  ```json
13
13
  {
14
14
  "$schema": "https://opencode.ai/config.json",
15
- "plugin": ["opencode-gitwt@latest"]
15
+ "plugins": ["opencode-gitwt@latest"]
16
16
  }
17
17
  ```
18
18
 
19
+ For **V1**, use `"plugin": ["opencode-gitwt@latest"]` instead. Restart OpenCode
20
+ after installation. Both versions expose the same four gitwt tools.
21
+
19
22
  Ask the agent in chat, for example:
20
23
 
21
24
  > Create a worktree on branch feature/login from main, fix the login issue there,
@@ -43,3 +46,23 @@ and `~/.config/gitwt/config.json` globally. Options include `remote`, `base`,
43
46
 
44
47
  For the standalone `gitwt` command, run `npm install -g @voischev/gitwt`.
45
48
  Move existing settings to these paths and remove comments and trailing commas.
49
+
50
+ ## Why use it with OpenCode V2?
51
+
52
+ V2 already has native worktree tools, setup commands, and session moves.
53
+ Use gitwt when you want:
54
+
55
+ - **One workflow across agents:** the same standalone CLI, Node API, and JSON
56
+ contract in OpenCode, Codex, Claude Code, and scripts.
57
+ - **Named branches from a fresh remote base:** gitwt fetches the selected base
58
+ and verifies path, branch, and commit before setup. V2's built-in Git strategy
59
+ creates a detached checkout from a local ref or HEAD, without fetching.
60
+ - **Per-worktree lifecycle hooks:** saved `postCreate` and `preRemove` commands;
61
+ teardown failure blocks removal through gitwt, even with `--force`.
62
+
63
+ Prefer native V2 features for integrated UI navigation and actual session moves.
64
+ Native removal does not run gitwt's teardown hooks: remove gitwt-managed copies
65
+ through `gitwt_remove` or the CLI when those hooks matter.
66
+
67
+ Comparison verified against OpenCode V2.2.5's built-in Git strategy:
68
+ https://github.com/anomalyco/opencode/blob/v2.2.5/packages/core/src/worktree.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-gitwt",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Git worktree tools for OpenCode, powered by gitwt",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -15,7 +15,7 @@
15
15
  ],
16
16
  "engines": {
17
17
  "node": ">=22.14.0",
18
- "opencode": ">=1.19.3 <2"
18
+ "opencode": ">=1.19.3 <2 || >=2.2.5 <3"
19
19
  },
20
20
  "scripts": {
21
21
  "check": "biome check .",
package/src/index.js CHANGED
@@ -102,4 +102,29 @@ export async function GitwtPlugin({ directory }, config = {}) {
102
102
  };
103
103
  }
104
104
 
105
- export default { id: "opencode-gitwt", server: GitwtPlugin };
105
+ export default {
106
+ id: "opencode-gitwt",
107
+ server: GitwtPlugin,
108
+ async setup(ctx) {
109
+ const directory = ctx.location.directory;
110
+ const hooks = await GitwtPlugin({ directory }, ctx.options);
111
+ const definitions = [];
112
+ for (const [name, definition] of Object.entries(hooks.tool)) {
113
+ const output = {};
114
+ await hooks["tool.definition"]({ toolID: name }, output);
115
+ definitions.push({
116
+ name,
117
+ description: definition.description,
118
+ input: output.jsonSchema,
119
+ options: { codemode: false },
120
+ async execute(args, call) {
121
+ call.signal.throwIfAborted();
122
+ return { content: await definition.execute(args, { directory, abort: call.signal }) };
123
+ },
124
+ });
125
+ }
126
+ await ctx.tool.transform((editor) => {
127
+ for (const definition of definitions) editor.add(definition);
128
+ });
129
+ },
130
+ };