feat: surface deferred resource context cost

This commit is contained in:
yaojingang
2026-06-14 09:29:05 +08:00
parent f03189a8b4
commit c6ee987bb5
25 changed files with 337 additions and 65 deletions
@@ -6,9 +6,39 @@
"context_budget_tier": "production",
"context_budget_limit": 1000,
"skill_body_tokens": 718,
"other_text_tokens": 1946,
"other_text_tokens": 2113,
"estimated_initial_load_tokens": 790,
"estimated_total_text_tokens": 2664,
"estimated_total_text_tokens": 2831,
"deferred_resource_tokens": 1657,
"deferred_resource_warn_threshold": 120000,
"deferred_resource_dirs": [
{
"path": "references",
"estimated_tokens": 554,
"file_count": 4
},
{
"path": "scripts",
"estimated_tokens": 367,
"file_count": 1
},
{
"path": "input",
"estimated_tokens": 315,
"file_count": 1
},
{
"path": "outputs",
"estimated_tokens": 263,
"file_count": 1
},
{
"path": "evals",
"estimated_tokens": 158,
"file_count": 1
}
],
"large_deferred_resource_dirs": [],
"relevant_file_count": 12,
"unused_resource_dirs": [],
"quality_signal_points": 130,
@@ -6,9 +6,39 @@
"context_budget_tier": "production",
"context_budget_limit": 1000,
"skill_body_tokens": 658,
"other_text_tokens": 1603,
"other_text_tokens": 1770,
"estimated_initial_load_tokens": 760,
"estimated_total_text_tokens": 2261,
"estimated_total_text_tokens": 2428,
"deferred_resource_tokens": 1030,
"deferred_resource_warn_threshold": 120000,
"deferred_resource_dirs": [
{
"path": "scripts",
"estimated_tokens": 278,
"file_count": 1
},
{
"path": "references",
"estimated_tokens": 266,
"file_count": 3
},
{
"path": "outputs",
"estimated_tokens": 203,
"file_count": 1
},
{
"path": "input",
"estimated_tokens": 153,
"file_count": 1
},
{
"path": "evals",
"estimated_tokens": 130,
"file_count": 1
}
],
"large_deferred_resource_dirs": [],
"relevant_file_count": 13,
"unused_resource_dirs": [],
"quality_signal_points": 130,
+1 -1
View File
@@ -16,7 +16,7 @@
"vscode"
],
"package_metadata": "registry/packages/yao-meta-skill.json",
"package_sha256": "c42643ea854dd90bb03ca607595f6a6b2c00118da64a78e8bdbb4392d7f204fb"
"package_sha256": "2d237fe645ef197282d514782f3bd37025c00e4d7efda725145aa5c3af180ba5"
}
]
}
+1 -1
View File
@@ -16,7 +16,7 @@
"trust_level": "local",
"license": "MIT",
"checksums": {
"package_sha256": "c42643ea854dd90bb03ca607595f6a6b2c00118da64a78e8bdbb4392d7f204fb",
"package_sha256": "2d237fe645ef197282d514782f3bd37025c00e4d7efda725145aa5c3af180ba5",
"archive_sha256": "76793bd367e9aaf6c25e6b11ac1139156950827bd87ba3dd8a1bdc883f7d70fe"
},
"compatibility": {
+31 -3
View File
@@ -1,14 +1,42 @@
{
"ok": true,
"failures": [],
"warnings": [],
"warnings": [
"Deferred resource footprint is high: 381942 estimated tokens across references/scripts/evals. Keep Review Studio warnings visible until the largest resource dirs are split, archived, or justified."
],
"stats": {
"context_budget_tier": "production",
"context_budget_limit": 1000,
"skill_body_tokens": 751,
"other_text_tokens": 1183524,
"other_text_tokens": 1187833,
"estimated_initial_load_tokens": 944,
"estimated_total_text_tokens": 1184275,
"estimated_total_text_tokens": 1188584,
"deferred_resource_tokens": 381942,
"deferred_resource_warn_threshold": 120000,
"deferred_resource_dirs": [
{
"path": "scripts",
"estimated_tokens": 334459,
"file_count": 95
},
{
"path": "references",
"estimated_tokens": 25648,
"file_count": 32
},
{
"path": "evals",
"estimated_tokens": 21835,
"file_count": 27
}
],
"large_deferred_resource_dirs": [
{
"path": "scripts",
"estimated_tokens": 334459,
"file_count": 95
}
],
"relevant_file_count": 500,
"unused_resource_dirs": [],
"quality_signal_points": 130,
+5 -5
View File
@@ -1,9 +1,9 @@
# Context Budget Summary
| Target | Path | Tier | Limit | Initial | SKILL | Quality Density | Unused Dirs | Status |
| --- | --- | --- | ---: | ---: | ---: | ---: | --- | --- |
| root | `.` | `production` | 1000 | 944 | 751 | 137.7 | - | ok |
| complex-release-orchestrator | `examples/complex-release-orchestrator/generated-skill` | `production` | 1000 | 790 | 718 | 164.6 | - | ok |
| governed-incident-command | `examples/governed-incident-command/generated-skill` | `production` | 1000 | 760 | 658 | 171.1 | - | ok |
| Target | Path | Tier | Limit | Initial | SKILL | Deferred | Large Deferred Dirs | Quality Density | Unused Dirs | Status |
| --- | --- | --- | ---: | ---: | ---: | ---: | --- | ---: | --- | --- |
| root | `.` | `production` | 1000 | 944 | 751 | 381942 | scripts:334459 | 137.7 | - | ok |
| complex-release-orchestrator | `examples/complex-release-orchestrator/generated-skill` | `production` | 1000 | 790 | 718 | 1657 | - | 164.6 | - | ok |
| governed-incident-command | `examples/governed-incident-command/generated-skill` | `production` | 1000 | 760 | 658 | 1030 | - | 171.1 | - | ok |
Per-target JSON reports are written beside each target and under `reports/`.
+15 -1
View File
@@ -8,10 +8,20 @@
"budget_limit": 1000,
"initial_tokens": 944,
"skill_body_tokens": 751,
"deferred_resource_tokens": 381942,
"large_deferred_resource_dirs": [
{
"path": "scripts",
"estimated_tokens": 334459,
"file_count": 95
}
],
"quality_density": 137.7,
"unused_resource_dirs": [],
"ok": true,
"warnings": []
"warnings": [
"Deferred resource footprint is high: 381942 estimated tokens across references/scripts/evals. Keep Review Studio warnings visible until the largest resource dirs are split, archived, or justified."
]
},
{
"label": "complex-release-orchestrator",
@@ -20,6 +30,8 @@
"budget_limit": 1000,
"initial_tokens": 790,
"skill_body_tokens": 718,
"deferred_resource_tokens": 1657,
"large_deferred_resource_dirs": [],
"quality_density": 164.6,
"unused_resource_dirs": [],
"ok": true,
@@ -32,6 +44,8 @@
"budget_limit": 1000,
"initial_tokens": 760,
"skill_body_tokens": 658,
"deferred_resource_tokens": 1030,
"large_deferred_resource_dirs": [],
"quality_density": 171.1,
"unused_resource_dirs": [],
"ok": true,
+2 -2
View File
@@ -21,7 +21,7 @@
"trust_level": "local",
"license": "MIT",
"checksums": {
"package_sha256": "c42643ea854dd90bb03ca607595f6a6b2c00118da64a78e8bdbb4392d7f204fb",
"package_sha256": "2d237fe645ef197282d514782f3bd37025c00e4d7efda725145aa5c3af180ba5",
"archive_sha256": "76793bd367e9aaf6c25e6b11ac1139156950827bd87ba3dd8a1bdc883f7d70fe"
},
"compatibility": {
@@ -78,7 +78,7 @@
"vscode"
],
"package_metadata": "registry/packages/yao-meta-skill.json",
"package_sha256": "c42643ea854dd90bb03ca607595f6a6b2c00118da64a78e8bdbb4392d7f204fb"
"package_sha256": "2d237fe645ef197282d514782f3bd37025c00e4d7efda725145aa5c3af180ba5"
}
]
},
+1 -1
View File
@@ -6,7 +6,7 @@
- Maturity: `governed`
- Owner: `Yao Team`
- License: `MIT`
- Package SHA256: `c42643ea854dd90bb03ca607595f6a6b2c00118da64a78e8bdbb4392d7f204fb`
- Package SHA256: `2d237fe645ef197282d514782f3bd37025c00e4d7efda725145aa5c3af180ba5`
- Archive SHA256: `76793bd367e9aaf6c25e6b11ac1139156950827bd87ba3dd8a1bdc883f7d70fe`
- Install simulated: `True`
File diff suppressed because one or more lines are too long
+98 -16
View File
@@ -4,11 +4,11 @@
"skill_dir": ".",
"summary": {
"decision": "review",
"world_class_score": 91,
"world_class_score": 89,
"gate_count": 16,
"blocker_count": 0,
"warning_count": 3,
"action_count": 3,
"warning_count": 4,
"action_count": 4,
"annotation_count": 0,
"open_annotation_count": 0,
"open_annotation_blocker_count": 0,
@@ -42,8 +42,8 @@
{
"key": "context-budget",
"label": "上下文",
"status": "pass",
"detail": "initial load 944/1000; quality density 137.7",
"status": "warn",
"detail": "initial load 944/1000; deferred 381942/120000; top deferred scripts 334459; quality density 137.7",
"evidence": "reports/context_budget.json",
"link": "context_budget.md"
},
@@ -115,7 +115,7 @@
"key": "review-waivers",
"label": "人工批准",
"status": "warn",
"detail": "0 active waivers; 1 warning gates still need reviewer decision",
"detail": "0 active waivers; 2 warning gates still need reviewer decision",
"evidence": "reports/review_waivers.json",
"link": "review_waivers.md"
},
@@ -154,11 +154,19 @@
"evidence": "reports/output_quality_scorecard.json",
"link": "output_quality_scorecard.md"
},
{
"key": "context-budget",
"label": "上下文",
"status": "warn",
"detail": "initial load 944/1000; deferred 381942/120000; top deferred scripts 334459; quality density 137.7",
"evidence": "reports/context_budget.json",
"link": "context_budget.md"
},
{
"key": "review-waivers",
"label": "人工批准",
"status": "warn",
"detail": "0 active waivers; 1 warning gates still need reviewer decision",
"detail": "0 active waivers; 2 warning gates still need reviewer decision",
"evidence": "reports/review_waivers.json",
"link": "review_waivers.md"
},
@@ -234,6 +242,52 @@
"evidence_link": "output_quality_scorecard.md",
"verification_command": "python3 scripts/adjudicate_output_review.py --write-template && python3 scripts/yao.py output-review"
},
{
"gate_key": "context-budget",
"label": "上下文",
"status": "warn",
"priority": "warning",
"summary": "压缩或拆分高成本 deferred resources,保留最小可路由上下文。",
"why": "初始加载可以安全,但后续 references、scripts、evals 体量过大时,reviewer 仍需要看到维护和读取成本。",
"source_fix": "SKILL.md + references/ + scripts/ + evals/",
"source_refs": [
{
"path": "SKILL.md",
"label": "entrypoint",
"kind": "source",
"line": 9,
"exists": true,
"link": "../SKILL.md"
},
{
"path": "reports/context_budget.md",
"label": "context budget",
"kind": "report",
"line": 1,
"exists": true,
"link": "context_budget.md"
},
{
"path": "scripts/resource_boundary_check.py",
"label": "resource boundary checker",
"kind": "source",
"line": 44,
"exists": true,
"link": "../scripts/resource_boundary_check.py"
},
{
"path": "references/skill-engineering-method.md",
"label": "skill engineering method",
"kind": "method",
"line": 208,
"exists": true,
"link": "../references/skill-engineering-method.md"
}
],
"evidence": "reports/context_budget.json",
"evidence_link": "context_budget.md",
"verification_command": "python3 scripts/render_context_reports.py"
},
{
"gate_key": "review-waivers",
"label": "人工批准",
@@ -4996,7 +5050,7 @@
"label": "Review Studio",
"status": "pass",
"objective": "One HTML page supports first-pass production review across trigger, output, runtime, trust, release, and evidence actions.",
"current": "16 gates; decision review; warnings 3",
"current": "16 gates; decision review; warnings 4",
"command": "python3 scripts/yao.py review-studio .",
"test": "python3 tests/verify_review_studio.py",
"evidence": [
@@ -10257,7 +10311,7 @@
"interactive_script_count": 0,
"package_hash_scope": "source-contract-without-generated-reports",
"package_hash_file_count": 179,
"package_sha256": "c42643ea854dd90bb03ca607595f6a6b2c00118da64a78e8bdbb4392d7f204fb"
"package_sha256": "2d237fe645ef197282d514782f3bd37025c00e4d7efda725145aa5c3af180ba5"
},
"failures": [],
"warnings": [],
@@ -13646,7 +13700,7 @@
"architecture_maintainability": {
"schema_version": "1.0",
"ok": true,
"generated_at": "2026-06-13",
"generated_at": "2026-06-14",
"skill_dir": ".",
"summary": {
"python_file_count": 154,
@@ -13758,14 +13812,42 @@
"context_budget": {
"ok": true,
"failures": [],
"warnings": [],
"warnings": [
"Deferred resource footprint is high: 381942 estimated tokens across references/scripts/evals. Keep Review Studio warnings visible until the largest resource dirs are split, archived, or justified."
],
"stats": {
"context_budget_tier": "production",
"context_budget_limit": 1000,
"skill_body_tokens": 751,
"other_text_tokens": 1183524,
"other_text_tokens": 1187832,
"estimated_initial_load_tokens": 944,
"estimated_total_text_tokens": 1184275,
"estimated_total_text_tokens": 1188583,
"deferred_resource_tokens": 381942,
"deferred_resource_warn_threshold": 120000,
"deferred_resource_dirs": [
{
"path": "scripts",
"estimated_tokens": 334459,
"file_count": 95
},
{
"path": "references",
"estimated_tokens": 25648,
"file_count": 32
},
{
"path": "evals",
"estimated_tokens": 21835,
"file_count": 27
}
],
"large_deferred_resource_dirs": [
{
"path": "scripts",
"estimated_tokens": 334459,
"file_count": 95
}
],
"relevant_file_count": 500,
"unused_resource_dirs": [],
"quality_signal_points": 130,
@@ -17237,7 +17319,7 @@
"trust_level": "local",
"license": "MIT",
"checksums": {
"package_sha256": "c42643ea854dd90bb03ca607595f6a6b2c00118da64a78e8bdbb4392d7f204fb",
"package_sha256": "2d237fe645ef197282d514782f3bd37025c00e4d7efda725145aa5c3af180ba5",
"archive_sha256": "76793bd367e9aaf6c25e6b11ac1139156950827bd87ba3dd8a1bdc883f7d70fe"
},
"compatibility": {
@@ -17294,7 +17376,7 @@
"vscode"
],
"package_metadata": "registry/packages/yao-meta-skill.json",
"package_sha256": "c42643ea854dd90bb03ca607595f6a6b2c00118da64a78e8bdbb4392d7f204fb"
"package_sha256": "2d237fe645ef197282d514782f3bd37025c00e4d7efda725145aa5c3af180ba5"
}
]
},
@@ -18330,7 +18412,7 @@
{
"field": "package_sha256",
"from": "0000000000000000000000000000000000000000000000000000000000000000",
"to": "c42643ea854dd90bb03ca607595f6a6b2c00118da64a78e8bdbb4392d7f204fb"
"to": "2d237fe645ef197282d514782f3bd37025c00e4d7efda725145aa5c3af180ba5"
}
]
},
+1 -1
View File
@@ -23,7 +23,7 @@
"interactive_script_count": 0,
"package_hash_scope": "source-contract-without-generated-reports",
"package_hash_file_count": 179,
"package_sha256": "c42643ea854dd90bb03ca607595f6a6b2c00118da64a78e8bdbb4392d7f204fb"
"package_sha256": "2d237fe645ef197282d514782f3bd37025c00e4d7efda725145aa5c3af180ba5"
},
"failures": [],
"warnings": [],
+1 -1
View File
@@ -16,7 +16,7 @@
- Interactive scripts: `0`
- Package hash scope: `source-contract-without-generated-reports`
- Package hash files: `179`
- Package SHA256: `c42643ea854dd90bb03ca607595f6a6b2c00118da64a78e8bdbb4392d7f204fb`
- Package SHA256: `2d237fe645ef197282d514782f3bd37025c00e4d7efda725145aa5c3af180ba5`
## Failures
+3 -3
View File
@@ -1046,7 +1046,7 @@
"interactive_script_count": 0,
"package_hash_scope": "source-contract-without-generated-reports",
"package_hash_file_count": 179,
"package_sha256": "c42643ea854dd90bb03ca607595f6a6b2c00118da64a78e8bdbb4392d7f204fb"
"package_sha256": "2d237fe645ef197282d514782f3bd37025c00e4d7efda725145aa5c3af180ba5"
},
"skill_atlas": {
"skill_count": 12,
@@ -1084,7 +1084,7 @@
"trust_level": "local",
"license": "MIT",
"checksums": {
"package_sha256": "c42643ea854dd90bb03ca607595f6a6b2c00118da64a78e8bdbb4392d7f204fb",
"package_sha256": "2d237fe645ef197282d514782f3bd37025c00e4d7efda725145aa5c3af180ba5",
"archive_sha256": "76793bd367e9aaf6c25e6b11ac1139156950827bd87ba3dd8a1bdc883f7d70fe"
},
"compatibility": {
@@ -1216,7 +1216,7 @@
{
"field": "package_sha256",
"from": "0000000000000000000000000000000000000000000000000000000000000000",
"to": "c42643ea854dd90bb03ca607595f6a6b2c00118da64a78e8bdbb4392d7f204fb"
"to": "2d237fe645ef197282d514782f3bd37025c00e4d7efda725145aa5c3af180ba5"
}
]
},
+1 -1
View File
@@ -307,7 +307,7 @@
"key": "review-studio",
"label": "Review Studio",
"status": "pass",
"current": "decision review; warnings 3; score 91",
"current": "decision review; warnings 4; score 89",
"target": "One page shows gates, evidence paths, blockers, warnings, actions, waivers, and annotations",
"evidence": [
{
+1 -1
View File
@@ -28,7 +28,7 @@ Generated at: `2026-06-13`
| Native Permission Enforcement | external-required | native-enforced targets 0; installer-enforced targets 4 | At least one target/client enforces approved permissions at runtime | Integrate a real target-client or external installer runtime guard before claiming native permission enforcement. |
| Skill Atlas | pass | 12 skills; actionable collisions 0 | Workspace catalog, route overlap, stale/owner gaps, drift, and no-route opportunities | Feed real drift data into Atlas once client telemetry is installed. |
| Registry Distribution | pass | zip entries 574; install failures 0; permission failures 0 | Package metadata, archive checksum, package verification, and install simulation pass | Regenerate registry after package verification so checksums stay aligned. |
| Review Studio | pass | decision review; warnings 3; score 91 | One page shows gates, evidence paths, blockers, warnings, actions, waivers, and annotations | Resolve human/external warning gates before claiming full release readiness. |
| Review Studio | pass | decision review; warnings 4; score 89 | One page shows gates, evidence paths, blockers, warnings, actions, waivers, and annotations | Resolve human/external warning gates before claiming full release readiness. |
| Telemetry Drift | pass | events 1; risk low; recipes 5 | Local-first metadata-only event contract, aggregate drift report, hook recipes, and import path | Keep raw JSONL out of distributed packages and use aggregate reports for Atlas. |
| Native Client Telemetry | external-required | external source events 0; adoption samples 1 | A real Browser/Chrome/provider client sends production metadata events | Install a real client against the native host and import production metadata-only events. |
+1 -1
View File
@@ -237,7 +237,7 @@
"label": "Review Studio",
"status": "pass",
"objective": "One HTML page supports first-pass production review across trigger, output, runtime, trust, release, and evidence actions.",
"current": "16 gates; decision review; warnings 3",
"current": "16 gates; decision review; warnings 4",
"command": "python3 scripts/yao.py review-studio .",
"test": "python3 tests/verify_review_studio.py",
"evidence": [
+1 -1
View File
@@ -24,7 +24,7 @@ This report maps the Skill OS 2.0 upgrade blueprint to concrete local artifacts,
| Trust Security | `pass` | 95 scripts; secrets 0; help failures 0 | `python3 scripts/yao.py trust .` | `python3 tests/verify_trust_check.py` |
| Skill Atlas | `pass` | 12 scanned skills; actionable collisions 0 | `python3 scripts/yao.py skill-atlas --workspace-root .` | `python3 tests/verify_skill_atlas.py` |
| Registry Distribution | `pass` | archive entries 574; install failures 0 | `python3 scripts/yao.py package . --platform openai --platform claude --platform generic --platform vscode --output-dir dist --zip && python3 scripts/yao.py registry-audit .` | `python3 tests/verify_registry_audit.py` |
| Review Studio | `pass` | 16 gates; decision review; warnings 3 | `python3 scripts/yao.py review-studio .` | `python3 tests/verify_review_studio.py` |
| Review Studio | `pass` | 16 gates; decision review; warnings 4 | `python3 scripts/yao.py review-studio .` | `python3 tests/verify_review_studio.py` |
| Telemetry Drift | `pass` | events 1; recipes 5; risk low | `python3 scripts/yao.py telemetry-hooks . && python3 scripts/yao.py adoption-drift .` | `python3 tests/verify_telemetry_hooks.py` |
## Recommended PR Coverage
+1 -1
View File
@@ -75,7 +75,7 @@
{
"field": "package_sha256",
"from": "0000000000000000000000000000000000000000000000000000000000000000",
"to": "c42643ea854dd90bb03ca607595f6a6b2c00118da64a78e8bdbb4392d7f204fb"
"to": "2d237fe645ef197282d514782f3bd37025c00e4d7efda725145aa5c3af180ba5"
}
]
},
+9 -3
View File
@@ -52,6 +52,8 @@ def main() -> None:
"budget_limit": stats.get("context_budget_limit"),
"initial_tokens": stats.get("estimated_initial_load_tokens"),
"skill_body_tokens": stats.get("skill_body_tokens"),
"deferred_resource_tokens": stats.get("deferred_resource_tokens"),
"large_deferred_resource_dirs": stats.get("large_deferred_resource_dirs", []),
"quality_density": stats.get("quality_density"),
"unused_resource_dirs": stats.get("unused_resource_dirs", []),
"ok": report.get("ok"),
@@ -72,14 +74,18 @@ def main() -> None:
lines = [
"# Context Budget Summary",
"",
"| Target | Path | Tier | Limit | Initial | SKILL | Quality Density | Unused Dirs | Status |",
"| --- | --- | --- | ---: | ---: | ---: | ---: | --- | --- |",
"| Target | Path | Tier | Limit | Initial | SKILL | Deferred | Large Deferred Dirs | Quality Density | Unused Dirs | Status |",
"| --- | --- | --- | ---: | ---: | ---: | ---: | --- | ---: | --- | --- |",
]
for row in rows:
unused = ", ".join(row["unused_resource_dirs"]) if row["unused_resource_dirs"] else "-"
large_dirs = ", ".join(
f"{item['path']}:{item['estimated_tokens']}"
for item in row.get("large_deferred_resource_dirs", [])
) or "-"
status = "ok" if row["ok"] else "fail"
lines.append(
f"| {row['label']} | `{row['path']}` | `{row['budget_tier']}` | {row['budget_limit']} | {row['initial_tokens']} | {row['skill_body_tokens']} | {row['quality_density']} | {unused} | {status} |"
f"| {row['label']} | `{row['path']}` | `{row['budget_tier']}` | {row['budget_limit']} | {row['initial_tokens']} | {row['skill_body_tokens']} | {row['deferred_resource_tokens']} | {large_dirs} | {row['quality_density']} | {unused} | {status} |"
)
lines.extend(["", "Per-target JSON reports are written beside each target and under `reports/`."])
(ROOT / "reports" / "context_budget.md").write_text("\n".join(lines) + "\n", encoding="utf-8")
+4 -4
View File
@@ -154,12 +154,12 @@ ACTION_GUIDANCE: dict[str, dict[str, str]] = {
"verification": "python3 scripts/adjudicate_output_review.py --write-template && python3 scripts/yao.py output-review",
},
"context-budget": {
"summary": "压缩入口与高成本 references,保留最小可路由上下文。",
"why": "上下文成本过高会降低加载稳定性,并挤压用户任务材料的预算。",
"source_fix": "SKILL.md + references/",
"source_paths": [
"summary": "压缩或拆分高成本 deferred resources,保留最小可路由上下文。", "why": "初始加载可以安全,但后续 references、scripts、evals 体量过大时,reviewer 仍需要看到维护和读取成本。",
"source_fix": "SKILL.md + references/ + scripts/ + evals/", "source_paths": [
{"path": "SKILL.md", "label": "entrypoint", "kind": "source", "patterns": ["# Yao Meta Skill"]},
{"path": "reports/context_budget.md", "label": "context budget", "kind": "report", "patterns": ["# Context"]},
{"path": "scripts/resource_boundary_check.py", "label": "resource boundary checker", "kind": "source", "patterns": ["DEFERRED_RESOURCE"]},
{"path": "references/skill-engineering-method.md", "label": "skill engineering method", "kind": "method", "patterns": ["Design Principle"]},
],
"verification": "python3 scripts/render_context_reports.py",
},
+38
View File
@@ -41,6 +41,9 @@ CONTEXT_BUDGETS = {
}
SKILL_BODY_BUFFER = 100
SKILL_BODY_WARN_RATIO = 0.85
DEFERRED_RESOURCE_DIRS = {"references", "scripts", "evals", "templates", "assets", "input", "outputs"}
DEFERRED_RESOURCE_WARN_TOKENS = 120_000
DEFERRED_RESOURCE_WARN_DIR_TOKENS = 80_000
def has_files(path: Path) -> bool:
@@ -128,6 +131,8 @@ def analyze_skill(
other_tokens = 0
initial_load_tokens = 0
total_text_tokens = 0
deferred_resource_tokens = 0
deferred_resource_dirs: dict[str, dict[str, int | str]] = {}
for path in files:
if path.suffix and path.suffix not in TEXT_EXTS and path.name != "SKILL.md":
continue
@@ -135,6 +140,7 @@ def analyze_skill(
tokens = estimate_tokens(text)
total_text_tokens += tokens
rel = path.relative_to(root)
top_dir = rel.parts[0] if rel.parts else str(rel)
if rel == Path("SKILL.md"):
skill_body_tokens += tokens
initial_load_tokens += tokens
@@ -142,6 +148,14 @@ def analyze_skill(
other_tokens += tokens
if rel.parts[0] in {"agents"}:
initial_load_tokens += tokens
if top_dir in DEFERRED_RESOURCE_DIRS:
deferred_resource_tokens += tokens
current = deferred_resource_dirs.setdefault(
top_dir,
{"path": top_dir, "estimated_tokens": 0, "file_count": 0},
)
current["estimated_tokens"] = int(current["estimated_tokens"]) + tokens
current["file_count"] = int(current["file_count"]) + 1
budget_tier = budget_tier_for(manifest)
budget_limit = max_initial_tokens if max_initial_tokens is not None else CONTEXT_BUDGETS[budget_tier]
@@ -174,6 +188,22 @@ def analyze_skill(
if other_tokens and skill_body_tokens / (skill_body_tokens + other_tokens) > 0.75:
warnings.append("Most text still lives in SKILL.md; consider moving detail into references/ or scripts/.")
large_deferred_resource_dirs = [
item
for item in sorted(
deferred_resource_dirs.values(),
key=lambda payload: int(payload["estimated_tokens"]),
reverse=True,
)
if int(item["estimated_tokens"]) > DEFERRED_RESOURCE_WARN_DIR_TOKENS
]
if deferred_resource_tokens > DEFERRED_RESOURCE_WARN_TOKENS:
warnings.append(
"Deferred resource footprint is high: "
f"{deferred_resource_tokens} estimated tokens across references/scripts/evals. "
"Keep Review Studio warnings visible until the largest resource dirs are split, archived, or justified."
)
frontmatter = read_frontmatter(skill_md)
governance_score, _ = compute_score(root, manifest, frontmatter, skill_text, bool(manifest))
signal_points = quality_signal_points(root, manifest, governance_score)
@@ -190,6 +220,14 @@ def analyze_skill(
"other_text_tokens": other_tokens,
"estimated_initial_load_tokens": initial_load_tokens,
"estimated_total_text_tokens": total_text_tokens,
"deferred_resource_tokens": deferred_resource_tokens,
"deferred_resource_warn_threshold": DEFERRED_RESOURCE_WARN_TOKENS,
"deferred_resource_dirs": sorted(
deferred_resource_dirs.values(),
key=lambda payload: int(payload["estimated_tokens"]),
reverse=True,
),
"large_deferred_resource_dirs": large_deferred_resource_dirs,
"relevant_file_count": len(files),
"unused_resource_dirs": unused_resource_dirs,
"quality_signal_points": signal_points,
+10 -1
View File
@@ -200,9 +200,18 @@ def build_gates(skill_dir: Path, output_html: Path, data: dict[str, dict[str, An
context_status = "warn" if context_status == "pass" else context_status
if not context:
context_status = "warn"
large_deferred_dirs = context_stats.get("large_deferred_resource_dirs", []) or []
top_deferred = "none"
if large_deferred_dirs:
first = large_deferred_dirs[0]
top_deferred = f"{first.get('path', 'resource')} {first.get('estimated_tokens', 'n/a')}"
context_detail = (
f"initial load {context_stats.get('estimated_initial_load_tokens', 'n/a')}/"
f"{context_stats.get('context_budget_limit', 'n/a')}; quality density {context_stats.get('quality_density', 'n/a')}"
f"{context_stats.get('context_budget_limit', 'n/a')}; "
f"deferred {context_stats.get('deferred_resource_tokens', 'n/a')}/"
f"{context_stats.get('deferred_resource_warn_threshold', 'n/a')}; "
f"top deferred {top_deferred}; "
f"quality density {context_stats.get('quality_density', 'n/a')}"
)
gates.append(
gate(
+9
View File
@@ -44,16 +44,25 @@ def require_context_targets(case: dict, max_initial: int, min_density: float) ->
stats = case.get("payload", {}).get("stats", {})
initial = stats.get("estimated_initial_load_tokens")
density = stats.get("quality_density")
deferred = stats.get("deferred_resource_tokens")
deferred_threshold = stats.get("deferred_resource_warn_threshold")
deferred_dirs = stats.get("deferred_resource_dirs", [])
unused = stats.get("unused_resource_dirs", [])
case["max_initial_load"] = max_initial
case["observed_initial_load"] = initial
case["minimum_quality_density"] = min_density
case["observed_quality_density"] = density
case["observed_deferred_resource_tokens"] = deferred
case["deferred_resource_warn_threshold"] = deferred_threshold
case["deferred_resource_dir_count"] = len(deferred_dirs) if isinstance(deferred_dirs, list) else None
case["unused_resource_dirs"] = unused
case["passed"] = (
case["passed"]
and initial is not None
and density is not None
and deferred is not None
and deferred_threshold is not None
and isinstance(deferred_dirs, list)
and initial <= max_initial
and density >= min_density
and not unused
+32 -6
View File
@@ -116,6 +116,13 @@ def main() -> None:
capture_output=True,
text=True,
)
subprocess.run(
[sys.executable, str(ROOT / "scripts" / "render_context_reports.py")],
cwd=ROOT,
check=True,
capture_output=True,
text=True,
)
subprocess.run(
[
sys.executable,
@@ -279,20 +286,21 @@ def main() -> None:
assert payload["schema_version"] == "2.0", payload
assert payload["summary"]["decision"] == "review", payload
assert payload["summary"]["gate_count"] == 16, payload
assert payload["summary"]["world_class_score"] == 91, payload
assert payload["summary"]["warning_count"] == 3, payload
assert payload["summary"]["world_class_score"] == 89, payload
assert payload["summary"]["warning_count"] == 4, payload
assert payload["summary"]["blocker_count"] == 0, payload
assert payload["summary"]["action_count"] == 3, payload
assert payload["summary"]["action_count"] == 4, payload
assert payload["summary"]["annotation_count"] == 0, payload
assert payload["summary"]["open_annotation_blocker_count"] == 0, payload
assert payload["summary"]["action_count"] == payload["summary"]["warning_count"] + payload["summary"]["blocker_count"], payload
assert {item["gate_key"] for item in payload["review_actions"]} == {
"output-lab",
"context-budget",
"review-waivers",
"world-class-evidence",
}, payload
gate_keys = {item["key"] for item in payload["gates"]}
assert {"intent-canvas", "trigger-lab", "output-lab", "runtime-matrix", "trust-report", "python-compat", "architecture-maintainability", "permission-gates", "permission-runtime", "skill-atlas", "operations-loop", "review-waivers", "world-class-evidence", "registry-audit", "release-notes"} <= gate_keys, payload
assert {"intent-canvas", "trigger-lab", "output-lab", "context-budget", "runtime-matrix", "trust-report", "python-compat", "architecture-maintainability", "permission-gates", "permission-runtime", "skill-atlas", "operations-loop", "review-waivers", "world-class-evidence", "registry-audit", "release-notes"} <= gate_keys, payload
output_gate = next(item for item in payload["gates"] if item["key"] == "output-lab")
assert output_gate["status"] == "warn", output_gate
assert "5/5 cases" in output_gate["detail"], output_gate
@@ -302,6 +310,13 @@ def main() -> None:
assert "model 0" in output_gate["detail"], output_gate
assert "reviewed 0/5" in output_gate["detail"], output_gate
assert "review pending 5" in output_gate["detail"], output_gate
context_gate = next(item for item in payload["gates"] if item["key"] == "context-budget")
assert context_gate["status"] == "warn", context_gate
assert "initial load 944/1000" in context_gate["detail"], context_gate
assert "deferred " in context_gate["detail"], context_gate
assert "/120000" in context_gate["detail"], context_gate
assert "top deferred scripts" in context_gate["detail"], context_gate
assert "quality density" in context_gate["detail"], context_gate
release_gate = next(item for item in payload["gates"] if item["key"] == "release-notes")
assert "upgrade minor declared / minor recommended" in release_gate["detail"], release_gate
assert "reports/upgrade_check.json" in release_gate["evidence"], release_gate
@@ -347,7 +362,7 @@ def main() -> None:
assert "reports/adoption_drift_report.json" in operations_gate["evidence"], operations_gate
waivers_gate = next(item for item in payload["gates"] if item["key"] == "review-waivers")
assert waivers_gate["status"] == "warn", waivers_gate
assert "1 warning gates still need reviewer decision" in waivers_gate["detail"], waivers_gate
assert "2 warning gates still need reviewer decision" in waivers_gate["detail"], waivers_gate
assert "reports/review_waivers.json" in waivers_gate["evidence"], waivers_gate
world_class_gate = next(item for item in payload["gates"] if item["key"] == "world-class-evidence")
assert world_class_gate["status"] == "warn", world_class_gate
@@ -411,7 +426,17 @@ def main() -> None:
assert full_payload["data"]["architecture_maintainability"]["summary"]["hotspot_count"] == 0, full_payload["data"]["architecture_maintainability"]
assert full_payload["data"]["architecture_maintainability"]["summary"]["blocker_count"] == 0, full_payload["data"]["architecture_maintainability"]
action_keys = {item["gate_key"] for item in full_payload["review_actions"]}
assert action_keys == {"output-lab", "review-waivers", "world-class-evidence"}, full_payload["review_actions"]
assert action_keys == {"output-lab", "context-budget", "review-waivers", "world-class-evidence"}, full_payload["review_actions"]
context_action = next(item for item in full_payload["review_actions"] if item["gate_key"] == "context-budget")
assert "deferred resources" in context_action["summary"], context_action
assert {item["path"] for item in context_action["source_refs"]} >= {
"SKILL.md",
"reports/context_budget.md",
"scripts/resource_boundary_check.py",
"references/skill-engineering-method.md",
}, context_action
assert all(item["exists"] for item in context_action["source_refs"]), context_action
assert "python3 scripts/render_context_reports.py" == context_action["verification_command"], context_action
world_class_action = next(item for item in full_payload["review_actions"] if item["gate_key"] == "world-class-evidence")
assert {item["path"] for item in world_class_action["source_refs"]} >= {
"reports/world_class_evidence_ledger.md",
@@ -505,6 +530,7 @@ def main() -> None:
assert "审查闸门" in html, html[:1200]
assert "修复动作" in html, html[:3000]
assert "补足 output eval 覆盖、execution evidence、blind A/B 和 reviewer adjudication。" in html, html[:9000]
assert "压缩或拆分高成本 deferred resources" in html, html[:9000]
assert "reports/output_review_kit.html" in html, html[:9000]
assert "python3 scripts/adjudicate_output_review.py --write-template" in html, html[:9000]
assert "对保留的 warning 写入 reviewer、理由、范围和到期时间,或修掉 warning。" in html, html[:9000]