Skip to content

Run a saved query by id or title, narrow it at run time, negate filters, and filter into link and object values #3554

Closed

Description

@malibio

Overview

A saved query is the way a team defines a view, and under ADR-094 it is also how a queue of work is defined: "Ready tasks", "Awaiting review", or anything a team saves. Today a saved query can only be opened in the app. It cannot be run from the CLI or by the built-in agent, it cannot say "none of" or "is not", and it cannot filter on a value inside a link or object field. This issue makes saved queries runnable and expressive enough to serve as queues.

Problem Statement

  • No way to run one. ExecuteQuery takes an inline definition. No RPC or CLI command takes a query node's id, so an agent has to fetch the node and copy its filters into nodespace query by hand. The only backend code that loads and runs a saved query is a Play's scheduled selector.
  • No narrowing. One "Ready tasks" query cannot be run for a single project without saving a copy per project.
  • No negation. Filters are ANDed and existential. "Has no unfinished blocker", "has no plan that is not approved" and "has no assignee" cannot be written.
  • No path into a structured value. A property filter's name may not contain a dot, so repository.url on a link field is refused. Finding the project for a git remote needs it.

Proposed Solution

  • nodespace query run <id|title> executes a saved query node and returns its nodes, with the global --json. The built-in agent gets the same as a tool.
  • Extra filters given at run time are ANDed with the stored ones.
  • Any filter can be negated, including a Related filter and the filter nested inside one.
  • A property filter and a sort can name a field inside an object or link value, validated against the schema.

Nothing here knows any type or workflow.

Documentation

  • ADR-094 §1 - a queue is a saved query; run by id or title; run-time narrowing; negation; paths into object and link values. Build order step 1
  • ADR-091 - saved queries, relative dates, where saved views appear
  • ADR-093 §1 and §4 - running a saved query is part of a coding agent's interface; the project for a checkout is found by an ordinary query
  • Relationship paths - the paths a Related filter follows
  • Updates: the saved-query sections of architecture/data-layer.md or the query component doc (negation, structured paths, run by id), packages/skill/references/cli.md and SKILL.md

Architecture Impact

Implements ADR-094 §1. It extends the query filter vocabulary and adds an execution path; it changes no existing decision.

Acceptance Criteria

  • nodespace query run <id> and nodespace query run "<title>" return the nodes the saved query matches, honouring its filters, sorting, limit and relative dates; --json returns the node list
  • A title that matches no saved query, or more than one, fails with a message that says which
  • Filters given at run time are ANDed with the stored filters and do not change the stored query
  • A filter can be negated; a negated Related filter means "the path reaches no node matching the nested filter"; the nested filter can be negated too
  • "Tasks with no blocked_by task whose status is not done or cancelled" and "tasks with no plan whose plan_status is not approved" can each be written as a saved query and return the right tasks, including tasks with no blocker and no plan at all
  • A property filter and a sort accept a path into an object or link field (repository.url); a path that the schema does not declare is refused at save time and at run time with a message naming it
  • A filter name still cannot break out of the JSON path: quotes, whitespace and unknown segments are refused
  • The built-in agent has a tool that runs a saved query by id or title, and the tool is in the tool registry with its CLI command
  • A Play's scheduled selector keeps working, and accepts the new filter forms
  • The app's query builder still loads and saves every query it could before; a query using a form the builder cannot edit is shown read-only rather than rewritten
  • references/cli.md and SKILL.md document query run, run-time narrowing and negation, and bun run skill:check passes
  • Docs updated as listed under Documentation
  • Code passes bun run quality:fix
  • Tests pass (bun run test:changed)

Technical Specifications

Reference Files

  • packages/nodespace-types/src/query.rs - FilterType, FilterOperator, QueryFilter, SortConfig, QueryFields
  • packages/core/src/services/query_service/mod.rs - filter compilation, validate_identifier, the Related filter and its nesting limit, sorting
  • packages/core/src/ops/query_ops.rs - execute_query_nodes
  • packages/core/src/playbook/selectors.rs - the one place that loads a saved query node and runs it
  • packages/proto/proto/node_service.proto, packages/daemon/src/services/node_service.rs - ExecuteQuery, CountQuery
  • packages/cli/src/commands/query.rs - nodespace query
  • packages/agent/src/local_agent/tools.rs, packages/agent/src/skill_pipeline.rs - the built-in agent's tools and the seeded tool nodes
  • packages/desktop-app/src/lib/components/viewers/query-node-viewer.svelte - the app's query viewer

Implementation Details

  • QueryFilter is a wire type: change it once in nodespace-types, regenerate TypeScript, and keep deny_unknown_fields.
  • Negation is one optional flag on a filter, not a set of new operators.
  • A structured path is a list of segments checked against the schema's declared fields, not a string spliced into SQL.
  • Resolve types through the registry, never a literal node_type comparison.
  • The filter shape changes with no migration: reset the database.

Related Issues

Non-Goals

  • OR between filters
  • A filter that asks whether a change would be allowed
  • Returning each node's context or skills with a run

Activity

  1. malibio commented on Oct 5, 2026

    @malibio
    CollaboratorAuthor

    Baseline — Frontend: 317 test files passed, 5733 tests passed

  2. self-assigned this
    on Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions