@omerrgocmen/crewctl 1.1.1 → 1.3.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 +193 -193
- package/orchestrator/README.md +473 -462
- package/orchestrator/config.default.json +79 -71
- package/orchestrator/roles/executor.md +57 -57
- package/orchestrator/roles/operator.md +77 -77
- package/orchestrator/roles/planner.md +58 -58
- package/orchestrator/roles/reviewer.md +63 -63
- package/orchestrator/skills/acceptance-criteria.md +18 -18
- package/orchestrator/skills/accessibility-audit.md +16 -16
- package/orchestrator/skills/accessible-forms.md +16 -16
- package/orchestrator/skills/api-design.md +27 -27
- package/orchestrator/skills/api-documentation.md +16 -16
- package/orchestrator/skills/architecture-decision-record.md +18 -18
- package/orchestrator/skills/authentication-design.md +16 -16
- package/orchestrator/skills/authorization-review.md +16 -16
- package/orchestrator/skills/backward-compatibility.md +17 -17
- package/orchestrator/skills/changelog-writing.md +16 -16
- package/orchestrator/skills/ci-pipeline-design.md +16 -16
- package/orchestrator/skills/cli-design.md +16 -16
- package/orchestrator/skills/code-review.md +27 -27
- package/orchestrator/skills/configuration-management.md +16 -16
- package/orchestrator/skills/container-review.md +16 -16
- package/orchestrator/skills/contract-testing.md +16 -16
- package/orchestrator/skills/dashboard-design.md +16 -16
- package/orchestrator/skills/database-migration.md +16 -16
- package/orchestrator/skills/database-schema-design.md +16 -16
- package/orchestrator/skills/debugging.md +26 -26
- package/orchestrator/skills/dependency-review.md +16 -16
- package/orchestrator/skills/design-review.md +29 -29
- package/orchestrator/skills/design-system.md +16 -16
- package/orchestrator/skills/docs-api-reference.md +16 -16
- package/orchestrator/skills/docs-troubleshooting.md +16 -16
- package/orchestrator/skills/docs-tutorial.md +16 -16
- package/orchestrator/skills/docs-writing.md +25 -25
- package/orchestrator/skills/empty-error-loading-states.md +16 -16
- package/orchestrator/skills/end-to-end-testing.md +16 -16
- package/orchestrator/skills/error-handling.md +16 -16
- package/orchestrator/skills/frontend-design.md +28 -28
- package/orchestrator/skills/git-commit-writing.md +16 -16
- package/orchestrator/skills/graphql-design.md +16 -16
- package/orchestrator/skills/incident-runbook.md +18 -18
- package/orchestrator/skills/input-validation.md +16 -16
- package/orchestrator/skills/integration-testing.md +16 -16
- package/orchestrator/skills/interaction-design.md +16 -16
- package/orchestrator/skills/landing-page-design.md +16 -16
- package/orchestrator/skills/observability-design.md +16 -16
- package/orchestrator/skills/openapi-contract.md +16 -16
- package/orchestrator/skills/performance-profiling.md +16 -16
- package/orchestrator/skills/privacy-review.md +16 -16
- package/orchestrator/skills/property-based-testing.md +16 -16
- package/orchestrator/skills/pull-request-writing.md +16 -16
- package/orchestrator/skills/refactoring.md +16 -16
- package/orchestrator/skills/release-readiness.md +16 -16
- package/orchestrator/skills/responsive-design.md +16 -16
- package/orchestrator/skills/secrets-management.md +16 -16
- package/orchestrator/skills/secure-file-upload.md +16 -16
- package/orchestrator/skills/security-review.md +26 -26
- package/orchestrator/skills/semantic-versioning.md +17 -17
- package/orchestrator/skills/seo-on-page.md +16 -16
- package/orchestrator/skills/seo-structured-data.md +16 -16
- package/orchestrator/skills/seo-technical-audit.md +16 -16
- package/orchestrator/skills/sql-query-review.md +16 -16
- package/orchestrator/skills/supply-chain-security.md +16 -16
- package/orchestrator/skills/test-strategy.md +16 -16
- package/orchestrator/skills/threat-modeling.md +16 -16
- package/orchestrator/skills/unit-testing.md +16 -16
- package/orchestrator/skills/write-tests.md +28 -28
- package/orchestrator/src/cli-registry.js +740 -682
- package/orchestrator/src/cli.js +140 -135
- package/orchestrator/src/doctor.js +64 -64
- package/orchestrator/src/engine.js +1735 -1630
- package/orchestrator/src/schedule.js +126 -126
- package/orchestrator/src/server.js +818 -795
- package/orchestrator/src/skill-registry.js +272 -272
- package/orchestrator/src/store.js +470 -426
- package/orchestrator/web/OrbitControls.js +1417 -1417
- package/orchestrator/web/board.html +146 -146
- package/orchestrator/web/code.html +213 -213
- package/orchestrator/web/flow.html +741 -741
- package/orchestrator/web/index.html +602 -602
- package/orchestrator/web/jsm/postprocessing/EffectComposer.js +231 -231
- package/orchestrator/web/jsm/postprocessing/MaskPass.js +104 -104
- package/orchestrator/web/jsm/postprocessing/Pass.js +95 -95
- package/orchestrator/web/jsm/postprocessing/RenderPass.js +99 -99
- package/orchestrator/web/jsm/postprocessing/ShaderPass.js +77 -77
- package/orchestrator/web/jsm/postprocessing/UnrealBloomPass.js +415 -415
- package/orchestrator/web/jsm/shaders/CopyShader.js +45 -45
- package/orchestrator/web/jsm/shaders/LuminosityHighPassShader.js +66 -66
- package/orchestrator/web/site.webmanifest +12 -12
- package/orchestrator/web/three.module.min.js +6 -6
- package/package.json +51 -51
|
@@ -1,682 +1,740 @@
|
|
|
1
|
-
const { spawn, spawnSync } = require("child_process");
|
|
2
|
-
const fs = require("fs");
|
|
3
|
-
const os = require("os");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
|
|
6
|
-
const isWin = process.platform === "win32";
|
|
7
|
-
|
|
8
|
-
const DEFINITIONS = {
|
|
9
|
-
codex: {
|
|
10
|
-
command: "codex",
|
|
11
|
-
versionArgs: ["--version"],
|
|
12
|
-
defaultArgs: ["exec", "--skip-git-repo-check"],
|
|
13
|
-
// Codex calisirken surekli ilerleme akitir; 3 dakikalik sessizlik gercek bir takilmadir.
|
|
14
|
-
silenceTimeoutSeconds: 180,
|
|
15
|
-
description: "OpenAI Codex kodlama, hata ayiklama ve inceleme agenti",
|
|
16
|
-
capabilities: ["implementation", "debugging", "testing", "review", "analysis"],
|
|
17
|
-
roleFile: "roles/executor.md",
|
|
18
|
-
},
|
|
19
|
-
claude: {
|
|
20
|
-
command: "claude",
|
|
21
|
-
versionArgs: ["--version"],
|
|
22
|
-
defaultArgs: ["-p", "--permission-mode", "acceptEdits", "--output-format", "text"],
|
|
23
|
-
description: "Claude Code uygulama, analiz ve test agenti",
|
|
24
|
-
capabilities: ["implementation", "debugging", "testing", "review", "web"],
|
|
25
|
-
roleFile: "roles/executor.md",
|
|
26
|
-
},
|
|
27
|
-
gemini: {
|
|
28
|
-
command: "gemini",
|
|
29
|
-
versionArgs: ["--version"],
|
|
30
|
-
// Argumansiz gemini interaktif TUI acar ve izin bekler; yolo ile otonom, stdin'den prompt alir.
|
|
31
|
-
defaultArgs: ["--approval-mode", "yolo"],
|
|
32
|
-
// Gemini de akis halinde cikti verir; uzun sessizlik takilma isaretidir.
|
|
33
|
-
silenceTimeoutSeconds: 180,
|
|
34
|
-
description: "Gemini CLI analiz, uygulama ve web arastirma agenti",
|
|
35
|
-
capabilities: ["implementation", "planning", "analysis", "research", "web"],
|
|
36
|
-
roleFile: "roles/executor.md",
|
|
37
|
-
},
|
|
38
|
-
opencode: {
|
|
39
|
-
command: "opencode",
|
|
40
|
-
versionArgs: ["--version"],
|
|
41
|
-
// OpenCode saglayici/model kombinasyonuna gore uzun sure sessiz kalabilir. Varsayilan
|
|
42
|
-
// agent timeout'u, basarili bir calismayi SIGTERM ile yarida kesmeyecek kadar genis tut.
|
|
43
|
-
timeoutSeconds: 1800,
|
|
44
|
-
// OpenCode adim baslattiktan sonra model/provider yanitini beklerken uzun sure hic cikti
|
|
45
|
-
// akitmayabilir (ozellikle yavas/rate-limitli modeller). 180sn cok agresifti ve calisan bir
|
|
46
|
-
// kosmayi yariyordu; sessizlik payini genis tut. Gercek takilma yine timeoutSeconds ile yakalanir.
|
|
47
|
-
silenceTimeoutSeconds: 300,
|
|
48
|
-
// Bazi eski OpenCode surumleri --auto bayragini tanimaz. Otonom izinler
|
|
49
|
-
// engine tarafinda OPENCODE_CONFIG_CONTENT ile surumden bagimsiz aktarilir.
|
|
50
|
-
defaultArgs: ["run", "--format", "json", "Attached file contains the full task. Follow it exactly, make the changes, and report what you did.", "--file", "{PROMPT_FILE}"],
|
|
51
|
-
description: "OpenCode coklu saglayici kodlama, uygulama ve inceleme agenti",
|
|
52
|
-
capabilities: ["implementation", "debugging", "testing", "review", "analysis", "research"],
|
|
53
|
-
roleFile: "roles/executor.md",
|
|
54
|
-
install: {
|
|
55
|
-
windows: "npm install -g opencode-ai (alternatif: choco install opencode / scoop install opencode)",
|
|
56
|
-
macos: "brew install anomalyco/tap/opencode (alternatif: npm install -g opencode-ai)",
|
|
57
|
-
linux: "curl -fsSL https://opencode.ai/install | bash (alternatif: npm install -g opencode-ai)",
|
|
58
|
-
auth: "opencode auth login",
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
const RESOLVED = new Map();
|
|
63
|
-
let OPEN_CODE_MODELS = [];
|
|
64
|
-
|
|
65
|
-
// En fazla bir CLI'yi (or. codex) ayni anda hem canli saglik/model probe'u hem de motorun
|
|
66
|
-
// operatör kosumu calistirirsa, codex gibi bazi CLI'lar ayni is dizininde ikinci exec oturumunu
|
|
67
|
-
// SIGTERM ile keser. Probe'lar "en iyi caba"dir; motor onceliklidir. Aktif probe cocuklarini
|
|
68
|
-
// izleyip motor bir goreve baslarken hepsini sonlandiriyoruz.
|
|
69
|
-
const ACTIVE_PROBES = new Set();
|
|
70
|
-
function registerProbe(child) {
|
|
71
|
-
if (!child) return () => {};
|
|
72
|
-
ACTIVE_PROBES.add(child);
|
|
73
|
-
return () => ACTIVE_PROBES.delete(child);
|
|
74
|
-
}
|
|
75
|
-
// Uctan uca proses agacini oldur (codex kabuk altinda alt proses baslatabilir).
|
|
76
|
-
function terminateProbeTree(child) {
|
|
77
|
-
if (!child) return;
|
|
78
|
-
try {
|
|
79
|
-
if (isWin && child.pid) spawn("taskkill", ["/pid", String(child.pid), "/t", "/f"], { windowsHide: true, stdio: "ignore" });
|
|
80
|
-
else child.kill("SIGKILL");
|
|
81
|
-
} catch {}
|
|
82
|
-
}
|
|
83
|
-
// Motor bir goreve baslarken cagirir: uctaki tum canli probe'lari sonlandirir ki operatörun
|
|
84
|
-
// CLI'si (codex vb.) temiz bir alanda calissin. Probe'lar sonuc olarak "timeout/failed" doner;
|
|
85
|
-
// bu zararsizdir, motor bosaldiginda yeniden denenir.
|
|
86
|
-
// Iptal sayaci: motor bir goreve baslarken probe'lari oldurdugunde artar. Oldurulen probe
|
|
87
|
-
// "cikis kodu != 0" ile doner ve saglik siniflandiricisi bunu GERCEK bir ariza sanardi;
|
|
88
|
-
// sonuc 6 saatlik onbellege yazilinca CLI o sure boyunca yanlislikla kullanilamaz kalirdi.
|
|
89
|
-
// refreshCliHealth bu sayaci once/sonra karsilastirip kirlenmis sonucu ONBELLEGE YAZMAZ.
|
|
90
|
-
let probeGeneration = 0;
|
|
91
|
-
function currentProbeGeneration() {
|
|
92
|
-
return probeGeneration;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function abortActiveProbes() {
|
|
96
|
-
const count = ACTIVE_PROBES.size;
|
|
97
|
-
if (count) probeGeneration++;
|
|
98
|
-
for (const child of ACTIVE_PROBES) terminateProbeTree(child);
|
|
99
|
-
ACTIVE_PROBES.clear();
|
|
100
|
-
return count;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function selectOpenCodeModel(models) {
|
|
104
|
-
const list = Array.isArray(models) ? models.map(String).filter(Boolean) : [];
|
|
105
|
-
const priorities = [
|
|
106
|
-
(x) => x === "opencode/big-pickle",
|
|
107
|
-
(x) => /^opencode\/.+free$/i.test(x),
|
|
108
|
-
(x) => x.startsWith("opencode/"),
|
|
109
|
-
(x) => x.startsWith("opencode-go/"),
|
|
110
|
-
(x) => x.startsWith("minimax-coding-plan/"),
|
|
111
|
-
(x) => !x.startsWith("ollama/"),
|
|
112
|
-
];
|
|
113
|
-
for (const match of priorities) {
|
|
114
|
-
const found = list.find(match);
|
|
115
|
-
if (found) return found;
|
|
116
|
-
}
|
|
117
|
-
return "";
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// `opencode models` ciktisindan saglayici/model satirlarini ayiklar. Baslik, bos satir ve
|
|
121
|
-
// log gurultusunu eler; her "saglayici/model" bicimli satir gecerli sayilir.
|
|
122
|
-
function parseOpenCodeModels(stdout) {
|
|
123
|
-
const found = new Set();
|
|
124
|
-
for (const line of String(stdout || "").split(/\r?\n/)) {
|
|
125
|
-
const model = line.trim();
|
|
126
|
-
if (/^[A-Za-z0-9._-]+\/.+/.test(model) && !/\s/.test(model)) found.add(model);
|
|
127
|
-
}
|
|
128
|
-
return [...found];
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function listOpenCodeModels(command) {
|
|
132
|
-
try {
|
|
133
|
-
// Tum saglayicilarin listesi sorgulanir. Kullanicilarin ucretli abonelikleri
|
|
134
|
-
// (opencode-go, minimax-coding-plan vb.) ayri saglayici olarak gorunur; yalnizca
|
|
135
|
-
// "opencode" saglayicisini sorgulamak bu modelleri gizliyor ve kurulum yanlislikla
|
|
136
|
-
// "hazir degil" sayiliyordu. Otomatik oneri siralamasini selectOpenCodeModel yapar.
|
|
137
|
-
const result = spawnSync(command, ["models"], {
|
|
138
|
-
encoding: "utf8", timeout: 20000, windowsHide: true,
|
|
139
|
-
shell: isWin && (!path.isAbsolute(command) || /\.(cmd|bat)$/i.test(command)),
|
|
140
|
-
});
|
|
141
|
-
if (result.status !== 0) return [];
|
|
142
|
-
return parseOpenCodeModels(result.stdout);
|
|
143
|
-
} catch { return []; }
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function adapterId(command) {
|
|
147
|
-
const base = path.basename(String(command || "")).toLowerCase().replace(/\.(cmd|bat|exe|ps1)$/, "");
|
|
148
|
-
if (base.includes("codex")) return "codex";
|
|
149
|
-
if (base.includes("claude")) return "claude";
|
|
150
|
-
if (base.includes("gemini")) return "gemini";
|
|
151
|
-
if (base.includes("opencode")) return "opencode";
|
|
152
|
-
return "custom";
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Farkli paket yoneticileri / kurulum araclari CLI'lari farkli dizinlere koyar. Her PC'de
|
|
156
|
-
// calismasi icin yaygin npm/pnpm/yarn/bun/volta/scoop/winget/choco/homebrew konumlarini tarariz.
|
|
157
|
-
function commonCandidates(id) {
|
|
158
|
-
const home = os.homedir();
|
|
159
|
-
if (isWin) {
|
|
160
|
-
const APPDATA = process.env.APPDATA, LOCAL = process.env.LOCALAPPDATA, PD = process.env.ProgramData;
|
|
161
|
-
const exts = ["cmd", "exe", "ps1", "bat", ""];
|
|
162
|
-
const bases = [
|
|
163
|
-
APPDATA && path.join(APPDATA, "npm"),
|
|
164
|
-
LOCAL && path.join(LOCAL, "pnpm"),
|
|
165
|
-
LOCAL && path.join(LOCAL, "Yarn", "bin"),
|
|
166
|
-
LOCAL && path.join(LOCAL, "Microsoft", "WinGet", "Links"),
|
|
167
|
-
LOCAL && path.join(LOCAL, "Programs", id),
|
|
168
|
-
path.join(home, ".bun", "bin"),
|
|
169
|
-
path.join(home, ".volta", "bin"),
|
|
170
|
-
path.join(home, "scoop", "shims"),
|
|
171
|
-
PD && path.join(PD, "chocolatey", "bin"),
|
|
172
|
-
path.join(home, ".local", "bin"),
|
|
173
|
-
path.join(home, "AppData", "Roaming", "npm"),
|
|
174
|
-
].filter(Boolean);
|
|
175
|
-
const out = [];
|
|
176
|
-
for (const base of bases) for (const ext of exts) out.push(path.join(base, ext ? `${id}.${ext}` : id));
|
|
177
|
-
return out;
|
|
178
|
-
}
|
|
179
|
-
return [
|
|
180
|
-
path.join(home, ".local", "bin", id),
|
|
181
|
-
path.join(home, "bin", id),
|
|
182
|
-
path.join(home, ".bun", "bin", id),
|
|
183
|
-
path.join(home, ".volta", "bin", id),
|
|
184
|
-
path.join(home, ".npm-global", "bin", id),
|
|
185
|
-
path.join(home, ".yarn", "bin", id),
|
|
186
|
-
path.join(home, ".local", "share", "pnpm", id),
|
|
187
|
-
`/usr/local/bin/${id}`,
|
|
188
|
-
`/opt/homebrew/bin/${id}`,
|
|
189
|
-
`/usr/bin/${id}`,
|
|
190
|
-
`/snap/bin/${id}`,
|
|
191
|
-
];
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// Bilinen bir CLI komutu adapter alanindan daha guvenilir kaynaktir. Eski veya elle
|
|
195
|
-
// duzenlenmis config'te adapter=claude + cmd=codex gibi bir celiski varsa hedef CLI'nin
|
|
196
|
-
// guvenli varsayilan argumanlarina donulur; boylece bir CLI'ye digerinin bayragi gitmez.
|
|
197
|
-
function normalizeAgentAdapter(agent) {
|
|
198
|
-
if (!agent || typeof agent !== "object") return false;
|
|
199
|
-
const configured = String(agent.adapter || "").trim().toLowerCase();
|
|
200
|
-
const inferred = adapterId(agent.cmd);
|
|
201
|
-
const adapter = inferred !== "custom" ? inferred : (DEFINITIONS[configured] ? configured : "custom");
|
|
202
|
-
let changed = false;
|
|
203
|
-
if (inferred !== "custom" && configured && configured !== inferred) {
|
|
204
|
-
agent.args = DEFINITIONS[inferred].defaultArgs.slice();
|
|
205
|
-
delete agent.model;
|
|
206
|
-
delete agent.modelOverride;
|
|
207
|
-
changed = true;
|
|
208
|
-
}
|
|
209
|
-
if (agent.adapter !== adapter) {
|
|
210
|
-
agent.adapter = adapter;
|
|
211
|
-
changed = true;
|
|
212
|
-
}
|
|
213
|
-
return changed;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function normalizeAgentAdapters(cfg) {
|
|
217
|
-
if (!cfg?.agents || typeof cfg.agents !== "object") return false;
|
|
218
|
-
let changed = false;
|
|
219
|
-
for (const agent of Object.values(cfg.agents)) if (normalizeAgentAdapter(agent)) changed = true;
|
|
220
|
-
return changed;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
//
|
|
224
|
-
//
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
if (
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
//
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
result.
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
//
|
|
322
|
-
//
|
|
323
|
-
//
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
//
|
|
377
|
-
//
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
if (
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
//
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
1
|
+
const { spawn, spawnSync } = require("child_process");
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const os = require("os");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
const isWin = process.platform === "win32";
|
|
7
|
+
|
|
8
|
+
const DEFINITIONS = {
|
|
9
|
+
codex: {
|
|
10
|
+
command: "codex",
|
|
11
|
+
versionArgs: ["--version"],
|
|
12
|
+
defaultArgs: ["exec", "--skip-git-repo-check"],
|
|
13
|
+
// Codex calisirken surekli ilerleme akitir; 3 dakikalik sessizlik gercek bir takilmadir.
|
|
14
|
+
silenceTimeoutSeconds: 180,
|
|
15
|
+
description: "OpenAI Codex kodlama, hata ayiklama ve inceleme agenti",
|
|
16
|
+
capabilities: ["implementation", "debugging", "testing", "review", "analysis"],
|
|
17
|
+
roleFile: "roles/executor.md",
|
|
18
|
+
},
|
|
19
|
+
claude: {
|
|
20
|
+
command: "claude",
|
|
21
|
+
versionArgs: ["--version"],
|
|
22
|
+
defaultArgs: ["-p", "--permission-mode", "acceptEdits", "--output-format", "text"],
|
|
23
|
+
description: "Claude Code uygulama, analiz ve test agenti",
|
|
24
|
+
capabilities: ["implementation", "debugging", "testing", "review", "web"],
|
|
25
|
+
roleFile: "roles/executor.md",
|
|
26
|
+
},
|
|
27
|
+
gemini: {
|
|
28
|
+
command: "gemini",
|
|
29
|
+
versionArgs: ["--version"],
|
|
30
|
+
// Argumansiz gemini interaktif TUI acar ve izin bekler; yolo ile otonom, stdin'den prompt alir.
|
|
31
|
+
defaultArgs: ["--approval-mode", "yolo"],
|
|
32
|
+
// Gemini de akis halinde cikti verir; uzun sessizlik takilma isaretidir.
|
|
33
|
+
silenceTimeoutSeconds: 180,
|
|
34
|
+
description: "Gemini CLI analiz, uygulama ve web arastirma agenti",
|
|
35
|
+
capabilities: ["implementation", "planning", "analysis", "research", "web"],
|
|
36
|
+
roleFile: "roles/executor.md",
|
|
37
|
+
},
|
|
38
|
+
opencode: {
|
|
39
|
+
command: "opencode",
|
|
40
|
+
versionArgs: ["--version"],
|
|
41
|
+
// OpenCode saglayici/model kombinasyonuna gore uzun sure sessiz kalabilir. Varsayilan
|
|
42
|
+
// agent timeout'u, basarili bir calismayi SIGTERM ile yarida kesmeyecek kadar genis tut.
|
|
43
|
+
timeoutSeconds: 1800,
|
|
44
|
+
// OpenCode adim baslattiktan sonra model/provider yanitini beklerken uzun sure hic cikti
|
|
45
|
+
// akitmayabilir (ozellikle yavas/rate-limitli modeller). 180sn cok agresifti ve calisan bir
|
|
46
|
+
// kosmayi yariyordu; sessizlik payini genis tut. Gercek takilma yine timeoutSeconds ile yakalanir.
|
|
47
|
+
silenceTimeoutSeconds: 300,
|
|
48
|
+
// Bazi eski OpenCode surumleri --auto bayragini tanimaz. Otonom izinler
|
|
49
|
+
// engine tarafinda OPENCODE_CONFIG_CONTENT ile surumden bagimsiz aktarilir.
|
|
50
|
+
defaultArgs: ["run", "--format", "json", "Attached file contains the full task. Follow it exactly, make the changes, and report what you did.", "--file", "{PROMPT_FILE}"],
|
|
51
|
+
description: "OpenCode coklu saglayici kodlama, uygulama ve inceleme agenti",
|
|
52
|
+
capabilities: ["implementation", "debugging", "testing", "review", "analysis", "research"],
|
|
53
|
+
roleFile: "roles/executor.md",
|
|
54
|
+
install: {
|
|
55
|
+
windows: "npm install -g opencode-ai (alternatif: choco install opencode / scoop install opencode)",
|
|
56
|
+
macos: "brew install anomalyco/tap/opencode (alternatif: npm install -g opencode-ai)",
|
|
57
|
+
linux: "curl -fsSL https://opencode.ai/install | bash (alternatif: npm install -g opencode-ai)",
|
|
58
|
+
auth: "opencode auth login",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
const RESOLVED = new Map();
|
|
63
|
+
let OPEN_CODE_MODELS = [];
|
|
64
|
+
|
|
65
|
+
// En fazla bir CLI'yi (or. codex) ayni anda hem canli saglik/model probe'u hem de motorun
|
|
66
|
+
// operatör kosumu calistirirsa, codex gibi bazi CLI'lar ayni is dizininde ikinci exec oturumunu
|
|
67
|
+
// SIGTERM ile keser. Probe'lar "en iyi caba"dir; motor onceliklidir. Aktif probe cocuklarini
|
|
68
|
+
// izleyip motor bir goreve baslarken hepsini sonlandiriyoruz.
|
|
69
|
+
const ACTIVE_PROBES = new Set();
|
|
70
|
+
function registerProbe(child) {
|
|
71
|
+
if (!child) return () => {};
|
|
72
|
+
ACTIVE_PROBES.add(child);
|
|
73
|
+
return () => ACTIVE_PROBES.delete(child);
|
|
74
|
+
}
|
|
75
|
+
// Uctan uca proses agacini oldur (codex kabuk altinda alt proses baslatabilir).
|
|
76
|
+
function terminateProbeTree(child) {
|
|
77
|
+
if (!child) return;
|
|
78
|
+
try {
|
|
79
|
+
if (isWin && child.pid) spawn("taskkill", ["/pid", String(child.pid), "/t", "/f"], { windowsHide: true, stdio: "ignore" });
|
|
80
|
+
else child.kill("SIGKILL");
|
|
81
|
+
} catch {}
|
|
82
|
+
}
|
|
83
|
+
// Motor bir goreve baslarken cagirir: uctaki tum canli probe'lari sonlandirir ki operatörun
|
|
84
|
+
// CLI'si (codex vb.) temiz bir alanda calissin. Probe'lar sonuc olarak "timeout/failed" doner;
|
|
85
|
+
// bu zararsizdir, motor bosaldiginda yeniden denenir.
|
|
86
|
+
// Iptal sayaci: motor bir goreve baslarken probe'lari oldurdugunde artar. Oldurulen probe
|
|
87
|
+
// "cikis kodu != 0" ile doner ve saglik siniflandiricisi bunu GERCEK bir ariza sanardi;
|
|
88
|
+
// sonuc 6 saatlik onbellege yazilinca CLI o sure boyunca yanlislikla kullanilamaz kalirdi.
|
|
89
|
+
// refreshCliHealth bu sayaci once/sonra karsilastirip kirlenmis sonucu ONBELLEGE YAZMAZ.
|
|
90
|
+
let probeGeneration = 0;
|
|
91
|
+
function currentProbeGeneration() {
|
|
92
|
+
return probeGeneration;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function abortActiveProbes() {
|
|
96
|
+
const count = ACTIVE_PROBES.size;
|
|
97
|
+
if (count) probeGeneration++;
|
|
98
|
+
for (const child of ACTIVE_PROBES) terminateProbeTree(child);
|
|
99
|
+
ACTIVE_PROBES.clear();
|
|
100
|
+
return count;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function selectOpenCodeModel(models) {
|
|
104
|
+
const list = Array.isArray(models) ? models.map(String).filter(Boolean) : [];
|
|
105
|
+
const priorities = [
|
|
106
|
+
(x) => x === "opencode/big-pickle",
|
|
107
|
+
(x) => /^opencode\/.+free$/i.test(x),
|
|
108
|
+
(x) => x.startsWith("opencode/"),
|
|
109
|
+
(x) => x.startsWith("opencode-go/"),
|
|
110
|
+
(x) => x.startsWith("minimax-coding-plan/"),
|
|
111
|
+
(x) => !x.startsWith("ollama/"),
|
|
112
|
+
];
|
|
113
|
+
for (const match of priorities) {
|
|
114
|
+
const found = list.find(match);
|
|
115
|
+
if (found) return found;
|
|
116
|
+
}
|
|
117
|
+
return "";
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// `opencode models` ciktisindan saglayici/model satirlarini ayiklar. Baslik, bos satir ve
|
|
121
|
+
// log gurultusunu eler; her "saglayici/model" bicimli satir gecerli sayilir.
|
|
122
|
+
function parseOpenCodeModels(stdout) {
|
|
123
|
+
const found = new Set();
|
|
124
|
+
for (const line of String(stdout || "").split(/\r?\n/)) {
|
|
125
|
+
const model = line.trim();
|
|
126
|
+
if (/^[A-Za-z0-9._-]+\/.+/.test(model) && !/\s/.test(model)) found.add(model);
|
|
127
|
+
}
|
|
128
|
+
return [...found];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function listOpenCodeModels(command) {
|
|
132
|
+
try {
|
|
133
|
+
// Tum saglayicilarin listesi sorgulanir. Kullanicilarin ucretli abonelikleri
|
|
134
|
+
// (opencode-go, minimax-coding-plan vb.) ayri saglayici olarak gorunur; yalnizca
|
|
135
|
+
// "opencode" saglayicisini sorgulamak bu modelleri gizliyor ve kurulum yanlislikla
|
|
136
|
+
// "hazir degil" sayiliyordu. Otomatik oneri siralamasini selectOpenCodeModel yapar.
|
|
137
|
+
const result = spawnSync(command, ["models"], {
|
|
138
|
+
encoding: "utf8", timeout: 20000, windowsHide: true,
|
|
139
|
+
shell: isWin && (!path.isAbsolute(command) || /\.(cmd|bat)$/i.test(command)),
|
|
140
|
+
});
|
|
141
|
+
if (result.status !== 0) return [];
|
|
142
|
+
return parseOpenCodeModels(result.stdout);
|
|
143
|
+
} catch { return []; }
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function adapterId(command) {
|
|
147
|
+
const base = path.basename(String(command || "")).toLowerCase().replace(/\.(cmd|bat|exe|ps1)$/, "");
|
|
148
|
+
if (base.includes("codex")) return "codex";
|
|
149
|
+
if (base.includes("claude")) return "claude";
|
|
150
|
+
if (base.includes("gemini")) return "gemini";
|
|
151
|
+
if (base.includes("opencode")) return "opencode";
|
|
152
|
+
return "custom";
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Farkli paket yoneticileri / kurulum araclari CLI'lari farkli dizinlere koyar. Her PC'de
|
|
156
|
+
// calismasi icin yaygin npm/pnpm/yarn/bun/volta/scoop/winget/choco/homebrew konumlarini tarariz.
|
|
157
|
+
function commonCandidates(id) {
|
|
158
|
+
const home = os.homedir();
|
|
159
|
+
if (isWin) {
|
|
160
|
+
const APPDATA = process.env.APPDATA, LOCAL = process.env.LOCALAPPDATA, PD = process.env.ProgramData;
|
|
161
|
+
const exts = ["cmd", "exe", "ps1", "bat", ""];
|
|
162
|
+
const bases = [
|
|
163
|
+
APPDATA && path.join(APPDATA, "npm"),
|
|
164
|
+
LOCAL && path.join(LOCAL, "pnpm"),
|
|
165
|
+
LOCAL && path.join(LOCAL, "Yarn", "bin"),
|
|
166
|
+
LOCAL && path.join(LOCAL, "Microsoft", "WinGet", "Links"),
|
|
167
|
+
LOCAL && path.join(LOCAL, "Programs", id),
|
|
168
|
+
path.join(home, ".bun", "bin"),
|
|
169
|
+
path.join(home, ".volta", "bin"),
|
|
170
|
+
path.join(home, "scoop", "shims"),
|
|
171
|
+
PD && path.join(PD, "chocolatey", "bin"),
|
|
172
|
+
path.join(home, ".local", "bin"),
|
|
173
|
+
path.join(home, "AppData", "Roaming", "npm"),
|
|
174
|
+
].filter(Boolean);
|
|
175
|
+
const out = [];
|
|
176
|
+
for (const base of bases) for (const ext of exts) out.push(path.join(base, ext ? `${id}.${ext}` : id));
|
|
177
|
+
return out;
|
|
178
|
+
}
|
|
179
|
+
return [
|
|
180
|
+
path.join(home, ".local", "bin", id),
|
|
181
|
+
path.join(home, "bin", id),
|
|
182
|
+
path.join(home, ".bun", "bin", id),
|
|
183
|
+
path.join(home, ".volta", "bin", id),
|
|
184
|
+
path.join(home, ".npm-global", "bin", id),
|
|
185
|
+
path.join(home, ".yarn", "bin", id),
|
|
186
|
+
path.join(home, ".local", "share", "pnpm", id),
|
|
187
|
+
`/usr/local/bin/${id}`,
|
|
188
|
+
`/opt/homebrew/bin/${id}`,
|
|
189
|
+
`/usr/bin/${id}`,
|
|
190
|
+
`/snap/bin/${id}`,
|
|
191
|
+
];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Bilinen bir CLI komutu adapter alanindan daha guvenilir kaynaktir. Eski veya elle
|
|
195
|
+
// duzenlenmis config'te adapter=claude + cmd=codex gibi bir celiski varsa hedef CLI'nin
|
|
196
|
+
// guvenli varsayilan argumanlarina donulur; boylece bir CLI'ye digerinin bayragi gitmez.
|
|
197
|
+
function normalizeAgentAdapter(agent) {
|
|
198
|
+
if (!agent || typeof agent !== "object") return false;
|
|
199
|
+
const configured = String(agent.adapter || "").trim().toLowerCase();
|
|
200
|
+
const inferred = adapterId(agent.cmd);
|
|
201
|
+
const adapter = inferred !== "custom" ? inferred : (DEFINITIONS[configured] ? configured : "custom");
|
|
202
|
+
let changed = false;
|
|
203
|
+
if (inferred !== "custom" && configured && configured !== inferred) {
|
|
204
|
+
agent.args = DEFINITIONS[inferred].defaultArgs.slice();
|
|
205
|
+
delete agent.model;
|
|
206
|
+
delete agent.modelOverride;
|
|
207
|
+
changed = true;
|
|
208
|
+
}
|
|
209
|
+
if (agent.adapter !== adapter) {
|
|
210
|
+
agent.adapter = adapter;
|
|
211
|
+
changed = true;
|
|
212
|
+
}
|
|
213
|
+
return changed;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function normalizeAgentAdapters(cfg) {
|
|
217
|
+
if (!cfg?.agents || typeof cfg.agents !== "object") return false;
|
|
218
|
+
let changed = false;
|
|
219
|
+
for (const agent of Object.values(cfg.agents)) if (normalizeAgentAdapter(agent)) changed = true;
|
|
220
|
+
return changed;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Ajan hapsi acik mi? cfg.sandbox.mode === "workspace" ise CLI'lar calisma klasoru DISINA
|
|
224
|
+
// yazamaz/aga cikamaz. cfg verilmeyen (test/edge) cagrilar hapissiz kalir; boylece mevcut
|
|
225
|
+
// arguman-esitlik testleri aynen gecer. Gercek calistirmada normalizeConfig mode'u daima
|
|
226
|
+
// doldurur (varsayilan "workspace").
|
|
227
|
+
function confineWorkspace(cfg) {
|
|
228
|
+
return cfg?.sandbox?.mode === "workspace";
|
|
229
|
+
}
|
|
230
|
+
function sandboxWritableRoots(cfg) {
|
|
231
|
+
const roots = cfg?.sandbox?.extraWritableDirs;
|
|
232
|
+
return Array.isArray(roots) ? roots.filter((x) => typeof x === "string" && x.trim()).map(String) : [];
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// cfg verilirse cfg.cliSettings[adapter] o CLI'nin varsayilan model ayari olarak uygulanir.
|
|
236
|
+
// Oncelik: agent.model (profil bazli) > cliSettings[adapter].model (global) > CLI varsayilani.
|
|
237
|
+
function effectiveAgent(agent, cfg) {
|
|
238
|
+
const copy = { ...agent, args: Array.isArray(agent.args) ? agent.args.map(String) : [] };
|
|
239
|
+
normalizeAgentAdapter(copy);
|
|
240
|
+
const adapter = copy.adapter;
|
|
241
|
+
const commandAdapter = adapterId(copy.cmd);
|
|
242
|
+
const settings = (cfg && cfg.cliSettings && cfg.cliSettings[adapter]) || {};
|
|
243
|
+
if (!copy.silenceTimeoutSeconds && DEFINITIONS[adapter]?.silenceTimeoutSeconds) copy.silenceTimeoutSeconds = DEFINITIONS[adapter].silenceTimeoutSeconds;
|
|
244
|
+
if (commandAdapter === adapter && RESOLVED.has(adapter) && !path.isAbsolute(copy.cmd)) copy.cmd = RESOLVED.get(adapter);
|
|
245
|
+
if (adapter === "codex") {
|
|
246
|
+
const commands = new Set(["exec", "review", "resume", "apply"]);
|
|
247
|
+
if (!copy.args.some((arg) => commands.has(arg))) copy.args.unshift("exec", "--skip-git-repo-check");
|
|
248
|
+
else if (copy.args.includes("exec") && !copy.args.includes("--skip-git-repo-check")) copy.args.splice(copy.args.indexOf("exec") + 1, 0, "--skip-git-repo-check");
|
|
249
|
+
// Hapis: calisma klasoru (spawn cwd = codex "workspace") disina yazma ve ag engellenir.
|
|
250
|
+
// Native sandbox — mac Seatbelt / Linux Landlock+seccomp / Windows restricted-token+ACL —
|
|
251
|
+
// Docker/Git GEREKTIRMEZ. Kullanici acikca kendi -s/--sandbox veya bypass bayragini
|
|
252
|
+
// koyduysa ona dokunmayiz. Bayrak, model/effort/tier PUSH'undan ONCE ve exec/skip-git'ten
|
|
253
|
+
// HEMEN SONRA eklenir; testlerin args.slice(0,2) ve slice(-6) beklentileri korunur.
|
|
254
|
+
const alreadySandboxed = copy.args.some((arg) => arg === "-s" || arg === "--sandbox" || arg === "--dangerously-bypass-approvals-and-sandbox" || arg === "--full-auto");
|
|
255
|
+
if (confineWorkspace(cfg) && !alreadySandboxed) {
|
|
256
|
+
const anchor = copy.args.indexOf("--skip-git-repo-check");
|
|
257
|
+
const at = anchor >= 0 ? anchor + 1 : Math.max(copy.args.indexOf("exec") + 1, 0);
|
|
258
|
+
const flags = ["-s", "workspace-write"];
|
|
259
|
+
const roots = sandboxWritableRoots(cfg);
|
|
260
|
+
if (roots.length) flags.push("-c", `sandbox_workspace_write.writable_roots=${JSON.stringify(roots)}`);
|
|
261
|
+
copy.args.splice(at, 0, ...flags);
|
|
262
|
+
}
|
|
263
|
+
const model = String(copy.model || settings.model || "").trim();
|
|
264
|
+
const effort = ["low", "medium", "high", "xhigh", "max", "ultra"].includes(String(settings.reasoningEffort)) ? String(settings.reasoningEffort) : "";
|
|
265
|
+
const serviceTier = /^[A-Za-z0-9._-]{1,64}$/.test(String(settings.serviceTier || "")) ? String(settings.serviceTier) : "";
|
|
266
|
+
if (model && !copy.args.includes("--model") && !copy.args.includes("-m")) copy.args.push("--model", model);
|
|
267
|
+
if (effort && !copy.args.some((arg) => String(arg).startsWith("model_reasoning_effort="))) copy.args.push("-c", `model_reasoning_effort="${effort}"`);
|
|
268
|
+
if (serviceTier && !copy.args.some((arg) => String(arg).startsWith("service_tier="))) copy.args.push("-c", `service_tier="${serviceTier}"`);
|
|
269
|
+
}
|
|
270
|
+
if (adapter === "claude") {
|
|
271
|
+
if (!copy.args.includes("-p") && !copy.args.includes("--print")) copy.args.unshift("-p");
|
|
272
|
+
if (!copy.args.includes("--output-format")) copy.args.push("--output-format", "text");
|
|
273
|
+
}
|
|
274
|
+
if (adapter === "gemini") {
|
|
275
|
+
// Otonom, non-interaktif calisma icin onay modu sart; yoksa izin bekleyip takilir.
|
|
276
|
+
if (!copy.args.includes("--approval-mode") && !copy.args.includes("-y") && !copy.args.includes("--yolo")) copy.args.push("--approval-mode", "yolo");
|
|
277
|
+
}
|
|
278
|
+
if (adapter === "opencode") {
|
|
279
|
+
if (!copy.args.includes("run")) copy.args.unshift("run");
|
|
280
|
+
// config.json'da eski otomatik profil kalmis olsa da uyumsuz bayragi temizle.
|
|
281
|
+
copy.args = copy.args.filter((arg) => arg !== "--auto");
|
|
282
|
+
const formatAt = copy.args.indexOf("--format");
|
|
283
|
+
if (formatAt >= 0) copy.args.splice(formatAt, 2);
|
|
284
|
+
copy.args.splice(copy.args.indexOf("run") + 1, 0, "--format", "json");
|
|
285
|
+
const hasModel = copy.args.includes("--model") || copy.args.includes("-m");
|
|
286
|
+
const model = copy.model || String(settings.model || "").trim() || selectOpenCodeModel(OPEN_CODE_MODELS);
|
|
287
|
+
if (!hasModel && model) copy.args.splice(copy.args.indexOf("run") + 3, 0, "--model", model);
|
|
288
|
+
if (model) copy.model = model;
|
|
289
|
+
if (!copy.args.includes("{PROMPT}") && !copy.args.includes("{PROMPT_FILE}")) {
|
|
290
|
+
copy.args.push("Attached file contains the full task. Follow it exactly, make the changes, and report what you did.", "--file", "{PROMPT_FILE}");
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return copy;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function probeCommand(command, definition) {
|
|
297
|
+
try {
|
|
298
|
+
const result = spawnSync(command, definition.versionArgs, {
|
|
299
|
+
encoding: "utf8",
|
|
300
|
+
timeout: 12000,
|
|
301
|
+
windowsHide: true,
|
|
302
|
+
shell: isWin && (!path.isAbsolute(command) || /\.(cmd|bat)$/i.test(command)),
|
|
303
|
+
});
|
|
304
|
+
const output = String(result.stdout || result.stderr || "").trim().split(/\r?\n/)[0];
|
|
305
|
+
return { installed: result.status === 0, version: result.status === 0 ? output : "", error: result.status === 0 ? "" : output, resolvedCommand: result.status === 0 ? command : "" };
|
|
306
|
+
} catch (error) {
|
|
307
|
+
return { installed: false, version: "", error: error.message, resolvedCommand: "" };
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function probe(id, definition) {
|
|
312
|
+
let result = probeCommand(definition.command, definition);
|
|
313
|
+
let installedPath = "";
|
|
314
|
+
if (!result.installed) {
|
|
315
|
+
for (const candidate of commonCandidates(id)) {
|
|
316
|
+
if (!fs.existsSync(candidate)) continue;
|
|
317
|
+
if (!installedPath) installedPath = candidate;
|
|
318
|
+
result = probeCommand(candidate, definition);
|
|
319
|
+
if (result.installed) break;
|
|
320
|
+
}
|
|
321
|
+
// Bazi CLI'lar (or. gemini) --version cagrisinda cmd.exe uzerinden yavas acildigi icin
|
|
322
|
+
// zaman asimina ugrar. Ikili dosya diskte mevcutsa, versiyon okunamasa bile "kurulu" say;
|
|
323
|
+
// aksi halde kurulu CLI yanlislikla devre disi birakiliyordu.
|
|
324
|
+
if (!result.installed && installedPath) {
|
|
325
|
+
result = { installed: true, version: "kurulu", error: "", resolvedCommand: installedPath };
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
if (result.installed) RESOLVED.set(id, result.resolvedCommand);
|
|
329
|
+
if (result.installed && id === "opencode") {
|
|
330
|
+
OPEN_CODE_MODELS = listOpenCodeModels(result.resolvedCommand || definition.command);
|
|
331
|
+
result.models = OPEN_CODE_MODELS.slice();
|
|
332
|
+
result.recommendedModel = selectOpenCodeModel(OPEN_CODE_MODELS);
|
|
333
|
+
result.ready = Boolean(result.recommendedModel);
|
|
334
|
+
result.readinessError = result.ready ? "" : (OPEN_CODE_MODELS.length
|
|
335
|
+
? "Kullanilabilir otomatik OpenCode modeli bulunamadi. Ayarlardan erisilebilir bir model secin."
|
|
336
|
+
: "OpenCode kurulu, ancak model listesi okunamadi. Once saglayici girisini tamamlayin.");
|
|
337
|
+
}
|
|
338
|
+
return result;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// Her acilista tum CLI'lar --version ile yoklaniyordu; olculen maliyet 4.8 saniye ve panel
|
|
342
|
+
// bu sure boyunca hic acilmiyordu. Onbellek YALNIZCA su kosulda kullanilir: CLI daha once
|
|
343
|
+
// KURULU bulunmus VE cozulmus ikili dosya HALA diskte duruyor. Bu durumda tekrar yoklamak
|
|
344
|
+
// zaten bilinen bir cevabi dogrulamaktan ibarettir.
|
|
345
|
+
//
|
|
346
|
+
// Bilerek onbelleklenmeyenler (dogruluk hizdan onceliklidir):
|
|
347
|
+
// - Daha once "kurulu degil" bulunanlar -> yeni kurulan CLI ilk acilista gorunur.
|
|
348
|
+
// - Diskte bulunamayan cozulmus yol -> kaldirilan CLI hemen fark edilir.
|
|
349
|
+
// - opencode -> model listesi/ready durumu degisebilir;
|
|
350
|
+
// her acilista tam yoklanir, davranisi aynen korunur.
|
|
351
|
+
// "Yeniden Tara" (/api/cli/discover) daima force ile cagirir ve onbellegi tumden atlar.
|
|
352
|
+
const DISCOVERY_CACHE_VERSION = 1;
|
|
353
|
+
const ALWAYS_PROBE = new Set(["opencode"]);
|
|
354
|
+
|
|
355
|
+
// probeCommand, CLI'yi PATH uzerinden buldugunda resolvedCommand'i CIPLAK AD olarak dondurur
|
|
356
|
+
// ("codex"), mutlak yol olarak degil. Duz fs.existsSync bu durumda daima false verir ve
|
|
357
|
+
// onbellek hic tutmaz. Bu yuzden ciplak adlar PATH (+ Windows'ta PATHEXT) uzerinde aranir:
|
|
358
|
+
// spawn maliyeti olmadan, birkac milisaniyede ve dogru sonucla.
|
|
359
|
+
function resolvesOnPath(command) {
|
|
360
|
+
if (!command) return false;
|
|
361
|
+
if (command.includes("/") || command.includes("\\")) return fs.existsSync(command);
|
|
362
|
+
const dirs = String(process.env.PATH || "").split(path.delimiter).filter(Boolean);
|
|
363
|
+
const exts = isWin ? String(process.env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean) : [""];
|
|
364
|
+
for (const dir of dirs) {
|
|
365
|
+
for (const ext of exts) {
|
|
366
|
+
try { if (fs.existsSync(path.join(dir, command + ext))) return true; } catch {}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function cachedProbeUsable(entry) {
|
|
373
|
+
return Boolean(entry && entry.installed && entry.resolvedCommand && resolvesOnPath(entry.resolvedCommand));
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// OpenCode model listesi persist EDILMEZ; her acilista `opencode models` ile bellekten
|
|
377
|
+
// uretilir. O cagri acilista gecici olarak yavas/basarisiz olursa (soguk ilk cagri, auth
|
|
378
|
+
// oturmamis, ag) liste bos kalir ve panel model dropdown'i o process boyunca bos gorunur.
|
|
379
|
+
// codex icin codexModelCache ile cozulen bu kirilganligi opencode icin de kapatiriz: prob
|
|
380
|
+
// bos donerse son basarili liste (config'te saklanan) fallback olarak kullanilir. Fallback
|
|
381
|
+
// ayni zamanda OPEN_CODE_MODELS'i doldurur ki otomatik model secimi de calissin.
|
|
382
|
+
function applyOpenCodeFallback(entry, fallback) {
|
|
383
|
+
if (!entry || entry.id !== "opencode" || !entry.installed) return entry;
|
|
384
|
+
if ((entry.models && entry.models.length) || !Array.isArray(fallback) || !fallback.length) return entry;
|
|
385
|
+
const models = fallback.map(String).filter(Boolean);
|
|
386
|
+
if (!models.length) return entry;
|
|
387
|
+
OPEN_CODE_MODELS = models.slice();
|
|
388
|
+
entry.models = models.slice();
|
|
389
|
+
entry.recommendedModel = selectOpenCodeModel(models);
|
|
390
|
+
entry.ready = Boolean(entry.recommendedModel);
|
|
391
|
+
entry.modelsFromCache = true;
|
|
392
|
+
if (entry.ready) entry.readinessError = "";
|
|
393
|
+
return entry;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function discoverInstalled(options = {}) {
|
|
397
|
+
const cache = options.cache?.version === DISCOVERY_CACHE_VERSION ? options.cache.results || {} : {};
|
|
398
|
+
const force = options.force === true;
|
|
399
|
+
const openCodeFallback = Array.isArray(options.openCodeModels) ? options.openCodeModels : [];
|
|
400
|
+
return Object.entries(DEFINITIONS).map(([id, definition]) => {
|
|
401
|
+
const cached = cache[id];
|
|
402
|
+
if (!force && !ALWAYS_PROBE.has(id) && cachedProbeUsable(cached)) {
|
|
403
|
+
RESOLVED.set(id, cached.resolvedCommand);
|
|
404
|
+
return { id, ...definition, installed: true, version: cached.version || "kurulu", error: "", resolvedCommand: cached.resolvedCommand, fromCache: true };
|
|
405
|
+
}
|
|
406
|
+
const result = { id, ...definition, ...probe(id, definition) };
|
|
407
|
+
return id === "opencode" ? applyOpenCodeFallback(result, openCodeFallback) : result;
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// Bir sonraki acilista kullanilacak onbellek gorununu uretir. Yalnizca kurulu ve yolu
|
|
412
|
+
// cozulmus girdiler saklanir; digerleri zaten her acilista yeniden yoklanir.
|
|
413
|
+
function discoveryCacheFrom(discovered) {
|
|
414
|
+
const results = {};
|
|
415
|
+
for (const cli of discovered || []) {
|
|
416
|
+
if (cli.installed && cli.resolvedCommand && !ALWAYS_PROBE.has(cli.id)) {
|
|
417
|
+
results[cli.id] = { installed: true, version: cli.version || "kurulu", resolvedCommand: cli.resolvedCommand };
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return { version: DISCOVERY_CACHE_VERSION, checkedAt: new Date().toISOString(), results };
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// Tek kaynak: hem gercek gorev calistirici (engine.runCli) hem saglik testi ve model
|
|
424
|
+
// listeleme ayni komut kurulumunu kullanir. Bare npm CLI adlarini where.exe ile fiziksel
|
|
425
|
+
// yola cevirmiyoruz; cmd.exe PATHEXT/PATH cozumlemesini Unicode olarak kendisi yapar.
|
|
426
|
+
function buildCommand(command, args) {
|
|
427
|
+
if (!isWin) return { file: command, args, shell: false };
|
|
428
|
+
const bare = !path.isAbsolute(command) && !/[\\/]/.test(command);
|
|
429
|
+
if (bare) {
|
|
430
|
+
// shell:true iken Node argumanlari birlestirip cmd.exe'ye verir ve OTOMATIK TIRNAK KOYMAZ.
|
|
431
|
+
// Bosluk iceren yol argumanlari (or. "C:\Users\John Doe\...\x.settings.json" veya
|
|
432
|
+
// {PROMPT_FILE}) ikiye bolunurdu; bu da --settings/--file yolunu bozardi. Bosluk veya
|
|
433
|
+
// kabuk metakarakteri iceren argumanlari tirnakla; sade bayrak/model adlari dokunulmaz.
|
|
434
|
+
const shellQuote = (value) => {
|
|
435
|
+
const v = String(value);
|
|
436
|
+
return /[\s"^&|<>()%!]/.test(v) ? `"${v.replace(/"/g, '\\"')}"` : v;
|
|
437
|
+
};
|
|
438
|
+
return { file: command, args: args.map(shellQuote), shell: true };
|
|
439
|
+
}
|
|
440
|
+
if (!/\.(cmd|bat)$/i.test(command)) return { file: command, args, shell: false };
|
|
441
|
+
const quote = (value) => `"${String(value).replace(/"/g, '""')}"`;
|
|
442
|
+
return { file: process.env.ComSpec || "cmd.exe", args: ["/d", "/s", "/c", `"${[command, ...args].map(quote).join(" ")}"`], shell: false, verbatim: true };
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function healthPrompt(id) {
|
|
446
|
+
return [
|
|
447
|
+
"CLI_TEAM_HEALTH_CHECK",
|
|
448
|
+
`Bu ${id} cli aracinin kullanilabilirlik testidir.`,
|
|
449
|
+
"Yalnizca HEALTH_OK yaz.",
|
|
450
|
+
"Dosya olusturma, degistirme, silme, komut calistirma veya dis sisteme istek gonderme.",
|
|
451
|
+
].join("\n");
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// Normal gorev calistiricisi {PROMPT}/{PROMPT_FILE} yer tutucularini cagridan once
|
|
455
|
+
// doldurur. Health check de ayni sozlesmeyi kullanmali; aksi halde OpenCode literal
|
|
456
|
+
// `{PROMPT_FILE}` yolunu acmaya calisir ve saglikli agent katalogdan yanlislikla elenir.
|
|
457
|
+
function preparePromptArgs(args, prompt) {
|
|
458
|
+
let tempDir = "", promptFile = "", useStdin = true;
|
|
459
|
+
const prepared = (Array.isArray(args) ? args : []).map((arg) => {
|
|
460
|
+
const value = String(arg);
|
|
461
|
+
if (value.includes("{PROMPT}")) {
|
|
462
|
+
useStdin = false;
|
|
463
|
+
return value.replaceAll("{PROMPT}", prompt);
|
|
464
|
+
}
|
|
465
|
+
if (value.includes("{PROMPT_FILE}")) {
|
|
466
|
+
useStdin = false;
|
|
467
|
+
if (!promptFile) {
|
|
468
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "cli-team-health-"));
|
|
469
|
+
promptFile = path.join(tempDir, "prompt.md");
|
|
470
|
+
fs.writeFileSync(promptFile, prompt, "utf8");
|
|
471
|
+
}
|
|
472
|
+
return value.replaceAll("{PROMPT_FILE}", promptFile);
|
|
473
|
+
}
|
|
474
|
+
return value;
|
|
475
|
+
});
|
|
476
|
+
return {
|
|
477
|
+
args: prepared,
|
|
478
|
+
useStdin,
|
|
479
|
+
promptFile,
|
|
480
|
+
cleanup() { if (tempDir) { try { fs.rmSync(tempDir, { recursive: true, force: true }); } catch {} } },
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// Tek kaynak: OpenCode icin otonom izinler surumden bagimsiz olarak OPENCODE_CONFIG_CONTENT
|
|
485
|
+
// ile aktarilir. Hem engine.runCli hem saglik testi bu ortami kullanir ki test ile gercek
|
|
486
|
+
// calistirma ayni izinlerle calissin.
|
|
487
|
+
function agentEnvironment(agent) {
|
|
488
|
+
const env = { ...process.env };
|
|
489
|
+
if (agent.adapter !== "opencode") return env;
|
|
490
|
+
let inline = {};
|
|
491
|
+
try { inline = JSON.parse(env.OPENCODE_CONFIG_CONTENT || "{}"); } catch {}
|
|
492
|
+
env.OPENCODE_CONFIG_CONTENT = JSON.stringify({ ...inline, permission: { "*": "allow" } });
|
|
493
|
+
return env;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function classifyHealthFailure(text) {
|
|
497
|
+
const raw = String(text || "");
|
|
498
|
+
if (/requires a newer version|upgrade to the latest|version.*unsupported|unsupported.*version|model metadata.*not found|unsupported.*model/i.test(raw)) return { status: "version-incompatible", label: "Sürüm uyumsuz", detail: raw };
|
|
499
|
+
if (/api key|unauthorized|unauthenticated|authentication|login required|not logged in|sign in|giriÅŸ gerekli/i.test(raw)) return { status: "auth-required", label: "Giriş gerekli", detail: raw };
|
|
500
|
+
if (/rate.?limit|quota|too many requests|billing|credit/i.test(raw)) return { status: "quota", label: "Kota veya ödeme gerekli", detail: raw };
|
|
501
|
+
if (/timeout|timed out|zaman aşım/i.test(raw)) return { status: "timeout", label: "Yanıt zaman aşımına uğradı", detail: raw };
|
|
502
|
+
return { status: "failed", label: "Test başarısız", detail: raw };
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function testInstalledCli(id, options = {}) {
|
|
506
|
+
const definition = DEFINITIONS[id];
|
|
507
|
+
if (!definition) return Promise.resolve({ id, installed: false, health: { status: "unknown", label: "Bilinmiyor", detail: "Tanımsız CLI" } });
|
|
508
|
+
const found = probe(id, definition);
|
|
509
|
+
if (!found.installed) return Promise.resolve({ id, installed: false, version: found.version, error: found.error, health: { status: "not-installed", label: "Kurulu değil", detail: found.error || "CLI bulunamadı" } });
|
|
510
|
+
const agent = effectiveAgent({ adapter: id, cmd: definition.command, args: definition.defaultArgs.slice() }, options.cfg);
|
|
511
|
+
const prompt = healthPrompt(id);
|
|
512
|
+
const prepared = preparePromptArgs(agent.args, prompt);
|
|
513
|
+
const command = buildCommand(agent.cmd, prepared.args);
|
|
514
|
+
const timeoutMs = Math.max(10000, Number(options.timeoutMs || 45000));
|
|
515
|
+
return new Promise((resolve) => {
|
|
516
|
+
let stdout = "", stderr = "", settled = false;
|
|
517
|
+
let child;
|
|
518
|
+
try {
|
|
519
|
+
child = spawn(command.file, command.args, { env: agentEnvironment(agent), shell: command.shell, windowsHide: true, windowsVerbatimArguments: !!command.verbatim });
|
|
520
|
+
} catch (error) {
|
|
521
|
+
prepared.cleanup();
|
|
522
|
+
return resolve({ id, installed: true, version: found.version, health: classifyHealthFailure(error.message) });
|
|
523
|
+
}
|
|
524
|
+
const unregister = registerProbe(child);
|
|
525
|
+
const timer = setTimeout(() => {
|
|
526
|
+
if (settled) return;
|
|
527
|
+
settled = true;
|
|
528
|
+
unregister();
|
|
529
|
+
terminateProbeTree(child);
|
|
530
|
+
prepared.cleanup();
|
|
531
|
+
resolve({ id, installed: true, version: found.version, health: { status: "timeout", label: "Yanıt zaman aşımına uğradı", detail: `Sağlık testi ${Math.round(timeoutMs / 1000)} saniyede tamamlanmadı.` } });
|
|
532
|
+
}, timeoutMs);
|
|
533
|
+
child.stdout?.setEncoding("utf8");
|
|
534
|
+
child.stderr?.setEncoding("utf8");
|
|
535
|
+
child.stdout?.on("data", (data) => { stdout += String(data); });
|
|
536
|
+
child.stderr?.on("data", (data) => { stderr += String(data); });
|
|
537
|
+
child.on("error", (error) => {
|
|
538
|
+
if (settled) return;
|
|
539
|
+
settled = true;
|
|
540
|
+
clearTimeout(timer);
|
|
541
|
+
unregister();
|
|
542
|
+
prepared.cleanup();
|
|
543
|
+
const failure = classifyHealthFailure(error.message);
|
|
544
|
+
resolve({ id, installed: true, version: found.version, health: failure });
|
|
545
|
+
});
|
|
546
|
+
child.on("close", (code) => {
|
|
547
|
+
if (settled) return;
|
|
548
|
+
settled = true;
|
|
549
|
+
clearTimeout(timer);
|
|
550
|
+
unregister();
|
|
551
|
+
prepared.cleanup();
|
|
552
|
+
const raw = `${stdout}\n${stderr}`.trim();
|
|
553
|
+
if (code === 0 && /HEALTH_OK/i.test(raw)) resolve({ id, installed: true, version: found.version, health: { status: "ready", label: "Hazır", detail: "Gerçek sağlık testi başarılı." } });
|
|
554
|
+
else resolve({ id, installed: true, version: found.version, health: classifyHealthFailure(raw || `Çıkış kodu ${code}`) });
|
|
555
|
+
});
|
|
556
|
+
child.stdin?.on("error", () => {});
|
|
557
|
+
child.stdin?.end(prepared.useStdin ? prompt : "");
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
async function healthCheckAll(discovered = discoverInstalled(), options = {}) {
|
|
562
|
+
const results = await Promise.all(discovered.map((item) => testInstalledCli(item.id, options)));
|
|
563
|
+
return discovered.map((item) => ({ ...item, ...(results.find((result) => result.id === item.id) || {}) }));
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
function listCodexModels(options = {}) {
|
|
567
|
+
const command = buildCommand("codex", ["app-server", "--listen", "stdio://"]);
|
|
568
|
+
const timeoutMs = Math.max(5000, Number(options.timeoutMs || 20000));
|
|
569
|
+
return new Promise((resolve, reject) => {
|
|
570
|
+
let buffer = "", settled = false, modelRequestSent = false;
|
|
571
|
+
let child, unregister = () => {};
|
|
572
|
+
const finish = (error, value) => {
|
|
573
|
+
if (settled) return;
|
|
574
|
+
settled = true;
|
|
575
|
+
clearTimeout(timer);
|
|
576
|
+
unregister();
|
|
577
|
+
terminateProbeTree(child);
|
|
578
|
+
if (error) reject(error); else resolve(value);
|
|
579
|
+
};
|
|
580
|
+
const timer = setTimeout(() => finish(new Error(`Codex model listesi ${Math.round(timeoutMs / 1000)} saniyede alınamadı.`)), timeoutMs);
|
|
581
|
+
try { child = spawn(command.file, command.args, { shell: command.shell, windowsHide: true, windowsVerbatimArguments: !!command.verbatim }); }
|
|
582
|
+
catch (error) { finish(error); return; }
|
|
583
|
+
unregister = registerProbe(child);
|
|
584
|
+
child.stdout?.setEncoding("utf8");
|
|
585
|
+
child.stderr?.setEncoding("utf8");
|
|
586
|
+
child.stdout?.on("data", (chunk) => {
|
|
587
|
+
buffer += String(chunk);
|
|
588
|
+
const lines = buffer.split(/\r?\n/);
|
|
589
|
+
buffer = lines.pop() || "";
|
|
590
|
+
for (const line of lines) {
|
|
591
|
+
let message;
|
|
592
|
+
try { message = JSON.parse(line); } catch { continue; }
|
|
593
|
+
if (message.id === 1 && !modelRequestSent) {
|
|
594
|
+
modelRequestSent = true;
|
|
595
|
+
child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", id: 2, method: "model/list", params: { includeHidden: false, limit: 200 } })}\n`);
|
|
596
|
+
} else if (message.id === 2) {
|
|
597
|
+
if (message.error) { finish(new Error(message.error.message || "Codex model listesi alınamadı.")); return; }
|
|
598
|
+
const models = Array.isArray(message.result?.data) ? message.result.data : [];
|
|
599
|
+
finish(null, models.filter((model) => model && model.hidden !== true).map((model) => ({
|
|
600
|
+
id: String(model.id || model.model || ""),
|
|
601
|
+
model: String(model.model || model.id || ""),
|
|
602
|
+
displayName: String(model.displayName || model.id || model.model || ""),
|
|
603
|
+
description: String(model.description || ""),
|
|
604
|
+
defaultReasoningEffort: String(model.defaultReasoningEffort || "medium"),
|
|
605
|
+
reasoningEfforts: (model.supportedReasoningEfforts || []).map((item) => ({
|
|
606
|
+
id: String(item.reasoningEffort || item.id || ""),
|
|
607
|
+
description: String(item.description || ""),
|
|
608
|
+
})).filter((item) => item.id),
|
|
609
|
+
serviceTiers: (model.serviceTiers || []).map((item) => ({
|
|
610
|
+
id: String(item.id || ""),
|
|
611
|
+
name: String(item.name || item.id || ""),
|
|
612
|
+
description: String(item.description || ""),
|
|
613
|
+
})).filter((item) => item.id),
|
|
614
|
+
additionalSpeedTiers: Array.isArray(model.additionalSpeedTiers) ? model.additionalSpeedTiers.map(String) : [],
|
|
615
|
+
defaultServiceTier: model.defaultServiceTier ? String(model.defaultServiceTier) : "",
|
|
616
|
+
isDefault: model.isDefault === true,
|
|
617
|
+
})).filter((model) => model.id));
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
child.stderr?.on("data", () => {});
|
|
622
|
+
child.on("error", finish);
|
|
623
|
+
child.stdin?.on("error", () => {});
|
|
624
|
+
child.stdin?.write(`${JSON.stringify({ jsonrpc: "2.0", id: 1, method: "initialize", params: { clientInfo: { name: "crewctl", version: "1.0.0", title: "CrewCtl" } } })}\n`);
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
function addMissingAgents(cfg, discovered) {
|
|
629
|
+
cfg.agents ||= {};
|
|
630
|
+
const ignored = new Set(Array.isArray(cfg.discoveryIgnoredAdapters) ? cfg.discoveryIgnoredAdapters.map(String) : []);
|
|
631
|
+
let changed = normalizeAgentAdapters(cfg);
|
|
632
|
+
for (const cli of discovered) {
|
|
633
|
+
const usable = cli.installed && (cli.id !== "opencode" || cli.ready !== false || Boolean(cfg.cliSettings?.opencode?.model));
|
|
634
|
+
const matchingEntries = Object.entries(cfg.agents).filter(([, agent]) => (agent.adapter || adapterId(agent.cmd)) === cli.id);
|
|
635
|
+
const existingEntry = matchingEntries.find(([, agent]) => !agent.autoDiscovered) || matchingEntries[0];
|
|
636
|
+
const existing = existingEntry?.[1];
|
|
637
|
+
// Kullanici otomatik bulunan bir profili sildiyse bu karar kalicidir. O adapter'a ait
|
|
638
|
+
// elle olusturulmus profil varsa ona dokunma; yalnizca autoDiscovered kaydini temizle.
|
|
639
|
+
if (ignored.has(cli.id)) {
|
|
640
|
+
for (const [name, agent] of matchingEntries) {
|
|
641
|
+
if (!agent.autoDiscovered) continue;
|
|
642
|
+
delete cfg.agents[name];
|
|
643
|
+
changed = true;
|
|
644
|
+
}
|
|
645
|
+
continue;
|
|
646
|
+
}
|
|
647
|
+
if (existing) {
|
|
648
|
+
if (usable && existing.autoDiscovered && existing.unavailablePlaceholder) {
|
|
649
|
+
existing.enabled = true;
|
|
650
|
+
existing.args = cli.defaultArgs.slice();
|
|
651
|
+
delete existing.unavailablePlaceholder;
|
|
652
|
+
changed = true;
|
|
653
|
+
}
|
|
654
|
+
// Eski surumler otomatik oneriyi agent.model alanina yaziyordu. Bu alan global
|
|
655
|
+
// CLI ayarini ezdigi icin, kullanici tarafindan acikca override olarak isaretlenmemis
|
|
656
|
+
// otomatik profiller modeli daima CLI ayarindan/otomatik secimden miras alir.
|
|
657
|
+
if (cli.id === "opencode" && existing.autoDiscovered && existing.model && existing.modelOverride !== true) {
|
|
658
|
+
delete existing.model;
|
|
659
|
+
changed = true;
|
|
660
|
+
}
|
|
661
|
+
if (cli.installed && cli.id === "opencode" && existing.autoDiscovered && Number(existing.timeoutSeconds || 0) < cli.timeoutSeconds) {
|
|
662
|
+
existing.timeoutSeconds = cli.timeoutSeconds;
|
|
663
|
+
changed = true;
|
|
664
|
+
}
|
|
665
|
+
if (!usable && existing.autoDiscovered && existing.enabled !== false) {
|
|
666
|
+
existing.enabled = false;
|
|
667
|
+
existing.unavailablePlaceholder = true;
|
|
668
|
+
changed = true;
|
|
669
|
+
}
|
|
670
|
+
continue;
|
|
671
|
+
}
|
|
672
|
+
// OpenCode adapteri her cihazda katalogda gorunur. Kurulu degilse guvenli
|
|
673
|
+
// sekilde devre disi placeholder olur; taramada bulundugunda otomatik etkinlesir.
|
|
674
|
+
if (!cli.installed && cli.id !== "opencode") continue;
|
|
675
|
+
let name = `${cli.id}-auto`, suffix = 2;
|
|
676
|
+
while (cfg.agents[name]) name = `${cli.id}-auto-${suffix++}`;
|
|
677
|
+
cfg.agents[name] = {
|
|
678
|
+
adapter: cli.id,
|
|
679
|
+
cmd: cli.command,
|
|
680
|
+
args: cli.defaultArgs.slice(),
|
|
681
|
+
enabled: usable,
|
|
682
|
+
description: cli.description,
|
|
683
|
+
capabilities: cli.capabilities.slice(),
|
|
684
|
+
roleFile: cli.roleFile,
|
|
685
|
+
costTier: "standard",
|
|
686
|
+
timeoutSeconds: cli.timeoutSeconds || 1200,
|
|
687
|
+
...(cli.silenceTimeoutSeconds ? { silenceTimeoutSeconds: cli.silenceTimeoutSeconds } : {}),
|
|
688
|
+
autoDiscovered: true,
|
|
689
|
+
...(!usable ? { unavailablePlaceholder: true } : {}),
|
|
690
|
+
};
|
|
691
|
+
changed = true;
|
|
692
|
+
}
|
|
693
|
+
return changed;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
// Operator, uzman agent'lardan BAGIMSIZ bir CLI secimidir (claude/codex/gemini/opencode).
|
|
697
|
+
// operator.md rolunu bu CLI giyer; uzman agent'lar operatorun ALTINDA delege edilir.
|
|
698
|
+
// Bir uzman agent silinse bile operator etkilenmez.
|
|
699
|
+
function operatorSpec(cli, cfg) {
|
|
700
|
+
const op = (cfg && cfg.operator) || {};
|
|
701
|
+
const definition = DEFINITIONS[cli];
|
|
702
|
+
// Standart CLI'lar DEFINITIONS'tan cozulur. cfg.operator.cmd verilirse (ozel/test operatoru)
|
|
703
|
+
// dogrudan o komut kullanilir; boylece operator, uzman agent'lardan tamamen bagimsiz kalir.
|
|
704
|
+
const cmd = op.cmd || (definition && definition.command);
|
|
705
|
+
if (!cmd) return null;
|
|
706
|
+
const args = op.cmd ? (Array.isArray(op.args) ? op.args.slice() : []) : (definition ? definition.defaultArgs.slice() : []);
|
|
707
|
+
// Model/effort/tier secimi CLI bazlidir (cfg.cliSettings) ve effectiveAgent icinde uygulanir;
|
|
708
|
+
// ayni ayar o CLI'yi kullanan operator ve tum uzman agent'lar icin gecerlidir.
|
|
709
|
+
const timeoutSeconds = op.timeoutSeconds || (cfg && cfg.agentTimeoutSeconds) || 900;
|
|
710
|
+
const silenceTimeoutSeconds = op.silenceTimeoutSeconds || (definition && definition.silenceTimeoutSeconds) || (cfg && cfg.cliSilenceTimeoutSeconds) || 300;
|
|
711
|
+
const adapter = definition ? cli : (op.adapter || adapterId(cmd));
|
|
712
|
+
return effectiveAgent({ adapter, cmd, args, timeoutSeconds, silenceTimeoutSeconds }, cfg);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// Operator gecerli, kurulu bir CLI olmali. Eski semada operator.agent (uzman agent adi)
|
|
716
|
+
// tutuluyordu; burada operator.cli'ye tasinir. Kurulu degilse ilk kurulu CLI'ye gecilir.
|
|
717
|
+
function ensureValidOperator(cfg, discovered) {
|
|
718
|
+
cfg.operator ||= {};
|
|
719
|
+
let changed = false;
|
|
720
|
+
if (cfg.operator.roleFile !== "roles/operator.md") { cfg.operator.roleFile = "roles/operator.md"; changed = true; }
|
|
721
|
+
if (!cfg.operator.cli) {
|
|
722
|
+
const legacy = cfg.operator.agent;
|
|
723
|
+
const source = legacy && cfg.agents?.[legacy] ? cfg.agents[legacy].cmd : legacy;
|
|
724
|
+
cfg.operator.cli = adapterId(source || "codex");
|
|
725
|
+
changed = true;
|
|
726
|
+
}
|
|
727
|
+
if ("agent" in cfg.operator) { delete cfg.operator.agent; changed = true; }
|
|
728
|
+
const installed = Array.isArray(discovered) ? discovered
|
|
729
|
+
.filter((x) => x.installed && (x.id !== "opencode" || x.ready !== false || Boolean(cfg.cliSettings?.opencode?.model)))
|
|
730
|
+
.map((x) => x.id) : null;
|
|
731
|
+
const known = !!DEFINITIONS[cfg.operator.cli];
|
|
732
|
+
const availableOnHost = !installed || installed.length === 0 || installed.includes(cfg.operator.cli);
|
|
733
|
+
if (!known || !availableOnHost) {
|
|
734
|
+
const fallback = (installed && installed[0]) || Object.keys(DEFINITIONS)[0];
|
|
735
|
+
if (fallback && fallback !== cfg.operator.cli) { cfg.operator.cli = fallback; changed = true; }
|
|
736
|
+
}
|
|
737
|
+
return changed;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
module.exports = { DEFINITIONS, KNOWN_CLIS: Object.keys(DEFINITIONS), adapterId, normalizeAgentAdapter, normalizeAgentAdapters, effectiveAgent, preparePromptArgs, operatorSpec, buildCommand, agentEnvironment, discoverInstalled, discoveryCacheFrom, applyOpenCodeFallback, healthCheckAll, listCodexModels, abortActiveProbes, currentProbeGeneration, selectOpenCodeModel, parseOpenCodeModels, addMissingAgents, ensureValidOperator };
|