Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions plugins/claude-code-hermit/scripts/lib/routines/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import fs from 'node:fs';
import path from 'node:path';
import { utcISOStamp } from '../time';
import { utcISOStamp, localISOStamp } from '../time';
import { appendJsonlLine } from '../append-jsonl';

// Deliberately not an enum check: the shell version accepted any event string,
Expand Down Expand Up @@ -62,10 +62,32 @@ export function logRoutineEvent(
} catch { /* no ledger yet — nothing to dedup against */ }
}

return appendJsonlLine(
const err = appendJsonlLine(
metrics,
JSON.stringify({ ts: utcISOStamp(), routine_id: id, event, delivery }),
);
if (err) return err;

// A routine that actually ran (as opposed to skipped-paused/skipped-waiting) is
// real session activity. Without this, an always-on session cycling routines
// via Monitor between operator turns never touches runtime.json's `updated_at`
// — only session-archive.ts's open/close/heartbeat transitions do — so
// evaluate-session.ts's stale-session nudge fires on a session that is working
// exactly as designed, just not writing Progress Log lines for background
// routine cycles. Touching updated_at here is fail-soft: a failure must not
// block or fail the routine event itself.
if (event === 'fired' || event === 'started') {
try {
const runtimePath = path.join(root, '.claude-code-hermit', 'state', 'runtime.json');
const runtime = JSON.parse(fs.readFileSync(runtimePath, 'utf-8'));
runtime.updated_at = localISOStamp();
const tmp = `${runtimePath}.${process.pid}.tmp`;
fs.writeFileSync(tmp, JSON.stringify(runtime, null, 2) + '\n', 'utf-8');
fs.renameSync(tmp, runtimePath);
Comment on lines +81 to +86
} catch { /* fail-soft — runtime.json missing/corrupt must not block the routine */ }
Comment on lines +84 to +87
}

return null;
}

export function run(args: string[]): void {
Expand Down
Loading