Skip to content

Commit edcdf7f

Browse files
committed
fix: compact lcm describe details
1 parent b6568da commit edcdf7f

3 files changed

Lines changed: 46 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@martian-engineering/lossless-claw": patch
3+
---
4+
5+
Keep lcm_describe tool result details compact so OpenClaw post-processing middleware accepts large summary descriptions.

src/tools/lcm-describe-tool.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,32 @@ function normalizeRequestedTokenCap(value: unknown): number | undefined {
5555
return Math.max(1, Math.trunc(value));
5656
}
5757

58+
function compactDescribeDetails(result: Awaited<ReturnType<LcmContextEngine["getRetrieval"]>["describe"]>) {
59+
if (!result) {
60+
return result;
61+
}
62+
if (result.type === "summary" && result.summary) {
63+
const { content: _content, subtree: _subtree, ...summary } = result.summary;
64+
return {
65+
id: result.id,
66+
type: result.type,
67+
summary,
68+
};
69+
}
70+
if (result.type === "file" && result.file) {
71+
const { explorationSummary: _explorationSummary, storageUri: _storageUri, ...file } = result.file;
72+
return {
73+
id: result.id,
74+
type: result.type,
75+
file: {
76+
...file,
77+
hasExplorationSummary: Boolean(result.file.explorationSummary),
78+
},
79+
};
80+
}
81+
return { id: result.id, type: result.type };
82+
}
83+
5884
export function createLcmDescribeTool(input: {
5985
deps: LcmDependencies;
6086
lcm?: LcmContextEngine;
@@ -203,7 +229,7 @@ export function createLcmDescribeTool(input: {
203229
return {
204230
content: [{ type: "text", text: lines.join("\n") }],
205231
details: {
206-
...result,
232+
...compactDescribeDetails(result),
207233
manifest: {
208234
tokenCap: resolvedTokenCap,
209235
budgetSource:
@@ -242,7 +268,7 @@ export function createLcmDescribeTool(input: {
242268

243269
return {
244270
content: [{ type: "text", text: lines.join("\n") }],
245-
details: result,
271+
details: compactDescribeDetails(result),
246272
};
247273
}
248274

test/lcm-tools.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,5 +409,18 @@ describe("LCM tools session scoping", () => {
409409
expect((cross.content[0] as { text: string }).text).toContain(
410410
formatTimestamp(new Date("2026-01-01T00:00:00.000Z"), timezone),
411411
);
412+
expect(cross.details).toMatchObject({
413+
id: "sum_foreign",
414+
type: "summary",
415+
summary: {
416+
conversationId: 99,
417+
tokenCount: 12,
418+
},
419+
manifest: {
420+
tokenCap: 120,
421+
},
422+
});
423+
expect(JSON.stringify(cross.details)).not.toContain("foreign summary");
424+
expect(JSON.stringify(cross.details)).not.toContain("subtree");
412425
});
413426
});

0 commit comments

Comments
 (0)