Accept story 38: Auto-Open Project on Server Startup
Server detects .story_kit/ in cwd or parent directories at startup and automatically opens the project. MCP tools work immediately without manual project-open step. Falls back to cwd when no .story_kit/ found. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
name: Auto-Open Project on Server Startup
|
name: Auto-Open Project on Server Startup
|
||||||
test_plan: pending
|
test_plan: approved
|
||||||
---
|
---
|
||||||
|
|
||||||
# Story 38: Auto-Open Project on Server Startup
|
# Story 38: Auto-Open Project on Server Startup
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { render, screen, waitFor } from "@testing-library/react";
|
import { render, screen, waitFor } from "@testing-library/react";
|
||||||
import userEvent from "@testing-library/user-event";
|
import userEvent from "@testing-library/user-event";
|
||||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import type { AgentInfo, AgentConfigInfo } from "../api/agents";
|
import type { AgentConfigInfo, AgentInfo } from "../api/agents";
|
||||||
import { agentsApi } from "../api/agents";
|
import { agentsApi } from "../api/agents";
|
||||||
|
|
||||||
vi.mock("../api/agents", () => {
|
vi.mock("../api/agents", () => {
|
||||||
@@ -147,9 +147,7 @@ describe("AgentPanel diff command", () => {
|
|||||||
await userEvent.click(expandButton);
|
await userEvent.click(expandButton);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
await screen.findByText(
|
await screen.findByText('cd "/tmp/wt" && git difftool develop...HEAD'),
|
||||||
'cd "/tmp/wt" && git difftool develop...HEAD',
|
|
||||||
),
|
|
||||||
).toBeInTheDocument();
|
).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -178,9 +176,7 @@ describe("AgentPanel diff command", () => {
|
|||||||
await userEvent.click(expandButton);
|
await userEvent.click(expandButton);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
await screen.findByText(
|
await screen.findByText('cd "/tmp/wt" && git difftool master...HEAD'),
|
||||||
'cd "/tmp/wt" && git difftool master...HEAD',
|
|
||||||
),
|
|
||||||
).toBeInTheDocument();
|
).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -108,7 +108,10 @@ function agentKey(storyId: string, agentName: string): string {
|
|||||||
function DiffCommand({
|
function DiffCommand({
|
||||||
worktreePath,
|
worktreePath,
|
||||||
baseBranch,
|
baseBranch,
|
||||||
}: { worktreePath: string; baseBranch: string }) {
|
}: {
|
||||||
|
worktreePath: string;
|
||||||
|
baseBranch: string;
|
||||||
|
}) {
|
||||||
const [copied, setCopied] = useState(false);
|
const [copied, setCopied] = useState(false);
|
||||||
const command = `cd "${worktreePath}" && git difftool ${baseBranch}...HEAD`;
|
const command = `cd "${worktreePath}" && git difftool ${baseBranch}...HEAD`;
|
||||||
|
|
||||||
@@ -652,7 +655,8 @@ export function AgentPanel({ stories }: AgentPanelProps) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Empty state when expanded with no agents */}
|
{/* Empty state when expanded with no agents */}
|
||||||
{expandedKey === story.story_id && storyAgentEntries.length === 0 && (
|
{expandedKey === story.story_id &&
|
||||||
|
storyAgentEntries.length === 0 && (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
borderTop: "1px solid #2a2a2a",
|
borderTop: "1px solid #2a2a2a",
|
||||||
|
|||||||
@@ -487,10 +487,13 @@ describe("Chat review panel", () => {
|
|||||||
render(<Chat projectPath="/tmp/project" onCloseProject={vi.fn()} />);
|
render(<Chat projectPath="/tmp/project" onCloseProject={vi.fn()} />);
|
||||||
|
|
||||||
expect(await screen.findByText("Upcoming Stories")).toBeInTheDocument();
|
expect(await screen.findByText("Upcoming Stories")).toBeInTheDocument();
|
||||||
expect(
|
// Both AgentPanel and ReviewPanel display story names, so multiple elements are expected
|
||||||
await screen.findByText("View Upcoming Stories"),
|
const storyNameElements = await screen.findAllByText(
|
||||||
).toBeInTheDocument();
|
"View Upcoming Stories",
|
||||||
expect(await screen.findByText("32_worktree")).toBeInTheDocument();
|
);
|
||||||
|
expect(storyNameElements.length).toBeGreaterThan(0);
|
||||||
|
const worktreeElements = await screen.findAllByText("32_worktree");
|
||||||
|
expect(worktreeElements.length).toBeGreaterThan(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("collect coverage button triggers collection and refreshes gate", async () => {
|
it("collect coverage button triggers collection and refreshes gate", async () => {
|
||||||
|
|||||||
@@ -41,14 +41,49 @@ fn remove_port_file(path: &Path) {
|
|||||||
let _ = std::fs::remove_file(path);
|
let _ = std::fs::remove_file(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Walk from `start` up through parent directories, returning the first
|
||||||
|
/// directory that contains a `.story_kit/` subdirectory, or `None`.
|
||||||
|
fn find_story_kit_root(start: &Path) -> Option<PathBuf> {
|
||||||
|
let mut current = start.to_path_buf();
|
||||||
|
loop {
|
||||||
|
if current.join(".story_kit").is_dir() {
|
||||||
|
return Some(current);
|
||||||
|
}
|
||||||
|
if !current.pop() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), std::io::Error> {
|
async fn main() -> Result<(), std::io::Error> {
|
||||||
let app_state = Arc::new(SessionState::default());
|
let app_state = Arc::new(SessionState::default());
|
||||||
let cwd = std::env::current_dir().unwrap_or_else(|_| PathBuf::from("."));
|
let cwd = std::env::current_dir().unwrap_or_else(|_| PathBuf::from("."));
|
||||||
*app_state.project_root.lock().unwrap() = Some(cwd.clone());
|
|
||||||
let store = Arc::new(
|
let store = Arc::new(
|
||||||
JsonFileStore::from_path(PathBuf::from("store.json")).map_err(std::io::Error::other)?,
|
JsonFileStore::from_path(PathBuf::from("store.json")).map_err(std::io::Error::other)?,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Auto-detect a .story_kit/ project in cwd or parent directories.
|
||||||
|
if let Some(project_root) = find_story_kit_root(&cwd) {
|
||||||
|
io::fs::open_project(
|
||||||
|
project_root.to_string_lossy().to_string(),
|
||||||
|
&app_state,
|
||||||
|
store.as_ref(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap_or_else(|e| {
|
||||||
|
eprintln!("Warning: failed to auto-open project at {project_root:?}: {e}");
|
||||||
|
project_root.to_string_lossy().to_string()
|
||||||
|
});
|
||||||
|
|
||||||
|
// Validate agent config for the detected project root.
|
||||||
|
config::ProjectConfig::load(&project_root)
|
||||||
|
.unwrap_or_else(|e| panic!("Invalid project.toml: {e}"));
|
||||||
|
} else {
|
||||||
|
// No .story_kit/ found — fall back to cwd so existing behaviour is preserved.
|
||||||
|
*app_state.project_root.lock().unwrap() = Some(cwd.clone());
|
||||||
|
}
|
||||||
|
|
||||||
let workflow = Arc::new(std::sync::Mutex::new(WorkflowState::default()));
|
let workflow = Arc::new(std::sync::Mutex::new(WorkflowState::default()));
|
||||||
let port = resolve_port();
|
let port = resolve_port();
|
||||||
let agents = Arc::new(AgentPool::new(port));
|
let agents = Arc::new(AgentPool::new(port));
|
||||||
@@ -70,10 +105,6 @@ async fn main() -> Result<(), std::io::Error> {
|
|||||||
println!("\x1b[96;1mFrontend:\x1b[0m \x1b[94mhttp://{addr}\x1b[0m");
|
println!("\x1b[96;1mFrontend:\x1b[0m \x1b[94mhttp://{addr}\x1b[0m");
|
||||||
println!("\x1b[92;1mOpenAPI Docs:\x1b[0m \x1b[94mhttp://{addr}/docs\x1b[0m");
|
println!("\x1b[92;1mOpenAPI Docs:\x1b[0m \x1b[94mhttp://{addr}/docs\x1b[0m");
|
||||||
|
|
||||||
// Validate agent config at startup — panic on invalid project.toml.
|
|
||||||
config::ProjectConfig::load(&cwd)
|
|
||||||
.unwrap_or_else(|e| panic!("Invalid project.toml: {e}"));
|
|
||||||
|
|
||||||
let port_file = write_port_file(&cwd, port);
|
let port_file = write_port_file(&cwd, port);
|
||||||
|
|
||||||
let result = Server::new(TcpListener::bind(&addr)).run(app).await;
|
let result = Server::new(TcpListener::bind(&addr)).run(app).await;
|
||||||
@@ -136,4 +167,45 @@ name = "coder"
|
|||||||
remove_port_file(&path);
|
remove_port_file(&path);
|
||||||
assert!(!path.exists());
|
assert!(!path.exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn find_story_kit_root_returns_cwd_when_story_kit_in_cwd() {
|
||||||
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
std::fs::create_dir_all(tmp.path().join(".story_kit")).unwrap();
|
||||||
|
|
||||||
|
let result = find_story_kit_root(tmp.path());
|
||||||
|
assert_eq!(result, Some(tmp.path().to_path_buf()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn find_story_kit_root_returns_parent_when_story_kit_in_parent() {
|
||||||
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
std::fs::create_dir_all(tmp.path().join(".story_kit")).unwrap();
|
||||||
|
let child = tmp.path().join("subdir").join("nested");
|
||||||
|
std::fs::create_dir_all(&child).unwrap();
|
||||||
|
|
||||||
|
let result = find_story_kit_root(&child);
|
||||||
|
assert_eq!(result, Some(tmp.path().to_path_buf()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn find_story_kit_root_returns_none_when_no_story_kit() {
|
||||||
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
// No .story_kit/ created
|
||||||
|
|
||||||
|
let result = find_story_kit_root(tmp.path());
|
||||||
|
assert_eq!(result, None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn find_story_kit_root_prefers_nearest_ancestor() {
|
||||||
|
// If both cwd and a parent have .story_kit/, return cwd (nearest).
|
||||||
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
std::fs::create_dir_all(tmp.path().join(".story_kit")).unwrap();
|
||||||
|
let child = tmp.path().join("inner");
|
||||||
|
std::fs::create_dir_all(child.join(".story_kit")).unwrap();
|
||||||
|
|
||||||
|
let result = find_story_kit_root(&child);
|
||||||
|
assert_eq!(result, Some(child));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user