Skip to content

fix(frontmatter): preserve skill metadata when assigning dashboard targets - #973

Merged
runkids merged 3 commits into
runkids:mainfrom
salmonumbrella:fix/okf-preserve-target-metadata
Nov 23, 2026
Merged

runkids merged 3 commits into
runkids:mainfrom
salmonumbrella:fix/okf-preserve-target-metadata

Conversation

@salmonumbrella

@salmonumbrella salmonumbrella commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

This PR's own commits: b271e5f..30f72b2

Type

  • Bug fix
  • Small improvement (docs, typo, minor refactor)
  • Feature proposal (proposals/ only — see CONTRIBUTING.md)
  • Approved feature or large change (the linked issue has the approved label)

What changed

Dashboard target assignment no longer round-trips a closed skill or agent YAML header. It uses the shared delimiter walker, key spans and YAML node positions. The writer verifies the body and decoded values before it writes. CRLF, BOM, key order, unrelated metadata spellings and adjacent comments are preserved in supported layouts.

Clearing absent targets in a recognized header leaves the file untouched, including when metadata is an alias, empty or non-mapping. Clearing the last explicit target removes its otherwise empty metadata mapping. Setting targets on non-mapping metadata replaces it. A skill edit also removes the legacy top-level targets field; an agent edit works on the top-level field.

A requested edit is refused when it cannot be shown safe. Examples include aliased metadata with targets that must change, fully indented block roots, mixed-key metadata that must be edited, and flow target values with source spellings the editor cannot bound exactly. Comments on the entry being replaced or removed may change. Files with no recognized closed header still take the legacy writer path.

Skill and agent PATCH return 422 with an actionable error code for file refusals; ordinary I/O failures remain server errors. Folder operations warn with affected names and real update/failure counts, including when no edits succeed. Older batch clients still receive the existing string errors. The dashboard translates file guidance in all 11 locales.

Why

Assigning a dashboard target could silently change a skill. On a CRLF file, readers lost the name, description and all metadata. On LF files, the full-map round trip turned 012 into octal 10, gave date-only values a time, and could give an invalid expiry a valid UTC offset.

Usage

No usage change.

Checklist

  • I've read CONTRIBUTING.md, including its AI-assisted contributions section
  • I've reviewed every line of the diff and can explain it (pending author confirmation)
  • Tests included and passing (make check) — for code changes
  • No unrelated changes in the diff
  • Scope is focused — one concern per PR

Testing

  • make check passed in the devcontainer on the exact candidate tree, including Go unit/integration and all 159 Herdr checks.
  • Dashboard: all 1,005 tests passed, as did typecheck/build, format, lint and typed lint (warnings, no errors).
  • With a synthetic source in Chrome against Air/Vite and the real API, verified single refusal plus mixed/all-refused folders in English and Traditional Chinese across Clean/Playful and light/dark, at 1152×820.
  • GitHub CI was in progress at the time of this update. No mobile visual QA.

Linked Issue

Builds on merged #970: #970
Refs #894
Refs #449

@salmonumbrella

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T14:38:08.257137Z 5d66a71 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 5d66a714e6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@salmonumbrella
salmonumbrella marked this pull request as ready for review November 20, 2026 14:33
@runkids

runkids commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thanks @salmonumbrella. The CRLF fix alone is worth having: today a dashboard target on a CRLF skill buries the whole old header. We also found no corruption: every output we tried (LF, CRLF, BOM, flow and block metadata, aliases, U+2028/U+0085, comments) decoded correctly with the body intact, and the unsafe ones were refused.

Could you change a few things before we merge?

  1. Show a refusal to the dashboard user. The refusals are new, and both paths hide or mislabel them:
    • Folder batch: /resources/batch/targets returns 200 with errors, but setFolderTargets.onSuccess in ui/src/pages/ResourcesPage.tsx never reads it. A folder whose skills are all refused shows a success toast ("0 skills updated"). Please show the errors (a warning toast with the names is enough).
    • Single PATCH (skill and agent, handler_skills_batch.go): a refusal returns 500 with "failed to update skill: cannot safely edit target frontmatter…". It is the file, not the server, so please return a 4xx with a message that says what to fix, like fix(list): preserve flow-style skill metadata when toggling manual invocation #970's delimiter message.
  2. Reuse the helpers instead of adding parallel ones. frontmatter_write.go grows by about 500 lines, much of it copies of what is already there:
  3. Don't refuse a no-op. With metadata: *anchor, clearing targets is refused even when there are none to clear (the alias check at the top of rewriteTargetsUnchecked fires for any values). Clearing absent targets should leave the file alone.
  4. Description accuracy. "Behavior is unchanged… removing metadata when its last target is cleared" isn't quite true: clearing on metadata: {} or a non-mapping metadata used to drop it and now keeps it. Either keep the old behaviour or say so. Please also list the new refusals (an aliased metadata, a fully indented root mapping, flow values the scanner can't place) so users of those files know.
  5. Tests. Handler tests cover translation (status and response fields); the writer rules belong once in internal/utils. Keep the CRLF handler test as wiring proof, drop the Unicode-separator and alias handler duplicates, and add one for the refusal status/response from item 1. In frontmatter_write_test.go (+489 lines), the three Unicode-separator tests and the flow boundary/variant tests can each become one table.
  6. Checklist: please tick "reviewed every line" yourself.

…sals

Use shared delimiter, key-span and offset handling to splice only target entries and verify decoded metadata and body before writing. Preserve no-op clears, classify uneditable files separately from I/O, and report named, localized folder outcomes without counting unchanged files.
@salmonumbrella
salmonumbrella force-pushed the fix/okf-preserve-target-metadata branch from 5d66a71 to 30f72b2 Compare November 21, 2026 17:10
@salmonumbrella

Copy link
Copy Markdown
Contributor Author

@runkids Could you re-review 30f72b2? It’s rebased onto main after #970 and reuses the shared delimiter, key-span, and offset helpers. Unsafe skill/agent edits now return 422 with actionable guidance, absent targets clear without a write, and folder warnings list the affected skills with accurate counts. The writer is still about +270 net lines, above the ~200 target.

Locally, make check and all 1,005 dashboard tests passed. I also verified single refusals and mixed/all-refused folders in Chrome in English and Traditional Chinese. GitHub CI is still running.

Review follow-up for the dashboard target writer.

A request that changes nothing rewrote the file anyway: setting a target
to its current value reformatted the list, and clearing targets in a
file without a header added an empty one. Both now return the file as it
is, so a folder batch reports those files as unchanged.

Metadata with non-string keys refused every edit, including removing a
legacy top-level targets key that sits outside it. Only edits inside
metadata are refused now.

A refusal gave the remedy but not the cause. The error now ends with the
reason, and still matches ErrTargetFrontmatter.

The batch endpoint logged "ok" when files failed, which hid failures in
the operation log. It now logs "partial" or "error" with the failure
count and the first error.

The error code becomes target_frontmatter, in line with the other codes.
Dashboard toasts are built from translated templates instead of joined
strings, so word order and punctuation follow each locale, and the docs
list the layouts the dashboard refuses.
@runkids
runkids merged commit 115b50a into runkids:main Nov 23, 2026
10 checks passed
@runkids

runkids commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Thanks @salmonumbrella, merged. The re-review of 30f72b2 found no corruption: the line editors behave the same as on main, and every target edit I tried either kept the rest of the file as written or was refused.

Before merging I pushed one follow-up commit to your branch, 2101b9e, plus a merge of main. What it changes:

  • No-op requests leave the file alone. Setting a target to the value it already has no longer reformats the list, and clearing targets in a file without a header no longer adds an empty one. A folder batch now counts those files as unchanged.
  • Non-string metadata keys only block edits inside metadata. A legacy top-level targets: beside them can still be removed.
  • Refusals say why. The error keeps your remedy text and ends with the reason, and still matches ErrTargetFrontmatter.
  • The error code is now target_frontmatter (was target.frontmatter), in line with the other codes.
  • The batch operation log records partial or error with the failure count when files fail. It logged ok before.
  • Dashboard toasts are built from translated templates in all 11 locales, and filtering.md and its translations list the layouts the dashboard refuses.

One sentence in the PR description no longer holds: a file with no recognized closed header still takes the legacy writer path when you set targets, but clearing targets it does not have is now a no-op.

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