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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with: { go-version: '1.26.9' }
with: { go-version: '1.26.10' }
- name: gofmt
run: test -z "$(gofmt -l .)" || (gofmt -l . && exit 1)
- name: vet
Expand All @@ -65,7 +65,7 @@ jobs:
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with: { go-version: '1.26.9' }
with: { go-version: '1.26.10' }
- name: golangci-lint
uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0
with:
Expand All @@ -84,7 +84,7 @@ jobs:
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with: { go-version: '1.26.9' }
with: { go-version: '1.26.10' }
- name: fuzz untrusted-input parsers (negative control — normal input passes)
run: |
set -euo pipefail
Expand Down Expand Up @@ -259,7 +259,7 @@ jobs:
echo "negative control rejected as required — the schema gate catches malformed manifests"
- name: set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with: { go-version: '1.26.9' }
with: { go-version: '1.26.10' }
- name: leak gate + offline validator on the packaged artifact
# The Go suite validates the manifest offline AND runs the leak gate over
# the packaged skill payload (declared skills resolve to shareable, no
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with: { go-version: '1.26.9' }
with: { go-version: '1.26.10' }
- name: Initialize CodeQL
uses: github/codeql-action/init@1c5b675653bb5c22dbe9b12b556ec555138e09fd # v4.38.1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/govulncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with: { go-version: '1.26.9' }
with: { go-version: '1.26.10' }
- name: govulncheck
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with: { fetch-depth: 0 }
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with: { go-version: '1.26.9' }
with: { go-version: '1.26.10' }
# Refuse to publish a tag whose version has no real changelog entry. This
# runs BEFORE goreleaser, so an empty release fails the build rather than
# publishing and being reported after the fact. The gate asserts a dated,
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,19 @@ tagged release, goreleaser generates the release notes from the commit log
reference that cannot be loaded is a hard error naming the path (plain
`validate` without `--templates` never consults the key). (#182)

### Changed

- `index build` now links a subdirectory entry to the child's index file
(`* [Wine](wine/index.md)`) instead of the bare directory (`wine/`), so a
reader that can only open files can follow it. An index written by an older
build reads as stale under `index check` once; the next `index build`
rewrites its links and keeps hand-written subdirectory descriptions.

### Fixed

- `node touch` and every other `modified` refresh no longer turn an empty null
frontmatter key (`? `) into an empty-string key the node never had.

- `validate` now enforces OKF v0.2 §9 on every reserved `log.md` at any depth:
each `## ` date heading must be a valid ISO-8601 `YYYY-MM-DD` (rejecting
impossible dates like `2025-13-45` and non-dates like `last Tuesday`),
Expand All @@ -51,6 +62,8 @@ tagged release, goreleaser generates the release notes from the commit log
- The Go toolchain was bumped from 1.26.6 to 1.26.9 to pick up patched
standard-library fixes for seven disclosed vulnerabilities (GO-2026-6603,
-6607, -6608, -6611, -6612, -6613, -6617), clearing `govulncheck` in CI.
- The Go toolchain was bumped from 1.26.9 to 1.26.10 for the `crypto/x509`
fix (GO-2026-6809), reached through the atomic writer's temp-file naming.

## [0.4.0] - 2026-08-19

Expand Down
8 changes: 8 additions & 0 deletions docs/guides/index-and-freshness.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ concepts or subdirectories, enumerating only that directory's own contents with
index carries frontmatter (the §12 `okf_version` marker); every nested index
carries none.

A subdirectory entry links to the child's own index file, as in
`* [Wine](wine/index.md) - description`, not to the bare directory, so a reader that can only open files
(an agent's read tool, a plain Markdown viewer) can follow it. §8 leaves the
relative URL open; its `subdir/` example is one spelling, not a rule. An index
written by an older build with `wine/` links reads as stale under `index check`
until the next `index build`, which rewrites the links and keeps every
hand-written subdirectory description.

- `okfctl index build [dir]` regenerates the reserved `index.md` files from the
current bundle. Orphaned indexes left in a now-empty directory are pruned.
- `okfctl index check [dir]` verifies every directory's `index.md` is current;
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cwest/okfctl

go 1.26.9
go 1.26.10

require (
github.com/spf13/cobra v1.10.2
Expand Down
6 changes: 3 additions & 3 deletions internal/fsutil/confine.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func ResolveInRoot(root, rel string) (string, error) {
if filepath.VolumeName(native) != "" {
return "", fmt.Errorf("%w: %s", ErrEscapesRoot, rel)
}
native = strings.TrimLeft(native, string(filepath.Separator)+"/")
native = strings.TrimLeftFunc(native, func(r rune) bool { return r == '/' || r == filepath.Separator })
clean := filepath.Clean(native)
if clean == "." || native == "" {
return "", fmt.Errorf("%w: %q names the bundle root", ErrInvalidPath, rel)
Expand Down Expand Up @@ -103,7 +103,7 @@ func ResolveInRoot(root, rel string) (string, error) {
}
realExisting, err := filepath.EvalSymlinks(existing)
if err != nil {
return "", fmt.Errorf("%w: %s (%v)", ErrEscapesRoot, rel, err)
return "", fmt.Errorf("%w: %s (%w)", ErrEscapesRoot, rel, err)
}
if !within(realRoot, realExisting) {
return "", fmt.Errorf("%w: %s resolves through a symlink to %s", ErrEscapesRoot, rel, realExisting)
Expand All @@ -122,7 +122,7 @@ func ResolveInRoot(root, rel string) (string, error) {
cur = filepath.Join(cur, part)
fi, err := os.Lstat(cur)
if err != nil {
return "", fmt.Errorf("%w: %s (%v)", ErrEscapesRoot, rel, err)
return "", fmt.Errorf("%w: %s (%w)", ErrEscapesRoot, rel, err)
}
if fi.Mode()&(os.ModeSymlink|os.ModeIrregular) == 0 {
continue
Expand Down
28 changes: 28 additions & 0 deletions internal/okf/frontmatter_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ func TouchModifiedFile(abs string, at time.Time) error {
return fsutil.WriteFileAtomic(abs, out.Bytes(), 0o644) //nolint:gosec // G306: shareable bundle content file
}

// Refuse a block the frontmatter parser rejects. Decoding into a yaml.Node
// skips the map-level checks (a duplicate key, for one), so without this the
// refresh would rewrite an invalid block instead of leaving it byte-identical.
if _, _, err := ParseFrontmatter(raw); err != nil {
return fmt.Errorf("parse frontmatter of %s: %w", abs, err)
}

var doc yaml.Node
if err := yaml.Unmarshal(yamlBlock, &doc); err != nil {
return fmt.Errorf("parse frontmatter of %s: %w", abs, err)
Expand All @@ -69,6 +76,7 @@ func TouchModifiedFile(abs string, at time.Time) error {
return fmt.Errorf("frontmatter of %s is not a mapping", abs)
}
setScalar(root, "modified", stamp)
keepEmptyNullKeysNull(root)

var fmBuf bytes.Buffer
enc := yaml.NewEncoder(&fmBuf)
Expand Down Expand Up @@ -104,6 +112,26 @@ func frontmatterMapping(doc *yaml.Node) *yaml.Node {
return doc
}

// keepEmptyNullKeysNull rewrites every mapping key that is an empty plain null
// (an explicit `? ` key) as `~`, recursively. yaml.v3 encodes that empty plain
// scalar as an empty quoted STRING, so a refresh would otherwise invent a key
// the node never had. `~` is the same null, spelled so it survives the encoder.
// A key that is already a quoted empty string is real data and is left alone.
func keepEmptyNullKeysNull(n *yaml.Node) {
for _, c := range n.Content {
keepEmptyNullKeysNull(c)
}
if n.Kind != yaml.MappingNode {
return
}
for i := 0; i+1 < len(n.Content); i += 2 {
k := n.Content[i]
if k.Kind == yaml.ScalarNode && k.Value == "" && k.Style == 0 && k.ShortTag() == "!!null" {
k.Value = "~"
}
}
}

// setScalar updates the scalar value of key in a mapping node in place,
// preserving key order; if the key is absent it is appended, keeping the
// original keys ahead of it.
Expand Down
40 changes: 40 additions & 0 deletions internal/okf/frontmatter_edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,46 @@ func TestTouchModifiedFileAddsMissingModified(t *testing.T) {
}
}

// A null key written as an empty explicit key (`? `) must stay null across a
// refresh. yaml.v3 re-encodes that empty plain scalar as an empty quoted STRING
// key, which a parser then reads as a key the node never had (the
// FuzzTouchModifiedRoundTrip failure `touch added keys: [] -> [ modified]`,
// where the blank is the empty key). The negative
// control: a key that really is the empty string keeps its quotes.
func TestTouchModifiedFileKeepsEmptyNullKeyNull(t *testing.T) {
at := time.Date(2026, 7, 26, 0, 0, 0, 0, time.UTC)
cases := []struct {
name, src string
wantKeys int // keys a parser sees after the touch
}{
{"null key stays null", "---\n? \n---\n", 1},
{"nested null key stays null", "---\na:\n ? \n---\n", 2},
{"empty string key stays a key", "---\n'': x\n---\n", 2},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
abs := filepath.Join(t.TempDir(), "n.md")
if err := os.WriteFile(abs, []byte(c.src), 0o644); err != nil {
t.Fatal(err)
}
if err := TouchModifiedFile(abs, at); err != nil {
t.Fatalf("TouchModifiedFile: %v", err)
}
got := readAll(t, abs)
fm, _, err := ParseFrontmatter([]byte(got))
if err != nil {
t.Fatalf("touched frontmatter does not parse: %v\n%q", err, got)
}
if len(fm) != c.wantKeys {
t.Fatalf("got %d keys %q, want %d:\n%q", len(fm), sortedKeys(fm), c.wantKeys, got)
}
if c.name == "nested null key stays null" && strings.Contains(got, "''") {
t.Fatalf("nested null key re-encoded as an empty string:\n%q", got)
}
})
}
}

// The separator blank line between the frontmatter fence and the body must
// survive a refresh byte-for-byte. The corpus writes `---\n\n# Heading`; a
// refresh that collapses that to `---\n# Heading` is a prose change the drift
Expand Down
2 changes: 1 addition & 1 deletion internal/okf/tagfold.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func tagPluralCandidates(w string) []string {
case strings.HasSuffix(w, "es"):
j := n - 3 // the letter before "es"
var out []string
if j > 0 && !(w[j] == 's' && w[j-1] == 's') {
if j > 0 && (w[j] != 's' || w[j-1] != 's') {
out = append(out, w[:n-1])
}
return append(out, w[:n-2])
Expand Down
2 changes: 2 additions & 0 deletions internal/okf/writepath_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ func FuzzTouchModifiedRoundTrip(f *testing.F) {
"---\r\ntype: Reference\r\n---\r\n\r\nCRLF body\r\n",
"---\ntitle: |\n line\n ---\n injected: true\n---\n",
"---\n- a list\n---\n",
"---\n? \n---\n", // an empty null key: re-encoded as '' it became a new key
"---\nype: 0\nype:\n---\n", // a duplicate key: the parser rejects it, so touch must too
"",
}
for _, s := range seeds {
Expand Down
Loading