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.
- package/LICENSE +21 -0
- package/README.md +151 -0
- package/bin/install.js +431 -0
- package/docs/agent-guides/architecture.md +107 -0
- package/ecc/agents/architect.md +211 -0
- package/ecc/agents/code-reviewer.md +237 -0
- package/ecc/agents/doc-updater.md +107 -0
- package/ecc/agents/e2e-runner.md +107 -0
- package/ecc/agents/security-reviewer.md +108 -0
- package/ecc/agents/tdd-guide.md +91 -0
- package/ecc/commands/checkpoint.md +74 -0
- package/ecc/commands/evolve.md +178 -0
- package/ecc/commands/learn.md +70 -0
- package/ecc/commands/model-route.md +26 -0
- package/ecc/commands/quality-gate.md +29 -0
- package/ecc/commands/resume-session.md +155 -0
- package/ecc/commands/save-session.md +275 -0
- package/ecc/commands/sessions.md +305 -0
- package/ecc/commands/verify.md +59 -0
- package/ecc/contexts/dev.md +20 -0
- package/ecc/contexts/research.md +26 -0
- package/ecc/contexts/review.md +22 -0
- package/ecc/examples/CLAUDE.md +100 -0
- package/ecc/examples/django-api-CLAUDE.md +308 -0
- package/ecc/examples/go-microservice-CLAUDE.md +267 -0
- package/ecc/examples/rust-api-CLAUDE.md +285 -0
- package/ecc/examples/saas-nextjs-CLAUDE.md +166 -0
- package/ecc/examples/user-CLAUDE.md +109 -0
- package/ecc/rules/common/agents.md +49 -0
- package/ecc/rules/common/coding-style.md +48 -0
- package/ecc/rules/common/development-workflow.md +37 -0
- package/ecc/rules/common/git-workflow.md +24 -0
- package/ecc/rules/common/hooks.md +30 -0
- package/ecc/rules/common/patterns.md +31 -0
- package/ecc/rules/common/performance.md +55 -0
- package/ecc/rules/common/security.md +29 -0
- package/ecc/rules/common/testing.md +29 -0
- package/ecc/rules/golang/coding-style.md +32 -0
- package/ecc/rules/golang/hooks.md +17 -0
- package/ecc/rules/golang/patterns.md +45 -0
- package/ecc/rules/golang/security.md +34 -0
- package/ecc/rules/golang/testing.md +31 -0
- package/ecc/rules/kotlin/coding-style.md +86 -0
- package/ecc/rules/kotlin/patterns.md +146 -0
- package/ecc/rules/kotlin/security.md +82 -0
- package/ecc/rules/kotlin/testing.md +128 -0
- package/ecc/rules/perl/coding-style.md +46 -0
- package/ecc/rules/perl/hooks.md +22 -0
- package/ecc/rules/perl/patterns.md +76 -0
- package/ecc/rules/perl/security.md +69 -0
- package/ecc/rules/perl/testing.md +54 -0
- package/ecc/rules/php/coding-style.md +35 -0
- package/ecc/rules/php/hooks.md +24 -0
- package/ecc/rules/php/patterns.md +32 -0
- package/ecc/rules/php/security.md +33 -0
- package/ecc/rules/php/testing.md +34 -0
- package/ecc/rules/python/coding-style.md +42 -0
- package/ecc/rules/python/hooks.md +19 -0
- package/ecc/rules/python/patterns.md +39 -0
- package/ecc/rules/python/security.md +30 -0
- package/ecc/rules/python/testing.md +38 -0
- package/ecc/rules/swift/coding-style.md +47 -0
- package/ecc/rules/swift/hooks.md +20 -0
- package/ecc/rules/swift/patterns.md +66 -0
- package/ecc/rules/swift/security.md +33 -0
- package/ecc/rules/swift/testing.md +45 -0
- package/ecc/rules/typescript/coding-style.md +199 -0
- package/ecc/rules/typescript/hooks.md +22 -0
- package/ecc/rules/typescript/patterns.md +52 -0
- package/ecc/rules/typescript/security.md +28 -0
- package/ecc/rules/typescript/testing.md +18 -0
- package/ecc/scripts/hooks/check-hook-enabled.js +12 -0
- package/ecc/scripts/hooks/evaluate-session.js +100 -0
- package/ecc/scripts/hooks/pre-compact.js +48 -0
- package/ecc/scripts/hooks/run-with-flags-shell.sh +32 -0
- package/ecc/scripts/hooks/run-with-flags.js +120 -0
- package/ecc/scripts/hooks/session-end-marker.js +15 -0
- package/ecc/scripts/hooks/session-end.js +258 -0
- package/ecc/scripts/hooks/session-start.js +97 -0
- package/ecc/scripts/hooks/suggest-compact.js +80 -0
- package/ecc/scripts/lib/hook-flags.js +74 -0
- package/ecc/scripts/lib/package-manager.d.ts +119 -0
- package/ecc/scripts/lib/package-manager.js +431 -0
- package/ecc/scripts/lib/project-detect.js +428 -0
- package/ecc/scripts/lib/resolve-formatter.js +185 -0
- package/ecc/scripts/lib/session-aliases.d.ts +136 -0
- package/ecc/scripts/lib/session-aliases.js +481 -0
- package/ecc/scripts/lib/session-manager.d.ts +131 -0
- package/ecc/scripts/lib/session-manager.js +444 -0
- package/ecc/scripts/lib/shell-split.js +86 -0
- package/ecc/scripts/lib/utils.d.ts +183 -0
- package/ecc/scripts/lib/utils.js +543 -0
- package/ecc/skills/continuous-learning-v2/SKILL.md +365 -0
- package/ecc/skills/continuous-learning-v2/agents/observer-loop.sh +144 -0
- package/ecc/skills/continuous-learning-v2/agents/observer.md +198 -0
- package/ecc/skills/continuous-learning-v2/agents/start-observer.sh +194 -0
- package/ecc/skills/continuous-learning-v2/config.json +8 -0
- package/ecc/skills/continuous-learning-v2/hooks/observe.sh +246 -0
- package/ecc/skills/continuous-learning-v2/scripts/detect-project.sh +218 -0
- package/ecc/skills/continuous-learning-v2/scripts/instinct-cli.py +1148 -0
- package/ecc/skills/continuous-learning-v2/scripts/test_parse_instinct.py +984 -0
- package/ecc/skills/strategic-compact/SKILL.md +103 -0
- package/ecc/skills/strategic-compact/suggest-compact.sh +54 -0
- package/ecc/skills/verification-loop-SKILL.md +126 -0
- package/gsd/LICENSE +21 -0
- package/gsd/agents/gsd-codebase-mapper.md +772 -0
- package/gsd/agents/gsd-debugger.md +1257 -0
- package/gsd/agents/gsd-executor.md +489 -0
- package/gsd/agents/gsd-integration-checker.md +445 -0
- package/gsd/agents/gsd-nyquist-auditor.md +178 -0
- package/gsd/agents/gsd-phase-researcher.md +555 -0
- package/gsd/agents/gsd-plan-checker.md +708 -0
- package/gsd/agents/gsd-planner.md +1309 -0
- package/gsd/agents/gsd-project-researcher.md +631 -0
- package/gsd/agents/gsd-research-synthesizer.md +249 -0
- package/gsd/agents/gsd-roadmapper.md +652 -0
- package/gsd/agents/gsd-verifier.md +581 -0
- package/gsd/commands-gsd/add-phase.md +43 -0
- package/gsd/commands-gsd/add-tests.md +41 -0
- package/gsd/commands-gsd/add-todo.md +47 -0
- package/gsd/commands-gsd/audit-milestone.md +36 -0
- package/gsd/commands-gsd/check-todos.md +45 -0
- package/gsd/commands-gsd/cleanup.md +18 -0
- package/gsd/commands-gsd/complete-milestone.md +136 -0
- package/gsd/commands-gsd/debug.md +168 -0
- package/gsd/commands-gsd/discuss-phase.md +90 -0
- package/gsd/commands-gsd/execute-phase.md +41 -0
- package/gsd/commands-gsd/health.md +22 -0
- package/gsd/commands-gsd/help.md +22 -0
- package/gsd/commands-gsd/insert-phase.md +32 -0
- package/gsd/commands-gsd/join-discord.md +18 -0
- package/gsd/commands-gsd/list-phase-assumptions.md +46 -0
- package/gsd/commands-gsd/map-codebase.md +71 -0
- package/gsd/commands-gsd/new-milestone.md +44 -0
- package/gsd/commands-gsd/new-project.md +42 -0
- package/gsd/commands-gsd/pause-work.md +38 -0
- package/gsd/commands-gsd/plan-milestone-gaps.md +34 -0
- package/gsd/commands-gsd/plan-phase.md +45 -0
- package/gsd/commands-gsd/progress.md +24 -0
- package/gsd/commands-gsd/quick.md +45 -0
- package/gsd/commands-gsd/reapply-patches.md +123 -0
- package/gsd/commands-gsd/remove-phase.md +31 -0
- package/gsd/commands-gsd/research-phase.md +190 -0
- package/gsd/commands-gsd/resume-work.md +40 -0
- package/gsd/commands-gsd/set-profile.md +34 -0
- package/gsd/commands-gsd/settings.md +36 -0
- package/gsd/commands-gsd/update.md +37 -0
- package/gsd/commands-gsd/validate-phase.md +35 -0
- package/gsd/commands-gsd/verify-work.md +38 -0
- package/gsd/get-shit-done/bin/gsd-tools.cjs +592 -0
- package/gsd/get-shit-done/bin/lib/commands.cjs +548 -0
- package/gsd/get-shit-done/bin/lib/config.cjs +169 -0
- package/gsd/get-shit-done/bin/lib/core.cjs +492 -0
- package/gsd/get-shit-done/bin/lib/frontmatter.cjs +299 -0
- package/gsd/get-shit-done/bin/lib/init.cjs +710 -0
- package/gsd/get-shit-done/bin/lib/milestone.cjs +241 -0
- package/gsd/get-shit-done/bin/lib/phase.cjs +901 -0
- package/gsd/get-shit-done/bin/lib/roadmap.cjs +298 -0
- package/gsd/get-shit-done/bin/lib/state.cjs +721 -0
- package/gsd/get-shit-done/bin/lib/template.cjs +222 -0
- package/gsd/get-shit-done/bin/lib/verify.cjs +820 -0
- package/gsd/get-shit-done/references/checkpoints.md +776 -0
- package/gsd/get-shit-done/references/continuation-format.md +249 -0
- package/gsd/get-shit-done/references/decimal-phase-calculation.md +65 -0
- package/gsd/get-shit-done/references/git-integration.md +248 -0
- package/gsd/get-shit-done/references/git-planning-commit.md +38 -0
- package/gsd/get-shit-done/references/model-profile-resolution.md +34 -0
- package/gsd/get-shit-done/references/model-profiles.md +93 -0
- package/gsd/get-shit-done/references/phase-argument-parsing.md +61 -0
- package/gsd/get-shit-done/references/planning-config.md +200 -0
- package/gsd/get-shit-done/references/questioning.md +162 -0
- package/gsd/get-shit-done/references/tdd.md +263 -0
- package/gsd/get-shit-done/references/ui-brand.md +160 -0
- package/gsd/get-shit-done/references/verification-patterns.md +612 -0
- package/gsd/get-shit-done/templates/DEBUG.md +164 -0
- package/gsd/get-shit-done/templates/UAT.md +247 -0
- package/gsd/get-shit-done/templates/VALIDATION.md +76 -0
- package/gsd/get-shit-done/templates/codebase/architecture.md +255 -0
- package/gsd/get-shit-done/templates/codebase/concerns.md +310 -0
- package/gsd/get-shit-done/templates/codebase/conventions.md +307 -0
- package/gsd/get-shit-done/templates/codebase/integrations.md +280 -0
- package/gsd/get-shit-done/templates/codebase/stack.md +186 -0
- package/gsd/get-shit-done/templates/codebase/structure.md +285 -0
- package/gsd/get-shit-done/templates/codebase/testing.md +480 -0
- package/gsd/get-shit-done/templates/config.json +37 -0
- package/gsd/get-shit-done/templates/context.md +297 -0
- package/gsd/get-shit-done/templates/continue-here.md +78 -0
- package/gsd/get-shit-done/templates/debug-subagent-prompt.md +91 -0
- package/gsd/get-shit-done/templates/discovery.md +146 -0
- package/gsd/get-shit-done/templates/milestone-archive.md +123 -0
- package/gsd/get-shit-done/templates/milestone.md +115 -0
- package/gsd/get-shit-done/templates/phase-prompt.md +569 -0
- package/gsd/get-shit-done/templates/planner-subagent-prompt.md +117 -0
- package/gsd/get-shit-done/templates/project.md +184 -0
- package/gsd/get-shit-done/templates/requirements.md +231 -0
- package/gsd/get-shit-done/templates/research-project/ARCHITECTURE.md +204 -0
- package/gsd/get-shit-done/templates/research-project/FEATURES.md +147 -0
- package/gsd/get-shit-done/templates/research-project/PITFALLS.md +200 -0
- package/gsd/get-shit-done/templates/research-project/STACK.md +120 -0
- package/gsd/get-shit-done/templates/research-project/SUMMARY.md +170 -0
- package/gsd/get-shit-done/templates/research.md +552 -0
- package/gsd/get-shit-done/templates/retrospective.md +54 -0
- package/gsd/get-shit-done/templates/roadmap.md +202 -0
- package/gsd/get-shit-done/templates/state.md +176 -0
- package/gsd/get-shit-done/templates/summary-complex.md +59 -0
- package/gsd/get-shit-done/templates/summary-minimal.md +41 -0
- package/gsd/get-shit-done/templates/summary-standard.md +48 -0
- package/gsd/get-shit-done/templates/summary.md +248 -0
- package/gsd/get-shit-done/templates/user-setup.md +311 -0
- package/gsd/get-shit-done/templates/verification-report.md +322 -0
- package/gsd/get-shit-done/workflows/add-phase.md +112 -0
- package/gsd/get-shit-done/workflows/add-tests.md +351 -0
- package/gsd/get-shit-done/workflows/add-todo.md +158 -0
- package/gsd/get-shit-done/workflows/audit-milestone.md +332 -0
- package/gsd/get-shit-done/workflows/check-todos.md +177 -0
- package/gsd/get-shit-done/workflows/cleanup.md +152 -0
- package/gsd/get-shit-done/workflows/complete-milestone.md +764 -0
- package/gsd/get-shit-done/workflows/diagnose-issues.md +219 -0
- package/gsd/get-shit-done/workflows/discovery-phase.md +289 -0
- package/gsd/get-shit-done/workflows/discuss-phase.md +676 -0
- package/gsd/get-shit-done/workflows/execute-phase.md +459 -0
- package/gsd/get-shit-done/workflows/execute-plan.md +449 -0
- package/gsd/get-shit-done/workflows/health.md +159 -0
- package/gsd/get-shit-done/workflows/help.md +489 -0
- package/gsd/get-shit-done/workflows/insert-phase.md +130 -0
- package/gsd/get-shit-done/workflows/list-phase-assumptions.md +178 -0
- package/gsd/get-shit-done/workflows/map-codebase.md +316 -0
- package/gsd/get-shit-done/workflows/new-milestone.md +384 -0
- package/gsd/get-shit-done/workflows/new-project.md +1111 -0
- package/gsd/get-shit-done/workflows/pause-work.md +122 -0
- package/gsd/get-shit-done/workflows/plan-milestone-gaps.md +274 -0
- package/gsd/get-shit-done/workflows/plan-phase.md +560 -0
- package/gsd/get-shit-done/workflows/progress.md +382 -0
- package/gsd/get-shit-done/workflows/quick.md +601 -0
- package/gsd/get-shit-done/workflows/remove-phase.md +155 -0
- package/gsd/get-shit-done/workflows/research-phase.md +74 -0
- package/gsd/get-shit-done/workflows/resume-project.md +307 -0
- package/gsd/get-shit-done/workflows/set-profile.md +81 -0
- package/gsd/get-shit-done/workflows/settings.md +214 -0
- package/gsd/get-shit-done/workflows/transition.md +544 -0
- package/gsd/get-shit-done/workflows/update.md +240 -0
- package/gsd/get-shit-done/workflows/validate-phase.md +167 -0
- package/gsd/get-shit-done/workflows/verify-phase.md +243 -0
- package/gsd/get-shit-done/workflows/verify-work.md +583 -0
- package/gsd/hooks/gsd-check-update.js +81 -0
- package/gsd/hooks/gsd-context-monitor.js +141 -0
- package/gsd/hooks/gsd-statusline.js +115 -0
- package/kit/CLAUDE.md +43 -0
- package/kit/commands/kit/update.md +46 -0
- package/kit/commands/setup-refresh.md +50 -0
- package/kit/commands/setup.md +579 -0
- package/kit/commands/tool-guide.md +44 -0
- package/kit/hooks/kit-check-update.js +54 -0
- package/kit/mcp.json +10 -0
- package/kit/rules/code-style.md +24 -0
- package/manifest.json +30 -0
- 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"
|