Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions promptbook/prompts.json
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,26 @@
],
"formatNotes": "All three. Point the tool at the target `*.sh` file, any workflow or Jenkinsfile that calls it, and the Dockerfile if it is an entrypoint. Copilot: path-scoped bash instructions plus the files. Claude Code: the bash-script-hardening-guardrails skill plus the script. Codex: AGENTS.md shell section, then the diff.",
"body": "Task: Harden the Bash script I specify so it fails safely and passes ShellCheck. Produce a small diff plus a short verification note.\n\nContext placeholders (fill from the repo or ask only if missing):\n- Script path: {{SCRIPT}}\n- Runs in: {{RUNTIME}} (github-actions | jenkins | container-entrypoint | local-ops)\n- Shell target: {{SHELL}} (bash | posix-sh)\n- Required env vars: {{ENV_VARS}}\n\nRequirements:\n1. Inventory: list external commands used, env vars read, temp files written, destructive operations (`rm`, `mv`, overwrites), and every current ShellCheck finding (`shellcheck -x -f gcc {{SCRIPT}}`).\n2. Header: correct shebang for {{SHELL}}; add `set -Eeuo pipefail` (Bash) or `set -eu` (POSIX) and an ERR trap that reports `$LINENO` and the failing command to stderr.\n3. Quoting and arrays: quote all expansions, convert word-split argument strings to arrays, add `--` before user-supplied paths, replace `$(ls ...)` loops with globs or `find -print0 | while IFS= read -r -d ''`.\n4. Inputs: validate {{ENV_VARS}} with `${VAR:?message}`, check required binaries with `command -v`, add a `usage` function and exit 2 on bad args.\n5. Cleanup and safety: `mktemp` + `trap ... EXIT`; guard any `rm -rf` path against empty variables; make reruns idempotent.\n6. Secrets: remove `set -x` near credentials, move secrets out of argv to env/stdin, and add `::add-mask::` if {{RUNTIME}} is github-actions.\n7. If {{RUNTIME}} is container-entrypoint: end with `exec \"$@\"` so signals reach the main process.\n8. Tests and CI: add `bats` tests for the main branches (happy path, missing env var, bad argument) and a CI step running `shellcheck -x` and `shfmt -d`.\n\nOutput format:\n- Summary of changes (bullets)\n- Unified diff\n- Verification: commands to run shellcheck, shfmt, and bats, with expected results\n- Risks / follow-ups (behaviour that strict mode may now surface as failures)\n\nConstraints: do not change the script's intended behaviour or outputs; do not rewrite it in another language; keep the diff minimal and reviewable.\n"
},
{
"id": "scaffold-spring-openapi-first-api",
"title": "Scaffold a Spring OpenAPI-First API",
"whenToUse": "Bootstrap or retrofit a Spring Boot module so an OpenAPI 3 contract drives controllers, DTOs, validation, problem+json errors, and versioning — with agent instruction files in place.",
"tools": [
"copilot",
"claude-code",
"codex"
],
"tags": [
"spring-boot",
"openapi",
"api-design",
"validation",
"java",
"contracts"
],
"formatNotes": "All three. Point the tool at `openapi/`, the API package, `pom.xml`/`build.gradle`, and security config. Copilot: path-scoped spring-openapi instructions plus the files. Claude Code: the spring-boot-openapi-contract-guardrails skill plus the module. Codex: AGENTS.md OpenAPI section, then the diff.",
"body": "Task: Scaffold or retrofit the Spring Boot API I specify so the OpenAPI contract is the source of truth. Produce a small diff plus a short verification note.\n\nContext placeholders (fill from the repo or ask only if missing):\n- OpenAPI spec path: {{SPEC}} (e.g. openapi/openapi.yaml)\n- Base package: {{PACKAGE}} (e.g. com.example.orders.api)\n- Module / Maven artifact: {{MODULE}}\n- API version prefix: {{API_VERSION}} (e.g. /api/v1)\n- springdoc starter: {{SPRINGDOC}} (springdoc-openapi-starter-webmvc-ui | webflux-ui | none-yet)\n- Auth scheme: {{AUTH}} (none | bearer-jwt | oauth2)\n\nRequirements:\n1. Inventory: list existing controllers, DTOs, exception handlers, and whether {{SPEC}} already exists. Note any entity leak or undocumented endpoints.\n2. Contract: create or update {{SPEC}} (OpenAPI 3) with paths under {{API_VERSION}}, components/schemas for each request/response, `application/problem+json` error responses, and {{AUTH}} security schemes applied to protected operations.\n3. Dependencies: add {{SPRINGDOC}} (or confirm present) and enable Problem Details. Keep the diff minimal — no unrelated starters.\n4. Code: under {{PACKAGE}}, add thin controllers matching the spec paths/methods, request/response DTOs (records preferred) with Bean Validation mirroring schema constraints, and a `@RestControllerAdvice` that returns `ProblemDetail` for validation and domain errors.\n5. Alignment: ensure field names, required flags, status codes, and media types match {{SPEC}}. Do not expose JPA entities. Prefer constructor binding / records over mutable anemic DTOs.\n6. Versioning: all new public routes live under {{API_VERSION}}; document the versioning rule in a short README section.\n7. Agent instruction files: add Copilot `.github/instructions/spring-openapi.instructions.md` with applyTo for controllers and OpenAPI YAML; Claude `.claude/skills/spring-boot-openapi-contract-guardrails/SKILL.md` (or a one-line CLAUDE.md pointer); and an OpenAPI section in `AGENTS.md`.\n8. Verification: add a test that loads the app (or MockMvc), fetches `/v3/api-docs` (or the committed YAML), and asserts key paths/schemas exist; optionally add an openapi-diff / golden-file check sketch in CI notes.\n\nOutput format:\n- Summary of changes (bullets)\n- Unified diff\n- Verification: commands to run tests and how to open Swagger UI / compare {{SPEC}} to `/v3/api-docs`\n- Risks / follow-ups (breaking changes deferred to a future major version, security on docs endpoints)\n\nConstraints: stay inside Java/Spring Boot; do not rewrite the service in another stack; do not change unrelated business logic; keep the diff reviewable and free of secrets.\n"
}
]
}
20 changes: 20 additions & 0 deletions skillbook/skills.json
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,26 @@
],
"formatNotes": "All three. Copilot: path-scoped `.github/instructions/bash.instructions.md` with applyTo `**/*.sh`, `**/*.bash`, and `**/docker-entrypoint*`. Claude Code: `.claude/skills/bash-script-hardening-guardrails/SKILL.md` plus a one-line CLAUDE.md fact: strict mode, quote every expansion, ShellCheck must pass. Codex: a Shell Scripts section in root `AGENTS.md` or linked `docs/agents/shell.md`. Pair with gha-devsecops-pipeline for workflow `run:` blocks; this skill owns standalone script quality.",
"body": "# Skill: Bash Script Hardening Guardrails\n\n## Goal\nShell scripts that fail loudly, handle any filename or input safely, clean up after themselves, and pass ShellCheck in CI.\n\n## When to apply\n- New or changed `*.sh` files, container entrypoints, or Jenkins/GitHub Actions helper scripts\n- Reviews where a script silently continued after an error or broke on spaces in paths\n- Incidents caused by an unset variable, a glob, or a leaked secret in `set -x` output\n\n## Baseline rules\n1. **Explicit interpreter and strict mode.** Start with `#!/usr/bin/env bash` and `set -Eeuo pipefail`. If the script must be POSIX `sh`, say so and drop Bash-only features. Do not rely on strict mode alone — check exit codes where `set -e` is known not to fire (inside `if`, `&&`/`||` chains, command substitution in `local x=$(...)`).\n2. **Quote every expansion.** `\"$var\"`, `\"$@\"`, `\"${arr[@]}\"`. Use arrays for argument lists, never word-split strings. Use `--` before user-supplied paths (`rm -- \"$file\"`).\n3. **Safe temp files and cleanup.** `tmp=$(mktemp -d)` plus `trap 'rm -rf -- \"$tmp\"' EXIT`. Add an `ERR` trap that prints the failing line (`$LINENO`, `$BASH_COMMAND`) to stderr.\n4. **Validate inputs up front.** Required env vars via `: \"${API_URL:?API_URL is required}\"`; check required binaries with `command -v`. Print usage and exit 2 on bad arguments.\n5. **No secrets in output.** Never `set -x` around tokens; never echo credentials or pass them as command-line args visible in `ps` — use env vars or stdin (`--password-stdin`). Mask values in GitHub Actions with `::add-mask::`.\n6. **Idempotent and safe to rerun.** `mkdir -p`, check-before-create, no destructive `rm -rf \"$DIR/\"` where `DIR` could be empty (guard with `:?`).\n7. **Containers: exec the main process.** Entrypoints end with `exec \"$@\"` so signals reach the app (see k8s-probes-graceful-shutdown-guardrails).\n8. **Lint and format in CI.** `shellcheck -x` with zero warnings (justify any `# shellcheck disable=SCxxxx` inline) and `shfmt -d`; add `bats` tests for non-trivial logic.\n\n## Review checklist\n- [ ] Shebang + `set -Eeuo pipefail` (or documented POSIX sh)\n- [ ] All expansions quoted; arrays used for arg lists\n- [ ] `mktemp` + `trap ... EXIT` for temp state\n- [ ] Required env vars and tools validated with clear errors\n- [ ] No secrets in `set -x`, echo, or argv\n- [ ] ShellCheck and shfmt pass in CI; bats tests for branching logic\n\n## Anti-patterns\n- `for f in $(ls *.txt)` and unquoted `$1`\n- `curl ... | bash` from an unpinned URL\n- `cd somedir` without `|| exit` followed by `rm -rf *`\n- Entrypoint that runs the app as a child so SIGTERM never arrives\n"
},
{
"id": "spring-boot-openapi-contract-guardrails",
"title": "Spring Boot OpenAPI Contract Guardrails",
"whenToUse": "Designing or reviewing Spring Boot REST APIs that must stay faithful to an OpenAPI 3 contract — springdoc (or equivalent), DTO/schema alignment, Bean Validation, problem+json errors, and explicit versioning.",
"tools": [
"copilot",
"claude-code",
"codex"
],
"tags": [
"spring-boot",
"openapi",
"api-design",
"validation",
"java",
"contracts"
],
"formatNotes": "All three. Copilot: path-scoped `.github/instructions/spring-openapi.instructions.md` with applyTo `**/*Controller.java`, `**/openapi/**/*.{yaml,yml,json}`, `**/api/**/*.java`, and `**/dto/**/*.java`. Claude Code: `.claude/skills/spring-boot-openapi-contract-guardrails/SKILL.md` plus a one-line CLAUDE.md fact: OpenAPI YAML is source of truth; controllers and DTOs must match; errors are problem+json. Codex: an OpenAPI / API Contracts section in root `AGENTS.md` or linked `docs/agents/openapi.md`. Pair with spring-boot-actuator-hardening for docs-endpoint exposure; this skill owns contract fidelity.",
"body": "# Skill: Spring Boot OpenAPI Contract Guardrails\n\n## Goal\nREST APIs whose published OpenAPI 3 document is the source of truth — request/response shapes, validation, error media type, and versioning stay aligned with the running Spring Boot code.\n\n## When to apply\n- New Spring Boot services exposing HTTP APIs, or reviews that touch controllers, DTOs, or OpenAPI YAML\n- Migrations from code-first annotation sprawl to a maintained contract under `openapi/`\n- Client or partner integration work where a breaking schema change would ship unnoticed\n\n## Baseline rules\n1. **Contract first.** Keep an OpenAPI 3.0/3.1 document in the repo (e.g. `openapi/openapi.yaml`). Treat it as the source of truth for paths, methods, status codes, media types, and schemas. Generate or hand-write controllers and DTOs to match — do not invent fields in Java that are absent from the spec (or vice versa).\n2. **springdoc (or equivalent) stays honest.** Prefer springdoc-openapi to serve `/v3/api-docs` and Swagger UI from the running app. If you use annotation overlays (`@Operation`, `@Schema`), they must not contradict the YAML. Fail CI when the served document drifts from the committed contract (diff against a golden file or an openapi-diff step).\n3. **DTOs match schemas.** Map every request/response schema to a dedicated record/class. Use Jakarta Bean Validation (`@NotNull`, `@Size`, `@Email`, `@Pattern`, `@Valid` on nested objects) that mirrors `required`, `minLength`/`maxLength`, `pattern`, and `format` in the OpenAPI schema. Prefer records or immutable types; avoid exposing JPA entities on the wire.\n4. **Controllers are thin.** `@RestController` methods accept/return DTOs only, declare explicit `@RequestMapping`/`@GetMapping` paths and produces/consumes, and map to the versioned base path from the contract (`/api/v1/...`). No business logic in the controller — delegate to a service.\n5. **Errors are `application/problem+json`.** Enable Spring Problem Details (`spring.mvc.problemdetails.enabled=true` or WebFlux equivalent). Use `@RestControllerAdvice` returning `ProblemDetail` (or a documented subtype) for 4xx/5xx. Document error responses in the OpenAPI with `content.application/problem+json` and a Problem schema — do not leave error bodies as unspecified `application/json`.\n6. **Version deliberately.** Put the major version in the URL (`/api/v1`). Additive changes (new optional fields, new endpoints) stay in the same major; breaking changes get a new major and a deprecation window. Never silently rename or remove a required field.\n7. **Security and docs endpoints are explicit.** Document auth schemes (`bearer`, OAuth2) in the OpenAPI `components.securitySchemes` and apply them per operation. If Swagger UI / `/v3/api-docs` are exposed, gate them behind profile or Spring Security rules appropriate for the environment (see actuator hardening for management-port patterns).\n8. **Instruction files for coding agents.** Keep path-scoped Copilot instructions on controllers and OpenAPI YAML; a Claude skill for this checklist; and an AGENTS.md OpenAPI section so agents regenerate or edit against the contract instead of freelancing shapes.\n\n## Review checklist\n- [ ] Committed OpenAPI YAML covers every public endpoint (path, method, status, media type)\n- [ ] Request/response DTOs and Bean Validation match schema `required` / constraints\n- [ ] Controllers use versioned base path; no entity leak onto the API\n- [ ] Error responses documented and returned as `application/problem+json`\n- [ ] CI fails on contract drift (golden `/v3/api-docs` or openapi-diff)\n- [ ] Security schemes declared; docs UI not wide-open in production\n- [ ] Agent instruction files point at controllers + OpenAPI paths\n\n## Anti-patterns\n- Returning JPA entities or `Map<String,Object>` from controllers\n- `@ApiResponse` / springdoc annotations that disagree with the committed YAML\n- Undocumented 500 HTML error pages or ad-hoc `{ \"message\": \"...\" }` JSON\n- Breaking field renames without a `/api/v2` and a deprecation note\n"
}
]
}
Loading