@cosmicdrift/kumiko-guards 0.406.0 → 0.409.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-guards",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.409.0",
|
|
4
4
|
"description": "AST-based security guards for Kumiko repos: direct-fs/fetch, tenant escalation, admin-API, escape hatches and related checks, run over a shared ts-morph project.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"kumiko-pre-push": "./src/pre-push.sh"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@cosmicdrift/kumiko-types": "0.
|
|
39
|
+
"@cosmicdrift/kumiko-types": "0.409.0",
|
|
40
40
|
"ts-morph": "^28.0.0",
|
|
41
41
|
"zod": "^4.6.7"
|
|
42
42
|
},
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"LICENSE"
|
|
53
53
|
],
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@cosmicdrift/kumiko-framework": "0.
|
|
55
|
+
"@cosmicdrift/kumiko-framework": "0.409.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"@cosmicdrift/kumiko-framework": {
|
|
@@ -60,6 +60,6 @@
|
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@cosmicdrift/kumiko-framework": "0.
|
|
63
|
+
"@cosmicdrift/kumiko-framework": "0.409.0"
|
|
64
64
|
}
|
|
65
65
|
}
|
package/src/changes.json
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.409.0",
|
|
4
|
+
"type": "improvement",
|
|
5
|
+
"title": "Guard boot-raw-throws removed",
|
|
6
|
+
"detail": "The temporary `boot-raw-throws` guard and `.kumiko-boot-raw-throws-baseline.json` are deleted because every boot validator throw in the framework is migrated to a rule id. The guard only scanned the framework repo, so apps need no change."
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"version": "0.409.0",
|
|
10
|
+
"type": "improvement",
|
|
11
|
+
"title": "Cross-feature import guard scans .tsx and accepts web barrels",
|
|
12
|
+
"detail": "The guard scanned only .ts files, so a deep import across features from a .tsx screen or cell went through. It now scans .tsx as well (test files stay excluded). Next to the barrel, contract and schema/entity, another feature's web barrel (`../B/web`, `../B/web/index.ts`) is allowed, because browser code must not load the server barrel. Consumer note: after the bump, deep imports across feature boundaries in .tsx files fail the guard; import from the feature's barrel, its web barrel or its contract instead."
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"version": "0.409.0",
|
|
16
|
+
"type": "improvement",
|
|
17
|
+
"title": "no-custom-primitives knows the inbox widgets",
|
|
18
|
+
"detail": "The guard flags app components named MessageThread, MessageReader, StepList, ClampedText, AttachmentChip, HtmlMailFrame, SenderSheet, SenderFrame or AiSurface, so apps use the framework widgets instead of rebuilding them."
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"version": "0.408.0",
|
|
22
|
+
"type": "improvement",
|
|
23
|
+
"title": "No-Direct-Fs allowlists the static page writer",
|
|
24
|
+
"detail": "packages/server-runtime/src/static-html-pages.ts is on the No-Direct-Fs allowlist, next to run-prod-app-static-files.ts. It writes build output under the caller's outDir and checks page paths for traversal."
|
|
25
|
+
},
|
|
2
26
|
{
|
|
3
27
|
"version": "0.404.0",
|
|
4
28
|
"type": "improvement",
|
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
* What's enforced:
|
|
8
8
|
* - A file inside feature A may not import from feature B's internals.
|
|
9
9
|
* - Allowed cross-feature imports: the barrel (`from "../B"`, or
|
|
10
|
-
* `"../B/index"` / `"../B/index.ts"`),
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* `"../B/index"` / `"../B/index.ts"`), the client barrel (`"../B/web"`,
|
|
11
|
+
* `"../B/web/index"`), and two side-effect-free public surface modules,
|
|
12
|
+
* `"../B/contract"` and `"../B/schema/entity"` (with or without
|
|
13
|
+
* extension). Anything else — `from "../B/types"`,
|
|
13
14
|
* `from "../B/handlers/foo"`, `from "../B/feature"` — is rejected.
|
|
14
15
|
* - Same-feature relative imports (`./x`, `../sibling-in-same-feature`)
|
|
15
16
|
* stay unrestricted.
|
|
@@ -20,6 +21,10 @@
|
|
|
20
21
|
* sites. A rename inside B silently breaks A. The barrel is B's public
|
|
21
22
|
* contract — A only sees what B chose to export.
|
|
22
23
|
*
|
|
24
|
+
* The web barrel is B's client contract. Browser code (.tsx screens, cells)
|
|
25
|
+
* must not load B's server barrel, which pulls the whole server graph into
|
|
26
|
+
* the client bundle, so without it a screen would have no allowed path.
|
|
27
|
+
*
|
|
23
28
|
* Feature-boundary inference:
|
|
24
29
|
* - packages/bundled-features/src/<feature>/...
|
|
25
30
|
* - samples/<sample>/src/features/<feature>/...
|
|
@@ -46,11 +51,11 @@ const ROOT = process.cwd();
|
|
|
46
51
|
|
|
47
52
|
const SCAN: ScanSpec = {
|
|
48
53
|
scope: "source",
|
|
49
|
-
extensions: ["ts"],
|
|
54
|
+
extensions: ["ts", "tsx"],
|
|
50
55
|
frameworkWithin: ["packages/*/src/**", "samples/recipes/*/src/**", "samples/apps/*/src/**"],
|
|
51
56
|
};
|
|
52
57
|
|
|
53
|
-
const EXCLUDE = /(__tests__|\.test\.
|
|
58
|
+
const EXCLUDE = /(__tests__|\.test\.tsx?$|\.integration\.ts$|\.d\.ts$|\.g\.ts$)/;
|
|
54
59
|
|
|
55
60
|
// Files with an explicit, documented exception. Each entry must come with a
|
|
56
61
|
// TODO naming the planned refactor — the allowlist exists to turn the guard
|
|
@@ -136,6 +141,10 @@ const PUBLIC_SURFACE_MODULES = new Set([
|
|
|
136
141
|
"schema/entity",
|
|
137
142
|
"schema/entity.ts",
|
|
138
143
|
"schema/entity.tsx",
|
|
144
|
+
"web",
|
|
145
|
+
"web/index",
|
|
146
|
+
"web/index.ts",
|
|
147
|
+
"web/index.tsx",
|
|
139
148
|
]);
|
|
140
149
|
|
|
141
150
|
// True when the resolved import path points inside `featureRoot` AND
|
|
@@ -44,7 +44,7 @@ const IGNORE_TAG = "kumiko-lint-ignore no-custom-primitives";
|
|
|
44
44
|
|
|
45
45
|
// PascalCase + primitive suffix, or a known widget name.
|
|
46
46
|
const PRIMITIVE_NAME =
|
|
47
|
-
/^[A-Z]\w*(Card|Table|Badge|Button|Chart|Modal|Dialog|Tooltip|Spinner|Sparkline)$|^(ProgressBar|MiniStat|StatCard|EmptyState|LoadingState|ErrorState|ModeSwitch|Collapsible\w*|DetailList)$/;
|
|
47
|
+
/^[A-Z]\w*(Card|Table|Badge|Button|Chart|Modal|Dialog|Tooltip|Spinner|Sparkline)$|^(ProgressBar|MiniStat|StatCard|EmptyState|LoadingState|ErrorState|ModeSwitch|Collapsible\w*|DetailList|MessageThread|MessageReader|StepList|MobileTopBar|ClampedText|AttachmentChip|AttachmentCard|HtmlMailFrame|SenderSheet|SenderFrame|AiSurface)$/;
|
|
48
48
|
|
|
49
49
|
const RAW_FORM_TAGS = new Set(["input", "select", "textarea", "label"]);
|
|
50
50
|
|
|
@@ -115,6 +115,8 @@ const ALLOWLIST: readonly AllowEntry[] = [
|
|
|
115
115
|
repo: "kumiko-framework",
|
|
116
116
|
pattern: /^packages\/server-runtime\/src\/run-prod-app-static-files\.ts$/,
|
|
117
117
|
},
|
|
118
|
+
// Writes app build output (static HTML pages) under the caller's outDir; page paths are traversal-checked.
|
|
119
|
+
{ repo: "kumiko-framework", pattern: /^packages\/server-runtime\/src\/static-html-pages\.ts$/ },
|
|
118
120
|
// Package lookup for the build and the dev server: existence check for
|
|
119
121
|
// node_modules/<pkg>/package.json above a directory, no request input as a path.
|
|
120
122
|
{
|
package/src/run-guards.ts
CHANGED
|
@@ -25,7 +25,6 @@ import { guard as complexity } from "./check-complexity";
|
|
|
25
25
|
import { guard as predicateExtraction } from "./check-predicates";
|
|
26
26
|
import { guard as adminApi } from "./guard-admin-api";
|
|
27
27
|
import { guard as appFeatureStructure } from "./guard-app-feature-structure";
|
|
28
|
-
import { guard as bootRawThrows } from "./guard-boot-raw-throws";
|
|
29
28
|
import { guard as commentIssueRefOnly } from "./guard-comment-issue-ref-only";
|
|
30
29
|
import { guard as crossFeatureImports } from "./guard-cross-feature-imports";
|
|
31
30
|
import { guard as directEntityWrites } from "./guard-direct-entity-writes";
|
|
@@ -97,7 +96,6 @@ export const GUARDS = [
|
|
|
97
96
|
commentIssueRefOnly,
|
|
98
97
|
testTitle,
|
|
99
98
|
ignoreTagReason,
|
|
100
|
-
bootRawThrows,
|
|
101
99
|
];
|
|
102
100
|
|
|
103
101
|
export const GUARD_FLAGS = [
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
/**
|
|
3
|
-
* Boot Raw Throws Guard: freezes raw `throw new Error` in boot validation per file, because new boot rules use `throw bootRuleError(RULE, { message })` with a rule table in `<validator>-rules.ts`; the guard and its baseline `.kumiko-boot-raw-throws-baseline.json` are deleted once every file is at 0.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import path from "node:path";
|
|
7
|
-
import { type SourceFile, SyntaxKind } from "ts-morph";
|
|
8
|
-
import {
|
|
9
|
-
type AstGuard,
|
|
10
|
-
baselineRatchet,
|
|
11
|
-
buildSharedProject,
|
|
12
|
-
filesForGuard,
|
|
13
|
-
isLocalFinding,
|
|
14
|
-
relFromRepoRoot,
|
|
15
|
-
runStandalone,
|
|
16
|
-
type ScanSpec,
|
|
17
|
-
} from "./_lib/guard-kit";
|
|
18
|
-
import { resolveRepoRoots } from "./_lib/roots";
|
|
19
|
-
|
|
20
|
-
const ROOT = process.cwd();
|
|
21
|
-
const GUARD_NAME = "boot-raw-throws";
|
|
22
|
-
|
|
23
|
-
const SCAN: ScanSpec = {
|
|
24
|
-
scope: "source",
|
|
25
|
-
kinds: ["framework"],
|
|
26
|
-
extensions: ["ts"],
|
|
27
|
-
frameworkWithin: [
|
|
28
|
-
"packages/framework/src/engine/boot-validator/**",
|
|
29
|
-
"packages/bundled-features/src/*/boot-checks.ts",
|
|
30
|
-
],
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const EXCLUDE = /(__tests__|\.test\.ts$|\.d\.ts$)/;
|
|
34
|
-
|
|
35
|
-
export function rawErrorThrowLines(file: SourceFile): number[] {
|
|
36
|
-
return file
|
|
37
|
-
.getDescendantsOfKind(SyntaxKind.ThrowStatement)
|
|
38
|
-
.filter((statement) => {
|
|
39
|
-
const thrown = statement.getExpression();
|
|
40
|
-
return (
|
|
41
|
-
thrown.isKind(SyntaxKind.NewExpression) && thrown.getExpression().getText() === "Error"
|
|
42
|
-
);
|
|
43
|
-
})
|
|
44
|
-
.map((statement) => statement.getStartLineNumber());
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function rawThrowCounts(
|
|
48
|
-
files: readonly SourceFile[],
|
|
49
|
-
roots: ReadonlyArray<{ readonly absPath: string }> = resolveRepoRoots(),
|
|
50
|
-
): { counts: Record<string, number>; firstLine: Record<string, number> } {
|
|
51
|
-
const counts: Record<string, number> = {};
|
|
52
|
-
const firstLine: Record<string, number> = {};
|
|
53
|
-
for (const sf of files) {
|
|
54
|
-
if (EXCLUDE.test(sf.getFilePath())) continue;
|
|
55
|
-
const lines = rawErrorThrowLines(sf);
|
|
56
|
-
const first = lines[0];
|
|
57
|
-
if (first === undefined) continue;
|
|
58
|
-
const file = relFromRepoRoot(sf.getFilePath(), roots);
|
|
59
|
-
if (!isLocalFinding({ file })) continue;
|
|
60
|
-
counts[file] = lines.length;
|
|
61
|
-
firstLine[file] = first;
|
|
62
|
-
}
|
|
63
|
-
return { counts, firstLine };
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const rawThrowBaseline = baselineRatchet({
|
|
67
|
-
file: path.join(ROOT, ".kumiko-boot-raw-throws-baseline.json"),
|
|
68
|
-
formatVersion: 1,
|
|
69
|
-
unit: "raw throw new Error in boot validation",
|
|
70
|
-
failClosed: true,
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const REMEDIATION =
|
|
74
|
-
"Declare the rule in the validator's `<validator>-rules.ts` table and throw `bootRuleError(RULES.name, { message })` instead of `new Error(...)`.";
|
|
75
|
-
|
|
76
|
-
export const guard: AstGuard = {
|
|
77
|
-
name: GUARD_NAME,
|
|
78
|
-
scan: SCAN,
|
|
79
|
-
hint: `after fixing hits: \`kumiko-guards guards --write-baseline --guard=${GUARD_NAME}\``,
|
|
80
|
-
run: (files, roots = resolveRepoRoots()) => {
|
|
81
|
-
const { counts, firstLine } = rawThrowCounts(files, roots);
|
|
82
|
-
return {
|
|
83
|
-
violations: rawThrowBaseline.check(counts, REMEDIATION, {
|
|
84
|
-
formatDriftRemediation: `Run \`kumiko-guards guards --write-baseline --guard=${GUARD_NAME}\` once.`,
|
|
85
|
-
resolveLine: (file) => firstLine[file] ?? 1,
|
|
86
|
-
}),
|
|
87
|
-
};
|
|
88
|
-
},
|
|
89
|
-
writeBaseline: (files, roots = resolveRepoRoots()) => {
|
|
90
|
-
rawThrowBaseline.write(rawThrowCounts(files, roots).counts);
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
if (import.meta.main) {
|
|
95
|
-
if (process.argv.slice(2).includes("--write-baseline")) {
|
|
96
|
-
const project = buildSharedProject([guard]);
|
|
97
|
-
guard.writeBaseline?.(filesForGuard(project, guard));
|
|
98
|
-
process.exit(0);
|
|
99
|
-
}
|
|
100
|
-
runStandalone(guard);
|
|
101
|
-
}
|