@frontendxlab/opencode-computer-use 0.1.2 → 0.1.4

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/README.md CHANGED
@@ -111,8 +111,25 @@ npx opencode-computer-use-setup --global --v1
111
111
  ```
112
112
 
113
113
  Use `--dry-run` to inspect the action without changing files. Set
114
- `OPENCODE_COMPUTER_USE_SKIP_SETUP=1` to disable the postinstall hook. Restart
115
- OpenCode after a successful setup so the plugin is loaded.
114
+ `OPENCODE_COMPUTER_USE_SKIP_SETUP=1` to disable the postinstall hook. Setup also
115
+ skips automatically when `CI=1` or `CI=true`. Restart OpenCode after a
116
+ successful setup so the plugin is loaded.
117
+
118
+ The postinstall flow also runs the native permission check. To rerun it later:
119
+
120
+ ```sh
121
+ npx opencode-computer-use-permissions
122
+ # or, from a pnpm project
123
+ pnpm exec opencode-computer-use-permissions
124
+ ```
125
+
126
+ The command delegates to the native `open-computer-use doctor` flow. macOS runs
127
+ the native Accessibility and Screen Recording onboarding when needed. Linux
128
+ reports AT-SPI and desktop-session requirements. Windows reports UI Automation
129
+ and interactive-session requirements. The command never changes permissions
130
+ automatically. Use `--strict` when a missing or failed native
131
+ check should return a nonzero exit status, or set
132
+ `OPENCODE_COMPUTER_USE_SKIP_PERMISSIONS=1` to skip it.
116
133
 
117
134
  Recent pnpm releases may require explicit approval before running lifecycle
118
135
  scripts from dependencies. If pnpm reports `ERR_PNPM_IGNORED_BUILDS`, approve
package/SECURITY.md CHANGED
@@ -26,7 +26,10 @@ sandbox.
26
26
  - The postinstall setup only adds this package to OpenCode's plugin list, keeps
27
27
  JSONC comments, creates a `.bak` before replacement, and never edits a
28
28
  conflicting or malformed configuration. Ambiguous setup is non-destructive
29
- and prints manual instructions.
29
+ and prints manual instructions. CI and explicit skip environments bypass
30
+ postinstall mutation.
31
+ - The permission command delegates to the native runtime's `doctor` flow. It
32
+ may open macOS onboarding, but it never grants or changes permissions.
30
33
 
31
34
  ## Operator responsibilities
32
35
 
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawnSync } from "node:child_process";
4
+ import { realpathSync } from "node:fs";
5
+ import { dirname, resolve } from "node:path";
6
+ import process from "node:process";
7
+ import { fileURLToPath } from "node:url";
8
+ import { backendEnvironment, resolveBackend } from "../lib/backend.js";
9
+
10
+ const SKIP_ENV = "OPENCODE_COMPUTER_USE_SKIP_PERMISSIONS";
11
+ const PACKAGE_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
12
+
13
+ function print(text, stream = "stdout") {
14
+ process[stream].write(`${text}\n`);
15
+ }
16
+
17
+ export function usage() {
18
+ return `Usage: opencode-computer-use-permissions [options]
19
+
20
+ Run the native Open Computer Use permission and runtime onboarding check.
21
+
22
+ Options:
23
+ --strict Return a failure when the native check cannot run
24
+ --help, -h Show this help
25
+
26
+ The command uses the installed open-computer-use runtime:
27
+ macOS checks or launches Accessibility and Screen Recording onboarding
28
+ Linux reports AT-SPI and signed-in desktop-session requirements
29
+ Windows reports UI Automation and interactive-session requirements
30
+ `;
31
+ }
32
+
33
+ function parseArguments(argv) {
34
+ const options = { strict: false, help: false };
35
+ for (const argument of argv) {
36
+ if (argument === "--strict") options.strict = true;
37
+ else if (argument === "--help" || argument === "-h") options.help = true;
38
+ else throw new Error(`Unknown permission option: ${argument}`);
39
+ }
40
+ return options;
41
+ }
42
+
43
+ function shouldSkip(env) {
44
+ const developmentInstall = env.npm_lifecycle_event === "postinstall"
45
+ && env.INIT_CWD
46
+ && resolve(env.INIT_CWD) === PACKAGE_ROOT;
47
+ return developmentInstall || env.CI === "true" || env.CI === "1" || env[SKIP_ENV] === "1";
48
+ }
49
+
50
+ export function main(argv = process.argv.slice(2), env = process.env, io = print) {
51
+ let options;
52
+ try {
53
+ options = parseArguments(argv);
54
+ } catch (error) {
55
+ io(`[opencode-computer-use-permissions] ${error instanceof Error ? error.message : String(error)}`, "stderr");
56
+ io(usage(), "stderr");
57
+ return 2;
58
+ }
59
+ if (options.help) {
60
+ io(usage());
61
+ return 0;
62
+ }
63
+ if (shouldSkip(env)) {
64
+ io("OpenCode Computer Use permission onboarding skipped.");
65
+ return 0;
66
+ }
67
+
68
+ let backend;
69
+ try {
70
+ backend = resolveBackend({ backend: "native" }, env);
71
+ } catch (error) {
72
+ const message = error instanceof Error ? error.message : String(error);
73
+ io(`[opencode-computer-use-permissions] Native permission check unavailable: ${message}`);
74
+ if (options.strict) return 1;
75
+ io("Install the optional open-computer-use runtime, then run this command again.");
76
+ return 0;
77
+ }
78
+
79
+ const result = spawnSync(backend.command, ["doctor"], {
80
+ env: backendEnvironment(env),
81
+ stdio: "inherit",
82
+ windowsHide: false,
83
+ timeout: 120_000,
84
+ });
85
+ if (result.error) {
86
+ io(`[opencode-computer-use-permissions] Permission check failed: ${result.error.message}`);
87
+ return options.strict ? 1 : 0;
88
+ }
89
+ if (result.status !== 0) {
90
+ io(`[opencode-computer-use-permissions] Native permission check exited with status ${result.status}.`);
91
+ return options.strict ? 1 : 0;
92
+ }
93
+ return 0;
94
+ }
95
+
96
+ function sameFile(left, right) {
97
+ try {
98
+ return realpathSync(left) === realpathSync(right);
99
+ } catch {
100
+ return resolve(left) === resolve(right);
101
+ }
102
+ }
103
+
104
+ const invokedPath = process.argv[1] ? resolve(process.argv[1]) : "";
105
+ const scriptPath = fileURLToPath(import.meta.url);
106
+ if (invokedPath && sameFile(invokedPath, scriptPath)) {
107
+ process.exitCode = main();
108
+ }
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { copyFileSync, existsSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
3
+ import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
4
+ import { randomUUID } from "node:crypto";
4
5
  import { homedir } from "node:os";
5
6
  import { delimiter, dirname, join, resolve } from "node:path";
6
7
  import { spawnSync } from "node:child_process";
@@ -189,6 +190,7 @@ function configFlavor(text) {
189
190
  }
190
191
 
191
192
  function existingConfigFiles(root, scope, env = process.env) {
193
+ if (env.OPENCODE_CONFIG) return [resolve(env.OPENCODE_CONFIG)];
192
194
  const bases = scope === "global"
193
195
  ? [globalConfigDir(env)]
194
196
  : [root, join(root, ".opencode")];
@@ -290,15 +292,29 @@ export function updateConfigText(text, flavor) {
290
292
  function writeConfig(file, content, dryRun) {
291
293
  if (dryRun) return;
292
294
  mkdirSync(dirname(file), { recursive: true });
295
+ const mode = existsSync(file) ? statSync(file).mode & 0o777 : 0o600;
293
296
  if (existsSync(file)) {
294
- copyFileSync(file, `${file}.bak`);
297
+ const backup = `${file}.bak`;
298
+ copyFileSync(file, backup);
299
+ chmodSync(backup, mode);
295
300
  }
296
- const temporary = `${file}.tmp-${process.pid}`;
297
- writeFileSync(temporary, content, "utf8");
301
+ const temporary = `${file}.tmp-${process.pid}-${randomUUID()}`;
302
+ writeFileSync(temporary, content, { encoding: "utf8", mode, flag: "wx" });
303
+ chmodSync(temporary, mode);
298
304
  if (process.platform === "win32" && existsSync(file)) rmSync(file, { force: true });
299
305
  renameSync(temporary, file);
300
306
  }
301
307
 
308
+ function validateConfigFiles(root, scope, env) {
309
+ for (const file of existingConfigFiles(root, scope, env)) {
310
+ const text = readFileSync(file, "utf8");
311
+ const data = parse(text);
312
+ if (text.trim() && (data === undefined || data === null || typeof data !== "object" || Array.isArray(data))) {
313
+ throw new Error(`configuration is not valid JSON or JSONC: ${file}`);
314
+ }
315
+ }
316
+ }
317
+
302
318
  function packageAlreadyConfigured(root, scope, env) {
303
319
  for (const file of existingConfigFiles(root, scope, env)) {
304
320
  try {
@@ -312,6 +328,12 @@ function packageAlreadyConfigured(root, scope, env) {
312
328
  return undefined;
313
329
  }
314
330
 
331
+ function redactMessage(value) {
332
+ return String(value)
333
+ .replace(/\b(token|secret|password|api[_-]?key|authorization)\s*[:=]\s*(?:bearer|basic)?[^\n\r,;]*/giu, "$1=[redacted]")
334
+ .slice(0, 500);
335
+ }
336
+
315
337
  function runPluginCli(flavor, scope, root, env) {
316
338
  const command = flavor === "v1" ? "opencode" : "opencode2";
317
339
  const args = ["plugin", "add", PACKAGE_NAME];
@@ -325,7 +347,7 @@ function runPluginCli(flavor, scope, root, env) {
325
347
  timeout: 120_000,
326
348
  });
327
349
  if (result.error || result.status !== 0) {
328
- const detail = `${result.stdout || ""}${result.stderr || ""}`.trim().slice(0, 500);
350
+ const detail = redactMessage(`${result.stdout || ""}${result.stderr || ""}`.trim());
329
351
  throw new Error(`${command} plugin add failed${detail ? `: ${detail}` : ""}`);
330
352
  }
331
353
  }
@@ -388,12 +410,16 @@ export async function setup(options = {}, env = process.env, io = print) {
388
410
  const requestedFlavor = options.flavor || "auto";
389
411
  const scope = inferScope(requestedScope, env);
390
412
  const root = chooseRoot(scope, env);
413
+ if (env.OPENCODE_CONFIG_CONTENT) {
414
+ throw new Error("OPENCODE_CONFIG_CONTENT is immutable; add the plugin to that configuration manually");
415
+ }
391
416
  const detection = detectOpenCode(env);
392
417
  const config = detectConfigFlavor(root, scope, env);
393
418
  const flavor = chooseFlavor(requestedFlavor, detection, config);
394
419
  const dryRun = Boolean(options.dryRun);
395
420
  let result;
396
421
  if (scope === "global" && !dryRun) {
422
+ validateConfigFiles(root, scope, env);
397
423
  const existing = packageAlreadyConfigured(root, scope, env);
398
424
  if (existing) {
399
425
  result = { file: existing, changed: false };
@@ -406,9 +432,10 @@ export async function setup(options = {}, env = process.env, io = print) {
406
432
  } else {
407
433
  result = configForSetup(root, scope, flavor, env, dryRun);
408
434
  }
409
- io(
410
- `OpenCode Computer Use setup ${result.changed ? "configured" : "already configured"} for ${flavor.toUpperCase()} (${scope}).`,
411
- );
435
+ const action = options.dryRun
436
+ ? (result.changed ? "would configure" : "already configured")
437
+ : (result.changed ? "configured" : "already configured");
438
+ io(`OpenCode Computer Use setup ${action} for ${flavor.toUpperCase()} (${scope}).`);
412
439
  if (result.changed) io(`Configuration: ${result.file}`);
413
440
  return { ...result, scope, flavor, detection };
414
441
  }
@@ -423,14 +450,6 @@ function isDevelopmentInstall(env) {
423
450
  }
424
451
 
425
452
  export async function main(argv = process.argv.slice(2), env = process.env, io = print) {
426
- if (isDevelopmentInstall(env)) {
427
- io("OpenCode Computer Use setup skipped for a package-development install.");
428
- return 0;
429
- }
430
- if (env.OPENCODE_COMPUTER_USE_SKIP_SETUP === "1") {
431
- io("OpenCode Computer Use setup skipped by OPENCODE_COMPUTER_USE_SKIP_SETUP.");
432
- return 0;
433
- }
434
453
  let options;
435
454
  try {
436
455
  options = parseArguments(argv);
@@ -443,6 +462,18 @@ export async function main(argv = process.argv.slice(2), env = process.env, io =
443
462
  printHelp();
444
463
  return 0;
445
464
  }
465
+ if (env.CI === "true" || env.CI === "1") {
466
+ io("OpenCode Computer Use setup skipped in CI.");
467
+ return 0;
468
+ }
469
+ if (isDevelopmentInstall(env)) {
470
+ io("OpenCode Computer Use setup skipped for a package-development install.");
471
+ return 0;
472
+ }
473
+ if (env.OPENCODE_COMPUTER_USE_SKIP_SETUP === "1") {
474
+ io("OpenCode Computer Use setup skipped by OPENCODE_COMPUTER_USE_SKIP_SETUP.");
475
+ return 0;
476
+ }
446
477
  return setup(options, env, io)
447
478
  .then(() => 0)
448
479
  .catch((error) => {
package/docs/index.html CHANGED
@@ -459,7 +459,8 @@ npm install</code></pre><button class="copy" type="button" data-copy="#clone">Co
459
459
  <div class="code"><pre><code id="npm-install">npm install @frontendxlab/opencode-computer-use
460
460
  # pnpm install @frontendxlab/opencode-computer-use also works</code></pre><button class="copy" type="button" data-copy="#npm-install">Copy</button></div>
461
461
  <p>The package postinstall step detects OpenCode 1 versus OpenCode2 and local versus global installation. It edits JSONC without discarding comments, avoids duplicate entries, and prints both manual formats when the choice is ambiguous. Run it explicitly with <code>npx opencode-computer-use-setup</code>, or add <code>--local</code>, <code>--global</code>, <code>--v1</code>, or <code>--v2</code> when you want to choose explicitly.</p>
462
- <p>Recent pnpm releases can require explicit lifecycle-script approval. If pnpm reports <code>ERR_PNPM_IGNORED_BUILDS</code>, run <code>pnpm approve-builds @frontendxlab/opencode-computer-use</code> once, then rerun <code>pnpm install</code>. If scripts are disabled, run <code>pnpm exec opencode-computer-use-setup</code> manually.</p>
462
+ <p>Recent pnpm releases can require explicit lifecycle-script approval. If pnpm reports <code>ERR_PNPM_IGNORED_BUILDS</code>, run <code>pnpm approve-builds @frontendxlab/opencode-computer-use</code> once, then rerun <code>pnpm install</code>. If scripts are disabled, run <code>pnpm exec opencode-computer-use-setup</code> manually. CI environments skip setup automatically.</p>
463
+ <p>The postinstall flow also runs the native <code>open-computer-use doctor</code> permission check. To rerun it, use <code>npx opencode-computer-use-permissions</code> or <code>pnpm exec opencode-computer-use-permissions</code>. macOS can launch Accessibility and Screen Recording onboarding, Linux reports AT-SPI requirements, and Windows reports UI Automation requirements. Permissions are never changed automatically.</p>
463
464
  <div class="tabs" role="tablist" aria-label="OpenCode generation">
464
465
  <button role="tab" id="tab-v1" aria-controls="panel-v1" aria-selected="true">OpenCode 1</button>
465
466
  <button role="tab" id="tab-v2" aria-controls="panel-v2" aria-selected="false" tabindex="-1">OpenCode2</button>
@@ -626,7 +627,8 @@ nodeRepl.write(state);</code></pre><button class="copy" type="button" data-copy=
626
627
  <h2>When the session is quiet.</h2>
627
628
  <details><summary><code>cua_repl</code> is not listed</summary><p>Check that the plugin path is in the active OpenCode generation's configuration, restart the TUI, and run <code>opencode mcp list</code>. Do not register the same plugin and MCP server twice.</p></details>
628
629
  <details><summary>Node cannot be found</summary><p>Set <code>OPENCODE_NODE</code> to an absolute Node executable before starting OpenCode, or make <code>node</code> available on the server PATH.</p></details>
629
- <details><summary>The app list is empty</summary><p>Run <code>open-computer-use list-apps</code> in the same graphical session. Confirm the app is already running and that the desktop accessibility session is available.</p></details>
630
+ <details><summary>Permission onboarding needs to be rerun</summary><p>Run <code>opencode-computer-use-permissions</code>. On macOS it can reopen Accessibility and Screen Recording onboarding; Linux and Windows print the relevant runtime requirements.</p></details>
631
+ <details><summary>The app list is empty</summary><p>Run <code>open-computer-use-permissions</code>, then <code>open-computer-use list-apps</code> in the same graphical session. Confirm the app is already running and that the desktop accessibility session is available.</p></details>
630
632
  <details><summary>Screenshots are unavailable</summary><p>Screen capture depends on the OS compositor and permissions. The plugin can still provide bounded accessibility text when capture is unavailable.</p></details>
631
633
  <details><summary>Linux input returns success but nothing changes</summary><p>Check the desktop session type and native runtime prerequisites. A pseudo-window or Wayland compositor can expose state without accepting synthetic input. Observe again before retrying a mutating action.</p></details>
632
634
  <details><summary>Global pointer fallback is rejected</summary><p>This is the expected safety gate. Enable <code>allowGlobalPointerFallbacks</code> only for an explicit diagnostic session where moving the real pointer and changing focus are acceptable.</p></details>
@@ -90,7 +90,11 @@ manual instructions. Run it explicitly with npx opencode-computer-use-setup;
90
90
  use --local, --global, --v1, or --v2 to choose explicitly. If pnpm reports
91
91
  ERR_PNPM_IGNORED_BUILDS, approve the package once with pnpm approve-builds
92
92
  @frontendxlab/opencode-computer-use, or run pnpm exec
93
- opencode-computer-use-setup manually.
93
+ opencode-computer-use-setup manually. CI environments skip setup. The
94
+ postinstall flow also runs the native permission check. Rerun it with
95
+ npx opencode-computer-use-permissions or pnpm exec
96
+ opencode-computer-use-permissions. macOS can launch onboarding, Linux reports
97
+ AT-SPI requirements, and Windows reports UI Automation requirements.
94
98
  OpenCode 1 (opencode.json or opencode.jsonc, plugin list):
95
99
  { "$schema": "https://opencode.ai/config.json",
96
100
  "plugin": [["@frontendxlab/opencode-computer-use", { "backend": "auto" }]] }
package/docs/llms.txt CHANGED
@@ -27,6 +27,6 @@
27
27
  - Safety profiles: safetyMode=read-only blocks mutating CUA methods and changes js annotations; appAccess supports exact-name and ID allow/deny rules.
28
28
  - Reliability: app bindings and output are bounded; native timeouts send cancellation; shutdown sends a best-effort turn-ended notification.
29
29
  - No arbitrary shell escape. No run_shell in the model-facing API. Restricted VM blocks require, process, fetch, filesystem, dynamic import, and code generation.
30
- - Published package: @frontendxlab/opencode-computer-use. Its postinstall setup detects OpenCode generation and local/global scope, preserves JSONC, and prints manual instructions when ambiguous. Explicit setup: npx opencode-computer-use-setup --local|--global --v1|--v2.
30
+ - Published package: @frontendxlab/opencode-computer-use. Its postinstall setup detects OpenCode generation and local/global scope, preserves JSONC, and prints manual instructions when ambiguous. Explicit setup: npx opencode-computer-use-setup --local|--global --v1|--v2. Permission onboarding rerun: npx opencode-computer-use-permissions.
31
31
  - Requirements: Node.js 18 or newer, OpenCode 1.18.29 or newer (V1) or OpenCode2 V2, plus a signed-in graphical desktop session with OS accessibility and capture permissions.
32
32
  - Native runtimes packaged for darwin-arm64, darwin-x64, linux-arm64, linux-x64, win32-arm64, win32-x64. Live smoke tests passed on Linux x64 only; macOS and Windows need on-host validation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontendxlab/opencode-computer-use",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "A dual OpenCode and OpenCode2 plugin for local cross-platform desktop control.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -29,7 +29,8 @@
29
29
  },
30
30
  "bin": {
31
31
  "opencode-computer-use-repl": "bin/opencode-computer-use-repl.js",
32
- "opencode-computer-use-setup": "bin/opencode-computer-use-setup.js"
32
+ "opencode-computer-use-setup": "bin/opencode-computer-use-setup.js",
33
+ "opencode-computer-use-permissions": "bin/opencode-computer-use-permissions.js"
33
34
  },
34
35
  "files": [
35
36
  "bin/",
@@ -46,10 +47,10 @@
46
47
  "opencode": ">=0.0.0-beta-18684"
47
48
  },
48
49
  "scripts": {
49
- "postinstall": "node bin/opencode-computer-use-setup.js --auto",
50
- "lint": "node --check index.js && node --check bin/opencode-computer-use-repl.js && node --check bin/opencode-computer-use-setup.js && node --check lib/backend.js && node --check lib/json-line-peer.mjs && node --check lib/options.js && node --check lib/output.mjs && node --check lib/repl.mjs && node --check lib/repl-kernel.mjs && node --check lib/sandbox.mjs",
50
+ "postinstall": "node bin/opencode-computer-use-setup.js --auto && node bin/opencode-computer-use-permissions.js",
51
+ "lint": "node --check index.js && node --check bin/opencode-computer-use-repl.js && node --check bin/opencode-computer-use-setup.js && node --check bin/opencode-computer-use-permissions.js && node --check lib/backend.js && node --check lib/json-line-peer.mjs && node --check lib/options.js && node --check lib/output.mjs && node --check lib/repl.mjs && node --check lib/repl-kernel.mjs && node --check lib/sandbox.mjs",
51
52
  "test": "node --test",
52
- "prepack": "node --check index.js && node --check bin/opencode-computer-use-repl.js && node --check bin/opencode-computer-use-setup.js && node -e \"JSON.parse(require('fs').readFileSync('package.json','utf8'))\"",
53
+ "prepack": "node --check index.js && node --check bin/opencode-computer-use-repl.js && node --check bin/opencode-computer-use-setup.js && node --check bin/opencode-computer-use-permissions.js && node -e \"JSON.parse(require('fs').readFileSync('package.json','utf8'))\"",
53
54
  "prepublishOnly": "npm run lint && npm test"
54
55
  },
55
56
  "optionalDependencies": {