okengine 0.5.1 → 0.6.1

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 (105) hide show
  1. package/README.md +148 -13
  2. package/package.json +4 -3
  3. package/site/content/docs/elements/ai.mdx +82 -1
  4. package/site/content/docs/elements/channel.mdx +77 -8
  5. package/site/content/docs/elements/flow.mdx +20 -17
  6. package/site/content/docs/plugins/email-otp.mdx +25 -19
  7. package/site/content/docs/plugins/magic-link.mdx +27 -21
  8. package/site/content/docs/reference/configuration.mdx +12 -4
  9. package/site/content/docs/reference/environment-variables.mdx +42 -13
  10. package/site/content/docs/reference/errors.mdx +14 -0
  11. package/site/content/docs/reference/fx.mdx +68 -16
  12. package/site/content/docs/reference/i18n.mdx +313 -0
  13. package/site/content/docs/reference/index.mdx +6 -1
  14. package/site/content/docs/reference/meta.json +1 -0
  15. package/site/content/docs/reference/plugins.mdx +1 -0
  16. package/src/auth/auth.test.ts +3 -0
  17. package/src/auth/bindings.ts +1 -1
  18. package/src/auth/method-context.ts +12 -2
  19. package/src/cli/openbao-restart.integration.test.ts +106 -97
  20. package/src/compiler/aot.test.ts +16 -13
  21. package/src/compiler/effects-infer.ts +46 -0
  22. package/src/console/server/ai.test.ts +34 -5
  23. package/src/docker/compose.ts +9 -0
  24. package/src/docker/docker.test.ts +39 -0
  25. package/src/docker/dockerfile.integration.test.ts +126 -119
  26. package/src/docker/index.ts +11 -1
  27. package/src/docker/recipes/index.ts +3 -1
  28. package/src/docker/recipes/ollama.ts +43 -0
  29. package/src/docker/stack-id.ts +2 -0
  30. package/src/docker/stack.integration.test.ts +118 -102
  31. package/src/drivers/ai-mock.ts +60 -0
  32. package/src/drivers/ai-ollama-tools.integration.test.ts +109 -0
  33. package/src/drivers/ai-ollama.integration.test.ts +181 -0
  34. package/src/drivers/ai-ollama.ts +327 -0
  35. package/src/drivers/ai-openai-compatible.ts +211 -21
  36. package/src/drivers/ai-providers.test.ts +179 -2
  37. package/src/drivers/ai-stream.test.ts +195 -0
  38. package/src/drivers/ai-types.ts +42 -1
  39. package/src/drivers/channel-fcm.ts +49 -53
  40. package/src/drivers/channel-msegat.ts +61 -0
  41. package/src/drivers/channel-sently-map.ts +57 -0
  42. package/src/drivers/channel-sently.test.ts +99 -0
  43. package/src/drivers/channel-smtp.ts +8 -2
  44. package/src/drivers/channel-sndr.ts +28 -0
  45. package/src/drivers/channel-taqnyat.ts +57 -0
  46. package/src/drivers/channel-types.ts +79 -2
  47. package/src/drivers/channel-unifonic.ts +26 -43
  48. package/src/drivers/channel-wa-cloud.ts +33 -47
  49. package/src/drivers/channel-webpush.ts +39 -239
  50. package/src/drivers/index.ts +25 -1
  51. package/src/drivers/ollama.ts +14 -0
  52. package/src/elements/ai/rate.test.ts +53 -0
  53. package/src/elements/ai/rate.ts +66 -0
  54. package/src/elements/ai/redacted-prompt.test.ts +90 -0
  55. package/src/elements/ai/runtime.ts +330 -100
  56. package/src/elements/ai/tools.test.ts +99 -0
  57. package/src/elements/ai.test.ts +26 -2
  58. package/src/elements/ai.ts +10 -1
  59. package/src/elements/channel/costs.test.ts +2 -2
  60. package/src/elements/channel/costs.ts +14 -2
  61. package/src/elements/channel/mime.ts +11 -0
  62. package/src/elements/channel/runtime.ts +94 -0
  63. package/src/elements/channel/sndr-webhooks.test.ts +26 -0
  64. package/src/elements/channel.ts +10 -1
  65. package/src/elements/index.ts +9 -0
  66. package/src/i18n/catalogs/ar.ts +67 -0
  67. package/src/i18n/catalogs/en.ts +68 -0
  68. package/src/i18n/failure-message.test.ts +56 -0
  69. package/src/i18n/failure-message.ts +93 -0
  70. package/src/i18n/format.ts +67 -0
  71. package/src/i18n/index.ts +57 -0
  72. package/src/i18n/locale-context.ts +48 -0
  73. package/src/i18n/messages.test.ts +173 -0
  74. package/src/i18n/messages.ts +169 -0
  75. package/src/i18n/types.ts +90 -0
  76. package/src/index.ts +26 -0
  77. package/src/kernel/app.ts +92 -2
  78. package/src/kernel/boot-bind/ai.test.ts +60 -0
  79. package/src/kernel/boot-bind/ai.ts +125 -2
  80. package/src/kernel/boot-bind/channel.test.ts +68 -3
  81. package/src/kernel/boot-bind/channel.ts +93 -2
  82. package/src/kernel/boot.test.ts +4 -3
  83. package/src/kernel/boot.ts +1 -1
  84. package/src/kernel/errors.ts +56 -5
  85. package/src/kernel/fx.test.ts +27 -0
  86. package/src/kernel/fx.ts +74 -18
  87. package/src/kernel/pipeline.test.ts +4 -0
  88. package/src/kernel/pipeline.ts +1 -1
  89. package/src/kernel/plugin.ts +16 -0
  90. package/src/kernel/registry.ts +15 -0
  91. package/src/plugins/auth/shared.ts +5 -1
  92. package/src/plugins/auth-delivery.mailpit.integration.test.ts +336 -0
  93. package/src/plugins/auth-methods.security.test.ts +12 -10
  94. package/src/plugins/email-otp.ts +54 -1
  95. package/src/plugins/index.ts +16 -2
  96. package/src/plugins/magic-link.ts +63 -3
  97. package/src/plugins/username-policy.test.ts +302 -0
  98. package/src/plugins/username.ts +290 -9
  99. package/src/release/exports.test.ts +26 -0
  100. package/src/release/exports.ts +64 -5
  101. package/src/release/index.ts +5 -0
  102. package/src/release/measure.exports.test.ts +13 -1
  103. package/src/release/measure.ts +84 -14
  104. package/src/release/official-plugins.ts +46 -0
  105. package/src/release/readme.test.ts +30 -2
@@ -9,7 +9,9 @@ import {
9
9
  exportBudgetLabel,
10
10
  isMeasurableDriverFile,
11
11
  listDriverModules,
12
+ OFFICIAL_PLUGIN_BUDGETS,
12
13
  resolveExportBudgetTargets,
14
+ resolvePluginBudgetTargets,
13
15
  } from "./exports.ts";
14
16
 
15
17
  const ROOT = resolve(import.meta.dir, "../..");
@@ -29,12 +31,32 @@ describe("export budget targets", () => {
29
31
  expect(exportBudgetLabel(".")).toBe("okengine");
30
32
  expect(exportBudgetLabel("./channel")).toBe("channel");
31
33
  expect(exportBudgetLabel("./drivers/postgres")).toBe("postgres");
34
+ expect(exportBudgetLabel("./plugins/cors")).toBe("cors");
32
35
  expect(exportBudgetGroup(".")).toBe("exports");
33
36
  expect(exportBudgetGroup("./channel")).toBe("exports");
37
+ expect(exportBudgetGroup("./plugins")).toBe("exports");
38
+ expect(exportBudgetGroup("./plugins/cors")).toBe("plugins");
34
39
  expect(exportBudgetGroup("./drivers")).toBe("drivers");
35
40
  expect(exportBudgetGroup("./drivers/postgres")).toBe("drivers");
36
41
  });
37
42
 
43
+ test("official plugin catalogue files exist and resolve uniquely", async () => {
44
+ const plugins = resolvePluginBudgetTargets();
45
+ expect(plugins.length).toBe(OFFICIAL_PLUGIN_BUDGETS.length);
46
+ expect(new Set(plugins.map((t) => t.id)).size).toBe(plugins.length);
47
+
48
+ for (const plugin of OFFICIAL_PLUGIN_BUDGETS) {
49
+ const path = join(ROOT, "src/plugins", plugin.file);
50
+ expect(await Bun.file(path).exists()).toBe(true);
51
+ const target = plugins.find((t) => t.label === plugin.name);
52
+ expect(target).toBeDefined();
53
+ expect(target!.id).toBe(`export:./plugins/${plugin.name}`);
54
+ expect(target!.group).toBe("plugins");
55
+ expect(target!.category).toBe(plugin.category);
56
+ expect(target!.entry).toBe(path);
57
+ }
58
+ });
59
+
38
60
  test("every non-glob package export and every driver module is covered", async () => {
39
61
  const pkg = (await Bun.file(join(ROOT, "package.json")).json()) as {
40
62
  exports: Record<string, string>;
@@ -65,6 +87,10 @@ describe("export budget targets", () => {
65
87
  expect(target!.entry).toBe(join(ROOT, "src/drivers", file));
66
88
  }
67
89
 
90
+ for (const plugin of OFFICIAL_PLUGIN_BUDGETS) {
91
+ expect(bySubpath.get(`./plugins/${plugin.name}`)).toBeDefined();
92
+ }
93
+
68
94
  // No duplicates.
69
95
  expect(new Set(targets.map((t) => t.id)).size).toBe(targets.length);
70
96
  });
@@ -2,22 +2,37 @@
2
2
  * Resolve published `package.json` exports into measurable bundle entries.
3
3
  *
4
4
  * Expands `./drivers/*` to concrete driver modules (tree-shaken subpaths).
5
+ * Official `okengine/plugins` named modules are sampled separately (not published
6
+ * as `./plugins/*` subpaths).
5
7
  */
6
8
 
7
9
  import { readdir } from "node:fs/promises";
8
10
  import { basename, join, resolve } from "node:path";
11
+ import {
12
+ OFFICIAL_PLUGIN_BUDGETS,
13
+ type OfficialPluginBudget,
14
+ type PluginBudgetCategory,
15
+ } from "./official-plugins.ts";
16
+
17
+ export {
18
+ OFFICIAL_PLUGIN_BUDGETS,
19
+ PLUGIN_BUDGET_CATEGORIES,
20
+ type OfficialPluginBudget,
21
+ type PluginBudgetCategory,
22
+ } from "./official-plugins.ts";
9
23
 
10
24
  const ROOT = resolve(import.meta.dir, "../..");
11
25
  const DRIVERS_DIR = join(ROOT, "src/drivers");
26
+ const PLUGINS_DIR = join(ROOT, "src/plugins");
12
27
 
13
28
  /** Report / snapshot group for a budget sample. */
14
- export type BudgetGroup = "core" | "exports" | "drivers";
29
+ export type BudgetGroup = "core" | "exports" | "plugins" | "drivers";
15
30
 
16
31
  /** One published subpath ready for gzip measurement. */
17
32
  export interface ExportBudgetTarget {
18
33
  /** Sample id — `export:<subpath>`. */
19
34
  readonly id: string;
20
- /** Package subpath (`.` or `./store`, `./drivers/postgres`, …). */
35
+ /** Package subpath (`.` or `./store`, `./drivers/postgres`, `./plugins/cors`, …). */
21
36
  readonly subpath: string;
22
37
  /** Short human label (`channel`, `postgres`, `okengine`, …). */
23
38
  readonly label: string;
@@ -25,18 +40,23 @@ export interface ExportBudgetTarget {
25
40
  readonly group: BudgetGroup;
26
41
  /** Absolute path to the TypeScript entry. */
27
42
  readonly entry: string;
43
+ /** Docs category when `group` is `plugins`. */
44
+ readonly category?: PluginBudgetCategory;
28
45
  }
29
46
 
30
47
  /**
31
48
  * Short display name for a package subpath.
32
49
  *
33
- * @param subpath - `.` / `./channel` / `./drivers/postgres`
50
+ * @param subpath - `.` / `./channel` / `./drivers/postgres` / `./plugins/cors`
34
51
  */
35
52
  export function exportBudgetLabel(subpath: string): string {
36
53
  if (subpath === ".") return "okengine";
37
54
  if (subpath.startsWith("./drivers/")) {
38
55
  return subpath.slice("./drivers/".length);
39
56
  }
57
+ if (subpath.startsWith("./plugins/")) {
58
+ return subpath.slice("./plugins/".length);
59
+ }
40
60
  if (subpath.startsWith("./")) return subpath.slice(2);
41
61
  return subpath;
42
62
  }
@@ -50,6 +70,10 @@ export function exportBudgetGroup(subpath: string): BudgetGroup {
50
70
  if (subpath === "./drivers" || subpath.startsWith("./drivers/")) {
51
71
  return "drivers";
52
72
  }
73
+ // Named plugin modules (not the `./plugins` barrel — that stays in exports).
74
+ if (subpath.startsWith("./plugins/")) {
75
+ return "plugins";
76
+ }
53
77
  return "exports";
54
78
  }
55
79
 
@@ -82,6 +106,30 @@ export async function listDriverModules(driversDir = DRIVERS_DIR): Promise<reado
82
106
  return entries.filter(isMeasurableDriverFile).sort((a, b) => a.localeCompare(b));
83
107
  }
84
108
 
109
+ /**
110
+ * Resolve official plugin modules into measurement targets.
111
+ *
112
+ * @param options - Override plugins dir (tests)
113
+ */
114
+ export function resolvePluginBudgetTargets(options?: {
115
+ readonly pluginsDir?: string;
116
+ readonly catalogue?: readonly OfficialPluginBudget[];
117
+ }): readonly ExportBudgetTarget[] {
118
+ const pluginsDir = options?.pluginsDir ?? PLUGINS_DIR;
119
+ const catalogue = options?.catalogue ?? OFFICIAL_PLUGIN_BUDGETS;
120
+ return catalogue.map((plugin) => {
121
+ const subpath = `./plugins/${plugin.name}`;
122
+ return {
123
+ id: `export:${subpath}`,
124
+ subpath,
125
+ label: plugin.name,
126
+ group: "plugins" as const,
127
+ entry: join(pluginsDir, plugin.file),
128
+ category: plugin.category,
129
+ };
130
+ });
131
+ }
132
+
85
133
  /**
86
134
  * Resolve every published export into a stable, sorted measurement target list.
87
135
  *
@@ -91,12 +139,14 @@ export async function resolveExportBudgetTargets(options?: {
91
139
  readonly root?: string;
92
140
  readonly pkg?: PackageExports;
93
141
  readonly driversDir?: string;
142
+ readonly pluginsDir?: string;
94
143
  }): Promise<readonly ExportBudgetTarget[]> {
95
144
  const root = options?.root ?? ROOT;
96
145
  const pkg =
97
146
  options?.pkg ?? ((await Bun.file(join(root, "package.json")).json()) as PackageExports);
98
147
  const exportsMap = pkg.exports ?? {};
99
148
  const driversDir = options?.driversDir ?? join(root, "src/drivers");
149
+ const pluginsDir = options?.pluginsDir ?? join(root, "src/plugins");
100
150
 
101
151
  const targets: ExportBudgetTarget[] = [];
102
152
 
@@ -121,6 +171,8 @@ export async function resolveExportBudgetTargets(options?: {
121
171
  targets.push(targetFor(subpath, resolve(root, entryRel)));
122
172
  }
123
173
 
174
+ targets.push(...resolvePluginBudgetTargets({ pluginsDir }));
175
+
124
176
  targets.sort((a, b) => {
125
177
  const g = groupOrder(a.group) - groupOrder(b.group);
126
178
  if (g !== 0) return g;
@@ -129,6 +181,12 @@ export async function resolveExportBudgetTargets(options?: {
129
181
  if (b.subpath === "./drivers") return 1;
130
182
  if (a.subpath === ".") return -1;
131
183
  if (b.subpath === ".") return 1;
184
+ // Catalogue order for plugins (docs category order).
185
+ if (a.group === "plugins" && b.group === "plugins") {
186
+ const ai = OFFICIAL_PLUGIN_BUDGETS.findIndex((p) => p.name === a.label);
187
+ const bi = OFFICIAL_PLUGIN_BUDGETS.findIndex((p) => p.name === b.label);
188
+ if (ai !== -1 && bi !== -1) return ai - bi;
189
+ }
132
190
  return a.label.localeCompare(b.label);
133
191
  });
134
192
  return targets;
@@ -146,6 +204,7 @@ function targetFor(subpath: string, entry: string): ExportBudgetTarget {
146
204
 
147
205
  function groupOrder(group: BudgetGroup): number {
148
206
  if (group === "exports") return 0;
149
- if (group === "drivers") return 1;
150
- return 2;
207
+ if (group === "plugins") return 1;
208
+ if (group === "drivers") return 2;
209
+ return 3;
151
210
  }
@@ -7,9 +7,14 @@ export {
7
7
  exportBudgetLabel,
8
8
  isMeasurableDriverFile,
9
9
  listDriverModules,
10
+ OFFICIAL_PLUGIN_BUDGETS,
11
+ PLUGIN_BUDGET_CATEGORIES,
10
12
  resolveExportBudgetTargets,
13
+ resolvePluginBudgetTargets,
11
14
  type BudgetGroup,
12
15
  type ExportBudgetTarget,
16
+ type OfficialPluginBudget,
17
+ type PluginBudgetCategory,
13
18
  } from "./exports.ts";
14
19
 
15
20
  export {
@@ -31,7 +31,7 @@ describe("export gzip budgets", () => {
31
31
  );
32
32
  });
33
33
 
34
- test("formatBudgetsReport groups Core / Exports / Drivers with short names", () => {
34
+ test("formatBudgetsReport groups Core / Exports / Plugins / Drivers with short names", () => {
35
35
  const snapshot: BudgetsSnapshot = {
36
36
  measuredAt: "2026-07-25T00:00:00.000Z",
37
37
  version: "0.0.0",
@@ -56,6 +56,16 @@ describe("export gzip budgets", () => {
56
56
  group: "exports",
57
57
  ok: true,
58
58
  },
59
+ {
60
+ id: "export:./plugins/cors",
61
+ label: "cors",
62
+ value: 100,
63
+ limit: 200,
64
+ unit: "bytes",
65
+ gate: "regression",
66
+ group: "plugins",
67
+ ok: true,
68
+ },
59
69
  {
60
70
  id: "export:./drivers/postgres",
61
71
  label: "postgres",
@@ -71,8 +81,10 @@ describe("export gzip budgets", () => {
71
81
  const report = formatBudgetsReport(snapshot);
72
82
  expect(report).toContain("\nCore\n");
73
83
  expect(report).toContain("\nExports\n");
84
+ expect(report).toContain("\nPlugins\n");
74
85
  expect(report).toContain("\nDrivers\n");
75
86
  expect(report).toContain("[ok] channel:");
87
+ expect(report).toContain("[ok] cors:");
76
88
  expect(report).toContain("[ok] postgres:");
77
89
  expect(report).not.toContain("regression Export");
78
90
  expect(report).not.toContain("./channel");
@@ -6,7 +6,12 @@ import { mkdtemp, readdir, rm } from "node:fs/promises";
6
6
  import { tmpdir } from "node:os";
7
7
  import { join, resolve } from "node:path";
8
8
  import { createRouter } from "../kernel/router.ts";
9
- import { type BudgetGroup, resolveExportBudgetTargets } from "./exports.ts";
9
+ import {
10
+ type BudgetGroup,
11
+ OFFICIAL_PLUGIN_BUDGETS,
12
+ PLUGIN_BUDGET_CATEGORIES,
13
+ resolveExportBudgetTargets,
14
+ } from "./exports.ts";
10
15
  import {
11
16
  CLIENT_BUDGET_BYTES,
12
17
  COLD_START_BUDGET_MS,
@@ -24,7 +29,14 @@ const BUDGETS_JSON_PATH = resolve(ROOT, "budgets.json");
24
29
  * Deps measured separately from OKE code in export samples.
25
30
  * Edge/client absolute gates keep the historical smaller external list.
26
31
  */
27
- const BUILD_EXTERNALS = ["@duckdb/node-api", "@duckdb/*"] as const;
32
+ const BUILD_EXTERNALS = [
33
+ "@duckdb/node-api",
34
+ "@duckdb/*",
35
+ // ICU MessageFormat — adopted FormatJS runtime; kept out of the edge
36
+ // micro-bundle the same way other heavy deps are measured separately.
37
+ "intl-messageformat",
38
+ "@formatjs/*",
39
+ ] as const;
28
40
 
29
41
  /** Heavy optional / peer packages — not counted in export:* gzip samples. */
30
42
  const EXPORT_BUILD_EXTERNALS = [
@@ -49,9 +61,18 @@ export type BudgetGate = "absolute" | "regression";
49
61
  const GROUP_HEADINGS: Readonly<Record<BudgetGroup, string>> = {
50
62
  core: "Core",
51
63
  exports: "Exports",
64
+ plugins: "Plugins",
52
65
  drivers: "Drivers",
53
66
  };
54
67
 
68
+ /** Docs category → markdown subheading under Plugins. */
69
+ const PLUGIN_CATEGORY_HEADINGS: Readonly<Record<string, string>> = {
70
+ auth: "Auth",
71
+ security: "Security",
72
+ ops: "Ops",
73
+ perf: "Perf",
74
+ };
75
+
55
76
  /** One measured budget sample. */
56
77
  export interface BudgetSample {
57
78
  /** Stable metric id. */
@@ -482,13 +503,13 @@ export async function measureAllBudgets(): Promise<BudgetsSnapshot> {
482
503
  }
483
504
 
484
505
  /**
485
- * Format a snapshot for CI logs (Core / Exports / Drivers sections).
506
+ * Format a snapshot for CI logs (Core / Exports / Plugins / Drivers).
486
507
  *
487
508
  * @param snapshot - Measured budgets
488
509
  */
489
510
  export function formatBudgetsReport(snapshot: BudgetsSnapshot): string {
490
511
  const lines = [`okengine budgets v${snapshot.version} @ ${snapshot.measuredAt}`];
491
- const order: readonly BudgetGroup[] = ["core", "exports", "drivers"];
512
+ const order: readonly BudgetGroup[] = ["core", "exports", "plugins", "drivers"];
492
513
  for (const group of order) {
493
514
  const rows = snapshot.budgets.filter((b) => b.group === group);
494
515
  if (rows.length === 0) continue;
@@ -504,6 +525,28 @@ export function formatBudgetsReport(snapshot: BudgetsSnapshot): string {
504
525
  return `${lines.join("\n")}\n`;
505
526
  }
506
527
 
528
+ /**
529
+ * Markdown table with column widths padded so `oxfmt` is a no-op.
530
+ * Compact `|---|` tables get realigned by oxfmt and make Format fail after
531
+ * every `bun run budgets` refresh.
532
+ *
533
+ * @param headers - Column headers (use `""` for an unnamed first column)
534
+ * @param rows - Body cells
535
+ */
536
+ export function formatMarkdownTable(
537
+ headers: readonly string[],
538
+ rows: readonly (readonly string[])[],
539
+ ): string[] {
540
+ const widths = headers.map((header, i) =>
541
+ Math.max(header.length, ...rows.map((row) => (row[i] ?? "").length)),
542
+ );
543
+ const cell = (value: string, i: number): string => value.padEnd(widths[i]!);
544
+ const line = (cells: readonly string[]): string =>
545
+ `| ${cells.map((value, i) => cell(value, i)).join(" | ")} |`;
546
+ const sep = `| ${widths.map((w) => "-".repeat(w)).join(" | ")} |`;
547
+ return [line(headers), sep, ...rows.map((row) => line(row))];
548
+ }
549
+
507
550
  /**
508
551
  * Full markdown document for [`BUDGETS.md`](../../BUDGETS.md).
509
552
  * Written by `bun run budgets` — do not edit the tables by hand.
@@ -518,24 +561,51 @@ export function formatBudgetsMarkdown(snapshot: BudgetsSnapshot): string {
518
561
  "",
519
562
  `_okengine v${snapshot.version} · measured ${snapshot.measuredAt}_`,
520
563
  "",
521
- "Core rows are absolute AGENTS caps. Exports and Drivers fail on regression vs the prior [`budgets.json`](budgets.json) (max +256 B or +2%). Export gzip excludes peers/optionals (`zod`, `sently`, `oxc-parser`, `ajv`).",
564
+ "Core rows are absolute AGENTS caps. Exports, Plugins, and Drivers fail on regression vs the prior [`budgets.json`](budgets.json) (max +256 B or +2%). Export gzip excludes peers/optionals (`zod`, `sently`, `oxc-parser`, `ajv`).",
522
565
  ];
523
- const order: readonly BudgetGroup[] = ["core", "exports", "drivers"];
566
+ const order: readonly BudgetGroup[] = ["core", "exports", "plugins", "drivers"];
524
567
  for (const group of order) {
525
568
  const rows = snapshot.budgets.filter((b) => b.group === group);
526
569
  if (rows.length === 0) continue;
527
570
  const limitCol = group === "core" ? "Limit" : "Ceiling";
528
571
  lines.push("");
529
572
  lines.push(`## ${GROUP_HEADINGS[group]}`);
530
- lines.push("");
531
- lines.push(`| | Measured | ${limitCol} |`);
532
- lines.push("|---|---|---|");
533
- for (const b of rows) {
534
- const mark = b.ok ? "" : " **FAIL**";
535
- lines.push(
536
- `| ${b.label}${mark} | ${formatValue(b.value, b.unit)} | ${formatValue(b.limit, b.unit)} |`,
537
- );
573
+ if (group === "plugins") {
574
+ for (const category of PLUGIN_BUDGET_CATEGORIES) {
575
+ const names = new Set(
576
+ OFFICIAL_PLUGIN_BUDGETS.filter((p) => p.category === category).map((p) => p.name),
577
+ );
578
+ const catRows = rows.filter((b) => names.has(b.label));
579
+ if (catRows.length === 0) continue;
580
+ lines.push("");
581
+ lines.push(`### ${PLUGIN_CATEGORY_HEADINGS[category] ?? category}`);
582
+ lines.push("");
583
+ lines.push(
584
+ ...formatMarkdownTable(
585
+ ["", "Measured", limitCol],
586
+ catRows.map((b) => {
587
+ const mark = b.ok ? "" : " **FAIL**";
588
+ return [
589
+ `${b.label}${mark}`,
590
+ formatValue(b.value, b.unit),
591
+ formatValue(b.limit, b.unit),
592
+ ];
593
+ }),
594
+ ),
595
+ );
596
+ }
597
+ continue;
538
598
  }
599
+ lines.push("");
600
+ lines.push(
601
+ ...formatMarkdownTable(
602
+ ["", "Measured", limitCol],
603
+ rows.map((b) => {
604
+ const mark = b.ok ? "" : " **FAIL**";
605
+ return [`${b.label}${mark}`, formatValue(b.value, b.unit), formatValue(b.limit, b.unit)];
606
+ }),
607
+ ),
608
+ );
539
609
  }
540
610
  return `${lines.join("\n")}\n`;
541
611
  }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Official `okengine/plugins` named exports measured for CI budgets.
3
+ * Categories match `site/content/docs/plugins/index.mdx`.
4
+ * Keep in sync with the docs catalogue — landing + budgets both read this.
5
+ */
6
+
7
+ /** Docs / landing category for an official plugin. */
8
+ export type PluginBudgetCategory = "auth" | "security" | "ops" | "perf";
9
+
10
+ /** One official plugin entry measured as `export:./plugins/<name>`. */
11
+ export type OfficialPluginBudget = {
12
+ /** Named export from `okengine/plugins`. */
13
+ readonly name: string;
14
+ /** Basename under `src/plugins/` (e.g. `magic-link.ts`). */
15
+ readonly file: string;
16
+ /** Docs category. */
17
+ readonly category: PluginBudgetCategory;
18
+ };
19
+
20
+ /** Category display order (docs index). */
21
+ export const PLUGIN_BUDGET_CATEGORIES: readonly PluginBudgetCategory[] = [
22
+ "auth",
23
+ "security",
24
+ "ops",
25
+ "perf",
26
+ ] as const;
27
+
28
+ /**
29
+ * Canonical official plugins — membership, file mapping, and grouping.
30
+ * Order within a category is docs order; landing may re-sort by size.
31
+ */
32
+ export const OFFICIAL_PLUGIN_BUDGETS: readonly OfficialPluginBudget[] = [
33
+ { name: "username", file: "username.ts", category: "auth" },
34
+ { name: "anonymous", file: "anonymous.ts", category: "auth" },
35
+ { name: "magicLink", file: "magic-link.ts", category: "auth" },
36
+ { name: "emailOtp", file: "email-otp.ts", category: "auth" },
37
+ { name: "phoneNumber", file: "phone-number.ts", category: "auth" },
38
+ { name: "twoFactor", file: "two-factor.ts", category: "auth" },
39
+ { name: "passkey", file: "passkey.ts", category: "auth" },
40
+ { name: "headers", file: "headers.ts", category: "security" },
41
+ { name: "cors", file: "cors.ts", category: "security" },
42
+ { name: "csrf", file: "csrf.ts", category: "security" },
43
+ { name: "ipAllowlist", file: "ip-allowlist.ts", category: "security" },
44
+ { name: "maintenanceMode", file: "maintenance-mode.ts", category: "ops" },
45
+ { name: "compression", file: "compression.ts", category: "perf" },
46
+ ] as const;
@@ -36,6 +36,26 @@ describe("budgets markdown", () => {
36
36
  group: "exports",
37
37
  ok: true,
38
38
  },
39
+ {
40
+ id: "export:./plugins/cors",
41
+ label: "cors",
42
+ value: 2048,
43
+ limit: 2304,
44
+ unit: "bytes",
45
+ gate: "regression",
46
+ group: "plugins",
47
+ ok: true,
48
+ },
49
+ {
50
+ id: "export:./plugins/username",
51
+ label: "username",
52
+ value: 3072,
53
+ limit: 3328,
54
+ unit: "bytes",
55
+ gate: "regression",
56
+ group: "plugins",
57
+ ok: true,
58
+ },
39
59
  {
40
60
  id: "export:./drivers/postgres",
41
61
  label: "postgres",
@@ -52,10 +72,18 @@ describe("budgets markdown", () => {
52
72
  expect(md.startsWith("# Budgets\n")).toBe(true);
53
73
  expect(md).toContain("## Core");
54
74
  expect(md).toContain("## Exports");
75
+ expect(md).toContain("## Plugins");
76
+ expect(md).toContain("### Auth");
77
+ expect(md).toContain("### Security");
55
78
  expect(md).toContain("## Drivers");
56
- expect(md).toContain("| channel |");
57
- expect(md).toContain("| postgres |");
79
+ expect(md).toMatch(/\|\s*channel\s*\|/);
80
+ expect(md).toMatch(/\|\s*cors\s*\|/);
81
+ expect(md).toMatch(/\|\s*username\s*\|/);
82
+ expect(md).toMatch(/\|\s*postgres\s*\|/);
58
83
  expect(md).toContain("[`budgets.json`](budgets.json)");
59
84
  expect(md).not.toContain("./channel");
85
+ // oxfmt-aligned separators (not compact `|---|---|---|`) so Format stays green
86
+ expect(md).not.toContain("|---|---|---|");
87
+ expect(md).toMatch(/\| -{3,} \| -{3,} \| -{3,} \|/);
60
88
  });
61
89
  });