@deftai/directive-content 0.59.0 → 0.60.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.
Files changed (184) hide show
  1. package/.githooks/pre-push +10 -9
  2. package/Taskfile.yml +48 -58
  3. package/UPGRADING.md +1 -1
  4. package/docs/assets/directive-lifecycle-diagram.png +0 -0
  5. package/docs/directive-lifecycle.md +73 -0
  6. package/docs/getting-started.md +5 -1
  7. package/package.json +3 -3
  8. package/packs/skills/skills-pack-0.1.json +22 -22
  9. package/scm/github.md +20 -2
  10. package/tasks/change.yml +16 -31
  11. package/tasks/ci.yml +8 -0
  12. package/tasks/commit.yml +12 -19
  13. package/tasks/core.yml +10 -0
  14. package/tasks/engine.yml +42 -0
  15. package/tasks/framework.yml +3 -0
  16. package/tasks/install.yml +20 -19
  17. package/tasks/migrate.yml +26 -15
  18. package/tasks/project.yml +16 -0
  19. package/tasks/toolchain.yml +15 -5
  20. package/tasks/vbrief.yml +4 -3
  21. package/tasks/verify.yml +12 -14
  22. package/scripts/_agents_md.py +0 -494
  23. package/scripts/_cache_fetch.py +0 -635
  24. package/scripts/_cache_quota.py +0 -529
  25. package/scripts/_cache_refresh.py +0 -163
  26. package/scripts/_cache_validate.py +0 -209
  27. package/scripts/_content_root.py +0 -42
  28. package/scripts/_doctor_state.py +0 -277
  29. package/scripts/_event_detect.py +0 -305
  30. package/scripts/_events.py +0 -514
  31. package/scripts/_lifecycle_hygiene.py +0 -568
  32. package/scripts/_pathspec.py +0 -91
  33. package/scripts/_policy_show_cli.py +0 -266
  34. package/scripts/_precutover.py +0 -92
  35. package/scripts/_project_context.py +0 -224
  36. package/scripts/_project_definition_io.py +0 -164
  37. package/scripts/_relocate_snapshot.py +0 -209
  38. package/scripts/_relocate_states.py +0 -343
  39. package/scripts/_resolve_preflight_path.py +0 -152
  40. package/scripts/_safe_subprocess.py +0 -167
  41. package/scripts/_session_start_hook.py +0 -205
  42. package/scripts/_sor_gate_diff.py +0 -365
  43. package/scripts/_stdio_utf8.py +0 -59
  44. package/scripts/_triage_bootstrap_gitignore.py +0 -904
  45. package/scripts/_triage_classify_cli.py +0 -122
  46. package/scripts/_triage_queue_cli.py +0 -625
  47. package/scripts/_triage_scope_cli.py +0 -343
  48. package/scripts/_triage_scope_drift_cli.py +0 -121
  49. package/scripts/_triage_scope_ignores.py +0 -286
  50. package/scripts/_triage_scope_milestone.py +0 -432
  51. package/scripts/_triage_scope_mutations.py +0 -337
  52. package/scripts/_triage_scope_renderers.py +0 -207
  53. package/scripts/_triage_smoketest_stages.py +0 -674
  54. package/scripts/_triage_subscribe_cli.py +0 -140
  55. package/scripts/_triage_welcome_cli.py +0 -421
  56. package/scripts/_vbrief_build.py +0 -239
  57. package/scripts/_vbrief_fidelity.py +0 -479
  58. package/scripts/_vbrief_legacy.py +0 -589
  59. package/scripts/_vbrief_reconciliation.py +0 -883
  60. package/scripts/_vbrief_routing.py +0 -277
  61. package/scripts/_vbrief_safety.py +0 -778
  62. package/scripts/_vbrief_sources.py +0 -312
  63. package/scripts/_vbrief_speckit.py +0 -262
  64. package/scripts/_vbrief_story_quality.py +0 -353
  65. package/scripts/_vbrief_validation.py +0 -299
  66. package/scripts/build_dist.py +0 -412
  67. package/scripts/cache.py +0 -1078
  68. package/scripts/cache_scanner.py +0 -745
  69. package/scripts/candidates_log.py +0 -432
  70. package/scripts/capacity_backfill.py +0 -680
  71. package/scripts/capacity_show.py +0 -653
  72. package/scripts/ci_local.py +0 -689
  73. package/scripts/code_structure_validate.py +0 -765
  74. package/scripts/codebase_default_extractor.py +0 -495
  75. package/scripts/codebase_map.py +0 -304
  76. package/scripts/codebase_map_fresh.py +0 -104
  77. package/scripts/codebase_projection_registry.py +0 -94
  78. package/scripts/codebase_provider.py +0 -582
  79. package/scripts/doctor.py +0 -2552
  80. package/scripts/framework_commands.py +0 -505
  81. package/scripts/gh_rest.py +0 -882
  82. package/scripts/github_auth_modes.py +0 -437
  83. package/scripts/github_body.py +0 -292
  84. package/scripts/ip_risk.py +0 -531
  85. package/scripts/issue_emit.py +0 -670
  86. package/scripts/issue_ingest.py +0 -1064
  87. package/scripts/migrate_preflight.py +0 -418
  88. package/scripts/migrate_vbrief.py +0 -2677
  89. package/scripts/monitor_pr.py +0 -401
  90. package/scripts/pack_migrate_lessons.py +0 -336
  91. package/scripts/pack_migrate_patterns.py +0 -254
  92. package/scripts/pack_migrate_rules.py +0 -350
  93. package/scripts/pack_migrate_skills.py +0 -423
  94. package/scripts/pack_migrate_strategies.py +0 -311
  95. package/scripts/pack_migrate_swarm_spec.py +0 -250
  96. package/scripts/pack_render.py +0 -434
  97. package/scripts/packs_slice.py +0 -712
  98. package/scripts/platform_capabilities.py +0 -336
  99. package/scripts/policy.py +0 -2826
  100. package/scripts/policy_set.py +0 -324
  101. package/scripts/pr_check_closing_keywords.py +0 -524
  102. package/scripts/pr_check_protected_issues.py +0 -267
  103. package/scripts/pr_merge_readiness.py +0 -1004
  104. package/scripts/pr_wait_mergeable.py +0 -669
  105. package/scripts/prd_render.py +0 -159
  106. package/scripts/preflight_architecture_sor.py +0 -974
  107. package/scripts/preflight_branch.py +0 -289
  108. package/scripts/preflight_cache.py +0 -974
  109. package/scripts/preflight_gh.py +0 -721
  110. package/scripts/preflight_implementation.py +0 -272
  111. package/scripts/preflight_story_start.py +0 -838
  112. package/scripts/preflight_wip_cap.py +0 -149
  113. package/scripts/probe_session.py +0 -545
  114. package/scripts/project_render.py +0 -293
  115. package/scripts/quarantine_ext.py +0 -237
  116. package/scripts/reconcile_issues.py +0 -1442
  117. package/scripts/refresh-path.ps1 +0 -107
  118. package/scripts/release.py +0 -2030
  119. package/scripts/release_e2e.py +0 -1011
  120. package/scripts/release_publish.py +0 -486
  121. package/scripts/release_rollback.py +0 -980
  122. package/scripts/relocate.py +0 -1034
  123. package/scripts/resolve_changelog_unreleased.py +0 -667
  124. package/scripts/resolve_version.py +0 -490
  125. package/scripts/resume_conditions.py +0 -706
  126. package/scripts/ritual_sentinel.py +0 -609
  127. package/scripts/roadmap_render.py +0 -635
  128. package/scripts/rule_ownership_lint.py +0 -325
  129. package/scripts/scm.py +0 -591
  130. package/scripts/scope_audit_log.py +0 -387
  131. package/scripts/scope_decompose.py +0 -654
  132. package/scripts/scope_demote.py +0 -509
  133. package/scripts/scope_lifecycle.py +0 -1126
  134. package/scripts/scope_undo.py +0 -772
  135. package/scripts/session_start.py +0 -406
  136. package/scripts/setup_ghx.py +0 -339
  137. package/scripts/setup_windows.ps1 +0 -220
  138. package/scripts/slice_audit.py +0 -585
  139. package/scripts/slice_record.py +0 -530
  140. package/scripts/slice_record_existing.py +0 -692
  141. package/scripts/slug_normalize.py +0 -178
  142. package/scripts/spec_render.py +0 -477
  143. package/scripts/spec_validate.py +0 -238
  144. package/scripts/subagent_monitor.py +0 -658
  145. package/scripts/swarm_complete_cohort.py +0 -644
  146. package/scripts/swarm_launch.py +0 -1206
  147. package/scripts/swarm_readiness.py +0 -554
  148. package/scripts/swarm_verify_review_clean.py +0 -438
  149. package/scripts/swarm_worktrees.py +0 -497
  150. package/scripts/toolchain-check.py +0 -52
  151. package/scripts/triage_actions.py +0 -871
  152. package/scripts/triage_bootstrap.py +0 -1153
  153. package/scripts/triage_bulk.py +0 -630
  154. package/scripts/triage_classify.py +0 -932
  155. package/scripts/triage_help.py +0 -1685
  156. package/scripts/triage_queue.py +0 -1944
  157. package/scripts/triage_reconcile.py +0 -581
  158. package/scripts/triage_refresh.py +0 -643
  159. package/scripts/triage_scope.py +0 -999
  160. package/scripts/triage_scope_drift.py +0 -575
  161. package/scripts/triage_smoketest.py +0 -396
  162. package/scripts/triage_subscribe.py +0 -399
  163. package/scripts/triage_summary.py +0 -1011
  164. package/scripts/triage_welcome.py +0 -1178
  165. package/scripts/ts_check_lane.py +0 -86
  166. package/scripts/validate-links.py +0 -64
  167. package/scripts/validate_strategy_output.py +0 -212
  168. package/scripts/vbrief_activate.py +0 -228
  169. package/scripts/vbrief_migrate_conformance.py +0 -368
  170. package/scripts/vbrief_reconcile_graph.py +0 -306
  171. package/scripts/vbrief_reconcile_labels.py +0 -460
  172. package/scripts/vbrief_reconcile_umbrellas.py +0 -741
  173. package/scripts/vbrief_validate.py +0 -1144
  174. package/scripts/verify-stubs.py +0 -61
  175. package/scripts/verify_capacity.py +0 -160
  176. package/scripts/verify_encoding.py +0 -699
  177. package/scripts/verify_hooks_installed.py +0 -206
  178. package/scripts/verify_investigation.py +0 -360
  179. package/scripts/verify_judgment_gates.py +0 -827
  180. package/scripts/verify_no_task_runtime.py +0 -171
  181. package/scripts/verify_scm_boundary.py +0 -509
  182. package/scripts/verify_session_ritual.py +0 -389
  183. package/scripts/verify_tools.py +0 -426
  184. package/scripts/verify_vbrief_conformance.py +0 -478
@@ -1,343 +0,0 @@
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 []
@@ -1,121 +0,0 @@
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