squeze-cli 2.2.1 → 3.0.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/CHANGELOG.md +24 -0
- package/README.md +81 -21
- package/dist/cli.cjs +185 -62
- package/dist/extension.cjs +825 -113
- package/docs/ARCHITECTURE.md +1 -1
- package/docs/GRAPH.md +1 -1
- package/docs/SCALE_EVALUATION.md +19 -1
- package/docs/STANDARD.md +27 -0
- package/media/explorer.css +317 -0
- package/media/explorer.js +869 -0
- package/package.json +23 -2
package/dist/extension.cjs
CHANGED
|
@@ -738,11 +738,11 @@ var require_ignore = __commonJS({
|
|
|
738
738
|
const rules = this._rules;
|
|
739
739
|
const { length } = rules;
|
|
740
740
|
const shortcut = this._basenameCount * 2 >= length;
|
|
741
|
-
const
|
|
741
|
+
const basename2 = shortcut ? basenameOf(path) : path;
|
|
742
742
|
for (let index = length - 1; index >= 0; index--) {
|
|
743
743
|
const rule = rules[index];
|
|
744
744
|
if (rule[mode].test(
|
|
745
|
-
shortcut && rule._basenameOnly ?
|
|
745
|
+
shortcut && rule._basenameOnly ? basename2 : path
|
|
746
746
|
)) {
|
|
747
747
|
const { negative } = rule;
|
|
748
748
|
const ret = {
|
|
@@ -2422,6 +2422,7 @@ __export(extension_exports, {
|
|
|
2422
2422
|
module.exports = __toCommonJS(extension_exports);
|
|
2423
2423
|
init_import_meta();
|
|
2424
2424
|
var vscode = __toESM(require("vscode"), 1);
|
|
2425
|
+
var import_node_path8 = require("node:path");
|
|
2425
2426
|
|
|
2426
2427
|
// src/engine.ts
|
|
2427
2428
|
init_import_meta();
|
|
@@ -3267,9 +3268,9 @@ function scanAdoc(src) {
|
|
|
3267
3268
|
let block;
|
|
3268
3269
|
for (let n = 1; n <= src.count; n++) {
|
|
3269
3270
|
const line = src.lines[n - 1];
|
|
3270
|
-
const
|
|
3271
|
+
const trimmed2 = line.length > 200 ? "" : line.trim();
|
|
3271
3272
|
if (block) {
|
|
3272
|
-
if (
|
|
3273
|
+
if (trimmed2 === block.delimiter) {
|
|
3273
3274
|
if (n - block.start + 1 >= MIN_BLOCK_LINES) {
|
|
3274
3275
|
const table = block.delimiter[0] === "|";
|
|
3275
3276
|
const label = tidy(src.line(src.firstContent(block.start + 1, n - 1)), 60);
|
|
@@ -3279,9 +3280,9 @@ function scanAdoc(src) {
|
|
|
3279
3280
|
}
|
|
3280
3281
|
continue;
|
|
3281
3282
|
}
|
|
3282
|
-
if (ADOC_DELIMITER.test(
|
|
3283
|
+
if (ADOC_DELIMITER.test(trimmed2)) {
|
|
3283
3284
|
tree.intro(n);
|
|
3284
|
-
block = { delimiter:
|
|
3285
|
+
block = { delimiter: trimmed2, start: n };
|
|
3285
3286
|
continue;
|
|
3286
3287
|
}
|
|
3287
3288
|
const m = /^(={1,6})[ \t]+(\S.*)$/.exec(line.length > LINE_HEAD ? line.slice(0, LINE_HEAD) : line);
|
|
@@ -7286,7 +7287,7 @@ var import_node_url3 = require("node:url");
|
|
|
7286
7287
|
var import_node_zlib = require("node:zlib");
|
|
7287
7288
|
var PARSER_VERSION = 1;
|
|
7288
7289
|
var TEXT_PIPELINE_VERSION = 2;
|
|
7289
|
-
var CACHE_FORMAT_VERSION =
|
|
7290
|
+
var CACHE_FORMAT_VERSION = 2;
|
|
7290
7291
|
var MAX_CACHE_FILE_BYTES = 1024 * 1024 * 1024;
|
|
7291
7292
|
var MAX_TEMP_AGE_MS = 60 * 60 * 1e3;
|
|
7292
7293
|
var LITTLE_ENDIAN = new Uint8Array(new Uint32Array([1]).buffer)[0] === 1;
|
|
@@ -7674,6 +7675,9 @@ var StringTable = class _StringTable {
|
|
|
7674
7675
|
return table;
|
|
7675
7676
|
}
|
|
7676
7677
|
};
|
|
7678
|
+
function holdsStamp(columns, file, stamp) {
|
|
7679
|
+
return columns.sizes[file] === stamp.size && columns.mtimes[file] === stamp.mtimeMs && columns.ctimes[file] === stamp.ctimeMs && columns.inodes[file] === stamp.ino;
|
|
7680
|
+
}
|
|
7677
7681
|
var FileTable = class _FileTable {
|
|
7678
7682
|
constructor(dictionary, strings) {
|
|
7679
7683
|
this.dictionary = dictionary;
|
|
@@ -7683,6 +7687,8 @@ var FileTable = class _FileTable {
|
|
|
7683
7687
|
hashes = new Uint8Array(0);
|
|
7684
7688
|
sizes = new Float64Array(0);
|
|
7685
7689
|
mtimes = new Float64Array(0);
|
|
7690
|
+
ctimes = new Float64Array(0);
|
|
7691
|
+
inodes = new Float64Array(0);
|
|
7686
7692
|
languages = new Uint32Array(0);
|
|
7687
7693
|
lines = new Uint32Array(0);
|
|
7688
7694
|
flags = new Uint8Array(0);
|
|
@@ -7748,6 +7754,8 @@ var FileTable = class _FileTable {
|
|
|
7748
7754
|
table.hashes = new Uint8Array(files * 32);
|
|
7749
7755
|
table.sizes = new Float64Array(files);
|
|
7750
7756
|
table.mtimes = new Float64Array(files);
|
|
7757
|
+
table.ctimes = new Float64Array(files);
|
|
7758
|
+
table.inodes = new Float64Array(files);
|
|
7751
7759
|
table.languages = new Uint32Array(files);
|
|
7752
7760
|
table.lines = new Uint32Array(files);
|
|
7753
7761
|
table.flags = new Uint8Array(files);
|
|
@@ -7773,6 +7781,8 @@ var FileTable = class _FileTable {
|
|
|
7773
7781
|
table.hashes.set(block.hash, file * 32);
|
|
7774
7782
|
table.sizes[file] = block.size;
|
|
7775
7783
|
table.mtimes[file] = block.mtimeMs;
|
|
7784
|
+
table.ctimes[file] = block.ctimeMs;
|
|
7785
|
+
table.inodes[file] = block.ino;
|
|
7776
7786
|
table.languages[file] = block.language;
|
|
7777
7787
|
table.lines[file] = block.lines;
|
|
7778
7788
|
table.flags[file] = block.flags;
|
|
@@ -7907,6 +7917,8 @@ var FileTable = class _FileTable {
|
|
|
7907
7917
|
["fHash", this.hashes],
|
|
7908
7918
|
["fSize", this.sizes],
|
|
7909
7919
|
["fMtime", this.mtimes],
|
|
7920
|
+
["fCtime", this.ctimes],
|
|
7921
|
+
["fIno", this.inodes],
|
|
7910
7922
|
["fLang", this.languages],
|
|
7911
7923
|
["fLines", this.lines],
|
|
7912
7924
|
["fFlags", this.flags],
|
|
@@ -7980,6 +7992,8 @@ function blockFromTable(table, file, dictionary, strings) {
|
|
|
7980
7992
|
hash: table.hashes.subarray(file * 32, file * 32 + 32),
|
|
7981
7993
|
size: table.sizes[file],
|
|
7982
7994
|
mtimeMs: table.mtimes[file],
|
|
7995
|
+
ctimeMs: table.ctimes[file],
|
|
7996
|
+
ino: table.inodes[file],
|
|
7983
7997
|
language: table.languages[file],
|
|
7984
7998
|
lines: table.lines[file],
|
|
7985
7999
|
flags: table.flags[file],
|
|
@@ -8019,6 +8033,8 @@ function blockFromResult(meta, result, dictionary, strings) {
|
|
|
8019
8033
|
hash: new Uint8Array(hash2),
|
|
8020
8034
|
size: meta.size,
|
|
8021
8035
|
mtimeMs: meta.mtimeMs,
|
|
8036
|
+
ctimeMs: meta.ctimeMs,
|
|
8037
|
+
ino: meta.ino,
|
|
8022
8038
|
language: strings.add(result.language),
|
|
8023
8039
|
lines: result.lines,
|
|
8024
8040
|
flags: result.parsed ? 1 : 0,
|
|
@@ -8068,6 +8084,8 @@ function readTable(container, header2) {
|
|
|
8068
8084
|
table.hashes = container.array("fHash", Uint8Array);
|
|
8069
8085
|
table.sizes = container.array("fSize", Float64Array);
|
|
8070
8086
|
table.mtimes = container.array("fMtime", Float64Array);
|
|
8087
|
+
table.ctimes = container.array("fCtime", Float64Array);
|
|
8088
|
+
table.inodes = container.array("fIno", Float64Array);
|
|
8071
8089
|
table.languages = container.array("fLang", Uint32Array);
|
|
8072
8090
|
table.lines = container.array("fLines", Uint32Array);
|
|
8073
8091
|
table.flags = container.array("fFlags", Uint8Array);
|
|
@@ -8089,6 +8107,7 @@ function readTable(container, header2) {
|
|
|
8089
8107
|
table.refStart = container.array("refS", Uint32Array);
|
|
8090
8108
|
table.refIds = container.array("refI", Uint32Array);
|
|
8091
8109
|
expect(table.hashes.length === files * 32 && table.sizes.length === files && table.mtimes.length === files && table.languages.length === files, "file column length");
|
|
8110
|
+
expect(table.ctimes.length === files && table.inodes.length === files, "file stamp length");
|
|
8092
8111
|
expect(table.lines.length === files && table.flags.length === files && table.tokenCounts.length === files, "file column length");
|
|
8093
8112
|
expect(table.chunkFirst.length === files + 1 && table.pathTermStart.length === files + 1 && table.pathTerms.length === pathTerms, "file offsets length");
|
|
8094
8113
|
for (const column of [table.starts, table.ends, table.idStrings, table.nameStrings, table.kindStrings, table.chunkLen]) expect(column.length === chunks, "chunk column length");
|
|
@@ -8114,6 +8133,7 @@ function readTable(container, header2) {
|
|
|
8114
8133
|
for (let i2 = 0; i2 < entries; i2++) if (table.rowTf[i2] === 0) throw new CacheCorruptError("zero term frequency");
|
|
8115
8134
|
for (let file = 0; file < files; file++) {
|
|
8116
8135
|
expect(table.flags[file] <= 1 && Number.isFinite(table.sizes[file]) && table.sizes[file] >= 0 && Number.isFinite(table.mtimes[file]) && Number.isFinite(table.tokenCounts[file]), "file fields");
|
|
8136
|
+
expect(Number.isFinite(table.ctimes[file]) && Number.isFinite(table.inodes[file]), "file stamp fields");
|
|
8117
8137
|
for (let c = table.chunkFirst[file]; c < table.chunkFirst[file + 1]; c++) expect(table.starts[c] >= 1 && table.starts[c] <= table.ends[c] && table.ends[c] <= table.lines[file], "chunk range");
|
|
8118
8138
|
}
|
|
8119
8139
|
const records = (name2) => {
|
|
@@ -8383,7 +8403,7 @@ var import_node_crypto3 = require("node:crypto");
|
|
|
8383
8403
|
var SKETCH_MAGIC = "RSQSKTCH";
|
|
8384
8404
|
var MAX_TERM_HASHES = 8192;
|
|
8385
8405
|
var collator = new Intl.Collator();
|
|
8386
|
-
function makeSketch(path, text,
|
|
8406
|
+
function makeSketch(path, text, stamp, digest, tokenCount = -1) {
|
|
8387
8407
|
const pathTerms = new Set(terms(path));
|
|
8388
8408
|
const unique2 = /* @__PURE__ */ new Set();
|
|
8389
8409
|
for (const term of pathTerms) unique2.add(termHash(term));
|
|
@@ -8394,7 +8414,7 @@ function makeSketch(path, text, size, mtimeMs, digest, tokenCount = -1) {
|
|
|
8394
8414
|
let lines = 1;
|
|
8395
8415
|
for (let at = text.indexOf("\n"); at !== -1; at = text.indexOf("\n", at + 1)) lines++;
|
|
8396
8416
|
const pathHashes = Uint32Array.from(new Set([...pathTerms].map(termHash))).sort();
|
|
8397
|
-
return { path, size, mtimeMs, digest, language: languageFor(path), lines, tokenCount, termHashes, pathHashes };
|
|
8417
|
+
return { path, size: stamp.size, mtimeMs: stamp.mtimeMs, ctimeMs: stamp.ctimeMs, ino: stamp.ino, digest, language: languageFor(path), lines, tokenCount, termHashes, pathHashes };
|
|
8398
8418
|
}
|
|
8399
8419
|
function contains(sorted, from, to, value) {
|
|
8400
8420
|
let low = from, high = to - 1;
|
|
@@ -8410,6 +8430,8 @@ var SketchTable = class _SketchTable {
|
|
|
8410
8430
|
paths = [];
|
|
8411
8431
|
sizes = new Float64Array(0);
|
|
8412
8432
|
mtimes = new Float64Array(0);
|
|
8433
|
+
ctimes = new Float64Array(0);
|
|
8434
|
+
inodes = new Float64Array(0);
|
|
8413
8435
|
digests = new Uint8Array(0);
|
|
8414
8436
|
languageIds = new Uint32Array(0);
|
|
8415
8437
|
languageNames = [];
|
|
@@ -8446,6 +8468,8 @@ var SketchTable = class _SketchTable {
|
|
|
8446
8468
|
path: this.paths[file],
|
|
8447
8469
|
size: this.sizes[file],
|
|
8448
8470
|
mtimeMs: this.mtimes[file],
|
|
8471
|
+
ctimeMs: this.ctimes[file],
|
|
8472
|
+
ino: this.inodes[file],
|
|
8449
8473
|
digest: this.digestHex(file),
|
|
8450
8474
|
language: this.languageNames[this.languageIds[file]],
|
|
8451
8475
|
lines: this.lines[file],
|
|
@@ -8460,6 +8484,8 @@ var SketchTable = class _SketchTable {
|
|
|
8460
8484
|
table.paths = sketches.map((sketch) => sketch.path);
|
|
8461
8485
|
table.sizes = Float64Array.from(sketches, (sketch) => sketch.size);
|
|
8462
8486
|
table.mtimes = Float64Array.from(sketches, (sketch) => sketch.mtimeMs);
|
|
8487
|
+
table.ctimes = Float64Array.from(sketches, (sketch) => sketch.ctimeMs);
|
|
8488
|
+
table.inodes = Float64Array.from(sketches, (sketch) => sketch.ino);
|
|
8463
8489
|
table.digests = new Uint8Array(count * 32);
|
|
8464
8490
|
table.languageIds = new Uint32Array(count);
|
|
8465
8491
|
table.lines = Uint32Array.from(sketches, (sketch) => sketch.lines);
|
|
@@ -8493,6 +8519,8 @@ var SketchTable = class _SketchTable {
|
|
|
8493
8519
|
["paths", Buffer.from(this.paths.join("\n"), "utf8")],
|
|
8494
8520
|
["sSize", this.sizes],
|
|
8495
8521
|
["sMtime", this.mtimes],
|
|
8522
|
+
["sCtime", this.ctimes],
|
|
8523
|
+
["sIno", this.inodes],
|
|
8496
8524
|
["sDigest", this.digests],
|
|
8497
8525
|
["sLang", this.languageIds],
|
|
8498
8526
|
["sLines", this.lines],
|
|
@@ -8523,6 +8551,8 @@ var SketchTable = class _SketchTable {
|
|
|
8523
8551
|
table.paths = files ? text.split("\n") : [];
|
|
8524
8552
|
table.sizes = container.array("sSize", Float64Array);
|
|
8525
8553
|
table.mtimes = container.array("sMtime", Float64Array);
|
|
8554
|
+
table.ctimes = container.array("sCtime", Float64Array);
|
|
8555
|
+
table.inodes = container.array("sIno", Float64Array);
|
|
8526
8556
|
table.digests = container.array("sDigest", Uint8Array);
|
|
8527
8557
|
table.languageIds = container.array("sLang", Uint32Array);
|
|
8528
8558
|
table.lines = container.array("sLines", Uint32Array);
|
|
@@ -8533,6 +8563,7 @@ var SketchTable = class _SketchTable {
|
|
|
8533
8563
|
table.pathHashes = container.array("pHashes", Uint32Array);
|
|
8534
8564
|
table.pathOrder = container.array("order", Uint32Array);
|
|
8535
8565
|
expect(table.paths.length === files && table.sizes.length === files && table.mtimes.length === files && table.digests.length === files * 32, "column length");
|
|
8566
|
+
expect(table.ctimes.length === files && table.inodes.length === files, "column length");
|
|
8536
8567
|
expect(table.languageIds.length === files && table.lines.length === files && table.tokenCounts.length === files && table.pathOrder.length === files, "column length");
|
|
8537
8568
|
expect(table.hashStart.length === files + 1 && table.pathHashStart.length === files + 1, "offset length");
|
|
8538
8569
|
for (const [offsets, total] of [[table.hashStart, table.hashes.length], [table.pathHashStart, table.pathHashes.length]]) {
|
|
@@ -8542,6 +8573,7 @@ var SketchTable = class _SketchTable {
|
|
|
8542
8573
|
const seen = new Uint8Array(files);
|
|
8543
8574
|
for (let i2 = 0; i2 < files; i2++) {
|
|
8544
8575
|
expect(table.languageIds[i2] < table.languageNames.length && Number.isFinite(table.sizes[i2]) && Number.isFinite(table.mtimes[i2]) && Number.isFinite(table.tokenCounts[i2]), "file fields");
|
|
8576
|
+
expect(Number.isFinite(table.ctimes[i2]) && Number.isFinite(table.inodes[i2]), "file stamp fields");
|
|
8545
8577
|
expect(table.pathOrder[i2] < files && seen[table.pathOrder[i2]] === 0, "bad path order");
|
|
8546
8578
|
seen[table.pathOrder[i2]] = 1;
|
|
8547
8579
|
}
|
|
@@ -9345,9 +9377,17 @@ var SKETCH_FILE = "sketch-v1.bin";
|
|
|
9345
9377
|
var STATS_FILE = "stats-v1.json";
|
|
9346
9378
|
var VERIFY_FILE_LIMIT = 5e3;
|
|
9347
9379
|
var VERIFY_MAX_BYTES = 256 * 1024 * 1024;
|
|
9380
|
+
var RACY_WINDOW_MS = 2e3;
|
|
9348
9381
|
var MAX_PARSED_FILES = 6e3;
|
|
9349
9382
|
var NOT_EXPANDABLE = "Path is excluded, absent, outside repository, or beyond scan limits";
|
|
9350
9383
|
var NO_FOLLOW2 = import_node_fs4.constants.O_NOFOLLOW ?? 0;
|
|
9384
|
+
function candidateMeta(path, stat2, scanStart) {
|
|
9385
|
+
const racy = Math.max(stat2.mtimeMs, stat2.ctimeMs) >= scanStart - RACY_WINDOW_MS;
|
|
9386
|
+
return { path, size: stat2.size, mtimeMs: Math.trunc(stat2.mtimeMs), ctimeMs: stat2.ctimeMs, ino: stat2.ino, racy };
|
|
9387
|
+
}
|
|
9388
|
+
function recordedStamp(meta) {
|
|
9389
|
+
return { size: meta.size, mtimeMs: meta.mtimeMs, ctimeMs: meta.racy ? -1 : meta.ctimeMs, ino: meta.ino };
|
|
9390
|
+
}
|
|
9351
9391
|
var SourceChangedError = class extends Error {
|
|
9352
9392
|
};
|
|
9353
9393
|
var sha256 = (bytes) => (0, import_node_crypto4.createHash)("sha256").update(bytes).digest("hex");
|
|
@@ -9369,6 +9409,7 @@ var IgnoreRules = class {
|
|
|
9369
9409
|
custom = (0, import_ignore.default)();
|
|
9370
9410
|
hasCustom = false;
|
|
9371
9411
|
cache = /* @__PURE__ */ new Map();
|
|
9412
|
+
dirVerdicts = /* @__PURE__ */ new Map();
|
|
9372
9413
|
async load() {
|
|
9373
9414
|
try {
|
|
9374
9415
|
const text = await (0, import_promises2.readFile)((0, import_node_path4.resolve)(this.root, ".reposqueeze-v2ignore"), "utf8");
|
|
@@ -9389,16 +9430,37 @@ var IgnoreRules = class {
|
|
|
9389
9430
|
}
|
|
9390
9431
|
return rules;
|
|
9391
9432
|
}
|
|
9392
|
-
|
|
9393
|
-
|
|
9394
|
-
const parts2 = path.
|
|
9395
|
-
for (let depth =
|
|
9433
|
+
/** Git's precedence: the deepest .gitignore with a matching pattern decides, and a negation there can re-include. */
|
|
9434
|
+
async verdict(path, directory) {
|
|
9435
|
+
const parts2 = path.split("/");
|
|
9436
|
+
for (let depth = parts2.length - 1; depth >= 0; depth--) {
|
|
9396
9437
|
const dir = parts2.slice(0, depth).join("/");
|
|
9397
9438
|
const rules = await this.rulesIn(dir);
|
|
9398
|
-
if (rules
|
|
9439
|
+
if (!rules) continue;
|
|
9440
|
+
const result = rules.test((dir ? path.slice(dir.length + 1) : path) + (directory ? "/" : ""));
|
|
9441
|
+
if (result.ignored || result.unignored) return result.ignored;
|
|
9399
9442
|
}
|
|
9400
9443
|
return false;
|
|
9401
9444
|
}
|
|
9445
|
+
excludedDirectory(dir) {
|
|
9446
|
+
let verdict = this.dirVerdicts.get(dir);
|
|
9447
|
+
if (!verdict) {
|
|
9448
|
+
verdict = this.verdict(dir, true);
|
|
9449
|
+
this.dirVerdicts.set(dir, verdict);
|
|
9450
|
+
}
|
|
9451
|
+
return verdict;
|
|
9452
|
+
}
|
|
9453
|
+
/** Git never re-includes a file beneath an excluded directory, so ancestors are decided before the path itself. */
|
|
9454
|
+
async ignores(path) {
|
|
9455
|
+
if (this.hasCustom && this.custom.ignores(path)) return true;
|
|
9456
|
+
const directory = path.endsWith("/");
|
|
9457
|
+
const trimmed2 = directory ? path.slice(0, -1) : path;
|
|
9458
|
+
const parts2 = trimmed2.split("/");
|
|
9459
|
+
for (let depth = 1; depth < parts2.length; depth++) {
|
|
9460
|
+
if (await this.excludedDirectory(parts2.slice(0, depth).join("/"))) return true;
|
|
9461
|
+
}
|
|
9462
|
+
return this.verdict(trimmed2, directory);
|
|
9463
|
+
}
|
|
9402
9464
|
};
|
|
9403
9465
|
var Repository = class {
|
|
9404
9466
|
root;
|
|
@@ -9536,10 +9598,11 @@ var Repository = class {
|
|
|
9536
9598
|
} catch (error) {
|
|
9537
9599
|
if (error instanceof Error && error.message === NOT_EXPANDABLE) throw error;
|
|
9538
9600
|
}
|
|
9601
|
+
const scanStart = Date.now();
|
|
9539
9602
|
try {
|
|
9540
9603
|
const stats = await (0, import_promises2.lstat)((0, import_node_path4.resolve)(root, path));
|
|
9541
9604
|
if (!stats.isFile() || stats.isSymbolicLink() || stats.size > MAX_FILE_BYTES) throw new Error(NOT_EXPANDABLE);
|
|
9542
|
-
return
|
|
9605
|
+
return candidateMeta(path, stats, scanStart);
|
|
9543
9606
|
} catch {
|
|
9544
9607
|
throw new Error(NOT_EXPANDABLE);
|
|
9545
9608
|
}
|
|
@@ -9594,12 +9657,13 @@ var Repository = class {
|
|
|
9594
9657
|
async eligibleFiles(root, scan) {
|
|
9595
9658
|
let skipped = 0, totalBytes = 0, truncated = scan.truncated;
|
|
9596
9659
|
const metadata2 = [];
|
|
9660
|
+
const scanStart = Date.now();
|
|
9597
9661
|
const stats = await mapLimit(scan.paths, STAT_CONCURRENCY, async (path) => {
|
|
9598
9662
|
if (!allowedPath(path) || !scan.rules.trivial && await scan.rules.ignores(path)) return null;
|
|
9599
9663
|
try {
|
|
9600
9664
|
const stat2 = await (0, import_promises2.lstat)((0, import_node_path4.resolve)(root, path));
|
|
9601
9665
|
if (!stat2.isFile() || stat2.isSymbolicLink() || stat2.size > MAX_FILE_BYTES) return null;
|
|
9602
|
-
return
|
|
9666
|
+
return candidateMeta(path, stat2, scanStart);
|
|
9603
9667
|
} catch {
|
|
9604
9668
|
return null;
|
|
9605
9669
|
}
|
|
@@ -9653,7 +9717,7 @@ var Repository = class {
|
|
|
9653
9717
|
this.lap(state, "assemble+save");
|
|
9654
9718
|
const truncated = eligible.truncated;
|
|
9655
9719
|
if (truncated) warnings.push("Repository exceeds safety limits (100,000 files / 2 GiB indexed text / 2 MiB per file / depth 60); index is incomplete.");
|
|
9656
|
-
if (!verify) warnings.push("Index reuse trusts file size
|
|
9720
|
+
if (!verify) warnings.push("Index reuse trusts file size, modification time, change time and inode above 5,000 files or 256 MiB; REPOSQUEEZE_REFRESH_INDEX=1 forces a full re-read.");
|
|
9657
9721
|
const fallback = this.fallbackCount(table);
|
|
9658
9722
|
if (fallback) warnings.push(`${fallback} source files have parse errors or unavailable grammars; line-window search remains active.`);
|
|
9659
9723
|
const { files, chunks, rows } = table.materialize(state.text);
|
|
@@ -9703,7 +9767,7 @@ var Repository = class {
|
|
|
9703
9767
|
let reused = 0, refreshed = 0;
|
|
9704
9768
|
const built = await mapLimit(metadata2, READ_CONCURRENCY, async (meta) => {
|
|
9705
9769
|
const known = previous.fileOf(meta.path);
|
|
9706
|
-
if (!force && known >= 0 &&
|
|
9770
|
+
if (!force && known >= 0 && !meta.racy && holdsStamp(previous, known, meta) && !(exact && previous.tokenCounts[known] < 0)) {
|
|
9707
9771
|
reused++;
|
|
9708
9772
|
return known;
|
|
9709
9773
|
}
|
|
@@ -9711,7 +9775,7 @@ var Repository = class {
|
|
|
9711
9775
|
const bytes = await this.readBytes(state.root, meta, directories);
|
|
9712
9776
|
const text = await this.readText(state.root, meta, bytes);
|
|
9713
9777
|
refreshed++;
|
|
9714
|
-
return makeSketch(meta.path, text, meta
|
|
9778
|
+
return makeSketch(meta.path, text, recordedStamp(meta), sha256(bytes), exact ? fileTokens(meta.path, text) : -1);
|
|
9715
9779
|
} catch {
|
|
9716
9780
|
skipped++;
|
|
9717
9781
|
return null;
|
|
@@ -9748,7 +9812,7 @@ var Repository = class {
|
|
|
9748
9812
|
const { files, chunks, rows } = table.materialize(state.text);
|
|
9749
9813
|
this.lap(state, "materialize");
|
|
9750
9814
|
warnings.push(`Large-repository cascade: ${files.length.toLocaleString()} candidates parsed from ${sketches.count.toLocaleString()} eligible files.`);
|
|
9751
|
-
warnings.push("File sketches contain hashes, counts and term fingerprints only; returned evidence is re-read verbatim from current source.
|
|
9815
|
+
warnings.push("File sketches contain hashes, counts and term fingerprints only; returned evidence is re-read verbatim from current source. Files are trusted by size, modification time, change time and inode; REPOSQUEEZE_REFRESH_INDEX=1 forces a full re-read.");
|
|
9752
9816
|
if (!scan.git) warnings.push("Use a Git working tree for the strongest change detection and ignore behavior at this scale.");
|
|
9753
9817
|
if (eligible.truncated) warnings.push("Repository exceeds safety limits (100,000 files / 2 GiB indexed text / 2 MiB per file / depth 60); index is incomplete.");
|
|
9754
9818
|
const fallback = this.fallbackCount(table);
|
|
@@ -9794,7 +9858,7 @@ var Repository = class {
|
|
|
9794
9858
|
results = await mapLimit(metas, READ_CONCURRENCY, async (meta) => {
|
|
9795
9859
|
const known = old.fileOf(meta.path);
|
|
9796
9860
|
const needsCount = exact && known >= 0 && old.tokenCounts[known] < 0;
|
|
9797
|
-
if (known >= 0 && !force && !verify && !needsCount &&
|
|
9861
|
+
if (known >= 0 && !force && !verify && !needsCount && !meta.racy && holdsStamp(old, known, meta)) {
|
|
9798
9862
|
reused++;
|
|
9799
9863
|
return { source: old, file: known };
|
|
9800
9864
|
}
|
|
@@ -9807,9 +9871,12 @@ var Repository = class {
|
|
|
9807
9871
|
}
|
|
9808
9872
|
const digest = sha256(bytes);
|
|
9809
9873
|
if (known >= 0 && !force && old.hashHex(known) === digest) {
|
|
9810
|
-
|
|
9811
|
-
|
|
9812
|
-
old.
|
|
9874
|
+
const stamp = recordedStamp(meta);
|
|
9875
|
+
if (!holdsStamp(old, known, stamp)) {
|
|
9876
|
+
old.sizes[known] = stamp.size;
|
|
9877
|
+
old.mtimes[known] = stamp.mtimeMs;
|
|
9878
|
+
old.ctimes[known] = stamp.ctimeMs;
|
|
9879
|
+
old.inodes[known] = stamp.ino;
|
|
9813
9880
|
touched = true;
|
|
9814
9881
|
}
|
|
9815
9882
|
if (needsCount) {
|
|
@@ -9837,7 +9904,7 @@ var Repository = class {
|
|
|
9837
9904
|
return null;
|
|
9838
9905
|
}
|
|
9839
9906
|
parsed++;
|
|
9840
|
-
return { meta: { path: meta.path, hash: digest,
|
|
9907
|
+
return { meta: { path: meta.path, hash: digest, ...recordedStamp(meta), tokenCount: exact ? fileTokens(meta.path, text) : -1 }, result };
|
|
9841
9908
|
});
|
|
9842
9909
|
} finally {
|
|
9843
9910
|
await indexer.close();
|
|
@@ -9914,7 +9981,7 @@ var Repository = class {
|
|
|
9914
9981
|
const directories = /* @__PURE__ */ new Map();
|
|
9915
9982
|
const texts = await mapLimit(sample, 16, async (file) => {
|
|
9916
9983
|
try {
|
|
9917
|
-
const meta = { path: file.path
|
|
9984
|
+
const meta = { path: file.path };
|
|
9918
9985
|
return { path: file.path, text: await this.readText(state.root, meta, await this.readBytes(state.root, meta, directories)) };
|
|
9919
9986
|
} catch {
|
|
9920
9987
|
return null;
|
|
@@ -10157,8 +10224,8 @@ var collapse2 = (line) => line.trim().replace(/\s+/g, " ").slice(0, 160);
|
|
|
10157
10224
|
function declarationIndex(chunk, lines) {
|
|
10158
10225
|
if (PROSE_FILE.test(chunk.path)) return Math.max(0, lines.findIndex((line) => line.trim()));
|
|
10159
10226
|
const index = lines.findIndex((line) => {
|
|
10160
|
-
const
|
|
10161
|
-
return
|
|
10227
|
+
const trimmed2 = line.trim();
|
|
10228
|
+
return trimmed2 && !NON_DECLARATION.test(trimmed2);
|
|
10162
10229
|
});
|
|
10163
10230
|
return index >= 0 ? index : Math.max(0, lines.findIndex((line) => line.trim()));
|
|
10164
10231
|
}
|
|
@@ -10448,8 +10515,8 @@ function chooseRendering(candidate, bounds, taken, input, windows, compact, room
|
|
|
10448
10515
|
const narrowest = WINDOW_WIDTHS[WINDOW_WIDTHS.length - 1];
|
|
10449
10516
|
const wholeChunk = lo === chunk.start && hi === chunk.end;
|
|
10450
10517
|
const whole = candidate.segmentsText([bounds]);
|
|
10451
|
-
const
|
|
10452
|
-
if (room(
|
|
10518
|
+
const wholeTokens2 = tokens(whole) + overhead;
|
|
10519
|
+
if (room(wholeTokens2) && (!windows || wholeTokens2 <= maxFull || total <= narrowest)) {
|
|
10453
10520
|
return { segments: [bounds], body: whole, complete: wholeChunk };
|
|
10454
10521
|
}
|
|
10455
10522
|
const scores = candidate.lineScores.slice(lo - chunk.start, hi - chunk.start + 1);
|
|
@@ -11597,7 +11664,7 @@ var BRACKET_LEVEL_PREFIX = /^\[(?:ERROR|WARNING|WARN|INFO|DEBUG|FATAL|TRACE|erro
|
|
|
11597
11664
|
var ACTIONS_PREFIX = /^##\[(?:error|warning|notice|group|debug)\][ \t]*/;
|
|
11598
11665
|
function stripLinePrefix(input) {
|
|
11599
11666
|
let s = input;
|
|
11600
|
-
for (let
|
|
11667
|
+
for (let round2 = 0; round2 < 4; round2++) {
|
|
11601
11668
|
const before = s;
|
|
11602
11669
|
const c = s.charCodeAt(0);
|
|
11603
11670
|
if (c === 62 || c === 124) s = s.slice(1).trimStart();
|
|
@@ -12671,8 +12738,8 @@ function analyze(text) {
|
|
|
12671
12738
|
};
|
|
12672
12739
|
for (let li = 0; li < lines.length; li++) {
|
|
12673
12740
|
const raw = lines[li];
|
|
12674
|
-
const
|
|
12675
|
-
if (!
|
|
12741
|
+
const trimmed2 = raw.trim();
|
|
12742
|
+
if (!trimmed2) {
|
|
12676
12743
|
kinds[li] = K_BLANK;
|
|
12677
12744
|
sink.prevWasE = false;
|
|
12678
12745
|
sink.cargoList = false;
|
|
@@ -12681,19 +12748,19 @@ function analyze(text) {
|
|
|
12681
12748
|
finishNumbered(sink);
|
|
12682
12749
|
continue;
|
|
12683
12750
|
}
|
|
12684
|
-
if (
|
|
12751
|
+
if (trimmed2.startsWith("```") || trimmed2.startsWith("~~~")) {
|
|
12685
12752
|
inFence = !inFence;
|
|
12686
12753
|
kinds[li] = K_FENCE;
|
|
12687
12754
|
continue;
|
|
12688
12755
|
}
|
|
12689
12756
|
fenced[li] = inFence ? 1 : 0;
|
|
12690
|
-
if (
|
|
12757
|
+
if (trimmed2.length < 3) {
|
|
12691
12758
|
st.prevRaw = raw;
|
|
12692
12759
|
continue;
|
|
12693
12760
|
}
|
|
12694
|
-
const t = stripLinePrefix(
|
|
12761
|
+
const t = stripLinePrefix(trimmed2);
|
|
12695
12762
|
if (!t) continue;
|
|
12696
|
-
const indent = raw.length - raw.trimStart().length + (
|
|
12763
|
+
const indent = raw.length - raw.trimStart().length + (trimmed2.length - t.length);
|
|
12697
12764
|
const isPyFile = t.charCodeAt(0) === 70 && t.startsWith("File ");
|
|
12698
12765
|
if (pyIndent >= 0 && !isPyFile && indent < pyIndent) {
|
|
12699
12766
|
pyIndent = -1;
|
|
@@ -12755,7 +12822,7 @@ function analyze(text) {
|
|
|
12755
12822
|
if (isPyFile) pyIndent = indent;
|
|
12756
12823
|
if (match !== void 0) sink.prevWasE = false;
|
|
12757
12824
|
if (match) {
|
|
12758
|
-
const frame = { path: match.path, language: match.language, raw:
|
|
12825
|
+
const frame = { path: match.path, language: match.language, raw: trimmed2.slice(0, RAW_CHARS), index: 0 };
|
|
12759
12826
|
if (match.line !== void 0) frame.line = match.line;
|
|
12760
12827
|
if (match.column !== void 0) frame.column = match.column;
|
|
12761
12828
|
if (match.func) frame.func = match.func;
|
|
@@ -13369,7 +13436,7 @@ function cleanProseLine(raw, fenced) {
|
|
|
13369
13436
|
if (!s) return "";
|
|
13370
13437
|
if (!fenced) {
|
|
13371
13438
|
if (/^[-*+]\s*\[[ xX]\]\s*(?:I\b|I'|My\b|This\b|Please\b|The\b)/.test(s)) return "";
|
|
13372
|
-
for (let
|
|
13439
|
+
for (let round2 = 0; round2 < 3; round2++) {
|
|
13373
13440
|
const before = s;
|
|
13374
13441
|
s = s.replace(/^>+\s*/, "").replace(/^[-*+]\s+(?:\[[ xX]\]\s*)?/, "").replace(/^\d{1,3}[.)]\s+(?=\S)/, "");
|
|
13375
13442
|
if (s === before) break;
|
|
@@ -13412,7 +13479,7 @@ function displayPath(frame) {
|
|
|
13412
13479
|
if (marker) {
|
|
13413
13480
|
path = path.slice(marker.index + marker[0].length).replace(/^([^/]+?)@v?\d[^/]*\//, "$1/").replace(/^([^/]+?)-\d+(?:\.\d+)+[^/]*\//, "$1/");
|
|
13414
13481
|
} else {
|
|
13415
|
-
for (let
|
|
13482
|
+
for (let round2 = 0; round2 < 2; round2++) {
|
|
13416
13483
|
for (const prefix of ROOT_PREFIXES) {
|
|
13417
13484
|
const m = prefix.exec(path);
|
|
13418
13485
|
if (m) {
|
|
@@ -13967,8 +14034,8 @@ function rankV2(snapshot, query, settings = DEFAULTS, semanticScores, features =
|
|
|
13967
14034
|
let score = base2 + 0.16 * (fileFused.get(chunk.path) ?? 0) + 4e-3 * stability + 7e-4 * covered.length;
|
|
13968
14035
|
if (trace && testLike(chunk.path) && !testsWanted) score *= 0.48;
|
|
13969
14036
|
if (trace && !testLike(chunk.path)) {
|
|
13970
|
-
const
|
|
13971
|
-
if ([...stems].some((stem2) =>
|
|
14037
|
+
const basename2 = chunk.path.split("/").pop().replace(/\.[^.]+$/, "").toLowerCase();
|
|
14038
|
+
if ([...stems].some((stem2) => basename2.includes(stem2) || stem2.includes(basename2))) score *= 1.35;
|
|
13972
14039
|
}
|
|
13973
14040
|
if (features.has("priors")) score *= filePrior(chunk.path, query);
|
|
13974
14041
|
rows.push({ chunk, score, stability, obligations: covered });
|
|
@@ -14414,11 +14481,11 @@ var LogParser = class {
|
|
|
14414
14481
|
entry(path) {
|
|
14415
14482
|
const commit = this.commit;
|
|
14416
14483
|
if (!commit || path === null) return;
|
|
14417
|
-
const
|
|
14418
|
-
if (
|
|
14484
|
+
const relative3 = relativeTo(this.prefix, path);
|
|
14485
|
+
if (relative3 === null) return;
|
|
14419
14486
|
commit.total++;
|
|
14420
14487
|
if (commit.paths.length < this.history.maxFiles) {
|
|
14421
|
-
commit.paths.push(
|
|
14488
|
+
commit.paths.push(relative3);
|
|
14422
14489
|
commit.deleted.push(this.status[0] === "D");
|
|
14423
14490
|
}
|
|
14424
14491
|
}
|
|
@@ -14522,13 +14589,13 @@ var StatusParser = class {
|
|
|
14522
14589
|
}
|
|
14523
14590
|
add(path) {
|
|
14524
14591
|
if (path.endsWith("/")) return true;
|
|
14525
|
-
const
|
|
14526
|
-
if (
|
|
14592
|
+
const relative3 = relativeTo(this.prefix, path);
|
|
14593
|
+
if (relative3 === null) return true;
|
|
14527
14594
|
if (this.dirty.size >= this.maxPaths) {
|
|
14528
14595
|
this.overflowed = true;
|
|
14529
14596
|
return false;
|
|
14530
14597
|
}
|
|
14531
|
-
this.dirty.add(
|
|
14598
|
+
this.dirty.add(relative3);
|
|
14532
14599
|
return true;
|
|
14533
14600
|
}
|
|
14534
14601
|
};
|
|
@@ -14843,6 +14910,7 @@ async function collectSignals(root, options) {
|
|
|
14843
14910
|
// src/engine.ts
|
|
14844
14911
|
var MAX_QUERY_CHARS2 = 8e3;
|
|
14845
14912
|
var HARD_QUERY_LIMIT = 1e6;
|
|
14913
|
+
var MAX_PACK_ATTEMPTS = 3;
|
|
14846
14914
|
var Engine = class extends Repository {
|
|
14847
14915
|
features;
|
|
14848
14916
|
semantic;
|
|
@@ -14860,6 +14928,17 @@ var Engine = class extends Repository {
|
|
|
14860
14928
|
if (raw.length > HARD_QUERY_LIMIT) throw new Error("query is longer than 1,000,000 characters");
|
|
14861
14929
|
if (raw.length > MAX_QUERY_CHARS2 && !this.features.has("condense")) throw new Error("query must contain 1\u20138000 characters");
|
|
14862
14930
|
const text = raw.length > MAX_QUERY_CHARS2 ? condenseQuery(raw, 6e3) : raw;
|
|
14931
|
+
for (let attempt = 1; ; attempt++) {
|
|
14932
|
+
try {
|
|
14933
|
+
const pack = await this.buildPack(text, budget, known);
|
|
14934
|
+
pack.stats.elapsedMs = performance.now() - started;
|
|
14935
|
+
return pack;
|
|
14936
|
+
} catch (error) {
|
|
14937
|
+
if (!(error instanceof SourceChangedError) || attempt >= MAX_PACK_ATTEMPTS) throw error;
|
|
14938
|
+
}
|
|
14939
|
+
}
|
|
14940
|
+
}
|
|
14941
|
+
async buildPack(text, budget, known) {
|
|
14863
14942
|
const snapshot = await this.snapshot(text);
|
|
14864
14943
|
let semanticScores;
|
|
14865
14944
|
if (this.semantic) {
|
|
@@ -14867,9 +14946,7 @@ var Engine = class extends Repository {
|
|
|
14867
14946
|
semanticScores = await this.semantic.scores(snapshot, text, candidates);
|
|
14868
14947
|
}
|
|
14869
14948
|
const git = this.features.has("git") ? await loadGitSignals(this.root) : void 0;
|
|
14870
|
-
|
|
14871
|
-
pack.stats.elapsedMs = performance.now() - started;
|
|
14872
|
-
return pack;
|
|
14949
|
+
return contextPackV2(snapshot, text, budget, known, void 0, semanticScores, this.features, git);
|
|
14873
14950
|
}
|
|
14874
14951
|
async expandRange(path, start2, end, budget = 3e3) {
|
|
14875
14952
|
return this.expand(path, start2, end, budget);
|
|
@@ -15818,13 +15895,16 @@ function levels(csr, source, depth) {
|
|
|
15818
15895
|
|
|
15819
15896
|
// src/graph.ts
|
|
15820
15897
|
var GRAPH_FORMAT = "reposqueeze-graph";
|
|
15821
|
-
var GRAPH_VERSION =
|
|
15898
|
+
var GRAPH_VERSION = 3;
|
|
15822
15899
|
var NODE_KINDS = ["file", "def", "external"];
|
|
15823
|
-
var EDGE_KINDS = ["imports", "defines", "references", "contains"];
|
|
15900
|
+
var EDGE_KINDS = ["imports", "defines", "references", "contains", "calls"];
|
|
15824
15901
|
var CONFIDENCES = ["EXTRACTED", "INFERRED"];
|
|
15825
15902
|
var IMPORT_WEIGHT = 3;
|
|
15826
15903
|
var MAX_REFERENCE_TARGETS = 24;
|
|
15827
15904
|
var MIN_REFERENCE_WEIGHT = 0.04;
|
|
15905
|
+
var CALL_SITE = /\b([A-Za-z_$][\w$]*)\s*\(/g;
|
|
15906
|
+
var NOT_CALLS = /* @__PURE__ */ new Set(["if", "for", "while", "switch", "catch", "return", "function", "def", "func", "fn", "elif", "with", "sizeof", "typeof", "super", "this", "new", "await", "yield", "assert", "print", "len", "range", "make", "append", "cap", "delete", "panic", "require", "import", "export", "and", "or", "not", "in", "is", "lambda", "pass", "raise"]);
|
|
15907
|
+
var MAX_CALL_TARGETS = 8;
|
|
15828
15908
|
var MAX_DEFINERS = 40;
|
|
15829
15909
|
var FREE_DEFINERS = 3;
|
|
15830
15910
|
var COMMON_NAME_FILES = 8;
|
|
@@ -15942,7 +16022,7 @@ function buildGraph(snapshot, options = {}) {
|
|
|
15942
16022
|
});
|
|
15943
16023
|
const importTargets = files.map(() => /* @__PURE__ */ new Map());
|
|
15944
16024
|
const externalUsers = /* @__PURE__ */ new Map();
|
|
15945
|
-
const stats = { files: files.length, definitions: definitionCount, externals: 0, importEdges: 0, referenceEdges: 0, importStatements: 0, importsResolved: 0, importsExternal: 0, importsUnresolved: 0, externalsOmitted: 0, languages };
|
|
16025
|
+
const stats = { files: files.length, definitions: definitionCount, externals: 0, importEdges: 0, referenceEdges: 0, callEdges: 0, importStatements: 0, importsResolved: 0, importsExternal: 0, importsUnresolved: 0, externalsOmitted: 0, languages };
|
|
15946
16026
|
const textOnly = /* @__PURE__ */ new Set();
|
|
15947
16027
|
files.forEach((info3, f) => {
|
|
15948
16028
|
const source = info3.source;
|
|
@@ -15974,7 +16054,7 @@ function buildGraph(snapshot, options = {}) {
|
|
|
15974
16054
|
refs ??= referenced();
|
|
15975
16055
|
const members = info3.language === "go" ? qualifiedMembers(source.text, ref.spec.split("/").pop()) : void 0;
|
|
15976
16056
|
const mentioned = targets.filter((path) => topLevelNames(fileId.get(path)).some((name2) => (members ?? refs).has(name2)));
|
|
15977
|
-
targets =
|
|
16057
|
+
targets = mentioned.slice(0, MAX_PACKAGE_FILES);
|
|
15978
16058
|
confidence = "INFERRED";
|
|
15979
16059
|
}
|
|
15980
16060
|
for (const path of targets) {
|
|
@@ -16077,6 +16157,29 @@ function addReferenceEdges(files, importTargets, columns, stats) {
|
|
|
16077
16157
|
const defChunks = new Set(info3.defs.map((def) => def.chunk));
|
|
16078
16158
|
for (const root of analysis.roots) if (!defChunks.has(root)) sources.push({ node: g, refs: root.refs, exclude: allDefRefs });
|
|
16079
16159
|
const imported = importTargets[g];
|
|
16160
|
+
info3.defs.forEach((def, index) => {
|
|
16161
|
+
const node = info3.nodeOf.get(index);
|
|
16162
|
+
if (node === void 0 || !def.chunk.text) return;
|
|
16163
|
+
const seen = /* @__PURE__ */ new Set();
|
|
16164
|
+
const targets = /* @__PURE__ */ new Map();
|
|
16165
|
+
for (const match of def.chunk.text.matchAll(CALL_SITE)) {
|
|
16166
|
+
const name2 = match[1];
|
|
16167
|
+
if (seen.has(name2) || name2 === def.chunk.name || NOT_CALLS.has(name2)) continue;
|
|
16168
|
+
seen.add(name2);
|
|
16169
|
+
const list = definers.get(name2);
|
|
16170
|
+
if (!list || list.length > MAX_DEFINERS) continue;
|
|
16171
|
+
const local = list.filter((definer) => definer.file === g && definer.node !== node);
|
|
16172
|
+
const backed = list.filter((definer) => definer.file !== g && imported.has(definer.file));
|
|
16173
|
+
const unique2 = !local.length && !backed.length && list.length === 1 && list[0].node !== node && isDistinctive(name2) ? list : [];
|
|
16174
|
+
const pick = local.length ? local : backed.length ? backed : unique2;
|
|
16175
|
+
for (const definer of pick.slice(0, 3)) targets.set(definer.node, { weight: 1 / pick.length, exact: pick.length === 1 });
|
|
16176
|
+
if (targets.size >= MAX_CALL_TARGETS) break;
|
|
16177
|
+
}
|
|
16178
|
+
for (const [target, { weight, exact }] of [...targets].slice(0, MAX_CALL_TARGETS)) {
|
|
16179
|
+
columns.edge(node, target, "calls", Math.round(weight * 1e3) / 1e3, exact ? "EXTRACTED" : "INFERRED");
|
|
16180
|
+
stats.callEdges++;
|
|
16181
|
+
}
|
|
16182
|
+
});
|
|
16080
16183
|
for (const { node, refs, exclude } of sources) {
|
|
16081
16184
|
const scored = /* @__PURE__ */ new Map();
|
|
16082
16185
|
for (const name2 of refs) {
|
|
@@ -16377,7 +16480,7 @@ var CodeGraph = class {
|
|
|
16377
16480
|
}
|
|
16378
16481
|
};
|
|
16379
16482
|
function mergeSmall(community, csr, minSize) {
|
|
16380
|
-
for (let
|
|
16483
|
+
for (let round2 = 0; round2 < 3; round2++) {
|
|
16381
16484
|
const sizes = /* @__PURE__ */ new Map();
|
|
16382
16485
|
for (const c of community) sizes.set(c, (sizes.get(c) ?? 0) + 1);
|
|
16383
16486
|
let changed = false;
|
|
@@ -16466,12 +16569,21 @@ function dominantDirectory(paths) {
|
|
|
16466
16569
|
// src/graph-html.ts
|
|
16467
16570
|
init_import_meta();
|
|
16468
16571
|
var import_node_crypto6 = require("node:crypto");
|
|
16469
|
-
|
|
16470
|
-
|
|
16471
|
-
|
|
16472
|
-
var
|
|
16473
|
-
var
|
|
16474
|
-
|
|
16572
|
+
|
|
16573
|
+
// src/graph-layout.ts
|
|
16574
|
+
init_import_meta();
|
|
16575
|
+
var LAYOUT_WIDTH = 1200;
|
|
16576
|
+
var LAYOUT_HEIGHT = 800;
|
|
16577
|
+
var communityColor = (id) => `hsl(${Math.round(id * 137.508 % 360)},62%,52%)`;
|
|
16578
|
+
function ringSeeds(communities, width = LAYOUT_WIDTH, height = LAYOUT_HEIGHT) {
|
|
16579
|
+
const seeds = /* @__PURE__ */ new Map();
|
|
16580
|
+
communities.forEach((c, i2) => {
|
|
16581
|
+
const angle = i2 / communities.length * Math.PI * 2;
|
|
16582
|
+
seeds.set(c, { x: width / 2 + 0.33 * width * Math.cos(angle), y: height / 2 + 0.33 * height * Math.sin(angle) });
|
|
16583
|
+
});
|
|
16584
|
+
return seeds;
|
|
16585
|
+
}
|
|
16586
|
+
function layout(count, community, links, seeds, width = LAYOUT_WIDTH, height = LAYOUT_HEIGHT) {
|
|
16475
16587
|
const members = /* @__PURE__ */ new Map();
|
|
16476
16588
|
community.forEach((c, i2) => {
|
|
16477
16589
|
const list = members.get(c);
|
|
@@ -16487,10 +16599,10 @@ function layout(count, community, links, seeds) {
|
|
|
16487
16599
|
points[node] = { x: center.x + radius * Math.cos(angle), y: center.y + radius * Math.sin(angle) };
|
|
16488
16600
|
});
|
|
16489
16601
|
}
|
|
16490
|
-
const area =
|
|
16602
|
+
const area = width * height;
|
|
16491
16603
|
const spring = Math.sqrt(area / Math.max(1, count)) * 0.9;
|
|
16492
16604
|
const iterations = count > 800 ? 40 : count > 300 ? 80 : 150;
|
|
16493
|
-
let temperature =
|
|
16605
|
+
let temperature = width / 10;
|
|
16494
16606
|
const dx = new Float64Array(count);
|
|
16495
16607
|
const dy = new Float64Array(count);
|
|
16496
16608
|
for (let step = 0; step < iterations; step++) {
|
|
@@ -16536,6 +16648,12 @@ function layout(count, community, links, seeds) {
|
|
|
16536
16648
|
}
|
|
16537
16649
|
return points;
|
|
16538
16650
|
}
|
|
16651
|
+
|
|
16652
|
+
// src/graph-html.ts
|
|
16653
|
+
var WIDTH = 1200;
|
|
16654
|
+
var HEIGHT = 800;
|
|
16655
|
+
var MAX_EDGES = 4e3;
|
|
16656
|
+
var escapeHtml = (text) => text.replace(/[&<>"']/g, (ch) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[ch]);
|
|
16539
16657
|
var SCRIPT = `(function(){var svg=document.getElementById('g');var nodes=svg.querySelectorAll('circle');var lines=svg.querySelectorAll('line');
|
|
16540
16658
|
function clear(){svg.classList.remove('focus');nodes.forEach(function(n){n.classList.remove('hot')});lines.forEach(function(l){l.classList.remove('hot')});}
|
|
16541
16659
|
svg.addEventListener('click',function(ev){var t=ev.target;if(t.tagName!=='circle'){clear();return;}clear();svg.classList.add('focus');var id=t.getAttribute('data-i');t.classList.add('hot');
|
|
@@ -16551,11 +16669,7 @@ function renderHtml(graph, options = {}) {
|
|
|
16551
16669
|
const index = new Map(shown.map((f, i2) => [f, i2]));
|
|
16552
16670
|
const community = shown.map((f) => graph.community[f]);
|
|
16553
16671
|
const usedCommunities = [...new Set(community)].sort((a, b) => a - b);
|
|
16554
|
-
const seeds =
|
|
16555
|
-
usedCommunities.forEach((c, i2) => {
|
|
16556
|
-
const angle = i2 / usedCommunities.length * Math.PI * 2;
|
|
16557
|
-
seeds.set(c, { x: WIDTH / 2 + 0.33 * WIDTH * Math.cos(angle), y: HEIGHT / 2 + 0.33 * HEIGHT * Math.sin(angle) });
|
|
16558
|
-
});
|
|
16672
|
+
const seeds = ringSeeds(usedCommunities, WIDTH, HEIGHT);
|
|
16559
16673
|
const edges = [];
|
|
16560
16674
|
for (const f of shown) {
|
|
16561
16675
|
for (let e = graph.fileOut.start[f]; e < graph.fileOut.start[f + 1]; e++) {
|
|
@@ -16565,7 +16679,7 @@ function renderHtml(graph, options = {}) {
|
|
|
16565
16679
|
}
|
|
16566
16680
|
edges.sort((x, y) => y.weight - x.weight || x.a - y.a || x.b - y.b);
|
|
16567
16681
|
const kept = edges.slice(0, MAX_EDGES).sort((x, y) => x.a - y.a || x.b - y.b);
|
|
16568
|
-
const points = layout(shown.length, community, kept.map((edge) => [edge.a, edge.b, Math.log2(1 + edge.weight)]), seeds);
|
|
16682
|
+
const points = layout(shown.length, community, kept.map((edge) => [edge.a, edge.b, Math.log2(1 + edge.weight)]), seeds, WIDTH, HEIGHT);
|
|
16569
16683
|
const xs = points.map((p) => p.x);
|
|
16570
16684
|
const ys = points.map((p) => p.y);
|
|
16571
16685
|
const minX = Math.min(...xs, 0) - 20;
|
|
@@ -16573,16 +16687,16 @@ function renderHtml(graph, options = {}) {
|
|
|
16573
16687
|
const width = Math.max(...xs, 1) - minX + 20;
|
|
16574
16688
|
const height = Math.max(...ys, 1) - minY + 20;
|
|
16575
16689
|
const maxRank = Math.max(...shown.map((f) => graph.rank[f]), 1e-12);
|
|
16576
|
-
const
|
|
16690
|
+
const round2 = (v) => v.toFixed(1);
|
|
16577
16691
|
const parts2 = [];
|
|
16578
|
-
for (const edge of kept) parts2.push(`<line class="${edge.imports ? "imp" : "ref"}" data-a="${edge.a}" data-b="${edge.b}" x1="${
|
|
16692
|
+
for (const edge of kept) parts2.push(`<line class="${edge.imports ? "imp" : "ref"}" data-a="${edge.a}" data-b="${edge.b}" x1="${round2(points[edge.a].x)}" y1="${round2(points[edge.a].y)}" x2="${round2(points[edge.b].x)}" y2="${round2(points[edge.b].y)}"/>`);
|
|
16579
16693
|
shown.forEach((f, i2) => {
|
|
16580
16694
|
const radius = 3 + 11 * Math.sqrt(graph.rank[f] / maxRank);
|
|
16581
|
-
parts2.push(`<circle data-i="${i2}" cx="${
|
|
16695
|
+
parts2.push(`<circle data-i="${i2}" cx="${round2(points[i2].x)}" cy="${round2(points[i2].y)}" r="${radius.toFixed(1)}" fill="${communityColor(graph.community[f])}"><title>${escapeHtml(graph.label[f])} \xB7 S${graph.community[f]} \xB7 in ${graph.inDegree[f]} out ${graph.outDegree[f]}</title></circle>`);
|
|
16582
16696
|
});
|
|
16583
|
-
shown.slice(0, 25).forEach((f, i2) => parts2.push(`<text x="${
|
|
16697
|
+
shown.slice(0, 25).forEach((f, i2) => parts2.push(`<text x="${round2(points[i2].x + 6)}" y="${round2(points[i2].y - 6)}">${escapeHtml(graph.label[f].split("/").pop() ?? "")}</text>`));
|
|
16584
16698
|
const legend = usedCommunities.slice(0, 20).map((c) => `<p><span class="sw s${c}"></span>S${c} ${escapeHtml(graph.subsystems[c].name)} (${graph.subsystems[c].files.length})</p>`).join("");
|
|
16585
|
-
const swatchStyle = usedCommunities.slice(0, 20).map((c) => `.s${c}{background:${
|
|
16699
|
+
const swatchStyle = usedCommunities.slice(0, 20).map((c) => `.s${c}{background:${communityColor(c)}}`).join("");
|
|
16586
16700
|
const title = escapeHtml(options.title ?? "Code graph");
|
|
16587
16701
|
const style = STYLE + swatchStyle;
|
|
16588
16702
|
const csp = `default-src 'none'; style-src ${sha(style)}; script-src ${sha(SCRIPT)}; base-uri 'none'; form-action 'none'`;
|
|
@@ -16590,7 +16704,7 @@ function renderHtml(graph, options = {}) {
|
|
|
16590
16704
|
return `<!doctype html>
|
|
16591
16705
|
<html lang="en"><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="${csp}"><title>${title}</title><style>${style}</style></head>
|
|
16592
16706
|
<body><div id="wrap"><div id="side"><h1>${title}</h1><p>${escapeHtml(summary)}</p><p>Click a node to highlight its neighbours; click the background to reset. Solid = import, dashed = name-based reference.</p>${legend}</div>
|
|
16593
|
-
<svg id="g" viewBox="${
|
|
16707
|
+
<svg id="g" viewBox="${round2(minX)} ${round2(minY)} ${round2(width)} ${round2(height)}" preserveAspectRatio="xMidYMid meet">${parts2.join("")}</svg></div>
|
|
16594
16708
|
<script>${SCRIPT}</script></body></html>
|
|
16595
16709
|
`;
|
|
16596
16710
|
}
|
|
@@ -16634,7 +16748,7 @@ function references(graph) {
|
|
|
16634
16748
|
const to = [];
|
|
16635
16749
|
const counts = new Uint32Array(graph.nodeCount);
|
|
16636
16750
|
for (let e = 0; e < graph.edgeFrom.length; e++) {
|
|
16637
|
-
if (graph.edgeKind[e] !== 2) continue;
|
|
16751
|
+
if (graph.edgeKind[e] !== 2 && graph.edgeKind[e] !== 4) continue;
|
|
16638
16752
|
from.push(graph.edgeFrom[e]);
|
|
16639
16753
|
to.push(graph.edgeTo[e]);
|
|
16640
16754
|
counts[graph.edgeTo[e]]++;
|
|
@@ -16732,18 +16846,18 @@ function listFiles(graph, nodes, cap, directory = "") {
|
|
|
16732
16846
|
const sorted = [...nodes].sort(byImportance(graph));
|
|
16733
16847
|
return sorted.slice(0, cap).map((n) => short(graph, n, directory)).join(", ") + more(nodes.length, cap);
|
|
16734
16848
|
}
|
|
16735
|
-
function renderNeighbors(graph, target, depth, budget) {
|
|
16849
|
+
function renderNeighbors(graph, target, depth, budget, style = "full") {
|
|
16736
16850
|
const picked = pickTarget(graph, target);
|
|
16737
16851
|
if ("message" in picked) return clamp(picked.message, budget);
|
|
16738
16852
|
const node = picked.node;
|
|
16739
16853
|
const steps = Math.max(1, Math.min(3, Math.floor(depth) || 1));
|
|
16740
|
-
const render = (cap) => graph.nodeKind(node) === "file" ? fileNeighbors(graph, node, steps, cap) : graph.nodeKind(node) === "def" ? defNeighbors(graph, node, steps, cap) : externalNeighbors(graph, node, cap);
|
|
16854
|
+
const render = (cap) => graph.nodeKind(node) === "file" ? fileNeighbors(graph, node, steps, cap, style) : graph.nodeKind(node) === "def" ? defNeighbors(graph, node, steps, cap) : externalNeighbors(graph, node, cap);
|
|
16741
16855
|
return richest([40, 25, 15, 8, 4, 2, 1], render, budget);
|
|
16742
16856
|
}
|
|
16743
|
-
function fileNeighbors(graph, file, depth, cap) {
|
|
16857
|
+
function fileNeighbors(graph, file, depth, cap, style = "full") {
|
|
16744
16858
|
const sub = graph.subsystems[graph.community[file]];
|
|
16745
16859
|
const rankPosition = graph.filesByRank().indexOf(file) + 1;
|
|
16746
|
-
const lines = [`file ${graph.label[file]} [S${sub.id} ${sub.name}] \xB7 ${graph.detail[file]} \xB7 rank #${rankPosition}/${graph.fileCount}`];
|
|
16860
|
+
const lines = [style === "caveman" ? `${graph.label[file]} [S${sub.id}] #${rankPosition}/${graph.fileCount}` : `file ${graph.label[file]} [S${sub.id} ${sub.name}] \xB7 ${graph.detail[file]} \xB7 rank #${rankPosition}/${graph.fileCount}`];
|
|
16747
16861
|
const split = (csr, wanted) => {
|
|
16748
16862
|
const out2 = [];
|
|
16749
16863
|
for (let e = csr.start[file]; e < csr.start[file + 1]; e++) if (wanted(graph.fileMask[csr.edge[e]])) out2.push(csr.to[e]);
|
|
@@ -16757,7 +16871,7 @@ function fileNeighbors(graph, file, depth, cap) {
|
|
|
16757
16871
|
for (let e = graph.out.start[file]; e < graph.out.start[file + 1]; e++) if (graph.kind[graph.out.to[e]] === 2) externals.push(graph.label[graph.out.to[e]].replace(/^external:/, ""));
|
|
16758
16872
|
if (imports.length) lines.push(`imports (${imports.length}): ${listFiles(graph, imports, cap)}`);
|
|
16759
16873
|
if (externals.length) lines.push(`external (${externals.length}): ${externals.slice(0, cap).join(", ")}${more(externals.length, cap)}`);
|
|
16760
|
-
if (uses.length) lines.push(
|
|
16874
|
+
if (uses.length) lines.push(`${style === "caveman" ? "uses" : "uses without import"} (${uses.length}${style === "caveman" ? ", name" : ", name-based"}): ${listFiles(graph, uses, cap)}`);
|
|
16761
16875
|
if (importedBy.length) lines.push(`imported by (${importedBy.length}): ${listFiles(graph, importedBy, cap)}`);
|
|
16762
16876
|
if (usedBy.length) lines.push(`used by (${usedBy.length}, name-based): ${listFiles(graph, usedBy, cap)}`);
|
|
16763
16877
|
const defs = [];
|
|
@@ -16829,7 +16943,7 @@ function findPath(graph, from, to) {
|
|
|
16829
16943
|
const hops = shortestPath(graph.out, graph.into, from, to, true, isExternal);
|
|
16830
16944
|
return hops ? { hops, directed: false, kind: "full" } : void 0;
|
|
16831
16945
|
}
|
|
16832
|
-
function renderPath(graph, a, b, budget) {
|
|
16946
|
+
function renderPath(graph, a, b, budget, style = "full") {
|
|
16833
16947
|
const first = pickTarget(graph, a, "from");
|
|
16834
16948
|
if ("message" in first) return clamp(first.message, budget);
|
|
16835
16949
|
const second = pickTarget(graph, b, "to");
|
|
@@ -16840,12 +16954,12 @@ function renderPath(graph, a, b, budget) {
|
|
|
16840
16954
|
}
|
|
16841
16955
|
const kindOf = (edge) => found.kind === "imports" ? "imports" : found.kind === "file" ? graph.fileMask[edge] & 1 ? "imports" : "references~" : mark(graph, edge);
|
|
16842
16956
|
const quality = found.hops.every((hop) => kindOf(hop.edge) === "imports") ? "imports only" : "uses name-based references (~)";
|
|
16843
|
-
const lines = [`path ${graph.describe(first.node)} \u2192 ${graph.describe(second.node)}: ${found.hops.length} hops${found.directed ? "" : ", edge direction ignored"} \xB7 ${quality}`, graph.describe(first.node)];
|
|
16957
|
+
const lines = style === "caveman" ? [`${graph.describe(first.node)} \u2192 ${graph.describe(second.node)}: ${found.hops.length} hops${found.directed ? "" : " (undirected)"}, ${found.hops.every((hop) => kindOf(hop.edge) === "imports") ? "imports" : "name-based"}`] : [`path ${graph.describe(first.node)} \u2192 ${graph.describe(second.node)}: ${found.hops.length} hops${found.directed ? "" : ", edge direction ignored"} \xB7 ${quality}`, graph.describe(first.node)];
|
|
16844
16958
|
found.hops.forEach((hop) => lines.push(` ${hopText(graph, hop, kindOf)}`));
|
|
16845
16959
|
if (!found.hops.length) lines.push(" (same node)");
|
|
16846
16960
|
return clamp(lines.join("\n"), budget);
|
|
16847
16961
|
}
|
|
16848
|
-
function renderImpact(graph, target, depth, budget) {
|
|
16962
|
+
function renderImpact(graph, target, depth, budget, style = "full") {
|
|
16849
16963
|
const picked = pickTarget(graph, target);
|
|
16850
16964
|
if ("message" in picked) return clamp(picked.message, budget);
|
|
16851
16965
|
const node = picked.node;
|
|
@@ -16862,11 +16976,11 @@ function renderImpact(graph, target, depth, budget) {
|
|
|
16862
16976
|
const tests = [...files].filter((f) => isTestPath(graph.label[f])).length;
|
|
16863
16977
|
const render = (cap) => {
|
|
16864
16978
|
const via = isFile ? "via imports" : "via references";
|
|
16865
|
-
const lines = [`impact of ${graph.describe(node)}: ${strongSet.size} ${isFile ? "files" : "definitions/files"} ${via} within ${steps} hops (direct ${strong[0]?.length ?? 0})${weak.length ? `, +${weak.length} only via name-based references` : ""} \xB7 ${files.size} files total, ${tests} test files${graph.partial ? " \xB7 partial graph" : ""}`];
|
|
16979
|
+
const lines = style === "caveman" ? [`${graph.describe(node)} \u2190 ${strong[0]?.length ?? 0} direct, ${files.size} total${weak.length ? `, ${weak.length} name-only` : ""}${tests ? `, ${tests} tests` : ""}${graph.partial ? " (partial)" : ""}`] : [`impact of ${graph.describe(node)}: ${strongSet.size} ${isFile ? "files" : "definitions/files"} ${via} within ${steps} hops (direct ${strong[0]?.length ?? 0})${weak.length ? `, +${weak.length} only via name-based references` : ""} \xB7 ${files.size} files total, ${tests} test files${graph.partial ? " \xB7 partial graph" : ""}`];
|
|
16866
16980
|
strong.forEach((level, d) => {
|
|
16867
16981
|
if (level.length) lines.push(`d${d + 1} (${level.length}): ${listFiles(graph, level, cap)}`);
|
|
16868
16982
|
});
|
|
16869
|
-
if (weak.length) lines.push(
|
|
16983
|
+
if (weak.length) lines.push(`${style === "caveman" ? "name-only" : "name-based only"} (${weak.length}): ${listFiles(graph, weak, Math.max(1, Math.floor(cap / 2)))}`);
|
|
16870
16984
|
if (!strongSet.size && !weak.length) lines.push("nothing in the graph depends on it");
|
|
16871
16985
|
return lines.join("\n");
|
|
16872
16986
|
};
|
|
@@ -16986,6 +17100,7 @@ async function loadGraph(repo) {
|
|
|
16986
17100
|
async function runGraph(repo, request = {}) {
|
|
16987
17101
|
const mode = request.mode ?? "overview";
|
|
16988
17102
|
const budget = request.budget === void 0 ? DEFAULT_GRAPH_BUDGET : checkBudget(request.budget);
|
|
17103
|
+
const style = request.style === "caveman" ? "caveman" : "full";
|
|
16989
17104
|
const { graph } = await loadGraph(repo);
|
|
16990
17105
|
const need = (value, name2) => {
|
|
16991
17106
|
if (!value?.trim()) throw new Error(`${name2} is required for mode ${mode}`);
|
|
@@ -16995,11 +17110,11 @@ async function runGraph(repo, request = {}) {
|
|
|
16995
17110
|
case "overview":
|
|
16996
17111
|
return renderOverview(graph, budget);
|
|
16997
17112
|
case "neighbors":
|
|
16998
|
-
return renderNeighbors(graph, need(request.target, "target"), request.depth ?? 1, budget);
|
|
17113
|
+
return renderNeighbors(graph, need(request.target, "target"), request.depth ?? 1, budget, style);
|
|
16999
17114
|
case "path":
|
|
17000
|
-
return renderPath(graph, need(request.target, "target"), need(request.to, "to"), budget);
|
|
17115
|
+
return renderPath(graph, need(request.target, "target"), need(request.to, "to"), budget, style);
|
|
17001
17116
|
case "impact":
|
|
17002
|
-
return renderImpact(graph, need(request.target, "target"), request.depth ?? 3, budget);
|
|
17117
|
+
return renderImpact(graph, need(request.target, "target"), request.depth ?? 3, budget, style);
|
|
17003
17118
|
case "mermaid":
|
|
17004
17119
|
return renderMermaid(graph, request.target?.trim() || void 0, budget);
|
|
17005
17120
|
case "json":
|
|
@@ -17011,20 +17126,589 @@ async function runGraph(repo, request = {}) {
|
|
|
17011
17126
|
}
|
|
17012
17127
|
}
|
|
17013
17128
|
|
|
17129
|
+
// src/explorer-model.ts
|
|
17130
|
+
init_import_meta();
|
|
17131
|
+
var EXPLORER_MODEL_VERSION = 1;
|
|
17132
|
+
var DEFAULT_EXPLORER_NODES = 600;
|
|
17133
|
+
var MAX_EXPLORER_NODES = 2e3;
|
|
17134
|
+
var DEFAULT_EXPLORER_EDGES = 6e3;
|
|
17135
|
+
var MAX_EXPLORER_EDGES = 1e4;
|
|
17136
|
+
var clampInt = (value, min, max, fallback) => {
|
|
17137
|
+
if (value === void 0 || !Number.isFinite(value)) return fallback;
|
|
17138
|
+
return Math.min(max, Math.max(min, Math.floor(value)));
|
|
17139
|
+
};
|
|
17140
|
+
var round = (value, digits) => {
|
|
17141
|
+
const factor = 10 ** digits;
|
|
17142
|
+
return Math.round(value * factor) / factor;
|
|
17143
|
+
};
|
|
17144
|
+
var basename = (path) => path.slice(path.lastIndexOf("/") + 1);
|
|
17145
|
+
function isShownPath(model, path) {
|
|
17146
|
+
return model.nodes.some((node) => node.path === path);
|
|
17147
|
+
}
|
|
17148
|
+
var MAX_OPEN_PATH = 1024;
|
|
17149
|
+
function explorerOpenPath(message) {
|
|
17150
|
+
if (typeof message !== "object" || message === null) return void 0;
|
|
17151
|
+
const { type, path } = message;
|
|
17152
|
+
if (type !== "open" || typeof path !== "string" || path.length === 0 || path.length > MAX_OPEN_PATH) return void 0;
|
|
17153
|
+
return path;
|
|
17154
|
+
}
|
|
17155
|
+
function buildExplorerModel(graph, options = {}) {
|
|
17156
|
+
const maxNodes = clampInt(options.maxNodes, 1, MAX_EXPLORER_NODES, DEFAULT_EXPLORER_NODES);
|
|
17157
|
+
const maxEdges = clampInt(options.maxEdges, 0, MAX_EXPLORER_EDGES, DEFAULT_EXPLORER_EDGES);
|
|
17158
|
+
const shown = graph.filesByRank().slice(0, maxNodes);
|
|
17159
|
+
const index = new Map(shown.map((file, i2) => [file, i2]));
|
|
17160
|
+
const candidates = [];
|
|
17161
|
+
shown.forEach((file, from) => {
|
|
17162
|
+
for (let e = graph.fileOut.start[file]; e < graph.fileOut.start[file + 1]; e++) {
|
|
17163
|
+
const to = index.get(graph.fileOut.to[e]);
|
|
17164
|
+
if (to === void 0) continue;
|
|
17165
|
+
candidates.push({
|
|
17166
|
+
from,
|
|
17167
|
+
to,
|
|
17168
|
+
imports: (graph.fileMask[graph.fileOut.edge[e]] & 1) !== 0,
|
|
17169
|
+
weight: graph.fileOut.weight[e]
|
|
17170
|
+
});
|
|
17171
|
+
}
|
|
17172
|
+
});
|
|
17173
|
+
candidates.sort((x, y) => y.weight - x.weight || x.from - y.from || x.to - y.to);
|
|
17174
|
+
const kept = candidates.slice(0, maxEdges).sort((x, y) => x.from - y.from || x.to - y.to);
|
|
17175
|
+
const community = shown.map((file) => graph.community[file]);
|
|
17176
|
+
const communityIds = [...new Set(community)].sort((a, b) => a - b);
|
|
17177
|
+
const seeds = ringSeeds(communityIds, LAYOUT_WIDTH, LAYOUT_HEIGHT);
|
|
17178
|
+
const points = layout(
|
|
17179
|
+
shown.length,
|
|
17180
|
+
community,
|
|
17181
|
+
kept.map((edge) => [edge.from, edge.to, Math.log2(1 + edge.weight)]),
|
|
17182
|
+
seeds,
|
|
17183
|
+
LAYOUT_WIDTH,
|
|
17184
|
+
LAYOUT_HEIGHT
|
|
17185
|
+
);
|
|
17186
|
+
let maxRank = 1e-12;
|
|
17187
|
+
for (const file of shown) maxRank = Math.max(maxRank, graph.rank[file]);
|
|
17188
|
+
const nodes = shown.map((file, i2) => ({
|
|
17189
|
+
id: i2,
|
|
17190
|
+
path: graph.label[file],
|
|
17191
|
+
name: basename(graph.label[file]),
|
|
17192
|
+
community: community[i2],
|
|
17193
|
+
rank: round(graph.rank[file] / maxRank, 4),
|
|
17194
|
+
inDegree: graph.inDegree[file],
|
|
17195
|
+
outDegree: graph.outDegree[file],
|
|
17196
|
+
x: round(points[i2].x, 1),
|
|
17197
|
+
y: round(points[i2].y, 1)
|
|
17198
|
+
}));
|
|
17199
|
+
const communities = communityIds.map((id) => {
|
|
17200
|
+
const info3 = graph.subsystems[id];
|
|
17201
|
+
return { id, name: info3.name, directory: info3.directory, color: communityColor(id), files: info3.files.length };
|
|
17202
|
+
});
|
|
17203
|
+
const xs = points.map((p) => p.x);
|
|
17204
|
+
const ys = points.map((p) => p.y);
|
|
17205
|
+
const bounds = points.length ? { minX: round(Math.min(...xs), 1), minY: round(Math.min(...ys), 1), maxX: round(Math.max(...xs), 1), maxY: round(Math.max(...ys), 1) } : { minX: 0, minY: 0, maxX: 0, maxY: 0 };
|
|
17206
|
+
return {
|
|
17207
|
+
version: EXPLORER_MODEL_VERSION,
|
|
17208
|
+
title: options.title?.trim().slice(0, 200) || "Squeze Explorer",
|
|
17209
|
+
revision: graph.revision,
|
|
17210
|
+
partial: graph.partial,
|
|
17211
|
+
notes: graph.notes.slice(0, 20),
|
|
17212
|
+
totals: {
|
|
17213
|
+
files: graph.fileCount,
|
|
17214
|
+
links: graph.fileOut.to.length,
|
|
17215
|
+
definitions: graph.stats.definitions,
|
|
17216
|
+
importEdges: graph.stats.importEdges,
|
|
17217
|
+
referenceEdges: graph.stats.referenceEdges,
|
|
17218
|
+
subsystems: graph.subsystems.length,
|
|
17219
|
+
cycles: graph.cycles.length
|
|
17220
|
+
},
|
|
17221
|
+
shown: { nodes: nodes.length, edges: kept.length },
|
|
17222
|
+
bounds,
|
|
17223
|
+
nodes,
|
|
17224
|
+
edges: kept.map((edge) => ({ from: edge.from, to: edge.to, imports: edge.imports, weight: round(edge.weight, 3) })),
|
|
17225
|
+
communities
|
|
17226
|
+
};
|
|
17227
|
+
}
|
|
17228
|
+
|
|
17229
|
+
// src/explorer-html.ts
|
|
17230
|
+
init_import_meta();
|
|
17231
|
+
var import_node_crypto8 = require("node:crypto");
|
|
17232
|
+
var import_node_fs6 = require("node:fs");
|
|
17233
|
+
var import_node_path7 = require("node:path");
|
|
17234
|
+
var escapeHtml2 = (text) => text.replace(/[&<>"']/g, (ch) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[ch]);
|
|
17235
|
+
var NONCE_PATTERN = /^[A-Za-z0-9+/]{16,}={0,2}$/;
|
|
17236
|
+
var newNonce = () => (0, import_node_crypto8.randomBytes)(16).toString("base64");
|
|
17237
|
+
var jsonForScript = (value) => JSON.stringify(value).replace(/[<>&\u2028\u2029]/g, (ch) => `\\u${ch.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
17238
|
+
var assertInline = (name2, text, forbidden) => {
|
|
17239
|
+
if (forbidden.test(text)) throw new Error(`${name2} contains markup that would end its inline element early`);
|
|
17240
|
+
};
|
|
17241
|
+
function renderExplorerHtml(model, assets, nonce = newNonce()) {
|
|
17242
|
+
if (!NONCE_PATTERN.test(nonce)) throw new Error("nonce must be base64");
|
|
17243
|
+
assertInline("explorer.css", assets.css, /<\/style/i);
|
|
17244
|
+
assertInline("explorer.js", assets.js, /<\/script|<!--/i);
|
|
17245
|
+
const title = escapeHtml2(model.title);
|
|
17246
|
+
const csp = `default-src 'none'; style-src 'nonce-${nonce}'; script-src 'nonce-${nonce}'; base-uri 'none'; form-action 'none'`;
|
|
17247
|
+
return `<!doctype html>
|
|
17248
|
+
<html lang="en">
|
|
17249
|
+
<head>
|
|
17250
|
+
<meta charset="utf-8">
|
|
17251
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
17252
|
+
<meta http-equiv="Content-Security-Policy" content="${csp}">
|
|
17253
|
+
<title>${title}</title>
|
|
17254
|
+
<style nonce="${nonce}">${assets.css}</style>
|
|
17255
|
+
</head>
|
|
17256
|
+
<body>
|
|
17257
|
+
<header class="bar">
|
|
17258
|
+
<h1 id="title">${title}</h1>
|
|
17259
|
+
<p id="summary" class="summary">Loading the code map\u2026</p>
|
|
17260
|
+
<div class="actions">
|
|
17261
|
+
<button id="fit" type="button" class="ghost" title="Fit the whole map in view (0)">Fit</button>
|
|
17262
|
+
<button id="show-all" type="button" class="ghost" disabled title="Show every subsystem again">Show all</button>
|
|
17263
|
+
</div>
|
|
17264
|
+
</header>
|
|
17265
|
+
<div class="layout">
|
|
17266
|
+
<main id="stage" class="stage">
|
|
17267
|
+
<canvas id="canvas" tabindex="0" role="application" aria-label="Code map" aria-describedby="keys"></canvas>
|
|
17268
|
+
<div id="tip" class="tip" role="tooltip" hidden></div>
|
|
17269
|
+
<div id="empty" class="empty"><p id="empty-text">Loading the code map\u2026</p></div>
|
|
17270
|
+
</main>
|
|
17271
|
+
<aside class="side" aria-label="Explorer controls">
|
|
17272
|
+
<section aria-labelledby="h-find">
|
|
17273
|
+
<h2 id="h-find">Find a file</h2>
|
|
17274
|
+
<input id="search" type="search" placeholder="Name or path (press /)" aria-label="Find a file by name or path" autocomplete="off" spellcheck="false">
|
|
17275
|
+
<ul id="results" class="results" aria-label="Matching files"></ul>
|
|
17276
|
+
</section>
|
|
17277
|
+
<section aria-labelledby="h-sub">
|
|
17278
|
+
<h2 id="h-sub">Subsystems</h2>
|
|
17279
|
+
<ul id="legend" class="legend" aria-label="Subsystems. Select one to show or hide it."></ul>
|
|
17280
|
+
</section>
|
|
17281
|
+
<section aria-labelledby="h-info">
|
|
17282
|
+
<h2 id="h-info">Selected file</h2>
|
|
17283
|
+
<p id="info-empty" class="keys">Select a file on the map or in the results. Its links and importance appear here.</p>
|
|
17284
|
+
<div id="info-body" hidden>
|
|
17285
|
+
<p id="info-path" class="info-path"></p>
|
|
17286
|
+
<p><span id="info-swatch" class="swatch" aria-hidden="true"></span> <span id="info-sub"></span></p>
|
|
17287
|
+
<dl>
|
|
17288
|
+
<dt>Importance</dt><dd id="info-rank"></dd>
|
|
17289
|
+
<dt>Imported by</dt><dd id="info-in"></dd>
|
|
17290
|
+
<dt>Imports</dt><dd id="info-out"></dd>
|
|
17291
|
+
</dl>
|
|
17292
|
+
<h2>Links <span id="neighbour-count" class="count"></span></h2>
|
|
17293
|
+
<ul id="neighbours" class="neighbours" aria-label="Linked files"></ul>
|
|
17294
|
+
<button id="open-btn" type="button" class="open-btn" disabled>Open file</button>
|
|
17295
|
+
</div>
|
|
17296
|
+
</section>
|
|
17297
|
+
<section id="notes-section" aria-labelledby="h-notes" hidden>
|
|
17298
|
+
<h2 id="h-notes">Notes</h2>
|
|
17299
|
+
<ul id="notes" class="notes"></ul>
|
|
17300
|
+
</section>
|
|
17301
|
+
<section aria-labelledby="h-keys">
|
|
17302
|
+
<h2 id="h-keys">Keys</h2>
|
|
17303
|
+
<div id="keys" class="keys">
|
|
17304
|
+
<div><kbd>/</kbd> search</div>
|
|
17305
|
+
<div><kbd>n</kbd> / <kbd>N</kbd> next or previous match</div>
|
|
17306
|
+
<div>Arrows pan \xB7 <kbd>+</kbd> <kbd>-</kbd> zoom \xB7 <kbd>0</kbd> fit</div>
|
|
17307
|
+
<div><kbd>Enter</kbd> open \xB7 <kbd>Esc</kbd> clear selection</div>
|
|
17308
|
+
<div>Drag to pan, wheel to zoom, double-click to open</div>
|
|
17309
|
+
</div>
|
|
17310
|
+
</section>
|
|
17311
|
+
</aside>
|
|
17312
|
+
</div>
|
|
17313
|
+
<p id="status" class="sr-only" role="status" aria-live="polite"></p>
|
|
17314
|
+
<script id="squeze-model" type="application/json">${jsonForScript(model)}</script>
|
|
17315
|
+
<script nonce="${nonce}">${assets.js}</script>
|
|
17316
|
+
</body>
|
|
17317
|
+
</html>
|
|
17318
|
+
`;
|
|
17319
|
+
}
|
|
17320
|
+
function readExplorerAssets(mediaDir) {
|
|
17321
|
+
return {
|
|
17322
|
+
css: (0, import_node_fs6.readFileSync)((0, import_node_path7.join)(mediaDir, "explorer.css"), "utf8"),
|
|
17323
|
+
js: (0, import_node_fs6.readFileSync)((0, import_node_path7.join)(mediaDir, "explorer.js"), "utf8")
|
|
17324
|
+
};
|
|
17325
|
+
}
|
|
17326
|
+
|
|
17327
|
+
// src/live-refresh.ts
|
|
17328
|
+
init_import_meta();
|
|
17329
|
+
function createRefreshScheduler(task, options) {
|
|
17330
|
+
let timer;
|
|
17331
|
+
let running = false;
|
|
17332
|
+
let queued = false;
|
|
17333
|
+
let disposed = false;
|
|
17334
|
+
const schedule = () => {
|
|
17335
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
17336
|
+
timer = setTimeout(run2, options.delayMs);
|
|
17337
|
+
};
|
|
17338
|
+
async function run2() {
|
|
17339
|
+
timer = void 0;
|
|
17340
|
+
if (disposed) return;
|
|
17341
|
+
if (running) {
|
|
17342
|
+
queued = true;
|
|
17343
|
+
return;
|
|
17344
|
+
}
|
|
17345
|
+
running = true;
|
|
17346
|
+
try {
|
|
17347
|
+
await task();
|
|
17348
|
+
} catch (error) {
|
|
17349
|
+
options.onError?.(error);
|
|
17350
|
+
} finally {
|
|
17351
|
+
running = false;
|
|
17352
|
+
if (queued && !disposed) {
|
|
17353
|
+
queued = false;
|
|
17354
|
+
schedule();
|
|
17355
|
+
}
|
|
17356
|
+
}
|
|
17357
|
+
}
|
|
17358
|
+
return {
|
|
17359
|
+
trigger() {
|
|
17360
|
+
if (!disposed) schedule();
|
|
17361
|
+
},
|
|
17362
|
+
dispose() {
|
|
17363
|
+
disposed = true;
|
|
17364
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
17365
|
+
timer = void 0;
|
|
17366
|
+
}
|
|
17367
|
+
};
|
|
17368
|
+
}
|
|
17369
|
+
var IGNORED_SEGMENTS = /* @__PURE__ */ new Set([".git", "node_modules"]);
|
|
17370
|
+
function isWatchedPath(relativePath) {
|
|
17371
|
+
return !relativePath.split(/[\\/]/).some((segment2) => IGNORED_SEGMENTS.has(segment2));
|
|
17372
|
+
}
|
|
17373
|
+
|
|
17374
|
+
// src/token-ledger.ts
|
|
17375
|
+
init_import_meta();
|
|
17376
|
+
var LEDGER_VERSION = 1;
|
|
17377
|
+
var LEDGER_CAPACITY = 500;
|
|
17378
|
+
var MAX_TOOL_NAME = 64;
|
|
17379
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17380
|
+
var wholeTokens = (value) => typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.round(value) : 0;
|
|
17381
|
+
var emptyTotals = () => ({ calls: 0, inputTokens: 0, outputTokens: 0, savedTokens: 0 });
|
|
17382
|
+
var entryFrom = (at, tool, inputTokens, outputTokens) => ({
|
|
17383
|
+
at,
|
|
17384
|
+
tool: tool.slice(0, MAX_TOOL_NAME),
|
|
17385
|
+
inputTokens,
|
|
17386
|
+
outputTokens,
|
|
17387
|
+
savedTokens: Math.max(0, inputTokens - outputTokens)
|
|
17388
|
+
});
|
|
17389
|
+
var parseEntry = (value) => {
|
|
17390
|
+
if (!isRecord(value) || typeof value.tool !== "string") return [];
|
|
17391
|
+
const at = typeof value.at === "number" && Number.isFinite(value.at) ? value.at : 0;
|
|
17392
|
+
return [entryFrom(at, value.tool, wholeTokens(value.inputTokens), wholeTokens(value.outputTokens))];
|
|
17393
|
+
};
|
|
17394
|
+
var TokenLedger = class _TokenLedger {
|
|
17395
|
+
entries;
|
|
17396
|
+
lifetime;
|
|
17397
|
+
constructor(entries = [], lifetime = emptyTotals()) {
|
|
17398
|
+
this.entries = entries.slice(-LEDGER_CAPACITY);
|
|
17399
|
+
this.lifetime = { ...lifetime };
|
|
17400
|
+
}
|
|
17401
|
+
/** Saved tokens never go negative, so a pack larger than the repository counts as zero saved. */
|
|
17402
|
+
record(tool, sample, at = Date.now()) {
|
|
17403
|
+
const entry = entryFrom(at, tool, wholeTokens(sample.inputTokens), wholeTokens(sample.outputTokens));
|
|
17404
|
+
this.entries.push(entry);
|
|
17405
|
+
if (this.entries.length > LEDGER_CAPACITY) this.entries.splice(0, this.entries.length - LEDGER_CAPACITY);
|
|
17406
|
+
this.lifetime.calls += 1;
|
|
17407
|
+
this.lifetime.inputTokens += entry.inputTokens;
|
|
17408
|
+
this.lifetime.outputTokens += entry.outputTokens;
|
|
17409
|
+
this.lifetime.savedTokens += entry.savedTokens;
|
|
17410
|
+
return { ...entry };
|
|
17411
|
+
}
|
|
17412
|
+
/** Lifetime totals. They keep counting after old entries are evicted. */
|
|
17413
|
+
totals() {
|
|
17414
|
+
return { ...this.lifetime };
|
|
17415
|
+
}
|
|
17416
|
+
/** Newest first. */
|
|
17417
|
+
recent(limit = 10) {
|
|
17418
|
+
const count = Math.floor(limit);
|
|
17419
|
+
if (!(count > 0)) return [];
|
|
17420
|
+
return this.entries.slice(-count).reverse().map((entry) => ({ ...entry }));
|
|
17421
|
+
}
|
|
17422
|
+
toJSON() {
|
|
17423
|
+
return { version: LEDGER_VERSION, lifetime: this.totals(), entries: this.entries.map((entry) => ({ ...entry })) };
|
|
17424
|
+
}
|
|
17425
|
+
/** Accepts anything read back from storage. Malformed input yields an empty or partial ledger instead of throwing. */
|
|
17426
|
+
static fromJSON(value) {
|
|
17427
|
+
if (!isRecord(value) || value.version !== LEDGER_VERSION) return new _TokenLedger();
|
|
17428
|
+
const entries = Array.isArray(value.entries) ? value.entries.flatMap(parseEntry) : [];
|
|
17429
|
+
const stored = isRecord(value.lifetime) ? value.lifetime : {};
|
|
17430
|
+
return new _TokenLedger(entries, {
|
|
17431
|
+
calls: wholeTokens(stored.calls),
|
|
17432
|
+
inputTokens: wholeTokens(stored.inputTokens),
|
|
17433
|
+
outputTokens: wholeTokens(stored.outputTokens),
|
|
17434
|
+
savedTokens: wholeTokens(stored.savedTokens)
|
|
17435
|
+
});
|
|
17436
|
+
}
|
|
17437
|
+
};
|
|
17438
|
+
|
|
17439
|
+
// src/status-text.ts
|
|
17440
|
+
init_import_meta();
|
|
17441
|
+
var UNSAFE_CELL = /[^A-Za-z0-9_.:-]/g;
|
|
17442
|
+
function compactCount(value) {
|
|
17443
|
+
const n = Number.isFinite(value) && value > 0 ? Math.round(value) : 0;
|
|
17444
|
+
if (n < 1e3) return String(n);
|
|
17445
|
+
if (n < 999500) return trimmed(n / 1e3) + "k";
|
|
17446
|
+
return trimmed(n / 1e6) + "M";
|
|
17447
|
+
}
|
|
17448
|
+
function trimmed(value) {
|
|
17449
|
+
const text = value < 10 ? value.toFixed(1) : Math.round(value).toString();
|
|
17450
|
+
return text.replace(/\.0$/, "");
|
|
17451
|
+
}
|
|
17452
|
+
function indexedStatus(files, savedTokens) {
|
|
17453
|
+
return `$(graph) Squeze \xB7 ${files.toLocaleString("en-US")} files \xB7 ~${compactCount(savedTokens)} saved`;
|
|
17454
|
+
}
|
|
17455
|
+
function ledgerMarkdown(totals, recent) {
|
|
17456
|
+
const reduction = totals.inputTokens > 0 ? totals.savedTokens / totals.inputTokens * 100 : 0;
|
|
17457
|
+
const lines = [
|
|
17458
|
+
"# Squeze token ledger",
|
|
17459
|
+
"",
|
|
17460
|
+
"Estimates for pack calls in this workspace. These are not billing figures: the full-repository size is an estimate of the indexed repository, and the returned size is the pack Squeze sent back.",
|
|
17461
|
+
"",
|
|
17462
|
+
"| Measure | Value |",
|
|
17463
|
+
"|---|---|",
|
|
17464
|
+
`| Pack calls | ${number(totals.calls)} |`,
|
|
17465
|
+
`| Full repository (est. tokens) | ${number(totals.inputTokens)} |`,
|
|
17466
|
+
`| Returned (tokens) | ${number(totals.outputTokens)} |`,
|
|
17467
|
+
`| Saved (est. tokens) | ${number(totals.savedTokens)} |`,
|
|
17468
|
+
`| Reduction | ${reduction.toFixed(1)}% |`,
|
|
17469
|
+
""
|
|
17470
|
+
];
|
|
17471
|
+
if (recent.length === 0) {
|
|
17472
|
+
lines.push("No pack calls recorded yet.");
|
|
17473
|
+
} else {
|
|
17474
|
+
lines.push("## Recent calls", "", "| Time (UTC) | Tool | Returned | Saved |", "|---|---|---|---|");
|
|
17475
|
+
for (const entry of recent) {
|
|
17476
|
+
lines.push(`| ${timeOf(entry.at)} | ${cell(entry.tool)} | ${number(entry.outputTokens)} | ${number(entry.savedTokens)} |`);
|
|
17477
|
+
}
|
|
17478
|
+
}
|
|
17479
|
+
return lines.join("\n") + "\n";
|
|
17480
|
+
}
|
|
17481
|
+
function number(value) {
|
|
17482
|
+
return Math.round(value).toLocaleString("en-US");
|
|
17483
|
+
}
|
|
17484
|
+
function timeOf(at) {
|
|
17485
|
+
return at > 0 ? new Date(at).toISOString().slice(0, 19).replace("T", " ") : "\u2014";
|
|
17486
|
+
}
|
|
17487
|
+
function cell(text) {
|
|
17488
|
+
return text.replace(UNSAFE_CELL, "?");
|
|
17489
|
+
}
|
|
17490
|
+
|
|
17014
17491
|
// src/extension.ts
|
|
17492
|
+
var LEDGER_KEY = "squeze.ledger";
|
|
17493
|
+
var REFRESH_DELAY_MS = 1200;
|
|
17494
|
+
var MAX_REFRESH_ATTEMPTS = 3;
|
|
17495
|
+
function messageOf(error) {
|
|
17496
|
+
return error instanceof Error ? error.message : String(error);
|
|
17497
|
+
}
|
|
17015
17498
|
function activate(context) {
|
|
17016
|
-
const
|
|
17017
|
-
const
|
|
17499
|
+
const config = () => vscode.workspace.getConfiguration("squeze");
|
|
17500
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
17501
|
+
const ledger = TokenLedger.fromJSON(context.workspaceState.get(LEDGER_KEY));
|
|
17502
|
+
const statusItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 100);
|
|
17503
|
+
statusItem.name = "Squeze";
|
|
17504
|
+
statusItem.command = "squeze.explore";
|
|
17505
|
+
context.subscriptions.push(statusItem);
|
|
17506
|
+
let current;
|
|
17507
|
+
let explorer;
|
|
17508
|
+
let assets;
|
|
17509
|
+
function getSession() {
|
|
17018
17510
|
if (!vscode.workspace.isTrusted) throw new Error("Trust this workspace before indexing.");
|
|
17019
17511
|
const active = vscode.window.activeTextEditor?.document.uri;
|
|
17020
17512
|
const folder = active && vscode.workspace.getWorkspaceFolder(active) || vscode.workspace.workspaceFolders?.[0];
|
|
17021
17513
|
if (!folder || folder.uri.scheme !== "file") throw new Error("Open a local repository folder first.");
|
|
17022
|
-
const model =
|
|
17023
|
-
const features =
|
|
17514
|
+
const model = config().get("semanticModel", "");
|
|
17515
|
+
const features = config().get("features", "");
|
|
17024
17516
|
const key = folder.uri.fsPath + "\0" + model + "\0" + features;
|
|
17025
|
-
|
|
17026
|
-
|
|
17027
|
-
|
|
17517
|
+
let session = sessions.get(key);
|
|
17518
|
+
if (!session) {
|
|
17519
|
+
session = {
|
|
17520
|
+
key,
|
|
17521
|
+
folder,
|
|
17522
|
+
state: "idle",
|
|
17523
|
+
pending: Promise.resolve(),
|
|
17524
|
+
engine: new Engine(folder.uri.fsPath, { semanticModel: model || void 0, features: features || void 0 })
|
|
17525
|
+
};
|
|
17526
|
+
sessions.set(key, session);
|
|
17527
|
+
if (config().get("autoRefresh", true)) {
|
|
17528
|
+
startWatcher(session);
|
|
17529
|
+
void refresh(session, false);
|
|
17530
|
+
}
|
|
17531
|
+
}
|
|
17532
|
+
current = session;
|
|
17533
|
+
return session;
|
|
17534
|
+
}
|
|
17535
|
+
function startWatcher(session) {
|
|
17536
|
+
if (session.watcher) return;
|
|
17537
|
+
const root = session.folder.uri.fsPath;
|
|
17538
|
+
session.scheduler = createRefreshScheduler(() => refresh(session, false), { delayMs: REFRESH_DELAY_MS });
|
|
17539
|
+
const watcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(session.folder, "**/*"));
|
|
17540
|
+
const onChange = (uri) => {
|
|
17541
|
+
const rel = (0, import_node_path8.relative)(root, uri.fsPath);
|
|
17542
|
+
if (!rel || (0, import_node_path8.isAbsolute)(rel) || rel.split(/[\\/]/)[0] === "..") return;
|
|
17543
|
+
if (isWatchedPath(rel)) session.scheduler?.trigger();
|
|
17544
|
+
};
|
|
17545
|
+
watcher.onDidCreate(onChange);
|
|
17546
|
+
watcher.onDidChange(onChange);
|
|
17547
|
+
watcher.onDidDelete(onChange);
|
|
17548
|
+
session.watcher = watcher;
|
|
17549
|
+
}
|
|
17550
|
+
function stopWatcher(session) {
|
|
17551
|
+
session.watcher?.dispose();
|
|
17552
|
+
session.scheduler?.dispose();
|
|
17553
|
+
session.watcher = void 0;
|
|
17554
|
+
session.scheduler = void 0;
|
|
17555
|
+
}
|
|
17556
|
+
function disposeSessions() {
|
|
17557
|
+
for (const session of sessions.values()) stopWatcher(session);
|
|
17558
|
+
sessions.clear();
|
|
17559
|
+
current = void 0;
|
|
17560
|
+
explorer?.panel.dispose();
|
|
17561
|
+
explorer = void 0;
|
|
17562
|
+
}
|
|
17563
|
+
function refresh(session, force) {
|
|
17564
|
+
const run2 = session.pending.then(() => refreshNow(session, force));
|
|
17565
|
+
session.pending = run2;
|
|
17566
|
+
return run2;
|
|
17567
|
+
}
|
|
17568
|
+
async function refreshNow(session, force) {
|
|
17569
|
+
session.state = "indexing";
|
|
17570
|
+
updateStatus();
|
|
17571
|
+
try {
|
|
17572
|
+
const changed = await rebuildIfChanged(session, force);
|
|
17573
|
+
session.state = "ready";
|
|
17574
|
+
session.error = void 0;
|
|
17575
|
+
session.indexedAt = Date.now();
|
|
17576
|
+
if (changed) pushModel(session);
|
|
17577
|
+
} catch (error) {
|
|
17578
|
+
session.state = "failed";
|
|
17579
|
+
session.error = messageOf(error);
|
|
17580
|
+
}
|
|
17581
|
+
updateStatus();
|
|
17582
|
+
}
|
|
17583
|
+
async function rebuildIfChanged(session, force) {
|
|
17584
|
+
for (let attempt = 1; ; attempt++) {
|
|
17585
|
+
try {
|
|
17586
|
+
if (!force && session.graph) {
|
|
17587
|
+
const { revision } = await session.engine.snapshot("__repository_map__");
|
|
17588
|
+
if (revision === session.graph.revision) return false;
|
|
17589
|
+
}
|
|
17590
|
+
const { graph } = await loadGraph(session.engine);
|
|
17591
|
+
session.graph = graph;
|
|
17592
|
+
session.model = void 0;
|
|
17593
|
+
return true;
|
|
17594
|
+
} catch (error) {
|
|
17595
|
+
if (error instanceof SourceChangedError && attempt < MAX_REFRESH_ATTEMPTS) continue;
|
|
17596
|
+
throw error;
|
|
17597
|
+
}
|
|
17598
|
+
}
|
|
17599
|
+
}
|
|
17600
|
+
function modelFor(session) {
|
|
17601
|
+
if (!session.graph) return void 0;
|
|
17602
|
+
if (!session.model) session.model = buildExplorerModel(session.graph, { title: session.folder.name });
|
|
17603
|
+
return session.model;
|
|
17604
|
+
}
|
|
17605
|
+
function pushModel(session) {
|
|
17606
|
+
const view = explorer;
|
|
17607
|
+
const model = modelFor(session);
|
|
17608
|
+
if (view?.session === session && model) void view.panel.webview.postMessage({ type: "model", model });
|
|
17609
|
+
}
|
|
17610
|
+
function explorerAssets() {
|
|
17611
|
+
assets ??= readExplorerAssets((0, import_node_path8.join)(context.extensionPath, "media"));
|
|
17612
|
+
return assets;
|
|
17613
|
+
}
|
|
17614
|
+
function showExplorer(session) {
|
|
17615
|
+
const model = modelFor(session);
|
|
17616
|
+
if (!model) throw new Error(session.error ?? "Squeze could not index this repository.");
|
|
17617
|
+
const view = explorer;
|
|
17618
|
+
if (view) {
|
|
17619
|
+
view.panel.reveal();
|
|
17620
|
+
if (view.session === session) {
|
|
17621
|
+
void view.panel.webview.postMessage({ type: "model", model });
|
|
17622
|
+
} else {
|
|
17623
|
+
view.session = session;
|
|
17624
|
+
view.panel.title = `Squeze: ${session.folder.name}`;
|
|
17625
|
+
view.panel.webview.html = renderExplorerHtml(model, explorerAssets());
|
|
17626
|
+
}
|
|
17627
|
+
return;
|
|
17628
|
+
}
|
|
17629
|
+
const panel = vscode.window.createWebviewPanel("squeze.explorer", `Squeze: ${session.folder.name}`, vscode.ViewColumn.Beside, { enableScripts: true, retainContextWhenHidden: true, localResourceRoots: [] });
|
|
17630
|
+
const created = { panel, session };
|
|
17631
|
+
explorer = created;
|
|
17632
|
+
panel.webview.html = renderExplorerHtml(model, explorerAssets());
|
|
17633
|
+
panel.onDidDispose(() => {
|
|
17634
|
+
if (explorer === created) explorer = void 0;
|
|
17635
|
+
});
|
|
17636
|
+
panel.webview.onDidReceiveMessage((message) => {
|
|
17637
|
+
void openFromExplorer(created, message).catch((error) => vscode.window.showErrorMessage(messageOf(error)));
|
|
17638
|
+
});
|
|
17639
|
+
}
|
|
17640
|
+
async function openFromExplorer(view, message) {
|
|
17641
|
+
const path = explorerOpenPath(message);
|
|
17642
|
+
const model = view.session.model;
|
|
17643
|
+
if (!path || !model || !isShownPath(model, path)) return;
|
|
17644
|
+
const document2 = await vscode.workspace.openTextDocument(vscode.Uri.joinPath(view.session.folder.uri, path));
|
|
17645
|
+
await vscode.window.showTextDocument(document2, { preview: true });
|
|
17646
|
+
}
|
|
17647
|
+
async function openExplorer() {
|
|
17648
|
+
const session = getSession();
|
|
17649
|
+
await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: "Squeze: reading repository" }, () => refresh(session, false));
|
|
17650
|
+
if (session.state === "failed" || !session.graph) throw new Error(session.error ?? "Squeze could not index this repository.");
|
|
17651
|
+
showExplorer(session);
|
|
17652
|
+
}
|
|
17653
|
+
async function refreshIndex() {
|
|
17654
|
+
const session = getSession();
|
|
17655
|
+
await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: "Squeze: refreshing index" }, () => refresh(session, true));
|
|
17656
|
+
if (session.state === "failed" || !session.graph) throw new Error(session.error ?? "Squeze could not index this repository.");
|
|
17657
|
+
vscode.window.showInformationMessage(`Squeze: indexed ${session.graph.fileCount.toLocaleString("en-US")} files.`);
|
|
17658
|
+
}
|
|
17659
|
+
function recordPack(tool, stats) {
|
|
17660
|
+
ledger.record(tool, { inputTokens: stats.inputTokens, outputTokens: stats.outputTokens });
|
|
17661
|
+
void context.workspaceState.update(LEDGER_KEY, ledger.toJSON());
|
|
17662
|
+
updateStatus();
|
|
17663
|
+
}
|
|
17664
|
+
function updateStatus() {
|
|
17665
|
+
const session = current;
|
|
17666
|
+
statusItem.backgroundColor = void 0;
|
|
17667
|
+
if (!vscode.workspace.isTrusted) {
|
|
17668
|
+
statusItem.text = "$(lock) Squeze";
|
|
17669
|
+
statusItem.tooltip = "Squeze waits for workspace trust before indexing.";
|
|
17670
|
+
} else if (!session || session.state === "idle") {
|
|
17671
|
+
statusItem.text = "$(graph) Squeze";
|
|
17672
|
+
statusItem.tooltip = "Squeze: open the Code Explorer, or run Squeze: Refresh Index.";
|
|
17673
|
+
} else if (session.state === "indexing") {
|
|
17674
|
+
statusItem.text = "$(sync~spin) Squeze indexing\u2026";
|
|
17675
|
+
statusItem.tooltip = "Squeze is indexing this repository.";
|
|
17676
|
+
} else if (session.state === "failed") {
|
|
17677
|
+
statusItem.text = "$(warning) Squeze index failed";
|
|
17678
|
+
statusItem.backgroundColor = new vscode.ThemeColor("statusBarItem.warningBackground");
|
|
17679
|
+
statusItem.tooltip = session.error ?? "Squeze could not index this repository.";
|
|
17680
|
+
} else if (session.graph) {
|
|
17681
|
+
statusItem.text = indexedStatus(session.graph.fileCount, ledger.totals().savedTokens);
|
|
17682
|
+
statusItem.tooltip = readyTooltip(session, session.graph);
|
|
17683
|
+
}
|
|
17684
|
+
statusItem.show();
|
|
17685
|
+
}
|
|
17686
|
+
function readyTooltip(session, graph) {
|
|
17687
|
+
const totals = ledger.totals();
|
|
17688
|
+
const tip = new vscode.MarkdownString("", true);
|
|
17689
|
+
tip.appendMarkdown("**Squeze** \xB7 ");
|
|
17690
|
+
tip.appendText(session.folder.name);
|
|
17691
|
+
tip.appendMarkdown(`
|
|
17692
|
+
|
|
17693
|
+
Files: ${graph.fileCount.toLocaleString("en-US")} \xB7 Subsystems: ${graph.subsystems.length.toLocaleString("en-US")}`);
|
|
17694
|
+
tip.appendMarkdown(`
|
|
17695
|
+
|
|
17696
|
+
Last checked: ${session.indexedAt ? new Date(session.indexedAt).toLocaleTimeString() : "never"}`);
|
|
17697
|
+
tip.appendMarkdown(`
|
|
17698
|
+
|
|
17699
|
+
Pack calls: ${totals.calls.toLocaleString("en-US")} \xB7 est. saved: ${totals.savedTokens.toLocaleString("en-US")} tokens (estimate, not billing)`);
|
|
17700
|
+
tip.appendMarkdown("\n\nClick to open the Code Explorer.");
|
|
17701
|
+
return tip;
|
|
17702
|
+
}
|
|
17703
|
+
function command(id, run2) {
|
|
17704
|
+
context.subscriptions.push(vscode.commands.registerCommand(id, async () => {
|
|
17705
|
+
try {
|
|
17706
|
+
await run2();
|
|
17707
|
+
} catch (error) {
|
|
17708
|
+
vscode.window.showErrorMessage(messageOf(error));
|
|
17709
|
+
}
|
|
17710
|
+
}));
|
|
17711
|
+
}
|
|
17028
17712
|
const defaultBudget = () => vscode.workspace.getConfiguration("squeze").get("tokenBudget", 3e3);
|
|
17029
17713
|
const show = async (text) => vscode.window.showTextDocument(await vscode.workspace.openTextDocument({ content: text, language: "markdown" }), { preview: true });
|
|
17030
17714
|
context.subscriptions.push(vscode.commands.registerCommand("squeze.pack", async () => {
|
|
@@ -17032,7 +17716,8 @@ function activate(context) {
|
|
|
17032
17716
|
if (!query) return;
|
|
17033
17717
|
try {
|
|
17034
17718
|
await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: "Squeze: reading repository" }, async () => {
|
|
17035
|
-
const result = await
|
|
17719
|
+
const result = await getSession().engine.context(query, defaultBudget());
|
|
17720
|
+
recordPack("squeze.pack", result.stats);
|
|
17036
17721
|
await show(result.text);
|
|
17037
17722
|
vscode.window.showInformationMessage(`Squeze: ${result.stats.outputTokens.toLocaleString()} tokens (${result.stats.tokenizer}); ${(result.stats.reduction * 100).toFixed(1)}% smaller than full indexed repository. This is not measured billing savings.`);
|
|
17038
17723
|
});
|
|
@@ -17042,23 +17727,20 @@ function activate(context) {
|
|
|
17042
17727
|
}));
|
|
17043
17728
|
context.subscriptions.push(vscode.commands.registerCommand("squeze.map", async () => {
|
|
17044
17729
|
try {
|
|
17045
|
-
await show(repositoryMap(await
|
|
17046
|
-
} catch (e) {
|
|
17047
|
-
vscode.window.showErrorMessage(String(e));
|
|
17048
|
-
}
|
|
17049
|
-
}));
|
|
17050
|
-
context.subscriptions.push(vscode.commands.registerCommand("squeze.graph", async () => {
|
|
17051
|
-
try {
|
|
17052
|
-
const html = await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: "Squeze: building code graph" }, () => runGraph(getRepo(), { mode: "html" }));
|
|
17053
|
-
const panel = vscode.window.createWebviewPanel("squezeGraph", "Squeze: Code Graph", vscode.ViewColumn.Beside, { enableScripts: true, retainContextWhenHidden: false, localResourceRoots: [] });
|
|
17054
|
-
panel.webview.html = html;
|
|
17730
|
+
await show(repositoryMap(await getSession().engine.snapshot("__repository_map__"), defaultBudget()));
|
|
17055
17731
|
} catch (e) {
|
|
17056
17732
|
vscode.window.showErrorMessage(String(e));
|
|
17057
17733
|
}
|
|
17058
17734
|
}));
|
|
17735
|
+
command("squeze.graph", openExplorer);
|
|
17736
|
+
command("squeze.explore", openExplorer);
|
|
17737
|
+
command("squeze.refresh", refreshIndex);
|
|
17738
|
+
command("squeze.stats", async () => {
|
|
17739
|
+
await show(ledgerMarkdown(ledger.totals(), ledger.recent(10)));
|
|
17740
|
+
});
|
|
17059
17741
|
context.subscriptions.push(vscode.commands.registerCommand("squeze.setup", async () => {
|
|
17060
17742
|
try {
|
|
17061
|
-
const repo =
|
|
17743
|
+
const repo = getSession().engine;
|
|
17062
17744
|
const dir = vscode.Uri.file(`${repo.root}/.github/instructions`);
|
|
17063
17745
|
const target = vscode.Uri.joinPath(dir, "squeze.instructions.md");
|
|
17064
17746
|
try {
|
|
@@ -17080,8 +17762,9 @@ ${INSTRUCTIONS}`));
|
|
|
17080
17762
|
context.subscriptions.push(vscode.lm.registerTool("squeze_context", {
|
|
17081
17763
|
async invoke(options, token) {
|
|
17082
17764
|
if (token.isCancellationRequested) throw new vscode.CancellationError();
|
|
17083
|
-
const pack = await
|
|
17765
|
+
const pack = await getSession().engine.context(options.input.query, options.input.budget ?? defaultBudget());
|
|
17084
17766
|
if (token.isCancellationRequested) throw new vscode.CancellationError();
|
|
17767
|
+
recordPack("squeze_context", pack.stats);
|
|
17085
17768
|
return new vscode.LanguageModelToolResult([new vscode.LanguageModelTextPart(pack.text)]);
|
|
17086
17769
|
}
|
|
17087
17770
|
}));
|
|
@@ -17089,7 +17772,7 @@ ${INSTRUCTIONS}`));
|
|
|
17089
17772
|
async invoke(options, token) {
|
|
17090
17773
|
if (token.isCancellationRequested) throw new vscode.CancellationError();
|
|
17091
17774
|
const { path, start: start2, end, budget } = options.input;
|
|
17092
|
-
const text = await
|
|
17775
|
+
const text = await getSession().engine.expandRange(path, start2, end, budget ?? defaultBudget());
|
|
17093
17776
|
if (token.isCancellationRequested) throw new vscode.CancellationError();
|
|
17094
17777
|
return new vscode.LanguageModelToolResult([new vscode.LanguageModelTextPart(text)]);
|
|
17095
17778
|
}
|
|
@@ -17098,7 +17781,7 @@ ${INSTRUCTIONS}`));
|
|
|
17098
17781
|
async invoke(options, token) {
|
|
17099
17782
|
if (token.isCancellationRequested) throw new vscode.CancellationError();
|
|
17100
17783
|
const { path, query, budget } = options.input;
|
|
17101
|
-
const repo =
|
|
17784
|
+
const repo = getSession().engine;
|
|
17102
17785
|
const limit = budget ?? 1500;
|
|
17103
17786
|
let text;
|
|
17104
17787
|
if (path) {
|
|
@@ -17117,11 +17800,40 @@ ${INSTRUCTIONS}`));
|
|
|
17117
17800
|
async invoke(options, token) {
|
|
17118
17801
|
if (token.isCancellationRequested) throw new vscode.CancellationError();
|
|
17119
17802
|
const { mode, target, to, depth, budget } = options.input;
|
|
17120
|
-
const text = await runGraph(
|
|
17803
|
+
const text = await runGraph(getSession().engine, { mode, target, to, depth, budget: budget ?? 1500 });
|
|
17121
17804
|
if (token.isCancellationRequested) throw new vscode.CancellationError();
|
|
17122
17805
|
return new vscode.LanguageModelToolResult([new vscode.LanguageModelTextPart(text)]);
|
|
17123
17806
|
}
|
|
17124
17807
|
}));
|
|
17808
|
+
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration((event) => {
|
|
17809
|
+
if (event.affectsConfiguration("squeze.semanticModel") || event.affectsConfiguration("squeze.features")) {
|
|
17810
|
+
disposeSessions();
|
|
17811
|
+
} else if (event.affectsConfiguration("squeze.autoRefresh")) {
|
|
17812
|
+
for (const session of sessions.values()) {
|
|
17813
|
+
stopWatcher(session);
|
|
17814
|
+
if (config().get("autoRefresh", true)) {
|
|
17815
|
+
startWatcher(session);
|
|
17816
|
+
void refresh(session, false);
|
|
17817
|
+
}
|
|
17818
|
+
}
|
|
17819
|
+
}
|
|
17820
|
+
updateStatus();
|
|
17821
|
+
}));
|
|
17822
|
+
context.subscriptions.push(vscode.workspace.onDidGrantWorkspaceTrust(() => {
|
|
17823
|
+
try {
|
|
17824
|
+
getSession();
|
|
17825
|
+
} catch {
|
|
17826
|
+
}
|
|
17827
|
+
updateStatus();
|
|
17828
|
+
}));
|
|
17829
|
+
context.subscriptions.push({ dispose: disposeSessions });
|
|
17830
|
+
updateStatus();
|
|
17831
|
+
if (vscode.workspace.isTrusted) {
|
|
17832
|
+
try {
|
|
17833
|
+
getSession();
|
|
17834
|
+
} catch {
|
|
17835
|
+
}
|
|
17836
|
+
}
|
|
17125
17837
|
}
|
|
17126
17838
|
function deactivate() {
|
|
17127
17839
|
}
|