@kody-ade/kody-engine 0.4.602 → 0.4.604

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/bin/kody.js +65 -5
  2. package/package.json +1 -1
package/dist/bin/kody.js CHANGED
@@ -15,7 +15,7 @@ var init_package = __esm({
15
15
  "package.json"() {
16
16
  package_default = {
17
17
  name: "@kody-ade/kody-engine",
18
- version: "0.4.602",
18
+ version: "0.4.604",
19
19
  description: "kody \u2014 autonomous development engine. Single-session Claude Code agent behind a generic executor + declarative implementation profiles.",
20
20
  license: "MIT",
21
21
  type: "module",
@@ -18385,7 +18385,8 @@ function writeKodyStorageState(input) {
18385
18385
  repo: input.repo,
18386
18386
  token: input.token,
18387
18387
  addedAt: now,
18388
- isLogin: true
18388
+ isLogin: true,
18389
+ ...input.user ? { user: input.user } : {}
18389
18390
  };
18390
18391
  const unresolvedUser = { login: "", avatar_url: "", id: 0 };
18391
18392
  const auth = {
@@ -18393,7 +18394,7 @@ function writeKodyStorageState(input) {
18393
18394
  owner: input.owner,
18394
18395
  repo: input.repo,
18395
18396
  token: input.token,
18396
- user: unresolvedUser,
18397
+ user: input.user ?? unresolvedUser,
18397
18398
  loggedInAt: now,
18398
18399
  repos: [repoEntry],
18399
18400
  currentRepoIndex: 0
@@ -18408,7 +18409,7 @@ function writeKodyStorageState(input) {
18408
18409
  ]
18409
18410
  };
18410
18411
  fs48.writeFileSync(file, JSON.stringify(storageState), { mode: 384 });
18411
- return { directory, file };
18412
+ return { directory, file, auth };
18412
18413
  }
18413
18414
  function parseSetCookie(value, hostname) {
18414
18415
  const parts = value.split(";").map((part) => part.trim());
@@ -18450,11 +18451,66 @@ function writeCookieStorageState(targetUrl, setCookies) {
18450
18451
  );
18451
18452
  return { directory, file };
18452
18453
  }
18454
+ function currentStorageStatePath(args) {
18455
+ for (let index = 0; index < args.length; index += 1) {
18456
+ const arg = args[index];
18457
+ if (arg === "--storage-state") return args[index + 1];
18458
+ if (arg.startsWith("--storage-state=")) return arg.slice("--storage-state=".length);
18459
+ }
18460
+ return void 0;
18461
+ }
18462
+ function browserSessionCookieHeader(profile, targetUrl) {
18463
+ const playwright = profile.claudeCode.mcpServers.find((server) => server.name === "playwright");
18464
+ const storagePath = currentStorageStatePath(playwright?.args ?? []);
18465
+ if (!storagePath || !fs48.existsSync(storagePath)) return void 0;
18466
+ const hostname = new URL(targetUrl).hostname;
18467
+ const state = JSON.parse(fs48.readFileSync(storagePath, "utf-8"));
18468
+ const cookies = (state.cookies ?? []).filter((cookie) => {
18469
+ const domain = cookie.domain.replace(/^\./, "");
18470
+ return hostname === domain || hostname.endsWith(`.${domain}`);
18471
+ });
18472
+ if (cookies.length === 0) return void 0;
18473
+ return cookies.map((cookie) => `${cookie.name}=${String(cookie.value)}`).join("; ");
18474
+ }
18475
+ async function saveAccountRepositoryAuth(targetUrl, cookie, auth) {
18476
+ const origin = browserOrigin(targetUrl);
18477
+ const response = await fetch(`${origin}/api/kody/account/repositories`, {
18478
+ method: "PUT",
18479
+ headers: { "content-type": "application/json", cookie, origin },
18480
+ body: JSON.stringify({ auth })
18481
+ });
18482
+ if (!response.ok) throw new Error(`app repository setup returned ${response.status}`);
18483
+ }
18484
+ function mergeStorageStates(existingPath, nextPath) {
18485
+ if (existingPath === nextPath || !fs48.existsSync(existingPath)) return;
18486
+ const existing = JSON.parse(fs48.readFileSync(existingPath, "utf-8"));
18487
+ const next = JSON.parse(fs48.readFileSync(nextPath, "utf-8"));
18488
+ const cookies = /* @__PURE__ */ new Map();
18489
+ for (const cookie of [...existing.cookies ?? [], ...next.cookies ?? []]) {
18490
+ cookies.set(`${cookie.name}\0${cookie.domain}\0${cookie.path}`, cookie);
18491
+ }
18492
+ const origins = /* @__PURE__ */ new Map();
18493
+ for (const entry of [...existing.origins ?? [], ...next.origins ?? []]) {
18494
+ const current = origins.get(entry.origin);
18495
+ const localStorage = /* @__PURE__ */ new Map();
18496
+ for (const item of [...current?.localStorage ?? [], ...entry.localStorage ?? []]) {
18497
+ localStorage.set(item.name, item);
18498
+ }
18499
+ origins.set(entry.origin, { origin: entry.origin, localStorage: [...localStorage.values()] });
18500
+ }
18501
+ fs48.writeFileSync(
18502
+ nextPath,
18503
+ JSON.stringify({ cookies: [...cookies.values()], origins: [...origins.values()] }),
18504
+ { mode: 384 }
18505
+ );
18506
+ }
18453
18507
  function configurePlaywright(profile, storageStatePath) {
18454
18508
  const playwright = profile.claudeCode.mcpServers.find((server) => server.name === "playwright");
18455
18509
  if (!playwright) throw new Error("Playwright MCP server is not configured");
18456
18510
  const args = [];
18457
18511
  const currentArgs = playwright.args ?? [];
18512
+ const existingStorageStatePath = currentStorageStatePath(currentArgs);
18513
+ if (existingStorageStatePath) mergeStorageStates(existingStorageStatePath, storageStatePath);
18458
18514
  for (let index = 0; index < currentArgs.length; index += 1) {
18459
18515
  const arg = currentArgs[index];
18460
18516
  if (arg === "--storage-state") {
@@ -18525,13 +18581,17 @@ async function prepareKodyRepositoryBrowserAuth(ctx, profile, input) {
18525
18581
  );
18526
18582
  const [owner, repo] = repository.full_name.split("/");
18527
18583
  if (!owner || !repo) throw new Error("GitHub returned incomplete repository data");
18584
+ const appCookie = browserSessionCookieHeader(profile, input.targetUrl);
18585
+ const user = appCookie ? await githubJson("https://api.github.com/user", credential.value, "user") : void 0;
18528
18586
  state = writeKodyStorageState({
18529
18587
  origin: browserOrigin(input.targetUrl),
18530
18588
  repoUrl: `https://github.com/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}`,
18531
18589
  owner,
18532
18590
  repo,
18533
- token: credential.value
18591
+ token: credential.value,
18592
+ user
18534
18593
  });
18594
+ if (appCookie) await saveAccountRepositoryAuth(input.targetUrl, appCookie, state.auth);
18535
18595
  configurePlaywright(profile, state.file);
18536
18596
  const authDirectory = state.directory;
18537
18597
  registerRuntimeCleanup(ctx, () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kody-ade/kody-engine",
3
- "version": "0.4.602",
3
+ "version": "0.4.604",
4
4
  "description": "kody — autonomous development engine. Single-session Claude Code agent behind a generic executor + declarative implementation profiles.",
5
5
  "license": "MIT",
6
6
  "type": "module",