claude-code-pilot 2.0.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 (257) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +151 -0
  3. package/bin/install.js +431 -0
  4. package/docs/agent-guides/architecture.md +107 -0
  5. package/ecc/agents/architect.md +211 -0
  6. package/ecc/agents/code-reviewer.md +237 -0
  7. package/ecc/agents/doc-updater.md +107 -0
  8. package/ecc/agents/e2e-runner.md +107 -0
  9. package/ecc/agents/security-reviewer.md +108 -0
  10. package/ecc/agents/tdd-guide.md +91 -0
  11. package/ecc/commands/checkpoint.md +74 -0
  12. package/ecc/commands/evolve.md +178 -0
  13. package/ecc/commands/learn.md +70 -0
  14. package/ecc/commands/model-route.md +26 -0
  15. package/ecc/commands/quality-gate.md +29 -0
  16. package/ecc/commands/resume-session.md +155 -0
  17. package/ecc/commands/save-session.md +275 -0
  18. package/ecc/commands/sessions.md +305 -0
  19. package/ecc/commands/verify.md +59 -0
  20. package/ecc/contexts/dev.md +20 -0
  21. package/ecc/contexts/research.md +26 -0
  22. package/ecc/contexts/review.md +22 -0
  23. package/ecc/examples/CLAUDE.md +100 -0
  24. package/ecc/examples/django-api-CLAUDE.md +308 -0
  25. package/ecc/examples/go-microservice-CLAUDE.md +267 -0
  26. package/ecc/examples/rust-api-CLAUDE.md +285 -0
  27. package/ecc/examples/saas-nextjs-CLAUDE.md +166 -0
  28. package/ecc/examples/user-CLAUDE.md +109 -0
  29. package/ecc/rules/common/agents.md +49 -0
  30. package/ecc/rules/common/coding-style.md +48 -0
  31. package/ecc/rules/common/development-workflow.md +37 -0
  32. package/ecc/rules/common/git-workflow.md +24 -0
  33. package/ecc/rules/common/hooks.md +30 -0
  34. package/ecc/rules/common/patterns.md +31 -0
  35. package/ecc/rules/common/performance.md +55 -0
  36. package/ecc/rules/common/security.md +29 -0
  37. package/ecc/rules/common/testing.md +29 -0
  38. package/ecc/rules/golang/coding-style.md +32 -0
  39. package/ecc/rules/golang/hooks.md +17 -0
  40. package/ecc/rules/golang/patterns.md +45 -0
  41. package/ecc/rules/golang/security.md +34 -0
  42. package/ecc/rules/golang/testing.md +31 -0
  43. package/ecc/rules/kotlin/coding-style.md +86 -0
  44. package/ecc/rules/kotlin/patterns.md +146 -0
  45. package/ecc/rules/kotlin/security.md +82 -0
  46. package/ecc/rules/kotlin/testing.md +128 -0
  47. package/ecc/rules/perl/coding-style.md +46 -0
  48. package/ecc/rules/perl/hooks.md +22 -0
  49. package/ecc/rules/perl/patterns.md +76 -0
  50. package/ecc/rules/perl/security.md +69 -0
  51. package/ecc/rules/perl/testing.md +54 -0
  52. package/ecc/rules/php/coding-style.md +35 -0
  53. package/ecc/rules/php/hooks.md +24 -0
  54. package/ecc/rules/php/patterns.md +32 -0
  55. package/ecc/rules/php/security.md +33 -0
  56. package/ecc/rules/php/testing.md +34 -0
  57. package/ecc/rules/python/coding-style.md +42 -0
  58. package/ecc/rules/python/hooks.md +19 -0
  59. package/ecc/rules/python/patterns.md +39 -0
  60. package/ecc/rules/python/security.md +30 -0
  61. package/ecc/rules/python/testing.md +38 -0
  62. package/ecc/rules/swift/coding-style.md +47 -0
  63. package/ecc/rules/swift/hooks.md +20 -0
  64. package/ecc/rules/swift/patterns.md +66 -0
  65. package/ecc/rules/swift/security.md +33 -0
  66. package/ecc/rules/swift/testing.md +45 -0
  67. package/ecc/rules/typescript/coding-style.md +199 -0
  68. package/ecc/rules/typescript/hooks.md +22 -0
  69. package/ecc/rules/typescript/patterns.md +52 -0
  70. package/ecc/rules/typescript/security.md +28 -0
  71. package/ecc/rules/typescript/testing.md +18 -0
  72. package/ecc/scripts/hooks/check-hook-enabled.js +12 -0
  73. package/ecc/scripts/hooks/evaluate-session.js +100 -0
  74. package/ecc/scripts/hooks/pre-compact.js +48 -0
  75. package/ecc/scripts/hooks/run-with-flags-shell.sh +32 -0
  76. package/ecc/scripts/hooks/run-with-flags.js +120 -0
  77. package/ecc/scripts/hooks/session-end-marker.js +15 -0
  78. package/ecc/scripts/hooks/session-end.js +258 -0
  79. package/ecc/scripts/hooks/session-start.js +97 -0
  80. package/ecc/scripts/hooks/suggest-compact.js +80 -0
  81. package/ecc/scripts/lib/hook-flags.js +74 -0
  82. package/ecc/scripts/lib/package-manager.d.ts +119 -0
  83. package/ecc/scripts/lib/package-manager.js +431 -0
  84. package/ecc/scripts/lib/project-detect.js +428 -0
  85. package/ecc/scripts/lib/resolve-formatter.js +185 -0
  86. package/ecc/scripts/lib/session-aliases.d.ts +136 -0
  87. package/ecc/scripts/lib/session-aliases.js +481 -0
  88. package/ecc/scripts/lib/session-manager.d.ts +131 -0
  89. package/ecc/scripts/lib/session-manager.js +444 -0
  90. package/ecc/scripts/lib/shell-split.js +86 -0
  91. package/ecc/scripts/lib/utils.d.ts +183 -0
  92. package/ecc/scripts/lib/utils.js +543 -0
  93. package/ecc/skills/continuous-learning-v2/SKILL.md +365 -0
  94. package/ecc/skills/continuous-learning-v2/agents/observer-loop.sh +144 -0
  95. package/ecc/skills/continuous-learning-v2/agents/observer.md +198 -0
  96. package/ecc/skills/continuous-learning-v2/agents/start-observer.sh +194 -0
  97. package/ecc/skills/continuous-learning-v2/config.json +8 -0
  98. package/ecc/skills/continuous-learning-v2/hooks/observe.sh +246 -0
  99. package/ecc/skills/continuous-learning-v2/scripts/detect-project.sh +218 -0
  100. package/ecc/skills/continuous-learning-v2/scripts/instinct-cli.py +1148 -0
  101. package/ecc/skills/continuous-learning-v2/scripts/test_parse_instinct.py +984 -0
  102. package/ecc/skills/strategic-compact/SKILL.md +103 -0
  103. package/ecc/skills/strategic-compact/suggest-compact.sh +54 -0
  104. package/ecc/skills/verification-loop-SKILL.md +126 -0
  105. package/gsd/LICENSE +21 -0
  106. package/gsd/agents/gsd-codebase-mapper.md +772 -0
  107. package/gsd/agents/gsd-debugger.md +1257 -0
  108. package/gsd/agents/gsd-executor.md +489 -0
  109. package/gsd/agents/gsd-integration-checker.md +445 -0
  110. package/gsd/agents/gsd-nyquist-auditor.md +178 -0
  111. package/gsd/agents/gsd-phase-researcher.md +555 -0
  112. package/gsd/agents/gsd-plan-checker.md +708 -0
  113. package/gsd/agents/gsd-planner.md +1309 -0
  114. package/gsd/agents/gsd-project-researcher.md +631 -0
  115. package/gsd/agents/gsd-research-synthesizer.md +249 -0
  116. package/gsd/agents/gsd-roadmapper.md +652 -0
  117. package/gsd/agents/gsd-verifier.md +581 -0
  118. package/gsd/commands-gsd/add-phase.md +43 -0
  119. package/gsd/commands-gsd/add-tests.md +41 -0
  120. package/gsd/commands-gsd/add-todo.md +47 -0
  121. package/gsd/commands-gsd/audit-milestone.md +36 -0
  122. package/gsd/commands-gsd/check-todos.md +45 -0
  123. package/gsd/commands-gsd/cleanup.md +18 -0
  124. package/gsd/commands-gsd/complete-milestone.md +136 -0
  125. package/gsd/commands-gsd/debug.md +168 -0
  126. package/gsd/commands-gsd/discuss-phase.md +90 -0
  127. package/gsd/commands-gsd/execute-phase.md +41 -0
  128. package/gsd/commands-gsd/health.md +22 -0
  129. package/gsd/commands-gsd/help.md +22 -0
  130. package/gsd/commands-gsd/insert-phase.md +32 -0
  131. package/gsd/commands-gsd/join-discord.md +18 -0
  132. package/gsd/commands-gsd/list-phase-assumptions.md +46 -0
  133. package/gsd/commands-gsd/map-codebase.md +71 -0
  134. package/gsd/commands-gsd/new-milestone.md +44 -0
  135. package/gsd/commands-gsd/new-project.md +42 -0
  136. package/gsd/commands-gsd/pause-work.md +38 -0
  137. package/gsd/commands-gsd/plan-milestone-gaps.md +34 -0
  138. package/gsd/commands-gsd/plan-phase.md +45 -0
  139. package/gsd/commands-gsd/progress.md +24 -0
  140. package/gsd/commands-gsd/quick.md +45 -0
  141. package/gsd/commands-gsd/reapply-patches.md +123 -0
  142. package/gsd/commands-gsd/remove-phase.md +31 -0
  143. package/gsd/commands-gsd/research-phase.md +190 -0
  144. package/gsd/commands-gsd/resume-work.md +40 -0
  145. package/gsd/commands-gsd/set-profile.md +34 -0
  146. package/gsd/commands-gsd/settings.md +36 -0
  147. package/gsd/commands-gsd/update.md +37 -0
  148. package/gsd/commands-gsd/validate-phase.md +35 -0
  149. package/gsd/commands-gsd/verify-work.md +38 -0
  150. package/gsd/get-shit-done/bin/gsd-tools.cjs +592 -0
  151. package/gsd/get-shit-done/bin/lib/commands.cjs +548 -0
  152. package/gsd/get-shit-done/bin/lib/config.cjs +169 -0
  153. package/gsd/get-shit-done/bin/lib/core.cjs +492 -0
  154. package/gsd/get-shit-done/bin/lib/frontmatter.cjs +299 -0
  155. package/gsd/get-shit-done/bin/lib/init.cjs +710 -0
  156. package/gsd/get-shit-done/bin/lib/milestone.cjs +241 -0
  157. package/gsd/get-shit-done/bin/lib/phase.cjs +901 -0
  158. package/gsd/get-shit-done/bin/lib/roadmap.cjs +298 -0
  159. package/gsd/get-shit-done/bin/lib/state.cjs +721 -0
  160. package/gsd/get-shit-done/bin/lib/template.cjs +222 -0
  161. package/gsd/get-shit-done/bin/lib/verify.cjs +820 -0
  162. package/gsd/get-shit-done/references/checkpoints.md +776 -0
  163. package/gsd/get-shit-done/references/continuation-format.md +249 -0
  164. package/gsd/get-shit-done/references/decimal-phase-calculation.md +65 -0
  165. package/gsd/get-shit-done/references/git-integration.md +248 -0
  166. package/gsd/get-shit-done/references/git-planning-commit.md +38 -0
  167. package/gsd/get-shit-done/references/model-profile-resolution.md +34 -0
  168. package/gsd/get-shit-done/references/model-profiles.md +93 -0
  169. package/gsd/get-shit-done/references/phase-argument-parsing.md +61 -0
  170. package/gsd/get-shit-done/references/planning-config.md +200 -0
  171. package/gsd/get-shit-done/references/questioning.md +162 -0
  172. package/gsd/get-shit-done/references/tdd.md +263 -0
  173. package/gsd/get-shit-done/references/ui-brand.md +160 -0
  174. package/gsd/get-shit-done/references/verification-patterns.md +612 -0
  175. package/gsd/get-shit-done/templates/DEBUG.md +164 -0
  176. package/gsd/get-shit-done/templates/UAT.md +247 -0
  177. package/gsd/get-shit-done/templates/VALIDATION.md +76 -0
  178. package/gsd/get-shit-done/templates/codebase/architecture.md +255 -0
  179. package/gsd/get-shit-done/templates/codebase/concerns.md +310 -0
  180. package/gsd/get-shit-done/templates/codebase/conventions.md +307 -0
  181. package/gsd/get-shit-done/templates/codebase/integrations.md +280 -0
  182. package/gsd/get-shit-done/templates/codebase/stack.md +186 -0
  183. package/gsd/get-shit-done/templates/codebase/structure.md +285 -0
  184. package/gsd/get-shit-done/templates/codebase/testing.md +480 -0
  185. package/gsd/get-shit-done/templates/config.json +37 -0
  186. package/gsd/get-shit-done/templates/context.md +297 -0
  187. package/gsd/get-shit-done/templates/continue-here.md +78 -0
  188. package/gsd/get-shit-done/templates/debug-subagent-prompt.md +91 -0
  189. package/gsd/get-shit-done/templates/discovery.md +146 -0
  190. package/gsd/get-shit-done/templates/milestone-archive.md +123 -0
  191. package/gsd/get-shit-done/templates/milestone.md +115 -0
  192. package/gsd/get-shit-done/templates/phase-prompt.md +569 -0
  193. package/gsd/get-shit-done/templates/planner-subagent-prompt.md +117 -0
  194. package/gsd/get-shit-done/templates/project.md +184 -0
  195. package/gsd/get-shit-done/templates/requirements.md +231 -0
  196. package/gsd/get-shit-done/templates/research-project/ARCHITECTURE.md +204 -0
  197. package/gsd/get-shit-done/templates/research-project/FEATURES.md +147 -0
  198. package/gsd/get-shit-done/templates/research-project/PITFALLS.md +200 -0
  199. package/gsd/get-shit-done/templates/research-project/STACK.md +120 -0
  200. package/gsd/get-shit-done/templates/research-project/SUMMARY.md +170 -0
  201. package/gsd/get-shit-done/templates/research.md +552 -0
  202. package/gsd/get-shit-done/templates/retrospective.md +54 -0
  203. package/gsd/get-shit-done/templates/roadmap.md +202 -0
  204. package/gsd/get-shit-done/templates/state.md +176 -0
  205. package/gsd/get-shit-done/templates/summary-complex.md +59 -0
  206. package/gsd/get-shit-done/templates/summary-minimal.md +41 -0
  207. package/gsd/get-shit-done/templates/summary-standard.md +48 -0
  208. package/gsd/get-shit-done/templates/summary.md +248 -0
  209. package/gsd/get-shit-done/templates/user-setup.md +311 -0
  210. package/gsd/get-shit-done/templates/verification-report.md +322 -0
  211. package/gsd/get-shit-done/workflows/add-phase.md +112 -0
  212. package/gsd/get-shit-done/workflows/add-tests.md +351 -0
  213. package/gsd/get-shit-done/workflows/add-todo.md +158 -0
  214. package/gsd/get-shit-done/workflows/audit-milestone.md +332 -0
  215. package/gsd/get-shit-done/workflows/check-todos.md +177 -0
  216. package/gsd/get-shit-done/workflows/cleanup.md +152 -0
  217. package/gsd/get-shit-done/workflows/complete-milestone.md +764 -0
  218. package/gsd/get-shit-done/workflows/diagnose-issues.md +219 -0
  219. package/gsd/get-shit-done/workflows/discovery-phase.md +289 -0
  220. package/gsd/get-shit-done/workflows/discuss-phase.md +676 -0
  221. package/gsd/get-shit-done/workflows/execute-phase.md +459 -0
  222. package/gsd/get-shit-done/workflows/execute-plan.md +449 -0
  223. package/gsd/get-shit-done/workflows/health.md +159 -0
  224. package/gsd/get-shit-done/workflows/help.md +489 -0
  225. package/gsd/get-shit-done/workflows/insert-phase.md +130 -0
  226. package/gsd/get-shit-done/workflows/list-phase-assumptions.md +178 -0
  227. package/gsd/get-shit-done/workflows/map-codebase.md +316 -0
  228. package/gsd/get-shit-done/workflows/new-milestone.md +384 -0
  229. package/gsd/get-shit-done/workflows/new-project.md +1111 -0
  230. package/gsd/get-shit-done/workflows/pause-work.md +122 -0
  231. package/gsd/get-shit-done/workflows/plan-milestone-gaps.md +274 -0
  232. package/gsd/get-shit-done/workflows/plan-phase.md +560 -0
  233. package/gsd/get-shit-done/workflows/progress.md +382 -0
  234. package/gsd/get-shit-done/workflows/quick.md +601 -0
  235. package/gsd/get-shit-done/workflows/remove-phase.md +155 -0
  236. package/gsd/get-shit-done/workflows/research-phase.md +74 -0
  237. package/gsd/get-shit-done/workflows/resume-project.md +307 -0
  238. package/gsd/get-shit-done/workflows/set-profile.md +81 -0
  239. package/gsd/get-shit-done/workflows/settings.md +214 -0
  240. package/gsd/get-shit-done/workflows/transition.md +544 -0
  241. package/gsd/get-shit-done/workflows/update.md +240 -0
  242. package/gsd/get-shit-done/workflows/validate-phase.md +167 -0
  243. package/gsd/get-shit-done/workflows/verify-phase.md +243 -0
  244. package/gsd/get-shit-done/workflows/verify-work.md +583 -0
  245. package/gsd/hooks/gsd-check-update.js +81 -0
  246. package/gsd/hooks/gsd-context-monitor.js +141 -0
  247. package/gsd/hooks/gsd-statusline.js +115 -0
  248. package/kit/CLAUDE.md +43 -0
  249. package/kit/commands/kit/update.md +46 -0
  250. package/kit/commands/setup-refresh.md +50 -0
  251. package/kit/commands/setup.md +579 -0
  252. package/kit/commands/tool-guide.md +44 -0
  253. package/kit/hooks/kit-check-update.js +54 -0
  254. package/kit/mcp.json +10 -0
  255. package/kit/rules/code-style.md +24 -0
  256. package/manifest.json +30 -0
  257. package/package.json +36 -0
@@ -0,0 +1,218 @@
1
+ #!/bin/bash
2
+ # Continuous Learning v2 - Project Detection Helper
3
+ #
4
+ # Shared logic for detecting current project context.
5
+ # Sourced by observe.sh and start-observer.sh.
6
+ #
7
+ # Exports:
8
+ # _CLV2_PROJECT_ID - Short hash identifying the project (or "global")
9
+ # _CLV2_PROJECT_NAME - Human-readable project name
10
+ # _CLV2_PROJECT_ROOT - Absolute path to project root
11
+ # _CLV2_PROJECT_DIR - Project-scoped storage directory under homunculus
12
+ #
13
+ # Also sets unprefixed convenience aliases:
14
+ # PROJECT_ID, PROJECT_NAME, PROJECT_ROOT, PROJECT_DIR
15
+ #
16
+ # Detection priority:
17
+ # 1. CLAUDE_PROJECT_DIR env var (if set)
18
+ # 2. git remote URL (hashed for uniqueness across machines)
19
+ # 3. git repo root path (fallback, machine-specific)
20
+ # 4. "global" (no project context detected)
21
+
22
+ _CLV2_HOMUNCULUS_DIR="${HOME}/.claude/homunculus"
23
+ _CLV2_PROJECTS_DIR="${_CLV2_HOMUNCULUS_DIR}/projects"
24
+ _CLV2_REGISTRY_FILE="${_CLV2_HOMUNCULUS_DIR}/projects.json"
25
+
26
+ _clv2_resolve_python_cmd() {
27
+ if [ -n "${CLV2_PYTHON_CMD:-}" ] && command -v "$CLV2_PYTHON_CMD" >/dev/null 2>&1; then
28
+ printf '%s\n' "$CLV2_PYTHON_CMD"
29
+ return 0
30
+ fi
31
+
32
+ if command -v python3 >/dev/null 2>&1; then
33
+ printf '%s\n' python3
34
+ return 0
35
+ fi
36
+
37
+ if command -v python >/dev/null 2>&1; then
38
+ printf '%s\n' python
39
+ return 0
40
+ fi
41
+
42
+ return 1
43
+ }
44
+
45
+ _CLV2_PYTHON_CMD="$(_clv2_resolve_python_cmd 2>/dev/null || true)"
46
+ CLV2_PYTHON_CMD="$_CLV2_PYTHON_CMD"
47
+ export CLV2_PYTHON_CMD
48
+
49
+ _clv2_detect_project() {
50
+ local project_root=""
51
+ local project_name=""
52
+ local project_id=""
53
+ local source_hint=""
54
+
55
+ # 1. Try CLAUDE_PROJECT_DIR env var
56
+ if [ -n "$CLAUDE_PROJECT_DIR" ] && [ -d "$CLAUDE_PROJECT_DIR" ]; then
57
+ project_root="$CLAUDE_PROJECT_DIR"
58
+ source_hint="env"
59
+ fi
60
+
61
+ # 2. Try git repo root from CWD (only if git is available)
62
+ if [ -z "$project_root" ] && command -v git &>/dev/null; then
63
+ project_root=$(git rev-parse --show-toplevel 2>/dev/null || true)
64
+ if [ -n "$project_root" ]; then
65
+ source_hint="git"
66
+ fi
67
+ fi
68
+
69
+ # 3. No project detected — fall back to global
70
+ if [ -z "$project_root" ]; then
71
+ _CLV2_PROJECT_ID="global"
72
+ _CLV2_PROJECT_NAME="global"
73
+ _CLV2_PROJECT_ROOT=""
74
+ _CLV2_PROJECT_DIR="${_CLV2_HOMUNCULUS_DIR}"
75
+ return 0
76
+ fi
77
+
78
+ # Derive project name from directory basename
79
+ project_name=$(basename "$project_root")
80
+
81
+ # Derive project ID: prefer git remote URL hash (portable across machines),
82
+ # fall back to path hash (machine-specific but still useful)
83
+ local remote_url=""
84
+ if command -v git &>/dev/null; then
85
+ if [ "$source_hint" = "git" ] || [ -d "${project_root}/.git" ]; then
86
+ remote_url=$(git -C "$project_root" remote get-url origin 2>/dev/null || true)
87
+ fi
88
+ fi
89
+
90
+ # Compute hash from the original remote URL (legacy, for backward compatibility)
91
+ local legacy_hash_input="${remote_url:-$project_root}"
92
+
93
+ # Strip embedded credentials from remote URL (e.g., https://ghp_xxxx@github.com/...)
94
+ if [ -n "$remote_url" ]; then
95
+ remote_url=$(printf '%s' "$remote_url" | sed -E 's|://[^@]+@|://|')
96
+ fi
97
+
98
+ local hash_input="${remote_url:-$project_root}"
99
+ # Prefer Python for consistent SHA256 behavior across shells/platforms.
100
+ if [ -n "$_CLV2_PYTHON_CMD" ]; then
101
+ project_id=$(printf '%s' "$hash_input" | "$_CLV2_PYTHON_CMD" -c "import sys,hashlib; print(hashlib.sha256(sys.stdin.buffer.read()).hexdigest()[:12])" 2>/dev/null)
102
+ fi
103
+
104
+ # Fallback if Python is unavailable or hash generation failed.
105
+ if [ -z "$project_id" ]; then
106
+ project_id=$(printf '%s' "$hash_input" | shasum -a 256 2>/dev/null | cut -c1-12 || \
107
+ printf '%s' "$hash_input" | sha256sum 2>/dev/null | cut -c1-12 || \
108
+ echo "fallback")
109
+ fi
110
+
111
+ # Backward compatibility: if credentials were stripped and the hash changed,
112
+ # check if a project dir exists under the legacy hash and reuse it
113
+ if [ "$legacy_hash_input" != "$hash_input" ] && [ -n "$_CLV2_PYTHON_CMD" ]; then
114
+ local legacy_id=""
115
+ legacy_id=$(printf '%s' "$legacy_hash_input" | "$_CLV2_PYTHON_CMD" -c "import sys,hashlib; print(hashlib.sha256(sys.stdin.buffer.read()).hexdigest()[:12])" 2>/dev/null)
116
+ if [ -n "$legacy_id" ] && [ -d "${_CLV2_PROJECTS_DIR}/${legacy_id}" ] && [ ! -d "${_CLV2_PROJECTS_DIR}/${project_id}" ]; then
117
+ # Migrate legacy directory to new hash
118
+ mv "${_CLV2_PROJECTS_DIR}/${legacy_id}" "${_CLV2_PROJECTS_DIR}/${project_id}" 2>/dev/null || project_id="$legacy_id"
119
+ fi
120
+ fi
121
+
122
+ # Export results
123
+ _CLV2_PROJECT_ID="$project_id"
124
+ _CLV2_PROJECT_NAME="$project_name"
125
+ _CLV2_PROJECT_ROOT="$project_root"
126
+ _CLV2_PROJECT_DIR="${_CLV2_PROJECTS_DIR}/${project_id}"
127
+
128
+ # Ensure project directory structure exists
129
+ mkdir -p "${_CLV2_PROJECT_DIR}/instincts/personal"
130
+ mkdir -p "${_CLV2_PROJECT_DIR}/instincts/inherited"
131
+ mkdir -p "${_CLV2_PROJECT_DIR}/observations.archive"
132
+ mkdir -p "${_CLV2_PROJECT_DIR}/evolved/skills"
133
+ mkdir -p "${_CLV2_PROJECT_DIR}/evolved/commands"
134
+ mkdir -p "${_CLV2_PROJECT_DIR}/evolved/agents"
135
+
136
+ # Update project registry (lightweight JSON mapping)
137
+ _clv2_update_project_registry "$project_id" "$project_name" "$project_root" "$remote_url"
138
+ }
139
+
140
+ _clv2_update_project_registry() {
141
+ local pid="$1"
142
+ local pname="$2"
143
+ local proot="$3"
144
+ local premote="$4"
145
+ local pdir="$_CLV2_PROJECT_DIR"
146
+
147
+ mkdir -p "$(dirname "$_CLV2_REGISTRY_FILE")"
148
+
149
+ if [ -z "$_CLV2_PYTHON_CMD" ]; then
150
+ return 0
151
+ fi
152
+
153
+ # Pass values via env vars to avoid shell→python injection.
154
+ # Python reads them with os.environ, which is safe for any string content.
155
+ _CLV2_REG_PID="$pid" \
156
+ _CLV2_REG_PNAME="$pname" \
157
+ _CLV2_REG_PROOT="$proot" \
158
+ _CLV2_REG_PREMOTE="$premote" \
159
+ _CLV2_REG_PDIR="$pdir" \
160
+ _CLV2_REG_FILE="$_CLV2_REGISTRY_FILE" \
161
+ "$_CLV2_PYTHON_CMD" -c '
162
+ import json, os, tempfile
163
+ from datetime import datetime, timezone
164
+
165
+ registry_path = os.environ["_CLV2_REG_FILE"]
166
+ project_dir = os.environ["_CLV2_REG_PDIR"]
167
+ project_file = os.path.join(project_dir, "project.json")
168
+
169
+ os.makedirs(project_dir, exist_ok=True)
170
+
171
+ def atomic_write_json(path, payload):
172
+ fd, tmp_path = tempfile.mkstemp(
173
+ prefix=f".{os.path.basename(path)}.tmp.",
174
+ dir=os.path.dirname(path),
175
+ text=True,
176
+ )
177
+ try:
178
+ with os.fdopen(fd, "w") as f:
179
+ json.dump(payload, f, indent=2)
180
+ f.write("\n")
181
+ os.replace(tmp_path, path)
182
+ finally:
183
+ if os.path.exists(tmp_path):
184
+ os.unlink(tmp_path)
185
+
186
+ try:
187
+ with open(registry_path) as f:
188
+ registry = json.load(f)
189
+ except (FileNotFoundError, json.JSONDecodeError):
190
+ registry = {}
191
+
192
+ now = datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
193
+ entry = registry.get(os.environ["_CLV2_REG_PID"], {})
194
+
195
+ metadata = {
196
+ "id": os.environ["_CLV2_REG_PID"],
197
+ "name": os.environ["_CLV2_REG_PNAME"],
198
+ "root": os.environ["_CLV2_REG_PROOT"],
199
+ "remote": os.environ["_CLV2_REG_PREMOTE"],
200
+ "created_at": entry.get("created_at", now),
201
+ "last_seen": now,
202
+ }
203
+
204
+ registry[os.environ["_CLV2_REG_PID"]] = metadata
205
+
206
+ atomic_write_json(project_file, metadata)
207
+ atomic_write_json(registry_path, registry)
208
+ ' 2>/dev/null || true
209
+ }
210
+
211
+ # Auto-detect on source
212
+ _clv2_detect_project
213
+
214
+ # Convenience aliases for callers (short names pointing to prefixed vars)
215
+ PROJECT_ID="$_CLV2_PROJECT_ID"
216
+ PROJECT_NAME="$_CLV2_PROJECT_NAME"
217
+ PROJECT_ROOT="$_CLV2_PROJECT_ROOT"
218
+ PROJECT_DIR="$_CLV2_PROJECT_DIR"