cnagent 2.2.16 → 2.2.18

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.
package/bin/cn-cron ADDED
@@ -0,0 +1,12 @@
1
+ #!/bin/sh
2
+ # cn-cron - Run cn sync cycle with logging
3
+ # Installed by: npm install -g cnagent
4
+ # Usage: */5 * * * * cn-cron /path/to/hub
5
+
6
+ set -e
7
+
8
+ HUB="${1:-$(pwd)}"
9
+ LOG="/var/log/cn-$(date +%Y%m%d).log"
10
+
11
+ cd "$HUB"
12
+ exec cn sync >> "$LOG" 2>&1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cnagent",
3
- "version": "2.2.16",
3
+ "version": "2.2.18",
4
4
  "description": "Coherent Network agent CLI — everything runs through cn",
5
5
  "keywords": [
6
6
  "cn-agent",
@@ -18,7 +18,8 @@
18
18
  "url": "https://github.com/usurobor/cn-agent.git"
19
19
  },
20
20
  "bin": {
21
- "cn": "bin/cn"
21
+ "cn": "bin/cn",
22
+ "cn-cron": "bin/cn-cron"
22
23
  },
23
24
  "files": [
24
25
  "bin/",
package/tools/dist/cn.js CHANGED
@@ -12160,6 +12160,9 @@ var require_cn_lib = __commonJS({
12160
12160
  case /* Weekly */
12161
12161
  10:
12162
12162
  return "weekly";
12163
+ case /* Setup */
12164
+ 11:
12165
+ return "setup";
12163
12166
  }
12164
12167
  } else {
12165
12168
  switch (t.TAG) {
@@ -13182,6 +13185,15 @@ var require_cn_lib = __commonJS({
13182
13185
  }
13183
13186
  exit = 3;
13184
13187
  break;
13188
+ case "setup":
13189
+ if (param.tl) {
13190
+ return;
13191
+ } else {
13192
+ return (
13193
+ /* Setup */
13194
+ 11
13195
+ );
13196
+ }
13185
13197
  case "status":
13186
13198
  if (param.tl) {
13187
13199
  return;
@@ -13654,8 +13666,8 @@ var require_cn_lib = __commonJS({
13654
13666
  10
13655
13667
  );
13656
13668
  }
13657
- 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 # Thread creation\n adhoc <title> Create adhoc thread\n daily Create/show daily reflection\n weekly Create/show weekly reflection\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";
13658
- var version = "2.2.16";
13669
+ 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 # Thread creation\n adhoc <title> Create adhoc thread\n daily Create/show daily reflection\n weekly Create/show weekly reflection\n \n # Hub management\n init [name] Create new hub\n setup System setup (logrotate + cron) \xE2\x80\x94 run with sudo\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";
13670
+ var version = "2.2.18";
13659
13671
  module2.exports = {
13660
13672
  starts_with,
13661
13673
  strip_prefix,
@@ -37646,7 +37658,44 @@ function inbox_flush(hub_path, _name) {
37646
37658
  }
37647
37659
  console.log(ok("Inbox empty"));
37648
37660
  }
37649
- function update_cron(hub_path) {
37661
+ function run_setup(hub_path) {
37662
+ const s = exec("id -u");
37663
+ const uid = s !== void 0 ? Stdlib__String.trim(s) : "unknown";
37664
+ if (uid !== "0") {
37665
+ console.log(fail("Setup requires root. Run: sudo cn setup"));
37666
+ process.exit(1);
37667
+ }
37668
+ console.log(color("36", "Setting up cn system components..."));
37669
+ const logrotate_path = "/etc/logrotate.d/cn";
37670
+ Fs.writeFileSync(logrotate_path, "/var/log/cn-*.log {\n daily\n rotate 7\n compress\n missingok\n notifempty\n}\n");
37671
+ console.log(ok(Curry._1(Stdlib__Printf.sprintf({
37672
+ TAG: (
37673
+ /* Format */
37674
+ 0
37675
+ ),
37676
+ _0: {
37677
+ TAG: (
37678
+ /* String_literal */
37679
+ 11
37680
+ ),
37681
+ _0: "Created ",
37682
+ _1: {
37683
+ TAG: (
37684
+ /* String */
37685
+ 2
37686
+ ),
37687
+ _0: (
37688
+ /* No_padding */
37689
+ 0
37690
+ ),
37691
+ _1: (
37692
+ /* End_of_format */
37693
+ 0
37694
+ )
37695
+ }
37696
+ },
37697
+ _1: "Created %s"
37698
+ }), logrotate_path)));
37650
37699
  const cron_line = Curry._1(Stdlib__Printf.sprintf({
37651
37700
  TAG: (
37652
37701
  /* Format */
@@ -37657,7 +37706,35 @@ function update_cron(hub_path) {
37657
37706
  /* String_literal */
37658
37707
  11
37659
37708
  ),
37660
- _0: "*/5 * * * * cd ",
37709
+ _0: "*/5 * * * * cn-cron ",
37710
+ _1: {
37711
+ TAG: (
37712
+ /* String */
37713
+ 2
37714
+ ),
37715
+ _0: (
37716
+ /* No_padding */
37717
+ 0
37718
+ ),
37719
+ _1: (
37720
+ /* End_of_format */
37721
+ 0
37722
+ )
37723
+ }
37724
+ },
37725
+ _1: "*/5 * * * * cn-cron %s"
37726
+ }), hub_path);
37727
+ const cmd2 = Curry._1(Stdlib__Printf.sprintf({
37728
+ TAG: (
37729
+ /* Format */
37730
+ 0
37731
+ ),
37732
+ _0: {
37733
+ TAG: (
37734
+ /* String_literal */
37735
+ 11
37736
+ ),
37737
+ _0: "echo '",
37661
37738
  _1: {
37662
37739
  TAG: (
37663
37740
  /* String */
@@ -37672,66 +37749,113 @@ function update_cron(hub_path) {
37672
37749
  /* String_literal */
37673
37750
  11
37674
37751
  ),
37675
- _0: " && cn sync && cn process >> /var/log/cn-$(date +\\",
37676
- _1: {
37677
- TAG: (
37678
- /* Char_literal */
37679
- 12
37680
- ),
37681
- _0: (
37682
- /* '%' */
37683
- 37
37684
- ),
37685
- _1: {
37686
- TAG: (
37687
- /* String_literal */
37688
- 11
37689
- ),
37690
- _0: "Y\\",
37691
- _1: {
37692
- TAG: (
37693
- /* Char_literal */
37694
- 12
37695
- ),
37696
- _0: (
37697
- /* '%' */
37698
- 37
37699
- ),
37700
- _1: {
37701
- TAG: (
37702
- /* String_literal */
37703
- 11
37704
- ),
37705
- _0: "m\\",
37706
- _1: {
37707
- TAG: (
37708
- /* Char_literal */
37709
- 12
37710
- ),
37711
- _0: (
37712
- /* '%' */
37713
- 37
37714
- ),
37715
- _1: {
37716
- TAG: (
37717
- /* String_literal */
37718
- 11
37719
- ),
37720
- _0: "d).log 2>&1",
37721
- _1: (
37722
- /* End_of_format */
37723
- 0
37724
- )
37725
- }
37726
- }
37727
- }
37728
- }
37729
- }
37730
- }
37752
+ _0: "' | crontab -",
37753
+ _1: (
37754
+ /* End_of_format */
37755
+ 0
37756
+ )
37731
37757
  }
37732
37758
  }
37733
37759
  },
37734
- _1: "*/5 * * * * cd %s && cn sync && cn process >> /var/log/cn-$(date +\\%%Y\\%%m\\%%d).log 2>&1"
37760
+ _1: "echo '%s' | crontab -"
37761
+ }), cron_line);
37762
+ const match2 = exec(cmd2);
37763
+ if (match2 !== void 0) {
37764
+ console.log(ok("Crontab configured"));
37765
+ } else {
37766
+ console.log(warn("Crontab update failed - configure manually"));
37767
+ }
37768
+ console.log("");
37769
+ console.log(ok("Setup complete!"));
37770
+ console.log("");
37771
+ console.log("Configured:");
37772
+ console.log(Curry._1(Stdlib__Printf.sprintf({
37773
+ TAG: (
37774
+ /* Format */
37775
+ 0
37776
+ ),
37777
+ _0: {
37778
+ TAG: (
37779
+ /* String_literal */
37780
+ 11
37781
+ ),
37782
+ _0: " \xE2\x80\xA2 Logrotate: ",
37783
+ _1: {
37784
+ TAG: (
37785
+ /* String */
37786
+ 2
37787
+ ),
37788
+ _0: (
37789
+ /* No_padding */
37790
+ 0
37791
+ ),
37792
+ _1: (
37793
+ /* End_of_format */
37794
+ 0
37795
+ )
37796
+ }
37797
+ },
37798
+ _1: " \xE2\x80\xA2 Logrotate: %s"
37799
+ }), logrotate_path));
37800
+ console.log(Curry._1(Stdlib__Printf.sprintf({
37801
+ TAG: (
37802
+ /* Format */
37803
+ 0
37804
+ ),
37805
+ _0: {
37806
+ TAG: (
37807
+ /* String_literal */
37808
+ 11
37809
+ ),
37810
+ _0: " \xE2\x80\xA2 Cron: */5 * * * * cn-cron ",
37811
+ _1: {
37812
+ TAG: (
37813
+ /* String */
37814
+ 2
37815
+ ),
37816
+ _0: (
37817
+ /* No_padding */
37818
+ 0
37819
+ ),
37820
+ _1: (
37821
+ /* End_of_format */
37822
+ 0
37823
+ )
37824
+ }
37825
+ },
37826
+ _1: " \xE2\x80\xA2 Cron: */5 * * * * cn-cron %s"
37827
+ }), hub_path));
37828
+ console.log("");
37829
+ console.log("Logs will be written to: /var/log/cn-YYYYMMDD.log");
37830
+ }
37831
+ function update_cron(hub_path) {
37832
+ const cron_line = Curry._1(Stdlib__Printf.sprintf({
37833
+ TAG: (
37834
+ /* Format */
37835
+ 0
37836
+ ),
37837
+ _0: {
37838
+ TAG: (
37839
+ /* String_literal */
37840
+ 11
37841
+ ),
37842
+ _0: "*/5 * * * * cn-cron ",
37843
+ _1: {
37844
+ TAG: (
37845
+ /* String */
37846
+ 2
37847
+ ),
37848
+ _0: (
37849
+ /* No_padding */
37850
+ 0
37851
+ ),
37852
+ _1: (
37853
+ /* End_of_format */
37854
+ 0
37855
+ )
37856
+ }
37857
+ },
37858
+ _1: "*/5 * * * * cn-cron %s"
37735
37859
  }), hub_path);
37736
37860
  console.log(color("36", "Updating crontab (5 min intervals)..."));
37737
37861
  const cmd2 = Curry._1(Stdlib__Printf.sprintf({
@@ -38183,6 +38307,10 @@ if (cmd !== void 0) {
38183
38307
  10:
38184
38308
  run_weekly(hub_path$1);
38185
38309
  break;
38310
+ case /* Setup */
38311
+ 11:
38312
+ run_setup(hub_path$1);
38313
+ break;
38186
38314
  }
38187
38315
  } else {
38188
38316
  switch (cmd.TAG) {
@@ -38467,6 +38595,7 @@ module.exports = {
38467
38595
  run_peer_remove,
38468
38596
  run_peer_sync,
38469
38597
  inbox_flush,
38598
+ run_setup,
38470
38599
  update_cron,
38471
38600
  run_update,
38472
38601
  run_update_with_cron,