beast-agent 2.15.0 → 2.17.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/package.json +1 -1
- package/src/agent/engine.js +505 -156
- package/src/agent/opencode/agents.js +161 -0
- package/src/agent/opencode/askperm.js +135 -0
- package/src/agent/opencode/index.js +51 -0
- package/src/agent/opencode/permission.js +108 -0
- package/src/agent/opencode/prompts/anthropic.txt +105 -0
- package/src/agent/opencode/prompts/beast.txt +147 -0
- package/src/agent/opencode/prompts/build-switch.txt +5 -0
- package/src/agent/opencode/prompts/codex.txt +79 -0
- package/src/agent/opencode/prompts/default.txt +95 -0
- package/src/agent/opencode/prompts/edit.txt +10 -0
- package/src/agent/opencode/prompts/explore.txt +18 -0
- package/src/agent/opencode/prompts/gemini.txt +155 -0
- package/src/agent/opencode/prompts/glob.txt +6 -0
- package/src/agent/opencode/prompts/gpt.txt +107 -0
- package/src/agent/opencode/prompts/grep.txt +8 -0
- package/src/agent/opencode/prompts/kimi.txt +95 -0
- package/src/agent/opencode/prompts/max-steps.txt +16 -0
- package/src/agent/opencode/prompts/meta.txt +65 -0
- package/src/agent/opencode/prompts/plan.txt +26 -0
- package/src/agent/opencode/prompts/read.txt +14 -0
- package/src/agent/opencode/prompts/skill.txt +5 -0
- package/src/agent/opencode/prompts/task.txt +19 -0
- package/src/agent/opencode/prompts/todowrite.txt +44 -0
- package/src/agent/opencode/prompts/trinity.txt +97 -0
- package/src/agent/opencode/prompts/webfetch.txt +13 -0
- package/src/agent/opencode/prompts/websearch.txt +14 -0
- package/src/agent/opencode/prompts/write.txt +8 -0
- package/src/agent/opencode/systemprompt.js +157 -0
- package/src/agent/opencode/toolmap.js +316 -0
- package/src/agent/supermemory.js +132 -0
- package/src/main.js +135 -41
- package/src/preload.js +5 -0
- package/src/renderer/renderer.js +59 -15
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/* ---------- opencode agent/agent.ts portu (birebir) ----------
|
|
4
|
+
Beast Code (bcCode) oturumları artık "mod" değil AJAN koşar:
|
|
5
|
+
build (varsayılan) · plan (salt-okur) · general/explore (task alt-ajanları).
|
|
6
|
+
|
|
7
|
+
Agent.Info şeması (opencode):
|
|
8
|
+
{ name, description, mode: 'subagent'|'primary'|'all', hidden, temperature,
|
|
9
|
+
permission: Ruleset, model?, prompt?, steps?, options }
|
|
10
|
+
|
|
11
|
+
Permission birleşim sırası (opencode birebir): defaults → ajan özel → user.
|
|
12
|
+
Son eşleşen kural kazanır (permission.evaluate findLast). */
|
|
13
|
+
|
|
14
|
+
const path = require('path');
|
|
15
|
+
const Permission = require('./permission');
|
|
16
|
+
|
|
17
|
+
/* opencode SystemPrompt.environment'daki gibi runtime klasörleri ajan
|
|
18
|
+
kurallarına basar: plan ajanı workspace içindeki .opencode/plans/*.md'ye
|
|
19
|
+
yazabilir (opencode: Global.Path.data/plans + .opencode/plans/*.md allow) */
|
|
20
|
+
function planRules(worktree) {
|
|
21
|
+
const ws = String(worktree || '');
|
|
22
|
+
return Permission.fromConfig({
|
|
23
|
+
question: 'allow',
|
|
24
|
+
plan_exit: 'allow',
|
|
25
|
+
task: { general: 'deny' },
|
|
26
|
+
external_directory: { '*': 'ask' },
|
|
27
|
+
edit: {
|
|
28
|
+
'*': 'deny',
|
|
29
|
+
[path.join('.opencode', 'plans', '*.md')]: 'allow',
|
|
30
|
+
...(ws ? { [path.join(ws, '.opencode', 'plans', '*.md')]: 'allow' } : {}),
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* opencode agent.ts defaults (satır 119-136) — birebir.
|
|
36
|
+
Beast'te "question" aracı yok; kural etkisiz kalır, dokunma.
|
|
37
|
+
panel_run: Beast'e özgü (Sandbox ÇALIŞTIR paneli) — default DENY,
|
|
38
|
+
yalnız sandbox ajanında allow edilir (opencode custom-agent deseni). */
|
|
39
|
+
function defaultRuleset() {
|
|
40
|
+
return Permission.fromConfig({
|
|
41
|
+
'*': 'allow',
|
|
42
|
+
doom_loop: 'ask',
|
|
43
|
+
external_directory: { '*': 'ask' },
|
|
44
|
+
question: 'deny',
|
|
45
|
+
plan_enter: 'deny',
|
|
46
|
+
plan_exit: 'deny',
|
|
47
|
+
panel_run: 'deny',
|
|
48
|
+
// github/gitignore Node.gitignore desenine uygun .env koruması
|
|
49
|
+
read: {
|
|
50
|
+
'*': 'allow',
|
|
51
|
+
'*.env': 'ask',
|
|
52
|
+
'*.env.*': 'ask',
|
|
53
|
+
'*.env.example': 'allow',
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* Yerleşik ajanlar — opencode agent.ts:140-265 birebir (promptlar
|
|
59
|
+
opencode-dev'den kopyalandı: prompts/explore.txt) */
|
|
60
|
+
function build(opts = {}) {
|
|
61
|
+
const defaults = defaultRuleset();
|
|
62
|
+
const user = Permission.fromConfig(opts.user || {});
|
|
63
|
+
return {
|
|
64
|
+
build: {
|
|
65
|
+
name: 'build',
|
|
66
|
+
description: 'The default agent. Executes tools based on configured permissions.',
|
|
67
|
+
options: {},
|
|
68
|
+
permission: Permission.merge(
|
|
69
|
+
defaults,
|
|
70
|
+
Permission.fromConfig({ question: 'allow', plan_enter: 'allow' }),
|
|
71
|
+
user
|
|
72
|
+
),
|
|
73
|
+
mode: 'primary',
|
|
74
|
+
native: true,
|
|
75
|
+
},
|
|
76
|
+
plan: {
|
|
77
|
+
name: 'plan',
|
|
78
|
+
description: 'Plan mode. Disallows all edit tools.',
|
|
79
|
+
options: {},
|
|
80
|
+
permission: Permission.merge(defaults, planRules(opts.worktree), user),
|
|
81
|
+
mode: 'primary',
|
|
82
|
+
native: true,
|
|
83
|
+
},
|
|
84
|
+
general: {
|
|
85
|
+
name: 'general',
|
|
86
|
+
description:
|
|
87
|
+
'General-purpose agent for researching complex questions and executing multi-step tasks. Use this agent to execute multiple units of work in parallel.',
|
|
88
|
+
permission: Permission.merge(defaults, Permission.fromConfig({ todowrite: 'deny' }), user),
|
|
89
|
+
options: {},
|
|
90
|
+
mode: 'subagent',
|
|
91
|
+
native: true,
|
|
92
|
+
},
|
|
93
|
+
explore: {
|
|
94
|
+
name: 'explore',
|
|
95
|
+
permission: Permission.merge(
|
|
96
|
+
defaults,
|
|
97
|
+
Permission.fromConfig({
|
|
98
|
+
'*': 'deny',
|
|
99
|
+
grep: 'allow',
|
|
100
|
+
glob: 'allow',
|
|
101
|
+
list: 'allow',
|
|
102
|
+
bash: 'allow',
|
|
103
|
+
webfetch: 'allow',
|
|
104
|
+
websearch: 'allow',
|
|
105
|
+
read: 'allow',
|
|
106
|
+
external_directory: { '*': 'ask' },
|
|
107
|
+
}),
|
|
108
|
+
user
|
|
109
|
+
),
|
|
110
|
+
description:
|
|
111
|
+
'Fast agent specialized for exploring codebases. Use this when you need to quickly find files by patterns (eg. "src/components/**/*.tsx"), search code for keywords (eg. "API endpoints"), or answer questions about the codebase (eg. "how do API endpoints work?"). When calling this agent, specify the desired thoroughness level: "quick" for basic searches, "medium" for moderate exploration, or "very thorough" for comprehensive analysis across multiple locations and naming conventions.',
|
|
112
|
+
prompt: opts.promptExplore || '',
|
|
113
|
+
options: {},
|
|
114
|
+
mode: 'subagent',
|
|
115
|
+
native: true,
|
|
116
|
+
},
|
|
117
|
+
/* opencode custom-agent deseni (mode: 'all'): Beast Sandbox — GitHub'dan
|
|
118
|
+
indirilmiş açık kaynak repo klasöründe koşan build ajanı. Repo disiplini
|
|
119
|
+
+ panel_run (ÇALIŞTIR paneli) izni buradan gelir */
|
|
120
|
+
sandbox: {
|
|
121
|
+
name: 'sandbox',
|
|
122
|
+
description: 'Beast Sandbox agent. Works inside an open-source repo cloned from GitHub; follows the repo owner conventions.',
|
|
123
|
+
options: {},
|
|
124
|
+
permission: Permission.merge(
|
|
125
|
+
defaults,
|
|
126
|
+
Permission.fromConfig({
|
|
127
|
+
question: 'allow',
|
|
128
|
+
panel_run: { '*': 'allow' },
|
|
129
|
+
}),
|
|
130
|
+
user
|
|
131
|
+
),
|
|
132
|
+
prompt: [
|
|
133
|
+
'BEAST SANDBOX MODUNDASIN: GitHub\u2019dan indirilmi\u015f A\u00c7IK KAYNAK bir repo klas\u00f6r\u00fcndesin (Beast-Sandbox). Bu kodun sahibi de\u011filsin \u2014 hazir bir di\u015f proje; repo sahibinin konvansiyonlarina uy, gereksiz yeniden bi\u00e7imlendirme yapma.',
|
|
134
|
+
'\u0130\u015fe README + paket bildirim dosyalar\u0131yla ba\u015fla (list/glob); ba\u011f\u0131ml\u0131l\u0131klar kurulu de\u011filse \u00f6nce kurulum komutunu \u00e7al\u0131\u015ft\u0131r (npm install vb.).',
|
|
135
|
+
'UZUN S\u00dcREL\u0130 sunucu/s\u00fcre\u00e7 (npm start, npm run dev, python app.py vb.) bash ile ASLA ba\u015flatma \u2014 tur kilitlenir; kullan\u0131c\u0131 \u00e7al\u0131\u015ft\u0131rmak isterse panel_run arac\u0131yla \u00c7ALI\u015eTIR paneline b\u0131rak (\u00e7\u0131kt\u0131 orada canl\u0131 akar) ve adresi kullan\u0131c\u0131ya bildir. panel_run yaln\u0131z B\u0130R s\u00fcre\u00e7 \u00e7al\u0131\u015ft\u0131r\u0131r.',
|
|
136
|
+
].join('\n'),
|
|
137
|
+
mode: 'all',
|
|
138
|
+
native: false,
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/* opencode Agent.get(name) — bilinmeyen isim null döner (çağıran hata basar) */
|
|
144
|
+
function get(name, opts = {}) {
|
|
145
|
+
const agents = build(opts);
|
|
146
|
+
return agents[name] || null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/* opencode Agent.list() — alfabetik, build önce */
|
|
150
|
+
function list(opts = {}) {
|
|
151
|
+
const agents = Object.values(build(opts));
|
|
152
|
+
return agents.sort((a, b) => (a.name === 'build' ? -1 : b.name === 'build' ? 1 : a.name.localeCompare(b.name)));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/* opencode Agent.defaultInfo() — görünür primary ajan (build) */
|
|
156
|
+
function defaultInfo(opts = {}) {
|
|
157
|
+
const agents = Object.values(build(opts));
|
|
158
|
+
return agents.find((a) => a.mode !== 'subagent' && a.hidden !== true) || agents[0];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
module.exports = { get, list, defaultInfo, build, defaultRuleset, planRules };
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/* ---------- opencode permission Service portu (index.ts:67-167) ----------
|
|
4
|
+
Ask akışı: her pattern için kural değerlendirilir (ruleset + approved) →
|
|
5
|
+
deny → PermissionDeniedError (asla sorulmaz, anında hata)
|
|
6
|
+
allow → geç
|
|
7
|
+
ask → kullanıcıya sorulur
|
|
8
|
+
Sorulacaklar: 'permission.asked' eventi yayınlanır (UI/WA dinler) ve
|
|
9
|
+
promise bekletilir. Cevap (reply):
|
|
10
|
+
'once' → yalnız bu istek serbest
|
|
11
|
+
'always' → pattern'ler oturum boyu approved listesine kural olarak eklenir;
|
|
12
|
+
aynı oturumdaki diğer pending'lerden artık allow olanlar da serbest bırakılır
|
|
13
|
+
'reject' → RejectedError (feedback'siz) veya CorrectedError (feedback'li);
|
|
14
|
+
aynı oturumdaki DİĞER pending istekler de reddedilir (opencode birebir)
|
|
15
|
+
|
|
16
|
+
Hata nesneleri araç çıktısına JSON hata olarak akıtılır; opencode
|
|
17
|
+
core/v1/permission.ts mesajları kullanılır. */
|
|
18
|
+
|
|
19
|
+
const Permission = require('./permission');
|
|
20
|
+
|
|
21
|
+
let seq = 0;
|
|
22
|
+
function newId() {
|
|
23
|
+
return 'prm_' + Date.now().toString(36) + (++seq).toString(36);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
class AskService {
|
|
27
|
+
constructor(emitFn) {
|
|
28
|
+
this.emit = typeof emitFn === 'function' ? emitFn : () => {};
|
|
29
|
+
this.pending = new Map(); // id -> { info, resolve, reject }
|
|
30
|
+
this.approved = []; // oturumlar arası paylaşılan kural listesi (engine'e aşılanır)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/* opencode Permission.ask — throws: { kind:'denied'|'rejected'|'corrected', feedback? } */
|
|
34
|
+
ask({ sessionId, ruleset, permission, patterns, metadata, always, tool }) {
|
|
35
|
+
const pats = Array.isArray(patterns) && patterns.length ? patterns : ['*'];
|
|
36
|
+
let needsAsk = false;
|
|
37
|
+
for (const pattern of pats) {
|
|
38
|
+
const rule = Permission.evaluate(permission, pattern, ruleset || [], this.approved);
|
|
39
|
+
if (rule.action === 'deny') {
|
|
40
|
+
throw { kind: 'denied', permission, pattern };
|
|
41
|
+
}
|
|
42
|
+
if (rule.action === 'allow') continue;
|
|
43
|
+
needsAsk = true;
|
|
44
|
+
}
|
|
45
|
+
if (!needsAsk) return Promise.resolve();
|
|
46
|
+
|
|
47
|
+
const id = newId();
|
|
48
|
+
const info = {
|
|
49
|
+
id,
|
|
50
|
+
sessionID: String(sessionId || ''),
|
|
51
|
+
permission,
|
|
52
|
+
patterns: pats,
|
|
53
|
+
metadata: metadata || {},
|
|
54
|
+
always: Array.isArray(always) ? always : [],
|
|
55
|
+
tool: tool || null,
|
|
56
|
+
};
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
this.pending.set(id, { info, resolve, reject });
|
|
59
|
+
try {
|
|
60
|
+
this.emit({ type: 'permission.asked', sessionId: info.sessionID, request: info });
|
|
61
|
+
} catch {}
|
|
62
|
+
/* güvenlik: emit kanalı koptuysa pending asılı kalmasın */
|
|
63
|
+
setTimeout(() => {
|
|
64
|
+
if (this.pending.has(id)) {
|
|
65
|
+
this.pending.delete(id);
|
|
66
|
+
reject({ kind: 'rejected' });
|
|
67
|
+
}
|
|
68
|
+
}, 5 * 60 * 1000);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/* opencode Permission.reply — UI/WA tarafından çağrılır */
|
|
73
|
+
reply(requestId, action, message) {
|
|
74
|
+
const id = String(requestId || '');
|
|
75
|
+
const existing = this.pending.get(id);
|
|
76
|
+
if (!existing) return { ok: false, error: 'bekleyen izin isteği yok' };
|
|
77
|
+
this.pending.delete(id);
|
|
78
|
+
const { info } = existing;
|
|
79
|
+
try {
|
|
80
|
+
this.emit({ type: 'permission.replied', sessionId: info.sessionID, requestId: id, reply: action });
|
|
81
|
+
} catch {}
|
|
82
|
+
|
|
83
|
+
if (action === 'reject') {
|
|
84
|
+
const err = message ? { kind: 'corrected', feedback: String(message) } : { kind: 'rejected' };
|
|
85
|
+
existing.reject(err);
|
|
86
|
+
/* aynı oturumdaki diğer pending'ler de reddedilir (opencode birebir) */
|
|
87
|
+
for (const [pid, item] of [...this.pending.entries()]) {
|
|
88
|
+
if (item.info.sessionID !== info.sessionID) continue;
|
|
89
|
+
this.pending.delete(pid);
|
|
90
|
+
try {
|
|
91
|
+
this.emit({ type: 'permission.replied', sessionId: item.info.sessionID, requestId: pid, reply: 'reject' });
|
|
92
|
+
} catch {}
|
|
93
|
+
item.reject({ kind: 'rejected' });
|
|
94
|
+
}
|
|
95
|
+
return { ok: true };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
existing.resolve();
|
|
99
|
+
if (action === 'once') return { ok: true };
|
|
100
|
+
|
|
101
|
+
/* 'always' — pattern bazlı kural yazılır (opencode birebir) */
|
|
102
|
+
for (const pattern of info.always) {
|
|
103
|
+
this.approved.push({ permission: info.permission, pattern, action: 'allow' });
|
|
104
|
+
}
|
|
105
|
+
for (const [pid, item] of [...this.pending.entries()]) {
|
|
106
|
+
if (item.info.sessionID !== info.sessionID) continue;
|
|
107
|
+
const ok = item.info.patterns.every(
|
|
108
|
+
(pattern) => Permission.evaluate(item.info.permission, pattern, this.approved).action === 'allow'
|
|
109
|
+
);
|
|
110
|
+
if (!ok) continue;
|
|
111
|
+
this.pending.delete(pid);
|
|
112
|
+
try {
|
|
113
|
+
this.emit({ type: 'permission.replied', sessionId: item.info.sessionID, requestId: pid, reply: 'always' });
|
|
114
|
+
} catch {}
|
|
115
|
+
item.resolve();
|
|
116
|
+
}
|
|
117
|
+
return { ok: true };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* bekleyen istekler (UI listesi için) */
|
|
121
|
+
list() {
|
|
122
|
+
return [...this.pending.values()].map((x) => x.info);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* hata nesnesini araç çıktısı metnine çevirir (opencode mesajları) */
|
|
126
|
+
static errorText(err) {
|
|
127
|
+
if (!err) return 'Permission denied';
|
|
128
|
+
if (err.kind === 'denied') return 'Permission denied';
|
|
129
|
+
if (err.kind === 'corrected')
|
|
130
|
+
return 'The user rejected the permission request and gave feedback: ' + String(err.feedback || '');
|
|
131
|
+
return Permission.MESSAGES.rejected;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
module.exports = { AskService };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/* ---------- opencode mantığı — Beast Code portu (birleşim) ----------
|
|
4
|
+
opencode-dev/packages/opencode/src çekirdek mimarisinin CommonJS portu:
|
|
5
|
+
|
|
6
|
+
agents.js → agent/agent.ts (build/plan/general/explore + permission)
|
|
7
|
+
permission.js → permission/index.ts (ruleset, evaluate findLast, fromConfig)
|
|
8
|
+
askperm.js → permission Service (ask/reply: once|always|reject)
|
|
9
|
+
systemprompt.js → session/system.ts + reminders.ts
|
|
10
|
+
toolmap.js → tool/registry.ts builtin seti (read/edit/write/bash/...)
|
|
11
|
+
prompts/ → session/prompt/*.txt + tool/*.txt (opencode-dev'den birebir)
|
|
12
|
+
|
|
13
|
+
Kullanım (engine, bcCode oturumlarında):
|
|
14
|
+
opencode.agents.get(name, {worktree}) → Agent.Info
|
|
15
|
+
opencode.system.provider(modelId) → model-bazlı ana prompt
|
|
16
|
+
opencode.toolmap.definitions() → modele sunulacak opencode araç seti
|
|
17
|
+
opencode.toolmap.execMap(name, args) → Beast aracına çevirim
|
|
18
|
+
opencode.Permission → kural motoru
|
|
19
|
+
opencode.AskService → izin isteme/yanıtlama servisi */
|
|
20
|
+
|
|
21
|
+
const fs = require('fs');
|
|
22
|
+
const path = require('path');
|
|
23
|
+
|
|
24
|
+
const PROMPTS_DIR = path.join(__dirname, 'prompts');
|
|
25
|
+
function loadPrompt(name) {
|
|
26
|
+
try {
|
|
27
|
+
return fs.readFileSync(path.join(PROMPTS_DIR, name), 'utf8').replace(/\s+$/, '');
|
|
28
|
+
} catch {
|
|
29
|
+
return '';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const MAX_STEPS_PROMPT = loadPrompt('max-steps.txt');
|
|
34
|
+
const PROMPT_EXPLORE = loadPrompt('explore.txt');
|
|
35
|
+
|
|
36
|
+
const agents = require('./agents');
|
|
37
|
+
const Permission = require('./permission');
|
|
38
|
+
const { AskService } = require('./askperm');
|
|
39
|
+
const systemprompt = require('./systemprompt');
|
|
40
|
+
const toolmap = require('./toolmap');
|
|
41
|
+
|
|
42
|
+
module.exports = {
|
|
43
|
+
agents,
|
|
44
|
+
Permission,
|
|
45
|
+
AskService,
|
|
46
|
+
systemprompt,
|
|
47
|
+
toolmap,
|
|
48
|
+
MAX_STEPS_PROMPT,
|
|
49
|
+
PROMPT_EXPLORE,
|
|
50
|
+
loadPrompt,
|
|
51
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/* ---------- opencode permission/index.ts portu (birebir) ----------
|
|
4
|
+
Kural şeması: { permission, pattern, action: 'allow' | 'deny' | 'ask' }
|
|
5
|
+
Değerlendirme: kümeler düzleştirilir, SON eşleşen kural kazanır (findLast).
|
|
6
|
+
Eşleşme yoksa varsayılan { action: 'ask', pattern: '*' }.
|
|
7
|
+
|
|
8
|
+
fromConfig: { "*": "allow", read: { "*.env": "ask" }, bash: { "git push": "ask" } }
|
|
9
|
+
→ kural listesi (~/, $HOME genişletmesi dahil)
|
|
10
|
+
merge: kümeleri sırayla birleştirir (sonraki öncekini gölgeler)
|
|
11
|
+
disabled: ruleset'te pattern:'*' + deny olan ARAÇLARI bulur —
|
|
12
|
+
opencode'da edit/write/apply_patch aynı "edit" iznine takılır,
|
|
13
|
+
MCP resource araçları (list_mcp_resources vb.) "read" iznine. */
|
|
14
|
+
|
|
15
|
+
const os = require('os');
|
|
16
|
+
|
|
17
|
+
/* opencode core util/wildcard.ts portu — Windows'ta yolsayıç ayracı
|
|
18
|
+
normalize edilir, * → .*, ? → ., " <-> sondaki " .*" opsiyonel grup */
|
|
19
|
+
function wildcardMatch(input, pattern) {
|
|
20
|
+
const normalized = String(input).replaceAll('\\', '/');
|
|
21
|
+
let escaped = String(pattern)
|
|
22
|
+
.replaceAll('\\', '/')
|
|
23
|
+
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
|
|
24
|
+
.replace(/\*/g, '.*')
|
|
25
|
+
.replace(/\?/g, '.');
|
|
26
|
+
if (escaped.endsWith(' .*')) escaped = escaped.slice(0, -3) + '( .*)?';
|
|
27
|
+
return new RegExp('^' + escaped + '$', process.platform === 'win32' ? 'si' : 's').test(normalized);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* opencode permission.evaluate — findLast: SON eşleşen kural kazanır */
|
|
31
|
+
function evaluate(permission, pattern, ...rulesets) {
|
|
32
|
+
return (
|
|
33
|
+
rulesets
|
|
34
|
+
.flat()
|
|
35
|
+
.findLast((rule) => wildcardMatch(permission, rule.permission) && wildcardMatch(pattern, rule.pattern)) || {
|
|
36
|
+
action: 'ask',
|
|
37
|
+
permission,
|
|
38
|
+
pattern: '*',
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function expand(pattern) {
|
|
44
|
+
if (pattern.startsWith('~/')) return os.homedir() + pattern.slice(1);
|
|
45
|
+
if (pattern === '~') return os.homedir();
|
|
46
|
+
if (pattern.startsWith('$HOME/')) return os.homedir() + pattern.slice(5);
|
|
47
|
+
if (pattern.startsWith('$HOME')) return os.homedir() + pattern.slice(5);
|
|
48
|
+
return pattern;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* opencode permission.fromConfig — {"*":"allow"} veya {read:{"*.env":"ask"}} */
|
|
52
|
+
function fromConfig(permission) {
|
|
53
|
+
const ruleset = [];
|
|
54
|
+
if (!permission || typeof permission !== 'object') return ruleset;
|
|
55
|
+
for (const [key, value] of Object.entries(permission)) {
|
|
56
|
+
if (typeof value === 'string') {
|
|
57
|
+
ruleset.push({ permission: key, action: value, pattern: '*' });
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (value && typeof value === 'object') {
|
|
61
|
+
for (const [pattern, action] of Object.entries(value)) {
|
|
62
|
+
ruleset.push({ permission: key, pattern: expand(pattern), action: String(action) });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return ruleset;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* opencode permission.merge — kümeleri sırayla birleştirir */
|
|
70
|
+
function merge(...rulesets) {
|
|
71
|
+
return rulesets.flat();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* opencode permission.disabled — ruleset'te * pattern ile deny edilmiş araç adları.
|
|
75
|
+
edit/write/apply_patch "edit" iznine, MCP resource araçları "read" iznine indirgenir. */
|
|
76
|
+
function disabled(tools, ruleset) {
|
|
77
|
+
const edits = ['edit', 'write', 'apply_patch'];
|
|
78
|
+
const reads = ['list_mcp_resources', 'list_mcp_resource_templates', 'read_mcp_resource'];
|
|
79
|
+
return new Set(
|
|
80
|
+
(tools || []).filter((tool) => {
|
|
81
|
+
const permission = edits.includes(tool) ? 'edit' : reads.includes(tool) ? 'read' : tool;
|
|
82
|
+
const rule = (ruleset || []).findLast((r) => wildcardMatch(permission, r.permission));
|
|
83
|
+
return rule && rule.pattern === '*' && rule.action === 'deny';
|
|
84
|
+
})
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/* opencode permission.visibleTools — deny edilmişleri listeden düşürür */
|
|
89
|
+
function visibleTools(tools, ruleset) {
|
|
90
|
+
const hidden = disabled(Object.keys(tools || {}), ruleset);
|
|
91
|
+
return Object.fromEntries(Object.entries(tools || {}).filter(([name]) => !hidden.has(name)));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* opencode v1/permission.ts hata metinleri — modele geri beslenir */
|
|
95
|
+
const MESSAGES = {
|
|
96
|
+
rejected: 'The user rejected the permission request. Do not try this action again unless the user explicitly asks you to.',
|
|
97
|
+
denied: 'Permission denied',
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
module.exports = {
|
|
101
|
+
wildcardMatch,
|
|
102
|
+
evaluate,
|
|
103
|
+
fromConfig,
|
|
104
|
+
merge,
|
|
105
|
+
disabled,
|
|
106
|
+
visibleTools,
|
|
107
|
+
MESSAGES,
|
|
108
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
You are Beast Code, the best coding agent on the planet.
|
|
2
|
+
|
|
3
|
+
You are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.
|
|
4
|
+
|
|
5
|
+
IMPORTANT: You must NEVER generate or guess URLs for the user unless you are confident that the URLs are for helping the user with programming. You may use URLs provided by the user in their messages or local files.
|
|
6
|
+
|
|
7
|
+
If the user asks for help or wants to give feedback inform them of the following:
|
|
8
|
+
- ctrl+p to list available actions
|
|
9
|
+
- To give feedback, users should report the issue at
|
|
10
|
+
https://github.com/anomalyco/opencode
|
|
11
|
+
|
|
12
|
+
When the user directly asks about OpenCode (eg. "can OpenCode do...", "does OpenCode have..."), or asks in second person (eg. "are you able...", "can you do..."), or asks how to use a specific OpenCode feature (eg. implement a hook, write a slash command, or install an MCP server), use the WebFetch tool to gather information to answer the question from OpenCode docs. The list of available docs is available at https://opencode.ai/docs
|
|
13
|
+
|
|
14
|
+
# Tone and style
|
|
15
|
+
- Only use emojis if the user explicitly requests it. Avoid using emojis in all communication unless asked.
|
|
16
|
+
- Your output will be displayed on a command line interface. Your responses should be short and concise. You can use GitHub-flavored markdown for formatting, and will be rendered in a monospace font using the CommonMark specification.
|
|
17
|
+
- Output text to communicate with the user; all text you output outside of tool use is displayed to the user. Only use tools to complete tasks. Never use tools like Bash or code comments as means to communicate with the user during the session.
|
|
18
|
+
- NEVER create files unless they're absolutely necessary for achieving your goal. ALWAYS prefer editing an existing file to creating a new one. This includes markdown files.
|
|
19
|
+
|
|
20
|
+
# Professional objectivity
|
|
21
|
+
Prioritize technical accuracy and truthfulness over validating the user's beliefs. Focus on facts and problem-solving, providing direct, objective technical info without any unnecessary superlatives, praise, or emotional validation. It is best for the user if OpenCode honestly applies the same rigorous standards to all ideas and disagrees when necessary, even if it may not be what the user wants to hear. Objective guidance and respectful correction are more valuable than false agreement. Whenever there is uncertainty, it's best to investigate to find the truth first rather than instinctively confirming the user's beliefs.
|
|
22
|
+
|
|
23
|
+
# Task Management
|
|
24
|
+
You have access to the TodoWrite tools to help you manage and plan tasks. Use these tools VERY frequently to ensure that you are tracking your tasks and giving the user visibility into your progress.
|
|
25
|
+
These tools are also EXTREMELY helpful for planning tasks, and for breaking down larger complex tasks into smaller steps. If you do not use this tool when planning, you may forget to do important tasks - and that is unacceptable.
|
|
26
|
+
|
|
27
|
+
It is critical that you mark todos as completed as soon as you are done with a task. Do not batch up multiple tasks before marking them as completed.
|
|
28
|
+
|
|
29
|
+
Examples:
|
|
30
|
+
|
|
31
|
+
<example>
|
|
32
|
+
user: Run the build and fix any type errors
|
|
33
|
+
assistant: I'm going to use the TodoWrite tool to write the following items to the todo list:
|
|
34
|
+
- Run the build
|
|
35
|
+
- Fix any type errors
|
|
36
|
+
|
|
37
|
+
I'm now going to run the build using Bash.
|
|
38
|
+
|
|
39
|
+
Looks like I found 10 type errors. I'm going to use the TodoWrite tool to write 10 items to the todo list.
|
|
40
|
+
|
|
41
|
+
marking the first todo as in_progress
|
|
42
|
+
|
|
43
|
+
Let me start working on the first item...
|
|
44
|
+
|
|
45
|
+
The first item has been fixed, let me mark the first todo as completed, and move on to the second item...
|
|
46
|
+
..
|
|
47
|
+
..
|
|
48
|
+
</example>
|
|
49
|
+
In the above example, the assistant completes all the tasks, including the 10 error fixes and running the build and fixing all errors.
|
|
50
|
+
|
|
51
|
+
<example>
|
|
52
|
+
user: Help me write a new feature that allows users to track their usage metrics and export them to various formats
|
|
53
|
+
assistant: I'll help you implement a usage metrics tracking and export feature. Let me first use the TodoWrite tool to plan this task.
|
|
54
|
+
Adding the following todos to the todo list:
|
|
55
|
+
1. Research existing metrics tracking in the codebase
|
|
56
|
+
2. Design the metrics collection system
|
|
57
|
+
3. Implement core metrics tracking functionality
|
|
58
|
+
4. Create export functionality for different formats
|
|
59
|
+
|
|
60
|
+
Let me start by researching the existing codebase to understand what metrics we might already be tracking and how we can build on that.
|
|
61
|
+
|
|
62
|
+
I'm going to search for any existing metrics or telemetry code in the project.
|
|
63
|
+
|
|
64
|
+
I've found some existing telemetry code. Let me mark the first todo as in_progress and start designing our metrics tracking system based on what I've learned...
|
|
65
|
+
|
|
66
|
+
[Assistant continues implementing the feature step by step, marking todos as in_progress and completed as they go]
|
|
67
|
+
</example>
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# Doing tasks
|
|
71
|
+
The user will primarily request you perform software engineering tasks. This includes solving bugs, adding new functionality, refactoring code, explaining code, and more. For these tasks the following steps are recommended:
|
|
72
|
+
-
|
|
73
|
+
- Use the TodoWrite tool to plan the task if required
|
|
74
|
+
|
|
75
|
+
- Tool results and user messages may include <system-reminder> tags. <system-reminder> tags contain useful information and reminders. They are automatically added by the system, and bear no direct relation to the specific tool results or user messages in which they appear.
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# Tool usage policy
|
|
79
|
+
- When doing file search, prefer to use the Task tool in order to reduce context usage.
|
|
80
|
+
- You should proactively use the Task tool with specialized agents when the task at hand matches the agent's description.
|
|
81
|
+
|
|
82
|
+
- When WebFetch returns a message about a redirect to a different host, you should immediately make a new WebFetch request with the redirect URL provided in the response.
|
|
83
|
+
- You can call multiple tools in a single response. If you intend to call multiple tools and there are no dependencies between them, make all independent tool calls in parallel. Maximize use of parallel tool calls where possible to increase efficiency. However, if some tool calls depend on previous calls to inform dependent values, do NOT call these tools in parallel and instead call them sequentially. For instance, if one operation must complete before another starts, run these operations sequentially instead. Never use placeholders or guess missing parameters in tool calls.
|
|
84
|
+
- If the user specifies that they want you to run tools "in parallel", you MUST send a single message with multiple tool use content blocks. For example, if you need to launch multiple agents in parallel, send a single message with multiple Task tool calls.
|
|
85
|
+
- Use specialized tools instead of bash commands when possible, as this provides a better user experience. For file operations, use dedicated tools: Read for reading files instead of cat/head/tail, Edit for editing instead of sed/awk, and Write for creating files instead of cat with heredoc or echo redirection. Reserve bash tools exclusively for actual system commands and terminal operations that require shell execution. NEVER use bash echo or other command-line tools to communicate thoughts, explanations, or instructions to the user. Output all communication directly in your response text instead.
|
|
86
|
+
- VERY IMPORTANT: When exploring the codebase to gather context or to answer a question that is not a needle query for a specific file/class/function, it is CRITICAL that you use the Task tool instead of running search commands directly.
|
|
87
|
+
<example>
|
|
88
|
+
user: Where are errors from the client handled?
|
|
89
|
+
assistant: [Uses the Task tool to find the files that handle client errors instead of using Glob or Grep directly]
|
|
90
|
+
</example>
|
|
91
|
+
<example>
|
|
92
|
+
user: What is the codebase structure?
|
|
93
|
+
assistant: [Uses the Task tool]
|
|
94
|
+
</example>
|
|
95
|
+
|
|
96
|
+
IMPORTANT: Always use the TodoWrite tool to plan and track tasks throughout the conversation.
|
|
97
|
+
|
|
98
|
+
# Code References
|
|
99
|
+
|
|
100
|
+
When referencing specific functions or pieces of code include the pattern `file_path:line_number` to allow the user to easily navigate to the source code location.
|
|
101
|
+
|
|
102
|
+
<example>
|
|
103
|
+
user: Where are errors from the client handled?
|
|
104
|
+
assistant: Clients are marked as failed in the `connectToServer` function in src/services/process.ts:712.
|
|
105
|
+
</example>
|