opencode-gitwt 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +52 -2
- package/package.json +49 -4
- package/src/index.js +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 voischev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,53 @@
|
|
|
1
|
-
#
|
|
1
|
+
# opencode-gitwt
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
OpenCode adapter for `gitwt`. It exposes the shared worktree core as agent tools:
|
|
4
|
+
https://github.com/voischev/gitwt
|
|
5
|
+
|
|
6
|
+
Requires Node.js 22.14+ and Git. Supports OpenCode 1.19.3–<2.
|
|
7
|
+
|
|
8
|
+
## Use in OpenCode
|
|
9
|
+
|
|
10
|
+
Add the plugin to your project's `opencode.json`, then restart OpenCode:
|
|
11
|
+
|
|
12
|
+
```json
|
|
13
|
+
{
|
|
14
|
+
"$schema": "https://opencode.ai/config.json",
|
|
15
|
+
"plugin": ["opencode-gitwt@latest"]
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Ask the agent in chat, for example:
|
|
20
|
+
|
|
21
|
+
> Create a worktree on branch feature/login from main, fix the login issue there,
|
|
22
|
+
> and run the tests. Keep the worktree for review.
|
|
23
|
+
|
|
24
|
+
The agent calls `gitwt_create` with `{"branch":"feature/login","base":"main"}`.
|
|
25
|
+
Use the returned `worktreePath` as the cwd for commands and as the base for
|
|
26
|
+
absolute paths in file operations. Continue in the same session; approve access
|
|
27
|
+
to that directory if OpenCode asks. `gitwt_cd` only returns the path and does not
|
|
28
|
+
change the session directory. Use `gitwt_list` to inspect copies and
|
|
29
|
+
`gitwt_remove` only on explicit request when the worktree is no longer in use.
|
|
30
|
+
|
|
31
|
+
## Tools
|
|
32
|
+
|
|
33
|
+
- `gitwt_create` creates and verifies a worktree.
|
|
34
|
+
- `gitwt_list` shows registered worktrees with optional status.
|
|
35
|
+
- `gitwt_cd` resolves a branch or full path without changing cwd.
|
|
36
|
+
- `gitwt_remove` removes a worktree explicitly, optionally with `force`.
|
|
37
|
+
|
|
38
|
+
## Configuration
|
|
39
|
+
|
|
40
|
+
The plugin uses the shared gitwt configuration: `.gitwt.jsonc` in the project
|
|
41
|
+
and `~/.config/gitwt/config.jsonc` globally. Options include `remote`, `base`,
|
|
42
|
+
`prefix`, `worktreeDir`, and `hooks`. See the core repository for details.
|
|
43
|
+
|
|
44
|
+
For the standalone `gitwt` command, run `npm install -g @voischev/gitwt`.
|
|
45
|
+
Upgrading from 0.1.x: move `.opencode/gitwt.jsonc` to `.gitwt.jsonc` and global
|
|
46
|
+
settings from `~/.config/opencode/gitwt.jsonc` to `~/.config/gitwt/config.jsonc`.
|
|
47
|
+
|
|
48
|
+
## Development
|
|
49
|
+
|
|
50
|
+
GitHub is the primary repository; SourceCraft is a mirror. Releases publish to
|
|
51
|
+
npm from GitHub with `NPM_TOKEN`.
|
|
52
|
+
|
|
53
|
+
Run `npm ci --ignore-scripts`, `npm run check`, and `npm test`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-gitwt",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Git worktree для OpenCode: создать, проверить, вернуть путь и явно удалить",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.js",
|
|
9
|
+
"./server": "./src/index.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"src",
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE"
|
|
15
|
+
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=22.14.0",
|
|
18
|
+
"opencode": ">=1.19.3 <2"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"check": "biome check .",
|
|
22
|
+
"test": "node --test",
|
|
23
|
+
"release": "node scripts/release.js"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@voischev/gitwt": "^0.1.3",
|
|
27
|
+
"zod": "4.1.8"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@biomejs/biome": "2.6.3"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/voischev/opencode-gitwt.git"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/voischev/opencode-gitwt",
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/voischev/opencode-gitwt/issues"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public",
|
|
42
|
+
"registry": "https://registry.npmjs.org/"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"opencode",
|
|
46
|
+
"opencode-plugin",
|
|
47
|
+
"git",
|
|
48
|
+
"worktree"
|
|
49
|
+
],
|
|
50
|
+
"license": "MIT"
|
|
51
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { createWorktree, listWorktrees, removeWorktree, resolveWorktree } from "@voischev/gitwt";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
export async function GitwtPlugin({ directory }, config = {}) {
|
|
5
|
+
return {
|
|
6
|
+
tool: {
|
|
7
|
+
gitwt_create: {
|
|
8
|
+
description:
|
|
9
|
+
"Создать и проверить новый worktree. Продолжайте текущую сессию, используя возвращённый worktreePath в командах и файловых операциях. Сохраняйте worktree при паузе и передаче задачи.",
|
|
10
|
+
args: {
|
|
11
|
+
branch: z.string().describe("Имя новой ветки"),
|
|
12
|
+
base: z.string().optional().describe("Базовая remote-ветка"),
|
|
13
|
+
from: z
|
|
14
|
+
.string()
|
|
15
|
+
.optional()
|
|
16
|
+
.describe("Явная локальная ссылка или проверенный commit вместо remote-базы"),
|
|
17
|
+
path: z.string().optional().describe("Полный путь нового worktree"),
|
|
18
|
+
noHooks: z.boolean().optional().describe("Явно отключить хуки для создаваемого worktree"),
|
|
19
|
+
},
|
|
20
|
+
execute: async (args, ctx) =>
|
|
21
|
+
JSON.stringify(
|
|
22
|
+
await createWorktree(ctx.directory ?? directory, {
|
|
23
|
+
...args,
|
|
24
|
+
signal: ctx.abort,
|
|
25
|
+
config: { ...config, base: args.base ?? config.base },
|
|
26
|
+
}),
|
|
27
|
+
),
|
|
28
|
+
},
|
|
29
|
+
gitwt_list: {
|
|
30
|
+
description:
|
|
31
|
+
"Показать worktree из реестра Git. status проверяет dirty и доступные ahead/behind; null означает неизвестное состояние.",
|
|
32
|
+
args: { status: z.boolean().optional() },
|
|
33
|
+
execute: async (args, ctx) =>
|
|
34
|
+
JSON.stringify(await listWorktrees(ctx.directory ?? directory, args)),
|
|
35
|
+
},
|
|
36
|
+
gitwt_cd: {
|
|
37
|
+
description:
|
|
38
|
+
"Найти worktree по точной ветке или полному пути и вернуть его путь, HEAD и статус. Каталог текущей сессии не меняется: используйте worktreePath явно.",
|
|
39
|
+
args: { target: z.string() },
|
|
40
|
+
execute: async ({ target }, ctx) =>
|
|
41
|
+
JSON.stringify(
|
|
42
|
+
await resolveWorktree(ctx.directory ?? directory, target, { status: true }),
|
|
43
|
+
),
|
|
44
|
+
},
|
|
45
|
+
gitwt_remove: {
|
|
46
|
+
description:
|
|
47
|
+
"Только по явной просьбе удалить указанный worktree, убедившись, что он больше не используется. force разрешает потерю изменений, но не обходит ошибку preRemove. Без автокоммитов и отложенной очистки.",
|
|
48
|
+
args: {
|
|
49
|
+
target: z.string(),
|
|
50
|
+
force: z.boolean().optional(),
|
|
51
|
+
keepBranch: z.boolean().optional(),
|
|
52
|
+
},
|
|
53
|
+
execute: async ({ target, force, keepBranch }, ctx) =>
|
|
54
|
+
JSON.stringify(
|
|
55
|
+
await removeWorktree(ctx.directory ?? directory, target, {
|
|
56
|
+
force,
|
|
57
|
+
deleteBranch: !keepBranch,
|
|
58
|
+
signal: ctx.abort,
|
|
59
|
+
}),
|
|
60
|
+
),
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default { id: "opencode-gitwt", server: GitwtPlugin };
|