win-nice 0.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/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +356 -0
- package/bin/abovenormal +11 -0
- package/bin/abovenormal.bat +13 -0
- package/bin/abovenormal.ps1 +193 -0
- package/bin/admin +11 -0
- package/bin/admin.bat +12 -0
- package/bin/admin.ps1 +259 -0
- package/bin/belownormal +11 -0
- package/bin/belownormal.bat +13 -0
- package/bin/belownormal.ps1 +192 -0
- package/bin/cap +11 -0
- package/bin/cap.bat +10 -0
- package/bin/cap.ps1 +269 -0
- package/bin/cx +11 -0
- package/bin/cx.bat +8 -0
- package/bin/cx.ps1 +185 -0
- package/bin/cy +11 -0
- package/bin/cy.bat +8 -0
- package/bin/cy.ps1 +185 -0
- package/bin/high +11 -0
- package/bin/high.bat +12 -0
- package/bin/high.ps1 +193 -0
- package/bin/idle +11 -0
- package/bin/idle.bat +12 -0
- package/bin/idle.ps1 +192 -0
- package/bin/pint +11 -0
- package/bin/pint.bat +8 -0
- package/bin/pint.ps1 +270 -0
- package/bin/realtime +11 -0
- package/bin/realtime.bat +13 -0
- package/bin/realtime.ps1 +197 -0
- package/bin/uiup +11 -0
- package/bin/uiup.bat +4 -0
- package/bin/uiup.ps1 +41 -0
- package/install/cli.js +62 -0
- package/install/install.js +79 -0
- package/install/manifest.js +29 -0
- package/install/paths.js +141 -0
- package/install/skill.js +68 -0
- package/install/uninstall.js +76 -0
- package/package.json +48 -0
- package/skills/win-nice/SKILL.md +132 -0
package/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 win-nice contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
# win-nice
|
|
2
|
+
|
|
3
|
+
[](https://github.com/PHPCraftdream/win-nice/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/win-nice)
|
|
5
|
+
[](https://www.npmjs.com/package/win-nice)
|
|
6
|
+
[](#license)
|
|
7
|
+
[](#requirements)
|
|
8
|
+
[](package.json)
|
|
9
|
+
[](package.json)
|
|
10
|
+
|
|
11
|
+
Windows equivalent of the unix `nice` / `renice` / `cpulimit` family, built for a
|
|
12
|
+
specific pain point: running several parallel AI coding agents (Claude Code, etc.)
|
|
13
|
+
on one Windows box without their builds/tests pegging every core and freezing the
|
|
14
|
+
desktop — mouse, keyboard, window dragging, audio, all of it.
|
|
15
|
+
|
|
16
|
+
No compiled binaries, no runtime dependencies. Just `.bat` + `.ps1` files that
|
|
17
|
+
call the relevant Win32 APIs directly (Job Objects, process priority classes).
|
|
18
|
+
npm is used only as a distribution/version channel and for the install CLI —
|
|
19
|
+
none of the tools themselves need Node.js to run.
|
|
20
|
+
|
|
21
|
+
## Argument handling
|
|
22
|
+
|
|
23
|
+
Every tool tries to launch the wrapped command directly first (`CreateProcess`,
|
|
24
|
+
no shell involved at all) and only falls back to `cmd.exe /c` when the target
|
|
25
|
+
turns out to be a `.bat`/`.cmd` file or a cmd.exe builtin that genuinely needs
|
|
26
|
+
one.
|
|
27
|
+
|
|
28
|
+
**Direct-launch path** (the common case: the target is a real `.exe`): arguments
|
|
29
|
+
are immune to cmd.exe's special characters entirely — `&`, `|`, `<`, `>`, `^`,
|
|
30
|
+
`%`, quotes, spaces, empty strings all pass through exactly as given, standard
|
|
31
|
+
MSVCRT/`CommandLineToArgvW` quoting. cmd.exe is never invoked on this path, so
|
|
32
|
+
there's nothing to expand.
|
|
33
|
+
|
|
34
|
+
**`cmd.exe /c` fallback path** (only reached for `.bat`/`.cmd` targets or
|
|
35
|
+
cmd.exe builtins): `&|<>^`/quotes/spaces/empty strings are still fully
|
|
36
|
+
protected. A literal `%` used to be able to trigger environment-variable
|
|
37
|
+
expansion here — cmd.exe pairs up `%` characters across the *entire* command
|
|
38
|
+
line, even across separate arguments, and there's no reliable per-character
|
|
39
|
+
escape for that at the `cmd.exe /c` level. Rather than risk that, this path now
|
|
40
|
+
**fails closed**: if any argument contains `%`, the tool refuses to run,
|
|
41
|
+
prints an error to stderr, and exits with code `1` — the command never reaches
|
|
42
|
+
cmd.exe. This is a change from just checking for the character; it's a hard
|
|
43
|
+
reject, not a best-effort escape.
|
|
44
|
+
|
|
45
|
+
**Separately, and unaffected by the fail-closed fix above:** each tool ships
|
|
46
|
+
as up to three files — `name.bat`, `name.ps1`, and a plain extensionless
|
|
47
|
+
`name` shim (a `#!/bin/sh` script) — and which one a bare `name ...`
|
|
48
|
+
invocation resolves to depends on the calling shell:
|
|
49
|
+
|
|
50
|
+
| Calling shell | Resolves to | `%` handling |
|
|
51
|
+
| --- | --- | --- |
|
|
52
|
+
| PowerShell | `name.ps1` | full argument safety (see above) |
|
|
53
|
+
| cmd.exe, or PATHEXT-based resolution (e.g. Node's `child_process`, which doesn't include `.PS1` in `PATHEXT` by default) | `name.bat` | corrupted before `.ps1` ever runs (see below) |
|
|
54
|
+
| POSIX shell (Git Bash only — ignores `PATHEXT`/bare-name extension resolution entirely) | `name` (no extension) | full argument safety — the shim `exec`s straight into `name.ps1` via `powershell -File`, the same direct-to-`.ps1` path PowerShell itself uses, with MSYS argument conversion disabled so slash-style switches (`/c`, `/d`) and Windows paths arrive untouched; no `.bat`/cmd.exe hop involved |
|
|
55
|
+
|
|
56
|
+
The extensionless shims are Git Bash-specific; WSL is not supported — WSL has
|
|
57
|
+
no bare `powershell` (only `powershell.exe`), Windows PowerShell can't resolve
|
|
58
|
+
the `/mnt/...` script path such a shim would pass to `-File`, and a WSL-side
|
|
59
|
+
npm refuses this package anyway (`"os": ["win32"]` in `package.json`). Install
|
|
60
|
+
through Windows Node/npm and call the tools from Git Bash.
|
|
61
|
+
|
|
62
|
+
The `.bat` file corrupts any literal `%` in its own arguments before your
|
|
63
|
+
command, and before `.ps1`, ever runs at all, confirmed with nothing more
|
|
64
|
+
than a bare `echo %1` in a plain `.bat`. This is cmd.exe's own
|
|
65
|
+
batch-parameter substitution (`%1`/`%*`) rescanning for `%...%` patterns
|
|
66
|
+
across the whole line while parsing the `.bat` entry point itself; there's no
|
|
67
|
+
fix for it from inside a `.bat` file, and it happens before the `.ps1` (and
|
|
68
|
+
its fail-closed `%` check) ever sees the arguments. Every other special
|
|
69
|
+
character (`&|<>^`) survives this hop untouched.
|
|
70
|
+
|
|
71
|
+
## Tools
|
|
72
|
+
|
|
73
|
+
### `idle <command> [args...]`
|
|
74
|
+
Runs `command` at `IDLE_PRIORITY_CLASS`, waits for it to exit, propagates its exit
|
|
75
|
+
code. Priority applies to the whole spawned process tree automatically — Windows'
|
|
76
|
+
`CreateProcess` inherits `IDLE`/`BELOW_NORMAL` priority by default when a child
|
|
77
|
+
process doesn't request a priority of its own.
|
|
78
|
+
|
|
79
|
+
### `belownormal <command> [args...]`
|
|
80
|
+
Same as `idle`, at `BELOW_NORMAL_PRIORITY_CLASS` — a lighter touch than idle.
|
|
81
|
+
|
|
82
|
+
### `abovenormal <command> [args...]`
|
|
83
|
+
Runs `command` at `ABOVE_NORMAL_PRIORITY_CLASS`, waits for it to exit, propagates
|
|
84
|
+
its exit code.
|
|
85
|
+
|
|
86
|
+
**Unlike `idle`/`belownormal`, this does *not* apply to the whole process tree** —
|
|
87
|
+
confirmed empirically. Windows only inherits `IDLE`/`BELOW_NORMAL` priority into
|
|
88
|
+
child processes by default; `ABOVE_NORMAL` and higher are not, so anything the
|
|
89
|
+
wrapped command spawns runs back at ordinary `Normal` priority. Only useful when
|
|
90
|
+
the command you're wrapping does the actual work itself rather than delegating to
|
|
91
|
+
child processes.
|
|
92
|
+
|
|
93
|
+
### `high <command> [args...]`
|
|
94
|
+
Same as `abovenormal`, at `HIGH_PRIORITY_CLASS` — a stronger boost. Same
|
|
95
|
+
single-process-only caveat applies.
|
|
96
|
+
|
|
97
|
+
### `realtime <command> [args...]`
|
|
98
|
+
Same shape, at `REALTIME_PRIORITY_CLASS`. **Dangerous, use with caution:**
|
|
99
|
+
`REALTIME` outranks the OS's own input/audio/UI threads — a busy realtime-priority
|
|
100
|
+
process can make the entire desktop (mouse, keyboard, everything) stop responding,
|
|
101
|
+
which is the exact failure mode this project otherwise exists to prevent. It also
|
|
102
|
+
needs the `SeIncreaseBasePriorityPrivilege` privilege (elevated/admin processes
|
|
103
|
+
have it by default); without it, Windows doesn't error out, it silently downgrades
|
|
104
|
+
the request to `HIGH_PRIORITY_CLASS` instead — confirmed empirically. Same
|
|
105
|
+
single-process-only caveat as `abovenormal`/`high` applies on top of all that.
|
|
106
|
+
|
|
107
|
+
### `cap <percent> <command> [args...]`
|
|
108
|
+
Hard CPU quota (1-100) for the whole process tree, enforced by a Windows Job
|
|
109
|
+
Object (`JOBOBJECT_CPU_RATE_CONTROL_INFORMATION`, hard cap). Unlike `idle`/
|
|
110
|
+
`belownormal`, this is a real ceiling on total CPU%, not just a scheduling
|
|
111
|
+
priority — it holds even when nothing else on the machine is contending for CPU.
|
|
112
|
+
|
|
113
|
+
The cap covers the whole subtree from its very first instruction: the wrapped
|
|
114
|
+
command is created suspended, assigned to the Job Object, and only then resumed
|
|
115
|
+
— there's no window where it runs uncapped. Every process it spawns (and their
|
|
116
|
+
children, recursively) automatically joins the same job; this is standard Job
|
|
117
|
+
Object behavior on any supported Windows version, not something specific to
|
|
118
|
+
newer ones. The only way out is a descendant explicitly requesting
|
|
119
|
+
`CREATE_BREAKAWAY_FROM_JOB`, and since the job here never sets a
|
|
120
|
+
breakaway-allowed flag, that fails closed — the child just fails to launch
|
|
121
|
+
rather than silently escaping the cap.
|
|
122
|
+
|
|
123
|
+
Windows 8+ specifically matters if something inside the wrapped command creates
|
|
124
|
+
*its own* Job Object (some tools do, e.g. Chromium-based ones): before Windows 8
|
|
125
|
+
a process could belong to only one job at a time, so that inner
|
|
126
|
+
`AssignProcessToJobObject` call would fail. Windows 8+ allows nested jobs, so it
|
|
127
|
+
succeeds instead, and both jobs' limits apply (whichever is more restrictive
|
|
128
|
+
wins).
|
|
129
|
+
|
|
130
|
+
Blocks until the command exits, propagates its exit code.
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
cap 50 npm run build
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### `pint <thread-count> <command> [args...]`
|
|
137
|
+
Short for **pin threads**. Restricts the whole process tree to the first
|
|
138
|
+
`<thread-count>` logical processors via Windows process affinity
|
|
139
|
+
(`JOBOBJECT_BASIC_LIMIT_INFORMATION`, `JOB_OBJECT_LIMIT_AFFINITY`) — same
|
|
140
|
+
suspend-then-assign-then-resume Job Object mechanism as `cap`, so the same
|
|
141
|
+
"covers the whole subtree from the first instruction" and "breakaway fails
|
|
142
|
+
closed" guarantees apply.
|
|
143
|
+
|
|
144
|
+
Deliberately *threads*, not *cores*, in both the name and the semantics:
|
|
145
|
+
Windows affinity masks address logical processors (hardware threads), not
|
|
146
|
+
physical cores. On a machine with Hyper-Threading/SMT, `pint 4` pins to 4
|
|
147
|
+
*logical processors* — depending on which ones, that could be 2 fully-used
|
|
148
|
+
physical cores or 4 half-used ones; the affinity API has no concept of "whole
|
|
149
|
+
core" grouping on its own. `<thread-count>` must be between 1 and the number
|
|
150
|
+
of logical processors on the machine (`[Environment]::ProcessorCount`, capped
|
|
151
|
+
at 63 — a single affinity mask can't address more).
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
pint 4 npm run build
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**A `cap`/`pint` limit sticks to any daemon the wrapped command leaves
|
|
158
|
+
running**, for that daemon's entire lifetime — not just for the wrapped
|
|
159
|
+
command's own run. Job Object membership is permanent for a process once
|
|
160
|
+
assigned (short of an explicit, disallowed breakaway); a background process
|
|
161
|
+
the command spawns and detaches from is still in the same job, still capped,
|
|
162
|
+
for as long as it stays alive. This bites build tools that reuse a persistent
|
|
163
|
+
process across invocations to skip cold-start cost: `dotnet build`'s
|
|
164
|
+
`VBCSCompiler`/MSBuild node reuse, a Gradle daemon, file-watcher processes
|
|
165
|
+
left running by `npm run watch`-style scripts. A follow-up **uncapped**
|
|
166
|
+
`dotnet build` (or `gradle`) can end up running inside the *previous* `cap`
|
|
167
|
+
call's Job Object without a new `cap`/`pint` invocation of its own, capped
|
|
168
|
+
because a stale daemon from an earlier call is doing the work. Either don't
|
|
169
|
+
leave the daemon running across a `cap`/`pint` call whose limit shouldn't
|
|
170
|
+
persist (`dotnet build -p:UseSharedCompilation=false`, `gradle --no-daemon`),
|
|
171
|
+
or accept that the limit is now effectively attached to the daemon until it's
|
|
172
|
+
killed.
|
|
173
|
+
|
|
174
|
+
### `uiup`
|
|
175
|
+
One-shot priority boost (`HIGH`) for the live shell/UI/audio processes so the
|
|
176
|
+
desktop stays responsive while heavy background work runs underneath:
|
|
177
|
+
`explorer`, `dwm`, `sihost`, `ShellExperienceHost`, `StartMenuExperienceHost`,
|
|
178
|
+
`StartMenu`, `SearchApp`, `audiodg`.
|
|
179
|
+
|
|
180
|
+
Self-elevates via UAC — `dwm`/`sihost` run under a separate account
|
|
181
|
+
(`Window Manager\DWM-1`), so raising their priority needs admin rights.
|
|
182
|
+
|
|
183
|
+
The boost does **not** propagate to apps you launch from Explorer afterwards:
|
|
184
|
+
`HIGH` priority isn't inherited by child processes under Windows' default
|
|
185
|
+
`CreateProcess` rules (only `IDLE`/`BELOW_NORMAL` are). Confirmed empirically —
|
|
186
|
+
see the project history for the test.
|
|
187
|
+
|
|
188
|
+
### `admin <command> [args...]`
|
|
189
|
+
Runs `command` elevated (as Administrator), waits for it to exit, propagates its
|
|
190
|
+
exit code — the elevated equivalent of `idle`. If it's already elevated, runs
|
|
191
|
+
inline sharing the current console, with the full direct-launch argument safety
|
|
192
|
+
described above.
|
|
193
|
+
|
|
194
|
+
If the calling shell isn't already elevated, triggers the standard UAC consent
|
|
195
|
+
prompt (via `ShellExecute`, always opening its own console window, incompatible
|
|
196
|
+
with sharing the caller's). Unlike a plain `ShellExecute("cmd.exe", "/c ...")`,
|
|
197
|
+
this branch also tries a direct launch first: a `.bat`/`.cmd` target still needs
|
|
198
|
+
the `cmd.exe /c` fallback (no elevation-capable equivalent of `CreateProcess`'s
|
|
199
|
+
own `.bat`/`.cmd` auto-relaunch), but any other target launches directly via
|
|
200
|
+
`-FilePath`, never touching cmd.exe — same as the already-elevated branch, a
|
|
201
|
+
literal `%` in any argument is only refused when the `.bat`/`.cmd` fallback is
|
|
202
|
+
actually needed, since a direct launch is never exposed to `%` expansion at all.
|
|
203
|
+
|
|
204
|
+
```
|
|
205
|
+
admin npm install -g some-package
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## AI CLI launchers
|
|
209
|
+
|
|
210
|
+
Not part of the priority/CPU-limiting toolset above — these two are unrelated
|
|
211
|
+
one-line convenience wrappers that happened to live alongside win-nice's own
|
|
212
|
+
scripts and got folded into the same install/PATH mechanism.
|
|
213
|
+
|
|
214
|
+
### `cy [args...]`
|
|
215
|
+
Runs `claude --dangerously-skip-permissions [args...]`.
|
|
216
|
+
|
|
217
|
+
### `cx [args...]`
|
|
218
|
+
Runs `codex --dangerously-bypass-approvals-and-sandbox [args...]`.
|
|
219
|
+
|
|
220
|
+
**Both bypass the tool's own permission/approval/sandbox prompts.** Only use them
|
|
221
|
+
in a context where you'd already accept running that AI agent unattended (e.g.
|
|
222
|
+
inside an already-sandboxed/disposable environment). They do not add any sandboxing
|
|
223
|
+
of their own — the flag names describe exactly what they do.
|
|
224
|
+
|
|
225
|
+
## Install
|
|
226
|
+
|
|
227
|
+
```
|
|
228
|
+
npm install -g win-nice
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
This copies every tool above into `%LOCALAPPDATA%\win-nice\bin` and adds that
|
|
232
|
+
directory to your user `PATH` (via `postinstall`). Restart your terminal
|
|
233
|
+
afterwards so the new `PATH` takes effect.
|
|
234
|
+
|
|
235
|
+
`npm uninstall -g win-nice` does **not** reverse this — npm's `uninstall`
|
|
236
|
+
lifecycle script was removed (npm ≥ 7 never runs it at all; there is no
|
|
237
|
+
supported npm version where a `preuninstall` script would fire). Run
|
|
238
|
+
`npx win-nice uninstall` (see below) before or after the `npm uninstall`,
|
|
239
|
+
either order — `npx` re-fetches the package to run it, so it still works even
|
|
240
|
+
after the global package itself is gone.
|
|
241
|
+
|
|
242
|
+
The commands themselves are never registered through npm's own global `bin`
|
|
243
|
+
shimming — `idle`/`cap`/etc. are too generic a name to risk colliding with
|
|
244
|
+
someone else's global npm package. npm here is only the delivery mechanism for
|
|
245
|
+
a dedicated, PATH-managed install directory.
|
|
246
|
+
|
|
247
|
+
Without npm: copy the contents of `bin/` into any directory on your `PATH`.
|
|
248
|
+
|
|
249
|
+
### Managing an existing install
|
|
250
|
+
|
|
251
|
+
```
|
|
252
|
+
npx win-nice status # what's installed, where, which version
|
|
253
|
+
npx win-nice reinstall # re-copy from the current package version
|
|
254
|
+
npx win-nice uninstall # remove files + PATH entry
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
`uninstall`/`reinstall` treat every file recorded in the install manifest
|
|
258
|
+
(`%LOCALAPPDATA%\win-nice\install-manifest.json`) as owned by the package and
|
|
259
|
+
remove it regardless of local edits — these are managed files, not a
|
|
260
|
+
customization point. If the manifest itself is missing or corrupt, uninstall
|
|
261
|
+
falls back to scanning the install directory and only removes files that still
|
|
262
|
+
carry the `win-nice: managed-file` marker comment, so that scan doesn't delete
|
|
263
|
+
unrelated files sitting in the same directory.
|
|
264
|
+
|
|
265
|
+
### Claude Code / Codex skill
|
|
266
|
+
|
|
267
|
+
```
|
|
268
|
+
npx win-nice skill install # add the win-nice reference skill
|
|
269
|
+
npx win-nice skill uninstall # remove it
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Separate, opt-in install step — not run automatically by `postinstall`. Copies
|
|
273
|
+
[`skills/win-nice/SKILL.md`](skills/win-nice/SKILL.md) (documents every tool
|
|
274
|
+
above except `cy`/`cx`) to `~/.claude/skills/win-nice/SKILL.md` and
|
|
275
|
+
`~/.agents/skills/win-nice/SKILL.md` (Codex CLI's personal-skill location) —
|
|
276
|
+
`SKILL.md` is an open, cross-agent format (agentskills.io), so the same file
|
|
277
|
+
works for both unmodified.
|
|
278
|
+
|
|
279
|
+
Unlike the `bin/` install directory, `~/.claude/skills` and `~/.agents/skills`
|
|
280
|
+
aren't exclusively win-nice's — a `win-nice` folder there could belong to
|
|
281
|
+
something else entirely. `install` refuses to overwrite a file that's already
|
|
282
|
+
there without the `win-nice: managed-skill` marker comment (reports it as
|
|
283
|
+
skipped rather than clobbering it), and `uninstall` only removes a copy that
|
|
284
|
+
still carries that marker.
|
|
285
|
+
|
|
286
|
+
Exit code reflects this: `install`/`uninstall` exit 1 if any target was
|
|
287
|
+
skipped due to a real conflict (foreign file present for `install`;
|
|
288
|
+
marker-stripped/user-modified file for `uninstall`). A clean install/uninstall
|
|
289
|
+
exits 0, and so does `uninstall` finding nothing to remove — a missing target
|
|
290
|
+
isn't a conflict.
|
|
291
|
+
|
|
292
|
+
## Requirements
|
|
293
|
+
|
|
294
|
+
Windows 8 / Server 2012 or newer (Job Object CPU rate control). PowerShell is
|
|
295
|
+
bundled with Windows — no separate install needed to run the tools. Node.js is
|
|
296
|
+
only needed for the npm-based installer/tests, not for the tools themselves.
|
|
297
|
+
`cy`/`cx` additionally need `claude`/`codex` installed and on `PATH`.
|
|
298
|
+
|
|
299
|
+
**PowerShell execution policy:** Windows client editions default to
|
|
300
|
+
`Restricted`, which blocks a bare `.ps1` invoked directly by PowerShell itself
|
|
301
|
+
(`... cannot be loaded because running scripts is disabled on this system`).
|
|
302
|
+
The `.bat` files are unaffected (they pass `-ExecutionPolicy Bypass`
|
|
303
|
+
explicitly), and so are the Git Bash shims — each one runs
|
|
304
|
+
`powershell -NoProfile -ExecutionPolicy Bypass -File ...` itself, so only
|
|
305
|
+
invoking a bare `name.ps1` from PowerShell needs the one-time fix below.
|
|
306
|
+
Caveat: Group Policy can still override `-ExecutionPolicy Bypass` in some
|
|
307
|
+
managed environments. Run once, as the user who'll run these tools:
|
|
308
|
+
|
|
309
|
+
```
|
|
310
|
+
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### Environment variables
|
|
314
|
+
|
|
315
|
+
- `WIN_NICE_HOME` — overrides the install root (default
|
|
316
|
+
`%LOCALAPPDATA%\win-nice`). Used by the test suite; also useful for a
|
|
317
|
+
non-default install location.
|
|
318
|
+
- `WIN_NICE_SKILL_HOME` — overrides the home directory `skill install`/
|
|
319
|
+
`skill uninstall` resolve `~/.claude/skills/...` and `~/.agents/skills/...`
|
|
320
|
+
against (default: the real user home). Mirrors `WIN_NICE_HOME`, for the
|
|
321
|
+
skill files instead of `bin/`.
|
|
322
|
+
- `WIN_NICE_NO_PATH` — if set (to anything), `install`/`uninstall`/
|
|
323
|
+
`reinstall` skip the user `PATH` update/removal entirely, only managing
|
|
324
|
+
files under the install directory.
|
|
325
|
+
|
|
326
|
+
## Testing
|
|
327
|
+
|
|
328
|
+
```
|
|
329
|
+
npm test # installer logic (fast; isolated scratch registry key, cleaned up automatically)
|
|
330
|
+
powershell -Command "Invoke-Pester -Path test\win-nice.Tests.ps1" # real tool behavior
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Pin the Pester version before running the second command by hand: Windows
|
|
334
|
+
ships Pester 3.4.0 built in, but a system with a newer Pester also installed
|
|
335
|
+
(GitHub-hosted runners have both 3.4.0 and 5.x side by side) auto-loads the
|
|
336
|
+
newer one, and this suite uses Pester 3's legacy assertion syntax (`Should
|
|
337
|
+
Be`), which 5.x removed entirely. If bare `Invoke-Pester` fails immediately
|
|
338
|
+
on every `It`, import the right version first:
|
|
339
|
+
|
|
340
|
+
```
|
|
341
|
+
powershell -Command "Import-Module Pester -MaximumVersion 3.99; Invoke-Pester -Path test\win-nice.Tests.ps1"
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
(this is what CI/publish do; see `.github/workflows/ci.yml`.)
|
|
345
|
+
|
|
346
|
+
The Pester suite is an integration suite: it spawns real processes, checks
|
|
347
|
+
actual `PriorityClass`, `ProcessorAffinity`, and Job Object CPU throttling
|
|
348
|
+
across every tool, and takes roughly 1-2 minutes (more under system load - the
|
|
349
|
+
CPU-cap test retries a few times if the machine is too busy to get a clean
|
|
350
|
+
baseline). It never touches the real system `PATH`/registry; the installer
|
|
351
|
+
tests use `WIN_NICE_HOME` to redirect installs into a temp directory instead.
|
|
352
|
+
|
|
353
|
+
## License
|
|
354
|
+
|
|
355
|
+
Dual-licensed under [MIT](LICENSE-MIT) or [Apache License, Version 2.0](LICENSE-APACHE),
|
|
356
|
+
at your option.
|
package/bin/abovenormal
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# SPDX-License-Identifier: MIT OR Apache-2.0
|
|
3
|
+
# win-nice: managed-file
|
|
4
|
+
# Git Bash ignores PATHEXT for bare-name resolution; this shim covers that shell.
|
|
5
|
+
# MSYS2_ARG_CONV_EXCL='*' stops Git Bash/MSYS from rewriting user arguments
|
|
6
|
+
# (e.g. /c, /d, C:\...) into Windows paths before the exec; the shim's own
|
|
7
|
+
# .ps1 path is converted explicitly with cygpath -w so -File gets a Windows path.
|
|
8
|
+
MSYS2_ARG_CONV_EXCL='*'
|
|
9
|
+
export MSYS2_ARG_CONV_EXCL
|
|
10
|
+
script=$(cygpath -w "$(dirname "$0")/abovenormal.ps1" 2>/dev/null) || script="$(dirname "$0")/abovenormal.ps1"
|
|
11
|
+
exec powershell -NoProfile -ExecutionPolicy Bypass -File "$script" "$@"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
:: SPDX-License-Identifier: MIT OR Apache-2.0
|
|
3
|
+
:: win-nice: managed-file
|
|
4
|
+
if "%~1"=="" (
|
|
5
|
+
echo usage: abovenormal ^<command^> [args...] 1>&2
|
|
6
|
+
exit /b 1
|
|
7
|
+
)
|
|
8
|
+
:: A literal "%" in any argument gets corrupted here - see cap.bat for why (a
|
|
9
|
+
:: cmd.exe batch-parameter quirk, not fixable from inside a .bat). Every other
|
|
10
|
+
:: cmd.exe metacharacter (&|<>^) survives this hop untouched. Invoking
|
|
11
|
+
:: "abovenormal" bare from an actual PowerShell session skips this file
|
|
12
|
+
:: (abovenormal.ps1 preferred).
|
|
13
|
+
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0abovenormal.ps1" %*
|