cnagent 2.2.5 → 2.2.7

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 +4 -1
  2. package/tools/dist/cn.js +216 -127
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cnagent",
3
- "version": "2.2.5",
3
+ "version": "2.2.7",
4
4
  "description": "Coherent Network agent CLI — everything runs through cn",
5
5
  "keywords": [
6
6
  "cn-agent",
@@ -35,5 +35,8 @@
35
35
  "license": "Apache-2.0",
36
36
  "engines": {
37
37
  "node": ">=18"
38
+ },
39
+ "dependencies": {
40
+ "yaml": "^2.8.2"
38
41
  }
39
42
  }
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.5";
13601
+ var version = "2.2.7";
13602
13602
  module2.exports = {
13603
13603
  starts_with,
13604
13604
  strip_prefix,
@@ -26292,6 +26292,7 @@ var Fs$1 = {
26292
26292
  ensure_dir
26293
26293
  };
26294
26294
  var Path$1 = {};
26295
+ var Yaml = {};
26295
26296
  function exec_in(cwd, cmd2) {
26296
26297
  let result;
26297
26298
  try {
@@ -26428,9 +26429,10 @@ function find_hub_path(_dir) {
26428
26429
  if (dir === "/") {
26429
26430
  return;
26430
26431
  }
26431
- const has_config = Fs.existsSync(Path.join(dir, ".cn/config.json"));
26432
+ const has_yaml = Fs.existsSync(Path.join(dir, ".cn/config.yaml"));
26433
+ const has_json = Fs.existsSync(Path.join(dir, ".cn/config.json"));
26432
26434
  const has_peers = Fs.existsSync(Path.join(dir, "state/peers.md"));
26433
- if (has_config || has_peers) {
26435
+ if (has_yaml || has_json || has_peers) {
26434
26436
  return dir;
26435
26437
  }
26436
26438
  _dir = Path.dirname(dir);
@@ -26697,6 +26699,78 @@ function inbox_check(hub_path, name) {
26697
26699
  return;
26698
26700
  }
26699
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
+ }
26700
26774
  function materialize_branch(hub_path, inbox_dir, peer_name, branch) {
26701
26775
  const diff_cmd = Curry._2(Stdlib__Printf.sprintf({
26702
26776
  TAG: (
@@ -26750,18 +26824,40 @@ function materialize_branch(hub_path, inbox_dir, peer_name, branch) {
26750
26824
  },
26751
26825
  _1: "git diff main...origin/%s --name-only 2>/dev/null || git diff master...origin/%s --name-only"
26752
26826
  }), branch, branch);
26753
- return Stdlib__List.filter_map((function(file) {
26754
- 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 match2 = Stdlib__List.rev(Stdlib__String.split_on_char(
26833
+ /* '/' */
26834
+ 47,
26835
+ branch
26836
+ ));
26837
+ const branch_slug = match2 ? match2.hd : branch;
26838
+ const inbox_file = Curry._2(Stdlib__Printf.sprintf({
26839
+ TAG: (
26840
+ /* Format */
26841
+ 0
26842
+ ),
26843
+ _0: {
26755
26844
  TAG: (
26756
- /* Format */
26845
+ /* String */
26846
+ 2
26847
+ ),
26848
+ _0: (
26849
+ /* No_padding */
26757
26850
  0
26758
26851
  ),
26759
- _0: {
26852
+ _1: {
26760
26853
  TAG: (
26761
- /* String_literal */
26762
- 11
26854
+ /* Char_literal */
26855
+ 12
26856
+ ),
26857
+ _0: (
26858
+ /* '-' */
26859
+ 45
26763
26860
  ),
26764
- _0: "git show origin/",
26765
26861
  _1: {
26766
26862
  TAG: (
26767
26863
  /* String */
@@ -26773,65 +26869,41 @@ function materialize_branch(hub_path, inbox_dir, peer_name, branch) {
26773
26869
  ),
26774
26870
  _1: {
26775
26871
  TAG: (
26776
- /* Char_literal */
26777
- 12
26778
- ),
26779
- _0: (
26780
- /* ':' */
26781
- 58
26872
+ /* String_literal */
26873
+ 11
26782
26874
  ),
26783
- _1: {
26784
- TAG: (
26785
- /* String */
26786
- 2
26787
- ),
26788
- _0: (
26789
- /* No_padding */
26790
- 0
26791
- ),
26792
- _1: (
26793
- /* End_of_format */
26794
- 0
26795
- )
26796
- }
26875
+ _0: ".md",
26876
+ _1: (
26877
+ /* End_of_format */
26878
+ 0
26879
+ )
26797
26880
  }
26798
26881
  }
26799
- },
26800
- _1: "git show origin/%s:%s"
26801
- }), branch, file);
26802
- const content = exec_in(hub_path, show_cmd);
26803
- if (content === void 0) {
26804
- return;
26805
- }
26806
- const match2 = Stdlib__List.rev(Stdlib__String.split_on_char(
26807
- /* '/' */
26808
- 47,
26809
- branch
26810
- ));
26811
- const branch_slug = match2 ? match2.hd : branch;
26812
- const inbox_file = Curry._2(Stdlib__Printf.sprintf({
26813
- TAG: (
26814
- /* Format */
26815
- 0
26816
- ),
26817
- _0: {
26882
+ }
26883
+ },
26884
+ _1: "%s-%s.md"
26885
+ }), peer_name, branch_slug);
26886
+ const inbox_path = Path.join(inbox_dir, inbox_file);
26887
+ const archived_path = Path.join(Path.join(inbox_dir, "_archived"), inbox_file);
26888
+ if (Fs.existsSync(inbox_path) || Fs.existsSync(archived_path)) {
26889
+ delete_remote_branch(hub_path, branch);
26890
+ return (
26891
+ /* [] */
26892
+ 0
26893
+ );
26894
+ } else {
26895
+ return Stdlib__List.filter_map((function(file) {
26896
+ const show_cmd = Curry._2(Stdlib__Printf.sprintf({
26818
26897
  TAG: (
26819
- /* String */
26820
- 2
26821
- ),
26822
- _0: (
26823
- /* No_padding */
26898
+ /* Format */
26824
26899
  0
26825
26900
  ),
26826
- _1: {
26901
+ _0: {
26827
26902
  TAG: (
26828
- /* Char_literal */
26829
- 12
26830
- ),
26831
- _0: (
26832
- /* '-' */
26833
- 45
26903
+ /* String_literal */
26904
+ 11
26834
26905
  ),
26906
+ _0: "git show origin/",
26835
26907
  _1: {
26836
26908
  TAG: (
26837
26909
  /* String */
@@ -26843,64 +26915,73 @@ function materialize_branch(hub_path, inbox_dir, peer_name, branch) {
26843
26915
  ),
26844
26916
  _1: {
26845
26917
  TAG: (
26846
- /* String_literal */
26847
- 11
26918
+ /* Char_literal */
26919
+ 12
26848
26920
  ),
26849
- _0: ".md",
26850
- _1: (
26851
- /* End_of_format */
26852
- 0
26853
- )
26921
+ _0: (
26922
+ /* ':' */
26923
+ 58
26924
+ ),
26925
+ _1: {
26926
+ TAG: (
26927
+ /* String */
26928
+ 2
26929
+ ),
26930
+ _0: (
26931
+ /* No_padding */
26932
+ 0
26933
+ ),
26934
+ _1: (
26935
+ /* End_of_format */
26936
+ 0
26937
+ )
26938
+ }
26854
26939
  }
26855
26940
  }
26856
- }
26857
- },
26858
- _1: "%s-%s.md"
26859
- }), peer_name, branch_slug);
26860
- const inbox_path = Path.join(inbox_dir, inbox_file);
26861
- const archived_path = Path.join(Path.join(inbox_dir, "_archived"), inbox_file);
26862
- if (Fs.existsSync(inbox_path) || Fs.existsSync(archived_path)) {
26863
- return;
26864
- }
26865
- const meta_0 = [
26866
- "from",
26867
- peer_name
26868
- ];
26869
- const meta_1 = {
26870
- hd: [
26871
- "branch",
26872
- branch
26873
- ],
26874
- tl: {
26941
+ },
26942
+ _1: "git show origin/%s:%s"
26943
+ }), branch, file);
26944
+ const content = exec_in(hub_path, show_cmd);
26945
+ if (content === void 0) {
26946
+ return;
26947
+ }
26948
+ const meta_0 = [
26949
+ "from",
26950
+ peer_name
26951
+ ];
26952
+ const meta_1 = {
26875
26953
  hd: [
26876
- "file",
26877
- file
26954
+ "branch",
26955
+ branch
26878
26956
  ],
26879
26957
  tl: {
26880
26958
  hd: [
26881
- "received",
26882
- (/* @__PURE__ */ new Date()).toISOString()
26959
+ "file",
26960
+ file
26883
26961
  ],
26884
- tl: (
26885
- /* [] */
26886
- 0
26887
- )
26962
+ tl: {
26963
+ hd: [
26964
+ "received",
26965
+ (/* @__PURE__ */ new Date()).toISOString()
26966
+ ],
26967
+ tl: (
26968
+ /* [] */
26969
+ 0
26970
+ )
26971
+ }
26888
26972
  }
26889
- }
26890
- };
26891
- const meta = {
26892
- hd: meta_0,
26893
- tl: meta_1
26894
- };
26895
- const prim1 = Cn_lib.update_frontmatter(content, meta);
26896
- Fs.writeFileSync(inbox_path, prim1);
26897
- log_action(hub_path, "inbox.materialize", inbox_file);
26898
- return inbox_file;
26899
- }), Stdlib__List.filter(is_md_file, Stdlib__Option.value(
26900
- Stdlib__Option.map(split_lines, exec_in(hub_path, diff_cmd)),
26901
- /* [] */
26902
- 0
26903
- )));
26973
+ };
26974
+ const meta = {
26975
+ hd: meta_0,
26976
+ tl: meta_1
26977
+ };
26978
+ const prim1 = Cn_lib.update_frontmatter(content, meta);
26979
+ Fs.writeFileSync(inbox_path, prim1);
26980
+ log_action(hub_path, "inbox.materialize", inbox_file);
26981
+ delete_remote_branch(hub_path, branch);
26982
+ return inbox_file;
26983
+ }), files);
26984
+ }
26904
26985
  }
26905
26986
  function inbox_process(hub_path) {
26906
26987
  console.log(color("36", "Processing inbox..."));
@@ -29708,14 +29789,17 @@ function run_doctor(hub_path) {
29708
29789
  const v = exec("git --version");
29709
29790
  const v$1 = exec("git config user.name");
29710
29791
  const v$2 = exec("git config user.email");
29711
- const p = Path.join(hub_path, ".cn/config.json");
29712
- const p$1 = Path.join(hub_path, "spec/SOUL.md");
29713
- const p$2 = Path.join(hub_path, "state/peers.md");
29792
+ const yaml_path = Path.join(hub_path, ".cn/config.yaml");
29793
+ const json_path = Path.join(hub_path, ".cn/config.json");
29794
+ const has_yaml = Fs.existsSync(yaml_path);
29795
+ const has_json = Fs.existsSync(json_path);
29796
+ const p = Path.join(hub_path, "spec/SOUL.md");
29797
+ const p$1 = Path.join(hub_path, "state/peers.md");
29714
29798
  let tmp;
29715
- if (Fs.existsSync(p$2)) {
29799
+ if (Fs.existsSync(p$1)) {
29716
29800
  const count = Stdlib__Option.value(Stdlib__Option.map((function(prim) {
29717
29801
  return prim.length;
29718
- }), Caml_option.null_to_opt(Fs.readFileSync(p$2, "utf8").match(/- name:/g))), 0);
29802
+ }), Caml_option.null_to_opt(Fs.readFileSync(p$1, "utf8").match(/- name:/g))), 0);
29719
29803
  tmp = {
29720
29804
  name: "state/peers.md",
29721
29805
  passed: true,
@@ -29801,15 +29885,15 @@ function run_doctor(hub_path) {
29801
29885
  },
29802
29886
  tl: {
29803
29887
  hd: {
29804
- name: ".cn/config.json",
29805
- passed: Fs.existsSync(p),
29806
- value: Fs.existsSync(p) ? "exists" : "missing"
29888
+ name: ".cn/config",
29889
+ passed: has_yaml || has_json,
29890
+ value: has_yaml ? "config.yaml" : has_json ? "config.json (migrate to .yaml)" : "missing"
29807
29891
  },
29808
29892
  tl: {
29809
29893
  hd: {
29810
29894
  name: "spec/SOUL.md",
29811
- passed: Fs.existsSync(p$1),
29812
- value: Fs.existsSync(p$1) ? "exists" : "missing (optional)"
29895
+ passed: Fs.existsSync(p),
29896
+ value: Fs.existsSync(p) ? "exists" : "missing (optional)"
29813
29897
  },
29814
29898
  tl: {
29815
29899
  hd: tmp,
@@ -34608,7 +34692,7 @@ function run_init(name) {
34608
34692
  /* String_literal */
34609
34693
  11
34610
34694
  ),
34611
- _0: '{\n "name": "',
34695
+ _0: "name: ",
34612
34696
  _1: {
34613
34697
  TAG: (
34614
34698
  /* String */
@@ -34623,7 +34707,7 @@ function run_init(name) {
34623
34707
  /* String_literal */
34624
34708
  11
34625
34709
  ),
34626
- _0: '",\n "version": "1.0.0",\n "created": "',
34710
+ _0: "\nversion: 1.0.0\ncreated: ",
34627
34711
  _1: {
34628
34712
  TAG: (
34629
34713
  /* String */
@@ -34635,10 +34719,13 @@ function run_init(name) {
34635
34719
  ),
34636
34720
  _1: {
34637
34721
  TAG: (
34638
- /* String_literal */
34639
- 11
34722
+ /* Char_literal */
34723
+ 12
34724
+ ),
34725
+ _0: (
34726
+ /* '\n' */
34727
+ 10
34640
34728
  ),
34641
- _0: '"\n}',
34642
34729
  _1: (
34643
34730
  /* End_of_format */
34644
34731
  0
@@ -34648,9 +34735,9 @@ function run_init(name) {
34648
34735
  }
34649
34736
  }
34650
34737
  },
34651
- _1: '{\n "name": "%s",\n "version": "1.0.0",\n "created": "%s"\n}'
34738
+ _1: "name: %s\nversion: 1.0.0\ncreated: %s\n"
34652
34739
  }), hub_name, (/* @__PURE__ */ new Date()).toISOString());
34653
- const prim0 = Path.join(hub_dir, ".cn/config.json");
34740
+ const prim0 = Path.join(hub_dir, ".cn/config.yaml");
34654
34741
  Fs.writeFileSync(prim0, config);
34655
34742
  const soul = Curry._3(Stdlib__Printf.sprintf({
34656
34743
  TAG: (
@@ -36207,6 +36294,7 @@ module.exports = {
36207
36294
  Process,
36208
36295
  Fs: Fs$1,
36209
36296
  Path: Path$1,
36297
+ Yaml,
36210
36298
  Child_process: Child_process$1,
36211
36299
  Json,
36212
36300
  now_iso,
@@ -36228,6 +36316,7 @@ module.exports = {
36228
36316
  split_lines,
36229
36317
  get_peer_branches,
36230
36318
  inbox_check,
36319
+ delete_remote_branch,
36231
36320
  materialize_branch,
36232
36321
  inbox_process,
36233
36322
  outbox_check,