sensemaking 0.28.2 → 0.28.3
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/cjs/chunk/extract.js +2 -2
- package/dist/cjs/chunk/extract.js.map +1 -1
- package/dist/cjs/chunk/group.js +14 -14
- package/dist/cjs/chunk/group.js.map +1 -1
- package/dist/cjs/chunk/index.js +13 -13
- package/dist/cjs/chunk/index.js.map +1 -1
- package/dist/cjs/chunk/parse.js +4 -4
- package/dist/cjs/chunk/parse.js.map +1 -1
- package/dist/cjs/chunk/parser.js.map +1 -1
- package/dist/cjs/chunk/tokens.js +2 -2
- package/dist/cjs/chunk/tokens.js.map +1 -1
- package/dist/cjs/cli/build.js +7 -7
- package/dist/cjs/cli/build.js.map +1 -1
- package/dist/cjs/cli/download.js +12 -12
- package/dist/cjs/cli/download.js.map +1 -1
- package/dist/cjs/cli/init.js +6 -6
- package/dist/cjs/cli/init.js.map +1 -1
- package/dist/cjs/cli/map.js +9 -9
- package/dist/cjs/cli/map.js.map +1 -1
- package/dist/cjs/cli/named.js +21 -21
- package/dist/cjs/cli/named.js.map +1 -1
- package/dist/cjs/cli/path.js +10 -10
- package/dist/cjs/cli/path.js.map +1 -1
- package/dist/cjs/cli/peek.js +11 -11
- package/dist/cjs/cli/peek.js.map +1 -1
- package/dist/cjs/cli/related.js +19 -19
- package/dist/cjs/cli/related.js.map +1 -1
- package/dist/cjs/cli/search.js +21 -21
- package/dist/cjs/cli/search.js.map +1 -1
- package/dist/cjs/cli/shared.js +15 -15
- package/dist/cjs/cli/shared.js.map +1 -1
- package/dist/cjs/cli/sql.js +6 -6
- package/dist/cjs/cli/sql.js.map +1 -1
- package/dist/cjs/cli/status.js +40 -40
- package/dist/cjs/cli/status.js.map +1 -1
- package/dist/cjs/cli/watch.js +7 -7
- package/dist/cjs/cli/watch.js.map +1 -1
- package/dist/cjs/cli.js +15 -15
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/commands/index.js +15 -15
- package/dist/cjs/commands/index.js.map +1 -1
- package/dist/cjs/commands/map.js +13 -13
- package/dist/cjs/commands/map.js.map +1 -1
- package/dist/cjs/commands/path.js +16 -16
- package/dist/cjs/commands/path.js.map +1 -1
- package/dist/cjs/commands/peek.js +23 -23
- package/dist/cjs/commands/peek.js.map +1 -1
- package/dist/cjs/commands/related.js +28 -28
- package/dist/cjs/commands/related.js.map +1 -1
- package/dist/cjs/commands/scope.js +10 -10
- package/dist/cjs/commands/scope.js.map +1 -1
- package/dist/cjs/commands/search.js +43 -43
- package/dist/cjs/commands/search.js.map +1 -1
- package/dist/cjs/commands/signals.js +9 -9
- package/dist/cjs/commands/signals.js.map +1 -1
- package/dist/cjs/commands/snapshot.js +11 -11
- package/dist/cjs/commands/snapshot.js.map +1 -1
- package/dist/cjs/commands/status.js +4 -4
- package/dist/cjs/commands/status.js.map +1 -1
- package/dist/cjs/config/access.js +4 -4
- package/dist/cjs/config/access.js.map +1 -1
- package/dist/cjs/config/index.js +31 -31
- package/dist/cjs/config/index.js.map +1 -1
- package/dist/cjs/config/load.js +26 -26
- package/dist/cjs/config/load.js.map +1 -1
- package/dist/cjs/config/resolve.js +4 -4
- package/dist/cjs/config/resolve.js.map +1 -1
- package/dist/cjs/config/validate.js +53 -53
- package/dist/cjs/config/validate.js.map +1 -1
- package/dist/cjs/embed/cohere.js +11 -11
- package/dist/cjs/embed/cohere.js.map +1 -1
- package/dist/cjs/embed/distribution.js +3 -3
- package/dist/cjs/embed/distribution.js.map +1 -1
- package/dist/cjs/embed/endpoint.js.map +1 -1
- package/dist/cjs/embed/handoff.js.map +1 -1
- package/dist/cjs/embed/http.js +3 -3
- package/dist/cjs/embed/http.js.map +1 -1
- package/dist/cjs/embed/identity.js +3 -3
- package/dist/cjs/embed/identity.js.map +1 -1
- package/dist/cjs/embed/langfit.js +7 -7
- package/dist/cjs/embed/langfit.js.map +1 -1
- package/dist/cjs/embed/openai.js +11 -11
- package/dist/cjs/embed/openai.js.map +1 -1
- package/dist/cjs/embed/query.js +35 -35
- package/dist/cjs/embed/query.js.map +1 -1
- package/dist/cjs/embed/registry.js +14 -14
- package/dist/cjs/embed/registry.js.map +1 -1
- package/dist/cjs/embed/static.js +9 -9
- package/dist/cjs/embed/static.js.map +1 -1
- package/dist/cjs/embed/store.js +47 -47
- package/dist/cjs/embed/store.js.map +1 -1
- package/dist/cjs/features/embed.js +16 -16
- package/dist/cjs/features/embed.js.map +1 -1
- package/dist/cjs/features/index.js +15 -15
- package/dist/cjs/features/index.js.map +1 -1
- package/dist/cjs/features/links.js +4 -4
- package/dist/cjs/features/links.js.map +1 -1
- package/dist/cjs/features/rank.js +4 -4
- package/dist/cjs/features/rank.js.map +1 -1
- package/dist/cjs/features/sections.js +7 -7
- package/dist/cjs/features/sections.js.map +1 -1
- package/dist/cjs/features/tags.js +4 -4
- package/dist/cjs/features/tags.js.map +1 -1
- package/dist/cjs/graph/graph.js.map +1 -1
- package/dist/cjs/graph/traverse.js +2 -2
- package/dist/cjs/graph/traverse.js.map +1 -1
- package/dist/cjs/index.js +27 -27
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/atomic-write.js.map +1 -1
- package/dist/cjs/lib/watch-notification.js +2 -2
- package/dist/cjs/lib/watch-notification.js.map +1 -1
- package/dist/cjs/lib/worker-file.js.map +1 -1
- package/dist/cjs/output/output.js.map +1 -1
- package/dist/cjs/output/progress.js.map +1 -1
- package/dist/cjs/output/search-error.js +7 -7
- package/dist/cjs/output/search-error.js.map +1 -1
- package/dist/cjs/scan/frontmatter.js.map +1 -1
- package/dist/cjs/scan/index.js +18 -18
- package/dist/cjs/scan/index.js.map +1 -1
- package/dist/cjs/scan/list.js +5 -5
- package/dist/cjs/scan/list.js.map +1 -1
- package/dist/cjs/scan/pool.js +4 -4
- package/dist/cjs/scan/pool.js.map +1 -1
- package/dist/cjs/scan/reparse.js +4 -4
- package/dist/cjs/scan/reparse.js.map +1 -1
- package/dist/cjs/scan/worker-error.js +3 -3
- package/dist/cjs/scan/worker-error.js.map +1 -1
- package/dist/cjs/store/builder.js +60 -60
- package/dist/cjs/store/builder.js.map +1 -1
- package/dist/cjs/store/cache.js +2 -2
- package/dist/cjs/store/cache.js.map +1 -1
- package/dist/cjs/store/duckdb/batch.js +2 -2
- package/dist/cjs/store/duckdb/batch.js.map +1 -1
- package/dist/cjs/store/duckdb/connection.js +9 -9
- package/dist/cjs/store/duckdb/connection.js.map +1 -1
- package/dist/cjs/store/duckdb/engine.js +4 -4
- package/dist/cjs/store/duckdb/engine.js.map +1 -1
- package/dist/cjs/store/duckdb/fieldStats.js +2 -2
- package/dist/cjs/store/duckdb/fieldStats.js.map +1 -1
- package/dist/cjs/store/duckdb/lexical.js +27 -27
- package/dist/cjs/store/duckdb/lexical.js.map +1 -1
- package/dist/cjs/store/duckdb/native.js +3 -3
- package/dist/cjs/store/duckdb/native.js.map +1 -1
- package/dist/cjs/store/duckdb/open.js +39 -39
- package/dist/cjs/store/duckdb/open.js.map +1 -1
- package/dist/cjs/store/duckdb/reconcile.js +14 -14
- package/dist/cjs/store/duckdb/reconcile.js.map +1 -1
- package/dist/cjs/store/duckdb/sql-functions.js +7 -7
- package/dist/cjs/store/duckdb/sql-functions.js.map +1 -1
- package/dist/cjs/store/duckdb/store.js +18 -18
- package/dist/cjs/store/duckdb/store.js.map +1 -1
- package/dist/cjs/store/duckdb/vectors.js +10 -10
- package/dist/cjs/store/duckdb/vectors.js.map +1 -1
- package/dist/cjs/store/engine.js +2 -2
- package/dist/cjs/store/engine.js.map +1 -1
- package/dist/cjs/store/index.js +37 -37
- package/dist/cjs/store/index.js.map +1 -1
- package/dist/cjs/store/lock-wait.js +2 -2
- package/dist/cjs/store/lock-wait.js.map +1 -1
- package/dist/cjs/store/native.js +13 -5
- package/dist/cjs/store/native.js.map +1 -1
- package/dist/cjs/store/open.js +43 -43
- package/dist/cjs/store/open.js.map +1 -1
- package/dist/cjs/store/preset-scope.js +4 -4
- package/dist/cjs/store/preset-scope.js.map +1 -1
- package/dist/cjs/store/reconcile.js +27 -27
- package/dist/cjs/store/reconcile.js.map +1 -1
- package/dist/cjs/store/shared.js.map +1 -1
- package/dist/cjs/store/sql-functions.js.map +1 -1
- package/dist/cjs/store/sqlite/connection.js +3 -3
- package/dist/cjs/store/sqlite/connection.js.map +1 -1
- package/dist/cjs/store/sqlite/engine.js +3 -3
- package/dist/cjs/store/sqlite/engine.js.map +1 -1
- package/dist/cjs/store/sqlite/fieldStats.js +2 -2
- package/dist/cjs/store/sqlite/fieldStats.js.map +1 -1
- package/dist/cjs/store/sqlite/lexical.js +4 -4
- package/dist/cjs/store/sqlite/lexical.js.map +1 -1
- package/dist/cjs/store/sqlite/open.js +31 -31
- package/dist/cjs/store/sqlite/open.js.map +1 -1
- package/dist/cjs/store/sqlite/reconcile.js +11 -11
- package/dist/cjs/store/sqlite/reconcile.js.map +1 -1
- package/dist/cjs/store/sqlite/sql-functions.js +5 -5
- package/dist/cjs/store/sqlite/sql-functions.js.map +1 -1
- package/dist/cjs/store/sqlite/store.js +16 -16
- package/dist/cjs/store/sqlite/store.js.map +1 -1
- package/dist/cjs/store/sqlite/vectors.js +8 -8
- package/dist/cjs/store/sqlite/vectors.js.map +1 -1
- package/dist/cjs/store/transaction.js.map +1 -1
- package/dist/cjs/store/turso/connection.js +14 -14
- package/dist/cjs/store/turso/connection.js.map +1 -1
- package/dist/cjs/store/turso/engine.js +4 -4
- package/dist/cjs/store/turso/engine.js.map +1 -1
- package/dist/cjs/store/turso/fieldStats.js +2 -2
- package/dist/cjs/store/turso/fieldStats.js.map +1 -1
- package/dist/cjs/store/turso/lexical-text.js +3 -3
- package/dist/cjs/store/turso/lexical-text.js.map +1 -1
- package/dist/cjs/store/turso/lexical.js +12 -12
- package/dist/cjs/store/turso/lexical.js.map +1 -1
- package/dist/cjs/store/turso/native.js +3 -3
- package/dist/cjs/store/turso/native.js.map +1 -1
- package/dist/cjs/store/turso/open.js +40 -40
- package/dist/cjs/store/turso/open.js.map +1 -1
- package/dist/cjs/store/turso/reconcile.js +15 -15
- package/dist/cjs/store/turso/reconcile.js.map +1 -1
- package/dist/cjs/store/turso/sql-functions.js +2 -2
- package/dist/cjs/store/turso/sql-functions.js.map +1 -1
- package/dist/cjs/store/turso/store.js +25 -25
- package/dist/cjs/store/turso/store.js.map +1 -1
- package/dist/cjs/store/turso/vectors.js +8 -8
- package/dist/cjs/store/turso/vectors.js.map +1 -1
- package/dist/cjs/text/segment.js.map +1 -1
- package/dist/cjs/text/strip.js +4 -4
- package/dist/cjs/text/strip.js.map +1 -1
- package/dist/cjs/watch-claim.js +11 -11
- package/dist/cjs/watch-claim.js.map +1 -1
- package/dist/cjs/watch.js +18 -18
- package/dist/cjs/watch.js.map +1 -1
- package/dist/cjs/workers/parse.js +7 -7
- package/dist/cjs/workers/parse.js.map +1 -1
- package/dist/cjs/workers/watch-heartbeat.js +8 -8
- package/dist/cjs/workers/watch-heartbeat.js.map +1 -1
- package/dist/esm/chunk/extract.js +1 -1
- package/dist/esm/chunk/extract.js.map +1 -1
- package/dist/esm/chunk/group.js +3 -3
- package/dist/esm/chunk/group.js.map +1 -1
- package/dist/esm/chunk/index.js +6 -6
- package/dist/esm/chunk/parse.js +2 -2
- package/dist/esm/chunk/tokens.js +1 -1
- package/dist/esm/cli/build.js +3 -3
- package/dist/esm/cli/download.js +5 -5
- package/dist/esm/cli/index.js +11 -11
- package/dist/esm/cli/init.js +3 -3
- package/dist/esm/cli/map.js +4 -4
- package/dist/esm/cli/named.js +7 -7
- package/dist/esm/cli/path.js +4 -4
- package/dist/esm/cli/path.js.map +1 -1
- package/dist/esm/cli/peek.js +4 -4
- package/dist/esm/cli/related.js +7 -7
- package/dist/esm/cli/search.js +7 -7
- package/dist/esm/cli/search.js.map +1 -1
- package/dist/esm/cli/shared.js +6 -6
- package/dist/esm/cli/shared.js.map +1 -1
- package/dist/esm/cli/sql.js +2 -2
- package/dist/esm/cli/status.js +11 -11
- package/dist/esm/cli/status.js.map +1 -1
- package/dist/esm/cli/watch.js +3 -3
- package/dist/esm/cli.js +4 -4
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/commands/index.js +7 -7
- package/dist/esm/commands/map.js +5 -5
- package/dist/esm/commands/map.js.map +1 -1
- package/dist/esm/commands/path.js +7 -7
- package/dist/esm/commands/path.js.map +1 -1
- package/dist/esm/commands/peek.js +6 -6
- package/dist/esm/commands/peek.js.map +1 -1
- package/dist/esm/commands/related.js +8 -8
- package/dist/esm/commands/related.js.map +1 -1
- package/dist/esm/commands/scope.js +3 -3
- package/dist/esm/commands/scope.js.map +1 -1
- package/dist/esm/commands/search.js +10 -10
- package/dist/esm/commands/search.js.map +1 -1
- package/dist/esm/commands/signals.js +4 -4
- package/dist/esm/commands/signals.js.map +1 -1
- package/dist/esm/commands/snapshot.js +4 -4
- package/dist/esm/commands/status.js +1 -1
- package/dist/esm/commands/status.js.map +1 -1
- package/dist/esm/config/access.js +1 -1
- package/dist/esm/config/index.js +6 -6
- package/dist/esm/config/load.js +4 -4
- package/dist/esm/config/load.js.map +1 -1
- package/dist/esm/config/resolve.js +2 -2
- package/dist/esm/config/validate.js +3 -3
- package/dist/esm/config/validate.js.map +1 -1
- package/dist/esm/embed/cohere.js +3 -3
- package/dist/esm/embed/cohere.js.map +1 -1
- package/dist/esm/embed/distribution.js +1 -1
- package/dist/esm/embed/http.js +1 -1
- package/dist/esm/embed/identity.js +1 -1
- package/dist/esm/embed/langfit.js +3 -3
- package/dist/esm/embed/openai.js +3 -3
- package/dist/esm/embed/openai.js.map +1 -1
- package/dist/esm/embed/query.js +13 -13
- package/dist/esm/embed/query.js.map +1 -1
- package/dist/esm/embed/registry.js +6 -6
- package/dist/esm/embed/registry.js.map +1 -1
- package/dist/esm/embed/static.js +2 -2
- package/dist/esm/embed/store.js +7 -7
- package/dist/esm/embed/store.js.map +1 -1
- package/dist/esm/features/embed.js +7 -7
- package/dist/esm/features/embed.js.map +1 -1
- package/dist/esm/features/index.js +7 -7
- package/dist/esm/features/links.js +2 -2
- package/dist/esm/features/links.js.map +1 -1
- package/dist/esm/features/rank.js +2 -2
- package/dist/esm/features/rank.js.map +1 -1
- package/dist/esm/features/sections.js +3 -3
- package/dist/esm/features/tags.js +2 -2
- package/dist/esm/graph/graph.js.map +1 -1
- package/dist/esm/graph/traverse.js +1 -1
- package/dist/esm/index.js +6 -6
- package/dist/esm/lib/atomic-write.js.map +1 -1
- package/dist/esm/lib/watch-notification.js +1 -1
- package/dist/esm/output/output.js.map +1 -1
- package/dist/esm/output/progress.js.map +1 -1
- package/dist/esm/output/search-error.js +2 -2
- package/dist/esm/scan/index.js +5 -5
- package/dist/esm/scan/list.js +1 -1
- package/dist/esm/scan/pool.js +2 -2
- package/dist/esm/scan/pool.js.map +1 -1
- package/dist/esm/scan/reparse.js +2 -2
- package/dist/esm/scan/reparse.js.map +1 -1
- package/dist/esm/scan/worker-error.js +1 -1
- package/dist/esm/store/builder.js +16 -16
- package/dist/esm/store/builder.js.map +1 -1
- package/dist/esm/store/cache.js +1 -1
- package/dist/esm/store/duckdb/batch.js +1 -1
- package/dist/esm/store/duckdb/connection.js +4 -4
- package/dist/esm/store/duckdb/engine.js +2 -2
- package/dist/esm/store/duckdb/engine.js.map +1 -1
- package/dist/esm/store/duckdb/fieldStats.js +1 -1
- package/dist/esm/store/duckdb/lexical.js +6 -6
- package/dist/esm/store/duckdb/lexical.js.map +1 -1
- package/dist/esm/store/duckdb/native.js +1 -1
- package/dist/esm/store/duckdb/native.js.map +1 -1
- package/dist/esm/store/duckdb/open.js +14 -14
- package/dist/esm/store/duckdb/open.js.map +1 -1
- package/dist/esm/store/duckdb/reconcile.js +4 -4
- package/dist/esm/store/duckdb/reconcile.js.map +1 -1
- package/dist/esm/store/duckdb/sql-functions.js +3 -3
- package/dist/esm/store/duckdb/store.js +8 -8
- package/dist/esm/store/duckdb/vectors.js +3 -3
- package/dist/esm/store/duckdb/vectors.js.map +1 -1
- package/dist/esm/store/engine.js +1 -1
- package/dist/esm/store/index.js +13 -13
- package/dist/esm/store/lock-wait.js +1 -1
- package/dist/esm/store/native.js +11 -3
- package/dist/esm/store/native.js.map +1 -1
- package/dist/esm/store/open.js +14 -14
- package/dist/esm/store/open.js.map +1 -1
- package/dist/esm/store/preset-scope.js +2 -2
- package/dist/esm/store/reconcile.js +8 -8
- package/dist/esm/store/reconcile.js.map +1 -1
- package/dist/esm/store/sqlite/connection.js +1 -1
- package/dist/esm/store/sqlite/engine.js +1 -1
- package/dist/esm/store/sqlite/fieldStats.js +1 -1
- package/dist/esm/store/sqlite/lexical.js +2 -2
- package/dist/esm/store/sqlite/open.js +11 -11
- package/dist/esm/store/sqlite/open.js.map +1 -1
- package/dist/esm/store/sqlite/reconcile.js +4 -4
- package/dist/esm/store/sqlite/sql-functions.js +2 -2
- package/dist/esm/store/sqlite/store.js +6 -6
- package/dist/esm/store/sqlite/vectors.js +1 -1
- package/dist/esm/store/sqlite/vectors.js.map +1 -1
- package/dist/esm/store/turso/connection.js +5 -5
- package/dist/esm/store/turso/connection.js.map +1 -1
- package/dist/esm/store/turso/engine.js +2 -2
- package/dist/esm/store/turso/engine.js.map +1 -1
- package/dist/esm/store/turso/fieldStats.js +1 -1
- package/dist/esm/store/turso/lexical-text.js +1 -1
- package/dist/esm/store/turso/lexical.js +4 -4
- package/dist/esm/store/turso/lexical.js.map +1 -1
- package/dist/esm/store/turso/native.js +1 -1
- package/dist/esm/store/turso/native.js.map +1 -1
- package/dist/esm/store/turso/open.js +13 -13
- package/dist/esm/store/turso/open.js.map +1 -1
- package/dist/esm/store/turso/reconcile.js +6 -6
- package/dist/esm/store/turso/reconcile.js.map +1 -1
- package/dist/esm/store/turso/sql-functions.js +1 -1
- package/dist/esm/store/turso/store.js +8 -8
- package/dist/esm/store/turso/store.js.map +1 -1
- package/dist/esm/store/turso/vectors.js +1 -1
- package/dist/esm/store/turso/vectors.js.map +1 -1
- package/dist/esm/text/segment.js.map +1 -1
- package/dist/esm/text/strip.js +2 -2
- package/dist/esm/watch-claim.js +5 -5
- package/dist/esm/watch-claim.js.map +1 -1
- package/dist/esm/watch.js +5 -5
- package/dist/esm/watch.js.map +1 -1
- package/dist/esm/workers/parse.js +4 -4
- package/dist/esm/workers/watch-heartbeat.js +3 -3
- package/package.json +4 -3
|
@@ -8,13 +8,13 @@ Object.defineProperty(exports, "findPath", {
|
|
|
8
8
|
return findPath;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var
|
|
11
|
+
var _index = require("../config/index.js");
|
|
12
|
+
var _errors = require("../errors.js");
|
|
13
|
+
var _traverse = require("../graph/traverse.js");
|
|
14
|
+
var _serialquery = require("../lib/serial-query.js");
|
|
15
|
+
var _peek = require("./peek.js");
|
|
16
|
+
var _scope = require("./scope.js");
|
|
17
|
+
var _snapshot = require("./snapshot.js");
|
|
18
18
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
19
19
|
try {
|
|
20
20
|
var info = gen[key](arg);
|
|
@@ -142,7 +142,7 @@ function _ts_generator(thisArg, body) {
|
|
|
142
142
|
}
|
|
143
143
|
function findPath(store, cfg, fromArg, toArg) {
|
|
144
144
|
var options = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {};
|
|
145
|
-
return (0,
|
|
145
|
+
return (0, _serialquery.serialQuery)(store, function() {
|
|
146
146
|
return findScopedPath(store, cfg, fromArg, toArg, options);
|
|
147
147
|
});
|
|
148
148
|
}
|
|
@@ -150,11 +150,11 @@ function findScopedPath(store, cfg, fromArg, toArg, options) {
|
|
|
150
150
|
return _async_to_generator(function() {
|
|
151
151
|
return _ts_generator(this, function(_state) {
|
|
152
152
|
if (options.maxDepth !== undefined && (!Number.isFinite(options.maxDepth) || !Number.isInteger(options.maxDepth) || options.maxDepth <= 0)) {
|
|
153
|
-
throw new
|
|
153
|
+
throw new _errors.SenseError('SEARCH_OPTION_INVALID', 'path option "maxDepth" must be a positive finite integer, got '.concat(String(options.maxDepth)));
|
|
154
154
|
}
|
|
155
155
|
// Validate the named preset before opening the snapshot; repeat it inside because preset_files
|
|
156
156
|
// and the compatibility assertion below belong to the final published generation.
|
|
157
|
-
(0,
|
|
157
|
+
(0, _index.resolveSearch)(cfg, options);
|
|
158
158
|
return [
|
|
159
159
|
2,
|
|
160
160
|
store.transaction(function() {
|
|
@@ -165,11 +165,11 @@ function findScopedPath(store, cfg, fromArg, toArg, options) {
|
|
|
165
165
|
case 0:
|
|
166
166
|
return [
|
|
167
167
|
4,
|
|
168
|
-
(0,
|
|
168
|
+
(0, _snapshot.assertQuerySnapshot)(store, cfg)
|
|
169
169
|
];
|
|
170
170
|
case 1:
|
|
171
171
|
_state.sent();
|
|
172
|
-
(0,
|
|
172
|
+
(0, _index.resolveSearch)(cfg, options);
|
|
173
173
|
return [
|
|
174
174
|
4,
|
|
175
175
|
store.prepare('SELECT "path" FROM frontmatter')
|
|
@@ -183,17 +183,17 @@ function findScopedPath(store, cfg, fromArg, toArg, options) {
|
|
|
183
183
|
paths = _state.sent().map(function(row) {
|
|
184
184
|
return row.path;
|
|
185
185
|
});
|
|
186
|
-
from = (0,
|
|
187
|
-
to = (0,
|
|
186
|
+
from = (0, _peek.resolveNote)(paths, fromArg);
|
|
187
|
+
to = (0, _peek.resolveNote)(paths, toArg);
|
|
188
188
|
return [
|
|
189
189
|
4,
|
|
190
|
-
(0,
|
|
190
|
+
(0, _scope.scopedPaths)(store, cfg, options)
|
|
191
191
|
];
|
|
192
192
|
case 4:
|
|
193
193
|
allowed = _state.sent();
|
|
194
194
|
return [
|
|
195
195
|
2,
|
|
196
|
-
(0,
|
|
196
|
+
(0, _traverse.findPathInSnapshot)(store, from, to, {
|
|
197
197
|
maxDepth: options.maxDepth,
|
|
198
198
|
allowed: allowed
|
|
199
199
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/sensemaking/src/commands/path.ts"],"sourcesContent":["import type { ResolvedConfig, SearchOverrides } from '../config/index.ts';\nimport { resolveSearch } from '../config/index.ts';\nimport { SenseError } from '../errors.ts';\nimport { findPathInSnapshot } from '../graph/traverse.ts';\nimport { serialQuery } from '../lib/serial-query.ts';\nimport type { Store } from '../store/types.ts';\nimport { resolveNote } from './peek.ts';\nimport { scopedPaths } from './scope.ts';\nimport { assertQuerySnapshot } from './snapshot.ts';\n\n/**\n * Options for {@link findPath}. Scope fields constrain intermediate nodes; `maxDepth` limits the\n * number of traversed links and must be a positive integer when supplied.\n */\nexport type PathOptions = Omit<SearchOverrides, 'k'> & {\n maxDepth?: number;\n};\n\n/**\n * Finds the shortest undirected link path between two indexed notes. Endpoints resolve across\n * the indexed tree and remain permitted outside the scope applied to intermediate nodes.\n */\nexport function findPath(store: Store, cfg: ResolvedConfig, fromArg: string, toArg: string, options: PathOptions = {}): Promise<string[] | null> {\n return serialQuery(store, () => findScopedPath(store, cfg, fromArg, toArg, options));\n}\n\nasync function findScopedPath(store: Store, cfg: ResolvedConfig, fromArg: string, toArg: string, options: PathOptions): Promise<string[] | null> {\n if (options.maxDepth !== undefined && (!Number.isFinite(options.maxDepth) || !Number.isInteger(options.maxDepth) || options.maxDepth <= 0)) {\n throw new SenseError('SEARCH_OPTION_INVALID', `path option \"maxDepth\" must be a positive finite integer, got ${String(options.maxDepth)}`);\n }\n // Validate the named preset before opening the snapshot; repeat it inside because preset_files\n // and the compatibility assertion below belong to the final published generation.\n resolveSearch(cfg, options);\n return store.transaction(async () => {\n await assertQuerySnapshot(store, cfg);\n resolveSearch(cfg, options);\n const paths = ((await (await store.prepare('SELECT \"path\" FROM frontmatter')).all()) as Array<{ path: string }>).map((row) => row.path);\n const from = resolveNote(paths, fromArg);\n const to = resolveNote(paths, toArg);\n const allowed = await scopedPaths(store, cfg, options);\n return findPathInSnapshot(store, from, to, { maxDepth: options.maxDepth, allowed });\n });\n}\n"],"names":["findPath","store","cfg","fromArg","toArg","options","serialQuery","findScopedPath","maxDepth","undefined","Number","isFinite","isInteger","SenseError","String","resolveSearch","transaction","paths","from","to","allowed","assertQuerySnapshot","prepare","all","map","row","path","resolveNote","scopedPaths","findPathInSnapshot"],"mappings":";;;;+BAsBgBA;;;eAAAA;;;
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/sensemaking/src/commands/path.ts"],"sourcesContent":["import type { ResolvedConfig, SearchOverrides } from '../config/index.ts';\nimport { resolveSearch } from '../config/index.ts';\nimport { SenseError } from '../errors.ts';\nimport { findPathInSnapshot } from '../graph/traverse.ts';\nimport { serialQuery } from '../lib/serial-query.ts';\nimport type { Store } from '../store/types.ts';\nimport { resolveNote } from './peek.ts';\nimport { scopedPaths } from './scope.ts';\nimport { assertQuerySnapshot } from './snapshot.ts';\n\n/**\n * Options for {@link findPath}. Scope fields constrain intermediate nodes; `maxDepth` limits the\n * number of traversed links and must be a positive integer when supplied.\n */\nexport type PathOptions = Omit<SearchOverrides, 'k'> & {\n maxDepth?: number;\n};\n\n/**\n * Finds the shortest undirected link path between two indexed notes. Endpoints resolve across\n * the indexed tree and remain permitted outside the scope applied to intermediate nodes.\n */\nexport function findPath(store: Store, cfg: ResolvedConfig, fromArg: string, toArg: string, options: PathOptions = {}): Promise<string[] | null> {\n return serialQuery(store, () => findScopedPath(store, cfg, fromArg, toArg, options));\n}\n\nasync function findScopedPath(store: Store, cfg: ResolvedConfig, fromArg: string, toArg: string, options: PathOptions): Promise<string[] | null> {\n if (options.maxDepth !== undefined && (!Number.isFinite(options.maxDepth) || !Number.isInteger(options.maxDepth) || options.maxDepth <= 0)) {\n throw new SenseError('SEARCH_OPTION_INVALID', `path option \"maxDepth\" must be a positive finite integer, got ${String(options.maxDepth)}`);\n }\n // Validate the named preset before opening the snapshot; repeat it inside because preset_files\n // and the compatibility assertion below belong to the final published generation.\n resolveSearch(cfg, options);\n return store.transaction(async () => {\n await assertQuerySnapshot(store, cfg);\n resolveSearch(cfg, options);\n const paths = ((await (await store.prepare('SELECT \"path\" FROM frontmatter')).all()) as Array<{ path: string }>).map((row) => row.path);\n const from = resolveNote(paths, fromArg);\n const to = resolveNote(paths, toArg);\n const allowed = await scopedPaths(store, cfg, options);\n return findPathInSnapshot(store, from, to, { maxDepth: options.maxDepth, allowed });\n });\n}\n"],"names":["findPath","store","cfg","fromArg","toArg","options","serialQuery","findScopedPath","maxDepth","undefined","Number","isFinite","isInteger","SenseError","String","resolveSearch","transaction","paths","from","to","allowed","assertQuerySnapshot","prepare","all","map","row","path","resolveNote","scopedPaths","findPathInSnapshot"],"mappings":";;;;+BAsBgBA;;;eAAAA;;;aArBc,QAAA;cACH,QAAA;gBACQ,QAAA;mBACP,QAAA;YAEA,QAAA;aACA,QAAA;gBACQ,QAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAc7B,SAASA,SAASC,KAAY,EAAEC,GAAmB,EAAEC,OAAe,EAAEC,KAAa;QAAEC,UAAAA,iEAAuB,CAAC;IAClH,OAAOC,IAAAA,wBAAW,EAACL,OAAO;eAAMM,eAAeN,OAAOC,KAAKC,SAASC,OAAOC;;AAC7E;AAEA,SAAeE,eAAeN,KAAY,EAAEC,GAAmB,EAAEC,OAAe,EAAEC,KAAa,EAAEC,OAAoB;;;YACnH,IAAIA,QAAQG,QAAQ,KAAKC,aAAc,CAAA,CAACC,OAAOC,QAAQ,CAACN,QAAQG,QAAQ,KAAK,CAACE,OAAOE,SAAS,CAACP,QAAQG,QAAQ,KAAKH,QAAQG,QAAQ,IAAI,CAAC,GAAG;gBAC1I,MAAM,IAAIK,kBAAU,CAAC,yBAAyB,AAAC,iEAAyF,OAAzBC,OAAOT,QAAQG,QAAQ;YACxI;YACA,+FAA+F;YAC/F,kFAAkF;YAClFO,IAAAA,oBAAa,EAACb,KAAKG;YACnB;;gBAAOJ,MAAMe,WAAW,CAAC;;4BAGjBC,OACAC,MACAC,IACAC;;;;oCALN;;wCAAMC,IAAAA,6BAAmB,EAACpB,OAAOC;;;oCAAjC;oCACAa,IAAAA,oBAAa,EAACb,KAAKG;oCACI;;wCAAMJ,MAAMqB,OAAO,CAAC;;;oCAA3B;;wCAAO,cAAuDC,GAAG;;;oCAA3EN,QAAQ,AAAE,cAAiGO,GAAG,CAAC,SAACC;+CAAQA,IAAIC,IAAI;;oCAChIR,OAAOS,IAAAA,iBAAW,EAACV,OAAOd;oCAC1BgB,KAAKQ,IAAAA,iBAAW,EAACV,OAAOb;oCACd;;wCAAMwB,IAAAA,kBAAW,EAAC3B,OAAOC,KAAKG;;;oCAAxCe,UAAU;oCAChB;;wCAAOS,IAAAA,4BAAkB,EAAC5B,OAAOiB,MAAMC,IAAI;4CAAEX,UAAUH,QAAQG,QAAQ;4CAAEY,SAAAA;wCAAQ;;;;oBACnF;;;;IACF"}
|
|
@@ -17,12 +17,12 @@ _export(exports, {
|
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
var _posix = /*#__PURE__*/ _interop_require_default(require("node:path/posix"));
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var
|
|
20
|
+
var _index = require("../chunk/index.js");
|
|
21
|
+
var _index1 = require("../config/index.js");
|
|
22
|
+
var _errors = require("../errors.js");
|
|
23
|
+
var _serialquery = require("../lib/serial-query.js");
|
|
24
|
+
var _scope = require("./scope.js");
|
|
25
|
+
var _snapshot = require("./snapshot.js");
|
|
26
26
|
function _array_like_to_array(arr, len) {
|
|
27
27
|
if (len == null || len > arr.length) len = arr.length;
|
|
28
28
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
@@ -229,13 +229,13 @@ function resolveNote(paths, arg) {
|
|
|
229
229
|
return _posix.default.basename(p).replace(/\.md$/i, '').toLowerCase() === base;
|
|
230
230
|
});
|
|
231
231
|
if (matches.length === 1) return matches[0];
|
|
232
|
-
if (matches.length > 1) throw new
|
|
233
|
-
throw new
|
|
232
|
+
if (matches.length > 1) throw new _errors.SenseError('NOTE_AMBIGUOUS', '"'.concat(arg, '" is ambiguous: ').concat(matches.join(', ')));
|
|
233
|
+
throw new _errors.SenseError('NOTE_NOT_FOUND', 'no note matches "'.concat(arg, '"'));
|
|
234
234
|
}
|
|
235
235
|
var PEEK_COUNT_LIMIT = 20;
|
|
236
236
|
function peek(store, cfg, pathArg) {
|
|
237
237
|
var overrides = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
238
|
-
return (0,
|
|
238
|
+
return (0, _serialquery.serialQuery)(store, function() {
|
|
239
239
|
return peekIndexed(store, cfg, pathArg, overrides);
|
|
240
240
|
});
|
|
241
241
|
}
|
|
@@ -250,7 +250,7 @@ function peekIndexed(store, cfg, pathArg, overrides) {
|
|
|
250
250
|
name = _iter[_i];
|
|
251
251
|
value = overrides[name];
|
|
252
252
|
if (value !== undefined && (!Number.isSafeInteger(value) || value <= 0)) {
|
|
253
|
-
throw new
|
|
253
|
+
throw new _errors.SenseError('SEARCH_OPTION_INVALID', 'peek option "'.concat(name, '" must be a positive safe integer, got ').concat(String(value)));
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
256
|
sectionCountLimit = (_overrides_sectionCountLimit = overrides.sectionCountLimit) !== null && _overrides_sectionCountLimit !== void 0 ? _overrides_sectionCountLimit : PEEK_COUNT_LIMIT;
|
|
@@ -265,7 +265,7 @@ function peekIndexed(store, cfg, pathArg, overrides) {
|
|
|
265
265
|
case 0:
|
|
266
266
|
return [
|
|
267
267
|
4,
|
|
268
|
-
(0,
|
|
268
|
+
(0, _snapshot.assertQuerySnapshot)(store, cfg)
|
|
269
269
|
];
|
|
270
270
|
case 1:
|
|
271
271
|
_state.sent();
|
|
@@ -285,27 +285,27 @@ function peekIndexed(store, cfg, pathArg, overrides) {
|
|
|
285
285
|
});
|
|
286
286
|
return [
|
|
287
287
|
4,
|
|
288
|
-
(0,
|
|
288
|
+
(0, _scope.scopedPaths)(store, cfg, overrides)
|
|
289
289
|
];
|
|
290
290
|
case 4:
|
|
291
291
|
allowed = _state.sent();
|
|
292
292
|
if (paths.includes(pathArg) && !allowed.has(pathArg)) {
|
|
293
|
-
throw new
|
|
293
|
+
throw new _errors.SenseError('NOTE_NOT_FOUND', 'note "'.concat(pathArg, '" exists but is outside the current scope; change the preset, include/exclude patterns, or where condition'));
|
|
294
294
|
}
|
|
295
295
|
try {
|
|
296
296
|
path = resolveNote(_to_consumable_array(allowed), pathArg);
|
|
297
297
|
} catch (err) {
|
|
298
|
-
if (_instanceof(err,
|
|
298
|
+
if (_instanceof(err, _errors.SenseError) && err.code === 'NOTE_NOT_FOUND') {
|
|
299
299
|
;
|
|
300
300
|
try {
|
|
301
301
|
excludedPath = resolveNote(paths, pathArg);
|
|
302
302
|
} catch (unscopedErr) {
|
|
303
|
-
if (_instanceof(unscopedErr,
|
|
304
|
-
throw new
|
|
303
|
+
if (_instanceof(unscopedErr, _errors.SenseError) && unscopedErr.code === 'NOTE_AMBIGUOUS') {
|
|
304
|
+
throw new _errors.SenseError('NOTE_NOT_FOUND', 'no note in the current scope matches "'.concat(pathArg, '"; indexed matches exist outside the scope, so change the preset, include/exclude patterns, or where condition'));
|
|
305
305
|
}
|
|
306
306
|
throw err;
|
|
307
307
|
}
|
|
308
|
-
throw new
|
|
308
|
+
throw new _errors.SenseError('NOTE_NOT_FOUND', 'note "'.concat(excludedPath, '" exists but is outside the current scope; change the preset, include/exclude patterns, or where condition'));
|
|
309
309
|
}
|
|
310
310
|
throw err;
|
|
311
311
|
}
|
|
@@ -327,7 +327,7 @@ function peekIndexed(store, cfg, pathArg, overrides) {
|
|
|
327
327
|
try {
|
|
328
328
|
for(_iterator = Object.entries(row)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
329
329
|
_step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
|
|
330
|
-
if (!
|
|
330
|
+
if (!_scope.INTERNAL_COLUMNS.has(key) && value !== null) frontmatter[key] = value;
|
|
331
331
|
}
|
|
332
332
|
} catch (err) {
|
|
333
333
|
_didIteratorError = true;
|
|
@@ -345,7 +345,7 @@ function peekIndexed(store, cfg, pathArg, overrides) {
|
|
|
345
345
|
}
|
|
346
346
|
sectionsTotal = 0;
|
|
347
347
|
sections = [];
|
|
348
|
-
if (!(0,
|
|
348
|
+
if (!(0, _index1.featureEnabled)(cfg, 'sections')) return [
|
|
349
349
|
3,
|
|
350
350
|
11
|
|
351
351
|
];
|
|
@@ -379,13 +379,13 @@ function peekIndexed(store, cfg, pathArg, overrides) {
|
|
|
379
379
|
outboundTotal = 0;
|
|
380
380
|
backlinksTotal = 0;
|
|
381
381
|
unresolvedTotal = 0;
|
|
382
|
-
if (!(0,
|
|
382
|
+
if (!(0, _index1.featureEnabled)(cfg, 'links')) return [
|
|
383
383
|
3,
|
|
384
384
|
25
|
|
385
385
|
];
|
|
386
386
|
return [
|
|
387
387
|
4,
|
|
388
|
-
(0,
|
|
388
|
+
(0, _scope.materializeScope)(store, '_peek_scope', allowed)
|
|
389
389
|
];
|
|
390
390
|
case 12:
|
|
391
391
|
_state.sent();
|
|
@@ -476,7 +476,7 @@ function peekIndexed(store, cfg, pathArg, overrides) {
|
|
|
476
476
|
case 27:
|
|
477
477
|
body = (_this = _state.sent()) === null || _this === void 0 ? void 0 : _this.text;
|
|
478
478
|
byteTokens = Math.ceil(((_row__size = row._size) !== null && _row__size !== void 0 ? _row__size : 0) / 4);
|
|
479
|
-
tokens = body !== undefined ? Math.max(Math.ceil((0,
|
|
479
|
+
tokens = body !== undefined ? Math.max(Math.ceil((0, _index.estimateTokens)(body)), byteTokens) : byteTokens;
|
|
480
480
|
return [
|
|
481
481
|
2,
|
|
482
482
|
{
|
|
@@ -496,7 +496,7 @@ function peekIndexed(store, cfg, pathArg, overrides) {
|
|
|
496
496
|
'sections',
|
|
497
497
|
'links'
|
|
498
498
|
].filter(function(name) {
|
|
499
|
-
return !(0,
|
|
499
|
+
return !(0, _index1.featureEnabled)(cfg, name);
|
|
500
500
|
})
|
|
501
501
|
}
|
|
502
502
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/sensemaking/src/commands/peek.ts"],"sourcesContent":["import posix from 'node:path/posix';\nimport { estimateTokens } from '../chunk/index.ts';\nimport type { FeatureName, ResolvedConfig, SearchOverrides } from '../config/index.ts';\nimport { featureEnabled } from '../config/index.ts';\nimport { SenseError } from '../errors.ts';\nimport { serialQuery } from '../lib/serial-query.ts';\nimport type { Row } from '../output/output.ts';\nimport type { Store } from '../store/types.ts';\nimport { INTERNAL_COLUMNS, materializeScope, scopedPaths } from './scope.ts';\nimport { assertQuerySnapshot } from './snapshot.ts';\n\n// Note resolution shared by peek and path: an exact path, or a unique basename (case\n// insensitive, .md stripped).\nexport function resolveNote(paths: string[], arg: string): string {\n const exact = paths.find((p) => p === arg);\n if (exact) return exact;\n const base = posix.basename(arg).replace(/\\.md$/i, '').toLowerCase();\n const matches = paths.filter((p) => posix.basename(p).replace(/\\.md$/i, '').toLowerCase() === base);\n if (matches.length === 1) return matches[0];\n if (matches.length > 1) throw new SenseError('NOTE_AMBIGUOUS', `\"${arg}\" is ambiguous: ${matches.join(', ')}`);\n throw new SenseError('NOTE_NOT_FOUND', `no note matches \"${arg}\"`);\n}\n\n/** Structured, bounded metadata returned by the root {@link peek} API. */\nexport interface Peek {\n path: string;\n tokens: number;\n frontmatter: Row;\n /** Set when frontmatter parsing failed, distinguishing that case from an empty block. */\n parseError: string | null;\n sections: PeekSection[];\n outbound: string[];\n backlinks: string[];\n unresolved: string[];\n /** Totals before each bounded list is truncated. */\n sectionsTotal: number;\n outboundTotal: number;\n backlinksTotal: number;\n unresolvedTotal: number;\n /** Disabled features whose result blocks are omitted rather than returned empty. */\n off: FeatureName[];\n}\n\n/** A section description, with an inclusive source line range and token estimate, not section prose. */\nexport interface PeekSection {\n level: number;\n heading: string;\n start_line: number;\n end_line: number;\n tokens: number;\n}\n\n/** Options for the root {@link peek} API. */\nexport interface PeekOptions extends SearchOverrides {\n /** Maximum section descriptions. Defaults to 20; must be a positive safe integer. */\n sectionCountLimit?: number;\n /** Maximum entries in each link group independently. Defaults to 20; must be a positive safe integer. */\n linkCountLimit?: number;\n}\n\nconst PEEK_COUNT_LIMIT = 20;\n\n/**\n * Returns indexed metadata for a note in scope. Exact excluded paths fail before scoped basename\n * resolution; resolved neighbors stay in scope, while unresolved written targets remain visible.\n */\nexport function peek(store: Store, cfg: ResolvedConfig, pathArg: string, overrides: PeekOptions = {}): Promise<Peek> {\n return serialQuery(store, () => peekIndexed(store, cfg, pathArg, overrides));\n}\n\nasync function peekIndexed(store: Store, cfg: ResolvedConfig, pathArg: string, overrides: PeekOptions): Promise<Peek> {\n for (const name of ['sectionCountLimit', 'linkCountLimit'] as const) {\n const value = overrides[name];\n if (value !== undefined && (!Number.isSafeInteger(value) || value <= 0)) {\n throw new SenseError('SEARCH_OPTION_INVALID', `peek option \"${name}\" must be a positive safe integer, got ${String(value)}`);\n }\n }\n const sectionCountLimit = overrides.sectionCountLimit ?? PEEK_COUNT_LIMIT;\n const linkCountLimit = overrides.linkCountLimit ?? PEEK_COUNT_LIMIT;\n return store.transaction(async () => {\n await assertQuerySnapshot(store, cfg);\n const pathsStmt = await store.prepare('SELECT \"path\" FROM frontmatter');\n const paths = ((await pathsStmt.all()) as Array<{ path: string }>).map((r) => r.path);\n const allowed = await scopedPaths(store, cfg, overrides);\n if (paths.includes(pathArg) && !allowed.has(pathArg)) {\n throw new SenseError('NOTE_NOT_FOUND', `note \"${pathArg}\" exists but is outside the current scope; change the preset, include/exclude patterns, or where condition`);\n }\n let path: string;\n try {\n path = resolveNote([...allowed], pathArg);\n } catch (err) {\n if (err instanceof SenseError && err.code === 'NOTE_NOT_FOUND') {\n let excludedPath: string;\n try {\n excludedPath = resolveNote(paths, pathArg);\n } catch (unscopedErr) {\n if (unscopedErr instanceof SenseError && unscopedErr.code === 'NOTE_AMBIGUOUS') {\n throw new SenseError('NOTE_NOT_FOUND', `no note in the current scope matches \"${pathArg}\"; indexed matches exist outside the scope, so change the preset, include/exclude patterns, or where condition`);\n }\n throw err;\n }\n throw new SenseError('NOTE_NOT_FOUND', `note \"${excludedPath}\" exists but is outside the current scope; change the preset, include/exclude patterns, or where condition`);\n }\n throw err;\n }\n\n const rowStmt = await store.prepare('SELECT * FROM frontmatter WHERE \"path\" = ?');\n const row = (await rowStmt.get(path)) as Row;\n const parseError = (row._parse_error as string | null) ?? null;\n const frontmatter: Row = {};\n for (const [key, value] of Object.entries(row)) {\n if (!INTERNAL_COLUMNS.has(key) && value !== null) frontmatter[key] = value;\n }\n\n let sectionsTotal = 0;\n let sections: PeekSection[] = [];\n if (featureEnabled(cfg, 'sections')) {\n sectionsTotal = ((await (await store.prepare('SELECT COUNT(*) AS n FROM sections WHERE \"path\" = ?')).get(path)) as { n: number }).n;\n sections = (await (await store.prepare('SELECT level, heading, start_line, end_line, tokens FROM sections WHERE \"path\" = ? ORDER BY idx LIMIT ?')).all(path, sectionCountLimit)) as PeekSection[];\n }\n\n let outbound: string[] = [];\n let backlinks: string[] = [];\n let unresolved: string[] = [];\n let outboundTotal = 0;\n let backlinksTotal = 0;\n let unresolvedTotal = 0;\n if (featureEnabled(cfg, 'links')) {\n await materializeScope(store, '_peek_scope', allowed);\n outboundTotal = ((await (await store.prepare('SELECT COUNT(DISTINCT dst) AS n FROM links WHERE src = ? AND dst != src AND dst IN (SELECT \"path\" FROM _peek_scope)')).get(path)) as { n: number }).n;\n // The first written target determines each resolved destination's position.\n outbound = ((await (await store.prepare('SELECT dst FROM links WHERE src = ? AND dst != src AND dst IN (SELECT \"path\" FROM _peek_scope) GROUP BY dst ORDER BY MIN(target) LIMIT ?')).all(path, linkCountLimit)) as Array<{ dst: string }>).map((r) => r.dst);\n unresolvedTotal = ((await (await store.prepare('SELECT COUNT(*) AS n FROM links WHERE src = ? AND dst IS NULL')).get(path)) as { n: number }).n;\n unresolved = ((await (await store.prepare('SELECT target FROM links WHERE src = ? AND dst IS NULL ORDER BY target LIMIT ?')).all(path, linkCountLimit)) as Array<{ target: string }>).map((r) => r.target);\n backlinksTotal = ((await (await store.prepare('SELECT COUNT(DISTINCT src) AS n FROM links WHERE dst = ? AND src != dst AND src IN (SELECT \"path\" FROM _peek_scope)')).get(path)) as { n: number }).n;\n backlinks = ((await (await store.prepare('SELECT DISTINCT src FROM links WHERE dst = ? AND src != dst AND src IN (SELECT \"path\" FROM _peek_scope) ORDER BY src LIMIT ?')).all(path, linkCountLimit)) as Array<{ src: string }>).map((r) => r.src);\n }\n\n // content.text is the stripped body already computed at reconcile time (no extra file read),\n // floored by the byte/4 estimate so stripped-away syntax and frontmatter can't vanish from the price.\n const body = ((await (await store.prepare('SELECT text FROM content WHERE \"path\" = ?')).get(path)) as { text: string } | undefined)?.text;\n const byteTokens = Math.ceil(((row._size as number) ?? 0) / 4);\n const tokens = body !== undefined ? Math.max(Math.ceil(estimateTokens(body)), byteTokens) : byteTokens;\n\n return {\n path,\n tokens,\n frontmatter,\n parseError,\n sections,\n outbound,\n backlinks,\n unresolved,\n sectionsTotal,\n outboundTotal,\n backlinksTotal,\n unresolvedTotal,\n off: (['sections', 'links'] as FeatureName[]).filter((name) => !featureEnabled(cfg, name)),\n };\n });\n}\n"],"names":["peek","resolveNote","paths","arg","exact","find","p","base","posix","basename","replace","toLowerCase","matches","filter","length","SenseError","join","PEEK_COUNT_LIMIT","store","cfg","pathArg","overrides","serialQuery","peekIndexed","name","value","sectionCountLimit","linkCountLimit","undefined","Number","isSafeInteger","String","transaction","row","pathsStmt","allowed","path","excludedPath","rowStmt","parseError","frontmatter","key","sectionsTotal","sections","outbound","backlinks","unresolved","outboundTotal","backlinksTotal","unresolvedTotal","body","byteTokens","tokens","assertQuerySnapshot","prepare","all","map","r","scopedPaths","includes","has","err","code","unscopedErr","get","_parse_error","Object","entries","INTERNAL_COLUMNS","featureEnabled","n","materializeScope","dst","target","src","text","Math","ceil","_size","max","estimateTokens","off"],"mappings":";;;;;;;;;;;QAkEgBA;eAAAA;;QArDAC;eAAAA;;;4DAbE;uBACa;wBAEA;wBACJ;6BACC;uBAGoC;0BAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAI7B,SAASA,YAAYC,KAAe,EAAEC,GAAW;IACtD,IAAMC,QAAQF,MAAMG,IAAI,CAAC,SAACC;eAAMA,MAAMH;;IACtC,IAAIC,OAAO,OAAOA;IAClB,IAAMG,OAAOC,cAAK,CAACC,QAAQ,CAACN,KAAKO,OAAO,CAAC,UAAU,IAAIC,WAAW;IAClE,IAAMC,UAAUV,MAAMW,MAAM,CAAC,SAACP;eAAME,cAAK,CAACC,QAAQ,CAACH,GAAGI,OAAO,CAAC,UAAU,IAAIC,WAAW,OAAOJ;;IAC9F,IAAIK,QAAQE,MAAM,KAAK,GAAG,OAAOF,OAAO,CAAC,EAAE;IAC3C,IAAIA,QAAQE,MAAM,GAAG,GAAG,MAAM,IAAIC,oBAAU,CAAC,kBAAkB,AAAC,IAAyBH,OAAtBT,KAAI,oBAAqC,OAAnBS,QAAQI,IAAI,CAAC;IACtG,MAAM,IAAID,oBAAU,CAAC,kBAAkB,AAAC,oBAAuB,OAAJZ,KAAI;AACjE;AAuCA,IAAMc,mBAAmB;AAMlB,SAASjB,KAAKkB,KAAY,EAAEC,GAAmB,EAAEC,OAAe;QAAEC,YAAAA,iEAAyB,CAAC;IACjG,OAAOC,IAAAA,0BAAW,EA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C,OAAO,CAAC;;;oCAA3B;;wCAAO,cAAkEU,GAAG,CAAC5B;;;oCAAtFc,QAAS,QAAA,2BAAA,4BAAF,AAAE,MAAsHyB,IAAI;oCACnIxB,aAAayB,KAAKC,IAAI,CAAC,EAAE5C,aAAAA,IAAI6C,KAAK,cAAT7C,wBAAAA,aAAwB,KAAK;oCACtDmB,SAASF,SAAStB,YAAYgD,KAAKG,GAAG,CAACH,KAAKC,IAAI,CAACG,IAAAA,uBAAc,EAAC9B,QAAQC,cAAcA;oCAE5F;;wCAAO;4CACLf,MAAAA;4CACAgB,QAAAA;4CACAZ,aAAAA;4CACAD,YAAAA;4CACAI,UAAAA;4CACAC,UAAAA;4CACAC,WAAAA;4CACAC,YAAAA;4CACAJ,eAAAA;4CACAK,eAAAA;4CACAC,gBAAAA;4CACAC,iBAAAA;4CACAgC,KAAK;gDAAE;gDAAY;8CAA2BpE,MAAM,CAAC,SAACW;uDAAS,CAAC6C,IAAAA,wBAAc,EAAClD,KAAKK;;wCACtF;;;;oBACF;;;;IACF"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/sensemaking/src/commands/peek.ts"],"sourcesContent":["import posix from 'node:path/posix';\nimport { estimateTokens } from '../chunk/index.ts';\nimport type { FeatureName, ResolvedConfig, SearchOverrides } from '../config/index.ts';\nimport { featureEnabled } from '../config/index.ts';\nimport { SenseError } from '../errors.ts';\nimport { serialQuery } from '../lib/serial-query.ts';\nimport type { Row } from '../output/output.ts';\nimport type { Store } from '../store/types.ts';\nimport { INTERNAL_COLUMNS, materializeScope, scopedPaths } from './scope.ts';\nimport { assertQuerySnapshot } from './snapshot.ts';\n\n// Note resolution shared by peek and path: an exact path, or a unique basename (case\n// insensitive, .md stripped).\nexport function resolveNote(paths: string[], arg: string): string {\n const exact = paths.find((p) => p === arg);\n if (exact) return exact;\n const base = posix.basename(arg).replace(/\\.md$/i, '').toLowerCase();\n const matches = paths.filter((p) => posix.basename(p).replace(/\\.md$/i, '').toLowerCase() === base);\n if (matches.length === 1) return matches[0];\n if (matches.length > 1) throw new SenseError('NOTE_AMBIGUOUS', `\"${arg}\" is ambiguous: ${matches.join(', ')}`);\n throw new SenseError('NOTE_NOT_FOUND', `no note matches \"${arg}\"`);\n}\n\n/** Structured, bounded metadata returned by the root {@link peek} API. */\nexport interface Peek {\n path: string;\n tokens: number;\n frontmatter: Row;\n /** Set when frontmatter parsing failed, distinguishing that case from an empty block. */\n parseError: string | null;\n sections: PeekSection[];\n outbound: string[];\n backlinks: string[];\n unresolved: string[];\n /** Totals before each bounded list is truncated. */\n sectionsTotal: number;\n outboundTotal: number;\n backlinksTotal: number;\n unresolvedTotal: number;\n /** Disabled features whose result blocks are omitted rather than returned empty. */\n off: FeatureName[];\n}\n\n/** A section description, with an inclusive source line range and token estimate, not section prose. */\nexport interface PeekSection {\n level: number;\n heading: string;\n start_line: number;\n end_line: number;\n tokens: number;\n}\n\n/** Options for the root {@link peek} API. */\nexport interface PeekOptions extends SearchOverrides {\n /** Maximum section descriptions. Defaults to 20; must be a positive safe integer. */\n sectionCountLimit?: number;\n /** Maximum entries in each link group independently. Defaults to 20; must be a positive safe integer. */\n linkCountLimit?: number;\n}\n\nconst PEEK_COUNT_LIMIT = 20;\n\n/**\n * Returns indexed metadata for a note in scope. Exact excluded paths fail before scoped basename\n * resolution; resolved neighbors stay in scope, while unresolved written targets remain visible.\n */\nexport function peek(store: Store, cfg: ResolvedConfig, pathArg: string, overrides: PeekOptions = {}): Promise<Peek> {\n return serialQuery(store, () => peekIndexed(store, cfg, pathArg, overrides));\n}\n\nasync function peekIndexed(store: Store, cfg: ResolvedConfig, pathArg: string, overrides: PeekOptions): Promise<Peek> {\n for (const name of ['sectionCountLimit', 'linkCountLimit'] as const) {\n const value = overrides[name];\n if (value !== undefined && (!Number.isSafeInteger(value) || value <= 0)) {\n throw new SenseError('SEARCH_OPTION_INVALID', `peek option \"${name}\" must be a positive safe integer, got ${String(value)}`);\n }\n }\n const sectionCountLimit = overrides.sectionCountLimit ?? PEEK_COUNT_LIMIT;\n const linkCountLimit = overrides.linkCountLimit ?? PEEK_COUNT_LIMIT;\n return store.transaction(async () => {\n await assertQuerySnapshot(store, cfg);\n const pathsStmt = await store.prepare('SELECT \"path\" FROM frontmatter');\n const paths = ((await pathsStmt.all()) as Array<{ path: string }>).map((r) => r.path);\n const allowed = await scopedPaths(store, cfg, overrides);\n if (paths.includes(pathArg) && !allowed.has(pathArg)) {\n throw new SenseError('NOTE_NOT_FOUND', `note \"${pathArg}\" exists but is outside the current scope; change the preset, include/exclude patterns, or where condition`);\n }\n let path: string;\n try {\n path = resolveNote([...allowed], pathArg);\n } catch (err) {\n if (err instanceof SenseError && err.code === 'NOTE_NOT_FOUND') {\n let excludedPath: string;\n try {\n excludedPath = resolveNote(paths, pathArg);\n } catch (unscopedErr) {\n if (unscopedErr instanceof SenseError && unscopedErr.code === 'NOTE_AMBIGUOUS') {\n throw new SenseError('NOTE_NOT_FOUND', `no note in the current scope matches \"${pathArg}\"; indexed matches exist outside the scope, so change the preset, include/exclude patterns, or where condition`);\n }\n throw err;\n }\n throw new SenseError('NOTE_NOT_FOUND', `note \"${excludedPath}\" exists but is outside the current scope; change the preset, include/exclude patterns, or where condition`);\n }\n throw err;\n }\n\n const rowStmt = await store.prepare('SELECT * FROM frontmatter WHERE \"path\" = ?');\n const row = (await rowStmt.get(path)) as Row;\n const parseError = (row._parse_error as string | null) ?? null;\n const frontmatter: Row = {};\n for (const [key, value] of Object.entries(row)) {\n if (!INTERNAL_COLUMNS.has(key) && value !== null) frontmatter[key] = value;\n }\n\n let sectionsTotal = 0;\n let sections: PeekSection[] = [];\n if (featureEnabled(cfg, 'sections')) {\n sectionsTotal = ((await (await store.prepare('SELECT COUNT(*) AS n FROM sections WHERE \"path\" = ?')).get(path)) as { n: number }).n;\n sections = (await (await store.prepare('SELECT level, heading, start_line, end_line, tokens FROM sections WHERE \"path\" = ? ORDER BY idx LIMIT ?')).all(path, sectionCountLimit)) as PeekSection[];\n }\n\n let outbound: string[] = [];\n let backlinks: string[] = [];\n let unresolved: string[] = [];\n let outboundTotal = 0;\n let backlinksTotal = 0;\n let unresolvedTotal = 0;\n if (featureEnabled(cfg, 'links')) {\n await materializeScope(store, '_peek_scope', allowed);\n outboundTotal = ((await (await store.prepare('SELECT COUNT(DISTINCT dst) AS n FROM links WHERE src = ? AND dst != src AND dst IN (SELECT \"path\" FROM _peek_scope)')).get(path)) as { n: number }).n;\n // The first written target determines each resolved destination's position.\n outbound = ((await (await store.prepare('SELECT dst FROM links WHERE src = ? AND dst != src AND dst IN (SELECT \"path\" FROM _peek_scope) GROUP BY dst ORDER BY MIN(target) LIMIT ?')).all(path, linkCountLimit)) as Array<{ dst: string }>).map((r) => r.dst);\n unresolvedTotal = ((await (await store.prepare('SELECT COUNT(*) AS n FROM links WHERE src = ? AND dst IS NULL')).get(path)) as { n: number }).n;\n unresolved = ((await (await store.prepare('SELECT target FROM links WHERE src = ? AND dst IS NULL ORDER BY target LIMIT ?')).all(path, linkCountLimit)) as Array<{ target: string }>).map((r) => r.target);\n backlinksTotal = ((await (await store.prepare('SELECT COUNT(DISTINCT src) AS n FROM links WHERE dst = ? AND src != dst AND src IN (SELECT \"path\" FROM _peek_scope)')).get(path)) as { n: number }).n;\n backlinks = ((await (await store.prepare('SELECT DISTINCT src FROM links WHERE dst = ? AND src != dst AND src IN (SELECT \"path\" FROM _peek_scope) ORDER BY src LIMIT ?')).all(path, linkCountLimit)) as Array<{ src: string }>).map((r) => r.src);\n }\n\n // content.text is the stripped body already computed at reconcile time (no extra file read),\n // floored by the byte/4 estimate so stripped-away syntax and frontmatter can't vanish from the price.\n const body = ((await (await store.prepare('SELECT text FROM content WHERE \"path\" = ?')).get(path)) as { text: string } | undefined)?.text;\n const byteTokens = Math.ceil(((row._size as number) ?? 0) / 4);\n const tokens = body !== undefined ? Math.max(Math.ceil(estimateTokens(body)), byteTokens) : byteTokens;\n\n return {\n path,\n tokens,\n frontmatter,\n parseError,\n sections,\n outbound,\n backlinks,\n unresolved,\n sectionsTotal,\n outboundTotal,\n backlinksTotal,\n unresolvedTotal,\n off: (['sections', 'links'] as FeatureName[]).filter((name) => !featureEnabled(cfg, name)),\n };\n });\n}\n"],"names":["peek","resolveNote","paths","arg","exact","find","p","base","posix","basename","replace","toLowerCase","matches","filter","length","SenseError","join","PEEK_COUNT_LIMIT","store","cfg","pathArg","overrides","serialQuery","peekIndexed","name","value","sectionCountLimit","linkCountLimit","undefined","Number","isSafeInteger","String","transaction","row","pathsStmt","allowed","path","excludedPath","rowStmt","parseError","frontmatter","key","sectionsTotal","sections","outbound","backlinks","unresolved","outboundTotal","backlinksTotal","unresolvedTotal","body","byteTokens","tokens","assertQuerySnapshot","prepare","all","map","r","scopedPaths","includes","has","err","code","unscopedErr","get","_parse_error","Object","entries","INTERNAL_COLUMNS","featureEnabled","n","materializeScope","dst","target","src","text","Math","ceil","_size","max","estimateTokens","off"],"mappings":";;;;;;;;;;;QAkEgBA;eAAAA;;QArDAC;eAAAA;;;oDAbE,QAAA;aACa,QAAA;cAEA,QAAA;cACJ,QAAA;mBACC,QAAA;aAGoC,QAAA;gBAC5B,QAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAI7B,SAASA,YAAYC,KAAe,EAAEC,GAAW;IACtD,IAAMC,QAAQF,MAAMG,IAAI,CAAC,SAACC;eAAMA,MAAMH;;IACtC,IAAIC,OAAO,OAAOA;IAClB,IAAMG,OAAOC,cAAK,CAACC,QAAQ,CAACN,KAAKO,OAAO,CAAC,UAAU,IAAIC,WAAW;IAClE,IAAMC,UAAUV,MAAMW,MAAM,CAAC,SAACP;eAAME,cAAK,CAACC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var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
var
|
|
22
|
+
var _index = require("../config/index.js");
|
|
23
|
+
var _query = require("../embed/query.js");
|
|
24
|
+
var _store = require("../embed/store.js");
|
|
25
|
+
var _errors = require("../errors.js");
|
|
26
|
+
var _serialquery = require("../lib/serial-query.js");
|
|
27
|
+
var _peek = require("./peek.js");
|
|
28
|
+
var _scope = require("./scope.js");
|
|
29
|
+
var _snapshot = require("./snapshot.js");
|
|
30
30
|
function _array_like_to_array(arr, len) {
|
|
31
31
|
if (len == null || len > arr.length) len = arr.length;
|
|
32
32
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
@@ -201,7 +201,7 @@ function resolveRelatedSeed(store, pathArg) {
|
|
|
201
201
|
});
|
|
202
202
|
return [
|
|
203
203
|
2,
|
|
204
|
-
(0,
|
|
204
|
+
(0, _peek.resolveNote)(paths, pathArg)
|
|
205
205
|
];
|
|
206
206
|
}
|
|
207
207
|
});
|
|
@@ -209,7 +209,7 @@ function resolveRelatedSeed(store, pathArg) {
|
|
|
209
209
|
}
|
|
210
210
|
function relatedNotes(store, cfg, pathArg) {
|
|
211
211
|
var options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
212
|
-
return (0,
|
|
212
|
+
return (0, _serialquery.serialQuery)(store, function() {
|
|
213
213
|
var _options_k;
|
|
214
214
|
return relatedIndexed(store, cfg, pathArg, options, (_options_k = options.k) !== null && _options_k !== void 0 ? _options_k : RELATED_DEFAULT_K);
|
|
215
215
|
});
|
|
@@ -219,24 +219,24 @@ function relatedIndexed(store, cfg, pathArg, overrides, k) {
|
|
|
219
219
|
var effective, e;
|
|
220
220
|
return _ts_generator(this, function(_state) {
|
|
221
221
|
if (!Number.isFinite(k) || !Number.isInteger(k) || k <= 0) {
|
|
222
|
-
throw new
|
|
222
|
+
throw new _errors.SenseError('SEARCH_OPTION_INVALID', 'related option "k" must be a positive finite integer, got '.concat(String(k)));
|
|
223
223
|
}
|
|
224
224
|
// Vectors are the only signal `related` has, so every way of not having them is an error
|
|
225
225
|
// naming the cause; an empty result means one thing, nothing near in meaning.
|
|
226
|
-
effective = (0,
|
|
227
|
-
if (!(0,
|
|
228
|
-
throw new
|
|
226
|
+
effective = (0, _index.resolveSearch)(cfg, overrides);
|
|
227
|
+
if (!(0, _index.embedEnabled)(cfg)) {
|
|
228
|
+
throw new _errors.SenseError('EMBED_DISABLED', 'related ranks notes by meaning, and this tree has no embedding model; add an "embed" block naming one to sense.config.json (a Hugging Face id fetches automatically at first use; `sense download` prefetches it) -- search works without it, on words and links');
|
|
229
229
|
}
|
|
230
230
|
// search gates on the same signal, so a preset's declared signals mean one thing: without
|
|
231
231
|
// this check an overlapping vectors-on preset would answer for a scope that declined them.
|
|
232
232
|
if (effective.signals.vectors === undefined) {
|
|
233
|
-
throw new
|
|
233
|
+
throw new _errors.SenseError('PRESET_NOT_SEMANTIC', 'preset "'.concat(effective.presetName, '" has no "vectors" signal, so this scope has no vectors and related has no other signal; search it instead (words and links), or add "vectors" to that preset\'s signals'));
|
|
234
234
|
}
|
|
235
235
|
// A downloadable HF id can be fetched by preparation. Only a local path with missing files
|
|
236
236
|
// can never fetch itself.
|
|
237
|
-
e = (0,
|
|
238
|
-
if ((0,
|
|
239
|
-
throw new
|
|
237
|
+
e = (0, _index.embedConfig)(cfg); // embedEnabled(cfg) above guarantees this is set
|
|
238
|
+
if ((0, _store.localModelMissing)(e)) {
|
|
239
|
+
throw new _errors.SenseError('EMBED_MODEL_MISSING', 'related ranks notes by meaning, so it needs the embedding model, but the local model path "'.concat(e.model, '" is missing ').concat(_store.MODEL_FILENAMES, "; point embed.model at a directory containing them (search still works without it, on words and links)"));
|
|
240
240
|
}
|
|
241
241
|
return [
|
|
242
242
|
2,
|
|
@@ -248,14 +248,14 @@ function relatedIndexed(store, cfg, pathArg, overrides, k) {
|
|
|
248
248
|
case 0:
|
|
249
249
|
return [
|
|
250
250
|
4,
|
|
251
|
-
(0,
|
|
251
|
+
(0, _snapshot.assertQuerySnapshot)(store, cfg)
|
|
252
252
|
];
|
|
253
253
|
case 1:
|
|
254
254
|
_state.sent();
|
|
255
255
|
// Repeat effective preset validation inside the snapshot that supplies its durable scope.
|
|
256
|
-
current = (0,
|
|
256
|
+
current = (0, _index.resolveSearch)(cfg, overrides);
|
|
257
257
|
if (current.signals.vectors === undefined) {
|
|
258
|
-
throw new
|
|
258
|
+
throw new _errors.SenseError('PRESET_NOT_SEMANTIC', 'preset "'.concat(current.presetName, '" has no "vectors" signal, so this scope has no vectors and related has no other signal; search it instead (words and links), or add "vectors" to that preset\'s signals'));
|
|
259
259
|
}
|
|
260
260
|
return [
|
|
261
261
|
4,
|
|
@@ -294,7 +294,7 @@ function relatedIndexed(store, cfg, pathArg, overrides, k) {
|
|
|
294
294
|
].concat(_to_consumable_array(outbound), _to_consumable_array(backlinks)));
|
|
295
295
|
return [
|
|
296
296
|
4,
|
|
297
|
-
(0,
|
|
297
|
+
(0, _scope.scopedPaths)(store, cfg, overrides)
|
|
298
298
|
];
|
|
299
299
|
case 7:
|
|
300
300
|
allowed = _state.sent();
|
|
@@ -302,7 +302,7 @@ function relatedIndexed(store, cfg, pathArg, overrides, k) {
|
|
|
302
302
|
// be ready, while pending vectors in unrelated notes do not block this operation.
|
|
303
303
|
return [
|
|
304
304
|
4,
|
|
305
|
-
(0,
|
|
305
|
+
(0, _query.ensureDocumentEmbeddings)(store, cfg, new Set(_to_consumable_array(allowed).concat([
|
|
306
306
|
path
|
|
307
307
|
])))
|
|
308
308
|
];
|
|
@@ -310,15 +310,15 @@ function relatedIndexed(store, cfg, pathArg, overrides, k) {
|
|
|
310
310
|
_state.sent();
|
|
311
311
|
return [
|
|
312
312
|
4,
|
|
313
|
-
(0,
|
|
313
|
+
(0, _query.hasEmbedding)(store, path)
|
|
314
314
|
];
|
|
315
315
|
case 9:
|
|
316
316
|
if (!_state.sent()) {
|
|
317
|
-
throw new
|
|
317
|
+
throw new _errors.SenseError('NOTE_NOT_EMBEDDED', "".concat(path, " has no indexed text to compare -- a note that is frontmatter only, or empty, has nothing to rank by meaning"));
|
|
318
318
|
}
|
|
319
319
|
return [
|
|
320
320
|
4,
|
|
321
|
-
(0,
|
|
321
|
+
(0, _scope.scopeHasEmbeddings)(store, cfg, allowed)
|
|
322
322
|
];
|
|
323
323
|
case 10:
|
|
324
324
|
if (!_state.sent()) return [
|
|
@@ -327,8 +327,8 @@ function relatedIndexed(store, cfg, pathArg, overrides, k) {
|
|
|
327
327
|
];
|
|
328
328
|
return [
|
|
329
329
|
2,
|
|
330
|
-
(0,
|
|
331
|
-
return (0,
|
|
330
|
+
(0, _scope.withMaterializedVectorScope)(store, allowed, function() {
|
|
331
|
+
return (0, _query.similarNotes)(store, cfg, path, {
|
|
332
332
|
exclude: exclude,
|
|
333
333
|
allowed: allowed,
|
|
334
334
|
k: k
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/sensemaking/src/commands/related.ts"],"sourcesContent":["import type { ResolvedConfig, SearchOverrides } from '../config/index.ts';\nimport { embedConfig, embedEnabled, resolveSearch } from '../config/index.ts';\nimport { ensureDocumentEmbeddings, hasEmbedding, similarNotes } from '../embed/query.ts';\nimport { localModelMissing, MODEL_FILENAMES } from '../embed/store.ts';\nimport { SenseError } from '../errors.ts';\nimport { serialQuery } from '../lib/serial-query.ts';\nimport type { Store } from '../store/types.ts';\nimport { resolveNote } from './peek.ts';\nimport { scopedPaths, scopeHasEmbeddings, withMaterializedVectorScope } from './scope.ts';\nimport { assertQuerySnapshot } from './snapshot.ts';\n\nexport const RELATED_DEFAULT_K = 5;\n\n/**\n * Options for {@link relatedNotes}. Scope fields filter result candidates, not the seed note;\n * `k` defaults to 5, matching the CLI.\n */\nexport interface RelatedOptions extends SearchOverrides {\n k?: number;\n}\n\nexport type RelatedResult = {\n path: string;\n similarity: number;\n};\n\nexport async function resolveRelatedSeed(store: Store, pathArg: string): Promise<string> {\n const paths = ((await (await store.prepare('SELECT \"path\" FROM frontmatter')).all()) as Array<{ path: string }>).map((row) => row.path);\n return resolveNote(paths, pathArg);\n}\n\n/**\n * Returns the notes most similar to an indexed seed, excluding the seed and notes linked either\n * way. The seed resolves across the indexed tree even when it is outside the candidate scope.\n */\nexport function relatedNotes(store: Store, cfg: ResolvedConfig, pathArg: string, options: RelatedOptions = {}): Promise<RelatedResult[]> {\n return serialQuery(store, () => relatedIndexed(store, cfg, pathArg, options, options.k ?? RELATED_DEFAULT_K));\n}\n\nasync function relatedIndexed(store: Store, cfg: ResolvedConfig, pathArg: string, overrides: RelatedOptions, k: number): Promise<RelatedResult[]> {\n if (!Number.isFinite(k) || !Number.isInteger(k) || k <= 0) {\n throw new SenseError('SEARCH_OPTION_INVALID', `related option \"k\" must be a positive finite integer, got ${String(k)}`);\n }\n // Vectors are the only signal `related` has, so every way of not having them is an error\n // naming the cause; an empty result means one thing, nothing near in meaning.\n const effective = resolveSearch(cfg, overrides);\n if (!embedEnabled(cfg)) {\n throw new SenseError('EMBED_DISABLED', 'related ranks notes by meaning, and this tree has no embedding model; add an \"embed\" block naming one to sense.config.json (a Hugging Face id fetches automatically at first use; `sense download` prefetches it) -- search works without it, on words and links');\n }\n // search gates on the same signal, so a preset's declared signals mean one thing: without\n // this check an overlapping vectors-on preset would answer for a scope that declined them.\n if (effective.signals.vectors === undefined) {\n throw new SenseError('PRESET_NOT_SEMANTIC', `preset \"${effective.presetName}\" has no \"vectors\" signal, so this scope has no vectors and related has no other signal; search it instead (words and links), or add \"vectors\" to that preset's signals`);\n }\n // A downloadable HF id can be fetched by preparation. Only a local path with missing files\n // can never fetch itself.\n const e = embedConfig(cfg); // embedEnabled(cfg) above guarantees this is set\n if (localModelMissing(e)) {\n throw new SenseError('EMBED_MODEL_MISSING', `related ranks notes by meaning, so it needs the embedding model, but the local model path \"${e.model}\" is missing ${MODEL_FILENAMES}; point embed.model at a directory containing them (search still works without it, on words and links)`);\n }\n\n return store.transaction(async () => {\n await assertQuerySnapshot(store, cfg);\n // Repeat effective preset validation inside the snapshot that supplies its durable scope.\n const current = resolveSearch(cfg, overrides);\n if (current.signals.vectors === undefined) {\n throw new SenseError('PRESET_NOT_SEMANTIC', `preset \"${current.presetName}\" has no \"vectors\" signal, so this scope has no vectors and related has no other signal; search it instead (words and links), or add \"vectors\" to that preset's signals`);\n }\n\n const path = await resolveRelatedSeed(store, pathArg);\n const outbound = ((await (await store.prepare('SELECT DISTINCT dst FROM links WHERE src = ? AND dst IS NOT NULL AND dst != src')).all(path)) as Array<{ dst: string }>).map((r) => r.dst);\n const backlinks = ((await (await store.prepare('SELECT DISTINCT src FROM links WHERE dst = ? AND src != dst')).all(path)) as Array<{ src: string }>).map((r) => r.src);\n const exclude = new Set([path, ...outbound, ...backlinks]);\n const allowed = await scopedPaths(store, cfg, overrides);\n // The seed may sit outside a narrowed candidate scope; both it and every eligible result must\n // be ready, while pending vectors in unrelated notes do not block this operation.\n await ensureDocumentEmbeddings(store, cfg, new Set([...allowed, path]));\n if (!(await hasEmbedding(store, path))) {\n throw new SenseError('NOTE_NOT_EMBEDDED', `${path} has no indexed text to compare -- a note that is frontmatter only, or empty, has nothing to rank by meaning`);\n }\n if (!(await scopeHasEmbeddings(store, cfg, allowed))) return [];\n return withMaterializedVectorScope(store, allowed, () => similarNotes(store, cfg, path, { exclude, allowed, k }));\n });\n}\n"],"names":["RELATED_DEFAULT_K","relatedNotes","resolveRelatedSeed","store","pathArg","paths","prepare","all","map","row","path","resolveNote","cfg","options","serialQuery","relatedIndexed","k","overrides","effective","e","Number","isFinite","isInteger","SenseError","String","resolveSearch","embedEnabled","signals","vectors","undefined","presetName","embedConfig","localModelMissing","MODEL_FILENAMES","model","transaction","current","outbound","backlinks","exclude","allowed","assertQuerySnapshot","r","dst","src","Set","scopedPaths","ensureDocumentEmbeddings","hasEmbedding","scopeHasEmbeddings","withMaterializedVectorScope","similarNotes"],"mappings":";;;;;;;;;;;QAWaA;eAAAA;;QAwBGC;eAAAA;;QATMC;eAAAA;;;
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/sensemaking/src/commands/related.ts"],"sourcesContent":["import type { ResolvedConfig, SearchOverrides } from '../config/index.ts';\nimport { embedConfig, embedEnabled, resolveSearch } from '../config/index.ts';\nimport { ensureDocumentEmbeddings, hasEmbedding, similarNotes } from '../embed/query.ts';\nimport { localModelMissing, MODEL_FILENAMES } from '../embed/store.ts';\nimport { SenseError } from '../errors.ts';\nimport { serialQuery } from '../lib/serial-query.ts';\nimport type { Store } from '../store/types.ts';\nimport { resolveNote } from './peek.ts';\nimport { scopedPaths, scopeHasEmbeddings, withMaterializedVectorScope } from './scope.ts';\nimport { assertQuerySnapshot } from './snapshot.ts';\n\nexport const RELATED_DEFAULT_K = 5;\n\n/**\n * Options for {@link relatedNotes}. Scope fields filter result candidates, not the seed note;\n * `k` defaults to 5, matching the CLI.\n */\nexport interface RelatedOptions extends SearchOverrides {\n k?: number;\n}\n\nexport type RelatedResult = {\n path: string;\n similarity: number;\n};\n\nexport async function resolveRelatedSeed(store: Store, pathArg: string): Promise<string> {\n const paths = ((await (await store.prepare('SELECT \"path\" FROM frontmatter')).all()) as Array<{ path: string }>).map((row) => row.path);\n return resolveNote(paths, pathArg);\n}\n\n/**\n * Returns the notes most similar to an indexed seed, excluding the seed and notes linked either\n * way. The seed resolves across the indexed tree even when it is outside the candidate scope.\n */\nexport function relatedNotes(store: Store, cfg: ResolvedConfig, pathArg: string, options: RelatedOptions = {}): Promise<RelatedResult[]> {\n return serialQuery(store, () => relatedIndexed(store, cfg, pathArg, options, options.k ?? RELATED_DEFAULT_K));\n}\n\nasync function relatedIndexed(store: Store, cfg: ResolvedConfig, pathArg: string, overrides: RelatedOptions, k: number): Promise<RelatedResult[]> {\n if (!Number.isFinite(k) || !Number.isInteger(k) || k <= 0) {\n throw new SenseError('SEARCH_OPTION_INVALID', `related option \"k\" must be a positive finite integer, got ${String(k)}`);\n }\n // Vectors are the only signal `related` has, so every way of not having them is an error\n // naming the cause; an empty result means one thing, nothing near in meaning.\n const effective = resolveSearch(cfg, overrides);\n if (!embedEnabled(cfg)) {\n throw new SenseError('EMBED_DISABLED', 'related ranks notes by meaning, and this tree has no embedding model; add an \"embed\" block naming one to sense.config.json (a Hugging Face id fetches automatically at first use; `sense download` prefetches it) -- search works without it, on words and links');\n }\n // search gates on the same signal, so a preset's declared signals mean one thing: without\n // this check an overlapping vectors-on preset would answer for a scope that declined them.\n if (effective.signals.vectors === undefined) {\n throw new SenseError('PRESET_NOT_SEMANTIC', `preset \"${effective.presetName}\" has no \"vectors\" signal, so this scope has no vectors and related has no other signal; search it instead (words and links), or add \"vectors\" to that preset's signals`);\n }\n // A downloadable HF id can be fetched by preparation. Only a local path with missing files\n // can never fetch itself.\n const e = embedConfig(cfg); // embedEnabled(cfg) above guarantees this is set\n if (localModelMissing(e)) {\n throw new SenseError('EMBED_MODEL_MISSING', `related ranks notes by meaning, so it needs the embedding model, but the local model path \"${e.model}\" is missing ${MODEL_FILENAMES}; point embed.model at a directory containing them (search still works without it, on words and links)`);\n }\n\n return store.transaction(async () => {\n await assertQuerySnapshot(store, cfg);\n // Repeat effective preset validation inside the snapshot that supplies its durable scope.\n const current = resolveSearch(cfg, overrides);\n if (current.signals.vectors === undefined) {\n throw new SenseError('PRESET_NOT_SEMANTIC', `preset \"${current.presetName}\" has no \"vectors\" signal, so this scope has no vectors and related has no other signal; search it instead (words and links), or add \"vectors\" to that preset's signals`);\n }\n\n const path = await resolveRelatedSeed(store, pathArg);\n const outbound = ((await (await store.prepare('SELECT DISTINCT dst FROM links WHERE src = ? AND dst IS NOT NULL AND dst != src')).all(path)) as Array<{ dst: string }>).map((r) => r.dst);\n const backlinks = ((await (await store.prepare('SELECT DISTINCT src FROM links WHERE dst = ? AND src != dst')).all(path)) as Array<{ src: string }>).map((r) => r.src);\n const exclude = new Set([path, ...outbound, ...backlinks]);\n const allowed = await scopedPaths(store, cfg, overrides);\n // The seed may sit outside a narrowed candidate scope; both it and every eligible result must\n // be ready, while pending vectors in unrelated notes do not block this operation.\n await ensureDocumentEmbeddings(store, cfg, new Set([...allowed, path]));\n if (!(await hasEmbedding(store, path))) {\n throw new SenseError('NOTE_NOT_EMBEDDED', `${path} has no indexed text to compare -- a note that is frontmatter only, or empty, has nothing to rank by meaning`);\n }\n if (!(await scopeHasEmbeddings(store, cfg, allowed))) return [];\n return withMaterializedVectorScope(store, allowed, () => similarNotes(store, cfg, path, { exclude, allowed, k }));\n });\n}\n"],"names":["RELATED_DEFAULT_K","relatedNotes","resolveRelatedSeed","store","pathArg","paths","prepare","all","map","row","path","resolveNote","cfg","options","serialQuery","relatedIndexed","k","overrides","effective","e","Number","isFinite","isInteger","SenseError","String","resolveSearch","embedEnabled","signals","vectors","undefined","presetName","embedConfig","localModelMissing","MODEL_FILENAMES","model","transaction","current","outbound","backlinks","exclude","allowed","assertQuerySnapshot","r","dst","src","Set","scopedPaths","ensureDocumentEmbeddings","hasEmbedding","scopeHasEmbeddings","withMaterializedVectorScope","similarNotes"],"mappings":";;;;;;;;;;;QAWaA;eAAAA;;QAwBGC;eAAAA;;QATMC;eAAAA;;;aAzBmC,QAAA;aACY,QAAA;aAClB,QAAA;cACxB,QAAA;mBACC,QAAA;YAEA,QAAA;aACiD,QAAA;gBACzC,QAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE7B,IAAMF,oBAAoB;AAe1B,SAAeE,mBAAmBC,KAAY,EAAEC,OAAe;;YAC9DC;;;;oBAAiB;;wBAAMF,MAAMG,OAAO,CAAC;;;oBAA3B;;wBAAO,cAAuDC,GAAG;;;oBAA3EF,QAAQ,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mDAAMW,IAAAA,mBAAY,EAAChD,OAAOS,KAAKF,MAAM;gDAAE6B,SAAAA;gDAASC,SAAAA;gDAASxB,GAAAA;4CAAE;;;;;oBAChH;;;;IACF"}
|
|
@@ -38,9 +38,9 @@ _export(exports, {
|
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
var _nodepath = require("node:path");
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
-
var
|
|
41
|
+
var _index = require("../config/index.js");
|
|
42
|
+
var _columnhint = require("../output/column-hint.js");
|
|
43
|
+
var _vectors = require("../store/vectors.js");
|
|
44
44
|
function _array_like_to_array(arr, len) {
|
|
45
45
|
if (len == null || len > arr.length) len = arr.length;
|
|
46
46
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
@@ -216,7 +216,7 @@ function scopeHasEmbeddings(store, cfg, scopedPaths) {
|
|
|
216
216
|
return _ts_generator(this, function(_state) {
|
|
217
217
|
switch(_state.label){
|
|
218
218
|
case 0:
|
|
219
|
-
if (!(0,
|
|
219
|
+
if (!(0, _index.anyPresetEmbeds)(cfg)) return [
|
|
220
220
|
2,
|
|
221
221
|
false
|
|
222
222
|
]; // the embeddings table doesn't exist at all in this case
|
|
@@ -248,7 +248,7 @@ function rawScope(store, cfg, overrides, allPaths) {
|
|
|
248
248
|
return _ts_generator(this, function(_state) {
|
|
249
249
|
switch(_state.label){
|
|
250
250
|
case 0:
|
|
251
|
-
effective = (0,
|
|
251
|
+
effective = (0, _index.resolveSearch)(cfg, overrides);
|
|
252
252
|
include = effective.include, exclude = effective.exclude;
|
|
253
253
|
adHocScope = overrides.include !== undefined || overrides.exclude !== undefined || overrides.noExclude === true;
|
|
254
254
|
if (!!adHocScope) return [
|
|
@@ -374,7 +374,7 @@ function narrowByWhere(store, paths, where) {
|
|
|
374
374
|
store.docs.columns()
|
|
375
375
|
];
|
|
376
376
|
case 5:
|
|
377
|
-
throw
|
|
377
|
+
throw _columnhint.columnHint.apply(void 0, [
|
|
378
378
|
_state.sent(),
|
|
379
379
|
err
|
|
380
380
|
]);
|
|
@@ -398,7 +398,7 @@ function scopedPaths(store, cfg, overrides) {
|
|
|
398
398
|
return _ts_generator(this, function(_state) {
|
|
399
399
|
switch(_state.label){
|
|
400
400
|
case 0:
|
|
401
|
-
effective = (0,
|
|
401
|
+
effective = (0, _index.resolveSearch)(cfg, overrides);
|
|
402
402
|
_tmp = [
|
|
403
403
|
store
|
|
404
404
|
];
|
|
@@ -458,7 +458,7 @@ function withMaterializedVectorScope(store, allowed, callback, knownTotal) {
|
|
|
458
458
|
return _ts_generator(this, function(_state) {
|
|
459
459
|
switch(_state.label){
|
|
460
460
|
case 0:
|
|
461
|
-
reservation = (0,
|
|
461
|
+
reservation = (0, _vectors.reserveNativeVectorScope)(store.vectors, allowed);
|
|
462
462
|
if (!reservation) return [
|
|
463
463
|
2,
|
|
464
464
|
callback()
|
|
@@ -525,7 +525,7 @@ function withMaterializedVectorScope(store, allowed, callback, knownTotal) {
|
|
|
525
525
|
]);
|
|
526
526
|
return [
|
|
527
527
|
4,
|
|
528
|
-
materializeScope(store,
|
|
528
|
+
materializeScope(store, _vectors.NATIVE_VECTOR_SCOPE_TABLE, allowed)
|
|
529
529
|
];
|
|
530
530
|
case 7:
|
|
531
531
|
_state.sent();
|
|
@@ -561,7 +561,7 @@ function withMaterializedVectorScope(store, allowed, callback, knownTotal) {
|
|
|
561
561
|
reservation.deactivate();
|
|
562
562
|
return [
|
|
563
563
|
4,
|
|
564
|
-
store.exec("DROP TABLE IF EXISTS ".concat(
|
|
564
|
+
store.exec("DROP TABLE IF EXISTS ".concat(_vectors.NATIVE_VECTOR_SCOPE_TABLE))
|
|
565
565
|
];
|
|
566
566
|
case 12:
|
|
567
567
|
_state.sent();
|