opencode-landstrip 0.18.21 → 0.18.23

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 (2) hide show
  1. package/index.ts +28 -1
  2. package/package.json +2 -2
package/index.ts CHANGED
@@ -73,6 +73,7 @@ type ToastVariant = 'info' | 'success' | 'warning' | 'error';
73
73
  const LANDSTRIP_VERSION = [0, 17, 0] as const;
74
74
  const REQUIRED_LANDSTRIP_VERSION = LANDSTRIP_VERSION.join('.');
75
75
  const SUPPORTED_PLATFORMS = new Set<NodeJS.Platform>(['linux', 'darwin', 'win32']);
76
+ const DISCOVERY_CONNECT_TIMEOUT_MS = 250;
76
77
 
77
78
  const prohibitedProxyAddresses = new BlockList();
78
79
 
@@ -874,6 +875,31 @@ function startTrapServer(
874
875
  });
875
876
  }
876
877
 
878
+ function trapPortAcceptsConnections(port: number): Promise<boolean> {
879
+ return new Promise((resolve) => {
880
+ const socket = connectNet({ host: '127.0.0.1', port });
881
+ let settled = false;
882
+ let timer: NodeJS.Timeout;
883
+ const finish = (ok: boolean): void => {
884
+ if (settled) return;
885
+ settled = true;
886
+ clearTimeout(timer);
887
+ socket.destroy();
888
+ resolve(ok);
889
+ };
890
+ timer = setTimeout(() => finish(false), DISCOVERY_CONNECT_TIMEOUT_MS);
891
+
892
+ socket.once('connect', () => finish(true));
893
+ socket.once('error', () => finish(false));
894
+ });
895
+ }
896
+
897
+ async function readLiveDiscoveryPort(baseDirectory: string): Promise<number | null> {
898
+ const port = readDiscoveryPort(baseDirectory);
899
+ if (port === null) return null;
900
+ return (await trapPortAcceptsConnections(port)) ? port : null;
901
+ }
902
+
877
903
  function buildWrappedCommand(
878
904
  policyPath: string,
879
905
  shell: string,
@@ -1366,7 +1392,8 @@ const plugin: Plugin = async ({ client, directory }: PluginInput, options?: Plug
1366
1392
 
1367
1393
  // The TUI owns interactive query handling. Fall back to an in-process
1368
1394
  // broker when no TUI endpoint is available (for example, in headless mode).
1369
- const tuiTrapPort = process.platform === 'linux' ? readDiscoveryPort(directory) : null;
1395
+ const tuiTrapPort =
1396
+ process.platform === 'linux' ? await readLiveDiscoveryPort(directory) : null;
1370
1397
  const trapServer =
1371
1398
  tuiTrapPort === null
1372
1399
  ? await startTrapServer(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-landstrip",
3
- "version": "0.18.21",
3
+ "version": "0.18.23",
4
4
  "description": "OS-level AI command sandboxing for OpenCode with Landstrip",
5
5
  "keywords": [
6
6
  "landlock",
@@ -48,7 +48,7 @@
48
48
  "ci:test": "npm test"
49
49
  },
50
50
  "dependencies": {
51
- "@landstrip/landstrip": "^0.18.21",
51
+ "@landstrip/landstrip": "^0.18.23",
52
52
  "@opentui/solid": ">=0.3.4",
53
53
  "solid-js": "1.9.12"
54
54
  },