⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(cli): cap passthrough image size and report labels after create
Andrej6eb185cc9c70
diff --git a/packages/cli/src/commands/task/create.ts b/packages/cli/src/commands/task/create.tsindex d1deace4b..25c868306 100644--- a/packages/cli/src/commands/task/create.ts+++ b/packages/cli/src/commands/task/create.ts@@ -7,6 +7,7 @@ import {createTask,type Priority,} from "../../api/task-mutations.js";+import { describeError } from "../../errors/describe.js";import { Cancelled, InvalidArgument } from "../../errors/errors.js";import { toTaskLabelJson } from "../../labels/label-json.js";import { resolveLabels } from "../../labels/resolve-labels.js";@@ -147,17 +148,27 @@ export const runTaskCreate = Effect.fn("command.task.create")(const created = yield* withSpinner("Creating task")(createTask(project.id, body),);+ const createdLabel =+ ticketId(project.slug, created.number) ?? created.id.slice(0, 8);const attached: ReadonlyArray<Label> =labels.length > 0? yield* withSpinner("Adding labels")(Effect.forEach(labels, (label) =>attachLabelToTask(label.id, created.id),),+ ).pipe(+ Effect.mapError(+ (error) =>+ new InvalidArgument({+ message: `Created ${createdLabel}, but could not add the labels: ${describeError(error).message}`,+ hint: `Add them with kaneo task edit ${createdLabel} ${labels.map((label) => `--add-label "${label.name}"`).join(" ")}`,+ }),+ ),): [];const parentRef = yield* linkToParent(parent, {id: created.id,- label: ticketId(project.slug, created.number) ?? created.id.slice(0, 8),+ label: createdLabel,});const json = toTaskDetailJson({diff --git a/packages/cli/src/images/decode-image.ts b/packages/cli/src/images/decode-image.tsindex 484e16950..fe3605f49 100644--- a/packages/cli/src/images/decode-image.ts+++ b/packages/cli/src/images/decode-image.ts@@ -3,6 +3,8 @@ import type { RgbaImage } from "./rgba.js";export const MAX_DECODE_PIXELS = 40_000_000;+export const MAX_PASSTHROUGH_PIXELS = 4096 * 4096;+function asBuffer(bytes: Uint8Array): Buffer {return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);}diff --git a/packages/cli/src/images/image-art.test.ts b/packages/cli/src/images/image-art.test.tsindex 469b546e7..1c61d40f0 100644--- a/packages/cli/src/images/image-art.test.ts+++ b/packages/cli/src/images/image-art.test.ts@@ -23,6 +23,14 @@ const gif = new Uint8Array([0,]);+function withDeclaredSize(png: Uint8Array, width: number, height: number) {+ const copy = new Uint8Array(png);+ const view = new DataView(copy.buffer);+ view.setUint32(16, width);+ view.setUint32(20, height);+ return copy;+}+const run = (bytes: Uint8Array, at: ImageTarget, maxColumns = 64) =>Effect.runPromise(imageArt(bytes, at, { maxColumns }));@@ -67,6 +75,16 @@ describe("imageArt", () => {}});+ it("refuses images whose declared size would overload the terminal", async () => {+ const huge = withDeclaredSize(red, 100_000, 100_000);+ for (const protocol of ["kitty", "iterm"] as const) {+ expect(await run(huge, target(protocol))).toEqual({+ _tag: "Unsupported",+ reason: "100000x100000 is too large to show",+ });+ }+ });+it("explains formats that cannot be shown", async () => {expect(await run(gif, target("blocks"))).toEqual({_tag: "Unsupported",diff --git a/packages/cli/src/images/image-art.ts b/packages/cli/src/images/image-art.tsindex 3c97e54dd..7212ce9e7 100644--- a/packages/cli/src/images/image-art.ts+++ b/packages/cli/src/images/image-art.ts@@ -1,7 +1,11 @@import { Effect } from "effect";import { renderBlocks } from "./blocks.js";import type { CellSize } from "./cell-size.js";-import { canDecode, decodeImage } from "./decode-image.js";+import {+ canDecode,+ decodeImage,+ MAX_PASSTHROUGH_PIXELS,+} from "./decode-image.js";import {BLOCK_CELL,fitImage,@@ -40,6 +44,18 @@ function art(lines: ReadonlyArray<string>, size: CellSize): ImageArt {return { _tag: "Art", lines, ...size };}+function fitsPassthrough(info: ImageInfo): boolean {+ return (+ info.width > 0 &&+ info.height > 0 &&+ info.width * info.height <= MAX_PASSTHROUGH_PIXELS+ );+}++function tooLarge(info: ImageInfo): ImageArt {+ return unsupported(`${info.width}x${info.height} is too large to show`);+}+function notShown(info: ImageInfo): ImageArt {return unsupported(`${FORMAT_LABELS[info.format]} cannot be shown here`);}@@ -85,11 +101,13 @@ export const imageArt = Effect.fnUntraced(function* (if (!ITERM_FORMATS.has(info.format) || info.width === 0) {return notShown(info);}+ if (!fitsPassthrough(info)) return tooLarge(info);const size = graphicsSize();return art([encodeIterm(bytes, size, tmux)], size);}case "kitty": {if (info.format === "png" && info.width > 0) {+ if (!fitsPassthrough(info)) return tooLarge(info);const size = graphicsSize();return art([encodeKitty({ format: "png", bytes }, size, tmux)], size);}