@deftai/directive-content 0.55.2 → 0.56.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.
- 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,418 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""migrate_preflight.py -- agent-side environment preflight for ``task migrate:vbrief`` (#793).
|
|
3
|
+
|
|
4
|
+
Reifies the prose contract documented in
|
|
5
|
+
``skills/deft-directive-setup/SKILL.md`` § Environment Preflight as a runnable
|
|
6
|
+
task so consumers running ``task migrate:vbrief`` directly (not via the
|
|
7
|
+
agent-driven setup skill) get the same checks before any destructive mutation
|
|
8
|
+
runs.
|
|
9
|
+
|
|
10
|
+
Pure stdlib + ``subprocess``. Three-state exit (mirrors
|
|
11
|
+
``scripts/preflight_branch.py`` (#747) and ``scripts/preflight_implementation.py``
|
|
12
|
+
(#810) shape):
|
|
13
|
+
|
|
14
|
+
- ``0`` -- ready: every check PASS (or non-blocking WARN, e.g. dirty git tree).
|
|
15
|
+
- ``1`` -- not-ready: any check FAIL with an actionable remediation pointer.
|
|
16
|
+
- ``2`` -- config error: e.g. ``--project-root`` does not exist or is not a
|
|
17
|
+
directory. Distinct from FAIL so callers can disambiguate "user can fix"
|
|
18
|
+
from "calling environment is wrong".
|
|
19
|
+
|
|
20
|
+
The checks are:
|
|
21
|
+
|
|
22
|
+
1. ``uv`` on PATH -- the migrator runs via ``uv run python``; absence is fatal.
|
|
23
|
+
2. v0.20+ layout -- ``<deft-root>/scripts/migrate_vbrief.py`` and
|
|
24
|
+
``<project>/vbrief/`` (with the ``schemas/`` subdirectory carried by the
|
|
25
|
+
framework checkout) must exist; absence indicates an incomplete or
|
|
26
|
+
pre-cutover checkout.
|
|
27
|
+
3. Document-model state -- delegates to ``scripts/_precutover.py`` so a
|
|
28
|
+
generated ``SPECIFICATION.md`` from ``task spec:render`` does not send a
|
|
29
|
+
current vBRIEF project through destructive migration.
|
|
30
|
+
4. Git working-tree state -- a dirty tree is reported as WARN (the migrator's
|
|
31
|
+
own dirty-tree guard fires with an actionable ``--force`` pointer; we do
|
|
32
|
+
NOT block here so ``--dry-run`` previews remain usable). Non-git
|
|
33
|
+
directories are also a WARN-level skip rather than a FAIL.
|
|
34
|
+
|
|
35
|
+
The intent is to surface every fixable blocker at once, with one line per
|
|
36
|
+
check, so operators can resolve them in a single pass instead of fighting
|
|
37
|
+
through three separate subprocess error tracebacks.
|
|
38
|
+
|
|
39
|
+
Soft-dep on #792 (``cmd_doctor`` uv-detection helper): a local
|
|
40
|
+
``_uv_available()`` is defined here for now to keep this PR self-contained;
|
|
41
|
+
when #792 lands a future small follow-up can DRY both surfaces against a
|
|
42
|
+
single shared helper.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
from __future__ import annotations
|
|
46
|
+
|
|
47
|
+
import argparse
|
|
48
|
+
import shutil
|
|
49
|
+
import subprocess
|
|
50
|
+
import sys
|
|
51
|
+
from pathlib import Path
|
|
52
|
+
from typing import NamedTuple
|
|
53
|
+
|
|
54
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
55
|
+
|
|
56
|
+
from _content_root import content_root # noqa: E402
|
|
57
|
+
from _precutover import ( # noqa: E402
|
|
58
|
+
detect_pre_cutover_legacy,
|
|
59
|
+
is_current_generated_specification,
|
|
60
|
+
is_generated_specification_export,
|
|
61
|
+
missing_lifecycle_folders,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class CheckResult(NamedTuple):
|
|
66
|
+
"""A single preflight check's outcome.
|
|
67
|
+
|
|
68
|
+
Attributes:
|
|
69
|
+
name: Short, stable identifier (e.g. ``uv``, ``layout``, ``git-clean``).
|
|
70
|
+
status: One of ``PASS`` / ``WARN`` / ``FAIL``.
|
|
71
|
+
message: Human-readable remediation pointer or status note.
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
name: str
|
|
75
|
+
status: str # "PASS" | "WARN" | "FAIL"
|
|
76
|
+
message: str
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# ---------------------------------------------------------------------------
|
|
80
|
+
# Individual check primitives
|
|
81
|
+
# ---------------------------------------------------------------------------
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _uv_available() -> bool:
|
|
85
|
+
"""Return True when the ``uv`` executable is resolvable on PATH.
|
|
86
|
+
|
|
87
|
+
Local helper for #793; once #792 lands a shared ``cmd_doctor`` helper a
|
|
88
|
+
follow-up should DRY this against a single source of truth (the brief's
|
|
89
|
+
``soft_dep_on: #792`` note).
|
|
90
|
+
"""
|
|
91
|
+
return shutil.which("uv") is not None
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def check_uv() -> CheckResult:
|
|
95
|
+
"""Verify ``uv`` is on PATH.
|
|
96
|
+
|
|
97
|
+
The migrator dispatches via ``uv run python ...``; without ``uv`` the
|
|
98
|
+
consumer hits a raw ``FileNotFoundError`` with no recovery pointer. This
|
|
99
|
+
check is the actionable replacement for that traceback.
|
|
100
|
+
"""
|
|
101
|
+
if _uv_available():
|
|
102
|
+
return CheckResult("uv", "PASS", "uv is on PATH.")
|
|
103
|
+
return CheckResult(
|
|
104
|
+
"uv",
|
|
105
|
+
"FAIL",
|
|
106
|
+
"uv is not on PATH. Install from https://docs.astral.sh/uv/ and re-run.",
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def check_layout(deft_root: Path, project_root: Path) -> CheckResult:
|
|
111
|
+
"""Verify the framework checkout + project root carry the v0.20+ layout.
|
|
112
|
+
|
|
113
|
+
Two pieces are required:
|
|
114
|
+
|
|
115
|
+
1. ``<deft-root>/scripts/migrate_vbrief.py`` -- the migrator script the
|
|
116
|
+
``task migrate:vbrief`` target dispatches to. A missing file means the
|
|
117
|
+
framework checkout is incomplete or came from a pre-v0.20 release.
|
|
118
|
+
2. ``<project-root>/vbrief/`` -- the lifecycle root the migrator ingests
|
|
119
|
+
into. It is created on first run for greenfield projects, but most
|
|
120
|
+
v0.20+ projects already have it; existence here is informational
|
|
121
|
+
(``WARN`` when missing, not ``FAIL``).
|
|
122
|
+
|
|
123
|
+
The framework's ``vbrief/schemas/`` directory MUST exist on the deft root
|
|
124
|
+
too (carried by the checkout, not regenerated) -- absence indicates a
|
|
125
|
+
framework checkout problem and is FAIL.
|
|
126
|
+
"""
|
|
127
|
+
migrator = deft_root / "scripts" / "migrate_vbrief.py"
|
|
128
|
+
if not migrator.is_file():
|
|
129
|
+
return CheckResult(
|
|
130
|
+
"layout",
|
|
131
|
+
"FAIL",
|
|
132
|
+
(
|
|
133
|
+
f"Migrator script missing at {migrator}. The framework checkout "
|
|
134
|
+
"appears incomplete or pre-v0.20; refresh per "
|
|
135
|
+
"deft/QUICK-START.md."
|
|
136
|
+
),
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
schemas_dir = content_root(deft_root) / "vbrief" / "schemas"
|
|
140
|
+
if not schemas_dir.is_dir():
|
|
141
|
+
return CheckResult(
|
|
142
|
+
"layout",
|
|
143
|
+
"FAIL",
|
|
144
|
+
(
|
|
145
|
+
f"Framework schemas dir missing at {schemas_dir}. Refresh the "
|
|
146
|
+
"deft checkout (see deft/QUICK-START.md)."
|
|
147
|
+
),
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
project_vbrief = project_root / "vbrief"
|
|
151
|
+
if not project_vbrief.exists():
|
|
152
|
+
return CheckResult(
|
|
153
|
+
"layout",
|
|
154
|
+
"WARN",
|
|
155
|
+
(
|
|
156
|
+
f"Project vbrief/ not present at {project_vbrief} -- migrator "
|
|
157
|
+
"will create it on first run; this is expected for greenfield "
|
|
158
|
+
"projects."
|
|
159
|
+
),
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
return CheckResult(
|
|
163
|
+
"layout",
|
|
164
|
+
"PASS",
|
|
165
|
+
f"Framework migrator + schemas present; project vbrief/ at {project_vbrief}.",
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def check_git_clean(project_root: Path) -> CheckResult:
|
|
170
|
+
"""Surface git working-tree state non-blockingly.
|
|
171
|
+
|
|
172
|
+
A dirty tree is reported as WARN (not FAIL) because:
|
|
173
|
+
|
|
174
|
+
- ``task migrate:vbrief -- --dry-run`` is the recommended preview path and
|
|
175
|
+
runs fine against a dirty tree.
|
|
176
|
+
- The migrator itself has a dirty-tree guard with a ``--force`` recovery
|
|
177
|
+
pointer (#497); double-blocking here would be redundant.
|
|
178
|
+
|
|
179
|
+
A non-git directory is also a WARN: the gate has nothing to assert, but
|
|
180
|
+
the operator deserves to know the standard recovery path won't apply.
|
|
181
|
+
"""
|
|
182
|
+
try:
|
|
183
|
+
proc = subprocess.run(
|
|
184
|
+
["git", "status", "--porcelain"],
|
|
185
|
+
cwd=str(project_root),
|
|
186
|
+
capture_output=True,
|
|
187
|
+
text=True,
|
|
188
|
+
check=False,
|
|
189
|
+
)
|
|
190
|
+
except FileNotFoundError:
|
|
191
|
+
return CheckResult(
|
|
192
|
+
"git-clean",
|
|
193
|
+
"WARN",
|
|
194
|
+
(
|
|
195
|
+
"git executable not on PATH; skipping working-tree check. "
|
|
196
|
+
"Migrator's dirty-tree guard will still fire if applicable."
|
|
197
|
+
),
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
if proc.returncode != 0:
|
|
201
|
+
# Non-zero typically means "not a git repository". Treat as WARN.
|
|
202
|
+
return CheckResult(
|
|
203
|
+
"git-clean",
|
|
204
|
+
"WARN",
|
|
205
|
+
(
|
|
206
|
+
f"Not a git repository at {project_root} (git exit "
|
|
207
|
+
f"{proc.returncode}); skipping working-tree check."
|
|
208
|
+
),
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
if proc.stdout.strip():
|
|
212
|
+
return CheckResult(
|
|
213
|
+
"git-clean",
|
|
214
|
+
"WARN",
|
|
215
|
+
(
|
|
216
|
+
"Working tree is dirty. The migrator will refuse to run "
|
|
217
|
+
"without --force; preview with `task migrate:vbrief -- "
|
|
218
|
+
"--dry-run` first."
|
|
219
|
+
),
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
return CheckResult("git-clean", "PASS", "Working tree is clean.")
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def check_document_model(project_root: Path) -> CheckResult:
|
|
226
|
+
"""Verify migration is aimed at legacy or incomplete document-model state.
|
|
227
|
+
|
|
228
|
+
The preflight is a safety check, so it must not send current vBRIEF
|
|
229
|
+
projects into the destructive migration path merely because a generated
|
|
230
|
+
root ``SPECIFICATION.md`` exists.
|
|
231
|
+
"""
|
|
232
|
+
legacy = detect_pre_cutover_legacy(project_root)
|
|
233
|
+
if legacy:
|
|
234
|
+
return CheckResult(
|
|
235
|
+
"document-model",
|
|
236
|
+
"PASS",
|
|
237
|
+
"Legacy root artifact(s) detected: " + ", ".join(legacy) + ".",
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
spec_md = project_root / "SPECIFICATION.md"
|
|
241
|
+
if spec_md.is_file():
|
|
242
|
+
try:
|
|
243
|
+
content = spec_md.read_text(encoding="utf-8", errors="replace")
|
|
244
|
+
except OSError:
|
|
245
|
+
content = ""
|
|
246
|
+
if is_generated_specification_export(project_root, content):
|
|
247
|
+
missing = missing_lifecycle_folders(project_root)
|
|
248
|
+
if missing:
|
|
249
|
+
return CheckResult(
|
|
250
|
+
"document-model",
|
|
251
|
+
"FAIL",
|
|
252
|
+
(
|
|
253
|
+
"Generated SPECIFICATION.md detected "
|
|
254
|
+
"(source: vbrief/specification.vbrief.json); "
|
|
255
|
+
"repair missing lifecycle folder(s) instead of migrating: "
|
|
256
|
+
+ ", ".join(missing)
|
|
257
|
+
+ "."
|
|
258
|
+
),
|
|
259
|
+
)
|
|
260
|
+
if is_current_generated_specification(project_root, content):
|
|
261
|
+
return CheckResult(
|
|
262
|
+
"document-model",
|
|
263
|
+
"FAIL",
|
|
264
|
+
(
|
|
265
|
+
"Current generated SPECIFICATION.md detected "
|
|
266
|
+
"(source: vbrief/specification.vbrief.json); "
|
|
267
|
+
"`task migrate:vbrief` is not needed."
|
|
268
|
+
),
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
vbrief_root = project_root / "vbrief"
|
|
272
|
+
if vbrief_root.exists():
|
|
273
|
+
missing = missing_lifecycle_folders(project_root)
|
|
274
|
+
if missing:
|
|
275
|
+
return CheckResult(
|
|
276
|
+
"document-model",
|
|
277
|
+
"PASS",
|
|
278
|
+
"Partial vBRIEF layout detected; missing lifecycle folder(s): "
|
|
279
|
+
+ ", ".join(missing)
|
|
280
|
+
+ ".",
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
return CheckResult(
|
|
284
|
+
"document-model",
|
|
285
|
+
"WARN",
|
|
286
|
+
(
|
|
287
|
+
"No legacy root SPECIFICATION.md/PROJECT.md artifacts detected. "
|
|
288
|
+
"Migration may have nothing to do."
|
|
289
|
+
),
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
# ---------------------------------------------------------------------------
|
|
294
|
+
# Aggregate evaluation
|
|
295
|
+
# ---------------------------------------------------------------------------
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def evaluate(deft_root: Path, project_root: Path) -> tuple[int, list[CheckResult]]:
|
|
299
|
+
"""Run every check and return ``(exit_code, results)``.
|
|
300
|
+
|
|
301
|
+
Pure function -- separated from :func:`main` so tests can drive every
|
|
302
|
+
state without ``capsys`` plumbing or env-var leak. Mirrors the
|
|
303
|
+
``scripts/preflight_branch.py::evaluate`` surface.
|
|
304
|
+
|
|
305
|
+
Exit-code semantics:
|
|
306
|
+
|
|
307
|
+
- ``0`` -- every check PASS or WARN.
|
|
308
|
+
- ``1`` -- one or more checks FAIL.
|
|
309
|
+
- ``2`` is reserved for the CLI :func:`main` to signal config error
|
|
310
|
+
(e.g. ``--project-root`` does not exist); :func:`evaluate` itself never
|
|
311
|
+
emits 2.
|
|
312
|
+
"""
|
|
313
|
+
results = [
|
|
314
|
+
check_uv(),
|
|
315
|
+
check_layout(deft_root, project_root),
|
|
316
|
+
check_document_model(project_root),
|
|
317
|
+
check_git_clean(project_root),
|
|
318
|
+
]
|
|
319
|
+
if any(r.status == "FAIL" for r in results):
|
|
320
|
+
return 1, results
|
|
321
|
+
return 0, results
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
# ---------------------------------------------------------------------------
|
|
325
|
+
# CLI plumbing
|
|
326
|
+
# ---------------------------------------------------------------------------
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def _format_result(result: CheckResult) -> str:
|
|
330
|
+
"""Return the canonical ``CHECK <name>: <STATUS> <message>`` line."""
|
|
331
|
+
return f"CHECK {result.name}: {result.status} {result.message}"
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def _build_parser() -> argparse.ArgumentParser:
|
|
335
|
+
parser = argparse.ArgumentParser(
|
|
336
|
+
prog="migrate_preflight.py",
|
|
337
|
+
description=(
|
|
338
|
+
"Agent-side environment preflight for `task migrate:vbrief` "
|
|
339
|
+
"(#793). Verifies uv on PATH, v0.20+ layout, document-model "
|
|
340
|
+
"state, and git working-tree state before destructive migration "
|
|
341
|
+
"mutations."
|
|
342
|
+
),
|
|
343
|
+
)
|
|
344
|
+
parser.add_argument(
|
|
345
|
+
"--project-root",
|
|
346
|
+
default=".",
|
|
347
|
+
help=("Path to the consumer project root (default: current working " "directory)."),
|
|
348
|
+
)
|
|
349
|
+
parser.add_argument(
|
|
350
|
+
"--deft-root",
|
|
351
|
+
default=None,
|
|
352
|
+
help=(
|
|
353
|
+
"Path to the deft framework checkout (default: parent of this " "script's directory)."
|
|
354
|
+
),
|
|
355
|
+
)
|
|
356
|
+
parser.add_argument(
|
|
357
|
+
"--quiet",
|
|
358
|
+
action="store_true",
|
|
359
|
+
help="Suppress PASS lines (FAIL/WARN still print).",
|
|
360
|
+
)
|
|
361
|
+
return parser
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
def main(argv: list[str] | None = None) -> int:
|
|
365
|
+
# #814 + parity with scripts/preflight_branch.py: force UTF-8 stdout/stderr
|
|
366
|
+
# at entry so the gate's status lines render under Windows cp1252 default
|
|
367
|
+
# without a UnicodeEncodeError. Guarded by ``hasattr`` because reconfigure
|
|
368
|
+
# is only available on TextIOWrapper streams; ``errors='replace'`` is the
|
|
369
|
+
# belt-and-suspenders fallback per #814.
|
|
370
|
+
if hasattr(sys.stdout, "reconfigure"):
|
|
371
|
+
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
372
|
+
if hasattr(sys.stderr, "reconfigure"):
|
|
373
|
+
sys.stderr.reconfigure(encoding="utf-8", errors="replace")
|
|
374
|
+
|
|
375
|
+
parser = _build_parser()
|
|
376
|
+
args = parser.parse_args(argv)
|
|
377
|
+
|
|
378
|
+
project_root = Path(args.project_root).resolve()
|
|
379
|
+
if not project_root.exists() or not project_root.is_dir():
|
|
380
|
+
print(
|
|
381
|
+
f"ERROR: --project-root does not exist or is not a directory: " f"{project_root}",
|
|
382
|
+
file=sys.stderr,
|
|
383
|
+
)
|
|
384
|
+
return 2
|
|
385
|
+
|
|
386
|
+
if args.deft_root is None:
|
|
387
|
+
# Default: the directory containing scripts/ (this file's parent's
|
|
388
|
+
# parent). Mirrors the lookup pattern used by other framework scripts
|
|
389
|
+
# invoked via ``uv run python <script>`` from a Taskfile target.
|
|
390
|
+
deft_root = Path(__file__).resolve().parent.parent
|
|
391
|
+
else:
|
|
392
|
+
deft_root = Path(args.deft_root).resolve()
|
|
393
|
+
if not deft_root.exists() or not deft_root.is_dir():
|
|
394
|
+
print(
|
|
395
|
+
f"ERROR: --deft-root does not exist or is not a directory: " f"{deft_root}",
|
|
396
|
+
file=sys.stderr,
|
|
397
|
+
)
|
|
398
|
+
return 2
|
|
399
|
+
|
|
400
|
+
code, results = evaluate(deft_root, project_root)
|
|
401
|
+
|
|
402
|
+
for result in results:
|
|
403
|
+
if args.quiet and result.status == "PASS":
|
|
404
|
+
continue
|
|
405
|
+
stream = sys.stderr if result.status == "FAIL" else sys.stdout
|
|
406
|
+
print(_format_result(result), file=stream)
|
|
407
|
+
|
|
408
|
+
if code != 0:
|
|
409
|
+
print(
|
|
410
|
+
"migrate:preflight FAILED -- resolve the FAIL line(s) above before "
|
|
411
|
+
"re-running `task migrate:vbrief`.",
|
|
412
|
+
file=sys.stderr,
|
|
413
|
+
)
|
|
414
|
+
return code
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
if __name__ == "__main__":
|
|
418
|
+
sys.exit(main())
|