Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 22 to 23

Compare

+87 −1 in 3 places
Lines 7–25 at 23 (were 7–13 at 22)
77
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";
10+import {
11+ type Api,
12+ ApiError,
13+ type Ask,
14+ type Attachment,
15+ type CopyAnswer,
16+ type CopyBody,
17+ type Draft,
18+ type DraftBody,
19+ type IssuePage,
20+ type IssueRow,
21+ type IssueSearchHit,
22+} 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";
Lines 337–412 at 23 (were 325–330 at 22)
325337 };
326338}
327339
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;
355+ try {
356+ answer = await api.issueCopy(to, { ...texts, from, issue: id, ...(dryRun ? { dryRun: true } : {}) });
357+ } catch (e) {
358+ if (e instanceof ApiError && e.status === 403 && !dryRun)
359+ throw new ApiError(`${e.message}. --dry-run still shows what would go.`, e.status);
360+ throw e;
361+ }
362+ if ("dryRun" in answer) {
363+ const p = answer.plan;
364+ const edited = (list: { edited: boolean }[]) => list.filter((x) => x.edited).length;
365+ const lines = [
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.`,
371+ ];
372+ return { text: lines.join("\n"), json: answer };
373+ }
374+ return {
375+ text: [
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),
378+ ].join("\n"),
379+ json: answer,
380+ };
381+}
383+function skippedLines(skipped: { comments: number[]; asks: number[] }): string[] {
384+ const parts = [
385+ ...(skipped.comments.length > 0 ? [`comments ${skipped.comments.join(", ")}`] : []),
386+ ...(skipped.asks.length > 0 ? [`asks ${skipped.asks.join(", ")}`] : []),
387+ ];
388+ return parts.length > 0 ? [` not copied: ${parts.join("; ")} (open asks, and what --clean left out)`] : [];
389+}
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"> {
393+ let raw: unknown;
394+ try {
395+ raw = JSON.parse(readFileSync(path, "utf8"));
396+ } catch (e) {
397+ throw new UsageError(
398+ `--clean ${given}: ${(e as NodeJS.ErrnoException).code === "ENOENT" ? "no such file" : "not JSON"}`,
399+ );
400+ }
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">;
408+}
328410export async function runIssue(args: Parsed, env: Env): Promise<Output> {
329411 const [first, ...rest] = args.positionals;
330412 const { api } = openIssues(env);
Lines 429–438 at 23 (were 347–352 at 22)
347429 'abso issue <N> [--comment "..." | --object "..." | --drop | --reopen | --done [--done-by <version>] | an edit], or abso issue new "<title>"',
348430 );
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");
MCP
compare on this site's /mcp
CLI
abso diff 22 23 client/src/issues.ts --json
JSON
/christopher/abso-core/compare/22..23?file=client%2Fsrc%2Fissues.ts&format=json