akm-cli 0.10.261128 → 0.10.261129-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/dist/cli.js +2 -0
- package/dist/commands/agent/contribute-cli.js +7 -1
- package/dist/commands/backups-cli.js +103 -0
- package/dist/commands/health.js +1 -34
- package/dist/commands/improve/reflect-noise.js +0 -1
- package/dist/commands/lint/base-linter.js +24 -48
- package/dist/commands/lint/bundle-skip.js +27 -0
- package/dist/commands/lint/index.js +83 -45
- package/dist/commands/lint/tracked-secrets.js +43 -0
- package/dist/commands/lint/types.js +58 -0
- package/dist/commands/proposal/repository.js +5 -1
- package/dist/commands/sources/stash-skeleton.js +7 -26
- package/dist/core/adapter/adapters/akm-adapter.js +2 -2
- package/dist/core/adapter/adapters/akm-workflow-adapter.js +6 -1
- package/dist/core/adapter/adapters/shared.js +13 -25
- package/dist/core/asset/lint-text.js +14 -13
- package/dist/core/asset/stale-path.js +63 -0
- package/dist/core/config/schema/sources-bundles.js +3 -0
- package/dist/output/shapes/passthrough.js +1 -0
- package/dist/output/text/lint-format.js +90 -1
- package/dist/output/text/migrate.js +5 -0
- package/dist/scripts/akm-migrate-node.js +1149 -791
- package/dist/scripts/akm-migrate.js +1149 -791
- package/dist/sources/include.js +1 -1
- package/dist/sources/snapshot-fetchers/website-ingest.js +0 -2
- package/dist/workspace/backups.js +21 -0
- package/dist/workspace/cli-child.js +5 -1
- package/dist/workspace-node.mjs +2 -0
- package/dist/workspace.d.ts +4 -0
- package/dist/workspace.js +1 -0
- package/docs/architecture/internals/health-advisories.md +1 -2
- package/docs/guides/bundles.md +5 -4
- package/docs/integration/bundling-akm.md +9 -1
- package/docs/reference/asset-types.md +1 -2
- package/docs/reference/cli.md +83 -3
- package/docs/reference/configuration.md +8 -2
- package/docs/reference/data-and-telemetry.md +1 -0
- package/docs/reference/env-and-secrets.md +9 -4
- package/docs/reference/website-sources.md +2 -2
- package/docs/reference/workspace.md +1 -0
- package/package.json +1 -1
- package/schemas/akm-config.json +34 -0
- package/dist/commands/health/stash-exposure.js +0 -64
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,26 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `akm backups prune [--older-than <duration>] [--dry-run] [--yes]` removes the copies `akm migrate apply` leaves under the data directory's `backups/` that are older than the duration (default 30d), keeps the newest entry of each folder, and reports the count and bytes per folder. `akm-cli/workspace` has `backups.prune`.
|
|
12
|
+
- AKM Desktop: the "Data directory size" advisory has a "Prune backups…" action that shows what a dry run would free and asks before it removes anything.
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- AKM Desktop: the Review page and the Library file views fill the window instead of stopping at a 1600px column; accepting or rejecting one proposal no longer raises a toast (the "Last:" line reports it, with Undo… or Reopen…); "Why AKM proposed this" and its facts sit above the change; the judge's sentence is shown as the reason when the proposal has none of its own.
|
|
17
|
+
- `akm lint` policy lives in the bundle's config entry. `lint.skip` maps any rule lint reports to globs of bundle-relative paths (`**` is the whole bundle), for example `"stale-path": ["skills/sec/**"]`; a rule name lint does not know is warned about once and ignored. The `lint_skip:` frontmatter key is no longer read, and `akm import <url>` and website snapshots no longer write it.
|
|
18
|
+
- `stale-path` is for finding and correcting paths. It checks only paths this machine can judge: under the current user's home, a configured bundle or project root, and `/tmp`; `/opt`, `/var`, `/etc`, `/root` and other users' homes are not checked. Each finding carries `ref`, `file`, `line`, `path`, `lineText`, `nearestExisting` and `reason` (`missing`, or `ephemeral` for a `/tmp` path).
|
|
19
|
+
- `akm lint` prints one line per rule (findings, assets, top folders, whether `--fix` fixes it, how to fix it), and `--json` adds `byRule`. The new `--rule <name>` lists one rule's findings grouped by asset and combines with `--type`.
|
|
20
|
+
- `missing-updated` no longer applies to skills. `redacted-content` also ignores `[REDACTED]` in table cells and indented code.
|
|
21
|
+
- The `stash-git-exposure` health advisory is now the `tracked-secrets` lint rule: one finding per `env/` or `secrets/` file that git tracks in a bundle with a remote. List `"tracked-secrets": ["**"]` under `lint.skip` to keep tracking them on purpose.
|
|
22
|
+
- akm's own commits follow git: they no longer filter `env/` and `secrets/`. `akm bundle create` adds plain `env/` and `secrets/` lines to the bundle `.gitignore` when it mentions neither, and akm never reads `.gitignore` for policy.
|
|
23
|
+
- `akm migrate` (and `akm upgrade`) gain a `bundlePolicy` step: in writable bundles it strips `lint_skip:` frontmatter, and a `.gitignore` with the old `# akm: intentionally track env and secrets` line adds `"tracked-secrets": ["**"]` to the bundle's `lint.skip`. `.gitignore` is not modified. Run `akm migrate apply --dry-run` first.
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- AKM Desktop: chart tooltips are no longer cut off by a short chart or by the window's edge, and the library map's name tip flips above the pointer near the bottom.
|
|
28
|
+
|
|
9
29
|
## [0.10.261128] - 2026-11-16
|
|
10
30
|
|
|
11
31
|
### Fixed
|
package/dist/cli.js
CHANGED
|
@@ -72,6 +72,7 @@ import { defineGroupCommand, EXIT_CODES, emitJsonError, GLOBAL_OUTPUT_ARGS, outp
|
|
|
72
72
|
import { assertKnownFlags, consumeConfigFileFlag } from "./cli/unknown-flags.js";
|
|
73
73
|
import { startUsage } from "./cli/usage.js";
|
|
74
74
|
import { agentCommand, lintCommand } from "./commands/agent/contribute-cli.js";
|
|
75
|
+
import { backupsCommand } from "./commands/backups-cli.js";
|
|
75
76
|
import { commandCommand } from "./commands/command/command-cli.js";
|
|
76
77
|
import { generateBashCompletions, installBashCompletions } from "./commands/completions.js";
|
|
77
78
|
import { configCommand } from "./commands/config-cli.js";
|
|
@@ -598,6 +599,7 @@ const commands = {
|
|
|
598
599
|
metrics: metricsCommand,
|
|
599
600
|
info: infoCommand,
|
|
600
601
|
bundle: bundleCommand,
|
|
602
|
+
backups: backupsCommand,
|
|
601
603
|
upgrade: upgradeCommand,
|
|
602
604
|
search: searchCommand,
|
|
603
605
|
curate: curateCommand,
|
|
@@ -112,7 +112,7 @@ export const agentCommand = defineCommand({
|
|
|
112
112
|
export const lintCommand = defineCommand({
|
|
113
113
|
meta: {
|
|
114
114
|
name: "lint",
|
|
115
|
-
description: "Scan bundle .md files for structural issues (unquoted colons, missing updated field, orphaned stubs, placeholder stubs, missing name/type, stale paths, broken refs in body text and in refs/xrefs/supersededBy/contradictedBy frontmatter). Takes one file (`akm lint <file>`) or the whole bundle. Use --fix to auto-fix Tier 1 issues. Exits 0 on success regardless of findings; use --fail-on-flagged for CI fail-on-finding behavior.",
|
|
115
|
+
description: "Scan bundle .md files for structural issues (unquoted colons, missing updated field, orphaned stubs, placeholder stubs, missing name/type, stale paths (paths the agent can find and correct; `--rule stale-path` lists them), tracked secrets, broken refs in body text and in refs/xrefs/supersededBy/contradictedBy frontmatter). Takes one file (`akm lint <file>`) or the whole bundle. Use --fix to auto-fix Tier 1 issues. Exits 0 on success regardless of findings; use --fail-on-flagged for CI fail-on-finding behavior.",
|
|
116
116
|
},
|
|
117
117
|
args: {
|
|
118
118
|
// R-051: `lint` is a raw `defineCommand` (not `defineJsonCommand`), so it
|
|
@@ -164,6 +164,11 @@ export const lintCommand = defineCommand({
|
|
|
164
164
|
description: "Only lint assets of this type (akm bundles only; e.g. workflows, tasks); with a file, its type",
|
|
165
165
|
default: undefined,
|
|
166
166
|
},
|
|
167
|
+
rule: {
|
|
168
|
+
type: "string",
|
|
169
|
+
description: "List the findings of this rule grouped by asset (e.g. stale-path); cannot combine with --fix",
|
|
170
|
+
default: undefined,
|
|
171
|
+
},
|
|
167
172
|
},
|
|
168
173
|
async run({ args }) {
|
|
169
174
|
await runWithJsonErrors(async () => {
|
|
@@ -172,6 +177,7 @@ export const lintCommand = defineCommand({
|
|
|
172
177
|
dir: getStringArg(args, "dir"),
|
|
173
178
|
file: getStringArg(args, "file"),
|
|
174
179
|
typeFilter: getStringArg(args, "type"),
|
|
180
|
+
rule: getStringArg(args, "rule"),
|
|
175
181
|
pruneDanglingEdges: getHyphenatedBoolean(args, "prune-dangling-edges"),
|
|
176
182
|
});
|
|
177
183
|
output("lint", result);
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { confirmDestructive } from "../cli/confirm.js";
|
|
7
|
+
import { defineGroupCommand, defineJsonCommand, output } from "../cli/shared.js";
|
|
8
|
+
import { UsageError } from "../core/errors.js";
|
|
9
|
+
import { getDataDir } from "../core/paths.js";
|
|
10
|
+
import { DURATION_UNITS, parseDuration } from "../core/time.js";
|
|
11
|
+
import { sizeOfPath } from "./health/data-dir-usage.js";
|
|
12
|
+
export const DEFAULT_BACKUP_AGE = "30d";
|
|
13
|
+
/**
|
|
14
|
+
* Remove the entries of each folder under `<dataDir>/backups/` last modified before `now - olderThanMs`, except the
|
|
15
|
+
* newest entry of each folder. Backups are only ever written (`akm migrate apply` and `akm upgrade` copy a file in
|
|
16
|
+
* before they rewrite it); nothing reads an old one back, so the newest stays as the latest rollback point.
|
|
17
|
+
*/
|
|
18
|
+
export function pruneBackups(options) {
|
|
19
|
+
const olderThan = options.olderThan ?? DEFAULT_BACKUP_AGE;
|
|
20
|
+
const age = parseDuration(olderThan, DURATION_UNITS);
|
|
21
|
+
if (age === null) {
|
|
22
|
+
throw new UsageError(`Invalid --older-than "${olderThan}". Use a duration like 30d, 12h, or 3M.`, "INVALID_FLAG_VALUE");
|
|
23
|
+
}
|
|
24
|
+
const dryRun = options.dryRun === true;
|
|
25
|
+
const cutoff = (options.now ?? Date.now()) - age;
|
|
26
|
+
const root = path.join(options.dataDir, "backups");
|
|
27
|
+
const folders = [];
|
|
28
|
+
let top = [];
|
|
29
|
+
try {
|
|
30
|
+
top = fs.readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory());
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// No backups directory yet: nothing to prune.
|
|
34
|
+
}
|
|
35
|
+
for (const { name: folder } of top.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
36
|
+
const entries = fs
|
|
37
|
+
.readdirSync(path.join(root, folder))
|
|
38
|
+
.map((name) => ({ name, mtime: fs.lstatSync(path.join(root, folder, name)).mtimeMs }))
|
|
39
|
+
.sort((a, b) => a.mtime - b.mtime || a.name.localeCompare(b.name));
|
|
40
|
+
const old = entries.slice(0, -1).filter((entry) => entry.mtime < cutoff);
|
|
41
|
+
let bytes = 0;
|
|
42
|
+
for (const { name } of old) {
|
|
43
|
+
const target = path.join(root, folder, name);
|
|
44
|
+
bytes += sizeOfPath(target, { remaining: Number.POSITIVE_INFINITY }).bytes;
|
|
45
|
+
if (!dryRun)
|
|
46
|
+
fs.rmSync(target, { recursive: true, force: true });
|
|
47
|
+
}
|
|
48
|
+
if (old.length)
|
|
49
|
+
folders.push({ folder, count: old.length, bytes, kept: entries.length - old.length });
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
dryRun,
|
|
53
|
+
olderThan,
|
|
54
|
+
cutoff: new Date(cutoff).toISOString(),
|
|
55
|
+
count: folders.reduce((sum, f) => sum + f.count, 0),
|
|
56
|
+
bytes: folders.reduce((sum, f) => sum + f.bytes, 0),
|
|
57
|
+
folders,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const backupsPruneCommand = defineJsonCommand({
|
|
61
|
+
meta: {
|
|
62
|
+
name: "prune",
|
|
63
|
+
description: "Remove old backups under the data directory's backups/ folder, the copies `akm migrate apply` makes before it " +
|
|
64
|
+
"rewrites files. Removes entries older than --older-than (default 30d) and always keeps the newest entry of " +
|
|
65
|
+
"each folder, so the latest rollback point survives. --dry-run reports what would be removed. Reports the " +
|
|
66
|
+
"count and bytes per folder.",
|
|
67
|
+
},
|
|
68
|
+
args: {
|
|
69
|
+
"older-than": {
|
|
70
|
+
type: "string",
|
|
71
|
+
description: `Remove backups older than this duration, such as 30d, 12h or 3M (default ${DEFAULT_BACKUP_AGE})`,
|
|
72
|
+
},
|
|
73
|
+
"dry-run": { type: "boolean", description: "Report what would be removed without removing it", default: false },
|
|
74
|
+
yes: {
|
|
75
|
+
type: "boolean",
|
|
76
|
+
alias: "y",
|
|
77
|
+
description: "Skip the confirmation prompt (required in non-interactive mode)",
|
|
78
|
+
default: false,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
async run({ args }) {
|
|
82
|
+
const options = {
|
|
83
|
+
dataDir: getDataDir(),
|
|
84
|
+
...(typeof args["older-than"] === "string" ? { olderThan: args["older-than"] } : {}),
|
|
85
|
+
};
|
|
86
|
+
// The preview also validates --older-than before anything is asked or removed.
|
|
87
|
+
const preview = pruneBackups({ ...options, dryRun: true });
|
|
88
|
+
if (args["dry-run"] === true || preview.count === 0) {
|
|
89
|
+
output("backups-prune", { ...preview, dryRun: args["dry-run"] === true });
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const confirmed = await confirmDestructive(`Remove ${preview.count} backups older than ${preview.olderThan} from ${path.join(options.dataDir, "backups")}? This cannot be undone.`, { yes: args.yes === true });
|
|
93
|
+
if (!confirmed) {
|
|
94
|
+
process.stderr.write("Aborted.\n");
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
output("backups-prune", pruneBackups(options));
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
export const backupsCommand = defineGroupCommand({
|
|
101
|
+
meta: { name: "backups", description: "Manage the backups akm keeps in its data directory" },
|
|
102
|
+
subCommands: { prune: backupsPruneCommand },
|
|
103
|
+
});
|
package/dist/commands/health.js
CHANGED
|
@@ -33,7 +33,6 @@ import { emptyLlmUsageAggregate, readLlmUsageAggregate } from "./health/llm-usag
|
|
|
33
33
|
import { collectPluginStalenessAdvisories } from "./health/plugin-staleness.js";
|
|
34
34
|
import { collectSchedulerBinaryAdvisory } from "./health/scheduler-binary.js";
|
|
35
35
|
import { readSemanticSearchState } from "./health/semantic-search-check.js";
|
|
36
|
-
import { collectStashExposureAdvisory } from "./health/stash-exposure.js";
|
|
37
36
|
import { buildTypeDirectoryAdvisory } from "./health/type-directory-check.js";
|
|
38
37
|
import { MIN_ROWS_FOR_WORST_TASK_FAIL_RATE, } from "./health/types.js";
|
|
39
38
|
import { collectVersionDriftAdvisory } from "./health/version-drift.js";
|
|
@@ -258,8 +257,7 @@ function gatherSessionExtractionLedgerPhase(db, now) {
|
|
|
258
257
|
return { since, rows: getExtractOutcomeCountsSince(db, since) };
|
|
259
258
|
}
|
|
260
259
|
/**
|
|
261
|
-
* The best-effort advisory groups beyond the health-check registry: the
|
|
262
|
-
* `stash-git-exposure` probe, the 08 surfaces group (binary-config-skew,
|
|
260
|
+
* The best-effort advisory groups beyond the health-check registry: the 08 surfaces group (binary-config-skew,
|
|
263
261
|
* egress-endpoints), `type-directory-disagreement` (#831), `data-dir-usage`
|
|
264
262
|
* (#896), and `plugin-version` (itlackey/akm#832). Order matches emission
|
|
265
263
|
* order in the returned array. A probe/filesystem failure in any try/catch
|
|
@@ -271,37 +269,6 @@ function gatherAncillaryAdvisories(db, options, egressConfigView) {
|
|
|
271
269
|
const indexStateMismatch = detectIndexStateGenerationMismatch(db);
|
|
272
270
|
if (indexStateMismatch)
|
|
273
271
|
advisories.push(indexStateMismatch);
|
|
274
|
-
// Surface a `stash-git-exposure` advisory for each bundle whose env/secret
|
|
275
|
-
// assets are git-tracked AND that has a remote (the leak moment). Every
|
|
276
|
-
// configured bundle is checked, not just the working stash; each honours the
|
|
277
|
-
// intentional-tracking marker in its own `.gitignore`. Best-effort.
|
|
278
|
-
// Cheap guard: only shell out to git for a bundle root with its OWN `.git`
|
|
279
|
-
// (or when a test injected a fake seam), so the hot path never spawns for
|
|
280
|
-
// non-git bundles. Trade-off: a bundle pointed at a bare subdirectory of a
|
|
281
|
-
// parent git repo (no `.git` of its own) is not checked; akm-init and
|
|
282
|
-
// writable git installs put `.git` at the bundle root.
|
|
283
|
-
let exposureRoots = [];
|
|
284
|
-
try {
|
|
285
|
-
const exposureStashDir = options.stashDir ?? resolveStashDir();
|
|
286
|
-
exposureRoots = [exposureStashDir];
|
|
287
|
-
exposureRoots = resolveSourceEntries(exposureStashDir).map((source) => source.path);
|
|
288
|
-
}
|
|
289
|
-
catch {
|
|
290
|
-
// An unreadable working stash skips the advisory; an unreadable bundle
|
|
291
|
-
// config still checks the working stash. Neither aborts the report.
|
|
292
|
-
}
|
|
293
|
-
for (const root of new Set(exposureRoots.map((dir) => path.resolve(dir)))) {
|
|
294
|
-
try {
|
|
295
|
-
if (options.stashExposureGit || fs.existsSync(path.join(root, ".git"))) {
|
|
296
|
-
const stashExposure = collectStashExposureAdvisory(root, options.stashExposureGit);
|
|
297
|
-
if (stashExposure)
|
|
298
|
-
advisories.push(stashExposure);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
catch {
|
|
302
|
-
// Non-fatal — a git/probe failure must not abort the health report.
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
272
|
// 08 surfaces: the remaining read-only advisory group (binary-config-skew,
|
|
306
273
|
// egress-endpoints). Best-effort — a filesystem probe failure must not abort
|
|
307
274
|
// the health report.
|
|
@@ -38,9 +38,10 @@ import { assetPathCandidatesForName, assetPathForName, filesForRef, stashDirFor,
|
|
|
38
38
|
import { BUNDLE_REF_RE } from "../../core/asset/asset-ref.js";
|
|
39
39
|
import { removeFrontmatterListValues, rewriteFrontmatterListValue, spliceFrontmatterLine, } from "../../core/asset/frontmatter.js";
|
|
40
40
|
import { checkUnquotedDescriptionColon } from "../../core/asset/frontmatter-lint.js";
|
|
41
|
-
import {
|
|
41
|
+
import { isSkillPath } from "../../core/asset/lint-text.js";
|
|
42
42
|
import { isArchivedRelPath } from "../../core/asset/memory-archive.js";
|
|
43
43
|
import { conceptIdFromTypeName } from "../../core/asset/resolve-ref.js";
|
|
44
|
+
import { findStalePaths } from "../../core/asset/stale-path.js";
|
|
44
45
|
import { localDateStamp } from "../../core/common.js";
|
|
45
46
|
import { containsRedactedContent, REDACTED_CONTENT_MARKER } from "../../core/content-safety.js";
|
|
46
47
|
import { DERIVED_SUFFIX } from "../../core/recognition-util.js";
|
|
@@ -128,26 +129,12 @@ function fixUnquotedColon(raw) {
|
|
|
128
129
|
}
|
|
129
130
|
return null;
|
|
130
131
|
}
|
|
131
|
-
function checkMissingUpdated(data, frontmatterText) {
|
|
132
|
-
return frontmatterText !== null && !("updated" in data);
|
|
132
|
+
function checkMissingUpdated(relPath, data, frontmatterText) {
|
|
133
|
+
return frontmatterText !== null && !("updated" in data) && !isSkillPath(relPath);
|
|
133
134
|
}
|
|
134
135
|
function fixMissingUpdated(raw, mtime) {
|
|
135
136
|
return spliceFrontmatterLine(raw, `updated: ${localDateStamp(mtime)}`) ?? raw;
|
|
136
137
|
}
|
|
137
|
-
// ── stale-path helpers ────────────────────────────────────────────────────────
|
|
138
|
-
/**
|
|
139
|
-
* Absolute paths presented as current guidance that do not exist on this host.
|
|
140
|
-
* Paths under a home directory this host does not have belong to another host
|
|
141
|
-
* or user and are not checked.
|
|
142
|
-
*/
|
|
143
|
-
function checkStalePath(body) {
|
|
144
|
-
return findCurrentPathReferences(body).filter((candidate) => {
|
|
145
|
-
const home = homeRootOf(candidate);
|
|
146
|
-
if (home !== undefined && !fs.existsSync(home))
|
|
147
|
-
return false;
|
|
148
|
-
return !fs.existsSync(candidate);
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
138
|
// ── fence-strip helper ────────────────────────────────────────────────────────
|
|
152
139
|
/**
|
|
153
140
|
* Returns `body` with all fenced code block lines replaced by empty strings,
|
|
@@ -165,14 +152,21 @@ function stripFencedBlocks(body) {
|
|
|
165
152
|
return lines.join("\n");
|
|
166
153
|
}
|
|
167
154
|
/**
|
|
168
|
-
* `raw` without fenced code blocks, inline code spans,
|
|
169
|
-
* blockquote lines: places where `[REDACTED]` is
|
|
170
|
-
* example rather than left behind by damaged content.
|
|
155
|
+
* `raw` without fenced and indented code blocks, table rows, inline code spans,
|
|
156
|
+
* double-quoted text and blockquote lines: places where `[REDACTED]` is
|
|
157
|
+
* documented or quoted as an example rather than left behind by damaged content.
|
|
171
158
|
*/
|
|
172
159
|
function stripQuotedExamples(raw) {
|
|
160
|
+
let inIndentedCode = true; // an indented line starts a code block at the top or after a blank line
|
|
173
161
|
return stripFencedBlocks(raw)
|
|
174
162
|
.split("\n")
|
|
175
|
-
.filter((line) =>
|
|
163
|
+
.filter((line) => {
|
|
164
|
+
const blank = line.trim() === "";
|
|
165
|
+
const indented = /^(?: {4}|\t)/.test(line);
|
|
166
|
+
const code = indented && inIndentedCode;
|
|
167
|
+
inIndentedCode = blank || code;
|
|
168
|
+
return !code && !/^\s*[>|]/.test(line);
|
|
169
|
+
})
|
|
176
170
|
.join("\n")
|
|
177
171
|
.replace(/`[^`\n]*`|"[^"\n]*"|\u201c[^\u201d\n]*\u201d/g, "");
|
|
178
172
|
}
|
|
@@ -637,17 +631,7 @@ export function runBaseChecks(ctx) {
|
|
|
637
631
|
let modified = false;
|
|
638
632
|
/** Findings whose `fixed: true` is only true once the flush below succeeds. */
|
|
639
633
|
const pendingFixes = [];
|
|
640
|
-
|
|
641
|
-
// Accept both an array (`lint_skip: [missing-ref, stale-path]`) and a
|
|
642
|
-
// single scalar (`lint_skip: missing-ref`). Non-string entries are coerced
|
|
643
|
-
// and trimmed so loosely-typed YAML still gates correctly.
|
|
644
|
-
const rawLintSkip = ctx.data?.lint_skip;
|
|
645
|
-
const lintSkip = [
|
|
646
|
-
...(ctx.lintSkip ?? []),
|
|
647
|
-
...(Array.isArray(rawLintSkip) ? rawLintSkip : rawLintSkip != null ? [rawLintSkip] : []),
|
|
648
|
-
]
|
|
649
|
-
.map((v) => String(v).trim())
|
|
650
|
-
.filter(Boolean);
|
|
634
|
+
const lintSkip = ctx.lintSkip ?? [];
|
|
651
635
|
const shouldRun = (issueType) => !lintSkip.includes(issueType);
|
|
652
636
|
if (shouldRun("redacted-content") && containsRedactedContent(stripQuotedExamples(currentRaw))) {
|
|
653
637
|
issues.push({
|
|
@@ -695,7 +679,7 @@ export function runBaseChecks(ctx) {
|
|
|
695
679
|
}
|
|
696
680
|
} // end shouldRun("unquoted-colon")
|
|
697
681
|
// ── 2. missing-updated ─────────────────────────────────────────────────
|
|
698
|
-
if (shouldRun("missing-updated") && checkMissingUpdated(ctx.data, ctx.frontmatter)) {
|
|
682
|
+
if (shouldRun("missing-updated") && checkMissingUpdated(ctx.relPath, ctx.data, ctx.frontmatter)) {
|
|
699
683
|
if (ctx.fix) {
|
|
700
684
|
let mtime;
|
|
701
685
|
try {
|
|
@@ -755,22 +739,14 @@ export function runBaseChecks(ctx) {
|
|
|
755
739
|
};
|
|
756
740
|
flushIfModified();
|
|
757
741
|
// ── 3. stale-path ──────────────────────────────────────────────────────
|
|
758
|
-
// M3: checkStalePath returns all stale matches; push one issue per path.
|
|
759
|
-
// M4: Also scan ctx.frontmatter for stale paths (absolute paths in frontmatter).
|
|
760
742
|
if (shouldRun("stale-path")) {
|
|
761
|
-
const
|
|
762
|
-
const
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
issues.push({
|
|
769
|
-
file: ctx.relPath,
|
|
770
|
-
issue: "stale-path",
|
|
771
|
-
detail: `nonexistent path: ${candidate}${portableHint}`,
|
|
772
|
-
fixed: false,
|
|
773
|
-
});
|
|
743
|
+
const { frontmatter, body, bodyStartLine } = ctx;
|
|
744
|
+
const stale = [
|
|
745
|
+
...(frontmatter ? findStalePaths(frontmatter, 2, ctx.stalePathRoots, ctx.stashRoot) : []),
|
|
746
|
+
...findStalePaths(body, bodyStartLine, ctx.stalePathRoots, ctx.stashRoot),
|
|
747
|
+
];
|
|
748
|
+
for (const { detail, ...finding } of stale) {
|
|
749
|
+
issues.push({ file: ctx.relPath, issue: "stale-path", detail, fixed: false, ...finding });
|
|
774
750
|
}
|
|
775
751
|
}
|
|
776
752
|
// ── 4. missing-ref ─────────────────────────────────────────────────────
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4
|
+
import { bundleKeyForContentRoot } from "../../core/config/config-sources.js";
|
|
5
|
+
import { warnOnce } from "../../core/warn.js";
|
|
6
|
+
import { includeEntryToRegExp } from "../../sources/include.js";
|
|
7
|
+
import { LINT_RULES } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* The bundle's `lint.skip` map as a lookup from a bundle-relative path to the
|
|
10
|
+
* rules skipped for it. A rule name lint does not know is warned about once
|
|
11
|
+
* and ignored.
|
|
12
|
+
*/
|
|
13
|
+
export function bundleLintSkip(config, bundleRoot) {
|
|
14
|
+
const skip = config.bundles?.[bundleKeyForContentRoot(config, bundleRoot) ?? ""]?.lint?.skip ?? {};
|
|
15
|
+
const rules = [];
|
|
16
|
+
for (const [rule, globs] of Object.entries(skip)) {
|
|
17
|
+
if (!LINT_RULES.includes(rule)) {
|
|
18
|
+
warnOnce(`lint-skip-rule:${rule}`, `[lint] bundle lint.skip names "${rule}", which is not a lint rule; ignoring it.`);
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
rules.push([rule, globs.map(includeEntryToRegExp)]);
|
|
22
|
+
}
|
|
23
|
+
return (relPath) => {
|
|
24
|
+
const normalized = relPath.split("\\").join("/");
|
|
25
|
+
return rules.filter(([, patterns]) => patterns.some((pattern) => pattern.test(normalized))).map(([rule]) => rule);
|
|
26
|
+
};
|
|
27
|
+
}
|