pi-dev-flow 0.100.1 → 0.101.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +2 -2
- package/docs/jira.md +9 -7
- package/extensions/dev-flow.ts +14 -29
- package/package.json +1 -1
- package/src/core.ts +4 -0
- package/src/jira/client.ts +115 -232
- package/src/jira/creds.ts +14 -34
- package/src/jira/mcp.ts +63 -16
- package/src/jira/sync.ts +2 -1
- package/src/planhtml.ts +209 -0
- package/src/runtime/jira.ts +120 -38
- package/src/runtime/planpdf.ts +85 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** dev-flow runtime — plan.md printed to a PDF, mockups included, with the headless chromium the plan stage
|
|
2
|
+
* already renders mockups with. The PDF is what a linked Jira issue gets: an issue cannot show plan.md's
|
|
3
|
+
* embedded images, a PDF carries them. */
|
|
4
|
+
import { execFile } from "node:child_process";
|
|
5
|
+
import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
6
|
+
import os from "node:os";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { pathToFileURL } from "node:url";
|
|
9
|
+
import { promisify } from "node:util";
|
|
10
|
+
import { planHtml } from "../planhtml.ts";
|
|
11
|
+
|
|
12
|
+
const execFileAsync = promisify(execFile);
|
|
13
|
+
|
|
14
|
+
/** Test seams: the chromium binary (null: none found), the environment the search reads. */
|
|
15
|
+
export const pdfSeams: { chromium?: string | null; env?: NodeJS.ProcessEnv } = {};
|
|
16
|
+
|
|
17
|
+
const isExe = (f: string) => {
|
|
18
|
+
try {
|
|
19
|
+
return statSync(f).isFile();
|
|
20
|
+
} catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** The headless chromiums to print with, best first: `DEV_FLOW_CHROMIUM`, then chromium / chrome on PATH, the
|
|
26
|
+
* macOS app bundles, then playwright's browser cache (newest build first, its headless shell before its full
|
|
27
|
+
* chrome) — the same search the plan stage's mockup renders use. Empty when there is none. */
|
|
28
|
+
export function chromiumCandidates(): string[] {
|
|
29
|
+
if (pdfSeams.chromium !== undefined) return pdfSeams.chromium ? [pdfSeams.chromium] : [];
|
|
30
|
+
const env = pdfSeams.env ?? process.env;
|
|
31
|
+
const out: string[] = [];
|
|
32
|
+
const add = (f: string) => void (isExe(f) && !out.includes(f) && out.push(f));
|
|
33
|
+
if (env.DEV_FLOW_CHROMIUM) add(env.DEV_FLOW_CHROMIUM);
|
|
34
|
+
const dirs = (env.PATH ?? "").split(path.delimiter).filter(Boolean);
|
|
35
|
+
for (const name of ["chromium", "chromium-browser", "google-chrome", "google-chrome-stable", "chrome"]) for (const d of dirs) add(path.join(d, name));
|
|
36
|
+
add("/Applications/Chromium.app/Contents/MacOS/Chromium");
|
|
37
|
+
add("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome");
|
|
38
|
+
const cache = env.PLAYWRIGHT_BROWSERS_PATH || path.join(env.HOME ?? os.homedir(), ".cache", "ms-playwright");
|
|
39
|
+
if (existsSync(cache)) {
|
|
40
|
+
const rev = (d: string) => Number(d.match(/(\d+)$/)?.[1] ?? 0);
|
|
41
|
+
const builds = readdirSync(cache)
|
|
42
|
+
.filter((d) => /^chromium/.test(d))
|
|
43
|
+
.sort((a, b) => rev(b) - rev(a) || Number(b.includes("headless")) - Number(a.includes("headless")));
|
|
44
|
+
for (const b of builds)
|
|
45
|
+
for (const rel of ["chrome-headless-shell-linux64/chrome-headless-shell", "chrome-headless-shell-mac-arm64/chrome-headless-shell", "chrome-headless-shell-mac-x64/chrome-headless-shell", "chrome-linux64/chrome", "chrome-linux/chrome"]) add(path.join(cache, b, rel));
|
|
46
|
+
}
|
|
47
|
+
return out.slice(0, 4);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Print `planDir/plan.md` to `out` (a .pdf path). `meta` is the line printed above the plan. Tries each
|
|
51
|
+
* chromium found until one writes the PDF. */
|
|
52
|
+
export async function renderPlanPdf(planDir: string, out: string, o: { title: string; meta?: string }): Promise<{ ok: true } | { ok: false; error: string }> {
|
|
53
|
+
const bins = chromiumCandidates();
|
|
54
|
+
if (!bins.length) return { ok: false, error: "no headless chromium found (chromium / google-chrome on PATH, playwright's cache, or DEV_FLOW_CHROMIUM)" };
|
|
55
|
+
const md = readFileSync(path.join(planDir, "plan.md"), "utf8");
|
|
56
|
+
const tmp = mkdtempSync(path.join(os.tmpdir(), "dev-flow-pdf-"));
|
|
57
|
+
const errors: string[] = [];
|
|
58
|
+
try {
|
|
59
|
+
const html = path.join(tmp, "plan.html");
|
|
60
|
+
writeFileSync(html, planHtml(md, { title: o.title, meta: o.meta, base: `${pathToFileURL(planDir).href}/` }));
|
|
61
|
+
for (const [n, bin] of bins.entries()) {
|
|
62
|
+
rmSync(out, { force: true });
|
|
63
|
+
const args = ["--headless", "--no-sandbox", "--disable-gpu", "--hide-scrollbars", "--no-first-run", "--no-default-browser-check", `--user-data-dir=${path.join(tmp, `profile-${n}`)}`, "--allow-file-access-from-files", "--no-pdf-header-footer", "--virtual-time-budget=5000", `--print-to-pdf=${out}`, pathToFileURL(html).href];
|
|
64
|
+
try {
|
|
65
|
+
await execFileAsync(bin, args, { timeout: 45_000, maxBuffer: 4 * 1024 * 1024 });
|
|
66
|
+
} catch (e) {
|
|
67
|
+
// chromium can exit non-zero after writing the PDF (a crashpad or dbus complaint): judge by the file
|
|
68
|
+
if (!isPdf(out)) errors.push(`${path.basename(bin)}: ${String((e as { stderr?: string }).stderr || (e as Error).message).trim().split("\n").slice(-1)[0].slice(0, 200)}`);
|
|
69
|
+
}
|
|
70
|
+
if (isPdf(out)) return { ok: true };
|
|
71
|
+
if (errors.length <= n) errors.push(`${path.basename(bin)}: wrote no PDF`);
|
|
72
|
+
}
|
|
73
|
+
return { ok: false, error: `--print-to-pdf failed — ${errors.join("; ")}` };
|
|
74
|
+
} finally {
|
|
75
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function isPdf(f: string): boolean {
|
|
80
|
+
try {
|
|
81
|
+
return readFileSync(f).subarray(0, 5).toString("latin1") === "%PDF-";
|
|
82
|
+
} catch {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|