@sdxc/kit 2026.10.21 → 2026.10.24

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 (113) hide show
  1. package/README.md +84 -4
  2. package/changelog.jsonl +168 -0
  3. package/config.schema.json +154 -0
  4. package/dist/architecture/complexity.d.ts +73 -0
  5. package/dist/architecture/complexity.js +185 -0
  6. package/dist/architecture/crap.d.ts +62 -0
  7. package/dist/architecture/crap.js +121 -0
  8. package/dist/architecture/graph.d.ts +55 -0
  9. package/dist/architecture/graph.js +194 -0
  10. package/dist/architecture/layers.d.ts +29 -0
  11. package/dist/architecture/layers.js +81 -0
  12. package/dist/architecture/mermaid.d.ts +20 -0
  13. package/dist/architecture/mermaid.js +51 -0
  14. package/dist/cli.js +9 -0
  15. package/dist/commands/create.js +4 -3
  16. package/dist/commands/deploy.js +10 -9
  17. package/dist/commands/destroy.d.ts +1 -1
  18. package/dist/commands/diagram.d.ts +17 -0
  19. package/dist/commands/diagram.js +45 -0
  20. package/dist/commands/fix.d.ts +69 -0
  21. package/dist/commands/fix.js +102 -0
  22. package/dist/commands/make.d.ts +71 -2
  23. package/dist/commands/make.js +46 -0
  24. package/dist/commands/run.d.ts +15 -11
  25. package/dist/commands/run.js +21 -16
  26. package/dist/commands/scaffold.d.ts +1 -1
  27. package/dist/commands/setup.d.ts +26 -0
  28. package/dist/commands/setup.js +33 -0
  29. package/dist/config.d.ts +52 -0
  30. package/dist/config.js +88 -1
  31. package/dist/contract.d.ts +52 -3
  32. package/dist/contract.js +124 -2
  33. package/dist/dependencies.js +7 -1
  34. package/dist/deploy/plan.d.ts +5 -0
  35. package/dist/deploy/plan.js +10 -0
  36. package/dist/destroy.js +13 -6
  37. package/dist/diagram.d.ts +32 -0
  38. package/dist/diagram.js +47 -0
  39. package/dist/doctor/checks.d.ts +2 -1
  40. package/dist/doctor/checks.js +24 -1
  41. package/dist/doctor/complexity.d.ts +13 -0
  42. package/dist/doctor/complexity.js +52 -0
  43. package/dist/doctor/crap.d.ts +14 -0
  44. package/dist/doctor/crap.js +67 -0
  45. package/dist/doctor/dependencies.d.ts +13 -0
  46. package/dist/doctor/dependencies.js +42 -0
  47. package/dist/doctor/duplication.d.ts +19 -0
  48. package/dist/doctor/duplication.js +106 -0
  49. package/dist/doctor/fan-out.d.ts +12 -0
  50. package/dist/doctor/fan-out.js +42 -0
  51. package/dist/doctor/feature-scatter.d.ts +15 -0
  52. package/dist/doctor/feature-scatter.js +84 -0
  53. package/dist/doctor/module-size.d.ts +13 -0
  54. package/dist/doctor/module-size.js +50 -0
  55. package/dist/doctor/mutation.d.ts +20 -0
  56. package/dist/doctor/mutation.js +97 -0
  57. package/dist/doctor/orphans.d.ts +13 -0
  58. package/dist/doctor/orphans.js +50 -0
  59. package/dist/doctor/project.js +8 -5
  60. package/dist/doctor/result-throws.d.ts +17 -0
  61. package/dist/doctor/result-throws.js +72 -0
  62. package/dist/doctor/test-ratio.d.ts +12 -0
  63. package/dist/doctor/test-ratio.js +31 -0
  64. package/dist/fix/commands.d.ts +37 -0
  65. package/dist/fix/commands.js +63 -0
  66. package/dist/fix/emails.d.ts +21 -0
  67. package/dist/fix/emails.js +159 -0
  68. package/dist/fix/env.d.ts +29 -0
  69. package/dist/fix/env.js +58 -0
  70. package/dist/fix/index.d.ts +11 -0
  71. package/dist/fix/index.js +11 -0
  72. package/dist/fix/models.d.ts +20 -0
  73. package/dist/fix/models.js +95 -0
  74. package/dist/lock.js +12 -2
  75. package/dist/make/binding.d.ts +42 -0
  76. package/dist/make/binding.js +237 -0
  77. package/dist/make/imports.js +7 -5
  78. package/dist/make/schema-diff.js +8 -1
  79. package/dist/models.js +7 -7
  80. package/dist/routes/modules.js +8 -5
  81. package/dist/routes/parse.js +8 -7
  82. package/dist/routes/routers.js +9 -5
  83. package/dist/setup/auth.d.ts +12 -0
  84. package/dist/setup/auth.js +209 -0
  85. package/dist/setup/billing.d.ts +11 -0
  86. package/dist/setup/billing.js +116 -0
  87. package/dist/setup/catalog.d.ts +25 -0
  88. package/dist/setup/catalog.js +34 -0
  89. package/dist/setup/credit.d.ts +13 -0
  90. package/dist/setup/credit.js +21 -0
  91. package/dist/setup/flags.d.ts +11 -0
  92. package/dist/setup/flags.js +62 -0
  93. package/dist/setup/index.d.ts +25 -0
  94. package/dist/setup/index.js +53 -0
  95. package/dist/setup/plan.d.ts +38 -0
  96. package/dist/setup/plan.js +62 -0
  97. package/dist/testing.js +3 -3
  98. package/dist/ui/layout.js +1 -1
  99. package/dist/ui/registry.d.ts +2 -2
  100. package/dist/upgrade/project.d.ts +2 -2
  101. package/dist/upgrade/prompt.js +7 -5
  102. package/package.json +11 -8
  103. package/registry/ui/attachment.json +2 -2
  104. package/registry/ui/breadcrumbs.json +6 -3
  105. package/registry/ui/group.json +6 -3
  106. package/registry/ui/link-button.json +3 -3
  107. package/registry/ui/link.json +6 -3
  108. package/registry/ui/nav-link.json +6 -3
  109. package/registry/ui/navigation-menu.json +6 -3
  110. package/registry/ui/pagination.json +3 -3
  111. package/registry/ui/sidebar.json +3 -3
  112. package/templates/app/AGENTS.md +14 -1
  113. package/templates/app/package.json +1 -1
@@ -0,0 +1,209 @@
1
+ /**
2
+ * `sdxc setup auth`: OIDC relying-party wiring against r3-auth (default), reduced to the
3
+ * template's session/`actor` world — initializer, middleware, controllers, routes, secrets and
4
+ * a `signIn()` test helper.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { failure, isFailure, success } from "@sdxc/result";
10
+ import { CONFIG_FILE, ENV_EXAMPLE_FILE, declaredBindings, exampleKeys } from "../doctor/env.js";
11
+ import { creditSetupFiles } from "./credit.js";
12
+ import { readProjectFile } from "./plan.js";
13
+ /** Builds the auth setup plan for `provider` (currently only `r3-auth`). */
14
+ export async function planAuth(root, provider) {
15
+ if (provider !== "r3-auth") {
16
+ return failure(new Error(`Unknown auth provider "${provider}"; this release ships r3-auth only`));
17
+ }
18
+ let config = await readProjectFile(root, CONFIG_FILE);
19
+ if (isFailure(config))
20
+ return config;
21
+ let example = await readProjectFile(root, ENV_EXAMPLE_FILE);
22
+ let exampleText = isFailure(example) ? "" : example.data;
23
+ let bindings = declaredBindings(config.data);
24
+ let listed = exampleKeys(exampleText);
25
+ let secrets = ["CLIENT_ID", "CLIENT_SECRET"];
26
+ let configAfter = config.data;
27
+ let exampleAfter = exampleText;
28
+ let edits = [];
29
+ for (let key of secrets) {
30
+ if (!bindings.has(key)) {
31
+ let inserted = insertSecret(configAfter, key);
32
+ if (isFailure(inserted))
33
+ return inserted;
34
+ configAfter = inserted.data;
35
+ }
36
+ if (!listed.has(key)) {
37
+ if (exampleAfter === "")
38
+ exampleAfter = `${key}=\n`;
39
+ else if (exampleAfter.endsWith("\n"))
40
+ exampleAfter = `${exampleAfter}${key}=\n`;
41
+ else
42
+ exampleAfter = `${exampleAfter}\n${key}=\n`;
43
+ }
44
+ }
45
+ if (configAfter !== config.data) {
46
+ edits.push({ path: CONFIG_FILE, before: config.data, after: configAfter });
47
+ }
48
+ if (exampleAfter !== exampleText) {
49
+ edits.push({
50
+ path: ENV_EXAMPLE_FILE,
51
+ before: exampleText,
52
+ after: exampleAfter,
53
+ });
54
+ }
55
+ let files = await creditSetupFiles(root, [
56
+ { path: "app/initializers/issuer.ts", content: ISSUER },
57
+ { path: "app/initializers/relying-party.ts", content: RELYING_PARTY },
58
+ { path: "app/http/middleware/auth.ts", content: AUTH_MIDDLEWARE },
59
+ { path: "app/http/controllers/auth.tsx", content: AUTH_CONTROLLER },
60
+ { path: "routes/auth.ts", content: AUTH_ROUTES },
61
+ { path: "app/test/session.ts", content: SESSION_HELPER },
62
+ ]);
63
+ return success({
64
+ feature: "auth",
65
+ provider,
66
+ files,
67
+ edits,
68
+ dependencies: ["@sdxc/auth", "@sdxc/jwt"],
69
+ notes: [
70
+ "Map routes/auth.ts in the web router with lazy(() => import(…)).",
71
+ "Point app/initializers/issuer.ts at your r3-auth deployment.",
72
+ "Add CLIENT_ID / CLIENT_SECRET to the issuer's client registration.",
73
+ "Run sdxc run typegen after the secrets land.",
74
+ "Fill signIn() / mapProfile once the local account model exists.",
75
+ ],
76
+ });
77
+ }
78
+ function insertSecret(source, key) {
79
+ let env = /env\s*:\s*\{/.exec(source);
80
+ if (env === null || env.index === undefined) {
81
+ return failure(new Error(`${CONFIG_FILE} has no env: { … } block to edit`));
82
+ }
83
+ let start = env.index + env[0].length;
84
+ return success(`${source.slice(0, start)}\n\t\t\t${key}: bindings.secret(),${source.slice(start)}`);
85
+ }
86
+ const ISSUER = `/**
87
+ * The OpenID Connect issuer this app trusts — the r3-auth deployment that issues ID tokens.
88
+ */
89
+
90
+ import { Issuer } from "@sdxc/auth/issuer";
91
+
92
+ /** The issuer URL; replace with the r3-auth origin before the first login. */
93
+ const ISSUER_URL = "https://auth.example.com";
94
+
95
+ /** The issuer every relying-party login verifies tokens against. */
96
+ export function issuer(): Issuer {
97
+ return new Issuer(new URL(ISSUER_URL));
98
+ }
99
+ `;
100
+ const RELYING_PARTY = `/**
101
+ * The confidential OIDC client that signs a visitor in: authorization redirect, callback that
102
+ * verifies the ID token, provider logout, and the session scheme auth middleware resolves.
103
+ */
104
+
105
+ import { RelyingParty } from "@sdxc/auth/relying-party";
106
+ import { JWK } from "@sdxc/jwt";
107
+
108
+ import { getEnv } from "~/app/http/middleware/env";
109
+ import { issuer } from "~/app/initializers/issuer";
110
+ import routes from "~/routes/auth";
111
+
112
+ /**
113
+ * The client for the request's own origin. Replace the issuer URL with the r3-auth deployment
114
+ * this app registers against, and map verified claims onto the local session actor.
115
+ *
116
+ * @param url - The current request URL the callback is built against.
117
+ */
118
+ export function relyingParty(url: URL | string): RelyingParty<{ id: string }> {
119
+ return new RelyingParty<{ id: string }>(issuer(), {
120
+ clientId: getEnv("CLIENT_ID"),
121
+ clientSecret: getEnv("CLIENT_SECRET"),
122
+ redirectUri: new URL(routes.callback.href(), url),
123
+ clientAuth: "client_secret_basic",
124
+ algorithms: [JWK.Algorithm.ES256],
125
+ fallbackReturnTo: "/",
126
+ mapProfile(claims) {
127
+ let subject = typeof claims.sub === "string" ? claims.sub : null;
128
+ if (subject === null) throw new Error("ID token is missing sub");
129
+ return { id: subject };
130
+ },
131
+ });
132
+ }
133
+ `;
134
+ const AUTH_MIDDLEWARE = `/**
135
+ * Session helpers for the relying party: whether a visitor is signed in, and the login /
136
+ * logout actions controllers call.
137
+ */
138
+
139
+ import { getContext } from "remix/middleware/async-context";
140
+
141
+ /** Whether the current session holds an actor. */
142
+ export function isAuthenticated(): boolean {
143
+ let ctx = getContext<{ session: { get(key: string): unknown } }>();
144
+ return ctx.session.get("actor") != null;
145
+ }
146
+
147
+ /** Stores \`actor\` on the session after a successful callback. */
148
+ export function login(actor: { id: string }): void {
149
+ let ctx = getContext<{ session: { set(key: string, value: unknown): void } }>();
150
+ ctx.session.set("actor", actor);
151
+ }
152
+
153
+ /** Clears the session actor on logout. */
154
+ export function logout(): void {
155
+ let ctx = getContext<{ session: { unset(key: string): void } }>();
156
+ ctx.session.unset("actor");
157
+ }
158
+ `;
159
+ const AUTH_CONTROLLER = `/**
160
+ * Login, callback and logout controllers for the OIDC relying party. Fill the views and the
161
+ * return-path helpers for the app's own routes.
162
+ */
163
+
164
+ import { contextOf } from "@sdxc/auth/remix/context";
165
+ import { redirect } from "@sdxc/http/response";
166
+ import { createController } from "remix/router";
167
+
168
+ import { isAuthenticated, login, logout } from "~/app/http/middleware/auth";
169
+ import { relyingParty } from "~/app/initializers/relying-party";
170
+ import routes from "~/routes/auth";
171
+
172
+ /** Starts the authorization-code flow, or sends an already-signed-in visitor home. */
173
+ export default createController({
174
+ async login(ctx) {
175
+ if (isAuthenticated()) return redirect("/", { status: redirect.Status.SeeOther });
176
+ return relyingParty(ctx.url).authorize(contextOf(ctx));
177
+ },
178
+ async callback(ctx) {
179
+ let grant = await relyingParty(ctx.url).callback(contextOf(ctx));
180
+ login(grant.profile);
181
+ return redirect("/", { status: redirect.Status.SeeOther });
182
+ },
183
+ async logout(ctx) {
184
+ logout();
185
+ return relyingParty(ctx.url).logout(contextOf(ctx), { postLogoutRedirectUri: routes.login.href() });
186
+ },
187
+ });
188
+ `;
189
+ const AUTH_ROUTES = `/**
190
+ * Auth routes the relying-party controllers answer: login, callback and logout.
191
+ */
192
+
193
+ import { get, routes } from "remix/routes";
194
+
195
+ export default routes({
196
+ login: get("/login"),
197
+ callback: get("/auth/callback"),
198
+ logout: get("/logout"),
199
+ });
200
+ `;
201
+ const SESSION_HELPER = `/**
202
+ * Test helper that signs a visitor in by setting the session actor the auth middleware reads.
203
+ */
204
+
205
+ /** Puts \`actor\` on the test session the way a completed login would. */
206
+ export function signIn(session: { set(key: string, value: unknown): void }, actor = { id: "user_test" }): void {
207
+ session.set("actor", actor);
208
+ }
209
+ `;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `sdxc setup billing`: `@sdxc/billing` provider initializer, webhook route stub, checkout
3
+ * secrets and an empty product catalog.
4
+ *
5
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
6
+ * @copyright Sergio Xalambrí 2026
7
+ */
8
+ import type { Result } from "@sdxc/result";
9
+ import type { SetupPlan } from "./plan.js";
10
+ /** Builds the billing setup plan for `provider` (currently only `polar`). */
11
+ export declare function planBilling(root: string, provider: string): Promise<Result<SetupPlan, Error>>;
@@ -0,0 +1,116 @@
1
+ /**
2
+ * `sdxc setup billing`: `@sdxc/billing` provider initializer, webhook route stub, checkout
3
+ * secrets and an empty product catalog.
4
+ *
5
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
6
+ * @copyright Sergio Xalambrí 2026
7
+ */
8
+ import { failure, isFailure, success } from "@sdxc/result";
9
+ import { CONFIG_FILE, ENV_EXAMPLE_FILE, declaredBindings, exampleKeys } from "../doctor/env.js";
10
+ import { creditSetupFiles } from "./credit.js";
11
+ import { readProjectFile } from "./plan.js";
12
+ /** Builds the billing setup plan for `provider` (currently only `polar`). */
13
+ export async function planBilling(root, provider) {
14
+ if (provider !== "polar") {
15
+ return failure(new Error(`Unknown billing provider "${provider}"; this release ships polar only`));
16
+ }
17
+ let config = await readProjectFile(root, CONFIG_FILE);
18
+ if (isFailure(config))
19
+ return config;
20
+ let example = await readProjectFile(root, ENV_EXAMPLE_FILE);
21
+ let exampleText = isFailure(example) ? "" : example.data;
22
+ let bindings = declaredBindings(config.data);
23
+ let listed = exampleKeys(exampleText);
24
+ let secrets = ["POLAR_ACCESS_TOKEN", "POLAR_WEBHOOK_SECRET"];
25
+ let configAfter = config.data;
26
+ let exampleAfter = exampleText;
27
+ let edits = [];
28
+ for (let key of secrets) {
29
+ if (!bindings.has(key)) {
30
+ let env = /env\s*:\s*\{/.exec(configAfter);
31
+ if (env === null || env.index === undefined) {
32
+ return failure(new Error(`${CONFIG_FILE} has no env: { … } block to edit`));
33
+ }
34
+ let start = env.index + env[0].length;
35
+ configAfter = `${configAfter.slice(0, start)}\n\t\t\t${key}: bindings.secret(),${configAfter.slice(start)}`;
36
+ }
37
+ if (!listed.has(key)) {
38
+ if (exampleAfter === "")
39
+ exampleAfter = `${key}=\n`;
40
+ else if (exampleAfter.endsWith("\n"))
41
+ exampleAfter = `${exampleAfter}${key}=\n`;
42
+ else
43
+ exampleAfter = `${exampleAfter}\n${key}=\n`;
44
+ }
45
+ }
46
+ if (configAfter !== config.data) {
47
+ edits.push({ path: CONFIG_FILE, before: config.data, after: configAfter });
48
+ }
49
+ if (exampleAfter !== exampleText) {
50
+ edits.push({ path: ENV_EXAMPLE_FILE, before: exampleText, after: exampleAfter });
51
+ }
52
+ let files = await creditSetupFiles(root, [
53
+ { path: "app/initializers/billing.ts", content: BILLING_INITIALIZER },
54
+ { path: "config/products.ts", content: PRODUCTS },
55
+ { path: "app/http/controllers/billing-webhook.ts", content: WEBHOOK },
56
+ ]);
57
+ return success({
58
+ feature: "billing",
59
+ provider,
60
+ files,
61
+ edits,
62
+ dependencies: ["@sdxc/billing"],
63
+ notes: [
64
+ "Map the webhook route and pass polar into the handlers that need it.",
65
+ "Replace the placeholder product ids in config/products.ts with Polar's.",
66
+ "Run sdxc run typegen after the secrets land.",
67
+ ],
68
+ });
69
+ }
70
+ const BILLING_INITIALIZER = `/**
71
+ * The billing platform this app sells through, configured once. Call sites name a product by
72
+ * our own slug; vendor ids live only here and in config/products.ts.
73
+ */
74
+
75
+ import { PolarBilling } from "@sdxc/billing/providers/polar";
76
+ import { env } from "cloudflare:workers";
77
+
78
+ import { PRODUCTS } from "~/config/products";
79
+
80
+ /** The billing platform, reached through the vendor-neutral contract. */
81
+ export const polar = new PolarBilling({
82
+ accessToken: () => env.POLAR_ACCESS_TOKEN,
83
+ webhookSecret: () => env.POLAR_WEBHOOK_SECRET,
84
+ products: PRODUCTS,
85
+ meters: {},
86
+ });
87
+ `;
88
+ const PRODUCTS = `/**
89
+ * Product slugs this app sells, mapped to the vendor's product ids. Fill the ids before the
90
+ * first checkout; call sites import the slug constants, never the vendor ids.
91
+ */
92
+
93
+ /** Our own name for the subscription sold, and the only product until more are added. */
94
+ export const DEFAULT_PRODUCT = "default";
95
+
96
+ /** Slug → Polar product id. Replace the placeholder before going live. */
97
+ export const PRODUCTS: Record<string, string> = {
98
+ [DEFAULT_PRODUCT]: "00000000-0000-4000-8000-000000000000",
99
+ };
100
+ `;
101
+ const WEBHOOK = `/**
102
+ * Polar webhook endpoint: verify the signature and hand the event to @sdxc/billing.
103
+ */
104
+
105
+ import { createController } from "remix/router";
106
+
107
+ import { polar } from "~/app/initializers/billing";
108
+
109
+ /** Accepts Polar webhook deliveries. */
110
+ export default createController({
111
+ async post(ctx) {
112
+ await polar.webhooks.handle(ctx.request);
113
+ return new Response(null, { status: 204 });
114
+ },
115
+ });
116
+ `;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Features `sdxc setup` can install: each row names what the plan wires, so agents discover
3
+ * the catalog the same way they discover `make` kinds.
4
+ *
5
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
6
+ * @copyright Sergio Xalambrí 2026
7
+ */
8
+ /** One feature this kit release knows how to set up. */
9
+ export interface SetupFeature {
10
+ /** The verb after `sdxc setup`, such as `auth`. */
11
+ name: string;
12
+ /** One sentence of what it wires. */
13
+ description: string;
14
+ /** Provider flag values this feature accepts; empty when it has none. */
15
+ providers: readonly string[];
16
+ /** Default `--provider` when the feature has providers. */
17
+ defaultProvider?: string;
18
+ }
19
+ /**
20
+ * Features shipped in this kit release. Further rows land only when their planner has a
21
+ * deterministic file list a test can assert.
22
+ */
23
+ export declare const SETUP_FEATURES: readonly SetupFeature[];
24
+ /** Looks up a feature by name, or `null` when this release does not ship it. */
25
+ export declare function setupFeature(name: string): SetupFeature | null;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Features `sdxc setup` can install: each row names what the plan wires, so agents discover
3
+ * the catalog the same way they discover `make` kinds.
4
+ *
5
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
6
+ * @copyright Sergio Xalambrí 2026
7
+ */
8
+ /**
9
+ * Features shipped in this kit release. Further rows land only when their planner has a
10
+ * deterministic file list a test can assert.
11
+ */
12
+ export const SETUP_FEATURES = [
13
+ {
14
+ name: "auth",
15
+ description: "OIDC relying party, login/callback/logout, client secrets, CSP formAction, signIn() helper",
16
+ providers: ["r3-auth"],
17
+ defaultProvider: "r3-auth",
18
+ },
19
+ {
20
+ name: "billing",
21
+ description: "@sdxc/billing provider, webhook route stub, portal/checkout secrets, empty product catalog",
22
+ providers: ["polar"],
23
+ defaultProvider: "polar",
24
+ },
25
+ {
26
+ name: "flags",
27
+ description: "@sdxc/flags + engine store, empty catalog, wide-event hook ready for router middleware",
28
+ providers: [],
29
+ },
30
+ ];
31
+ /** Looks up a feature by name, or `null` when this release does not ship it. */
32
+ export function setupFeature(name) {
33
+ return SETUP_FEATURES.find((feature) => feature.name === name) ?? null;
34
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Credits setup-written files the way `make` stubs do: `@author` / `@copyright` from the
3
+ * project's package.json `author` or git `user.name`, never a kit maintainer hardcoded in.
4
+ *
5
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
6
+ * @copyright Sergio Xalambrí 2026
7
+ */
8
+ import type { SetupFile } from "./plan.js";
9
+ /**
10
+ * Returns `files` with each module JSDoc closed by the project's author tags. A project with
11
+ * no resolvable author leaves the sources unchanged.
12
+ */
13
+ export declare function creditSetupFiles(root: string, files: readonly SetupFile[]): Promise<SetupFile[]>;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Credits setup-written files the way `make` stubs do: `@author` / `@copyright` from the
3
+ * project's package.json `author` or git `user.name`, never a kit maintainer hardcoded in.
4
+ *
5
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
6
+ * @copyright Sergio Xalambrí 2026
7
+ */
8
+ import { addHeaderTags, headerTags, resolveAuthor } from "../author.js";
9
+ /**
10
+ * Returns `files` with each module JSDoc closed by the project's author tags. A project with
11
+ * no resolvable author leaves the sources unchanged.
12
+ */
13
+ export async function creditSetupFiles(root, files) {
14
+ let tags = headerTags(await resolveAuthor(root));
15
+ if (tags === "")
16
+ return [...files];
17
+ return files.map((file) => ({
18
+ path: file.path,
19
+ content: addHeaderTags(file.content, tags),
20
+ }));
21
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `sdxc setup flags`: `@sdxc/flags` + engine store, empty catalog and a wide-event hook ready
3
+ * for the router / dispatcher middleware.
4
+ *
5
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
6
+ * @copyright Sergio Xalambrí 2026
7
+ */
8
+ import type { Result } from "@sdxc/result";
9
+ import type { SetupPlan } from "./plan.js";
10
+ /** Builds the flags setup plan. */
11
+ export declare function planFlags(root: string): Promise<Result<SetupPlan, Error>>;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * `sdxc setup flags`: `@sdxc/flags` + engine store, empty catalog and a wide-event hook ready
3
+ * for the router / dispatcher middleware.
4
+ *
5
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
6
+ * @copyright Sergio Xalambrí 2026
7
+ */
8
+ import { success } from "@sdxc/result";
9
+ import { creditSetupFiles } from "./credit.js";
10
+ /** Builds the flags setup plan. */
11
+ export async function planFlags(root) {
12
+ let files = await creditSetupFiles(root, [
13
+ { path: "app/initializers/flags.ts", content: FLAGS_INITIALIZER },
14
+ ]);
15
+ return success({
16
+ feature: "flags",
17
+ provider: null,
18
+ files,
19
+ edits: [],
20
+ dependencies: ["@sdxc/flags", "@sdxc/flags-engine"],
21
+ notes: [
22
+ "Install the flags instance on the router and job dispatcher with the package's middleware.",
23
+ "Add flag definitions to FLAG_SET and features as product needs them.",
24
+ ],
25
+ });
26
+ }
27
+ const FLAGS_INITIALIZER = `/**
28
+ * The app's feature flags: the definitions every evaluation resolves against, the typed
29
+ * catalog a call site names one by, and the instance both surfaces evaluate through.
30
+ */
31
+
32
+ import type { StoredFlagSet } from "@sdxc/flags-engine/store";
33
+
34
+ import { createEngine } from "@sdxc/flags-engine";
35
+ import { EngineProvider } from "@sdxc/flags-engine/provider";
36
+ import { InMemoryFlagStore } from "@sdxc/flags-engine/store/memory";
37
+ import { defineFlags } from "@sdxc/flags/catalog";
38
+ import { createFlags, wideEventHook } from "@sdxc/flags/client";
39
+
40
+ /**
41
+ * What every evaluation resolves against. A key absent from here resolves to the default
42
+ * its call site passed, so retiring a flag is deleting its entry and then its branch.
43
+ */
44
+ export const FLAG_SET: StoredFlagSet = {
45
+ flags: {},
46
+ };
47
+
48
+ /**
49
+ * Every flag by the name a call site reaches for. Add entries with \`flag.boolean\` /
50
+ * \`flag.number\` / \`flag.string\` as product needs them.
51
+ */
52
+ export const features = defineFlags({});
53
+
54
+ /**
55
+ * The instance both surfaces evaluate through, installed by the router's middleware and
56
+ * the job dispatcher's.
57
+ */
58
+ export const flags = createFlags({
59
+ provider: new EngineProvider(createEngine({ store: new InMemoryFlagStore(FLAG_SET) })),
60
+ hooks: [wideEventHook()],
61
+ });
62
+ `;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * `sdxc setup`: feature installers that span app code and config — list known features, print
3
+ * a plan, and with confirmation write every path the feature needs.
4
+ *
5
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
6
+ * @copyright Sergio Xalambrí 2026
7
+ */
8
+ import type { Result } from "@sdxc/result";
9
+ import type { SetupPlan } from "./plan.js";
10
+ export { SETUP_FEATURES, setupFeature } from "./catalog.js";
11
+ export { applyPlan, formatPlan } from "./plan.js";
12
+ export type { SetupPlan } from "./plan.js";
13
+ /** Lists the features this kit release knows, one line each. */
14
+ export declare function listFeatures(): string;
15
+ /**
16
+ * Plans `feature` for the project at `root`. Unknown features fail naming the catalog.
17
+ */
18
+ export declare function planSetup(root: string, feature: string, provider: string | undefined): Promise<Result<SetupPlan, Error>>;
19
+ /** Plans then applies, returning early when the plan itself fails. */
20
+ export declare function runSetup(root: string, feature: string, options: {
21
+ provider: string | undefined;
22
+ dryRun: boolean;
23
+ yes: boolean;
24
+ stdout: (text: string) => void;
25
+ }): Promise<Result<void, Error>>;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * `sdxc setup`: feature installers that span app code and config — list known features, print
3
+ * a plan, and with confirmation write every path the feature needs.
4
+ *
5
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
6
+ * @copyright Sergio Xalambrí 2026
7
+ */
8
+ import { failure, isFailure } from "@sdxc/result";
9
+ import { planAuth } from "./auth.js";
10
+ import { planBilling } from "./billing.js";
11
+ import { SETUP_FEATURES, setupFeature } from "./catalog.js";
12
+ import { planFlags } from "./flags.js";
13
+ import { applyPlan } from "./plan.js";
14
+ export { SETUP_FEATURES, setupFeature } from "./catalog.js";
15
+ export { applyPlan, formatPlan } from "./plan.js";
16
+ /** Lists the features this kit release knows, one line each. */
17
+ export function listFeatures() {
18
+ return (SETUP_FEATURES.map((feature) => `${feature.name.padEnd(10)} ${feature.description}`).join("\n") + "\n");
19
+ }
20
+ /**
21
+ * Plans `feature` for the project at `root`. Unknown features fail naming the catalog.
22
+ */
23
+ export async function planSetup(root, feature, provider) {
24
+ let known = setupFeature(feature);
25
+ if (known === null) {
26
+ return failure(new Error(`Unknown setup feature "${feature}"; this release ships ${SETUP_FEATURES.map((row) => row.name).join(", ")}`));
27
+ }
28
+ let chosen = provider ??
29
+ known.defaultProvider ??
30
+ (known.providers.length === 1 ? known.providers[0] : undefined);
31
+ if (known.providers.length > 0 && chosen === undefined) {
32
+ return failure(new Error(`setup ${feature} needs --provider ${known.providers.join("|")} (default: ${known.defaultProvider})`));
33
+ }
34
+ if (known.providers.length > 0 && chosen !== undefined && !known.providers.includes(chosen)) {
35
+ return failure(new Error(`Unknown ${feature} provider "${chosen}"; choose ${known.providers.join(", ")}`));
36
+ }
37
+ if (feature === "auth")
38
+ return planAuth(root, chosen ?? "r3-auth");
39
+ if (feature === "billing")
40
+ return planBilling(root, chosen ?? "polar");
41
+ if (feature === "flags")
42
+ return planFlags(root);
43
+ return failure(new Error(`setup ${feature} is listed but has no planner yet`));
44
+ }
45
+ /** Plans then applies, returning early when the plan itself fails. */
46
+ export async function runSetup(root, feature, options) {
47
+ let planned = await planSetup(root, feature, options.provider);
48
+ if (isFailure(planned))
49
+ return planned;
50
+ /** Without `-y`, the plan is printed and nothing is written — the agent-safe default. */
51
+ let dryRun = !options.yes || options.dryRun;
52
+ return applyPlan(root, planned.data, { dryRun, stdout: options.stdout });
53
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Shared setup plan: every path a feature will write or edit, printed before confirmation so
3
+ * `--dry-run` is the default agent path until `-y` asks to write.
4
+ *
5
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
6
+ * @copyright Sergio Xalambrí 2026
7
+ */
8
+ import type { Result } from "@sdxc/result";
9
+ /** One new file the plan writes. */
10
+ export interface SetupFile {
11
+ path: string;
12
+ content: string;
13
+ }
14
+ /** One existing file the plan edits. */
15
+ export interface SetupEdit {
16
+ path: string;
17
+ before: string;
18
+ after: string;
19
+ }
20
+ /** The full plan for one `sdxc setup <feature>` run. */
21
+ export interface SetupPlan {
22
+ feature: string;
23
+ provider: string | null;
24
+ files: SetupFile[];
25
+ edits: SetupEdit[];
26
+ /** Packages to add as `workspace:*` / dated pins when missing. */
27
+ dependencies: string[];
28
+ notes: string[];
29
+ }
30
+ /** Prints the plan as the operator and agent read it. */
31
+ export declare function formatPlan(plan: SetupPlan): string;
32
+ /** Writes the plan's files and edits; under `dryRun` prints diffs and changes nothing. */
33
+ export declare function applyPlan(root: string, plan: SetupPlan, options: {
34
+ dryRun: boolean;
35
+ stdout: (text: string) => void;
36
+ }): Promise<Result<void, Error>>;
37
+ /** Reads a project file, or fails naming the path. */
38
+ export declare function readProjectFile(root: string, path: string): Promise<Result<string, Error>>;