@event4u/agent-config 1.18.0 → 1.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/.agent-src/commands/council/default.md +74 -76
- package/.agent-src/commands/feature/roadmap.md +22 -0
- package/.agent-src/commands/roadmap/create.md +38 -6
- package/.agent-src/commands/roadmap/execute.md +36 -9
- package/.agent-src/rules/agent-authority.md +1 -0
- package/.agent-src/rules/agent-docs.md +1 -0
- package/.agent-src/rules/analysis-skill-routing.md +1 -0
- package/.agent-src/rules/architecture.md +1 -0
- package/.agent-src/rules/artifact-drafting-protocol.md +1 -0
- package/.agent-src/rules/artifact-engagement-recording.md +1 -0
- package/.agent-src/rules/ask-when-uncertain.md +1 -0
- package/.agent-src/rules/augment-portability.md +1 -0
- package/.agent-src/rules/augment-source-of-truth.md +1 -0
- package/.agent-src/rules/autonomous-execution.md +1 -0
- package/.agent-src/rules/capture-learnings.md +1 -0
- package/.agent-src/rules/chat-history-cadence.md +34 -0
- package/.agent-src/rules/chat-history-ownership.md +1 -0
- package/.agent-src/rules/chat-history-visibility.md +1 -0
- package/.agent-src/rules/cli-output-handling.md +2 -2
- package/.agent-src/rules/command-suggestion-policy.md +1 -0
- package/.agent-src/rules/commit-conventions.md +1 -0
- package/.agent-src/rules/commit-policy.md +1 -0
- package/.agent-src/rules/context-hygiene.md +22 -0
- package/.agent-src/rules/direct-answers.md +1 -0
- package/.agent-src/rules/docker-commands.md +1 -0
- package/.agent-src/rules/docs-sync.md +1 -0
- package/.agent-src/rules/downstream-changes.md +1 -0
- package/.agent-src/rules/e2e-testing.md +1 -0
- package/.agent-src/rules/guidelines.md +1 -0
- package/.agent-src/rules/improve-before-implement.md +1 -0
- package/.agent-src/rules/language-and-tone.md +1 -0
- package/.agent-src/rules/laravel-translations.md +1 -0
- package/.agent-src/rules/markdown-safe-codeblocks.md +1 -0
- package/.agent-src/rules/minimal-safe-diff.md +1 -0
- package/.agent-src/rules/missing-tool-handling.md +1 -0
- package/.agent-src/rules/model-recommendation.md +1 -0
- package/.agent-src/rules/no-cheap-questions.md +1 -0
- package/.agent-src/rules/no-roadmap-references.md +1 -0
- package/.agent-src/rules/non-destructive-by-default.md +1 -0
- package/.agent-src/rules/onboarding-gate.md +26 -0
- package/.agent-src/rules/package-ci-checks.md +1 -0
- package/.agent-src/rules/php-coding.md +1 -0
- package/.agent-src/rules/preservation-guard.md +1 -0
- package/.agent-src/rules/review-routing-awareness.md +1 -0
- package/.agent-src/rules/reviewer-awareness.md +1 -0
- package/.agent-src/rules/roadmap-progress-sync.md +22 -0
- package/.agent-src/rules/role-mode-adherence.md +2 -2
- package/.agent-src/rules/rule-type-governance.md +1 -0
- package/.agent-src/rules/runtime-safety.md +1 -0
- package/.agent-src/rules/scope-control.md +1 -0
- package/.agent-src/rules/security-sensitive-stop.md +1 -0
- package/.agent-src/rules/size-enforcement.md +1 -0
- package/.agent-src/rules/skill-improvement-trigger.md +1 -0
- package/.agent-src/rules/skill-quality.md +1 -0
- package/.agent-src/rules/slash-command-routing-policy.md +39 -0
- package/.agent-src/rules/think-before-action.md +1 -0
- package/.agent-src/rules/token-efficiency.md +1 -0
- package/.agent-src/rules/tool-safety.md +1 -0
- package/.agent-src/rules/ui-audit-gate.md +1 -0
- package/.agent-src/rules/upstream-proposal.md +1 -0
- package/.agent-src/rules/user-interaction.md +1 -0
- package/.agent-src/rules/verify-before-complete.md +1 -0
- package/.agent-src/skills/roadmap-management/SKILL.md +29 -4
- package/.agent-src/skills/verify-completion-evidence/SKILL.md +8 -1
- package/.agent-src/templates/agent-settings.md +16 -0
- package/.agent-src/templates/roadmaps.md +8 -3
- package/.agent-src/templates/scripts/work_engine/hook_bootstrap.py +9 -0
- package/.agent-src/templates/scripts/work_engine/hooks/__init__.py +4 -0
- package/.agent-src/templates/scripts/work_engine/hooks/builtin/__init__.py +4 -0
- package/.agent-src/templates/scripts/work_engine/hooks/builtin/decision_trace.py +163 -0
- package/.agent-src/templates/scripts/work_engine/hooks/builtin/memory_visibility.py +111 -0
- package/.agent-src/templates/scripts/work_engine/hooks/settings.py +36 -0
- package/.agent-src/templates/scripts/work_engine/scoring/decision_trace.py +141 -0
- package/.agent-src/templates/scripts/work_engine/scoring/memory_visibility.py +125 -0
- package/.claude-plugin/marketplace.json +1 -1
- package/CHANGELOG.md +62 -0
- package/README.md +19 -19
- package/config/agent-settings.template.yml +23 -0
- package/docs/catalog.md +5 -2
- package/docs/contracts/adr-settings-sync-engine.md +127 -0
- package/docs/contracts/decision-trace-v1.md +146 -0
- package/docs/contracts/file-ownership-matrix.json +7 -0
- package/docs/contracts/hook-architecture-v1.md +213 -0
- package/docs/contracts/memory-visibility-v1.md +138 -0
- package/docs/contracts/one-off-script-lifecycle.md +109 -0
- package/docs/contracts/rule-interactions.yml +22 -0
- package/docs/customization.md +1 -0
- package/docs/development.md +4 -1
- package/docs/guidelines/agent-infra/layered-settings.md +32 -13
- package/package.json +1 -1
- package/scripts/agent-config +44 -0
- package/scripts/ai_council/bundler.py +3 -3
- package/scripts/ai_council/clients.py +24 -8
- package/scripts/ai_council/one_off_archive/2026-05/README.md +22 -0
- package/scripts/ai_council/one_off_archive/2026-05/_one_off_roundtrip.py +13 -8
- package/scripts/ai_council/one_off_archive/2026-05/_one_off_tier_retrofit.py +180 -0
- package/scripts/ai_council/session.py +92 -0
- package/scripts/capture_showcase_session.py +361 -0
- package/scripts/chat_history.py +11 -1
- package/scripts/check_always_budget.py +7 -2
- package/scripts/context_hygiene_hook.py +14 -6
- package/scripts/council_cli.py +357 -0
- package/scripts/hook_manifest.yaml +184 -0
- package/scripts/hooks/__init__.py +1 -0
- package/scripts/hooks/augment-dispatcher.sh +72 -0
- package/scripts/hooks/cline-dispatcher.sh +86 -0
- package/scripts/hooks/cursor-dispatcher.sh +76 -0
- package/scripts/hooks/dispatch_hook.py +348 -0
- package/scripts/hooks/envelope.py +98 -0
- package/scripts/hooks/gemini-dispatcher.sh +117 -0
- package/scripts/hooks/state_io.py +122 -0
- package/scripts/hooks/windsurf-dispatcher.sh +123 -0
- package/scripts/hooks_status.py +146 -0
- package/scripts/install.py +725 -87
- package/scripts/install.sh +1 -1
- package/scripts/lint_hook_manifest.py +216 -0
- package/scripts/lint_one_off_age.py +184 -0
- package/scripts/lint_rule_tiers.py +78 -0
- package/scripts/lint_showcase_sessions.py +148 -0
- package/scripts/minimal_safe_diff_hook.py +245 -0
- package/scripts/onboarding_gate_hook.py +13 -8
- package/scripts/readme_linter.py +12 -3
- package/scripts/roadmap_progress_hook.py +5 -0
- package/scripts/sync_agent_settings.py +32 -129
- package/scripts/sync_yaml_rt.py +734 -0
- package/scripts/verify_before_complete_hook.py +216 -0
package/scripts/install.sh
CHANGED
|
@@ -344,7 +344,7 @@ clean_stale() {
|
|
|
344
344
|
log_verbose "preserve: $entry"
|
|
345
345
|
continue
|
|
346
346
|
fi
|
|
347
|
-
if is_excluded_rule "$entry" || !
|
|
347
|
+
if is_excluded_rule "$entry" || ! grep -qxF -- "$entry" <<<"$source_manifest"; then
|
|
348
348
|
local path="$target_dir/$entry"
|
|
349
349
|
if $DRY_RUN; then
|
|
350
350
|
log_verbose "remove stale: $entry"
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Lint `scripts/hook_manifest.yaml`.
|
|
3
|
+
|
|
4
|
+
CI gate per roadmap step 7.10. Hard-fails on:
|
|
5
|
+
|
|
6
|
+
- missing or malformed top-level keys (`schema_version`, `concerns`,
|
|
7
|
+
`platforms`)
|
|
8
|
+
- a concern entry referencing a non-existent script file
|
|
9
|
+
- a platform binding referencing an unknown concern name
|
|
10
|
+
- a platform binding referencing an unknown event (outside the
|
|
11
|
+
vocabulary in `docs/contracts/hook-architecture-v1.md`)
|
|
12
|
+
- a `native_event_aliases` block referencing an unknown agent-config
|
|
13
|
+
event or an unknown platform
|
|
14
|
+
- a `scripts/hooks/<platform>-dispatcher.sh` trampoline that exists on
|
|
15
|
+
disk without a corresponding non-empty platform block in the
|
|
16
|
+
manifest (orphan trampoline)
|
|
17
|
+
|
|
18
|
+
Soft-warns on:
|
|
19
|
+
|
|
20
|
+
- platform blocks set to `null` / empty (Phase 7.5–7.8 placeholders)
|
|
21
|
+
- concerns declared but not bound to any platform (dead concern)
|
|
22
|
+
|
|
23
|
+
Exit codes:
|
|
24
|
+
0 — clean (warnings allowed)
|
|
25
|
+
1 — at least one hard failure
|
|
26
|
+
2 — file or schema-load error
|
|
27
|
+
|
|
28
|
+
Invocation:
|
|
29
|
+
|
|
30
|
+
python3 scripts/lint_hook_manifest.py [--manifest PATH] [--strict]
|
|
31
|
+
|
|
32
|
+
`--strict` upgrades warnings to errors. Wired into `task ci` via the
|
|
33
|
+
`lint-hook-manifest` task.
|
|
34
|
+
"""
|
|
35
|
+
from __future__ import annotations
|
|
36
|
+
|
|
37
|
+
import argparse
|
|
38
|
+
import sys
|
|
39
|
+
from pathlib import Path
|
|
40
|
+
|
|
41
|
+
REPO_ROOT = Path(__file__).resolve().parent.parent
|
|
42
|
+
DEFAULT_MANIFEST = REPO_ROOT / "scripts" / "hook_manifest.yaml"
|
|
43
|
+
HOOKS_DIR = REPO_ROOT / "scripts" / "hooks"
|
|
44
|
+
|
|
45
|
+
# Canonical event vocabulary — keep in lock-step with
|
|
46
|
+
# docs/contracts/hook-architecture-v1.md and dispatch_hook.EVENT_VOCABULARY.
|
|
47
|
+
# `agent_error` added in Round 2 (2026-05-04) — synthetic event the
|
|
48
|
+
# wrapper fires on host crashes outside a concern.
|
|
49
|
+
EVENT_VOCABULARY: set[str] = {
|
|
50
|
+
"session_start", "session_end",
|
|
51
|
+
"user_prompt_submit",
|
|
52
|
+
"pre_tool_use", "post_tool_use",
|
|
53
|
+
"stop", "pre_compact",
|
|
54
|
+
"agent_error",
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
# Known platform identifiers. New platforms MUST be added here as they
|
|
58
|
+
# land — the linter is the gate that proves no orphan slot escapes.
|
|
59
|
+
KNOWN_PLATFORMS: set[str] = {
|
|
60
|
+
"augment", "claude", "cursor", "cline", "windsurf", "gemini", "copilot",
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _load_manifest(path: Path) -> dict:
|
|
65
|
+
"""Reuse the dispatcher's loader so the linter sees exactly what
|
|
66
|
+
the runtime sees — including the fallback parser when PyYAML is
|
|
67
|
+
not installed."""
|
|
68
|
+
sys.path.insert(0, str(REPO_ROOT / "scripts"))
|
|
69
|
+
from hooks.dispatch_hook import _load_yaml # noqa: E402
|
|
70
|
+
return _load_yaml(path)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _check_concerns(manifest: dict, errors: list[str]) -> set[str]:
|
|
74
|
+
concerns = manifest.get("concerns") or {}
|
|
75
|
+
if not isinstance(concerns, dict) or not concerns:
|
|
76
|
+
errors.append("manifest: 'concerns' must be a non-empty mapping")
|
|
77
|
+
return set()
|
|
78
|
+
names: set[str] = set()
|
|
79
|
+
for name, spec in concerns.items():
|
|
80
|
+
if not isinstance(spec, dict):
|
|
81
|
+
errors.append(f"concerns.{name}: must be a mapping, got {type(spec).__name__}")
|
|
82
|
+
continue
|
|
83
|
+
script = spec.get("script")
|
|
84
|
+
if not script or not isinstance(script, str):
|
|
85
|
+
errors.append(f"concerns.{name}: 'script' must be a relative path")
|
|
86
|
+
continue
|
|
87
|
+
if not (REPO_ROOT / script).is_file():
|
|
88
|
+
errors.append(f"concerns.{name}: script not found at '{script}'")
|
|
89
|
+
names.add(name)
|
|
90
|
+
return names
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _check_platforms(manifest: dict, concern_names: set[str],
|
|
94
|
+
errors: list[str], warnings: list[str]) -> set[str]:
|
|
95
|
+
platforms = manifest.get("platforms") or {}
|
|
96
|
+
if not isinstance(platforms, dict) or not platforms:
|
|
97
|
+
errors.append("manifest: 'platforms' must be a non-empty mapping")
|
|
98
|
+
return set()
|
|
99
|
+
bound: set[str] = set()
|
|
100
|
+
for plat, block in platforms.items():
|
|
101
|
+
if plat not in KNOWN_PLATFORMS:
|
|
102
|
+
errors.append(f"platforms.{plat}: unknown platform "
|
|
103
|
+
f"(allowed: {sorted(KNOWN_PLATFORMS)})")
|
|
104
|
+
continue
|
|
105
|
+
if block is None:
|
|
106
|
+
warnings.append(f"platforms.{plat}: placeholder (no events bound)")
|
|
107
|
+
continue
|
|
108
|
+
if not isinstance(block, dict):
|
|
109
|
+
errors.append(f"platforms.{plat}: must be mapping or null")
|
|
110
|
+
continue
|
|
111
|
+
if block.get("fallback_only"):
|
|
112
|
+
continue # Copilot — intentional, no event surface
|
|
113
|
+
for event, names in block.items():
|
|
114
|
+
if event not in EVENT_VOCABULARY:
|
|
115
|
+
errors.append(f"platforms.{plat}.{event}: unknown event "
|
|
116
|
+
f"(allowed: {sorted(EVENT_VOCABULARY)})")
|
|
117
|
+
continue
|
|
118
|
+
if not isinstance(names, list):
|
|
119
|
+
errors.append(f"platforms.{plat}.{event}: must be a list of concern names")
|
|
120
|
+
continue
|
|
121
|
+
for n in names:
|
|
122
|
+
if n not in concern_names:
|
|
123
|
+
errors.append(f"platforms.{plat}.{event}: unknown concern '{n}'")
|
|
124
|
+
else:
|
|
125
|
+
bound.add(n)
|
|
126
|
+
return bound
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _check_aliases(manifest: dict, errors: list[str]) -> None:
|
|
130
|
+
aliases = manifest.get("native_event_aliases") or {}
|
|
131
|
+
if not isinstance(aliases, dict):
|
|
132
|
+
errors.append("native_event_aliases: must be a mapping")
|
|
133
|
+
return
|
|
134
|
+
for plat, mapping in aliases.items():
|
|
135
|
+
if plat not in KNOWN_PLATFORMS:
|
|
136
|
+
errors.append(f"native_event_aliases.{plat}: unknown platform")
|
|
137
|
+
continue
|
|
138
|
+
if not isinstance(mapping, dict):
|
|
139
|
+
errors.append(f"native_event_aliases.{plat}: must be a mapping")
|
|
140
|
+
continue
|
|
141
|
+
for native, target in mapping.items():
|
|
142
|
+
if target not in EVENT_VOCABULARY:
|
|
143
|
+
errors.append(f"native_event_aliases.{plat}.{native}: "
|
|
144
|
+
f"target '{target}' not in vocabulary")
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _check_orphan_trampolines(manifest: dict, errors: list[str]) -> None:
|
|
148
|
+
"""A `<platform>-dispatcher.sh` on disk MUST have a non-null,
|
|
149
|
+
non-empty manifest block — otherwise the trampoline runs but no
|
|
150
|
+
concerns fire (silent no-op, hardest class of bug to debug)."""
|
|
151
|
+
if not HOOKS_DIR.is_dir():
|
|
152
|
+
return
|
|
153
|
+
platforms = manifest.get("platforms") or {}
|
|
154
|
+
for entry in sorted(HOOKS_DIR.iterdir()):
|
|
155
|
+
if not entry.name.endswith("-dispatcher.sh"):
|
|
156
|
+
continue
|
|
157
|
+
plat = entry.name[: -len("-dispatcher.sh")]
|
|
158
|
+
if plat not in KNOWN_PLATFORMS:
|
|
159
|
+
errors.append(f"orphan trampoline {entry.name}: unknown platform '{plat}'")
|
|
160
|
+
continue
|
|
161
|
+
block = platforms.get(plat)
|
|
162
|
+
if block is None or (isinstance(block, dict)
|
|
163
|
+
and not any(k in EVENT_VOCABULARY for k in block)):
|
|
164
|
+
errors.append(f"orphan trampoline {entry.name}: "
|
|
165
|
+
f"platform '{plat}' has no event bindings in manifest")
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def _check_dead_concerns(concern_names: set[str], bound: set[str],
|
|
169
|
+
warnings: list[str]) -> None:
|
|
170
|
+
for n in sorted(concern_names - bound):
|
|
171
|
+
warnings.append(f"concerns.{n}: declared but not bound to any platform")
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def lint(manifest_path: Path, *, strict: bool) -> int:
|
|
175
|
+
if not manifest_path.is_file():
|
|
176
|
+
sys.stderr.write(f"lint_hook_manifest: file not found: {manifest_path}\n")
|
|
177
|
+
return 2
|
|
178
|
+
try:
|
|
179
|
+
manifest = _load_manifest(manifest_path)
|
|
180
|
+
except Exception as exc: # pragma: no cover — covered by malformed-yaml test
|
|
181
|
+
sys.stderr.write(f"lint_hook_manifest: load error: {exc}\n")
|
|
182
|
+
return 2
|
|
183
|
+
if not isinstance(manifest, dict) or manifest.get("schema_version") != 1:
|
|
184
|
+
sys.stderr.write("lint_hook_manifest: schema_version must be 1\n")
|
|
185
|
+
return 1
|
|
186
|
+
|
|
187
|
+
errors: list[str] = []
|
|
188
|
+
warnings: list[str] = []
|
|
189
|
+
concern_names = _check_concerns(manifest, errors)
|
|
190
|
+
bound = _check_platforms(manifest, concern_names, errors, warnings)
|
|
191
|
+
_check_aliases(manifest, errors)
|
|
192
|
+
_check_orphan_trampolines(manifest, errors)
|
|
193
|
+
_check_dead_concerns(concern_names, bound, warnings)
|
|
194
|
+
|
|
195
|
+
for w in warnings:
|
|
196
|
+
sys.stderr.write(f"warn: {w}\n")
|
|
197
|
+
for e in errors:
|
|
198
|
+
sys.stderr.write(f"error: {e}\n")
|
|
199
|
+
|
|
200
|
+
if errors:
|
|
201
|
+
return 1
|
|
202
|
+
if strict and warnings:
|
|
203
|
+
return 1
|
|
204
|
+
return 0
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def main(argv: list[str] | None = None) -> int:
|
|
208
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
209
|
+
parser.add_argument("--manifest", type=Path, default=DEFAULT_MANIFEST)
|
|
210
|
+
parser.add_argument("--strict", action="store_true")
|
|
211
|
+
args = parser.parse_args(argv)
|
|
212
|
+
return lint(args.manifest, strict=args.strict)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
if __name__ == "__main__":
|
|
216
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""One-off-script age linter.
|
|
3
|
+
|
|
4
|
+
Scans `scripts/_one_off/<YYYY-MM>/_one_off_*.py` and enforces the
|
|
5
|
+
TTL policy from `docs/contracts/one-off-script-lifecycle.md`:
|
|
6
|
+
|
|
7
|
+
* Age ≤ 60 days → active, silent.
|
|
8
|
+
* 60 < Age ≤ 90 → warning, exit 0.
|
|
9
|
+
* Age > 90 → hard fail, exit 1 (purge candidate).
|
|
10
|
+
|
|
11
|
+
Scripts MAY extend their TTL exactly once via a frontmatter block:
|
|
12
|
+
|
|
13
|
+
\"\"\"
|
|
14
|
+
---
|
|
15
|
+
ttl_extended_until: YYYY-MM-DD
|
|
16
|
+
ttl_reason: <free text>
|
|
17
|
+
---
|
|
18
|
+
\"\"\"
|
|
19
|
+
|
|
20
|
+
The extended date is honoured up to 180 days past the month-directory
|
|
21
|
+
date. Anything beyond hard-fails with no second extension.
|
|
22
|
+
|
|
23
|
+
Exit codes: 0 = clean (incl. warnings), 1 = hard fail, 3 = internal error.
|
|
24
|
+
"""
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
import argparse
|
|
28
|
+
import json
|
|
29
|
+
import re
|
|
30
|
+
import sys
|
|
31
|
+
from dataclasses import asdict, dataclass
|
|
32
|
+
from datetime import date, datetime, timezone
|
|
33
|
+
from pathlib import Path
|
|
34
|
+
|
|
35
|
+
ROOT = Path(__file__).resolve().parent.parent
|
|
36
|
+
ONE_OFF_DIR = ROOT / "scripts" / "_one_off"
|
|
37
|
+
|
|
38
|
+
NAME_RE = re.compile(r"^_one_off_[a-z0-9-]+\.py$")
|
|
39
|
+
MONTH_RE = re.compile(r"^\d{4}-\d{2}$")
|
|
40
|
+
TTL_RE = re.compile(
|
|
41
|
+
r"---\s*\n\s*ttl_extended_until:\s*(\d{4}-\d{2}-\d{2})\s*\n",
|
|
42
|
+
re.MULTILINE,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
WARN_DAYS = 60
|
|
46
|
+
HARD_DAYS = 90
|
|
47
|
+
EXTEND_CAP_DAYS = 180
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass
|
|
51
|
+
class Finding:
|
|
52
|
+
path: str
|
|
53
|
+
age_days: int
|
|
54
|
+
severity: str # "warn" | "fail"
|
|
55
|
+
reason: str
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _today_utc() -> date:
|
|
59
|
+
return datetime.now(timezone.utc).date()
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _month_anchor(month_dir: str) -> date | None:
|
|
63
|
+
if not MONTH_RE.match(month_dir):
|
|
64
|
+
return None
|
|
65
|
+
y, m = map(int, month_dir.split("-"))
|
|
66
|
+
try:
|
|
67
|
+
return date(y, m, 1)
|
|
68
|
+
except ValueError:
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _read_extension(path: Path) -> date | None:
|
|
73
|
+
try:
|
|
74
|
+
head = path.read_text(encoding="utf-8")[:1024]
|
|
75
|
+
except OSError:
|
|
76
|
+
return None
|
|
77
|
+
m = TTL_RE.search(head)
|
|
78
|
+
if not m:
|
|
79
|
+
return None
|
|
80
|
+
try:
|
|
81
|
+
return datetime.strptime(m.group(1), "%Y-%m-%d").date()
|
|
82
|
+
except ValueError:
|
|
83
|
+
return None
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def scan(root: Path, today: date | None = None) -> list[Finding]:
|
|
87
|
+
today = today or _today_utc()
|
|
88
|
+
base = root / "scripts" / "_one_off"
|
|
89
|
+
if not base.exists():
|
|
90
|
+
return []
|
|
91
|
+
out: list[Finding] = []
|
|
92
|
+
for month_dir in sorted(base.iterdir()):
|
|
93
|
+
if not month_dir.is_dir():
|
|
94
|
+
continue
|
|
95
|
+
anchor = _month_anchor(month_dir.name)
|
|
96
|
+
if anchor is None:
|
|
97
|
+
out.append(Finding(
|
|
98
|
+
path=str(month_dir.relative_to(root)),
|
|
99
|
+
age_days=-1,
|
|
100
|
+
severity="fail",
|
|
101
|
+
reason="invalid month directory name (expect YYYY-MM)",
|
|
102
|
+
))
|
|
103
|
+
continue
|
|
104
|
+
for f in sorted(month_dir.iterdir()):
|
|
105
|
+
if f.name == "README.md" or f.is_dir():
|
|
106
|
+
continue
|
|
107
|
+
if not NAME_RE.match(f.name):
|
|
108
|
+
out.append(Finding(
|
|
109
|
+
path=str(f.relative_to(root)),
|
|
110
|
+
age_days=-1,
|
|
111
|
+
severity="fail",
|
|
112
|
+
reason="filename does not match _one_off_<slug>.py",
|
|
113
|
+
))
|
|
114
|
+
continue
|
|
115
|
+
age = (today - anchor).days
|
|
116
|
+
extension = _read_extension(f)
|
|
117
|
+
if extension is not None:
|
|
118
|
+
cap = (extension - anchor).days
|
|
119
|
+
if cap > EXTEND_CAP_DAYS:
|
|
120
|
+
out.append(Finding(
|
|
121
|
+
path=str(f.relative_to(root)),
|
|
122
|
+
age_days=age,
|
|
123
|
+
severity="fail",
|
|
124
|
+
reason=f"ttl_extended_until exceeds 180-day cap ({cap}d)",
|
|
125
|
+
))
|
|
126
|
+
continue
|
|
127
|
+
if age <= cap:
|
|
128
|
+
continue # extension still valid, silent
|
|
129
|
+
if age > HARD_DAYS:
|
|
130
|
+
out.append(Finding(
|
|
131
|
+
path=str(f.relative_to(root)),
|
|
132
|
+
age_days=age,
|
|
133
|
+
severity="fail",
|
|
134
|
+
reason=f"age {age}d exceeds {HARD_DAYS}-day hard limit",
|
|
135
|
+
))
|
|
136
|
+
elif age > WARN_DAYS:
|
|
137
|
+
out.append(Finding(
|
|
138
|
+
path=str(f.relative_to(root)),
|
|
139
|
+
age_days=age,
|
|
140
|
+
severity="warn",
|
|
141
|
+
reason=f"age {age}d in soft window ({WARN_DAYS}–{HARD_DAYS}d)",
|
|
142
|
+
))
|
|
143
|
+
return out
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def format_text(findings: list[Finding]) -> str:
|
|
147
|
+
if not findings:
|
|
148
|
+
return "✅ No one-off-script age violations."
|
|
149
|
+
lines = []
|
|
150
|
+
fails = [f for f in findings if f.severity == "fail"]
|
|
151
|
+
warns = [f for f in findings if f.severity == "warn"]
|
|
152
|
+
if fails:
|
|
153
|
+
lines.append(f"❌ {len(fails)} one-off script(s) past hard limit:")
|
|
154
|
+
for f in fails:
|
|
155
|
+
lines.append(f" 🔴 {f.path} → {f.reason}")
|
|
156
|
+
if warns:
|
|
157
|
+
lines.append(f"⚠️ {len(warns)} one-off script(s) in soft window:")
|
|
158
|
+
for f in warns:
|
|
159
|
+
lines.append(f" 🟡 {f.path} → {f.reason}")
|
|
160
|
+
lines.append(
|
|
161
|
+
"\nPurge candidates per docs/contracts/one-off-script-lifecycle.md."
|
|
162
|
+
)
|
|
163
|
+
return "\n".join(lines)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def main() -> int:
|
|
167
|
+
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
|
168
|
+
parser.add_argument("--format", choices=["text", "json"], default="text")
|
|
169
|
+
parser.add_argument("--root", type=Path, default=ROOT)
|
|
170
|
+
args = parser.parse_args()
|
|
171
|
+
try:
|
|
172
|
+
findings = scan(args.root)
|
|
173
|
+
except Exception as e: # pragma: no cover
|
|
174
|
+
print(f"Internal error: {e}", file=sys.stderr)
|
|
175
|
+
return 3
|
|
176
|
+
if args.format == "json":
|
|
177
|
+
print(json.dumps([asdict(f) for f in findings], indent=2))
|
|
178
|
+
else:
|
|
179
|
+
print(format_text(findings))
|
|
180
|
+
return 1 if any(f.severity == "fail" for f in findings) else 0
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
if __name__ == "__main__":
|
|
184
|
+
sys.exit(main())
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Lint rule frontmatter for the `tier:` key.
|
|
3
|
+
|
|
4
|
+
Hard-fails CI if any rule under .agent-src.uncompressed/rules/ lacks a
|
|
5
|
+
`tier:` declaration or uses an unknown tier value. The valid tier set is
|
|
6
|
+
locked by agents/contexts/hardening-pattern.md and the matrix in
|
|
7
|
+
agents/contexts/rule-trigger-matrix.md.
|
|
8
|
+
|
|
9
|
+
Hooked into `task ci` after `task lint-skills`.
|
|
10
|
+
|
|
11
|
+
Exit codes:
|
|
12
|
+
0 every rule declares a valid tier
|
|
13
|
+
1 one or more rules missing or using an invalid tier
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import sys
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
REPO = Path(__file__).resolve().parents[1]
|
|
21
|
+
RULES_DIR = REPO / ".agent-src.uncompressed" / "rules"
|
|
22
|
+
|
|
23
|
+
VALID_TIERS = frozenset({"1", "2a", "2b", "3", "safety-floor", "mechanical-already"})
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def parse_tier(text: str) -> str | None:
|
|
27
|
+
if not text.startswith("---\n"):
|
|
28
|
+
return None
|
|
29
|
+
end = text.find("\n---\n", 4)
|
|
30
|
+
if end == -1:
|
|
31
|
+
return None
|
|
32
|
+
for line in text[4:end].splitlines():
|
|
33
|
+
if ":" not in line:
|
|
34
|
+
continue
|
|
35
|
+
k, _, v = line.partition(":")
|
|
36
|
+
if k.strip() == "tier":
|
|
37
|
+
return v.strip().strip('"').strip("'")
|
|
38
|
+
return None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def main() -> int:
|
|
42
|
+
rules = sorted(RULES_DIR.glob("*.md"))
|
|
43
|
+
if not rules:
|
|
44
|
+
print(f"lint_rule_tiers: no rules found under {RULES_DIR}", file=sys.stderr)
|
|
45
|
+
return 1
|
|
46
|
+
|
|
47
|
+
missing: list[str] = []
|
|
48
|
+
invalid: list[tuple[str, str]] = []
|
|
49
|
+
|
|
50
|
+
for rule in rules:
|
|
51
|
+
tier = parse_tier(rule.read_text(encoding="utf-8"))
|
|
52
|
+
if tier is None:
|
|
53
|
+
missing.append(rule.name)
|
|
54
|
+
elif tier not in VALID_TIERS:
|
|
55
|
+
invalid.append((rule.name, tier))
|
|
56
|
+
|
|
57
|
+
if missing or invalid:
|
|
58
|
+
print(
|
|
59
|
+
f"❌ lint_rule_tiers: {len(missing)} missing, "
|
|
60
|
+
f"{len(invalid)} invalid (of {len(rules)} rules)",
|
|
61
|
+
file=sys.stderr,
|
|
62
|
+
)
|
|
63
|
+
for name in missing:
|
|
64
|
+
print(f" missing tier: {name}", file=sys.stderr)
|
|
65
|
+
for name, tier in invalid:
|
|
66
|
+
print(f" invalid tier '{tier}': {name}", file=sys.stderr)
|
|
67
|
+
print(
|
|
68
|
+
f" valid tiers: {sorted(VALID_TIERS)}",
|
|
69
|
+
file=sys.stderr,
|
|
70
|
+
)
|
|
71
|
+
return 1
|
|
72
|
+
|
|
73
|
+
print(f"✅ lint_rule_tiers: {len(rules)} rules, all tier values valid")
|
|
74
|
+
return 0
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
if __name__ == "__main__":
|
|
78
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""lint_showcase_sessions.py — gate `docs/showcase.md` ↔ `docs/showcase/sessions/`.
|
|
3
|
+
|
|
4
|
+
Phase 1.6 deliverable for `road-to-feedback-consolidation.md`.
|
|
5
|
+
|
|
6
|
+
Rules:
|
|
7
|
+
1. Every `docs/showcase/sessions/<slug>.log` reference inside
|
|
8
|
+
`docs/showcase.md` must point to an existing file.
|
|
9
|
+
2. Every referenced session file must carry a YAML frontmatter block
|
|
10
|
+
containing at minimum `commit_sha` and a `metrics:` mapping (the
|
|
11
|
+
four outcome-baseline metrics; values may be null but the keys
|
|
12
|
+
must be present per `scripts/capture_showcase_session.py`).
|
|
13
|
+
3. Every file under `docs/showcase/sessions/` must be referenced
|
|
14
|
+
from `docs/showcase.md` — orphans are not allowed.
|
|
15
|
+
|
|
16
|
+
When `docs/showcase/sessions/` is empty AND `docs/showcase.md` carries
|
|
17
|
+
no session references, the linter exits 0 (clean — Phase 1.3-1.5 are
|
|
18
|
+
deferred to manual host-agent runs).
|
|
19
|
+
|
|
20
|
+
Exit codes:
|
|
21
|
+
0 clean
|
|
22
|
+
1 one or more violations
|
|
23
|
+
"""
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
import re
|
|
27
|
+
import sys
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
|
|
30
|
+
ROOT = Path(__file__).resolve().parent.parent
|
|
31
|
+
SHOWCASE_MD = ROOT / "docs" / "showcase.md"
|
|
32
|
+
SESSIONS_DIR = ROOT / "docs" / "showcase" / "sessions"
|
|
33
|
+
|
|
34
|
+
REQUIRED_METRICS = {
|
|
35
|
+
"tool_call_count",
|
|
36
|
+
"reply_chars_mean",
|
|
37
|
+
"memory_hit_ratio",
|
|
38
|
+
"verify_pass_rate",
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
REF_RE = re.compile(r"docs/showcase/sessions/([A-Za-z0-9_\-]+)\.log")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _parse_frontmatter(text: str) -> dict[str, str] | None:
|
|
45
|
+
if not text.startswith("---\n"):
|
|
46
|
+
return None
|
|
47
|
+
end = text.find("\n---\n", 4)
|
|
48
|
+
if end == -1:
|
|
49
|
+
return None
|
|
50
|
+
block: dict[str, str] = {}
|
|
51
|
+
current_key: str | None = None
|
|
52
|
+
nested: dict[str, str] = {}
|
|
53
|
+
for raw in text[4:end].splitlines():
|
|
54
|
+
if not raw.strip():
|
|
55
|
+
continue
|
|
56
|
+
if raw.startswith(" ") and current_key:
|
|
57
|
+
k, _, v = raw.strip().partition(":")
|
|
58
|
+
nested[k.strip()] = v.strip()
|
|
59
|
+
continue
|
|
60
|
+
if ":" not in raw:
|
|
61
|
+
continue
|
|
62
|
+
k, _, v = raw.partition(":")
|
|
63
|
+
v = v.strip()
|
|
64
|
+
if not v:
|
|
65
|
+
current_key = k.strip()
|
|
66
|
+
nested = {}
|
|
67
|
+
block[current_key] = ""
|
|
68
|
+
block[f"_{current_key}_nested"] = nested # type: ignore[assignment]
|
|
69
|
+
else:
|
|
70
|
+
block[k.strip()] = v
|
|
71
|
+
current_key = None
|
|
72
|
+
return block
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _validate_session(slug: str) -> list[str]:
|
|
76
|
+
errors: list[str] = []
|
|
77
|
+
path = SESSIONS_DIR / f"{slug}.log"
|
|
78
|
+
if not path.is_file():
|
|
79
|
+
errors.append(f"referenced session missing on disk: {path.relative_to(ROOT)}")
|
|
80
|
+
return errors
|
|
81
|
+
text = path.read_text(encoding="utf-8")
|
|
82
|
+
fm = _parse_frontmatter(text)
|
|
83
|
+
if fm is None:
|
|
84
|
+
errors.append(f"{slug}.log: no YAML frontmatter block")
|
|
85
|
+
return errors
|
|
86
|
+
if not fm.get("commit_sha"):
|
|
87
|
+
errors.append(f"{slug}.log: missing or empty `commit_sha`")
|
|
88
|
+
metrics = fm.get("_metrics_nested")
|
|
89
|
+
if not isinstance(metrics, dict):
|
|
90
|
+
errors.append(f"{slug}.log: missing `metrics:` mapping")
|
|
91
|
+
else:
|
|
92
|
+
missing = REQUIRED_METRICS - set(metrics.keys())
|
|
93
|
+
if missing:
|
|
94
|
+
errors.append(
|
|
95
|
+
f"{slug}.log: metrics block missing keys: {sorted(missing)}"
|
|
96
|
+
)
|
|
97
|
+
return errors
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def main() -> int:
|
|
101
|
+
if not SHOWCASE_MD.is_file():
|
|
102
|
+
print(f"❌ {SHOWCASE_MD.relative_to(ROOT)} not found", file=sys.stderr)
|
|
103
|
+
return 1
|
|
104
|
+
|
|
105
|
+
text = SHOWCASE_MD.read_text(encoding="utf-8")
|
|
106
|
+
referenced = set(REF_RE.findall(text))
|
|
107
|
+
|
|
108
|
+
on_disk: set[str] = set()
|
|
109
|
+
if SESSIONS_DIR.is_dir():
|
|
110
|
+
on_disk = {p.stem for p in SESSIONS_DIR.glob("*.log")}
|
|
111
|
+
|
|
112
|
+
errors: list[str] = []
|
|
113
|
+
|
|
114
|
+
for slug in sorted(referenced):
|
|
115
|
+
errors.extend(_validate_session(slug))
|
|
116
|
+
|
|
117
|
+
orphans = on_disk - referenced
|
|
118
|
+
for slug in sorted(orphans):
|
|
119
|
+
errors.append(
|
|
120
|
+
f"orphan session: docs/showcase/sessions/{slug}.log "
|
|
121
|
+
f"is not referenced from docs/showcase.md"
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
if errors:
|
|
125
|
+
print(
|
|
126
|
+
f"❌ lint_showcase_sessions: {len(errors)} violation(s) "
|
|
127
|
+
f"({len(referenced)} referenced, {len(on_disk)} on disk)",
|
|
128
|
+
file=sys.stderr,
|
|
129
|
+
)
|
|
130
|
+
for err in errors:
|
|
131
|
+
print(f" {err}", file=sys.stderr)
|
|
132
|
+
return 1
|
|
133
|
+
|
|
134
|
+
if not referenced and not on_disk:
|
|
135
|
+
print(
|
|
136
|
+
"✅ lint_showcase_sessions: 0 sessions referenced, 0 on disk "
|
|
137
|
+
"(Phase 1.3-1.5 deferred to manual host-agent runs)"
|
|
138
|
+
)
|
|
139
|
+
else:
|
|
140
|
+
print(
|
|
141
|
+
f"✅ lint_showcase_sessions: {len(referenced)} session(s) "
|
|
142
|
+
f"valid ({len(on_disk)} on disk)"
|
|
143
|
+
)
|
|
144
|
+
return 0
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
if __name__ == "__main__":
|
|
148
|
+
raise SystemExit(main())
|