opencode-pilot 0.9.3 → 0.10.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/README.md +1 -0
- package/examples/config.yaml +5 -0
- package/package.json +1 -1
- package/service/actions.js +26 -5
- package/service/repo-config.js +9 -0
package/README.md
CHANGED
|
@@ -45,6 +45,7 @@ See [examples/config.yaml](examples/config.yaml) for a complete example with all
|
|
|
45
45
|
|
|
46
46
|
### Key Sections
|
|
47
47
|
|
|
48
|
+
- **`server_port`** - Preferred OpenCode server port (e.g., `4096`). When multiple OpenCode instances are running, pilot attaches sessions to this port.
|
|
48
49
|
- **`defaults`** - Default values applied to all sources
|
|
49
50
|
- **`sources`** - What to poll (presets, shorthand, or full config)
|
|
50
51
|
- **`tools`** - Field mappings to normalize different MCP APIs
|
package/examples/config.yaml
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# Example config.yaml for opencode-pilot
|
|
2
2
|
# Copy to ~/.config/opencode-pilot/config.yaml
|
|
3
3
|
|
|
4
|
+
# Preferred OpenCode server port for attaching sessions
|
|
5
|
+
# When multiple OpenCode instances are running, pilot will attach new sessions
|
|
6
|
+
# to this port. If not set, pilot discovers servers automatically.
|
|
7
|
+
# server_port: 4096
|
|
8
|
+
|
|
4
9
|
defaults:
|
|
5
10
|
agent: plan
|
|
6
11
|
prompt: default
|
package/package.json
CHANGED
package/service/actions.js
CHANGED
|
@@ -9,6 +9,7 @@ import { spawn, execSync } from "child_process";
|
|
|
9
9
|
import { readFileSync, existsSync } from "fs";
|
|
10
10
|
import { debug } from "./logger.js";
|
|
11
11
|
import { getNestedValue } from "./utils.js";
|
|
12
|
+
import { getServerPort } from "./repo-config.js";
|
|
12
13
|
import path from "path";
|
|
13
14
|
import os from "os";
|
|
14
15
|
|
|
@@ -99,10 +100,11 @@ function isServerHealthy(project) {
|
|
|
99
100
|
* Discover a running opencode server that matches the target directory
|
|
100
101
|
*
|
|
101
102
|
* Queries all running opencode servers and finds the best match based on:
|
|
102
|
-
* 1.
|
|
103
|
-
* 2. Exact
|
|
104
|
-
* 3.
|
|
105
|
-
* 4.
|
|
103
|
+
* 1. Configured server_port (highest priority if set and healthy)
|
|
104
|
+
* 2. Exact sandbox match
|
|
105
|
+
* 3. Exact worktree match
|
|
106
|
+
* 4. Target is subdirectory of worktree
|
|
107
|
+
* 5. Global server (worktree="/") as fallback
|
|
106
108
|
*
|
|
107
109
|
* Global servers are used as a fallback when no project-specific match is found,
|
|
108
110
|
* since OpenCode Desktop may be connected to a global server that can display
|
|
@@ -112,11 +114,13 @@ function isServerHealthy(project) {
|
|
|
112
114
|
* @param {object} [options] - Options for testing/mocking
|
|
113
115
|
* @param {function} [options.getPorts] - Function to get server ports
|
|
114
116
|
* @param {function} [options.fetch] - Function to fetch URLs
|
|
117
|
+
* @param {number} [options.preferredPort] - Preferred port to use (overrides config)
|
|
115
118
|
* @returns {Promise<string|null>} Server URL (e.g., "http://localhost:4096") or null
|
|
116
119
|
*/
|
|
117
120
|
export async function discoverOpencodeServer(targetDir, options = {}) {
|
|
118
121
|
const getPorts = options.getPorts || getOpencodePorts;
|
|
119
122
|
const fetchFn = options.fetch || fetch;
|
|
123
|
+
const preferredPort = options.preferredPort ?? getServerPort();
|
|
120
124
|
|
|
121
125
|
const ports = await getPorts();
|
|
122
126
|
if (ports.length === 0) {
|
|
@@ -124,7 +128,24 @@ export async function discoverOpencodeServer(targetDir, options = {}) {
|
|
|
124
128
|
return null;
|
|
125
129
|
}
|
|
126
130
|
|
|
127
|
-
debug(`discoverOpencodeServer: checking ${ports.length} servers for ${targetDir}`);
|
|
131
|
+
debug(`discoverOpencodeServer: checking ${ports.length} servers for ${targetDir}, preferredPort=${preferredPort}`);
|
|
132
|
+
|
|
133
|
+
// If preferred port is configured and running, check it first
|
|
134
|
+
if (preferredPort && ports.includes(preferredPort)) {
|
|
135
|
+
const url = `http://localhost:${preferredPort}`;
|
|
136
|
+
try {
|
|
137
|
+
const response = await fetchFn(`${url}/project/current`);
|
|
138
|
+
if (response.ok) {
|
|
139
|
+
const project = await response.json();
|
|
140
|
+
if (isServerHealthy(project)) {
|
|
141
|
+
debug(`discoverOpencodeServer: using preferred port ${preferredPort}`);
|
|
142
|
+
return url;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
} catch (err) {
|
|
146
|
+
debug(`discoverOpencodeServer: preferred port ${preferredPort} error: ${err.message}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
128
149
|
|
|
129
150
|
let bestMatch = null;
|
|
130
151
|
let bestScore = 0;
|
package/service/repo-config.js
CHANGED
|
@@ -310,6 +310,15 @@ export function getCleanupTtlDays() {
|
|
|
310
310
|
return config?.cleanup?.ttl_days ?? 30;
|
|
311
311
|
}
|
|
312
312
|
|
|
313
|
+
/**
|
|
314
|
+
* Get preferred OpenCode server port from config
|
|
315
|
+
* @returns {number|null} Port number or null if not configured
|
|
316
|
+
*/
|
|
317
|
+
export function getServerPort() {
|
|
318
|
+
const config = getRawConfig();
|
|
319
|
+
return config?.server_port ?? null;
|
|
320
|
+
}
|
|
321
|
+
|
|
313
322
|
/**
|
|
314
323
|
* Clear config cache (for testing)
|
|
315
324
|
*/
|