Task 1.2: introduce a single path resolver so no harness script hardcodes `.specify/...` scattered across the tree. casan-paths.sh resolves four roots (HARNESS/STATE/GOVERNANCE/APP) by marker-based walk-up from its own location — never `git rev-parse` (git root is the repo PARENT here, not the app dir). - 101 bash scripts/tests: 238 hardcoded `$PROJECT_ROOT/.specify/...` refs rewritten to CASAN_HARNESS_ROOT (code) / CASAN_STATE_ROOT (logs,state) / CASAN_GOVERNANCE_ROOT. Sandbox test vars ($WORK/$TP/$FP/$T1_WORK) left untouched. - Roots are NOT exported: each script/subprocess self-resolves from its own tree, matching the original per-script semantics and preserving hermetic sandbox isolation (node casan-step.mjs, copied telemetry/rollback scripts must not inherit real roots). - Sandbox tests that copy a harness script now also copy casan-paths.sh (its new sibling dependency): adversarial (verify-audit-chain/verify-tool-audit/rollback) + track-a (security-check/telemetry-integrity). - control-plane-settings.json reclassified as STATE (untracked runtime store). Roots all still resolve to `.specify` in this monolithic layout, so behavior is unchanged. Full gate: PASS=64 FAIL=0 SKIP=3 (adversarial 44/0, track-a 25/0). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
41 lines
1.4 KiB
Bash
Executable File
41 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# CASAN Level 5 provider usage telemetry importer.
|
|
# Usage:
|
|
# import-provider-telemetry.sh <provider-usage-json>
|
|
|
|
INPUT_JSON="${1:-}"
|
|
if [[ -z "$INPUT_JSON" || ! -f "$INPUT_JSON" ]]; then
|
|
echo "Usage: import-provider-telemetry.sh <provider-usage-json>" >&2
|
|
exit 64
|
|
fi
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/casan-paths.sh"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
|
|
LOG_DIR="$CASAN_STATE_ROOT/logs/level5"
|
|
OUT="$LOG_DIR/provider-usage.jsonl"
|
|
mkdir -p "$LOG_DIR"
|
|
|
|
python - "$INPUT_JSON" "$OUT" <<'PY'
|
|
import json
|
|
import sys
|
|
from datetime import datetime, timezone
|
|
|
|
src, out = sys.argv[1], sys.argv[2]
|
|
data = json.load(open(src, encoding="utf-8"))
|
|
required = ["provider", "model", "run_id", "step", "input_tokens", "output_tokens", "total_tokens", "cost_usd", "latency_ms", "status"]
|
|
missing = [key for key in required if key not in data]
|
|
if missing:
|
|
raise SystemExit(f"PROVIDER_USAGE_INVALID missing={missing}")
|
|
record = {
|
|
"timestamp": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
|
"harness": "L5-provider-telemetry",
|
|
**data,
|
|
}
|
|
with open(out, "a", encoding="utf-8") as f:
|
|
f.write(json.dumps(record) + "\n")
|
|
print(f"PROVIDER_TELEMETRY_IMPORTED provider={data['provider']} model={data['model']} total_tokens={data['total_tokens']} cost_usd={data['cost_usd']} output={out}")
|
|
PY
|