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.
- package/README.md +309 -19
- package/bin/chainlesschain.js +4 -0
- package/package.json +1 -1
- package/src/commands/a2a.js +374 -0
- package/src/commands/audit.js +286 -0
- package/src/commands/auth.js +387 -0
- package/src/commands/bi.js +240 -0
- package/src/commands/browse.js +184 -0
- package/src/commands/cowork.js +317 -0
- package/src/commands/did.js +376 -0
- package/src/commands/economy.js +375 -0
- package/src/commands/encrypt.js +233 -0
- package/src/commands/evolution.js +398 -0
- package/src/commands/export.js +125 -0
- package/src/commands/git.js +215 -0
- package/src/commands/hmemory.js +273 -0
- package/src/commands/hook.js +260 -0
- package/src/commands/import.js +259 -0
- package/src/commands/init.js +184 -0
- package/src/commands/instinct.js +202 -0
- package/src/commands/llm.js +155 -4
- package/src/commands/lowcode.js +320 -0
- package/src/commands/mcp.js +302 -0
- package/src/commands/memory.js +282 -0
- package/src/commands/note.js +187 -0
- package/src/commands/org.js +505 -0
- package/src/commands/p2p.js +274 -0
- package/src/commands/plugin.js +451 -0
- package/src/commands/sandbox.js +366 -0
- package/src/commands/search.js +237 -0
- package/src/commands/session.js +238 -0
- package/src/commands/skill.js +254 -201
- package/src/commands/sync.js +249 -0
- package/src/commands/tokens.js +214 -0
- package/src/commands/wallet.js +416 -0
- package/src/commands/workflow.js +359 -0
- package/src/commands/zkp.js +277 -0
- package/src/index.js +93 -1
- package/src/lib/a2a-protocol.js +371 -0
- package/src/lib/agent-coordinator.js +273 -0
- package/src/lib/agent-economy.js +369 -0
- package/src/lib/app-builder.js +377 -0
- package/src/lib/audit-logger.js +364 -0
- package/src/lib/bi-engine.js +299 -0
- package/src/lib/bm25-search.js +322 -0
- package/src/lib/browser-automation.js +216 -0
- package/src/lib/cowork/ab-comparator-cli.js +180 -0
- package/src/lib/cowork/code-knowledge-graph-cli.js +232 -0
- package/src/lib/cowork/debate-review-cli.js +144 -0
- package/src/lib/cowork/decision-kb-cli.js +153 -0
- package/src/lib/cowork/project-style-analyzer-cli.js +168 -0
- package/src/lib/cowork-adapter.js +106 -0
- package/src/lib/crypto-manager.js +246 -0
- package/src/lib/did-manager.js +270 -0
- package/src/lib/ensure-utf8.js +59 -0
- package/src/lib/evolution-system.js +508 -0
- package/src/lib/git-integration.js +220 -0
- package/src/lib/hierarchical-memory.js +471 -0
- package/src/lib/hook-manager.js +387 -0
- package/src/lib/instinct-manager.js +190 -0
- package/src/lib/knowledge-exporter.js +302 -0
- package/src/lib/knowledge-importer.js +293 -0
- package/src/lib/llm-providers.js +325 -0
- package/src/lib/mcp-client.js +413 -0
- package/src/lib/memory-manager.js +211 -0
- package/src/lib/note-versioning.js +244 -0
- package/src/lib/org-manager.js +424 -0
- package/src/lib/p2p-manager.js +317 -0
- package/src/lib/pdf-parser.js +96 -0
- package/src/lib/permission-engine.js +374 -0
- package/src/lib/plan-mode.js +333 -0
- package/src/lib/plugin-manager.js +430 -0
- package/src/lib/project-detector.js +53 -0
- package/src/lib/response-cache.js +156 -0
- package/src/lib/sandbox-v2.js +503 -0
- package/src/lib/service-container.js +183 -0
- package/src/lib/session-manager.js +189 -0
- package/src/lib/skill-loader.js +274 -0
- package/src/lib/sync-manager.js +347 -0
- package/src/lib/token-tracker.js +200 -0
- package/src/lib/wallet-manager.js +348 -0
- package/src/lib/workflow-engine.js +503 -0
- package/src/lib/zkp-engine.js +241 -0
- package/src/repl/agent-repl.js +259 -124
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DID management commands
|
|
3
|
+
* chainlesschain did create|show|list|resolve|sign|verify|export|delete|set-default
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import chalk from "chalk";
|
|
7
|
+
import { logger } from "../lib/logger.js";
|
|
8
|
+
import { bootstrap, shutdown } from "../runtime/bootstrap.js";
|
|
9
|
+
import {
|
|
10
|
+
createIdentity,
|
|
11
|
+
getIdentity,
|
|
12
|
+
getAllIdentities,
|
|
13
|
+
setDefaultIdentity,
|
|
14
|
+
deleteIdentity,
|
|
15
|
+
signMessage,
|
|
16
|
+
verifyWithDID,
|
|
17
|
+
exportIdentity,
|
|
18
|
+
resolveDID,
|
|
19
|
+
} from "../lib/did-manager.js";
|
|
20
|
+
|
|
21
|
+
export function registerDidCommand(program) {
|
|
22
|
+
const did = program
|
|
23
|
+
.command("did")
|
|
24
|
+
.description("Decentralized Identity (DID) management");
|
|
25
|
+
|
|
26
|
+
// did create
|
|
27
|
+
did
|
|
28
|
+
.command("create")
|
|
29
|
+
.description("Create a new DID identity")
|
|
30
|
+
.option("--name <name>", "Display name for the identity")
|
|
31
|
+
.option("--json", "Output as JSON")
|
|
32
|
+
.action(async (options) => {
|
|
33
|
+
try {
|
|
34
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
35
|
+
if (!ctx.db) {
|
|
36
|
+
logger.error("Database not available");
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
const db = ctx.db.getDatabase();
|
|
40
|
+
const identity = createIdentity(db, options.name);
|
|
41
|
+
|
|
42
|
+
if (options.json) {
|
|
43
|
+
console.log(JSON.stringify(identity, null, 2));
|
|
44
|
+
} else {
|
|
45
|
+
logger.success("DID identity created");
|
|
46
|
+
logger.log(` ${chalk.bold("DID:")} ${chalk.cyan(identity.did)}`);
|
|
47
|
+
if (identity.displayName) {
|
|
48
|
+
logger.log(` ${chalk.bold("Name:")} ${identity.displayName}`);
|
|
49
|
+
}
|
|
50
|
+
logger.log(
|
|
51
|
+
` ${chalk.bold("Default:")} ${identity.isDefault ? chalk.green("yes") : "no"}`,
|
|
52
|
+
);
|
|
53
|
+
logger.log(
|
|
54
|
+
` ${chalk.bold("PubKey:")} ${chalk.gray(identity.publicKey.slice(0, 40))}...`,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
await shutdown();
|
|
59
|
+
} catch (err) {
|
|
60
|
+
logger.error(`Failed: ${err.message}`);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// did show
|
|
66
|
+
did
|
|
67
|
+
.command("show")
|
|
68
|
+
.description("Show a specific DID identity")
|
|
69
|
+
.argument("<did>", "DID or prefix")
|
|
70
|
+
.option("--json", "Output as JSON")
|
|
71
|
+
.action(async (didArg, options) => {
|
|
72
|
+
try {
|
|
73
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
74
|
+
if (!ctx.db) {
|
|
75
|
+
logger.error("Database not available");
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
const db = ctx.db.getDatabase();
|
|
79
|
+
const identity = getIdentity(db, didArg);
|
|
80
|
+
|
|
81
|
+
if (!identity) {
|
|
82
|
+
logger.error(`Identity not found: ${didArg}`);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (options.json) {
|
|
87
|
+
console.log(
|
|
88
|
+
JSON.stringify(
|
|
89
|
+
{
|
|
90
|
+
did: identity.did,
|
|
91
|
+
displayName: identity.display_name,
|
|
92
|
+
publicKey: identity.public_key,
|
|
93
|
+
isDefault: identity.is_default === 1,
|
|
94
|
+
document: JSON.parse(identity.did_document || "{}"),
|
|
95
|
+
createdAt: identity.created_at,
|
|
96
|
+
},
|
|
97
|
+
null,
|
|
98
|
+
2,
|
|
99
|
+
),
|
|
100
|
+
);
|
|
101
|
+
} else {
|
|
102
|
+
logger.log(chalk.bold("DID Identity:\n"));
|
|
103
|
+
logger.log(
|
|
104
|
+
` ${chalk.bold("DID:")} ${chalk.cyan(identity.did)}`,
|
|
105
|
+
);
|
|
106
|
+
logger.log(
|
|
107
|
+
` ${chalk.bold("Name:")} ${identity.display_name || chalk.gray("(none)")}`,
|
|
108
|
+
);
|
|
109
|
+
logger.log(
|
|
110
|
+
` ${chalk.bold("Default:")} ${identity.is_default ? chalk.green("yes") : "no"}`,
|
|
111
|
+
);
|
|
112
|
+
logger.log(
|
|
113
|
+
` ${chalk.bold("PubKey:")} ${chalk.gray(identity.public_key)}`,
|
|
114
|
+
);
|
|
115
|
+
logger.log(` ${chalk.bold("Created:")} ${identity.created_at}`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
await shutdown();
|
|
119
|
+
} catch (err) {
|
|
120
|
+
logger.error(`Failed: ${err.message}`);
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// did list
|
|
126
|
+
did
|
|
127
|
+
.command("list", { isDefault: true })
|
|
128
|
+
.description("List all DID identities")
|
|
129
|
+
.option("--json", "Output as JSON")
|
|
130
|
+
.action(async (options) => {
|
|
131
|
+
try {
|
|
132
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
133
|
+
if (!ctx.db) {
|
|
134
|
+
logger.error("Database not available");
|
|
135
|
+
process.exit(1);
|
|
136
|
+
}
|
|
137
|
+
const db = ctx.db.getDatabase();
|
|
138
|
+
const identities = getAllIdentities(db);
|
|
139
|
+
|
|
140
|
+
if (options.json) {
|
|
141
|
+
console.log(
|
|
142
|
+
JSON.stringify(
|
|
143
|
+
identities.map((i) => ({
|
|
144
|
+
did: i.did,
|
|
145
|
+
displayName: i.display_name,
|
|
146
|
+
isDefault: i.is_default === 1,
|
|
147
|
+
createdAt: i.created_at,
|
|
148
|
+
})),
|
|
149
|
+
null,
|
|
150
|
+
2,
|
|
151
|
+
),
|
|
152
|
+
);
|
|
153
|
+
} else if (identities.length === 0) {
|
|
154
|
+
logger.info(
|
|
155
|
+
'No DID identities. Create one with "chainlesschain did create"',
|
|
156
|
+
);
|
|
157
|
+
} else {
|
|
158
|
+
logger.log(chalk.bold(`DID Identities (${identities.length}):\n`));
|
|
159
|
+
for (const id of identities) {
|
|
160
|
+
const def = id.is_default ? chalk.green(" [default]") : "";
|
|
161
|
+
const name = id.display_name ? ` (${id.display_name})` : "";
|
|
162
|
+
logger.log(` ${chalk.cyan(id.did)}${name}${def}`);
|
|
163
|
+
logger.log(` ${chalk.gray(`created: ${id.created_at}`)}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
await shutdown();
|
|
168
|
+
} catch (err) {
|
|
169
|
+
logger.error(`Failed: ${err.message}`);
|
|
170
|
+
process.exit(1);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// did resolve
|
|
175
|
+
did
|
|
176
|
+
.command("resolve")
|
|
177
|
+
.description("Resolve a DID to its DID Document")
|
|
178
|
+
.argument("<did>", "DID to resolve")
|
|
179
|
+
.action(async (didArg) => {
|
|
180
|
+
try {
|
|
181
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
182
|
+
if (!ctx.db) {
|
|
183
|
+
logger.error("Database not available");
|
|
184
|
+
process.exit(1);
|
|
185
|
+
}
|
|
186
|
+
const db = ctx.db.getDatabase();
|
|
187
|
+
const doc = resolveDID(db, didArg);
|
|
188
|
+
|
|
189
|
+
if (!doc) {
|
|
190
|
+
logger.error(`DID not found: ${didArg}`);
|
|
191
|
+
process.exit(1);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
console.log(JSON.stringify(doc, null, 2));
|
|
195
|
+
await shutdown();
|
|
196
|
+
} catch (err) {
|
|
197
|
+
logger.error(`Failed: ${err.message}`);
|
|
198
|
+
process.exit(1);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// did sign
|
|
203
|
+
did
|
|
204
|
+
.command("sign")
|
|
205
|
+
.description("Sign a message with a DID identity")
|
|
206
|
+
.argument("<message>", "Message to sign")
|
|
207
|
+
.option("--did <did>", "DID to sign with (default: default identity)")
|
|
208
|
+
.option("--json", "Output as JSON")
|
|
209
|
+
.action(async (message, options) => {
|
|
210
|
+
try {
|
|
211
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
212
|
+
if (!ctx.db) {
|
|
213
|
+
logger.error("Database not available");
|
|
214
|
+
process.exit(1);
|
|
215
|
+
}
|
|
216
|
+
const db = ctx.db.getDatabase();
|
|
217
|
+
|
|
218
|
+
const didStr =
|
|
219
|
+
options.did ||
|
|
220
|
+
(() => {
|
|
221
|
+
const def = getIdentity(db, "did:chainless:");
|
|
222
|
+
if (!def) throw new Error("No identities found. Create one first.");
|
|
223
|
+
return def.did;
|
|
224
|
+
})();
|
|
225
|
+
|
|
226
|
+
const signature = signMessage(db, didStr, message);
|
|
227
|
+
|
|
228
|
+
if (options.json) {
|
|
229
|
+
console.log(
|
|
230
|
+
JSON.stringify({ did: didStr, message, signature }, null, 2),
|
|
231
|
+
);
|
|
232
|
+
} else {
|
|
233
|
+
logger.success("Message signed");
|
|
234
|
+
logger.log(` ${chalk.bold("Signature:")} ${chalk.gray(signature)}`);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
await shutdown();
|
|
238
|
+
} catch (err) {
|
|
239
|
+
logger.error(`Failed: ${err.message}`);
|
|
240
|
+
process.exit(1);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
// did verify
|
|
245
|
+
did
|
|
246
|
+
.command("verify")
|
|
247
|
+
.description("Verify a signed message")
|
|
248
|
+
.argument("<message>", "Original message")
|
|
249
|
+
.argument("<signature>", "Signature to verify (hex)")
|
|
250
|
+
.option("--did <did>", "DID that signed the message")
|
|
251
|
+
.action(async (message, signature, options) => {
|
|
252
|
+
try {
|
|
253
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
254
|
+
if (!ctx.db) {
|
|
255
|
+
logger.error("Database not available");
|
|
256
|
+
process.exit(1);
|
|
257
|
+
}
|
|
258
|
+
const db = ctx.db.getDatabase();
|
|
259
|
+
|
|
260
|
+
if (!options.did) {
|
|
261
|
+
logger.error("--did is required for verification");
|
|
262
|
+
process.exit(1);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const valid = verifyWithDID(db, options.did, message, signature);
|
|
266
|
+
if (valid) {
|
|
267
|
+
logger.success("Signature is VALID");
|
|
268
|
+
} else {
|
|
269
|
+
logger.error("Signature is INVALID");
|
|
270
|
+
process.exit(1);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
await shutdown();
|
|
274
|
+
} catch (err) {
|
|
275
|
+
logger.error(`Failed: ${err.message}`);
|
|
276
|
+
process.exit(1);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// did export
|
|
281
|
+
did
|
|
282
|
+
.command("export")
|
|
283
|
+
.description("Export DID identity (public data only)")
|
|
284
|
+
.argument("<did>", "DID to export")
|
|
285
|
+
.action(async (didArg) => {
|
|
286
|
+
try {
|
|
287
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
288
|
+
if (!ctx.db) {
|
|
289
|
+
logger.error("Database not available");
|
|
290
|
+
process.exit(1);
|
|
291
|
+
}
|
|
292
|
+
const db = ctx.db.getDatabase();
|
|
293
|
+
const exported = exportIdentity(db, didArg);
|
|
294
|
+
|
|
295
|
+
if (!exported) {
|
|
296
|
+
logger.error(`Identity not found: ${didArg}`);
|
|
297
|
+
process.exit(1);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
console.log(JSON.stringify(exported, null, 2));
|
|
301
|
+
await shutdown();
|
|
302
|
+
} catch (err) {
|
|
303
|
+
logger.error(`Failed: ${err.message}`);
|
|
304
|
+
process.exit(1);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
// did set-default
|
|
309
|
+
did
|
|
310
|
+
.command("set-default")
|
|
311
|
+
.description("Set a DID as the default identity")
|
|
312
|
+
.argument("<did>", "DID to set as default")
|
|
313
|
+
.action(async (didArg) => {
|
|
314
|
+
try {
|
|
315
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
316
|
+
if (!ctx.db) {
|
|
317
|
+
logger.error("Database not available");
|
|
318
|
+
process.exit(1);
|
|
319
|
+
}
|
|
320
|
+
const db = ctx.db.getDatabase();
|
|
321
|
+
const ok = setDefaultIdentity(db, didArg);
|
|
322
|
+
|
|
323
|
+
if (ok) {
|
|
324
|
+
logger.success("Default identity updated");
|
|
325
|
+
} else {
|
|
326
|
+
logger.error(`Identity not found: ${didArg}`);
|
|
327
|
+
process.exit(1);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
await shutdown();
|
|
331
|
+
} catch (err) {
|
|
332
|
+
logger.error(`Failed: ${err.message}`);
|
|
333
|
+
process.exit(1);
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
// did delete
|
|
338
|
+
did
|
|
339
|
+
.command("delete")
|
|
340
|
+
.description("Delete a DID identity")
|
|
341
|
+
.argument("<did>", "DID to delete")
|
|
342
|
+
.option("--force", "Skip confirmation")
|
|
343
|
+
.action(async (didArg, options) => {
|
|
344
|
+
try {
|
|
345
|
+
if (!options.force) {
|
|
346
|
+
const { confirm } = await import("@inquirer/prompts");
|
|
347
|
+
const ok = await confirm({
|
|
348
|
+
message: "Delete this DID identity? The secret key will be lost.",
|
|
349
|
+
});
|
|
350
|
+
if (!ok) {
|
|
351
|
+
logger.info("Cancelled");
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
357
|
+
if (!ctx.db) {
|
|
358
|
+
logger.error("Database not available");
|
|
359
|
+
process.exit(1);
|
|
360
|
+
}
|
|
361
|
+
const db = ctx.db.getDatabase();
|
|
362
|
+
const ok = deleteIdentity(db, didArg);
|
|
363
|
+
|
|
364
|
+
if (ok) {
|
|
365
|
+
logger.success("Identity deleted");
|
|
366
|
+
} else {
|
|
367
|
+
logger.error(`Identity not found: ${didArg}`);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
await shutdown();
|
|
371
|
+
} catch (err) {
|
|
372
|
+
logger.error(`Failed: ${err.message}`);
|
|
373
|
+
process.exit(1);
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
}
|