8000 Shared paths and lane lookup, one line editor, and remove inherited formats by anvk · Pull Request #8 · anvk/lanes · GitHub
[go: up one dir, main page]

Skip to content
8000 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
1 change: 0 additions & 1 deletion cli/src/bin/lanes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ program

program
.command("commands")
.alias("tabs")
.description("Manage the command lists run for each base's lanes")
.command("update")
.description("Re-fetch each base's command lists from its recorded template and save any changes")
Expand Down
66 changes: 9 additions & 57 deletions cli/src/cli/wizard.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type readline from "node:readline";
import { stdin as input, stdout as output } from "node:process";
import pc from "picocolors";
import { emitKeypresses, escapeCount, isPrintable } from "../ui/tui.js";
import { EscapePressed, readLine } from "../ui/tui.js";

export const NONE = "none";

Expand Down Expand Up @@ -46,7 +44,7 @@ export class Wizard {
return recorded || defaultValue || "";
}

const raw = (await readLine(prompt)).trim();
const raw = (await readLineOrRewind(prompt)).trim();
this.log.push(raw);
return raw || defaultValue || "";
}
Expand Down Expand Up @@ -114,57 +112,11 @@ export class Wizard {
}
}

// A line editor just big enough for answers: type, backspace, ctrl+u to clear, enter
// to submit. Esc rejects with a Rewind, one step per press. Raw mode is what lets a bare
// Esc be seen at all; readline's question() would swallow it.
function readLine(prompt: string): Promise<string> {
return new Promise((resolve, reject) => {
let buffer = "";

function cleanup(): void {
input.off("keypress", onKeypress);
input.setRawMode(false);
input.pause();
output.write("\n");
}

function onKeypress(str: string | undefined, key: readline.Key = {}): void {
if (key.ctrl && key.name === "c") {
cleanup();
process.exit(130);
}
if (key.name === "escape") {
cleanup();
reject(new Rewind(escapeCount(key)));
return;
}
if (key.name === "return" || key.name === "enter") {
cleanup();
resolve(buffer);
return;
}
if (key.name === "backspace") {
if (buffer) {
buffer = [...buffer].slice(0, -1).join("");
output.write("\b \b");
}
return;
}
if (key.ctrl && key.name === "u") {
output.write("\b \b".repeat([...buffer].length));
buffer = "";
return;
}
if (isPrintable(str, key)) {
buffer += str;
output.write(str);
}
}

output.write(prompt);
emitKeypresses();
input.setRawMode(true);
input.resume();
input.on("keypress", onKeypress);
});
// Esc in a prompt goes back that many questions.
async function readLineOrRewind(prompt: string): Promise<string> {
try {
return await readLine(prompt);
} catch (error) {
throw error instanceof EscapePressed ? new Rewind(error.steps) : error;
}
}
56 changes: 5 additions & 51 deletions cli/src/core/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { WARP_PLUGIN_SOURCE, normalizeConfig, parseOpenDocument, resolveBaseCommands } from "./config.js";
import { normalizeConfig, parseOpenDocument, resolveBaseCommands } from "./config.js";
import { setPlugins } from "../plugins/registry.js";
import type { Plugin } from "../plugins/types.js";

Expand Down Expand Up @@ -97,41 +97,6 @@ test("plugins map names to where to install them", () => {
assert.throws(() => normalizeConfig({ plugins: { warp: "" }, bases: [base("api")] }), /git URL or a path/);
});

test("a warpTabs list from before becomes lanes warp tab lines, and says where Warp comes from", () => {
const config = normalizeConfig({
warpTabGroup: true,
bases: [
base("api", {
open: undefined,
warpTabs: [
{ title: "API", path: "server/", color: "RED", setupCommand: "make dev", teardownCommand: "make down" },
{ title: "CLI", path: "." },
{ title: "Claude", path: ".", color: "yellow", command: "claude --continue", teardownCommand: "echo bye" }
],
warpTabsSource: "https://example.com/tabs.json"
})
]
});
const [api] = config.bases;
assert.deepEqual(api.open, [
"lanes warp tab API --path server --color red --setup 'make dev' --group",
"lanes warp tab CLI --group",
"lanes warp tab Claude --color yellow --command 'claude --continue' --group"
]);
assert.deepEqual(api.remove, ["cd server && make down", "echo bye"]);
assert.equal(api.template, "https://example.com/tabs.json");
assert.deepEqual(config.plugins, { warp: WARP_PLUGIN_SOURCE });
assert.equal("warpTabs" in api, false);
assert.equal("warpTabGroup" in config, false);
});

test("old tabs are still validated", () => {
const withTab = (warpTab: Record<string, unknown>) =>
normalizeConfig({ bases: [base("api", { open: undefined, warpTabs: [warpTab] })] });
assert.throws(() => withTab({ title: "", path: "." }), /title/);
assert.throws(() => withTab({ title: "A", path: ".", color: "purple" }), /must be one of/);
});

test("duplicate base names are rejected", () => {
assert.throws(() => normalizeConfig({ bases: [base("api"), base("api")] }), /more than one base named 'api'/);
});
Expand All @@ -152,28 +117,17 @@ test("oldLaneDays must be a positive integer", () => {
assert.throws(() => normalizeConfig({ oldLaneDays: 0, bases: [base("api")] }), /positive integer/);
});

test("a document holds command lists and plugin sources, or the older tab forms", () => {
test("a document holds command lists and plugin sources, or a bare list of open lines", () => {
assert.deepEqual(
parseOpenDocument(JSON.stringify({ open: ["cursor ."], remove: ["make down"], plugins: { tmux: "https://x/t.git" } }), "doc"),
{ open: ["cursor ."], remove: ["make down"], plugins: { tmux: "https://x/t.git" } }
);
assert.deepEqual(parseOpenDocument(JSON.stringify(["cursor ."]), "doc"), { open: ["cursor ."] });
const tab = { title: "Claude", path: ".", color: "yellow", command: "claude --continue" };
const warp = { warp: WARP_PLUGIN_SOURCE };
assert.deepEqual(parseOpenDocument(JSON.stringify([tab]), "doc"), { open: [CLAUDE_TAB], plugins: warp });
assert.deepEqual(parseOpenDocument(JSON.stringify({ other: 1, warpTabs: [tab] }), "doc"), { open: [CLAUDE_TAB], plugins: warp });
assert.deepEqual(parseOpenDocument(JSON.stringify([{ ...tab, teardownCommand: "make down" }]), "doc"), {
open: [CLAUDE_TAB],
remove: ["make down"],
plugins: warp
});
assert.throws(() => parseOpenDocument("{", "doc"), /not valid JSON/);
assert.throws(() => parseOpenDocument("{}", "doc"), /"open", "create" or "remove"/);
assert.throws(() => parseOpenDocument('{"warpTabs": null}', "doc"), /must be an array/);
});

test("a config from before multiple bases asks for lanes init", () => {
assert.throws(() => normalizeConfig({ baseFolder: "web", baseRef: "origin/main", lanesDir: "lanes" }), /lanes init/);
// Other keys are ignored, so a stray field from some other tool is not a document.
assert.throws(() => parseOpenDocument('{"warpTabs": [{"title": "x"}]}', "doc"), /"open", "create" or "remove"/);
assert.throws(() => parseOpenDocument('[{"title": "x"}]', "doc"), /must be a command line/);
});

test("a config without bases is rejected", () => {
Expand Down
Loading
< 1654 /ghcc-consent>
0