opencode-1password-auth 1.0.7 → 1.0.8

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 +40 -10
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -43,8 +43,16 @@ interface AuthJson {
43
43
  export const OnePasswordAuthPlugin: Plugin = async ({ client, $ }) => {
44
44
  let opClient: Awaited<ReturnType<typeof sdk.createClient>> | null = null;
45
45
  let mcpsEnvId: string | undefined;
46
+ let initialized = false;
47
+ let executionOrder = 0;
46
48
 
47
- debugLog("Plugin loaded");
49
+ debugLog(`Plugin loaded (order: ${++executionOrder})`);
50
+
51
+ // Log environment variable status (redacted)
52
+ const token = process.env.OP_SERVICE_ACCOUNT_TOKEN;
53
+ const configId = process.env.OP_CONFIG_ENV_ID;
54
+ debugLog(`Environment check - OP_SERVICE_ACCOUNT_TOKEN: ${token ? 'SET' : 'MISSING'} (${token ? token.substring(0, 8) + '...' : 'N/A'})`);
55
+ debugLog(`Environment check - OP_CONFIG_ENV_ID: ${configId ? 'SET' : 'MISSING'} (${configId ? configId.substring(0, 8) + '...' : 'N/A'})`);
48
56
 
49
57
  const normalizeProviderId = (variableName: string): string => {
50
58
  // Convert common patterns to match auth.json provider IDs
@@ -316,6 +324,11 @@ export const OnePasswordAuthPlugin: Plugin = async ({ client, $ }) => {
316
324
 
317
325
  // Initialize as soon as plugin loads (config hook runs early)
318
326
  const initializePlugin = async () => {
327
+ debugLog(`initializePlugin called (order: ${++executionOrder})`);
328
+ if (initialized) {
329
+ debugLog("initializePlugin: already initialized, skipping");
330
+ return;
331
+ }
319
332
  debugLog("Initializing plugin...");
320
333
 
321
334
  opClient = await initClient();
@@ -342,8 +355,9 @@ export const OnePasswordAuthPlugin: Plugin = async ({ client, $ }) => {
342
355
 
343
356
  const providersEnvId = configEnvIds.OPENCODE_PROVIDERS_ENV_ID;
344
357
  if (providersEnvId) {
345
- // First update the config files to use env var references
346
- await updateAuthJson(providersEnvId);
358
+ // Authenticate providers - client.auth.set() will write to auth.json
359
+ // SKIP updateAuthJson - it writes {env:...} placeholders which cause issues
360
+ // await updateAuthJson(providersEnvId);
347
361
  await authenticateProviders(providersEnvId);
348
362
  }
349
363
 
@@ -357,19 +371,35 @@ export const OnePasswordAuthPlugin: Plugin = async ({ client, $ }) => {
357
371
  }
358
372
  }
359
373
 
374
+ initialized = true;
360
375
  debugLog("Plugin initialization complete");
361
376
  };
362
377
 
363
- // Start initialization immediately
364
- initializePlugin().catch(err => {
365
- debugLog(`Failed to initialize plugin: ${err}`);
366
- });
378
+ // Start initialization immediately (but config hook might run first)
379
+ debugLog(`Starting immediate initialization (order: ${++executionOrder})`);
380
+ if (!initialized) {
381
+ initializePlugin().catch(err => {
382
+ debugLog(`Failed to initialize plugin: ${err}`);
383
+ });
384
+ } else {
385
+ debugLog("Already initialized, skipping immediate init");
386
+ }
367
387
 
368
388
  return {
369
389
  async config(config: any) {
370
- debugLog("Config hook called");
371
- // Config hook runs early, we could also initialize here
372
- // but we're already initializing above
390
+ debugLog(`Config hook called (order: ${++executionOrder})`);
391
+ // Config hook runs early - try to authenticate here
392
+ if (!initialized) {
393
+ debugLog("Config hook: attempting authentication");
394
+ try {
395
+ await initializePlugin();
396
+ initialized = true;
397
+ } catch (err) {
398
+ debugLog(`Config hook authentication failed: ${err}`);
399
+ }
400
+ } else {
401
+ debugLog("Config hook: already initialized");
402
+ }
373
403
  },
374
404
 
375
405
  async event({ event }: { event: { type: string } }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-1password-auth",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "1Password integration for OpenCode - authenticate providers and inject MCP secrets from 1Password environments",
5
5
  "type": "module",
6
6
  "main": "index.ts",