gemiterm 2.1.1 → 2.2.0-beta.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.
- package/LICENSE.md +21 -0
- package/README.md +223 -154
- package/package.json +3 -1
- package/src/cli/commands/auth-command.ts +12 -11
- package/src/cli/commands/delete-command.ts +3 -12
- package/src/cli/commands/export-all-command.ts +15 -15
- package/src/cli/commands/export-command.ts +6 -6
- package/src/cli/commands/fetch-command.ts +17 -17
- package/src/cli/commands/list-command.ts +114 -27
- package/src/cli/commands/profile-command.ts +2 -8
- package/src/cli/utils/interactive-prompt.ts +44 -36
- package/src/cli/utils/prompts.ts +319 -0
- package/src/core/query-handlers.ts +5 -2
- package/src/services/gemini-client-wrapper.ts +1 -1
|
@@ -16,7 +16,7 @@ import { joinPath, resolvePath } from "../../infrastructure/path-utils.ts";
|
|
|
16
16
|
|
|
17
17
|
interface ExportAllCommandOptions {
|
|
18
18
|
help: boolean;
|
|
19
|
-
|
|
19
|
+
outDir: string;
|
|
20
20
|
since: string;
|
|
21
21
|
includeMetadata: boolean;
|
|
22
22
|
allProfiles: boolean;
|
|
@@ -24,7 +24,7 @@ interface ExportAllCommandOptions {
|
|
|
24
24
|
|
|
25
25
|
const DEFAULT_OPTIONS: ExportAllCommandOptions = {
|
|
26
26
|
help: false,
|
|
27
|
-
|
|
27
|
+
outDir: "./exports",
|
|
28
28
|
since: "",
|
|
29
29
|
includeMetadata: false,
|
|
30
30
|
allProfiles: false,
|
|
@@ -75,8 +75,8 @@ export class ExportAllCommand implements CliCommand {
|
|
|
75
75
|
console.log(chalk.bold(`Found ${chats.length} conversation${chats.length !== 1 ? "s" : ""} to export.`));
|
|
76
76
|
console.log("");
|
|
77
77
|
|
|
78
|
-
const
|
|
79
|
-
ensureDir(
|
|
78
|
+
const outDir = resolvePath(options.outDir);
|
|
79
|
+
ensureDir(outDir);
|
|
80
80
|
|
|
81
81
|
const results: ExportResult[] = [];
|
|
82
82
|
|
|
@@ -92,7 +92,7 @@ export class ExportAllCommand implements CliCommand {
|
|
|
92
92
|
} as Query<FetchChatQueryPayload>);
|
|
93
93
|
|
|
94
94
|
const filename = this.sanitizeFilename(chat.title || chat.id);
|
|
95
|
-
const filePath = joinPath(
|
|
95
|
+
const filePath = joinPath(outDir, `${filename}.md`);
|
|
96
96
|
const content = formatChatAsMarkdown(
|
|
97
97
|
fetchResult.messages,
|
|
98
98
|
chat.title,
|
|
@@ -112,8 +112,8 @@ export class ExportAllCommand implements CliCommand {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
this.writeIndex(
|
|
116
|
-
this.printSummary(results,
|
|
115
|
+
this.writeIndex(outDir, results, options.includeMetadata);
|
|
116
|
+
this.printSummary(results, outDir);
|
|
117
117
|
} catch (error) {
|
|
118
118
|
const message = error instanceof Error ? error.message : String(error);
|
|
119
119
|
console.error(chalk.red(`Error: ${message}`));
|
|
@@ -138,7 +138,7 @@ export class ExportAllCommand implements CliCommand {
|
|
|
138
138
|
return `gemini-chat-${safe}-${date}`.replace(/-+$/, "");
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
private writeIndex(
|
|
141
|
+
private writeIndex(outDir: string, results: ExportResult[], includeMetadata: boolean): void {
|
|
142
142
|
const lines: string[] = [];
|
|
143
143
|
|
|
144
144
|
lines.push("# Exported Conversations");
|
|
@@ -173,11 +173,11 @@ export class ExportAllCommand implements CliCommand {
|
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
const indexPath = joinPath(
|
|
176
|
+
const indexPath = joinPath(outDir, "index.md");
|
|
177
177
|
writeTextFile(indexPath, lines.join("\n"));
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
private printSummary(results: ExportResult[],
|
|
180
|
+
private printSummary(results: ExportResult[], outDir: string): void {
|
|
181
181
|
const succeeded = results.filter((r) => r.success);
|
|
182
182
|
const failed = results.filter((r) => !r.success);
|
|
183
183
|
|
|
@@ -187,8 +187,8 @@ export class ExportAllCommand implements CliCommand {
|
|
|
187
187
|
if (failed.length > 0) {
|
|
188
188
|
console.log(` Failed: ${chalk.red(failed.length)}`);
|
|
189
189
|
}
|
|
190
|
-
console.log(` Output: ${
|
|
191
|
-
console.log(` Index: ${chalk.cyan(joinPath(
|
|
190
|
+
console.log(` Output: ${outDir}`);
|
|
191
|
+
console.log(` Index: ${chalk.cyan(joinPath(outDir, "index.md"))}`);
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
private parseArgs(args: string[]): ExportAllCommandOptions {
|
|
@@ -201,9 +201,9 @@ export class ExportAllCommand implements CliCommand {
|
|
|
201
201
|
case "-h":
|
|
202
202
|
options.help = true;
|
|
203
203
|
break;
|
|
204
|
-
case "--
|
|
204
|
+
case "--out-dir":
|
|
205
205
|
case "-o":
|
|
206
|
-
options.
|
|
206
|
+
options.outDir = args[++i] ?? DEFAULT_OPTIONS.outDir;
|
|
207
207
|
break;
|
|
208
208
|
case "--since":
|
|
209
209
|
options.since = args[++i] ?? "";
|
|
@@ -227,7 +227,7 @@ export class ExportAllCommand implements CliCommand {
|
|
|
227
227
|
console.log(chalk.bold("Options:"));
|
|
228
228
|
|
|
229
229
|
const flags = [
|
|
230
|
-
{ flag: "--
|
|
230
|
+
{ flag: "--out-dir, -o <dir>", desc: "Output directory (default: ./exports)" },
|
|
231
231
|
{ flag: "--since <date>", desc: "Only export chats from this date onwards" },
|
|
232
232
|
{ flag: "--include-metadata", desc: "Include metadata headers in exports" },
|
|
233
233
|
{ flag: "--all-profiles, -a", desc: "Export conversations from all profiles" },
|
|
@@ -16,14 +16,14 @@ import { writeTextFile } from "../../infrastructure/io.ts";
|
|
|
16
16
|
|
|
17
17
|
interface ExportCommandOptions {
|
|
18
18
|
help: boolean;
|
|
19
|
-
|
|
19
|
+
out: string;
|
|
20
20
|
format: "markdown" | "json";
|
|
21
21
|
includeMetadata: boolean;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const DEFAULT_OPTIONS: ExportCommandOptions = {
|
|
25
25
|
help: false,
|
|
26
|
-
|
|
26
|
+
out: "",
|
|
27
27
|
format: "markdown",
|
|
28
28
|
includeMetadata: false,
|
|
29
29
|
};
|
|
@@ -67,7 +67,7 @@ export class ExportCommand implements CliCommand {
|
|
|
67
67
|
payload: query,
|
|
68
68
|
} as Query<FetchChatQueryPayload>);
|
|
69
69
|
|
|
70
|
-
const outputPath = options.
|
|
70
|
+
const outputPath = options.out || this.defaultFilename(conversationId, options.format);
|
|
71
71
|
|
|
72
72
|
const content =
|
|
73
73
|
options.format === "json"
|
|
@@ -108,9 +108,9 @@ export class ExportCommand implements CliCommand {
|
|
|
108
108
|
case "-h":
|
|
109
109
|
options.help = true;
|
|
110
110
|
break;
|
|
111
|
-
case "--
|
|
111
|
+
case "--out":
|
|
112
112
|
case "-o":
|
|
113
|
-
options.
|
|
113
|
+
options.out = args[++i] ?? "";
|
|
114
114
|
break;
|
|
115
115
|
case "--format":
|
|
116
116
|
case "-f":
|
|
@@ -141,7 +141,7 @@ export class ExportCommand implements CliCommand {
|
|
|
141
141
|
console.log(chalk.bold("Options:"));
|
|
142
142
|
|
|
143
143
|
const flags = [
|
|
144
|
-
{ flag: "--
|
|
144
|
+
{ flag: "--out, -o <path>", desc: "Output file path (default: gemini-chat-<id>-<date>.md)" },
|
|
145
145
|
{ flag: "--format, -f <fmt>", desc: "Output format: markdown, json (default: markdown)" },
|
|
146
146
|
{ flag: "--include-metadata", desc: "Include metadata header (ID, count, date)" },
|
|
147
147
|
{ flag: "--help, -h", desc: "Show this help message" },
|
|
@@ -13,13 +13,13 @@ import { writeTextFile } from "../../infrastructure/io.ts";
|
|
|
13
13
|
interface FetchCommandOptions {
|
|
14
14
|
help: boolean;
|
|
15
15
|
format: "text" | "json";
|
|
16
|
-
|
|
16
|
+
out: string;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const DEFAULT_OPTIONS: FetchCommandOptions = {
|
|
20
20
|
help: false,
|
|
21
21
|
format: "text",
|
|
22
|
-
|
|
22
|
+
out: "",
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
export class FetchCommand implements CliCommand {
|
|
@@ -52,9 +52,9 @@ export class FetchCommand implements CliCommand {
|
|
|
52
52
|
} as Query<FetchChatQueryPayload>);
|
|
53
53
|
|
|
54
54
|
if (options.format === "json") {
|
|
55
|
-
this.outputJson(result.messages, conversationId, options.
|
|
55
|
+
this.outputJson(result.messages, conversationId, options.out);
|
|
56
56
|
} else {
|
|
57
|
-
this.outputText(result.messages, conversationId, options.
|
|
57
|
+
this.outputText(result.messages, conversationId, options.out);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -81,16 +81,16 @@ export class FetchCommand implements CliCommand {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
private outputJson(messages: Message[], conversationId: string,
|
|
84
|
+
private outputJson(messages: Message[], conversationId: string, out: string): void {
|
|
85
85
|
const output = JSON.stringify({ conversationId, messages }, null, 2);
|
|
86
|
-
if (
|
|
87
|
-
this.writeOutput(
|
|
86
|
+
if (out) {
|
|
87
|
+
this.writeOutput(out, output);
|
|
88
88
|
} else {
|
|
89
89
|
console.log(output);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
private outputText(messages: Message[], conversationId: string,
|
|
93
|
+
private outputText(messages: Message[], conversationId: string, out: string): void {
|
|
94
94
|
const lines: string[] = [];
|
|
95
95
|
|
|
96
96
|
lines.push(chalk.bold(`Conversation: ${chalk.cyan(conversationId)}`));
|
|
@@ -109,16 +109,16 @@ export class FetchCommand implements CliCommand {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
const output = lines.join("\n");
|
|
112
|
-
if (
|
|
113
|
-
this.writeOutput(
|
|
112
|
+
if (out) {
|
|
113
|
+
this.writeOutput(out, output);
|
|
114
114
|
} else {
|
|
115
115
|
console.log(output);
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
private writeOutput(
|
|
120
|
-
writeTextFile(
|
|
121
|
-
console.log(chalk.dim(`Output written to: ${
|
|
119
|
+
private writeOutput(out: string, content: string): void {
|
|
120
|
+
writeTextFile(out, content);
|
|
121
|
+
console.log(chalk.dim(`Output written to: ${out}`));
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
private parseArgs(args: string[]): FetchCommandOptions {
|
|
@@ -135,9 +135,9 @@ export class FetchCommand implements CliCommand {
|
|
|
135
135
|
case "-f":
|
|
136
136
|
options.format = this.parseFormat(args[++i]);
|
|
137
137
|
break;
|
|
138
|
-
case "--
|
|
139
|
-
case "-
|
|
140
|
-
options.
|
|
138
|
+
case "--out":
|
|
139
|
+
case "-o":
|
|
140
|
+
options.out = args[++i] ?? "";
|
|
141
141
|
break;
|
|
142
142
|
}
|
|
143
143
|
}
|
|
@@ -160,7 +160,7 @@ export class FetchCommand implements CliCommand {
|
|
|
160
160
|
|
|
161
161
|
const flags = [
|
|
162
162
|
{ flag: "--format, -f <fmt>", desc: "Output format: text, json (default: text)" },
|
|
163
|
-
{ flag: "--
|
|
163
|
+
{ flag: "--out, -o <path>", desc: "Write output to file" },
|
|
164
164
|
{ flag: "--help, -h", desc: "Show this help message" },
|
|
165
165
|
];
|
|
166
166
|
|
|
@@ -10,33 +10,37 @@ import {
|
|
|
10
10
|
import { formatChatList } from "../../infrastructure/formatters.ts";
|
|
11
11
|
import type { ChatInfo } from "../../core/types.ts";
|
|
12
12
|
import { writeTextFile } from "../../infrastructure/io.ts";
|
|
13
|
+
import { GemitermError } from "../../core/errors.ts";
|
|
14
|
+
import { browser, select, type BrowserAction } from "../utils/prompts.ts";
|
|
13
15
|
|
|
14
16
|
interface ListCommandOptions {
|
|
15
17
|
help: boolean;
|
|
16
18
|
limit: number;
|
|
17
19
|
offset: number;
|
|
18
|
-
all: boolean;
|
|
19
20
|
allProfiles: boolean;
|
|
21
|
+
profile: string;
|
|
20
22
|
sort: "recent" | "oldest" | "alpha";
|
|
21
23
|
search: string;
|
|
22
24
|
after: string;
|
|
23
25
|
before: string;
|
|
24
26
|
format: "text" | "json";
|
|
25
|
-
|
|
27
|
+
out: string;
|
|
28
|
+
interactive: boolean;
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
const DEFAULT_OPTIONS: ListCommandOptions = {
|
|
29
32
|
help: false,
|
|
30
|
-
limit:
|
|
33
|
+
limit: 0,
|
|
31
34
|
offset: 0,
|
|
32
|
-
all: false,
|
|
33
35
|
allProfiles: false,
|
|
36
|
+
profile: "",
|
|
34
37
|
sort: "recent",
|
|
35
38
|
search: "",
|
|
36
39
|
after: "",
|
|
37
40
|
before: "",
|
|
38
41
|
format: "text",
|
|
39
|
-
|
|
42
|
+
out: "",
|
|
43
|
+
interactive: false,
|
|
40
44
|
};
|
|
41
45
|
|
|
42
46
|
export class ListCommand implements CliCommand {
|
|
@@ -53,11 +57,13 @@ export class ListCommand implements CliCommand {
|
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
const mediator: Mediator = context.mediator;
|
|
60
|
+
const hasLimit = options.limit > 0;
|
|
56
61
|
const query: ListChatsQueryPayload = {
|
|
57
|
-
limit:
|
|
62
|
+
limit: hasLimit ? options.limit : undefined,
|
|
58
63
|
offset: options.offset || undefined,
|
|
59
64
|
search: options.search || undefined,
|
|
60
65
|
allProfiles: options.allProfiles,
|
|
66
|
+
profile: options.profile || undefined,
|
|
61
67
|
};
|
|
62
68
|
|
|
63
69
|
logger.debug(`Sending list-chats query: ${JSON.stringify(query)}`);
|
|
@@ -68,17 +74,24 @@ export class ListCommand implements CliCommand {
|
|
|
68
74
|
|
|
69
75
|
let chats = result.chats;
|
|
70
76
|
|
|
77
|
+
if (options.interactive) {
|
|
78
|
+
await this.runInteractiveBrowser(chats, options, context);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
71
82
|
chats = this.applySort(chats, options.sort);
|
|
72
83
|
chats = this.applyDateFilter(chats, options.after, options.before);
|
|
73
84
|
|
|
74
|
-
if (
|
|
85
|
+
if (hasLimit) {
|
|
75
86
|
chats = chats.slice(options.offset, options.offset + options.limit);
|
|
87
|
+
} else if (options.offset > 0) {
|
|
88
|
+
chats = chats.slice(options.offset);
|
|
76
89
|
}
|
|
77
90
|
|
|
78
91
|
if (options.format === "json") {
|
|
79
|
-
this.outputJson(chats, options.
|
|
92
|
+
this.outputJson(chats, options.out);
|
|
80
93
|
} else {
|
|
81
|
-
this.outputText(chats, options.
|
|
94
|
+
this.outputText(chats, options.out, options.allProfiles || Boolean(options.profile));
|
|
82
95
|
}
|
|
83
96
|
}
|
|
84
97
|
|
|
@@ -115,27 +128,84 @@ export class ListCommand implements CliCommand {
|
|
|
115
128
|
});
|
|
116
129
|
}
|
|
117
130
|
|
|
118
|
-
private outputJson(chats: ChatInfo[],
|
|
131
|
+
private outputJson(chats: ChatInfo[], out: string): void {
|
|
119
132
|
const output = JSON.stringify({ chats }, null, 2);
|
|
120
|
-
if (
|
|
121
|
-
this.writeOutput(
|
|
133
|
+
if (out) {
|
|
134
|
+
this.writeOutput(out, output);
|
|
122
135
|
} else {
|
|
123
136
|
console.log(output);
|
|
124
137
|
}
|
|
125
138
|
}
|
|
126
139
|
|
|
127
|
-
private outputText(chats: ChatInfo[],
|
|
140
|
+
private outputText(chats: ChatInfo[], out: string, allProfiles: boolean): void {
|
|
128
141
|
const output = formatChatList(chats, { includeProfileColumn: allProfiles });
|
|
129
|
-
if (
|
|
130
|
-
this.writeOutput(
|
|
142
|
+
if (out) {
|
|
143
|
+
this.writeOutput(out, output);
|
|
131
144
|
} else {
|
|
132
145
|
console.log(output);
|
|
133
146
|
}
|
|
134
147
|
}
|
|
135
148
|
|
|
136
|
-
private writeOutput(
|
|
137
|
-
writeTextFile(
|
|
138
|
-
console.log(chalk.dim(`Output written to: ${
|
|
149
|
+
private writeOutput(out: string, content: string): void {
|
|
150
|
+
writeTextFile(out, content);
|
|
151
|
+
console.log(chalk.dim(`Output written to: ${out}`));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private async runInteractiveBrowser(
|
|
155
|
+
chats: ChatInfo[],
|
|
156
|
+
options: ListCommandOptions,
|
|
157
|
+
context: CliCommandContext,
|
|
158
|
+
): Promise<void> {
|
|
159
|
+
while (true) {
|
|
160
|
+
const result = await browser({
|
|
161
|
+
chats,
|
|
162
|
+
initialSort: options.sort,
|
|
163
|
+
});
|
|
164
|
+
if (result.kind === "quit") return;
|
|
165
|
+
const actionResult = await this.showActionMenu(result.chat);
|
|
166
|
+
if (actionResult === "quit") return;
|
|
167
|
+
if (actionResult === "back") continue;
|
|
168
|
+
await this.executeAction(actionResult, result.chat, context);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
private async showActionMenu(chat: ChatInfo): Promise<BrowserAction> {
|
|
173
|
+
const choice = await select<BrowserAction>({
|
|
174
|
+
message: `Selected: ${chat.id} — "${chat.title}"`,
|
|
175
|
+
choices: [
|
|
176
|
+
{ value: "view", label: "View full conversation" },
|
|
177
|
+
{ value: "export-markdown", label: "Export to Markdown" },
|
|
178
|
+
{ value: "export-json", label: "Export to JSON" },
|
|
179
|
+
{ value: "copy-id", label: "Copy conversation ID" },
|
|
180
|
+
{ value: "back", label: "Back to list" },
|
|
181
|
+
{ value: "quit", label: "Quit" },
|
|
182
|
+
],
|
|
183
|
+
});
|
|
184
|
+
return choice;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private async executeAction(
|
|
188
|
+
action: "view" | "export-markdown" | "export-json" | "copy-id",
|
|
189
|
+
chat: ChatInfo,
|
|
190
|
+
context: CliCommandContext,
|
|
191
|
+
): Promise<void> {
|
|
192
|
+
if (action === "copy-id") {
|
|
193
|
+
console.log(chalk.cyan(`Copied: ${chat.id}`));
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const { CommandRegistry } = await import("../command-registry.ts");
|
|
197
|
+
const registry = new CommandRegistry();
|
|
198
|
+
registry.registerAllCommands();
|
|
199
|
+
if (action === "view") {
|
|
200
|
+
const fetch = registry.getHandler("fetch");
|
|
201
|
+
if (fetch) await fetch.execute([chat.id, "--format", "text"], context);
|
|
202
|
+
} else if (action === "export-markdown") {
|
|
203
|
+
const exportCmd = registry.getHandler("export");
|
|
204
|
+
if (exportCmd) await exportCmd.execute([chat.id, "--format", "markdown"], context);
|
|
205
|
+
} else if (action === "export-json") {
|
|
206
|
+
const exportCmd = registry.getHandler("export");
|
|
207
|
+
if (exportCmd) await exportCmd.execute([chat.id, "--format", "json"], context);
|
|
208
|
+
}
|
|
139
209
|
}
|
|
140
210
|
|
|
141
211
|
private parseArgs(args: string[]): ListCommandOptions {
|
|
@@ -155,12 +225,13 @@ export class ListCommand implements CliCommand {
|
|
|
155
225
|
case "--offset":
|
|
156
226
|
options.offset = parseInt(args[++i], 10) || 0;
|
|
157
227
|
break;
|
|
158
|
-
case "--all":
|
|
159
|
-
options.all = true;
|
|
160
|
-
break;
|
|
161
228
|
case "--all-profiles":
|
|
162
229
|
options.allProfiles = true;
|
|
163
230
|
break;
|
|
231
|
+
case "--profile":
|
|
232
|
+
case "-p":
|
|
233
|
+
options.profile = args[++i] ?? "";
|
|
234
|
+
break;
|
|
164
235
|
case "--sort":
|
|
165
236
|
options.sort = this.parseSort(args[++i]);
|
|
166
237
|
break;
|
|
@@ -178,13 +249,28 @@ export class ListCommand implements CliCommand {
|
|
|
178
249
|
case "-f":
|
|
179
250
|
options.format = this.parseFormat(args[++i]);
|
|
180
251
|
break;
|
|
181
|
-
case "--
|
|
182
|
-
case "-
|
|
183
|
-
options.
|
|
252
|
+
case "--out":
|
|
253
|
+
case "-o":
|
|
254
|
+
options.out = args[++i] ?? "";
|
|
255
|
+
break;
|
|
256
|
+
case "--interactive":
|
|
257
|
+
case "-i":
|
|
258
|
+
options.interactive = true;
|
|
184
259
|
break;
|
|
185
260
|
}
|
|
186
261
|
}
|
|
187
262
|
|
|
263
|
+
if (options.interactive && !options.profile) {
|
|
264
|
+
options.allProfiles = true;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (
|
|
268
|
+
options.interactive &&
|
|
269
|
+
(options.format !== DEFAULT_OPTIONS.format || options.out !== DEFAULT_OPTIONS.out)
|
|
270
|
+
) {
|
|
271
|
+
throw new GemitermError("Cannot use --interactive with --format or --out.");
|
|
272
|
+
}
|
|
273
|
+
|
|
188
274
|
return options;
|
|
189
275
|
}
|
|
190
276
|
|
|
@@ -204,16 +290,17 @@ export class ListCommand implements CliCommand {
|
|
|
204
290
|
console.log(chalk.bold("Options:"));
|
|
205
291
|
|
|
206
292
|
const flags = [
|
|
207
|
-
{ flag: "--limit, -n N", desc: "
|
|
293
|
+
{ flag: "--limit, -n N", desc: "Limit number of results (no limit by default)" },
|
|
208
294
|
{ flag: "--offset N", desc: "Skip N results (default: 0)" },
|
|
209
|
-
{ flag: "--all", desc: "Show all conversations (no limit)" },
|
|
210
295
|
{ flag: "--all-profiles", desc: "Show conversations from all profiles (with Profile column in text output)" },
|
|
296
|
+
{ flag: "--profile, -p <name>", desc: "Filter conversations to a specific profile (non-interactive)" },
|
|
211
297
|
{ flag: "--sort <mode>", desc: "Sort order: recent, oldest, alpha (default: recent)" },
|
|
212
298
|
{ flag: "--search, -s <query>", desc: "Filter by title search" },
|
|
213
299
|
{ flag: "--after <date>", desc: "Only show chats after this date" },
|
|
214
300
|
{ flag: "--before <date>", desc: "Only show chats before this date" },
|
|
215
301
|
{ flag: "--format, -f <fmt>", desc: "Output format: text, json (default: text)" },
|
|
216
|
-
{ flag: "--
|
|
302
|
+
{ flag: "--out, -o <path>", desc: "Write output to file" },
|
|
303
|
+
{ flag: "--interactive, -i", desc: "Open interactive chat-list browser (TTY only; shows all profiles by default)" },
|
|
217
304
|
{ flag: "--help, -h", desc: "Show this help message" },
|
|
218
305
|
];
|
|
219
306
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
-
import { createInterface } from "node:readline";
|
|
3
2
|
import type { CliCommand, CliCommandContext } from "../command-registry.ts";
|
|
3
|
+
import { text } from "../utils/prompts.ts";
|
|
4
4
|
import { Logger } from "../../infrastructure/logger.ts";
|
|
5
5
|
import { CookieStorage, ProfileManager } from "../../infrastructure/storage.ts";
|
|
6
6
|
import { PlaywrightCliDriver } from "../../services/playwright-cli-driver.ts";
|
|
@@ -215,12 +215,6 @@ export class ProfileCommand implements CliCommand {
|
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
private promptInput(prompt: string): Promise<string> {
|
|
218
|
-
return
|
|
219
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
220
|
-
rl.question(`${chalk.cyan(prompt + ": ")} `, (answer) => {
|
|
221
|
-
rl.close();
|
|
222
|
-
resolve(answer);
|
|
223
|
-
});
|
|
224
|
-
});
|
|
218
|
+
return text({ message: prompt });
|
|
225
219
|
}
|
|
226
220
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
-
import {
|
|
2
|
+
import { CancellationError, text, type TextOptions } from "./prompts.ts";
|
|
3
3
|
|
|
4
4
|
export interface MessageHandlerResult {
|
|
5
5
|
response: string;
|
|
@@ -11,54 +11,62 @@ export interface InteractiveLoopOptions {
|
|
|
11
11
|
profileName?: string | null;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
export interface InteractiveLoopDeps {
|
|
15
|
+
text: (opts: TextOptions) => Promise<string>;
|
|
16
|
+
CancellationError: typeof CancellationError;
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
export async function runInteractiveLoop(
|
|
15
20
|
messageHandler: MessageHandler,
|
|
16
21
|
options: InteractiveLoopOptions = {},
|
|
22
|
+
deps: InteractiveLoopDeps = { text, CancellationError },
|
|
17
23
|
): Promise<void> {
|
|
18
24
|
const profileLabel = options.profileName ?? "default";
|
|
19
25
|
console.log(chalk.dim(`Starting chat session (profile: ${chalk.cyan(profileLabel)})`));
|
|
20
26
|
console.log(chalk.dim("Type your message and press Enter. Type /exit to quit.\n"));
|
|
21
27
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
let resolveOuter: () => void = () => {};
|
|
29
|
+
const outerPromise = new Promise<void>((resolve) => {
|
|
30
|
+
resolveOuter = resolve;
|
|
25
31
|
});
|
|
26
32
|
|
|
27
|
-
const prompt = (): void => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
const prompt = async (): Promise<void> => {
|
|
34
|
+
let input: string;
|
|
35
|
+
try {
|
|
36
|
+
input = await deps.text({ message: "You" });
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error instanceof deps.CancellationError) {
|
|
39
|
+
console.log(chalk.dim("\nGoodbye."));
|
|
40
|
+
resolveOuter();
|
|
33
41
|
return;
|
|
34
42
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
})
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
const trimmed = input.trim();
|
|
46
|
+
if (trimmed === "/exit" || trimmed === "/quit") {
|
|
47
|
+
console.log(chalk.dim("\nGoodbye."));
|
|
48
|
+
resolveOuter();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (!trimmed) {
|
|
52
|
+
await prompt();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
console.log(chalk.dim("Thinking…"));
|
|
57
|
+
const result = await messageHandler(trimmed);
|
|
58
|
+
console.log(chalk.blue.bold("Model:"));
|
|
59
|
+
console.log(result.response);
|
|
60
|
+
console.log("");
|
|
61
|
+
} catch (error) {
|
|
62
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
63
|
+
console.error(chalk.red(`Error: ${message}`));
|
|
64
|
+
console.log("");
|
|
65
|
+
}
|
|
66
|
+
await prompt();
|
|
54
67
|
};
|
|
55
68
|
|
|
56
69
|
prompt();
|
|
57
70
|
|
|
58
|
-
await
|
|
59
|
-
|
|
60
|
-
console.log(chalk.dim("\nGoodbye."));
|
|
61
|
-
resolve();
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
}
|
|
71
|
+
await outerPromise;
|
|
72
|
+
}
|