Skip to content
Open
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
36 changes: 33 additions & 3 deletions LifeOS/install/LIFEOS/PULSE/Observability/src/app/conduit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ export default function ConduitPage() {
const [sources, setSources] = useState<SourcesReport | null>(null);
const [insight, setInsight] = useState<Insight | null>(null);
const [error, setError] = useState<string | null>(null);
const [building, setBuilding] = useState(false);
const [buildMsg, setBuildMsg] = useState<string | null>(null);

async function runBuildInsights() {
setBuilding(true);
setBuildMsg(null);
try {
const res = await fetch("/api/conduit/build", { method: "POST" });
const data = await res.json().catch(() => ({ ok: res.ok }));
setBuildMsg(data.ok ? "Insights rebuilt." : "Build failed — see server log.");
const fresh = await fetch("/api/conduit/insight").then((r) => r.json());
setInsight(fresh);
} catch (e) {
setBuildMsg("Build error: " + String(e));
} finally {
setBuilding(false);
}
}

useEffect(() => {
fetch("/api/conduit/today").then((r) => r.json()).then(setToday).catch((e) => setError(String(e)));
Expand Down Expand Up @@ -136,9 +154,21 @@ export default function ConduitPage() {
</div>
) : (
!insight.available && (
<div className="text-xs text-ink-3">
The insight job runs on the hour. Run it now:{" "}
<code className="text-ink-2 mono">bun Conduit/BuildInsight.ts</code>
<div className="text-xs text-ink-3 space-y-2">
<div>The insight job runs on the hour. Build it now:</div>
<button
type="button"
onClick={runBuildInsights}
disabled={building}
className="px-3 py-1.5 rounded-md bg-white/[0.06] hover:bg-white/[0.1] text-ink-1 text-xs font-medium disabled:opacity-50 transition-colors"
>
{building ? "Building…" : "Build insights now"}
</button>
{buildMsg && <div className="text-ink-2">{buildMsg}</div>}
<div>
Or from a terminal:{" "}
<code className="text-ink-2 mono">bun ~/.claude/LIFEOS/PULSE/Conduit/BuildInsight.ts</code>
</div>
</div>
)
)}
Expand Down
21 changes: 21 additions & 0 deletions LifeOS/install/LIFEOS/PULSE/modules/conduit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,29 @@ export function todayRecordPublic(): DailyRecord {
return todayRecord()
}

/** Run BuildInsight.ts on demand (the "Build insights now" button). Spawns the
* standalone script — same as the hourly launchd job — and returns its output. */
async function buildInsightNow(): Promise<Response> {
const script = join(import.meta.dir, "..", "Conduit", "BuildInsight.ts")
try {
const proc = Bun.spawn(["bun", script], { stdout: "pipe", stderr: "pipe" })
const [out, err, code] = await Promise.all([
new Response(proc.stdout).text(),
new Response(proc.stderr).text(),
proc.exited,
])
return Response.json(
{ ok: code === 0, output: ((out || "") + (err || "")).slice(-1500) },
{ status: code === 0 ? 200 : 500 },
)
} catch (e) {
return Response.json({ ok: false, output: String(e) }, { status: 500 })
}
}

export async function handleRequest(req: Request, pathname: string): Promise<Response | null> {
const sub = pathname.replace(/^\/api\/conduit/, "") || "/"
if (sub === "/build" && req.method === "POST") return buildInsightNow()
if (sub === "/" || sub === "/today") return Response.json(todayRecord())
if (sub === "/recent") {
const days = Math.max(1, Math.min(90, Number(new URL(req.url).searchParams.get("days")) || 7))
Expand Down