@ryuugg/stanza 0.4.1 → 0.5.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/README.md +14 -38
- package/package.json +12 -11
- package/src/launcher +92 -36
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
## ✨ What is Stanza?
|
|
19
19
|
|
|
20
|
-
Stanza formats the spacing inside TypeScript and JavaScript function bodies, the one thing other formatters leave alone, so it runs alongside them without fighting. It edits only blank lines, brace tokens and the line break under a header whose braces it removed, is deterministic and idempotent
|
|
20
|
+
Stanza formats the spacing inside TypeScript and JavaScript function bodies, the one thing other formatters leave alone, so it runs alongside them without fighting. It edits only blank lines, brace tokens and the line break under a header whose braces it removed, and is deterministic and idempotent.
|
|
21
21
|
|
|
22
22
|
The style is mine, hence opinionated. A function body reads as a sequence of steps, one blank line between steps, none inside a step. A fetch and the `if (!response.ok)` that guards it are one step. A ten line query and the `return` after it are two. If that is not how you read code, this tool will annoy you.
|
|
23
23
|
|
|
@@ -66,54 +66,30 @@ Take the binary for your machine from the [latest release](https://github.com/ry
|
|
|
66
66
|
|
|
67
67
|
### Commands
|
|
68
68
|
|
|
69
|
-
| Command
|
|
70
|
-
|
|
|
71
|
-
| `stanza --check <paths>`
|
|
72
|
-
| `stanza --fix <paths>`
|
|
73
|
-
| `stanza --fix --changed`
|
|
74
|
-
| `stanza --check --staged`
|
|
75
|
-
| `stanza explain <file>:<line
|
|
76
|
-
| `stanza hook`
|
|
69
|
+
| Command | What it does |
|
|
70
|
+
| -------------------------------------- | --------------------------------------------------------- |
|
|
71
|
+
| `stanza --check <paths>` | Report findings and change nothing. |
|
|
72
|
+
| `stanza --fix <paths>` | Apply every rule it can decide on its own. |
|
|
73
|
+
| `stanza --fix --changed` | Fix the files changed against HEAD, plus untracked files. |
|
|
74
|
+
| `stanza --check --staged` | Check what is staged, for a pre-commit hook. |
|
|
75
|
+
| `stanza explain <file>:<line>[:<col>]` | Explain the gap, braced body or wall at that line. |
|
|
76
|
+
| `stanza hook` | Run as a Claude Code or Codex hook. |
|
|
77
77
|
|
|
78
78
|
### Hooks
|
|
79
79
|
|
|
80
|
-
To
|
|
80
|
+
To fix each Write, Edit and MultiEdit as soon as it lands in Claude Code, then fix what a subagent wrote when it finishes and what the session wrote at the end of each turn, add the three hooks to `.claude/settings.json`:
|
|
81
81
|
|
|
82
82
|
```json
|
|
83
83
|
{
|
|
84
84
|
"hooks": {
|
|
85
|
-
"PreToolUse": [
|
|
86
|
-
{
|
|
87
|
-
"matcher": "Write",
|
|
88
|
-
"hooks": [
|
|
89
|
-
{
|
|
90
|
-
"type": "command",
|
|
91
|
-
"command": "stanza hook"
|
|
92
|
-
}
|
|
93
|
-
]
|
|
94
|
-
}
|
|
95
|
-
],
|
|
96
85
|
"PostToolUse": [
|
|
97
86
|
{
|
|
98
|
-
"matcher": "Edit|MultiEdit",
|
|
99
|
-
"hooks": [
|
|
100
|
-
{
|
|
101
|
-
"type": "command",
|
|
102
|
-
"command": "stanza hook"
|
|
103
|
-
}
|
|
104
|
-
]
|
|
87
|
+
"matcher": "Write|Edit|MultiEdit",
|
|
88
|
+
"hooks": [{ "type": "command", "command": "stanza hook" }]
|
|
105
89
|
}
|
|
106
90
|
],
|
|
107
|
-
"Stop": [
|
|
108
|
-
|
|
109
|
-
"hooks": [
|
|
110
|
-
{
|
|
111
|
-
"type": "command",
|
|
112
|
-
"command": "stanza hook"
|
|
113
|
-
}
|
|
114
|
-
]
|
|
115
|
-
}
|
|
116
|
-
]
|
|
91
|
+
"Stop": [{ "hooks": [{ "type": "command", "command": "stanza hook" }] }],
|
|
92
|
+
"SubagentStop": [{ "hooks": [{ "type": "command", "command": "stanza hook" }] }]
|
|
117
93
|
}
|
|
118
94
|
}
|
|
119
95
|
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ryuugg/stanza",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "An opinionated
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "An opinionated formatter for turning function bodies into readable steps.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"formatter",
|
|
7
7
|
"code-formatter",
|
|
@@ -47,22 +47,23 @@
|
|
|
47
47
|
"typecheck": "tsc --noEmit"
|
|
48
48
|
},
|
|
49
49
|
"optionalDependencies": {
|
|
50
|
-
"@ryuugg/stanza-darwin-arm64": "0.
|
|
51
|
-
"@ryuugg/stanza-darwin-x64": "0.
|
|
52
|
-
"@ryuugg/stanza-linux-arm64": "0.
|
|
53
|
-
"@ryuugg/stanza-linux-arm64-musl": "0.
|
|
54
|
-
"@ryuugg/stanza-linux-x64": "0.
|
|
55
|
-
"@ryuugg/stanza-linux-x64-musl": "0.
|
|
50
|
+
"@ryuugg/stanza-darwin-arm64": "0.5.0",
|
|
51
|
+
"@ryuugg/stanza-darwin-x64": "0.5.0",
|
|
52
|
+
"@ryuugg/stanza-linux-arm64": "0.5.0",
|
|
53
|
+
"@ryuugg/stanza-linux-arm64-musl": "0.5.0",
|
|
54
|
+
"@ryuugg/stanza-linux-x64": "0.5.0",
|
|
55
|
+
"@ryuugg/stanza-linux-x64-musl": "0.5.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@biomejs/biome": "2.6.3",
|
|
59
|
-
"@types/bun": "
|
|
59
|
+
"@types/bun": "1.4.4",
|
|
60
60
|
"oxc-parser": "0.151.0",
|
|
61
61
|
"oxfmt": "0.70.0",
|
|
62
62
|
"oxlint": "^1.85.0",
|
|
63
63
|
"prettier": "3.9.10",
|
|
64
|
-
"tegami": "
|
|
65
|
-
"typescript": "^7.0.2"
|
|
64
|
+
"tegami": "1.5.0",
|
|
65
|
+
"typescript": "^7.0.2",
|
|
66
|
+
"yaml": "2.9.1"
|
|
66
67
|
},
|
|
67
68
|
"engines": {
|
|
68
69
|
"node": ">=20.10"
|
package/src/launcher
CHANGED
|
@@ -1,23 +1,54 @@
|
|
|
1
1
|
#!/bin/sh
|
|
2
2
|
':' /*
|
|
3
3
|
# Runs as sh first and execs the binary where npm, pnpm and Bun install it, so no JavaScript runtime starts.
|
|
4
|
-
|
|
5
|
-
while [ -L "$self" ]; do
|
|
6
|
-
link=$(readlink "$self")
|
|
7
|
-
case $link in
|
|
8
|
-
/*) self=$link ;;
|
|
9
|
-
*) self=${self%/*}/$link ;;
|
|
10
|
-
esac
|
|
11
|
-
done
|
|
4
|
+
[ "$1" = hook ] && [ "$AGENT_HOOKS" = 0 ] && exit 0
|
|
12
5
|
|
|
13
|
-
case $
|
|
14
|
-
*"/"*)
|
|
15
|
-
*)
|
|
6
|
+
case $0 in
|
|
7
|
+
*"/"*) self=$0 ;;
|
|
8
|
+
*) self=./$0 ;;
|
|
16
9
|
esac
|
|
17
10
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
for package in "${self%/.bin/stanza}/@ryuugg/stanza" "${self%/bin/stanza}/lib/node_modules/@ryuugg/stanza" "${self%/bin/stanza}/install/global/node_modules/@ryuugg/stanza"; do
|
|
12
|
+
[ "$self" -ef "$package/src/launcher" ] 2>/dev/null && break
|
|
13
|
+
package=
|
|
14
|
+
done
|
|
15
|
+
|
|
16
|
+
if [ -z "$package" ]; then
|
|
17
|
+
while [ -L "$self" ]; do
|
|
18
|
+
link=$(readlink "$self")
|
|
19
|
+
case $link in
|
|
20
|
+
/*) self=$link ;;
|
|
21
|
+
*) self=${self%/*}/$link ;;
|
|
22
|
+
esac
|
|
23
|
+
done
|
|
24
|
+
|
|
25
|
+
package=${self%/*}/..
|
|
26
|
+
fi
|
|
27
|
+
|
|
28
|
+
present() {
|
|
29
|
+
for file in "$@"; do
|
|
30
|
+
[ -e "$file" ] && return 0
|
|
31
|
+
done
|
|
32
|
+
|
|
33
|
+
return 1
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
machine= dyld=/System/Library/dyld cryptex=/System/Volumes/Preboot/Cryptexes/OS/System/Library/dyld
|
|
37
|
+
if present "$cryptex/dyld_shared_cache_arm64e" "$dyld/dyld_shared_cache_arm64e"; then
|
|
38
|
+
machine="Darwin arm64"
|
|
39
|
+
elif present "$cryptex/dyld_shared_cache_x86_64" "$cryptex/dyld_shared_cache_x86_64h" "$dyld/dyld_shared_cache_x86_64" "$dyld/dyld_shared_cache_x86_64h"; then
|
|
40
|
+
machine="Darwin x86_64"
|
|
41
|
+
elif present /lib64/ld-linux-x86-64.so.2 /lib/ld-musl-x86_64.so.1; then
|
|
42
|
+
present /lib/ld-linux-aarch64.so.1 /lib/ld-musl-aarch64.so.1 || machine="Linux x86_64"
|
|
43
|
+
elif present /lib/ld-linux-aarch64.so.1 /lib/ld-musl-aarch64.so.1; then
|
|
44
|
+
machine="Linux aarch64"
|
|
45
|
+
fi
|
|
46
|
+
|
|
47
|
+
[ -n "$machine" ] || machine=$(uname -sm 2>/dev/null)
|
|
48
|
+
|
|
49
|
+
musl= rosetta=
|
|
50
|
+
case $machine in
|
|
51
|
+
"Darwin arm64") platform=darwin-arm64 rosetta=darwin-x64 ;;
|
|
21
52
|
"Darwin x86_64") platform=darwin-x64 ;;
|
|
22
53
|
"Linux aarch64") platform=linux-arm64 musl=/lib/ld-musl-aarch64.so.1 ;;
|
|
23
54
|
"Linux x86_64") platform=linux-x64 musl=/lib/ld-musl-x86_64.so.1 ;;
|
|
@@ -30,43 +61,54 @@ if [ -n "$platform" ]; then
|
|
|
30
61
|
elif [ -n "$musl" ]; then
|
|
31
62
|
order="$platform $platform-musl"
|
|
32
63
|
else
|
|
33
|
-
order
|
|
64
|
+
order="$platform $rosetta"
|
|
34
65
|
fi
|
|
35
66
|
|
|
36
67
|
for scope in "$package/node_modules/@ryuugg" "$package/.."; do
|
|
37
68
|
for candidate in $order; do
|
|
38
|
-
if [ -x "$scope/stanza-$candidate/stanza" ]; then
|
|
69
|
+
if [ -f "$scope/stanza-$candidate/stanza" ] && [ -x "$scope/stanza-$candidate/stanza" ]; then
|
|
39
70
|
exec "$scope/stanza-$candidate/stanza" "$@"
|
|
40
71
|
fi
|
|
41
72
|
done
|
|
42
73
|
done
|
|
43
74
|
fi
|
|
44
75
|
|
|
45
|
-
|
|
46
|
-
exec
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if command -v node >/dev/null 2>&1; then
|
|
50
|
-
exec node "$0" "$@"
|
|
51
|
-
fi
|
|
76
|
+
for runtime in bun node; do
|
|
77
|
+
"$runtime" --version >/dev/null 2>&1 && exec "$runtime" "$self" "$@"
|
|
78
|
+
done
|
|
52
79
|
|
|
53
|
-
|
|
54
|
-
[ "$1" = hook ] &&
|
|
55
|
-
|
|
80
|
+
program=stanza status=2 offer=
|
|
81
|
+
[ "$1" = hook ] && program="stanza hook" status=1
|
|
82
|
+
[ -n "$platform" ] && offer=", or a release binary (https://github.com/ryuudotgg/stanza/releases/latest)"
|
|
83
|
+
echo "$program: needs Node.js or Bun to start$offer" >&2
|
|
84
|
+
exit $status
|
|
56
85
|
*/
|
|
57
86
|
|
|
58
87
|
// Parses as CommonJS and as an ES module, since Node picks the format of an extensionless file by version.
|
|
59
88
|
const args = process.argv.slice(2);
|
|
60
|
-
const
|
|
89
|
+
const hook = args[0] === "hook";
|
|
90
|
+
if (hook && process.env.AGENT_HOOKS === "0") process.exit(0);
|
|
91
|
+
|
|
92
|
+
const program = hook ? "stanza hook" : "stanza";
|
|
93
|
+
const failure = hook ? 1 : 2;
|
|
61
94
|
const releases = "https://github.com/ryuudotgg/stanza/releases/latest";
|
|
95
|
+
const supported = [
|
|
96
|
+
"darwin-arm64",
|
|
97
|
+
"darwin-x64",
|
|
98
|
+
"linux-arm64",
|
|
99
|
+
"linux-arm64-musl",
|
|
100
|
+
"linux-x64",
|
|
101
|
+
"linux-x64-musl",
|
|
102
|
+
];
|
|
62
103
|
|
|
63
104
|
function fail(message) {
|
|
64
|
-
process.stderr.write(
|
|
105
|
+
process.stderr.write(`${program}: ${message}\n`);
|
|
65
106
|
process.exit(failure);
|
|
66
107
|
}
|
|
67
108
|
|
|
68
109
|
function candidates(fs) {
|
|
69
110
|
const host = `${process.platform}-${process.arch}`;
|
|
111
|
+
if (host === "darwin-arm64") return [host, "darwin-x64"];
|
|
70
112
|
if (process.platform !== "linux") return [host];
|
|
71
113
|
|
|
72
114
|
const loader = `/lib/ld-musl-${process.arch === "x64" ? "x86_64" : "aarch64"}.so.1`;
|
|
@@ -75,11 +117,15 @@ function candidates(fs) {
|
|
|
75
117
|
}
|
|
76
118
|
|
|
77
119
|
function locate(fs, path, require) {
|
|
78
|
-
const platforms = candidates(fs);
|
|
120
|
+
const platforms = candidates(fs).filter((platform) => supported.includes(platform));
|
|
121
|
+
if (platforms.length === 0)
|
|
122
|
+
fail(`no binary for ${process.platform}-${process.arch}; supported: ${supported.join(", ")}`);
|
|
123
|
+
|
|
79
124
|
for (const platform of platforms)
|
|
80
125
|
try {
|
|
81
|
-
const
|
|
82
|
-
|
|
126
|
+
const name = `@ryuugg/stanza-${platform}`;
|
|
127
|
+
const manifest = require.resolve(`${name}/package.json`);
|
|
128
|
+
return { name, binary: path.join(path.dirname(manifest), "stanza") };
|
|
83
129
|
} catch {}
|
|
84
130
|
|
|
85
131
|
fail(
|
|
@@ -87,7 +133,7 @@ function locate(fs, path, require) {
|
|
|
87
133
|
);
|
|
88
134
|
}
|
|
89
135
|
|
|
90
|
-
function run(binary, spawn) {
|
|
136
|
+
function run({ name, binary }, spawn, util) {
|
|
91
137
|
let child;
|
|
92
138
|
const forward = (signal) => child.kill(signal);
|
|
93
139
|
const signals = ["SIGINT", "SIGHUP", "SIGTERM"];
|
|
@@ -95,11 +141,20 @@ function run(binary, spawn) {
|
|
|
95
141
|
|
|
96
142
|
child = spawn(binary, args, { stdio: "inherit" });
|
|
97
143
|
|
|
98
|
-
child.on("error", (error) =>
|
|
144
|
+
child.on("error", (error) => {
|
|
145
|
+
const { errno } = error;
|
|
146
|
+
const reason =
|
|
147
|
+
typeof errno === "number"
|
|
148
|
+
? (util.getSystemErrorMap?.().get(errno)?.[1] ??
|
|
149
|
+
util.getSystemErrorName(errno).toLowerCase())
|
|
150
|
+
: error.message;
|
|
151
|
+
|
|
152
|
+
fail(`cannot start ${name}: ${reason.charAt(0).toLowerCase()}${reason.slice(1)}`);
|
|
153
|
+
});
|
|
99
154
|
child.on("exit", (code, signal) => {
|
|
100
155
|
if (signal === null) process.exit(code ?? failure);
|
|
101
156
|
|
|
102
|
-
for (const
|
|
157
|
+
for (const forwarded of signals) process.off(forwarded, forward);
|
|
103
158
|
process.kill(process.pid, signal);
|
|
104
159
|
});
|
|
105
160
|
}
|
|
@@ -109,7 +164,8 @@ Promise.all([
|
|
|
109
164
|
import("node:path"),
|
|
110
165
|
import("node:module"),
|
|
111
166
|
import("node:child_process"),
|
|
112
|
-
|
|
167
|
+
import("node:util"),
|
|
168
|
+
]).then(([fs, path, { createRequire }, { spawn }, util]) => {
|
|
113
169
|
const require = createRequire(fs.realpathSync(process.argv[1]));
|
|
114
|
-
run(locate(fs, path, require), spawn);
|
|
170
|
+
run(locate(fs, path, require), spawn, util);
|
|
115
171
|
});
|