@kodycodes/cli 1.26.1 → 1.26.3

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 (271) hide show
  1. package/dist/auth-4FW6GCLG.js +26 -0
  2. package/dist/auth-4FW6GCLG.js.map +6 -0
  3. package/dist/bin.js +27 -3
  4. package/dist/bin.js.map +6 -1
  5. package/dist/chunk-46IJPEID.js +30 -0
  6. package/dist/chunk-46IJPEID.js.map +6 -0
  7. package/dist/chunk-4D6ORNXY.js +24404 -0
  8. package/dist/chunk-4D6ORNXY.js.map +6 -0
  9. package/dist/chunk-64IM6G4Z.js +341 -0
  10. package/dist/chunk-64IM6G4Z.js.map +6 -0
  11. package/dist/{package-local-runtime-source.js → chunk-64XN367G.js} +373 -52
  12. package/dist/chunk-64XN367G.js.map +6 -0
  13. package/dist/chunk-6XQP5SWX.js +26 -0
  14. package/dist/chunk-6XQP5SWX.js.map +6 -0
  15. package/dist/chunk-75RZUXQL.js +62 -0
  16. package/dist/chunk-75RZUXQL.js.map +6 -0
  17. package/dist/chunk-BISUL7CE.js +106 -0
  18. package/dist/chunk-BISUL7CE.js.map +6 -0
  19. package/dist/chunk-BPGY4IE7.js +57 -0
  20. package/dist/chunk-BPGY4IE7.js.map +6 -0
  21. package/dist/chunk-CASGRYOF.js +21 -0
  22. package/dist/chunk-CASGRYOF.js.map +6 -0
  23. package/dist/chunk-CWWHR4FH.js +19 -0
  24. package/dist/chunk-CWWHR4FH.js.map +6 -0
  25. package/dist/chunk-D55XPY3T.js +1382 -0
  26. package/dist/chunk-D55XPY3T.js.map +6 -0
  27. package/dist/chunk-EOCV74B2.js +948 -0
  28. package/dist/chunk-EOCV74B2.js.map +6 -0
  29. package/dist/chunk-FBVNFWR6.js +437 -0
  30. package/dist/chunk-FBVNFWR6.js.map +6 -0
  31. package/dist/chunk-G4YN6XP5.js +14 -0
  32. package/dist/chunk-G4YN6XP5.js.map +6 -0
  33. package/dist/chunk-G6LJWROP.js +18 -0
  34. package/dist/chunk-G6LJWROP.js.map +6 -0
  35. package/dist/chunk-IHP6PV6X.js +49 -0
  36. package/dist/chunk-IHP6PV6X.js.map +6 -0
  37. package/dist/chunk-JWEFKKAD.js +24 -0
  38. package/dist/chunk-JWEFKKAD.js.map +6 -0
  39. package/dist/chunk-LWNB26KO.js +147 -0
  40. package/dist/chunk-LWNB26KO.js.map +6 -0
  41. package/dist/chunk-OVGXPRSY.js +20 -0
  42. package/dist/chunk-OVGXPRSY.js.map +6 -0
  43. package/dist/chunk-PDWCKWQF.js +453 -0
  44. package/dist/chunk-PDWCKWQF.js.map +6 -0
  45. package/dist/chunk-QHBCP4OB.js +44 -0
  46. package/dist/chunk-QHBCP4OB.js.map +6 -0
  47. package/dist/chunk-R4IUV5P5.js +664 -0
  48. package/dist/chunk-R4IUV5P5.js.map +6 -0
  49. package/dist/chunk-RM34N3KI.js +525 -0
  50. package/dist/chunk-RM34N3KI.js.map +6 -0
  51. package/dist/chunk-RTWUNV76.js +309 -0
  52. package/dist/chunk-RTWUNV76.js.map +6 -0
  53. package/dist/chunk-SMURF26I.js +23 -0
  54. package/dist/chunk-SMURF26I.js.map +6 -0
  55. package/dist/chunk-SXHULGL4.js +426 -0
  56. package/dist/chunk-SXHULGL4.js.map +6 -0
  57. package/dist/chunk-TIL35OWA.js +1959 -0
  58. package/dist/chunk-TIL35OWA.js.map +6 -0
  59. package/dist/chunk-VQS5YSCI.js +54 -0
  60. package/dist/chunk-VQS5YSCI.js.map +6 -0
  61. package/dist/chunk-XDCOWU5R.js +696 -0
  62. package/dist/chunk-XDCOWU5R.js.map +6 -0
  63. package/dist/chunk-XOPPGRUP.js +605 -0
  64. package/dist/chunk-XOPPGRUP.js.map +6 -0
  65. package/dist/cli.js +74 -1500
  66. package/dist/cli.js.map +6 -1
  67. package/dist/dev/dev-watcher.d.ts +5 -1
  68. package/dist/dev-command-3LX234N6.js +4900 -0
  69. package/dist/dev-command-3LX234N6.js.map +6 -0
  70. package/dist/git-credential-FUE3JE3T.js +163 -0
  71. package/dist/git-credential-FUE3JE3T.js.map +6 -0
  72. package/dist/install-ZML2TCDG.js +10694 -0
  73. package/dist/install-ZML2TCDG.js.map +6 -0
  74. package/dist/local-execute-SZV6XN4T.js +368 -0
  75. package/dist/local-execute-SZV6XN4T.js.map +6 -0
  76. package/dist/local-package-run-2TMCAZZ2.js +23 -0
  77. package/dist/local-package-run-2TMCAZZ2.js.map +6 -0
  78. package/dist/mcp-G2AWTIXR.js +21 -0
  79. package/dist/mcp-G2AWTIXR.js.map +6 -0
  80. package/dist/mock-dep-resolve-TVABDNR7.js +52 -0
  81. package/dist/mock-dep-resolve-TVABDNR7.js.map +6 -0
  82. package/dist/mock-fetch-gateway-B5TFGGQS.js +34 -0
  83. package/dist/mock-fetch-gateway-B5TFGGQS.js.map +6 -0
  84. package/dist/mock-local-deps-5SZT3PWT.js +197 -0
  85. package/dist/mock-local-deps-5SZT3PWT.js.map +6 -0
  86. package/dist/mock-server-SV2IKC4I.js +21 -0
  87. package/dist/mock-server-SV2IKC4I.js.map +6 -0
  88. package/dist/open-api-client-DVVMLY7P.js +42 -0
  89. package/dist/open-api-client-DVVMLY7P.js.map +6 -0
  90. package/dist/org-X7B5BI4R.js +132 -0
  91. package/dist/org-X7B5BI4R.js.map +6 -0
  92. package/dist/package-manifest-QH2RU64C.js +14 -0
  93. package/dist/package-manifest-QH2RU64C.js.map +6 -0
  94. package/dist/remote-execute-QMQDVHOY.js +110 -0
  95. package/dist/remote-execute-QMQDVHOY.js.map +6 -0
  96. package/dist/setup-git-5KCUBYPB.js +88 -0
  97. package/dist/setup-git-5KCUBYPB.js.map +6 -0
  98. package/dist/skill-ENPATRIW.js +43 -0
  99. package/dist/skill-ENPATRIW.js.map +6 -0
  100. package/dist/store-WTMRH527.js +48 -0
  101. package/dist/store-WTMRH527.js.map +6 -0
  102. package/dist/structured-error-C65GQ53Z.js +13 -0
  103. package/dist/structured-error-C65GQ53Z.js.map +6 -0
  104. package/dist/target-3QHY7JT4.js +45 -0
  105. package/dist/target-3QHY7JT4.js.map +6 -0
  106. package/dist/webapi-NTVP4BO3.js +2482 -0
  107. package/dist/webapi-NTVP4BO3.js.map +6 -0
  108. package/package.json +8 -8
  109. package/dist/add-mcp-install.js +0 -59
  110. package/dist/add-mcp-install.js.map +0 -1
  111. package/dist/api-token-store.js +0 -120
  112. package/dist/api-token-store.js.map +0 -1
  113. package/dist/api-token.js +0 -238
  114. package/dist/api-token.js.map +0 -1
  115. package/dist/auth-bootstrap.js +0 -373
  116. package/dist/auth-bootstrap.js.map +0 -1
  117. package/dist/auth.js +0 -386
  118. package/dist/auth.js.map +0 -1
  119. package/dist/capability-proxy.js +0 -527
  120. package/dist/capability-proxy.js.map +0 -1
  121. package/dist/credential-call-map.js +0 -155
  122. package/dist/credential-call-map.js.map +0 -1
  123. package/dist/credential-client-runtime-source.js +0 -9
  124. package/dist/credential-client-runtime-source.js.map +0 -1
  125. package/dist/credentialed-fetch-scan.js +0 -98
  126. package/dist/credentialed-fetch-scan.js.map +0 -1
  127. package/dist/defaults.js +0 -34
  128. package/dist/defaults.js.map +0 -1
  129. package/dist/detect-running-hosts.js +0 -13
  130. package/dist/detect-running-hosts.js.map +0 -1
  131. package/dist/dev/dev-assets.js +0 -202
  132. package/dist/dev/dev-assets.js.map +0 -1
  133. package/dist/dev/dev-bundler.js +0 -65
  134. package/dist/dev/dev-bundler.js.map +0 -1
  135. package/dist/dev/dev-events.js +0 -94
  136. package/dist/dev/dev-events.js.map +0 -1
  137. package/dist/dev/dev-port.js +0 -80
  138. package/dist/dev/dev-port.js.map +0 -1
  139. package/dist/dev/dev-protocol.js +0 -14
  140. package/dist/dev/dev-protocol.js.map +0 -1
  141. package/dist/dev/dev-registry.js +0 -95
  142. package/dist/dev/dev-registry.js.map +0 -1
  143. package/dist/dev/dev-watcher.js +0 -156
  144. package/dist/dev/dev-watcher.js.map +0 -1
  145. package/dist/dev/error-page.js +0 -64
  146. package/dist/dev/error-page.js.map +0 -1
  147. package/dist/dev/live-reload.js +0 -148
  148. package/dist/dev/live-reload.js.map +0 -1
  149. package/dist/dev/prebuild.js +0 -102
  150. package/dist/dev/prebuild.js.map +0 -1
  151. package/dist/dev/process-reaper.js +0 -151
  152. package/dist/dev/process-reaper.js.map +0 -1
  153. package/dist/dev/stack-trace.js +0 -56
  154. package/dist/dev/stack-trace.js.map +0 -1
  155. package/dist/dev/workerd-process.js +0 -118
  156. package/dist/dev/workerd-process.js.map +0 -1
  157. package/dist/dev-command.js +0 -672
  158. package/dist/dev-command.js.map +0 -1
  159. package/dist/discover-login-identity.js +0 -77
  160. package/dist/discover-login-identity.js.map +0 -1
  161. package/dist/discover-org.js +0 -62
  162. package/dist/discover-org.js.map +0 -1
  163. package/dist/git-credential.js +0 -147
  164. package/dist/git-credential.js.map +0 -1
  165. package/dist/help.js +0 -333
  166. package/dist/help.js.map +0 -1
  167. package/dist/host-catalog.js +0 -427
  168. package/dist/host-catalog.js.map +0 -1
  169. package/dist/host-config.js +0 -80
  170. package/dist/host-config.js.map +0 -1
  171. package/dist/http-error-body.js +0 -35
  172. package/dist/http-error-body.js.map +0 -1
  173. package/dist/install-hosts.js +0 -328
  174. package/dist/install-hosts.js.map +0 -1
  175. package/dist/install.js +0 -120
  176. package/dist/install.js.map +0 -1
  177. package/dist/invoke-passthrough.js +0 -60
  178. package/dist/invoke-passthrough.js.map +0 -1
  179. package/dist/local-bundle.js +0 -200
  180. package/dist/local-bundle.js.map +0 -1
  181. package/dist/local-execute-auth.js +0 -53
  182. package/dist/local-execute-auth.js.map +0 -1
  183. package/dist/local-execute.js +0 -338
  184. package/dist/local-execute.js.map +0 -1
  185. package/dist/local-gateway-fetch-forward.js +0 -135
  186. package/dist/local-gateway-fetch-forward.js.map +0 -1
  187. package/dist/local-host-runtime-surface.js +0 -75
  188. package/dist/local-host-runtime-surface.js.map +0 -1
  189. package/dist/local-package-graph.js +0 -405
  190. package/dist/local-package-graph.js.map +0 -1
  191. package/dist/local-package-run.js +0 -307
  192. package/dist/local-package-run.js.map +0 -1
  193. package/dist/local-runtime-bridge.js +0 -132
  194. package/dist/local-runtime-bridge.js.map +0 -1
  195. package/dist/local-runtime-source.js +0 -541
  196. package/dist/local-runtime-source.js.map +0 -1
  197. package/dist/login-callback-assets.js +0 -10
  198. package/dist/login-callback-assets.js.map +0 -1
  199. package/dist/login-callback-page.js +0 -362
  200. package/dist/login-callback-page.js.map +0 -1
  201. package/dist/mcp.js +0 -134
  202. package/dist/mcp.js.map +0 -1
  203. package/dist/mock/ensure-msw.js +0 -215
  204. package/dist/mock/ensure-msw.js.map +0 -1
  205. package/dist/mock/install-mock-fetch-shim.js +0 -36
  206. package/dist/mock/install-mock-fetch-shim.js.map +0 -1
  207. package/dist/mock/load-package-mocks.js +0 -136
  208. package/dist/mock/load-package-mocks.js.map +0 -1
  209. package/dist/mock/mock-fetch-gateway.js +0 -343
  210. package/dist/mock/mock-fetch-gateway.js.map +0 -1
  211. package/dist/mock/mock-gateway-fetch-shim.js +0 -104
  212. package/dist/mock/mock-gateway-fetch-shim.js.map +0 -1
  213. package/dist/mock/mock-server.js +0 -499
  214. package/dist/mock/mock-server.js.map +0 -1
  215. package/dist/mock/mock-storage.js +0 -186
  216. package/dist/mock/mock-storage.js.map +0 -1
  217. package/dist/mock/mock-supported.js +0 -63
  218. package/dist/mock/mock-supported.js.map +0 -1
  219. package/dist/mock-dep-resolve.js +0 -47
  220. package/dist/mock-dep-resolve.js.map +0 -1
  221. package/dist/mock-local-deps.js +0 -207
  222. package/dist/mock-local-deps.js.map +0 -1
  223. package/dist/network-error.js +0 -11
  224. package/dist/network-error.js.map +0 -1
  225. package/dist/node-engine.js +0 -21
  226. package/dist/node-engine.js.map +0 -1
  227. package/dist/oauth-provider.js +0 -107
  228. package/dist/oauth-provider.js.map +0 -1
  229. package/dist/onboarding-prompt.js +0 -15
  230. package/dist/onboarding-prompt.js.map +0 -1
  231. package/dist/open-api-client.js +0 -432
  232. package/dist/open-api-client.js.map +0 -1
  233. package/dist/open-url.js +0 -21
  234. package/dist/open-url.js.map +0 -1
  235. package/dist/org-resolve.js +0 -16
  236. package/dist/org-resolve.js.map +0 -1
  237. package/dist/org-slug.js +0 -11
  238. package/dist/org-slug.js.map +0 -1
  239. package/dist/org.js +0 -100
  240. package/dist/org.js.map +0 -1
  241. package/dist/package-app-dev.js +0 -905
  242. package/dist/package-app-dev.js.map +0 -1
  243. package/dist/package-collaborators.js +0 -179
  244. package/dist/package-collaborators.js.map +0 -1
  245. package/dist/package-info.js +0 -19
  246. package/dist/package-info.js.map +0 -1
  247. package/dist/package-local-runtime-source.js.map +0 -1
  248. package/dist/package-manifest.js +0 -364
  249. package/dist/package-manifest.js.map +0 -1
  250. package/dist/process-info.js +0 -14
  251. package/dist/process-info.js.map +0 -1
  252. package/dist/redact.js +0 -16
  253. package/dist/redact.js.map +0 -1
  254. package/dist/remote-execute.js +0 -108
  255. package/dist/remote-execute.js.map +0 -1
  256. package/dist/setup-git.js +0 -676
  257. package/dist/setup-git.js.map +0 -1
  258. package/dist/skill.js +0 -35
  259. package/dist/skill.js.map +0 -1
  260. package/dist/store.js +0 -597
  261. package/dist/store.js.map +0 -1
  262. package/dist/structured-error.js +0 -57
  263. package/dist/structured-error.js.map +0 -1
  264. package/dist/target.js +0 -52
  265. package/dist/target.js.map +0 -1
  266. package/dist/tool-result.js +0 -19
  267. package/dist/tool-result.js.map +0 -1
  268. package/dist/which.js +0 -22
  269. package/dist/which.js.map +0 -1
  270. package/dist/workerd-binary.js +0 -98
  271. package/dist/workerd-binary.js.map +0 -1
@@ -1,672 +0,0 @@
1
- /**
2
- * `kody dev` and its agent-facing subcommands: serve, fetch, job, webhook,
3
- * emit, check. Covers the four package surfaces: exports (via execute/invoke
4
- * against the local package), webhooks, schedules (job once), and subscriptions.
5
- */
6
- import { access, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
7
- import { dirname, join, resolve } from 'node:path';
8
- import { detectCredentialedFetchInSource, mocksSuggestionDetail, } from './credentialed-fetch-scan.js';
9
- import { buildLocalPackageContext, runLocalPackageModule } from './local-package-run.js';
10
- import { ensureMockTarget } from './mock/mock-server.js';
11
- import { packageMocksRelativePath } from './mock/load-package-mocks.js';
12
- import { startPackageAppDev } from './package-app-dev.js';
13
- import { loadPackageManifest, resolveExportModulePath, resolvePackagePath, } from './package-manifest.js';
14
- import { StructuredCliError } from './structured-error.js';
15
- import { formatToolResult } from './tool-result.js';
16
- import { bundleLocalUserModule } from './local-bundle.js';
17
- import { formatDevEvent } from './dev/dev-events.js';
18
- import { defaultDevPort } from './dev/dev-port.js';
19
- import { devStatusPath, findRunningDevServer, removeDevRegistration, writeDevRegistration, } from './dev/dev-registry.js';
20
- export { parseDevPort } from './dev/dev-port.js';
21
- export async function resolveDevAuth(input) {
22
- if (input.target !== 'mock') {
23
- return {
24
- token: input.token,
25
- apiUrl: input.apiUrl,
26
- ...(input.org ? { org: input.org } : {}),
27
- ...(input.passthroughHosts?.length
28
- ? { passthroughHosts: input.passthroughHosts }
29
- : {}),
30
- };
31
- }
32
- const ensured = await ensureMockTarget({
33
- sessionId: input.sessionId,
34
- resetStorage: input.resetStorage,
35
- packageId: input.packageId,
36
- orgSlug: input.orgSlug ?? input.org,
37
- });
38
- let mockClosed = false;
39
- return {
40
- token: ensured.token,
41
- apiUrl: ensured.apiUrl,
42
- ...(input.org ? { org: input.org } : {}),
43
- ...(input.depResolve ? { depResolve: input.depResolve } : {}),
44
- ...(input.passthroughHosts?.length
45
- ? { passthroughHosts: input.passthroughHosts }
46
- : {}),
47
- mockServer: ensured.server,
48
- closeMock: ensured.started
49
- ? async () => {
50
- if (mockClosed)
51
- return;
52
- mockClosed = true;
53
- await ensured.server.close();
54
- }
55
- : undefined,
56
- };
57
- }
58
- export async function runDevServe(input) {
59
- const manifest = await loadPackageManifest(input.cwd);
60
- if (input.port === undefined) {
61
- const running = await findRunningDevServer({ root: manifest.root, target: input.target });
62
- if (running) {
63
- const { registration } = running;
64
- throw new StructuredCliError({
65
- code: 'dev_already_running',
66
- target: input.target,
67
- message: `kody dev is already running for ${manifest.name} at ${registration.origin}${registration.basePath || '/'} (pid ${registration.pid}).`,
68
- fix: `Reuse it (\`kody dev fetch <path>\` attaches automatically), stop it with \`kill ${registration.pid}\`, or pass --port to start a second server.`,
69
- });
70
- }
71
- }
72
- const onEvent = input.json
73
- ? (event) => writeJsonEvent(input.io, event)
74
- : (event) => writeDevEvent(input.io, event);
75
- let registered = false;
76
- let server;
77
- try {
78
- server = await startPackageAppDev({
79
- manifest,
80
- token: input.auth.token,
81
- apiUrl: input.auth.apiUrl,
82
- target: input.target,
83
- port: input.port,
84
- defaultPort: defaultDevPort(manifest.kodyId),
85
- appBasePath: input.appBasePath,
86
- ...(input.auth.org ? { org: input.auth.org } : {}),
87
- ...(input.auth.depResolve ? { depResolve: input.auth.depResolve } : {}),
88
- ...(input.passthroughHosts?.length
89
- ? { passthroughHosts: input.passthroughHosts }
90
- : input.auth.passthroughHosts?.length
91
- ? { passthroughHosts: input.auth.passthroughHosts }
92
- : {}),
93
- allowPrivateNetwork: input.allowPrivateNetwork,
94
- liveReload: input.liveReload ?? true,
95
- onStatus: (message) => input.io.stderr(`${message}\n`),
96
- onError: (message) => input.io.stderr(`${message}\n`),
97
- onEvent,
98
- // Register as soon as the port is bound so a second `kody dev`
99
- // during the first build hits `dev_already_running` instead of
100
- // stealing the next free port and overwriting the registry.
101
- // Explicit `--port` starts a second server on purpose — leave the
102
- // primary attach registry alone so fetch keeps talking to it.
103
- onListening: async ({ port, hostedUrl, appBasePath }) => {
104
- if (input.port !== undefined)
105
- return;
106
- await writeDevRegistration({
107
- pid: process.pid,
108
- origin: hostedUrl,
109
- port,
110
- basePath: appBasePath,
111
- target: input.target,
112
- root: manifest.root,
113
- });
114
- registered = true;
115
- },
116
- });
117
- }
118
- catch (error) {
119
- if (registered) {
120
- await removeDevRegistration(manifest.root, process.pid, input.target).catch(() => { });
121
- }
122
- await input.auth.closeMock?.();
123
- throw error;
124
- }
125
- const shutdown = async () => {
126
- await server.close();
127
- await removeDevRegistration(manifest.root, process.pid, input.target).catch(() => { });
128
- if (input.readyFile)
129
- await removeOwnedReadyFile(input.readyFile, process.pid);
130
- await input.auth.closeMock?.();
131
- };
132
- try {
133
- const status = server.status();
134
- const statusUrl = `${server.hostedUrl}${devStatusPath}`;
135
- const ready = {
136
- url: status.url,
137
- port: server.port,
138
- basePath: server.appBasePath,
139
- pid: process.pid,
140
- statusUrl,
141
- };
142
- if (input.readyFile) {
143
- await mkdir(dirname(input.readyFile), { recursive: true });
144
- await writeFile(input.readyFile, `${JSON.stringify(ready, null, 2)}\n`);
145
- }
146
- if (input.json) {
147
- input.io.stdout(`${JSON.stringify({
148
- type: 'ready',
149
- ts: new Date().toISOString(),
150
- ...ready,
151
- target: input.target,
152
- package: status.package,
153
- buildId: status.buildId,
154
- state: status.state,
155
- })}\n`);
156
- }
157
- else {
158
- input.io.stdout(`kody dev listening on ${status.url}\n` +
159
- `target: ${input.target}\n` +
160
- `package: ${manifest.name} (${manifest.kodyId})\n` +
161
- `status: ${statusUrl}\n` +
162
- `Agents: kody dev fetch /path | job <name> | webhook <name> --body file.json | emit <event> --body file.json | check\n`);
163
- }
164
- }
165
- catch (error) {
166
- // Ready-file failures must not leave the listen handles up.
167
- await shutdown().catch(() => { });
168
- throw error;
169
- }
170
- if (input.serveOnce) {
171
- await shutdown();
172
- return 0;
173
- }
174
- await new Promise((resolveWait) => {
175
- const signals = ['SIGINT', 'SIGTERM', 'SIGHUP'];
176
- const stop = async () => {
177
- for (const signal of signals)
178
- process.off(signal, onSig);
179
- await shutdown();
180
- resolveWait();
181
- };
182
- const onSig = () => {
183
- void stop();
184
- };
185
- for (const signal of signals)
186
- process.on(signal, onSig);
187
- });
188
- return 0;
189
- }
190
- /**
191
- * `kody dev fetch` against an already running `kody dev` for this package and
192
- * target, if there is one. Returns null when nothing is running so the caller
193
- * can boot a one-shot server.
194
- */
195
- export async function tryAttachedDevFetch(input) {
196
- let root;
197
- try {
198
- root = (await loadPackageManifest(input.cwd)).root;
199
- }
200
- catch {
201
- return null;
202
- }
203
- const running = await findRunningDevServer({ root, target: input.target });
204
- if (!running)
205
- return null;
206
- const { registration } = running;
207
- const rest = input.path.startsWith('/') ? input.path : `/${input.path}`;
208
- const url = new URL(`${registration.basePath}${rest === '/' && registration.basePath ? '' : rest}` || '/', registration.origin);
209
- input.io.stderr(`Attached to running kody dev (pid ${registration.pid}) at ${registration.origin}\n`);
210
- const response = await fetch(url, {
211
- method: input.method ?? 'GET',
212
- headers: input.body ? { 'content-type': 'application/json' } : undefined,
213
- body: input.body,
214
- });
215
- const body = await response.text();
216
- const headers = {};
217
- response.headers.forEach((value, key) => {
218
- headers[key] = value;
219
- });
220
- const result = { status: response.status, headers, body };
221
- if (input.json) {
222
- input.io.stdout(`${JSON.stringify(result, null, 2)}\n`);
223
- }
224
- else {
225
- input.io.stdout(`HTTP ${result.status}\n${result.body}\n`);
226
- }
227
- return result.status >= 400 ? 1 : 0;
228
- }
229
- export async function runDevFetch(input) {
230
- let server;
231
- try {
232
- const manifest = await loadPackageManifest(input.cwd);
233
- server = await startPackageAppDev({
234
- manifest,
235
- token: input.auth.token,
236
- apiUrl: input.auth.apiUrl,
237
- target: input.target,
238
- port: input.port,
239
- appBasePath: input.appBasePath,
240
- ...(input.auth.org ? { org: input.auth.org } : {}),
241
- ...(input.auth.depResolve ? { depResolve: input.auth.depResolve } : {}),
242
- ...(input.auth.passthroughHosts?.length
243
- ? { passthroughHosts: input.auth.passthroughHosts }
244
- : {}),
245
- allowPrivateNetwork: input.allowPrivateNetwork,
246
- watch: false,
247
- onStatus: (message) => input.io.stderr(`${message}\n`),
248
- onError: (message) => input.io.stderr(`${message}\n`),
249
- onEvent: (event) => {
250
- // stdout is reserved for the fetch result; logs and errors go to stderr.
251
- // Without a watcher a build error rejects startup, and the CLI prints that.
252
- if (event.type === 'log' || event.type === 'runtime_error') {
253
- input.io.stderr(`${formatDevEvent(event).text}\n`);
254
- }
255
- },
256
- });
257
- }
258
- catch (error) {
259
- await input.auth.closeMock?.();
260
- throw error;
261
- }
262
- try {
263
- const result = await server.fetchPath(input.path, {
264
- method: input.method,
265
- body: input.body,
266
- headers: input.body
267
- ? { 'content-type': 'application/json' }
268
- : undefined,
269
- });
270
- if (input.json) {
271
- input.io.stdout(`${JSON.stringify(result, null, 2)}\n`);
272
- }
273
- else {
274
- input.io.stdout(`HTTP ${result.status}\n${result.body}\n`);
275
- }
276
- return result.status >= 400 ? 1 : 0;
277
- }
278
- finally {
279
- await server.close();
280
- await input.auth.closeMock?.();
281
- }
282
- }
283
- export async function runDevJob(input) {
284
- const manifest = await loadPackageManifest(input.cwd);
285
- const job = manifest.jobs[input.jobName];
286
- if (!job) {
287
- throw new StructuredCliError({
288
- code: 'dev_surface_missing',
289
- message: `No job named ${JSON.stringify(input.jobName)}.`,
290
- where: manifest.packageJsonPath,
291
- fix: `Known jobs: ${Object.keys(manifest.jobs).join(', ') || '(none)'}.`,
292
- target: input.target,
293
- });
294
- }
295
- const modulePath = resolvePackagePath(manifest, job.entry);
296
- if (input.dryRun) {
297
- return printDevDryRun({
298
- target: input.target,
299
- surface: `job:${input.jobName}`,
300
- modulePath,
301
- params: undefined,
302
- extra: {
303
- schedule: job.schedule,
304
- scheduleRaw: job.scheduleRaw,
305
- timezone: job.timezone ?? null,
306
- enabled: job.enabled ?? null,
307
- },
308
- json: input.json,
309
- io: input.io,
310
- closeMock: input.auth.closeMock,
311
- });
312
- }
313
- // Scheduler contract: no params. Never schedules locally — runs once.
314
- return await runPackageModuleOnce({
315
- manifest,
316
- modulePath,
317
- params: undefined,
318
- target: input.target,
319
- auth: input.auth,
320
- json: input.json,
321
- allowPrivateNetwork: input.allowPrivateNetwork,
322
- io: input.io,
323
- surface: `job:${input.jobName}`,
324
- });
325
- }
326
- export async function runDevWebhook(input) {
327
- const manifest = await loadPackageManifest(input.cwd);
328
- const webhook = manifest.webhooks[input.webhookName];
329
- if (!webhook) {
330
- throw new StructuredCliError({
331
- code: 'dev_surface_missing',
332
- message: `No webhook named ${JSON.stringify(input.webhookName)}.`,
333
- where: manifest.packageJsonPath,
334
- fix: `Known webhooks: ${Object.keys(manifest.webhooks).join(', ') || '(none)'}.`,
335
- target: input.target,
336
- });
337
- }
338
- const rawBody = await readFile(resolve(input.cwd ?? process.cwd(), input.bodyPath), 'utf8');
339
- let jsonBody = null;
340
- try {
341
- jsonBody = JSON.parse(rawBody);
342
- }
343
- catch {
344
- jsonBody = null;
345
- }
346
- const params = webhook.inputMode === 'params'
347
- ? (jsonBody ?? {})
348
- : {
349
- webhook: {
350
- packageKodyId: manifest.kodyId,
351
- name: input.webhookName,
352
- receivedAt: new Date().toISOString(),
353
- },
354
- request: {
355
- method: 'POST',
356
- contentType: 'application/json',
357
- headers: { 'content-type': 'application/json' },
358
- body: rawBody,
359
- json: jsonBody,
360
- },
361
- synthetic: true,
362
- };
363
- const modulePath = resolveExportModulePath(manifest, webhook.export);
364
- if (input.dryRun) {
365
- return printDevDryRun({
366
- target: input.target,
367
- surface: `webhook:${input.webhookName}`,
368
- modulePath,
369
- params,
370
- extra: { export: webhook.export, bodyPath: input.bodyPath },
371
- json: input.json,
372
- io: input.io,
373
- closeMock: input.auth.closeMock,
374
- });
375
- }
376
- return await runPackageModuleOnce({
377
- manifest,
378
- modulePath,
379
- params,
380
- target: input.target,
381
- auth: input.auth,
382
- json: input.json,
383
- allowPrivateNetwork: input.allowPrivateNetwork,
384
- io: input.io,
385
- surface: `webhook:${input.webhookName}`,
386
- });
387
- }
388
- /**
389
- * Deliver an event to the local subscription handler in the platform's delivery
390
- * shape. On mock, any event type is allowed (handler may still validate).
391
- */
392
- export async function runDevEmit(input) {
393
- const manifest = await loadPackageManifest(input.cwd);
394
- const subscription = manifest.subscriptions[input.event];
395
- if (!subscription) {
396
- if (input.target !== 'mock') {
397
- throw new StructuredCliError({
398
- code: 'dev_surface_missing',
399
- message: `No subscription for event ${JSON.stringify(input.event)}.`,
400
- where: manifest.packageJsonPath,
401
- fix: `Known subscriptions: ${Object.keys(manifest.subscriptions).join(', ') || '(none)'}. On --target mock you can still declare the handler first.`,
402
- target: input.target,
403
- });
404
- }
405
- throw new StructuredCliError({
406
- code: 'dev_surface_missing',
407
- message: `No subscription for event ${JSON.stringify(input.event)} in package.json#kody.subscriptions.`,
408
- where: manifest.packageJsonPath,
409
- fix: `Add a handler under kody.subscriptions[${JSON.stringify(input.event)}], then retry. Mock allows any event type once declared.`,
410
- target: input.target,
411
- });
412
- }
413
- const rawBody = await readFile(resolve(input.cwd ?? process.cwd(), input.bodyPath), 'utf8');
414
- let envelope;
415
- try {
416
- const parsed = JSON.parse(rawBody);
417
- if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
418
- throw new Error('body must be a JSON object');
419
- }
420
- envelope = { ...parsed };
421
- }
422
- catch (error) {
423
- throw new StructuredCliError({
424
- code: 'package_manifest_invalid',
425
- message: `Could not parse event body ${input.bodyPath} as a JSON object.`,
426
- fix: 'Pass --body event.json with the platform delivery envelope fields.',
427
- details: { cause: error instanceof Error ? error.message : String(error) },
428
- target: input.target,
429
- });
430
- }
431
- // Platform delivery shape: caller body is the handler params; mark synthetic.
432
- if (typeof envelope.event !== 'string') {
433
- envelope.event = input.event;
434
- }
435
- envelope.synthetic = true;
436
- if (envelope.idempotency_key === undefined) {
437
- envelope.idempotency_key = `synthetic:local:${Date.now()}`;
438
- }
439
- const modulePath = resolvePackagePath(manifest, subscription.handler);
440
- if (input.dryRun) {
441
- return printDevDryRun({
442
- target: input.target,
443
- surface: `subscription:${input.event}`,
444
- modulePath,
445
- params: envelope,
446
- extra: { handler: subscription.handler, bodyPath: input.bodyPath },
447
- json: input.json,
448
- io: input.io,
449
- closeMock: input.auth.closeMock,
450
- });
451
- }
452
- return await runPackageModuleOnce({
453
- manifest,
454
- modulePath,
455
- params: envelope,
456
- target: input.target,
457
- auth: input.auth,
458
- json: input.json,
459
- allowPrivateNetwork: input.allowPrivateNetwork,
460
- io: input.io,
461
- surface: `subscription:${input.event}`,
462
- });
463
- }
464
- /**
465
- * Bundle the package surfaces + light publish validations without running them.
466
- * Soft-suggests `.kody/mocks.ts` when credentialed fetch is detected.
467
- */
468
- export async function runDevCheck(input) {
469
- const manifest = await loadPackageManifest(input.cwd);
470
- const checks = [];
471
- const credentialSignals = [];
472
- const push = (name, ok, detail) => {
473
- checks.push({ name, ok, detail });
474
- };
475
- const bundleAndScan = async (label, modulePath) => {
476
- try {
477
- const bundled = await bundleLocalUserModule(modulePath);
478
- push(label, true, label.startsWith('app.entry') ? modulePath : undefined);
479
- credentialSignals.push(...(await detectCredentialedFetchInSource(bundled, label)));
480
- }
481
- catch (error) {
482
- push(label, false, error instanceof Error ? error.message : String(error));
483
- }
484
- };
485
- push('package.json', true, manifest.name);
486
- push('kody.id', Boolean(manifest.kodyId), manifest.kodyId);
487
- try {
488
- await readFile(resolve(manifest.root, 'README.md'));
489
- push('README.md', true);
490
- }
491
- catch {
492
- push('README.md', false, 'Publish requires README.md');
493
- }
494
- try {
495
- await readFile(resolve(manifest.root, 'AGENTS.md'));
496
- push('AGENTS.md', true);
497
- }
498
- catch {
499
- push('AGENTS.md', false, 'Publish requires AGENTS.md');
500
- }
501
- if (manifest.app?.entry) {
502
- await bundleAndScan('app.entry bundle', resolvePackagePath(manifest, manifest.app.entry));
503
- }
504
- else {
505
- push('app.entry', true, 'none (ok)');
506
- }
507
- for (const [name, job] of Object.entries(manifest.jobs)) {
508
- await bundleAndScan(`job:${name}`, resolvePackagePath(manifest, job.entry));
509
- }
510
- for (const [name, webhook] of Object.entries(manifest.webhooks)) {
511
- await bundleAndScan(`webhook:${name}`, resolveExportModulePath(manifest, webhook.export));
512
- }
513
- for (const [topic, sub] of Object.entries(manifest.subscriptions)) {
514
- await bundleAndScan(`subscription:${topic}`, resolvePackagePath(manifest, sub.handler));
515
- }
516
- for (const [key, rel] of Object.entries(manifest.exports)) {
517
- await bundleAndScan(`export:${key}`, resolvePackagePath(manifest, rel));
518
- }
519
- let hasMocksFile = false;
520
- try {
521
- await access(join(manifest.root, packageMocksRelativePath));
522
- hasMocksFile = true;
523
- }
524
- catch {
525
- hasMocksFile = false;
526
- }
527
- const mocksDetail = mocksSuggestionDetail({
528
- signals: credentialSignals,
529
- hasMocksFile,
530
- });
531
- if (mocksDetail) {
532
- // Soft tip — never fails the check; agents learn before unmocked_request.
533
- push(packageMocksRelativePath, true, mocksDetail);
534
- }
535
- const failed = checks.filter((check) => !check.ok);
536
- if (input.json) {
537
- input.io.stdout(`${JSON.stringify({
538
- target: input.target,
539
- checks,
540
- ok: failed.length === 0,
541
- ...(credentialSignals.length > 0
542
- ? {
543
- credentialedFetch: {
544
- detected: true,
545
- hasMocksFile,
546
- signals: credentialSignals,
547
- },
548
- }
549
- : {}),
550
- }, null, 2)}\n`);
551
- }
552
- else {
553
- for (const check of checks) {
554
- const mark = check.ok ? 'ok' : 'FAIL';
555
- input.io.stdout(`${mark.padEnd(4)} ${check.name}${check.detail ? ` — ${check.detail}` : ''}\n`);
556
- }
557
- input.io.stdout(failed.length === 0
558
- ? `kody dev check passed (${checks.length} checks, target ${input.target})\n`
559
- : `kody dev check failed: ${failed.length}/${checks.length}\n`);
560
- }
561
- return failed.length === 0 ? 0 : 1;
562
- }
563
- async function runPackageModuleOnce(input) {
564
- const packageContext = buildLocalPackageContext({
565
- kodyId: input.manifest.kodyId,
566
- hostedUrl: input.auth.apiUrl.startsWith('http')
567
- ? 'http://127.0.0.1:0'
568
- : 'http://127.0.0.1:0',
569
- appBasePath: '',
570
- });
571
- try {
572
- const result = await runLocalPackageModule({
573
- modulePath: input.modulePath,
574
- params: input.params,
575
- token: input.auth.token,
576
- apiUrl: input.auth.apiUrl,
577
- target: input.target,
578
- packageContext,
579
- packageRoot: input.manifest.root,
580
- ...(input.auth.org ? { org: input.auth.org } : {}),
581
- ...(input.auth.depResolve ? { depResolve: input.auth.depResolve } : {}),
582
- ...(input.auth.passthroughHosts?.length
583
- ? { passthroughHosts: input.auth.passthroughHosts }
584
- : {}),
585
- allowPrivateNetwork: input.allowPrivateNetwork,
586
- onStatus: (message) => input.io.stderr(`${message}\n`),
587
- });
588
- input.io.stdout(formatToolResult(result, input.json === true));
589
- return result.isError ? 1 : 0;
590
- }
591
- finally {
592
- await input.auth.closeMock?.();
593
- }
594
- }
595
- /**
596
- * Show what `kody dev job|webhook|emit` would run without invoking the module
597
- * (safe against prod side effects).
598
- */
599
- async function printDevDryRun(input) {
600
- try {
601
- const plan = {
602
- dryRun: true,
603
- wouldInvoke: true,
604
- target: input.target,
605
- surface: input.surface,
606
- modulePath: input.modulePath,
607
- params: input.params ?? null,
608
- ...(input.extra ?? {}),
609
- note: input.target === 'prod'
610
- ? 'No module run and no prod side effects. Drop --dry-run to invoke once against prod CapabilityProxy.'
611
- : 'No module run. Drop --dry-run to invoke against the selected target.',
612
- };
613
- if (input.json) {
614
- input.io.stdout(`${JSON.stringify(plan, null, 2)}\n`);
615
- }
616
- else {
617
- input.io.stdout(`dry-run: would invoke ${input.surface} on --target ${input.target}\n` +
618
- `module: ${input.modulePath}\n` +
619
- `params: ${JSON.stringify(input.params ?? null, null, 2)}\n` +
620
- (input.extra
621
- ? `detail: ${JSON.stringify(input.extra, null, 2)}\n`
622
- : '') +
623
- `${plan.note}\n`);
624
- }
625
- return 0;
626
- }
627
- finally {
628
- await input.closeMock?.();
629
- }
630
- }
631
- function writeJsonEvent(io, event) {
632
- io.stdout(`${JSON.stringify({ ...event, ts: new Date().toISOString() })}\n`);
633
- }
634
- function writeDevEvent(io, event) {
635
- const { stream, text } = formatDevEvent(event);
636
- io[stream](`${text}\n`);
637
- }
638
- /** Parse `kody dev` argv after the `dev` token. */
639
- export function parseDevSubcommand(positionals) {
640
- const raw = positionals[0];
641
- if (!raw || raw.startsWith('-')) {
642
- return { subcommand: 'serve', rest: positionals };
643
- }
644
- switch (raw) {
645
- case 'serve':
646
- case 'fetch':
647
- case 'job':
648
- case 'webhook':
649
- case 'emit':
650
- case 'check':
651
- return { subcommand: raw, rest: positionals.slice(1) };
652
- default:
653
- throw new Error(`Unknown kody dev subcommand ${JSON.stringify(raw)}. Use serve | fetch | job | webhook | emit | check.`);
654
- }
655
- }
656
- /**
657
- * Remove `--ready-file` only when it still names this process. A successor
658
- * `kody dev` may have rewritten the same path before our shutdown finishes.
659
- */
660
- export async function removeOwnedReadyFile(path, ownerPid) {
661
- try {
662
- const parsed = JSON.parse(await readFile(path, 'utf8'));
663
- if (parsed.pid !== ownerPid)
664
- return;
665
- await rm(path, { force: true });
666
- }
667
- catch {
668
- // Missing or unreadable — nothing to clean up.
669
- }
670
- }
671
- void null;
672
- //# sourceMappingURL=dev-command.js.map