layermap 0.1.51 → 0.1.53
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/analyzers/project-map-java/java-map.jar +0 -0
- package/dist/cli.mjs +439 -88
- package/package.json +3 -2
- package/pi/layermap.mjs +1 -1
|
Binary file
|
package/dist/cli.mjs
CHANGED
|
@@ -37,7 +37,7 @@ function mapCallLog(cache) {
|
|
|
37
37
|
// src/agent/environment.ts
|
|
38
38
|
import { createHash as createHash6 } from "node:crypto";
|
|
39
39
|
import { existsSync as existsSync6, readFileSync as readFileSync3 } from "node:fs";
|
|
40
|
-
import { mkdir as mkdir2, readdir, readFile as
|
|
40
|
+
import { mkdir as mkdir2, readdir, readFile as readFile5, rename as rename2, rm, stat as stat2, utimes, writeFile } from "node:fs/promises";
|
|
41
41
|
import { createRequire } from "node:module";
|
|
42
42
|
import { homedir } from "node:os";
|
|
43
43
|
import path16 from "node:path";
|
|
@@ -19126,7 +19126,6 @@ var TYPESCRIPT_MAP_LANGUAGE = Object.freeze({
|
|
|
19126
19126
|
reads: (path20) => path20.endsWith(".json") || path20.endsWith(".wxml") || path20 === "pnpm-workspace.yaml",
|
|
19127
19127
|
create: () => new TypeScriptMapAnalyzer()
|
|
19128
19128
|
});
|
|
19129
|
-
var CONFIGURATIONS_KEPT = 4;
|
|
19130
19129
|
var WORKERS_AT_ONCE = Math.min(4, availableParallelism());
|
|
19131
19130
|
function limit(atOnce) {
|
|
19132
19131
|
let running = 0;
|
|
@@ -19145,6 +19144,12 @@ function limit(atOnce) {
|
|
|
19145
19144
|
}
|
|
19146
19145
|
var MODULE_NAMES = /\b(?:from|import|require)\s*\(?\s*(["'`])([^"'`\n]+)\1|\/\/\/\s*<reference\s+(?:path|types|lib)\s*=\s*(["'])([^"'\n]+)\3/gu;
|
|
19147
19146
|
var moduleNames = (text) => digestValue([...text.matchAll(MODULE_NAMES)].map((match) => match[2] ?? match[4] ?? ""));
|
|
19147
|
+
var KeptDiscoverySchema = external_exports.object({
|
|
19148
|
+
key: external_exports.string(),
|
|
19149
|
+
discovered: MapConfigurationResultSchema,
|
|
19150
|
+
installed: external_exports.string(),
|
|
19151
|
+
files: external_exports.array(external_exports.tuple([external_exports.string(), external_exports.string().nullable(), external_exports.string().nullable()]))
|
|
19152
|
+
}).strict();
|
|
19148
19153
|
var sameShape = (left, right) => left.installed === right.installed && left.files.size === right.files.size && [...left.files].every(([path20, { shape }]) => right.files.get(path20)?.shape === shape);
|
|
19149
19154
|
var stopUnconfirmed = async (runs) => (await Promise.allSettled(runs)).flatMap((settled) => settled.status === "rejected" ? [settled.reason] : []).find((reason) => reason instanceof ProjectMapStopUnconfirmedError);
|
|
19150
19155
|
async function inOrder(tasks, take, signal, sizes) {
|
|
@@ -19178,11 +19183,6 @@ var TypeScriptMapAnalyzer = class {
|
|
|
19178
19183
|
id = TYPESCRIPT_MAP_LANGUAGE.id;
|
|
19179
19184
|
claims = TYPESCRIPT_MAP_LANGUAGE.claims;
|
|
19180
19185
|
reads = TYPESCRIPT_MAP_LANGUAGE.reads;
|
|
19181
|
-
// Discovery reads the texts of the files the language reads and what is installed, nothing else,
|
|
19182
|
-
// so a result stands while they are the same, as they are when only other languages' files changed.
|
|
19183
|
-
configurations = /* @__PURE__ */ new Map();
|
|
19184
|
-
// The last configuration discovered, and the shape of the code it was discovered from.
|
|
19185
|
-
last;
|
|
19186
19186
|
async operation(input, schema, signal, observe) {
|
|
19187
19187
|
const start = performance.now();
|
|
19188
19188
|
const event = {
|
|
@@ -19331,13 +19331,21 @@ var TypeScriptMapAnalyzer = class {
|
|
|
19331
19331
|
files: session.readable.map((entry) => [entry.path, entry.contentDigest ?? null]),
|
|
19332
19332
|
installed: installed.digest
|
|
19333
19333
|
});
|
|
19334
|
-
const
|
|
19334
|
+
const kept = session.kept === void 0 ? void 0 : KeptDiscoverySchema.parse(session.kept);
|
|
19335
|
+
const last = kept && {
|
|
19336
|
+
discovered: kept.discovered,
|
|
19337
|
+
shape: {
|
|
19338
|
+
installed: kept.installed,
|
|
19339
|
+
files: new Map(kept.files.map(([path20, digest, shape2]) => [path20, { digest, shape: shape2 }]))
|
|
19340
|
+
}
|
|
19341
|
+
};
|
|
19342
|
+
const known = kept?.key === configurationKey ? kept.discovered : void 0;
|
|
19335
19343
|
const shape = {
|
|
19336
19344
|
installed: installed.digest,
|
|
19337
19345
|
files: new Map(
|
|
19338
19346
|
session.readable.map((entry) => {
|
|
19339
19347
|
const digest = entry.contentDigest ?? null;
|
|
19340
|
-
const before =
|
|
19348
|
+
const before = last?.shape.files.get(entry.path);
|
|
19341
19349
|
return [
|
|
19342
19350
|
entry.path,
|
|
19343
19351
|
{
|
|
@@ -19348,7 +19356,7 @@ var TypeScriptMapAnalyzer = class {
|
|
|
19348
19356
|
})
|
|
19349
19357
|
)
|
|
19350
19358
|
};
|
|
19351
|
-
const guess = !known &&
|
|
19359
|
+
const guess = !known && last && sameShape(last.shape, shape) ? last.discovered : void 0;
|
|
19352
19360
|
const speculative = /* @__PURE__ */ new Map();
|
|
19353
19361
|
try {
|
|
19354
19362
|
if (guess && admitted(guess))
|
|
@@ -19381,11 +19389,12 @@ var TypeScriptMapAnalyzer = class {
|
|
|
19381
19389
|
signal,
|
|
19382
19390
|
observe
|
|
19383
19391
|
);
|
|
19384
|
-
|
|
19385
|
-
|
|
19386
|
-
|
|
19387
|
-
|
|
19388
|
-
|
|
19392
|
+
session.keep({
|
|
19393
|
+
key: configurationKey,
|
|
19394
|
+
discovered,
|
|
19395
|
+
installed: installed.digest,
|
|
19396
|
+
files: [...shape.files].map(([path20, file2]) => [path20, file2.digest, file2.shape])
|
|
19397
|
+
});
|
|
19389
19398
|
if (!admitted(discovered))
|
|
19390
19399
|
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
19391
19400
|
const { workspace } = discovered;
|
|
@@ -21412,6 +21421,21 @@ CREATE VIEW project_map_navigation AS
|
|
|
21412
21421
|
ON document.path = file.path AND document.unit_ref = coalesce(unit.unit_ref, '')
|
|
21413
21422
|
WHERE file.entry_state = 'TEXT';
|
|
21414
21423
|
`;
|
|
21424
|
+
var CODE_INDEX_COMPILE_RESULTS_MIGRATION = `
|
|
21425
|
+
CREATE TABLE project_map_compile_results (
|
|
21426
|
+
version_ref TEXT NOT NULL REFERENCES project_code_versions(version_ref) ON DELETE CASCADE,
|
|
21427
|
+
result_key TEXT NOT NULL,
|
|
21428
|
+
result_json TEXT NOT NULL CHECK (json_valid(result_json)),
|
|
21429
|
+
PRIMARY KEY (version_ref, result_key)
|
|
21430
|
+
);
|
|
21431
|
+
CREATE INDEX project_map_compile_result_key ON project_map_compile_results(result_key);
|
|
21432
|
+
CREATE TABLE project_map_language_states (
|
|
21433
|
+
version_ref TEXT NOT NULL REFERENCES project_code_versions(version_ref) ON DELETE CASCADE,
|
|
21434
|
+
language TEXT NOT NULL,
|
|
21435
|
+
state_json TEXT NOT NULL CHECK (json_valid(state_json)),
|
|
21436
|
+
PRIMARY KEY (version_ref, language)
|
|
21437
|
+
);
|
|
21438
|
+
`;
|
|
21415
21439
|
var MapReplayConflict = class extends Error {
|
|
21416
21440
|
};
|
|
21417
21441
|
var corrupt2 = () => {
|
|
@@ -21477,6 +21501,10 @@ var CodeIndexStore = class {
|
|
|
21477
21501
|
throw error51;
|
|
21478
21502
|
}
|
|
21479
21503
|
}
|
|
21504
|
+
/** Stages what a language keeps of the build for the next one, stored with the version. */
|
|
21505
|
+
appendMapLanguageState(buildRef, language, state) {
|
|
21506
|
+
this.database.prepare("INSERT INTO project_map_staging (build_ref, kind, value_json) VALUES (?, ?, ?)").run(buildRef, "states", canonicalJson({ language, state }));
|
|
21507
|
+
}
|
|
21480
21508
|
discardMapStage(buildRef) {
|
|
21481
21509
|
this.database.prepare("DELETE FROM project_map_staging WHERE build_ref = ?").run(buildRef);
|
|
21482
21510
|
}
|
|
@@ -21542,6 +21570,9 @@ var CodeIndexStore = class {
|
|
|
21542
21570
|
SELECT ?, json_extract(value_json, '$.ref'), json_extract(value_json, '$.requestDigest'),
|
|
21543
21571
|
value_json FROM project_map_staging
|
|
21544
21572
|
WHERE build_ref = ? AND kind = 'results' ORDER BY position`).run(version2.version, buildRef);
|
|
21573
|
+
this.database.prepare(`INSERT INTO project_map_language_states
|
|
21574
|
+
SELECT ?, value_json ->> '$.language', value_json -> '$.state'
|
|
21575
|
+
FROM project_map_staging WHERE build_ref = ? AND kind = 'states' ORDER BY position`).run(version2.version, buildRef);
|
|
21545
21576
|
this.commitUnits(version2.version, staged);
|
|
21546
21577
|
const member = this.database.prepare(
|
|
21547
21578
|
"INSERT INTO project_map_version_units VALUES (?, ?, ?)"
|
|
@@ -21726,6 +21757,42 @@ var CodeIndexStore = class {
|
|
|
21726
21757
|
WHERE version_ref = ? AND context_ref = ? AND json_type(result_json, '$.state') = 'object'`).get(version2, contextRef);
|
|
21727
21758
|
return row ? JSON.parse(String(row.state)) : void 0;
|
|
21728
21759
|
}
|
|
21760
|
+
/** What a language kept of a version's build, if anything. */
|
|
21761
|
+
mapLanguageState(version2, language) {
|
|
21762
|
+
const row = this.database.prepare(
|
|
21763
|
+
"SELECT state_json FROM project_map_language_states WHERE version_ref = ? AND language = ?"
|
|
21764
|
+
).get(version2, language);
|
|
21765
|
+
return row ? JSON.parse(String(row.state_json)) : void 0;
|
|
21766
|
+
}
|
|
21767
|
+
/**
|
|
21768
|
+
* The stored compile results of the given keys, whichever version stored them; a version reading
|
|
21769
|
+
* another's keeps a copy, so the result stays while either does.
|
|
21770
|
+
*/
|
|
21771
|
+
compileResults(version2, keys) {
|
|
21772
|
+
const own = this.database.prepare(
|
|
21773
|
+
"SELECT result_json FROM project_map_compile_results WHERE version_ref = ? AND result_key = ?"
|
|
21774
|
+
);
|
|
21775
|
+
const other = this.database.prepare(
|
|
21776
|
+
"SELECT result_json FROM project_map_compile_results WHERE result_key = ? LIMIT 1"
|
|
21777
|
+
);
|
|
21778
|
+
const copy = this.database.prepare(
|
|
21779
|
+
"INSERT OR IGNORE INTO project_map_compile_results VALUES (?, ?, ?)"
|
|
21780
|
+
);
|
|
21781
|
+
const found = /* @__PURE__ */ new Map();
|
|
21782
|
+
for (const key of new Set(keys)) {
|
|
21783
|
+
let row = own.get(version2, key);
|
|
21784
|
+
if (!row) {
|
|
21785
|
+
row = other.get(key);
|
|
21786
|
+
if (row) copy.run(version2, key, String(row.result_json));
|
|
21787
|
+
}
|
|
21788
|
+
if (row) found.set(key, JSON.parse(String(row.result_json)));
|
|
21789
|
+
}
|
|
21790
|
+
return found;
|
|
21791
|
+
}
|
|
21792
|
+
/** Keeps a compile result of a version, by the digest of what the compile read. */
|
|
21793
|
+
keepCompileResult(version2, key, result) {
|
|
21794
|
+
this.database.prepare("INSERT OR REPLACE INTO project_map_compile_results VALUES (?, ?, ?)").run(version2, key, canonicalJson(result));
|
|
21795
|
+
}
|
|
21729
21796
|
getVersion(version2) {
|
|
21730
21797
|
const row = this.database.prepare("SELECT * FROM project_code_versions WHERE version_ref = ?").get(version2);
|
|
21731
21798
|
if (!row) return void 0;
|
|
@@ -21976,7 +22043,7 @@ var ProjectMapAnalyzer = class {
|
|
|
21976
22043
|
diagnostics(input, path20, signal) {
|
|
21977
22044
|
return this.languages.find((language) => language.claims(path20))?.diagnostics?.(input, signal, this.observe);
|
|
21978
22045
|
}
|
|
21979
|
-
async analyze(reader, entries, installed, signal, consume, parent) {
|
|
22046
|
+
async analyze(reader, entries, installed, signal, consume, keep, parent) {
|
|
21980
22047
|
const result = {
|
|
21981
22048
|
gaps: [{ code: "MAP_COVERS_ADMITTED_SCOPE_AND_POLICY_ONLY" }],
|
|
21982
22049
|
parsedFiles: []
|
|
@@ -22110,6 +22177,8 @@ var ProjectMapAnalyzer = class {
|
|
|
22110
22177
|
replays,
|
|
22111
22178
|
previous,
|
|
22112
22179
|
configuration: (path20) => configurationInputs.add(path20),
|
|
22180
|
+
kept: parent?.kept(language.id),
|
|
22181
|
+
keep: (state) => keep(language.id, state),
|
|
22113
22182
|
observe: this.observe
|
|
22114
22183
|
},
|
|
22115
22184
|
signal
|
|
@@ -22195,14 +22264,93 @@ var ProjectMapReferenceQuery = class {
|
|
|
22195
22264
|
AND json_extract(c.context_json, '$.mode') != 'SYNTAX_ONLY'
|
|
22196
22265
|
ORDER BY c.context_ref`).all(version2, path20).map((value) => MapContextSchema.parse(JSON.parse(String(value.context_json))));
|
|
22197
22266
|
}
|
|
22198
|
-
// A context's
|
|
22199
|
-
|
|
22200
|
-
|
|
22267
|
+
// A context's files as the version captured them.
|
|
22268
|
+
entries(version2, context) {
|
|
22269
|
+
return context.inputFiles.map((file2) => {
|
|
22201
22270
|
const entry = this.store.getEntry(version2, file2);
|
|
22202
22271
|
if (entry?.state !== "TEXT")
|
|
22203
22272
|
throw new ProjectEvidenceError("PROJECT_EVIDENCE_STORE_CORRUPT", false);
|
|
22204
22273
|
return entry;
|
|
22205
22274
|
});
|
|
22275
|
+
}
|
|
22276
|
+
/**
|
|
22277
|
+
* The digest of everything a compile of a context reads: the analyzers, the context, its files'
|
|
22278
|
+
* contents and the packages installed now where they resolve them. A compile of equal inputs says
|
|
22279
|
+
* the same, so its stored result stands for it.
|
|
22280
|
+
*/
|
|
22281
|
+
compileInputs(version2, source, context) {
|
|
22282
|
+
const { ref, configPath, rootFiles, workspace, inputFiles } = context;
|
|
22283
|
+
return digestValue({
|
|
22284
|
+
analyzer: this.analyzer.id,
|
|
22285
|
+
context: {
|
|
22286
|
+
ref,
|
|
22287
|
+
configPath: configPath ?? null,
|
|
22288
|
+
rootFiles: rootFiles ?? null,
|
|
22289
|
+
workspace: workspace ?? null,
|
|
22290
|
+
inputFiles
|
|
22291
|
+
},
|
|
22292
|
+
contents: this.entries(version2, context).map((entry) => [entry.path, entry.contentDigest]),
|
|
22293
|
+
installed: mapInstalledDigest(source.directory.canonicalPath, inputFiles)
|
|
22294
|
+
});
|
|
22295
|
+
}
|
|
22296
|
+
/**
|
|
22297
|
+
* A context's compiler diagnostics: the stored result of a compile of the same inputs, or a
|
|
22298
|
+
* compile's, stored for the next. Undefined for a language without a compiler to ask.
|
|
22299
|
+
*/
|
|
22300
|
+
async compileDiagnostics(version2, source, context, path20, signal) {
|
|
22301
|
+
const key = digestValue({
|
|
22302
|
+
operation: "DIAGNOSTICS",
|
|
22303
|
+
inputs: this.compileInputs(version2, source, context)
|
|
22304
|
+
});
|
|
22305
|
+
const stored = this.store.compileResults(version2, [key]);
|
|
22306
|
+
if (stored.has(key)) return MapDiagnosticsSchema.parse(stored.get(key));
|
|
22307
|
+
const { reader, request } = await this.open(version2, source, context, signal);
|
|
22308
|
+
const result = await this.analyzer.diagnostics(request, path20, signal);
|
|
22309
|
+
await reader.assertStable();
|
|
22310
|
+
if (!result) return void 0;
|
|
22311
|
+
if (result.requiredFiles.length)
|
|
22312
|
+
throw new ProjectEvidenceError("PROJECT_MAP_CONTEXT_INCOMPLETE", false);
|
|
22313
|
+
this.store.keepCompileResult(version2, key, result);
|
|
22314
|
+
return result;
|
|
22315
|
+
}
|
|
22316
|
+
/**
|
|
22317
|
+
* A page for each request of one context, in order: stored pages of compiles of the same inputs,
|
|
22318
|
+
* and one compile for the rest, whose pages are stored for the next. A request the deadline left
|
|
22319
|
+
* unread has no page.
|
|
22320
|
+
*/
|
|
22321
|
+
async referencePages(version2, source, context, requests, signal, until) {
|
|
22322
|
+
const inputs = this.compileInputs(version2, source, context);
|
|
22323
|
+
const keys = requests.map(
|
|
22324
|
+
(request2) => digestValue({ operation: "REFERENCES", inputs, request: request2 })
|
|
22325
|
+
);
|
|
22326
|
+
const stored = this.store.compileResults(version2, keys);
|
|
22327
|
+
const pages = keys.map(
|
|
22328
|
+
(key) => stored.has(key) ? MapReferencePageSchema.nullable().parse(stored.get(key)) : void 0
|
|
22329
|
+
);
|
|
22330
|
+
const unread = keys.flatMap((_, at) => pages[at] === void 0 ? [at] : []);
|
|
22331
|
+
if (!unread.length) return pages;
|
|
22332
|
+
const { reader, files, request } = await this.open(version2, source, context, signal);
|
|
22333
|
+
const { pages: read, requiredFiles } = await this.analyzer.references(
|
|
22334
|
+
request,
|
|
22335
|
+
unread.map((at) => requests[at]),
|
|
22336
|
+
signal,
|
|
22337
|
+
until
|
|
22338
|
+
);
|
|
22339
|
+
if (requiredFiles.length)
|
|
22340
|
+
throw new ProjectEvidenceError("PROJECT_MAP_CONTEXT_INCOMPLETE", false);
|
|
22341
|
+
if (read.length > unread.length || read.some((page) => page?.references.some((reference) => !anchored(reference, files))))
|
|
22342
|
+
throw invalidProtocol();
|
|
22343
|
+
await reader.assertStable();
|
|
22344
|
+
for (const [index, page] of read.entries()) {
|
|
22345
|
+
const at = unread[index];
|
|
22346
|
+
pages[at] = page;
|
|
22347
|
+
this.store.keepCompileResult(version2, keys[at], page);
|
|
22348
|
+
}
|
|
22349
|
+
return pages;
|
|
22350
|
+
}
|
|
22351
|
+
// A context's sources, and the request for its compile.
|
|
22352
|
+
async open(version2, source, context, signal) {
|
|
22353
|
+
const entries = this.entries(version2, context);
|
|
22206
22354
|
const reader = await ProjectMapSourceReader.open(source, signal, false);
|
|
22207
22355
|
const files = /* @__PURE__ */ Object.create(null);
|
|
22208
22356
|
const contents = await reader.readAll(entries);
|
|
@@ -22258,12 +22406,8 @@ var ProjectMapReferenceQuery = class {
|
|
|
22258
22406
|
continue;
|
|
22259
22407
|
}
|
|
22260
22408
|
const [path20] = context.rootFiles ?? context.inputFiles;
|
|
22261
|
-
const
|
|
22262
|
-
const result = path20 === void 0 ? void 0 : await this.analyzer.diagnostics(request, path20, signal);
|
|
22263
|
-
await reader.assertStable();
|
|
22409
|
+
const result = path20 === void 0 ? void 0 : await this.compileDiagnostics(input.version, source, context, path20, signal);
|
|
22264
22410
|
if (!result) continue;
|
|
22265
|
-
if (result.requiredFiles.length)
|
|
22266
|
-
throw new ProjectEvidenceError("PROJECT_MAP_CONTEXT_INCOMPLETE", false);
|
|
22267
22411
|
const found = new Map(
|
|
22268
22412
|
result.diagnostics.map((item) => [
|
|
22269
22413
|
`${item.path}:${item.line}:${item.code}:${item.text}`,
|
|
@@ -22311,9 +22455,10 @@ var ProjectMapReferenceQuery = class {
|
|
|
22311
22455
|
}
|
|
22312
22456
|
for (const { context, targets } of compiles.values()) {
|
|
22313
22457
|
if (Date.now() > input.until) break;
|
|
22314
|
-
const
|
|
22315
|
-
|
|
22316
|
-
|
|
22458
|
+
const pages = await this.referencePages(
|
|
22459
|
+
input.version,
|
|
22460
|
+
source,
|
|
22461
|
+
context,
|
|
22317
22462
|
targets.map((object2) => ({
|
|
22318
22463
|
targetPath: object2.anchor.path,
|
|
22319
22464
|
symbolStart: object2.symbolStart,
|
|
@@ -22323,24 +22468,19 @@ var ProjectMapReferenceQuery = class {
|
|
|
22323
22468
|
signal,
|
|
22324
22469
|
input.until
|
|
22325
22470
|
);
|
|
22326
|
-
if (requiredFiles.length)
|
|
22327
|
-
throw new ProjectEvidenceError("PROJECT_MAP_CONTEXT_INCOMPLETE", false);
|
|
22328
|
-
if (pages.length > targets.length)
|
|
22329
|
-
throw new ProjectEvidenceError("PROJECT_MAP_PROTOCOL_INVALID", false);
|
|
22330
22471
|
for (const [at, page] of pages.entries()) {
|
|
22472
|
+
if (page === void 0) continue;
|
|
22331
22473
|
const read = found.get(targets[at]?.id ?? "");
|
|
22332
22474
|
read.waiting--;
|
|
22333
22475
|
if (!page || page.nextOffset !== void 0) read.complete = false;
|
|
22334
22476
|
for (const reference of page?.references ?? []) {
|
|
22335
22477
|
const location2 = canonicalJson(reference.anchor);
|
|
22336
|
-
if (!anchored(reference, files)) throw invalidProtocol();
|
|
22337
22478
|
if (read.locations.has(location2)) continue;
|
|
22338
22479
|
read.locations.add(location2);
|
|
22339
22480
|
const owner = this.owner(input.version, reference.anchor);
|
|
22340
22481
|
read.uses.push({ ...reference, ...owner ? { owner } : {} });
|
|
22341
22482
|
}
|
|
22342
22483
|
}
|
|
22343
|
-
await reader.assertStable();
|
|
22344
22484
|
if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
|
|
22345
22485
|
}
|
|
22346
22486
|
return new Map(
|
|
@@ -22420,12 +22560,10 @@ ${scope}`, input.cursor, 2) : [];
|
|
|
22420
22560
|
}
|
|
22421
22561
|
const context = contexts[cursor.context];
|
|
22422
22562
|
if (!context) throw new ProjectEvidenceError("PROJECT_CONTINUATION_INVALID", false);
|
|
22423
|
-
const
|
|
22424
|
-
|
|
22425
|
-
|
|
22426
|
-
|
|
22427
|
-
} = await this.analyzer.references(
|
|
22428
|
-
request,
|
|
22563
|
+
const [page] = await this.referencePages(
|
|
22564
|
+
input.version,
|
|
22565
|
+
source,
|
|
22566
|
+
context,
|
|
22429
22567
|
[
|
|
22430
22568
|
{
|
|
22431
22569
|
targetPath: object2.anchor.path,
|
|
@@ -22437,8 +22575,6 @@ ${scope}`, input.cursor, 2) : [];
|
|
|
22437
22575
|
],
|
|
22438
22576
|
signal
|
|
22439
22577
|
);
|
|
22440
|
-
if (requiredFiles.length)
|
|
22441
|
-
throw new ProjectEvidenceError("PROJECT_MAP_CONTEXT_INCOMPLETE", false);
|
|
22442
22578
|
if (page === void 0) throw invalidProtocol();
|
|
22443
22579
|
if (page === null)
|
|
22444
22580
|
throw new ProjectEvidenceError("PROJECT_MAP_REFERENCE_TARGET_UNAVAILABLE", false);
|
|
@@ -22448,14 +22584,13 @@ ${scope}`, input.cursor, 2) : [];
|
|
|
22448
22584
|
const locations = /* @__PURE__ */ new Set();
|
|
22449
22585
|
for (const reference of page.references) {
|
|
22450
22586
|
const location2 = canonicalJson(reference.anchor);
|
|
22451
|
-
if (!
|
|
22587
|
+
if (!mapPathAllowed(reference.anchor.path, prefixes) || !mapQueryPathMatches(reference.anchor.path, query.within) || !query.kinds.includes(reference.kind) || locations.has(location2))
|
|
22452
22588
|
throw invalidProtocol();
|
|
22453
22589
|
locations.add(location2);
|
|
22454
22590
|
const owner = this.owner(input.version, reference.anchor);
|
|
22455
22591
|
const item = { ...reference, contextRef: context.ref, ...owner ? { owner } : {} };
|
|
22456
22592
|
references.push(item);
|
|
22457
22593
|
}
|
|
22458
|
-
await reader.assertStable();
|
|
22459
22594
|
if (signal.aborted) throw new ProjectEvidenceError("PROJECT_READ_CANCELLED", true);
|
|
22460
22595
|
return mapQueryPage(
|
|
22461
22596
|
references.length,
|
|
@@ -22569,6 +22704,7 @@ var CodeIndex = class {
|
|
|
22569
22704
|
{ directory: source.directory.canonicalPath, digest: result.installedDigest },
|
|
22570
22705
|
controller.signal,
|
|
22571
22706
|
(unit, record2) => this.store.appendMapStage(stage, unit, record2),
|
|
22707
|
+
(language, state) => this.store.appendMapLanguageState(stage, language, state),
|
|
22572
22708
|
parent && { ...parent, link: (paths) => linked.push(...paths) }
|
|
22573
22709
|
);
|
|
22574
22710
|
await reader.readAll(result.entries);
|
|
@@ -22633,7 +22769,8 @@ var CodeIndex = class {
|
|
|
22633
22769
|
entries,
|
|
22634
22770
|
contexts: this.store.mapContexts(version2),
|
|
22635
22771
|
shell: (contextRef) => this.store.mapContextShell(version2, contextRef),
|
|
22636
|
-
state: (contextRef) => this.store.mapContextState(version2, contextRef)
|
|
22772
|
+
state: (contextRef) => this.store.mapContextState(version2, contextRef),
|
|
22773
|
+
kept: (language) => this.store.mapLanguageState(version2, language)
|
|
22637
22774
|
};
|
|
22638
22775
|
}
|
|
22639
22776
|
read(signal, operation) {
|
|
@@ -22781,9 +22918,178 @@ var CodeIndex = class {
|
|
|
22781
22918
|
};
|
|
22782
22919
|
|
|
22783
22920
|
// src/project-map-change-diff.ts
|
|
22784
|
-
import { lstat as lstat3, open as open2 } from "node:fs/promises";
|
|
22921
|
+
import { lstat as lstat3, open as open2, readFile as readFile2 } from "node:fs/promises";
|
|
22785
22922
|
import path12 from "node:path";
|
|
22786
22923
|
|
|
22924
|
+
// src/project-map-change-runtime.ts
|
|
22925
|
+
import { transformSync } from "esbuild";
|
|
22926
|
+
var LOADERS = {
|
|
22927
|
+
".ts": "ts",
|
|
22928
|
+
".mts": "ts",
|
|
22929
|
+
".cts": "ts",
|
|
22930
|
+
".tsx": "tsx"
|
|
22931
|
+
};
|
|
22932
|
+
var DECORATED = /\b__decorat(?:orStart|eClass|eParam)\b/u;
|
|
22933
|
+
var PAIRS = 4e6;
|
|
22934
|
+
var mapErasable = (path20) => !path20.endsWith(".d.ts") && LOADERS[path20.slice(path20.lastIndexOf("."))] !== void 0;
|
|
22935
|
+
function erase(text, path20) {
|
|
22936
|
+
const loader = LOADERS[path20.slice(path20.lastIndexOf("."))];
|
|
22937
|
+
if (!loader) return void 0;
|
|
22938
|
+
let code;
|
|
22939
|
+
let map2;
|
|
22940
|
+
try {
|
|
22941
|
+
({ code, map: map2 } = transformSync(text, {
|
|
22942
|
+
loader,
|
|
22943
|
+
sourcefile: path20,
|
|
22944
|
+
target: "esnext",
|
|
22945
|
+
// Lowered, so a decorator shows in the helpers it needs.
|
|
22946
|
+
supported: { decorators: false },
|
|
22947
|
+
jsx: "preserve",
|
|
22948
|
+
legalComments: "none",
|
|
22949
|
+
sourcemap: "external",
|
|
22950
|
+
logLevel: "silent",
|
|
22951
|
+
// Fields declared without a value are fields at run time under the standard semantics, and an
|
|
22952
|
+
// import is kept as written: whichever the project's settings, a change to either is code.
|
|
22953
|
+
tsconfigRaw: {
|
|
22954
|
+
compilerOptions: { useDefineForClassFields: true, verbatimModuleSyntax: true }
|
|
22955
|
+
}
|
|
22956
|
+
}));
|
|
22957
|
+
} catch {
|
|
22958
|
+
return void 0;
|
|
22959
|
+
}
|
|
22960
|
+
if (DECORATED.test(code)) return void 0;
|
|
22961
|
+
const lines = code.split("\n");
|
|
22962
|
+
if (lines.at(-1) === "") lines.pop();
|
|
22963
|
+
const from = sourceLines(map2, lines.length);
|
|
22964
|
+
if (!from) return void 0;
|
|
22965
|
+
return { lines: lines.map((line) => line.trim()), from };
|
|
22966
|
+
}
|
|
22967
|
+
var VLQ = new Map(
|
|
22968
|
+
[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"].map((c, i) => [c, i])
|
|
22969
|
+
);
|
|
22970
|
+
function sourceLines(map2, count) {
|
|
22971
|
+
let mappings;
|
|
22972
|
+
try {
|
|
22973
|
+
mappings = String(JSON.parse(map2).mappings);
|
|
22974
|
+
} catch {
|
|
22975
|
+
return void 0;
|
|
22976
|
+
}
|
|
22977
|
+
const seen = [];
|
|
22978
|
+
let source = 0;
|
|
22979
|
+
const groups = mappings.split(";");
|
|
22980
|
+
for (const [generated, group] of groups.entries()) {
|
|
22981
|
+
for (const segment of group ? group.split(",") : []) {
|
|
22982
|
+
const fields2 = [];
|
|
22983
|
+
let value = 0;
|
|
22984
|
+
let shift = 0;
|
|
22985
|
+
for (const char of segment) {
|
|
22986
|
+
const digit = VLQ.get(char);
|
|
22987
|
+
if (digit === void 0) return void 0;
|
|
22988
|
+
value += (digit & 31) << shift;
|
|
22989
|
+
if (digit & 32) shift += 5;
|
|
22990
|
+
else {
|
|
22991
|
+
fields2.push(value & 1 ? -(value >>> 1) : value >>> 1);
|
|
22992
|
+
value = 0;
|
|
22993
|
+
shift = 0;
|
|
22994
|
+
}
|
|
22995
|
+
}
|
|
22996
|
+
if (fields2.length < 4) continue;
|
|
22997
|
+
source += fields2[2];
|
|
22998
|
+
if (fields2[2] === 0 && fields2[3] === 0) continue;
|
|
22999
|
+
const lines = seen[generated] ?? [];
|
|
23000
|
+
lines.push(source + 1);
|
|
23001
|
+
seen[generated] = lines;
|
|
23002
|
+
}
|
|
23003
|
+
}
|
|
23004
|
+
const last = [];
|
|
23005
|
+
const next = [];
|
|
23006
|
+
for (let line = 0, at; line < count; line++) {
|
|
23007
|
+
last[line] = at;
|
|
23008
|
+
const own = seen[line];
|
|
23009
|
+
if (own?.length) at = Math.max(...own);
|
|
23010
|
+
}
|
|
23011
|
+
for (let line = count - 1, at; line >= 0; line--) {
|
|
23012
|
+
next[line] = at;
|
|
23013
|
+
const own = seen[line];
|
|
23014
|
+
if (own?.length) at = Math.min(...own);
|
|
23015
|
+
}
|
|
23016
|
+
const from = [];
|
|
23017
|
+
for (let line = 0; line < count; line++) {
|
|
23018
|
+
const own = seen[line];
|
|
23019
|
+
if (own?.length) from.push([Math.min(...own), Math.max(...own)]);
|
|
23020
|
+
else if (last[line] === void 0 && next[line] === void 0) return void 0;
|
|
23021
|
+
else from.push([last[line] ?? 1, next[line] ?? Number.MAX_SAFE_INTEGER]);
|
|
23022
|
+
}
|
|
23023
|
+
return from;
|
|
23024
|
+
}
|
|
23025
|
+
var touches = (region, [start, end]) => region.from <= region.to ? start <= region.to && region.from <= end : start <= region.to && end >= region.from;
|
|
23026
|
+
function mapRuntimeLines(path20, baseText, text, hunks) {
|
|
23027
|
+
const before = erase(baseText, path20);
|
|
23028
|
+
const after = erase(text, path20);
|
|
23029
|
+
if (!before || !after) return void 0;
|
|
23030
|
+
const regions = hunks.map((hunk) => ({
|
|
23031
|
+
base: hunk.baseCount ? { from: hunk.baseStart, to: hunk.baseStart + hunk.baseCount - 1 } : { from: hunk.baseStart + 1, to: hunk.baseStart },
|
|
23032
|
+
working: hunk.count ? { from: hunk.start, to: hunk.start + hunk.count - 1 } : { from: hunk.start + 1, to: hunk.start }
|
|
23033
|
+
}));
|
|
23034
|
+
const outside = (erased, side) => erased.lines.filter(
|
|
23035
|
+
(_, line) => !regions.some((region) => touches(region[side], erased.from[line]))
|
|
23036
|
+
);
|
|
23037
|
+
const kept = outside(before, "base");
|
|
23038
|
+
const left = outside(after, "working");
|
|
23039
|
+
const bare = (line) => line?.replace(/,$/u, "");
|
|
23040
|
+
if (kept.length !== left.length || kept.some((line, at) => bare(line) !== bare(left[at])))
|
|
23041
|
+
return void 0;
|
|
23042
|
+
const lines = [];
|
|
23043
|
+
for (const region of regions) {
|
|
23044
|
+
const pick2 = (erased, side) => erased.lines.flatMap((line, at) => {
|
|
23045
|
+
const from = erased.from[at];
|
|
23046
|
+
return touches(side, from) ? [{ line, from }] : [];
|
|
23047
|
+
});
|
|
23048
|
+
lines.push(
|
|
23049
|
+
...changedIn(pick2(before, region.base), pick2(after, region.working), region.working)
|
|
23050
|
+
);
|
|
23051
|
+
}
|
|
23052
|
+
const same3 = before.lines.length === after.lines.length && before.lines.every((line, at) => line === after.lines[at]);
|
|
23053
|
+
if (!same3 && !lines.length) return void 0;
|
|
23054
|
+
const seen = /* @__PURE__ */ new Set();
|
|
23055
|
+
return lines.sort(([a, b], [c, d]) => a - c || b - d).filter((range) => !seen.has(`${range}`) && Boolean(seen.add(`${range}`)));
|
|
23056
|
+
}
|
|
23057
|
+
function changedIn(base, working, region) {
|
|
23058
|
+
if (base.length === working.length && base.every((piece, at) => piece.line === working[at]?.line))
|
|
23059
|
+
return [];
|
|
23060
|
+
const whole = [region.from, region.to];
|
|
23061
|
+
if (base.length * working.length > PAIRS) return [whole];
|
|
23062
|
+
const width = working.length + 1;
|
|
23063
|
+
const table = new Uint32Array((base.length + 1) * width);
|
|
23064
|
+
for (let i = base.length - 1; i >= 0; i--)
|
|
23065
|
+
for (let j = working.length - 1; j >= 0; j--)
|
|
23066
|
+
table[i * width + j] = base[i]?.line === working[j]?.line ? table[(i + 1) * width + j + 1] + 1 : Math.max(table[(i + 1) * width + j], table[i * width + j + 1]);
|
|
23067
|
+
const pairs = [];
|
|
23068
|
+
for (let i = 0, j = 0; i < base.length && j < working.length; )
|
|
23069
|
+
if (base[i]?.line === working[j]?.line) pairs.push([i++, j++]);
|
|
23070
|
+
else if (table[(i + 1) * width + j] >= table[i * width + j + 1]) i++;
|
|
23071
|
+
else j++;
|
|
23072
|
+
const lines = [];
|
|
23073
|
+
const clamp = (start, end) => {
|
|
23074
|
+
const from = Math.max(start, region.from);
|
|
23075
|
+
const to = Math.min(end, region.to);
|
|
23076
|
+
lines.push(region.from <= region.to && from <= to ? [from, to] : whole);
|
|
23077
|
+
};
|
|
23078
|
+
const matched = new Set(pairs.map(([, j]) => j));
|
|
23079
|
+
for (const [j, piece] of working.entries()) if (!matched.has(j)) clamp(...piece.from);
|
|
23080
|
+
const bounds = [[-1, -1], ...pairs, [base.length, working.length]];
|
|
23081
|
+
for (let at = 1; at < bounds.length; at++) {
|
|
23082
|
+
const [i0, j0] = bounds[at - 1];
|
|
23083
|
+
const [i1, j1] = bounds[at];
|
|
23084
|
+
if (i1 - i0 <= 1) continue;
|
|
23085
|
+
clamp(
|
|
23086
|
+
j0 >= 0 ? working[j0].from[1] : region.from,
|
|
23087
|
+
j1 < working.length ? working[j1].from[0] : region.to
|
|
23088
|
+
);
|
|
23089
|
+
}
|
|
23090
|
+
return lines;
|
|
23091
|
+
}
|
|
23092
|
+
|
|
22787
23093
|
// src/project-map-names.ts
|
|
22788
23094
|
import { readFile } from "node:fs/promises";
|
|
22789
23095
|
import path11 from "node:path";
|
|
@@ -22946,6 +23252,7 @@ async function readMapChanges(project, base, signal, options = { names: true })
|
|
|
22946
23252
|
// not analyze is told the way git tells it, by a NUL in its first 8000 bytes.
|
|
22947
23253
|
binary: !mapLanguageOf(file2) && await startsBinary(path12.join(project, file2))
|
|
22948
23254
|
});
|
|
23255
|
+
await eraseTypes(project, commit, files, signal);
|
|
22949
23256
|
const stranded = options.names ? await strandedNames(
|
|
22950
23257
|
project,
|
|
22951
23258
|
files,
|
|
@@ -22955,6 +23262,22 @@ async function readMapChanges(project, base, signal, options = { names: true })
|
|
|
22955
23262
|
) : { names: [] };
|
|
22956
23263
|
return { base, commit, files, quoted: parsed.quoted, stranded };
|
|
22957
23264
|
}
|
|
23265
|
+
async function eraseTypes(project, commit, files, signal) {
|
|
23266
|
+
const erasable = [...files.entries()].filter(
|
|
23267
|
+
([, file2]) => file2.status !== "DELETED" && !file2.binary && !mapTestPath(file2.path) && mapErasable(file2.path)
|
|
23268
|
+
);
|
|
23269
|
+
for (let at = 0; at < erasable.length; at += 8)
|
|
23270
|
+
await Promise.all(
|
|
23271
|
+
erasable.slice(at, at + 8).map(async ([index, file2]) => {
|
|
23272
|
+
const text = await readFile2(path12.join(project, file2.path), "utf8").catch(() => void 0);
|
|
23273
|
+
const baseText = file2.status === "ADDED" || !file2.basePath ? "" : await git.run(["show", `${commit}:${file2.basePath}`], gitOptions(project, signal)).then((result) => result.stdout.toString("utf8")).catch(() => void 0);
|
|
23274
|
+
if (text === void 0 || baseText === void 0) return;
|
|
23275
|
+
const hunks = file2.hunks.length ? file2.hunks : [{ baseStart: 0, baseCount: 0, start: 1, count: text.split("\n").length }];
|
|
23276
|
+
const runtime = mapRuntimeLines(file2.path, baseText, text, hunks);
|
|
23277
|
+
if (runtime) files[index] = { ...file2, runtime };
|
|
23278
|
+
})
|
|
23279
|
+
);
|
|
23280
|
+
}
|
|
22958
23281
|
async function startsBinary(file2) {
|
|
22959
23282
|
if (!(await lstat3(file2).catch(() => void 0))?.isFile()) return false;
|
|
22960
23283
|
const handle = await open2(file2, "r").catch(() => void 0);
|
|
@@ -23080,7 +23403,7 @@ var DOCUMENTATION = /\.(?:md|mdx|markdown|rst|adoc)$|(?:^|\/)(?:LICENSE|NOTICE)[
|
|
|
23080
23403
|
var unmappedKind = (path20, binary) => nonCodeKind(path20) ?? (binary ? "binary file" : DOCUMENTATION.test(path20) ? void 0 : UNANALYZED.find(([pattern]) => pattern.test(path20))?.[1] ?? "unanalyzed file");
|
|
23081
23404
|
|
|
23082
23405
|
// src/project-map-changes.ts
|
|
23083
|
-
import { readFile as
|
|
23406
|
+
import { readFile as readFile4 } from "node:fs/promises";
|
|
23084
23407
|
import path14 from "node:path";
|
|
23085
23408
|
|
|
23086
23409
|
// src/project-map-change-types.ts
|
|
@@ -23285,6 +23608,15 @@ var routeClientsLine = ({ route, removed, clients }) => `${JSON.stringify(route)
|
|
|
23285
23608
|
var KINDS = /* @__PURE__ */ new Set(["PROPERTY", "TYPE", "INTERFACE", "ENUM"]);
|
|
23286
23609
|
var READ_MS = 2e4;
|
|
23287
23610
|
var mapIsShape = (object2) => KINDS.has(object2.kind) && object2.execution !== "CLOSURE";
|
|
23611
|
+
var TYPE_KINDS = /* @__PURE__ */ new Set(["TYPE", "INTERFACE"]);
|
|
23612
|
+
function mapTypeOnly(graph, ref) {
|
|
23613
|
+
for (let at = ref; at !== void 0; at = graph.parent(at)) {
|
|
23614
|
+
const object2 = graph.object(at);
|
|
23615
|
+
if (TYPE_KINDS.has(object2.kind)) return true;
|
|
23616
|
+
if (object2.execution || object2.kind !== "PROPERTY" && object2.kind !== "METHOD") return false;
|
|
23617
|
+
}
|
|
23618
|
+
return false;
|
|
23619
|
+
}
|
|
23288
23620
|
var mapShapeDeadline = () => Date.now() + READ_MS;
|
|
23289
23621
|
var MapShapeUses = class {
|
|
23290
23622
|
constructor(graph, reader, until) {
|
|
@@ -24083,7 +24415,7 @@ function mapChangeEdges(links) {
|
|
|
24083
24415
|
}
|
|
24084
24416
|
|
|
24085
24417
|
// src/project-map-change-tests.ts
|
|
24086
|
-
import { readFile as
|
|
24418
|
+
import { readFile as readFile3 } from "node:fs/promises";
|
|
24087
24419
|
import path13 from "node:path";
|
|
24088
24420
|
|
|
24089
24421
|
// src/project-map-route-paths.ts
|
|
@@ -24211,7 +24543,7 @@ var MAP_PATH_PARAMETER = "{}";
|
|
|
24211
24543
|
async function existingTestsChanged(before, after, file2, project) {
|
|
24212
24544
|
if (!file2.basePath || file2.baseText === void 0) return [];
|
|
24213
24545
|
const baseLines = file2.baseText.split("\n");
|
|
24214
|
-
const workingLines = file2.status !== "DELETED" && project ? (await
|
|
24546
|
+
const workingLines = file2.status !== "DELETED" && project ? (await readFile3(path13.join(project, file2.path), "utf8").catch(() => void 0))?.split(
|
|
24215
24547
|
"\n"
|
|
24216
24548
|
) ?? [] : [];
|
|
24217
24549
|
const body = (lines, object2) => lines.slice(object2.anchor.startLine - 1, object2.anchor.endLine).map((line) => line.trimEnd());
|
|
@@ -24379,7 +24711,7 @@ var RouteRequests = class {
|
|
|
24379
24711
|
}
|
|
24380
24712
|
const batch = this.candidates.slice(at, at + READ_BATCH);
|
|
24381
24713
|
const texts = await Promise.all(
|
|
24382
|
-
batch.map((file2) =>
|
|
24714
|
+
batch.map((file2) => readFile3(path13.join(project, file2), "utf8").catch(() => void 0))
|
|
24383
24715
|
);
|
|
24384
24716
|
for (const [index, text] of texts.entries())
|
|
24385
24717
|
if (text !== void 0) yield [batch[index], text];
|
|
@@ -24487,13 +24819,13 @@ async function mapRemovedImpact(input) {
|
|
|
24487
24819
|
input.cache.memberCalls(store, base),
|
|
24488
24820
|
new MapShapeUses(before, input.shapes, input.until)
|
|
24489
24821
|
);
|
|
24490
|
-
const
|
|
24822
|
+
const changedIn2 = changedInBase(changes.files);
|
|
24491
24823
|
const pathNow = (path20) => {
|
|
24492
|
-
const file2 =
|
|
24824
|
+
const file2 = changedIn2.get(path20);
|
|
24493
24825
|
return file2?.status === "DELETED" ? void 0 : file2?.path ?? path20;
|
|
24494
24826
|
};
|
|
24495
24827
|
const nowAt = (anchor) => {
|
|
24496
|
-
const file2 =
|
|
24828
|
+
const file2 = changedIn2.get(anchor.path);
|
|
24497
24829
|
if (file2 && (file2.status === "DELETED" || overlaps(file2.baseLines, anchor.startLine, anchor.endLine)))
|
|
24498
24830
|
return void 0;
|
|
24499
24831
|
return {
|
|
@@ -24659,8 +24991,9 @@ async function mapRemovedImpact(input) {
|
|
|
24659
24991
|
))
|
|
24660
24992
|
topLevel.push(file2.path);
|
|
24661
24993
|
}
|
|
24662
|
-
|
|
24663
|
-
|
|
24994
|
+
const ran = [...gone2].filter((ref) => !mapTypeOnly(before, ref));
|
|
24995
|
+
if (ran.length) {
|
|
24996
|
+
await beforeTracer.trace(ran, ran, true);
|
|
24664
24997
|
const siteNow = (site) => {
|
|
24665
24998
|
const at = site.lastIndexOf(":");
|
|
24666
24999
|
const line = Number(site.slice(at + 1));
|
|
@@ -24949,7 +25282,8 @@ Nothing changed against ${changes.base}.`;
|
|
|
24949
25282
|
"Where the diff changed a route's registration, check that the route still reaches the right handler."
|
|
24950
25283
|
);
|
|
24951
25284
|
if (impact.untested) {
|
|
24952
|
-
const { changed, entries, throughRoutes, routes: routes2, missing, truncated } = impact.untested;
|
|
25285
|
+
const { changed, entries, throughRoutes, routes: routes2, missing, truncated, typeOnly } = impact.untested;
|
|
25286
|
+
const runs = impact.changed.length - typeOnly;
|
|
24953
25287
|
const items = (shown, limit2) => {
|
|
24954
25288
|
lines.push(...shown.slice(0, limit2).map((item) => ` ${item}`));
|
|
24955
25289
|
if (shown.length > limit2) lines.push(` +${shown.length - limit2} more`);
|
|
@@ -24959,7 +25293,7 @@ Nothing changed against ${changes.base}.`;
|
|
|
24959
25293
|
lines.push(` the map has no code for these given files: ${missing.join(", ")}`);
|
|
24960
25294
|
if (changed.length) {
|
|
24961
25295
|
lines.push(
|
|
24962
|
-
` ${changed.length} of ${
|
|
25296
|
+
` ${changed.length} of ${runs} changed declarations are reached by none of the given tests; ${entries.length ? "the entry points above them, then the declarations:" : "the declarations:"}`
|
|
24963
25297
|
);
|
|
24964
25298
|
items(
|
|
24965
25299
|
entries.map((item) => {
|
|
@@ -24986,7 +25320,11 @@ Nothing changed against ${changes.base}.`;
|
|
|
24986
25320
|
);
|
|
24987
25321
|
} else
|
|
24988
25322
|
lines.push(
|
|
24989
|
-
|
|
25323
|
+
runs ? ` none: the given tests reach all ${runs} changed declarations` : impact.changed.length ? " none: outside the tests the diff changes types alone (or comments and layout)" : " none: the diff changes no declarations outside the tests"
|
|
25324
|
+
);
|
|
25325
|
+
if (typeOnly)
|
|
25326
|
+
lines.push(
|
|
25327
|
+
` ${typeOnly} changed declarations change types alone (or comments and layout) and are not judged: none of the code they run changed, and the type checker checks the types`
|
|
24990
25328
|
);
|
|
24991
25329
|
if (throughRoutes.length) {
|
|
24992
25330
|
lines.push(
|
|
@@ -25434,8 +25772,10 @@ async function mapChangeImpact(store, views, working, base, changes, links, shap
|
|
|
25434
25772
|
`the text search for the environment variables and configuration keys the diff removed did not finish (${changes.stranded.failed}), so the files still using them are not listed`
|
|
25435
25773
|
);
|
|
25436
25774
|
const unmapped = [];
|
|
25437
|
-
let changedCount = 0;
|
|
25438
25775
|
const starts = [];
|
|
25776
|
+
const traced = [];
|
|
25777
|
+
let typeOnly = 0;
|
|
25778
|
+
let untraced = 0;
|
|
25439
25779
|
const importers = /* @__PURE__ */ new Map();
|
|
25440
25780
|
let mapped;
|
|
25441
25781
|
const mappedPaths = () => mapped ??= store.database.prepare("SELECT DISTINCT path FROM project_map_objects WHERE version_ref = ?").all(working).map((row) => String(row.path));
|
|
@@ -25465,21 +25805,26 @@ async function mapChangeImpact(store, views, working, base, changes, links, shap
|
|
|
25465
25805
|
unmapped.push({ path: file2.path, kind });
|
|
25466
25806
|
}
|
|
25467
25807
|
if (!objects2.length) continue;
|
|
25468
|
-
const { refs: hits
|
|
25808
|
+
const { refs: hits } = changedUnits(graph, file2.path, file2.lines);
|
|
25809
|
+
const lines = file2.runtime ?? file2.lines;
|
|
25810
|
+
const { refs: running, topLevel } = changedUnits(graph, file2.path, lines);
|
|
25469
25811
|
for (const ref of hits) {
|
|
25470
|
-
|
|
25471
|
-
|
|
25472
|
-
|
|
25812
|
+
const types = !running.has(ref) || mapTypeOnly(graph, ref);
|
|
25813
|
+
if (!types && starts.length >= LIMITS.changed) {
|
|
25814
|
+
untraced++;
|
|
25815
|
+
continue;
|
|
25816
|
+
}
|
|
25817
|
+
const label = `${file2.path}${template ? " (template)" : `: ${graph.qualifiedName(ref)} ${mapDeclarationLabel(graph.object(ref))}`}${file2.status === "ADDED" ? " (new file)" : ""}`;
|
|
25818
|
+
changed.push(label);
|
|
25819
|
+
if (types) typeOnly++;
|
|
25820
|
+
else {
|
|
25821
|
+
traced.push(label);
|
|
25822
|
+
starts.push(tracer.startsAt(ref, lines));
|
|
25473
25823
|
}
|
|
25474
|
-
const object2 = graph.object(ref);
|
|
25475
|
-
changed.push(
|
|
25476
|
-
`${file2.path}${template ? " (template)" : `: ${graph.qualifiedName(ref)} ${mapDeclarationLabel(object2)}`}${file2.status === "ADDED" ? " (new file)" : ""}`
|
|
25477
|
-
);
|
|
25478
|
-
starts.push(tracer.startsAt(ref, file2.lines));
|
|
25479
25824
|
}
|
|
25480
25825
|
for (const relation of graph.relationsFrom(objects2.map((object2) => object2.id))) {
|
|
25481
25826
|
const route = mapRegisteredRoute(relation);
|
|
25482
|
-
if (route && overlaps(
|
|
25827
|
+
if (route && overlaps(lines, relation.anchor.startLine, relation.anchor.endLine)) {
|
|
25483
25828
|
const site = `${relation.anchor.path}:${relation.anchor.startLine}`;
|
|
25484
25829
|
unclear.push({
|
|
25485
25830
|
text: `the registration of ${JSON.stringify(route)} at ${site} changed; check that the route still reaches the right handler`,
|
|
@@ -25555,7 +25900,7 @@ async function mapChangeImpact(store, views, working, base, changes, links, shap
|
|
|
25555
25900
|
", "
|
|
25556
25901
|
)}${unread.length > LIST.names ? ", \u2026" : ""}); project_find_references lists their uses`
|
|
25557
25902
|
});
|
|
25558
|
-
const untested = tests && await untestedChanges(graph, tracer, memberCalls, starts,
|
|
25903
|
+
const untested = tests && await untestedChanges(graph, tracer, memberCalls, starts, traced, tests, typeOnly);
|
|
25559
25904
|
supportTests(store, working, tracer);
|
|
25560
25905
|
const taken = base ? await mapRemovedImpact({
|
|
25561
25906
|
store,
|
|
@@ -25594,6 +25939,9 @@ async function mapChangeImpact(store, views, working, base, changes, links, shap
|
|
|
25594
25939
|
],
|
|
25595
25940
|
incomplete: [
|
|
25596
25941
|
...incomplete,
|
|
25942
|
+
...untraced ? [
|
|
25943
|
+
`the diff changes more than ${LIMITS.changed} declarations that run; the ${untraced} after the first ${LIMITS.changed} were not followed, so what only they reach is not listed`
|
|
25944
|
+
] : [],
|
|
25597
25945
|
...tracer.truncated ? [
|
|
25598
25946
|
`the trace stopped at ${LIMITS.depth} levels or ${LIMITS.declarations} declarations; continue with project_explore_map from the last ones`
|
|
25599
25947
|
] : []
|
|
@@ -25603,11 +25951,11 @@ async function mapChangeImpact(store, views, working, base, changes, links, shap
|
|
|
25603
25951
|
uncalled: taken?.uncalled ?? [],
|
|
25604
25952
|
dependencies: newModuleDependencies(store, views, working, changes.files, links.files),
|
|
25605
25953
|
...untested ? { untested } : {},
|
|
25606
|
-
truncated: tracer.truncated
|
|
25954
|
+
truncated: tracer.truncated || untraced > 0
|
|
25607
25955
|
};
|
|
25608
25956
|
}
|
|
25609
25957
|
var entryOrder = (left, right) => Number(right.certain) - Number(left.certain) || Number(right.route) - Number(left.route) || (left.label < right.label ? -1 : left.label > right.label ? 1 : 0);
|
|
25610
|
-
async function untestedChanges(graph, tracer, memberCalls, starts, changed, tests) {
|
|
25958
|
+
async function untestedChanges(graph, tracer, memberCalls, starts, changed, tests, typeOnly) {
|
|
25611
25959
|
const given = new Set(tests);
|
|
25612
25960
|
const handlers = (requests, files) => {
|
|
25613
25961
|
const into = /* @__PURE__ */ new Map();
|
|
@@ -25659,6 +26007,7 @@ async function untestedChanges(graph, tracer, memberCalls, starts, changed, test
|
|
|
25659
26007
|
const others = new Set([...tracer.tests.keys()].filter((file2) => !given.has(file2)));
|
|
25660
26008
|
return {
|
|
25661
26009
|
changed: unreached.map((at) => changed[at] ?? ""),
|
|
26010
|
+
typeOnly,
|
|
25662
26011
|
runByOthers: runBy(others, requested),
|
|
25663
26012
|
mayRun: runBy(given, tracer.mayRequest),
|
|
25664
26013
|
entries: [...above.entries.values()].sort(entryOrder),
|
|
@@ -25758,7 +26107,7 @@ async function checkMapChanges(input, signal) {
|
|
|
25758
26107
|
working,
|
|
25759
26108
|
base,
|
|
25760
26109
|
changes.files,
|
|
25761
|
-
(file2) =>
|
|
26110
|
+
(file2) => readFile4(path14.join(project, file2), "utf8").catch(() => void 0)
|
|
25762
26111
|
)
|
|
25763
26112
|
),
|
|
25764
26113
|
changes.files.length ? await compileBreaks(input, views, changes, base, until, signal, phase, baseVersion) : void 0
|
|
@@ -25863,7 +26212,7 @@ async function compileBreaks(input, views, changes, base, until, signal, phase,
|
|
|
25863
26212
|
}
|
|
25864
26213
|
|
|
25865
26214
|
// src/layermap.ts
|
|
25866
|
-
var SCHEMA_VERSION =
|
|
26215
|
+
var SCHEMA_VERSION = 4;
|
|
25867
26216
|
var KEEP_VERSIONS = 3;
|
|
25868
26217
|
var KEEP_COMMIT_VERSIONS = 2;
|
|
25869
26218
|
var HOLD_EXPIRY_MS = 10 * 60 * 1e3;
|
|
@@ -25913,9 +26262,11 @@ function openMapDatabase(file2) {
|
|
|
25913
26262
|
CODE_INDEX_SCHEMA,
|
|
25914
26263
|
CODE_INDEX_UNITS_MIGRATION,
|
|
25915
26264
|
CODE_INDEX_CONTEXT_RESULTS_MIGRATION,
|
|
25916
|
-
CODE_INDEX_SHARED_NAVIGATION_MIGRATION
|
|
26265
|
+
CODE_INDEX_SHARED_NAVIGATION_MIGRATION,
|
|
26266
|
+
CODE_INDEX_COMPILE_RESULTS_MIGRATION
|
|
25917
26267
|
])
|
|
25918
26268
|
database.exec(sql);
|
|
26269
|
+
else if (current < 4) database.exec(CODE_INDEX_COMPILE_RESULTS_MIGRATION);
|
|
25919
26270
|
if (current < 3) database.exec(LAYERMAP_TABLES);
|
|
25920
26271
|
if (database.prepare("PRAGMA foreign_key_check").get())
|
|
25921
26272
|
throw new ProjectEvidenceError("PROJECT_EVIDENCE_STORE_CORRUPT", false);
|
|
@@ -26277,7 +26628,7 @@ var packageRoot = (() => {
|
|
|
26277
26628
|
directory = path16.dirname(directory);
|
|
26278
26629
|
}
|
|
26279
26630
|
})();
|
|
26280
|
-
var packageVersion = async () => JSON.parse(await
|
|
26631
|
+
var packageVersion = async () => JSON.parse(await readFile5(path16.join(packageRoot, "package.json"), "utf8")).version;
|
|
26281
26632
|
var cacheDirectory = (env = process.env) => {
|
|
26282
26633
|
if (env.LAYERMAP_CACHE) return path16.resolve(env.LAYERMAP_CACHE);
|
|
26283
26634
|
if (process.platform === "darwin") return path16.join(homedir(), "Library", "Caches", "layermap");
|
|
@@ -26337,11 +26688,11 @@ var absoluteIn = (directory, value) => Object.fromEntries(
|
|
|
26337
26688
|
var readAnalyzers = async (directory) => {
|
|
26338
26689
|
const file2 = path16.join(directory, "analyzers.json");
|
|
26339
26690
|
if (!existsSync6(file2)) return void 0;
|
|
26340
|
-
const analyzers = absoluteIn(directory, JSON.parse(await
|
|
26691
|
+
const analyzers = absoluteIn(directory, JSON.parse(await readFile5(file2, "utf8")));
|
|
26341
26692
|
return analyzers.java.runtimePath ? analyzers : { ...analyzers, java: { ...analyzers.java, ...discoverJavaRuntime() } };
|
|
26342
26693
|
};
|
|
26343
26694
|
var sourceDigest = async () => {
|
|
26344
|
-
const hash2 = createHash6("sha256").update(await
|
|
26695
|
+
const hash2 = createHash6("sha256").update(await readFile5(path16.join(packageRoot, "package.json")));
|
|
26345
26696
|
for (const part of ["src", "go-map", "java-map", "scripts"]) {
|
|
26346
26697
|
const directory = path16.join(packageRoot, part);
|
|
26347
26698
|
if (!existsSync6(directory)) continue;
|
|
@@ -26390,7 +26741,7 @@ async function pruneCache(cache, project, now = Date.now(), installed = packageR
|
|
|
26390
26741
|
const directory = path16.join(projects, name);
|
|
26391
26742
|
const marker = path16.join(directory, "last-used");
|
|
26392
26743
|
const last = (await stat2(existsSync6(marker) ? marker : directory).catch(() => void 0))?.mtimeMs;
|
|
26393
|
-
const owner = await
|
|
26744
|
+
const owner = await readFile5(marker, "utf8").catch(() => "");
|
|
26394
26745
|
if (last !== void 0 && now - last > 30 * DAY || owner !== "" && await gone(owner))
|
|
26395
26746
|
await rm(directory, { recursive: true, force: true });
|
|
26396
26747
|
}
|
|
@@ -26431,7 +26782,7 @@ async function pruneVersions(versions, own, now) {
|
|
|
26431
26782
|
}
|
|
26432
26783
|
async function pruneNpxInstalls(npx, installed, now) {
|
|
26433
26784
|
const own = path16.dirname(path16.dirname(installed));
|
|
26434
|
-
const manifest = async (file2) => JSON.parse(await
|
|
26785
|
+
const manifest = async (file2) => JSON.parse(await readFile5(file2, "utf8").catch(() => "{}"));
|
|
26435
26786
|
const parts = (version2) => version2?.split(".").map(Number) ?? [];
|
|
26436
26787
|
const current = parts((await manifest(path16.join(installed, "package.json"))).version);
|
|
26437
26788
|
const older = (version2) => {
|
|
@@ -26977,7 +27328,7 @@ ${text}` : text
|
|
|
26977
27328
|
// src/agent/setup.ts
|
|
26978
27329
|
import { execFile } from "node:child_process";
|
|
26979
27330
|
import { existsSync as existsSync8 } from "node:fs";
|
|
26980
|
-
import { mkdir as mkdir3, readFile as
|
|
27331
|
+
import { mkdir as mkdir3, readFile as readFile6, rename as rename3, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
26981
27332
|
import { homedir as homedir2 } from "node:os";
|
|
26982
27333
|
import path18 from "node:path";
|
|
26983
27334
|
var SERVER = "layermap";
|
|
@@ -27018,7 +27369,7 @@ var run = (command, args, env) => new Promise((resolve) => {
|
|
|
27018
27369
|
);
|
|
27019
27370
|
});
|
|
27020
27371
|
async function allowInClaudeSettings(file2, rule = SETUP_RULE) {
|
|
27021
|
-
const settings = existsSync8(file2) ? JSON.parse(await
|
|
27372
|
+
const settings = existsSync8(file2) ? JSON.parse(await readFile6(file2, "utf8")) : {};
|
|
27022
27373
|
if (typeof settings !== "object" || settings === null || Array.isArray(settings))
|
|
27023
27374
|
throw new Error(`${file2} is not a settings object.`);
|
|
27024
27375
|
settings.permissions ??= {};
|
|
@@ -27034,7 +27385,7 @@ async function allowInClaudeSettings(file2, rule = SETUP_RULE) {
|
|
|
27034
27385
|
}
|
|
27035
27386
|
var CODEX_TOOL_TIMEOUT_SEC = 300;
|
|
27036
27387
|
async function configureCodexServer(file2) {
|
|
27037
|
-
const lines = (await
|
|
27388
|
+
const lines = (await readFile6(file2, "utf8")).split("\n");
|
|
27038
27389
|
const header2 = lines.findIndex((line) => line.trim() === `[mcp_servers.${SERVER}]`);
|
|
27039
27390
|
if (header2 < 0) throw new Error(`${file2} has no [mcp_servers.${SERVER}] table.`);
|
|
27040
27391
|
let end = header2 + 1;
|
|
@@ -27057,7 +27408,7 @@ async function writeInstructionNote(file2, note = AGENT_MAP_NOTE) {
|
|
|
27057
27408
|
const block = `${BEGIN}
|
|
27058
27409
|
${note}
|
|
27059
27410
|
${END}`;
|
|
27060
|
-
const text = existsSync8(file2) ? await
|
|
27411
|
+
const text = existsSync8(file2) ? await readFile6(file2, "utf8") : "";
|
|
27061
27412
|
const start = text.indexOf(BEGIN);
|
|
27062
27413
|
const end = text.indexOf(END);
|
|
27063
27414
|
const next = start >= 0 && end > start ? `${text.slice(0, start)}${block}${text.slice(end + END.length)}` : `${text}${text && !text.endsWith("\n") ? "\n" : ""}${text ? "\n" : ""}${block}
|
|
@@ -27068,7 +27419,7 @@ ${END}`;
|
|
|
27068
27419
|
}
|
|
27069
27420
|
async function removeInstructionNote(file2) {
|
|
27070
27421
|
if (!existsSync8(file2)) return;
|
|
27071
|
-
const text = await
|
|
27422
|
+
const text = await readFile6(file2, "utf8");
|
|
27072
27423
|
const start = text.indexOf(BEGIN);
|
|
27073
27424
|
const end = text.indexOf(END);
|
|
27074
27425
|
if (start < 0 || end < start) return;
|
|
@@ -27079,7 +27430,7 @@ async function removeInstructionNote(file2) {
|
|
|
27079
27430
|
}
|
|
27080
27431
|
async function disallowInClaudeSettings(file2) {
|
|
27081
27432
|
if (!existsSync8(file2)) return;
|
|
27082
|
-
const settings = JSON.parse(await
|
|
27433
|
+
const settings = JSON.parse(await readFile6(file2, "utf8"));
|
|
27083
27434
|
const allow = settings?.permissions?.allow;
|
|
27084
27435
|
const ours = (rule) => rule === SETUP_RULE || rule === PLUGIN_RULE;
|
|
27085
27436
|
if (!Array.isArray(allow) || !allow.some(ours)) return;
|
|
@@ -27114,7 +27465,7 @@ var dshPatchBlock = (command, env) => {
|
|
|
27114
27465
|
].join("\n");
|
|
27115
27466
|
};
|
|
27116
27467
|
async function writeDshPatch(file2, block) {
|
|
27117
|
-
const text = existsSync8(file2) ? await
|
|
27468
|
+
const text = existsSync8(file2) ? await readFile6(file2, "utf8") : "";
|
|
27118
27469
|
const start = text.indexOf(YAML_BEGIN);
|
|
27119
27470
|
const end = text.indexOf(YAML_END);
|
|
27120
27471
|
let next;
|
|
@@ -27135,7 +27486,7 @@ async function writeDshPatch(file2, block) {
|
|
|
27135
27486
|
}
|
|
27136
27487
|
async function removeDshPatch(file2) {
|
|
27137
27488
|
if (!existsSync8(file2)) return;
|
|
27138
|
-
const text = await
|
|
27489
|
+
const text = await readFile6(file2, "utf8");
|
|
27139
27490
|
const start = text.indexOf(YAML_BEGIN);
|
|
27140
27491
|
const end = text.indexOf(YAML_END);
|
|
27141
27492
|
if (start < 0 || end < start) return;
|
|
@@ -27195,7 +27546,7 @@ async function setupAgent(options) {
|
|
|
27195
27546
|
await mkdir3(path18.dirname(file2), { recursive: true, mode: 448 });
|
|
27196
27547
|
await writeFile2(
|
|
27197
27548
|
`${file2}.${process.pid}`,
|
|
27198
|
-
launcherScript(await
|
|
27549
|
+
launcherScript(await readFile6(PUBLISHED_LAUNCHER, "utf8"), options.version)
|
|
27199
27550
|
);
|
|
27200
27551
|
await rename3(`${file2}.${process.pid}`, file2);
|
|
27201
27552
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "layermap",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.53",
|
|
4
4
|
"mcpName": "io.github.coffeecoproject/layermap",
|
|
5
5
|
"description": "A layered map of a codebase for coding agents: directories, modules and call chains across TypeScript, JavaScript, Go, Python and Java.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@photostructure/sqlite": "3.3.0",
|
|
29
|
-
"typescript": "7.0.2"
|
|
29
|
+
"typescript": "7.0.2",
|
|
30
|
+
"esbuild": "0.28.1"
|
|
30
31
|
},
|
|
31
32
|
"homepage": "https://github.com/coffeecoproject/layermap",
|
|
32
33
|
"repository": {
|
package/pi/layermap.mjs
CHANGED
|
@@ -293,7 +293,7 @@ function layermap(pi) {
|
|
|
293
293
|
if (server && !server.dead) return server;
|
|
294
294
|
starting ??= (async () => {
|
|
295
295
|
const next = new MapServer(cwd);
|
|
296
|
-
const tools = await next.start("0.1.
|
|
296
|
+
const tools = await next.start("0.1.53");
|
|
297
297
|
for (const tool of tools) {
|
|
298
298
|
if (registered.has(tool.name)) continue;
|
|
299
299
|
registered.add(tool.name);
|