Schema 1.6, all fields optional (D-0014): - F7 review: `review: draft|reviewed|needs_update`, `reviewed_by`, `reviewed_on`; lint check 17 and a review queue; ckb-lint marks reviews - F4 `> CONTRADICTION:` marker, lint check 18; validity dates deferred - F21 `tags` against the new `wiki/tags.md`, lint check 19, retrieve_candidates.py --tag, DRAFT/NEEDS_UPDATE flags - F9 profiles in workload/profiles/, protected `## Rules` on project scope pages, precedence AGENTS.md > Rules > profile - F8 explicit lessons (profile or wiki/lessons.md); new ckb-profile skill Carry-over: `.secrets-allow` `<glob> match:<hash>` entries (also in the bash/PowerShell fallbacks); open threads no longer print twice. ckb-upgrade migrates 1.5 -> 1.6; init/reset know tags.md; Starlight shows review and tags. Smoke test covers a 1.6 KB. Docs in EN and PL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
171 lines
9.4 KiB
PowerShell
171 lines
9.4 KiB
PowerShell
# Copyright 2026 Michał Kopeć
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
#
|
|
# No-Python fallback for `lint_report.py --quick` (Rule E session-start check).
|
|
#
|
|
# powershell -ExecutionPolicy Bypass -File lint_quick.ps1 [-Today YYYY-MM-DD]
|
|
#
|
|
# Run from the repository root. Read-only. Prints the same one-line summary
|
|
# shape as the Python script for four of its six quick checks:
|
|
# - malformed pages with no/unclosed frontmatter or no `type`
|
|
# - past freshness `last_updated` + `freshness_window_days` < today
|
|
# - source drift `## Sources` bullets whose sha256 no longer matches
|
|
# - possible secrets a reduced set of credential shapes, and `<private>` in wiki/
|
|
# Diverged crux quotes and the context budget need the full checker and are
|
|
# skipped; the summary says so. Exit 0 when clean, 1 when anything was flagged.
|
|
#
|
|
# Works on Windows PowerShell 5.1 and PowerShell 7+. Prefer the Python script
|
|
# whenever an interpreter is available — it is the reference implementation.
|
|
[CmdletBinding()]
|
|
param([string]$Today = "")
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
if (-not (Test-Path -LiteralPath "wiki" -PathType Container)) {
|
|
[Console]::Error.WriteLine("error: no wiki/ directory here — run from the repository root"); exit 2
|
|
}
|
|
function Parse-Date([string]$s) {
|
|
$s = $s.Trim()
|
|
if ($s -notmatch '^\d{4}-\d{2}-\d{2}$') { return $null }
|
|
try { return [datetime]::ParseExact($s, 'yyyy-MM-dd', [Globalization.CultureInfo]::InvariantCulture) } catch { return $null }
|
|
}
|
|
if ($Today -eq "") { $todayDate = (Get-Date).Date } else {
|
|
$todayDate = Parse-Date $Today
|
|
if ($null -eq $todayDate) { [Console]::Error.WriteLine("error: -Today is not a YYYY-MM-DD date: $Today"); exit 2 }
|
|
}
|
|
function Unquote([string]$v) {
|
|
$v = $v.Trim()
|
|
if ($v.Length -ge 2 -and $v[0] -eq $v[-1] -and ($v[0] -eq '"' -or $v[0] -eq "'")) { return $v.Substring(1, $v.Length - 2) }
|
|
return $v
|
|
}
|
|
|
|
$malformed = 0; $stale = 0; $drift = 0
|
|
$root = (Get-Location).Path
|
|
|
|
# Trees: wiki/ plus every connector-backed lib (has source.yaml).
|
|
$trees = @("wiki")
|
|
if (Test-Path -LiteralPath "libs" -PathType Container) {
|
|
Get-ChildItem -LiteralPath "libs" -Directory | ForEach-Object {
|
|
if (Test-Path -LiteralPath (Join-Path $_.FullName "source.yaml")) { $trees += "libs/$($_.Name)" }
|
|
}
|
|
}
|
|
|
|
foreach ($tree in $trees) {
|
|
$files = Get-ChildItem -LiteralPath $tree -Recurse -File -Filter *.md | Sort-Object FullName
|
|
foreach ($file in $files) {
|
|
if ($file.Name -eq "index.md" -or $file.Name -eq "log.md") { continue }
|
|
$rel = $file.FullName.Substring($root.Length).TrimStart('\', '/')
|
|
if (($rel -split '[\\/]') | Where-Object { $_.StartsWith('.') }) { continue }
|
|
|
|
$text = [IO.File]::ReadAllText($file.FullName) -replace "`r`n", "`n"
|
|
$lines = $text -split "`n"
|
|
|
|
# ---- frontmatter --------------------------------------------------
|
|
if ($lines.Count -eq 0 -or $lines[0] -ne '---') { $malformed++; continue }
|
|
$end = -1
|
|
for ($i = 1; $i -lt $lines.Count; $i++) { if ($lines[$i] -eq '---') { $end = $i; break } }
|
|
if ($end -lt 0) { $malformed++; continue }
|
|
$fm = @{}; $bad = $false
|
|
for ($i = 1; $i -lt $end; $i++) {
|
|
$line = $lines[$i]; $stripped = $line.Trim()
|
|
if ($stripped -eq '' -or $stripped.StartsWith('#')) { continue }
|
|
if ($line -match '^\s') { $bad = $true; break }
|
|
if ($stripped -notmatch ':') { $bad = $true; break }
|
|
$idx = $stripped.IndexOf(':')
|
|
$fm[$stripped.Substring(0, $idx).Trim()] = Unquote $stripped.Substring($idx + 1)
|
|
}
|
|
if ($bad) { $malformed++; continue }
|
|
if (-not $fm.ContainsKey('type') -or [string]::IsNullOrWhiteSpace($fm['type'])) { $malformed++; continue }
|
|
$body = ($lines | Select-Object -Skip ($end + 1)) -join "`n"
|
|
|
|
# ---- freshness ----------------------------------------------------
|
|
$win = $null
|
|
if ($fm.ContainsKey('freshness_window_days') -and $fm['freshness_window_days'] -match '^\s*\d+\s*$') { $win = [int]$fm['freshness_window_days'] }
|
|
$updRaw = if ($fm.ContainsKey('last_updated')) { $fm['last_updated'] } else { '' }
|
|
$upd = if ($updRaw -ne '') { Parse-Date $updRaw } else { $null }
|
|
if ($updRaw -ne '' -and $null -eq $upd) { $stale++ }
|
|
elseif ($null -ne $win -and $null -ne $upd) {
|
|
if (($todayDate - $upd).Days -gt $win) { $stale++ }
|
|
}
|
|
|
|
# ---- source fingerprints -----------------------------------------
|
|
$secStart = -1; $bodyLines = $body -split "`n"
|
|
for ($i = 0; $i -lt $bodyLines.Count; $i++) { if ($bodyLines[$i] -match '^## Sources\s*$') { $secStart = $i; break } }
|
|
if ($secStart -lt 0) { continue }
|
|
$section = @()
|
|
for ($i = $secStart + 1; $i -lt $bodyLines.Count; $i++) { if ($bodyLines[$i] -match '^## ') { break }; $section += $bodyLines[$i] }
|
|
$bullets = $section | Where-Object { $_ -match '^\s*[-*]\s+`([^`]+)`(.*)$' }
|
|
if (-not $bullets) { $drift++; continue }
|
|
foreach ($b in $bullets) {
|
|
if ($b -notmatch '^\s*[-*]\s+`([^`]+)`(.*)$') { continue }
|
|
$cited = $Matches[1].Trim(); $rest = $Matches[2]
|
|
if ($cited -match '^[a-z][a-z0-9+.-]*://') { continue }
|
|
$target = Join-Path $root $cited.TrimStart('/')
|
|
if (-not (Test-Path -LiteralPath $target)) { $target = Join-Path (Join-Path $root $tree) $cited.TrimStart('/') }
|
|
# A cited subtree is legal but has no single digest to recompute.
|
|
if (Test-Path -LiteralPath $target -PathType Container) { continue }
|
|
if (-not (Test-Path -LiteralPath $target -PathType Leaf)) { $drift++; continue }
|
|
if ($rest -notmatch '\b(sha256|etag|mtime):([^\s,)]+)') { $drift++; continue }
|
|
if ($Matches[1] -ne 'sha256') { continue }
|
|
$recorded = $Matches[2].ToLowerInvariant()
|
|
try { $actual = (Get-FileHash -LiteralPath $target -Algorithm SHA256).Hash.ToLowerInvariant() } catch { $drift++; continue }
|
|
if (-not $actual.StartsWith($recorded)) { $drift++ }
|
|
}
|
|
}
|
|
}
|
|
|
|
# ---- secrets: a reduced pattern set (lint_report.py knows more shapes) ----
|
|
$secretRe = '-----BEGIN ([A-Z0-9]+ )*PRIVATE KEY-----|(AKIA|ASIA)[0-9A-Z]{16}|gh[pousr]_[A-Za-z0-9]{36,}|github_pat_[A-Za-z0-9_]{50,}|xox[abprs]-[A-Za-z0-9-]{10,}|sk-(ant-|proj-)?[A-Za-z0-9_-]{20,}|AIza[0-9A-Za-z_-]{35}'
|
|
$secretExt = @('.md','.txt','.eml','.csv','.json','.jsonl','.yaml','.yml','.html','.log','.env','.ini','.toml','.sh','.py','.js','.ts','.xml')
|
|
$allow = @{}
|
|
$allowMatch = @() # `<glob> match:<hash>`: one matched string, every matching file
|
|
if (Test-Path -LiteralPath ".secrets-allow" -PathType Leaf) {
|
|
foreach ($a in (Get-Content -LiteralPath ".secrets-allow")) {
|
|
$parts = (($a -split '#', 2)[0]).Trim() -split '\s+'
|
|
if ($parts.Count -ne 2) { continue }
|
|
if ($parts[1] -like 'match:*') { $allowMatch += ,@($parts[0].TrimStart('/'), $parts[1].Substring(6).ToLowerInvariant()); continue }
|
|
$allow["$($parts[0].TrimStart('/')) $($parts[1].ToLowerInvariant())"] = $true
|
|
}
|
|
}
|
|
$sha = [Security.Cryptography.SHA256]::Create()
|
|
$secrets = 0
|
|
foreach ($top in @("wiki", "outputs", "workload", "raw")) {
|
|
if (-not (Test-Path -LiteralPath $top -PathType Container)) { continue }
|
|
foreach ($file in (Get-ChildItem -LiteralPath $top -Recurse -File | Sort-Object FullName)) {
|
|
if ($secretExt -notcontains $file.Extension.ToLowerInvariant()) { continue }
|
|
$rel = $file.FullName.Substring($root.Length).TrimStart('\', '/') -replace '\\', '/'
|
|
if ($rel -match '^outputs/(starlight|okf|teaching)/') { continue }
|
|
if (($rel -split '/') | Where-Object { $_.StartsWith('.') }) { continue }
|
|
foreach ($line in ([IO.File]::ReadAllText($file.FullName) -split "`n")) {
|
|
if ($top -eq "wiki" -and $line -match '(?i)<private>') { $secrets++ }
|
|
if ($line -cnotmatch $secretRe) { continue }
|
|
$bytes = [Text.Encoding]::UTF8.GetBytes($line.Trim())
|
|
$h = (-join ($sha.ComputeHash($bytes) | ForEach-Object { $_.ToString("x2") })).Substring(0, 8)
|
|
if ($allow.ContainsKey("$rel $h")) { continue }
|
|
$m = [regex]::Match($line, $secretRe).Value
|
|
$mh = (-join ($sha.ComputeHash([Text.Encoding]::UTF8.GetBytes($m)) | ForEach-Object { $_.ToString("x2") })).Substring(0, 8)
|
|
if ($allowMatch | Where-Object { $_[1] -eq $mh -and $rel -like $_[0] }) { continue }
|
|
$secrets++
|
|
}
|
|
}
|
|
}
|
|
|
|
$flagged = @()
|
|
if ($malformed) { $flagged += "$malformed malformed" }
|
|
if ($stale) { $flagged += "$stale past freshness window" }
|
|
if ($drift) { $flagged += "$drift source drift" }
|
|
if ($secrets) { $flagged += "$secrets possible secrets" }
|
|
$note = " (fallback: crux quotes and context budget not checked — install Python for the full check)"
|
|
if ($flagged.Count -eq 0) { Write-Output "ckb check: clean$note"; exit 0 }
|
|
Write-Output ("ckb check: " + ($flagged -join ", ") + " — run `"lint`" for detail" + $note)
|
|
exit 1
|