@bogyie/opencode-kiro-plugin 0.3.18 → 0.3.20

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/dist/auth.d.ts CHANGED
@@ -77,6 +77,7 @@ export interface KiroLoginFlowOptions {
77
77
  readonly login?: KiroCliLoginOptions;
78
78
  }
79
79
  export declare const KIRO_LOGIN_URL = "https://view.awsapps.com/start";
80
+ export declare const KIRO_LOCAL_TRANSPORT_KEY = "kiro-plugin-local-transport";
80
81
  export declare const DEFAULT_KIRO_CLI_DB_PATH: string;
81
82
  export declare const DEFAULT_KIRO_CLI_TOKEN_KEYS: readonly ["kirocli:odic:token", "codewhisperer:odic:token"];
82
83
  export declare function runCommand(command: string, args: ReadonlyArray<string>, options?: CommandRunOptions): Promise<CommandResult>;
package/dist/auth.js CHANGED
@@ -6,6 +6,7 @@ import { join } from "node:path";
6
6
  import { promisify } from "node:util";
7
7
  const execFileAsync = promisify(execFile);
8
8
  export const KIRO_LOGIN_URL = "https://view.awsapps.com/start";
9
+ export const KIRO_LOCAL_TRANSPORT_KEY = "kiro-plugin-local-transport";
9
10
  export const DEFAULT_KIRO_CLI_DB_PATH = join(homedir(), "Library", "Application Support", "kiro-cli", "data.sqlite3");
10
11
  export const DEFAULT_KIRO_CLI_TOKEN_KEYS = ["kirocli:odic:token", "codewhisperer:odic:token"];
11
12
  const KIRO_DEVICE_AUTH_KEY_PREFIX = "kiro-device:";
@@ -445,7 +446,7 @@ function loginMethodSelection(method) {
445
446
  case "github":
446
447
  return "\x1B[B\x1B[B\r";
447
448
  case "organization":
448
- return "\x1B[B\x1B[B\x1B[B\r";
449
+ return "";
449
450
  }
450
451
  }
451
452
  function loginMethodPromptSeen(output) {
@@ -455,6 +456,9 @@ function loginMethodPromptSeen(output) {
455
456
  output.includes("Use with GitHub") ||
456
457
  output.includes("Use with Your Organization"));
457
458
  }
459
+ function loginPromptReady(output) {
460
+ return Boolean(extractKiroLoginCode(output) || firstLoginUrl(output));
461
+ }
458
462
  export function startKiroCliLogin(optionsOrSpawner, spawner) {
459
463
  const resolved = loginOptionsAndSpawner(optionsOrSpawner, spawner);
460
464
  const child = resolved.spawner("kiro-cli", kiroCliLoginArgs(resolved.options));
@@ -463,8 +467,12 @@ export function startKiroCliLogin(optionsOrSpawner, spawner) {
463
467
  let exitCode = null;
464
468
  let selectedLoginMethod = false;
465
469
  const maybeSelectLoginMethod = () => {
466
- if (!resolved.options.method || selectedLoginMethod || !loginMethodPromptSeen(output))
470
+ if (!resolved.options.method ||
471
+ resolved.options.method === "organization" ||
472
+ selectedLoginMethod ||
473
+ !loginMethodPromptSeen(output)) {
467
474
  return;
475
+ }
468
476
  child.stdin?.write(loginMethodSelection(resolved.options.method));
469
477
  selectedLoginMethod = true;
470
478
  };
@@ -494,23 +502,21 @@ export function startKiroCliLogin(optionsOrSpawner, spawner) {
494
502
  async waitForPrompt(timeoutMs = 15_000) {
495
503
  const deadline = Date.now() + timeoutMs;
496
504
  while (Date.now() < deadline) {
497
- if (extractKiroLoginCode(output))
498
- return true;
499
- if (firstLoginUrl(output))
505
+ if (loginPromptReady(output))
500
506
  return true;
501
507
  if (exited && exitCode !== 0)
502
508
  return false;
503
509
  await delay(100);
504
510
  }
505
- return Boolean(extractKiroLoginCode(output) || firstLoginUrl(output));
511
+ return loginPromptReady(output);
506
512
  },
507
513
  async waitForAuth(runner = runCommand) {
508
514
  const deadline = Date.now() + 10 * 60 * 1000;
509
515
  while (Date.now() < deadline) {
510
516
  const auth = await detectAuth(process.env, runner);
511
- if (auth.authenticated)
517
+ if (auth.authenticated && (!loginPromptReady(output) || exited))
512
518
  return true;
513
- if (exited && exitCode !== 0)
519
+ if (exited && exitCode !== 0 && !loginPromptReady(output))
514
520
  return false;
515
521
  await delay(2000);
516
522
  }
@@ -625,7 +631,10 @@ export async function resolveApiKey(auth, env = process.env) {
625
631
  return env.KIRO_API_KEY;
626
632
  try {
627
633
  const credential = await auth();
628
- return credential.key || credential.access || "";
634
+ if (credential.type === "api")
635
+ return credential.key || credential.access || "";
636
+ const key = credential.key || credential.access || "";
637
+ return key === KIRO_LOCAL_TRANSPORT_KEY || isKiroDeviceAuthKey(key) ? key : "";
629
638
  }
630
639
  catch {
631
640
  return "";
package/dist/plugin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { tool } from "@opencode-ai/plugin";
2
2
  import { KiroAcpTransport } from "./acp-transport.js";
3
- import { credentialFromKiroDeviceAuthKey, detectAuth, isKiroDeviceAuthKey, readKiroCliSessionCredential, resolveApiKey, startKiroCliLoginOnce, runKiroLoginFlowOnce, } from "./auth.js";
3
+ import { credentialFromKiroDeviceAuthKey, detectAuth, isKiroDeviceAuthKey, KIRO_LOCAL_TRANSPORT_KEY, readKiroCliSessionCredential, resolveApiKey, startKiroCliLoginOnce, runKiroLoginFlowOnce, } from "./auth.js";
4
4
  import { KiroCliChatTransport } from "./cli-transport.js";
5
5
  import { loadOptions } from "./config.js";
6
6
  import { createKiroFetch } from "./fetch-adapter.js";
@@ -70,7 +70,7 @@ export function effectiveBackend(options, accessToken) {
70
70
  return "cli-chat";
71
71
  if (options.backend === "fetch")
72
72
  return "fetch";
73
- if (apiKey && apiKey !== "kiro-plugin-local-transport")
73
+ if (apiKey && apiKey !== KIRO_LOCAL_TRANSPORT_KEY)
74
74
  return "fetch";
75
75
  return "fetch";
76
76
  }
@@ -107,7 +107,7 @@ function localTransport(options, accessToken, behavior = {}) {
107
107
  login,
108
108
  });
109
109
  }
110
- return new KiroRestTransport(fetchTransportOptions(options, apiKey === "kiro-plugin-local-transport" ? undefined : apiKey), {
110
+ return new KiroRestTransport(fetchTransportOptions(options, apiKey === KIRO_LOCAL_TRANSPORT_KEY ? undefined : apiKey), {
111
111
  login,
112
112
  });
113
113
  }
@@ -238,7 +238,7 @@ export function createKiroPlugin() {
238
238
  await refreshModels(true).catch(() => []);
239
239
  return {
240
240
  type: "success",
241
- key: "kiro-plugin-local-transport",
241
+ key: KIRO_LOCAL_TRANSPORT_KEY,
242
242
  metadata: {
243
243
  source: "kiro-cli-device-flow",
244
244
  },
@@ -300,7 +300,7 @@ export function createKiroPlugin() {
300
300
  const apiKey = await resolveApiKey(auth);
301
301
  const server = await ensureLocalServer();
302
302
  return {
303
- apiKey: apiKey || "kiro-plugin-local-transport",
303
+ apiKey: apiKey || KIRO_LOCAL_TRANSPORT_KEY,
304
304
  baseURL: server.baseURL,
305
305
  };
306
306
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bogyie/opencode-kiro-plugin",
3
- "version": "0.3.18",
3
+ "version": "0.3.20",
4
4
  "description": "OpenCode plugin for using Kiro as a provider adapter",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",