cnagent 2.1.12 → 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 +982 -186
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cnagent",
3
- "version": "2.1.12",
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
@@ -11878,6 +11878,7 @@ var require_string = __commonJS({
11878
11878
  var require_cn_lib = __commonJS({
11879
11879
  "_build/default/tools/src/cn/output/tools/src/cn/cn_lib.js"(exports2, module2) {
11880
11880
  "use strict";
11881
+ var Caml_obj = require_caml_obj();
11881
11882
  var Stdlib__List2 = require_list();
11882
11883
  var Stdlib__Option2 = require_option();
11883
11884
  var Stdlib__String2 = require_string();
@@ -11999,17 +12000,28 @@ var require_cn_lib = __commonJS({
11999
12000
  } else {
12000
12001
  return "queue clear";
12001
12002
  }
12002
- case /* Read */
12003
+ case /* Mca */
12003
12004
  5:
12005
+ const d = t._0;
12006
+ if (
12007
+ /* tag */
12008
+ typeof d === "number" || typeof d === "string"
12009
+ ) {
12010
+ return "mca list";
12011
+ } else {
12012
+ return "mca add " + d._0;
12013
+ }
12014
+ case /* Read */
12015
+ 6:
12004
12016
  return "read " + t._0;
12005
12017
  case /* Reply */
12006
- 6:
12018
+ 7:
12007
12019
  return "reply " + t._0;
12008
12020
  case /* Send */
12009
- 7:
12021
+ 8:
12010
12022
  return "send " + t._0;
12011
12023
  case /* Gtd */
12012
- 8:
12024
+ 9:
12013
12025
  const t$1 = t._0;
12014
12026
  switch (t$1.TAG) {
12015
12027
  case /* GtdDelete */
@@ -12029,7 +12041,7 @@ var require_cn_lib = __commonJS({
12029
12041
  return "done " + t$1._0;
12030
12042
  }
12031
12043
  case /* Commit */
12032
- 9:
12044
+ 10:
12033
12045
  const m = t._0;
12034
12046
  if (m !== void 0) {
12035
12047
  return "commit " + m;
@@ -12037,7 +12049,7 @@ var require_cn_lib = __commonJS({
12037
12049
  return "commit";
12038
12050
  }
12039
12051
  case /* Save */
12040
- 10:
12052
+ 11:
12041
12053
  const m$1 = t._0;
12042
12054
  if (m$1 !== void 0) {
12043
12055
  return "save " + m$1;
@@ -12223,6 +12235,44 @@ var require_cn_lib = __commonJS({
12223
12235
  return;
12224
12236
  }
12225
12237
  }
12238
+ function parse_mca_cmd(param) {
12239
+ if (!param) {
12240
+ return (
12241
+ /* Mca_list */
12242
+ 0
12243
+ );
12244
+ }
12245
+ switch (param.hd) {
12246
+ case "add":
12247
+ const rest = param.tl;
12248
+ if (Caml_obj.caml_notequal(
12249
+ rest,
12250
+ /* [] */
12251
+ 0
12252
+ )) {
12253
+ return {
12254
+ TAG: (
12255
+ /* Mca_add */
12256
+ 0
12257
+ ),
12258
+ _0: Stdlib__String2.concat(" ", rest)
12259
+ };
12260
+ } else {
12261
+ return;
12262
+ }
12263
+ case "list":
12264
+ if (param.tl) {
12265
+ return;
12266
+ } else {
12267
+ return (
12268
+ /* Mca_list */
12269
+ 0
12270
+ );
12271
+ }
12272
+ default:
12273
+ return;
12274
+ }
12275
+ }
12226
12276
  function parse_gtd_cmd(param) {
12227
12277
  if (!param) {
12228
12278
  return;
@@ -12334,7 +12384,7 @@ var require_cn_lib = __commonJS({
12334
12384
  return {
12335
12385
  TAG: (
12336
12386
  /* Commit */
12337
- 9
12387
+ 10
12338
12388
  ),
12339
12389
  _0: join_rest(param.tl)
12340
12390
  };
@@ -12343,7 +12393,7 @@ var require_cn_lib = __commonJS({
12343
12393
  return {
12344
12394
  TAG: (
12345
12395
  /* Gtd */
12346
- 8
12396
+ 9
12347
12397
  ),
12348
12398
  _0: c
12349
12399
  };
@@ -12356,7 +12406,7 @@ var require_cn_lib = __commonJS({
12356
12406
  return {
12357
12407
  TAG: (
12358
12408
  /* Gtd */
12359
- 8
12409
+ 9
12360
12410
  ),
12361
12411
  _0: c
12362
12412
  };
@@ -12369,7 +12419,7 @@ var require_cn_lib = __commonJS({
12369
12419
  return {
12370
12420
  TAG: (
12371
12421
  /* Gtd */
12372
- 8
12422
+ 9
12373
12423
  ),
12374
12424
  _0: c
12375
12425
  };
@@ -12382,7 +12432,7 @@ var require_cn_lib = __commonJS({
12382
12432
  return {
12383
12433
  TAG: (
12384
12434
  /* Gtd */
12385
- 8
12435
+ 9
12386
12436
  ),
12387
12437
  _0: c
12388
12438
  };
@@ -12404,7 +12454,7 @@ var require_cn_lib = __commonJS({
12404
12454
  return {
12405
12455
  TAG: (
12406
12456
  /* Gtd */
12407
- 8
12457
+ 9
12408
12458
  ),
12409
12459
  _0: c
12410
12460
  };
@@ -12450,6 +12500,16 @@ var require_cn_lib = __commonJS({
12450
12500
  _0: void 0
12451
12501
  };
12452
12502
  }
12503
+ case "mca":
12504
+ return Stdlib__Option2.map((function(c) {
12505
+ return {
12506
+ TAG: (
12507
+ /* Mca */
12508
+ 5
12509
+ ),
12510
+ _0: c
12511
+ };
12512
+ }), parse_mca_cmd(param.tl));
12453
12513
  case "next":
12454
12514
  if (param.tl) {
12455
12515
  return;
@@ -12516,7 +12576,7 @@ var require_cn_lib = __commonJS({
12516
12576
  return {
12517
12577
  TAG: (
12518
12578
  /* Read */
12519
- 5
12579
+ 6
12520
12580
  ),
12521
12581
  _0: match$1.hd
12522
12582
  };
@@ -12530,7 +12590,7 @@ var require_cn_lib = __commonJS({
12530
12590
  return {
12531
12591
  TAG: (
12532
12592
  /* Reply */
12533
- 6
12593
+ 7
12534
12594
  ),
12535
12595
  _0: match$2.hd,
12536
12596
  _1: Stdlib__String2.concat(" ", match$2.tl)
@@ -12542,7 +12602,7 @@ var require_cn_lib = __commonJS({
12542
12602
  return {
12543
12603
  TAG: (
12544
12604
  /* Save */
12545
- 10
12605
+ 11
12546
12606
  ),
12547
12607
  _0: join_rest(param.tl)
12548
12608
  };
@@ -12552,7 +12612,7 @@ var require_cn_lib = __commonJS({
12552
12612
  return {
12553
12613
  TAG: (
12554
12614
  /* Send */
12555
- 7
12615
+ 8
12556
12616
  ),
12557
12617
  _0: match$3.hd,
12558
12618
  _1: Stdlib__String2.concat(" ", match$3.tl)
@@ -13014,8 +13074,8 @@ var require_cn_lib = __commonJS({
13014
13074
  10
13015
13075
  );
13016
13076
  }
13017
- 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 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";
13018
- var version = "2.1.12";
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.14";
13019
13079
  module2.exports = {
13020
13080
  starts_with,
13021
13081
  strip_prefix,
@@ -13027,6 +13087,7 @@ var require_cn_lib = __commonJS({
13027
13087
  parse_outbox_cmd,
13028
13088
  parse_peer_cmd,
13029
13089
  parse_queue_cmd,
13090
+ parse_mca_cmd,
13030
13091
  parse_gtd_cmd,
13031
13092
  join_rest,
13032
13093
  parse_command,
@@ -30302,107 +30363,6 @@ function wake_agent(param) {
30302
30363
  console.log(color("33", "\xE2\x9A\xA0 ") + "Wake trigger failed - is OpenClaw running?");
30303
30364
  }
30304
30365
  }
30305
- function run_process(hub_path) {
30306
- console.log(color("36", "cn process: actor loop..."));
30307
- const queued = queue_inbox_items(hub_path);
30308
- if (queued > 0) {
30309
- console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
30310
- TAG: (
30311
- /* Format */
30312
- 0
30313
- ),
30314
- _0: {
30315
- TAG: (
30316
- /* String_literal */
30317
- 11
30318
- ),
30319
- _0: "Added ",
30320
- _1: {
30321
- TAG: (
30322
- /* Int */
30323
- 4
30324
- ),
30325
- _0: (
30326
- /* Int_d */
30327
- 0
30328
- ),
30329
- _1: (
30330
- /* No_padding */
30331
- 0
30332
- ),
30333
- _2: (
30334
- /* No_precision */
30335
- 0
30336
- ),
30337
- _3: {
30338
- TAG: (
30339
- /* String_literal */
30340
- 11
30341
- ),
30342
- _0: " item(s) to queue",
30343
- _1: (
30344
- /* End_of_format */
30345
- 0
30346
- )
30347
- }
30348
- }
30349
- },
30350
- _1: "Added %d item(s) to queue"
30351
- }), queued)));
30352
- }
30353
- const inp = Path.join(hub_path, "state/input.md");
30354
- const outp = Path.join(hub_path, "state/output.md");
30355
- if (Fs.existsSync(inp) && Fs.existsSync(outp)) {
30356
- if (archive_io_pair(hub_path) && feed_next_input(hub_path)) {
30357
- return wake_agent(void 0);
30358
- } else {
30359
- return;
30360
- }
30361
- } else if (Fs.existsSync(inp)) {
30362
- console.log(color("36", "Agent working (input.md exists, awaiting output.md)"));
30363
- console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
30364
- TAG: (
30365
- /* Format */
30366
- 0
30367
- ),
30368
- _0: {
30369
- TAG: (
30370
- /* String_literal */
30371
- 11
30372
- ),
30373
- _0: "Queue depth: ",
30374
- _1: {
30375
- TAG: (
30376
- /* Int */
30377
- 4
30378
- ),
30379
- _0: (
30380
- /* Int_d */
30381
- 0
30382
- ),
30383
- _1: (
30384
- /* No_padding */
30385
- 0
30386
- ),
30387
- _2: (
30388
- /* No_precision */
30389
- 0
30390
- ),
30391
- _3: (
30392
- /* End_of_format */
30393
- 0
30394
- )
30395
- }
30396
- },
30397
- _1: "Queue depth: %d"
30398
- }), queue_count(hub_path))));
30399
- return;
30400
- } else if (feed_next_input(hub_path)) {
30401
- return wake_agent(void 0);
30402
- } else {
30403
- return;
30404
- }
30405
- }
30406
30366
  function run_sync(hub_path, name) {
30407
30367
  console.log(color("36", "Syncing..."));
30408
30368
  inbox_check(hub_path, name);
@@ -30616,84 +30576,898 @@ function run_queue_clear(hub_path) {
30616
30576
  }
30617
30577
  console.log(color("32", "\xE2\x9C\x93 ") + "Queue already empty");
30618
30578
  }
30619
- function update_runtime(hub_path) {
30620
- const runtime_path = Path.join(hub_path, "state/runtime.md");
30621
- const v = exec("cn --version 2>/dev/null");
30622
- let cn_ver;
30623
- if (v !== void 0) {
30624
- const s = Stdlib__String.trim(v);
30625
- const match2 = Stdlib__String.split_on_char(
30626
- /* ' ' */
30627
- 32,
30628
- s
30629
- );
30630
- if (match2) {
30631
- const match$1 = match2.tl;
30632
- cn_ver = match$1 ? match$1.hd : "unknown";
30633
- } else {
30634
- cn_ver = "unknown";
30635
- }
30636
- } else {
30637
- cn_ver = "unknown";
30638
- }
30639
- const v$1 = exec("openclaw --version 2>/dev/null");
30640
- const oc_ver = v$1 !== void 0 ? Stdlib__String.trim(v$1) : "unknown";
30641
- const hub_name = Cn_lib.derive_name(hub_path);
30642
- const c = exec_in(hub_path, "git rev-parse --short HEAD 2>/dev/null");
30643
- const hub_commit = c !== void 0 ? Stdlib__String.trim(c) : "unknown";
30644
- const c$1 = exec("git -C $(npm root -g)/cnagent rev-parse --short HEAD 2>/dev/null");
30645
- const cn_commit = c$1 !== void 0 ? Stdlib__String.trim(c$1) : "unknown";
30646
- const peers_path = Path.join(hub_path, "state/peers.md");
30647
- let peer_count;
30648
- if (Fs.existsSync(peers_path)) {
30649
- const content = Fs.readFileSync(peers_path, "utf8");
30650
- const lines = Stdlib__String.split_on_char(
30651
- /* '\n' */
30652
- 10,
30653
- content
30654
- );
30655
- peer_count = Stdlib__List.length(Stdlib__List.filter((function(l) {
30656
- if (l.length > 2) {
30657
- return Stdlib__String.sub(l, 0, 2) === "- ";
30658
- } else {
30659
- return false;
30660
- }
30661
- }), lines));
30662
- } else {
30663
- peer_count = 0;
30664
- }
30665
- const content$1 = Curry._8(Stdlib__Printf.sprintf({
30579
+ function mca_dir(hub_path) {
30580
+ return Path.join(hub_path, "state/mca");
30581
+ }
30582
+ function run_mca_add(hub_path, name, description) {
30583
+ const dir = Path.join(hub_path, "state/mca");
30584
+ ensure_dir(dir);
30585
+ const ts = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
30586
+ const slug = description.slice(0, 40).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
30587
+ const file_name = Curry._2(Stdlib__Printf.sprintf({
30666
30588
  TAG: (
30667
30589
  /* Format */
30668
30590
  0
30669
30591
  ),
30670
30592
  _0: {
30671
30593
  TAG: (
30672
- /* String_literal */
30673
- 11
30594
+ /* String */
30595
+ 2
30596
+ ),
30597
+ _0: (
30598
+ /* No_padding */
30599
+ 0
30674
30600
  ),
30675
- _0: "# Runtime State\n\nAuto-generated by `cn update`. Do not edit manually.\n\n```yaml\nsession_start: ",
30676
30601
  _1: {
30677
30602
  TAG: (
30678
- /* String */
30679
- 2
30603
+ /* Char_literal */
30604
+ 12
30680
30605
  ),
30681
30606
  _0: (
30682
- /* No_padding */
30683
- 0
30607
+ /* '-' */
30608
+ 45
30684
30609
  ),
30685
30610
  _1: {
30686
30611
  TAG: (
30687
- /* String_literal */
30688
- 11
30612
+ /* String */
30613
+ 2
30614
+ ),
30615
+ _0: (
30616
+ /* No_padding */
30617
+ 0
30689
30618
  ),
30690
- _0: "\ncn_version: ",
30691
30619
  _1: {
30692
30620
  TAG: (
30693
- /* String */
30694
- 2
30621
+ /* String_literal */
30622
+ 11
30695
30623
  ),
30696
- _0: (
30624
+ _0: ".md",
30625
+ _1: (
30626
+ /* End_of_format */
30627
+ 0
30628
+ )
30629
+ }
30630
+ }
30631
+ }
30632
+ },
30633
+ _1: "%s-%s.md"
30634
+ }), ts, slug);
30635
+ const file_path = Path.join(dir, file_name);
30636
+ const content = Curry._4(Stdlib__Printf.sprintf({
30637
+ TAG: (
30638
+ /* Format */
30639
+ 0
30640
+ ),
30641
+ _0: {
30642
+ TAG: (
30643
+ /* String_literal */
30644
+ 11
30645
+ ),
30646
+ _0: "---\nid: ",
30647
+ _1: {
30648
+ TAG: (
30649
+ /* String */
30650
+ 2
30651
+ ),
30652
+ _0: (
30653
+ /* No_padding */
30654
+ 0
30655
+ ),
30656
+ _1: {
30657
+ TAG: (
30658
+ /* String_literal */
30659
+ 11
30660
+ ),
30661
+ _0: "\nsurfaced-by: ",
30662
+ _1: {
30663
+ TAG: (
30664
+ /* String */
30665
+ 2
30666
+ ),
30667
+ _0: (
30668
+ /* No_padding */
30669
+ 0
30670
+ ),
30671
+ _1: {
30672
+ TAG: (
30673
+ /* String_literal */
30674
+ 11
30675
+ ),
30676
+ _0: "\ncreated: ",
30677
+ _1: {
30678
+ TAG: (
30679
+ /* String */
30680
+ 2
30681
+ ),
30682
+ _0: (
30683
+ /* No_padding */
30684
+ 0
30685
+ ),
30686
+ _1: {
30687
+ TAG: (
30688
+ /* String_literal */
30689
+ 11
30690
+ ),
30691
+ _0: "\nstatus: open\n---\n\n# MCA\n\n",
30692
+ _1: {
30693
+ TAG: (
30694
+ /* String */
30695
+ 2
30696
+ ),
30697
+ _0: (
30698
+ /* No_padding */
30699
+ 0
30700
+ ),
30701
+ _1: {
30702
+ TAG: (
30703
+ /* Char_literal */
30704
+ 12
30705
+ ),
30706
+ _0: (
30707
+ /* '\n' */
30708
+ 10
30709
+ ),
30710
+ _1: (
30711
+ /* End_of_format */
30712
+ 0
30713
+ )
30714
+ }
30715
+ }
30716
+ }
30717
+ }
30718
+ }
30719
+ }
30720
+ }
30721
+ }
30722
+ },
30723
+ _1: "---\nid: %s\nsurfaced-by: %s\ncreated: %s\nstatus: open\n---\n\n# MCA\n\n%s\n"
30724
+ }), slug, name, (/* @__PURE__ */ new Date()).toISOString(), description);
30725
+ Fs.writeFileSync(file_path, content);
30726
+ log_action(hub_path, "mca.add", Curry._2(Stdlib__Printf.sprintf({
30727
+ TAG: (
30728
+ /* Format */
30729
+ 0
30730
+ ),
30731
+ _0: {
30732
+ TAG: (
30733
+ /* String_literal */
30734
+ 11
30735
+ ),
30736
+ _0: "id:",
30737
+ _1: {
30738
+ TAG: (
30739
+ /* String */
30740
+ 2
30741
+ ),
30742
+ _0: (
30743
+ /* No_padding */
30744
+ 0
30745
+ ),
30746
+ _1: {
30747
+ TAG: (
30748
+ /* String_literal */
30749
+ 11
30750
+ ),
30751
+ _0: " desc:",
30752
+ _1: {
30753
+ TAG: (
30754
+ /* String */
30755
+ 2
30756
+ ),
30757
+ _0: (
30758
+ /* No_padding */
30759
+ 0
30760
+ ),
30761
+ _1: (
30762
+ /* End_of_format */
30763
+ 0
30764
+ )
30765
+ }
30766
+ }
30767
+ }
30768
+ },
30769
+ _1: "id:%s desc:%s"
30770
+ }), slug, description));
30771
+ const msg = Curry._1(Stdlib__Printf.sprintf({
30772
+ TAG: (
30773
+ /* Format */
30774
+ 0
30775
+ ),
30776
+ _0: {
30777
+ TAG: (
30778
+ /* String_literal */
30779
+ 11
30780
+ ),
30781
+ _0: "MCA surfaced: ",
30782
+ _1: {
30783
+ TAG: (
30784
+ /* String */
30785
+ 2
30786
+ ),
30787
+ _0: (
30788
+ /* No_padding */
30789
+ 0
30790
+ ),
30791
+ _1: (
30792
+ /* End_of_format */
30793
+ 0
30794
+ )
30795
+ }
30796
+ },
30797
+ _1: "MCA surfaced: %s"
30798
+ }), description);
30799
+ console.log(color("32", "\xE2\x9C\x93 ") + msg);
30800
+ }
30801
+ function run_mca_list(hub_path) {
30802
+ const dir = Path.join(hub_path, "state/mca");
30803
+ if (Fs.existsSync(dir)) {
30804
+ const items = Stdlib__List.sort(Stdlib__String.compare, Stdlib__List.filter(is_md_file, Stdlib__Array.to_list(Fs.readdirSync(dir))));
30805
+ if (items) {
30806
+ console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
30807
+ TAG: (
30808
+ /* Format */
30809
+ 0
30810
+ ),
30811
+ _0: {
30812
+ TAG: (
30813
+ /* String_literal */
30814
+ 11
30815
+ ),
30816
+ _0: "Open MCAs: ",
30817
+ _1: {
30818
+ TAG: (
30819
+ /* Int */
30820
+ 4
30821
+ ),
30822
+ _0: (
30823
+ /* Int_d */
30824
+ 0
30825
+ ),
30826
+ _1: (
30827
+ /* No_padding */
30828
+ 0
30829
+ ),
30830
+ _2: (
30831
+ /* No_precision */
30832
+ 0
30833
+ ),
30834
+ _3: (
30835
+ /* End_of_format */
30836
+ 0
30837
+ )
30838
+ }
30839
+ },
30840
+ _1: "Open MCAs: %d"
30841
+ }), Stdlib__List.length(items))));
30842
+ return Stdlib__List.iter((function(file) {
30843
+ const file_path = Path.join(dir, file);
30844
+ const content = Fs.readFileSync(file_path, "utf8");
30845
+ const meta = Cn_lib.parse_frontmatter(content);
30846
+ const id = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
30847
+ if (param[0] === "id") {
30848
+ return param[1];
30849
+ }
30850
+ }), meta), "?");
30851
+ const by = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
30852
+ if (param[0] === "surfaced-by") {
30853
+ return param[1];
30854
+ }
30855
+ }), meta), "?");
30856
+ const lines = Stdlib__String.split_on_char(
30857
+ /* '\n' */
30858
+ 10,
30859
+ content
30860
+ );
30861
+ const skip_frontmatter = function(_in_fm, _rest) {
30862
+ while (true) {
30863
+ const rest = _rest;
30864
+ const in_fm = _in_fm;
30865
+ if (!rest) {
30866
+ return (
30867
+ /* [] */
30868
+ 0
30869
+ );
30870
+ }
30871
+ if (rest.hd === "---") {
30872
+ const rest$1 = rest.tl;
30873
+ if (in_fm) {
30874
+ if (in_fm) {
30875
+ return rest$1;
30876
+ }
30877
+ } else {
30878
+ _rest = rest$1;
30879
+ _in_fm = true;
30880
+ continue;
30881
+ }
30882
+ }
30883
+ if (!in_fm) {
30884
+ return rest;
30885
+ }
30886
+ _rest = rest.tl;
30887
+ continue;
30888
+ }
30889
+ ;
30890
+ };
30891
+ const body_lines = skip_frontmatter(false, lines);
30892
+ const desc = Stdlib__Option.value(Stdlib__List.find_opt((function(l) {
30893
+ const t = Stdlib__String.trim(l);
30894
+ if (t !== "") {
30895
+ return !Cn_lib.starts_with("#", t);
30896
+ } else {
30897
+ return false;
30898
+ }
30899
+ }), body_lines), "(no description)");
30900
+ console.log(Curry._3(Stdlib__Printf.sprintf({
30901
+ TAG: (
30902
+ /* Format */
30903
+ 0
30904
+ ),
30905
+ _0: {
30906
+ TAG: (
30907
+ /* String_literal */
30908
+ 11
30909
+ ),
30910
+ _0: " [",
30911
+ _1: {
30912
+ TAG: (
30913
+ /* String */
30914
+ 2
30915
+ ),
30916
+ _0: (
30917
+ /* No_padding */
30918
+ 0
30919
+ ),
30920
+ _1: {
30921
+ TAG: (
30922
+ /* String_literal */
30923
+ 11
30924
+ ),
30925
+ _0: "] ",
30926
+ _1: {
30927
+ TAG: (
30928
+ /* String */
30929
+ 2
30930
+ ),
30931
+ _0: (
30932
+ /* No_padding */
30933
+ 0
30934
+ ),
30935
+ _1: {
30936
+ TAG: (
30937
+ /* String_literal */
30938
+ 11
30939
+ ),
30940
+ _0: " (by ",
30941
+ _1: {
30942
+ TAG: (
30943
+ /* String */
30944
+ 2
30945
+ ),
30946
+ _0: (
30947
+ /* No_padding */
30948
+ 0
30949
+ ),
30950
+ _1: {
30951
+ TAG: (
30952
+ /* Char_literal */
30953
+ 12
30954
+ ),
30955
+ _0: (
30956
+ /* ')' */
30957
+ 41
30958
+ ),
30959
+ _1: (
30960
+ /* End_of_format */
30961
+ 0
30962
+ )
30963
+ }
30964
+ }
30965
+ }
30966
+ }
30967
+ }
30968
+ }
30969
+ },
30970
+ _1: " [%s] %s (by %s)"
30971
+ }), id, Stdlib__String.trim(desc), by));
30972
+ }), items);
30973
+ } else {
30974
+ console.log("(no MCAs)");
30975
+ return;
30976
+ }
30977
+ }
30978
+ console.log("(no MCAs)");
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
+ }
31393
+ function update_runtime(hub_path) {
31394
+ const runtime_path = Path.join(hub_path, "state/runtime.md");
31395
+ const v = exec("cn --version 2>/dev/null");
31396
+ let cn_ver;
31397
+ if (v !== void 0) {
31398
+ const s = Stdlib__String.trim(v);
31399
+ const match2 = Stdlib__String.split_on_char(
31400
+ /* ' ' */
31401
+ 32,
31402
+ s
31403
+ );
31404
+ if (match2) {
31405
+ const match$1 = match2.tl;
31406
+ cn_ver = match$1 ? match$1.hd : "unknown";
31407
+ } else {
31408
+ cn_ver = "unknown";
31409
+ }
31410
+ } else {
31411
+ cn_ver = "unknown";
31412
+ }
31413
+ const v$1 = exec("openclaw --version 2>/dev/null");
31414
+ const oc_ver = v$1 !== void 0 ? Stdlib__String.trim(v$1) : "unknown";
31415
+ const hub_name = Cn_lib.derive_name(hub_path);
31416
+ const c = exec_in(hub_path, "git rev-parse --short HEAD 2>/dev/null");
31417
+ const hub_commit = c !== void 0 ? Stdlib__String.trim(c) : "unknown";
31418
+ const c$1 = exec("git -C $(npm root -g)/cnagent rev-parse --short HEAD 2>/dev/null");
31419
+ const cn_commit = c$1 !== void 0 ? Stdlib__String.trim(c$1) : "unknown";
31420
+ const peers_path = Path.join(hub_path, "state/peers.md");
31421
+ let peer_count;
31422
+ if (Fs.existsSync(peers_path)) {
31423
+ const content = Fs.readFileSync(peers_path, "utf8");
31424
+ const lines = Stdlib__String.split_on_char(
31425
+ /* '\n' */
31426
+ 10,
31427
+ content
31428
+ );
31429
+ peer_count = Stdlib__List.length(Stdlib__List.filter((function(l) {
31430
+ if (l.length > 2) {
31431
+ return Stdlib__String.sub(l, 0, 2) === "- ";
31432
+ } else {
31433
+ return false;
31434
+ }
31435
+ }), lines));
31436
+ } else {
31437
+ peer_count = 0;
31438
+ }
31439
+ const content$1 = Curry._8(Stdlib__Printf.sprintf({
31440
+ TAG: (
31441
+ /* Format */
31442
+ 0
31443
+ ),
31444
+ _0: {
31445
+ TAG: (
31446
+ /* String_literal */
31447
+ 11
31448
+ ),
31449
+ _0: "# Runtime State\n\nAuto-generated by `cn update`. Do not edit manually.\n\n```yaml\nsession_start: ",
31450
+ _1: {
31451
+ TAG: (
31452
+ /* String */
31453
+ 2
31454
+ ),
31455
+ _0: (
31456
+ /* No_padding */
31457
+ 0
31458
+ ),
31459
+ _1: {
31460
+ TAG: (
31461
+ /* String_literal */
31462
+ 11
31463
+ ),
31464
+ _0: "\ncn_version: ",
31465
+ _1: {
31466
+ TAG: (
31467
+ /* String */
31468
+ 2
31469
+ ),
31470
+ _0: (
30697
31471
  /* No_padding */
30698
31472
  0
30699
31473
  ),
@@ -32381,20 +33155,32 @@ if (cmd !== void 0) {
32381
33155
  run_queue_clear(hub_path$1);
32382
33156
  }
32383
33157
  break;
32384
- case /* Read */
33158
+ case /* Mca */
32385
33159
  5:
33160
+ const desc = cmd._0;
33161
+ if (
33162
+ /* tag */
33163
+ typeof desc === "number" || typeof desc === "string"
33164
+ ) {
33165
+ run_mca_list(hub_path$1);
33166
+ } else {
33167
+ run_mca_add(hub_path$1, name, desc._0);
33168
+ }
33169
+ break;
33170
+ case /* Read */
33171
+ 6:
32386
33172
  run_read(hub_path$1, cmd._0);
32387
33173
  break;
32388
33174
  case /* Reply */
32389
- 6:
33175
+ 7:
32390
33176
  run_reply(hub_path$1, cmd._0, cmd._1);
32391
33177
  break;
32392
33178
  case /* Send */
32393
- 7:
33179
+ 8:
32394
33180
  run_send(hub_path$1, cmd._0, cmd._1);
32395
33181
  break;
32396
33182
  case /* Gtd */
32397
- 8:
33183
+ 9:
32398
33184
  const t = cmd._0;
32399
33185
  switch (t.TAG) {
32400
33186
  case /* GtdDelete */
@@ -32420,11 +33206,11 @@ if (cmd !== void 0) {
32420
33206
  }
32421
33207
  break;
32422
33208
  case /* Commit */
32423
- 9:
33209
+ 10:
32424
33210
  run_commit(hub_path$1, name, cmd._0);
32425
33211
  break;
32426
33212
  case /* Save */
32427
- 10:
33213
+ 11:
32428
33214
  run_commit(hub_path$1, name, cmd._0);
32429
33215
  run_push(hub_path$1);
32430
33216
  break;
@@ -32475,6 +33261,7 @@ if (cmd !== void 0) {
32475
33261
  process.exit(1);
32476
33262
  }
32477
33263
  var info = cyan;
33264
+ var mca_review_interval = 5;
32478
33265
  module.exports = {
32479
33266
  Process,
32480
33267
  Fs: Fs$1,
@@ -32536,10 +33323,19 @@ module.exports = {
32536
33323
  queue_inbox_items,
32537
33324
  feed_next_input,
32538
33325
  wake_agent,
32539
- run_process,
32540
33326
  run_sync,
32541
33327
  run_queue_list,
32542
33328
  run_queue_clear,
33329
+ mca_dir,
33330
+ run_mca_add,
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,
32543
33339
  update_runtime,
32544
33340
  run_init,
32545
33341
  format_peers_md,