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,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* P2P commands
|
|
3
|
+
* chainlesschain p2p peers|send|inbox|pair|unpair|devices|status
|
|
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
|
+
registerPeer,
|
|
11
|
+
getAllPeers,
|
|
12
|
+
getOnlinePeers,
|
|
13
|
+
sendMessage,
|
|
14
|
+
getInbox,
|
|
15
|
+
markMessageRead,
|
|
16
|
+
getMessageCount,
|
|
17
|
+
pairDevice,
|
|
18
|
+
confirmPairing,
|
|
19
|
+
getPairedDevices,
|
|
20
|
+
unpairDevice,
|
|
21
|
+
generatePeerId,
|
|
22
|
+
P2PBridge,
|
|
23
|
+
} from "../lib/p2p-manager.js";
|
|
24
|
+
|
|
25
|
+
export function registerP2pCommand(program) {
|
|
26
|
+
const p2p = program
|
|
27
|
+
.command("p2p")
|
|
28
|
+
.description("Peer-to-peer messaging and device management");
|
|
29
|
+
|
|
30
|
+
// p2p status
|
|
31
|
+
p2p
|
|
32
|
+
.command("status", { isDefault: true })
|
|
33
|
+
.description("Show P2P connection status")
|
|
34
|
+
.option("--json", "Output as JSON")
|
|
35
|
+
.action(async (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 peers = getAllPeers(db);
|
|
44
|
+
const devices = getPairedDevices(db);
|
|
45
|
+
const bridge = new P2PBridge();
|
|
46
|
+
const bridgeAvailable = await bridge.checkBridge();
|
|
47
|
+
|
|
48
|
+
if (options.json) {
|
|
49
|
+
console.log(
|
|
50
|
+
JSON.stringify(
|
|
51
|
+
{ peers: peers.length, devices: devices.length, bridgeAvailable },
|
|
52
|
+
null,
|
|
53
|
+
2,
|
|
54
|
+
),
|
|
55
|
+
);
|
|
56
|
+
} else {
|
|
57
|
+
logger.log(chalk.bold("P2P Status:\n"));
|
|
58
|
+
logger.log(` ${chalk.bold("Peers:")} ${peers.length}`);
|
|
59
|
+
logger.log(` ${chalk.bold("Devices:")} ${devices.length}`);
|
|
60
|
+
logger.log(
|
|
61
|
+
` ${chalk.bold("Bridge:")} ${bridgeAvailable ? chalk.green("connected") : chalk.gray("not available")}`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
await shutdown();
|
|
66
|
+
} catch (err) {
|
|
67
|
+
logger.error(`Failed: ${err.message}`);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// p2p peers
|
|
73
|
+
p2p
|
|
74
|
+
.command("peers")
|
|
75
|
+
.description("List known peers")
|
|
76
|
+
.option("--online", "Show only online peers")
|
|
77
|
+
.option("--json", "Output as JSON")
|
|
78
|
+
.action(async (options) => {
|
|
79
|
+
try {
|
|
80
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
81
|
+
if (!ctx.db) {
|
|
82
|
+
logger.error("Database not available");
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
const db = ctx.db.getDatabase();
|
|
86
|
+
const peers = options.online ? getOnlinePeers(db) : getAllPeers(db);
|
|
87
|
+
|
|
88
|
+
if (options.json) {
|
|
89
|
+
console.log(JSON.stringify(peers, null, 2));
|
|
90
|
+
} else if (peers.length === 0) {
|
|
91
|
+
logger.info("No peers found");
|
|
92
|
+
} else {
|
|
93
|
+
logger.log(chalk.bold(`Peers (${peers.length}):\n`));
|
|
94
|
+
for (const p of peers) {
|
|
95
|
+
const status =
|
|
96
|
+
p.status === "online"
|
|
97
|
+
? chalk.green("online")
|
|
98
|
+
: chalk.gray(p.status);
|
|
99
|
+
const name = p.display_name ? ` (${p.display_name})` : "";
|
|
100
|
+
logger.log(` ${chalk.cyan(p.peer_id)}${name} [${status}]`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
await shutdown();
|
|
105
|
+
} catch (err) {
|
|
106
|
+
logger.error(`Failed: ${err.message}`);
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// p2p send
|
|
112
|
+
p2p
|
|
113
|
+
.command("send")
|
|
114
|
+
.description("Send a message to a peer")
|
|
115
|
+
.argument("<peer>", "Peer ID to send to")
|
|
116
|
+
.argument("<message>", "Message content")
|
|
117
|
+
.action(async (peer, message) => {
|
|
118
|
+
try {
|
|
119
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
120
|
+
if (!ctx.db) {
|
|
121
|
+
logger.error("Database not available");
|
|
122
|
+
process.exit(1);
|
|
123
|
+
}
|
|
124
|
+
const db = ctx.db.getDatabase();
|
|
125
|
+
const myPeerId = generatePeerId();
|
|
126
|
+
registerPeer(db, myPeerId, "CLI User", null, null, "cli");
|
|
127
|
+
const msg = sendMessage(db, myPeerId, peer, message);
|
|
128
|
+
logger.success(`Message sent (${msg.id})`);
|
|
129
|
+
await shutdown();
|
|
130
|
+
} catch (err) {
|
|
131
|
+
logger.error(`Failed: ${err.message}`);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// p2p inbox
|
|
137
|
+
p2p
|
|
138
|
+
.command("inbox")
|
|
139
|
+
.description("Show received messages")
|
|
140
|
+
.option("--unread", "Show only unread messages")
|
|
141
|
+
.option("--peer-id <id>", "Your peer ID")
|
|
142
|
+
.option("--json", "Output as JSON")
|
|
143
|
+
.action(async (options) => {
|
|
144
|
+
try {
|
|
145
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
146
|
+
if (!ctx.db) {
|
|
147
|
+
logger.error("Database not available");
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
const db = ctx.db.getDatabase();
|
|
151
|
+
const peerId = options.peerId || "cli-user";
|
|
152
|
+
const messages = getInbox(db, peerId, { unreadOnly: options.unread });
|
|
153
|
+
|
|
154
|
+
if (options.json) {
|
|
155
|
+
console.log(JSON.stringify(messages, null, 2));
|
|
156
|
+
} else if (messages.length === 0) {
|
|
157
|
+
logger.info("No messages");
|
|
158
|
+
} else {
|
|
159
|
+
logger.log(chalk.bold(`Inbox (${messages.length}):\n`));
|
|
160
|
+
for (const m of messages) {
|
|
161
|
+
const read = m.read ? chalk.gray("[read]") : chalk.yellow("[new]");
|
|
162
|
+
logger.log(` ${read} ${chalk.cyan(m.from_peer)}: ${m.content}`);
|
|
163
|
+
logger.log(` ${chalk.gray(m.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
|
+
// p2p pair
|
|
175
|
+
p2p
|
|
176
|
+
.command("pair")
|
|
177
|
+
.description("Pair a new device")
|
|
178
|
+
.argument("<device-name>", "Device name")
|
|
179
|
+
.option("--type <type>", "Device type (desktop/mobile/tablet)", "unknown")
|
|
180
|
+
.action(async (deviceName, options) => {
|
|
181
|
+
try {
|
|
182
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
183
|
+
if (!ctx.db) {
|
|
184
|
+
logger.error("Database not available");
|
|
185
|
+
process.exit(1);
|
|
186
|
+
}
|
|
187
|
+
const db = ctx.db.getDatabase();
|
|
188
|
+
const device = pairDevice(db, deviceName, options.type);
|
|
189
|
+
|
|
190
|
+
logger.success("Device pairing initiated");
|
|
191
|
+
logger.log(
|
|
192
|
+
` ${chalk.bold("Device ID:")} ${chalk.cyan(device.deviceId)}`,
|
|
193
|
+
);
|
|
194
|
+
logger.log(
|
|
195
|
+
` ${chalk.bold("Pairing Code:")} ${chalk.yellow(device.pairingCode)}`,
|
|
196
|
+
);
|
|
197
|
+
logger.log(
|
|
198
|
+
`\n Enter this code on the other device to complete pairing.`,
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
await shutdown();
|
|
202
|
+
} catch (err) {
|
|
203
|
+
logger.error(`Failed: ${err.message}`);
|
|
204
|
+
process.exit(1);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
// p2p devices
|
|
209
|
+
p2p
|
|
210
|
+
.command("devices")
|
|
211
|
+
.description("List paired devices")
|
|
212
|
+
.option("--json", "Output as JSON")
|
|
213
|
+
.action(async (options) => {
|
|
214
|
+
try {
|
|
215
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
216
|
+
if (!ctx.db) {
|
|
217
|
+
logger.error("Database not available");
|
|
218
|
+
process.exit(1);
|
|
219
|
+
}
|
|
220
|
+
const db = ctx.db.getDatabase();
|
|
221
|
+
const devices = getPairedDevices(db);
|
|
222
|
+
|
|
223
|
+
if (options.json) {
|
|
224
|
+
console.log(JSON.stringify(devices, null, 2));
|
|
225
|
+
} else if (devices.length === 0) {
|
|
226
|
+
logger.info("No paired devices");
|
|
227
|
+
} else {
|
|
228
|
+
logger.log(chalk.bold(`Paired Devices (${devices.length}):\n`));
|
|
229
|
+
for (const d of devices) {
|
|
230
|
+
const status =
|
|
231
|
+
d.status === "active"
|
|
232
|
+
? chalk.green("active")
|
|
233
|
+
: chalk.gray(d.status);
|
|
234
|
+
logger.log(
|
|
235
|
+
` ${chalk.cyan(d.device_id)} - ${d.device_name} [${status}]`,
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
await shutdown();
|
|
241
|
+
} catch (err) {
|
|
242
|
+
logger.error(`Failed: ${err.message}`);
|
|
243
|
+
process.exit(1);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
// p2p unpair
|
|
248
|
+
p2p
|
|
249
|
+
.command("unpair")
|
|
250
|
+
.description("Unpair a device")
|
|
251
|
+
.argument("<device-id>", "Device ID to unpair")
|
|
252
|
+
.action(async (deviceId) => {
|
|
253
|
+
try {
|
|
254
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
255
|
+
if (!ctx.db) {
|
|
256
|
+
logger.error("Database not available");
|
|
257
|
+
process.exit(1);
|
|
258
|
+
}
|
|
259
|
+
const db = ctx.db.getDatabase();
|
|
260
|
+
const ok = unpairDevice(db, deviceId);
|
|
261
|
+
|
|
262
|
+
if (ok) {
|
|
263
|
+
logger.success("Device unpaired");
|
|
264
|
+
} else {
|
|
265
|
+
logger.error(`Device not found: ${deviceId}`);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
await shutdown();
|
|
269
|
+
} catch (err) {
|
|
270
|
+
logger.error(`Failed: ${err.message}`);
|
|
271
|
+
process.exit(1);
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}
|