@luanpdd/kit-mcp 1.35.0 → 1.36.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/bin/cli.js +2 -2
- package/bin/mcp.js +6 -6
- package/bin/ui.js +74 -74
- package/gates/ai-prompt-stability.md +120 -120
- package/gates/budget-description.md +68 -68
- package/gates/confidence.md +29 -29
- package/gates/dependency-check.md +33 -33
- package/gates/dept-cycle-prevention.md +179 -179
- package/gates/golden-signals-coverage.md +133 -133
- package/gates/legacy-refactor-safety.md +178 -178
- package/gates/multi-tenant-rls-coverage.md +102 -102
- package/gates/no-personal-uuid.md +72 -72
- package/gates/obs-agents-mcp-supabase.md +86 -86
- package/gates/obs-skills-frontmatter.md +76 -76
- package/gates/observability-coverage.md +151 -151
- package/gates/omm-no-regression.md +83 -83
- package/gates/postmortem-template-required.md +127 -127
- package/gates/prr-checklist-coverage.md +128 -128
- package/gates/regression.md +32 -32
- package/gates/release-pipeline-policy.md +132 -132
- package/gates/secrets-scan.md +33 -33
- package/gates/service-role-not-in-user-facing.md +113 -113
- package/gates/skill-must-include.md +71 -71
- package/gates/sync-idempotent.md +62 -62
- package/gates/verify-phase-goal.md +34 -34
- package/kit/agents/designer-ui.md +216 -216
- package/kit/agents/workflow-generator.md +537 -167
- package/kit/commands/adicionar-backlog.md +1 -1
- package/kit/commands/adicionar-fase.md +1 -1
- package/kit/commands/adicionar-tarefa.md +1 -1
- package/kit/commands/auditar-observabilidade.md +103 -103
- package/kit/commands/auditar-toil.md +129 -129
- package/kit/commands/caracterizar-prompt.md +195 -195
- package/kit/commands/criar-workflow.md +158 -158
- package/kit/commands/definir-perfil.md +1 -1
- package/kit/commands/definir-slo.md +108 -108
- package/kit/commands/fio.md +1 -1
- package/kit/commands/golden-signals.md +142 -142
- package/kit/commands/instrumentar-fase.md +200 -200
- package/kit/commands/investigar-producao.md +162 -162
- package/kit/commands/observabilidade.md +118 -118
- package/kit/commands/postmortem.md +179 -179
- package/kit/commands/prr.md +205 -205
- package/kit/commands/publicar-rapido.md +207 -207
- package/kit/commands/risk-budget.md +220 -220
- package/kit/commands/sre.md +230 -230
- package/kit/file-manifest.json +424 -424
- package/kit/framework/references/output-style.md +22 -22
- package/kit/hooks/post-apply-migration.js +199 -199
- package/kit/hooks/sidecar-tool-publisher.js +210 -210
- package/kit/skills/_shared-dados-distribuidos/glossary.md +224 -224
- package/kit/skills/_shared-legacy/glossary.md +389 -389
- package/kit/skills/_shared-multi-tenant/glossary.md +186 -186
- package/kit/skills/_shared-observability/glossary.md +396 -396
- package/kit/skills/_shared-sre/glossary.md +712 -712
- package/kit/skills/_shared-supabase/glossary.md +234 -234
- package/kit/skills/blameless-postmortems/SKILL.md +340 -340
- package/kit/skills/burn-rate-alerting/SKILL.md +258 -258
- package/kit/skills/cascading-failures/SKILL.md +311 -311
- package/kit/skills/core-analysis-loop/SKILL.md +352 -352
- package/kit/skills/distributed-tracing/SKILL.md +362 -362
- package/kit/skills/dynamic-workflow-authoring/SKILL.md +327 -223
- package/kit/skills/eliminating-toil/SKILL.md +243 -243
- package/kit/skills/event-based-slos/SKILL.md +296 -296
- package/kit/skills/four-golden-signals/SKILL.md +314 -314
- package/kit/skills/hermetic-builds/SKILL.md +323 -323
- package/kit/skills/legacy-monster-methods/SKILL.md +444 -444
- package/kit/skills/llm-as-dependency/SKILL.md +436 -436
- package/kit/skills/load-shedding-graceful-degradation/SKILL.md +396 -396
- package/kit/skills/observability-driven-development/SKILL.md +315 -315
- package/kit/skills/observability-maturity-model/SKILL.md +222 -222
- package/kit/skills/opentelemetry-standard/SKILL.md +351 -351
- package/kit/skills/production-readiness-review/SKILL.md +305 -305
- package/kit/skills/release-engineering/SKILL.md +367 -367
- package/kit/skills/retry-strategies/SKILL.md +372 -372
- package/kit/skills/sre-risk-management/SKILL.md +221 -221
- package/kit/skills/structured-events/SKILL.md +265 -265
- package/kit/skills/supabase-cron-queues/SKILL.md +275 -275
- package/kit/skills/supabase-database-functions/SKILL.md +332 -332
- package/kit/skills/supabase-declarative-schema/SKILL.md +183 -183
- package/kit/skills/supabase-pgvector-rag/SKILL.md +253 -253
- package/kit/skills/supabase-postgres-style/SKILL.md +138 -138
- package/kit/skills/supabase-storage/SKILL.md +234 -234
- package/kit/skills/telemetry-pipelines/SKILL.md +259 -259
- package/kit/skills/telemetry-sampling/SKILL.md +256 -256
- package/kit/skills/ui-anti-padroes-ia/SKILL.md +261 -261
- package/kit/skills/ui-contexto-produto/SKILL.md +248 -248
- package/kit/skills/ui-cor-estrategia/SKILL.md +213 -213
- package/kit/skills/ui-critica-auditoria/SKILL.md +260 -260
- package/kit/skills/ui-motion-funcional/SKILL.md +264 -264
- package/kit/skills/ui-ritmo-espacial/SKILL.md +259 -259
- package/kit/skills/ui-tipografia/SKILL.md +211 -211
- package/package.json +1 -1
- package/src/cli/index.js +1114 -1114
- package/src/cli/render.js +194 -194
- package/src/cli/upgrade-check.js +135 -135
- package/src/core/error-redaction.js +76 -76
- package/src/core/failures.js +153 -153
- package/src/core/gate-runner.js +205 -205
- package/src/core/gates.js +82 -82
- package/src/core/logger.js +170 -170
- package/src/core/manifest-verify.js +174 -174
- package/src/core/metrics.js +268 -268
- package/src/core/notify.js +60 -60
- package/src/core/path-safety.js +141 -141
- package/src/core/replays.js +120 -120
- package/src/core/ui.js +185 -185
- package/src/mcp-server/install.js +149 -149
- package/src/mcp-server/roots.js +124 -124
- package/src/ui/auto-spawn.js +113 -113
- package/src/ui/browser.js +78 -78
- package/src/ui/client.js +130 -130
- package/src/ui/events.js +65 -65
- package/src/ui/lockfile.js +191 -191
- package/src/ui/port.js +67 -67
- package/src/ui/server.js +547 -547
- package/src/ui/wrapper.js +129 -129
|
@@ -1,174 +1,174 @@
|
|
|
1
|
-
// SEC-14-05: verify kit/file-manifest.json against actual file contents.
|
|
2
|
-
// Called by syncTo() in install path, before any write — refuses to project
|
|
3
|
-
// a tampered kit. Opt-out via KIT_MCP_SKIP_MANIFEST_CHECK=1 (warn on stderr).
|
|
4
|
-
//
|
|
5
|
-
// Manifest format (kit/file-manifest.json):
|
|
6
|
-
// { version, timestamp, files: { "<rel-to-kitRoot>": "<sha256-hex>", ... } }
|
|
7
|
-
//
|
|
8
|
-
// Returns:
|
|
9
|
-
// { ok: true } when all listed files exist + match.
|
|
10
|
-
// { ok: true, skipped: true } when KIT_MCP_SKIP_MANIFEST_CHECK=1.
|
|
11
|
-
// { ok: false, reason, mismatches, missing } otherwise.
|
|
12
|
-
|
|
13
|
-
import path from 'node:path';
|
|
14
|
-
import fs from 'node:fs/promises';
|
|
15
|
-
import crypto from 'node:crypto';
|
|
16
|
-
|
|
17
|
-
// PERF-17-01: parallelize SHA256 hashing in batches of 16. Same pattern
|
|
18
|
-
// as Phase 88.01 sync.js. Hardcoded — env override is overengineering
|
|
19
|
-
// for verifyManifest (single hot path, not user-facing latency budget).
|
|
20
|
-
const BATCH_SIZE = 16;
|
|
21
|
-
|
|
22
|
-
// PERF-17-01: in-memory cache for verifyManifest. Same pattern as kit.js
|
|
23
|
-
// listKit cache (PERF-01). Watch triggers (file save → re-sync) call this
|
|
24
|
-
// back-to-back; the 2nd+ call within TTL hits cache and returns <5ms.
|
|
25
|
-
//
|
|
26
|
-
// Caching rules:
|
|
27
|
-
// - Only cache ok=true results. mismatches/missing → recompute every call
|
|
28
|
-
// so devs see fixes immediately (don't punish them for the slow path).
|
|
29
|
-
// - Bypass via KIT_MCP_VERIFY_NO_CACHE=1 (test isolation + emergency dev escape).
|
|
30
|
-
// - Cache key is kitRoot — different roots are independent entries.
|
|
31
|
-
const VERIFY_CACHE_TTL_MS = 30_000;
|
|
32
|
-
const verifyManifestCache = new Map(); // kitRoot -> { value, ts }
|
|
33
|
-
const NO_CACHE_ENV = 'KIT_MCP_VERIFY_NO_CACHE';
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Test/emergency helper — clears the cache. Exported for unit tests.
|
|
37
|
-
* Production code should never need this; use the env var instead.
|
|
38
|
-
*/
|
|
39
|
-
export function clearVerifyManifestCache() { verifyManifestCache.clear(); }
|
|
40
|
-
|
|
41
|
-
const SKIP_ENV = 'KIT_MCP_SKIP_MANIFEST_CHECK';
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* SEC-14-05: verify kit/file-manifest.json against actual file contents.
|
|
45
|
-
* PERF-17-01: hashes in Promise.all batches of 16 (was sequential pre-v1.17).
|
|
46
|
-
* Called by syncTo() in install path before any write — refuses to project a tampered kit.
|
|
47
|
-
* @param {string} kitRoot - absolute path to kit/ directory.
|
|
48
|
-
* @returns {Promise<{ok: boolean, skipped?: boolean, reason?: string, mismatches?: Array, missing?: string[]}>}
|
|
49
|
-
*/
|
|
50
|
-
export async function verifyManifest(kitRoot) {
|
|
51
|
-
if (process.env[SKIP_ENV] === '1') {
|
|
52
|
-
process.stderr.write(
|
|
53
|
-
'[kit-mcp] WARNING: ' + SKIP_ENV + '=1 set — skipping kit/file-manifest.json verification (dev mode).\n'
|
|
54
|
-
);
|
|
55
|
-
return { ok: true, skipped: true };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// PERF-17-01: cache hit — repeated calls within TTL skip the I/O + hashing.
|
|
59
|
-
// Bypass via KIT_MCP_VERIFY_NO_CACHE=1 (tests + dev emergency escape).
|
|
60
|
-
if (process.env[NO_CACHE_ENV] !== '1') {
|
|
61
|
-
const cached = verifyManifestCache.get(kitRoot);
|
|
62
|
-
if (cached && Date.now() - cached.ts < VERIFY_CACHE_TTL_MS) {
|
|
63
|
-
return cached.value;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const manifestPath = path.join(kitRoot, 'file-manifest.json');
|
|
68
|
-
let manifest;
|
|
69
|
-
try {
|
|
70
|
-
const raw = await fs.readFile(manifestPath, 'utf8');
|
|
71
|
-
manifest = JSON.parse(raw);
|
|
72
|
-
} catch (e) {
|
|
73
|
-
return {
|
|
74
|
-
ok: false,
|
|
75
|
-
reason: 'kit manifest unreadable at ' + manifestPath + ': ' + e.message,
|
|
76
|
-
mismatches: [],
|
|
77
|
-
missing: [],
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (!manifest.files || typeof manifest.files !== 'object') {
|
|
82
|
-
return {
|
|
83
|
-
ok: false,
|
|
84
|
-
reason: "kit manifest malformed at " + manifestPath + ": missing 'files' object",
|
|
85
|
-
mismatches: [],
|
|
86
|
-
missing: [],
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const mismatches = [];
|
|
91
|
-
const missing = [];
|
|
92
|
-
|
|
93
|
-
const entries = Object.entries(manifest.files);
|
|
94
|
-
|
|
95
|
-
// Per-file check — returns { rel, status: 'ok'|'mismatch'|'missing', expected?, actual? }.
|
|
96
|
-
// Pure function (no side effects on shared arrays) so Promise.all in batches
|
|
97
|
-
// is safe — caller aggregates after each batch resolves.
|
|
98
|
-
const checkOne = async ([rel, expected]) => {
|
|
99
|
-
const abs = path.join(kitRoot, rel);
|
|
100
|
-
let buf;
|
|
101
|
-
try {
|
|
102
|
-
buf = await fs.readFile(abs);
|
|
103
|
-
} catch {
|
|
104
|
-
return { rel, status: 'missing' };
|
|
105
|
-
}
|
|
106
|
-
// Normalize CRLF→LF before hashing so manifest is platform-stable.
|
|
107
|
-
// git checkout converts EOL on Windows but Linux CI checks out LF —
|
|
108
|
-
// hashing raw bytes would diverge across platforms. (PRESERVED from v1.15)
|
|
109
|
-
const normalized = Buffer.from(buf.toString('binary').replace(/\r\n/g, '\n'), 'binary');
|
|
110
|
-
const actual = crypto.createHash('sha256').update(normalized).digest('hex');
|
|
111
|
-
if (actual !== expected) {
|
|
112
|
-
return { rel, status: 'mismatch', expected, actual };
|
|
113
|
-
}
|
|
114
|
-
return { rel, status: 'ok' };
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
// Sequential batches — within a batch, Promise.all parallelizes hashing;
|
|
118
|
-
// between batches, await bounds max-in-flight at BATCH_SIZE (defensive
|
|
119
|
-
// against fd ulimit on large kits). Order of completion within a batch
|
|
120
|
-
// doesn't matter — aggregator below is order-independent.
|
|
121
|
-
for (let i = 0; i < entries.length; i += BATCH_SIZE) {
|
|
122
|
-
const slice = entries.slice(i, i + BATCH_SIZE);
|
|
123
|
-
const results = await Promise.all(slice.map(checkOne));
|
|
124
|
-
for (const r of results) {
|
|
125
|
-
if (r.status === 'mismatch') {
|
|
126
|
-
mismatches.push({ path: r.rel, expected: r.expected.slice(0, 16), actual: r.actual.slice(0, 16) });
|
|
127
|
-
} else if (r.status === 'missing') {
|
|
128
|
-
missing.push(r.rel);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (mismatches.length === 0 && missing.length === 0) {
|
|
134
|
-
const result = { ok: true };
|
|
135
|
-
// PERF-17-01: cache only ok=true. Mismatch/missing always recompute
|
|
136
|
-
// so dev fixing a tampered file sees the next sync recover immediately.
|
|
137
|
-
if (process.env[NO_CACHE_ENV] !== '1') {
|
|
138
|
-
verifyManifestCache.set(kitRoot, { value: result, ts: Date.now() });
|
|
139
|
-
}
|
|
140
|
-
return result;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Build a concise reason — first 3 mismatches, plus counts.
|
|
144
|
-
const sample = mismatches
|
|
145
|
-
.slice(0, 3)
|
|
146
|
-
.map((m) => m.path + ' (expected ' + m.expected + ', got ' + m.actual + ')')
|
|
147
|
-
.join('; ');
|
|
148
|
-
const missingSample = missing.slice(0, 3).join(', ');
|
|
149
|
-
const reasonParts = [];
|
|
150
|
-
if (mismatches.length > 0) {
|
|
151
|
-
reasonParts.push(
|
|
152
|
-
mismatches.length +
|
|
153
|
-
' file(s) tampered: ' +
|
|
154
|
-
sample +
|
|
155
|
-
(mismatches.length > 3 ? ', +' + (mismatches.length - 3) + ' more' : '')
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
if (missing.length > 0) {
|
|
159
|
-
reasonParts.push(
|
|
160
|
-
missing.length +
|
|
161
|
-
' file(s) missing: ' +
|
|
162
|
-
missingSample +
|
|
163
|
-
(missing.length > 3 ? ', +' + (missing.length - 3) + ' more' : '')
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
reasonParts.push('set ' + SKIP_ENV + '=1 to bypass (dev only)');
|
|
167
|
-
|
|
168
|
-
return {
|
|
169
|
-
ok: false,
|
|
170
|
-
reason: 'kit manifest mismatch — ' + reasonParts.join('; '),
|
|
171
|
-
mismatches,
|
|
172
|
-
missing,
|
|
173
|
-
};
|
|
174
|
-
}
|
|
1
|
+
// SEC-14-05: verify kit/file-manifest.json against actual file contents.
|
|
2
|
+
// Called by syncTo() in install path, before any write — refuses to project
|
|
3
|
+
// a tampered kit. Opt-out via KIT_MCP_SKIP_MANIFEST_CHECK=1 (warn on stderr).
|
|
4
|
+
//
|
|
5
|
+
// Manifest format (kit/file-manifest.json):
|
|
6
|
+
// { version, timestamp, files: { "<rel-to-kitRoot>": "<sha256-hex>", ... } }
|
|
7
|
+
//
|
|
8
|
+
// Returns:
|
|
9
|
+
// { ok: true } when all listed files exist + match.
|
|
10
|
+
// { ok: true, skipped: true } when KIT_MCP_SKIP_MANIFEST_CHECK=1.
|
|
11
|
+
// { ok: false, reason, mismatches, missing } otherwise.
|
|
12
|
+
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import fs from 'node:fs/promises';
|
|
15
|
+
import crypto from 'node:crypto';
|
|
16
|
+
|
|
17
|
+
// PERF-17-01: parallelize SHA256 hashing in batches of 16. Same pattern
|
|
18
|
+
// as Phase 88.01 sync.js. Hardcoded — env override is overengineering
|
|
19
|
+
// for verifyManifest (single hot path, not user-facing latency budget).
|
|
20
|
+
const BATCH_SIZE = 16;
|
|
21
|
+
|
|
22
|
+
// PERF-17-01: in-memory cache for verifyManifest. Same pattern as kit.js
|
|
23
|
+
// listKit cache (PERF-01). Watch triggers (file save → re-sync) call this
|
|
24
|
+
// back-to-back; the 2nd+ call within TTL hits cache and returns <5ms.
|
|
25
|
+
//
|
|
26
|
+
// Caching rules:
|
|
27
|
+
// - Only cache ok=true results. mismatches/missing → recompute every call
|
|
28
|
+
// so devs see fixes immediately (don't punish them for the slow path).
|
|
29
|
+
// - Bypass via KIT_MCP_VERIFY_NO_CACHE=1 (test isolation + emergency dev escape).
|
|
30
|
+
// - Cache key is kitRoot — different roots are independent entries.
|
|
31
|
+
const VERIFY_CACHE_TTL_MS = 30_000;
|
|
32
|
+
const verifyManifestCache = new Map(); // kitRoot -> { value, ts }
|
|
33
|
+
const NO_CACHE_ENV = 'KIT_MCP_VERIFY_NO_CACHE';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Test/emergency helper — clears the cache. Exported for unit tests.
|
|
37
|
+
* Production code should never need this; use the env var instead.
|
|
38
|
+
*/
|
|
39
|
+
export function clearVerifyManifestCache() { verifyManifestCache.clear(); }
|
|
40
|
+
|
|
41
|
+
const SKIP_ENV = 'KIT_MCP_SKIP_MANIFEST_CHECK';
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* SEC-14-05: verify kit/file-manifest.json against actual file contents.
|
|
45
|
+
* PERF-17-01: hashes in Promise.all batches of 16 (was sequential pre-v1.17).
|
|
46
|
+
* Called by syncTo() in install path before any write — refuses to project a tampered kit.
|
|
47
|
+
* @param {string} kitRoot - absolute path to kit/ directory.
|
|
48
|
+
* @returns {Promise<{ok: boolean, skipped?: boolean, reason?: string, mismatches?: Array, missing?: string[]}>}
|
|
49
|
+
*/
|
|
50
|
+
export async function verifyManifest(kitRoot) {
|
|
51
|
+
if (process.env[SKIP_ENV] === '1') {
|
|
52
|
+
process.stderr.write(
|
|
53
|
+
'[kit-mcp] WARNING: ' + SKIP_ENV + '=1 set — skipping kit/file-manifest.json verification (dev mode).\n'
|
|
54
|
+
);
|
|
55
|
+
return { ok: true, skipped: true };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// PERF-17-01: cache hit — repeated calls within TTL skip the I/O + hashing.
|
|
59
|
+
// Bypass via KIT_MCP_VERIFY_NO_CACHE=1 (tests + dev emergency escape).
|
|
60
|
+
if (process.env[NO_CACHE_ENV] !== '1') {
|
|
61
|
+
const cached = verifyManifestCache.get(kitRoot);
|
|
62
|
+
if (cached && Date.now() - cached.ts < VERIFY_CACHE_TTL_MS) {
|
|
63
|
+
return cached.value;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const manifestPath = path.join(kitRoot, 'file-manifest.json');
|
|
68
|
+
let manifest;
|
|
69
|
+
try {
|
|
70
|
+
const raw = await fs.readFile(manifestPath, 'utf8');
|
|
71
|
+
manifest = JSON.parse(raw);
|
|
72
|
+
} catch (e) {
|
|
73
|
+
return {
|
|
74
|
+
ok: false,
|
|
75
|
+
reason: 'kit manifest unreadable at ' + manifestPath + ': ' + e.message,
|
|
76
|
+
mismatches: [],
|
|
77
|
+
missing: [],
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (!manifest.files || typeof manifest.files !== 'object') {
|
|
82
|
+
return {
|
|
83
|
+
ok: false,
|
|
84
|
+
reason: "kit manifest malformed at " + manifestPath + ": missing 'files' object",
|
|
85
|
+
mismatches: [],
|
|
86
|
+
missing: [],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const mismatches = [];
|
|
91
|
+
const missing = [];
|
|
92
|
+
|
|
93
|
+
const entries = Object.entries(manifest.files);
|
|
94
|
+
|
|
95
|
+
// Per-file check — returns { rel, status: 'ok'|'mismatch'|'missing', expected?, actual? }.
|
|
96
|
+
// Pure function (no side effects on shared arrays) so Promise.all in batches
|
|
97
|
+
// is safe — caller aggregates after each batch resolves.
|
|
98
|
+
const checkOne = async ([rel, expected]) => {
|
|
99
|
+
const abs = path.join(kitRoot, rel);
|
|
100
|
+
let buf;
|
|
101
|
+
try {
|
|
102
|
+
buf = await fs.readFile(abs);
|
|
103
|
+
} catch {
|
|
104
|
+
return { rel, status: 'missing' };
|
|
105
|
+
}
|
|
106
|
+
// Normalize CRLF→LF before hashing so manifest is platform-stable.
|
|
107
|
+
// git checkout converts EOL on Windows but Linux CI checks out LF —
|
|
108
|
+
// hashing raw bytes would diverge across platforms. (PRESERVED from v1.15)
|
|
109
|
+
const normalized = Buffer.from(buf.toString('binary').replace(/\r\n/g, '\n'), 'binary');
|
|
110
|
+
const actual = crypto.createHash('sha256').update(normalized).digest('hex');
|
|
111
|
+
if (actual !== expected) {
|
|
112
|
+
return { rel, status: 'mismatch', expected, actual };
|
|
113
|
+
}
|
|
114
|
+
return { rel, status: 'ok' };
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// Sequential batches — within a batch, Promise.all parallelizes hashing;
|
|
118
|
+
// between batches, await bounds max-in-flight at BATCH_SIZE (defensive
|
|
119
|
+
// against fd ulimit on large kits). Order of completion within a batch
|
|
120
|
+
// doesn't matter — aggregator below is order-independent.
|
|
121
|
+
for (let i = 0; i < entries.length; i += BATCH_SIZE) {
|
|
122
|
+
const slice = entries.slice(i, i + BATCH_SIZE);
|
|
123
|
+
const results = await Promise.all(slice.map(checkOne));
|
|
124
|
+
for (const r of results) {
|
|
125
|
+
if (r.status === 'mismatch') {
|
|
126
|
+
mismatches.push({ path: r.rel, expected: r.expected.slice(0, 16), actual: r.actual.slice(0, 16) });
|
|
127
|
+
} else if (r.status === 'missing') {
|
|
128
|
+
missing.push(r.rel);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (mismatches.length === 0 && missing.length === 0) {
|
|
134
|
+
const result = { ok: true };
|
|
135
|
+
// PERF-17-01: cache only ok=true. Mismatch/missing always recompute
|
|
136
|
+
// so dev fixing a tampered file sees the next sync recover immediately.
|
|
137
|
+
if (process.env[NO_CACHE_ENV] !== '1') {
|
|
138
|
+
verifyManifestCache.set(kitRoot, { value: result, ts: Date.now() });
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Build a concise reason — first 3 mismatches, plus counts.
|
|
144
|
+
const sample = mismatches
|
|
145
|
+
.slice(0, 3)
|
|
146
|
+
.map((m) => m.path + ' (expected ' + m.expected + ', got ' + m.actual + ')')
|
|
147
|
+
.join('; ');
|
|
148
|
+
const missingSample = missing.slice(0, 3).join(', ');
|
|
149
|
+
const reasonParts = [];
|
|
150
|
+
if (mismatches.length > 0) {
|
|
151
|
+
reasonParts.push(
|
|
152
|
+
mismatches.length +
|
|
153
|
+
' file(s) tampered: ' +
|
|
154
|
+
sample +
|
|
155
|
+
(mismatches.length > 3 ? ', +' + (mismatches.length - 3) + ' more' : '')
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
if (missing.length > 0) {
|
|
159
|
+
reasonParts.push(
|
|
160
|
+
missing.length +
|
|
161
|
+
' file(s) missing: ' +
|
|
162
|
+
missingSample +
|
|
163
|
+
(missing.length > 3 ? ', +' + (missing.length - 3) + ' more' : '')
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
reasonParts.push('set ' + SKIP_ENV + '=1 to bypass (dev only)');
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
ok: false,
|
|
170
|
+
reason: 'kit manifest mismatch — ' + reasonParts.join('; '),
|
|
171
|
+
mismatches,
|
|
172
|
+
missing,
|
|
173
|
+
};
|
|
174
|
+
}
|