@bogyie/opencode-kiro-plugin 0.3.4 → 0.3.5

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/dist/auth.js +53 -5
  2. package/package.json +1 -1
package/dist/auth.js CHANGED
@@ -96,11 +96,59 @@ export async function readKiroCliSessionCredential(options = {}, runner = runCom
96
96
  function delay(ms) {
97
97
  return new Promise((resolve) => setTimeout(resolve, ms));
98
98
  }
99
- function firstUrl(text) {
100
- return /https?:\/\/[^\s"'<>]+/.exec(text)?.[0];
99
+ function urls(text) {
100
+ return text.match(/https?:\/\/[^\s"'<>]+/g) ?? [];
101
+ }
102
+ function isLocalCallbackUrl(value) {
103
+ try {
104
+ const url = new URL(value);
105
+ const hostname = url.hostname.toLowerCase();
106
+ return ((hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1" || hostname === "[::1]") &&
107
+ url.pathname.includes("/callback"));
108
+ }
109
+ catch {
110
+ return false;
111
+ }
112
+ }
113
+ function loginUrlFromLocalCallbackUrl(value) {
114
+ if (!isLocalCallbackUrl(value))
115
+ return undefined;
116
+ try {
117
+ const issuerUrl = new URL(value).searchParams.get("issuer_url");
118
+ if (!issuerUrl || isLocalCallbackUrl(issuerUrl))
119
+ return undefined;
120
+ const parsed = new URL(issuerUrl);
121
+ return parsed.protocol === "https:" || parsed.protocol === "http:" ? parsed.toString() : undefined;
122
+ }
123
+ catch {
124
+ return undefined;
125
+ }
126
+ }
127
+ function isKiroSigninUrl(value) {
128
+ try {
129
+ const url = new URL(value);
130
+ return url.hostname.toLowerCase() === "app.kiro.dev" && url.pathname === "/signin";
131
+ }
132
+ catch {
133
+ return false;
134
+ }
135
+ }
136
+ function firstLoginUrl(text) {
137
+ const candidates = urls(text);
138
+ const kiroSigninUrl = candidates.find(isKiroSigninUrl);
139
+ if (kiroSigninUrl)
140
+ return kiroSigninUrl;
141
+ for (const url of candidates) {
142
+ const callbackLoginUrl = loginUrlFromLocalCallbackUrl(url);
143
+ if (callbackLoginUrl)
144
+ return callbackLoginUrl;
145
+ if (!isLocalCallbackUrl(url))
146
+ return url;
147
+ }
148
+ return undefined;
101
149
  }
102
150
  export function extractKiroLoginUrl(output) {
103
- return firstUrl(output) ?? KIRO_LOGIN_URL;
151
+ return firstLoginUrl(output) ?? KIRO_LOGIN_URL;
104
152
  }
105
153
  export function extractKiroLoginCode(output) {
106
154
  return /\b[A-Z0-9]{4}-[A-Z0-9]{4}\b/.exec(output)?.[0] ?? /\b[A-Z0-9]{8,}\b/.exec(output)?.[0];
@@ -136,13 +184,13 @@ export function startKiroCliLogin(spawner = (command, args) => spawn(command, [.
136
184
  while (Date.now() < deadline) {
137
185
  if (extractKiroLoginCode(output))
138
186
  return true;
139
- if (firstUrl(output))
187
+ if (firstLoginUrl(output))
140
188
  return true;
141
189
  if (exited && exitCode !== 0)
142
190
  return false;
143
191
  await delay(100);
144
192
  }
145
- return Boolean(extractKiroLoginCode(output) || firstUrl(output));
193
+ return Boolean(extractKiroLoginCode(output) || firstLoginUrl(output));
146
194
  },
147
195
  async waitForAuth(runner = runCommand) {
148
196
  const deadline = Date.now() + 10 * 60 * 1000;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bogyie/opencode-kiro-plugin",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "OpenCode plugin for using Kiro as a provider adapter",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",