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,192 +0,0 @@
1
- import { config } from "../../config.js";
2
- import { parseArgs } from "../lib/args.js";
3
- import { resolveServer, request } from "../lib/client.js";
4
- import {
5
- buildEffectiveConfig,
6
- deleteNestedKey,
7
- displayPath,
8
- envOverrideForKey,
9
- getNestedKey,
10
- loadFileCfg,
11
- restartNotice,
12
- saveFileCfg,
13
- setNestedKey,
14
- CONFIG_FILE,
15
- } from "../lib/config-store.js";
16
- import { color, die, dieWithError, json, out } from "../lib/output.js";
17
-
18
- const MODEL_KEYS = ["imageModels.default", "apiProvider.defaultImageModel"] as const;
19
- const REASONING_KEYS = ["imageModels.reasoningEffort", "apiProvider.defaultReasoningEffort"] as const;
20
-
21
- const HELP = `
22
- ima2 defaults [subcommand] [options]
23
-
24
- Inspect or change persistent model/reasoning defaults.
25
-
26
- Subcommands:
27
- ls Show effective defaults
28
- set model <model> Persist default model for GPT OAuth and API paths
29
- set reasoning <effort> Persist default reasoning effort for GPT OAuth and API paths
30
- reset model Remove persisted model defaults
31
- reset reasoning Remove persisted reasoning defaults
32
-
33
- Options:
34
- --json Print JSON
35
- --local Do not query running server
36
- --server <url> Query a specific running server for ls/default output
37
- `;
38
-
39
- const FLAGS = {
40
- json: { type: "boolean" },
41
- local: { type: "boolean" },
42
- server: { type: "string" },
43
- help: { short: "h", type: "boolean" },
44
- };
45
-
46
- function localDefaults() {
47
- const effective = buildEffectiveConfig();
48
- return {
49
- ok: true,
50
- source: "local",
51
- server: null,
52
- defaults: {
53
- oauth: {
54
- model: getNestedKey(effective, "imageModels.default"),
55
- reasoningEffort: getNestedKey(effective, "imageModels.reasoningEffort"),
56
- },
57
- api: {
58
- model: getNestedKey(effective, "apiProvider.defaultImageModel"),
59
- reasoningEffort: getNestedKey(effective, "apiProvider.defaultReasoningEffort"),
60
- size: getNestedKey(effective, "apiProvider.defaultSize"),
61
- webSearchEnabled: getNestedKey(effective, "apiProvider.allowWebSearch"),
62
- },
63
- },
64
- };
65
- }
66
-
67
- async function readDefaults(args: ReturnType<typeof parseArgs>) {
68
- if (args.local) return localDefaults();
69
- try {
70
- const server = await resolveServer({ serverFlag: args.server });
71
- const capabilities = await request(server.base, "/api/capabilities", { timeoutMs: 5000 });
72
- return {
73
- ok: true,
74
- source: "server",
75
- server: server.base,
76
- defaults: capabilities.defaults,
77
- };
78
- } catch (error) {
79
- if (args.server) throw error;
80
- return localDefaults();
81
- }
82
- }
83
-
84
- function printDefaults(payload: any): void {
85
- out(`ima2 defaults (${payload.source})`);
86
- out(`server: ${payload.server || "none"}`);
87
- out("");
88
- out(`oauth model: ${payload.defaults?.oauth?.model}`);
89
- out(`oauth reasoning: ${payload.defaults?.oauth?.reasoningEffort}`);
90
- out(`api model: ${payload.defaults?.api?.model}`);
91
- out(`api reasoning: ${payload.defaults?.api?.reasoningEffort}`);
92
- if (payload.defaults?.api?.size) out(`api size: ${payload.defaults.api.size}`);
93
- if (payload.defaults?.api?.webSearchEnabled !== undefined) {
94
- out(`api web search: ${payload.defaults.api.webSearchEnabled ? "enabled" : "disabled"}`);
95
- }
96
- }
97
-
98
- function validateModel(value: string): void {
99
- if (!config.imageModels.valid.has(value)) {
100
- die(2, `model must be one of: ${Array.from(config.imageModels.valid).join(", ")}`);
101
- }
102
- }
103
-
104
- function validateReasoning(value: string): void {
105
- if (!config.imageModels.validReasoningEfforts.has(value)) {
106
- die(2, `reasoning must be one of: ${Array.from(config.imageModels.validReasoningEfforts).join(", ")}`);
107
- }
108
- }
109
-
110
- function warnOverrides(keys: readonly string[]): void {
111
- for (const key of keys) {
112
- const override = envOverrideForKey(key);
113
- if (!override) continue;
114
- out(color.yellow(`warning: env ${override.envVar}=${override.value} is currently overriding ${key}.`));
115
- }
116
- }
117
-
118
- function setDefaults(keys: readonly string[], value: string): void {
119
- const fileCfg = loadFileCfg();
120
- for (const key of keys) setNestedKey(fileCfg, key, value);
121
- saveFileCfg(fileCfg);
122
- warnOverrides(keys);
123
- out(color.green("✓ ") + `wrote ${keys.join(", ")}=${JSON.stringify(value)} to ${displayPath(CONFIG_FILE)}`);
124
- out(color.dim(restartNotice()));
125
- }
126
-
127
- function resetDefaults(keys: readonly string[]): void {
128
- const fileCfg = loadFileCfg();
129
- let changed = false;
130
- for (const key of keys) changed = deleteNestedKey(fileCfg, key) || changed;
131
- if (!changed) {
132
- out(color.dim(`(no persisted defaults found for ${keys.join(", ")})`));
133
- return;
134
- }
135
- saveFileCfg(fileCfg);
136
- out(color.green("✓ ") + `removed ${keys.join(", ")} from ${displayPath(CONFIG_FILE)}`);
137
- out(color.dim(restartNotice()));
138
- }
139
-
140
- async function listSub(argv: string[]): Promise<void> {
141
- const args = parseArgs(argv, { flags: FLAGS });
142
- try {
143
- const payload = await readDefaults(args);
144
- if (args.json) json(payload);
145
- else printDefaults(payload);
146
- } catch (error) {
147
- dieWithError(error);
148
- }
149
- }
150
-
151
- async function setSub(argv: string[]): Promise<void> {
152
- const args = parseArgs(argv, { flags: FLAGS });
153
- const [target, value] = args.positional;
154
- if (!target || !value) die(2, "usage: defaults set <model|reasoning> <value>");
155
- if (target === "model") {
156
- validateModel(value);
157
- setDefaults(MODEL_KEYS, value);
158
- return;
159
- }
160
- if (target === "reasoning") {
161
- validateReasoning(value);
162
- setDefaults(REASONING_KEYS, value);
163
- return;
164
- }
165
- die(2, "target must be one of: model, reasoning");
166
- }
167
-
168
- async function resetSub(argv: string[]): Promise<void> {
169
- const args = parseArgs(argv, { flags: FLAGS });
170
- const target = args.positional[0];
171
- if (target === "model") {
172
- resetDefaults(MODEL_KEYS);
173
- return;
174
- }
175
- if (target === "reasoning") {
176
- resetDefaults(REASONING_KEYS);
177
- return;
178
- }
179
- die(2, "usage: defaults reset <model|reasoning>");
180
- }
181
-
182
- export default async function defaultsCmd(argv: string[]) {
183
- const sub = argv[0];
184
- if (sub === "--help" || sub === "-h") {
185
- out(HELP);
186
- return;
187
- }
188
- if (!sub || sub === "ls" || sub.startsWith("-")) return listSub(sub === "ls" ? argv.slice(1) : argv);
189
- if (sub === "set") return setSub(argv.slice(1));
190
- if (sub === "reset") return resetSub(argv.slice(1));
191
- die(2, `unknown subcommand: ${sub}\n${HELP}`);
192
- }
@@ -1,202 +0,0 @@
1
- import { createRequire } from "module";
2
- import { existsSync, readFileSync } from "fs";
3
- import { dirname, join } from "path";
4
- import { fileURLToPath } from "url";
5
- import { buildHardeningDoctorLines } from "../lib/doctor-checks.js";
6
- import { buildStorageDoctorLines } from "../lib/storage-doctor.js";
7
- import { detectCodexAuth } from "../../lib/codexDetect.js";
8
- import { runImageDoctorProbe } from "../../lib/responsesDoctor.js";
9
- import { config as runtimeConfig } from "../../config.js";
10
-
11
- const __dirname = dirname(fileURLToPath(import.meta.url));
12
- const ROOT = join(__dirname, "../..");
13
- const requireFromRoot = createRequire(join(ROOT, "package.json"));
14
- const CONFIG_FILE = runtimeConfig.storage.configFile;
15
- const LEGACY_CONFIG_FILE = join(ROOT, ".ima2", "config.json");
16
-
17
- let pkg = { version: "?", name: "ima2-gen" };
18
- try {
19
- pkg = JSON.parse(readFileSync(join(ROOT, "package.json"), "utf-8"));
20
- } catch {}
21
-
22
- function loadConfig() {
23
- if (existsSync(CONFIG_FILE)) {
24
- return JSON.parse(readFileSync(CONFIG_FILE, "utf-8"));
25
- }
26
- if (existsSync(LEGACY_CONFIG_FILE)) {
27
- try { return JSON.parse(readFileSync(LEGACY_CONFIG_FILE, "utf-8")); } catch {}
28
- }
29
- return {};
30
- }
31
-
32
- function missingRuntimeDeps() {
33
- const deps = ["express", "better-sqlite3", "openai", "openai-oauth", "progrok/package.json"];
34
- return deps.filter((dep) => {
35
- try {
36
- requireFromRoot.resolve(dep);
37
- return false;
38
- } catch {
39
- return true;
40
- }
41
- }).map((dep) => dep === "progrok/package.json" ? "progrok" : dep);
42
- }
43
-
44
- function valueAfter(args: string[], name: string) {
45
- const index = args.indexOf(name);
46
- if (index === -1) return null;
47
- return args[index + 1] || null;
48
- }
49
-
50
- function showImageProbeHelp() {
51
- console.log(`
52
- Usage: ima2 doctor image-probe [options]
53
-
54
- Runs live, sanitized Responses probes for EMPTY_RESPONSE diagnosis.
55
- The output never includes prompt text, auth tokens, URLs with credentials, or base64 image data.
56
-
57
- Options:
58
- --json Emit machine-readable JSON
59
- --matrix Add current-payload web_search/tool_choice probes
60
- --provider <api|oauth> Override configured provider
61
- --model <model> Override image-capable Responses model
62
- --size <size> Default: 1024x1024
63
- --quality <quality> Default: low
64
- --moderation <value> Default: low
65
- --prompt <text> Override built-in cat prompt
66
- --oauth-url <url> Override GPT OAuth proxy URL
67
- --timeout-ms <ms> Per-probe timeout
68
- `);
69
- }
70
-
71
- async function imageProbe(args: string[]) {
72
- if (args.includes("-h") || args.includes("--help")) {
73
- showImageProbeHelp();
74
- return;
75
- }
76
- const fileConfig = loadConfig();
77
- const result = await runImageDoctorProbe({
78
- provider: valueAfter(args, "--provider") || fileConfig.provider || "oauth",
79
- apiKey: typeof fileConfig.apiKey === "string" ? fileConfig.apiKey : undefined,
80
- oauthUrl: valueAfter(args, "--oauth-url") || undefined,
81
- model: valueAfter(args, "--model") || runtimeConfig.imageModels?.default || "gpt-5.4-mini",
82
- size: valueAfter(args, "--size") || "1024x1024",
83
- quality: valueAfter(args, "--quality") || "low",
84
- moderation: valueAfter(args, "--moderation") || "low",
85
- prompt: valueAfter(args, "--prompt") || undefined,
86
- matrix: args.includes("--matrix"),
87
- timeoutMs: Number(valueAfter(args, "--timeout-ms")) || undefined,
88
- ctx: { config: runtimeConfig },
89
- });
90
- if (args.includes("--json")) {
91
- console.log(JSON.stringify(result, null, 2));
92
- process.exit(result.summary.ok ? 0 : 1);
93
- }
94
- console.log(`\n ${pkg.name} v${pkg.version} — Image Probe\n`);
95
- console.log(` Provider: ${result.provider}`);
96
- console.log(` Model: ${result.model}`);
97
- console.log(` Prompt: ${result.promptId} (${result.promptChars} chars, redacted)`);
98
- for (const probe of result.probes) {
99
- const mark = probe.ok ? "✓" : "✗";
100
- const reason = probe.diagnosticReason ? ` — ${probe.diagnosticReason}` : "";
101
- console.log(` ${mark} ${probe.id}${reason}`);
102
- console.log(
103
- ` status=${probe.response.httpStatus ?? "n/a"} events=${probe.response.eventCount} images=${probe.response.imageResultCount} textChars=${probe.response.textOutputChars}`,
104
- );
105
- }
106
- console.log(`\n ${result.summary.passed} passed, ${result.summary.failed} failed\n`);
107
- process.exit(result.summary.ok ? 0 : 1);
108
- }
109
-
110
- async function standardDoctor() {
111
- console.log(`\n ${pkg.name} v${pkg.version} — Doctor\n`);
112
-
113
- let ok = 0;
114
- let fail = 0;
115
-
116
- const nodeVersion = process.version;
117
- const nodeMajor = parseInt(nodeVersion.slice(1).split(".")[0]);
118
- if (nodeMajor >= 20) {
119
- console.log(` ✓ Node.js ${nodeVersion} (>= 20)`);
120
- ok++;
121
- } else {
122
- console.log(` ✗ Node.js ${nodeVersion} (requires >= 20)`);
123
- fail++;
124
- }
125
-
126
- if (existsSync(join(ROOT, "package.json"))) {
127
- console.log(" ✓ package.json found");
128
- ok++;
129
- } else {
130
- console.log(" ✗ package.json missing");
131
- fail++;
132
- }
133
-
134
- const missingDeps = missingRuntimeDeps();
135
- if (missingDeps.length === 0) {
136
- console.log(" ✓ runtime dependencies resolvable");
137
- ok++;
138
- } else {
139
- console.log(` ✗ missing runtime dependencies: ${missingDeps.join(", ")}`);
140
- fail++;
141
- }
142
-
143
- if (existsSync(join(ROOT, ".env"))) {
144
- console.log(" ✓ .env file exists");
145
- ok++;
146
- } else {
147
- console.log(" ⚠ .env file not found (optional — copy from .env.example)");
148
- }
149
-
150
- const fileConfig = loadConfig();
151
- if (fileConfig.provider) {
152
- console.log(` ✓ Configured: ${fileConfig.provider}`);
153
- ok++;
154
- } else {
155
- console.log(" ⚠ Not configured — run 'ima2 setup'");
156
- }
157
-
158
- const advPath = runtimeConfig.storage.advertiseFile;
159
- const adv = existsSync(advPath) ? JSON.parse(readFileSync(advPath, "utf-8")) : null;
160
- console.log(` ℹ Preferred backend port: ${runtimeConfig.server.port}`);
161
- if (adv?.backend || adv?.port) {
162
- console.log(` ℹ Backend actual URL: ${adv?.backend?.url || adv?.url || `http://localhost:${adv.port}`}`);
163
- if (adv?.oauth) console.log(` ℹ GPT OAuth actual URL: ${adv.oauth.url} (${adv.oauth.status || "unknown"})`);
164
- }
165
-
166
- const hardeningLines = await buildHardeningDoctorLines({
167
- root: ROOT,
168
- configFile: CONFIG_FILE,
169
- fileConfig,
170
- });
171
- for (const line of hardeningLines) {
172
- const prefix =
173
- line.kind === "pass" ? "✓"
174
- : line.kind === "fail" ? "✗"
175
- : line.kind === "warn" ? "⚠"
176
- : "ℹ";
177
- console.log(` ${prefix} ${line.text}`);
178
- if (line.kind === "pass") ok++;
179
- if (line.kind === "fail") fail++;
180
- }
181
-
182
- const storageLines = await buildStorageDoctorLines({
183
- rootDir: ROOT,
184
- config: runtimeConfig,
185
- });
186
- console.log("");
187
- for (const line of storageLines) console.log(line);
188
-
189
- const auth = detectCodexAuth();
190
- if (auth.platform === "win32") console.log(" ℹ Windows GPT OAuth note: use WSL2 for Codex login.");
191
-
192
- console.log(`\n ${ok} passed, ${fail} failed\n`);
193
- process.exit(fail > 0 ? 1 : 0);
194
- }
195
-
196
- export async function doctor(args: string[] = []) {
197
- if (args[0] === "image-probe") {
198
- await imageProbe(args.slice(1));
199
- return;
200
- }
201
- await standardDoctor();
202
- }
@@ -1,150 +0,0 @@
1
- import { parseArgs } from "../lib/args.js";
2
- import { resolveServer, request } from "../lib/client.js";
3
- import { fileToDataUri, dataUriToFile, defaultOutName } 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
- prompt: { short: "p", type: "string" },
17
- quality: { short: "q", type: "string", default: "low" },
18
- size: { short: "s", type: "string", default: "1024x1024" },
19
- out: { short: "o", type: "string" },
20
- json: { type: "boolean" },
21
- timeout: { type: "string", default: "180" },
22
- server: { type: "string" },
23
- model: { type: "string" },
24
- provider: { type: "string" },
25
- mode: { type: "string", default: "auto" },
26
- moderation: { type: "string", default: "low" },
27
- session: { type: "string" },
28
- "reasoning-effort": { type: "string" },
29
- "web-search": { type: "boolean" },
30
- "no-web-search": { type: "boolean" },
31
- help: { short: "h", type: "boolean" },
32
- },
33
- };
34
-
35
- const HELP = `
36
- ima2 edit <file> --prompt "<text>" [options]
37
-
38
- Edit an existing image (inpainting-style).
39
-
40
- Options:
41
- -p, --prompt <text> Edit instruction (required)
42
- -q, --quality <low|medium|high>
43
- -s, --size <WxH>
44
- -o, --out <file>
45
- --json
46
- --model <gpt-5.5|gpt-5.4|gpt-5.4-mini|grok-imagine-image|grok-imagine-image-quality>
47
- --provider <auto|oauth|api|grok> Provider (oauth = GPT OAuth; grok = xAI Grok)
48
- --mode <auto|direct> Prompt handling mode. Default: auto
49
- --moderation <auto|low> Default: low
50
- --session <id> Apply session style sheet if enabled
51
- --reasoning-effort <none|low|medium|high|xhigh>
52
- --web-search / --no-web-search Override default web-search toggle
53
- `;
54
-
55
- export default async function editCmd(argv: string[]) {
56
- const args = parseArgs(argv, SPEC);
57
- if (args.help) { out(HELP); return; }
58
- const input = args.positional[0];
59
- if (!input) die(2, "input image path required");
60
- if (!args.prompt) die(2, "--prompt is required");
61
- if (!VALID_MODES.has(String(args.mode))) die(2, "--mode must be one of: auto, direct");
62
- if (!VALID_MODERATION.has(String(args.moderation))) die(2, "--moderation must be one of: auto, low");
63
- if (args.provider && !VALID_PROVIDERS.has(String(args.provider))) {
64
- die(2, "--provider must be one of: auto, oauth, api, grok");
65
- }
66
- if (args.model && !KNOWN_IMAGE_MODELS.has(String(args.model))) {
67
- 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");
68
- }
69
- const VALID_REASONING = new Set(["none", "low", "medium", "high", "xhigh"]);
70
- if (args["reasoning-effort"] && !VALID_REASONING.has(String(args["reasoning-effort"]))) {
71
- die(2, "--reasoning-effort must be one of: none, low, medium, high, xhigh");
72
- }
73
- if (args["web-search"] && args["no-web-search"]) {
74
- die(2, "--web-search and --no-web-search are mutually exclusive");
75
- }
76
-
77
- let server;
78
- try { server = await resolveServer({ serverFlag: args.server }); }
79
- catch (e) {
80
- const err = errInfo(e);
81
- if (args.json) json({ ok: false, error: err.message, code: err.code, status: err.status });
82
- dieWithError(e);
83
- }
84
-
85
- const imageDataUri = await fileToDataUri(input);
86
- const imageB64 = imageDataUri.split(",")[1];
87
-
88
- const timeoutMs = (parseInt(String(args.timeout)) || 180) * 1000;
89
- const explicitOut = args.out ? String(args.out) : null;
90
- const requestId = createCliRequestId("req_cli_edit");
91
-
92
- let resp;
93
- try {
94
- const editBody: any = {
95
- prompt: args.prompt,
96
- image: imageB64,
97
- quality: args.quality,
98
- size: args.size,
99
- model: args.model,
100
- mode: args.mode,
101
- moderation: args.moderation,
102
- sessionId: args.session,
103
- requestId,
104
- };
105
- if (args["reasoning-effort"]) editBody.reasoningEffort = args["reasoning-effort"];
106
- if (args.provider) editBody.provider = args.provider;
107
- if (args["no-web-search"]) editBody.webSearchEnabled = false;
108
- else if (args["web-search"]) editBody.webSearchEnabled = true;
109
- resp = await request(server.base, "/api/edit", {
110
- method: "POST",
111
- body: editBody,
112
- timeoutMs,
113
- headers: { "X-Request-Id": requestId },
114
- });
115
- } catch (e) {
116
- const err = errInfo(e);
117
- const isTimeout = err.name === "TimeoutError" || err.name === "AbortError";
118
- if (isTimeout && explicitOut) {
119
- const result = await recoverGeneratedOutputs(server.base, requestId, {
120
- explicitOut,
121
- expectedCount: 1,
122
- json: Boolean(args.json),
123
- });
124
- if (result.recovered) {
125
- if (args.json) {
126
- json({ ok: true, requestId, recovered: true, path: result.paths[0] });
127
- } else {
128
- out(formatRecoveryHint(result));
129
- out(color.green("✓ ") + result.paths[0] + color.dim(" (recovered)"));
130
- }
131
- return;
132
- }
133
- if (!args.json) out(formatRecoveryHint(result));
134
- }
135
- if (args.json) json({ ok: false, error: err.message, code: err.code, requestId });
136
- dieWithError(e);
137
- }
138
-
139
- const image = resp.image;
140
- if (!image) die(1, "server returned no image");
141
- const target = explicitOut || `${config.storage.generatedDir}/${defaultOutName(0, 1)}`;
142
- await dataUriToFile(image, String(target));
143
-
144
- if (args.json) {
145
- json({ ok: true, path: target, requestId: resp.requestId, elapsed: resp.elapsed });
146
- } else {
147
- out(color.green("✓ ") + target);
148
- if (resp.elapsed) out(color.dim(`elapsed ${resp.elapsed}s`));
149
- }
150
- }