fix(mcp): explain a missing login password in vm_unlock

vm_unlock returned the host's raw "secret setting is empty" when a VM had no
saved password, which reads like an internal fault and hides what the user has
to do. Wrap the typeSecret failure with the step that failed and keep the
host's readable explanation, and say in the tool description that the VM (or
an MCP clone's source VM) must have a saved login password.

model: deepseek/deepseek-v4.1-flash
agent: lead (DeepSeek Harness)
This commit is contained in:
千川白浪 committed 2026-12-04 06:16:46 -07:00
1 parent 6b6a7ff81b
commit 23d0271c93
2 files changed
+31 -2

No files matched your search

+2 -2
View File
@@ -641,7 +641,7 @@ func (s *Server) vmUnlock(ctx context.Context, raw json.RawMessage) (any, error)
var typed hostReply
if err := s.host.Call(ctx, "host/console.typeSecret", map[string]any{"vm": args.VM, "setting": "login_password"}, &typed); err != nil {
return nil, err
return nil, fmt.Errorf("cannot enter the login password: %w", err)
}
var key hostReply
if err := s.host.Call(ctx, "host/console.key", map[string]any{"vm": args.VM, "key": "ret"}, &key); err != nil {
@@ -1059,7 +1059,7 @@ var toolCatalog = []map[string]any{
{"name": "session_dispose", "description": "Dispose an MCP-owned temporary VM session.", "inputSchema": objectSchema(map[string]any{"session_id": map[string]any{"type": "string"}}, []string{"session_id"})},
{"name": "vm_suspend", "description": "Save a running VM state and stop its process.", "inputSchema": objectSchema(map[string]any{"vm": map[string]any{"type": "string", "description": "VM reference."}}, []string{"vm"})},
{"name": "vm_resume", "description": "Restore a suspended VM from its saved state.", "inputSchema": objectSchema(map[string]any{"vm": map[string]any{"type": "string", "description": "VM reference."}}, []string{"vm"})},
{"name": "vm_unlock", "description": "Enter the host-stored macOS login password, wait for the desktop to settle (skipping transitional blank frames), and return the screen.", "inputSchema": objectSchema(map[string]any{
{"name": "vm_unlock", "description": "Type the macOS login password saved in the Reims-Go MCP Service settings into the VM's login screen, wait for the desktop to settle (skipping transitional blank frames), and return the screen. Requires the VM, or the source VM of an MCP clone, to have a saved login password.", "inputSchema": objectSchema(map[string]any{
"vm": map[string]any{"type": "string", "description": "VM reference."},
"timeout_ms": map[string]any{"type": "integer", "minimum": 1, "maximum": 60000, "description": "Max milliseconds to wait for the unlocked screen to settle (default 20000)."},
"stable_ms": map[string]any{"type": "integer", "minimum": 0, "maximum": 30000, "description": "Stability window in milliseconds after leaving the login screen (default 1500)."},
+29
View File
@@ -28,6 +28,7 @@ type testHost struct {
frames []string
frameIndex int
secretValue string
secretErr error
vmPhase string
deleteErr error
}
@@ -93,6 +94,9 @@ func (h *testHost) Call(_ context.Context, method string, params any, out any) e
return nil
}
if strings.HasSuffix(method, "typeSecret") {
if h.secretErr != nil {
return h.secretErr
}
*out.(*hostReply) = hostReply{Characters: 19}
return nil
}
@@ -248,6 +252,31 @@ func TestVMUnlockNeverReturnsThePassword(t *testing.T) {
}
}
func TestVMUnlockExplainsMissingPassword(t *testing.T) {
const hostMessage = "secret_missing: 该虚拟机未保存登录密码,无法自动输入。"
host := &testHost{secretErr: errors.New(hostMessage)}
server := New()
server.BindHost(host)
response := sendRequest(t, server, `{"jsonrpc":"2.0","id":6,"method":"tools/call","params":{"name":"vm_unlock","arguments":{"vm":"macos1"}}}`)
result := parseResponse(t, response)["result"].(map[string]any)
if isErr, _ := result["isError"].(bool); !isErr {
t.Fatalf("vm_unlock should report a tool error, got %s", response)
}
text := result["content"].([]any)[0].(map[string]any)["text"].(string)
if !strings.Contains(text, "cannot enter the login password") {
t.Fatalf("vm_unlock did not explain the failure step: %q", text)
}
if !strings.Contains(text, hostMessage) {
t.Fatalf("vm_unlock dropped the host explanation: %q", text)
}
if strings.Contains(text, "Login password entered") {
t.Fatalf("vm_unlock claimed success after a failed secret entry: %q", text)
}
if host.frameIndex != 0 || len(host.frames) != 0 {
t.Fatalf("vm_unlock must not press Return or screenshot after the secret fails")
}
}
func TestWaitForScreenRecognizesChangedFrame(t *testing.T) {
first := base64JPEG(t, color.RGBA{B: 200, A: 255})
second := base64JPEG(t, color.RGBA{R: 200, A: 255})