gitlab-labkit 5.1.2 → 5.7.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.
- checksums.yaml +4 -4
- data/.claude/hooks/precommit-validate.sh +48 -0
- data/.claude/settings.json +15 -0
- data/.copier-answers.yml +2 -1
- data/.gitignore +0 -1
- data/.gitlab/CODEOWNERS +1 -1
- data/.gitlab/duo/agent-config.yml +7 -7
- data/.gitlab-ci.yml +24 -3
- data/.mise.toml +3 -0
- data/.opencode/plugins/precommit-validate.ts +226 -0
- data/.pre-commit-config.yaml +3 -2
- data/.rubocop_todo.yml +2 -17
- data/AGENTS.md +173 -0
- data/CLAUDE.md +1 -0
- data/CODEOWNERS +1 -1
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +5 -0
- data/README.md +6 -19
- data/gitlab-labkit.gemspec +1 -0
- data/lib/labkit/fields.rb +29 -2
- data/lib/labkit/json_schema/README.md +1 -1
- data/lib/labkit/rate_limit/README.md +82 -7
- data/lib/labkit/rate_limit/matcher.rb +138 -28
- data/lib/labkit/rate_limit/result.rb +32 -9
- data/lib/labkit/rate_limit/rule.rb +14 -4
- data/lib/labkit/rspec/matchers/user_experience_matchers.rb +2 -2
- data/performance.yml +70 -0
- data/scripts/prepare-dev-env.sh +24 -1
- metadata +21 -2
- data/.env.example.sh +0 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f2d9d587afe49d99a2ada5a8757230d69024a1085009f1e65c29ac97aa005e98
|
|
4
|
+
data.tar.gz: 35e55c1e1f9aef6836736e6917cffe4813aa37655eebf5534893f9b7b232fb89
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 83a9378e749aa4c04cf05cca872fffabe8945802b169c996aba579b43b73e582d98dca6c37b31c82098fe3edda41932ddc81813010ab278e2df7569812c7926e
|
|
7
|
+
data.tar.gz: 5b00ebd19184fbfaec05c1cdf40de93b74a70c0a7aa2b167213425debada2ea6708b61874d4ad23a9de40c950724b47da599d37daf0116d323ed8b4db76a6d23
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# PostToolUse hook: validate a just-edited file against this repo's pre-commit rules.
|
|
3
|
+
#
|
|
4
|
+
# Runs `pre-commit run --files <file>` on the file that Edit/Write/MultiEdit
|
|
5
|
+
# touched. On failure it prints the output to stderr and exits 2, which feeds the
|
|
6
|
+
# result back to Claude so it can fix the issue. A clean run exits 0 silently.
|
|
7
|
+
set -euo pipefail
|
|
8
|
+
IFS=$'\n\t'
|
|
9
|
+
|
|
10
|
+
# no-commit-to-branch guards the branch, not file content, and would fire
|
|
11
|
+
# spuriously (e.g. on jj's detached HEAD). It is irrelevant to file validation.
|
|
12
|
+
export SKIP="no-commit-to-branch"
|
|
13
|
+
|
|
14
|
+
# Run through `mise exec` so mise-managed tools that the hooks rely on
|
|
15
|
+
# (pre-commit, jsonnet-tool, shfmt, ...) are on PATH, matching a normal
|
|
16
|
+
# interactive shell.
|
|
17
|
+
if ! command -v mise >/dev/null 2>&1; then
|
|
18
|
+
echo "pre-commit validation hook requires mise to run." >&2
|
|
19
|
+
exit 1
|
|
20
|
+
fi
|
|
21
|
+
|
|
22
|
+
run() { mise exec -- "$@"; }
|
|
23
|
+
|
|
24
|
+
repo_root="$(git rev-parse --show-toplevel 2>/dev/null)" || exit 0
|
|
25
|
+
|
|
26
|
+
input="$(cat)"
|
|
27
|
+
file="$(printf '%s' "$input" | mise exec jq@1.8 -- jq -r '.tool_input.file_path // empty')"
|
|
28
|
+
[[ -z $file ]] && exit 0
|
|
29
|
+
|
|
30
|
+
# Only validate files that live inside this repository.
|
|
31
|
+
case "$file" in
|
|
32
|
+
"$repo_root"/*) ;;
|
|
33
|
+
*) exit 0 ;;
|
|
34
|
+
esac
|
|
35
|
+
|
|
36
|
+
if ! output="$(cd "$repo_root" && run pre-commit run --files "$file" 2>&1)"; then
|
|
37
|
+
{
|
|
38
|
+
echo "pre-commit reported issues on ${file#"$repo_root"/}:"
|
|
39
|
+
echo
|
|
40
|
+
echo "$output"
|
|
41
|
+
echo
|
|
42
|
+
echo "Re-read the file (hooks such as trailing-whitespace, shfmt, and"
|
|
43
|
+
echo "generate may have rewritten it) and fix any remaining problems."
|
|
44
|
+
} >&2
|
|
45
|
+
exit 2
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
exit 0
|
data/.copier-answers.yml
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# See the project for instructions on how to update the project
|
|
4
4
|
#
|
|
5
5
|
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
|
|
6
|
-
_commit: v1.
|
|
6
|
+
_commit: v1.87.1
|
|
7
7
|
_src_path: https://gitlab.com/gitlab-com/gl-infra/common-template-copier.git
|
|
8
8
|
ee_licensed: false
|
|
9
9
|
gitlab_namespace: gitlab-org/ruby/gems
|
|
@@ -17,5 +17,6 @@ release_platform: false
|
|
|
17
17
|
ruby: true
|
|
18
18
|
rubygem: true
|
|
19
19
|
rust: false
|
|
20
|
+
scaffold_target: repo
|
|
20
21
|
terraform: false
|
|
21
22
|
truncated_tags: true
|
data/.gitignore
CHANGED
data/.gitlab/CODEOWNERS
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
* @
|
|
1
|
+
* @mkaeppler @ayufan @hmerscher @sankalp_gl @hardikgala @nindurkar @ashs2
|
|
@@ -7,22 +7,22 @@
|
|
|
7
7
|
image: registry.gitlab.com/gitlab-com/gl-infra/common-ci-tasks-images/duo-workflow-sandbox:latest
|
|
8
8
|
|
|
9
9
|
setup_script:
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
-
|
|
13
|
-
- export MISE_CACHE_DIR="${CI_PROJECT_DIR}/.cache/mise/cache"
|
|
14
|
-
- mise trust --yes
|
|
15
|
-
- mise install --yes
|
|
10
|
+
# duo-workflow-setup (baked into the image) exports some variables as
|
|
11
|
+
# `export KEY=VALUE` lines on stdout, which we `eval` into the flow's shell.
|
|
12
|
+
- eval "$(/usr/local/bin/duo-workflow-setup)"
|
|
16
13
|
|
|
17
14
|
cache:
|
|
18
|
-
# Re-use installed tools as long as the version
|
|
15
|
+
# Re-use installed tools and primed pre-commit hooks as long as the version
|
|
16
|
+
# pins / hook config are unchanged.
|
|
19
17
|
key:
|
|
20
18
|
files:
|
|
21
19
|
- .tool-versions
|
|
22
20
|
- .mise.toml
|
|
21
|
+
- .pre-commit-config.yaml
|
|
23
22
|
paths:
|
|
24
23
|
- .cache/mise/data
|
|
25
24
|
- .cache/mise/cache
|
|
25
|
+
- .cache/pre-commit
|
|
26
26
|
|
|
27
27
|
network_policy:
|
|
28
28
|
# Allow the Sandbox Runtime's recommended allowlist (GitLab, package
|
data/.gitlab-ci.yml
CHANGED
|
@@ -19,13 +19,27 @@ include:
|
|
|
19
19
|
# It includes standard checks, gitlab-scanners, validations and release processes
|
|
20
20
|
# common to all projects using this template library.
|
|
21
21
|
# see https://gitlab.com/gitlab-com/gl-infra/common-ci-tasks/-/blob/main/templates/standard.md
|
|
22
|
-
- component: $CI_SERVER_FQDN/gitlab-com/gl-infra/common-ci-tasks/standard-build@v5.
|
|
22
|
+
- component: $CI_SERVER_FQDN/gitlab-com/gl-infra/common-ci-tasks/standard-build@v5.46
|
|
23
23
|
|
|
24
24
|
# Runs rspec tests and rubocop on the project
|
|
25
25
|
# see https://gitlab.com/gitlab-com/gl-infra/common-ci-tasks/-/blob/main/templates/ruby.md
|
|
26
|
-
- component: $CI_SERVER_FQDN/gitlab-com/gl-infra/common-ci-tasks/ruby-build@v5.
|
|
26
|
+
- component: $CI_SERVER_FQDN/gitlab-com/gl-infra/common-ci-tasks/ruby-build@v5.46
|
|
27
27
|
|
|
28
|
-
- component: $CI_SERVER_FQDN/gitlab-com/gl-infra/common-ci-tasks/danger@v5.
|
|
28
|
+
- component: $CI_SERVER_FQDN/gitlab-com/gl-infra/common-ci-tasks/danger@v5.46
|
|
29
|
+
|
|
30
|
+
# danger-review reads its token from Vault, which the community fork has no
|
|
31
|
+
# access to, so it fails on merge requests from the fork. Let it fail for those;
|
|
32
|
+
# the second rule is the component's own. See
|
|
33
|
+
# https://gitlab.com/gitlab-org/labkit/-/work_items/171
|
|
34
|
+
danger-review:
|
|
35
|
+
rules:
|
|
36
|
+
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_SOURCE_PROJECT_PATH == "gitlab-community/gitlab-org/ruby/gems/labkit-ruby"
|
|
37
|
+
exists:
|
|
38
|
+
- Dangerfile
|
|
39
|
+
allow_failure: true
|
|
40
|
+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
41
|
+
exists:
|
|
42
|
+
- Dangerfile
|
|
29
43
|
|
|
30
44
|
# Attach a redis service to the rspec job from common-ci-tasks/ruby-build.
|
|
31
45
|
# GitLab merges keys when a local job has the same name as an included one,
|
|
@@ -79,6 +93,13 @@ conformance-spec:
|
|
|
79
93
|
variables:
|
|
80
94
|
LABKIT_RUBY_SHA: $CI_COMMIT_SHA
|
|
81
95
|
rules:
|
|
96
|
+
# Renovate's project-token bot cannot create pipelines in labkit-spec
|
|
97
|
+
# (GitLab forbids project bots from joining other projects), so its MRs
|
|
98
|
+
# would hard-fail the bridge. Attempt the trigger but do not block; a
|
|
99
|
+
# human re-running the pipeline gates the MR properly (it runs as them).
|
|
100
|
+
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $GITLAB_USER_LOGIN =~ /^project_\d+_bot/'
|
|
101
|
+
changes: !reference [.conformance-trigger-paths, changes]
|
|
102
|
+
allow_failure: true
|
|
82
103
|
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
83
104
|
changes: !reference [.conformance-trigger-paths, changes]
|
|
84
105
|
trigger:
|
data/.mise.toml
CHANGED
|
@@ -7,6 +7,9 @@ legacy_version_file = false
|
|
|
7
7
|
# OpenSSL and sidesteps it. This becomes mise's default in 2026.8.0.
|
|
8
8
|
ruby.compile = false
|
|
9
9
|
|
|
10
|
+
# Disable sending anonymous download statistics to mise-versions.jdx.dev.
|
|
11
|
+
use_versions_host_track = false
|
|
12
|
+
|
|
10
13
|
[tools]
|
|
11
14
|
# Please continue to use `.tool-versions` to specify tool versions, rather than adding them directly here.
|
|
12
15
|
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import type { Hooks, PluginModule } from "@opencode-ai/plugin";
|
|
2
|
+
import type { Plugin } from "@opencode/plugin";
|
|
3
|
+
import { execFile, spawn } from "node:child_process";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* precommit-validate plugin
|
|
9
|
+
*
|
|
10
|
+
* OpenCode equivalent of the Claude Code PostToolUse hook defined in
|
|
11
|
+
* `.claude/hooks/precommit-validate.sh` (wired up by `.claude/settings.json`).
|
|
12
|
+
*
|
|
13
|
+
* After the agent edits or writes a file, this runs that *same* shell script to
|
|
14
|
+
* validate the file against the repo's pre-commit rules. When pre-commit reports
|
|
15
|
+
* problems, the findings are appended to the tool result so the agent sees them
|
|
16
|
+
* on its next turn and can fix the file. A clean run is silent.
|
|
17
|
+
*
|
|
18
|
+
* The script's exit codes mirror Claude Code's hook contract, so we honour the
|
|
19
|
+
* same distinction here:
|
|
20
|
+
* - 0 = clean or no-op (silent)
|
|
21
|
+
* - 2 = pre-commit reported issues; feed the report back to the model
|
|
22
|
+
* - any other non-zero = non-blocking error (e.g. mise missing); log it for
|
|
23
|
+
* the user but do not nag the model, since it can't fix its environment.
|
|
24
|
+
*
|
|
25
|
+
* The script is reused verbatim: it reads Claude Code's PostToolUse payload on
|
|
26
|
+
* stdin (`{ "tool_input": { "file_path": "..." } }`), so we synthesize that same
|
|
27
|
+
* shape here from OpenCode's tool input.
|
|
28
|
+
*
|
|
29
|
+
* Supports both plugin APIs from one default export, as described in
|
|
30
|
+
* https://opencode.ai/v2/docs/build/plugins/migrate-v1:
|
|
31
|
+
* - OpenCode 2 reads `id` and `setup()` (the `@opencode/plugin` API).
|
|
32
|
+
* - OpenCode 1 (>= 1.18.29) calls `server()` (the `@opencode-ai/plugin` API).
|
|
33
|
+
* Both imports are type-only, so neither OpenCode version needs the other's
|
|
34
|
+
* plugin package installed at runtime. Remove `server()` once V1 is gone.
|
|
35
|
+
*
|
|
36
|
+
* Auto-loaded from `.opencode/plugins/`.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
const ID = "precommit-validate";
|
|
40
|
+
|
|
41
|
+
const HOOK_SCRIPT = ".claude/hooks/precommit-validate.sh";
|
|
42
|
+
|
|
43
|
+
// OpenCode file-mutating tools, analogous to Claude Code's `Edit|Write|MultiEdit`
|
|
44
|
+
// matcher. V1 and V2 both have `edit` and `write`; patches go through
|
|
45
|
+
// `apply_patch` in V1 and `patch` in V2.
|
|
46
|
+
const FILE_TOOLS = new Set(["apply_patch", "edit", "patch", "write"]);
|
|
47
|
+
|
|
48
|
+
interface HookResult {
|
|
49
|
+
/** Exit code 2: pre-commit findings to feed back to the model. */
|
|
50
|
+
readonly reports: string[];
|
|
51
|
+
/** Any other failure: environment problems to log for the user. */
|
|
52
|
+
readonly warnings: string[];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const asRecord = (value: unknown): Record<string, unknown> =>
|
|
56
|
+
value && typeof value === "object" && !Array.isArray(value) ? (value as Record<string, unknown>) : {};
|
|
57
|
+
|
|
58
|
+
const asString = (value: unknown): string | undefined => (typeof value === "string" && value ? value : undefined);
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Collect the files a tool call touched from its input and result metadata.
|
|
62
|
+
*
|
|
63
|
+
* Input: V2 `edit`/`write` take `path`; V1 takes `filePath`.
|
|
64
|
+
* Metadata: `files` entries carry `file` in V2 and `filePath` in V1. This is
|
|
65
|
+
* the only source for patch tools, whose input is a single `patchText` blob.
|
|
66
|
+
*/
|
|
67
|
+
function touchedFiles(input: unknown, metadata: unknown): Set<string> {
|
|
68
|
+
const args = asRecord(input);
|
|
69
|
+
const files = new Set<string>();
|
|
70
|
+
|
|
71
|
+
const direct = asString(args.path) ?? asString(args.filePath);
|
|
72
|
+
if (direct) files.add(direct);
|
|
73
|
+
|
|
74
|
+
const entries = asRecord(metadata).files;
|
|
75
|
+
for (const entry of Array.isArray(entries) ? entries : []) {
|
|
76
|
+
const file = asRecord(entry);
|
|
77
|
+
// A deleted file has nothing left to validate.
|
|
78
|
+
if (file.status === "deleted" || file.type === "delete") continue;
|
|
79
|
+
const path = asString(file.file) ?? asString(file.filePath);
|
|
80
|
+
if (path) files.add(path);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return files;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Run the shared hook script for one file, feeding the payload on stdin. */
|
|
87
|
+
function runHookScript(
|
|
88
|
+
script: string,
|
|
89
|
+
root: string,
|
|
90
|
+
payload: string,
|
|
91
|
+
signal?: AbortSignal,
|
|
92
|
+
): Promise<{ code: number | null; stdout: string; stderr: string }> {
|
|
93
|
+
return new Promise((done, fail) => {
|
|
94
|
+
const child = spawn(script, [], { cwd: root, signal, stdio: ["pipe", "pipe", "pipe"] });
|
|
95
|
+
let stdout = "";
|
|
96
|
+
let stderr = "";
|
|
97
|
+
child.stdout.setEncoding("utf8").on("data", (chunk: string) => (stdout += chunk));
|
|
98
|
+
child.stderr.setEncoding("utf8").on("data", (chunk: string) => (stderr += chunk));
|
|
99
|
+
// The script exits early (e.g. mise missing) without reading stdin.
|
|
100
|
+
child.stdin.on("error", () => {});
|
|
101
|
+
child.on("error", fail);
|
|
102
|
+
child.on("close", (code) => done({ code, stdout, stderr }));
|
|
103
|
+
child.stdin.end(payload);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Validate every touched file and sort the outcomes into reports and warnings. */
|
|
108
|
+
async function validate(root: string, filePaths: Iterable<string>, signal?: AbortSignal): Promise<HookResult> {
|
|
109
|
+
const result: HookResult = { reports: [], warnings: [] };
|
|
110
|
+
const script = join(root, HOOK_SCRIPT);
|
|
111
|
+
// Inert when the shared script is absent (e.g. loaded in another repo).
|
|
112
|
+
if (!existsSync(script)) return result;
|
|
113
|
+
|
|
114
|
+
for (const filePath of filePaths) {
|
|
115
|
+
if (signal?.aborted) break;
|
|
116
|
+
const absolute = isAbsolute(filePath) ? filePath : resolve(root, filePath);
|
|
117
|
+
|
|
118
|
+
// Same JSON shape Claude Code's PostToolUse hook delivers on stdin. The
|
|
119
|
+
// script itself decides whether the file lives inside the repo.
|
|
120
|
+
const payload = JSON.stringify({ tool_input: { file_path: absolute } });
|
|
121
|
+
|
|
122
|
+
let run: Awaited<ReturnType<typeof runHookScript>>;
|
|
123
|
+
try {
|
|
124
|
+
run = await runHookScript(script, root, payload, signal);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (signal?.aborted) break; // plugin unloaded mid-run
|
|
127
|
+
result.warnings.push(`pre-commit validation hook failed to start: ${String(error)}`);
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (run.code === 0) continue; // clean / no-op
|
|
132
|
+
|
|
133
|
+
const report = run.stderr.trim() || run.stdout.trim();
|
|
134
|
+
|
|
135
|
+
if (run.code === 2) {
|
|
136
|
+
// Blocking: pre-commit reported issues. Surface them to the model, the
|
|
137
|
+
// OpenCode equivalent of feeding the hook's stderr back to Claude Code.
|
|
138
|
+
if (report) result.reports.push(report);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Non-blocking error (e.g. exit 1 = mise not on PATH). Not something the
|
|
143
|
+
// model can act on, so log it for the user instead of polluting the turn.
|
|
144
|
+
result.warnings.push(report || `pre-commit validation hook exited ${run.code}`);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const formatReports = (reports: string[]): string =>
|
|
151
|
+
`<pre-commit-validation>\n${reports.join("\n\n")}\n</pre-commit-validation>`;
|
|
152
|
+
|
|
153
|
+
/** The repository root, so the hook script is found from any subdirectory. */
|
|
154
|
+
function gitToplevel(directory: string): Promise<string> {
|
|
155
|
+
return new Promise((done) => {
|
|
156
|
+
execFile("git", ["rev-parse", "--show-toplevel"], { cwd: directory }, (error, stdout) => {
|
|
157
|
+
done(error ? directory : stdout.trim() || directory);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** OpenCode 2 implementation (`@opencode/plugin`). */
|
|
163
|
+
const v2: Plugin.Plugin = {
|
|
164
|
+
id: ID,
|
|
165
|
+
async setup(ctx) {
|
|
166
|
+
const root = await gitToplevel(ctx.location.directory);
|
|
167
|
+
// Hook events carry no abort signal; stop in-flight runs on unload instead.
|
|
168
|
+
const controller = new AbortController();
|
|
169
|
+
|
|
170
|
+
await ctx.tool.hook("execute.after", async (event) => {
|
|
171
|
+
if (event.status !== "completed") return;
|
|
172
|
+
if (!FILE_TOOLS.has(event.tool)) return;
|
|
173
|
+
|
|
174
|
+
const filePaths = touchedFiles(event.input, event.result.metadata);
|
|
175
|
+
if (filePaths.size === 0) return;
|
|
176
|
+
|
|
177
|
+
const { reports, warnings } = await validate(root, filePaths, controller.signal);
|
|
178
|
+
|
|
179
|
+
for (const warning of warnings) console.warn(`[${ID}] ${warning}`);
|
|
180
|
+
|
|
181
|
+
if (reports.length === 0) return;
|
|
182
|
+
|
|
183
|
+
// Results are read-only: replace the result, appending to its content.
|
|
184
|
+
const text = formatReports(reports);
|
|
185
|
+
const content = event.result.content;
|
|
186
|
+
event.result = {
|
|
187
|
+
...event.result,
|
|
188
|
+
content:
|
|
189
|
+
typeof content === "string" || content === undefined
|
|
190
|
+
? content ? `${content}\n\n${text}` : text
|
|
191
|
+
: [...content, { type: "text", text }],
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
return () => controller.abort();
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/** OpenCode 1 implementation (`@opencode-ai/plugin`, >= 1.18.29). */
|
|
200
|
+
const v1: PluginModule = {
|
|
201
|
+
id: ID,
|
|
202
|
+
async server({ client, directory, worktree }) {
|
|
203
|
+
const root = worktree || directory;
|
|
204
|
+
|
|
205
|
+
const hooks: Hooks = {
|
|
206
|
+
"tool.execute.after": async (input, output) => {
|
|
207
|
+
if (!FILE_TOOLS.has(input.tool)) return;
|
|
208
|
+
|
|
209
|
+
const filePaths = touchedFiles(input.args, output.metadata);
|
|
210
|
+
if (filePaths.size === 0) return;
|
|
211
|
+
|
|
212
|
+
const { reports, warnings } = await validate(root, filePaths);
|
|
213
|
+
|
|
214
|
+
for (const warning of warnings) {
|
|
215
|
+
await client.app.log({ body: { service: ID, level: "warn", message: warning } });
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (reports.length > 0) output.output += `\n\n${formatReports(reports)}`;
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
return hooks;
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
export default { ...v2, server: v1.server };
|
data/.pre-commit-config.yaml
CHANGED
|
@@ -15,7 +15,7 @@ repos:
|
|
|
15
15
|
- id: check-json
|
|
16
16
|
- id: detect-private-key
|
|
17
17
|
- id: mixed-line-ending
|
|
18
|
-
args: [
|
|
18
|
+
args: [--fix=lf]
|
|
19
19
|
- id: no-commit-to-branch
|
|
20
20
|
args: [--branch, main]
|
|
21
21
|
- id: pretty-format-json
|
|
@@ -25,7 +25,7 @@ repos:
|
|
|
25
25
|
# Documentation available at
|
|
26
26
|
# https://gitlab.com/gitlab-com/gl-infra/common-ci-tasks/-/blob/main/docs/pre-commit.md
|
|
27
27
|
- repo: https://gitlab.com/gitlab-com/gl-infra/common-ci-tasks
|
|
28
|
-
rev: v5.
|
|
28
|
+
rev: v5.46 # renovate:managed
|
|
29
29
|
|
|
30
30
|
hooks:
|
|
31
31
|
- id: shellcheck # Run shellcheck for changed Shell files
|
|
@@ -36,3 +36,4 @@ repos:
|
|
|
36
36
|
- id: gitleaks # Detect hardcoded secrets using Gitleaks
|
|
37
37
|
- id: editorconfig # Validate text files against .editorconfig
|
|
38
38
|
- id: yamllint # Validate YAML files using yamllint
|
|
39
|
+
- id: ensure-claude-md
|
data/.rubocop_todo.yml
CHANGED
|
@@ -151,12 +151,6 @@ Lint/SymbolConversion:
|
|
|
151
151
|
- 'spec/labkit/logging/json_logger_spec.rb'
|
|
152
152
|
- 'spec/support/tracing/shared_examples.rb'
|
|
153
153
|
|
|
154
|
-
# Offense count: 1
|
|
155
|
-
# Configuration parameters: Methods.
|
|
156
|
-
Lint/UnexpectedBlockArity:
|
|
157
|
-
Exclude:
|
|
158
|
-
- 'tools/update-changelog.rb'
|
|
159
|
-
|
|
160
154
|
# Offense count: 41
|
|
161
155
|
# This cop supports safe autocorrection (--autocorrect).
|
|
162
156
|
# Configuration parameters: AutoCorrect, AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods, NotImplementedExceptions.
|
|
@@ -196,13 +190,6 @@ Naming/RescuedExceptionsVariableName:
|
|
|
196
190
|
Exclude:
|
|
197
191
|
- 'lib/labkit/logging/grpc/server_interceptor.rb'
|
|
198
192
|
|
|
199
|
-
# Offense count: 1
|
|
200
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
201
|
-
# Configuration parameters: EnabledForFlattenWithoutParams.
|
|
202
|
-
Performance/FlatMap:
|
|
203
|
-
Exclude:
|
|
204
|
-
- 'tools/update-changelog.rb'
|
|
205
|
-
|
|
206
193
|
# Offense count: 1
|
|
207
194
|
Performance/MethodObjectAsBlock:
|
|
208
195
|
Exclude:
|
|
@@ -402,7 +389,7 @@ Style/FileNull:
|
|
|
402
389
|
- 'spec/labkit/middleware/sidekiq/user_experience_sli/server_spec.rb'
|
|
403
390
|
- 'spec/spec_helper.rb'
|
|
404
391
|
|
|
405
|
-
# Offense count:
|
|
392
|
+
# Offense count: 7
|
|
406
393
|
# This cop supports unsafe autocorrection (--autocorrect-all).
|
|
407
394
|
# Configuration parameters: EnforcedStyle.
|
|
408
395
|
# SupportedStyles: always, always_true, never
|
|
@@ -415,7 +402,6 @@ Style/FrozenStringLiteralComment:
|
|
|
415
402
|
- 'spec/labkit/tracing/rails/active_support/cache_read_instrumenter_spec.rb'
|
|
416
403
|
- 'spec/labkit/tracing/rails/active_support/cache_write_instrumenter_spec.rb'
|
|
417
404
|
- 'spec/support/grpc_service/test_services_pb.rb'
|
|
418
|
-
- 'tools/update-changelog.rb'
|
|
419
405
|
|
|
420
406
|
# Offense count: 2
|
|
421
407
|
# This cop supports unsafe autocorrection (--autocorrect-all).
|
|
@@ -539,7 +525,7 @@ Style/StringConcatenation:
|
|
|
539
525
|
- 'lib/labkit/tracing/jaeger_factory.rb'
|
|
540
526
|
- 'lib/labkit/tracing/redis/redis_interceptor_helper.rb'
|
|
541
527
|
|
|
542
|
-
# Offense count:
|
|
528
|
+
# Offense count: 4
|
|
543
529
|
# This cop supports safe autocorrection (--autocorrect).
|
|
544
530
|
# Configuration parameters: EnforcedStyle.
|
|
545
531
|
# SupportedStyles: single_quotes, double_quotes
|
|
@@ -549,7 +535,6 @@ Style/StringLiteralsInInterpolation:
|
|
|
549
535
|
- 'lib/labkit/tracing/grpc/server_interceptor.rb'
|
|
550
536
|
- 'lib/labkit/tracing/jaeger_factory.rb'
|
|
551
537
|
- 'spec/labkit/logging/json_logger_spec.rb'
|
|
552
|
-
- 'tools/update-changelog.rb'
|
|
553
538
|
|
|
554
539
|
# Offense count: 10
|
|
555
540
|
# This cop supports safe autocorrection (--autocorrect).
|