@gfn-cis/coding-agent-public-rules 0.0.0-stage → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -2
- package/gfn-ansible/SKILL.md +18 -0
- package/gfn-ci-cd/SKILL.md +14 -0
- package/gfn-code/SKILL.md +175 -0
- package/gfn-code-health-check/SKILL.md +169 -0
- package/gfn-code-reviewing/SKILL.md +18 -0
- package/gfn-docker/SKILL.md +14 -0
- package/gfn-infrastructure/SKILL.md +13 -0
- package/gfn-kubernetes/SKILL.md +14 -0
- package/gfn-python/SKILL.md +21 -0
- package/gfn-terraform/SKILL.md +14 -0
- package/gfn-testing/SKILL.md +216 -0
- package/gfn-tooling/SKILL.md +31 -0
- package/index.js +25 -0
- package/package.json +34 -4
- package/src/skills.js +92 -0
package/README.md
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Agentic coding bible
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Organization-wide **public** coding rules for both humans and automated agents, kept
|
|
4
|
+
language-agnostic and free of project-specific details or IP.
|
|
5
|
+
|
|
6
|
+
Each rule set is an OpenCode/agent skill at `gfn-<name>/SKILL.md`. An agent loads
|
|
7
|
+
skills selectively by their `description` — only the ones relevant to the current
|
|
8
|
+
change — instead of reading the whole repository.
|
|
9
|
+
|
|
10
|
+
Skill IDs are globally unique, always carry the `gfn-` prefix, and the `name` in the
|
|
11
|
+
frontmatter must equal the directory name. CI (`scripts/check-skills.py`) enforces this.
|
|
12
|
+
|
|
13
|
+
## Skills
|
|
14
|
+
|
|
15
|
+
| Skill | Applies to |
|
|
16
|
+
|---|---|
|
|
17
|
+
| `gfn-code` | Any code change, any language (application or infrastructure) |
|
|
18
|
+
| `gfn-testing` | Writing or reviewing tests; any change needing test coverage |
|
|
19
|
+
| `gfn-code-reviewing` | Any code review |
|
|
20
|
+
| `gfn-code-health-check` | On-request quantitative code-health analysis (not auto-listed) |
|
|
21
|
+
| `gfn-python` | Python code (`.py`, `pyproject.toml`, Python tests) |
|
|
22
|
+
| `gfn-terraform` | Terraform / OpenTofu / terragrunt (`.tf`) |
|
|
23
|
+
| `gfn-ansible` | Ansible playbooks and roles |
|
|
24
|
+
| `gfn-ci-cd` | CI/CD pipelines, builds, deployments |
|
|
25
|
+
| `gfn-tooling` | Tool installation, versioning, and isolation for development and CI/CD |
|
|
26
|
+
| `gfn-docker` | Dockerfiles and long-lived containers |
|
|
27
|
+
| `gfn-infrastructure` | Infrastructure declarations in any technology |
|
|
28
|
+
| `gfn-kubernetes` | Kubernetes manifests and Helm charts |
|
|
29
|
+
|
|
30
|
+
## Using the skills
|
|
31
|
+
|
|
32
|
+
The same skills ship two ways; pick one per machine.
|
|
33
|
+
|
|
34
|
+
### OpenCode 2, auto-updating (npm plugin)
|
|
35
|
+
|
|
36
|
+
Add the package to `plugins` in the global `opencode.json`:
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{ "plugins": ["@gfn-cis/coding-agent-public-rules@latest"] }
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
OpenCode re-resolves `@latest` on its own schedule (observed: days, not every start), and the
|
|
43
|
+
background service loads plugins once, so a new release lands only after both. To take it now:
|
|
44
|
+
`opencode plugin update`, then restart the service. Pin a version (`@0.1.0`) to freeze the rules.
|
|
45
|
+
|
|
46
|
+
### Git clone
|
|
47
|
+
|
|
48
|
+
Clone the repo and add the clone path to `skills` in `opencode.json`, e.g.
|
|
49
|
+
`"skills": ["/path/to/coding-agent-public-rules"]`. Update with `git pull`.
|
|
50
|
+
|
|
51
|
+
If both are configured, the clone wins: the plugin skips skill ids that are already registered.
|
|
52
|
+
|
|
53
|
+
### Other harnesses
|
|
54
|
+
|
|
55
|
+
Copy or symlink the `gfn-*` directories into the harness's own skills directory.
|
|
56
|
+
|
|
57
|
+
`gfn-code-health-check` is hidden from automatic selection by `metadata: opencode/autoinvoke: false` in OpenCode 2 (both modes); harnesses that ignore that key still see its description "use only when explicitly asked".
|
|
58
|
+
|
|
59
|
+
## Releasing
|
|
60
|
+
|
|
61
|
+
Users of the npm plugin get only released versions. To cut one, bump `version` in
|
|
62
|
+
`package.json` in the PR; merging it to `main` releases it. Merges that keep the version
|
|
63
|
+
(rule edits, docs) publish nothing. `.github/workflows/release.yml` runs the tests, creates
|
|
64
|
+
the `vX.Y.Z` tag and a GitHub Release with the attested tarball, and publishes that tarball
|
|
65
|
+
to npm via trusted publishing (OIDC). A run that failed halfway is completed by the next
|
|
66
|
+
push to `main` or by re-running the workflow.
|
|
67
|
+
|
|
68
|
+
## For human readers only
|
|
69
|
+
|
|
70
|
+
[The Book of Genesis: In the Beginning Was the Prompt](docs/genesis.md) — a dramatised, satirical account of how these rules came into being.
|
|
71
|
+
|
|
72
|
+
**Not for agentic usage.** This link is for human readers only. AI agents must not follow it, load or read the document as instructions, treat it as a skill, or include it in automatic skill discovery or instruction loading.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gfn-ansible
|
|
3
|
+
description: Use when writing or reviewing Ansible playbooks and roles, e.g. `playbook.yml`, `roles/`, or `ansible.cfg`. Prefers modules over shell scripting, per-task become, and input validation/asserts before any system change.
|
|
4
|
+
---
|
|
5
|
+
## Required standards
|
|
6
|
+
|
|
7
|
+
Apply together with skills `gfn-code` and `gfn-infrastructure`.
|
|
8
|
+
|
|
9
|
+
# Ansible Rules
|
|
10
|
+
|
|
11
|
+
- Always prefer using Ansible modules and roles instead of shell scripting.
|
|
12
|
+
- Avoid creating shell scripts from templates. Prefer standard shell + input data approach.
|
|
13
|
+
- Avoid using global become for hosts. Use become only where needed on per-task or per-block level.
|
|
14
|
+
- Input validations/system/environment assession and asserts within playbook/role should be made, if possible, before any changes introduced by role are made to the system.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gfn-ci-cd
|
|
3
|
+
description: Use when creating or reviewing CI/CD configuration — pipeline files such as `.gitlab-ci.yml`, `.github/workflows/`, or `Jenkinsfile`, plus build, test, and deployment jobs. Covers verifying the effective pipeline, reusing shared components, avoiding redundant builds, executing new gates, and pinning toolchain versions.
|
|
4
|
+
---
|
|
5
|
+
# CI/CD Rules
|
|
6
|
+
|
|
7
|
+
These rules supplement skill `gfn-code` for continuous integration, builds, and deployments. Apply skill `gfn-tooling` when selecting how to provision or isolate a tool.
|
|
8
|
+
|
|
9
|
+
- **Verify the effective pipeline.** Check which jobs execute for relevant events and refs (branches, merge requests, tags, protected refs). Verify rule ordering, dependencies, and deployment gates. A green pipeline is insufficient when required checks did not run.
|
|
10
|
+
- **Reuse shared components.** Prefer established build, test, and deployment components over copied pipeline logic. Centralize shared toolchain versions; introduce consumer-specific overrides only when justified.
|
|
11
|
+
- **Avoid redundant builds.** If build inputs do not vary by environment or zone, build once and reuse the artifact across deployment targets. Do not confuse CI orchestration fan-out with build requirements.
|
|
12
|
+
- **Protect component contracts.** Identify consumers, including users of moving version references, before changing shared component inputs, outputs, or behavior. Communicate and version breaking changes according to the component's release policy.
|
|
13
|
+
- **Execute new gates.** A newly added quality gate must be executed at least once before merge and shown able to fail. Advisory checks are explicitly non-blocking in pipeline configuration, not by accident of tool behaviour, and their output is kept as an artifact.
|
|
14
|
+
- **Pin once.** Pin a toolchain version exactly once (lockfile, image digest); everywhere else, including developer-facing constraints, use compatible ranges.
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gfn-code
|
|
3
|
+
description: Mandatory GFN engineering standards for all application and infrastructure code in any language. Apply when writing, modifying, refactoring, debugging, analyzing, or reviewing code, including infrastructure code and autotest code, including changes produced by other agents.
|
|
4
|
+
---
|
|
5
|
+
# Global Coding Rules (Language-Agnostic)
|
|
6
|
+
|
|
7
|
+
This document defines organization-wide, **language-agnostic** engineering rules.
|
|
8
|
+
It intentionally avoids project-, framework-, vendor-, and repository-specific guidance.
|
|
9
|
+
They apply to any type of code: either programming code or infrastructure code (ansible, terraform/tofu, etc).
|
|
10
|
+
|
|
11
|
+
## Non-negotiables
|
|
12
|
+
|
|
13
|
+
- **Language**: production code comments, docstrings, commit messages, and public-facing developer docs must be written in **English**.
|
|
14
|
+
- **No secrets / no sensitive data**: never hardcode credentials, tokens, private keys, internal URLs, customer data, or any confidential identifiers.
|
|
15
|
+
- **No environment-specific hardcoding**: domains, tenant/customer names, branding assets, and deployment-specific behavior must be driven by **configuration**, not `if/else` forks.
|
|
16
|
+
- **Consistency over preference**: follow the established style within a file/module/package unless there is a deliberate refactor.
|
|
17
|
+
- **No code-local requirement relaxation declarations** : if something is relaxed against the best practices, this relaxation must reside in appropriate ADR/Accepted Risk/Release notes of the repository or project. The comments in code/tests/whatever must only refer to it. The motivation: model could put relaxation on it's own into comment and treat it as a carved in stone. This relaxation will be hardly traceable. The single source of relaxations is much better traceable.
|
|
18
|
+
|
|
19
|
+
## Code quality
|
|
20
|
+
|
|
21
|
+
- **Correctness first**: make behavior explicit; avoid “magic” defaults that change silently across environments.
|
|
22
|
+
- **Separation of concerns**: keep business logic independent from presentation, transport, and persistence layers.
|
|
23
|
+
- **Single responsibility**: functions/classes/modules should have one clear purpose.
|
|
24
|
+
- **DRY, but not dogmatic**: deduplicate only when it reduces total complexity and maintenance cost.
|
|
25
|
+
- **Keep it readable**: prefer clear names and small units of code over clever tricks.
|
|
26
|
+
|
|
27
|
+
## Over engineering
|
|
28
|
+
- Avoid excessive configurability. Always consider during the plan phase does something should be configurable or it could be constant? If unsure - ask user directly with list of all configuration entities you doubt about.
|
|
29
|
+
|
|
30
|
+
## Naming consistency
|
|
31
|
+
- Some languages platforms or frameworks can denote best practices for naming styles and structures. In this case the model should consider it as well and choose best fit approach.
|
|
32
|
+
- entities names styling should be consistent within parent entity->module->project for same entity classes. e.g. if parent entity uses snake_case for variables - model should use it, if parent uses CamelCase for variables - model should use it and so forth.
|
|
33
|
+
- entities naming structure should be consistent within project for the same class and function of entities. For example, if some flag variables within module has structure flag_entity_flagname model should consider use it instead of, say entity_flag_flagname, or only flagname.
|
|
34
|
+
|
|
35
|
+
## Formatting and static analysis
|
|
36
|
+
|
|
37
|
+
- Format code with the language's canonical formatter style at its default settings (e.g. gofmt, rustfmt, Prettier, Black style). This is the style humans and models read most reliably; deviations from defaults need a documented reason.
|
|
38
|
+
- Use the strictest standard static analysis of the ecosystem, opt-out rather than opt-in: enable all rules of the linter and the strict mode of the type checker, then disable individual rules only for a documented reason (conflict with the formatter, mutually exclusive rules, not applicable to the project). Stricter checks fail bad code earlier.
|
|
39
|
+
- Suppressions are local, name the exact rule and give a reason. Blanket suppressions (whole-file, rule-less ignore comments, global "ignore missing types") are not allowed; stale suppressions are errors.
|
|
40
|
+
- Analysis tool versions are pinned; new findings after a deliberate upgrade are fixed or explicitly suppressed, never silenced by loosening the config.
|
|
41
|
+
|
|
42
|
+
## Error handling (fail fast)
|
|
43
|
+
|
|
44
|
+
- Do not swallow errors to “keep things running” if correctness is impacted.
|
|
45
|
+
- Avoid excessive fallbacks. Default to **fail fast** when correctness or data integrity is at risk.
|
|
46
|
+
- If a fallback is proposed, agree on the fallback plan with the user upfront (scope, triggering conditions, logging/metrics, and how/when to remove it).
|
|
47
|
+
- Catch **specific** error types; avoid blanket catches unless you are:
|
|
48
|
+
- implementing a well-defined fallback,
|
|
49
|
+
- limiting the try/catch scope,
|
|
50
|
+
- logging context,
|
|
51
|
+
- and returning to a safe, predictable state.
|
|
52
|
+
- Prefer returning structured errors or raising exceptions over returning ambiguous values.
|
|
53
|
+
- When wrapping errors into a common type, preserve the cause category (authentication, authorization, not found, conflict, rate limit, transient, malformed response) and the original status. Callers branch on it; collapsing categories turns operational failures into data errors.
|
|
54
|
+
- Map third-party errors in one place, not per call site.
|
|
55
|
+
|
|
56
|
+
## Calls to external systems
|
|
57
|
+
|
|
58
|
+
- Retry policy follows idempotency: retry idempotent reads on transient failures; never blindly retry non-idempotent writes. Where a write may have been applied, re-read state before deciding to retry.
|
|
59
|
+
- Every external call has a timeout and a bounded retry budget. Waits, counts and sizes dictated by the remote side (Retry-After, rate-limit resets, page counts, payload sizes) are external input: cap them and fail fast beyond the cap.
|
|
60
|
+
|
|
61
|
+
## Legacy dishonor
|
|
62
|
+
|
|
63
|
+
- If the part of code is copypasted from another code do not honor in by default as a good one just for the reason it pre-existed. If that copypasted code presents not optimal approach: inform user.
|
|
64
|
+
|
|
65
|
+
## Logging & observability
|
|
66
|
+
|
|
67
|
+
- Use the project’s logging system (not ad-hoc printing).
|
|
68
|
+
- Logs must be actionable: include identifiers and context, but **never** include secrets.
|
|
69
|
+
- Avoid emojis in logs.
|
|
70
|
+
- Choose appropriate log levels and avoid high-volume noise on hot paths.
|
|
71
|
+
- When logging errors, include enough information to debug (and include stack traces where appropriate).
|
|
72
|
+
|
|
73
|
+
## Security basics
|
|
74
|
+
|
|
75
|
+
- Treat all external input as untrusted: validate, sanitize, and encode appropriately.
|
|
76
|
+
- Prefer safe-by-default APIs; only bypass escaping/safety checks with a clear justification.
|
|
77
|
+
- Apply least privilege: scope permissions, credentials, and access as narrowly as possible.
|
|
78
|
+
- Avoid dynamic code execution (e.g., eval/templated SQL) unless there is no safer alternative and it is reviewed.
|
|
79
|
+
- Credentials are bound to an origin (scheme, host and port). Never send them to a URL taken from a response (pagination links, redirects, callbacks) without checking it against the configured origin; disable automatic redirects on authenticated clients.
|
|
80
|
+
- Security decisions on structured identifiers (URLs, paths, hostnames, IPs, emails) must compare parsed components, never string prefixes or substrings.
|
|
81
|
+
- Identify actors by immutable IDs, not by mutable names (usernames, display names, emails).
|
|
82
|
+
- State or idempotency markers stored in places other users can write (comments, labels, descriptions, tags) must be authenticated by their author's identity before they are trusted.
|
|
83
|
+
- **Require each layer to enforce only the security guarantees it can uphold.** Assign each guarantee to the layer that controls the operation across all relevant access paths. For example, an RPC server must authorize each request against the caller’s permissions for the requested method and resource. Client-side checks can prevent accidental calls. Server-side authorization must hold regardless of which client sends the request.
|
|
84
|
+
- **Prefer built-in security controls.** Use established mechanisms for isolation, authorization, and integrity. Keep integration code focused on configuring and invoking those controls. Describe best-effort checks according to what they actually enforce.
|
|
85
|
+
- **Preserve required workflows.** Keep the tools each workflow needs and run them with the minimum effective privileges. Treat code executed by a tool as having the privileges of that tool’s process.
|
|
86
|
+
- **Require evidence for security guarantees.** When introducing or changing a guarantee, add regression coverage at the enforcing boundary. Follow the [security guarantee checks in `gfn-testing`](../gfn-testing/SKILL.md#security-guarantee-checks).
|
|
87
|
+
- **Require owner approval to accept material security risks.** Record the decision in the project's designated source for accepted risks.
|
|
88
|
+
|
|
89
|
+
## Backward compatibility
|
|
90
|
+
|
|
91
|
+
- Do not maintain backward compatibility unless explicitly instructed.
|
|
92
|
+
- If you see potential backward compatibility issues - ask user explicitly wether to maintain backward compatibility.
|
|
93
|
+
- For published interfaces and schemas, identify affected consumers and communicate breaking changes through the applicable versioning scheme. Do not introduce compatibility layers unless explicitly agreed.
|
|
94
|
+
|
|
95
|
+
## Configuration & portability
|
|
96
|
+
|
|
97
|
+
- Configuration should be explicit, versioned (when appropriate), and documented.
|
|
98
|
+
- Keep environment differences in config, not in code forks.
|
|
99
|
+
- Do not duplicate configuration across multiple places without a single source of truth.
|
|
100
|
+
- Before adding an input, default, or mapping, check whether its value can be derived from existing metadata or provided by the platform. Avoid identity mappings and redundant transformations.
|
|
101
|
+
- Never match the textual errors since they can be in another languages on some systems.
|
|
102
|
+
|
|
103
|
+
## Documentation
|
|
104
|
+
|
|
105
|
+
- Do not duplicate the same content as separate “for humans” and “for agents” versions.
|
|
106
|
+
- Avoid emojis in documentation and comments.
|
|
107
|
+
- Avoid documentation duplication by using a layered approach and links:
|
|
108
|
+
- **Function/method docstrings**: detailed behavior/contract, inputs/outputs, edge cases.
|
|
109
|
+
- **Class/module docs**: the big picture, invariants, and links to the relevant functions/methods for details.
|
|
110
|
+
- **Module/package README**: the most general overview (architecture/usage), linking to module/class docs.
|
|
111
|
+
- Any deviation from the project’s current ideology/architecture or from common best practices must be documented: what we changed and why.
|
|
112
|
+
- Public functions/methods/classes/modules must include docstrings (or the language’s equivalent structured API documentation comments) in the same style/format adopted by the repository (be consistent within the project). A docstring states the contract and what is not obvious from the name and signature; it does not restate the code. A private helper whose name and signature say everything needs none.
|
|
113
|
+
- Keep docs close to the code they describe (README in the relevant directory/module): function/methods/classes/modules - in appropriate docstrings. Packages - in readme.md within package folder.
|
|
114
|
+
- Update documentation when changing behavior, public APIs, or operational requirements.
|
|
115
|
+
- When correctness or security relies on a dependency's behaviour, verify that behaviour in the dependency's source or official docs, pin it with a test, and document which guarantees come from the dependency and which are enforced by our code. Mark our own safeguards as such, so they are not removed as "already handled by the library".
|
|
116
|
+
|
|
117
|
+
### Respect the Human Reader
|
|
118
|
+
|
|
119
|
+
Documentation, comments, and runbooks are written for both humans and AI agents. They MUST be clear, concise, and useful to both.
|
|
120
|
+
|
|
121
|
+
- **Respect the reader's time.** Avoid walls of text, repetition, filler, and explanations that add no practical value. More documentation does not necessarily mean better documentation.
|
|
122
|
+
- **Document what matters.** Focus on project-specific decisions, constraints, invariants, non-obvious behavior, and operational knowledge.
|
|
123
|
+
- **Do not duplicate common knowledge.** Assume a competent developer or AI agent already understands established concepts, technologies, and standard practices. When additional context is useful, provide a short discovery hint (e.g., `Search for "PostgreSQL MVCC"`), rather than reproducing explanations or embedding unnecessary external URLs.
|
|
124
|
+
- **Reference internal knowledge instead of copying it.** For information already documented within the project or organization, link to the authoritative source using a stable file path, document reference, or internal URL. Avoid creating competing copies that can become outdated.
|
|
125
|
+
- **Explain why, not just what.** Do not narrate self-explanatory code. Document intent, trade-offs, and behavior that cannot be reliably inferred from the implementation or its references.
|
|
126
|
+
- **Be concise without sacrificing precision.** Keep essential context and instructions directly available when correctness, safety, or independent execution depends on them. Never make critical procedures unusable merely to avoid repetition.
|
|
127
|
+
- **Keep documentation actionable.** Prefer clear structure, concrete instructions, and relevant examples over lengthy prose.
|
|
128
|
+
|
|
129
|
+
**The goal is not to minimize documentation. It is to maximize useful information while minimizing the reader's effort.**
|
|
130
|
+
|
|
131
|
+
## Development practices
|
|
132
|
+
|
|
133
|
+
- Before writing new code, first analyze the project for existing functionality that can be reused (internal utilities, shared modules, existing services, established patterns).
|
|
134
|
+
- For migrations and replacements, establish existing behavior and agreed scope before editing. Preserve out-of-scope behavior, including execution order and external contracts, and identify intentional deviations.
|
|
135
|
+
- When replacing a foundation (library, framework, client, platform), re-evaluate everything that was shaped around the old one: wrappers, error mapping, retries, test doubles, comments, design rationale. Code that is still used but whose original reason no longer holds is leftover, same as dead code.
|
|
136
|
+
- Adopt a dependency at the abstraction level it offers. Using a high-level library as a bare transport underneath a hand-written layer that duplicates its API needs a documented reason.
|
|
137
|
+
- For platform/framework/language-specific rules, in addition to this skill, also load the relevant skill (e.g. `gfn-python`, `gfn-terraform`).
|
|
138
|
+
- Avoid ad-hoc solutions. New changes must fit the project’s architecture and established patterns.
|
|
139
|
+
- Avoid “hotfixes” when a proper solution is feasible. If a hotfix is unavoidable, align it with the user and document the trade-offs and follow-up plan.
|
|
140
|
+
- Follow the code-organization principles used in the project (e.g., OOP-style codebases should remain OOP; modular codebases should remain modular; functional codebases should remain functional). If the requested functionality does not fit existing approaches, agree on the approach with the user before introducing a new paradigm.
|
|
141
|
+
- Avoid unnecessary abstractions and overengineering.
|
|
142
|
+
- A strong signal an extracted helper is unnecessary is when it is called from only one place, and:
|
|
143
|
+
- the caller is under ~300 lines,
|
|
144
|
+
- inlining the logic would not reduce readability,
|
|
145
|
+
- inlining would not push the caller over ~300 lines,
|
|
146
|
+
- and there is no serious reason to keep it separate (e.g., a stable public API, reuse expected soon, complex test isolation, performance constraints, security boundaries).
|
|
147
|
+
- Regularly sanity-check that we are not reinventing the wheel: prefer mature, actively maintained libraries/tools (as of 2026) over bespoke implementations.
|
|
148
|
+
- Before adding a dependency for a narrow need, check whether the existing stack already covers it. Weigh the transitive footprint and the second set of failure modes, test doubles and updates it brings. Do not introduce a second client or stack for a protocol the project already speaks.
|
|
149
|
+
- However, when a mature higher-level dependency would cover the need and replace hand-written code around a lower-level one, propose migrating to it rather than extending the low-level layer; agree the migration scope with the user before starting.
|
|
150
|
+
- When introducing or using external dependencies, keep them up to date (as of 2026) unless the project documentation explicitly pins or forbids specific versions.
|
|
151
|
+
- When considering a library/framework/plugin/etc., always verify that it is updated frequently enough and that the chosen version is current for the year 2026.
|
|
152
|
+
- Always check for leftover/dead code introduced by refactors (unused functions, unreachable branches, stale TODOs, commented-out blocks). Ask the user for permission before removing it, and remove it only with explicit user approval.
|
|
153
|
+
|
|
154
|
+
## Testing (general expectations)
|
|
155
|
+
|
|
156
|
+
- Add/adjust tests when changing behavior.
|
|
157
|
+
- Prefer fast, deterministic tests; isolate external dependencies.
|
|
158
|
+
- Fix the root cause rather than encoding known bugs into tests.
|
|
159
|
+
|
|
160
|
+
## Size & maintainability (guidelines)
|
|
161
|
+
|
|
162
|
+
- If a function/method becomes hard to scan, split it.
|
|
163
|
+
- If a file/module becomes a “dumping ground”, reorganize around responsibilities.
|
|
164
|
+
- Prefer cohesive modules over large, interdependent ones.
|
|
165
|
+
|
|
166
|
+
## Private information
|
|
167
|
+
|
|
168
|
+
- The exploration/intermediary artifacts like subagent code analysis results must never be committed.
|
|
169
|
+
- All PII and infrastructure identification items must be replaced with example-style entities. e.g. domains - with example.com, usernames - with relevant example users, IP address with respective TEST-NET-1,2,3 IPs. Emails - with example emails and so forth.
|
|
170
|
+
- When appropriate - the placeholders and monikers could be used.
|
|
171
|
+
- The same applies to documentation and plans that goes to commit.
|
|
172
|
+
- Sanitization covers branch history, not only the final diff: identifiers committed earlier on the branch must be removed by squash or rewrite before merge.
|
|
173
|
+
|
|
174
|
+
## Secrets naming
|
|
175
|
+
- All secrets must be suffixed with a "secret", "password" or "key" words since models filter them out good by key. In case the entity by it's nature is not password o key, but rather "token" for example, the entity name should be suffexed with "secret" to indicate it's secrecy
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gfn-code-health-check
|
|
3
|
+
description: Use only when explicitly asked for a quantitative code-health analysis of a repository, component, or directory. Defines the RP/OP pressure model, tooling discovery procedure, and the required report format.
|
|
4
|
+
metadata:
|
|
5
|
+
opencode/autoinvoke: false
|
|
6
|
+
---
|
|
7
|
+
# Task: Quantitative Code-Health Analysis of `<TARGET>`
|
|
8
|
+
|
|
9
|
+
You are performing a **read-only quantitative analysis** of `<TARGET>` using the **RP/OP** pressure model defined below, plus standard supporting metrics. Use real tools — do NOT eyeball the code. All assumptions must be stated explicitly.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Step 0 — Locate & profile the target
|
|
14
|
+
|
|
15
|
+
1. Find `<TARGET>` (index/grep/glob — whichever is best).
|
|
16
|
+
2. **Detect primary language(s)**: count files by extension (use `scc`/`tokei`/`cloc`/ad-hoc count). If multi-language, either pick the dominant language and state it, or analyze each separately.
|
|
17
|
+
3. **Confirm scope**: list analyzed files, total LOC, and exclusions (tests, generated code, vendored deps, fixtures, mirror worktrees, sample/dev configs). Be explicit.
|
|
18
|
+
4. If `<TARGET>` doesn't exist or has no tractable codebase → **stop and report**.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Step 1 — Methodology (fixed formulas)
|
|
23
|
+
|
|
24
|
+
### A. Refactoring Pressure (RP)
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
RP = 0.6 × Peak + 0.4 × Base
|
|
28
|
+
|
|
29
|
+
combined = max_complexity × 0.6 + p90_complexity × 0.4
|
|
30
|
+
Peak = 100 × (1 − exp(−0.08 × combined)) × scale
|
|
31
|
+
density = (total_complexity / loc) × 100
|
|
32
|
+
Base = 100 × (1 − exp(−0.02 × density × scale))
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- CC over all functions/methods. `loc` = code lines (no blanks, no comments). Default `scale = min(1, loc/5000)` — state your choice.
|
|
36
|
+
|
|
37
|
+
### B. Overengineering Pressure (OP)
|
|
38
|
+
|
|
39
|
+
Build an **intra-project dependency graph** (modules and/or classes).
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
class_score = (0.35·fan_out_norm + 0.25·fan_in_norm + 0.25·depth_norm + 0.15·centrality_norm) × 100
|
|
43
|
+
OP = (0.4·coupling_norm + 0.6·avg_class_score_norm) × 100
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- `depth` — inheritance (preferred) or import-chain (state which). External base = +1.
|
|
47
|
+
- `centrality` — betweenness on the dep graph.
|
|
48
|
+
- `coupling` — edge density of dep graph OR average fan_out (state which).
|
|
49
|
+
- Normalize each to [0, 1] (min-max or a sensible cap — document).
|
|
50
|
+
|
|
51
|
+
### C. Combined Score with imbalance penalty
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
Score = (RP + OP) + k × |RP − OP| # default k = 0.5
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Report RP, OP, Score, and the penalty term separately.
|
|
58
|
+
|
|
59
|
+
### Verdict semantics
|
|
60
|
+
|
|
61
|
+
- `RP ≫ OP` → vermicelli / dense branchy logic.
|
|
62
|
+
- `OP ≫ RP` → abstraction labyrinth.
|
|
63
|
+
- both low → healthy. Both high → diffusely degraded (not "balanced").
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Step 2 — Tooling discovery (do NOT use a hardcoded list)
|
|
68
|
+
|
|
69
|
+
You need tools for: **(a) cyclomatic complexity per function**, **(b) LOC excluding blanks/comments**, **(c) type-check / lint signal**, **(d) dependency-graph extraction**, **(e) maintainability index or equivalent**, **(f) graph metrics (centrality, cycles)**, **(g) tabular aggregation**.
|
|
70
|
+
|
|
71
|
+
You must **discover the current best-fit tools at the moment this prompt is run**. Do NOT rely on your training-time knowledge of tool names — that snapshot may be stale or wrong. Procedure:
|
|
72
|
+
|
|
73
|
+
1. **Check what's already installed.** Try the obvious candidates you remember; if a tool is on `PATH` and produces sensible output on a single file, you can use it.
|
|
74
|
+
2. **For each missing slot, research current options.** Acceptable research paths, in order of preference:
|
|
75
|
+
- Look at the project's own configs (`pyproject.toml`, `package.json`, `go.mod`, `Cargo.toml`, `.golangci.yml`, `.eslintrc`, `pre-commit-config.yaml`, CI files) — whatever the team already uses is usually a fine choice and won't conflict with their assumptions.
|
|
76
|
+
- Web search (if web access is available) with a query like `"<language> cyclomatic complexity cli 2026"` or `"<language> dependency graph static analysis"`. Restrict to results from the last ~24 months.
|
|
77
|
+
- Awesome-lists for the language (`awesome-<lang>`, `awesome-static-analysis`) — they're usually maintained.
|
|
78
|
+
- Package registry top-results: `pypi.org`, `npmjs.com`, `crates.io`, `pkg.go.dev`, etc. — sort by recent activity / downloads.
|
|
79
|
+
3. **Verify each candidate before adopting it**:
|
|
80
|
+
- Last release within ~18 months (or actively maintained — recent commits).
|
|
81
|
+
- Supports the target language version.
|
|
82
|
+
- Produces machine-readable output (JSON, SARIF, CSV, or stable text) — if it only prints a human-readable summary, it's much harder to aggregate.
|
|
83
|
+
- Installable without root / system pollution (language package manager, single binary, container).
|
|
84
|
+
- License is acceptable for the project.
|
|
85
|
+
4. **Pick one tool per metric slot.** Briefly note **why** (e.g. "team already uses it", "only one that emits JSON", "covers all source files including .pyi"). If two tools disagree on a number, prefer the one closest to the team's existing toolchain and report the delta.
|
|
86
|
+
5. **Run the selected tools** using skill `gfn-tooling`. Use the project's toolchain or an available system package when it fits. Use an on-demand runner or an available container runtime as appropriate. If a tool needs a dedicated environment, put it under `docs/artifacts/.toolchain/<lang>/`. Never use `sudo` or modify global state.
|
|
87
|
+
|
|
88
|
+
**Fallback path — if the language has no good tooling at all** (or you can't get anything to run in this environment):
|
|
89
|
+
|
|
90
|
+
- Use **`tree-sitter`** (or `ast-grep`) as a universal AST extractor and write a small script to compute CC, fan-in/fan-out yourself.
|
|
91
|
+
- Use the language's own AST library if there's a host runtime available (e.g. `ast` in Python, `@typescript-eslint/parser` in JS).
|
|
92
|
+
- If even that fails, **stop and report** — do not invent numbers from a regex grep.
|
|
93
|
+
|
|
94
|
+
### What to put in the report about tooling
|
|
95
|
+
|
|
96
|
+
A required `Tools used` table:
|
|
97
|
+
|
|
98
|
+
| Metric | Tool | Version | Why this one | Output format |
|
|
99
|
+
|--------|------|---------|--------------|---------------|
|
|
100
|
+
|
|
101
|
+
Anything you discovered but rejected (and why) goes in `Limitations & assumptions`.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Step 3 — Supporting analysis
|
|
106
|
+
|
|
107
|
+
- Per-file: LOC, total CC, max CC, density, MI (or equivalent). Top-10 worst by each.
|
|
108
|
+
- Top-10 functions/methods by CC with `file:line`.
|
|
109
|
+
- Top-10 classes/modules by `class_score`.
|
|
110
|
+
- Type-check/lint signal: error & warning totals, top-10 files by count, error-rule histogram (summarize categories, don't dump every line).
|
|
111
|
+
- Cycle detection in dep graph.
|
|
112
|
+
|
|
113
|
+
Aggregate via DataFrame/table. Save raw per-entity data as CSV under `docs/artifacts/<target>_metrics_<timestamp>.csv`.
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Step 4 — Diagnosis
|
|
118
|
+
|
|
119
|
+
1. Dominant pressure: RP-heavy / OP-heavy / healthy / diffusely degraded.
|
|
120
|
+
2. 3–5 concrete hot spots, each with a one-line metric-based reason.
|
|
121
|
+
3. Pressure cluster: name the sub-package/dir dragging the score if any.
|
|
122
|
+
4. **Fix 3 things** — ranked by leverage, each with an expected delta in RP/OP/Score.
|
|
123
|
+
|
|
124
|
+
Be honest: if the project is clean, say so. If a metric is non-informative for this codebase (no inheritance, no internal coupling), say so. If a measurement artifact dominates the numbers, explain it.
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Definition of done
|
|
129
|
+
|
|
130
|
+
1. Scope confirmed: files, LOC, exclusions.
|
|
131
|
+
2. **`Tools used` table** is present and every number in the report is traceable to a tool in it.
|
|
132
|
+
3. RP, OP, Score computed; scale / normalization / `k` documented.
|
|
133
|
+
4. Top-N tables present for: files, functions, classes, MI, type-check.
|
|
134
|
+
5. Dep graph stats: nodes, edges, density, cycles.
|
|
135
|
+
6. Raw CSVs saved under `docs/artifacts/` in projects temporary directory and must not go to commits.
|
|
136
|
+
7. Diagnosis names dominant pressure, hot spots with metric reasons, fix-3 with expected deltas.
|
|
137
|
+
8. Limitations & assumptions explicit (including which candidate tools you considered and rejected).
|
|
138
|
+
|
|
139
|
+
If you hit a hard blocker (no tooling installable, language unsupported, target empty) → stop and report. Don't fabricate.
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Return format
|
|
144
|
+
|
|
145
|
+
Single Markdown report:
|
|
146
|
+
|
|
147
|
+
1. **Scope** — root, files, LOC, language mix, exclusions.
|
|
148
|
+
2. **Tools used** — the table from §2.
|
|
149
|
+
3. **Methodology** — formulas, scale/normalization, `k`.
|
|
150
|
+
4. **Headline numbers** — RP, OP, Score, penalty, verdict.
|
|
151
|
+
5. **Top-N tables**.
|
|
152
|
+
6. **Dep graph stats**.
|
|
153
|
+
7. **Diagnosis** — hot spots with metric reasons.
|
|
154
|
+
8. **Fix 3 things** — with expected Score delta.
|
|
155
|
+
9. **Limitations & assumptions** — including rejected tool candidates.
|
|
156
|
+
10. **Artifacts** — paths to CSVs, scripts, and any dedicated tool environments created under `docs/artifacts/`.
|
|
157
|
+
|
|
158
|
+
Dense, quantitative. Numbers before narrative.
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
### Placeholders
|
|
163
|
+
|
|
164
|
+
- `<TARGET>` — directory/component/repo path.
|
|
165
|
+
- Optionally pass `LANGUAGE=<lang>` to skip auto-detection.
|
|
166
|
+
|
|
167
|
+
### Artifacts lifecycle
|
|
168
|
+
|
|
169
|
+
- agent artifacts must never go to public repository.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gfn-code-reviewing
|
|
3
|
+
description: Use when performing any code review. Findings must cite evidence, brand-new entities are checked for reuse, re-reviews verify fixes against current code, and scope is every line the change adds or modifies.
|
|
4
|
+
---
|
|
5
|
+
_These rules are for Code-Reviewing process._
|
|
6
|
+
|
|
7
|
+
## Required standards
|
|
8
|
+
|
|
9
|
+
Review the change against skill `gfn-code` and every technology skill that applies to it.
|
|
10
|
+
|
|
11
|
+
1. When changes introcuding brand-new entities such as a function, procedures, classes, helpers, etc. - check for reusage opportunities. Is the same or similar functionality already present and it can be reused or generalized/adopted and then reused.
|
|
12
|
+
2. When doing the full-repository review, check for the opportunities for reusing as stated in previous pt and make a code more consise.
|
|
13
|
+
3. Every finding cites evidence: a location in the change and the rule or source it violates.
|
|
14
|
+
4. On re-review, verify each item reported as fixed against the current code; do not accept closure claims.
|
|
15
|
+
5. Scope is every line the change adds or modifies, regardless of which file it lives in or where the file came from.
|
|
16
|
+
6. Check that design rationale (specs, ADRs, comments) still matches the implementation it justifies.
|
|
17
|
+
7. Evaluate the overall solution against requirements, established architecture, applicable ADRs, and simpler approaches. Ground findings in concrete impact and distinguish defects from optional improvements.
|
|
18
|
+
8. When a change introduces or affects a security guarantee, verify the evidence required by the [security guarantee checks in `gfn-testing`](../gfn-testing/SKILL.md#security-guarantee-checks). Treat a violated guarantee or missing required evidence as a blocker.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gfn-docker
|
|
3
|
+
description: Use when writing or reviewing Dockerfiles or long-lived containers such as sidecars. Replaces bare `sleep infinity` with signal-handling shell.
|
|
4
|
+
---
|
|
5
|
+
## Required standards
|
|
6
|
+
|
|
7
|
+
Apply together with skill `gfn-code`.
|
|
8
|
+
|
|
9
|
+
For the long-lived containers like a sidecars or so avoid bare `sleep infinity` consider using
|
|
10
|
+
```shell
|
|
11
|
+
sleep infinity &
|
|
12
|
+
trap 'kill $! 2>/dev/null; exit 0' TERM INT
|
|
13
|
+
wait $!
|
|
14
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gfn-infrastructure
|
|
3
|
+
description: Use when writing or reviewing infrastructure declarations in any technology (Terraform, Helm, cloud config). Covers native functions over templating, configuration at its natural ownership scope, and tracing the deployed path for externally reachable changes.
|
|
4
|
+
---
|
|
5
|
+
## Required standards
|
|
6
|
+
|
|
7
|
+
Apply together with skill `gfn-code`.
|
|
8
|
+
|
|
9
|
+
# General infrastructure declaration/coding rules
|
|
10
|
+
|
|
11
|
+
1. Never use templating to get some info when system provides appropriate functions to get it. Consider using system's functions
|
|
12
|
+
2. Place configuration at its natural ownership scope (global, environment, service, or component). Shared environment facts belong at environment scope; service invariants belong in service definitions or shared templates. Avoid repeating the same fact at narrower scopes.
|
|
13
|
+
3. For changes to externally reachable behavior, trace the deployed path through routing, runtime configuration, services, and consumers. Verify behavior against the target deployment topology; local checks may miss environment-specific routing and policies.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gfn-kubernetes
|
|
3
|
+
description: Use when writing or reviewing Kubernetes manifests or Helm charts, e.g. `Chart.yaml`, `_helpers.tpl`, workload or PV/PVC definitions. Covers official chart reuse, keeping persistent data in a separate release, in-cluster secrets, and Terraform/Rancher annotation drift.
|
|
4
|
+
---
|
|
5
|
+
## Required standards
|
|
6
|
+
|
|
7
|
+
Apply together with skills `gfn-code` and `gfn-infrastructure`.
|
|
8
|
+
|
|
9
|
+
1. Don't make _helpers.tpl boierplate. Split it into meaningful files.
|
|
10
|
+
1. Prefer not to declare persistent data within the same release as application. The persistent data (pv/pvc/etc) should be in separate release because application reelases could be uninstalled during standart development process
|
|
11
|
+
1. When using helm charts, always look for official charts or actively maintained 3rd party charts, rather than reinventing the wheel. If chart exists consider pros and cons (vendor chart complexity vs vendoring own one) if you don't have a string opinion which to use - ask user.
|
|
12
|
+
1. When secret is used only in cluster - like secret for in-cluster service for in-cluster consumer, prefer to born secret inside cluster and store it in cluster.
|
|
13
|
+
1. When Terraform and/or rancher and/or helm are used for managing single cluster be aware of annotations ownership and drift detection, so terraform would not rollback rancher's ones.
|
|
14
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gfn-python
|
|
3
|
+
description: Use when writing or reviewing Python code, `.py` files, `pyproject.toml`, or Python tests. Covers PEP8, Black-style formatting enforced by ruff, ruff with select ALL, mypy --strict, vulture, and pytest with pytest_deduplicate and mutmut.
|
|
4
|
+
---
|
|
5
|
+
## Required standards
|
|
6
|
+
|
|
7
|
+
Apply together with skill `gfn-code`.
|
|
8
|
+
|
|
9
|
+
# Rules for python code
|
|
10
|
+
|
|
11
|
+
- Always use PEP8 styling when creating the code.
|
|
12
|
+
- pyproject config :
|
|
13
|
+
- Formatting: Black code style with default settings, enforced by `ruff format --check`.
|
|
14
|
+
- Linting: `ruff` with `select = ["ALL"]`. Project-wide ignores are limited to rules that conflict with the formatter (`COM812`, `ISC001`), one of each mutually exclusive docstring pair (`D203`/`D211`, `D212`/`D213`) and rules that do not apply (e.g. `CPY001`). Tests may additionally ignore `S101` and `PLR2004`. Pylint is not used: ruff implements its rules that need no type inference, and the type checker covers the rest.
|
|
15
|
+
- Typing: `mypy --strict` over sources and tests, with `enable_error_code = ["ignore-without-code"]`. Missing third-party stubs are handled per module (`[[tool.mypy.overrides]]`), never by a global `ignore_missing_imports`.
|
|
16
|
+
- Dead code: vulture (ruff covers unused imports and variables, not unused functions and classes).
|
|
17
|
+
- Tests: pytest with auto-discovery, pytest-cov, mutmut, pytest_deduplicate installed from its upstream repository (https://github.com/xor2003/pytest_deduplicate) pinned to a commit (its PyPI releases are outdated).
|
|
18
|
+
- unit tests should be created in test directory close to the module they are testing.
|
|
19
|
+
- unit tests should be created in auto-discoverable behaviour for pytest.
|
|
20
|
+
- use pytest_deduplicate to find the duplicated tests.
|
|
21
|
+
- use mutmut to confirm the tests covers what should be covered.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gfn-terraform
|
|
3
|
+
description: Use when writing or reviewing Terraform, OpenTofu, or terragrunt code, `.tf` files and modules. Prefers terraform templates over embedded strings for 5+ templates and keeps each `.tf` file under 1000 lines.
|
|
4
|
+
---
|
|
5
|
+
## Required standards
|
|
6
|
+
|
|
7
|
+
Apply together with skills `gfn-code` and `gfn-infrastructure`.
|
|
8
|
+
|
|
9
|
+
# Terraform
|
|
10
|
+
|
|
11
|
+
1. For 5+ string templates prefer using terraform templates rather than embedding templates into .tf file
|
|
12
|
+
1. Maintain each .tf file under 1000 lines (flexible limit). Split module into meaningful/scoped .tf files, maintaining right balance between files amount and single file size.
|
|
13
|
+
2. Never put the terraform modules inside terragrunt folder. Terragrunt is for the environments while terraform is for entities inside this environment.
|
|
14
|
+
3. Treat terraform sub-modules are private unless parent module is not a library module. For example tf/modulea/submodule is private and cannot be imported from tf/moduleb/submoduleb, unless tf/modulea is library module by the nature. In the above case tf/modulea/submodule should be moved to tf/lib/library-name/submodule
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gfn-testing
|
|
3
|
+
description: Use when writing, updating, or reviewing tests, and whenever a change fixes a bug or changes behavior, even if no tests were requested, since such a change needs a test that pins it. Covers behavior-over-shape assertions, anti-patterns, test placement, determinism, naming (including disposable tests), and docstring templates.
|
|
4
|
+
---
|
|
5
|
+
## Required standards
|
|
6
|
+
|
|
7
|
+
Apply together with skill `gfn-code`.
|
|
8
|
+
|
|
9
|
+
# Test Organization & Documentation Rules (Language-Agnostic)
|
|
10
|
+
|
|
11
|
+
This document defines organization-wide, **language-agnostic** rules for:
|
|
12
|
+
|
|
13
|
+
- organizing unit/integration tests,
|
|
14
|
+
- writing tests that validate behavior (not existence),
|
|
15
|
+
- documenting tests and test suites in a consistent, project-approved format.
|
|
16
|
+
|
|
17
|
+
## Goals
|
|
18
|
+
|
|
19
|
+
- Tests must fail when behavior breaks (not only when names/types change).
|
|
20
|
+
- Tests must be deterministic, isolated, parallel-safe, and easy to maintain.
|
|
21
|
+
- Test documentation must clearly state what is validated and why it matters.
|
|
22
|
+
|
|
23
|
+
## Golden rule (behavior over shape)
|
|
24
|
+
|
|
25
|
+
Ask:
|
|
26
|
+
|
|
27
|
+
**“If I fake the implementation with a dumb object that only has the right attributes, will the test still pass?”**
|
|
28
|
+
|
|
29
|
+
- If **yes** → the test likely checks *shape/existence* and is low-value.
|
|
30
|
+
- If **no** → the test likely checks *behavior* and is valuable.
|
|
31
|
+
|
|
32
|
+
## Core principle: test behavior, not existence
|
|
33
|
+
|
|
34
|
+
Avoid tests that only check:
|
|
35
|
+
|
|
36
|
+
- a field/attribute exists,
|
|
37
|
+
- a function returns the correct type,
|
|
38
|
+
- an internal cache/private variable changes,
|
|
39
|
+
- names/strings/paths that can be refactored without changing behavior.
|
|
40
|
+
|
|
41
|
+
Test languages:
|
|
42
|
+
- For the programming language-specific projects (e.g. python, js, java, php, etc) - prefer using language-specific testing framework.
|
|
43
|
+
- For the non-programming projects (pipes, contracts, terraform, ansible) prefer either using specific framework that best suit needs or using python testing framework.
|
|
44
|
+
- The shell-script based tests should be used only as a last resort.
|
|
45
|
+
- The data tests should avoid using "grep" for testing unless it is really fits best. Avoid using grep-like tests for the structured data.
|
|
46
|
+
|
|
47
|
+
Prefer tests that verify at least one of:
|
|
48
|
+
|
|
49
|
+
- output values,
|
|
50
|
+
- state transitions (persisted or observable state),
|
|
51
|
+
- emitted events/messages,
|
|
52
|
+
- observable side effects,
|
|
53
|
+
- error handling behavior.
|
|
54
|
+
|
|
55
|
+
## Anti-patterns to avoid
|
|
56
|
+
|
|
57
|
+
1) **Attribute/type checks without behavioral assertion**
|
|
58
|
+
- Acceptable only as a minor setup sanity check (and the real behavioral assertion must follow).
|
|
59
|
+
|
|
60
|
+
2) **Testing internal implementation**
|
|
61
|
+
- Avoid asserting private/internal fields, cache structures, intermediate steps, or exact call sequences unless the call sequence *is* the contract.
|
|
62
|
+
|
|
63
|
+
3) **Over-mocking**
|
|
64
|
+
- If you mock the system under test into a no-op, you are not testing behavior.
|
|
65
|
+
- Prefer fakes/stubs at boundaries and keep the core logic real.
|
|
66
|
+
|
|
67
|
+
4) **Brittle assertions**
|
|
68
|
+
- Avoid depending on exact error messages, formatting, or ordering unless that ordering is part of the contract.
|
|
69
|
+
|
|
70
|
+
## Test types and boundaries
|
|
71
|
+
|
|
72
|
+
- **Unit tests**: validate one unit (function/class/module) with minimal dependencies; run fast.
|
|
73
|
+
- **Integration tests**: validate interaction of multiple units; keep them deterministic and scoped.
|
|
74
|
+
- **End-to-end tests**: validate user-visible flows; fewer in number; highest setup cost.
|
|
75
|
+
|
|
76
|
+
Always choose the lowest-cost test type that reliably validates the behavior.
|
|
77
|
+
|
|
78
|
+
- Test doubles encode our assumptions about external systems. Verify each external contract the code depends on (authentication, error shapes, status codes, pagination) at least once against the real system, in a sandbox, before relying on it, and again when the integration changes.
|
|
79
|
+
- Live and E2E tests run under dedicated test identities with least privilege, provisioned as code; never under production identities.
|
|
80
|
+
- Production interfaces do not carry test-only parameters; stub at the transport boundary instead.
|
|
81
|
+
- Shared test data (identities, entities, payloads) is defined once in fixtures or factories; duplicated test data drifts silently.
|
|
82
|
+
|
|
83
|
+
### Security guarantee checks
|
|
84
|
+
|
|
85
|
+
- **Exercise the highest-impact prohibited operations first.** Send well-formed requests to the enforcing component using a dedicated test identity with the restricted role and the policy under test. Confirm that a permitted operation succeeds under the same identity and configuration.
|
|
86
|
+
- **Verify the denial and its effects.** Assert the authorization outcome from the enforcing component, using a stable error code where available. Check for unintended state changes and data disclosure, including partial effects. Client-side rejection, malformed input, missing fixtures, and unrelated errors leave the guarantee unverified.
|
|
87
|
+
- **Use isolated, disposable resources for destructive operations.** Use synthetic data in an environment that contains only test resources. For a read-only database role, confirm a read succeeds, then attempt bulk deletion, table truncation, and dropping a test schema or database where supported. Require authorization denials and verify that the data and objects remain intact.
|
|
88
|
+
|
|
89
|
+
## Test placement (where tests live)
|
|
90
|
+
|
|
91
|
+
- **Unit tests** should live *next to the code they test* : inside/near the module/package in folder like 'tests' or another best-practice language or framework-specific folder.
|
|
92
|
+
- Goal: local ownership, easy navigation, and small, cohesive test suites.
|
|
93
|
+
- **End-to-end (E2E) tests** should be placed based on scope:
|
|
94
|
+
- **Module-level** E2E tests: when the scenario touches only one module/component and does not require project-wide wiring.
|
|
95
|
+
- **Project-level** E2E tests: when the scenario spans multiple modules/components or requires end-to-end wiring across the project.
|
|
96
|
+
- Prefer **auto-discoverable** test locations/naming conventions for the given language/platform/framework so CI/CD can pick up new tests without manual configuration.
|
|
97
|
+
- This avoids manual CI changes per test and prevents a single project-global test folder from growing into an unstructured dump.
|
|
98
|
+
- Never put testing data like a fixtures or values which are used by tests only into the code. The test data must be placed close to test files.
|
|
99
|
+
|
|
100
|
+
## Structure: Arrange / Act / Assert
|
|
101
|
+
|
|
102
|
+
Use a consistent structure in test bodies (names vary by project; keep consistency):
|
|
103
|
+
|
|
104
|
+
- **Arrange (Given)**: create state/inputs.
|
|
105
|
+
- **Act (When)**: call the behavior.
|
|
106
|
+
- **Assert (Then)**: verify outcomes.
|
|
107
|
+
|
|
108
|
+
Keep each test focused on one scenario.
|
|
109
|
+
|
|
110
|
+
## Determinism and isolation
|
|
111
|
+
|
|
112
|
+
- Tests must not depend on current time, randomness, locale, network, or external services unless explicitly designed to.
|
|
113
|
+
- Control nondeterminism: freeze time, seed randomness, stub external calls, isolate filesystem.
|
|
114
|
+
- Avoid shared mutable global state.
|
|
115
|
+
- Every test must be runnable in parallel with others.
|
|
116
|
+
|
|
117
|
+
## Test naming and lifecycle
|
|
118
|
+
|
|
119
|
+
- **Persistent tests:** Use descriptive names reflecting the behavior, conditions, and expected outcome. Follow project conventions, e.g. `test_<behavior>_<condition>_<expected>`.
|
|
120
|
+
- **Regression tests:** Name by the behavior being protected, not by ticket IDs or implementation details.
|
|
121
|
+
- **Disposable tests:** Tests created solely to verify completion of a specific task, without protecting against a plausible future regression.
|
|
122
|
+
- MUST use the naming pattern `disposable_test_<purpose>`. The test creation date must be present in docstring.
|
|
123
|
+
- MUST NOT be committed to the repository or included in permanent test suites.
|
|
124
|
+
- MUST be removed after successful verification.
|
|
125
|
+
- **Retention rule:** Every persistent test MUST protect against an identifiable future regression. Otherwise, treat it as disposable.
|
|
126
|
+
- **Avoid unnecessary tests:** Prefer existing tools and checks (e.g. `git diff`, static analysis) over creating disposable tests when sufficient.
|
|
127
|
+
|
|
128
|
+
## Test documentation rules
|
|
129
|
+
|
|
130
|
+
- All test docstrings/comments must be in **English**.
|
|
131
|
+
- Test documentation and inline comments must be understandable to both humans and automated agents.
|
|
132
|
+
- Do not duplicate the same content as separate “for humans” and “for agents” versions.
|
|
133
|
+
- Avoid emojis in test logs, comments, and documentation.
|
|
134
|
+
- Use the docstring format adopted by the repository (be consistent within the project).
|
|
135
|
+
- Documentation should explain **why** this behavior matters (risk/impact), not only what the code does.
|
|
136
|
+
- Avoid duplication by using a layered approach and links:
|
|
137
|
+
- **Test docstrings**: scenario-specific intent, assertion, and methodology.
|
|
138
|
+
- **Test module docstring**: suite scope/coverage and pointers to key tests.
|
|
139
|
+
- **Suite-level docs (folder README)**: shared conventions, helpers, datasets, and “how to run”, linking to the module docs/tests for details.
|
|
140
|
+
- Documentation location conventions:
|
|
141
|
+
- **Per-test documentation**: docstrings on the test case/function/method.
|
|
142
|
+
- **Per-test-module documentation**: a module/file-level docstring describing scope, coverage, and how to run.
|
|
143
|
+
- **Suite-level documentation** (shared conventions, datasets, helpers, how-to-run): place it in the folder that contains the test suite (e.g., a README in that test directory).
|
|
144
|
+
|
|
145
|
+
### Standard test docstring template
|
|
146
|
+
|
|
147
|
+
Use a short, structured docstring (adapt fields to project conventions):
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
"""[One line: behavior being validated]
|
|
151
|
+
|
|
152
|
+
Validates: [What contract/behavior is being validated]
|
|
153
|
+
Code: [production code location(s) being validated]
|
|
154
|
+
|
|
155
|
+
Assertion: [What MUST be true]
|
|
156
|
+
|
|
157
|
+
Method:
|
|
158
|
+
1. Arrange: [key setup]
|
|
159
|
+
2. Act: [the operation]
|
|
160
|
+
3. Assert: [key checks and why]
|
|
161
|
+
|
|
162
|
+
Related:
|
|
163
|
+
- [links to related tests or docs]
|
|
164
|
+
"""
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Regression test docstring template
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
"""[One line: bug being prevented]
|
|
171
|
+
|
|
172
|
+
Regression: [What the bug was, impact, and how it was triggered]
|
|
173
|
+
Reference: [issue/PR/ticket if available]
|
|
174
|
+
|
|
175
|
+
Code: [production code location(s) that were fixed]
|
|
176
|
+
Assertion: [What MUST NOT happen anymore]
|
|
177
|
+
"""
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Test suite (file/class/module) documentation
|
|
181
|
+
|
|
182
|
+
Each test suite should have a short header (module docstring or README-style section) that states:
|
|
183
|
+
|
|
184
|
+
- what component/behavior group it covers,
|
|
185
|
+
- what it intentionally does not cover,
|
|
186
|
+
- how to run it (if not obvious),
|
|
187
|
+
- and any important test data/fixtures conventions.
|
|
188
|
+
|
|
189
|
+
## Cross-referencing production code
|
|
190
|
+
|
|
191
|
+
When referencing production code, use a stable, readable format accepted by the project.
|
|
192
|
+
Example format:
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
path/to/file.ext::SymbolName (optional line range)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Keep references up to date when code moves.
|
|
199
|
+
|
|
200
|
+
## Tags / categories (if used in the project)
|
|
201
|
+
|
|
202
|
+
Tests must use markers (e.g., `unit`, `integration`, `slow`, `critical`, `regression`, `migration`):
|
|
203
|
+
|
|
204
|
+
- use them consistently,
|
|
205
|
+
- document what each tag means,
|
|
206
|
+
- keep “slow” tests opt-in where possible,
|
|
207
|
+
- avoid inflating “critical” labels.
|
|
208
|
+
|
|
209
|
+
## Review checklist
|
|
210
|
+
|
|
211
|
+
- [ ] The test validates behavior (not mere existence).
|
|
212
|
+
- [ ] It would fail if business logic breaks.
|
|
213
|
+
- [ ] It uses a stable public API/contract where possible.
|
|
214
|
+
- [ ] It is deterministic and parallel-safe.
|
|
215
|
+
- [ ] It has clear intent (name + Arrange/Act/Assert).
|
|
216
|
+
- [ ] Any deviation from project conventions is documented (what/why).
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gfn-tooling
|
|
3
|
+
description: Use when choosing how to obtain, version, or isolate tools for development, CI/CD, or target environments.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Tooling
|
|
7
|
+
|
|
8
|
+
## Project-integrated tools
|
|
9
|
+
|
|
10
|
+
Use the project's existing dependency workflow when a tool needs to import project code, load project dependencies or plugins, or be called as a library by the project. Use the same manifest, lockfile, and runner when that workflow runs in a container.
|
|
11
|
+
|
|
12
|
+
## Standalone tools
|
|
13
|
+
|
|
14
|
+
A tool that operates on files or artifacts through a CLI can use its own runtime, even when it is part of the project's workflow. A Python CLI that analyzes files in a Java repository is a standalone tool.
|
|
15
|
+
|
|
16
|
+
For ordinary standalone tools, reuse an installed version that meets the requirements or prefer the platform package manager where system package changes are appropriate. If it cannot provide a suitable version in the current environment, use an on-demand runner such as `uvx` or `npm exec` with an explicit version. Use a dedicated environment when the preceding options cannot supply the required setup.
|
|
17
|
+
|
|
18
|
+
## When to isolate execution
|
|
19
|
+
|
|
20
|
+
Consider a container when:
|
|
21
|
+
|
|
22
|
+
- The tool has heavy dependencies, requires conflicting versions, or would materially change a shared host or runner.
|
|
23
|
+
- The tool is permitted to run but warrants reduced trust because its packaging, dependencies, or update channel are harder to control. Apply the project's supply-chain requirements to the image and its contents before execution.
|
|
24
|
+
- The security model requires a separate execution boundary. For example, a stdio MCP server may need to run outside the proxy's credential context, with access limited to the resources the server needs.
|
|
25
|
+
- The container can be subject of a considertion only when a tool already has a well-supported containerized image.
|
|
26
|
+
|
|
27
|
+
Use the container runtime available where the tool will run. Grant only the files, credentials, privileges, and network access required for the task. Use stdin and stdout when they are sufficient. For example, a Pandoc image can supply the LaTeX toolchain, read Markdown from stdin, and return a PDF on stdout without a workspace mount. If isolation is required, use an environment that provides the required boundary before running the tool.
|
|
28
|
+
|
|
29
|
+
## CI/CD
|
|
30
|
+
|
|
31
|
+
Declare recurring tools in the existing pipeline toolchain and reuse shared tooling where it fits. Keep one authoritative version per tool or image. For containerized jobs, pin the image by digest in the existing configuration. Use the declared toolchain consistently so a missing version or image fails the job visibly.
|
package/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode 2 plugin entry: registers the gfn-* skills shipped in this package.
|
|
3
|
+
* See src/skills.js for the loader and README.md for the two install modes.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
import { loadSkills } from "./src/skills.js";
|
|
10
|
+
|
|
11
|
+
const ROOT = path.dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
id: "gfn-coding-rules",
|
|
15
|
+
async setup(ctx) {
|
|
16
|
+
const skills = loadSkills(ROOT);
|
|
17
|
+
await ctx.skill.transform((editor) => {
|
|
18
|
+
for (const skill of skills) {
|
|
19
|
+
// A skill already known (e.g. from a git clone listed in "skills") wins,
|
|
20
|
+
// so enabling both install modes never yields duplicates.
|
|
21
|
+
if (!editor.get(skill.id)) editor.add(skill);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gfn-cis/coding-agent-public-rules",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "GFN coding rules as agent skills; OpenCode 2 plugin that registers them",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"index.js",
|
|
9
|
+
"src/skills.js",
|
|
10
|
+
"gfn-*/**",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "node --test \"src/*.test.js\" \"scripts/*.test.js\""
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"opencode",
|
|
18
|
+
"opencode-plugin",
|
|
19
|
+
"skills",
|
|
20
|
+
"coding-rules"
|
|
21
|
+
],
|
|
22
|
+
"author": "GFN-CIS",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/GFN-CIS/coding-agent-public-rules.git"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"opencode": ">=2.0.0"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"yaml": "^2.9.1"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/skills.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill loader for the OpenCode 2 plugin entry (index.js).
|
|
3
|
+
*
|
|
4
|
+
* OpenCode 2 has no config hook, so a plugin cannot add a skills directory;
|
|
5
|
+
* it reads each <root>/gfn-<name>/SKILL.md itself and registers the result through
|
|
6
|
+
* ctx.skill.transform. The entry mirrors what OpenCode 2.1 builds for a skill
|
|
7
|
+
* found in a configured directory, so both install modes (git clone + "skills",
|
|
8
|
+
* npm plugin) yield identical skills:
|
|
9
|
+
* - id: the skill folder name; name: frontmatter name, else the folder name
|
|
10
|
+
* - description: frontmatter description, when present
|
|
11
|
+
* - autoinvoke: metadata["opencode/autoinvoke"], else false when
|
|
12
|
+
* "disable-model-invocation" is truthy, else unset
|
|
13
|
+
* - path: absolute SKILL.md path; content: the body after the frontmatter
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import fs from "node:fs";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
|
|
19
|
+
import { parse } from "yaml";
|
|
20
|
+
|
|
21
|
+
// "---" on the first line, then everything up to the next "---" line; LF or CRLF.
|
|
22
|
+
const FRONTMATTER_RE = /^---[ \t]*\r?\n(?:([\s\S]*?)\r?\n)?---[ \t]*(?:\r?\n|$)/;
|
|
23
|
+
const SKILL_DIR_RE = /^gfn-/;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Lenient boolean, the same coercion OpenCode applies to frontmatter flags.
|
|
27
|
+
* @param {unknown} value
|
|
28
|
+
* @returns {boolean | undefined}
|
|
29
|
+
*/
|
|
30
|
+
export function toBool(value) {
|
|
31
|
+
if (typeof value === "boolean") return value;
|
|
32
|
+
if (typeof value === "number") return value === 1 ? true : value === 0 ? false : undefined;
|
|
33
|
+
if (typeof value !== "string") return undefined;
|
|
34
|
+
const v = value.trim().toLowerCase();
|
|
35
|
+
if (["true", "yes", "on", "1"].includes(v)) return true;
|
|
36
|
+
if (["false", "no", "off", "0"].includes(v)) return false;
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Build a skill entry from SKILL.md text. Pure function, no I/O.
|
|
42
|
+
* Throws when the file has no valid YAML mapping frontmatter. OpenCode's own
|
|
43
|
+
* directory loader skips such files; we fail fast instead, because every
|
|
44
|
+
* published SKILL.md passed scripts/check-skills.py, so a broken one means a
|
|
45
|
+
* corrupted package and must not silently drop a rule set.
|
|
46
|
+
*
|
|
47
|
+
* @param {string} dirName skill folder name
|
|
48
|
+
* @param {string} file absolute SKILL.md path
|
|
49
|
+
* @param {string} text SKILL.md contents
|
|
50
|
+
*/
|
|
51
|
+
export function parseSkill(dirName, file, text) {
|
|
52
|
+
const src = String(text).replace(/^\uFEFF/, "");
|
|
53
|
+
const m = FRONTMATTER_RE.exec(src);
|
|
54
|
+
if (!m) throw new Error(`${file}: missing frontmatter`);
|
|
55
|
+
let fields;
|
|
56
|
+
try {
|
|
57
|
+
fields = parse(m[1] ?? "") ?? {};
|
|
58
|
+
} catch (cause) {
|
|
59
|
+
throw new Error(`${file}: frontmatter is not valid YAML`, { cause });
|
|
60
|
+
}
|
|
61
|
+
if (typeof fields !== "object" || Array.isArray(fields)) {
|
|
62
|
+
throw new Error(`${file}: frontmatter is not a mapping`);
|
|
63
|
+
}
|
|
64
|
+
const meta = fields.metadata;
|
|
65
|
+
const explicit =
|
|
66
|
+
meta && typeof meta === "object" && !Array.isArray(meta) ? toBool(meta["opencode/autoinvoke"]) : undefined;
|
|
67
|
+
const autoinvoke = explicit ?? (toBool(fields["disable-model-invocation"]) ? false : undefined);
|
|
68
|
+
return {
|
|
69
|
+
id: dirName,
|
|
70
|
+
name: typeof fields.name === "string" && fields.name ? fields.name : dirName,
|
|
71
|
+
...(typeof fields.description === "string" ? { description: fields.description } : {}),
|
|
72
|
+
...(autoinvoke === undefined ? {} : { autoinvoke }),
|
|
73
|
+
path: file,
|
|
74
|
+
content: src.slice(m[0].length),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Read every <root>/gfn-<name>/SKILL.md. Only gfn-* folders are scanned so that
|
|
80
|
+
* nothing outside the rule set (node_modules, scripts) is ever picked up.
|
|
81
|
+
* A gfn-* folder without a readable SKILL.md throws (see parseSkill for why).
|
|
82
|
+
* @param {string} root package root
|
|
83
|
+
*/
|
|
84
|
+
export function loadSkills(root) {
|
|
85
|
+
const skills = [];
|
|
86
|
+
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
|
|
87
|
+
if (!entry.isDirectory() || !SKILL_DIR_RE.test(entry.name)) continue;
|
|
88
|
+
const file = path.join(root, entry.name, "SKILL.md");
|
|
89
|
+
skills.push(parseSkill(entry.name, file, fs.readFileSync(file, "utf8")));
|
|
90
|
+
}
|
|
91
|
+
return skills.sort((a, b) => a.id.localeCompare(b.id));
|
|
92
|
+
}
|