@blxzer/cursor-trellis 0.1.0 → 0.1.1

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 (279) hide show
  1. package/README.md +124 -5
  2. package/README.zh-CN.md +170 -0
  3. package/dist/cli/index.d.ts.map +1 -1
  4. package/dist/cli/index.js +1 -33
  5. package/dist/cli/index.js.map +1 -1
  6. package/dist/commands/init.d.ts +0 -13
  7. package/dist/commands/init.d.ts.map +1 -1
  8. package/dist/commands/init.js +7 -14
  9. package/dist/commands/init.js.map +1 -1
  10. package/dist/commands/uninstall.d.ts.map +1 -1
  11. package/dist/commands/uninstall.js +3 -32
  12. package/dist/commands/uninstall.js.map +1 -1
  13. package/dist/commands/update.d.ts.map +1 -1
  14. package/dist/commands/update.js +7 -84
  15. package/dist/commands/update.js.map +1 -1
  16. package/dist/configurators/index.d.ts +7 -8
  17. package/dist/configurators/index.d.ts.map +1 -1
  18. package/dist/configurators/index.js +11 -236
  19. package/dist/configurators/index.js.map +1 -1
  20. package/dist/configurators/workflow.d.ts.map +1 -1
  21. package/dist/configurators/workflow.js +5 -1
  22. package/dist/configurators/workflow.js.map +1 -1
  23. package/dist/templates/common/bundled-skills/smart-search-cli/SKILL.md +3 -3
  24. package/dist/templates/common/bundled-skills/trellis-meta/SKILL.md +4 -2
  25. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-agents.md +8 -15
  26. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-hooks.md +7 -7
  27. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-skills-or-commands.md +18 -21
  28. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/overview.md +2 -2
  29. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/generated-files.md +10 -7
  30. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/overview.md +4 -4
  31. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/agents.md +20 -31
  32. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/hooks-and-settings.md +20 -31
  33. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/overview.md +24 -40
  34. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/platform-map.md +28 -59
  35. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/skills-and-commands.md +12 -28
  36. package/dist/templates/common/bundled-skills/trellis-skill-creator/references/trellis-skill-locations.md +2 -2
  37. package/dist/templates/cursor/hooks.json +6 -0
  38. package/dist/templates/cursor/rules/retrieval-routing.mdc +57 -0
  39. package/dist/templates/extract.d.ts +0 -14
  40. package/dist/templates/extract.d.ts.map +1 -1
  41. package/dist/templates/extract.js +0 -34
  42. package/dist/templates/extract.js.map +1 -1
  43. package/dist/templates/markdown/agents.md +2 -6
  44. package/dist/templates/markdown/index.d.ts +1 -0
  45. package/dist/templates/markdown/index.d.ts.map +1 -1
  46. package/dist/templates/markdown/index.js +1 -0
  47. package/dist/templates/markdown/index.js.map +1 -1
  48. package/dist/templates/markdown/prompts/run-semantic-slice-12.md.txt +41 -0
  49. package/dist/templates/markdown/spec/guides/code-reuse-thinking-guide.md.txt +14 -14
  50. package/dist/templates/markdown/spec/guides/cross-layer-thinking-guide.md.txt +8 -20
  51. package/dist/templates/markdown/spec/guides/cross-platform-thinking-guide.md.txt +15 -14
  52. package/dist/templates/markdown/spec/guides/cursor-context-injection-guide.md.txt +2 -1
  53. package/dist/templates/markdown/spec/guides/cursor-semantic-compliance.md.txt +49 -0
  54. package/dist/templates/markdown/spec/guides/cursor-subagent-policy.md.txt +2 -2
  55. package/dist/templates/markdown/spec/guides/retrieval-daily-guide.md.txt +68 -20
  56. package/dist/templates/shared-hooks/index.d.ts +1 -1
  57. package/dist/templates/shared-hooks/index.d.ts.map +1 -1
  58. package/dist/templates/shared-hooks/index.js +1 -0
  59. package/dist/templates/shared-hooks/index.js.map +1 -1
  60. package/dist/templates/shared-hooks/inject-retrieval-plan.py +163 -0
  61. package/dist/templates/shared-hooks/research-end-retrieval-pack.py +2 -11
  62. package/dist/templates/trellis/index.d.ts +11 -0
  63. package/dist/templates/trellis/index.d.ts.map +1 -1
  64. package/dist/templates/trellis/index.js +22 -0
  65. package/dist/templates/trellis/index.js.map +1 -1
  66. package/dist/templates/trellis/scripts/aggregate_retrieval_telemetry.py +342 -0
  67. package/dist/templates/trellis/scripts/batch_plan_envelope.py +105 -0
  68. package/dist/templates/trellis/scripts/codegraph_session_smoke.py +76 -0
  69. package/dist/templates/trellis/scripts/common/active_task.py +116 -147
  70. package/dist/templates/trellis/scripts/common/cli_adapter.py +34 -710
  71. package/dist/templates/trellis/scripts/common/codebase_retrieval_router.py +49 -106
  72. package/dist/templates/trellis/scripts/common/git_context.py +17 -2
  73. package/dist/templates/trellis/scripts/common/project_file_stats.py +91 -0
  74. package/dist/templates/trellis/scripts/common/retrieval_adapter_metadata.py +9 -11
  75. package/dist/templates/trellis/scripts/common/retrieval_agent_instructions.py +313 -0
  76. package/dist/templates/trellis/scripts/common/retrieval_pack.py +0 -6
  77. package/dist/templates/trellis/scripts/common/retrieval_pack_context.py +0 -4
  78. package/dist/templates/trellis/scripts/common/retrieval_plan_gate.py +76 -0
  79. package/dist/templates/trellis/scripts/common/retrieval_result_ranking.py +253 -0
  80. package/dist/templates/trellis/scripts/common/retrieval_tool_classification.py +157 -0
  81. package/dist/templates/trellis/scripts/common/semantic_plan_gate.py +52 -0
  82. package/dist/templates/trellis/scripts/common/workflow_phase.py +3 -24
  83. package/dist/templates/trellis/scripts/rank_retrieval_candidates.py +80 -0
  84. package/dist/templates/trellis/scripts/route_codebase_retrieval.py +38 -11
  85. package/dist/templates/trellis/scripts/score_evidence.py +112 -0
  86. package/dist/templates/trellis/workflow.md +861 -960
  87. package/dist/types/ai-tools.d.ts +13 -16
  88. package/dist/types/ai-tools.d.ts.map +1 -1
  89. package/dist/types/ai-tools.js +5 -238
  90. package/dist/types/ai-tools.js.map +1 -1
  91. package/dist/utils/codebase-retrieval-router.d.ts +1 -8
  92. package/dist/utils/codebase-retrieval-router.d.ts.map +1 -1
  93. package/dist/utils/codebase-retrieval-router.js +39 -180
  94. package/dist/utils/codebase-retrieval-router.js.map +1 -1
  95. package/dist/utils/project-capabilities.d.ts.map +1 -1
  96. package/dist/utils/project-capabilities.js +10 -24
  97. package/dist/utils/project-capabilities.js.map +1 -1
  98. package/dist/utils/retrieval-agent-instructions.d.ts +14 -0
  99. package/dist/utils/retrieval-agent-instructions.d.ts.map +1 -0
  100. package/dist/utils/retrieval-agent-instructions.js +221 -0
  101. package/dist/utils/retrieval-agent-instructions.js.map +1 -0
  102. package/dist/utils/retrieval-execution-telemetry.d.ts +43 -85
  103. package/dist/utils/retrieval-execution-telemetry.d.ts.map +1 -1
  104. package/dist/utils/retrieval-execution-telemetry.js +289 -22
  105. package/dist/utils/retrieval-execution-telemetry.js.map +1 -1
  106. package/dist/utils/retrieval-result-ranking.js +1 -1
  107. package/dist/utils/retrieval-result-ranking.js.map +1 -1
  108. package/dist/utils/retrieval-tool-classification.d.ts +32 -0
  109. package/dist/utils/retrieval-tool-classification.d.ts.map +1 -0
  110. package/dist/utils/retrieval-tool-classification.js +113 -0
  111. package/dist/utils/retrieval-tool-classification.js.map +1 -0
  112. package/dist/utils/uninstall-scrubbers.d.ts +0 -36
  113. package/dist/utils/uninstall-scrubbers.d.ts.map +1 -1
  114. package/dist/utils/uninstall-scrubbers.js +0 -184
  115. package/dist/utils/uninstall-scrubbers.js.map +1 -1
  116. package/package.json +4 -2
  117. package/dist/commands/mem.d.ts +0 -30
  118. package/dist/commands/mem.d.ts.map +0 -1
  119. package/dist/commands/mem.js +0 -424
  120. package/dist/commands/mem.js.map +0 -1
  121. package/dist/configurators/antigravity.d.ts +0 -7
  122. package/dist/configurators/antigravity.d.ts.map +0 -1
  123. package/dist/configurators/antigravity.js +0 -19
  124. package/dist/configurators/antigravity.js.map +0 -1
  125. package/dist/configurators/claude.d.ts +0 -9
  126. package/dist/configurators/claude.d.ts.map +0 -1
  127. package/dist/configurators/claude.js +0 -72
  128. package/dist/configurators/claude.js.map +0 -1
  129. package/dist/configurators/codebuddy.d.ts +0 -10
  130. package/dist/configurators/codebuddy.d.ts.map +0 -1
  131. package/dist/configurators/codebuddy.js +0 -30
  132. package/dist/configurators/codebuddy.js.map +0 -1
  133. package/dist/configurators/codex.d.ts +0 -8
  134. package/dist/configurators/codex.d.ts.map +0 -1
  135. package/dist/configurators/codex.js +0 -87
  136. package/dist/configurators/codex.js.map +0 -1
  137. package/dist/configurators/copilot.d.ts +0 -10
  138. package/dist/configurators/copilot.d.ts.map +0 -1
  139. package/dist/configurators/copilot.js +0 -51
  140. package/dist/configurators/copilot.js.map +0 -1
  141. package/dist/configurators/droid.d.ts +0 -10
  142. package/dist/configurators/droid.d.ts.map +0 -1
  143. package/dist/configurators/droid.js +0 -30
  144. package/dist/configurators/droid.js.map +0 -1
  145. package/dist/configurators/gemini.d.ts +0 -16
  146. package/dist/configurators/gemini.d.ts.map +0 -1
  147. package/dist/configurators/gemini.js +0 -38
  148. package/dist/configurators/gemini.js.map +0 -1
  149. package/dist/configurators/kilo.d.ts +0 -7
  150. package/dist/configurators/kilo.d.ts.map +0 -1
  151. package/dist/configurators/kilo.js +0 -19
  152. package/dist/configurators/kilo.js.map +0 -1
  153. package/dist/configurators/kiro.d.ts +0 -8
  154. package/dist/configurators/kiro.d.ts.map +0 -1
  155. package/dist/configurators/kiro.js +0 -24
  156. package/dist/configurators/kiro.js.map +0 -1
  157. package/dist/configurators/opencode.d.ts +0 -14
  158. package/dist/configurators/opencode.d.ts.map +0 -1
  159. package/dist/configurators/opencode.js +0 -96
  160. package/dist/configurators/opencode.js.map +0 -1
  161. package/dist/configurators/pi.d.ts +0 -3
  162. package/dist/configurators/pi.d.ts.map +0 -1
  163. package/dist/configurators/pi.js +0 -45
  164. package/dist/configurators/pi.js.map +0 -1
  165. package/dist/configurators/qoder.d.ts +0 -11
  166. package/dist/configurators/qoder.d.ts.map +0 -1
  167. package/dist/configurators/qoder.js +0 -31
  168. package/dist/configurators/qoder.js.map +0 -1
  169. package/dist/configurators/windsurf.d.ts +0 -7
  170. package/dist/configurators/windsurf.d.ts.map +0 -1
  171. package/dist/configurators/windsurf.js +0 -19
  172. package/dist/configurators/windsurf.js.map +0 -1
  173. package/dist/templates/claude/agents/trellis-check.md +0 -124
  174. package/dist/templates/claude/agents/trellis-implement.md +0 -110
  175. package/dist/templates/claude/agents/trellis-research.md +0 -137
  176. package/dist/templates/claude/index.d.ts +0 -22
  177. package/dist/templates/claude/index.d.ts.map +0 -1
  178. package/dist/templates/claude/index.js +0 -46
  179. package/dist/templates/claude/index.js.map +0 -1
  180. package/dist/templates/claude/settings.json +0 -84
  181. package/dist/templates/codebuddy/agents/trellis-check.md +0 -115
  182. package/dist/templates/codebuddy/agents/trellis-implement.md +0 -110
  183. package/dist/templates/codebuddy/agents/trellis-research.md +0 -137
  184. package/dist/templates/codebuddy/index.d.ts +0 -15
  185. package/dist/templates/codebuddy/index.d.ts.map +0 -1
  186. package/dist/templates/codebuddy/index.js +0 -15
  187. package/dist/templates/codebuddy/index.js.map +0 -1
  188. package/dist/templates/codebuddy/settings.json +0 -70
  189. package/dist/templates/codex/agents/trellis-check.toml +0 -67
  190. package/dist/templates/codex/agents/trellis-implement.toml +0 -40
  191. package/dist/templates/codex/agents/trellis-research.toml +0 -73
  192. package/dist/templates/codex/config.toml +0 -28
  193. package/dist/templates/codex/hooks/session-start.py +0 -575
  194. package/dist/templates/codex/hooks.json +0 -15
  195. package/dist/templates/codex/index.d.ts +0 -39
  196. package/dist/templates/codex/index.d.ts.map +0 -1
  197. package/dist/templates/codex/index.js +0 -85
  198. package/dist/templates/codex/index.js.map +0 -1
  199. package/dist/templates/codex/skills/before-dev/SKILL.md +0 -40
  200. package/dist/templates/codex/skills/brainstorm/SKILL.md +0 -112
  201. package/dist/templates/codex/skills/break-loop/SKILL.md +0 -130
  202. package/dist/templates/codex/skills/check/SKILL.md +0 -98
  203. package/dist/templates/codex/skills/check-cross-layer/SKILL.md +0 -158
  204. package/dist/templates/codex/skills/create-command/SKILL.md +0 -101
  205. package/dist/templates/codex/skills/finish-work/SKILL.md +0 -90
  206. package/dist/templates/codex/skills/improve-ut/SKILL.md +0 -69
  207. package/dist/templates/codex/skills/integrate-skill/SKILL.md +0 -221
  208. package/dist/templates/codex/skills/onboard/SKILL.md +0 -363
  209. package/dist/templates/codex/skills/record-session/SKILL.md +0 -67
  210. package/dist/templates/codex/skills/start/SKILL.md +0 -66
  211. package/dist/templates/codex/skills/update-spec/SKILL.md +0 -335
  212. package/dist/templates/copilot/hooks/session-start.py +0 -557
  213. package/dist/templates/copilot/hooks.json +0 -19
  214. package/dist/templates/copilot/index.d.ts +0 -23
  215. package/dist/templates/copilot/index.d.ts.map +0 -1
  216. package/dist/templates/copilot/index.js +0 -54
  217. package/dist/templates/copilot/index.js.map +0 -1
  218. package/dist/templates/copilot/prompts/before-dev.prompt.md +0 -39
  219. package/dist/templates/copilot/prompts/brainstorm.prompt.md +0 -111
  220. package/dist/templates/copilot/prompts/break-loop.prompt.md +0 -129
  221. package/dist/templates/copilot/prompts/check-cross-layer.prompt.md +0 -157
  222. package/dist/templates/copilot/prompts/check.prompt.md +0 -97
  223. package/dist/templates/copilot/prompts/create-command.prompt.md +0 -116
  224. package/dist/templates/copilot/prompts/finish-work.prompt.md +0 -99
  225. package/dist/templates/copilot/prompts/integrate-skill.prompt.md +0 -223
  226. package/dist/templates/copilot/prompts/onboard.prompt.md +0 -362
  227. package/dist/templates/copilot/prompts/parallel.prompt.md +0 -204
  228. package/dist/templates/copilot/prompts/record-session.prompt.md +0 -66
  229. package/dist/templates/copilot/prompts/start.prompt.md +0 -63
  230. package/dist/templates/copilot/prompts/update-spec.prompt.md +0 -358
  231. package/dist/templates/droid/droids/trellis-check.md +0 -107
  232. package/dist/templates/droid/droids/trellis-implement.md +0 -102
  233. package/dist/templates/droid/droids/trellis-research.md +0 -137
  234. package/dist/templates/droid/index.d.ts +0 -15
  235. package/dist/templates/droid/index.d.ts.map +0 -1
  236. package/dist/templates/droid/index.js +0 -15
  237. package/dist/templates/droid/index.js.map +0 -1
  238. package/dist/templates/droid/settings.json +0 -70
  239. package/dist/templates/gemini/agents/trellis-check.md +0 -107
  240. package/dist/templates/gemini/agents/trellis-implement.md +0 -102
  241. package/dist/templates/gemini/agents/trellis-research.md +0 -136
  242. package/dist/templates/gemini/index.d.ts +0 -13
  243. package/dist/templates/gemini/index.d.ts.map +0 -1
  244. package/dist/templates/gemini/index.js +0 -13
  245. package/dist/templates/gemini/index.js.map +0 -1
  246. package/dist/templates/gemini/settings.json +0 -28
  247. package/dist/templates/kiro/agents/trellis-check.json +0 -26
  248. package/dist/templates/kiro/agents/trellis-implement.json +0 -26
  249. package/dist/templates/kiro/agents/trellis-research.json +0 -30
  250. package/dist/templates/kiro/index.d.ts +0 -18
  251. package/dist/templates/kiro/index.d.ts.map +0 -1
  252. package/dist/templates/kiro/index.js +0 -18
  253. package/dist/templates/kiro/index.js.map +0 -1
  254. package/dist/templates/opencode/agents/trellis-check.md +0 -122
  255. package/dist/templates/opencode/agents/trellis-implement.md +0 -118
  256. package/dist/templates/opencode/agents/trellis-research.md +0 -145
  257. package/dist/templates/opencode/lib/session-utils.js +0 -667
  258. package/dist/templates/opencode/lib/trellis-context.js +0 -336
  259. package/dist/templates/opencode/package.json +0 -5
  260. package/dist/templates/opencode/plugins/inject-subagent-context.js +0 -495
  261. package/dist/templates/opencode/plugins/inject-workflow-state.js +0 -159
  262. package/dist/templates/opencode/plugins/session-start.js +0 -101
  263. package/dist/templates/pi/agents/trellis-check.md +0 -37
  264. package/dist/templates/pi/agents/trellis-implement.md +0 -42
  265. package/dist/templates/pi/agents/trellis-research.md +0 -25
  266. package/dist/templates/pi/extensions/trellis/index.ts.txt +0 -1600
  267. package/dist/templates/pi/index.d.ts +0 -5
  268. package/dist/templates/pi/index.d.ts.map +0 -1
  269. package/dist/templates/pi/index.js +0 -12
  270. package/dist/templates/pi/index.js.map +0 -1
  271. package/dist/templates/pi/settings.json +0 -12
  272. package/dist/templates/qoder/agents/trellis-check.md +0 -108
  273. package/dist/templates/qoder/agents/trellis-implement.md +0 -103
  274. package/dist/templates/qoder/agents/trellis-research.md +0 -137
  275. package/dist/templates/qoder/index.d.ts +0 -15
  276. package/dist/templates/qoder/index.d.ts.map +0 -1
  277. package/dist/templates/qoder/index.js +0 -15
  278. package/dist/templates/qoder/index.js.map +0 -1
  279. package/dist/templates/qoder/settings.json +0 -47
@@ -1,575 +0,0 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """
4
- Codex Session Start Hook - Inject Trellis context into Codex sessions.
5
-
6
- Output format follows Codex hook protocol:
7
- stdout JSON → { hookSpecificOutput: { hookEventName: "SessionStart", additionalContext: "..." } }
8
- """
9
-
10
- from __future__ import annotations
11
-
12
- import json
13
- import os
14
- import re
15
- import subprocess
16
- import sys
17
- import warnings
18
- from io import StringIO
19
- from pathlib import Path
20
-
21
- # Force UTF-8 on stdin/stdout/stderr on Windows. Default codepage there is
22
- # cp936 / cp1252 / etc. — non-ASCII content (Chinese task names, prd snippets)
23
- # both in stdin (hook payload from host CLI) and stdout (our emitted blocks)
24
- # raises UnicodeDecodeError / UnicodeEncodeError. Equivalent to `python -X utf8`
25
- # but applied per-stream so we don't depend on host CLI's command wiring.
26
- if sys.platform.startswith("win"):
27
- import io as _io
28
- for _stream_name in ("stdin", "stdout", "stderr"):
29
- _stream = getattr(sys, _stream_name, None)
30
- if _stream is None:
31
- continue
32
- if hasattr(_stream, "reconfigure"):
33
- try:
34
- _stream.reconfigure(encoding="utf-8", errors="replace") # type: ignore[union-attr]
35
- except Exception:
36
- pass
37
- elif hasattr(_stream, "detach"):
38
- try:
39
- setattr(sys, _stream_name, _io.TextIOWrapper(_stream.detach(), encoding="utf-8", errors="replace"))
40
- except Exception:
41
- pass
42
-
43
-
44
- def _normalize_windows_shell_path(path_str: str) -> str:
45
- """Normalize Unix-style shell paths to real Windows paths.
46
-
47
- On Windows, shells like Git Bash / MSYS2 / Cygwin may report paths like
48
- `/d/Users/...` or `/cygdrive/d/Users/...`. `Path.resolve()` will misinterpret
49
- these as `D:/d/Users...` on drive D: (or similar), breaking repo root
50
- detection.
51
-
52
- This function is intentionally conservative: it only rewrites patterns that
53
- unambiguously represent a drive letter mount.
54
- """
55
- if not isinstance(path_str, str) or not path_str:
56
- return path_str
57
-
58
- # Only relevant on Windows; keep other platforms untouched.
59
- if not sys.platform.startswith("win"):
60
- return path_str
61
-
62
- p = path_str.strip()
63
-
64
- # Already a Windows drive path (C:\... or C:/...)
65
- if re.match(r"^[A-Za-z]:[\/]", p):
66
- return p
67
-
68
- # MSYS/Git-Bash style: /c/Users/... or /d/Work/...
69
- m = re.match(r"^/([A-Za-z])/(.*)", p)
70
- if m:
71
- drive, rest = m.group(1).upper(), m.group(2)
72
- rest = rest.replace('/', '\\')
73
- return f"{drive}:\\{rest}"
74
-
75
- # Cygwin style: /cygdrive/c/Users/...
76
- m = re.match(r"^/cygdrive/([A-Za-z])/(.*)", p)
77
- if m:
78
- drive, rest = m.group(1).upper(), m.group(2)
79
- rest = rest.replace('/', '\\')
80
- return f"{drive}:\\{rest}"
81
-
82
- # WSL mounted drive (sometimes leaked into env): /mnt/c/Users/...
83
- m = re.match(r"^/mnt/([A-Za-z])/(.*)", p)
84
- if m:
85
- drive, rest = m.group(1).upper(), m.group(2)
86
- rest = rest.replace('/', '\\')
87
- return f"{drive}:\\{rest}"
88
-
89
- return path_str
90
-
91
-
92
- warnings.filterwarnings("ignore")
93
-
94
- FIRST_REPLY_NOTICE = """<first-reply-notice>
95
- On the first visible assistant reply in this session, begin with exactly one short Chinese sentence:
96
- Trellis SessionStart 已注入:workflow、selected task 状态、开发者身份、git 状态、Task Dashboard、spec 索引已加载。
97
- Then continue directly with the user's request. This notice is one-shot: do not repeat it after the first assistant reply in the same session.
98
- </first-reply-notice>"""
99
-
100
- def should_skip_injection() -> bool:
101
- if os.environ.get("TRELLIS_HOOKS") == "0":
102
- return True
103
- if os.environ.get("TRELLIS_DISABLE_HOOKS") == "1":
104
- return True
105
- return os.environ.get("CODEX_NON_INTERACTIVE") == "1"
106
-
107
-
108
- def configure_project_encoding(project_dir: Path) -> None:
109
- """Reuse Trellis' shared Windows stdio encoding helper before JSON output."""
110
- scripts_dir = project_dir / ".trellis" / "scripts"
111
- if str(scripts_dir) not in sys.path:
112
- sys.path.insert(0, str(scripts_dir))
113
-
114
- try:
115
- from common import configure_encoding # type: ignore[import-not-found]
116
-
117
- configure_encoding()
118
- except Exception:
119
- pass
120
-
121
-
122
- def _has_curated_jsonl_entry(jsonl_path: Path) -> bool:
123
- """Return True iff jsonl has at least one row with a ``file`` field.
124
-
125
- A freshly seeded jsonl only contains a ``{"_example": ...}`` row (no
126
- ``file`` key) — that is NOT "ready". Readiness requires at least one
127
- curated entry. Matches the contract used by ``inject-subagent-context.py``.
128
- """
129
- try:
130
- for line in jsonl_path.read_text(encoding="utf-8").splitlines():
131
- line = line.strip()
132
- if not line:
133
- continue
134
- try:
135
- row = json.loads(line)
136
- except json.JSONDecodeError:
137
- continue
138
- if isinstance(row, dict) and row.get("file"):
139
- return True
140
- except (OSError, UnicodeDecodeError):
141
- return False
142
- return False
143
-
144
-
145
- def read_file(path: Path, fallback: str = "") -> str:
146
- try:
147
- return path.read_text(encoding="utf-8")
148
- except (FileNotFoundError, PermissionError):
149
- return fallback
150
-
151
-
152
- def _resolve_context_key(project_dir: Path, hook_input: dict) -> str | None:
153
- scripts_dir = project_dir / ".trellis" / "scripts"
154
- if str(scripts_dir) not in sys.path:
155
- sys.path.insert(0, str(scripts_dir))
156
- try:
157
- from common.active_task import resolve_context_key # type: ignore[import-not-found]
158
- except Exception:
159
- return None
160
- return resolve_context_key(hook_input, platform="codex")
161
-
162
-
163
- def _resolve_selected_task(trellis_dir: Path, hook_input: dict):
164
- scripts_dir = trellis_dir / "scripts"
165
- if str(scripts_dir) not in sys.path:
166
- sys.path.insert(0, str(scripts_dir))
167
- from common.active_task import resolve_selected_task # type: ignore[import-not-found]
168
-
169
- return resolve_selected_task(trellis_dir.parent, hook_input, platform="codex")
170
-
171
-
172
- def run_script(script_path: Path, context_key: str | None = None) -> str:
173
- try:
174
- env = os.environ.copy()
175
- env["PYTHONIOENCODING"] = "utf-8"
176
- if context_key:
177
- env["TRELLIS_CONTEXT_ID"] = context_key
178
- cmd = [sys.executable, "-W", "ignore", str(script_path)]
179
- result = subprocess.run(
180
- cmd,
181
- capture_output=True,
182
- text=True,
183
- encoding="utf-8",
184
- errors="replace",
185
- timeout=5,
186
- cwd=str(script_path.parent.parent.parent),
187
- env=env,
188
- )
189
- return result.stdout if result.returncode == 0 else "No context available"
190
- except (subprocess.TimeoutExpired, FileNotFoundError, PermissionError):
191
- return "No context available"
192
-
193
-
194
- def _normalize_task_ref(task_ref: str) -> str:
195
- normalized = task_ref.strip()
196
- if not normalized:
197
- return ""
198
-
199
- path_obj = Path(normalized)
200
- if path_obj.is_absolute():
201
- return str(path_obj)
202
-
203
- normalized = normalized.replace("\\", "/")
204
- while normalized.startswith("./"):
205
- normalized = normalized[2:]
206
-
207
- if normalized.startswith("tasks/"):
208
- return f".trellis/{normalized}"
209
-
210
- return normalized
211
-
212
-
213
- def _resolve_task_dir(trellis_dir: Path, task_ref: str) -> Path:
214
- normalized = _normalize_task_ref(task_ref)
215
- path_obj = Path(normalized)
216
- if path_obj.is_absolute():
217
- return path_obj
218
- if normalized.startswith(".trellis/"):
219
- return trellis_dir.parent / path_obj
220
- return trellis_dir / "tasks" / path_obj
221
-
222
-
223
- def _get_task_status(trellis_dir: Path, hook_input: dict) -> str:
224
- active = _resolve_selected_task(trellis_dir, hook_input)
225
- if not active.task_path:
226
- return (
227
- "Trellis framework: active\n"
228
- "Selected task: none\n"
229
- "Next: Use the Task Dashboard to choose select/create/inspect/continue-without-task. "
230
- "Do not auto-select an existing task."
231
- )
232
-
233
- task_ref = active.task_path
234
- task_dir = _resolve_task_dir(trellis_dir, task_ref)
235
- if active.stale or not task_dir.is_dir():
236
- return (
237
- f"Trellis framework: active\nSelected task: {task_ref}\n"
238
- "Status: STALE SELECTION\n"
239
- "Next: Task directory not found. Run: python3 ./.trellis/scripts/task.py exit"
240
- )
241
-
242
- task_json_path = task_dir / "task.json"
243
- task_data: dict = {}
244
- if task_json_path.is_file():
245
- try:
246
- task_data = json.loads(task_json_path.read_text(encoding="utf-8"))
247
- except (json.JSONDecodeError, PermissionError):
248
- pass
249
-
250
- task_title = task_data.get("title", task_ref)
251
- task_status = task_data.get("status", "unknown")
252
-
253
- if task_status == "completed":
254
- return (
255
- f"Status: COMPLETED\nTask: {task_title}\n"
256
- f"Next: Archive with `python3 ./.trellis/scripts/task.py archive {task_dir.name}` "
257
- "or start a new task."
258
- )
259
-
260
- has_prd = (task_dir / "prd.md").is_file()
261
- has_design = (task_dir / "design.md").is_file()
262
- has_implement = (task_dir / "implement.md").is_file()
263
- present = [
264
- name
265
- for name in ("prd.md", "design.md", "implement.md", "implement.jsonl", "check.jsonl")
266
- if (task_dir / name).is_file()
267
- ]
268
- present_line = ", ".join(present) if present else "none"
269
-
270
- if not has_prd:
271
- return (
272
- f"Status: PLANNING\nTask: {task_title}\nPresent: {present_line}\n"
273
- "Next: Load trellis-brainstorm and write prd.md. Stay in planning."
274
- )
275
-
276
- if task_status == "planning":
277
- if has_design and has_implement:
278
- next_action = "Run `task.py start-execution <task> --check`, report PASS, then ask for explicit execution approval."
279
- else:
280
- next_action = (
281
- "Lightweight task can ask for start review with PRD-only; "
282
- "complex task must add design.md and implement.md before `task.py start-execution --check`."
283
- )
284
- return (
285
- f"Status: PLANNING\nTask: {task_title}\nPresent: {present_line}\n"
286
- f"Next: {next_action}"
287
- )
288
-
289
- return (
290
- f"Status: {task_status.upper()}\nTask: {task_title}\nPresent: {present_line}\n"
291
- "Next: Follow the matching per-turn workflow-state. Context order is jsonl entries, "
292
- "prd.md, design.md if present, implement.md if present."
293
- )
294
-
295
-
296
- def _run_git(repo_root: Path, args: list[str]) -> str:
297
- try:
298
- result = subprocess.run(
299
- ["git", *args],
300
- capture_output=True,
301
- text=True,
302
- encoding="utf-8",
303
- errors="replace",
304
- timeout=3,
305
- cwd=str(repo_root),
306
- )
307
- except (subprocess.TimeoutExpired, FileNotFoundError, PermissionError):
308
- return ""
309
- if result.returncode != 0:
310
- return ""
311
- return result.stdout.strip()
312
-
313
-
314
- def _format_git_state(repo_root: Path) -> str:
315
- branch = _run_git(repo_root, ["branch", "--show-current"]) or "(detached)"
316
- dirty_lines = [
317
- line for line in _run_git(repo_root, ["status", "--porcelain"]).splitlines()
318
- if line.strip()
319
- ]
320
- dirty_text = "clean" if not dirty_lines else f"dirty {len(dirty_lines)} paths"
321
- return f"Git: branch {branch}; {dirty_text}."
322
-
323
-
324
- def _repo_relative(repo_root: Path, path: Path) -> str:
325
- try:
326
- return path.relative_to(repo_root).as_posix()
327
- except ValueError:
328
- return str(path)
329
-
330
-
331
- def _collect_spec_index_paths(trellis_dir: Path) -> list[str]:
332
- paths: list[str] = []
333
- guides_index = trellis_dir / "spec" / "guides" / "index.md"
334
- if guides_index.is_file():
335
- paths.append(".trellis/spec/guides/index.md")
336
-
337
- spec_dir = trellis_dir / "spec"
338
- if not spec_dir.is_dir():
339
- return paths
340
-
341
- for sub in sorted(spec_dir.iterdir()):
342
- if not sub.is_dir() or sub.name.startswith(".") or sub.name == "guides":
343
- continue
344
- index_file = sub / "index.md"
345
- if index_file.is_file():
346
- paths.append(f".trellis/spec/{sub.name}/index.md")
347
- continue
348
- for nested in sorted(sub.iterdir()):
349
- if not nested.is_dir():
350
- continue
351
- nested_index = nested / "index.md"
352
- if nested_index.is_file():
353
- paths.append(f".trellis/spec/{sub.name}/{nested.name}/index.md")
354
-
355
- return paths
356
-
357
-
358
- def _build_compact_current_state(
359
- trellis_dir: Path,
360
- hook_input: dict,
361
- spec_index_paths: list[str],
362
- ) -> str:
363
- repo_root = trellis_dir.parent
364
- lines: list[str] = []
365
-
366
- try:
367
- from common.paths import get_active_journal_file, get_developer, get_tasks_dir, count_lines # type: ignore[import-not-found]
368
- from common.tasks import iter_active_tasks # type: ignore[import-not-found]
369
- except Exception:
370
- get_active_journal_file = None # type: ignore[assignment]
371
- get_developer = None # type: ignore[assignment]
372
- get_tasks_dir = None # type: ignore[assignment]
373
- count_lines = None # type: ignore[assignment]
374
- iter_active_tasks = None # type: ignore[assignment]
375
-
376
- developer = get_developer(repo_root) if get_developer else None
377
- lines.append(f"Developer: {developer or '(not initialized)'}")
378
- lines.append(_format_git_state(repo_root))
379
-
380
- active = _resolve_selected_task(trellis_dir, hook_input)
381
- if active.task_path:
382
- task_dir = _resolve_task_dir(trellis_dir, active.task_path)
383
- status = "unknown"
384
- task_json = task_dir / "task.json"
385
- if task_json.is_file():
386
- try:
387
- data = json.loads(task_json.read_text(encoding="utf-8"))
388
- if isinstance(data, dict):
389
- status = str(data.get("status") or "unknown")
390
- except (json.JSONDecodeError, OSError):
391
- pass
392
- lines.append(f"Trellis framework: active")
393
- lines.append(f"Selected task: {_repo_relative(repo_root, task_dir)}; status={status}.")
394
- else:
395
- lines.append("Trellis framework: active")
396
- lines.append("Selected task: none.")
397
-
398
- if get_tasks_dir and iter_active_tasks:
399
- try:
400
- task_count = sum(1 for _ in iter_active_tasks(get_tasks_dir(repo_root)))
401
- lines.append(
402
- f"Active tasks: {task_count} total. Use the Task Dashboard for routing; use `python3 ./.trellis/scripts/task.py list --mine` only for raw inspection."
403
- )
404
- except Exception:
405
- pass
406
-
407
- if get_active_journal_file and count_lines:
408
- journal = get_active_journal_file(repo_root)
409
- if journal:
410
- lines.append(
411
- f"Journal: {_repo_relative(repo_root, journal)}, {count_lines(journal)} / 2000 lines."
412
- )
413
-
414
- if spec_index_paths:
415
- lines.append(f"Spec indexes: {len(spec_index_paths)} available.")
416
-
417
- return "\n".join(lines)
418
-
419
-
420
- def _build_task_dashboard(trellis_dir: Path, hook_input: dict) -> str:
421
- scripts_dir = trellis_dir / "scripts"
422
- if str(scripts_dir) not in sys.path:
423
- sys.path.insert(0, str(scripts_dir))
424
- try:
425
- from common.task_dashboard import render_task_dashboard # type: ignore[import-not-found]
426
-
427
- return render_task_dashboard(trellis_dir.parent, hook_input, "codex")
428
- except Exception:
429
- return "Task Dashboard unavailable. Run: python3 ./.trellis/scripts/task.py dashboard"
430
-
431
-
432
- def _extract_range(content: str, start_header: str, end_header: str) -> str:
433
- """Extract lines starting at `## start_header` up to (but excluding) `## end_header`."""
434
- lines = content.splitlines()
435
- start: "int | None" = None
436
- end: int = len(lines)
437
- start_match = f"## {start_header}"
438
- end_match = f"## {end_header}"
439
- for i, line in enumerate(lines):
440
- stripped = line.strip()
441
- if start is None and stripped == start_match:
442
- start = i
443
- continue
444
- if start is not None and stripped == end_match:
445
- end = i
446
- break
447
- if start is None:
448
- return ""
449
- return "\n".join(lines[start:end]).rstrip()
450
-
451
-
452
- _BREADCRUMB_TAG_RE = re.compile(
453
- r"\[workflow-state:([A-Za-z0-9_-]+)\]\s*\n.*?\n\s*\[/workflow-state:\1\]",
454
- re.DOTALL,
455
- )
456
-
457
-
458
- def _strip_breadcrumb_tag_blocks(content: str) -> str:
459
- stripped = _BREADCRUMB_TAG_RE.sub("", content)
460
- stripped = re.sub(r"<!--.*?-->", "", stripped, flags=re.DOTALL)
461
- # Strip orphan bracket-tag lines (residual when a [workflow-state:STATUS]
462
- # pair is split across an extraction boundary), but preserve legitimate
463
- # documentation examples like `[Triage: <Mode>] <reason>` in the Request
464
- # Triage section. The negative lookahead skips both workflow-state tags
465
- # (handled by the pair regex above) and Triage classification marks.
466
- stripped = re.sub(
467
- r"^\[(?!/?workflow-state:|Triage:)/?[^\]\n]+\]\s*\n?",
468
- "",
469
- stripped,
470
- flags=re.MULTILINE,
471
- )
472
- return re.sub(r"\n{3,}", "\n\n", stripped).strip()
473
-
474
-
475
- def _build_workflow_toc(workflow_path: Path) -> str:
476
- """Inject only the compact Phase Index summary for SessionStart."""
477
- content = read_file(workflow_path)
478
- if not content:
479
- return "No workflow.md found"
480
-
481
- out_lines = [
482
- "# Development Workflow - Session Summary",
483
- "Full guide: .trellis/workflow.md. Step detail: `python3 ./.trellis/scripts/get_context.py --mode phase --step <X.Y>`.",
484
- "",
485
- ]
486
-
487
- phases = _extract_range(content, "Phase Index", "Phase 1: Plan")
488
- if phases:
489
- out_lines.append(_strip_breadcrumb_tag_blocks(phases).rstrip())
490
-
491
- return "\n".join(out_lines).rstrip()
492
-
493
-
494
- def main() -> None:
495
- if should_skip_injection():
496
- sys.exit(0)
497
-
498
- # Read hook input from stdin
499
- try:
500
- hook_input = json.loads(sys.stdin.read())
501
- if not isinstance(hook_input, dict):
502
- hook_input = {}
503
- project_dir = Path(_normalize_windows_shell_path(hook_input.get("cwd", "."))).resolve()
504
- except (json.JSONDecodeError, KeyError):
505
- hook_input = {}
506
- project_dir = Path(".").resolve()
507
-
508
- configure_project_encoding(project_dir)
509
-
510
- trellis_dir = project_dir / ".trellis"
511
- spec_index_paths = _collect_spec_index_paths(trellis_dir)
512
-
513
- output = StringIO()
514
-
515
- output.write("""<session-context>
516
- Trellis compact SessionStart context. Use it to orient the session; load details on demand.
517
- </session-context>
518
-
519
- """)
520
- output.write(FIRST_REPLY_NOTICE)
521
- output.write("\n\n")
522
-
523
- output.write("<current-state>\n")
524
- output.write(_build_compact_current_state(trellis_dir, hook_input, spec_index_paths))
525
- output.write("\n</current-state>\n\n")
526
-
527
- output.write("<task-dashboard>\n")
528
- output.write(_build_task_dashboard(trellis_dir, hook_input))
529
- output.write("\n</task-dashboard>\n\n")
530
-
531
- output.write("<trellis-workflow>\n")
532
- output.write(_build_workflow_toc(trellis_dir / "workflow.md"))
533
- output.write("\n</trellis-workflow>\n\n")
534
-
535
- output.write("<guidelines>\n")
536
- output.write(
537
- "Task context order for implementation/check: jsonl entries -> `prd.md` -> "
538
- "`design.md if present` -> `implement.md if present`. Missing optional artifacts "
539
- "are skipped for lightweight tasks.\n\n"
540
- )
541
-
542
- if spec_index_paths:
543
- output.write("## Available indexes (read on demand)\n")
544
- for p in spec_index_paths:
545
- output.write(f"- {p}\n")
546
- output.write("\n")
547
-
548
- output.write(
549
- "Discover more via: "
550
- "`python3 ./.trellis/scripts/get_context.py --mode packages`\n"
551
- )
552
- output.write("</guidelines>\n\n")
553
-
554
- task_status = _get_task_status(trellis_dir, hook_input)
555
- output.write(f"<task-status>\n{task_status}\n</task-status>\n\n")
556
-
557
- output.write("""<ready>
558
- Context loaded. Follow <task-status>. Load workflow/spec/task details only when needed.
559
- </ready>""")
560
-
561
- context = output.getvalue()
562
- result = {
563
- "suppressOutput": True,
564
- "systemMessage": f"Trellis context injected ({len(context)} chars)",
565
- "hookSpecificOutput": {
566
- "hookEventName": "SessionStart",
567
- "additionalContext": context,
568
- },
569
- }
570
-
571
- print(json.dumps(result, ensure_ascii=False), flush=True)
572
-
573
-
574
- if __name__ == "__main__":
575
- main()
@@ -1,15 +0,0 @@
1
- {
2
- "hooks": {
3
- "UserPromptSubmit": [
4
- {
5
- "hooks": [
6
- {
7
- "type": "command",
8
- "command": "{{PYTHON_CMD}} -X utf8 .codex/hooks/inject-workflow-state.py",
9
- "timeout": 15
10
- }
11
- ]
12
- }
13
- ]
14
- }
15
- }
@@ -1,39 +0,0 @@
1
- /**
2
- * Codex templates
3
- *
4
- * These are GENERIC templates for user projects.
5
- * Do NOT use Trellis project's own .agents/skills or .codex directories
6
- * (which may be customized).
7
- *
8
- * Directory structure:
9
- * codex/
10
- * ├── agents/ # Project-scoped Codex custom agents (.toml)
11
- * ├── codex-skills/ # Codex-specific skills → .codex/skills/
12
- * ├── skills/ # Shared skills → .agents/skills/
13
- * └── config.toml # Project-scoped Codex config
14
- */
15
- export interface SkillTemplate {
16
- name: string;
17
- content: string;
18
- }
19
- export interface AgentTemplate {
20
- name: string;
21
- content: string;
22
- }
23
- export interface ConfigTemplate {
24
- targetPath: string;
25
- content: string;
26
- }
27
- export declare function getAllAgents(): AgentTemplate[];
28
- /**
29
- * Get Codex-specific skills (installed to .codex/skills/, not shared .agents/skills/).
30
- */
31
- export declare function getAllCodexSkills(): SkillTemplate[];
32
- export interface HookTemplate {
33
- name: string;
34
- content: string;
35
- }
36
- export declare function getAllHooks(): HookTemplate[];
37
- export declare function getHooksConfig(): string;
38
- export declare function getConfigTemplate(): ConfigTemplate;
39
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/templates/codex/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAgCH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAID,wBAAgB,YAAY,IAAI,aAAa,EAAE,CAc9C;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,aAAa,EAAE,CASnD;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,WAAW,IAAI,YAAY,EAAE,CAW5C;AAED,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,wBAAgB,iBAAiB,IAAI,cAAc,CAKlD"}