mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-22 08:01:32 +01:00
fix(hooks): option values are not the check verb, wrapper chains stay linear, agent stalls are timed, report re-checks deferred runs (GST-1088 follow-up review)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
365dd613d2
commit
7595189caf
6 files changed
+98
-39
No files matched your search
+33
-15
@@ -268,7 +268,7 @@ export const STATUS_RE = /^[ \t>*_-]*(?:\*\*|__)?(?:STATUS|Status)(?:\*\*|__)?[
|
||||
const EDIT_TOOLS = /^(?:Edit|Write|MultiEdit|NotebookEdit)$/;
|
||||
const AGENT_TOOLS = /^(?:Agent|Task)$/;
|
||||
const TEST_RUNNER = /^(?:pytest|py\.test|jest|vitest|mocha|rspec|phpunit|ctest|tox|nox|tsc|rake|playwright|cypress)$/i;
|
||||
const CHECK_SCRIPT = /(?:^|[-_.:])(?:tests?|spec|repro|check|verify|lint)(?:[-_.:]|$)/i;
|
||||
const CHECK_SCRIPT = /(?:^|[-_.:])(?:tests?|spec|repro|check|typecheck|verify|lint)(?:[-_.:]|$)/i;
|
||||
const CHECK_VERB = /^(?:tests?|t|check|verify|spec|vet|clippy|nextest|lint|e2e)$/i;
|
||||
const SUBCOMMAND_TOOL = /^(?:make|cargo|go|dotnet|swift|mix|bazel|just|dart|flutter|rails|mvn|gradlew?|xcodebuild|bun|npm|pnpm|yarn|deno)$/i;
|
||||
const RUNS_PROGRAM = /^(?:cargo|go|dotnet|swift)$/i;
|
||||
@@ -278,22 +278,39 @@ const FILE_INTERPRETER = /^(?:bun|deno)$/i;
|
||||
const COMMAND_WRAPPER = /^(?:bundle|uv|poetry|pipenv|docker|podman|xvfb-run|bash|sh|zsh)$/;
|
||||
const COMMAND_PREFIX = /^(?:env|sudo|time|nice|timeout|command|exec|\w+=\S*|-\S*|\d+[smh]?)$/;
|
||||
const SCRIPT_ARG = /[\\/]|\.(?:[cm]?[jt]sx?|py|rb|php|pl|sh)$/;
|
||||
/** Options whose next word is their value (`make -C web test`, `pnpm --filter app test`, `xcodebuild -scheme App test`). */
|
||||
const VALUE_FLAG = /^(?:-[CfpwF]|--(?:prefix|filter|cwd|dir|directory|workspace|package|manifest-path|project|file)|-(?:scheme|project|workspace|destination|configuration|target|sdk))$/;
|
||||
const WRAPPER_DEPTH = 3;
|
||||
const baseName = (word: string) => word.split(/[\\/]/).pop() ?? '';
|
||||
const isCheckScript = (word: string) => { const name = baseName(word); return name !== 'test' && CHECK_SCRIPT.test(name); };
|
||||
|
||||
/** One command's words (prefixes removed): does it run tests, a check, or a repro? Installs, builds and version probes do not. */
|
||||
function runsCheck(words: string[]): boolean {
|
||||
/** The words after the program that are not options or option values. */
|
||||
function positionals(words: string[]): string[] {
|
||||
const out: string[] = [];
|
||||
for (let i = 1; i < words.length; i++) {
|
||||
if (words[i] === '--') break;
|
||||
if (!words[i].startsWith('-')) out.push(words[i]);
|
||||
else if (VALUE_FLAG.test(words[i])) i++;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* One command's words (prefixes removed): does it run tests, a check, or a repro? Installs, builds and version probes
|
||||
* do not. Wrappers nest at most WRAPPER_DEPTH deep, so a long chain of wrapper words costs linear time, not exponential.
|
||||
*/
|
||||
function runsCheck(words: string[], depth = 0): boolean {
|
||||
const program = baseName(words[0] ?? '');
|
||||
const args = words.slice(1).filter(w => !w.startsWith('-'));
|
||||
const args = positionals(words);
|
||||
if (TEST_RUNNER.test(program) || isCheckScript(words[0] ?? '')) return true;
|
||||
if (PACKAGE_EXEC.test(program)) return runsCheck(words.slice(1).filter(w => !w.startsWith('-')));
|
||||
if (COMMAND_WRAPPER.test(program)) return [1, 2, 3, 4, 5].some(i => i < words.length && runsCheck(words.slice(i)));
|
||||
if (INTERPRETER.test(program)) return args.length > 0 || words.slice(1).some(w => /^-[ecm]$/.test(w));
|
||||
if (depth < WRAPPER_DEPTH && PACKAGE_EXEC.test(program)) return runsCheck(words.slice(1).filter(w => !w.startsWith('-')), depth + 1);
|
||||
if (COMMAND_WRAPPER.test(program)) return depth < WRAPPER_DEPTH && [1, 2, 3, 4, 5].some(i => i < words.length && runsCheck(words.slice(i), depth + 1));
|
||||
if (INTERPRETER.test(program)) return args.length > 0 || words.slice(1).some(w => /^-[ecm]$|^--test$/.test(w));
|
||||
if (program === 'curl') return args.some(a => /^https?:\/\/|^localhost|^127\./.test(a));
|
||||
if (FILE_INTERPRETER.test(program) && args[0] && SCRIPT_ARG.test(args[0])) return true;
|
||||
if (!SUBCOMMAND_TOOL.test(program) || !args[0]) return false;
|
||||
const [verb, next] = args;
|
||||
if (CHECK_VERB.test(verb) || isCheckScript(verb)) return true;
|
||||
if (CHECK_VERB.test(verb) || isCheckScript(verb) || args.some(a => CHECK_VERB.test(a))) return true;
|
||||
if (verb === 'run' || verb === 'exec' || verb === 'x') return RUNS_PROGRAM.test(program) || (!!next && (CHECK_VERB.test(next) || isCheckScript(next) || TEST_RUNNER.test(baseName(next)) || SCRIPT_ARG.test(next)));
|
||||
return /^(?:yarn|pnpm)$/i.test(program) && TEST_RUNNER.test(verb);
|
||||
}
|
||||
@@ -521,8 +538,10 @@ export function lookupContract(skill: string, skillsDir: string, skillFile?: str
|
||||
}
|
||||
|
||||
export type Outcome = 'met' | 'met_waived' | 'blocked' | 'met_after_block' | 'miss' | 'deferred';
|
||||
/** deferred_agents: the Agent dispatches still running at the last stop the hook let through unchecked. */
|
||||
export interface RunRecord { skill: string; load_line: number; outcome: Outcome; missing: string[]; waived: string[]; blocked_at?: string; deferred_agents?: string[]; updated_at: string }
|
||||
/** deferred_agents: the Agent dispatches still running at the last stop the hook let through unchecked; deferred_at: when that set was first seen. */
|
||||
export interface RunRecord { skill: string; load_line: number; outcome: Outcome; missing: string[]; waived: string[]; blocked_at?: string; deferred_agents?: string[]; deferred_at?: string; updated_at: string }
|
||||
/** The same Agent dispatches still running this long after the stop that first saw them count as stalled. */
|
||||
export const AGENT_STALL_MS = 10 * 60 * 1000;
|
||||
export interface SessionRecord { version: 1; session_id: string; transcript_path: string; runs: Record<string, RunRecord> }
|
||||
|
||||
export function recordsDir(env: NodeJS.ProcessEnv = process.env): string {
|
||||
@@ -588,16 +607,15 @@ export function bumpCanary(why: string, env: NodeJS.ProcessEnv = process.env): n
|
||||
|
||||
export interface ReportRow { session: string; skill: string; outcome: Outcome | 'fixed_after_block'; missing: string[]; waived: string[]; transcript: string }
|
||||
|
||||
/** Every recorded run; a run still marked blocked is re-checked against its transcript when a recheck is given. */
|
||||
/** Every recorded run; a run still marked blocked or deferred is re-checked against its transcript when a recheck is given. */
|
||||
export function reportRows(records: SessionRecord[], recheck?: (rec: SessionRecord, run: RunRecord) => CheckResult | null): ReportRow[] {
|
||||
return records.flatMap(rec => Object.values(rec.runs).map(run => {
|
||||
const row: ReportRow = { session: rec.session_id, skill: run.skill, outcome: run.outcome, missing: run.missing, waived: run.waived, transcript: rec.transcript_path };
|
||||
if (run.outcome !== 'blocked' || !recheck) return row;
|
||||
if ((run.outcome !== 'blocked' && run.outcome !== 'deferred') || !recheck) return row;
|
||||
const again = recheck(rec, run);
|
||||
if (!again) return row;
|
||||
return again.met
|
||||
? { ...row, outcome: 'fixed_after_block' as const, missing: [], waived: again.waived }
|
||||
: { ...row, outcome: 'miss' as const, missing: again.missing, waived: again.waived };
|
||||
if (!again.met) return { ...row, outcome: 'miss' as const, missing: again.missing, waived: again.waived };
|
||||
return { ...row, outcome: run.outcome === 'blocked' ? 'fixed_after_block' as const : 'met' as const, missing: [], waived: again.waived };
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user