sensemaking 0.28.0 → 0.28.2

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 (87) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/chunk/group.js +1 -1
  3. package/dist/cjs/cli/path.js +1 -1
  4. package/dist/cjs/cli/peek.js +1 -1
  5. package/dist/cjs/cli/related.js +1 -1
  6. package/dist/cjs/cli/search.js +1 -1
  7. package/dist/cjs/cli/shared.js +1 -1
  8. package/dist/cjs/cli/sql.js +1 -1
  9. package/dist/cjs/cli/status.js +1 -1
  10. package/dist/cjs/cli.js +1 -1
  11. package/dist/cjs/commands/map.js +1 -1
  12. package/dist/cjs/commands/peek.js +1 -1
  13. package/dist/cjs/commands/related.js +1 -1
  14. package/dist/cjs/commands/scope.js +1 -1
  15. package/dist/cjs/commands/search.js +1 -1
  16. package/dist/cjs/commands/signals.js +1 -1
  17. package/dist/cjs/config/access.js +1 -1
  18. package/dist/cjs/config/load.js +1 -1
  19. package/dist/cjs/config/validate.js +1 -1
  20. package/dist/cjs/embed/identity.js +1 -1
  21. package/dist/cjs/embed/langfit.js +1 -1
  22. package/dist/cjs/embed/openai.js +1 -1
  23. package/dist/cjs/embed/query.js +1 -1
  24. package/dist/cjs/embed/static.js +1 -1
  25. package/dist/cjs/embed/store.d.cts +1 -1
  26. package/dist/cjs/embed/store.d.ts +1 -1
  27. package/dist/cjs/embed/store.js +154 -31
  28. package/dist/cjs/embed/store.js.map +1 -1
  29. package/dist/cjs/features/links.js +1 -1
  30. package/dist/cjs/features/rank.js +1 -1
  31. package/dist/cjs/features/tags.js +1 -1
  32. package/dist/cjs/graph/graph.js +1 -1
  33. package/dist/cjs/graph/traverse.js +1 -1
  34. package/dist/cjs/output/column-hint.js +1 -1
  35. package/dist/cjs/output/output.js +1 -1
  36. package/dist/cjs/scan/frontmatter.js +1 -1
  37. package/dist/cjs/scan/list.js +1 -1
  38. package/dist/cjs/scan/pool.js +1 -1
  39. package/dist/cjs/scan/reparse.js +1 -1
  40. package/dist/cjs/store/batch.js +1 -1
  41. package/dist/cjs/store/builder.js +1 -1
  42. package/dist/cjs/store/duckdb/batch.js +1 -1
  43. package/dist/cjs/store/duckdb/connection.js +1 -1
  44. package/dist/cjs/store/duckdb/fieldStats.js +1 -1
  45. package/dist/cjs/store/duckdb/lexical.js +1 -1
  46. package/dist/cjs/store/duckdb/reconcile.js +1 -1
  47. package/dist/cjs/store/duckdb/store.js +1 -1
  48. package/dist/cjs/store/duckdb/vectors.js +1 -1
  49. package/dist/cjs/store/embed-scope.js +1 -1
  50. package/dist/cjs/store/feature-scope.js +1 -1
  51. package/dist/cjs/store/native.js +1 -1
  52. package/dist/cjs/store/open.js +1 -1
  53. package/dist/cjs/store/preset-scope.js +1 -1
  54. package/dist/cjs/store/reconcile.js +1 -1
  55. package/dist/cjs/store/signature.js +1 -1
  56. package/dist/cjs/store/sqlite/connection.js +1 -1
  57. package/dist/cjs/store/sqlite/fieldStats.js +1 -1
  58. package/dist/cjs/store/sqlite/store.js +1 -1
  59. package/dist/cjs/store/sqlite/vectors.js +1 -1
  60. package/dist/cjs/store/stages.js +1 -1
  61. package/dist/cjs/store/turso/connection.js +1 -1
  62. package/dist/cjs/store/turso/fieldStats.js +1 -1
  63. package/dist/cjs/store/turso/lexical.js +1 -1
  64. package/dist/cjs/store/turso/open.js +1 -1
  65. package/dist/cjs/store/turso/store.js +1 -1
  66. package/dist/cjs/store/turso/vectors.js +1 -1
  67. package/dist/esm/embed/store.d.ts +1 -1
  68. package/dist/esm/embed/store.js +77 -8
  69. package/dist/esm/embed/store.js.map +1 -1
  70. package/package.json +3 -3
  71. package/skills/sense/EXAMPLES.md +0 -99
  72. package/skills/sense/SKILL.md +0 -145
  73. package/skills/sense/references/search.md +0 -63
  74. package/skills/sense/references/sql.md +0 -120
  75. package/skills/sense/references/stores/duckdb.md +0 -35
  76. package/skills/sense/references/stores/sqlite.md +0 -66
  77. package/skills/sense/references/stores/turso.md +0 -36
  78. package/skills/sense/references/terminology.md +0 -32
  79. package/skills/sense-bases/EXAMPLES.md +0 -103
  80. package/skills/sense-bases/SKILL.md +0 -147
  81. package/skills/sense-setup/EXAMPLES.md +0 -129
  82. package/skills/sense-setup/SKILL.md +0 -112
  83. package/skills/sense-setup/references/embeddings.md +0 -51
  84. package/skills/sense-setup/references/store-benchmarks.md +0 -16
  85. package/skills/sense-setup/references/stores/duckdb.md +0 -28
  86. package/skills/sense-setup/references/stores/sqlite.md +0 -21
  87. package/skills/sense-setup/references/stores/turso.md +0 -25
@@ -1,120 +0,0 @@
1
- # Portable SQL
2
-
3
- Read this guide for raw SQL over sense tables. These patterns use the shared schema and avoid native text-index syntax. Read the selected store's query guide as well when the statement uses dates, JSON table functions, native types, or text matching.
4
-
5
- ## Discover the tree before assuming fields
6
-
7
- Frontmatter columns come from the indexed notes. Inspect them before writing a field query:
8
-
9
- ```sh
10
- sense map
11
- sense sql "SELECT name FROM pragma_table_info('frontmatter')"
12
- sense sql "SELECT DISTINCT status FROM frontmatter ORDER BY status"
13
- ```
14
-
15
- Punctuated field names need double quotes. Values should use `?` parameters:
16
-
17
- ```sh
18
- sense sql 'SELECT path FROM frontmatter WHERE "plugin-id" = ? LIMIT 50' example
19
- ```
20
-
21
- `content.title` and `content.summary` always exist. A frontmatter column with either name exists only when at least one indexed note declares it.
22
-
23
- ## Shared tables
24
-
25
- | Table | Main columns |
26
- |---|---|
27
- | `frontmatter` | `path`, discovered fields, `_mtime`, `_ctime`, `_size`, `_rank`, `_parse_error` |
28
- | `content` | `path`, `title`, `summary`, `text` |
29
- | `links` | `src`, `target`, `dst`, `embed` |
30
- | `tags` | `path`, `tag` |
31
- | `sections` | `path`, `heading`, `level`, `start_line`, `end_line`, `tokens` |
32
- | `preset_files` | `path`, `preset` |
33
-
34
- `links.dst` is null when the written target does not resolve to indexed markdown. `links.embed` is 1 for an embed and 0 for an ordinary wikilink. The `tags` table merges frontmatter and inline tags and stores a nested tag such as `book/scifi` in full.
35
-
36
- ## Shared query patterns
37
-
38
- ```sql
39
- SELECT COUNT(*) AS notes FROM frontmatter;
40
-
41
- SELECT path, title
42
- FROM frontmatter
43
- WHERE status = ?
44
- ORDER BY path
45
- LIMIT 50;
46
-
47
- SELECT src
48
- FROM links
49
- WHERE dst = ?
50
- ORDER BY src;
51
-
52
- SELECT heading, start_line, end_line, tokens
53
- FROM sections
54
- WHERE path = ?
55
- ORDER BY start_line;
56
-
57
- SELECT path, tag
58
- FROM tags
59
- WHERE tag = ? OR tag LIKE ?
60
- ORDER BY path;
61
- ```
62
-
63
- For a nested tag family, bind the same value twice as `book` and `book/%`.
64
-
65
- `has(field, value)` works on every store. It tests membership for a JSON array and substring presence for a scalar string. Use `field = ?` for exact scalar equality because `has(status, 'active')` also matches `inactive`.
66
-
67
- `basename(path[, suffix])` works on every store. `segment(terms)` is available on SQLite and DuckDB only; the store guides explain when it is needed.
68
-
69
- ## Preset scope
70
-
71
- `sense sql` covers the whole index unless it receives `--preset`. With that flag, sense binds a temporary `scope(path)` table and requires the statement to join it:
72
-
73
- ```sh
74
- sense sql "SELECT f.path FROM frontmatter f JOIN scope ON scope.path = f.path ORDER BY f.path" --preset default
75
- ```
76
-
77
- A saved SQL query written against `scope` can run under different presets without duplicating the statement. Without `--preset`, join `preset_files` directly and name the preset in SQL.
78
-
79
- ## Graph queries
80
-
81
- Bound recursive walks. An unrestricted walk on a dense graph can enumerate paths faster than it eliminates them.
82
-
83
- ```sql
84
- WITH RECURSIVE hop(path, d) AS (
85
- SELECT ?, 0
86
- UNION
87
- SELECT CASE WHEN l.src = hop.path THEN l.dst ELSE l.src END, hop.d + 1
88
- FROM hop
89
- JOIN links l ON (l.src = hop.path OR l.dst = hop.path) AND l.dst IS NOT NULL
90
- WHERE hop.d < 2
91
- )
92
- SELECT DISTINCT path FROM hop WHERE d > 0;
93
- ```
94
-
95
- Use `sense path` for the shortest chain between two known notes. Use raw recursion when the task needs a set of neighbors to filter or join.
96
-
97
- ## Unresolved links
98
-
99
- `dst IS NULL` includes links to attachments that sense never indexes, such as images, PDFs, and `.base` files. Exclude the attachment extensions used by the tree before treating the remaining rows as broken links. Trees with dotted markdown titles need an explicit extension list instead of a blanket "contains a dot" filter.
100
-
101
- Templates and examples can also contain deliberately unresolved wikilinks. Scope the query to authored content when those files are indexed.
102
-
103
- ## Types and parse errors
104
-
105
- YAML strings remain text, whole numbers and booleans remain integer-like values, fractions remain real-like values, and lists and maps remain structured or JSON-backed values according to the store. Use `sense map` to see the types observed for each field. Read the store guide before comparing a field that contains more than one type.
106
-
107
- A malformed frontmatter block produces `_parse_error` and no recovered field values. This query lists the files to fix:
108
-
109
- ```sql
110
- SELECT path, _parse_error
111
- FROM frontmatter
112
- WHERE _parse_error IS NOT NULL
113
- ORDER BY path;
114
- ```
115
-
116
- To find notes that genuinely omit `status`, use `status IS NULL AND _parse_error IS NULL`.
117
-
118
- ## Bound the output
119
-
120
- Select only the columns required by the task and add `LIMIT` while exploring. Avoid `SELECT text FROM content` because it returns the tree's prose. Use `search` for bounded passages, or select `path`, `title`, and `summary` and read the relevant files afterward.
@@ -1,35 +0,0 @@
1
- # DuckDB query guide
2
-
3
- Read this guide when `store` is `duckdb`.
4
-
5
- Sense stores the cache at `.sense/cache.duckdb`. It is a DuckDB database file with frontmatter values in `VARIANT` columns and embeddings in native fixed-width float arrays. Use this store when another DuckDB tool needs to inspect or analyze the cache.
6
-
7
- The first open installs `@duckdb/node-api` if needed, at the newest version in sensemaking's declared range. Its native download is about 110 MB. A build after the installed version changes rebuilds the cache, and a no-build query on that cache fails with `INDEX_NOT_READY` until it does. Under DuckDB's [concurrency model](https://duckdb.org/docs/current/connect/concurrency), Sense opens an existing cache for no-build observation in read-only mode, so several independent reader processes can coexist. A build-enabled command or watcher opens it read-write and excludes every other process until it closes. Contenders wait within Sense's bounded lock budget, then fail with `STORE_BUSY`. This cross-process rule does not promise writer/reader coexistence or unrestricted sharing by independently configured DuckDB instances in one process.
8
-
9
- ## `sense search` grammar
10
-
11
- Bare words and quoted phrases work. Bare words are joined with AND, and phrases are verified against authored text.
12
-
13
- The portable search command does not accept FTS5 prefix, boolean, `NEAR`, initial-token, column-filter, or grouping operators. Examples include `foo*`, `a OR b`, `NEAR(a b)`, `^term`, `title:term`, and `(a b)`. Sense raises `STORE_CAPABILITY_MISSING` instead of interpreting them as literals.
14
-
15
- To express alternatives, run separate bounded searches and combine the paths, or use a frontmatter filter when the distinction is structured.
16
-
17
- ## Raw text search
18
-
19
- `content` is a plain table. SQLite's `content MATCH`, `snippet()`, and `bm25()` do not run here. Use `sense search` for ranked text retrieval and combine it with `--where` for frontmatter filters.
20
-
21
- DuckDB maintains its own native FTS index for the search command. Its generated index name and scoring adapter are implementation details. Saved queries should not call them.
22
-
23
- ## Functions and types
24
-
25
- `has()`, `basename()`, and `segment()` are registered SQL functions. `segment()` is available for portable saved queries, although `sense search` already handles unspaced scripts.
26
-
27
- Frontmatter columns use DuckDB `VARIANT`. Homogeneous values compare normally. A numeric comparison against a field that contains numbers in some notes and text in others can raise a type error. Check `sense map` for mixed observed types before writing the predicate.
28
-
29
- DuckDB has its own date, JSON, list, and casting syntax. Use DuckDB SQL rather than copying SQLite functions into a saved query. For ISO 8601 timestamps with offsets, cast to `TIMESTAMPTZ` before comparing:
30
-
31
- ```sql
32
- WHERE created::TIMESTAMPTZ >= ?::TIMESTAMPTZ
33
- ```
34
-
35
- DuckDB's dialect closely follows PostgreSQL but has documented differences and its own extensions. Read the official [DuckDB SQL introduction](https://duckdb.org/docs/current/sql/introduction) for engine SQL. Queries written with DuckDB-only syntax stay tied to this store.
@@ -1,66 +0,0 @@
1
- # SQLite query guide
2
-
3
- Read this guide when `store` is `sqlite` or omitted.
4
-
5
- SQLite is the default store. It uses Node's built-in SQLite, keeps the cache at `.sense/cache.db`, supports concurrent sense commands through WAL, and implements the full search grammar documented here. A build after a Node upgrade that changes the bundled SQLite version rebuilds the cache, and a no-build query on that cache fails with `INDEX_NOT_READY` until it does.
6
-
7
- ## `sense search` grammar
8
-
9
- Search text uses FTS5 syntax:
10
-
11
- - Bare words are joined with AND. If one word is absent, the lexical signal returns no row.
12
- - `a OR b` matches either word.
13
- - `pref*` matches a token prefix.
14
- - `"exact phrase"` requires adjacent tokens.
15
- - `NEAR(a b, 5)` limits token distance.
16
- - `^term` requires the token at the start of a column.
17
- - `title:term` and `summary:term` filter by indexed column.
18
- - Parentheses group expressions.
19
-
20
- Double-quote terms containing punctuation. Bare `customer-facing` treats the hyphen as syntax, and a bare apostrophe is invalid.
21
-
22
- ## Raw text search
23
-
24
- `content` is an FTS5 virtual table. Refer to it by its table name in `MATCH`, even when the `FROM` clause has an alias:
25
-
26
- ```sql
27
- SELECT content.path, content.title
28
- FROM content
29
- WHERE content MATCH ?
30
- ORDER BY bm25(content, 10.0, 5.0, 1.0)
31
- LIMIT 20;
32
- ```
33
-
34
- The three BM25 weights rank title above summary above body. For queries that can match the machine-written unspaced-script sidecars, use all eight weights so the sidecars receive the same field weighting:
35
-
36
- ```sql
37
- ORDER BY bm25(content, 10.0, 5.0, 1.0, 0, 10.0, 5.0, 1.0)
38
- ```
39
-
40
- Raw `snippet(content, 2, '«', '»', '…', 10)` targets the authored body column. Avoid `-1` because it may choose a machine-written sidecar. SQLite's `snippet()` tokenizes the matched text again, so prefer `sense search` for large notes. Sense builds its own bounded passages on every store.
41
-
42
- ## Functions and unspaced scripts
43
-
44
- `has()`, `basename()`, and `segment()` are registered SQL functions. `sense search` handles Chinese, Japanese, Thai, Khmer, Lao, and Burmese automatically. Hand-written `MATCH` cannot be rewritten, so pass such terms through `segment()`:
45
-
46
- ```sql
47
- SELECT path FROM content WHERE content MATCH segment(?);
48
- ```
49
-
50
- `segment()` leaves other text unchanged.
51
-
52
- ## Dates and values
53
-
54
- Use SQLite's `datetime()` to compare ISO 8601 values with different offsets:
55
-
56
- ```sql
57
- WHERE datetime(created) >= datetime(?)
58
- ```
59
-
60
- SQLite's `now` is UTC. A calendar-day query in the machine's local timezone needs `localtime`:
61
-
62
- ```sql
63
- WHERE date(created) = date('now', 'localtime')
64
- ```
65
-
66
- Frontmatter values use SQLite storage classes. Booleans are integers, so compare true with 1. Lists and maps are JSON text and can be expanded with `json_each()`.
@@ -1,36 +0,0 @@
1
- # Turso query guide
2
-
3
- Read this guide when `store` is `turso`.
4
-
5
- Sense stores the cache at `.sense/cache.turso.db` and uses `@tursodatabase/database` with Tantivy full-text indexes. Use this experimental adapter when the tree benefits from the embedded Turso engine or its text-index behavior.
6
-
7
- The first open installs the native package if needed, at the newest version in sensemaking's declared range. A build after the installed version changes rebuilds the cache, and a no-build query on that cache fails with `INDEX_NOT_READY` until it does. Turso holds the cache file for the connection's lifetime, so another Sense command waits for the current command or watcher cycle to close it. The upstream engine supports more deployment and concurrency options than this adapter currently exposes. Sense opens a local file and does not configure sync, remote access, concurrent writers, or encryption.
8
-
9
- ## `sense search` grammar
10
-
11
- Bare words and quoted phrases work. Sense applies shared stemming and joins bare words with AND. It verifies phrases against authored text and uses n-gram sidecars for unspaced scripts.
12
-
13
- The portable search command does not accept FTS5 prefix, boolean, `NEAR`, initial-token or boost, column-filter, or grouping operators. Examples include `foo*`, `a OR b`, `NEAR(a b)`, `^term`, `title:term`, and `(a b)`. Sense raises `STORE_CAPABILITY_MISSING` instead of passing those forms to Tantivy.
14
-
15
- To express alternatives, run separate bounded searches and combine the paths, or use a frontmatter filter when the distinction is structured.
16
-
17
- ## Raw text search
18
-
19
- `content` is a regular table with store-owned stem and n-gram columns. SQLite's `content MATCH`, `snippet()`, and `bm25()` do not run here. Use `sense search` for ranked text retrieval.
20
-
21
- Turso exposes native `fts_match()` and `fts_score()`, but their valid scoring forms depend on the exact index projection. Sense owns those calls so that scores do not silently flatten. Saved queries should not call the store-owned text indexes.
22
-
23
- ## Functions and types
24
-
25
- `has()` and `basename()` work in raw SQL. Sense rewrites them into portable SQL because the client cannot register user-defined functions. Nested calls and placeholders are supported.
26
-
27
- `segment()` is unavailable. A query that calls it raises `STORE_CAPABILITY_MISSING`. `sense search` still handles unspaced scripts without it.
28
-
29
- Turso follows SQLite syntax for common date and JSON operations. Use `datetime()` for ISO 8601 comparisons and add `localtime` when a calendar-day query means the machine's local day:
30
-
31
- ```sql
32
- WHERE datetime(created) >= datetime(?)
33
- WHERE date(created) = date('now', 'localtime')
34
- ```
35
-
36
- Frontmatter lists and maps are stored as JSON text and can be expanded with `json_each()`.
@@ -1,32 +0,0 @@
1
- # Sense terminology
2
-
3
- This is the shared vocabulary for Sense's README, command help, API documentation and skills. Use these names when describing results and output controls.
4
-
5
- | Term | Meaning |
6
- |---|---|
7
- | Note | One Markdown file. A document is the same unit; SQL and some status fields use that name. |
8
- | Tree | The directory of notes configured as Sense's root. |
9
- | Frontmatter | The YAML metadata at the beginning of a note, such as its title, tags or status. |
10
- | Search result | One matching note, returned with its path, ranking information and any snippets. A result is not a section or a chunk. |
11
- | Snippet | A short passage selected around matching words, marked with `«»`. A note can return multiple snippets. A snippet need not contain a whole section. |
12
- | Heading | A Markdown heading such as `## Installation`. Its level is its depth, from 1 to 6. |
13
- | Section | A heading and the content following it until the next heading of any level, or the end of the note. Text before the first heading is not a section in the `sections` table. A parent section does not include subsequent subsections. |
14
- | Section description | The heading text, level, start and end lines, and estimated token count returned by `peek`. It does not contain the section's prose. |
15
- | Outline | The section descriptions in document order. It is a view of the note's structure, not another stored type of content. |
16
- | Chunk | A span of note content prepared for embedding. Chunking follows document structure and a token budget; a chunk is not necessarily one section or one snippet. |
17
- | Line range | Inclusive, one-based lines in the indexed source note, such as `L12-28`. Search can point to a section or an embedding chunk. A null range provides no narrower location. |
18
- | Outbound link | A link from the current note to another indexed note. `peek.outbound` returns distinct destination paths. |
19
- | Backlink | A link from another indexed note to the current note. `peek.backlinks` returns distinct source paths. |
20
- | Unresolved link | A written link target that did not resolve to an indexed note. This does not establish that the link is broken: attachments and notes outside the index can also be unresolved. `peek.unresolved` returns written targets. |
21
- | Scope | The indexed notes selected for an operation by its preset and filters. Scope is not an access-control boundary. |
22
- | Search signal | One source of ranking evidence: word matches, link relationships or vector similarity. A signal's rank is a candidate's position within that signal, not the final combined position. |
23
-
24
- ## Reading a section description
25
-
26
- The illustrative entry `## Installation [L12-28, ~90t]` describes a section headed “Installation”, starting at line 12 and ending at line 28, with an estimated 90 tokens. `peek` returns that description. Reading the indicated lines retrieves the content. With nested headings, the description ends before the next heading, even when that heading is deeper.
27
-
28
- ## Naming output controls
29
-
30
- Name the object and the unit: a snippet count is how many passages are returned; a snippet character limit controls passage length; a section count is how many section descriptions are returned; a link count controls link entries. A count limit is not pagination. An offset, when supported by an operation, skips entries before returning the requested count. Raw SQL supports `LIMIT` and `OFFSET`; search and peek do not currently expose offset options.
31
-
32
- Peek count limits request prefixes of the ordered section and link lists. Each search or peek reads one committed index snapshot; separately issued operations can observe later commits. See [finite retrieval and paging](search.md#finite-retrieval-and-paging) for search budgets and paging retained results.
@@ -1,103 +0,0 @@
1
- # sense-bases: worked translations
2
-
3
- Two real `.base` shapes translated end to end. Field names are illustrative; your tree
4
- defines its own.
5
-
6
- ## A. Filtered, sorted table with formulas
7
-
8
- The base: notes categorized as Movies, excluding templates, with a "To-watch" view of unseen
9
- entries sorted by score.
10
-
11
- ```yaml
12
- filters:
13
- and:
14
- - categories.contains(link("Movies"))
15
- - '!file.name.contains("Template")'
16
- views:
17
- - type: table
18
- name: To-watch
19
- filters:
20
- and:
21
- - last.isEmpty()
22
- - rating.isEmpty()
23
- order: [file.name, year, scoreImdb, runtime, director]
24
- sort:
25
- - { property: scoreImdb, direction: DESC }
26
- - { property: file.name, direction: ASC }
27
- ```
28
-
29
- One view, one query. Base filters AND view filters; `order` is the SELECT list; `sort` the
30
- ORDER BY. The link comparison is the literal written text (`[[Movies]]`), the name test uses
31
- `basename` so a folder named Templates does not false-positive:
32
-
33
- ```sql
34
- SELECT basename(f.path, '.md') AS name, f.year, f.scoreImdb, f.runtime, f.director
35
- FROM frontmatter f
36
- WHERE EXISTS (SELECT 1 FROM json_each(f.categories) WHERE value = '[[Movies]]')
37
- AND instr(basename(f.path), 'Template') = 0
38
- AND (f.last IS NULL OR f.last IN ('', '[]', '[null]'))
39
- AND (f.rating IS NULL OR f.rating IN ('', '[]', '[null]'))
40
- ORDER BY f.scoreImdb DESC, name ASC
41
- ```
42
-
43
- Saved in `sense.config.json` under `queries` as e.g. `to-watch`, it runs as `sense to-watch`.
44
-
45
- ## B. `this`-relative: the Related pattern
46
-
47
- The base: for the current note, every other note ranked by shared outgoing links, including
48
- anything it links or that links to it.
49
-
50
- ```yaml
51
- filters:
52
- and:
53
- - file.path != this.file.path
54
- formulas:
55
- Related: list(this.file.links).filter(list(file.links).containsAny(value)).unique()
56
- LinksOverlap: formula.Related.length
57
- views:
58
- - type: table
59
- name: Related
60
- filters:
61
- or:
62
- - formula.LinksOverlap > 2
63
- - file.hasLink(this)
64
- - this.file.hasLink(file)
65
- sort:
66
- - { property: formula.LinksOverlap, direction: DESC }
67
- limit: 20
68
- ```
69
-
70
- `this` becomes one bound path. The chained list formula (`filter(...containsAny).unique()`)
71
- is set intersection, which SQL states as an IN-filtered count; the `Related` list itself is
72
- the same rows through `GROUP_CONCAT`:
73
-
74
- ```sql
75
- WITH me AS (SELECT ? AS p),
76
- mine AS (SELECT DISTINCT dst FROM links, me WHERE src = me.p AND dst IS NOT NULL),
77
- scored AS (
78
- SELECT f.path,
79
- (SELECT COUNT(DISTINCT l.dst) FROM links l
80
- WHERE l.src = f.path AND l.dst IN (SELECT dst FROM mine)) AS overlap,
81
- EXISTS (SELECT 1 FROM links, me WHERE src = f.path AND dst = me.p) AS links_to_me,
82
- EXISTS (SELECT 1 FROM links, me WHERE src = me.p AND dst = f.path) AS linked_by_me,
83
- (SELECT GROUP_CONCAT(DISTINCT l.dst) FROM links l
84
- WHERE l.src = f.path AND l.dst IN (SELECT dst FROM mine)) AS shared_links
85
- FROM frontmatter f, me WHERE f.path != me.p)
86
- SELECT path, overlap, shared_links FROM scored
87
- WHERE overlap > 2 OR links_to_me OR linked_by_me
88
- ORDER BY overlap DESC
89
- LIMIT 20
90
- ```
91
-
92
- Run as `sense sql "..." current-note.md`, or saved with the `?` in place and the path passed
93
- as the parameter. The `or:` block reproduces Obsidian's semantics exactly: rows qualify by
94
- overlap, by linking to the note, or by being linked from it, so leaf notes the current note
95
- links to appear even at zero overlap, as they do in Obsidian.
96
-
97
- ## Notes that recur across translations
98
-
99
- - Multiple views over the same base share the base-level filter; write it once per query
100
- rather than factoring it out. Saved queries are self-contained by design.
101
- - `sort` keys referencing formulas sort by the SELECT alias.
102
- - A `groupBy` view keeps its rows; see the window-function shape in SKILL.md. Only a
103
- deliberately collapsed report wants `GROUP BY`.
@@ -1,147 +0,0 @@
1
- ---
2
- name: sense-bases
3
- description: "Translate an Obsidian Bases .base file into sense SQL that returns the same rows. Use when asked to convert, import, or reproduce a .base file (or a Bases view, filter, or formula) with sense, or when a markdown tree contains .base files whose views someone wants queryable outside Obsidian."
4
- ---
5
-
6
- # sense-bases
7
-
8
- A `.base` file is YAML: filters selecting notes, formulas computing values, and views ordering
9
- and grouping them. Obsidian evaluates it against its own metadata cache; sense holds the same
10
- data in SQL tables. Every Bases construct that selects or computes rows has a SQL equivalent.
11
- What has none is presentation (`columnSize`, card layout), those change pixels, not rows, so
12
- a translation loses nothing by ignoring them.
13
-
14
- Translate one view to one query: base-level `filters` AND the view's `filters`, the view's
15
- `order`/`sort`/`limit` as the SELECT list, ORDER BY, and LIMIT. A base with four views becomes
16
- four queries; saving them under the base's name in `sense.config.json`'s `queries` block keeps
17
- them runnable as `sense <name>`. The general query surface is the `sense` skill; this one only
18
- maps Bases constructs onto it.
19
-
20
- ## Properties
21
-
22
- | Bases | sense | notes |
23
- |---|---|---|
24
- | `note.field` / bare `field` | `f.<field>` | frontmatter column, same name |
25
- | `file.name` | `basename(f.path, '.md')` | the Name column: no directory, no extension |
26
- | a name with extension | `basename(f.path)` | the suffix arg is Unix basename's: present, stripped |
27
- | `file.folder` | `f.path LIKE 'Folder/%'` | for `inFolder("Folder")` |
28
- | `file.ext` | `'md'` | sense indexes only markdown |
29
- | `file.size` | `f._size` | bytes |
30
- | `file.mtime` | `datetime(f._mtime / 1000, 'unixepoch')` | stored as ms |
31
- | `file.ctime` | `datetime(f._ctime / 1000, 'unixepoch')` | see the caveat below |
32
- | `file.tags` | the `tags` table | frontmatter + inline `#tags`, deduplicated, Obsidian's grain |
33
- | `file.links` | `links WHERE embed = 0` | one row per distinct written target |
34
- | `file.embeds` | `links WHERE embed = 1` | |
35
- | `file.backlinks` | `links WHERE dst = f.path` | |
36
- | `this` | a bound `?` | see below |
37
-
38
- `file.ctime` is the filesystem's creation time. A `git clone` or a copy resets it, so on a
39
- tree that arrived as a checkout, every ctime is the checkout date and age formulas are wrong
40
- about authorship without being wrong about the filesystem. `map` warns when modification
41
- times have this shape; creation times share it.
42
-
43
- ## Predicates
44
-
45
- | Bases | sense |
46
- |---|---|
47
- | `==` `!=` `>` `<` `>=` `<=` | same |
48
- | `&&` `\|\|` `!` | `AND` `OR` `NOT` |
49
- | `and:` / `or:` / `not:` filter blocks | parenthesized `AND` / `OR` / `NOT` |
50
- | `field.isEmpty()` | `(f.field IS NULL OR f.field IN ('', '[]', '[null]'))` |
51
- | `file.hasTag("book")` | `EXISTS (SELECT 1 FROM tags WHERE tags.path = f.path AND (tag = 'book' OR tag LIKE 'book/%'))` |
52
- | `file.hasLink("Note")` | `EXISTS (SELECT 1 FROM links WHERE src = f.path AND dst = 'Note.md')` |
53
- | `list.contains(x)` | `EXISTS (SELECT 1 FROM json_each(f.list) WHERE value = x)` |
54
- | `string.contains(x)` | `instr(f.string, x) > 0` |
55
- | `list.containsAny(...)` | the `json_each` EXISTS with `value IN (...)` |
56
- | `/regex/.matches(x)` | no SQLite regex; `LIKE`/`GLOB` cover anchored and wildcard shapes |
57
- | `value.isType("object")` | `json_each`'s own `type` column: `... FROM json_each(f.field) j WHERE j.type = 'object'` |
58
-
59
- A field no note in the tree declares has no column at all, so a filter naming it errors with
60
- `no such column` instead of treating every row as empty. Obsidian's evaluator returns empty
61
- for unknown properties; SQL does not. Dropping the clause states the same thing the error
62
- did, and `SELECT name FROM pragma_table_info('frontmatter')` lists what exists.
63
-
64
- `isEmpty()` has four true cases because empty is stored three ways: NULL (key absent), `''`
65
- (empty string value), `'[]'` (a list written `[]`), and `'[null]'` (a list key above a bare
66
- `-`). Obsidian's `isEmpty()` is true for all of them; `IS NULL` alone finds only the first.
67
- The IN list is the whole test. `json_array_length()` is not: it reads `'[null]'` as length
68
- 1 and throws on plain strings. The same trap inside a list: `json_each` hands a string member
69
- to `value` as plain text, so `json_type(value)` throws `malformed JSON` on it; the scan's own
70
- `type` column is the discriminator.
71
-
72
- `contains(link("Movies"))` compares against a link value. In frontmatter, a list of links
73
- holds the written text, so the `json_each` comparison value is the literal `[[Movies]]`.
74
- `hasLink` compares resolved paths: `links.dst` is the resolved target (`NULL` for dead
75
- links), so the comparison value is the target's path, not its display name.
76
-
77
- sense's own `has(field, x)` is looser than both `contains` variants: exact membership on JSON
78
- arrays but substring on strings, so `has(f.status, 'active')` also matches `inactive`. It
79
- reads shorter when the field is known to be a list; the `json_each` form is the exact
80
- translation.
81
-
82
- ## Formulas
83
-
84
- Formulas are SELECT expressions. The Bases functions map onto SQLite's:
85
-
86
- | Bases | sense |
87
- |---|---|
88
- | `if(c, a, b)` | `iif(c, a, b)` or `CASE WHEN` |
89
- | `now()` / `today()` | `datetime('now')` / `date('now')` |
90
- | `date(x)` | `datetime(x)` |
91
- | `(date1 - date2).days` | `julianday(date1) - julianday(date2)` |
92
- | `(now() - acquired).months` | `(julianday('now') - julianday(f.acquired)) / 30.44` |
93
- | `x.round(n)` / `x.toFixed(n)` | `round(x, n)` / `printf('%.2f', x)` |
94
- | `d.format("YYYY-MM-DD")` | `strftime('%Y-%m-%d', d)` |
95
- | `x.toString()` | `CAST(x AS TEXT)` |
96
- | `list.length` | `json_array_length(f.list)` on a JSON column, a COUNT subquery on a table |
97
- | `list(a).filter(list(b).containsAny(value)).unique()` | an EXISTS-joined subquery; worked example in EXAMPLES.md |
98
-
99
- Bases durations are typed; SQL date arithmetic is julianday day-fractions. A formula chaining
100
- duration fields (`.days.round()`) flattens to arithmetic on the julianday difference.
101
-
102
- A formula referencing another formula becomes a CTE layer: SQL cannot read a SELECT alias in
103
- the same SELECT list, so each dependency level computes its formulas as columns and the next
104
- level reads them (`WITH t AS (SELECT ..., <level-1 formulas> FROM frontmatter) SELECT ...,
105
- <level-2 formulas> FROM t`). A five-formula chain is however many *levels* it has, not five
106
- CTEs. Formulas that only read base columns share one layer.
107
-
108
- ## Views
109
-
110
- - `sort:` (multi-key, each with direction) -> `ORDER BY a DESC, b ASC`. `limit:` -> `LIMIT`.
111
- - `groupBy` does not collapse rows. Obsidian shows every row bucketed under headers with
112
- per-group summaries. The SQL producing the same rows and numbers is ordering plus window
113
- functions, not GROUP BY:
114
-
115
- ```sql
116
- SELECT f.path, f.status, f.days,
117
- AVG(f.days) OVER (PARTITION BY f.status) AS group_avg,
118
- COUNT(*) OVER (PARTITION BY f.status) AS group_n
119
- FROM frontmatter f WHERE f.days IS NOT NULL
120
- ORDER BY f.status, f.days DESC
121
- ```
122
-
123
- A collapsed one-row-per-group report is plain `GROUP BY`. That is a different result than
124
- the Bases view shows.
125
- - View `summaries` (Sum, Average, Median via ordering, Unique, Filled, Checked) are the
126
- matching aggregates, windowed as above to keep the rows, or a separate aggregate query.
127
-
128
- ## `this`
129
-
130
- `this` is the note the base is evaluated against: the embedding note, or Obsidian's active
131
- pane. sense has no pane, so the caller supplies the path as a bound parameter: `sense sql
132
- "..." <path>`, or a saved query run as `sense <name> <path>`. A CTE keeps it single-bind:
133
-
134
- ```sql
135
- WITH me AS (SELECT ? AS p)
136
- ```
137
-
138
- and every `this.file.*` expression joins `me`. The full Related.base translation in
139
- EXAMPLES.md is the worked case: link overlap, mutual-link filters, and the shared-target list
140
- via `GROUP_CONCAT`, all from one bound path.
141
-
142
- ## Not translatable, and why it costs nothing
143
-
144
- - `columnSize`, card/table/list/map chrome: pixel layout over the same rows.
145
- - Obsidian choosing `this` from the active pane: there is no pane; the path parameter is the
146
- resolution.
147
- - Live re-evaluation as files change: default CLI queries incrementally prepare the needed capabilities; `--no-build` reads the last completed generation and requires its requested readiness without scanning live files. Nothing re-renders on its own.