@deftai/directive-content 0.55.2 → 0.56.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.githooks/pre-commit +143 -0
- package/.githooks/pre-push +121 -0
- package/QUICK-START.md +2 -2
- package/Taskfile.yml +934 -0
- package/UPGRADING.md +47 -1
- package/events/README.md +3 -3
- package/package.json +5 -4
- package/scripts/_agents_md.py +494 -0
- package/scripts/_cache_fetch.py +635 -0
- package/scripts/_cache_quota.py +529 -0
- package/scripts/_cache_refresh.py +163 -0
- package/scripts/_cache_validate.py +209 -0
- package/scripts/_content_root.py +42 -0
- package/scripts/_doctor_state.py +277 -0
- package/scripts/_event_detect.py +305 -0
- package/scripts/_events.py +514 -0
- package/scripts/_lifecycle_hygiene.py +568 -0
- package/scripts/_pathspec.py +91 -0
- package/scripts/_policy_show_cli.py +266 -0
- package/scripts/_precutover.py +92 -0
- package/scripts/_project_context.py +224 -0
- package/scripts/_project_definition_io.py +164 -0
- package/scripts/_relocate_snapshot.py +209 -0
- package/scripts/_relocate_states.py +343 -0
- package/scripts/_resolve_preflight_path.py +152 -0
- package/scripts/_safe_subprocess.py +167 -0
- package/scripts/_session_start_hook.py +205 -0
- package/scripts/_sor_gate_diff.py +365 -0
- package/scripts/_stdio_utf8.py +59 -0
- package/scripts/_triage_bootstrap_gitignore.py +904 -0
- package/scripts/_triage_classify_cli.py +122 -0
- package/scripts/_triage_queue_cli.py +625 -0
- package/scripts/_triage_scope_cli.py +343 -0
- package/scripts/_triage_scope_drift_cli.py +121 -0
- package/scripts/_triage_scope_ignores.py +286 -0
- package/scripts/_triage_scope_milestone.py +432 -0
- package/scripts/_triage_scope_mutations.py +337 -0
- package/scripts/_triage_scope_renderers.py +207 -0
- package/scripts/_triage_smoketest_stages.py +674 -0
- package/scripts/_triage_subscribe_cli.py +140 -0
- package/scripts/_triage_welcome_cli.py +421 -0
- package/scripts/_vbrief_build.py +239 -0
- package/scripts/_vbrief_fidelity.py +479 -0
- package/scripts/_vbrief_legacy.py +589 -0
- package/scripts/_vbrief_reconciliation.py +883 -0
- package/scripts/_vbrief_routing.py +277 -0
- package/scripts/_vbrief_safety.py +778 -0
- package/scripts/_vbrief_sources.py +312 -0
- package/scripts/_vbrief_speckit.py +262 -0
- package/scripts/_vbrief_story_quality.py +353 -0
- package/scripts/_vbrief_validation.py +299 -0
- package/scripts/build_dist.py +412 -0
- package/scripts/cache.py +1078 -0
- package/scripts/cache_scanner.py +745 -0
- package/scripts/candidates_log.py +432 -0
- package/scripts/capacity_backfill.py +680 -0
- package/scripts/capacity_show.py +653 -0
- package/scripts/ci_local.py +689 -0
- package/scripts/code_structure_validate.py +765 -0
- package/scripts/codebase_default_extractor.py +495 -0
- package/scripts/codebase_map.py +304 -0
- package/scripts/codebase_map_fresh.py +104 -0
- package/scripts/codebase_projection_registry.py +94 -0
- package/scripts/codebase_provider.py +582 -0
- package/scripts/doctor.py +2257 -0
- package/scripts/framework_commands.py +505 -0
- package/scripts/gh_rest.py +882 -0
- package/scripts/github_auth_modes.py +437 -0
- package/scripts/github_body.py +292 -0
- package/scripts/ip_risk.py +531 -0
- package/scripts/issue_emit.py +670 -0
- package/scripts/issue_ingest.py +1064 -0
- package/scripts/migrate_preflight.py +418 -0
- package/scripts/migrate_vbrief.py +2677 -0
- package/scripts/monitor_pr.py +401 -0
- package/scripts/pack_migrate_lessons.py +336 -0
- package/scripts/pack_migrate_patterns.py +254 -0
- package/scripts/pack_migrate_rules.py +350 -0
- package/scripts/pack_migrate_skills.py +423 -0
- package/scripts/pack_migrate_strategies.py +311 -0
- package/scripts/pack_migrate_swarm_spec.py +250 -0
- package/scripts/pack_render.py +434 -0
- package/scripts/packs_slice.py +712 -0
- package/scripts/platform_capabilities.py +336 -0
- package/scripts/policy.py +2826 -0
- package/scripts/policy_set.py +324 -0
- package/scripts/pr_check_closing_keywords.py +524 -0
- package/scripts/pr_check_protected_issues.py +267 -0
- package/scripts/pr_merge_readiness.py +1004 -0
- package/scripts/pr_wait_mergeable.py +669 -0
- package/scripts/prd_render.py +159 -0
- package/scripts/preflight_architecture_sor.py +974 -0
- package/scripts/preflight_branch.py +289 -0
- package/scripts/preflight_cache.py +974 -0
- package/scripts/preflight_gh.py +721 -0
- package/scripts/preflight_implementation.py +272 -0
- package/scripts/preflight_story_start.py +838 -0
- package/scripts/preflight_wip_cap.py +149 -0
- package/scripts/probe_session.py +545 -0
- package/scripts/project_render.py +293 -0
- package/scripts/quarantine_ext.py +237 -0
- package/scripts/reconcile_issues.py +1442 -0
- package/scripts/refresh-path.ps1 +107 -0
- package/scripts/release.py +2030 -0
- package/scripts/release_e2e.py +1011 -0
- package/scripts/release_publish.py +486 -0
- package/scripts/release_rollback.py +980 -0
- package/scripts/relocate.py +1034 -0
- package/scripts/resolve_changelog_unreleased.py +667 -0
- package/scripts/resolve_version.py +490 -0
- package/scripts/resume_conditions.py +706 -0
- package/scripts/ritual_sentinel.py +609 -0
- package/scripts/roadmap_render.py +635 -0
- package/scripts/rule_ownership_lint.py +325 -0
- package/scripts/scm.py +591 -0
- package/scripts/scope_audit_log.py +387 -0
- package/scripts/scope_decompose.py +654 -0
- package/scripts/scope_demote.py +509 -0
- package/scripts/scope_lifecycle.py +1126 -0
- package/scripts/scope_undo.py +772 -0
- package/scripts/session_start.py +406 -0
- package/scripts/setup_ghx.py +339 -0
- package/scripts/setup_windows.ps1 +220 -0
- package/scripts/slice_audit.py +585 -0
- package/scripts/slice_record.py +530 -0
- package/scripts/slice_record_existing.py +692 -0
- package/scripts/slug_normalize.py +178 -0
- package/scripts/spec_render.py +477 -0
- package/scripts/spec_validate.py +238 -0
- package/scripts/subagent_monitor.py +658 -0
- package/scripts/swarm_complete_cohort.py +644 -0
- package/scripts/swarm_launch.py +1206 -0
- package/scripts/swarm_readiness.py +554 -0
- package/scripts/swarm_verify_review_clean.py +438 -0
- package/scripts/swarm_worktrees.py +497 -0
- package/scripts/toolchain-check.py +52 -0
- package/scripts/triage_actions.py +871 -0
- package/scripts/triage_bootstrap.py +1153 -0
- package/scripts/triage_bulk.py +630 -0
- package/scripts/triage_classify.py +932 -0
- package/scripts/triage_help.py +1685 -0
- package/scripts/triage_queue.py +1944 -0
- package/scripts/triage_reconcile.py +581 -0
- package/scripts/triage_refresh.py +643 -0
- package/scripts/triage_scope.py +999 -0
- package/scripts/triage_scope_drift.py +575 -0
- package/scripts/triage_smoketest.py +396 -0
- package/scripts/triage_subscribe.py +399 -0
- package/scripts/triage_summary.py +1011 -0
- package/scripts/triage_welcome.py +1178 -0
- package/scripts/ts_check_lane.py +86 -0
- package/scripts/validate-links.py +64 -0
- package/scripts/validate_strategy_output.py +212 -0
- package/scripts/vbrief_activate.py +228 -0
- package/scripts/vbrief_migrate_conformance.py +368 -0
- package/scripts/vbrief_reconcile_graph.py +306 -0
- package/scripts/vbrief_reconcile_labels.py +460 -0
- package/scripts/vbrief_reconcile_umbrellas.py +741 -0
- package/scripts/vbrief_validate.py +1195 -0
- package/scripts/verify-stubs.py +61 -0
- package/scripts/verify_capacity.py +160 -0
- package/scripts/verify_encoding.py +699 -0
- package/scripts/verify_hooks_installed.py +206 -0
- package/scripts/verify_investigation.py +360 -0
- package/scripts/verify_judgment_gates.py +827 -0
- package/scripts/verify_no_task_runtime.py +171 -0
- package/scripts/verify_scm_boundary.py +509 -0
- package/scripts/verify_session_ritual.py +389 -0
- package/scripts/verify_tools.py +426 -0
- package/scripts/verify_vbrief_conformance.py +478 -0
- package/tasks/architecture.yml +13 -0
- package/tasks/cache.yml +69 -0
- package/tasks/capacity.yml +38 -0
- package/tasks/change.yml +46 -0
- package/tasks/changelog.yml +24 -0
- package/tasks/ci.yml +49 -0
- package/tasks/codebase.yml +47 -0
- package/tasks/commit.yml +30 -0
- package/tasks/core.yml +126 -0
- package/tasks/deployments.yml +54 -0
- package/tasks/framework.yml +74 -0
- package/tasks/install.yml +60 -0
- package/tasks/issue.yml +50 -0
- package/tasks/migrate.yml +73 -0
- package/tasks/packs.yml +92 -0
- package/tasks/policy.yml +75 -0
- package/tasks/pr.yml +89 -0
- package/tasks/prd.yml +39 -0
- package/tasks/project.yml +27 -0
- package/tasks/reconcile.yml +32 -0
- package/tasks/relocate.yml +56 -0
- package/tasks/roadmap.yml +28 -0
- package/tasks/scm.yml +126 -0
- package/tasks/scope-undo.yml +36 -0
- package/tasks/scope.yml +141 -0
- package/tasks/session.yml +19 -0
- package/tasks/setup.yml +37 -0
- package/tasks/slice.yml +69 -0
- package/tasks/spec.yml +41 -0
- package/tasks/swarm.yml +85 -0
- package/tasks/toolchain.yml +13 -0
- package/tasks/triage-actions.yml +94 -0
- package/tasks/triage-bootstrap.yml +43 -0
- package/tasks/triage-bulk.yml +75 -0
- package/tasks/triage-classify.yml +30 -0
- package/tasks/triage-queue.yml +50 -0
- package/tasks/triage-reconcile.yml +29 -0
- package/tasks/triage-scope-drift.yml +29 -0
- package/tasks/triage-scope.yml +31 -0
- package/tasks/triage-smoketest.yml +33 -0
- package/tasks/triage-subscribe.yml +36 -0
- package/tasks/triage-summary.yml +29 -0
- package/tasks/triage-welcome.yml +32 -0
- package/tasks/ts.yml +328 -0
- package/tasks/vbrief.yml +206 -0
- package/tasks/verify.yml +292 -0
- package/templates/agents-entry.md +1 -1
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
"""CLI helpers for ``scripts/triage_scope.py`` (#1131).
|
|
2
|
+
|
|
3
|
+
Extracted from ``scripts/triage_scope.py`` so the parent module stays
|
|
4
|
+
under the 1000-line MUST cap documented in ``coding/coding.md``. The
|
|
5
|
+
public surface lives in ``triage_scope``; this module is the argparse
|
|
6
|
+
shim and command dispatcher only.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import os
|
|
13
|
+
import sys
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
19
|
+
"""Return the ``triage_scope.py`` argument parser."""
|
|
20
|
+
parser = argparse.ArgumentParser(
|
|
21
|
+
prog="triage_scope.py",
|
|
22
|
+
description=(
|
|
23
|
+
"Inspect, mutate, and diff the typed plan.policy.triageScope[] "
|
|
24
|
+
"subscription + plan.policy.triageScopeIgnores[] (#1131 / D12, "
|
|
25
|
+
"#1133 / D14, #1182 / D14c). Read paths never trigger a "
|
|
26
|
+
"recompute; use --refresh-denominator to update the coverage "
|
|
27
|
+
"cache. Mutation flags --add-label / --add-milestone / "
|
|
28
|
+
"--ignore-label are idempotent and atomic; every mutation "
|
|
29
|
+
"appends a subscription-change audit entry to "
|
|
30
|
+
"vbrief/.eval/subscription-history.jsonl."
|
|
31
|
+
),
|
|
32
|
+
)
|
|
33
|
+
parser.add_argument(
|
|
34
|
+
"--project-root",
|
|
35
|
+
default=os.environ.get("DEFT_PROJECT_ROOT", "."),
|
|
36
|
+
help=(
|
|
37
|
+
"Path to the consumer project root (default: "
|
|
38
|
+
"$DEFT_PROJECT_ROOT or current working directory)."
|
|
39
|
+
),
|
|
40
|
+
)
|
|
41
|
+
parser.add_argument(
|
|
42
|
+
"--list",
|
|
43
|
+
action="store_true",
|
|
44
|
+
dest="do_list",
|
|
45
|
+
help=(
|
|
46
|
+
"Print the effective subscription rules + per-issue notes "
|
|
47
|
+
"from explicit-watch + the triageScopeIgnores[] block. "
|
|
48
|
+
"Read-only; never triggers a denominator recompute."
|
|
49
|
+
),
|
|
50
|
+
)
|
|
51
|
+
parser.add_argument(
|
|
52
|
+
"--refresh-denominator",
|
|
53
|
+
action="store_true",
|
|
54
|
+
dest="refresh_denominator",
|
|
55
|
+
help=(
|
|
56
|
+
"Recompute and write the coverage denominator at "
|
|
57
|
+
".deft-cache/<source>/<owner>/<repo>/coverage.json. "
|
|
58
|
+
"Requires --repo OWNER/NAME and --count <int>."
|
|
59
|
+
),
|
|
60
|
+
)
|
|
61
|
+
parser.add_argument(
|
|
62
|
+
"--repo",
|
|
63
|
+
default=os.environ.get("DEFT_TRIAGE_REPO"),
|
|
64
|
+
help=(
|
|
65
|
+
"Upstream repo slug 'owner/name' for --refresh-denominator "
|
|
66
|
+
"and --diff-from-upstream. Falls back to $DEFT_TRIAGE_REPO."
|
|
67
|
+
),
|
|
68
|
+
)
|
|
69
|
+
# D14c (#1182): wrapper-verb flag set.
|
|
70
|
+
parser.add_argument(
|
|
71
|
+
"--add-label",
|
|
72
|
+
default=None,
|
|
73
|
+
help=(
|
|
74
|
+
"Append <L> to plan.policy.triageScope[] (merges into an "
|
|
75
|
+
"existing labels.any-of rule when present, otherwise "
|
|
76
|
+
"creates a new one). Idempotent; atomic; audit-logged."
|
|
77
|
+
),
|
|
78
|
+
)
|
|
79
|
+
parser.add_argument(
|
|
80
|
+
"--add-milestone",
|
|
81
|
+
default=None,
|
|
82
|
+
help=(
|
|
83
|
+
"Append a {rule: 'milestone', name: <M>} entry to "
|
|
84
|
+
"plan.policy.triageScope[]. Idempotent; atomic; audit-logged."
|
|
85
|
+
),
|
|
86
|
+
)
|
|
87
|
+
parser.add_argument(
|
|
88
|
+
"--ignore-label",
|
|
89
|
+
default=None,
|
|
90
|
+
help=(
|
|
91
|
+
"Append a {label: <L>} entry to "
|
|
92
|
+
"plan.policy.triageScopeIgnores[]. Canonical surface; the "
|
|
93
|
+
"older `task triage:scope-drift -- --ignore-label` form "
|
|
94
|
+
"continues to work as an alias against the same field. "
|
|
95
|
+
"Idempotent; atomic; audit-logged."
|
|
96
|
+
),
|
|
97
|
+
)
|
|
98
|
+
parser.add_argument(
|
|
99
|
+
"--diff-from-upstream",
|
|
100
|
+
action="store_true",
|
|
101
|
+
dest="diff_from_upstream",
|
|
102
|
+
help=(
|
|
103
|
+
"Fetch upstream labels + milestones via gh REST and partition "
|
|
104
|
+
"them into subscribed / ignored / neither sets. Requires "
|
|
105
|
+
"--repo OWNER/NAME (or $DEFT_TRIAGE_REPO)."
|
|
106
|
+
),
|
|
107
|
+
)
|
|
108
|
+
parser.add_argument(
|
|
109
|
+
"--source",
|
|
110
|
+
default="github-issue",
|
|
111
|
+
help=(
|
|
112
|
+
"Cache source (default: github-issue; v1 supports only "
|
|
113
|
+
"github-issue)."
|
|
114
|
+
),
|
|
115
|
+
)
|
|
116
|
+
parser.add_argument(
|
|
117
|
+
"--cache-root",
|
|
118
|
+
default=None,
|
|
119
|
+
help=(
|
|
120
|
+
"Override the cache root (default: "
|
|
121
|
+
"<project-root>/.deft-cache). Useful for tests."
|
|
122
|
+
),
|
|
123
|
+
)
|
|
124
|
+
parser.add_argument(
|
|
125
|
+
"--count",
|
|
126
|
+
type=int,
|
|
127
|
+
default=None,
|
|
128
|
+
help=(
|
|
129
|
+
"When --refresh-denominator is set, write this count instead "
|
|
130
|
+
"of computing one. Production callers (triage:bootstrap) "
|
|
131
|
+
"pass the live upstream open-issue count; CI / tests can "
|
|
132
|
+
"pass a synthetic value. Required by --refresh-denominator "
|
|
133
|
+
"until the live-probe wiring lands in D5."
|
|
134
|
+
),
|
|
135
|
+
)
|
|
136
|
+
return parser
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def run_cli(argv: list[str] | None, ts_module: Any) -> int:
|
|
140
|
+
"""Dispatch ``triage_scope`` CLI args using ``ts_module`` as backend.
|
|
141
|
+
|
|
142
|
+
``ts_module`` is the parent ``triage_scope`` module; passed in to
|
|
143
|
+
avoid a circular import at module-load time.
|
|
144
|
+
"""
|
|
145
|
+
parser = build_parser()
|
|
146
|
+
args = parser.parse_args(argv)
|
|
147
|
+
|
|
148
|
+
project_root = Path(args.project_root).resolve()
|
|
149
|
+
if not project_root.exists() or not project_root.is_dir():
|
|
150
|
+
print(
|
|
151
|
+
f"triage:scope: --project-root {project_root} does not exist "
|
|
152
|
+
"or is not a directory.",
|
|
153
|
+
file=sys.stderr,
|
|
154
|
+
)
|
|
155
|
+
return 2
|
|
156
|
+
|
|
157
|
+
mutation_flags = [
|
|
158
|
+
flag
|
|
159
|
+
for flag, val in (
|
|
160
|
+
("--add-label", args.add_label),
|
|
161
|
+
("--add-milestone", args.add_milestone),
|
|
162
|
+
("--ignore-label", args.ignore_label),
|
|
163
|
+
)
|
|
164
|
+
if val is not None
|
|
165
|
+
]
|
|
166
|
+
if len(mutation_flags) > 1:
|
|
167
|
+
print(
|
|
168
|
+
"triage:scope: --add-label / --add-milestone / --ignore-label "
|
|
169
|
+
f"are mutually exclusive (got {mutation_flags}).",
|
|
170
|
+
file=sys.stderr,
|
|
171
|
+
)
|
|
172
|
+
return 2
|
|
173
|
+
|
|
174
|
+
no_action = (
|
|
175
|
+
not args.do_list
|
|
176
|
+
and not args.refresh_denominator
|
|
177
|
+
and not mutation_flags
|
|
178
|
+
and not args.diff_from_upstream
|
|
179
|
+
)
|
|
180
|
+
if no_action:
|
|
181
|
+
parser.print_help()
|
|
182
|
+
return 0
|
|
183
|
+
|
|
184
|
+
# Mutation paths run before read paths so the post-mutation
|
|
185
|
+
# --list / --diff-from-upstream view reflects the new state on a
|
|
186
|
+
# combined invocation (e.g. `task triage:scope -- --add-label=X --list`).
|
|
187
|
+
if mutation_flags:
|
|
188
|
+
rc = _handle_mutation(project_root, args)
|
|
189
|
+
if rc != 0:
|
|
190
|
+
return rc
|
|
191
|
+
|
|
192
|
+
data = ts_module._load_project_definition(project_root)
|
|
193
|
+
rules = ts_module.resolve_scope_rules(project_root, project_definition=data)
|
|
194
|
+
is_default = ts_module._is_default_applied(data)
|
|
195
|
+
|
|
196
|
+
schema_errors, _schema_warnings = ts_module.validate_scope_rules(
|
|
197
|
+
ts_module._get_raw_scope(data)
|
|
198
|
+
)
|
|
199
|
+
if schema_errors:
|
|
200
|
+
print(
|
|
201
|
+
"triage:scope: PROJECT-DEFINITION plan.policy.triageScope "
|
|
202
|
+
f"has {len(schema_errors)} validation error(s):",
|
|
203
|
+
file=sys.stderr,
|
|
204
|
+
)
|
|
205
|
+
for err in schema_errors:
|
|
206
|
+
print(f" - {err}", file=sys.stderr)
|
|
207
|
+
return 1
|
|
208
|
+
|
|
209
|
+
if args.do_list:
|
|
210
|
+
print(
|
|
211
|
+
ts_module.render_list(
|
|
212
|
+
rules, project_root=project_root, is_default=is_default
|
|
213
|
+
)
|
|
214
|
+
)
|
|
215
|
+
# D14c (#1182): --list also renders the ignore-list block so the
|
|
216
|
+
# operator sees both halves of the cache-scope contract in one
|
|
217
|
+
# pass.
|
|
218
|
+
from _triage_scope_renderers import render_ignores # local import: cap
|
|
219
|
+
|
|
220
|
+
raw_ignores = _get_raw_ignores(data)
|
|
221
|
+
print(render_ignores(raw_ignores))
|
|
222
|
+
|
|
223
|
+
if args.refresh_denominator:
|
|
224
|
+
if not args.repo or "/" not in args.repo:
|
|
225
|
+
print(
|
|
226
|
+
"triage:scope --refresh-denominator requires --repo "
|
|
227
|
+
"OWNER/NAME (or $DEFT_TRIAGE_REPO).",
|
|
228
|
+
file=sys.stderr,
|
|
229
|
+
)
|
|
230
|
+
return 2
|
|
231
|
+
if args.count is None:
|
|
232
|
+
print(
|
|
233
|
+
"triage:scope --refresh-denominator requires --count "
|
|
234
|
+
"<int> (D5 will provide the live-probe wiring; until "
|
|
235
|
+
"then a synthetic / cached count is the caller's "
|
|
236
|
+
"contract).",
|
|
237
|
+
file=sys.stderr,
|
|
238
|
+
)
|
|
239
|
+
return 2
|
|
240
|
+
cache_root = Path(args.cache_root).resolve() if args.cache_root else None
|
|
241
|
+
path = ts_module.coverage_path(
|
|
242
|
+
args.source,
|
|
243
|
+
args.repo,
|
|
244
|
+
project_root=project_root,
|
|
245
|
+
cache_root=cache_root,
|
|
246
|
+
)
|
|
247
|
+
sub_hash = ts_module.subscription_hash(rules)
|
|
248
|
+
record = ts_module.write_coverage_denominator(
|
|
249
|
+
path,
|
|
250
|
+
count=args.count,
|
|
251
|
+
subscription_hash_value=sub_hash,
|
|
252
|
+
)
|
|
253
|
+
print(
|
|
254
|
+
f"triage:scope: wrote coverage denominator "
|
|
255
|
+
f"count={record.count} "
|
|
256
|
+
f"subscription-hash={record.subscription_hash} "
|
|
257
|
+
f"path={path}"
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
if args.diff_from_upstream:
|
|
261
|
+
rc = _handle_diff_from_upstream(project_root, args)
|
|
262
|
+
if rc != 0:
|
|
263
|
+
return rc
|
|
264
|
+
|
|
265
|
+
return 0
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def _handle_mutation(project_root: Path, args: argparse.Namespace) -> int:
|
|
269
|
+
"""Dispatch the D14c --add-label / --add-milestone / --ignore-label flag."""
|
|
270
|
+
from _triage_scope_mutations import (
|
|
271
|
+
add_label_to_ignores,
|
|
272
|
+
add_label_to_scope,
|
|
273
|
+
add_milestone_to_scope,
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
try:
|
|
277
|
+
if args.add_label is not None:
|
|
278
|
+
changed, message = add_label_to_scope(project_root, args.add_label)
|
|
279
|
+
verb = "add-label"
|
|
280
|
+
elif args.add_milestone is not None:
|
|
281
|
+
changed, message = add_milestone_to_scope(
|
|
282
|
+
project_root, args.add_milestone
|
|
283
|
+
)
|
|
284
|
+
verb = "add-milestone"
|
|
285
|
+
else:
|
|
286
|
+
changed, message = add_label_to_ignores(project_root, args.ignore_label)
|
|
287
|
+
verb = "ignore-label"
|
|
288
|
+
except Exception as exc: # pylint: disable=broad-except
|
|
289
|
+
print(f"triage:scope: {exc}", file=sys.stderr)
|
|
290
|
+
return 1
|
|
291
|
+
|
|
292
|
+
stream = sys.stderr if not changed else sys.stdout
|
|
293
|
+
suffix = " (no-op)." if not changed else "."
|
|
294
|
+
print(f"triage:scope {verb}: {message}{suffix}", file=stream)
|
|
295
|
+
return 0
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def _handle_diff_from_upstream(
|
|
299
|
+
project_root: Path, args: argparse.Namespace
|
|
300
|
+
) -> int:
|
|
301
|
+
"""Dispatch the D14c --diff-from-upstream flag."""
|
|
302
|
+
if not args.repo or "/" not in args.repo:
|
|
303
|
+
print(
|
|
304
|
+
"triage:scope --diff-from-upstream requires --repo OWNER/NAME "
|
|
305
|
+
"(or $DEFT_TRIAGE_REPO).",
|
|
306
|
+
file=sys.stderr,
|
|
307
|
+
)
|
|
308
|
+
return 2
|
|
309
|
+
|
|
310
|
+
from _triage_scope_mutations import (
|
|
311
|
+
compute_diff_from_upstream,
|
|
312
|
+
fetch_upstream_labels_and_milestones,
|
|
313
|
+
render_diff_report,
|
|
314
|
+
)
|
|
315
|
+
|
|
316
|
+
try:
|
|
317
|
+
labels, milestones = fetch_upstream_labels_and_milestones(args.repo)
|
|
318
|
+
except RuntimeError as exc:
|
|
319
|
+
print(f"triage:scope --diff-from-upstream: {exc}", file=sys.stderr)
|
|
320
|
+
return 1
|
|
321
|
+
|
|
322
|
+
report = compute_diff_from_upstream(
|
|
323
|
+
project_root,
|
|
324
|
+
upstream_labels=labels,
|
|
325
|
+
upstream_milestones=milestones,
|
|
326
|
+
repo=args.repo,
|
|
327
|
+
)
|
|
328
|
+
print(render_diff_report(report))
|
|
329
|
+
return 0
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def _get_raw_ignores(data: dict | None) -> list:
|
|
333
|
+
"""Return the raw ``plan.policy.triageScopeIgnores`` list (empty when absent)."""
|
|
334
|
+
if not isinstance(data, dict):
|
|
335
|
+
return []
|
|
336
|
+
plan = data.get("plan")
|
|
337
|
+
if not isinstance(plan, dict):
|
|
338
|
+
return []
|
|
339
|
+
policy = plan.get("policy")
|
|
340
|
+
if not isinstance(policy, dict):
|
|
341
|
+
return []
|
|
342
|
+
raw = policy.get("triageScopeIgnores")
|
|
343
|
+
return raw if isinstance(raw, list) else []
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""CLI helpers for ``scripts/triage_scope_drift.py`` (D14 / #1133).
|
|
2
|
+
|
|
3
|
+
Extracted from ``scripts/triage_scope_drift.py`` so the parent module
|
|
4
|
+
stays under the 1000-line MUST cap.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import argparse
|
|
10
|
+
import os
|
|
11
|
+
import sys
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
17
|
+
parser = argparse.ArgumentParser(
|
|
18
|
+
prog="triage_scope_drift.py",
|
|
19
|
+
description=(
|
|
20
|
+
"Detect subscription drift: labels / milestones on cached open "
|
|
21
|
+
"issues that fall outside plan.policy.triageScope[]. The "
|
|
22
|
+
"framework threshold is >= 3 issues per signal (D14 / #1133). "
|
|
23
|
+
"Honors plan.policy.triageScopeIgnores[] to suppress signals "
|
|
24
|
+
"the operator has explicitly opted out of."
|
|
25
|
+
),
|
|
26
|
+
)
|
|
27
|
+
parser.add_argument(
|
|
28
|
+
"--project-root",
|
|
29
|
+
default=os.environ.get("DEFT_PROJECT_ROOT", "."),
|
|
30
|
+
help=(
|
|
31
|
+
"Path to the consumer project root (default: "
|
|
32
|
+
"$DEFT_PROJECT_ROOT or current working directory)."
|
|
33
|
+
),
|
|
34
|
+
)
|
|
35
|
+
parser.add_argument(
|
|
36
|
+
"--cache-root",
|
|
37
|
+
default=None,
|
|
38
|
+
help=(
|
|
39
|
+
"Override the cache root (default: "
|
|
40
|
+
"<project-root>/.deft-cache). Useful for tests."
|
|
41
|
+
),
|
|
42
|
+
)
|
|
43
|
+
parser.add_argument(
|
|
44
|
+
"--threshold",
|
|
45
|
+
type=int,
|
|
46
|
+
default=None,
|
|
47
|
+
help=(
|
|
48
|
+
"Override the framework threshold (default 3). Test-only; "
|
|
49
|
+
"consumer tunability is v2 scope per umbrella section 12."
|
|
50
|
+
),
|
|
51
|
+
)
|
|
52
|
+
parser.add_argument(
|
|
53
|
+
"--ignore-label",
|
|
54
|
+
default=None,
|
|
55
|
+
help=(
|
|
56
|
+
"Add a {label: <name>} entry to "
|
|
57
|
+
"plan.policy.triageScopeIgnores[] and exit. Idempotent; "
|
|
58
|
+
"re-adding an existing entry prints an informational "
|
|
59
|
+
"message and exits 0."
|
|
60
|
+
),
|
|
61
|
+
)
|
|
62
|
+
parser.add_argument(
|
|
63
|
+
"--ignore-milestone",
|
|
64
|
+
default=None,
|
|
65
|
+
help=(
|
|
66
|
+
"Add a {milestone: <name>} entry to "
|
|
67
|
+
"plan.policy.triageScopeIgnores[] and exit. Idempotent."
|
|
68
|
+
),
|
|
69
|
+
)
|
|
70
|
+
return parser
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def run_cli(argv: list[str] | None, module: Any) -> int:
|
|
74
|
+
"""Dispatch ``triage_scope_drift`` CLI args using ``module`` as backend."""
|
|
75
|
+
parser = build_parser()
|
|
76
|
+
args = parser.parse_args(argv)
|
|
77
|
+
|
|
78
|
+
project_root = Path(args.project_root).resolve()
|
|
79
|
+
if not project_root.exists() or not project_root.is_dir():
|
|
80
|
+
print(
|
|
81
|
+
f"triage:scope-drift: --project-root {project_root} does not "
|
|
82
|
+
"exist or is not a directory.",
|
|
83
|
+
file=sys.stderr,
|
|
84
|
+
)
|
|
85
|
+
return 2
|
|
86
|
+
|
|
87
|
+
if args.ignore_label is not None and args.ignore_milestone is not None:
|
|
88
|
+
print(
|
|
89
|
+
"triage:scope-drift: --ignore-label and --ignore-milestone are "
|
|
90
|
+
"mutually exclusive (pick one per invocation).",
|
|
91
|
+
file=sys.stderr,
|
|
92
|
+
)
|
|
93
|
+
return 2
|
|
94
|
+
|
|
95
|
+
if args.ignore_label is not None or args.ignore_milestone is not None:
|
|
96
|
+
try:
|
|
97
|
+
changed, message = module.add_ignore(
|
|
98
|
+
project_root,
|
|
99
|
+
label=args.ignore_label,
|
|
100
|
+
milestone=args.ignore_milestone,
|
|
101
|
+
)
|
|
102
|
+
except Exception as exc: # pylint: disable=broad-except
|
|
103
|
+
print(f"triage:scope-drift: {exc}", file=sys.stderr)
|
|
104
|
+
return 1
|
|
105
|
+
if not changed:
|
|
106
|
+
print(f"triage:scope-drift: {message} (no-op).", file=sys.stderr)
|
|
107
|
+
else:
|
|
108
|
+
print(f"triage:scope-drift: {message}.")
|
|
109
|
+
print(
|
|
110
|
+
" Next run of `task triage:scope-drift` will exclude "
|
|
111
|
+
"this signal.",
|
|
112
|
+
file=sys.stderr,
|
|
113
|
+
)
|
|
114
|
+
return 0
|
|
115
|
+
|
|
116
|
+
cache_root = Path(args.cache_root).resolve() if args.cache_root else None
|
|
117
|
+
report = module.compute_drift(
|
|
118
|
+
project_root, cache_root=cache_root, threshold=args.threshold
|
|
119
|
+
)
|
|
120
|
+
print(module.render_drift_report(report))
|
|
121
|
+
return 0
|