seatmesh 1.0.5 → 1.0.6

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/bin/seatmesh +140 -0
  2. package/package.json +8 -7
package/bin/seatmesh ADDED
@@ -0,0 +1,140 @@
1
+ #!/usr/bin/env bash
2
+ # seatmesh CLI shim — blazing live attach (tmux-zsign style), else Node CLI.
3
+ set -euo pipefail
4
+
5
+ SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")"
6
+ HERE="$(cd "$(dirname "$SCRIPT")" && pwd)"
7
+
8
+ # npm: …/node_modules/seatmesh/bin/seatmesh → ../dist/main.js
9
+ # monorepo: repo/bin/seatmesh → packages/cli/dist/main.js
10
+ if [[ -f "$HERE/../dist/main.js" ]]; then
11
+ CLI="$HERE/../dist/main.js"
12
+ PKG_ROOT="$(cd "$HERE/.." && pwd)"
13
+ elif [[ -f "$HERE/../packages/cli/dist/main.js" ]]; then
14
+ CLI="$HERE/../packages/cli/dist/main.js"
15
+ PKG_ROOT="$(cd "$HERE/.." && pwd)"
16
+ elif [[ -f "$HERE/main.js" ]]; then
17
+ CLI="$HERE/main.js"
18
+ PKG_ROOT="$(cd "$HERE/.." && pwd)"
19
+ else
20
+ echo "seatmesh: cannot find dist/main.js (from $HERE)" >&2
21
+ exit 1
22
+ fi
23
+
24
+ PROFILE=""
25
+ ARGS=()
26
+ prev=""
27
+ for a in "$@"; do
28
+ if [[ "$prev" == "--profile" ]]; then
29
+ PROFILE="$a"
30
+ prev=""
31
+ continue
32
+ fi
33
+ if [[ "$a" == "--profile" ]]; then
34
+ prev="$a"
35
+ continue
36
+ fi
37
+ if [[ "$a" == --profile=* ]]; then
38
+ PROFILE="${a#--profile=}"
39
+ continue
40
+ fi
41
+ ARGS+=("$a")
42
+ done
43
+ [[ -n "$prev" ]] && ARGS+=("$prev")
44
+
45
+ find_sm_dir() {
46
+ local d
47
+ d="$(pwd)"
48
+ while [[ -n "$d" && "$d" != "/" ]]; do
49
+ if [[ -f "$d/.sm/mesh.config.yaml" || -f "$d/.sm/mesh-agents.json" ]]; then
50
+ echo "$d/.sm"
51
+ return 0
52
+ fi
53
+ d="$(dirname "$d")"
54
+ done
55
+ return 1
56
+ }
57
+
58
+ resolve_profile_dir() {
59
+ local p="${1:-}"
60
+ if [[ -z "$p" ]]; then
61
+ find_sm_dir || return 1
62
+ return 0
63
+ fi
64
+ if [[ -d "$p" ]]; then
65
+ (cd "$p" && pwd)
66
+ return 0
67
+ fi
68
+ if [[ -f "$p" ]]; then
69
+ (cd "$(dirname "$p")" && pwd)
70
+ return 0
71
+ fi
72
+ return 1
73
+ }
74
+
75
+ session_name_from_profile() {
76
+ local dir="$1"
77
+ local agents="$dir/mesh-agents.json"
78
+ [[ -f "$agents" ]] || return 1
79
+ local s
80
+ s="$(grep -oE '"session"[[:space:]]*:[[:space:]]*"[^"]+"' "$agents" 2>/dev/null | head -1 | sed -E 's/.*"([^"]+)"/\1/')"
81
+ [[ -n "$s" ]] || return 1
82
+ echo "$s"
83
+ }
84
+
85
+ is_attach_cmd() {
86
+ local a0="${ARGS[0]:-}"
87
+ local a1="${ARGS[1]:-}"
88
+ [[ "$a0" == "session" && ( "$a1" == "attach" || -z "$a1" ) ]] && return 0
89
+ [[ "$a0" == "attach" ]] && return 0
90
+ return 1
91
+ }
92
+
93
+ lazy_attach() {
94
+ local prof_dir session
95
+ prof_dir="$(resolve_profile_dir "$PROFILE")" || return 1
96
+ session="$(session_name_from_profile "$prof_dir")" || return 1
97
+ tmux has-session -t "$session" 2>/dev/null || return 1
98
+
99
+ (
100
+ SEATMESH_SKIP_VERSION_CHECK=1 \
101
+ node "$CLI" --profile "$prof_dir" session sync \
102
+ >/dev/null 2>&1 || true
103
+ ) &
104
+ disown 2>/dev/null || true
105
+
106
+ if [[ -n "${TMUX:-}" ]]; then
107
+ local cur
108
+ cur="$(tmux display-message -p '#{session_name}' 2>/dev/null || true)"
109
+ if [[ "$cur" == "$session" ]]; then
110
+ echo "already inside session '$session'"
111
+ exit 0
112
+ fi
113
+ exec tmux switch-client -t "$session"
114
+ fi
115
+ exec tmux attach-session -t "$session"
116
+ }
117
+
118
+ if is_attach_cmd; then
119
+ lazy_attach && exit 0
120
+ fi
121
+
122
+ # Monorepo cold start
123
+ if [[ -f "$PKG_ROOT/package.json" && -d "$PKG_ROOT/packages/cli" ]]; then
124
+ needs=0
125
+ [[ -f "$CLI" ]] || needs=1
126
+ [[ -d "$PKG_ROOT/node_modules" ]] || needs=1
127
+ if [[ -f "$PKG_ROOT/package.json" && -f "$CLI" && "$PKG_ROOT/package.json" -nt "$CLI" ]]; then
128
+ needs=1
129
+ fi
130
+ if [[ "$needs" -eq 1 ]]; then
131
+ command -v npm >/dev/null 2>&1 || {
132
+ echo "seatmesh: npm not found" >&2
133
+ exit 1
134
+ }
135
+ echo "seatmesh: cold start — npm install + build in $PKG_ROOT ..." >&2
136
+ (cd "$PKG_ROOT" && npm install && npm run build)
137
+ fi
138
+ fi
139
+
140
+ exec node "$CLI" "$@"
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "seatmesh",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "engines": {
5
5
  "node": ">=22"
6
6
  },
7
7
  "type": "module",
8
8
  "files": [
9
+ "bin",
9
10
  "dist",
10
11
  "profiles",
11
12
  "templates"
12
13
  ],
13
14
  "bin": {
14
- "seatmesh": "dist/main.js"
15
+ "seatmesh": "bin/seatmesh"
15
16
  },
16
17
  "publishConfig": {
17
18
  "access": "public"
@@ -24,11 +25,11 @@
24
25
  },
25
26
  "dependencies": {
26
27
  "@clack/prompts": "^1.8.0",
27
- "@seat-mesh/connectivity": "1.0.5",
28
- "@seat-mesh/core": "1.0.5",
29
- "@seat-mesh/daemon": "1.0.5",
30
- "@seat-mesh/providers": "1.0.5",
31
- "@seat-mesh/tmux": "1.0.5",
28
+ "@seat-mesh/connectivity": "1.0.6",
29
+ "@seat-mesh/core": "1.0.6",
30
+ "@seat-mesh/daemon": "1.0.6",
31
+ "@seat-mesh/providers": "1.0.6",
32
+ "@seat-mesh/tmux": "1.0.6",
32
33
  "boxen": "^8.0.1",
33
34
  "cfonts": "^3.3.1",
34
35
  "commander": "^15.0.0"