mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-18 21:01:19 -08:00
Fix the desktop app's dead terminal, dual-instance hang and bar layout
AI Assisted
This commit is contained in:
1 parent
26013db54f
commit
0de630603b
4 files changed
+30
-26
No files matched your search
@@ -168,6 +168,13 @@ fn sync_agent_env(app: &tauri::AppHandle) {
|
|||||||
agent.set_env(env);
|
agent.set_env(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `on_output` is deliberately not a parameter here: `agent_reattach` already
|
||||||
|
// registered `state.page` when the page mounted (`main()` on the frontend
|
||||||
|
// calls it before this), and that registration must stay the only one. Every
|
||||||
|
// Channel argument Tauri deserializes for an invoke is a fresh wrapper around
|
||||||
|
// the same frontend id; dropping one (as happened here when it replaced the
|
||||||
|
// reattach registration) sends the frontend an "end" message that
|
||||||
|
// unregisters that id for good, breaking all future sends through it.
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn agent_start(
|
fn agent_start(
|
||||||
app: tauri::AppHandle,
|
app: tauri::AppHandle,
|
||||||
@@ -178,11 +185,9 @@ fn agent_start(
|
|||||||
mode: String,
|
mode: String,
|
||||||
cols: u16,
|
cols: u16,
|
||||||
rows: u16,
|
rows: u16,
|
||||||
on_output: Channel<InvokeResponseBody>,
|
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let kind = AgentKind::from_id(&kind).ok_or_else(|| format!("unknown agent: {kind}"))?;
|
let kind = AgentKind::from_id(&kind).ok_or_else(|| format!("unknown agent: {kind}"))?;
|
||||||
let mode = PermissionMode::from_id(&mode).ok_or_else(|| format!("unknown permission mode: {mode}"))?;
|
let mode = PermissionMode::from_id(&mode).ok_or_else(|| format!("unknown permission mode: {mode}"))?;
|
||||||
*state.page.lock().map_err(|e| e.to_string())? = Some(on_output);
|
|
||||||
let agent = agent_for_project(&state)?;
|
let agent = agent_for_project(&state)?;
|
||||||
agent.resize(cols, rows)?;
|
agent.resize(cols, rows)?;
|
||||||
sync_agent_env(&app);
|
sync_agent_env(&app);
|
||||||
@@ -459,15 +464,19 @@ fn pick_project_folder(app: tauri::AppHandle, state: State<'_, AppState>) -> Res
|
|||||||
|
|
||||||
/// Stops the old project's agent and console and clears both from state, so
|
/// Stops the old project's agent and console and clears both from state, so
|
||||||
/// neither `agent_for_project` nor `console_start` can hand either back once
|
/// neither `agent_for_project` nor `console_start` can hand either back once
|
||||||
/// the project has moved on (Task 9.5). The old agent's `Idle` state still
|
/// the project has moved on (Task 9.5). `state.page` is deliberately left
|
||||||
/// reaches the page's current channel here; only after that does this take
|
/// alone: it is the page's own output channel, not the project's, and it must
|
||||||
/// the channel away.
|
/// stay the single live registration for `agentChannel`'s id for the page's
|
||||||
|
/// whole lifetime. Dropping it here (even briefly, to `None`) sends the
|
||||||
|
/// frontend an "end" message that unregisters that id for good — no later
|
||||||
|
/// command can ever re-register the same frontend `Channel` object after
|
||||||
|
/// that, whatever it passes, so a project switch would silently and
|
||||||
|
/// permanently cut the new agent's output off from the page.
|
||||||
fn teardown_project(state: &AppState) -> Result<(), String> {
|
fn teardown_project(state: &AppState) -> Result<(), String> {
|
||||||
if let Some(agent) = current_agent(state) {
|
if let Some(agent) = current_agent(state) {
|
||||||
agent.stop();
|
agent.stop();
|
||||||
}
|
}
|
||||||
*state.agent.lock().map_err(|e| e.to_string())? = None;
|
*state.agent.lock().map_err(|e| e.to_string())? = None;
|
||||||
*state.page.lock().map_err(|e| e.to_string())? = None;
|
|
||||||
if let Ok(mut guard) = state.console.lock() {
|
if let Ok(mut guard) = state.console.lock() {
|
||||||
if let Some(mut sup) = guard.take() {
|
if let Some(mut sup) = guard.take() {
|
||||||
let _ = sup.stop();
|
let _ = sup.stop();
|
||||||
|
|||||||
@@ -18,7 +18,8 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"security": {
|
"security": {
|
||||||
"csp": "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src ipc: http://ipc.localhost; frame-src http://127.0.0.1:*; object-src 'none'; base-uri 'none'"
|
"csp": "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src ipc: http://ipc.localhost; frame-src http://127.0.0.1:*; object-src 'none'; base-uri 'none'",
|
||||||
|
"dangerousDisableAssetCspModification": ["style-src"]
|
||||||
},
|
},
|
||||||
"withGlobalTauri": true
|
"withGlobalTauri": true
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -138,11 +138,7 @@ function applyAgentState(next, { skipReset } = {}) {
|
|||||||
// The agent is back (a fresh generation, running): the restart message stays
|
// The agent is back (a fresh generation, running): the restart message stays
|
||||||
// on screen (restarting() below) until its dashboard page is announced.
|
// on screen (restarting() below) until its dashboard page is announced.
|
||||||
if (restarting && freshScreen && agent.state === 'running') {
|
if (restarting && freshScreen && agent.state === 'running') {
|
||||||
terminal.write('
|
terminal.write('\r\n\r\n[Fresh agent started. Waiting for the dashboard...]\r\n\r\n');
|
||||||
|
|
||||||
[Fresh agent started. Waiting for the dashboard...]
|
|
||||||
|
|
||||||
');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (agent.state === 'ended') {
|
if (agent.state === 'ended') {
|
||||||
@@ -330,7 +326,7 @@ async function startAgent(event) {
|
|||||||
showState('Waiting for the agent to open the dashboard');
|
showState('Waiting for the agent to open the dashboard');
|
||||||
const { cols, rows } = terminal.size();
|
const { cols, rows } = terminal.size();
|
||||||
try {
|
try {
|
||||||
await invoke('agent_start', { kind, model, effort, mode, cols, rows, onOutput: agentChannel });
|
await invoke('agent_start', { kind, model, effort, mode, cols, rows });
|
||||||
terminal.focus();
|
terminal.focus();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
agentStatusEl.textContent = `Could not start the agent: ${error}`;
|
agentStatusEl.textContent = `Could not start the agent: ${error}`;
|
||||||
@@ -774,7 +770,6 @@ async function autoStartAgent(state) {
|
|||||||
mode: 'bypass',
|
mode: 'bypass',
|
||||||
cols,
|
cols,
|
||||||
rows,
|
rows,
|
||||||
onOutput: agentChannel,
|
|
||||||
});
|
});
|
||||||
terminal.focus();
|
terminal.focus();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
+11
-12
@@ -10,24 +10,24 @@
|
|||||||
html, body { margin: 0; height: 100%; font-family: system-ui, sans-serif; background: #1e1e1e; color: #ddd; }
|
html, body { margin: 0; height: 100%; font-family: system-ui, sans-serif; background: #1e1e1e; color: #ddd; }
|
||||||
body { display: flex; flex-direction: column; overflow: hidden; }
|
body { display: flex; flex-direction: column; overflow: hidden; }
|
||||||
|
|
||||||
#bar { flex: none; display: flex; flex-direction: column; border-bottom: 1px solid #444; }
|
#bar { flex: none; border-bottom: 1px solid #444; }
|
||||||
#bar-top { height: 32px; flex: none; display: flex; align-items: center; gap: 12px; padding: 0 10px; white-space: nowrap; overflow-x: auto; overflow-y: hidden; }
|
#bar-row { height: 34px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 10px; font-size: 12px; white-space: nowrap; overflow-x: auto; overflow-y: hidden; }
|
||||||
#bar-status { flex: none; display: flex; align-items: center; gap: 12px; padding: 3px 10px; font-size: 12px; white-space: nowrap; overflow-x: auto; overflow-y: hidden; border-top: 1px solid #2a2a2a; }
|
#bar-sep { flex: none; align-self: stretch; width: 1px; margin: 8px 0; background: #3a3a3a; }
|
||||||
#title { font-weight: 600; }
|
#title { font-weight: 600; font-size: 13px; }
|
||||||
#project-dir { color: #9ab; overflow: hidden; text-overflow: ellipsis; min-width: 0; max-width: 40%; }
|
#project-dir { color: #9ab; overflow: hidden; text-overflow: ellipsis; min-width: 0; max-width: 220px; }
|
||||||
#current-page { color: #8c8; }
|
#current-page { color: #8c8; }
|
||||||
#current-page:not(:empty)::before { content: "page: "; color: #666; }
|
#current-page:not(:empty)::before { content: "page: "; color: #666; }
|
||||||
#agent-name { color: #9ab; }
|
#agent-name { color: #9ab; }
|
||||||
#agent-name:not(:empty)::before { content: "agent: "; color: #666; }
|
#agent-name:not(:empty)::before { content: "agent: "; color: #666; }
|
||||||
#console-status, #agent-status { color: #d7ba7d; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
|
#console-status, #agent-status { color: #d7ba7d; overflow: hidden; text-overflow: ellipsis; min-width: 0; max-width: 260px; }
|
||||||
#agent-restart[hidden], #change-agent[hidden] { display: none; }
|
#agent-restart[hidden], #change-agent[hidden] { display: none; }
|
||||||
.bar-slot { flex: none; }
|
.bar-slot { flex: none; }
|
||||||
#permissions-note { color: #888; }
|
#permissions-note { color: #888; }
|
||||||
#context-nudge { display: flex; align-items: center; gap: 6px; color: #d7ba7d; font-size: 12px; }
|
#context-nudge { display: flex; align-items: center; gap: 6px; color: #d7ba7d; }
|
||||||
#context-nudge[hidden] { display: none; }
|
#context-nudge[hidden] { display: none; }
|
||||||
#version-update { display: flex; align-items: center; gap: 6px; color: #d7ba7d; font-size: 12px; }
|
#version-update { display: flex; align-items: center; gap: 6px; color: #d7ba7d; }
|
||||||
#version-update[hidden], #version-update-button[hidden] { display: none; }
|
#version-update[hidden], #version-update-button[hidden] { display: none; }
|
||||||
#bar-slot-meter { display: flex; align-items: center; gap: 6px; color: #9ab; font-size: 12px; }
|
#bar-slot-meter { display: flex; align-items: center; gap: 6px; color: #9ab; }
|
||||||
#bar-slot-meter:empty { display: none; }
|
#bar-slot-meter:empty { display: none; }
|
||||||
.meter-track { display: inline-block; width: 64px; height: 8px; border: 1px solid #666; border-radius: 2px; overflow: hidden; background: #2a2a2a; }
|
.meter-track { display: inline-block; width: 64px; height: 8px; border: 1px solid #666; border-radius: 2px; overflow: hidden; background: #2a2a2a; }
|
||||||
.meter-track.estimate { border-style: dashed; }
|
.meter-track.estimate { border-style: dashed; }
|
||||||
@@ -127,14 +127,13 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header id="bar">
|
<header id="bar">
|
||||||
<div id="bar-top">
|
<div id="bar-row">
|
||||||
<span id="title">Plan2Code</span>
|
<span id="title">Plan2Code</span>
|
||||||
<span id="project-dir"></span>
|
<span id="project-dir"></span>
|
||||||
<span id="bar-slot-restart" class="bar-slot"><button id="agent-restart" hidden>Restart</button></span>
|
<span id="bar-slot-restart" class="bar-slot"><button id="agent-restart" hidden>Restart</button></span>
|
||||||
<span id="bar-slot-change-agent" class="bar-slot"><button id="change-agent" hidden>Change agent</button></span>
|
<span id="bar-slot-change-agent" class="bar-slot"><button id="change-agent" hidden>Change agent</button></span>
|
||||||
<span id="bar-slot-change-project" class="bar-slot"><button id="change-project">Change project</button></span>
|
<span id="bar-slot-change-project" class="bar-slot"><button id="change-project">Change project</button></span>
|
||||||
</div>
|
<span id="bar-sep" aria-hidden="true"></span>
|
||||||
<div id="bar-status">
|
|
||||||
<span id="current-page" title="The page the agent opened"></span>
|
<span id="current-page" title="The page the agent opened"></span>
|
||||||
<span id="agent-name"></span>
|
<span id="agent-name"></span>
|
||||||
<span id="agent-status" role="status"></span>
|
<span id="agent-status" role="status"></span>
|
||||||
|
|||||||
Reference in new issue
Block a user