--- a/client/src/issues.ts
+++ b/client/src/issues.ts
@@ -7,7 +7,19 @@
88import { readFileSync, statSync } from "node:fs"; 99import { basename, resolve } from "node:path"; 10−import type { Api, Ask, Attachment, Draft, DraftBody, IssuePage, IssueRow, IssueSearchHit } from "./api.ts";
1123import { bool, type Parsed, str, UsageError } from "./args.ts"; 1224import { type Env, type Output, open, plural } from "./commands.ts"; 1325import { type Config, readMachineServers, trustedServers } from "./config.ts"; @@ -325,6 +337,76 @@
340+/** The flags --copy-to goes with: anything else on the same command is refused, so a copy is never half an edit. */ 341+const COPY_FLAGS = new Set(["copy-to", "clean", "dry-run"]); 343+/** abso issue <N> --copy-to <project>: the server reads the issue and writes the copy. */ 344+async function runCopy(api: Api, id: number, to: string, args: Parsed, env: Env): Promise<Output> { 345+ const other = [...args.flags.keys()].filter((f) => !COPY_FLAGS.has(f) && f !== "json"); 346+ if (other.length > 0) 347+ throw new UsageError(`--copy-to goes alone (with --clean and --dry-run), not with --${other[0]}`); 348+ if (to === api.config.project) 349+ throw new UsageError(`issue ${id} is already in ${to}; --copy-to names another project`); 350+ const clean = str(args, "clean"); 351+ const texts = clean === undefined ? {} : readClean(resolve(env.cwd, clean), clean); 352+ const dryRun = bool(args, "dry-run"); 353+ const from = api.config.project; 354+ let answer: CopyAnswer; 356+ answer = await api.issueCopy(to, { ...texts, from, issue: id, ...(dryRun ? { dryRun: true } : {}) }); 358+ if (e instanceof ApiError && e.status === 403 && !dryRun) 359+ throw new ApiError(`${e.message}. --dry-run still shows what would go.`, e.status); 362+ if ("dryRun" in answer) { 363+ const p = answer.plan; 364+ const edited = (list: { edited: boolean }[]) => list.filter((x) => x.edited).length; 366+ `A dry run: nothing was written. Copying ${from} issue ${id} into ${to} would make:`, 367+ ` ${q(p.title)}${p.closed ? `, ${p.closed.how}` : ""}${p.edited.length > 0 ? ` (${p.edited.join(" and ")} edited when copied)` : ""}`, 368+ ` ${plural(p.comments.length, "comment")}${edited(p.comments) > 0 ? ` (${edited(p.comments)} edited)` : ""}, ${plural(p.asks.length, "answered ask")}${edited(p.asks) > 0 ? ` (${edited(p.asks)} edited)` : ""}${p.labels.length > 0 ? `, labelled ${p.labels.join(", ")}` : ""}`, 369+ ...skippedLines(p.skipped), 370+ `Run it again without --dry-run to copy it.`, 372+ return { text: lines.join("\n"), json: answer }; 376+ `Copied ${from} issue ${id} to ${to} issue ${answer.id}. Its comments and asks keep their authors and times, and issue ${id} has a comment saying where it went.`, 377+ ...skippedLines(answer.skipped), 383+function skippedLines(skipped: { comments: number[]; asks: number[] }): string[] { 385+ ...(skipped.comments.length > 0 ? [`comments ${skipped.comments.join(", ")}`] : []), 386+ ...(skipped.asks.length > 0 ? [`asks ${skipped.asks.join(", ")}`] : []), 388+ return parts.length > 0 ? [` not copied: ${parts.join("; ")} (open asks, and what --clean left out)`] : []; 391+/** --clean's file: cleaned texts by source id. The server checks each id against the issue it reads. */ 392+function readClean(path: string, given: string): Omit<CopyBody, "from" | "issue"> { 395+ raw = JSON.parse(readFileSync(path, "utf8")); 397+ throw new UsageError( 398+ `--clean ${given}: ${(e as NodeJS.ErrnoException).code === "ENOENT" ? "no such file" : "not JSON"}`, 401+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) 402+ throw new UsageError(`--clean ${given}: a JSON object with title, description, comments or asks`); 403+ const known = new Set(["title", "description", "comments", "asks"]); 404+ const unknown = Object.keys(raw).filter((k) => !known.has(k)); 405+ if (unknown.length > 0) 406+ throw new UsageError(`--clean ${given}: ${unknown[0]} isn't one of title, description, comments, asks`); 407+ return raw as Omit<CopyBody, "from" | "issue">; 328410export async function runIssue(args: Parsed, env: Env): Promise<Output> { 329411 const [first, ...rest] = args.positionals; 330412 const { api } = openIssues(env); @@ -347,6 +429,10 @@
347429 'abso issue <N> [--comment "..." | --object "..." | --drop | --reopen | --done [--done-by <version>] | an edit], or abso issue new "<title>"', 349431 const id = issueNumber(first); 432+ const copyTo = str(args, "copy-to"); 433+ if (copyTo !== undefined) return runCopy(api, id, copyTo, args, env); 434+ if (str(args, "clean") !== undefined || bool(args, "dry-run")) 435+ throw new UsageError("--clean and --dry-run go with --copy-to <project>"); 350436 const comment = str(args, "comment"); 351437 const object = str(args, "object"); 352438 const doneBy = str(args, "done-by"); --- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -387,11 +387,14 @@
388388 delete: "boolean", 390+ "copy-to": "string", 392+ "dry-run": "boolean", 392− 'abso issue <N> [--comment "..." [--attach <file,file>] | --object "..." | --drop | --reopen | --done [--done-by <version>]] | abso issue <N> [--title "..."] [--description "..."] [--parent <N|none>] [--agent <agent|none>] [--blocked-by <N,N|none>] [--label <l,l>] [--unlabel <l,l>] [--notify <who,who> | --quiet] | abso issue new "<title>" [--description "..."] [--parent <N>] [--lines <file>:<from>-<to>@<version>] [--agent <agent>] [--blocked-by <N,N>] [--notify <who,who>] [--label <l,l>] [--attach <file,file>]',
395+ 'abso issue <N> --copy-to <project> [--clean <file>] [--dry-run] | abso issue <N> [--comment "..." [--attach <file,file>] | --object "..." | --drop | --reopen | --done [--done-by <version>]] | abso issue <N> [--title "..."] [--description "..."] [--parent <N|none>] [--agent <agent|none>] [--blocked-by <N,N|none>] [--label <l,l>] [--unlabel <l,l>] [--notify <who,who> | --quiet] | abso issue new "<title>" [--description "..."] [--parent <N>] [--lines <file>:<from>-<to>@<version>] [--agent <agent>] [--blocked-by <N,N>] [--notify <who,who>] [--label <l,l>] [--attach <file,file>]', 394− "One issue: its description, Agent, Blocked by, labels, asks, comments, edits, sub-issues and watchers. --comment comments on it and --object objects; its agents hear either. --drop drops it. --reopen opens a dropped issue again. --done marks it done by hand, and --done-by <version> names the published version that did it. publish --done still marks it done too. --title, --description, --parent, --agent and --blocked-by edit it, and the edit tells its watchers (who opened it, its Agent and agents, its Reviewer, whoever was named in Notify, and whoever commented); --notify tells more people, --quiet tells nobody. --label adds labels and --unlabel takes them off (friction, area:client: lower-case letters, digits and - _ . :); a label-only edit tells nobody unless --notify names people. An issue is Blocked until each issue it's blocked by is Done. abso issue new opens one; --lines ties it to lines at a version of shared, --agent says who it's for, --notify tells people now, and --label labels it. --attach shot.png,after.png puts images on a new issue or a comment (png, jpeg, gif or webp, 10 MB each; the server checks the type by the bytes and takes out metadata such as where a photo was taken), and prints each one's id for the text to point at; the issue's page lists them with a link. abso issue draft \"<title>\" [the same fields] saves a draft instead: yours alone, with no number and no news; abso issue draft <D> [fields] changes it, --open opens it as an issue, --delete deletes it.",
397+ "One issue: its description, Agent, Blocked by, labels, asks, comments, edits, sub-issues and watchers. --comment comments on it and --object objects; its agents hear either. --drop drops it. --reopen opens a dropped issue again. --done marks it done by hand, and --done-by <version> names the published version that did it. publish --done still marks it done too. --title, --description, --parent, --agent and --blocked-by edit it, and the edit tells its watchers (who opened it, its Agent and agents, its Reviewer, whoever was named in Notify, and whoever commented); --notify tells more people, --quiet tells nobody. --label adds labels and --unlabel takes them off (friction, area:client: lower-case letters, digits and - _ . :); a label-only edit tells nobody unless --notify names people. An issue is Blocked until each issue it's blocked by is Done. abso issue new opens one; --lines ties it to lines at a version of shared, --agent says who it's for, --notify tells people now, and --label labels it. --attach shot.png,after.png puts images on a new issue or a comment (png, jpeg, gif or webp, 10 MB each; the server checks the type by the bytes and takes out metadata such as where a photo was taken), and prints each one's id for the text to point at; the issue's page lists them with a link. --copy-to <project> copies the issue into another project, with its comments, answered asks and labels, each keeping its author and time; --dry-run shows what would go and writes nothing, and --clean <file> gives cleaned texts by source id as JSON ({title, description, comments: [{id, text}], asks: [{id, question, answer}]}; a comment left out of a given list isn't copied). Copying out of a project on a live server takes an owner of that project. abso issue draft \"<title>\" [the same fields] saves a draft instead: yours alone, with no number and no news; abso issue draft <D> [fields] changes it, --open opens it as an issue, --delete deletes it.", --- a/client/src/mcp.ts
+++ b/client/src/mcp.ts
@@ -120,12 +120,15 @@
120120 return rel === "" || (rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel)); 123+/** The tool inputs that name files on this machine to read, comma-separated: each is confined like the folder. */ 124+export const FILE_INPUTS = ["attach", "clean"] as const; 124127 * Where a tool call runs, and what it may read: its folder and 125− * every --attach file stay inside the folder the server started in. A relative
126− * path that climbs out (..), an absolute one elsewhere, or a link out is
127− * refused, so no tool reads a file outside the project. Answers the folder, or
128− * why the call is refused.
128+ * every file a FILE_INPUTS input names stay inside the folder the server 129+ * started in. A relative path that climbs out (..), an absolute one elsewhere, 130+ * or a link out is refused, so no tool reads a file outside the project. 131+ * Answers the folder, or why the call is refused. 130133export function confineCall( @@ -137,15 +140,18 @@
138141 refused: `folder ${JSON.stringify(named)} is outside ${start}, the folder this server started in; tools run there or below`, 140− if (typeof input.attach === "string")
141− for (const p of input.attach
143+ for (const flag of FILE_INPUTS) { 144+ const value = input[flag]; 145+ if (typeof value !== "string") continue; 146+ for (const p of value 143148 .map((x) => x.trim()) 144149 .filter((x) => x !== "")) 145150 if (!inside(start, resolve(folder, p))) 147− refused: `--attach ${p} is outside ${start}, the folder this server started in; a tool attaches files from there or below`,
152+ refused: `--${flag} ${p} is outside ${start}, the folder this server started in; a tool reads files from there or below`, 149155 return { folder }; --- a/client/test/issues.test.ts
+++ b/client/test/issues.test.ts
@@ -12,7 +12,7 @@
1212import { tmpdir } from "node:os"; 1313import { join } from "node:path"; 1414import { after, before, describe, it } from "node:test"; 15−import { readMachineServers } from "../src/config.ts";
15+import { readConfig, readMachineServers } from "../src/config.ts"; 1616import { issuesServerFor, tokenGoesTo } from "../src/core.ts"; 1717import { searchLines } from "../src/issues.ts"; 1818import { main } from "../src/main.ts"; @@ -26,13 +26,45 @@
2626let issuesUrl: string; 2727/** Every call the stand-in Issues server took. */ 2828const seen: string[] = []; 29+/** The bodies of the copy requests it took. */ 30+const copies: Record<string, unknown>[] = []; 2931const dirs: string[] = []; 3234 fake = await startFake(0, TOKEN); 3335 issues = createServer((req, res) => { 3436 seen.push(`${req.method} ${req.url}`); 35− res.writeHead(500, { "content-type": "application/json" }).end(JSON.stringify({ error: "a stand-in" }));
37+ const send = (status: number, body: unknown) => 38+ res.writeHead(status, { "content-type": "application/json" }).end(JSON.stringify(body)); 39+ if (req.method === "POST" && /\/copy$/.test(req.url ?? "")) { 41+ req.on("data", (c: Buffer) => (raw += c.toString("utf8"))); 42+ req.on("end", () => { 43+ const body = JSON.parse(raw) as Record<string, unknown>; 45+ // Issue 403 stands for a live server refusing an agent's copy. 46+ if (body.issue === 403 && body.dryRun !== true) 47+ return send(403, { error: "copying an issue out of its project takes an owner of that project" }); 48+ const skipped = { comments: [4], asks: [2] }; 49+ if (body.dryRun === true) 53+ from: { project: body.from, issue: body.issue }, 54+ title: "Sync is slow", 55+ edited: ["description"], 57+ closed: { how: "done" }, 58+ comments: [{ edited: false }, { edited: true }], 59+ asks: [{ edited: false }], 63+ send(200, { ok: true, id: 31, from: { project: body.from, issue: body.issue }, skipped }); 67+ send(500, { error: "a stand-in" }); 3769 await new Promise<void>((ok) => issues.listen(0, "127.0.0.1", ok)); 3870 issuesUrl = `http://127.0.0.1:${(issues.address() as AddressInfo).port}`; @@ -166,3 +198,84 @@
166198 assert.match(posts[0]!, /^POST \/p\/issues\d+\/a\/erin\/withdraw\/3$/); 202+describe("abso issue <N> --copy-to <project>", () => { 203+ const text = async (cwd: string, argv: string[]) => { 204+ const r = await main(argv, { cwd, env: ENV(), write: () => {} }); 205+ return { exit: r.exit, out: r.stdout + r.stderr }; 208+ it("a dry run asks the other project's copy route for the plan, and says nothing was written", async () => { 209+ const gil = await folder("gil"); 210+ const before = seen.length; 211+ const r = await text(gil, ["issue", "12", "--copy-to", "core", "--dry-run"]); 212+ assert.equal(r.exit, 0, r.out); 213+ assert.deepEqual(seen.slice(before), ["POST /p/core/a/gil/copy"]); 214+ const from = (copies.at(-1) as { from: string }).from; 215+ assert.match(from, /^issues\d+$/); 216+ assert.deepEqual(copies.at(-1), { from, issue: 12, dryRun: true }); 220+ `A dry run: nothing was written. Copying ${from} issue 12 into core would make:`, 221+ ` "Sync is slow", done (description edited when copied)`, 222+ " 2 comments (1 edited), 1 answered ask, labelled client", 223+ " not copied: comments 4; asks 2 (open asks, and what --clean left out)", 224+ "Run it again without --dry-run to copy it.", 229+ it("copies with the cleaned texts --clean gives, by source id", async () => { 230+ const gil = await folder("gil"); 232+ join(gil, "clean.json"), 233+ JSON.stringify({ description: "Cleaned.", comments: [{ id: 1 }, { id: 3, text: "Cleaned too." }] }), 235+ const r = await text(gil, ["issue", "12", "--copy-to", "core", "--clean", "clean.json"]); 236+ assert.equal(r.exit, 0, r.out); 237+ const from = (copies.at(-1) as { from: string }).from; 238+ assert.deepEqual(copies.at(-1), { 239+ description: "Cleaned.", 240+ comments: [{ id: 1 }, { id: 3, text: "Cleaned too." }], 246+ new RegExp(`^Copied ${from} issue 12 to core issue 31\\. Its comments and asks keep their authors`), 250+ it("says a dry run still works when the server refuses the copy", async () => { 251+ const gil = await folder("gil"); 252+ const r = await text(gil, ["issue", "403", "--copy-to", "core"]); 253+ assert.equal(r.exit, 1, r.out); 254+ assert.match(r.out, /takes an owner of that project\. --dry-run still shows what would go\./); 257+ it("refuses mistakes before any call", async () => { 258+ const gil = await folder("gil"); 259+ writeFileSync(join(gil, "bad.json"), JSON.stringify({ from: "elsewhere" })); 260+ const before = seen.length; 261+ for (const [argv, why] of [ 262+ [["issue", "12", "--copy-to", "core", "--comment", "x"], /--copy-to goes alone .* not with --comment/], 263+ [["issue", "12", "--dry-run"], /--clean and --dry-run go with --copy-to <project>/], 264+ [["issue", "12", "--copy-to", "core", "--clean", "nope.json"], /--clean nope\.json: no such file/], 266+ ["issue", "12", "--copy-to", "core", "--clean", "bad.json"], 267+ /from isn't one of title, description, comments, asks/, 270+ const r = await text(gil, [...argv]); 271+ assert.notEqual(r.exit, 0, argv.join(" ")); 272+ assert.match(r.out, why); 274+ const { project } = readConfig(gil); 276+ (await text(gil, ["issue", "12", "--copy-to", project])).out, 277+ /issue 12 is already in issues\d+; --copy-to names another project/, 279+ assert.equal(seen.length, before, "nothing reached the Issues server");