cnagent 2.1.13 → 2.1.15

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 +2434 -949
package/tools/dist/cn.js CHANGED
@@ -11908,6 +11908,191 @@ var require_cn_lib = __commonJS({
11908
11908
  function non_empty(s) {
11909
11909
  return Stdlib__String2.trim(s) !== "";
11910
11910
  }
11911
+ function string_of_agent_op(id) {
11912
+ switch (id.TAG) {
11913
+ case /* OpAck */
11914
+ 0:
11915
+ return "ack:" + id._0;
11916
+ case /* OpDone */
11917
+ 1:
11918
+ return "done:" + id._0;
11919
+ case /* OpFail */
11920
+ 2:
11921
+ return "fail:" + (id._0 + (" reason:" + id._1));
11922
+ case /* OpReply */
11923
+ 3:
11924
+ return "reply:" + id._0;
11925
+ case /* OpSend */
11926
+ 4:
11927
+ return "send:" + id._0;
11928
+ case /* OpDelegate */
11929
+ 5:
11930
+ return "delegate:" + (id._0 + (" to:" + id._1));
11931
+ case /* OpDefer */
11932
+ 6:
11933
+ const until = id._1;
11934
+ const id$1 = id._0;
11935
+ if (until !== void 0) {
11936
+ return "defer:" + (id$1 + (" until:" + until));
11937
+ } else {
11938
+ return "defer:" + id$1;
11939
+ }
11940
+ case /* OpDelete */
11941
+ 7:
11942
+ return "delete:" + id._0;
11943
+ case /* OpSurface */
11944
+ 8:
11945
+ return "surface:" + id._0;
11946
+ }
11947
+ }
11948
+ function parse_agent_op(key, value) {
11949
+ switch (key) {
11950
+ case "ack":
11951
+ return {
11952
+ TAG: (
11953
+ /* OpAck */
11954
+ 0
11955
+ ),
11956
+ _0: value
11957
+ };
11958
+ case "defer":
11959
+ const i = Stdlib__String2.index_opt(
11960
+ value,
11961
+ /* '|' */
11962
+ 124
11963
+ );
11964
+ if (i !== void 0) {
11965
+ return {
11966
+ TAG: (
11967
+ /* OpDefer */
11968
+ 6
11969
+ ),
11970
+ _0: Stdlib__String2.sub(value, 0, i),
11971
+ _1: Stdlib__String2.sub(value, i + 1 | 0, (value.length - i | 0) - 1 | 0)
11972
+ };
11973
+ } else {
11974
+ return {
11975
+ TAG: (
11976
+ /* OpDefer */
11977
+ 6
11978
+ ),
11979
+ _0: value,
11980
+ _1: void 0
11981
+ };
11982
+ }
11983
+ case "delegate":
11984
+ const i$1 = Stdlib__String2.index_opt(
11985
+ value,
11986
+ /* '|' */
11987
+ 124
11988
+ );
11989
+ if (i$1 !== void 0) {
11990
+ return {
11991
+ TAG: (
11992
+ /* OpDelegate */
11993
+ 5
11994
+ ),
11995
+ _0: Stdlib__String2.sub(value, 0, i$1),
11996
+ _1: Stdlib__String2.sub(value, i$1 + 1 | 0, (value.length - i$1 | 0) - 1 | 0)
11997
+ };
11998
+ } else {
11999
+ return;
12000
+ }
12001
+ case "delete":
12002
+ return {
12003
+ TAG: (
12004
+ /* OpDelete */
12005
+ 7
12006
+ ),
12007
+ _0: value
12008
+ };
12009
+ case "done":
12010
+ return {
12011
+ TAG: (
12012
+ /* OpDone */
12013
+ 1
12014
+ ),
12015
+ _0: value
12016
+ };
12017
+ case "fail":
12018
+ const i$2 = Stdlib__String2.index_opt(
12019
+ value,
12020
+ /* '|' */
12021
+ 124
12022
+ );
12023
+ if (i$2 !== void 0) {
12024
+ return {
12025
+ TAG: (
12026
+ /* OpFail */
12027
+ 2
12028
+ ),
12029
+ _0: Stdlib__String2.sub(value, 0, i$2),
12030
+ _1: Stdlib__String2.sub(value, i$2 + 1 | 0, (value.length - i$2 | 0) - 1 | 0)
12031
+ };
12032
+ } else {
12033
+ return {
12034
+ TAG: (
12035
+ /* OpFail */
12036
+ 2
12037
+ ),
12038
+ _0: value,
12039
+ _1: "unspecified"
12040
+ };
12041
+ }
12042
+ case "reply":
12043
+ const i$3 = Stdlib__String2.index_opt(
12044
+ value,
12045
+ /* '|' */
12046
+ 124
12047
+ );
12048
+ if (i$3 !== void 0) {
12049
+ return {
12050
+ TAG: (
12051
+ /* OpReply */
12052
+ 3
12053
+ ),
12054
+ _0: Stdlib__String2.sub(value, 0, i$3),
12055
+ _1: Stdlib__String2.sub(value, i$3 + 1 | 0, (value.length - i$3 | 0) - 1 | 0)
12056
+ };
12057
+ } else {
12058
+ return;
12059
+ }
12060
+ case "send":
12061
+ const i$4 = Stdlib__String2.index_opt(
12062
+ value,
12063
+ /* '|' */
12064
+ 124
12065
+ );
12066
+ if (i$4 !== void 0) {
12067
+ return {
12068
+ TAG: (
12069
+ /* OpSend */
12070
+ 4
12071
+ ),
12072
+ _0: Stdlib__String2.sub(value, 0, i$4),
12073
+ _1: Stdlib__String2.sub(value, i$4 + 1 | 0, (value.length - i$4 | 0) - 1 | 0)
12074
+ };
12075
+ } else {
12076
+ return;
12077
+ }
12078
+ case "mca":
12079
+ case "surface":
12080
+ return {
12081
+ TAG: (
12082
+ /* OpSurface */
12083
+ 8
12084
+ ),
12085
+ _0: value
12086
+ };
12087
+ default:
12088
+ return;
12089
+ }
12090
+ }
12091
+ function extract_ops(frontmatter) {
12092
+ return Stdlib__List2.filter_map((function(param) {
12093
+ return parse_agent_op(param[0], param[1]);
12094
+ }), frontmatter);
12095
+ }
11911
12096
  function string_of_command(t) {
11912
12097
  if (
11913
12098
  /* tag */
@@ -13075,12 +13260,15 @@ var require_cn_lib = __commonJS({
13075
13260
  );
13076
13261
  }
13077
13262
  var help_text = "cn - Coherent Network agent CLI\n\nUsage: cn <command> [options]\n\nCommands:\n # Agent decisions (output)\n delete <thread> GTD: discard\n defer <thread> GTD: postpone\n delegate <t> <peer> GTD: forward\n do <thread> GTD: claim/start\n done <thread> GTD: complete \xE2\x86\x92 archive\n reply <thread> <msg> Append to thread\n send <peer> <msg> Message to peer (or self)\n \n # cn operations (orchestrator)\n sync Fetch inbound + send outbound\n process Queue inbox \xE2\x86\x92 input.md \xE2\x86\x92 wake agent\n queue [list|clear] View or clear the task queue\n mca [list|add <desc>] Surface MCAs for community pickup\n inbox List inbox threads\n outbox List outbox threads\n next Get next inbox item (with cadence)\n read <thread> Read thread with cadence\n \n # Hub management\n init [name] Create new hub\n status Show hub state\n commit [msg] Stage + commit\n push Push to origin\n save [msg] Commit + push\n peer Manage peers\n doctor Health check\n update Update cn to latest version\n\nAliases:\n i = inbox, o = outbox, s = status, d = doctor\n\nFlags:\n --help, -h Show help\n --version, -V Show version\n --json Machine-readable output\n --quiet, -q Minimal output\n --dry-run Show what would happen\n\nActor Model:\n cn runs on cron (every 5 min). It:\n 1. Syncs peers \xE2\x86\x92 queues new inbox items to state/queue/\n 2. If input.md empty \xE2\x86\x92 pops from queue \xE2\x86\x92 writes input.md \xE2\x86\x92 wakes agent\n Agent reads input.md, processes, deletes when done.\n";
13078
- var version = "2.1.13";
13263
+ var version = "2.1.15";
13079
13264
  module2.exports = {
13080
13265
  starts_with,
13081
13266
  strip_prefix,
13082
13267
  ends_with,
13083
13268
  non_empty,
13269
+ string_of_agent_op,
13270
+ parse_agent_op,
13271
+ extract_ops,
13084
13272
  string_of_command,
13085
13273
  expand_alias,
13086
13274
  parse_inbox_cmd,
@@ -29755,41 +29943,15 @@ function get_file_id(path) {
29755
29943
  }
29756
29944
  }), meta);
29757
29945
  }
29758
- function archive_io_pair(hub_path) {
29759
- const inp = Path.join(hub_path, "state/input.md");
29760
- const outp = Path.join(hub_path, "state/output.md");
29761
- const match2 = get_file_id(inp);
29762
- const match$1 = get_file_id(outp);
29763
- if (match2 === void 0) {
29764
- if (match$1 !== void 0) {
29765
- console.log(color("33", "\xE2\x9A\xA0 ") + "Orphan output.md found (no input.md)");
29766
- return false;
29767
- } else {
29768
- return true;
29769
- }
29770
- }
29771
- if (match$1 === void 0) {
29772
- return false;
29773
- }
29774
- if (match2 === match$1) {
29775
- const logs_in = Path.join(hub_path, "logs/input");
29776
- const logs_out = Path.join(hub_path, "logs/output");
29777
- ensure_dir(logs_in);
29778
- ensure_dir(logs_out);
29779
- const output_content = Fs.readFileSync(outp, "utf8");
29780
- const archive_name = match2 + ".md";
29781
- const prim1 = Fs.readFileSync(inp, "utf8");
29782
- const prim0 = Path.join(logs_in, archive_name);
29783
- Fs.writeFileSync(prim0, prim1);
29784
- const prim0$1 = Path.join(logs_out, archive_name);
29785
- Fs.writeFileSync(prim0$1, output_content);
29786
- const output_meta = Cn_lib.parse_frontmatter(output_content);
29787
- const match$2 = Stdlib__List.find_opt((function(param) {
29788
- return param[0] === "mca";
29789
- }), output_meta);
29790
- if (match$2 !== void 0) {
29791
- const mca_text = match$2[1];
29792
- const mca_id = Curry._1(Stdlib__Printf.sprintf({
29946
+ function mca_dir(hub_path) {
29947
+ return Path.join(hub_path, "state/mca");
29948
+ }
29949
+ function execute_op(hub_path, name, input_id, op) {
29950
+ switch (op.TAG) {
29951
+ case /* OpAck */
29952
+ 0:
29953
+ log_action(hub_path, "op.ack", input_id);
29954
+ const msg = Curry._1(Stdlib__Printf.sprintf({
29793
29955
  TAG: (
29794
29956
  /* Format */
29795
29957
  0
@@ -29799,7 +29961,7 @@ function archive_io_pair(hub_path) {
29799
29961
  /* String_literal */
29800
29962
  11
29801
29963
  ),
29802
- _0: "mca-",
29964
+ _0: "Ack: ",
29803
29965
  _1: {
29804
29966
  TAG: (
29805
29967
  /* String */
@@ -29815,9 +29977,15 @@ function archive_io_pair(hub_path) {
29815
29977
  )
29816
29978
  }
29817
29979
  },
29818
- _1: "mca-%s"
29819
- }), match2);
29820
- const mca_content = Curry._4(Stdlib__Printf.sprintf({
29980
+ _1: "Ack: %s"
29981
+ }), input_id);
29982
+ console.log(color("32", "\xE2\x9C\x93 ") + msg);
29983
+ return;
29984
+ case /* OpDone */
29985
+ 1:
29986
+ const id = op._0;
29987
+ log_action(hub_path, "op.done", id);
29988
+ const msg$1 = Curry._1(Stdlib__Printf.sprintf({
29821
29989
  TAG: (
29822
29990
  /* Format */
29823
29991
  0
@@ -29827,7 +29995,7 @@ function archive_io_pair(hub_path) {
29827
29995
  /* String_literal */
29828
29996
  11
29829
29997
  ),
29830
- _0: "---\nid: ",
29998
+ _0: "Done: ",
29831
29999
  _1: {
29832
30000
  TAG: (
29833
30001
  /* String */
@@ -29837,112 +30005,55 @@ function archive_io_pair(hub_path) {
29837
30005
  /* No_padding */
29838
30006
  0
29839
30007
  ),
29840
- _1: {
29841
- TAG: (
29842
- /* String_literal */
29843
- 11
29844
- ),
29845
- _0: "\ntype: mca-feedback\noriginal: ",
29846
- _1: {
29847
- TAG: (
29848
- /* String */
29849
- 2
29850
- ),
29851
- _0: (
29852
- /* No_padding */
29853
- 0
29854
- ),
29855
- _1: {
29856
- TAG: (
29857
- /* String_literal */
29858
- 11
29859
- ),
29860
- _0: "\n---\n\n# MCA Reinforcement\n\nYou identified this MCA during processing of ",
29861
- _1: {
29862
- TAG: (
29863
- /* String */
29864
- 2
29865
- ),
29866
- _0: (
29867
- /* No_padding */
29868
- 0
29869
- ),
29870
- _1: {
29871
- TAG: (
29872
- /* String_literal */
29873
- 11
29874
- ),
29875
- _0: ":\n\n> ",
29876
- _1: {
29877
- TAG: (
29878
- /* String */
29879
- 2
29880
- ),
29881
- _0: (
29882
- /* No_padding */
29883
- 0
29884
- ),
29885
- _1: {
29886
- TAG: (
29887
- /* String_literal */
29888
- 11
29889
- ),
29890
- _0: "\n\nApply this pattern next time.\n",
29891
- _1: (
29892
- /* End_of_format */
29893
- 0
29894
- )
29895
- }
29896
- }
29897
- }
29898
- }
29899
- }
29900
- }
29901
- }
30008
+ _1: (
30009
+ /* End_of_format */
30010
+ 0
30011
+ )
29902
30012
  }
29903
30013
  },
29904
- _1: "---\nid: %s\ntype: mca-feedback\noriginal: %s\n---\n\n# MCA Reinforcement\n\nYou identified this MCA during processing of %s:\n\n> %s\n\nApply this pattern next time.\n"
29905
- }), mca_id, match2, match2, mca_text);
29906
- const qdir = Path.join(hub_path, "state/queue");
29907
- ensure_dir(qdir);
29908
- const qfile = Path.join(qdir, Curry._2(Stdlib__Printf.sprintf({
30014
+ _1: "Done: %s"
30015
+ }), id);
30016
+ console.log(color("32", "\xE2\x9C\x93 ") + msg$1);
30017
+ return;
30018
+ case /* OpFail */
30019
+ 2:
30020
+ const reason = op._1;
30021
+ const id$1 = op._0;
30022
+ log_action(hub_path, "op.fail", Curry._2(Stdlib__Printf.sprintf({
29909
30023
  TAG: (
29910
30024
  /* Format */
29911
30025
  0
29912
30026
  ),
29913
30027
  _0: {
29914
30028
  TAG: (
29915
- /* String */
29916
- 2
29917
- ),
29918
- _0: (
29919
- /* No_padding */
29920
- 0
30029
+ /* String_literal */
30030
+ 11
29921
30031
  ),
30032
+ _0: "id:",
29922
30033
  _1: {
29923
30034
  TAG: (
29924
- /* Char_literal */
29925
- 12
30035
+ /* String */
30036
+ 2
29926
30037
  ),
29927
30038
  _0: (
29928
- /* '-' */
29929
- 45
30039
+ /* No_padding */
30040
+ 0
29930
30041
  ),
29931
30042
  _1: {
29932
30043
  TAG: (
29933
- /* String */
29934
- 2
29935
- ),
29936
- _0: (
29937
- /* No_padding */
29938
- 0
30044
+ /* String_literal */
30045
+ 11
29939
30046
  ),
30047
+ _0: " reason:",
29940
30048
  _1: {
29941
30049
  TAG: (
29942
- /* String_literal */
29943
- 11
30050
+ /* String */
30051
+ 2
30052
+ ),
30053
+ _0: (
30054
+ /* No_padding */
30055
+ 0
29944
30056
  ),
29945
- _0: ".md",
29946
30057
  _1: (
29947
30058
  /* End_of_format */
29948
30059
  0
@@ -29951,10 +30062,9 @@ function archive_io_pair(hub_path) {
29951
30062
  }
29952
30063
  }
29953
30064
  },
29954
- _1: "%s-%s.md"
29955
- }), (/* @__PURE__ */ new Date()).toISOString(), mca_id));
29956
- Fs.writeFileSync(qfile, mca_content);
29957
- log_action(hub_path, "mca.queued", Curry._2(Stdlib__Printf.sprintf({
30065
+ _1: "id:%s reason:%s"
30066
+ }), id$1, reason));
30067
+ const msg$2 = Curry._2(Stdlib__Printf.sprintf({
29958
30068
  TAG: (
29959
30069
  /* Format */
29960
30070
  0
@@ -29964,7 +30074,7 @@ function archive_io_pair(hub_path) {
29964
30074
  /* String_literal */
29965
30075
  11
29966
30076
  ),
29967
- _0: "id:",
30077
+ _0: "Failed: ",
29968
30078
  _1: {
29969
30079
  TAG: (
29970
30080
  /* String */
@@ -29979,7 +30089,7 @@ function archive_io_pair(hub_path) {
29979
30089
  /* String_literal */
29980
30090
  11
29981
30091
  ),
29982
- _0: " mca:",
30092
+ _0: " - ",
29983
30093
  _1: {
29984
30094
  TAG: (
29985
30095
  /* String */
@@ -29997,175 +30107,49 @@ function archive_io_pair(hub_path) {
29997
30107
  }
29998
30108
  }
29999
30109
  },
30000
- _1: "id:%s mca:%s"
30001
- }), match2, mca_text));
30002
- console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
30003
- TAG: (
30004
- /* Format */
30005
- 0
30006
- ),
30007
- _0: {
30110
+ _1: "Failed: %s - %s"
30111
+ }), id$1, reason);
30112
+ console.log(color("33", "\xE2\x9A\xA0 ") + msg$2);
30113
+ return;
30114
+ case /* OpReply */
30115
+ 3:
30116
+ const id$2 = op._0;
30117
+ const path = find_thread(hub_path, id$2);
30118
+ if (path !== void 0) {
30119
+ const reply = Curry._2(Stdlib__Printf.sprintf({
30008
30120
  TAG: (
30009
- /* String_literal */
30010
- 11
30121
+ /* Format */
30122
+ 0
30011
30123
  ),
30012
- _0: "MCA queued for feedback: ",
30013
- _1: {
30124
+ _0: {
30014
30125
  TAG: (
30015
- /* String */
30016
- 2
30017
- ),
30018
- _0: (
30019
- /* No_padding */
30020
- 0
30021
- ),
30022
- _1: (
30023
- /* End_of_format */
30024
- 0
30025
- )
30026
- }
30027
- },
30028
- _1: "MCA queued for feedback: %s"
30029
- }), mca_text)));
30030
- }
30031
- Fs.unlinkSync(inp);
30032
- Fs.unlinkSync(outp);
30033
- log_action(hub_path, "io.archive", Curry._1(Stdlib__Printf.sprintf({
30034
- TAG: (
30035
- /* Format */
30036
- 0
30037
- ),
30038
- _0: {
30039
- TAG: (
30040
- /* String_literal */
30041
- 11
30042
- ),
30043
- _0: "id:",
30044
- _1: {
30045
- TAG: (
30046
- /* String */
30047
- 2
30048
- ),
30049
- _0: (
30050
- /* No_padding */
30051
- 0
30052
- ),
30053
- _1: (
30054
- /* End_of_format */
30055
- 0
30056
- )
30057
- }
30058
- },
30059
- _1: "id:%s"
30060
- }), match2));
30061
- const msg = Curry._1(Stdlib__Printf.sprintf({
30062
- TAG: (
30063
- /* Format */
30064
- 0
30065
- ),
30066
- _0: {
30067
- TAG: (
30068
- /* String_literal */
30069
- 11
30070
- ),
30071
- _0: "Archived IO pair: ",
30072
- _1: {
30073
- TAG: (
30074
- /* String */
30075
- 2
30076
- ),
30077
- _0: (
30078
- /* No_padding */
30079
- 0
30080
- ),
30081
- _1: (
30082
- /* End_of_format */
30083
- 0
30084
- )
30085
- }
30086
- },
30087
- _1: "Archived IO pair: %s"
30088
- }), match2);
30089
- console.log(color("32", "\xE2\x9C\x93 ") + msg);
30090
- return true;
30091
- }
30092
- console.log(color("31", "\xE2\x9C\x97 ") + "ID mismatch between input.md and output.md");
30093
- return false;
30094
- }
30095
- function queue_inbox_items(hub_path) {
30096
- const inbox_dir = Path.join(hub_path, "threads/inbox");
30097
- if (Fs.existsSync(inbox_dir)) {
30098
- return Stdlib__List.length(Stdlib__List.filter_map((function(file) {
30099
- const file_path = Path.join(inbox_dir, file);
30100
- const content = Fs.readFileSync(file_path, "utf8");
30101
- const meta = Cn_lib.parse_frontmatter(content);
30102
- const is_queued = Stdlib__List.exists((function(param) {
30103
- return param[0] === "queued-for-processing";
30104
- }), meta);
30105
- if (is_queued) {
30106
- return;
30107
- }
30108
- const id = Path.basename(file, ".md");
30109
- const from = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
30110
- if (param[0] === "from") {
30111
- return param[1];
30112
- }
30113
- }), meta), "unknown");
30114
- queue_add(hub_path, id, from, content);
30115
- const prim1 = Cn_lib.update_frontmatter(content, {
30116
- hd: [
30117
- "queued-for-processing",
30118
- (/* @__PURE__ */ new Date()).toISOString()
30119
- ],
30120
- tl: (
30121
- /* [] */
30122
- 0
30123
- )
30124
- });
30125
- Fs.writeFileSync(file_path, prim1);
30126
- const msg = Curry._2(Stdlib__Printf.sprintf({
30127
- TAG: (
30128
- /* Format */
30129
- 0
30130
- ),
30131
- _0: {
30132
- TAG: (
30133
- /* String_literal */
30134
- 11
30135
- ),
30136
- _0: "Queued: ",
30137
- _1: {
30138
- TAG: (
30139
- /* String */
30140
- 2
30141
- ),
30142
- _0: (
30143
- /* No_padding */
30144
- 0
30126
+ /* String_literal */
30127
+ 11
30145
30128
  ),
30129
+ _0: "\n\n## Reply (",
30146
30130
  _1: {
30147
30131
  TAG: (
30148
- /* String_literal */
30149
- 11
30132
+ /* String */
30133
+ 2
30134
+ ),
30135
+ _0: (
30136
+ /* No_padding */
30137
+ 0
30150
30138
  ),
30151
- _0: " (from ",
30152
30139
  _1: {
30153
30140
  TAG: (
30154
- /* String */
30155
- 2
30156
- ),
30157
- _0: (
30158
- /* No_padding */
30159
- 0
30141
+ /* String_literal */
30142
+ 11
30160
30143
  ),
30144
+ _0: ")\n\n",
30161
30145
  _1: {
30162
30146
  TAG: (
30163
- /* Char_literal */
30164
- 12
30147
+ /* String */
30148
+ 2
30165
30149
  ),
30166
30150
  _0: (
30167
- /* ')' */
30168
- 41
30151
+ /* No_padding */
30152
+ 0
30169
30153
  ),
30170
30154
  _1: (
30171
30155
  /* End_of_format */
@@ -30174,60 +30158,21 @@ function queue_inbox_items(hub_path) {
30174
30158
  }
30175
30159
  }
30176
30160
  }
30177
- }
30178
- },
30179
- _1: "Queued: %s (from %s)"
30180
- }), id, from);
30181
- console.log(color("32", "\xE2\x9C\x93 ") + msg);
30182
- return file;
30183
- }), Stdlib__List.filter(is_md_file, Stdlib__Array.to_list(Fs.readdirSync(inbox_dir)))));
30184
- } else {
30185
- return 0;
30186
- }
30187
- }
30188
- function feed_next_input(hub_path) {
30189
- const inp = Path.join(hub_path, "state/input.md");
30190
- const content = queue_pop(hub_path);
30191
- if (content !== void 0) {
30192
- ensure_dir(Path.join(hub_path, "state"));
30193
- Fs.writeFileSync(inp, content);
30194
- const meta = Cn_lib.parse_frontmatter(content);
30195
- const id = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
30196
- if (param[0] === "id") {
30197
- return param[1];
30198
- }
30199
- }), meta), "unknown");
30200
- const from = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
30201
- if (param[0] === "from") {
30202
- return param[1];
30203
- }
30204
- }), meta), "unknown");
30205
- log_action(hub_path, "process.feed", Curry._2(Stdlib__Printf.sprintf({
30206
- TAG: (
30207
- /* Format */
30208
- 0
30209
- ),
30210
- _0: {
30211
- TAG: (
30212
- /* String_literal */
30213
- 11
30214
- ),
30215
- _0: "id:",
30216
- _1: {
30161
+ },
30162
+ _1: "\n\n## Reply (%s)\n\n%s"
30163
+ }), (/* @__PURE__ */ new Date()).toISOString(), op._1);
30164
+ Fs.appendFileSync(path, reply);
30165
+ log_action(hub_path, "op.reply", Curry._1(Stdlib__Printf.sprintf({
30217
30166
  TAG: (
30218
- /* String */
30219
- 2
30220
- ),
30221
- _0: (
30222
- /* No_padding */
30167
+ /* Format */
30223
30168
  0
30224
30169
  ),
30225
- _1: {
30170
+ _0: {
30226
30171
  TAG: (
30227
30172
  /* String_literal */
30228
30173
  11
30229
30174
  ),
30230
- _0: " from:",
30175
+ _0: "thread:",
30231
30176
  _1: {
30232
30177
  TAG: (
30233
30178
  /* String */
@@ -30242,37 +30187,20 @@ function feed_next_input(hub_path) {
30242
30187
  0
30243
30188
  )
30244
30189
  }
30245
- }
30246
- }
30247
- },
30248
- _1: "id:%s from:%s"
30249
- }), id, from));
30250
- const msg = Curry._2(Stdlib__Printf.sprintf({
30251
- TAG: (
30252
- /* Format */
30253
- 0
30254
- ),
30255
- _0: {
30256
- TAG: (
30257
- /* String_literal */
30258
- 11
30259
- ),
30260
- _0: "Wrote state/input.md: ",
30261
- _1: {
30190
+ },
30191
+ _1: "thread:%s"
30192
+ }), id$2));
30193
+ const msg$3 = Curry._1(Stdlib__Printf.sprintf({
30262
30194
  TAG: (
30263
- /* String */
30264
- 2
30265
- ),
30266
- _0: (
30267
- /* No_padding */
30195
+ /* Format */
30268
30196
  0
30269
30197
  ),
30270
- _1: {
30198
+ _0: {
30271
30199
  TAG: (
30272
30200
  /* String_literal */
30273
30201
  11
30274
30202
  ),
30275
- _0: " (from ",
30203
+ _0: "Replied to ",
30276
30204
  _1: {
30277
30205
  TAG: (
30278
30206
  /* String */
@@ -30282,30 +30210,18 @@ function feed_next_input(hub_path) {
30282
30210
  /* No_padding */
30283
30211
  0
30284
30212
  ),
30285
- _1: {
30286
- TAG: (
30287
- /* Char_literal */
30288
- 12
30289
- ),
30290
- _0: (
30291
- /* ')' */
30292
- 41
30293
- ),
30294
- _1: (
30295
- /* End_of_format */
30296
- 0
30297
- )
30298
- }
30213
+ _1: (
30214
+ /* End_of_format */
30215
+ 0
30216
+ )
30299
30217
  }
30300
- }
30301
- }
30302
- },
30303
- _1: "Wrote state/input.md: %s (from %s)"
30304
- }), id, from);
30305
- console.log(color("32", "\xE2\x9C\x93 ") + msg);
30306
- const remaining = queue_count(hub_path);
30307
- if (remaining > 0) {
30308
- console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
30218
+ },
30219
+ _1: "Replied to %s"
30220
+ }), id$2);
30221
+ console.log(color("32", "\xE2\x9C\x93 ") + msg$3);
30222
+ return;
30223
+ }
30224
+ log_action(hub_path, "op.reply", Curry._1(Stdlib__Printf.sprintf({
30309
30225
  TAG: (
30310
30226
  /* Format */
30311
30227
  0
@@ -30315,30 +30231,22 @@ function feed_next_input(hub_path) {
30315
30231
  /* String_literal */
30316
30232
  11
30317
30233
  ),
30318
- _0: "Queue depth: ",
30234
+ _0: "thread:",
30319
30235
  _1: {
30320
30236
  TAG: (
30321
- /* Int */
30322
- 4
30237
+ /* String */
30238
+ 2
30323
30239
  ),
30324
30240
  _0: (
30325
- /* Int_d */
30326
- 0
30327
- ),
30328
- _1: (
30329
30241
  /* No_padding */
30330
30242
  0
30331
30243
  ),
30332
- _2: (
30333
- /* No_precision */
30334
- 0
30335
- ),
30336
- _3: {
30244
+ _1: {
30337
30245
  TAG: (
30338
30246
  /* String_literal */
30339
30247
  11
30340
30248
  ),
30341
- _0: " remaining",
30249
+ _0: " (not found)",
30342
30250
  _1: (
30343
30251
  /* End_of_format */
30344
30252
  0
@@ -30346,185 +30254,53 @@ function feed_next_input(hub_path) {
30346
30254
  }
30347
30255
  }
30348
30256
  },
30349
- _1: "Queue depth: %d remaining"
30350
- }), remaining)));
30351
- }
30352
- return true;
30353
- }
30354
- console.log(color("32", "\xE2\x9C\x93 ") + "Queue empty - nothing to process");
30355
- return false;
30356
- }
30357
- function wake_agent(param) {
30358
- console.log(color("36", "Triggering OpenClaw wake..."));
30359
- const match2 = exec("openclaw system event --text 'input.md ready' --mode now 2>/dev/null");
30360
- if (match2 !== void 0) {
30361
- console.log(color("32", "\xE2\x9C\x93 ") + "Wake triggered");
30362
- } else {
30363
- console.log(color("33", "\xE2\x9A\xA0 ") + "Wake trigger failed - is OpenClaw running?");
30364
- }
30365
- }
30366
- function run_process(hub_path) {
30367
- console.log(color("36", "cn process: actor loop..."));
30368
- const queued = queue_inbox_items(hub_path);
30369
- if (queued > 0) {
30370
- console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
30371
- TAG: (
30372
- /* Format */
30373
- 0
30374
- ),
30375
- _0: {
30257
+ _1: "thread:%s (not found)"
30258
+ }), id$2));
30259
+ const msg$4 = Curry._1(Stdlib__Printf.sprintf({
30376
30260
  TAG: (
30377
- /* String_literal */
30378
- 11
30261
+ /* Format */
30262
+ 0
30379
30263
  ),
30380
- _0: "Added ",
30381
- _1: {
30264
+ _0: {
30382
30265
  TAG: (
30383
- /* Int */
30384
- 4
30385
- ),
30386
- _0: (
30387
- /* Int_d */
30388
- 0
30389
- ),
30390
- _1: (
30391
- /* No_padding */
30392
- 0
30393
- ),
30394
- _2: (
30395
- /* No_precision */
30396
- 0
30266
+ /* String_literal */
30267
+ 11
30397
30268
  ),
30398
- _3: {
30269
+ _0: "Thread not found for reply: ",
30270
+ _1: {
30399
30271
  TAG: (
30400
- /* String_literal */
30401
- 11
30272
+ /* String */
30273
+ 2
30274
+ ),
30275
+ _0: (
30276
+ /* No_padding */
30277
+ 0
30402
30278
  ),
30403
- _0: " item(s) to queue",
30404
30279
  _1: (
30405
30280
  /* End_of_format */
30406
30281
  0
30407
30282
  )
30408
30283
  }
30409
- }
30410
- },
30411
- _1: "Added %d item(s) to queue"
30412
- }), queued)));
30413
- }
30414
- const inp = Path.join(hub_path, "state/input.md");
30415
- const outp = Path.join(hub_path, "state/output.md");
30416
- if (Fs.existsSync(inp) && Fs.existsSync(outp)) {
30417
- if (archive_io_pair(hub_path) && feed_next_input(hub_path)) {
30418
- return wake_agent(void 0);
30419
- } else {
30284
+ },
30285
+ _1: "Thread not found for reply: %s"
30286
+ }), id$2);
30287
+ console.log(color("33", "\xE2\x9A\xA0 ") + msg$4);
30420
30288
  return;
30421
- }
30422
- } else if (Fs.existsSync(inp)) {
30423
- console.log(color("36", "Agent working (input.md exists, awaiting output.md)"));
30424
- console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
30425
- TAG: (
30426
- /* Format */
30427
- 0
30428
- ),
30429
- _0: {
30430
- TAG: (
30431
- /* String_literal */
30432
- 11
30433
- ),
30434
- _0: "Queue depth: ",
30435
- _1: {
30436
- TAG: (
30437
- /* Int */
30438
- 4
30439
- ),
30440
- _0: (
30441
- /* Int_d */
30442
- 0
30443
- ),
30444
- _1: (
30445
- /* No_padding */
30446
- 0
30447
- ),
30448
- _2: (
30449
- /* No_precision */
30450
- 0
30451
- ),
30452
- _3: (
30453
- /* End_of_format */
30454
- 0
30455
- )
30456
- }
30457
- },
30458
- _1: "Queue depth: %d"
30459
- }), queue_count(hub_path))));
30460
- return;
30461
- } else if (feed_next_input(hub_path)) {
30462
- return wake_agent(void 0);
30463
- } else {
30464
- return;
30465
- }
30466
- }
30467
- function run_sync(hub_path, name) {
30468
- console.log(color("36", "Syncing..."));
30469
- inbox_check(hub_path, name);
30470
- inbox_process(hub_path);
30471
- outbox_flush(hub_path, name);
30472
- console.log(color("32", "\xE2\x9C\x93 ") + "Sync complete");
30473
- }
30474
- function run_queue_list(hub_path) {
30475
- const items = queue_list(hub_path);
30476
- if (items) {
30477
- console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
30478
- TAG: (
30479
- /* Format */
30480
- 0
30481
- ),
30482
- _0: {
30483
- TAG: (
30484
- /* String_literal */
30485
- 11
30486
- ),
30487
- _0: "Queue depth: ",
30488
- _1: {
30489
- TAG: (
30490
- /* Int */
30491
- 4
30492
- ),
30493
- _0: (
30494
- /* Int_d */
30495
- 0
30496
- ),
30497
- _1: (
30498
- /* No_padding */
30499
- 0
30500
- ),
30501
- _2: (
30502
- /* No_precision */
30503
- 0
30504
- ),
30505
- _3: (
30506
- /* End_of_format */
30507
- 0
30508
- )
30509
- }
30510
- },
30511
- _1: "Queue depth: %d"
30512
- }), Stdlib__List.length(items))));
30513
- return Stdlib__List.iter((function(file) {
30514
- const file_path = Path.join(Path.join(hub_path, "state/queue"), file);
30515
- const content = Fs.readFileSync(file_path, "utf8");
30516
- const meta = Cn_lib.parse_frontmatter(content);
30517
- const id = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
30518
- if (param[0] === "id") {
30519
- return param[1];
30520
- }
30521
- }), meta), "?");
30522
- const from = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
30523
- if (param[0] === "from") {
30524
- return param[1];
30525
- }
30526
- }), meta), "?");
30527
- console.log(Curry._2(Stdlib__Printf.sprintf({
30289
+ case /* OpSend */
30290
+ 4:
30291
+ const msg$5 = op._1;
30292
+ const peer = op._0;
30293
+ const outbox_dir = Path.join(hub_path, "threads/outbox");
30294
+ ensure_dir(outbox_dir);
30295
+ const slug = msg$5.slice(0, 30).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
30296
+ const file_name = slug + ".md";
30297
+ const match2 = Stdlib__String.split_on_char(
30298
+ /* '\n' */
30299
+ 10,
30300
+ msg$5
30301
+ );
30302
+ const first_line = match2 ? match2.hd : msg$5;
30303
+ const content = Curry._5(Stdlib__Printf.sprintf({
30528
30304
  TAG: (
30529
30305
  /* Format */
30530
30306
  0
@@ -30534,7 +30310,7 @@ function run_queue_list(hub_path) {
30534
30310
  /* String_literal */
30535
30311
  11
30536
30312
  ),
30537
- _0: " ",
30313
+ _0: "---\nto: ",
30538
30314
  _1: {
30539
30315
  TAG: (
30540
30316
  /* String */
@@ -30549,7 +30325,7 @@ function run_queue_list(hub_path) {
30549
30325
  /* String_literal */
30550
30326
  11
30551
30327
  ),
30552
- _0: " (from ",
30328
+ _0: "\ncreated: ",
30553
30329
  _1: {
30554
30330
  TAG: (
30555
30331
  /* String */
@@ -30561,75 +30337,1899 @@ function run_queue_list(hub_path) {
30561
30337
  ),
30562
30338
  _1: {
30563
30339
  TAG: (
30564
- /* Char_literal */
30565
- 12
30566
- ),
30567
- _0: (
30568
- /* ')' */
30569
- 41
30340
+ /* String_literal */
30341
+ 11
30570
30342
  ),
30571
- _1: (
30572
- /* End_of_format */
30573
- 0
30574
- )
30343
+ _0: "\nfrom: ",
30344
+ _1: {
30345
+ TAG: (
30346
+ /* String */
30347
+ 2
30348
+ ),
30349
+ _0: (
30350
+ /* No_padding */
30351
+ 0
30352
+ ),
30353
+ _1: {
30354
+ TAG: (
30355
+ /* String_literal */
30356
+ 11
30357
+ ),
30358
+ _0: "\n---\n\n# ",
30359
+ _1: {
30360
+ TAG: (
30361
+ /* String */
30362
+ 2
30363
+ ),
30364
+ _0: (
30365
+ /* No_padding */
30366
+ 0
30367
+ ),
30368
+ _1: {
30369
+ TAG: (
30370
+ /* String_literal */
30371
+ 11
30372
+ ),
30373
+ _0: "\n\n",
30374
+ _1: {
30375
+ TAG: (
30376
+ /* String */
30377
+ 2
30378
+ ),
30379
+ _0: (
30380
+ /* No_padding */
30381
+ 0
30382
+ ),
30383
+ _1: {
30384
+ TAG: (
30385
+ /* Char_literal */
30386
+ 12
30387
+ ),
30388
+ _0: (
30389
+ /* '\n' */
30390
+ 10
30391
+ ),
30392
+ _1: (
30393
+ /* End_of_format */
30394
+ 0
30395
+ )
30396
+ }
30397
+ }
30398
+ }
30399
+ }
30400
+ }
30401
+ }
30575
30402
  }
30576
30403
  }
30577
30404
  }
30578
30405
  }
30579
30406
  },
30580
- _1: " %s (from %s)"
30581
- }), id, from));
30582
- }), items);
30583
- } else {
30584
- console.log("(queue empty)");
30585
- return;
30586
- }
30587
- }
30588
- function run_queue_clear(hub_path) {
30589
- const dir = Path.join(hub_path, "state/queue");
30590
- if (Fs.existsSync(dir)) {
30591
- const items = Stdlib__List.filter(is_md_file, Stdlib__Array.to_list(Fs.readdirSync(dir)));
30592
- Stdlib__List.iter((function(file) {
30593
- const prim = Path.join(dir, file);
30594
- Fs.unlinkSync(prim);
30595
- }), items);
30596
- log_action(hub_path, "queue.clear", Curry._1(Stdlib__Printf.sprintf({
30597
- TAG: (
30598
- /* Format */
30599
- 0
30600
- ),
30601
- _0: {
30407
+ _1: "---\nto: %s\ncreated: %s\nfrom: %s\n---\n\n# %s\n\n%s\n"
30408
+ }), peer, (/* @__PURE__ */ new Date()).toISOString(), name, first_line, msg$5);
30409
+ const prim0 = Path.join(outbox_dir, file_name);
30410
+ Fs.writeFileSync(prim0, content);
30411
+ log_action(hub_path, "op.send", Curry._2(Stdlib__Printf.sprintf({
30602
30412
  TAG: (
30603
- /* String_literal */
30604
- 11
30413
+ /* Format */
30414
+ 0
30605
30415
  ),
30606
- _0: "count:",
30607
- _1: {
30416
+ _0: {
30608
30417
  TAG: (
30609
- /* Int */
30610
- 4
30418
+ /* String_literal */
30419
+ 11
30611
30420
  ),
30612
- _0: (
30613
- /* Int_d */
30421
+ _0: "to:",
30422
+ _1: {
30423
+ TAG: (
30424
+ /* String */
30425
+ 2
30426
+ ),
30427
+ _0: (
30428
+ /* No_padding */
30429
+ 0
30430
+ ),
30431
+ _1: {
30432
+ TAG: (
30433
+ /* String_literal */
30434
+ 11
30435
+ ),
30436
+ _0: " thread:",
30437
+ _1: {
30438
+ TAG: (
30439
+ /* String */
30440
+ 2
30441
+ ),
30442
+ _0: (
30443
+ /* No_padding */
30444
+ 0
30445
+ ),
30446
+ _1: (
30447
+ /* End_of_format */
30448
+ 0
30449
+ )
30450
+ }
30451
+ }
30452
+ }
30453
+ },
30454
+ _1: "to:%s thread:%s"
30455
+ }), peer, slug));
30456
+ const msg$6 = Curry._1(Stdlib__Printf.sprintf({
30457
+ TAG: (
30458
+ /* Format */
30459
+ 0
30460
+ ),
30461
+ _0: {
30462
+ TAG: (
30463
+ /* String_literal */
30464
+ 11
30465
+ ),
30466
+ _0: "Queued message to ",
30467
+ _1: {
30468
+ TAG: (
30469
+ /* String */
30470
+ 2
30471
+ ),
30472
+ _0: (
30473
+ /* No_padding */
30474
+ 0
30475
+ ),
30476
+ _1: (
30477
+ /* End_of_format */
30478
+ 0
30479
+ )
30480
+ }
30481
+ },
30482
+ _1: "Queued message to %s"
30483
+ }), peer);
30484
+ console.log(color("32", "\xE2\x9C\x93 ") + msg$6);
30485
+ return;
30486
+ case /* OpDelegate */
30487
+ 5:
30488
+ const peer$1 = op._1;
30489
+ const id$3 = op._0;
30490
+ const path$1 = find_thread(hub_path, id$3);
30491
+ if (path$1 !== void 0) {
30492
+ const outbox_dir$1 = Path.join(hub_path, "threads/outbox");
30493
+ ensure_dir(outbox_dir$1);
30494
+ const content$1 = Fs.readFileSync(path$1, "utf8");
30495
+ const prim1 = Cn_lib.update_frontmatter(content$1, {
30496
+ hd: [
30497
+ "to",
30498
+ peer$1
30499
+ ],
30500
+ tl: {
30501
+ hd: [
30502
+ "delegated",
30503
+ (/* @__PURE__ */ new Date()).toISOString()
30504
+ ],
30505
+ tl: {
30506
+ hd: [
30507
+ "delegated-by",
30508
+ name
30509
+ ],
30510
+ tl: (
30511
+ /* [] */
30512
+ 0
30513
+ )
30514
+ }
30515
+ }
30516
+ });
30517
+ const prim0$1 = Path.join(outbox_dir$1, Path.basename(path$1));
30518
+ Fs.writeFileSync(prim0$1, prim1);
30519
+ Fs.unlinkSync(path$1);
30520
+ log_action(hub_path, "op.delegate", Curry._2(Stdlib__Printf.sprintf({
30521
+ TAG: (
30522
+ /* Format */
30614
30523
  0
30615
30524
  ),
30616
- _1: (
30617
- /* No_padding */
30525
+ _0: {
30526
+ TAG: (
30527
+ /* String */
30528
+ 2
30529
+ ),
30530
+ _0: (
30531
+ /* No_padding */
30532
+ 0
30533
+ ),
30534
+ _1: {
30535
+ TAG: (
30536
+ /* String_literal */
30537
+ 11
30538
+ ),
30539
+ _0: " to:",
30540
+ _1: {
30541
+ TAG: (
30542
+ /* String */
30543
+ 2
30544
+ ),
30545
+ _0: (
30546
+ /* No_padding */
30547
+ 0
30548
+ ),
30549
+ _1: (
30550
+ /* End_of_format */
30551
+ 0
30552
+ )
30553
+ }
30554
+ }
30555
+ },
30556
+ _1: "%s to:%s"
30557
+ }), id$3, peer$1));
30558
+ const msg$7 = Curry._2(Stdlib__Printf.sprintf({
30559
+ TAG: (
30560
+ /* Format */
30618
30561
  0
30619
30562
  ),
30620
- _2: (
30621
- /* No_precision */
30563
+ _0: {
30564
+ TAG: (
30565
+ /* String_literal */
30566
+ 11
30567
+ ),
30568
+ _0: "Delegated ",
30569
+ _1: {
30570
+ TAG: (
30571
+ /* String */
30572
+ 2
30573
+ ),
30574
+ _0: (
30575
+ /* No_padding */
30576
+ 0
30577
+ ),
30578
+ _1: {
30579
+ TAG: (
30580
+ /* String_literal */
30581
+ 11
30582
+ ),
30583
+ _0: " to ",
30584
+ _1: {
30585
+ TAG: (
30586
+ /* String */
30587
+ 2
30588
+ ),
30589
+ _0: (
30590
+ /* No_padding */
30591
+ 0
30592
+ ),
30593
+ _1: (
30594
+ /* End_of_format */
30595
+ 0
30596
+ )
30597
+ }
30598
+ }
30599
+ }
30600
+ },
30601
+ _1: "Delegated %s to %s"
30602
+ }), id$3, peer$1);
30603
+ console.log(color("32", "\xE2\x9C\x93 ") + msg$7);
30604
+ return;
30605
+ }
30606
+ const msg$8 = Curry._1(Stdlib__Printf.sprintf({
30607
+ TAG: (
30608
+ /* Format */
30609
+ 0
30610
+ ),
30611
+ _0: {
30612
+ TAG: (
30613
+ /* String_literal */
30614
+ 11
30615
+ ),
30616
+ _0: "Thread not found for delegate: ",
30617
+ _1: {
30618
+ TAG: (
30619
+ /* String */
30620
+ 2
30621
+ ),
30622
+ _0: (
30623
+ /* No_padding */
30624
+ 0
30625
+ ),
30626
+ _1: (
30627
+ /* End_of_format */
30628
+ 0
30629
+ )
30630
+ }
30631
+ },
30632
+ _1: "Thread not found for delegate: %s"
30633
+ }), id$3);
30634
+ console.log(color("33", "\xE2\x9A\xA0 ") + msg$8);
30635
+ return;
30636
+ case /* OpDefer */
30637
+ 6:
30638
+ const id$4 = op._0;
30639
+ const path$2 = find_thread(hub_path, id$4);
30640
+ if (path$2 !== void 0) {
30641
+ const deferred_dir = Path.join(hub_path, "threads/deferred");
30642
+ ensure_dir(deferred_dir);
30643
+ const content$2 = Fs.readFileSync(path$2, "utf8");
30644
+ const until_str = Stdlib__Option.value(op._1, "unspecified");
30645
+ const prim1$1 = Cn_lib.update_frontmatter(content$2, {
30646
+ hd: [
30647
+ "deferred",
30648
+ (/* @__PURE__ */ new Date()).toISOString()
30649
+ ],
30650
+ tl: {
30651
+ hd: [
30652
+ "until",
30653
+ until_str
30654
+ ],
30655
+ tl: (
30656
+ /* [] */
30657
+ 0
30658
+ )
30659
+ }
30660
+ });
30661
+ const prim0$2 = Path.join(deferred_dir, Path.basename(path$2));
30662
+ Fs.writeFileSync(prim0$2, prim1$1);
30663
+ Fs.unlinkSync(path$2);
30664
+ log_action(hub_path, "op.defer", Curry._2(Stdlib__Printf.sprintf({
30665
+ TAG: (
30666
+ /* Format */
30622
30667
  0
30623
30668
  ),
30624
- _3: (
30625
- /* End_of_format */
30669
+ _0: {
30670
+ TAG: (
30671
+ /* String */
30672
+ 2
30673
+ ),
30674
+ _0: (
30675
+ /* No_padding */
30676
+ 0
30677
+ ),
30678
+ _1: {
30679
+ TAG: (
30680
+ /* String_literal */
30681
+ 11
30682
+ ),
30683
+ _0: " until:",
30684
+ _1: {
30685
+ TAG: (
30686
+ /* String */
30687
+ 2
30688
+ ),
30689
+ _0: (
30690
+ /* No_padding */
30691
+ 0
30692
+ ),
30693
+ _1: (
30694
+ /* End_of_format */
30695
+ 0
30696
+ )
30697
+ }
30698
+ }
30699
+ },
30700
+ _1: "%s until:%s"
30701
+ }), id$4, until_str));
30702
+ const msg$9 = Curry._1(Stdlib__Printf.sprintf({
30703
+ TAG: (
30704
+ /* Format */
30626
30705
  0
30627
- )
30706
+ ),
30707
+ _0: {
30708
+ TAG: (
30709
+ /* String_literal */
30710
+ 11
30711
+ ),
30712
+ _0: "Deferred ",
30713
+ _1: {
30714
+ TAG: (
30715
+ /* String */
30716
+ 2
30717
+ ),
30718
+ _0: (
30719
+ /* No_padding */
30720
+ 0
30721
+ ),
30722
+ _1: (
30723
+ /* End_of_format */
30724
+ 0
30725
+ )
30726
+ }
30727
+ },
30728
+ _1: "Deferred %s"
30729
+ }), id$4);
30730
+ console.log(color("32", "\xE2\x9C\x93 ") + msg$9);
30731
+ return;
30732
+ }
30733
+ const msg$10 = Curry._1(Stdlib__Printf.sprintf({
30734
+ TAG: (
30735
+ /* Format */
30736
+ 0
30737
+ ),
30738
+ _0: {
30739
+ TAG: (
30740
+ /* String_literal */
30741
+ 11
30742
+ ),
30743
+ _0: "Thread not found for defer: ",
30744
+ _1: {
30745
+ TAG: (
30746
+ /* String */
30747
+ 2
30748
+ ),
30749
+ _0: (
30750
+ /* No_padding */
30751
+ 0
30752
+ ),
30753
+ _1: (
30754
+ /* End_of_format */
30755
+ 0
30756
+ )
30757
+ }
30758
+ },
30759
+ _1: "Thread not found for defer: %s"
30760
+ }), id$4);
30761
+ console.log(color("33", "\xE2\x9A\xA0 ") + msg$10);
30762
+ return;
30763
+ case /* OpDelete */
30764
+ 7:
30765
+ const id$5 = op._0;
30766
+ const path$3 = find_thread(hub_path, id$5);
30767
+ if (path$3 !== void 0) {
30768
+ Fs.unlinkSync(path$3);
30769
+ log_action(hub_path, "op.delete", id$5);
30770
+ const msg$11 = Curry._1(Stdlib__Printf.sprintf({
30771
+ TAG: (
30772
+ /* Format */
30773
+ 0
30774
+ ),
30775
+ _0: {
30776
+ TAG: (
30777
+ /* String_literal */
30778
+ 11
30779
+ ),
30780
+ _0: "Deleted ",
30781
+ _1: {
30782
+ TAG: (
30783
+ /* String */
30784
+ 2
30785
+ ),
30786
+ _0: (
30787
+ /* No_padding */
30788
+ 0
30789
+ ),
30790
+ _1: (
30791
+ /* End_of_format */
30792
+ 0
30793
+ )
30794
+ }
30795
+ },
30796
+ _1: "Deleted %s"
30797
+ }), id$5);
30798
+ console.log(color("32", "\xE2\x9C\x93 ") + msg$11);
30799
+ return;
30800
+ }
30801
+ log_action(hub_path, "op.delete", Curry._1(Stdlib__Printf.sprintf({
30802
+ TAG: (
30803
+ /* Format */
30804
+ 0
30805
+ ),
30806
+ _0: {
30807
+ TAG: (
30808
+ /* String */
30809
+ 2
30810
+ ),
30811
+ _0: (
30812
+ /* No_padding */
30813
+ 0
30814
+ ),
30815
+ _1: {
30816
+ TAG: (
30817
+ /* String_literal */
30818
+ 11
30819
+ ),
30820
+ _0: " (not found)",
30821
+ _1: (
30822
+ /* End_of_format */
30823
+ 0
30824
+ )
30825
+ }
30826
+ },
30827
+ _1: "%s (not found)"
30828
+ }), id$5));
30829
+ console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
30830
+ TAG: (
30831
+ /* Format */
30832
+ 0
30833
+ ),
30834
+ _0: {
30835
+ TAG: (
30836
+ /* String_literal */
30837
+ 11
30838
+ ),
30839
+ _0: "Thread already gone: ",
30840
+ _1: {
30841
+ TAG: (
30842
+ /* String */
30843
+ 2
30844
+ ),
30845
+ _0: (
30846
+ /* No_padding */
30847
+ 0
30848
+ ),
30849
+ _1: (
30850
+ /* End_of_format */
30851
+ 0
30852
+ )
30853
+ }
30854
+ },
30855
+ _1: "Thread already gone: %s"
30856
+ }), id$5)));
30857
+ return;
30858
+ case /* OpSurface */
30859
+ 8:
30860
+ const desc = op._0;
30861
+ const dir = Path.join(hub_path, "state/mca");
30862
+ ensure_dir(dir);
30863
+ const ts = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
30864
+ const slug$1 = desc.slice(0, 40).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
30865
+ const file_name$1 = Curry._2(Stdlib__Printf.sprintf({
30866
+ TAG: (
30867
+ /* Format */
30868
+ 0
30869
+ ),
30870
+ _0: {
30871
+ TAG: (
30872
+ /* String */
30873
+ 2
30874
+ ),
30875
+ _0: (
30876
+ /* No_padding */
30877
+ 0
30878
+ ),
30879
+ _1: {
30880
+ TAG: (
30881
+ /* Char_literal */
30882
+ 12
30883
+ ),
30884
+ _0: (
30885
+ /* '-' */
30886
+ 45
30887
+ ),
30888
+ _1: {
30889
+ TAG: (
30890
+ /* String */
30891
+ 2
30892
+ ),
30893
+ _0: (
30894
+ /* No_padding */
30895
+ 0
30896
+ ),
30897
+ _1: {
30898
+ TAG: (
30899
+ /* String_literal */
30900
+ 11
30901
+ ),
30902
+ _0: ".md",
30903
+ _1: (
30904
+ /* End_of_format */
30905
+ 0
30906
+ )
30907
+ }
30908
+ }
30909
+ }
30910
+ },
30911
+ _1: "%s-%s.md"
30912
+ }), ts, slug$1);
30913
+ const content$3 = Curry._4(Stdlib__Printf.sprintf({
30914
+ TAG: (
30915
+ /* Format */
30916
+ 0
30917
+ ),
30918
+ _0: {
30919
+ TAG: (
30920
+ /* String_literal */
30921
+ 11
30922
+ ),
30923
+ _0: "---\nid: ",
30924
+ _1: {
30925
+ TAG: (
30926
+ /* String */
30927
+ 2
30928
+ ),
30929
+ _0: (
30930
+ /* No_padding */
30931
+ 0
30932
+ ),
30933
+ _1: {
30934
+ TAG: (
30935
+ /* String_literal */
30936
+ 11
30937
+ ),
30938
+ _0: "\nsurfaced-by: ",
30939
+ _1: {
30940
+ TAG: (
30941
+ /* String */
30942
+ 2
30943
+ ),
30944
+ _0: (
30945
+ /* No_padding */
30946
+ 0
30947
+ ),
30948
+ _1: {
30949
+ TAG: (
30950
+ /* String_literal */
30951
+ 11
30952
+ ),
30953
+ _0: "\ncreated: ",
30954
+ _1: {
30955
+ TAG: (
30956
+ /* String */
30957
+ 2
30958
+ ),
30959
+ _0: (
30960
+ /* No_padding */
30961
+ 0
30962
+ ),
30963
+ _1: {
30964
+ TAG: (
30965
+ /* String_literal */
30966
+ 11
30967
+ ),
30968
+ _0: "\nstatus: open\n---\n\n# MCA\n\n",
30969
+ _1: {
30970
+ TAG: (
30971
+ /* String */
30972
+ 2
30973
+ ),
30974
+ _0: (
30975
+ /* No_padding */
30976
+ 0
30977
+ ),
30978
+ _1: {
30979
+ TAG: (
30980
+ /* Char_literal */
30981
+ 12
30982
+ ),
30983
+ _0: (
30984
+ /* '\n' */
30985
+ 10
30986
+ ),
30987
+ _1: (
30988
+ /* End_of_format */
30989
+ 0
30990
+ )
30991
+ }
30992
+ }
30993
+ }
30994
+ }
30995
+ }
30996
+ }
30997
+ }
30998
+ }
30999
+ },
31000
+ _1: "---\nid: %s\nsurfaced-by: %s\ncreated: %s\nstatus: open\n---\n\n# MCA\n\n%s\n"
31001
+ }), slug$1, name, (/* @__PURE__ */ new Date()).toISOString(), desc);
31002
+ const prim0$3 = Path.join(dir, file_name$1);
31003
+ Fs.writeFileSync(prim0$3, content$3);
31004
+ log_action(hub_path, "op.surface", Curry._2(Stdlib__Printf.sprintf({
31005
+ TAG: (
31006
+ /* Format */
31007
+ 0
31008
+ ),
31009
+ _0: {
31010
+ TAG: (
31011
+ /* String_literal */
31012
+ 11
31013
+ ),
31014
+ _0: "id:",
31015
+ _1: {
31016
+ TAG: (
31017
+ /* String */
31018
+ 2
31019
+ ),
31020
+ _0: (
31021
+ /* No_padding */
31022
+ 0
31023
+ ),
31024
+ _1: {
31025
+ TAG: (
31026
+ /* String_literal */
31027
+ 11
31028
+ ),
31029
+ _0: " desc:",
31030
+ _1: {
31031
+ TAG: (
31032
+ /* String */
31033
+ 2
31034
+ ),
31035
+ _0: (
31036
+ /* No_padding */
31037
+ 0
31038
+ ),
31039
+ _1: (
31040
+ /* End_of_format */
31041
+ 0
31042
+ )
31043
+ }
31044
+ }
31045
+ }
31046
+ },
31047
+ _1: "id:%s desc:%s"
31048
+ }), slug$1, desc));
31049
+ const msg$12 = Curry._1(Stdlib__Printf.sprintf({
31050
+ TAG: (
31051
+ /* Format */
31052
+ 0
31053
+ ),
31054
+ _0: {
31055
+ TAG: (
31056
+ /* String_literal */
31057
+ 11
31058
+ ),
31059
+ _0: "Surfaced MCA: ",
31060
+ _1: {
31061
+ TAG: (
31062
+ /* String */
31063
+ 2
31064
+ ),
31065
+ _0: (
31066
+ /* No_padding */
31067
+ 0
31068
+ ),
31069
+ _1: (
31070
+ /* End_of_format */
31071
+ 0
31072
+ )
31073
+ }
31074
+ },
31075
+ _1: "Surfaced MCA: %s"
31076
+ }), desc);
31077
+ console.log(color("32", "\xE2\x9C\x93 ") + msg$12);
31078
+ return;
31079
+ }
31080
+ }
31081
+ function archive_io_pair(hub_path, name) {
31082
+ const inp = Path.join(hub_path, "state/input.md");
31083
+ const outp = Path.join(hub_path, "state/output.md");
31084
+ const match2 = get_file_id(inp);
31085
+ const match$1 = get_file_id(outp);
31086
+ if (match2 === void 0) {
31087
+ if (match$1 !== void 0) {
31088
+ console.log(color("33", "\xE2\x9A\xA0 ") + "Orphan output.md found (no input.md)");
31089
+ return false;
31090
+ } else {
31091
+ return true;
31092
+ }
31093
+ }
31094
+ if (match$1 === void 0) {
31095
+ return false;
31096
+ }
31097
+ if (match2 === match$1) {
31098
+ const logs_in = Path.join(hub_path, "logs/input");
31099
+ const logs_out = Path.join(hub_path, "logs/output");
31100
+ ensure_dir(logs_in);
31101
+ ensure_dir(logs_out);
31102
+ const output_content = Fs.readFileSync(outp, "utf8");
31103
+ const archive_name = match2 + ".md";
31104
+ const prim1 = Fs.readFileSync(inp, "utf8");
31105
+ const prim0 = Path.join(logs_in, archive_name);
31106
+ Fs.writeFileSync(prim0, prim1);
31107
+ const prim0$1 = Path.join(logs_out, archive_name);
31108
+ Fs.writeFileSync(prim0$1, output_content);
31109
+ const output_meta = Cn_lib.parse_frontmatter(output_content);
31110
+ const ops = Cn_lib.extract_ops(output_meta);
31111
+ Stdlib__List.iter((function(op) {
31112
+ console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
31113
+ TAG: (
31114
+ /* Format */
31115
+ 0
31116
+ ),
31117
+ _0: {
31118
+ TAG: (
31119
+ /* String_literal */
31120
+ 11
31121
+ ),
31122
+ _0: "Executing: ",
31123
+ _1: {
31124
+ TAG: (
31125
+ /* String */
31126
+ 2
31127
+ ),
31128
+ _0: (
31129
+ /* No_padding */
31130
+ 0
31131
+ ),
31132
+ _1: (
31133
+ /* End_of_format */
31134
+ 0
31135
+ )
31136
+ }
31137
+ },
31138
+ _1: "Executing: %s"
31139
+ }), Cn_lib.string_of_agent_op(op))));
31140
+ execute_op(hub_path, name, match2, op);
31141
+ }), ops);
31142
+ Fs.unlinkSync(inp);
31143
+ Fs.unlinkSync(outp);
31144
+ log_action(hub_path, "io.archive", Curry._2(Stdlib__Printf.sprintf({
31145
+ TAG: (
31146
+ /* Format */
31147
+ 0
31148
+ ),
31149
+ _0: {
31150
+ TAG: (
31151
+ /* String_literal */
31152
+ 11
31153
+ ),
31154
+ _0: "id:",
31155
+ _1: {
31156
+ TAG: (
31157
+ /* String */
31158
+ 2
31159
+ ),
31160
+ _0: (
31161
+ /* No_padding */
31162
+ 0
31163
+ ),
31164
+ _1: {
31165
+ TAG: (
31166
+ /* String_literal */
31167
+ 11
31168
+ ),
31169
+ _0: " ops:",
31170
+ _1: {
31171
+ TAG: (
31172
+ /* Int */
31173
+ 4
31174
+ ),
31175
+ _0: (
31176
+ /* Int_d */
31177
+ 0
31178
+ ),
31179
+ _1: (
31180
+ /* No_padding */
31181
+ 0
31182
+ ),
31183
+ _2: (
31184
+ /* No_precision */
31185
+ 0
31186
+ ),
31187
+ _3: (
31188
+ /* End_of_format */
31189
+ 0
31190
+ )
31191
+ }
31192
+ }
31193
+ }
31194
+ },
31195
+ _1: "id:%s ops:%d"
31196
+ }), match2, Stdlib__List.length(ops)));
31197
+ const msg = Curry._2(Stdlib__Printf.sprintf({
31198
+ TAG: (
31199
+ /* Format */
31200
+ 0
31201
+ ),
31202
+ _0: {
31203
+ TAG: (
31204
+ /* String_literal */
31205
+ 11
31206
+ ),
31207
+ _0: "Archived IO pair: ",
31208
+ _1: {
31209
+ TAG: (
31210
+ /* String */
31211
+ 2
31212
+ ),
31213
+ _0: (
31214
+ /* No_padding */
31215
+ 0
31216
+ ),
31217
+ _1: {
31218
+ TAG: (
31219
+ /* String_literal */
31220
+ 11
31221
+ ),
31222
+ _0: " (",
31223
+ _1: {
31224
+ TAG: (
31225
+ /* Int */
31226
+ 4
31227
+ ),
31228
+ _0: (
31229
+ /* Int_d */
31230
+ 0
31231
+ ),
31232
+ _1: (
31233
+ /* No_padding */
31234
+ 0
31235
+ ),
31236
+ _2: (
31237
+ /* No_precision */
31238
+ 0
31239
+ ),
31240
+ _3: {
31241
+ TAG: (
31242
+ /* String_literal */
31243
+ 11
31244
+ ),
31245
+ _0: " ops)",
31246
+ _1: (
31247
+ /* End_of_format */
31248
+ 0
31249
+ )
31250
+ }
31251
+ }
31252
+ }
31253
+ }
31254
+ },
31255
+ _1: "Archived IO pair: %s (%d ops)"
31256
+ }), match2, Stdlib__List.length(ops));
31257
+ console.log(color("32", "\xE2\x9C\x93 ") + msg);
31258
+ return true;
31259
+ }
31260
+ console.log(color("31", "\xE2\x9C\x97 ") + "ID mismatch between input.md and output.md");
31261
+ return false;
31262
+ }
31263
+ function queue_inbox_items(hub_path) {
31264
+ const inbox_dir = Path.join(hub_path, "threads/inbox");
31265
+ if (Fs.existsSync(inbox_dir)) {
31266
+ return Stdlib__List.length(Stdlib__List.filter_map((function(file) {
31267
+ const file_path = Path.join(inbox_dir, file);
31268
+ const content = Fs.readFileSync(file_path, "utf8");
31269
+ const meta = Cn_lib.parse_frontmatter(content);
31270
+ const is_queued = Stdlib__List.exists((function(param) {
31271
+ return param[0] === "queued-for-processing";
31272
+ }), meta);
31273
+ if (is_queued) {
31274
+ return;
31275
+ }
31276
+ const id = Path.basename(file, ".md");
31277
+ const from = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
31278
+ if (param[0] === "from") {
31279
+ return param[1];
31280
+ }
31281
+ }), meta), "unknown");
31282
+ queue_add(hub_path, id, from, content);
31283
+ const prim1 = Cn_lib.update_frontmatter(content, {
31284
+ hd: [
31285
+ "queued-for-processing",
31286
+ (/* @__PURE__ */ new Date()).toISOString()
31287
+ ],
31288
+ tl: (
31289
+ /* [] */
31290
+ 0
31291
+ )
31292
+ });
31293
+ Fs.writeFileSync(file_path, prim1);
31294
+ const msg = Curry._2(Stdlib__Printf.sprintf({
31295
+ TAG: (
31296
+ /* Format */
31297
+ 0
31298
+ ),
31299
+ _0: {
31300
+ TAG: (
31301
+ /* String_literal */
31302
+ 11
31303
+ ),
31304
+ _0: "Queued: ",
31305
+ _1: {
31306
+ TAG: (
31307
+ /* String */
31308
+ 2
31309
+ ),
31310
+ _0: (
31311
+ /* No_padding */
31312
+ 0
31313
+ ),
31314
+ _1: {
31315
+ TAG: (
31316
+ /* String_literal */
31317
+ 11
31318
+ ),
31319
+ _0: " (from ",
31320
+ _1: {
31321
+ TAG: (
31322
+ /* String */
31323
+ 2
31324
+ ),
31325
+ _0: (
31326
+ /* No_padding */
31327
+ 0
31328
+ ),
31329
+ _1: {
31330
+ TAG: (
31331
+ /* Char_literal */
31332
+ 12
31333
+ ),
31334
+ _0: (
31335
+ /* ')' */
31336
+ 41
31337
+ ),
31338
+ _1: (
31339
+ /* End_of_format */
31340
+ 0
31341
+ )
31342
+ }
31343
+ }
31344
+ }
31345
+ }
31346
+ },
31347
+ _1: "Queued: %s (from %s)"
31348
+ }), id, from);
31349
+ console.log(color("32", "\xE2\x9C\x93 ") + msg);
31350
+ return file;
31351
+ }), Stdlib__List.filter(is_md_file, Stdlib__Array.to_list(Fs.readdirSync(inbox_dir)))));
31352
+ } else {
31353
+ return 0;
31354
+ }
31355
+ }
31356
+ function feed_next_input(hub_path) {
31357
+ const inp = Path.join(hub_path, "state/input.md");
31358
+ const content = queue_pop(hub_path);
31359
+ if (content !== void 0) {
31360
+ ensure_dir(Path.join(hub_path, "state"));
31361
+ Fs.writeFileSync(inp, content);
31362
+ const meta = Cn_lib.parse_frontmatter(content);
31363
+ const id = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
31364
+ if (param[0] === "id") {
31365
+ return param[1];
31366
+ }
31367
+ }), meta), "unknown");
31368
+ const from = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
31369
+ if (param[0] === "from") {
31370
+ return param[1];
31371
+ }
31372
+ }), meta), "unknown");
31373
+ log_action(hub_path, "process.feed", Curry._2(Stdlib__Printf.sprintf({
31374
+ TAG: (
31375
+ /* Format */
31376
+ 0
31377
+ ),
31378
+ _0: {
31379
+ TAG: (
31380
+ /* String_literal */
31381
+ 11
31382
+ ),
31383
+ _0: "id:",
31384
+ _1: {
31385
+ TAG: (
31386
+ /* String */
31387
+ 2
31388
+ ),
31389
+ _0: (
31390
+ /* No_padding */
31391
+ 0
31392
+ ),
31393
+ _1: {
31394
+ TAG: (
31395
+ /* String_literal */
31396
+ 11
31397
+ ),
31398
+ _0: " from:",
31399
+ _1: {
31400
+ TAG: (
31401
+ /* String */
31402
+ 2
31403
+ ),
31404
+ _0: (
31405
+ /* No_padding */
31406
+ 0
31407
+ ),
31408
+ _1: (
31409
+ /* End_of_format */
31410
+ 0
31411
+ )
31412
+ }
31413
+ }
31414
+ }
31415
+ },
31416
+ _1: "id:%s from:%s"
31417
+ }), id, from));
31418
+ const msg = Curry._2(Stdlib__Printf.sprintf({
31419
+ TAG: (
31420
+ /* Format */
31421
+ 0
31422
+ ),
31423
+ _0: {
31424
+ TAG: (
31425
+ /* String_literal */
31426
+ 11
31427
+ ),
31428
+ _0: "Wrote state/input.md: ",
31429
+ _1: {
31430
+ TAG: (
31431
+ /* String */
31432
+ 2
31433
+ ),
31434
+ _0: (
31435
+ /* No_padding */
31436
+ 0
31437
+ ),
31438
+ _1: {
31439
+ TAG: (
31440
+ /* String_literal */
31441
+ 11
31442
+ ),
31443
+ _0: " (from ",
31444
+ _1: {
31445
+ TAG: (
31446
+ /* String */
31447
+ 2
31448
+ ),
31449
+ _0: (
31450
+ /* No_padding */
31451
+ 0
31452
+ ),
31453
+ _1: {
31454
+ TAG: (
31455
+ /* Char_literal */
31456
+ 12
31457
+ ),
31458
+ _0: (
31459
+ /* ')' */
31460
+ 41
31461
+ ),
31462
+ _1: (
31463
+ /* End_of_format */
31464
+ 0
31465
+ )
31466
+ }
31467
+ }
31468
+ }
31469
+ }
31470
+ },
31471
+ _1: "Wrote state/input.md: %s (from %s)"
31472
+ }), id, from);
31473
+ console.log(color("32", "\xE2\x9C\x93 ") + msg);
31474
+ const remaining = queue_count(hub_path);
31475
+ if (remaining > 0) {
31476
+ console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
31477
+ TAG: (
31478
+ /* Format */
31479
+ 0
31480
+ ),
31481
+ _0: {
31482
+ TAG: (
31483
+ /* String_literal */
31484
+ 11
31485
+ ),
31486
+ _0: "Queue depth: ",
31487
+ _1: {
31488
+ TAG: (
31489
+ /* Int */
31490
+ 4
31491
+ ),
31492
+ _0: (
31493
+ /* Int_d */
31494
+ 0
31495
+ ),
31496
+ _1: (
31497
+ /* No_padding */
31498
+ 0
31499
+ ),
31500
+ _2: (
31501
+ /* No_precision */
31502
+ 0
31503
+ ),
31504
+ _3: {
31505
+ TAG: (
31506
+ /* String_literal */
31507
+ 11
31508
+ ),
31509
+ _0: " remaining",
31510
+ _1: (
31511
+ /* End_of_format */
31512
+ 0
31513
+ )
31514
+ }
31515
+ }
31516
+ },
31517
+ _1: "Queue depth: %d remaining"
31518
+ }), remaining)));
31519
+ }
31520
+ return true;
31521
+ }
31522
+ console.log(color("32", "\xE2\x9C\x93 ") + "Queue empty - nothing to process");
31523
+ return false;
31524
+ }
31525
+ function wake_agent(param) {
31526
+ console.log(color("36", "Triggering OpenClaw wake..."));
31527
+ const match2 = exec("openclaw system event --text 'input.md ready' --mode now 2>/dev/null");
31528
+ if (match2 !== void 0) {
31529
+ console.log(color("32", "\xE2\x9C\x93 ") + "Wake triggered");
31530
+ } else {
31531
+ console.log(color("33", "\xE2\x9A\xA0 ") + "Wake trigger failed - is OpenClaw running?");
31532
+ }
31533
+ }
31534
+ function run_sync(hub_path, name) {
31535
+ console.log(color("36", "Syncing..."));
31536
+ inbox_check(hub_path, name);
31537
+ inbox_process(hub_path);
31538
+ outbox_flush(hub_path, name);
31539
+ console.log(color("32", "\xE2\x9C\x93 ") + "Sync complete");
31540
+ }
31541
+ function run_queue_list(hub_path) {
31542
+ const items = queue_list(hub_path);
31543
+ if (items) {
31544
+ console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
31545
+ TAG: (
31546
+ /* Format */
31547
+ 0
31548
+ ),
31549
+ _0: {
31550
+ TAG: (
31551
+ /* String_literal */
31552
+ 11
31553
+ ),
31554
+ _0: "Queue depth: ",
31555
+ _1: {
31556
+ TAG: (
31557
+ /* Int */
31558
+ 4
31559
+ ),
31560
+ _0: (
31561
+ /* Int_d */
31562
+ 0
31563
+ ),
31564
+ _1: (
31565
+ /* No_padding */
31566
+ 0
31567
+ ),
31568
+ _2: (
31569
+ /* No_precision */
31570
+ 0
31571
+ ),
31572
+ _3: (
31573
+ /* End_of_format */
31574
+ 0
31575
+ )
31576
+ }
31577
+ },
31578
+ _1: "Queue depth: %d"
31579
+ }), Stdlib__List.length(items))));
31580
+ return Stdlib__List.iter((function(file) {
31581
+ const file_path = Path.join(Path.join(hub_path, "state/queue"), file);
31582
+ const content = Fs.readFileSync(file_path, "utf8");
31583
+ const meta = Cn_lib.parse_frontmatter(content);
31584
+ const id = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
31585
+ if (param[0] === "id") {
31586
+ return param[1];
31587
+ }
31588
+ }), meta), "?");
31589
+ const from = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
31590
+ if (param[0] === "from") {
31591
+ return param[1];
31592
+ }
31593
+ }), meta), "?");
31594
+ console.log(Curry._2(Stdlib__Printf.sprintf({
31595
+ TAG: (
31596
+ /* Format */
31597
+ 0
31598
+ ),
31599
+ _0: {
31600
+ TAG: (
31601
+ /* String_literal */
31602
+ 11
31603
+ ),
31604
+ _0: " ",
31605
+ _1: {
31606
+ TAG: (
31607
+ /* String */
31608
+ 2
31609
+ ),
31610
+ _0: (
31611
+ /* No_padding */
31612
+ 0
31613
+ ),
31614
+ _1: {
31615
+ TAG: (
31616
+ /* String_literal */
31617
+ 11
31618
+ ),
31619
+ _0: " (from ",
31620
+ _1: {
31621
+ TAG: (
31622
+ /* String */
31623
+ 2
31624
+ ),
31625
+ _0: (
31626
+ /* No_padding */
31627
+ 0
31628
+ ),
31629
+ _1: {
31630
+ TAG: (
31631
+ /* Char_literal */
31632
+ 12
31633
+ ),
31634
+ _0: (
31635
+ /* ')' */
31636
+ 41
31637
+ ),
31638
+ _1: (
31639
+ /* End_of_format */
31640
+ 0
31641
+ )
31642
+ }
31643
+ }
31644
+ }
31645
+ }
31646
+ },
31647
+ _1: " %s (from %s)"
31648
+ }), id, from));
31649
+ }), items);
31650
+ } else {
31651
+ console.log("(queue empty)");
31652
+ return;
31653
+ }
31654
+ }
31655
+ function run_queue_clear(hub_path) {
31656
+ const dir = Path.join(hub_path, "state/queue");
31657
+ if (Fs.existsSync(dir)) {
31658
+ const items = Stdlib__List.filter(is_md_file, Stdlib__Array.to_list(Fs.readdirSync(dir)));
31659
+ Stdlib__List.iter((function(file) {
31660
+ const prim = Path.join(dir, file);
31661
+ Fs.unlinkSync(prim);
31662
+ }), items);
31663
+ log_action(hub_path, "queue.clear", Curry._1(Stdlib__Printf.sprintf({
31664
+ TAG: (
31665
+ /* Format */
31666
+ 0
31667
+ ),
31668
+ _0: {
31669
+ TAG: (
31670
+ /* String_literal */
31671
+ 11
31672
+ ),
31673
+ _0: "count:",
31674
+ _1: {
31675
+ TAG: (
31676
+ /* Int */
31677
+ 4
31678
+ ),
31679
+ _0: (
31680
+ /* Int_d */
31681
+ 0
31682
+ ),
31683
+ _1: (
31684
+ /* No_padding */
31685
+ 0
31686
+ ),
31687
+ _2: (
31688
+ /* No_precision */
31689
+ 0
31690
+ ),
31691
+ _3: (
31692
+ /* End_of_format */
31693
+ 0
31694
+ )
31695
+ }
31696
+ },
31697
+ _1: "count:%d"
31698
+ }), Stdlib__List.length(items)));
31699
+ const msg = Curry._1(Stdlib__Printf.sprintf({
31700
+ TAG: (
31701
+ /* Format */
31702
+ 0
31703
+ ),
31704
+ _0: {
31705
+ TAG: (
31706
+ /* String_literal */
31707
+ 11
31708
+ ),
31709
+ _0: "Cleared ",
31710
+ _1: {
31711
+ TAG: (
31712
+ /* Int */
31713
+ 4
31714
+ ),
31715
+ _0: (
31716
+ /* Int_d */
31717
+ 0
31718
+ ),
31719
+ _1: (
31720
+ /* No_padding */
31721
+ 0
31722
+ ),
31723
+ _2: (
31724
+ /* No_precision */
31725
+ 0
31726
+ ),
31727
+ _3: {
31728
+ TAG: (
31729
+ /* String_literal */
31730
+ 11
31731
+ ),
31732
+ _0: " item(s) from queue",
31733
+ _1: (
31734
+ /* End_of_format */
31735
+ 0
31736
+ )
31737
+ }
31738
+ }
31739
+ },
31740
+ _1: "Cleared %d item(s) from queue"
31741
+ }), Stdlib__List.length(items));
31742
+ console.log(color("32", "\xE2\x9C\x93 ") + msg);
31743
+ return;
31744
+ }
31745
+ console.log(color("32", "\xE2\x9C\x93 ") + "Queue already empty");
31746
+ }
31747
+ function run_mca_add(hub_path, name, description) {
31748
+ const dir = Path.join(hub_path, "state/mca");
31749
+ ensure_dir(dir);
31750
+ const ts = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
31751
+ const slug = description.slice(0, 40).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
31752
+ const file_name = Curry._2(Stdlib__Printf.sprintf({
31753
+ TAG: (
31754
+ /* Format */
31755
+ 0
31756
+ ),
31757
+ _0: {
31758
+ TAG: (
31759
+ /* String */
31760
+ 2
31761
+ ),
31762
+ _0: (
31763
+ /* No_padding */
31764
+ 0
31765
+ ),
31766
+ _1: {
31767
+ TAG: (
31768
+ /* Char_literal */
31769
+ 12
31770
+ ),
31771
+ _0: (
31772
+ /* '-' */
31773
+ 45
31774
+ ),
31775
+ _1: {
31776
+ TAG: (
31777
+ /* String */
31778
+ 2
31779
+ ),
31780
+ _0: (
31781
+ /* No_padding */
31782
+ 0
31783
+ ),
31784
+ _1: {
31785
+ TAG: (
31786
+ /* String_literal */
31787
+ 11
31788
+ ),
31789
+ _0: ".md",
31790
+ _1: (
31791
+ /* End_of_format */
31792
+ 0
31793
+ )
31794
+ }
31795
+ }
31796
+ }
31797
+ },
31798
+ _1: "%s-%s.md"
31799
+ }), ts, slug);
31800
+ const file_path = Path.join(dir, file_name);
31801
+ const content = Curry._4(Stdlib__Printf.sprintf({
31802
+ TAG: (
31803
+ /* Format */
31804
+ 0
31805
+ ),
31806
+ _0: {
31807
+ TAG: (
31808
+ /* String_literal */
31809
+ 11
31810
+ ),
31811
+ _0: "---\nid: ",
31812
+ _1: {
31813
+ TAG: (
31814
+ /* String */
31815
+ 2
31816
+ ),
31817
+ _0: (
31818
+ /* No_padding */
31819
+ 0
31820
+ ),
31821
+ _1: {
31822
+ TAG: (
31823
+ /* String_literal */
31824
+ 11
31825
+ ),
31826
+ _0: "\nsurfaced-by: ",
31827
+ _1: {
31828
+ TAG: (
31829
+ /* String */
31830
+ 2
31831
+ ),
31832
+ _0: (
31833
+ /* No_padding */
31834
+ 0
31835
+ ),
31836
+ _1: {
31837
+ TAG: (
31838
+ /* String_literal */
31839
+ 11
31840
+ ),
31841
+ _0: "\ncreated: ",
31842
+ _1: {
31843
+ TAG: (
31844
+ /* String */
31845
+ 2
31846
+ ),
31847
+ _0: (
31848
+ /* No_padding */
31849
+ 0
31850
+ ),
31851
+ _1: {
31852
+ TAG: (
31853
+ /* String_literal */
31854
+ 11
31855
+ ),
31856
+ _0: "\nstatus: open\n---\n\n# MCA\n\n",
31857
+ _1: {
31858
+ TAG: (
31859
+ /* String */
31860
+ 2
31861
+ ),
31862
+ _0: (
31863
+ /* No_padding */
31864
+ 0
31865
+ ),
31866
+ _1: {
31867
+ TAG: (
31868
+ /* Char_literal */
31869
+ 12
31870
+ ),
31871
+ _0: (
31872
+ /* '\n' */
31873
+ 10
31874
+ ),
31875
+ _1: (
31876
+ /* End_of_format */
31877
+ 0
31878
+ )
31879
+ }
31880
+ }
31881
+ }
31882
+ }
31883
+ }
31884
+ }
31885
+ }
31886
+ }
31887
+ },
31888
+ _1: "---\nid: %s\nsurfaced-by: %s\ncreated: %s\nstatus: open\n---\n\n# MCA\n\n%s\n"
31889
+ }), slug, name, (/* @__PURE__ */ new Date()).toISOString(), description);
31890
+ Fs.writeFileSync(file_path, content);
31891
+ log_action(hub_path, "mca.add", Curry._2(Stdlib__Printf.sprintf({
31892
+ TAG: (
31893
+ /* Format */
31894
+ 0
31895
+ ),
31896
+ _0: {
31897
+ TAG: (
31898
+ /* String_literal */
31899
+ 11
31900
+ ),
31901
+ _0: "id:",
31902
+ _1: {
31903
+ TAG: (
31904
+ /* String */
31905
+ 2
31906
+ ),
31907
+ _0: (
31908
+ /* No_padding */
31909
+ 0
31910
+ ),
31911
+ _1: {
31912
+ TAG: (
31913
+ /* String_literal */
31914
+ 11
31915
+ ),
31916
+ _0: " desc:",
31917
+ _1: {
31918
+ TAG: (
31919
+ /* String */
31920
+ 2
31921
+ ),
31922
+ _0: (
31923
+ /* No_padding */
31924
+ 0
31925
+ ),
31926
+ _1: (
31927
+ /* End_of_format */
31928
+ 0
31929
+ )
31930
+ }
31931
+ }
31932
+ }
31933
+ },
31934
+ _1: "id:%s desc:%s"
31935
+ }), slug, description));
31936
+ const msg = Curry._1(Stdlib__Printf.sprintf({
31937
+ TAG: (
31938
+ /* Format */
31939
+ 0
31940
+ ),
31941
+ _0: {
31942
+ TAG: (
31943
+ /* String_literal */
31944
+ 11
31945
+ ),
31946
+ _0: "MCA surfaced: ",
31947
+ _1: {
31948
+ TAG: (
31949
+ /* String */
31950
+ 2
31951
+ ),
31952
+ _0: (
31953
+ /* No_padding */
31954
+ 0
31955
+ ),
31956
+ _1: (
31957
+ /* End_of_format */
31958
+ 0
31959
+ )
31960
+ }
31961
+ },
31962
+ _1: "MCA surfaced: %s"
31963
+ }), description);
31964
+ console.log(color("32", "\xE2\x9C\x93 ") + msg);
31965
+ }
31966
+ function run_mca_list(hub_path) {
31967
+ const dir = Path.join(hub_path, "state/mca");
31968
+ if (Fs.existsSync(dir)) {
31969
+ const items = Stdlib__List.sort(Stdlib__String.compare, Stdlib__List.filter(is_md_file, Stdlib__Array.to_list(Fs.readdirSync(dir))));
31970
+ if (items) {
31971
+ console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
31972
+ TAG: (
31973
+ /* Format */
31974
+ 0
31975
+ ),
31976
+ _0: {
31977
+ TAG: (
31978
+ /* String_literal */
31979
+ 11
31980
+ ),
31981
+ _0: "Open MCAs: ",
31982
+ _1: {
31983
+ TAG: (
31984
+ /* Int */
31985
+ 4
31986
+ ),
31987
+ _0: (
31988
+ /* Int_d */
31989
+ 0
31990
+ ),
31991
+ _1: (
31992
+ /* No_padding */
31993
+ 0
31994
+ ),
31995
+ _2: (
31996
+ /* No_precision */
31997
+ 0
31998
+ ),
31999
+ _3: (
32000
+ /* End_of_format */
32001
+ 0
32002
+ )
32003
+ }
32004
+ },
32005
+ _1: "Open MCAs: %d"
32006
+ }), Stdlib__List.length(items))));
32007
+ return Stdlib__List.iter((function(file) {
32008
+ const file_path = Path.join(dir, file);
32009
+ const content = Fs.readFileSync(file_path, "utf8");
32010
+ const meta = Cn_lib.parse_frontmatter(content);
32011
+ const id = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
32012
+ if (param[0] === "id") {
32013
+ return param[1];
32014
+ }
32015
+ }), meta), "?");
32016
+ const by = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
32017
+ if (param[0] === "surfaced-by") {
32018
+ return param[1];
32019
+ }
32020
+ }), meta), "?");
32021
+ const lines = Stdlib__String.split_on_char(
32022
+ /* '\n' */
32023
+ 10,
32024
+ content
32025
+ );
32026
+ const skip_frontmatter = function(_in_fm, _rest) {
32027
+ while (true) {
32028
+ const rest = _rest;
32029
+ const in_fm = _in_fm;
32030
+ if (!rest) {
32031
+ return (
32032
+ /* [] */
32033
+ 0
32034
+ );
32035
+ }
32036
+ if (rest.hd === "---") {
32037
+ const rest$1 = rest.tl;
32038
+ if (in_fm) {
32039
+ if (in_fm) {
32040
+ return rest$1;
32041
+ }
32042
+ } else {
32043
+ _rest = rest$1;
32044
+ _in_fm = true;
32045
+ continue;
32046
+ }
32047
+ }
32048
+ if (!in_fm) {
32049
+ return rest;
32050
+ }
32051
+ _rest = rest.tl;
32052
+ continue;
32053
+ }
32054
+ ;
32055
+ };
32056
+ const body_lines = skip_frontmatter(false, lines);
32057
+ const desc = Stdlib__Option.value(Stdlib__List.find_opt((function(l) {
32058
+ const t = Stdlib__String.trim(l);
32059
+ if (t !== "") {
32060
+ return !Cn_lib.starts_with("#", t);
32061
+ } else {
32062
+ return false;
32063
+ }
32064
+ }), body_lines), "(no description)");
32065
+ console.log(Curry._3(Stdlib__Printf.sprintf({
32066
+ TAG: (
32067
+ /* Format */
32068
+ 0
32069
+ ),
32070
+ _0: {
32071
+ TAG: (
32072
+ /* String_literal */
32073
+ 11
32074
+ ),
32075
+ _0: " [",
32076
+ _1: {
32077
+ TAG: (
32078
+ /* String */
32079
+ 2
32080
+ ),
32081
+ _0: (
32082
+ /* No_padding */
32083
+ 0
32084
+ ),
32085
+ _1: {
32086
+ TAG: (
32087
+ /* String_literal */
32088
+ 11
32089
+ ),
32090
+ _0: "] ",
32091
+ _1: {
32092
+ TAG: (
32093
+ /* String */
32094
+ 2
32095
+ ),
32096
+ _0: (
32097
+ /* No_padding */
32098
+ 0
32099
+ ),
32100
+ _1: {
32101
+ TAG: (
32102
+ /* String_literal */
32103
+ 11
32104
+ ),
32105
+ _0: " (by ",
32106
+ _1: {
32107
+ TAG: (
32108
+ /* String */
32109
+ 2
32110
+ ),
32111
+ _0: (
32112
+ /* No_padding */
32113
+ 0
32114
+ ),
32115
+ _1: {
32116
+ TAG: (
32117
+ /* Char_literal */
32118
+ 12
32119
+ ),
32120
+ _0: (
32121
+ /* ')' */
32122
+ 41
32123
+ ),
32124
+ _1: (
32125
+ /* End_of_format */
32126
+ 0
32127
+ )
32128
+ }
32129
+ }
32130
+ }
32131
+ }
32132
+ }
32133
+ }
32134
+ },
32135
+ _1: " [%s] %s (by %s)"
32136
+ }), id, Stdlib__String.trim(desc), by));
32137
+ }), items);
32138
+ } else {
32139
+ console.log("(no MCAs)");
32140
+ return;
32141
+ }
32142
+ }
32143
+ console.log("(no MCAs)");
32144
+ }
32145
+ function mca_cycle_path(hub_path) {
32146
+ return Path.join(hub_path, "state/.mca-cycle");
32147
+ }
32148
+ function get_mca_cycle(hub_path) {
32149
+ const path = Path.join(hub_path, "state/.mca-cycle");
32150
+ if (Fs.existsSync(path)) {
32151
+ return Stdlib__Option.value(Stdlib.int_of_string_opt(Stdlib__String.trim(Fs.readFileSync(path, "utf8"))), 0);
32152
+ } else {
32153
+ return 0;
32154
+ }
32155
+ }
32156
+ function increment_mca_cycle(hub_path) {
32157
+ const current = get_mca_cycle(hub_path);
32158
+ const next = current + 1 | 0;
32159
+ const prim1 = String(next);
32160
+ const prim0 = Path.join(hub_path, "state/.mca-cycle");
32161
+ Fs.writeFileSync(prim0, prim1);
32162
+ return next;
32163
+ }
32164
+ function mca_count(hub_path) {
32165
+ const dir = Path.join(hub_path, "state/mca");
32166
+ if (Fs.existsSync(dir)) {
32167
+ return Stdlib__List.length(Stdlib__List.filter(is_md_file, Stdlib__Array.to_list(Fs.readdirSync(dir))));
32168
+ } else {
32169
+ return 0;
32170
+ }
32171
+ }
32172
+ function queue_mca_review(hub_path) {
32173
+ const dir = Path.join(hub_path, "state/mca");
32174
+ const mcas = Stdlib__List.sort(Stdlib__String.compare, Stdlib__List.filter(is_md_file, Stdlib__Array.to_list(Fs.readdirSync(dir))));
32175
+ const mca_list = Stdlib__String.concat("\n", Stdlib__List.map((function(file) {
32176
+ const content = Fs.readFileSync(Path.join(dir, file), "utf8");
32177
+ const meta = Cn_lib.parse_frontmatter(content);
32178
+ const id = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
32179
+ if (param[0] === "id") {
32180
+ return param[1];
32181
+ }
32182
+ }), meta), "?");
32183
+ const by = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
32184
+ if (param[0] === "surfaced-by") {
32185
+ return param[1];
32186
+ }
32187
+ }), meta), "?");
32188
+ const lines = Stdlib__String.split_on_char(
32189
+ /* '\n' */
32190
+ 10,
32191
+ content
32192
+ );
32193
+ const skip_fm = function(_in_fm, _rest) {
32194
+ while (true) {
32195
+ const rest = _rest;
32196
+ const in_fm = _in_fm;
32197
+ if (!rest) {
32198
+ return (
32199
+ /* [] */
32200
+ 0
32201
+ );
30628
32202
  }
30629
- },
30630
- _1: "count:%d"
30631
- }), Stdlib__List.length(items)));
30632
- const msg = Curry._1(Stdlib__Printf.sprintf({
32203
+ if (rest.hd === "---") {
32204
+ const rest$1 = rest.tl;
32205
+ if (in_fm) {
32206
+ if (in_fm) {
32207
+ return rest$1;
32208
+ }
32209
+ } else {
32210
+ _rest = rest$1;
32211
+ _in_fm = true;
32212
+ continue;
32213
+ }
32214
+ }
32215
+ if (!in_fm) {
32216
+ return rest;
32217
+ }
32218
+ _rest = rest.tl;
32219
+ continue;
32220
+ }
32221
+ ;
32222
+ };
32223
+ const body_lines = skip_fm(false, lines);
32224
+ const desc = Stdlib__Option.value(Stdlib__List.find_opt((function(l) {
32225
+ const t = Stdlib__String.trim(l);
32226
+ if (t !== "") {
32227
+ return !Cn_lib.starts_with("#", t);
32228
+ } else {
32229
+ return false;
32230
+ }
32231
+ }), body_lines), "(no description)");
32232
+ return Curry._3(Stdlib__Printf.sprintf({
30633
32233
  TAG: (
30634
32234
  /* Format */
30635
32235
  0
@@ -30639,102 +32239,98 @@ function run_queue_clear(hub_path) {
30639
32239
  /* String_literal */
30640
32240
  11
30641
32241
  ),
30642
- _0: "Cleared ",
32242
+ _0: "- [",
30643
32243
  _1: {
30644
32244
  TAG: (
30645
- /* Int */
30646
- 4
32245
+ /* String */
32246
+ 2
30647
32247
  ),
30648
32248
  _0: (
30649
- /* Int_d */
30650
- 0
30651
- ),
30652
- _1: (
30653
32249
  /* No_padding */
30654
32250
  0
30655
32251
  ),
30656
- _2: (
30657
- /* No_precision */
30658
- 0
30659
- ),
30660
- _3: {
32252
+ _1: {
30661
32253
  TAG: (
30662
32254
  /* String_literal */
30663
32255
  11
30664
32256
  ),
30665
- _0: " item(s) from queue",
30666
- _1: (
30667
- /* End_of_format */
30668
- 0
30669
- )
32257
+ _0: "] ",
32258
+ _1: {
32259
+ TAG: (
32260
+ /* String */
32261
+ 2
32262
+ ),
32263
+ _0: (
32264
+ /* No_padding */
32265
+ 0
32266
+ ),
32267
+ _1: {
32268
+ TAG: (
32269
+ /* String_literal */
32270
+ 11
32271
+ ),
32272
+ _0: " (by ",
32273
+ _1: {
32274
+ TAG: (
32275
+ /* String */
32276
+ 2
32277
+ ),
32278
+ _0: (
32279
+ /* No_padding */
32280
+ 0
32281
+ ),
32282
+ _1: {
32283
+ TAG: (
32284
+ /* Char_literal */
32285
+ 12
32286
+ ),
32287
+ _0: (
32288
+ /* ')' */
32289
+ 41
32290
+ ),
32291
+ _1: (
32292
+ /* End_of_format */
32293
+ 0
32294
+ )
32295
+ }
32296
+ }
32297
+ }
32298
+ }
30670
32299
  }
30671
32300
  }
30672
32301
  },
30673
- _1: "Cleared %d item(s) from queue"
30674
- }), Stdlib__List.length(items));
30675
- console.log(color("32", "\xE2\x9C\x93 ") + msg);
30676
- return;
30677
- }
30678
- console.log(color("32", "\xE2\x9C\x93 ") + "Queue already empty");
30679
- }
30680
- function mca_dir(hub_path) {
30681
- return Path.join(hub_path, "state/mca");
30682
- }
30683
- function run_mca_add(hub_path, name, description) {
30684
- const dir = Path.join(hub_path, "state/mca");
30685
- ensure_dir(dir);
30686
- const ts = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
30687
- const slug = description.slice(0, 40).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
30688
- const file_name = Curry._2(Stdlib__Printf.sprintf({
32302
+ _1: "- [%s] %s (by %s)"
32303
+ }), id, Stdlib__String.trim(desc), by);
32304
+ }), mcas));
32305
+ const review_id = Curry._1(Stdlib__Printf.sprintf({
30689
32306
  TAG: (
30690
32307
  /* Format */
30691
32308
  0
30692
32309
  ),
30693
32310
  _0: {
30694
32311
  TAG: (
30695
- /* String */
30696
- 2
30697
- ),
30698
- _0: (
30699
- /* No_padding */
30700
- 0
32312
+ /* String_literal */
32313
+ 11
30701
32314
  ),
32315
+ _0: "mca-review-",
30702
32316
  _1: {
30703
32317
  TAG: (
30704
- /* Char_literal */
30705
- 12
32318
+ /* String */
32319
+ 2
30706
32320
  ),
30707
32321
  _0: (
30708
- /* '-' */
30709
- 45
32322
+ /* No_padding */
32323
+ 0
30710
32324
  ),
30711
- _1: {
30712
- TAG: (
30713
- /* String */
30714
- 2
30715
- ),
30716
- _0: (
30717
- /* No_padding */
30718
- 0
30719
- ),
30720
- _1: {
30721
- TAG: (
30722
- /* String_literal */
30723
- 11
30724
- ),
30725
- _0: ".md",
30726
- _1: (
30727
- /* End_of_format */
30728
- 0
30729
- )
30730
- }
30731
- }
32325
+ _1: (
32326
+ /* End_of_format */
32327
+ 0
32328
+ )
30732
32329
  }
30733
32330
  },
30734
- _1: "%s-%s.md"
30735
- }), ts, slug);
30736
- const file_path = Path.join(dir, file_name);
30737
- const content = Curry._4(Stdlib__Printf.sprintf({
32331
+ _1: "mca-review-%s"
32332
+ }), (/* @__PURE__ */ new Date()).toISOString().slice(0, 10));
32333
+ const body = Curry._1(Stdlib__Printf.sprintf({
30738
32334
  TAG: (
30739
32335
  /* Format */
30740
32336
  0
@@ -30744,7 +32340,7 @@ function run_mca_add(hub_path, name, description) {
30744
32340
  /* String_literal */
30745
32341
  11
30746
32342
  ),
30747
- _0: "---\nid: ",
32343
+ _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",
30748
32344
  _1: {
30749
32345
  TAG: (
30750
32346
  /* String */
@@ -30756,75 +32352,24 @@ function run_mca_add(hub_path, name, description) {
30756
32352
  ),
30757
32353
  _1: {
30758
32354
  TAG: (
30759
- /* String_literal */
30760
- 11
32355
+ /* Char_literal */
32356
+ 12
30761
32357
  ),
30762
- _0: "\nsurfaced-by: ",
30763
- _1: {
30764
- TAG: (
30765
- /* String */
30766
- 2
30767
- ),
30768
- _0: (
30769
- /* No_padding */
30770
- 0
30771
- ),
30772
- _1: {
30773
- TAG: (
30774
- /* String_literal */
30775
- 11
30776
- ),
30777
- _0: "\ncreated: ",
30778
- _1: {
30779
- TAG: (
30780
- /* String */
30781
- 2
30782
- ),
30783
- _0: (
30784
- /* No_padding */
30785
- 0
30786
- ),
30787
- _1: {
30788
- TAG: (
30789
- /* String_literal */
30790
- 11
30791
- ),
30792
- _0: "\nstatus: open\n---\n\n# MCA\n\n",
30793
- _1: {
30794
- TAG: (
30795
- /* String */
30796
- 2
30797
- ),
30798
- _0: (
30799
- /* No_padding */
30800
- 0
30801
- ),
30802
- _1: {
30803
- TAG: (
30804
- /* Char_literal */
30805
- 12
30806
- ),
30807
- _0: (
30808
- /* '\n' */
30809
- 10
30810
- ),
30811
- _1: (
30812
- /* End_of_format */
30813
- 0
30814
- )
30815
- }
30816
- }
30817
- }
30818
- }
30819
- }
30820
- }
32358
+ _0: (
32359
+ /* '\n' */
32360
+ 10
32361
+ ),
32362
+ _1: (
32363
+ /* End_of_format */
32364
+ 0
32365
+ )
30821
32366
  }
30822
32367
  }
30823
32368
  },
30824
- _1: "---\nid: %s\nsurfaced-by: %s\ncreated: %s\nstatus: open\n---\n\n# MCA\n\n%s\n"
30825
- }), slug, name, (/* @__PURE__ */ new Date()).toISOString(), description);
30826
- Fs.writeFileSync(file_path, content);
30827
- log_action(hub_path, "mca.add", Curry._2(Stdlib__Printf.sprintf({
32369
+ _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"
32370
+ }), mca_list);
32371
+ queue_add(hub_path, review_id, "system", body);
32372
+ log_action(hub_path, "mca.review-queued", Curry._1(Stdlib__Printf.sprintf({
30828
32373
  TAG: (
30829
32374
  /* Format */
30830
32375
  0
@@ -30834,41 +32379,32 @@ function run_mca_add(hub_path, name, description) {
30834
32379
  /* String_literal */
30835
32380
  11
30836
32381
  ),
30837
- _0: "id:",
32382
+ _0: "count:",
30838
32383
  _1: {
30839
32384
  TAG: (
30840
- /* String */
30841
- 2
32385
+ /* Int */
32386
+ 4
30842
32387
  ),
30843
32388
  _0: (
32389
+ /* Int_d */
32390
+ 0
32391
+ ),
32392
+ _1: (
30844
32393
  /* No_padding */
30845
32394
  0
30846
32395
  ),
30847
- _1: {
30848
- TAG: (
30849
- /* String_literal */
30850
- 11
30851
- ),
30852
- _0: " desc:",
30853
- _1: {
30854
- TAG: (
30855
- /* String */
30856
- 2
30857
- ),
30858
- _0: (
30859
- /* No_padding */
30860
- 0
30861
- ),
30862
- _1: (
30863
- /* End_of_format */
30864
- 0
30865
- )
30866
- }
30867
- }
32396
+ _2: (
32397
+ /* No_precision */
32398
+ 0
32399
+ ),
32400
+ _3: (
32401
+ /* End_of_format */
32402
+ 0
32403
+ )
30868
32404
  }
30869
32405
  },
30870
- _1: "id:%s desc:%s"
30871
- }), slug, description));
32406
+ _1: "count:%d"
32407
+ }), Stdlib__List.length(mcas)));
30872
32408
  const msg = Curry._1(Stdlib__Printf.sprintf({
30873
32409
  TAG: (
30874
32410
  /* Format */
@@ -30879,204 +32415,145 @@ function run_mca_add(hub_path, name, description) {
30879
32415
  /* String_literal */
30880
32416
  11
30881
32417
  ),
30882
- _0: "MCA surfaced: ",
32418
+ _0: "Queued MCA review (",
30883
32419
  _1: {
30884
32420
  TAG: (
30885
- /* String */
30886
- 2
32421
+ /* Int */
32422
+ 4
30887
32423
  ),
30888
32424
  _0: (
30889
- /* No_padding */
32425
+ /* Int_d */
30890
32426
  0
30891
32427
  ),
30892
32428
  _1: (
30893
- /* End_of_format */
32429
+ /* No_padding */
30894
32430
  0
30895
- )
32431
+ ),
32432
+ _2: (
32433
+ /* No_precision */
32434
+ 0
32435
+ ),
32436
+ _3: {
32437
+ TAG: (
32438
+ /* String_literal */
32439
+ 11
32440
+ ),
32441
+ _0: " MCAs)",
32442
+ _1: (
32443
+ /* End_of_format */
32444
+ 0
32445
+ )
32446
+ }
30896
32447
  }
30897
32448
  },
30898
- _1: "MCA surfaced: %s"
30899
- }), description);
32449
+ _1: "Queued MCA review (%d MCAs)"
32450
+ }), Stdlib__List.length(mcas));
30900
32451
  console.log(color("32", "\xE2\x9C\x93 ") + msg);
30901
32452
  }
30902
- function run_mca_list(hub_path) {
30903
- const dir = Path.join(hub_path, "state/mca");
30904
- if (Fs.existsSync(dir)) {
30905
- const items = Stdlib__List.sort(Stdlib__String.compare, Stdlib__List.filter(is_md_file, Stdlib__Array.to_list(Fs.readdirSync(dir))));
30906
- if (items) {
30907
- console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
32453
+ function run_process(hub_path, name) {
32454
+ console.log(color("36", "cn process: actor loop..."));
32455
+ const queued = queue_inbox_items(hub_path);
32456
+ if (queued > 0) {
32457
+ console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
32458
+ TAG: (
32459
+ /* Format */
32460
+ 0
32461
+ ),
32462
+ _0: {
30908
32463
  TAG: (
30909
- /* Format */
30910
- 0
32464
+ /* String_literal */
32465
+ 11
30911
32466
  ),
30912
- _0: {
32467
+ _0: "Added ",
32468
+ _1: {
30913
32469
  TAG: (
30914
- /* String_literal */
30915
- 11
32470
+ /* Int */
32471
+ 4
30916
32472
  ),
30917
- _0: "Open MCAs: ",
30918
- _1: {
32473
+ _0: (
32474
+ /* Int_d */
32475
+ 0
32476
+ ),
32477
+ _1: (
32478
+ /* No_padding */
32479
+ 0
32480
+ ),
32481
+ _2: (
32482
+ /* No_precision */
32483
+ 0
32484
+ ),
32485
+ _3: {
30919
32486
  TAG: (
30920
- /* Int */
30921
- 4
30922
- ),
30923
- _0: (
30924
- /* Int_d */
30925
- 0
32487
+ /* String_literal */
32488
+ 11
30926
32489
  ),
32490
+ _0: " item(s) to queue",
30927
32491
  _1: (
30928
- /* No_padding */
30929
- 0
30930
- ),
30931
- _2: (
30932
- /* No_precision */
30933
- 0
30934
- ),
30935
- _3: (
30936
32492
  /* End_of_format */
30937
32493
  0
30938
32494
  )
30939
32495
  }
30940
- },
30941
- _1: "Open MCAs: %d"
30942
- }), Stdlib__List.length(items))));
30943
- return Stdlib__List.iter((function(file) {
30944
- const file_path = Path.join(dir, file);
30945
- const content = Fs.readFileSync(file_path, "utf8");
30946
- const meta = Cn_lib.parse_frontmatter(content);
30947
- const id = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
30948
- if (param[0] === "id") {
30949
- return param[1];
30950
- }
30951
- }), meta), "?");
30952
- const by = Stdlib__Option.value(Stdlib__List.find_map((function(param) {
30953
- if (param[0] === "surfaced-by") {
30954
- return param[1];
30955
- }
30956
- }), meta), "?");
30957
- const lines = Stdlib__String.split_on_char(
30958
- /* '\n' */
30959
- 10,
30960
- content
30961
- );
30962
- const skip_frontmatter = function(_in_fm, _rest) {
30963
- while (true) {
30964
- const rest = _rest;
30965
- const in_fm = _in_fm;
30966
- if (!rest) {
30967
- return (
30968
- /* [] */
30969
- 0
30970
- );
30971
- }
30972
- if (rest.hd === "---") {
30973
- const rest$1 = rest.tl;
30974
- if (in_fm) {
30975
- if (in_fm) {
30976
- return rest$1;
30977
- }
30978
- } else {
30979
- _rest = rest$1;
30980
- _in_fm = true;
30981
- continue;
30982
- }
30983
- }
30984
- if (!in_fm) {
30985
- return rest;
30986
- }
30987
- _rest = rest.tl;
30988
- continue;
30989
- }
30990
- ;
30991
- };
30992
- const body_lines = skip_frontmatter(false, lines);
30993
- const desc = Stdlib__Option.value(Stdlib__List.find_opt((function(l) {
30994
- const t = Stdlib__String.trim(l);
30995
- if (t !== "") {
30996
- return !Cn_lib.starts_with("#", t);
30997
- } else {
30998
- return false;
30999
- }
31000
- }), body_lines), "(no description)");
31001
- console.log(Curry._3(Stdlib__Printf.sprintf({
31002
- TAG: (
31003
- /* Format */
31004
- 0
31005
- ),
31006
- _0: {
31007
- TAG: (
31008
- /* String_literal */
31009
- 11
31010
- ),
31011
- _0: " [",
31012
- _1: {
31013
- TAG: (
31014
- /* String */
31015
- 2
31016
- ),
31017
- _0: (
31018
- /* No_padding */
31019
- 0
31020
- ),
31021
- _1: {
31022
- TAG: (
31023
- /* String_literal */
31024
- 11
31025
- ),
31026
- _0: "] ",
31027
- _1: {
31028
- TAG: (
31029
- /* String */
31030
- 2
31031
- ),
31032
- _0: (
31033
- /* No_padding */
31034
- 0
31035
- ),
31036
- _1: {
31037
- TAG: (
31038
- /* String_literal */
31039
- 11
31040
- ),
31041
- _0: " (by ",
31042
- _1: {
31043
- TAG: (
31044
- /* String */
31045
- 2
31046
- ),
31047
- _0: (
31048
- /* No_padding */
31049
- 0
31050
- ),
31051
- _1: {
31052
- TAG: (
31053
- /* Char_literal */
31054
- 12
31055
- ),
31056
- _0: (
31057
- /* ')' */
31058
- 41
31059
- ),
31060
- _1: (
31061
- /* End_of_format */
31062
- 0
31063
- )
31064
- }
31065
- }
31066
- }
31067
- }
31068
- }
31069
- }
31070
- },
31071
- _1: " [%s] %s (by %s)"
31072
- }), id, Stdlib__String.trim(desc), by));
31073
- }), items);
32496
+ }
32497
+ },
32498
+ _1: "Added %d item(s) to queue"
32499
+ }), queued)));
32500
+ }
32501
+ const cycle = increment_mca_cycle(hub_path);
32502
+ if (cycle % 5 === 0 && mca_count(hub_path) > 0) {
32503
+ queue_mca_review(hub_path);
32504
+ }
32505
+ const inp = Path.join(hub_path, "state/input.md");
32506
+ const outp = Path.join(hub_path, "state/output.md");
32507
+ if (Fs.existsSync(inp) && Fs.existsSync(outp)) {
32508
+ if (archive_io_pair(hub_path, name) && feed_next_input(hub_path)) {
32509
+ return wake_agent(void 0);
31074
32510
  } else {
31075
- console.log("(no MCAs)");
31076
32511
  return;
31077
32512
  }
32513
+ } else if (Fs.existsSync(inp)) {
32514
+ console.log(color("36", "Agent working (input.md exists, awaiting output.md)"));
32515
+ console.log(color("36", Curry._1(Stdlib__Printf.sprintf({
32516
+ TAG: (
32517
+ /* Format */
32518
+ 0
32519
+ ),
32520
+ _0: {
32521
+ TAG: (
32522
+ /* String_literal */
32523
+ 11
32524
+ ),
32525
+ _0: "Queue depth: ",
32526
+ _1: {
32527
+ TAG: (
32528
+ /* Int */
32529
+ 4
32530
+ ),
32531
+ _0: (
32532
+ /* Int_d */
32533
+ 0
32534
+ ),
32535
+ _1: (
32536
+ /* No_padding */
32537
+ 0
32538
+ ),
32539
+ _2: (
32540
+ /* No_precision */
32541
+ 0
32542
+ ),
32543
+ _3: (
32544
+ /* End_of_format */
32545
+ 0
32546
+ )
32547
+ }
32548
+ },
32549
+ _1: "Queue depth: %d"
32550
+ }), queue_count(hub_path))));
32551
+ return;
32552
+ } else if (feed_next_input(hub_path)) {
32553
+ return wake_agent(void 0);
32554
+ } else {
32555
+ return;
31078
32556
  }
31079
- console.log("(no MCAs)");
31080
32557
  }
31081
32558
  function update_runtime(hub_path) {
31082
32559
  const runtime_path = Path.join(hub_path, "state/runtime.md");
@@ -32783,7 +34260,7 @@ if (cmd !== void 0) {
32783
34260
  break;
32784
34261
  case /* Process */
32785
34262
  7:
32786
- run_process(hub_path$1);
34263
+ run_process(hub_path$1, name);
32787
34264
  break;
32788
34265
  }
32789
34266
  } else {
@@ -32949,6 +34426,7 @@ if (cmd !== void 0) {
32949
34426
  process.exit(1);
32950
34427
  }
32951
34428
  var info = cyan;
34429
+ var mca_review_interval = 5;
32952
34430
  module.exports = {
32953
34431
  Process,
32954
34432
  Fs: Fs$1,
@@ -33006,17 +34484,24 @@ module.exports = {
33006
34484
  logs_input_dir,
33007
34485
  logs_output_dir,
33008
34486
  get_file_id,
34487
+ mca_dir,
34488
+ execute_op,
33009
34489
  archive_io_pair,
33010
34490
  queue_inbox_items,
33011
34491
  feed_next_input,
33012
34492
  wake_agent,
33013
- run_process,
33014
34493
  run_sync,
33015
34494
  run_queue_list,
33016
34495
  run_queue_clear,
33017
- mca_dir,
33018
34496
  run_mca_add,
33019
34497
  run_mca_list,
34498
+ mca_cycle_path,
34499
+ mca_review_interval,
34500
+ get_mca_cycle,
34501
+ increment_mca_cycle,
34502
+ mca_count,
34503
+ queue_mca_review,
34504
+ run_process,
33020
34505
  update_runtime,
33021
34506
  run_init,
33022
34507
  format_peers_md,