Status: SHIPPED (Jul 6 2026, in [Unreleased]). All three landed in the built order
(1c → 1a → 1b): coverage expansion (parse_adv_group widened + field-aware between),
aggregation/group-by (∑ summarize control + queryAggregate.ts + Aggregate/GroupBy
no-op preds), and the ⚙ advanced switch (skeleton + EDN ;-comment support in
scan_groups). Verified: cargo test -p tine-core, npm test, and the screenshot
harnesses scripts/shot-summarize.mjs + scripts/shot-advanced-switch.mjs. This doc is
kept as the design record; the resume-from-cold spec below reflects what was built.
Three features, one subsystem:
- 1a Aggregation on query results — no-code count / sum-of-property / average / group-by.
- 1b Discoverable advanced
[:find …]queries — a "switch to advanced" affordance. - 1c Datalog coverage expansion — widen the advanced clause subset.
Engine — crates/tine-core/src/query.rs:
enum Pred(~1143) mirrors the builder clauses:PageRef, Task, Priority, Property, Scheduled, Deadline, Journal, Between(BetweenField,…), Page, Namespace, PageProperty, PageTags, Content, And/Or/Not, Sample(usize), SortBy(String,bool).Sample/SortByare result-level options whoseevalreturnstrue(no filtering) — the template to copy for anAggregatedirective.- Parse:
Pred::parse(~1250) bails toNoneifis_advanced(src)(~1134), elsetokenize(~1407) →parse_expr(~1486). Clause-head dispatch =match headat 1508–1599; unknown head →return None(1599) → whole query fails. (Critical constraint for 1a — see decision below.) - Eval:
Pred::eval(block, ctx)(~1271);EvalCtx(~1195) carries page facts. - Results:
run_query(~231)→run_pred(~243). ReturnsVec<RefGroup>, NOT ids.RefGroup { page, kind, blocks: Vec<BlockDto> }(model.rs 191). EachBlockDto(model.rs 159, built byblock_to_dtomodel.rs ~3543) already carriesmarker, priority, scheduled, deadline, properties: Vec<(String,String)>.sample Ntruncation ~337. - Advanced:
is_advanced(~1134),run_advanced_query(~445),parse_adv_group(538–621) — supported heads today:and/or/not, task, priority, page-ref, property, page-property, between(between hardwired toBetweenField::Journalat ~612). The simple parser supports strictly MORE (page, namespace, page-tags/tags, scheduled, deadline, journal, sample, sort-by). ReturnsAdvancedResult { groups, ran, ignored, supported }(~431) — ran-vs-ignored already reported.
Command boundary — src-tauri/src/commands.rs: run_query(238)→Vec<RefGroup>,
run_advanced_query(246)→AdvancedResult, query_facets(257)→property facets for the
builder pickers. JS: backend.ts runQuery(97)/runAdvancedQuery(100)/queryFacets(103);
types in src/types.ts (RefGroup/BlockDto/AdvancedQueryResult ~146–159); mock in
src/mock.ts (runQuery 465, runAdvancedQuery 460, queryFacets 526).
Builder model — src/editor/queryBuilder.ts (DOM-free; SSOT is the DSL text):
type Clause (~14), parseQuery(~325), toDsl(~405)/clauseDsl(~357), mutations
(~542), SORT_PRESETS(~430), clauseLabel(~450).
Builder UI — src/components/QueryBuilder.tsx: QueryBuilder({dsl,onChange,blockId})
(~170) → apply(next)=onChange(toDsl(next)) (~184); SortControl (69–167) is the model
for a result-level control; FILTER_TYPES (378–392) registers clause kinds; AddPicker
(394), ValuePicker (437), ChipMenu (296). Auto-open signal in src/ui.ts (~368),
triggered from Block.tsx (~1241).
Render — src/components/Macro.tsx QueryMacro (~70): ADVANCED_RE(14)/isAdvanced
(125) picks the path; createResource fetch keyed on dataRev (142–155); total() (156)
= working count; rows() (166–176) flattens groups to {page,kind,text,props}; cols()
(178); table sorts by property client-side (184–189); header query-count (284); result
body <Switch> (~210). advInfo (ran/ignored) already surfaced for the advanced path.
Tests: src/editor/queryBuilder.test.ts (roundtrip = toDsl(parseQuery(dsl)), ~16 +
per-clause suites) is the builder oracle. query.rs #[cfg(test)] (~1672): pred(src)
helper, parse/eval tests, advanced_datalog_is_unsupported (~1762).
- D1 — aggregation is computed in JS, from the returned block list. The DTO already
ships every field an aggregate needs;
rows()already flattens them;total()already counts. No Rust aggregate payload, no second render branch. (Scout-confirmed: lower risk, no duplication, no perf win from Rust since the set is already materialized + bounded.) - D2 — the aggregate directive lives IN the
{{query}}DSL, and Rust must parse-but- ignore it. The builder's single source of truth is the DSL text, and{{query}}must round-trip. Butparse_exprfails the whole query on an unknown head (1599), andMacro.tsxsends the DSL torun_query. So add anAggregateno-op-filterPredvariant (eval→true, exactly likeSample) parsed from(aggregate count),(aggregate sum <prop>),(aggregate avg <prop>),(group-by page|<prop>). Rust then returns the full set; the frontend re-parses the same DSL (parseQuery) to know which aggregate to render. This keeps run_query succeeding and the builder round-tripping. - D3 — OG-parity flag (surface to Martin when shipping). OG does aggregation only via
datalog
:result-transform/(count …), which Tine lists asignored. A no-code JS aggregation is a Tine-specific addition on top of OG, not OG-faithful — note the divergence (per the match-OG working agreement) but it's an explicitly-wanted beat-OG. - D4 — 1b emits a datalog skeleton; because
Macro.tsxgates onADVANCED_RE, writing[:find …]text auto-flips the render path torunAdvancedQuery. The skeleton lists the supported heads (post-1c) as inline hints;advInfoalready shows ran/ignored so mistakes stay visible.
Step 1 — 1c (coverage expansion) first (unblocks the 1b skeleton's hint list):
- Widen
parse_adv_group(query.rs 556–620) to the heads the simple parser already has but advanced lacks:page,namespace,page-tags/tags,scheduled,deadline,journal; makebetweenfield-aware (drop the hardwiredBetweenField::Journalat ~612, read the field like the simple parser does). - Tests: extend
query.rstests next toadvanced_datalog_is_unsupported— assert each new head maps (appears inran, filters correctly) and unknowns still land inignored.
Step 2 — 1a (aggregation):
- Rust: add
Aggregate(and/or reuse for group-by) variant toPred(~1143); parse headsaggregate/group-byinparse_expr(~1508);eval→true(no filter, likeSample~1327); make surecollect_opts/run_preddon't treat it as a filter. Round-trip test inquery.rs. - Builder model (
queryBuilder.ts): add anaggregate/group-byClausekind; parse inparseQuery/serialize inclauseDslsotoDsl(parseQuery(dsl))round-trips; addclauseLabel. Round-trip tests inqueryBuilder.test.ts. - Builder UI (
QueryBuilder.tsx): a result-level control modeled onSortControl(69–167) — a dropdown (None / Count / Sum property / Average property / Group by page|property), the property choices fromqueryFacets(). Render it next toSortControlin theQueryBuilderreturn (~190). - Render (
Macro.tsx): read the aggregate directive (re-parseform()viaparseQuery, or thread it from the builder); compute acreateMemooverrows()(166) — count = length; sum/avg = parse the chosen property's values as numbers (skip non-numeric, surface how many skipped); group-by = aMap<groupKey, rows[]>rendering oneQueryGroup/table per key. Render count/sum/avg near the headerquery-count(284) or as a summary row above the<Switch>(210); group-by replaces the flat list with per-group sections. - Mock: ensure
src/mock.ts runQueryreturns blocks withpropertiesso the aggregate is demoable in the screenshot harness; add a fixture query.
Step 3 — 1b (discoverable advanced):
- Add a "Switch to advanced" button to
QueryBuilder.tsx(~190) →props.onChange(skeleton)where skeleton =[:find (pull ?b [*])\n :where\n ; supported: (task TODO DOING) (priority A) (page-ref "X") (property k v) (between …) …\n ]pre-filled from the post-1c supported heads. Because it's datalog,Macro.tsxflips torunAdvancedQueryautomatically. - Optionally a reverse "back to visual builder" only when the datalog is still builder-representable (nice-to-have; can defer).
- Confirm
advInfo(ran/ignored) renders for the skeleton so users see which lines took.
npm test(both configs) +cargo test -p tine-corefor the engine.- Visual: screenshot-harness a
{{query}}with an aggregation control + a group-by, per the visual-verification rule (mock must returnproperties). - Round-trip is the core invariant:
toDsl(parseQuery(dsl)) === dslfor every new clause.
docs/FEATURES.md(query section),CHANGELOG.md [Unreleased], remove the item(s) fromdocs/BACKLOG.mdNext, and the comparison page (website/compare.html) "math on queries" row this closes.