ima2-gen 1.1.21 → 1.1.23

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 (214) hide show
  1. package/README.md +44 -7
  2. package/bin/commands/video.js +14 -0
  3. package/bin/ima2.js +14 -4
  4. package/bin/lib/platform.js +34 -5
  5. package/docs/README.ko.md +43 -2
  6. package/lib/agentQueueWorker.js +6 -0
  7. package/lib/agentRuntime.js +3 -2
  8. package/lib/atomicWrite.js +14 -0
  9. package/lib/grokImageAdapter.js +6 -0
  10. package/lib/grokProxyLauncher.js +5 -3
  11. package/lib/grokVideoAdapter.js +1 -1
  12. package/lib/grokVideoPlannerPrompt.js +10 -0
  13. package/lib/inflight.js +1 -1
  14. package/lib/oauthLauncher.js +5 -0
  15. package/lib/videoFrameExtract.js +3 -3
  16. package/package.json +5 -7
  17. package/routes/capabilities.js +13 -0
  18. package/routes/edit.js +2 -1
  19. package/routes/generate.js +32 -6
  20. package/routes/health.js +4 -3
  21. package/routes/multimode.js +2 -1
  22. package/routes/video.js +35 -3
  23. package/server.js +29 -2
  24. package/skills/ima2/SKILL.md +48 -6
  25. package/ui/dist/.vite/manifest.json +12 -12
  26. package/ui/dist/assets/{AgentWorkspace-B_hq9CLg.js → AgentWorkspace-C21zqdTZ.js} +1 -1
  27. package/ui/dist/assets/{CardNewsWorkspace-wD12J7qk.js → CardNewsWorkspace-BN-ga1lG.js} +1 -1
  28. package/ui/dist/assets/{NodeCanvas-CI_wuPMf.js → NodeCanvas-BbMa4IhI.js} +1 -1
  29. package/ui/dist/assets/{PromptBuilderPanel-CUTujJUV.js → PromptBuilderPanel-DRwBJRDQ.js} +1 -1
  30. package/ui/dist/assets/{PromptImportDialog-CUi66jPK.js → PromptImportDialog-Dp85kHCq.js} +2 -2
  31. package/ui/dist/assets/{PromptImportDiscoverySection-Cm3vrjY4.js → PromptImportDiscoverySection-BE8Q8MLD.js} +1 -1
  32. package/ui/dist/assets/{PromptImportFolderSection-DOtWTD9n.js → PromptImportFolderSection-PtH5x0sc.js} +1 -1
  33. package/ui/dist/assets/{PromptLibraryPanel-BMjQegRa.js → PromptLibraryPanel-FnM9tHI9.js} +2 -2
  34. package/ui/dist/assets/SettingsWorkspace-MARPGyBL.js +1 -0
  35. package/ui/dist/assets/index-BAFI6htx.js +42 -0
  36. package/ui/dist/assets/{index-31uVIdt4.js → index-BSXxr_Bt.js} +1 -1
  37. package/ui/dist/assets/index-DS-ADE7U.css +1 -0
  38. package/ui/dist/index.html +2 -2
  39. package/bin/commands/annotate.ts +0 -119
  40. package/bin/commands/cancel.ts +0 -48
  41. package/bin/commands/canvas-versions.ts +0 -80
  42. package/bin/commands/capabilities.ts +0 -110
  43. package/bin/commands/cardnews.ts +0 -249
  44. package/bin/commands/comfy.ts +0 -54
  45. package/bin/commands/config.ts +0 -186
  46. package/bin/commands/defaults.ts +0 -192
  47. package/bin/commands/doctor.ts +0 -202
  48. package/bin/commands/edit.ts +0 -150
  49. package/bin/commands/gen.ts +0 -214
  50. package/bin/commands/grok.ts +0 -90
  51. package/bin/commands/history.ts +0 -146
  52. package/bin/commands/ls.ts +0 -64
  53. package/bin/commands/metadata.ts +0 -39
  54. package/bin/commands/multimode.ts +0 -196
  55. package/bin/commands/node.ts +0 -166
  56. package/bin/commands/observability.ts +0 -176
  57. package/bin/commands/ping.ts +0 -31
  58. package/bin/commands/prompt-sub/build.ts +0 -101
  59. package/bin/commands/prompt.ts +0 -492
  60. package/bin/commands/ps.ts +0 -81
  61. package/bin/commands/session.ts +0 -266
  62. package/bin/commands/show.ts +0 -72
  63. package/bin/commands/skill.ts +0 -70
  64. package/bin/commands/video.ts +0 -442
  65. package/bin/ima2.ts +0 -430
  66. package/bin/lib/args.ts +0 -92
  67. package/bin/lib/browser-id.ts +0 -16
  68. package/bin/lib/client.ts +0 -122
  69. package/bin/lib/config-store.ts +0 -120
  70. package/bin/lib/destructive-confirm.ts +0 -19
  71. package/bin/lib/doctor-checks.ts +0 -91
  72. package/bin/lib/error-hints.ts +0 -23
  73. package/bin/lib/files.ts +0 -39
  74. package/bin/lib/output.ts +0 -73
  75. package/bin/lib/platform.ts +0 -99
  76. package/bin/lib/recover-output.ts +0 -139
  77. package/bin/lib/sse.ts +0 -73
  78. package/bin/lib/star-prompt.ts +0 -97
  79. package/bin/lib/storage-doctor.ts +0 -39
  80. package/bin/lib/ui-build.ts +0 -85
  81. package/config.ts +0 -354
  82. package/lib/agentCommandParser.ts +0 -69
  83. package/lib/agentGenerationPlanner.ts +0 -273
  84. package/lib/agentQuestionResponder.ts +0 -266
  85. package/lib/agentQueueStore.ts +0 -270
  86. package/lib/agentQueueWorker.ts +0 -89
  87. package/lib/agentRuntime.ts +0 -604
  88. package/lib/agentSettings.ts +0 -72
  89. package/lib/agentStore.ts +0 -422
  90. package/lib/agentStoreRows.ts +0 -136
  91. package/lib/agentTypes.ts +0 -154
  92. package/lib/apiCachePolicy.ts +0 -11
  93. package/lib/assetLifecycle.ts +0 -146
  94. package/lib/canvasVersionStore.ts +0 -223
  95. package/lib/capabilities.ts +0 -126
  96. package/lib/cardNewsGenerator.ts +0 -271
  97. package/lib/cardNewsJobStore.ts +0 -142
  98. package/lib/cardNewsManifestStore.ts +0 -154
  99. package/lib/cardNewsPlanner.ts +0 -236
  100. package/lib/cardNewsPlannerClient.ts +0 -155
  101. package/lib/cardNewsPlannerPrompt.ts +0 -62
  102. package/lib/cardNewsPlannerSchema.ts +0 -321
  103. package/lib/cardNewsRoleTemplateStore.ts +0 -47
  104. package/lib/cardNewsTemplateStore.ts +0 -252
  105. package/lib/codexDetect.ts +0 -71
  106. package/lib/comfyBridge.ts +0 -235
  107. package/lib/composerSnapshot.ts +0 -33
  108. package/lib/configKeys.ts +0 -62
  109. package/lib/db.ts +0 -295
  110. package/lib/errInfo.ts +0 -43
  111. package/lib/errorClassify.ts +0 -100
  112. package/lib/generationCancel.ts +0 -28
  113. package/lib/generationErrors.ts +0 -238
  114. package/lib/grokImageAdapter.ts +0 -513
  115. package/lib/grokMultimodeAdapter.ts +0 -84
  116. package/lib/grokProxyLauncher.ts +0 -153
  117. package/lib/grokRuntime.ts +0 -23
  118. package/lib/grokSizeMapper.ts +0 -71
  119. package/lib/grokVideoAdapter.ts +0 -458
  120. package/lib/grokVideoCanvas.ts +0 -26
  121. package/lib/grokVideoDownload.ts +0 -59
  122. package/lib/grokVideoPlannerPrompt.ts +0 -67
  123. package/lib/historyIndex.ts +0 -51
  124. package/lib/historyList.ts +0 -181
  125. package/lib/imageMetadata.ts +0 -113
  126. package/lib/imageMetadataStore.ts +0 -67
  127. package/lib/imageModels.ts +0 -165
  128. package/lib/inflight.ts +0 -281
  129. package/lib/localImportStore.ts +0 -114
  130. package/lib/logger.ts +0 -161
  131. package/lib/nodeStore.ts +0 -91
  132. package/lib/oauthLauncher.ts +0 -94
  133. package/lib/oauthNormalize.ts +0 -30
  134. package/lib/oauthProxy/errors.ts +0 -128
  135. package/lib/oauthProxy/generators.ts +0 -494
  136. package/lib/oauthProxy/index.ts +0 -28
  137. package/lib/oauthProxy/prompts.ts +0 -123
  138. package/lib/oauthProxy/references.ts +0 -45
  139. package/lib/oauthProxy/runtime.ts +0 -115
  140. package/lib/oauthProxy/streams.ts +0 -232
  141. package/lib/oauthProxy/types.ts +0 -9
  142. package/lib/oauthProxy.ts +0 -3
  143. package/lib/openDirectory.ts +0 -47
  144. package/lib/pngInfo.ts +0 -26
  145. package/lib/promptBuilder/attachments.ts +0 -74
  146. package/lib/promptBuilder/client.ts +0 -130
  147. package/lib/promptBuilder/constants.ts +0 -9
  148. package/lib/promptBuilder/context.ts +0 -36
  149. package/lib/promptBuilder/errors.ts +0 -12
  150. package/lib/promptBuilder/requestSchema.ts +0 -56
  151. package/lib/promptBuilder/responseParser.ts +0 -219
  152. package/lib/promptBuilder/systemPrompt.ts +0 -135
  153. package/lib/promptBuilder/transport.ts +0 -94
  154. package/lib/promptBuilder/types.ts +0 -109
  155. package/lib/promptImport/curatedSources.ts +0 -141
  156. package/lib/promptImport/discoveryRegistry.ts +0 -329
  157. package/lib/promptImport/errors.ts +0 -18
  158. package/lib/promptImport/githubDiscovery.ts +0 -309
  159. package/lib/promptImport/githubFolder.ts +0 -397
  160. package/lib/promptImport/githubSource.ts +0 -257
  161. package/lib/promptImport/gptImageHints.ts +0 -70
  162. package/lib/promptImport/parsePromptCandidates.ts +0 -179
  163. package/lib/promptImport/promptIndex.ts +0 -326
  164. package/lib/promptImport/rankPromptCandidates.ts +0 -65
  165. package/lib/promptImport/types.ts +0 -103
  166. package/lib/promptSafetyPolicy.ts +0 -5
  167. package/lib/providerOptions.ts +0 -56
  168. package/lib/referenceImageCompress.ts +0 -84
  169. package/lib/refs.ts +0 -133
  170. package/lib/requestLogger.ts +0 -49
  171. package/lib/responsesDoctor.ts +0 -456
  172. package/lib/responsesErrors.ts +0 -83
  173. package/lib/responsesFallback.ts +0 -114
  174. package/lib/responsesImageAdapter.ts +0 -466
  175. package/lib/responsesParse.ts +0 -452
  176. package/lib/responsesTools.ts +0 -28
  177. package/lib/runtimeContext.ts +0 -146
  178. package/lib/runtimePorts.ts +0 -105
  179. package/lib/sessionStore.ts +0 -308
  180. package/lib/storageMigration.ts +0 -310
  181. package/lib/styleSheet.ts +0 -139
  182. package/lib/systemTrash.ts +0 -20
  183. package/lib/videoContinuity.ts +0 -180
  184. package/lib/videoFrameExtract.ts +0 -78
  185. package/lib/videoSeriesChain.ts +0 -29
  186. package/lib/visibleTextLanguagePolicy.ts +0 -7
  187. package/routes/agent.ts +0 -308
  188. package/routes/annotations.ts +0 -118
  189. package/routes/canvasVersions.ts +0 -69
  190. package/routes/capabilities.ts +0 -18
  191. package/routes/cardNews.ts +0 -211
  192. package/routes/comfy.ts +0 -43
  193. package/routes/edit.ts +0 -352
  194. package/routes/generate.ts +0 -492
  195. package/routes/grok.ts +0 -24
  196. package/routes/health.ts +0 -123
  197. package/routes/history.ts +0 -221
  198. package/routes/imageImport.ts +0 -37
  199. package/routes/index.ts +0 -52
  200. package/routes/metadata.ts +0 -77
  201. package/routes/multimode.ts +0 -499
  202. package/routes/nodes.ts +0 -578
  203. package/routes/promptBuilder.ts +0 -37
  204. package/routes/promptImport.ts +0 -379
  205. package/routes/prompts.ts +0 -428
  206. package/routes/quota.ts +0 -89
  207. package/routes/sessions.ts +0 -317
  208. package/routes/storage.ts +0 -47
  209. package/routes/video.ts +0 -300
  210. package/routes/videoExtended.ts +0 -284
  211. package/server.ts +0 -293
  212. package/ui/dist/assets/SettingsWorkspace-PiaVnsdA.js +0 -1
  213. package/ui/dist/assets/index-CjgnNtgt.css +0 -1
  214. package/ui/dist/assets/index-Da2s4_-5.js +0 -36
@@ -1,186 +0,0 @@
1
- import { createInterface } from "readline/promises";
2
- import { parseArgs } from "../lib/args.js";
3
- import { confirmDestructiveAction } from "../lib/destructive-confirm.js";
4
- import { out, die, color, json } from "../lib/output.js";
5
- import {
6
- CONFIG_FILE,
7
- KEY_TO_ENV,
8
- WRITABLE_CONFIG_KEYS,
9
- buildEffectiveConfig,
10
- deleteNestedKey,
11
- displayPath,
12
- envOverrideForKey,
13
- getNestedKey,
14
- isAuthConfigKey,
15
- isSensitiveConfigKey,
16
- isWritableConfigKey,
17
- loadFileCfg,
18
- parseConfigValue,
19
- redactValue,
20
- restartNotice,
21
- saveFileCfg,
22
- setNestedKey,
23
- } from "../lib/config-store.js";
24
-
25
- const HELP = `
26
- ima2 config <subcommand> [options]
27
-
28
- Subcommands:
29
- path Print config file path
30
- ls [--effective] [--json] List file layer (or merged effective config with --effective)
31
- get <key> [--json] Get a dotted key from effective config (redacts secrets)
32
- set <key> <value> [-y] Write a key to the file layer
33
- rm <key> [-y] Remove a key from the file layer
34
- keys [--json] List writable keys and environment overrides
35
-
36
- Keys use dot notation, e.g.: imageModels.default, log.level, features.cardNews
37
-
38
- Options:
39
- --effective Use effective (merged env+file+defaults) config for ls/get
40
- --json Output raw JSON
41
- -y, --yes Skip confirmation prompts
42
- `;
43
-
44
- const FLAGS = {
45
- effective: { type: "boolean" },
46
- json: { type: "boolean" },
47
- yes: { short: "y", type: "boolean" },
48
- help: { short: "h", type: "boolean" },
49
- };
50
-
51
- async function pathSub(_argv: string[]) {
52
- out(CONFIG_FILE);
53
- }
54
-
55
- async function lsSub(argv: string[]) {
56
- const args = parseArgs(argv, { flags: FLAGS });
57
- if (args.effective) {
58
- const eff = buildEffectiveConfig();
59
- if (args.json) { json(eff); return; }
60
- out(JSON.stringify(eff, null, 2));
61
- } else {
62
- const fileCfg = loadFileCfg();
63
- if (args.json) { json(fileCfg); return; }
64
- out(JSON.stringify(fileCfg, null, 2));
65
- }
66
- }
67
-
68
- async function getSub(argv: string[]) {
69
- const args = parseArgs(argv, { flags: FLAGS });
70
- const key = args.positional[0];
71
- if (!key) die(2, "key required. Usage: config get <dotted.key>");
72
- const eff = buildEffectiveConfig();
73
- const raw = getNestedKey(eff, key);
74
- const value = redactValue(key, raw);
75
- if (args.json) { json({ key, value }); return; }
76
- if (value === undefined) {
77
- out(color.dim(`(key not found: ${key})`));
78
- } else {
79
- out(typeof value === "object" ? JSON.stringify(value, null, 2) : String(value));
80
- }
81
- }
82
-
83
- async function keysSub(argv: string[]) {
84
- const args = parseArgs(argv, { flags: FLAGS });
85
- const keys = [...WRITABLE_CONFIG_KEYS].sort().map((key) => ({
86
- key,
87
- env: KEY_TO_ENV[key] ?? null,
88
- }));
89
- if (args.json) {
90
- json({ keys });
91
- return;
92
- }
93
- for (const item of keys) {
94
- out(item.env ? `${item.key} (${item.env})` : item.key);
95
- }
96
- }
97
-
98
- async function setSub(argv: string[]) {
99
- const args = parseArgs(argv, { flags: FLAGS });
100
- const [key, rawValue] = args.positional;
101
- if (!key || rawValue === undefined) die(2, "usage: config set <key> <value>");
102
-
103
- if (isAuthConfigKey(key)) {
104
- die(2, `"${key}" is an auth key. Use 'ima2 setup' or 'ima2 login' to change authentication.`);
105
- }
106
- if (!isWritableConfigKey(key)) {
107
- die(2, `unknown config key: "${key}". Run 'ima2 config ls --effective' to see the config structure.`);
108
- }
109
-
110
- const value = parseConfigValue(rawValue);
111
-
112
- // Warn if env var is overriding this key
113
- const override = envOverrideForKey(key);
114
- if (override) {
115
- out(color.yellow(`warning: env ${override.envVar}=${override.value} is currently overriding this value.`));
116
- out(`The file change will only apply after unsetting the env var and restarting the server.`);
117
- }
118
-
119
- // Confirm if writing a sensitive key
120
- if (isSensitiveConfigKey(key) && !args.yes) {
121
- const rl = createInterface({ input: process.stdin, output: process.stdout });
122
- const ans = await rl.question(`warning: "${key}" is a sensitive credential. Write to config file? [y/N] `);
123
- rl.close();
124
- if (!ans.trim().toLowerCase().startsWith("y")) { out("Aborted."); process.exit(0); }
125
- }
126
-
127
- const fileCfg = loadFileCfg();
128
- setNestedKey(fileCfg, key, value);
129
- saveFileCfg(fileCfg);
130
-
131
- out(color.green("✓ ") + `wrote ${key}=${JSON.stringify(value)} to ${displayPath(CONFIG_FILE)}`);
132
- out(color.dim(restartNotice()));
133
- }
134
-
135
- async function rmSub(argv: string[]) {
136
- const args = parseArgs(argv, { flags: FLAGS });
137
- const key = args.positional[0];
138
- if (!key) die(2, "key required. Usage: config rm <key>");
139
-
140
- if (isAuthConfigKey(key)) {
141
- die(2, `"${key}" is an auth key. Use 'ima2 setup' or 'ima2 login' to change authentication.`);
142
- }
143
-
144
- const fileCfg = loadFileCfg();
145
- if (getNestedKey(fileCfg, key) === undefined) {
146
- out(color.dim(`(key not found in file layer: ${key})`));
147
- return;
148
- }
149
-
150
- try {
151
- const confirmed = await confirmDestructiveAction(`Remove config key "${key}"?`, Boolean(args.yes));
152
- if (!confirmed) {
153
- out("Aborted.");
154
- return;
155
- }
156
- } catch (err) {
157
- die(2, err instanceof Error ? err.message : String(err));
158
- }
159
-
160
- const removed = deleteNestedKey(fileCfg, key);
161
- if (!removed) {
162
- out(color.dim(`(key not found in file layer: ${key})`));
163
- return;
164
- }
165
- saveFileCfg(fileCfg);
166
- out(color.green("✓ ") + `removed ${key} from ${displayPath(CONFIG_FILE)}`);
167
- out(color.dim(restartNotice()));
168
- }
169
-
170
- type Sub = (argv: any[]) => Promise<void>;
171
- const SUB: Record<string, Sub> = {
172
- path: pathSub,
173
- ls: lsSub,
174
- get: getSub,
175
- set: setSub,
176
- rm: rmSub,
177
- keys: keysSub,
178
- };
179
-
180
- export default async function configCmd(argv: string[]) {
181
- const sub = argv[0];
182
- if (!sub || sub === "--help" || sub === "-h") { out(HELP); return; }
183
- const handler = SUB[sub];
184
- if (!handler) die(2, `unknown subcommand: ${sub}\n${HELP}`);
185
- return handler(argv.slice(1));
186
- }
@@ -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
- }