gemiterm 2.0.0 → 2.1.1

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 (155) hide show
  1. package/README.md +32 -9
  2. package/package.json +13 -4
  3. package/src/cli/command-registry.ts +66 -62
  4. package/src/cli/commands/continue-command.ts +75 -1
  5. package/src/cli/commands/install-skills-command.ts +35 -0
  6. package/src/cli/commands/new-command.ts +62 -0
  7. package/src/cli/index.ts +19 -44
  8. package/src/cli/utils/long-arg-guard.ts +28 -0
  9. package/src/cli/utils/prompt-file.ts +26 -0
  10. package/src/infrastructure/cli-parser.ts +77 -0
  11. package/src/infrastructure/io.ts +9 -0
  12. package/src/services/skills-cli-driver.ts +58 -0
  13. package/src/services/skills-service.ts +52 -0
  14. package/.env +0 -2
  15. package/.github/workflows/manual-release.yml +0 -34
  16. package/.github/workflows/release.yml +0 -198
  17. package/.github/workflows/test.yml +0 -29
  18. package/.opencode/commands/opsx-apply.md +0 -152
  19. package/.opencode/commands/opsx-archive.md +0 -157
  20. package/.opencode/commands/opsx-explore.md +0 -169
  21. package/.opencode/commands/opsx-propose.md +0 -104
  22. package/.opencode/commands/opsx-sync.md +0 -140
  23. package/.opencode/commands/search-intelligently.md +0 -9
  24. package/.opencode/opencode.json +0 -20
  25. package/.opencode/skills/intellisearch/.version +0 -1
  26. package/.opencode/skills/intellisearch/SKILL.md +0 -84
  27. package/.opencode/skills/intellisearch/references/brave-search.md +0 -67
  28. package/.opencode/skills/intellisearch/references/ddg-search.md +0 -79
  29. package/.opencode/skills/intellisearch/references/deepwiki-tools.md +0 -246
  30. package/.opencode/skills/intellisearch/references/examples.md +0 -97
  31. package/.opencode/skills/intellisearch/references/gh-cli.md +0 -143
  32. package/.opencode/skills/intellisearch/references/google-search.md +0 -40
  33. package/.opencode/skills/intellisearch/references/search-workflow.md +0 -143
  34. package/.opencode/skills/intellisearch/references/workflow.md +0 -115
  35. package/.opencode/skills/openspec-apply-change/SKILL.md +0 -159
  36. package/.opencode/skills/openspec-archive-change/SKILL.md +0 -117
  37. package/.opencode/skills/openspec-explore/SKILL.md +0 -287
  38. package/.opencode/skills/openspec-propose/SKILL.md +0 -111
  39. package/.opencode/skills/openspec-sync-specs/SKILL.md +0 -147
  40. package/.serena/project.yml +0 -133
  41. package/AGENTS.md +0 -136
  42. package/CHANGELOG.md +0 -3
  43. package/bun.lock +0 -105
  44. package/docs/INSTALL.md +0 -185
  45. package/docs/PLAYWRIGHT_CLI_API.md +0 -306
  46. package/docs/python-release-for-reference.md +0 -175
  47. package/examples/sample_json_export.json +0 -32
  48. package/examples/sample_markdown_export.md +0 -221
  49. package/examples/usage_examples.sh +0 -222
  50. package/install.ps1 +0 -264
  51. package/install.sh +0 -275
  52. package/openspec/MAESTRO_MIGRATION.md +0 -180
  53. package/openspec/changes/archive/2026-06-08-command-spec-conformance/.openspec.yaml +0 -2
  54. package/openspec/changes/archive/2026-06-08-command-spec-conformance/design.md +0 -194
  55. package/openspec/changes/archive/2026-06-08-command-spec-conformance/proposal.md +0 -52
  56. package/openspec/changes/archive/2026-06-08-command-spec-conformance/specs/multi-profile-conversations/spec.md +0 -133
  57. package/openspec/changes/archive/2026-06-08-command-spec-conformance/tasks.md +0 -95
  58. package/openspec/changes/archive/2026-06-09-refactor-interactive-prompt-loop/.openspec.yaml +0 -2
  59. package/openspec/changes/archive/2026-06-09-refactor-interactive-prompt-loop/design.md +0 -28
  60. package/openspec/changes/archive/2026-06-09-refactor-interactive-prompt-loop/proposal.md +0 -22
  61. package/openspec/changes/archive/2026-06-09-refactor-interactive-prompt-loop/specs/interactive-prompt-loop/spec.md +0 -35
  62. package/openspec/changes/archive/2026-06-09-refactor-interactive-prompt-loop/tasks.md +0 -28
  63. package/openspec/changes/archive/2026-06-09-replace-gemini-api-placeholder-with-gemini-reverse/.openspec.yaml +0 -2
  64. package/openspec/changes/archive/2026-06-09-replace-gemini-api-placeholder-with-gemini-reverse/design.md +0 -323
  65. package/openspec/changes/archive/2026-06-09-replace-gemini-api-placeholder-with-gemini-reverse/proposal.md +0 -122
  66. package/openspec/changes/archive/2026-06-09-replace-gemini-api-placeholder-with-gemini-reverse/specs/no-capability-changes/spec.md +0 -29
  67. package/openspec/changes/archive/2026-06-09-replace-gemini-api-placeholder-with-gemini-reverse/tasks.md +0 -172
  68. package/openspec/changes/archive/2026-06-09-v2-install-migration/.openspec.yaml +0 -2
  69. package/openspec/changes/archive/2026-06-09-v2-install-migration/design.md +0 -241
  70. package/openspec/changes/archive/2026-06-09-v2-install-migration/proposal.md +0 -41
  71. package/openspec/changes/archive/2026-06-09-v2-install-migration/specs/v2-installer/spec.md +0 -205
  72. package/openspec/changes/archive/2026-06-09-v2-install-migration/tasks.md +0 -97
  73. package/openspec/changes/commander-cli-parser/.openspec.yaml +0 -2
  74. package/openspec/changes/commander-cli-parser/design.md +0 -107
  75. package/openspec/changes/commander-cli-parser/proposal.md +0 -31
  76. package/openspec/changes/commander-cli-parser/specs/cli/spec.md +0 -48
  77. package/openspec/changes/commander-cli-parser/tasks.md +0 -33
  78. package/openspec/changes/cross-platform-build-and-ci/.openspec.yaml +0 -2
  79. package/openspec/changes/cross-platform-build-and-ci/design.md +0 -213
  80. package/openspec/changes/cross-platform-build-and-ci/proposal.md +0 -50
  81. package/openspec/changes/cross-platform-build-and-ci/specs/path-and-file-mediation/spec.md +0 -335
  82. package/openspec/changes/cross-platform-build-and-ci/specs/release-pipeline/spec.md +0 -95
  83. package/openspec/changes/cross-platform-build-and-ci/tasks.md +0 -164
  84. package/openspec/config.yaml +0 -20
  85. package/openspec/specs/auth/spec.md +0 -394
  86. package/openspec/specs/cli/spec.md +0 -108
  87. package/openspec/specs/commands/spec.md +0 -409
  88. package/openspec/specs/configuration/spec.md +0 -130
  89. package/openspec/specs/conversations/spec.md +0 -139
  90. package/openspec/specs/domain-model/spec.md +0 -128
  91. package/openspec/specs/formatters/spec.md +0 -158
  92. package/openspec/specs/install-browser/spec.md +0 -146
  93. package/openspec/specs/interactive-prompt-loop/spec.md +0 -41
  94. package/openspec/specs/logger/spec.md +0 -71
  95. package/openspec/specs/mediator/spec.md +0 -72
  96. package/openspec/specs/multi-profile-conversations/spec.md +0 -145
  97. package/openspec/specs/path-utils/spec.md +0 -101
  98. package/openspec/specs/profiles/spec.md +0 -94
  99. package/openspec/specs/storage/spec.md +0 -198
  100. package/openspec/specs/testing/spec.md +0 -237
  101. package/openspec/specs/v2-installer/spec.md +0 -205
  102. package/openspec/specs/validators/spec.md +0 -65
  103. package/scripts/build.ts +0 -88
  104. package/scripts/clean-build.ps1 +0 -4
  105. package/scripts/clean-build.sh +0 -5
  106. package/scripts/install-browser.ps1 +0 -5
  107. package/scripts/install-browser.sh +0 -6
  108. package/scripts/lint-path-mediation.ps1 +0 -65
  109. package/scripts/lint-path-mediation.sh +0 -40
  110. package/tests/cli/auth-command.test.ts +0 -220
  111. package/tests/cli/command-registry.test.ts +0 -67
  112. package/tests/cli/continue-command.test.ts +0 -100
  113. package/tests/cli/delete-command.test.ts +0 -128
  114. package/tests/cli/export-all-command.test.ts +0 -375
  115. package/tests/cli/install-browser-command.test.ts +0 -48
  116. package/tests/cli/list-command.test.ts +0 -179
  117. package/tests/cli/new-command.test.ts +0 -139
  118. package/tests/cli/status-command.test.ts +0 -106
  119. package/tests/core/query-handlers.test.ts +0 -187
  120. package/tests/fixtures/auth-fixtures.ts +0 -98
  121. package/tests/fixtures/chat-fixtures.ts +0 -87
  122. package/tests/infrastructure/cli-table.test.ts +0 -107
  123. package/tests/infrastructure/formatters.test.ts +0 -202
  124. package/tests/infrastructure/io.test.ts +0 -197
  125. package/tests/infrastructure/logger.test.ts +0 -74
  126. package/tests/infrastructure/storage.test.ts +0 -335
  127. package/tests/infrastructure/validators.test.ts +0 -67
  128. package/tests/integration/commands/auth.test.ts +0 -186
  129. package/tests/integration/commands/continue.test.ts +0 -130
  130. package/tests/integration/commands/delete.test.ts +0 -140
  131. package/tests/integration/commands/export.test.ts +0 -266
  132. package/tests/integration/commands/fetch.test.ts +0 -238
  133. package/tests/integration/commands/list.test.ts +0 -281
  134. package/tests/integration/commands/profile.test.ts +0 -258
  135. package/tests/integration/commands/status.test.ts +0 -223
  136. package/tests/integration/installer-script-shape.test.ts +0 -67
  137. package/tests/parity/compare-outputs.ts +0 -359
  138. package/tests/parity/test-commands-parity.ps1 +0 -82
  139. package/tests/parity/test-commands-parity.sh +0 -61
  140. package/tests/services/auth-service.test.ts +0 -315
  141. package/tests/services/cookie-monitor.test.ts +0 -229
  142. package/tests/services/cookie-storage-service.test.ts +0 -230
  143. package/tests/services/gemini-client-wrapper.test.ts +0 -688
  144. package/tests/services/install-browser-service.test.ts +0 -83
  145. package/tests/services/playwright-cli-driver.test.ts +0 -468
  146. package/tests/services/profile-auth-manager.test.ts +0 -334
  147. package/tests/services/profile-service.test.ts +0 -224
  148. package/tests/setup.ts +0 -95
  149. package/tests/smoke/smoke.test.ts +0 -52
  150. package/tests/unit/config.test.ts +0 -159
  151. package/tests/unit/errors.test.ts +0 -119
  152. package/tests/unit/formatters.test.ts +0 -316
  153. package/tests/unit/mediator.test.ts +0 -152
  154. package/tests/unit/path-utils.test.ts +0 -289
  155. package/tsconfig.json +0 -16
@@ -1,238 +0,0 @@
1
- import { describe, test, expect, mock, beforeEach, afterEach, spyOn } from "bun:test";
2
- import { FetchCommand } from "../../../src/cli/commands/fetch-command.ts";
3
- import { Mediator } from "../../../src/core/mediator.ts";
4
- import { QUERY_TYPES, type FetchChatQueryResult } from "../../../src/core/query-handlers.ts";
5
- import type { CliCommandContext } from "../../../src/cli/command-registry.ts";
6
- import { setupTestConfig, teardownTestConfig } from "../../setup.ts";
7
- import { createMockMessageHistory } from "../../fixtures/chat-fixtures.ts";
8
- import * as configModule from "../../../src/infrastructure/config.ts";
9
- import { existsSync, unlinkSync, readFileSync } from "node:fs";
10
- import { resolve } from "node:path";
11
- import { tmpdir } from "node:os";
12
- import { join } from "node:path";
13
-
14
- describe("fetch command integration", () => {
15
- let command: FetchCommand;
16
- let context: CliCommandContext;
17
- let logSpy: ReturnType<typeof spyOn>;
18
- let originalEnv: Record<string, string | undefined>;
19
- let mediatorSendSpy: ReturnType<typeof spyOn>;
20
-
21
- beforeEach(() => {
22
- command = new FetchCommand();
23
- context = { verbose: false, mediator: new Mediator() };
24
- logSpy = spyOn(console, "log").mockImplementation(() => {});
25
- originalEnv = {
26
- GEMITERM_CONFIG_DIR: process.env.GEMITERM_CONFIG_DIR,
27
- };
28
- const configDir = setupTestConfig("fetch-integration");
29
- spyOn(configModule, "getConfigDir").mockReturnValue(configDir);
30
- spyOn(configModule, "ensureConfigDir").mockImplementation(() => {});
31
-
32
- const mockMessages = createMockMessageHistory({ count: 4 });
33
- mediatorSendSpy = spyOn(context.mediator, "send").mockResolvedValue({ messages: mockMessages });
34
- });
35
-
36
- afterEach(() => {
37
- mock.restore();
38
- logSpy.mockRestore();
39
- teardownTestConfig(originalEnv);
40
- });
41
-
42
- describe("command metadata", () => {
43
- test("has correct name and description", () => {
44
- expect(command.name).toBe("fetch");
45
- expect(command.description).toBe("Fetch and display a conversation");
46
- });
47
- });
48
-
49
- describe("--help flag", () => {
50
- test("--help shows usage information", async () => {
51
- await command.execute(["--help"], context);
52
-
53
- const output = logSpy.mock.calls.map((c) => c[0]).join("\n");
54
- expect(output).toContain("Usage: gemiterm fetch");
55
- expect(output).toContain("--format");
56
- expect(output).toContain("--path");
57
- expect(output).toContain("--help");
58
- });
59
-
60
- test("-h shows usage information", async () => {
61
- await command.execute(["-h"], context);
62
-
63
- const output = logSpy.mock.calls.map((c) => c[0]).join("\n");
64
- expect(output).toContain("Usage: gemiterm fetch");
65
- });
66
-
67
- test("help does not send query to mediator", async () => {
68
- await command.execute(["--help"], context);
69
-
70
- expect(mediatorSendSpy).not.toHaveBeenCalled();
71
- });
72
- });
73
-
74
- describe("fetch with conversation id", () => {
75
- test("sends fetch-chat query to mediator with correct id", async () => {
76
- await command.execute(["conv-abc123"], context);
77
-
78
- expect(mediatorSendSpy).toHaveBeenCalledTimes(1);
79
- const sentQuery = mediatorSendSpy.mock.calls[0][0] as any;
80
- expect(sentQuery.type).toBe(QUERY_TYPES.FETCH_CHAT);
81
- expect(sentQuery.payload.conversationId).toBe("conv-abc123");
82
- });
83
-
84
- test("returns formatted text output by default", async () => {
85
- await command.execute(["conv-abc123"], context);
86
-
87
- const output = logSpy.mock.calls.map((c) => c[0]).join("\n");
88
- expect(output).toContain("Conversation:");
89
- expect(output).toContain("conv-abc123");
90
- expect(output).toContain("User:");
91
- expect(output).toContain("Model:");
92
- });
93
-
94
- test("displays message content in text output", async () => {
95
- const mockMessages = createMockMessageHistory({
96
- count: 2,
97
- contents: ["Hello!", "Hi there!"],
98
- });
99
- mediatorSendSpy.mockResolvedValue({ messages: mockMessages });
100
-
101
- await command.execute(["conv-xyz"], context);
102
-
103
- const output = logSpy.mock.calls.map((c) => c[0]).join("\n");
104
- expect(output).toContain("Hello!");
105
- expect(output).toContain("Hi there!");
106
- });
107
-
108
- test("shows 'No messages found' when conversation has no messages", async () => {
109
- mediatorSendSpy.mockResolvedValue({ messages: [] });
110
-
111
- await command.execute(["conv-empty"], context);
112
-
113
- const output = logSpy.mock.calls.map((c) => c[0]).join("\n");
114
- expect(output).toContain("No messages found");
115
- });
116
- });
117
-
118
- describe("--format json option", () => {
119
- test("outputs valid JSON when --format json", async () => {
120
- const mockMessages = createMockMessageHistory({ count: 2 });
121
- mediatorSendSpy.mockResolvedValue({ messages: mockMessages });
122
-
123
- await command.execute(["conv-abc123", "--format", "json"], context);
124
-
125
- const jsonOutput = logSpy.mock.calls.map((c) => c[0]).join("\n");
126
- const parsed = JSON.parse(jsonOutput);
127
- expect(parsed).toHaveProperty("conversationId", "conv-abc123");
128
- expect(parsed).toHaveProperty("messages");
129
- expect(parsed.messages).toHaveLength(2);
130
- });
131
-
132
- test("-f json also outputs valid JSON", async () => {
133
- const mockMessages = createMockMessageHistory({ count: 3 });
134
- mediatorSendSpy.mockResolvedValue({ messages: mockMessages });
135
-
136
- await command.execute(["conv-abc123", "-f", "json"], context);
137
-
138
- const jsonOutput = logSpy.mock.calls.map((c) => c[0]).join("\n");
139
- const parsed = JSON.parse(jsonOutput);
140
- expect(parsed.messages).toHaveLength(3);
141
- });
142
-
143
- test("JSON output contains message roles and content", async () => {
144
- const mockMessages = createMockMessageHistory({
145
- count: 2,
146
- roles: ["user", "model"],
147
- contents: ["What is TypeScript?", "TypeScript is a typed superset of JavaScript."],
148
- });
149
- mediatorSendSpy.mockResolvedValue({ messages: mockMessages });
150
-
151
- await command.execute(["conv-abc123", "--format", "json"], context);
152
-
153
- const jsonOutput = logSpy.mock.calls.map((c) => c[0]).join("\n");
154
- const parsed = JSON.parse(jsonOutput);
155
- expect(parsed.messages[0].role).toBe("user");
156
- expect(parsed.messages[0].content).toBe("What is TypeScript?");
157
- expect(parsed.messages[1].role).toBe("model");
158
- });
159
- });
160
-
161
- describe("--path option", () => {
162
- test("--path writes text output to file", async () => {
163
- const outputPath = join(tmpdir(), `fetch-test-${Date.now()}.txt`);
164
-
165
- try {
166
- await command.execute(["conv-abc123", "--path", outputPath], context);
167
-
168
- expect(existsSync(outputPath)).toBe(true);
169
- const content = readFileSync(outputPath, "utf-8");
170
- expect(content).toContain("Conversation:");
171
- expect(content).toContain("conv-abc123");
172
- } finally {
173
- if (existsSync(outputPath)) unlinkSync(outputPath);
174
- }
175
- });
176
-
177
- test("-p writes text output to file", async () => {
178
- const outputPath = join(tmpdir(), `fetch-test-short-${Date.now()}.txt`);
179
-
180
- try {
181
- await command.execute(["conv-abc123", "-p", outputPath], context);
182
-
183
- expect(existsSync(outputPath)).toBe(true);
184
- const content = readFileSync(outputPath, "utf-8");
185
- expect(content).toContain("Conversation:");
186
- } finally {
187
- if (existsSync(outputPath)) unlinkSync(outputPath);
188
- }
189
- });
190
-
191
- test("--path with json format writes JSON to file", async () => {
192
- const outputPath = join(tmpdir(), `fetch-test-json-${Date.now()}.json`);
193
-
194
- try {
195
- await command.execute(["conv-abc123", "--format", "json", "--path", outputPath], context);
196
-
197
- expect(existsSync(outputPath)).toBe(true);
198
- const content = readFileSync(outputPath, "utf-8");
199
- const parsed = JSON.parse(content);
200
- expect(parsed).toHaveProperty("conversationId");
201
- expect(parsed).toHaveProperty("messages");
202
- } finally {
203
- if (existsSync(outputPath)) unlinkSync(outputPath);
204
- }
205
- });
206
- });
207
-
208
- describe("no conversation id", () => {
209
- test("does not send fetch-chat query when no id is provided", async () => {
210
- const mockListExecute = mock(() => Promise.resolve());
211
- const mockListHandler = { name: "list", description: "", execute: mockListExecute };
212
- const mockRegistry = {
213
- registerAllCommands: mock(() => {}),
214
- getHandler: mock(() => mockListHandler),
215
- };
216
- spyOn(command as any, "invokeListCommand").mockImplementation(() => {});
217
-
218
- await command.execute([], context);
219
-
220
- expect(mediatorSendSpy).not.toHaveBeenCalled();
221
- expect((command as any).invokeListCommand).toHaveBeenCalledTimes(1);
222
- });
223
- });
224
-
225
- describe("error handling", () => {
226
- test("propagates mediator errors", async () => {
227
- mediatorSendSpy.mockRejectedValue(new Error("Conversation not found"));
228
-
229
- await expect(command.execute(["conv-invalid"], context)).rejects.toThrow("Conversation not found");
230
- });
231
-
232
- test("propagates network errors", async () => {
233
- mediatorSendSpy.mockRejectedValue(new Error("Network error"));
234
-
235
- await expect(command.execute(["conv-abc123"], context)).rejects.toThrow("Network error");
236
- });
237
- });
238
- });
@@ -1,281 +0,0 @@
1
- import { describe, test, expect, mock, beforeEach, afterEach, spyOn } from "bun:test";
2
- import { ListCommand } from "../../../src/cli/commands/list-command.ts";
3
- import { Mediator } from "../../../src/core/mediator.ts";
4
- import { QUERY_TYPES, type ListChatsQueryPayload, type ListChatsQueryResult } from "../../../src/core/query-handlers.ts";
5
- import type { CliCommandContext } from "../../../src/cli/command-registry.ts";
6
- import { setupTestConfig, teardownTestConfig } from "../../setup.ts";
7
- import { createMockChatList } from "../../fixtures/chat-fixtures.ts";
8
- import * as configModule from "../../../src/infrastructure/config.ts";
9
-
10
- describe("list command integration", () => {
11
- let command: ListCommand;
12
- let context: CliCommandContext;
13
- let logSpy: ReturnType<typeof spyOn>;
14
- let originalEnv: Record<string, string | undefined>;
15
- let mediatorSendSpy: ReturnType<typeof spyOn>;
16
-
17
- beforeEach(() => {
18
- command = new ListCommand();
19
- context = { verbose: false, mediator: new Mediator() };
20
- logSpy = spyOn(console, "log").mockImplementation(() => {});
21
- originalEnv = {
22
- GEMITERM_CONFIG_DIR: process.env.GEMITERM_CONFIG_DIR,
23
- };
24
- const configDir = setupTestConfig("list-integration");
25
- spyOn(configModule, "getConfigDir").mockReturnValue(configDir);
26
- spyOn(configModule, "ensureConfigDir").mockImplementation(() => {});
27
-
28
- const mockChats = createMockChatList({ count: 5 });
29
- mediatorSendSpy = spyOn(context.mediator, "send").mockResolvedValue({ chats: mockChats });
30
- });
31
-
32
- afterEach(() => {
33
- mock.restore();
34
- logSpy.mockRestore();
35
- teardownTestConfig(originalEnv);
36
- });
37
-
38
- describe("command metadata", () => {
39
- test("has correct name and description", () => {
40
- expect(command.name).toBe("list");
41
- expect(command.description).toBe("List conversations");
42
- });
43
- });
44
-
45
- describe("--help flag", () => {
46
- test("--help shows usage information", async () => {
47
- await command.execute(["--help"], context);
48
-
49
- const output = logSpy.mock.calls.map((c) => c[0]).join("\n");
50
- expect(output).toContain("Usage: gemiterm list");
51
- expect(output).toContain("--limit");
52
- expect(output).toContain("--search");
53
- expect(output).toContain("--format");
54
- });
55
-
56
- test("-h shows usage information", async () => {
57
- await command.execute(["-h"], context);
58
-
59
- const output = logSpy.mock.calls.map((c) => c[0]).join("\n");
60
- expect(output).toContain("Usage: gemiterm list");
61
- });
62
-
63
- test("help does not send query to mediator", async () => {
64
- await command.execute(["--help"], context);
65
-
66
- expect(mediatorSendSpy).not.toHaveBeenCalled();
67
- });
68
- });
69
-
70
- describe("list with mock data", () => {
71
- test("sends list-chats query to mediator", async () => {
72
- await command.execute([], context);
73
-
74
- expect(mediatorSendSpy).toHaveBeenCalledTimes(1);
75
- const sentQuery = mediatorSendSpy.mock.calls[0][0] as any;
76
- expect(sentQuery.type).toBe(QUERY_TYPES.LIST_CHATS);
77
- });
78
-
79
- test("returns formatted table output by default", async () => {
80
- await command.execute([], context);
81
-
82
- const output = logSpy.mock.calls.map((c) => c[0]).join("\n");
83
- expect(output).toContain("ID");
84
- expect(output).toContain("TITLE");
85
- expect(output).toContain("DATE");
86
- expect(output).toContain("Total:");
87
- });
88
-
89
- test("displays chat IDs in output", async () => {
90
- const mockChats = createMockChatList({ count: 3 });
91
- mediatorSendSpy.mockResolvedValue({ chats: mockChats });
92
-
93
- await command.execute([], context);
94
-
95
- const output = logSpy.mock.calls.map((c) => c[0]).join("\n");
96
- for (const chat of mockChats) {
97
- expect(output).toContain(chat.id);
98
- }
99
- });
100
-
101
- test("displays empty message when no chats", async () => {
102
- mediatorSendSpy.mockResolvedValue({ chats: [] });
103
-
104
- await command.execute([], context);
105
-
106
- const output = logSpy.mock.calls.map((c) => c[0]).join("\n");
107
- expect(output).toContain("No conversations found");
108
- });
109
- });
110
-
111
- describe("--limit option", () => {
112
- test("--limit 2 passes limit to mediator query", async () => {
113
- await command.execute(["--limit", "2"], context);
114
-
115
- const sentQuery = mediatorSendSpy.mock.calls[0][0] as any;
116
- expect(sentQuery.payload.limit).toBe(2);
117
- });
118
-
119
- test("-n 5 passes limit to mediator query", async () => {
120
- await command.execute(["-n", "5"], context);
121
-
122
- const sentQuery = mediatorSendSpy.mock.calls[0][0] as any;
123
- expect(sentQuery.payload.limit).toBe(5);
124
- });
125
-
126
- test("limits output to specified number of results", async () => {
127
- const mockChats = createMockChatList({ count: 10 });
128
- mediatorSendSpy.mockResolvedValue({ chats: mockChats });
129
-
130
- await command.execute(["--limit", "3"], context);
131
-
132
- const output = logSpy.mock.calls.map((c) => c[0]).join("\n");
133
- const lines = output.split("\n");
134
- const dataLines = lines.filter((l) => l.includes("\u2502") && !l.includes("Total:"));
135
- expect(dataLines.length).toBeLessThanOrEqual(4);
136
- });
137
- });
138
-
139
- describe("--format json option", () => {
140
- test("outputs valid JSON when --format json", async () => {
141
- const mockChats = createMockChatList({ count: 3 });
142
- mediatorSendSpy.mockResolvedValue({ chats: mockChats });
143
-
144
- await command.execute(["--format", "json"], context);
145
-
146
- const jsonOutput = logSpy.mock.calls.map((c) => c[0]).join("\n");
147
- const parsed = JSON.parse(jsonOutput);
148
- expect(parsed).toHaveProperty("chats");
149
- expect(parsed.chats).toHaveLength(3);
150
- });
151
-
152
- test("-f json also outputs valid JSON", async () => {
153
- const mockChats = createMockChatList({ count: 2 });
154
- mediatorSendSpy.mockResolvedValue({ chats: mockChats });
155
-
156
- await command.execute(["-f", "json"], context);
157
-
158
- const jsonOutput = logSpy.mock.calls.map((c) => c[0]).join("\n");
159
- const parsed = JSON.parse(jsonOutput);
160
- expect(parsed.chats).toHaveLength(2);
161
- });
162
-
163
- test("JSON output contains chat ids and titles", async () => {
164
- const mockChats = createMockChatList({ count: 2, ids: ["id-one", "id-two"], titles: ["First", "Second"] });
165
- mediatorSendSpy.mockResolvedValue({ chats: mockChats });
166
-
167
- await command.execute(["--format", "json"], context);
168
-
169
- const jsonOutput = logSpy.mock.calls.map((c) => c[0]).join("\n");
170
- const parsed = JSON.parse(jsonOutput);
171
- expect(parsed.chats[0].id).toBe("id-one");
172
- expect(parsed.chats[0].title).toBe("First");
173
- });
174
- });
175
-
176
- describe("--search option", () => {
177
- test("--search passes search term to mediator query", async () => {
178
- await command.execute(["--search", "TypeScript"], context);
179
-
180
- const sentQuery = mediatorSendSpy.mock.calls[0][0] as any;
181
- expect(sentQuery.payload.search).toBe("TypeScript");
182
- });
183
-
184
- test("-s passes search term to mediator query", async () => {
185
- await command.execute(["-s", "Bun"], context);
186
-
187
- const sentQuery = mediatorSendSpy.mock.calls[0][0] as any;
188
- expect(sentQuery.payload.search).toBe("Bun");
189
- });
190
- });
191
-
192
- describe("--all flag", () => {
193
- test("--all sends query without limit", async () => {
194
- await command.execute(["--all"], context);
195
-
196
- const sentQuery = mediatorSendSpy.mock.calls[0][0] as any;
197
- expect(sentQuery.payload.limit).toBeUndefined();
198
- });
199
- });
200
-
201
- describe("sort options", () => {
202
- test("default sort is recent", async () => {
203
- await command.execute([], context);
204
-
205
- const output = logSpy.mock.calls.map((c) => c[0]).join("\n");
206
- expect(output).toContain("Total:");
207
- });
208
-
209
- test("--sort oldest is accepted", async () => {
210
- await command.execute(["--sort", "oldest"], context);
211
-
212
- expect(mediatorSendSpy).toHaveBeenCalledTimes(1);
213
- });
214
-
215
- test("--sort alpha is accepted", async () => {
216
- await command.execute(["--sort", "alpha"], context);
217
-
218
- expect(mediatorSendSpy).toHaveBeenCalledTimes(1);
219
- });
220
- });
221
-
222
- describe("--all-profiles flag", () => {
223
- test("renders Profile column when --all-profiles is set", async () => {
224
- const mockChats = [
225
- { id: "conv-1", title: "Chat 1", isPinned: false, timestamp: Date.now(), profile: "work" },
226
- { id: "conv-2", title: "Chat 2", isPinned: false, timestamp: Date.now(), profile: "personal" },
227
- ];
228
- mediatorSendSpy.mockResolvedValue({ chats: mockChats });
229
-
230
- await command.execute(["--all-profiles"], context);
231
-
232
- const output = logSpy.mock.calls.map((c) => c[0]).join("\n");
233
- expect(output).toContain("PROFILE");
234
- expect(output).toContain("work");
235
- expect(output).toContain("personal");
236
- });
237
-
238
- test("omits Profile column when --all-profiles is not set", async () => {
239
- const mockChats = [
240
- { id: "conv-1", title: "Chat 1", isPinned: false, timestamp: Date.now(), profile: "work" },
241
- ];
242
- mediatorSendSpy.mockResolvedValue({ chats: mockChats });
243
-
244
- await command.execute([], context);
245
-
246
- const output = logSpy.mock.calls.map((c) => c[0]).join("\n");
247
- expect(output).not.toContain("PROFILE");
248
- });
249
-
250
- test("JSON output includes profile field only when --all-profiles is set", async () => {
251
- const mockChatsWithProfile = [
252
- { id: "conv-1", title: "Chat 1", isPinned: false, timestamp: Date.now(), profile: "work" },
253
- ];
254
- mediatorSendSpy.mockResolvedValue({ chats: mockChatsWithProfile });
255
-
256
- await command.execute(["--all-profiles", "--format", "json"], context);
257
- const outputWithFlag = logSpy.mock.calls.map((c) => c[0]).join("\n");
258
- const parsedWithFlag = JSON.parse(outputWithFlag);
259
- expect(parsedWithFlag.chats[0]).toHaveProperty("profile");
260
- expect(parsedWithFlag.chats[0].profile).toBe("work");
261
-
262
- const mockChatsWithoutProfile = [
263
- { id: "conv-1", title: "Chat 1", isPinned: false, timestamp: Date.now() },
264
- ];
265
- logSpy.mockClear();
266
- mediatorSendSpy.mockResolvedValue({ chats: mockChatsWithoutProfile });
267
- await command.execute(["--format", "json"], context);
268
- const outputWithoutFlag = logSpy.mock.calls.map((c) => c[0]).join("\n");
269
- const parsedWithoutFlag = JSON.parse(outputWithoutFlag);
270
- expect(parsedWithoutFlag.chats[0]).not.toHaveProperty("profile");
271
- });
272
- });
273
-
274
- describe("error handling", () => {
275
- test("propagates mediator errors", async () => {
276
- mediatorSendSpy.mockRejectedValue(new Error("Network error"));
277
-
278
- await expect(command.execute([], context)).rejects.toThrow("Network error");
279
- });
280
- });
281
- });