Skip to content

Commit d434b3d

Browse files
authored
refactor(agents): reuse Workshop text result envelopes (#133453)
1 parent a420656 commit d434b3d

4 files changed

Lines changed: 51 additions & 71 deletions

File tree

‎src/agents/tools/skill-workshop-tool-collection.ts‎

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { listSkillCollectionReviewOutcomes } from "../../skills/workshop/collect
1919
import { readSkillProposalTargetTreeSha256 } from "../../skills/workshop/proposal-bundle.js";
2020
import { stringEnum } from "../schema/typebox.js";
2121
import { readToolStringParam, ToolInputError } from "./common.js";
22+
import { textResult } from "./tool-results.js";
2223

2324
const SKILL_COLLECTION_HISTORY_REASON_MAX_CHARS = 300;
2425
const SKILL_COLLECTION_HISTORY_NAME_LIMIT = 10;
@@ -122,31 +123,21 @@ export async function executeSkillCollectionReconcile(params: {
122123
params.context.reconciling = false;
123124
}
124125
}
125-
return {
126-
content: [
127-
{
128-
type: "text" as const,
129-
text: `Reconciled the skill collection: kept ${result.kept.length}, wrote ${result.written.length}, dropped ${result.dropped.length}. Backup ${result.backupId}.`,
130-
},
131-
],
132-
details: result,
133-
};
126+
return textResult(
127+
`Reconciled the skill collection: kept ${result.kept.length}, wrote ${result.written.length}, dropped ${result.dropped.length}. Backup ${result.backupId}.`,
128+
result,
129+
);
134130
}
135131

136132
export async function executeSkillCollectionRestore(params: {
137133
workspaceDir: string;
138134
env?: NodeJS.ProcessEnv;
139135
}) {
140136
const result = await restoreLatestSkillCollectionBackup(params);
141-
return {
142-
content: [
143-
{
144-
type: "text" as const,
145-
text: `Restored skill collection backup ${result.backupId}: restored ${result.restored.length}, removed ${result.removed.length}.`,
146-
},
147-
],
148-
details: result,
149-
};
137+
return textResult(
138+
`Restored skill collection backup ${result.backupId}: restored ${result.restored.length}, removed ${result.removed.length}.`,
139+
result,
140+
);
150141
}
151142

152143
export function executeSkillCollectionHistory(
@@ -189,15 +180,10 @@ export function executeSkillCollectionHistory(
189180
if (truncated) {
190181
text = `${truncateUtf16Safe(text, textLimit)}${SKILL_COLLECTION_HISTORY_TRUNCATION_MARKER}`;
191182
}
192-
return {
193-
content: [
194-
{
195-
type: "text" as const,
196-
text: outcomes.length === 0 ? "No recorded collection reviews." : text,
197-
},
198-
],
199-
details: { reviews, truncated },
200-
};
183+
return textResult(outcomes.length === 0 ? "No recorded collection reviews." : text, {
184+
reviews,
185+
truncated,
186+
});
201187
}
202188

203189
function readCollectionPlanParam(params: Record<string, unknown>): SkillCollectionPlanEntry[] {

‎src/agents/tools/skill-workshop-tool-helpers.ts‎

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
SkillWorkshopProposalReviewCompletion,
1818
} from "../../skills/workshop/types.js";
1919
import { readPositiveIntegerParam, readToolStringParam, ToolInputError } from "./common.js";
20+
import { textResult } from "./tool-results.js";
2021

2122
export function assertAutonomousSkillSize(
2223
name: string,
@@ -97,10 +98,7 @@ export async function completeProposalReview(completion: SkillWorkshopProposalRe
9798
}
9899

99100
function completionResult() {
100-
return {
101-
content: [{ type: "text" as const, text: "Completed Skill Workshop review." }],
102-
details: { completed: true },
103-
};
101+
return textResult("Completed Skill Workshop review.", { completed: true });
104102
}
105103

106104
export function proposalMutationText(action: string, record: SkillProposalRecord): string {
@@ -111,20 +109,17 @@ export function actionResult(
111109
record: SkillProposalRecord,
112110
options: { contentText: string; targetSkillFile?: string },
113111
) {
114-
return {
115-
content: [{ type: "text" as const, text: options.contentText }],
116-
details: {
117-
id: record.id,
118-
status: record.status,
119-
kind: record.kind,
120-
skillName: record.target.skillName,
121-
skillKey: record.target.skillKey,
122-
targetSkillFile: options.targetSkillFile ?? record.target.skillFile,
123-
scanState: record.scan.state,
124-
proposedVersion: record.proposedVersion,
125-
draftHash: record.draftHash,
126-
},
127-
};
112+
return textResult(options.contentText, {
113+
id: record.id,
114+
status: record.status,
115+
kind: record.kind,
116+
skillName: record.target.skillName,
117+
skillKey: record.target.skillKey,
118+
targetSkillFile: options.targetSkillFile ?? record.target.skillFile,
119+
scanState: record.scan.state,
120+
proposedVersion: record.proposedVersion,
121+
draftHash: record.draftHash,
122+
});
128123
}
129124

130125
export function proposalResult(

‎src/agents/tools/skill-workshop-tool.collection-restore.test.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ describe("skill_workshop collection restore", () => {
4343
collectionReconcile: { approvedSkillNames: new Set(["duplicate"]) },
4444
});
4545
await reviewTool.execute("read", { action: "read", skill_name: "duplicate" });
46-
await reviewTool.execute("reconcile", {
46+
const reconciled = await reviewTool.execute("reconcile", {
4747
action: "reconcile",
4848
collection: [{ action: "drop", name: "duplicate", reason: "redundant" }],
4949
});
50+
const backupId = (reconciled.details as { backupId: string }).backupId;
5051
const aliasParent = await tempDirs.make("openclaw-skill-collection-restore-alias-");
5152
const workspaceAlias = path.join(aliasParent, "workspace-alias");
5253
await fs.symlink(
@@ -59,7 +60,16 @@ describe("skill_workshop collection restore", () => {
5960
workspaceDir: workspaceAlias,
6061
env: testState.env,
6162
});
62-
await foregroundTool.execute("restore", { action: "restore_collection" });
63+
const restored = await foregroundTool.execute("restore", { action: "restore_collection" });
64+
expect(restored).toMatchObject({
65+
content: [
66+
{
67+
type: "text",
68+
text: `Restored skill collection backup ${backupId}: restored 1, removed 0.`,
69+
},
70+
],
71+
details: { backupId, restored: ["duplicate"], removed: [] },
72+
});
6373

6474
await expect(
6575
fs.readFile(path.join(workspaceAlias, "skills", "duplicate", "SKILL.md"), "utf8"),

‎src/agents/tools/skill-workshop-tool.ts‎

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import {
8383
SKILL_PROPOSAL_STATUSES,
8484
SKILL_WORKSHOP_ACTIONS,
8585
} from "./skill-workshop-tool-schema.js";
86+
import { textResult } from "./tool-results.js";
8687

8788
const SKILL_WORKSHOP_MUTATION_ACTIONS = new Set(["create", "patch", "update", "revise"]);
8889
function requireProposalContent(content: string | undefined): string {
@@ -279,10 +280,11 @@ export function createSkillWorkshopTool(options: SkillWorkshopToolOptions): AnyA
279280
readMaxChars,
280281
)
281282
: skill.content;
282-
return {
283-
content: [{ type: "text", text }],
284-
details: { skillKey: skill.skillKey, sizeBytes, contentIncluded: !truncated },
285-
};
283+
return textResult(text, {
284+
skillKey: skill.skillKey,
285+
sizeBytes,
286+
contentIncluded: !truncated,
287+
});
286288
}
287289

288290
if (action === "prepare_patch") {
@@ -335,12 +337,7 @@ export function createSkillWorkshopTool(options: SkillWorkshopToolOptions): AnyA
335337
query,
336338
limit,
337339
});
338-
return {
339-
content: [{ type: "text", text: formatProposalList(proposals) }],
340-
details: {
341-
proposals,
342-
},
343-
};
340+
return textResult(formatProposalList(proposals), { proposals });
344341
}
345342

346343
if (action === "inspect") {
@@ -392,20 +389,12 @@ export function createSkillWorkshopTool(options: SkillWorkshopToolOptions): AnyA
392389
expectedRevisionHash: readToolStringParam(params, "expected_revision_hash"),
393390
correlationId: readToolStringParam(params, "correlation_id"),
394391
});
395-
return {
396-
content: [
397-
{
398-
type: "text",
399-
text: formatProposalEvaluation(evaluated.evaluation, evaluated.record.id),
400-
},
401-
],
402-
details: {
403-
id: evaluated.record.id,
404-
proposedVersion: evaluated.evaluation.proposedVersion,
405-
revisionHash: evaluated.evaluation.revisionHash,
406-
evaluation: evaluated.evaluation,
407-
},
408-
};
392+
return textResult(formatProposalEvaluation(evaluated.evaluation, evaluated.record.id), {
393+
id: evaluated.record.id,
394+
proposedVersion: evaluated.evaluation.proposedVersion,
395+
revisionHash: evaluated.evaluation.revisionHash,
396+
evaluation: evaluated.evaluation,
397+
});
409398
}
410399

411400
if (action === "apply") {

0 commit comments

Comments
 (0)