Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(computer): keep elements when the Markdown tree is empty

Dash4dd31ac1c256
diff --git a/packages/lizi-mcps/src/computer/server.ts b/packages/lizi-mcps/src/computer/server.ts
index cf59553c17..1e8c8a5035 100644
--- a/packages/lizi-mcps/src/computer/server.ts
+++ b/packages/lizi-mcps/src/computer/server.ts
@@ -1586,7 +1586,9 @@ export function createComputerMcpServer(
*/
function withoutDuplicateElements(name: string, data: unknown): unknown {
if (name !== 'get_window_state' || !data || typeof data !== 'object' || Array.isArray(data)) return data;
- if (typeof (data as { tree_markdown?: unknown }).tree_markdown !== 'string') return data;
+ // A degraded read can carry elements with an empty tree; they are then the only targets.
+ const markdown = (data as { tree_markdown?: unknown }).tree_markdown;
+ if (typeof markdown !== 'string' || markdown.trim().length === 0) return data;
if (!('elements' in data)) return data;
const { elements: _elements, ...rest } = data as Record<string, unknown>;
return rest;
diff --git a/packages/lizi-mcps/src/computer/snapshotGuard.test.ts b/packages/lizi-mcps/src/computer/snapshotGuard.test.ts
index c65394b957..381820e58b 100644
--- a/packages/lizi-mcps/src/computer/snapshotGuard.test.ts
+++ b/packages/lizi-mcps/src/computer/snapshotGuard.test.ts
@@ -435,6 +435,19 @@ describe('computer snapshot guard', () => {
await h.cleanup();
});
+ it('keeps elements when the Markdown tree is empty so the model still has targets', async () => {
+ const callTool = vi.fn(async (name: string) =>
+ name === 'get_window_state'
+ ? { ok: true, snapshot_id: 's0000002d', tree_markdown: '', elements: [{ element_index: 0, element_token: 's0000002d:0' }] }
+ : { ok: true });
+ const h = await makeHarness({ getStatus: vi.fn(), callTool }, { sessionId: 'sess-1' });
+
+ const observed = await h.call('get_window_state', { pid: 100, window_id: 1 });
+ expect(observed.ok).toBe(true);
+ expect(observed.data).toMatchObject({ elements: [{ element_token: 's0000002d:0' }] });
+ await h.cleanup();
+ });
+
it('accepts a driver data.snapshot_id as a snapshot_id alias', async () => {
const callTool = vi.fn(async (name: string) => {
if (name === 'get_window_state') {
@@ -736,7 +749,8 @@ describe('computer snapshot guard', () => {
expect(Boolean(observed.snapshot_id)).toBe(ok);
// The model reads Markdown rows; the structured duplicate stays host-side.
const { elements: _elements, ...markdownOnly } = state as Record<string, unknown>;
- expect(observed.data).toEqual(ok && "tree_markdown" in state ? markdownOnly : state);
+ const hasMarkdown = "tree_markdown" in state && typeof state.tree_markdown === "string" && state.tree_markdown.trim() !== "";
+ expect(observed.data).toEqual(ok && hasMarkdown ? markdownOnly : state);
// A failed AX observation may discover windows once, but never replays
// the observation, switches the target, or restarts the driver.
const rediscovered =