Skip to content

Commit 1303d8c

Browse files
[AI] Make yaml input inline-only and clarify query source options
1 parent 5da1809 commit 1303d8c

6 files changed

Lines changed: 29 additions & 6 deletions

File tree

AGENTS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ When asked to create commits in this repository:
111111
- CSV serialisation uses the selected/declared column list as the canonical header order.
112112
- View `order` is treated as projected column order; row sorting is driven by `sort`.
113113
- When no explicit columns are configured, projected columns are inferred from matched note frontmatter keys (with `file.name` first).
114+
- `--yaml`/`yaml` accepts inline YAML text only; file paths must use `--base`/`basePath`.
114115

115116
## Decision Log
116117

@@ -133,3 +134,8 @@ When asked to create commits in this repository:
133134
- Context: Real `.base` files depend on `order` for visible columns and often use frontmatter keys containing spaces.
134135
- Decision: Treat `view.order` as column projection order, keep `view.sort` for row ordering, infer columns when unspecified, and resolve non-expression property names directly from note data.
135136
- Consequence: Query output now includes expected Base properties instead of falling back to `file.name`/`file.path` defaults.
137+
138+
- 2026-02-18 - Inline-only YAML option semantics
139+
- Context: `--yaml` overlapped with `--base` by auto-detecting file paths, which created ambiguous query source behavior.
140+
- Decision: Restrict `--yaml`/`yaml` to inline YAML text and reject path-like input with guidance to use `--base`/`basePath`.
141+
- Consequence: CLI and library query-source semantics are clearer and avoid accidental mode switching based on filesystem state.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ There is one command surface; all behavior is controlled through options.
4343
`mdbasequery` supports three ways to provide the query definition:
4444

4545
1. `.base` file via `--base <path>`
46-
2. YAML via `--yaml <string-or-path>`
46+
2. Inline YAML via `--yaml <yaml-text>`
4747
3. Flag-built query mode (`--filter`, `--select`, `--sort`, etc.)
4848

4949
If `--base`/`--yaml` are not provided, the query is built from flags.
@@ -111,7 +111,7 @@ mdbasequery --yaml "views: [{ type: table, name: default }]" --no-strict
111111
| --- | --- | --- |
112112
| `--dir <path>` | string | Target directory to scan (default: current directory). |
113113
| `--base <path>` | string | Path to Obsidian-style `.base` YAML file. |
114-
| `--yaml <string-or-path>` | string | Inline YAML text or a path to a YAML file. |
114+
| `--yaml <yaml-text>` | string | Inline YAML text. |
115115
| `--view <name>` | string | View name to run (default: first view). |
116116
| `--format <json|jsonl|yaml|csv|md>` | string | Output format (default: `json`). |
117117
| `--out <path>` | string | Write serialized output to file instead of stdout. |
@@ -206,7 +206,7 @@ Runtime adapters:
206206

207207
- `spec?: QuerySpec` - already parsed query spec.
208208
- `basePath?: string` - path to `.base` file.
209-
- `yaml?: string` - inline YAML or YAML path.
209+
- `yaml?: string` - inline YAML text.
210210
- `view?: string` - selected view name.
211211
- `dir?: string` - vault root directory.
212212
- `strict?: boolean` - strict symbol/function behavior (default true).

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const HELP_TEXT = `mdbasequery [options]
3030
Core options:
3131
--dir <path> target directory (default .)
3232
--base <path> load .base YAML file
33-
--yaml <string-or-path> inline YAML query or path to YAML file
33+
--yaml <yaml-text> inline YAML query text
3434
--view <name> choose view by name (default first view)
3535
--format <fmt> json|jsonl|yaml|csv|md (default json)
3636
--out <path> write output to file

src/query.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ async function loadSpec(
3333
const yamlInput = options.yaml;
3434

3535
if (await adapter.exists(yamlInput)) {
36-
const content = await adapter.readTextFile(yamlInput);
37-
return parseBaseYaml(content);
36+
throw new Error("--yaml expects inline YAML text; use basePath/--base for file paths");
3837
}
3938

4039
return parseBaseYaml(yamlInput);

tests/cli.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ describe("cli integration", () => {
4545
expect(result.stdout).toContain("Alpha");
4646
});
4747

48+
test("rejects file path passed to --yaml", () => {
49+
const yamlPath = resolve(fixturesRoot, "queries/basic.base");
50+
const result = runCli(["--yaml", yamlPath, "--dir", vaultDir, "--format", "json"]);
51+
52+
expect(result.status).toBe(1);
53+
expect(result.stderr).toContain("--yaml expects inline YAML text");
54+
expect(result.stderr).toContain("--base");
55+
});
56+
4857
test("--view selection and output destination", () => {
4958
const basePath = resolve(fixturesRoot, "queries/grouped.base");
5059
const tempDir = mkdtempSync(resolve(tmpdir(), "mdbasequery-"));

tests/phase0-smoke.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ views:
2323
expect(serialized).toContain("rows");
2424
});
2525

26+
test("queryBase rejects yaml file paths", async () => {
27+
await expect(
28+
queryBase({
29+
dir: resolve(fixturesRoot, "vaults/basic"),
30+
yaml: resolve(fixturesRoot, "queries/basic.base"),
31+
}),
32+
).rejects.toThrow("--yaml expects inline YAML text");
33+
});
34+
2635
test("CLI help works", () => {
2736
const output = spawnSync("bun", ["run", "src/cli.ts", "--help"], {
2837
cwd: repoRoot,

0 commit comments

Comments
 (0)