@kodycodes/cli 1.3.0 → 1.5.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 (40) hide show
  1. package/README.md +67 -3
  2. package/dist/api-token.d.ts +14 -0
  3. package/dist/api-token.js +21 -0
  4. package/dist/api-token.js.map +1 -0
  5. package/dist/auth.js +2 -2
  6. package/dist/auth.js.map +1 -1
  7. package/dist/capability-proxy.d.ts +46 -0
  8. package/dist/capability-proxy.js +151 -0
  9. package/dist/capability-proxy.js.map +1 -0
  10. package/dist/cli.d.ts +23 -1
  11. package/dist/cli.js +117 -4
  12. package/dist/cli.js.map +1 -1
  13. package/dist/defaults.d.ts +3 -0
  14. package/dist/defaults.js +3 -0
  15. package/dist/defaults.js.map +1 -1
  16. package/dist/help.js +20 -4
  17. package/dist/help.js.map +1 -1
  18. package/dist/invoke-passthrough.d.ts +8 -0
  19. package/dist/invoke-passthrough.js +46 -0
  20. package/dist/invoke-passthrough.js.map +1 -0
  21. package/dist/local-execute.d.ts +28 -0
  22. package/dist/local-execute.js +286 -0
  23. package/dist/local-execute.js.map +1 -0
  24. package/dist/local-runtime-source.d.ts +32 -0
  25. package/dist/local-runtime-source.js +199 -0
  26. package/dist/local-runtime-source.js.map +1 -0
  27. package/dist/network-error.d.ts +2 -0
  28. package/dist/network-error.js +11 -0
  29. package/dist/network-error.js.map +1 -0
  30. package/dist/open-api-client.d.ts +40 -0
  31. package/dist/open-api-client.js +152 -0
  32. package/dist/open-api-client.js.map +1 -0
  33. package/dist/remote-execute.d.ts +28 -0
  34. package/dist/remote-execute.js +99 -0
  35. package/dist/remote-execute.js.map +1 -0
  36. package/dist/workerd-binary.d.ts +31 -0
  37. package/dist/workerd-binary.js +98 -0
  38. package/dist/workerd-binary.js.map +1 -0
  39. package/package.json +1 -1
  40. package/skills/kody/SKILL.md +11 -0
@@ -0,0 +1,98 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { createReadStream, createWriteStream, existsSync } from 'node:fs';
3
+ import { chmod, mkdir, rename, rm } from 'node:fs/promises';
4
+ import { homedir } from 'node:os';
5
+ import { dirname, join } from 'node:path';
6
+ import { Readable, Transform } from 'node:stream';
7
+ import { pipeline } from 'node:stream/promises';
8
+ import { createGunzip } from 'node:zlib';
9
+ import { describeNetworkError } from './network-error.js';
10
+ /** Matches the workerd the Kody platform runs; bump together with the digests. */
11
+ export const workerdVersion = '1.20260815.1';
12
+ /** sha256 of each gzipped release asset on github.com/cloudflare/workerd. */
13
+ export const workerdAssetDigests = {
14
+ 'linux-64': '05099ec6f50832fcbc327490e5a971d682c97231fb01943b61726db07677e559',
15
+ 'linux-arm64': '0331597b53771170df2ab8344d9ae81d38bad4959e47152dd86592eedd9264c7',
16
+ 'darwin-64': '752ec91c01dfc44d660de6e3a654879cfc1277caa7f3c5312871c608c4c2d6df',
17
+ 'darwin-arm64': 'c189fc08f691739c37d8784945e943e33b66cbd4e14635a061fe516dc95f2b39',
18
+ };
19
+ export function workerdTargetFor(platform = process.platform, arch = process.arch) {
20
+ const os = platform === 'linux' ? 'linux' : platform === 'darwin' ? 'darwin' : null;
21
+ const cpu = arch === 'x64' ? '64' : arch === 'arm64' ? 'arm64' : null;
22
+ if (!os || !cpu) {
23
+ throw new Error(`execute --local supports Linux and macOS on x64 or arm64 (this machine is ${platform}-${arch}).`);
24
+ }
25
+ return `${os}-${cpu}`;
26
+ }
27
+ export function workerdAssetUrl(target, version = workerdVersion) {
28
+ return `https://github.com/cloudflare/workerd/releases/download/v${version}/workerd-${target}.gz`;
29
+ }
30
+ export function userCacheDir(env = process.env, platform = process.platform, home = homedir()) {
31
+ if (env.KODY_CACHE_DIR)
32
+ return env.KODY_CACHE_DIR;
33
+ if (platform === 'darwin')
34
+ return join(home, 'Library', 'Caches', 'kody');
35
+ return join(env.XDG_CACHE_HOME || join(home, '.cache'), 'kody');
36
+ }
37
+ export function cachedWorkerdPath(cacheDir, target) {
38
+ return join(cacheDir, 'workerd', `${workerdVersion}-${target}`, 'workerd');
39
+ }
40
+ /**
41
+ * Returns a runnable workerd path: `KODY_WORKERD_PATH` when set, otherwise the
42
+ * pinned release under the user cache dir (downloaded and verified on first use).
43
+ */
44
+ export async function ensureWorkerdBinary(input = {}) {
45
+ const env = input.env ?? process.env;
46
+ if (env.KODY_WORKERD_PATH)
47
+ return env.KODY_WORKERD_PATH;
48
+ const target = input.target ?? workerdTargetFor();
49
+ const binaryPath = cachedWorkerdPath(input.cacheDir ?? userCacheDir(env), target);
50
+ if (existsSync(binaryPath))
51
+ return binaryPath;
52
+ const url = workerdAssetUrl(target);
53
+ input.onDownload?.(url);
54
+ await downloadVerifiedGzip({
55
+ url,
56
+ sha256: workerdAssetDigests[target],
57
+ destination: binaryPath,
58
+ fetchFn: input.fetchFn ?? fetch,
59
+ });
60
+ return binaryPath;
61
+ }
62
+ export async function downloadVerifiedGzip(input) {
63
+ let response;
64
+ try {
65
+ response = await input.fetchFn(input.url);
66
+ }
67
+ catch (error) {
68
+ throw new Error(`Could not download workerd from ${input.url} (${describeNetworkError(error)}).`);
69
+ }
70
+ if (!response.ok || !response.body) {
71
+ throw new Error(`Could not download workerd from ${input.url} (HTTP ${response.status}).`);
72
+ }
73
+ await mkdir(dirname(input.destination), { recursive: true });
74
+ const gzipPath = `${input.destination}.${process.pid}.gz`;
75
+ const partialPath = `${input.destination}.${process.pid}.partial`;
76
+ const hash = createHash('sha256');
77
+ const hashing = new Transform({
78
+ transform(chunk, _encoding, callback) {
79
+ hash.update(chunk);
80
+ callback(null, chunk);
81
+ },
82
+ });
83
+ try {
84
+ await pipeline(Readable.fromWeb(response.body), hashing, createWriteStream(gzipPath));
85
+ const digest = hash.digest('hex');
86
+ if (digest !== input.sha256) {
87
+ throw new Error(`workerd download from ${input.url} failed verification (sha256 ${digest}, expected ${input.sha256}).`);
88
+ }
89
+ await pipeline(createReadStream(gzipPath), createGunzip(), createWriteStream(partialPath));
90
+ await chmod(partialPath, 0o755);
91
+ await rename(partialPath, input.destination);
92
+ }
93
+ finally {
94
+ await rm(gzipPath, { force: true });
95
+ await rm(partialPath, { force: true });
96
+ }
97
+ }
98
+ //# sourceMappingURL=workerd-binary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workerd-binary.js","sourceRoot":"","sources":["../src/workerd-binary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACzE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAEzD,kFAAkF;AAClF,MAAM,CAAC,MAAM,cAAc,GAAG,cAAc,CAAA;AAE5C,6EAA6E;AAC7E,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAClC,UAAU,EAAE,kEAAkE;IAC9E,aAAa,EAAE,kEAAkE;IACjF,WAAW,EAAE,kEAAkE;IAC/E,cAAc,EAAE,kEAAkE;CACzE,CAAA;AAIV,MAAM,UAAU,gBAAgB,CAC/B,WAA4B,OAAO,CAAC,QAAQ,EAC5C,OAAe,OAAO,CAAC,IAAI;IAE3B,MAAM,EAAE,GAAG,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAA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I,EAAE,CAAC,CAAA;IACvC,CAAC;AACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kodycodes/cli",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "Official Kody MCP client CLI: login, secure token storage, search, and execute.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -69,3 +69,14 @@ Never ask the user to paste tokens into chat.
69
69
 
70
70
  Override the MCP URL with `--mcp-url` or `KODY_MCP_URL` for preview or local
71
71
  servers. Default: `https://kody.codes/mcp`.
72
+
73
+ To run execute with a scoped API token and **no** `kody login`, set
74
+ `KODY_API_TOKEN` (or `--token`). Cloud execute (no `--local`) goes through
75
+ CapabilityProxy → `kody.execute`. Add `--local` to run the module on this
76
+ machine instead. Mint the token with Kody's `api` tool — never read MCP OAuth
77
+ tokens from the host.
78
+
79
+ ```bash
80
+ KODY_API_TOKEN=… npx @kodycodes/cli execute --file ./task.js --params '{"q":"email"}'
81
+ KODY_API_TOKEN=… npx @kodycodes/cli execute --local --file ./task.js --params '{"q":"email"}'
82
+ ```