@kodycodes/cli 3.34.14 → 3.35.0

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 (87) hide show
  1. package/dist/{auth-CJGMSRPQ.js → auth-QVKERRWX.js} +5 -4
  2. package/dist/auth-bootstrap.d.ts +2 -0
  3. package/dist/bin.js +7 -6
  4. package/dist/bin.js.map +1 -1
  5. package/dist/{chunk-EKVVIFRW.js → chunk-3STT5AKR.js} +2 -2
  6. package/dist/{chunk-GZCZPBUM.js → chunk-53PQCA4T.js} +8 -2
  7. package/dist/chunk-53PQCA4T.js.map +6 -0
  8. package/dist/{chunk-M44CO6QB.js → chunk-7P4IRMKT.js} +2 -1
  9. package/dist/{chunk-M44CO6QB.js.map → chunk-7P4IRMKT.js.map} +1 -1
  10. package/dist/{chunk-NBJ3X25P.js → chunk-DJMZA33K.js} +2 -2
  11. package/dist/{chunk-AIRKIBWV.js → chunk-G2SFAZE7.js} +23 -7
  12. package/dist/chunk-G2SFAZE7.js.map +6 -0
  13. package/dist/chunk-G6LJWROP.js +18 -0
  14. package/dist/chunk-G6LJWROP.js.map +6 -0
  15. package/dist/{chunk-C42MRUTR.js → chunk-G7PO2D4W.js} +3 -3
  16. package/dist/chunk-IEGR76KD.js +116 -0
  17. package/dist/chunk-IEGR76KD.js.map +6 -0
  18. package/dist/{chunk-SNXLFUYP.js → chunk-KYB2MPO3.js} +156 -4
  19. package/dist/chunk-KYB2MPO3.js.map +6 -0
  20. package/dist/{chunk-XIZ7EZDP.js → chunk-PRJ5BA7K.js} +4 -14
  21. package/dist/chunk-PRJ5BA7K.js.map +6 -0
  22. package/dist/{chunk-7BGOL5PB.js → chunk-TIXLYGDA.js} +7 -5
  23. package/dist/chunk-TIXLYGDA.js.map +6 -0
  24. package/dist/{chunk-WEJLTJUI.js → chunk-TO2NVKC3.js} +2 -2
  25. package/dist/{chunk-6T3ZZBRY.js → chunk-UMTYOOTV.js} +7 -7
  26. package/dist/{chunk-7XY3VABI.js → chunk-ZOTZLLGJ.js} +123 -53
  27. package/dist/chunk-ZOTZLLGJ.js.map +6 -0
  28. package/dist/cli.d.ts +6 -0
  29. package/dist/cli.js +7 -6
  30. package/dist/{commands-PLHV77ZM.js → commands-UOA3PH5D.js} +2 -2
  31. package/dist/dev/dev-registry.d.ts +4 -0
  32. package/dist/dev/local-kody.d.ts +60 -0
  33. package/dist/{dev-command-HRLCH7SC.js → dev-command-HQEI4YMG.js} +372 -135
  34. package/dist/dev-command-HQEI4YMG.js.map +6 -0
  35. package/dist/dev-command.d.ts +11 -1
  36. package/dist/{git-credential-HFCBL3TZ.js → git-credential-CMHDH5CW.js} +6 -5
  37. package/dist/git-credential-CMHDH5CW.js.map +6 -0
  38. package/dist/{local-execute-FAALT4AL.js → local-execute-2HZQRBWH.js} +6 -5
  39. package/dist/local-execute-2HZQRBWH.js.map +6 -0
  40. package/dist/local-kody-NDNDB5MV.js +344 -0
  41. package/dist/local-kody-NDNDB5MV.js.map +6 -0
  42. package/dist/{local-package-graph-QSRKLQIP.js → local-package-graph-4OV2YXQV.js} +4 -3
  43. package/dist/{local-package-run-LZTXOFKQ.js → local-package-run-OYQDFXPJ.js} +9 -8
  44. package/dist/{local-secrets-LMXJBIPU.js → local-secrets-BD434YXP.js} +4 -3
  45. package/dist/local-secrets-BD434YXP.js.map +6 -0
  46. package/dist/mock/ensure-msw.d.ts +6 -0
  47. package/dist/{mock-dep-resolve-42AMGI4V.js → mock-dep-resolve-QTL45S2K.js} +2 -2
  48. package/dist/{mock-fetch-gateway-Q6P723KA.js → mock-fetch-gateway-5FABDZ5I.js} +2 -2
  49. package/dist/{mock-local-deps-FHH4S4TB.js → mock-local-deps-DTNPB3JC.js} +5 -4
  50. package/dist/{mock-server-MX2BMUBB.js → mock-server-575CLUOW.js} +3 -3
  51. package/dist/{open-api-client-ZGLGMDKA.js → open-api-client-WTCB3SYP.js} +4 -3
  52. package/dist/package-app-dev.d.ts +26 -0
  53. package/dist/publish-builder.js +41 -3
  54. package/dist/{remote-execute-SOSMXVTG.js → remote-execute-7RUQH5S4.js} +4 -3
  55. package/dist/remote-execute-7RUQH5S4.js.map +6 -0
  56. package/dist/{run-executor-4NQ65T6B.js → run-executor-6AZ2WP5F.js} +2 -2
  57. package/dist/{setup-git-QGJOYTHH.js → setup-git-C7UEZX26.js} +5 -4
  58. package/dist/{whoami-A77EEULC.js → whoami-VG4OKEIS.js} +3 -3
  59. package/package.json +2 -2
  60. package/dist/chunk-7BGOL5PB.js.map +0 -6
  61. package/dist/chunk-7XY3VABI.js.map +0 -6
  62. package/dist/chunk-AIRKIBWV.js.map +0 -6
  63. package/dist/chunk-GZCZPBUM.js.map +0 -6
  64. package/dist/chunk-SNXLFUYP.js.map +0 -6
  65. package/dist/chunk-XIZ7EZDP.js.map +0 -6
  66. package/dist/dev-command-HRLCH7SC.js.map +0 -6
  67. package/dist/git-credential-HFCBL3TZ.js.map +0 -6
  68. package/dist/local-execute-FAALT4AL.js.map +0 -6
  69. package/dist/local-secrets-LMXJBIPU.js.map +0 -6
  70. package/dist/remote-execute-SOSMXVTG.js.map +0 -6
  71. /package/dist/{auth-CJGMSRPQ.js.map → auth-QVKERRWX.js.map} +0 -0
  72. /package/dist/{chunk-EKVVIFRW.js.map → chunk-3STT5AKR.js.map} +0 -0
  73. /package/dist/{chunk-NBJ3X25P.js.map → chunk-DJMZA33K.js.map} +0 -0
  74. /package/dist/{chunk-C42MRUTR.js.map → chunk-G7PO2D4W.js.map} +0 -0
  75. /package/dist/{chunk-WEJLTJUI.js.map → chunk-TO2NVKC3.js.map} +0 -0
  76. /package/dist/{chunk-6T3ZZBRY.js.map → chunk-UMTYOOTV.js.map} +0 -0
  77. /package/dist/{commands-PLHV77ZM.js.map → commands-UOA3PH5D.js.map} +0 -0
  78. /package/dist/{local-package-graph-QSRKLQIP.js.map → local-package-graph-4OV2YXQV.js.map} +0 -0
  79. /package/dist/{local-package-run-LZTXOFKQ.js.map → local-package-run-OYQDFXPJ.js.map} +0 -0
  80. /package/dist/{mock-dep-resolve-42AMGI4V.js.map → mock-dep-resolve-QTL45S2K.js.map} +0 -0
  81. /package/dist/{mock-fetch-gateway-Q6P723KA.js.map → mock-fetch-gateway-5FABDZ5I.js.map} +0 -0
  82. /package/dist/{mock-local-deps-FHH4S4TB.js.map → mock-local-deps-DTNPB3JC.js.map} +0 -0
  83. /package/dist/{mock-server-MX2BMUBB.js.map → mock-server-575CLUOW.js.map} +0 -0
  84. /package/dist/{open-api-client-ZGLGMDKA.js.map → open-api-client-WTCB3SYP.js.map} +0 -0
  85. /package/dist/{run-executor-4NQ65T6B.js.map → run-executor-6AZ2WP5F.js.map} +0 -0
  86. /package/dist/{setup-git-QGJOYTHH.js.map → setup-git-C7UEZX26.js.map} +0 -0
  87. /package/dist/{whoami-A77EEULC.js.map → whoami-VG4OKEIS.js.map} +0 -0
@@ -12,7 +12,7 @@ import {
12
12
  resolveLocalPackageBinding,
13
13
  runLocalPackageModule,
14
14
  trustedDevHostFromHostedUrl
15
- } from "./chunk-6T3ZZBRY.js";
15
+ } from "./chunk-UMTYOOTV.js";
16
16
  import {
17
17
  assertDevHostAllowed,
18
18
  defaultDevHost,
@@ -20,6 +20,12 @@ import {
20
20
  parseDevHost,
21
21
  planDevListen
22
22
  } from "./chunk-TJ4YVG6B.js";
23
+ import {
24
+ collectPackageCheckFiles,
25
+ formatUnpublishedBundleInputMessage,
26
+ listPackageCheckPaths,
27
+ unpublishedBundleInputPaths
28
+ } from "./chunk-IEGR76KD.js";
23
29
  import {
24
30
  publishOutsideCloudAdvice
25
31
  } from "./chunk-3UTX2E3H.js";
@@ -28,21 +34,21 @@ import {
28
34
  forwardLocalGatewayFetchStream,
29
35
  installMockFetchShimModules,
30
36
  startLocalRuntimeBridge
31
- } from "./chunk-C42MRUTR.js";
37
+ } from "./chunk-G7PO2D4W.js";
32
38
  import {
33
39
  ensureMockTarget
34
- } from "./chunk-GZCZPBUM.js";
40
+ } from "./chunk-53PQCA4T.js";
35
41
  import {
36
42
  packageMocksRelativePath,
37
43
  resolveMockFetchGateway,
38
44
  tryHandleMockGatewayFetchCall
39
- } from "./chunk-M44CO6QB.js";
45
+ } from "./chunk-7P4IRMKT.js";
40
46
  import "./chunk-LQNGII7U.js";
41
47
  import {
42
48
  cleanWorkerdStderrLine,
43
49
  startWorkerd
44
50
  } from "./chunk-PPVTGF73.js";
45
- import "./chunk-NBJ3X25P.js";
51
+ import "./chunk-DJMZA33K.js";
46
52
  import {
47
53
  BundleError,
48
54
  bundleInputs,
@@ -61,7 +67,7 @@ import {
61
67
  resolveLocalPackageGraph,
62
68
  runSecretEnvVar,
63
69
  writePackageModuleFiles
64
- } from "./chunk-7BGOL5PB.js";
70
+ } from "./chunk-TIXLYGDA.js";
65
71
  import "./chunk-F6SEQDAM.js";
66
72
  import {
67
73
  loadPackageManifest,
@@ -77,12 +83,13 @@ import {
77
83
  import {
78
84
  redact
79
85
  } from "./chunk-CASGRYOF.js";
80
- import "./chunk-SNXLFUYP.js";
86
+ import "./chunk-KYB2MPO3.js";
81
87
  import {
82
88
  assertTokenSafeApiUrl,
83
89
  callCapabilityProxy
84
- } from "./chunk-XIZ7EZDP.js";
90
+ } from "./chunk-PRJ5BA7K.js";
85
91
  import "./chunk-UNRRMZM2.js";
92
+ import "./chunk-G6LJWROP.js";
86
93
  import "./chunk-X5L5M6AR.js";
87
94
  import "./chunk-AM2SBW3C.js";
88
95
  import "./chunk-N33Y3A4H.js";
@@ -97,8 +104,8 @@ import "./chunk-YVWOK4LV.js";
97
104
  import "./chunk-UW6AWLXX.js";
98
105
 
99
106
  // src/dev-command.ts
100
- import { access, mkdir as mkdir3, readFile as readFile6, rm as rm4, writeFile as writeFile4 } from "node:fs/promises";
101
- import { dirname as dirname4, join as join10, resolve as resolve8 } from "node:path";
107
+ import { access, mkdir as mkdir3, readFile as readFile5, rm as rm4, writeFile as writeFile4 } from "node:fs/promises";
108
+ import { dirname as dirname4, join as join9, resolve as resolve8 } from "node:path";
102
109
 
103
110
  // src/credentialed-fetch-scan.ts
104
111
  var esModuleLexerReady = init();
@@ -1383,6 +1390,8 @@ function isProcessAlive(pid) {
1383
1390
 
1384
1391
  // src/dev/dev-registry.ts
1385
1392
  var devStatusPath = "/__kody/dev/status";
1393
+ var devOutboxPath = "/__kody/dev/outbox";
1394
+ var devCallPath = "/__kody/dev/call";
1386
1395
  function devRegistryPath(root, target, cacheDir = userCacheDir()) {
1387
1396
  const key = createHash3("sha256").update(`${root}\0${target}`).digest("hex").slice(0, 16);
1388
1397
  return join5(cacheDir, "dev-servers", `${key}.json`);
@@ -2457,11 +2466,11 @@ function createPattern(matcher) {
2457
2466
  if (matcher.path === string)
2458
2467
  return true;
2459
2468
  if (matcher.recursive) {
2460
- const relative7 = sysPath2.relative(matcher.path, string);
2461
- if (!relative7) {
2469
+ const relative6 = sysPath2.relative(matcher.path, string);
2470
+ if (!relative6) {
2462
2471
  return false;
2463
2472
  }
2464
- return !relative7.startsWith("..") && !sysPath2.isAbsolute(relative7);
2473
+ return !relative6.startsWith("..") && !sysPath2.isAbsolute(relative6);
2465
2474
  }
2466
2475
  return false;
2467
2476
  };
@@ -4126,6 +4135,7 @@ async function startPackageAppDev(options) {
4126
4135
  });
4127
4136
  const killAllSync = () => {
4128
4137
  for (const generation of generations) {
4138
+ if (generation.upstream) continue;
4129
4139
  try {
4130
4140
  process.kill(generation.workerd.pid, "SIGKILL");
4131
4141
  } catch {
@@ -4155,6 +4165,66 @@ async function startPackageAppDev(options) {
4155
4165
  const address = proxy.address();
4156
4166
  const listenPlan = planDevListen({ bindHost: host, port: address.port });
4157
4167
  const { hostedUrl, localUrl, networkUrls } = listenPlan;
4168
+ proxy.on("upgrade", (req, socket, head) => {
4169
+ const upstream = active?.upstream;
4170
+ const publicHost = resolveAllowedDevHost({
4171
+ incomingHost: req.headers.host,
4172
+ trustedHost: trustedDevHostFromHostedUrl(hostedUrl),
4173
+ aliases: [
4174
+ ...options.hostAliases ?? [],
4175
+ ...listenPlan.extraAllowedHosts()
4176
+ ]
4177
+ });
4178
+ if (!upstream || !publicHost) {
4179
+ socket.destroy();
4180
+ return;
4181
+ }
4182
+ const incomingUrl = new URL(req.url ?? "/", hostedUrl);
4183
+ const restPath = stripMount(incomingUrl.pathname, appBasePath);
4184
+ const forwardUrl = new URL(
4185
+ buildTrustedDevForwardUrl({
4186
+ baseUrl: upstream.origin,
4187
+ restPath: `${upstream.appPath}${restPath === "/" ? "/" : restPath}`,
4188
+ search: incomingUrl.search
4189
+ })
4190
+ );
4191
+ const upstreamReq = httpRequest(forwardUrl, {
4192
+ method: req.method,
4193
+ headers: devVisitorHeaders(req.headers, {
4194
+ host: forwardUrl.host,
4195
+ cookie: upstream.cookie
4196
+ })
4197
+ });
4198
+ upstreamReq.on("upgrade", (upstreamRes, upstreamSocket, upstreamHead) => {
4199
+ const lines = [
4200
+ `HTTP/1.1 101 ${upstreamRes.statusMessage ?? "Switching Protocols"}`
4201
+ ];
4202
+ for (let i = 0; i < upstreamRes.rawHeaders.length; i += 2) {
4203
+ lines.push(
4204
+ `${upstreamRes.rawHeaders[i]}: ${upstreamRes.rawHeaders[i + 1]}`
4205
+ );
4206
+ }
4207
+ socket.write(`${lines.join("\r\n")}\r
4208
+ \r
4209
+ `);
4210
+ if (upstreamHead.length > 0) socket.write(upstreamHead);
4211
+ if (head.length > 0) upstreamSocket.write(head);
4212
+ upstreamSocket.pipe(socket).pipe(upstreamSocket);
4213
+ upstreamSocket.on("error", () => socket.destroy());
4214
+ socket.on("error", () => upstreamSocket.destroy());
4215
+ });
4216
+ upstreamReq.on("response", (upstreamRes) => {
4217
+ socket.end(
4218
+ `HTTP/1.1 ${upstreamRes.statusCode ?? 502} ${upstreamRes.statusMessage ?? ""}\r
4219
+ connection: close\r
4220
+ \r
4221
+ `
4222
+ );
4223
+ upstreamRes.resume();
4224
+ });
4225
+ upstreamReq.on("error", () => socket.destroy());
4226
+ upstreamReq.end();
4227
+ });
4158
4228
  try {
4159
4229
  await options.onListening?.({
4160
4230
  port: address.port,
@@ -4394,6 +4464,33 @@ async function startPackageAppDev(options) {
4394
4464
  async function startGeneration(bundle, client2) {
4395
4465
  const id = ++generationCounter;
4396
4466
  const dir = join8(workDir, `g${id}`);
4467
+ if (options.localKody) {
4468
+ await options.localKody.sync();
4469
+ const generation2 = {
4470
+ id,
4471
+ dir,
4472
+ workerd: {
4473
+ pid: 0,
4474
+ port: Number(new URL(options.localKody.origin).port),
4475
+ exited: new Promise(() => {
4476
+ }),
4477
+ kill: async () => {
4478
+ }
4479
+ },
4480
+ upstream: options.localKody,
4481
+ code: bundle.code,
4482
+ client: client2,
4483
+ mapStack: createStackMapper({
4484
+ sourceMap: bundle.sourceMap,
4485
+ userModule: localWorkerModuleNames.user
4486
+ }),
4487
+ inflight: 0,
4488
+ retired: false,
4489
+ stopped: false
4490
+ };
4491
+ generations.add(generation2);
4492
+ return generation2;
4493
+ }
4397
4494
  await writeWorkerFiles({
4398
4495
  workDir: dir,
4399
4496
  code: bundle.code,
@@ -4480,8 +4577,10 @@ async function startPackageAppDev(options) {
4480
4577
  if (generation.stopped) return;
4481
4578
  generation.stopped = true;
4482
4579
  generation.retired = true;
4483
- await generation.workerd.kill();
4484
- reaper.untrack(generation.workerd.pid);
4580
+ if (!generation.upstream) {
4581
+ await generation.workerd.kill();
4582
+ reaper.untrack(generation.workerd.pid);
4583
+ }
4485
4584
  generations.delete(generation);
4486
4585
  await rm3(generation.dir, { recursive: true, force: true });
4487
4586
  }
@@ -4540,6 +4639,61 @@ async function startPackageAppDev(options) {
4540
4639
  `);
4541
4640
  return true;
4542
4641
  }
4642
+ if (pathname === devCallPath) {
4643
+ const send2 = (code, body) => {
4644
+ res.writeHead(code, {
4645
+ "content-type": "application/json; charset=utf-8",
4646
+ "cache-control": "no-store"
4647
+ });
4648
+ res.end(`${JSON.stringify(body, null, 2)}
4649
+ `);
4650
+ };
4651
+ const localKody = options.localKody;
4652
+ if (!localKody || req.method !== "POST") {
4653
+ send2(localKody ? 405 : 404, {
4654
+ error: localKody ? "POST {operation, input}." : "This kody dev server is not running local Kody."
4655
+ });
4656
+ return true;
4657
+ }
4658
+ void readDevCallBody(req).then(async ({ operation, input }) => {
4659
+ if (!devCallOperations.has(operation)) {
4660
+ send2(400, {
4661
+ error: `Unsupported operation ${JSON.stringify(operation)}.`
4662
+ });
4663
+ return;
4664
+ }
4665
+ await waitForBuild();
4666
+ const packageId = localKody.packageId();
4667
+ const scoped = packageId && operation !== "jobList" && operation !== "jobRunNow" ? { ...input, package_id: packageId } : input;
4668
+ send2(200, { result: await localKody.call(operation, scoped) });
4669
+ }).catch(
4670
+ (error) => send2(502, {
4671
+ error: error instanceof Error ? error.message : String(error)
4672
+ })
4673
+ );
4674
+ return true;
4675
+ }
4676
+ if (pathname === devOutboxPath) {
4677
+ const send2 = (code, body) => {
4678
+ res.writeHead(code, {
4679
+ "content-type": "application/json; charset=utf-8",
4680
+ "cache-control": "no-store"
4681
+ });
4682
+ res.end(`${JSON.stringify(body, null, 2)}
4683
+ `);
4684
+ };
4685
+ if (!options.localKody) {
4686
+ send2(200, { count: 0, messages: [] });
4687
+ return true;
4688
+ }
4689
+ options.localKody.listOutbox().then(
4690
+ (outbox) => send2(200, outbox),
4691
+ (error) => send2(502, {
4692
+ error: error instanceof Error ? error.message : String(error)
4693
+ })
4694
+ );
4695
+ return true;
4696
+ }
4543
4697
  if (!liveReload) return false;
4544
4698
  if (pathname === liveReloadEventsPath) {
4545
4699
  liveReloadHub.handleEvents(req, res);
@@ -4634,10 +4788,11 @@ async function startPackageAppDev(options) {
4634
4788
  restPath,
4635
4789
  search: incomingUrl.search
4636
4790
  });
4791
+ const upstream = generation.upstream;
4637
4792
  const forwardUrl = new URL(
4638
4793
  buildTrustedDevForwardUrl({
4639
- baseUrl: `http://127.0.0.1:${generation.workerd.port}`,
4640
- restPath,
4794
+ baseUrl: upstream?.origin ?? `http://127.0.0.1:${generation.workerd.port}`,
4795
+ restPath: upstream ? `${upstream.appPath}${restPath === "/" ? "/" : restPath}` : restPath,
4641
4796
  search: incomingUrl.search
4642
4797
  })
4643
4798
  );
@@ -4653,8 +4808,27 @@ async function startPackageAppDev(options) {
4653
4808
  runSecret,
4654
4809
  requestId: tag.id
4655
4810
  });
4811
+ if (upstream) {
4812
+ headers.host = forwardUrl.host;
4813
+ if (isAnonymousDevVisitor(req.headers)) delete headers.cookie;
4814
+ else headers.cookie = upstream.cookie;
4815
+ delete headers[devVisitorHeader];
4816
+ }
4817
+ const startedAt2 = performance.now();
4818
+ const cpuLimitMs = options.cpuLimitMs ?? defaultDevCpuLimitMs;
4819
+ const warnIfOverCpuLimit = () => {
4820
+ const ms = Math.round(performance.now() - startedAt2);
4821
+ if (cpuLimitMs <= 0 || ms <= cpuLimitMs) return;
4822
+ emit({
4823
+ type: "log",
4824
+ source: "app",
4825
+ level: "warn",
4826
+ message: `took ${ms}ms, over the ${cpuLimitMs}ms CPU limit (simulated from wall time; Cloudflare may stop this request)`,
4827
+ request: tag
4828
+ });
4829
+ };
4656
4830
  return new Promise((resolve9, reject) => {
4657
- const upstream = httpRequest(
4831
+ const upstream2 = httpRequest(
4658
4832
  forwardUrl,
4659
4833
  { method: req.method, headers },
4660
4834
  (upstreamRes) => {
@@ -4694,16 +4868,19 @@ async function startPackageAppDev(options) {
4694
4868
  }
4695
4869
  res.writeHead(status2, upstreamRes.headers);
4696
4870
  upstreamRes.pipe(res);
4697
- upstreamRes.on("end", () => resolve9());
4871
+ upstreamRes.on("end", () => {
4872
+ warnIfOverCpuLimit();
4873
+ resolve9();
4874
+ });
4698
4875
  upstreamRes.on("error", reject);
4699
4876
  }
4700
4877
  );
4701
- upstream.on("error", reject);
4878
+ upstream2.on("error", reject);
4702
4879
  res.on("close", () => {
4703
- if (!res.writableFinished) upstream.destroy();
4880
+ if (!res.writableFinished) upstream2.destroy();
4704
4881
  resolve9();
4705
4882
  });
4706
- req.pipe(upstream);
4883
+ req.pipe(upstream2);
4707
4884
  });
4708
4885
  }
4709
4886
  function respondWithRuntimeError(generation, req, res, tag, raw) {
@@ -4992,112 +5169,33 @@ function joinUrlPath(base, path) {
4992
5169
  if (!base) return rest;
4993
5170
  return `${base}${rest === "/" ? "" : rest}` || base;
4994
5171
  }
4995
-
4996
- // src/package-check-files.ts
4997
- import { execFile } from "node:child_process";
4998
- import { readdir as readdir4, readFile as readFile5 } from "node:fs/promises";
4999
- import { isAbsolute as isAbsolute2, join as join9, relative as relative6, sep as sep4 } from "node:path";
5000
- import { promisify } from "node:util";
5001
- import ignore from "ignore";
5002
- var execFileAsync = promisify(execFile);
5003
- var skippedDirectories = /* @__PURE__ */ new Set(["node_modules", ".git"]);
5004
- async function listGitFiles(root) {
5005
- try {
5006
- const { stdout } = await execFileAsync(
5007
- "git",
5008
- ["ls-files", "-z", "--cached", "--others", "--exclude-standard"],
5009
- { cwd: root, maxBuffer: 64 * 1024 * 1024 }
5010
- );
5011
- return stdout.split("\0").filter((path) => path.length > 0);
5012
- } catch {
5013
- return null;
5014
- }
5015
- }
5016
- async function walkFiles(root, dir = root) {
5017
- const entries = await readdir4(dir, { withFileTypes: true });
5018
- const files = [];
5019
- for (const entry of entries) {
5020
- if (entry.isDirectory()) {
5021
- if (skippedDirectories.has(entry.name)) continue;
5022
- files.push(...await walkFiles(root, join9(dir, entry.name)));
5023
- } else if (entry.isFile()) {
5024
- files.push(relative6(root, join9(dir, entry.name)).split(sep4).join("/"));
5025
- }
5026
- }
5027
- return files;
5028
- }
5029
- var kodyIgnoreFileName = ".kodyignore";
5030
- var neverKodyIgnored = /* @__PURE__ */ new Set(["package.json", kodyIgnoreFileName]);
5031
- function createKodyIgnoreMatcher(content) {
5032
- if (content == null || content.trim() === "") return null;
5033
- const matcher = ignore().add(content);
5034
- return (relativePath) => {
5035
- const path = relativePath.replace(/^\/+/, "");
5036
- if (path === "" || neverKodyIgnored.has(path)) return false;
5037
- try {
5038
- return matcher.ignores(path);
5039
- } catch {
5040
- return false;
5041
- }
5042
- };
5043
- }
5044
- async function readKodyIgnore(root) {
5045
- try {
5046
- return await readFile5(join9(root, kodyIgnoreFileName), "utf8");
5047
- } catch {
5048
- return null;
5049
- }
5050
- }
5051
- async function listPackageCheckPaths(root) {
5052
- const paths = await listGitFiles(root) ?? await walkFiles(root);
5053
- const isKodyIgnored = createKodyIgnoreMatcher(await readKodyIgnore(root));
5054
- return paths.filter(
5055
- (path) => !path.split("/").some((segment) => skippedDirectories.has(segment)) && !isKodyIgnored?.(path)
5056
- ).sort();
5057
- }
5058
- function unpublishedBundleInputPaths(input) {
5059
- const missing = [];
5060
- for (const absolute of input.absoluteInputs) {
5061
- const rel = relative6(input.packageRoot, absolute);
5062
- if (!rel || rel.startsWith(`..${sep4}`) || rel === ".." || isAbsolute2(rel)) {
5063
- missing.push(rel.split(sep4).join("/") || absolute);
5064
- continue;
5065
- }
5066
- const posix = rel.split(sep4).join("/");
5067
- if (!input.snapshotPaths.has(posix)) {
5068
- missing.push(posix);
5069
- }
5070
- }
5071
- return missing;
5072
- }
5073
- function formatUnpublishedBundleInputMessage(relativePath, options) {
5074
- const base = `${relativePath} is imported but will not be in the published snapshot (gitignored, untracked, or matched by .kodyignore). Commit it and keep it out of .kodyignore, or generate it somewhere publish can see.`;
5075
- if (options?.hasPrebuild === true) {
5076
- return `${base} Note: kody.dev.prebuild runs only in \`kody dev\`; publish builds the git snapshot, so commit generated output.`;
5077
- }
5078
- return base;
5079
- }
5080
- var utf8 = new TextDecoder("utf-8", { fatal: true });
5081
- async function collectPackageCheckFiles(root) {
5082
- const paths = await listPackageCheckPaths(root);
5083
- const files = {};
5084
- const binaryFiles = {};
5085
- const binaryContents = {};
5086
- for (const path of paths) {
5087
- let bytes;
5088
- try {
5089
- bytes = await readFile5(join9(root, path));
5090
- } catch {
5091
- continue;
5092
- }
5093
- try {
5094
- files[path] = utf8.decode(bytes);
5095
- } catch {
5096
- binaryFiles[path] = bytes.byteLength;
5097
- binaryContents[path] = bytes.toString("base64");
5098
- }
5172
+ var defaultDevCpuLimitMs = 3e4;
5173
+ var devVisitorHeader = "x-kody-dev-visitor";
5174
+ function isAnonymousDevVisitor(headers) {
5175
+ return String(headers[devVisitorHeader] ?? "").trim() === "anonymous";
5176
+ }
5177
+ function devVisitorHeaders(base, local) {
5178
+ const headers = { ...base, host: local.host };
5179
+ delete headers[devVisitorHeader];
5180
+ if (isAnonymousDevVisitor(base)) delete headers.cookie;
5181
+ else headers.cookie = local.cookie;
5182
+ return headers;
5183
+ }
5184
+ var devCallOperations = /* @__PURE__ */ new Set([
5185
+ "jobList",
5186
+ "jobRunNow",
5187
+ "packageSubscriptionDispatch",
5188
+ "webhookSyntheticDispatch"
5189
+ ]);
5190
+ async function readDevCallBody(req) {
5191
+ const chunks = [];
5192
+ for await (const chunk of req) chunks.push(Buffer.from(chunk));
5193
+ const parsed = JSON.parse(Buffer.concat(chunks).toString("utf8"));
5194
+ if (typeof parsed.operation !== "string") {
5195
+ throw new Error("POST {operation, input}.");
5099
5196
  }
5100
- return { files, binaryFiles, binaryContents };
5197
+ const input = parsed.input && typeof parsed.input === "object" && !Array.isArray(parsed.input) ? parsed.input : {};
5198
+ return { operation: parsed.operation, input };
5101
5199
  }
5102
5200
 
5103
5201
  // src/dev-command.ts
@@ -5158,9 +5256,11 @@ async function runDevServe(input) {
5158
5256
  const onEvent = input.json ? (event) => writeJsonEvent(input.io, event) : (event) => writeDevEvent(input.io, event);
5159
5257
  let registered = false;
5160
5258
  let server;
5259
+ const localKody = input.startLocalKody ? await input.startLocalKody(manifest) : null;
5161
5260
  try {
5162
5261
  server = await startPackageAppDev({
5163
5262
  manifest,
5263
+ ...localKody ? { localKody: localKody.upstream } : {},
5164
5264
  token: input.auth.token,
5165
5265
  apiUrl: input.auth.apiUrl,
5166
5266
  target: input.target,
@@ -5173,6 +5273,7 @@ async function runDevServe(input) {
5173
5273
  ...input.passthroughHosts?.length ? { passthroughHosts: input.passthroughHosts } : input.auth.passthroughHosts?.length ? { passthroughHosts: input.auth.passthroughHosts } : {},
5174
5274
  allowPrivateNetwork: input.allowPrivateNetwork,
5175
5275
  liveReload: input.liveReload ?? true,
5276
+ ...input.cpuLimitMs !== void 0 ? { cpuLimitMs: input.cpuLimitMs } : {},
5176
5277
  onStatus: (message) => input.io.stderr(`${message}
5177
5278
  `),
5178
5279
  onError: (message) => input.io.stderr(`${message}
@@ -5206,10 +5307,12 @@ async function runDevServe(input) {
5206
5307
  });
5207
5308
  }
5208
5309
  await input.auth.closeMock?.();
5310
+ await localKody?.close();
5209
5311
  throw error;
5210
5312
  }
5211
5313
  const shutdown = async () => {
5212
5314
  await server.close();
5315
+ await localKody?.close();
5213
5316
  await removeDevRegistration(manifest.root, process.pid, input.target).catch(
5214
5317
  () => {
5215
5318
  }
@@ -5392,6 +5495,90 @@ ${result.body}
5392
5495
  await input.auth.closeMock?.();
5393
5496
  }
5394
5497
  }
5498
+ async function tryAttachedDevCall(input) {
5499
+ if (input.target !== "mock") return null;
5500
+ let manifest;
5501
+ try {
5502
+ manifest = await loadPackageManifest(input.cwd);
5503
+ } catch {
5504
+ return null;
5505
+ }
5506
+ const running = await findRunningDevServer({
5507
+ root: manifest.root,
5508
+ target: input.target
5509
+ });
5510
+ let call;
5511
+ let ranOn;
5512
+ let closeLocal;
5513
+ if (running) {
5514
+ const { registration } = running;
5515
+ const url = new URL(
5516
+ `${registration.basePath}${devCallPath}`,
5517
+ registration.origin
5518
+ );
5519
+ ranOn = `running kody dev (pid ${registration.pid})`;
5520
+ call = async (operation, args) => {
5521
+ const response = await fetch(url, {
5522
+ method: "POST",
5523
+ headers: { "content-type": "application/json" },
5524
+ body: JSON.stringify({ operation, input: args })
5525
+ });
5526
+ const body = await response.json().catch(() => null);
5527
+ if (response.status === 404) return devCallUnavailable;
5528
+ if (!response.ok) {
5529
+ throw new StructuredCliError({
5530
+ code: "dev_local_call_failed",
5531
+ message: body?.error ?? `Local Kody ${operation} failed (HTTP ${response.status}).`,
5532
+ target: input.target
5533
+ });
5534
+ }
5535
+ return body?.result;
5536
+ };
5537
+ } else {
5538
+ if (process.env.KODY_DEV_STUB_RUNTIME === "1") return null;
5539
+ const local = await import("./local-kody-NDNDB5MV.js");
5540
+ const kody = await local.startLocalKody({
5541
+ manifest,
5542
+ onStatus: (message) => input.io.stderr(`${message}
5543
+ `)
5544
+ });
5545
+ closeLocal = kody.close;
5546
+ ranOn = "a one-shot local Kody";
5547
+ try {
5548
+ const upstream = local.createLocalKodyUpstream({ kody, manifest });
5549
+ await upstream.sync();
5550
+ call = async (operation, args) => {
5551
+ const packageId = upstream.packageId();
5552
+ return await upstream.call(
5553
+ operation,
5554
+ packageId && operation !== "jobList" && operation !== "jobRunNow" ? { ...args, package_id: packageId } : args
5555
+ );
5556
+ };
5557
+ } catch (error) {
5558
+ await closeLocal();
5559
+ await input.closeMock?.();
5560
+ throw error;
5561
+ }
5562
+ }
5563
+ let first;
5564
+ try {
5565
+ first = await input.steps(call);
5566
+ } catch (error) {
5567
+ await closeLocal?.();
5568
+ await input.closeMock?.();
5569
+ throw error;
5570
+ }
5571
+ await closeLocal?.();
5572
+ if (first === devCallUnavailable) return null;
5573
+ await input.closeMock?.();
5574
+ input.io.stderr(`Ran on local Kody via ${ranOn}
5575
+ `);
5576
+ input.io.stdout(`${JSON.stringify(first, null, 2)}
5577
+ `);
5578
+ const failed = first && typeof first === "object" && "status" in first && typeof first.status === "number" && first.status >= 400;
5579
+ return failed ? 1 : 0;
5580
+ }
5581
+ var devCallUnavailable = /* @__PURE__ */ Symbol("devCallUnavailable");
5395
5582
  async function runDevJob(input) {
5396
5583
  const manifest = await loadPackageManifest(input.cwd);
5397
5584
  const job = manifest.jobs[input.jobName];
@@ -5422,6 +5609,28 @@ async function runDevJob(input) {
5422
5609
  closeMock: input.auth.closeMock
5423
5610
  });
5424
5611
  }
5612
+ const attached = await tryAttachedDevCall({
5613
+ target: input.target,
5614
+ cwd: input.cwd,
5615
+ io: input.io,
5616
+ closeMock: input.auth.closeMock,
5617
+ steps: async (call) => {
5618
+ const listed = await call("jobList", {});
5619
+ if (listed === devCallUnavailable) return listed;
5620
+ const jobs = listed.jobs ?? [];
5621
+ const match = jobs.find((entry) => entry.name === input.jobName);
5622
+ if (!match) {
5623
+ throw new StructuredCliError({
5624
+ code: "dev_surface_missing",
5625
+ message: `Local Kody has no job named ${JSON.stringify(input.jobName)} yet.`,
5626
+ fix: "Wait for the next kody dev rebuild to sync package jobs, then retry.",
5627
+ target: input.target
5628
+ });
5629
+ }
5630
+ return await call("jobRunNow", { id: match.id });
5631
+ }
5632
+ });
5633
+ if (attached !== null) return attached;
5425
5634
  return await runPackageModuleOnce({
5426
5635
  manifest,
5427
5636
  modulePath,
@@ -5446,7 +5655,7 @@ async function runDevWebhook(input) {
5446
5655
  target: input.target
5447
5656
  });
5448
5657
  }
5449
- const rawBody = await readFile6(
5658
+ const rawBody = await readFile5(
5450
5659
  resolve8(input.cwd ?? process.cwd(), input.bodyPath),
5451
5660
  "utf8"
5452
5661
  );
@@ -5484,6 +5693,23 @@ async function runDevWebhook(input) {
5484
5693
  closeMock: input.auth.closeMock
5485
5694
  });
5486
5695
  }
5696
+ const attachedWebhook = await tryAttachedDevCall({
5697
+ target: input.target,
5698
+ cwd: input.cwd,
5699
+ io: input.io,
5700
+ closeMock: input.auth.closeMock,
5701
+ steps: async (call) => await call("webhookSyntheticDispatch", {
5702
+ webhookName: input.webhookName,
5703
+ ...webhook.inputMode === "params" ? { params: jsonBody ?? {} } : {
5704
+ request: {
5705
+ method: "POST",
5706
+ headers: { "content-type": "application/json" },
5707
+ body: rawBody
5708
+ }
5709
+ }
5710
+ })
5711
+ });
5712
+ if (attachedWebhook !== null) return attachedWebhook;
5487
5713
  return await runPackageModuleOnce({
5488
5714
  manifest,
5489
5715
  modulePath,
@@ -5513,11 +5739,11 @@ async function runDevEmit(input) {
5513
5739
  code: "dev_surface_missing",
5514
5740
  message: `No subscription for event ${JSON.stringify(input.event)} in package.json#kody.subscriptions.`,
5515
5741
  where: manifest.packageJsonPath,
5516
- fix: `Add a handler under kody.subscriptions[${JSON.stringify(input.event)}], then retry. Mock allows any event type once declared.`,
5742
+ fix: `Add a handler under kody.subscriptions[${JSON.stringify(input.event)}], then retry. A running kody dev checks the topic against the local event catalog.`,
5517
5743
  target: input.target
5518
5744
  });
5519
5745
  }
5520
- const rawBody = await readFile6(
5746
+ const rawBody = await readFile5(
5521
5747
  resolve8(input.cwd ?? process.cwd(), input.bodyPath),
5522
5748
  "utf8"
5523
5749
  );
@@ -5559,6 +5785,17 @@ async function runDevEmit(input) {
5559
5785
  closeMock: input.auth.closeMock
5560
5786
  });
5561
5787
  }
5788
+ const attachedEmit = await tryAttachedDevCall({
5789
+ target: input.target,
5790
+ cwd: input.cwd,
5791
+ io: input.io,
5792
+ closeMock: input.auth.closeMock,
5793
+ steps: async (call) => await call("packageSubscriptionDispatch", {
5794
+ topic: input.event,
5795
+ params: envelope
5796
+ })
5797
+ });
5798
+ if (attachedEmit !== null) return attachedEmit;
5562
5799
  return await runPackageModuleOnce({
5563
5800
  manifest,
5564
5801
  modulePath,
@@ -5750,13 +5987,13 @@ async function runDevCheck(input) {
5750
5987
  }
5751
5988
  }
5752
5989
  try {
5753
- await readFile6(resolve8(manifest.root, "README.md"));
5990
+ await readFile5(resolve8(manifest.root, "README.md"));
5754
5991
  push("README.md", true);
5755
5992
  } catch {
5756
5993
  push("README.md", false, "Publish requires README.md");
5757
5994
  }
5758
5995
  try {
5759
- await readFile6(resolve8(manifest.root, "AGENTS.md"));
5996
+ await readFile5(resolve8(manifest.root, "AGENTS.md"));
5760
5997
  push("AGENTS.md", true);
5761
5998
  } catch {
5762
5999
  push("AGENTS.md", false, "Publish requires AGENTS.md");
@@ -5789,7 +6026,7 @@ async function runDevCheck(input) {
5789
6026
  }
5790
6027
  let hasMocksFile = false;
5791
6028
  try {
5792
- await access(join10(manifest.root, packageMocksRelativePath));
6029
+ await access(join9(manifest.root, packageMocksRelativePath));
5793
6030
  hasMocksFile = true;
5794
6031
  } catch {
5795
6032
  hasMocksFile = false;
@@ -5992,7 +6229,7 @@ function parseDevSubcommand(positionals) {
5992
6229
  }
5993
6230
  async function removeOwnedReadyFile(path, ownerPid) {
5994
6231
  try {
5995
- const parsed = JSON.parse(await readFile6(path, "utf8"));
6232
+ const parsed = JSON.parse(await readFile5(path, "utf8"));
5996
6233
  if (parsed.pid !== ownerPid) return;
5997
6234
  await rm4(path, { force: true });
5998
6235
  } catch {
@@ -6019,4 +6256,4 @@ export {
6019
6256
  chokidar/esm/index.js:
6020
6257
  (*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) *)
6021
6258
  */
6022
- //# sourceMappingURL=dev-command-HRLCH7SC.js.map
6259
+ //# sourceMappingURL=dev-command-HQEI4YMG.js.map