cnagent 2.1.13 → 2.1.14

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 (2) hide show
  1. package/package.json +1 -1
  2. package/tools/dist/cn.js +422 -103
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cnagent",
3
- "version": "2.1.13",
3
+ "version": "2.1.14",
4
4
  "description": "Coherent Network agent CLI — everything runs through cn",
5
5
  "keywords": [
6
6
  "cn-agent",
package/tools/dist/cn.js CHANGED
@@ -13075,7 +13075,7 @@ var require_cn_lib = __commonJS({
13075
13075
  );
13076
13076
  }
13077
13077
  var help_text = "cn - Coherent Network agent CLI\n\nUsage: cn <command> [options]\n\nCommands:\n # Agent decisions (output)\n delete <thread> GTD: discard\n defer <thread> GTD: postpone\n delegate <t> <peer> GTD: forward\n do <thread> GTD: claim/start\n done <thread> GTD: complete \xE2\x86\x92 archive\n reply <thread> <msg> Append to thread\n send <peer> <msg> Message to peer (or self)\n \n # cn operations (orchestrator)\n sync Fetch inbound + send outbound\n process Queue inbox \xE2\x86\x92 input.md \xE2\x86\x92 wake agent\n queue [list|clear] View or clear the task queue\n mca [list|add <desc>] Surface MCAs for community pickup\n inbox List inbox threads\n outbox List outbox threads\n next Get next inbox item (with cadence)\n read <thread> Read thread with cadence\n \n # Hub management\n init [name] Create new hub\n status Show hub state\n commit [msg] Stage + commit\n push Push to origin\n save [msg] Commit + push\n peer Manage peers\n doctor Health check\n update Update cn to latest version\n\nAliases:\n i = inbox, o = outbox, s = status, d = doctor\n\nFlags:\n --help, -h Show help\n --version, -V Show version\n --json Machine-readable output\n --quiet, -q Minimal output\n --dry-run Show what would happen\n\nActor Model:\n cn runs on cron (every 5 min). It:\n 1. Syncs peers \xE2\x86\x92 queues new inbox items to state/queue/\n 2. If input.md empty \xE2\x86\x92 pops from queue \xE2\x86\x92 writes input.md \xE2\x86\x92 wakes agent\n Agent reads input.md, processes, deletes when done.\n";
13078
- var version = "2.1.13";
13078
+ var version = "2.1.14";
13079
13079
  module2.exports = {
13080
13080
  starts_with,
13081
13081
  strip_prefix,
@@ -30363,107 +30363,6 @@ function wake_agent(param) {
30363
30363
  console.log(color("33", "\xE2\x9A\xA0 ") + "Wake trigger failed - is OpenClaw running?");
30364
30364
  }
30365
30365
  }
30366
- function run_process(hub_path) {
30367
- console.log(color("36", "cn process: actor loop..."));
30368
- const queued = queue_inbox_items(hub_path);
30369
- if (queued > 0) {
30370
- console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
30371
- TAG: (
30372
- /* Format */
30373
- 0
30374
- ),
30375
- _0: {
30376
- TAG: (
30377
- /* String_literal */
30378
- 11
30379
- ),
30380
- _0: "Added ",
30381
- _1: {
30382
- TAG: (
30383
- /* Int */
30384
- 4
30385
- ),
30386
- _0: (
30387
- /* Int_d */
30388
- 0
30389
- ),
30390
- _1: (
30391
- /* No_padding */
30392
- 0
30393
- ),
30394
- _2: (
30395
- /* No_precision */
30396
- 0
30397
- ),
30398
- _3: {
30399
- TAG: (
30400
- /* String_literal */
30401
- 11
30402
- ),
30403
- _0: " item(s) to queue",
30404
- _1: (
30405
- /* End_of_format */
30406
- 0
30407
- )
30408
- }
30409
- }
30410
- },
30411
- _1: "Added %d item(s) to queue"
30412
- }), queued)));
30413
- }
30414
- const inp = Path.join(hub_path, "state/input.md");
30415
- const outp = Path.join(hub_path, "state/output.md");
30416
- if (Fs.existsSync(inp) && Fs.existsSync(outp)) {
30417
- if (archive_io_pair(hub_path) && feed_next_input(hub_path)) {
30418
- return wake_agent(void 0);
30419
- } else {
30420
- return;
30421
- }
30422
- } else if (Fs.existsSync(inp)) {
30423
- console.log(color("36", "Agent working (input.md exists, awaiting output.md)"));
30424
- console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
30425
- TAG: (
30426
- /* Format */
30427
- 0
30428
- ),
30429
- _0: {
30430
- TAG: (
30431
- /* String_literal */
30432
- 11
30433
- ),
30434
- _0: "Queue depth: ",
30435
- _1: {
30436
- TAG: (
30437
- /* Int */
30438
- 4
30439
- ),
30440
- _0: (
30441
- /* Int_d */
30442
- 0
30443
- ),
30444
- _1: (
30445
- /* No_padding */
30446
- 0
30447
- ),
30448
- _2: (
30449
- /* No_precision */
30450
- 0
30451
- ),
30452
- _3: (
30453
- /* End_of_format */
30454
- 0
30455
- )
30456
- }
30457
- },
30458
- _1: "Queue depth: %d"
30459
- }), queue_count(hub_path))));
30460
- return;
30461
- } else if (feed_next_input(hub_path)) {
30462
- return wake_agent(void 0);
30463
- } else {
30464
- return;
30465
- }
30466
- }
30467
30366
  function run_sync(hub_path, name) {
30468
30367
  console.log(color("36", "Syncing..."));
30469
30368
  inbox_check(hub_path, name);
@@ -31078,6 +30977,419 @@ function run_mca_list(hub_path) {
31078
30977
  }
31079
30978
  console.log("(no MCAs)");
31080
30979
  }
30980
+ function mca_cycle_path(hub_path) {
30981
+ return Path.join(hub_path, "state/.mca-cycle");
30982
+ }
30983
+ function get_mca_cycle(hub_path) {
30984
+ const path = Path.join(hub_path, "state/.mca-cycle");
30985
+ if (Fs.existsSync(path)) {
30986
+ return Stdlib__Option.value(Stdlib.int_of_string_opt(Stdlib__String.trim(Fs.readFileSync(path, "utf8"))), 0);
30987
+ } else {
30988
+ return 0;
30989
+ }
30990
+ }
30991
+ function increment_mca_cycle(hub_path) {
30992
+ const current = get_mca_cycle(hub_path);
30993
+ const next = current + 1 | 0;
30994
+ const prim1 = String(next);
30995
+ const prim0 = Path.join(hub_path, "state/.mca-cycle");
30996
+ Fs.writeFileSync(prim0, prim1);
30997
+ return next;
30998
+ }
30999
+ function mca_count(hub_path) {
31000
+ const dir = Path.join(hub_path, "state/mca");
31001
+ if (Fs.existsSync(dir)) {
31002
+ return Stdlib__List.length(Stdlib__List.filter(is_md_file, Stdlib__Array.to_list(Fs.readdirSync(dir))));
31003
+ } else {
31004
+ return 0;
31005
+ }
31006
+ }
31007
+ function queue_mca_review(hub_path) {
31008
+ const dir = Path.join(hub_path, "state/mca");
31009
+ const mcas = Stdlib__List.sort(Stdlib__String.compare, Stdlib__List.filter(is_md_file, Stdlib__Array.to_list(Fs.readdirSync(dir))));
31010
+ const mca_list = Stdlib__String.concat("\n", Stdlib__List.map((function(file) {
31011
+ const content = Fs.readFileSync(Path.join(dir, file), "utf8");
31012
+ const meta = Cn_lib.parse_frontmatter(content);
31013
+ const id = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
31014
+ if (param[0] === "id") {
31015
+ return param[1];
31016
+ }
31017
+ }), meta), "?");
31018
+ const by = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
31019
+ if (param[0] === "surfaced-by") {
31020
+ return param[1];
31021
+ }
31022
+ }), meta), "?");
31023
+ const lines = Stdlib__String.split_on_char(
31024
+ /* '\n' */
31025
+ 10,
31026
+ content
31027
+ );
31028
+ const skip_fm = function(_in_fm, _rest) {
31029
+ while (true) {
31030
+ const rest = _rest;
31031
+ const in_fm = _in_fm;
31032
+ if (!rest) {
31033
+ return (
31034
+ /* [] */
31035
+ 0
31036
+ );
31037
+ }
31038
+ if (rest.hd === "---") {
31039
+ const rest$1 = rest.tl;
31040
+ if (in_fm) {
31041
+ if (in_fm) {
31042
+ return rest$1;
31043
+ }
31044
+ } else {
31045
+ _rest = rest$1;
31046
+ _in_fm = true;
31047
+ continue;
31048
+ }
31049
+ }
31050
+ if (!in_fm) {
31051
+ return rest;
31052
+ }
31053
+ _rest = rest.tl;
31054
+ continue;
31055
+ }
31056
+ ;
31057
+ };
31058
+ const body_lines = skip_fm(false, lines);
31059
+ const desc = Stdlib__Option.value(Stdlib__List.find_opt((function(l) {
31060
+ const t = Stdlib__String.trim(l);
31061
+ if (t !== "") {
31062
+ return !Cn_lib.starts_with("#", t);
31063
+ } else {
31064
+ return false;
31065
+ }
31066
+ }), body_lines), "(no description)");
31067
+ return Curry._3(Stdlib__Printf.sprintf({
31068
+ TAG: (
31069
+ /* Format */
31070
+ 0
31071
+ ),
31072
+ _0: {
31073
+ TAG: (
31074
+ /* String_literal */
31075
+ 11
31076
+ ),
31077
+ _0: "- [",
31078
+ _1: {
31079
+ TAG: (
31080
+ /* String */
31081
+ 2
31082
+ ),
31083
+ _0: (
31084
+ /* No_padding */
31085
+ 0
31086
+ ),
31087
+ _1: {
31088
+ TAG: (
31089
+ /* String_literal */
31090
+ 11
31091
+ ),
31092
+ _0: "] ",
31093
+ _1: {
31094
+ TAG: (
31095
+ /* String */
31096
+ 2
31097
+ ),
31098
+ _0: (
31099
+ /* No_padding */
31100
+ 0
31101
+ ),
31102
+ _1: {
31103
+ TAG: (
31104
+ /* String_literal */
31105
+ 11
31106
+ ),
31107
+ _0: " (by ",
31108
+ _1: {
31109
+ TAG: (
31110
+ /* String */
31111
+ 2
31112
+ ),
31113
+ _0: (
31114
+ /* No_padding */
31115
+ 0
31116
+ ),
31117
+ _1: {
31118
+ TAG: (
31119
+ /* Char_literal */
31120
+ 12
31121
+ ),
31122
+ _0: (
31123
+ /* ')' */
31124
+ 41
31125
+ ),
31126
+ _1: (
31127
+ /* End_of_format */
31128
+ 0
31129
+ )
31130
+ }
31131
+ }
31132
+ }
31133
+ }
31134
+ }
31135
+ }
31136
+ },
31137
+ _1: "- [%s] %s (by %s)"
31138
+ }), id, Stdlib__String.trim(desc), by);
31139
+ }), mcas));
31140
+ const review_id = Curry._1(Stdlib__Printf.sprintf({
31141
+ TAG: (
31142
+ /* Format */
31143
+ 0
31144
+ ),
31145
+ _0: {
31146
+ TAG: (
31147
+ /* String_literal */
31148
+ 11
31149
+ ),
31150
+ _0: "mca-review-",
31151
+ _1: {
31152
+ TAG: (
31153
+ /* String */
31154
+ 2
31155
+ ),
31156
+ _0: (
31157
+ /* No_padding */
31158
+ 0
31159
+ ),
31160
+ _1: (
31161
+ /* End_of_format */
31162
+ 0
31163
+ )
31164
+ }
31165
+ },
31166
+ _1: "mca-review-%s"
31167
+ }), (/* @__PURE__ */ new Date()).toISOString().slice(0, 10));
31168
+ const body = Curry._1(Stdlib__Printf.sprintf({
31169
+ TAG: (
31170
+ /* Format */
31171
+ 0
31172
+ ),
31173
+ _0: {
31174
+ TAG: (
31175
+ /* String_literal */
31176
+ 11
31177
+ ),
31178
+ _0: "# MCA Review\n\nReview the MCA queue below. Identify the highest priority MCA with:\n- Lowest cost to complete\n- Highest probability of success\n\nIf you can do it now, do it. Otherwise, explain why not.\n\n## Open MCAs\n\n",
31179
+ _1: {
31180
+ TAG: (
31181
+ /* String */
31182
+ 2
31183
+ ),
31184
+ _0: (
31185
+ /* No_padding */
31186
+ 0
31187
+ ),
31188
+ _1: {
31189
+ TAG: (
31190
+ /* Char_literal */
31191
+ 12
31192
+ ),
31193
+ _0: (
31194
+ /* '\n' */
31195
+ 10
31196
+ ),
31197
+ _1: (
31198
+ /* End_of_format */
31199
+ 0
31200
+ )
31201
+ }
31202
+ }
31203
+ },
31204
+ _1: "# MCA Review\n\nReview the MCA queue below. Identify the highest priority MCA with:\n- Lowest cost to complete\n- Highest probability of success\n\nIf you can do it now, do it. Otherwise, explain why not.\n\n## Open MCAs\n\n%s\n"
31205
+ }), mca_list);
31206
+ queue_add(hub_path, review_id, "system", body);
31207
+ log_action(hub_path, "mca.review-queued", Curry._1(Stdlib__Printf.sprintf({
31208
+ TAG: (
31209
+ /* Format */
31210
+ 0
31211
+ ),
31212
+ _0: {
31213
+ TAG: (
31214
+ /* String_literal */
31215
+ 11
31216
+ ),
31217
+ _0: "count:",
31218
+ _1: {
31219
+ TAG: (
31220
+ /* Int */
31221
+ 4
31222
+ ),
31223
+ _0: (
31224
+ /* Int_d */
31225
+ 0
31226
+ ),
31227
+ _1: (
31228
+ /* No_padding */
31229
+ 0
31230
+ ),
31231
+ _2: (
31232
+ /* No_precision */
31233
+ 0
31234
+ ),
31235
+ _3: (
31236
+ /* End_of_format */
31237
+ 0
31238
+ )
31239
+ }
31240
+ },
31241
+ _1: "count:%d"
31242
+ }), Stdlib__List.length(mcas)));
31243
+ const msg = Curry._1(Stdlib__Printf.sprintf({
31244
+ TAG: (
31245
+ /* Format */
31246
+ 0
31247
+ ),
31248
+ _0: {
31249
+ TAG: (
31250
+ /* String_literal */
31251
+ 11
31252
+ ),
31253
+ _0: "Queued MCA review (",
31254
+ _1: {
31255
+ TAG: (
31256
+ /* Int */
31257
+ 4
31258
+ ),
31259
+ _0: (
31260
+ /* Int_d */
31261
+ 0
31262
+ ),
31263
+ _1: (
31264
+ /* No_padding */
31265
+ 0
31266
+ ),
31267
+ _2: (
31268
+ /* No_precision */
31269
+ 0
31270
+ ),
31271
+ _3: {
31272
+ TAG: (
31273
+ /* String_literal */
31274
+ 11
31275
+ ),
31276
+ _0: " MCAs)",
31277
+ _1: (
31278
+ /* End_of_format */
31279
+ 0
31280
+ )
31281
+ }
31282
+ }
31283
+ },
31284
+ _1: "Queued MCA review (%d MCAs)"
31285
+ }), Stdlib__List.length(mcas));
31286
+ console.log(color("32", "\xE2\x9C\x93 ") + msg);
31287
+ }
31288
+ function run_process(hub_path) {
31289
+ console.log(color("36", "cn process: actor loop..."));
31290
+ const queued = queue_inbox_items(hub_path);
31291
+ if (queued > 0) {
31292
+ console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
31293
+ TAG: (
31294
+ /* Format */
31295
+ 0
31296
+ ),
31297
+ _0: {
31298
+ TAG: (
31299
+ /* String_literal */
31300
+ 11
31301
+ ),
31302
+ _0: "Added ",
31303
+ _1: {
31304
+ TAG: (
31305
+ /* Int */
31306
+ 4
31307
+ ),
31308
+ _0: (
31309
+ /* Int_d */
31310
+ 0
31311
+ ),
31312
+ _1: (
31313
+ /* No_padding */
31314
+ 0
31315
+ ),
31316
+ _2: (
31317
+ /* No_precision */
31318
+ 0
31319
+ ),
31320
+ _3: {
31321
+ TAG: (
31322
+ /* String_literal */
31323
+ 11
31324
+ ),
31325
+ _0: " item(s) to queue",
31326
+ _1: (
31327
+ /* End_of_format */
31328
+ 0
31329
+ )
31330
+ }
31331
+ }
31332
+ },
31333
+ _1: "Added %d item(s) to queue"
31334
+ }), queued)));
31335
+ }
31336
+ const cycle = increment_mca_cycle(hub_path);
31337
+ if (cycle % 5 === 0 && mca_count(hub_path) > 0) {
31338
+ queue_mca_review(hub_path);
31339
+ }
31340
+ const inp = Path.join(hub_path, "state/input.md");
31341
+ const outp = Path.join(hub_path, "state/output.md");
31342
+ if (Fs.existsSync(inp) && Fs.existsSync(outp)) {
31343
+ if (archive_io_pair(hub_path) && feed_next_input(hub_path)) {
31344
+ return wake_agent(void 0);
31345
+ } else {
31346
+ return;
31347
+ }
31348
+ } else if (Fs.existsSync(inp)) {
31349
+ console.log(color("36", "Agent working (input.md exists, awaiting output.md)"));
31350
+ console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
31351
+ TAG: (
31352
+ /* Format */
31353
+ 0
31354
+ ),
31355
+ _0: {
31356
+ TAG: (
31357
+ /* String_literal */
31358
+ 11
31359
+ ),
31360
+ _0: "Queue depth: ",
31361
+ _1: {
31362
+ TAG: (
31363
+ /* Int */
31364
+ 4
31365
+ ),
31366
+ _0: (
31367
+ /* Int_d */
31368
+ 0
31369
+ ),
31370
+ _1: (
31371
+ /* No_padding */
31372
+ 0
31373
+ ),
31374
+ _2: (
31375
+ /* No_precision */
31376
+ 0
31377
+ ),
31378
+ _3: (
31379
+ /* End_of_format */
31380
+ 0
31381
+ )
31382
+ }
31383
+ },
31384
+ _1: "Queue depth: %d"
31385
+ }), queue_count(hub_path))));
31386
+ return;
31387
+ } else if (feed_next_input(hub_path)) {
31388
+ return wake_agent(void 0);
31389
+ } else {
31390
+ return;
31391
+ }
31392
+ }
31081
31393
  function update_runtime(hub_path) {
31082
31394
  const runtime_path = Path.join(hub_path, "state/runtime.md");
31083
31395
  const v = exec("cn --version 2>/dev/null");
@@ -32949,6 +33261,7 @@ if (cmd !== void 0) {
32949
33261
  process.exit(1);
32950
33262
  }
32951
33263
  var info = cyan;
33264
+ var mca_review_interval = 5;
32952
33265
  module.exports = {
32953
33266
  Process,
32954
33267
  Fs: Fs$1,
@@ -33010,13 +33323,19 @@ module.exports = {
33010
33323
  queue_inbox_items,
33011
33324
  feed_next_input,
33012
33325
  wake_agent,
33013
- run_process,
33014
33326
  run_sync,
33015
33327
  run_queue_list,
33016
33328
  run_queue_clear,
33017
33329
  mca_dir,
33018
33330
  run_mca_add,
33019
33331
  run_mca_list,
33332
+ mca_cycle_path,
33333
+ mca_review_interval,
33334
+ get_mca_cycle,
33335
+ increment_mca_cycle,
33336
+ mca_count,
33337
+ queue_mca_review,
33338
+ run_process,
33020
33339
  update_runtime,
33021
33340
  run_init,
33022
33341
  format_peers_md,