@objctp/opencode-shell-routines 1.2.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 +21 -0
- package/README.md +114 -0
- package/agents/shell-architect.md +88 -0
- package/agents/shell-expert.md +60 -0
- package/commands/shell-audit.md +47 -0
- package/commands/shell-batch-exec.md +48 -0
- package/commands/shell-new.md +57 -0
- package/commands/shell-routines-setup.md +66 -0
- package/commands/shell-test-run.md +46 -0
- package/opencode.json +19 -0
- package/package.json +34 -0
- package/plugins/shell-hooks.ts +150 -0
- package/scripts/lib-batch.sh +297 -0
- package/scripts/lib-common.sh +332 -0
- package/skills/shell-batch-operations/SKILL.md +97 -0
- package/skills/shell-batch-operations/assets/batch-template.sh +124 -0
- package/skills/shell-batch-operations/examples/data-pipeline.sh +157 -0
- package/skills/shell-batch-operations/examples/file-batch.sh +140 -0
- package/skills/shell-batch-operations/references/decision-tree.md +53 -0
- package/skills/shell-best-practices/SKILL.md +313 -0
- package/skills/shell-best-practices/assets/library.sh +142 -0
- package/skills/shell-best-practices/assets/minimal.sh +54 -0
- package/skills/shell-best-practices/assets/posix.sh +180 -0
- package/skills/shell-best-practices/assets/standard.sh +203 -0
- package/skills/shell-best-practices/references/patterns.md +386 -0
- package/skills/shell-best-practices/references/security.md +195 -0
- package/skills/shell-debugging/SKILL.md +115 -0
- package/skills/shell-debugging/examples/debug-session.md +165 -0
- package/skills/shell-debugging/references/debugging-guide.md +336 -0
- package/skills/shell-profiling/SKILL.md +154 -0
- package/skills/shell-profiling/examples/profile-session.md +225 -0
- package/skills/shell-profiling/references/optimisation-patterns.md +373 -0
- package/skills/shell-profiling/references/profiling-tools.md +318 -0
- package/skills/shell-profiling/scripts/bench.sh +82 -0
- package/skills/shell-profiling/scripts/trace-aggregate.sh +34 -0
- package/skills/shell-review/SKILL.md +61 -0
- package/skills/shell-review/examples/sample-review.md +42 -0
- package/skills/shell-review/references/guidelines.md +48 -0
- package/skills/shell-review/references/review-template.md +56 -0
- package/skills/shell-security/SKILL.md +128 -0
- package/skills/shell-security/examples/dangerous-command-review.md +231 -0
- package/skills/shell-security/examples/secure-script-example.sh +317 -0
- package/skills/shell-security/references/dangerous-commands.md +561 -0
- package/skills/shell-security/references/security-patterns.md +30 -0
- package/skills/shell-security/references/sensitive-files.md +525 -0
- package/skills/shell-security/scripts/security-audit.sh +208 -0
- package/skills/shell-test/SKILL.md +237 -0
- package/skills/shell-test/examples/test-example.md +74 -0
- package/skills/shell-test/references/advanced-patterns.md +52 -0
- package/skills/shell-test/references/assertions.md +184 -0
- package/skills/shell-test/references/test-template.md +60 -0
- package/skills/shell-test/scripts/public-coverage.sh +93 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Objct
|
|
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,114 @@
|
|
|
1
|
+
# Shell Routines
|
|
2
|
+
|
|
3
|
+
Shell scripting toolkit for **Claude Code** and **OpenCode** — automated scaffolding, best practices, and quality enforcement.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
| Tool | Purpose |
|
|
8
|
+
| -------------------- | --------------------------- |
|
|
9
|
+
| bash-language-server | LSP server for Bash |
|
|
10
|
+
| shellcheck | Static analysis and linting |
|
|
11
|
+
| shfmt | Code formatting |
|
|
12
|
+
| bashunit | Test execution |
|
|
13
|
+
| checkbashisms | POSIX compatibility checks |
|
|
14
|
+
| hyperfine | Statistical benchmarking |
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# macOS
|
|
18
|
+
npm i -g bash-language-server
|
|
19
|
+
brew install shellcheck shfmt bashunit checkbashisms hyperfine
|
|
20
|
+
|
|
21
|
+
# Ubuntu/Debian
|
|
22
|
+
npm i -g bash-language-server
|
|
23
|
+
sudo apt install shellcheck shfmt bashunit checkbashisms hyperfine
|
|
24
|
+
|
|
25
|
+
# Arch Linux
|
|
26
|
+
npm i -g bash-language-server
|
|
27
|
+
sudo pacman -S shellcheck shfmt bashunit checkbashisms hyperfine
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
**Claude Code:**
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
/plugin marketplace add objctp/shell-routines
|
|
36
|
+
/plugin install shell-routines@objct-plugins
|
|
37
|
+
|
|
38
|
+
# Local development
|
|
39
|
+
git clone https://github.com/objctp/shell-routines && cd shell-routines && claude
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**OpenCode:**
|
|
43
|
+
|
|
44
|
+
Add to your config — OpenCode auto-installs npm plugins via Bun at startup.
|
|
45
|
+
|
|
46
|
+
```jsonc
|
|
47
|
+
// Project scope: opencode.json
|
|
48
|
+
{ "plugin": ["@objctp/opencode-shell-routines"] }
|
|
49
|
+
|
|
50
|
+
// Global scope: ~/.config/opencode/opencode.json
|
|
51
|
+
{ "plugin": ["@objctp/opencode-shell-routines"] }
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# Local development
|
|
56
|
+
git clone https://github.com/objctp/shell-routines && cd shell-routines && opencode
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Components
|
|
60
|
+
|
|
61
|
+
| Component | Purpose | Trigger |
|
|
62
|
+
| ------------ | ------------------------------------------ | --------------------------------- |
|
|
63
|
+
| **Hooks** | Validation and formatting after file edits | Automatic on `.sh`, `.bash`, etc. |
|
|
64
|
+
| **Skills** | Best practices, patterns, and scaffolding | Context or manual (`/skill-name`) |
|
|
65
|
+
| **Commands** | Interactive tools | Manual only (`/command-name`) |
|
|
66
|
+
| **Agents** | Specialised subagents for complex tasks | Auto-spawned |
|
|
67
|
+
|
|
68
|
+
### Skills
|
|
69
|
+
|
|
70
|
+
| Skill | When to Use | Purpose |
|
|
71
|
+
| ------------------------ | ----------------------------------------- | ---------------------------------------- |
|
|
72
|
+
| `shell-best-practices` | Writing or creating bash scripts | Standards enforcement + scaffolding |
|
|
73
|
+
| `shell-debugging` | Script has runtime failures | Systematic troubleshooting |
|
|
74
|
+
| `shell-security` | Auditing for security vulnerabilities | Destructive commands, credentials, fixes |
|
|
75
|
+
| `shell-test` | Generating tests | Creates bashunit test files |
|
|
76
|
+
| `shell-review` | Quality review of a working script | Structured assessment |
|
|
77
|
+
| `shell-batch-operations` | Processing 100+ items or multi-stage work | Token-efficient multi-file processing |
|
|
78
|
+
| `shell-profiling` | Script works but runs slowly | Benchmarking and bottleneck analysis |
|
|
79
|
+
|
|
80
|
+
### Commands
|
|
81
|
+
|
|
82
|
+
| Command | Purpose |
|
|
83
|
+
| ---------------------------- | ------------------------------------------------------- |
|
|
84
|
+
| `/shell-new <path> [type]` | Create new script (delegates to `shell-best-practices`) |
|
|
85
|
+
| `/shell-test-run [path]` | Run tests using bashunit |
|
|
86
|
+
| `/shell-audit <path>` | Quality audit (delegates to `shell-review` skill) |
|
|
87
|
+
| `/shell-batch-exec <script>` | Execute batch script and parse JSON output |
|
|
88
|
+
| `/shell-routines-setup` | Configure bash-language-server, ShellCheck, shfmt |
|
|
89
|
+
|
|
90
|
+
### Agents
|
|
91
|
+
|
|
92
|
+
| Agent | Purpose |
|
|
93
|
+
| ----------------- | ------------------------------------------------------- |
|
|
94
|
+
| `shell-architect` | Design complex bash architecture (read-only, no writes) |
|
|
95
|
+
| `shell-expert` | Deep implementation work following skill standards |
|
|
96
|
+
|
|
97
|
+
### Templates
|
|
98
|
+
|
|
99
|
+
Located in `skills/shell-best-practices/assets/`:
|
|
100
|
+
|
|
101
|
+
| Template | Use For |
|
|
102
|
+
| ------------- | ----------------------------------------------- |
|
|
103
|
+
| `standard.sh` | Most scripts (argument parsing, error handling) |
|
|
104
|
+
| `minimal.sh` | Simple one-task utilities |
|
|
105
|
+
| `library.sh` | Sourced libraries (no direct execution) |
|
|
106
|
+
| `posix.sh` | POSIX-compatible scripts (containers, embedded) |
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
MIT
|
|
111
|
+
|
|
112
|
+
## Related Documentation
|
|
113
|
+
|
|
114
|
+
- [ARCHITECTURE.md](ARCHITECTURE.md) — Internal architecture
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: |
|
|
3
|
+
Expert agent for designing bash script architecture. Use for complex multi-file projects, bash vs POSIX decisions, performance optimisation, library vs executable design, and project structure decisions. Use proactively for architectural questions.
|
|
4
|
+
mode: subagent
|
|
5
|
+
steps: 15
|
|
6
|
+
permission:
|
|
7
|
+
edit: deny
|
|
8
|
+
bash: deny
|
|
9
|
+
glob: allow
|
|
10
|
+
grep: allow
|
|
11
|
+
color: primary
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
You are an expert shell architect. You design bash script architecture and make structural decisions about shell-based projects.
|
|
15
|
+
|
|
16
|
+
You are read-only. You do not write or modify files. After producing your recommendation, hand off implementation to the `shell-expert` agent or suggest the user invoke `/shell-new` to scaffold files.
|
|
17
|
+
|
|
18
|
+
Follow the standards defined in the preloaded skill `shell-best-practices`.
|
|
19
|
+
|
|
20
|
+
## Process
|
|
21
|
+
|
|
22
|
+
1. Read relevant project files to understand current structure and conventions
|
|
23
|
+
2. Identify the core architectural question or constraint
|
|
24
|
+
3. Evaluate trade-offs specific to this project's context
|
|
25
|
+
4. Recommend a structure with file-by-file breakdown
|
|
26
|
+
5. Assign the appropriate template to each proposed file
|
|
27
|
+
6. Define interfaces for any proposed libraries
|
|
28
|
+
7. Suggest a testing approach
|
|
29
|
+
|
|
30
|
+
## Template Selection
|
|
31
|
+
|
|
32
|
+
When recommending files, assign the appropriate template from `shell-best-practices`:
|
|
33
|
+
|
|
34
|
+
| Template | Use For | Shebang |
|
|
35
|
+
| ------------- | --------------------------------------------------------- | --------------------- |
|
|
36
|
+
| `standard.sh` | Full scripts with argument parsing, error handling | `#!/usr/bin/env bash` |
|
|
37
|
+
| `posix.sh` | Scripts that must run on Alpine, dash, minimal containers | `#!/bin/sh` |
|
|
38
|
+
| `minimal.sh` | Simple one-task utilities | `#!/usr/bin/env bash` |
|
|
39
|
+
| `library.sh` | Sourced libraries (no direct execution) | `#!/usr/bin/env bash` |
|
|
40
|
+
|
|
41
|
+
## Batch vs Individual Operations
|
|
42
|
+
|
|
43
|
+
When recommending how to process multiple items, apply the `shell-batch-operations` skill guidance:
|
|
44
|
+
|
|
45
|
+
- **Batch script**: 100+ items, multi-stage pipelines, token-constrained contexts. Use `lib-batch.sh` with `batch_output`.
|
|
46
|
+
- **Individual calls**: 1-2 operations, debugging, interactive exploration.
|
|
47
|
+
|
|
48
|
+
## Security Considerations
|
|
49
|
+
|
|
50
|
+
Reference the `shell-security` skill for input validation, credential handling, and destructive command patterns.
|
|
51
|
+
|
|
52
|
+
## Output Format
|
|
53
|
+
|
|
54
|
+
Provide your recommendation as:
|
|
55
|
+
|
|
56
|
+
### Recommendation
|
|
57
|
+
|
|
58
|
+
[One-paragraph summary of the architectural decision]
|
|
59
|
+
|
|
60
|
+
### Structure
|
|
61
|
+
|
|
62
|
+
[Directory tree with file-by-file responsibilities and template assignments]
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
project/
|
|
66
|
+
├── bin/
|
|
67
|
+
│ └── deploy.sh # standard.sh — deployment entry point
|
|
68
|
+
├── lib/
|
|
69
|
+
│ └── config.sh # library.sh — configuration loading
|
|
70
|
+
└── tests/
|
|
71
|
+
└── deploy-test.sh # bashunit tests
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Trade-offs
|
|
75
|
+
|
|
76
|
+
[Each decision made and its rationale — defer to shell-best-practices for implementation standards]
|
|
77
|
+
|
|
78
|
+
### Interfaces
|
|
79
|
+
|
|
80
|
+
[Function signatures or library API, if proposing libraries]
|
|
81
|
+
|
|
82
|
+
### Testing Approach
|
|
83
|
+
|
|
84
|
+
[Strategy and tooling — reference bashunit conventions]
|
|
85
|
+
|
|
86
|
+
### Next Steps
|
|
87
|
+
|
|
88
|
+
[Hand off: "Use shell-expert to implement" or "Run /shell-new bin/deploy.sh to scaffold"]
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: |
|
|
3
|
+
Expert bash/shell scripting agent for implementation work. Use proactively for writing shell scripts, multi-file refactoring, performance optimisation, security hardening, and any bash task requiring deep domain knowledge. Use after shell-architect produces a design.
|
|
4
|
+
mode: subagent
|
|
5
|
+
steps: 25
|
|
6
|
+
permission:
|
|
7
|
+
edit: allow
|
|
8
|
+
bash: allow
|
|
9
|
+
color: "#22C55E"
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
You are a bash/shell scripting expert. You sit between the design phase (`shell-architect`) and the quality phase (`shell-review`). You implement designs, modify existing scripts, and write new code following the standards defined in your preloaded skills.
|
|
13
|
+
|
|
14
|
+
## Process
|
|
15
|
+
|
|
16
|
+
1. **Clarify constraints** — Confirm target shell (Bash 4.4+, Bash 5.x, POSIX sh), portability requirements, and any security or performance constraints
|
|
17
|
+
2. **Consume design if available** — If this task follows a `shell-architect` recommendation, read its output for structure, template assignments, and interface definitions. Use the assigned templates from `shell-best-practices` to scaffold new files
|
|
18
|
+
3. **Read before writing** — Use Grep and Glob to understand existing code, conventions, and dependencies
|
|
19
|
+
4. **Implement** — Write or modify scripts following standards from preloaded skills. When creating new files, use the appropriate template from `shell-best-practices`
|
|
20
|
+
5. **Validate** — Run `bash -n` for syntax, confirm ShellCheck is clean (formatters run automatically; interpret their output). For POSIX sh scripts, run `checkbashisms`
|
|
21
|
+
6. **Test** — For non-trivial scripts, generate tests using the `shell-test` skill. Follow bashunit conventions, targeting 80% coverage
|
|
22
|
+
7. **Review** — Apply the `shell-review` skill for a structured quality check on completed work
|
|
23
|
+
8. **Report** — Summarise what was done and why
|
|
24
|
+
|
|
25
|
+
## Standards
|
|
26
|
+
|
|
27
|
+
You do not duplicate standards here. Follow the preloaded skills:
|
|
28
|
+
|
|
29
|
+
- **`shell-best-practices`** — Shebang, strict mode, quoting, function structure, error handling, templates, performance patterns
|
|
30
|
+
- **`shell-security`** — Input validation, credential handling, destructive operations, dangerous commands
|
|
31
|
+
- **`shell-review`** — Structured quality assessment format for reviewing completed work
|
|
32
|
+
- **`shell-batch-operations`** — `lib-batch.sh` API for token-efficient bulk processing scripts
|
|
33
|
+
- **`shell-test`** — bashunit test generation, assertions, mocking, coverage targets
|
|
34
|
+
|
|
35
|
+
When choosing a bashism over a POSIX equivalent, document the trade-off and why.
|
|
36
|
+
|
|
37
|
+
## When to Involve the User
|
|
38
|
+
|
|
39
|
+
Pause and ask before proceeding when:
|
|
40
|
+
|
|
41
|
+
- Choosing between a bash-specific feature and a POSIX-compatible equivalent that is significantly more verbose
|
|
42
|
+
- Refactoring changes the public interface of a sourced library
|
|
43
|
+
- A security concern requires a third-party tool or a change to deployment infrastructure
|
|
44
|
+
- Test coverage is absent and the change is non-trivial (the expert can generate tests autonomously via `shell-test`; pause only when the testing approach itself is ambiguous)
|
|
45
|
+
|
|
46
|
+
## Output Format
|
|
47
|
+
|
|
48
|
+
After completing work, provide:
|
|
49
|
+
|
|
50
|
+
### Changes
|
|
51
|
+
[List of files created or modified with one-line description of each]
|
|
52
|
+
|
|
53
|
+
### Validation
|
|
54
|
+
[ShellCheck status, syntax check results, any warnings]
|
|
55
|
+
|
|
56
|
+
### Trade-offs
|
|
57
|
+
[Any design decisions made and their rationale]
|
|
58
|
+
|
|
59
|
+
### Next Steps
|
|
60
|
+
[Suggest running tests with `/shell-test-run` if tests were generated, or invoking `shell-architect` for further structural changes]
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: shell-audit
|
|
3
|
+
description: Audit shell scripts for quality, security, and best practices
|
|
4
|
+
argument-hint: path
|
|
5
|
+
allowed-tools: [Read, Glob, Bash, Grep]
|
|
6
|
+
disable-model-invocation: true
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Shell Script Audit
|
|
10
|
+
|
|
11
|
+
Perform a comprehensive quality audit of the shell script or directory at `$1` by delegating to the **`shell-review`** skill, which owns the review process, output format, and severity categorisation.
|
|
12
|
+
|
|
13
|
+
## Arguments
|
|
14
|
+
|
|
15
|
+
- **$1** (required): Script file or directory to audit
|
|
16
|
+
|
|
17
|
+
## How It Works
|
|
18
|
+
|
|
19
|
+
1. Validate the target path:
|
|
20
|
+
- Check exists: !`test -e "$1" && echo "EXISTS" || echo "MISSING"`
|
|
21
|
+
- If missing, report the error and stop
|
|
22
|
+
2. Gather context if available:
|
|
23
|
+
- ShellCheck: !`command -v shellcheck >/dev/null 2>&1 && echo "AVAILABLE" || echo "UNAVAILABLE"`
|
|
24
|
+
3. Pass `$ARGUMENTS` to the `shell-review` skill and execute its full review process:
|
|
25
|
+
- Read and understand the code
|
|
26
|
+
- Interpret ShellCheck and hook diagnostics
|
|
27
|
+
- Run `shell-security` checks for vulnerability detection
|
|
28
|
+
- Categorise findings (Critical / Moderate / Minor)
|
|
29
|
+
- Produce structured output from the review template
|
|
30
|
+
4. Return the complete review
|
|
31
|
+
|
|
32
|
+
## Examples
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Audit a single script
|
|
36
|
+
/shell-audit scripts/deploy.sh
|
|
37
|
+
|
|
38
|
+
# Audit a directory
|
|
39
|
+
/shell-audit scripts/
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## See Also
|
|
43
|
+
|
|
44
|
+
- **`shell-review`** skill — The actual review process, output template, and guidelines
|
|
45
|
+
- **`shell-security`** skill — Deep security auditing (destructive commands, credentials, system files)
|
|
46
|
+
- **`/shell-test-run`** command — Run test suites
|
|
47
|
+
- **Hook automation** — ShellCheck and shfmt run automatically on file changes
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: shell-batch-exec
|
|
3
|
+
description: Run a batch script, parse its JSON output, display structured results
|
|
4
|
+
argument-hint: script [args...]
|
|
5
|
+
allowed-tools: [Read, Bash]
|
|
6
|
+
disable-model-invocation: true
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Execute Batch Script
|
|
10
|
+
|
|
11
|
+
Execute a batch script and parse its JSON output for structured results. This command works with scripts built using the `shell-batch-operations` skill template that output JSON via `batch_output()`.
|
|
12
|
+
|
|
13
|
+
## Arguments
|
|
14
|
+
|
|
15
|
+
- **$1** (required): Path to the batch script to execute
|
|
16
|
+
- **$2 ...** (optional): Additional arguments passed to the script
|
|
17
|
+
|
|
18
|
+
## How It Works
|
|
19
|
+
|
|
20
|
+
1. Validate the script at `$1` — confirm it exists and is executable:
|
|
21
|
+
- Check file: !`test -f "$1" && echo "EXISTS" || echo "MISSING"`
|
|
22
|
+
- Check executable: !`test -x "$1" && echo "EXECUTABLE" || echo "NOT_EXECUTABLE"`
|
|
23
|
+
2. If validation passes, execute the script and capture output:
|
|
24
|
+
- Run: !`bash "$1" $2 $3 2>&1`
|
|
25
|
+
3. Parse the JSON stdout and display:
|
|
26
|
+
- Results section (key-value pairs from `results`)
|
|
27
|
+
- Metadata section (script name, timestamps)
|
|
28
|
+
- Errors section (any entries in `errors` array)
|
|
29
|
+
4. If validation fails or output is malformed, report the issue and suggest fixes
|
|
30
|
+
|
|
31
|
+
## Examples
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# Execute a batch script
|
|
35
|
+
/shell-batch-exec scripts/process-files.sh
|
|
36
|
+
|
|
37
|
+
# Execute with arguments
|
|
38
|
+
/shell-batch-exec scripts/data-pipeline.sh access.log
|
|
39
|
+
|
|
40
|
+
# Execute from current directory
|
|
41
|
+
/shell-batch-exec ./my-batch-script.sh
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## See Also
|
|
45
|
+
|
|
46
|
+
- **`shell-batch-operations`** skill — Full documentation on batch pattern, output format, and `batch_output()` contract
|
|
47
|
+
- **`batch-template.sh`** — Script template with batch utilities
|
|
48
|
+
- **`lib-batch.sh`** — Batch utility functions reference
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: shell-new
|
|
3
|
+
description: Scaffold a new bash script from template with best practices
|
|
4
|
+
argument-hint: path [type]
|
|
5
|
+
allowed-tools: [Read, Write, Bash]
|
|
6
|
+
disable-model-invocation: true
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Create New Bash Script
|
|
10
|
+
|
|
11
|
+
Create a new bash script at `$1` by delegating to the **`shell-best-practices`** skill (Mode B — New Script), which owns the scaffolding process, template selection, and standards enforcement.
|
|
12
|
+
|
|
13
|
+
## Arguments
|
|
14
|
+
|
|
15
|
+
- **$1** (required): File path where the script will be created
|
|
16
|
+
- **$2** (optional): Template type
|
|
17
|
+
- `minimal` — Simple single-function script
|
|
18
|
+
- `standard` — Full-featured script with argument parsing (default)
|
|
19
|
+
- `library` — Sourced by other scripts; provides reusable functions
|
|
20
|
+
- `posix` — Posix compatible script
|
|
21
|
+
|
|
22
|
+
## How It Works
|
|
23
|
+
|
|
24
|
+
1. Validate the target path:
|
|
25
|
+
- Check parent directory: !`dirname "$1" | xargs test -d && echo "DIR_EXISTS" || echo "DIR_MISSING"`
|
|
26
|
+
- Check file doesn't already exist: !`test -e "$1" && echo "ALREADY_EXISTS" || echo "NEW"`
|
|
27
|
+
- If directory is missing or file exists, report the issue and stop
|
|
28
|
+
2. Pass `$ARGUMENTS` to the `shell-best-practices` skill (Mode B) and execute its scaffolding process:
|
|
29
|
+
- Determine script name from the path
|
|
30
|
+
- Select template type based on `$2` (default: `standard`)
|
|
31
|
+
- Create the file — for directly executed scripts, omit the `.sh` extension (e.g. `deploy` not `deploy.sh`); for libraries meant to be sourced, keep the `.sh` extension (e.g. `lib-helpers.sh`)
|
|
32
|
+
- Fill in placeholders (description, usage, functions)
|
|
33
|
+
- Apply all core standards (shebang, strict mode, quoting, error handling)
|
|
34
|
+
- Make the file executable (`chmod +x`)
|
|
35
|
+
3. Hooks run automatically (ShellCheck, shfmt)
|
|
36
|
+
|
|
37
|
+
## Examples
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# Create a standard script
|
|
41
|
+
/shell-new scripts/process-data
|
|
42
|
+
|
|
43
|
+
# Create a minimal script
|
|
44
|
+
/shell-new utils/quick-fix minimal
|
|
45
|
+
|
|
46
|
+
# Create a library
|
|
47
|
+
/shell-new lib/helpers.sh library
|
|
48
|
+
|
|
49
|
+
# Create in current directory
|
|
50
|
+
/shell-new myscript
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## See Also
|
|
54
|
+
|
|
55
|
+
- **`shell-best-practices`** skill — Owns the scaffolding process, templates, and core standards
|
|
56
|
+
- **`/shell-audit`** command — Quality audit after development
|
|
57
|
+
- **`/shell-test-run`** command — Run test suites
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: shell-routines-setup
|
|
3
|
+
description: Configure Bash LSP development environment and tools
|
|
4
|
+
allowed-tools: [Bash]
|
|
5
|
+
disable-model-invocation: true
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Bash LSP Setup
|
|
9
|
+
|
|
10
|
+
Configure the Bash/Shell development environment. Detect and install required tools, verify the LSP configuration, and validate the hook pipeline.
|
|
11
|
+
|
|
12
|
+
## Prerequisites
|
|
13
|
+
|
|
14
|
+
Node.js is required for bash-language-server. Check first:
|
|
15
|
+
|
|
16
|
+
- Node.js: !`command -v node >/dev/null 2>&1 && node --version || echo "MISSING"`
|
|
17
|
+
- npm: !`command -v npm >/dev/null 2>&1 && npm --version || echo "MISSING"`
|
|
18
|
+
|
|
19
|
+
If Node.js is missing, stop and ask the user whether to install the latest LTS version before continuing.
|
|
20
|
+
|
|
21
|
+
## How It Works
|
|
22
|
+
|
|
23
|
+
### 1. Detect installed tools
|
|
24
|
+
|
|
25
|
+
Check which tools are already present before installing:
|
|
26
|
+
|
|
27
|
+
- bash-language-server: !`command -v bash-language-server >/dev/null 2>&1 && bash-language-server --version || echo "MISSING"`
|
|
28
|
+
- shellcheck: !`command -v shellcheck >/dev/null 2>&1 && shellcheck --version || echo "MISSING"`
|
|
29
|
+
- shfmt: !`command -v shfmt >/dev/null 2>&1 && shfmt --version || echo "MISSING"`
|
|
30
|
+
- bashunit: !`command -v bashunit >/dev/null 2>&1 && bashunit --version || echo "MISSING"`
|
|
31
|
+
- checkbashisms: !`command -v checkbashisms >/dev/null 2>&1 && checkbashisms --version || echo "MISSING"`
|
|
32
|
+
- hyperfine: !`command -v hyperfine >/dev/null 2>&1 && hyperfine --version || echo "MISSING"`
|
|
33
|
+
|
|
34
|
+
### 2. Install missing tools
|
|
35
|
+
|
|
36
|
+
**Ask the user for confirmation before installing anything.** List the missing tools and the commands that will install them, then wait for approval:
|
|
37
|
+
|
|
38
|
+
- **bash-language-server** (via npm): `npm install -g bash-language-server`
|
|
39
|
+
- **shellcheck, shfmt, bashunit, hyperfine** (via brew): `brew install shellcheck shfmt bashunit hyperfine`
|
|
40
|
+
- **checkbashisms** (via devscripts): `brew install devscripts`
|
|
41
|
+
|
|
42
|
+
Only proceed with installation after the user confirms. Skip any tool already installed. Report what was installed vs what was already present.
|
|
43
|
+
|
|
44
|
+
### 3. Verify LSP configuration
|
|
45
|
+
|
|
46
|
+
Confirm the plugin's LSP config is in place:
|
|
47
|
+
|
|
48
|
+
- Check `.lsp.json`: !`test -f "${CLAUDE_PLUGIN_ROOT}/.lsp.json" && echo "LSP_CONFIG_OK" || echo "LSP_CONFIG_MISSING"`
|
|
49
|
+
|
|
50
|
+
If missing, report that the plugin installation may be incomplete.
|
|
51
|
+
|
|
52
|
+
### 4. Validate hook pipeline
|
|
53
|
+
|
|
54
|
+
Test that the hook pipeline works end-to-end by creating a temporary shell script and running ShellCheck and shfmt against it:
|
|
55
|
+
|
|
56
|
+
- Test ShellCheck: !`echo '#!/usr/bin/env bash\ngreet() { local name="$1"; echo "Hello, ${name}!"; }\ngreet "World"' > /tmp/test_lsp.sh && shellcheck /tmp/test_lsp.sh && echo "SHELLCHECK_OK" || echo "SHELLCHECK_FAIL"`
|
|
57
|
+
- Test shfmt: !`shfmt -d /tmp/test_lsp.sh && echo "SHFMT_OK" || echo "SHFMT_FAIL"`
|
|
58
|
+
- Clean up: !`rm -f /tmp/test_lsp.sh`
|
|
59
|
+
|
|
60
|
+
If both pass, the environment is ready. If either fails, report the specific tool and suggest troubleshooting steps.
|
|
61
|
+
|
|
62
|
+
## See Also
|
|
63
|
+
|
|
64
|
+
- **README.md** — Full prerequisites list and installation alternatives
|
|
65
|
+
- **`.lsp.json`** — LSP server configuration for bash-language-server
|
|
66
|
+
- **Hooks** — PostToolUse hook runs ShellCheck, shfmt, `bash -n`, and `checkbashisms` automatically
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: shell-test-run
|
|
3
|
+
description: Run bash script tests with coverage enforcement
|
|
4
|
+
argument-hint: path
|
|
5
|
+
allowed-tools: [Bash, Read, Glob]
|
|
6
|
+
disable-model-invocation: false
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Run Bash Tests
|
|
10
|
+
|
|
11
|
+
Run tests for bash scripts at `$1` (default: current directory) using the available testing framework. Execute with coverage enabled and enforce an 80% minimum threshold.
|
|
12
|
+
|
|
13
|
+
## Arguments
|
|
14
|
+
|
|
15
|
+
- **$1** (optional): Script or directory to test (default: current directory)
|
|
16
|
+
|
|
17
|
+
## How It Works
|
|
18
|
+
|
|
19
|
+
1. Detect available test framework:
|
|
20
|
+
- bashunit: !`command -v bashunit >/dev/null 2>&1 && echo "AVAILABLE" || echo "UNAVAILABLE"`
|
|
21
|
+
2. Validate the target path if provided:
|
|
22
|
+
- Check exists: !`test -z "$1" || { test -e "$1" && echo "EXISTS" || echo "MISSING"; }`
|
|
23
|
+
- If missing, report the error and stop
|
|
24
|
+
3. Run tests using the detected framework:
|
|
25
|
+
- If bashunit: run with `--coverage --coverage-min 80` against `$1` or default test directory
|
|
26
|
+
- Report results, coverage percentage, and any failures
|
|
27
|
+
4. If no framework is found, report the issue and suggest installing bashunit
|
|
28
|
+
|
|
29
|
+
## Examples
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# Run all tests in current directory
|
|
33
|
+
/shell-test-run
|
|
34
|
+
|
|
35
|
+
# Run tests for specific script
|
|
36
|
+
/shell-test-run tests/process-test.sh
|
|
37
|
+
|
|
38
|
+
# Run tests in a directory
|
|
39
|
+
/shell-test-run ./tests
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## See Also
|
|
43
|
+
|
|
44
|
+
- **`shell-test`** skill — Test writing patterns, framework setup, and coverage configuration
|
|
45
|
+
- **`/shell-audit`** command — Quality audit for scripts under test
|
|
46
|
+
- **`/shell-new`** command — Scaffold new scripts with test-ready structure
|
package/opencode.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://opencode.ai/config.json",
|
|
3
|
+
"lsp": {
|
|
4
|
+
"bash": {
|
|
5
|
+
"command": ["bash-language-server", "start"],
|
|
6
|
+
"extensions": [".sh", ".bash", ".zsh", ".ksh"]
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"permission": {
|
|
10
|
+
"lsp": "allow",
|
|
11
|
+
"skill": "allow"
|
|
12
|
+
},
|
|
13
|
+
"formatter": {
|
|
14
|
+
"shfmt": {
|
|
15
|
+
"command": ["shfmt", "-w", "-i", "2", "$FILE"],
|
|
16
|
+
"extensions": [".sh", ".bash", ".zsh", ".ksh"]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@objctp/opencode-shell-routines",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Shell script development toolkit — automated scaffolding, best practices, and quality enforcement for OpenCode and Claude Code",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "objct",
|
|
7
|
+
"url": "https://objct.link"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/objctp/shell-routines",
|
|
10
|
+
"repository": "https://github.com/objctp/shell-routines",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"opencode-plugin",
|
|
14
|
+
"claude-code-plugin",
|
|
15
|
+
"shell",
|
|
16
|
+
"bash",
|
|
17
|
+
"shellcheck",
|
|
18
|
+
"shfmt",
|
|
19
|
+
"scaffolding",
|
|
20
|
+
"static-analysis",
|
|
21
|
+
"code-quality",
|
|
22
|
+
"bash-scripting"
|
|
23
|
+
],
|
|
24
|
+
"files": [
|
|
25
|
+
"agents/",
|
|
26
|
+
"commands/",
|
|
27
|
+
"plugins/",
|
|
28
|
+
"skills/",
|
|
29
|
+
"scripts/",
|
|
30
|
+
"opencode.json",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE"
|
|
33
|
+
]
|
|
34
|
+
}
|