layermap 0.1.34 → 0.1.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -16772,6 +16772,9 @@ var mapQuerySelection = (input, knownKinds) => {
16772
16772
  return { path: path17, kinds: [...new Set(kinds)].sort() };
16773
16773
  };
16774
16774
  var mapQueryPathMatches = (path17, prefix) => prefix === "." || path17 === prefix || path17.startsWith(`${prefix}/`);
16775
+ var MAP_RELATION_TARGET_JOIN = `LEFT JOIN project_map_unit_objects t ON t.entity_ref = r.to_ref
16776
+ AND EXISTS (SELECT 1 FROM project_map_version_units target
16777
+ WHERE target.version_ref = r.version_ref AND target.unit_ref = t.unit_ref AND target.path = t.path)`;
16775
16778
  var mapQueryPathSql = (column) => `(? = '.' OR ${column} = ? OR substr(${column}, 1, length(?) + 1) = ? || '/')`;
16776
16779
 
16777
16780
  // src/project-map-search-focus.ts
@@ -17003,7 +17006,7 @@ function mapSearchRows(store, input, query, scope, offset, signal) {
17003
17006
  )
17004
17007
  SELECT object.object_json,
17005
17008
  (SELECT count(*) FROM project_map_relations r
17006
- LEFT JOIN project_map_objects t ON t.version_ref = r.version_ref AND t.entity_ref = r.to_ref
17009
+ ${MAP_RELATION_TARGET_JOIN}
17007
17010
  WHERE r.version_ref = object.version_ref AND r.from_ref = object.entity_ref
17008
17011
  AND ${mapSearchAllowedSql("r.path")}
17009
17012
  AND (r.to_ref IS NULL OR ${mapSearchAllowedSql("t.path")})) +
@@ -17122,25 +17125,17 @@ async function mapExploreTraversal(store, input, signal) {
17122
17125
  assertActive();
17123
17126
  };
17124
17127
  await checkpoint();
17125
- const statement = store.database.prepare(`
17128
+ const relations = (seeded, order) => store.database.prepare(`
17126
17129
  SELECT r.relation_ref, r.from_ref, r.to_ref, json_extract(r.relation_json, '$.kind') AS kind
17127
17130
  FROM project_map_relations r
17128
17131
  JOIN project_map_objects f ON f.version_ref = r.version_ref AND f.entity_ref = r.from_ref
17129
- LEFT JOIN project_map_objects t ON t.version_ref = r.version_ref AND t.entity_ref = r.to_ref
17132
+ ${MAP_RELATION_TARGET_JOIN}
17130
17133
  WHERE r.version_ref = ? AND ${allowed("r.path")} AND ${allowed("f.path")}
17131
17134
  AND (r.to_ref IS NULL OR ${allowed("t.path")})
17132
17135
  AND ${mapQueryPathSql("r.path")}
17133
17136
  AND json_extract(r.relation_json, '$.kind') IN (SELECT value FROM json_each(?))
17134
- ${input.scope === "PROJECT" ? `ORDER BY ${relationOrder}` : ""}`);
17135
- const relationRefs = [];
17136
- const adjacency = /* @__PURE__ */ new Map();
17137
- const connect = (ref, edge) => {
17138
- const existing = adjacency.get(ref);
17139
- if (existing) existing.push(edge);
17140
- else adjacency.set(ref, [edge]);
17141
- };
17142
- let inspected = 0;
17143
- for (const row of statement.iterate(
17137
+ ${seeded} ${order}`);
17138
+ const filters = [
17144
17139
  input.version,
17145
17140
  input.authorizationScope,
17146
17141
  input.authorizationScope,
@@ -17150,29 +17145,22 @@ async function mapExploreTraversal(store, input, signal) {
17150
17145
  input.selection.path,
17151
17146
  input.selection.path,
17152
17147
  canonicalJson(input.selection.kinds)
17153
- )) {
17154
- if (++inspected % 256 === 0) await checkpoint();
17155
- const relation = {
17156
- id: String(row.relation_ref),
17157
- from: String(row.from_ref),
17158
- ...row.to_ref === null ? {} : { to: String(row.to_ref) },
17159
- kind: row.kind
17160
- };
17161
- if (input.scope === "PROJECT") {
17162
- relationRefs.push(relation.id);
17163
- continue;
17164
- }
17165
- if (input.direction !== "INCOMING") connect(relation.from, relation);
17166
- if (input.direction !== "OUTGOING" && relation.to && relation.to !== relation.from)
17167
- connect(relation.to, relation);
17168
- else if (input.direction === "INCOMING" && relation.to === relation.from)
17169
- connect(relation.to, relation);
17170
- }
17148
+ ];
17149
+ const relationRefs = [];
17150
+ let inspected = 0;
17171
17151
  if (input.scope === "PROJECT") {
17152
+ for (const row of relations("", `ORDER BY ${relationOrder}`).iterate(...filters)) {
17153
+ if (++inspected % 256 === 0) await checkpoint();
17154
+ relationRefs.push(String(row.relation_ref));
17155
+ }
17172
17156
  assertActive();
17173
17157
  return { relationRefs, frontier: [] };
17174
17158
  }
17175
17159
  if (!input.entityRef) throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
17160
+ const ends = [
17161
+ ...input.direction === "INCOMING" ? [] : ["r.from_ref"],
17162
+ ...input.direction === "OUTGOING" ? [] : ["r.to_ref"]
17163
+ ].map((end) => relations(`AND ${end} IN (SELECT value FROM json_each(?))`, ""));
17176
17164
  const known = /* @__PURE__ */ new Set([input.entityRef]);
17177
17165
  const seenRelations = /* @__PURE__ */ new Set();
17178
17166
  const frontier = [];
@@ -17182,10 +17170,18 @@ async function mapExploreTraversal(store, input, signal) {
17182
17170
  await checkpoint();
17183
17171
  depth++;
17184
17172
  const candidates = /* @__PURE__ */ new Map();
17185
- for (const ref of seeds) {
17186
- for (const edge of adjacency.get(ref) ?? []) {
17173
+ const seedRefs = canonicalJson(seeds);
17174
+ for (const end of ends) {
17175
+ for (const row of end.iterate(...filters, seedRefs)) {
17187
17176
  if (++inspected % 256 === 0) await checkpoint();
17188
- if (!seenRelations.has(edge.id)) candidates.set(edge.id, edge);
17177
+ const id2 = String(row.relation_ref);
17178
+ if (seenRelations.has(id2)) continue;
17179
+ candidates.set(id2, {
17180
+ id: id2,
17181
+ from: String(row.from_ref),
17182
+ ...row.to_ref === null ? {} : { to: String(row.to_ref) },
17183
+ kind: row.kind
17184
+ });
17189
17185
  }
17190
17186
  }
17191
17187
  const next = [];
@@ -19330,7 +19326,7 @@ function loadImports(store, version2) {
19330
19326
  return store.database.prepare(`SELECT r.path AS source, t.path AS target,
19331
19327
  json_extract(r.relation_json, '$.target') AS specifier, count(*) AS count
19332
19328
  FROM project_map_relations r NOT INDEXED
19333
- LEFT JOIN project_map_objects t ON t.version_ref = r.version_ref AND t.entity_ref = r.to_ref
19329
+ ${MAP_RELATION_TARGET_JOIN}
19334
19330
  WHERE r.version_ref = ? AND json_extract(r.relation_json, '$.kind') IN ('IMPORTS', 'TEST_IMPORTS')
19335
19331
  GROUP BY source, target, specifier`).all(version2).map((row) => ({
19336
19332
  source: String(row.source),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "layermap",
3
- "version": "0.1.34",
3
+ "version": "0.1.35",
4
4
  "mcpName": "io.github.coffeecoproject/layermap",
5
5
  "description": "A layered map of a codebase for coding agents: directories, modules and call chains across TypeScript, JavaScript, Go, Python and Java.",
6
6
  "license": "Apache-2.0",
package/pi/layermap.mjs CHANGED
@@ -268,7 +268,7 @@ function layermap(pi) {
268
268
  if (server && !server.dead) return server;
269
269
  starting ??= (async () => {
270
270
  const next = new MapServer(cwd);
271
- const tools = await next.start("0.1.34");
271
+ const tools = await next.start("0.1.35");
272
272
  for (const tool of tools) {
273
273
  if (registered.has(tool.name)) continue;
274
274
  registered.add(tool.name);