@gate-forge/cli 0.3.0 → 0.4.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/README.md +76 -0
- package/dist/args.js +1 -1
- package/dist/args.js.map +1 -1
- package/dist/commands/init.d.ts +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +91 -2
- package/dist/commands/init.js.map +1 -1
- package/dist/endpoint-compiler.d.ts +3 -1
- package/dist/endpoint-compiler.d.ts.map +1 -1
- package/dist/endpoint-compiler.js +92 -3
- package/dist/endpoint-compiler.js.map +1 -1
- package/dist/endpoint-config.d.ts +144 -0
- package/dist/endpoint-config.d.ts.map +1 -0
- package/dist/endpoint-config.js +245 -0
- package/dist/endpoint-config.js.map +1 -0
- package/dist/input-snapshot.d.ts.map +1 -1
- package/dist/input-snapshot.js +1 -1
- package/dist/input-snapshot.js.map +1 -1
- package/dist/planes-inference.d.ts +49 -0
- package/dist/planes-inference.d.ts.map +1 -0
- package/dist/planes-inference.js +122 -0
- package/dist/planes-inference.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plane-config inference for `gateforge init --planes`.
|
|
3
|
+
*
|
|
4
|
+
* Unconfigured repos block every table with `PLANE_UNRESOLVED` — the
|
|
5
|
+
* classifier never guesses across tenant/master/global (ADR 0003 D5) —
|
|
6
|
+
* so init can PROPOSE `.gateforge/planes.json` from what discovery
|
|
7
|
+
* actually saw: the source directories of the discovered business
|
|
8
|
+
* tables. The proposal is a review artifact, never a silent decision:
|
|
9
|
+
* every rule carries a reason naming the directory it was inferred
|
|
10
|
+
* from, init writes the file only on explicit consent, and the user is
|
|
11
|
+
* told to review it before the next run.
|
|
12
|
+
*
|
|
13
|
+
* Semantics (deterministic, conservative):
|
|
14
|
+
* - tables under conventional test directories (`tests/`, `test/`) are
|
|
15
|
+
* EXCLUDED from inference: they are fixtures, not business tables,
|
|
16
|
+
* and a rule endorsing them would misclassify them as business
|
|
17
|
+
* surface (they stay plane-less and gate-visible instead);
|
|
18
|
+
* - source directories are grouped into MODEL TREES under the longest
|
|
19
|
+
* common directory prefix, one non-overlapping `match` glob per tree;
|
|
20
|
+
* - a tree whose path names a control-plane segment (`admin`, `master`,
|
|
21
|
+
* `control`, `root`, `operator`) proposes `master`; everything else
|
|
22
|
+
* proposes `tenant`. A keyword heuristic IS a guess — but a
|
|
23
|
+
* reviewable one, written into the file with its evidence, never a
|
|
24
|
+
* runtime inference.
|
|
25
|
+
*/
|
|
26
|
+
import { dirname } from 'node:path';
|
|
27
|
+
/** Directory segments that mark test fixtures (exact segment match). */
|
|
28
|
+
const TEST_SEGMENTS = new Set(['tests', 'test']);
|
|
29
|
+
/** Path keywords that mark a control-plane (master) model tree. */
|
|
30
|
+
const MASTER_KEYWORDS = ['admin', 'master', 'control', 'root', 'operator'];
|
|
31
|
+
/** The posix directory of a repo-relative source path ('' at the root). */
|
|
32
|
+
function directoryOf(source) {
|
|
33
|
+
const normalized = source.replaceAll('\\', '/');
|
|
34
|
+
const index = normalized.lastIndexOf('/');
|
|
35
|
+
return index === -1 ? '' : normalized.slice(0, index);
|
|
36
|
+
}
|
|
37
|
+
/** Whether any path segment marks the path as test fixture surface. */
|
|
38
|
+
function isTestPath(source) {
|
|
39
|
+
return source
|
|
40
|
+
.replaceAll('\\', '/')
|
|
41
|
+
.split('/')
|
|
42
|
+
.slice(0, -1)
|
|
43
|
+
.some((segment) => TEST_SEGMENTS.has(segment));
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Whether the relative directory names a control-plane tree (a keyword
|
|
47
|
+
* appears as a segment substring, case-insensitive: `admin_platform`,
|
|
48
|
+
* `Master`, `control-plane` all match).
|
|
49
|
+
*/
|
|
50
|
+
function isMasterTree(relativeDir) {
|
|
51
|
+
const lower = relativeDir.toLowerCase();
|
|
52
|
+
return MASTER_KEYWORDS.some((keyword) => lower.includes(keyword));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Derives a proposed planes config from discovered table source paths.
|
|
56
|
+
* Pure over its input; the caller owns consent and the write.
|
|
57
|
+
*
|
|
58
|
+
* Args:
|
|
59
|
+
* tableSources: Repo-root-relative source paths of discovered
|
|
60
|
+
* `sqlalchemy.table` resources.
|
|
61
|
+
*
|
|
62
|
+
* Returns:
|
|
63
|
+
* PlaneInference: The proposal with diagnostics; `config` is null
|
|
64
|
+
* when no table was discovered (nothing to map) — the note says so.
|
|
65
|
+
*/
|
|
66
|
+
export function inferPlanesConfig(tableSources) {
|
|
67
|
+
const unique = [...new Set(tableSources)].sort();
|
|
68
|
+
if (unique.length === 0) {
|
|
69
|
+
return { config: null, note: 'no sqlalchemy tables discovered — nothing to propose', skippedTestTables: 0 };
|
|
70
|
+
}
|
|
71
|
+
const business = unique.filter((source) => !isTestPath(source));
|
|
72
|
+
const skippedTestTables = unique.length - business.length;
|
|
73
|
+
if (business.length === 0) {
|
|
74
|
+
return {
|
|
75
|
+
config: null,
|
|
76
|
+
note: 'every discovered table lives under a test directory — no business plane to propose ' +
|
|
77
|
+
'(exclude test paths from the scan or classify them deliberately)',
|
|
78
|
+
skippedTestTables,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
// Longest common directory prefix of the business trees (segment-wise).
|
|
82
|
+
const dirs = business.map(directoryOf);
|
|
83
|
+
let prefix = dirs[0]?.split('/') ?? [];
|
|
84
|
+
for (const dir of dirs.slice(1)) {
|
|
85
|
+
const segments = dir.split('/');
|
|
86
|
+
let common = 0;
|
|
87
|
+
while (common < prefix.length && common < segments.length && prefix[common] === segments[common]) {
|
|
88
|
+
common += 1;
|
|
89
|
+
}
|
|
90
|
+
prefix = prefix.slice(0, common);
|
|
91
|
+
if (prefix.length === 0)
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
const prefixPath = prefix.join('/');
|
|
95
|
+
// One group per directory segment directly under the prefix (files
|
|
96
|
+
// directly IN the prefix form their own group), so the resulting
|
|
97
|
+
// `match` globs never overlap — overlapping plane rules with
|
|
98
|
+
// different planes would block as PLANE_RULE_CONTRADICTION at runtime.
|
|
99
|
+
const groups = new Map();
|
|
100
|
+
for (const dir of dirs) {
|
|
101
|
+
const relative = prefixPath.length === 0 ? dir : dir.startsWith(`${prefixPath}/`) ? dir.slice(prefixPath.length + 1) : '';
|
|
102
|
+
const head = relative === '' ? '' : (relative.split('/')[0] ?? '');
|
|
103
|
+
groups.set(head, (groups.get(head) ?? 0) + 1);
|
|
104
|
+
}
|
|
105
|
+
const rules = [];
|
|
106
|
+
for (const head of [...groups.keys()].sort()) {
|
|
107
|
+
const treePath = head === '' ? prefixPath : prefixPath.length === 0 ? head : `${prefixPath}/${head}`;
|
|
108
|
+
// `P/<seg>/**` covers the subtree; the files-directly-under-P group
|
|
109
|
+
// covers exactly one level (`P/*.py`) so the globs stay disjoint.
|
|
110
|
+
const match = head === '' ? (prefixPath.length === 0 ? '*.py' : `${prefixPath}/*.py`) : `${treePath}/**`;
|
|
111
|
+
const plane = isMasterTree(head === '' ? prefixPath : head) ? 'master' : 'tenant';
|
|
112
|
+
rules.push({
|
|
113
|
+
match,
|
|
114
|
+
plane,
|
|
115
|
+
reason: `inferred from model directory '${treePath}' by gateforge init; ` +
|
|
116
|
+
'review before relying on this',
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
rules.sort((a, b) => (a.match ?? '').localeCompare(b.match ?? ''));
|
|
120
|
+
return { config: { rules }, note: null, skippedTestTables };
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=planes-inference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planes-inference.js","sourceRoot":"","sources":["../src/planes-inference.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,wEAAwE;AACxE,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC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