chainlesschain 0.37.10 → 0.37.12
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 +166 -10
- package/package.json +1 -1
- package/src/commands/a2a.js +374 -0
- package/src/commands/bi.js +240 -0
- package/src/commands/cowork.js +317 -0
- package/src/commands/economy.js +375 -0
- package/src/commands/evolution.js +398 -0
- package/src/commands/hmemory.js +273 -0
- package/src/commands/hook.js +260 -0
- package/src/commands/init.js +184 -0
- package/src/commands/lowcode.js +320 -0
- package/src/commands/plugin.js +55 -2
- package/src/commands/sandbox.js +366 -0
- package/src/commands/skill.js +254 -201
- package/src/commands/workflow.js +359 -0
- package/src/commands/zkp.js +277 -0
- package/src/index.js +44 -0
- 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/bi-engine.js +299 -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/evolution-system.js +508 -0
- package/src/lib/hierarchical-memory.js +471 -0
- package/src/lib/hook-manager.js +387 -0
- package/src/lib/plugin-manager.js +118 -0
- package/src/lib/project-detector.js +53 -0
- package/src/lib/sandbox-v2.js +503 -0
- package/src/lib/service-container.js +183 -0
- package/src/lib/skill-loader.js +274 -0
- package/src/lib/workflow-engine.js +503 -0
- package/src/lib/zkp-engine.js +241 -0
- package/src/repl/agent-repl.js +117 -112
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Economy commands
|
|
3
|
+
* chainlesschain economy price|pay|balance|channel|market|trade|nft|revenue|contribute
|
|
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
|
+
ensureEconomyTables,
|
|
11
|
+
priceService,
|
|
12
|
+
getServicePrice,
|
|
13
|
+
pay,
|
|
14
|
+
getBalance,
|
|
15
|
+
openChannel,
|
|
16
|
+
closeChannel,
|
|
17
|
+
listResource,
|
|
18
|
+
getMarketListings,
|
|
19
|
+
tradeResource,
|
|
20
|
+
mintNFT,
|
|
21
|
+
recordContribution,
|
|
22
|
+
getContributions,
|
|
23
|
+
distributeRevenue,
|
|
24
|
+
} from "../lib/agent-economy.js";
|
|
25
|
+
|
|
26
|
+
export function registerEconomyCommand(program) {
|
|
27
|
+
const economy = program
|
|
28
|
+
.command("economy")
|
|
29
|
+
.description("Agent economy — payments, channels, marketplace, NFTs");
|
|
30
|
+
|
|
31
|
+
// economy price
|
|
32
|
+
economy
|
|
33
|
+
.command("price <service-id> <price>")
|
|
34
|
+
.description("Set a service price")
|
|
35
|
+
.action(async (serviceId, price) => {
|
|
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
|
+
ensureEconomyTables(db);
|
|
44
|
+
|
|
45
|
+
const result = priceService(db, serviceId, parseFloat(price), {});
|
|
46
|
+
logger.success(
|
|
47
|
+
`Price set for ${chalk.cyan(serviceId)}: ${chalk.bold(result.price)}`,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
await shutdown();
|
|
51
|
+
} catch (err) {
|
|
52
|
+
logger.error(`Failed: ${err.message}`);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// economy pay
|
|
58
|
+
economy
|
|
59
|
+
.command("pay <from> <to> <amount>")
|
|
60
|
+
.description("Make a payment between agents")
|
|
61
|
+
.option("--description <text>", "Payment description")
|
|
62
|
+
.action(async (from, to, amount, options) => {
|
|
63
|
+
try {
|
|
64
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
65
|
+
if (!ctx.db) {
|
|
66
|
+
logger.error("Database not available");
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
const db = ctx.db.getDatabase();
|
|
70
|
+
ensureEconomyTables(db);
|
|
71
|
+
|
|
72
|
+
const result = pay(
|
|
73
|
+
db,
|
|
74
|
+
from,
|
|
75
|
+
to,
|
|
76
|
+
parseFloat(amount),
|
|
77
|
+
options.description,
|
|
78
|
+
);
|
|
79
|
+
logger.success("Payment complete");
|
|
80
|
+
logger.log(` ${chalk.bold("Tx ID:")} ${chalk.cyan(result.txId)}`);
|
|
81
|
+
logger.log(` ${chalk.bold("From:")} ${result.from}`);
|
|
82
|
+
logger.log(` ${chalk.bold("To:")} ${result.to}`);
|
|
83
|
+
logger.log(` ${chalk.bold("Amount:")} ${result.amount}`);
|
|
84
|
+
logger.log(` ${chalk.bold("Balance:")} ${result.balance}`);
|
|
85
|
+
|
|
86
|
+
await shutdown();
|
|
87
|
+
} catch (err) {
|
|
88
|
+
logger.error(`Failed: ${err.message}`);
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// economy balance
|
|
94
|
+
economy
|
|
95
|
+
.command("balance <agent-id>")
|
|
96
|
+
.description("Show agent balance")
|
|
97
|
+
.option("--json", "Output as JSON")
|
|
98
|
+
.action(async (agentId, options) => {
|
|
99
|
+
try {
|
|
100
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
101
|
+
if (!ctx.db) {
|
|
102
|
+
logger.error("Database not available");
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
const db = ctx.db.getDatabase();
|
|
106
|
+
ensureEconomyTables(db);
|
|
107
|
+
|
|
108
|
+
const bal = getBalance(agentId);
|
|
109
|
+
if (options.json) {
|
|
110
|
+
console.log(JSON.stringify({ agentId, ...bal }, null, 2));
|
|
111
|
+
} else {
|
|
112
|
+
logger.log(` ${chalk.bold("Agent:")} ${chalk.cyan(agentId)}`);
|
|
113
|
+
logger.log(` ${chalk.bold("Balance:")} ${bal.balance}`);
|
|
114
|
+
logger.log(` ${chalk.bold("Locked:")} ${bal.locked}`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
await shutdown();
|
|
118
|
+
} catch (err) {
|
|
119
|
+
logger.error(`Failed: ${err.message}`);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// economy channel open / close
|
|
125
|
+
const channel = economy
|
|
126
|
+
.command("channel")
|
|
127
|
+
.description("State channel management");
|
|
128
|
+
|
|
129
|
+
channel
|
|
130
|
+
.command("open <party-a> <party-b>")
|
|
131
|
+
.description("Open a state channel")
|
|
132
|
+
.option("--deposit <amount>", "Initial deposit from party A", "0")
|
|
133
|
+
.action(async (partyA, partyB, 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
|
+
ensureEconomyTables(db);
|
|
142
|
+
|
|
143
|
+
const ch = openChannel(db, partyA, partyB, parseFloat(options.deposit));
|
|
144
|
+
logger.success("Channel opened");
|
|
145
|
+
logger.log(` ${chalk.bold("ID:")} ${chalk.cyan(ch.id)}`);
|
|
146
|
+
logger.log(` ${chalk.bold("Party A:")} ${ch.partyA} (${ch.balanceA})`);
|
|
147
|
+
logger.log(` ${chalk.bold("Party B:")} ${ch.partyB} (${ch.balanceB})`);
|
|
148
|
+
|
|
149
|
+
await shutdown();
|
|
150
|
+
} catch (err) {
|
|
151
|
+
logger.error(`Failed: ${err.message}`);
|
|
152
|
+
process.exit(1);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
channel
|
|
157
|
+
.command("close <channel-id>")
|
|
158
|
+
.description("Close and settle a state channel")
|
|
159
|
+
.action(async (channelId) => {
|
|
160
|
+
try {
|
|
161
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
162
|
+
if (!ctx.db) {
|
|
163
|
+
logger.error("Database not available");
|
|
164
|
+
process.exit(1);
|
|
165
|
+
}
|
|
166
|
+
const db = ctx.db.getDatabase();
|
|
167
|
+
ensureEconomyTables(db);
|
|
168
|
+
|
|
169
|
+
const ch = closeChannel(db, channelId);
|
|
170
|
+
logger.success("Channel closed and settled");
|
|
171
|
+
logger.log(` ${chalk.bold("ID:")} ${chalk.cyan(ch.id)}`);
|
|
172
|
+
logger.log(` ${chalk.bold("Status:")} ${ch.status}`);
|
|
173
|
+
|
|
174
|
+
await shutdown();
|
|
175
|
+
} catch (err) {
|
|
176
|
+
logger.error(`Failed: ${err.message}`);
|
|
177
|
+
process.exit(1);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// economy market list / browse
|
|
182
|
+
const market = economy.command("market").description("Resource marketplace");
|
|
183
|
+
|
|
184
|
+
market
|
|
185
|
+
.command("list <type> <provider> <price> <amount>")
|
|
186
|
+
.description("List a resource on the marketplace")
|
|
187
|
+
.action(async (type, provider, price, amount) => {
|
|
188
|
+
try {
|
|
189
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
190
|
+
if (!ctx.db) {
|
|
191
|
+
logger.error("Database not available");
|
|
192
|
+
process.exit(1);
|
|
193
|
+
}
|
|
194
|
+
const db = ctx.db.getDatabase();
|
|
195
|
+
ensureEconomyTables(db);
|
|
196
|
+
|
|
197
|
+
const listing = listResource(
|
|
198
|
+
db,
|
|
199
|
+
type,
|
|
200
|
+
provider,
|
|
201
|
+
parseFloat(price),
|
|
202
|
+
parseFloat(amount),
|
|
203
|
+
"unit",
|
|
204
|
+
);
|
|
205
|
+
logger.success("Resource listed");
|
|
206
|
+
logger.log(` ${chalk.bold("ID:")} ${chalk.cyan(listing.id)}`);
|
|
207
|
+
logger.log(` ${chalk.bold("Type:")} ${listing.resourceType}`);
|
|
208
|
+
logger.log(` ${chalk.bold("Provider:")} ${listing.provider}`);
|
|
209
|
+
logger.log(` ${chalk.bold("Price:")} ${listing.price}`);
|
|
210
|
+
logger.log(` ${chalk.bold("Available:")} ${listing.available}`);
|
|
211
|
+
|
|
212
|
+
await shutdown();
|
|
213
|
+
} catch (err) {
|
|
214
|
+
logger.error(`Failed: ${err.message}`);
|
|
215
|
+
process.exit(1);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
market
|
|
220
|
+
.command("browse")
|
|
221
|
+
.description("Browse marketplace listings")
|
|
222
|
+
.option("--type <filter>", "Filter by resource type")
|
|
223
|
+
.option("--json", "Output as JSON")
|
|
224
|
+
.action(async (options) => {
|
|
225
|
+
try {
|
|
226
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
227
|
+
if (!ctx.db) {
|
|
228
|
+
logger.error("Database not available");
|
|
229
|
+
process.exit(1);
|
|
230
|
+
}
|
|
231
|
+
const db = ctx.db.getDatabase();
|
|
232
|
+
ensureEconomyTables(db);
|
|
233
|
+
|
|
234
|
+
const filter = options.type ? { type: options.type } : undefined;
|
|
235
|
+
const listings = getMarketListings(filter);
|
|
236
|
+
|
|
237
|
+
if (options.json) {
|
|
238
|
+
console.log(JSON.stringify(listings, null, 2));
|
|
239
|
+
} else {
|
|
240
|
+
if (listings.length === 0) {
|
|
241
|
+
logger.log("No active listings");
|
|
242
|
+
} else {
|
|
243
|
+
for (const l of listings) {
|
|
244
|
+
logger.log(
|
|
245
|
+
` ${chalk.cyan(l.id.slice(0, 8))} ${l.resourceType} by ${l.provider} — ${l.price}/${l.unit} (${l.available} avail)`,
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
await shutdown();
|
|
252
|
+
} catch (err) {
|
|
253
|
+
logger.error(`Failed: ${err.message}`);
|
|
254
|
+
process.exit(1);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// economy trade
|
|
259
|
+
economy
|
|
260
|
+
.command("trade <listing-id> <buyer> <quantity>")
|
|
261
|
+
.description("Buy a resource from the marketplace")
|
|
262
|
+
.action(async (listingId, buyer, quantity) => {
|
|
263
|
+
try {
|
|
264
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
265
|
+
if (!ctx.db) {
|
|
266
|
+
logger.error("Database not available");
|
|
267
|
+
process.exit(1);
|
|
268
|
+
}
|
|
269
|
+
const db = ctx.db.getDatabase();
|
|
270
|
+
ensureEconomyTables(db);
|
|
271
|
+
|
|
272
|
+
const result = tradeResource(listingId, buyer, parseFloat(quantity));
|
|
273
|
+
logger.success("Trade complete");
|
|
274
|
+
logger.log(` ${chalk.bold("Cost:")} ${result.cost}`);
|
|
275
|
+
logger.log(` ${chalk.bold("Quantity:")} ${result.quantity}`);
|
|
276
|
+
logger.log(` ${chalk.bold("Remaining:")} ${result.remaining}`);
|
|
277
|
+
|
|
278
|
+
await shutdown();
|
|
279
|
+
} catch (err) {
|
|
280
|
+
logger.error(`Failed: ${err.message}`);
|
|
281
|
+
process.exit(1);
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
// economy nft mint
|
|
286
|
+
const nft = economy.command("nft").description("NFT management");
|
|
287
|
+
|
|
288
|
+
nft
|
|
289
|
+
.command("mint <owner> <type>")
|
|
290
|
+
.description("Mint a new NFT")
|
|
291
|
+
.option("--metadata <json>", "NFT metadata as JSON")
|
|
292
|
+
.action(async (owner, type, options) => {
|
|
293
|
+
try {
|
|
294
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
295
|
+
if (!ctx.db) {
|
|
296
|
+
logger.error("Database not available");
|
|
297
|
+
process.exit(1);
|
|
298
|
+
}
|
|
299
|
+
const db = ctx.db.getDatabase();
|
|
300
|
+
ensureEconomyTables(db);
|
|
301
|
+
|
|
302
|
+
const metadata = options.metadata ? JSON.parse(options.metadata) : {};
|
|
303
|
+
const nftObj = mintNFT(db, owner, type, metadata);
|
|
304
|
+
logger.success("NFT minted");
|
|
305
|
+
logger.log(` ${chalk.bold("ID:")} ${chalk.cyan(nftObj.id)}`);
|
|
306
|
+
logger.log(` ${chalk.bold("Owner:")} ${nftObj.owner}`);
|
|
307
|
+
logger.log(` ${chalk.bold("Type:")} ${nftObj.type}`);
|
|
308
|
+
|
|
309
|
+
await shutdown();
|
|
310
|
+
} catch (err) {
|
|
311
|
+
logger.error(`Failed: ${err.message}`);
|
|
312
|
+
process.exit(1);
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// economy revenue
|
|
317
|
+
economy
|
|
318
|
+
.command("revenue <pool> <agent-ids>")
|
|
319
|
+
.description("Distribute revenue pool (comma-separated agent IDs)")
|
|
320
|
+
.action(async (pool, agentIds) => {
|
|
321
|
+
try {
|
|
322
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
323
|
+
if (!ctx.db) {
|
|
324
|
+
logger.error("Database not available");
|
|
325
|
+
process.exit(1);
|
|
326
|
+
}
|
|
327
|
+
const db = ctx.db.getDatabase();
|
|
328
|
+
ensureEconomyTables(db);
|
|
329
|
+
|
|
330
|
+
const ids = agentIds.split(",").map((s) => s.trim());
|
|
331
|
+
const results = distributeRevenue(db, parseFloat(pool), ids);
|
|
332
|
+
logger.success(
|
|
333
|
+
`Revenue distributed: ${pool} among ${ids.length} agents`,
|
|
334
|
+
);
|
|
335
|
+
for (const r of results) {
|
|
336
|
+
logger.log(
|
|
337
|
+
` ${chalk.cyan(r.agentId)}: +${r.share} → ${r.newBalance}`,
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
await shutdown();
|
|
342
|
+
} catch (err) {
|
|
343
|
+
logger.error(`Failed: ${err.message}`);
|
|
344
|
+
process.exit(1);
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
// economy contribute
|
|
349
|
+
economy
|
|
350
|
+
.command("contribute <agent-id> <type> <value>")
|
|
351
|
+
.description("Record agent contribution")
|
|
352
|
+
.action(async (agentId, type, value) => {
|
|
353
|
+
try {
|
|
354
|
+
const ctx = await bootstrap({ verbose: program.opts().verbose });
|
|
355
|
+
if (!ctx.db) {
|
|
356
|
+
logger.error("Database not available");
|
|
357
|
+
process.exit(1);
|
|
358
|
+
}
|
|
359
|
+
const db = ctx.db.getDatabase();
|
|
360
|
+
ensureEconomyTables(db);
|
|
361
|
+
|
|
362
|
+
const c = recordContribution(db, agentId, type, parseFloat(value), "");
|
|
363
|
+
logger.success("Contribution recorded");
|
|
364
|
+
logger.log(` ${chalk.bold("ID:")} ${chalk.cyan(c.id)}`);
|
|
365
|
+
logger.log(` ${chalk.bold("Agent:")} ${c.agentId}`);
|
|
366
|
+
logger.log(` ${chalk.bold("Type:")} ${c.type}`);
|
|
367
|
+
logger.log(` ${chalk.bold("Value:")} ${c.value}`);
|
|
368
|
+
|
|
369
|
+
await shutdown();
|
|
370
|
+
} catch (err) {
|
|
371
|
+
logger.error(`Failed: ${err.message}`);
|
|
372
|
+
process.exit(1);
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
}
|