@vellumai/assistant 0.9.0-dev.202606191847.4c0bfe4 → 0.9.0-dev.202606191950.a2e5513
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +1 -1
- package/package.json +1 -1
- package/src/__tests__/conversation-skill-tools.test.ts +3 -1
- package/src/__tests__/disk-pressure-tools.test.ts +41 -1
- package/src/__tests__/first-class-skill-defs.test.ts +99 -0
- package/src/__tests__/injector-disk-pressure.test.ts +10 -5
- package/src/__tests__/skill-execute-input.test.ts +126 -0
- package/src/__tests__/skill-load-tool.test.ts +72 -0
- package/src/__tests__/skill-tool-factory.test.ts +18 -0
- package/src/__tests__/system-storage-cleanup-skill.test.ts +56 -0
- package/src/config/bundled-skills/system-storage-cleanup/SKILL.md +74 -0
- package/src/daemon/conversation-skill-tools.ts +4 -1
- package/src/daemon/conversation-tool-setup.ts +66 -4
- package/src/plugins/defaults/memory-retrieval/injectors.ts +4 -4
- package/src/tools/skills/execute.ts +66 -2
- package/src/tools/skills/load.ts +43 -2
- package/src/tools/skills/skill-tool-factory.ts +6 -1
- package/src/tools/types.ts +1 -0
package/ARCHITECTURE.md
CHANGED
|
@@ -33,7 +33,7 @@ Safe storage limits protect the workspace volume from running out of disk. The d
|
|
|
33
33
|
|
|
34
34
|
**Background work:** Heartbeats, scheduled tasks, filing work, retry sweeps, and background tool completions call `src/daemon/disk-pressure-background-gate.ts` before starting work. While effectively locked they skip the wake or job and log throttled disk-pressure fields.
|
|
35
35
|
|
|
36
|
-
**Prompt and tools:** Cleanup-mode turns carry `diskPressureContext` through runtime assembly and receive the `<disk_pressure_warning>` injector in `src/plugins/defaults/injectors.ts`. The instruction tells the assistant to warn first,
|
|
36
|
+
**Prompt and tools:** Cleanup-mode turns carry `diskPressureContext` through runtime assembly and receive the concise `<disk_pressure_warning>` injector in `src/plugins/defaults/memory-retrieval/injectors.ts`. The instruction tells the assistant to warn first, call `skill_load` for `system-storage-cleanup`, and explain that background processes and trusted-contact messages are blocked. Tool setup marks the turn as cleanup mode; `skill_load` remains available so the assistant can load the cleanup skill (or another already-installed skill) for its instructions, but under the lock it performs **no side effects** — it skips catalog auto-install (workspace writes / `bun install`) and strips inline command tokens instead of executing them, so loading a skill cannot write to the workspace or run shell. `skill_execute` and skill-origin tools remain unavailable, and a loaded skill's own tools stay filtered by the cleanup allowlist. The bundled `system-storage-cleanup` skill (`src/config/bundled-skills/system-storage-cleanup/SKILL.md`) carries the detailed cleanup procedure and deletion safety rules, including read-only SQLite diagnosis only; product-owned retention and maintenance work remains tracked separately by ATL-450 and related tickets. `src/tools/tool-approval-handler.ts` rejects non-cleanup-safe tools, and foreground shell inspection remains available while background `bash` and `host_bash` modes are rejected. When a new lock is created, active background terminal tools are cancelled with reason `disk_pressure`.
|
|
37
37
|
|
|
38
38
|
### Single-Header JWT Auth Model
|
|
39
39
|
|
package/package.json
CHANGED
|
@@ -372,7 +372,9 @@ describe("projectSkillTools", () => {
|
|
|
372
372
|
previouslyActiveSkillIds: sessionState,
|
|
373
373
|
});
|
|
374
374
|
|
|
375
|
-
// Tool definitions are
|
|
375
|
+
// Tool definitions are not sent to the LLM here — tools are invoked via
|
|
376
|
+
// skill_execute dispatch; weak-open-model first-class exposure resolves
|
|
377
|
+
// defs from the registry by name in createResolveToolsCallback.
|
|
376
378
|
expect(result.toolDefinitions).toEqual([]);
|
|
377
379
|
expect(result.allowedToolNames).toEqual(
|
|
378
380
|
new Set(["deploy_run", "deploy_status"]),
|
|
@@ -96,6 +96,9 @@ const {
|
|
|
96
96
|
} = await import("../tools/background-tool-registry.js");
|
|
97
97
|
const { shellTool } = await import("../tools/terminal/shell.js");
|
|
98
98
|
const { hostShellTool } = await import("../tools/host-terminal/host-shell.js");
|
|
99
|
+
const { __clearRegistryForTesting: clearToolRegistryForTesting, registerTool } =
|
|
100
|
+
await import("../tools/registry.js");
|
|
101
|
+
const { skillLoadTool } = await import("../tools/skills/load.js");
|
|
99
102
|
|
|
100
103
|
function makeToolDef(name: string): ToolDefinition {
|
|
101
104
|
return { name, description: `${name} tool`, input_schema: {} };
|
|
@@ -124,12 +127,15 @@ function setDiskUsage(usedMb: number, totalMb = 100): void {
|
|
|
124
127
|
|
|
125
128
|
beforeEach(() => {
|
|
126
129
|
_clearRegistryForTesting();
|
|
130
|
+
clearToolRegistryForTesting();
|
|
131
|
+
registerTool(skillLoadTool);
|
|
127
132
|
__resetDiskPressureGuardForTests();
|
|
128
133
|
setDiskUsage(10);
|
|
129
134
|
});
|
|
130
135
|
|
|
131
136
|
afterEach(() => {
|
|
132
137
|
_clearRegistryForTesting();
|
|
138
|
+
clearToolRegistryForTesting();
|
|
133
139
|
__resetDiskPressureGuardForTests();
|
|
134
140
|
diskSample = null;
|
|
135
141
|
});
|
|
@@ -140,6 +146,7 @@ describe("disk pressure cleanup tool restrictions", () => {
|
|
|
140
146
|
makeToolDef("bash"),
|
|
141
147
|
makeToolDef("host_bash"),
|
|
142
148
|
makeToolDef("file_read"),
|
|
149
|
+
makeToolDef("skill_load"),
|
|
143
150
|
makeToolDef("file_write"),
|
|
144
151
|
makeToolDef("skill_execute"),
|
|
145
152
|
makeToolDef("web_fetch"),
|
|
@@ -150,8 +157,14 @@ describe("disk pressure cleanup tool restrictions", () => {
|
|
|
150
157
|
const cleanupTools = resolve([]);
|
|
151
158
|
const cleanupNames = cleanupTools.map((tool) => tool.name).sort();
|
|
152
159
|
|
|
153
|
-
expect(cleanupNames).toEqual([
|
|
160
|
+
expect(cleanupNames).toEqual([
|
|
161
|
+
"bash",
|
|
162
|
+
"file_read",
|
|
163
|
+
"host_bash",
|
|
164
|
+
"skill_load",
|
|
165
|
+
]);
|
|
154
166
|
expect(ctx.allowedToolNames?.has("bash")).toBe(true);
|
|
167
|
+
expect(ctx.allowedToolNames?.has("skill_load")).toBe(true);
|
|
155
168
|
expect(ctx.allowedToolNames?.has("file_write")).toBe(false);
|
|
156
169
|
expect(ctx.allowedToolNames?.has("skill_execute")).toBe(false);
|
|
157
170
|
|
|
@@ -192,6 +205,33 @@ describe("disk pressure cleanup tool restrictions", () => {
|
|
|
192
205
|
);
|
|
193
206
|
});
|
|
194
207
|
|
|
208
|
+
test("executor fallback allows normal skill_load during cleanup mode", async () => {
|
|
209
|
+
const handler = new ToolApprovalHandler();
|
|
210
|
+
const result = await handler.checkPreExecutionGates(
|
|
211
|
+
"skill_load",
|
|
212
|
+
{ skill: "system-storage-cleanup" },
|
|
213
|
+
{
|
|
214
|
+
workingDir: "/workspace",
|
|
215
|
+
conversationId: "conv-cleanup",
|
|
216
|
+
trustClass: "guardian",
|
|
217
|
+
allowedToolNames: new Set(["skill_load"]),
|
|
218
|
+
diskPressureCleanupModeActive: true,
|
|
219
|
+
},
|
|
220
|
+
"sandbox",
|
|
221
|
+
"low",
|
|
222
|
+
Date.now(),
|
|
223
|
+
() => undefined,
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
expect(result.allowed).toBe(true);
|
|
227
|
+
if (!result.allowed) {
|
|
228
|
+
throw new Error(
|
|
229
|
+
"Expected disk pressure cleanup mode to allow skill_load",
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
expect(result.tool.name).toBe("skill_load");
|
|
233
|
+
});
|
|
234
|
+
|
|
195
235
|
test("locking cancels registered terminal background tools with disk pressure reason", () => {
|
|
196
236
|
const bashCancel = mock((_reason?: string) => undefined);
|
|
197
237
|
const hostCancel = mock((_reason?: string) => undefined);
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for resolveFirstClassSkillDefs: weak open models get loaded skill tools
|
|
3
|
+
* exposed first-class (resolved from the registry by name), capable models do
|
|
4
|
+
* not, and the turn allowlist still gates which defs are included.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
8
|
+
|
|
9
|
+
import { resolveFirstClassSkillDefs } from "../daemon/conversation-tool-setup.js";
|
|
10
|
+
import { RiskLevel } from "../permissions/types.js";
|
|
11
|
+
import { registerSkillTools, unregisterSkillTools } from "../tools/registry.js";
|
|
12
|
+
import type { Tool } from "../tools/types.js";
|
|
13
|
+
|
|
14
|
+
const MINIMAX = "accounts/fireworks/models/minimax-m3";
|
|
15
|
+
const CLAUDE = "claude-opus-4-8";
|
|
16
|
+
|
|
17
|
+
const SKILL_ID = "first-class-test-skill";
|
|
18
|
+
|
|
19
|
+
function makeSkillTool(name: string): Tool {
|
|
20
|
+
return {
|
|
21
|
+
name,
|
|
22
|
+
description: `Test tool ${name}`,
|
|
23
|
+
category: "testing",
|
|
24
|
+
defaultRiskLevel: RiskLevel.Low,
|
|
25
|
+
executionTarget: "host",
|
|
26
|
+
input_schema: {
|
|
27
|
+
type: "object",
|
|
28
|
+
properties: { content: { type: "string" } },
|
|
29
|
+
required: ["content"],
|
|
30
|
+
},
|
|
31
|
+
execute: async () => ({ content: "", isError: false }),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe("resolveFirstClassSkillDefs", () => {
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
registerSkillTools(SKILL_ID, [
|
|
38
|
+
makeSkillTool("document_update"),
|
|
39
|
+
makeSkillTool("document_create"),
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
unregisterSkillTools(SKILL_ID);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const allowed = new Set(["document_update", "document_create"]);
|
|
48
|
+
const turnAllowed = new Set([
|
|
49
|
+
"document_update",
|
|
50
|
+
"document_create",
|
|
51
|
+
"skill_execute",
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
test("exposes loaded skill tools for a weak open model", () => {
|
|
55
|
+
const defs = resolveFirstClassSkillDefs(allowed, turnAllowed, MINIMAX);
|
|
56
|
+
expect(defs.map((d) => d.name).sort()).toEqual([
|
|
57
|
+
"document_create",
|
|
58
|
+
"document_update",
|
|
59
|
+
]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("returns nothing for a capable model", () => {
|
|
63
|
+
const defs = resolveFirstClassSkillDefs(allowed, turnAllowed, CLAUDE);
|
|
64
|
+
expect(defs).toEqual([]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("returns nothing when the model is unknown/absent", () => {
|
|
68
|
+
expect(resolveFirstClassSkillDefs(allowed, turnAllowed, null)).toEqual([]);
|
|
69
|
+
expect(resolveFirstClassSkillDefs(allowed, turnAllowed, undefined)).toEqual(
|
|
70
|
+
[],
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("respects the turn allowlist (subagent / exclude gating)", () => {
|
|
75
|
+
// Only document_update is allowed this turn — document_create is filtered.
|
|
76
|
+
const restricted = new Set(["document_update", "skill_execute"]);
|
|
77
|
+
const defs = resolveFirstClassSkillDefs(allowed, restricted, MINIMAX);
|
|
78
|
+
expect(defs.map((d) => d.name)).toEqual(["document_update"]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("skips names with no registered tool", () => {
|
|
82
|
+
const withGhost = new Set([...allowed, "not_registered"]);
|
|
83
|
+
const turn = new Set([...turnAllowed, "not_registered"]);
|
|
84
|
+
const defs = resolveFirstClassSkillDefs(withGhost, turn, MINIMAX);
|
|
85
|
+
expect(defs.map((d) => d.name).sort()).toEqual([
|
|
86
|
+
"document_create",
|
|
87
|
+
"document_update",
|
|
88
|
+
]);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("each exposed def carries its real scalar schema (single-escape)", () => {
|
|
92
|
+
const defs = resolveFirstClassSkillDefs(allowed, turnAllowed, MINIMAX);
|
|
93
|
+
const update = defs.find((d) => d.name === "document_update");
|
|
94
|
+
expect(update?.input_schema).toMatchObject({
|
|
95
|
+
properties: { content: { type: "string" } },
|
|
96
|
+
required: ["content"],
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -204,7 +204,7 @@ describe("disk-pressure-warning injector", () => {
|
|
|
204
204
|
.run();
|
|
205
205
|
});
|
|
206
206
|
|
|
207
|
-
test("emits the
|
|
207
|
+
test("emits the concise cleanup skill prompt during disk pressure cleanup mode", async () => {
|
|
208
208
|
seedDiskPressure(true);
|
|
209
209
|
const block = await diskPressureInjector.produce(makeContext());
|
|
210
210
|
|
|
@@ -217,14 +217,19 @@ describe("disk-pressure-warning injector", () => {
|
|
|
217
217
|
DEFAULT_INJECTOR_ORDER.diskPressureWarning,
|
|
218
218
|
);
|
|
219
219
|
expect(DISK_PRESSURE_WARNING_PROMPT).toBe(`<disk_pressure_warning>
|
|
220
|
-
|
|
220
|
+
Storage is critically low and normal work is suspended until space is freed.
|
|
221
221
|
|
|
222
|
-
|
|
222
|
+
Your first user-visible paragraph must warn the user that storage is critically low and normal work is suspended.
|
|
223
223
|
|
|
224
|
-
|
|
224
|
+
Before taking cleanup actions, call \`skill_load\` with \`skill: "system-storage-cleanup"\` and follow the cleanup skill.
|
|
225
225
|
|
|
226
|
-
|
|
226
|
+
Unrelated work remains blocked until disk usage drops below the critical threshold or the guardian explicitly overrides the lock. Background processes and trusted-contact messages remain blocked while this cleanup mode is active.
|
|
227
227
|
</disk_pressure_warning>`);
|
|
228
|
+
expect(DISK_PRESSURE_WARNING_PROMPT).toContain("skill_load");
|
|
229
|
+
expect(DISK_PRESSURE_WARNING_PROMPT).toContain("system-storage-cleanup");
|
|
230
|
+
expect(DISK_PRESSURE_WARNING_PROMPT).not.toContain(
|
|
231
|
+
"Prefer safe inspection steps first",
|
|
232
|
+
);
|
|
228
233
|
});
|
|
229
234
|
|
|
230
235
|
test("omits the prompt when no cleanup context is registered or it is inactive", async () => {
|
|
@@ -2,9 +2,20 @@ import { describe, expect, test } from "bun:test";
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
augmentSkillExecuteError,
|
|
5
|
+
recoverSkillExecuteEnvelope,
|
|
5
6
|
resolveSkillExecuteInput,
|
|
6
7
|
} from "../tools/skills/execute.js";
|
|
7
8
|
|
|
9
|
+
/** Schema with exactly one required string field (e.g. document_update). */
|
|
10
|
+
const SINGLE_REQUIRED_STRING_SCHEMA = {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: {
|
|
13
|
+
content: { type: "string" },
|
|
14
|
+
mode: { type: "string", enum: ["replace", "append"] },
|
|
15
|
+
},
|
|
16
|
+
required: ["content"],
|
|
17
|
+
};
|
|
18
|
+
|
|
8
19
|
describe("resolveSkillExecuteInput", () => {
|
|
9
20
|
test("returns a correctly nested object unchanged", () => {
|
|
10
21
|
const input = { prompt: "a sunset", variants: 2 };
|
|
@@ -85,6 +96,121 @@ describe("resolveSkillExecuteInput", () => {
|
|
|
85
96
|
});
|
|
86
97
|
expect(result).toEqual({ foo: "bar" });
|
|
87
98
|
});
|
|
99
|
+
|
|
100
|
+
test("maps a bare (non-JSON) input string to the sole required string field", () => {
|
|
101
|
+
// The exact shape from the doc-writer incident: the full Markdown body
|
|
102
|
+
// passed as `input` instead of `{ "content": "..." }`.
|
|
103
|
+
const body = "# AI in 2026\n\nWe're halfway through the year.";
|
|
104
|
+
const result = resolveSkillExecuteInput(
|
|
105
|
+
{ tool: "document_update", input: body, activity: "Streaming article" },
|
|
106
|
+
SINGLE_REQUIRED_STRING_SCHEMA,
|
|
107
|
+
);
|
|
108
|
+
expect(result).toEqual({ content: body });
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("does not map a bare string without the inner schema", () => {
|
|
112
|
+
const result = resolveSkillExecuteInput({
|
|
113
|
+
tool: "document_update",
|
|
114
|
+
input: "# AI in 2026",
|
|
115
|
+
activity: "Streaming article",
|
|
116
|
+
});
|
|
117
|
+
expect(result).toEqual({});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("does not map a bare string when the schema has multiple required fields", () => {
|
|
121
|
+
const schema = {
|
|
122
|
+
type: "object",
|
|
123
|
+
properties: { a: { type: "string" }, b: { type: "string" } },
|
|
124
|
+
required: ["a", "b"],
|
|
125
|
+
};
|
|
126
|
+
const result = resolveSkillExecuteInput(
|
|
127
|
+
{ tool: "t", input: "some text", activity: "x" },
|
|
128
|
+
schema,
|
|
129
|
+
);
|
|
130
|
+
expect(result).toEqual({});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test("does not map a bare string when the sole required field is not a string", () => {
|
|
134
|
+
const schema = {
|
|
135
|
+
type: "object",
|
|
136
|
+
properties: { count: { type: "number" } },
|
|
137
|
+
required: ["count"],
|
|
138
|
+
};
|
|
139
|
+
const result = resolveSkillExecuteInput(
|
|
140
|
+
{ tool: "t", input: "42", activity: "x" },
|
|
141
|
+
schema,
|
|
142
|
+
);
|
|
143
|
+
// "42" parses as JSON but isn't an object, and the lone required field is
|
|
144
|
+
// not a string — no rescue applies.
|
|
145
|
+
expect(result).toEqual({});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("a valid JSON-object string still wins over the bare-string rescue", () => {
|
|
149
|
+
const result = resolveSkillExecuteInput(
|
|
150
|
+
{
|
|
151
|
+
tool: "document_update",
|
|
152
|
+
input: '{"content":"hello","mode":"append"}',
|
|
153
|
+
activity: "x",
|
|
154
|
+
},
|
|
155
|
+
SINGLE_REQUIRED_STRING_SCHEMA,
|
|
156
|
+
);
|
|
157
|
+
expect(result).toEqual({ content: "hello", mode: "append" });
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test("an empty input string is not rescued (nothing to map)", () => {
|
|
161
|
+
const result = resolveSkillExecuteInput(
|
|
162
|
+
{ tool: "document_update", input: "", activity: "x" },
|
|
163
|
+
SINGLE_REQUIRED_STRING_SCHEMA,
|
|
164
|
+
);
|
|
165
|
+
expect(result).toEqual({});
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe("recoverSkillExecuteEnvelope", () => {
|
|
170
|
+
test("recovers a valid envelope wrapped under the _raw marker", () => {
|
|
171
|
+
// MiniMax coercion marks a bare-string `input` call unparseable even though
|
|
172
|
+
// the outer arguments are valid JSON.
|
|
173
|
+
const raw = JSON.stringify({
|
|
174
|
+
tool: "document_update",
|
|
175
|
+
input: "# AI in 2026\n\nbody",
|
|
176
|
+
activity: "Streaming",
|
|
177
|
+
});
|
|
178
|
+
const recovered = recoverSkillExecuteEnvelope({ _raw: raw });
|
|
179
|
+
expect(recovered).toEqual({
|
|
180
|
+
tool: "document_update",
|
|
181
|
+
input: "# AI in 2026\n\nbody",
|
|
182
|
+
activity: "Streaming",
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test("leaves a genuinely unparseable (truncated) call wrapped", () => {
|
|
187
|
+
const wrapped = { _raw: '{"tool":"document_update","input":"# AI' };
|
|
188
|
+
expect(recoverSkillExecuteEnvelope(wrapped)).toBe(wrapped);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test("passes a normal envelope through untouched", () => {
|
|
192
|
+
const envelope = {
|
|
193
|
+
tool: "document_update",
|
|
194
|
+
input: { content: "hi" },
|
|
195
|
+
activity: "x",
|
|
196
|
+
};
|
|
197
|
+
expect(recoverSkillExecuteEnvelope(envelope)).toBe(envelope);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test("end-to-end: recovered bare-string envelope resolves to content", () => {
|
|
201
|
+
const body = "# Title\n\nThe full article body.";
|
|
202
|
+
const raw = JSON.stringify({
|
|
203
|
+
tool: "document_update",
|
|
204
|
+
input: body,
|
|
205
|
+
activity: "Streaming",
|
|
206
|
+
});
|
|
207
|
+
const envelope = recoverSkillExecuteEnvelope({ _raw: raw });
|
|
208
|
+
const resolved = resolveSkillExecuteInput(
|
|
209
|
+
envelope,
|
|
210
|
+
SINGLE_REQUIRED_STRING_SCHEMA,
|
|
211
|
+
);
|
|
212
|
+
expect(resolved).toEqual({ content: body });
|
|
213
|
+
});
|
|
88
214
|
});
|
|
89
215
|
|
|
90
216
|
describe("augmentSkillExecuteError", () => {
|
|
@@ -100,6 +100,21 @@ async function executeSkillLoad(
|
|
|
100
100
|
return { content: result.content, isError: result.isError };
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
async function executeSkillLoadCleanup(
|
|
104
|
+
input: Record<string, unknown>,
|
|
105
|
+
): Promise<{ content: string; isError: boolean }> {
|
|
106
|
+
const tool = getTool("skill_load");
|
|
107
|
+
if (!tool) throw new Error("skill_load tool was not registered");
|
|
108
|
+
|
|
109
|
+
const result = await tool.execute(input, {
|
|
110
|
+
workingDir: "/tmp",
|
|
111
|
+
conversationId: "conversation-1",
|
|
112
|
+
trustClass: "guardian",
|
|
113
|
+
diskPressureCleanupModeActive: true,
|
|
114
|
+
});
|
|
115
|
+
return { content: result.content, isError: result.isError };
|
|
116
|
+
}
|
|
117
|
+
|
|
103
118
|
describe("skill_load tool", () => {
|
|
104
119
|
beforeEach(() => {
|
|
105
120
|
mkdirSync(join(TEST_DIR, "skills"), { recursive: true });
|
|
@@ -911,4 +926,61 @@ describe("skill_load tool", () => {
|
|
|
911
926
|
expect(result.content).toContain("Suggested Included Skills (not loaded):");
|
|
912
927
|
expect(installCount).toBeLessThanOrEqual(5);
|
|
913
928
|
});
|
|
929
|
+
|
|
930
|
+
// During disk-pressure cleanup mode, skill_load is allowed but must not
|
|
931
|
+
// produce side effects: no catalog auto-install (workspace writes / bun
|
|
932
|
+
// install) and no inline command execution. Instructions are still returned.
|
|
933
|
+
test("does not auto-install a missing catalog skill during cleanup mode", async () => {
|
|
934
|
+
mockAutoInstall.mockImplementation((skillId: string) => {
|
|
935
|
+
writeSkill(skillId, "Should Not Install", "nope", "body");
|
|
936
|
+
return Promise.resolve(true);
|
|
937
|
+
});
|
|
938
|
+
|
|
939
|
+
const result = await executeSkillLoadCleanup({ skill: "absent-skill" });
|
|
940
|
+
|
|
941
|
+
expect(mockAutoInstall).not.toHaveBeenCalled();
|
|
942
|
+
expect(result.isError).toBe(true);
|
|
943
|
+
});
|
|
944
|
+
|
|
945
|
+
test("does not auto-install missing includes during cleanup mode", async () => {
|
|
946
|
+
writeSkillWithIncludes(
|
|
947
|
+
"cleanup-parent",
|
|
948
|
+
"Cleanup Parent",
|
|
949
|
+
"Has a missing include",
|
|
950
|
+
"Parent body",
|
|
951
|
+
["cleanup-dep"],
|
|
952
|
+
);
|
|
953
|
+
mockAutoInstall.mockImplementation((skillId: string) => {
|
|
954
|
+
writeSkill(skillId, "Cleanup Dep", "should not install", "Dep body");
|
|
955
|
+
return Promise.resolve(true);
|
|
956
|
+
});
|
|
957
|
+
|
|
958
|
+
const result = await executeSkillLoadCleanup({ skill: "cleanup-parent" });
|
|
959
|
+
|
|
960
|
+
expect(mockAutoInstall).not.toHaveBeenCalled();
|
|
961
|
+
expect(result.isError).toBe(false);
|
|
962
|
+
expect(result.content).toContain("Skill: Cleanup Parent");
|
|
963
|
+
expect(result.content).toContain("Suggested Included Skills (not loaded):");
|
|
964
|
+
expect(result.content).toContain("cleanup-dep");
|
|
965
|
+
});
|
|
966
|
+
|
|
967
|
+
test("strips inline command tokens instead of executing them during cleanup mode", async () => {
|
|
968
|
+
writeSkill(
|
|
969
|
+
"cleanup-inline",
|
|
970
|
+
"Cleanup Inline",
|
|
971
|
+
"Has an inline command",
|
|
972
|
+
"Before !`echo SENTINEL_OUTPUT` after",
|
|
973
|
+
);
|
|
974
|
+
|
|
975
|
+
const result = await executeSkillLoadCleanup({ skill: "cleanup-inline" });
|
|
976
|
+
|
|
977
|
+
expect(result.isError).toBe(false);
|
|
978
|
+
expect(result.content).toContain(
|
|
979
|
+
"[inline command skipped: storage cleanup mode]",
|
|
980
|
+
);
|
|
981
|
+
expect(result.content).not.toContain("SENTINEL_OUTPUT");
|
|
982
|
+
expect(result.content).not.toContain("!`echo SENTINEL_OUTPUT`");
|
|
983
|
+
expect(result.content).toContain("Before");
|
|
984
|
+
expect(result.content).toContain("after");
|
|
985
|
+
});
|
|
914
986
|
});
|
|
@@ -255,6 +255,24 @@ describe("createSkillTool — unknown parameter validation", () => {
|
|
|
255
255
|
expect(result.isError).toBe(false);
|
|
256
256
|
});
|
|
257
257
|
|
|
258
|
+
test("strips the harness `activity` field before validation", async () => {
|
|
259
|
+
const hash = computeSkillVersionHash(tempDir);
|
|
260
|
+
const tool = createSkillTool(
|
|
261
|
+
makeEntry({ executor: "echo.ts" }),
|
|
262
|
+
tempDir,
|
|
263
|
+
hash,
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
// A first-class skill-tool call may carry `activity` (the harness progress
|
|
267
|
+
// field). It must not be rejected as an unknown parameter.
|
|
268
|
+
const result = await tool.execute(
|
|
269
|
+
{ query: "hello", activity: "Doing the thing" },
|
|
270
|
+
makeContext(),
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
expect(result.isError).toBe(false);
|
|
274
|
+
});
|
|
275
|
+
|
|
258
276
|
test("allows empty input when schema has no required fields", async () => {
|
|
259
277
|
const hash = computeSkillVersionHash(tempDir);
|
|
260
278
|
const tool = createSkillTool(
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import { loadSkillBySelector, loadSkillCatalog } from "../config/skills.js";
|
|
4
|
+
|
|
5
|
+
describe("system-storage-cleanup bundled skill", () => {
|
|
6
|
+
test("is bundled without tools or inline command expansions", () => {
|
|
7
|
+
const catalog = loadSkillCatalog();
|
|
8
|
+
const skill = catalog.find(
|
|
9
|
+
(candidate) => candidate.id === "system-storage-cleanup",
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
expect(skill).toBeDefined();
|
|
13
|
+
expect(skill!.source).toBe("bundled");
|
|
14
|
+
expect(skill!.bundled).toBe(true);
|
|
15
|
+
expect(skill!.toolManifest).toBeUndefined();
|
|
16
|
+
expect(skill!.inlineCommandExpansions).toBeUndefined();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("loads by id with the cleanup safety contract", () => {
|
|
20
|
+
const result = loadSkillBySelector("system-storage-cleanup");
|
|
21
|
+
|
|
22
|
+
expect(result.error).toBeUndefined();
|
|
23
|
+
expect(result.skill).toBeDefined();
|
|
24
|
+
expect(result.skill!.id).toBe("system-storage-cleanup");
|
|
25
|
+
expect(result.skill!.source).toBe("bundled");
|
|
26
|
+
|
|
27
|
+
const body = result.skill!.body.toLowerCase();
|
|
28
|
+
|
|
29
|
+
expect(body).toContain("normal work is suspended");
|
|
30
|
+
expect(body).toContain("stay scoped to freeing storage");
|
|
31
|
+
expect(body).toContain("prefer foreground inspection");
|
|
32
|
+
expect(body).toContain("before any mutation");
|
|
33
|
+
expect(body).toContain("ask for explicit approval before deleting");
|
|
34
|
+
expect(body).toContain("target volume");
|
|
35
|
+
expect(body).toContain("workspace path");
|
|
36
|
+
expect(body).toContain("read-only `sqlite3` access");
|
|
37
|
+
expect(body).toContain("never run ad hoc `delete`");
|
|
38
|
+
expect(body).toContain("`vacuum`");
|
|
39
|
+
expect(body).toContain("mutating sqlite command");
|
|
40
|
+
|
|
41
|
+
for (const protectedText of [
|
|
42
|
+
"credentials",
|
|
43
|
+
"security material",
|
|
44
|
+
"workspace database files",
|
|
45
|
+
"config files",
|
|
46
|
+
"backups",
|
|
47
|
+
"backup keys",
|
|
48
|
+
"memory graph nodes or segments",
|
|
49
|
+
"`journal/`",
|
|
50
|
+
"`data/reflections/`",
|
|
51
|
+
"pkb files",
|
|
52
|
+
]) {
|
|
53
|
+
expect(body).toContain(protectedText);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: system-storage-cleanup
|
|
3
|
+
description: "Handle disk pressure, critically low storage, safe storage limits, and storage cleanup mode by inspecting disk usage and proposing safe cleanup steps."
|
|
4
|
+
compatibility: "Designed for Vellum personal assistants"
|
|
5
|
+
metadata:
|
|
6
|
+
emoji: "\U0001F9F9"
|
|
7
|
+
vellum:
|
|
8
|
+
display-name: "System Storage Cleanup"
|
|
9
|
+
category: "system"
|
|
10
|
+
activation-hints:
|
|
11
|
+
- "Critical disk usage or disk-pressure lock is blocking normal work"
|
|
12
|
+
- "The assistant is in storage cleanup mode or normal work is suspended due to low storage"
|
|
13
|
+
- "User asks to inspect large files or find what is using disk space"
|
|
14
|
+
- "User asks to free workspace storage safely"
|
|
15
|
+
- "User asks to delete caches, logs, temp files, Docker artifacts, or other storage safely"
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
You are operating under a critical storage cleanup contract. Your only goal is to free enough storage for the assistant to resume normal work without damaging user data.
|
|
19
|
+
|
|
20
|
+
## Cleanup Contract
|
|
21
|
+
|
|
22
|
+
Start by warning the user that storage is critically low and normal work is suspended until storage cleanup mode clears. Stay scoped to freeing storage until the disk-pressure lock clears or the guardian explicitly overrides it.
|
|
23
|
+
|
|
24
|
+
Prefer foreground inspection with available cleanup-safe tools before any mutation. Identify both the target volume that is actually full and the workspace path before proposing deletions. Do not work on unrelated tasks, refactors, installs, upgrades, or product changes while the storage lock is active.
|
|
25
|
+
|
|
26
|
+
Ask for explicit approval before deleting files, caches, logs, package caches, Docker artifacts, or any other data unless the user has already approved that exact action. Before asking, present each proposed deletion with:
|
|
27
|
+
|
|
28
|
+
- Exact path or artifact name.
|
|
29
|
+
- Estimated reclaimable size.
|
|
30
|
+
- Expected consequence, including whether it is regenerable or may remove user-visible history.
|
|
31
|
+
|
|
32
|
+
If the user approves a broad category, narrow it to exact paths or artifacts before deleting. If the user approves one exact path, do not treat that as approval for adjacent paths.
|
|
33
|
+
|
|
34
|
+
Never delete credentials, security material, workspace database files, config files, active profiler runs, migrations, skill source, app source, conversation records, memory graph nodes or segments, `journal/`, `data/reflections/`, PKB files, backups, or backup keys unless the user explicitly names that path and accepts the consequence.
|
|
35
|
+
|
|
36
|
+
## Inspection Procedure
|
|
37
|
+
|
|
38
|
+
Use local/container-visible inspection first. Prefer `df -h` on the current workspace path and on `VELLUM_WORKSPACE_DIR` when that variable is available. In Docker/container mode, `/workspace` is the persistent volume and cleanup should normally focus there.
|
|
39
|
+
|
|
40
|
+
Use `du` one level at a time and sort by size to identify large directories before drilling deeper. Keep each pass readable and bounded to the volume or workspace that is actually full. Avoid whole-filesystem scans unless the target volume cannot be isolated.
|
|
41
|
+
|
|
42
|
+
Use `host_bash` only when the sandbox cannot see the volume that is actually full and host-level inspection is necessary. Explain why host-level inspection is needed before using it.
|
|
43
|
+
|
|
44
|
+
## SQLite Diagnosis Only
|
|
45
|
+
|
|
46
|
+
If `data/db/assistant.db` dominates disk usage, inspect it only through read-only `sqlite3` access. Diagnostics may use `PRAGMA` and `SELECT` queries for:
|
|
47
|
+
|
|
48
|
+
- `page_size`
|
|
49
|
+
- `page_count`
|
|
50
|
+
- `freelist_count`
|
|
51
|
+
- `dbstat` object-size breakdowns
|
|
52
|
+
|
|
53
|
+
The purpose is to determine whether growth comes from specific tables/indexes or from free-page bloat. Do not edit the database manually.
|
|
54
|
+
|
|
55
|
+
Never run ad hoc `DELETE`, `UPDATE`, `INSERT`, `DROP`, `REINDEX`, schema changes, `VACUUM`, `PRAGMA writable_schema`, or any other mutating SQLite command from this skill. If SQLite tables are the main culprit, tell the user this needs product-owned retention or maintenance work rather than manual database editing.
|
|
56
|
+
|
|
57
|
+
## Safer Cleanup Candidates
|
|
58
|
+
|
|
59
|
+
Good candidates to inspect and propose, when they are clearly nonessential and user-approved, include:
|
|
60
|
+
|
|
61
|
+
- Scratch or temporary downloads created by the assistant.
|
|
62
|
+
- Generated build artifacts.
|
|
63
|
+
- Old logs.
|
|
64
|
+
- Stale temporary directories.
|
|
65
|
+
- Completed profiler runs that are no longer active.
|
|
66
|
+
- Stale caches.
|
|
67
|
+
- Large old diagnostic text attachments such as spindumps.
|
|
68
|
+
- Package cache cleanup or Docker cache/artifact cleanup after the user approves the exact package manager or Docker action.
|
|
69
|
+
|
|
70
|
+
Treat source files, persistent records, and user-authored content as protected unless the user explicitly names them for deletion and accepts the consequence.
|
|
71
|
+
|
|
72
|
+
## Non-Goals
|
|
73
|
+
|
|
74
|
+
ATL-450 product work is out of scope for this skill. Do not implement configurable trace or audit retention jobs, attachment retention or compression jobs, upload-time image re-encoding, first-class disk-usage UI, one-click cleanup buttons, or scheduled SQLite vacuuming. If inspection shows those are needed, report that as follow-up product work after the immediate storage cleanup path is safe.
|
|
@@ -360,7 +360,10 @@ export function projectSkillTools(
|
|
|
360
360
|
return { toolDefinitions: [], allowedToolNames: new Set() };
|
|
361
361
|
}
|
|
362
362
|
|
|
363
|
-
// Tool definitions are
|
|
363
|
+
// Tool definitions are not sent to the LLM here — tools are invoked via
|
|
364
|
+
// skill_execute dispatch (capable models), and the weak-open-model
|
|
365
|
+
// first-class exposure resolves the registered defs from the registry in
|
|
366
|
+
// createResolveToolsCallback by name.
|
|
364
367
|
const allToolNames = new Set<string>();
|
|
365
368
|
const successfulEntries = new Map<string, string>();
|
|
366
369
|
// Track skills already unregistered in the version-change branch so the
|
|
@@ -19,16 +19,18 @@ import type { PermissionPrompter } from "../permissions/prompter.js";
|
|
|
19
19
|
import type { SecretPrompter } from "../permissions/secret-prompter.js";
|
|
20
20
|
import { advisorEnabledForProfile } from "../plugins/defaults/advisor/advisor-gate.js";
|
|
21
21
|
import type { Message, ToolDefinition } from "../providers/types.js";
|
|
22
|
+
import { isWeakOpenModel } from "../providers/weak-open-model.js";
|
|
22
23
|
import { assistantEventHub } from "../runtime/assistant-event-hub.js";
|
|
23
24
|
import { registerConversationSender } from "../tools/browser/browser-screencast.js";
|
|
24
25
|
import type { ToolExecutor } from "../tools/executor.js";
|
|
25
|
-
import { getMcpToolDefinitions } from "../tools/registry.js";
|
|
26
|
+
import { getMcpToolDefinitions, getTool } from "../tools/registry.js";
|
|
26
27
|
import {
|
|
27
28
|
ACTIVITY_SKIP_SET,
|
|
28
29
|
injectActivityField,
|
|
29
30
|
} from "../tools/schema-transforms.js";
|
|
30
31
|
import {
|
|
31
32
|
augmentSkillExecuteError,
|
|
33
|
+
recoverSkillExecuteEnvelope,
|
|
32
34
|
resolveSkillExecuteInput,
|
|
33
35
|
} from "../tools/skills/execute.js";
|
|
34
36
|
import { resolveToolInvocationAlias } from "../tools/tool-name-aliases.js";
|
|
@@ -306,9 +308,16 @@ export function createToolExecutor(
|
|
|
306
308
|
// risk level, permission checks, hooks, and lifecycle events all fire
|
|
307
309
|
// with the real tool name.
|
|
308
310
|
if (executionName === "skill_execute") {
|
|
311
|
+
// Recover an envelope the provider wrapped as unparseable when MiniMax's
|
|
312
|
+
// coercion failed to JSON-decode a bare-string `input` (see
|
|
313
|
+
// recoverSkillExecuteEnvelope), then resolve the inner tool + params.
|
|
314
|
+
const envelope = recoverSkillExecuteEnvelope(executionInput);
|
|
309
315
|
const rawToolName =
|
|
310
|
-
typeof
|
|
311
|
-
const
|
|
316
|
+
typeof envelope.tool === "string" ? envelope.tool : "";
|
|
317
|
+
const innerSchema = rawToolName
|
|
318
|
+
? getTool(rawToolName)?.input_schema
|
|
319
|
+
: undefined;
|
|
320
|
+
const rawToolInput = resolveSkillExecuteInput(envelope, innerSchema);
|
|
312
321
|
|
|
313
322
|
// Clone to avoid mutating shared input objects
|
|
314
323
|
const { name: toolName, input: toolInput } = resolveToolInvocationAlias(
|
|
@@ -673,6 +682,36 @@ export function isToolActiveForContext(
|
|
|
673
682
|
return true;
|
|
674
683
|
}
|
|
675
684
|
|
|
685
|
+
/**
|
|
686
|
+
* Resolve the loaded skill tools to expose first-class to weak open models.
|
|
687
|
+
*
|
|
688
|
+
* Weak open models (MiniMax, Kimi, DeepSeek, GLM) fail to serialize the nested
|
|
689
|
+
* `skill_execute` envelope — a large value double-escaped as a JSON string in
|
|
690
|
+
* `input` — and either drop it or emit it bare. Exposing each loaded skill
|
|
691
|
+
* tool first-class lets the model fill the tool's own scalar params directly
|
|
692
|
+
* (single-escape). Capable models keep the envelope-only contract: this returns
|
|
693
|
+
* `[]` for them, so their wire surface is unchanged.
|
|
694
|
+
*
|
|
695
|
+
* Defs are resolved from the registry by name; `skillToolNames` come from the
|
|
696
|
+
* projection (skill tools only), filtered by `turnAllowed` so subagent
|
|
697
|
+
* allowlists and the tool exclude list still apply. The generic `skill_execute`
|
|
698
|
+
* tool remains available as a fallback for both model tiers.
|
|
699
|
+
*/
|
|
700
|
+
export function resolveFirstClassSkillDefs(
|
|
701
|
+
skillToolNames: Iterable<string>,
|
|
702
|
+
turnAllowed: ReadonlySet<string>,
|
|
703
|
+
resolvedModel: string | null | undefined,
|
|
704
|
+
): ToolDefinition[] {
|
|
705
|
+
if (!isWeakOpenModel(resolvedModel)) return [];
|
|
706
|
+
const defs: ToolDefinition[] = [];
|
|
707
|
+
for (const name of skillToolNames) {
|
|
708
|
+
if (!turnAllowed.has(name)) continue;
|
|
709
|
+
const tool = getTool(name);
|
|
710
|
+
if (tool) defs.push(tool);
|
|
711
|
+
}
|
|
712
|
+
return defs;
|
|
713
|
+
}
|
|
714
|
+
|
|
676
715
|
/**
|
|
677
716
|
* Build a resolveTools callback that merges base tool definitions with
|
|
678
717
|
* dynamically projected skill tools on each agent turn. Also updates
|
|
@@ -802,7 +841,30 @@ export function createResolveToolsCallback(
|
|
|
802
841
|
}
|
|
803
842
|
|
|
804
843
|
ctx.allowedToolNames = turnAllowed;
|
|
805
|
-
|
|
844
|
+
|
|
845
|
+
// Weak open models fail to serialize the nested `skill_execute` envelope
|
|
846
|
+
// (a large value double-escaped as a JSON string in `input`), so expose the
|
|
847
|
+
// loaded skill tools first-class — their scalar params are emitted directly
|
|
848
|
+
// (single-escape). The defs are resolved from the registry by name; the
|
|
849
|
+
// names are already in `turnAllowed`. The generic `skill_execute` stays
|
|
850
|
+
// available as a fallback, and capable models keep the envelope-only
|
|
851
|
+
// contract (this branch is skipped for them).
|
|
852
|
+
const resolvedModel = resolveConversationAttribution({
|
|
853
|
+
conversationId: ctx.conversationId ?? "",
|
|
854
|
+
currentCallSite: ctx.currentCallSite,
|
|
855
|
+
currentTurnOverrideProfile: ctx.currentTurnOverrideProfile,
|
|
856
|
+
})?.resolvedModel;
|
|
857
|
+
const baseDefs = [
|
|
858
|
+
...injectActivityField(allBaseDefs, ACTIVITY_SKIP_SET),
|
|
859
|
+
...injectActivityField(
|
|
860
|
+
resolveFirstClassSkillDefs(
|
|
861
|
+
projection.allowedToolNames,
|
|
862
|
+
turnAllowed,
|
|
863
|
+
resolvedModel,
|
|
864
|
+
),
|
|
865
|
+
ACTIVITY_SKIP_SET,
|
|
866
|
+
),
|
|
867
|
+
];
|
|
806
868
|
|
|
807
869
|
const config = getConfig();
|
|
808
870
|
if (
|
|
@@ -117,13 +117,13 @@ export const DEFAULT_INJECTOR_ORDER = {
|
|
|
117
117
|
} as const satisfies Record<string, number>;
|
|
118
118
|
|
|
119
119
|
export const DISK_PRESSURE_WARNING_PROMPT = `<disk_pressure_warning>
|
|
120
|
-
|
|
120
|
+
Storage is critically low and normal work is suspended until space is freed.
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
Your first user-visible paragraph must warn the user that storage is critically low and normal work is suspended.
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
Before taking cleanup actions, call \`skill_load\` with \`skill: "system-storage-cleanup"\` and follow the cleanup skill.
|
|
125
125
|
|
|
126
|
-
|
|
126
|
+
Unrelated work remains blocked until disk usage drops below the critical threshold or the guardian explicitly overrides the lock. Background processes and trusted-contact messages remain blocked while this cleanup mode is active.
|
|
127
127
|
</disk_pressure_warning>`;
|
|
128
128
|
|
|
129
129
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RiskLevel } from "../../permissions/types.js";
|
|
2
|
+
import { isUnparseableToolArgs } from "../../providers/unparseable-tool-args.js";
|
|
2
3
|
import { registerTool } from "../registry.js";
|
|
3
4
|
import type {
|
|
4
5
|
ToolContext,
|
|
@@ -9,6 +10,38 @@ import type {
|
|
|
9
10
|
/** Envelope keys consumed by `skill_execute` itself, never inner-tool params. */
|
|
10
11
|
const SKILL_EXECUTE_ENVELOPE_KEYS = new Set(["tool", "input", "activity"]);
|
|
11
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Recover a `skill_execute` envelope that the provider layer wrapped under the
|
|
15
|
+
* `_raw` unparseable marker.
|
|
16
|
+
*
|
|
17
|
+
* MiniMax's object→string argument coercion JSON-decodes the inner `input`
|
|
18
|
+
* value after parsing the outer arguments. When the model passes a bare string
|
|
19
|
+
* as `input` (e.g. Markdown body instead of `{ "content": "..." }`), that inner
|
|
20
|
+
* decode fails and the whole call is marked unparseable — even though the outer
|
|
21
|
+
* envelope is valid JSON. Re-parsing `_raw` recovers `{ tool, input, activity }`
|
|
22
|
+
* so the inner tool can still be dispatched. A genuinely truncated/malformed
|
|
23
|
+
* call's `_raw` won't parse and is returned unchanged, preserving the
|
|
24
|
+
* retryable-error path for real stream corruption.
|
|
25
|
+
*/
|
|
26
|
+
export function recoverSkillExecuteEnvelope(
|
|
27
|
+
envelope: Record<string, unknown>,
|
|
28
|
+
): Record<string, unknown> {
|
|
29
|
+
if (!isUnparseableToolArgs(envelope)) return envelope;
|
|
30
|
+
try {
|
|
31
|
+
const parsed: unknown = JSON.parse(envelope._raw);
|
|
32
|
+
if (
|
|
33
|
+
parsed != null &&
|
|
34
|
+
typeof parsed === "object" &&
|
|
35
|
+
!Array.isArray(parsed)
|
|
36
|
+
) {
|
|
37
|
+
return parsed as Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
} catch {
|
|
40
|
+
// Genuinely malformed/truncated — leave wrapped for the retryable error.
|
|
41
|
+
}
|
|
42
|
+
return envelope;
|
|
43
|
+
}
|
|
44
|
+
|
|
12
45
|
/**
|
|
13
46
|
* Resolve the inner tool's parameters from a `skill_execute` envelope.
|
|
14
47
|
*
|
|
@@ -19,15 +52,20 @@ const SKILL_EXECUTE_ENVELOPE_KEYS = new Set(["tool", "input", "activity"]);
|
|
|
19
52
|
* Weaker models routinely misplace the parameters. Left unhandled, the inner
|
|
20
53
|
* tool receives `{}`, fails schema validation ("<field> is required"), and the
|
|
21
54
|
* model retries the identical malformed call until it gives up — the empty-
|
|
22
|
-
* input retry loop.
|
|
55
|
+
* input retry loop. Three common misplacements are rescued so the call can
|
|
23
56
|
* succeed instead:
|
|
24
57
|
*
|
|
25
58
|
* 1. `input` passed as a JSON-encoded string instead of an object.
|
|
26
59
|
* 2. Parameters spread as top-level siblings of `tool`/`activity`, with `input`
|
|
27
60
|
* absent or an empty object.
|
|
61
|
+
* 3. The sole required field's value passed bare as `input` (a non-JSON string)
|
|
62
|
+
* — e.g. the full Markdown body as `input` instead of `{ "content": "..." }`.
|
|
63
|
+
* Rescued only when `innerSchema` has exactly one required string field, so
|
|
64
|
+
* the mapping is unambiguous.
|
|
28
65
|
*/
|
|
29
66
|
export function resolveSkillExecuteInput(
|
|
30
67
|
envelope: Record<string, unknown>,
|
|
68
|
+
innerSchema?: unknown,
|
|
31
69
|
): Record<string, unknown> {
|
|
32
70
|
const raw = envelope.input;
|
|
33
71
|
|
|
@@ -48,7 +86,14 @@ export function resolveSkillExecuteInput(
|
|
|
48
86
|
return parsed as Record<string, unknown>;
|
|
49
87
|
}
|
|
50
88
|
} catch {
|
|
51
|
-
// Not JSON
|
|
89
|
+
// Not JSON. A weak model may have placed the inner tool's sole required
|
|
90
|
+
// string value directly as `input` (e.g. the full Markdown body as
|
|
91
|
+
// `document_update`'s `content`) instead of a `{ "content": "..." }`
|
|
92
|
+
// object. When the inner tool has exactly one required string field, map
|
|
93
|
+
// the bare string onto it rather than discarding content the model
|
|
94
|
+
// actually produced.
|
|
95
|
+
const field = soleRequiredStringField(innerSchema);
|
|
96
|
+
if (field) return { [field]: raw };
|
|
52
97
|
}
|
|
53
98
|
}
|
|
54
99
|
|
|
@@ -62,6 +107,25 @@ export function resolveSkillExecuteInput(
|
|
|
62
107
|
return {};
|
|
63
108
|
}
|
|
64
109
|
|
|
110
|
+
/**
|
|
111
|
+
* The single required string property of an inner tool's input schema, or
|
|
112
|
+
* `null` when the schema has zero or more than one required field, or its lone
|
|
113
|
+
* required field is not a string. Used to map a bare `input` string onto the
|
|
114
|
+
* one field it can unambiguously belong to.
|
|
115
|
+
*/
|
|
116
|
+
function soleRequiredStringField(innerSchema: unknown): string | null {
|
|
117
|
+
if (innerSchema == null || typeof innerSchema !== "object") return null;
|
|
118
|
+
const schema = innerSchema as {
|
|
119
|
+
required?: unknown;
|
|
120
|
+
properties?: Record<string, { type?: unknown } | undefined>;
|
|
121
|
+
};
|
|
122
|
+
const required = Array.isArray(schema.required) ? schema.required : [];
|
|
123
|
+
if (required.length !== 1) return null;
|
|
124
|
+
const field = required[0];
|
|
125
|
+
if (typeof field !== "string") return null;
|
|
126
|
+
return schema.properties?.[field]?.type === "string" ? field : null;
|
|
127
|
+
}
|
|
128
|
+
|
|
65
129
|
/**
|
|
66
130
|
* Augment an inner-tool error with `skill_execute` envelope guidance when the
|
|
67
131
|
* call carried no inner parameters.
|
package/src/tools/skills/load.ts
CHANGED
|
@@ -39,6 +39,17 @@ const INLINE_COMMAND_ELIGIBLE_SOURCES = new Set([
|
|
|
39
39
|
"workspace",
|
|
40
40
|
]);
|
|
41
41
|
|
|
42
|
+
/** Matches raw `` !`...` `` inline command tokens in a skill body. */
|
|
43
|
+
const INLINE_COMMAND_TOKEN_PATTERN = /!`[^`]*`/g;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Replacement for inline command tokens when they are not rendered during
|
|
47
|
+
* disk-pressure cleanup mode — keeps the raw tokens out of the prompt without
|
|
48
|
+
* executing any shell.
|
|
49
|
+
*/
|
|
50
|
+
const INLINE_COMMAND_CLEANUP_STUB =
|
|
51
|
+
"[inline command skipped: storage cleanup mode]";
|
|
52
|
+
|
|
42
53
|
const log = getLogger("skill-load");
|
|
43
54
|
|
|
44
55
|
/**
|
|
@@ -159,11 +170,18 @@ export const skillLoadTool = {
|
|
|
159
170
|
};
|
|
160
171
|
}
|
|
161
172
|
|
|
173
|
+
// During disk-pressure cleanup mode, skill_load must not produce side
|
|
174
|
+
// effects: no auto-install (workspace writes / `bun install`) and no inline
|
|
175
|
+
// command execution. Instructions are still returned so the assistant can
|
|
176
|
+
// load the system-storage-cleanup skill (and any already-installed skill).
|
|
177
|
+
const cleanupMode = context.diskPressureCleanupModeActive === true;
|
|
178
|
+
|
|
162
179
|
let loaded = loadSkillBySelector(selector);
|
|
163
180
|
|
|
164
181
|
// Auto-install from catalog if the skill isn't found locally
|
|
165
182
|
if (
|
|
166
183
|
!loaded.skill &&
|
|
184
|
+
!cleanupMode &&
|
|
167
185
|
(loaded.errorCode === "not_found" || loaded.errorCode === "empty_catalog")
|
|
168
186
|
) {
|
|
169
187
|
try {
|
|
@@ -221,6 +239,10 @@ export const skillLoadTool = {
|
|
|
221
239
|
const missing = collectAllMissing(skill.id, catalogIndex);
|
|
222
240
|
if (missing.size === 0) break;
|
|
223
241
|
|
|
242
|
+
// Under the disk-pressure lock, never auto-install missing includes
|
|
243
|
+
// (that writes to the workspace). Leave them advisory ("not loaded").
|
|
244
|
+
if (cleanupMode) break;
|
|
245
|
+
|
|
224
246
|
// Lazily resolve catalog on first round with missing includes
|
|
225
247
|
if (!remoteCatalog) {
|
|
226
248
|
try {
|
|
@@ -289,7 +311,19 @@ export const skillLoadTool = {
|
|
|
289
311
|
const hasInlineCommands =
|
|
290
312
|
skill.inlineCommandExpansions && skill.inlineCommandExpansions.length > 0;
|
|
291
313
|
|
|
292
|
-
if (hasInlineCommands) {
|
|
314
|
+
if (hasInlineCommands && cleanupMode) {
|
|
315
|
+
// Under the disk-pressure lock, loading a skill must not execute shell.
|
|
316
|
+
// Strip inline command tokens instead of rendering them; the rest of the
|
|
317
|
+
// instructions are still returned.
|
|
318
|
+
body = body.replace(
|
|
319
|
+
INLINE_COMMAND_TOKEN_PATTERN,
|
|
320
|
+
INLINE_COMMAND_CLEANUP_STUB,
|
|
321
|
+
);
|
|
322
|
+
log.info(
|
|
323
|
+
{ skillId: skill.id },
|
|
324
|
+
"Skipped inline command expansion during disk pressure cleanup mode",
|
|
325
|
+
);
|
|
326
|
+
} else if (hasInlineCommands) {
|
|
293
327
|
if (skill.source === "extra" || skill.source === "plugin") {
|
|
294
328
|
// Third-party skill roots — `extra` dirs and skills shipped inside
|
|
295
329
|
// installed plugins — are out of scope for inline command expansion.
|
|
@@ -368,7 +402,14 @@ export const skillLoadTool = {
|
|
|
368
402
|
childLoaded.skill.inlineCommandExpansions &&
|
|
369
403
|
childLoaded.skill.inlineCommandExpansions.length > 0;
|
|
370
404
|
|
|
371
|
-
if (childHasInlineCommands) {
|
|
405
|
+
if (childHasInlineCommands && cleanupMode) {
|
|
406
|
+
// No shell execution under the disk-pressure lock — strip the
|
|
407
|
+
// child's inline command tokens rather than rendering them.
|
|
408
|
+
childBody = childBody.replace(
|
|
409
|
+
INLINE_COMMAND_TOKEN_PATTERN,
|
|
410
|
+
INLINE_COMMAND_CLEANUP_STUB,
|
|
411
|
+
);
|
|
412
|
+
} else if (childHasInlineCommands) {
|
|
372
413
|
if (
|
|
373
414
|
childLoaded.skill.source === "extra" ||
|
|
374
415
|
childLoaded.skill.source === "plugin"
|
|
@@ -46,7 +46,12 @@ export function createSkillTool(
|
|
|
46
46
|
context: ToolContext,
|
|
47
47
|
): Promise<ToolExecutionResult> {
|
|
48
48
|
const schema = entry.input_schema as Record<string, unknown> | undefined;
|
|
49
|
-
|
|
49
|
+
// `activity` is a harness field (the skill_execute envelope and
|
|
50
|
+
// first-class skill-tool exposure both surface it for progress display),
|
|
51
|
+
// never an inner tool parameter. Strip it before validation so a model
|
|
52
|
+
// that includes it on a direct call isn't rejected for an unknown field.
|
|
53
|
+
const { activity: _activity, ...rest } = input;
|
|
54
|
+
const coercedInput = coerceStringBooleans(rest, schema);
|
|
50
55
|
const validation = validateInputAgainstSchema(
|
|
51
56
|
entry.name,
|
|
52
57
|
coercedInput,
|