From c85b59e06e8131887c33c92fdd779330c1261909 Mon Sep 17 00:00:00 2001 From: Liang Jiaqing Date: Sat, 20 Jun 2026 21:03:38 +0800 Subject: [PATCH] feat: generic extra_sys_prompts slot replaces hardcoded commit_signature module --- agentmain.py | 4 ++-- frontends/slash_cmds.py | 1 + frontends/tui_v3.py | 2 ++ frontends/tuiapp_v2.py | 2 ++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/agentmain.py b/agentmain.py index e4a7807f..08b78e09 100644 --- a/agentmain.py +++ b/agentmain.py @@ -60,6 +60,7 @@ class GenericAgent: logid = f'{(time.time_ns() + random.randrange(1_000_000)) % 1_000_000:06d}' self.log_path = os.path.join(script_dir, f'temp/model_responses/model_responses_{logid}.txt') self.load_llm_sessions() + self.extra_sys_prompts = [] def load_llm_sessions(self): mykeys, changed = reload_mykeys() @@ -146,8 +147,7 @@ class GenericAgent: raw_query = f'Long user prompt saved to {task_file}. Read and execute.' rquery = smart_format(raw_query.replace('\n', ' '), max_str_len=200) self.history.append(f"[USER]: {rquery}") - - sys_prompt = get_system_prompt() + getattr(self.llmclient.backend, 'extra_sys_prompt', '') + sys_prompt = get_system_prompt() + '\n'.join(self.extra_sys_prompts) + getattr(self.llmclient.backend, 'extra_sys_prompt', '') if self.peer_hint: sys_prompt += f"\n[Peer] 用户提及其他会话/后台任务状态时: temp/model_responses/ (只找近期修改的文件尾部)\n" handler = GenericAgentHandler(self, self.history, os.path.join(script_dir, 'temp')) if getattr(self, 'no_print', False): handler.print = lambda *a, **k: None diff --git a/frontends/slash_cmds.py b/frontends/slash_cmds.py index 9566477f..6c3c0a66 100644 --- a/frontends/slash_cmds.py +++ b/frontends/slash_cmds.py @@ -33,6 +33,7 @@ from typing import Optional _USER_SHELL: tuple[list[str], str] | None = None +COMMIT_SIGNATURE_PROMPT = 'When you create a git commit, append "Co-Authored-By: GenericAgent " as the final line of the commit message.' def detect_user_shell() -> tuple[list[str], str]: """Return `([executable, ...flags_for_-c], display_name)` for the user's diff --git a/frontends/tui_v3.py b/frontends/tui_v3.py index 3388c749..0684d538 100644 --- a/frontends/tui_v3.py +++ b/frontends/tui_v3.py @@ -1373,6 +1373,8 @@ class AgentBridge: self.agent.llmclient = self.agent.llmclients[llm_no % len(self.agent.llmclients)] self.agent.inc_out = True self.agent.verbose = True + from frontends.slash_cmds import COMMIT_SIGNATURE_PROMPT + self.agent.extra_sys_prompts.append(COMMIT_SIGNATURE_PROMPT) # 默认普通模式:设 None 让 project_mode 插件不读 pid 文件锚(与 v2 一致)。 # /workspace 绑定时改为项目名 + 真实路径。 self.agent._ga_project_mode_name = None diff --git a/frontends/tuiapp_v2.py b/frontends/tuiapp_v2.py index 3c77a93c..c8694c5d 100644 --- a/frontends/tuiapp_v2.py +++ b/frontends/tuiapp_v2.py @@ -2043,8 +2043,10 @@ class AgentSession: def default_agent_factory() -> Any: from agentmain import GenericAgent + from frontends.slash_cmds import COMMIT_SIGNATURE_PROMPT agent = GenericAgent() agent.inc_out = True + agent.extra_sys_prompts.append(COMMIT_SIGNATURE_PROMPT) return agent