@liustack/modlens 3.0.0 → 3.1.0
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/CHANGELOG.md +9 -1
- package/README.md +18 -123
- package/README.zh-CN.md +38 -143
- package/dist/main.js +14 -11
- package/docs/harness-setup.md +6 -0
- package/docs/troubleshooting.md +9 -1
- package/package.json +15 -13
- package/skills/modlens/SKILL.md +23 -8
- package/skills/modlens/references/cli.md +77 -0
- package/skills/modlens/references/configure.md +34 -0
- package/skills/modlens/references/runtime.md +95 -0
- package/skills/modlens/scripts/run.ps1 +250 -0
- package/skills/modlens/scripts/run.sh +283 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# modlens skill launcher (macOS / Linux).
|
|
3
|
+
#
|
|
4
|
+
# One stable action for the agent ("run modlens"); this script picks a working
|
|
5
|
+
# way to run it in the current environment. Written to POSIX sh so it runs under
|
|
6
|
+
# dash, busybox ash, and bash alike. Invoke it with `bash run.sh ...` (or plain
|
|
7
|
+
# `sh run.sh ...`) so a lost execute bit after a file copy never matters.
|
|
8
|
+
#
|
|
9
|
+
# Resolution order (kept identical in run.ps1):
|
|
10
|
+
# 1. A compatible modlens already on PATH -> run it directly.
|
|
11
|
+
# 2. npx present -> run the pinned npm version.
|
|
12
|
+
# 3. bunx present -> run the pinned version via Bun.
|
|
13
|
+
# 4. (phase B placeholder) a native artifact -> not published yet.
|
|
14
|
+
# 5. Nothing usable -> structured diagnosis, exit 78.
|
|
15
|
+
#
|
|
16
|
+
# It never writes PATH, never needs admin rights, never fetches a second script,
|
|
17
|
+
# and has no postinstall step.
|
|
18
|
+
set -eu
|
|
19
|
+
|
|
20
|
+
# --- Version constants: stamped by scripts/release.mjs at release time. --------
|
|
21
|
+
# Do not edit PINNED by hand; scripts/stamp.test.mjs asserts it equals the
|
|
22
|
+
# package.json version, and the release script rewrites it on every bump.
|
|
23
|
+
PKG="@liustack/modlens"
|
|
24
|
+
BIN="modlens"
|
|
25
|
+
PINNED="3.1.0"
|
|
26
|
+
# -------------------------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
NATIVE_NOTE="no native artifact is published for this tool yet; phase A ships npm launch paths only"
|
|
29
|
+
|
|
30
|
+
# Split "X.Y.Z" (extra suffix ignored) into the globals _MAJ, _MIN, _PAT.
|
|
31
|
+
# Any non-numeric component becomes 0 so integer tests below never abort.
|
|
32
|
+
parse_semver() {
|
|
33
|
+
_raw="$1"
|
|
34
|
+
_MAJ="${_raw%%.*}"
|
|
35
|
+
_rest="${_raw#*.}"
|
|
36
|
+
if [ "$_rest" = "$_raw" ]; then
|
|
37
|
+
_MIN=0
|
|
38
|
+
_PAT=0
|
|
39
|
+
else
|
|
40
|
+
_MIN="${_rest%%.*}"
|
|
41
|
+
_rest2="${_rest#*.}"
|
|
42
|
+
if [ "$_rest2" = "$_rest" ]; then _PAT=0; else _PAT="${_rest2%%.*}"; fi
|
|
43
|
+
fi
|
|
44
|
+
case "$_MAJ" in '' | *[!0-9]*) _MAJ=0 ;; esac
|
|
45
|
+
case "$_MIN" in '' | *[!0-9]*) _MIN=0 ;; esac
|
|
46
|
+
case "$_PAT" in '' | *[!0-9]*) _PAT=0 ;; esac
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
# Compatible = same major version as PINNED AND not older than PINNED.
|
|
50
|
+
# Same major keeps a globally installed CLI usable without a forced re-download;
|
|
51
|
+
# not-older refuses a stale build that predates the version this skill needs.
|
|
52
|
+
compatible() {
|
|
53
|
+
parse_semver "$1"
|
|
54
|
+
_f_maj=$_MAJ
|
|
55
|
+
_f_min=$_MIN
|
|
56
|
+
_f_pat=$_PAT
|
|
57
|
+
parse_semver "$PINNED"
|
|
58
|
+
[ "$_f_maj" = "$_MAJ" ] || return 1
|
|
59
|
+
if [ "$_f_min" -gt "$_MIN" ]; then return 0; fi
|
|
60
|
+
if [ "$_f_min" -lt "$_MIN" ]; then return 1; fi
|
|
61
|
+
[ "$_f_pat" -ge "$_PAT" ]
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# First "X.Y.Z" token printed by `$BIN --version`.
|
|
65
|
+
cli_version() {
|
|
66
|
+
"$BIN" --version 2>/dev/null | head -n 1 |
|
|
67
|
+
sed -n 's/.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/p'
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
# Echo exactly one word: the chosen launch path.
|
|
71
|
+
resolve() {
|
|
72
|
+
if command -v "$BIN" >/dev/null 2>&1; then
|
|
73
|
+
_v="$(cli_version)"
|
|
74
|
+
if [ -n "$_v" ] && compatible "$_v"; then
|
|
75
|
+
echo "path"
|
|
76
|
+
return
|
|
77
|
+
fi
|
|
78
|
+
fi
|
|
79
|
+
if command -v npx >/dev/null 2>&1; then
|
|
80
|
+
echo "npx"
|
|
81
|
+
return
|
|
82
|
+
fi
|
|
83
|
+
if command -v bunx >/dev/null 2>&1; then
|
|
84
|
+
echo "bunx"
|
|
85
|
+
return
|
|
86
|
+
fi
|
|
87
|
+
# Phase B goes here: check a versioned user cache, then download and verify a
|
|
88
|
+
# native artifact into it. Any such download must use curl (never a piped
|
|
89
|
+
# second script), which does not stamp quarantine / Mark-of-the-Web the way a
|
|
90
|
+
# browser does, matching design.md 8.3.
|
|
91
|
+
echo "none"
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
# Run the resolved CLI without exec, so its output can be captured (used to
|
|
95
|
+
# chain the CLI's own doctor). Passes every argument through untouched.
|
|
96
|
+
run_cli() {
|
|
97
|
+
case "$G_SEL" in
|
|
98
|
+
path) "$BIN" "$@" ;;
|
|
99
|
+
npx) npx --yes --package "$PKG@$PINNED" "$BIN" "$@" ;;
|
|
100
|
+
bunx) bunx --bun "$PKG@$PINNED" "$@" ;;
|
|
101
|
+
esac
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
detect_os() { uname -s 2>/dev/null | tr '[:upper:]' '[:lower:]'; }
|
|
105
|
+
|
|
106
|
+
detect_arch() {
|
|
107
|
+
_a="$(uname -m 2>/dev/null)"
|
|
108
|
+
case "$_a" in
|
|
109
|
+
x86_64 | amd64) echo "x64" ;;
|
|
110
|
+
aarch64 | arm64) echo "arm64" ;;
|
|
111
|
+
*) echo "$_a" ;;
|
|
112
|
+
esac
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
# Escape a value for a JSON string literal (backslash and double quote).
|
|
116
|
+
json_escape() { printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'; }
|
|
117
|
+
|
|
118
|
+
# Render "null" for an empty value, else an escaped JSON string.
|
|
119
|
+
jstr() {
|
|
120
|
+
if [ -z "$1" ]; then printf 'null'; else printf '"%s"' "$(json_escape "$1")"; fi
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
# 1 -> true, anything else -> false.
|
|
124
|
+
jbool() { if [ "$1" = "1" ]; then printf 'true'; else printf 'false'; fi; }
|
|
125
|
+
|
|
126
|
+
# Probe the environment once into G_* globals shared by the emitters.
|
|
127
|
+
collect() {
|
|
128
|
+
G_OS="$(detect_os)"
|
|
129
|
+
G_ARCH="$(detect_arch)"
|
|
130
|
+
|
|
131
|
+
G_CLI_PRESENT=0
|
|
132
|
+
G_CLI_PATH=""
|
|
133
|
+
G_CLI_VER=""
|
|
134
|
+
G_CLI_COMPAT=0
|
|
135
|
+
if command -v "$BIN" >/dev/null 2>&1; then
|
|
136
|
+
G_CLI_PRESENT=1
|
|
137
|
+
G_CLI_PATH="$(command -v "$BIN")"
|
|
138
|
+
G_CLI_VER="$(cli_version)"
|
|
139
|
+
if [ -n "$G_CLI_VER" ] && compatible "$G_CLI_VER"; then G_CLI_COMPAT=1; fi
|
|
140
|
+
fi
|
|
141
|
+
|
|
142
|
+
G_NPX_PRESENT=0
|
|
143
|
+
G_NPX_PATH=""
|
|
144
|
+
if command -v npx >/dev/null 2>&1; then
|
|
145
|
+
G_NPX_PRESENT=1
|
|
146
|
+
G_NPX_PATH="$(command -v npx)"
|
|
147
|
+
fi
|
|
148
|
+
|
|
149
|
+
G_BUNX_PRESENT=0
|
|
150
|
+
G_BUNX_PATH=""
|
|
151
|
+
if command -v bunx >/dev/null 2>&1; then
|
|
152
|
+
G_BUNX_PRESENT=1
|
|
153
|
+
G_BUNX_PATH="$(command -v bunx)"
|
|
154
|
+
fi
|
|
155
|
+
|
|
156
|
+
G_NODE_PRESENT=0
|
|
157
|
+
G_NODE_VER=""
|
|
158
|
+
if command -v node >/dev/null 2>&1; then
|
|
159
|
+
G_NODE_PRESENT=1
|
|
160
|
+
G_NODE_VER="$(node --version 2>/dev/null | sed 's/^v//')"
|
|
161
|
+
fi
|
|
162
|
+
|
|
163
|
+
G_SEL="$(resolve)"
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
# Build the nextSteps JSON array body (without the brackets) into G_NEXTSTEPS.
|
|
167
|
+
compute_next_steps() {
|
|
168
|
+
if [ "$G_SEL" = "none" ]; then
|
|
169
|
+
_s1="Install Node 22.13+ from https://nodejs.org so npx can run $PKG@$PINNED, then re-run this launcher."
|
|
170
|
+
_s2="No JavaScript runtime? Install Bun from https://bun.sh to use bunx, or put a compatible $BIN (major ${PINNED%%.*}, at or above $PINNED) on PATH."
|
|
171
|
+
G_NEXTSTEPS="$(printf '"%s", "%s"' "$(json_escape "$_s1")" "$(json_escape "$_s2")")"
|
|
172
|
+
else
|
|
173
|
+
G_NEXTSTEPS=""
|
|
174
|
+
fi
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
# Emit the structured diagnosis. $1, when a JSON object, is embedded as cliDoctor.
|
|
178
|
+
emit_json() {
|
|
179
|
+
_chained="${1:-}"
|
|
180
|
+
compute_next_steps
|
|
181
|
+
printf '{\n'
|
|
182
|
+
printf ' "tool": %s,\n' "$(jstr "$BIN")"
|
|
183
|
+
printf ' "package": %s,\n' "$(jstr "$PKG")"
|
|
184
|
+
printf ' "pinnedVersion": %s,\n' "$(jstr "$PINNED")"
|
|
185
|
+
printf ' "os": %s,\n' "$(jstr "$G_OS")"
|
|
186
|
+
printf ' "arch": %s,\n' "$(jstr "$G_ARCH")"
|
|
187
|
+
printf ' "checked": {\n'
|
|
188
|
+
printf ' "pathCli": { "present": %s, "path": %s, "version": %s, "compatible": %s },\n' \
|
|
189
|
+
"$(jbool "$G_CLI_PRESENT")" "$(jstr "$G_CLI_PATH")" "$(jstr "$G_CLI_VER")" "$(jbool "$G_CLI_COMPAT")"
|
|
190
|
+
printf ' "npx": { "present": %s, "path": %s },\n' "$(jbool "$G_NPX_PRESENT")" "$(jstr "$G_NPX_PATH")"
|
|
191
|
+
printf ' "bunx": { "present": %s, "path": %s },\n' "$(jbool "$G_BUNX_PRESENT")" "$(jstr "$G_BUNX_PATH")"
|
|
192
|
+
printf ' "node": { "present": %s, "version": %s }\n' "$(jbool "$G_NODE_PRESENT")" "$(jstr "$G_NODE_VER")"
|
|
193
|
+
printf ' },\n'
|
|
194
|
+
printf ' "nativeArtifact": { "available": false, "note": %s },\n' "$(jstr "$NATIVE_NOTE")"
|
|
195
|
+
printf ' "selected": %s,\n' "$(jstr "$G_SEL")"
|
|
196
|
+
printf ' "nextSteps": [%s],\n' "$G_NEXTSTEPS"
|
|
197
|
+
# First character of the captured output, via POSIX parameter expansion
|
|
198
|
+
# (cut -c1 would take the first char of every line, not of the whole string).
|
|
199
|
+
_first="${_chained%"${_chained#?}"}"
|
|
200
|
+
if [ -n "$_chained" ] && [ "$_first" = "{" ]; then
|
|
201
|
+
printf ' "cliDoctor": %s\n' "$_chained"
|
|
202
|
+
else
|
|
203
|
+
printf ' "cliDoctor": null\n'
|
|
204
|
+
fi
|
|
205
|
+
printf '}\n'
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
# Human-readable diagnosis for `doctor` without --json.
|
|
209
|
+
emit_text() {
|
|
210
|
+
printf '%s launcher diagnosis\n\n' "$BIN"
|
|
211
|
+
printf ' os / arch: %s / %s\n' "$G_OS" "$G_ARCH"
|
|
212
|
+
printf ' pinned version: %s (%s)\n' "$PINNED" "$PKG"
|
|
213
|
+
if [ "$G_CLI_PRESENT" = 1 ]; then
|
|
214
|
+
printf ' %s on PATH: %s (version %s, %s)\n' "$BIN" "$G_CLI_PATH" \
|
|
215
|
+
"${G_CLI_VER:-unknown}" "$([ "$G_CLI_COMPAT" = 1 ] && echo compatible || echo incompatible)"
|
|
216
|
+
else
|
|
217
|
+
printf ' %s on PATH: no\n' "$BIN"
|
|
218
|
+
fi
|
|
219
|
+
printf ' npx: %s\n' "$([ "$G_NPX_PRESENT" = 1 ] && echo "$G_NPX_PATH" || echo no)"
|
|
220
|
+
printf ' bunx: %s\n' "$([ "$G_BUNX_PRESENT" = 1 ] && echo "$G_BUNX_PATH" || echo no)"
|
|
221
|
+
printf ' node: %s\n' "$([ "$G_NODE_PRESENT" = 1 ] && echo "${G_NODE_VER:-yes}" || echo no)"
|
|
222
|
+
printf ' selected path: %s\n' "$G_SEL"
|
|
223
|
+
if [ "$G_SEL" = "none" ]; then
|
|
224
|
+
printf '\nNo runtime can launch %s here. %s\n' "$BIN" "$NATIVE_NOTE"
|
|
225
|
+
printf 'Next steps:\n'
|
|
226
|
+
printf ' - Install Node 22.13+ from https://nodejs.org, then re-run this launcher.\n'
|
|
227
|
+
printf ' - Or install Bun from https://bun.sh, or put a compatible %s on PATH.\n' "$BIN"
|
|
228
|
+
fi
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
# `doctor [--json] [extra...]`: launcher selection diagnosis. When a CLI is
|
|
232
|
+
# resolvable, chain the CLI's own doctor (engine/config diagnosis) so one call
|
|
233
|
+
# reports both layers. Extra flags pass through to the chained CLI doctor.
|
|
234
|
+
doctor() {
|
|
235
|
+
collect
|
|
236
|
+
_json=0
|
|
237
|
+
for _a in "$@"; do
|
|
238
|
+
if [ "$_a" = "--json" ]; then _json=1; fi
|
|
239
|
+
done
|
|
240
|
+
if [ "$_json" = 1 ]; then
|
|
241
|
+
_chained=""
|
|
242
|
+
if [ "$G_SEL" != "none" ]; then
|
|
243
|
+
_chained="$(run_cli doctor "$@" 2>/dev/null)" || _chained=""
|
|
244
|
+
fi
|
|
245
|
+
emit_json "$_chained"
|
|
246
|
+
else
|
|
247
|
+
emit_text
|
|
248
|
+
if [ "$G_SEL" != "none" ]; then
|
|
249
|
+
printf '\n--- %s doctor ---\n' "$BIN"
|
|
250
|
+
run_cli doctor "$@" || true
|
|
251
|
+
fi
|
|
252
|
+
fi
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
# Default action: forward every argument to the resolved CLI, inheriting stdio
|
|
256
|
+
# and exit code. No usable runtime -> structured diagnosis on stderr, exit 78
|
|
257
|
+
# (EX_CONFIG) so the agent never mistakes the diagnosis for a result.
|
|
258
|
+
run() {
|
|
259
|
+
_sel="$(resolve)"
|
|
260
|
+
case "$_sel" in
|
|
261
|
+
path) exec "$BIN" "$@" ;;
|
|
262
|
+
npx) exec npx --yes --package "$PKG@$PINNED" "$BIN" "$@" ;;
|
|
263
|
+
bunx) exec bunx --bun "$PKG@$PINNED" "$@" ;;
|
|
264
|
+
none)
|
|
265
|
+
collect
|
|
266
|
+
emit_json "" >&2
|
|
267
|
+
exit 78
|
|
268
|
+
;;
|
|
269
|
+
esac
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
case "${1:-}" in
|
|
273
|
+
doctor)
|
|
274
|
+
shift
|
|
275
|
+
doctor "$@"
|
|
276
|
+
;;
|
|
277
|
+
where)
|
|
278
|
+
resolve
|
|
279
|
+
;;
|
|
280
|
+
*)
|
|
281
|
+
run "$@"
|
|
282
|
+
;;
|
|
283
|
+
esac
|