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,101 +0,0 @@
1
- import { readFile } from "fs/promises";
2
- import { parseArgs } 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 } from "../../lib/output.js";
6
-
7
- const BUILD_HELP = `
8
- ima2 prompt build [options]
9
-
10
- Refine prompt intent through the embedded prompt builder.
11
-
12
- Options:
13
- --message <text> User message (required unless --messages)
14
- --messages <file|@file|-> Multi-turn conversation as JSON array
15
- --ref <image> Image reference (repeatable)
16
- --model <model> Builder model (gpt-5.5, gpt-5.4, gpt-5.4-mini)
17
- --language <ko|en|both> Preferred output language hint
18
- --server <url> Override server URL
19
- --json Output raw JSON
20
- -h, --help Show this help
21
-
22
- Examples:
23
- ima2 prompt build --message "make this prompt more cinematic" --json
24
- ima2 prompt build --messages @conversation.json --model gpt-5.5
25
- echo '{"role":"user","content":"hi"}' | ima2 prompt build --messages -
26
- `;
27
-
28
- const FLAGS = {
29
- message: { type: "string" },
30
- messages: { type: "string" },
31
- ref: { type: "string", repeatable: true },
32
- model: { type: "string" },
33
- language: { type: "string" },
34
- server: { type: "string" },
35
- json: { type: "boolean" },
36
- help: { short: "h", type: "boolean" },
37
- } as const;
38
-
39
- async function resolveMessages(args: Record<string, unknown>): Promise<Array<{ role: string; content: string }>> {
40
- if (args.messages) {
41
- const raw = String(args.messages);
42
- let text: string;
43
- if (raw === "-") {
44
- text = await readStdin();
45
- } else if (raw.startsWith("@")) {
46
- text = await readFile(raw.slice(1), "utf-8");
47
- } else {
48
- text = await readFile(raw, "utf-8");
49
- }
50
- const parsed = JSON.parse(text);
51
- if (!Array.isArray(parsed)) die(2, "--messages must resolve to a JSON array");
52
- return parsed;
53
- }
54
- if (args.message) {
55
- return [{ role: "user", content: String(args.message) }];
56
- }
57
- die(2, "--message or --messages required");
58
- throw new Error("unreachable");
59
- }
60
-
61
- export default async function buildSub(argv: string[]) {
62
- const args = parseArgs(argv, { flags: FLAGS });
63
- if (args.help) { out(BUILD_HELP); return; }
64
-
65
- const messages = await resolveMessages(args);
66
- const body: Record<string, unknown> = { messages };
67
- if (args.model) body.model = args.model;
68
-
69
- let server: { base: string };
70
- try {
71
- server = await resolveServer({ serverFlag: args.server as string | undefined });
72
- } catch (e: unknown) {
73
- die(exitCodeForError(e), (e as Error).message);
74
- throw e;
75
- }
76
-
77
- let result: Record<string, unknown>;
78
- try {
79
- result = await request(server.base, "/api/prompt-builder/chat", {
80
- method: "POST",
81
- body,
82
- }) as Record<string, unknown>;
83
- } catch (e: unknown) {
84
- const err = e as { message?: string; code?: string };
85
- die(exitCodeForError(e), `${err.message}${err.code ? ` (${err.code})` : ""}`);
86
- throw e;
87
- }
88
-
89
- if (args.json) {
90
- json(result);
91
- return;
92
- }
93
-
94
- const message = result.message as { content?: string } | undefined;
95
- const content = message?.content ?? "";
96
- if (content) {
97
- out(content);
98
- } else {
99
- out(color.dim("(empty response)"));
100
- }
101
- }
@@ -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
- }
@@ -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
- }