opencode-add-dir 1.4.0 → 1.5.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/bin/ensure-tui.mjs +39 -0
- package/dist/index.js +3 -3
- package/dist/tui.tsx +3 -3
- package/package.json +4 -2
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs"
|
|
3
|
+
import { join } from "path"
|
|
4
|
+
import { homedir } from "os"
|
|
5
|
+
|
|
6
|
+
const PKG = "opencode-add-dir"
|
|
7
|
+
|
|
8
|
+
try {
|
|
9
|
+
const dir = join(
|
|
10
|
+
process.env.XDG_CONFIG_HOME || join(homedir(), ".config"),
|
|
11
|
+
"opencode",
|
|
12
|
+
)
|
|
13
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true })
|
|
14
|
+
|
|
15
|
+
let filePath = join(dir, "tui.json")
|
|
16
|
+
for (const name of ["tui.jsonc", "tui.json"]) {
|
|
17
|
+
const p = join(dir, name)
|
|
18
|
+
if (existsSync(p)) { filePath = p; break }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let config = {}
|
|
22
|
+
if (existsSync(filePath)) {
|
|
23
|
+
const raw = readFileSync(filePath, "utf-8")
|
|
24
|
+
config = JSON.parse(raw.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, ""))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const plugins = config.plugin || []
|
|
28
|
+
const has = plugins.some((p) => {
|
|
29
|
+
const name = Array.isArray(p) ? p[0] : p
|
|
30
|
+
return name === PKG || (typeof name === "string" && name.startsWith(PKG + "@"))
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
if (!has) {
|
|
34
|
+
config.plugin = [...plugins, PKG]
|
|
35
|
+
writeFileSync(filePath, JSON.stringify(config, null, 2) + "\n")
|
|
36
|
+
}
|
|
37
|
+
} catch {
|
|
38
|
+
// Non-critical — TUI dialog available after manual setup or restart
|
|
39
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -215,11 +215,11 @@ ${content}`);
|
|
|
215
215
|
|
|
216
216
|
// src/plugin.ts
|
|
217
217
|
var SENTINEL = Object.assign(new Error("__ADD_DIR_HANDLED__"), { stack: "" });
|
|
218
|
+
ensureTuiConfig();
|
|
218
219
|
var AddDirPlugin = async ({ client, worktree, directory }) => {
|
|
219
220
|
const root = worktree || directory;
|
|
220
221
|
const dirs = loadDirs();
|
|
221
222
|
const sdk = client;
|
|
222
|
-
ensureTuiConfig();
|
|
223
223
|
function add(dirPath, persist) {
|
|
224
224
|
const result = validateDir(dirPath, root, [...dirs.values()].map((d) => d.path));
|
|
225
225
|
if (!result.ok)
|
|
@@ -258,7 +258,7 @@ var AddDirPlugin = async ({ client, worktree, directory }) => {
|
|
|
258
258
|
notify(sdk, sessionID, result.message);
|
|
259
259
|
}
|
|
260
260
|
const commands = {
|
|
261
|
-
|
|
261
|
+
__adddir: (args, sid) => handleAdd(args, sid),
|
|
262
262
|
"list-dir": (_, sid) => notify(sdk, sid, list()),
|
|
263
263
|
"remove-dir": (args, sid) => notify(sdk, sid, remove(args))
|
|
264
264
|
};
|
|
@@ -266,7 +266,7 @@ var AddDirPlugin = async ({ client, worktree, directory }) => {
|
|
|
266
266
|
config: async (cfg) => {
|
|
267
267
|
cfg.command ??= {};
|
|
268
268
|
const cmd = cfg.command;
|
|
269
|
-
cmd["
|
|
269
|
+
cmd["__adddir"] = { template: "/__adddir", description: "Internal: add a working directory" };
|
|
270
270
|
cmd["list-dir"] = { template: "/list-dir", description: "List added working directories" };
|
|
271
271
|
cmd["remove-dir"] = { template: "/remove-dir", description: "Remove a working directory" };
|
|
272
272
|
if (!dirs.size)
|
package/dist/tui.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import type { TuiPlugin, TuiPluginApi, TuiPluginModule } from "@opencode-ai/plug
|
|
|
2
2
|
import { createSignal } from "solid-js"
|
|
3
3
|
|
|
4
4
|
const PLUGIN_ID = "opencode-add-dir"
|
|
5
|
-
const
|
|
5
|
+
const INTERNAL_COMMAND = "__adddir"
|
|
6
6
|
|
|
7
7
|
function activeSessionID(api: TuiPluginApi): string | undefined {
|
|
8
8
|
const route = api.route.current
|
|
@@ -33,7 +33,7 @@ async function executeAddDir(api: TuiPluginApi, dirPath: string) {
|
|
|
33
33
|
// prevent the command template from reaching the LLM. This rejection is expected.
|
|
34
34
|
api.client.session.command({
|
|
35
35
|
sessionID,
|
|
36
|
-
command:
|
|
36
|
+
command: INTERNAL_COMMAND,
|
|
37
37
|
arguments: dirPath,
|
|
38
38
|
}).catch(() => {})
|
|
39
39
|
}
|
|
@@ -96,7 +96,7 @@ const tui: TuiPlugin = async (api) => {
|
|
|
96
96
|
value: "add-dir.dialog",
|
|
97
97
|
description: "Add a working directory to the session",
|
|
98
98
|
category: "Directories",
|
|
99
|
-
slash: { name:
|
|
99
|
+
slash: { name: "add-dir" },
|
|
100
100
|
onSelect: () => showDialog(api),
|
|
101
101
|
},
|
|
102
102
|
])
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-add-dir",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Add working directories to your OpenCode session with auto-approved permissions",
|
|
5
5
|
"author": "Cristian Fonseca <cfonsecacomas@gmail.com>",
|
|
6
6
|
"type": "module",
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"dist/",
|
|
30
|
-
"bin/",
|
|
30
|
+
"bin/ensure-tui.mjs",
|
|
31
|
+
"bin/setup.mjs",
|
|
31
32
|
"README.md",
|
|
32
33
|
"LICENSE"
|
|
33
34
|
],
|
|
@@ -35,6 +36,7 @@
|
|
|
35
36
|
"build": "bun run build:server && bun run build:tui && bun x tsc --emitDeclarationOnly",
|
|
36
37
|
"build:server": "bun build ./src/index.ts --outdir ./dist --target node --format esm --external @opencode-ai/plugin",
|
|
37
38
|
"build:tui": "cp ./src/tui-plugin.tsx ./dist/tui.tsx",
|
|
39
|
+
"postinstall": "node ./bin/ensure-tui.mjs",
|
|
38
40
|
"deploy": "bun run build:server && bun run build:tui",
|
|
39
41
|
"test": "bun test",
|
|
40
42
|
"typecheck": "bun x tsc --noEmit",
|