@deftai/directive-content 0.58.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 (187) hide show
  1. package/.githooks/pre-push +10 -9
  2. package/Taskfile.yml +57 -67
  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/rules/rules-pack-0.1.json +3 -3
  9. package/packs/skills/skills-pack-0.1.json +22 -22
  10. package/scm/github.md +20 -2
  11. package/tasks/change.yml +16 -31
  12. package/tasks/ci.yml +8 -0
  13. package/tasks/commit.yml +12 -19
  14. package/tasks/core.yml +10 -0
  15. package/tasks/engine.yml +42 -0
  16. package/tasks/framework.yml +3 -0
  17. package/tasks/install.yml +20 -19
  18. package/tasks/migrate.yml +26 -15
  19. package/tasks/project.yml +16 -0
  20. package/tasks/relocate.yml +18 -48
  21. package/tasks/toolchain.yml +15 -5
  22. package/tasks/vbrief.yml +4 -3
  23. package/tasks/verify.yml +12 -14
  24. package/templates/agents-entry.md +1 -2
  25. package/scripts/_agents_md.py +0 -494
  26. package/scripts/_cache_fetch.py +0 -635
  27. package/scripts/_cache_quota.py +0 -529
  28. package/scripts/_cache_refresh.py +0 -163
  29. package/scripts/_cache_validate.py +0 -209
  30. package/scripts/_content_root.py +0 -42
  31. package/scripts/_doctor_state.py +0 -277
  32. package/scripts/_event_detect.py +0 -305
  33. package/scripts/_events.py +0 -514
  34. package/scripts/_lifecycle_hygiene.py +0 -568
  35. package/scripts/_pathspec.py +0 -91
  36. package/scripts/_policy_show_cli.py +0 -266
  37. package/scripts/_precutover.py +0 -92
  38. package/scripts/_project_context.py +0 -224
  39. package/scripts/_project_definition_io.py +0 -164
  40. package/scripts/_relocate_snapshot.py +0 -209
  41. package/scripts/_relocate_states.py +0 -343
  42. package/scripts/_resolve_preflight_path.py +0 -152
  43. package/scripts/_safe_subprocess.py +0 -167
  44. package/scripts/_session_start_hook.py +0 -205
  45. package/scripts/_sor_gate_diff.py +0 -365
  46. package/scripts/_stdio_utf8.py +0 -59
  47. package/scripts/_triage_bootstrap_gitignore.py +0 -904
  48. package/scripts/_triage_classify_cli.py +0 -122
  49. package/scripts/_triage_queue_cli.py +0 -625
  50. package/scripts/_triage_scope_cli.py +0 -343
  51. package/scripts/_triage_scope_drift_cli.py +0 -121
  52. package/scripts/_triage_scope_ignores.py +0 -286
  53. package/scripts/_triage_scope_milestone.py +0 -432
  54. package/scripts/_triage_scope_mutations.py +0 -337
  55. package/scripts/_triage_scope_renderers.py +0 -207
  56. package/scripts/_triage_smoketest_stages.py +0 -674
  57. package/scripts/_triage_subscribe_cli.py +0 -140
  58. package/scripts/_triage_welcome_cli.py +0 -421
  59. package/scripts/_vbrief_build.py +0 -239
  60. package/scripts/_vbrief_fidelity.py +0 -479
  61. package/scripts/_vbrief_legacy.py +0 -589
  62. package/scripts/_vbrief_reconciliation.py +0 -883
  63. package/scripts/_vbrief_routing.py +0 -277
  64. package/scripts/_vbrief_safety.py +0 -778
  65. package/scripts/_vbrief_sources.py +0 -312
  66. package/scripts/_vbrief_speckit.py +0 -262
  67. package/scripts/_vbrief_story_quality.py +0 -353
  68. package/scripts/_vbrief_validation.py +0 -299
  69. package/scripts/build_dist.py +0 -412
  70. package/scripts/cache.py +0 -1078
  71. package/scripts/cache_scanner.py +0 -745
  72. package/scripts/candidates_log.py +0 -432
  73. package/scripts/capacity_backfill.py +0 -680
  74. package/scripts/capacity_show.py +0 -653
  75. package/scripts/ci_local.py +0 -689
  76. package/scripts/code_structure_validate.py +0 -765
  77. package/scripts/codebase_default_extractor.py +0 -495
  78. package/scripts/codebase_map.py +0 -304
  79. package/scripts/codebase_map_fresh.py +0 -104
  80. package/scripts/codebase_projection_registry.py +0 -94
  81. package/scripts/codebase_provider.py +0 -582
  82. package/scripts/doctor.py +0 -2551
  83. package/scripts/framework_commands.py +0 -505
  84. package/scripts/gh_rest.py +0 -882
  85. package/scripts/github_auth_modes.py +0 -437
  86. package/scripts/github_body.py +0 -292
  87. package/scripts/ip_risk.py +0 -531
  88. package/scripts/issue_emit.py +0 -670
  89. package/scripts/issue_ingest.py +0 -1064
  90. package/scripts/migrate_preflight.py +0 -418
  91. package/scripts/migrate_vbrief.py +0 -2677
  92. package/scripts/monitor_pr.py +0 -401
  93. package/scripts/pack_migrate_lessons.py +0 -336
  94. package/scripts/pack_migrate_patterns.py +0 -254
  95. package/scripts/pack_migrate_rules.py +0 -350
  96. package/scripts/pack_migrate_skills.py +0 -423
  97. package/scripts/pack_migrate_strategies.py +0 -311
  98. package/scripts/pack_migrate_swarm_spec.py +0 -250
  99. package/scripts/pack_render.py +0 -434
  100. package/scripts/packs_slice.py +0 -712
  101. package/scripts/platform_capabilities.py +0 -336
  102. package/scripts/policy.py +0 -2826
  103. package/scripts/policy_set.py +0 -324
  104. package/scripts/pr_check_closing_keywords.py +0 -524
  105. package/scripts/pr_check_protected_issues.py +0 -267
  106. package/scripts/pr_merge_readiness.py +0 -1004
  107. package/scripts/pr_wait_mergeable.py +0 -669
  108. package/scripts/prd_render.py +0 -159
  109. package/scripts/preflight_architecture_sor.py +0 -974
  110. package/scripts/preflight_branch.py +0 -289
  111. package/scripts/preflight_cache.py +0 -974
  112. package/scripts/preflight_gh.py +0 -721
  113. package/scripts/preflight_implementation.py +0 -272
  114. package/scripts/preflight_story_start.py +0 -838
  115. package/scripts/preflight_wip_cap.py +0 -149
  116. package/scripts/probe_session.py +0 -545
  117. package/scripts/project_render.py +0 -293
  118. package/scripts/quarantine_ext.py +0 -237
  119. package/scripts/reconcile_issues.py +0 -1442
  120. package/scripts/refresh-path.ps1 +0 -107
  121. package/scripts/release.py +0 -2030
  122. package/scripts/release_e2e.py +0 -1011
  123. package/scripts/release_publish.py +0 -486
  124. package/scripts/release_rollback.py +0 -980
  125. package/scripts/relocate.py +0 -1034
  126. package/scripts/resolve_changelog_unreleased.py +0 -667
  127. package/scripts/resolve_version.py +0 -490
  128. package/scripts/resume_conditions.py +0 -706
  129. package/scripts/ritual_sentinel.py +0 -609
  130. package/scripts/roadmap_render.py +0 -635
  131. package/scripts/rule_ownership_lint.py +0 -325
  132. package/scripts/scm.py +0 -591
  133. package/scripts/scope_audit_log.py +0 -387
  134. package/scripts/scope_decompose.py +0 -654
  135. package/scripts/scope_demote.py +0 -509
  136. package/scripts/scope_lifecycle.py +0 -1126
  137. package/scripts/scope_undo.py +0 -772
  138. package/scripts/session_start.py +0 -406
  139. package/scripts/setup_ghx.py +0 -339
  140. package/scripts/setup_windows.ps1 +0 -220
  141. package/scripts/slice_audit.py +0 -585
  142. package/scripts/slice_record.py +0 -530
  143. package/scripts/slice_record_existing.py +0 -692
  144. package/scripts/slug_normalize.py +0 -178
  145. package/scripts/spec_render.py +0 -477
  146. package/scripts/spec_validate.py +0 -238
  147. package/scripts/subagent_monitor.py +0 -658
  148. package/scripts/swarm_complete_cohort.py +0 -644
  149. package/scripts/swarm_launch.py +0 -1206
  150. package/scripts/swarm_readiness.py +0 -554
  151. package/scripts/swarm_verify_review_clean.py +0 -438
  152. package/scripts/swarm_worktrees.py +0 -497
  153. package/scripts/toolchain-check.py +0 -52
  154. package/scripts/triage_actions.py +0 -871
  155. package/scripts/triage_bootstrap.py +0 -1153
  156. package/scripts/triage_bulk.py +0 -630
  157. package/scripts/triage_classify.py +0 -932
  158. package/scripts/triage_help.py +0 -1685
  159. package/scripts/triage_queue.py +0 -1944
  160. package/scripts/triage_reconcile.py +0 -581
  161. package/scripts/triage_refresh.py +0 -643
  162. package/scripts/triage_scope.py +0 -999
  163. package/scripts/triage_scope_drift.py +0 -575
  164. package/scripts/triage_smoketest.py +0 -396
  165. package/scripts/triage_subscribe.py +0 -399
  166. package/scripts/triage_summary.py +0 -1011
  167. package/scripts/triage_welcome.py +0 -1178
  168. package/scripts/ts_check_lane.py +0 -86
  169. package/scripts/validate-links.py +0 -64
  170. package/scripts/validate_strategy_output.py +0 -212
  171. package/scripts/vbrief_activate.py +0 -228
  172. package/scripts/vbrief_migrate_conformance.py +0 -368
  173. package/scripts/vbrief_reconcile_graph.py +0 -306
  174. package/scripts/vbrief_reconcile_labels.py +0 -460
  175. package/scripts/vbrief_reconcile_umbrellas.py +0 -741
  176. package/scripts/vbrief_validate.py +0 -1144
  177. package/scripts/verify-stubs.py +0 -61
  178. package/scripts/verify_capacity.py +0 -160
  179. package/scripts/verify_encoding.py +0 -699
  180. package/scripts/verify_hooks_installed.py +0 -206
  181. package/scripts/verify_investigation.py +0 -360
  182. package/scripts/verify_judgment_gates.py +0 -827
  183. package/scripts/verify_no_task_runtime.py +0 -171
  184. package/scripts/verify_scm_boundary.py +0 -509
  185. package/scripts/verify_session_ritual.py +0 -389
  186. package/scripts/verify_tools.py +0 -426
  187. package/scripts/verify_vbrief_conformance.py +0 -478
@@ -1,625 +0,0 @@
1
- """CLI helpers for ``scripts/triage_queue.py`` (#1128).
2
-
3
- Extracted from ``scripts/triage_queue.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_queue``; this module is the argparse
6
- shim and command dispatcher only.
7
-
8
- Repo resolution (#1246)
9
- -----------------------
10
- The ``triage:queue`` / ``triage:show`` / ``triage:audit`` CLI surfaces
11
- resolve ``--repo`` with the precedence: explicit ``--repo`` flag >
12
- ``$DEFT_TRIAGE_REPO`` env var > auto-detection from
13
- ``git remote get-url origin`` (run inside ``--project-root``) > error.
14
- The auto-detection step removes the most-common-path papercut where an
15
- operator inside an unambiguous clone had to repeat the repo slug on
16
- every invocation. Cross-repo invocations remain supported via the
17
- explicit flag (highest precedence).
18
- """
19
-
20
- from __future__ import annotations
21
-
22
- import argparse
23
- import contextlib
24
- import os
25
- import re
26
- import subprocess
27
- import sys
28
- from pathlib import Path
29
- from typing import Any
30
-
31
- # Make sibling scripts importable when invoked via Taskfile + uv.
32
- sys.path.insert(0, str(Path(__file__).resolve().parent))
33
-
34
- # Optional: slice_audit ships in the same wave as this CLI (#1132 / D13).
35
- # Guarded so an out-of-band import on a slim test checkout does not break.
36
- try: # pragma: no cover -- exercised once #1132 lands.
37
- import slice_audit # type: ignore[import-not-found]
38
- except ImportError: # pragma: no cover
39
- slice_audit = None # type: ignore[assignment]
40
-
41
-
42
- def _add_common_args(parser: argparse.ArgumentParser) -> None:
43
- parser.add_argument(
44
- "--project-root",
45
- default=os.environ.get("DEFT_PROJECT_ROOT", "."),
46
- help=(
47
- "Path to the consumer project root (default: $DEFT_PROJECT_ROOT or"
48
- " the current working directory)."
49
- ),
50
- )
51
- parser.add_argument(
52
- "--repo",
53
- default=os.environ.get("DEFT_TRIAGE_REPO"),
54
- help=("Upstream repo slug 'owner/name'. Falls back to $DEFT_TRIAGE_REPO."),
55
- )
56
- parser.add_argument(
57
- "--cache-root",
58
- default=None,
59
- help="Override the cache root (default: <project-root>/.deft-cache).",
60
- )
61
- parser.add_argument(
62
- "--audit-log",
63
- default=None,
64
- help=(
65
- "Override the audit log path (default: <project-root>/"
66
- "vbrief/.eval/candidates.jsonl). Test hook."
67
- ),
68
- )
69
- parser.add_argument(
70
- "--slices-log",
71
- default=None,
72
- help=(
73
- "Override the slices.jsonl path (default: <project-root>/"
74
- "vbrief/.eval/slices.jsonl). Test hook for #1132 / D13."
75
- ),
76
- )
77
-
78
-
79
- def build_parser(default_limit: int) -> argparse.ArgumentParser:
80
- parser = argparse.ArgumentParser(
81
- prog="triage_queue.py",
82
- description=("Ranked triage queue + per-item show + audit-log surface (#1128)."),
83
- )
84
- sub = parser.add_subparsers(dest="cmd", required=True)
85
-
86
- p_queue = sub.add_parser("queue", help="Print the ranked triage queue.")
87
- _add_common_args(p_queue)
88
- p_queue.add_argument(
89
- "--limit",
90
- type=int,
91
- default=default_limit,
92
- help=(
93
- f"Cap the number of rows printed (default: {default_limit}). Pass 0 to disable the cap."
94
- ),
95
- )
96
- p_queue.add_argument(
97
- "--include-blocked",
98
- action="store_true",
99
- dest="include_blocked",
100
- help=(
101
- "Re-surface items whose linked vBRIEF is blocked (plan.status:blocked"
102
- " or an unresolved swarm.depends_on) into their natural group. By"
103
- " default such items are demoted into the [BLOCKED] group (#1286)."
104
- ),
105
- )
106
-
107
- p_show = sub.add_parser(
108
- "show",
109
- help="Print per-issue triage detail (read-only).",
110
- )
111
- _add_common_args(p_show)
112
- p_show.add_argument(
113
- "number",
114
- type=int,
115
- help="Upstream issue number, e.g. 1128.",
116
- )
117
-
118
- p_audit = sub.add_parser(
119
- "audit",
120
- help="Print the audit-log surface (plain text or --format=json).",
121
- )
122
- _add_common_args(p_audit)
123
- p_audit.add_argument(
124
- "--format",
125
- # 'text' is an alias for 'plain' so the documented surface
126
- # ('--format=text|json' in the #1180 issue body and the D6 skill)
127
- # matches the implementation surface (D11 shipped 'plain'|'json').
128
- choices=("plain", "text", "json"),
129
- default="plain",
130
- help=(
131
- "Output format. 'json' emits the stable schema consumed by D2"
132
- " (#1122) for triage:summary integration. 'text' is an alias"
133
- " for 'plain'."
134
- ),
135
- )
136
- p_audit.add_argument(
137
- "--vbrief-staleness",
138
- action="store_true",
139
- help=(
140
- "Filter to audit entries whose latest 'accept' decision lacks an"
141
- " active-vBRIEF reference. Used by D4 (#1124)."
142
- ),
143
- )
144
- p_audit.add_argument(
145
- "--evaluate-resume",
146
- action="store_true",
147
- dest="evaluate_resume",
148
- help=(
149
- "Before rendering, walk every open 'defer' audit entry whose"
150
- " resume_on field is non-null and append a 'resume-eligible'"
151
- " entry for each condition that fires (#1123 / D3)."
152
- " Idempotent."
153
- ),
154
- )
155
- # Date filters (#1180) -- distinct argparse group so the parallel D13
156
- # 'Slice operations' group on the same subparser does not textually
157
- # overlap during rebase. Both flags are optional + composable; an
158
- # unset flag keeps D11's original behaviour (full audit-log dump).
159
- date_filters = p_audit.add_argument_group(
160
- "Date filters (#1180)",
161
- "Read-only filters over the audit log; transform with jq.",
162
- )
163
- date_filters.add_argument(
164
- "--action",
165
- default=None,
166
- help=(
167
- "Filter to audit entries whose `decision` equals <verb> (e.g."
168
- " --action=demote-meta, --action=accept). v1 accepts a single"
169
- " verb; pipe through jq for multi-verb queries. Invalid verb"
170
- " -> exit 2 with explanatory stderr."
171
- ),
172
- )
173
- date_filters.add_argument(
174
- "--since",
175
- default=None,
176
- help=(
177
- "Filter to entries whose timestamp is at-or-after now - <window>."
178
- " Accepts the framework duration grammar: Nd / Nh / Nm / Nw / Ns"
179
- " (e.g. '7d', '24h', '30m') or ISO-8601 PnDTnHnMnS (e.g. 'P7D',"
180
- " 'PT24H'). Invalid -> exit 2 with explanatory stderr."
181
- ),
182
- )
183
-
184
- # ----- Slice operations (#1132 / D13) -----
185
- #
186
- # Each of the three flags below selects a distinct slice-related
187
- # surface; they are mutually exclusive (the CLI picks the first one
188
- # set and emits its renderer instead of the default audit dump).
189
- # Kept as a distinct argparse group so #1180's date-filter flags can
190
- # land as a separate `Date filters` group without textual overlap.
191
- slice_group = p_audit.add_argument_group(
192
- "Slice operations (#1132 / D13)",
193
- "Read-only surfaces that join slices.jsonl against the cache.",
194
- )
195
- slice_group.add_argument(
196
- "--orphans",
197
- action="store_true",
198
- help=(
199
- "List children whose umbrella issue is closed while they remain"
200
- " open. Output: one line per orphan with umbrella back-pointer."
201
- ),
202
- )
203
- slice_group.add_argument(
204
- "--slice-stalled",
205
- action="store_true",
206
- dest="slice_stalled",
207
- help=(
208
- "List cohorts where >=1 child has merged but >=1 sibling has"
209
- " not moved in --days days (default 30)."
210
- ),
211
- )
212
- slice_group.add_argument(
213
- "--slice-coverage",
214
- action="store_true",
215
- dest="slice_coverage",
216
- help=(
217
- "For each open umbrella in slices.jsonl, print"
218
- " <umbrella>: <closed>/<total> children merged."
219
- ),
220
- )
221
- slice_group.add_argument(
222
- "--days",
223
- type=int,
224
- default=None,
225
- help=(
226
- "Stall window in days for --slice-stalled (default 30)."
227
- " No effect without --slice-stalled."
228
- ),
229
- )
230
-
231
- return parser
232
-
233
-
234
- #: subprocess.run timeout for ``git remote get-url origin`` auto-detection
235
- #: (#1246). Defensive: a stuck ``git`` proxy (corporate VPN re-auth) would
236
- #: otherwise hang every ``task triage:queue`` invocation indefinitely.
237
- _GIT_INFER_TIMEOUT_S: int = 10
238
-
239
-
240
- def _detect_origin_repo(project_root: Path | None) -> str | None:
241
- """Return ``owner/name`` parsed from ``git remote get-url origin``, or ``None``.
242
-
243
- Run inside ``project_root`` (or the current working directory when
244
- ``project_root`` is ``None``). Returns ``None`` on any of:
245
-
246
- * ``git`` not on PATH.
247
- * ``git remote get-url origin`` exits non-zero (outside a git working
248
- tree, or no ``origin`` remote configured).
249
- * The subprocess hangs past :data:`_GIT_INFER_TIMEOUT_S` seconds --
250
- defensive against a wedged credential helper / VPN re-auth.
251
- * The origin URL is not a recognised ``github.com`` form (https /
252
- ssh / git@ shapes).
253
-
254
- Delegated to ``scripts/_project_context.py::_detect_repo_from_git``
255
- where importable so the framework keeps a single origin-detection
256
- grammar; falls back to an inline implementation only on slim test
257
- checkouts that have not yet rebased onto that module.
258
- """
259
- try:
260
- from _project_context import _detect_repo_from_git
261
- except ImportError: # pragma: no cover -- slim-checkout fallback
262
- return _detect_origin_repo_inline(project_root)
263
- return _detect_repo_from_git(project_root)
264
-
265
-
266
- def _detect_origin_repo_inline(project_root: Path | None) -> str | None:
267
- """Fallback origin-detector used when ``_project_context`` is unimportable.
268
-
269
- Mirrors the precedence + parsing rules of the canonical helper so
270
- consumers on a slim test checkout still get the #1246 papercut
271
- eliminated. Returns ``None`` when detection fails so the caller can
272
- surface the canonical "--repo required" error.
273
- """
274
- cwd = str(project_root) if project_root is not None else None
275
- try:
276
- result = subprocess.run( # noqa: S603 -- argv is a literal
277
- ["git", "remote", "get-url", "origin"],
278
- capture_output=True,
279
- text=True,
280
- check=False,
281
- cwd=cwd,
282
- timeout=_GIT_INFER_TIMEOUT_S,
283
- )
284
- except (FileNotFoundError, OSError, subprocess.SubprocessError):
285
- return None
286
- if result.returncode != 0:
287
- return None
288
- url = (result.stdout or "").strip()
289
- if not url:
290
- return None
291
- match = re.search(
292
- r"github\.com[:/]([A-Za-z0-9][A-Za-z0-9._-]*)/"
293
- r"([A-Za-z0-9][A-Za-z0-9._-]*?)(?:\.git)?/?\s*$",
294
- url,
295
- )
296
- if not match:
297
- return None
298
- return f"{match.group(1)}/{match.group(2)}"
299
-
300
-
301
- def _resolve_repo(args: argparse.Namespace) -> str | None:
302
- """Resolve the effective ``--repo`` slug for triage_queue CLI verbs.
303
-
304
- Delegates to the canonical :func:`triage_queue._resolve_repo` (#1238)
305
- so the resolution chain lives in the documented module and stays in
306
- lockstep with ``preflight_cache`` / ``triage_bootstrap``. Precedence,
307
- highest first:
308
-
309
- 1. ``args.repo`` -- the explicit ``--repo`` flag, which also picks up
310
- ``$DEFT_TRIAGE_REPO`` because the argparse default reads the env
311
- var. Highest precedence; preserved for cross-repo invocations.
312
- 2. ``$DEFT_TRIAGE_REPO`` -- the canonical helper re-checks the env var
313
- so the precedence is honoured even when a caller constructs the
314
- namespace without the argparse env default.
315
- 3. ``git remote get-url origin`` parsed from inside
316
- ``--project-root`` (or the current working directory). Removes
317
- the papercut where an operator inside an unambiguous clone had
318
- to repeat the repo slug on every ``task triage:queue`` call.
319
- 4. ``None`` -- the caller emits the canonical
320
- ``triage:<verb>: --repo OWNER/NAME (or $DEFT_TRIAGE_REPO) is
321
- required.`` error so the operator sees an actionable next step
322
- rather than a silent empty-cache walk.
323
- """
324
- import triage_queue
325
-
326
- project_root: Path | None = None
327
- if getattr(args, "project_root", None):
328
- with contextlib.suppress(OSError):
329
- project_root = Path(args.project_root).resolve()
330
- return triage_queue._resolve_repo(args.repo, project_root=project_root)
331
-
332
-
333
- def _override_cache_root(project_root: Path, cache_root: Path) -> None:
334
- """Best-effort symlink so the cache walker finds ``cache_root``.
335
-
336
- Used only by the ``--cache-root`` test hook. The function is a no-op
337
- on Windows without admin / dev mode (symlink creation rejected); the
338
- test path falls through and passes ``--project-root`` at the cache
339
- root instead.
340
- """
341
- target = project_root / ".deft-cache"
342
- if target.exists():
343
- with contextlib.suppress(OSError):
344
- if target.resolve() == cache_root.resolve():
345
- return
346
- return
347
- with contextlib.suppress(OSError):
348
- target.symlink_to(cache_root, target_is_directory=True)
349
-
350
-
351
- def _cmd_queue(args: argparse.Namespace, tq: Any) -> int:
352
- repo = _resolve_repo(args)
353
- if not repo:
354
- print(
355
- "triage:queue: --repo OWNER/NAME (or $DEFT_TRIAGE_REPO) is required.",
356
- file=sys.stderr,
357
- )
358
- return 2
359
- project_root = Path(args.project_root).resolve()
360
- if args.cache_root:
361
- _override_cache_root(project_root, Path(args.cache_root).resolve())
362
- # Load both open and closed issues so the orphan detection in #1132
363
- # can see closed umbrellas; the queue itself still filters to open
364
- # children via the QueueBuildOptions.orphan_issue_numbers set.
365
- issues_for_queue = tq.load_cached_issues(repo, project_root=project_root)
366
- issues_with_closed = tq.load_cached_issues(repo, project_root=project_root, include_closed=True)
367
- issues_by_number = {i["number"]: i for i in issues_with_closed}
368
- audit_entries = tq.read_audit_entries(repo, audit_path=args.audit_log)
369
- ranking_labels = tuple(tq.resolve_ranking_labels(project_root))
370
- active_refs = frozenset(tq._active_referenced_issue_numbers(project_root))
371
- orphan_numbers: frozenset[int] = frozenset()
372
- if slice_audit is not None:
373
- records = slice_audit.load_slice_records(tq.slice_record, path=args.slices_log)
374
- orphan_numbers = slice_audit.collect_orphan_issue_numbers(records, issues_by_number)
375
- limit = None if args.limit == 0 else max(0, int(args.limit))
376
- options = tq.QueueBuildOptions(
377
- ranking_labels=ranking_labels,
378
- active_referenced=active_refs,
379
- orphan_issue_numbers=orphan_numbers,
380
- include_blocked=getattr(args, "include_blocked", False),
381
- limit=limit,
382
- )
383
- items = tq.build_queue(issues_for_queue, audit_entries, repo=repo, options=options)
384
- print(
385
- tq.render_queue(
386
- items,
387
- repo=repo,
388
- limit=limit,
389
- ranking_labels=ranking_labels,
390
- )
391
- )
392
- return 0
393
-
394
-
395
- def _cmd_show(args: argparse.Namespace, tq: Any) -> int:
396
- repo = _resolve_repo(args)
397
- if not repo:
398
- print(
399
- "triage:show: --repo OWNER/NAME (or $DEFT_TRIAGE_REPO) is required.",
400
- file=sys.stderr,
401
- )
402
- return 2
403
- project_root = Path(args.project_root).resolve()
404
- if args.cache_root:
405
- _override_cache_root(project_root, Path(args.cache_root).resolve())
406
- issues = {
407
- i["number"]: i
408
- for i in tq.load_cached_issues(repo, project_root=project_root, include_closed=True)
409
- }
410
- issue = issues.get(int(args.number))
411
- history: list[dict[str, Any]] = []
412
- if tq.candidates_log is not None:
413
- history = list(tq.candidates_log.find_by_issue(int(args.number), repo, path=args.audit_log))
414
- history_sorted = sorted(history, key=lambda r: r.get("timestamp", ""))
415
- latest = history_sorted[-1] if history_sorted else None
416
- active_refs = tq._active_referenced_issue_numbers(project_root)
417
- print(
418
- tq.render_show(
419
- issue,
420
- repo=repo,
421
- number=int(args.number),
422
- latest_decision=latest,
423
- history=history_sorted,
424
- in_active_vbrief=int(args.number) in active_refs,
425
- )
426
- )
427
- return 0 if issue is not None else 1
428
-
429
-
430
- def _cmd_audit(args: argparse.Namespace, tq: Any) -> int:
431
- repo = _resolve_repo(args)
432
- project_root = Path(args.project_root).resolve()
433
- if args.cache_root:
434
- _override_cache_root(project_root, Path(args.cache_root).resolve())
435
- # #1132 / D13: slice operation flags short-circuit the audit dump.
436
- # Mutually exclusive: first set flag wins; if more than one is
437
- # passed the chained calls render only the highest-priority one.
438
- if getattr(args, "orphans", False):
439
- return _cmd_slice_orphans(args, tq, repo=repo, project_root=project_root)
440
- if getattr(args, "slice_stalled", False):
441
- return _cmd_slice_stalled(args, tq, repo=repo, project_root=project_root)
442
- if getattr(args, "slice_coverage", False):
443
- return _cmd_slice_coverage(args, tq, repo=repo, project_root=project_root)
444
- # #1180: validate --action / --since up front so a typo fails fast
445
- # (exit 2) instead of silently returning an empty result set. Runs
446
- # AFTER the D13 slice short-circuit so --orphans/--slice-stalled/
447
- # --slice-coverage don't waste cycles validating filters that the
448
- # slice handlers never consume.
449
- if args.action is not None:
450
- valid_actions = tq.valid_audit_actions()
451
- if args.action not in valid_actions:
452
- print(
453
- f"triage:audit --action: unknown verb {args.action!r};"
454
- f" expected one of {sorted(valid_actions)}",
455
- file=sys.stderr,
456
- )
457
- return 2
458
- since_window = None
459
- if args.since is not None:
460
- try:
461
- since_window = tq.parse_audit_window(args.since)
462
- except ValueError as exc:
463
- print(f"triage:audit --since: {exc}", file=sys.stderr)
464
- return 2
465
- # #1123 / D3: optional resume-eligibility evaluation pass. Runs
466
- # BEFORE the audit dump so newly-appended ``resume-eligible`` rows
467
- # surface in the same call. No-op when the resume_conditions module
468
- # is not importable (slim test checkout).
469
- if getattr(args, "evaluate_resume", False) and tq.resume_conditions is not None:
470
- cache_root = Path(args.cache_root).resolve() if args.cache_root else None
471
- try:
472
- tq.resume_conditions.evaluate_resume_eligibility(
473
- project_root,
474
- cache_root=cache_root,
475
- audit_log_path=args.audit_log,
476
- repo=repo,
477
- )
478
- except Exception as exc: # noqa: BLE001 -- best-effort surface
479
- print(
480
- f"triage:audit --evaluate-resume: evaluation failed: {exc}",
481
- file=sys.stderr,
482
- )
483
- entries = tq.read_audit_entries(repo, audit_path=args.audit_log)
484
- # #1180 date / action filters. Apply BEFORE --vbrief-staleness so the
485
- # staleness reduction sees the filtered set; the operator who asked
486
- # for `--since=30d --vbrief-staleness` wants "stale acceptances within
487
- # the last 30 days", not "stale acceptances ever, then filtered to
488
- # the last 30 days". Order: action -> since -> staleness.
489
- if args.action is not None:
490
- entries = tq.filter_by_action(entries, args.action)
491
- if since_window is not None:
492
- entries = tq.filter_by_since(entries, since_window)
493
- if args.vbrief_staleness:
494
- active_refs = frozenset(tq._active_referenced_issue_numbers(project_root))
495
- latest = tq.latest_decisions_by_issue(entries)
496
- entries = [entry for entry in latest.values() if tq.is_stale_acceptance(entry, active_refs)]
497
- entries.sort(key=lambda r: r.get("timestamp", ""))
498
- if args.format == "json":
499
- print(
500
- tq.render_audit_json(
501
- entries,
502
- repo=repo,
503
- vbrief_staleness=args.vbrief_staleness,
504
- )
505
- )
506
- else:
507
- # 'plain' and 'text' alias to the same renderer.
508
- print(
509
- tq.render_audit_plain(
510
- entries,
511
- repo=repo,
512
- vbrief_staleness=args.vbrief_staleness,
513
- )
514
- )
515
- return 0
516
-
517
-
518
- def _slice_inputs(
519
- args: argparse.Namespace,
520
- tq: Any,
521
- *,
522
- repo: str | None,
523
- project_root: Path,
524
- ) -> tuple[list[dict[str, Any]], dict[int, dict[str, Any]]] | None:
525
- """Load (slice_records, issues_by_number) or return ``None`` on missing surface.
526
-
527
- Prints the canonical informational message to stderr and returns ``None``
528
- when ``slice_audit`` is not importable -- the issue body's backward-
529
- compat requirement ("slices.jsonl missing -> flags exit 0 with
530
- informational stderr"). Repo is required for the cache walk but a
531
- missing slices.jsonl is silent (read_all returns []).
532
- """
533
- if slice_audit is None:
534
- print(
535
- "triage:audit: slice operation flags require scripts/slice_audit.py"
536
- " (#1132 / D13); skipping.",
537
- file=sys.stderr,
538
- )
539
- return None
540
- if not repo:
541
- print(
542
- "triage:audit: --repo OWNER/NAME (or $DEFT_TRIAGE_REPO) is required"
543
- " for slice operations.",
544
- file=sys.stderr,
545
- )
546
- return None
547
- records = slice_audit.load_slice_records(tq.slice_record, path=args.slices_log)
548
- issues = tq.load_cached_issues(repo, project_root=project_root, include_closed=True)
549
- issues_by_number = {i["number"]: i for i in issues}
550
- return records, issues_by_number
551
-
552
-
553
- def _cmd_slice_orphans(
554
- args: argparse.Namespace,
555
- tq: Any,
556
- *,
557
- repo: str | None,
558
- project_root: Path,
559
- ) -> int:
560
- loaded = _slice_inputs(args, tq, repo=repo, project_root=project_root)
561
- if loaded is None:
562
- return 0
563
- records, issues_by_number = loaded
564
- rows = slice_audit.compute_orphans(records, issues_by_number)
565
- if args.format == "json":
566
- print(slice_audit.render_orphans_json(rows, repo=repo))
567
- else:
568
- print(slice_audit.render_orphans_plain(rows, repo=repo))
569
- return 0
570
-
571
-
572
- def _cmd_slice_stalled(
573
- args: argparse.Namespace,
574
- tq: Any,
575
- *,
576
- repo: str | None,
577
- project_root: Path,
578
- ) -> int:
579
- loaded = _slice_inputs(args, tq, repo=repo, project_root=project_root)
580
- if loaded is None:
581
- return 0
582
- records, issues_by_number = loaded
583
- days = args.days if args.days is not None else tq.DEFAULT_SLICE_STALLED_DAYS
584
- rows = slice_audit.compute_stalled(records, issues_by_number, days=days)
585
- if args.format == "json":
586
- print(slice_audit.render_stalled_json(rows, repo=repo, days=days))
587
- else:
588
- print(slice_audit.render_stalled_plain(rows, repo=repo, days=days))
589
- return 0
590
-
591
-
592
- def _cmd_slice_coverage(
593
- args: argparse.Namespace,
594
- tq: Any,
595
- *,
596
- repo: str | None,
597
- project_root: Path,
598
- ) -> int:
599
- loaded = _slice_inputs(args, tq, repo=repo, project_root=project_root)
600
- if loaded is None:
601
- return 0
602
- records, issues_by_number = loaded
603
- rows = slice_audit.compute_coverage(records, issues_by_number)
604
- if args.format == "json":
605
- print(slice_audit.render_coverage_json(rows, repo=repo))
606
- else:
607
- print(slice_audit.render_coverage_plain(rows, repo=repo))
608
- return 0
609
-
610
-
611
- def run_cli(argv: list[str] | None, tq_module: Any) -> int:
612
- """Dispatch ``triage_queue`` CLI args using ``tq_module`` as backend."""
613
- parser = build_parser(tq_module.DEFAULT_QUEUE_LIMIT)
614
- try:
615
- args = parser.parse_args(argv)
616
- except SystemExit as exc:
617
- return int(exc.code) if isinstance(exc.code, int) else 2
618
- if args.cmd == "queue":
619
- return _cmd_queue(args, tq_module)
620
- if args.cmd == "show":
621
- return _cmd_show(args, tq_module)
622
- if args.cmd == "audit":
623
- return _cmd_audit(args, tq_module)
624
- parser.print_help()
625
- return 2