opencode-pilot 0.9.1 → 0.9.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-pilot",
3
- "version": "0.9.1",
3
+ "version": "0.9.3",
4
4
  "type": "module",
5
5
  "main": "plugin/index.js",
6
6
  "description": "Automation daemon for OpenCode - polls for work and spawns sessions",
@@ -102,7 +102,11 @@ function isServerHealthy(project) {
102
102
  * 1. Exact sandbox match (highest priority)
103
103
  * 2. Exact worktree match
104
104
  * 3. Target is subdirectory of worktree
105
- * 4. Global project (worktree="/") as fallback (e.g., OpenCode Desktop)
105
+ * 4. Global server (worktree="/") as fallback
106
+ *
107
+ * Global servers are used as a fallback when no project-specific match is found,
108
+ * since OpenCode Desktop may be connected to a global server that can display
109
+ * sessions for any project.
106
110
  *
107
111
  * @param {string} targetDir - The directory we want to work in
108
112
  * @param {object} [options] - Options for testing/mocking
@@ -124,6 +128,7 @@ export async function discoverOpencodeServer(targetDir, options = {}) {
124
128
 
125
129
  let bestMatch = null;
126
130
  let bestScore = 0;
131
+ let globalServer = null;
127
132
 
128
133
  for (const port of ports) {
129
134
  const url = `http://localhost:${port}`;
@@ -145,6 +150,13 @@ export async function discoverOpencodeServer(targetDir, options = {}) {
145
150
  const worktree = project.worktree || '/';
146
151
  const sandboxes = project.sandboxes || [];
147
152
 
153
+ // Track global server as fallback (but prefer project-specific matches)
154
+ if (worktree === '/') {
155
+ debug(`discoverOpencodeServer: ${url} is global project, tracking as fallback`);
156
+ globalServer = url;
157
+ continue;
158
+ }
159
+
148
160
  const score = getPathMatchScore(targetDir, worktree, sandboxes);
149
161
  debug(`discoverOpencodeServer: ${url} worktree=${worktree} score=${score}`);
150
162
 
@@ -157,8 +169,10 @@ export async function discoverOpencodeServer(targetDir, options = {}) {
157
169
  }
158
170
  }
159
171
 
160
- debug(`discoverOpencodeServer: best match=${bestMatch} score=${bestScore}`);
161
- return bestMatch;
172
+ // Use project-specific match if found, otherwise fall back to global server
173
+ const result = bestMatch || globalServer;
174
+ debug(`discoverOpencodeServer: best match=${bestMatch} score=${bestScore}, global=${globalServer}, using=${result}`);
175
+ return result;
162
176
  }
163
177
 
164
178
  // Default templates directory
@@ -394,19 +394,19 @@ describe('actions.js', () => {
394
394
  assert.strictEqual(result, 'http://localhost:4000');
395
395
  });
396
396
 
397
- test('falls back to healthy global project when no specific match', async () => {
397
+ test('uses global project server as fallback when no specific match', async () => {
398
398
  const { discoverOpencodeServer } = await import('../../service/actions.js');
399
399
 
400
400
  const mockPorts = async () => [3000];
401
401
  const mockFetch = async (url) => {
402
402
  if (url === 'http://localhost:3000/project/current') {
403
- // Healthy global project with proper structure
403
+ // Global project with worktree="/"
404
404
  return { ok: true, json: async () => ({ id: 'global', worktree: '/', sandboxes: [], time: { created: 1 } }) };
405
405
  }
406
406
  return { ok: false };
407
407
  };
408
408
 
409
- // Global servers (like OpenCode Desktop) should work as fallback
409
+ // Global servers should be used as fallback when no project-specific match
410
410
  const result = await discoverOpencodeServer('/Users/test/random/path', {
411
411
  getPorts: mockPorts,
412
412
  fetch: mockFetch