swallowkit 1.0.0-beta.55 → 1.0.0-beta.56

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 (135) hide show
  1. package/dist/cli/commands/add-auth.d.ts.map +1 -1
  2. package/dist/cli/commands/add-auth.js +154 -157
  3. package/dist/cli/commands/add-auth.js.map +1 -1
  4. package/dist/cli/commands/init.d.ts +5 -0
  5. package/dist/cli/commands/init.d.ts.map +1 -1
  6. package/dist/cli/commands/init.js +178 -25
  7. package/dist/cli/commands/init.js.map +1 -1
  8. package/dist/cli/commands/scaffold.d.ts +7 -2
  9. package/dist/cli/commands/scaffold.d.ts.map +1 -1
  10. package/dist/cli/commands/scaffold.js +111 -123
  11. package/dist/cli/commands/scaffold.js.map +1 -1
  12. package/dist/cli/index.d.ts.map +1 -1
  13. package/dist/cli/index.js +127 -2
  14. package/dist/cli/index.js.map +1 -1
  15. package/dist/core/config.d.ts +1 -1
  16. package/dist/core/config.d.ts.map +1 -1
  17. package/dist/core/config.js +8 -4
  18. package/dist/core/config.js.map +1 -1
  19. package/dist/core/operations/auth-operations.d.ts +57 -0
  20. package/dist/core/operations/auth-operations.d.ts.map +1 -0
  21. package/dist/core/operations/auth-operations.js +269 -0
  22. package/dist/core/operations/auth-operations.js.map +1 -0
  23. package/dist/core/operations/create-model.d.ts.map +1 -1
  24. package/dist/core/operations/create-model.js +23 -13
  25. package/dist/core/operations/create-model.js.map +1 -1
  26. package/dist/core/operations/file-session.d.ts +53 -0
  27. package/dist/core/operations/file-session.d.ts.map +1 -0
  28. package/dist/core/operations/file-session.js +195 -0
  29. package/dist/core/operations/file-session.js.map +1 -0
  30. package/dist/core/operations/provision-operations.d.ts +52 -0
  31. package/dist/core/operations/provision-operations.d.ts.map +1 -0
  32. package/dist/core/operations/provision-operations.js +211 -0
  33. package/dist/core/operations/provision-operations.js.map +1 -0
  34. package/dist/core/operations/runtime.d.ts +5 -0
  35. package/dist/core/operations/runtime.d.ts.map +1 -1
  36. package/dist/core/operations/runtime.js +23 -0
  37. package/dist/core/operations/runtime.js.map +1 -1
  38. package/dist/core/operations/scaffold-apply.d.ts +21 -0
  39. package/dist/core/operations/scaffold-apply.d.ts.map +1 -0
  40. package/dist/core/operations/scaffold-apply.js +57 -0
  41. package/dist/core/operations/scaffold-apply.js.map +1 -0
  42. package/dist/core/operations/scaffold-machine.d.ts.map +1 -1
  43. package/dist/core/operations/scaffold-machine.js +1 -13
  44. package/dist/core/operations/scaffold-machine.js.map +1 -1
  45. package/dist/core/operations/scaffold-plan.d.ts +43 -0
  46. package/dist/core/operations/scaffold-plan.d.ts.map +1 -0
  47. package/dist/core/operations/scaffold-plan.js +195 -0
  48. package/dist/core/operations/scaffold-plan.js.map +1 -0
  49. package/dist/core/project/artifacts.d.ts +58 -0
  50. package/dist/core/project/artifacts.d.ts.map +1 -0
  51. package/dist/core/project/artifacts.js +179 -0
  52. package/dist/core/project/artifacts.js.map +1 -0
  53. package/dist/core/project/boundaries.d.ts +50 -0
  54. package/dist/core/project/boundaries.d.ts.map +1 -0
  55. package/dist/core/project/boundaries.js +117 -0
  56. package/dist/core/project/boundaries.js.map +1 -0
  57. package/dist/core/project/drift.d.ts +29 -0
  58. package/dist/core/project/drift.d.ts.map +1 -0
  59. package/dist/core/project/drift.js +188 -0
  60. package/dist/core/project/drift.js.map +1 -0
  61. package/dist/core/project/infra.d.ts +49 -0
  62. package/dist/core/project/infra.d.ts.map +1 -0
  63. package/dist/core/project/infra.js +167 -0
  64. package/dist/core/project/infra.js.map +1 -0
  65. package/dist/core/project/state.d.ts +15 -0
  66. package/dist/core/project/state.d.ts.map +1 -0
  67. package/dist/core/project/state.js +106 -0
  68. package/dist/core/project/state.js.map +1 -0
  69. package/dist/core/project/workflows.d.ts +43 -0
  70. package/dist/core/project/workflows.d.ts.map +1 -0
  71. package/dist/core/project/workflows.js +255 -0
  72. package/dist/core/project/workflows.js.map +1 -0
  73. package/dist/core/scaffold/auth-generator.d.ts.map +1 -1
  74. package/dist/core/scaffold/auth-generator.js +24 -27
  75. package/dist/core/scaffold/auth-generator.js.map +1 -1
  76. package/dist/core/scaffold/functions-generator.js +9 -9
  77. package/dist/core/scaffold/nextjs-generator.js +6 -6
  78. package/dist/core/scaffold/ui-generator.js +19 -19
  79. package/dist/core/scaffold/ui-generator.js.map +1 -1
  80. package/dist/core/verify/index.d.ts +62 -0
  81. package/dist/core/verify/index.d.ts.map +1 -0
  82. package/dist/core/verify/index.js +343 -0
  83. package/dist/core/verify/index.js.map +1 -0
  84. package/dist/machine/contracts.d.ts +8 -0
  85. package/dist/machine/contracts.d.ts.map +1 -1
  86. package/dist/machine/errors.d.ts +4 -1
  87. package/dist/machine/errors.d.ts.map +1 -1
  88. package/dist/machine/errors.js +9 -1
  89. package/dist/machine/errors.js.map +1 -1
  90. package/dist/machine/index.d.ts.map +1 -1
  91. package/dist/machine/index.js +350 -16
  92. package/dist/machine/index.js.map +1 -1
  93. package/dist/mcp/index.d.ts.map +1 -1
  94. package/dist/mcp/index.js +202 -1
  95. package/dist/mcp/index.js.map +1 -1
  96. package/dist/types/index.d.ts +14 -0
  97. package/dist/types/index.d.ts.map +1 -1
  98. package/package.json +1 -1
  99. package/src/__tests__/__snapshots__/functions-generator.test.ts.snap +17 -17
  100. package/src/__tests__/__snapshots__/nextjs-generator.test.ts.snap +6 -6
  101. package/src/__tests__/__snapshots__/ui-generator.test.ts.snap +11 -11
  102. package/src/__tests__/agent-loop-phase34.test.ts +449 -0
  103. package/src/__tests__/file-session.test.ts +98 -0
  104. package/src/__tests__/init.test.ts +50 -0
  105. package/src/__tests__/mcp.test.ts +113 -5
  106. package/src/__tests__/plan-apply.test.ts +294 -0
  107. package/src/cli/commands/add-auth.ts +164 -164
  108. package/src/cli/commands/init.ts +186 -24
  109. package/src/cli/commands/scaffold.ts +128 -129
  110. package/src/cli/index.ts +148 -2
  111. package/src/core/config.ts +5 -4
  112. package/src/core/operations/auth-operations.ts +353 -0
  113. package/src/core/operations/create-model.ts +25 -13
  114. package/src/core/operations/file-session.ts +210 -0
  115. package/src/core/operations/provision-operations.ts +297 -0
  116. package/src/core/operations/runtime.ts +23 -0
  117. package/src/core/operations/scaffold-apply.ts +106 -0
  118. package/src/core/operations/scaffold-machine.ts +2 -16
  119. package/src/core/operations/scaffold-plan.ts +224 -0
  120. package/src/core/project/artifacts.ts +205 -0
  121. package/src/core/project/boundaries.ts +170 -0
  122. package/src/core/project/drift.ts +202 -0
  123. package/src/core/project/infra.ts +196 -0
  124. package/src/core/project/state.ts +77 -0
  125. package/src/core/project/workflows.ts +249 -0
  126. package/src/core/scaffold/auth-generator.ts +24 -27
  127. package/src/core/scaffold/functions-generator.ts +9 -9
  128. package/src/core/scaffold/nextjs-generator.ts +6 -6
  129. package/src/core/scaffold/ui-generator.ts +19 -19
  130. package/src/core/verify/index.ts +392 -0
  131. package/src/machine/contracts.ts +16 -0
  132. package/src/machine/errors.ts +12 -1
  133. package/src/machine/index.ts +444 -15
  134. package/src/mcp/index.ts +198 -2
  135. package/src/types/index.ts +17 -0
package/src/mcp/index.ts CHANGED
@@ -4,12 +4,14 @@ import * as path from "path";
4
4
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
5
5
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
6
6
  import * as z from "zod/v4";
7
- import type { MachineResponse } from "../machine/contracts";
7
+ import type { MachineNextAction, MachineOperationStatus, MachineResponse } from "../machine/contracts";
8
8
  import { getSwallowKitVersion } from "../version";
9
9
 
10
10
  interface MachineSuccessPayload<TData> {
11
11
  ok: true;
12
12
  command: string;
13
+ status?: MachineOperationStatus;
14
+ nextActions?: MachineNextAction[];
13
15
  data: TData;
14
16
  }
15
17
 
@@ -59,12 +61,26 @@ async function executeMachineCommand<TData>(
59
61
  }
60
62
 
61
63
  if (!parsed.ok) {
62
- throw new Error(parsed.error.message);
64
+ const detailsSuffix =
65
+ parsed.error.details !== undefined ? `\ndetails: ${JSON.stringify(parsed.error.details)}` : "";
66
+ const statusSuffix = parsed.status ? ` (status: ${parsed.status})` : "";
67
+ throw new Error(`[${parsed.error.code}] ${parsed.error.message}${statusSuffix}${detailsSuffix}`);
63
68
  }
64
69
 
65
70
  return parsed;
66
71
  }
67
72
 
73
+ function withOperationStatus<TData>(response: MachineSuccessPayload<TData>): Record<string, unknown> {
74
+ const data = response.data && typeof response.data === "object"
75
+ ? (response.data as Record<string, unknown>)
76
+ : { data: response.data };
77
+ return {
78
+ status: response.status ?? "complete",
79
+ ...(response.nextActions && response.nextActions.length > 0 ? { nextActions: response.nextActions } : {}),
80
+ ...data,
81
+ };
82
+ }
83
+
68
84
  function jsonTextContent(value: unknown): { content: Array<{ type: "text"; text: string }> } {
69
85
  return {
70
86
  content: [
@@ -170,6 +186,186 @@ export function buildSwallowKitToolDefinitions(
170
186
  return jsonTextContent(response.data);
171
187
  },
172
188
  },
189
+ {
190
+ name: "swallowkit_plan_scaffold",
191
+ description: "Compute the scaffold change plan (files to create/update/overwrite, conflicts, warnings) without writing any files. Returns a planId usable with swallowkit_apply_scaffold.",
192
+ inputSchema: z.object({
193
+ model: z.string(),
194
+ functionsDir: z.string().optional(),
195
+ apiDir: z.string().optional(),
196
+ apiOnly: z.boolean().optional(),
197
+ }),
198
+ handler: async ({ model, functionsDir, apiDir, apiOnly }: { model: string; functionsDir?: string; apiDir?: string; apiOnly?: boolean }) => {
199
+ const args = ["plan", "scaffold", model];
200
+ if (functionsDir) args.push("--functions-dir", functionsDir);
201
+ if (apiDir) args.push("--api-dir", apiDir);
202
+ if (apiOnly) args.push("--api-only");
203
+
204
+ const response = await executeMachineCommand(args, runMachineCli);
205
+ return jsonTextContent(withOperationStatus(response));
206
+ },
207
+ },
208
+ {
209
+ name: "swallowkit_apply_scaffold",
210
+ description: "Apply scaffold changes. Rejects stale plans (files changed after planning) and requires approve=true when user-modified files would be overwritten.",
211
+ inputSchema: z.object({
212
+ model: z.string().optional(),
213
+ planId: z.string().optional(),
214
+ approve: z.boolean().optional(),
215
+ functionsDir: z.string().optional(),
216
+ apiDir: z.string().optional(),
217
+ apiOnly: z.boolean().optional(),
218
+ }),
219
+ handler: async ({ model, planId, approve, functionsDir, apiDir, apiOnly }: { model?: string; planId?: string; approve?: boolean; functionsDir?: string; apiDir?: string; apiOnly?: boolean }) => {
220
+ const args = ["apply", "scaffold"];
221
+ if (model) args.push(model);
222
+ if (planId) args.push("--plan", planId);
223
+ if (approve) args.push("--approve");
224
+ if (functionsDir) args.push("--functions-dir", functionsDir);
225
+ if (apiDir) args.push("--api-dir", apiDir);
226
+ if (apiOnly) args.push("--api-only");
227
+
228
+ const response = await executeMachineCommand(args, runMachineCli);
229
+ return jsonTextContent(withOperationStatus(response));
230
+ },
231
+ },
232
+ {
233
+ name: "swallowkit_inspect_artifacts",
234
+ description: "Return the generated-artifact ledger with ownership, source model, and modified/missing flags.",
235
+ inputSchema: z.object({}),
236
+ handler: async () => {
237
+ const response = await executeMachineCommand(["inspect", "artifacts"], runMachineCli);
238
+ return jsonTextContent(withSwallowKitMetadata(response.data));
239
+ },
240
+ },
241
+ {
242
+ name: "swallowkit_inspect_drift",
243
+ description: "Detect drift between generated artifacts and the current project state (schema changes, manual edits, missing files, manifest mismatch). Each finding includes a repairAction.",
244
+ inputSchema: z.object({}),
245
+ handler: async () => {
246
+ const response = await executeMachineCommand(["inspect", "drift"], runMachineCli);
247
+ return jsonTextContent(withOperationStatus(response));
248
+ },
249
+ },
250
+ {
251
+ name: "swallowkit_verify_project",
252
+ description: "Run verification checks (structure, drift, typecheck by default; build, lint, test and custom checks from swallowkit.config verify.checks are also available) and return machine-readable evidence. summary.done=true means the project passed all checks.",
253
+ inputSchema: z.object({
254
+ checks: z.array(z.string()).optional(),
255
+ }),
256
+ handler: async ({ checks }: { checks?: string[] }) => {
257
+ const args = ["verify", "project"];
258
+ if (checks && checks.length > 0) {
259
+ args.push("--checks", checks.join(","));
260
+ }
261
+
262
+ const response = await executeMachineCommand(args, runMachineCli);
263
+ return jsonTextContent(withOperationStatus(response));
264
+ },
265
+ },
266
+ {
267
+ name: "swallowkit_explain_failure",
268
+ description: "Explain failures from the most recent swallowkit_verify_project run, including evidence and suggested actions.",
269
+ inputSchema: z.object({
270
+ check: z.string().optional(),
271
+ }),
272
+ handler: async ({ check }: { check?: string }) => {
273
+ const args = ["explain", "failure"];
274
+ if (check) {
275
+ args.push("--check", check);
276
+ }
277
+
278
+ const response = await executeMachineCommand(args, runMachineCli);
279
+ return jsonTextContent(withOperationStatus(response));
280
+ },
281
+ },
282
+ {
283
+ name: "swallowkit_inspect_boundaries",
284
+ description: "Return the responsibility boundary contract: which paths are deterministic (regenerate via plan/apply), which are AI/human-authored (free edit), and which are shared extension points.",
285
+ inputSchema: z.object({}),
286
+ handler: async () => {
287
+ const response = await executeMachineCommand(["inspect", "boundaries"], runMachineCli);
288
+ return jsonTextContent(withSwallowKitMetadata(response.data));
289
+ },
290
+ },
291
+ {
292
+ name: "swallowkit_plan_auth",
293
+ description: "Compute the add-auth change plan (files to create/update/overwrite, conflicts, warnings) without writing any files. Returns a planId usable with swallowkit_apply_auth.",
294
+ inputSchema: z.object({
295
+ provider: z.enum(["custom-jwt", "swa", "external-token", "none"]),
296
+ scheme: z.string().optional(),
297
+ }),
298
+ handler: async ({ provider, scheme }: { provider: string; scheme?: string }) => {
299
+ const args = ["plan", "auth", "--provider", provider];
300
+ if (scheme) args.push("--scheme", scheme);
301
+
302
+ const response = await executeMachineCommand(args, runMachineCli);
303
+ return jsonTextContent(withOperationStatus(response));
304
+ },
305
+ },
306
+ {
307
+ name: "swallowkit_apply_auth",
308
+ description: "Apply add-auth changes. Rejects stale plans and requires approve=true when user-modified files would be overwritten.",
309
+ inputSchema: z.object({
310
+ provider: z.enum(["custom-jwt", "swa", "external-token", "none"]).optional(),
311
+ scheme: z.string().optional(),
312
+ planId: z.string().optional(),
313
+ approve: z.boolean().optional(),
314
+ }),
315
+ handler: async ({ provider, scheme, planId, approve }: { provider?: string; scheme?: string; planId?: string; approve?: boolean }) => {
316
+ const args = ["apply", "auth"];
317
+ if (planId) args.push("--plan", planId);
318
+ if (provider) args.push("--provider", provider);
319
+ if (scheme) args.push("--scheme", scheme);
320
+ if (approve) args.push("--approve");
321
+
322
+ const response = await executeMachineCommand(args, runMachineCli);
323
+ return jsonTextContent(withOperationStatus(response));
324
+ },
325
+ },
326
+ {
327
+ name: "swallowkit_inspect_infra",
328
+ description: "Inspect Bicep infrastructure assets deterministically (params, modules, outputs, container wiring). Does not call Azure.",
329
+ inputSchema: z.object({}),
330
+ handler: async () => {
331
+ const response = await executeMachineCommand(["inspect", "infra"], runMachineCli);
332
+ return jsonTextContent(withSwallowKitMetadata(response.data));
333
+ },
334
+ },
335
+ {
336
+ name: "swallowkit_plan_provision",
337
+ description: "Preflight Azure provisioning locally (Bicep analysis, az CLI availability, command preview). Never deploys. Set whatIf=true to run az what-if (requires az login). The returned plan always requires human approval.",
338
+ inputSchema: z.object({
339
+ resourceGroup: z.string(),
340
+ location: z.string(),
341
+ swaLocation: z.string(),
342
+ subscription: z.string().optional(),
343
+ whatIf: z.boolean().optional(),
344
+ }),
345
+ handler: async ({ resourceGroup, location, swaLocation, subscription, whatIf }: { resourceGroup: string; location: string; swaLocation: string; subscription?: string; whatIf?: boolean }) => {
346
+ const args = ["plan", "provision", "--resource-group", resourceGroup, "--location", location, "--swa-location", swaLocation];
347
+ if (subscription) args.push("--subscription", subscription);
348
+ if (whatIf) args.push("--what-if");
349
+
350
+ const response = await executeMachineCommand(args, runMachineCli);
351
+ return jsonTextContent(withOperationStatus(response));
352
+ },
353
+ },
354
+ {
355
+ name: "swallowkit_apply_provision",
356
+ description: "Apply an approved provisioning plan. Creates billable Azure resources; approve=true is always required and must reflect explicit human consent.",
357
+ inputSchema: z.object({
358
+ planId: z.string(),
359
+ approve: z.boolean().optional(),
360
+ }),
361
+ handler: async ({ planId, approve }: { planId: string; approve?: boolean }) => {
362
+ const args = ["apply", "provision", "--plan", planId];
363
+ if (approve) args.push("--approve");
364
+
365
+ const response = await executeMachineCommand(args, runMachineCli);
366
+ return jsonTextContent(withOperationStatus(response));
367
+ },
368
+ },
173
369
  ];
174
370
  }
175
371
 
@@ -162,4 +162,21 @@ export interface SwallowKitConfig {
162
162
  };
163
163
  connectors?: Record<string, ConnectorDefinition>;
164
164
  auth?: AuthConfig;
165
+ verify?: VerifySettings;
166
+ }
167
+
168
+ // verify コマンドのプロジェクト固有設定
169
+ export interface CustomVerifyCheck {
170
+ /** チェック ID (built-in と重複不可)。 */
171
+ id: string;
172
+ title?: string;
173
+ /** プロジェクトルートで実行するシェルコマンド。exit 0 = pass。 */
174
+ command: string;
175
+ /** タイムアウト (ms)。既定 5 分。 */
176
+ timeoutMs?: number;
177
+ }
178
+
179
+ export interface VerifySettings {
180
+ /** プロジェクト固有の追加チェック。デフォルト実行セットに含まれる。 */
181
+ checks?: CustomVerifyCheck[];
165
182
  }