@rvdbreemen/adr-kit-opencode 0.52.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.
Files changed (129) hide show
  1. package/.claude-plugin/plugin.json +29 -0
  2. package/LICENSE +21 -0
  3. package/README.md +850 -0
  4. package/bin/adr +1552 -0
  5. package/bin/adr-audit +454 -0
  6. package/bin/adr-context +584 -0
  7. package/bin/adr-discover +546 -0
  8. package/bin/adr-doctor +166 -0
  9. package/bin/adr-generate-scripts +421 -0
  10. package/bin/adr-grill-signal +131 -0
  11. package/bin/adr-guardian +1263 -0
  12. package/bin/adr-index +199 -0
  13. package/bin/adr-judge +2832 -0
  14. package/bin/adr-judge-precommit +87 -0
  15. package/bin/adr-lint +2087 -0
  16. package/bin/adr-mcp +1093 -0
  17. package/bin/adr-migrate +644 -0
  18. package/bin/adr-quality +275 -0
  19. package/bin/adr-readiness +211 -0
  20. package/bin/adr-readiness-ci +111 -0
  21. package/bin/adr-related +401 -0
  22. package/bin/adr-renumber +254 -0
  23. package/bin/adr-retire +467 -0
  24. package/bin/adr-settings +399 -0
  25. package/bin/adr-status +797 -0
  26. package/bin/adr-suggest +803 -0
  27. package/bin/adr-watch +674 -0
  28. package/bin/adr_catalog.py +536 -0
  29. package/bin/adr_config.py +280 -0
  30. package/bin/adr_doctor_checks.py +407 -0
  31. package/bin/adr_doctor_core.py +342 -0
  32. package/bin/adr_doctor_models.py +186 -0
  33. package/bin/adr_doctor_probes.py +216 -0
  34. package/bin/adr_format.py +786 -0
  35. package/bin/adr_grill_signal.py +123 -0
  36. package/bin/adr_guardian_queue.py +218 -0
  37. package/bin/adr_history_scan.py +278 -0
  38. package/bin/adr_index_core.py +443 -0
  39. package/bin/adr_llm.py +333 -0
  40. package/bin/adr_llm_judge_migration.py +314 -0
  41. package/bin/adr_quality_core.py +674 -0
  42. package/bin/adr_query.py +678 -0
  43. package/bin/adr_readiness.py +442 -0
  44. package/bin/adr_readiness_ci.py +123 -0
  45. package/bin/adr_regex.py +165 -0
  46. package/bin/adr_regex_worker.py +30 -0
  47. package/bin/adr_retrieval_health.py +385 -0
  48. package/bin/adr_schema.py +448 -0
  49. package/bin/adr_state.py +172 -0
  50. package/bin/bump-version +71 -0
  51. package/clients/workflows.json +229 -0
  52. package/hooks/__init__.py +1 -0
  53. package/hooks/adapters/__init__.py +13 -0
  54. package/hooks/adapters/claude.py +27 -0
  55. package/hooks/adapters/codex.py +26 -0
  56. package/hooks/adapters/copilot.py +11 -0
  57. package/hooks/adr-hook.py +128 -0
  58. package/hooks/adr_hook_core.py +843 -0
  59. package/hooks/adr_pr_guard.py +367 -0
  60. package/instructions/ADR-guide.md +48 -0
  61. package/instructions/adr.coding.md +82 -0
  62. package/instructions/adr.review.md +182 -0
  63. package/opencode/plugin.ts +451 -0
  64. package/package.json +41 -0
  65. package/schemas/adr-context-probes.schema.json +56 -0
  66. package/schemas/adr-enforcement.schema.json +57 -0
  67. package/schemas/adr-frontmatter.schema.json +144 -0
  68. package/schemas/adr-index.schema.json +276 -0
  69. package/schemas/adr-kit-config.schema.json +371 -0
  70. package/schemas/adr-readiness.schema.json +41 -0
  71. package/schemas/client-capabilities.schema.json +503 -0
  72. package/schemas/client-certification.schema.json +101 -0
  73. package/schemas/doctor-output.schema.json +92 -0
  74. package/schemas/marketplace.json.schema.json +70 -0
  75. package/schemas/plugin.json.schema.json +67 -0
  76. package/scripts/adr_settings.py +239 -0
  77. package/scripts/benchmark-adr-grilling.py +323 -0
  78. package/scripts/benchmark-client-generation.py +178 -0
  79. package/scripts/build-client-adapters.py +139 -0
  80. package/scripts/bump-version.py +304 -0
  81. package/scripts/check-branch-sync.py +243 -0
  82. package/scripts/check-release-version.py +81 -0
  83. package/scripts/client_certification.py +153 -0
  84. package/scripts/client_evidence.py +280 -0
  85. package/scripts/client_generation.py +288 -0
  86. package/scripts/client_generation_artifacts.py +351 -0
  87. package/scripts/client_generation_model.py +173 -0
  88. package/scripts/client_generation_state.py +260 -0
  89. package/scripts/client_support_matrix.py +360 -0
  90. package/scripts/install-agent-envs.py +300 -0
  91. package/scripts/probe-client-events.py +183 -0
  92. package/scripts/project_setup.py +379 -0
  93. package/scripts/refresh-otgw-corpus.py +219 -0
  94. package/scripts/settings.py +81 -0
  95. package/scripts/setup-project.py +205 -0
  96. package/scripts/sync-agent-plugins.py +17 -0
  97. package/scripts/version_sites.py +377 -0
  98. package/skills/adr/SKILL.md +780 -0
  99. package/skills/audit/SKILL.md +103 -0
  100. package/skills/context/SKILL.md +77 -0
  101. package/skills/grill/SKILL.md +84 -0
  102. package/skills/grill/agents/openai.yaml +4 -0
  103. package/skills/guardian/SKILL.md +316 -0
  104. package/skills/init/SKILL.md +499 -0
  105. package/skills/install-hooks/SKILL.md +154 -0
  106. package/skills/judge/SKILL.md +168 -0
  107. package/skills/lint/SKILL.md +321 -0
  108. package/skills/migrate/SKILL.md +313 -0
  109. package/skills/related/SKILL.md +62 -0
  110. package/skills/retire/SKILL.md +41 -0
  111. package/skills/review/SKILL.md +167 -0
  112. package/skills/settings/SKILL.md +73 -0
  113. package/skills/setup/SKILL.md +128 -0
  114. package/skills/supersede/SKILL.md +136 -0
  115. package/skills/upgrade/SKILL.md +273 -0
  116. package/templates/adr-kit-guide.md +354 -0
  117. package/templates/adr-template.canonical.md +115 -0
  118. package/templates/adr-template.madr.md +131 -0
  119. package/templates/adr-template.md +131 -0
  120. package/templates/adr-template.nygard.md +111 -0
  121. package/templates/cc-settings/guardian-hook-entry.json +9 -0
  122. package/templates/githooks/pre-commit +337 -0
  123. package/templates/github-workflows/adr-audit.yml +58 -0
  124. package/templates/github-workflows/adr-guardian-audit.yml +133 -0
  125. package/templates/github-workflows/adr-index-check.yml +30 -0
  126. package/templates/github-workflows/adr-judge.yml +31 -0
  127. package/templates/github-workflows/adr-readiness.yml +18 -0
  128. package/templates/validate_adr_template.py +38 -0
  129. package/templates/validate_adr_template.sh +74 -0
@@ -0,0 +1,451 @@
1
+ import { existsSync, readFileSync } from "node:fs"
2
+ import { dirname, join, resolve } from "node:path"
3
+ import { fileURLToPath } from "node:url"
4
+
5
+ type AnyRecord = Record<string, any>
6
+
7
+ type PluginOptions = {
8
+ root?: string
9
+ python?: string
10
+ mcp?: boolean
11
+ skills?: boolean
12
+ commands?: boolean
13
+ instructions?: boolean
14
+ references?: boolean
15
+ hooks?: boolean
16
+ hookTimeoutMs?: number
17
+ }
18
+
19
+ type HookResult = {
20
+ context: string
21
+ denied: boolean
22
+ reason: string
23
+ }
24
+
25
+ type SessionState = {
26
+ context: string
27
+ contextKind: string
28
+ }
29
+
30
+ declare const Bun: {
31
+ spawn(
32
+ command: string[],
33
+ options: {
34
+ cwd: string
35
+ stdin: "pipe"
36
+ stdout: "pipe"
37
+ stderr: "ignore"
38
+ },
39
+ ): {
40
+ stdin: { write(value: string): void; end(): void }
41
+ stdout: ReadableStream<Uint8Array>
42
+ exited: Promise<number>
43
+ kill(): void
44
+ }
45
+ }
46
+
47
+ const PACKAGE_DIR = dirname(fileURLToPath(import.meta.url))
48
+ const PACKAGE_ROOT = dirname(PACKAGE_DIR)
49
+ const MAX_CONTEXT_CHARS = 4096
50
+ const MAX_INPUT_CHARS = 8192
51
+ const MAX_OUTPUT_CHARS = 16384
52
+ const DEFAULT_HOOK_TIMEOUT_MS = 2000
53
+ const PR_HOOK_TIMEOUT_MS = 5000
54
+ const ADR_CONTEXT_MARKER = "<adr-kit-context>"
55
+ const ADR_SYSTEM_MARKER = "<adr-kit-instructions>"
56
+ const WRITE_TOOLS = new Set(["edit", "multiedit", "write", "patch", "apply_patch"])
57
+ const SHELL_TOOLS = new Set(["bash", "shell", "terminal", "run"])
58
+
59
+ const STATIC_INSTRUCTIONS = `${ADR_SYSTEM_MARKER}
60
+ ADR Kit is active for this OpenCode project. Use the adr-kit MCP server to find
61
+ the governing Accepted ADRs before implementation and to judge diffs when asked.
62
+ Hook context is advisory and fail-open. The deterministic pre-commit and CI
63
+ judge remain the only normal enforcement floor. Never treat a retrieval result
64
+ as binding until you read the linked Markdown ADR.
65
+ </adr-kit-instructions>`
66
+
67
+ function isRuntimeRoot(path: string): boolean {
68
+ return (
69
+ existsSync(join(path, "bin", "adr-mcp")) &&
70
+ existsSync(join(path, "hooks", "adr-hook.py")) &&
71
+ existsSync(join(path, "skills"))
72
+ )
73
+ }
74
+
75
+ function ancestors(start: string): string[] {
76
+ const result: string[] = []
77
+ let current = resolve(start)
78
+ while (!result.includes(current)) {
79
+ result.push(current)
80
+ const parent = dirname(current)
81
+ if (parent === current) break
82
+ current = parent
83
+ }
84
+ return result
85
+ }
86
+
87
+ function findRuntimeRoot(
88
+ explicit: string | undefined,
89
+ directory: string,
90
+ worktree: string,
91
+ ): string | undefined {
92
+ const candidates = [explicit, process.env.ADR_KIT_ROOT, PACKAGE_ROOT, directory, worktree]
93
+ .filter((value): value is string => Boolean(value))
94
+ .map((value) => (explicit === value && !value.startsWith("/") && !/^[A-Za-z]:[\\/]/.test(value)
95
+ ? resolve(directory, value)
96
+ : resolve(value)))
97
+
98
+ for (const candidate of candidates) {
99
+ for (const path of ancestors(candidate)) {
100
+ if (isRuntimeRoot(path)) return path
101
+ }
102
+ }
103
+ return undefined
104
+ }
105
+
106
+ function unique(values: string[]): string[] {
107
+ return Array.from(new Set(values.filter(Boolean)))
108
+ }
109
+
110
+ function bounded(value: unknown, limit: number): string {
111
+ return typeof value === "string" ? value.slice(0, limit) : ""
112
+ }
113
+
114
+ function sessionKey(sessionID: string | undefined): string {
115
+ return sessionID || "__workspace__"
116
+ }
117
+
118
+ function stateFor(sessions: Map<string, SessionState>, sessionID: string | undefined): SessionState {
119
+ const key = sessionKey(sessionID)
120
+ let state = sessions.get(key)
121
+ if (!state) {
122
+ state = { context: "", contextKind: "" }
123
+ sessions.set(key, state)
124
+ }
125
+ return state
126
+ }
127
+
128
+ function promptText(parts: unknown): string {
129
+ if (!Array.isArray(parts)) return ""
130
+ return parts
131
+ .filter((part): part is AnyRecord => Boolean(part) && typeof part === "object")
132
+ .filter((part) => part.type === "text")
133
+ .map((part) => bounded(part.text, MAX_INPUT_CHARS))
134
+ .filter(Boolean)
135
+ .join("\n")
136
+ .slice(0, MAX_INPUT_CHARS)
137
+ }
138
+
139
+ function readJson(path: string): AnyRecord | undefined {
140
+ try {
141
+ const value = JSON.parse(readFileSync(path, "utf8"))
142
+ return value && typeof value === "object" ? value : undefined
143
+ } catch {
144
+ return undefined
145
+ }
146
+ }
147
+
148
+ function extractHookResult(raw: string): HookResult {
149
+ for (const line of raw.split(/\r?\n/).filter(Boolean)) {
150
+ try {
151
+ const value = JSON.parse(line) as AnyRecord
152
+ const specific = value.hookSpecificOutput && typeof value.hookSpecificOutput === "object"
153
+ ? value.hookSpecificOutput
154
+ : {}
155
+ const context = bounded(
156
+ specific.additionalContext || value.additionalContext,
157
+ MAX_CONTEXT_CHARS,
158
+ )
159
+ const denied = specific.permissionDecision === "deny" || value.permissionDecision === "deny"
160
+ const reason = bounded(
161
+ specific.permissionDecisionReason || value.permissionDecisionReason || context,
162
+ MAX_CONTEXT_CHARS,
163
+ )
164
+ return { context, denied, reason }
165
+ } catch {
166
+ // The shared hook is fail-open. Ignore malformed output and continue.
167
+ }
168
+ }
169
+ return { context: "", denied: false, reason: "" }
170
+ }
171
+
172
+ async function runHook(
173
+ runtimeRoot: string | undefined,
174
+ python: string,
175
+ cwd: string,
176
+ event: string,
177
+ sessionID: string | undefined,
178
+ payload: AnyRecord,
179
+ timeoutMs: number,
180
+ ): Promise<HookResult> {
181
+ if (!runtimeRoot) return { context: "", denied: false, reason: "" }
182
+ const hook = join(runtimeRoot, "hooks", "adr-hook.py")
183
+ if (!existsSync(hook)) return { context: "", denied: false, reason: "" }
184
+
185
+ let child: ReturnType<typeof Bun.spawn>
186
+ try {
187
+ child = Bun.spawn(
188
+ [python, hook, "--client", "claude-code-cli", "--event", event],
189
+ { cwd, stdin: "pipe", stdout: "pipe", stderr: "ignore" },
190
+ )
191
+ child.stdin.write(JSON.stringify({
192
+ cwd,
193
+ hook_event_name: event,
194
+ session_id: sessionID,
195
+ ...payload,
196
+ }))
197
+ child.stdin.end()
198
+ } catch {
199
+ return { context: "", denied: false, reason: "" }
200
+ }
201
+
202
+ let timer: ReturnType<typeof setTimeout> | undefined
203
+ const output = new Response(child.stdout).text().catch(() => "")
204
+ const completed = Promise.all([
205
+ output,
206
+ child.exited.catch(() => -1),
207
+ ]).then(([value, exitCode]) => ({ timedOut: false, value, exitCode }))
208
+ const result = await Promise.race([
209
+ completed,
210
+ new Promise<{ timedOut: true; value: string }>((resolveResult) => {
211
+ timer = setTimeout(() => resolveResult({ timedOut: true, value: "" }), timeoutMs)
212
+ }),
213
+ ])
214
+ if (timer) clearTimeout(timer)
215
+ if (result.timedOut) {
216
+ try { child.kill() } catch { /* fail open */ }
217
+ return { context: "", denied: false, reason: "" }
218
+ }
219
+
220
+ if (result.exitCode !== 0) return { context: "", denied: false, reason: "" }
221
+ return extractHookResult(result.value.slice(0, MAX_OUTPUT_CHARS))
222
+ }
223
+
224
+ function toolName(value: unknown): string {
225
+ return bounded(value, 80).toLowerCase().replace(/[^a-z0-9_]/g, "")
226
+ }
227
+
228
+ function toolPath(args: AnyRecord): string {
229
+ for (const key of ["filePath", "file_path", "path", "notebook_path"]) {
230
+ if (typeof args[key] === "string") return args[key]
231
+ }
232
+ return ""
233
+ }
234
+
235
+ function hookTimeout(options: PluginOptions, fallback: number): number {
236
+ const configured = options.hookTimeoutMs
237
+ if (!Number.isInteger(configured)) return fallback
238
+ return Math.max(100, Math.min(PR_HOOK_TIMEOUT_MS, configured))
239
+ }
240
+
241
+ function addContext(sessions: Map<string, SessionState>, sessionID: string | undefined, result: HookResult, kind: string): void {
242
+ if (!result.context) return
243
+ const state = stateFor(sessions, sessionID)
244
+ state.context = result.context
245
+ state.contextKind = kind
246
+ }
247
+
248
+ function commandTemplate(root: string, workflow: AnyRecord): string {
249
+ const procedure = Array.isArray(workflow.procedure)
250
+ ? workflow.procedure.map((item) => `- ${String(item).replaceAll("<plugin-root>", root)}`).join("\n")
251
+ : "- Follow the ADR Kit documentation and use the adr-kit MCP tools."
252
+ return [
253
+ `Run the ADR Kit '${workflow.id}' workflow in OpenCode.`,
254
+ "",
255
+ "User task or arguments:",
256
+ "$ARGUMENTS",
257
+ "",
258
+ "Use the active project's adr-kit MCP server and read linked Markdown ADRs before treating a decision as binding.",
259
+ "",
260
+ "Procedure:",
261
+ procedure,
262
+ ].join("\n")
263
+ }
264
+
265
+ export default async function AdrKitOpenCodePlugin(
266
+ input: { directory: string; worktree: string },
267
+ rawOptions: AnyRecord = {},
268
+ ) {
269
+ const options = rawOptions as PluginOptions
270
+ const runtimeRoot = findRuntimeRoot(options.root, input.directory, input.worktree)
271
+ const python = options.python || process.env.ADR_KIT_PYTHON || "python"
272
+ const sessions = new Map<string, SessionState>()
273
+
274
+ return {
275
+ config: async (rawConfig: AnyRecord) => {
276
+ if (!runtimeRoot) return
277
+ const config = rawConfig as AnyRecord
278
+
279
+ if (options.skills !== false) {
280
+ config.skills ||= {}
281
+ config.skills.paths = unique([...(Array.isArray(config.skills.paths) ? config.skills.paths : []), join(runtimeRoot, "skills")])
282
+ }
283
+
284
+ if (options.instructions !== false) {
285
+ const instructions = Array.isArray(config.instructions) ? config.instructions : []
286
+ const candidates = [
287
+ join(runtimeRoot, "instructions", "ADR-guide.md"),
288
+ join(input.directory, ".adr-kit", "ADR-guide.md"),
289
+ ].filter((path) => existsSync(path))
290
+ config.instructions = unique([...instructions, ...candidates])
291
+ }
292
+
293
+ if (options.references !== false && existsSync(join(input.directory, "docs", "adr"))) {
294
+ config.references ||= {}
295
+ if (!config.references["adr-decisions"]) {
296
+ config.references["adr-decisions"] = {
297
+ path: join(input.directory, "docs", "adr"),
298
+ description: "Architecture Decision Records. Read returned Markdown before applying a decision.",
299
+ }
300
+ }
301
+ }
302
+
303
+ if (options.mcp !== false && process.env.ADR_KIT_OPENCODE_MCP !== "0") {
304
+ config.mcp ||= {}
305
+ if (!config.mcp["adr-kit"]) {
306
+ config.mcp["adr-kit"] = {
307
+ type: "local",
308
+ command: [python, join(runtimeRoot, "bin", "adr-mcp"), "--root", input.directory],
309
+ cwd: input.directory,
310
+ enabled: true,
311
+ timeout: 60000,
312
+ environment: { PROJECT_ROOT: input.directory },
313
+ }
314
+ }
315
+ }
316
+
317
+ if (options.commands !== false) {
318
+ const workflows = readJson(join(runtimeRoot, "clients", "workflows.json"))
319
+ if (Array.isArray(workflows?.workflows)) {
320
+ config.command ||= {}
321
+ for (const workflow of workflows.workflows) {
322
+ if (!workflow || typeof workflow.id !== "string") continue
323
+ const name = `adr-kit-${workflow.id}`
324
+ if (config.command[name]) continue
325
+ config.command[name] = {
326
+ description: `ADR Kit: ${workflow.description || workflow.title || workflow.id}`,
327
+ template: commandTemplate(runtimeRoot, workflow),
328
+ }
329
+ }
330
+ }
331
+ }
332
+ },
333
+
334
+ "shell.env": async (_hookInput: { cwd: string }, output: { env: Record<string, string> }) => {
335
+ if (runtimeRoot && !output.env.ADR_KIT_ROOT) output.env.ADR_KIT_ROOT = runtimeRoot
336
+ },
337
+
338
+ "chat.message": async (
339
+ hookInput: { sessionID: string },
340
+ output: { parts: unknown[] },
341
+ ) => {
342
+ if (options.hooks === false) return
343
+ const prompt = promptText(output.parts)
344
+ if (!prompt) return
345
+ const result = await runHook(
346
+ runtimeRoot,
347
+ python,
348
+ input.directory,
349
+ "UserPromptSubmit",
350
+ hookInput.sessionID,
351
+ { prompt },
352
+ hookTimeout(options, DEFAULT_HOOK_TIMEOUT_MS),
353
+ )
354
+ addContext(sessions, hookInput.sessionID, result, "prompt")
355
+ },
356
+
357
+ "experimental.chat.system.transform": async (
358
+ hookInput: { sessionID?: string },
359
+ output: { system: string[] },
360
+ ) => {
361
+ if (!output.system.some((item) => item.includes(ADR_SYSTEM_MARKER))) {
362
+ output.system.push(STATIC_INSTRUCTIONS)
363
+ }
364
+ const state = sessions.get(sessionKey(hookInput.sessionID))
365
+ if (state?.context && !output.system.some((item) => item.includes(ADR_CONTEXT_MARKER))) {
366
+ output.system.push(`${ADR_CONTEXT_MARKER}\n${state.context}\n</adr-kit-context>`)
367
+ }
368
+ },
369
+
370
+ "experimental.session.compacting": async (
371
+ hookInput: { sessionID: string },
372
+ output: { context: string[] },
373
+ ) => {
374
+ const state = sessions.get(sessionKey(hookInput.sessionID))
375
+ if (state?.context) output.context.push(`${ADR_CONTEXT_MARKER}\n${state.context}\n</adr-kit-context>`)
376
+ output.context.push("Keep ADR Kit's governing decisions, open questions, and the rule that the pre-commit/CI judge is the enforcement floor.")
377
+ },
378
+
379
+ "tool.definition": async (
380
+ hookInput: { toolID: string },
381
+ output: { description: string },
382
+ ) => {
383
+ if (WRITE_TOOLS.has(toolName(hookInput.toolID)) && !output.description.includes("adr-kit MCP")) {
384
+ output.description += " Before editing, use the adr-kit MCP server to check governing ADRs."
385
+ }
386
+ },
387
+
388
+ "tool.execute.before": async (
389
+ hookInput: { tool: string; sessionID: string },
390
+ output: { args: AnyRecord },
391
+ ) => {
392
+ if (options.hooks === false) return
393
+ const normalized = toolName(hookInput.tool)
394
+ const args = output.args || {}
395
+ if (SHELL_TOOLS.has(normalized) && typeof args.command === "string") {
396
+ const result = await runHook(
397
+ runtimeRoot,
398
+ python,
399
+ input.directory,
400
+ "PreToolUse",
401
+ hookInput.sessionID,
402
+ { tool_name: "Bash", tool_input: { command: bounded(args.command, MAX_INPUT_CHARS) } },
403
+ hookTimeout(options, PR_HOOK_TIMEOUT_MS),
404
+ )
405
+ addContext(sessions, hookInput.sessionID, result, "shell")
406
+ if (result.denied) throw new Error(result.reason || "ADR Kit blocked this pull-request command.")
407
+ return
408
+ }
409
+ if (!WRITE_TOOLS.has(normalized) || !toolPath(args)) return
410
+ const result = await runHook(
411
+ runtimeRoot,
412
+ python,
413
+ input.directory,
414
+ "PreToolUse",
415
+ hookInput.sessionID,
416
+ { tool_name: normalized === "write" ? "Write" : "Edit", tool_input: args },
417
+ hookTimeout(options, DEFAULT_HOOK_TIMEOUT_MS),
418
+ )
419
+ addContext(sessions, hookInput.sessionID, result, "edit")
420
+ },
421
+
422
+ "tool.execute.after": async (
423
+ hookInput: { tool: string; sessionID: string; args: AnyRecord },
424
+ ) => {
425
+ if (options.hooks === false) return
426
+ const normalized = toolName(hookInput.tool)
427
+ if (!WRITE_TOOLS.has(normalized) || !toolPath(hookInput.args || {})) return
428
+ const result = await runHook(
429
+ runtimeRoot,
430
+ python,
431
+ input.directory,
432
+ "PostToolUse",
433
+ hookInput.sessionID,
434
+ { tool_name: normalized === "write" ? "Write" : "Edit", tool_input: hookInput.args || {} },
435
+ hookTimeout(options, DEFAULT_HOOK_TIMEOUT_MS),
436
+ )
437
+ addContext(sessions, hookInput.sessionID, result, "post-edit")
438
+ },
439
+
440
+ event: async ({ event }: { event: AnyRecord }) => {
441
+ const properties = event.properties && typeof event.properties === "object" ? event.properties : {}
442
+ const id = properties.sessionID || properties.session_id || properties.info?.id
443
+ if (event.type === "session.created" && typeof id === "string") stateFor(sessions, id)
444
+ if (event.type === "session.deleted" && typeof id === "string") sessions.delete(id)
445
+ },
446
+
447
+ dispose: async () => {
448
+ sessions.clear()
449
+ },
450
+ }
451
+ }
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@rvdbreemen/adr-kit-opencode",
3
+ "version": "0.52.0",
4
+ "description": "Native OpenCode plugin for ADR Kit, backed by the shared deterministic Python engines.",
5
+ "type": "module",
6
+ "main": "./opencode/plugin.ts",
7
+ "license": "MIT",
8
+ "repository": "https://github.com/rvdbreemen/adr-kit.git",
9
+ "homepage": "https://github.com/rvdbreemen/adr-kit",
10
+ "keywords": [
11
+ "opencode",
12
+ "adr",
13
+ "architecture-decision-records",
14
+ "agent-plugin",
15
+ "mcp"
16
+ ],
17
+ "engines": {
18
+ "opencode": ">=1.18.0"
19
+ },
20
+ "files": [
21
+ "opencode/plugin.ts",
22
+ "bin/adr",
23
+ "bin/adr-*",
24
+ "bin/*.py",
25
+ "bin/bump-version",
26
+ "hooks/__init__.py",
27
+ "hooks/adr-hook.py",
28
+ "hooks/adr_hook_core.py",
29
+ "hooks/adr_pr_guard.py",
30
+ "hooks/adapters/*.py",
31
+ "skills",
32
+ "instructions",
33
+ "schemas",
34
+ "scripts/*.py",
35
+ "templates",
36
+ "clients/workflows.json",
37
+ ".claude-plugin/plugin.json",
38
+ "LICENSE",
39
+ "README.md"
40
+ ]
41
+ }
@@ -0,0 +1,56 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://adr-kit.dev/schemas/adr-context-probes.schema.json",
4
+ "title": "ADR Kit selective-context retrieval probes",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": ["schema_version", "probes"],
8
+ "properties": {
9
+ "$schema": {"type": "string"},
10
+ "schema_version": {"const": 1},
11
+ "probes": {
12
+ "type": "array",
13
+ "maxItems": 100,
14
+ "items": {"$ref": "#/$defs/probe"}
15
+ }
16
+ },
17
+ "$defs": {
18
+ "strings": {
19
+ "type": "array",
20
+ "maxItems": 32,
21
+ "uniqueItems": true,
22
+ "items": {"type": "string", "minLength": 1, "maxLength": 240}
23
+ },
24
+ "adrIds": {
25
+ "type": "array",
26
+ "maxItems": 20,
27
+ "uniqueItems": true,
28
+ "items": {"type": "string", "pattern": "^ADR-[0-9]{3,4}$"}
29
+ },
30
+ "probe": {
31
+ "type": "object",
32
+ "additionalProperties": false,
33
+ "required": ["id", "query", "expect"],
34
+ "properties": {
35
+ "id": {
36
+ "type": "string",
37
+ "pattern": "^[a-z][a-z0-9-]{0,79}$"
38
+ },
39
+ "query": {"type": "string", "minLength": 1, "maxLength": 1000},
40
+ "paths": {"$ref": "#/$defs/strings"},
41
+ "components": {"$ref": "#/$defs/strings"},
42
+ "symbols": {"$ref": "#/$defs/strings"},
43
+ "topics": {"$ref": "#/$defs/strings"},
44
+ "limit": {"type": "integer", "minimum": 1, "maximum": 20, "default": 3},
45
+ "expect": {
46
+ "type": "object",
47
+ "additionalProperties": false,
48
+ "properties": {
49
+ "include": {"$ref": "#/$defs/adrIds"},
50
+ "exclude": {"$ref": "#/$defs/adrIds"}
51
+ }
52
+ }
53
+ }
54
+ }
55
+ }
56
+ }
@@ -0,0 +1,57 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "ADR Enforcement Block Schema (v0.14.0+)",
4
+ "type": "object",
5
+ "properties": {
6
+ "forbid_pattern": {
7
+ "type": "array",
8
+ "items": {
9
+ "type": "object",
10
+ "properties": {
11
+ "pattern": { "type": "string", "minLength": 1 },
12
+ "path_glob": { "type": "string" },
13
+ "message": { "type": "string" }
14
+ },
15
+ "required": ["pattern"],
16
+ "additionalProperties": false
17
+ }
18
+ },
19
+ "forbid_import": {
20
+ "type": "array",
21
+ "items": {
22
+ "type": "object",
23
+ "properties": {
24
+ "pattern": { "type": "string", "minLength": 1 },
25
+ "path_glob": { "type": "string" },
26
+ "message": { "type": "string" }
27
+ },
28
+ "required": ["pattern"],
29
+ "additionalProperties": false
30
+ }
31
+ },
32
+ "require_pattern": {
33
+ "type": "array",
34
+ "items": {
35
+ "type": "object",
36
+ "properties": {
37
+ "pattern": { "type": "string", "minLength": 1 },
38
+ "path_glob": { "type": "string" },
39
+ "message": { "type": "string" }
40
+ },
41
+ "required": ["pattern"],
42
+ "additionalProperties": false
43
+ }
44
+ },
45
+ "llm_judge": {
46
+ "type": "boolean",
47
+ "default": true,
48
+ "description": "Whether the LLM pass evaluates the staged diff against this ADR's Decision text. DEFAULT TRUE as of TASK-74: an Enforcement block that omits the key opts in, and only an explicit false opts out. The previous opt-in default failed silently -- a pass that was on by default with an empty population judged nothing while looking active. Cost is bounded by scope, not by this flag: an ADR is only judged when the diff touches a file matching its rules' path_glob set. An Enforcement block that declares no rules, or a rule without a path_glob, has no boundary to narrow with and is therefore judged on EVERY commit; prefer marking such a decision as having no code surface."
49
+ },
50
+ "llm_judge_reason": {
51
+ "type": "string",
52
+ "minLength": 1,
53
+ "description": "Why the LLM pass is off for this ADR. Only meaningful together with llm_judge:false. Since the default flipped to true, a bare false is ambiguous -- it may be a deliberate opt-out or a leftover from when false was the default. A reason makes the opt-out durable: the upgrade re-proposes a bare false and leaves a reasoned one alone. Typical value: 'no code surface -- this decision governs the release process, not code'."
54
+ }
55
+ },
56
+ "additionalProperties": false
57
+ }