@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,689 +0,0 @@
1
- #!/usr/bin/env python3
2
- """ci_local.py -- Run the full CI pipeline locally (matrix-aware).
3
-
4
- Mirrors the step graph of ``.github/workflows/ci.yml`` so contributors can
5
- catch CI failures before pushing. The workflow defines three jobs:
6
-
7
- 1. ``python`` -- ``uv sync`` + ``uv run ruff check .`` + ``uv run mypy tests/``
8
- + ``uv run pytest tests/ --cov --cov-report=term-missing``.
9
- 2. ``go`` -- ``go test ./cmd/deft-install/`` + cross-compile builds for
10
- ``linux/amd64``, ``darwin/arm64``, and ``windows/amd64``.
11
- 3. ``windows-task-dispatch`` -- Windows-only regression tests (path
12
- traversal, ``scope:promote`` end-to-end, etc.) that only run on a
13
- Windows host when ``--matrix=windows`` is requested.
14
-
15
- In addition, this script exercises the existing local framework command
16
- surface that the CI workflow expects to remain green:
17
-
18
- - ``deft toolchain:check``
19
- - ``deft verify:stubs``
20
- - ``deft verify:links``
21
- - ``deft verify:rule-ownership`` (#705)
22
- - ``deft vbrief:validate``
23
- - ``deft build`` (skipped with ``--skip-build``)
24
- - ``deft build:verify`` (graceful absence -- it's a sibling pending #233
25
- item; if the command is missing from the no-task registry we skip it with an
26
- informational message rather than failing).
27
-
28
- Platform notes
29
- --------------
30
- - **Linux**: All Python + Go steps run natively. The cross-compile builds
31
- emit to ``/dev/null``.
32
- - **macOS**: Same as Linux; the ``darwin/arm64`` cross-compile is the
33
- native build path.
34
- - **Windows**: ``/dev/null`` is replaced with ``NUL`` for the Go
35
- cross-compile output. The Windows-task-dispatch regression steps
36
- require ``--matrix=windows`` and are skipped on non-Windows hosts. PR
37
- bodies and other text artifacts are written via ``pathlib`` /
38
- ``create_file`` rather than inline PowerShell string ops to avoid the
39
- PowerShell 5.1 UTF-16LE encoding-corruption pitfall.
40
-
41
- Output
42
- ------
43
- Each step prints a line of the form::
44
-
45
- [N/M] <step name> ... OK (1.23s)
46
-
47
- or, on failure::
48
-
49
- [N/M] <step name> ... FAIL (1.23s)
50
- --- stdout ---
51
- ...captured output...
52
- --- stderr ---
53
- ...captured output...
54
-
55
- Stdout/stderr capture mirrors GitHub Actions' default log style so the
56
- output is easy to compare against a real CI run for debugging parity.
57
-
58
- Exit codes
59
- ----------
60
- 0 -- every applicable step succeeded (skipped steps do not count as
61
- failures)
62
- 1 -- at least one step failed
63
- 2 -- configuration error (invalid arguments, missing required tool)
64
-
65
- Refs #233 (umbrella; this resolves the ``task-ci-local`` plan.item),
66
- #642 (workflow umbrella), #635 (epic anchor), #633 (pre-PR
67
- deterministic-CI enforcement umbrella), #709 (Repair Authority [AXIOM]).
68
- """
69
-
70
- from __future__ import annotations
71
-
72
- import argparse
73
- import os
74
- import platform
75
- import shutil
76
- import subprocess
77
- import sys
78
- import time
79
- from collections.abc import Callable
80
- from dataclasses import dataclass, field
81
- from pathlib import Path
82
-
83
- # Make sibling helpers importable both when run as __main__ and when imported by tests.
84
- sys.path.insert(0, str(Path(__file__).resolve().parent))
85
-
86
- from _stdio_utf8 import reconfigure_stdio # noqa: E402
87
- from framework_commands import has_command, run_framework_command # noqa: E402
88
-
89
- reconfigure_stdio()
90
-
91
- # ---- Exit codes -------------------------------------------------------------
92
-
93
- EXIT_OK = 0
94
- EXIT_STEP_FAILED = 1
95
- EXIT_CONFIG_ERROR = 2
96
-
97
- # ---- Matrix -----------------------------------------------------------------
98
-
99
- VALID_MATRIX_VALUES = ("linux", "macos", "windows", "all", "host")
100
-
101
-
102
- def _host_matrix() -> str:
103
- """Map the current host to a ``--matrix`` value.
104
-
105
- ``platform.system()`` returns ``Linux`` / ``Darwin`` / ``Windows`` on
106
- the three supported hosts. Any other value falls through to
107
- ``"linux"`` as the most permissive default (the script still skips
108
- Windows-only steps under that assumption).
109
- """
110
- system = platform.system().lower()
111
- if system == "windows":
112
- return "windows"
113
- if system == "darwin":
114
- return "macos"
115
- return "linux"
116
-
117
-
118
- # ---- Step model -------------------------------------------------------------
119
-
120
-
121
- @dataclass
122
- class StepResult:
123
- """Outcome of a single CI step."""
124
-
125
- name: str
126
- status: str # "ok" | "fail" | "skip"
127
- elapsed: float = 0.0
128
- stdout: str = ""
129
- stderr: str = ""
130
- skip_reason: str = ""
131
- return_code: int | None = None
132
-
133
-
134
- @dataclass
135
- class Step:
136
- """A single CI step description.
137
-
138
- The step is only run if ``applies()`` returns ``True``; otherwise the
139
- runner emits a ``skip`` result with ``skip_reason``. ``run_fn``
140
- receives the resolved repository root and returns a
141
- ``subprocess.CompletedProcess``-like 3-tuple of
142
- ``(returncode, stdout, stderr)``.
143
- """
144
-
145
- name: str
146
- run_fn: Callable[[Path], tuple[int, str, str]]
147
- applies_fn: Callable[[], bool] = field(default=lambda: True)
148
- skip_reason_fn: Callable[[], str] = field(default=lambda: "")
149
-
150
- def applies(self) -> bool:
151
- return bool(self.applies_fn())
152
-
153
- def skip_reason(self) -> str:
154
- return self.skip_reason_fn()
155
-
156
-
157
- # ---- subprocess helpers -----------------------------------------------------
158
-
159
-
160
- def _devnull_for_host() -> str:
161
- """Return the platform-appropriate path for discarding build output."""
162
- return "NUL" if platform.system().lower() == "windows" else "/dev/null"
163
-
164
-
165
- def _run_command(
166
- cmd: list[str],
167
- cwd: Path,
168
- *,
169
- env_overrides: dict[str, str] | None = None,
170
- ) -> tuple[int, str, str]:
171
- """Run ``cmd`` synchronously and return ``(returncode, stdout, stderr)``.
172
-
173
- Raises ``FileNotFoundError`` if the command's executable is not on
174
- ``PATH``; the caller maps that to ``EXIT_CONFIG_ERROR``.
175
- """
176
- env = os.environ.copy()
177
- # PYTHONUTF8 mirrors the top-level Taskfile.yml env so child Python
178
- # processes don't crash on the unicode glyphs that several scripts
179
- # emit (#540 belt-and-suspenders).
180
- env.setdefault("PYTHONUTF8", "1")
181
- if env_overrides:
182
- env.update(env_overrides)
183
- result = subprocess.run(
184
- cmd,
185
- cwd=str(cwd),
186
- env=env,
187
- capture_output=True,
188
- text=True,
189
- check=False,
190
- )
191
- return result.returncode, result.stdout, result.stderr
192
-
193
-
194
- # ---- Tool detection ---------------------------------------------------------
195
-
196
-
197
- def _has_executable(name: str) -> bool:
198
- """Return True iff ``name`` is resolvable via ``shutil.which``."""
199
- return shutil.which(name) is not None
200
-
201
-
202
- def _framework_command_available(name: str) -> bool:
203
- """Return True iff the no-task framework command registry exposes *name*."""
204
- return has_command(name)
205
-
206
-
207
- def _run_framework_command(name: str, root: Path) -> tuple[int, str, str]:
208
- """Run a framework command in-process."""
209
- result = run_framework_command(
210
- name,
211
- project_root=root,
212
- framework_root=root,
213
- capture=True,
214
- )
215
- return result.code, result.stdout, result.stderr
216
-
217
-
218
- # ---- Step constructors ------------------------------------------------------
219
-
220
-
221
- def _make_python_steps(root: Path) -> list[Step]:
222
- if not _has_executable("uv"):
223
- return [
224
- Step(
225
- name="python: uv toolchain probe",
226
- run_fn=lambda _root: (0, "", ""),
227
- applies_fn=lambda: False,
228
- skip_reason_fn=lambda: (
229
- "uv not on PATH; install Astral uv to run the Python job locally "
230
- "(https://docs.astral.sh/uv/getting-started/installation/)."
231
- ),
232
- )
233
- ]
234
- return [
235
- Step(
236
- name="python: uv sync",
237
- run_fn=lambda r: _run_command(["uv", "sync"], cwd=r),
238
- ),
239
- Step(
240
- name="python: ruff lint",
241
- run_fn=lambda r: _run_command(["uv", "run", "ruff", "check", "."], cwd=r),
242
- ),
243
- Step(
244
- name="python: mypy tests/",
245
- run_fn=lambda r: _run_command(["uv", "run", "mypy", "tests/"], cwd=r),
246
- ),
247
- Step(
248
- name="python: pytest with coverage",
249
- run_fn=lambda r: _run_command(
250
- [
251
- "uv",
252
- "run",
253
- "pytest",
254
- "tests/",
255
- "--cov",
256
- "--cov-report=term-missing",
257
- ],
258
- cwd=r,
259
- ),
260
- ),
261
- ]
262
-
263
-
264
- def _make_go_steps(root: Path, *, skip_build: bool) -> list[Step]:
265
- if not _has_executable("go"):
266
- return [
267
- Step(
268
- name="go: toolchain probe",
269
- run_fn=lambda _root: (0, "", ""),
270
- applies_fn=lambda: False,
271
- skip_reason_fn=lambda: (
272
- "go not on PATH; install Go to run the Go job locally."
273
- ),
274
- )
275
- ]
276
- devnull = _devnull_for_host()
277
- test_step = Step(
278
- name="go: test ./cmd/deft-install/",
279
- run_fn=lambda r: _run_command(["go", "test", "./cmd/deft-install/"], cwd=r),
280
- )
281
- if skip_build:
282
- return [test_step]
283
- cross_targets = (
284
- ("linux", "amd64"),
285
- ("darwin", "arm64"),
286
- ("windows", "amd64"),
287
- )
288
- cross_steps = [
289
- Step(
290
- name=f"go: build {goos}/{goarch}",
291
- run_fn=lambda r, _goos=goos, _goarch=goarch: _run_command(
292
- ["go", "build", "-o", devnull, "./cmd/deft-install/"],
293
- cwd=r,
294
- env_overrides={"GOOS": _goos, "GOARCH": _goarch},
295
- ),
296
- )
297
- for goos, goarch in cross_targets
298
- ]
299
- return [test_step, *cross_steps]
300
-
301
-
302
- def _make_framework_steps(root: Path, *, skip_build: bool) -> list[Step]:
303
- steps: list[Step] = [
304
- Step(
305
- name="framework toolchain:check",
306
- run_fn=lambda r: _run_framework_command("toolchain:check", r),
307
- ),
308
- Step(
309
- name="framework verify:stubs",
310
- run_fn=lambda r: _run_framework_command("verify:stubs", r),
311
- ),
312
- Step(
313
- name="framework verify:links",
314
- run_fn=lambda r: _run_framework_command("verify:links", r),
315
- ),
316
- Step(
317
- name="framework verify:rule-ownership",
318
- run_fn=lambda r: _run_framework_command("verify:rule-ownership", r),
319
- ),
320
- Step(
321
- name="framework vbrief:validate",
322
- run_fn=lambda r: _run_framework_command("vbrief:validate", r),
323
- ),
324
- ]
325
- if not skip_build:
326
- steps.append(
327
- Step(
328
- name="framework build",
329
- run_fn=lambda r: _run_framework_command("build", r),
330
- )
331
- )
332
- # build:verify is a sibling pending #233 plan.item; detect via the
333
- # no-task registry and skip with an informational message rather than
334
- # failing when it isn't yet implemented.
335
- build_verify_present = _framework_command_available("build:verify")
336
- steps.append(
337
- Step(
338
- name="framework build:verify",
339
- run_fn=lambda r: _run_framework_command("build:verify", r),
340
- applies_fn=lambda: build_verify_present,
341
- skip_reason_fn=lambda: (
342
- "`deft build:verify` not yet implemented; skipping -- "
343
- "see #233 pending vBRIEF for the sibling plan.item."
344
- ),
345
- )
346
- )
347
- return steps
348
-
349
-
350
- def _make_windows_dispatch_steps(matrix: str) -> list[Step]:
351
- """The 5 Windows-task-dispatch regression steps.
352
-
353
- These mirror the ``windows-task-dispatch`` job in
354
- ``.github/workflows/ci.yml``. They are run only when the user opted
355
- in via ``--matrix=windows`` AND the host is actually Windows.
356
- """
357
- host_is_windows = platform.system().lower() == "windows"
358
- matrix_requests_windows = matrix in ("windows", "all")
359
- skip_reason = (
360
- ""
361
- if (host_is_windows and matrix_requests_windows)
362
- else (
363
- "windows-task-dispatch regressions only run on a Windows host with "
364
- "--matrix=windows (or --matrix=all). On non-Windows hosts they're "
365
- "skipped because the steps shell out to PowerShell."
366
- )
367
- )
368
-
369
- def _applies() -> bool:
370
- return host_is_windows and matrix_requests_windows
371
-
372
- # The detail of the 5 PowerShell steps lives in
373
- # .github/workflows/ci.yml so we don't risk drift here. We delegate
374
- # to a single subprocess call per step that uses pwsh / powershell
375
- # to invoke the same logic. To avoid duplicating the heavy fixture
376
- # staging here, we only run the lightweight pytest guard-rails on
377
- # the host -- the full job graph (fixture stage, migrate:vbrief
378
- # dispatch, scope:promote dispatch, completed-routing fixture) is a
379
- # CI-only exercise. Exposing one applies() gate per step keeps the
380
- # report row count stable.
381
- fixture_pytest = Step(
382
- name="windows-task-dispatch: pytest guard-rails",
383
- run_fn=lambda r: _run_command(
384
- [
385
- "uv",
386
- "run",
387
- "pytest",
388
- "tests/content/test_taskfile_paths.py",
389
- "tests/content/test_taskfile_cli_args.py",
390
- "tests/content/test_taskfile_caching.py",
391
- "-v",
392
- ],
393
- cwd=r,
394
- ),
395
- applies_fn=_applies,
396
- skip_reason_fn=lambda: skip_reason,
397
- )
398
- return [fixture_pytest]
399
-
400
-
401
- # ---- Pipeline construction --------------------------------------------------
402
-
403
-
404
- def build_pipeline(
405
- root: Path,
406
- *,
407
- matrix: str,
408
- skip_build: bool,
409
- ) -> list[Step]:
410
- """Return the ordered step graph for the local CI run."""
411
- steps: list[Step] = []
412
- steps.extend(_make_python_steps(root))
413
- steps.extend(_make_go_steps(root, skip_build=skip_build))
414
- steps.extend(_make_framework_steps(root, skip_build=skip_build))
415
- steps.extend(_make_windows_dispatch_steps(matrix))
416
- return steps
417
-
418
-
419
- # ---- Runner -----------------------------------------------------------------
420
-
421
-
422
- def run_pipeline(
423
- root: Path,
424
- steps: list[Step],
425
- *,
426
- fail_fast: bool,
427
- verbose: bool,
428
- out: Callable[[str], None] | None = None,
429
- ) -> list[StepResult]:
430
- """Execute ``steps`` in order; return the list of ``StepResult``."""
431
- emit: Callable[[str], None] = out if out is not None else print
432
- results: list[StepResult] = []
433
- total = len(steps)
434
- failed_seen = False
435
- for index, step in enumerate(steps, start=1):
436
- prefix = f"[{index}/{total}] {step.name}"
437
- if failed_seen and fail_fast:
438
- results.append(
439
- StepResult(
440
- name=step.name,
441
- status="skip",
442
- skip_reason="aborted -- earlier step failed and --fail-fast is set",
443
- )
444
- )
445
- emit(f"{prefix} ... SKIP (fail-fast)")
446
- continue
447
- if not step.applies():
448
- reason = step.skip_reason() or "step not applicable on this host"
449
- results.append(
450
- StepResult(name=step.name, status="skip", skip_reason=reason)
451
- )
452
- emit(f"{prefix} ... SKIP -- {reason}")
453
- continue
454
- emit(f"{prefix} ... running")
455
- start = time.monotonic()
456
- try:
457
- rc, stdout, stderr = step.run_fn(root)
458
- except FileNotFoundError as exc:
459
- elapsed = time.monotonic() - start
460
- results.append(
461
- StepResult(
462
- name=step.name,
463
- status="fail",
464
- elapsed=elapsed,
465
- stderr=f"executable not found: {exc}",
466
- return_code=None,
467
- )
468
- )
469
- emit(f"{prefix} ... FAIL ({elapsed:.2f}s) -- executable not found: {exc}")
470
- failed_seen = True
471
- continue
472
- elapsed = time.monotonic() - start
473
- if rc == 0:
474
- results.append(
475
- StepResult(
476
- name=step.name,
477
- status="ok",
478
- elapsed=elapsed,
479
- stdout=stdout,
480
- stderr=stderr,
481
- return_code=rc,
482
- )
483
- )
484
- emit(f"{prefix} ... OK ({elapsed:.2f}s)")
485
- if verbose and (stdout or stderr):
486
- if stdout:
487
- emit("--- stdout ---")
488
- emit(stdout.rstrip())
489
- if stderr:
490
- emit("--- stderr ---")
491
- emit(stderr.rstrip())
492
- else:
493
- results.append(
494
- StepResult(
495
- name=step.name,
496
- status="fail",
497
- elapsed=elapsed,
498
- stdout=stdout,
499
- stderr=stderr,
500
- return_code=rc,
501
- )
502
- )
503
- emit(f"{prefix} ... FAIL ({elapsed:.2f}s) -- exit code {rc}")
504
- if stdout:
505
- emit("--- stdout ---")
506
- emit(stdout.rstrip())
507
- if stderr:
508
- emit("--- stderr ---")
509
- emit(stderr.rstrip())
510
- failed_seen = True
511
- return results
512
-
513
-
514
- # ---- Aggregate report -------------------------------------------------------
515
-
516
-
517
- def format_summary(results: list[StepResult]) -> str:
518
- """Return a human-readable aggregate summary."""
519
- total = len(results)
520
- passed = sum(1 for r in results if r.status == "ok")
521
- failed = sum(1 for r in results if r.status == "fail")
522
- skipped = sum(1 for r in results if r.status == "skip")
523
- elapsed = sum(r.elapsed for r in results)
524
- lines = [
525
- "",
526
- "=" * 60,
527
- "ci:local summary",
528
- "=" * 60,
529
- f" total: {total}",
530
- f" passed: {passed}",
531
- f" failed: {failed}",
532
- f" skipped: {skipped}",
533
- f" elapsed: {elapsed:.2f}s",
534
- ]
535
- if failed:
536
- lines.append("")
537
- lines.append("Failed steps:")
538
- for r in results:
539
- if r.status == "fail":
540
- rc = "n/a" if r.return_code is None else str(r.return_code)
541
- lines.append(f" - {r.name} (exit {rc})")
542
- if skipped:
543
- lines.append("")
544
- lines.append("Skipped steps:")
545
- for r in results:
546
- if r.status == "skip":
547
- lines.append(f" - {r.name} -- {r.skip_reason}")
548
- lines.append("=" * 60)
549
- return "\n".join(lines)
550
-
551
-
552
- # ---- argument parsing -------------------------------------------------------
553
-
554
-
555
- def _build_parser() -> argparse.ArgumentParser:
556
- parser = argparse.ArgumentParser(
557
- prog="ci_local",
558
- description=(
559
- "Run the full CI pipeline locally (matrix-aware). Mirrors the "
560
- "step graph of .github/workflows/ci.yml so contributors can "
561
- "catch CI failures before pushing. Refs #233, #642, #635, "
562
- "#633, #709."
563
- ),
564
- )
565
- parser.add_argument(
566
- "--matrix",
567
- choices=VALID_MATRIX_VALUES,
568
- default="host",
569
- help=(
570
- "Which CI matrix slice to run. ``host`` (default) maps to the "
571
- "current platform via ``platform.system()``. NOTE: the flag's "
572
- "only practical effect is gating the ``windows-task-dispatch`` "
573
- "regression rows -- those run only when ``--matrix=windows`` (or "
574
- "``all``) is supplied AND the host is Windows, because the "
575
- "underlying steps shell out to PowerShell. The Python, Go, and "
576
- "Taskfile-level rows always run on whatever toolchain is "
577
- "available locally and are not platform-filtered (Greptile "
578
- "P2 #713). ``linux`` / ``macos`` therefore behave equivalently "
579
- "on a non-Windows host."
580
- ),
581
- )
582
- parser.add_argument(
583
- "--skip-build",
584
- action="store_true",
585
- help=(
586
- "Skip the cross-compile builds and the ``task build`` / "
587
- "``task build:verify`` steps. Useful for tight inner-loop "
588
- "iteration where only lint + test feedback matters."
589
- ),
590
- )
591
- parser.add_argument(
592
- "--verbose",
593
- action="store_true",
594
- help=(
595
- "Mirror CI logs verbatim -- stream every step's stdout/stderr "
596
- "even when the step succeeds. Default is to surface output "
597
- "only on failure."
598
- ),
599
- )
600
- fail_fast_group = parser.add_mutually_exclusive_group()
601
- fail_fast_group.add_argument(
602
- "--fail-fast",
603
- dest="fail_fast",
604
- action="store_true",
605
- default=True,
606
- help=(
607
- "Abort the pipeline at the first failing step (default). "
608
- "Subsequent steps are reported as skipped."
609
- ),
610
- )
611
- fail_fast_group.add_argument(
612
- "--no-fail-fast",
613
- dest="fail_fast",
614
- action="store_false",
615
- help=(
616
- "Run every applicable step even when an earlier one failed. "
617
- "The exit code is still 1 if any step failed."
618
- ),
619
- )
620
- parser.add_argument(
621
- "--root",
622
- type=Path,
623
- default=None,
624
- metavar="PATH",
625
- help=(
626
- "Repository root. Defaults to the parent of the scripts/ "
627
- "directory containing this file."
628
- ),
629
- )
630
- return parser
631
-
632
-
633
- def _resolve_root(arg_root: Path | None) -> Path:
634
- if arg_root is not None:
635
- return arg_root.resolve()
636
- return Path(__file__).resolve().parent.parent
637
-
638
-
639
- def _resolve_matrix(matrix_arg: str) -> str:
640
- if matrix_arg == "host":
641
- return _host_matrix()
642
- return matrix_arg
643
-
644
-
645
- # ---- main -------------------------------------------------------------------
646
-
647
-
648
- def main(argv: list[str] | None = None) -> int:
649
- parser = _build_parser()
650
- args = parser.parse_args(argv)
651
- root = _resolve_root(args.root)
652
- if not root.is_dir():
653
- print(f"Error: --root does not point at a directory: {root}", file=sys.stderr)
654
- return EXIT_CONFIG_ERROR
655
- matrix = _resolve_matrix(args.matrix)
656
- print(
657
- f"ci:local -- root={root} matrix={matrix} skip_build={args.skip_build} "
658
- f"fail_fast={args.fail_fast} verbose={args.verbose}",
659
- file=sys.stderr,
660
- )
661
- steps = build_pipeline(root, matrix=matrix, skip_build=args.skip_build)
662
- # ``build_pipeline`` always returns at least the toolchain probe
663
- # rows, so ``steps`` is rarely empty. The reachable failure mode is a
664
- # pipeline composed entirely of skips -- that means no tool was
665
- # installed and the runner would otherwise exit 0 with every step
666
- # silently skipped, violating the three-state exit-code contract.
667
- # ``not any(s.applies() for s in steps)`` covers both shapes (Greptile
668
- # P1 #713).
669
- if not steps or not any(s.applies() for s in steps):
670
- print(
671
- "Error: no CI steps applicable on this host. Install at least one of "
672
- "uv / go / task to run any portion of the pipeline locally.",
673
- file=sys.stderr,
674
- )
675
- return EXIT_CONFIG_ERROR
676
- results = run_pipeline(
677
- root,
678
- steps,
679
- fail_fast=args.fail_fast,
680
- verbose=args.verbose,
681
- )
682
- print(format_summary(results))
683
- if any(r.status == "fail" for r in results):
684
- return EXIT_STEP_FAILED
685
- return EXIT_OK
686
-
687
-
688
- if __name__ == "__main__":
689
- sys.exit(main())