Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ and listed with their assets on the

### Added

- **`devstack lane start`, `stop` and `reset` take the lane of the worktree
they run in.** In a lane's worktree, `devstack up` found the lane by
itself, while `devstack lane stop` refused without its name, and an agent
finishing its work had to work out the name first. Without a name, the
three now take the lane whose worktree the command runs in (from any
folder of it), and so does the MCP tool `lane_stop` without `lane`. In
the main working tree, or outside a worktree, they ask for the name as
before.

### Added

- **`devstack init` sets `PYTHONUTF8 = "1"` for Python apps.** On Windows a
native Python process opens text files in the ANSI code page (cp1252)
unless the code passes `encoding=`, while the same code in a container
Expand Down
27 changes: 24 additions & 3 deletions crates/devstack/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2184,9 +2184,13 @@ pub fn lane_start(
/// daemon's list; `None` in the main working tree, or without a daemon.
pub fn worktree_lane(stack_file: &Path) -> Option<String> {
let c = Client::probe(&state_dir(stack_file).ok()?).ok().flatten()?;
let wt = worktree()?;
let lanes: Vec<Value> = serde_json::from_str(&c.get("/v1/lanes").ok()?).ok()?;
let me = devstack_proc::long_path(&wt.path);
lane_at(&c, &worktree()?.path).ok()
}

/// The name of the lane whose worktree is `path`, by the daemon's list.
fn lane_at(c: &Client, path: &Path) -> Result<String> {
let lanes: Vec<Value> = serde_json::from_str(&c.get("/v1/lanes")?)?;
let me = devstack_proc::long_path(path);
lanes
.iter()
.find(|l| {
Expand All @@ -2195,6 +2199,23 @@ pub fn worktree_lane(stack_file: &Path) -> Option<String> {
.is_some_and(|p| same_dir(&devstack_proc::long_path(Path::new(p)), &me))
})
.and_then(|l| l["name"].as_str().map(str::to_string))
.ok_or_else(|| anyhow!("the daemon knows no lane at {}", path.display()))
}

/// The lane of the worktree the CLI runs in, for `devstack lane` without a
/// name (#476): an error in the main working tree or outside a worktree.
/// With `start`, the daemon is started to ask it, as `up` does.
pub fn lane_here(stack_file: &Path, start: bool) -> Result<String> {
let state = state_dir(stack_file)?;
let Some(wt) = worktree() else {
bail!("this is not a lane's worktree");
};
let c = if start {
ensure_daemon(&daemon_file(stack_file), &state)?
} else {
need(&state)?
};
lane_at(&c, &wt.path)
}

/// In the worktree of a lane on a node, for `status`: what `prepare` makes,
Expand Down
21 changes: 18 additions & 3 deletions crates/devstack/src/dispatch/lane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ pub(crate) fn run(file: &Path, action: LaneAction) -> Result<()> {
on,
profile,
run,
} => client::lane_start(file, &name, on.as_deref(), profile.as_deref(), run),
LaneAction::Stop { name } => client::lane_stop(file, &name),
LaneAction::Reset { name } => client::lane_reset(file, &name),
} => {
let name = named(file, name, "start", true)?;
client::lane_start(file, &name, on.as_deref(), profile.as_deref(), run)
}
LaneAction::Stop { name } => client::lane_stop(file, &named(file, name, "stop", false)?),
LaneAction::Reset { name } => client::lane_reset(file, &named(file, name, "reset", false)?),
LaneAction::Prune {
older_than,
dry_run,
Expand All @@ -23,3 +26,15 @@ pub(crate) fn run(file: &Path, action: LaneAction) -> Result<()> {
LaneAction::Share { name, with } => client::lane_share(file, &name, &with),
}
}

/// The lane named, or without a name the lane of the worktree the command
/// runs in, as `devstack up` there finds it (#476). `start` brings the
/// daemon up to ask it; the others need it running anyway.
fn named(file: &Path, name: Option<String>, action: &str, start: bool) -> Result<String> {
match name {
Some(n) => Ok(n),
None => client::lane_here(file, start).map_err(|e| {
anyhow::anyhow!("{e}; name it: `devstack lane {action} <NAME>` (`devstack lane list`)")
}),
}
}
33 changes: 27 additions & 6 deletions crates/devstack/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,10 @@ enum LaneAction {
List,
/// Start a lane (its name or branch, see `lane list`) from anywhere in
/// the repository, as `devstack up` in its worktree does: its own ports
/// and containers, beside the main tree.
/// and containers, beside the main tree. Without a name: the lane of
/// the worktree it runs in.
Start {
name: String,
name: Option<String>,
/// Run it on this node of the pool (its name or member id), or
/// `pool` to let the coordinator choose (ADR-0025).
#[arg(long, value_name = "NODE")]
Expand All @@ -570,12 +571,13 @@ enum LaneAction {
},
/// Stop a lane: its services stop and it is no longer started (its
/// builds stay). The worktree is git's: devstack never creates or removes
/// one.
Stop { name: String },
/// one. Without a name: the lane of the worktree it runs in.
Stop { name: Option<String> },
/// Throw a stopped lane's data away (ADR-0038): its containers and
/// volumes here and on the nodes it ran on. Its next start is a fresh
/// one, seeded again; its worktree and builds stay.
Reset { name: String },
/// one, seeded again; its worktree and builds stay. Without a name: the
/// lane of the worktree it runs in.
Reset { name: Option<String> },
/// Remove what this repository's lanes leave behind: on this machine
/// the containers and volumes of lanes whose worktree is gone, on the
/// pool's nodes this machine's kept lanes of this repository that are
Expand Down Expand Up @@ -1276,6 +1278,25 @@ mod tests {

#[test]
fn lane_pool_and_node_subcommands() {
// In a lane's worktree the name may be left out (#476).
for action in ["start", "stop", "reset"] {
let cli = parse(&["lane", action]);
assert!(
matches!(
cli.cmd,
Cmd::Lane {
action: LaneAction::Start { name: None, .. }
| LaneAction::Stop { name: None }
| LaneAction::Reset { name: None }
}
),
"{action}"
);
}
assert!(matches!(
parse(&["lane", "stop", "feature"]).cmd,
Cmd::Lane { action: LaneAction::Stop { name: Some(n) } } if n == "feature"
));
assert!(matches!(
parse(&["lane", "move", "feature", "--to", "local"]).cmd,
Cmd::Lane { action: LaneAction::Move { name, to } } if name == "feature" && to == "local"
Expand Down
13 changes: 10 additions & 3 deletions crates/devstack/src/mcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,9 @@ pub fn tools() -> Vec<Value> {
"lane_stop",
"Stop a started lane: its services stop, its builds and containers' data stay; `lane_start` starts it again. Not the lane serving the main ports (`promote_lane` main first). POST /v1/lanes/{lane}/stop.",
json!({
"lane": { "type": "string", "description": "The lane's name (see `lanes`)" },
"lane": { "type": "string", "description": "The lane's name (see `lanes`). Without it: the lane of the worktree this server runs in" },
}),
&["lane"],
&[],
false,
),
tool(
Expand Down Expand Up @@ -973,7 +973,14 @@ fn call(name: &str, args: &Value, file: &Path) -> Result<String> {
}
}
"lane_stop" => {
let lane = name_arg(args, "lane")?;
// Without a name, the lane of this worktree, as the CLI (#476).
let here;
let lane = if args.get("lane").is_some_and(|l| !l.is_null()) {
name_arg(args, "lane")?
} else {
here = client::lane_here(file, false)?;
here.as_str()
};
let c = client::main_client(file)?;
let (status, text) = c.call_raw("POST", &format!("/v1/lanes/{lane}/stop"), None)?;
if status >= 400 {
Expand Down
3 changes: 2 additions & 1 deletion docs/stack-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,8 @@ stop the lane first: see `prepare`). Ignored files are not in the snapshot:
`devstack lane stop <name>` stops a lane (its builds stay, the worktree
too); `devstack lane reset <name>` throws a stopped lane's data away (its
containers and volumes, here and on the nodes it ran on), so it starts
fresh; `devstack lane prune [--older-than 7d] [--dry-run]` removes what
fresh. In a lane's worktree, `start`, `stop` and `reset` take that lane
without a name; `devstack lane prune [--older-than 7d] [--dry-run]` removes what
lanes whose worktree is gone left behind, here and on the pool's nodes
(ADR-0038); with `--older-than`, also entries of the store of `prepare`
that no copy used for as long (ADR-0062).
Expand Down
2 changes: 1 addition & 1 deletion skills/devstack/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Run from anywhere in the repository: without `-f`, devstack looks for `devstack.
| `devstack up` refuses: "the stack `<other>` … runs on <ports>" | another repository's stack on this machine runs on the same ports. Nothing started. Ask the user, then `devstack up --shift auto` (MCP `up` with `shift: "auto"`): this stack runs on its ports + 1000 (2000, ...) on this machine, services, containers and links alike, its data unchanged, and keeps the shift until `devstack up --shift none`. Ports written into app config outside devstack's placeholders do not move. A stopped stack on the same ports only warns while they are free. `devstack status` shows `shifted +1000` |
| `devstack up` refuses: "the containers of the stack `<other>` … hold <ports>, though its daemon does not run" | Docker started that stack's containers again (their restart policy) while its daemon stayed down. Nothing started. Ask the user, then `devstack down` in that stack's repository: its containers go, its volumes and data stay. Or shift this stack as above. "another program holds <ports>": find it with `Get-NetTCPConnection -LocalPort <p>` (Windows) or `lsof -nP -iTCP:<p> -sTCP:LISTEN` |
| `devstack up` in a `git worktree` | starts that worktree's **lane** (every worktree is one) in the main tree's daemon: its own builds, ports moved by +100 (+200, ...), its own containers (a Compose project per lane, ports moved alike; the deprecated `shared` services come from the main tree), no background workers (`--workers` turns them on; `--force` skips the memory check). Every command in the worktree then acts on the lane (`devstack lane list` shows all) |
| `git worktree add <path> -b <branch>` | a new worktree is a lane at once, not started (devstack never creates or removes worktrees; use git or your tool); tell the user its dashboard page (`devstack ui --link` in it). A lane runs from a copy of its worktree, so removing the worktree stops the lane and takes its state along. `devstack lane stop <name>` stops a lane and keeps the worktree. **When the lane links directories into its worktree** (`devstack lane list`: `linked`, from `prepare.link`), run `devstack lane stop <name>` before `git worktree remove`: on Windows Git follows the junction and empties the lane's copy, or leaves the worktree behind with the junction in it; the stop removes the links. Without links the remove works while the lane runs |
| `git worktree add <path> -b <branch>` | a new worktree is a lane at once, not started (devstack never creates or removes worktrees; use git or your tool); tell the user its dashboard page (`devstack ui --link` in it). A lane runs from a copy of its worktree, so removing the worktree stops the lane and takes its state along. `devstack lane stop <name>` stops a lane and keeps the worktree; in the lane's own worktree `devstack lane stop` (likewise `lane start`, `lane reset`) needs no name. **When the lane links directories into its worktree** (`devstack lane list`: `linked`, from `prepare.link`), run `devstack lane stop <name>` before `git worktree remove`: on Windows Git follows the junction and empties the lane's copy, or leaves the worktree behind with the junction in it; the stop removes the links. Without links the remove works while the lane runs |
| a directory in a worktree that `prepare` links (`node_modules`, see `devstack lane list`: `linked`) | it is **the lane's copy**, not the worktree's own: on Windows a junction, which looks like a folder. Do not reinstall, delete or clean it there (`npm ci`, `rm -rf`, `git clean -x`, an IDE's "delete node_modules"): that empties what the lane runs from (for a lane on a node, its copy from the store), and a running dev server then fails. To install your own, ask the user, then stop the lane (`devstack lane stop <name>` removes the link) or remove only the link (`cmd /c rmdir <dir>` on Windows, without `/s`; `rm <dir>` elsewhere, no trailing slash), then install. devstack prepares a copy emptied this way again (a notice says so), but the lane's dev server fails until then |
| `devstack lane start <name> [--on <node>]` | start a lane from the main tree (or anywhere in the repository), as `devstack up` in its worktree does; `status` in the main tree lists the lanes in one line. **To run another branch or commit beside the main stack** (an end-to-end run against a given commit, a review): `git worktree add <dir> <commit>`, `devstack lane start <name>` (its ports are the main ports plus its offset, `devstack lane list`), test against those, `devstack lane stop <name>`, `git worktree remove <dir>`. A commit without a stack file of its own runs with the main tree's. **For an acceptance run** use the stack file's profile if it has one (`status` lists none; `[profiles]` in the file): `devstack lane start <name> --profile <p> --run` starts the lane as the profile says (a build instead of a dev server, workers, fresh data, the suite's env) and runs its suite command. A worktree another tool or script created is a lane too: starting it gives its own ports, containers and database without building a separate environment |
| `devstack lane reset <name>` / `devstack lane prune [--older-than 7d] [--dry-run]` | throw a stopped lane's data away (it starts fresh, seeded again); remove what lanes whose worktree is gone left behind, here and on the pool's nodes. A lane on a node keeps its data there between starts. Ask the user before either: data goes |
Expand Down