cnagent 2.2.6 → 2.2.8

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 +514 -167
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cnagent",
3
- "version": "2.2.6",
3
+ "version": "2.2.8",
4
4
  "description": "Coherent Network agent CLI — everything runs through cn",
5
5
  "keywords": [
6
6
  "cn-agent",
package/tools/dist/cn.js CHANGED
@@ -13598,7 +13598,7 @@ var require_cn_lib = __commonJS({
13598
13598
  );
13599
13599
  }
13600
13600
  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 in Queue inbox \xE2\x86\x92 input.md \xE2\x86\x92 wake agent (alias: inbound, process)\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";
13601
- var version = "2.2.6";
13601
+ var version = "2.2.8";
13602
13602
  module2.exports = {
13603
13603
  starts_with,
13604
13604
  strip_prefix,
@@ -26699,6 +26699,78 @@ function inbox_check(hub_path, name) {
26699
26699
  return;
26700
26700
  }
26701
26701
  }
26702
+ function delete_remote_branch(hub_path, branch) {
26703
+ const cmd2 = Curry._1(Stdlib__Printf.sprintf({
26704
+ TAG: (
26705
+ /* Format */
26706
+ 0
26707
+ ),
26708
+ _0: {
26709
+ TAG: (
26710
+ /* String_literal */
26711
+ 11
26712
+ ),
26713
+ _0: "git push origin --delete ",
26714
+ _1: {
26715
+ TAG: (
26716
+ /* String */
26717
+ 2
26718
+ ),
26719
+ _0: (
26720
+ /* No_padding */
26721
+ 0
26722
+ ),
26723
+ _1: {
26724
+ TAG: (
26725
+ /* String_literal */
26726
+ 11
26727
+ ),
26728
+ _0: " 2>/dev/null",
26729
+ _1: (
26730
+ /* End_of_format */
26731
+ 0
26732
+ )
26733
+ }
26734
+ }
26735
+ },
26736
+ _1: "git push origin --delete %s 2>/dev/null"
26737
+ }), branch);
26738
+ const match2 = exec_in(hub_path, cmd2);
26739
+ if (match2 !== void 0) {
26740
+ log_action(hub_path, "branch.delete", branch);
26741
+ console.log(color("2", Curry._1(Stdlib__Printf.sprintf({
26742
+ TAG: (
26743
+ /* Format */
26744
+ 0
26745
+ ),
26746
+ _0: {
26747
+ TAG: (
26748
+ /* String_literal */
26749
+ 11
26750
+ ),
26751
+ _0: " Deleted remote: ",
26752
+ _1: {
26753
+ TAG: (
26754
+ /* String */
26755
+ 2
26756
+ ),
26757
+ _0: (
26758
+ /* No_padding */
26759
+ 0
26760
+ ),
26761
+ _1: (
26762
+ /* End_of_format */
26763
+ 0
26764
+ )
26765
+ }
26766
+ },
26767
+ _1: " Deleted remote: %s"
26768
+ }), branch)));
26769
+ return true;
26770
+ } else {
26771
+ return false;
26772
+ }
26773
+ }
26702
26774
  function materialize_branch(hub_path, inbox_dir, peer_name, branch) {
26703
26775
  const diff_cmd = Curry._2(Stdlib__Printf.sprintf({
26704
26776
  TAG: (
@@ -26752,18 +26824,68 @@ function materialize_branch(hub_path, inbox_dir, peer_name, branch) {
26752
26824
  },
26753
26825
  _1: "git diff main...origin/%s --name-only 2>/dev/null || git diff master...origin/%s --name-only"
26754
26826
  }), branch, branch);
26755
- return Stdlib__List.filter_map((function(file) {
26756
- const show_cmd = Curry._2(Stdlib__Printf.sprintf({
26827
+ const files = Stdlib__List.filter(is_md_file, Stdlib__Option.value(
26828
+ Stdlib__Option.map(split_lines, exec_in(hub_path, diff_cmd)),
26829
+ /* [] */
26830
+ 0
26831
+ ));
26832
+ const trigger = Stdlib__Option.value(Stdlib__Option.map(Stdlib__String.trim, exec_in(hub_path, Curry._1(Stdlib__Printf.sprintf({
26833
+ TAG: (
26834
+ /* Format */
26835
+ 0
26836
+ ),
26837
+ _0: {
26757
26838
  TAG: (
26758
- /* Format */
26839
+ /* String_literal */
26840
+ 11
26841
+ ),
26842
+ _0: "git rev-parse origin/",
26843
+ _1: {
26844
+ TAG: (
26845
+ /* String */
26846
+ 2
26847
+ ),
26848
+ _0: (
26849
+ /* No_padding */
26850
+ 0
26851
+ ),
26852
+ _1: (
26853
+ /* End_of_format */
26854
+ 0
26855
+ )
26856
+ }
26857
+ },
26858
+ _1: "git rev-parse origin/%s"
26859
+ }), branch))), "unknown");
26860
+ const match2 = Stdlib__List.rev(Stdlib__String.split_on_char(
26861
+ /* '/' */
26862
+ 47,
26863
+ branch
26864
+ ));
26865
+ const branch_slug = match2 ? match2.hd : branch;
26866
+ const inbox_file = Curry._2(Stdlib__Printf.sprintf({
26867
+ TAG: (
26868
+ /* Format */
26869
+ 0
26870
+ ),
26871
+ _0: {
26872
+ TAG: (
26873
+ /* String */
26874
+ 2
26875
+ ),
26876
+ _0: (
26877
+ /* No_padding */
26759
26878
  0
26760
26879
  ),
26761
- _0: {
26880
+ _1: {
26762
26881
  TAG: (
26763
- /* String_literal */
26764
- 11
26882
+ /* Char_literal */
26883
+ 12
26884
+ ),
26885
+ _0: (
26886
+ /* '-' */
26887
+ 45
26765
26888
  ),
26766
- _0: "git show origin/",
26767
26889
  _1: {
26768
26890
  TAG: (
26769
26891
  /* String */
@@ -26775,134 +26897,162 @@ function materialize_branch(hub_path, inbox_dir, peer_name, branch) {
26775
26897
  ),
26776
26898
  _1: {
26777
26899
  TAG: (
26778
- /* Char_literal */
26779
- 12
26900
+ /* String_literal */
26901
+ 11
26902
+ ),
26903
+ _0: ".md",
26904
+ _1: (
26905
+ /* End_of_format */
26906
+ 0
26907
+ )
26908
+ }
26909
+ }
26910
+ }
26911
+ },
26912
+ _1: "%s-%s.md"
26913
+ }), peer_name, branch_slug);
26914
+ const inbox_path = Path.join(inbox_dir, inbox_file);
26915
+ const archived_path = Path.join(Path.join(inbox_dir, "_archived"), inbox_file);
26916
+ if (Fs.existsSync(inbox_path) || Fs.existsSync(archived_path)) {
26917
+ delete_remote_branch(hub_path, branch);
26918
+ return (
26919
+ /* [] */
26920
+ 0
26921
+ );
26922
+ } else {
26923
+ return Stdlib__List.filter_map((function(file) {
26924
+ const show_cmd = Curry._2(Stdlib__Printf.sprintf({
26925
+ TAG: (
26926
+ /* Format */
26927
+ 0
26928
+ ),
26929
+ _0: {
26930
+ TAG: (
26931
+ /* String_literal */
26932
+ 11
26933
+ ),
26934
+ _0: "git show origin/",
26935
+ _1: {
26936
+ TAG: (
26937
+ /* String */
26938
+ 2
26780
26939
  ),
26781
26940
  _0: (
26782
- /* ':' */
26783
- 58
26941
+ /* No_padding */
26942
+ 0
26784
26943
  ),
26785
26944
  _1: {
26786
26945
  TAG: (
26787
- /* String */
26788
- 2
26946
+ /* Char_literal */
26947
+ 12
26789
26948
  ),
26790
26949
  _0: (
26791
- /* No_padding */
26792
- 0
26950
+ /* ':' */
26951
+ 58
26793
26952
  ),
26794
- _1: (
26795
- /* End_of_format */
26953
+ _1: {
26954
+ TAG: (
26955
+ /* String */
26956
+ 2
26957
+ ),
26958
+ _0: (
26959
+ /* No_padding */
26960
+ 0
26961
+ ),
26962
+ _1: (
26963
+ /* End_of_format */
26964
+ 0
26965
+ )
26966
+ }
26967
+ }
26968
+ }
26969
+ },
26970
+ _1: "git show origin/%s:%s"
26971
+ }), branch, file);
26972
+ const content = exec_in(hub_path, show_cmd);
26973
+ if (content === void 0) {
26974
+ return;
26975
+ }
26976
+ const meta_0 = [
26977
+ "from",
26978
+ peer_name
26979
+ ];
26980
+ const meta_1 = {
26981
+ hd: [
26982
+ "branch",
26983
+ branch
26984
+ ],
26985
+ tl: {
26986
+ hd: [
26987
+ "trigger",
26988
+ trigger
26989
+ ],
26990
+ tl: {
26991
+ hd: [
26992
+ "file",
26993
+ file
26994
+ ],
26995
+ tl: {
26996
+ hd: [
26997
+ "received",
26998
+ (/* @__PURE__ */ new Date()).toISOString()
26999
+ ],
27000
+ tl: (
27001
+ /* [] */
26796
27002
  0
26797
27003
  )
26798
27004
  }
26799
27005
  }
26800
27006
  }
26801
- },
26802
- _1: "git show origin/%s:%s"
26803
- }), branch, file);
26804
- const content = exec_in(hub_path, show_cmd);
26805
- if (content === void 0) {
26806
- return;
26807
- }
26808
- const match2 = Stdlib__List.rev(Stdlib__String.split_on_char(
26809
- /* '/' */
26810
- 47,
26811
- branch
26812
- ));
26813
- const branch_slug = match2 ? match2.hd : branch;
26814
- const inbox_file = Curry._2(Stdlib__Printf.sprintf({
26815
- TAG: (
26816
- /* Format */
26817
- 0
26818
- ),
26819
- _0: {
27007
+ };
27008
+ const meta = {
27009
+ hd: meta_0,
27010
+ tl: meta_1
27011
+ };
27012
+ const prim1 = Cn_lib.update_frontmatter(content, meta);
27013
+ Fs.writeFileSync(inbox_path, prim1);
27014
+ log_action(hub_path, "inbox.materialize", Curry._2(Stdlib__Printf.sprintf({
26820
27015
  TAG: (
26821
- /* String */
26822
- 2
26823
- ),
26824
- _0: (
26825
- /* No_padding */
27016
+ /* Format */
26826
27017
  0
26827
27018
  ),
26828
- _1: {
27019
+ _0: {
26829
27020
  TAG: (
26830
- /* Char_literal */
26831
- 12
27021
+ /* String */
27022
+ 2
26832
27023
  ),
26833
27024
  _0: (
26834
- /* '-' */
26835
- 45
27025
+ /* No_padding */
27026
+ 0
26836
27027
  ),
26837
27028
  _1: {
26838
27029
  TAG: (
26839
- /* String */
26840
- 2
26841
- ),
26842
- _0: (
26843
- /* No_padding */
26844
- 0
27030
+ /* String_literal */
27031
+ 11
26845
27032
  ),
27033
+ _0: " trigger:",
26846
27034
  _1: {
26847
27035
  TAG: (
26848
- /* String_literal */
26849
- 11
27036
+ /* String */
27037
+ 2
27038
+ ),
27039
+ _0: (
27040
+ /* No_padding */
27041
+ 0
26850
27042
  ),
26851
- _0: ".md",
26852
27043
  _1: (
26853
27044
  /* End_of_format */
26854
27045
  0
26855
27046
  )
26856
27047
  }
26857
27048
  }
26858
- }
26859
- },
26860
- _1: "%s-%s.md"
26861
- }), peer_name, branch_slug);
26862
- const inbox_path = Path.join(inbox_dir, inbox_file);
26863
- const archived_path = Path.join(Path.join(inbox_dir, "_archived"), inbox_file);
26864
- if (Fs.existsSync(inbox_path) || Fs.existsSync(archived_path)) {
26865
- return;
26866
- }
26867
- const meta_0 = [
26868
- "from",
26869
- peer_name
26870
- ];
26871
- const meta_1 = {
26872
- hd: [
26873
- "branch",
26874
- branch
26875
- ],
26876
- tl: {
26877
- hd: [
26878
- "file",
26879
- file
26880
- ],
26881
- tl: {
26882
- hd: [
26883
- "received",
26884
- (/* @__PURE__ */ new Date()).toISOString()
26885
- ],
26886
- tl: (
26887
- /* [] */
26888
- 0
26889
- )
26890
- }
26891
- }
26892
- };
26893
- const meta = {
26894
- hd: meta_0,
26895
- tl: meta_1
26896
- };
26897
- const prim1 = Cn_lib.update_frontmatter(content, meta);
26898
- Fs.writeFileSync(inbox_path, prim1);
26899
- log_action(hub_path, "inbox.materialize", inbox_file);
26900
- return inbox_file;
26901
- }), Stdlib__List.filter(is_md_file, Stdlib__Option.value(
26902
- Stdlib__Option.map(split_lines, exec_in(hub_path, diff_cmd)),
26903
- /* [] */
26904
- 0
26905
- )));
27049
+ },
27050
+ _1: "%s trigger:%s"
27051
+ }), inbox_file, trigger));
27052
+ delete_remote_branch(hub_path, branch);
27053
+ return inbox_file;
27054
+ }), files);
27055
+ }
26906
27056
  }
26907
27057
  function inbox_process(hub_path) {
26908
27058
  console.log(color("36", "Processing inbox..."));
@@ -31432,29 +31582,23 @@ function execute_op(hub_path, name, input_id, op) {
31432
31582
  return;
31433
31583
  }
31434
31584
  }
31585
+ function generate_trigger(param) {
31586
+ return (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
31587
+ }
31435
31588
  function archive_io_pair(hub_path, name) {
31436
31589
  const inp = Path.join(hub_path, "state/input.md");
31437
31590
  const outp = Path.join(hub_path, "state/output.md");
31438
- const match2 = get_file_id(inp);
31439
- const match$1 = get_file_id(outp);
31440
- if (match2 === void 0) {
31441
- if (match$1 !== void 0) {
31442
- console.log(color("33", "\xE2\x9A\xA0 ") + "Orphan output.md found (no input.md)");
31443
- return false;
31444
- } else {
31445
- return true;
31446
- }
31447
- }
31448
- if (match$1 === void 0) {
31449
- return false;
31450
- }
31451
- if (match2 === match$1) {
31591
+ const arg = generate_trigger(void 0);
31592
+ const trigger = (function(param) {
31593
+ return Stdlib__Option.value(param, arg);
31594
+ })(get_file_id(inp));
31595
+ if (Fs.existsSync(outp)) {
31452
31596
  const logs_in = Path.join(hub_path, "logs/input");
31453
31597
  const logs_out = Path.join(hub_path, "logs/output");
31454
31598
  ensure_dir(logs_in);
31455
31599
  ensure_dir(logs_out);
31456
31600
  const output_content = Fs.readFileSync(outp, "utf8");
31457
- const archive_name = match2 + ".md";
31601
+ const archive_name = trigger + ".md";
31458
31602
  const prim1 = Fs.readFileSync(inp, "utf8");
31459
31603
  const prim0 = Path.join(logs_in, archive_name);
31460
31604
  Fs.writeFileSync(prim0, prim1);
@@ -31491,7 +31635,7 @@ function archive_io_pair(hub_path, name) {
31491
31635
  },
31492
31636
  _1: "Executing: %s"
31493
31637
  }), Cn_lib.string_of_agent_op(op))));
31494
- execute_op(hub_path, name, match2, op);
31638
+ execute_op(hub_path, name, trigger, op);
31495
31639
  }), ops);
31496
31640
  Fs.unlinkSync(inp);
31497
31641
  Fs.unlinkSync(outp);
@@ -31505,7 +31649,7 @@ function archive_io_pair(hub_path, name) {
31505
31649
  /* String_literal */
31506
31650
  11
31507
31651
  ),
31508
- _0: "id:",
31652
+ _0: "trigger:",
31509
31653
  _1: {
31510
31654
  TAG: (
31511
31655
  /* String */
@@ -31546,8 +31690,8 @@ function archive_io_pair(hub_path, name) {
31546
31690
  }
31547
31691
  }
31548
31692
  },
31549
- _1: "id:%s ops:%d"
31550
- }), match2, Stdlib__List.length(ops)));
31693
+ _1: "trigger:%s ops:%d"
31694
+ }), trigger, Stdlib__List.length(ops)));
31551
31695
  const msg = Curry._2(Stdlib__Printf.sprintf({
31552
31696
  TAG: (
31553
31697
  /* Format */
@@ -31558,7 +31702,7 @@ function archive_io_pair(hub_path, name) {
31558
31702
  /* String_literal */
31559
31703
  11
31560
31704
  ),
31561
- _0: "Archived IO pair: ",
31705
+ _0: "Archived: ",
31562
31706
  _1: {
31563
31707
  TAG: (
31564
31708
  /* String */
@@ -31606,12 +31750,46 @@ function archive_io_pair(hub_path, name) {
31606
31750
  }
31607
31751
  }
31608
31752
  },
31609
- _1: "Archived IO pair: %s (%d ops)"
31610
- }), match2, Stdlib__List.length(ops));
31753
+ _1: "Archived: %s (%d ops)"
31754
+ }), trigger, Stdlib__List.length(ops));
31611
31755
  console.log(color("32", "\xE2\x9C\x93 ") + msg);
31612
31756
  return true;
31613
31757
  }
31614
- console.log(color("31", "\xE2\x9C\x97 ") + "ID mismatch between input.md and output.md");
31758
+ console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
31759
+ TAG: (
31760
+ /* Format */
31761
+ 0
31762
+ ),
31763
+ _0: {
31764
+ TAG: (
31765
+ /* String_literal */
31766
+ 11
31767
+ ),
31768
+ _0: "Waiting: trigger=",
31769
+ _1: {
31770
+ TAG: (
31771
+ /* String */
31772
+ 2
31773
+ ),
31774
+ _0: (
31775
+ /* No_padding */
31776
+ 0
31777
+ ),
31778
+ _1: {
31779
+ TAG: (
31780
+ /* String_literal */
31781
+ 11
31782
+ ),
31783
+ _0: ", no output yet",
31784
+ _1: (
31785
+ /* End_of_format */
31786
+ 0
31787
+ )
31788
+ }
31789
+ }
31790
+ },
31791
+ _1: "Waiting: trigger=%s, no output yet"
31792
+ }), trigger)));
31615
31793
  return false;
31616
31794
  }
31617
31795
  function queue_inbox_items(hub_path) {
@@ -31627,13 +31805,20 @@ function queue_inbox_items(hub_path) {
31627
31805
  if (is_queued) {
31628
31806
  return;
31629
31807
  }
31630
- const id = Path.basename(file, ".md");
31808
+ const arg = Path.basename(file, ".md");
31809
+ const trigger = (function(param) {
31810
+ return Stdlib__Option.value(param, arg);
31811
+ })(Stdlib__List.find_map((function(param) {
31812
+ if (param[0] === "trigger") {
31813
+ return param[1];
31814
+ }
31815
+ }), meta));
31631
31816
  const from = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
31632
31817
  if (param[0] === "from") {
31633
31818
  return param[1];
31634
31819
  }
31635
31820
  }), meta), "unknown");
31636
- queue_add(hub_path, id, from, content);
31821
+ queue_add(hub_path, trigger, from, content);
31637
31822
  const prim1 = Cn_lib.update_frontmatter(content, {
31638
31823
  hd: [
31639
31824
  "queued-for-processing",
@@ -31699,7 +31884,7 @@ function queue_inbox_items(hub_path) {
31699
31884
  }
31700
31885
  },
31701
31886
  _1: "Queued: %s (from %s)"
31702
- }), id, from);
31887
+ }), trigger, from);
31703
31888
  console.log(color("32", "\xE2\x9C\x93 ") + msg);
31704
31889
  return file;
31705
31890
  }), Stdlib__List.filter(is_md_file, Stdlib__Array.to_list(Fs.readdirSync(inbox_dir)))));
@@ -33820,7 +34005,7 @@ function mca_count(hub_path) {
33820
34005
  return 0;
33821
34006
  }
33822
34007
  }
33823
- function queue_mca_review(hub_path) {
34008
+ function queue_mca_review(hub_path, name) {
33824
34009
  const dir = Path.join(hub_path, "state/mca");
33825
34010
  const mcas = Stdlib__List.sort(Stdlib__String.compare, Stdlib__List.filter(is_md_file, Stdlib__Array.to_list(Fs.readdirSync(dir))));
33826
34011
  const mca_list = Stdlib__String.concat("\n", Stdlib__List.map((function(file) {
@@ -33953,7 +34138,8 @@ function queue_mca_review(hub_path) {
33953
34138
  _1: "- [%s] %s (by %s)"
33954
34139
  }), id, Stdlib__String.trim(desc), by);
33955
34140
  }), mcas));
33956
- const review_id = Curry._1(Stdlib__Printf.sprintf({
34141
+ const ts = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
34142
+ const event_file = Curry._1(Stdlib__Printf.sprintf({
33957
34143
  TAG: (
33958
34144
  /* Format */
33959
34145
  0
@@ -33963,7 +34149,7 @@ function queue_mca_review(hub_path) {
33963
34149
  /* String_literal */
33964
34150
  11
33965
34151
  ),
33966
- _0: "mca-review-",
34152
+ _0: "threads/system/mca-review-",
33967
34153
  _1: {
33968
34154
  TAG: (
33969
34155
  /* String */
@@ -33973,15 +34159,81 @@ function queue_mca_review(hub_path) {
33973
34159
  /* No_padding */
33974
34160
  0
33975
34161
  ),
33976
- _1: (
33977
- /* End_of_format */
34162
+ _1: {
34163
+ TAG: (
34164
+ /* String_literal */
34165
+ 11
34166
+ ),
34167
+ _0: ".md",
34168
+ _1: (
34169
+ /* End_of_format */
34170
+ 0
34171
+ )
34172
+ }
34173
+ }
34174
+ },
34175
+ _1: "threads/system/mca-review-%s.md"
34176
+ }), ts);
34177
+ const body = Curry._2(Stdlib__Printf.sprintf({
34178
+ TAG: (
34179
+ /* Format */
34180
+ 0
34181
+ ),
34182
+ _0: {
34183
+ TAG: (
34184
+ /* String_literal */
34185
+ 11
34186
+ ),
34187
+ _0: "---\ntype: mca-review\ncreated: ",
34188
+ _1: {
34189
+ TAG: (
34190
+ /* String */
34191
+ 2
34192
+ ),
34193
+ _0: (
34194
+ /* No_padding */
33978
34195
  0
33979
- )
34196
+ ),
34197
+ _1: {
34198
+ TAG: (
34199
+ /* String_literal */
34200
+ 11
34201
+ ),
34202
+ _0: "\n---\n\n# 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",
34203
+ _1: {
34204
+ TAG: (
34205
+ /* String */
34206
+ 2
34207
+ ),
34208
+ _0: (
34209
+ /* No_padding */
34210
+ 0
34211
+ ),
34212
+ _1: {
34213
+ TAG: (
34214
+ /* Char_literal */
34215
+ 12
34216
+ ),
34217
+ _0: (
34218
+ /* '\n' */
34219
+ 10
34220
+ ),
34221
+ _1: (
34222
+ /* End_of_format */
34223
+ 0
34224
+ )
34225
+ }
34226
+ }
34227
+ }
33980
34228
  }
33981
34229
  },
33982
- _1: "mca-review-%s"
33983
- }), (/* @__PURE__ */ new Date()).toISOString().slice(0, 10));
33984
- const body = Curry._1(Stdlib__Printf.sprintf({
34230
+ _1: "---\ntype: mca-review\ncreated: %s\n---\n\n# 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"
34231
+ }), (/* @__PURE__ */ new Date()).toISOString(), mca_list);
34232
+ const system_dir = Path.join(hub_path, "threads/system");
34233
+ ensure_dir(system_dir);
34234
+ const prim0 = Path.join(hub_path, event_file);
34235
+ Fs.writeFileSync(prim0, body);
34236
+ exec_in(hub_path, Curry._1(Stdlib__Printf.sprintf({
33985
34237
  TAG: (
33986
34238
  /* Format */
33987
34239
  0
@@ -33991,7 +34243,7 @@ function queue_mca_review(hub_path) {
33991
34243
  /* String_literal */
33992
34244
  11
33993
34245
  ),
33994
- _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",
34246
+ _0: "git add '",
33995
34247
  _1: {
33996
34248
  TAG: (
33997
34249
  /* String */
@@ -34007,8 +34259,8 @@ function queue_mca_review(hub_path) {
34007
34259
  12
34008
34260
  ),
34009
34261
  _0: (
34010
- /* '\n' */
34011
- 10
34262
+ /* '\'' */
34263
+ 39
34012
34264
  ),
34013
34265
  _1: (
34014
34266
  /* End_of_format */
@@ -34017,10 +34269,9 @@ function queue_mca_review(hub_path) {
34017
34269
  }
34018
34270
  }
34019
34271
  },
34020
- _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"
34021
- }), mca_list);
34022
- queue_add(hub_path, review_id, "system", body);
34023
- log_action(hub_path, "mca.review-queued", Curry._1(Stdlib__Printf.sprintf({
34272
+ _1: "git add '%s'"
34273
+ }), event_file));
34274
+ exec_in(hub_path, Curry._1(Stdlib__Printf.sprintf({
34024
34275
  TAG: (
34025
34276
  /* Format */
34026
34277
  0
@@ -34030,33 +34281,117 @@ function queue_mca_review(hub_path) {
34030
34281
  /* String_literal */
34031
34282
  11
34032
34283
  ),
34033
- _0: "count:",
34284
+ _0: "git commit -m '",
34034
34285
  _1: {
34035
34286
  TAG: (
34036
- /* Int */
34037
- 4
34287
+ /* String */
34288
+ 2
34038
34289
  ),
34039
34290
  _0: (
34040
- /* Int_d */
34041
- 0
34042
- ),
34043
- _1: (
34044
34291
  /* No_padding */
34045
34292
  0
34046
34293
  ),
34047
- _2: (
34048
- /* No_precision */
34294
+ _1: {
34295
+ TAG: (
34296
+ /* String_literal */
34297
+ 11
34298
+ ),
34299
+ _0: ": system event mca-review'",
34300
+ _1: (
34301
+ /* End_of_format */
34302
+ 0
34303
+ )
34304
+ }
34305
+ }
34306
+ },
34307
+ _1: "git commit -m '%s: system event mca-review'"
34308
+ }), name));
34309
+ const arg = Curry._1(Stdlib__Printf.sprintf({
34310
+ TAG: (
34311
+ /* Format */
34312
+ 0
34313
+ ),
34314
+ _0: {
34315
+ TAG: (
34316
+ /* String_literal */
34317
+ 11
34318
+ ),
34319
+ _0: "mca-review-",
34320
+ _1: {
34321
+ TAG: (
34322
+ /* String */
34323
+ 2
34324
+ ),
34325
+ _0: (
34326
+ /* No_padding */
34049
34327
  0
34050
34328
  ),
34051
- _3: (
34329
+ _1: (
34052
34330
  /* End_of_format */
34053
34331
  0
34054
34332
  )
34055
34333
  }
34056
34334
  },
34057
- _1: "count:%d"
34058
- }), Stdlib__List.length(mcas)));
34059
- const msg = Curry._1(Stdlib__Printf.sprintf({
34335
+ _1: "mca-review-%s"
34336
+ }), ts);
34337
+ const trigger = (function(param) {
34338
+ return Stdlib__Option.value(param, arg);
34339
+ })(Stdlib__Option.map(Stdlib__String.trim, exec_in(hub_path, "git rev-parse HEAD")));
34340
+ queue_add(hub_path, trigger, "system", body);
34341
+ log_action(hub_path, "mca.review-queued", Curry._2(Stdlib__Printf.sprintf({
34342
+ TAG: (
34343
+ /* Format */
34344
+ 0
34345
+ ),
34346
+ _0: {
34347
+ TAG: (
34348
+ /* String_literal */
34349
+ 11
34350
+ ),
34351
+ _0: "trigger:",
34352
+ _1: {
34353
+ TAG: (
34354
+ /* String */
34355
+ 2
34356
+ ),
34357
+ _0: (
34358
+ /* No_padding */
34359
+ 0
34360
+ ),
34361
+ _1: {
34362
+ TAG: (
34363
+ /* String_literal */
34364
+ 11
34365
+ ),
34366
+ _0: " count:",
34367
+ _1: {
34368
+ TAG: (
34369
+ /* Int */
34370
+ 4
34371
+ ),
34372
+ _0: (
34373
+ /* Int_d */
34374
+ 0
34375
+ ),
34376
+ _1: (
34377
+ /* No_padding */
34378
+ 0
34379
+ ),
34380
+ _2: (
34381
+ /* No_precision */
34382
+ 0
34383
+ ),
34384
+ _3: (
34385
+ /* End_of_format */
34386
+ 0
34387
+ )
34388
+ }
34389
+ }
34390
+ }
34391
+ },
34392
+ _1: "trigger:%s count:%d"
34393
+ }), trigger, Stdlib__List.length(mcas)));
34394
+ const msg = Curry._2(Stdlib__Printf.sprintf({
34060
34395
  TAG: (
34061
34396
  /* Format */
34062
34397
  0
@@ -34089,16 +34424,26 @@ function queue_mca_review(hub_path) {
34089
34424
  /* String_literal */
34090
34425
  11
34091
34426
  ),
34092
- _0: " MCAs)",
34093
- _1: (
34094
- /* End_of_format */
34095
- 0
34096
- )
34427
+ _0: " MCAs) trigger:",
34428
+ _1: {
34429
+ TAG: (
34430
+ /* String */
34431
+ 2
34432
+ ),
34433
+ _0: (
34434
+ /* No_padding */
34435
+ 0
34436
+ ),
34437
+ _1: (
34438
+ /* End_of_format */
34439
+ 0
34440
+ )
34441
+ }
34097
34442
  }
34098
34443
  }
34099
34444
  },
34100
- _1: "Queued MCA review (%d MCAs)"
34101
- }), Stdlib__List.length(mcas));
34445
+ _1: "Queued MCA review (%d MCAs) trigger:%s"
34446
+ }), Stdlib__List.length(mcas), Stdlib__String.sub(trigger, 0, 7));
34102
34447
  console.log(color("32", "\xE2\x9C\x93 ") + msg);
34103
34448
  }
34104
34449
  function auto_save(hub_path, name) {
@@ -34252,7 +34597,7 @@ function run_inbound(hub_path, name) {
34252
34597
  }
34253
34598
  const cycle = increment_mca_cycle(hub_path);
34254
34599
  if (cycle % 5 === 0 && mca_count(hub_path) > 0) {
34255
- queue_mca_review(hub_path);
34600
+ queue_mca_review(hub_path, name);
34256
34601
  }
34257
34602
  const inp = Path.join(hub_path, "state/input.md");
34258
34603
  const outp = Path.join(hub_path, "state/output.md");
@@ -36237,6 +36582,7 @@ module.exports = {
36237
36582
  split_lines,
36238
36583
  get_peer_branches,
36239
36584
  inbox_check,
36585
+ delete_remote_branch,
36240
36586
  materialize_branch,
36241
36587
  inbox_process,
36242
36588
  outbox_check,
@@ -36271,6 +36617,7 @@ module.exports = {
36271
36617
  get_file_id,
36272
36618
  mca_dir,
36273
36619
  execute_op,
36620
+ generate_trigger,
36274
36621
  archive_io_pair,
36275
36622
  queue_inbox_items,
36276
36623
  feed_next_input,