@dsh-cc/plugin-dsh-cc-shunt 0.6.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/.claude-plugin/plugin.json +5 -0
- package/LICENSE +201 -0
- package/README.md +50 -0
- package/agents/shunt-reader.md +22 -0
- package/agents/shunt-writer.md +18 -0
- package/hooks/check-bash-read.mjs +113 -0
- package/hooks/check-file-size.mjs +104 -0
- package/hooks/hooks.json +26 -0
- package/package.json +22 -0
- package/skills/bulk-reader/SKILL.md +25 -0
- package/skills/code-writer/SKILL.md +24 -0
package/LICENSE
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/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# dsh-cc-shunt
|
|
2
|
+
|
|
3
|
+
Official dsh-cc plugin that keeps bulk file content out of the main context.
|
|
4
|
+
|
|
5
|
+
**How it works**: two hard PreToolUse gates (Read and Bash) block whole-file
|
|
6
|
+
reads of large files; the block message redirects to the `bulk-reader` /
|
|
7
|
+
`code-writer` skills, which delegate to the plugin's cheap-lane worker
|
|
8
|
+
subagents (`shunt-reader`, `shunt-writer`). The file corpus is read — or
|
|
9
|
+
written — by the worker; only a compact digest or a one-line confirmation
|
|
10
|
+
returns to the main context.
|
|
11
|
+
|
|
12
|
+
- `shunt-reader` — answers questions across large files / many files / big
|
|
13
|
+
diffs, returning a structured digest led by `file:line` references.
|
|
14
|
+
- `shunt-writer` — generates tests/config/stubs to disk matching a mandatory
|
|
15
|
+
reference file's patterns; never returns the generated code body.
|
|
16
|
+
|
|
17
|
+
## Install / enable
|
|
18
|
+
|
|
19
|
+
The `dsh-cc` marketplace ships this plugin. Enable it in settings.json:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"enabledPlugins": { "dsh-cc-shunt@dsh-cc": true }
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Configuration
|
|
28
|
+
|
|
29
|
+
Set via the top-level `"env"` object in settings.json:
|
|
30
|
+
|
|
31
|
+
| Variable | Default | Meaning |
|
|
32
|
+
| ------------------ | -------- | ------------------------------------------------------------------ |
|
|
33
|
+
| `SHUNT_MIN_LINES` | `350` | Line-count threshold; whole-file reads above it are blocked |
|
|
34
|
+
| `SHUNT_MAX_BYTES` | `100000` | Byte threshold; blocks minified/one-line files regardless of lines |
|
|
35
|
+
| `SHUNT_DISABLED` | unset | Set to `1`/`true`/`yes` to disable both gates entirely |
|
|
36
|
+
|
|
37
|
+
## Model alias requirement
|
|
38
|
+
|
|
39
|
+
**The shunt-worker agents pin `model: haiku`.** If your deployment's haiku
|
|
40
|
+
alias is unconfigured, the workers silently inherit the parent's model route
|
|
41
|
+
— everything works, but you get **zero token savings**. Configure the haiku
|
|
42
|
+
alias for actual savings.
|
|
43
|
+
|
|
44
|
+
## Known limits
|
|
45
|
+
|
|
46
|
+
- Digest line references can go stale after edits — verify with a targeted
|
|
47
|
+
offset/limit read before editing at a cited location.
|
|
48
|
+
- Nothing about debugging or architecture gets delegated — only bulk
|
|
49
|
+
reading and boilerplate generation.
|
|
50
|
+
- Worker calls are one-shot and foreground; follow-ups mean re-spawning.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: shunt-reader
|
|
3
|
+
description: Cheap-lane bulk code analyst. Delegation target when a question spans files over the shunt threshold (~350 lines), 3+ files, or a large diff — it reads them so the caller's context stays clean, and returns a compact structured digest. Official dsh-cc-shunt plugin build; spawns on the haiku alias when the deployment configures it.
|
|
4
|
+
model: haiku
|
|
5
|
+
tools: [Read, Grep, Glob]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
You are a precise code analyst working in the cheap lane. You are spawned to read files so the caller's context stays clean.
|
|
9
|
+
|
|
10
|
+
## STRICT pagination rule
|
|
11
|
+
Never read a whole file. Use Read with offset+limit windows of ≤300 lines, and Grep for navigation (locating symbols, imports, definitions before reading around them). Targeted reads always pass the host's shunt gate; a bare full-file read gets blocked.
|
|
12
|
+
|
|
13
|
+
## How to work
|
|
14
|
+
- Read only what the question needs: Grep to locate, then paginate small windows around the hits.
|
|
15
|
+
- Each spawn is one-shot — there are no follow-ups. If the question needs more files, the caller re-spawns with the same paths.
|
|
16
|
+
|
|
17
|
+
## Output contract (always)
|
|
18
|
+
- Structured bullets only; no greetings, prose, or preamble.
|
|
19
|
+
- Lead every bullet with the exact symbol/type name or `file:line`.
|
|
20
|
+
- Nest details under the bullet they belong to.
|
|
21
|
+
- Never paste whole files or long verbatim spans — cite `file:line` instead.
|
|
22
|
+
- Answer only what was asked.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: shunt-writer
|
|
3
|
+
description: Cheap-lane boilerplate generator — writes tests/config/stubs to disk matching a mandatory reference file's patterns; returns only a one-line confirmation. Official dsh-cc-shunt plugin build; spawns on the haiku alias when configured.
|
|
4
|
+
model: haiku
|
|
5
|
+
tools: [Read, Grep, Glob, Write]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
You are a boilerplate generator working in the cheap lane. You receive a spec, a reference file (mandatory), and a target path.
|
|
9
|
+
|
|
10
|
+
## How to work
|
|
11
|
+
- Read the reference file paginated (offset+limit windows of ≤300 lines, Grep for navigation) and match its patterns, conventions, naming, and style exactly.
|
|
12
|
+
- If the spec is ambiguous, pick the option most consistent with the reference.
|
|
13
|
+
- Generate the output with NO explanations and no markdown fences.
|
|
14
|
+
- Write it to the target path with the Write tool.
|
|
15
|
+
|
|
16
|
+
## Output contract (always)
|
|
17
|
+
Return ONLY one line: `<path> — <N> lines written`.
|
|
18
|
+
Never return the generated code body — the caller must not receive generated code in context.
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* check-bash-read.mjs — shunt PreToolUse gate for the Bash tool.
|
|
4
|
+
*
|
|
5
|
+
* Blocks cat/head/tail/less/more commands that read large files into
|
|
6
|
+
* context and redirects to the bulk-reader skill. Piped and redirected
|
|
7
|
+
* commands are targeted operations and always pass. Port of the upstream
|
|
8
|
+
* shunt bash+jq hook as a dependency-free Node script.
|
|
9
|
+
*
|
|
10
|
+
* Upstream-eval-pinned behavior: leading flags are stripped (cat -n,
|
|
11
|
+
* head -100), so ONLY the file's own size decides — `head -100 bigfile`
|
|
12
|
+
* is blocked like a plain cat.
|
|
13
|
+
*/
|
|
14
|
+
import { existsSync, readFileSync, statSync } from 'node:fs'
|
|
15
|
+
import { resolve } from 'node:path'
|
|
16
|
+
|
|
17
|
+
const DEFAULT_MIN_LINES = 350
|
|
18
|
+
const DEFAULT_MAX_BYTES = 100000
|
|
19
|
+
const READ_COMMAND_RE = /^(cat|head|tail|less|more)\s+/
|
|
20
|
+
|
|
21
|
+
function truthy(v) {
|
|
22
|
+
return ['1', 'true', 'yes'].includes(String(v ?? '').trim().toLowerCase())
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function intEnv(name, fallback) {
|
|
26
|
+
const raw = process.env[name]
|
|
27
|
+
if (raw === undefined || raw.trim() === '') return fallback
|
|
28
|
+
const n = Number(raw)
|
|
29
|
+
return Number.isFinite(n) ? n : fallback
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function countLines(text) {
|
|
33
|
+
let n = 0
|
|
34
|
+
for (const ch of text) if (ch === '\n') n++
|
|
35
|
+
return n
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function allow() {
|
|
39
|
+
process.stdout.write(JSON.stringify({ decision: 'allow' }) + '\n')
|
|
40
|
+
process.exit(0)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function block(reason) {
|
|
44
|
+
process.stdout.write(JSON.stringify({ decision: 'block', reason }) + '\n')
|
|
45
|
+
process.exit(0)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let input = ''
|
|
49
|
+
process.stdin.setEncoding('utf8')
|
|
50
|
+
for await (const chunk of process.stdin) input += chunk
|
|
51
|
+
|
|
52
|
+
let payload = {}
|
|
53
|
+
try {
|
|
54
|
+
payload = JSON.parse(input)
|
|
55
|
+
} catch {
|
|
56
|
+
allow()
|
|
57
|
+
}
|
|
58
|
+
const command = typeof payload.tool_input?.command === 'string' ? payload.tool_input.command : ''
|
|
59
|
+
|
|
60
|
+
// Kill switch.
|
|
61
|
+
if (truthy(process.env.SHUNT_DISABLED)) allow()
|
|
62
|
+
|
|
63
|
+
// No command, or a targeted (piped / redirected) command.
|
|
64
|
+
if (!command || command.includes('|') || command.includes('>') || !READ_COMMAND_RE.test(command)) allow()
|
|
65
|
+
|
|
66
|
+
// Strip the command name, then strip flags and quotes; first non-flag arg is the path.
|
|
67
|
+
const args = command.slice(command.match(READ_COMMAND_RE)[1].length).trim().split(/\s+/)
|
|
68
|
+
let filePath = ''
|
|
69
|
+
for (const arg of args) {
|
|
70
|
+
if (arg.startsWith('-')) continue
|
|
71
|
+
filePath = arg.replace(/^["']|["']$/g, '')
|
|
72
|
+
break
|
|
73
|
+
}
|
|
74
|
+
if (!filePath) allow()
|
|
75
|
+
|
|
76
|
+
// Hooks run in the session workspace.
|
|
77
|
+
const abs = resolve(process.cwd(), filePath)
|
|
78
|
+
if (!existsSync(abs)) allow()
|
|
79
|
+
|
|
80
|
+
let stat
|
|
81
|
+
try {
|
|
82
|
+
stat = statSync(abs)
|
|
83
|
+
} catch {
|
|
84
|
+
allow()
|
|
85
|
+
}
|
|
86
|
+
if (!stat.isFile()) allow()
|
|
87
|
+
|
|
88
|
+
const minLines = intEnv('SHUNT_MIN_LINES', DEFAULT_MIN_LINES)
|
|
89
|
+
const maxBytes = intEnv('SHUNT_MAX_BYTES', DEFAULT_MAX_BYTES)
|
|
90
|
+
|
|
91
|
+
// Byte fallback: catch minified / one-line files.
|
|
92
|
+
if (stat.size > maxBytes) {
|
|
93
|
+
block(
|
|
94
|
+
`File is ~${Math.round(stat.size / 1024)} KB, over the shunt byte threshold (${maxBytes} bytes). ` +
|
|
95
|
+
`To understand it, delegate via the "bulk-reader" skill instead of reading it into your context. ` +
|
|
96
|
+
`Piping to grep/head (e.g. cat file | grep pattern) is the targeted alternative — targeted reads always pass.`,
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let lines = 0
|
|
101
|
+
try {
|
|
102
|
+
lines = countLines(readFileSync(abs, 'utf8'))
|
|
103
|
+
} catch {
|
|
104
|
+
allow()
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (lines <= minLines) allow()
|
|
108
|
+
|
|
109
|
+
block(
|
|
110
|
+
`File is ${lines} lines (~${Math.max(1, Math.round(stat.size / 1024))} KB), over the shunt threshold (${minLines} lines / ${maxBytes} bytes). ` +
|
|
111
|
+
`To understand it, delegate via the "bulk-reader" skill instead of reading it into your context. ` +
|
|
112
|
+
`Piping to grep/head (e.g. cat file | grep pattern) is the targeted alternative — targeted reads always pass.`,
|
|
113
|
+
)
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* check-file-size.mjs — shunt PreToolUse gate for the Read tool.
|
|
4
|
+
*
|
|
5
|
+
* Blocks whole-file reads of large files and redirects to the bulk-reader
|
|
6
|
+
* skill (cheap-lane subagent delegation), keeping bulk file content out of
|
|
7
|
+
* the main context. Port of the upstream shunt bash+jq hook as a
|
|
8
|
+
* dependency-free Node script.
|
|
9
|
+
*
|
|
10
|
+
* Allow contract: {"decision": "allow"} on stdout, exit 0.
|
|
11
|
+
* Block contract: one-line {"decision": "block", "reason": "..."} on stdout, exit 0.
|
|
12
|
+
*/
|
|
13
|
+
import { existsSync, readFileSync, statSync } from 'node:fs'
|
|
14
|
+
|
|
15
|
+
const DEFAULT_MIN_LINES = 350
|
|
16
|
+
const DEFAULT_MAX_BYTES = 100000
|
|
17
|
+
|
|
18
|
+
function truthy(v) {
|
|
19
|
+
return ['1', 'true', 'yes'].includes(String(v ?? '').trim().toLowerCase())
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function intEnv(name, fallback) {
|
|
23
|
+
const raw = process.env[name]
|
|
24
|
+
if (raw === undefined || raw.trim() === '') return fallback
|
|
25
|
+
const n = Number(raw)
|
|
26
|
+
return Number.isFinite(n) ? n : fallback
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function countLines(text) {
|
|
30
|
+
// Count like `wc -l`: number of '\n' bytes.
|
|
31
|
+
let n = 0
|
|
32
|
+
for (const ch of text) if (ch === '\n') n++
|
|
33
|
+
return n
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function allow() {
|
|
37
|
+
process.stdout.write(JSON.stringify({ decision: 'allow' }) + '\n')
|
|
38
|
+
process.exit(0)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function block(reason) {
|
|
42
|
+
process.stdout.write(JSON.stringify({ decision: 'block', reason }) + '\n')
|
|
43
|
+
process.exit(0)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let input = ''
|
|
47
|
+
process.stdin.setEncoding('utf8')
|
|
48
|
+
for await (const chunk of process.stdin) input += chunk
|
|
49
|
+
|
|
50
|
+
let payload = {}
|
|
51
|
+
try {
|
|
52
|
+
payload = JSON.parse(input)
|
|
53
|
+
} catch {
|
|
54
|
+
allow()
|
|
55
|
+
}
|
|
56
|
+
const toolInput = payload.tool_input ?? {}
|
|
57
|
+
const filePath = typeof toolInput.file_path === 'string' ? toolInput.file_path : ''
|
|
58
|
+
const offset = toolInput.offset
|
|
59
|
+
const limit = toolInput.limit
|
|
60
|
+
|
|
61
|
+
// Kill switch.
|
|
62
|
+
if (truthy(process.env.SHUNT_DISABLED)) allow()
|
|
63
|
+
|
|
64
|
+
// Targeted reads always pass — the caller already knows what it needs.
|
|
65
|
+
if (offset !== undefined || limit !== undefined) allow()
|
|
66
|
+
|
|
67
|
+
// No path / nonexistent file: let Read handle it.
|
|
68
|
+
if (!filePath || !existsSync(filePath)) allow()
|
|
69
|
+
|
|
70
|
+
let stat
|
|
71
|
+
try {
|
|
72
|
+
stat = statSync(filePath)
|
|
73
|
+
} catch {
|
|
74
|
+
allow()
|
|
75
|
+
}
|
|
76
|
+
if (!stat.isFile()) allow()
|
|
77
|
+
|
|
78
|
+
const minLines = intEnv('SHUNT_MIN_LINES', DEFAULT_MIN_LINES)
|
|
79
|
+
const maxBytes = intEnv('SHUNT_MAX_BYTES', DEFAULT_MAX_BYTES)
|
|
80
|
+
|
|
81
|
+
// Byte fallback: catch minified / one-line files whose line count is tiny.
|
|
82
|
+
if (stat.size > maxBytes) {
|
|
83
|
+
block(
|
|
84
|
+
`File is ~${Math.round(stat.size / 1024)} KB, over the shunt byte threshold (${maxBytes} bytes). ` +
|
|
85
|
+
`To understand it, delegate via the "bulk-reader" skill instead of reading it into your context. ` +
|
|
86
|
+
`For exact content to edit a specific section, re-read just that range with offset/limit — targeted reads always pass.`,
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let text = ''
|
|
91
|
+
try {
|
|
92
|
+
text = readFileSync(filePath, 'utf8')
|
|
93
|
+
} catch {
|
|
94
|
+
allow()
|
|
95
|
+
}
|
|
96
|
+
const lines = countLines(text)
|
|
97
|
+
|
|
98
|
+
if (lines <= minLines) allow()
|
|
99
|
+
|
|
100
|
+
block(
|
|
101
|
+
`File is ${lines} lines (~${Math.max(1, Math.round(stat.size / 1024))} KB), over the shunt threshold (${minLines} lines / ${maxBytes} bytes). ` +
|
|
102
|
+
`To understand it, delegate via the "bulk-reader" skill instead of reading it into your context. ` +
|
|
103
|
+
`For exact content to edit a specific section, re-read just that range with offset/limit — targeted reads always pass.`,
|
|
104
|
+
)
|
package/hooks/hooks.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"PreToolUse": [
|
|
4
|
+
{
|
|
5
|
+
"matcher": "Read",
|
|
6
|
+
"hooks": [
|
|
7
|
+
{
|
|
8
|
+
"type": "command",
|
|
9
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/check-file-size.mjs\"",
|
|
10
|
+
"timeout": 5
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"matcher": "Bash",
|
|
16
|
+
"hooks": [
|
|
17
|
+
{
|
|
18
|
+
"type": "command",
|
|
19
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/check-bash-read.mjs\"",
|
|
20
|
+
"timeout": 5
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dsh-cc/plugin-dsh-cc-shunt",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Official dsh-cc plugin: hard PreToolUse gates redirect bulk reads and boilerplate generation to cheap-lane shunt-worker subagents to save main-context tokens.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"files": [
|
|
8
|
+
".claude-plugin/plugin.json",
|
|
9
|
+
"agents",
|
|
10
|
+
"hooks",
|
|
11
|
+
"skills",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/dsh-cc/dsh-cc.git",
|
|
20
|
+
"directory": "packages/plugin/dsh-cc-shunt"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: bulk-reader
|
|
3
|
+
description: Delegate bulk file reading to a cheap-lane worker subagent. Use when you need to read files >350 lines, answer a question across 3+ files, or summarize a large diff.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Delegate bulk reading to the shunt-reader worker. The files' content never
|
|
7
|
+
enters your context — only its digest does.
|
|
8
|
+
|
|
9
|
+
Call the subagent_fork/Task tool with `subagent_type: "dsh-cc-shunt:shunt-reader"`
|
|
10
|
+
FOREGROUND (omit `run_in_background`), passing a prompt that lists the exact
|
|
11
|
+
file paths and the question:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
Question: <question>
|
|
15
|
+
Files:
|
|
16
|
+
- <path1>
|
|
17
|
+
- <path2>
|
|
18
|
+
Read them (paginated) and return the digest.
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- Each call is one-shot: to follow up, spawn again with the same paths.
|
|
22
|
+
- The files go to the worker, never your context. Do not re-read delegated
|
|
23
|
+
files yourself.
|
|
24
|
+
- Before editing code at a cited location, verify the specific line numbers
|
|
25
|
+
with a targeted offset/limit read.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: code-writer
|
|
3
|
+
description: Delegate boilerplate code generation to a cheap-lane worker subagent. Use for tests, config stubs, type stubs, docstrings, or any generation where >80% is predictable from an existing reference file.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Delegate boilerplate generation to the shunt-writer worker. The generated
|
|
7
|
+
code never enters your context — the worker writes it to disk and returns
|
|
8
|
+
only a one-line confirmation.
|
|
9
|
+
|
|
10
|
+
Call the subagent_fork/Task tool with `subagent_type: "dsh-cc-shunt:shunt-writer"`
|
|
11
|
+
FOREGROUND (omit `run_in_background`):
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
Spec: <what to generate>
|
|
15
|
+
Reference: <reference-file-path> (mandatory — match its patterns)
|
|
16
|
+
Target: <output-path>
|
|
17
|
+
Write the output to Target and reply with only the one-line confirmation.
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
- A reference file is always required. Without one the worker generates
|
|
21
|
+
context-free code.
|
|
22
|
+
- Follow-ups: pass the previously generated file as the new reference.
|
|
23
|
+
- After it returns, review the target with targeted reads and apply the
|
|
24
|
+
~5–20% needing judgment as surgical edits yourself.
|