Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 17 additions & 3 deletions packages/ghost/ghost.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,25 @@ async function cmdWatch() {

// Mode B — filesystem watcher (works with ANY agent, no events needed)
let burst = null;
const checkpoint = (label) => {
const pendingFiles = new Set();
const hasGit = !!session.head;
const isNoise = (p) => p.startsWith(".ghost/") || p === ".ghost";
const checkpoint = (label, burstFiles = []) => {
try {
if (!hasGit) {
// Non-git project: shadow-git is unavailable, so record the burst as a
// plain file-list checkpoint (paths are facts; no patch to compute).
const files = [...new Set(burstFiles)].filter((p) => p && !isNoise(p));
if (!files.length) return;
const sha = `nogit-${crypto.createHash("sha1").update(files.join("\n") + Date.now()).digest("hex").slice(0, 12)}`;
session.checkpoints.push({ ts: new Date().toISOString(), turnNumber: currentTurn(), sha, files });
const t = activeTurn();
return;
}
const snap = shadow.commitSnapshot(repo, `ghost: ${label}`);
if (!snap.diff) return;
// recorder internals (.ghost/*) are bookkeeping, not app files — they
// must never become towers in the city.
const isNoise = (p) => p.startsWith(".ghost/") || p === ".ghost";
const changedFiles = snap.changedFiles.filter((p) => !isNoise(p));
const churnEntries = Object.entries(parseDiffChurn(snap.diff)).filter(([p]) => !isNoise(p));
if (!changedFiles.length || !churnEntries.length) return;
Expand All @@ -287,12 +299,14 @@ async function cmdWatch() {
if (!file) return;
const p = file.split(path.sep)[0];
if (["node_modules", ".next", ".git", ".ghost", "out", ".vercel", "testsprite_tests"].includes(p)) return;
pendingFiles.add(file.split(path.sep).join("/"));
if (burst) clearTimeout(burst);
burst = setTimeout(() => {
burst = null;
// no open turn? attribute as estimated turn so nothing is lost
if (!activeTurn()) startTurn({ ts: new Date().toISOString() });
checkpoint("worktree burst");
checkpoint("worktree burst", [...pendingFiles]);
pendingFiles.clear();
const t = activeTurn(); if (t && !t.endedAt) t.endedAt = new Date().toISOString();
}, 900);
}); } catch { console.error(" ! recursive watch unavailable on this FS — adapter events only"); }
Expand Down
16 changes: 16 additions & 0 deletions packages/ghost/lib/probes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,23 @@ export function createProbes({ url, intervalMs = 4000, fetchImpl = globalThis.fe
}
}

// Back off when the target keeps failing (wrong URL, app down, no
// /api/health): keep the last sample slot moving but stop hammering the
// app — 5 straight failures slow the cadence 8x, 10 straight 30x.
let consecutiveFailures = 0;
function reschedule() {
if (state.timer) clearInterval(state.timer);
const slot = intervalMs * (consecutiveFailures >= 10 ? 30 : consecutiveFailures >= 5 ? 8 : 1);
state.timer = setInterval(() => void sample(), slot);
state.timer.unref?.();
}

function push(ts, metrics, failed) {
if (failed) consecutiveFailures += 1; else consecutiveFailures = 0;
if (consecutiveFailures === 5 || consecutiveFailures === 10) {
// keep the slot bookkeeping correct while the cadence backs off
reschedule();
}
state.out({ ts, metrics, probeFailed: failed });
}

Expand Down
9 changes: 6 additions & 3 deletions src/components/playground/AutopsyPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export default function AutopsyPanel({
<div className="pg-block">
<div className="pg-block__head">
<span className="pg-label">Runtime metrics</span>
<span className="pg-block__count">28 samples</span>
<span className="pg-block__count">{session.metrics.length} samples</span>
</div>
<MetricsChart
metrics={session.metrics}
Expand All @@ -223,9 +223,12 @@ export default function AutopsyPanel({
<div className="pg-block">
<div className="pg-block__head">
<span className="pg-label">Fix prompt</span>
<CopyButton value={autopsy.fixPrompt} label="Copy" />
{autopsy?.fixPrompt ? <CopyButton value={autopsy.fixPrompt} label="Copy" /> : null}
</div>
<p className="pg-fix">{autopsy.fixPrompt}</p>
<p className="pg-fix">
{autopsy?.fixPrompt ??
"No anomaly detected — nothing to heal yet. Keep recording; the engine drafts the heal prompt if a sample breaches a threshold."}
</p>
</div>
</aside>
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/playground/TimelineDock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ export default function TimelineDock({
<span
className="pg-dock__anomaly"
style={{ left: `${anomaly}%` }}
title="Anomaly on turn 4"
aria-label="Anomaly on turn 4"
title={`Anomaly on turn ${anomalyTurn + 1}`}
aria-label={`Anomaly on turn ${anomalyTurn + 1}`}
>
<i aria-hidden="true" />
</span>
Expand Down
6 changes: 5 additions & 1 deletion src/components/playground/city.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ export function buildPlaygroundCity(
turn: firstSeen.get(file.path) ?? 1,
seed: hash(file.path),
}))
: (KNOWN_FILES.map((path) => {
: isLive
// live recording without churn data (e.g. not a git repo): no towers —
// never fill the user's city with the demo's files.
? []
: (KNOWN_FILES.map((path) => {
const snap = snapshotFiles.get(path);
const seed = hash(path);
return {
Expand Down
Loading