@wirecat/cli-template 0.8.0 → 0.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.
Files changed (125) hide show
  1. package/.github/workflows/ci.yml +3 -3
  2. package/.github/workflows/release.yml +63 -0
  3. package/.gitleaks.toml +18 -0
  4. package/AGENTS.md +9 -15
  5. package/CHANGELOG.md +87 -1
  6. package/README.md +4 -3
  7. package/bin/release +5 -3
  8. package/contracts/plan.json +2 -2
  9. package/dist/bin/clidev.js +34 -12
  10. package/dist/bundle/all-profiles-XHC7BG3P.js +24 -0
  11. package/dist/bundle/anthropic-N6B3ZZHQ.js +70 -0
  12. package/dist/bundle/bun-HUJLS7KP.js +169 -0
  13. package/dist/bundle/bun-sqlite-OWFO2TVR.js +69 -0
  14. package/dist/bundle/chunk-222FANS2.js +161 -0
  15. package/dist/bundle/chunk-2CFBHYFA.js +884 -0
  16. package/dist/bundle/chunk-2KQZ24GI.js +82 -0
  17. package/dist/bundle/chunk-2TBVT4SZ.js +31 -0
  18. package/dist/bundle/chunk-437W3Z2M.js +76 -0
  19. package/dist/bundle/chunk-4QRLPOJ7.js +18 -0
  20. package/dist/bundle/chunk-54AJONOM.js +54 -0
  21. package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
  22. package/dist/bundle/chunk-6CBWO7OF.js +73 -0
  23. package/dist/bundle/chunk-75LVQQEK.js +35782 -0
  24. package/dist/bundle/chunk-7RB76E2L.js +264 -0
  25. package/dist/bundle/chunk-7RXBN7HP.js +63 -0
  26. package/dist/bundle/chunk-ABP7FDMJ.js +122 -0
  27. package/dist/bundle/chunk-ADLS6FVG.js +24600 -0
  28. package/dist/bundle/chunk-AP7QKYBG.js +3531 -0
  29. package/dist/bundle/chunk-ASMH7JWZ.js +288 -0
  30. package/dist/bundle/chunk-B4EED2RF.js +100 -0
  31. package/dist/bundle/chunk-B4LM2B6F.js +1900 -0
  32. package/dist/bundle/chunk-BDSDQCV4.js +281 -0
  33. package/dist/bundle/chunk-DFDN6AUB.js +21 -0
  34. package/dist/bundle/chunk-DMCN22H6.js +35 -0
  35. package/dist/bundle/chunk-E42W72PQ.js +151 -0
  36. package/dist/bundle/chunk-EFHLQXG6.js +5104 -0
  37. package/dist/bundle/chunk-FIHDGZIB.js +34352 -0
  38. package/dist/bundle/chunk-FWVKHD2L.js +48 -0
  39. package/dist/bundle/chunk-FXS3X76A.js +193 -0
  40. package/dist/bundle/chunk-HTQTIKWP.js +928 -0
  41. package/dist/bundle/chunk-IJ3IA7EK.js +24 -0
  42. package/dist/bundle/chunk-JEBSORH7.js +3379 -0
  43. package/dist/bundle/chunk-JTTW5ZKF.js +45 -0
  44. package/dist/bundle/chunk-LSEF4QC3.js +3075 -0
  45. package/dist/bundle/chunk-LY7GS2YI.js +58 -0
  46. package/dist/bundle/chunk-MFS52LTZ.js +570 -0
  47. package/dist/bundle/chunk-MNSD5BX2.js +78 -0
  48. package/dist/bundle/chunk-MTGLJCAZ.js +24 -0
  49. package/dist/bundle/chunk-MZVV2JZT.js +744 -0
  50. package/dist/bundle/chunk-NE3NSB5O.js +8341 -0
  51. package/dist/bundle/chunk-NTLPDH76.js +440 -0
  52. package/dist/bundle/chunk-O3PBQVAB.js +447 -0
  53. package/dist/bundle/chunk-O5EHUB2V.js +2 -0
  54. package/dist/bundle/chunk-O5LMDQTO.js +82 -0
  55. package/dist/bundle/chunk-OPJ24VGH.js +1028 -0
  56. package/dist/bundle/chunk-OPPMGPFW.js +164 -0
  57. package/dist/bundle/chunk-QGNNMPUB.js +158 -0
  58. package/dist/bundle/chunk-QVJLOUQB.js +2 -0
  59. package/dist/bundle/chunk-S57AMKLX.js +6848 -0
  60. package/dist/bundle/chunk-TARN7CHN.js +215 -0
  61. package/dist/bundle/chunk-TJLGI3N6.js +1095 -0
  62. package/dist/bundle/chunk-VMTM46FH.js +7532 -0
  63. package/dist/bundle/chunk-W2IDKBNB.js +2315 -0
  64. package/dist/bundle/chunk-XFXBXQBS.js +630 -0
  65. package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
  66. package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
  67. package/dist/bundle/clidev.js +22 -0
  68. package/dist/bundle/command-contract-PEM3S634.js +29 -0
  69. package/dist/bundle/dist-ESHIQU4M.js +7577 -0
  70. package/dist/bundle/echarts-2QGL2JP5.js +42501 -0
  71. package/dist/bundle/embed-HHAAGHA6.js +35 -0
  72. package/dist/bundle/embedder-W2OGVVYH.js +108 -0
  73. package/dist/bundle/first-run-WCJUDUBU.js +23 -0
  74. package/dist/bundle/first-screen-U4DFUKUC.js +27 -0
  75. package/dist/bundle/instructions-OTZHT6NV.js +9 -0
  76. package/dist/bundle/mcp-OQBZXELQ.js +165 -0
  77. package/dist/bundle/mcp-VVF6J7SQ.js +151 -0
  78. package/dist/bundle/mcp-Y7VCIZ2J.js +78 -0
  79. package/dist/bundle/node-P4E63KXA.js +2340 -0
  80. package/dist/bundle/node-SYD4GX5O.js +176 -0
  81. package/dist/bundle/node-TLZSIHIJ.js +21 -0
  82. package/dist/bundle/node-sqlite-X2DGRFOZ.js +45 -0
  83. package/dist/bundle/oauth-42M34GQ5.js +17 -0
  84. package/dist/bundle/open-SWXRCDLN.js +19 -0
  85. package/dist/bundle/process-KAFGXZ7Q.js +91 -0
  86. package/dist/bundle/program-EHR4G7VN.js +16967 -0
  87. package/dist/bundle/prompt-ZQTMHRGX.js +12 -0
  88. package/dist/bundle/recognize-TTED4SE3.js +190 -0
  89. package/dist/bundle/remote-C37XJ4BP.js +26 -0
  90. package/dist/bundle/rerank-APFZAMQL.js +49 -0
  91. package/dist/bundle/serve-DDPIHDVZ.js +19 -0
  92. package/dist/bundle/server-L5GNG7KC.js +793 -0
  93. package/dist/bundle/server-LKVYA2AE.js +39 -0
  94. package/dist/bundle/state-WWPPHERF.js +33 -0
  95. package/dist/bundle/store-H6UIA4PK.js +120 -0
  96. package/dist/bundle/store-maintenance-command-EYBT64A2.js +40 -0
  97. package/dist/commands/mcp.d.ts.map +1 -1
  98. package/dist/commands/mcp.js +45 -30
  99. package/dist/commands/mcp.js.map +1 -1
  100. package/dist/version.d.ts +1 -1
  101. package/dist/version.d.ts.map +1 -1
  102. package/dist/version.js +1 -1
  103. package/dist/version.js.map +1 -1
  104. package/docs/commands.md +38 -22
  105. package/docs/dev/TESTING.md +14 -3
  106. package/docs/dev/reference-clis.md +17 -9
  107. package/docs/dev/skills/release/SKILL.md +9 -6
  108. package/docs/dev/skills/release/fresh-audit.md +4 -0
  109. package/docs/dev/test-matrix.md +10 -11
  110. package/docs/security.md +4 -0
  111. package/docs/usage.md +7 -6
  112. package/kit/dist/new.js +17 -2
  113. package/package.json +7 -5
  114. package/scripts/audit.sh +5 -3
  115. package/scripts/smoke-bundle.ts +63 -0
  116. package/scripts/test-matrix-untested.ts +4 -10
  117. package/scripts/version-level.test.ts +17 -1
  118. package/scripts/version-level.ts +35 -7
  119. package/skills/clidev-cli/SKILL.md +8 -0
  120. package/src/commands/mcp.ts +54 -33
  121. package/src/mcp-http.test.ts +20 -13
  122. package/src/mcp.test.ts +3 -3
  123. package/src/program.test.ts +8 -2
  124. package/src/roots.test.ts +2 -7
  125. package/src/version.ts +1 -1
@@ -0,0 +1,48 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ CliError
5
+ } from "./chunk-EFHLQXG6.js";
6
+ import {
7
+ __name
8
+ } from "./chunk-ZVVMGPBJ.js";
9
+
10
+ // node_modules/.pnpm/@wirecat+cli-core@0.469.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_9d12b0091b773232c527328da5835651/node_modules/@wirecat/cli-core/dist/http/public-url.js
11
+ var EXAMPLE = "--public-url https://<name>.ts.net";
12
+ var publicUrlOf = /* @__PURE__ */ __name((given, { missing, reaches, path = false }) => {
13
+ if (!given)
14
+ throw new CliError("configuration_error", `${missing} needs the tunnel's address: ${EXAMPLE}`);
15
+ let url;
16
+ try {
17
+ url = new URL(given);
18
+ } catch {
19
+ throw new CliError("validation_error", `--public-url is not an address: ${EXAMPLE}`);
20
+ }
21
+ if (url.username || url.password)
22
+ throw new CliError("validation_error", "--public-url must not contain login credentials");
23
+ const local = url.protocol === "http:" && ["localhost", "127.0.0.1"].includes(url.hostname);
24
+ if (url.protocol !== "https:" && !local)
25
+ throw new CliError("validation_error", `--public-url must be https \u2014 ${reaches} through it`);
26
+ if (url.search || url.hash || !path && url.pathname !== "/")
27
+ throw new CliError("validation_error", path ? `--public-url is the tunnel's address, or a path of it, without a query: ${EXAMPLE}/tg` : `--public-url is the tunnel's address only, without a path: ${EXAMPLE}`);
28
+ if (path && !/^(\/[A-Za-z0-9_-][A-Za-z0-9._-]*)*\/?$/.test(url.pathname))
29
+ throw new CliError("validation_error", "--public-url's path takes letters, digits, dot, dash and underscore: /tg");
30
+ if (path)
31
+ url.pathname = url.pathname.replace(/\/+$/, "") || "/";
32
+ return url;
33
+ }, "publicUrlOf");
34
+ var portOf = /* @__PURE__ */ __name((given, fallback) => {
35
+ if (given === void 0)
36
+ return fallback;
37
+ const port = Number(given);
38
+ if (!Number.isInteger(port) || port < 1 || port > 65535)
39
+ throw new CliError("validation_error", "--port takes 1\u201365535");
40
+ return port;
41
+ }, "portOf");
42
+ var mcpUrlOf = /* @__PURE__ */ __name((publicUrl) => new URL(`${publicUrl.pathname.replace(/\/+$/, "")}/mcp`, publicUrl.origin), "mcpUrlOf");
43
+
44
+ export {
45
+ publicUrlOf,
46
+ portOf,
47
+ mcpUrlOf
48
+ };
@@ -0,0 +1,193 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ listen
5
+ } from "./chunk-MNSD5BX2.js";
6
+ import {
7
+ ownerLogin
8
+ } from "./chunk-ASMH7JWZ.js";
9
+ import {
10
+ WebStandardStreamableHTTPServerTransport,
11
+ createMcpHandler,
12
+ getOAuthProtectedResourceMetadataUrl,
13
+ hostHeaderValidationResponse,
14
+ isLegacyRequest,
15
+ oauthMetadataResponse,
16
+ requireBearerAuth
17
+ } from "./chunk-5D4AEUVA.js";
18
+ import {
19
+ activityRecorder,
20
+ calledTools,
21
+ httpActivityFile,
22
+ httpLock
23
+ } from "./chunk-222FANS2.js";
24
+ import {
25
+ CliError
26
+ } from "./chunk-EFHLQXG6.js";
27
+ import {
28
+ __name
29
+ } from "./chunk-ZVVMGPBJ.js";
30
+
31
+ // node_modules/.pnpm/@wirecat+cli-core@0.469.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_9d12b0091b773232c527328da5835651/node_modules/@wirecat/cli-core/dist/mcp/http/serve.js
32
+ import { randomUUID } from "node:crypto";
33
+ var MCP_PATH = "/mcp";
34
+ var AS_METADATA = "/.well-known/oauth-authorization-server";
35
+ var LOCAL = ["localhost", "127.0.0.1"];
36
+ var MAX_SESSIONS = 20;
37
+ var MAX_LOGIN_BODY = 64 * 1024;
38
+ var SESSION_IDLE_MS = 60 * 60 * 1e3;
39
+ var sessionMissing = /* @__PURE__ */ __name(() => new Response(JSON.stringify({ jsonrpc: "2.0", error: { code: -32001, message: "Session not found" }, id: null }), {
40
+ status: 404,
41
+ headers: { "content-type": "application/json" }
42
+ }), "sessionMissing");
43
+ var legacySessions = /* @__PURE__ */ __name((build, now) => {
44
+ const sessions = /* @__PURE__ */ new Map();
45
+ const drop = /* @__PURE__ */ __name(async (id) => {
46
+ const one = sessions.get(id);
47
+ sessions.delete(id);
48
+ await one?.close();
49
+ }, "drop");
50
+ const handle = /* @__PURE__ */ __name(async (request, auth) => {
51
+ for (const [id2, one] of sessions)
52
+ if (now() - one.seen > SESSION_IDLE_MS)
53
+ await drop(id2);
54
+ const id = request.headers.get("mcp-session-id");
55
+ if (id) {
56
+ const known = sessions.get(id);
57
+ if (!known || known.clientId !== auth.clientId)
58
+ return sessionMissing();
59
+ known.seen = now();
60
+ return known.transport.handleRequest(request, { authInfo: auth });
61
+ }
62
+ const server = build();
63
+ const transport = new WebStandardStreamableHTTPServerTransport({
64
+ sessionIdGenerator: /* @__PURE__ */ __name(() => randomUUID(), "sessionIdGenerator"),
65
+ onsessionclosed: /* @__PURE__ */ __name((closed) => void sessions.delete(closed), "onsessionclosed")
66
+ });
67
+ await server.connect(transport);
68
+ const response = await transport.handleRequest(request, { authInfo: auth });
69
+ if (!transport.sessionId) {
70
+ await server.close();
71
+ return response;
72
+ }
73
+ sessions.set(transport.sessionId, { transport, close: /* @__PURE__ */ __name(() => server.close(), "close"), clientId: auth.clientId, seen: now() });
74
+ while (sessions.size > MAX_SESSIONS)
75
+ await drop(sessions.keys().next().value);
76
+ return response;
77
+ }, "handle");
78
+ return {
79
+ handle,
80
+ close: /* @__PURE__ */ __name(async () => {
81
+ for (const id of [...sessions.keys()])
82
+ await drop(id);
83
+ }, "close")
84
+ };
85
+ }, "legacySessions");
86
+ var metadataRequest = /* @__PURE__ */ __name((request, path, base) => {
87
+ const url = new URL(request.url);
88
+ const inserted = base && path === `${AS_METADATA}${base}`;
89
+ if (!inserted && url.pathname === path)
90
+ return request;
91
+ url.pathname = inserted ? AS_METADATA : path;
92
+ return new Request(url, { method: request.method, headers: request.headers });
93
+ }, "metadataRequest");
94
+ var toolsIn = /* @__PURE__ */ __name(async (request) => {
95
+ if (request.method !== "POST")
96
+ return [];
97
+ try {
98
+ return calledTools(await request.clone().json());
99
+ } catch {
100
+ return [];
101
+ }
102
+ }, "toolsIn");
103
+ var serveOverHttp = /* @__PURE__ */ __name(async (build, options) => {
104
+ const { publicUrl, port, tokenFile, appName, onCode, onError, now, lockFile, version } = options;
105
+ const lock = lockFile ? httpLock(lockFile, {
106
+ pid: process.pid,
107
+ startedAt: (/* @__PURE__ */ new Date()).toISOString(),
108
+ port,
109
+ publicUrl: publicUrl.href,
110
+ ...version ? { version } : {}
111
+ }) : void 0;
112
+ if (lock?.held)
113
+ throw new CliError("validation_error", `${appName} already serves MCP over HTTP for this profile on port ${lock.held.port} (PID ${lock.held.pid}, since ${lock.held.startedAt})`);
114
+ const base = publicUrl.pathname === "/" ? "" : publicUrl.pathname.replace(/\/+$/, "");
115
+ const issuer = new URL(`${publicUrl.origin}${base}`);
116
+ const resource = new URL(`${base}${MCP_PATH}`, publicUrl.origin);
117
+ const mcpPath = resource.pathname;
118
+ const publicPath = /* @__PURE__ */ __name((path) => base && path !== base && !path.startsWith(`${base}/`) && !path.startsWith("/.well-known/") ? `${base}${path}` : path, "publicPath");
119
+ const login = ownerLogin({
120
+ issuer,
121
+ resource,
122
+ file: tokenFile,
123
+ appName,
124
+ onCode: /* @__PURE__ */ __name((code, expires) => {
125
+ lock?.update({ loginCode: code, loginCodeExpiresAt: expires.toISOString() });
126
+ onCode(code, expires);
127
+ }, "onCode"),
128
+ ...now ? { now } : {}
129
+ });
130
+ const insecure = issuer.protocol === "http:" && LOCAL.includes(issuer.hostname);
131
+ const mcp = createMcpHandler(build, { legacy: "reject", ...onError ? { onerror: onError } : {} });
132
+ const legacy = legacySessions(build, now ?? Date.now);
133
+ const bearer = requireBearerAuth({
134
+ verifier: login.verifier,
135
+ resourceMetadataUrl: getOAuthProtectedResourceMetadataUrl(resource)
136
+ });
137
+ const activity = activityRecorder(httpActivityFile(tokenFile), now);
138
+ const allowedHosts = [.../* @__PURE__ */ new Set([publicUrl.hostname, ...LOCAL])];
139
+ const allowedOrigins = [publicUrl.origin];
140
+ const listening = await listen(async (request) => {
141
+ const refused = hostHeaderValidationResponse(request, allowedHosts);
142
+ if (refused)
143
+ return refused;
144
+ const path = publicPath(new URL(request.url).pathname);
145
+ const discovery = oauthMetadataResponse(metadataRequest(request, path, base), {
146
+ oauthMetadata: login.metadata,
147
+ resourceServerUrl: resource,
148
+ resourceName: appName,
149
+ ...insecure ? { dangerouslyAllowInsecureIssuerUrl: true } : {}
150
+ });
151
+ if (discovery)
152
+ return discovery;
153
+ if (Number(request.headers.get("content-length") ?? 0) > MAX_LOGIN_BODY && path !== mcpPath)
154
+ return new Response("Request too large", { status: 413 });
155
+ const origin = request.headers.get("origin");
156
+ if (origin && !allowedOrigins.includes(origin))
157
+ return new Response("Origin not allowed", { status: 403 });
158
+ const answered = await login.handle(request, path);
159
+ if (answered)
160
+ return answered;
161
+ if (path !== mcpPath)
162
+ return new Response("Not found", { status: 404 });
163
+ const auth = await bearer(request);
164
+ if (auth instanceof Response)
165
+ return auth;
166
+ activity.record(auth.clientId, await toolsIn(request));
167
+ return await isLegacyRequest(request) ? legacy.handle(request, auth) : mcp.fetch(request, { authInfo: auth });
168
+ }, { host: "127.0.0.1", port }).catch((error) => {
169
+ login.close();
170
+ lock?.release();
171
+ throw error;
172
+ });
173
+ lock?.update({ listeningAt: (/* @__PURE__ */ new Date()).toISOString() });
174
+ return {
175
+ url: listening.url,
176
+ close: /* @__PURE__ */ __name(async () => {
177
+ login.close();
178
+ activity.flush();
179
+ try {
180
+ await listening.close();
181
+ await legacy.close();
182
+ await mcp.close();
183
+ } finally {
184
+ lock?.release();
185
+ }
186
+ }, "close")
187
+ };
188
+ }, "serveOverHttp");
189
+
190
+ export {
191
+ MCP_PATH,
192
+ serveOverHttp
193
+ };