chainlesschain 0.37.9 → 0.37.11

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 (84) hide show
  1. package/README.md +309 -19
  2. package/bin/chainlesschain.js +4 -0
  3. package/package.json +1 -1
  4. package/src/commands/a2a.js +374 -0
  5. package/src/commands/audit.js +286 -0
  6. package/src/commands/auth.js +387 -0
  7. package/src/commands/bi.js +240 -0
  8. package/src/commands/browse.js +184 -0
  9. package/src/commands/cowork.js +317 -0
  10. package/src/commands/did.js +376 -0
  11. package/src/commands/economy.js +375 -0
  12. package/src/commands/encrypt.js +233 -0
  13. package/src/commands/evolution.js +398 -0
  14. package/src/commands/export.js +125 -0
  15. package/src/commands/git.js +215 -0
  16. package/src/commands/hmemory.js +273 -0
  17. package/src/commands/hook.js +260 -0
  18. package/src/commands/import.js +259 -0
  19. package/src/commands/init.js +184 -0
  20. package/src/commands/instinct.js +202 -0
  21. package/src/commands/llm.js +155 -4
  22. package/src/commands/lowcode.js +320 -0
  23. package/src/commands/mcp.js +302 -0
  24. package/src/commands/memory.js +282 -0
  25. package/src/commands/note.js +187 -0
  26. package/src/commands/org.js +505 -0
  27. package/src/commands/p2p.js +274 -0
  28. package/src/commands/plugin.js +451 -0
  29. package/src/commands/sandbox.js +366 -0
  30. package/src/commands/search.js +237 -0
  31. package/src/commands/session.js +238 -0
  32. package/src/commands/skill.js +254 -201
  33. package/src/commands/sync.js +249 -0
  34. package/src/commands/tokens.js +214 -0
  35. package/src/commands/wallet.js +416 -0
  36. package/src/commands/workflow.js +359 -0
  37. package/src/commands/zkp.js +277 -0
  38. package/src/index.js +93 -1
  39. package/src/lib/a2a-protocol.js +371 -0
  40. package/src/lib/agent-coordinator.js +273 -0
  41. package/src/lib/agent-economy.js +369 -0
  42. package/src/lib/app-builder.js +377 -0
  43. package/src/lib/audit-logger.js +364 -0
  44. package/src/lib/bi-engine.js +299 -0
  45. package/src/lib/bm25-search.js +322 -0
  46. package/src/lib/browser-automation.js +216 -0
  47. package/src/lib/cowork/ab-comparator-cli.js +180 -0
  48. package/src/lib/cowork/code-knowledge-graph-cli.js +232 -0
  49. package/src/lib/cowork/debate-review-cli.js +144 -0
  50. package/src/lib/cowork/decision-kb-cli.js +153 -0
  51. package/src/lib/cowork/project-style-analyzer-cli.js +168 -0
  52. package/src/lib/cowork-adapter.js +106 -0
  53. package/src/lib/crypto-manager.js +246 -0
  54. package/src/lib/did-manager.js +270 -0
  55. package/src/lib/ensure-utf8.js +59 -0
  56. package/src/lib/evolution-system.js +508 -0
  57. package/src/lib/git-integration.js +220 -0
  58. package/src/lib/hierarchical-memory.js +471 -0
  59. package/src/lib/hook-manager.js +387 -0
  60. package/src/lib/instinct-manager.js +190 -0
  61. package/src/lib/knowledge-exporter.js +302 -0
  62. package/src/lib/knowledge-importer.js +293 -0
  63. package/src/lib/llm-providers.js +325 -0
  64. package/src/lib/mcp-client.js +413 -0
  65. package/src/lib/memory-manager.js +211 -0
  66. package/src/lib/note-versioning.js +244 -0
  67. package/src/lib/org-manager.js +424 -0
  68. package/src/lib/p2p-manager.js +317 -0
  69. package/src/lib/pdf-parser.js +96 -0
  70. package/src/lib/permission-engine.js +374 -0
  71. package/src/lib/plan-mode.js +333 -0
  72. package/src/lib/plugin-manager.js +430 -0
  73. package/src/lib/project-detector.js +53 -0
  74. package/src/lib/response-cache.js +156 -0
  75. package/src/lib/sandbox-v2.js +503 -0
  76. package/src/lib/service-container.js +183 -0
  77. package/src/lib/session-manager.js +189 -0
  78. package/src/lib/skill-loader.js +274 -0
  79. package/src/lib/sync-manager.js +347 -0
  80. package/src/lib/token-tracker.js +200 -0
  81. package/src/lib/wallet-manager.js +348 -0
  82. package/src/lib/workflow-engine.js +503 -0
  83. package/src/lib/zkp-engine.js +241 -0
  84. package/src/repl/agent-repl.js +259 -124
@@ -0,0 +1,398 @@
1
+ /**
2
+ * Self-Evolving System commands
3
+ * chainlesschain evolution assess|learn|diagnose|repair|predict|growth|stats|export
4
+ */
5
+
6
+ import chalk from "chalk";
7
+ import ora from "ora";
8
+ import { logger } from "../lib/logger.js";
9
+ import { bootstrap, shutdown } from "../runtime/bootstrap.js";
10
+ import {
11
+ assessCapability,
12
+ trainIncremental,
13
+ selfDiagnose,
14
+ selfRepair,
15
+ predictBehavior,
16
+ getGrowthLog,
17
+ getCapabilities,
18
+ getModels,
19
+ exportModel,
20
+ } from "../lib/evolution-system.js";
21
+
22
+ export function registerEvolutionCommand(program) {
23
+ const evolution = program
24
+ .command("evolution")
25
+ .description("Self-evolving AI system — capabilities, learning, diagnosis");
26
+
27
+ // evolution assess <name> <score>
28
+ evolution
29
+ .command("assess")
30
+ .description("Assess and track a capability")
31
+ .argument("<name>", "Capability name")
32
+ .argument("<score>", "Score (0-1)")
33
+ .option("--category <cat>", "Capability category", "general")
34
+ .option("--json", "Output as JSON")
35
+ .action(async (name, score, options) => {
36
+ try {
37
+ const ctx = await bootstrap({ verbose: program.opts().verbose });
38
+ if (!ctx.db) {
39
+ logger.error("Database not available");
40
+ process.exit(1);
41
+ }
42
+ const db = ctx.db.getDatabase();
43
+ const spinner = ora(`Assessing capability: ${name}...`).start();
44
+
45
+ const result = assessCapability(
46
+ db,
47
+ name,
48
+ parseFloat(score),
49
+ options.category,
50
+ );
51
+ spinner.succeed("Capability assessed");
52
+
53
+ if (options.json) {
54
+ console.log(JSON.stringify(result, null, 2));
55
+ } else {
56
+ const trendIcon =
57
+ result.trend === "improving"
58
+ ? chalk.green("improving")
59
+ : result.trend === "declining"
60
+ ? chalk.red("declining")
61
+ : chalk.gray("stable");
62
+ logger.log(chalk.bold(`Capability: ${result.name}`));
63
+ logger.log(` Score: ${chalk.cyan(result.score)}`);
64
+ logger.log(` Trend: ${trendIcon}`);
65
+ logger.log(` History: ${result.history.length} assessments`);
66
+ }
67
+
68
+ await shutdown();
69
+ } catch (err) {
70
+ logger.error(`Failed: ${err.message}`);
71
+ process.exit(1);
72
+ }
73
+ });
74
+
75
+ // evolution learn <model-id>
76
+ evolution
77
+ .command("learn")
78
+ .description("Train a model with incremental data")
79
+ .argument("<model-id>", "Model ID to train")
80
+ .option("--data <json>", "Training data as JSON array")
81
+ .option(
82
+ "--type <type>",
83
+ "Model type (classification|regression)",
84
+ "classification",
85
+ )
86
+ .option("--json", "Output as JSON")
87
+ .action(async (modelId, options) => {
88
+ try {
89
+ const ctx = await bootstrap({ verbose: program.opts().verbose });
90
+ if (!ctx.db) {
91
+ logger.error("Database not available");
92
+ process.exit(1);
93
+ }
94
+ const db = ctx.db.getDatabase();
95
+ const spinner = ora(`Training model: ${modelId}...`).start();
96
+
97
+ let data = [{ sample: true }];
98
+ if (options.data) {
99
+ try {
100
+ data = JSON.parse(options.data);
101
+ } catch (_err) {
102
+ // Use data string as single data point
103
+ data = [options.data];
104
+ }
105
+ }
106
+
107
+ const result = trainIncremental(db, modelId, data, {
108
+ type: options.type,
109
+ });
110
+ spinner.succeed("Model trained");
111
+
112
+ if (options.json) {
113
+ console.log(JSON.stringify(result, null, 2));
114
+ } else {
115
+ logger.log(chalk.bold(`Model: ${result.name}`));
116
+ logger.log(` Type: ${result.type}`);
117
+ logger.log(` Accuracy: ${chalk.cyan(result.accuracy.toFixed(4))}`);
118
+ logger.log(` Data Points: ${result.dataPoints}`);
119
+ }
120
+
121
+ await shutdown();
122
+ } catch (err) {
123
+ logger.error(`Failed: ${err.message}`);
124
+ process.exit(1);
125
+ }
126
+ });
127
+
128
+ // evolution diagnose
129
+ evolution
130
+ .command("diagnose")
131
+ .description("Run self-diagnosis on the system")
132
+ .option("--json", "Output as JSON")
133
+ .action(async (options) => {
134
+ try {
135
+ const ctx = await bootstrap({ verbose: program.opts().verbose });
136
+ if (!ctx.db) {
137
+ logger.error("Database not available");
138
+ process.exit(1);
139
+ }
140
+ const db = ctx.db.getDatabase();
141
+ const spinner = ora("Running self-diagnosis...").start();
142
+
143
+ const result = selfDiagnose(db);
144
+ spinner.succeed("Diagnosis complete");
145
+
146
+ if (options.json) {
147
+ console.log(JSON.stringify(result, null, 2));
148
+ } else {
149
+ const statusColor =
150
+ result.overallStatus === "healthy" ? chalk.green : chalk.yellow;
151
+ logger.log(
152
+ chalk.bold(`Overall Status: ${statusColor(result.overallStatus)}`),
153
+ );
154
+
155
+ logger.log(chalk.bold("\nComponents:"));
156
+ for (const c of result.components) {
157
+ const icon =
158
+ c.status === "healthy" ? chalk.green("OK") : chalk.yellow("WARN");
159
+ logger.log(` ${icon} ${c.name}`);
160
+ }
161
+
162
+ if (result.issues.length > 0) {
163
+ logger.log(chalk.bold("\nIssues:"));
164
+ for (const issue of result.issues) {
165
+ logger.log(` - ${chalk.yellow(issue.type)}: ${issue.details}`);
166
+ }
167
+ }
168
+
169
+ if (result.recommendations.length > 0) {
170
+ logger.log(chalk.bold("\nRecommendations:"));
171
+ for (const rec of result.recommendations) {
172
+ logger.log(` - ${rec}`);
173
+ }
174
+ }
175
+ }
176
+
177
+ await shutdown();
178
+ } catch (err) {
179
+ logger.error(`Failed: ${err.message}`);
180
+ process.exit(1);
181
+ }
182
+ });
183
+
184
+ // evolution repair <issue>
185
+ evolution
186
+ .command("repair")
187
+ .description("Self-repair a diagnosed issue")
188
+ .argument("<issue>", "Issue type (high-memory|stale-cache|degraded-model)")
189
+ .option("--json", "Output as JSON")
190
+ .action(async (issue, options) => {
191
+ try {
192
+ const ctx = await bootstrap({ verbose: program.opts().verbose });
193
+ if (!ctx.db) {
194
+ logger.error("Database not available");
195
+ process.exit(1);
196
+ }
197
+ const db = ctx.db.getDatabase();
198
+ const spinner = ora(`Repairing: ${issue}...`).start();
199
+
200
+ const result = selfRepair(db, issue);
201
+ spinner.succeed("Repair complete");
202
+
203
+ if (options.json) {
204
+ console.log(JSON.stringify(result, null, 2));
205
+ } else {
206
+ logger.log(chalk.bold(`Repaired: ${result.issue}`));
207
+ logger.log(chalk.bold("Actions taken:"));
208
+ for (const action of result.actions) {
209
+ logger.log(` - ${chalk.green(action)}`);
210
+ }
211
+ }
212
+
213
+ await shutdown();
214
+ } catch (err) {
215
+ logger.error(`Failed: ${err.message}`);
216
+ process.exit(1);
217
+ }
218
+ });
219
+
220
+ // evolution predict [user-id]
221
+ evolution
222
+ .command("predict")
223
+ .description("Predict user behavior")
224
+ .argument("[user-id]", "User ID (optional)")
225
+ .option("--json", "Output as JSON")
226
+ .action(async (userId, options) => {
227
+ try {
228
+ const ctx = await bootstrap({ verbose: program.opts().verbose });
229
+ if (!ctx.db) {
230
+ logger.error("Database not available");
231
+ process.exit(1);
232
+ }
233
+ const db = ctx.db.getDatabase();
234
+ const spinner = ora("Predicting behavior...").start();
235
+
236
+ const result = predictBehavior(db, userId);
237
+ spinner.succeed("Prediction complete");
238
+
239
+ if (options.json) {
240
+ console.log(JSON.stringify(result, null, 2));
241
+ } else {
242
+ logger.log(
243
+ chalk.bold(`Behavior Prediction (user: ${result.userId})`),
244
+ );
245
+ logger.log(` Confidence: ${chalk.cyan(result.confidence)}`);
246
+ logger.log(` Based on: ${result.basedOnEvents} events\n`);
247
+
248
+ if (result.predictions.length > 0) {
249
+ logger.log(chalk.bold(" Predicted Actions:"));
250
+ for (const p of result.predictions) {
251
+ const bar = "=".repeat(Math.round(p.probability * 20));
252
+ logger.log(
253
+ ` ${p.action.padEnd(25)} ${chalk.cyan(bar)} ${(p.probability * 100).toFixed(1)}%`,
254
+ );
255
+ }
256
+ } else {
257
+ logger.log(chalk.gray(" No predictions available yet."));
258
+ }
259
+ }
260
+
261
+ await shutdown();
262
+ } catch (err) {
263
+ logger.error(`Failed: ${err.message}`);
264
+ process.exit(1);
265
+ }
266
+ });
267
+
268
+ // evolution growth
269
+ evolution
270
+ .command("growth")
271
+ .description("Show growth log")
272
+ .option("--type <filter>", "Filter by event type")
273
+ .option("--limit <n>", "Limit entries", parseInt)
274
+ .option("--json", "Output as JSON")
275
+ .action(async (options) => {
276
+ try {
277
+ const ctx = await bootstrap({ verbose: program.opts().verbose });
278
+ if (!ctx.db) {
279
+ logger.error("Database not available");
280
+ process.exit(1);
281
+ }
282
+ const db = ctx.db.getDatabase();
283
+ const entries = getGrowthLog(db, {
284
+ type: options.type,
285
+ limit: options.limit,
286
+ });
287
+
288
+ if (options.json) {
289
+ console.log(JSON.stringify(entries, null, 2));
290
+ } else if (entries.length === 0) {
291
+ logger.info("No growth events recorded yet.");
292
+ } else {
293
+ logger.log(chalk.bold(`Growth Log (${entries.length} entries):\n`));
294
+ for (const e of entries) {
295
+ const ts = chalk.gray(e.timestamp);
296
+ const type = chalk.yellow(e.eventType);
297
+ logger.log(` ${ts} ${type}`);
298
+ logger.log(` ${e.description}`);
299
+ }
300
+ }
301
+
302
+ await shutdown();
303
+ } catch (err) {
304
+ logger.error(`Failed: ${err.message}`);
305
+ process.exit(1);
306
+ }
307
+ });
308
+
309
+ // evolution stats
310
+ evolution
311
+ .command("stats")
312
+ .description("Show capabilities and models overview")
313
+ .option("--json", "Output as JSON")
314
+ .action(async (options) => {
315
+ try {
316
+ const ctx = await bootstrap({ verbose: program.opts().verbose });
317
+ if (!ctx.db) {
318
+ logger.error("Database not available");
319
+ process.exit(1);
320
+ }
321
+ const db = ctx.db.getDatabase();
322
+ const caps = getCapabilities(db);
323
+ const mdls = getModels(db);
324
+
325
+ if (options.json) {
326
+ console.log(
327
+ JSON.stringify({ capabilities: caps, models: mdls }, null, 2),
328
+ );
329
+ } else {
330
+ logger.log(chalk.bold(`Capabilities (${caps.length}):\n`));
331
+ if (caps.length === 0) {
332
+ logger.log(chalk.gray(" No capabilities tracked yet."));
333
+ }
334
+ for (const c of caps) {
335
+ const trendColor =
336
+ c.trend === "improving"
337
+ ? chalk.green
338
+ : c.trend === "declining"
339
+ ? chalk.red
340
+ : chalk.gray;
341
+ logger.log(
342
+ ` ${chalk.cyan(c.name.padEnd(20))} score=${c.score.toFixed(2)} trend=${trendColor(c.trend)} [${c.category}]`,
343
+ );
344
+ }
345
+
346
+ logger.log(chalk.bold(`\nModels (${mdls.length}):\n`));
347
+ if (mdls.length === 0) {
348
+ logger.log(chalk.gray(" No models registered yet."));
349
+ }
350
+ for (const m of mdls) {
351
+ logger.log(
352
+ ` ${chalk.cyan(m.id.padEnd(20))} type=${m.type} accuracy=${m.accuracy.toFixed(4)} data=${m.dataPoints}`,
353
+ );
354
+ }
355
+ }
356
+
357
+ await shutdown();
358
+ } catch (err) {
359
+ logger.error(`Failed: ${err.message}`);
360
+ process.exit(1);
361
+ }
362
+ });
363
+
364
+ // evolution export <model-id>
365
+ evolution
366
+ .command("export")
367
+ .description("Export a model for portability")
368
+ .argument("<model-id>", "Model ID to export")
369
+ .option("--json", "Output as JSON")
370
+ .action(async (modelId, options) => {
371
+ try {
372
+ const ctx = await bootstrap({ verbose: program.opts().verbose });
373
+ if (!ctx.db) {
374
+ logger.error("Database not available");
375
+ process.exit(1);
376
+ }
377
+ const db = ctx.db.getDatabase();
378
+
379
+ const result = exportModel(db, modelId);
380
+
381
+ if (options.json) {
382
+ console.log(JSON.stringify(result, null, 2));
383
+ } else {
384
+ logger.log(chalk.bold(`Exported Model: ${result.name}`));
385
+ logger.log(` ID: ${result.id}`);
386
+ logger.log(` Type: ${result.type}`);
387
+ logger.log(` Accuracy: ${result.accuracy.toFixed(4)}`);
388
+ logger.log(` Data Points: ${result.dataPoints}`);
389
+ logger.log(` Exported: ${result.exportedAt}`);
390
+ }
391
+
392
+ await shutdown();
393
+ } catch (err) {
394
+ logger.error(`Failed: ${err.message}`);
395
+ process.exit(1);
396
+ }
397
+ });
398
+ }
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Knowledge export commands
3
+ * chainlesschain export markdown|site --output <dir>
4
+ */
5
+
6
+ import chalk from "chalk";
7
+ import ora from "ora";
8
+ import { resolve } from "path";
9
+ import { logger } from "../lib/logger.js";
10
+ import { bootstrap, shutdown } from "../runtime/bootstrap.js";
11
+ import { exportToMarkdown, exportToSite } from "../lib/knowledge-exporter.js";
12
+
13
+ export function registerExportCommand(program) {
14
+ const exp = program
15
+ .command("export")
16
+ .description("Export knowledge base to external formats");
17
+
18
+ // export markdown
19
+ exp
20
+ .command("markdown")
21
+ .description("Export notes as markdown files")
22
+ .requiredOption("-o, --output <dir>", "Output directory")
23
+ .option("--category <category>", "Filter by category")
24
+ .option("--tag <tag>", "Filter by tag")
25
+ .option("-n, --limit <n>", "Max notes to export")
26
+ .option("--json", "Output as JSON")
27
+ .action(async (options) => {
28
+ try {
29
+ const outputDir = resolve(options.output);
30
+ const spinner = ora("Exporting to markdown...").start();
31
+ const ctx = await bootstrap({ verbose: program.opts().verbose });
32
+ if (!ctx.db) {
33
+ spinner.fail("Database not available");
34
+ process.exit(1);
35
+ }
36
+
37
+ const db = ctx.db.getDatabase();
38
+ const exported = exportToMarkdown(db, outputDir, {
39
+ category: options.category,
40
+ tag: options.tag,
41
+ limit: options.limit ? parseInt(options.limit) : undefined,
42
+ });
43
+ spinner.stop();
44
+
45
+ if (options.json) {
46
+ console.log(
47
+ JSON.stringify(
48
+ { count: exported.length, output: outputDir, files: exported },
49
+ null,
50
+ 2,
51
+ ),
52
+ );
53
+ } else if (exported.length === 0) {
54
+ logger.info("No notes to export");
55
+ } else {
56
+ logger.success(
57
+ `Exported ${chalk.cyan(exported.length)} notes to ${chalk.gray(outputDir)}`,
58
+ );
59
+ for (const f of exported.slice(0, 10)) {
60
+ logger.log(` ${chalk.gray(f.path)}`);
61
+ }
62
+ if (exported.length > 10) {
63
+ logger.log(chalk.gray(` ... and ${exported.length - 10} more`));
64
+ }
65
+ }
66
+
67
+ await shutdown();
68
+ } catch (err) {
69
+ logger.error(`Export failed: ${err.message}`);
70
+ process.exit(1);
71
+ }
72
+ });
73
+
74
+ // export site
75
+ exp
76
+ .command("site")
77
+ .description("Export notes as a static HTML website")
78
+ .requiredOption("-o, --output <dir>", "Output directory")
79
+ .option("--title <title>", "Site title", "ChainlessChain Knowledge Base")
80
+ .option("--category <category>", "Filter by category")
81
+ .option("--tag <tag>", "Filter by tag")
82
+ .option("--json", "Output as JSON")
83
+ .action(async (options) => {
84
+ try {
85
+ const outputDir = resolve(options.output);
86
+ const spinner = ora("Generating static site...").start();
87
+ const ctx = await bootstrap({ verbose: program.opts().verbose });
88
+ if (!ctx.db) {
89
+ spinner.fail("Database not available");
90
+ process.exit(1);
91
+ }
92
+
93
+ const db = ctx.db.getDatabase();
94
+ const exported = exportToSite(db, outputDir, {
95
+ title: options.title,
96
+ category: options.category,
97
+ tag: options.tag,
98
+ });
99
+ spinner.stop();
100
+
101
+ if (options.json) {
102
+ console.log(
103
+ JSON.stringify(
104
+ { count: exported.length, output: outputDir, files: exported },
105
+ null,
106
+ 2,
107
+ ),
108
+ );
109
+ } else {
110
+ logger.success(
111
+ `Generated static site with ${chalk.cyan(exported.length)} pages`,
112
+ );
113
+ logger.log(` ${chalk.gray("Output:")} ${outputDir}`);
114
+ logger.log(
115
+ ` ${chalk.gray("Files:")} index.html, style.css, ${exported.length} note pages`,
116
+ );
117
+ }
118
+
119
+ await shutdown();
120
+ } catch (err) {
121
+ logger.error(`Export failed: ${err.message}`);
122
+ process.exit(1);
123
+ }
124
+ });
125
+ }