swallowkit 1.0.0-beta.8 → 1.0.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 (272) hide show
  1. package/README.ja.md +87 -181
  2. package/README.md +87 -238
  3. package/dist/__tests__/fixtures.d.ts +12 -0
  4. package/dist/__tests__/fixtures.d.ts.map +1 -1
  5. package/dist/__tests__/fixtures.js +101 -0
  6. package/dist/__tests__/fixtures.js.map +1 -1
  7. package/dist/cli/commands/add-auth.d.ts +15 -0
  8. package/dist/cli/commands/add-auth.d.ts.map +1 -0
  9. package/dist/cli/commands/add-auth.js +790 -0
  10. package/dist/cli/commands/add-auth.js.map +1 -0
  11. package/dist/cli/commands/add-connector.d.ts +20 -0
  12. package/dist/cli/commands/add-connector.d.ts.map +1 -0
  13. package/dist/cli/commands/add-connector.js +164 -0
  14. package/dist/cli/commands/add-connector.js.map +1 -0
  15. package/dist/cli/commands/cosmos-worktree-isolation.d.ts +25 -0
  16. package/dist/cli/commands/cosmos-worktree-isolation.d.ts.map +1 -0
  17. package/dist/cli/commands/cosmos-worktree-isolation.js +124 -0
  18. package/dist/cli/commands/cosmos-worktree-isolation.js.map +1 -0
  19. package/dist/cli/commands/create-model.d.ts +1 -4
  20. package/dist/cli/commands/create-model.d.ts.map +1 -1
  21. package/dist/cli/commands/create-model.js +20 -82
  22. package/dist/cli/commands/create-model.js.map +1 -1
  23. package/dist/cli/commands/dev-seeds.d.ts +27 -0
  24. package/dist/cli/commands/dev-seeds.d.ts.map +1 -1
  25. package/dist/cli/commands/dev-seeds.js +188 -6
  26. package/dist/cli/commands/dev-seeds.js.map +1 -1
  27. package/dist/cli/commands/dev.d.ts +30 -0
  28. package/dist/cli/commands/dev.d.ts.map +1 -1
  29. package/dist/cli/commands/dev.js +495 -129
  30. package/dist/cli/commands/dev.js.map +1 -1
  31. package/dist/cli/commands/init.d.ts +70 -0
  32. package/dist/cli/commands/init.d.ts.map +1 -1
  33. package/dist/cli/commands/init.js +797 -768
  34. package/dist/cli/commands/init.js.map +1 -1
  35. package/dist/cli/commands/scaffold.d.ts +24 -3
  36. package/dist/cli/commands/scaffold.d.ts.map +1 -1
  37. package/dist/cli/commands/scaffold.js +408 -189
  38. package/dist/cli/commands/scaffold.js.map +1 -1
  39. package/dist/cli/index.d.ts +5 -1
  40. package/dist/cli/index.d.ts.map +1 -1
  41. package/dist/cli/index.js +335 -58
  42. package/dist/cli/index.js.map +1 -1
  43. package/dist/core/config.d.ts +13 -3
  44. package/dist/core/config.d.ts.map +1 -1
  45. package/dist/core/config.js +151 -8
  46. package/dist/core/config.js.map +1 -1
  47. package/dist/core/mock/connector-mock-server.d.ts +101 -0
  48. package/dist/core/mock/connector-mock-server.d.ts.map +1 -0
  49. package/dist/core/mock/connector-mock-server.js +480 -0
  50. package/dist/core/mock/connector-mock-server.js.map +1 -0
  51. package/dist/core/mock/zod-mock-generator.d.ts +14 -0
  52. package/dist/core/mock/zod-mock-generator.d.ts.map +1 -0
  53. package/dist/core/mock/zod-mock-generator.js +163 -0
  54. package/dist/core/mock/zod-mock-generator.js.map +1 -0
  55. package/dist/core/operations/auth-operations.d.ts +61 -0
  56. package/dist/core/operations/auth-operations.d.ts.map +1 -0
  57. package/dist/core/operations/auth-operations.js +272 -0
  58. package/dist/core/operations/auth-operations.js.map +1 -0
  59. package/dist/core/operations/create-model.d.ts +15 -0
  60. package/dist/core/operations/create-model.d.ts.map +1 -0
  61. package/dist/core/operations/create-model.js +185 -0
  62. package/dist/core/operations/create-model.js.map +1 -0
  63. package/dist/core/operations/file-session.d.ts +56 -0
  64. package/dist/core/operations/file-session.d.ts.map +1 -0
  65. package/dist/core/operations/file-session.js +203 -0
  66. package/dist/core/operations/file-session.js.map +1 -0
  67. package/dist/core/operations/provision-operations.d.ts +52 -0
  68. package/dist/core/operations/provision-operations.d.ts.map +1 -0
  69. package/dist/core/operations/provision-operations.js +211 -0
  70. package/dist/core/operations/provision-operations.js.map +1 -0
  71. package/dist/core/operations/runtime.d.ts +37 -0
  72. package/dist/core/operations/runtime.d.ts.map +1 -0
  73. package/dist/core/operations/runtime.js +248 -0
  74. package/dist/core/operations/runtime.js.map +1 -0
  75. package/dist/core/operations/scaffold-apply.d.ts +21 -0
  76. package/dist/core/operations/scaffold-apply.d.ts.map +1 -0
  77. package/dist/core/operations/scaffold-apply.js +57 -0
  78. package/dist/core/operations/scaffold-apply.js.map +1 -0
  79. package/dist/core/operations/scaffold-machine.d.ts +16 -0
  80. package/dist/core/operations/scaffold-machine.d.ts.map +1 -0
  81. package/dist/core/operations/scaffold-machine.js +51 -0
  82. package/dist/core/operations/scaffold-machine.js.map +1 -0
  83. package/dist/core/operations/scaffold-plan.d.ts +43 -0
  84. package/dist/core/operations/scaffold-plan.d.ts.map +1 -0
  85. package/dist/core/operations/scaffold-plan.js +187 -0
  86. package/dist/core/operations/scaffold-plan.js.map +1 -0
  87. package/dist/core/project/agent-instructions.d.ts +29 -0
  88. package/dist/core/project/agent-instructions.d.ts.map +1 -0
  89. package/dist/core/project/agent-instructions.js +160 -0
  90. package/dist/core/project/agent-instructions.js.map +1 -0
  91. package/dist/core/project/artifacts.d.ts +58 -0
  92. package/dist/core/project/artifacts.d.ts.map +1 -0
  93. package/dist/core/project/artifacts.js +179 -0
  94. package/dist/core/project/artifacts.js.map +1 -0
  95. package/dist/core/project/boundaries.d.ts +50 -0
  96. package/dist/core/project/boundaries.d.ts.map +1 -0
  97. package/dist/core/project/boundaries.js +117 -0
  98. package/dist/core/project/boundaries.js.map +1 -0
  99. package/dist/core/project/capabilities.d.ts +58 -0
  100. package/dist/core/project/capabilities.d.ts.map +1 -0
  101. package/dist/core/project/capabilities.js +135 -0
  102. package/dist/core/project/capabilities.js.map +1 -0
  103. package/dist/core/project/drift.d.ts +29 -0
  104. package/dist/core/project/drift.d.ts.map +1 -0
  105. package/dist/core/project/drift.js +188 -0
  106. package/dist/core/project/drift.js.map +1 -0
  107. package/dist/core/project/infra.d.ts +49 -0
  108. package/dist/core/project/infra.d.ts.map +1 -0
  109. package/dist/core/project/infra.js +167 -0
  110. package/dist/core/project/infra.js.map +1 -0
  111. package/dist/core/project/manifest.d.ts +92 -0
  112. package/dist/core/project/manifest.d.ts.map +1 -0
  113. package/dist/core/project/manifest.js +321 -0
  114. package/dist/core/project/manifest.js.map +1 -0
  115. package/dist/core/project/state.d.ts +15 -0
  116. package/dist/core/project/state.d.ts.map +1 -0
  117. package/dist/core/project/state.js +106 -0
  118. package/dist/core/project/state.js.map +1 -0
  119. package/dist/core/project/validation.d.ts +20 -0
  120. package/dist/core/project/validation.d.ts.map +1 -0
  121. package/dist/core/project/validation.js +274 -0
  122. package/dist/core/project/validation.js.map +1 -0
  123. package/dist/core/project/workflows.d.ts +43 -0
  124. package/dist/core/project/workflows.d.ts.map +1 -0
  125. package/dist/core/project/workflows.js +299 -0
  126. package/dist/core/project/workflows.js.map +1 -0
  127. package/dist/core/scaffold/auth-generator.d.ts +63 -0
  128. package/dist/core/scaffold/auth-generator.d.ts.map +1 -0
  129. package/dist/core/scaffold/auth-generator.js +1774 -0
  130. package/dist/core/scaffold/auth-generator.js.map +1 -0
  131. package/dist/core/scaffold/connector-functions-generator.d.ts +41 -0
  132. package/dist/core/scaffold/connector-functions-generator.d.ts.map +1 -0
  133. package/dist/core/scaffold/connector-functions-generator.js +1029 -0
  134. package/dist/core/scaffold/connector-functions-generator.js.map +1 -0
  135. package/dist/core/scaffold/functions-generator.d.ts +4 -3
  136. package/dist/core/scaffold/functions-generator.d.ts.map +1 -1
  137. package/dist/core/scaffold/functions-generator.js +405 -134
  138. package/dist/core/scaffold/functions-generator.js.map +1 -1
  139. package/dist/core/scaffold/model-parser.d.ts +20 -0
  140. package/dist/core/scaffold/model-parser.d.ts.map +1 -1
  141. package/dist/core/scaffold/model-parser.js +229 -78
  142. package/dist/core/scaffold/model-parser.js.map +1 -1
  143. package/dist/core/scaffold/native-schema-generator.d.ts +19 -0
  144. package/dist/core/scaffold/native-schema-generator.d.ts.map +1 -0
  145. package/dist/core/scaffold/native-schema-generator.js +753 -0
  146. package/dist/core/scaffold/native-schema-generator.js.map +1 -0
  147. package/dist/core/scaffold/nextjs-generator.d.ts +8 -0
  148. package/dist/core/scaffold/nextjs-generator.d.ts.map +1 -1
  149. package/dist/core/scaffold/nextjs-generator.js +152 -8
  150. package/dist/core/scaffold/nextjs-generator.js.map +1 -1
  151. package/dist/core/scaffold/ui-generator.d.ts +17 -4
  152. package/dist/core/scaffold/ui-generator.d.ts.map +1 -1
  153. package/dist/core/scaffold/ui-generator.js +174 -34
  154. package/dist/core/scaffold/ui-generator.js.map +1 -1
  155. package/dist/core/verify/index.d.ts +69 -0
  156. package/dist/core/verify/index.d.ts.map +1 -0
  157. package/dist/core/verify/index.js +412 -0
  158. package/dist/core/verify/index.js.map +1 -0
  159. package/dist/machine/contracts.d.ts +24 -0
  160. package/dist/machine/contracts.d.ts.map +1 -0
  161. package/dist/machine/contracts.js +3 -0
  162. package/dist/machine/contracts.js.map +1 -0
  163. package/dist/machine/errors.d.ts +14 -0
  164. package/dist/machine/errors.d.ts.map +1 -0
  165. package/dist/machine/errors.js +42 -0
  166. package/dist/machine/errors.js.map +1 -0
  167. package/dist/machine/index.d.ts +3 -0
  168. package/dist/machine/index.d.ts.map +1 -0
  169. package/dist/machine/index.js +566 -0
  170. package/dist/machine/index.js.map +1 -0
  171. package/dist/mcp/index.d.ts +25 -0
  172. package/dist/mcp/index.d.ts.map +1 -0
  173. package/dist/mcp/index.js +425 -0
  174. package/dist/mcp/index.js.map +1 -0
  175. package/dist/types/index.d.ts +105 -0
  176. package/dist/types/index.d.ts.map +1 -1
  177. package/dist/utils/package-manager.d.ts +7 -11
  178. package/dist/utils/package-manager.d.ts.map +1 -1
  179. package/dist/utils/package-manager.js +42 -17
  180. package/dist/utils/package-manager.js.map +1 -1
  181. package/dist/utils/python-uv.d.ts +21 -0
  182. package/dist/utils/python-uv.d.ts.map +1 -0
  183. package/dist/utils/python-uv.js +111 -0
  184. package/dist/utils/python-uv.js.map +1 -0
  185. package/dist/version.d.ts +2 -0
  186. package/dist/version.d.ts.map +1 -0
  187. package/dist/version.js +49 -0
  188. package/dist/version.js.map +1 -0
  189. package/package.json +15 -17
  190. package/src/__tests__/__snapshots__/functions-generator.test.ts.snap +716 -22
  191. package/src/__tests__/__snapshots__/nextjs-generator.test.ts.snap +19 -7
  192. package/src/__tests__/__snapshots__/ui-generator.test.ts.snap +20 -12
  193. package/src/__tests__/agent-instructions.test.ts +237 -0
  194. package/src/__tests__/agent-loop-phase34.test.ts +513 -0
  195. package/src/__tests__/auth.test.ts +770 -0
  196. package/src/__tests__/bff-swa-auth.test.ts +275 -0
  197. package/src/__tests__/config.test.ts +176 -3
  198. package/src/__tests__/connector-functions-generator.test.ts +288 -0
  199. package/src/__tests__/connector-mock-server.test.ts +459 -0
  200. package/src/__tests__/connector-model-bff.test.ts +162 -0
  201. package/src/__tests__/cosmos-worktree-isolation.test.ts +149 -0
  202. package/src/__tests__/dev-seeds.test.ts +124 -0
  203. package/src/__tests__/dev.test.ts +254 -0
  204. package/src/__tests__/file-session.test.ts +98 -0
  205. package/src/__tests__/fixtures.ts +101 -0
  206. package/src/__tests__/functions-generator.test.ts +137 -1
  207. package/src/__tests__/init.test.ts +386 -1
  208. package/src/__tests__/jest-globals.d.ts +8 -0
  209. package/src/__tests__/machine.test.ts +371 -0
  210. package/src/__tests__/mcp.test.ts +253 -0
  211. package/src/__tests__/model-parser.test.ts +142 -0
  212. package/src/__tests__/multi-auth.test.ts +160 -0
  213. package/src/__tests__/nextjs-generator.test.ts +8 -0
  214. package/src/__tests__/package-manager.test.ts +59 -4
  215. package/src/__tests__/plan-apply.test.ts +499 -0
  216. package/src/__tests__/python-uv.test.ts +48 -0
  217. package/src/__tests__/scaffold.test.ts +287 -24
  218. package/src/__tests__/tsconfig.json +15 -0
  219. package/src/__tests__/ui-generator.test.ts +104 -0
  220. package/src/__tests__/zod-mock-generator.test.ts +132 -0
  221. package/src/cli/commands/add-auth.ts +853 -0
  222. package/src/cli/commands/add-connector.ts +159 -0
  223. package/src/cli/commands/cosmos-worktree-isolation.ts +130 -0
  224. package/src/cli/commands/create-model.ts +21 -100
  225. package/src/cli/commands/dev-seeds.ts +278 -7
  226. package/src/cli/commands/dev.ts +607 -160
  227. package/src/cli/commands/init.ts +880 -808
  228. package/src/cli/commands/scaffold.ts +531 -236
  229. package/src/cli/index.ts +338 -60
  230. package/src/core/config.ts +145 -9
  231. package/src/core/mock/connector-mock-server.ts +555 -0
  232. package/src/core/mock/zod-mock-generator.ts +205 -0
  233. package/src/core/operations/auth-operations.ts +360 -0
  234. package/src/core/operations/create-model.ts +191 -0
  235. package/src/core/operations/file-session.ts +222 -0
  236. package/src/core/operations/provision-operations.ts +297 -0
  237. package/src/core/operations/runtime.ts +258 -0
  238. package/src/core/operations/scaffold-apply.ts +106 -0
  239. package/src/core/operations/scaffold-machine.ts +77 -0
  240. package/src/core/operations/scaffold-plan.ts +215 -0
  241. package/src/core/project/agent-instructions.ts +167 -0
  242. package/src/core/project/agent-templates/AGENTS.md +504 -0
  243. package/src/core/project/agent-templates/CLAUDE.md +31 -0
  244. package/src/core/project/agent-templates/azure-functions.instructions.md +22 -0
  245. package/src/core/project/agent-templates/bff-routes.instructions.md +18 -0
  246. package/src/core/project/agent-templates/copilot-instructions.md +27 -0
  247. package/src/core/project/agent-templates/shared-models.instructions.md +72 -0
  248. package/src/core/project/artifacts.ts +205 -0
  249. package/src/core/project/boundaries.ts +170 -0
  250. package/src/core/project/capabilities.ts +193 -0
  251. package/src/core/project/drift.ts +202 -0
  252. package/src/core/project/infra.ts +196 -0
  253. package/src/core/project/manifest.ts +402 -0
  254. package/src/core/project/state.ts +77 -0
  255. package/src/core/project/validation.ts +295 -0
  256. package/src/core/project/workflows.ts +295 -0
  257. package/src/core/scaffold/auth-generator.ts +1824 -0
  258. package/src/core/scaffold/connector-functions-generator.ts +1133 -0
  259. package/src/core/scaffold/functions-generator.ts +432 -134
  260. package/src/core/scaffold/model-parser.ts +244 -90
  261. package/src/core/scaffold/native-schema-generator.ts +904 -0
  262. package/src/core/scaffold/nextjs-generator.ts +174 -9
  263. package/src/core/scaffold/ui-generator.ts +191 -36
  264. package/src/core/verify/index.ts +468 -0
  265. package/src/machine/contracts.ts +33 -0
  266. package/src/machine/errors.ts +45 -0
  267. package/src/machine/index.ts +690 -0
  268. package/src/mcp/index.ts +423 -0
  269. package/src/types/index.ts +137 -0
  270. package/src/utils/package-manager.ts +41 -19
  271. package/src/utils/python-uv.ts +96 -0
  272. package/src/version.ts +13 -0
@@ -0,0 +1,167 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ import { BackendLanguage } from "../../types";
4
+ import { PackageManager, getCommands } from "../../utils/package-manager";
5
+
6
+ export interface AgentInstructionContext {
7
+ projectName: string;
8
+ backendLanguage: BackendLanguage;
9
+ packageManager: PackageManager;
10
+ }
11
+
12
+ export interface AgentInstructionDocuments {
13
+ agentsMd: string;
14
+ claudeMd: string;
15
+ copilotInstructions: string;
16
+ pathSpecificInstructions: Record<string, string>;
17
+ }
18
+
19
+ export const AGENT_TEMPLATE_FILES = {
20
+ agentsMd: "AGENTS.md",
21
+ claudeMd: "CLAUDE.md",
22
+ copilotInstructions: "copilot-instructions.md",
23
+ sharedModelsInstructions: "shared-models.instructions.md",
24
+ bffRoutesInstructions: "bff-routes.instructions.md",
25
+ azureFunctionsInstructions: "azure-functions.instructions.md",
26
+ } as const;
27
+
28
+ const BACKEND_LANGUAGE_LABELS: Record<BackendLanguage, string> = {
29
+ typescript: "TypeScript",
30
+ csharp: "C#",
31
+ python: "Python",
32
+ };
33
+
34
+ function getTemplatePath(fileName: string): string {
35
+ const candidates = [
36
+ path.join(__dirname, "agent-templates", fileName),
37
+ path.join(__dirname, "../../../src/core/project/agent-templates", fileName),
38
+ ];
39
+ const templatePath = candidates.find((candidate) => fs.existsSync(candidate));
40
+ if (!templatePath) {
41
+ throw new Error(`Agent instruction template not found: ${fileName}`);
42
+ }
43
+ return templatePath;
44
+ }
45
+
46
+ export function readAgentInstructionTemplate(fileName: string): string {
47
+ return fs.readFileSync(getTemplatePath(fileName), "utf-8").replace(/\r\n/g, "\n");
48
+ }
49
+
50
+ function getFunctionsStructureLine(backendLanguage: BackendLanguage): string {
51
+ if (backendLanguage === "typescript") {
52
+ return "│ └── src/ # HTTP trigger handlers with Cosmos DB bindings";
53
+ }
54
+ if (backendLanguage === "csharp") {
55
+ return "│ ├── Crud/ # C# HTTP trigger handlers\n│ └── generated/ # Native-generated C# schema assets";
56
+ }
57
+ return "│ ├── blueprints/ # Python HTTP trigger handlers\n│ └── generated/ # Native-generated Python schema assets";
58
+ }
59
+
60
+ function getBackendRules(backendLanguage: BackendLanguage): string {
61
+ if (backendLanguage === "typescript") {
62
+ return [
63
+ "- All backend business logic and data access live in `functions/src/`.",
64
+ "- Prefer Azure Functions Cosmos DB input/output bindings for reads and writes.",
65
+ "- Use the Cosmos DB SDK directly only where bindings do not support the operation, such as deletes.",
66
+ "- Validate data against the shared Zod schemas before persistence.",
67
+ ].join("\n");
68
+ }
69
+ return [
70
+ "- All backend business logic and data access live in `functions/`.",
71
+ `- SwallowKit derives OpenAPI and native ${BACKEND_LANGUAGE_LABELS[backendLanguage]} schema assets from the Zod source of truth.`,
72
+ "- Keep custom business logic in ai-authored locations identified by the current boundary contract.",
73
+ ].join("\n");
74
+ }
75
+
76
+ function interpolateTemplate(template: string, context: AgentInstructionContext): string {
77
+ const runCmd = getCommands(context.packageManager).exec;
78
+ const replacements: Record<string, string> = {
79
+ projectName: context.projectName,
80
+ backendLanguageLabel: BACKEND_LANGUAGE_LABELS[context.backendLanguage],
81
+ functionsStructureLine: getFunctionsStructureLine(context.backendLanguage),
82
+ backendRules: getBackendRules(context.backendLanguage),
83
+ pm: context.packageManager,
84
+ runCmd,
85
+ };
86
+
87
+ const result = template.replace(/\{\{([A-Za-z]+)\}\}/g, (placeholder, key: string) => {
88
+ const replacement = replacements[key];
89
+ if (replacement === undefined) {
90
+ throw new Error(`Unknown Agent instruction placeholder: ${placeholder}`);
91
+ }
92
+ return replacement;
93
+ });
94
+
95
+ if (/\{\{[^}]+\}\}/.test(result)) {
96
+ throw new Error("Unresolved Agent instruction template placeholder");
97
+ }
98
+ return result;
99
+ }
100
+
101
+ function buildTemplate(fileName: string, context: AgentInstructionContext): string {
102
+ return interpolateTemplate(readAgentInstructionTemplate(fileName), context);
103
+ }
104
+
105
+ export function buildAgentsMd(context: AgentInstructionContext): string {
106
+ return buildTemplate(AGENT_TEMPLATE_FILES.agentsMd, context);
107
+ }
108
+
109
+ export function buildClaudeMd(context: AgentInstructionContext): string {
110
+ return buildTemplate(AGENT_TEMPLATE_FILES.claudeMd, context);
111
+ }
112
+
113
+ export function buildCopilotInstructions(context: AgentInstructionContext): string {
114
+ return buildTemplate(AGENT_TEMPLATE_FILES.copilotInstructions, context);
115
+ }
116
+
117
+ export function buildPathSpecificInstructions(
118
+ context: AgentInstructionContext
119
+ ): Record<string, string> {
120
+ return {
121
+ [AGENT_TEMPLATE_FILES.sharedModelsInstructions]: buildTemplate(
122
+ AGENT_TEMPLATE_FILES.sharedModelsInstructions,
123
+ context
124
+ ),
125
+ [AGENT_TEMPLATE_FILES.bffRoutesInstructions]: buildTemplate(
126
+ AGENT_TEMPLATE_FILES.bffRoutesInstructions,
127
+ context
128
+ ),
129
+ [AGENT_TEMPLATE_FILES.azureFunctionsInstructions]: buildTemplate(
130
+ AGENT_TEMPLATE_FILES.azureFunctionsInstructions,
131
+ context
132
+ ),
133
+ };
134
+ }
135
+
136
+ export function buildAgentInstructionDocuments(
137
+ context: AgentInstructionContext
138
+ ): AgentInstructionDocuments {
139
+ return {
140
+ agentsMd: buildAgentsMd(context),
141
+ claudeMd: buildClaudeMd(context),
142
+ copilotInstructions: buildCopilotInstructions(context),
143
+ pathSpecificInstructions: buildPathSpecificInstructions(context),
144
+ };
145
+ }
146
+
147
+ export function writeAgentInstructionFiles(
148
+ projectDir: string,
149
+ context: AgentInstructionContext
150
+ ): AgentInstructionDocuments {
151
+ const documents = buildAgentInstructionDocuments(context);
152
+ fs.writeFileSync(path.join(projectDir, "AGENTS.md"), documents.agentsMd, "utf-8");
153
+ fs.writeFileSync(path.join(projectDir, "CLAUDE.md"), documents.claudeMd, "utf-8");
154
+
155
+ const githubDir = path.join(projectDir, ".github");
156
+ const instructionsDir = path.join(githubDir, "instructions");
157
+ fs.mkdirSync(instructionsDir, { recursive: true });
158
+ fs.writeFileSync(
159
+ path.join(githubDir, "copilot-instructions.md"),
160
+ documents.copilotInstructions,
161
+ "utf-8"
162
+ );
163
+ for (const [fileName, content] of Object.entries(documents.pathSpecificInstructions)) {
164
+ fs.writeFileSync(path.join(instructionsDir, fileName), content, "utf-8");
165
+ }
166
+ return documents;
167
+ }
@@ -0,0 +1,504 @@
1
+ # AGENTS.md
2
+
3
+ This project was generated by **SwallowKit**.
4
+
5
+ SwallowKit is part of this project's architecture and development workflow.
6
+ Treat it as a standing constraint during discovery, requirements clarification,
7
+ specification, planning, ticket decomposition, implementation, verification,
8
+ and review — not only during code generation.
9
+
10
+ ## How SwallowKit Fits Into the Development Process
11
+
12
+ SwallowKit does **not** own the overall software development process.
13
+
14
+ If the user or another Agent Skill or framework defines a process for
15
+ requirements discovery, specification, planning, ticketing, TDD,
16
+ implementation, or review, continue to follow that process.
17
+
18
+ Use SwallowKit as the authoritative project-specific layer for:
19
+
20
+ - inspecting the current project
21
+ - understanding entities, routes, infrastructure, and responsibility boundaries
22
+ - determining which artifacts may be edited directly
23
+ - performing deterministic generation through plan/apply
24
+ - detecting drift
25
+ - verifying the resulting project
26
+ - enforcing human approval gates for sensitive operations
27
+
28
+ External development-process skills and SwallowKit are intended to compose.
29
+
30
+ A process skill decides **how to proceed**.
31
+ SwallowKit determines **how this SwallowKit project can be changed safely and reproducibly**.
32
+
33
+ ## Do Not Assume SwallowKit Capabilities From Memory
34
+
35
+ SwallowKit evolves over time.
36
+
37
+ Do not rely on model knowledge or assumptions about what SwallowKit can or
38
+ cannot generate.
39
+
40
+ When a SwallowKit capability, project structure, or ownership boundary affects
41
+ a design decision, inspect the current project and the currently available
42
+ SwallowKit interfaces before deciding.
43
+
44
+ Prefer the `swallowkit_*` MCP tools when available.
45
+
46
+ If MCP is unavailable, use the machine interface:
47
+
48
+ ```bash
49
+ {{runCmd}} swallowkit machine ...
50
+ ```
51
+
52
+ The machine interface is the fallback Agent-facing interface and returns
53
+ structured `status` / `nextActions` suitable for autonomous workflows.
54
+
55
+ ## Inspect Before Asking or Designing
56
+
57
+ When a task may affect SwallowKit-managed application structure, inspect the
58
+ project before asking the human questions or committing to an implementation
59
+ design.
60
+
61
+ Use only the inspections relevant to the task. Typical inspections include:
62
+
63
+ ```bash
64
+ {{runCmd}} swallowkit machine inspect project
65
+ {{runCmd}} swallowkit machine inspect entities
66
+ {{runCmd}} swallowkit machine inspect routes
67
+ {{runCmd}} swallowkit machine inspect boundaries
68
+ {{runCmd}} swallowkit machine inspect drift
69
+ {{runCmd}} swallowkit machine inspect infra
70
+ {{runCmd}} swallowkit machine inspect capabilities
71
+ ```
72
+
73
+ `inspect capabilities` answers "what can SwallowKit do" (supported model
74
+ declarations with exact formats, the correct auth-introduction workflow, what
75
+ generated CRUD does and does not guarantee, how seeds are applied). Use it
76
+ instead of guessing or grepping SwallowKit internals.
77
+
78
+ Use the equivalent `swallowkit_*` MCP tools when available.
79
+
80
+ Questions that can be answered from the repository or SwallowKit inspection
81
+ should be answered by the agent instead of being delegated to the human.
82
+
83
+ Examples:
84
+
85
+ - Do not ask how generated CRUD layers should be wired if SwallowKit already
86
+ defines and generates them.
87
+ - Do not propose editing a generated file until responsibility boundaries have
88
+ been checked.
89
+ - Do not assume an infrastructure capability is unavailable before inspecting
90
+ the current SwallowKit project and available operations.
91
+
92
+ ## Specification and Planning Guidance
93
+
94
+ When producing or refining a specification:
95
+
96
+ - describe user-visible behavior and domain intent
97
+ - define acceptance criteria and important test seams
98
+ - treat SwallowKit's architecture and responsibility boundaries as
99
+ implementation constraints
100
+ - avoid prematurely describing generated artifacts as manually implemented
101
+ components
102
+ - do not duplicate work that SwallowKit can deterministically derive from its
103
+ source of truth
104
+
105
+ For example, if adding a model field causes SwallowKit to regenerate backend,
106
+ BFF, UI, and infrastructure artifacts, the specification should primarily
107
+ describe the desired end-to-end behavior and the SwallowKit constraint.
108
+
109
+ It should not imply that every generated layer is an independent manual
110
+ implementation decision.
111
+
112
+ If whether SwallowKit supports the desired behavior affects the specification,
113
+ inspect the current capabilities before finalizing the spec.
114
+
115
+ ## Ticket Decomposition Guidance
116
+
117
+ Prefer independently verifiable **vertical slices** of user or system behavior.
118
+
119
+ Do not split work into horizontal tickets such as:
120
+
121
+ - schema ticket
122
+ - backend ticket
123
+ - BFF ticket
124
+ - UI ticket
125
+ - infrastructure ticket
126
+
127
+ merely because those artifacts exist in separate layers.
128
+
129
+ When SwallowKit deterministically produces those layers, keep them inside the
130
+ same vertical slice whenever they represent one end-to-end behavior.
131
+
132
+ Example:
133
+
134
+ ```text
135
+ Add priority support to Todo
136
+ ├─ update the source-of-truth model
137
+ ├─ use SwallowKit plan/apply to realign managed artifacts
138
+ ├─ add any required ai-authored business logic
139
+ ├─ add/update tests
140
+ └─ verify the project
141
+ ```
142
+
143
+ Ticket boundaries should reflect independently valuable and verifiable
144
+ behavior, not SwallowKit's generated file structure.
145
+
146
+ ## Responsibility Boundary
147
+
148
+ Before making file-level implementation decisions, inspect the current
149
+ machine-readable boundary contract:
150
+
151
+ ```bash
152
+ {{runCmd}} swallowkit machine inspect boundaries
153
+ ```
154
+
155
+ Treat its current result as authoritative.
156
+
157
+ The general ownership model is:
158
+
159
+ ### ai-authored
160
+
161
+ The agent may edit these directly.
162
+
163
+ Typical examples include:
164
+
165
+ - source-of-truth models
166
+ - custom business logic
167
+ - custom pages/components
168
+ - tests
169
+
170
+ ### deterministic
171
+
172
+ Do not hand-edit these artifacts.
173
+
174
+ They are generated and owned by SwallowKit. Change the appropriate source of
175
+ truth or configuration, then use SwallowKit plan/apply to regenerate them.
176
+
177
+ Managed artifacts are tracked by SwallowKit metadata such as
178
+ `.swallowkit/artifacts.json`.
179
+
180
+ ### shared
181
+
182
+ Edit only outside SwallowKit-managed markers.
183
+
184
+ Always inspect the current boundary contract instead of relying solely on the
185
+ examples in this document.
186
+
187
+ ## Deterministic Changes: Plan → Apply → Verify
188
+
189
+ For autonomous or agent-driven generation, prefer the SwallowKit two-phase
190
+ workflow.
191
+
192
+ ```text
193
+ inspect
194
+ ↓
195
+ plan
196
+ ↓
197
+ evaluate conflicts / approval requirements
198
+ ↓
199
+ apply
200
+ ↓
201
+ verify
202
+ ```
203
+
204
+ Example:
205
+
206
+ ```bash
207
+ {{runCmd}} swallowkit machine plan scaffold <model>
208
+ {{runCmd}} swallowkit machine apply scaffold --plan <planId>
209
+ {{runCmd}} swallowkit machine verify project
210
+ ```
211
+
212
+ Do not bypass plan/apply by manually editing deterministic artifacts.
213
+
214
+ If a plan reports conflicts, determine whether existing hand-written behavior
215
+ must be moved to an ai-authored location or whether overwrite approval is
216
+ required.
217
+
218
+ Never invent or implicitly grant human approval.
219
+
220
+ ## Model Changes
221
+
222
+ For an existing model change, the normal pattern is:
223
+
224
+ ```text
225
+ edit source-of-truth model
226
+ ↓
227
+ inspect drift
228
+ ↓
229
+ plan scaffold
230
+ ↓
231
+ resolve conflicts / approvals if any
232
+ ↓
233
+ apply
234
+ ↓
235
+ verify
236
+ ```
237
+
238
+ Use the `swallowkit-modify-model` Agent Skill when available.
239
+
240
+ Otherwise read and follow the equivalent runbook under
241
+ `.swallowkit/workflows/`.
242
+
243
+ Never repair schema drift by directly patching SwallowKit-managed artifacts.
244
+
245
+ Additional model-change facts:
246
+
247
+ - The shared package is consumed through its built `dist/`. `verify project`
248
+ rebuilds it automatically before typecheck; when typechecking manually,
249
+ build the shared package first (stale `dist/` shows up as
250
+ "no exported member" errors).
251
+ - Seed JSON under `dev-seeds/` is only applied by
252
+ `{{runCmd}} swallowkit dev --seed-env <environment>`; editing the files
253
+ alone does nothing.
254
+
255
+ ## New Models / CRUD Features
256
+
257
+ Use the `swallowkit-add-model` Agent Skill when available.
258
+
259
+ Otherwise follow the equivalent runbook under `.swallowkit/workflows/`.
260
+
261
+ The agent may author domain-specific schema fields and custom behavior, but
262
+ SwallowKit should generate framework-owned CRUD artifacts.
263
+
264
+ Do not manually recreate boilerplate that SwallowKit owns.
265
+
266
+ ## Authentication
267
+
268
+ Authentication is a **plan/apply operation**, not a free-form config edit.
269
+ Ownership of `swallowkit.config` is split:
270
+
271
+ - `auth.schemes` — owned by SwallowKit. **Always start with
272
+ `{{runCmd}} swallowkit machine plan auth --provider <p> [--scheme <name>]`.
273
+ Never hand-write `auth.schemes` entries**; apply auth appends them, and a
274
+ hand-written scheme makes the plan fail with "already exists".
275
+ - `auth.authorization.policies` and `swa.allowedProviders` — hand-edited
276
+ **after** apply (the config is an extension point; this edit is expected).
277
+ `swa.allowedProviders` can also be set at plan time with
278
+ `--allowed-providers github,aad`.
279
+
280
+ After `apply auth`, follow the returned `nextActions`:
281
+
282
+ 1. Define `auth.authorization.policies` referencing the new scheme.
283
+ 2. For `swa`: confirm `swa.allowedProviders`; generated login URLs use it.
284
+ 3. For `external-token`: implement the generated verifier stub. It fails
285
+ closed, and **verify passes with the stub in place** — a green verify does
286
+ not mean external-token auth works end-to-end (`verify project` surfaces a
287
+ `auth-verifier-stub` warning while the stub is unmodified).
288
+ 4. Re-run plan/apply scaffold for models that need auth guards, then verify.
289
+
290
+ Use the `swallowkit-add-auth` Agent Skill or the
291
+ `.swallowkit/workflows/add-auth.md` runbook when available.
292
+
293
+ ### Generated CRUD scope
294
+
295
+ Generated CRUD endpoints enforce the model's `authPolicy`
296
+ (authentication + roles) — **they do NOT scope data to the authenticated
297
+ user**. Any caller passing the policy can read or write any document. For
298
+ multi-user data where users may only touch their own records, add ai-authored
299
+ custom endpoints that derive the scoping key (e.g. `learnerId`) from the
300
+ verified principal — never from the request body — and restrict the generated
301
+ write endpoints to admin roles.
302
+
303
+ ## Verification Is a Completion Gate
304
+
305
+ Before treating an agent-driven implementation as complete, run SwallowKit
306
+ verification:
307
+
308
+ ```bash
309
+ {{runCmd}} swallowkit machine verify project
310
+ ```
311
+
312
+ or the equivalent MCP operation.
313
+
314
+ Verification covers SwallowKit structural correctness, drift, type correctness,
315
+ and configured project checks.
316
+
317
+ When verification fails, use the structured failure explanation:
318
+
319
+ ```bash
320
+ {{runCmd}} swallowkit machine explain failure
321
+ ```
322
+
323
+ or its MCP equivalent, then repair the appropriate source and verify again.
324
+
325
+ Use the `swallowkit-verify-repair` Agent Skill or runbook when applicable.
326
+
327
+ SwallowKit verification answers:
328
+
329
+ > Is the SwallowKit project mechanically and structurally valid?
330
+
331
+ A semantic code review answers different questions:
332
+
333
+ > Is this implementation well designed?
334
+ > Does it satisfy the specification and user intent?
335
+
336
+ Therefore, perform SwallowKit verification before treating semantic code review
337
+ as the final quality gate.
338
+
339
+ ## Human Approval Gates
340
+
341
+ A machine operation may return terminal states such as:
342
+
343
+ - `complete`
344
+ - `in-progress`
345
+ - `blocked`
346
+ - `requires-human`
347
+ - `failed`
348
+
349
+ Follow `nextActions`.
350
+
351
+ When the status is `requires-human`, stop and request the required human
352
+ decision.
353
+
354
+ Do not reinterpret `requires-human` as an error to work around.
355
+
356
+ Azure provisioning is a human-approved operation.
357
+
358
+ Use the `swallowkit-provision` Agent Skill or runbook and never bypass its
359
+ approval gate. A broad request to deploy does not itself grant the explicit
360
+ approval required by that workflow.
361
+
362
+ ## SwallowKit Agent Skills and Runbooks
363
+
364
+ SwallowKit installs task-specific Agent Skills under:
365
+
366
+ ```text
367
+ .github/skills/
368
+ ```
369
+
370
+ Current workflows include:
371
+
372
+ - `swallowkit-add-model`
373
+ - `swallowkit-modify-model`
374
+ - `swallowkit-add-auth`
375
+ - `swallowkit-verify-repair`
376
+ - `swallowkit-provision`
377
+
378
+ Equivalent agent-agnostic runbooks are available under:
379
+
380
+ ```text
381
+ .swallowkit/workflows/
382
+ ```
383
+
384
+ If the runtime supports Agent Skills, use the relevant Skill when the task
385
+ matches. If it does not, read the corresponding runbook.
386
+
387
+ These task-specific instructions supplement this `AGENTS.md`; they do not
388
+ replace the always-on project contract.
389
+
390
+ ## Architecture
391
+
392
+ This is a full-stack application deployed on Azure with a TypeScript
393
+ frontend/BFF and an Azure Functions backend in {{backendLanguageLabel}}.
394
+
395
+ ```text
396
+ Frontend (React / Next.js App Router)
397
+ ↓
398
+ BFF (Next.js API Routes)
399
+ ↓
400
+ Azure Functions
401
+ ↓
402
+ Azure Cosmos DB
403
+ ```
404
+
405
+ ### Core architecture rules
406
+
407
+ 1. Next.js API routes are a BFF/proxy layer. Do not place application business
408
+ logic or direct database access there.
409
+ 2. Zod schemas under `shared/models/` are the application model source of truth.
410
+ 3. Do not duplicate model definitions across layers.
411
+ 4. Azure Functions own backend business logic and data access.
412
+ 5. SwallowKit-generated artifacts must be changed through their source of truth
413
+ and deterministic generation workflow, not by hand.
414
+ 6. Infrastructure is managed as code with Bicep. Respect SwallowKit ownership
415
+ markers and boundaries.
416
+ 7. Production access to Azure resources must follow the generated security
417
+ architecture; do not introduce hard-coded credentials or connection strings.
418
+
419
+ ### Backend-specific rules
420
+
421
+ {{backendRules}}
422
+
423
+ The backend owns `id`, `createdAt`, and `updatedAt`; never trust client-sent
424
+ values for these fields.
425
+
426
+ ## Project Structure
427
+
428
+ ```text
429
+ {{projectName}}/
430
+ ├── app/ # Next.js App Router
431
+ │ ├── api/ # BFF routes
432
+ │ └── {model}/ # generated/custom UI
433
+ ├── functions/ # Azure Functions backend
434
+ {{functionsStructureLine}}
435
+ ├── shared/
436
+ │ ├── models/ # Zod source-of-truth models
437
+ │ └── index.ts
438
+ ├── lib/
439
+ │ └── api/
440
+ ├── components/
441
+ ├── infra/ # Bicep infrastructure
442
+ ├── .swallowkit/ # SwallowKit project metadata and runbooks
443
+ ├── .github/skills/ # SwallowKit Agent Skills
444
+ ├── .mcp.json # project-scoped SwallowKit MCP bootstrap
445
+ └── AGENTS.md
446
+ ```
447
+
448
+ Inspect the current project rather than assuming every project has exactly the
449
+ same generated structure.
450
+
451
+ ## Naming and Model Conventions
452
+
453
+ - Model schema files use `shared/models/{kebab-case}.ts`.
454
+ - The Zod schema constant and inferred TypeScript type use the same PascalCase
455
+ name: `export const Todo = z.object(...); export type Todo = z.infer<typeof Todo>`.
456
+ - Re-export models from `shared/index.ts`.
457
+ - `id` is a required `z.string()`; only `createdAt` / `updatedAt` are optional
458
+ backend-managed fields.
459
+ - Models may declare `partitionKey`, `authPolicy`, `displayName`, and
460
+ `connectorConfig` as exported constants. Exact formats:
461
+ `{{runCmd}} swallowkit machine inspect capabilities` (modelDeclarations).
462
+ - Cosmos DB containers use PascalCase plural names and default to `/id` as the
463
+ partition key unless the model declares another key, e.g.
464
+ `export const partitionKey = '/learnerId';` (the field must exist in the
465
+ schema).
466
+
467
+ ## Everyday Commands
468
+
469
+ ```bash
470
+ {{pm}} install
471
+ {{runCmd}} swallowkit dev
472
+ {{pm}} run build
473
+ {{pm}} run lint
474
+ {{runCmd}} swallowkit machine verify project
475
+ ```
476
+
477
+ Always invoke SwallowKit using the package-runner convention generated for this
478
+ project. Do not arbitrarily mix package-manager invocation styles.
479
+
480
+ ## Final Rules
481
+
482
+ Do not:
483
+
484
+ - rely on remembered SwallowKit capabilities when current inspection can answer
485
+ the question
486
+ - hand-edit deterministic SwallowKit-managed artifacts
487
+ - bypass plan/apply safety checks
488
+ - bypass human approval gates
489
+ - duplicate model definitions across generated layers
490
+ - move backend business logic into the BFF
491
+ - decompose one end-to-end SwallowKit-generated feature into artificial
492
+ horizontal tickets solely because multiple generated layers exist
493
+ - consider an implementation complete before SwallowKit verification succeeds
494
+
495
+ Do:
496
+
497
+ - inspect before making SwallowKit-dependent design assumptions
498
+ - preserve external development-process workflows
499
+ - use SwallowKit as the deterministic execution and verification layer
500
+ - keep specifications focused on intent and observable behavior
501
+ - prefer vertical, independently verifiable slices
502
+ - verify before final semantic review
503
+
504
+ Use `{{pm}}`, the package manager selected for this project. Do not introduce another package manager or lockfile. Use `{{runCmd}} swallowkit` for the project-local CLI. The MCP launcher intentionally resolves `latest` independently.
@@ -0,0 +1,31 @@
1
+ # CLAUDE.md
2
+
3
+ This is a **SwallowKit** project.
4
+
5
+ Before discovery, requirements clarification, specification, planning, ticket
6
+ decomposition, implementation, verification, or review, read and follow the
7
+ root `AGENTS.md`.
8
+
9
+ SwallowKit must be considered before implementation, not only when generating
10
+ code.
11
+
12
+ Always-on rules:
13
+
14
+ - Inspect the current project and SwallowKit capabilities before making
15
+ SwallowKit-dependent assumptions or asking questions the repository can answer.
16
+ - Prefer `swallowkit_*` MCP tools.
17
+ - Fall back to `{{runCmd}} swallowkit machine ...` when MCP is unavailable.
18
+ - Inspect responsibility boundaries before editing framework-related files.
19
+ - Never hand-edit deterministic SwallowKit-managed artifacts.
20
+ - Add auth schemes only via plan/apply auth; never hand-write `auth.schemes`
21
+ in swallowkit.config (policies and `swa.allowedProviders` are hand-edited
22
+ after apply).
23
+ - Use plan/apply for deterministic generation.
24
+ - Respect all `requires-human` states and provisioning approval gates.
25
+ - Run SwallowKit verification before considering implementation complete.
26
+
27
+ Task-specific SwallowKit Agent Skills are available under `.github/skills/`.
28
+ Equivalent agent-agnostic runbooks are available under
29
+ `.swallowkit/workflows/`.
30
+
31
+ The root `AGENTS.md` is the canonical project contract.