chainlesschain 0.49.0 → 0.66.0

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 (43) hide show
  1. package/package.json +1 -1
  2. package/src/assets/web-panel/.build-hash +1 -1
  3. package/src/assets/web-panel/assets/{AppLayout-Rvi759IS.js → AppLayout-6SPt_8Y_.js} +1 -1
  4. package/src/assets/web-panel/assets/{Dashboard-DBhFxXYQ.js → Dashboard-Br7kCwKJ.js} +2 -2
  5. package/src/assets/web-panel/assets/Dashboard-CKeMmCoT.css +1 -0
  6. package/src/assets/web-panel/assets/{index-uL0cZ8N_.js → index-tN-8TosE.js} +2 -2
  7. package/src/assets/web-panel/index.html +2 -2
  8. package/src/commands/agent-network.js +785 -0
  9. package/src/commands/automation.js +654 -0
  10. package/src/commands/dao.js +565 -0
  11. package/src/commands/did-v2.js +620 -0
  12. package/src/commands/economy.js +578 -0
  13. package/src/commands/evolution.js +391 -0
  14. package/src/commands/hmemory.js +442 -0
  15. package/src/commands/ipfs.js +392 -0
  16. package/src/commands/multimodal.js +404 -0
  17. package/src/commands/perf.js +433 -0
  18. package/src/commands/pipeline.js +449 -0
  19. package/src/commands/plugin-ecosystem.js +517 -0
  20. package/src/commands/sandbox.js +401 -0
  21. package/src/commands/social.js +311 -0
  22. package/src/commands/sso.js +798 -0
  23. package/src/commands/workflow.js +320 -0
  24. package/src/commands/zkp.js +227 -1
  25. package/src/index.js +27 -0
  26. package/src/lib/agent-economy.js +479 -0
  27. package/src/lib/agent-network.js +1121 -0
  28. package/src/lib/automation-engine.js +948 -0
  29. package/src/lib/dao-governance.js +569 -0
  30. package/src/lib/did-v2-manager.js +1127 -0
  31. package/src/lib/evolution-system.js +453 -0
  32. package/src/lib/hierarchical-memory.js +481 -0
  33. package/src/lib/ipfs-storage.js +575 -0
  34. package/src/lib/multimodal.js +39 -12
  35. package/src/lib/perf-tuning.js +734 -0
  36. package/src/lib/pipeline-orchestrator.js +928 -0
  37. package/src/lib/plugin-ecosystem.js +1109 -0
  38. package/src/lib/sandbox-v2.js +306 -0
  39. package/src/lib/social-graph-analytics.js +707 -0
  40. package/src/lib/sso-manager.js +841 -0
  41. package/src/lib/workflow-engine.js +454 -1
  42. package/src/lib/zkp-engine.js +249 -20
  43. package/src/assets/web-panel/assets/Dashboard-BS-tzGNj.css +0 -1
@@ -0,0 +1,404 @@
1
+ /**
2
+ * `cc multimodal` — CLI surface for Phase 27 多模态协作.
3
+ *
4
+ * Exposes 5-modality weighted fusion, doc parsing (txt/md/csv/json),
5
+ * context building with 4000-token cap, and 6 output formats.
6
+ */
7
+
8
+ import fs from "fs";
9
+ import { Command } from "commander";
10
+
11
+ import {
12
+ MODALITIES,
13
+ MODALITY_WEIGHTS,
14
+ INPUT_FORMATS,
15
+ NATIVE_FORMATS,
16
+ OUTPUT_FORMATS,
17
+ SESSION_STATUS,
18
+ DEFAULT_MAX_TOKENS,
19
+ ensureMultimodalTables,
20
+ createSession,
21
+ getSession,
22
+ listSessions,
23
+ completeSession,
24
+ deleteSession,
25
+ addModality,
26
+ getSessionModalities,
27
+ fuse,
28
+ parseDocument,
29
+ getSupportedFormats,
30
+ buildContext,
31
+ getContext,
32
+ clearContext,
33
+ trimContext,
34
+ generateOutput,
35
+ getOutputFormats,
36
+ listArtifacts,
37
+ getMultimodalStats,
38
+ } from "../lib/multimodal.js";
39
+
40
+ function _dbFromCtx(cmd) {
41
+ const root = cmd?.parent?.parent ?? cmd?.parent;
42
+ return root?._db;
43
+ }
44
+
45
+ function _parseJson(raw) {
46
+ if (raw == null) return null;
47
+ try {
48
+ return JSON.parse(raw);
49
+ } catch (_e) {
50
+ return raw;
51
+ }
52
+ }
53
+
54
+ function _readData(opts) {
55
+ if (opts.file) return fs.readFileSync(opts.file, "utf-8");
56
+ if (opts.text != null) return opts.text;
57
+ if (opts.data != null) return _parseJson(opts.data);
58
+ return null;
59
+ }
60
+
61
+ export function registerMultimodalCommand(program) {
62
+ const mm = new Command("multimodal")
63
+ .alias("mm")
64
+ .description("Multimodal collaboration (Phase 27)")
65
+ .hook("preAction", (thisCmd) => {
66
+ const db = _dbFromCtx(thisCmd);
67
+ if (db) ensureMultimodalTables(db);
68
+ });
69
+
70
+ /* ── Catalogs ─────────────────────────────────────── */
71
+
72
+ mm.command("modalities")
73
+ .description("List 5 input modalities with weights")
74
+ .option("--json", "JSON output")
75
+ .action((opts) => {
76
+ const rows = MODALITIES.map((m) => ({
77
+ modality: m,
78
+ weight: MODALITY_WEIGHTS[m],
79
+ }));
80
+ if (opts.json) return console.log(JSON.stringify(rows, null, 2));
81
+ for (const r of rows)
82
+ console.log(` ${r.modality.padEnd(10)} weight=${r.weight}`);
83
+ });
84
+
85
+ mm.command("input-formats")
86
+ .description("List 7 supported document formats (4 native)")
87
+ .option("--json", "JSON output")
88
+ .action((opts) => {
89
+ const r = getSupportedFormats();
90
+ if (opts.json) return console.log(JSON.stringify(r, null, 2));
91
+ console.log("Formats:", r.formats.join(", "));
92
+ console.log("Native: ", r.native.join(", "));
93
+ });
94
+
95
+ mm.command("output-formats")
96
+ .description("List 6 output formats")
97
+ .option("--json", "JSON output")
98
+ .action((opts) => {
99
+ const r = getOutputFormats();
100
+ if (opts.json) return console.log(JSON.stringify(r, null, 2));
101
+ for (const f of r) console.log(` ${f}`);
102
+ });
103
+
104
+ mm.command("statuses")
105
+ .description("List session statuses")
106
+ .option("--json", "JSON output")
107
+ .action((opts) => {
108
+ const s = Object.values(SESSION_STATUS);
109
+ if (opts.json) return console.log(JSON.stringify(s, null, 2));
110
+ for (const x of s) console.log(` ${x}`);
111
+ });
112
+
113
+ /* ── Sessions ─────────────────────────────────────── */
114
+
115
+ mm.command("session-create")
116
+ .description("Create a multimodal session")
117
+ .option("-t, --title <title>", "Session title")
118
+ .option("-m, --meta <json>", "Metadata JSON")
119
+ .option("--json", "JSON output")
120
+ .action((opts) => {
121
+ const db = _dbFromCtx(mm);
122
+ const r = createSession(db, {
123
+ title: opts.title,
124
+ metadata: _parseJson(opts.meta),
125
+ });
126
+ if (opts.json) return console.log(JSON.stringify(r, null, 2));
127
+ console.log(`Session created: ${r.sessionId}`);
128
+ });
129
+
130
+ mm.command("session-show <sessionId>")
131
+ .description("Show session details")
132
+ .option("--json", "JSON output")
133
+ .action((sessionId, opts) => {
134
+ const db = _dbFromCtx(mm);
135
+ const s = getSession(db, sessionId);
136
+ if (!s) return console.log("Not found");
137
+ if (opts.json) return console.log(JSON.stringify(s, null, 2));
138
+ console.log(`ID: ${s.id}`);
139
+ console.log(`Status: ${s.status}`);
140
+ console.log(`Modalities: ${s.modalities.join(", ") || "-"}`);
141
+ console.log(`Tokens: ${s.tokenCount}`);
142
+ console.log(`Created: ${new Date(s.createdAt).toISOString()}`);
143
+ });
144
+
145
+ mm.command("sessions")
146
+ .description("List sessions")
147
+ .option("-s, --status <status>", "Filter by status")
148
+ .option("-n, --limit <n>", "Limit", (v) => parseInt(v, 10), 50)
149
+ .option("--json", "JSON output")
150
+ .action((opts) => {
151
+ const db = _dbFromCtx(mm);
152
+ const rows = listSessions(db, { status: opts.status, limit: opts.limit });
153
+ if (opts.json) return console.log(JSON.stringify(rows, null, 2));
154
+ if (rows.length === 0) return console.log("No sessions");
155
+ for (const r of rows)
156
+ console.log(
157
+ ` ${r.id.slice(0, 8)}… ${r.status.padEnd(10)} tok=${String(r.tokenCount).padStart(5)} [${r.modalities.join(",")}]`,
158
+ );
159
+ });
160
+
161
+ mm.command("session-complete <sessionId>")
162
+ .description("Mark session as completed")
163
+ .option("--json", "JSON output")
164
+ .action((sessionId, opts) => {
165
+ const db = _dbFromCtx(mm);
166
+ const r = completeSession(db, sessionId);
167
+ if (opts.json) return console.log(JSON.stringify(r, null, 2));
168
+ if (!r.completed) return console.log(`Failed: ${r.reason}`);
169
+ console.log("Session completed");
170
+ });
171
+
172
+ mm.command("session-delete <sessionId>")
173
+ .description("Delete session and all artifacts")
174
+ .option("--json", "JSON output")
175
+ .action((sessionId, opts) => {
176
+ const db = _dbFromCtx(mm);
177
+ const r = deleteSession(db, sessionId);
178
+ if (opts.json) return console.log(JSON.stringify(r, null, 2));
179
+ if (!r.deleted) return console.log(`Failed: ${r.reason}`);
180
+ console.log("Session deleted");
181
+ });
182
+
183
+ /* ── Modalities ───────────────────────────────────── */
184
+
185
+ mm.command("add <sessionId>")
186
+ .description("Add a modality input to a session")
187
+ .requiredOption(
188
+ "-m, --modality <type>",
189
+ "Modality (text|document|image|audio|screen)",
190
+ )
191
+ .option("-f, --file <path>", "Read content from file")
192
+ .option("-t, --text <text>", "Inline text content")
193
+ .option("-d, --data <json>", "Inline JSON content")
194
+ .option("--meta <json>", "Metadata JSON")
195
+ .option("--json", "JSON output")
196
+ .action((sessionId, opts) => {
197
+ const db = _dbFromCtx(mm);
198
+ const data = _readData(opts);
199
+ if (data == null)
200
+ return console.log("Must provide --file, --text, or --data");
201
+ const r = addModality(db, sessionId, opts.modality, data, {
202
+ metadata: _parseJson(opts.meta),
203
+ });
204
+ if (opts.json) return console.log(JSON.stringify(r, null, 2));
205
+ if (!r.added) return console.log(`Failed: ${r.reason}`);
206
+ console.log(`Added ${r.modality} modality (artifact=${r.artifactId})`);
207
+ });
208
+
209
+ mm.command("modalities-of <sessionId>")
210
+ .description("List modalities added to a session")
211
+ .option("--json", "JSON output")
212
+ .action((sessionId, opts) => {
213
+ const db = _dbFromCtx(mm);
214
+ const r = getSessionModalities(db, sessionId);
215
+ if (opts.json) return console.log(JSON.stringify(r, null, 2));
216
+ for (const [m, items] of Object.entries(r))
217
+ console.log(` ${m.padEnd(10)} ${items.length} item(s)`);
218
+ });
219
+
220
+ mm.command("fuse <sessionId>")
221
+ .description("Weighted fusion of all input artifacts")
222
+ .option("--json", "JSON output")
223
+ .action((sessionId, opts) => {
224
+ const db = _dbFromCtx(mm);
225
+ const r = fuse(db, sessionId);
226
+ if (opts.json) return console.log(JSON.stringify(r, null, 2));
227
+ if (!r.fused) return console.log(`Failed: ${r.reason}`);
228
+ console.log(
229
+ `Fused ${r.summary.length} modalities (weight=${r.totalWeight}, tokens~${r.tokenEstimate})`,
230
+ );
231
+ for (const s of r.summary)
232
+ console.log(` ${s.modality.padEnd(10)} n=${s.count} w=${s.weight}`);
233
+ });
234
+
235
+ /* ── Parsing ──────────────────────────────────────── */
236
+
237
+ mm.command("parse <filePath>")
238
+ .description("Parse a document (txt/md/csv/json native)")
239
+ .option("--json", "JSON output")
240
+ .action((filePath, opts) => {
241
+ const r = parseDocument(filePath);
242
+ if (opts.json) return console.log(JSON.stringify(r, null, 2));
243
+ if (!r.parsed)
244
+ return console.log(
245
+ `Failed: ${r.reason}${r.hint ? `\n ${r.hint}` : ""}`,
246
+ );
247
+ console.log(
248
+ `Parsed ${r.format}: length=${r.length}, tokens~${r.tokenEstimate}`,
249
+ );
250
+ if (r.rowCount != null) console.log(`Rows: ${r.rowCount}`);
251
+ });
252
+
253
+ /* ── Context ──────────────────────────────────────── */
254
+
255
+ mm.command("build-context <sessionId>")
256
+ .description("Build context from session artifacts")
257
+ .option(
258
+ "-t, --max-tokens <n>",
259
+ "Max tokens",
260
+ (v) => parseInt(v, 10),
261
+ DEFAULT_MAX_TOKENS,
262
+ )
263
+ .option("--json", "JSON output")
264
+ .action((sessionId, opts) => {
265
+ const db = _dbFromCtx(mm);
266
+ const r = buildContext(db, sessionId, { maxTokens: opts.maxTokens });
267
+ if (opts.json) return console.log(JSON.stringify(r, null, 2));
268
+ if (!r.built) return console.log(`Failed: ${r.reason}`);
269
+ console.log(
270
+ `Built context: ${r.tokens}/${r.maxTokens} tokens across ${r.itemCount} items`,
271
+ );
272
+ });
273
+
274
+ mm.command("get-context <sessionId>")
275
+ .description("Get cached/stored context")
276
+ .option("--json", "JSON output")
277
+ .action((sessionId, opts) => {
278
+ const db = _dbFromCtx(mm);
279
+ const r = getContext(db, sessionId);
280
+ if (!r) return console.log("No context built yet");
281
+ if (opts.json) return console.log(JSON.stringify(r, null, 2));
282
+ console.log(`Tokens: ${r.tokens}/${r.maxTokens}`);
283
+ console.log(`Items: ${r.items?.length || 0}`);
284
+ if (r.content) console.log(`\n--- content ---\n${r.content}`);
285
+ });
286
+
287
+ mm.command("clear-context <sessionId>")
288
+ .description("Clear the session's context")
289
+ .option("--json", "JSON output")
290
+ .action((sessionId, opts) => {
291
+ const db = _dbFromCtx(mm);
292
+ const r = clearContext(db, sessionId);
293
+ if (opts.json) return console.log(JSON.stringify(r, null, 2));
294
+ if (!r.cleared) return console.log(`Failed: ${r.reason}`);
295
+ console.log("Context cleared");
296
+ });
297
+
298
+ mm.command("trim-context <sessionId>")
299
+ .description("Trim current context to max tokens")
300
+ .requiredOption("-t, --max-tokens <n>", "Max tokens", (v) =>
301
+ parseInt(v, 10),
302
+ )
303
+ .option("--json", "JSON output")
304
+ .action((sessionId, opts) => {
305
+ const db = _dbFromCtx(mm);
306
+ const ctx = getContext(db, sessionId);
307
+ if (!ctx) return console.log("No context built yet");
308
+ const r = trimContext(ctx, opts.maxTokens);
309
+ if (opts.json) return console.log(JSON.stringify(r, null, 2));
310
+ if (!r.trimmed) return console.log(`Failed: ${r.reason}`);
311
+ console.log(
312
+ `Trimmed to ${r.tokens}/${r.maxTokens} tokens (${r.items.length} items)`,
313
+ );
314
+ });
315
+
316
+ /* ── Output generation ────────────────────────────── */
317
+
318
+ mm.command("generate")
319
+ .description("Generate output in one of 6 formats")
320
+ .requiredOption("-f, --format <format>", "Output format")
321
+ .option("-s, --session <id>", "Session to attach artifact")
322
+ .option("-c, --content <text>", "Inline content")
323
+ .option("--file <path>", "Read content from file")
324
+ .option("--data <json>", "Inline JSON content")
325
+ .option("-o, --out <path>", "Write output to file")
326
+ .option("--title <title>", "Optional title")
327
+ .option("--chart-type <type>", "Chart type for chart format", "line")
328
+ .option("--json", "JSON output")
329
+ .action((opts) => {
330
+ const db = _dbFromCtx(mm);
331
+ let content;
332
+ if (opts.file) content = fs.readFileSync(opts.file, "utf-8");
333
+ else if (opts.data) content = _parseJson(opts.data);
334
+ else content = opts.content ?? "";
335
+ const r = generateOutput(db, opts.session, content, opts.format, {
336
+ title: opts.title,
337
+ chartType: opts.chartType,
338
+ });
339
+ if (!r.generated)
340
+ return console.log(
341
+ `Failed: ${r.reason}${r.format ? ` (format=${r.format})` : ""}`,
342
+ );
343
+ if (opts.out) {
344
+ fs.writeFileSync(opts.out, r.content);
345
+ console.log(`Wrote ${r.size} bytes to ${opts.out}`);
346
+ return;
347
+ }
348
+ if (opts.json) return console.log(JSON.stringify(r, null, 2));
349
+ console.log(`--- ${r.format} (${r.size} bytes) ---`);
350
+ console.log(r.content);
351
+ });
352
+
353
+ /* ── Artifacts ────────────────────────────────────── */
354
+
355
+ mm.command("artifacts <sessionId>")
356
+ .description("List artifacts for a session")
357
+ .option("-t, --type <type>", "input|output")
358
+ .option("-m, --modality <m>", "Filter by modality")
359
+ .option("-n, --limit <n>", "Limit", (v) => parseInt(v, 10), 100)
360
+ .option("--json", "JSON output")
361
+ .action((sessionId, opts) => {
362
+ const db = _dbFromCtx(mm);
363
+ const rows = listArtifacts(db, sessionId, {
364
+ type: opts.type,
365
+ modality: opts.modality,
366
+ limit: opts.limit,
367
+ });
368
+ if (opts.json) return console.log(JSON.stringify(rows, null, 2));
369
+ if (rows.length === 0) return console.log("No artifacts");
370
+ for (const a of rows) {
371
+ const head =
372
+ typeof a.content === "string"
373
+ ? a.content.slice(0, 40).replace(/\n/g, " ")
374
+ : "(json)";
375
+ console.log(
376
+ ` ${a.id.slice(0, 8)}… ${a.type.padEnd(6)} ${(a.modality || a.format || "-").padEnd(10)} ${head}`,
377
+ );
378
+ }
379
+ });
380
+
381
+ /* ── Stats ────────────────────────────────────────── */
382
+
383
+ mm.command("stats")
384
+ .description("Multimodal system statistics")
385
+ .option("--json", "JSON output")
386
+ .action((opts) => {
387
+ const db = _dbFromCtx(mm);
388
+ const s = getMultimodalStats(db);
389
+ if (opts.json) return console.log(JSON.stringify(s, null, 2));
390
+ console.log(`Sessions: ${s.sessions}`);
391
+ console.log(
392
+ `Artifacts: ${s.artifacts} (in=${s.inputs}, out=${s.outputs})`,
393
+ );
394
+ console.log(`Tokens: ${s.totalTokens}`);
395
+ console.log("By status:");
396
+ for (const [k, v] of Object.entries(s.byStatus))
397
+ console.log(` ${k}: ${v}`);
398
+ console.log("By modality:");
399
+ for (const [k, v] of Object.entries(s.byModality))
400
+ console.log(` ${k}: ${v}`);
401
+ });
402
+
403
+ program.addCommand(mm);
404
+ }