opencode-pilot 0.16.3 → 0.16.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-pilot",
3
- "version": "0.16.3",
3
+ "version": "0.16.4",
4
4
  "type": "module",
5
5
  "main": "plugin/index.js",
6
6
  "description": "Automation daemon for OpenCode - polls for work and spawns sessions",
@@ -470,6 +470,8 @@ function runSpawn(args, options = {}) {
470
470
  export async function createSessionViaApi(serverUrl, directory, prompt, options = {}) {
471
471
  const fetchFn = options.fetch || fetch;
472
472
 
473
+ let session = null;
474
+
473
475
  try {
474
476
  // Step 1: Create a new session with the directory parameter
475
477
  const sessionUrl = new URL('/session', serverUrl);
@@ -486,7 +488,7 @@ export async function createSessionViaApi(serverUrl, directory, prompt, options
486
488
  throw new Error(`Failed to create session: ${createResponse.status} ${errorText}`);
487
489
  }
488
490
 
489
- const session = await createResponse.json();
491
+ session = await createResponse.json();
490
492
  debug(`createSessionViaApi: created session ${session.id} in ${directory}`);
491
493
 
492
494
  // Step 2: Update session title if provided
@@ -543,6 +545,17 @@ export async function createSessionViaApi(serverUrl, directory, prompt, options
543
545
  };
544
546
  } catch (err) {
545
547
  debug(`createSessionViaApi: error - ${err.message}`);
548
+ // If session was created but message failed, still return success
549
+ // to prevent re-processing (the session exists, user can send message manually)
550
+ if (session) {
551
+ debug(`createSessionViaApi: session ${session.id} was created, marking as success despite message error`);
552
+ return {
553
+ success: true,
554
+ sessionId: session.id,
555
+ directory,
556
+ warning: err.message,
557
+ };
558
+ }
546
559
  return {
547
560
  success: false,
548
561
  error: err.message,
@@ -227,9 +227,13 @@ export async function pollOnce(options = {}) {
227
227
  itemUpdatedAt: item.updated_at || null,
228
228
  });
229
229
  }
230
- console.log(`[poll] Started session for ${item.id}`);
230
+ if (result.warning) {
231
+ console.log(`[poll] Started session for ${item.id} (warning: ${result.warning})`);
232
+ } else {
233
+ console.log(`[poll] Started session for ${item.id}`);
234
+ }
231
235
  } else {
232
- console.error(`[poll] Failed to start session: ${result.stderr}`);
236
+ console.error(`[poll] Failed to start session: ${result.error || result.stderr || 'unknown error'}`);
233
237
  }
234
238
  } catch (err) {
235
239
  console.error(`[poll] Error executing action: ${err.message}`);
@@ -930,5 +930,47 @@ describe('actions.js', () => {
930
930
  assert.strictEqual(messageBody.providerID, 'anthropic', 'Should parse provider from model');
931
931
  assert.strictEqual(messageBody.modelID, 'claude-sonnet-4-20250514', 'Should parse model ID');
932
932
  });
933
+
934
+ test('returns success with warning when session created but message fails', async () => {
935
+ const { createSessionViaApi } = await import('../../service/actions.js');
936
+
937
+ const mockSessionId = 'ses_partial123';
938
+
939
+ const mockFetch = async (url, opts) => {
940
+ const urlObj = new URL(url);
941
+
942
+ // Session creation succeeds
943
+ if (urlObj.pathname === '/session' && opts?.method === 'POST') {
944
+ return {
945
+ ok: true,
946
+ json: async () => ({ id: mockSessionId }),
947
+ };
948
+ }
949
+
950
+ // Message send fails
951
+ if (urlObj.pathname.includes('/message') && opts?.method === 'POST') {
952
+ return {
953
+ ok: false,
954
+ status: 500,
955
+ text: async () => 'Message send failed',
956
+ };
957
+ }
958
+
959
+ return { ok: true, json: async () => ({}) };
960
+ };
961
+
962
+ const result = await createSessionViaApi(
963
+ 'http://localhost:4096',
964
+ '/path/to/project',
965
+ 'Fix the bug',
966
+ { fetch: mockFetch }
967
+ );
968
+
969
+ // Should return success because session was created
970
+ assert.ok(result.success, 'Should return success when session was created');
971
+ assert.strictEqual(result.sessionId, mockSessionId, 'Should return session ID');
972
+ assert.ok(result.warning, 'Should include warning about message failure');
973
+ assert.ok(result.warning.includes('Failed to send message'), 'Warning should mention message failure');
974
+ });
933
975
  });
934
976
  });