Skip to content

feat(system): lazy-load system prompt when opening the System panel - #475

Open
lyhue1991 wants to merge 2 commits into
agegr:mainfrom
lyhue1991:codex/system-prompt-lazy-load
Open

feat(system): lazy-load system prompt when opening the System panel#475
lyhue1991 wants to merge 2 commits into
agegr:mainfrom
lyhue1991:codex/system-prompt-lazy-load

Conversation

@lyhue1991

Copy link
Copy Markdown
Contributor

Summary

  • 点击 System 按钮打开面板时,惰性初始化休眠会话(通过非 prompt 的 get_state 命令)并立即拉取真实 System Prompt,无需先发送消息。
  • 新增 systemPromptLoading 加载态与 i18n 文案(en / zh-CN)。
  • 新增对应单元测试(hooks/useAgentSession.test.mjs)。

改动文件

  • hooks/useAgentSession.ts:新增 loadSystemPrompt 回调 + onSystemPromptLoaderChange 透传。
  • components/AppShell.tsx:新增 loading 态、handleSystemPromptToggle,System 按钮 onClick 改走该 handler。
  • components/ChatWindow.tsx:透传 onSystemPromptLoaderChange
  • lib/i18n/messages/en.ts / zh-CN.ts:更新/新增 system.loadsystem.loading

Test plan

  • node --test hooks/useAgentSession.test.mjs 通过新增的 system-prompt loader 断言。

🤖 Generated with Codex.

Open the System panel now initializes a dormant session (via a non-prompt
get_state command) to fetch and display the system prompt, instead of
requiring a message to be sent first. Adds a loading state and i18n strings.
Copilot AI lite review requested due to automatic review settings August 11, 2026 15:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the chat shell to lazily initialize a dormant AgentSession and fetch the current system prompt when the user opens the System top panel, avoiding the need to send a message first. This is implemented by wiring a “system prompt loader” callback from useAgentSession up to AppShell, plus adding UI loading state and i18n strings, and introducing a unit test to pin the behavior.

Changes:

  • Add a loadSystemPrompt callback in useAgentSession that runs a non-prompt get_state command, and expose it via onSystemPromptLoaderChange.
  • Update AppShell to trigger the loader when opening the System panel, including a systemPromptLoading UI state.
  • Add/adjust i18n strings and a unit test that asserts the new loader behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
hooks/useAgentSession.ts Adds a system-prompt loader callback and exposes it to the shell via onSystemPromptLoaderChange.
hooks/useAgentSession.test.mjs Adds a unit test that asserts System-panel opening uses get_state (not prompt) and registers a loader effect.
components/ChatWindow.tsx Plumbs the new loader callback prop from AppShell into useAgentSession.
components/AppShell.tsx Triggers lazy system-prompt loading when opening the System panel and renders a loading message.
lib/i18n/messages/en.ts Updates System panel empty/loading copy (English).
lib/i18n/messages/zh-CN.ts Updates System panel empty/loading copy (Simplified Chinese).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread hooks/useAgentSession.ts
Comment on lines +634 to +639
// A fresh session is persisted by the SDK as soon as it is created. Publish
// it to the shell now so the visible session and its runtime cannot diverge.
promoteNewSession();
const state = await sendAgentCommand<AgentStateResponse>(sid, { type: "get_state" });
if (!sessionHookMountedRef.current || sessionIdRef.current !== sid) return;
setSystemPrompt(state.systemPrompt ?? "");
Comment on lines +83 to +88
assert.match(loadSystemPromptSource, /sessionIdRef\.current \?\? await ensureNewSession\(\)/);
assert.match(loadSystemPromptSource, /promoteNewSession\(\)/);
assert.match(loadSystemPromptSource, /sendAgentCommand<AgentStateResponse>\(sid, \{ type: "get_state" \}\)/);
assert.doesNotMatch(loadSystemPromptSource, /type: "prompt"/);
assert.match(loadSystemPromptSource, /setSystemPrompt\(state\.systemPrompt \?\? ""\)/);
assert.match(loaderEffectSource, /onSystemPromptLoaderChange\?\.\(loadSystemPrompt\)/);
# Conflicts:
#	components/ChatWindow.tsx
#	hooks/useAgentSession.ts
@lyhue1991

Copy link
Copy Markdown
Contributor Author
System.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants