⚡ 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): print recovery commands that work in every shell
Andrej60963ddecd5f
diff --git a/packages/cli/src/commands/task/create.ts b/packages/cli/src/commands/task/create.tsindex 500e09ae9..413101d28 100644--- a/packages/cli/src/commands/task/create.ts+++ b/packages/cli/src/commands/task/create.ts@@ -35,7 +35,7 @@ import { renderTaskChange } from "../../tasks/render-task-change.js";import { resolveAssignee } from "../../tasks/resolve-assignee.js";import { toTaskDetailJson } from "../../tasks/task-detail-json.js";import { readTextInput } from "../../input/read-text-input.js";-import { shellQuote } from "../../input/shell-quote.js";+import { shellSafeOr } from "../../input/shell-safe.js";import { ApiLayer } from "../api-layer.js";const PRIORITIES = ["no-priority", "low", "medium", "high", "urgent"] as const;@@ -149,7 +149,9 @@ 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;+ const createdTicket = ticketId(project.slug, created.number);+ const createdLabel = createdTicket ?? created.id;+ const createdArgument = shellSafeOr(createdTicket, created.id);const attached: ReadonlyArray<Label> =labels.length > 0? yield* withSpinner("Adding labels")(@@ -161,7 +163,7 @@ export const runTaskCreate = Effect.fn("command.task.create")((error) =>new InvalidArgument({message: `Created ${createdLabel}, but could not add the labels: ${describeError(error).message}`,- hint: `Add them with kaneo task edit ${shellQuote(createdLabel)} ${labels.map((label) => `--add-label ${shellQuote(label.name)}`).join(" ")}`,+ hint: `Add them with kaneo task edit ${createdArgument} ${labels.map((label) => `--add-label ${shellSafeOr(label.name, label.id)}`).join(" ")}`,}),),)@@ -169,6 +171,7 @@ export const runTaskCreate = Effect.fn("command.task.create")(const parentRef = yield* linkToParent(parent, {id: created.id,label: createdLabel,+ argument: createdArgument,});const json = toTaskDetailJson({diff --git a/packages/cli/src/input/shell-quote.test.ts b/packages/cli/src/input/shell-quote.test.tsdeleted file mode 100644index 7cdedc11c..000000000--- a/packages/cli/src/input/shell-quote.test.ts+++ /dev/null@@ -1,16 +0,0 @@-import { describe, expect, it } from "vite-plus/test";-import { shellQuote } from "./shell-quote.js";--describe("shellQuote", () => {- it("leaves simple words alone", () => {- expect(shellQuote("Bug")).toBe("Bug");- expect(shellQuote("KAN-12")).toBe("KAN-12");- });-- it("single quotes anything the shell would interpret", () => {- expect(shellQuote('Needs "QA"')).toBe(`'Needs "QA"'`);- expect(shellQuote("$(rm -rf ~)")).toBe(`'$(rm -rf ~)'`);- expect(shellQuote("it's done")).toBe(`'it'\\''s done'`);- expect(shellQuote("")).toBe("''");- });-});diff --git a/packages/cli/src/input/shell-quote.ts b/packages/cli/src/input/shell-quote.tsdeleted file mode 100644index 6041ca37c..000000000--- a/packages/cli/src/input/shell-quote.ts+++ /dev/null@@ -1,6 +0,0 @@-const SAFE = /^[A-Za-z0-9_@%+=:,./-]+$/;--export function shellQuote(value: string): string {- if (SAFE.test(value)) return value;- return `'${value.replaceAll("'", `'\\''`)}'`;-}diff --git a/packages/cli/src/input/shell-safe.test.ts b/packages/cli/src/input/shell-safe.test.tsnew file mode 100644index 000000000..9d1e3b57d--- /dev/null+++ b/packages/cli/src/input/shell-safe.test.ts@@ -0,0 +1,38 @@+import { describe, expect, it } from "vite-plus/test";+import { isShellSafe, shellSafeOr } from "./shell-safe.js";++describe("isShellSafe", () => {+ it("accepts tokens that need no quoting in any shell", () => {+ expect(isShellSafe("Bug")).toBe(true);+ expect(isShellSafe("KAN-12")).toBe(true);+ expect(isShellSafe("quoxax9njxycy4ws7pxuvmk5")).toBe(true);+ });++ it("rejects anything a POSIX shell, cmd or PowerShell would interpret", () => {+ for (const value of [+ 'Needs "QA"',+ "it's",+ "$(rm)",+ "a b",+ "a&b",+ "a|b",+ "a^b",+ "%PATH%",+ "a,b",+ "@a",+ "-rf",+ "",+ "Ä-1",+ ]) {+ expect(isShellSafe(value)).toBe(false);+ }+ });+});++describe("shellSafeOr", () => {+ it("falls back to an always safe token", () => {+ expect(shellSafeOr("KAN-12", "id1")).toBe("KAN-12");+ expect(shellSafeOr('Needs "QA"', "lbl_1")).toBe("lbl_1");+ expect(shellSafeOr(null, "task_1")).toBe("task_1");+ });+});diff --git a/packages/cli/src/input/shell-safe.ts b/packages/cli/src/input/shell-safe.tsnew file mode 100644index 000000000..cf66edcbe--- /dev/null+++ b/packages/cli/src/input/shell-safe.ts@@ -0,0 +1,9 @@+const SAFE = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;++export function isShellSafe(value: string): boolean {+ return SAFE.test(value);+}++export function shellSafeOr(value: string | null, fallback: string): string {+ return value !== null && isShellSafe(value) ? value : fallback;+}diff --git a/packages/cli/src/relations/link-subtask.test.ts b/packages/cli/src/relations/link-subtask.test.tsindex 8f6f330b6..4aefa0b37 100644--- a/packages/cli/src/relations/link-subtask.test.ts+++ b/packages/cli/src/relations/link-subtask.test.ts@@ -56,9 +56,11 @@ function run(respond: Responder) {),),);- const effect = linkToParent(parent, { id: "child", label: "KAN-9" }).pipe(- Effect.provide(Layer.mergeAll(api, captureOutput().layer)),- );+ const effect = linkToParent(parent, {+ id: "child",+ label: "KAN-9",+ argument: "KAN-9",+ }).pipe(Effect.provide(Layer.mergeAll(api, captureOutput().layer)));return { recorded, result: Effect.runPromise(Effect.result(effect)) };}@@ -106,7 +108,11 @@ describe("linkToParent", () => {});it("does nothing without a parent", async () => {- const effect = linkToParent(undefined, { id: "child", label: "KAN-9" });+ const effect = linkToParent(undefined, {+ id: "child",+ label: "KAN-9",+ argument: "KAN-9",+ });expect(await Effect.runPromise(effect.pipe(diff --git a/packages/cli/src/relations/link-subtask.ts b/packages/cli/src/relations/link-subtask.tsindex 132c340b0..84eed49a3 100644--- a/packages/cli/src/relations/link-subtask.ts+++ b/packages/cli/src/relations/link-subtask.ts@@ -2,7 +2,6 @@ import { Effect, Option } from "effect";import { createTaskRelation } from "../api/task-relations.js";import { describeError } from "../errors/describe.js";import { InvalidArgument } from "../errors/errors.js";-import { shellQuote } from "../input/shell-quote.js";import { withSpinner } from "../output/spinner.js";import { type ResolvedTask, resolveTask } from "../tasks/resolve-task.js";import { toApiRelation } from "./relation-types.js";@@ -36,7 +35,11 @@ export function projectOrParent(export const linkToParent = Effect.fn("relations.linkToParent")(function* (parent: ResolvedTask | undefined,- child: { readonly id: string; readonly label: string },+ child: {+ readonly id: string;+ readonly label: string;+ readonly argument: string;+ },) {if (!parent) return null;const ref: TaskRef = taskRef(parent);@@ -48,7 +51,7 @@ export const linkToParent = Effect.fn("relations.linkToParent")(function* ((error) =>new InvalidArgument({message: `Created ${child.label}, but could not make it a subtask of ${parentLabel}: ${describeError(error).message}`,- hint: `Link it with kaneo task relation add ${shellQuote(child.label)} subtask-of ${shellQuote(taskArgument(ref))}`,+ hint: `Link it with kaneo task relation add ${child.argument} subtask-of ${taskArgument(ref)}`,}),),);diff --git a/packages/cli/src/relations/task-ref.ts b/packages/cli/src/relations/task-ref.tsindex 11c4ee1c4..e4e7c043c 100644--- a/packages/cli/src/relations/task-ref.ts+++ b/packages/cli/src/relations/task-ref.ts@@ -1,3 +1,4 @@+import { shellSafeOr } from "../input/shell-safe.js";import type { ResolvedTask } from "../tasks/resolve-task.js";export type TaskRef = {@@ -21,5 +22,5 @@ export function taskLabel(task: TaskRef): string {}export function taskArgument(task: TaskRef): string {- return task.ticketId ?? task.id;+ return shellSafeOr(task.ticketId, task.id);}