feat(system): lazy-load system prompt when opening the System panel - #475
Open
lyhue1991 wants to merge 2 commits into
Open
feat(system): lazy-load system prompt when opening the System panel#475lyhue1991 wants to merge 2 commits into
lyhue1991 wants to merge 2 commits into
Conversation
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.
There was a problem hiding this comment.
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
loadSystemPromptcallback inuseAgentSessionthat runs a non-promptget_statecommand, and expose it viaonSystemPromptLoaderChange. - Update
AppShellto trigger the loader when opening the System panel, including asystemPromptLoadingUI 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 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
Contributor
Author
System.mp4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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.load与system.loading。Test plan
node --test hooks/useAgentSession.test.mjs通过新增的 system-prompt loader 断言。🤖 Generated with Codex.