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
package/bin/commands/prompt.ts
DELETED
|
@@ -1,492 +0,0 @@
|
|
|
1
|
-
import { readFile, writeFile } from "fs/promises";
|
|
2
|
-
import { parseArgs, type ParsedArgs } from "../lib/args.js";
|
|
3
|
-
import { resolveServer, request } from "../lib/client.js";
|
|
4
|
-
import { readStdin } from "../lib/files.js";
|
|
5
|
-
import { out, die, color, json, exitCodeForError, table } from "../lib/output.js";
|
|
6
|
-
|
|
7
|
-
const HELP = `
|
|
8
|
-
ima2 prompt <subcommand> [options]
|
|
9
|
-
|
|
10
|
-
Core:
|
|
11
|
-
ls [--folder <id>] [--search <q>] [--favorites] [--json]
|
|
12
|
-
show <id> [--json]
|
|
13
|
-
create --text <t|@file|-> [--name <n>] [--folder <id>] [--tag <t>...] [--mode <m>]
|
|
14
|
-
edit <id> [--name] [--text <t|@file|->] [--folder] [--tag <t>...] [--mode]
|
|
15
|
-
rm <id> [--yes]
|
|
16
|
-
favorite <id>
|
|
17
|
-
export [-o <file>] Dump all non-trash prompts + folders
|
|
18
|
-
|
|
19
|
-
Builder:
|
|
20
|
-
build --message "<text>" [--ref <image>] [--model <m>] [--json]
|
|
21
|
-
build --messages <file|@file|-> [--json]
|
|
22
|
-
|
|
23
|
-
Folders:
|
|
24
|
-
folder ls
|
|
25
|
-
folder create <name>
|
|
26
|
-
folder rename <id> <name>
|
|
27
|
-
folder rm <id> [--strategy move|delete] [--yes]
|
|
28
|
-
|
|
29
|
-
Import:
|
|
30
|
-
import sources List curated + discovery sources
|
|
31
|
-
import refresh --source <id> Refresh curated cache
|
|
32
|
-
import curated --source <id> [-q <q>] [--limit <n>] [--folder <id>] [--dry-run]
|
|
33
|
-
import discovery -q <q> --seed <repo>... [--limit <n>] [--folder <id>] [--dry-run]
|
|
34
|
-
import folder <path> [--folder <id>] [--dry-run]
|
|
35
|
-
import json <file|@file|-> [--folder <id>] [--dry-run]
|
|
36
|
-
import preview <file|@file|-> [--filename <name>] [--json]
|
|
37
|
-
|
|
38
|
-
Common options:
|
|
39
|
-
--server <url> Override server URL
|
|
40
|
-
--json JSON output
|
|
41
|
-
--yes Skip destructive confirmation
|
|
42
|
-
`;
|
|
43
|
-
|
|
44
|
-
const COMMON_FLAGS = {
|
|
45
|
-
json: { type: "boolean" },
|
|
46
|
-
server: { type: "string" },
|
|
47
|
-
yes: { type: "boolean" },
|
|
48
|
-
out: { short: "o", type: "string" },
|
|
49
|
-
text: { type: "string" },
|
|
50
|
-
name: { type: "string" },
|
|
51
|
-
folder: { type: "string" },
|
|
52
|
-
filename: { type: "string" },
|
|
53
|
-
tag: { type: "string", repeatable: true },
|
|
54
|
-
mode: { type: "string" },
|
|
55
|
-
search: { type: "string" },
|
|
56
|
-
favorites: { type: "boolean" },
|
|
57
|
-
source: { type: "string" },
|
|
58
|
-
q: { short: "q", type: "string" },
|
|
59
|
-
query: { type: "string" },
|
|
60
|
-
seed: { type: "string", repeatable: true },
|
|
61
|
-
limit: { type: "string" },
|
|
62
|
-
strategy: { type: "string" },
|
|
63
|
-
"dry-run": { type: "boolean" },
|
|
64
|
-
help: { short: "h", type: "boolean" },
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
async function getServer(args: ParsedArgs) {
|
|
68
|
-
try { return await resolveServer({ serverFlag: args.server }); }
|
|
69
|
-
catch (e: any) { die(exitCodeForError(e), e.message); throw e; }
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function handle(e: unknown) {
|
|
73
|
-
const err = e as { message?: string; code?: string };
|
|
74
|
-
die(exitCodeForError(e), `${err.message}${err.code ? ` (${err.code})` : ""}`);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async function readLine(): Promise<string> {
|
|
78
|
-
return new Promise((resolve) => {
|
|
79
|
-
let buf = "";
|
|
80
|
-
process.stdin.setEncoding("utf-8");
|
|
81
|
-
const onData = (chunk: Buffer | string) => {
|
|
82
|
-
buf += chunk;
|
|
83
|
-
const nl = buf.indexOf("\n");
|
|
84
|
-
if (nl !== -1) {
|
|
85
|
-
process.stdin.removeListener("data", onData);
|
|
86
|
-
process.stdin.pause();
|
|
87
|
-
resolve(buf.slice(0, nl));
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
process.stdin.resume();
|
|
91
|
-
process.stdin.on("data", onData);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
async function resolveText(value: unknown): Promise<string | null> {
|
|
96
|
-
if (!value) return null;
|
|
97
|
-
if (typeof value !== "string") return null;
|
|
98
|
-
if (value === "-") return await readStdin();
|
|
99
|
-
if (value.startsWith("@")) return await readFile(value.slice(1), "utf-8");
|
|
100
|
-
return value;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async function readSourceArg(value: unknown, fallbackFilename: string) {
|
|
104
|
-
if (!value || typeof value !== "string") die(2, "source file required");
|
|
105
|
-
if (value === "-") return { text: await readStdin(), filename: fallbackFilename };
|
|
106
|
-
const path = value.startsWith("@") ? value.slice(1) : value;
|
|
107
|
-
return { text: await readFile(path, "utf-8"), filename: path.split(/[\\/]/).pop() || fallbackFilename };
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// ---------- core ----------
|
|
111
|
-
|
|
112
|
-
async function lsSub(argv: string[]) {
|
|
113
|
-
const args = parseArgs(argv, { flags: COMMON_FLAGS });
|
|
114
|
-
const server = await getServer(args);
|
|
115
|
-
const qs = new URLSearchParams();
|
|
116
|
-
if (args.folder) qs.set("folderId", String(args.folder));
|
|
117
|
-
if (args.search) qs.set("search", String(args.search));
|
|
118
|
-
if (args.favorites) qs.set("favoritesOnly", "1");
|
|
119
|
-
const path = qs.toString() ? `/api/prompts?${qs.toString()}` : "/api/prompts";
|
|
120
|
-
const resp: any = await request(server.base, path).catch(handle);
|
|
121
|
-
const prompts = resp.prompts || resp.items || [];
|
|
122
|
-
if (args.json) { json({ prompts }); return; }
|
|
123
|
-
if (prompts.length === 0) { out(color.dim("(no prompts)")); return; }
|
|
124
|
-
table(prompts, [
|
|
125
|
-
{ key: "id", label: "ID" },
|
|
126
|
-
{ key: "name", label: "NAME" },
|
|
127
|
-
{ key: "folder_id", label: "FOLDER" },
|
|
128
|
-
{ key: "is_favorite", label: "★", format: (v: unknown) => v ? "★" : "" },
|
|
129
|
-
{ key: "text", label: "TEXT", format: (v: unknown) => {
|
|
130
|
-
const s = String(v || "").replace(/\s+/g, " ");
|
|
131
|
-
return s.length > 48 ? s.slice(0, 45) + "…" : s;
|
|
132
|
-
} },
|
|
133
|
-
]);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
async function showSub(argv: string[]) {
|
|
137
|
-
const args = parseArgs(argv, { flags: COMMON_FLAGS });
|
|
138
|
-
const id = args.positional[0];
|
|
139
|
-
if (!id) die(2, "prompt id required");
|
|
140
|
-
const server = await getServer(args);
|
|
141
|
-
const resp = await request(server.base, `/api/prompts/${encodeURIComponent(id)}`).catch(handle);
|
|
142
|
-
json(resp);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
async function createSub(argv: string[]) {
|
|
146
|
-
const args = parseArgs(argv, { flags: COMMON_FLAGS });
|
|
147
|
-
const text = await resolveText(args.text);
|
|
148
|
-
if (!text) die(2, "--text <value|@file|-> required");
|
|
149
|
-
const body: any = { text };
|
|
150
|
-
if (args.name) body.name = args.name;
|
|
151
|
-
if (args.folder) body.folderId = args.folder;
|
|
152
|
-
if (args.tag && Array.isArray(args.tag) && args.tag.length) body.tags = args.tag;
|
|
153
|
-
if (args.mode) body.mode = args.mode;
|
|
154
|
-
const server = await getServer(args);
|
|
155
|
-
const resp = await request(server.base, "/api/prompts", { method: "POST", body }).catch(handle);
|
|
156
|
-
if (args.json) { json(resp); return; }
|
|
157
|
-
out(color.green("✓ ") + ((resp as any).id || (resp as any).prompt?.id || "(no id)"));
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
async function editSub(argv: string[]) {
|
|
161
|
-
const args = parseArgs(argv, { flags: COMMON_FLAGS });
|
|
162
|
-
const id = args.positional[0];
|
|
163
|
-
if (!id) die(2, "prompt id required");
|
|
164
|
-
const body: any = {};
|
|
165
|
-
if (args.name !== undefined) body.name = args.name;
|
|
166
|
-
if (args.text !== undefined) body.text = await resolveText(args.text);
|
|
167
|
-
if (args.folder !== undefined) body.folderId = args.folder;
|
|
168
|
-
if (args.tag && Array.isArray(args.tag) && args.tag.length) body.tags = args.tag;
|
|
169
|
-
if (args.mode !== undefined) body.mode = args.mode;
|
|
170
|
-
if (Object.keys(body).length === 0) die(2, "no fields to update");
|
|
171
|
-
const server = await getServer(args);
|
|
172
|
-
const resp = await request(server.base, `/api/prompts/${encodeURIComponent(id)}`, {
|
|
173
|
-
method: "PATCH", body,
|
|
174
|
-
}).catch(handle);
|
|
175
|
-
if (args.json) { json(resp); return; }
|
|
176
|
-
out(color.green("✓ updated"));
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
async function rmSub(argv: string[]) {
|
|
180
|
-
const args = parseArgs(argv, { flags: COMMON_FLAGS });
|
|
181
|
-
const id = args.positional[0];
|
|
182
|
-
if (!id) die(2, "prompt id required");
|
|
183
|
-
if (!args.yes && !process.stdin.isTTY) die(2, "destructive: pass --yes for non-TTY");
|
|
184
|
-
if (!args.yes) {
|
|
185
|
-
process.stdout.write(`Delete prompt ${id}? [y/N] `);
|
|
186
|
-
const ans = await readLine();
|
|
187
|
-
if (!/^y(es)?$/i.test(ans.trim())) { out("(canceled)"); return; }
|
|
188
|
-
}
|
|
189
|
-
const server = await getServer(args);
|
|
190
|
-
await request(server.base, `/api/prompts/${encodeURIComponent(id)}`, { method: "DELETE" }).catch(handle);
|
|
191
|
-
out(color.green("✓ deleted"));
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
async function favoriteSub(argv: string[]) {
|
|
195
|
-
const args = parseArgs(argv, { flags: COMMON_FLAGS });
|
|
196
|
-
const id = args.positional[0];
|
|
197
|
-
if (!id) die(2, "prompt id required");
|
|
198
|
-
const server = await getServer(args);
|
|
199
|
-
const resp: any = await request(server.base, `/api/prompts/${encodeURIComponent(id)}/favorite`, {
|
|
200
|
-
method: "POST",
|
|
201
|
-
}).catch(handle);
|
|
202
|
-
if (args.json) { json(resp); return; }
|
|
203
|
-
out(color.green(resp?.isFavorite ? "✓ favorited" : "✓ unfavorited"));
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
async function exportSub(argv: string[]) {
|
|
207
|
-
const args = parseArgs(argv, { flags: COMMON_FLAGS });
|
|
208
|
-
const server = await getServer(args);
|
|
209
|
-
const resp = await request(server.base, "/api/prompts/export").catch(handle);
|
|
210
|
-
const text = JSON.stringify(resp, null, 2);
|
|
211
|
-
if (args.out) {
|
|
212
|
-
await writeFile(String(args.out), text);
|
|
213
|
-
out(color.green("✓ ") + String(args.out));
|
|
214
|
-
} else {
|
|
215
|
-
process.stdout.write(text + "\n");
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// ---------- folders ----------
|
|
220
|
-
|
|
221
|
-
async function folderSub(argv: string[]) {
|
|
222
|
-
const action = argv[0];
|
|
223
|
-
const rest = argv.slice(1);
|
|
224
|
-
if (action === "ls") return folderLs(rest);
|
|
225
|
-
if (action === "create") return folderCreate(rest);
|
|
226
|
-
if (action === "rename") return folderRename(rest);
|
|
227
|
-
if (action === "rm") return folderRm(rest);
|
|
228
|
-
die(2, "usage: prompt folder <ls|create|rename|rm> ...");
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
async function folderLs(argv: string[]) {
|
|
232
|
-
const args = parseArgs(argv, { flags: COMMON_FLAGS });
|
|
233
|
-
const server = await getServer(args);
|
|
234
|
-
const resp: any = await request(server.base, "/api/prompts/folders").catch(handle);
|
|
235
|
-
const folders = resp.folders || resp.items || [];
|
|
236
|
-
if (args.json) { json({ folders }); return; }
|
|
237
|
-
if (folders.length === 0) { out(color.dim("(no folders)")); return; }
|
|
238
|
-
table(folders, [
|
|
239
|
-
{ key: "id", label: "ID" },
|
|
240
|
-
{ key: "name", label: "NAME" },
|
|
241
|
-
]);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
async function folderCreate(argv: string[]) {
|
|
245
|
-
const args = parseArgs(argv, { flags: COMMON_FLAGS });
|
|
246
|
-
const name = args.positional.join(" ").trim();
|
|
247
|
-
if (!name) die(2, "folder name required");
|
|
248
|
-
const server = await getServer(args);
|
|
249
|
-
const resp = await request(server.base, "/api/prompts/folders", {
|
|
250
|
-
method: "POST", body: { name },
|
|
251
|
-
}).catch(handle);
|
|
252
|
-
if (args.json) { json(resp); return; }
|
|
253
|
-
out(color.green("✓ ") + ((resp as any).id || (resp as any).folder?.id || "(no id)"));
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
async function folderRename(argv: string[]) {
|
|
257
|
-
const args = parseArgs(argv, { flags: COMMON_FLAGS });
|
|
258
|
-
const [id, ...rest] = args.positional;
|
|
259
|
-
const name = rest.join(" ").trim();
|
|
260
|
-
if (!id || !name) die(2, "usage: prompt folder rename <id> <name>");
|
|
261
|
-
const server = await getServer(args);
|
|
262
|
-
await request(server.base, `/api/prompts/folders/${encodeURIComponent(id)}`, {
|
|
263
|
-
method: "PATCH", body: { name },
|
|
264
|
-
}).catch(handle);
|
|
265
|
-
out(color.green("✓ renamed"));
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
async function folderRm(argv: string[]) {
|
|
269
|
-
const args = parseArgs(argv, { flags: COMMON_FLAGS });
|
|
270
|
-
const id = args.positional[0];
|
|
271
|
-
if (!id) die(2, "folder id required");
|
|
272
|
-
if (!args.yes && !process.stdin.isTTY) die(2, "destructive: pass --yes for non-TTY");
|
|
273
|
-
if (!args.yes) {
|
|
274
|
-
process.stdout.write(`Delete folder ${id}? [y/N] `);
|
|
275
|
-
const ans = await readLine();
|
|
276
|
-
if (!/^y(es)?$/i.test(ans.trim())) { out("(canceled)"); return; }
|
|
277
|
-
}
|
|
278
|
-
// CLI alias: --strategy delete → server's deleteItems; default → moveToRoot
|
|
279
|
-
const cliStrategy = String(args.strategy || "").toLowerCase();
|
|
280
|
-
const serverStrategy = cliStrategy === "delete" || cliStrategy === "deleteitems"
|
|
281
|
-
? "deleteItems"
|
|
282
|
-
: "moveToRoot";
|
|
283
|
-
const server = await getServer(args);
|
|
284
|
-
await request(server.base,
|
|
285
|
-
`/api/prompts/folders/${encodeURIComponent(id)}?strategy=${serverStrategy}`,
|
|
286
|
-
{ method: "DELETE" },
|
|
287
|
-
).catch(handle);
|
|
288
|
-
out(color.green(`✓ deleted (strategy: ${serverStrategy})`));
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// ---------- import ----------
|
|
292
|
-
|
|
293
|
-
async function importSub(argv: string[]) {
|
|
294
|
-
const action = argv[0];
|
|
295
|
-
const rest = argv.slice(1);
|
|
296
|
-
if (action === "sources") return importSources(rest);
|
|
297
|
-
if (action === "refresh") return importRefresh(rest);
|
|
298
|
-
if (action === "curated") return importCurated(rest);
|
|
299
|
-
if (action === "discovery") return importDiscovery(rest);
|
|
300
|
-
if (action === "folder") return importFolder(rest);
|
|
301
|
-
if (action === "json") return importJson(rest);
|
|
302
|
-
if (action === "preview") return importPreview(rest);
|
|
303
|
-
die(2, "usage: prompt import <sources|refresh|curated|discovery|folder|json|preview> ...");
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
async function importSources(argv: string[]) {
|
|
307
|
-
const args = parseArgs(argv, { flags: COMMON_FLAGS });
|
|
308
|
-
const server = await getServer(args);
|
|
309
|
-
const [curated, discovery] = await Promise.all([
|
|
310
|
-
request(server.base, "/api/prompts/import/curated-sources").catch(() => ({})),
|
|
311
|
-
request(server.base, "/api/prompts/import/discovery").catch(() => ({})),
|
|
312
|
-
]);
|
|
313
|
-
if (args.json) { json({ curated, discovery }); return; }
|
|
314
|
-
out(color.bold("Curated sources:"));
|
|
315
|
-
out(JSON.stringify(curated, null, 2));
|
|
316
|
-
out("");
|
|
317
|
-
out(color.bold("Discovery candidates:"));
|
|
318
|
-
out(JSON.stringify(discovery, null, 2));
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
async function importRefresh(argv: string[]) {
|
|
322
|
-
const args = parseArgs(argv, { flags: COMMON_FLAGS });
|
|
323
|
-
if (!args.source) die(2, "--source <id> required");
|
|
324
|
-
const server = await getServer(args);
|
|
325
|
-
const resp = await request(server.base, "/api/prompts/import/curated-refresh", {
|
|
326
|
-
method: "POST", body: { sourceId: args.source },
|
|
327
|
-
}).catch(handle);
|
|
328
|
-
if (args.json) { json(resp); return; }
|
|
329
|
-
out(color.green("✓ refreshed"));
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
async function importCurated(argv: string[]) {
|
|
333
|
-
const args = parseArgs(argv, { flags: COMMON_FLAGS });
|
|
334
|
-
if (!args.source) die(2, "--source <id> required (run `prompt import sources`)");
|
|
335
|
-
const server = await getServer(args);
|
|
336
|
-
const limit = args.limit ? parseInt(String(args.limit)) : undefined;
|
|
337
|
-
const search: any = await request(server.base, "/api/prompts/import/curated-search", {
|
|
338
|
-
method: "POST",
|
|
339
|
-
body: {
|
|
340
|
-
q: args.q || args.query || "",
|
|
341
|
-
sourceIds: [args.source],
|
|
342
|
-
...(limit ? { limit } : {}),
|
|
343
|
-
},
|
|
344
|
-
}, ).catch(handle);
|
|
345
|
-
const candidates = search.candidates || [];
|
|
346
|
-
if (candidates.length === 0) { out(color.dim("(no candidates)")); return; }
|
|
347
|
-
out(`${candidates.length} candidates`);
|
|
348
|
-
if (args["dry-run"]) { json({ candidates }); return; }
|
|
349
|
-
const commit: any = await request(server.base, "/api/prompts/import/commit", {
|
|
350
|
-
method: "POST",
|
|
351
|
-
body: { candidates, ...(args.folder ? { folderId: args.folder } : {}) },
|
|
352
|
-
}).catch(handle);
|
|
353
|
-
if (args.json) { json(commit); return; }
|
|
354
|
-
out(color.green(`✓ imported ${commit.imported || candidates.length}`));
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
async function importDiscovery(argv: string[]) {
|
|
358
|
-
const args = parseArgs(argv, { flags: COMMON_FLAGS });
|
|
359
|
-
const q = args.q || args.query;
|
|
360
|
-
if (!q) die(2, "-q <query> required for discovery import");
|
|
361
|
-
const seeds = (Array.isArray(args.seed) ? args.seed : []) as string[];
|
|
362
|
-
if (!seeds.length) die(2, "--seed <repo>... required (at least 1)");
|
|
363
|
-
const server = await getServer(args);
|
|
364
|
-
const limit = args.limit ? parseInt(String(args.limit)) : undefined;
|
|
365
|
-
const search: any = await request(server.base, "/api/prompts/import/discovery-search", {
|
|
366
|
-
method: "POST",
|
|
367
|
-
body: { q, seeds, ...(limit ? { limit } : {}) },
|
|
368
|
-
timeoutMs: 120_000,
|
|
369
|
-
}).catch(handle);
|
|
370
|
-
const candidates = search.candidates || [];
|
|
371
|
-
if (candidates.length === 0) { out(color.dim("(no candidates)")); return; }
|
|
372
|
-
out(`${candidates.length} candidates`);
|
|
373
|
-
if (args["dry-run"]) { json({ candidates }); return; }
|
|
374
|
-
const commit: any = await request(server.base, "/api/prompts/import/commit", {
|
|
375
|
-
method: "POST",
|
|
376
|
-
body: { candidates, ...(args.folder ? { folderId: args.folder } : {}) },
|
|
377
|
-
}).catch(handle);
|
|
378
|
-
if (args.json) { json(commit); return; }
|
|
379
|
-
out(color.green(`✓ imported ${commit.imported || candidates.length}`));
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
async function importFolder(argv: string[]) {
|
|
383
|
-
const args = parseArgs(argv, { flags: COMMON_FLAGS });
|
|
384
|
-
const path = args.positional[0];
|
|
385
|
-
if (!path) die(2, "usage: prompt import folder <path>");
|
|
386
|
-
const server = await getServer(args);
|
|
387
|
-
// Folder import body shapes are opaque (handled by buildFolderFiles/buildFolderPreview helpers).
|
|
388
|
-
// Conservative attempt: send { source: { input: <path> } } and { paths } chains; surface server errors verbatim.
|
|
389
|
-
const filesResp: any = await request(server.base, "/api/prompts/import/folder-files", {
|
|
390
|
-
method: "POST",
|
|
391
|
-
body: { source: { input: path }, input: path },
|
|
392
|
-
}).catch(handle);
|
|
393
|
-
const previewResp: any = await request(server.base, "/api/prompts/import/folder-preview", {
|
|
394
|
-
method: "POST",
|
|
395
|
-
body: {
|
|
396
|
-
source: { input: path }, input: path,
|
|
397
|
-
files: filesResp.files,
|
|
398
|
-
paths: (filesResp.files || []).map((f: { path?: string }) => f.path).filter(Boolean),
|
|
399
|
-
},
|
|
400
|
-
}).catch(handle);
|
|
401
|
-
const candidates = previewResp.candidates || [];
|
|
402
|
-
if (candidates.length === 0) { out(color.dim("(no candidates)")); return; }
|
|
403
|
-
if (candidates.length > 100 && !args["dry-run"]) {
|
|
404
|
-
if (!process.stdin.isTTY && !args.yes) die(2, `${candidates.length} candidates: pass --yes for non-TTY`);
|
|
405
|
-
if (process.stdin.isTTY && !args.yes) {
|
|
406
|
-
process.stdout.write(`Import ${candidates.length} prompts? [y/N] `);
|
|
407
|
-
const ans = await readLine();
|
|
408
|
-
if (!/^y(es)?$/i.test(ans.trim())) { out("(canceled)"); return; }
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
out(`${candidates.length} candidates`);
|
|
412
|
-
if (args["dry-run"]) { json({ candidates }); return; }
|
|
413
|
-
const commit: any = await request(server.base, "/api/prompts/import/commit", {
|
|
414
|
-
method: "POST",
|
|
415
|
-
body: { candidates, ...(args.folder ? { folderId: args.folder } : {}) },
|
|
416
|
-
}).catch(handle);
|
|
417
|
-
if (args.json) { json(commit); return; }
|
|
418
|
-
out(color.green(`✓ imported ${commit.imported || candidates.length}`));
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
async function importJson(argv: string[]) {
|
|
422
|
-
const args = parseArgs(argv, { flags: COMMON_FLAGS });
|
|
423
|
-
const { text } = await readSourceArg(args.positional[0], "prompts.json");
|
|
424
|
-
const parsed = JSON.parse(text) as { folders?: unknown; prompts?: unknown } | unknown[];
|
|
425
|
-
const body = Array.isArray(parsed) ? { prompts: parsed } : { ...parsed };
|
|
426
|
-
if (args.folder && Array.isArray(body.prompts)) {
|
|
427
|
-
body.prompts = body.prompts.map((prompt) => (
|
|
428
|
-
prompt && typeof prompt === "object"
|
|
429
|
-
? { ...(prompt as Record<string, unknown>), folderId: args.folder }
|
|
430
|
-
: prompt
|
|
431
|
-
));
|
|
432
|
-
}
|
|
433
|
-
if (args["dry-run"]) {
|
|
434
|
-
json({
|
|
435
|
-
folders: Array.isArray(body.folders) ? body.folders.length : 0,
|
|
436
|
-
prompts: Array.isArray(body.prompts) ? body.prompts.length : 0,
|
|
437
|
-
});
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
const server = await getServer(args);
|
|
441
|
-
const resp = await request(server.base, "/api/prompts/import", {
|
|
442
|
-
method: "POST",
|
|
443
|
-
body,
|
|
444
|
-
}).catch(handle);
|
|
445
|
-
if (args.json) { json(resp); return; }
|
|
446
|
-
out(color.green("✓ imported prompt JSON"));
|
|
447
|
-
out(JSON.stringify(resp, null, 2));
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
async function importPreview(argv: string[]) {
|
|
451
|
-
const args = parseArgs(argv, { flags: COMMON_FLAGS });
|
|
452
|
-
const { text, filename } = await readSourceArg(args.positional[0], "prompt-source.md");
|
|
453
|
-
const server = await getServer(args);
|
|
454
|
-
const resp = await request(server.base, "/api/prompts/import/preview", {
|
|
455
|
-
method: "POST",
|
|
456
|
-
body: {
|
|
457
|
-
source: {
|
|
458
|
-
kind: "local",
|
|
459
|
-
filename: args.filename || filename,
|
|
460
|
-
text,
|
|
461
|
-
},
|
|
462
|
-
},
|
|
463
|
-
}).catch(handle);
|
|
464
|
-
if (args.json) { json(resp); return; }
|
|
465
|
-
out(JSON.stringify(resp, null, 2));
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
async function buildSub(argv: string[]) {
|
|
469
|
-
const mod = await import("./prompt-sub/build.js");
|
|
470
|
-
return mod.default(argv);
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
const SUB: Record<string, (argv: any[]) => Promise<void>> = {
|
|
474
|
-
ls: lsSub,
|
|
475
|
-
show: showSub,
|
|
476
|
-
create: createSub,
|
|
477
|
-
edit: editSub,
|
|
478
|
-
rm: rmSub,
|
|
479
|
-
favorite: favoriteSub,
|
|
480
|
-
export: exportSub,
|
|
481
|
-
folder: folderSub,
|
|
482
|
-
import: importSub,
|
|
483
|
-
build: buildSub,
|
|
484
|
-
};
|
|
485
|
-
|
|
486
|
-
export default async function promptCmd(argv: string[]) {
|
|
487
|
-
const sub = argv[0];
|
|
488
|
-
if (!sub || sub === "--help" || sub === "-h") { out(HELP); return; }
|
|
489
|
-
const handler = SUB[sub];
|
|
490
|
-
if (!handler) die(2, `unknown subcommand: ${sub}\n${HELP}`);
|
|
491
|
-
return handler(argv.slice(1));
|
|
492
|
-
}
|
package/bin/commands/ps.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { parseArgs } from "../lib/args.js";
|
|
2
|
-
import { resolveServer, request } from "../lib/client.js";
|
|
3
|
-
import { out, dieWithError, color, json, table } from "../lib/output.js";
|
|
4
|
-
|
|
5
|
-
import { errInfo } from "../../lib/errInfo.js";
|
|
6
|
-
const SPEC = {
|
|
7
|
-
flags: {
|
|
8
|
-
kind: { type: "string" },
|
|
9
|
-
session: { type: "string" },
|
|
10
|
-
terminal: { type: "boolean" },
|
|
11
|
-
json: { type: "boolean" },
|
|
12
|
-
server: { type: "string" },
|
|
13
|
-
help: { short: "h", type: "boolean" },
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export default async function psCmd(argv: string[]) {
|
|
18
|
-
const args = parseArgs(argv, SPEC);
|
|
19
|
-
if (args.help) { out("ima2 ps [--kind classic|node|multimode] [--session id] [--terminal] [--json]"); return; }
|
|
20
|
-
|
|
21
|
-
let server;
|
|
22
|
-
try { server = await resolveServer({ serverFlag: args.server }); }
|
|
23
|
-
catch (e) {
|
|
24
|
-
const err = errInfo(e);
|
|
25
|
-
if (args.json) json({ ok: false, error: err.message, code: err.code, status: err.status });
|
|
26
|
-
dieWithError(e);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const qs = new URLSearchParams();
|
|
30
|
-
if (args.kind) qs.set("kind", String(args.kind));
|
|
31
|
-
if (args.session) qs.set("sessionId", String(args.session));
|
|
32
|
-
if (args.terminal) qs.set("includeTerminal", "1");
|
|
33
|
-
const path = `/api/inflight${qs.toString() ? `?${qs}` : ""}`;
|
|
34
|
-
let resp;
|
|
35
|
-
try { resp = await request(server.base, path); }
|
|
36
|
-
catch (e) {
|
|
37
|
-
const err = errInfo(e);
|
|
38
|
-
if (args.json) json({ ok: false, error: err.message, code: err.code, status: err.status });
|
|
39
|
-
dieWithError(e);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const jobs = resp.jobs || resp.items || [];
|
|
43
|
-
const terminalJobs = resp.terminalJobs || [];
|
|
44
|
-
if (args.json) {
|
|
45
|
-
json(args.terminal ? { jobs, terminalJobs } : { jobs });
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
if (jobs.length === 0 && terminalJobs.length === 0) {
|
|
49
|
-
out(color.dim(args.terminal ? "(no active or terminal jobs)" : "(no active jobs)"));
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const now = Date.now();
|
|
54
|
-
if (jobs.length > 0) {
|
|
55
|
-
out(color.bold("Active jobs"));
|
|
56
|
-
table(jobs, [
|
|
57
|
-
{ key: "requestId", label: "ID", format: (v: unknown) => String(v || "").slice(0, 10) },
|
|
58
|
-
{ key: "kind", label: "KIND" },
|
|
59
|
-
{ key: "phase", label: "PHASE" },
|
|
60
|
-
{ key: "startedAt", label: "AGE", format: (v: unknown) => v ? `${Math.round((now - Number(v)) / 1000)}s` : "" },
|
|
61
|
-
{ key: "prompt", label: "PROMPT", format: (v: unknown) => {
|
|
62
|
-
const s = String(v || "").replace(/\s+/g, " ");
|
|
63
|
-
return s.length > 40 ? s.slice(0, 37) + "…" : s;
|
|
64
|
-
} },
|
|
65
|
-
]);
|
|
66
|
-
}
|
|
67
|
-
if (terminalJobs.length > 0) {
|
|
68
|
-
if (jobs.length > 0) out("");
|
|
69
|
-
out(color.bold("Terminal jobs"));
|
|
70
|
-
table(terminalJobs, [
|
|
71
|
-
{ key: "requestId", label: "ID", format: (v: unknown) => String(v || "").slice(0, 10) },
|
|
72
|
-
{ key: "kind", label: "KIND" },
|
|
73
|
-
{ key: "status", label: "STATUS" },
|
|
74
|
-
{ key: "finishedAt", label: "AGE", format: (v: unknown) => v ? `${Math.round((now - Number(v)) / 1000)}s` : "" },
|
|
75
|
-
{ key: "prompt", label: "PROMPT", format: (v: unknown) => {
|
|
76
|
-
const s = String(v || "").replace(/\s+/g, " ");
|
|
77
|
-
return s.length > 40 ? s.slice(0, 37) + "…" : s;
|
|
78
|
-
} },
|
|
79
|
-
]);
|
|
80
|
-
}
|
|
81
|
-
}
|