@kodycodes/cli 1.9.0 → 1.10.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.
@@ -3,6 +3,13 @@
3
3
  * same `kody:runtime` surface as ad hoc cloud execute; every call becomes a
4
4
  * `{ path, args }` hop to the CLI's loopback bridge, which adds the API token
5
5
  * and forwards it to CapabilityProxy. The token never enters workerd.
6
+ *
7
+ * Stamped `kody:@…` packages also receive a package-graph CapabilityProxy shim
8
+ * from origin. This host module still binds createAuthenticatedFetch /
9
+ * secretHeaders / oauthClientCredentials for ad hoc imports, and the entry
10
+ * installs the shared runtime ALS before evaluating user code so published
11
+ * bundles that inline optional runtime exports (Dropbox-style) see a populated
12
+ * store at module evaluation — matching cloud `__kodyRunInRuntime`.
6
13
  */
7
14
  export declare const localExecuteCompatibilityDate = "2026-04-16";
8
15
  export declare const localExecuteCompatibilityFlags: readonly ["nodejs_compat"];
@@ -14,6 +21,8 @@ export declare const localWorkerModuleNames: {
14
21
  /** Header carrying the per-run secret on workerd → bridge and CLI → workerd hops. */
15
22
  export declare const runSecretHeader = "x-kody-run-secret";
16
23
  export declare const runSecretEnvVar = "KODY_RUN_SECRET";
24
+ /** Runtime ALS symbol shared with stamped / inlined `kody:runtime` helpers. */
25
+ export declare const kodyRuntimeStorageSymbolDescription = "kody.runtimeStorage";
17
26
  export declare function createLocalRuntimeModuleSource(): string;
18
27
  export declare function createLocalEntrySource(): string;
19
28
  export type WorkerdPackageModuleFile = {
@@ -3,6 +3,13 @@
3
3
  * same `kody:runtime` surface as ad hoc cloud execute; every call becomes a
4
4
  * `{ path, args }` hop to the CLI's loopback bridge, which adds the API token
5
5
  * and forwards it to CapabilityProxy. The token never enters workerd.
6
+ *
7
+ * Stamped `kody:@…` packages also receive a package-graph CapabilityProxy shim
8
+ * from origin. This host module still binds createAuthenticatedFetch /
9
+ * secretHeaders / oauthClientCredentials for ad hoc imports, and the entry
10
+ * installs the shared runtime ALS before evaluating user code so published
11
+ * bundles that inline optional runtime exports (Dropbox-style) see a populated
12
+ * store at module evaluation — matching cloud `__kodyRunInRuntime`.
6
13
  */
7
14
  export const localExecuteCompatibilityDate = '2026-04-16';
8
15
  export const localExecuteCompatibilityFlags = ['nodejs_compat'];
@@ -14,8 +21,12 @@ export const localWorkerModuleNames = {
14
21
  /** Header carrying the per-run secret on workerd → bridge and CLI → workerd hops. */
15
22
  export const runSecretHeader = 'x-kody-run-secret';
16
23
  export const runSecretEnvVar = 'KODY_RUN_SECRET';
24
+ /** Runtime ALS symbol shared with stamped / inlined `kody:runtime` helpers. */
25
+ export const kodyRuntimeStorageSymbolDescription = 'kody.runtimeStorage';
17
26
  export function createLocalRuntimeModuleSource() {
18
27
  return `
28
+ import { AsyncLocalStorage } from 'node:async_hooks';
29
+
19
30
  let __kodyBridge = null;
20
31
 
21
32
  export function __kodyInstallLocalBridge(bridge) {
@@ -79,9 +90,131 @@ export const packageSecrets = {
79
90
  export const packageContext = Object.freeze({});
80
91
  export const email = null;
81
92
  export const events = null;
82
- export const createAuthenticatedFetch = undefined;
83
- export const secretHeaders = undefined;
84
- export const oauthClientCredentials = undefined;
93
+
94
+ const __kodyNullBodyStatuses = new Set([204, 205, 304]);
95
+
96
+ function __kodyBytesToBase64(bytes) {
97
+ let binary = '';
98
+ for (let i = 0; i < bytes.length; i += 1) {
99
+ binary += String.fromCharCode(bytes[i]);
100
+ }
101
+ return btoa(binary);
102
+ }
103
+
104
+ function __kodyBase64ToBytes(value) {
105
+ const binary = atob(value);
106
+ const bytes = new Uint8Array(binary.length);
107
+ for (let i = 0; i < binary.length; i += 1) {
108
+ bytes[i] = binary.charCodeAt(i);
109
+ }
110
+ return bytes;
111
+ }
112
+
113
+ async function __kodyBodyToBytes(body) {
114
+ if (typeof body === 'string') {
115
+ return new TextEncoder().encode(body);
116
+ }
117
+ if (body instanceof Uint8Array) return body;
118
+ if (body instanceof ArrayBuffer) return new Uint8Array(body);
119
+ if (ArrayBuffer.isView(body)) {
120
+ return new Uint8Array(body.buffer, body.byteOffset, body.byteLength);
121
+ }
122
+ if (typeof Blob !== 'undefined' && body instanceof Blob) {
123
+ return new Uint8Array(await body.arrayBuffer());
124
+ }
125
+ if (typeof URLSearchParams !== 'undefined' && body instanceof URLSearchParams) {
126
+ return new TextEncoder().encode(body.toString());
127
+ }
128
+ if (body && typeof body.getReader === 'function') {
129
+ return new Uint8Array(await new Response(body).arrayBuffer());
130
+ }
131
+ if (typeof FormData !== 'undefined' && body instanceof FormData) {
132
+ throw new Error(
133
+ 'Local execute createAuthenticatedFetch does not support FormData bodies yet; use Uint8Array, Blob, or string.',
134
+ );
135
+ }
136
+ throw new Error(
137
+ 'Local execute createAuthenticatedFetch could not serialize the request body.',
138
+ );
139
+ }
140
+
141
+ export async function createAuthenticatedFetch(providerName) {
142
+ const name = String(providerName ?? '').trim();
143
+ if (!name) {
144
+ throw new Error('Integration name is required.');
145
+ }
146
+ return async (input, init) => {
147
+ let url;
148
+ let method = 'GET';
149
+ let headers = {};
150
+ let bodyBytes = null;
151
+ if (typeof input === 'string' || input instanceof URL) {
152
+ url = String(input);
153
+ method = String(init?.method ?? 'GET');
154
+ headers = Object.fromEntries(new Headers(init?.headers).entries());
155
+ if (init?.body != null) {
156
+ bodyBytes = await __kodyBodyToBytes(init.body);
157
+ }
158
+ } else {
159
+ const merged = new Request(input, init);
160
+ url = merged.url;
161
+ method = merged.method;
162
+ headers = Object.fromEntries(merged.headers.entries());
163
+ if (method !== 'GET' && method !== 'HEAD') {
164
+ bodyBytes = new Uint8Array(await merged.arrayBuffer());
165
+ }
166
+ }
167
+ const result = await __kodyCall(['kody', 'authenticatedFetch'], [{
168
+ providerName: name,
169
+ request: {
170
+ url,
171
+ method,
172
+ headers,
173
+ ...(bodyBytes != null
174
+ ? { bodyBase64: __kodyBytesToBase64(bodyBytes) }
175
+ : {}),
176
+ },
177
+ }]);
178
+ const bytes = __kodyBase64ToBytes(result.bodyBase64 ?? '');
179
+ return new Response(
180
+ __kodyNullBodyStatuses.has(result.status) ? null : bytes,
181
+ {
182
+ status: result.status,
183
+ statusText: result.statusText,
184
+ headers: result.headers,
185
+ },
186
+ );
187
+ };
188
+ }
189
+
190
+ export const secretHeaders = {
191
+ basic(input) {
192
+ const usernameSecret = String(input?.usernameSecret ?? '').trim();
193
+ const passwordSecret = String(input?.passwordSecret ?? '').trim();
194
+ if (!usernameSecret || !passwordSecret) {
195
+ throw new Error(
196
+ 'secretHeaders.basic requires usernameSecret and passwordSecret.',
197
+ );
198
+ }
199
+ const scope =
200
+ typeof input?.scope === 'string' && input.scope.trim()
201
+ ? input.scope.trim()
202
+ : null;
203
+ return scope
204
+ ? \`{{secret-basic:username=\${usernameSecret},password=\${passwordSecret}|scope=\${scope}}}\`
205
+ : \`{{secret-basic:username=\${usernameSecret},password=\${passwordSecret}}}\`;
206
+ },
207
+ };
208
+
209
+ export async function oauthClientCredentials(input) {
210
+ return await __kodyCall(['kody', 'oauthClientCredentials'], [input ?? {}]);
211
+ }
212
+
213
+ const __kodyRuntimeStorageSymbol = Symbol.for(${JSON.stringify(kodyRuntimeStorageSymbolDescription)});
214
+ const __globalAny = globalThis;
215
+ const __kodyRuntimeStorage =
216
+ __globalAny[__kodyRuntimeStorageSymbol] ??
217
+ (__globalAny[__kodyRuntimeStorageSymbol] = new AsyncLocalStorage());
85
218
 
86
219
  const __kodyRuntimeDefault = Object.freeze({
87
220
  kody,
@@ -98,11 +231,19 @@ const __kodyRuntimeDefault = Object.freeze({
98
231
  });
99
232
  export default __kodyRuntimeDefault;
100
233
  export const KodyRuntime = Object.freeze({ defaultValue: __kodyRuntimeDefault });
234
+
235
+ /** Enter the shared runtime ALS before evaluating user / package modules. */
236
+ export function __kodyRunInLocalRuntime(callback) {
237
+ return __kodyRuntimeStorage.run(__kodyRuntimeDefault, callback);
238
+ }
101
239
  `.trimStart();
102
240
  }
103
241
  export function createLocalEntrySource() {
104
242
  return `
105
- import { __kodyInstallLocalBridge } from ${JSON.stringify(localWorkerModuleNames.runtime)};
243
+ import {
244
+ __kodyInstallLocalBridge,
245
+ __kodyRunInLocalRuntime,
246
+ } from ${JSON.stringify(localWorkerModuleNames.runtime)};
106
247
 
107
248
  const __kodyRunSecretHeader = ${JSON.stringify(runSecretHeader)};
108
249
  let __kodyClaimed = false;
@@ -140,11 +281,15 @@ export default {
140
281
  error: (...a) => { logs.push('[error] ' + __kodyFormatLogArgs(a)); },
141
282
  };
142
283
  try {
143
- const module = await import(${JSON.stringify(`./${localWorkerModuleNames.user}`)});
144
- if (typeof module?.default !== 'function') {
145
- throw new Error('Kody execute modules must default export a function.');
146
- }
147
- const result = await module.default(params);
284
+ // Evaluate user + stamped package modules inside the runtime ALS so
285
+ // inlined optional exports capture callable helpers (cloud parity).
286
+ const result = await __kodyRunInLocalRuntime(async () => {
287
+ const module = await import(${JSON.stringify(`./${localWorkerModuleNames.user}`)});
288
+ if (typeof module?.default !== 'function') {
289
+ throw new Error('Kody execute modules must default export a function.');
290
+ }
291
+ return await module.default(params);
292
+ });
148
293
  return new Response(JSON.stringify({ result, logs }), {
149
294
  headers: { 'content-type': 'application/json' },
150
295
  });
@@ -1 +1 @@
1
- {"version":3,"file":"local-runtime-source.js","sourceRoot":"","sources":["../src/local-runtime-source.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,6BAA6B,GAAG,YAAY,CAAA;AACzD,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,eAAe,CAAU,CAAA;AAExE,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACrC,KAAK,EAAE,uBAAuB;IAC9B,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,cAAc;CACd,CAAA;AAEV,qFAAqF;AACrF,MAAM,CAAC,MAAM,eAAe,GAAG,mBAAmB,CAAA;AAClD,MAAM,CAAC,MAAM,eAAe,GAAG,iBAAiB,CAAA;AAEhD,MAAM,UAAU,8BAA8B;IAC7C,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;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AAC,sBAAsB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC;cACjG,IAAI,CAAC,SAAS,CAAC,sBAAsB,CAAC,OAAO,CAAC,sBAAsB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,YAAY;;wBAE9G,IAAI,CAAC,SAAS,CAAC,6BAA6B,CAAC;0BAC3C,KAAK;;;;cAIjB,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,uBAAuB,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC;;;CAGlG,CAAA;AACD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kodycodes/cli",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "Official Kody MCP client CLI: login, secure token storage, search, and execute.",
5
5
  "type": "module",
6
6
  "bin": {