-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.ts
More file actions
143 lines (125 loc) · 5.09 KB
/
Copy pathplugin.ts
File metadata and controls
143 lines (125 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import type { Plugin, Config } from "@opencode-ai/plugin";
import { install, getGlobalConfigPath, getPackageVersion, ScopeResolver, isLocalInstalled, readLocalConfig, mergeConfigWithOverrides, printRecommendations } from "./src/installer.ts";
import { join } from "node:path";
const SKILL_NAMES = ["test-baselining", "regression-checking", "grilling"] as const;
function setTaskSkillPermissions(input: Config): void {
input.agent ??= {};
input.agent.task ??= {};
const taskAgent = input.agent.task as Record<string, unknown>;
taskAgent.permission ??= {};
const permission = taskAgent.permission as Record<string, unknown>;
permission.skill ??= {};
const skillPermissions = permission.skill as Record<string, string>;
for (const skillName of ["test-baselining", "regression-checking", "grilling"]) {
skillPermissions[skillName] = "allow";
}
}
const plugin: Plugin = async ({ directory }) => ({
config: async (input: Config) => {
const version = await getPackageVersion();
const globalConfigPath = getGlobalConfigPath();
const globalVersionMarker = join(globalConfigPath, "skills", "test-baselining", ".version");
const scope = ScopeResolver.resolve(directory, globalConfigPath);
if (scope === "global") {
const marker = globalVersionMarker;
try {
const installedVersion = (await Bun.file(marker).text()).trim();
if (installedVersion === version) {
setTaskSkillPermissions(input);
return;
}
} catch {
// Not installed, proceed
}
const result = await install("global", directory);
console.log(`\nInstalled opencode-auto-qcgates globally:`);
if (result.skillPaths.length > 0) {
console.log(` Skills: ${result.skillPaths.join(", ")}`);
}
if (result.commandPaths.length > 0) {
console.log(` Commands: ${result.commandPaths.join(", ")}`);
}
printRecommendations(result.recommendations);
setTaskSkillPermissions(input);
return;
}
const localMarker = join(directory, ".opencode", "skills", "test-baselining", ".version");
const localInstalled = await isLocalInstalled(directory);
if (localInstalled) {
try {
const installedVersion = (await Bun.file(localMarker).text()).trim();
if (installedVersion === version) {
const localConfig = await readLocalConfig(directory);
if (localConfig) {
mergeConfigWithOverrides(input as Record<string, unknown>, localConfig);
}
setTaskSkillPermissions(input);
return;
}
} catch {
// Proceed with install
}
const result = await install("local", directory);
console.log(`\nInstalled opencode-auto-qcgates locally:`);
if (result.skillPaths.length > 0) {
console.log(` Skills: ${result.skillPaths.join(", ")}`);
}
if (result.commandPaths.length > 0) {
console.log(` Commands: ${result.commandPaths.join(", ")}`);
}
if (result.migrated) {
console.log(` Migrated: opencode.json → .opencode/opencode.json`);
}
printRecommendations(result.recommendations);
const newLocalConfig = await readLocalConfig(directory);
if (newLocalConfig) {
mergeConfigWithOverrides(input as Record<string, unknown>, newLocalConfig);
}
setTaskSkillPermissions(input);
return;
}
try {
const globalVersion = (await Bun.file(globalVersionMarker).text()).trim();
if (globalVersion === version) {
const result = await install("local", directory);
console.log(`\nInstalled opencode-auto-qcgates locally (overriding global):`);
if (result.skillPaths.length > 0) {
console.log(` Skills: ${result.skillPaths.join(", ")}`);
}
if (result.commandPaths.length > 0) {
console.log(` Commands: ${result.commandPaths.join(", ")}`);
}
if (result.migrated) {
console.log(` Migrated: opencode.json → .opencode/opencode.json`);
}
printRecommendations(result.recommendations);
const localConfig = await readLocalConfig(directory);
if (localConfig) {
mergeConfigWithOverrides(input as Record<string, unknown>, localConfig);
}
setTaskSkillPermissions(input);
return;
}
} catch {
// Global not installed, proceed with local install
}
const result = await install("local", directory);
console.log(`\nInstalled opencode-auto-qcgates locally:`);
if (result.skillPaths.length > 0) {
console.log(` Skills: ${result.skillPaths.join(", ")}`);
}
if (result.commandPaths.length > 0) {
console.log(` Commands: ${result.commandPaths.join(", ")}`);
}
if (result.migrated) {
console.log(` Migrated: opencode.json → .opencode/opencode.json`);
}
printRecommendations(result.recommendations);
const finalLocalConfig = await readLocalConfig(directory);
if (finalLocalConfig) {
mergeConfigWithOverrides(input as Record<string, unknown>, finalLocalConfig);
}
setTaskSkillPermissions(input);
},
});
export default plugin;