swallowkit 2.0.0-alpha.3 → 2.0.0-alpha.5
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/commands/add-auth.js +37 -6
- package/dist/cli/commands/add-auth.js.map +1 -1
- package/dist/cli/commands/configure-mcp.d.ts +12 -0
- package/dist/cli/commands/configure-mcp.d.ts.map +1 -0
- package/dist/cli/commands/configure-mcp.js +42 -0
- package/dist/cli/commands/configure-mcp.js.map +1 -0
- package/dist/cli/commands/init.d.ts +6 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +19 -5
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/migrations.d.ts.map +1 -1
- package/dist/cli/commands/migrations.js +25 -0
- package/dist/cli/commands/migrations.js.map +1 -1
- package/dist/cli/commands/provision.d.ts +2 -0
- package/dist/cli/commands/provision.d.ts.map +1 -1
- package/dist/cli/commands/provision.js +45 -16
- package/dist/cli/commands/provision.js.map +1 -1
- package/dist/cli/commands/scaffold.d.ts +4 -0
- package/dist/cli/commands/scaffold.d.ts.map +1 -1
- package/dist/cli/commands/scaffold.js +85 -3
- package/dist/cli/commands/scaffold.js.map +1 -1
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +29 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/core/operations/create-model.d.ts +2 -0
- package/dist/core/operations/create-model.d.ts.map +1 -1
- package/dist/core/operations/create-model.js +60 -8
- package/dist/core/operations/create-model.js.map +1 -1
- package/dist/core/operations/model-migration.d.ts +22 -0
- package/dist/core/operations/model-migration.d.ts.map +1 -0
- package/dist/core/operations/model-migration.js +36 -0
- package/dist/core/operations/model-migration.js.map +1 -0
- package/dist/core/operations/provision-operations.d.ts +19 -1
- package/dist/core/operations/provision-operations.d.ts.map +1 -1
- package/dist/core/operations/provision-operations.js +62 -35
- package/dist/core/operations/provision-operations.js.map +1 -1
- package/dist/core/operations/scaffold-apply.d.ts +1 -0
- package/dist/core/operations/scaffold-apply.d.ts.map +1 -1
- package/dist/core/operations/scaffold-apply.js +1 -0
- package/dist/core/operations/scaffold-apply.js.map +1 -1
- package/dist/core/operations/scaffold-machine.d.ts +1 -0
- package/dist/core/operations/scaffold-machine.d.ts.map +1 -1
- package/dist/core/operations/scaffold-machine.js.map +1 -1
- package/dist/core/operations/scaffold-plan.d.ts +2 -0
- package/dist/core/operations/scaffold-plan.d.ts.map +1 -1
- package/dist/core/operations/scaffold-plan.js +3 -1
- package/dist/core/operations/scaffold-plan.js.map +1 -1
- package/dist/core/project/boundaries.d.ts +5 -2
- package/dist/core/project/boundaries.d.ts.map +1 -1
- package/dist/core/project/boundaries.js +51 -20
- package/dist/core/project/boundaries.js.map +1 -1
- package/dist/core/project/capabilities.d.ts +2 -0
- package/dist/core/project/capabilities.d.ts.map +1 -1
- package/dist/core/project/capabilities.js +29 -5
- package/dist/core/project/capabilities.js.map +1 -1
- package/dist/core/project/mcp-config.d.ts +26 -0
- package/dist/core/project/mcp-config.d.ts.map +1 -0
- package/dist/core/project/mcp-config.js +117 -0
- package/dist/core/project/mcp-config.js.map +1 -0
- package/dist/core/project/react-project.js +1 -1
- package/dist/core/project/workflows.d.ts.map +1 -1
- package/dist/core/project/workflows.js +23 -5
- package/dist/core/project/workflows.js.map +1 -1
- package/dist/core/scaffold/auth-generator.d.ts.map +1 -1
- package/dist/core/scaffold/auth-generator.js +18 -19
- package/dist/core/scaffold/auth-generator.js.map +1 -1
- package/dist/core/scaffold/model-parser.d.ts +23 -0
- package/dist/core/scaffold/model-parser.d.ts.map +1 -1
- package/dist/core/scaffold/model-parser.js +407 -137
- package/dist/core/scaffold/model-parser.js.map +1 -1
- package/dist/core/scaffold/native-schema-generator.d.ts +13 -0
- package/dist/core/scaffold/native-schema-generator.d.ts.map +1 -1
- package/dist/core/scaffold/native-schema-generator.js +289 -76
- package/dist/core/scaffold/native-schema-generator.js.map +1 -1
- package/dist/core/scaffold/openapi-generator.d.ts +5 -0
- package/dist/core/scaffold/openapi-generator.d.ts.map +1 -1
- package/dist/core/scaffold/openapi-generator.js +53 -3
- package/dist/core/scaffold/openapi-generator.js.map +1 -1
- package/dist/core/scaffold/ui-generator.d.ts +0 -3
- package/dist/core/scaffold/ui-generator.d.ts.map +1 -1
- package/dist/core/scaffold/ui-generator.js +68 -7
- package/dist/core/scaffold/ui-generator.js.map +1 -1
- package/dist/core/verify/index.d.ts +4 -3
- package/dist/core/verify/index.d.ts.map +1 -1
- package/dist/core/verify/index.js +122 -5
- package/dist/core/verify/index.js.map +1 -1
- package/dist/machine/contracts.d.ts +1 -0
- package/dist/machine/contracts.d.ts.map +1 -1
- package/dist/machine/errors.d.ts +3 -2
- package/dist/machine/errors.d.ts.map +1 -1
- package/dist/machine/errors.js +2 -1
- package/dist/machine/errors.js.map +1 -1
- package/dist/machine/index.d.ts.map +1 -1
- package/dist/machine/index.js +42 -17
- package/dist/machine/index.js.map +1 -1
- package/dist/mcp/index.d.ts +4 -2
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +154 -15
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/version-selection.d.ts +55 -0
- package/dist/mcp/version-selection.d.ts.map +1 -0
- package/dist/mcp/version-selection.js +152 -0
- package/dist/mcp/version-selection.js.map +1 -0
- package/dist/utils/azure-cli.d.ts +44 -0
- package/dist/utils/azure-cli.d.ts.map +1 -0
- package/dist/utils/azure-cli.js +164 -0
- package/dist/utils/azure-cli.js.map +1 -0
- package/dist/utils/semver.d.ts +14 -0
- package/dist/utils/semver.d.ts.map +1 -0
- package/dist/utils/semver.js +61 -0
- package/dist/utils/semver.js.map +1 -0
- package/package.json +6 -3
- package/src/__tests__/__snapshots__/boundaries.test.ts.snap +154 -0
- package/src/__tests__/agent-loop-phase34.test.ts +124 -0
- package/src/__tests__/azure-cli.test.ts +199 -0
- package/src/__tests__/boundaries.test.ts +42 -0
- package/src/__tests__/csharp-schema.test.ts +261 -0
- package/src/__tests__/generated-project-matrix.test.ts +789 -0
- package/src/__tests__/mcp-version.test.ts +262 -0
- package/src/__tests__/mcp.test.ts +64 -3
- package/src/__tests__/multi-auth.test.ts +115 -4
- package/src/__tests__/plan-apply.test.ts +170 -0
- package/src/__tests__/schema-analysis.test.ts +329 -0
- package/src/cli/commands/add-auth.ts +36 -6
- package/src/cli/commands/configure-mcp.ts +54 -0
- package/src/cli/commands/init.ts +23 -8
- package/src/cli/commands/migrations.ts +22 -0
- package/src/cli/commands/provision.ts +53 -17
- package/src/cli/commands/scaffold.ts +105 -3
- package/src/cli/index.ts +28 -5
- package/src/core/operations/create-model.ts +51 -13
- package/src/core/operations/model-migration.ts +52 -0
- package/src/core/operations/provision-operations.ts +86 -42
- package/src/core/operations/scaffold-apply.ts +2 -0
- package/src/core/operations/scaffold-machine.ts +1 -0
- package/src/core/operations/scaffold-plan.ts +5 -1
- package/src/core/project/agent-templates/AGENTS.md +67 -6
- package/src/core/project/agent-templates/CLAUDE.md +7 -1
- package/src/core/project/agent-templates/copilot-instructions.md +7 -1
- package/src/core/project/agent-templates/shared-models.instructions.md +11 -3
- package/src/core/project/boundaries.ts +62 -20
- package/src/core/project/capabilities.ts +32 -5
- package/src/core/project/mcp-config.ts +84 -0
- package/src/core/project/react-project.ts +1 -1
- package/src/core/project/workflows.ts +23 -5
- package/src/core/scaffold/auth-generator.ts +18 -19
- package/src/core/scaffold/model-parser.ts +413 -129
- package/src/core/scaffold/native-schema-generator.ts +313 -78
- package/src/core/scaffold/openapi-generator.ts +63 -5
- package/src/core/scaffold/ui-generator.ts +70 -8
- package/src/core/verify/index.ts +118 -6
- package/src/machine/contracts.ts +1 -0
- package/src/machine/errors.ts +4 -2
- package/src/machine/index.ts +45 -20
- package/src/mcp/index.ts +173 -18
- package/src/mcp/version-selection.ts +163 -0
- package/src/utils/azure-cli.ts +154 -0
- package/src/utils/semver.ts +59 -0
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
* - shared: マーカー区切りの共有領域。マーカー内は SwallowKit、外は自由。
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
import { getBackendLanguage } from "../config";
|
|
13
14
|
import { ArtifactOwnership } from "../operations/file-session";
|
|
15
|
+
import { BackendLanguage } from "../../types";
|
|
14
16
|
import { inspectArtifacts } from "./artifacts";
|
|
15
17
|
|
|
16
18
|
export type BoundaryZone = "deterministic" | "ai-authored" | "shared";
|
|
@@ -48,6 +50,8 @@ export interface BoundaryArtifact {
|
|
|
48
50
|
export interface BoundariesContract {
|
|
49
51
|
contractVersion: number;
|
|
50
52
|
summary: string;
|
|
53
|
+
/** backend.language the convention rules were resolved for */
|
|
54
|
+
backendLanguage: BackendLanguage;
|
|
51
55
|
ownershipPolicies: OwnershipPolicy[];
|
|
52
56
|
/** 台帳に載っていないパスの既定規約 */
|
|
53
57
|
conventionRules: BoundaryPathRule[];
|
|
@@ -82,7 +86,7 @@ export const OWNERSHIP_POLICIES: OwnershipPolicy[] = [
|
|
|
82
86
|
zone: "shared",
|
|
83
87
|
editPolicy: "edit-outside-markers",
|
|
84
88
|
howToChange:
|
|
85
|
-
"SwallowKit appends
|
|
89
|
+
"SwallowKit appends at the file-specific extension point: marked sections (e.g. `# SwallowKit scaffold registrations`) or append-only files such as shared/index.ts. Follow the path rule; preserve existing generated entries and any markers.",
|
|
86
90
|
},
|
|
87
91
|
{
|
|
88
92
|
ownership: "metadata",
|
|
@@ -92,7 +96,7 @@ export const OWNERSHIP_POLICIES: OwnershipPolicy[] = [
|
|
|
92
96
|
},
|
|
93
97
|
];
|
|
94
98
|
|
|
95
|
-
|
|
99
|
+
const COMMON_LEADING_RULES: BoundaryPathRule[] = [
|
|
96
100
|
{
|
|
97
101
|
pattern: ".swallowkit/",
|
|
98
102
|
zone: "deterministic",
|
|
@@ -107,32 +111,66 @@ export const CONVENTION_RULES: BoundaryPathRule[] = [
|
|
|
107
111
|
"Zod model schemas — the single source of truth. AI/developers author these freely; deterministic generation derives everything else from them.",
|
|
108
112
|
},
|
|
109
113
|
{
|
|
110
|
-
pattern: "infra/
|
|
111
|
-
zone: "
|
|
112
|
-
editPolicy: "
|
|
113
|
-
description:
|
|
114
|
+
pattern: "infra/migrations/manifest.json",
|
|
115
|
+
zone: "deterministic",
|
|
116
|
+
editPolicy: "never-hand-edit",
|
|
117
|
+
description:
|
|
118
|
+
"Infrastructure migration ledger with baseline checksums. Updated by scaffold, `swallowkit migrations add-model`, and `swallowkit create-migration`.",
|
|
114
119
|
},
|
|
115
120
|
{
|
|
116
|
-
pattern: "
|
|
117
|
-
zone: "
|
|
118
|
-
editPolicy: "edit
|
|
119
|
-
description:
|
|
121
|
+
pattern: "infra/migrations/",
|
|
122
|
+
zone: "ai-authored",
|
|
123
|
+
editPolicy: "free-edit",
|
|
124
|
+
description:
|
|
125
|
+
"Versioned Bicep migrations. Edit a migration only before it is provisioned; never change an applied migration — add a new one with `swallowkit create-migration <slug>`.",
|
|
120
126
|
},
|
|
121
127
|
{
|
|
122
|
-
pattern: "
|
|
123
|
-
zone: "
|
|
124
|
-
editPolicy: "
|
|
125
|
-
description:
|
|
128
|
+
pattern: "infra/",
|
|
129
|
+
zone: "deterministic",
|
|
130
|
+
editPolicy: "never-hand-edit",
|
|
131
|
+
description:
|
|
132
|
+
"Baseline infrastructure (main.bicep and modules) whose checksums are recorded in infra/migrations/manifest.json. Hand edits block scaffold with baseline-drift; add resources through a new migration instead.",
|
|
126
133
|
},
|
|
127
134
|
{
|
|
128
|
-
pattern: "
|
|
129
|
-
zone: "
|
|
135
|
+
pattern: "shared/index.ts",
|
|
136
|
+
zone: "shared",
|
|
130
137
|
editPolicy: "free-edit",
|
|
131
|
-
description:
|
|
132
|
-
"Any path not recorded in the artifact ledger is AI/developer-authored. Business logic, custom pages, custom Functions, and tests belong here.",
|
|
138
|
+
description: "create-model and scaffold append missing model exports while preserving existing content. No managed markers; manual exports are allowed. Keep exports needed by generated code.",
|
|
133
139
|
},
|
|
134
140
|
];
|
|
135
141
|
|
|
142
|
+
/** Backend files that SwallowKit appends to; C# and TypeScript discover functions without a registration file. */
|
|
143
|
+
const BACKEND_EXTENSION_RULES: Record<BackendLanguage, BoundaryPathRule[]> = {
|
|
144
|
+
python: [
|
|
145
|
+
{
|
|
146
|
+
pattern: "functions/function_app.py",
|
|
147
|
+
zone: "shared",
|
|
148
|
+
editPolicy: "edit-outside-markers",
|
|
149
|
+
description: "SwallowKit appends blueprint registrations under its marker; other edits are free.",
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
pattern: "functions/requirements.txt",
|
|
153
|
+
zone: "shared",
|
|
154
|
+
editPolicy: "free-edit",
|
|
155
|
+
description: "SwallowKit appends connector driver requirements when connector models are scaffolded; keep those lines and edit other requirements freely.",
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
csharp: [],
|
|
159
|
+
typescript: [],
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const FALLBACK_RULE: BoundaryPathRule = {
|
|
163
|
+
pattern: "*",
|
|
164
|
+
zone: "ai-authored",
|
|
165
|
+
editPolicy: "free-edit",
|
|
166
|
+
description:
|
|
167
|
+
"Any path not recorded in the artifact ledger is AI/developer-authored. Business logic, custom pages, custom Functions, and tests belong here.",
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export function buildConventionRules(backendLanguage: BackendLanguage): BoundaryPathRule[] {
|
|
171
|
+
return [...COMMON_LEADING_RULES, ...BACKEND_EXTENSION_RULES[backendLanguage], FALLBACK_RULE];
|
|
172
|
+
}
|
|
173
|
+
|
|
136
174
|
const POLICY_BY_OWNERSHIP = new Map(OWNERSHIP_POLICIES.map((policy) => [policy.ownership, policy] as const));
|
|
137
175
|
|
|
138
176
|
export const BOUNDARY_GUIDANCE: string[] = [
|
|
@@ -143,7 +181,10 @@ export const BOUNDARY_GUIDANCE: string[] = [
|
|
|
143
181
|
"Run `swallowkit machine verify project` after applying changes; use `explain failure` to get repair evidence.",
|
|
144
182
|
];
|
|
145
183
|
|
|
146
|
-
export function inspectBoundaries(
|
|
184
|
+
export function inspectBoundaries(
|
|
185
|
+
projectRoot: string = process.cwd(),
|
|
186
|
+
backendLanguage: BackendLanguage = getBackendLanguage()
|
|
187
|
+
): BoundariesContract {
|
|
147
188
|
const inspected = inspectArtifacts(projectRoot);
|
|
148
189
|
|
|
149
190
|
const artifacts: BoundaryArtifact[] = inspected.artifacts.map((artifact) => {
|
|
@@ -162,8 +203,9 @@ export function inspectBoundaries(projectRoot: string = process.cwd()): Boundari
|
|
|
162
203
|
contractVersion: 1,
|
|
163
204
|
summary:
|
|
164
205
|
"SwallowKit separates deterministic generation (models → CRUD/BFF/UI/infra via plan/apply) from AI free-form authoring (models, business logic, custom code). This contract tells agents which files belong to which side.",
|
|
206
|
+
backendLanguage,
|
|
165
207
|
ownershipPolicies: OWNERSHIP_POLICIES,
|
|
166
|
-
conventionRules:
|
|
208
|
+
conventionRules: buildConventionRules(backendLanguage),
|
|
167
209
|
artifacts,
|
|
168
210
|
guidance: BOUNDARY_GUIDANCE,
|
|
169
211
|
};
|
|
@@ -53,6 +53,7 @@ export interface CapabilitiesContract {
|
|
|
53
53
|
sharedModels: {
|
|
54
54
|
idFieldRule: string;
|
|
55
55
|
buildNote: string;
|
|
56
|
+
nativeSchemaMapping: string[];
|
|
56
57
|
};
|
|
57
58
|
seeding: {
|
|
58
59
|
createTemplates: string;
|
|
@@ -64,6 +65,7 @@ export interface CapabilitiesContract {
|
|
|
64
65
|
defaultChecks: string[];
|
|
65
66
|
optInChecks: string[];
|
|
66
67
|
customChecks: string;
|
|
68
|
+
backendBuild: string;
|
|
67
69
|
};
|
|
68
70
|
}
|
|
69
71
|
|
|
@@ -108,6 +110,19 @@ export function inspectCapabilities(): CapabilitiesContract {
|
|
|
108
110
|
"Role-based access control metadata applied to the generated CRUD Functions. `roles` guards all operations; `read`/`write` guard per-operation; `policy` references a named authorization policy from swallowkit.config auth.authorization.policies.",
|
|
109
111
|
format:
|
|
110
112
|
"export const authPolicy = { roles: ['admin'] };\n// or per-operation:\nexport const authPolicy = { read: ['user'], write: ['admin'] };\n// or a named policy:\nexport const authPolicy = { policy: 'adminOnly' };",
|
|
113
|
+
notes: [
|
|
114
|
+
"An explicit authPolicy without configured authentication blocks plan/apply/generate scaffold with auth-policy-without-auth before any artifacts are written. Run plan auth, apply auth, then re-plan scaffold. An empty {} declaration keeps the existing behavior: no explicit policy.",
|
|
115
|
+
"With named auth.schemes, define auth.authorization.policies selecting schemes and roles, then reference them via policy or read/write names. A role-only declaration cannot select a named scheme and blocks with auth-policy-requires-named-policy; it is supported by legacy single-provider authentication.",
|
|
116
|
+
"Conversely, single-provider authentication (auth.provider) supports role lists only. Referencing a named policy (authPolicy.policy, read/write names, or a named auth.authorization.defaultPolicy) blocks with auth-named-policy-requires-named-scheme; add a named scheme first.",
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "references",
|
|
121
|
+
required: false,
|
|
122
|
+
description:
|
|
123
|
+
"Explicit foreign keys used by generated UI lookups. Without it, a string field named <model>Id is treated as a foreign key only when shared/models contains that model (userId -> User only if user.ts exists). Map a field to false to disable inference. References to missing models are ignored with a reference-model-not-found warning.",
|
|
124
|
+
format: "export const references = { authorId: 'User', legacyId: false };",
|
|
125
|
+
notes: ["Only single string id fields can reference a model.", "No lookup UI, fetch, or OpenAPI reference is generated for fields that do not reference an existing model."],
|
|
111
126
|
},
|
|
112
127
|
{
|
|
113
128
|
name: "connectorConfig",
|
|
@@ -174,15 +189,24 @@ export function inspectCapabilities(): CapabilitiesContract {
|
|
|
174
189
|
],
|
|
175
190
|
notGuaranteed: [
|
|
176
191
|
"Owner scoping: generated CRUD does NOT restrict rows to the authenticated principal. Any authenticated caller passing the policy can read/write any document.",
|
|
192
|
+
"Without authentication, plan scaffold reports user-scoped-data-without-auth when the partition key or an owner-like field (userId, learnerId, ownerId, ...) suggests per-user data.",
|
|
177
193
|
],
|
|
178
194
|
guidance: [
|
|
179
|
-
"For multi-user data where users may only touch their own records, add ai-authored custom endpoints that derive the scoping key (e.g. learnerId) from the verified principal — never from the request body — and restrict generated write endpoints to admin roles or disable them.",
|
|
195
|
+
"Configure authentication via plan/apply auth before declaring authPolicy. For multi-user data where users may only touch their own records, add ai-authored custom endpoints that derive the scoping key (e.g. learnerId) from the verified principal — never from the request body — and restrict generated write endpoints to admin roles or disable them.",
|
|
180
196
|
],
|
|
181
197
|
},
|
|
182
198
|
sharedModels: {
|
|
183
199
|
idFieldRule: "id: z.string() (required). createdAt/updatedAt: z.string().optional(). The backend owns their values.",
|
|
200
|
+
nativeSchemaMapping: [
|
|
201
|
+
"C#/Python schema assets derive types from Zod, never from field names: z.string() -> string/str (including createdAt/updatedAt).",
|
|
202
|
+
"Date types only when declared: z.iso.datetime() -> DateTime/datetime, z.iso.date() -> DateOnly/date, z.date() -> DateTime/datetime.",
|
|
203
|
+
"z.number() -> double / float|int; z.number().int() or z.int() -> long / int.",
|
|
204
|
+
"Inline z.object({...}) fields become named classes <Model><Field> (e.g. ProbeItemNested); imported model schemas keep their own class.",
|
|
205
|
+
"min/max/length/nonempty/regex/int/gt/gte/lt/lte/positive/nonnegative and array min/max are enforced by C# IValidatableObject.Validate and Python Field bounds/validators. Regexes use search semantics like Zod.",
|
|
206
|
+
"String formats (email/uuid/url), refinements, and transforms are not re-implemented natively; the BFF Zod schemas remain the authoritative validation.",
|
|
207
|
+
],
|
|
184
208
|
buildNote:
|
|
185
|
-
"verify typecheck resolves the shared package from its built dist/. SwallowKit rebuilds shared automatically during verify; when typechecking manually, build
|
|
209
|
+
"create-model and plan/apply scaffold append missing model exports to shared/index.ts, including manually authored models. Manual exports are allowed (no markers); existing content is preserved. verify typecheck resolves the shared package from its built dist/. SwallowKit rebuilds shared automatically during verify; when typechecking manually, build shared first.",
|
|
186
210
|
},
|
|
187
211
|
seeding: {
|
|
188
212
|
createTemplates: "swallowkit create-dev-seeds <environment> — writes dev-seeds/<environment>/<model>.json templates.",
|
|
@@ -193,15 +217,18 @@ export function inspectCapabilities(): CapabilitiesContract {
|
|
|
193
217
|
"inspect project | entities | routes | artifacts | boundaries | infra | drift | capabilities",
|
|
194
218
|
"validate project",
|
|
195
219
|
"generate model <names...> | generate scaffold <model>",
|
|
196
|
-
"plan scaffold <models...> | plan auth --provider <p> [--scheme <name>] [--allowed-providers <csv>] | plan provision -g <rg> --location <loc> --swa-location <loc> [--adopt-existing --baseline 0 --what-if] [--reconcile --what-if]",
|
|
197
|
-
"apply scaffold [models...] --plan <id> [--approve] | apply auth --plan <id> [--approve] | apply provision --plan <id> --approve",
|
|
220
|
+
"plan scaffold <models...> [--api-only] [--skip-infra] | plan auth --provider <p> [--scheme <name>] [--allowed-providers <csv>] | plan provision -g <rg> --location <loc> --swa-location <loc> [--adopt-existing --baseline 0 --what-if] [--reconcile --what-if]",
|
|
221
|
+
"apply scaffold [models...] --plan <id> [--approve] [--skip-infra] | apply auth --plan <id> [--approve] | apply provision --plan <id> --approve",
|
|
198
222
|
"verify project [--checks <ids>] [--compact]",
|
|
199
223
|
"explain failure [--check <id>]",
|
|
224
|
+
"(regular CLI) migrations add-model <model> [--dry-run] — generate only the container migration after scaffold --skip-infra",
|
|
225
|
+
"(regular CLI) configure-mcp [--version auto|latest|<semver>] — re-select the MCP launcher version in .mcp.json",
|
|
200
226
|
],
|
|
201
227
|
verifyChecks: {
|
|
202
|
-
defaultChecks: ["structure", "drift", "typecheck"],
|
|
228
|
+
defaultChecks: ["structure", "drift", "typecheck", "backend-build"],
|
|
203
229
|
optInChecks: ["build", "lint", "test"],
|
|
204
230
|
customChecks: "swallowkit.config verify.checks: [{ id, command, title?, timeoutMs? }]",
|
|
231
|
+
backendBuild: "Runs dotnet build in functions/ (C#), the project tsc --noEmit (TypeScript), or Python 3 compileall (syntax only, using functions/.venv before PATH). Missing toolchains are skip with a reason, not proof of validation. Root build scripts do not replace backend-build; use --checks \"structure,drift,typecheck,backend-build,build\" for both.",
|
|
205
232
|
},
|
|
206
233
|
};
|
|
207
234
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project-scoped MCP launcher version management.
|
|
3
|
+
*
|
|
4
|
+
* `.mcp.json` intentionally resolves `swallowkit@latest` so that projects created
|
|
5
|
+
* with older releases still get the current stable tools. A prerelease project can
|
|
6
|
+
* be newer than `latest`; in that case the launcher is pinned to the project
|
|
7
|
+
* version until a stable release that understands project-aware delegation catches up.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { spawnSync } from "child_process";
|
|
11
|
+
import * as fs from "fs";
|
|
12
|
+
import * as os from "os";
|
|
13
|
+
import * as path from "path";
|
|
14
|
+
import { compareSemver, isPrerelease, parseSemver } from "../../utils/semver";
|
|
15
|
+
|
|
16
|
+
export const MCP_CONFIG_PATH = ".mcp.json";
|
|
17
|
+
export const MCP_VERSION_ENV = "SWALLOWKIT_MCP_VERSION";
|
|
18
|
+
export const MCP_LATEST = "latest";
|
|
19
|
+
|
|
20
|
+
export interface McpPinDecision {
|
|
21
|
+
version: string;
|
|
22
|
+
reason: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Decide the SWALLOWKIT_MCP_VERSION value for a project that uses `projectVersion`.
|
|
27
|
+
* Uses `latest` unless the project version is newer than the published `latest`.
|
|
28
|
+
* When the registry could not be reached, prereleases are pinned conservatively.
|
|
29
|
+
*/
|
|
30
|
+
export function resolveMcpPinVersion(projectVersion: string, publishedLatest: string | null): McpPinDecision {
|
|
31
|
+
if (!parseSemver(projectVersion)) {
|
|
32
|
+
return { version: MCP_LATEST, reason: `Project version ${projectVersion} is not a valid semantic version.` };
|
|
33
|
+
}
|
|
34
|
+
if (publishedLatest && parseSemver(publishedLatest)) {
|
|
35
|
+
const comparison = compareSemver(projectVersion, publishedLatest)!;
|
|
36
|
+
return comparison > 0
|
|
37
|
+
? { version: projectVersion, reason: `Project version ${projectVersion} is newer than published latest ${publishedLatest}.` }
|
|
38
|
+
: { version: MCP_LATEST, reason: `Published latest ${publishedLatest} is the same as or newer than project version ${projectVersion}.` };
|
|
39
|
+
}
|
|
40
|
+
return isPrerelease(projectVersion)
|
|
41
|
+
? { version: projectVersion, reason: `Published latest is unknown; prerelease ${projectVersion} is pinned so MCP matches the project.` }
|
|
42
|
+
: { version: MCP_LATEST, reason: "Published latest is unknown; stable projects keep latest." };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function lookupPublishedLatestVersion(packageName: string, timeoutMs = 15000): string | null {
|
|
46
|
+
// Run outside the project so its devEngines/packageManager policy does not reject npm.
|
|
47
|
+
const result = spawnSync("npm", ["view", `${packageName}@latest`, "version"], {
|
|
48
|
+
cwd: os.tmpdir(),
|
|
49
|
+
encoding: "utf8",
|
|
50
|
+
timeout: timeoutMs,
|
|
51
|
+
shell: process.platform === "win32",
|
|
52
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
53
|
+
});
|
|
54
|
+
if (result.error || result.status !== 0) return null;
|
|
55
|
+
const version = String(result.stdout).trim().split(/\s+/).pop() ?? "";
|
|
56
|
+
return parseSemver(version) ? version : null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function readMcpConfigVersion(projectDir: string): string | null {
|
|
60
|
+
const configPath = path.join(projectDir, MCP_CONFIG_PATH);
|
|
61
|
+
if (!fs.existsSync(configPath)) return null;
|
|
62
|
+
try {
|
|
63
|
+
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
64
|
+
const value = config?.mcpServers?.swallowkit?.env?.[MCP_VERSION_ENV];
|
|
65
|
+
return typeof value === "string" ? value : null;
|
|
66
|
+
} catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Update only the SwallowKit MCP version in .mcp.json, preserving all other content. */
|
|
72
|
+
export function writeMcpConfigVersion(projectDir: string, version: string): void {
|
|
73
|
+
const configPath = path.join(projectDir, MCP_CONFIG_PATH);
|
|
74
|
+
if (!fs.existsSync(configPath)) {
|
|
75
|
+
throw new Error(`${MCP_CONFIG_PATH} was not found. Run this command from a SwallowKit project root.`);
|
|
76
|
+
}
|
|
77
|
+
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
78
|
+
const server = config?.mcpServers?.swallowkit;
|
|
79
|
+
if (!server || typeof server !== "object") {
|
|
80
|
+
throw new Error(`${MCP_CONFIG_PATH} does not define mcpServers.swallowkit.`);
|
|
81
|
+
}
|
|
82
|
+
server.env = { ...(server.env ?? {}), [MCP_VERSION_ENV]: version };
|
|
83
|
+
fs.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`);
|
|
84
|
+
}
|
|
@@ -407,7 +407,7 @@ live in \`functions/local.settings.json\`. Keep their secrets out of source cont
|
|
|
407
407
|
\`\`\`sh
|
|
408
408
|
${pm} run build
|
|
409
409
|
${cmd.exec} swallowkit machine verify project
|
|
410
|
-
${cmd.exec} swallowkit machine verify project --checks structure,drift,typecheck,build
|
|
410
|
+
${cmd.exec} swallowkit machine verify project --checks "structure,drift,typecheck,backend-build,build"
|
|
411
411
|
\`\`\`
|
|
412
412
|
|
|
413
413
|
The build compiles shared schemas, checks the SPA, builds static assets, and
|
|
@@ -52,9 +52,23 @@ Goal: add a data model and derive CRUD/BFF/UI/infra deterministically.
|
|
|
52
52
|
1. Create the model file (deterministic template):
|
|
53
53
|
\`${runCmd} swallowkit machine generate model <name> --overwrite never\`
|
|
54
54
|
2. Edit \`shared/models/<name>.ts\` — add domain fields (free-form authoring).
|
|
55
|
+
- Native C#/Python types follow Zod, not names: \`z.iso.datetime()\` for dates, \`z.number().int()\` for integers.
|
|
56
|
+
- \`<model>Id\` fields reference a model only when it exists in \`shared/models\`; otherwise declare
|
|
57
|
+
\`export const references = { fieldId: 'Model' }\` (or \`false\` to opt out).
|
|
55
58
|
3. Compute the change plan (writes nothing):
|
|
56
59
|
\`${runCmd} swallowkit machine plan scaffold <name>\`
|
|
57
60
|
- \`status: "requires-human"\` → review \`data.conflicts\`; only proceed with \`--approve\` if overwriting is intended.
|
|
61
|
+
- Must not change Bicep/infrastructure? Add \`--skip-infra\` to plan and apply. Nothing under \`infra/\` changes and
|
|
62
|
+
the plan warns \`infra-skipped\`; later run \`${runCmd} swallowkit migrations add-model <name>\` to add only the container migration.
|
|
63
|
+
- Read \`data.warnings\`. \`user-scoped-data-without-auth\` means generated CRUD would expose every user's documents;
|
|
64
|
+
add auth (\`swallowkit-add-auth\`) and owner-scoped ai-authored endpoints before exposing the model.
|
|
65
|
+
- \`auth-policy-without-auth\` blocks generation before file writes: configure authentication with plan/apply auth,
|
|
66
|
+
then re-plan. Do not remove a required policy to bypass this prerequisite.
|
|
67
|
+
For named \`auth.schemes\`, define named authorization policies selecting schemes/roles and reference them from
|
|
68
|
+
\`authPolicy.policy\` or read/write names; role-only declarations block with \`auth-policy-requires-named-policy\`.
|
|
69
|
+
Single-provider \`auth.provider\` supports role lists only; named policies block with \`auth-named-policy-requires-named-scheme\`.
|
|
70
|
+
- Scaffold appends missing exports to \`shared/index.ts\` for hand-authored models too.
|
|
71
|
+
Manual exports are allowed; no managed markers exist in that file.
|
|
58
72
|
4. Apply:
|
|
59
73
|
\`${runCmd} swallowkit machine apply scaffold --plan <planId>\`
|
|
60
74
|
5. Verify:
|
|
@@ -153,7 +167,7 @@ the scoping key from the verified principal, never from the request body.
|
|
|
153
167
|
title: "Verify and repair loop",
|
|
154
168
|
skillName: "swallowkit-verify-repair",
|
|
155
169
|
skillDescription:
|
|
156
|
-
"Converge a SwallowKit project to a verified state: run structure/drift/typecheck (and build/lint/test) checks, read evidence with explain failure, repair, and repeat. Use after any code or schema change, when verification fails, when the build/lint/tests are broken, or before finishing a task.",
|
|
170
|
+
"Converge a SwallowKit project to a verified state: run structure/drift/typecheck/backend-build (and build/lint/test) checks, read evidence with explain failure, repair, and repeat. Use after any code or schema change, when verification fails, when the build/lint/tests are broken, or before finishing a task.",
|
|
157
171
|
content: `# Workflow: Verify and repair
|
|
158
172
|
|
|
159
173
|
Goal: converge the project to a verified state after any change.
|
|
@@ -161,14 +175,16 @@ Goal: converge the project to a verified state after any change.
|
|
|
161
175
|
## Loop
|
|
162
176
|
|
|
163
177
|
1. \`${runCmd} swallowkit machine verify project\`
|
|
164
|
-
- default checks: structure, drift, typecheck (+ project-specific checks from swallowkit.config \`verify.checks\`)
|
|
165
|
-
-
|
|
178
|
+
- default checks: structure, drift, typecheck, backend-build (+ project-specific checks from swallowkit.config \`verify.checks\`)
|
|
179
|
+
- backend-build: standalone C# \`dotnet build\`, TypeScript \`tsc --noEmit\`, Python 3 \`compileall\` (syntax only).
|
|
180
|
+
Missing toolchains are skipped with a reason, not proof of a working backend. Restore them and re-run.
|
|
181
|
+
- opt-in heavier checks: \`--checks "structure,drift,typecheck,backend-build,build,lint,test"\` (quote CSV in PowerShell)
|
|
166
182
|
2. If \`summary.done\` is false:
|
|
167
183
|
- \`${runCmd} swallowkit machine explain failure\` → evidence (logTail, findings, violations) and suggestedActions per check.
|
|
168
184
|
- Repair:
|
|
169
185
|
- \`drift\` failures → follow each finding's \`repairAction\` (usually re-run plan/apply scaffold).
|
|
170
186
|
- \`structure\` failures → follow \`suggestedFix\` per violation.
|
|
171
|
-
- \`typecheck\`/\`build\`/\`lint\`/\`test\` failures → fix the code
|
|
187
|
+
- \`typecheck\`/\`backend-build\`/\`build\`/\`lint\`/\`test\` failures → fix the source code, not generated artifacts.
|
|
172
188
|
3. Repeat until \`summary.done: true\`.
|
|
173
189
|
|
|
174
190
|
## Exit criteria
|
|
@@ -247,7 +263,9 @@ under \`.github/skills/\` so skills-aware agents load them automatically.
|
|
|
247
263
|
|
|
248
264
|
- **ai-authored** (write freely): \`shared/models/\`, business logic, custom pages/components, tests.
|
|
249
265
|
- **deterministic** (never hand-edit): artifacts generated by SwallowKit (see \`.swallowkit/artifacts.json\`) and \`.swallowkit/\` metadata. Change models/config and regenerate via plan/apply.
|
|
250
|
-
- **shared
|
|
266
|
+
- **shared**: \`shared/index.ts\` allows manual exports (no markers; SwallowKit appends missing entries).
|
|
267
|
+
For Python \`functions/function_app.py\`, edit outside the registration marker.
|
|
268
|
+
- **infrastructure**: baseline \`infra/\` files are checksum-locked by \`infra/migrations/manifest.json\`; add resources as new migrations (\`swallowkit create-migration <slug>\`, \`swallowkit migrations add-model <model>\`).
|
|
251
269
|
|
|
252
270
|
Full machine-readable contract: \`${runCmd} swallowkit machine inspect boundaries\`
|
|
253
271
|
`,
|
|
@@ -117,8 +117,7 @@ export function generateNamedAuthRouterCSharp(config: NormalizedAuthConfig): str
|
|
|
117
117
|
using System.Text;
|
|
118
118
|
using System.Text.Json;
|
|
119
119
|
using Microsoft.Azure.Functions.Worker.Http;
|
|
120
|
-
using Functions.Auth.Schemes;
|
|
121
|
-
namespace Functions.Auth;
|
|
120
|
+
${externalCases ? "using Functions.Auth.Schemes;\n" : ""}namespace Functions.Auth;
|
|
122
121
|
public record AuthPrincipal(string Subject, string Scheme, string Issuer, string[] Roles, IReadOnlyDictionary<string, object?> Claims)
|
|
123
122
|
{
|
|
124
123
|
[Obsolete("Use Subject")] public string UserId => Subject;
|
|
@@ -171,15 +170,15 @@ ${externalCases}
|
|
|
171
170
|
export function generateNamedAuthRouterPython(config: NormalizedAuthConfig): string {
|
|
172
171
|
const external = Object.entries(config.schemes).filter(([,s])=>s.provider === "external-token");
|
|
173
172
|
const imports = external.map(([n])=>`from auth.schemes.${schemeSlug(n).replace(/-/g,"_")}.verifier import verify_external_token as verify_${safeIdentifier(n)}, ExternalTokenVerificationError as Error_${safeIdentifier(n)}`).join("\n");
|
|
174
|
-
const cases = external.map(([n], index)=>`
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
173
|
+
const cases = external.map(([n], index)=>` ${index === 0 ? "if" : "elif"} scheme == ${JSON.stringify(n)}:
|
|
174
|
+
try:
|
|
175
|
+
value = verify_${safeIdentifier(n)}(bearer)
|
|
176
|
+
except Error_${safeIdentifier(n)} as exc:
|
|
177
|
+
raise AuthError(503 if exc.identity_provider_unavailable else 401, "Identity provider unavailable" if exc.identity_provider_unavailable else "Invalid token")
|
|
178
|
+
except Exception:
|
|
179
|
+
raise AuthError(503, "External token verifier unavailable")
|
|
180
|
+
if not value.get("subject") or not isinstance(value.get("roles"), list): raise AuthError(401, "Invalid external principal")
|
|
181
|
+
principal = {"subject": value["subject"], "scheme": scheme, "issuer": value.get("issuer", scheme), "roles": value["roles"], "claims": value.get("claims", {}), "userId": value["subject"]}`).join("\n");
|
|
183
182
|
return `import base64
|
|
184
183
|
import json
|
|
185
184
|
import azure.functions as func
|
|
@@ -199,14 +198,14 @@ def require_auth(req: func.HttpRequest, policy_name: str):
|
|
|
199
198
|
if len(candidates) != 1: raise AuthError(401, "Authentication required" if not candidates else "Ambiguous credentials")
|
|
200
199
|
scheme = candidates[0]
|
|
201
200
|
${cases}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
201
|
+
${external.length ? "elif" : "if"} PROVIDERS[scheme] == "swa":
|
|
202
|
+
try:
|
|
203
|
+
value=json.loads(base64.b64decode(swa).decode("utf-8")); roles=[r for r in value.get("userRoles",[]) if isinstance(r,str)]
|
|
204
|
+
if not value.get("userId") or "authenticated" not in roles: raise ValueError()
|
|
205
|
+
if ALLOWED_PROVIDERS[scheme] and value.get("identityProvider") not in ALLOWED_PROVIDERS[scheme]: raise ValueError()
|
|
206
|
+
principal={"subject":value["userId"],"scheme":scheme,"issuer":"swa:"+value.get("identityProvider", "unknown"),"roles":roles,"claims":value,"userId":value["userId"]}
|
|
207
|
+
except Exception: raise AuthError(401,"Invalid SWA client principal")
|
|
208
|
+
else: raise AuthError(401,"Authentication adapter is not configured")
|
|
210
209
|
require_roles(principal, policy.get("roles", [])); return principal
|
|
211
210
|
def require_roles(principal, roles):
|
|
212
211
|
if roles and not any(role in principal.get("roles",[]) for role in roles): raise AuthError(403,"Insufficient permissions")
|