@zinn-dev/cli 0.39.0 → 0.40.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.
Files changed (93) hide show
  1. package/README.md +5 -2
  2. package/index.d.ts +2 -0
  3. package/index.js +23 -0
  4. package/package.json +22 -18
  5. package/src/actor.d.ts +6 -0
  6. package/src/actor.js +62 -0
  7. package/src/database.d.ts +6 -0
  8. package/src/database.js +27 -0
  9. package/src/lib.d.ts +31 -0
  10. package/src/lib.js +137 -0
  11. package/src/presentation/activity-presentation.d.ts +23 -0
  12. package/src/presentation/activity-presentation.js +389 -0
  13. package/src/presentation/color.d.ts +9 -0
  14. package/src/presentation/color.js +21 -0
  15. package/src/presentation/column-presentation.d.ts +16 -0
  16. package/src/presentation/column-presentation.js +29 -0
  17. package/src/presentation/description-presentation.d.ts +3 -0
  18. package/src/presentation/description-presentation.js +11 -0
  19. package/src/presentation/row-layout.d.ts +22 -0
  20. package/src/presentation/row-layout.js +58 -0
  21. package/src/presentation/section.d.ts +4 -0
  22. package/src/presentation/section.js +9 -0
  23. package/src/presentation/task-presentation.d.ts +17 -0
  24. package/src/presentation/task-presentation.js +62 -0
  25. package/src/presentation/time.d.ts +1 -0
  26. package/src/presentation/time.js +13 -0
  27. package/src/project.d.ts +6 -0
  28. package/src/project.js +31 -0
  29. package/src/release-identity.d.ts +2 -0
  30. package/src/release-identity.js +1 -0
  31. package/src/routes/activity-router.d.ts +10 -0
  32. package/src/routes/{activity-router.ts → activity-router.js} +36 -46
  33. package/src/routes/backup-router.d.ts +4 -0
  34. package/src/routes/backup-router.js +18 -0
  35. package/src/routes/comment-router.d.ts +24 -0
  36. package/src/routes/comment-router.js +134 -0
  37. package/src/routes/label-router.d.ts +18 -0
  38. package/src/routes/label-router.js +136 -0
  39. package/src/routes/migrate-router.d.ts +4 -0
  40. package/src/routes/migrate-router.js +37 -0
  41. package/src/routes/project-router.d.ts +40 -0
  42. package/src/routes/project-router.js +328 -0
  43. package/src/routes/reindex-router.d.ts +4 -0
  44. package/src/routes/reindex-router.js +21 -0
  45. package/src/routes/relation-router.d.ts +28 -0
  46. package/src/routes/relation-router.js +163 -0
  47. package/src/routes/restore-router.d.ts +4 -0
  48. package/src/routes/restore-router.js +71 -0
  49. package/src/routes/router.d.ts +6 -0
  50. package/src/routes/router.js +185 -0
  51. package/src/routes/routes.d.ts +170 -0
  52. package/src/routes/routes.js +19 -0
  53. package/src/routes/task-router.d.ts +84 -0
  54. package/src/routes/task-router.js +533 -0
  55. package/src/text-edit.d.ts +25 -0
  56. package/src/text-edit.js +45 -0
  57. package/src/types.d.ts +10 -0
  58. package/src/types.js +1 -0
  59. package/index.ts +0 -26
  60. package/release-stamp.json +0 -1
  61. package/src/actor.test.ts +0 -41
  62. package/src/actor.ts +0 -78
  63. package/src/database.test.ts +0 -70
  64. package/src/database.ts +0 -41
  65. package/src/lib.test.ts +0 -86
  66. package/src/lib.ts +0 -159
  67. package/src/presentation/activity-presentation.test.ts +0 -112
  68. package/src/presentation/activity-presentation.ts +0 -490
  69. package/src/presentation/color.ts +0 -29
  70. package/src/presentation/column-presentation.ts +0 -48
  71. package/src/presentation/description-presentation.ts +0 -18
  72. package/src/presentation/row-layout.ts +0 -77
  73. package/src/presentation/section.ts +0 -16
  74. package/src/presentation/task-presentation.ts +0 -92
  75. package/src/presentation/time.ts +0 -17
  76. package/src/project.test.ts +0 -479
  77. package/src/project.ts +0 -53
  78. package/src/routes/backup-router.ts +0 -24
  79. package/src/routes/comment-router.ts +0 -171
  80. package/src/routes/label-router.ts +0 -168
  81. package/src/routes/migrate-router.test.ts +0 -31
  82. package/src/routes/migrate-router.ts +0 -48
  83. package/src/routes/project-router.ts +0 -415
  84. package/src/routes/reindex-router.ts +0 -27
  85. package/src/routes/relation-router.ts +0 -194
  86. package/src/routes/restore-router.test.ts +0 -44
  87. package/src/routes/restore-router.ts +0 -90
  88. package/src/routes/router.test.ts +0 -136
  89. package/src/routes/router.ts +0 -248
  90. package/src/routes/routes.ts +0 -20
  91. package/src/routes/task-router.ts +0 -649
  92. package/src/text-edit.ts +0 -68
  93. package/src/types.ts +0 -6
package/src/actor.test.ts DELETED
@@ -1,41 +0,0 @@
1
- import type { Actor } from "@zinn-dev/core";
2
-
3
- import { expect, test } from "bun:test";
4
-
5
- import { detectAgent } from "./actor";
6
-
7
- const agent = (name: string): Actor => ({ name, email: null, kind: "agent" });
8
-
9
- test("AI_AGENT is recorded as given, ahead of tool markers", () => {
10
- expect(detectAgent({ AI_AGENT: "claude-code_2-1-280_agent", CLAUDECODE: "1" })).toEqual(
11
- agent("claude-code_2-1-280_agent"),
12
- );
13
- expect(detectAgent({ AI_AGENT: "hermes" })).toEqual(agent("hermes"));
14
- });
15
-
16
- test("AGENT comes before CLAUDECODE, since Amp sets both", () => {
17
- expect(detectAgent({ AGENT: "amp", CLAUDECODE: "1" })).toEqual(agent("amp"));
18
- });
19
-
20
- test("tool-specific markers map to fixed names", () => {
21
- const cases: Array<[Record<string, string>, string]> = [
22
- [{ CLAUDECODE: "1" }, "claude-code"],
23
- [{ CODEX_THREAD_ID: "thread" }, "codex"],
24
- [{ CODEX_SANDBOX: "seatbelt" }, "codex"],
25
- [{ OPENCODE: "1" }, "opencode"],
26
- [{ GEMINI_CLI: "1" }, "gemini-cli"],
27
- [{ CLINE_ACTIVE: "true" }, "cline"],
28
- [{ CURSOR_AGENT: "1" }, "cursor"],
29
- [{ COPILOT_AGENT_SESSION_ID: "session" }, "copilot"],
30
- [{ CRUSH: "1" }, "crush"],
31
- ];
32
-
33
- for (const [env, name] of cases) {
34
- expect(detectAgent(env)).toEqual(agent(name));
35
- }
36
- });
37
-
38
- test("empty or unrelated variables are not agents", () => {
39
- expect(detectAgent({})).toBeNull();
40
- expect(detectAgent({ AI_AGENT: " ", AGENT: "", HOME: "/home/someone" })).toBeNull();
41
- });
package/src/actor.ts DELETED
@@ -1,78 +0,0 @@
1
- import type { Actor } from "@zinn-dev/core";
2
-
3
- import { execFileSync } from "node:child_process";
4
- import { userInfo } from "node:os";
5
-
6
- type Env = Record<string, string | undefined>;
7
- type AgentMarker = { variables: Array<string>; name: string | null };
8
-
9
- /**
10
- * Environment variables that coding agents set in the shells they run.
11
- * Undetected tools can set `AI_AGENT` through their own env configuration.
12
- */
13
- const AGENT_MARKERS: Array<AgentMarker> = [
14
- { variables: ["AI_AGENT"], name: null },
15
- { variables: ["AGENT"], name: null },
16
- { variables: ["CLAUDECODE"], name: "claude-code" },
17
- { variables: ["CODEX_THREAD_ID", "CODEX_SANDBOX"], name: "codex" },
18
- { variables: ["OPENCODE"], name: "opencode" },
19
- { variables: ["GEMINI_CLI"], name: "gemini-cli" },
20
- { variables: ["CLINE_ACTIVE"], name: "cline" },
21
- { variables: ["CURSOR_AGENT"], name: "cursor" },
22
- { variables: ["COPILOT_AGENT_SESSION_ID"], name: "copilot" },
23
- { variables: ["CRUSH"], name: "crush" },
24
- ];
25
-
26
- /** A marker without a fixed name records the variable's own value, e.g. `AI_AGENT=claude-code_2-1-280_agent`. */
27
- export function detectAgent(env: Env): Actor | null {
28
- for (const marker of AGENT_MARKERS) {
29
- for (const variable of marker.variables) {
30
- const value = env[variable]?.trim();
31
- if (value == null || value.length === 0) {
32
- continue;
33
- }
34
-
35
- return { name: marker.name ?? value, email: null, kind: "agent" };
36
- }
37
- }
38
-
39
- return null;
40
- }
41
-
42
- function readGitConfig(key: string) {
43
- try {
44
- const value = execFileSync("git", ["config", key], {
45
- encoding: "utf-8",
46
- stdio: ["ignore", "pipe", "ignore"],
47
- }).trim();
48
-
49
- return value.length > 0 ? value : null;
50
- } catch {
51
- // git is missing or the key is unset
52
- return null;
53
- }
54
- }
55
-
56
- function resolveActor(): Actor {
57
- const agent = detectAgent(process.env);
58
- if (agent != null) {
59
- return agent;
60
- }
61
-
62
- const gitName = readGitConfig("user.name");
63
- if (gitName != null) {
64
- return { name: gitName, email: readGitConfig("user.email"), kind: "human" };
65
- }
66
-
67
- return { name: userInfo().username, email: null, kind: "human" };
68
- }
69
-
70
- let actor: Actor | null = null;
71
-
72
- export function currentActor(): Actor {
73
- if (actor == null) {
74
- actor = resolveActor();
75
- }
76
-
77
- return actor;
78
- }
@@ -1,70 +0,0 @@
1
- import { expect, spyOn, test } from "bun:test";
2
- import { existsSync } from "node:fs";
3
- import { join } from "node:path";
4
- import { fileURLToPath } from "node:url";
5
-
6
- import packageJson from "../package.json";
7
- import { cliOpenPolicy, reportLegacyRead, reportLockWait } from "./database";
8
- import { setLegacyReadAllowed } from "./lib";
9
-
10
- const CLI_DIRECTORY = fileURLToPath(new URL("..", import.meta.url));
11
- // The file name core's release reading looks for.
12
- const RELEASE_STAMP_FILE = "release-stamp.json";
13
-
14
- test("the CLI opens the database as the cli client of its own release mode, without legacy reads", () => {
15
- const { onWait, onLegacyRead, ...policy } = cliOpenPolicy();
16
- const stderr = spyOn(console, "error").mockImplementation(() => {});
17
-
18
- try {
19
- onWait?.({ databasePath: "/data/zinn.sqlite", budgetMs: 30000 });
20
-
21
- expect(policy).toEqual({
22
- client: "cli",
23
- version: packageJson.version,
24
- executable: process.argv[1] ?? process.execPath,
25
- release: "source",
26
- allowsLegacyRead: false,
27
- });
28
- expect(onWait).toBe(reportLockWait);
29
- expect(stderr.mock.calls).toEqual([
30
- ["Another process is using the database. Waiting up to 30 seconds for it to finish."],
31
- ]);
32
- } finally {
33
- stderr.mockRestore();
34
- }
35
- });
36
-
37
- test("the policy allows legacy reads only once --allow-legacy-read was handled", () => {
38
- const policy = cliOpenPolicy();
39
-
40
- try {
41
- expect(policy.allowsLegacyRead).toBe(false);
42
- setLegacyReadAllowed(true);
43
- expect(policy.allowsLegacyRead).toBe(true);
44
- } finally {
45
- setLegacyReadAllowed(false);
46
- }
47
- });
48
-
49
- test("the policy warns on stderr about the unmarked database that opened for reading", () => {
50
- const stderr = spyOn(console, "error").mockImplementation(() => {});
51
-
52
- try {
53
- expect(cliOpenPolicy().onLegacyRead).toBe(reportLegacyRead);
54
- reportLegacyRead({ databasePath: "/data/zinn.sqlite", version: 0, latestVersion: 1 });
55
-
56
- expect(stderr.mock.calls).toHaveLength(1);
57
- expect(stderr.mock.calls[0]![0]).toContain("/data/zinn.sqlite");
58
- expect(stderr.mock.calls[0]![0]).toContain("no schema version");
59
- } finally {
60
- stderr.mockRestore();
61
- }
62
- });
63
-
64
- test("this source folder has no stamp", () => {
65
- expect(existsSync(join(CLI_DIRECTORY, RELEASE_STAMP_FILE))).toBe(false);
66
- });
67
-
68
- test("the published package includes the stamp", () => {
69
- expect(packageJson.files).toContain(RELEASE_STAMP_FILE);
70
- });
package/src/database.ts DELETED
@@ -1,41 +0,0 @@
1
- import type { DatabaseFacts, LockWait, OpenPolicy } from "@zinn-dev/core";
2
-
3
- import { fileURLToPath } from "node:url";
4
- import { readReleaseMode } from "@zinn-dev/core";
5
-
6
- import packageJson from "../package.json";
7
- import { isLegacyReadAllowed } from "./lib";
8
-
9
- const MS_PER_SECOND = 1000;
10
- /** The CLI's package folder, which holds its release stamp once it is packed. */
11
- const PACKAGE_DIRECTORY = fileURLToPath(new URL("..", import.meta.url));
12
-
13
- /** Says once on stderr that the command waits for another process to finish with the database. */
14
- export function reportLockWait({ budgetMs }: LockWait) {
15
- console.error(
16
- `Another process is using the database. Waiting up to ${budgetMs / MS_PER_SECOND} seconds for it to finish.`,
17
- );
18
- }
19
-
20
- export function reportLegacyRead({ databasePath }: DatabaseFacts) {
21
- console.error(
22
- `Warning: the database at ${databasePath} has no schema version. Reads are best effort and may fail or omit data.`,
23
- );
24
- }
25
-
26
- /** How the CLI asks core to open the database. */
27
- export function cliOpenPolicy(): OpenPolicy {
28
- return {
29
- client: "cli",
30
- version: packageJson.version,
31
- // The script the CLI runs from; the runtime itself when there is none.
32
- executable: process.argv[1] ?? process.execPath,
33
- release: readReleaseMode(PACKAGE_DIRECTORY),
34
- // Read when the database opens, after the router has handled `--allow-legacy-read`
35
- get allowsLegacyRead() {
36
- return isLegacyReadAllowed();
37
- },
38
- onWait: reportLockWait,
39
- onLegacyRead: reportLegacyRead,
40
- };
41
- }
package/src/lib.test.ts DELETED
@@ -1,86 +0,0 @@
1
- import type { OpenPolicy } from "@zinn-dev/core";
2
-
3
- import { expect, test } from "bun:test";
4
- import { ReadOnlyDatabaseError, TextEditMatchError, UnmarkedDatabaseError } from "@zinn-dev/core";
5
-
6
- import { failureMessage, UsageError, validatePositionals } from "./lib";
7
-
8
- const FALLBACK = "Something went wrong";
9
- const POLICY: OpenPolicy = {
10
- client: "cli",
11
- version: "1.0.0",
12
- executable: "/test/zinn",
13
- release: "source",
14
- allowsLegacyRead: false,
15
- };
16
-
17
- function readOnlyError(reason: "older" | "newer" | "unmarked") {
18
- const versions = { older: 1, newer: 3, unmarked: 0 };
19
- const version = versions[reason];
20
- return new ReadOnlyDatabaseError(
21
- reason,
22
- { databasePath: "/data/zinn.sqlite", version, latestVersion: 2 },
23
- POLICY,
24
- );
25
- }
26
-
27
- test("an older database that stays read-only points at zinn migrate in the same line", () => {
28
- const error = readOnlyError("older");
29
-
30
- expect(failureMessage(error, FALLBACK)).toBe(
31
- `${error.message}. Run \`zinn migrate\` to upgrade it.`,
32
- );
33
- });
34
-
35
- test("other failures keep their own message, or the fallback when they have none", () => {
36
- const newer = readOnlyError("newer");
37
-
38
- expect(failureMessage(newer, FALLBACK)).toBe(newer.message);
39
- expect(failureMessage(new Error("Task does not exist"), FALLBACK)).toBe("Task does not exist");
40
- expect(failureMessage(undefined, FALLBACK)).toBe(FALLBACK);
41
- });
42
-
43
- test("an unmarked database that was not opened names --allow-legacy-read", () => {
44
- const error = new UnmarkedDatabaseError({
45
- databasePath: "/data/zinn.sqlite",
46
- version: 0,
47
- latestVersion: 2,
48
- });
49
- const message = failureMessage(error, FALLBACK);
50
-
51
- expect(message).toStartWith(error.message);
52
- expect(message).toContain("/data/zinn.sqlite");
53
- expect(message).toContain("--allow-legacy-read");
54
- });
55
-
56
- test("an unmarked database opened for reading refuses changes without pointing at the flag", () => {
57
- const error = readOnlyError("unmarked");
58
-
59
- expect(failureMessage(error, FALLBACK)).toBe(error.message);
60
- });
61
-
62
- test("a text edit that matches several places points at --all, and one that matches none does not", () => {
63
- const several = new TextEditMatchError(3, "ZINN-1's description");
64
- const none = new TextEditMatchError(0, "ZINN-1's description");
65
-
66
- expect(failureMessage(several, FALLBACK)).toBe(
67
- `${several.message} Use --all to replace every match.`,
68
- );
69
- expect(failureMessage(none, FALLBACK)).toBe(none.message);
70
- });
71
-
72
- test("validatePositionals names the first missing word, or the first word past the most it takes", () => {
73
- const words = ["<project-key>", "<column-name>"];
74
-
75
- expect(() => validatePositionals(["SHOP", "Later"], words)).not.toThrow();
76
- expect(() => validatePositionals(["SHOP"], words)).toThrow(UsageError);
77
- expect(() => validatePositionals(["SHOP"], words)).toThrow("<column-name>");
78
- expect(() => validatePositionals([], words)).toThrow("<project-key>");
79
- expect(() => validatePositionals(["SHOP", "Needs", "Review", "Now"], words)).toThrow('"Review"');
80
-
81
- // ? Written as in the usage lines: [...] marks an optional word and a trailing ... a word that repeats.
82
- expect(() => validatePositionals([], ["[<project-key>]"])).not.toThrow();
83
- expect(() => validatePositionals(["SHOP", "extra"], ["[<project-key>]"])).toThrow('"extra"');
84
- expect(() => validatePositionals(["A-1", "A-2", "A-3"], ["<task-key>..."])).not.toThrow();
85
- expect(() => validatePositionals(["A-1"], ["<task-key>...", "<target-column>"])).toThrow("<target-column>");
86
- });
package/src/lib.ts DELETED
@@ -1,159 +0,0 @@
1
- import type { parseArgs } from "node:util";
2
-
3
- import {
4
- assertWritable,
5
- ReadOnlyDatabaseError,
6
- TextEditMatchError,
7
- UnmarkedDatabaseError,
8
- } from "@zinn-dev/core";
9
-
10
- type ParsedTokens = NonNullable<ReturnType<typeof parseArgs>["tokens"]>;
11
- type OutputMode = "text" | "json";
12
-
13
- let outputMode: OutputMode = "text";
14
- let legacyReadAllowed = false;
15
-
16
- export function setOutputMode(mode: OutputMode) {
17
- outputMode = mode;
18
- }
19
-
20
- export function isJsonFlag(flag: string) {
21
- return flag === "--json";
22
- }
23
-
24
- export function isAllowLegacyReadFlag(flag: string) {
25
- return flag === "--allow-legacy-read";
26
- }
27
-
28
- export function setLegacyReadAllowed(allowed: boolean) {
29
- legacyReadAllowed = allowed;
30
- }
31
-
32
- export function isLegacyReadAllowed() {
33
- return legacyReadAllowed;
34
- }
35
-
36
- export function output<T>(data: T, transformToString: (data: T) => string) {
37
- if (outputMode === "json") {
38
- console.info(JSON.stringify(data, null, 2));
39
- return;
40
- }
41
-
42
- const dataText = transformToString(data);
43
-
44
- if (dataText.length > 0) {
45
- console.info(dataText);
46
- }
47
- }
48
-
49
- /** Asks before a change that cannot be undone, unless --yes already confirmed it. */
50
- export function confirmAction(message: string, isPreconfirmed: boolean, jsonRefusal?: string) {
51
- // Throws on a read-only database, to avoid asking for confirmation to an already refused action
52
- assertWritable();
53
-
54
- return askConfirmation(message, isPreconfirmed, jsonRefusal);
55
- }
56
-
57
- /** Like confirmAction, without opening the database, for commands that bypass the open policy. */
58
- export function askConfirmation(
59
- message: string,
60
- isPreconfirmed: boolean,
61
- jsonRefusal = "Commands that ask for confirmation need --yes when used with --json",
62
- ) {
63
- if (isPreconfirmed) {
64
- return true;
65
- }
66
-
67
- if (outputMode === "json") {
68
- quit(jsonRefusal);
69
- }
70
-
71
- // Refuses rather than treating an unanswered prompt as declined, so scripts do not see a false success
72
- if (!canPrompt()) {
73
- quit("Commands that ask for confirmation need --yes when not running in a terminal");
74
- }
75
-
76
- return confirm(message);
77
- }
78
-
79
- /** Whether someone can answer a prompt: stdin and stdout are both terminals, like how gh decides it. */
80
- export function canPrompt() {
81
- return process.stdin.isTTY === true && process.stdout.isTTY === true;
82
- }
83
-
84
- /** The message to report for a failed command, or fallback when the error has none. */
85
- export function failureMessage(error: any, fallback: string) {
86
- const isOlderReadOnly = error instanceof ReadOnlyDatabaseError && error.reason === "older";
87
- if (isOlderReadOnly) {
88
- return `${error.message}. Run \`zinn migrate\` to upgrade it.`;
89
- }
90
-
91
- if (error instanceof UnmarkedDatabaseError) {
92
- return `${error.message}. Add --allow-legacy-read to read it anyway.`;
93
- }
94
-
95
- if (error instanceof TextEditMatchError && error.matchCount > 1) {
96
- return `${error.message} Use --all to replace every match.`;
97
- }
98
-
99
- if (error?.message === "no such table: task_search") {
100
- return `${error.message}. Run \`zinn reindex\` to rebuild the search index.`;
101
- }
102
-
103
- return error?.message ?? fallback;
104
- }
105
-
106
- /** Prints the reason as an error, followed by help when given, and exits with code 1. */
107
- export function quit(reason: string, help?: string): never {
108
- if (outputMode === "json") {
109
- const error = help == null ? { message: reason } : { message: reason, help };
110
- console.error(JSON.stringify({ error }, null, 2));
111
- } else {
112
- console.error(help == null ? reason : `${reason}\n\n${help}`);
113
- }
114
-
115
- process.exit(1);
116
- }
117
-
118
- /** A command was given the wrong words. The router prints the message with the command's usage lines. */
119
- export class UsageError extends Error {}
120
-
121
- /**
122
- * Checks a command's words against its usage line, with the words written the same way:
123
- * `<task-key>` is required, `[<project-key>]` is optional and `<task-key>...` repeats.
124
- * Optional words go last.
125
- */
126
- export function validatePositionals(positionals: Array<string>, words: Array<string>) {
127
- const requiredWords = words.filter((word) => !word.startsWith("["));
128
- const missingWord = requiredWords[positionals.length];
129
- if (missingWord !== undefined) {
130
- throw new UsageError(`Missing argument ${missingWord}`);
131
- }
132
-
133
- const hasRepeatingWord = words.some((word) => word.endsWith("..."));
134
- const extraWord = positionals[words.length];
135
- if (!hasRepeatingWord && extraWord !== undefined) {
136
- throw new UsageError(`Unexpected argument "${extraWord}"`);
137
- }
138
- }
139
-
140
- export function validateUniqueOptions(tokens: ParsedTokens, repeatableOptions: Array<string> = []) {
141
- const parsedArgs = new Set<string>();
142
-
143
- for (const token of tokens) {
144
- if (token.kind !== "option") {
145
- continue;
146
- }
147
-
148
- const isRepeatable = repeatableOptions.includes(token.name);
149
- if (parsedArgs.has(token.name) && !isRepeatable) {
150
- quit(`Option "--${token.name}" can only be specified once`);
151
- }
152
-
153
- parsedArgs.add(token.name);
154
- }
155
- }
156
-
157
- export function isHelpFlag(flag: string) {
158
- return ["-h", "--help"].includes(flag);
159
- }
@@ -1,112 +0,0 @@
1
- import type { Activity } from "@zinn-dev/core";
2
-
3
- import { expect, test } from "bun:test";
4
- import { abbreviateActivityIds, formatActivityList } from "./activity-presentation";
5
-
6
- test("activity abbreviations are shortest unique canonical prefixes across all supplied IDs", () => {
7
- const first = "019abcdf-1234-7000-8000-123456abcde1";
8
- const second = "019abcdf-1234-7000-8000-123456abcde2";
9
- const earlier = "019abcdf-0234-7000-8000-123456abcde1";
10
- const separate = "019abcda-1234-7000-8000-123456abcde1";
11
- const prefixes = abbreviateActivityIds([second, separate, first, earlier]);
12
- expect(prefixes.get(first)).toBe(first);
13
- expect(prefixes.get(second)).toBe(second);
14
- expect(prefixes.get(earlier)).toBe("019abcdf-0");
15
- expect(prefixes.get(separate)).toBe("019abcda");
16
- expect(abbreviateActivityIds([first]).get(first)).toBe("019abcdf");
17
- });
18
-
19
- test("activity text keeps full task identities when a long reused key needs disambiguation", () => {
20
- const event: Activity = {
21
- id: "019abcdf-1234-7000-8000-123456abcde1", created_at: 1,
22
- actor_name: "Test", actor_email: null, actor_kind: "human",
23
- entity_type: "task", entity_id: "019abcdf-1234-7000-8000-123456abcde2",
24
- action: "archive", changes: null,
25
- };
26
- const text = formatActivityList([{ event, displayId: "019abcdf", removedTasks: [],
27
- navigation: { name: `${"A".repeat(100)}-1`, status: "deleted", distinguishesTaskId: true } }]);
28
- expect(text).toContain(event.entity_id);
29
- expect(text).toContain("deleted");
30
- expect(text).toContain("archive");
31
- });
32
-
33
- test("activity details keep explicit empty containers distinct from null changes", () => {
34
- const event: Activity = {
35
- id: "019abcdf-1234-7000-8000-123456abcde1", created_at: 1,
36
- actor_name: "Test", actor_email: null, actor_kind: "human",
37
- entity_type: "task", entity_id: "019abcdf-1234-7000-8000-123456abcde2",
38
- action: "create", changes: { labels: [], column: {} },
39
- };
40
- const entry = { event, displayId: event.id, removedTasks: [],
41
- navigation: { name: "APP-1", status: "current" as const } };
42
- const text = formatActivityList([entry], { showsDetails: true });
43
- expect(text).toContain("labels:\n[]");
44
- expect(text).toContain("column:\n{}");
45
- expect(formatActivityList([{ ...entry, event: { ...event, changes: null } }], { showsDetails: true }))
46
- .toContain("Changes:\nnull");
47
- });
48
-
49
- test("task rows for a shared key mark only deleted tasks and keep every task ID", () => {
50
- const event: Activity = {
51
- id: "019abcdf-1234-7000-8000-123456abcde1", created_at: 1,
52
- actor_name: "Test", actor_email: null, actor_kind: "human",
53
- entity_type: "task", entity_id: "current-task", action: "edit", changes: null,
54
- };
55
- const identities = [
56
- { id: "current-task", status: "current" as const },
57
- { id: "archived-task", status: "archived" as const },
58
- { id: "first-deleted-task", status: "deleted" as const },
59
- { id: "second-deleted-task", status: "deleted" as const },
60
- ];
61
- for (const identity of identities) {
62
- const entry = {
63
- event: { ...event, entity_id: identity.id }, displayId: event.id, removedTasks: [],
64
- navigation: { name: "APP-1", status: identity.status, distinguishesTaskId: true },
65
- };
66
- const text = formatActivityList([entry]);
67
- expect(text.split("\n")[0]!.split(" · ")[0]!.includes("deleted")).toBe(identity.status === "deleted");
68
- expect(text).toContain(identity.id);
69
- }
70
- });
71
-
72
- test("project deletion keeps its project and removed-task identities visible", () => {
73
- const event: Activity = {
74
- id: "019abcdf-1234-7000-8000-123456abcde1", created_at: 1,
75
- actor_name: "Test", actor_email: null, actor_kind: "human",
76
- entity_type: "project", entity_id: "old-project", action: "delete",
77
- changes: { key: "APP", tasks: [{ id: "old-task", key: "APP-1", title: "Old task" }] },
78
- };
79
- const text = formatActivityList([{
80
- event, displayId: event.id,
81
- navigation: { name: "APP", status: "deleted" },
82
- removedTasks: [{ id: "old-task", key: "APP-1", title: "Old task", status: "deleted" }],
83
- }]);
84
- expect(text.split("\n")[0]!.split(" · ")[0]).toContain("deleted");
85
- expect(text).toContain("APP-1");
86
- expect(text).toContain("old-task");
87
- });
88
-
89
- test("long entity identities do not pad neighboring activity descriptions", () => {
90
- const event: Activity = {
91
- id: "019abcdf-1234-7000-8000-123456abcde1", created_at: 1,
92
- actor_name: "Test", actor_email: null, actor_kind: "human",
93
- entity_type: "task", entity_id: "task-id", action: "archive", changes: null,
94
- };
95
- const short = { event, displayId: "019abcdf", removedTasks: [],
96
- navigation: { name: "APP-1", status: "archived" as const } };
97
- const longKey = "PB137E58A84AC41B5A704693239312DF2";
98
- const outlier = { ...short, displayId: "019abcda",
99
- event: { ...event, id: "019abcda-1234-7000-8000-123456abcde1", entity_type: "project" as const,
100
- action: "delete" as const, changes: { key: longKey, name: "Active ordering tail" } },
101
- navigation: { name: longKey, status: "deleted" as const } };
102
- const alone = formatActivityList([short]);
103
- const together = formatActivityList([short, outlier]);
104
- expect(together.split("\n")[0]).toBe(alone);
105
- expect(alone).toContain("APP-1 · archived");
106
- expect(alone).not.toContain("[archived]");
107
- expect(together).toContain(`Full project key: ${longKey}`);
108
- const contentColumn = alone.indexOf("APP-1");
109
- expect(together.split("\n").find((line) => line.includes("Full project key:"))!.indexOf("Full project key:"))
110
- .toBe(contentColumn);
111
- expect(together.split("\n")[1]).not.toContain(longKey);
112
- });