@wundero/bts 3.44.1-preview-20260929-07a3082

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.
package/dist/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+ export {}
package/dist/cli.mjs ADDED
@@ -0,0 +1,305 @@
1
+ #!/usr/bin/env node
2
+ import { b as types_exports, g as getSchemaResult, i as SchemaNameSchema, k as setProcessMode, l as create, s as add, u as createBtsCli, x as getLatestCLIVersion } from "./src-Bs-QhN50.mjs";
3
+ import { lineByLineConsoleLogger } from "trpc-cli";
4
+ import z from "zod";
5
+ import { McpServer } from "@modelcontextprotocol/server";
6
+ import { serveStdio } from "@modelcontextprotocol/server/stdio";
7
+ //#region src/mcp.ts
8
+ const ToolResponseSchema = z.object({
9
+ ok: z.boolean(),
10
+ data: z.any().optional(),
11
+ error: z.string().optional()
12
+ });
13
+ const SchemaToolInputSchema = z.object({ name: SchemaNameSchema.optional().describe("Schema name to inspect. Defaults to all.") });
14
+ const McpCreateProjectInputSchema = types_exports.CreateInputSchema.safeExtend({
15
+ projectName: z.string().describe("Project name or relative path"),
16
+ frontend: z.array(types_exports.FrontendSchema).describe("Explicit frontend app surfaces. Do not use native frontends as styling options."),
17
+ backend: types_exports.BackendSchema.describe("Explicit backend framework"),
18
+ runtime: types_exports.RuntimeSchema.describe("Explicit runtime environment"),
19
+ database: types_exports.DatabaseSchema.describe("Explicit database choice"),
20
+ orm: types_exports.ORMSchema.describe("Explicit ORM choice"),
21
+ api: types_exports.APISchema.describe("Explicit API layer"),
22
+ auth: types_exports.AuthSchema.describe("Explicit authentication provider"),
23
+ payments: types_exports.PaymentsSchema.describe("Explicit payments provider"),
24
+ emailRenderer: types_exports.EmailRendererSchema.describe("Explicit email renderer"),
25
+ emailDeploy: types_exports.EmailDeploySchema.describe("Explicit email deployment choice"),
26
+ addons: z.array(types_exports.AddonsSchema).describe("Explicit addon list. Use [] when no addons are needed."),
27
+ examples: z.array(types_exports.ExamplesSchema).describe("Explicit example list. Use [] when no examples are needed."),
28
+ git: z.boolean().describe("Whether to initialize a git repository"),
29
+ packageManager: types_exports.PackageManagerSchema.describe("Explicit package manager"),
30
+ install: z.boolean().describe("Whether to install dependencies"),
31
+ dbSetup: types_exports.DatabaseSetupSchema.describe("Explicit database setup/provisioning choice"),
32
+ webDeploy: types_exports.WebDeploySchema.describe("Explicit web deployment choice"),
33
+ serverDeploy: types_exports.ServerDeploySchema.describe("Explicit server deployment choice"),
34
+ addonOptions: types_exports.AddonOptionsSchema.optional(),
35
+ dbSetupOptions: types_exports.DbSetupOptionsSchema.optional(),
36
+ shadcn: types_exports.ShadcnConfigSchema.optional().describe("shadcn theme configuration. Set preset to a preset code, named preset, or preset URL."),
37
+ directoryConflict: types_exports.DirectoryConflictSchema.optional()
38
+ }).describe("Explicit Better T Stack project configuration for MCP use. Provide the full stack config instead of relying on inferred defaults.");
39
+ function formatToolSuccess(data) {
40
+ return {
41
+ content: [{
42
+ type: "text",
43
+ text: JSON.stringify(data, null, 2)
44
+ }],
45
+ structuredContent: {
46
+ ok: true,
47
+ data
48
+ }
49
+ };
50
+ }
51
+ function formatToolError(cause) {
52
+ const message = cause instanceof Error ? cause.message : String(cause);
53
+ return {
54
+ content: [{
55
+ type: "text",
56
+ text: message
57
+ }],
58
+ structuredContent: {
59
+ ok: false,
60
+ error: message
61
+ },
62
+ isError: true
63
+ };
64
+ }
65
+ function getProjectToolAnnotations() {
66
+ return {
67
+ destructiveHint: true,
68
+ idempotentHint: false,
69
+ openWorldHint: true
70
+ };
71
+ }
72
+ function getMcpInstallTimeoutMessage(packageManager) {
73
+ return [
74
+ "MCP project creation requires `install: false`.",
75
+ "Dependency installation can exceed common MCP client request timeouts and cause the connection to close before the tool returns.",
76
+ `Scaffold the project first, then run \`${packageManager} install\` in the generated project directory from a terminal.`
77
+ ].join(" ");
78
+ }
79
+ function getStackGuidance() {
80
+ return {
81
+ workflow: [
82
+ "Call bts_get_schema or bts_get_stack_guidance before constructing a config if the request is ambiguous.",
83
+ "For project creation, build a full explicit config before calling bts_plan_project.",
84
+ "Always call bts_plan_project before bts_create_project.",
85
+ "Only call bts_create_project after the plan succeeds and matches the user's intent.",
86
+ "Use bts_plan_addons before bts_add_addons when adding addons or scaffolding a workspace package in an existing project."
87
+ ],
88
+ createContract: {
89
+ requiresExplicitFields: [
90
+ "projectName",
91
+ "frontend",
92
+ "backend",
93
+ "runtime",
94
+ "database",
95
+ "orm",
96
+ "api",
97
+ "auth",
98
+ "payments",
99
+ "emailRenderer",
100
+ "emailDeploy",
101
+ "addons",
102
+ "examples",
103
+ "git",
104
+ "packageManager",
105
+ "install",
106
+ "dbSetup",
107
+ "webDeploy",
108
+ "serverDeploy"
109
+ ],
110
+ optionalFields: [
111
+ "addonOptions",
112
+ "dbSetupOptions",
113
+ "shadcn",
114
+ "directoryConflict"
115
+ ],
116
+ rule: "Do not call bts_plan_project or bts_create_project with a partial payload. MCP project creation requires the full explicit stack config."
117
+ },
118
+ fieldNotes: {
119
+ frontend: "frontend is for app surfaces only. Choose explicit app targets such as next, react-router, tanstack-router, native-bare, native-uniwind, or native-unistyles.",
120
+ addons: "addons must be an explicit array. Use [] when no addons are requested.",
121
+ examples: "examples must be an explicit array. Use [] when no examples are requested.",
122
+ dbSetup: "dbSetup is always required. Use 'none' when no managed database provisioning is requested.",
123
+ webDeploy: "webDeploy is always required. Use 'none' when no web deployment target is requested.",
124
+ serverDeploy: "serverDeploy is always required. Use 'none' when no server deployment target is requested.",
125
+ emailRenderer: "emailRenderer is always required. Use 'none' when no email rendering setup is requested.",
126
+ emailDeploy: "emailDeploy is always required. Use 'none' when no email deployment target is requested.",
127
+ packageManager: "packageManager is always required because installation and reproducible commands depend on it.",
128
+ install: "install is always required. For MCP project creation, prefer false because many clients enforce request timeouts around long-running dependency installs.",
129
+ git: "git is always required. Set it to true or false explicitly instead of relying on defaults.",
130
+ shadcn: "shadcn is optional and only applies to React web frontends. When provided it must include a preset (code, named preset, or preset URL); base defaults to baseui."
131
+ },
132
+ ambiguityRules: [
133
+ "If the user request leaves major stack choices unspecified, stop and resolve them before calling bts_plan_project.",
134
+ "Do not infer extra app surfaces, addons, examples, or provisioning choices from a template name or styling preference.",
135
+ "If the user wants the smallest valid stack, still send the full config with explicit 'none', [] , true, or false values where appropriate.",
136
+ "For MCP execution, scaffold with install=false and let the user or agent run dependency installation separately from a terminal session."
137
+ ]
138
+ };
139
+ }
140
+ function createBtsMcpServer() {
141
+ setProcessMode("mcp");
142
+ const server = new McpServer({
143
+ name: "create-better-t-stack",
144
+ version: getLatestCLIVersion()
145
+ }, { cacheHints: { "tools/list": {
146
+ ttlMs: 36e5,
147
+ cacheScope: "public"
148
+ } } });
149
+ server.registerTool("bts_get_stack_guidance", {
150
+ title: "Get Better T Stack MCP Guidance",
151
+ description: "Read MCP-specific guidance for choosing valid Better T Stack configurations. Use this before planning when user intent is ambiguous. This explains the full explicit config required by MCP project creation, plus important field semantics and ambiguity rules.",
152
+ outputSchema: ToolResponseSchema,
153
+ annotations: {
154
+ title: "Get Better T Stack MCP Guidance",
155
+ readOnlyHint: true,
156
+ destructiveHint: false,
157
+ idempotentHint: true,
158
+ openWorldHint: false
159
+ }
160
+ }, async () => {
161
+ try {
162
+ return formatToolSuccess(getStackGuidance());
163
+ } catch (error) {
164
+ return formatToolError(error);
165
+ }
166
+ });
167
+ server.registerTool("bts_get_schema", {
168
+ title: "Get Better T Stack Schemas",
169
+ description: "Inspect Better T Stack CLI and input schemas so agents can plan valid create/add requests. Use this together with bts_get_stack_guidance before creating a project if any part of the request is ambiguous.",
170
+ inputSchema: SchemaToolInputSchema,
171
+ outputSchema: ToolResponseSchema,
172
+ annotations: {
173
+ title: "Get Better T Stack Schemas",
174
+ readOnlyHint: true,
175
+ destructiveHint: false,
176
+ idempotentHint: true,
177
+ openWorldHint: false
178
+ }
179
+ }, async ({ name }) => {
180
+ try {
181
+ return formatToolSuccess(getSchemaResult(name ?? "all"));
182
+ } catch (error) {
183
+ return formatToolError(error);
184
+ }
185
+ });
186
+ server.registerTool("bts_plan_project", {
187
+ title: "Plan Better T Stack Project",
188
+ description: "Validate and preview a Better T Stack project creation without writing files or provisioning resources. Always use this before bts_create_project. This tool requires an explicit full stack config rather than a partial payload with inferred defaults.",
189
+ inputSchema: McpCreateProjectInputSchema,
190
+ outputSchema: ToolResponseSchema,
191
+ annotations: {
192
+ title: "Plan Better T Stack Project",
193
+ readOnlyHint: true,
194
+ destructiveHint: false,
195
+ idempotentHint: true,
196
+ openWorldHint: false
197
+ }
198
+ }, async (input) => {
199
+ try {
200
+ const result = await create(input.projectName, {
201
+ ...input,
202
+ dryRun: true,
203
+ disableAnalytics: true
204
+ });
205
+ if (result.isErr()) return formatToolError(result.error);
206
+ return formatToolSuccess(input.install ? {
207
+ ...result.value,
208
+ warnings: [getMcpInstallTimeoutMessage(input.packageManager)],
209
+ recommendedMcpExecution: {
210
+ ...input,
211
+ install: false
212
+ }
213
+ } : result.value);
214
+ } catch (error) {
215
+ return formatToolError(error);
216
+ }
217
+ });
218
+ server.registerTool("bts_create_project", {
219
+ title: "Create Better T Stack Project",
220
+ description: "Create a Better T Stack project on disk using the same silent programmatic flow as the CLI JSON API. Call this only after bts_plan_project succeeds and the plan clearly matches the user's intent. This tool requires an explicit full stack config.",
221
+ inputSchema: McpCreateProjectInputSchema,
222
+ outputSchema: ToolResponseSchema,
223
+ annotations: {
224
+ title: "Create Better T Stack Project",
225
+ ...getProjectToolAnnotations()
226
+ }
227
+ }, async (input) => {
228
+ try {
229
+ if (input.install) return formatToolError(getMcpInstallTimeoutMessage(input.packageManager));
230
+ const result = await create(input.projectName, {
231
+ ...input,
232
+ disableAnalytics: input.disableAnalytics ?? false
233
+ });
234
+ if (result.isErr()) return formatToolError(result.error);
235
+ return formatToolSuccess(result.value);
236
+ } catch (error) {
237
+ return formatToolError(error);
238
+ }
239
+ });
240
+ server.registerTool("bts_plan_addons", {
241
+ title: "Plan Better T Stack Project Additions",
242
+ description: "Validate and preview addon installation or workspace package scaffolding for an existing Better T Stack project without writing files. Always use this before bts_add_addons.",
243
+ inputSchema: types_exports.AddInputSchema,
244
+ outputSchema: ToolResponseSchema,
245
+ annotations: {
246
+ title: "Plan Better T Stack Project Additions",
247
+ readOnlyHint: true,
248
+ destructiveHint: false,
249
+ idempotentHint: true,
250
+ openWorldHint: false
251
+ }
252
+ }, async (input) => {
253
+ try {
254
+ const result = await add({
255
+ ...input,
256
+ dryRun: true
257
+ });
258
+ if (!result?.success) return formatToolError(result?.error ?? "Failed to plan project additions");
259
+ return formatToolSuccess(result);
260
+ } catch (error) {
261
+ return formatToolError(error);
262
+ }
263
+ });
264
+ server.registerTool("bts_add_addons", {
265
+ title: "Apply Better T Stack Project Additions",
266
+ description: "Install addons or scaffold a workspace package in an existing Better T Stack project using the same silent flow as add-json. Call this only after bts_plan_addons succeeds and the planned changes match the user's intent.",
267
+ inputSchema: types_exports.AddInputSchema,
268
+ outputSchema: ToolResponseSchema,
269
+ annotations: {
270
+ title: "Apply Better T Stack Project Additions",
271
+ destructiveHint: true,
272
+ idempotentHint: false,
273
+ openWorldHint: true
274
+ }
275
+ }, async (input) => {
276
+ try {
277
+ const result = await add(input);
278
+ if (!result?.success) return formatToolError(result?.error ?? "Failed to update project");
279
+ return formatToolSuccess(result);
280
+ } catch (error) {
281
+ return formatToolError(error);
282
+ }
283
+ });
284
+ return server;
285
+ }
286
+ function startBtsMcpServer() {
287
+ return serveStdio(() => createBtsMcpServer());
288
+ }
289
+ //#endregion
290
+ //#region src/cli.ts
291
+ const [, , command, ...args] = process.argv;
292
+ if (command === "mcp") {
293
+ if (args.includes("--help") || args.includes("-h")) {
294
+ console.log(`Usage: create-better-t-stack mcp
295
+
296
+ Start the Better T Stack MCP server over stdio.
297
+
298
+ This command is intended to be launched by an MCP client, for example:
299
+ create-better-t-stack mcp`);
300
+ process.exit(0);
301
+ }
302
+ await startBtsMcpServer();
303
+ } else await createBtsCli().run({ logger: lineByLineConsoleLogger });
304
+ //#endregion
305
+ export {};