Skip to content

The VS Code of video editing, built for agents.

TypeScript

Refactor `dapi report` command for direct issue filing and improved documentation

konstantin-paulusa9c21b44273e
diff --git a/README.md b/README.md
index 889445e1..6139a1fd 100644
--- a/README.md
+++ b/README.md
@@ -140,7 +140,7 @@ dapi node capture # see the canvas itself
| `dapi screenshot` / `dapi logs` | The app itself: capture the window, read recent console output |
| `dapi fetch` | Download a video from yt/tt/ig, ready for `dapi asset add` |
| `dapi whoami` | The authenticated account |
-| `dapi report` | Report a bug in the CLI or the app: diagnostics bundled, prefilled GitHub issue link |
+| `dapi report` | Report a bug in the CLI or the app: diagnostics bundled, filed as a GitHub issue via `gh` |
Conventions throughout: single results are one JSON value, collections are JSON Lines, errors go to stderr with exit code `1`. Everything is built to be piped, grepped, and driven by a program.
diff --git a/apps/cli/src/index.ts b/apps/cli/src/index.ts
index 16b3d5c8..d0f9e132 100644
--- a/apps/cli/src/index.ts
+++ b/apps/cli/src/index.ts
@@ -14,7 +14,7 @@ import { parseTime, TIME_FPS } from "@diffusionstudio/jsx";
import { editor, errnoCode, waitForCliSocket, GENERATE_TIMEOUT_MS } from "./cli-client";
import { compileProject } from "./compile-project";
import { listLocalFonts } from "./fonts";
-import { buildIssueReport } from "./report";
+import { buildIssueBody, createIssue } from "./report";
import { openFolder } from "./open-folder";
import { fetchVideo } from "./ytdlp";
import { MAX_FRAMES_PER_SHEET } from "./protocol";
@@ -1054,7 +1054,7 @@ async function appScreenshot(opts: ScreenshotOptions): Promise<void> {
}
}
-type IssueOptions = { body?: string; command?: string[]; logs?: string; output?: string; open?: boolean };
+type IssueOptions = { body?: string; command?: string[]; logs?: string; open?: boolean };
const ISSUE_LOG_TAIL = 50;
@@ -1091,42 +1091,25 @@ async function reportIssue(title: string, opts: IssueOptions): Promise<void> {
}
}
- const slug = summary.toLowerCase().replace(/[^a-z0-9]+/g, "-").slice(0, 40).replace(/^-|-$/g, "");
- const filename = `dapi-report-${slug || "untitled"}-${randomUUID().slice(0, 8)}.md`;
-
- let path: string;
- let dir: string;
- if (opts.output === undefined) {
- dir = tmpdir();
- path = join(dir, filename);
- } else {
- const output = isAbsolute(opts.output) ? opts.output : resolve(process.cwd(), opts.output);
- // A trailing separator always means a directory, as does an existing one.
- const isDir = /[\\/]$/.test(opts.output) || (existsSync(output) && statSync(output).isDirectory());
- dir = isDir ? output : dirname(output);
- path = isDir ? join(output, filename) : output;
- }
-
- const { markdown, url, truncated } = buildIssueReport({
+ const body = buildIssueBody({
title: summary,
body: opts.body,
commands: opts.command,
logs,
appStatus,
version,
- reportPath: path,
});
+ let url: string;
try {
- mkdirSync(dir, { recursive: true });
- writeFileSync(path, markdown);
+ url = await createIssue(summary, body);
} catch (e) {
- console.error(`Could not write the report to ${path}: ${(e as Error).message}`);
+ console.error((e as Error).message);
process.exit(1);
}
if (opts.open) openInBrowser(url);
- console.log(JSON.stringify({ path, url, truncated }));
+ console.log(JSON.stringify({ url }));
}
function startSpinner(label: string): () => void {
@@ -1645,14 +1628,13 @@ program
.command("report")
.alias("issue")
.description(
- `Report a bug in dapi or the app itself. Writes a markdown report with diagnostics attached (dapi version, platform, recent app logs) and prints a prefilled GitHub issue URL; nothing is submitted, a human reviews and opens it.`,
+ `Report a bug in dapi or the app itself. Files a GitHub issue on diffusionstudio/editor with diagnostics attached (dapi version, platform, recent app logs) and prints its URL. Submits immediately and publicly through the gh CLI, which must be installed and authenticated; there is no review step, so only report real defects and check the attached logs for anything private.`,
)
.argument("<title>", "one-line summary of the problem")
.option("-b, --body <text>", "what happened, in markdown: expected vs actual, and anything the diagnostics won't show")
.option("-c, --command <cmd...>", "the dapi command(s) that reproduce it, in order; repeatable")
.option("--logs <n>", `trailing app log entries to attach (0 to omit; default: ${ISSUE_LOG_TAIL})`)
- .option("-o, --output <path>", "file path, or directory to write the report into (default: system temp dir)")
- .option("--open", "open the prefilled GitHub issue page in the default browser")
+ .option("--open", "open the created issue in the default browser")
.action((title: string, opts: IssueOptions) => reportIssue(title, opts));
program
diff --git a/apps/cli/src/report.ts b/apps/cli/src/report.ts
index a2960ac0..d618dec5 100644
--- a/apps/cli/src/report.ts
+++ b/apps/cli/src/report.ts
@@ -2,13 +2,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+import { spawn } from "node:child_process";
import { arch, platform, release } from "node:os";
-const ISSUE_URL = "https://github.com/diffusionstudio/editor/issues/new";
+const REPO = "diffusionstudio/editor";
-// GitHub answers a prefilled issue URL with 414 well before the 8 KB mark, so
-// the link carries a trimmed body and points at the full report on disk.
-const MAX_URL_LENGTH = 6000;
+export const GH_MISSING =
+ "gh (GitHub CLI) is not installed, so the issue cannot be filed. Install it from https://cli.github.com, run `gh auth login`, then retry.";
export type IssueInput = {
title: string;
@@ -17,11 +17,8 @@ export type IssueInput = {
logs?: string[]; // already formatted log lines, oldest first
appStatus: string; // "running", "not running", "not checked", or why it was unreachable
version: string;
- reportPath: string; // where the full report is written; referenced when the URL is truncated
};
-export type IssueReport = { markdown: string; url: string; truncated: boolean };
-
function fence(language: string, content: string): string {
return `\`\`\`${language}\n${content}\n\`\`\``;
}
@@ -36,35 +33,7 @@ function environmentTable(input: IssueInput): string {
return ["| | |", "| --- | --- |", ...rows.map(([k, v]) => `| ${k} | ${v} |`)].join("\n");
}
-// encodeURIComponent throws on a lone surrogate, which slicing the body mid
-// emoji can produce; dropping the orphan half is enough to keep the search safe.
-function encodedLength(text: string): number {
- const code = text.charCodeAt(text.length - 1);
- const safe = code >= 0xd800 && code <= 0xdbff ? text.slice(0, -1) : text;
- return encodeURIComponent(safe).length;
-}
-
-function issueUrl(title: string, body: string, reportPath: string): { url: string; truncated: boolean } {
- const base = `${ISSUE_URL}?title=${encodeURIComponent(title)}&body=`;
- const room = MAX_URL_LENGTH - base.length;
- if (encodedLength(body) <= room) return { url: base + encodeURIComponent(body), truncated: false };
-
- const note = `\n\n_Truncated for the link — full report: ${reportPath}_\n`;
- const budget = room - encodedLength(note);
-
- // Longest prefix of the body that still fits, by binary search on characters:
- // percent-encoding is per-character, so the encoded length grows monotonically.
- let lo = 0;
- let hi = body.length;
- while (lo < hi) {
- const mid = Math.ceil((lo + hi) / 2);
- if (encodedLength(body.slice(0, mid)) <= budget) lo = mid;
- else hi = mid - 1;
- }
- return { url: base + encodeURIComponent(body.slice(0, lo) + note), truncated: true };
-}
-
-export function buildIssueReport(input: IssueInput): IssueReport {
+export function buildIssueBody(input: IssueInput): string {
const sections: string[] = [];
if (input.body?.trim()) sections.push(input.body.trim());
@@ -72,8 +41,39 @@ export function buildIssueReport(input: IssueInput): IssueReport {
sections.push(`## Environment\n\n${environmentTable(input)}`);
if (input.logs?.length) sections.push(`## App logs\n\n${fence("", input.logs.join("\n"))}`);
- const body = sections.join("\n\n");
- const { url, truncated } = issueUrl(input.title, body, input.reportPath);
+ return `${sections.join("\n\n")}\n`;
+}
+
+// --repo is explicit because dapi runs from the user's project, not a checkout
+// of the editor; the body goes over stdin so a long log tail can't blow the
+// argv size limit.
+export function createIssue(title: string, body: string): Promise<string> {
+ return new Promise((resolve, reject) => {
+ const gh = spawn("gh", ["issue", "create", "--repo", REPO, "--title", title, "--body-file", "-"]);
+
+ let stdout = "";
+ let stderr = "";
+ gh.stdout.on("data", (chunk) => (stdout += chunk));
+ gh.stderr.on("data", (chunk) => (stderr += chunk));
+
+ gh.on("error", (e) => {
+ reject((e as NodeJS.ErrnoException).code === "ENOENT" ? new Error(GH_MISSING) : e);
+ });
+ gh.on("close", (code) => {
+ if (code !== 0) {
+ // gh explains itself well (not authenticated, no access, rate limited).
+ reject(new Error(stderr.trim() || `gh issue create exited with code ${code}`));
+ return;
+ }
+ const url = stdout.trim().split("\n").pop() ?? "";
+ if (!url.startsWith("https://")) {
+ reject(new Error(`gh issue create did not print an issue URL: ${stdout.trim() || "(no output)"}`));
+ return;
+ }
+ resolve(url);
+ });
- return { markdown: `# ${input.title}\n\n${body}\n`, url, truncated };
+ gh.stdin.on("error", () => { }); // gh exiting early (auth failure) breaks the pipe
+ gh.stdin.end(body);
+ });
}
diff --git a/reference/README.md b/reference/README.md
index 914e5bb3..7c112f01 100644
--- a/reference/README.md
+++ b/reference/README.md
@@ -32,7 +32,7 @@ How the surface is divided:
- [`dapi whoami`](./whoami.md): print the authenticated account
- [`dapi logs`](./logs.md): recent console output from the running app
- [`dapi screenshot`](./screenshot.md): capture the entire application window as a PNG
-- [`dapi report`](./report.md): file a bug report about the CLI or the app, with diagnostics attached
+- [`dapi report`](./report.md): file a GitHub issue about a bug in the CLI or the app, with diagnostics attached
### Document
@@ -123,4 +123,4 @@ Time inputs take the `Time` format unless noted otherwise. Times in **outputs**
- **Unix-style names are canonical:** list/read is `ls`, delete is `rm`, duplicate is `cp`, move/reparent is `mv`, search is `grep`. The longer English forms (`list`, `remove`, `duplicate`, `move`) are aliases of the Unix forms, not the other way around. `get` is a universal alias for `ls`. Commands without a natural Unix equivalent (`tree`, `rename`, `patch`, `add`, `create`, `active`, `context`, `whoami`, `open`, `focus`, `set`) keep their descriptive names.
- **Stderr:** human-readable error messages.
- **Exit codes:** `0` on success, `1` on any error (missing file, app not running, invalid input, IPC error).
-- **App must be running:** every command except `open`, `fonts`, and `fetch` talks to the open Diffusion Studio instance. If the app isn't running, the CLI prints an instruction to launch it and exits `1`. `report` is the one command that reads from the app but tolerates its absence, recording it in the report instead of failing.
+- **App must be running:** every command except `open`, `fonts`, and `fetch` talks to the open Diffusion Studio instance. If the app isn't running, the CLI prints an instruction to launch it and exits `1`. `report` is the one command that reads from the app but tolerates its absence, recording it in the issue instead of failing.
diff --git a/reference/report.md b/reference/report.md
index 59d37e2e..742897e1 100644
--- a/reference/report.md
+++ b/reference/report.md
@@ -1,8 +1,8 @@
# `dapi report <title>`
-Reports a bug in `dapi` itself or in the app behind it: a command that errors, contradicts this reference, or returns something it shouldn't. Bundles the description with diagnostics (dapi version, platform, node version, the app's recent console output) into a markdown report on disk, and prints a prefilled GitHub issue URL for [diffusionstudio/editor](https://github.com/diffusionstudio/editor/issues).
+Reports a bug in `dapi` itself or in the app behind it: a command that errors, contradicts this reference, or returns something it shouldn't. Bundles the description with diagnostics (dapi version, platform, node version, the app's recent console output) and files it as a GitHub issue on [diffusionstudio/editor](https://github.com/diffusionstudio/editor/issues), printing the URL of the created issue.
-Nothing is submitted. The command only writes a file and composes a link; a human reviews the report and opens the issue, either from the printed URL or by pasting the file. `--open` opens the prefilled page in the default browser.
+The issue is submitted immediately, in the background, with no review step: the command returns once the issue exists. Filing goes through the [`gh`](https://cli.github.com) CLI, which must be installed and authenticated (`gh auth login`); without it the command exits `1` and files nothing.
This is for defects in the tooling, not for problems inside a project: a composition that looks wrong, a node in the wrong place, or a generation that missed the prompt are editing problems, fixed with `node patch` / `mount`, not reported here.
@@ -10,15 +10,14 @@ Does not require the app to be running. If the app is down or unreachable, the r
## Arguments
-- `<title>`: one-line summary of the problem, used as the issue title and in the report filename.
+- `<title>`: one-line summary of the problem, used as the issue title.
## Options
- `-b, --body <text>`: what happened, in markdown: what you expected, what you got, and anything the diagnostics won't show.
- `-c, --command <cmd...>`: the `dapi` command(s) that reproduce it, in order. Repeatable (`-c "dapi node ls 5" -c "dapi node capture 5"`); rendered as a shell block under `## Repro`.
- `--logs <n>`: trailing app log entries to attach (default: 50). `--logs 0` omits the section, and then the app is not contacted at all.
-- `-o, --output <path>`: where to write the report. A directory when it exists as one or ends with a path separator (the file is named after the title); otherwise an exact file path. Default: the system temp directory.
-- `--open`: open the prefilled GitHub issue page in the default browser.
+- `--open`: open the created issue in the default browser.
## Output
@@ -26,19 +25,15 @@ One JSON object:
```ts
{
- path: string, // absolute path of the markdown report
- url: string, // prefilled github.com/diffusionstudio/editor/issues/new link
- truncated: boolean // true when the body was too long for the URL and was cut short in the link only
+ url: string // the created github.com/diffusionstudio/editor issue
}
```
-The report on disk is always complete. Long reports exceed what a prefilled URL can carry, so the link's body is trimmed and ends with a pointer to `path`; `truncated` says when that happened.
+## Issue layout
-## Report layout
+The title is the issue title; the body is assembled from the options and the diagnostics:
````md
-# <title>
-
<body>
## Repro
@@ -67,6 +62,6 @@ The `app` row reads `running`, `not running`, `not checked` (with `--logs 0`), o
## Notes
-- Attached logs are the same entries [`logs`](./logs.md) prints, and can contain project names, file paths, and prompt text. They land in a local file, not on GitHub, until someone submits the report: review it before posting.
-- Exits non-zero on an empty title, an invalid `--logs`, or an unwritable `--output`.
+- Attached logs are the same entries [`logs`](./logs.md) prints, and can contain project names, file paths, and prompt text. They go straight to a public issue: pass `--logs 0`, or check what [`logs`](./logs.md) currently holds, before reporting from a sensitive project.
+- Exits non-zero on an empty title, an invalid `--logs`, a missing `gh`, or a failure from `gh` (not authenticated, no access to the repo); the message from `gh` is passed through.
- `dapi issue` is an alias of this command.