@moneko/core 4.11.5 → 4.12.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/hooks/ai-eslint.sh +66 -0
- package/hooks/ai-stylelint.sh +28 -0
- package/lib/bin/setup.mjs +1 -1
- package/lib/commom/ai-hooks.d.mts +2 -0
- package/lib/commom/ai-hooks.mjs +11 -0
- package/package.json +4 -3
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -u
|
|
3
|
+
|
|
4
|
+
if [ ! -t 0 ]; then
|
|
5
|
+
hook_input=$(cat)
|
|
6
|
+
if printf '%s' "$hook_input" | grep -Eq '"stop_hook_active"[[:space:]]*:[[:space:]]*true'; then
|
|
7
|
+
exit 0
|
|
8
|
+
fi
|
|
9
|
+
fi
|
|
10
|
+
|
|
11
|
+
repo_root=$(git rev-parse --show-toplevel 2>/dev/null) || {
|
|
12
|
+
printf 'AI ESLint hook: unable to locate the Git repository root.\n' >&2
|
|
13
|
+
exit 2
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
cd "$repo_root" || exit 2
|
|
17
|
+
|
|
18
|
+
if ! command -v npx >/dev/null 2>&1; then
|
|
19
|
+
printf 'AI ESLint hook: npx is unavailable; install no dependency automatically and fix the environment before continuing.\n' >&2
|
|
20
|
+
exit 2
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
tmp_dir=$(mktemp -d "${TMPDIR:-/tmp}/ai-eslint-fix.XXXXXX") || exit 2
|
|
24
|
+
trap 'rm -rf "$tmp_dir"' EXIT
|
|
25
|
+
|
|
26
|
+
had_errors=0
|
|
27
|
+
|
|
28
|
+
while IFS= read -r -d '' record; do
|
|
29
|
+
xy=${record:0:2}
|
|
30
|
+
path=${record:3}
|
|
31
|
+
|
|
32
|
+
case "$xy" in
|
|
33
|
+
*R*|*C*)
|
|
34
|
+
# Rename/copy records contain a second NUL-delimited path. Always consume it.
|
|
35
|
+
IFS= read -r -d '' ignored_path || true
|
|
36
|
+
;;
|
|
37
|
+
esac
|
|
38
|
+
|
|
39
|
+
case "$xy" in
|
|
40
|
+
\?\?) should_lint=1 ;;
|
|
41
|
+
*)
|
|
42
|
+
case "$xy" in
|
|
43
|
+
*A*|*M*) should_lint=1 ;;
|
|
44
|
+
*) should_lint=0 ;;
|
|
45
|
+
esac
|
|
46
|
+
;;
|
|
47
|
+
esac
|
|
48
|
+
|
|
49
|
+
[ "$should_lint" -eq 1 ] || continue
|
|
50
|
+
[ -e "$path" ] || [ -L "$path" ] || continue
|
|
51
|
+
|
|
52
|
+
output_file="$tmp_dir/output-${RANDOM}-${RANDOM}"
|
|
53
|
+
if ! npx mo eslint "$path" --fix >"$output_file" 2>&1; then
|
|
54
|
+
had_errors=1
|
|
55
|
+
fi
|
|
56
|
+
if [ -s "$output_file" ]; then
|
|
57
|
+
cat "$output_file" >&2
|
|
58
|
+
fi
|
|
59
|
+
done < <(git status --porcelain=v1 -z --untracked-files=all)
|
|
60
|
+
|
|
61
|
+
if [ "$had_errors" -ne 0 ]; then
|
|
62
|
+
printf '\nAI ESLint hook: 请 Agent ç»§ç»ä¿®å¤å©ä½ ESLint é®é¢ã\n' >&2
|
|
63
|
+
exit 2
|
|
64
|
+
fi
|
|
65
|
+
|
|
66
|
+
exit 0
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -u
|
|
3
|
+
|
|
4
|
+
if [ ! -t 0 ]; then
|
|
5
|
+
hook_input=$(cat)
|
|
6
|
+
if printf '%s' "$hook_input" | grep -Eq '"stop_hook_active"[[:space:]]*:[[:space:]]*true'; then
|
|
7
|
+
exit 0
|
|
8
|
+
fi
|
|
9
|
+
fi
|
|
10
|
+
|
|
11
|
+
repo_root=$(git rev-parse --show-toplevel 2>/dev/null) || {
|
|
12
|
+
printf 'AI Stylelint hook: unable to locate the Git repository root.\n' >&2
|
|
13
|
+
exit 2
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
cd "$repo_root" || exit 2
|
|
17
|
+
|
|
18
|
+
if ! command -v npx >/dev/null 2>&1; then
|
|
19
|
+
printf 'AI Stylelint hook: npx is unavailable; install no dependency automatically and fix the environment before continuing.\n' >&2
|
|
20
|
+
exit 2
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
if ! npx mo stylelint src; then
|
|
24
|
+
printf '\nAI Stylelint hook: 请 Agent 继续修复剩余 Stylelint 问题。\n' >&2
|
|
25
|
+
exit 2
|
|
26
|
+
fi
|
|
27
|
+
|
|
28
|
+
exit 0
|
package/lib/bin/setup.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import m from"../commom/check-npm.mjs";import{corepack as
|
|
1
|
+
import{argv as o}from"node:process";import{ensureClaudeHooks as m,ensureCodexHooks as r}from"../commom/ai-hooks.mjs";import c from"../commom/check-npm.mjs";import{corepack as p}from"../commom/corepack.mjs";import{parseArgs as s}from"../commom/parse-args.mjs";import{CONFIG as i}from"../config.mjs";export default function(){p(i.corepack),c(),s(o)["ai-hooks"]&&(r(),m())};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import{existsSync as o,mkdirSync as e,readFileSync as s,writeFileSync as t}from"node:fs";import{dirname as r,resolve as n}from"node:path";import{paths as m}from"./paths.mjs";let h=m.programPath,i='bash "$(git rev-parse --show-toplevel)/node_modules/@moneko/core/hooks/ai-eslint.sh"',p='bash "$(git rev-parse --show-toplevel)/node_modules/@moneko/core/hooks/ai-stylelint.sh"';export function ensureCodexHooks(){let m=n(h,".codex/config.toml"),a=o(m)?s(m,"utf8"):"[features]\nhooks = true\n";for(let o of(a.includes("[[hooks.Stop]]")||(a=`${a.trimEnd()}
|
|
2
|
+
|
|
3
|
+
[[hooks.Stop]]
|
|
4
|
+
matcher = ".*"
|
|
5
|
+
`),[i,p])){let e=JSON.stringify(o);a.includes(`command = ${e}`)||(a=`${a.trimEnd()}
|
|
6
|
+
|
|
7
|
+
[[hooks.Stop.hooks]]
|
|
8
|
+
type = "command"
|
|
9
|
+
command = ${e}
|
|
10
|
+
`)}e(r(m),{recursive:!0}),t(m,a)}export function ensureClaudeHooks(){let m=n(h,".claude/settings.json"),a=o(m)?JSON.parse(s(m,"utf8")):{};a.hooks??={},a.hooks.Stop??=[];let l=a.hooks.Stop.find(o=>o?.matcher===".*");for(let o of(l||(l={matcher:".*",hooks:[]},a.hooks.Stop.push(l)),l.hooks??=[],[i,p]))l.hooks.some(e=>e?.type==="command"&&e.command===o)||l.hooks.push({type:"command",command:o});e(r(m),{recursive:!0}),t(m,`${JSON.stringify(a,null,2)}
|
|
11
|
+
`)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneko/core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.12.0",
|
|
4
4
|
"description": "@moneko/core",
|
|
5
5
|
"main": "lib/index.mjs",
|
|
6
6
|
"type": "module",
|
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
"homepage": "https://moneko-o.github.io/neko-ui/@moneko/config",
|
|
132
132
|
"license": "MIT",
|
|
133
133
|
"dependencies": {
|
|
134
|
-
"@jsonjoy.com/fs-node": "4.
|
|
134
|
+
"@jsonjoy.com/fs-node": "4.71.0",
|
|
135
135
|
"@moneko/convert": "1.3.2",
|
|
136
136
|
"@moneko/eslint": "1.11.2",
|
|
137
137
|
"@moneko/mdx": "1.0.3",
|
|
@@ -165,6 +165,7 @@
|
|
|
165
165
|
},
|
|
166
166
|
"files": [
|
|
167
167
|
"lib",
|
|
168
|
-
"typings"
|
|
168
|
+
"typings",
|
|
169
|
+
"hooks"
|
|
169
170
|
]
|
|
170
171
|
}
|