@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.
Files changed (217) hide show
  1. package/.githooks/pre-commit +143 -0
  2. package/.githooks/pre-push +121 -0
  3. package/QUICK-START.md +2 -2
  4. package/Taskfile.yml +934 -0
  5. package/UPGRADING.md +47 -1
  6. package/events/README.md +3 -3
  7. package/package.json +5 -4
  8. package/scripts/_agents_md.py +494 -0
  9. package/scripts/_cache_fetch.py +635 -0
  10. package/scripts/_cache_quota.py +529 -0
  11. package/scripts/_cache_refresh.py +163 -0
  12. package/scripts/_cache_validate.py +209 -0
  13. package/scripts/_content_root.py +42 -0
  14. package/scripts/_doctor_state.py +277 -0
  15. package/scripts/_event_detect.py +305 -0
  16. package/scripts/_events.py +514 -0
  17. package/scripts/_lifecycle_hygiene.py +568 -0
  18. package/scripts/_pathspec.py +91 -0
  19. package/scripts/_policy_show_cli.py +266 -0
  20. package/scripts/_precutover.py +92 -0
  21. package/scripts/_project_context.py +224 -0
  22. package/scripts/_project_definition_io.py +164 -0
  23. package/scripts/_relocate_snapshot.py +209 -0
  24. package/scripts/_relocate_states.py +343 -0
  25. package/scripts/_resolve_preflight_path.py +152 -0
  26. package/scripts/_safe_subprocess.py +167 -0
  27. package/scripts/_session_start_hook.py +205 -0
  28. package/scripts/_sor_gate_diff.py +365 -0
  29. package/scripts/_stdio_utf8.py +59 -0
  30. package/scripts/_triage_bootstrap_gitignore.py +904 -0
  31. package/scripts/_triage_classify_cli.py +122 -0
  32. package/scripts/_triage_queue_cli.py +625 -0
  33. package/scripts/_triage_scope_cli.py +343 -0
  34. package/scripts/_triage_scope_drift_cli.py +121 -0
  35. package/scripts/_triage_scope_ignores.py +286 -0
  36. package/scripts/_triage_scope_milestone.py +432 -0
  37. package/scripts/_triage_scope_mutations.py +337 -0
  38. package/scripts/_triage_scope_renderers.py +207 -0
  39. package/scripts/_triage_smoketest_stages.py +674 -0
  40. package/scripts/_triage_subscribe_cli.py +140 -0
  41. package/scripts/_triage_welcome_cli.py +421 -0
  42. package/scripts/_vbrief_build.py +239 -0
  43. package/scripts/_vbrief_fidelity.py +479 -0
  44. package/scripts/_vbrief_legacy.py +589 -0
  45. package/scripts/_vbrief_reconciliation.py +883 -0
  46. package/scripts/_vbrief_routing.py +277 -0
  47. package/scripts/_vbrief_safety.py +778 -0
  48. package/scripts/_vbrief_sources.py +312 -0
  49. package/scripts/_vbrief_speckit.py +262 -0
  50. package/scripts/_vbrief_story_quality.py +353 -0
  51. package/scripts/_vbrief_validation.py +299 -0
  52. package/scripts/build_dist.py +412 -0
  53. package/scripts/cache.py +1078 -0
  54. package/scripts/cache_scanner.py +745 -0
  55. package/scripts/candidates_log.py +432 -0
  56. package/scripts/capacity_backfill.py +680 -0
  57. package/scripts/capacity_show.py +653 -0
  58. package/scripts/ci_local.py +689 -0
  59. package/scripts/code_structure_validate.py +765 -0
  60. package/scripts/codebase_default_extractor.py +495 -0
  61. package/scripts/codebase_map.py +304 -0
  62. package/scripts/codebase_map_fresh.py +104 -0
  63. package/scripts/codebase_projection_registry.py +94 -0
  64. package/scripts/codebase_provider.py +582 -0
  65. package/scripts/doctor.py +2257 -0
  66. package/scripts/framework_commands.py +505 -0
  67. package/scripts/gh_rest.py +882 -0
  68. package/scripts/github_auth_modes.py +437 -0
  69. package/scripts/github_body.py +292 -0
  70. package/scripts/ip_risk.py +531 -0
  71. package/scripts/issue_emit.py +670 -0
  72. package/scripts/issue_ingest.py +1064 -0
  73. package/scripts/migrate_preflight.py +418 -0
  74. package/scripts/migrate_vbrief.py +2677 -0
  75. package/scripts/monitor_pr.py +401 -0
  76. package/scripts/pack_migrate_lessons.py +336 -0
  77. package/scripts/pack_migrate_patterns.py +254 -0
  78. package/scripts/pack_migrate_rules.py +350 -0
  79. package/scripts/pack_migrate_skills.py +423 -0
  80. package/scripts/pack_migrate_strategies.py +311 -0
  81. package/scripts/pack_migrate_swarm_spec.py +250 -0
  82. package/scripts/pack_render.py +434 -0
  83. package/scripts/packs_slice.py +712 -0
  84. package/scripts/platform_capabilities.py +336 -0
  85. package/scripts/policy.py +2826 -0
  86. package/scripts/policy_set.py +324 -0
  87. package/scripts/pr_check_closing_keywords.py +524 -0
  88. package/scripts/pr_check_protected_issues.py +267 -0
  89. package/scripts/pr_merge_readiness.py +1004 -0
  90. package/scripts/pr_wait_mergeable.py +669 -0
  91. package/scripts/prd_render.py +159 -0
  92. package/scripts/preflight_architecture_sor.py +974 -0
  93. package/scripts/preflight_branch.py +289 -0
  94. package/scripts/preflight_cache.py +974 -0
  95. package/scripts/preflight_gh.py +721 -0
  96. package/scripts/preflight_implementation.py +272 -0
  97. package/scripts/preflight_story_start.py +838 -0
  98. package/scripts/preflight_wip_cap.py +149 -0
  99. package/scripts/probe_session.py +545 -0
  100. package/scripts/project_render.py +293 -0
  101. package/scripts/quarantine_ext.py +237 -0
  102. package/scripts/reconcile_issues.py +1442 -0
  103. package/scripts/refresh-path.ps1 +107 -0
  104. package/scripts/release.py +2030 -0
  105. package/scripts/release_e2e.py +1011 -0
  106. package/scripts/release_publish.py +486 -0
  107. package/scripts/release_rollback.py +980 -0
  108. package/scripts/relocate.py +1034 -0
  109. package/scripts/resolve_changelog_unreleased.py +667 -0
  110. package/scripts/resolve_version.py +490 -0
  111. package/scripts/resume_conditions.py +706 -0
  112. package/scripts/ritual_sentinel.py +609 -0
  113. package/scripts/roadmap_render.py +635 -0
  114. package/scripts/rule_ownership_lint.py +325 -0
  115. package/scripts/scm.py +591 -0
  116. package/scripts/scope_audit_log.py +387 -0
  117. package/scripts/scope_decompose.py +654 -0
  118. package/scripts/scope_demote.py +509 -0
  119. package/scripts/scope_lifecycle.py +1126 -0
  120. package/scripts/scope_undo.py +772 -0
  121. package/scripts/session_start.py +406 -0
  122. package/scripts/setup_ghx.py +339 -0
  123. package/scripts/setup_windows.ps1 +220 -0
  124. package/scripts/slice_audit.py +585 -0
  125. package/scripts/slice_record.py +530 -0
  126. package/scripts/slice_record_existing.py +692 -0
  127. package/scripts/slug_normalize.py +178 -0
  128. package/scripts/spec_render.py +477 -0
  129. package/scripts/spec_validate.py +238 -0
  130. package/scripts/subagent_monitor.py +658 -0
  131. package/scripts/swarm_complete_cohort.py +644 -0
  132. package/scripts/swarm_launch.py +1206 -0
  133. package/scripts/swarm_readiness.py +554 -0
  134. package/scripts/swarm_verify_review_clean.py +438 -0
  135. package/scripts/swarm_worktrees.py +497 -0
  136. package/scripts/toolchain-check.py +52 -0
  137. package/scripts/triage_actions.py +871 -0
  138. package/scripts/triage_bootstrap.py +1153 -0
  139. package/scripts/triage_bulk.py +630 -0
  140. package/scripts/triage_classify.py +932 -0
  141. package/scripts/triage_help.py +1685 -0
  142. package/scripts/triage_queue.py +1944 -0
  143. package/scripts/triage_reconcile.py +581 -0
  144. package/scripts/triage_refresh.py +643 -0
  145. package/scripts/triage_scope.py +999 -0
  146. package/scripts/triage_scope_drift.py +575 -0
  147. package/scripts/triage_smoketest.py +396 -0
  148. package/scripts/triage_subscribe.py +399 -0
  149. package/scripts/triage_summary.py +1011 -0
  150. package/scripts/triage_welcome.py +1178 -0
  151. package/scripts/ts_check_lane.py +86 -0
  152. package/scripts/validate-links.py +64 -0
  153. package/scripts/validate_strategy_output.py +212 -0
  154. package/scripts/vbrief_activate.py +228 -0
  155. package/scripts/vbrief_migrate_conformance.py +368 -0
  156. package/scripts/vbrief_reconcile_graph.py +306 -0
  157. package/scripts/vbrief_reconcile_labels.py +460 -0
  158. package/scripts/vbrief_reconcile_umbrellas.py +741 -0
  159. package/scripts/vbrief_validate.py +1195 -0
  160. package/scripts/verify-stubs.py +61 -0
  161. package/scripts/verify_capacity.py +160 -0
  162. package/scripts/verify_encoding.py +699 -0
  163. package/scripts/verify_hooks_installed.py +206 -0
  164. package/scripts/verify_investigation.py +360 -0
  165. package/scripts/verify_judgment_gates.py +827 -0
  166. package/scripts/verify_no_task_runtime.py +171 -0
  167. package/scripts/verify_scm_boundary.py +509 -0
  168. package/scripts/verify_session_ritual.py +389 -0
  169. package/scripts/verify_tools.py +426 -0
  170. package/scripts/verify_vbrief_conformance.py +478 -0
  171. package/tasks/architecture.yml +13 -0
  172. package/tasks/cache.yml +69 -0
  173. package/tasks/capacity.yml +38 -0
  174. package/tasks/change.yml +46 -0
  175. package/tasks/changelog.yml +24 -0
  176. package/tasks/ci.yml +49 -0
  177. package/tasks/codebase.yml +47 -0
  178. package/tasks/commit.yml +30 -0
  179. package/tasks/core.yml +126 -0
  180. package/tasks/deployments.yml +54 -0
  181. package/tasks/framework.yml +74 -0
  182. package/tasks/install.yml +60 -0
  183. package/tasks/issue.yml +50 -0
  184. package/tasks/migrate.yml +73 -0
  185. package/tasks/packs.yml +92 -0
  186. package/tasks/policy.yml +75 -0
  187. package/tasks/pr.yml +89 -0
  188. package/tasks/prd.yml +39 -0
  189. package/tasks/project.yml +27 -0
  190. package/tasks/reconcile.yml +32 -0
  191. package/tasks/relocate.yml +56 -0
  192. package/tasks/roadmap.yml +28 -0
  193. package/tasks/scm.yml +126 -0
  194. package/tasks/scope-undo.yml +36 -0
  195. package/tasks/scope.yml +141 -0
  196. package/tasks/session.yml +19 -0
  197. package/tasks/setup.yml +37 -0
  198. package/tasks/slice.yml +69 -0
  199. package/tasks/spec.yml +41 -0
  200. package/tasks/swarm.yml +85 -0
  201. package/tasks/toolchain.yml +13 -0
  202. package/tasks/triage-actions.yml +94 -0
  203. package/tasks/triage-bootstrap.yml +43 -0
  204. package/tasks/triage-bulk.yml +75 -0
  205. package/tasks/triage-classify.yml +30 -0
  206. package/tasks/triage-queue.yml +50 -0
  207. package/tasks/triage-reconcile.yml +29 -0
  208. package/tasks/triage-scope-drift.yml +29 -0
  209. package/tasks/triage-scope.yml +31 -0
  210. package/tasks/triage-smoketest.yml +33 -0
  211. package/tasks/triage-subscribe.yml +36 -0
  212. package/tasks/triage-summary.yml +29 -0
  213. package/tasks/triage-welcome.yml +32 -0
  214. package/tasks/ts.yml +328 -0
  215. package/tasks/vbrief.yml +206 -0
  216. package/tasks/verify.yml +292 -0
  217. package/templates/agents-entry.md +1 -1
@@ -0,0 +1,423 @@
1
+ #!/usr/bin/env python3
2
+ """pack_migrate_skills.py -- one-shot migration: skills/ + routing -> structured pack.
3
+
4
+ Builds the canonical structured source ``packs/skills/skills-pack-0.1.json`` (the
5
+ source of truth per ADR-001) by scanning every ``skills/*/SKILL.md`` and the
6
+ AGENTS.md Skill Routing table. This is the #1295 generalization of the #1294
7
+ lessons pilot: the same render/slice machinery, a second domain.
8
+
9
+ What is captured per skill
10
+ --------------------------
11
+ - ``id`` the YAML frontmatter ``name`` (e.g. deft-directive-cost).
12
+ - ``description`` the frontmatter ``description``, folded to one normalised
13
+ string.
14
+ - ``triggers`` the routing keywords mapped to this skill's path in the
15
+ AGENTS.md Skill Routing table (in table order; empty when unrouted). Triggers
16
+ are NOT read from frontmatter -- the routing table is the single source so the
17
+ pack cannot drift from routing.
18
+ - ``path`` the repo-relative ``skills/<name>/SKILL.md``.
19
+ - ``version`` a frontmatter ``version:`` when present, else ``0.1``.
20
+ - ``body`` the full SKILL.md body (frontmatter stripped, any prior
21
+ provenance banner stripped). Captured for EVERY skill by default (packs:slice
22
+ v2, #1637) so every ``skills/*/SKILL.md`` is a drift-checked projection; the
23
+ back-compat ``--proof-skill`` flag still restricts capture to one skill.
24
+ - ``frontmatter_extra`` the verbatim frontmatter lines that are NOT ``name`` or
25
+ ``description`` (e.g. ``triggers:``, ``metadata:``, ``os:``). The renderer
26
+ reconstructs ``name`` + a folded ``description`` itself and re-emits this block
27
+ verbatim, so regenerating a projection is LOSSLESS -- no hand-authored
28
+ frontmatter key is dropped. ``null`` when a skill carries only name +
29
+ description (the proof-skill shape).
30
+
31
+ SKILL.md files without YAML frontmatter (deprecated redirect stubs) are skipped.
32
+
33
+ Usage::
34
+
35
+ uv run python scripts/pack_migrate_skills.py \\
36
+ [--skills-dir skills] [--agents-md AGENTS.md] \\
37
+ [--proof-skill deft-directive-cost] \\
38
+ [--out packs/skills/skills-pack-0.1.json]
39
+
40
+ Exit codes:
41
+ 0 -- migrated successfully
42
+ 1 -- skills dir / AGENTS.md missing, or no skills discovered
43
+ 2 -- usage error
44
+ """
45
+
46
+ from __future__ import annotations
47
+
48
+ import argparse
49
+ import json
50
+ import re
51
+ import sys
52
+ from pathlib import Path
53
+
54
+ # Repo root resolved from this file's location (scripts/ -> repo root) so the
55
+ # default paths are CWD-independent.
56
+ REPO_ROOT = Path(__file__).resolve().parent.parent
57
+
58
+ sys.path.insert(0, str(Path(__file__).resolve().parent))
59
+ from _content_root import content_root # noqa: E402
60
+
61
+ # Shippable content moved under content/ in the source repo and is
62
+ # flattened to the framework root in a consumer deposit (#1875 C1).
63
+ CONTENT_ROOT = content_root(REPO_ROOT)
64
+ DEFAULT_SKILLS_DIR = CONTENT_ROOT / "skills"
65
+ DEFAULT_AGENTS_MD = REPO_ROOT / "AGENTS.md"
66
+ DEFAULT_OUT = CONTENT_ROOT / "packs" / "skills" / "skills-pack-0.1.json"
67
+
68
+ PACK_ID = "skills-pack-0.1"
69
+ PACK_VERSION = "0.1"
70
+ DEFAULT_SKILL_VERSION = "0.1"
71
+
72
+ _ROUTING_HEADING = "## Skill Routing"
73
+ _QUOTED_RE = re.compile(r'"([^"]+)"')
74
+ # The maintainer AGENTS.md Skill Routing table references the source-repo path,
75
+ # which after the #1875 content/ move is `content/skills/...`. Strip the optional
76
+ # content/ prefix so the captured path stays consumer-relative (`skills/...`) and
77
+ # matches the pack entry paths (which are relative to the flattened deposit root).
78
+ _PATH_RE = re.compile(r"`(?:content/)?(skills/[^`]+/SKILL\.md)`")
79
+ _ARROW_SPLIT_RE = re.compile(r"\u2192|->")
80
+ _FRONTMATTER_RE = re.compile(r"^---\n(.*?\n)---\n?(.*)$", re.DOTALL)
81
+ _KEY_RE = re.compile(r"^([A-Za-z_][\w-]*):(.*)$")
82
+ _BLOCK_INDICATORS = {">", ">-", ">+", "|", "|-", "|+"}
83
+
84
+
85
+ def parse_routing(agents_md_text: str) -> dict[str, list[str]]:
86
+ """Parse the AGENTS.md Skill Routing table into a path -> triggers map.
87
+
88
+ Reads the FIRST ``## Skill Routing`` section (the maintainer table whose
89
+ paths are repo-relative ``skills/...``), up to the next ``## `` heading. For
90
+ each bullet, the double-quoted keywords BEFORE the arrow are the triggers and
91
+ the backticked ``skills/.../SKILL.md`` token is the path. Bullets that route
92
+ to a task (no SKILL.md path) are skipped. Multiple bullets mapping to the
93
+ same path accumulate (deduped, order-preserving).
94
+ """
95
+ start = agents_md_text.find(_ROUTING_HEADING)
96
+ if start == -1:
97
+ return {}
98
+ rest = agents_md_text[start + len(_ROUTING_HEADING):]
99
+ end = rest.find("\n## ")
100
+ section = rest[:end] if end != -1 else rest
101
+
102
+ mapping: dict[str, list[str]] = {}
103
+ for raw in section.splitlines():
104
+ line = raw.strip()
105
+ if not line.startswith("- "):
106
+ continue
107
+ path_match = _PATH_RE.search(line)
108
+ if not path_match:
109
+ continue
110
+ path = path_match.group(1)
111
+ head = _ARROW_SPLIT_RE.split(line, maxsplit=1)[0]
112
+ keywords = _QUOTED_RE.findall(head)
113
+ bucket = mapping.setdefault(path, [])
114
+ for kw in keywords:
115
+ if kw not in bucket:
116
+ bucket.append(kw)
117
+ return mapping
118
+
119
+
120
+ def split_frontmatter(text: str) -> tuple[str | None, str]:
121
+ """Split a SKILL.md into (frontmatter_block, body).
122
+
123
+ Returns ``(None, text)`` when the document has no leading ``---`` YAML
124
+ frontmatter (e.g. a deprecated redirect stub). ``frontmatter_block`` is the
125
+ text between the fences; ``body`` is everything after the closing fence.
126
+ """
127
+ if not text.startswith("---\n"):
128
+ return None, text
129
+ match = _FRONTMATTER_RE.match(text)
130
+ if not match:
131
+ return None, text
132
+ return match.group(1), match.group(2)
133
+
134
+
135
+ def _fold_block(block_lines: list[str]) -> str:
136
+ """Fold a YAML folded block scalar's lines into a single normalised string.
137
+
138
+ Non-empty lines within a paragraph join with single spaces; blank lines
139
+ separate paragraphs (joined with a newline). Sufficient for the single-
140
+ paragraph skill descriptions in this repo.
141
+ """
142
+ paragraphs: list[str] = []
143
+ current: list[str] = []
144
+ for line in block_lines:
145
+ if line.strip() == "":
146
+ if current:
147
+ paragraphs.append(" ".join(current))
148
+ current = []
149
+ else:
150
+ current.append(line.strip())
151
+ if current:
152
+ paragraphs.append(" ".join(current))
153
+ return "\n".join(paragraphs)
154
+
155
+
156
+ def parse_frontmatter_fields(frontmatter: str) -> dict[str, str]:
157
+ """Extract scalar / folded fields (name, description, version, ...).
158
+
159
+ Handles inline scalars (``name: foo``), folded / literal block scalars
160
+ (``description: >``), and skips list values (``triggers:`` + ``- item``).
161
+ Only top-level (zero-indent) keys are recognised.
162
+ """
163
+ lines = frontmatter.split("\n")
164
+ fields: dict[str, str] = {}
165
+ i = 0
166
+ n = len(lines)
167
+ while i < n:
168
+ line = lines[i]
169
+ match = _KEY_RE.match(line)
170
+ if not match or line.startswith((" ", "\t")):
171
+ i += 1
172
+ continue
173
+ key = match.group(1)
174
+ value = match.group(2).strip()
175
+ if value in _BLOCK_INDICATORS:
176
+ block: list[str] = []
177
+ i += 1
178
+ while i < n:
179
+ nxt = lines[i]
180
+ if nxt.strip() == "":
181
+ block.append("")
182
+ i += 1
183
+ continue
184
+ if nxt.startswith((" ", "\t")):
185
+ block.append(nxt)
186
+ i += 1
187
+ continue
188
+ break
189
+ fields[key] = _fold_block(block)
190
+ continue
191
+ if value == "" or value.startswith("- "):
192
+ # Likely a block sequence (e.g. triggers:). Consume its `- ` items
193
+ # so they are not mis-parsed as top-level keys; value is not needed.
194
+ i += 1
195
+ while i < n and (
196
+ lines[i].lstrip().startswith("- ") or lines[i].startswith((" ", "\t"))
197
+ ):
198
+ i += 1
199
+ fields.setdefault(key, "")
200
+ continue
201
+ fields[key] = value.strip().strip('"').strip("'")
202
+ i += 1
203
+ return fields
204
+
205
+
206
+ def extract_extra_frontmatter(frontmatter: str) -> str | None:
207
+ """Return the verbatim frontmatter lines that are NOT ``name``/``description``.
208
+
209
+ The renderer reconstructs ``name`` + a folded ``description`` from the
210
+ structured fields, but every OTHER top-level key a skill declares
211
+ (``triggers:``, ``metadata:``, ``os:``, ``version:``, ...) must survive the
212
+ round-trip so regenerating a projection is LOSSLESS -- the migration would
213
+ otherwise silently drop e.g. ``metadata.clawdbot.requires.bins`` (#1637).
214
+
215
+ Each top-level key (and its block-scalar / block-sequence / nested
216
+ continuation lines) is preserved verbatim. Returns ``None`` when only
217
+ ``name`` + ``description`` are present (the proof-skill shape), so the
218
+ renderer emits exactly the name + description frontmatter.
219
+ """
220
+ lines = frontmatter.split("\n")
221
+ extra: list[str] = []
222
+ i = 0
223
+ n = len(lines)
224
+ while i < n:
225
+ line = lines[i]
226
+ match = _KEY_RE.match(line)
227
+ if not match or line.startswith((" ", "\t")):
228
+ i += 1
229
+ continue
230
+ key = match.group(1)
231
+ value = match.group(2).strip()
232
+ block = [line]
233
+ i += 1
234
+ if value in _BLOCK_INDICATORS:
235
+ while i < n and (lines[i].strip() == "" or lines[i].startswith((" ", "\t"))):
236
+ block.append(lines[i])
237
+ i += 1
238
+ elif value == "" or value.startswith("- "):
239
+ while i < n and (
240
+ lines[i].lstrip().startswith("- ") or lines[i].startswith((" ", "\t"))
241
+ ):
242
+ block.append(lines[i])
243
+ i += 1
244
+ if key not in ("name", "description"):
245
+ extra.extend(block)
246
+ while extra and extra[-1].strip() == "":
247
+ extra.pop()
248
+ return "\n".join(extra) if extra else None
249
+
250
+
251
+ def strip_leading_banner(body: str) -> str:
252
+ """Strip a leading provenance banner + blank lines from a captured body.
253
+
254
+ Makes re-migration idempotent: after the proof skill's SKILL.md is
255
+ regenerated (frontmatter + banner + body), re-running the migration must
256
+ recover the same body. Only strips a banner block that opens with the
257
+ renderer's first banner line, so unrelated leading HTML comments survive.
258
+ """
259
+ lines = body.split("\n")
260
+ i = 0
261
+ while i < len(lines) and lines[i].strip() == "":
262
+ i += 1
263
+ if i < len(lines) and lines[i].startswith("<!-- AUTO-GENERATED by task packs:render"):
264
+ while i < len(lines) and lines[i].lstrip().startswith("<!--"):
265
+ i += 1
266
+ while i < len(lines) and lines[i].strip() == "":
267
+ i += 1
268
+ return "\n".join(lines[i:])
269
+
270
+
271
+ def build_skill_entry(
272
+ skill_md: Path,
273
+ skills_dir: Path,
274
+ routing: dict[str, list[str]],
275
+ *,
276
+ capture_body: bool,
277
+ ) -> dict | None:
278
+ """Build one skill entry, or None when the file has no YAML frontmatter."""
279
+ text = skill_md.read_text(encoding="utf-8")
280
+ frontmatter, body = split_frontmatter(text)
281
+ if frontmatter is None:
282
+ return None
283
+ fields = parse_frontmatter_fields(frontmatter)
284
+ name = fields.get("name", "").strip()
285
+ if not name:
286
+ return None
287
+
288
+ rel_path = skill_md.resolve().relative_to(skills_dir.resolve().parent).as_posix()
289
+ triggers = routing.get(rel_path, [])
290
+ version = fields.get("version", "").strip() or DEFAULT_SKILL_VERSION
291
+ captured = strip_leading_banner(body) if capture_body else None
292
+
293
+ return {
294
+ "id": name,
295
+ "description": fields.get("description", "").strip(),
296
+ "triggers": triggers,
297
+ "path": rel_path,
298
+ "version": version,
299
+ "body": captured,
300
+ "frontmatter_extra": extract_extra_frontmatter(frontmatter),
301
+ }
302
+
303
+
304
+ def build_pack(
305
+ skills_dir: Path,
306
+ agents_md: Path,
307
+ *,
308
+ proof_skill: str | None,
309
+ ) -> dict:
310
+ """Scan the skills dir + routing table and assemble the full pack object.
311
+
312
+ ``proof_skill`` is the back-compat single-skill restrictor: when ``None``
313
+ (the default, packs:slice v2 / #1637) the body is captured for EVERY skill;
314
+ when set, only that one skill's body is captured (the #1295 proof shape).
315
+ """
316
+ routing = parse_routing(agents_md.read_text(encoding="utf-8"))
317
+ capture_all = proof_skill is None
318
+ proof_path = f"skills/{proof_skill}/SKILL.md" if proof_skill else None
319
+
320
+ skills: list[dict] = []
321
+ for skill_md in sorted(skills_dir.glob("*/SKILL.md")):
322
+ rel_path = skill_md.resolve().relative_to(skills_dir.resolve().parent).as_posix()
323
+ entry = build_skill_entry(
324
+ skill_md,
325
+ skills_dir,
326
+ routing,
327
+ capture_body=(capture_all or rel_path == proof_path),
328
+ )
329
+ if entry is not None:
330
+ skills.append(entry)
331
+
332
+ return {
333
+ "pack": PACK_ID,
334
+ "version": PACK_VERSION,
335
+ "generated_from": "skills/*/SKILL.md + AGENTS.md (Skill Routing)",
336
+ "skills": skills,
337
+ }
338
+
339
+
340
+ def migrate(
341
+ skills_dir: Path,
342
+ agents_md: Path,
343
+ out: Path,
344
+ *,
345
+ proof_skill: str | None,
346
+ ) -> dict:
347
+ """Build the pack from ``skills_dir`` + ``agents_md`` and write it to ``out``.
348
+
349
+ Raises ``FileNotFoundError`` when an input is missing and ``ValueError`` when
350
+ no frontmatter-bearing skills are discovered.
351
+ """
352
+ if not skills_dir.is_dir():
353
+ raise FileNotFoundError(f"skills directory not found: {skills_dir}")
354
+ if not agents_md.is_file():
355
+ raise FileNotFoundError(f"AGENTS.md not found: {agents_md}")
356
+
357
+ pack = build_pack(skills_dir, agents_md, proof_skill=proof_skill)
358
+ if not pack["skills"]:
359
+ raise ValueError(f"no skills with frontmatter discovered under {skills_dir}")
360
+
361
+ out.parent.mkdir(parents=True, exist_ok=True)
362
+ # ensure_ascii=True: the canonical source is serialized as pure ASCII with
363
+ # \uXXXX escapes (mirrors pack_migrate_lessons). Lossless and keeps the JSON
364
+ # clean against `task verify:encoding` (#798) even when a skill body carries
365
+ # non-ASCII glyphs (em dashes, RFC2119 symbols).
366
+ out.write_text(json.dumps(pack, indent=2, ensure_ascii=True) + "\n", encoding="utf-8")
367
+ return pack
368
+
369
+
370
+ def main(argv: list[str] | None = None) -> int:
371
+ parser = argparse.ArgumentParser(
372
+ prog="pack_migrate_skills.py",
373
+ description="Migrate skills/ + AGENTS.md routing into the skills-pack-0.1 source.",
374
+ )
375
+ parser.add_argument(
376
+ "--skills-dir",
377
+ type=Path,
378
+ default=DEFAULT_SKILLS_DIR,
379
+ help="Directory of skill folders to scan (default: skills/).",
380
+ )
381
+ parser.add_argument(
382
+ "--agents-md",
383
+ type=Path,
384
+ default=DEFAULT_AGENTS_MD,
385
+ help="AGENTS.md whose Skill Routing table maps keywords -> paths.",
386
+ )
387
+ parser.add_argument(
388
+ "--proof-skill",
389
+ default=None,
390
+ help="Back-compat: restrict body capture to ONE skill's directory name "
391
+ "(e.g. deft-directive-cost). Default: capture every skill's body (#1637).",
392
+ )
393
+ parser.add_argument(
394
+ "--out",
395
+ type=Path,
396
+ default=DEFAULT_OUT,
397
+ help="Output pack JSON path (default: packs/skills/skills-pack-0.1.json).",
398
+ )
399
+ args = parser.parse_args(argv)
400
+
401
+ try:
402
+ pack = migrate(
403
+ args.skills_dir,
404
+ args.agents_md,
405
+ args.out,
406
+ proof_skill=args.proof_skill,
407
+ )
408
+ except FileNotFoundError as exc:
409
+ print(f"error: {exc}", file=sys.stderr)
410
+ return 1
411
+ except ValueError as exc:
412
+ print(f"error: {exc}", file=sys.stderr)
413
+ return 1
414
+
415
+ bodied = sum(1 for s in pack["skills"] if s["body"] is not None)
416
+ print(
417
+ f"Migrated {len(pack['skills'])} skills ({bodied} with body) -> {args.out}"
418
+ )
419
+ return 0
420
+
421
+
422
+ if __name__ == "__main__":
423
+ raise SystemExit(main())