Skip to content

Add built-in JSON/JSONL parse plugin with multi-parser merging - #277

Merged
mindsocket merged 3 commits into
mainfrom
feat/112-json-parser
Nov 30, 2026
Merged

mindsocket merged 3 commits into
mainfrom
feat/112-json-parser

Conversation

@mindsocket

Copy link
Copy Markdown
Owner

Closes #112

Summary

  • Add a built-in sctx-json parse plugin (src/plugins/json/index.ts), enabled by default, that parses .json (single node object or array of node objects) and .jsonl (one node object per line with 1-based line numbers) files, with optional plugins.json.enabled and plugins.json.fieldMap.
  • Skip the space's own resolved schema file when it sits inside the space directory, and support incremental options.files refreshes for watch mode.
  • Update dispatchParse in src/read/read-space.ts so non-built-in parse plugins retain first-match-wins precedence while built-in filesystem parse plugins (sctx-markdown + sctx-json) run together and merge nodes, parse issues, excluded pages, and diagnostics before graph resolution.
  • Update markdownPlugin to return null for non-.md single-file spaces so single .json/.jsonl file spaces dispatch to sctx-json.
  • Document plugins.json in docs/config.md and add tests in tests/plugins/json/read-json.test.ts.

@claude

claude Bot commented Nov 30, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

Comment thread docs/config.md Outdated

## JSON plugin config

The built-in `json` plugin (`sctx-json`) runs alongside `sctx-markdown` by default and parses `.json` files (a single node object or an array of node objects) and `.jsonl` files (one node object per line) in the space. Set under `plugins.json` per space:

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking magic defaults like this are a slippery slope. We have a mechanism for specifying per plugin config (which also gives us a way to specify one or multiple parse plugins genetically) and i think we should use it. Including json automatically could have unintended side effects and reduce flexibility.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a json plugin when specified without configuration could look in the path as currently defined, but could also override how and where json is sought with optional parameters

Comment thread docs/config.md Outdated
With an empty config (`{}`), the plugin scans the space's `path` for `**/*.json` and `**/*.jsonl`. Optional fields:

- **`path`** — directory or single `.json`/`.jsonl` file to read instead of the space's `path` (relative paths resolve from the config root).
- **`include`** — glob patterns relative to `path` (default `["**/*.json", "**/*.jsonl"]`).

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yagni. Drop

Comment thread docs/config.md Outdated

- **`path`** — directory or single `.json`/`.jsonl` file to read instead of the space's `path` (relative paths resolve from the config root).
- **`include`** — glob patterns relative to `path` (default `["**/*.json", "**/*.jsonl"]`).
- **`fieldMap`** — maps source JSON property names to canonical schema field names.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yagni. Drop

Comment thread docs/config.md Outdated

## JSON plugin config

Enable the built-in `json` plugin (`sctx-json`) per space under `plugins.json` to parse `.json` files (a single node object or an array of node objects) and `.jsonl` files (one node object per line) alongside markdown:

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have it use json5 parser for .json and .json5

Comment thread src/plugins/json/index.ts Outdated

function isPluginConfigured(plugins: Record<string, Record<string, unknown>> | undefined): boolean {
if (!plugins) return false;
return BUILTIN_PLUGIN_NAMES.json in plugins || shortenPluginName(BUILTIN_PLUGIN_NAMES.json) in plugins;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a little odd to have at the plug-in level. Fine to leave it if there's a precedent and not a good workaround, but I wonder if built-in plug-in handling (eg prefixes) and detecting if enabled can be handled better outside of each built-in plug-in, so it's not importing the built-in plugins list.

Comment thread tests/plugins/json/read-json.test.ts Outdated
import { readSpace, refreshReadResult } from '../../../src/read/read-space';
import { createSpaceContext } from '../../../src/space-context';

const META =

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why hardcode this?

Comment thread src/read/read-space.ts Outdated
}

throw new Error(`No plugin handled space at: ${context.space.path}`);
// Built-in filesystem parse plugins (e.g. markdown + json) run together and merge their results.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is ok for right now, but it's sort of arbitrary and there's likely a more general approach that's more future proof. Constraints:
Preserve ease of config and use with markdown.
Assume it will be valuable to merge parse results from multiple configured plugins (don't assume first one wins for 3rd party)
Running parse calls (promises) in parallel, concurrency reasonably limited somehow, seems reasonable.

@mindsocket
mindsocket merged commit b48dae7 into main Nov 30, 2026
2 checks passed
@mindsocket
mindsocket deleted the feat/112-json-parser branch November 30, 2026 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support parsing of json

1 participant