@krisada-m/ksd-intelligence 0.0.0-stage → 1.1.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/.antigravity-plugin/plugin.json +20 -0
- package/LICENSE +21 -0
- package/README.md +195 -2
- package/agy-skills/erosiano-review/SKILL.md +17 -0
- package/dist/adapters/agy/skills.js +252 -0
- package/dist/adapters/cli/check-changed.js +3 -0
- package/dist/adapters/cli/main.js +1013 -0
- package/dist/adapters/cli/policy-bin.js +10 -0
- package/dist/adapters/cli/review-verdict.js +3 -0
- package/dist/adapters/omp/extension.js +884 -0
- package/dist/adapters/omp/skills.js +130 -0
- package/dist/adapters/ui/hud.js +389 -0
- package/dist/adapters/ui/tree.js +471 -0
- package/dist/core/audit/index.js +2 -0
- package/dist/core/audit/log.js +505 -0
- package/dist/core/audit/summary.js +188 -0
- package/dist/core/changes/changes.js +591 -0
- package/dist/core/changes/git.js +266 -0
- package/dist/core/changes/plan.js +109 -0
- package/dist/core/changes/render.js +356 -0
- package/dist/core/engine/build.js +178 -0
- package/dist/core/engine/child.js +389 -0
- package/dist/core/engine/host.js +206 -0
- package/dist/core/engine/lock.js +133 -0
- package/dist/core/engine/protocol.js +43 -0
- package/dist/core/engine/runtime.js +44 -0
- package/dist/core/engine/status.js +452 -0
- package/dist/core/engine/typescript.js +194 -0
- package/dist/core/engine/workspace.js +72 -0
- package/dist/core/graph/graph.js +127 -0
- package/dist/core/graph/limits.js +16 -0
- package/dist/core/impact/query.js +1292 -0
- package/dist/core/impact/render.js +590 -0
- package/dist/core/impact/session.js +694 -0
- package/dist/core/indexing/declarations.js +455 -0
- package/dist/core/indexing/differential.js +345 -0
- package/dist/core/indexing/doctor.js +120 -0
- package/dist/core/indexing/indexer.js +811 -0
- package/dist/core/indexing/keys.js +451 -0
- package/dist/core/indexing/lexical.js +212 -0
- package/dist/core/indexing/packages.js +57 -0
- package/dist/core/indexing/program.js +171 -0
- package/dist/core/indexing/resolve.js +1004 -0
- package/dist/core/indexing/stamp.js +52 -0
- package/dist/core/indexing/surface.js +335 -0
- package/dist/core/indexing/ui-progress.js +37 -0
- package/dist/core/indexing/verify.js +76 -0
- package/dist/core/kernel/config.js +383 -0
- package/dist/core/kernel/glob.js +105 -0
- package/dist/core/kernel/guards.js +4 -0
- package/dist/core/kernel/types.js +3 -0
- package/dist/core/kernel/verdict.js +142 -0
- package/dist/core/knowledge/anchors.js +139 -0
- package/dist/core/knowledge/knowledge.js +95 -0
- package/dist/core/knowledge/learning.js +102 -0
- package/dist/core/knowledge/render.js +76 -0
- package/dist/core/knowledge/store.js +109 -0
- package/dist/core/knowledge/yaml.js +87 -0
- package/dist/core/search/lexical.js +382 -0
- package/dist/core/search/render.js +98 -0
- package/dist/core/search/segments.js +118 -0
- package/dist/core/verify/parse.js +127 -0
- package/dist/core/verify/render.js +67 -0
- package/dist/core/verify/report.js +40 -0
- package/dist/core/verify/revision.js +79 -0
- package/dist/core/verify/run.js +117 -0
- package/dist/core/verify/store.js +66 -0
- package/dist/core/verify/verify.js +173 -0
- package/dist/core/workspace/init.js +267 -0
- package/dist/core/workspace/probe.js +56 -0
- package/dist/core/workspace/scan.js +420 -0
- package/dist/engineering/baseline.js +337 -0
- package/dist/engineering/change-scope.js +500 -0
- package/dist/engineering/check-changed.js +40 -0
- package/dist/engineering/config.js +129 -0
- package/dist/engineering/dist/policy.d.ts +17 -0
- package/dist/engineering/dist/policy.js +150 -0
- package/dist/engineering/dist/runtime.d.ts +40 -0
- package/dist/engineering/dist/runtime.js +77 -0
- package/dist/engineering/dist/sdlc.d.ts +7 -0
- package/dist/engineering/dist/sdlc.js +27 -0
- package/dist/engineering/eslint-rules/index.js +107 -0
- package/dist/engineering/index.d.ts +7 -0
- package/dist/engineering/index.js +319 -0
- package/dist/engineering/intelligence.js +44 -0
- package/dist/engineering/package.json +36 -0
- package/dist/engineering/policy.js +2 -0
- package/dist/engineering/practice-tool.js +72 -0
- package/dist/engineering/practices.js +283 -0
- package/dist/engineering/practices.json +2453 -0
- package/dist/engineering/review-verdict.js +262 -0
- package/dist/engineering/sdlc.js +2 -0
- package/dist/index.js +20 -0
- package/dist/storage/records.js +245 -0
- package/dist/storage/sqlite.js +314 -0
- package/dist/workflow/catalog.js +69 -0
- package/dist/workflow/classify.js +55 -0
- package/dist/workflow/loader.js +140 -0
- package/dist/workflow/packs.js +469 -0
- package/dist/workflow/registry.js +359 -0
- package/dist/workflow/render.js +61 -0
- package/dist/workflow/router.js +141 -0
- package/dist/workflow/sources.js +229 -0
- package/dist/workflow/types.js +44 -0
- package/dist/workflow/updates.js +532 -0
- package/engineering.lock.json +94 -0
- package/package.json +81 -4
- package/rules/engineering.md +20 -0
- package/scripts/agy-mcp.mjs +27 -0
- package/scripts/mcp/engineering.mjs +91 -0
- package/scripts/mcp/stdio.mjs +304 -0
- package/scripts/mcp/tools.mjs +491 -0
- package/skills/ksd-intelligence/SKILL.md +54 -0
- package/skills/matt-sdlc/SKILL.md +42 -0
- package/skills/osmani-quality/SKILL.md +38 -0
- package/skills/poteto-mode/SKILL.md +40 -0
- package/skills/pstack-analysis/SKILL.md +36 -0
- package/skills.lock.json +71 -0
- package/skills.registry.json +181 -0
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import { isRecord } from './guards.js';
|
|
2
|
+
export const DEFAULT_RISK_ZONES = [
|
|
3
|
+
{
|
|
4
|
+
zone: 'payments',
|
|
5
|
+
floor: 'high',
|
|
6
|
+
match: ['**/payments/**', '**/billing/**', '**/subscription*/**'],
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
zone: 'auth',
|
|
10
|
+
floor: 'high',
|
|
11
|
+
match: ['**/auth/**', '**/session*/**', '**/middleware.ts'],
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
zone: 'migrations',
|
|
15
|
+
floor: 'critical',
|
|
16
|
+
match: ['**/migrations/**', '**/*.sql', '**/schema.prisma', '**/drizzle/**'],
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
zone: 'prod-config',
|
|
20
|
+
floor: 'critical',
|
|
21
|
+
match: ['**/.env*', '**/*production*.{json,ts,yaml,yml}'],
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
export function defaultConfig(inferred) {
|
|
25
|
+
return {
|
|
26
|
+
skills: { enabled: true },
|
|
27
|
+
impact: {
|
|
28
|
+
enabled: true,
|
|
29
|
+
include: inferred?.include ?? ['packages/**', 'apps/**'],
|
|
30
|
+
exclude: ['**/dist/**'],
|
|
31
|
+
routes: inferred?.routes ?? [],
|
|
32
|
+
maxDepth: 10,
|
|
33
|
+
freshness: 'stat',
|
|
34
|
+
watch: true,
|
|
35
|
+
manyCallers: 10,
|
|
36
|
+
commonName: 10,
|
|
37
|
+
useWorkspaceTypescript: false,
|
|
38
|
+
maxMemoryMb: null,
|
|
39
|
+
},
|
|
40
|
+
bridges: {
|
|
41
|
+
B1: true,
|
|
42
|
+
B2: true,
|
|
43
|
+
B3: true,
|
|
44
|
+
B4: true,
|
|
45
|
+
B5: true,
|
|
46
|
+
B6: true,
|
|
47
|
+
},
|
|
48
|
+
search: { enabled: true, semantic: false },
|
|
49
|
+
riskZones: 'default',
|
|
50
|
+
context: { enabled: false },
|
|
51
|
+
compression: { enabled: false },
|
|
52
|
+
knowledge: { enabled: false },
|
|
53
|
+
verification: { enabled: false },
|
|
54
|
+
gitlab: {
|
|
55
|
+
enabled: false,
|
|
56
|
+
host: 'https://gitlab.example.com',
|
|
57
|
+
project: 'group/repo',
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function isStringArray(value) {
|
|
62
|
+
return Array.isArray(value) && value.every((item) => typeof item === 'string');
|
|
63
|
+
}
|
|
64
|
+
function isPositiveInteger(value) {
|
|
65
|
+
return typeof value === 'number' && Number.isInteger(value) && value > 0;
|
|
66
|
+
}
|
|
67
|
+
/** Names of checks and reports: no spaces, separators, quotes or path characters. */
|
|
68
|
+
export const VERIFY_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/;
|
|
69
|
+
const MAX_CHECK_TIMEOUT_SEC = 3600;
|
|
70
|
+
const DEFAULT_CHECK_TIMEOUT_SEC = 600;
|
|
71
|
+
function parseCheckEntry(entry, index, errors) {
|
|
72
|
+
const where = `verification.checks[${index}]`;
|
|
73
|
+
if (!isRecord(entry)) {
|
|
74
|
+
errors.push(`${where} must be an object; ignored`);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
if (typeof entry.name !== 'string' || !VERIFY_NAME_RE.test(entry.name)) {
|
|
78
|
+
errors.push(`${where}.name must match ${VERIFY_NAME_RE.source}; ignored`);
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
const command = entry.command;
|
|
82
|
+
if (!isStringArray(command) ||
|
|
83
|
+
command.length === 0 ||
|
|
84
|
+
command.some((part) => part === '' || part.includes('\0'))) {
|
|
85
|
+
errors.push(`${where}.command must be a non-empty array of non-empty strings; ignored`);
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
if (entry.timeoutSec === undefined) {
|
|
89
|
+
return { name: entry.name, command: [...command], timeoutSec: DEFAULT_CHECK_TIMEOUT_SEC };
|
|
90
|
+
}
|
|
91
|
+
if (!isPositiveInteger(entry.timeoutSec) || entry.timeoutSec > MAX_CHECK_TIMEOUT_SEC) {
|
|
92
|
+
errors.push(`${where}.timeoutSec must be an integer 1–${MAX_CHECK_TIMEOUT_SEC}; ignored`);
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
return { name: entry.name, command: [...command], timeoutSec: entry.timeoutSec };
|
|
96
|
+
}
|
|
97
|
+
function isRepoRelativePath(path) {
|
|
98
|
+
if (path === '' || path.includes('\0') || path.startsWith('/') || /^[A-Za-z]:/.test(path)) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
return !path.split(/[\\/]/).some((segment) => segment === '..');
|
|
102
|
+
}
|
|
103
|
+
function parseReportEntry(entry, index, errors) {
|
|
104
|
+
const where = `verification.reports[${index}]`;
|
|
105
|
+
if (!isRecord(entry)) {
|
|
106
|
+
errors.push(`${where} must be an object; ignored`);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
if (typeof entry.name !== 'string' || !VERIFY_NAME_RE.test(entry.name)) {
|
|
110
|
+
errors.push(`${where}.name must match ${VERIFY_NAME_RE.source}; ignored`);
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
if (entry.format !== 'junit' && entry.format !== 'tap') {
|
|
114
|
+
errors.push(`${where}.format must be "junit" or "tap"; ignored`);
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
if (typeof entry.path !== 'string' || !isRepoRelativePath(entry.path)) {
|
|
118
|
+
errors.push(`${where}.path must be a repository-relative path; ignored`);
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
if (entry.covers !== undefined && (!isStringArray(entry.covers) || entry.covers.length === 0)) {
|
|
122
|
+
errors.push(`${where}.covers must be a non-empty array of globs; ignored`);
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
name: entry.name,
|
|
127
|
+
format: entry.format,
|
|
128
|
+
path: entry.path,
|
|
129
|
+
covers: entry.covers === undefined ? ['**'] : [...entry.covers],
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function parseNamedList(value, key, parseEntry, errors) {
|
|
133
|
+
if (value === undefined)
|
|
134
|
+
return undefined;
|
|
135
|
+
if (!Array.isArray(value)) {
|
|
136
|
+
errors.push(`verification.${key} must be an array; ignored`);
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
139
|
+
const out = [];
|
|
140
|
+
value.forEach((entry, index) => {
|
|
141
|
+
const parsed = parseEntry(entry, index, errors);
|
|
142
|
+
if (parsed === null)
|
|
143
|
+
return;
|
|
144
|
+
if (out.some((existing) => existing.name === parsed.name)) {
|
|
145
|
+
errors.push(`verification.${key}[${index}].name "${parsed.name}" is a duplicate; ignored`);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
out.push(parsed);
|
|
149
|
+
});
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
function parseVerification(section, fallback, errors) {
|
|
153
|
+
if (section === undefined)
|
|
154
|
+
return fallback;
|
|
155
|
+
if (!isRecord(section) || typeof section.enabled !== 'boolean') {
|
|
156
|
+
errors.push('Invalid or missing "verification" section; using defaults');
|
|
157
|
+
return fallback;
|
|
158
|
+
}
|
|
159
|
+
const checks = parseNamedList(section.checks, 'checks', parseCheckEntry, errors);
|
|
160
|
+
const reports = parseNamedList(section.reports, 'reports', parseReportEntry, errors);
|
|
161
|
+
return {
|
|
162
|
+
enabled: section.enabled,
|
|
163
|
+
...(checks === undefined ? {} : { checks }),
|
|
164
|
+
...(reports === undefined ? {} : { reports }),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function parseToggle(section, fallback, name, errors) {
|
|
168
|
+
if (section === undefined)
|
|
169
|
+
return fallback;
|
|
170
|
+
if (!isRecord(section) || typeof section.enabled !== 'boolean') {
|
|
171
|
+
errors.push(`Invalid or missing "${name}" section; using defaults`);
|
|
172
|
+
return fallback;
|
|
173
|
+
}
|
|
174
|
+
return { enabled: section.enabled };
|
|
175
|
+
}
|
|
176
|
+
function parseImpact(section, fallback, errors) {
|
|
177
|
+
if (section === undefined)
|
|
178
|
+
return fallback;
|
|
179
|
+
if (!isRecord(section)) {
|
|
180
|
+
errors.push('Invalid "impact" section; using defaults');
|
|
181
|
+
return fallback;
|
|
182
|
+
}
|
|
183
|
+
const enabled = typeof section.enabled === 'boolean' ? section.enabled : fallback.enabled;
|
|
184
|
+
const include = isStringArray(section.include) ? section.include : fallback.include;
|
|
185
|
+
const exclude = isStringArray(section.exclude) ? section.exclude : fallback.exclude;
|
|
186
|
+
const routes = isStringArray(section.routes) ? section.routes : fallback.routes;
|
|
187
|
+
const maxDepth = typeof section.maxDepth === 'number' && section.maxDepth > 0
|
|
188
|
+
? section.maxDepth
|
|
189
|
+
: fallback.maxDepth;
|
|
190
|
+
const freshness = section.freshness === 'stat' || section.freshness === 'hash'
|
|
191
|
+
? section.freshness
|
|
192
|
+
: fallback.freshness;
|
|
193
|
+
const watch = typeof section.watch === 'boolean' ? section.watch : fallback.watch;
|
|
194
|
+
const manyCallers = typeof section.manyCallers === 'number' && section.manyCallers > 0
|
|
195
|
+
? section.manyCallers
|
|
196
|
+
: fallback.manyCallers;
|
|
197
|
+
const commonName = typeof section.commonName === 'number' && section.commonName > 0
|
|
198
|
+
? section.commonName
|
|
199
|
+
: fallback.commonName;
|
|
200
|
+
const useWorkspaceTypescript = typeof section.useWorkspaceTypescript === 'boolean'
|
|
201
|
+
? section.useWorkspaceTypescript
|
|
202
|
+
: fallback.useWorkspaceTypescript;
|
|
203
|
+
const maxMemoryMb = section.maxMemoryMb === null || isPositiveInteger(section.maxMemoryMb)
|
|
204
|
+
? section.maxMemoryMb
|
|
205
|
+
: fallback.maxMemoryMb;
|
|
206
|
+
if (section.enabled !== undefined && typeof section.enabled !== 'boolean') {
|
|
207
|
+
errors.push('impact.enabled must be boolean');
|
|
208
|
+
}
|
|
209
|
+
if (section.include !== undefined && !isStringArray(section.include)) {
|
|
210
|
+
errors.push('impact.include must be string[]');
|
|
211
|
+
}
|
|
212
|
+
if (section.exclude !== undefined && !isStringArray(section.exclude)) {
|
|
213
|
+
errors.push('impact.exclude must be string[]');
|
|
214
|
+
}
|
|
215
|
+
if (section.routes !== undefined && !isStringArray(section.routes)) {
|
|
216
|
+
errors.push('impact.routes must be string[]');
|
|
217
|
+
}
|
|
218
|
+
if (section.maxDepth !== undefined &&
|
|
219
|
+
(typeof section.maxDepth !== 'number' || section.maxDepth <= 0)) {
|
|
220
|
+
errors.push('impact.maxDepth must be positive number');
|
|
221
|
+
}
|
|
222
|
+
if (section.freshness !== undefined &&
|
|
223
|
+
section.freshness !== 'stat' &&
|
|
224
|
+
section.freshness !== 'hash') {
|
|
225
|
+
errors.push('impact.freshness must be "stat" | "hash"');
|
|
226
|
+
}
|
|
227
|
+
if (section.watch !== undefined && typeof section.watch !== 'boolean') {
|
|
228
|
+
errors.push('impact.watch must be boolean');
|
|
229
|
+
}
|
|
230
|
+
if (section.manyCallers !== undefined &&
|
|
231
|
+
(typeof section.manyCallers !== 'number' || section.manyCallers <= 0)) {
|
|
232
|
+
errors.push('impact.manyCallers must be positive number');
|
|
233
|
+
}
|
|
234
|
+
if (section.commonName !== undefined &&
|
|
235
|
+
(typeof section.commonName !== 'number' || section.commonName <= 0)) {
|
|
236
|
+
errors.push('impact.commonName must be positive number');
|
|
237
|
+
}
|
|
238
|
+
if (section.useWorkspaceTypescript !== undefined &&
|
|
239
|
+
typeof section.useWorkspaceTypescript !== 'boolean') {
|
|
240
|
+
errors.push('impact.useWorkspaceTypescript must be boolean');
|
|
241
|
+
}
|
|
242
|
+
if (section.maxMemoryMb !== undefined &&
|
|
243
|
+
section.maxMemoryMb !== null &&
|
|
244
|
+
!isPositiveInteger(section.maxMemoryMb)) {
|
|
245
|
+
errors.push('impact.maxMemoryMb must be a positive integer or null');
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
enabled,
|
|
249
|
+
include,
|
|
250
|
+
exclude,
|
|
251
|
+
routes,
|
|
252
|
+
maxDepth,
|
|
253
|
+
freshness,
|
|
254
|
+
watch,
|
|
255
|
+
manyCallers,
|
|
256
|
+
commonName,
|
|
257
|
+
useWorkspaceTypescript,
|
|
258
|
+
maxMemoryMb,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
function parseBridges(section, fallback, errors) {
|
|
262
|
+
if (section === undefined)
|
|
263
|
+
return fallback;
|
|
264
|
+
if (!isRecord(section)) {
|
|
265
|
+
errors.push('Invalid "bridges" section; using defaults');
|
|
266
|
+
return fallback;
|
|
267
|
+
}
|
|
268
|
+
const result = {};
|
|
269
|
+
for (const [key, value] of Object.entries(section)) {
|
|
270
|
+
if (typeof value === 'boolean') {
|
|
271
|
+
result[key] = value;
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
errors.push(`bridges.${key} must be boolean`);
|
|
275
|
+
result[key] = fallback[key] ?? true;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return result;
|
|
279
|
+
}
|
|
280
|
+
function parseSearch(section, fallback, errors) {
|
|
281
|
+
if (section === undefined)
|
|
282
|
+
return fallback;
|
|
283
|
+
if (!isRecord(section)) {
|
|
284
|
+
errors.push('Invalid "search" section; using defaults');
|
|
285
|
+
return fallback;
|
|
286
|
+
}
|
|
287
|
+
const enabled = typeof section.enabled === 'boolean' ? section.enabled : fallback.enabled;
|
|
288
|
+
const semantic = typeof section.semantic === 'boolean' ? section.semantic : fallback.semantic;
|
|
289
|
+
if (section.enabled !== undefined && typeof section.enabled !== 'boolean') {
|
|
290
|
+
errors.push('search.enabled must be boolean');
|
|
291
|
+
}
|
|
292
|
+
if (section.semantic !== undefined && typeof section.semantic !== 'boolean') {
|
|
293
|
+
errors.push('search.semantic must be boolean');
|
|
294
|
+
}
|
|
295
|
+
return { enabled, semantic };
|
|
296
|
+
}
|
|
297
|
+
export function resolveRiskZones(riskZones) {
|
|
298
|
+
if (riskZones === undefined)
|
|
299
|
+
return [];
|
|
300
|
+
return riskZones === 'default' ? DEFAULT_RISK_ZONES : riskZones;
|
|
301
|
+
}
|
|
302
|
+
function parseRiskZones(section, fallback, errors) {
|
|
303
|
+
if (section === undefined || section === 'default') {
|
|
304
|
+
return 'default';
|
|
305
|
+
}
|
|
306
|
+
if (!Array.isArray(section)) {
|
|
307
|
+
errors.push('riskZones must be "default" or array of RiskZoneConfig');
|
|
308
|
+
return fallback;
|
|
309
|
+
}
|
|
310
|
+
const validZones = [];
|
|
311
|
+
let hasInvalid = false;
|
|
312
|
+
for (let i = 0; i < section.length; i++) {
|
|
313
|
+
const item = section[i];
|
|
314
|
+
if (isRecord(item) &&
|
|
315
|
+
typeof item.zone === 'string' &&
|
|
316
|
+
item.zone.trim() !== '' &&
|
|
317
|
+
(item.floor === 'high' || item.floor === 'critical') &&
|
|
318
|
+
isStringArray(item.match) &&
|
|
319
|
+
item.match.length > 0 &&
|
|
320
|
+
item.match.every((pattern) => pattern.trim() !== '')) {
|
|
321
|
+
validZones.push({
|
|
322
|
+
zone: item.zone.trim(),
|
|
323
|
+
floor: item.floor,
|
|
324
|
+
match: item.match,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
hasInvalid = true;
|
|
329
|
+
errors.push(`Invalid item in riskZones[${i}]`);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return hasInvalid ? fallback : validZones;
|
|
333
|
+
}
|
|
334
|
+
function parseGitlab(section, fallback, errors) {
|
|
335
|
+
if (section === undefined)
|
|
336
|
+
return fallback;
|
|
337
|
+
if (!isRecord(section)) {
|
|
338
|
+
errors.push('Invalid "gitlab" section; using defaults');
|
|
339
|
+
return fallback;
|
|
340
|
+
}
|
|
341
|
+
const enabled = typeof section.enabled === 'boolean' ? section.enabled : fallback.enabled;
|
|
342
|
+
const host = typeof section.host === 'string' ? section.host : fallback.host;
|
|
343
|
+
const project = typeof section.project === 'string' ? section.project : fallback.project;
|
|
344
|
+
if (section.enabled !== undefined && typeof section.enabled !== 'boolean') {
|
|
345
|
+
errors.push('gitlab.enabled must be boolean');
|
|
346
|
+
}
|
|
347
|
+
if (section.host !== undefined && typeof section.host !== 'string') {
|
|
348
|
+
errors.push('gitlab.host must be string');
|
|
349
|
+
}
|
|
350
|
+
if (section.project !== undefined && typeof section.project !== 'string') {
|
|
351
|
+
errors.push('gitlab.project must be string');
|
|
352
|
+
}
|
|
353
|
+
return { enabled, host, project };
|
|
354
|
+
}
|
|
355
|
+
export function parseProjectConfig(raw) {
|
|
356
|
+
const errors = [];
|
|
357
|
+
const defaults = defaultConfig();
|
|
358
|
+
let parsed;
|
|
359
|
+
try {
|
|
360
|
+
parsed = JSON.parse(raw);
|
|
361
|
+
}
|
|
362
|
+
catch (error) {
|
|
363
|
+
errors.push(`JSON parse error: ${error instanceof Error ? error.message : String(error)}`);
|
|
364
|
+
return { config: defaults, errors };
|
|
365
|
+
}
|
|
366
|
+
if (!isRecord(parsed)) {
|
|
367
|
+
errors.push('Root configuration must be a JSON object');
|
|
368
|
+
return { config: defaults, errors };
|
|
369
|
+
}
|
|
370
|
+
const config = {
|
|
371
|
+
skills: parseToggle(parsed.skills, defaults.skills, 'skills', errors),
|
|
372
|
+
impact: parseImpact(parsed.impact, defaults.impact, errors),
|
|
373
|
+
bridges: parseBridges(parsed.bridges, defaults.bridges, errors),
|
|
374
|
+
search: parseSearch(parsed.search, defaults.search, errors),
|
|
375
|
+
riskZones: parseRiskZones(parsed.riskZones, defaults.riskZones, errors),
|
|
376
|
+
context: parseToggle(parsed.context, defaults.context, 'context', errors),
|
|
377
|
+
compression: parseToggle(parsed.compression, defaults.compression, 'compression', errors),
|
|
378
|
+
knowledge: parseToggle(parsed.knowledge, defaults.knowledge, 'knowledge', errors),
|
|
379
|
+
verification: parseVerification(parsed.verification, defaults.verification, errors),
|
|
380
|
+
gitlab: parseGitlab(parsed.gitlab, defaults.gitlab, errors),
|
|
381
|
+
};
|
|
382
|
+
return { config, errors };
|
|
383
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Minimal glob matcher for repo-relative POSIX paths. Dependency-free by AGENTS.md.
|
|
2
|
+
//
|
|
3
|
+
// Supported: `**` (a whole path segment: zero or more directories), `*` (anything but `/`),
|
|
4
|
+
// `?` (one char but `/`), `{a,b}` alternation (nestable, items may hold globs). Dotfiles are
|
|
5
|
+
// ordinary names, so `**/.env*` matches `.env`. Not supported: character classes, backslash
|
|
6
|
+
// escapes. An unbalanced `{`, and `,` or `}` outside braces, are literals.
|
|
7
|
+
const cache = new Map();
|
|
8
|
+
function hasClosingBrace(p, open) {
|
|
9
|
+
let depth = 0;
|
|
10
|
+
for (let i = open; i < p.length; i++) {
|
|
11
|
+
if (p[i] === '{')
|
|
12
|
+
depth++;
|
|
13
|
+
if (p[i] === '}' && --depth === 0)
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
function escapeChar(c) {
|
|
19
|
+
return /[.+^$()|[\]\\{}]/.test(c) ? `\\${c}` : c;
|
|
20
|
+
}
|
|
21
|
+
function translate(p, start, inBrace) {
|
|
22
|
+
let src = '';
|
|
23
|
+
let i = start;
|
|
24
|
+
while (i < p.length) {
|
|
25
|
+
const c = p[i];
|
|
26
|
+
if (inBrace && (c === ',' || c === '}'))
|
|
27
|
+
break;
|
|
28
|
+
if (c === '*') {
|
|
29
|
+
let stars = 0;
|
|
30
|
+
while (p[i + stars] === '*')
|
|
31
|
+
stars++;
|
|
32
|
+
const after = i + stars;
|
|
33
|
+
const prev = p[i - 1];
|
|
34
|
+
const next = p[after];
|
|
35
|
+
const startsSegment = i === start || prev === '/';
|
|
36
|
+
const endsSegment = after === p.length || next === '/' || (inBrace && (next === ',' || next === '}'));
|
|
37
|
+
if (stars >= 2 && startsSegment && endsSegment) {
|
|
38
|
+
// `**/` also matches zero directories, so `**/a` matches `a`.
|
|
39
|
+
if (next === '/') {
|
|
40
|
+
src += '(?:.*/)?';
|
|
41
|
+
i = after + 1;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
src += '.*';
|
|
45
|
+
i = after;
|
|
46
|
+
}
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
src += '[^/]*';
|
|
50
|
+
i = after;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (c === '?') {
|
|
54
|
+
src += '[^/]';
|
|
55
|
+
i++;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (c === '{' && hasClosingBrace(p, i)) {
|
|
59
|
+
const alternatives = [];
|
|
60
|
+
let j = i + 1;
|
|
61
|
+
for (;;) {
|
|
62
|
+
const piece = translate(p, j, true);
|
|
63
|
+
alternatives.push(piece.src);
|
|
64
|
+
j = piece.end;
|
|
65
|
+
if (p[j] !== ',')
|
|
66
|
+
break;
|
|
67
|
+
j++;
|
|
68
|
+
}
|
|
69
|
+
src += `(?:${alternatives.join('|')})`;
|
|
70
|
+
i = j + 1;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
src += escapeChar(c ?? '');
|
|
74
|
+
i++;
|
|
75
|
+
}
|
|
76
|
+
return { src, end: i };
|
|
77
|
+
}
|
|
78
|
+
function compile(pattern) {
|
|
79
|
+
const cached = cache.get(pattern);
|
|
80
|
+
if (cached)
|
|
81
|
+
return cached;
|
|
82
|
+
const regex = new RegExp(`^${translate(pattern, 0, false).src}$`, 's');
|
|
83
|
+
cache.set(pattern, regex);
|
|
84
|
+
return regex;
|
|
85
|
+
}
|
|
86
|
+
export function matchGlob(pattern, repoRelativePosixPath) {
|
|
87
|
+
return compile(pattern).test(repoRelativePosixPath);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* True when at least one positive pattern matches and no `!`-prefixed pattern does. Order does
|
|
91
|
+
* not matter. Negation only subtracts, so a list of only negations matches nothing.
|
|
92
|
+
*/
|
|
93
|
+
export function matchAny(patterns, repoRelativePosixPath) {
|
|
94
|
+
let matched = false;
|
|
95
|
+
for (const pattern of patterns) {
|
|
96
|
+
if (pattern.startsWith('!')) {
|
|
97
|
+
if (matchGlob(pattern.slice(1), repoRelativePosixPath))
|
|
98
|
+
return false;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (matchGlob(pattern, repoRelativePosixPath))
|
|
102
|
+
matched = true;
|
|
103
|
+
}
|
|
104
|
+
return matched;
|
|
105
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Pure path-only risk zone matching and verdict derivation (docs/RISK.md §2.1–2.3).
|
|
2
|
+
// Zero filesystem imports: excluded and secret files are matched by path alone.
|
|
3
|
+
import { resolveRiskZones } from './config.js';
|
|
4
|
+
import { matchAny } from './glob.js';
|
|
5
|
+
export const LEVEL_RANK = {
|
|
6
|
+
low: 0,
|
|
7
|
+
medium: 1,
|
|
8
|
+
unknown: 2,
|
|
9
|
+
high: 3,
|
|
10
|
+
critical: 4,
|
|
11
|
+
};
|
|
12
|
+
export const ACTION_RANK = {
|
|
13
|
+
proceed: 0,
|
|
14
|
+
'run-tests': 1,
|
|
15
|
+
'check-gaps': 2,
|
|
16
|
+
'ask-owner': 3,
|
|
17
|
+
};
|
|
18
|
+
export function normalizeRepoPath(path) {
|
|
19
|
+
return path
|
|
20
|
+
.replaceAll('\\', '/')
|
|
21
|
+
.replace(/^\.?\//, '')
|
|
22
|
+
.replace(/\/+/g, '/');
|
|
23
|
+
}
|
|
24
|
+
export function matchedRiskZones(paths, riskZones) {
|
|
25
|
+
const configured = resolveRiskZones(riskZones);
|
|
26
|
+
if (configured.length === 0)
|
|
27
|
+
return [];
|
|
28
|
+
const normalizedLower = [];
|
|
29
|
+
const seen = new Set();
|
|
30
|
+
for (const raw of paths) {
|
|
31
|
+
const norm = normalizeRepoPath(raw).toLowerCase();
|
|
32
|
+
if (norm === '' || seen.has(norm))
|
|
33
|
+
continue;
|
|
34
|
+
seen.add(norm);
|
|
35
|
+
normalizedLower.push(norm);
|
|
36
|
+
}
|
|
37
|
+
if (normalizedLower.length === 0)
|
|
38
|
+
return [];
|
|
39
|
+
const matched = [];
|
|
40
|
+
for (const zone of configured) {
|
|
41
|
+
const lowerPatterns = zone.match.map((pattern) => pattern.toLowerCase());
|
|
42
|
+
if (normalizedLower.some((path) => matchAny(lowerPatterns, path))) {
|
|
43
|
+
matched.push(zone);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return matched;
|
|
47
|
+
}
|
|
48
|
+
export function deriveVerdict(input) {
|
|
49
|
+
const zones = [...new Set(input.matchedZones.map((zone) => zone.zone))].sort();
|
|
50
|
+
const hasCritical = input.matchedZones.some((zone) => zone.floor === 'critical');
|
|
51
|
+
const hasHigh = input.matchedZones.some((zone) => zone.floor === 'high');
|
|
52
|
+
let level;
|
|
53
|
+
let action;
|
|
54
|
+
let requiredActions;
|
|
55
|
+
if (hasCritical) {
|
|
56
|
+
level = 'critical';
|
|
57
|
+
action = 'ask-owner';
|
|
58
|
+
requiredActions = [
|
|
59
|
+
'Present the planned change to the owner before editing',
|
|
60
|
+
'Never batch with other changes',
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
else if (hasHigh) {
|
|
64
|
+
level = 'high';
|
|
65
|
+
if (input.incomplete) {
|
|
66
|
+
action = 'ask-owner';
|
|
67
|
+
requiredActions = ['Present gaps and planned change to the owner before editing'];
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
action = 'run-tests';
|
|
71
|
+
requiredActions = [
|
|
72
|
+
'Run every file in tests. If tests is empty, say so in the report',
|
|
73
|
+
'Call ei_workflow with risk: high at verify and review',
|
|
74
|
+
'Call ei_changes before reporting done',
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else if (input.incomplete) {
|
|
79
|
+
level = 'unknown';
|
|
80
|
+
action = 'check-gaps';
|
|
81
|
+
requiredActions = [
|
|
82
|
+
'Open each site named in completeness.reasons, state what was found, then decide',
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
else if (input.hasFactors) {
|
|
86
|
+
level = 'medium';
|
|
87
|
+
action = 'run-tests';
|
|
88
|
+
requiredActions = ['Run every file in tests. If tests is empty, say so in the report'];
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
level = 'low';
|
|
92
|
+
action = 'proceed';
|
|
93
|
+
requiredActions = [];
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
level,
|
|
97
|
+
action,
|
|
98
|
+
zones,
|
|
99
|
+
requiredActions,
|
|
100
|
+
basis: [...new Set([...input.basis, ...zones.map((zone) => `zone:${zone}`)])],
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export function applyRiskZones(base, paths, riskZones, options = {}) {
|
|
104
|
+
const configured = resolveRiskZones(riskZones);
|
|
105
|
+
const byPath = matchedRiskZones(paths, configured);
|
|
106
|
+
const byName = new Map(byPath.map((zone) => [zone.zone, zone]));
|
|
107
|
+
for (const name of options.preMatchedZones ?? base.zones) {
|
|
108
|
+
if (byName.has(name))
|
|
109
|
+
continue;
|
|
110
|
+
const found = configured.find((zone) => zone.zone === name);
|
|
111
|
+
if (found !== undefined) {
|
|
112
|
+
byName.set(name, found);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
byName.set(name, {
|
|
116
|
+
zone: name,
|
|
117
|
+
floor: base.level === 'critical' ? 'critical' : 'high',
|
|
118
|
+
match: [],
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const incomplete = options.incomplete ?? base.level === 'unknown';
|
|
123
|
+
const hasFactors = options.hasFactors ?? base.level !== 'low';
|
|
124
|
+
const derived = deriveVerdict({
|
|
125
|
+
incomplete,
|
|
126
|
+
hasFactors,
|
|
127
|
+
basis: base.basis,
|
|
128
|
+
matchedZones: [...byName.values()],
|
|
129
|
+
});
|
|
130
|
+
// Monotonicity invariant: applying risk zones never lowers level or action.
|
|
131
|
+
if (LEVEL_RANK[derived.level] < LEVEL_RANK[base.level]) {
|
|
132
|
+
return {
|
|
133
|
+
...derived,
|
|
134
|
+
level: base.level,
|
|
135
|
+
action: ACTION_RANK[derived.action] >= ACTION_RANK[base.action] ? derived.action : base.action,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
if (ACTION_RANK[derived.action] < ACTION_RANK[base.action]) {
|
|
139
|
+
return { ...derived, action: base.action };
|
|
140
|
+
}
|
|
141
|
+
return derived;
|
|
142
|
+
}
|