2026-02-19 17:58:53 +00:00
|
|
|
import * as React from "react";
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
import type {
|
|
|
|
|
AgentConfigInfo,
|
|
|
|
|
AgentEvent,
|
|
|
|
|
AgentStatusValue,
|
|
|
|
|
} from "../api/agents";
|
2026-02-19 17:58:53 +00:00
|
|
|
import { agentsApi, subscribeAgentStream } from "../api/agents";
|
2026-02-20 14:42:41 +00:00
|
|
|
import { settingsApi } from "../api/settings";
|
2026-02-23 15:04:10 +00:00
|
|
|
import { useLozengeFly } from "./LozengeFlyContext";
|
2026-02-19 17:58:53 +00:00
|
|
|
|
|
|
|
|
const { useCallback, useEffect, useRef, useState } = React;
|
|
|
|
|
|
|
|
|
|
interface AgentState {
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
agentName: string;
|
2026-02-19 17:58:53 +00:00
|
|
|
status: AgentStatusValue;
|
|
|
|
|
log: string[];
|
|
|
|
|
sessionId: string | null;
|
|
|
|
|
worktreePath: string | null;
|
2026-02-20 12:48:50 +00:00
|
|
|
baseBranch: string | null;
|
2026-02-23 14:27:15 +00:00
|
|
|
terminalAt: number | null;
|
2026-02-19 17:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const formatTimestamp = (value: Date | null): string => {
|
|
|
|
|
if (!value) return "";
|
|
|
|
|
return value.toLocaleTimeString([], {
|
|
|
|
|
hour: "2-digit",
|
|
|
|
|
minute: "2-digit",
|
|
|
|
|
second: "2-digit",
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-23 21:34:59 +00:00
|
|
|
function RosterBadge({ agent }: { agent: AgentConfigInfo }) {
|
2026-02-23 15:04:10 +00:00
|
|
|
const { registerRosterEl } = useLozengeFly();
|
|
|
|
|
const badgeRef = useRef<HTMLSpanElement>(null);
|
2026-02-23 13:23:35 +00:00
|
|
|
|
2026-02-23 15:04:10 +00:00
|
|
|
// Register this element so fly animations know where to start/end
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const el = badgeRef.current;
|
|
|
|
|
if (el) registerRosterEl(agent.name, el);
|
|
|
|
|
return () => registerRosterEl(agent.name, null);
|
|
|
|
|
}, [agent.name, registerRosterEl]);
|
|
|
|
|
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
return (
|
|
|
|
|
<span
|
2026-02-23 15:04:10 +00:00
|
|
|
ref={badgeRef}
|
|
|
|
|
data-testid={`roster-badge-${agent.name}`}
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
style={{
|
|
|
|
|
display: "inline-flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
gap: "4px",
|
|
|
|
|
padding: "2px 8px",
|
|
|
|
|
borderRadius: "6px",
|
|
|
|
|
fontSize: "0.7em",
|
2026-02-23 21:34:59 +00:00
|
|
|
background: "#aaaaaa18",
|
|
|
|
|
color: "#aaa",
|
|
|
|
|
border: "1px solid #aaaaaa44",
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
}}
|
2026-02-23 21:34:59 +00:00
|
|
|
title={`${agent.role || agent.name} — available`}
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
>
|
2026-02-23 21:34:59 +00:00
|
|
|
<span
|
|
|
|
|
data-testid={`roster-dot-${agent.name}`}
|
|
|
|
|
style={{
|
|
|
|
|
width: "5px",
|
|
|
|
|
height: "5px",
|
|
|
|
|
borderRadius: "50%",
|
|
|
|
|
background: "#3fb950",
|
|
|
|
|
flexShrink: 0,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<span style={{ fontWeight: 600, color: "#aaa" }}>{agent.name}</span>
|
|
|
|
|
{agent.model && <span style={{ color: "#888" }}>{agent.model}</span>}
|
|
|
|
|
<span style={{ color: "#888", fontStyle: "italic" }}>available</span>
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Build a composite key for tracking agent state. */
|
|
|
|
|
function agentKey(storyId: string, agentName: string): string {
|
|
|
|
|
return `${storyId}:${agentName}`;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 22:58:51 +00:00
|
|
|
interface AgentPanelProps {
|
|
|
|
|
/** Increment this to trigger a re-fetch of the agent roster. */
|
|
|
|
|
configVersion?: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function AgentPanel({ configVersion = 0 }: AgentPanelProps) {
|
2026-02-23 19:52:23 +00:00
|
|
|
const { hiddenRosterAgents } = useLozengeFly();
|
2026-02-19 17:58:53 +00:00
|
|
|
const [agents, setAgents] = useState<Record<string, AgentState>>({});
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
const [roster, setRoster] = useState<AgentConfigInfo[]>([]);
|
2026-02-19 17:58:53 +00:00
|
|
|
const [actionError, setActionError] = useState<string | null>(null);
|
|
|
|
|
const [lastRefresh, setLastRefresh] = useState<Date | null>(null);
|
2026-02-20 14:42:41 +00:00
|
|
|
const [editorCommand, setEditorCommand] = useState<string | null>(null);
|
|
|
|
|
const [editorInput, setEditorInput] = useState<string>("");
|
|
|
|
|
const [editingEditor, setEditingEditor] = useState(false);
|
2026-02-19 17:58:53 +00:00
|
|
|
const cleanupRefs = useRef<Record<string, () => void>>({});
|
|
|
|
|
|
2026-02-23 22:58:51 +00:00
|
|
|
// Re-fetch roster whenever configVersion changes (triggered by agent_config_changed WS event).
|
2026-02-19 17:58:53 +00:00
|
|
|
useEffect(() => {
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
agentsApi
|
|
|
|
|
.getAgentConfig()
|
|
|
|
|
.then(setRoster)
|
|
|
|
|
.catch((err) => console.error("Failed to load agent config:", err));
|
2026-02-23 22:58:51 +00:00
|
|
|
}, [configVersion]);
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
|
2026-02-23 22:58:51 +00:00
|
|
|
// Load existing agents and editor preference on mount
|
|
|
|
|
useEffect(() => {
|
2026-02-19 17:58:53 +00:00
|
|
|
agentsApi
|
|
|
|
|
.listAgents()
|
|
|
|
|
.then((agentList) => {
|
|
|
|
|
const agentMap: Record<string, AgentState> = {};
|
2026-02-23 14:27:15 +00:00
|
|
|
const now = Date.now();
|
2026-02-19 17:58:53 +00:00
|
|
|
for (const a of agentList) {
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
const key = agentKey(a.story_id, a.agent_name);
|
2026-02-23 15:04:10 +00:00
|
|
|
const isTerminal = a.status === "completed" || a.status === "failed";
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
agentMap[key] = {
|
|
|
|
|
agentName: a.agent_name,
|
2026-02-19 17:58:53 +00:00
|
|
|
status: a.status,
|
|
|
|
|
log: [],
|
|
|
|
|
sessionId: a.session_id,
|
|
|
|
|
worktreePath: a.worktree_path,
|
2026-02-20 12:48:50 +00:00
|
|
|
baseBranch: a.base_branch,
|
2026-02-23 14:27:15 +00:00
|
|
|
terminalAt: isTerminal ? now : null,
|
2026-02-19 17:58:53 +00:00
|
|
|
};
|
|
|
|
|
if (a.status === "running" || a.status === "pending") {
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
subscribeToAgent(a.story_id, a.agent_name);
|
2026-02-19 17:58:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
setAgents(agentMap);
|
|
|
|
|
setLastRefresh(new Date());
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => console.error("Failed to load agents:", err));
|
|
|
|
|
|
2026-02-20 14:42:41 +00:00
|
|
|
settingsApi
|
|
|
|
|
.getEditorCommand()
|
|
|
|
|
.then((s) => {
|
|
|
|
|
setEditorCommand(s.editor_command);
|
|
|
|
|
setEditorInput(s.editor_command ?? "");
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => console.error("Failed to load editor command:", err));
|
|
|
|
|
|
2026-02-19 17:58:53 +00:00
|
|
|
return () => {
|
|
|
|
|
for (const cleanup of Object.values(cleanupRefs.current)) {
|
|
|
|
|
cleanup();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, []);
|
|
|
|
|
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
const subscribeToAgent = useCallback((storyId: string, agentName: string) => {
|
|
|
|
|
const key = agentKey(storyId, agentName);
|
|
|
|
|
cleanupRefs.current[key]?.();
|
2026-02-19 17:58:53 +00:00
|
|
|
|
|
|
|
|
const cleanup = subscribeAgentStream(
|
|
|
|
|
storyId,
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
agentName,
|
2026-02-19 17:58:53 +00:00
|
|
|
(event: AgentEvent) => {
|
|
|
|
|
setAgents((prev) => {
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
const current = prev[key] ?? {
|
|
|
|
|
agentName,
|
2026-02-19 17:58:53 +00:00
|
|
|
status: "pending" as AgentStatusValue,
|
|
|
|
|
log: [],
|
|
|
|
|
sessionId: null,
|
|
|
|
|
worktreePath: null,
|
2026-02-20 12:48:50 +00:00
|
|
|
baseBranch: null,
|
2026-02-23 14:27:15 +00:00
|
|
|
terminalAt: null,
|
2026-02-19 17:58:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
switch (event.type) {
|
2026-02-23 14:27:15 +00:00
|
|
|
case "status": {
|
|
|
|
|
const newStatus =
|
|
|
|
|
(event.status as AgentStatusValue) ?? current.status;
|
|
|
|
|
const isTerminal =
|
|
|
|
|
newStatus === "completed" || newStatus === "failed";
|
2026-02-19 17:58:53 +00:00
|
|
|
return {
|
|
|
|
|
...prev,
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
[key]: {
|
2026-02-19 17:58:53 +00:00
|
|
|
...current,
|
2026-02-23 14:27:15 +00:00
|
|
|
status: newStatus,
|
|
|
|
|
terminalAt: isTerminal
|
|
|
|
|
? (current.terminalAt ?? Date.now())
|
|
|
|
|
: current.terminalAt,
|
2026-02-19 17:58:53 +00:00
|
|
|
},
|
|
|
|
|
};
|
2026-02-23 14:27:15 +00:00
|
|
|
}
|
2026-02-19 17:58:53 +00:00
|
|
|
case "output":
|
|
|
|
|
return {
|
|
|
|
|
...prev,
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
[key]: {
|
2026-02-19 17:58:53 +00:00
|
|
|
...current,
|
|
|
|
|
log: [...current.log, event.text ?? ""],
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
case "done":
|
|
|
|
|
return {
|
|
|
|
|
...prev,
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
[key]: {
|
2026-02-19 17:58:53 +00:00
|
|
|
...current,
|
|
|
|
|
status: "completed",
|
|
|
|
|
sessionId: event.session_id ?? current.sessionId,
|
2026-02-23 14:27:15 +00:00
|
|
|
terminalAt: current.terminalAt ?? Date.now(),
|
2026-02-19 17:58:53 +00:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
case "error":
|
|
|
|
|
return {
|
|
|
|
|
...prev,
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
[key]: {
|
2026-02-19 17:58:53 +00:00
|
|
|
...current,
|
|
|
|
|
status: "failed",
|
|
|
|
|
log: [
|
|
|
|
|
...current.log,
|
|
|
|
|
`[ERROR] ${event.message ?? "Unknown error"}`,
|
|
|
|
|
],
|
2026-02-23 14:27:15 +00:00
|
|
|
terminalAt: current.terminalAt ?? Date.now(),
|
2026-02-19 17:58:53 +00:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
default:
|
|
|
|
|
return prev;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
() => {
|
|
|
|
|
// SSE error — agent may not be streaming yet
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
cleanupRefs.current[key] = cleanup;
|
2026-02-19 17:58:53 +00:00
|
|
|
}, []);
|
|
|
|
|
|
2026-02-20 14:42:41 +00:00
|
|
|
const handleSaveEditor = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const trimmed = editorInput.trim() || null;
|
|
|
|
|
const result = await settingsApi.setEditorCommand(trimmed);
|
|
|
|
|
setEditorCommand(result.editor_command);
|
|
|
|
|
setEditorInput(result.editor_command ?? "");
|
|
|
|
|
setEditingEditor(false);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
const message = err instanceof Error ? err.message : String(err);
|
|
|
|
|
setActionError(`Failed to save editor: ${message}`);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-19 17:58:53 +00:00
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
border: "1px solid #333",
|
|
|
|
|
borderRadius: "10px",
|
|
|
|
|
padding: "12px 16px",
|
|
|
|
|
background: "#1f1f1f",
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
gap: "8px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
gap: "12px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
gap: "8px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div style={{ fontWeight: 600 }}>Agents</div>
|
2026-02-24 13:59:10 +00:00
|
|
|
{Object.values(agents).filter((a) => a.status === "running").length >
|
|
|
|
|
0 && (
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
fontSize: "0.75em",
|
|
|
|
|
color: "#777",
|
|
|
|
|
fontFamily: "monospace",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{
|
|
|
|
|
Object.values(agents).filter((a) => a.status === "running")
|
|
|
|
|
.length
|
|
|
|
|
}{" "}
|
|
|
|
|
running
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-02-19 17:58:53 +00:00
|
|
|
</div>
|
|
|
|
|
{lastRefresh && (
|
|
|
|
|
<div style={{ fontSize: "0.7em", color: "#555" }}>
|
|
|
|
|
Loaded {formatTimestamp(lastRefresh)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-02-20 14:42:41 +00:00
|
|
|
{/* Editor preference */}
|
|
|
|
|
<div style={{ display: "flex", alignItems: "center", gap: "6px" }}>
|
|
|
|
|
<span style={{ fontSize: "0.75em", color: "#666" }}>Editor:</span>
|
|
|
|
|
{editingEditor ? (
|
|
|
|
|
<>
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
value={editorInput}
|
|
|
|
|
onChange={(e) => setEditorInput(e.target.value)}
|
|
|
|
|
onKeyDown={(e) => {
|
|
|
|
|
if (e.key === "Enter") handleSaveEditor();
|
|
|
|
|
if (e.key === "Escape") setEditingEditor(false);
|
|
|
|
|
}}
|
|
|
|
|
placeholder="zed, code, cursor..."
|
|
|
|
|
style={{
|
|
|
|
|
fontSize: "0.75em",
|
|
|
|
|
background: "#111",
|
|
|
|
|
border: "1px solid #444",
|
|
|
|
|
borderRadius: "4px",
|
|
|
|
|
color: "#ccc",
|
|
|
|
|
padding: "2px 6px",
|
|
|
|
|
width: "120px",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={handleSaveEditor}
|
|
|
|
|
style={{
|
|
|
|
|
fontSize: "0.7em",
|
|
|
|
|
padding: "2px 8px",
|
|
|
|
|
borderRadius: "4px",
|
|
|
|
|
border: "1px solid #238636",
|
|
|
|
|
background: "#238636",
|
|
|
|
|
color: "#fff",
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Save
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => setEditingEditor(false)}
|
|
|
|
|
style={{
|
|
|
|
|
fontSize: "0.7em",
|
|
|
|
|
padding: "2px 8px",
|
|
|
|
|
borderRadius: "4px",
|
|
|
|
|
border: "1px solid #444",
|
|
|
|
|
background: "none",
|
|
|
|
|
color: "#888",
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Cancel
|
|
|
|
|
</button>
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => setEditingEditor(true)}
|
|
|
|
|
style={{
|
|
|
|
|
fontSize: "0.75em",
|
|
|
|
|
background: "none",
|
|
|
|
|
border: "1px solid #333",
|
|
|
|
|
borderRadius: "4px",
|
|
|
|
|
color: editorCommand ? "#aaa" : "#555",
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
padding: "2px 8px",
|
|
|
|
|
fontFamily: editorCommand ? "monospace" : "inherit",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{editorCommand ?? "Set editor..."}
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-02-23 21:34:59 +00:00
|
|
|
{/* Roster badges — agents always display in idle state here */}
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
{roster.length > 0 && (
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexWrap: "wrap",
|
|
|
|
|
gap: "4px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2026-02-23 13:23:35 +00:00
|
|
|
{roster.map((a) => {
|
2026-02-23 19:52:23 +00:00
|
|
|
const isHidden = hiddenRosterAgents.has(a.name);
|
2026-02-23 13:23:35 +00:00
|
|
|
return (
|
2026-02-23 19:52:23 +00:00
|
|
|
<div
|
|
|
|
|
key={`roster-wrapper-${a.name}`}
|
|
|
|
|
data-testid={`roster-badge-wrapper-${a.name}`}
|
|
|
|
|
style={{
|
|
|
|
|
overflow: "hidden",
|
|
|
|
|
maxWidth: isHidden ? "0" : "300px",
|
|
|
|
|
opacity: isHidden ? 0 : 1,
|
|
|
|
|
transition: "max-width 0.35s ease, opacity 0.2s ease",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2026-02-23 21:34:59 +00:00
|
|
|
<RosterBadge agent={a} />
|
2026-02-23 19:52:23 +00:00
|
|
|
</div>
|
2026-02-23 13:23:35 +00:00
|
|
|
);
|
|
|
|
|
})}
|
Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.
- AgentConfig expanded with structured fields, validated at startup (panics
on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2026-02-19 17:58:53 +00:00
|
|
|
{actionError && (
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
fontSize: "0.85em",
|
|
|
|
|
color: "#ff7b72",
|
|
|
|
|
padding: "4px 8px",
|
|
|
|
|
background: "#ff7b7211",
|
|
|
|
|
borderRadius: "6px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{actionError}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|