Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions .github/skills/article-metadata-update/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
---
name: article-metadata-update
description: Finds articles that meet user-defined criteria, presents evidence for approval, and applies narrowly scoped frontmatter updates. Use for bulk article metadata changes with a discover-then-approve workflow.
argument-hint: 'Provide the article criteria, exclusions, search scope, metadata key, and desired string value; or identify a previously approved manifest and groups or paths'
---

# Update article metadata

Use this skill to select articles by their actual scope and update one frontmatter key. Keep eligibility decisions separate from the script that applies the edits.

## Required inputs

Confirm the following details before discovery:

- The selection criteria and exclusions.
- The repository-relative search directories.
- The metadata key and desired string value.

Reuse details that the user already supplied. Don't assume that a version number, release cutoff, metadata key, or value from a previous task applies to a new task.

## Discover mode

Discovery doesn't authorize article edits.

1. Read the applicable repository instructions and inspect existing workspace changes. Keep the user's branch, commits, and unrelated edits intact.
1. Use fast, scoped searches to collect candidates from paths, titles, frontmatter, and relevant article text. Read enough context to establish each candidate's scope. Don't repeatedly scan every line of every article.
1. Classify each entry as `candidate`, `review`, or `excluded`. Record a reason and evidence with a repository-relative path, line number, and short quotation.
1. Verify time-sensitive eligibility facts against current authoritative sources when the criteria depend on support status or release dates.
1. Create a JSON manifest in the session artifacts directory, outside the repository. Use the schema below. Give groups stable, descriptive IDs.
1. Run the script in `Preview` mode. The script records current values, content hashes, expected result hashes, and completion status. It also writes a CSV beside the manifest.
1. Present the grouped list, reasons, uncertainties, exclusions, and already-correct counts. Attach the report when the list is too large for chat. **Stop and wait for explicit approval.**

### Eligibility rules

Apply the user's filter, not a hard-coded documentation retirement policy.

- A text match or old SDK example doesn't establish that an article is obsolete.
- A feature introduced in an earlier release can remain relevant to current releases.
- Historical release summaries and breaking-change records can qualify as stable, release-specific content even when their features or migration advice remain useful.
- A diagnostic or feature that the tools no longer produce differs from an API that merely became obsolete.
- Don't equate versions of .NET, .NET Framework, language compilers, or independent tools.
- Treat mixed-version articles and uncertain scope as `review` unless the user's criteria resolve the uncertainty.
- Exclude shared includes and general reference pages unless the user explicitly includes them.

### Manifest schema

The initial manifest contains selection decisions, not approval flags:

```json
{
"schemaVersion": 1,
"metadata": {
"key": "ms.update-cycle",
"value": "3650-days"
},
"articles": [
{
"path": "docs\\core\\compatibility\\9.0.md",
"group": "breaking-change-indexes",
"classification": "candidate",
"reason": "The introduction scopes the list to migration to .NET 9.",
"evidence": "docs\\core\\compatibility\\9.0.md:10: If you're migrating an app to .NET 9..."
}
]
}
```

The example illustrates the format, not a default filter or permission to edit that file. Include `review` and `excluded` entries in the manifest so the report explains the selection boundaries.

Run commands from the repository root, or pass `-RepositoryRoot` explicitly:

```powershell
.\.github\skills\article-metadata-update\scripts\update-frontmatter.ps1 `
-Mode Preview `
-ManifestPath "<session-artifacts>\article-metadata-manifest.json"
```

Don't manually edit the snapshot hashes, preview metadata, or completion status. After the target key, value, or article contents change, run a new preview and obtain approval for the revised proposal.

## Apply mode

The user can approve the full candidate list, specific groups, or individual paths. Translate that approval into explicit arguments; never infer approval from the manifest's existence.

1. Identify exactly which groups or paths the user approved. A group selects only `candidate` entries. A `review` entry requires explicit path approval; the script never selects an `excluded` entry.
1. Run `Apply` against the previewed manifest. Don't rediscover a broader set of files or use wildcard approvals.
1. If the script reports stale content, stop. Reinspect the affected articles, create a fresh preview, and obtain approval for any materially changed proposal. Don't replace hashes to bypass the check.
1. Verify the diff against the approved scope. Confirm that only the target frontmatter field changed and that article text, other metadata, encoding, and line endings remain intact.
1. Report changed, already-correct, and remaining counts. Leave edits local and uncommitted unless the user requests a Git operation.

```powershell
.\.github\skills\article-metadata-update\scripts\update-frontmatter.ps1 `
-Mode Apply `
-ManifestPath "<session-artifacts>\article-metadata-manifest.json" `
-ApprovedGroups "breaking-change-indexes"
```

```powershell
.\.github\skills\article-metadata-update\scripts\update-frontmatter.ps1 `
-Mode Apply `
-ManifestPath "<session-artifacts>\article-metadata-manifest.json" `
-ApprovedPaths "docs\core\compatibility\9.0.md"
```

## Script contract

Location: `.\scripts\update-frontmatter.ps1`. Requires PowerShell 7.2 or later; no additional packages.

| Parameter | Purpose |
| --- | --- |
| `Mode` | `Preview` records the proposal without article edits. `Apply` edits explicitly selected entries. |
| `ManifestPath` | Identifies the JSON manifest. The derived CSV uses the same basename. Keep both outside the repository. |
| `RepositoryRoot` | Selects the article repository root. Defaults to the current directory. Apply must use the root recorded by preview. |
| `ApprovedGroups` | Selects named groups of `candidate` entries in Apply mode. |
| `ApprovedPaths` | Selects individual `candidate` or `review` entries in Apply mode. |

The script supports unquoted top-level keys and single-line printable string values, including plain strings, YAML single-quoted strings, and JSON-compatible double-quoted strings. It quotes new values when plain YAML could change their meaning. It rejects multiline or structured target values, duplicate top-level keys, merge keys, quoted frontmatter keys, unsupported encodings, and linked paths rather than guess.

UTF-8 files retain their BOM, if present, and existing line endings. Existing inline comments on the target field remain intact. New fields appear after `ms.date`, or immediately before the closing frontmatter delimiter when `ms.date` is absent. The script doesn't update `ms.date`, `ai-usage`, or any other field unless that field is the explicitly requested target.

All selected files pass stale-content checks before any article write. The script also checks each file immediately before its write and verifies the resulting bytes. If a later operation fails, earlier edits can remain; inspect the surfaced error and manifest rather than assume an atomic batch. Repeating an approved apply verifies and skips completed results.

For CRLF files, use a command-scoped whitespace check that recognizes carriage returns without changing Git configuration:

```powershell
git -c core.whitespace=blank-at-eol,blank-at-eof,space-before-tab,cr-at-eol diff --check
```

## Regression checks

Run the standalone fixture checks after you change the script:

```powershell
.\.github\skills\article-metadata-update\scripts\update-frontmatter.Tests.ps1
```

The checks use temporary articles and manifests, require no test framework, and remove their fixtures when they finish. They cover approval boundaries, stale-file preflight, already-correct values, ambiguous frontmatter, safe YAML string values, comments, encoding, and line endings.
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
#Requires -Version 7.2
$ErrorActionPreference = 'Stop'
$script = Join-Path $PSScriptRoot 'update-frontmatter.ps1'
$testRoot = Join-Path ([IO.Path]::GetTempPath()) ('article-metadata-fixtures-' + [guid]::NewGuid().ToString('N'))
$fixtureRoot = Join-Path $testRoot 'articles'
$utf8 = [Text.UTF8Encoding]::new($false, $true)
[void](New-Item -ItemType Directory -Path $fixtureRoot)
$assertions = 0

function Assert {
param([bool]$Condition, [string]$Message)
if (!$Condition) { throw $Message }
$script:assertions++
}
function Expect-Error {
param([scriptblock]$Action, [string]$Pattern)
try { & $Action }
catch {
Assert ($_.Exception.Message -like "*$Pattern*") "Unexpected error: $_"
return
}
throw "Expected an error containing: $Pattern"
}
function Write-Fixture {
param([string]$Name, [string]$Text, [bool]$Bom = $false)
[byte[]]$bytes = $utf8.GetBytes($Text)
if ($Bom) { $bytes = [byte[]](@(0xEF, 0xBB, 0xBF) + $bytes) }
[IO.File]::WriteAllBytes((Join-Path $fixtureRoot $Name), $bytes)
}
function Snapshot {
param([string]$Name)
[Convert]::ToBase64String([IO.File]::ReadAllBytes((Join-Path $fixtureRoot $Name)))
}
function Make-Manifest {
param([string]$Name, [object[]]$Entries, [string]$Value = '3650-days', [string]$Key = 'ms.update-cycle')
$path = Join-Path $testRoot "$Name.json"
$rows = foreach ($entry in $Entries) {
if ($entry -is [string]) { $entry = @{ path = $entry; classification = 'candidate' } }
@{
path = $entry.path
group = 'batch'
classification = $entry.classification
reason = 'Fixture scope'
evidence = "$($entry.path):1: Fixture evidence"
}
}
@{
schemaVersion = 1
metadata = @{ key = $Key; value = $Value }
articles = @($rows)
} | ConvertTo-Json -Depth 10 | Set-Content -LiteralPath $path -Encoding utf8
$path
}
function Preview {
param([string]$Manifest)
$null = & $script -Mode Preview -RepositoryRoot $fixtureRoot -ManifestPath $Manifest
}
function Apply {
param([string]$Manifest)
& $script -Mode Apply -RepositoryRoot $fixtureRoot -ManifestPath $Manifest -ApprovedGroups batch
}

try {
$tokens = $null
$errors = $null
[void][Management.Automation.Language.Parser]::ParseFile($script, [ref]$tokens, [ref]$errors)
Assert ($errors.Count -eq 0) "Script parse errors: $errors"

$body = "# Fixture`n`nms.update-cycle: unchanged body example`n"
$base = "---`ntitle: Fixture`nms.date: 01/01/2020`n---`n$body"
Write-Fixture 'lf.md' $base
Write-Fixture 'bom.md' ($base.Replace("`n", "`r`n")) $true
Write-Fixture 'old.md' ($base.Replace("ms.date: 01/01/2020`n", "ms.date: 01/01/2020`nms.update-cycle: '30-days' # preserve comment`n"))
Write-Fixture 'plain.md' ($base.Replace("ms.date: 01/01/2020`n", "ms.date: 01/01/2020`nms.update-cycle: 3650-days`n"))
Write-Fixture 'single.md' ($base.Replace("ms.date: 01/01/2020`n", "ms.date: 01/01/2020`nms.update-cycle: '3650-days' # retain quoting`n"))
Write-Fixture 'double.md' ($base.Replace("ms.date: 01/01/2020`n", "ms.date: 01/01/2020`nms.update-cycle: `"3650-days`"`n"))
Write-Fixture 'review.md' $base
Write-Fixture 'excluded.md' $base
$entries = @('lf.md', 'bom.md', 'old.md', 'plain.md', 'single.md', 'double.md',
@{ path = 'review.md'; classification = 'review' }, @{ path = 'excluded.md'; classification = 'excluded' })
$manifest = Make-Manifest main $entries
$before = @{}
foreach ($name in 'lf.md', 'bom.md', 'old.md', 'plain.md', 'single.md', 'double.md', 'review.md', 'excluded.md') {
$before[$name] = Snapshot $name
}
Preview $manifest
foreach ($name in $before.Keys) { Assert ((Snapshot $name) -ceq $before[$name]) "Preview edited $name" }
Assert (Test-Path ([IO.Path]::ChangeExtension($manifest, '.csv'))) 'Preview omitted the report'
Expect-Error { & $script -Mode Apply -RepositoryRoot $fixtureRoot -ManifestPath $manifest } 'explicit Approved'
$result = Apply $manifest
Assert ($result.Changed -eq 3 -and $result.Selected -eq 6 -and $result.AlreadyAtDesiredResult -eq 3) 'Incorrect group-selection counts'
$expected = $base.Replace("ms.date: 01/01/2020`n", "ms.date: 01/01/2020`nms.update-cycle: 3650-days`n")
Assert ([IO.File]::ReadAllText((Join-Path $fixtureRoot 'lf.md')) -ceq $expected) 'LF content changed outside the field'
[byte[]]$expectedBom = @(0xEF, 0xBB, 0xBF) + $utf8.GetBytes($expected.Replace("`n", "`r`n"))
Assert ((Snapshot 'bom.md') -ceq [Convert]::ToBase64String($expectedBom)) 'BOM or CRLF changed'
Assert ([IO.File]::ReadAllText((Join-Path $fixtureRoot 'old.md')) -ceq $expected.Replace("ms.update-cycle: 3650-days`n", "ms.update-cycle: 3650-days # preserve comment`n")) 'Inline comment was lost'
foreach ($name in 'plain.md', 'single.md', 'double.md', 'review.md', 'excluded.md') {
Assert ((Snapshot $name) -ceq $before[$name]) "Unselected or correct article changed: $name"
}
$result = Apply $manifest
Assert ($result.Changed -eq 0 -and $result.AlreadyAtDesiredResult -eq 6) 'Repeated apply was not idempotent'
$result = & $script -Mode Apply -RepositoryRoot $fixtureRoot -ManifestPath $manifest -ApprovedPaths review.md
Assert ($result.Changed -eq 1) 'Explicit review approval did not apply'
Expect-Error { & $script -Mode Apply -RepositoryRoot $fixtureRoot -ManifestPath $manifest -ApprovedPaths excluded.md } 'Excluded article'
Expect-Error { & $script -Mode Apply -RepositoryRoot $fixtureRoot -ManifestPath $manifest -ApprovedGroups missing } 'no candidate entries'
$saved = Get-Content $manifest -Raw | ConvertFrom-Json
Assert (@($saved.articles | Where-Object status -eq applied).Count -eq 4) 'Manifest did not record completion'

Write-Fixture 'first.md' $base
Write-Fixture 'stale.md' $base
$manifest = Make-Manifest stale @('first.md', 'stale.md')
Preview $manifest
$firstBefore = Snapshot 'first.md'
Write-Fixture 'stale.md' ($base + 'External edit')
Expect-Error { Apply $manifest } 'Stale article'
Assert ((Snapshot 'first.md') -ceq $firstBefore) 'Stale batch partly wrote articles'
$data = Get-Content $manifest -Raw | ConvertFrom-Json -AsHashtable
$data.metadata.value = 'different'
$data | ConvertTo-Json -Depth 10 | Set-Content $manifest -Encoding utf8
Expect-Error { Apply $manifest } 'proposed metadata changed'

$badCases = @{
'duplicate.md' = @{ Text = "---`ntitle: Fixture`nms.update-cycle: old`nms.update-cycle: older`n---`nBody"; Error = 'Duplicate frontmatter key' }
'quoted-key.md' = @{ Text = "---`ntitle: Fixture`n'ms.update-cycle': old`n---`nBody"; Error = 'quoted frontmatter keys' }
'merge.md' = @{ Text = "---`ntitle: Fixture`n<<: *defaults`n---`nBody"; Error = 'YAML merge keys' }
'block.md' = @{ Text = "---`nms.update-cycle: |`n old`n---`nBody"; Error = 'ambiguous target scalar' }
'folded.md' = @{ Text = "---`nms.update-cycle: old`n continuation`n---`nBody"; Error = 'Multiline or structured' }
'indentless-list.md' = @{ Text = "---`nms.update-cycle:`n- old`n---`nBody"; Error = 'Multiline or structured' }
'indentless-list-comments.md' = @{ Text = "---`r`nms.update-cycle: # list`r`n`r`n# comment`r`n- old`r`n---`r`nBody"; Error = 'Multiline or structured' }
'indentless-list-empty-item.md' = @{ Text = "---`nms.update-cycle:`n-`n---`nBody"; Error = 'Multiline or structured' }
'list.md' = @{ Text = "---`nms.update-cycle: [old, older]`n---`nBody"; Error = 'ambiguous target scalar' }
'missing.md' = @{ Text = 'No frontmatter'; Error = 'opening YAML frontmatter delimiters' }
'spaced-duplicate.md' = @{ Text = "---`nms.update-cycle: old`nms.update-cycle : older`n---`nBody"; Error = 'Duplicate frontmatter key' }
'indented.md' = @{ Text = "---`n ms.update-cycle: old`n---`nBody"; Error = 'unindented mapping keys' }
'flow.md' = @{ Text = "---`n{ms.update-cycle: old}`n---`nBody"; Error = 'unindented mapping keys' }
}
foreach ($name in $badCases.Keys) {
Write-Fixture $name $badCases[$name].Text
$manifest = Make-Manifest invalid @($name)
$beforeBad = Snapshot $name
Expect-Error { Preview $manifest } $badCases[$name].Error
Assert ((Snapshot $name) -ceq $beforeBad) "Invalid article changed: $name"
}
$manifest = Make-Manifest traversal @('..\outside.md')
Expect-Error { Preview $manifest } 'without traversal'
[void](New-Item -ItemType Directory (Join-Path $fixtureRoot 'directory.md'))
$manifest = Make-Manifest directory @('directory.md')
Expect-Error { Preview $manifest } 'Expected an article file'
[IO.File]::WriteAllText((Join-Path $fixtureRoot 'utf16.md'), $base, [Text.Encoding]::Unicode)
$manifest = Make-Manifest utf16 @('utf16.md')
Expect-Error { Preview $manifest } 'not valid UTF-8'
$manifest = Make-Manifest duplicated @('lf.md', '.\lf.md')
Expect-Error { Preview $manifest } 'Duplicate article path'

foreach ($value in @('yes', '123', '2026-11-25', 'a: b # c', "it's fine", '')) {
Write-Fixture 'scalar.md' "---`ntitle: Fixture`n---`nBody without final newline"
$manifest = Make-Manifest scalar @('scalar.md') $value 'custom.key'
Preview $manifest
$null = Apply $manifest
$expectedScalar = "'" + $value.Replace("'", "''") + "'"
$expectedText = "---`ntitle: Fixture`ncustom.key: $expectedScalar`n---`nBody without final newline"
Assert ([IO.File]::ReadAllText((Join-Path $fixtureRoot 'scalar.md')) -ceq $expectedText) "Unsafe YAML string output: $value"
Preview $manifest
$result = Apply $manifest
Assert ($result.Changed -eq 0) "Quoted scalar was not idempotent: $value"
}
Write-Fixture 'comment.md' "---`ncustom.key: # empty value`n---`nBody"
$manifest = Make-Manifest comment @('comment.md') '# empty value' 'custom.key'
Preview $manifest
$null = Apply $manifest
Assert ([IO.File]::ReadAllText((Join-Path $fixtureRoot 'comment.md')) -ceq "---`ncustom.key: '# empty value' # empty value`n---`nBody") 'Empty comment-only value was treated as a string'
Write-Fixture 'numeric.md' "---`ncustom.key: .01`n---`nBody"
$manifest = Make-Manifest numeric @('numeric.md') '.01' 'custom.key'
Preview $manifest
$result = Apply $manifest
Assert ($result.Changed -eq 1) 'A numeric YAML scalar was mistaken for an already-correct string'
Assert ([IO.File]::ReadAllText((Join-Path $fixtureRoot 'numeric.md')) -ceq "---`ncustom.key: '.01'`n---`nBody") 'Numeric string was not quoted'
Write-Fixture 'spaced.md' "---`ncustom.key : old # keep spacing`n---`nBody"
$manifest = Make-Manifest spaced @('spaced.md') 'new-value' 'custom.key'
Preview $manifest
$null = Apply $manifest
Assert ([IO.File]::ReadAllText((Join-Path $fixtureRoot 'spaced.md')) -ceq "---`ncustom.key : new-value # keep spacing`n---`nBody") 'Existing key spacing was lost or a duplicate key was added'
Write-Fixture 'unrelated-list.md' "---`nms.update-cycle: old`nkeywords:`n- stable`n---`nBody"
$manifest = Make-Manifest unrelated-list @('unrelated-list.md')
Preview $manifest
$null = Apply $manifest
Assert ([IO.File]::ReadAllText((Join-Path $fixtureRoot 'unrelated-list.md')) -ceq "---`nms.update-cycle: 3650-days`nkeywords:`n- stable`n---`nBody") 'An unrelated indentless sequence prevented or changed the scalar edit'
"Passed $assertions assertions."
}
finally {
Remove-Item -LiteralPath $testRoot -Recurse -Force
}
Loading
Loading