framework
Version:
The (AI) Framework: turnkey, zero-config AI orchestration that wraps a coding-agent CLI (Claude Code) as a black box and takes you from an idea to a running app. Vite for AI.
55 lines • 2.54 kB
JavaScript
import { readEventLog, readLiveMetas } from '../store/index.js';
/**
* The full {@link ChoiceRequest} still open under this id: its `choice` event with no later
* `choice-resolved` for the same id. The sibling of live-run.ts's `openGate`, which slims the
* gate down to what chat can render — an answering *panel* needs everything the event carried
* (multi, recommended, detail lines), so this keeps the request whole.
*/
export function openChoiceRequest(events, gateId) {
let open;
for (const event of events) {
if (event.kind === 'choice' && event.id === gateId) {
const { kind: _kind, ...request } = event;
open = request;
}
else if (event.kind === 'choice-resolved' && event.id === gateId) {
open = undefined;
}
}
return open;
}
/**
* Every project's parked questions, longest-waiting first (#1455): an agent that has been blocked
* on its human the longest is the one to unblock first.
*
* Forgiving throughout, like every cross-project rollup: an unreadable project, agent list or
* event log contributes nothing rather than failing the read. A pending gate whose log no
* longer shows it open (already resolved, log unreadable) is skipped — offering an answer the
* daemon would refuse is worse than one card fewer.
*/
export async function buildOpenQuestions(projects, deps = {}) {
const liveAgents = deps.liveAgents ?? readLiveMetas;
const events = deps.events ?? readEventLog;
const items = [];
for (const project of projects) {
for (const meta of await liveAgents(project.path).catch(() => [])) {
if (meta.status !== 'running' || !meta.pendingChoice)
continue;
// The agent's own checkout, not the project root: a daemon-spawned agent logs in its worktree.
const choice = openChoiceRequest(await events(meta.cwd).catch(() => []), meta.pendingChoice.id);
if (!choice)
continue;
items.push({
projectId: project.id,
projectName: project.name,
agentId: meta.id,
...(meta.sessionName ? { sessionName: meta.sessionName } : {}),
...(meta.intent ? { intent: meta.intent } : {}),
...(meta.updatedAt ? { updatedAt: meta.updatedAt } : {}),
choice,
});
}
}
return items.sort((a, b) => (a.updatedAt ?? '').localeCompare(b.updatedAt ?? ''));
}
//# sourceMappingURL=open-questions.js.map