Files
brain/tools/snapshot-decide.mjs
T

23 lines
976 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/** snapshot-decide (М6, Блок 2) — чистое ядро авто-снимка. */
import { bashIsFloor } from './floor-decide.mjs';
/** Нужен ли снимок: только Bash-floor (reset --hard / rm -rf и т.п.). */
export function snapshotNeeded(toolName, toolInput) {
if (toolName !== 'Bash') return false;
return bashIsFloor((toolInput && toolInput.command) || '');
}
/**
* Разобрать результат git-захвата. Чистое дерево (stash пуст) → ref=HEAD = УСПЕХ.
* Реальная ошибка git → ok:false (fail-close). Различение F-S2.
*/
export function resolveGitState({ stashOut, headOut, error }) {
if (error) return { ok: false, ref: null };
const stash = String(stashOut || '').trim();
if (stash) return { ok: true, ref: stash };
const head = String(headOut || '').trim();
if (head) return { ok: true, ref: head };
return { ok: false, ref: null };
}