mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 04:45:33 -08:00
Let set-version ask for the version on a terminal (Enter takes the next patch) and run as npm run set-version, bump every carrier to 3.0.6, and read the Ask entry for screenshots from the session's chat log now that chat hands over only the seq
AI Assisted
This commit is contained in:
1 parent
567a65ff5b
commit
9199fc00af
14 files changed
+104
-22
No files matched your search
@@ -535,10 +535,17 @@ async function captureAsk(browser, project, sid, url, question) {
|
||||
if (send) send.click();
|
||||
});
|
||||
|
||||
// `chat` hands over only the message's seq (its text goes in `reply`) and
|
||||
// moves its cursor past it, so the first seq seen is the one; the entry
|
||||
// itself, with its conversation, is read from the session's chat log.
|
||||
let entry = null;
|
||||
for (let i = 0; i < 40 && !entry; i++) {
|
||||
const r = cli(project, "chat", "--session", sid);
|
||||
if (r.code === 0 && r.out && r.out.chat) entry = r.out.chat.find((c) => c.kind === "message");
|
||||
const seq = r.code === 0 && r.out && Array.isArray(r.out.chat) ? r.out.chat[0] : undefined;
|
||||
if (Number.isInteger(seq)) {
|
||||
const log = path.join(HOME, "sessions", sid, "chat.ndjson");
|
||||
entry = fs.readFileSync(log, "utf8").split("\n").filter(Boolean).map((l) => JSON.parse(l)).find((e) => e.seq === seq) || null;
|
||||
}
|
||||
if (!entry) await sleep(250);
|
||||
}
|
||||
if (!entry) throw new Error("the Ask question never reached the console");
|
||||
|
||||
+62
-5
@@ -5,8 +5,11 @@
|
||||
// entries). It never touches CHANGELOG.md: write its heading by hand, then run this.
|
||||
// `check-versions.mjs` is the reader of the same places and stays the judge.
|
||||
//
|
||||
// node scripts/set-version.mjs <x.y.z> [--date YYYY-MM-DD] [--root <dir>]
|
||||
// node scripts/set-version.mjs [x.y.z] [--date YYYY-MM-DD] [--root <dir>]
|
||||
// npm run set-version [-- x.y.z]
|
||||
//
|
||||
// With no version on a terminal it shows the current one and asks (Enter takes the next patch);
|
||||
// with no version and no terminal (a script, a pipe) it prints the usage line and exits 2.
|
||||
// The release date defaults to today (local time). Every carrier is read and checked before any is
|
||||
// written, so a file that has no version leaves the tree as it was. Exit 0 when written, 1 when a
|
||||
// carrier could not be edited, 2 for bad arguments.
|
||||
@@ -111,6 +114,47 @@ export function setVersion(root, version, date = today()) {
|
||||
|
||||
export const CARRIER_FILES = CARRIERS.map((c) => c.file);
|
||||
|
||||
// The next patch after `current` (x.y.z), or "" when `current` is not one.
|
||||
export function nextPatch(current) {
|
||||
if (!SEMVER.test(current || "")) return "";
|
||||
const [major, minor, patch] = current.split(".").map(Number);
|
||||
return `${major}.${minor}.${patch + 1}`;
|
||||
}
|
||||
|
||||
// Ask on the terminal until a valid x.y.z is typed. Enter takes the suggested next patch.
|
||||
// Returns "" when the input ends (Ctrl+D, Ctrl+C) without one.
|
||||
async function askVersion(root) {
|
||||
let current = "";
|
||||
try {
|
||||
current = JSON.parse(fs.readFileSync(path.join(root, "version.json"), "utf8")).version || "";
|
||||
} catch {
|
||||
// No readable version.json: ask without a current version or a suggestion.
|
||||
}
|
||||
const suggested = nextPatch(current);
|
||||
const { createInterface } = await import("node:readline");
|
||||
const rl = createInterface({ input: process.stdin, terminal: false });
|
||||
// The line iterator buffers what is typed and ends on Ctrl+D or Ctrl+C, where a pending
|
||||
// rl.question() would never settle and leave the process to exit on an unsettled await.
|
||||
const lines = rl[Symbol.asyncIterator]();
|
||||
rl.on("SIGINT", () => rl.close());
|
||||
try {
|
||||
if (current) console.log(`Current version: ${current}`);
|
||||
for (;;) {
|
||||
process.stdout.write(`New version (x.y.z)${suggested ? ` [${suggested}]` : ""}: `);
|
||||
const { value, done } = await lines.next();
|
||||
if (done) {
|
||||
process.stdout.write("\n");
|
||||
return "";
|
||||
}
|
||||
const picked = value.trim() || suggested;
|
||||
if (SEMVER.test(picked)) return picked;
|
||||
console.log(picked ? `"${picked}" is not x.y.z, for example 3.1.0.` : "Type a version, for example 3.1.0.");
|
||||
}
|
||||
} finally {
|
||||
rl.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
||||
const args = process.argv.slice(2);
|
||||
const take = (flag) => {
|
||||
@@ -121,13 +165,26 @@ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.me
|
||||
};
|
||||
const date = take("--date");
|
||||
const rootArg = take("--root");
|
||||
const [version, ...extra] = args;
|
||||
const usage = "Usage: node scripts/set-version.mjs <x.y.z> [--date YYYY-MM-DD] [--root <dir>]";
|
||||
if (!version || extra.length || !SEMVER.test(version) || (date !== undefined && !validDate(date)) || rootArg === "") {
|
||||
let [version, ...extra] = args;
|
||||
const usage = "Usage: node scripts/set-version.mjs [x.y.z] [--date YYYY-MM-DD] [--root <dir>] (npm run set-version)";
|
||||
const root = rootArg ? path.resolve(rootArg) : ROOT;
|
||||
if (extra.length || (version !== undefined && !SEMVER.test(version)) || (date !== undefined && !validDate(date)) || rootArg === "") {
|
||||
console.error(usage);
|
||||
process.exit(2);
|
||||
}
|
||||
const { ok, written, problems } = setVersion(rootArg ? path.resolve(rootArg) : ROOT, version, date);
|
||||
// No version given: ask for one on a terminal; a script or a pipe gets the usage line instead.
|
||||
if (version === undefined) {
|
||||
if (!process.stdin.isTTY) {
|
||||
console.error(usage);
|
||||
process.exit(2);
|
||||
}
|
||||
version = await askVersion(root);
|
||||
if (!version) {
|
||||
console.error("No version given. Nothing was written.");
|
||||
process.exit(2);
|
||||
}
|
||||
}
|
||||
const { ok, written, problems } = setVersion(root, version, date);
|
||||
if (!ok) {
|
||||
for (const problem of problems) console.error(`CANNOT SET: ${problem}`);
|
||||
console.error("Nothing was written.");
|
||||
|
||||
@@ -12,7 +12,7 @@ import path from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { checkVersions } from "./check-versions.mjs";
|
||||
import { CARRIER_FILES } from "./set-version.mjs";
|
||||
import { CARRIER_FILES, nextPatch } from "./set-version.mjs";
|
||||
|
||||
const here = path.dirname(fileURLToPath(import.meta.url));
|
||||
const ROOT = path.resolve(here, "..");
|
||||
@@ -124,12 +124,29 @@ test("a carrier with no version in it fails and writes nothing", () => {
|
||||
|
||||
test("bad arguments exit 2 and write nothing", () => {
|
||||
const dir = scratch();
|
||||
// Compared with the file as copied, not with a number: the repo may already be at 3.0.1.
|
||||
const before = read(dir, "version.json");
|
||||
for (const args of [[], ["3.0"], ["v3.0.1"], ["3.0.1-beta"], ["3.0.1", "extra"], ["3.0.1", "--date", "yesterday"], ["3.0.1", "--root"]]) {
|
||||
const r = run(...args, ...(args.includes("--root") ? [] : ["--root", dir]));
|
||||
assert.equal(r.status, 2, `${args.join(" ")}: ${r.stderr}`);
|
||||
assert.match(r.stderr, /Usage: node scripts\/set-version\.mjs/);
|
||||
}
|
||||
assert.ok(!read(dir, "version.json").includes("3.0.1"));
|
||||
assert.equal(read(dir, "version.json"), before);
|
||||
});
|
||||
|
||||
test("no version and no terminal prints the usage line instead of asking", () => {
|
||||
// run() pipes stdin, so this is the script-or-pipe case: no prompt, exit 2, nothing written.
|
||||
const dir = scratch();
|
||||
const r = run("--root", dir);
|
||||
assert.equal(r.status, 2, r.stderr);
|
||||
assert.match(r.stderr, /npm run set-version/);
|
||||
});
|
||||
|
||||
test("the prompt suggests the next patch", () => {
|
||||
assert.equal(nextPatch("3.0.9"), "3.0.10");
|
||||
assert.equal(nextPatch("2.10.0"), "2.10.1");
|
||||
assert.equal(nextPatch("v3.0.1"), "");
|
||||
assert.equal(nextPatch(undefined), "");
|
||||
});
|
||||
|
||||
test("an impossible date is refused", () => {
|
||||
|
||||
Reference in new issue
Block a user