@kodycodes/cli 3.45.5 → 3.45.7

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 (56) hide show
  1. package/dist/bin.js +1 -1
  2. package/dist/{chunk-TB7NX637.js → chunk-2OMFUIFM.js} +263 -119
  3. package/dist/chunk-2OMFUIFM.js.map +6 -0
  4. package/dist/{chunk-M6JCNIX6.js → chunk-2PJZFZB4.js} +2 -2
  5. package/dist/{remote-execute-K5T677LE.js → chunk-A2YYKKHG.js} +4 -11
  6. package/dist/chunk-A2YYKKHG.js.map +6 -0
  7. package/dist/{chunk-QGLAGTUX.js → chunk-BQISP46M.js} +38 -14
  8. package/dist/{chunk-QGLAGTUX.js.map → chunk-BQISP46M.js.map} +1 -1
  9. package/dist/{chunk-2RRDYVW3.js → chunk-BYPUQBDP.js} +4 -4
  10. package/dist/chunk-HYL2OFVE.js +302 -0
  11. package/dist/chunk-HYL2OFVE.js.map +6 -0
  12. package/dist/{chunk-Z5EBUX3U.js → chunk-PYDYPCST.js} +4 -4
  13. package/dist/{local-kody-2OCWWF6E.js → chunk-QCIN3KQT.js} +45 -28
  14. package/dist/chunk-QCIN3KQT.js.map +6 -0
  15. package/dist/{chunk-UC2OBYKG.js → chunk-VUVCPMIE.js} +11 -1
  16. package/dist/{chunk-UC2OBYKG.js.map → chunk-VUVCPMIE.js.map} +1 -1
  17. package/dist/{chunk-FZ67GC66.js → chunk-ZADDFBAP.js} +2 -2
  18. package/dist/cli.js +1 -1
  19. package/dist/{commands-BMIGLU7X.js → commands-FGJMFEDS.js} +2 -2
  20. package/dist/dev/dev-registry.d.ts +4 -0
  21. package/dist/dev/execute-local-package.d.ts +19 -0
  22. package/dist/dev/local-kody-session.d.ts +17 -0
  23. package/dist/dev/local-kody.d.ts +3 -0
  24. package/dist/{dev-command-K65OPONH.js → dev-command-VELMK2SY.js} +107 -442
  25. package/dist/dev-command-VELMK2SY.js.map +6 -0
  26. package/dist/dev-command.d.ts +4 -0
  27. package/dist/execute-local-package-GBTN56CS.js +116 -0
  28. package/dist/execute-local-package-GBTN56CS.js.map +6 -0
  29. package/dist/{local-execute-TL2JIRBK.js → local-execute-WNLIXCWZ.js} +3 -3
  30. package/dist/local-kody-IO7UOYO6.js +37 -0
  31. package/dist/{local-package-graph-VN53AG4I.js → local-package-graph-JH4L7OF3.js} +2 -2
  32. package/dist/{local-package-run-BXFC2HQE.js → local-package-run-7MNWRJHY.js} +5 -5
  33. package/dist/mock/mock-server.d.ts +2 -0
  34. package/dist/{mock-local-deps-2G5NX4MR.js → mock-local-deps-4FWQ2M2T.js} +3 -3
  35. package/dist/{mock-server-NM6XOOS3.js → mock-server-GCDZFOQN.js} +2 -2
  36. package/dist/mock-server-GCDZFOQN.js.map +6 -0
  37. package/dist/publish-builder.js +1 -0
  38. package/dist/remote-execute-3I42PSF7.js +25 -0
  39. package/dist/remote-execute-3I42PSF7.js.map +6 -0
  40. package/dist/{run-executor-WN6W7JKN.js → run-executor-PYY7GUZC.js} +2 -2
  41. package/package.json +1 -1
  42. package/dist/chunk-TB7NX637.js.map +0 -6
  43. package/dist/dev-command-K65OPONH.js.map +0 -6
  44. package/dist/local-kody-2OCWWF6E.js.map +0 -6
  45. package/dist/remote-execute-K5T677LE.js.map +0 -6
  46. /package/dist/{chunk-M6JCNIX6.js.map → chunk-2PJZFZB4.js.map} +0 -0
  47. /package/dist/{chunk-2RRDYVW3.js.map → chunk-BYPUQBDP.js.map} +0 -0
  48. /package/dist/{chunk-Z5EBUX3U.js.map → chunk-PYDYPCST.js.map} +0 -0
  49. /package/dist/{chunk-FZ67GC66.js.map → chunk-ZADDFBAP.js.map} +0 -0
  50. /package/dist/{commands-BMIGLU7X.js.map → commands-FGJMFEDS.js.map} +0 -0
  51. /package/dist/{local-execute-TL2JIRBK.js.map → local-execute-WNLIXCWZ.js.map} +0 -0
  52. /package/dist/{local-package-graph-VN53AG4I.js.map → local-kody-IO7UOYO6.js.map} +0 -0
  53. /package/dist/{local-package-run-BXFC2HQE.js.map → local-package-graph-JH4L7OF3.js.map} +0 -0
  54. /package/dist/{mock-local-deps-2G5NX4MR.js.map → local-package-run-7MNWRJHY.js.map} +0 -0
  55. /package/dist/{mock-server-NM6XOOS3.js.map → mock-local-deps-4FWQ2M2T.js.map} +0 -0
  56. /package/dist/{run-executor-WN6W7JKN.js.map → run-executor-PYY7GUZC.js.map} +0 -0
@@ -1,4 +1,34 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
+ import {
3
+ publishOutsideCloudAdvice
4
+ } from "./chunk-XQY2VX3O.js";
5
+ import {
6
+ defaultDevPort,
7
+ devCallPath,
8
+ devCallUnavailable,
9
+ devOutboxPath,
10
+ devStatusPath,
11
+ findRunningDevServer,
12
+ listenDevServer,
13
+ parseDevPort,
14
+ removeDevRegistration,
15
+ reserveDevPort,
16
+ resolveLocalKodySession,
17
+ writeDevRegistration
18
+ } from "./chunk-HYL2OFVE.js";
19
+ import {
20
+ collectPackageCheckFiles,
21
+ devPackageAppOrigin,
22
+ devWorkDirPrefix,
23
+ findPackageFetchBodyWarnings,
24
+ formatFetchBodySecretResolutionWarning,
25
+ formatUnpublishedBundleInputMessage,
26
+ listPackageCheckPaths,
27
+ localUsernameFor,
28
+ startProcessReaper,
29
+ sweepStaleDevDirs,
30
+ unpublishedBundleInputPaths
31
+ } from "./chunk-2OMFUIFM.js";
2
32
  import {
3
33
  appLogMarker,
4
34
  buildDevProxyUpstreamHeaders,
@@ -12,7 +42,7 @@ import {
12
42
  resolveLocalPackageBinding,
13
43
  runLocalPackageModule,
14
44
  trustedDevHostFromHostedUrl
15
- } from "./chunk-Z5EBUX3U.js";
45
+ } from "./chunk-PYDYPCST.js";
16
46
  import {
17
47
  assertDevHostAllowed,
18
48
  defaultDevHost,
@@ -20,28 +50,15 @@ import {
20
50
  parseDevHost,
21
51
  planDevListen
22
52
  } from "./chunk-CSXFRVBI.js";
23
- import {
24
- collectPackageCheckFiles,
25
- devPackageAppOrigin,
26
- findPackageFetchBodyWarnings,
27
- formatFetchBodySecretResolutionWarning,
28
- formatUnpublishedBundleInputMessage,
29
- listPackageCheckPaths,
30
- localUsernameFor,
31
- unpublishedBundleInputPaths
32
- } from "./chunk-TB7NX637.js";
33
- import {
34
- publishOutsideCloudAdvice
35
- } from "./chunk-XQY2VX3O.js";
36
53
  import {
37
54
  assertLocalPackageScopedSecretWriteAllowed,
38
55
  forwardLocalGatewayFetchStream,
39
56
  installMockFetchShimModules,
40
57
  startLocalRuntimeBridge
41
- } from "./chunk-M6JCNIX6.js";
58
+ } from "./chunk-2PJZFZB4.js";
42
59
  import {
43
60
  ensureMockTarget
44
- } from "./chunk-UC2OBYKG.js";
61
+ } from "./chunk-VUVCPMIE.js";
45
62
  import {
46
63
  packageMocksRelativePath,
47
64
  resolveMockFetchGateway,
@@ -52,7 +69,7 @@ import {
52
69
  cleanWorkerdStderrLine,
53
70
  startWorkerd
54
71
  } from "./chunk-PPVTGF73.js";
55
- import "./chunk-FZ67GC66.js";
72
+ import "./chunk-ZADDFBAP.js";
56
73
  import {
57
74
  BundleError,
58
75
  bundleInputs,
@@ -71,7 +88,7 @@ import {
71
88
  resolveLocalPackageGraph,
72
89
  runSecretEnvVar,
73
90
  writePackageModuleFiles
74
- } from "./chunk-2RRDYVW3.js";
91
+ } from "./chunk-BYPUQBDP.js";
75
92
  import "./chunk-2PCUYOMX.js";
76
93
  import {
77
94
  loadPackageManifest,
@@ -100,15 +117,14 @@ import {
100
117
  apiTokenEnvVar
101
118
  } from "./chunk-NKH2L5RA.js";
102
119
  import {
103
- ensureWorkerdBinary,
104
- userCacheDir
120
+ ensureWorkerdBinary
105
121
  } from "./chunk-VHYJU2U2.js";
106
122
  import "./chunk-YVWOK4LV.js";
107
123
  import "./chunk-UW6AWLXX.js";
108
124
 
109
125
  // src/dev-command.ts
110
- import { access, mkdir as mkdir3, readFile as readFile4, rm as rm4, writeFile as writeFile4 } from "node:fs/promises";
111
- import { dirname as dirname3, join as join8, resolve as resolve7 } from "node:path";
126
+ import { access, mkdir as mkdir2, readFile as readFile2, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
127
+ import { dirname as dirname3, join as join6, resolve as resolve7 } from "node:path";
112
128
 
113
129
  // src/credentialed-fetch-scan.ts
114
130
  var esModuleLexerReady = init();
@@ -183,13 +199,13 @@ function mocksSuggestionDetail(input) {
183
199
  // src/package-app-dev.ts
184
200
  import { randomBytes } from "node:crypto";
185
201
  import { rmSync, statSync } from "node:fs";
186
- import { mkdir as mkdir2, mkdtemp, rm as rm3, writeFile as writeFile3 } from "node:fs/promises";
202
+ import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
187
203
  import {
188
- createServer as createServer2,
204
+ createServer,
189
205
  request as httpRequest
190
206
  } from "node:http";
191
- import { tmpdir as tmpdir2 } from "node:os";
192
- import { join as join7, relative as relative4, resolve as resolve6, sep as sep3 } from "node:path";
207
+ import { tmpdir } from "node:os";
208
+ import { join as join5, relative as relative4, resolve as resolve6, sep as sep3 } from "node:path";
193
209
 
194
210
  // src/dev/dev-assets.ts
195
211
  import * as esbuild2 from "esbuild";
@@ -526,321 +542,14 @@ fix: ${event.fix}` : ""}`
526
542
  }
527
543
  }
528
544
 
529
- // src/dev/dev-port.ts
530
- import { createHash as createHash2 } from "node:crypto";
531
- import { createServer } from "node:http";
532
- var devPortRange = { min: 4100, max: 4999 };
533
- var fallbackAttempts = 20;
534
- function defaultDevPort(kodyId) {
535
- const span = devPortRange.max - devPortRange.min + 1;
536
- const hash = createHash2("sha256").update(kodyId).digest();
537
- return devPortRange.min + hash.readUInt32BE(0) % span;
538
- }
539
- function parseDevPort(raw) {
540
- const port = /^\d+$/.test(raw.trim()) ? Number(raw) : Number.NaN;
541
- if (!Number.isInteger(port) || port > 65535) {
542
- throw new StructuredCliError({
543
- code: "invalid_port",
544
- message: `--port must be an integer from 0 to 65535 (got "${raw}").`,
545
- fix: "Pass --port 0 for any free port, or omit --port to use this package\u2019s stable default."
546
- });
547
- }
548
- return port;
549
- }
550
- async function listenDevServer(server, input) {
551
- const attempts = input.explicit || input.port === 0 ? 1 : fallbackAttempts;
552
- for (let attempt = 0; attempt < attempts; attempt += 1) {
553
- const port = input.port === 0 ? 0 : wrapPort(input.port + attempt);
554
- try {
555
- await listenOnce(server, input.host, port);
556
- return server.address().port;
557
- } catch (error) {
558
- if (isAddressUnavailable(error)) throw hostUnavailableError(input.host);
559
- if (input.explicit) {
560
- if (isAddressInUse(error)) throw portInUseError(input.host, port);
561
- throw error;
562
- }
563
- if (!isAddressInUse(error) && !isPortReserved(error)) throw error;
564
- }
565
- }
566
- throw new StructuredCliError({
567
- code: "dev_port_in_use",
568
- message: `Ports ${input.port}\u2013${wrapPort(input.port + attempts - 1)} on ${input.host} are all in use.`,
569
- fix: "Stop old `kody dev` processes, or pass --port 0 for any free port."
570
- });
571
- }
572
- async function reserveDevPort(input) {
573
- const probe = createServer();
574
- const port = await listenDevServer(probe, input);
575
- await new Promise((resolve8) => probe.close(() => resolve8()));
576
- return port;
577
- }
578
- function portInUseError(host, port) {
579
- return new StructuredCliError({
580
- code: "dev_port_in_use",
581
- message: `Port ${port} on ${host} is already in use.`,
582
- fix: `Find the owner with \`lsof -nP -iTCP:${port} -sTCP:LISTEN\` and stop it, pass another --port, or omit --port to use this package\u2019s default (it moves to the next free port automatically).`
583
- });
584
- }
585
- function hostUnavailableError(host) {
586
- return new StructuredCliError({
587
- code: "dev_host_unavailable",
588
- message: `Cannot listen on ${host}: it is not an address of this machine.`,
589
- fix: "Pass one of this machine\u2019s IP addresses, or --host 0.0.0.0 to listen on all of them."
590
- });
591
- }
592
- function isAddressUnavailable(error) {
593
- return error?.code === "EADDRNOTAVAIL";
594
- }
595
- function wrapPort(port) {
596
- return port > 65535 ? devPortRange.min + (port - 65536) : port;
597
- }
598
- function listenOnce(server, host, port) {
599
- return new Promise((resolve8, reject) => {
600
- const onError = (error) => {
601
- server.off("listening", onListening);
602
- reject(error);
603
- };
604
- const onListening = () => {
605
- server.off("error", onError);
606
- resolve8();
607
- };
608
- server.once("error", onError);
609
- server.once("listening", onListening);
610
- server.listen(port, host);
611
- });
612
- }
613
- function isAddressInUse(error) {
614
- return error?.code === "EADDRINUSE";
615
- }
616
- function isPortReserved(error) {
617
- return error?.code === "EACCES";
618
- }
619
-
620
- // src/dev/dev-registry.ts
621
- import { createHash as createHash3 } from "node:crypto";
622
- import { mkdir, readFile as readFile3, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
623
- import { join as join4 } from "node:path";
624
-
625
- // src/dev/process-reaper.ts
626
- import { spawn } from "node:child_process";
627
- import { readdir, readFile as readFile2, rm, stat as stat2, writeFile } from "node:fs/promises";
628
- import { tmpdir } from "node:os";
629
- import { join as join3 } from "node:path";
630
- import psList from "ps-list";
631
- var devWorkDirPrefix = "kody-dev-";
632
- var ownerFileName = "owner.json";
633
- var legacyDirMinAgeMs = 10 * 6e4;
634
- var reaperScript = `
635
- pids=" "
636
- while IFS= read -r line; do
637
- case "$line" in
638
- +*) pids="$pids\${line#+} " ;;
639
- -*) pids="$(printf '%s' "$pids" | sed "s/ \${line#-} / /g")" ;;
640
- esac
641
- done
642
- for entry in $pids; do
643
- case "$entry" in
644
- g*) /bin/kill -s KILL -- -\${entry#g} 2>/dev/null ;;
645
- *) /bin/kill -s KILL -- $entry 2>/dev/null ;;
646
- esac
647
- done
648
- rm -rf "$1"
649
- `;
650
- async function startProcessReaper(input) {
651
- await writeFile(
652
- join3(input.workDir, ownerFileName),
653
- JSON.stringify({ pid: process.pid, startedAt: (/* @__PURE__ */ new Date()).toISOString() })
654
- );
655
- let reaper;
656
- try {
657
- reaper = spawn(
658
- "/bin/sh",
659
- ["-c", reaperScript, "kody-dev-reaper", input.workDir],
660
- {
661
- stdio: ["pipe", "ignore", "ignore"],
662
- detached: true
663
- }
664
- );
665
- reaper.on("error", () => {
666
- reaper = void 0;
667
- });
668
- reaper.stdin?.on("error", () => {
669
- });
670
- reaper.unref();
671
- reaper.stdin?.unref?.();
672
- } catch {
673
- reaper = void 0;
674
- }
675
- const send2 = (line) => {
676
- if (reaper?.stdin?.writable) reaper.stdin.write(`${line}
677
- `);
678
- };
679
- return {
680
- track: (pid) => send2(`+${pid}`),
681
- untrack: (pid) => send2(`-${pid}`),
682
- trackGroup: (pid) => send2(`+g${pid}`),
683
- untrackGroup: (pid) => send2(`-g${pid}`),
684
- close: () => {
685
- reaper?.stdin?.end();
686
- reaper = void 0;
687
- }
688
- };
689
- }
690
- async function sweepStaleDevDirs(input = {}) {
691
- const tmp = input.tmp ?? tmpdir();
692
- const now = input.now ?? Date.now();
693
- const isAlive = input.isAlive ?? isProcessAlive;
694
- const kill = input.kill ?? ((pid) => process.kill(pid, "SIGKILL"));
695
- const removed = [];
696
- const killed = [];
697
- let entries;
698
- try {
699
- entries = (await readdir(tmp)).filter(
700
- (name) => name.startsWith(devWorkDirPrefix)
701
- );
702
- } catch {
703
- return { removed, killed };
704
- }
705
- if (entries.length === 0) return { removed, killed };
706
- let processes = [];
707
- try {
708
- processes = await (input.listProcesses ?? psList)();
709
- } catch {
710
- processes = [];
711
- }
712
- const byPid = new Map(processes.map((item) => [item.pid, item]));
713
- for (const name of entries) {
714
- const dir = join3(tmp, name);
715
- try {
716
- const owner = await readOwnerPid(dir);
717
- if (owner !== null && isAlive(owner)) continue;
718
- const workerds = processes.filter(
719
- (item) => /workerd/.test(item.name) && (item.cmd ?? "").includes(`${dir}/`)
720
- );
721
- if (owner === null) {
722
- const info = await stat2(dir);
723
- if (now - info.mtimeMs < legacyDirMinAgeMs) continue;
724
- if (workerds.some((item) => !isOrphaned(item, byPid, isAlive))) continue;
725
- }
726
- for (const item of workerds) {
727
- try {
728
- kill(item.pid);
729
- killed.push(item.pid);
730
- } catch {
731
- }
732
- }
733
- await rm(dir, { recursive: true, force: true });
734
- removed.push(dir);
735
- } catch {
736
- }
737
- }
738
- return { removed, killed };
739
- }
740
- function isOrphaned(item, byPid, isAlive) {
741
- if (item.ppid === void 0) return false;
742
- if (item.ppid <= 1 || !isAlive(item.ppid)) return true;
743
- const parent = byPid.get(item.ppid);
744
- return parent !== void 0 && !/node|kody/i.test(`${parent.name} ${parent.cmd ?? ""}`);
745
- }
746
- async function readOwnerPid(dir) {
747
- try {
748
- const parsed = JSON.parse(
749
- await readFile2(join3(dir, ownerFileName), "utf8")
750
- );
751
- return typeof parsed.pid === "number" ? parsed.pid : null;
752
- } catch {
753
- return null;
754
- }
755
- }
756
- function isProcessAlive(pid) {
757
- try {
758
- process.kill(pid, 0);
759
- return true;
760
- } catch (error) {
761
- return error.code === "EPERM";
762
- }
763
- }
764
-
765
- // src/dev/dev-registry.ts
766
- var devStatusPath = "/__kody/dev/status";
767
- var devOutboxPath = "/__kody/dev/outbox";
768
- var devCallPath = "/__kody/dev/call";
769
- function devRegistryPath(root, target, cacheDir = userCacheDir()) {
770
- const key = createHash3("sha256").update(`${root}\0${target}`).digest("hex").slice(0, 16);
771
- return join4(cacheDir, "dev-servers", `${key}.json`);
772
- }
773
- async function writeDevRegistration(registration, cacheDir) {
774
- const path = devRegistryPath(registration.root, registration.target, cacheDir);
775
- await mkdir(join4(path, ".."), { recursive: true });
776
- await writeFile2(path, `${JSON.stringify(registration, null, 2)}
777
- `);
778
- return path;
779
- }
780
- async function removeDevRegistration(root, pid, target, cacheDir) {
781
- const path = devRegistryPath(root, target, cacheDir);
782
- try {
783
- const current = await readRegistration(path);
784
- if (!current || current.pid !== pid) return;
785
- await rm2(path, { force: true });
786
- } catch {
787
- }
788
- }
789
- async function findRunningDevServer(input) {
790
- const path = devRegistryPath(input.root, input.target, input.cacheDir);
791
- const registration = await readRegistration(path);
792
- if (!registration || registration.root !== input.root) return null;
793
- if (!isProcessAlive(registration.pid)) {
794
- const current = await readRegistration(path);
795
- if (current && current.pid === registration.pid) {
796
- await rm2(path, { force: true });
797
- }
798
- return null;
799
- }
800
- if (registration.target !== input.target) return null;
801
- try {
802
- const response = await (input.fetchFn ?? fetch)(
803
- new URL(devStatusPath, registration.origin),
804
- { signal: AbortSignal.timeout(input.timeoutMs ?? 1500) }
805
- );
806
- if (!response.ok) return null;
807
- const status = await response.json();
808
- if (status.package?.root !== input.root || status.target !== input.target)
809
- return null;
810
- return { registration, status };
811
- } catch {
812
- return null;
813
- }
814
- }
815
- async function readRegistration(path) {
816
- try {
817
- const parsed = JSON.parse(
818
- await readFile3(path, "utf8")
819
- );
820
- if (typeof parsed.pid !== "number" || typeof parsed.origin !== "string" || typeof parsed.root !== "string" || parsed.target !== "mock" && parsed.target !== "prod") {
821
- return null;
822
- }
823
- return {
824
- pid: parsed.pid,
825
- origin: parsed.origin,
826
- port: typeof parsed.port === "number" ? parsed.port : Number(new URL(parsed.origin).port),
827
- basePath: typeof parsed.basePath === "string" ? parsed.basePath : "",
828
- target: parsed.target,
829
- root: parsed.root
830
- };
831
- } catch {
832
- return null;
833
- }
834
- }
835
-
836
545
  // node_modules/chokidar/esm/index.js
837
546
  import { stat as statcb } from "fs";
838
- import { stat as stat5, readdir as readdir3 } from "fs/promises";
547
+ import { stat as stat4, readdir as readdir2 } from "fs/promises";
839
548
  import { EventEmitter } from "events";
840
549
  import * as sysPath2 from "path";
841
550
 
842
551
  // node_modules/readdirp/esm/index.js
843
- import { stat as stat3, lstat, readdir as readdir2, realpath } from "node:fs/promises";
552
+ import { stat as stat2, lstat, readdir, realpath } from "node:fs/promises";
844
553
  import { Readable } from "node:stream";
845
554
  import { resolve as presolve, relative as prelative, join as pjoin, sep as psep } from "node:path";
846
555
  var EntryTypes = {
@@ -907,7 +616,7 @@ var ReaddirpStream = class extends Readable {
907
616
  const { root, type } = opts;
908
617
  this._fileFilter = normalizeFilter(opts.fileFilter);
909
618
  this._directoryFilter = normalizeFilter(opts.directoryFilter);
910
- const statMethod = opts.lstat ? lstat : stat3;
619
+ const statMethod = opts.lstat ? lstat : stat2;
911
620
  if (wantBigintFsStats) {
912
621
  this._stat = (path) => statMethod(path, { bigint: true });
913
622
  } else {
@@ -978,7 +687,7 @@ var ReaddirpStream = class extends Readable {
978
687
  async _exploreDir(path, depth) {
979
688
  let files;
980
689
  try {
981
- files = await readdir2(path, this._rdOptions);
690
+ files = await readdir(path, this._rdOptions);
982
691
  } catch (error) {
983
692
  this._onError(error);
984
693
  }
@@ -1060,7 +769,7 @@ function readdirp(root, options = {}) {
1060
769
 
1061
770
  // node_modules/chokidar/esm/handler.js
1062
771
  import { watchFile, unwatchFile, watch as fs_watch } from "fs";
1063
- import { open, stat as stat4, lstat as lstat2, realpath as fsrealpath } from "fs/promises";
772
+ import { open, stat as stat3, lstat as lstat2, realpath as fsrealpath } from "fs/promises";
1064
773
  import * as sysPath from "path";
1065
774
  import { type as osType } from "os";
1066
775
  var STR_DATA = "data";
@@ -1087,7 +796,7 @@ var EVENTS = {
1087
796
  };
1088
797
  var EV = EVENTS;
1089
798
  var THROTTLE_MODE_WATCH = "watch";
1090
- var statMethods = { lstat: lstat2, stat: stat4 };
799
+ var statMethods = { lstat: lstat2, stat: stat3 };
1091
800
  var KEY_LISTENERS = "listeners";
1092
801
  var KEY_ERR = "errHandlers";
1093
802
  var KEY_RAW = "rawEmitters";
@@ -1573,7 +1282,7 @@ var NodeFsHandler = class {
1573
1282
  return;
1574
1283
  if (!newStats || newStats.mtimeMs === 0) {
1575
1284
  try {
1576
- const newStats2 = await stat4(file);
1285
+ const newStats2 = await stat3(file);
1577
1286
  if (this.fsw.closed)
1578
1287
  return;
1579
1288
  const at = newStats2.atimeMs;
@@ -1947,7 +1656,7 @@ var DirEntry = class {
1947
1656
  return;
1948
1657
  const dir = this.path;
1949
1658
  try {
1950
- await readdir3(dir);
1659
+ await readdir2(dir);
1951
1660
  } catch (err) {
1952
1661
  if (this._removeWatcher) {
1953
1662
  this._removeWatcher(sysPath2.dirname(dir), sysPath2.basename(dir));
@@ -2272,7 +1981,7 @@ var FSWatcher = class extends EventEmitter {
2272
1981
  const fullPath = opts.cwd ? sysPath2.join(opts.cwd, path) : path;
2273
1982
  let stats2;
2274
1983
  try {
2275
- stats2 = await stat5(fullPath);
1984
+ stats2 = await stat4(fullPath);
2276
1985
  } catch (err) {
2277
1986
  }
2278
1987
  if (!stats2 || this.closed)
@@ -2399,8 +2108,8 @@ var FSWatcher = class extends EventEmitter {
2399
2108
  }
2400
2109
  return this._userIgnored(path, stats);
2401
2110
  }
2402
- _isntIgnored(path, stat7) {
2403
- return !this._isIgnored(path, stat7);
2111
+ _isntIgnored(path, stat6) {
2112
+ return !this._isIgnored(path, stat6);
2404
2113
  }
2405
2114
  /**
2406
2115
  * Provides a set of common helpers and properties relating to symlink handling.
@@ -2525,7 +2234,7 @@ function watch(paths, options = {}) {
2525
2234
  var esm_default = { watch, FSWatcher };
2526
2235
 
2527
2236
  // src/dev/dev-watcher.ts
2528
- import { stat as stat6 } from "node:fs/promises";
2237
+ import { stat as stat5 } from "node:fs/promises";
2529
2238
  import { relative as relative3, sep as sep2 } from "node:path";
2530
2239
  var defaultPollIntervalMs = 1e3;
2531
2240
  function createDevWatcher(input) {
@@ -2631,7 +2340,7 @@ function createDevWatcher(input) {
2631
2340
  }
2632
2341
  async function fingerprint(path) {
2633
2342
  try {
2634
- const info = await stat6(path);
2343
+ const info = await stat5(path);
2635
2344
  return `${info.ino}:${info.size}:${info.mtimeMs}`;
2636
2345
  } catch {
2637
2346
  return "missing";
@@ -2860,7 +2569,7 @@ connect();
2860
2569
  `.trimStart();
2861
2570
 
2862
2571
  // src/dev/prebuild.ts
2863
- import { spawn as spawn2 } from "node:child_process";
2572
+ import { spawn } from "node:child_process";
2864
2573
  var outputTailLines = 20;
2865
2574
  var PrebuildError = class extends Error {
2866
2575
  constructor(message) {
@@ -2874,7 +2583,7 @@ async function runPrebuild(input) {
2874
2583
  }
2875
2584
  const env = { ...process.env, KODY_DEV: "1" };
2876
2585
  delete env[apiTokenEnvVar];
2877
- const child = spawn2("sh", ["-c", input.command], {
2586
+ const child = spawn("sh", ["-c", input.command], {
2878
2587
  cwd: input.cwd,
2879
2588
  env,
2880
2589
  stdio: ["ignore", "pipe", "pipe"],
@@ -3480,7 +3189,7 @@ async function startPackageAppDev(options) {
3480
3189
  const errorPageTail = liveReload ? `<script>globalThis.__kodyDevErrorPage = true</script>${liveReloadScriptTag}` : "";
3481
3190
  void sweepStaleDevDirs().catch(() => {
3482
3191
  });
3483
- const workDir = await mkdtemp(join7(tmpdir2(), devWorkDirPrefix));
3192
+ const workDir = await mkdtemp(join5(tmpdir(), devWorkDirPrefix));
3484
3193
  const reaper = await startProcessReaper({ workDir });
3485
3194
  const workerdPath = options.workerdPath ?? await ensureWorkerdBinary({
3486
3195
  onDownload: (url) => options.onStatus?.(`Downloading workerd from ${url}\u2026`)
@@ -3533,7 +3242,7 @@ async function startPackageAppDev(options) {
3533
3242
  }
3534
3243
  };
3535
3244
  process.once("exit", killAllSync);
3536
- const proxy = createServer2((req, res) => {
3245
+ const proxy = createServer((req, res) => {
3537
3246
  void handleRequest(req, res);
3538
3247
  });
3539
3248
  try {
@@ -3545,7 +3254,7 @@ async function startPackageAppDev(options) {
3545
3254
  } catch (error) {
3546
3255
  process.off("exit", killAllSync);
3547
3256
  reaper.close();
3548
- await rm3(workDir, { recursive: true, force: true });
3257
+ await rm(workDir, { recursive: true, force: true });
3549
3258
  throw error;
3550
3259
  }
3551
3260
  const address = proxy.address();
@@ -3633,7 +3342,7 @@ async function startPackageAppDev(options) {
3633
3342
  await new Promise((resolve8) => {
3634
3343
  proxy.close(() => resolve8());
3635
3344
  });
3636
- await rm3(workDir, { recursive: true, force: true, maxRetries: 10 });
3345
+ await rm(workDir, { recursive: true, force: true, maxRetries: 10 });
3637
3346
  throw error;
3638
3347
  }
3639
3348
  const contextFor = (client2) => buildLocalPackageContext({
@@ -3872,7 +3581,7 @@ async function startPackageAppDev(options) {
3872
3581
  }
3873
3582
  async function startGeneration(bundle, client2) {
3874
3583
  const id = ++generationCounter;
3875
- const dir = join7(workDir, `g${id}`);
3584
+ const dir = join5(workDir, `g${id}`);
3876
3585
  if (options.localKody) {
3877
3586
  await options.localKody.sync();
3878
3587
  const generation2 = {
@@ -3921,7 +3630,7 @@ async function startPackageAppDev(options) {
3921
3630
  try {
3922
3631
  workerd = await startWorkerd({
3923
3632
  workerdPath,
3924
- configPath: join7(dir, "config.capnp"),
3633
+ configPath: join5(dir, "config.capnp"),
3925
3634
  cwd: dir,
3926
3635
  env: workerdEnv,
3927
3636
  onSpawn: (pid) => {
@@ -3943,7 +3652,7 @@ async function startPackageAppDev(options) {
3943
3652
  });
3944
3653
  } catch (error) {
3945
3654
  if (trackedPid !== void 0) reaper.untrack(trackedPid);
3946
- await rm3(dir, { recursive: true, force: true }).catch(() => {
3655
+ await rm(dir, { recursive: true, force: true }).catch(() => {
3947
3656
  });
3948
3657
  throw error;
3949
3658
  }
@@ -3991,7 +3700,7 @@ async function startPackageAppDev(options) {
3991
3700
  reaper.untrack(generation.workerd.pid);
3992
3701
  }
3993
3702
  generations.delete(generation);
3994
- await rm3(generation.dir, { recursive: true, force: true });
3703
+ await rm(generation.dir, { recursive: true, force: true });
3995
3704
  }
3996
3705
  async function waitForBuild() {
3997
3706
  const flush = debounceFlush;
@@ -4065,6 +3774,11 @@ async function startPackageAppDev(options) {
4065
3774
  return true;
4066
3775
  }
4067
3776
  void readDevCallBody(req).then(async ({ operation, input }) => {
3777
+ if (operation === "sync") {
3778
+ await localKody.sync();
3779
+ send2(200, { result: null });
3780
+ return;
3781
+ }
4068
3782
  if (!devCallOperations.has(operation)) {
4069
3783
  send2(400, {
4070
3784
  error: `Unsupported operation ${JSON.stringify(operation)}.`
@@ -4403,7 +4117,7 @@ fix: ${fix}` : mapped,
4403
4117
  await new Promise((resolve9) => {
4404
4118
  proxy.close(() => resolve9());
4405
4119
  });
4406
- await rm3(workDir, { recursive: true, force: true, maxRetries: 10 });
4120
+ await rm(workDir, { recursive: true, force: true, maxRetries: 10 });
4407
4121
  };
4408
4122
  try {
4409
4123
  await Promise.all([requestBuild([]), watcher?.ready]);
@@ -4477,7 +4191,7 @@ async function readStream(stream) {
4477
4191
  return Buffer.concat(chunks).toString("utf8");
4478
4192
  }
4479
4193
  async function writeWorkerFiles(input) {
4480
- await mkdir2(input.workDir, { recursive: true });
4194
+ await mkdir(input.workDir, { recursive: true });
4481
4195
  const packageGraph = await resolveLocalPackageGraph({
4482
4196
  code: input.code,
4483
4197
  apiUrl: input.apiUrl,
@@ -4516,8 +4230,8 @@ async function writeWorkerFiles(input) {
4516
4230
  let packageModules = await writePackageModuleFiles(
4517
4231
  input.workDir,
4518
4232
  packageGraph,
4519
- writeFile3,
4520
- join7
4233
+ writeFile,
4234
+ join5
4521
4235
  );
4522
4236
  let gatewayFetchShimModules = packageGraph.modules.map((module) => module.name).filter((name) => name === localExecuteGatewayFetchShimModuleName);
4523
4237
  if (input.mockFetchGateway) {
@@ -4528,25 +4242,25 @@ async function writeWorkerFiles(input) {
4528
4242
  packageModules = installed.packageModules;
4529
4243
  gatewayFetchShimModules = installed.sideEffectModules;
4530
4244
  }
4531
- await writeFile3(
4532
- join7(input.workDir, files.entry),
4245
+ await writeFile(
4246
+ join5(input.workDir, files.entry),
4533
4247
  createPackageAppEntrySource({ sideEffectModules: gatewayFetchShimModules })
4534
4248
  );
4535
- await writeFile3(join7(input.workDir, files.user), input.code);
4536
- await writeFile3(
4537
- join7(input.workDir, files.runtime),
4249
+ await writeFile(join5(input.workDir, files.user), input.code);
4250
+ await writeFile(
4251
+ join5(input.workDir, files.runtime),
4538
4252
  createPackageLocalRuntimeModuleSource({
4539
4253
  packageContext,
4540
4254
  mockStorage: input.mockStorage,
4541
4255
  ...boundPackage?.packageBinding ? { packageBinding: boundPackage.packageBinding } : {}
4542
4256
  })
4543
4257
  );
4544
- await writeFile3(
4545
- join7(input.workDir, localWorkerModuleNames.runtimeFlatAlias),
4258
+ await writeFile(
4259
+ join5(input.workDir, localWorkerModuleNames.runtimeFlatAlias),
4546
4260
  createRuntimeFlatAliasSource()
4547
4261
  );
4548
- await writeFile3(
4549
- join7(input.workDir, "config.capnp"),
4262
+ await writeFile(
4263
+ join5(input.workDir, "config.capnp"),
4550
4264
  createWorkerdConfig({
4551
4265
  bridgePort: input.bridgePort,
4552
4266
  files,
@@ -4741,7 +4455,8 @@ async function runDevServe(input) {
4741
4455
  port,
4742
4456
  basePath: appBasePath,
4743
4457
  target: input.target,
4744
- root: manifest.root
4458
+ root: manifest.root,
4459
+ ...localKody?.api ? { localKody: localKody.api } : {}
4745
4460
  });
4746
4461
  registered = true;
4747
4462
  }
@@ -4795,8 +4510,8 @@ async function runDevServe(input) {
4795
4510
  }
4796
4511
  }
4797
4512
  if (input.readyFile) {
4798
- await mkdir3(dirname3(input.readyFile), { recursive: true });
4799
- await writeFile4(input.readyFile, `${JSON.stringify(ready, null, 2)}
4513
+ await mkdir2(dirname3(input.readyFile), { recursive: true });
4514
+ await writeFile2(input.readyFile, `${JSON.stringify(ready, null, 2)}
4800
4515
  `);
4801
4516
  }
4802
4517
  if (input.json) {
@@ -4953,83 +4668,33 @@ async function tryAttachedDevCall(input) {
4953
4668
  } catch {
4954
4669
  return null;
4955
4670
  }
4956
- const running = await findRunningDevServer({
4957
- root: manifest.root,
4958
- target: input.target
4959
- });
4960
- let call;
4961
- let ranOn;
4962
- let closeLocal;
4963
- if (running) {
4964
- const { registration } = running;
4965
- const url = new URL(
4966
- `${registration.basePath}${devCallPath}`,
4967
- registration.origin
4968
- );
4969
- ranOn = `running kody dev (pid ${registration.pid})`;
4970
- call = async (operation, args) => {
4971
- const response = await fetch(url, {
4972
- method: "POST",
4973
- headers: { "content-type": "application/json" },
4974
- body: JSON.stringify({ operation, input: args })
4975
- });
4976
- const body = await response.json().catch(() => null);
4977
- if (response.status === 404) return devCallUnavailable;
4978
- if (!response.ok) {
4979
- throw new StructuredCliError({
4980
- code: "dev_local_call_failed",
4981
- message: body?.error ?? `Local Kody ${operation} failed (HTTP ${response.status}).`,
4982
- target: input.target
4983
- });
4984
- }
4985
- return body?.result;
4986
- };
4987
- } else {
4988
- if (process.env.KODY_DEV_STUB_RUNTIME === "1") return null;
4989
- const local = await import("./local-kody-2OCWWF6E.js");
4990
- const kody = await local.startLocalKody({
4991
- manifest,
4992
- packageAppPort: defaultDevPort(manifest.kodyId),
4993
- onStatus: (message) => input.io.stderr(`${message}
4671
+ const session = await resolveLocalKodySession({
4672
+ manifest,
4673
+ onStatus: (message) => input.io.stderr(`${message}
4994
4674
  `)
4995
- });
4996
- closeLocal = kody.close;
4997
- ranOn = "a one-shot local Kody";
4998
- try {
4999
- const upstream = local.createLocalKodyUpstream({ kody, manifest });
5000
- await upstream.sync();
5001
- call = async (operation, args) => {
5002
- const packageId = upstream.packageId();
5003
- return await upstream.call(
5004
- operation,
5005
- packageId && operation !== "jobList" && operation !== "jobRunNow" ? { ...args, package_id: packageId } : args
5006
- );
5007
- };
5008
- } catch (error) {
5009
- await closeLocal();
5010
- await input.closeMock?.();
5011
- throw error;
5012
- }
5013
- }
4675
+ }).catch(async (error) => {
4676
+ await input.closeMock?.();
4677
+ throw error;
4678
+ });
4679
+ if (!session) return null;
5014
4680
  let first;
5015
4681
  try {
5016
- first = await input.steps(call);
4682
+ first = await input.steps(session.call);
5017
4683
  } catch (error) {
5018
- await closeLocal?.();
5019
4684
  await input.closeMock?.();
5020
4685
  throw error;
4686
+ } finally {
4687
+ await session.close();
5021
4688
  }
5022
- await closeLocal?.();
5023
4689
  if (first === devCallUnavailable) return null;
5024
4690
  await input.closeMock?.();
5025
- input.io.stderr(`Ran on local Kody via ${ranOn}
4691
+ input.io.stderr(`Ran on local Kody via ${session.ranOn}
5026
4692
  `);
5027
4693
  input.io.stdout(`${JSON.stringify(first, null, 2)}
5028
4694
  `);
5029
4695
  const failed = first && typeof first === "object" && "status" in first && typeof first.status === "number" && first.status >= 400;
5030
4696
  return failed ? 1 : 0;
5031
4697
  }
5032
- var devCallUnavailable = /* @__PURE__ */ Symbol("devCallUnavailable");
5033
4698
  async function runDevJob(input) {
5034
4699
  const manifest = await loadPackageManifest(input.cwd);
5035
4700
  const job = manifest.jobs[input.jobName];
@@ -5106,7 +4771,7 @@ async function runDevWebhook(input) {
5106
4771
  target: input.target
5107
4772
  });
5108
4773
  }
5109
- const rawBody = await readFile4(
4774
+ const rawBody = await readFile2(
5110
4775
  resolve7(input.cwd ?? process.cwd(), input.bodyPath),
5111
4776
  "utf8"
5112
4777
  );
@@ -5194,7 +4859,7 @@ async function runDevEmit(input) {
5194
4859
  target: input.target
5195
4860
  });
5196
4861
  }
5197
- const rawBody = await readFile4(
4862
+ const rawBody = await readFile2(
5198
4863
  resolve7(input.cwd ?? process.cwd(), input.bodyPath),
5199
4864
  "utf8"
5200
4865
  );
@@ -5438,13 +5103,13 @@ async function runDevCheck(input) {
5438
5103
  }
5439
5104
  }
5440
5105
  try {
5441
- await readFile4(resolve7(manifest.root, "README.md"));
5106
+ await readFile2(resolve7(manifest.root, "README.md"));
5442
5107
  push("README.md", true);
5443
5108
  } catch {
5444
5109
  push("README.md", false, "Publish requires README.md");
5445
5110
  }
5446
5111
  try {
5447
- await readFile4(resolve7(manifest.root, "AGENTS.md"));
5112
+ await readFile2(resolve7(manifest.root, "AGENTS.md"));
5448
5113
  push("AGENTS.md", true);
5449
5114
  } catch {
5450
5115
  push("AGENTS.md", false, "Publish requires AGENTS.md");
@@ -5477,7 +5142,7 @@ async function runDevCheck(input) {
5477
5142
  }
5478
5143
  let hasMocksFile = false;
5479
5144
  try {
5480
- await access(join8(manifest.root, packageMocksRelativePath));
5145
+ await access(join6(manifest.root, packageMocksRelativePath));
5481
5146
  hasMocksFile = true;
5482
5147
  } catch {
5483
5148
  hasMocksFile = false;
@@ -5680,9 +5345,9 @@ function parseDevSubcommand(positionals) {
5680
5345
  }
5681
5346
  async function removeOwnedReadyFile(path, ownerPid) {
5682
5347
  try {
5683
- const parsed = JSON.parse(await readFile4(path, "utf8"));
5348
+ const parsed = JSON.parse(await readFile2(path, "utf8"));
5684
5349
  if (parsed.pid !== ownerPid) return;
5685
- await rm4(path, { force: true });
5350
+ await rm2(path, { force: true });
5686
5351
  } catch {
5687
5352
  }
5688
5353
  }
@@ -5707,4 +5372,4 @@ export {
5707
5372
  chokidar/esm/index.js:
5708
5373
  (*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) *)
5709
5374
  */
5710
- //# sourceMappingURL=dev-command-K65OPONH.js.map
5375
+ //# sourceMappingURL=dev-command-VELMK2SY.js.map