@inerrata-corporation/errata 2.0.6-dev.2169 → 2.0.6-dev.2250

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.
Files changed (2) hide show
  1. package/errata.mjs +1082 -203
  2. package/package.json +1 -1
package/errata.mjs CHANGED
@@ -15984,12 +15984,35 @@ var init_project_symbol = __esm({
15984
15984
  });
15985
15985
 
15986
15986
  // ../../packages/shared/src/lockfile.ts
15987
+ function rankDirect(raw2, ecosystem = "npm") {
15988
+ const byName = /* @__PURE__ */ new Map();
15989
+ for (const { name: name2, version: version2 } of raw2) {
15990
+ const prev = byName.get(name2);
15991
+ if (prev) {
15992
+ prev.importers++;
15993
+ continue;
15994
+ }
15995
+ byName.set(name2, {
15996
+ purl: `pkg:${ecosystem}/${name2}@${version2}`,
15997
+ name: name2,
15998
+ version: version2,
15999
+ ecosystem,
16000
+ importers: 1
16001
+ });
16002
+ }
16003
+ return [...byName.values()].sort(
16004
+ (a, b) => b.importers - a.importers || a.name.localeCompare(b.name)
16005
+ );
16006
+ }
15987
16007
  function npmPurl(name2, version2) {
15988
16008
  return `pkg:npm/${name2}@${version2}`;
15989
16009
  }
15990
16010
  function component(name2, version2) {
15991
16011
  return { purl: npmPurl(name2, version2), name: name2, version: version2, ecosystem: "npm" };
15992
16012
  }
16013
+ function isNpmImporterPath(path2) {
16014
+ return path2 === "" || !path2.includes("node_modules/");
16015
+ }
15993
16016
  function parsePackageLockJson(jsonText) {
15994
16017
  let doc;
15995
16018
  try {
@@ -16028,7 +16051,23 @@ function parsePackageLockJson(jsonText) {
16028
16051
  if (dependsOn.length > 0)
16029
16052
  dependencies.push({ ref: npmPurl(self.name, self.version), dependsOn });
16030
16053
  }
16031
- return { components, dependencies: dedupeRefs(dependencies) };
16054
+ const directRaw = [];
16055
+ for (const [path2, meta3] of Object.entries(packages)) {
16056
+ if (!isNpmImporterPath(path2)) continue;
16057
+ for (const section of [meta3.dependencies, meta3.devDependencies, meta3.optionalDependencies]) {
16058
+ if (!section || typeof section !== "object") continue;
16059
+ for (const name2 of Object.keys(section)) {
16060
+ const target = hoisted.get(name2);
16061
+ if (target) directRaw.push({ name: name2, version: target.version });
16062
+ }
16063
+ }
16064
+ }
16065
+ const direct = rankDirect(directRaw);
16066
+ return {
16067
+ components,
16068
+ dependencies: dedupeRefs(dependencies),
16069
+ ...direct.length > 0 ? { direct } : {}
16070
+ };
16032
16071
  }
16033
16072
  function splitPnpmKey(raw2) {
16034
16073
  let k = raw2.trim().replace(/^['"]|['"]$/g, "");
@@ -16043,6 +16082,53 @@ function splitPnpmKey(raw2) {
16043
16082
  if (!name2 || !version2) return null;
16044
16083
  return { name: name2, version: version2 };
16045
16084
  }
16085
+ function parsePnpmImporters(lines) {
16086
+ const DEP_SECTIONS = /* @__PURE__ */ new Set(["dependencies:", "devDependencies:", "optionalDependencies:"]);
16087
+ const raw2 = [];
16088
+ let inImporters = false;
16089
+ let inDepSection = false;
16090
+ let depName = null;
16091
+ for (const line of lines) {
16092
+ if (!line.trim() || line.trimStart().startsWith("#")) continue;
16093
+ const indent = line.length - line.trimStart().length;
16094
+ if (indent === 0) {
16095
+ inImporters = line.trimEnd() === "importers:";
16096
+ inDepSection = false;
16097
+ depName = null;
16098
+ continue;
16099
+ }
16100
+ if (!inImporters) continue;
16101
+ if (indent === 2) {
16102
+ inDepSection = false;
16103
+ depName = null;
16104
+ continue;
16105
+ }
16106
+ if (indent === 4) {
16107
+ inDepSection = DEP_SECTIONS.has(line.trim());
16108
+ depName = null;
16109
+ continue;
16110
+ }
16111
+ if (!inDepSection) continue;
16112
+ if (indent === 6 && line.trimEnd().endsWith(":")) {
16113
+ depName = line.trim().slice(0, -1).replace(/^['"]|['"]$/g, "") || null;
16114
+ continue;
16115
+ }
16116
+ if (indent === 8 && depName) {
16117
+ const t = line.trim();
16118
+ if (!t.startsWith("version:")) continue;
16119
+ let version2 = t.slice("version:".length).trim().replace(/^['"]|['"]$/g, "");
16120
+ const paren = version2.indexOf("(");
16121
+ if (paren !== -1) version2 = version2.slice(0, paren);
16122
+ if (!version2 || version2.startsWith("link:") || version2.startsWith("file:") || version2.includes("://")) {
16123
+ depName = null;
16124
+ continue;
16125
+ }
16126
+ raw2.push({ name: depName, version: version2 });
16127
+ depName = null;
16128
+ }
16129
+ }
16130
+ return rankDirect(raw2);
16131
+ }
16046
16132
  function parsePnpmLock(text) {
16047
16133
  const lines = text.split(/\r?\n/);
16048
16134
  const components = [];
@@ -16104,7 +16190,92 @@ function parsePnpmLock(text) {
16104
16190
  }
16105
16191
  }
16106
16192
  flushDeps();
16107
- return { components, dependencies: dedupeRefs(dependencies) };
16193
+ const direct = parsePnpmImporters(lines);
16194
+ return {
16195
+ components,
16196
+ dependencies: dedupeRefs(dependencies),
16197
+ ...direct.length > 0 ? { direct } : {}
16198
+ };
16199
+ }
16200
+ function parseGemfileLock(text) {
16201
+ const lines = text.split(/\r?\n/);
16202
+ const components = [];
16203
+ const dependencies = [];
16204
+ const seen = /* @__PURE__ */ new Set();
16205
+ const registryVersions = /* @__PURE__ */ new Map();
16206
+ const nonRegistry = /* @__PURE__ */ new Set();
16207
+ const declared = [];
16208
+ let section = null;
16209
+ let inSpecs = false;
16210
+ let currentGem = null;
16211
+ const specLine = /^\s{4}([A-Za-z0-9_.-]+)\s*\(([^)]*)\)\s*$/;
16212
+ const nestedDep = /^\s{6}([A-Za-z0-9_.-]+)/;
16213
+ for (const line of lines) {
16214
+ if (!line.trim()) continue;
16215
+ if (!/^\s/.test(line)) {
16216
+ const header = line.trim();
16217
+ section = header === "GEM" ? "gem" : header === "PATH" || header === "GIT" || header === "PLUGIN SOURCE" ? "path-or-git" : header === "DEPENDENCIES" ? "dependencies" : null;
16218
+ inSpecs = false;
16219
+ currentGem = null;
16220
+ continue;
16221
+ }
16222
+ if (section === "dependencies") {
16223
+ const d = /^\s{2}([A-Za-z0-9_.-]+)(!?)/.exec(line);
16224
+ if (d?.[1] && d[2] !== "!") declared.push(d[1]);
16225
+ continue;
16226
+ }
16227
+ if (!section) continue;
16228
+ if (/^\s{2}specs:\s*$/.test(line)) {
16229
+ inSpecs = true;
16230
+ currentGem = null;
16231
+ continue;
16232
+ }
16233
+ if (/^\s{2}\S/.test(line)) {
16234
+ inSpecs = false;
16235
+ currentGem = null;
16236
+ continue;
16237
+ }
16238
+ if (!inSpecs) continue;
16239
+ const spec = specLine.exec(line);
16240
+ if (spec) {
16241
+ const name2 = spec[1];
16242
+ const version2 = (spec[2] ?? "").trim();
16243
+ if (section === "path-or-git") {
16244
+ nonRegistry.add(name2);
16245
+ currentGem = null;
16246
+ continue;
16247
+ }
16248
+ if (!version2) continue;
16249
+ currentGem = { name: name2, version: version2 };
16250
+ registryVersions.set(name2, version2);
16251
+ const purl = `pkg:gem/${name2}@${version2}`;
16252
+ if (!seen.has(purl)) {
16253
+ seen.add(purl);
16254
+ components.push({ purl, name: name2, version: version2, ecosystem: "gem" });
16255
+ }
16256
+ continue;
16257
+ }
16258
+ const nested = nestedDep.exec(line);
16259
+ if (nested?.[1] && currentGem) {
16260
+ dependencies.push({
16261
+ ref: `pkg:gem/${currentGem.name}@${currentGem.version}`,
16262
+ dependsOn: [nested[1]]
16263
+ });
16264
+ }
16265
+ }
16266
+ const resolved = dependencies.map((d) => ({
16267
+ ref: d.ref,
16268
+ dependsOn: d.dependsOn.filter((n) => !nonRegistry.has(n) && registryVersions.has(n)).map((n) => `pkg:gem/${n}@${registryVersions.get(n)}`)
16269
+ })).filter((d) => d.dependsOn.length > 0);
16270
+ const direct = rankDirect(
16271
+ declared.filter((n) => !nonRegistry.has(n) && registryVersions.has(n)).map((n) => ({ name: n, version: registryVersions.get(n) })),
16272
+ "gem"
16273
+ );
16274
+ return {
16275
+ components,
16276
+ dependencies: dedupeRefs(resolved),
16277
+ ...direct.length > 0 ? { direct } : {}
16278
+ };
16108
16279
  }
16109
16280
  function dedupeRefs(deps) {
16110
16281
  const byRef = /* @__PURE__ */ new Map();
@@ -16237,6 +16408,86 @@ function parseCargo(path2, text) {
16237
16408
  }
16238
16409
  return deps;
16239
16410
  }
16411
+ function mavenName(groupId, artifactId) {
16412
+ return `${groupId.trim()}:${artifactId.trim()}`;
16413
+ }
16414
+ function parsePom(path2, text) {
16415
+ const deps = [];
16416
+ const coord = (block) => {
16417
+ const g = /<groupId>([^<]+)<\/groupId>/.exec(block)?.[1];
16418
+ const a = /<artifactId>([^<]+)<\/artifactId>/.exec(block)?.[1];
16419
+ if (!g || !a) return null;
16420
+ return { g, a, v: /<version>([^<]+)<\/version>/.exec(block)?.[1]?.trim() ?? null };
16421
+ };
16422
+ for (const m of text.matchAll(/<dependency>([\s\S]*?)<\/dependency>/g)) {
16423
+ const c = coord(m[1] ?? "");
16424
+ if (c) deps.push({ ecosystem: "maven", name: mavenName(c.g, c.a), version: c.v, kind: "package", manifest: path2 });
16425
+ }
16426
+ for (const m of text.matchAll(/<parent>([\s\S]*?)<\/parent>/g)) {
16427
+ const c = coord(m[1] ?? "");
16428
+ if (c) deps.push({ ecosystem: "maven", name: mavenName(c.g, c.a), version: c.v, kind: "sdk", manifest: path2 });
16429
+ }
16430
+ return deps;
16431
+ }
16432
+ function parseGradle(path2, text) {
16433
+ const deps = [];
16434
+ const re = new RegExp(`\\b(?:${GRADLE_CONFIGS})\\s*(?:\\(\\s*)?["']([^"']+)["']`, "g");
16435
+ for (const m of text.matchAll(re)) {
16436
+ const parts2 = (m[1] ?? "").split(":");
16437
+ const [group, artifact, version2] = parts2;
16438
+ if (!group || !artifact || parts2.length < 2) continue;
16439
+ deps.push({
16440
+ ecosystem: "maven",
16441
+ name: mavenName(group, artifact),
16442
+ version: version2?.trim() || null,
16443
+ kind: "package",
16444
+ manifest: path2
16445
+ });
16446
+ }
16447
+ return deps;
16448
+ }
16449
+ function parseVersionCatalog(path2, text) {
16450
+ const section = /^\s*\[libraries\]([\s\S]*?)(?=^\s*\[|(?![\s\S]))/m.exec(text);
16451
+ if (!section) return [];
16452
+ const deps = [];
16453
+ for (const line of (section[1] ?? "").split(/\r?\n/)) {
16454
+ if (!line.trim() || line.trimStart().startsWith("#")) continue;
16455
+ const module2 = /module\s*=\s*["']([^"']+)["']/.exec(line)?.[1];
16456
+ const version2 = /version(?:\.ref)?\s*=\s*["']([^"']+)["']/.exec(line)?.[1] ?? null;
16457
+ if (module2) {
16458
+ const [group2, artifact2] = module2.split(":");
16459
+ if (group2 && artifact2) {
16460
+ deps.push({ ecosystem: "maven", name: mavenName(group2, artifact2), version: version2, kind: "package", manifest: path2 });
16461
+ }
16462
+ continue;
16463
+ }
16464
+ const group = /\bgroup\s*=\s*["']([^"']+)["']/.exec(line)?.[1];
16465
+ const artifact = /\bname\s*=\s*["']([^"']+)["']/.exec(line)?.[1];
16466
+ if (group && artifact) {
16467
+ deps.push({ ecosystem: "maven", name: mavenName(group, artifact), version: version2, kind: "package", manifest: path2 });
16468
+ }
16469
+ }
16470
+ return deps;
16471
+ }
16472
+ function parseGemfile(path2, text) {
16473
+ const deps = [];
16474
+ for (const raw2 of text.split(/\r?\n/)) {
16475
+ const line = (raw2.split("#", 1)[0] ?? "").trim();
16476
+ const m = /^gem\s+["']([^"']+)["']\s*(?:,\s*["']([^"']+)["'])?/.exec(line);
16477
+ if (!m?.[1]) continue;
16478
+ deps.push({ ecosystem: "gem", name: m[1], version: m[2] ?? null, kind: "package", manifest: path2 });
16479
+ }
16480
+ return deps;
16481
+ }
16482
+ function parseGemspec(path2, text) {
16483
+ const deps = [];
16484
+ for (const m of text.matchAll(
16485
+ /\.add_(?:runtime_|development_)?dependency\s*\(?\s*["']([^"']+)["']\s*(?:,\s*["']([^"']+)["'])?/g
16486
+ )) {
16487
+ if (m[1]) deps.push({ ecosystem: "gem", name: m[1], version: m[2] ?? null, kind: "package", manifest: path2 });
16488
+ }
16489
+ return deps;
16490
+ }
16240
16491
  function parseManifest(path2, text) {
16241
16492
  const name2 = basename(path2);
16242
16493
  if (name2.endsWith(".csproj") || name2.endsWith(".fsproj")) return parseCsproj(path2, text);
@@ -16248,12 +16499,17 @@ function parseManifest(path2, text) {
16248
16499
  return parseDocker(path2, text);
16249
16500
  }
16250
16501
  if (name2 === "go.mod") return parseGoMod(path2, text);
16502
+ if (name2 === "libs.versions.toml") return parseVersionCatalog(path2, text);
16251
16503
  if (name2 === "Cargo.toml") return parseCargo(path2, text);
16504
+ if (name2 === "pom.xml") return parsePom(path2, text);
16505
+ if (name2 === "build.gradle" || name2 === "build.gradle.kts") return parseGradle(path2, text);
16506
+ if (name2 === "Gemfile") return parseGemfile(path2, text);
16507
+ if (name2.endsWith(".gemspec")) return parseGemspec(path2, text);
16252
16508
  return [];
16253
16509
  }
16254
- function buildSpine(sha2, manifestPaths, readText) {
16510
+ function buildSpine(sha2, manifestPaths2, readText) {
16255
16511
  const manifests = {};
16256
- for (const p of manifestPaths) {
16512
+ for (const p of manifestPaths2) {
16257
16513
  const deps = parseManifest(p, readText(p));
16258
16514
  if (deps.length > 0) manifests[p] = deps;
16259
16515
  }
@@ -16298,11 +16554,22 @@ function depsForUnit(spine, touched, readParentText) {
16298
16554
  for (const purl of declared.keys()) context.delete(purl);
16299
16555
  return { declared: [...declared.values()], context: [...context.values()] };
16300
16556
  }
16301
- var ECOSYSTEM_LANGUAGE, TOOL_KINDS, MANIFEST_PATH_RE, LOCAL_IMAGE_RE, PACKAGE_JSON_SECTIONS;
16557
+ var ECOSYSTEM_SYSTEM, ECOSYSTEM_LANGUAGE, TOOL_KINDS, MANIFEST_PATH_RE, LOCAL_IMAGE_RE, PACKAGE_JSON_SECTIONS, GRADLE_CONFIGS;
16302
16558
  var init_manifests = __esm({
16303
16559
  "../../packages/shared/src/manifests.ts"() {
16304
16560
  "use strict";
16305
16561
  init_identity();
16562
+ ECOSYSTEM_SYSTEM = {
16563
+ npm: "npm",
16564
+ pypi: "pypi",
16565
+ cargo: "cargo",
16566
+ go: "go",
16567
+ golang: "go",
16568
+ maven: "maven",
16569
+ nuget: "nuget",
16570
+ gem: "rubygems",
16571
+ rubygems: "rubygems"
16572
+ };
16306
16573
  ECOSYSTEM_LANGUAGE = {
16307
16574
  npm: "JavaScript",
16308
16575
  pypi: "Python",
@@ -16315,9 +16582,10 @@ var init_manifests = __esm({
16315
16582
  rubygems: "Ruby"
16316
16583
  };
16317
16584
  TOOL_KINDS = ["engine", "runtime"];
16318
- MANIFEST_PATH_RE = /(^|\/)(?:[^/]+\.csproj|[^/]+\.fsproj|project\.godot|package\.json|requirements[^/]*\.txt|pyproject\.toml|docker-compose[^/]*\.ya?ml|compose[^/]*\.ya?ml|Dockerfile(?:\.[^/]+)?|go\.mod|Cargo\.toml)$/;
16585
+ MANIFEST_PATH_RE = /(^|\/)(?:[^/]+\.csproj|[^/]+\.fsproj|project\.godot|package\.json|requirements[^/]*\.txt|pyproject\.toml|docker-compose[^/]*\.ya?ml|compose[^/]*\.ya?ml|Dockerfile(?:\.[^/]+)?|go\.mod|Cargo\.toml|pom\.xml|build\.gradle(?:\.kts)?|libs\.versions\.toml|Gemfile|[^/]+\.gemspec)$/;
16319
16586
  LOCAL_IMAGE_RE = /^(openbane|local)[/-]|:local$/;
16320
16587
  PACKAGE_JSON_SECTIONS = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"];
16588
+ GRADLE_CONFIGS = "implementation|api|compileOnly|compileOnlyApi|runtimeOnly|testImplementation|testCompileOnly|testRuntimeOnly|annotationProcessor|kapt|ksp|classpath|developmentOnly";
16321
16589
  }
16322
16590
  });
16323
16591
 
@@ -16377,6 +16645,7 @@ __export(src_exports, {
16377
16645
  DECOMPOSITION_EDGES: () => DECOMPOSITION_EDGES,
16378
16646
  DRIFT_KIND: () => DRIFT_KIND,
16379
16647
  ECOSYSTEM_LANGUAGE: () => ECOSYSTEM_LANGUAGE,
16648
+ ECOSYSTEM_SYSTEM: () => ECOSYSTEM_SYSTEM,
16380
16649
  EDGE_CONDUCTANCE_OVERRIDES: () => EDGE_CONDUCTANCE_OVERRIDES,
16381
16650
  EDGE_RULES: () => EDGE_RULES,
16382
16651
  EDGE_WEIGHT: () => EDGE_WEIGHT,
@@ -16466,6 +16735,7 @@ __export(src_exports, {
16466
16735
  osNameForPlatform: () => osNameForPlatform,
16467
16736
  packageCanonicalId: () => packageCanonicalId,
16468
16737
  pagerankEdgeTypes: () => pagerankEdgeTypes,
16738
+ parseGemfileLock: () => parseGemfileLock,
16469
16739
  parseManifest: () => parseManifest,
16470
16740
  parsePackageLockJson: () => parsePackageLockJson,
16471
16741
  parsePackageRef: () => parsePackageRef,
@@ -24738,6 +25008,19 @@ function provenanceHeaders(provenance) {
24738
25008
  ...provenance.agentModel ? { "x-inerrata-agent-model": provenance.agentModel } : {}
24739
25009
  };
24740
25010
  }
25011
+ function parseRestErrorEnvelope(text) {
25012
+ if (!text.trimStart().startsWith("{")) return null;
25013
+ try {
25014
+ const body2 = JSON.parse(text);
25015
+ const error48 = body2?.error;
25016
+ if (!error48 || typeof error48 !== "object") return null;
25017
+ const { code, message: message2 } = error48;
25018
+ if (typeof code !== "string" || !code) return null;
25019
+ return { code, message: typeof message2 === "string" && message2 ? message2 : code };
25020
+ } catch {
25021
+ return null;
25022
+ }
25023
+ }
24741
25024
  var asWireCount, INGEST_NODE_CHUNK, E6B_PUBLIC_CONTEXT_SENTINEL, CloudClient, CloudError;
24742
25025
  var init_client = __esm({
24743
25026
  "../../packages/cloud-client/src/client.ts"() {
@@ -25368,9 +25651,11 @@ var init_client = __esm({
25368
25651
  });
25369
25652
  if (!res.ok) {
25370
25653
  const text = await res.text();
25654
+ const envelope = parseRestErrorEnvelope(text);
25371
25655
  throw new CloudError(
25372
- `${method} ${path2} failed: HTTP ${res.status} ${text.slice(0, 200)}`,
25373
- res.status
25656
+ `${method} ${path2} failed: HTTP ${res.status} ${envelope?.message ?? text.slice(0, 200)}`,
25657
+ res.status,
25658
+ envelope?.code
25374
25659
  );
25375
25660
  }
25376
25661
  return await res.json();
@@ -25381,10 +25666,15 @@ var init_client = __esm({
25381
25666
  };
25382
25667
  CloudError = class extends Error {
25383
25668
  status;
25384
- constructor(message2, status) {
25669
+ /** The server's machine-readable error code, when the body carried a REST
25670
+ * error envelope. Callers branch on this rather than regexing the message —
25671
+ * e.g. `installation_revoked` means reconnect, not re-issue the key. */
25672
+ code;
25673
+ constructor(message2, status, code) {
25385
25674
  super(message2);
25386
25675
  this.name = "CloudError";
25387
25676
  this.status = status;
25677
+ this.code = code ?? null;
25388
25678
  }
25389
25679
  };
25390
25680
  }
@@ -51196,16 +51486,16 @@ __export(witness_ledger_exports, {
51196
51486
  summarizeWitnessLedger: () => summarizeWitnessLedger,
51197
51487
  witnessLedgerPath: () => witnessLedgerPath
51198
51488
  });
51199
- import { appendFileSync as appendFileSync3, existsSync as existsSync23, readFileSync as readFileSync23, writeFileSync as writeFileSync19 } from "node:fs";
51200
- import { join as join28 } from "node:path";
51489
+ import { appendFileSync as appendFileSync3, existsSync as existsSync24, readFileSync as readFileSync24, writeFileSync as writeFileSync19 } from "node:fs";
51490
+ import { join as join29 } from "node:path";
51201
51491
  function witnessLedgerPath(configDir) {
51202
- return join28(configDir, "witness-ledger.jsonl");
51492
+ return join29(configDir, "witness-ledger.jsonl");
51203
51493
  }
51204
51494
  function appendWitnessLedger(configDir, entry) {
51205
51495
  const path2 = witnessLedgerPath(configDir);
51206
51496
  try {
51207
51497
  appendFileSync3(path2, JSON.stringify(entry) + "\n");
51208
- const lines = readFileSync23(path2, "utf8").split("\n").filter(Boolean);
51498
+ const lines = readFileSync24(path2, "utf8").split("\n").filter(Boolean);
51209
51499
  if (lines.length > LEDGER_MAX_LINES) {
51210
51500
  writeFileSync19(path2, lines.slice(-Math.floor(LEDGER_MAX_LINES / 2)).join("\n") + "\n");
51211
51501
  }
@@ -51214,9 +51504,9 @@ function appendWitnessLedger(configDir, entry) {
51214
51504
  }
51215
51505
  function readWitnessLedger(configDir) {
51216
51506
  const path2 = witnessLedgerPath(configDir);
51217
- if (!existsSync23(path2)) return [];
51507
+ if (!existsSync24(path2)) return [];
51218
51508
  try {
51219
- return readFileSync23(path2, "utf8").split("\n").filter(Boolean).map((l) => JSON.parse(l)).filter((e) => typeof e.ts === "number" && typeof e.channel === "string");
51509
+ return readFileSync24(path2, "utf8").split("\n").filter(Boolean).map((l) => JSON.parse(l)).filter((e) => typeof e.ts === "number" && typeof e.channel === "string");
51220
51510
  } catch {
51221
51511
  return [];
51222
51512
  }
@@ -70433,12 +70723,12 @@ var init_report_render = __esm({
70433
70723
 
70434
70724
  // src/cli.ts
70435
70725
  init_src6();
70436
- import { closeSync as closeSync2, existsSync as existsSync32, openSync as openSync2, readFileSync as readFileSync31, renameSync as renameSync4, statSync as statSync7 } from "node:fs";
70437
- import { join as join36, resolve as pathResolve } from "node:path";
70726
+ import { closeSync as closeSync2, existsSync as existsSync33, openSync as openSync2, readFileSync as readFileSync32, renameSync as renameSync4, statSync as statSync8 } from "node:fs";
70727
+ import { join as join37, resolve as pathResolve } from "node:path";
70438
70728
  import { spawn as spawn3 } from "node:child_process";
70439
70729
 
70440
70730
  // src/daemon.ts
70441
- import { existsSync as existsSync25, writeFileSync as writeFileSync21 } from "node:fs";
70731
+ import { existsSync as existsSync26, writeFileSync as writeFileSync21 } from "node:fs";
70442
70732
 
70443
70733
  // ../../node_modules/.pnpm/@hono+node-server@1.19.11_hono@4.12.8/node_modules/@hono/node-server/dist/index.mjs
70444
70734
  import { createServer as createServerHTTP } from "http";
@@ -71017,9 +71307,9 @@ init_webui();
71017
71307
  init_config();
71018
71308
 
71019
71309
  // src/engine.ts
71020
- import { execFileSync as execFileSync3 } from "node:child_process";
71021
- import { existsSync as existsSync24, statSync as statSync6, appendFileSync as appendFileSync4, readdirSync as readdirSync10, renameSync as renameSync3, readFileSync as readFileSync24, writeFileSync as writeFileSync20 } from "node:fs";
71022
- import { join as join29, relative as relative6, sep as sep4 } from "node:path";
71310
+ import { execFileSync as execFileSync4 } from "node:child_process";
71311
+ import { existsSync as existsSync25, statSync as statSync7, appendFileSync as appendFileSync4, readdirSync as readdirSync10, renameSync as renameSync3, readFileSync as readFileSync25, writeFileSync as writeFileSync20 } from "node:fs";
71312
+ import { join as join30, relative as relative6, sep as sep4 } from "node:path";
71023
71313
 
71024
71314
  // ../../node_modules/.pnpm/chokidar@4.0.3/node_modules/chokidar/esm/index.js
71025
71315
  import { stat as statcb } from "fs";
@@ -75714,23 +76004,594 @@ async function pullCloudTriage(shared, cloud, profile, limit = 50) {
75714
76004
  return merged;
75715
76005
  }
75716
76006
 
75717
- // src/git-sensor.ts
75718
- import { existsSync as existsSync19, readFileSync as readFileSync18, watch as fsWatch } from "node:fs";
76007
+ // src/retrieval-stack.ts
76008
+ init_src();
76009
+ import { execFileSync as execFileSync3 } from "node:child_process";
76010
+ import { existsSync as existsSync19, readFileSync as readFileSync18, statSync as statSync6 } from "node:fs";
76011
+ import { homedir as homedir6 } from "node:os";
75719
76012
  import { join as join23 } from "node:path";
76013
+ var RETRIEVAL_STACK_CAP = 24;
76014
+ var MANIFEST_SCAN_CAP = 400;
76015
+ var RUNTIME_TOKENS = /* @__PURE__ */ new Set([
76016
+ "node",
76017
+ "deno",
76018
+ "bun",
76019
+ "python",
76020
+ "go",
76021
+ "rust",
76022
+ "java",
76023
+ "ruby",
76024
+ "php",
76025
+ "dotnet",
76026
+ "godot"
76027
+ ]);
76028
+ var RUNTIME_KINDS = /* @__PURE__ */ new Set(["runtime", "engine"]);
76029
+ var KIND_WEIGHT = { package: 1, sdk: 0.9, image: 0.5 };
76030
+ var PUBLIC_NPM_HOSTS = /* @__PURE__ */ new Set(["registry.npmjs.org", "registry.yarnpkg.com"]);
76031
+ var PUBLIC_PYPI_HOSTS = /* @__PURE__ */ new Set(["pypi.org", "files.pythonhosted.org", "pypi.python.org"]);
76032
+ var PUBLIC_NUGET_HOSTS = /* @__PURE__ */ new Set(["api.nuget.org", "www.nuget.org", "nuget.org"]);
76033
+ var PUBLIC_GEM_HOSTS = /* @__PURE__ */ new Set(["rubygems.org", "index.rubygems.org"]);
76034
+ var PUBLIC_MAVEN_HOSTS = /* @__PURE__ */ new Set([
76035
+ "repo.maven.apache.org",
76036
+ "repo1.maven.org",
76037
+ "central.sonatype.com",
76038
+ "oss.sonatype.org",
76039
+ "dl.google.com",
76040
+ "maven.google.com",
76041
+ "plugins.gradle.org"
76042
+ ]);
76043
+ var PUBLIC_GO_HOSTS = /* @__PURE__ */ new Set([
76044
+ "github.com",
76045
+ "gitlab.com",
76046
+ "bitbucket.org",
76047
+ "golang.org",
76048
+ "google.golang.org",
76049
+ "cloud.google.com",
76050
+ "gopkg.in",
76051
+ "go.uber.org",
76052
+ "go.opentelemetry.io",
76053
+ "k8s.io",
76054
+ "sigs.k8s.io",
76055
+ "gotest.tools",
76056
+ "gonum.org",
76057
+ "modernc.org",
76058
+ "rsc.io",
76059
+ "honnef.co"
76060
+ ]);
76061
+ var PUBLIC_REGISTRY_POLICY = {
76062
+ blockedEcosystems: /* @__PURE__ */ new Set(),
76063
+ npmPrivateScopes: /* @__PURE__ */ new Set(),
76064
+ goPrivatePatterns: [],
76065
+ privateGemNames: /* @__PURE__ */ new Set(),
76066
+ selfTokens: []
76067
+ };
76068
+ function hostOf(value) {
76069
+ try {
76070
+ return new URL(value.trim()).hostname.toLowerCase();
76071
+ } catch {
76072
+ return null;
76073
+ }
76074
+ }
76075
+ function urlIsPublic(value, publicHosts) {
76076
+ const host = hostOf(value);
76077
+ return host !== null && publicHosts.has(host);
76078
+ }
76079
+ var unquote = (s) => s.trim().replace(/^['"]|['"]$/g, "");
76080
+ function parseNpmrcPolicy(texts) {
76081
+ let defaultPublic = null;
76082
+ const privateScopes = /* @__PURE__ */ new Set();
76083
+ const decidedScopes = /* @__PURE__ */ new Set();
76084
+ for (const text of texts) {
76085
+ for (const rawLine of text.split(/\r?\n/)) {
76086
+ const line = rawLine.trim();
76087
+ if (!line || line.startsWith("#") || line.startsWith(";")) continue;
76088
+ const eq = line.indexOf("=");
76089
+ if (eq === -1) continue;
76090
+ const key = line.slice(0, eq).trim().toLowerCase();
76091
+ const value = line.slice(eq + 1).trim();
76092
+ if (key === "registry") {
76093
+ if (defaultPublic === null) defaultPublic = urlIsPublic(value, PUBLIC_NPM_HOSTS);
76094
+ continue;
76095
+ }
76096
+ const scoped = /^(@[^:]+):registry$/.exec(key);
76097
+ if (!scoped) continue;
76098
+ const scope = (scoped[1] ?? "").toLowerCase();
76099
+ if (decidedScopes.has(scope)) continue;
76100
+ decidedScopes.add(scope);
76101
+ if (!urlIsPublic(value, PUBLIC_NPM_HOSTS)) privateScopes.add(scope);
76102
+ }
76103
+ }
76104
+ return { defaultPublic: defaultPublic ?? true, privateScopes };
76105
+ }
76106
+ function pypiIndexIsPrivate(texts) {
76107
+ for (const text of texts) {
76108
+ if (/^\s*\[\[?\s*tool\.(poetry\.source|uv\.index)\s*\]\]?/m.test(text)) {
76109
+ const urls = [...text.matchAll(/^\s*url\s*=\s*(.+)$/gm)].map((m) => unquote(m[1] ?? ""));
76110
+ if (urls.length === 0 || urls.some((u) => !urlIsPublic(u, PUBLIC_PYPI_HOSTS))) return true;
76111
+ }
76112
+ for (const m of text.matchAll(/^\s*(?:-i\b|--?(?:extra-)?index-url)\s*[=:]?\s*(\S+)/gm)) {
76113
+ if (!urlIsPublic(unquote(m[1] ?? ""), PUBLIC_PYPI_HOSTS)) return true;
76114
+ }
76115
+ for (const m of text.matchAll(/^\s*(?:extra-)?index-url\s*=\s*(\S+)/gm)) {
76116
+ if (!urlIsPublic(unquote(m[1] ?? ""), PUBLIC_PYPI_HOSTS)) return true;
76117
+ }
76118
+ }
76119
+ return false;
76120
+ }
76121
+ function cargoRegistryIsPrivate(texts) {
76122
+ return texts.some(
76123
+ (t) => /^\s*\[registries(\.|\])/m.test(t) || /^\s*replace-with\s*=/m.test(t)
76124
+ );
76125
+ }
76126
+ function nugetSourcesArePrivate(texts) {
76127
+ for (const text of texts) {
76128
+ const block = /<packageSources>([\s\S]*?)<\/packageSources>/i.exec(text);
76129
+ if (!block) continue;
76130
+ for (const m of (block[1] ?? "").matchAll(/<add\b[^>]*\bvalue\s*=\s*"([^"]+)"/gi)) {
76131
+ if (!urlIsPublic(m[1] ?? "", PUBLIC_NUGET_HOSTS)) return true;
76132
+ }
76133
+ }
76134
+ return false;
76135
+ }
76136
+ function parseGoPrivate(values) {
76137
+ return values.flatMap((v) => (v ?? "").split(",")).map((s) => s.trim()).filter(Boolean);
76138
+ }
76139
+ function goPrivateMatches(patterns, modulePath) {
76140
+ if (patterns.length === 0) return false;
76141
+ const parts2 = modulePath.split("/");
76142
+ const prefixes = parts2.map((_, i2) => parts2.slice(0, i2 + 1).join("/"));
76143
+ return patterns.some((pattern) => {
76144
+ const rx = new RegExp(
76145
+ "^" + pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*") + "$"
76146
+ );
76147
+ return prefixes.some((p) => rx.test(p));
76148
+ });
76149
+ }
76150
+ var OFFICIAL_DOCKER_IMAGES = /* @__PURE__ */ new Set([
76151
+ "alpine",
76152
+ "busybox",
76153
+ "debian",
76154
+ "ubuntu",
76155
+ "fedora",
76156
+ "rockylinux",
76157
+ "postgres",
76158
+ "mysql",
76159
+ "mariadb",
76160
+ "mongo",
76161
+ "redis",
76162
+ "memcached",
76163
+ "cassandra",
76164
+ "couchdb",
76165
+ "influxdb",
76166
+ "neo4j",
76167
+ "elasticsearch",
76168
+ "rabbitmq",
76169
+ "nats",
76170
+ "kafka",
76171
+ "zookeeper",
76172
+ "consul",
76173
+ "vault",
76174
+ "etcd",
76175
+ "minio",
76176
+ "clickhouse",
76177
+ "nginx",
76178
+ "httpd",
76179
+ "haproxy",
76180
+ "traefik",
76181
+ "caddy",
76182
+ "varnish",
76183
+ "node",
76184
+ "python",
76185
+ "golang",
76186
+ "rust",
76187
+ "ruby",
76188
+ "php",
76189
+ "openjdk",
76190
+ "eclipse-temurin",
76191
+ "gradle",
76192
+ "maven",
76193
+ "composer",
76194
+ "perl",
76195
+ "erlang",
76196
+ "elixir",
76197
+ "haskell",
76198
+ "docker",
76199
+ "registry",
76200
+ "grafana",
76201
+ "prometheus",
76202
+ "telegraf",
76203
+ "jenkins",
76204
+ "sonarqube",
76205
+ "wordpress",
76206
+ "drupal",
76207
+ "ghost",
76208
+ "nextcloud",
76209
+ "gitlab",
76210
+ "gitea",
76211
+ "sentry",
76212
+ "hello-world",
76213
+ "selenium",
76214
+ "playwright",
76215
+ "ollama"
76216
+ ]);
76217
+ function dockerImageIsPublicOfficial(name2) {
76218
+ const n = name2.trim().toLowerCase();
76219
+ if (!n || n.includes("/") || n.includes(":") || n.includes("@")) return false;
76220
+ return OFFICIAL_DOCKER_IMAGES.has(n);
76221
+ }
76222
+ function mavenReposArePrivate(texts) {
76223
+ for (const text of texts) {
76224
+ if (/<servers>[\s\S]*?<server>/i.test(text)) return true;
76225
+ for (const m of text.matchAll(/<(?:repository|pluginRepository|mirror)\b[\s\S]*?<\/(?:repository|pluginRepository|mirror)>/gi)) {
76226
+ const url2 = /<url>([^<]+)<\/url>/i.exec(m[0])?.[1];
76227
+ if (!url2 || !urlIsPublic(url2, PUBLIC_MAVEN_HOSTS)) return true;
76228
+ }
76229
+ }
76230
+ return false;
76231
+ }
76232
+ function gemSourceIsPrivate(texts) {
76233
+ for (const text of texts) {
76234
+ for (const m of text.matchAll(/^\s*source\s+["']([^"']+)["']/gm)) {
76235
+ if (!urlIsPublic(m[1] ?? "", PUBLIC_GEM_HOSTS)) return true;
76236
+ }
76237
+ }
76238
+ return false;
76239
+ }
76240
+ function privateGemNamesIn(texts) {
76241
+ const names = /* @__PURE__ */ new Set();
76242
+ for (const text of texts) {
76243
+ for (const raw2 of text.split(/\r?\n/)) {
76244
+ const line = (raw2.split("#", 1)[0] ?? "").trim();
76245
+ const m = /^gem\s+["']([^"']+)["']/.exec(line);
76246
+ if (!m?.[1]) continue;
76247
+ if (/(?::(?:git|path|github|gist|bitbucket)\s*=>|\b(?:git|path|github|gist|bitbucket):\s)/.test(line)) {
76248
+ names.add(m[1]);
76249
+ }
76250
+ }
76251
+ }
76252
+ return names;
76253
+ }
76254
+ function selfTokensFromLocator(repoLocator) {
76255
+ if (!repoLocator) return [];
76256
+ const segments = repoLocator.toLowerCase().split("/").slice(1).filter(Boolean);
76257
+ return [...new Set(segments.filter((s) => s.length >= 3))];
76258
+ }
76259
+ function mavenGroupIsSelfDisclosing(name2, selfTokens) {
76260
+ if (selfTokens.length === 0) return false;
76261
+ const group = (name2.split(":")[0] ?? "").toLowerCase();
76262
+ const parts2 = group.split(".");
76263
+ return selfTokens.some((t) => parts2.includes(t));
76264
+ }
76265
+ function loadRegistryPolicy(root, env2 = process.env, repoLocator) {
76266
+ const read2 = (p) => {
76267
+ try {
76268
+ return readFileSync18(p, "utf8");
76269
+ } catch {
76270
+ return null;
76271
+ }
76272
+ };
76273
+ const texts = (...paths) => paths.map(read2).filter((t) => t !== null);
76274
+ const home = homedir6();
76275
+ const npm = parseNpmrcPolicy(texts(join23(root, ".npmrc"), join23(home, ".npmrc")));
76276
+ const blocked = /* @__PURE__ */ new Set();
76277
+ if (!npm.defaultPublic) blocked.add("npm");
76278
+ if (pypiIndexIsPrivate(
76279
+ texts(
76280
+ join23(root, "pip.conf"),
76281
+ join23(root, "pip.ini"),
76282
+ join23(root, "pyproject.toml"),
76283
+ join23(root, "requirements.txt"),
76284
+ join23(home, ".pip", "pip.conf"),
76285
+ join23(home, ".config", "pip", "pip.conf"),
76286
+ join23(env2["APPDATA"] ?? home, "pip", "pip.ini")
76287
+ )
76288
+ )) {
76289
+ blocked.add("pypi");
76290
+ }
76291
+ if (cargoRegistryIsPrivate(
76292
+ texts(
76293
+ join23(root, ".cargo", "config.toml"),
76294
+ join23(root, ".cargo", "config"),
76295
+ join23(home, ".cargo", "config.toml"),
76296
+ join23(home, ".cargo", "config")
76297
+ )
76298
+ )) {
76299
+ blocked.add("cargo");
76300
+ }
76301
+ if (nugetSourcesArePrivate(
76302
+ texts(
76303
+ join23(root, "NuGet.config"),
76304
+ join23(root, "nuget.config"),
76305
+ join23(root, "NuGet.Config"),
76306
+ join23(env2["APPDATA"] ?? home, "NuGet", "NuGet.Config"),
76307
+ join23(home, ".nuget", "NuGet", "NuGet.Config")
76308
+ )
76309
+ )) {
76310
+ blocked.add("nuget");
76311
+ }
76312
+ const goEnvFile = env2["GOENV"] ?? join23(env2["APPDATA"] ?? join23(home, ".config"), "go", "env");
76313
+ const goEnvText = read2(goEnvFile) ?? "";
76314
+ const fromFile = ["GOPRIVATE", "GONOSUMDB", "GONOSUMCHECK"].map(
76315
+ (k) => new RegExp(`^${k}=(.*)$`, "m").exec(goEnvText)?.[1]
76316
+ );
76317
+ const goPrivatePatterns = parseGoPrivate([
76318
+ env2["GOPRIVATE"],
76319
+ env2["GONOSUMDB"],
76320
+ env2["GONOSUMCHECK"],
76321
+ ...fromFile
76322
+ ]);
76323
+ const gemfiles = texts(join23(root, "Gemfile"));
76324
+ if (gemSourceIsPrivate(gemfiles)) blocked.add("gem");
76325
+ if (mavenReposArePrivate(
76326
+ texts(join23(root, "pom.xml"), join23(home, ".m2", "settings.xml"))
76327
+ )) {
76328
+ blocked.add("maven");
76329
+ }
76330
+ return {
76331
+ blockedEcosystems: blocked,
76332
+ npmPrivateScopes: npm.privateScopes,
76333
+ goPrivatePatterns,
76334
+ privateGemNames: privateGemNamesIn(gemfiles),
76335
+ selfTokens: selfTokensFromLocator(repoLocator)
76336
+ };
76337
+ }
76338
+ function npmScopeOf(name2) {
76339
+ if (!name2.startsWith("@")) return null;
76340
+ const slash = name2.indexOf("/");
76341
+ return slash === -1 ? null : name2.slice(0, slash).toLowerCase();
76342
+ }
76343
+ function isPublicDep(dep, policy) {
76344
+ const ecosystem = dep.ecosystem.toLowerCase();
76345
+ if (policy.blockedEcosystems.has(ecosystem)) return false;
76346
+ switch (ecosystem) {
76347
+ case "npm": {
76348
+ const scope = npmScopeOf(dep.name);
76349
+ return scope === null || !policy.npmPrivateScopes.has(scope);
76350
+ }
76351
+ case "pypi":
76352
+ case "cargo":
76353
+ return true;
76354
+ case "nuget":
76355
+ return true;
76356
+ case "maven":
76357
+ return !mavenGroupIsSelfDisclosing(dep.name, policy.selfTokens);
76358
+ case "gem":
76359
+ case "rubygems":
76360
+ return !policy.privateGemNames.has(dep.name);
76361
+ case "go":
76362
+ case "golang": {
76363
+ if (goPrivateMatches(policy.goPrivatePatterns, dep.name)) return false;
76364
+ const host = dep.name.split("/")[0]?.toLowerCase() ?? "";
76365
+ return PUBLIC_GO_HOSTS.has(host);
76366
+ }
76367
+ case "docker":
76368
+ return dockerImageIsPublicOfficial(dep.name);
76369
+ default:
76370
+ return false;
76371
+ }
76372
+ }
76373
+ function normStackToken(raw2) {
76374
+ return raw2.trim().toLowerCase().replace(/(?!^)[@\s].*$/, "");
76375
+ }
76376
+ function normStackTokens(xs) {
76377
+ return (xs ?? []).map(normStackToken).filter(Boolean);
76378
+ }
76379
+ function isRuntimeToken(token) {
76380
+ return RUNTIME_TOKENS.has(token);
76381
+ }
76382
+ function rankCandidates(cs) {
76383
+ return [...cs].sort((a, b) => b.weight - a.weight || a.name.localeCompare(b.name));
76384
+ }
76385
+ function isLocalSpec(version2) {
76386
+ if (!version2) return false;
76387
+ const v = version2.trim().toLowerCase();
76388
+ return v.startsWith("workspace:") || v.startsWith("link:") || v.startsWith("file:") || v.startsWith("portal:") || v.startsWith("path:") || v.startsWith("git:") || v.startsWith("git+") || v.includes("://");
76389
+ }
76390
+ function retrievalStackTokens(input) {
76391
+ const cap = input.cap ?? RETRIEVAL_STACK_CAP;
76392
+ const registry2 = input.registry ?? PUBLIC_REGISTRY_POLICY;
76393
+ const ignore2 = input.ignorePatterns ?? [];
76394
+ const ignored = (token) => ignore2.length > 0 && ignore2.some((p) => token.includes(p));
76395
+ const packagesAllowed = input.contributePackages;
76396
+ const tokens = [];
76397
+ const seen = /* @__PURE__ */ new Set();
76398
+ const push = (token) => {
76399
+ if (!token || seen.has(token) || ignored(token)) return false;
76400
+ seen.add(token);
76401
+ tokens.push(token);
76402
+ return true;
76403
+ };
76404
+ const manifestDeps = input.manifestDeps ?? [];
76405
+ const ecosystemLanguages = /* @__PURE__ */ new Set();
76406
+ for (const d of [...manifestDeps, ...input.direct ?? []]) {
76407
+ const lang = ECOSYSTEM_LANGUAGE[d.ecosystem.toLowerCase()];
76408
+ if (lang) ecosystemLanguages.add(normStackToken(lang));
76409
+ }
76410
+ for (const l of [...ecosystemLanguages, ...normStackTokens(input.languages)]) push(l);
76411
+ for (const t of normStackTokens(input.profileStack)) {
76412
+ if (isRuntimeToken(t)) push(t);
76413
+ }
76414
+ for (const d of manifestDeps) {
76415
+ if (RUNTIME_KINDS.has(d.kind)) push(normStackToken(d.name));
76416
+ }
76417
+ const byEcosystem = /* @__PURE__ */ new Map();
76418
+ const add = (c) => {
76419
+ const list = byEcosystem.get(c.ecosystem);
76420
+ if (list) list.push(c);
76421
+ else byEcosystem.set(c.ecosystem, [c]);
76422
+ };
76423
+ let fromLockfile = 0;
76424
+ let fromManifest = 0;
76425
+ const lockfileKeys = /* @__PURE__ */ new Set();
76426
+ const ecoKey = (ecosystem, name2) => `${ecosystem.toLowerCase()}\0${name2.toLowerCase()}`;
76427
+ if (packagesAllowed) {
76428
+ for (const d of input.direct ?? []) {
76429
+ lockfileKeys.add(ecoKey(d.ecosystem, d.name));
76430
+ if (!isPublicDep(d, registry2)) continue;
76431
+ add({ ecosystem: d.ecosystem.toLowerCase(), name: d.name, weight: d.importers });
76432
+ }
76433
+ const counted = /* @__PURE__ */ new Map();
76434
+ for (const d of manifestDeps) {
76435
+ if (RUNTIME_KINDS.has(d.kind)) continue;
76436
+ const ecosystem = d.ecosystem.toLowerCase();
76437
+ if (lockfileKeys.has(ecoKey(ecosystem, d.name))) continue;
76438
+ if (isLocalSpec(d.version)) continue;
76439
+ if (!isPublicDep({ ecosystem, name: d.name }, registry2)) continue;
76440
+ const key = ecoKey(ecosystem, d.name);
76441
+ const prev = counted.get(key);
76442
+ const w = KIND_WEIGHT[d.kind] ?? 0.5;
76443
+ if (prev) prev.weight += w;
76444
+ else counted.set(key, { ecosystem, name: d.name, weight: w });
76445
+ }
76446
+ for (const c of counted.values()) add(c);
76447
+ }
76448
+ const queues = [...byEcosystem.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([ecosystem, cs]) => ({ ecosystem, items: rankCandidates(cs) }));
76449
+ const usedEcosystems = /* @__PURE__ */ new Set();
76450
+ for (let round2 = 0; tokens.length < cap; round2++) {
76451
+ let emittedThisRound = false;
76452
+ for (const q of queues) {
76453
+ if (tokens.length >= cap) break;
76454
+ const c = q.items[round2];
76455
+ if (!c) continue;
76456
+ emittedThisRound = true;
76457
+ if (!push(normStackToken(c.name))) continue;
76458
+ usedEcosystems.add(c.ecosystem);
76459
+ if (lockfileKeys.has(ecoKey(c.ecosystem, c.name))) fromLockfile++;
76460
+ else fromManifest++;
76461
+ }
76462
+ if (!emittedThisRound) break;
76463
+ }
76464
+ if (packagesAllowed) {
76465
+ for (const t of normStackTokens(input.profileStack)) {
76466
+ if (tokens.length >= cap) break;
76467
+ if (isRuntimeToken(t)) continue;
76468
+ if (!isPublicDep({ ecosystem: "npm", name: t }, registry2)) continue;
76469
+ push(t);
76470
+ }
76471
+ }
76472
+ const source = fromLockfile > 0 && fromManifest > 0 ? "both" : fromLockfile > 0 ? "lockfile" : fromManifest > 0 ? "manifest" : "profile";
76473
+ return { tokens: tokens.slice(0, cap), source, ecosystems: [...usedEcosystems].sort() };
76474
+ }
76475
+ var LOCKFILES = [
76476
+ { file: "pnpm-lock.yaml", family: "npm", parse: parsePnpmLock },
76477
+ { file: "package-lock.json", family: "npm", parse: parsePackageLockJson },
76478
+ { file: "Gemfile.lock", family: "gem", parse: parseGemfileLock }
76479
+ ];
76480
+ var directCache = /* @__PURE__ */ new Map();
76481
+ function readDirectDependencies(root) {
76482
+ const stamps = [];
76483
+ const found = [];
76484
+ const familiesSeen = /* @__PURE__ */ new Set();
76485
+ for (const c of LOCKFILES) {
76486
+ if (familiesSeen.has(c.family)) continue;
76487
+ const p = join23(root, c.file);
76488
+ if (!existsSync19(p)) continue;
76489
+ try {
76490
+ const s = statSync6(p);
76491
+ stamps.push(`${c.file}:${s.mtimeMs}:${s.size}`);
76492
+ } catch {
76493
+ continue;
76494
+ }
76495
+ familiesSeen.add(c.family);
76496
+ found.push({ c, path: p });
76497
+ }
76498
+ if (found.length === 0) {
76499
+ directCache.delete(root);
76500
+ return [];
76501
+ }
76502
+ const key = stamps.join("|");
76503
+ const hit = directCache.get(root);
76504
+ if (hit && hit.key === key) return hit.direct;
76505
+ const direct = [];
76506
+ for (const { c, path: path2 } of found) {
76507
+ try {
76508
+ direct.push(...c.parse(readFileSync18(path2, "utf8")).direct ?? []);
76509
+ } catch {
76510
+ }
76511
+ }
76512
+ directCache.set(root, { key, direct });
76513
+ return direct;
76514
+ }
76515
+ function manifestPaths(root) {
76516
+ try {
76517
+ const out2 = execFileSync3("git", ["-C", root, "ls-files", "-z"], {
76518
+ encoding: "utf8",
76519
+ maxBuffer: 128 * 1024 * 1024,
76520
+ windowsHide: true,
76521
+ stdio: ["ignore", "pipe", "ignore"]
76522
+ });
76523
+ const paths = out2.split("\0").filter((f) => f && isManifestPath(f));
76524
+ if (paths.length > 0) return paths.slice(0, MANIFEST_SCAN_CAP);
76525
+ } catch {
76526
+ }
76527
+ const ROOT_MANIFESTS = [
76528
+ "package.json",
76529
+ "pyproject.toml",
76530
+ "requirements.txt",
76531
+ "go.mod",
76532
+ "Cargo.toml",
76533
+ "pom.xml",
76534
+ "build.gradle",
76535
+ "build.gradle.kts",
76536
+ "gradle/libs.versions.toml",
76537
+ "Gemfile",
76538
+ "docker-compose.yml",
76539
+ "docker-compose.yaml",
76540
+ "compose.yaml",
76541
+ "Dockerfile",
76542
+ "project.godot"
76543
+ ];
76544
+ return ROOT_MANIFESTS.filter((f) => existsSync19(join23(root, f)));
76545
+ }
76546
+ var manifestCache = /* @__PURE__ */ new Map();
76547
+ function readManifestDependencies(root) {
76548
+ const paths = manifestPaths(root);
76549
+ if (paths.length === 0) {
76550
+ manifestCache.delete(root);
76551
+ return [];
76552
+ }
76553
+ const texts = /* @__PURE__ */ new Map();
76554
+ const stamps = [];
76555
+ for (const rel of paths) {
76556
+ const abs = join23(root, rel);
76557
+ try {
76558
+ const s = statSync6(abs);
76559
+ stamps.push(`${rel}:${s.mtimeMs}:${s.size}`);
76560
+ texts.set(rel, readFileSync18(abs, "utf8"));
76561
+ } catch {
76562
+ }
76563
+ }
76564
+ const key = stamps.join("|");
76565
+ const hit = manifestCache.get(root);
76566
+ if (hit && hit.key === key) return hit.deps;
76567
+ let deps = [];
76568
+ try {
76569
+ const spine = buildSpine("workspace", [...texts.keys()], (p) => texts.get(p) ?? "");
76570
+ deps = Object.values(spine.manifests).flat();
76571
+ } catch {
76572
+ deps = [];
76573
+ }
76574
+ manifestCache.set(root, { key, deps });
76575
+ return deps;
76576
+ }
76577
+
76578
+ // src/git-sensor.ts
76579
+ import { existsSync as existsSync20, readFileSync as readFileSync19, watch as fsWatch } from "node:fs";
76580
+ import { join as join24 } from "node:path";
75720
76581
  function readFirstLine(path2) {
75721
76582
  try {
75722
- return readFileSync18(path2, "utf8").split(/\r?\n/, 1)[0].trim();
76583
+ return readFileSync19(path2, "utf8").split(/\r?\n/, 1)[0].trim();
75723
76584
  } catch {
75724
76585
  return null;
75725
76586
  }
75726
76587
  }
75727
76588
  function readGitRefState(gitDir) {
75728
- const head2 = readFirstLine(join23(gitDir, "HEAD"));
76589
+ const head2 = readFirstLine(join24(gitDir, "HEAD"));
75729
76590
  const m = head2 ? /^ref:\s*refs\/heads\/(.+)$/.exec(head2) : null;
75730
76591
  const branch = m ? m[1] : null;
75731
76592
  let sha2 = null;
75732
76593
  if (branch) {
75733
- sha2 = readFirstLine(join23(gitDir, "refs", "heads", branch));
76594
+ sha2 = readFirstLine(join24(gitDir, "refs", "heads", branch));
75734
76595
  if (!sha2) sha2 = shaFromPackedRefs(gitDir, `refs/heads/${branch}`);
75735
76596
  } else if (head2 && /^[0-9a-f]{7,40}$/i.test(head2)) {
75736
76597
  sha2 = head2;
@@ -75738,13 +76599,13 @@ function readGitRefState(gitDir) {
75738
76599
  return {
75739
76600
  branch,
75740
76601
  sha: sha2,
75741
- mergeHeadExists: existsSync19(join23(gitDir, "MERGE_HEAD")),
75742
- origHeadExists: existsSync19(join23(gitDir, "ORIG_HEAD"))
76602
+ mergeHeadExists: existsSync20(join24(gitDir, "MERGE_HEAD")),
76603
+ origHeadExists: existsSync20(join24(gitDir, "ORIG_HEAD"))
75743
76604
  };
75744
76605
  }
75745
76606
  function shaFromPackedRefs(gitDir, ref) {
75746
76607
  try {
75747
- for (const line of readFileSync18(join23(gitDir, "packed-refs"), "utf8").split(/\r?\n/)) {
76608
+ for (const line of readFileSync19(join24(gitDir, "packed-refs"), "utf8").split(/\r?\n/)) {
75748
76609
  const [sha2, name2] = line.split(/\s+/);
75749
76610
  if (name2 === ref && sha2) return sha2;
75750
76611
  }
@@ -75778,7 +76639,7 @@ function startGitSensor(gitDir, onEvent, opts = {}) {
75778
76639
  const settle = () => {
75779
76640
  if (timer) clearTimeout(timer);
75780
76641
  timer = setTimeout(() => {
75781
- if (existsSync19(join23(gitDir, "index.lock"))) {
76642
+ if (existsSync20(join24(gitDir, "index.lock"))) {
75782
76643
  settle();
75783
76644
  return;
75784
76645
  }
@@ -75789,7 +76650,7 @@ function startGitSensor(gitDir, onEvent, opts = {}) {
75789
76650
  }, debounceMs);
75790
76651
  };
75791
76652
  for (const sub of ["HEAD", "logs/HEAD", "MERGE_HEAD", "ORIG_HEAD"]) {
75792
- const p = join23(gitDir, sub);
76653
+ const p = join24(gitDir, sub);
75793
76654
  try {
75794
76655
  watchers.push(fsWatch(p, settle));
75795
76656
  } catch {
@@ -76014,21 +76875,21 @@ var TelemetryRecorder = class {
76014
76875
 
76015
76876
  // src/skills.ts
76016
76877
  import {
76017
- existsSync as existsSync20,
76878
+ existsSync as existsSync21,
76018
76879
  mkdirSync as mkdirSync7,
76019
- readFileSync as readFileSync19,
76880
+ readFileSync as readFileSync20,
76020
76881
  readdirSync as readdirSync8,
76021
76882
  unlinkSync as unlinkSync2,
76022
76883
  writeFileSync as writeFileSync15
76023
76884
  } from "node:fs";
76024
- import { basename as basename6, join as join24 } from "node:path";
76885
+ import { basename as basename6, join as join25 } from "node:path";
76025
76886
  function skillFileName(id) {
76026
76887
  return `${id.replace(/[^A-Za-z0-9_.-]/g, "_")}.md`;
76027
76888
  }
76028
76889
  function readSkillManifest(manifestPath) {
76029
- if (!existsSync20(manifestPath)) return [];
76890
+ if (!existsSync21(manifestPath)) return [];
76030
76891
  try {
76031
- const parsed = JSON.parse(readFileSync19(manifestPath, "utf8"));
76892
+ const parsed = JSON.parse(readFileSync20(manifestPath, "utf8"));
76032
76893
  return (parsed.skills ?? []).map((s) => ({
76033
76894
  title: s.title ?? "",
76034
76895
  layer: s.layer ?? "technique",
@@ -76052,7 +76913,7 @@ async function syncSkills(paths, client, seed, pins = [], techSeed) {
76052
76913
  for (const s of res.skills) {
76053
76914
  const fileName = skillFileName(s.id);
76054
76915
  keep.add(fileName);
76055
- writeFileSync15(join24(paths.skillsDir, fileName), s.markdown, "utf8");
76916
+ writeFileSync15(join25(paths.skillsDir, fileName), s.markdown, "utf8");
76056
76917
  rows.push({
76057
76918
  id: s.id,
76058
76919
  title: s.title,
@@ -76065,7 +76926,7 @@ async function syncSkills(paths, client, seed, pins = [], techSeed) {
76065
76926
  const fileName = skillFileName(p.id);
76066
76927
  if (keep.has(fileName)) continue;
76067
76928
  keep.add(fileName);
76068
- writeFileSync15(join24(paths.skillsDir, fileName), p.markdown, "utf8");
76929
+ writeFileSync15(join25(paths.skillsDir, fileName), p.markdown, "utf8");
76069
76930
  rows.push({
76070
76931
  id: p.id,
76071
76932
  title: p.title,
@@ -76079,7 +76940,7 @@ async function syncSkills(paths, client, seed, pins = [], techSeed) {
76079
76940
  if (!f.endsWith(".md")) continue;
76080
76941
  if (keep.has(basename6(f))) continue;
76081
76942
  try {
76082
- unlinkSync2(join24(paths.skillsDir, f));
76943
+ unlinkSync2(join25(paths.skillsDir, f));
76083
76944
  pruned++;
76084
76945
  } catch {
76085
76946
  }
@@ -76097,22 +76958,22 @@ async function syncSkills(paths, client, seed, pins = [], techSeed) {
76097
76958
  init_src2();
76098
76959
  import {
76099
76960
  cpSync,
76100
- existsSync as existsSync21,
76961
+ existsSync as existsSync22,
76101
76962
  lstatSync,
76102
76963
  mkdirSync as mkdirSync8,
76103
- readFileSync as readFileSync20,
76964
+ readFileSync as readFileSync21,
76104
76965
  readdirSync as readdirSync9,
76105
76966
  rmSync as rmSync3,
76106
76967
  symlinkSync,
76107
76968
  writeFileSync as writeFileSync16
76108
76969
  } from "node:fs";
76109
- import { join as join25 } from "node:path";
76970
+ import { join as join26 } from "node:path";
76110
76971
  var SKILL_NS = "errata-";
76111
76972
  var HARNESS_SKILL_DIRS = [
76112
- { configDir: ".claude", skillsDir: join25(".claude", "skills") },
76973
+ { configDir: ".claude", skillsDir: join26(".claude", "skills") },
76113
76974
  // Cursor adopted the standard; its exact project dir is still moving — kept
76114
76975
  // best-effort and gated on `.cursor/` presence so we never create it blind.
76115
- { configDir: ".cursor", skillsDir: join25(".cursor", "skills") }
76976
+ { configDir: ".cursor", skillsDir: join26(".cursor", "skills") }
76116
76977
  ];
76117
76978
  function skillSlug(title, id) {
76118
76979
  const base = title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || id.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "skill";
@@ -76157,12 +77018,12 @@ function skillCiteHandle(s) {
76157
77018
  return priorHandle({ id: s.id, description: s.title });
76158
77019
  }
76159
77020
  function reconcileNamespaced(dir, keep) {
76160
- if (!existsSync21(dir)) return 0;
77021
+ if (!existsSync22(dir)) return 0;
76161
77022
  let pruned = 0;
76162
77023
  for (const name2 of readdirSync9(dir)) {
76163
77024
  if (!name2.startsWith(SKILL_NS) || keep.has(name2)) continue;
76164
77025
  try {
76165
- rmSync3(join25(dir, name2), { recursive: true, force: true });
77026
+ rmSync3(join26(dir, name2), { recursive: true, force: true });
76166
77027
  pruned++;
76167
77028
  } catch {
76168
77029
  }
@@ -76171,7 +77032,7 @@ function reconcileNamespaced(dir, keep) {
76171
77032
  }
76172
77033
  function linkOrCopy(linkPath, target) {
76173
77034
  try {
76174
- if (existsSync21(linkPath) || safeLstat(linkPath)) rmSync3(linkPath, { recursive: true, force: true });
77035
+ if (existsSync22(linkPath) || safeLstat(linkPath)) rmSync3(linkPath, { recursive: true, force: true });
76175
77036
  } catch {
76176
77037
  }
76177
77038
  try {
@@ -76192,7 +77053,7 @@ function safeLstat(p) {
76192
77053
  }
76193
77054
  }
76194
77055
  function emitAndProjectSkills(root, skills) {
76195
- const agentsSkillsDir = join25(root, ".agents", "skills");
77056
+ const agentsSkillsDir = join26(root, ".agents", "skills");
76196
77057
  mkdirSync8(agentsSkillsDir, { recursive: true });
76197
77058
  const slugs = [];
76198
77059
  const keep = /* @__PURE__ */ new Set();
@@ -76200,7 +77061,7 @@ function emitAndProjectSkills(root, skills) {
76200
77061
  for (const s of skills) {
76201
77062
  let body2;
76202
77063
  try {
76203
- body2 = readFileSync20(s.bodyPath, "utf8");
77064
+ body2 = readFileSync21(s.bodyPath, "utf8");
76204
77065
  } catch {
76205
77066
  continue;
76206
77067
  }
@@ -76209,9 +77070,9 @@ function emitAndProjectSkills(root, skills) {
76209
77070
  keep.add(slug2);
76210
77071
  slugs.push(slug2);
76211
77072
  const description = deriveDescription(s.title, s.layer, body2);
76212
- mkdirSync8(join25(agentsSkillsDir, slug2), { recursive: true });
77073
+ mkdirSync8(join26(agentsSkillsDir, slug2), { recursive: true });
76213
77074
  writeFileSync16(
76214
- join25(agentsSkillsDir, slug2, "SKILL.md"),
77075
+ join26(agentsSkillsDir, slug2, "SKILL.md"),
76215
77076
  renderSkillMd(slug2, description, body2, skillCiteHandle(s)),
76216
77077
  "utf8"
76217
77078
  );
@@ -76220,11 +77081,11 @@ function emitAndProjectSkills(root, skills) {
76220
77081
  reconcileNamespaced(agentsSkillsDir, keep);
76221
77082
  let projected = 0;
76222
77083
  for (const h of HARNESS_SKILL_DIRS) {
76223
- if (!existsSync21(join25(root, h.configDir))) continue;
76224
- const dir = join25(root, h.skillsDir);
77084
+ if (!existsSync22(join26(root, h.configDir))) continue;
77085
+ const dir = join26(root, h.skillsDir);
76225
77086
  mkdirSync8(dir, { recursive: true });
76226
77087
  for (const slug2 of slugs) {
76227
- linkOrCopy(join25(dir, slug2), join25(agentsSkillsDir, slug2));
77088
+ linkOrCopy(join26(dir, slug2), join26(agentsSkillsDir, slug2));
76228
77089
  projected++;
76229
77090
  }
76230
77091
  reconcileNamespaced(dir, keep);
@@ -76233,15 +77094,15 @@ function emitAndProjectSkills(root, skills) {
76233
77094
  return { slugs, emitted, projected };
76234
77095
  }
76235
77096
  function emitInputsFromManifest(erretaDir, manifestPath) {
76236
- if (!existsSync21(manifestPath)) return [];
77097
+ if (!existsSync22(manifestPath)) return [];
76237
77098
  try {
76238
- const parsed = JSON.parse(readFileSync20(manifestPath, "utf8"));
77099
+ const parsed = JSON.parse(readFileSync21(manifestPath, "utf8"));
76239
77100
  return (parsed.skills ?? []).filter((s) => Boolean(s.id && s.file)).map((s) => ({
76240
77101
  id: s.id,
76241
77102
  title: s.title ?? s.id,
76242
77103
  layer: s.layer ?? "technique",
76243
77104
  confidence: s.confidence ?? 0,
76244
- bodyPath: join25(erretaDir, s.file)
77105
+ bodyPath: join26(erretaDir, s.file)
76245
77106
  }));
76246
77107
  } catch {
76247
77108
  return [];
@@ -76255,10 +77116,10 @@ var GITIGNORE_LINES = [
76255
77116
  ".cursor/skills/errata-*/"
76256
77117
  ];
76257
77118
  function ensureSkillGitignore(root) {
76258
- const path2 = join25(root, ".gitignore");
77119
+ const path2 = join26(root, ".gitignore");
76259
77120
  let current = "";
76260
77121
  try {
76261
- current = existsSync21(path2) ? readFileSync20(path2, "utf8") : "";
77122
+ current = existsSync22(path2) ? readFileSync21(path2, "utf8") : "";
76262
77123
  } catch {
76263
77124
  return;
76264
77125
  }
@@ -76363,9 +77224,9 @@ init_paths();
76363
77224
  init_src2();
76364
77225
  init_paths();
76365
77226
  init_git_remote();
76366
- import { existsSync as existsSync22, readFileSync as readFileSync21, writeFileSync as writeFileSync17 } from "node:fs";
77227
+ import { existsSync as existsSync23, readFileSync as readFileSync22, writeFileSync as writeFileSync17 } from "node:fs";
76367
77228
  import { createHash as createHash14 } from "node:crypto";
76368
- import { join as join26 } from "node:path";
77229
+ import { join as join27 } from "node:path";
76369
77230
  function workspaceId(root) {
76370
77231
  return "wp_" + createHash14("sha256").update(root).digest("hex").slice(0, 12);
76371
77232
  }
@@ -76388,8 +77249,8 @@ function refreshRepoLocator(root, profile) {
76388
77249
  }
76389
77250
  function loadProfile(root) {
76390
77251
  const p = workspacePaths(root);
76391
- if (!existsSync22(p.workspaceJson)) return null;
76392
- return JSON.parse(readFileSync21(p.workspaceJson, "utf8"));
77252
+ if (!existsSync23(p.workspaceJson)) return null;
77253
+ return JSON.parse(readFileSync22(p.workspaceJson, "utf8"));
76393
77254
  }
76394
77255
  function saveProfile(root, profile) {
76395
77256
  const p = workspacePaths(root);
@@ -76402,14 +77263,17 @@ function autodetectProfile(root) {
76402
77263
  const p = emptyProfile(id, name2);
76403
77264
  const locator = detectRepoLocator(root);
76404
77265
  if (locator) p.repoLocator = locator;
76405
- const pkgPath = join26(root, "package.json");
76406
- if (existsSync22(pkgPath)) {
77266
+ const pkgPath = join27(root, "package.json");
77267
+ if (existsSync23(pkgPath)) {
76407
77268
  try {
76408
- const pkg = JSON.parse(readFileSync21(pkgPath, "utf8"));
76409
- p.languages.push("typescript", "javascript");
76410
- const nodeVer = pkg.engines?.node ?? "node";
76411
- p.stack.push(`node@${nodeVer}`);
77269
+ const pkg = JSON.parse(readFileSync22(pkgPath, "utf8"));
76412
77270
  const deps = { ...pkg.dependencies ?? {}, ...pkg.devDependencies ?? {} };
77271
+ p.languages.push("javascript");
77272
+ if (existsSync23(join27(root, "tsconfig.json")) || deps["typescript"]) {
77273
+ p.languages.push("typescript");
77274
+ }
77275
+ const nodeVer = pkg.engines?.node?.trim();
77276
+ p.stack.push(nodeVer ? `node@${nodeVer}` : "node");
76413
77277
  const interesting = [
76414
77278
  "next",
76415
77279
  "react",
@@ -76426,10 +77290,10 @@ function autodetectProfile(root) {
76426
77290
  } catch {
76427
77291
  }
76428
77292
  }
76429
- const pyproject = join26(root, "pyproject.toml");
76430
- if (existsSync22(pyproject)) {
77293
+ const pyproject = join27(root, "pyproject.toml");
77294
+ if (existsSync23(pyproject)) {
76431
77295
  try {
76432
- const txt = readFileSync21(pyproject, "utf8");
77296
+ const txt = readFileSync22(pyproject, "utf8");
76433
77297
  const py = /python\s*=\s*"([^"]+)"/.exec(txt)?.[1];
76434
77298
  p.languages.push("python");
76435
77299
  p.stack.push(`python@${py ?? "3"}`);
@@ -76440,16 +77304,16 @@ function autodetectProfile(root) {
76440
77304
  } catch {
76441
77305
  }
76442
77306
  }
76443
- const reqs = join26(root, "requirements.txt");
76444
- if (existsSync22(reqs)) {
77307
+ const reqs = join27(root, "requirements.txt");
77308
+ if (existsSync23(reqs)) {
76445
77309
  if (!p.languages.includes("python")) p.languages.push("python");
76446
77310
  if (!p.stack.includes("python@3")) p.stack.push("python@3");
76447
77311
  }
76448
- if (existsSync22(join26(root, "go.mod"))) {
77312
+ if (existsSync23(join27(root, "go.mod"))) {
76449
77313
  p.languages.push("go");
76450
77314
  p.stack.push("go");
76451
77315
  }
76452
- if (existsSync22(join26(root, "Cargo.toml"))) {
77316
+ if (existsSync23(join27(root, "Cargo.toml"))) {
76453
77317
  p.languages.push("rust");
76454
77318
  p.stack.push("rust");
76455
77319
  }
@@ -76459,18 +77323,18 @@ function autodetectProfile(root) {
76459
77323
  }
76460
77324
 
76461
77325
  // src/witness-queue.ts
76462
- import { readFileSync as readFileSync22, renameSync as renameSync2, writeFileSync as writeFileSync18 } from "node:fs";
76463
- import { dirname as dirname11, join as join27 } from "node:path";
77326
+ import { readFileSync as readFileSync23, renameSync as renameSync2, writeFileSync as writeFileSync18 } from "node:fs";
77327
+ import { dirname as dirname11, join as join28 } from "node:path";
76464
77328
  var WITNESS_QUEUE_CAP = 500;
76465
77329
  var WITNESS_TTL_MS = 14 * 24 * 60 * 60 * 1e3;
76466
77330
  var WITNESS_MAX_ATTEMPTS = 5;
76467
77331
  function witnessQueuePath(workspaceConfigDir) {
76468
- return join27(workspaceConfigDir, "witness-queue.json");
77332
+ return join28(workspaceConfigDir, "witness-queue.json");
76469
77333
  }
76470
77334
  function loadWitnessQueueWithLosses(path2) {
76471
77335
  let raw2;
76472
77336
  try {
76473
- raw2 = JSON.parse(readFileSync22(path2, "utf8"));
77337
+ raw2 = JSON.parse(readFileSync23(path2, "utf8"));
76474
77338
  } catch (err2) {
76475
77339
  const absent = err2?.code === "ENOENT";
76476
77340
  return { queue: [], fileUnreadable: !absent, malformedEntries: 0 };
@@ -76483,7 +77347,7 @@ function loadWitnessQueueWithLosses(path2) {
76483
77347
  }
76484
77348
  function saveWitnessQueue(path2, queue) {
76485
77349
  try {
76486
- const tmp = join27(dirname11(path2), `.${Date.now()}.witness-queue.tmp`);
77350
+ const tmp = join28(dirname11(path2), `.${Date.now()}.witness-queue.tmp`);
76487
77351
  writeFileSync18(tmp, JSON.stringify(queue), "utf8");
76488
77352
  renameSync2(tmp, path2);
76489
77353
  } catch {
@@ -77057,7 +77921,7 @@ function createWatchBreaker(deps) {
77057
77921
  }
77058
77922
 
77059
77923
  // src/engine.ts
77060
- var DAEMON_VERSION = true ? "2.0.6-dev.2169" : "2.0.0-alpha.0";
77924
+ var DAEMON_VERSION = true ? "2.0.6-dev.2250" : "2.0.0-alpha.0";
77061
77925
  var IGNORED_PATH = /[\\/](?:\.git|node_modules|\.errata|\.claude|\.codex|\.cursor|\.turbo|\.next|dist|coverage|test-results|playwright-report|__pycache__)(?:[\\/]|$)/;
77062
77926
  var IGNORED_NOISE = /castalia\.db|eventlog\.sqlite|turn-cursors/;
77063
77927
  var GIT_OP_MUTE_MS = 4e3;
@@ -77068,7 +77932,7 @@ var CODEX_SWEEP_LOOKBACK_MS = 10 * 6e4;
77068
77932
  function appendIdentityAudit(path2, record2, line) {
77069
77933
  if (!record2.accepted && record2.score <= 0) return;
77070
77934
  try {
77071
- if (existsSync24(path2) && statSync6(path2).size >= IDENTITY_AUDIT_MAX_BYTES) {
77935
+ if (existsSync25(path2) && statSync7(path2).size >= IDENTITY_AUDIT_MAX_BYTES) {
77072
77936
  renameSync3(path2, `${path2}.1`);
77073
77937
  }
77074
77938
  appendFileSync4(path2, line);
@@ -77078,7 +77942,7 @@ function appendIdentityAudit(path2, record2, line) {
77078
77942
  var yieldToLoop = () => new Promise((r) => setImmediate(r));
77079
77943
  function loadTurnCursors(path2) {
77080
77944
  try {
77081
- const raw2 = JSON.parse(readFileSync24(path2, "utf8"));
77945
+ const raw2 = JSON.parse(readFileSync25(path2, "utf8"));
77082
77946
  return new Map(
77083
77947
  Object.entries(raw2).map(([k, v]) => [k, typeof v === "string" ? v : String(v?.uuid ?? "")])
77084
77948
  );
@@ -77088,7 +77952,7 @@ function loadTurnCursors(path2) {
77088
77952
  }
77089
77953
  function loadTurnOffsets(path2) {
77090
77954
  try {
77091
- const raw2 = JSON.parse(readFileSync24(path2, "utf8"));
77955
+ const raw2 = JSON.parse(readFileSync25(path2, "utf8"));
77092
77956
  const out2 = /* @__PURE__ */ new Map();
77093
77957
  for (const [k, v] of Object.entries(raw2)) {
77094
77958
  const off = typeof v === "object" && v !== null ? v.offset : void 0;
@@ -77111,7 +77975,7 @@ function saveTurnCursors(path2, cursors, offsets) {
77111
77975
  function gitSourceWatchTargets(root) {
77112
77976
  const SOURCE = /\.(ts|tsx|js|jsx|mjs|cjs|py)$/i;
77113
77977
  try {
77114
- const lsOut = execFileSync3("git", ["-C", root, "ls-files", "-z"], {
77978
+ const lsOut = execFileSync4("git", ["-C", root, "ls-files", "-z"], {
77115
77979
  encoding: "utf8",
77116
77980
  maxBuffer: 128 * 1024 * 1024,
77117
77981
  windowsHide: true,
@@ -77121,12 +77985,12 @@ function gitSourceWatchTargets(root) {
77121
77985
  if (sourceFiles.length === 0) throw new Error("no tracked source");
77122
77986
  let ignoredDirs = [];
77123
77987
  try {
77124
- const igOut = execFileSync3(
77988
+ const igOut = execFileSync4(
77125
77989
  "git",
77126
77990
  ["-C", root, "ls-files", "--others", "--ignored", "--exclude-standard", "--directory", "-z"],
77127
77991
  { encoding: "utf8", maxBuffer: 256 * 1024 * 1024, windowsHide: true, stdio: ["ignore", "pipe", "ignore"] }
77128
77992
  );
77129
- ignoredDirs = igOut.split("\0").filter(Boolean).map((d) => d.replace(/\/+$/, "")).filter((d) => !IGNORED_PATH.test(join29(root, d) + sep4));
77993
+ ignoredDirs = igOut.split("\0").filter(Boolean).map((d) => d.replace(/\/+$/, "")).filter((d) => !IGNORED_PATH.test(join30(root, d) + sep4));
77130
77994
  } catch {
77131
77995
  }
77132
77996
  const hasIgnoredChild = (dir) => ignoredDirs.some((ig) => ig.startsWith(dir + "/"));
@@ -77138,19 +78002,19 @@ function gitSourceWatchTargets(root) {
77138
78002
  if (!f.startsWith(prefix)) continue;
77139
78003
  const rest2 = f.slice(prefix.length);
77140
78004
  if (rest2.includes("/")) children.add(dir === "" ? rest2.slice(0, rest2.indexOf("/")) : dir + "/" + rest2.slice(0, rest2.indexOf("/")));
77141
- else targets.add(join29(root, f));
78005
+ else targets.add(join30(root, f));
77142
78006
  }
77143
78007
  for (const c of children) {
77144
- if (IGNORED_PATH.test(join29(root, c) + sep4)) continue;
78008
+ if (IGNORED_PATH.test(join30(root, c) + sep4)) continue;
77145
78009
  if (hasIgnoredChild(c)) addUnder(c);
77146
- else targets.add(join29(root, c));
78010
+ else targets.add(join30(root, c));
77147
78011
  }
77148
78012
  };
77149
78013
  addUnder("");
77150
78014
  if (targets.size > 0) return [...targets];
77151
78015
  } catch {
77152
78016
  }
77153
- return readdirSync10(root, { withFileTypes: true }).filter((e) => e.isDirectory() && !IGNORED_PATH.test(join29(root, String(e.name)) + sep4)).map((e) => join29(root, String(e.name)));
78017
+ return readdirSync10(root, { withFileTypes: true }).filter((e) => e.isDirectory() && !IGNORED_PATH.test(join30(root, String(e.name)) + sep4)).map((e) => join30(root, String(e.name)));
77154
78018
  }
77155
78019
  function createWorkspaceEngine(opts) {
77156
78020
  const paths = workspacePaths(opts.workspaceRoot);
@@ -77228,7 +78092,7 @@ function createWorkspaceEngine(opts) {
77228
78092
  }
77229
78093
  let size = 0;
77230
78094
  try {
77231
- size = statSync6(path2).size;
78095
+ size = statSync7(path2).size;
77232
78096
  } catch {
77233
78097
  }
77234
78098
  lastActivityTs = Date.now();
@@ -77343,7 +78207,7 @@ function createWorkspaceEngine(opts) {
77343
78207
  const srcPaths = diff.changedPaths.filter((p) => /\.(ts|tsx|js|jsx|mjs|cjs|py)$/i.test(p));
77344
78208
  let episodeId2;
77345
78209
  if (srcPaths.length > 0) {
77346
- const abs = srcPaths.map((p) => join29(opts.workspaceRoot, p));
78210
+ const abs = srcPaths.map((p) => join30(opts.workspaceRoot, p));
77347
78211
  try {
77348
78212
  const r = await runReindexPass(
77349
78213
  `git-reindex:${profile.name} (${abs.length} files)`,
@@ -77379,8 +78243,8 @@ function createWorkspaceEngine(opts) {
77379
78243
  `[errata] git: ${ev.kind} ${ev.newSha.slice(0, 7)} by ${meta3.authorName} \u2014 ${diff.changedPaths.length} file(s), ${diff.renames.length} rename(s)`
77380
78244
  );
77381
78245
  };
77382
- const gitDir = join29(opts.workspaceRoot, ".git");
77383
- if (existsSync24(gitDir)) {
78246
+ const gitDir = join30(opts.workspaceRoot, ".git");
78247
+ if (existsSync25(gitDir)) {
77384
78248
  stopGit = startGitSensor(gitDir, (ev) => {
77385
78249
  void handleGitEvent(ev).catch((err2) => {
77386
78250
  console.warn("[errata] git event handler failed:", err2);
@@ -77561,10 +78425,10 @@ function createWorkspaceEngine(opts) {
77561
78425
  console.warn("[errata] render ledger failed:", err2.message?.slice(0, 120));
77562
78426
  }
77563
78427
  writeContextFile(opts.workspaceRoot, body2);
77564
- const target = join29(opts.workspaceRoot, "AGENTS.md");
78428
+ const target = join30(opts.workspaceRoot, "AGENTS.md");
77565
78429
  writeManagedBlock(target, { body: AGENTS_POINTER_BODY, stable: true, force: true });
77566
78430
  if (elicit) {
77567
- writePrimingHandles(join29(paths.configDir, "priming-handles.json"), [
78431
+ writePrimingHandles(join30(paths.configDir, "priming-handles.json"), [
77568
78432
  ...snapshot.recentProblems.map((r) => r.node),
77569
78433
  // Resolved-band handles: the ✓ problem AND its Solution are citable
77570
78434
  // (a fix tag on an already-resolved problem no-ops idempotently; the
@@ -77584,7 +78448,21 @@ function createWorkspaceEngine(opts) {
77584
78448
  contextDirty = false;
77585
78449
  notifyDigest("recall");
77586
78450
  };
77587
- const normStackTokens = (xs) => (xs ?? []).map((t) => t.trim().toLowerCase().replace(/(?!^)[@\s].*$/, "")).filter(Boolean);
78451
+ const outboundStack = () => retrievalStackTokens({
78452
+ direct: readDirectDependencies(opts.workspaceRoot),
78453
+ manifestDeps: readManifestDependencies(opts.workspaceRoot),
78454
+ profileStack: profile?.stack ?? [],
78455
+ // Languages ride the stack list: the cloud's context-affinity matcher
78456
+ // resolves each token against both the Package and Language namespaces,
78457
+ // and the profile keeps them in separate fields.
78458
+ languages: profile?.languages ?? [],
78459
+ contributePackages: loadConfig().consent.contributePackages,
78460
+ // `repoLocator` feeds the Maven self-disclosure rule ONLY: a groupId
78461
+ // carrying this project's own owner/repo token is the project naming
78462
+ // itself, not a library it depends on.
78463
+ registry: loadRegistryPolicy(opts.workspaceRoot, process.env, profile?.repoLocator),
78464
+ ignorePatterns: loadClaimIgnorePatterns(opts.workspaceRoot)
78465
+ }).tokens;
77588
78466
  const maybeRefreshRemotePriors = () => {
77589
78467
  if (opts.skipContextWriter || remoteInFlight) return;
77590
78468
  const now = Date.now();
@@ -77598,10 +78476,7 @@ function createWorkspaceEngine(opts) {
77598
78476
  const norm = normStackTokens;
77599
78477
  const seed = store.findNodesByLabel("Problem").sort((a, b) => b.lastUpdatedAt - a.lastUpdatedAt).slice(0, 6).map((p) => p.id);
77600
78478
  const q = {
77601
- // Languages ride the stack list: the cloud's context-affinity matcher
77602
- // resolves each token against both the Package and Language
77603
- // namespaces, and the profile keeps them in separate fields.
77604
- stack: norm([...profile.stack ?? [], ...profile.languages ?? []]),
78479
+ stack: outboundStack(),
77605
78480
  domains: norm(profile.domains),
77606
78481
  kinds: ["Pattern", "Technique", "AntiPattern"],
77607
78482
  ...seed.length ? { seed } : {},
@@ -77645,7 +78520,7 @@ function createWorkspaceEngine(opts) {
77645
78520
  // longer concatenates these tokens into the embedding string, it
77646
78521
  // re-weights anchored hits with them (stated beats derived — the
77647
78522
  // intent text drives entry search, the stack only re-ranks).
77648
- stack: normStackTokens([...profile?.stack ?? [], ...profile?.languages ?? []]),
78523
+ stack: outboundStack(),
77649
78524
  domains: normStackTokens(profile?.domains ?? []),
77650
78525
  kinds: ["Pattern", "Technique", "AntiPattern", "Problem", "Solution"],
77651
78526
  q: liveIntent,
@@ -77865,7 +78740,7 @@ function createWorkspaceEngine(opts) {
77865
78740
  resultSummary: { exitCode: e.exitCode ?? 1, errorTokens: e.errorTokens }
77866
78741
  });
77867
78742
  };
77868
- const turnCursorPath = join29(paths.configDir, "turn-cursors.json");
78743
+ const turnCursorPath = join30(paths.configDir, "turn-cursors.json");
77869
78744
  const lastTurnUuid = loadTurnCursors(turnCursorPath);
77870
78745
  const turnOffset = loadTurnOffsets(turnCursorPath);
77871
78746
  const readLosses = { parseFailures: 0, ioFailures: 0, bytesUnreachable: 0, sliceGuardHits: 0 };
@@ -77920,7 +78795,7 @@ function createWorkspaceEngine(opts) {
77920
78795
  let processedTurns = 0;
77921
78796
  const seqAtStart = store.currentIngestSeq();
77922
78797
  const elicit = isEdgeElicitationEnabled();
77923
- const handleMap = elicit ? readPrimingHandles(join29(paths.configDir, "priming-handles.json")) : {};
78798
+ const handleMap = elicit ? readPrimingHandles(join30(paths.configDir, "priming-handles.json")) : {};
77924
78799
  const wsRoot = (opts.workspaceRoot ?? "").replace(/\\/g, "/");
77925
78800
  const toRel = (abs) => {
77926
78801
  const p = abs.replace(/\\/g, "/");
@@ -78212,10 +79087,10 @@ function createWorkspaceEngine(opts) {
78212
79087
  let enclosing = {};
78213
79088
  if (p.location?.line !== void 0) {
78214
79089
  try {
78215
- const headSha = readGitRefState(join29(opts.workspaceRoot, ".git")).sha ?? void 0;
79090
+ const headSha = readGitRefState(join30(opts.workspaceRoot, ".git")).sha ?? void 0;
78216
79091
  enclosing = {
78217
79092
  line: p.location.line,
78218
- fileText: readFileSync24(join29(opts.workspaceRoot, anchorPath), "utf8"),
79093
+ fileText: readFileSync25(join30(opts.workspaceRoot, anchorPath), "utf8"),
78219
79094
  ...headSha ? { headSha } : {}
78220
79095
  };
78221
79096
  } catch {
@@ -78937,7 +79812,7 @@ B: ${b}`,
78937
79812
  try {
78938
79813
  const inputs = emitInputsFromManifest(paths.configDir, paths.skillsManifest);
78939
79814
  emitAndProjectSkills(opts.workspaceRoot, inputs);
78940
- writePrimingHandles(join29(paths.configDir, "priming-handles.json"), skillHandleNodes(inputs));
79815
+ writePrimingHandles(join30(paths.configDir, "priming-handles.json"), skillHandleNodes(inputs));
78941
79816
  } catch (err2) {
78942
79817
  console.warn("[skills] agent-skills projection failed (non-fatal):", err2 instanceof Error ? err2.message : err2);
78943
79818
  }
@@ -79230,7 +80105,7 @@ B: ${b}`,
79230
80105
  console.log(
79231
80106
  "[errata] sync skipped \u2014 cloud sync consent is off (enable with `errata consent sync on`)"
79232
80107
  );
79233
- const pending = existsSync24(paths.outbox) ? readdirSync10(paths.outbox).filter((f) => f.endsWith(".json")).length : 0;
80108
+ const pending = existsSync25(paths.outbox) ? readdirSync10(paths.outbox).filter((f) => f.endsWith(".json")).length : 0;
79234
80109
  return { uploaded: 0, failed: 0, remaining: pending };
79235
80110
  }
79236
80111
  try {
@@ -79364,7 +80239,7 @@ async function startDaemon(opts) {
79364
80239
  );
79365
80240
  await engine.stop();
79366
80241
  try {
79367
- if (existsSync25(engine.paths.daemonLock)) {
80242
+ if (existsSync26(engine.paths.daemonLock)) {
79368
80243
  }
79369
80244
  } catch {
79370
80245
  }
@@ -79386,7 +80261,7 @@ init_identity2();
79386
80261
  // src/multi.ts
79387
80262
  init_dist();
79388
80263
  init_src5();
79389
- import { existsSync as existsSync31, readFileSync as readFileSync30, unlinkSync as unlinkSync3, writeFileSync as writeFileSync23 } from "node:fs";
80264
+ import { existsSync as existsSync32, readFileSync as readFileSync31, unlinkSync as unlinkSync3, writeFileSync as writeFileSync23 } from "node:fs";
79390
80265
 
79391
80266
  // src/principle-sync.ts
79392
80267
  init_src5();
@@ -79414,8 +80289,8 @@ init_reconcile();
79414
80289
 
79415
80290
  // src/lockfile-auto.ts
79416
80291
  init_src();
79417
- import { existsSync as existsSync26, readFileSync as readFileSync25 } from "node:fs";
79418
- import { join as join30 } from "node:path";
80292
+ import { existsSync as existsSync27, readFileSync as readFileSync26 } from "node:fs";
80293
+ import { join as join31 } from "node:path";
79419
80294
 
79420
80295
  // src/package-index.ts
79421
80296
  init_src();
@@ -79564,11 +80439,11 @@ function runLockfilePass(opts) {
79564
80439
  { file: "package-lock.json", parse: parsePackageLockJson }
79565
80440
  ];
79566
80441
  for (const c of candidates) {
79567
- const p = join30(opts.root, c.file);
79568
- if (!existsSync26(p)) continue;
80442
+ const p = join31(opts.root, c.file);
80443
+ if (!existsSync27(p)) continue;
79569
80444
  let sbom;
79570
80445
  try {
79571
- sbom = c.parse(readFileSync25(p, "utf8"));
80446
+ sbom = c.parse(readFileSync26(p, "utf8"));
79572
80447
  } catch {
79573
80448
  continue;
79574
80449
  }
@@ -79625,8 +80500,8 @@ function noveltyAgainst(node2, neighbors, opts = {}) {
79625
80500
  }
79626
80501
 
79627
80502
  // src/public-symbols.ts
79628
- import { readFileSync as readFileSync26, readdirSync as readdirSync11, existsSync as existsSync27 } from "node:fs";
79629
- import { join as join31 } from "node:path";
80503
+ import { readFileSync as readFileSync27, readdirSync as readdirSync11, existsSync as existsSync28 } from "node:fs";
80504
+ import { join as join32 } from "node:path";
79630
80505
  var HEAD_BYTES = 8 * 1024;
79631
80506
  var INDEX_TTL_MS = 10 * 60 * 1e3;
79632
80507
  var MIN_SYMBOL_LEN = 4;
@@ -79659,20 +80534,20 @@ function bindingNames(clause) {
79659
80534
  function internalPackageNames(workspaceRoot) {
79660
80535
  const names = /* @__PURE__ */ new Set();
79661
80536
  const tryRead = (dir) => {
79662
- const pj = join31(dir, "package.json");
79663
- if (!existsSync27(pj)) return;
80537
+ const pj = join32(dir, "package.json");
80538
+ if (!existsSync28(pj)) return;
79664
80539
  try {
79665
- const name2 = JSON.parse(readFileSync26(pj, "utf8")).name;
80540
+ const name2 = JSON.parse(readFileSync27(pj, "utf8")).name;
79666
80541
  if (typeof name2 === "string" && name2.length > 0) names.add(name2);
79667
80542
  } catch {
79668
80543
  }
79669
80544
  };
79670
80545
  tryRead(workspaceRoot);
79671
80546
  for (const group of ["packages", "apps"]) {
79672
- const groupDir = join31(workspaceRoot, group);
79673
- if (!existsSync27(groupDir)) continue;
80547
+ const groupDir = join32(workspaceRoot, group);
80548
+ if (!existsSync28(groupDir)) continue;
79674
80549
  try {
79675
- for (const entry of readdirSync11(groupDir)) tryRead(join31(groupDir, entry));
80550
+ for (const entry of readdirSync11(groupDir)) tryRead(join32(groupDir, entry));
79676
80551
  } catch {
79677
80552
  }
79678
80553
  }
@@ -79685,7 +80560,7 @@ function publicSymbolIndex(store, workspaceRoot, deps = {}) {
79685
80560
  if (cached2 && now - cached2.builtAt < INDEX_TTL_MS) return cached2;
79686
80561
  const readHead = deps.readHead ?? ((absPath) => {
79687
80562
  try {
79688
- return readFileSync26(absPath, "utf8").slice(0, HEAD_BYTES);
80563
+ return readFileSync27(absPath, "utf8").slice(0, HEAD_BYTES);
79689
80564
  } catch {
79690
80565
  return "";
79691
80566
  }
@@ -79705,7 +80580,7 @@ function publicSymbolIndex(store, workspaceRoot, deps = {}) {
79705
80580
  }
79706
80581
  const symbols = /* @__PURE__ */ new Set();
79707
80582
  for (const rel of files) {
79708
- const head2 = readHead(join31(workspaceRoot, rel));
80583
+ const head2 = readHead(join32(workspaceRoot, rel));
79709
80584
  if (!head2) continue;
79710
80585
  for (const re of [NAMED_IMPORT_RE, REQUIRE_RE]) {
79711
80586
  re.lastIndex = 0;
@@ -80336,7 +81211,7 @@ var ConsolidateWorker = class {
80336
81211
  init_paths();
80337
81212
 
80338
81213
  // src/lock.ts
80339
- import { existsSync as existsSync28, readFileSync as readFileSync27 } from "node:fs";
81214
+ import { existsSync as existsSync29, readFileSync as readFileSync28 } from "node:fs";
80340
81215
  function isProcessAlive(pid) {
80341
81216
  if (!pid || pid <= 0) return false;
80342
81217
  try {
@@ -80347,9 +81222,9 @@ function isProcessAlive(pid) {
80347
81222
  }
80348
81223
  }
80349
81224
  function readDaemonLock(lockPath) {
80350
- if (!existsSync28(lockPath)) return null;
81225
+ if (!existsSync29(lockPath)) return null;
80351
81226
  try {
80352
- const lock = JSON.parse(readFileSync27(lockPath, "utf8"));
81227
+ const lock = JSON.parse(readFileSync28(lockPath, "utf8"));
80353
81228
  return typeof lock.pid === "number" ? lock : null;
80354
81229
  } catch {
80355
81230
  return null;
@@ -80821,8 +81696,8 @@ async function hydrateProject(opts) {
80821
81696
  init_src7();
80822
81697
  init_src();
80823
81698
  import { execFile as execFile3 } from "node:child_process";
80824
- import { readFileSync as readFileSync29 } from "node:fs";
80825
- import { join as join33 } from "node:path";
81699
+ import { readFileSync as readFileSync30 } from "node:fs";
81700
+ import { join as join34 } from "node:path";
80826
81701
  import { promisify } from "node:util";
80827
81702
 
80828
81703
  // src/history-walk.ts
@@ -81044,8 +81919,8 @@ function narrative(unit, group) {
81044
81919
 
81045
81920
  // src/history-bundle.ts
81046
81921
  import { execFile as execFile2 } from "node:child_process";
81047
- import { readFileSync as readFileSync28 } from "node:fs";
81048
- import { join as join32 } from "node:path";
81922
+ import { readFileSync as readFileSync29 } from "node:fs";
81923
+ import { join as join33 } from "node:path";
81049
81924
 
81050
81925
  // ../../packages/privacy/src/patterns/credentials.ts
81051
81926
  var CREDENTIAL_PATTERNS = [
@@ -81827,7 +82702,7 @@ function pathAllowedByFloor(path2) {
81827
82702
  function loadRepoIgnore(root, extraPatterns = []) {
81828
82703
  let source = "";
81829
82704
  try {
81830
- source = readFileSync28(join32(root, ".errataignore"), "utf8");
82705
+ source = readFileSync29(join33(root, ".errataignore"), "utf8");
81831
82706
  } catch {
81832
82707
  source = "";
81833
82708
  }
@@ -82241,17 +83116,17 @@ async function defaultGit(root, args2) {
82241
83116
  function readIgnoreLines(root, profile) {
82242
83117
  let lines = [];
82243
83118
  try {
82244
- lines = readFileSync29(join33(root, ".errataignore"), "utf8").split("\n");
83119
+ lines = readFileSync30(join34(root, ".errataignore"), "utf8").split("\n");
82245
83120
  } catch {
82246
83121
  }
82247
83122
  return [...lines, ...profile.ignoreExtra ?? []].map((l) => l.trim()).filter((l) => l && !l.startsWith("#"));
82248
83123
  }
82249
83124
  async function spineForUnit(git3, root, unit) {
82250
83125
  const listing = await git3(root, ["ls-tree", "-r", "--name-only", unit.sha]);
82251
- const manifestPaths = listing.split("\n").map((l) => l.trim()).filter((p) => p && isManifestPath(p));
82252
- if (manifestPaths.length === 0) return void 0;
83126
+ const manifestPaths2 = listing.split("\n").map((l) => l.trim()).filter((p) => p && isManifestPath(p));
83127
+ if (manifestPaths2.length === 0) return void 0;
82253
83128
  const texts = /* @__PURE__ */ new Map();
82254
- for (const p of manifestPaths) {
83129
+ for (const p of manifestPaths2) {
82255
83130
  try {
82256
83131
  texts.set(p, await git3(root, ["show", `${unit.sha}:${p}`]));
82257
83132
  } catch {
@@ -82569,9 +83444,9 @@ async function startHistoryStage(root, input, client, walk10 = {}) {
82569
83444
  // src/link-flow.ts
82570
83445
  init_cloud_auth();
82571
83446
  import { createHash as createHash15 } from "node:crypto";
82572
- import { execFileSync as execFileSync4 } from "node:child_process";
82573
- import { existsSync as existsSync29, writeFileSync as writeFileSync22 } from "node:fs";
82574
- import { join as join34 } from "node:path";
83447
+ import { execFileSync as execFileSync5 } from "node:child_process";
83448
+ import { existsSync as existsSync30, writeFileSync as writeFileSync22 } from "node:fs";
83449
+ import { join as join35 } from "node:path";
82575
83450
 
82576
83451
  // src/device-poll.ts
82577
83452
  var THROTTLED_POLL_MIN_WAIT_MS = 11e3;
@@ -82933,7 +83808,7 @@ async function linkThroughConsole(opts) {
82933
83808
  function collectRepoFacts(root) {
82934
83809
  const git3 = (args2) => {
82935
83810
  try {
82936
- return execFileSync4("git", args2, { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
83811
+ return execFileSync5("git", args2, { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
82937
83812
  } catch {
82938
83813
  return null;
82939
83814
  }
@@ -83004,8 +83879,8 @@ function applyLinkDecision(root, profile, config2, decision, now = Date.now) {
83004
83879
  delete nextProfile.projectLinkDisabled;
83005
83880
  let wroteIgnore = false;
83006
83881
  if (decision.writeIgnoreStarter !== false) {
83007
- const target = join34(root, ".errataignore");
83008
- if (!existsSync29(target)) {
83882
+ const target = join35(root, ".errataignore");
83883
+ if (!existsSync30(target)) {
83009
83884
  writeFileSync22(target, IGNORE_STARTER, "utf8");
83010
83885
  wroteIgnore = true;
83011
83886
  }
@@ -83018,12 +83893,12 @@ init_registry();
83018
83893
 
83019
83894
  // src/adopt.ts
83020
83895
  init_git_remote();
83021
- import { existsSync as existsSync30 } from "node:fs";
83022
- import { dirname as dirname12, join as join35 } from "node:path";
83896
+ import { existsSync as existsSync31 } from "node:fs";
83897
+ import { dirname as dirname12, join as join36 } from "node:path";
83023
83898
  function findGitRoot(absPath) {
83024
83899
  let dir = absPath;
83025
83900
  for (let depth = 0; depth < 64; depth++) {
83026
- if (existsSync30(join35(dir, ".git"))) return dir;
83901
+ if (existsSync31(join36(dir, ".git"))) return dir;
83027
83902
  const parent = dirname12(dir);
83028
83903
  if (parent === dir) return null;
83029
83904
  dir = parent;
@@ -83849,7 +84724,7 @@ async function startMultiDaemon(opts = {}) {
83849
84724
  lastActiveAt = Math.max(lastActiveAt, rec.engine.lastActivityAt());
83850
84725
  } catch {
83851
84726
  }
83852
- const reason = retireDecision({ exists: existsSync31(rec.root), lastActiveAt, now });
84727
+ const reason = retireDecision({ exists: existsSync32(rec.root), lastActiveAt, now });
83853
84728
  if (reason) void retireWorkspace(rec, reason);
83854
84729
  }
83855
84730
  };
@@ -84736,7 +85611,7 @@ async function startMultiDaemon(opts = {}) {
84736
85611
  clearInterval(anchorPull);
84737
85612
  clearTimeout(codexWakeBoot);
84738
85613
  try {
84739
- const cur = readFileSync30(lockPath, "utf8");
85614
+ const cur = readFileSync31(lockPath, "utf8");
84740
85615
  if (JSON.parse(cur).pid === process.pid) unlinkSync3(lockPath);
84741
85616
  } catch {
84742
85617
  }
@@ -85772,21 +86647,21 @@ async function cmdInit() {
85772
86647
  if (!skipHooks) {
85773
86648
  console.log("");
85774
86649
  console.log("installing harness hooks...");
85775
- const { existsSync: existsSync33 } = await import("node:fs");
85776
- const { join: join37 } = await import("node:path");
86650
+ const { existsSync: existsSync34 } = await import("node:fs");
86651
+ const { join: join38 } = await import("node:path");
85777
86652
  try {
85778
86653
  await installClaudeHooks(port);
85779
86654
  } catch (err2) {
85780
86655
  console.warn(` \u26A0\uFE0F Claude hook install failed: ${err2 instanceof Error ? err2.message : err2}`);
85781
86656
  }
85782
- if (existsSync33(join37(ROOT, ".cursor"))) {
86657
+ if (existsSync34(join38(ROOT, ".cursor"))) {
85783
86658
  try {
85784
86659
  await installCursorMcpConfig();
85785
86660
  } catch (err2) {
85786
86661
  console.warn(` \u26A0\uFE0F Cursor MCP config failed: ${err2 instanceof Error ? err2.message : err2}`);
85787
86662
  }
85788
86663
  }
85789
- if (existsSync33(join37(ROOT, ".codex"))) {
86664
+ if (existsSync34(join38(ROOT, ".codex"))) {
85790
86665
  try {
85791
86666
  await installCodexHooks(port);
85792
86667
  } catch (err2) {
@@ -85963,9 +86838,9 @@ async function cmdStatus() {
85963
86838
  console.log(` stack: ${profile.stack.join(", ") || "(none)"}`);
85964
86839
  console.log(` languages: ${profile.languages.join(", ") || "(none)"}`);
85965
86840
  }
85966
- console.log(` graph db: ${existsSync32(paths.castalia) ? "yes" : "no"} (${paths.castalia})`);
85967
- console.log(` event log: ${existsSync32(paths.eventLog) ? "yes" : "no"} (${paths.eventLog})`);
85968
- if (existsSync32(paths.castalia)) {
86841
+ console.log(` graph db: ${existsSync33(paths.castalia) ? "yes" : "no"} (${paths.castalia})`);
86842
+ console.log(` event log: ${existsSync33(paths.eventLog) ? "yes" : "no"} (${paths.eventLog})`);
86843
+ if (existsSync33(paths.castalia)) {
85969
86844
  try {
85970
86845
  const { openGraphStore: openGraphStore2 } = await Promise.resolve().then(() => (init_src5(), src_exports2));
85971
86846
  const store = openGraphStore2({ path: paths.castalia });
@@ -86381,6 +87256,10 @@ async function applyToken(cfg, token) {
86381
87256
  return true;
86382
87257
  } catch (err2) {
86383
87258
  console.error(`token rejected by ${cfg.cloudUrl}: ${err2 instanceof Error ? err2.message : err2}`);
87259
+ if (err2 instanceof CloudError && err2.code === "installation_revoked") {
87260
+ console.error(` this connection was revoked in the console \u2014 the key is fine, the profile is gone.`);
87261
+ console.error(` reconnect this machine from the console's Connect page, then: errata login --token <errk_\u2026>`);
87262
+ }
86384
87263
  process.exitCode = 1;
86385
87264
  return false;
86386
87265
  }
@@ -86855,11 +87734,11 @@ function cmdInstallationProfile(args2) {
86855
87734
  }
86856
87735
  async function cmdReview() {
86857
87736
  const paths = workspacePaths(ROOT);
86858
- if (!existsSync32(paths.reviewQueue)) {
87737
+ if (!existsSync33(paths.reviewQueue)) {
86859
87738
  console.log("(review queue empty)");
86860
87739
  return;
86861
87740
  }
86862
- const queue = JSON.parse(readFileSync31(paths.reviewQueue, "utf8"));
87741
+ const queue = JSON.parse(readFileSync32(paths.reviewQueue, "utf8"));
86863
87742
  if (queue.length === 0) {
86864
87743
  console.log("(review queue empty)");
86865
87744
  return;
@@ -87530,7 +88409,7 @@ async function gatherRepo(store, ws) {
87530
88409
  };
87531
88410
  }
87532
88411
  async function gatherReportData(generatedAt) {
87533
- const { existsSync: existsSync33 } = await import("node:fs");
88412
+ const { existsSync: existsSync34 } = await import("node:fs");
87534
88413
  const { openGraphStore: openGraphStore2 } = await Promise.resolve().then(() => (init_src5(), src_exports2));
87535
88414
  const cfg = loadConfig();
87536
88415
  const outbound = cfg.consent.sync ? "auto" : "off";
@@ -87538,7 +88417,7 @@ async function gatherReportData(generatedAt) {
87538
88417
  for (const ws of listWorkspaces()) {
87539
88418
  if (ws.missing) continue;
87540
88419
  const dbPath = workspacePaths(ws.path).castalia;
87541
- if (!existsSync33(dbPath)) continue;
88420
+ if (!existsSync34(dbPath)) continue;
87542
88421
  let store = null;
87543
88422
  try {
87544
88423
  store = openGraphStore2({ path: dbPath });
@@ -87582,8 +88461,8 @@ async function cmdReport(args2) {
87582
88461
  const outDir = workspacePaths(ROOT).configDir;
87583
88462
  mkdirSync9(outDir, { recursive: true });
87584
88463
  const files = renderReport2(data, { includeFutureVerbs });
87585
- for (const f of files) writeFileSync24(join36(outDir, f.name), f.html, "utf8");
87586
- const indexPath = join36(outDir, "report.html");
88464
+ for (const f of files) writeFileSync24(join37(outDir, f.name), f.html, "utf8");
88465
+ const indexPath = join37(outDir, "report.html");
87587
88466
  console.log(`report \u2192 ${indexPath}`);
87588
88467
  console.log(
87589
88468
  ` ${data.repos.length} repo(s) \xB7 ${files.length} file(s) \xB7 ${data.rollup.nodes.toLocaleString("en-US")} nodes`
@@ -87638,7 +88517,7 @@ function spawnDaemonDetached(options = {}) {
87638
88517
  try {
87639
88518
  const logPath = daemonLogPath();
87640
88519
  try {
87641
- if (statSync7(logPath).size > 5 * 1024 * 1024) renameSync4(logPath, `${logPath}.1`);
88520
+ if (statSync8(logPath).size > 5 * 1024 * 1024) renameSync4(logPath, `${logPath}.1`);
87642
88521
  } catch {
87643
88522
  }
87644
88523
  out2 = openSync2(logPath, "a");
@@ -87703,24 +88582,24 @@ async function cmdInstallHooks(args2) {
87703
88582
  }
87704
88583
  }
87705
88584
  async function installOpencodePlugin(port) {
87706
- const { mkdirSync: mkdirSync9, existsSync: existsSync33, readFileSync: readFileSync32, writeFileSync: writeFileSync24 } = await import("node:fs");
87707
- const { join: join37 } = await import("node:path");
87708
- const dir = join37(ROOT, ".opencode", "plugin");
87709
- if (!existsSync33(dir)) mkdirSync9(dir, { recursive: true });
87710
- const file2 = join37(dir, "inerrata.js");
87711
- if (existsSync33(file2)) {
87712
- const head2 = readFileSync32(file2, "utf8").split("\n")[0] ?? "";
88585
+ const { mkdirSync: mkdirSync9, existsSync: existsSync34, readFileSync: readFileSync33, writeFileSync: writeFileSync24 } = await import("node:fs");
88586
+ const { join: join38 } = await import("node:path");
88587
+ const dir = join38(ROOT, ".opencode", "plugin");
88588
+ if (!existsSync34(dir)) mkdirSync9(dir, { recursive: true });
88589
+ const file2 = join38(dir, "inerrata.js");
88590
+ if (existsSync34(file2)) {
88591
+ const head2 = readFileSync33(file2, "utf8").split("\n")[0] ?? "";
87713
88592
  if (head2.trim() !== OPENCODE_PLUGIN_MARKER) {
87714
88593
  console.error(`refusing to overwrite ${file2}: not an errata-managed plugin (line 1 lacks the marker)`);
87715
88594
  process.exit(2);
87716
88595
  }
87717
88596
  }
87718
88597
  writeFileSync24(file2, buildOpencodePluginSource(port, { version: DAEMON_VERSION }), "utf8");
87719
- const cfgFile = join37(ROOT, "opencode.json");
88598
+ const cfgFile = join38(ROOT, "opencode.json");
87720
88599
  let cfg = { $schema: "https://opencode.ai/config.json" };
87721
- if (existsSync33(cfgFile)) {
88600
+ if (existsSync34(cfgFile)) {
87722
88601
  try {
87723
- cfg = JSON.parse(readFileSync32(cfgFile, "utf8"));
88602
+ cfg = JSON.parse(readFileSync33(cfgFile, "utf8"));
87724
88603
  } catch {
87725
88604
  console.error(`refusing to touch invalid JSON at ${cfgFile} \u2014 fix it and re-run`);
87726
88605
  process.exit(2);
@@ -87751,15 +88630,15 @@ function errataMcpInvocation() {
87751
88630
  return { command: cmd2, args: args2 };
87752
88631
  }
87753
88632
  async function installClaudeHooks(port) {
87754
- const { mkdirSync: mkdirSync9, existsSync: existsSync33, readFileSync: readFileSync32, writeFileSync: writeFileSync24 } = await import("node:fs");
87755
- const { join: join37 } = await import("node:path");
87756
- const dir = join37(ROOT, ".claude");
87757
- if (!existsSync33(dir)) mkdirSync9(dir, { recursive: true });
87758
- const file2 = join37(dir, "settings.json");
88633
+ const { mkdirSync: mkdirSync9, existsSync: existsSync34, readFileSync: readFileSync33, writeFileSync: writeFileSync24 } = await import("node:fs");
88634
+ const { join: join38 } = await import("node:path");
88635
+ const dir = join38(ROOT, ".claude");
88636
+ if (!existsSync34(dir)) mkdirSync9(dir, { recursive: true });
88637
+ const file2 = join38(dir, "settings.json");
87759
88638
  let settings = {};
87760
- if (existsSync33(file2)) {
88639
+ if (existsSync34(file2)) {
87761
88640
  try {
87762
- settings = JSON.parse(readFileSync32(file2, "utf8"));
88641
+ settings = JSON.parse(readFileSync33(file2, "utf8"));
87763
88642
  } catch {
87764
88643
  console.error(`refusing to overwrite invalid JSON at ${file2}`);
87765
88644
  process.exit(2);
@@ -87808,7 +88687,7 @@ async function installClaudeHooks(port) {
87808
88687
  writeFileSync24(file2, JSON.stringify(settings, null, 2) + "\n", "utf8");
87809
88688
  console.log(`installed Claude Code hooks \u2192 ${file2}`);
87810
88689
  await installClaudeMcpConfig();
87811
- const claudeMd = join37(ROOT, "CLAUDE.md");
88690
+ const claudeMd = join38(ROOT, "CLAUDE.md");
87812
88691
  const recall = writeManagedBlock(claudeMd, { body: RECALL_FIRST_BLOCK });
87813
88692
  if (recall.kind === "collision") {
87814
88693
  console.warn(
@@ -87820,15 +88699,15 @@ async function installClaudeHooks(port) {
87820
88699
  console.log(` endpoint: http://127.0.0.1:${port}/api/hook`);
87821
88700
  }
87822
88701
  async function installClaudeMcpConfig() {
87823
- const { mkdirSync: mkdirSync9, existsSync: existsSync33, readFileSync: readFileSync32, writeFileSync: writeFileSync24 } = await import("node:fs");
87824
- const { join: join37, dirname: dirname13 } = await import("node:path");
87825
- const file2 = join37(ROOT, ".mcp.json");
88702
+ const { mkdirSync: mkdirSync9, existsSync: existsSync34, readFileSync: readFileSync33, writeFileSync: writeFileSync24 } = await import("node:fs");
88703
+ const { join: join38, dirname: dirname13 } = await import("node:path");
88704
+ const file2 = join38(ROOT, ".mcp.json");
87826
88705
  const dir = dirname13(file2);
87827
- if (!existsSync33(dir)) mkdirSync9(dir, { recursive: true });
88706
+ if (!existsSync34(dir)) mkdirSync9(dir, { recursive: true });
87828
88707
  let cfg = {};
87829
- if (existsSync33(file2)) {
88708
+ if (existsSync34(file2)) {
87830
88709
  try {
87831
- cfg = JSON.parse(readFileSync32(file2, "utf8"));
88710
+ cfg = JSON.parse(readFileSync33(file2, "utf8"));
87832
88711
  } catch {
87833
88712
  console.error(`refusing to overwrite invalid JSON at ${file2}`);
87834
88713
  process.exit(2);
@@ -87842,15 +88721,15 @@ async function installClaudeMcpConfig() {
87842
88721
  console.log(` Tools: errata.search / locate / neighbors / callers_of / what_uses / show / similar`);
87843
88722
  }
87844
88723
  async function installCursorMcpConfig() {
87845
- const { mkdirSync: mkdirSync9, existsSync: existsSync33, readFileSync: readFileSync32, writeFileSync: writeFileSync24 } = await import("node:fs");
87846
- const { join: join37 } = await import("node:path");
87847
- const dir = join37(ROOT, ".cursor");
87848
- if (!existsSync33(dir)) mkdirSync9(dir, { recursive: true });
87849
- const file2 = join37(dir, "mcp.json");
88724
+ const { mkdirSync: mkdirSync9, existsSync: existsSync34, readFileSync: readFileSync33, writeFileSync: writeFileSync24 } = await import("node:fs");
88725
+ const { join: join38 } = await import("node:path");
88726
+ const dir = join38(ROOT, ".cursor");
88727
+ if (!existsSync34(dir)) mkdirSync9(dir, { recursive: true });
88728
+ const file2 = join38(dir, "mcp.json");
87850
88729
  let cfg = {};
87851
- if (existsSync33(file2)) {
88730
+ if (existsSync34(file2)) {
87852
88731
  try {
87853
- cfg = JSON.parse(readFileSync32(file2, "utf8"));
88732
+ cfg = JSON.parse(readFileSync33(file2, "utf8"));
87854
88733
  } catch {
87855
88734
  console.error(`refusing to overwrite invalid JSON at ${file2}`);
87856
88735
  process.exit(2);
@@ -87866,14 +88745,14 @@ async function installCursorMcpConfig() {
87866
88745
  console.log(` \u26A0\uFE0F reload Cursor (Cmd/Ctrl-Shift-P \u2192 "Reload Window") to pick it up.`);
87867
88746
  }
87868
88747
  async function installCodexHooks(port) {
87869
- const { mkdirSync: mkdirSync9, existsSync: existsSync33, readFileSync: readFileSync32, writeFileSync: writeFileSync24 } = await import("node:fs");
87870
- const { join: join37 } = await import("node:path");
87871
- const dir = join37(ROOT, ".codex");
87872
- if (!existsSync33(dir)) mkdirSync9(dir, { recursive: true });
87873
- const file2 = join37(dir, "config.toml");
88748
+ const { mkdirSync: mkdirSync9, existsSync: existsSync34, readFileSync: readFileSync33, writeFileSync: writeFileSync24 } = await import("node:fs");
88749
+ const { join: join38 } = await import("node:path");
88750
+ const dir = join38(ROOT, ".codex");
88751
+ if (!existsSync34(dir)) mkdirSync9(dir, { recursive: true });
88752
+ const file2 = join38(dir, "config.toml");
87874
88753
  let existing = "";
87875
- if (existsSync33(file2)) {
87876
- existing = readFileSync32(file2, "utf8");
88754
+ if (existsSync34(file2)) {
88755
+ existing = readFileSync33(file2, "utf8");
87877
88756
  const beginIdx = existing.indexOf(CODEX_HOOKS_BEGIN);
87878
88757
  const endIdx = existing.indexOf(CODEX_HOOKS_END);
87879
88758
  if (beginIdx >= 0 && endIdx > beginIdx) {
@@ -88228,7 +89107,7 @@ async function cmdDash(args2) {
88228
89107
  await yieldToLoop2();
88229
89108
  try {
88230
89109
  const items = selectDurableMemory(handle2.sharedStore, r.engine.profile);
88231
- const res = bleedRules(join36(r.root, ".claude", "rules"), items);
89110
+ const res = bleedRules(join37(r.root, ".claude", "rules"), items);
88232
89111
  if (res.written || res.pruned) {
88233
89112
  console.log(
88234
89113
  `[rules:${r.entry.name}] ${res.written} collective principle(s) \u2192 .claude/rules` + (res.pruned ? `, ${res.pruned} pruned` : "")