Skip to content

Read refs in YAML values of the files that the config names - #1

Merged
mondaychen merged 4 commits into
mainfrom
yaml-values
Dec 4, 2026
Merged

mondaychen merged 4 commits into
mainfrom
yaml-values

Conversation

@PaoloRondot

@PaoloRondot PaoloRondot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

In a YAML file that the new yaml-values key of the config file names,
a value that is one ref counts as a ref. The value can be plain or
quoted, and it can be an item of a [...] or {...} collection:

spec: sync:/docs/auth.md#token-lifetime
- "iref:/docs/auth.md"
specs: [sync:/docs/auth.md, sync:/docs/api.md]

The yaml package reads these files, so a value can also be on the line
under its key, come after an anchor or a tag, or be an item of a list
that goes across lines. Comments count as before, in every file.

These values are not refs:

  • A ref inside a longer value, such as note: Tokens, sync:/docs/auth.md.
  • A value in a | or > block.
  • A plain value that goes on in the next line, or that continues the
    line before it.
  • A key, an alias, or a value with an escape.
  • A quoted value with no closing quote.

Changes

  • packages/core/src/values.ts finds the refs in YAML values with the
    yaml parser. findRefs takes values, and checkText sets it from
    the config, so the CLI and the extension both read the values.
  • In VS Code, completion works for a ref that starts a value. It reads
    the ref from the start of the value that the cursor is in.
  • encodeRefPath also encodes , as %2C, so a completion or a quick
    fix in a [...] list does not split the list.
  • yaml (ISC) has no dependencies of its own. esbuild bundles it into
    the CLI and the extension. Its license is in the new
    THIRD-PARTY-NOTICES, which the npm package and the .vsix ship next to
    LICENSE.
  • The README, the guide, the extension's README and DEVELOPMENT.md
    describe the key, the parser, and the cases that are not refs.

Tests

72 core and 21 CLI tests pass. Lint is clean. pnpm verify-comments
shows no disagreement. The VS Code package has no tests; a script
checked the completion cases against the built core.

🤖 Generated with Claude Code

PaoloRondot and others added 2 commits December 1, 2026 14:34
In a YAML file that the new `yaml-values` key of the config file names,
a value that is one ref counts as a ref, plain or quoted, on one line,
also as an item of a `[...]` or `{...}` collection:

    spec: sync:/docs/auth.md#token-lifetime
    - "iref:/docs/auth.md"
    specs: [sync:/docs/auth.md, sync:/docs/api.md]

A ref inside a longer value, in a `|` or `>` block, or in a plain value
that goes on in the next line is still not a ref. `,`, `[`, `{`, `]`
and `}` end a value only inside a collection, so the ref in
`note: Tokens, sync:/docs/auth.md` is not a value. Comments count as
before, in every file.

- The lexer can also return the string tokens of a file, so that a
  quoted value that holds only the ref is told from a longer string.
- `findRefs` takes `values`, and `checkText` sets it from the config,
  so the CLI and the extension both read the values.
- The README, the guide and the extension's README describe the key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… to read

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@mondaychen mondaychen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I found 5 problems in the YAML-value refs. I checked each YAML case against the built core. Problems 1 and 2 are important, and I suggest that you fix them before this PR merges. Problems 3 to 5 are minor and can be follow-up work.

4 (minor). VS Code gives no completion in a YAML value (packages/vscode/src/features.ts:270, a file that this PR does not change, so I cannot comment on the line).
Completion.provideCompletionItems stops if the cursor is not in a commentSpans span. Links and diagnostics use checkText, so they work in YAML values. But completion does not, and the VS Code README now says that a value can be a ref.
Example: the config has yaml-values = ["model/**"]. In model/a.yaml, type spec: sync:/do. No completion items come. The same text in a # comment gives completions.
Possible fix: when repo.readsYamlValues(source) is true for a YAML file, also accept a cursor in a value. For example, use findRefs with values = true, or add a helper that returns the value spans.

Comment thread packages/core/src/comments.ts Outdated
const before = text.slice(lineStart, start);
const after = text.slice(end, lineEnd);
if (flowAt(ref.start) !== undefined) return YAML_FLOW_VALUE.test(before) && YAML_FLOW_END.test(after);
if (!YAML_BLOCK_VALUE.test(before) || !YAML_BLOCK_END.test(after)) return false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 (important). A ref that is only the last line of a multi-line plain value is found.

The rule is that the ref must be the whole value. But here, interref reports a ref:

key: some text
  - sync:/a.md
next: x

YAML reads this as {key: "some text - sync:/a.md"}, so sync:/a.md is not the whole value. findRefs(..., true) still returns sync:/a.md. - some text followed by - sync:/b.md gives the same false ref.

The cause: YAML_BLOCK_VALUE tests only the text before the ref on its own line, and it accepts -. continues() checks the lines after the ref, but nothing checks the lines before it.

Possible fix: also look back. If an earlier plain scalar has not ended, and the line of the ref has more indentation than the key of that scalar, the line continues the scalar. Then reject the ref.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed by the parser. key: some text followed by - sync:/a.md is one value, so there is no
ref. Your two examples are now tests.

Comment thread packages/core/src/comments.ts Outdated
const lineEnd = newline < 0 ? text.length : newline;
const before = text.slice(lineStart, start);
const after = text.slice(end, lineEnd);
if (flowAt(ref.start) !== undefined) return YAML_FLOW_VALUE.test(before) && YAML_FLOW_END.test(after);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2 (important). Items of a flow collection that goes across lines are not found.

This is a common list style:

specs: [
  sync:/a.md,
  sync:/b.md
]

YAML reads this as two items, sync:/a.md and sync:/b.md. But findRefs(..., true) returns no refs, so a broken target in this list is not reported. The README and SKILL.md say that an item of a [...] or {...} collection counts.

The cause: YAML_FLOW_VALUE needs [, {, , or key: before the item on the same line. YAML_FLOW_END needs ,, ], } or a comment after the item on the same line. So an item at the start of a line fails, and the last item before a line break also fails.

Possible fix: in a flow collection, also accept an item that has only indentation before it on its line. Also accept the end of the line when the next line that is not blank starts with ,, ] or }.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed by the parser. specs: [, sync:/a.md,, sync:/b.md, ] gives both refs. This is a
test now.

Comment thread packages/core/src/comments.ts Outdated
* Matches the text before a value in block context: one or more `- ` at the start of the line, or
* `key: `.
*/
const YAML_BLOCK_VALUE = /(?:^[ \t]*(?:-[ \t]+)+|[^\s:]:[ \t]+)$/u;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

3 (minor). Some plain values on one line are not found.

YAML_BLOCK_VALUE needs key: or - directly before the ref, on the same line. So these two values are not found, although YAML reads each one as a whole value:

  • A value on the line under its key: key: and then sync:/c.md on the next line. YAML gives {key: "sync:/c.md"}.
  • A value after an anchor or a tag: key: &x sync:/f.md or key: !!str sync:/f.md.

Possible fix: accept a value that is alone on an indented line under a key: that has no value. Also let &anchor and !tag come before the value. If you prefer to keep this limit, write it in the README.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed by the parser: key: followed by sync:/c.md, key: &x sync:/f.md and
key: !!str sync:/f.md are refs. An alias (*x) is not counted a second time. The README lists
these cases.

Comment thread packages/core/src/comments.ts Outdated
if (depth === 0) flows.push({ start, end: at + 1 });
}
}
if (depth > 0) flows.push({ start, end: text.length });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

5 (minor). One [ or { without a close makes the rest of the file a flow collection.

When depth > 0 at the end of the text, this line adds a span to text.length. After that, every block value is tested with the flow rules, and every comma becomes a space.

Example:

title: [draft
k: sync:/e.md

This can come from a typo or from a template line. findRefs(..., true) returns no refs. So the valid value k: sync:/e.md, and all later refs in the file, are not checked.

Possible fix: end a flow collection that has no close at the first later line that does not have more indentation than the line where the collection started. Or skip a collection that has no close.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed by the parser. The parser reports an error, but it still reads the later values, so
k: sync:/e.md after title: [draft is found. This is a test now.

@mondaychen

Copy link
Copy Markdown
Contributor

If we do want this, I recommend using a real YAML parser in place of the regex rules. The yaml (https://www.npmjs.com/package/yaml) package is a good choice: it is well maintained and has no dependencies of its own.

Why the current approach has these bugs

To know whether a ref is the whole value, interref must know where each YAML value starts and ends. The PR finds this with regexes that look at one line at a time. But YAML values can go across lines:

  • A plain value can continue on the next lines.
  • A [...] list can go across lines.
  • A value can be on the line under its key.
  • A value can have an anchor or a tag before it.

The 5 problems in the review all come from this gap. A fix for each one adds more rules, and other YAML cases will still be missing. The
existing comment lexer is different. It only has to tell a comment from a string, so it does not need to know the structure of the file.
To find whole values, interref must know that structure, and only a parser gives it.

…in VS Code

The review of the YAML values asked for a real YAML parser in place of
the regex rules. These rules look at one line at a time, but a YAML
value can go across lines, and the 5 problems that the review found all
come from this gap. `packages/core/src/values.ts` now reads a file that
`yaml-values` names with the `yaml` package. A plain or quoted scalar
that is not a key, and whose text is exactly one ref, is a ref. The
lexer still finds the comments, as before, and no longer returns the
string tokens.

- A plain value that continues the line before it, as `  - sync:/a.md`
  under `key: some text`, is not a ref.
- A `[...]` list that goes across lines gives each of its refs.
- A value on the line under its key, or after an anchor or a tag
  (`key: &x sync:/a.md`, `key: !!str sync:/a.md`), is a ref. An alias
  does not count the ref a second time.
- A `[` that is not closed no longer hides the later values of the file.
- In VS Code, completion also works for a ref that starts a value. A
  key counts too, because a ref that is still being typed, such as
  `- sync:`, reads as a key.

`yaml` (ISC) has no dependencies of its own. esbuild bundles it into
the CLI and the extension. `yaml` is CommonJS, so the ES module bundle
of the CLI makes a `require` for it. Its license is in the new
THIRD-PARTY-NOTICES, which the npm package and the .vsix ship next to
LICENSE. The README, the guide, the extension's README and
DEVELOPMENT.md describe the parser and the cases that are not refs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PaoloRondot

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Both branches are updated: yaml-values keeps both of its commits, yours included, with one new commit on top; stamped-refs is one commit on the new yaml-values.

Use a real YAML parser

Done. The regex rules are gone. packages/core/src/values.ts now reads the file with the yaml
package and keeps a plain or quoted scalar that is not a key, when its text is exactly one ref.
The lexer still finds the comments, as before. esbuild bundles yaml into the CLI and the
extension. Because yaml is CommonJS and calls require("process"), the ESM CLI bundle gets a
createRequire banner.

Your commit that rewrote the comments and docs stays as it is, and the fixes are a new commit after
it. The docs keep your wording. Only the comments on the regex code went away, together with that
code.

yaml is ISC, which asks for its copyright and permission notice in every copy. The new
THIRD-PARTY-NOTICES at the repo root holds yaml's LICENSE text. The CLI's prepack and the
extension's package script copy it next to LICENSE, and the CLI's files and the extension's
.vscodeignore let it in, so the npm package and the .vsix both ship it. DEVELOPMENT.md says so.

Item 4: completion in a YAML value

Fixed. In a file that yaml-values names, completion now also works for a ref that starts a
plain or quoted scalar. Keys count too, because a ref that you are still typing, such as
- sync:, reads as a key. The README and the extension's README mention it.

- A completion or a quick fix that puts a path into a `[...]` list no
  longer breaks the list when the file name has a `,`. `encodeRefPath`
  now writes `,` as `%2C`. This also keeps a `,` at the end of a file
  name, which the scanner dropped as punctuation.
- A quoted value with no closing quote at the end of the file is not a
  ref. Before, the parser dropped the last character of the path, so
  `a: 'sync:/docs/auth.md` gave the ref `sync:/docs/auth.m`.
- Completion in a YAML value reads the ref from the start of the value
  that the cursor is in. Thus `[sync:/a.md,sync:/]` now gives paths for
  the second item, and `key: (sync:/` gives no paths, since the value
  that it makes is not a ref. `valueStartAt` replaces `valueSpans`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mondaychen
mondaychen merged commit 9b500cd into main Dec 4, 2026
1 check passed
@mondaychen
mondaychen deleted the yaml-values branch December 4, 2026 15:17
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.

2 participants