cnagent 2.1.19 → 2.1.22

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 +1202 -71
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cnagent",
3
- "version": "2.1.19",
3
+ "version": "2.1.22",
4
4
  "description": "Coherent Network agent CLI — everything runs through cn",
5
5
  "keywords": [
6
6
  "cn-agent",
package/tools/dist/cn.js CHANGED
@@ -11879,6 +11879,7 @@ 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
11881
  var Caml_obj = require_caml_obj();
11882
+ var Caml_option2 = require_caml_option();
11882
11883
  var Stdlib__List2 = require_list();
11883
11884
  var Stdlib__Option2 = require_option();
11884
11885
  var Stdlib__String2 = require_string();
@@ -11914,6 +11915,7 @@ var require_cn_lib = __commonJS({
11914
11915
  var Queue = {};
11915
11916
  var Mca = {};
11916
11917
  var Gtd = {};
11918
+ var Out = {};
11917
11919
  function string_of_agent_op(id) {
11918
11920
  switch (id.TAG) {
11919
11921
  case /* Ack */
@@ -12231,8 +12233,42 @@ var require_cn_lib = __commonJS({
12231
12233
  4:
12232
12234
  return "done " + t$1._0;
12233
12235
  }
12234
- case /* Commit */
12236
+ case /* Out */
12235
12237
  10:
12238
+ const match2 = t._0;
12239
+ switch (match2.TAG) {
12240
+ case /* Do */
12241
+ 0:
12242
+ const match$1 = match2._0;
12243
+ switch (match$1.TAG) {
12244
+ case /* Reply */
12245
+ 0:
12246
+ return "out do reply";
12247
+ case /* Send */
12248
+ 1:
12249
+ return "out do send " + match$1.to_;
12250
+ case /* Surface */
12251
+ 2:
12252
+ return "out do surface";
12253
+ case /* Noop */
12254
+ 3:
12255
+ return "out do noop";
12256
+ case /* Commit */
12257
+ 4:
12258
+ return "out do commit " + match$1.artifact;
12259
+ }
12260
+ case /* Defer */
12261
+ 1:
12262
+ return "out defer";
12263
+ case /* Delegate */
12264
+ 2:
12265
+ return "out delegate " + match2.to_;
12266
+ case /* Delete */
12267
+ 3:
12268
+ return "out delete";
12269
+ }
12270
+ case /* Commit */
12271
+ 11:
12236
12272
  const m = t._0;
12237
12273
  if (m !== void 0) {
12238
12274
  return "commit " + m;
@@ -12240,7 +12276,7 @@ var require_cn_lib = __commonJS({
12240
12276
  return "commit";
12241
12277
  }
12242
12278
  case /* Save */
12243
- 11:
12279
+ 12:
12244
12280
  const m$1 = t._0;
12245
12281
  if (m$1 !== void 0) {
12246
12282
  return "save " + m$1;
@@ -12544,6 +12580,287 @@ var require_cn_lib = __commonJS({
12544
12580
  return;
12545
12581
  }
12546
12582
  }
12583
+ function parse_flags_from_args(_acc, _param) {
12584
+ while (true) {
12585
+ const param = _param;
12586
+ const acc = _acc;
12587
+ if (!param) {
12588
+ return acc;
12589
+ }
12590
+ switch (param.hd) {
12591
+ case "--artifact":
12592
+ const match2 = param.tl;
12593
+ if (match2) {
12594
+ _param = match2.tl;
12595
+ _acc = {
12596
+ hd: [
12597
+ "artifact",
12598
+ match2.hd
12599
+ ],
12600
+ tl: acc
12601
+ };
12602
+ continue;
12603
+ }
12604
+ _param = param.tl;
12605
+ continue;
12606
+ case "--desc":
12607
+ const match$1 = param.tl;
12608
+ if (match$1) {
12609
+ _param = match$1.tl;
12610
+ _acc = {
12611
+ hd: [
12612
+ "desc",
12613
+ match$1.hd
12614
+ ],
12615
+ tl: acc
12616
+ };
12617
+ continue;
12618
+ }
12619
+ _param = param.tl;
12620
+ continue;
12621
+ case "--id":
12622
+ const match$2 = param.tl;
12623
+ if (match$2) {
12624
+ _param = match$2.tl;
12625
+ _acc = {
12626
+ hd: [
12627
+ "id",
12628
+ match$2.hd
12629
+ ],
12630
+ tl: acc
12631
+ };
12632
+ continue;
12633
+ }
12634
+ _param = param.tl;
12635
+ continue;
12636
+ case "--message":
12637
+ const match$3 = param.tl;
12638
+ if (match$3) {
12639
+ _param = match$3.tl;
12640
+ _acc = {
12641
+ hd: [
12642
+ "message",
12643
+ match$3.hd
12644
+ ],
12645
+ tl: acc
12646
+ };
12647
+ continue;
12648
+ }
12649
+ _param = param.tl;
12650
+ continue;
12651
+ case "--reason":
12652
+ const match$4 = param.tl;
12653
+ if (match$4) {
12654
+ _param = match$4.tl;
12655
+ _acc = {
12656
+ hd: [
12657
+ "reason",
12658
+ match$4.hd
12659
+ ],
12660
+ tl: acc
12661
+ };
12662
+ continue;
12663
+ }
12664
+ _param = param.tl;
12665
+ continue;
12666
+ case "--to":
12667
+ const match$5 = param.tl;
12668
+ if (match$5) {
12669
+ _param = match$5.tl;
12670
+ _acc = {
12671
+ hd: [
12672
+ "to",
12673
+ match$5.hd
12674
+ ],
12675
+ tl: acc
12676
+ };
12677
+ continue;
12678
+ }
12679
+ _param = param.tl;
12680
+ continue;
12681
+ default:
12682
+ _param = param.tl;
12683
+ continue;
12684
+ }
12685
+ }
12686
+ ;
12687
+ }
12688
+ function get_flag(key, flags) {
12689
+ return Stdlib__List2.find_map((function(param) {
12690
+ if (Caml_obj.caml_equal(param[0], key)) {
12691
+ return Caml_option2.some(param[1]);
12692
+ }
12693
+ }), flags);
12694
+ }
12695
+ function parse_out_cmd(args2) {
12696
+ const flags = parse_flags_from_args(
12697
+ /* [] */
12698
+ 0,
12699
+ args2
12700
+ );
12701
+ if (!args2) {
12702
+ return;
12703
+ }
12704
+ switch (args2.hd) {
12705
+ case "defer":
12706
+ return Stdlib__Option2.map((function(r) {
12707
+ return {
12708
+ TAG: (
12709
+ /* Defer */
12710
+ 1
12711
+ ),
12712
+ reason: r
12713
+ };
12714
+ }), get_flag("reason", flags));
12715
+ case "delegate":
12716
+ return Stdlib__Option2.map((function(t) {
12717
+ return {
12718
+ TAG: (
12719
+ /* Delegate */
12720
+ 2
12721
+ ),
12722
+ to_: t
12723
+ };
12724
+ }), get_flag("to", flags));
12725
+ case "delete":
12726
+ return Stdlib__Option2.map((function(r) {
12727
+ return {
12728
+ TAG: (
12729
+ /* Delete */
12730
+ 3
12731
+ ),
12732
+ reason: r
12733
+ };
12734
+ }), get_flag("reason", flags));
12735
+ case "do":
12736
+ const match2 = args2.tl;
12737
+ if (!match2) {
12738
+ return;
12739
+ }
12740
+ switch (match2.hd) {
12741
+ case "commit":
12742
+ return Stdlib__Option2.map((function(a) {
12743
+ return {
12744
+ TAG: (
12745
+ /* Do */
12746
+ 0
12747
+ ),
12748
+ _0: {
12749
+ TAG: (
12750
+ /* Commit */
12751
+ 4
12752
+ ),
12753
+ artifact: a
12754
+ }
12755
+ };
12756
+ }), get_flag("artifact", flags));
12757
+ case "noop":
12758
+ const r = get_flag("reason", flags);
12759
+ if (r === void 0) {
12760
+ return;
12761
+ }
12762
+ const r_lower = Stdlib__String2.lowercase_ascii(r);
12763
+ if (Stdlib__List2.mem(r_lower, {
12764
+ hd: "ack",
12765
+ tl: {
12766
+ hd: "ok",
12767
+ tl: {
12768
+ hd: "done",
12769
+ tl: {
12770
+ hd: "yes",
12771
+ tl: {
12772
+ hd: "no",
12773
+ tl: {
12774
+ hd: "acknowledged",
12775
+ tl: {
12776
+ hd: "noted",
12777
+ tl: (
12778
+ /* [] */
12779
+ 0
12780
+ )
12781
+ }
12782
+ }
12783
+ }
12784
+ }
12785
+ }
12786
+ }
12787
+ }) || r.length < 10) {
12788
+ return;
12789
+ } else {
12790
+ return {
12791
+ TAG: (
12792
+ /* Do */
12793
+ 0
12794
+ ),
12795
+ _0: {
12796
+ TAG: (
12797
+ /* Noop */
12798
+ 3
12799
+ ),
12800
+ reason: r
12801
+ }
12802
+ };
12803
+ }
12804
+ case "reply":
12805
+ return Stdlib__Option2.map((function(m) {
12806
+ return {
12807
+ TAG: (
12808
+ /* Do */
12809
+ 0
12810
+ ),
12811
+ _0: {
12812
+ TAG: (
12813
+ /* Reply */
12814
+ 0
12815
+ ),
12816
+ message: m
12817
+ }
12818
+ };
12819
+ }), get_flag("message", flags));
12820
+ case "send":
12821
+ const match$1 = get_flag("to", flags);
12822
+ const match$2 = get_flag("message", flags);
12823
+ if (match$1 !== void 0 && match$2 !== void 0) {
12824
+ return {
12825
+ TAG: (
12826
+ /* Do */
12827
+ 0
12828
+ ),
12829
+ _0: {
12830
+ TAG: (
12831
+ /* Send */
12832
+ 1
12833
+ ),
12834
+ to_: match$1,
12835
+ message: match$2
12836
+ }
12837
+ };
12838
+ } else {
12839
+ return;
12840
+ }
12841
+ case "surface":
12842
+ return Stdlib__Option2.map((function(d) {
12843
+ return {
12844
+ TAG: (
12845
+ /* Do */
12846
+ 0
12847
+ ),
12848
+ _0: {
12849
+ TAG: (
12850
+ /* Surface */
12851
+ 2
12852
+ ),
12853
+ desc: d
12854
+ }
12855
+ };
12856
+ }), get_flag("desc", flags));
12857
+ default:
12858
+ return;
12859
+ }
12860
+ default:
12861
+ return;
12862
+ }
12863
+ }
12547
12864
  function join_rest(rest) {
12548
12865
  if (rest) {
12549
12866
  return Stdlib__String2.concat(" ", rest);
@@ -12575,7 +12892,7 @@ var require_cn_lib = __commonJS({
12575
12892
  return {
12576
12893
  TAG: (
12577
12894
  /* Commit */
12578
- 10
12895
+ 11
12579
12896
  ),
12580
12897
  _0: join_rest(param.tl)
12581
12898
  };
@@ -12710,6 +13027,16 @@ var require_cn_lib = __commonJS({
12710
13027
  5
12711
13028
  );
12712
13029
  }
13030
+ case "out":
13031
+ return Stdlib__Option2.map((function(c) {
13032
+ return {
13033
+ TAG: (
13034
+ /* Out */
13035
+ 10
13036
+ ),
13037
+ _0: c
13038
+ };
13039
+ }), parse_out_cmd(param.tl));
12713
13040
  case "outbox":
12714
13041
  return Stdlib__Option2.map((function(c) {
12715
13042
  return {
@@ -12793,7 +13120,7 @@ var require_cn_lib = __commonJS({
12793
13120
  return {
12794
13121
  TAG: (
12795
13122
  /* Save */
12796
- 11
13123
+ 12
12797
13124
  ),
12798
13125
  _0: join_rest(param.tl)
12799
13126
  };
@@ -13266,7 +13593,7 @@ var require_cn_lib = __commonJS({
13266
13593
  );
13267
13594
  }
13268
13595
  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";
13269
- var version = "2.1.19";
13596
+ var version = "2.1.21";
13270
13597
  module2.exports = {
13271
13598
  starts_with,
13272
13599
  strip_prefix,
@@ -13278,6 +13605,7 @@ var require_cn_lib = __commonJS({
13278
13605
  Queue,
13279
13606
  Mca,
13280
13607
  Gtd,
13608
+ Out,
13281
13609
  string_of_agent_op,
13282
13610
  parse_agent_op,
13283
13611
  extract_ops,
@@ -13289,6 +13617,9 @@ var require_cn_lib = __commonJS({
13289
13617
  parse_queue_cmd,
13290
13618
  parse_mca_cmd,
13291
13619
  parse_gtd_cmd,
13620
+ parse_flags_from_args,
13621
+ get_flag,
13622
+ parse_out_cmd,
13292
13623
  join_rest,
13293
13624
  parse_command,
13294
13625
  default_flags,
@@ -26522,7 +26853,8 @@ function materialize_branch(hub_path, inbox_dir, peer_name, branch) {
26522
26853
  _1: "%s-%s.md"
26523
26854
  }), peer_name, branch_slug);
26524
26855
  const inbox_path = Path.join(inbox_dir, inbox_file);
26525
- if (Fs.existsSync(inbox_path)) {
26856
+ const archived_path = Path.join(Path.join(inbox_dir, "_archived"), inbox_file);
26857
+ if (Fs.existsSync(inbox_path) || Fs.existsSync(archived_path)) {
26526
26858
  return;
26527
26859
  }
26528
26860
  const meta_0 = [
@@ -32154,68 +32486,842 @@ function run_mca_list(hub_path) {
32154
32486
  }
32155
32487
  console.log("(no MCAs)");
32156
32488
  }
32157
- function mca_cycle_path(hub_path) {
32158
- return Path.join(hub_path, "state/.mca-cycle");
32159
- }
32160
- function get_mca_cycle(hub_path) {
32161
- const path = Path.join(hub_path, "state/.mca-cycle");
32162
- if (Fs.existsSync(path)) {
32163
- return Stdlib__Option.value(Stdlib.int_of_string_opt(Stdlib__String.trim(Fs.readFileSync(path, "utf8"))), 0);
32164
- } else {
32165
- return 0;
32166
- }
32167
- }
32168
- function increment_mca_cycle(hub_path) {
32169
- const current = get_mca_cycle(hub_path);
32170
- const next = current + 1 | 0;
32171
- const prim1 = String(next);
32172
- const prim0 = Path.join(hub_path, "state/.mca-cycle");
32173
- Fs.writeFileSync(prim0, prim1);
32174
- return next;
32175
- }
32176
- function mca_count(hub_path) {
32177
- const dir = Path.join(hub_path, "state/mca");
32178
- if (Fs.existsSync(dir)) {
32179
- return Stdlib__List.length(Stdlib__List.filter(is_md_file, Stdlib__Array.to_list(Fs.readdirSync(dir))));
32180
- } else {
32181
- return 0;
32182
- }
32183
- }
32184
- function queue_mca_review(hub_path) {
32185
- const dir = Path.join(hub_path, "state/mca");
32186
- const mcas = Stdlib__List.sort(Stdlib__String.compare, Stdlib__List.filter(is_md_file, Stdlib__Array.to_list(Fs.readdirSync(dir))));
32187
- const mca_list = Stdlib__String.concat("\n", Stdlib__List.map((function(file) {
32188
- const content = Fs.readFileSync(Path.join(dir, file), "utf8");
32189
- const meta = Cn_lib.parse_frontmatter(content);
32190
- const id = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
32191
- if (param[0] === "id") {
32192
- return param[1];
32193
- }
32194
- }), meta), "?");
32195
- const by = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
32196
- if (param[0] === "surfaced-by") {
32197
- return param[1];
32198
- }
32199
- }), meta), "?");
32200
- const lines = Stdlib__String.split_on_char(
32201
- /* '\n' */
32202
- 10,
32203
- content
32204
- );
32205
- const skip_fm = function(_in_fm, _rest) {
32206
- while (true) {
32207
- const rest = _rest;
32208
- const in_fm = _in_fm;
32209
- if (!rest) {
32210
- return (
32211
- /* [] */
32212
- 0
32213
- );
32214
- }
32215
- if (rest.hd === "---") {
32216
- const rest$1 = rest.tl;
32217
- if (in_fm) {
32218
- if (in_fm) {
32489
+ function run_out(hub_path, name, gtd) {
32490
+ const inp = Path.join(hub_path, "state/input.md");
32491
+ const input_meta = Fs.existsSync(inp) ? Cn_lib.parse_frontmatter(Fs.readFileSync(inp, "utf8")) : void 0;
32492
+ const input_id = input_meta !== void 0 ? Stdlib__List.find_map((function(param) {
32493
+ if (param[0] === "id") {
32494
+ return param[1];
32495
+ }
32496
+ }), input_meta) : void 0;
32497
+ const input_from = input_meta !== void 0 ? Stdlib__List.find_map((function(param) {
32498
+ if (param[0] === "from") {
32499
+ return param[1];
32500
+ }
32501
+ }), input_meta) : void 0;
32502
+ const outp = Path.join(hub_path, "state/output.md");
32503
+ const id = Stdlib__Option.value(input_id, "unknown");
32504
+ let match2;
32505
+ switch (gtd.TAG) {
32506
+ case /* Do */
32507
+ 0:
32508
+ const match$1 = gtd._0;
32509
+ switch (match$1.TAG) {
32510
+ case /* Reply */
32511
+ 0:
32512
+ match2 = [
32513
+ "do",
32514
+ Curry._1(Stdlib__Printf.sprintf({
32515
+ TAG: (
32516
+ /* Format */
32517
+ 0
32518
+ ),
32519
+ _0: {
32520
+ TAG: (
32521
+ /* String_literal */
32522
+ 11
32523
+ ),
32524
+ _0: "reply: ",
32525
+ _1: {
32526
+ TAG: (
32527
+ /* String */
32528
+ 2
32529
+ ),
32530
+ _0: (
32531
+ /* No_padding */
32532
+ 0
32533
+ ),
32534
+ _1: (
32535
+ /* End_of_format */
32536
+ 0
32537
+ )
32538
+ }
32539
+ },
32540
+ _1: "reply: %s"
32541
+ }), match$1.message)
32542
+ ];
32543
+ break;
32544
+ case /* Send */
32545
+ 1:
32546
+ match2 = [
32547
+ "do",
32548
+ Curry._2(Stdlib__Printf.sprintf({
32549
+ TAG: (
32550
+ /* Format */
32551
+ 0
32552
+ ),
32553
+ _0: {
32554
+ TAG: (
32555
+ /* String_literal */
32556
+ 11
32557
+ ),
32558
+ _0: "send: ",
32559
+ _1: {
32560
+ TAG: (
32561
+ /* String */
32562
+ 2
32563
+ ),
32564
+ _0: (
32565
+ /* No_padding */
32566
+ 0
32567
+ ),
32568
+ _1: {
32569
+ TAG: (
32570
+ /* Char_literal */
32571
+ 12
32572
+ ),
32573
+ _0: (
32574
+ /* '|' */
32575
+ 124
32576
+ ),
32577
+ _1: {
32578
+ TAG: (
32579
+ /* String */
32580
+ 2
32581
+ ),
32582
+ _0: (
32583
+ /* No_padding */
32584
+ 0
32585
+ ),
32586
+ _1: (
32587
+ /* End_of_format */
32588
+ 0
32589
+ )
32590
+ }
32591
+ }
32592
+ }
32593
+ },
32594
+ _1: "send: %s|%s"
32595
+ }), match$1.to_, match$1.message)
32596
+ ];
32597
+ break;
32598
+ case /* Surface */
32599
+ 2:
32600
+ match2 = [
32601
+ "do",
32602
+ Curry._1(Stdlib__Printf.sprintf({
32603
+ TAG: (
32604
+ /* Format */
32605
+ 0
32606
+ ),
32607
+ _0: {
32608
+ TAG: (
32609
+ /* String_literal */
32610
+ 11
32611
+ ),
32612
+ _0: "surface: ",
32613
+ _1: {
32614
+ TAG: (
32615
+ /* String */
32616
+ 2
32617
+ ),
32618
+ _0: (
32619
+ /* No_padding */
32620
+ 0
32621
+ ),
32622
+ _1: (
32623
+ /* End_of_format */
32624
+ 0
32625
+ )
32626
+ }
32627
+ },
32628
+ _1: "surface: %s"
32629
+ }), match$1.desc)
32630
+ ];
32631
+ break;
32632
+ case /* Noop */
32633
+ 3:
32634
+ match2 = [
32635
+ "do",
32636
+ Curry._1(Stdlib__Printf.sprintf({
32637
+ TAG: (
32638
+ /* Format */
32639
+ 0
32640
+ ),
32641
+ _0: {
32642
+ TAG: (
32643
+ /* String_literal */
32644
+ 11
32645
+ ),
32646
+ _0: "noop: ",
32647
+ _1: {
32648
+ TAG: (
32649
+ /* String */
32650
+ 2
32651
+ ),
32652
+ _0: (
32653
+ /* No_padding */
32654
+ 0
32655
+ ),
32656
+ _1: (
32657
+ /* End_of_format */
32658
+ 0
32659
+ )
32660
+ }
32661
+ },
32662
+ _1: "noop: %s"
32663
+ }), match$1.reason)
32664
+ ];
32665
+ break;
32666
+ case /* Commit */
32667
+ 4:
32668
+ match2 = [
32669
+ "do",
32670
+ Curry._1(Stdlib__Printf.sprintf({
32671
+ TAG: (
32672
+ /* Format */
32673
+ 0
32674
+ ),
32675
+ _0: {
32676
+ TAG: (
32677
+ /* String_literal */
32678
+ 11
32679
+ ),
32680
+ _0: "commit: ",
32681
+ _1: {
32682
+ TAG: (
32683
+ /* String */
32684
+ 2
32685
+ ),
32686
+ _0: (
32687
+ /* No_padding */
32688
+ 0
32689
+ ),
32690
+ _1: (
32691
+ /* End_of_format */
32692
+ 0
32693
+ )
32694
+ }
32695
+ },
32696
+ _1: "commit: %s"
32697
+ }), match$1.artifact)
32698
+ ];
32699
+ break;
32700
+ }
32701
+ break;
32702
+ case /* Defer */
32703
+ 1:
32704
+ match2 = [
32705
+ "defer",
32706
+ Curry._1(Stdlib__Printf.sprintf({
32707
+ TAG: (
32708
+ /* Format */
32709
+ 0
32710
+ ),
32711
+ _0: {
32712
+ TAG: (
32713
+ /* String_literal */
32714
+ 11
32715
+ ),
32716
+ _0: "reason: ",
32717
+ _1: {
32718
+ TAG: (
32719
+ /* String */
32720
+ 2
32721
+ ),
32722
+ _0: (
32723
+ /* No_padding */
32724
+ 0
32725
+ ),
32726
+ _1: (
32727
+ /* End_of_format */
32728
+ 0
32729
+ )
32730
+ }
32731
+ },
32732
+ _1: "reason: %s"
32733
+ }), gtd.reason)
32734
+ ];
32735
+ break;
32736
+ case /* Delegate */
32737
+ 2:
32738
+ match2 = [
32739
+ "delegate",
32740
+ Curry._1(Stdlib__Printf.sprintf({
32741
+ TAG: (
32742
+ /* Format */
32743
+ 0
32744
+ ),
32745
+ _0: {
32746
+ TAG: (
32747
+ /* String_literal */
32748
+ 11
32749
+ ),
32750
+ _0: "to: ",
32751
+ _1: {
32752
+ TAG: (
32753
+ /* String */
32754
+ 2
32755
+ ),
32756
+ _0: (
32757
+ /* No_padding */
32758
+ 0
32759
+ ),
32760
+ _1: (
32761
+ /* End_of_format */
32762
+ 0
32763
+ )
32764
+ }
32765
+ },
32766
+ _1: "to: %s"
32767
+ }), gtd.to_)
32768
+ ];
32769
+ break;
32770
+ case /* Delete */
32771
+ 3:
32772
+ match2 = [
32773
+ "delete",
32774
+ Curry._1(Stdlib__Printf.sprintf({
32775
+ TAG: (
32776
+ /* Format */
32777
+ 0
32778
+ ),
32779
+ _0: {
32780
+ TAG: (
32781
+ /* String_literal */
32782
+ 11
32783
+ ),
32784
+ _0: "reason: ",
32785
+ _1: {
32786
+ TAG: (
32787
+ /* String */
32788
+ 2
32789
+ ),
32790
+ _0: (
32791
+ /* No_padding */
32792
+ 0
32793
+ ),
32794
+ _1: (
32795
+ /* End_of_format */
32796
+ 0
32797
+ )
32798
+ }
32799
+ },
32800
+ _1: "reason: %s"
32801
+ }), gtd.reason)
32802
+ ];
32803
+ break;
32804
+ }
32805
+ const gtd_type = match2[0];
32806
+ const content = Curry._4(Stdlib__Printf.sprintf({
32807
+ TAG: (
32808
+ /* Format */
32809
+ 0
32810
+ ),
32811
+ _0: {
32812
+ TAG: (
32813
+ /* String_literal */
32814
+ 11
32815
+ ),
32816
+ _0: "---\nid: ",
32817
+ _1: {
32818
+ TAG: (
32819
+ /* String */
32820
+ 2
32821
+ ),
32822
+ _0: (
32823
+ /* No_padding */
32824
+ 0
32825
+ ),
32826
+ _1: {
32827
+ TAG: (
32828
+ /* String_literal */
32829
+ 11
32830
+ ),
32831
+ _0: "\ngtd: ",
32832
+ _1: {
32833
+ TAG: (
32834
+ /* String */
32835
+ 2
32836
+ ),
32837
+ _0: (
32838
+ /* No_padding */
32839
+ 0
32840
+ ),
32841
+ _1: {
32842
+ TAG: (
32843
+ /* Char_literal */
32844
+ 12
32845
+ ),
32846
+ _0: (
32847
+ /* '\n' */
32848
+ 10
32849
+ ),
32850
+ _1: {
32851
+ TAG: (
32852
+ /* String */
32853
+ 2
32854
+ ),
32855
+ _0: (
32856
+ /* No_padding */
32857
+ 0
32858
+ ),
32859
+ _1: {
32860
+ TAG: (
32861
+ /* String_literal */
32862
+ 11
32863
+ ),
32864
+ _0: "\ncreated: ",
32865
+ _1: {
32866
+ TAG: (
32867
+ /* String */
32868
+ 2
32869
+ ),
32870
+ _0: (
32871
+ /* No_padding */
32872
+ 0
32873
+ ),
32874
+ _1: {
32875
+ TAG: (
32876
+ /* String_literal */
32877
+ 11
32878
+ ),
32879
+ _0: "\n---\n",
32880
+ _1: (
32881
+ /* End_of_format */
32882
+ 0
32883
+ )
32884
+ }
32885
+ }
32886
+ }
32887
+ }
32888
+ }
32889
+ }
32890
+ }
32891
+ }
32892
+ },
32893
+ _1: "---\nid: %s\ngtd: %s\n%s\ncreated: %s\n---\n"
32894
+ }), id, gtd_type, match2[1], (/* @__PURE__ */ new Date()).toISOString());
32895
+ Fs.writeFileSync(outp, content);
32896
+ log_action(hub_path, "out", Curry._2(Stdlib__Printf.sprintf({
32897
+ TAG: (
32898
+ /* Format */
32899
+ 0
32900
+ ),
32901
+ _0: {
32902
+ TAG: (
32903
+ /* String_literal */
32904
+ 11
32905
+ ),
32906
+ _0: "id:",
32907
+ _1: {
32908
+ TAG: (
32909
+ /* String */
32910
+ 2
32911
+ ),
32912
+ _0: (
32913
+ /* No_padding */
32914
+ 0
32915
+ ),
32916
+ _1: {
32917
+ TAG: (
32918
+ /* String_literal */
32919
+ 11
32920
+ ),
32921
+ _0: " gtd:",
32922
+ _1: {
32923
+ TAG: (
32924
+ /* String */
32925
+ 2
32926
+ ),
32927
+ _0: (
32928
+ /* No_padding */
32929
+ 0
32930
+ ),
32931
+ _1: (
32932
+ /* End_of_format */
32933
+ 0
32934
+ )
32935
+ }
32936
+ }
32937
+ }
32938
+ },
32939
+ _1: "id:%s gtd:%s"
32940
+ }), id, gtd_type));
32941
+ const msg = Curry._2(Stdlib__Printf.sprintf({
32942
+ TAG: (
32943
+ /* Format */
32944
+ 0
32945
+ ),
32946
+ _0: {
32947
+ TAG: (
32948
+ /* String_literal */
32949
+ 11
32950
+ ),
32951
+ _0: "Output: ",
32952
+ _1: {
32953
+ TAG: (
32954
+ /* String */
32955
+ 2
32956
+ ),
32957
+ _0: (
32958
+ /* No_padding */
32959
+ 0
32960
+ ),
32961
+ _1: {
32962
+ TAG: (
32963
+ /* String_literal */
32964
+ 11
32965
+ ),
32966
+ _0: " (",
32967
+ _1: {
32968
+ TAG: (
32969
+ /* String */
32970
+ 2
32971
+ ),
32972
+ _0: (
32973
+ /* No_padding */
32974
+ 0
32975
+ ),
32976
+ _1: {
32977
+ TAG: (
32978
+ /* Char_literal */
32979
+ 12
32980
+ ),
32981
+ _0: (
32982
+ /* ')' */
32983
+ 41
32984
+ ),
32985
+ _1: (
32986
+ /* End_of_format */
32987
+ 0
32988
+ )
32989
+ }
32990
+ }
32991
+ }
32992
+ }
32993
+ },
32994
+ _1: "Output: %s (%s)"
32995
+ }), gtd_type, id);
32996
+ console.log(color("32", "\xE2\x9C\x93 ") + msg);
32997
+ if (input_from === void 0) {
32998
+ return;
32999
+ }
33000
+ if (!(input_from !== name && input_from !== "system")) {
33001
+ return;
33002
+ }
33003
+ const notify_msg = Curry._3(Stdlib__Printf.sprintf({
33004
+ TAG: (
33005
+ /* Format */
33006
+ 0
33007
+ ),
33008
+ _0: {
33009
+ TAG: (
33010
+ /* String_literal */
33011
+ 11
33012
+ ),
33013
+ _0: "[auto] ",
33014
+ _1: {
33015
+ TAG: (
33016
+ /* String */
33017
+ 2
33018
+ ),
33019
+ _0: (
33020
+ /* No_padding */
33021
+ 0
33022
+ ),
33023
+ _1: {
33024
+ TAG: (
33025
+ /* String_literal */
33026
+ 11
33027
+ ),
33028
+ _0: ": ",
33029
+ _1: {
33030
+ TAG: (
33031
+ /* String */
33032
+ 2
33033
+ ),
33034
+ _0: (
33035
+ /* No_padding */
33036
+ 0
33037
+ ),
33038
+ _1: {
33039
+ TAG: (
33040
+ /* String_literal */
33041
+ 11
33042
+ ),
33043
+ _0: " on ",
33044
+ _1: {
33045
+ TAG: (
33046
+ /* String */
33047
+ 2
33048
+ ),
33049
+ _0: (
33050
+ /* No_padding */
33051
+ 0
33052
+ ),
33053
+ _1: (
33054
+ /* End_of_format */
33055
+ 0
33056
+ )
33057
+ }
33058
+ }
33059
+ }
33060
+ }
33061
+ }
33062
+ },
33063
+ _1: "[auto] %s: %s on %s"
33064
+ }), name, gtd_type, id);
33065
+ const outbox_dir = Path.join(hub_path, "threads/outbox");
33066
+ ensure_dir(outbox_dir);
33067
+ const notify_file = Curry._2(Stdlib__Printf.sprintf({
33068
+ TAG: (
33069
+ /* Format */
33070
+ 0
33071
+ ),
33072
+ _0: {
33073
+ TAG: (
33074
+ /* String */
33075
+ 2
33076
+ ),
33077
+ _0: (
33078
+ /* No_padding */
33079
+ 0
33080
+ ),
33081
+ _1: {
33082
+ TAG: (
33083
+ /* String_literal */
33084
+ 11
33085
+ ),
33086
+ _0: "-auto-notify-",
33087
+ _1: {
33088
+ TAG: (
33089
+ /* String */
33090
+ 2
33091
+ ),
33092
+ _0: (
33093
+ /* No_padding */
33094
+ 0
33095
+ ),
33096
+ _1: {
33097
+ TAG: (
33098
+ /* String_literal */
33099
+ 11
33100
+ ),
33101
+ _0: ".md",
33102
+ _1: (
33103
+ /* End_of_format */
33104
+ 0
33105
+ )
33106
+ }
33107
+ }
33108
+ }
33109
+ },
33110
+ _1: "%s-auto-notify-%s.md"
33111
+ }), input_from, id);
33112
+ const notify_content = Curry._3(Stdlib__Printf.sprintf({
33113
+ TAG: (
33114
+ /* Format */
33115
+ 0
33116
+ ),
33117
+ _0: {
33118
+ TAG: (
33119
+ /* String_literal */
33120
+ 11
33121
+ ),
33122
+ _0: "---\nto: ",
33123
+ _1: {
33124
+ TAG: (
33125
+ /* String */
33126
+ 2
33127
+ ),
33128
+ _0: (
33129
+ /* No_padding */
33130
+ 0
33131
+ ),
33132
+ _1: {
33133
+ TAG: (
33134
+ /* String_literal */
33135
+ 11
33136
+ ),
33137
+ _0: "\ncreated: ",
33138
+ _1: {
33139
+ TAG: (
33140
+ /* String */
33141
+ 2
33142
+ ),
33143
+ _0: (
33144
+ /* No_padding */
33145
+ 0
33146
+ ),
33147
+ _1: {
33148
+ TAG: (
33149
+ /* String_literal */
33150
+ 11
33151
+ ),
33152
+ _0: "\nauto: true\n---\n\n",
33153
+ _1: {
33154
+ TAG: (
33155
+ /* String */
33156
+ 2
33157
+ ),
33158
+ _0: (
33159
+ /* No_padding */
33160
+ 0
33161
+ ),
33162
+ _1: {
33163
+ TAG: (
33164
+ /* Char_literal */
33165
+ 12
33166
+ ),
33167
+ _0: (
33168
+ /* '\n' */
33169
+ 10
33170
+ ),
33171
+ _1: (
33172
+ /* End_of_format */
33173
+ 0
33174
+ )
33175
+ }
33176
+ }
33177
+ }
33178
+ }
33179
+ }
33180
+ }
33181
+ },
33182
+ _1: "---\nto: %s\ncreated: %s\nauto: true\n---\n\n%s\n"
33183
+ }), input_from, (/* @__PURE__ */ new Date()).toISOString(), notify_msg);
33184
+ const prim0 = Path.join(outbox_dir, notify_file);
33185
+ Fs.writeFileSync(prim0, notify_content);
33186
+ log_action(hub_path, "out.notify", Curry._2(Stdlib__Printf.sprintf({
33187
+ TAG: (
33188
+ /* Format */
33189
+ 0
33190
+ ),
33191
+ _0: {
33192
+ TAG: (
33193
+ /* String_literal */
33194
+ 11
33195
+ ),
33196
+ _0: "to:",
33197
+ _1: {
33198
+ TAG: (
33199
+ /* String */
33200
+ 2
33201
+ ),
33202
+ _0: (
33203
+ /* No_padding */
33204
+ 0
33205
+ ),
33206
+ _1: {
33207
+ TAG: (
33208
+ /* String_literal */
33209
+ 11
33210
+ ),
33211
+ _0: " id:",
33212
+ _1: {
33213
+ TAG: (
33214
+ /* String */
33215
+ 2
33216
+ ),
33217
+ _0: (
33218
+ /* No_padding */
33219
+ 0
33220
+ ),
33221
+ _1: (
33222
+ /* End_of_format */
33223
+ 0
33224
+ )
33225
+ }
33226
+ }
33227
+ }
33228
+ },
33229
+ _1: "to:%s id:%s"
33230
+ }), input_from, id));
33231
+ const msg$1 = Curry._1(Stdlib__Printf.sprintf({
33232
+ TAG: (
33233
+ /* Format */
33234
+ 0
33235
+ ),
33236
+ _0: {
33237
+ TAG: (
33238
+ /* String_literal */
33239
+ 11
33240
+ ),
33241
+ _0: "Notified ",
33242
+ _1: {
33243
+ TAG: (
33244
+ /* String */
33245
+ 2
33246
+ ),
33247
+ _0: (
33248
+ /* No_padding */
33249
+ 0
33250
+ ),
33251
+ _1: (
33252
+ /* End_of_format */
33253
+ 0
33254
+ )
33255
+ }
33256
+ },
33257
+ _1: "Notified %s"
33258
+ }), input_from);
33259
+ console.log(color("32", "\xE2\x9C\x93 ") + msg$1);
33260
+ exec_in(hub_path, "git add -A && git commit -m '[auto] notify' && git push");
33261
+ console.log(color("32", "\xE2\x9C\x93 ") + "Pushed notification");
33262
+ }
33263
+ function mca_cycle_path(hub_path) {
33264
+ return Path.join(hub_path, "state/.mca-cycle");
33265
+ }
33266
+ function get_mca_cycle(hub_path) {
33267
+ const path = Path.join(hub_path, "state/.mca-cycle");
33268
+ if (Fs.existsSync(path)) {
33269
+ return Stdlib__Option.value(Stdlib.int_of_string_opt(Stdlib__String.trim(Fs.readFileSync(path, "utf8"))), 0);
33270
+ } else {
33271
+ return 0;
33272
+ }
33273
+ }
33274
+ function increment_mca_cycle(hub_path) {
33275
+ const current = get_mca_cycle(hub_path);
33276
+ const next = current + 1 | 0;
33277
+ const prim1 = String(next);
33278
+ const prim0 = Path.join(hub_path, "state/.mca-cycle");
33279
+ Fs.writeFileSync(prim0, prim1);
33280
+ return next;
33281
+ }
33282
+ function mca_count(hub_path) {
33283
+ const dir = Path.join(hub_path, "state/mca");
33284
+ if (Fs.existsSync(dir)) {
33285
+ return Stdlib__List.length(Stdlib__List.filter(is_md_file, Stdlib__Array.to_list(Fs.readdirSync(dir))));
33286
+ } else {
33287
+ return 0;
33288
+ }
33289
+ }
33290
+ function queue_mca_review(hub_path) {
33291
+ const dir = Path.join(hub_path, "state/mca");
33292
+ const mcas = Stdlib__List.sort(Stdlib__String.compare, Stdlib__List.filter(is_md_file, Stdlib__Array.to_list(Fs.readdirSync(dir))));
33293
+ const mca_list = Stdlib__String.concat("\n", Stdlib__List.map((function(file) {
33294
+ const content = Fs.readFileSync(Path.join(dir, file), "utf8");
33295
+ const meta = Cn_lib.parse_frontmatter(content);
33296
+ const id = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
33297
+ if (param[0] === "id") {
33298
+ return param[1];
33299
+ }
33300
+ }), meta), "?");
33301
+ const by = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
33302
+ if (param[0] === "surfaced-by") {
33303
+ return param[1];
33304
+ }
33305
+ }), meta), "?");
33306
+ const lines = Stdlib__String.split_on_char(
33307
+ /* '\n' */
33308
+ 10,
33309
+ content
33310
+ );
33311
+ const skip_fm = function(_in_fm, _rest) {
33312
+ while (true) {
33313
+ const rest = _rest;
33314
+ const in_fm = _in_fm;
33315
+ if (!rest) {
33316
+ return (
33317
+ /* [] */
33318
+ 0
33319
+ );
33320
+ }
33321
+ if (rest.hd === "---") {
33322
+ const rest$1 = rest.tl;
33323
+ if (in_fm) {
33324
+ if (in_fm) {
32219
33325
  return rest$1;
32220
33326
  }
32221
33327
  } else {
@@ -33112,6 +34218,7 @@ function run_init(name) {
33112
34218
  const prim0$3 = Path.join(hub_dir, "state/peers.md");
33113
34219
  Fs.writeFileSync(prim0$3, peers);
33114
34220
  exec_in(hub_dir, "git init");
34221
+ update_runtime(hub_dir);
33115
34222
  exec_in(hub_dir, "git add -A");
33116
34223
  exec_in(hub_dir, Curry._1(Stdlib__Printf.sprintf({
33117
34224
  TAG: (
@@ -33148,7 +34255,6 @@ function run_init(name) {
33148
34255
  },
33149
34256
  _1: "git commit -m 'Initialize %s hub'"
33150
34257
  }), hub_name));
33151
- update_runtime(hub_dir);
33152
34258
  const msg$1 = Curry._1(Stdlib__Printf.sprintf({
33153
34259
  TAG: (
33154
34260
  /* Format */
@@ -34251,6 +35357,26 @@ function run_update_with_cron(hub_path) {
34251
35357
  run_update(void 0);
34252
35358
  update_cron(hub_path);
34253
35359
  update_runtime(hub_path);
35360
+ console.log(color("36", "Auto-committing runtime changes..."));
35361
+ exec_in(hub_path, "git add state/runtime.md");
35362
+ const commit_result = exec_in(hub_path, "git commit -m 'chore: cn update runtime'");
35363
+ if (commit_result !== void 0) {
35364
+ console.log(color("32", "\xE2\x9C\x93 ") + "Committed runtime changes");
35365
+ const match2 = exec_in(hub_path, "git remote get-url origin 2>/dev/null");
35366
+ if (match2 !== void 0) {
35367
+ console.log(color("36", "Pushing to origin..."));
35368
+ const match$1 = exec_in(hub_path, "git push origin HEAD 2>&1");
35369
+ if (match$1 !== void 0) {
35370
+ console.log(color("32", "\xE2\x9C\x93 ") + "Pushed to origin");
35371
+ } else {
35372
+ console.log(color("33", "\xE2\x9A\xA0 ") + "Push failed - push manually");
35373
+ }
35374
+ return;
35375
+ }
35376
+ console.log(color("2", "No origin remote - skipping push"));
35377
+ return;
35378
+ }
35379
+ console.log(color("2", "No runtime changes to commit"));
34254
35380
  }
34255
35381
  function drop(n, lst) {
34256
35382
  let _n = n;
@@ -34488,12 +35614,16 @@ if (cmd !== void 0) {
34488
35614
  break;
34489
35615
  }
34490
35616
  break;
34491
- case /* Commit */
35617
+ case /* Out */
34492
35618
  10:
35619
+ run_out(hub_path$1, name, cmd._0);
35620
+ break;
35621
+ case /* Commit */
35622
+ 11:
34493
35623
  run_commit(hub_path$1, name, cmd._0);
34494
35624
  break;
34495
35625
  case /* Save */
34496
- 11:
35626
+ 12:
34497
35627
  run_commit(hub_path$1, name, cmd._0);
34498
35628
  run_push(hub_path$1);
34499
35629
  break;
@@ -34613,6 +35743,7 @@ module.exports = {
34613
35743
  run_queue_clear,
34614
35744
  run_mca_add,
34615
35745
  run_mca_list,
35746
+ run_out,
34616
35747
  mca_cycle_path,
34617
35748
  mca_review_interval,
34618
35749
  get_mca_cycle,