Files
CASAN/AINative_OKR_CASAN5/packages/casan-harness/scripts/bash/casan-paths.sh
T
thanhnvandClaude Opus 4.8 664bd1f00c feat(plan-01): Phase 1 — relocate harness code to packages/casan-harness (symlink facade)
Physically move the pure-code subtrees out of .specify into the package, leaving
compat symlinks at the old .specify/<dir> paths so every existing reference (internal
CASAN_HARNESS_ROOT + external CI/docker/mjs) keeps resolving. Runtime state stays put.

Moved (git mv): scripts/ tests/ security/ templates/ config/ governance/ memory/
  .specify/<dir>  ->  packages/casan-harness/<dir>   (+ .specify/<dir> symlink)
Stays in .specify (state/governance/domain, handled later): logs/ agentops/ level5/
  init-options.json traceability-map.json

Python `.resolve()` self-location followed the compat symlink into packages and lost
the app root; generate-casan-demo-context.py, generate-agentops-dashboard.py and
dashboard-server.py now walk UP for the `.specify` state marker instead of a fixed
parent depth (fixes "missing trace files" in run-casan4).

Full gate: PASS=64 FAIL=0 SKIP=3 (CASAN_CI_STEP_TIMEOUT_SEC=1200 — track-a ~450s runs
close to the 600s default and can tip over under load; this is timing variance, not a
regression — it passed cleanly with headroom). Runtime log/audit artifacts kept unstaged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-08 00:06:00 +09:00

77 lines
3.6 KiB
Bash

#!/usr/bin/env bash
# CASAN path resolver — single source of truth for harness / state / governance roots.
#
# Plan-01 restructure: physical file moves (`.specify/` -> `packages/casan-harness/`,
# domain -> `apps/okr/domain/`) are absorbed HERE. Callers must reference the
# CASAN_*_ROOT variables below instead of hardcoding ".specify/...", so a move only
# changes this file, not the 37+ scripts that consume the paths.
#
# Resolution rules (per root):
# - An explicit env override always wins (e.g. CASAN_HARNESS_ROOT=... bash foo.sh).
# - CASAN_HARNESS_ROOT derives from THIS file's own location: casan-paths.sh always
# lives at <harness-root>/scripts/bash/casan-paths.sh, so `../..` is the harness
# root wherever the tree is moved. No edit needed when the package relocates.
# - CASAN_APP_ROOT is found by walking UP for the `.specify` state marker.
# NEVER use `git rev-parse --show-toplevel`: in this checkout the git root is the
# repo PARENT, not the app dir, which would shift every path up one level.
#
# Idempotent and `set -e` safe: sourcing multiple times is a no-op; nothing here
# returns a non-zero status to a caller running under `set -euo pipefail`.
if [[ -n "${CASAN_PATHS_SOURCED:-}" ]]; then
return 0 2>/dev/null || true
fi
_casan_paths_self="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Walk up from a starting dir until a dir containing `.specify/` is found.
_casan_find_app_root() {
local d="$1"
while [[ -n "$d" && "$d" != "/" ]]; do
if [[ -d "$d/.specify" ]]; then
printf '%s\n' "$d"
return 0
fi
d="$(dirname "$d")"
done
return 1
}
# Harness (CODE) root: the tree that holds scripts/, security/, templates/, tests/,
# config/, level5/*.yaml. Derived from this file's location so it follows the move.
if [[ -z "${CASAN_HARNESS_ROOT:-}" ]]; then
CASAN_HARNESS_ROOT="$(cd "$_casan_paths_self/../.." && pwd)"
fi
# App root: where runtime state lives (holds the `.specify` marker). Walk up from the
# harness root; fall back to the classic `<harness>/..`-style layout if not found.
if [[ -z "${CASAN_APP_ROOT:-}" ]]; then
CASAN_APP_ROOT="$(_casan_find_app_root "$_casan_paths_self" || true)"
fi
if [[ -z "${CASAN_APP_ROOT:-}" ]]; then
CASAN_APP_ROOT="$(cd "$CASAN_HARNESS_ROOT/.." && pwd)"
fi
# State (RUNTIME) root: logs/, state/, agentops/ — stays with the app, not the package.
if [[ -z "${CASAN_STATE_ROOT:-}" ]]; then
CASAN_STATE_ROOT="$CASAN_APP_ROOT/.specify"
fi
# Governance root: central-governance mixes harness pub-keys/registries, runtime
# policy-manifest state, and a private key. Rooted under STATE (not HARNESS) so the
# runtime-regenerated policy-manifest.{json,sig} and the private key never land inside
# the shipped code package; it stays at .specify/level5/central-governance across the
# move. Plan-01 can still split individual files later via per-file overrides
# (CASAN_AUDIT_PUB, CASAN_AGENT_REGISTRY, CASAN_AGENT_KEYS_DIR, CASAN_BUNDLE_MANIFEST).
if [[ -z "${CASAN_GOVERNANCE_ROOT:-}" ]]; then
CASAN_GOVERNANCE_ROOT="$CASAN_STATE_ROOT/level5/central-governance"
fi
# NOTE: roots are deliberately NOT exported. Each script/test sources this resolver
# and self-derives its roots from its OWN location (BASH_SOURCE), matching the original
# per-script `PROJECT_ROOT="$SCRIPT_DIR/../../.."` semantics. Exporting them would leak
# the caller's (real-repo) roots into sandbox subprocesses (e.g. `node casan-step.mjs`,
# copied telemetry/rollback scripts), breaking hermetic test isolation. The idempotency
# flag is likewise NOT exported, so every subprocess re-resolves against its own tree.
CASAN_PATHS_SOURCED=1