mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 09:20:03 +01:00
fix(control): clarify live agent runtime states
This commit is contained in:
7 files changed
+116
-45
No files matched your search
+35
-19
@@ -780,6 +780,29 @@ _build_state_json() {
|
||||
continue
|
||||
fi
|
||||
|
||||
# Resolve the canonical project key to the live Zellij tab. Many sessions
|
||||
# run as "Project Claude" / "Project Codex" while the registered project key
|
||||
# remains "Project". Runtime state is stored under the canonical key, but
|
||||
# sentinels, current prompt files, and session handoffs use the live tab.
|
||||
local live_tab="$tab" exact_tab="" suffix_tab=""
|
||||
local tab_lower="${tab,,}"
|
||||
while IFS= read -r open_tab; do
|
||||
[ -z "$open_tab" ] && continue
|
||||
local open_lower="${open_tab,,}"
|
||||
if [ "$open_lower" = "$tab_lower" ]; then
|
||||
exact_tab="$open_tab"
|
||||
break
|
||||
fi
|
||||
if [ -z "$suffix_tab" ] && { [[ "$open_lower" == "$tab_lower "* ]] || [[ "$open_lower" == "$tab_lower-"* ]]; }; then
|
||||
suffix_tab="$open_tab"
|
||||
fi
|
||||
done <<< "$all_open_tabs"
|
||||
if [ -n "$exact_tab" ]; then
|
||||
live_tab="$exact_tab"
|
||||
elif [ -n "$suffix_tab" ]; then
|
||||
live_tab="$suffix_tab"
|
||||
fi
|
||||
|
||||
# Determine agent running + active agent names for this dir
|
||||
local running="false" agents_json="[]"
|
||||
while IFS= read -r line; do
|
||||
@@ -796,20 +819,20 @@ _build_state_json() {
|
||||
|
||||
# Check if this project's Zellij tab is actually open (case-insensitive exact line)
|
||||
local tab_open="false"
|
||||
if echo "$all_open_tabs" | grep -qixF "$tab"; then
|
||||
if echo "$all_open_tabs" | grep -qixF "$live_tab"; then
|
||||
tab_open="true"
|
||||
fi
|
||||
|
||||
# Sentinel timestamps
|
||||
local ready_at closing_at closed_at lock_at
|
||||
ready_at=$(_sentinel "/tmp/agent-ready-${tab}")
|
||||
closing_at=$(_sentinel "/tmp/agent-closing-${tab}")
|
||||
closed_at=$(_sentinel "/tmp/agent-closed-${tab}")
|
||||
lock_at=$(_sentinel "/tmp/agent-stop-active-${tab}")
|
||||
ready_at=$(_sentinel "/tmp/agent-ready-${live_tab}")
|
||||
closing_at=$(_sentinel "/tmp/agent-closing-${live_tab}")
|
||||
closed_at=$(_sentinel "/tmp/agent-closed-${live_tab}")
|
||||
lock_at=$(_sentinel "/tmp/agent-stop-active-${live_tab}")
|
||||
|
||||
# Current prompt JSON
|
||||
local cpk="" cpl="" cpsat="null"
|
||||
local pf="/tmp/agent-current-prompt-${tab}"
|
||||
local pf="/tmp/agent-current-prompt-${live_tab}"
|
||||
if [ -f "$pf" ]; then
|
||||
local pj
|
||||
pj=$(cat "$pf" 2>/dev/null)
|
||||
@@ -850,22 +873,15 @@ _build_state_json() {
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
# A stop/notification hook is authoritative evidence of the configured
|
||||
# agent in this open tab even when the CLI launches through a wrapper whose
|
||||
# process basename is not recognized by /proc scanning.
|
||||
if [ "$tab_open" = "true" ] && [ "$agents_json" = "[]" ] && [ "$ready_at" != "null" ]; then
|
||||
local ready_age
|
||||
ready_age=$(( $(date +%s) - ready_at ))
|
||||
if [ "$ready_age" -ge 0 ] && [ "$ready_age" -lt 900 ]; then
|
||||
agents_json=$(jq -nc --arg a "$adapter" '[$a]')
|
||||
running="true"
|
||||
fi
|
||||
fi
|
||||
# A ready sentinel is lifecycle evidence, not process evidence. Do not
|
||||
# manufacture activeAgents/running from it; otherwise the cloud UI can show
|
||||
# "Codex ready" because Codex is configured even when Claude is the live
|
||||
# process in the tab.
|
||||
local sf
|
||||
if type _session_file >/dev/null 2>&1; then
|
||||
sf="$(_session_file "$tab" "$adapter")"
|
||||
sf="$(_session_file "$live_tab" "$adapter")"
|
||||
else
|
||||
sf="$HOME/.claude/sessions/${tab}.md"
|
||||
sf="$HOME/.claude/sessions/${live_tab}.md"
|
||||
fi
|
||||
local sess_status="" sess_done="" sess_next="" sess_tests="" sess_todos="" sess_health="" sess_mtime="null"
|
||||
if [ -f "$sf" ]; then
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
findProjectForOpenTab,
|
||||
formatAgentRuntimeLabel,
|
||||
getProjectDisplayState,
|
||||
isProjectTabOpen,
|
||||
isCurrentPromptStale,
|
||||
} from "@/components/control/control-presenter";
|
||||
import type { ProjectState } from "@/lib/control-types";
|
||||
@@ -62,6 +63,12 @@ function runTests(): void {
|
||||
assert(findProjectForOpenTab("Cockpit Claude", projects)?.tab === "Cockpit", "expected prefix match");
|
||||
});
|
||||
|
||||
check("isProjectTabOpen accepts agent-suffixed live tabs", () => {
|
||||
const project = stubProject({ tab: "Cockpit", liveTab: "Cockpit" });
|
||||
assert(isProjectTabOpen(project, ["Cockpit Claude"]), "expected suffix tab to count as open");
|
||||
assert(!isProjectTabOpen(project, ["Cockpit2 Claude"]), "must not match unrelated prefixes");
|
||||
});
|
||||
|
||||
check("buildLiveTabRows sorts Working before Open", () => {
|
||||
const nowS = 1_700_000_000;
|
||||
const projects = [
|
||||
@@ -132,9 +139,24 @@ function runTests(): void {
|
||||
assert(snapshot.evidenceKind === "historical", "handoff provenance must be historical");
|
||||
});
|
||||
|
||||
check("open session waiting for input has one explicit user-facing label", () => {
|
||||
const state = getProjectDisplayState(stubProject({ tab: "Cockpit", agentRunning: true }), ["Cockpit"], 1_700_000_000);
|
||||
assert(state.stateLabel === "Waiting for you", "open inactive agent must explain the required action");
|
||||
check("open session is not mislabeled as waiting for input", () => {
|
||||
const nowS = 1_700_000_000;
|
||||
const project = stubProject({ tab: "Cockpit", agentRunning: true });
|
||||
const state = getProjectDisplayState(project, ["Cockpit"], nowS);
|
||||
const snapshot = buildProjectOperationsSnapshot(project, ["Cockpit"], nowS);
|
||||
assert(state.stateLabel === "Agent shell open", "open inactive agent must describe the observed shell");
|
||||
assert(snapshot.phase === "open_idle", "open inactive agent must not count as waiting for input");
|
||||
assert(snapshot.evidenceLabel === "Agent shell open; no active task detected", "evidence should explain the live signal");
|
||||
});
|
||||
|
||||
check("ready sentinel is a next-step state, not generic waiting", () => {
|
||||
const nowS = 1_700_000_000;
|
||||
const project = stubProject({ tab: "Cockpit", readyAt: nowS - 5 });
|
||||
const state = getProjectDisplayState(project, ["Cockpit"], nowS);
|
||||
const snapshot = buildProjectOperationsSnapshot(project, ["Cockpit"], nowS);
|
||||
assert(state.stateLabel === "Ready for next step", "ready signal must name the action state");
|
||||
assert(snapshot.phase === "waiting_for_user", "ready signal remains actionable");
|
||||
assert(snapshot.evidenceLabel === "Agent signaled ready on connected computer", "ready evidence should identify the signal");
|
||||
});
|
||||
|
||||
check("operations list prioritizes projects waiting for user action", () => {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { postJson, patchJson } from "@/lib/api/fetch";
|
||||
import type { ProjectState } from "@/lib/control-types";
|
||||
import type { PromptMeta } from "@/lib/agent-config";
|
||||
import type { OrchestrationTaskIntentId } from "@/lib/orchestration";
|
||||
import { getProjectDisplayState, type ProjectOperationsSnapshot } from "./control-presenter";
|
||||
import { getProjectDisplayState, isProjectTabOpen, type ProjectOperationsSnapshot } from "./control-presenter";
|
||||
import { ProjectProfile } from "./ProjectProfile";
|
||||
import { LatestOrchestrationPanel } from "./project-card-helpers";
|
||||
import { ProjectCardHeader, SessionSummary } from "./project-card-sections";
|
||||
@@ -72,7 +72,7 @@ export function ProjectCard({
|
||||
patchJson(`/api/user-projects/${project.id}`, { agentPref: agentId ?? undefined }).catch(() => {});
|
||||
}
|
||||
const workspaceTab = project.liveTab ?? project.tab;
|
||||
const tabIsOpen = zellijTabs.some((t) => t.toLowerCase() === workspaceTab.toLowerCase());
|
||||
const tabIsOpen = isProjectTabOpen(project, zellijTabs);
|
||||
if (agentId && agentId !== currentAgent && tabIsOpen && project.dir) {
|
||||
setSwitchingAgent(true);
|
||||
try {
|
||||
|
||||
@@ -59,6 +59,7 @@ export function ProjectOperationsView({
|
||||
const selected = snapshots.find((snapshot) => snapshot.project.tab === selectedTab) ?? snapshots[0];
|
||||
const readyCount = snapshots.filter((snapshot) => snapshot.phase === "waiting_for_user").length;
|
||||
const workingCount = snapshots.filter((snapshot) => snapshot.phase === "working").length;
|
||||
const openIdleCount = snapshots.filter((snapshot) => snapshot.phase === "open_idle").length;
|
||||
|
||||
return (
|
||||
<section className="ui-control-workspace">
|
||||
@@ -66,7 +67,7 @@ export function ProjectOperationsView({
|
||||
<div className="border-b border-border-subtle px-4 pb-3 pt-4">
|
||||
<h2 className="text-sm font-semibold text-text-primary">Projects</h2>
|
||||
<p className="mt-1 text-xs text-text-tertiary">
|
||||
{workingCount} working · {readyCount} waiting for you
|
||||
{workingCount} working · {readyCount} ready · {openIdleCount} open
|
||||
</p>
|
||||
</div>
|
||||
<div className="ui-control-project-list">
|
||||
@@ -76,6 +77,8 @@ export function ProjectOperationsView({
|
||||
? "bg-accent-primary animate-pulse"
|
||||
: snapshot.phase === "waiting_for_user" || snapshot.phase === "completed"
|
||||
? "bg-status-positive"
|
||||
: snapshot.phase === "open_idle"
|
||||
? "bg-border-strong"
|
||||
: snapshot.phase === "offline"
|
||||
? "bg-status-warning"
|
||||
: "bg-border-default";
|
||||
|
||||
@@ -63,6 +63,13 @@ export function ProjectStatusChips({
|
||||
const [commitState, setCommitState] = useState<"idle" | "committing" | "done" | "error">("idle");
|
||||
const [commitResult, setCommitResult] = useState<{ sha?: string; error?: string } | null>(null);
|
||||
const runtimeLabel = runtimeStateKnown ? formatAgentRuntimeLabel(project) : "";
|
||||
const runtimeStateLabel = working
|
||||
? `${runtimeLabel} working`
|
||||
: project.readyAt
|
||||
? `${runtimeLabel} ready`
|
||||
: project.agentRunning
|
||||
? `${runtimeLabel} open`
|
||||
: `${runtimeLabel} detected`;
|
||||
const git = project.git;
|
||||
const workspaceTab = project.liveTab ?? project.tab;
|
||||
const changesLabel = pendingChangesLabel(project);
|
||||
@@ -133,7 +140,7 @@ export function ProjectStatusChips({
|
||||
>
|
||||
{switchingAgent
|
||||
? <><Loader2 className="h-3 w-3 shrink-0 animate-spin" /><span>Switching…</span></>
|
||||
: <><span>{working ? `${runtimeLabel} working` : `${runtimeLabel} ready`}</span>
|
||||
: <><span>{runtimeStateLabel}</span>
|
||||
<ChevronDown className={cn("h-3 w-3 shrink-0 opacity-50 transition-transform", agentPopoverOpen && "rotate-180")} /></>
|
||||
}
|
||||
</button>
|
||||
@@ -149,9 +156,9 @@ export function ProjectStatusChips({
|
||||
) : (
|
||||
<span
|
||||
className={compact ? undefined : statusChipClass(working ? "warning" : "neutral")}
|
||||
title={`${runtimeLabel} is currently detected in this project workspace. This comes from local process detection, not a cloud status API.`}
|
||||
title={`${runtimeLabel} is currently detected in this project workspace. "Open" means the agent process exists but no active task is being tracked. This comes from local process detection, not a cloud status API.`}
|
||||
>
|
||||
{working ? `${runtimeLabel} working` : `${runtimeLabel} ready`}
|
||||
{runtimeStateLabel}
|
||||
</span>
|
||||
)
|
||||
)}
|
||||
|
||||
@@ -67,7 +67,7 @@ export type ProjectDisplayState = {
|
||||
| "closed"
|
||||
| "idle";
|
||||
/** Human-readable label for the state badge — single source of truth */
|
||||
stateLabel: "Offline" | "Working" | "Waiting for you" | "Closing" | "Completed" | "Not running";
|
||||
stateLabel: "Offline" | "Working" | "Ready for next step" | "Agent shell open" | "Closing" | "Completed" | "Not running";
|
||||
/** Tailwind classes for the ui-tag badge */
|
||||
stateTagClass: string;
|
||||
};
|
||||
@@ -77,6 +77,7 @@ export type ControlPhase =
|
||||
| "not_running"
|
||||
| "working"
|
||||
| "waiting_for_user"
|
||||
| "open_idle"
|
||||
| "closing"
|
||||
| "completed";
|
||||
|
||||
@@ -123,7 +124,8 @@ type LiveTabRankLabel = LiveTabRow["stateLabel"];
|
||||
const LIVE_TAB_RANK: Record<LiveTabRankLabel, number> = {
|
||||
Offline: 0,
|
||||
Working: 0,
|
||||
"Waiting for you": 1,
|
||||
"Ready for next step": 1,
|
||||
"Agent shell open": 3,
|
||||
Closing: 2,
|
||||
Completed: 3,
|
||||
"Not running": 4,
|
||||
@@ -146,6 +148,14 @@ export function findProjectForOpenTab(openTab: string, projects: ProjectState[])
|
||||
return prefix ?? null;
|
||||
}
|
||||
|
||||
export function isProjectTabOpen(project: ProjectState, zellijTabs: string[]): boolean {
|
||||
const canonical = (project.liveTab ?? project.tab).toLowerCase();
|
||||
return zellijTabs.some((tab) => {
|
||||
const open = tab.toLowerCase();
|
||||
return open === canonical || open.startsWith(`${canonical} `) || open.startsWith(`${canonical}-`);
|
||||
});
|
||||
}
|
||||
|
||||
export function getTabActivityText(
|
||||
project: ProjectState | null,
|
||||
display: ProjectDisplayState | null,
|
||||
@@ -158,7 +168,7 @@ export function getTabActivityText(
|
||||
return project.session.next.trim();
|
||||
}
|
||||
if (display?.isReady || display?.isOrchestrationReady) {
|
||||
return "Waiting for your next instruction";
|
||||
return "Agent finished the last task; choose the next action";
|
||||
}
|
||||
if (project.session?.next?.trim()) return `Saved handoff: ${project.session.next.trim()}`;
|
||||
if (project.session?.done?.trim()) {
|
||||
@@ -317,9 +327,7 @@ export function getProjectDisplayState(
|
||||
!isOrchestrationReady &&
|
||||
!isClosing &&
|
||||
!isClosed;
|
||||
const tabOpen = zellijTabs.some(
|
||||
(tab) => tab.toLowerCase() === (project.liveTab ?? project.tab).toLowerCase(),
|
||||
);
|
||||
const tabOpen = isProjectTabOpen(project, zellijTabs);
|
||||
const isActive =
|
||||
isRunning ||
|
||||
isOrchestrationReady ||
|
||||
@@ -346,9 +354,9 @@ export function getProjectDisplayState(
|
||||
const STATE_LABEL: Record<ProjectDisplayState["tone"], ProjectDisplayState["stateLabel"]> = {
|
||||
offline: "Offline",
|
||||
running: "Working",
|
||||
"session-open": "Waiting for you",
|
||||
ready: "Waiting for you",
|
||||
"orchestration-ready": "Waiting for you",
|
||||
"session-open": "Agent shell open",
|
||||
ready: "Ready for next step",
|
||||
"orchestration-ready": "Ready for next step",
|
||||
closing: "Closing",
|
||||
closed: "Completed",
|
||||
idle: "Not running",
|
||||
@@ -398,8 +406,10 @@ export function buildProjectOperationsSnapshot(
|
||||
? "closing"
|
||||
: display.isClosed
|
||||
? "completed"
|
||||
: display.isReady || display.isOrchestrationReady || display.isSessionOpen
|
||||
: display.isReady || display.isOrchestrationReady
|
||||
? "waiting_for_user"
|
||||
: display.isSessionOpen
|
||||
? "open_idle"
|
||||
: "not_running";
|
||||
const attention = attentionScore(project);
|
||||
const handoffAt = project.session?.mtime ?? null;
|
||||
@@ -410,7 +420,18 @@ export function buildProjectOperationsSnapshot(
|
||||
: project.session?.done?.trim()
|
||||
? project.session.done.trim()
|
||||
: null;
|
||||
const liveObserved = runtimeStateKnown && (display.isRunning || display.isSessionOpen || display.tabOpen);
|
||||
const liveObserved = runtimeStateKnown && (display.isRunning || display.isReady || display.isOrchestrationReady || display.isSessionOpen || display.tabOpen);
|
||||
const liveEvidenceLabel = display.isRunning
|
||||
? "Live agent process detected"
|
||||
: display.isReady
|
||||
? "Agent signaled ready on connected computer"
|
||||
: display.isOrchestrationReady
|
||||
? "Last run completed"
|
||||
: display.isSessionOpen
|
||||
? "Agent shell open; no active task detected"
|
||||
: display.tabOpen
|
||||
? "Workspace tab open"
|
||||
: "No live observation";
|
||||
|
||||
return {
|
||||
project,
|
||||
@@ -419,7 +440,7 @@ export function buildProjectOperationsSnapshot(
|
||||
evidenceLabel: !runtimeStateKnown
|
||||
? "Live status unavailable"
|
||||
: liveObserved
|
||||
? "Observed on connected computer"
|
||||
? liveEvidenceLabel
|
||||
: handoffAt
|
||||
? "Saved agent context"
|
||||
: "No live observation",
|
||||
@@ -481,11 +502,7 @@ export function buildControlPageState(
|
||||
const state = getProjectDisplayState(project, data.zellijTabs, nowS, false, runtimeStateKnown);
|
||||
return state.isReady || state.isOrchestrationReady;
|
||||
}).length;
|
||||
const openTabCount = data.projects.filter((project) =>
|
||||
data.zellijTabs.some(
|
||||
(tab) => tab.toLowerCase() === (project.liveTab ?? project.tab).toLowerCase(),
|
||||
),
|
||||
).length;
|
||||
const openTabCount = data.projects.filter((project) => isProjectTabOpen(project, data.zellijTabs)).length;
|
||||
const controlProjectCount = data.inventory.controlProjectCount ?? 0;
|
||||
const idleCount = data.projects.filter((project) => {
|
||||
const state = getProjectDisplayState(project, data.zellijTabs, nowS, false, runtimeStateKnown);
|
||||
|
||||
@@ -131,6 +131,12 @@ export function resolveEffectiveTab(canonical: string, activeTabs: string[]): st
|
||||
const findAlive = (name: string) => activeTabs.find((t) => t.toLowerCase() === name.toLowerCase());
|
||||
const liveMatch = findAlive(canonical);
|
||||
if (liveMatch) return liveMatch;
|
||||
const lower = canonical.toLowerCase();
|
||||
const suffixedMatch = activeTabs.find((tab) => {
|
||||
const active = tab.toLowerCase();
|
||||
return active.startsWith(`${lower} `) || active.startsWith(`${lower}-`);
|
||||
});
|
||||
if (suffixedMatch) return suffixedMatch;
|
||||
// Canonical not open; try a conf alias pointing to the same directory
|
||||
const all = parseProjectsConf();
|
||||
const canonicalDir = all.find((p) => p.tab.toLowerCase() === canonical.toLowerCase())?.dir;
|
||||
|
||||
Reference in new issue
Block a user