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.
- package/README.md +30 -4
- package/bin/ima2.js +14 -4
- package/bin/lib/platform.js +34 -5
- package/docs/README.ko.md +31 -0
- package/lib/agentQueueWorker.js +6 -0
- package/lib/agentRuntime.js +3 -2
- package/lib/atomicWrite.js +14 -0
- package/lib/grokProxyLauncher.js +5 -3
- package/lib/inflight.js +1 -1
- package/lib/oauthLauncher.js +5 -0
- package/lib/videoFrameExtract.js +3 -3
- package/package.json +5 -7
- package/routes/edit.js +2 -1
- package/routes/generate.js +4 -3
- package/routes/health.js +4 -3
- package/routes/multimode.js +2 -1
- package/routes/video.js +4 -2
- package/server.js +29 -2
- package/ui/dist/.vite/manifest.json +12 -12
- package/ui/dist/assets/{AgentWorkspace-B_hq9CLg.js → AgentWorkspace-COxQ5TjU.js} +1 -1
- package/ui/dist/assets/{CardNewsWorkspace-wD12J7qk.js → CardNewsWorkspace-B0OkcuVz.js} +1 -1
- package/ui/dist/assets/{NodeCanvas-CI_wuPMf.js → NodeCanvas-BSsclEBh.js} +1 -1
- package/ui/dist/assets/{PromptBuilderPanel-CUTujJUV.js → PromptBuilderPanel-DpC9A5Rz.js} +1 -1
- package/ui/dist/assets/{PromptImportDialog-CUi66jPK.js → PromptImportDialog-CVwT0rLd.js} +2 -2
- package/ui/dist/assets/{PromptImportDiscoverySection-Cm3vrjY4.js → PromptImportDiscoverySection-BDCkRCRs.js} +1 -1
- package/ui/dist/assets/{PromptImportFolderSection-DOtWTD9n.js → PromptImportFolderSection-QoKbZD83.js} +1 -1
- package/ui/dist/assets/{PromptLibraryPanel-BMjQegRa.js → PromptLibraryPanel-BhFgeKnY.js} +2 -2
- package/ui/dist/assets/SettingsWorkspace-CfjrlH5R.js +1 -0
- package/ui/dist/assets/index-C-mur7pa.css +1 -0
- package/ui/dist/assets/index-CCP5nUOj.js +42 -0
- package/ui/dist/assets/{index-31uVIdt4.js → index-Cxhzi3bs.js} +1 -1
- package/ui/dist/index.html +2 -2
- package/bin/commands/annotate.ts +0 -119
- package/bin/commands/cancel.ts +0 -48
- package/bin/commands/canvas-versions.ts +0 -80
- package/bin/commands/capabilities.ts +0 -110
- package/bin/commands/cardnews.ts +0 -249
- package/bin/commands/comfy.ts +0 -54
- package/bin/commands/config.ts +0 -186
- package/bin/commands/defaults.ts +0 -192
- package/bin/commands/doctor.ts +0 -202
- package/bin/commands/edit.ts +0 -150
- package/bin/commands/gen.ts +0 -214
- package/bin/commands/grok.ts +0 -90
- package/bin/commands/history.ts +0 -146
- package/bin/commands/ls.ts +0 -64
- package/bin/commands/metadata.ts +0 -39
- package/bin/commands/multimode.ts +0 -196
- package/bin/commands/node.ts +0 -166
- package/bin/commands/observability.ts +0 -176
- package/bin/commands/ping.ts +0 -31
- package/bin/commands/prompt-sub/build.ts +0 -101
- package/bin/commands/prompt.ts +0 -492
- package/bin/commands/ps.ts +0 -81
- package/bin/commands/session.ts +0 -266
- package/bin/commands/show.ts +0 -72
- package/bin/commands/skill.ts +0 -70
- package/bin/commands/video.ts +0 -442
- package/bin/ima2.ts +0 -430
- package/bin/lib/args.ts +0 -92
- package/bin/lib/browser-id.ts +0 -16
- package/bin/lib/client.ts +0 -122
- package/bin/lib/config-store.ts +0 -120
- package/bin/lib/destructive-confirm.ts +0 -19
- package/bin/lib/doctor-checks.ts +0 -91
- package/bin/lib/error-hints.ts +0 -23
- package/bin/lib/files.ts +0 -39
- package/bin/lib/output.ts +0 -73
- package/bin/lib/platform.ts +0 -99
- package/bin/lib/recover-output.ts +0 -139
- package/bin/lib/sse.ts +0 -73
- package/bin/lib/star-prompt.ts +0 -97
- package/bin/lib/storage-doctor.ts +0 -39
- package/bin/lib/ui-build.ts +0 -85
- package/config.ts +0 -354
- package/lib/agentCommandParser.ts +0 -69
- package/lib/agentGenerationPlanner.ts +0 -273
- package/lib/agentQuestionResponder.ts +0 -266
- package/lib/agentQueueStore.ts +0 -270
- package/lib/agentQueueWorker.ts +0 -89
- package/lib/agentRuntime.ts +0 -604
- package/lib/agentSettings.ts +0 -72
- package/lib/agentStore.ts +0 -422
- package/lib/agentStoreRows.ts +0 -136
- package/lib/agentTypes.ts +0 -154
- package/lib/apiCachePolicy.ts +0 -11
- package/lib/assetLifecycle.ts +0 -146
- package/lib/canvasVersionStore.ts +0 -223
- package/lib/capabilities.ts +0 -126
- package/lib/cardNewsGenerator.ts +0 -271
- package/lib/cardNewsJobStore.ts +0 -142
- package/lib/cardNewsManifestStore.ts +0 -154
- package/lib/cardNewsPlanner.ts +0 -236
- package/lib/cardNewsPlannerClient.ts +0 -155
- package/lib/cardNewsPlannerPrompt.ts +0 -62
- package/lib/cardNewsPlannerSchema.ts +0 -321
- package/lib/cardNewsRoleTemplateStore.ts +0 -47
- package/lib/cardNewsTemplateStore.ts +0 -252
- package/lib/codexDetect.ts +0 -71
- package/lib/comfyBridge.ts +0 -235
- package/lib/composerSnapshot.ts +0 -33
- package/lib/configKeys.ts +0 -62
- package/lib/db.ts +0 -295
- package/lib/errInfo.ts +0 -43
- package/lib/errorClassify.ts +0 -100
- package/lib/generationCancel.ts +0 -28
- package/lib/generationErrors.ts +0 -238
- package/lib/grokImageAdapter.ts +0 -513
- package/lib/grokMultimodeAdapter.ts +0 -84
- package/lib/grokProxyLauncher.ts +0 -153
- package/lib/grokRuntime.ts +0 -23
- package/lib/grokSizeMapper.ts +0 -71
- package/lib/grokVideoAdapter.ts +0 -458
- package/lib/grokVideoCanvas.ts +0 -26
- package/lib/grokVideoDownload.ts +0 -59
- package/lib/grokVideoPlannerPrompt.ts +0 -67
- package/lib/historyIndex.ts +0 -51
- package/lib/historyList.ts +0 -181
- package/lib/imageMetadata.ts +0 -113
- package/lib/imageMetadataStore.ts +0 -67
- package/lib/imageModels.ts +0 -165
- package/lib/inflight.ts +0 -281
- package/lib/localImportStore.ts +0 -114
- package/lib/logger.ts +0 -161
- package/lib/nodeStore.ts +0 -91
- package/lib/oauthLauncher.ts +0 -94
- package/lib/oauthNormalize.ts +0 -30
- package/lib/oauthProxy/errors.ts +0 -128
- package/lib/oauthProxy/generators.ts +0 -494
- package/lib/oauthProxy/index.ts +0 -28
- package/lib/oauthProxy/prompts.ts +0 -123
- package/lib/oauthProxy/references.ts +0 -45
- package/lib/oauthProxy/runtime.ts +0 -115
- package/lib/oauthProxy/streams.ts +0 -232
- package/lib/oauthProxy/types.ts +0 -9
- package/lib/oauthProxy.ts +0 -3
- package/lib/openDirectory.ts +0 -47
- package/lib/pngInfo.ts +0 -26
- package/lib/promptBuilder/attachments.ts +0 -74
- package/lib/promptBuilder/client.ts +0 -130
- package/lib/promptBuilder/constants.ts +0 -9
- package/lib/promptBuilder/context.ts +0 -36
- package/lib/promptBuilder/errors.ts +0 -12
- package/lib/promptBuilder/requestSchema.ts +0 -56
- package/lib/promptBuilder/responseParser.ts +0 -219
- package/lib/promptBuilder/systemPrompt.ts +0 -135
- package/lib/promptBuilder/transport.ts +0 -94
- package/lib/promptBuilder/types.ts +0 -109
- package/lib/promptImport/curatedSources.ts +0 -141
- package/lib/promptImport/discoveryRegistry.ts +0 -329
- package/lib/promptImport/errors.ts +0 -18
- package/lib/promptImport/githubDiscovery.ts +0 -309
- package/lib/promptImport/githubFolder.ts +0 -397
- package/lib/promptImport/githubSource.ts +0 -257
- package/lib/promptImport/gptImageHints.ts +0 -70
- package/lib/promptImport/parsePromptCandidates.ts +0 -179
- package/lib/promptImport/promptIndex.ts +0 -326
- package/lib/promptImport/rankPromptCandidates.ts +0 -65
- package/lib/promptImport/types.ts +0 -103
- package/lib/promptSafetyPolicy.ts +0 -5
- package/lib/providerOptions.ts +0 -56
- package/lib/referenceImageCompress.ts +0 -84
- package/lib/refs.ts +0 -133
- package/lib/requestLogger.ts +0 -49
- package/lib/responsesDoctor.ts +0 -456
- package/lib/responsesErrors.ts +0 -83
- package/lib/responsesFallback.ts +0 -114
- package/lib/responsesImageAdapter.ts +0 -466
- package/lib/responsesParse.ts +0 -452
- package/lib/responsesTools.ts +0 -28
- package/lib/runtimeContext.ts +0 -146
- package/lib/runtimePorts.ts +0 -105
- package/lib/sessionStore.ts +0 -308
- package/lib/storageMigration.ts +0 -310
- package/lib/styleSheet.ts +0 -139
- package/lib/systemTrash.ts +0 -20
- package/lib/videoContinuity.ts +0 -180
- package/lib/videoFrameExtract.ts +0 -78
- package/lib/videoSeriesChain.ts +0 -29
- package/lib/visibleTextLanguagePolicy.ts +0 -7
- package/routes/agent.ts +0 -308
- package/routes/annotations.ts +0 -118
- package/routes/canvasVersions.ts +0 -69
- package/routes/capabilities.ts +0 -18
- package/routes/cardNews.ts +0 -211
- package/routes/comfy.ts +0 -43
- package/routes/edit.ts +0 -352
- package/routes/generate.ts +0 -492
- package/routes/grok.ts +0 -24
- package/routes/health.ts +0 -123
- package/routes/history.ts +0 -221
- package/routes/imageImport.ts +0 -37
- package/routes/index.ts +0 -52
- package/routes/metadata.ts +0 -77
- package/routes/multimode.ts +0 -499
- package/routes/nodes.ts +0 -578
- package/routes/promptBuilder.ts +0 -37
- package/routes/promptImport.ts +0 -379
- package/routes/prompts.ts +0 -428
- package/routes/quota.ts +0 -89
- package/routes/sessions.ts +0 -317
- package/routes/storage.ts +0 -47
- package/routes/video.ts +0 -300
- package/routes/videoExtended.ts +0 -284
- package/server.ts +0 -293
- package/ui/dist/assets/SettingsWorkspace-PiaVnsdA.js +0 -1
- package/ui/dist/assets/index-CjgnNtgt.css +0 -1
- package/ui/dist/assets/index-Da2s4_-5.js +0 -36
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { readFile } from "fs/promises";
|
|
2
|
-
import { parseArgs, type ParsedArgs } from "../lib/args.js";
|
|
3
|
-
import { resolveServer, request } from "../lib/client.js";
|
|
4
|
-
import { out, die, color, json, exitCodeForError } from "../lib/output.js";
|
|
5
|
-
|
|
6
|
-
const HELP = `
|
|
7
|
-
ima2 canvas-versions <subcommand> [options]
|
|
8
|
-
|
|
9
|
-
Subcommands:
|
|
10
|
-
save <imagefile> [--source <filename>] [--prompt <text>]
|
|
11
|
-
update <filename> <imagefile> [--source <filename>] [--prompt <text>]
|
|
12
|
-
|
|
13
|
-
Notes: server only exposes POST /api/canvas-versions (collection) and
|
|
14
|
-
PUT /api/canvas-versions/:filename. No GET, no DELETE.
|
|
15
|
-
`;
|
|
16
|
-
|
|
17
|
-
const FLAGS = {
|
|
18
|
-
json: { type: "boolean" },
|
|
19
|
-
server: { type: "string" },
|
|
20
|
-
source: { type: "string" },
|
|
21
|
-
prompt: { type: "string" },
|
|
22
|
-
help: { short: "h", type: "boolean" },
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
async function getServer(args: ParsedArgs) {
|
|
26
|
-
try { return await resolveServer({ serverFlag: args.server }); }
|
|
27
|
-
catch (e: any) { die(exitCodeForError(e), e.message); throw e; }
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function buildHeaders(args: ParsedArgs) {
|
|
31
|
-
const h: Record<string, string> = { "Content-Type": "image/png" };
|
|
32
|
-
if (args.source) h["X-Ima2-Canvas-Source-Filename"] = String(args.source);
|
|
33
|
-
if (args.prompt) h["X-Ima2-Canvas-Prompt"] = String(args.prompt);
|
|
34
|
-
return h;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function saveSub(argv: string[]) {
|
|
38
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
39
|
-
const file = args.positional[0];
|
|
40
|
-
if (!file) die(2, "image file required");
|
|
41
|
-
const buf = await readFile(file);
|
|
42
|
-
const server = await getServer(args);
|
|
43
|
-
const resp = await request(server.base, "/api/canvas-versions", {
|
|
44
|
-
method: "POST",
|
|
45
|
-
body: buf,
|
|
46
|
-
raw: true,
|
|
47
|
-
headers: buildHeaders(args),
|
|
48
|
-
}).catch((e: unknown) => { const err = e as { message?: string; code?: string }; die(exitCodeForError(e), `${err.message}${err.code ? ` (${err.code})` : ""}`); });
|
|
49
|
-
if (args.json) { json(resp); return; }
|
|
50
|
-
out(color.green("✓ saved canvas version"));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async function updateSub(argv: string[]) {
|
|
54
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
55
|
-
const [filename, file] = args.positional;
|
|
56
|
-
if (!filename || !file) die(2, "usage: canvas-versions update <filename> <imagefile>");
|
|
57
|
-
const buf = await readFile(file);
|
|
58
|
-
const server = await getServer(args);
|
|
59
|
-
const resp = await request(server.base, `/api/canvas-versions/${encodeURIComponent(filename)}`, {
|
|
60
|
-
method: "PUT",
|
|
61
|
-
body: buf,
|
|
62
|
-
raw: true,
|
|
63
|
-
headers: buildHeaders(args),
|
|
64
|
-
}).catch((e: unknown) => { const err = e as { message?: string; code?: string }; die(exitCodeForError(e), `${err.message}${err.code ? ` (${err.code})` : ""}`); });
|
|
65
|
-
if (args.json) { json(resp); return; }
|
|
66
|
-
out(color.green("✓ updated"));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const SUB: Record<string, (argv: any[]) => Promise<void>> = {
|
|
70
|
-
save: saveSub,
|
|
71
|
-
update: updateSub,
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export default async function canvasVersionsCmd(argv: string[]) {
|
|
75
|
-
const sub = argv[0];
|
|
76
|
-
if (!sub || sub === "--help" || sub === "-h") { out(HELP); return; }
|
|
77
|
-
const handler = SUB[sub];
|
|
78
|
-
if (!handler) die(2, `unknown subcommand: ${sub}\n${HELP}`);
|
|
79
|
-
return handler(argv.slice(1));
|
|
80
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "fs";
|
|
2
|
-
import { dirname, join } from "path";
|
|
3
|
-
import { fileURLToPath } from "url";
|
|
4
|
-
import { config } from "../../config.js";
|
|
5
|
-
import { buildIma2Capabilities } from "../../lib/capabilities.js";
|
|
6
|
-
import { parseArgs } from "../lib/args.js";
|
|
7
|
-
import { resolveServer, request } from "../lib/client.js";
|
|
8
|
-
import { color, dieWithError, json, out } from "../lib/output.js";
|
|
9
|
-
|
|
10
|
-
const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
11
|
-
const PACKAGE_PATH = join(ROOT, "package.json");
|
|
12
|
-
|
|
13
|
-
const HELP = `
|
|
14
|
-
ima2 capabilities [--json] [--server <url>] [--require-server]
|
|
15
|
-
|
|
16
|
-
Print agent-friendly capability metadata.
|
|
17
|
-
|
|
18
|
-
Options:
|
|
19
|
-
--json Print JSON
|
|
20
|
-
--server <url> Query a specific running server
|
|
21
|
-
--require-server Fail instead of falling back to local package metadata
|
|
22
|
-
`;
|
|
23
|
-
|
|
24
|
-
const FLAGS = {
|
|
25
|
-
json: { type: "boolean" },
|
|
26
|
-
server: { type: "string" },
|
|
27
|
-
"require-server": { type: "boolean" },
|
|
28
|
-
help: { short: "h", type: "boolean" },
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
function packageVersion(): string {
|
|
32
|
-
try {
|
|
33
|
-
const pkg = JSON.parse(readFileSync(PACKAGE_PATH, "utf-8")) as { version?: string };
|
|
34
|
-
return pkg.version || "?";
|
|
35
|
-
} catch {
|
|
36
|
-
return "?";
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function localCapabilities() {
|
|
41
|
-
return buildIma2Capabilities({
|
|
42
|
-
appConfig: config,
|
|
43
|
-
packageVersion: packageVersion(),
|
|
44
|
-
source: "local",
|
|
45
|
-
server: null,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async function readCapabilities(args: ReturnType<typeof parseArgs>) {
|
|
50
|
-
try {
|
|
51
|
-
const server = await resolveServer({ serverFlag: args.server });
|
|
52
|
-
return await request(server.base, "/api/capabilities", { timeoutMs: 5000 });
|
|
53
|
-
} catch (error) {
|
|
54
|
-
if (args.server || args["require-server"]) throw error;
|
|
55
|
-
return localCapabilities();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function printText(capabilities: any): void {
|
|
60
|
-
out(`ima2 capabilities (${capabilities.source})`);
|
|
61
|
-
out(`version: ${capabilities.version}`);
|
|
62
|
-
out(`server: ${capabilities.server || "none"}`);
|
|
63
|
-
out("");
|
|
64
|
-
out("defaults:");
|
|
65
|
-
out(` gpt-oauth model: ${capabilities.defaults?.oauth?.model}`);
|
|
66
|
-
out(` gpt-oauth reasoning: ${capabilities.defaults?.oauth?.reasoningEffort}`);
|
|
67
|
-
out(` api model: ${capabilities.defaults?.api?.model}`);
|
|
68
|
-
out(` api reasoning: ${capabilities.defaults?.api?.reasoningEffort}`);
|
|
69
|
-
out(` grok model: ${capabilities.defaults?.grok?.model}`);
|
|
70
|
-
out(` grok planner: ${capabilities.defaults?.grok?.plannerModel}`);
|
|
71
|
-
out("");
|
|
72
|
-
out("valid:");
|
|
73
|
-
out(` models: ${capabilities.valid?.imageModels?.supported?.join(", ")}`);
|
|
74
|
-
if (capabilities.valid?.imageModels?.grokSupported?.length) {
|
|
75
|
-
out(` grok models: ${capabilities.valid.imageModels.grokSupported.join(", ")}`);
|
|
76
|
-
}
|
|
77
|
-
if (capabilities.valid?.videoModels?.supported?.length) {
|
|
78
|
-
out(` video models: ${capabilities.valid.videoModels.supported.join(", ")}`);
|
|
79
|
-
out(` video resolutions: ${capabilities.valid.videoModels.resolutions?.join(", ")}`);
|
|
80
|
-
out(` video aspect ratios: ${capabilities.valid.videoModels.aspectRatios?.join(", ")}`);
|
|
81
|
-
out(` video duration: ${capabilities.valid.videoModels.durationRange?.[0]}-${capabilities.valid.videoModels.durationRange?.[1]}s`);
|
|
82
|
-
}
|
|
83
|
-
out(` reasoning: ${capabilities.valid?.reasoningEfforts?.join(", ")}`);
|
|
84
|
-
out(` quality: ${capabilities.valid?.quality?.join(", ")}`);
|
|
85
|
-
out(` modes: ${capabilities.valid?.modes?.join(", ")}`);
|
|
86
|
-
out(` moderation: ${capabilities.valid?.moderation?.join(", ")}`);
|
|
87
|
-
out(` providers: ${capabilities.valid?.providers?.join(", ")}`);
|
|
88
|
-
out("");
|
|
89
|
-
out(`config keys: ${capabilities.configKeys?.writable?.length ?? 0} writable`);
|
|
90
|
-
out(color.dim("run: ima2 config keys --json"));
|
|
91
|
-
out("");
|
|
92
|
-
out(`limits: refs=${capabilities.limits?.maxRefCount}, images=${capabilities.limits?.maxGeneratedImages}`);
|
|
93
|
-
out(color.dim(`maxParallel: ${capabilities.limits?.maxParallel?.value} (${capabilities.limits?.maxParallel?.note})`));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export default async function capabilitiesCmd(argv: string[]) {
|
|
97
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
98
|
-
if (args.help) {
|
|
99
|
-
out(HELP);
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
try {
|
|
104
|
-
const capabilities = await readCapabilities(args);
|
|
105
|
-
if (args.json) json(capabilities);
|
|
106
|
-
else printText(capabilities);
|
|
107
|
-
} catch (error) {
|
|
108
|
-
dieWithError(error);
|
|
109
|
-
}
|
|
110
|
-
}
|
package/bin/commands/cardnews.ts
DELETED
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import { parseArgs, type ParsedArgs } from "../lib/args.js";
|
|
2
|
-
import { resolveServer, request } from "../lib/client.js";
|
|
3
|
-
import { out, die, color, json, exitCodeForError } from "../lib/output.js";
|
|
4
|
-
import { config as runtimeConfig } from "../../config.js";
|
|
5
|
-
|
|
6
|
-
const HELP = `
|
|
7
|
-
ima2 cardnews <subcommand> [options]
|
|
8
|
-
|
|
9
|
-
Subcommands:
|
|
10
|
-
templates List image-templates + role-templates
|
|
11
|
-
template preview <templateId> Preview an image template
|
|
12
|
-
sets List card news sets
|
|
13
|
-
set show <setId> Show a set
|
|
14
|
-
set manifest <setId> Show a set manifest
|
|
15
|
-
draft [--data <json>] Create a draft
|
|
16
|
-
generate [--data <json>] Run generation
|
|
17
|
-
job create [--data <json>] Create and start a job
|
|
18
|
-
job show <jobId> Show a job
|
|
19
|
-
job retry <jobId> [--cards <id,...>] Retry a job (optionally specific cards)
|
|
20
|
-
card regenerate <cardId> [--data <json>] Regenerate a single card
|
|
21
|
-
export [--data <json>] Export a bundle
|
|
22
|
-
|
|
23
|
-
Note: Card News must be enabled (IMA2_CARD_NEWS=1 or features.cardNews: true in config.json).
|
|
24
|
-
|
|
25
|
-
Options:
|
|
26
|
-
--data <json> JSON body to send (for draft/generate/job create/card regenerate/export)
|
|
27
|
-
--cards <ids> Comma-separated card IDs for job retry
|
|
28
|
-
--json Output raw JSON
|
|
29
|
-
--server <url> Override server URL
|
|
30
|
-
`;
|
|
31
|
-
|
|
32
|
-
const FLAGS = {
|
|
33
|
-
json: { type: "boolean" },
|
|
34
|
-
server: { type: "string" },
|
|
35
|
-
data: { type: "string" },
|
|
36
|
-
cards: { type: "string" },
|
|
37
|
-
help: { short: "h", type: "boolean" },
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
function ensureCardNewsEnabled() {
|
|
41
|
-
if (!runtimeConfig.features?.cardNews) {
|
|
42
|
-
die(2, "Card News feature is disabled. Set IMA2_CARD_NEWS=1 (or features.cardNews: true in config.json) and restart the server.");
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async function getServer(args: ParsedArgs) {
|
|
47
|
-
try { return await resolveServer({ serverFlag: args.server }); }
|
|
48
|
-
catch (e: any) { die(exitCodeForError(e), e.message); throw e; }
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function parseData(raw: unknown): any {
|
|
52
|
-
if (!raw) return {};
|
|
53
|
-
if (typeof raw !== "string") return {};
|
|
54
|
-
try { return JSON.parse(raw); }
|
|
55
|
-
catch { die(2, `--data must be valid JSON`); }
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async function templatesSub(argv: string[]) {
|
|
59
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
60
|
-
if (args.help) { out(HELP); return; }
|
|
61
|
-
ensureCardNewsEnabled();
|
|
62
|
-
const server = await getServer(args);
|
|
63
|
-
const [imgTemplates, roleTemplates] = await Promise.all([
|
|
64
|
-
request(server.base, "/api/cardnews/image-templates")
|
|
65
|
-
.catch((e) => die(exitCodeForError(e), e.message)),
|
|
66
|
-
request(server.base, "/api/cardnews/role-templates")
|
|
67
|
-
.catch((e) => die(exitCodeForError(e), e.message)),
|
|
68
|
-
]);
|
|
69
|
-
if (args.json) { json({ imageTemplates: imgTemplates, roleTemplates }); return; }
|
|
70
|
-
out(color.bold("Image templates:"));
|
|
71
|
-
out(JSON.stringify(imgTemplates, null, 2));
|
|
72
|
-
out(color.bold("Role templates:"));
|
|
73
|
-
out(JSON.stringify(roleTemplates, null, 2));
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async function templatePreviewSub(argv: string[]) {
|
|
77
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
78
|
-
const templateId = args.positional[0];
|
|
79
|
-
if (!templateId) die(2, "templateId required");
|
|
80
|
-
ensureCardNewsEnabled();
|
|
81
|
-
const server = await getServer(args);
|
|
82
|
-
const resp = await request(server.base, `/api/cardnews/image-templates/${encodeURIComponent(templateId)}/preview`)
|
|
83
|
-
.catch((e) => die(exitCodeForError(e), e.message));
|
|
84
|
-
if (args.json) { json(resp); return; }
|
|
85
|
-
out(JSON.stringify(resp, null, 2));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async function setsSub(argv: string[]) {
|
|
89
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
90
|
-
ensureCardNewsEnabled();
|
|
91
|
-
const server = await getServer(args);
|
|
92
|
-
const resp = await request(server.base, "/api/cardnews/sets")
|
|
93
|
-
.catch((e) => die(exitCodeForError(e), e.message));
|
|
94
|
-
if (args.json) { json(resp); return; }
|
|
95
|
-
out(JSON.stringify(resp, null, 2));
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async function setShowSub(argv: string[]) {
|
|
99
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
100
|
-
const setId = args.positional[0];
|
|
101
|
-
if (!setId) die(2, "setId required");
|
|
102
|
-
ensureCardNewsEnabled();
|
|
103
|
-
const server = await getServer(args);
|
|
104
|
-
const resp = await request(server.base, `/api/cardnews/sets/${encodeURIComponent(setId)}`)
|
|
105
|
-
.catch((e) => die(exitCodeForError(e), e.message));
|
|
106
|
-
if (args.json) { json(resp); return; }
|
|
107
|
-
out(JSON.stringify(resp, null, 2));
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
async function setManifestSub(argv: string[]) {
|
|
111
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
112
|
-
const setId = args.positional[0];
|
|
113
|
-
if (!setId) die(2, "setId required");
|
|
114
|
-
ensureCardNewsEnabled();
|
|
115
|
-
const server = await getServer(args);
|
|
116
|
-
const resp = await request(server.base, `/api/cardnews/sets/${encodeURIComponent(setId)}/manifest`)
|
|
117
|
-
.catch((e) => die(exitCodeForError(e), e.message));
|
|
118
|
-
if (args.json) { json(resp); return; }
|
|
119
|
-
out(JSON.stringify(resp, null, 2));
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
async function draftSub(argv: string[]) {
|
|
123
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
124
|
-
ensureCardNewsEnabled();
|
|
125
|
-
const server = await getServer(args);
|
|
126
|
-
const body = parseData(args.data);
|
|
127
|
-
const resp = await request(server.base, "/api/cardnews/draft", { method: "POST", body })
|
|
128
|
-
.catch((e) => die(exitCodeForError(e), e.message));
|
|
129
|
-
if (args.json) { json(resp); return; }
|
|
130
|
-
out(JSON.stringify(resp, null, 2));
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
async function generateSub(argv: string[]) {
|
|
134
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
135
|
-
ensureCardNewsEnabled();
|
|
136
|
-
const server = await getServer(args);
|
|
137
|
-
const body = parseData(args.data);
|
|
138
|
-
const resp = await request(server.base, "/api/cardnews/generate", { method: "POST", body })
|
|
139
|
-
.catch((e) => die(exitCodeForError(e), e.message));
|
|
140
|
-
if (args.json) { json(resp); return; }
|
|
141
|
-
out(JSON.stringify(resp, null, 2));
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
async function jobCreateSub(argv: string[]) {
|
|
145
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
146
|
-
ensureCardNewsEnabled();
|
|
147
|
-
const server = await getServer(args);
|
|
148
|
-
const body = parseData(args.data);
|
|
149
|
-
const resp = await request(server.base, "/api/cardnews/jobs", { method: "POST", body })
|
|
150
|
-
.catch((e) => die(exitCodeForError(e), e.message));
|
|
151
|
-
if (args.json) { json(resp); return; }
|
|
152
|
-
out(JSON.stringify(resp, null, 2));
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
async function jobShowSub(argv: string[]) {
|
|
156
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
157
|
-
const jobId = args.positional[0];
|
|
158
|
-
if (!jobId) die(2, "jobId required");
|
|
159
|
-
ensureCardNewsEnabled();
|
|
160
|
-
const server = await getServer(args);
|
|
161
|
-
const resp = await request(server.base, `/api/cardnews/jobs/${encodeURIComponent(jobId)}`)
|
|
162
|
-
.catch((e) => die(exitCodeForError(e), e.message));
|
|
163
|
-
if (args.json) { json(resp); return; }
|
|
164
|
-
out(JSON.stringify(resp, null, 2));
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async function jobRetrySub(argv: string[]) {
|
|
168
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
169
|
-
const jobId = args.positional[0];
|
|
170
|
-
if (!jobId) die(2, "jobId required");
|
|
171
|
-
ensureCardNewsEnabled();
|
|
172
|
-
const server = await getServer(args);
|
|
173
|
-
const body: any = {};
|
|
174
|
-
if (args.cards) body.cardIds = String(args.cards).split(",").map((s: string) => s.trim()).filter(Boolean);
|
|
175
|
-
const resp = await request(server.base, `/api/cardnews/jobs/${encodeURIComponent(jobId)}/retry`, { method: "POST", body })
|
|
176
|
-
.catch((e) => die(exitCodeForError(e), e.message));
|
|
177
|
-
if (args.json) { json(resp); return; }
|
|
178
|
-
out(color.green("✓ ") + "retry requested");
|
|
179
|
-
if (resp && typeof resp === "object" && Object.keys(resp).length > 0) out(JSON.stringify(resp, null, 2));
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
async function cardRegenerateSub(argv: string[]) {
|
|
183
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
184
|
-
const cardId = args.positional[0];
|
|
185
|
-
if (!cardId) die(2, "cardId required");
|
|
186
|
-
ensureCardNewsEnabled();
|
|
187
|
-
const server = await getServer(args);
|
|
188
|
-
const body = parseData(args.data);
|
|
189
|
-
const resp = await request(server.base, `/api/cardnews/cards/${encodeURIComponent(cardId)}/regenerate`, { method: "POST", body })
|
|
190
|
-
.catch((e) => die(exitCodeForError(e), e.message));
|
|
191
|
-
if (args.json) { json(resp); return; }
|
|
192
|
-
out(color.green("✓ ") + "regeneration started");
|
|
193
|
-
if (resp && typeof resp === "object" && Object.keys(resp).length > 0) out(JSON.stringify(resp, null, 2));
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
async function exportSub(argv: string[]) {
|
|
197
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
198
|
-
ensureCardNewsEnabled();
|
|
199
|
-
const server = await getServer(args);
|
|
200
|
-
const body = parseData(args.data);
|
|
201
|
-
const resp = await request(server.base, "/api/cardnews/export", { method: "POST", body })
|
|
202
|
-
.catch((e) => die(exitCodeForError(e), e.message));
|
|
203
|
-
if (args.json) { json(resp); return; }
|
|
204
|
-
out(color.green("✓ ") + "export requested");
|
|
205
|
-
if (resp && typeof resp === "object" && Object.keys(resp).length > 0) out(JSON.stringify(resp, null, 2));
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
type Sub = (argv: any[]) => Promise<void>;
|
|
209
|
-
|
|
210
|
-
export default async function cardnewsCmd(argv: string[]) {
|
|
211
|
-
const sub = argv[0];
|
|
212
|
-
if (!sub || sub === "--help" || sub === "-h") { out(HELP); return; }
|
|
213
|
-
|
|
214
|
-
if (sub === "template") {
|
|
215
|
-
const s2 = argv[1];
|
|
216
|
-
if (s2 === "preview") return templatePreviewSub(argv.slice(2));
|
|
217
|
-
die(2, `unknown subcommand: template ${s2 || ""}\n${HELP}`);
|
|
218
|
-
}
|
|
219
|
-
if (sub === "set") {
|
|
220
|
-
const s2 = argv[1];
|
|
221
|
-
const SET_SUB: Record<string, Sub> = { show: setShowSub, manifest: setManifestSub };
|
|
222
|
-
const handler = SET_SUB[s2];
|
|
223
|
-
if (!handler) die(2, `unknown subcommand: set ${s2 || ""}\n${HELP}`);
|
|
224
|
-
return handler(argv.slice(2));
|
|
225
|
-
}
|
|
226
|
-
if (sub === "job") {
|
|
227
|
-
const s2 = argv[1];
|
|
228
|
-
const JOB_SUB: Record<string, Sub> = { create: jobCreateSub, show: jobShowSub, retry: jobRetrySub };
|
|
229
|
-
const handler = JOB_SUB[s2];
|
|
230
|
-
if (!handler) die(2, `unknown subcommand: job ${s2 || ""}\n${HELP}`);
|
|
231
|
-
return handler(argv.slice(2));
|
|
232
|
-
}
|
|
233
|
-
if (sub === "card") {
|
|
234
|
-
const s2 = argv[1];
|
|
235
|
-
if (s2 === "regenerate") return cardRegenerateSub(argv.slice(2));
|
|
236
|
-
die(2, `unknown subcommand: card ${s2 || ""}\n${HELP}`);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const FLAT: Record<string, Sub> = {
|
|
240
|
-
templates: templatesSub,
|
|
241
|
-
sets: setsSub,
|
|
242
|
-
draft: draftSub,
|
|
243
|
-
generate: generateSub,
|
|
244
|
-
export: exportSub,
|
|
245
|
-
};
|
|
246
|
-
const handler = FLAT[sub];
|
|
247
|
-
if (!handler) die(2, `unknown subcommand: ${sub}\n${HELP}`);
|
|
248
|
-
return handler(argv.slice(1));
|
|
249
|
-
}
|
package/bin/commands/comfy.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { writeFile, access } from "fs/promises";
|
|
2
|
-
import { parseArgs } from "../lib/args.js";
|
|
3
|
-
import { resolveServer, request } from "../lib/client.js";
|
|
4
|
-
import { out, die, color, json, exitCodeForError } from "../lib/output.js";
|
|
5
|
-
|
|
6
|
-
const HELP = `
|
|
7
|
-
ima2 comfy <subcommand> [options]
|
|
8
|
-
|
|
9
|
-
Subcommands:
|
|
10
|
-
export <filename> [-o <out>] [--force]
|
|
11
|
-
`;
|
|
12
|
-
|
|
13
|
-
const FLAGS = {
|
|
14
|
-
json: { type: "boolean" },
|
|
15
|
-
server: { type: "string" },
|
|
16
|
-
out: { short: "o", type: "string" },
|
|
17
|
-
force: { type: "boolean" },
|
|
18
|
-
help: { short: "h", type: "boolean" },
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
async function exportSub(argv: string[]) {
|
|
22
|
-
const args = parseArgs(argv, { flags: FLAGS });
|
|
23
|
-
const filename = args.positional[0];
|
|
24
|
-
if (!filename) die(2, "filename required");
|
|
25
|
-
let server;
|
|
26
|
-
try { server = await resolveServer({ serverFlag: args.server }); }
|
|
27
|
-
catch (e: any) { die(exitCodeForError(e), e.message); throw e; }
|
|
28
|
-
const resp: any = await request(server.base, "/api/comfy/export-image", {
|
|
29
|
-
method: "POST",
|
|
30
|
-
body: { filename },
|
|
31
|
-
}).catch((e: unknown) => { const err = e as { message?: string; code?: string }; die(exitCodeForError(e), `${err.message}${err.code ? ` (${err.code})` : ""}`); });
|
|
32
|
-
const target = String(args.out || `${filename}.workflow.json`);
|
|
33
|
-
if (!args.force) {
|
|
34
|
-
try {
|
|
35
|
-
await access(target);
|
|
36
|
-
die(2, `${target} already exists. Pass --force to overwrite.`);
|
|
37
|
-
} catch { /* file does not exist — proceed */ }
|
|
38
|
-
}
|
|
39
|
-
await writeFile(target, JSON.stringify(resp, null, 2));
|
|
40
|
-
if (args.json) { json({ path: target }); return; }
|
|
41
|
-
out(color.green("✓ ") + target);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const SUB: Record<string, (argv: any[]) => Promise<void>> = {
|
|
45
|
-
export: exportSub,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export default async function comfyCmd(argv: string[]) {
|
|
49
|
-
const sub = argv[0];
|
|
50
|
-
if (!sub || sub === "--help" || sub === "-h") { out(HELP); return; }
|
|
51
|
-
const handler = SUB[sub];
|
|
52
|
-
if (!handler) die(2, `unknown subcommand: ${sub}\n${HELP}`);
|
|
53
|
-
return handler(argv.slice(1));
|
|
54
|
-
}
|
package/bin/commands/config.ts
DELETED
|
@@ -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
|
-
}
|