Эх сурвалжийг харах

Relax agent file operation rules

Alvin Unreal 2 сар өмнө
parent
commit
7bc7b41fb2

+ 2 - 5
src/agents/council.ts

@@ -1,3 +1,4 @@
+import { READONLY_FILE_OPERATIONS_RULES } from '../config';
 import { shortModelLabel } from '../utils/session';
 import { type AgentDefinition, resolvePrompt } from './orchestrator';
 
@@ -41,11 +42,7 @@ key insight and unique contribution by name
 - Be transparent about trade-offs when different approaches have valid pros/cons
 - Don't just average responses — choose the best approach and improve upon it
 
-**File Operations Rules**:
-- Use dedicated tools for file I/O if local files must be inspected
-- Search files/code with glob, grep, or ast_grep_search
-- Read files with read. Never use cat, head, tail, sed, awk, or bash commands to read file contents
-- Use bash only for execution/diagnostics, never for file I/O
+${READONLY_FILE_OPERATIONS_RULES}
 
 **Required Output Format**:
 Always include these sections in your final response:

+ 2 - 5
src/agents/councillor.ts

@@ -1,3 +1,4 @@
+import { NO_SHELL_READONLY_FILE_OPERATIONS_RULES } from '../config';
 import { type AgentDefinition, resolvePrompt } from './orchestrator';
 
 /**
@@ -30,11 +31,7 @@ problem.
 You CANNOT edit files, write files, run shell commands, or delegate to \
 other agents. You are an advisor, not an implementer.
 
-**File Operations Rules**:
-- READ-ONLY: do not modify files
-- Search files/code with glob, grep, or ast_grep_search
-- Read files with read. Never use cat, head, tail, sed, awk, or bash commands to read file contents
-- Do not use bash or shell commands
+${NO_SHELL_READONLY_FILE_OPERATIONS_RULES}
 
 **Behavior**:
 - **Examine the codebase** before answering — your read access is what makes \

+ 2 - 6
src/agents/designer.ts

@@ -1,3 +1,4 @@
+import { WRITABLE_FILE_OPERATIONS_RULES } from '../config';
 import type { AgentDefinition } from './orchestrator';
 
 const DESIGNER_PROMPT = `You are a Designer - a frontend UI/UX specialist who creates and reviews intentional, polished experiences.
@@ -49,12 +50,7 @@ const DESIGNER_PROMPT = `You are a Designer - a frontend UI/UX specialist who cr
 - Prioritize visual excellence—code perfection comes second
 - Use grounded, normal, regular english - don't use jargon or overly technical language
 
-## File Operations Rules
-- Always use dedicated file tools for file I/O
-- Search files/code with glob, grep, or ast_grep_search
-- Read files with read. Never use cat, head, tail, sed, awk, or bash commands to read file contents
-- Edit/write files with write, edit, or apply_patch. Never use shell redirection, echo, printf, or heredocs for file content unless no file tool can do the job
-- Use bash only for execution: git, package managers, tests, builds, scripts, or diagnostics
+${WRITABLE_FILE_OPERATIONS_RULES}
 
 ## Review Responsibilities
 - Review existing UI for usability, responsiveness, visual consistency, and polish when asked

+ 2 - 5
src/agents/explorer.ts

@@ -1,3 +1,4 @@
+import { READONLY_FILE_OPERATIONS_RULES } from '../config';
 import type { AgentDefinition } from './orchestrator';
 
 const EXPLORER_PROMPT = `You are Explorer - a fast codebase navigation specialist.
@@ -9,11 +10,7 @@ const EXPLORER_PROMPT = `You are Explorer - a fast codebase navigation specialis
 - **Structural patterns** (function shapes, class structures): ast_grep_search
 - **File discovery** (find by name/extension): glob
 
-**File Operations Rules**:
-- READ-ONLY: Search and report, don't modify files
-- Search files/code with glob, grep, or ast_grep_search
-- Read files with read. Never use cat, head, tail, sed, awk, or bash commands to read file contents
-- Use bash only for execution/diagnostics, never for file I/O
+${READONLY_FILE_OPERATIONS_RULES}
 
 **Behavior**:
 - Be fast and thorough

+ 2 - 6
src/agents/fixer.ts

@@ -1,3 +1,4 @@
+import { WRITABLE_FILE_OPERATIONS_RULES } from '../config';
 import type { AgentDefinition } from './orchestrator';
 
 const FIXER_PROMPT = `You are Fixer - a fast, focused implementation specialist.
@@ -13,12 +14,7 @@ const FIXER_PROMPT = `You are Fixer - a fast, focused implementation specialist.
 - Run relevant validation when requested or clearly applicable (otherwise note as skipped with reason)
 - Report completion with summary of changes
 
-**File Operations Rules**:
-- Always use dedicated file tools for file I/O
-- Search files/code with glob, grep, or ast_grep_search
-- Read files with read. Never use cat, head, tail, sed, awk, or bash commands to read file contents
-- Edit/write files with write, edit, or apply_patch. Never use shell redirection, echo, printf, or heredocs for file content unless no file tool can do the job
-- Use bash only for execution: git, package managers, tests, builds, scripts, or diagnostics
+${WRITABLE_FILE_OPERATIONS_RULES}
 
 **Constraints**:
 - NO external research (no websearch, context7, grep_app)

+ 2 - 5
src/agents/librarian.ts

@@ -1,3 +1,4 @@
+import { READONLY_FILE_OPERATIONS_RULES } from '../config';
 import type { AgentDefinition } from './orchestrator';
 
 const LIBRARIAN_PROMPT = `You are Librarian - a research specialist for codebases and documentation.
@@ -15,11 +16,7 @@ const LIBRARIAN_PROMPT = `You are Librarian - a research specialist for codebase
 - grep_app: Search GitHub repositories
 - websearch: General web search for docs
 
-**File Operations Rules**:
-- Use dedicated tools for file I/O when local files must be inspected
-- Search files/code with glob, grep, or ast_grep_search
-- Read files with read. Never use cat, head, tail, sed, awk, or bash commands to read file contents
-- Use bash only for execution/diagnostics, never for file I/O
+${READONLY_FILE_OPERATIONS_RULES}
 
 **Behavior**:
 - Provide evidence-based answers with sources

+ 2 - 4
src/agents/observer.ts

@@ -1,3 +1,4 @@
+import { READONLY_FILE_OPERATIONS_RULES } from '../config';
 import type { AgentDefinition } from './orchestrator';
 
 const OBSERVER_PROMPT = `You are Observer — a visual analysis specialist.
@@ -18,10 +19,7 @@ const OBSERVER_PROMPT = `You are Observer — a visual analysis specialist.
 - Match the language of the request
 - If info not found, state clearly what's missing
 
-**File Operations Rules**:
-- READ-ONLY: do not modify files
-- Read files with read. Never use cat, head, tail, sed, awk, or bash commands to read file contents
-- Use bash only for execution/diagnostics, never for file I/O
+${READONLY_FILE_OPERATIONS_RULES}
 `;
 
 export function createObserverAgent(

+ 2 - 5
src/agents/oracle.ts

@@ -1,3 +1,4 @@
+import { READONLY_FILE_OPERATIONS_RULES } from '../config';
 import type { AgentDefinition } from './orchestrator';
 
 const ORACLE_PROMPT = `You are Oracle - a strategic technical advisor and code reviewer.
@@ -23,11 +24,7 @@ const ORACLE_PROMPT = `You are Oracle - a strategic technical advisor and code r
 - Focus on strategy, not execution
 - Point to specific files/lines when relevant
 
-**File Operations Rules**:
-- READ-ONLY: do not modify files
-- Search files/code with glob, grep, or ast_grep_search
-- Read files with read. Never use cat, head, tail, sed, awk, or bash commands to read file contents
-- Use bash only for execution/diagnostics, never for file I/O
+${READONLY_FILE_OPERATIONS_RULES}
 `;
 
 export function createOracleAgent(

+ 2 - 6
src/agents/orchestrator.ts

@@ -1,4 +1,5 @@
 import type { AgentConfig } from '@opencode-ai/sdk/v2';
+import { WRITABLE_FILE_OPERATIONS_RULES } from '../config';
 
 export interface AgentDefinition {
   name: string;
@@ -177,12 +178,7 @@ Review available agents and lane rules.
 - Do not immediately wait after spawning independent background tasks unless the next step truly depends on their result
 - Reconcile results, resolve conflicts, and gate dependent lanes
 
-**File operations rules:**
-- Always use dedicated file tools for file I/O.
-- Search files/code with \`glob\`, \`grep\`, or \`ast_grep_search\`.
-- Read files with \`read\`. Never use \`cat\`, \`head\`, \`tail\`, \`sed\`, \`awk\`, or bash commands to read file contents.
-- Edit files with \`apply_patch\`. Never use shell redirection, \`echo\`, \`printf\`, or heredocs for file content unless no file tool can do the job.
-- Use \`bash\` only for execution: git, package managers, tests, builds, scripts, or diagnostics.
+${WRITABLE_FILE_OPERATIONS_RULES}
 
 ## 4. Plan and Parallelize
 Build a short work graph before dispatching:

+ 18 - 0
src/config/constants.ts

@@ -95,6 +95,24 @@ export const DEFAULT_MAX_SUBAGENT_DEPTH = 3;
 // Workflow reminders
 export const PHASE_REMINDER_TEXT = `!IMPORTANT! Scheduler workflow: plan lanes/dependencies → dispatch background specialists → track task IDs → wait for hook-driven completion or use task_status only when needed → reconcile terminal results → verify. Do not consume running-job output or advance dependent work. !END!`;
 
+export const WRITABLE_FILE_OPERATIONS_RULES = `**File Operations Rules**:
+- Prefer dedicated file tools for normal code work: glob/grep/ast_grep_search for discovery, read for file contents, and edit/write/apply_patch for targeted source changes.
+- Use bash for execution and automation: git, package managers, tests, builds, scripts, diagnostics, and shell-native filesystem operations.
+- Shell is acceptable for bulk or mechanical filesystem changes when it is clearer or safer than many individual edits (for example: truncate generated logs, remove build artifacts, batch rename/move files), especially when the user explicitly asks for that shell operation.
+- Before destructive or broad shell operations, verify the target set and quote paths. Prefer a dry-run/listing first when practical.
+- Do not use cat/head/tail/sed/awk only to read code into context; use read/grep unless a shell pipeline is genuinely the better diagnostic.`;
+
+export const READONLY_FILE_OPERATIONS_RULES = `**File Operations Rules**:
+- READ-ONLY: inspect and report; do not modify files.
+- Prefer dedicated file tools for codebase inspection: glob/grep/ast_grep_search for discovery and read for file contents.
+- Bash is allowed for non-mutating diagnostics and shell-native inspection when it is the clearest tool, but not for modifying files.
+- Do not use cat/head/tail/sed/awk only to read code into context; use read/grep unless a shell pipeline is genuinely the better diagnostic.`;
+
+export const NO_SHELL_READONLY_FILE_OPERATIONS_RULES = `**File Operations Rules**:
+- READ-ONLY: inspect and report; do not modify files.
+- Use glob/grep/ast_grep_search for discovery and read for file contents.
+- Do not use bash or shell commands.`;
+
 // Tmux pane spawn delay (ms) — gives TmuxSessionManager time to create pane
 export const TMUX_SPAWN_DELAY_MS = 500;