Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/calm-trains-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@calycode/cli': patch
---

chore: Improved OpenCode native host stability and setup across Chromium browsers.

- Added safer OpenCode version control with a pinned default and optional override.
- Improved native host setup and extension discovery behavior for Chromium-based browsers.
- Added support for passing OpenCode version from native host message payloads.
23 changes: 22 additions & 1 deletion docs/commands/oc-init.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,25 @@ Options:

Run 'caly-xano <command> --help' for detailed usage.
https://github.com/calycode/xano-tools | https://links.calycode.com/discord
```
```

### Build-time and runtime configuration

The native host extension discovery uses this precedence order:
1. runtime `CALY_OC_*` variables
2. build-time pinned `CALY_BUILD_OC_*` variables (embedded at build)
3. repository defaults

Set these **before build** to bake defaults into the CLI/binary:
- `CALY_BUILD_OC_EXT_DISCOVERY_MODE`
- `CALY_BUILD_OC_EXT_NAME`
- `CALY_BUILD_OC_EXT_TRUSTED_AUTHORS`
- `CALY_BUILD_OC_EXT_TRUSTED_HOMEPAGES`
- `CALY_BUILD_OC_EXT_TRUSTED_UPDATE_URLS`
- `CALY_BUILD_OC_EXT_REQUIRE_NATIVE_MESSAGING`
- `CALY_BUILD_OC_EXT_PUBLIC_KEY_B64`
- `CALY_BUILD_OC_EXT_DISCOVERY_ENABLED`
- `CALY_BUILD_OC_EXT_INCLUDE_KNOWN_IDS`
- `CALY_BUILD_OC_WRITE_ALL_BROWSER_MANIFESTS`

At runtime, use the same variable names with `CALY_OC_` prefix to override baked defaults.
35 changes: 33 additions & 2 deletions docs/commands/oc-native-host.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,39 @@ Options:
└─ -h, --help display help for command

Commands:
└─ status Show native host manifest, wrapper, and extension allowli...
├─ status Show native host manifest, wrapper, and extension allowlist status.
└─ help display help for command
```

### oc native-host status
```term
$ caly-xano oc native-host status
Native Host Status:
- Platform: win32
- Wrapper Path: C:\Users\<user>\.calycode\bin\calycode-host.bat
- Wrapper Exists: Yes
- App ID: com.calycode.cli
- Extension ID Source: discovery:balanced+known
- Chrome Manifest: C:\Users\<user>\.calycode\com.calycode.cli.json
- Chrome Manifest Exists: Yes
- Brave Manifest: C:\Users\<user>\.calycode\com.calycode.cli.json
- Brave Manifest Exists: Yes
- Edge Manifest: C:\Users\<user>\.calycode\com.calycode.cli.json
- Edge Manifest Exists: Yes
- Chromium Manifest: C:\Users\<user>\.calycode\com.calycode.cli.json
- Chromium Manifest Exists: Yes
- Chrome Registry Key: HKEY_CURRENT_USER\Software\Google\Chrome\NativeMessagingHosts\com.calycode.cli
- Chrome Registry Configured: Yes
- Brave Registry Key: HKEY_CURRENT_USER\Software\BraveSoftware\Brave-Browser\NativeMessagingHosts\com.calycode.cli
- Brave Registry Configured: Yes
- Edge Registry Key: HKEY_CURRENT_USER\Software\Microsoft\Edge\NativeMessagingHosts\com.calycode.cli
- Edge Registry Configured: Yes
- Chromium Registry Key: HKEY_CURRENT_USER\Software\Chromium\NativeMessagingHosts\com.calycode.cli
- Chromium Registry Configured: Yes
- Expected Extension IDs: hadkkdmpcmllbkfopioopcmeapjchpbm, lnhipaeaeiegnlokhokfokndgadkohfe
- Expected Origins: chrome-extension://hadkkdmpcmllbkfopioopcmeapjchpbm/, chrome-extension://lnhipaeaeiegnlokhokfokndgadkohfe/
- Manifest Allowed Origins: chrome-extension://hadkkdmpcmllbkfopioopcmeapjchpbm/, chrome-extension://lnhipaeaeiegnlokhokfokndgadkohfe/
```

Run 'caly-xano <command> --help' for detailed usage.
https://github.com/calycode/xano-tools | https://links.calycode.com/discord
```
19 changes: 19 additions & 0 deletions packages/cli/esbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
const rootDir = resolve(__dirname);
const distDir = resolve(__dirname, 'dist');

function defineEnvValue(name: string): string {
const value = process.env[name];
return value === undefined ? JSON.stringify('') : JSON.stringify(value);
}
Comment on lines +10 to +13
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check how discovery.ts handles potentially 'undefined' string values

rg -n -A5 -B2 'BUILD_OC_DEFAULTS\.' packages/cli/src/commands/opencode/native-host/discovery.ts

Repository: calycode/xano-tools

Length of output: 2742


🏁 Script executed:

#!/bin/bash
# Get context around defineEnvValue function
cat -n packages/cli/esbuild.config.ts | head -30

Repository: calycode/xano-tools

Length of output: 1921


🏁 Script executed:

#!/bin/bash
# Find resolveEnvWithBuildFallback and related helpers
rg -n "resolveEnvWithBuildFallback|parseListEnvWithBuildFallback|parseBooleanEnvWithBuildFallback|defineEnvValue" packages/cli/src/commands/opencode/native-host/discovery.ts | head -20

Repository: calycode/xano-tools

Length of output: 976


🏁 Script executed:

#!/bin/bash
# Find where defineEnvValue is defined and used
rg -n "defineEnvValue" packages/cli/

Repository: calycode/xano-tools

Length of output: 1563


🏁 Script executed:

#!/bin/bash
# Get resolveEnvWithBuildFallback implementation
sed -n '88,100p' packages/cli/src/commands/opencode/native-host/discovery.ts

Repository: calycode/xano-tools

Length of output: 399


🏁 Script executed:

#!/bin/bash
# Find BUILD_OC_DEFAULTS definition
rg -n "BUILD_OC_DEFAULTS\s*=" packages/cli/src/commands/opencode/native-host/discovery.ts -A 20

Repository: calycode/xano-tools

Length of output: 1020


🏁 Script executed:

#!/bin/bash
# Get parseBooleanEnvWithBuildFallback and parseListEnvWithBuildFallback implementations
sed -n '102,125p' packages/cli/src/commands/opencode/native-host/discovery.ts

Repository: calycode/xano-tools

Length of output: 721


🏁 Script executed:

#!/bin/bash
# Check if string 'undefined' is handled specially anywhere in discovery.ts
rg -n "'undefined'|\"undefined\"" packages/cli/src/commands/opencode/native-host/discovery.ts

Repository: calycode/xano-tools

Length of output: 45


🏁 Script executed:

#!/bin/bash
# Find parseBooleanEnv and parseListEnv functions
rg -n "function parseBooleanEnv|function parseListEnv" packages/cli/src/commands/opencode/native-host/discovery.ts -A 10

Repository: calycode/xano-tools

Length of output: 1599


🏁 Script executed:

#!/bin/bash
# Check imports to see if these parsing functions come from elsewhere
head -30 packages/cli/src/commands/opencode/native-host/discovery.ts

Repository: calycode/xano-tools

Length of output: 1213


🏁 Script executed:

#!/bin/bash
# See how parseListEnvWithBuildFallback results are used - specifically the trusted* patterns
sed -n '168,190p' packages/cli/src/commands/opencode/native-host/discovery.ts

Repository: calycode/xano-tools

Length of output: 967


🏁 Script executed:

#!/bin/bash
# Check if there are any filters for 'undefined' string value anywhere
rg -n "isValidExtensionId|filter|Boolean" packages/cli/src/commands/opencode/native-host/discovery.ts | head -20

Repository: calycode/xano-tools

Length of output: 1131


Fix defineEnvValue to properly indicate missing environment variables.

The function returns the string 'undefined' when an environment variable is missing, but downstream parsing functions treat non-empty strings as valid values. This causes parseListEnv('undefined') to return ['undefined'] and resolveEnvWithBuildFallback to return the string 'undefined' instead of undefined, bypassing intended fallbacks.

Return an empty string '' instead of 'undefined' when a variable is missing. This allows existing parsing functions to correctly treat it as absent.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/cli/esbuild.config.ts` around lines 10 - 13, The defineEnvValue
helper returns the literal string 'undefined' when process.env[name] is missing;
change it so missing env vars are emitted as an empty string so downstream
parsers treat them as absent—update defineEnvValue(name: string) to return
JSON.stringify(value) when present and JSON.stringify('') (i.e., an empty
string) when value === undefined; this fixes parseListEnv('undefined') and
resolveEnvWithBuildFallback returning the string 'undefined' by ensuring they
receive an empty value instead.


const buildEnvDefines: Record<string, string> = {
'process.env.CALY_BUILD_OC_EXT_DISCOVERY_MODE': defineEnvValue('CALY_BUILD_OC_EXT_DISCOVERY_MODE'),
'process.env.CALY_BUILD_OC_EXT_NAME': defineEnvValue('CALY_BUILD_OC_EXT_NAME'),
'process.env.CALY_BUILD_OC_EXT_TRUSTED_AUTHORS': defineEnvValue('CALY_BUILD_OC_EXT_TRUSTED_AUTHORS'),
'process.env.CALY_BUILD_OC_EXT_TRUSTED_HOMEPAGES': defineEnvValue('CALY_BUILD_OC_EXT_TRUSTED_HOMEPAGES'),
'process.env.CALY_BUILD_OC_EXT_TRUSTED_UPDATE_URLS': defineEnvValue('CALY_BUILD_OC_EXT_TRUSTED_UPDATE_URLS'),
'process.env.CALY_BUILD_OC_EXT_REQUIRE_NATIVE_MESSAGING': defineEnvValue('CALY_BUILD_OC_EXT_REQUIRE_NATIVE_MESSAGING'),
'process.env.CALY_BUILD_OC_EXT_PUBLIC_KEY_B64': defineEnvValue('CALY_BUILD_OC_EXT_PUBLIC_KEY_B64'),
'process.env.CALY_BUILD_OC_EXT_DISCOVERY_ENABLED': defineEnvValue('CALY_BUILD_OC_EXT_DISCOVERY_ENABLED'),
'process.env.CALY_BUILD_OC_EXT_INCLUDE_KNOWN_IDS': defineEnvValue('CALY_BUILD_OC_EXT_INCLUDE_KNOWN_IDS'),
'process.env.CALY_BUILD_OC_WRITE_ALL_BROWSER_MANIFESTS': defineEnvValue('CALY_BUILD_OC_WRITE_ALL_BROWSER_MANIFESTS'),
};

(async () => {
try {
// Copy github actions
Expand All @@ -22,6 +40,7 @@ const distDir = resolve(__dirname, 'dist');
},
bundle: true,
platform: 'node',
define: buildEnvDefines,
plugins: [],
target: 'node20',
format: 'cjs',
Expand Down
Loading