Add a shared log taxonomy (error<warn<info<debug<trace, default info) wired through all three layers, plus a machine-readable per-step run log. - scripts/casan-log.mjs + .specify/scripts/bash/casan-log.sh: shared logger ([LEVEL] ts [component] msg), stderr-only so stdout contracts and exit codes are byte-identical. Node side includes trace-level redaction (secret/PII). - run-casan-pipeline.mjs: per-STEP info line, loop-activation warnings (BACK-TO-PLAN, FAIL->STEP6), debug harness rc + trace_id, trace payload excerpt, end-of-run 13-STEP summary table, and one JSONL line/step in .specify/logs/pipeline-run.jsonl. New --dry-run stubs all agents but keeps the real wrapper in the loop (deterministic, offline, full 13 STEP + loops). - casan-step.mjs: debug logs for judge verdict, checkpoint, rollback; logger import degrades to noop when the file is copied standalone (T1 test). - casan-harness.sh: debug-log each phase H4-in -> H5 -> [H2-gate] -> H6-exec -> H4-out with its rc; optional CASAN_PHASE_REPORT JSON for the Boss. Default level (info) keeps output close to before; behavior opt-in via env. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
43 lines
1.8 KiB
JavaScript
43 lines
1.8 KiB
JavaScript
// CASAN shared log helper (Node side).
|
|
// Taxonomy (shared with .specify/scripts/bash/casan-log.sh):
|
|
// error(0) < warn(1) < info(2) < debug(3) < trace(4), default info.
|
|
// All lines go to stderr so stdout stays reserved for existing outputs.
|
|
|
|
export const LEVELS = { error: 0, warn: 1, info: 2, debug: 3, trace: 4 };
|
|
|
|
const raw = (process.env.CASAN_LOG_LEVEL ?? 'info').toLowerCase();
|
|
export const LOG_LEVEL = raw in LEVELS ? raw : 'info';
|
|
export const LOG_THRESHOLD = LEVELS[LOG_LEVEL];
|
|
|
|
export function enabled(level) {
|
|
return (LEVELS[level] ?? LEVELS.info) <= LOG_THRESHOLD;
|
|
}
|
|
|
|
export function log(level, component, message) {
|
|
if (!enabled(level)) return;
|
|
process.stderr.write(
|
|
`[${level.toUpperCase()}] ${new Date().toISOString()} [${component}] ${message}\n`,
|
|
);
|
|
}
|
|
|
|
// Redaction for trace-level payload excerpts. Mirrors the H4 masking families
|
|
// (email/phone/id/credit-card/secret/private-key/conn-string/AWS key) so no
|
|
// secret or PII ever reaches the terminal, even at trace.
|
|
const REDACTIONS = [
|
|
[/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(-----END [A-Z ]*PRIVATE KEY-----|$)/g, '[REDACTED_PRIVATE_KEY]'],
|
|
[/(API[_-]?KEY|ACCESS[_-]?TOKEN|REFRESH[_-]?TOKEN|PASSWORD|JWT[_-]?SECRET|SECRET)\s*[:=]\s*\S+/gi, '$1=[REDACTED]'],
|
|
[/(postgres|mysql|mongodb):\/\/[^@\s]+@/gi, '$1://[REDACTED]@'],
|
|
[/AKIA[0-9A-Z]{16}/g, '[REDACTED_AWS_KEY]'],
|
|
[/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g, '***MASKED_EMAIL***'],
|
|
[/\b(?:[0-9]{4}[- ]?){3}[0-9]{4}\b/g, '***MASKED_CARD***'],
|
|
[/\b[0-9]{9,12}\b/g, '***MASKED_ID***'],
|
|
[/\+?[0-9][0-9 .-]{8,}[0-9]/g, '***MASKED_PHONE***'],
|
|
];
|
|
|
|
export function redact(text, maxLen = 200) {
|
|
let out = String(text ?? '');
|
|
for (const [re, sub] of REDACTIONS) out = out.replace(re, sub);
|
|
if (out.length > maxLen) out = `${out.slice(0, maxLen)}…(+${out.length - maxLen} chars)`;
|
|
return out.replace(/\n/g, '\\n');
|
|
}
|