@event4u/agent-config 1.23.0 → 1.25.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/.agent-src/commands/analyze-reference-repo.md +3 -0
- package/.agent-src/commands/review-routing.md +7 -10
- package/.agent-src/commands/roadmap/process-full.md +41 -1
- package/.agent-src/contexts/authority/kernel-rule-edits.md +48 -0
- package/.agent-src/contexts/authority/scope-mechanics.md +15 -0
- package/.agent-src/contexts/contracts/consumer-agents-md-guide.md +127 -0
- package/.agent-src/contexts/contracts/emergency-triage-block.md +53 -0
- package/.agent-src/contexts/execution/roadmap-process-loop.md +29 -6
- package/.agent-src/rules/analysis-skill-routing.md +1 -1
- package/.agent-src/rules/artifact-drafting-protocol.md +1 -1
- package/.agent-src/rules/artifact-engagement-recording.md +1 -1
- package/.agent-src/rules/augment-source-of-truth.md +1 -1
- package/.agent-src/rules/autonomous-execution.md +1 -1
- package/.agent-src/rules/caveman-speak.md +1 -1
- package/.agent-src/rules/cli-output-handling.md +1 -1
- package/.agent-src/rules/command-suggestion-policy.md +1 -1
- package/.agent-src/rules/docs-sync.md +1 -1
- package/.agent-src/rules/guidelines.md +1 -1
- package/.agent-src/rules/improve-before-implement.md +1 -1
- package/.agent-src/rules/invite-challenge.md +1 -1
- package/.agent-src/rules/minimal-safe-diff.md +1 -1
- package/.agent-src/rules/model-recommendation.md +1 -1
- package/.agent-src/rules/no-attribution-footers.md +1 -1
- package/.agent-src/rules/no-roadmap-references.md +56 -20
- package/.agent-src/rules/onboarding-gate.md +1 -1
- package/.agent-src/rules/package-ci-checks.md +1 -1
- package/.agent-src/rules/reviewer-awareness.md +9 -2
- package/.agent-src/rules/roadmap-progress-sync.md +37 -3
- package/.agent-src/rules/scope-control.md +6 -0
- package/.agent-src/rules/security-sensitive-stop.md +1 -1
- package/.agent-src/rules/size-enforcement.md +1 -1
- package/.agent-src/rules/token-optimizer-maintenance.md +1 -1
- package/.agent-src/rules/ui-audit-gate.md +1 -1
- package/.agent-src/skills/adr-create/SKILL.md +2 -1
- package/.agent-src/skills/agents-md-thin-root/SKILL.md +125 -0
- package/.agent-src/skills/ai-council/SKILL.md +9 -7
- package/.agent-src/skills/learning-to-rule-or-skill/SKILL.md +9 -0
- package/.agent-src/skills/markitdown/SKILL.md +239 -0
- package/.agent-src/skills/review-routing/SKILL.md +3 -4
- package/.agent-src/skills/universal-project-analysis/SKILL.md +8 -0
- package/.agent-src/templates/AGENTS.md +18 -148
- package/.agent-src/templates/copilot-instructions.md +41 -17
- package/.agent-src/templates/github-workflows/pr-risk-review.yml +1 -1
- package/.agent-src/templates/scripts/pr_review_routing.py +1 -1
- package/.claude-plugin/marketplace.json +7 -5
- package/AGENTS.md +18 -205
- package/CHANGELOG.md +70 -0
- package/README.md +2 -2
- package/docs/architecture.md +13 -7
- package/docs/catalog.md +45 -29
- package/docs/contracts/agents-md-tech-stack.md +74 -0
- package/docs/contracts/linear-ai-rules-inclusion.md +1 -1
- package/docs/contracts/package-self-orientation.md +135 -0
- package/docs/contracts/rule-classification.md +4 -4
- package/docs/decisions/ADR-004-rule-governance-pruning.md +240 -0
- package/docs/getting-started.md +1 -1
- package/docs/guidelines/agent-infra/review-routing-data-format.md +1 -2
- package/package.json +1 -1
- package/scripts/_p4_migrate.py +5 -5
- package/scripts/audit_auto_rules.py +159 -0
- package/scripts/audit_likelihood.py +148 -0
- package/scripts/audit_overlap.py +145 -0
- package/scripts/build_rule_trigger_matrix.py +3 -5
- package/scripts/check_augment_description_cap.py +79 -0
- package/scripts/check_council_references.py +3 -3
- package/scripts/check_kernel_rule_bundle.py +151 -0
- package/scripts/check_references.py +21 -1
- package/scripts/compile_router.py +3 -0
- package/scripts/install.sh +0 -1
- package/scripts/lint_agents_md.py +168 -0
- package/scripts/measure_augment_budget.py +208 -0
- package/scripts/measure_markitdown_lift.py +127 -0
- package/scripts/schemas/rule.schema.json +2 -1
- package/scripts/skill_linter.py +10 -4
- package/scripts/spotcheck_thin_root.py +134 -0
- package/scripts/update_counts.py +6 -10
- package/.agent-src/rules/no-council-references.md +0 -76
- package/.agent-src/rules/review-routing-awareness.md +0 -19
- package/.agent-src/templates/copilot-review-instructions.md +0 -76
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Trigger-overlap analysis for the Rule-Governance pass (Phase 5.2 of
|
|
3
|
+
road-to-augment-limit-fit).
|
|
4
|
+
|
|
5
|
+
Reads `agents/reports/auto-rules-audit.json` (produced by
|
|
6
|
+
`audit_auto_rules.py`) and computes:
|
|
7
|
+
|
|
8
|
+
- path-prefix Jaccard similarity (per pair of rules);
|
|
9
|
+
- description-keyword overlap fraction (per pair of rules).
|
|
10
|
+
|
|
11
|
+
Pairs scoring `path_jaccard >= 0.5` OR `keyword_overlap >= 0.4` are
|
|
12
|
+
flagged as merge candidates. Output is appended to
|
|
13
|
+
`agents/reports/auto-rules-audit.md` and a structured JSON list is
|
|
14
|
+
written to `agents/reports/auto-rules-overlap.json` for downstream
|
|
15
|
+
consumers (Phase 5.3 likelihood, 5.4 council walk).
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import json
|
|
21
|
+
import re
|
|
22
|
+
import sys
|
|
23
|
+
from itertools import combinations
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
|
|
26
|
+
REPO_ROOT = Path(__file__).resolve().parent.parent
|
|
27
|
+
REPORT_DIR = REPO_ROOT / "agents" / "reports"
|
|
28
|
+
AUDIT_JSON = REPORT_DIR / "auto-rules-audit.json"
|
|
29
|
+
AUDIT_MD = REPORT_DIR / "auto-rules-audit.md"
|
|
30
|
+
OVERLAP_JSON = REPORT_DIR / "auto-rules-overlap.json"
|
|
31
|
+
|
|
32
|
+
PATH_THRESHOLD = 0.5
|
|
33
|
+
KEYWORD_THRESHOLD = 0.4
|
|
34
|
+
|
|
35
|
+
STOPWORDS = {
|
|
36
|
+
"the", "and", "for", "with", "when", "use", "or", "of", "to", "a",
|
|
37
|
+
"an", "is", "in", "on", "by", "be", "at", "as", "it", "if", "are",
|
|
38
|
+
"this", "that", "from", "but", "not", "can", "any", "all", "no",
|
|
39
|
+
"after", "before", "during", "user", "agent", "code", "project",
|
|
40
|
+
"via", "into", "onto", "even", "without", "naming",
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def keyword_set(text: str) -> set[str]:
|
|
45
|
+
tokens = re.findall(r"[A-Za-z][A-Za-z0-9_-]{2,}", text.lower())
|
|
46
|
+
return {t for t in tokens if t not in STOPWORDS and not t.isdigit()}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def jaccard(a: set, b: set) -> float:
|
|
50
|
+
if not a and not b:
|
|
51
|
+
return 0.0
|
|
52
|
+
return len(a & b) / len(a | b)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def overlap_fraction(a: set, b: set) -> float:
|
|
56
|
+
"""Symmetric overlap as fraction of smaller set."""
|
|
57
|
+
if not a or not b:
|
|
58
|
+
return 0.0
|
|
59
|
+
return len(a & b) / min(len(a), len(b))
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def analyse(rules: list[dict]) -> list[dict]:
|
|
63
|
+
pairs: list[dict] = []
|
|
64
|
+
for r in rules:
|
|
65
|
+
r["_paths"] = set(r["triggers"]["path_prefixes"])
|
|
66
|
+
r["_keywords"] = (
|
|
67
|
+
keyword_set(r["description"])
|
|
68
|
+
| keyword_set(" ".join(r["triggers"]["keywords"]))
|
|
69
|
+
| keyword_set(" ".join(r["triggers"]["intents"]))
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
for a, b in combinations(rules, 2):
|
|
73
|
+
pj = jaccard(a["_paths"], b["_paths"])
|
|
74
|
+
ko = overlap_fraction(a["_keywords"], b["_keywords"])
|
|
75
|
+
flagged = pj >= PATH_THRESHOLD or ko >= KEYWORD_THRESHOLD
|
|
76
|
+
if not flagged:
|
|
77
|
+
continue
|
|
78
|
+
pairs.append(
|
|
79
|
+
{
|
|
80
|
+
"rule_a": a["name"],
|
|
81
|
+
"rule_b": b["name"],
|
|
82
|
+
"path_jaccard": round(pj, 3),
|
|
83
|
+
"keyword_overlap": round(ko, 3),
|
|
84
|
+
"shared_paths": sorted(a["_paths"] & b["_paths"]),
|
|
85
|
+
"shared_keywords": sorted(a["_keywords"] & b["_keywords"])[:12],
|
|
86
|
+
"rule_a_desc": a["description"],
|
|
87
|
+
"rule_b_desc": b["description"],
|
|
88
|
+
}
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
return sorted(
|
|
92
|
+
pairs, key=lambda p: -(p["path_jaccard"] + p["keyword_overlap"])
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def render_md(pairs: list[dict]) -> str:
|
|
97
|
+
lines = [
|
|
98
|
+
"",
|
|
99
|
+
"## Phase 5.2 — Trigger overlap (Jaccard + keyword)",
|
|
100
|
+
"",
|
|
101
|
+
f"Pairs flagged: **{len(pairs)}** "
|
|
102
|
+
f"(thresholds: path-Jaccard ≥ {PATH_THRESHOLD}, "
|
|
103
|
+
f"keyword-overlap ≥ {KEYWORD_THRESHOLD}).",
|
|
104
|
+
"",
|
|
105
|
+
]
|
|
106
|
+
if not pairs:
|
|
107
|
+
lines.append("_No pairs over threshold._")
|
|
108
|
+
lines.append("")
|
|
109
|
+
return "\n".join(lines)
|
|
110
|
+
lines += [
|
|
111
|
+
"| # | Rule A | Rule B | Path-J | Keyword-O | Shared keywords |",
|
|
112
|
+
"|---|--------|--------|--------|-----------|-----------------|",
|
|
113
|
+
]
|
|
114
|
+
for i, p in enumerate(pairs, 1):
|
|
115
|
+
kw = ", ".join(f"`{k}`" for k in p["shared_keywords"][:6]) or "—"
|
|
116
|
+
lines.append(
|
|
117
|
+
f"| {i} | `{p['rule_a']}` | `{p['rule_b']}` | "
|
|
118
|
+
f"{p['path_jaccard']:.2f} | {p['keyword_overlap']:.2f} | {kw} |"
|
|
119
|
+
)
|
|
120
|
+
lines.append("")
|
|
121
|
+
return "\n".join(lines)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def main() -> int:
|
|
125
|
+
if not AUDIT_JSON.exists():
|
|
126
|
+
print(f"❌ Run audit_auto_rules.py first: missing {AUDIT_JSON}", file=sys.stderr)
|
|
127
|
+
return 1
|
|
128
|
+
data = json.loads(AUDIT_JSON.read_text(encoding="utf-8"))
|
|
129
|
+
pairs = analyse(data["rules"])
|
|
130
|
+
OVERLAP_JSON.write_text(
|
|
131
|
+
json.dumps({"pair_count": len(pairs), "pairs": pairs}, indent=2),
|
|
132
|
+
encoding="utf-8",
|
|
133
|
+
)
|
|
134
|
+
md_existing = AUDIT_MD.read_text(encoding="utf-8") if AUDIT_MD.exists() else ""
|
|
135
|
+
if "## Phase 5.2 — Trigger overlap" in md_existing:
|
|
136
|
+
md_existing = md_existing.split("## Phase 5.2 — Trigger overlap")[0].rstrip() + "\n"
|
|
137
|
+
AUDIT_MD.write_text(md_existing + render_md(pairs), encoding="utf-8")
|
|
138
|
+
print(f"✅ Overlap analysis: {len(pairs)} pairs flagged.")
|
|
139
|
+
print(f" JSON: {OVERLAP_JSON.relative_to(REPO_ROOT)}")
|
|
140
|
+
print(f" MD appended: {AUDIT_MD.relative_to(REPO_ROOT)}")
|
|
141
|
+
return 0
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
if __name__ == "__main__":
|
|
145
|
+
sys.exit(main())
|
|
@@ -117,11 +117,9 @@ add("agent-docs.md", "file-edit on agents/docs/, AGENTS.md", "hook",
|
|
|
117
117
|
"tool-call", "medium", "2a", notes="Path-pattern based marker")
|
|
118
118
|
add("upstream-proposal.md", "skill/rule create event", "hook", "output",
|
|
119
119
|
"medium", "2a", notes="Marker after new artifact lands")
|
|
120
|
-
add("
|
|
121
|
-
"output", "medium", "2a",
|
|
122
|
-
notes="
|
|
123
|
-
add("reviewer-awareness.md", "PR-prep", "hook", "output",
|
|
124
|
-
"medium", "2a", notes="Reviewer-suggestion marker at PR creation")
|
|
120
|
+
add("reviewer-awareness.md", "PR-prep / reviewer-suggestion / risk flagging",
|
|
121
|
+
"hook", "output", "medium", "2a",
|
|
122
|
+
notes="Reviewer-suggestion + risk-tagging marker at PR creation; consolidates former review-routing-awareness")
|
|
125
123
|
add("security-sensitive-stop.md", "file-edit on auth/billing/secrets paths",
|
|
126
124
|
"hook", "tool-call", "low", "2a",
|
|
127
125
|
notes="Path-pattern based marker — strong candidate for low-cost hook")
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Auto-rule description-length CI gate (Phase 1.3 of
|
|
3
|
+
road-to-augment-limit-fit).
|
|
4
|
+
|
|
5
|
+
For every `type: auto` rule under `.agent-src.uncompressed/rules/`,
|
|
6
|
+
fail CI when the frontmatter `description:` exceeds DESC_CAP chars.
|
|
7
|
+
|
|
8
|
+
Why: Augment injects each auto-rule's description into the
|
|
9
|
+
workspace-guidelines registry stub. Empirical 2026-05-08 budget
|
|
10
|
+
analysis showed this channel consuming 25 % of the 49,512-char
|
|
11
|
+
ceiling. Capping descriptions guards future drift.
|
|
12
|
+
|
|
13
|
+
Source of truth: `.agent-src.uncompressed/rules/`. The compressed
|
|
14
|
+
projection is regenerated; the source dictates what ships.
|
|
15
|
+
|
|
16
|
+
Exit codes: 0 = pass, 1 = at least one rule over cap.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import re
|
|
22
|
+
import sys
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
|
|
25
|
+
REPO_ROOT = Path(__file__).resolve().parent.parent
|
|
26
|
+
RULES_DIR = REPO_ROOT / ".agent-src.uncompressed" / "rules"
|
|
27
|
+
DESC_CAP = 150
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def parse_frontmatter(text: str) -> dict[str, str]:
|
|
31
|
+
if not text.startswith("---\n"):
|
|
32
|
+
return {}
|
|
33
|
+
end = text.find("\n---", 4)
|
|
34
|
+
if end < 0:
|
|
35
|
+
return {}
|
|
36
|
+
fm: dict[str, str] = {}
|
|
37
|
+
for line in text[4:end].splitlines():
|
|
38
|
+
m = re.match(r"^([A-Za-z_][A-Za-z0-9_-]*):\s*(.*)$", line)
|
|
39
|
+
if m:
|
|
40
|
+
fm[m.group(1)] = m.group(2).strip().strip('"').strip("'")
|
|
41
|
+
return fm
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def main() -> int:
|
|
45
|
+
failures: list[tuple[str, int, str]] = []
|
|
46
|
+
checked = 0
|
|
47
|
+
|
|
48
|
+
for path in sorted(RULES_DIR.glob("*.md")):
|
|
49
|
+
text = path.read_text()
|
|
50
|
+
fm = parse_frontmatter(text)
|
|
51
|
+
if fm.get("type") != "auto":
|
|
52
|
+
continue
|
|
53
|
+
desc = fm.get("description", "")
|
|
54
|
+
checked += 1
|
|
55
|
+
if len(desc) > DESC_CAP:
|
|
56
|
+
failures.append((path.name, len(desc), desc))
|
|
57
|
+
|
|
58
|
+
if failures:
|
|
59
|
+
print(
|
|
60
|
+
f"❌ {len(failures)} auto-rule description(s) exceed {DESC_CAP} chars:\n",
|
|
61
|
+
file=sys.stderr,
|
|
62
|
+
)
|
|
63
|
+
for name, dlen, desc in sorted(failures, key=lambda x: -x[1]):
|
|
64
|
+
print(f" [{dlen:>3}] {name}", file=sys.stderr)
|
|
65
|
+
print(f" {desc}", file=sys.stderr)
|
|
66
|
+
print(
|
|
67
|
+
f"\n Guard rationale: each char in an auto-rule description "
|
|
68
|
+
f"costs one char in the\n Augment workspace-guidelines budget "
|
|
69
|
+
f"(cap 49,512). Trim to ≤ {DESC_CAP}.",
|
|
70
|
+
file=sys.stderr,
|
|
71
|
+
)
|
|
72
|
+
return 1
|
|
73
|
+
|
|
74
|
+
print(f"✅ All {checked} auto-rule descriptions ≤ {DESC_CAP} chars.")
|
|
75
|
+
return 0
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if __name__ == "__main__":
|
|
79
|
+
sys.exit(main())
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
"""CI guard for the `no-
|
|
2
|
+
"""CI guard for the council clause of the `no-roadmap-references` rule.
|
|
3
3
|
|
|
4
4
|
Council artefacts under `agents/council-{questions,responses,sessions}/`
|
|
5
5
|
are gitignored, local-only, and auto-pruned. A link to a specific
|
|
@@ -68,7 +68,7 @@ ALLOWLIST_PREFIXES: tuple[str, ...] = (
|
|
|
68
68
|
# the SKIP_DIRS contract in scripts/check_references.py).
|
|
69
69
|
"agents/analysis/",
|
|
70
70
|
# The rule itself documents forbidden vs. allowed forms.
|
|
71
|
-
".agent-src.uncompressed/rules/no-
|
|
71
|
+
".agent-src.uncompressed/rules/no-roadmap-references.md",
|
|
72
72
|
# ai-council skill documents the output-path schema.
|
|
73
73
|
".agent-src.uncompressed/skills/ai-council/",
|
|
74
74
|
# Council commands document the output-path schema.
|
|
@@ -134,7 +134,7 @@ def main() -> int:
|
|
|
134
134
|
for path, ln, ref in violations:
|
|
135
135
|
print(f" - {path.as_posix()}:{ln}: {ref}")
|
|
136
136
|
print(
|
|
137
|
-
"\nRule: .agent-src/rules/no-
|
|
137
|
+
"\nRule: .agent-src/rules/no-roadmap-references.md (council clause)\n"
|
|
138
138
|
"Fix: inline the convergence summary (members + date) instead of\n"
|
|
139
139
|
"linking the file. Append "
|
|
140
140
|
"<!-- council-ref-allowed: <reason> --> on the same line to\n"
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""check_kernel_rule_bundle — Phase 4.2 of road-to-always-budget-relief.
|
|
3
|
+
|
|
4
|
+
Fails when a single PR (or commit range) modifies more than one
|
|
5
|
+
kernel rule under `.agent-src.uncompressed/rules/`. Override via the
|
|
6
|
+
PR label `bundled-always-rules-acknowledged`.
|
|
7
|
+
|
|
8
|
+
Kernel set is the locked 9-rule list in
|
|
9
|
+
`docs/contracts/rule-classification.md` § 3.1, mirrored as
|
|
10
|
+
`KERNEL_RULES` below. The list is short and stable; on kernel-set
|
|
11
|
+
change, update both files in the same PR.
|
|
12
|
+
|
|
13
|
+
Inputs:
|
|
14
|
+
--base-ref REF git ref to diff against (default: origin/main, then main)
|
|
15
|
+
--label NAME PR label that overrides the gate (default:
|
|
16
|
+
bundled-always-rules-acknowledged)
|
|
17
|
+
--event-path P GitHub event JSON (defaults to $GITHUB_EVENT_PATH)
|
|
18
|
+
--files F [F …] override changed-file list (testing only)
|
|
19
|
+
|
|
20
|
+
Exit codes: 0 = pass · 1 = fail (> 1 kernel rule, no override) ·
|
|
21
|
+
3 = internal error.
|
|
22
|
+
|
|
23
|
+
Source: `agents/contexts/adr-always-budget-relief-strategy.md`.
|
|
24
|
+
"""
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
import argparse
|
|
28
|
+
import json
|
|
29
|
+
import os
|
|
30
|
+
import subprocess
|
|
31
|
+
import sys
|
|
32
|
+
from pathlib import Path
|
|
33
|
+
|
|
34
|
+
KERNEL_RULES = frozenset({
|
|
35
|
+
"agent-authority.md",
|
|
36
|
+
"ask-when-uncertain.md",
|
|
37
|
+
"commit-policy.md",
|
|
38
|
+
"direct-answers.md",
|
|
39
|
+
"language-and-tone.md",
|
|
40
|
+
"no-cheap-questions.md",
|
|
41
|
+
"non-destructive-by-default.md",
|
|
42
|
+
"scope-control.md",
|
|
43
|
+
"verify-before-complete.md",
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
KERNEL_DIR = ".agent-src.uncompressed/rules"
|
|
47
|
+
DEFAULT_LABEL = "bundled-always-rules-acknowledged"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _git_changed_files(base_ref: str) -> list[str]:
|
|
51
|
+
try:
|
|
52
|
+
out = subprocess.check_output(
|
|
53
|
+
["git", "diff", "--name-only", f"{base_ref}...HEAD"],
|
|
54
|
+
stderr=subprocess.STDOUT,
|
|
55
|
+
text=True,
|
|
56
|
+
)
|
|
57
|
+
except subprocess.CalledProcessError as exc:
|
|
58
|
+
print(f"❌ git diff failed: {exc.output.strip()}", file=sys.stderr)
|
|
59
|
+
return []
|
|
60
|
+
return [line for line in out.splitlines() if line.strip()]
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _resolve_base_ref(explicit: str | None) -> str:
|
|
64
|
+
if explicit:
|
|
65
|
+
return explicit
|
|
66
|
+
for candidate in ("origin/main", "origin/master", "main", "master"):
|
|
67
|
+
try:
|
|
68
|
+
subprocess.check_output(
|
|
69
|
+
["git", "rev-parse", "--verify", candidate],
|
|
70
|
+
stderr=subprocess.DEVNULL,
|
|
71
|
+
)
|
|
72
|
+
return candidate
|
|
73
|
+
except subprocess.CalledProcessError:
|
|
74
|
+
continue
|
|
75
|
+
return "HEAD~1"
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _pr_labels(event_path: str | None) -> list[str]:
|
|
79
|
+
path = event_path or os.environ.get("GITHUB_EVENT_PATH")
|
|
80
|
+
if not path or not Path(path).exists():
|
|
81
|
+
return []
|
|
82
|
+
try:
|
|
83
|
+
data = json.loads(Path(path).read_text(encoding="utf-8"))
|
|
84
|
+
except (OSError, json.JSONDecodeError):
|
|
85
|
+
return []
|
|
86
|
+
pr = data.get("pull_request") or {}
|
|
87
|
+
return [lbl.get("name", "") for lbl in pr.get("labels", []) if lbl.get("name")]
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _kernel_changes(files: list[str]) -> list[str]:
|
|
91
|
+
hits: list[str] = []
|
|
92
|
+
for path in files:
|
|
93
|
+
if not path.startswith(f"{KERNEL_DIR}/"):
|
|
94
|
+
continue
|
|
95
|
+
name = Path(path).name
|
|
96
|
+
if name in KERNEL_RULES:
|
|
97
|
+
hits.append(path)
|
|
98
|
+
return sorted(set(hits))
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def main(argv: list[str] | None = None) -> int:
|
|
102
|
+
ap = argparse.ArgumentParser(description=__doc__.split("\n", 1)[0])
|
|
103
|
+
ap.add_argument("--base-ref", default=None)
|
|
104
|
+
ap.add_argument("--label", default=DEFAULT_LABEL)
|
|
105
|
+
ap.add_argument("--event-path", default=None)
|
|
106
|
+
ap.add_argument("--files", nargs="*", default=None)
|
|
107
|
+
args = ap.parse_args(argv)
|
|
108
|
+
|
|
109
|
+
files = args.files or _git_changed_files(_resolve_base_ref(args.base_ref))
|
|
110
|
+
hits = _kernel_changes(files)
|
|
111
|
+
|
|
112
|
+
if len(hits) <= 1:
|
|
113
|
+
if hits:
|
|
114
|
+
print(f"✅ OK kernel-rule bundle: 1 rule touched ({hits[0]})")
|
|
115
|
+
else:
|
|
116
|
+
print("✅ OK kernel-rule bundle: no kernel rule touched")
|
|
117
|
+
return 0
|
|
118
|
+
|
|
119
|
+
labels = _pr_labels(args.event_path)
|
|
120
|
+
if args.label in labels:
|
|
121
|
+
print(
|
|
122
|
+
f"✅ OK kernel-rule bundle: {len(hits)} rules touched but "
|
|
123
|
+
f"label '{args.label}' present"
|
|
124
|
+
)
|
|
125
|
+
for h in hits:
|
|
126
|
+
print(f" · {h}")
|
|
127
|
+
return 0
|
|
128
|
+
|
|
129
|
+
print(
|
|
130
|
+
f"❌ FAIL kernel-rule bundle: {len(hits)} kernel rules touched in "
|
|
131
|
+
f"one PR — slow-rollout requires one-rule-per-PR.",
|
|
132
|
+
file=sys.stderr,
|
|
133
|
+
)
|
|
134
|
+
print(" Touched:", file=sys.stderr)
|
|
135
|
+
for h in hits:
|
|
136
|
+
print(f" · {h}", file=sys.stderr)
|
|
137
|
+
print(
|
|
138
|
+
f" Override: add the label '{args.label}' on the PR and "
|
|
139
|
+
f"document the bundle rationale in the PR body.",
|
|
140
|
+
file=sys.stderr,
|
|
141
|
+
)
|
|
142
|
+
print(
|
|
143
|
+
" Source: agents/contexts/adr-always-budget-relief-strategy.md "
|
|
144
|
+
"(Phase 4.2).",
|
|
145
|
+
file=sys.stderr,
|
|
146
|
+
)
|
|
147
|
+
return 1
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
if __name__ == "__main__":
|
|
151
|
+
sys.exit(main())
|
|
@@ -228,6 +228,10 @@ def check_file(filepath: Path, artifacts: dict[str, set[str]], root: Path) -> Li
|
|
|
228
228
|
))
|
|
229
229
|
|
|
230
230
|
in_code_block = False
|
|
231
|
+
# Track whether we are inside an unchecked-TODO bullet (multi-line
|
|
232
|
+
# roadmap items wrap continuation text under the `- [ ]` line and
|
|
233
|
+
# those continuation lines must inherit the forward-ref exemption).
|
|
234
|
+
in_unchecked_todo = False
|
|
231
235
|
for i, line in enumerate(text.splitlines(), 1):
|
|
232
236
|
stripped = line.strip()
|
|
233
237
|
if stripped.startswith("```"):
|
|
@@ -237,9 +241,25 @@ def check_file(filepath: Path, artifacts: dict[str, set[str]], root: Path) -> Li
|
|
|
237
241
|
continue
|
|
238
242
|
|
|
239
243
|
# Unchecked TODO checkboxes document future work — their refs are
|
|
240
|
-
# forward-looking and will not resolve yet.
|
|
244
|
+
# forward-looking and will not resolve yet. Track multi-line bullets:
|
|
245
|
+
# any `- [ ]` opens a TODO context; a new top-level bullet, heading,
|
|
246
|
+
# or blank line closes it.
|
|
241
247
|
if UNCHECKED_TODO_PATTERN.match(line):
|
|
248
|
+
in_unchecked_todo = True
|
|
242
249
|
continue
|
|
250
|
+
if in_unchecked_todo:
|
|
251
|
+
if not stripped:
|
|
252
|
+
in_unchecked_todo = False
|
|
253
|
+
continue
|
|
254
|
+
# A new bullet (checked or unchecked) or a heading closes the
|
|
255
|
+
# current TODO context. An indented continuation line keeps it.
|
|
256
|
+
if re.match(r"^[-*+]\s+\[", line) or stripped.startswith("#"):
|
|
257
|
+
in_unchecked_todo = False
|
|
258
|
+
elif line[:1] in (" ", "\t"):
|
|
259
|
+
# Indented continuation of the unchecked TODO — skip.
|
|
260
|
+
continue
|
|
261
|
+
else:
|
|
262
|
+
in_unchecked_todo = False
|
|
243
263
|
|
|
244
264
|
# File path references
|
|
245
265
|
for m in PATH_PATTERN.finditer(line):
|
|
@@ -125,6 +125,9 @@ def _collect(rules_dir: Path) -> dict:
|
|
|
125
125
|
if not COMPILE_TIME_TOGGLES[rule_id](settings):
|
|
126
126
|
continue
|
|
127
127
|
rule_type = str(fm.get("type", "auto"))
|
|
128
|
+
# Manual rules are reference-only (ADR-004) — no router emission.
|
|
129
|
+
if rule_type == "manual":
|
|
130
|
+
continue
|
|
128
131
|
tier = _resolve_tier(rule_type, fm.get("tier", ""))
|
|
129
132
|
if tier not in ALLOWED_TIERS:
|
|
130
133
|
continue
|
package/scripts/install.sh
CHANGED
|
@@ -728,7 +728,6 @@ main() {
|
|
|
728
728
|
# into consumer projects.
|
|
729
729
|
copy_if_missing "$SOURCE_PAYLOAD/templates/AGENTS.md" "$TARGET_DIR/AGENTS.md"
|
|
730
730
|
copy_if_missing "$SOURCE_PAYLOAD/templates/copilot-instructions.md" "$TARGET_DIR/.github/copilot-instructions.md"
|
|
731
|
-
copy_if_missing "$SOURCE_PAYLOAD/templates/copilot-review-instructions.md" "$TARGET_DIR/.github/copilot-review-instructions.md"
|
|
732
731
|
|
|
733
732
|
# 3. Create tool-specific symlinks
|
|
734
733
|
create_tool_symlinks "$TARGET_DIR"
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Thin-Root contract linter for AGENTS.md files (Phase 7).
|
|
3
|
+
|
|
4
|
+
Enforces caps + pointer-ratio + pointer-anatomy + emergency-triage
|
|
5
|
+
contract from `.agent-src.uncompressed/skills/agents-md-thin-root/SKILL.md`:
|
|
6
|
+
|
|
7
|
+
(a) total char-count under FAIL/WARN budgets per file class
|
|
8
|
+
(b) substantive-pointer ratio >= 0.40
|
|
9
|
+
(c) every pointer's *why* clause >= 60 chars
|
|
10
|
+
(d) every pointer target resolves on disk (anchor validity)
|
|
11
|
+
(e) emergency-triage section present with the five canonical questions
|
|
12
|
+
|
|
13
|
+
Exit non-zero on any (a) FAIL, (b)–(e) error. WARN is informational.
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import re
|
|
18
|
+
import sys
|
|
19
|
+
from dataclasses import dataclass
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
|
|
22
|
+
ROOT = Path(__file__).resolve().parent.parent
|
|
23
|
+
QUIET = "--quiet" in sys.argv
|
|
24
|
+
|
|
25
|
+
LINK_RE = re.compile(r"\[([^\]]+)\]\(([^)]+)\)")
|
|
26
|
+
TRIAGE_KEYWORDS = (
|
|
27
|
+
"what is this repo",
|
|
28
|
+
"what language",
|
|
29
|
+
"where do i edit",
|
|
30
|
+
"lint / test / sync",
|
|
31
|
+
"where do the always",
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass
|
|
36
|
+
class Target:
|
|
37
|
+
path: Path
|
|
38
|
+
label: str
|
|
39
|
+
fail_at: int
|
|
40
|
+
warn_at: int
|
|
41
|
+
template: bool # consumer template — relax pointer-target resolution
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
TARGETS = [
|
|
45
|
+
Target(ROOT / "AGENTS.md", "package-root", 3000, 2800, template=False),
|
|
46
|
+
Target(
|
|
47
|
+
ROOT / ".agent-src.uncompressed" / "templates" / "AGENTS.md",
|
|
48
|
+
"consumer-template", 2500, 2300, template=True,
|
|
49
|
+
),
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _strip_links(line: str) -> str:
|
|
54
|
+
return LINK_RE.sub(lambda m: m.group(1), line)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _resolve(target_str: str, template: bool) -> bool:
|
|
58
|
+
raw = target_str.split("#", 1)[0].strip()
|
|
59
|
+
if raw.startswith("http://") or raw.startswith("https://"):
|
|
60
|
+
return True
|
|
61
|
+
candidates = [ROOT / raw]
|
|
62
|
+
if template and raw.startswith(".augment/"):
|
|
63
|
+
candidates.append(ROOT / raw.replace(".augment/", ".agent-src.uncompressed/", 1))
|
|
64
|
+
candidates.append(ROOT / raw.replace(".augment/", ".agent-src/", 1))
|
|
65
|
+
if raw.startswith(".agent-src/"):
|
|
66
|
+
candidates.append(ROOT / raw.replace(".agent-src/", ".agent-src.uncompressed/", 1))
|
|
67
|
+
return any(c.exists() for c in candidates)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def lint_file(t: Target) -> tuple[bool, list[str], list[str]]:
|
|
71
|
+
"""Return (ok, errors, warnings)."""
|
|
72
|
+
errors: list[str] = []
|
|
73
|
+
warnings: list[str] = []
|
|
74
|
+
if not t.path.exists():
|
|
75
|
+
return False, [f"{t.label}: {t.path} not found"], []
|
|
76
|
+
|
|
77
|
+
text = t.path.read_text(encoding="utf-8")
|
|
78
|
+
size = len(text.encode("utf-8"))
|
|
79
|
+
|
|
80
|
+
# (a) size
|
|
81
|
+
if size > t.fail_at:
|
|
82
|
+
errors.append(f"{t.label}: {size} chars > FAIL cap {t.fail_at}")
|
|
83
|
+
elif size > t.warn_at:
|
|
84
|
+
warnings.append(f"{t.label}: {size} chars > WARN cap {t.warn_at}")
|
|
85
|
+
|
|
86
|
+
# Filter out structural lines that are not "prose" the contract
|
|
87
|
+
# asks us to replace with pointers: headings, code fences + content,
|
|
88
|
+
# HTML comments, and Markdown table rows.
|
|
89
|
+
lines = text.splitlines()
|
|
90
|
+
in_fence = False
|
|
91
|
+
in_comment = False
|
|
92
|
+
prose: list[str] = []
|
|
93
|
+
for ln in lines:
|
|
94
|
+
s = ln.strip()
|
|
95
|
+
if not s:
|
|
96
|
+
continue
|
|
97
|
+
if s.startswith("```"):
|
|
98
|
+
in_fence = not in_fence
|
|
99
|
+
continue
|
|
100
|
+
if in_fence:
|
|
101
|
+
continue
|
|
102
|
+
if "<!--" in s:
|
|
103
|
+
in_comment = True
|
|
104
|
+
if in_comment:
|
|
105
|
+
if "-->" in s:
|
|
106
|
+
in_comment = False
|
|
107
|
+
continue
|
|
108
|
+
if s.startswith("#"): # heading
|
|
109
|
+
continue
|
|
110
|
+
if s.startswith("|"): # markdown table row / separator
|
|
111
|
+
continue
|
|
112
|
+
prose.append(ln)
|
|
113
|
+
|
|
114
|
+
non_blank = prose
|
|
115
|
+
pointer_lines = 0
|
|
116
|
+
|
|
117
|
+
for ln in non_blank:
|
|
118
|
+
m = LINK_RE.search(ln)
|
|
119
|
+
if not m:
|
|
120
|
+
continue
|
|
121
|
+
target = m.group(2)
|
|
122
|
+
# (d) target resolves
|
|
123
|
+
if not _resolve(target, t.template):
|
|
124
|
+
errors.append(f"{t.label}: broken pointer target `{target}` in line: {ln.strip()[:100]}")
|
|
125
|
+
# (c) why-clause length: line minus link syntax
|
|
126
|
+
why = _strip_links(ln).strip()
|
|
127
|
+
if len(why) >= 60:
|
|
128
|
+
pointer_lines += 1
|
|
129
|
+
# else line has a link but no real why-clause — does not count
|
|
130
|
+
|
|
131
|
+
# (b) ratio
|
|
132
|
+
ratio = pointer_lines / max(len(non_blank), 1)
|
|
133
|
+
if ratio < 0.40:
|
|
134
|
+
errors.append(
|
|
135
|
+
f"{t.label}: substantive-pointer ratio {ratio:.2f} < 0.40 "
|
|
136
|
+
f"({pointer_lines}/{len(non_blank)} non-blank lines)"
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
# (e) emergency-triage block
|
|
140
|
+
lower = text.lower()
|
|
141
|
+
missing = [k for k in TRIAGE_KEYWORDS if k not in lower]
|
|
142
|
+
if missing:
|
|
143
|
+
errors.append(f"{t.label}: emergency-triage block missing keywords: {missing}")
|
|
144
|
+
if "emergency triage" not in lower:
|
|
145
|
+
errors.append(f"{t.label}: missing 'Emergency triage' section heading")
|
|
146
|
+
|
|
147
|
+
return not errors, errors, warnings
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def main() -> int:
|
|
151
|
+
rc = 0
|
|
152
|
+
for t in TARGETS:
|
|
153
|
+
ok, errors, warnings = lint_file(t)
|
|
154
|
+
if not QUIET or errors or warnings:
|
|
155
|
+
print(f"== {t.label} ({t.path.relative_to(ROOT)}) ==")
|
|
156
|
+
for w in warnings:
|
|
157
|
+
print(f" ⚠️ {w}")
|
|
158
|
+
for e in errors:
|
|
159
|
+
print(f" ❌ {e}")
|
|
160
|
+
if ok and not warnings and not QUIET:
|
|
161
|
+
print(f" ✅ ok ({t.path.stat().st_size} bytes)")
|
|
162
|
+
if not ok:
|
|
163
|
+
rc = 1
|
|
164
|
+
return rc
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
if __name__ == "__main__":
|
|
168
|
+
raise SystemExit(main())
|