ima2-gen 1.1.21 → 1.1.22

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 (208) hide show
  1. package/README.md +30 -4
  2. package/bin/ima2.js +14 -4
  3. package/bin/lib/platform.js +34 -5
  4. package/docs/README.ko.md +31 -0
  5. package/lib/agentQueueWorker.js +6 -0
  6. package/lib/agentRuntime.js +3 -2
  7. package/lib/atomicWrite.js +14 -0
  8. package/lib/grokProxyLauncher.js +5 -3
  9. package/lib/inflight.js +1 -1
  10. package/lib/oauthLauncher.js +5 -0
  11. package/lib/videoFrameExtract.js +3 -3
  12. package/package.json +5 -7
  13. package/routes/edit.js +2 -1
  14. package/routes/generate.js +4 -3
  15. package/routes/health.js +4 -3
  16. package/routes/multimode.js +2 -1
  17. package/routes/video.js +4 -2
  18. package/server.js +29 -2
  19. package/ui/dist/.vite/manifest.json +12 -12
  20. package/ui/dist/assets/{AgentWorkspace-B_hq9CLg.js → AgentWorkspace-COxQ5TjU.js} +1 -1
  21. package/ui/dist/assets/{CardNewsWorkspace-wD12J7qk.js → CardNewsWorkspace-B0OkcuVz.js} +1 -1
  22. package/ui/dist/assets/{NodeCanvas-CI_wuPMf.js → NodeCanvas-BSsclEBh.js} +1 -1
  23. package/ui/dist/assets/{PromptBuilderPanel-CUTujJUV.js → PromptBuilderPanel-DpC9A5Rz.js} +1 -1
  24. package/ui/dist/assets/{PromptImportDialog-CUi66jPK.js → PromptImportDialog-CVwT0rLd.js} +2 -2
  25. package/ui/dist/assets/{PromptImportDiscoverySection-Cm3vrjY4.js → PromptImportDiscoverySection-BDCkRCRs.js} +1 -1
  26. package/ui/dist/assets/{PromptImportFolderSection-DOtWTD9n.js → PromptImportFolderSection-QoKbZD83.js} +1 -1
  27. package/ui/dist/assets/{PromptLibraryPanel-BMjQegRa.js → PromptLibraryPanel-BhFgeKnY.js} +2 -2
  28. package/ui/dist/assets/SettingsWorkspace-CfjrlH5R.js +1 -0
  29. package/ui/dist/assets/index-C-mur7pa.css +1 -0
  30. package/ui/dist/assets/index-CCP5nUOj.js +42 -0
  31. package/ui/dist/assets/{index-31uVIdt4.js → index-Cxhzi3bs.js} +1 -1
  32. package/ui/dist/index.html +2 -2
  33. package/bin/commands/annotate.ts +0 -119
  34. package/bin/commands/cancel.ts +0 -48
  35. package/bin/commands/canvas-versions.ts +0 -80
  36. package/bin/commands/capabilities.ts +0 -110
  37. package/bin/commands/cardnews.ts +0 -249
  38. package/bin/commands/comfy.ts +0 -54
  39. package/bin/commands/config.ts +0 -186
  40. package/bin/commands/defaults.ts +0 -192
  41. package/bin/commands/doctor.ts +0 -202
  42. package/bin/commands/edit.ts +0 -150
  43. package/bin/commands/gen.ts +0 -214
  44. package/bin/commands/grok.ts +0 -90
  45. package/bin/commands/history.ts +0 -146
  46. package/bin/commands/ls.ts +0 -64
  47. package/bin/commands/metadata.ts +0 -39
  48. package/bin/commands/multimode.ts +0 -196
  49. package/bin/commands/node.ts +0 -166
  50. package/bin/commands/observability.ts +0 -176
  51. package/bin/commands/ping.ts +0 -31
  52. package/bin/commands/prompt-sub/build.ts +0 -101
  53. package/bin/commands/prompt.ts +0 -492
  54. package/bin/commands/ps.ts +0 -81
  55. package/bin/commands/session.ts +0 -266
  56. package/bin/commands/show.ts +0 -72
  57. package/bin/commands/skill.ts +0 -70
  58. package/bin/commands/video.ts +0 -442
  59. package/bin/ima2.ts +0 -430
  60. package/bin/lib/args.ts +0 -92
  61. package/bin/lib/browser-id.ts +0 -16
  62. package/bin/lib/client.ts +0 -122
  63. package/bin/lib/config-store.ts +0 -120
  64. package/bin/lib/destructive-confirm.ts +0 -19
  65. package/bin/lib/doctor-checks.ts +0 -91
  66. package/bin/lib/error-hints.ts +0 -23
  67. package/bin/lib/files.ts +0 -39
  68. package/bin/lib/output.ts +0 -73
  69. package/bin/lib/platform.ts +0 -99
  70. package/bin/lib/recover-output.ts +0 -139
  71. package/bin/lib/sse.ts +0 -73
  72. package/bin/lib/star-prompt.ts +0 -97
  73. package/bin/lib/storage-doctor.ts +0 -39
  74. package/bin/lib/ui-build.ts +0 -85
  75. package/config.ts +0 -354
  76. package/lib/agentCommandParser.ts +0 -69
  77. package/lib/agentGenerationPlanner.ts +0 -273
  78. package/lib/agentQuestionResponder.ts +0 -266
  79. package/lib/agentQueueStore.ts +0 -270
  80. package/lib/agentQueueWorker.ts +0 -89
  81. package/lib/agentRuntime.ts +0 -604
  82. package/lib/agentSettings.ts +0 -72
  83. package/lib/agentStore.ts +0 -422
  84. package/lib/agentStoreRows.ts +0 -136
  85. package/lib/agentTypes.ts +0 -154
  86. package/lib/apiCachePolicy.ts +0 -11
  87. package/lib/assetLifecycle.ts +0 -146
  88. package/lib/canvasVersionStore.ts +0 -223
  89. package/lib/capabilities.ts +0 -126
  90. package/lib/cardNewsGenerator.ts +0 -271
  91. package/lib/cardNewsJobStore.ts +0 -142
  92. package/lib/cardNewsManifestStore.ts +0 -154
  93. package/lib/cardNewsPlanner.ts +0 -236
  94. package/lib/cardNewsPlannerClient.ts +0 -155
  95. package/lib/cardNewsPlannerPrompt.ts +0 -62
  96. package/lib/cardNewsPlannerSchema.ts +0 -321
  97. package/lib/cardNewsRoleTemplateStore.ts +0 -47
  98. package/lib/cardNewsTemplateStore.ts +0 -252
  99. package/lib/codexDetect.ts +0 -71
  100. package/lib/comfyBridge.ts +0 -235
  101. package/lib/composerSnapshot.ts +0 -33
  102. package/lib/configKeys.ts +0 -62
  103. package/lib/db.ts +0 -295
  104. package/lib/errInfo.ts +0 -43
  105. package/lib/errorClassify.ts +0 -100
  106. package/lib/generationCancel.ts +0 -28
  107. package/lib/generationErrors.ts +0 -238
  108. package/lib/grokImageAdapter.ts +0 -513
  109. package/lib/grokMultimodeAdapter.ts +0 -84
  110. package/lib/grokProxyLauncher.ts +0 -153
  111. package/lib/grokRuntime.ts +0 -23
  112. package/lib/grokSizeMapper.ts +0 -71
  113. package/lib/grokVideoAdapter.ts +0 -458
  114. package/lib/grokVideoCanvas.ts +0 -26
  115. package/lib/grokVideoDownload.ts +0 -59
  116. package/lib/grokVideoPlannerPrompt.ts +0 -67
  117. package/lib/historyIndex.ts +0 -51
  118. package/lib/historyList.ts +0 -181
  119. package/lib/imageMetadata.ts +0 -113
  120. package/lib/imageMetadataStore.ts +0 -67
  121. package/lib/imageModels.ts +0 -165
  122. package/lib/inflight.ts +0 -281
  123. package/lib/localImportStore.ts +0 -114
  124. package/lib/logger.ts +0 -161
  125. package/lib/nodeStore.ts +0 -91
  126. package/lib/oauthLauncher.ts +0 -94
  127. package/lib/oauthNormalize.ts +0 -30
  128. package/lib/oauthProxy/errors.ts +0 -128
  129. package/lib/oauthProxy/generators.ts +0 -494
  130. package/lib/oauthProxy/index.ts +0 -28
  131. package/lib/oauthProxy/prompts.ts +0 -123
  132. package/lib/oauthProxy/references.ts +0 -45
  133. package/lib/oauthProxy/runtime.ts +0 -115
  134. package/lib/oauthProxy/streams.ts +0 -232
  135. package/lib/oauthProxy/types.ts +0 -9
  136. package/lib/oauthProxy.ts +0 -3
  137. package/lib/openDirectory.ts +0 -47
  138. package/lib/pngInfo.ts +0 -26
  139. package/lib/promptBuilder/attachments.ts +0 -74
  140. package/lib/promptBuilder/client.ts +0 -130
  141. package/lib/promptBuilder/constants.ts +0 -9
  142. package/lib/promptBuilder/context.ts +0 -36
  143. package/lib/promptBuilder/errors.ts +0 -12
  144. package/lib/promptBuilder/requestSchema.ts +0 -56
  145. package/lib/promptBuilder/responseParser.ts +0 -219
  146. package/lib/promptBuilder/systemPrompt.ts +0 -135
  147. package/lib/promptBuilder/transport.ts +0 -94
  148. package/lib/promptBuilder/types.ts +0 -109
  149. package/lib/promptImport/curatedSources.ts +0 -141
  150. package/lib/promptImport/discoveryRegistry.ts +0 -329
  151. package/lib/promptImport/errors.ts +0 -18
  152. package/lib/promptImport/githubDiscovery.ts +0 -309
  153. package/lib/promptImport/githubFolder.ts +0 -397
  154. package/lib/promptImport/githubSource.ts +0 -257
  155. package/lib/promptImport/gptImageHints.ts +0 -70
  156. package/lib/promptImport/parsePromptCandidates.ts +0 -179
  157. package/lib/promptImport/promptIndex.ts +0 -326
  158. package/lib/promptImport/rankPromptCandidates.ts +0 -65
  159. package/lib/promptImport/types.ts +0 -103
  160. package/lib/promptSafetyPolicy.ts +0 -5
  161. package/lib/providerOptions.ts +0 -56
  162. package/lib/referenceImageCompress.ts +0 -84
  163. package/lib/refs.ts +0 -133
  164. package/lib/requestLogger.ts +0 -49
  165. package/lib/responsesDoctor.ts +0 -456
  166. package/lib/responsesErrors.ts +0 -83
  167. package/lib/responsesFallback.ts +0 -114
  168. package/lib/responsesImageAdapter.ts +0 -466
  169. package/lib/responsesParse.ts +0 -452
  170. package/lib/responsesTools.ts +0 -28
  171. package/lib/runtimeContext.ts +0 -146
  172. package/lib/runtimePorts.ts +0 -105
  173. package/lib/sessionStore.ts +0 -308
  174. package/lib/storageMigration.ts +0 -310
  175. package/lib/styleSheet.ts +0 -139
  176. package/lib/systemTrash.ts +0 -20
  177. package/lib/videoContinuity.ts +0 -180
  178. package/lib/videoFrameExtract.ts +0 -78
  179. package/lib/videoSeriesChain.ts +0 -29
  180. package/lib/visibleTextLanguagePolicy.ts +0 -7
  181. package/routes/agent.ts +0 -308
  182. package/routes/annotations.ts +0 -118
  183. package/routes/canvasVersions.ts +0 -69
  184. package/routes/capabilities.ts +0 -18
  185. package/routes/cardNews.ts +0 -211
  186. package/routes/comfy.ts +0 -43
  187. package/routes/edit.ts +0 -352
  188. package/routes/generate.ts +0 -492
  189. package/routes/grok.ts +0 -24
  190. package/routes/health.ts +0 -123
  191. package/routes/history.ts +0 -221
  192. package/routes/imageImport.ts +0 -37
  193. package/routes/index.ts +0 -52
  194. package/routes/metadata.ts +0 -77
  195. package/routes/multimode.ts +0 -499
  196. package/routes/nodes.ts +0 -578
  197. package/routes/promptBuilder.ts +0 -37
  198. package/routes/promptImport.ts +0 -379
  199. package/routes/prompts.ts +0 -428
  200. package/routes/quota.ts +0 -89
  201. package/routes/sessions.ts +0 -317
  202. package/routes/storage.ts +0 -47
  203. package/routes/video.ts +0 -300
  204. package/routes/videoExtended.ts +0 -284
  205. package/server.ts +0 -293
  206. package/ui/dist/assets/SettingsWorkspace-PiaVnsdA.js +0 -1
  207. package/ui/dist/assets/index-CjgnNtgt.css +0 -1
  208. package/ui/dist/assets/index-Da2s4_-5.js +0 -36
@@ -1,214 +0,0 @@
1
- import { parseArgs } from "../lib/args.js";
2
- import { resolveServer, request, normalizeGenerate } from "../lib/client.js";
3
- import { fileToDataUri, dataUriToFile, defaultOutName, readStdin } from "../lib/files.js";
4
- import { out, die, dieWithError, color, json } from "../lib/output.js";
5
- import { config } from "../../config.js";
6
- import { createCliRequestId, recoverGeneratedOutputs, formatRecoveryHint } from "../lib/recover-output.js";
7
-
8
- import { errInfo } from "../../lib/errInfo.js";
9
- const VALID_MODES = new Set(["auto", "direct"]);
10
- const VALID_MODERATION = new Set(["auto", "low"]);
11
- const VALID_PROVIDERS = new Set(["auto", "oauth", "api", "grok"]);
12
- const KNOWN_IMAGE_MODELS = new Set(["gpt-5.5", "gpt-5.4", "gpt-5.4-mini", "gpt-5.3-codex-spark", "grok-imagine-image", "grok-imagine-image-quality"]);
13
-
14
- const SPEC = {
15
- flags: {
16
- quality: { short: "q", type: "string", default: "low" },
17
- size: { short: "s", type: "string", default: "1024x1024" },
18
- count: { short: "n", type: "string", default: "1" },
19
- ref: { type: "string", repeatable: true },
20
- out: { short: "o", type: "string" },
21
- "out-dir": { short: "d", type: "string" },
22
- json: { type: "boolean" },
23
- "no-save": { type: "boolean" },
24
- force: { type: "boolean" },
25
- stdin: { type: "boolean" },
26
- timeout: { type: "string", default: "180" },
27
- server: { type: "string" },
28
- model: { type: "string" },
29
- provider: { type: "string" },
30
- mode: { type: "string", default: "auto" },
31
- moderation: { type: "string", default: "low" },
32
- session: { type: "string" },
33
- "reasoning-effort": { type: "string" },
34
- "web-search": { type: "boolean" },
35
- "no-web-search": { type: "boolean" },
36
- help: { short: "h", type: "boolean" },
37
- },
38
- };
39
-
40
- const HELP = `
41
- ima2 gen <prompt...> [options]
42
-
43
- Generate image(s) via the running ima2 server.
44
-
45
- Options:
46
- -q, --quality <low|medium|high> Default: low
47
- -s, --size <WxH | auto> Default: 1024x1024
48
- -n, --count <1..8> Default: 1
49
- --ref <file> Attach reference image (repeatable, max 5)
50
- -o, --out <file> Single-image output path (implies -n 1)
51
- -d, --out-dir <dir> Output dir for multiple images
52
- --json Print JSON result to stdout
53
- --no-save Skip save; print b64 to stdout (use --force for TTY)
54
- --stdin Read prompt from stdin
55
- --timeout <sec> Default: 180
56
- --server <url> Override server URL
57
- --model <gpt-5.5|gpt-5.4|gpt-5.4-mini|grok-imagine-image|grok-imagine-image-quality>
58
- --provider <auto|oauth|api|grok> Provider (oauth = GPT OAuth; grok = xAI Grok)
59
- --mode <auto|direct> Prompt handling mode. Default: auto
60
- --moderation <auto|low> Default: low
61
- --session <id> Apply session style sheet if enabled
62
- --reasoning-effort <none|low|medium|high|xhigh>
63
- Override server's reasoning effort
64
- --web-search / --no-web-search Override default web-search toggle
65
-
66
- Examples:
67
- ima2 gen "a shiba in space"
68
- ima2 gen "poster" --model gpt-5.4 --mode direct --moderation low
69
- ima2 gen "merge" --ref a.png --ref b.png -q high -o out.png
70
- cat prompt.txt | ima2 gen --stdin -n 2 -d ./out
71
- `;
72
-
73
- export default async function genCmd(argv: string[]) {
74
- const args = parseArgs(argv, SPEC);
75
- if (args.help) { out(HELP); return; }
76
-
77
- let prompt = args.positional.join(" ");
78
- if (args.stdin) {
79
- const piped = await readStdin();
80
- if (piped) prompt = prompt ? `${prompt} ${piped}` : piped;
81
- }
82
- if (!prompt) die(2, "prompt is required (positional or via --stdin)");
83
-
84
- const refs = (Array.isArray(args.ref) ? args.ref : []) as string[];
85
- if (refs.length > 5) die(2, "max 5 --ref attachments");
86
- if (!VALID_MODES.has(String(args.mode))) die(2, "--mode must be one of: auto, direct");
87
- if (!VALID_MODERATION.has(String(args.moderation))) die(2, "--moderation must be one of: auto, low");
88
- if (args.provider && !VALID_PROVIDERS.has(String(args.provider))) {
89
- die(2, "--provider must be one of: auto, oauth, api, grok");
90
- }
91
- if (args.model && !KNOWN_IMAGE_MODELS.has(String(args.model))) {
92
- die(2, "--model must be one of: gpt-5.5, gpt-5.4, gpt-5.4-mini, gpt-5.3-codex-spark, grok-imagine-image, grok-imagine-image-quality");
93
- }
94
- const VALID_REASONING = new Set(["none", "low", "medium", "high", "xhigh"]);
95
- if (args["reasoning-effort"] && !VALID_REASONING.has(String(args["reasoning-effort"]))) {
96
- die(2, "--reasoning-effort must be one of: none, low, medium, high, xhigh");
97
- }
98
- if (args["web-search"] && args["no-web-search"]) {
99
- die(2, "--web-search and --no-web-search are mutually exclusive");
100
- }
101
-
102
- const n = Math.max(1, Math.min(8, parseInt(String(args.count)) || 1));
103
- const timeoutMs = (parseInt(String(args.timeout)) || 180) * 1000;
104
-
105
- let server;
106
- try {
107
- server = await resolveServer({ serverFlag: args.server });
108
- } catch (e) {
109
- const err = errInfo(e);
110
- if (args.json) json({ ok: false, error: err.message, code: err.code, status: err.status });
111
- dieWithError(e);
112
- }
113
-
114
- const references = await Promise.all(refs.map((p: string) => fileToDataUri(p)));
115
-
116
- const outDir = args["out-dir"] ? String(args["out-dir"]) : null;
117
- const explicitOut = args.out ? String(args.out) : null;
118
- const requestId = createCliRequestId("req_cli_gen");
119
-
120
- const body: any = {
121
- prompt,
122
- quality: args.quality,
123
- size: args.size,
124
- n,
125
- references,
126
- model: args.model,
127
- mode: args.mode,
128
- moderation: args.moderation,
129
- sessionId: args.session,
130
- requestId,
131
- };
132
- if (args["reasoning-effort"]) body.reasoningEffort = args["reasoning-effort"];
133
- if (args.provider) body.provider = args.provider;
134
- if (args["no-web-search"]) body.webSearchEnabled = false;
135
- else if (args["web-search"]) body.webSearchEnabled = true;
136
-
137
- let resp;
138
- try {
139
- resp = await request(server.base, "/api/generate", {
140
- method: "POST",
141
- body,
142
- timeoutMs,
143
- headers: { "X-Request-Id": requestId },
144
- });
145
- } catch (e) {
146
- const err = errInfo(e);
147
- const isTimeout = err.name === "TimeoutError" || err.name === "AbortError";
148
- if (isTimeout && (explicitOut || outDir)) {
149
- const result = await recoverGeneratedOutputs(server.base, requestId, {
150
- explicitOut,
151
- outDir,
152
- expectedCount: n,
153
- json: Boolean(args.json),
154
- });
155
- if (result.recovered) {
156
- if (args.json) {
157
- json({ ok: true, requestId, recovered: true, images: result.paths.map((p) => ({ path: p })) });
158
- } else {
159
- out(formatRecoveryHint(result));
160
- for (const p of result.paths) out(color.green("✓ ") + p + color.dim(" (recovered)"));
161
- }
162
- return;
163
- }
164
- if (!args.json) out(formatRecoveryHint(result));
165
- }
166
- if (args.json) json({ ok: false, error: err.message, code: err.code, status: err.status, requestId });
167
- dieWithError(e);
168
- }
169
-
170
- const norm = normalizeGenerate(resp);
171
- if (norm.images.length === 0) die(1, "server returned no images");
172
-
173
- // --no-save path
174
- if (args["no-save"]) {
175
- const totalBytes = norm.images.reduce((s: number, im) => s + (im.image?.length ?? 0), 0);
176
- if (process.stdout.isTTY && totalBytes > 2 * 1024 * 1024 && !args.force) {
177
- die(2, "refusing to print >2MB of b64 to TTY; use --force or drop --no-save");
178
- }
179
- for (const im of norm.images) out(im.image);
180
- return;
181
- }
182
-
183
- // Save path
184
- if (explicitOut && norm.images.length > 1) {
185
- die(2, "--out only supports a single image; use --out-dir for n>1");
186
- }
187
-
188
- const savedPaths: string[] = [];
189
- for (let i = 0; i < norm.images.length; i++) {
190
- const im = norm.images[i];
191
- let target: string;
192
- if (explicitOut) {
193
- target = explicitOut;
194
- } else if (outDir) {
195
- target = `${outDir}/${defaultOutName(i, norm.images.length)}`;
196
- } else {
197
- target = `${config.storage.generatedDir}/${defaultOutName(i, norm.images.length)}`;
198
- }
199
- await dataUriToFile(String(im.image), target);
200
- savedPaths.push(target);
201
- }
202
-
203
- if (args.json) {
204
- json({
205
- ok: true,
206
- requestId: norm.requestId,
207
- elapsed: norm.elapsed,
208
- images: savedPaths.map((p, i) => ({ path: p, filename: norm.images[i].filename })),
209
- });
210
- } else {
211
- for (const p of savedPaths) out(color.green("✓ ") + p);
212
- if (norm.elapsed) out(color.dim(`elapsed ${norm.elapsed}s`));
213
- }
214
- }
@@ -1,90 +0,0 @@
1
- import { spawn } from "node:child_process";
2
- import { dirname, join, delimiter } from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- import { color, die, out } from "../lib/output.js";
5
- import { isWin } from "../lib/platform.js";
6
-
7
- const __dirname = dirname(fileURLToPath(import.meta.url));
8
- const ROOT = join(__dirname, "..", "..");
9
- const HELP = `
10
- ima2 grok <subcommand> [options]
11
-
12
- Manage the bundled progrok runtime used by the Grok image provider.
13
- No separate progrok install is required.
14
-
15
- Subcommands:
16
- login [options] Log in to xAI OAuth (default: --manual-paste)
17
- logout Remove stored xAI credentials
18
- status Show bundled progrok authentication status
19
- models List available Grok models
20
- proxy [options] Start the bundled proxy directly
21
-
22
- Notes:
23
- ima2 serve auto-starts the bundled proxy on 127.0.0.1:18645 by default.
24
- ima2 grok login defaults to --manual-paste for reliable copy/paste auth.
25
- Use IMA2_NO_GROK_PROXY=1 to disable automatic proxy startup.
26
- `;
27
-
28
- const MANUAL_PASTE_FLAG = "--manual-paste";
29
- const NON_MANUAL_LOGIN_FLOW_FLAGS = new Set(["--device-code", "--browser"]);
30
-
31
- function localBinPath() {
32
- return join(ROOT, "node_modules", ".bin");
33
- }
34
-
35
- function spawnProgrok(argv: string[], env: NodeJS.ProcessEnv): Promise<number | null> {
36
- return new Promise((resolve, reject) => {
37
- const progrokBin = join(localBinPath(), isWin ? "progrok.cmd" : "progrok");
38
- const child = spawn(progrokBin, argv, {
39
- cwd: ROOT,
40
- env,
41
- stdio: "inherit",
42
- shell: isWin,
43
- windowsHide: true,
44
- });
45
- child.on("error", (err) => reject(err));
46
- child.on("close", resolve);
47
- });
48
- }
49
-
50
- export function normalizeGrokLoginArgs(argv: string[]): string[] {
51
- const sub = argv[0];
52
- if (sub !== "login") return argv;
53
- const normalized = argv.filter((arg) => !NON_MANUAL_LOGIN_FLOW_FLAGS.has(arg));
54
- if (normalized.includes(MANUAL_PASTE_FLAG)) return normalized;
55
- return [...normalized, MANUAL_PASTE_FLAG];
56
- }
57
-
58
- export default async function grokCmd(argv: string[]) {
59
- const sub = argv[0];
60
- if (!sub || sub === "--help" || sub === "-h") {
61
- out(HELP);
62
- return;
63
- }
64
-
65
- const env = {
66
- ...process.env,
67
- PATH: `${localBinPath()}${delimiter}${process.env.PATH || ""}`,
68
- };
69
-
70
- try {
71
- argv = normalizeGrokLoginArgs(argv);
72
-
73
- const code = await spawnProgrok(argv, env);
74
- if (code && code !== 0) {
75
- if (sub === "login") {
76
- out(color.yellow("⚠ ") + "Login failed. Try again with:\n");
77
- out(" ima2 grok login\n");
78
- die(code, "bundled Grok OAuth login failed");
79
- } else {
80
- die(code, `bundled progrok exited with code ${code}`);
81
- }
82
- }
83
- } catch (err: any) {
84
- die(1, `bundled progrok failed to start: ${err.message}`);
85
- }
86
-
87
- if (sub === "login") {
88
- out(color.green("✓ ") + "Grok OAuth is ready for ima2 serve");
89
- }
90
- }
@@ -1,146 +0,0 @@
1
- import { readFile } from "fs/promises";
2
- import { extname, basename } from "path";
3
- import { parseArgs, type ParsedArgs } from "../lib/args.js";
4
- import { resolveServer, request } from "../lib/client.js";
5
- import { out, die, color, json, exitCodeForError } from "../lib/output.js";
6
- import { getCliBrowserId } from "../lib/browser-id.js";
7
-
8
- const HELP = `
9
- ima2 history <subcommand> [options]
10
-
11
- Subcommands:
12
- rm <filename> [--permanent] [--yes] Soft-delete (default) or hard-delete
13
- restore <filename> --trash-id <id> Restore from trash
14
- favorite <filename> Toggle favorite status
15
- import <localfile> Import a local image into history
16
-
17
- Common options:
18
- --server <url> Override server URL
19
- --json JSON output
20
- --yes Skip destructive confirmation
21
- `;
22
-
23
- const COMMON_FLAGS = {
24
- json: { type: "boolean" },
25
- server: { type: "string" },
26
- yes: { type: "boolean" },
27
- permanent: { type: "boolean" },
28
- "trash-id": { type: "string" },
29
- help: { short: "h", type: "boolean" },
30
- };
31
-
32
- async function getServer(args: ParsedArgs) {
33
- try { return await resolveServer({ serverFlag: args.server }); }
34
- catch (e: any) { die(exitCodeForError(e), e.message); throw e; }
35
- }
36
-
37
- function handle(e: unknown) {
38
- const err = e as { message?: string; code?: string };
39
- die(exitCodeForError(e), `${err.message}${err.code ? ` (${err.code})` : ""}`);
40
- }
41
-
42
- async function readLine(): Promise<string> {
43
- return new Promise((resolve) => {
44
- let buf = "";
45
- process.stdin.setEncoding("utf-8");
46
- const onData = (chunk: Buffer | string) => {
47
- buf += chunk;
48
- const nl = buf.indexOf("\n");
49
- if (nl !== -1) {
50
- process.stdin.removeListener("data", onData);
51
- process.stdin.pause();
52
- resolve(buf.slice(0, nl));
53
- }
54
- };
55
- process.stdin.resume();
56
- process.stdin.on("data", onData);
57
- });
58
- }
59
-
60
- async function rmSub(argv: string[]) {
61
- const args = parseArgs(argv, { flags: COMMON_FLAGS });
62
- const filename = args.positional[0];
63
- if (!filename) die(2, "filename required");
64
- if (!args.yes && !process.stdin.isTTY) die(2, "destructive: pass --yes for non-TTY");
65
- if (!args.yes) {
66
- process.stdout.write(`${args.permanent ? "PERMANENTLY delete" : "Soft-delete"} ${filename}? [y/N] `);
67
- const ans = await readLine();
68
- if (!/^y(es)?$/i.test(ans.trim())) { out("(canceled)"); return; }
69
- }
70
- const server = await getServer(args);
71
- const path = args.permanent
72
- ? `/api/history/${encodeURIComponent(filename)}/permanent`
73
- : `/api/history/${encodeURIComponent(filename)}`;
74
- const resp = await request(server.base, path, { method: "DELETE" }).catch(handle);
75
- if (args.json) { json(resp); return; }
76
- out(color.green(args.permanent ? "✓ permanently deleted" : "✓ moved to trash"));
77
- if (resp?.trashId) out(color.dim(` trashId: ${resp.trashId}`));
78
- }
79
-
80
- async function restoreSub(argv: string[]) {
81
- const args = parseArgs(argv, { flags: COMMON_FLAGS });
82
- const filename = args.positional[0];
83
- if (!filename) die(2, "filename required");
84
- const trashId = args["trash-id"];
85
- if (!trashId) die(2, "--trash-id required (returned by `history rm <filename>`)");
86
- const server = await getServer(args);
87
- const resp = await request(server.base, `/api/history/${encodeURIComponent(filename)}/restore`, {
88
- method: "POST",
89
- body: { trashId },
90
- }).catch(handle);
91
- if (args.json) { json(resp); return; }
92
- out(color.green("✓ restored"));
93
- }
94
-
95
- async function favoriteSub(argv: string[]) {
96
- const args = parseArgs(argv, { flags: COMMON_FLAGS });
97
- const filename = args.positional[0];
98
- if (!filename) die(2, "filename required");
99
- const server = await getServer(args);
100
- const browserId = getCliBrowserId();
101
- const resp: any = await request(server.base, "/api/history/favorite", {
102
- method: "POST",
103
- body: { filename },
104
- headers: { "X-Ima2-Browser-Id": browserId },
105
- }).catch(handle);
106
- if (args.json) { json(resp); return; }
107
- out(color.green(resp.isFavorite ? "✓ favorited" : "✓ unfavorited"));
108
- }
109
-
110
- async function importSub(argv: string[]) {
111
- const args = parseArgs(argv, { flags: COMMON_FLAGS });
112
- const filepath = args.positional[0];
113
- if (!filepath) die(2, "filename required");
114
- const buf = await readFile(filepath);
115
- const ext = extname(filepath).toLowerCase();
116
- const mime =
117
- ext === ".jpg" || ext === ".jpeg" ? "image/jpeg" :
118
- ext === ".webp" ? "image/webp" : "image/png";
119
- const server = await getServer(args);
120
- const resp: any = await request(server.base, "/api/history/import-local", {
121
- method: "POST",
122
- body: buf,
123
- raw: true,
124
- headers: {
125
- "Content-Type": mime,
126
- "X-Ima2-Original-Filename": basename(filepath),
127
- },
128
- }).catch(handle);
129
- if (args.json) { json(resp); return; }
130
- out(color.green("✓ imported as ") + (resp?.item?.filename || "(unknown)"));
131
- }
132
-
133
- const SUB: Record<string, (argv: any[]) => Promise<void>> = {
134
- rm: rmSub,
135
- restore: restoreSub,
136
- favorite: favoriteSub,
137
- import: importSub,
138
- };
139
-
140
- export default async function historyCmd(argv: string[]) {
141
- const sub = argv[0];
142
- if (!sub || sub === "--help" || sub === "-h") { out(HELP); return; }
143
- const handler = SUB[sub];
144
- if (!handler) die(2, `unknown subcommand: ${sub}\n${HELP}`);
145
- return handler(argv.slice(1));
146
- }
@@ -1,64 +0,0 @@
1
- import { parseArgs } from "../lib/args.js";
2
- import { resolveServer, request } from "../lib/client.js";
3
- import { out, die, color, json, table, exitCodeForError } from "../lib/output.js";
4
-
5
- import { errInfo } from "../../lib/errInfo.js";
6
- const SPEC = {
7
- flags: {
8
- count: { short: "n", type: "string", default: "20" },
9
- json: { type: "boolean" },
10
- session: { type: "string" },
11
- favorites: { type: "boolean" },
12
- server: { type: "string" },
13
- help: { short: "h", type: "boolean" },
14
- },
15
- };
16
-
17
- export default async function lsCmd(argv: string[]) {
18
- const args = parseArgs(argv, SPEC);
19
- if (args.help) {
20
- out("ima2 ls [-n count] [--session <id>] [--favorites] [--json]");
21
- return;
22
- }
23
-
24
- let server;
25
- try { server = await resolveServer({ serverFlag: args.server }); }
26
- catch (e) {
27
- const err = errInfo(e); die(exitCodeForError(e), err.message); }
28
-
29
- const limit = parseInt(String(args.count)) || 20;
30
- const qs = new URLSearchParams();
31
- if (args.session) qs.set("sessionId", String(args.session));
32
- if (args.favorites) qs.set("favoritesOnly", "1");
33
- qs.set("limit", String(limit));
34
- const path = `/api/history?${qs.toString()}`;
35
- let resp;
36
- try { resp = await request(server.base, path); }
37
- catch (e) {
38
- const err = errInfo(e); die(exitCodeForError(e), err.message); }
39
-
40
- let items: Record<string, unknown>[] = (resp.items || resp.history || []);
41
- if (args.favorites) items = items.filter((it: Record<string, unknown>) => it.isFavorite === true);
42
- items = items.slice(0, limit);
43
-
44
- if (args.json) { json({ items }); return; }
45
-
46
- if (items.length === 0) {
47
- out(color.dim("(no history)"));
48
- return;
49
- }
50
- table(items, [
51
- { key: "filename", label: "FILENAME" },
52
- { key: "quality", label: "Q" },
53
- { key: "size", label: "SIZE" },
54
- { key: "createdAt", label: "WHEN", format: (v: unknown) => {
55
- if (!v) return "";
56
- const d = new Date(v as string);
57
- return d.toISOString().replace("T", " ").slice(0, 19);
58
- } },
59
- { key: "prompt", label: "PROMPT", format: (v: unknown) => {
60
- const s = String(v || "").replace(/\s+/g, " ");
61
- return s.length > 48 ? s.slice(0, 45) + "…" : s;
62
- } },
63
- ]);
64
- }
@@ -1,39 +0,0 @@
1
- import { parseArgs } from "../lib/args.js";
2
- import { resolveServer, request } from "../lib/client.js";
3
- import { fileToDataUri } from "../lib/files.js";
4
- import { out, die, json, exitCodeForError } from "../lib/output.js";
5
-
6
- const SPEC = {
7
- flags: {
8
- json: { type: "boolean" },
9
- server: { type: "string" },
10
- help: { short: "h", type: "boolean" },
11
- },
12
- };
13
-
14
- const HELP = `
15
- ima2 metadata <imagefile> [--json]
16
-
17
- Read embedded metadata from any local image file.
18
- POSTs { dataUrl } to /api/metadata/read.
19
- `;
20
-
21
- export default async function metadataCmd(argv: string[]) {
22
- const args = parseArgs(argv, SPEC);
23
- if (args.help) { out(HELP); return; }
24
- const file = args.positional[0];
25
- if (!file) die(2, "image file required");
26
- const dataUrl = await fileToDataUri(file);
27
- let server;
28
- try { server = await resolveServer({ serverFlag: args.server }); }
29
- catch (e: any) { die(exitCodeForError(e), e.message); throw e; }
30
- const resp = await request(server.base, "/api/metadata/read", {
31
- method: "POST",
32
- body: { dataUrl },
33
- }).catch((e: unknown) => {
34
- const err = e as { message?: string; code?: string };
35
- die(exitCodeForError(e), `${err.message}${err.code ? ` (${err.code})` : ""}`);
36
- });
37
- if (args.json) { json(resp); }
38
- else out(JSON.stringify(resp, null, 2));
39
- }