session-orchestrator 3.16.0 → 3.19.0
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.cursor/rules/030-wave-execution.mdc +17 -1
- package/CHANGELOG.md +130 -412
- package/README.md +17 -12
- package/SECURITY.md +190 -27
- package/agents/AGENTS.md +20 -3
- package/agents/code-implementer.md +6 -6
- package/agents/db-specialist.md +1 -1
- package/agents/qa-strategist.md +31 -6
- package/agents/schemas/qa-strategist.schema.json +27 -0
- package/agents/schemas/test-writer.schema.json +60 -2
- package/agents/security-reviewer.md +1 -1
- package/agents/session-reviewer.md +1 -1
- package/agents/test-writer.md +29 -10
- package/agents/ui-developer.md +1 -1
- package/commands/contract-version-bump.md +28 -0
- package/commands/portfolio.md +1 -1
- package/docs/README.md +2 -1
- package/docs/USER-GUIDE.md +8 -3
- package/docs/ci-setup.md +121 -7
- package/docs/codex-setup.md +1 -1
- package/docs/components.md +7 -7
- package/docs/cursor-setup.md +22 -9
- package/docs/events-schema.md +5 -1
- package/docs/instruction-delivery.md +444 -0
- package/docs/pi-setup.md +1 -1
- package/docs/rule-authoring.md +58 -9
- package/docs/session-config-reference.md +306 -6
- package/docs/session-config-template.md +66 -3
- package/docs/telemetry/telemetry-claims.md +204 -0
- package/docs/telemetry.md +158 -0
- package/hooks/_lib/guard-source-loader.mjs +467 -0
- package/hooks/_lib/lock-bootstrap.mjs +21 -0
- package/hooks/_lib/vcs-create-matcher.mjs +119 -0
- package/hooks/config-protection.mjs +0 -0
- package/hooks/enforce-commands.mjs +10 -2
- package/hooks/hooks-codex.json +1 -1
- package/hooks/hooks-cursor.json +11 -2
- package/hooks/hooks-pi.json +10 -0
- package/hooks/hooks.json +21 -1
- package/hooks/on-session-end.mjs +178 -18
- package/hooks/on-session-start.mjs +23 -0
- package/hooks/post-bash-write-verify.mjs +977 -0
- package/hooks/post-subagent-discovery-validator.mjs +256 -41
- package/hooks/pre-bash-destructive-guard.mjs +525 -160
- package/hooks/pre-bash-issue-budget.mjs +167 -0
- package/hooks/pre-bash-sessions-ledger-guard.mjs +627 -0
- package/hooks/pre-bash-templates-first.mjs +96 -63
- package/hooks/skill-invocation-telemetry.mjs +109 -10
- package/hooks/subagent-telemetry.mjs +527 -37
- package/package.json +16 -3
- package/pi/prompts/contract-version-bump.md +12 -0
- package/rules/README.md +32 -0
- package/scripts/archive-closed-prds.mjs +12 -22
- package/scripts/autopilot-multi.mjs +103 -20
- package/scripts/backfill-abandoned-sessions.mjs +160 -4
- package/scripts/check-doc-consistency.sh +17 -1
- package/scripts/compute-grounding-injection.sh +18 -3
- package/scripts/dialectic-deriver.mjs +7 -2
- package/scripts/eval-session.mjs +50 -9
- package/scripts/fleet-instruction-scan.mjs +141 -0
- package/scripts/lib/auto-dialectic.mjs +11 -2
- package/scripts/lib/auto-dream.mjs +16 -5
- package/scripts/lib/autopilot/mr-draft.mjs +31 -1
- package/scripts/lib/autopilot/worktree-pipeline.mjs +113 -5
- package/scripts/lib/backlog-scan.mjs +39 -6
- package/scripts/lib/blocked-commands-policy.mjs +340 -0
- package/scripts/lib/build-live-signals.mjs +7 -4
- package/scripts/lib/ci-status-banner.mjs +75 -12
- package/scripts/lib/claude-md-budget-lint.mjs +283 -34
- package/scripts/lib/command-blocker.mjs +1013 -58
- package/scripts/lib/config/config-protection.mjs +2 -1
- package/scripts/lib/config/context-coverage.mjs +82 -0
- package/scripts/lib/config/drift-check.mjs +9 -1
- package/scripts/lib/config/gitlab-portfolio.mjs +1 -1
- package/scripts/lib/config/issue-budget.mjs +123 -0
- package/scripts/lib/config/moc-staleness.mjs +98 -0
- package/scripts/lib/config/reconcile.mjs +21 -0
- package/scripts/lib/config/section-extractor.mjs +121 -1
- package/scripts/lib/config/worktree-orphans.mjs +138 -0
- package/scripts/lib/config-schema.mjs +23 -3
- package/scripts/lib/config.mjs +32 -0
- package/scripts/lib/context-coverage-banner.mjs +223 -0
- package/scripts/lib/convergence-monitor.mjs +49 -3
- package/scripts/lib/description-surface.mjs +535 -0
- package/scripts/lib/dispatcher/enumerate.mjs +136 -30
- package/scripts/lib/dispatcher/rank.mjs +22 -8
- package/scripts/lib/ecosystem-wizard/config-writer.mjs +26 -24
- package/scripts/lib/ecosystem-wizard/wizard-prompt.mjs +1 -1
- package/scripts/lib/eval/engine.mjs +47 -5
- package/scripts/lib/events.mjs +59 -7
- package/scripts/lib/evolve/autonomy-verdict.mjs +5 -0
- package/scripts/lib/evolve/autopilot-effectiveness.mjs +54 -7
- package/scripts/lib/gates/gate-full.mjs +15 -3
- package/scripts/lib/gates/gate-helpers.mjs +132 -6
- package/scripts/lib/gitlab-ops/stale-mr-sweep.mjs +28 -8
- package/scripts/lib/gitlab-portfolio/aggregator.mjs +8 -2
- package/scripts/lib/gitlab-portfolio/cli.mjs +1 -1
- package/scripts/lib/handover-gate.mjs +7 -3
- package/scripts/lib/harness-audit/categories/category4.mjs +22 -5
- package/scripts/lib/instruction-budget-guard.mjs +402 -51
- package/scripts/lib/io.mjs +345 -10
- package/scripts/lib/issue-budget.mjs +269 -0
- package/scripts/lib/issue-close-strip-labels.mjs +39 -9
- package/scripts/lib/label-scope.mjs +47 -0
- package/scripts/lib/learnings/schema.mjs +43 -3
- package/scripts/lib/lock-reaper.mjs +1 -2
- package/scripts/lib/memory-proposals/schema.mjs +36 -1
- package/scripts/lib/moc-staleness-banner.mjs +267 -0
- package/scripts/lib/peer-discovery.mjs +645 -0
- package/scripts/lib/pi-hook-bridge.mjs +146 -17
- package/scripts/lib/product-repo-detect.mjs +9 -8
- package/scripts/lib/project-hygiene.mjs +432 -0
- package/scripts/lib/quality-gate.mjs +167 -0
- package/scripts/lib/recommendations-v0.mjs +1 -1
- package/scripts/lib/reconcile/eligibility.mjs +1 -1
- package/scripts/lib/reconcile/emitter.mjs +23 -4
- package/scripts/lib/reconcile/engine.mjs +147 -39
- package/scripts/lib/reconcile/idempotency.mjs +114 -14
- package/scripts/lib/reconcile-nudge-banner.mjs +65 -9
- package/scripts/lib/resource-probe/evaluate.mjs +70 -4
- package/scripts/lib/resource-probe.mjs +19 -0
- package/scripts/lib/rule-loader.mjs +6 -0
- package/scripts/lib/scope-baseline.mjs +564 -0
- package/scripts/lib/scope-gate.mjs +399 -98
- package/scripts/lib/session-close-backfill.mjs +61 -6
- package/scripts/lib/session-end/phase-skip.mjs +1 -0
- package/scripts/lib/session-end/worktree-orphan-sweep.mjs +252 -0
- package/scripts/lib/session-id.mjs +221 -41
- package/scripts/lib/session-lock.mjs +304 -6
- package/scripts/lib/session-schema/constants.mjs +22 -3
- package/scripts/lib/session-schema/filters.mjs +88 -0
- package/scripts/lib/session-schema/validator.mjs +16 -0
- package/scripts/lib/session-schema.mjs +1 -0
- package/scripts/lib/sessions-integrity-banner.mjs +294 -0
- package/scripts/lib/sessions-staleness-banner.mjs +121 -12
- package/scripts/lib/skill-evolution/idempotency.mjs +135 -16
- package/scripts/lib/skill-evolution/mr-opener.mjs +9 -1
- package/scripts/lib/skill-health/join.mjs +35 -9
- package/scripts/lib/spiral-carryover.mjs +142 -30
- package/scripts/lib/state-md/mission-status.mjs +53 -3
- package/scripts/lib/subagents-schema.mjs +43 -9
- package/scripts/lib/telemetry/anon-id.mjs +141 -0
- package/scripts/lib/telemetry/consent.mjs +299 -0
- package/scripts/lib/telemetry/paths.mjs +27 -0
- package/scripts/lib/telemetry/queue.mjs +287 -0
- package/scripts/lib/telemetry/schema.mjs +384 -0
- package/scripts/lib/telemetry/sync.mjs +312 -0
- package/scripts/lib/test-runner/issue-reconcile.mjs +53 -13
- package/scripts/lib/tests-src-ratio.mjs +484 -0
- package/scripts/lib/validate/check-agents.mjs +56 -0
- package/scripts/lib/validate/check-hooks-symmetry.mjs +244 -10
- package/scripts/lib/validate/check-rules.mjs +217 -35
- package/scripts/lib/validate/check-test-value-bans.mjs +782 -0
- package/scripts/lib/validate/check-unicode-safety.mjs +1 -0
- package/scripts/lib/validate-vendored-rules.mjs +10 -2
- package/scripts/lib/vault-archive.mjs +17 -2
- package/scripts/lib/vault-backfill/glab.mjs +8 -0
- package/scripts/lib/vault-mirror/process.mjs +30 -0
- package/scripts/lib/vault-mirror/render-sessions.mjs +293 -36
- package/scripts/lib/vault-status/board-writer.mjs +63 -5
- package/scripts/lib/vault-status/narrative-mirror.mjs +13 -7
- package/scripts/lib/vcs-repo-spec.mjs +362 -0
- package/scripts/lib/wave-resource-gate.mjs +115 -11
- package/scripts/lib/worktree/listing.mjs +44 -7
- package/scripts/mcp-server.sh +32 -6
- package/scripts/measure-context-overhead.sh +151 -0
- package/scripts/memory-propose.mjs +72 -9
- package/scripts/print-applicable-rules.mjs +51 -12
- package/scripts/release.mjs +534 -0
- package/scripts/run-quality-gate.mjs +123 -5
- package/scripts/telemetry.mjs +250 -0
- package/scripts/validate-wave-scope.mjs +182 -17
- package/scripts/vault-integration-watcher.mjs +32 -10
- package/skills/_shared/config-reading.md +2 -2
- package/skills/bootstrap/fast-template.md +1 -1
- package/skills/claude-md-drift-check/checker.mjs +145 -28
- package/skills/contract-version-bump/SKILL.md +219 -0
- package/skills/discovery/SKILL.md +4 -4
- package/skills/discovery/issue-templates.md +11 -11
- package/skills/discovery/probes-audit.md +1 -1
- package/skills/discovery/probes-feature.md +1 -1
- package/skills/discovery/probes-session.md +26 -5
- package/skills/ecosystem-health/SKILL.md +1 -1
- package/skills/ecosystem-health/wizard.md +4 -4
- package/skills/evolve/SKILL.md +1 -0
- package/skills/gitlab-ops/SKILL.md +20 -12
- package/skills/gitlab-portfolio/SKILL.md +2 -2
- package/skills/hook-development/SKILL.md +1 -1
- package/skills/mode-selector/SKILL.md +1 -1
- package/skills/npm-publish/SKILL.md +97 -0
- package/skills/plan/SKILL.md +5 -5
- package/skills/plan/mode-feature.md +4 -4
- package/skills/plan/mode-new.md +10 -10
- package/skills/plan/mode-retro.md +1 -1
- package/skills/quality-gates/SKILL.md +1 -1
- package/skills/reconcile/SKILL.md +21 -4
- package/skills/session-end/SKILL.md +108 -14
- package/skills/session-end/discovery-scan.md +4 -2
- package/skills/session-end/drift-operations.md +4 -4
- package/skills/session-end/metrics-collection.md +13 -0
- package/skills/session-end/phase-3-2-docs-verification.md +1 -1
- package/skills/session-end/phase-3-6-tail.md +2 -1
- package/skills/session-end/plan-verification.md +5 -2
- package/skills/session-end/vault-operations.md +1 -1
- package/skills/session-end/verification-checklist.md +1 -1
- package/skills/session-plan/SKILL.md +6 -2
- package/skills/session-plan/wave-template.md +2 -0
- package/skills/session-start/SKILL.md +149 -7
- package/skills/session-start/phase-4-5-resource-health.md +15 -2
- package/skills/test-runner/SKILL.md +2 -2
- package/skills/vault-sync/SKILL.md +1 -1
- package/skills/vault-sync/package-lock.json +3 -3
- package/skills/vault-sync/validator.mjs +228 -40
- package/skills/wave-executor/SKILL.md +5 -2
- package/skills/wave-executor/circuit-breaker.md +2 -0
- package/skills/wave-executor/wave-loop.md +163 -10
- package/templates/_shared/loop.md +4 -4
|
@@ -1,21 +1,71 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// check-rules.mjs — Validate .claude/rules/*.md files
|
|
3
|
-
// against the never-always-on invariant (FA4 #697 backstop for the reconcile emitter
|
|
4
|
-
// brandmauer in scripts/lib/reconcile/emitter.mjs ~line 193).
|
|
2
|
+
// check-rules.mjs — Validate .claude/rules/*.md files against two invariants:
|
|
5
3
|
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
4
|
+
// (1) AUTO-GENERATED rules (`auto-generated: true` — FA4 #697 backstop for the
|
|
5
|
+
// reconcile emitter brandmauer in scripts/lib/reconcile/emitter.mjs ~line
|
|
6
|
+
// 193). HARD-FAIL, exit-code-driving:
|
|
7
|
+
// (a) never-always-on: must have at least one activation axis — a
|
|
8
|
+
// non-empty `globs` array OR a `host-class` key. A rule that is
|
|
9
|
+
// always-on (globs null/absent AND no host-class) is a budget
|
|
10
|
+
// violation (#668 / #687).
|
|
11
|
+
// SPECIAL CASE (#892 QA Defect — the auto-generated twin of #880 QA
|
|
12
|
+
// Defect 1) — an EMPTY `globs` array (`globs: []`) is NOT the
|
|
13
|
+
// "no axis" case and is NOT always-on: rule-loader.mjs
|
|
14
|
+
// unconditionally excludes on `globs.length === 0` (~line 526)
|
|
15
|
+
// AFTER gating runs, so the rule never loads in ANY context — even
|
|
16
|
+
// one where a co-present `host-class:` key would otherwise satisfy
|
|
17
|
+
// the axis. Before #892 this branch silently mis-reported (or, when
|
|
18
|
+
// paired with `host-class:`, silently missed entirely) this case
|
|
19
|
+
// under the inverted "always-on" FAIL message. This gets its own
|
|
20
|
+
// distinct FAIL, fired independent of `host-class`, because
|
|
21
|
+
// `host-class` cannot rescue an empty globs array from that
|
|
22
|
+
// unconditional exclusion — mirrors the handwritten branch's
|
|
23
|
+
// identical `hasEmptyGlobs` fix below.
|
|
24
|
+
// (b) learning-key must be present (traceability back to the emitter source).
|
|
25
|
+
// (c) expires-at must be present (auto-generated rules must have a TTL).
|
|
8
26
|
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
27
|
+
// (2) HANDWRITTEN rules (no `auto-generated: true` — #880 FA5, WARN-only,
|
|
28
|
+
// NEVER affects the exit code). The auto-generated brandmauer above only
|
|
29
|
+
// binds the MACHINE author (the reconcile emitter) — a human authoring a
|
|
30
|
+
// rule file by hand bypasses it entirely. #880's finding: several
|
|
31
|
+
// handwritten rules in this repo carry only a `tier:` axis (no
|
|
32
|
+
// `globs`/`paths`/`host-class`) and no periodic-review marker, and nothing
|
|
33
|
+
// in the system ever prompts a re-review. This second, symmetric check
|
|
34
|
+
// extends the SAME invariant shape to handwritten rules, starting in WARN
|
|
35
|
+
// mode — a hard gate is a later, deliberate step (see
|
|
36
|
+
// docs/rule-authoring.md § "Handwritten Rule Review Date (#880 FA5)").
|
|
37
|
+
// A handwritten rule is flagged when it is missing EITHER:
|
|
38
|
+
// (a) an activation axis — a non-empty `globs`/`paths` array, a
|
|
39
|
+
// `host-class` key, OR a `tier` key. `tier:` counts: rule-loader.mjs
|
|
40
|
+
// `applyGates()` honours it as a real load-context gate (excludes
|
|
41
|
+
// `coordinator-only` rules from wave context and vice versa) — see
|
|
42
|
+
// docs/rule-authoring.md § "Tier gating (issue #692)".
|
|
43
|
+
// SPECIAL CASE — an EMPTY `globs`/`paths` array (`globs: []`) is
|
|
44
|
+
// NOT the "no axis" case and is NOT always-on: rule-loader.mjs
|
|
45
|
+
// unconditionally excludes on `globs.length === 0` AFTER gating
|
|
46
|
+
// runs, so the rule never loads in any context — even one where a
|
|
47
|
+
// co-present `tier:`/`host-class:` key would otherwise satisfy the
|
|
48
|
+
// axis. This branch gets its own distinct WARN, fired independent
|
|
49
|
+
// of `tier`/`host-class`, because neither can rescue an empty
|
|
50
|
+
// globs array from that unconditional exclusion (#880 QA Defect 1
|
|
51
|
+
// fix — see the FAIL/WARN inversion this replaced in git blame).
|
|
52
|
+
// (b) a `review-date` key (ISO 8601 date) — a periodic-review marker,
|
|
53
|
+
// DELIBERATELY DISTINCT from `expires-at`. rule-loader.mjs treats
|
|
54
|
+
// `expires-at` as a live EXPIRY gate (`applyGates`): reusing it on a
|
|
55
|
+
// hand-authored always-on safety rule (e.g. security.md) would make
|
|
56
|
+
// that rule silently stop loading the day the date passes — an
|
|
57
|
+
// unacceptable behaviour change for a metadata-only review marker.
|
|
58
|
+
// `review-date` is inert: it is NOT in rule-loader.mjs's
|
|
59
|
+
// SCALAR_META_KEYS allowlist (contract-locked, not modified by
|
|
60
|
+
// #880), so `parseGlobsFrontmatter()` never surfaces it and
|
|
61
|
+
// `loadApplicableRules()` never gates on it — it is parsed only by
|
|
62
|
+
// THIS script, via the local `hasFrontmatterKey()` helper below.
|
|
15
63
|
//
|
|
16
64
|
// Usage: check-rules.mjs <plugin-root>
|
|
17
|
-
// Outputs lines of the form " PASS: ..." / " FAIL: ..."
|
|
18
|
-
// Exit 0 = all invariants satisfied (
|
|
65
|
+
// Outputs lines of the form " PASS: ..." / " FAIL: ..." / " WARN: ...".
|
|
66
|
+
// Exit 0 = all AUTO-GENERATED invariants satisfied (WARN lines from the
|
|
67
|
+
// handwritten check NEVER affect the exit code); exit 1 = at least one
|
|
68
|
+
// auto-generated FAIL.
|
|
19
69
|
|
|
20
70
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
21
71
|
import { join } from 'node:path';
|
|
@@ -32,6 +82,7 @@ const RULES_DIR = join(pluginRoot, '.claude', 'rules');
|
|
|
32
82
|
|
|
33
83
|
let passed = 0;
|
|
34
84
|
let failed = 0;
|
|
85
|
+
let warned = 0;
|
|
35
86
|
|
|
36
87
|
function pass(msg) {
|
|
37
88
|
console.log(` PASS: ${msg}`);
|
|
@@ -43,8 +94,39 @@ function fail(msg) {
|
|
|
43
94
|
failed++;
|
|
44
95
|
}
|
|
45
96
|
|
|
97
|
+
function warn(msg) {
|
|
98
|
+
console.log(` WARN: ${msg}`);
|
|
99
|
+
warned++;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ---------------------------------------------------------------------------
|
|
103
|
+
// Local frontmatter helper for the `review-date` key (#880 FA5). Deliberately
|
|
104
|
+
// NOT routed through rule-loader.mjs's `parseGlobsFrontmatter()` — that
|
|
105
|
+
// module is contract-locked and its SCALAR_META_KEYS allowlist does not (and
|
|
106
|
+
// should not) recognise `review-date`, per the module-doc rationale above.
|
|
107
|
+
// This is a minimal, self-contained frontmatter-block scan mirroring
|
|
108
|
+
// rule-loader.mjs's own FRONTMATTER_RE, not a general YAML parser.
|
|
109
|
+
// ---------------------------------------------------------------------------
|
|
110
|
+
const FRONTMATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Returns true when the frontmatter block of `contents` contains a top-level
|
|
114
|
+
* `key:` line carrying a non-empty value.
|
|
115
|
+
*
|
|
116
|
+
* @param {string} contents - raw file contents
|
|
117
|
+
* @param {string} key - frontmatter key name (no colon)
|
|
118
|
+
* @returns {boolean}
|
|
119
|
+
*/
|
|
120
|
+
function hasFrontmatterKey(contents, key) {
|
|
121
|
+
const match = FRONTMATTER_RE.exec(contents);
|
|
122
|
+
if (!match) return false;
|
|
123
|
+
const keyRe = new RegExp(`^${key}:\\s*(\\S.*)?$`, 'm');
|
|
124
|
+
const keyMatch = keyRe.exec(match[1]);
|
|
125
|
+
return Boolean(keyMatch && keyMatch[1] && keyMatch[1].trim() !== '');
|
|
126
|
+
}
|
|
127
|
+
|
|
46
128
|
// ============================================================================
|
|
47
|
-
// Check:
|
|
129
|
+
// Check: .claude/rules/ rule invariants
|
|
48
130
|
// ============================================================================
|
|
49
131
|
console.log('--- Check: .claude/rules/ auto-generated rule invariants ---');
|
|
50
132
|
|
|
@@ -52,7 +134,7 @@ console.log('--- Check: .claude/rules/ auto-generated rule invariants ---');
|
|
|
52
134
|
if (!existsSync(RULES_DIR)) {
|
|
53
135
|
pass('no .claude/rules/ directory found — nothing to validate');
|
|
54
136
|
console.log('');
|
|
55
|
-
console.log(`Results: ${passed} passed, ${failed} failed`);
|
|
137
|
+
console.log(`Results: ${passed} passed, ${failed} failed, ${warned} warned`);
|
|
56
138
|
process.exit(0);
|
|
57
139
|
}
|
|
58
140
|
|
|
@@ -67,12 +149,16 @@ try {
|
|
|
67
149
|
if (mdFiles.length === 0) {
|
|
68
150
|
pass('no .md rule files found — nothing to validate');
|
|
69
151
|
console.log('');
|
|
70
|
-
console.log(`Results: ${passed} passed, ${failed} failed`);
|
|
152
|
+
console.log(`Results: ${passed} passed, ${failed} failed, ${warned} warned`);
|
|
71
153
|
process.exit(0);
|
|
72
154
|
}
|
|
73
155
|
|
|
74
|
-
//
|
|
75
|
-
|
|
156
|
+
// Parse every rule file once, splitting into the auto-generated and
|
|
157
|
+
// handwritten cohorts. Malformed frontmatter → skipped from BOTH checks
|
|
158
|
+
// (matches pre-#880 behaviour: a rule whose frontmatter cannot be parsed is
|
|
159
|
+
// neither PASS'd nor FAIL'd).
|
|
160
|
+
const autoGeneratedEntries = [];
|
|
161
|
+
const handwrittenEntries = [];
|
|
76
162
|
|
|
77
163
|
for (const name of mdFiles.sort()) {
|
|
78
164
|
const filePath = join(RULES_DIR, name);
|
|
@@ -88,28 +174,52 @@ for (const name of mdFiles.sort()) {
|
|
|
88
174
|
try {
|
|
89
175
|
parsed = parseGlobsFrontmatter(contents);
|
|
90
176
|
} catch {
|
|
91
|
-
// Malformed frontmatter — not
|
|
177
|
+
// Malformed frontmatter — not auditable by either branch, skip.
|
|
92
178
|
continue;
|
|
93
179
|
}
|
|
94
180
|
|
|
95
181
|
const { globs, meta } = parsed;
|
|
96
|
-
|
|
97
|
-
// Only validate rules that explicitly declare auto-generated: true.
|
|
98
|
-
if (meta['auto-generated'] !== true) continue;
|
|
99
|
-
|
|
100
|
-
autoGeneratedCount++;
|
|
101
182
|
const rel = `.claude/rules/${name}`;
|
|
102
183
|
|
|
184
|
+
if (meta['auto-generated'] === true) {
|
|
185
|
+
autoGeneratedEntries.push({ rel, globs, meta });
|
|
186
|
+
} else {
|
|
187
|
+
handwrittenEntries.push({ rel, globs, meta, contents });
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// ---------------------------------------------------------------------------
|
|
192
|
+
// Auto-generated branch (FA4 #697) — UNCHANGED behaviour, hard-fail.
|
|
193
|
+
// ---------------------------------------------------------------------------
|
|
194
|
+
for (const { rel, globs, meta } of autoGeneratedEntries) {
|
|
103
195
|
// (a) never-always-on: must have at least one activation axis.
|
|
104
|
-
// globs is null (no frontmatter / no globs key)
|
|
105
|
-
//
|
|
196
|
+
// globs is one of: null (no frontmatter / no globs key), [] (key present
|
|
197
|
+
// but EMPTY — the #892 QA-Defect special case, see module doc), or a
|
|
198
|
+
// populated array. host-class absent → no host-class axis.
|
|
199
|
+
const hasEmptyGlobs = Array.isArray(globs) && globs.length === 0;
|
|
106
200
|
const hasGlobs = Array.isArray(globs) && globs.length > 0;
|
|
107
201
|
const hasHostClass = Object.prototype.hasOwnProperty.call(meta, 'host-class');
|
|
108
202
|
|
|
109
|
-
if (
|
|
203
|
+
if (hasEmptyGlobs) {
|
|
204
|
+
// An empty globs array is NOT "no axis at all" and is NOT "always-on" —
|
|
205
|
+
// it is the opposite: rule-loader.mjs's unconditional globs.length === 0
|
|
206
|
+
// exclusion (~line 526) fires AFTER gating, so this rule never loads in
|
|
207
|
+
// ANY context, even one that also carries a host-class: key. Fire
|
|
208
|
+
// independent of hasHostClass — host-class cannot rescue an empty globs
|
|
209
|
+
// array from that unconditional exclusion (#892 QA Defect fix — see the
|
|
210
|
+
// module doc for the full rule-loader.mjs citation and the identical
|
|
211
|
+
// handwritten-branch fix this mirrors, #880 QA Defect 1).
|
|
110
212
|
fail(
|
|
111
|
-
`${rel} — auto-generated rule
|
|
112
|
-
|
|
213
|
+
`${rel} — auto-generated rule has an empty globs array (globs: []) — this rule matches NOTHING and never ` +
|
|
214
|
+
'loads in ANY context, even one that also carries a host-class: key (rule-loader.mjs excludes on ' +
|
|
215
|
+
'globs.length === 0 unconditionally, after gating runs). This is the OPPOSITE of "always-on" but still ' +
|
|
216
|
+
'violates the never-always-on invariant (#668/#687) because the rule never activates at all. Populate ' +
|
|
217
|
+
'globs: with real patterns or remove the file.',
|
|
218
|
+
);
|
|
219
|
+
} else if (!hasGlobs && !hasHostClass) {
|
|
220
|
+
fail(
|
|
221
|
+
`${rel} — auto-generated rule is always-on (no activation axis: globs is absent AND host-class absent). ` +
|
|
222
|
+
'This violates the never-always-on invariant (#668/#687). Add a globs filter or host-class axis.',
|
|
113
223
|
);
|
|
114
224
|
}
|
|
115
225
|
|
|
@@ -123,21 +233,93 @@ for (const name of mdFiles.sort()) {
|
|
|
123
233
|
fail(`${rel} — auto-generated rule is missing required frontmatter key: expires-at`);
|
|
124
234
|
}
|
|
125
235
|
|
|
126
|
-
// Emit a PASS line only when the rule satisfies ALL three invariants:
|
|
127
|
-
//
|
|
128
|
-
//
|
|
236
|
+
// Emit a PASS line only when the rule satisfies ALL three invariants: a
|
|
237
|
+
// genuine activation axis (a NON-EMPTY globs array, or host-class — NEVER
|
|
238
|
+
// an empty globs array, which is dead-not-passing regardless of host-class)
|
|
239
|
+
// AND learning-key AND expires-at. When any failed, the FAIL line(s) above
|
|
240
|
+
// already emitted.
|
|
129
241
|
const lkOk = Object.prototype.hasOwnProperty.call(meta, 'learning-key');
|
|
130
242
|
const eaOk = Object.prototype.hasOwnProperty.call(meta, 'expires-at');
|
|
131
|
-
if ((hasGlobs || hasHostClass) && lkOk && eaOk) {
|
|
243
|
+
if (!hasEmptyGlobs && (hasGlobs || hasHostClass) && lkOk && eaOk) {
|
|
132
244
|
pass(`${rel} — auto-generated rule satisfies all invariants`);
|
|
133
245
|
}
|
|
134
246
|
}
|
|
135
247
|
|
|
136
|
-
if (
|
|
248
|
+
if (autoGeneratedEntries.length === 0) {
|
|
137
249
|
pass('no auto-generated rules found — nothing to validate');
|
|
138
250
|
}
|
|
139
251
|
|
|
252
|
+
// ---------------------------------------------------------------------------
|
|
253
|
+
// Handwritten branch (#880 FA5) — WARN-only, non-fatal, never affects exit code.
|
|
254
|
+
// ---------------------------------------------------------------------------
|
|
255
|
+
console.log('');
|
|
256
|
+
console.log(
|
|
257
|
+
'--- Check: .claude/rules/ handwritten-rule activation + review-date (warn mode, #880) ---',
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
for (const { rel, globs, meta, contents } of handwrittenEntries) {
|
|
261
|
+
// `globs` (the merged globs/paths value from parseGlobsFrontmatter — #795
|
|
262
|
+
// alias, `globs:` wins when both are present) is one of:
|
|
263
|
+
// - null → neither key present
|
|
264
|
+
// - [] (Array, length 0) → key present but EMPTY
|
|
265
|
+
// - [...] (Array, length>0) → key present and populated
|
|
266
|
+
const hasEmptyGlobs = Array.isArray(globs) && globs.length === 0;
|
|
267
|
+
const hasGlobsAxis = Array.isArray(globs) && globs.length > 0;
|
|
268
|
+
const hasHostClassAxis = Object.prototype.hasOwnProperty.call(meta, 'host-class');
|
|
269
|
+
const hasTierAxis = Object.prototype.hasOwnProperty.call(meta, 'tier');
|
|
270
|
+
const hasAxis = hasGlobsAxis || hasHostClassAxis || hasTierAxis;
|
|
271
|
+
const hasReviewDate = hasFrontmatterKey(contents, 'review-date');
|
|
272
|
+
|
|
273
|
+
if (hasEmptyGlobs) {
|
|
274
|
+
// An empty globs/paths array is NOT the same condition as "no axis at
|
|
275
|
+
// all", and it is NOT "always-on" — it is the opposite. Per
|
|
276
|
+
// rule-loader.mjs's loadApplicableRules() (~line 526): once frontmatter
|
|
277
|
+
// parses, tier/host-class/mode/expiry gating (applyGates) runs FIRST and
|
|
278
|
+
// can only ADD exclusions; if the rule survives that gating, the loader
|
|
279
|
+
// THEN unconditionally excludes it when `globs.length === 0` ("matches
|
|
280
|
+
// nothing (intentionally scoped out)") — this check fires regardless of
|
|
281
|
+
// whether a tier:/host-class: key would otherwise have satisfied the
|
|
282
|
+
// axis requirement. So a rule with `globs: []` never loads in ANY
|
|
283
|
+
// context, even one paired with `tier: always`. Always warn with the
|
|
284
|
+
// accurate "dead rule" message here, independent of `hasAxis` — a
|
|
285
|
+
// co-present tier:/host-class: key cannot rescue an empty globs array
|
|
286
|
+
// from this unconditional exclusion, so it must not suppress the warning
|
|
287
|
+
// either (#880 QA Defect 1 fix).
|
|
288
|
+
warn(
|
|
289
|
+
`${rel} — handwritten rule has an empty globs/paths array (globs: [] or paths: []) — this rule matches ` +
|
|
290
|
+
'NOTHING and never loads in ANY context, even one that also carries a tier:/host-class: key ' +
|
|
291
|
+
'(rule-loader.mjs excludes on globs.length === 0 unconditionally, after gating runs). This is the ' +
|
|
292
|
+
'OPPOSITE of "always-on". If this is a deliberately disabled rule, consider removing the file instead; ' +
|
|
293
|
+
'otherwise populate globs:/paths: with real patterns.',
|
|
294
|
+
);
|
|
295
|
+
} else if (!hasAxis) {
|
|
296
|
+
warn(
|
|
297
|
+
`${rel} — handwritten rule has no activation axis (globs/paths/host-class/tier all absent) — loads ` +
|
|
298
|
+
'always-on in every context. Not a build failure yet (warn mode, #880); add a tier: or globs: axis ' +
|
|
299
|
+
'if this rule should be scoped.',
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (!hasReviewDate) {
|
|
304
|
+
warn(
|
|
305
|
+
`${rel} — handwritten rule is missing a review-date (no periodic-review marker). ` +
|
|
306
|
+
'See docs/rule-authoring.md § "Handwritten Rule Review Date (#880 FA5)".',
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (!hasEmptyGlobs && hasAxis && hasReviewDate) {
|
|
311
|
+
pass(`${rel} — handwritten rule has an activation axis and a review-date`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (handwrittenEntries.length === 0) {
|
|
316
|
+
// Deliberately NOT routed through pass() — this is bookkeeping, not an
|
|
317
|
+
// audited invariant, and must not inflate the `passed` count that
|
|
318
|
+
// auto-generated-only fixtures assert an exact value against.
|
|
319
|
+
console.log(' (no handwritten rules found — nothing to check)');
|
|
320
|
+
}
|
|
321
|
+
|
|
140
322
|
console.log('');
|
|
141
|
-
console.log(`Results: ${passed} passed, ${failed} failed`);
|
|
323
|
+
console.log(`Results: ${passed} passed, ${failed} failed, ${warned} warned`);
|
|
142
324
|
|
|
143
325
|
process.exit(failed > 0 ? 1 : 0);
|