Skip to content

feat(sync): add the adapter core and the Markdown adapter - #988

Merged
ctawiah merged 1 commit into
mainfrom
ctawiah/sync-reference-core-3bbf
Nov 5, 2026
Merged

ctawiah merged 1 commit into
mainfrom
ctawiah/sync-reference-core-3bbf

Conversation

@ctawiah

@ctawiah ctawiah commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Context

Every source format needs the same contract. The shared core owns path resolution, projection building, and edit planning, so an adapter cannot get them wrong.

What changes

  • Add the adapter contract. An adapter turns bytes into a tree of logical nodes with byte spans and encoders. The core resolves select and map paths, builds the typed projection, and plans exact edits.
  • Add the select and map path grammar, the registry, and the node constructors.
  • Add the YAML tree with exact scalar spans, which the YAML adapter and Markdown front matter share.
  • Add the Markdown adapter. One format exposes the front matter, the body, the heading sections, and the LaunchDarkly marker regions. It serves prompt files, AGENTS.md, CLAUDE.md, Cursor rules, and Copilot instructions.
  • Add the Agent Skill adapter.

Design notes

  • Adapters receive bytes only. They never read files, run code, or use the network.
  • Each format is its own package. A format cannot import another format.
  • Parse is mode-agnostic. The planner converts the prompt to the mode of the config.

Review focus

  • Can a new format be added with one package and one registration?
  • Do edits keep every byte outside the accepted spans?

Verification

  • make build
  • go test ./...
  • golangci-lint run ./...

Related changes

  1. refactor(sync): remove Phase 1 source references #1005: Phase 1 reference removal
  2. feat(sync): add projection and problem core #987: projection and problem core
  3. This PR: adapter core and Markdown
  4. feat(sync): add the structured document adapters #989: structured adapters
  5. feat(sync): add the Python adapter #991: Python adapter
  6. feat(sync): add the TypeScript and JavaScript adapters #992: TypeScript and JavaScript adapters
  7. feat(sync): add source descriptor storage #993: descriptor storage
  8. feat(sync): compile and publish repository sources #994: compile and publish
  9. feat(sync): detach descriptor-backed sources #1003: descriptor detach
  10. feat(sync): prepare repository source links #997: link preparation
  11. feat(sync): integrate repository sources with planning and link #995: planning and link
  12. feat(sync): add the link commands #998: link commands

🤖 Generated with Claude Code


Note

Overview
Introduces internal/sync/adapter, the shared layer between the sync engine and per-format parsers: registered Adapter implementations turn a SourceBundle into a logical Node tree with byte spans and encoders, while the core owns select/map path parsing and resolution, descriptor normalization, typed projections (variation, tool, skill), indexed-selection fingerprints, and UpdateSource planning of **TextEdit**s with read-only fallbacks when structure or capabilities block writes.

Adds yamltree for YAML→nodes with exact scalar spans (shared by front matter and future YAML support), marking structural YAML, aliases, merge keys, and non-exact scalars read-only where appropriate.

Adds markdown and agent-skill formats: documents expose frontmatter, body, sections, and LaunchDarkly marker regions, with fenced/indented-code-aware parsing; markdown defaults variation prompts to body, agent-skill validates SKILL.md front matter and maps description + body for skills. Includes testdata/golden fixtures for common agent instruction file shapes.

Reviewed by Cursor Bugbot for commit 7abc71a. Bugbot is set up for automated code reviews on this repo. Configure here.

@ctawiah
ctawiah added this pull request to stack #1000 October 30, 2026 20:15
@ctawiah
ctawiah force-pushed the ctawiah/sync-reference-core-3bbf branch from 31e85d7 to 6cd3884 Compare October 31, 2026 00:05
@ctawiah
ctawiah force-pushed the ctawiah/sync-reference-core-3bbf branch from 6cd3884 to f17e19b Compare November 2, 2026 02:26
@ctawiah
ctawiah force-pushed the ctawiah/sync-reference-core-3bbf branch from f17e19b to 506ef88 Compare November 3, 2026 00:29
@ctawiah ctawiah changed the title feat(sync): add reference registry and Markdown adapters feat(sync): add the adapter core and the Markdown adapter Nov 3, 2026
@ctawiah
ctawiah removed this pull request from stack #1000 November 3, 2026 00:32
@ctawiah
ctawiah added this pull request to stack #1004 November 3, 2026 00:34
@ctawiah
ctawiah removed this pull request from stack #1004 November 3, 2026 00:53
@ctawiah
ctawiah added this pull request to stack #1006 November 3, 2026 00:53
@ctawiah
ctawiah force-pushed the ctawiah/sync-reference-core-3bbf branch from 506ef88 to 32c01cd Compare November 4, 2026 15:29
@ctawiah
ctawiah marked this pull request as ready for review November 4, 2026 15:30
@ctawiah
ctawiah requested a review from a team as a code owner November 4, 2026 15:30
@ctawiah
ctawiah requested review from nkester-ld and wchieng and removed request for a team November 4, 2026 15:30

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@ctawiah
ctawiah force-pushed the ctawiah/sync-reference-core-3bbf branch from 32c01cd to 595a360 Compare November 4, 2026 19:25

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@ctawiah
ctawiah force-pushed the ctawiah/sync-reference-core-3bbf branch from 595a360 to 21dc118 Compare November 4, 2026 19:46

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This doesn't seem to be used in this PR. we could move it to it's first reference #992 - or keep it. It seems reasonable to have this in place for later testing.

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.

Good call. The package now lands in #992 with the conformance tests, which are its only user. I updated both descriptions.

"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

IMO, a nit that claude helped me find, but does crash the yaml reader given valid yaml:

yamlValueNode sends every !!int and !!float through strconv.ParseFloat (yamltree.go:252). That function rejects some valid YAML numbers, such as 0x10, 0o17, .inf, -.inf and .nan. All my test numbers cause it to crash file read with:
strconv.ParseFloat: parsing "0x10": invalid syntax (and the same error for the others).`

This is the test I ran to confirm the issue. It needs "github.com/launchdarkly/ldcli/internal/sync/adapter" in the imports):

func buildDocument(t *testing.T, source string) (*adapter.Node, error) {
        t.Helper()
        var document yaml.Node
        require.NoError(t, yaml.Unmarshal([]byte(source), &document))
        return Build([]byte(source), document.Content[0], 0, false)
}

func TestValidYAMLNumbersDoNotFailTheDocument(t *testing.T) {
        for _, value := range []string{"0x10", "0o17", ".inf", "-.inf", ".nan"} {
                t.Run(value, func(t *testing.T) {
                        root, err := buildDocument(t, "limit: "+value+"\nname: kept\n")
                        require.NoError(t, err)
                        assert.Equal(t, "kept", root.Fields["name"].Value)
                })
        }
}

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.

Thanks for the test. Hex and octal now decode through the YAML library, so they are plain numbers. Infinity and NaN decode too, but they have no JSON form, so the builder keeps them as read-only text instead of a number that would fail later in a fingerprint. Your test is in yamltree_test.go as TestValidYAMLNumbersDoNotFailTheDocument, with the read-only check added.

@ctawiah
ctawiah force-pushed the ctawiah/sync-reference-core-3bbf branch from 21dc118 to dc5f291 Compare November 4, 2026 21:53

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Base automatically changed from ctawiah/sync-projection-core-3bbf to main November 4, 2026 22:26
@ctawiah
ctawiah force-pushed the ctawiah/sync-reference-core-3bbf branch 2 times, most recently from c783601 to bb5ff9c Compare November 4, 2026 22:52

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@ctawiah
ctawiah force-pushed the ctawiah/sync-reference-core-3bbf branch from bb5ff9c to d501e74 Compare November 4, 2026 23:57

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d501e74. Configure here.

Comment thread internal/sync/adapter/parse.go Resolved
Add the adapter contract: a format turns source bytes into a tree of logical nodes, and the core resolves select and map paths, builds projections, and plans exact edits. Add the YAML tree, the Markdown adapter with front matter, sections, and markers, and the Agent Skill adapter.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@ctawiah
ctawiah force-pushed the ctawiah/sync-reference-core-3bbf branch from d501e74 to 7abc71a Compare November 5, 2026 00:47
@ctawiah
ctawiah merged commit 3b2d454 into main Nov 5, 2026
10 checks passed
@ctawiah
ctawiah deleted the ctawiah/sync-reference-core-3bbf branch November 5, 2026 01:01
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