@starci/eslint-grammar-core 0.15.6 → 0.15.10

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/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.15.10 - 2026-10-29
4
+
5
+ - Changed: `@starci/eslint-canon-fe` 9.4.9 is the peer dependency; the bundled slot manifest gives the model libraries their owners in `ruleParams.be.infraOwners` (`@starci/ai-router` to `integrations/ai-gateway`, `@langchain/*` to `integrations/ai`; `openai`, `langchain`, `@langchain/langgraph`, `@langchain/community` and the provider SDKs nowhere) and lists R326 and R327 on `be.integrations`; the bundled rule catalog carries R326 and R327; the bundled canon pins name hfs 4.9.11, eslint-canon-be 3.6.8, eslint-canon-fe 9.4.9, the Grammar family 0.15.10 (grammar, eslint-grammar-core, eslint-grammar-offset-pop), and pin `@langchain/core` 1.3.1 and `@langchain/openai` 1.8.0. No rule changed.
6
+
7
+ ## 0.15.9 - 2026-10-29
8
+
9
+ - Changed: `@starci/eslint-canon-fe` 9.4.8 is the peer dependency; the bundled canon pins name hfs 4.9.10, eslint-canon-be 3.6.7, eslint-canon-fe 9.4.8, eslint-grammar-core 0.15.9 and eslint-grammar-offset-pop 0.15.9. No rule changed.
10
+
11
+ ## 0.15.8 - 2026-10-29
12
+
13
+ - Changed: `starci-grammar/route-page-is-one-page` (R325) follows the owner ruling `page-frame` as rewritten: a route segment `layout` whose owner (`fe.feature`, kind `layouts`), its pure half or its one root block draws a `Page` whose `header` carries `tabs` is the one `Page` of every route under it. The rule finds the route `page` files that mount a page owner, walks up through the `layout` files of their segments and resolves each layout's owner one level deep. A page owner every route of which is so framed is not judged `missing`; one that draws a `Page` (or a root block that draws one) under such a layout is `twice`, and the message names the layout. A layout whose `Page` carries no `tabs` frames no segment.
14
+ - Changed: R325 also judges layout owners (`fe.feature`, kind `layouts`): a `Page` they draw has nothing beside it (`sibling`; a `PageHeader` block beside the segment's `Page` belongs in its `header`), no `Page` inside another (`twice`), and no bare `PageHeader` or `PageContainer` (`part`). A layout owner that draws no `Page` is never `missing`.
15
+ - Changed: `@starci/eslint-canon-fe` 9.4.7 is the peer dependency; versioned together with Grammar 0.15.8; the bundled canon pins name the Grammar family 0.15.8 (grammar, eslint-grammar-core, eslint-grammar-offset-pop), eslint-canon-fe 9.4.7 and eslint-canon-be 3.6.6.
16
+ - Spec: `src/page.spec.ts`, `src/page-owners.spec.ts` (layout cases on the project fixture); docs: `docs/page.md`.
17
+
18
+ ## 0.15.7 - 2026-10-29
19
+
20
+ - Changed: `starci-grammar/route-page-is-one-page` (R325) follows the owner ruling that a route draws exactly one `Page`, drawn by the page owner, its pure half (`./component`), or the one connected block (`fe.components`, kind `blocks`) the owner renders as its root, read one level deep (the block's connected half and its own pure half). A server page owner whose header needs client data renders that block and passes the page body as its children. An element that draws the `Page` with an element sibling stays `sibling`; a `Page` (or a block that draws one) inside another is the new finding `twice`.
21
+ - Changed: R325 does not judge a page owner as `missing` when every route `page` file that imports it lies under the route group `(auth)` with its own `layout`: that layout draws the auth frame, the page frame of its sign-in, sign-up, password and callback pages. A page owner that draws no JSX (it only calls `redirect()` or `notFound()`, or returns null) stays unjudged. Workbench pages get no exemption.
22
+ - Changed: `@starci/eslint-canon-fe` 9.4.6 is the peer dependency; versioned together with Grammar 0.15.7; the bundled canon pins name the Grammar family 0.15.7 (grammar, eslint-grammar-core, eslint-grammar-offset-pop) and eslint-canon-fe 9.4.6.
23
+ - Spec: `src/page.spec.ts`, `src/page-owners.spec.ts` (new, cross-file); docs: `docs/page.md`.
24
+
3
25
  ## 0.15.6 - 2026-10-28
4
26
 
5
27
  - Changed: `starci-grammar/route-page-is-one-page` (R325) also refuses a page owner file that draws JSX but no `Page` and draws through no pure half of its own (an element imported from `./component`), with the message `missing` on its first element. The segment boundary owners of FE-BOUNDARY-1 (`*ErrorPage`, `*LoadingPage`, `*NotFoundPage`) are not judged for it; a file that draws a bare `PageHeader` or `PageContainer` is reported once, as `part`. Spec: `src/page.spec.ts`; docs: `docs/page.md`.
@@ -7,5 +7,7 @@ export interface Owner {
7
7
  }
8
8
  /** An imported JSX owner, or null when its implementation cannot be proved from owned source. */
9
9
  export declare const importedHeader: (context: ReaderContext, opening: TSESTree.JSXOpeningElement) => Owner | null;
10
+ /** A file of the app parsed on its own (a route `layout`), sharing the run's parse cache. */
11
+ export declare const parsedSource: (context: ReaderContext, filename: string) => ParsedContext;
10
12
  /** The per-repository proof cache shares the same lifetime as parsed header source. */
11
13
  export declare const headerProofs: (context: ReaderContext) => Map<string, boolean>;
@@ -155,5 +155,7 @@ export const importedHeader = (context, opening) => {
155
155
  const exported = name.type === "JSXMemberExpression" ? name.property.name : imported.imported ?? "default";
156
156
  return target ? headerExport(target, exported) : null;
157
157
  };
158
+ /** A file of the app parsed on its own (a route `layout`), sharing the run's parse cache. */
159
+ export const parsedSource = (context, filename) => sourceContext(context, filename);
158
160
  /** The per-repository proof cache shares the same lifetime as parsed header source. */
159
161
  export const headerProofs = (context) => stateOf(context).proofs;
@@ -0,0 +1,29 @@
1
+ import type { TSESTree } from "@typescript-eslint/types";
2
+ import type { ReaderContext } from "./types.js";
3
+ /** The pure half of a unit: the module its connected half draws through. */
4
+ export declare const PURE_HALF: RegExp;
5
+ /**
6
+ * True when the element is one of the app's connected blocks (`fe.components`, kind `blocks`) and that block draws a
7
+ * `Page`, in its connected half or in the pure half it draws through (`./component`). One level only: what the block
8
+ * hands to other blocks is not followed.
9
+ */
10
+ export declare const blockDrawsPage: (context: ReaderContext, opening: TSESTree.JSXOpeningElement) => boolean;
11
+ /** The route group whose layout frames sign-in, sign-up, password and auth callback pages. */
12
+ export declare const AUTH_GROUP = "(auth)";
13
+ /**
14
+ * True when every route page that mounts this page owner lies under the app's auth route group (`app/**\/(auth)/`) with
15
+ * its own layout: that layout draws the auth frame, which is the page frame of the sign-in, sign-up, password and
16
+ * callback pages in it. An owner no route mounts, or one mounted anywhere else too, is not an auth page.
17
+ */
18
+ export declare const mountedOnlyUnderAuthGroup: (context: ReaderContext) => boolean;
19
+ /** Which of the routes that mount a page owner lie under a segment layout that draws their one `Page`. */
20
+ export interface SegmentFrame {
21
+ /** At least one mounting route is framed: the owner draws body content only, and a `Page` of its own is a second one. */
22
+ readonly some: boolean;
23
+ /** Every mounting route is framed (and at least one mounts it): the owner needs no `Page`. */
24
+ readonly every: boolean;
25
+ /** The nearest such `layout`, relative to the app folder, for the finding. */
26
+ readonly layout: string | null;
27
+ }
28
+ /** Whether the routes that mount this page owner sit under a segment `layout` that draws their one `Page`. */
29
+ export declare const segmentFrame: (context: ReaderContext) => SegmentFrame;
@@ -0,0 +1,179 @@
1
+ /**
2
+ * What R325 reads beyond the owner's own file: whether the one connected block an owner renders draws the `Page`, whether
3
+ * a page owner is mounted only under an auth route group whose layout is its page frame, and whether a route segment
4
+ * `layout` above it already draws the one `Page` of its tabbed segment.
5
+ */
6
+ import fs from "node:fs";
7
+ import path from "node:path";
8
+ import { walk } from "@starci/eslint-canon-fe/lib/ast.mjs";
9
+ import { hfsOf } from "@starci/eslint-canon-fe/lib/hfs.mjs";
10
+ import { importedHeader, parsedSource } from "./app-shell-owner-source.js";
11
+ /** The pure half of a unit: the module its connected half draws through. */
12
+ export const PURE_HALF = /^\.\/component(?:\.[cm]?[jt]sx?)?$/;
13
+ /** The name a JSX element is drawn by (`Page`, or `Grammar.Page` as `Page`), or null. */
14
+ const openingName = (opening) => {
15
+ const name = opening.name;
16
+ if (name.type === "JSXIdentifier")
17
+ return name.name;
18
+ if (name.type === "JSXMemberExpression")
19
+ return name.property.name;
20
+ return null;
21
+ };
22
+ /** The JSX elements of one parsed file. */
23
+ const elementsOf = (context) => {
24
+ const found = [];
25
+ walk(context.sourceCode, context.program, (node) => {
26
+ if (node.type === "JSXElement")
27
+ found.push(node);
28
+ });
29
+ return found;
30
+ };
31
+ /** The names a parsed file imports from its own pure half (`./component`). */
32
+ const pureHalfNames = (context) => {
33
+ const names = new Set();
34
+ for (const statement of context.program.body) {
35
+ if (statement.type !== "ImportDeclaration" || !PURE_HALF.test(String(statement.source.value)))
36
+ continue;
37
+ for (const specifier of statement.specifiers)
38
+ names.add(specifier.local.name);
39
+ }
40
+ return names;
41
+ };
42
+ /** A unit's file and the pure halves it draws through (`./component`): the files that together draw what the unit draws. */
43
+ const withHalves = (context) => {
44
+ const halves = pureHalfNames(context);
45
+ const files = [context];
46
+ for (const element of elementsOf(context)) {
47
+ const name = element.openingElement.name;
48
+ if (name.type !== "JSXIdentifier" || !halves.has(name.name))
49
+ continue;
50
+ const half = importedHeader(context, element.openingElement);
51
+ if (half !== null && !files.includes(half.context))
52
+ files.push(half.context);
53
+ }
54
+ return files;
55
+ };
56
+ /** The `Page` elements a parsed file draws itself. */
57
+ const pagesIn = (context) => elementsOf(context).filter((element) => openingName(element.openingElement) === "Page");
58
+ /** The object literal a `header={...}` attribute passes: written in place, or a `const` of the same file. */
59
+ const headerObject = (context, opening) => {
60
+ const attribute = opening.attributes.find((entry) => entry.type === "JSXAttribute" && entry.name.name === "header");
61
+ const value = attribute?.value?.type === "JSXExpressionContainer" ? attribute.value.expression : null;
62
+ if (value?.type === "ObjectExpression")
63
+ return value;
64
+ if (value?.type !== "Identifier")
65
+ return null;
66
+ let found = null;
67
+ walk(context.sourceCode, context.program, (node) => {
68
+ if (node.type === "VariableDeclarator" && node.id.type === "Identifier" && node.id.name === value.name && node.init?.type === "ObjectExpression")
69
+ found = node.init;
70
+ });
71
+ return found;
72
+ };
73
+ /** True when a `Page` element's `header` carries `tabs`: the page heads a segment whose routes are its tabs. */
74
+ const headsTabbedSegment = (context, opening) => headerObject(context, opening)?.properties.some((property) => property.type === "Property" && property.key.type === "Identifier" && property.key.name === "tabs") === true;
75
+ /** The files of an app block (`fe.components`, kind `blocks`) an element draws, with its pure half; null for anything else. */
76
+ const blockFiles = (context, opening) => {
77
+ const owner = importedHeader(context, opening);
78
+ if (owner === null)
79
+ return null;
80
+ const found = hfsOf(context).classify(owner.context.filename);
81
+ if (found.slot !== "fe.components" || found.kind !== "blocks")
82
+ return null;
83
+ return withHalves(owner.context);
84
+ };
85
+ /**
86
+ * True when the element is one of the app's connected blocks (`fe.components`, kind `blocks`) and that block draws a
87
+ * `Page`, in its connected half or in the pure half it draws through (`./component`). One level only: what the block
88
+ * hands to other blocks is not followed.
89
+ */
90
+ export const blockDrawsPage = (context, opening) => blockFiles(context, opening)?.some((file) => pagesIn(file).length > 0) === true;
91
+ /**
92
+ * True when a unit (a layout owner) draws a `Page` whose header carries `tabs`: itself, through its pure half, or through
93
+ * the one connected block either renders, read one level deep as for a page owner.
94
+ */
95
+ const unitDrawsTabbedPage = (context) => withHalves(context).some((file) => {
96
+ const tabbed = (target) => pagesIn(target).some((page) => headsTabbedSegment(target, page.openingElement));
97
+ if (tabbed(file))
98
+ return true;
99
+ return elementsOf(file).some((element) => blockFiles(file, element.openingElement)?.some(tabbed) === true);
100
+ });
101
+ /** The route group whose layout frames sign-in, sign-up, password and auth callback pages. */
102
+ export const AUTH_GROUP = "(auth)";
103
+ const PAGE_OWNER = /^(.*\/src)\/features\/pages\/([^/]+)\//;
104
+ const ROUTE_PAGE = /(?:^|[\\/])page\.[cm]?[jt]sx?$/;
105
+ const ROUTE_LAYOUT = /^layout\.[cm]?[jt]sx?$/;
106
+ /**
107
+ * True when a route file imports a value of the page owner `owner` (`@/features/pages/<owner>`, or a relative path to it):
108
+ * a default, named or namespace import. A type import, or a re-export such as `export { metadata } from` the owner, mounts
109
+ * nothing: a route that only borrows the owner's metadata renders another page.
110
+ */
111
+ const mountsOwner = (text, owner) => new RegExp(String.raw `\bimport\s+(?!type\s)(?:[\w$]+\s*,?\s*)?(?:\{[^}]*\}|\*\s*as\s+[\w$]+)?\s*from\s+["'][^"']*\/features\/pages\/${owner}(?:\/index)?["']`).test(text);
112
+ /** The app's `app/` folder and the route `page` files that mount this page owner; null outside a page owner. */
113
+ const mountingRoutes = (context) => {
114
+ const match = PAGE_OWNER.exec(context.filename.replaceAll("\\", "/"));
115
+ if (match === null)
116
+ return null;
117
+ const [, source = "", owner = ""] = match;
118
+ const appDirectory = path.normalize(path.join(source, "app"));
119
+ if (!fs.existsSync(appDirectory))
120
+ return null;
121
+ const routes = fs.readdirSync(appDirectory, { recursive: true, encoding: "utf8" })
122
+ .filter((relative) => ROUTE_PAGE.test(relative))
123
+ .map((relative) => path.join(appDirectory, relative))
124
+ .filter((route) => mountsOwner(fs.readFileSync(route, "utf8"), owner));
125
+ return { appDirectory, routes };
126
+ };
127
+ /** The `layout` files of the segments that wrap a route page, nearest first, up to the app folder. */
128
+ const layoutsAbove = (route, appDirectory) => {
129
+ const layouts = [];
130
+ for (let directory = path.dirname(route); directory.length >= appDirectory.length; directory = path.dirname(directory)) {
131
+ for (const name of fs.readdirSync(directory))
132
+ if (ROUTE_LAYOUT.test(name))
133
+ layouts.push(path.join(directory, name));
134
+ if (directory === appDirectory)
135
+ break;
136
+ }
137
+ return layouts;
138
+ };
139
+ /** True when a route file lies under an auth route group that has its own `layout`, the frame of every page in it. */
140
+ const underAuthGroup = (route, appDirectory) => layoutsAbove(route, appDirectory).some((layout) => path.basename(path.dirname(layout)) === AUTH_GROUP);
141
+ /**
142
+ * True when every route page that mounts this page owner lies under the app's auth route group (`app/**\/(auth)/`) with
143
+ * its own layout: that layout draws the auth frame, which is the page frame of the sign-in, sign-up, password and
144
+ * callback pages in it. An owner no route mounts, or one mounted anywhere else too, is not an auth page.
145
+ */
146
+ export const mountedOnlyUnderAuthGroup = (context) => {
147
+ const found = mountingRoutes(context);
148
+ return found !== null && found.routes.length > 0 && found.routes.every((route) => underAuthGroup(route, found.appDirectory));
149
+ };
150
+ /**
151
+ * True when a route segment `layout` draws the one `Page` of its tabbed segment: the layout file, or a layout owner it
152
+ * renders (`fe.feature`, kind `layouts`) through itself, its pure half or the one connected block it renders as its root,
153
+ * draws a `Page` whose `header` carries `tabs`.
154
+ */
155
+ const layoutDrawsSegmentPage = (context, layout) => {
156
+ const file = parsedSource(context, layout);
157
+ if (pagesIn(file).some((page) => headsTabbedSegment(file, page.openingElement)))
158
+ return true;
159
+ return elementsOf(file).some((element) => {
160
+ const owner = importedHeader(file, element.openingElement);
161
+ if (owner === null)
162
+ return false;
163
+ const found = hfsOf(context).classify(owner.context.filename);
164
+ return found.slot === "fe.feature" && found.kind === "layouts" && unitDrawsTabbedPage(owner.context);
165
+ });
166
+ };
167
+ /** Whether the routes that mount this page owner sit under a segment `layout` that draws their one `Page`. */
168
+ export const segmentFrame = (context) => {
169
+ const found = mountingRoutes(context);
170
+ if (found === null || found.routes.length === 0)
171
+ return { some: false, every: false, layout: null };
172
+ const framing = found.routes.map((route) => layoutsAbove(route, found.appDirectory).find((layout) => layoutDrawsSegmentPage(context, layout)) ?? null);
173
+ const first = framing.find((layout) => layout !== null) ?? null;
174
+ return {
175
+ some: first !== null,
176
+ every: framing.every((layout) => layout !== null),
177
+ layout: first === null ? null : path.relative(found.appDirectory, first).replaceAll("\\", "/"),
178
+ };
179
+ };
package/dist/lib/why.js CHANGED
@@ -41,8 +41,8 @@ export const why = {
41
41
  },
42
42
  "route-page-is-one-page": {
43
43
  code: "FE_ROUTE_PAGE_OUTSIDE_PAGE",
44
- en: "The page owner `<file>` draws something beside its Page, a bare PageHeader or PageContainer, or no Page at all.",
45
- fix: "Draw one Page: the band as its header, everything else in its body, the measure as its measure.",
44
+ en: "The page or layout owner `<file>` draws something beside its Page, a Page inside another (or inside the Page its tabbed segment's layout draws), a bare PageHeader or PageContainer, or no Page at all (itself, through its pure half, or through the one connected block it renders as its root).",
45
+ fix: "Draw one Page: the band as its header, everything else in its body, the measure as its measure. When client data builds the header, render as the root the one connected block that draws the Page and pass the body as its children. Under a segment layout whose Page carries header.tabs, a page draws its body only; that layout's Page has nothing beside it, its head in its header. A page mounted only under the (auth) route group is framed by that group's layout.",
46
46
  },
47
47
  "no-shell-bottom-tabs": {
48
48
  code: "FE_APP_SHELL_BOTTOM_TABS",
package/dist/page.d.ts CHANGED
@@ -4,7 +4,10 @@ import type { TSESTree } from "@typescript-eslint/types";
4
4
  export declare const tabsOutsideHeader: (parent: TSESTree.JSXElement | TSESTree.JSXFragment) => TSESTree.JSXElement | null;
5
5
  /** Page tabs are the header's `tabs`, never a `Tabs` at the top of the body or beside a `PageHeader`. */
6
6
  export declare const pageTabsInHeader: Rule.RuleModule;
7
- /** A page owner draws one `Page` and nothing beside it; `PageHeader` and `PageContainer` are Page's own parts. */
7
+ /**
8
+ * A route draws exactly one `Page` and nothing beside it: the page owner draws it, its pure half does, or the one connected
9
+ * block it renders as its root does. `PageHeader` and `PageContainer` are Page's own parts.
10
+ */
8
11
  export declare const routePageIsOnePage: Rule.RuleModule;
9
12
  /** The rules these laws contribute to the plugin. */
10
13
  export declare const rules: Record<string, Rule.RuleModule>;
package/dist/page.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { inSlot, isProductSource, kindOfFile } from "@starci/eslint-canon-fe/lib/scope.mjs";
2
+ import { PURE_HALF, blockDrawsPage, mountedOnlyUnderAuthGroup, segmentFrame } from "./lib/page-frame.js";
2
3
  import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
3
4
  /**
4
5
  * The rules that hold the page frame laws: Grammar's `Page` is the one owner of a route page's header band, its inset
@@ -7,15 +8,25 @@ import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
7
8
  * - R324 (`FE_PAGE_TABS_OUTSIDE_HEADER`): page tabs are the header's tabs. A `Tabs` that is the first element child of a
8
9
  * `Page` (the top of the body, right under the band), or the next element sibling of a `PageHeader`, is a page tab bar
9
10
  * drawn outside the band: it misses the separator it stands on and takes the body's inset and gap.
10
- * - R325 (`FE_ROUTE_PAGE_OUTSIDE_PAGE`): a page owner (`fe.feature`, kind `pages`) draws one `Page` and nothing beside it.
11
- * A `Page` with an element sibling, or a bare `PageHeader` or `PageContainer` in the page owner, re-decides the inset
12
- * and the rhythm `Page` owns. A page owner file that draws JSX but no `Page`, and hands drawing to no pure half of its
13
- * own (an element imported from `./component`), has no page frame at all.
11
+ * - R325 (`FE_ROUTE_PAGE_OUTSIDE_PAGE`): a route draws exactly one `Page` and nothing beside it. The page owner
12
+ * (`fe.feature`, kind `pages`) draws it itself, through its pure half (`./component`), or through the one connected
13
+ * block it renders as its root, where client data builds the header a server owner cannot build. A route segment
14
+ * `layout` whose owner (`fe.feature`, kind `layouts`) draws, in the same ways, a `Page` whose `header` carries `tabs` is
15
+ * the one `Page` of every route under it: those page owners draw body content only, so a `Page` they draw is a second
16
+ * one, and they need none. A `Page` (or a block that draws one) with an element sibling, a `Page` inside another, or a
17
+ * bare `PageHeader` or `PageContainer` in a page or layout owner re-decides the inset and the rhythm `Page` owns. A page
18
+ * owner file that draws JSX but no `Page` in one of those ways has no page frame at all, unless a segment layout frames
19
+ * every route that mounts it, or every such route lies under the auth route group `(auth)` with its own layout: that
20
+ * layout draws the auth frame, the page frame of its sign-in, sign-up, password and callback pages.
14
21
  *
15
22
  * WHAT IT READS. Element names (`Page`, or `Grammar.Page` as `Page`), the element children of one JSX parent, and the
16
- * names a file imports from a relative module; whitespace text and JSX comments are not children. A `Tabs` lower in the
17
- * body, a `Page` wrapped alone in a provider, and files outside a page owner (for R325) are not judged. The segment
18
- * boundary owners of FE-BOUNDARY-1 (`*ErrorPage`, `*LoadingPage`, `*NotFoundPage`) are not judged for a missing `Page`:
23
+ * names a file imports from a relative module; whitespace text and JSX comments are not children. For R325 it also reads,
24
+ * one level deep, the source of each app block (`fe.components`, kind `blocks`) the owner draws with that block's pure
25
+ * half, the app's route `page` files that import the owner, and the route `layout` files of the segments above them with
26
+ * the layout owners they render (the same one level). A page owner that draws no JSX (its body only calls
27
+ * `redirect()` or `notFound()`, or returns null) draws no UI and is not judged, nor is a layout owner for a missing
28
+ * `Page`. A `Tabs` lower in the body, a `Page` wrapped alone in a provider, and files outside a page or layout owner (for
29
+ * R325) are not judged. The segment boundary owners of FE-BOUNDARY-1 (`*ErrorPage`, `*LoadingPage`, `*NotFoundPage`) are not judged for a missing `Page`:
19
30
  * an app-level boundary stands in for whichever page failed or waits and draws its notice.
20
31
  */
21
32
  /** The element name of a JSX child (`Tabs`, or `Grammar.Tabs` as `Tabs`), or null for text and expressions. */
@@ -75,39 +86,74 @@ export const pageTabsInHeader = defineRule({
75
86
  },
76
87
  });
77
88
  const PAGE_PARTS = new Set(["PageHeader", "PageContainer"]);
78
- /** True for a page owner's file: `fe.feature`, kind `pages`. */
79
- const isPageOwner = (context) => inSlot(context, "fe.feature") && kindOfFile(context) === "pages";
89
+ /** The owner kind a file belongs to: a page owner or a layout owner (`fe.feature`, kind `pages` or `layouts`), or null. */
90
+ const ownerKind = (context) => {
91
+ if (!inSlot(context, "fe.feature"))
92
+ return null;
93
+ const kind = kindOfFile(context);
94
+ return kind === "pages" || kind === "layouts" ? kind : null;
95
+ };
80
96
  /** The segment boundary owners of FE-BOUNDARY-1: an error, loading or not-found page, which may draw a notice. */
81
97
  const BOUNDARY_OWNER = /\/features\/pages\/[^/]*(?:ErrorPage|LoadingPage|NotFoundPage)\//;
82
98
  /** True when the file is a boundary owner's, judged by its owner folder. */
83
99
  const isBoundaryOwner = (context) => BOUNDARY_OWNER.test(context.filename.replaceAll("\\", "/"));
84
- /** The pure half of a page owner: the module its connected half draws through. */
85
- const PURE_HALF = /^\.\/component(?:\.[cm]?[jt]sx?)?$/;
86
- /** A page owner draws one `Page` and nothing beside it; `PageHeader` and `PageContainer` are Page's own parts. */
100
+ /** An import of the app's own source (`@/...` or a relative path), where its blocks come from. */
101
+ const APP_SOURCE = /^(?:@\/|\.\.?\/)/;
102
+ /** The nearest JSX element that encloses a node, or null. */
103
+ const enclosingElement = (node) => {
104
+ for (let parent = node.parent; parent; parent = parent.parent)
105
+ if (parent.type === "JSXElement")
106
+ return parent;
107
+ return null;
108
+ };
109
+ /**
110
+ * A route draws exactly one `Page` and nothing beside it: the page owner draws it, its pure half does, or the one connected
111
+ * block it renders as its root does. `PageHeader` and `PageContainer` are Page's own parts.
112
+ */
87
113
  export const routePageIsOnePage = defineRule({
88
114
  meta: {
89
115
  type: "problem",
90
- docs: { description: "R325: a page owner draws one Page with nothing beside it, never a bare PageHeader or PageContainer, and never no Page at all." },
116
+ docs: { description: "R325: a route draws one Page (in its page owner, its pure half or its one root block, or in the layout of its tabbed segment) with nothing beside it, never a bare PageHeader or PageContainer, and never no Page at all." },
91
117
  schema: [],
92
118
  messages: {
93
- sibling: "This `Page` has a sibling: a route page is one `Page`, and whatever sits beside it escapes the header band, the measure and the rhythm `Page` owns. Move the sibling into the `Page` body, or into `header` when it heads the page.",
94
- part: "`{{name}}` is drawn by `Page`: a page owner composes `Page` (`header` for the band, `measure` for the body), so the inset and the rhythm have one owner. Replace it with `Page`.",
95
- missing: "This page owner draws no `Page`: a route page is one Grammar `Page`, which owns the header band, the measure and the rhythm, so without it the page has no heading band and its body sits on no inset. Wrap what it draws in a `Page` whose `header.title` is the page heading (never a `Heading` of its own), or draw it through the owner's pure half in `./component`.",
119
+ sibling: "This `{{name}}` draws the route's `Page` and has a sibling: a route page is one `Page`, and whatever sits beside it escapes the header band, the measure and the rhythm `Page` owns. Move the sibling into the `Page` body (as the block's children when a block draws the `Page`), or into `header` when it heads the page.",
120
+ twice: "This `{{name}}` draws a second `Page` inside the route's `Page`{{framer}}: a route page is exactly one `Page`, so the band, the measure and the rhythm would be decided twice. Draw its content as the body of the one `Page`.",
121
+ part: "`{{name}}` is drawn by `Page`: a page or layout owner composes `Page` (`header` for the band, `measure` for the body), so the inset and the rhythm have one owner. Replace it with `Page`.",
122
+ missing: "This page owner draws no `Page`: a route page is one Grammar `Page`, which owns the header band, the measure and the rhythm, so without it the page has no heading band and its body sits on no inset. Wrap what it draws in a `Page` whose `header.title` is the page heading (never a `Heading` of its own), draw it through the owner's pure half in `./component`, or render as the root the one connected block that draws the `Page` from client data.",
96
123
  },
97
124
  },
98
125
  create(context) {
99
- if (!isProductSource(context) || !isPageOwner(context))
126
+ const kind = isProductSource(context) ? ownerKind(context) : null;
127
+ if (kind === null)
100
128
  return {};
101
- const judgeMissing = !isBoundaryOwner(context);
129
+ // A layout owner may draw no Page (a pure frame); a boundary owner draws its notice.
130
+ const judgeMissing = kind === "pages" && !isBoundaryOwner(context);
131
+ let segment = null;
132
+ /** The segment layout above the page owner's routes, read once and only when a finding needs it. */
133
+ const framedBy = () => {
134
+ segment ??= kind === "pages" ? segmentFrame(context) : { some: false, every: false, layout: null };
135
+ return segment;
136
+ };
102
137
  const pureHalf = new Set();
138
+ const appImports = new Set();
139
+ const frames = new Set();
103
140
  let first = null;
104
141
  let drawsPage = false;
142
+ /** True when the element draws the route's `Page`: a `Page`, or an app block whose source draws one. */
143
+ const drawsFrame = (element, name) => {
144
+ if (name === "Page")
145
+ return true;
146
+ const opening = element.openingElement.name;
147
+ return opening.type === "JSXIdentifier" && appImports.has(opening.name) && blockDrawsPage(context, element.openingElement);
148
+ };
105
149
  return {
106
150
  ImportDeclaration(declaration) {
107
- if (!PURE_HALF.test(String(declaration.source.value)))
151
+ const source = String(declaration.source.value);
152
+ const into = PURE_HALF.test(source) ? pureHalf : APP_SOURCE.test(source) ? appImports : null;
153
+ if (into === null || declaration.importKind === "type")
108
154
  return;
109
155
  for (const specifier of declaration.specifiers)
110
- pureHalf.add(specifier.local.name);
156
+ into.add(specifier.local.name);
111
157
  },
112
158
  JSXElement(element) {
113
159
  first ??= element;
@@ -121,17 +167,33 @@ export const routePageIsOnePage = defineRule({
121
167
  context.report({ node: element, messageId: "part", data: { name } });
122
168
  return;
123
169
  }
124
- if (name !== "Page")
170
+ if (!drawsFrame(element, name))
125
171
  return;
126
172
  drawsPage = true;
173
+ frames.add(element);
174
+ const label = name ?? "Page";
175
+ const framer = framedBy();
176
+ if (framer.some) {
177
+ const layout = framer.layout ?? "layout";
178
+ context.report({ node: element, messageId: "twice", data: { name: label, framer: ` (the segment layout \`${layout}\` draws it; a page under it draws its body only)` } });
179
+ return;
180
+ }
181
+ for (let outer = enclosingElement(element); outer; outer = enclosingElement(outer)) {
182
+ if (!frames.has(outer))
183
+ continue;
184
+ context.report({ node: element, messageId: "twice", data: { name: label, framer: "" } });
185
+ return;
186
+ }
127
187
  const parent = element.parent;
128
188
  if (parent.type !== "JSXElement" && parent.type !== "JSXFragment")
129
189
  return;
130
190
  if (renderedChildren(parent.children).length > 1)
131
- context.report({ node: element, messageId: "sibling" });
191
+ context.report({ node: element, messageId: "sibling", data: { name: label } });
132
192
  },
133
193
  "Program:exit"() {
134
- if (judgeMissing && first !== null && !drawsPage)
194
+ if (!judgeMissing || first === null || drawsPage || framedBy().every)
195
+ return;
196
+ if (!mountedOnlyUnderAuthGroup(context))
135
197
  context.report({ node: first, messageId: "missing" });
136
198
  },
137
199
  };
package/docs/page.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Law module: `page.ts`. Catalogue: R324 FE_PAGE_TABS_OUTSIDE_HEADER, R325 FE_ROUTE_PAGE_OUTSIDE_PAGE.
4
4
 
5
- Grammar's `Page` is a route page: the header band full width, then the body inside the page measure and gutter one region step below it. It is the single owner of the page inset and the page rhythm, so the page tabs belong to its header and nothing of the page sits beside it.
5
+ Grammar's `Page` is a route page: the header band full width, then the body inside the page measure and gutter one region step below it (or, with `chrome="bleed"`, an app surface whose body fills the region). It is the single owner of the page inset and the page rhythm, so the page tabs belong to its header and nothing of the page sits beside it.
6
6
 
7
7
  Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
8
8
 
@@ -31,7 +31,25 @@ A `Tabs` element that is the first element child of a `Page`, or the next elemen
31
31
 
32
32
  ## `starci-grammar/route-page-is-one-page`
33
33
 
34
- In a page owner (`fe.feature`, kind `pages`), a `Page` with an element sibling in its parent is a finding, and so is any `PageHeader` or `PageContainer`: both are Page's own parts. A page owner file that draws JSX but no `Page`, and draws no element imported from its own pure half (`./component`), is a finding too, reported on its first element: the page has no frame at all. A `Page` alone in a fragment or a provider, and one `Page` per branch of a conditional, are legal. Files outside a page owner are not judged, and the segment boundary owners of FE-BOUNDARY-1 (`*ErrorPage`, `*LoadingPage`, `*NotFoundPage`) are not judged for a missing `Page`: an app-level boundary stands in for whichever page failed or waits and draws its notice.
34
+ A route draws exactly one `Page`. In a page owner (`fe.feature`, kind `pages`) or a layout owner (`fe.feature`, kind `layouts`) the element that draws it is a `Page`, or an element of one of the app's connected blocks (`fe.components`, kind `blocks`, imported from `@/` or a relative path) whose source draws a `Page` in its connected half or in the pure half it draws through (`./component`). The rule reads that block one level deep: a block the block relays to is not followed. This is how a server owner gets a header built from client data: it renders that block as its root and passes the page's content as the block's children.
35
+
36
+ A tabbed segment has its `Page` in its layout. A route segment `layout` file (`src/app/**/layout.tsx`) frames every route `page` below it; when it, or a layout owner it renders (through that owner, its pure half or its one root block, as above), draws a `Page` whose `header` carries `tabs` (an object literal written in place or held in a `const` of the same file), that `Page` is the one `Page` of every route under the segment. For a page owner the rule finds the route `page` files that import it, walks up from each through the `layout` files of the segments above it to the app folder, and resolves each layout's owner. A layout whose `Page` carries no `tabs` frames no segment: the pages under it draw their own.
37
+
38
+ Findings, each reported on the element:
39
+
40
+ - `sibling`: an element that draws the `Page` has an element sibling in its parent, in a page owner or a layout owner.
41
+ - `twice`: an element that draws a `Page` sits inside another one (a `Page` in a `Page`, or a block that draws one inside a `Page` or inside the root block), or sits in a page owner mounted by a route under a segment layout that draws the `Page`; the finding names that layout.
42
+ - `part`: any `PageHeader` or `PageContainer` in a page or layout owner: both are Page's own parts.
43
+ - `missing`: a page owner file draws JSX but nothing that draws the `Page`, and draws no element imported from its own pure half, reported on its first element: the page has no frame at all.
44
+
45
+ A `Page` (or the root block) alone in a fragment or a provider, and one per branch of a conditional, are legal; the root block's children are the page body. Not judged for `missing`:
46
+
47
+ - files outside a page owner, a layout owner (a pure frame draws no `Page`), and a page owner that draws no JSX: its body only calls `redirect()` or `notFound()`, or returns null, so it draws no UI;
48
+ - a page owner every route of which lies under a segment layout that draws the `Page`: it draws body content only;
49
+ - the segment boundary owners of FE-BOUNDARY-1 (`*ErrorPage`, `*LoadingPage`, `*NotFoundPage`): an app-level boundary stands in for whichever page failed or waits and draws its notice;
50
+ - an auth page: every route `page` file of the app (`src/app/**/page.tsx`) that imports the owner (`@/features/pages/<Owner>`) lies under the route group `(auth)`, and that group has its own `layout`. The Grammar ships no auth frame; the app's `(auth)` layout draws it, and it is the page frame of the sign-in, sign-up, password and callback pages it holds. An owner no route mounts, one also mounted outside the group, or a group without a layout gets no exemption.
51
+
52
+ A workbench page is an ordinary page: it draws its `Page` like any other, usually through its root block.
35
53
 
36
54
  **Invalid** (`src/features/pages/ConnectionPage/component.tsx`)
37
55
 
@@ -51,6 +69,15 @@ In a page owner (`fe.feature`, kind `pages`), a `Page` with an element sibling i
51
69
  </>
52
70
  ```
53
71
 
72
+ **Invalid** (`src/features/pages/DecisionsPage/component.tsx`, `DecisionsBoard` draws the `Page`)
73
+
74
+ ```tsx
75
+ <>
76
+ <Banner />
77
+ <DecisionsBoard />
78
+ </>
79
+ ```
80
+
54
81
  **Valid**
55
82
 
56
83
  ```tsx
@@ -59,6 +86,54 @@ In a page owner (`fe.feature`, kind `pages`), a `Page` with an element sibling i
59
86
  </Page>
60
87
  ```
61
88
 
89
+ **Valid** (`src/features/pages/AgentProfilePage/component.tsx`, the connected block `AgentProfileHead` draws the `Page` from client data)
90
+
91
+ ```tsx
92
+ <AgentProfileHead agentId={agentId}>
93
+ <AgentProfileOwner agentId={agentId} />
94
+ <AgentProfileRecent agentId={agentId} />
95
+ </AgentProfileHead>
96
+ ```
97
+
98
+ **Valid** (`src/features/pages/ChatPage/component.tsx`'s root block `AgentChat` draws an app surface under the trail alone)
99
+
100
+ ```tsx
101
+ <Page chrome="bleed" header={{ breadcrumbs }}>
102
+ <FillViewport minHeight="md" bottomInset="page">
103
+ <SurfaceCard ariaLabel={label} composition="joined" height="fill">{rail}{thread}</SurfaceCard>
104
+ </FillViewport>
105
+ </Page>
106
+ ```
107
+
108
+ **Valid** (`src/features/layouts/InstanceLayout/component.tsx` frames the segment `app/**/[instance]/layout.tsx`; its root block `InstanceFrame` draws `<Page header={{ title, tabs: { label, items } }}>{children}</Page>`, items with `href`)
109
+
110
+ ```tsx
111
+ <InstanceFrame instanceId={instanceId}>{children}</InstanceFrame>
112
+ ```
113
+
114
+ and a page owner under it draws its body only:
115
+
116
+ ```tsx
117
+ <SettingsGrid instanceId={instanceId} />
118
+ ```
119
+
120
+ **Invalid** (`src/features/layouts/InstanceLayout/component.tsx`: the head drawn beside the segment's `Page`)
121
+
122
+ ```tsx
123
+ <>
124
+ <InstanceHeader instanceId={instanceId} />
125
+ <Page>{children}</Page>
126
+ </>
127
+ ```
128
+
129
+ **Invalid** (`src/features/pages/SettingsPage/component.tsx` under that segment: a second `Page`)
130
+
131
+ ```tsx
132
+ <Page header={{ title: "Settings" }}>
133
+ <SettingsGrid instanceId={instanceId} />
134
+ </Page>
135
+ ```
136
+
62
137
  **Finding code:** `FE_ROUTE_PAGE_OUTSIDE_PAGE`
63
138
 
64
139
  Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starci/eslint-grammar-core",
3
- "version": "0.15.6",
3
+ "version": "0.15.10",
4
4
  "description": "ESLint rules for the core Grammar's component, token and composition contracts.",
5
5
  "keywords": [
6
6
  "eslint",
@@ -41,7 +41,7 @@
41
41
  "node": ">=22"
42
42
  },
43
43
  "peerDependencies": {
44
- "@starci/eslint-canon-fe": "9.4.5",
44
+ "@starci/eslint-canon-fe": "9.4.9",
45
45
  "eslint": ">=9",
46
46
  "typescript": ">=5.9"
47
47
  },
@@ -31,35 +31,35 @@ pins:
31
31
  source: packages/event-stream/package.json
32
32
  why: 'the one server-sent-events client of every front end (fe-stack event-stream, owner:event-stream-package): the transport client layer (modules/api/sse/clients) creates one instance for the app with the bearer token source and the stream operations follow on it; it carries Last-Event-ID resume, the capped doubling backoff, the heartbeat timeout, the single 401 renewal and the useSWRSubscription adapter, so no app keeps a hand-written reader.'
33
33
  '@starci/grammar':
34
- version: 0.15.6
34
+ version: 0.15.10
35
35
  group: starci
36
36
  install: registry
37
37
  side: fe
38
38
  source: packages/grammar/package.json
39
39
  why: 'the grammar front ends read: the brand layer sets `--font-sans` and `--font-mono` and the grammar reads them; it carries the Input tel kind, the copyable and read-only Input, the IconButton disclosure props and count badge, ChatBubble, FillViewport, Textarea mentions and Enter-to-send, the leading PrimaryRailLayout rail, the plate-less Image, ListRow, the soft Alert, Progress steps, the floating primary IconButton, FlowGraph, the STATE-8 loading views and the bordered selectable TagGroup chips. The runtime source version wins for a @starci package.'
40
40
  '@starci/eslint-canon-be':
41
- version: 3.6.4
41
+ version: 3.6.8
42
42
  group: starci
43
43
  install: registry
44
44
  side: be
45
45
  source: packages/eslint-canon-be/package.json
46
46
  why: 'the back-end ESLint canon: `loadHfs(import.meta.url)` of be/eslint.config.mjs finds the app-root hfs.json (kind app) and gives every linted file the view of the be side, and the project graph is built per side; its bundled runtime copies (slots, canon-pins, failure codes, the architecture machine) put .starcistacks and .sops.yaml at the app root; `starciBeConfig({ hfs: loadHfs(import.meta.url) })` is the typed factory and the BE-CONVENTION laws are its rules.'
47
47
  '@starci/eslint-canon-fe':
48
- version: 9.4.5
48
+ version: 9.4.9
49
49
  group: starci
50
50
  install: registry
51
51
  side: fe
52
52
  source: packages/eslint-canon-fe/package.json
53
53
  why: 'the front-end ESLint canon: `loadHfs(import.meta.url)` of fe/eslint.config.mjs finds the app-root hfs.json (kind app) and gives every linted file the view of the fe side, and the project graph is built per side; its bundled runtime copies (slots, canon-pins, failure codes, the architecture machine) put .starcistacks and .sops.yaml at the app root; the front end has no tests (FE_NO_TESTS R97 in hfs) and no-vietnamese-in-source (R91) applies.'
54
54
  '@starci/eslint-grammar-core':
55
- version: 0.15.6
55
+ version: 0.15.10
56
56
  group: starci
57
57
  install: registry
58
58
  side: fe
59
59
  source: packages/eslint-grammar-core/package.json
60
60
  why: 'the StarCi Grammar component API lint, versioned with @starci/grammar; front ends compose this family package with the universal FE canon.'
61
61
  '@starci/eslint-grammar-offset-pop':
62
- version: 0.15.6
62
+ version: 0.15.10
63
63
  group: starci
64
64
  install: registry
65
65
  side: fe
@@ -106,7 +106,7 @@ pins:
106
106
  source: packages/ai-router/package.json
107
107
  why: 'the AI pool router of a back end: a NestJS module that routes OpenAI-compatible chat, stream and embeddings calls across keys, models and providers, with @starci/ai-router/testing for its specs; @starci/jest-preset compiles it as an ESM-only dependency.'
108
108
  '@starci/hfs':
109
- version: 4.9.8
109
+ version: 4.9.11
110
110
  group: starci
111
111
  install: registry
112
112
  side: both
@@ -241,6 +241,16 @@ pins:
241
241
  group: framework
242
242
  side: be
243
243
  why: readiness probes with dependency indicators use Terminus (the liveness route of the scaffolded skeleton does not, being a thin door over the liveness service); every measured product back end resolves 11.1.1.
244
+ '@langchain/core':
245
+ version: 1.3.1
246
+ group: framework
247
+ side: be
248
+ why: 'the LangChain core of the one AI integration (BE-AI-3): prompt templates, output parsers, runnables and BaseRetriever; @langchain/openai takes it as its peer. The registry latest on 2026-10-29.'
249
+ '@langchain/openai':
250
+ version: 1.8.0
251
+ group: framework
252
+ side: be
253
+ why: 'ChatOpenAI and OpenAIEmbeddings of the one AI integration, pointed at the ai-router gateway with a virtual key (BE-AI-1, BE-AI-3, R327); peer @langchain/core ^1.3.1. The registry latest on 2026-10-29.'
244
254
  '@nestjs/cqrs':
245
255
  version: 11.0.3
246
256
  group: framework
@@ -1820,7 +1820,7 @@ rules:
1820
1820
  - {path: packages/eslint/be/be-r89-source-form-coverage.spec.mjs, edition: full, codes: [BE_SOURCE_FORM, BE_PUBLIC_CONTRACT_FORM]}
1821
1821
  - id: R90
1822
1822
  code: "BE_INFRA_OWNER"
1823
- law: "Each raw infrastructure library (HTTP, cache, queue, scheduler, logger, date, config, events) is imported or referenced only by its one owning platform or integration capability, and the `HttpClient` port of `platform/http` is called only by an `integrations` capability."
1823
+ law: "Each raw infrastructure library (HTTP, cache, queue, scheduler, logger, date, config, events, model SDKs) is imported or referenced only by its one owning platform or integration capability, and the `HttpClient` port of `platform/http` is called only by an `integrations` capability."
1824
1824
  kinds: [lint, codemod]
1825
1825
  failureCodes: ["BE_INFRA_OWNER"]
1826
1826
  enforcers:
@@ -5756,3 +5756,74 @@ rules:
5756
5756
  source: owner
5757
5757
  quote: "ok trò"
5758
5758
  ruling: "A route page is one Grammar Page (owner ruling page-frame): the single owner of the page inset and rhythm; the lint refuses a sibling beside the Page and a bare PageHeader or PageContainer in a page owner."
5759
+ - id: R326
5760
+ code: "BE_AI_KEY_CUSTODY"
5761
+ law: "An upstream model provider key variable (OPENROUTER_API_KEY, OPENAI_API_KEY and the rest of the canon's one list) is named only inside the ai-router gateway's custody owner integrations/ai-gateway, in a literal, a member or a destructured property; every other file reaches a model through the gateway with a virtual key."
5762
+ kinds: [lint]
5763
+ gates: [pre-commit, settle, land, ci]
5764
+ failureCodes: ["BE_AI_KEY_CUSTODY"]
5765
+ enforcers:
5766
+ - {kind: eslint-be, id: provider-key-custody}
5767
+ editions: [lite, full]
5768
+ docs: [contexts/code/be/ai.md]
5769
+ templateNa: "The skeleton scaffolds no model call; an app adds the ai and ai-gateway integrations when it calls a model."
5770
+ proves:
5771
+ - packages/eslint-canon-be/src/ai-gateway.spec.ts
5772
+ exemplifiedBy:
5773
+ - {path: packages/eslint-canon-be/src/ai-gateway.spec.ts, editions: [lite, full], codes: [BE_AI_KEY_CUSTODY]}
5774
+ witness:
5775
+ - {path: packages/eslint-canon-be/src/ai-gateway.spec.ts, editions: [lite, full], codes: [BE_AI_KEY_CUSTODY]}
5776
+ cases:
5777
+ - id: case-1
5778
+ date: "2026-10-29"
5779
+ source: owner
5780
+ quote: "nhớ làm langchain nhé update .claude lun là call thẳng từ code phải dùng langchain với embeded context"
5781
+ ruling: "A model call made straight from code uses LangChain with retrieved context, through the ai-router gateway (owner ruling be-ai-langchain-gateway): only the gateway's custody owner reads a provider key."
5782
+ - id: R327
5783
+ code: "BE_AI_GATEWAY_CLIENT"
5784
+ law: "Code builds only the ChatOpenAI and OpenAIEmbeddings clients of @langchain/openai, each from an inline options object with no spread, its configuration.baseURL read from a <c>.options.ts type and its apiKey the reveal() of a platform/config Secret, so every model call goes through the ai-router gateway with a virtual key."
5785
+ kinds: [lint]
5786
+ gates: [pre-commit, settle, land, ci]
5787
+ failureCodes: ["BE_AI_GATEWAY_CLIENT"]
5788
+ enforcers:
5789
+ - {kind: eslint-be, id: ai-client-through-gateway}
5790
+ editions: [lite, full]
5791
+ docs: [contexts/code/be/ai.md]
5792
+ templateNa: "The skeleton scaffolds no model call; an app adds the ai and ai-gateway integrations when it calls a model."
5793
+ proves:
5794
+ - packages/eslint-canon-be/src/ai-gateway.spec.ts
5795
+ exemplifiedBy:
5796
+ - {path: packages/eslint-canon-be/src/ai-gateway.spec.ts, editions: [lite, full], codes: [BE_AI_GATEWAY_CLIENT]}
5797
+ witness:
5798
+ - {path: packages/eslint-canon-be/src/ai-gateway.spec.ts, editions: [lite, full], codes: [BE_AI_GATEWAY_CLIENT]}
5799
+ cases:
5800
+ - id: case-1
5801
+ date: "2026-10-29"
5802
+ source: owner
5803
+ quote: "nhớ làm langchain nhé update .claude lun là call thẳng từ code phải dùng langchain với embeded context"
5804
+ ruling: "A model call made straight from code uses LangChain with retrieved context, through the ai-router gateway (owner ruling be-ai-langchain-gateway): the LangChain clients point at the gateway's base URL with its virtual key."
5805
+ - id: R333
5806
+ code: "BE_ENTITY_SCHEMA_DRIFT"
5807
+ law: "Every TypeORM entity column of an app's entity list (be/src/platform/database/entities.ts) matches the schema its SQL migrations build: `starci app db drift` applies db/bootstrap.sql and every active db/migrations/*.sql to a scratch database (a container of the app's db image, or the empty database --url-env names), reads information_schema.columns and pg_catalog, and refuses a missing table, a missing column, a type that differs once both are normalised to PostgreSQL's format_type names (an enum by its type name), and a nullability that differs. A database column no entity maps is fine. A host that cannot provide the scratch database gets no verdict (exit 2, needs a database), never a green."
5808
+ kinds: [check]
5809
+ gates: [ci]
5810
+ failureCodes: ["BE_ENTITY_SCHEMA_DRIFT"]
5811
+ enforcers:
5812
+ - {kind: hfs, id: db-drift, at: packages/hfs/db/drift.mjs}
5813
+ editions: [lite]
5814
+ editionWhy: "The owner ruling of 2026-10-29 maps lite tables with TypeORM entities while db/migrations/*.sql stays the only DDL and synchronize is false, so only lite entities can drift from a schema they do not create; full entities ship with their own TypeORM migrations."
5815
+ docs: [contexts/code/be/persistence.md]
5816
+ templateNa: "The entities and the migrations are the product's tables; the check judges whichever an app writes, and a template scaffolds no table."
5817
+ proves:
5818
+ - {path: packages/hfs/src/db-drift.spec.mjs, edition: lite, codes: [BE_ENTITY_SCHEMA_DRIFT]}
5819
+ - {path: packages/hfs/src/db-drift-docker.spec.mjs, edition: lite, codes: [BE_ENTITY_SCHEMA_DRIFT]}
5820
+ exemplifiedBy:
5821
+ - {path: packages/hfs/src/db-drift.spec.mjs, edition: lite, codes: [BE_ENTITY_SCHEMA_DRIFT]}
5822
+ witness:
5823
+ - {path: packages/hfs/src/db-drift.spec.mjs, edition: lite, codes: [BE_ENTITY_SCHEMA_DRIFT]}
5824
+ cases:
5825
+ - id: case-1
5826
+ date: "2026-10-29"
5827
+ source: owner
5828
+ quote: "lite persistence moves to TypeORM entities while db/migrations/*.sql stays the only DDL and synchronize is false"
5829
+ ruling: "Lite entities only map tables the migrations create, so each entity column is checked against the migrated schema by starci app db drift, which CI runs in the build job and the release gate runs as its db-drift row."
@@ -254,6 +254,25 @@ ruleParams:
254
254
  "@socket.io/postgres-adapter": [platform/realtime] # the stateless socket.io adapter of a scaled lite back end without Redis
255
255
  "@socket.io/redis-adapter": [platform/realtime] # the sharded socket.io adapter of a scaled back end on the declared Redis
256
256
  pg: [platform/realtime] # the LISTEN connection of the Postgres hub; every other query goes through TypeORM
257
+ # BE-AI-1, BE-AI-3: every model call goes through the ai-router gateway. Its custody owner registers @starci/ai-router with the
258
+ # provider keys; the one LangChain integration owns @langchain/*; no provider SDK, openai client or agent framework is imported.
259
+ "@starci/ai-router": [integrations/ai-gateway]
260
+ "@starci/ai-router/testing": [integrations/ai-gateway, integrations/ai] # the fake provider a spec of either side boots the gateway with
261
+ "@langchain": [integrations/ai] # a scope key: every @langchain/* package
262
+ "@langchain/langgraph": [] # an agent loop runs in the agent runtime, never in code
263
+ "@langchain/community": [] # retrieval reads the app's own persistence through its owner
264
+ langchain: [] # createAgent is an agent loop
265
+ openai: [] # code calls models through @langchain/openai
266
+ "@anthropic-ai/sdk": []
267
+ "@google/genai": []
268
+ "@google/generative-ai": []
269
+ "@mistralai/mistralai": []
270
+ "@openrouter/ai-sdk-provider": []
271
+ "@ai-sdk": []
272
+ ai: []
273
+ cohere-ai: []
274
+ groq-sdk: []
275
+ ollama: []
257
276
  # R87 BE_CQRS_SHAPE no-event-bus: the in-process event vocabulary the rule refuses. `imports` maps a module
258
277
  # specifier to the member names that are an in-process event; `[]` flags the package itself (its emitter packages
259
278
  # are the `[]` owners of infraOwners above). `classes` maps a module specifier to the class names that are an
@@ -1892,7 +1911,7 @@ slots:
1892
1911
  tests: unit-beside # <name>.service.spec.ts beside each <name>.service.ts; plus src/tests/integration/<provider>/ (R112)
1893
1912
  coverage: required
1894
1913
  budget: {indexExports: 80} # a provider's port surface includes clients, config, options, tokens and errors
1895
- rules: [BE_TIER_DIRECTION, BE_ERROR_HOME, BE_SECRET_DEFAULT, BE_INTEGRATION_SPEC_MISSING]
1914
+ rules: [BE_TIER_DIRECTION, BE_ERROR_HOME, BE_SECRET_DEFAULT, BE_INTEGRATION_SPEC_MISSING, BE_AI_KEY_CUSTODY, BE_AI_GATEWAY_CLIENT]
1896
1915
  - id: be.integrations.model
1897
1916
  since: 3.1.0
1898
1917
  profiles: [be]
@@ -1902,7 +1921,7 @@ slots:
1902
1921
  tier: integrations
1903
1922
  tests: none
1904
1923
  coverage: required
1905
- why: an ML or LLM model client is an integration; weights and datasets are never in git
1924
+ why: a self-hosted ML model client is an integration; weights and datasets are never in git, and a language model is called through the ai-router gateway by the integrations/ai LangChain client (BE-AI-1, BE-AI-3)
1906
1925
  rules: [BE_TIER_DIRECTION, BE_INFRA_OWNER, BE_INTEGRATION_SPEC_MISSING]
1907
1926
 
1908
1927
  - id: be.integrations.supabase