opencode-swarm-plugin 0.44.0 → 0.44.2
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/bin/swarm.serve.test.ts +6 -4
- package/bin/swarm.ts +18 -12
- package/dist/compaction-prompt-scoring.js +139 -0
- package/dist/eval-capture.js +12811 -0
- package/dist/hive.d.ts.map +1 -1
- package/dist/hive.js +14834 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7743 -62593
- package/dist/plugin.js +24052 -78907
- package/dist/swarm-orchestrate.d.ts.map +1 -1
- package/dist/swarm-prompts.d.ts.map +1 -1
- package/dist/swarm-prompts.js +39407 -0
- package/dist/swarm-review.d.ts.map +1 -1
- package/dist/swarm-validation.d.ts +127 -0
- package/dist/swarm-validation.d.ts.map +1 -0
- package/dist/validators/index.d.ts +7 -0
- package/dist/validators/index.d.ts.map +1 -0
- package/dist/validators/schema-validator.d.ts +58 -0
- package/dist/validators/schema-validator.d.ts.map +1 -0
- package/package.json +17 -5
- package/.changeset/swarm-insights-data-layer.md +0 -63
- package/.hive/analysis/eval-failure-analysis-2025-12-25.md +0 -331
- package/.hive/analysis/session-data-quality-audit.md +0 -320
- package/.hive/eval-results.json +0 -483
- package/.hive/issues.jsonl +0 -138
- package/.hive/memories.jsonl +0 -729
- package/.opencode/eval-history.jsonl +0 -327
- package/.turbo/turbo-build.log +0 -9
- package/CHANGELOG.md +0 -2286
- package/SCORER-ANALYSIS.md +0 -598
- package/docs/analysis/subagent-coordination-patterns.md +0 -902
- package/docs/analysis-socratic-planner-pattern.md +0 -504
- package/docs/planning/ADR-001-monorepo-structure.md +0 -171
- package/docs/planning/ADR-002-package-extraction.md +0 -393
- package/docs/planning/ADR-003-performance-improvements.md +0 -451
- package/docs/planning/ADR-004-message-queue-features.md +0 -187
- package/docs/planning/ADR-005-devtools-observability.md +0 -202
- package/docs/planning/ADR-007-swarm-enhancements-worktree-review.md +0 -168
- package/docs/planning/ADR-008-worker-handoff-protocol.md +0 -293
- package/docs/planning/ADR-009-oh-my-opencode-patterns.md +0 -353
- package/docs/planning/ADR-010-cass-inhousing.md +0 -1215
- package/docs/planning/ROADMAP.md +0 -368
- package/docs/semantic-memory-cli-syntax.md +0 -123
- package/docs/swarm-mail-architecture.md +0 -1147
- package/docs/testing/context-recovery-test.md +0 -470
- package/evals/ARCHITECTURE.md +0 -1189
- package/evals/README.md +0 -768
- package/evals/compaction-prompt.eval.ts +0 -149
- package/evals/compaction-resumption.eval.ts +0 -289
- package/evals/coordinator-behavior.eval.ts +0 -307
- package/evals/coordinator-session.eval.ts +0 -154
- package/evals/evalite.config.ts.bak +0 -15
- package/evals/example.eval.ts +0 -31
- package/evals/fixtures/cass-baseline.ts +0 -217
- package/evals/fixtures/compaction-cases.ts +0 -350
- package/evals/fixtures/compaction-prompt-cases.ts +0 -311
- package/evals/fixtures/coordinator-sessions.ts +0 -328
- package/evals/fixtures/decomposition-cases.ts +0 -105
- package/evals/lib/compaction-loader.test.ts +0 -248
- package/evals/lib/compaction-loader.ts +0 -320
- package/evals/lib/data-loader.evalite-test.ts +0 -289
- package/evals/lib/data-loader.test.ts +0 -345
- package/evals/lib/data-loader.ts +0 -281
- package/evals/lib/llm.ts +0 -115
- package/evals/scorers/compaction-prompt-scorers.ts +0 -145
- package/evals/scorers/compaction-scorers.ts +0 -305
- package/evals/scorers/coordinator-discipline.evalite-test.ts +0 -539
- package/evals/scorers/coordinator-discipline.ts +0 -325
- package/evals/scorers/index.test.ts +0 -146
- package/evals/scorers/index.ts +0 -328
- package/evals/scorers/outcome-scorers.evalite-test.ts +0 -27
- package/evals/scorers/outcome-scorers.ts +0 -349
- package/evals/swarm-decomposition.eval.ts +0 -121
- package/examples/commands/swarm.md +0 -745
- package/examples/plugin-wrapper-template.ts +0 -2515
- package/examples/skills/hive-workflow/SKILL.md +0 -212
- package/examples/skills/skill-creator/SKILL.md +0 -223
- package/examples/skills/swarm-coordination/SKILL.md +0 -292
- package/global-skills/cli-builder/SKILL.md +0 -344
- package/global-skills/cli-builder/references/advanced-patterns.md +0 -244
- package/global-skills/learning-systems/SKILL.md +0 -644
- package/global-skills/skill-creator/LICENSE.txt +0 -202
- package/global-skills/skill-creator/SKILL.md +0 -352
- package/global-skills/skill-creator/references/output-patterns.md +0 -82
- package/global-skills/skill-creator/references/workflows.md +0 -28
- package/global-skills/swarm-coordination/SKILL.md +0 -995
- package/global-skills/swarm-coordination/references/coordinator-patterns.md +0 -235
- package/global-skills/swarm-coordination/references/strategies.md +0 -138
- package/global-skills/system-design/SKILL.md +0 -213
- package/global-skills/testing-patterns/SKILL.md +0 -430
- package/global-skills/testing-patterns/references/dependency-breaking-catalog.md +0 -586
- package/opencode-swarm-plugin-0.30.7.tgz +0 -0
- package/opencode-swarm-plugin-0.31.0.tgz +0 -0
- package/scripts/cleanup-test-memories.ts +0 -346
- package/scripts/init-skill.ts +0 -222
- package/scripts/migrate-unknown-sessions.ts +0 -349
- package/scripts/validate-skill.ts +0 -204
- package/src/agent-mail.ts +0 -1724
- package/src/anti-patterns.test.ts +0 -1167
- package/src/anti-patterns.ts +0 -448
- package/src/compaction-capture.integration.test.ts +0 -257
- package/src/compaction-hook.test.ts +0 -838
- package/src/compaction-hook.ts +0 -1204
- package/src/compaction-observability.integration.test.ts +0 -139
- package/src/compaction-observability.test.ts +0 -187
- package/src/compaction-observability.ts +0 -324
- package/src/compaction-prompt-scorers.test.ts +0 -475
- package/src/compaction-prompt-scoring.ts +0 -300
- package/src/contributor-tools.test.ts +0 -133
- package/src/contributor-tools.ts +0 -201
- package/src/dashboard.test.ts +0 -611
- package/src/dashboard.ts +0 -462
- package/src/error-enrichment.test.ts +0 -403
- package/src/error-enrichment.ts +0 -219
- package/src/eval-capture.test.ts +0 -1015
- package/src/eval-capture.ts +0 -929
- package/src/eval-gates.test.ts +0 -306
- package/src/eval-gates.ts +0 -218
- package/src/eval-history.test.ts +0 -508
- package/src/eval-history.ts +0 -214
- package/src/eval-learning.test.ts +0 -378
- package/src/eval-learning.ts +0 -360
- package/src/eval-runner.test.ts +0 -223
- package/src/eval-runner.ts +0 -402
- package/src/export-tools.test.ts +0 -476
- package/src/export-tools.ts +0 -257
- package/src/hive.integration.test.ts +0 -2241
- package/src/hive.ts +0 -1628
- package/src/index.ts +0 -940
- package/src/learning.integration.test.ts +0 -1815
- package/src/learning.ts +0 -1079
- package/src/logger.test.ts +0 -189
- package/src/logger.ts +0 -135
- package/src/mandate-promotion.test.ts +0 -473
- package/src/mandate-promotion.ts +0 -239
- package/src/mandate-storage.integration.test.ts +0 -601
- package/src/mandate-storage.test.ts +0 -578
- package/src/mandate-storage.ts +0 -794
- package/src/mandates.ts +0 -540
- package/src/memory-tools.test.ts +0 -195
- package/src/memory-tools.ts +0 -344
- package/src/memory.integration.test.ts +0 -334
- package/src/memory.test.ts +0 -158
- package/src/memory.ts +0 -527
- package/src/model-selection.test.ts +0 -188
- package/src/model-selection.ts +0 -68
- package/src/observability-tools.test.ts +0 -359
- package/src/observability-tools.ts +0 -871
- package/src/output-guardrails.test.ts +0 -438
- package/src/output-guardrails.ts +0 -381
- package/src/pattern-maturity.test.ts +0 -1160
- package/src/pattern-maturity.ts +0 -525
- package/src/planning-guardrails.test.ts +0 -491
- package/src/planning-guardrails.ts +0 -438
- package/src/plugin.ts +0 -23
- package/src/post-compaction-tracker.test.ts +0 -251
- package/src/post-compaction-tracker.ts +0 -237
- package/src/query-tools.test.ts +0 -636
- package/src/query-tools.ts +0 -324
- package/src/rate-limiter.integration.test.ts +0 -466
- package/src/rate-limiter.ts +0 -774
- package/src/replay-tools.test.ts +0 -496
- package/src/replay-tools.ts +0 -240
- package/src/repo-crawl.integration.test.ts +0 -441
- package/src/repo-crawl.ts +0 -610
- package/src/schemas/cell-events.test.ts +0 -347
- package/src/schemas/cell-events.ts +0 -807
- package/src/schemas/cell.ts +0 -257
- package/src/schemas/evaluation.ts +0 -166
- package/src/schemas/index.test.ts +0 -199
- package/src/schemas/index.ts +0 -286
- package/src/schemas/mandate.ts +0 -232
- package/src/schemas/swarm-context.ts +0 -115
- package/src/schemas/task.ts +0 -161
- package/src/schemas/worker-handoff.test.ts +0 -302
- package/src/schemas/worker-handoff.ts +0 -131
- package/src/sessions/agent-discovery.test.ts +0 -137
- package/src/sessions/agent-discovery.ts +0 -112
- package/src/sessions/index.ts +0 -15
- package/src/skills.integration.test.ts +0 -1192
- package/src/skills.test.ts +0 -643
- package/src/skills.ts +0 -1549
- package/src/storage.integration.test.ts +0 -341
- package/src/storage.ts +0 -884
- package/src/structured.integration.test.ts +0 -817
- package/src/structured.test.ts +0 -1046
- package/src/structured.ts +0 -762
- package/src/swarm-decompose.test.ts +0 -188
- package/src/swarm-decompose.ts +0 -1302
- package/src/swarm-deferred.integration.test.ts +0 -157
- package/src/swarm-deferred.test.ts +0 -38
- package/src/swarm-insights.test.ts +0 -214
- package/src/swarm-insights.ts +0 -459
- package/src/swarm-mail.integration.test.ts +0 -970
- package/src/swarm-mail.ts +0 -739
- package/src/swarm-orchestrate.integration.test.ts +0 -282
- package/src/swarm-orchestrate.test.ts +0 -548
- package/src/swarm-orchestrate.ts +0 -3084
- package/src/swarm-prompts.test.ts +0 -1270
- package/src/swarm-prompts.ts +0 -2077
- package/src/swarm-research.integration.test.ts +0 -701
- package/src/swarm-research.test.ts +0 -698
- package/src/swarm-research.ts +0 -472
- package/src/swarm-review.integration.test.ts +0 -285
- package/src/swarm-review.test.ts +0 -879
- package/src/swarm-review.ts +0 -709
- package/src/swarm-strategies.ts +0 -407
- package/src/swarm-worktree.test.ts +0 -501
- package/src/swarm-worktree.ts +0 -575
- package/src/swarm.integration.test.ts +0 -2377
- package/src/swarm.ts +0 -38
- package/src/tool-adapter.integration.test.ts +0 -1221
- package/src/tool-availability.ts +0 -461
- package/tsconfig.json +0 -28
|
@@ -1,1192 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Skills Integration Tests
|
|
3
|
-
*
|
|
4
|
-
* Tests all skills_* tools with real filesystem operations.
|
|
5
|
-
* These are happy-path integration tests verifying tools work end-to-end.
|
|
6
|
-
*
|
|
7
|
-
* Tools under test:
|
|
8
|
-
* - skills_list
|
|
9
|
-
* - skills_read
|
|
10
|
-
* - skills_use
|
|
11
|
-
* - skills_create
|
|
12
|
-
* - skills_update
|
|
13
|
-
* - skills_delete
|
|
14
|
-
* - skills_init
|
|
15
|
-
* - skills_add_script
|
|
16
|
-
* - skills_execute
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { describe, expect, it, afterAll, beforeEach, vi } from "vitest";
|
|
20
|
-
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
21
|
-
import { join } from "node:path";
|
|
22
|
-
import {
|
|
23
|
-
skills_list,
|
|
24
|
-
skills_read,
|
|
25
|
-
skills_use,
|
|
26
|
-
skills_create,
|
|
27
|
-
skills_update,
|
|
28
|
-
skills_delete,
|
|
29
|
-
skills_init,
|
|
30
|
-
skills_add_script,
|
|
31
|
-
skills_execute,
|
|
32
|
-
setSkillsProjectDirectory,
|
|
33
|
-
invalidateSkillsCache,
|
|
34
|
-
} from "./skills";
|
|
35
|
-
|
|
36
|
-
// =============================================================================
|
|
37
|
-
// Test Setup
|
|
38
|
-
// =============================================================================
|
|
39
|
-
|
|
40
|
-
const TEST_RUN_ID = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
41
|
-
const TEST_DIR = join(process.cwd(), `.test-skills-integration-${TEST_RUN_ID}`);
|
|
42
|
-
const SKILLS_DIR = join(TEST_DIR, ".opencode", "skills");
|
|
43
|
-
|
|
44
|
-
function cleanupTestDir() {
|
|
45
|
-
if (existsSync(TEST_DIR)) {
|
|
46
|
-
rmSync(TEST_DIR, { recursive: true, force: true });
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function setupTestDir() {
|
|
51
|
-
cleanupTestDir();
|
|
52
|
-
mkdirSync(SKILLS_DIR, { recursive: true });
|
|
53
|
-
setSkillsProjectDirectory(TEST_DIR);
|
|
54
|
-
invalidateSkillsCache();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// =============================================================================
|
|
58
|
-
// skills_list Tool
|
|
59
|
-
// =============================================================================
|
|
60
|
-
|
|
61
|
-
describe("skills_list tool", () => {
|
|
62
|
-
beforeEach(() => {
|
|
63
|
-
setupTestDir();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
afterAll(() => {
|
|
67
|
-
cleanupTestDir();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("should list empty skills directory", async () => {
|
|
71
|
-
const result = await skills_list.execute({});
|
|
72
|
-
|
|
73
|
-
// May find global skills, so just verify it doesn't error
|
|
74
|
-
expect(result).toBeDefined();
|
|
75
|
-
expect(typeof result).toBe("string");
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("should list discovered skills with metadata", async () => {
|
|
79
|
-
// Create a test skill first
|
|
80
|
-
await skills_create.execute({
|
|
81
|
-
name: "test-skill",
|
|
82
|
-
description: "Use when testing - this is a test skill",
|
|
83
|
-
body: "# Test Instructions\n\nDo the thing.",
|
|
84
|
-
tags: ["testing"],
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
invalidateSkillsCache();
|
|
88
|
-
const result = await skills_list.execute({});
|
|
89
|
-
|
|
90
|
-
// Should include our test skill (may include global skills too)
|
|
91
|
-
expect(result).toContain("test-skill");
|
|
92
|
-
expect(result).toContain("Use when testing");
|
|
93
|
-
expect(result).toContain("(testing)");
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("should filter skills by tag", async () => {
|
|
97
|
-
await skills_create.execute({
|
|
98
|
-
name: "skill-a",
|
|
99
|
-
description: "Use when A",
|
|
100
|
-
body: "A",
|
|
101
|
-
tags: ["frontend"],
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
await skills_create.execute({
|
|
105
|
-
name: "skill-b",
|
|
106
|
-
description: "Use when B",
|
|
107
|
-
body: "B",
|
|
108
|
-
tags: ["backend"],
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
invalidateSkillsCache();
|
|
112
|
-
const result = await skills_list.execute({ tag: "frontend" });
|
|
113
|
-
|
|
114
|
-
expect(result).toContain("skill-a");
|
|
115
|
-
expect(result).not.toContain("skill-b");
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("should show [has scripts] indicator", async () => {
|
|
119
|
-
await skills_create.execute({
|
|
120
|
-
name: "with-scripts",
|
|
121
|
-
description: "Use when scripting",
|
|
122
|
-
body: "Scripts",
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
await skills_add_script.execute({
|
|
126
|
-
skill: "with-scripts",
|
|
127
|
-
script_name: "helper.sh",
|
|
128
|
-
content: "#!/bin/bash\necho hi",
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
invalidateSkillsCache();
|
|
132
|
-
const result = await skills_list.execute({});
|
|
133
|
-
|
|
134
|
-
expect(result).toContain("with-scripts");
|
|
135
|
-
expect(result).toContain("[has scripts]");
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// =============================================================================
|
|
140
|
-
// skills_use Tool
|
|
141
|
-
// =============================================================================
|
|
142
|
-
|
|
143
|
-
describe("skills_use tool", () => {
|
|
144
|
-
beforeEach(() => {
|
|
145
|
-
setupTestDir();
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
afterAll(() => {
|
|
149
|
-
cleanupTestDir();
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it("should activate a skill and return full content", async () => {
|
|
153
|
-
const body = "# Test Skill\n\nThese are the instructions.";
|
|
154
|
-
await skills_create.execute({
|
|
155
|
-
name: "test-skill",
|
|
156
|
-
description: "Use when testing",
|
|
157
|
-
body,
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
invalidateSkillsCache();
|
|
161
|
-
const result = await skills_use.execute({ name: "test-skill" });
|
|
162
|
-
|
|
163
|
-
expect(result).toContain("# Skill: test-skill");
|
|
164
|
-
expect(result).toContain(body);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it("should list available scripts when skill has them", async () => {
|
|
168
|
-
await skills_create.execute({
|
|
169
|
-
name: "scripted-skill",
|
|
170
|
-
description: "Use when scripting",
|
|
171
|
-
body: "Instructions",
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
await skills_add_script.execute({
|
|
175
|
-
skill: "scripted-skill",
|
|
176
|
-
script_name: "setup.sh",
|
|
177
|
-
content: "#!/bin/bash\necho setup",
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
invalidateSkillsCache();
|
|
181
|
-
const result = await skills_use.execute({ name: "scripted-skill" });
|
|
182
|
-
|
|
183
|
-
expect(result).toContain("Available Scripts");
|
|
184
|
-
expect(result).toContain("setup.sh");
|
|
185
|
-
expect(result).toContain("skills_execute");
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it("should exclude scripts when include_scripts=false", async () => {
|
|
189
|
-
await skills_create.execute({
|
|
190
|
-
name: "scripted-skill",
|
|
191
|
-
description: "Use when scripting",
|
|
192
|
-
body: "Instructions",
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
await skills_add_script.execute({
|
|
196
|
-
skill: "scripted-skill",
|
|
197
|
-
script_name: "setup.sh",
|
|
198
|
-
content: "#!/bin/bash\necho setup",
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
invalidateSkillsCache();
|
|
202
|
-
const result = await skills_use.execute({
|
|
203
|
-
name: "scripted-skill",
|
|
204
|
-
include_scripts: false,
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
expect(result).not.toContain("Available Scripts");
|
|
208
|
-
expect(result).not.toContain("setup.sh");
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it("should return error for non-existent skill", async () => {
|
|
212
|
-
const result = await skills_use.execute({ name: "non-existent" });
|
|
213
|
-
|
|
214
|
-
expect(result).toContain("not found");
|
|
215
|
-
expect(result).toContain("Available skills:");
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
// =============================================================================
|
|
220
|
-
// skills_read Tool
|
|
221
|
-
// =============================================================================
|
|
222
|
-
|
|
223
|
-
describe("skills_read tool", () => {
|
|
224
|
-
beforeEach(() => {
|
|
225
|
-
setupTestDir();
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
afterAll(() => {
|
|
229
|
-
cleanupTestDir();
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it("should read a resource file from skill directory", async () => {
|
|
233
|
-
await skills_create.execute({
|
|
234
|
-
name: "documented-skill",
|
|
235
|
-
description: "Use when documenting",
|
|
236
|
-
body: "Instructions",
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
// Manually create a reference file
|
|
240
|
-
const skillDir = join(SKILLS_DIR, "documented-skill");
|
|
241
|
-
const exampleContent = "# Examples\n\nExample content here.";
|
|
242
|
-
writeFileSync(join(skillDir, "examples.md"), exampleContent);
|
|
243
|
-
|
|
244
|
-
const result = await skills_read.execute({
|
|
245
|
-
skill: "documented-skill",
|
|
246
|
-
file: "examples.md",
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
expect(result).toBe(exampleContent);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
it("should prevent path traversal attacks", async () => {
|
|
253
|
-
await skills_create.execute({
|
|
254
|
-
name: "secure-skill",
|
|
255
|
-
description: "Use when securing",
|
|
256
|
-
body: "Secure",
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
const maliciousPaths = [
|
|
260
|
-
"../../../etc/passwd",
|
|
261
|
-
"../../..",
|
|
262
|
-
"/etc/passwd",
|
|
263
|
-
"..\\..\\windows\\system32",
|
|
264
|
-
];
|
|
265
|
-
|
|
266
|
-
for (const path of maliciousPaths) {
|
|
267
|
-
const result = await skills_read.execute({
|
|
268
|
-
skill: "secure-skill",
|
|
269
|
-
file: path,
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
expect(result).toContain("Invalid file path");
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
it("should return error for non-existent skill", async () => {
|
|
277
|
-
const result = await skills_read.execute({
|
|
278
|
-
skill: "non-existent",
|
|
279
|
-
file: "anything.md",
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
expect(result).toContain("not found");
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
it("should return error for non-existent file", async () => {
|
|
286
|
-
await skills_create.execute({
|
|
287
|
-
name: "empty-skill",
|
|
288
|
-
description: "Use when empty",
|
|
289
|
-
body: "Empty",
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
const result = await skills_read.execute({
|
|
293
|
-
skill: "empty-skill",
|
|
294
|
-
file: "non-existent.md",
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
expect(result).toContain("Failed to read");
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
// =============================================================================
|
|
302
|
-
// skills_create Tool
|
|
303
|
-
// =============================================================================
|
|
304
|
-
|
|
305
|
-
describe("skills_create tool", () => {
|
|
306
|
-
beforeEach(() => {
|
|
307
|
-
setupTestDir();
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
afterAll(() => {
|
|
311
|
-
cleanupTestDir();
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
it("should create a new skill with minimal fields", async () => {
|
|
315
|
-
const result = await skills_create.execute({
|
|
316
|
-
name: "minimal-skill",
|
|
317
|
-
description: "Use when minimal",
|
|
318
|
-
body: "# Minimal\n\nInstructions here.",
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
const parsed = JSON.parse(result);
|
|
322
|
-
expect(parsed.success).toBe(true);
|
|
323
|
-
expect(parsed.skill).toBe("minimal-skill");
|
|
324
|
-
expect(parsed.path).toContain("minimal-skill");
|
|
325
|
-
|
|
326
|
-
// Verify file exists
|
|
327
|
-
const skillPath = join(SKILLS_DIR, "minimal-skill", "SKILL.md");
|
|
328
|
-
expect(existsSync(skillPath)).toBe(true);
|
|
329
|
-
|
|
330
|
-
// Verify content (description may or may not be quoted depending on content)
|
|
331
|
-
const content = readFileSync(skillPath, "utf-8");
|
|
332
|
-
expect(content).toContain("name: minimal-skill");
|
|
333
|
-
expect(content).toContain("Use when minimal"); // Either quoted or unquoted
|
|
334
|
-
expect(content).toContain("# Minimal");
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
it("should create skill with tags and tools", async () => {
|
|
338
|
-
const result = await skills_create.execute({
|
|
339
|
-
name: "full-skill",
|
|
340
|
-
description: "Use when full",
|
|
341
|
-
body: "Full body",
|
|
342
|
-
tags: ["testing", "automation"],
|
|
343
|
-
tools: ["Read", "Write", "Bash"],
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
const parsed = JSON.parse(result);
|
|
347
|
-
expect(parsed.success).toBe(true);
|
|
348
|
-
|
|
349
|
-
const skillPath = join(SKILLS_DIR, "full-skill", "SKILL.md");
|
|
350
|
-
const content = readFileSync(skillPath, "utf-8");
|
|
351
|
-
|
|
352
|
-
expect(content).toContain("tags:");
|
|
353
|
-
expect(content).toContain("- testing");
|
|
354
|
-
expect(content).toContain("- automation");
|
|
355
|
-
expect(content).toContain("tools:");
|
|
356
|
-
expect(content).toContain("- Read");
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
it("should return CSO warnings for non-compliant metadata", async () => {
|
|
360
|
-
const result = await skills_create.execute({
|
|
361
|
-
name: "bad-skill",
|
|
362
|
-
description: "I can help you with testing", // First-person, no "Use when"
|
|
363
|
-
body: "Body",
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
const parsed = JSON.parse(result);
|
|
367
|
-
expect(parsed.success).toBe(true); // Still creates, just warns
|
|
368
|
-
expect(parsed.cso_warnings).toBeDefined();
|
|
369
|
-
expect(parsed.cso_warnings).toContain("first-person");
|
|
370
|
-
expect(parsed.cso_warnings).toContain("Use when");
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
it("should prevent duplicate skill creation", async () => {
|
|
374
|
-
await skills_create.execute({
|
|
375
|
-
name: "duplicate-skill",
|
|
376
|
-
description: "Use when duplicating",
|
|
377
|
-
body: "First",
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
invalidateSkillsCache();
|
|
381
|
-
|
|
382
|
-
const result = await skills_create.execute({
|
|
383
|
-
name: "duplicate-skill",
|
|
384
|
-
description: "Use when duplicating again",
|
|
385
|
-
body: "Second",
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
expect(result).toContain("already exists");
|
|
389
|
-
expect(result).toContain("skills_update");
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
it("should invalidate cache after creation", async () => {
|
|
393
|
-
await skills_create.execute({
|
|
394
|
-
name: "cache-test",
|
|
395
|
-
description: "Use when caching",
|
|
396
|
-
body: "Cache",
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
// Should be immediately discoverable without manual cache clear
|
|
400
|
-
const skill = await skills_list.execute({});
|
|
401
|
-
expect(skill).toContain("cache-test");
|
|
402
|
-
});
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
// =============================================================================
|
|
406
|
-
// skills_update Tool
|
|
407
|
-
// =============================================================================
|
|
408
|
-
|
|
409
|
-
describe("skills_update tool", () => {
|
|
410
|
-
beforeEach(() => {
|
|
411
|
-
setupTestDir();
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
afterAll(() => {
|
|
415
|
-
cleanupTestDir();
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
it("should update skill description", async () => {
|
|
419
|
-
await skills_create.execute({
|
|
420
|
-
name: "update-test",
|
|
421
|
-
description: "Use when old",
|
|
422
|
-
body: "Old body",
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
invalidateSkillsCache();
|
|
426
|
-
|
|
427
|
-
const result = await skills_update.execute({
|
|
428
|
-
name: "update-test",
|
|
429
|
-
description: "Use when new",
|
|
430
|
-
});
|
|
431
|
-
|
|
432
|
-
const parsed = JSON.parse(result);
|
|
433
|
-
expect(parsed.success).toBe(true);
|
|
434
|
-
expect(parsed.updated.description).toBe(true);
|
|
435
|
-
|
|
436
|
-
const skillPath = join(SKILLS_DIR, "update-test", "SKILL.md");
|
|
437
|
-
const content = readFileSync(skillPath, "utf-8");
|
|
438
|
-
expect(content).toContain("Use when new");
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
it("should update skill body with content parameter", async () => {
|
|
442
|
-
await skills_create.execute({
|
|
443
|
-
name: "body-test",
|
|
444
|
-
description: "Use when body",
|
|
445
|
-
body: "Old body",
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
invalidateSkillsCache();
|
|
449
|
-
|
|
450
|
-
const result = await skills_update.execute({
|
|
451
|
-
name: "body-test",
|
|
452
|
-
content: "New body content",
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
const parsed = JSON.parse(result);
|
|
456
|
-
expect(parsed.success).toBe(true);
|
|
457
|
-
expect(parsed.updated.content).toBe(true);
|
|
458
|
-
|
|
459
|
-
const skillPath = join(SKILLS_DIR, "body-test", "SKILL.md");
|
|
460
|
-
const content = readFileSync(skillPath, "utf-8");
|
|
461
|
-
expect(content).toContain("New body content");
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
it("should append to existing body", async () => {
|
|
465
|
-
await skills_create.execute({
|
|
466
|
-
name: "append-test",
|
|
467
|
-
description: "Use when appending",
|
|
468
|
-
body: "Original content",
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
invalidateSkillsCache();
|
|
472
|
-
|
|
473
|
-
const result = await skills_update.execute({
|
|
474
|
-
name: "append-test",
|
|
475
|
-
append_body: "\n\nAppended content",
|
|
476
|
-
});
|
|
477
|
-
|
|
478
|
-
const parsed = JSON.parse(result);
|
|
479
|
-
expect(parsed.success).toBe(true);
|
|
480
|
-
|
|
481
|
-
const skillPath = join(SKILLS_DIR, "append-test", "SKILL.md");
|
|
482
|
-
const content = readFileSync(skillPath, "utf-8");
|
|
483
|
-
expect(content).toContain("Original content");
|
|
484
|
-
expect(content).toContain("Appended content");
|
|
485
|
-
});
|
|
486
|
-
|
|
487
|
-
it("should replace tags", async () => {
|
|
488
|
-
await skills_create.execute({
|
|
489
|
-
name: "tags-test",
|
|
490
|
-
description: "Use when tagging",
|
|
491
|
-
body: "Body",
|
|
492
|
-
tags: ["old", "tag"],
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
invalidateSkillsCache();
|
|
496
|
-
|
|
497
|
-
const result = await skills_update.execute({
|
|
498
|
-
name: "tags-test",
|
|
499
|
-
tags: ["new", "tags"],
|
|
500
|
-
});
|
|
501
|
-
|
|
502
|
-
const parsed = JSON.parse(result);
|
|
503
|
-
expect(parsed.success).toBe(true);
|
|
504
|
-
|
|
505
|
-
const skillPath = join(SKILLS_DIR, "tags-test", "SKILL.md");
|
|
506
|
-
const content = readFileSync(skillPath, "utf-8");
|
|
507
|
-
expect(content).toContain("- new");
|
|
508
|
-
expect(content).toContain("- tags");
|
|
509
|
-
expect(content).not.toContain("- old");
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
it("should add tags to existing", async () => {
|
|
513
|
-
await skills_create.execute({
|
|
514
|
-
name: "add-tags-test",
|
|
515
|
-
description: "Use when adding tags",
|
|
516
|
-
body: "Body",
|
|
517
|
-
tags: ["existing"],
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
invalidateSkillsCache();
|
|
521
|
-
|
|
522
|
-
const result = await skills_update.execute({
|
|
523
|
-
name: "add-tags-test",
|
|
524
|
-
add_tags: ["new", "additional"],
|
|
525
|
-
});
|
|
526
|
-
|
|
527
|
-
const parsed = JSON.parse(result);
|
|
528
|
-
expect(parsed.success).toBe(true);
|
|
529
|
-
|
|
530
|
-
const skillPath = join(SKILLS_DIR, "add-tags-test", "SKILL.md");
|
|
531
|
-
const content = readFileSync(skillPath, "utf-8");
|
|
532
|
-
expect(content).toContain("- existing");
|
|
533
|
-
expect(content).toContain("- new");
|
|
534
|
-
expect(content).toContain("- additional");
|
|
535
|
-
});
|
|
536
|
-
|
|
537
|
-
it("should deduplicate tags when adding", async () => {
|
|
538
|
-
await skills_create.execute({
|
|
539
|
-
name: "dedup-test",
|
|
540
|
-
description: "Use when deduping",
|
|
541
|
-
body: "Body",
|
|
542
|
-
tags: ["tag1"],
|
|
543
|
-
});
|
|
544
|
-
|
|
545
|
-
invalidateSkillsCache();
|
|
546
|
-
|
|
547
|
-
await skills_update.execute({
|
|
548
|
-
name: "dedup-test",
|
|
549
|
-
add_tags: ["tag1", "tag2"], // tag1 already exists
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
const skillPath = join(SKILLS_DIR, "dedup-test", "SKILL.md");
|
|
553
|
-
const content = readFileSync(skillPath, "utf-8");
|
|
554
|
-
|
|
555
|
-
// Count occurrences of "tag1"
|
|
556
|
-
const matches = content.match(/- tag1/g);
|
|
557
|
-
expect(matches?.length).toBe(1); // Should only appear once
|
|
558
|
-
});
|
|
559
|
-
|
|
560
|
-
it("should return error for non-existent skill", async () => {
|
|
561
|
-
const result = await skills_update.execute({
|
|
562
|
-
name: "non-existent",
|
|
563
|
-
description: "New desc",
|
|
564
|
-
});
|
|
565
|
-
|
|
566
|
-
expect(result).toContain("not found");
|
|
567
|
-
expect(result).toContain("Available:");
|
|
568
|
-
});
|
|
569
|
-
});
|
|
570
|
-
|
|
571
|
-
// =============================================================================
|
|
572
|
-
// skills_delete Tool
|
|
573
|
-
// =============================================================================
|
|
574
|
-
|
|
575
|
-
describe("skills_delete tool", () => {
|
|
576
|
-
beforeEach(() => {
|
|
577
|
-
setupTestDir();
|
|
578
|
-
});
|
|
579
|
-
|
|
580
|
-
afterAll(() => {
|
|
581
|
-
cleanupTestDir();
|
|
582
|
-
});
|
|
583
|
-
|
|
584
|
-
it("should delete a skill when confirm=true", async () => {
|
|
585
|
-
await skills_create.execute({
|
|
586
|
-
name: "delete-me",
|
|
587
|
-
description: "Use when deleting",
|
|
588
|
-
body: "Delete this",
|
|
589
|
-
});
|
|
590
|
-
|
|
591
|
-
const skillDir = join(SKILLS_DIR, "delete-me");
|
|
592
|
-
expect(existsSync(skillDir)).toBe(true);
|
|
593
|
-
|
|
594
|
-
const result = await skills_delete.execute({
|
|
595
|
-
name: "delete-me",
|
|
596
|
-
confirm: true,
|
|
597
|
-
});
|
|
598
|
-
|
|
599
|
-
const parsed = JSON.parse(result);
|
|
600
|
-
expect(parsed.success).toBe(true);
|
|
601
|
-
expect(parsed.skill).toBe("delete-me");
|
|
602
|
-
|
|
603
|
-
// Verify directory removed
|
|
604
|
-
expect(existsSync(skillDir)).toBe(false);
|
|
605
|
-
});
|
|
606
|
-
|
|
607
|
-
it("should refuse deletion without confirm", async () => {
|
|
608
|
-
await skills_create.execute({
|
|
609
|
-
name: "keep-me",
|
|
610
|
-
description: "Use when keeping",
|
|
611
|
-
body: "Keep this",
|
|
612
|
-
});
|
|
613
|
-
|
|
614
|
-
const result = await skills_delete.execute({
|
|
615
|
-
name: "keep-me",
|
|
616
|
-
confirm: false,
|
|
617
|
-
});
|
|
618
|
-
|
|
619
|
-
expect(result).toContain("not confirmed");
|
|
620
|
-
expect(result).toContain("confirm=true");
|
|
621
|
-
|
|
622
|
-
// Verify still exists
|
|
623
|
-
const skillDir = join(SKILLS_DIR, "keep-me");
|
|
624
|
-
expect(existsSync(skillDir)).toBe(true);
|
|
625
|
-
});
|
|
626
|
-
|
|
627
|
-
it("should return error for non-existent skill", async () => {
|
|
628
|
-
const result = await skills_delete.execute({
|
|
629
|
-
name: "non-existent",
|
|
630
|
-
confirm: true,
|
|
631
|
-
});
|
|
632
|
-
|
|
633
|
-
expect(result).toContain("not found");
|
|
634
|
-
});
|
|
635
|
-
|
|
636
|
-
it("should invalidate cache after deletion", async () => {
|
|
637
|
-
await skills_create.execute({
|
|
638
|
-
name: "cache-delete-test",
|
|
639
|
-
description: "Use when cache testing",
|
|
640
|
-
body: "Cache",
|
|
641
|
-
});
|
|
642
|
-
|
|
643
|
-
await skills_delete.execute({
|
|
644
|
-
name: "cache-delete-test",
|
|
645
|
-
confirm: true,
|
|
646
|
-
});
|
|
647
|
-
|
|
648
|
-
// Should be immediately gone from list
|
|
649
|
-
const result = await skills_list.execute({});
|
|
650
|
-
expect(result).not.toContain("cache-delete-test");
|
|
651
|
-
});
|
|
652
|
-
});
|
|
653
|
-
|
|
654
|
-
// =============================================================================
|
|
655
|
-
// skills_init Tool
|
|
656
|
-
// =============================================================================
|
|
657
|
-
|
|
658
|
-
describe("skills_init tool", () => {
|
|
659
|
-
beforeEach(() => {
|
|
660
|
-
setupTestDir();
|
|
661
|
-
});
|
|
662
|
-
|
|
663
|
-
afterAll(() => {
|
|
664
|
-
cleanupTestDir();
|
|
665
|
-
});
|
|
666
|
-
|
|
667
|
-
it("should initialize skill with full template structure", async () => {
|
|
668
|
-
const result = await skills_init.execute({
|
|
669
|
-
name: "init-test",
|
|
670
|
-
});
|
|
671
|
-
|
|
672
|
-
const parsed = JSON.parse(result);
|
|
673
|
-
expect(parsed.success).toBe(true);
|
|
674
|
-
expect(parsed.skill).toBe("init-test");
|
|
675
|
-
expect(parsed.created_files).toContain("SKILL.md");
|
|
676
|
-
expect(parsed.created_files).toContain("scripts/example.sh");
|
|
677
|
-
expect(parsed.created_files).toContain("references/guide.md");
|
|
678
|
-
|
|
679
|
-
// Verify files exist
|
|
680
|
-
const skillDir = join(SKILLS_DIR, "init-test");
|
|
681
|
-
expect(existsSync(join(skillDir, "SKILL.md"))).toBe(true);
|
|
682
|
-
expect(existsSync(join(skillDir, "scripts", "example.sh"))).toBe(true);
|
|
683
|
-
expect(existsSync(join(skillDir, "references", "guide.md"))).toBe(true);
|
|
684
|
-
});
|
|
685
|
-
|
|
686
|
-
it("should create SKILL.md with TODO placeholders", async () => {
|
|
687
|
-
await skills_init.execute({ name: "todo-test" });
|
|
688
|
-
|
|
689
|
-
const skillPath = join(SKILLS_DIR, "todo-test", "SKILL.md");
|
|
690
|
-
const content = readFileSync(skillPath, "utf-8");
|
|
691
|
-
|
|
692
|
-
expect(content).toContain("[TODO:");
|
|
693
|
-
expect(content).toContain("## When to Use This Skill");
|
|
694
|
-
expect(content).toContain("## Instructions");
|
|
695
|
-
expect(content).toContain("## Examples");
|
|
696
|
-
});
|
|
697
|
-
|
|
698
|
-
it("should exclude example script when include_example_script=false", async () => {
|
|
699
|
-
const result = await skills_init.execute({
|
|
700
|
-
name: "no-scripts",
|
|
701
|
-
include_example_script: false,
|
|
702
|
-
});
|
|
703
|
-
|
|
704
|
-
const parsed = JSON.parse(result);
|
|
705
|
-
expect(parsed.created_files).not.toContain("scripts/example.sh");
|
|
706
|
-
|
|
707
|
-
const scriptPath = join(SKILLS_DIR, "no-scripts", "scripts", "example.sh");
|
|
708
|
-
expect(existsSync(scriptPath)).toBe(false);
|
|
709
|
-
});
|
|
710
|
-
|
|
711
|
-
it("should exclude reference when include_reference=false", async () => {
|
|
712
|
-
const result = await skills_init.execute({
|
|
713
|
-
name: "no-refs",
|
|
714
|
-
include_reference: false,
|
|
715
|
-
});
|
|
716
|
-
|
|
717
|
-
const parsed = JSON.parse(result);
|
|
718
|
-
expect(parsed.created_files).not.toContain("references/guide.md");
|
|
719
|
-
|
|
720
|
-
const refPath = join(SKILLS_DIR, "no-refs", "references", "guide.md");
|
|
721
|
-
expect(existsSync(refPath)).toBe(false);
|
|
722
|
-
});
|
|
723
|
-
|
|
724
|
-
it("should use provided description in frontmatter", async () => {
|
|
725
|
-
await skills_init.execute({
|
|
726
|
-
name: "custom-desc",
|
|
727
|
-
description: "Use when custom description",
|
|
728
|
-
});
|
|
729
|
-
|
|
730
|
-
const skillPath = join(SKILLS_DIR, "custom-desc", "SKILL.md");
|
|
731
|
-
const content = readFileSync(skillPath, "utf-8");
|
|
732
|
-
|
|
733
|
-
expect(content).toContain("Use when custom description"); // May or may not be quoted
|
|
734
|
-
});
|
|
735
|
-
|
|
736
|
-
it("should prevent duplicate skill initialization", async () => {
|
|
737
|
-
// Provide a valid description so the skill is discoverable
|
|
738
|
-
await skills_init.execute({
|
|
739
|
-
name: "duplicate-init",
|
|
740
|
-
description: "Use when duplicate testing",
|
|
741
|
-
});
|
|
742
|
-
|
|
743
|
-
invalidateSkillsCache();
|
|
744
|
-
|
|
745
|
-
const result = await skills_init.execute({ name: "duplicate-init" });
|
|
746
|
-
|
|
747
|
-
const parsed = JSON.parse(result);
|
|
748
|
-
expect(parsed.success).toBe(false);
|
|
749
|
-
expect(parsed.error).toContain("already exists");
|
|
750
|
-
});
|
|
751
|
-
});
|
|
752
|
-
|
|
753
|
-
// =============================================================================
|
|
754
|
-
// skills_add_script Tool
|
|
755
|
-
// =============================================================================
|
|
756
|
-
|
|
757
|
-
describe("skills_add_script tool", () => {
|
|
758
|
-
beforeEach(() => {
|
|
759
|
-
setupTestDir();
|
|
760
|
-
});
|
|
761
|
-
|
|
762
|
-
afterAll(() => {
|
|
763
|
-
cleanupTestDir();
|
|
764
|
-
});
|
|
765
|
-
|
|
766
|
-
it("should add executable script to skill", async () => {
|
|
767
|
-
await skills_create.execute({
|
|
768
|
-
name: "script-test",
|
|
769
|
-
description: "Use when scripting",
|
|
770
|
-
body: "Body",
|
|
771
|
-
});
|
|
772
|
-
|
|
773
|
-
const scriptContent = "#!/bin/bash\necho 'Hello from script'";
|
|
774
|
-
const result = await skills_add_script.execute({
|
|
775
|
-
skill: "script-test",
|
|
776
|
-
script_name: "hello.sh",
|
|
777
|
-
content: scriptContent,
|
|
778
|
-
});
|
|
779
|
-
|
|
780
|
-
const parsed = JSON.parse(result);
|
|
781
|
-
expect(parsed.success).toBe(true);
|
|
782
|
-
expect(parsed.script).toBe("hello.sh");
|
|
783
|
-
// executable defaults to true if not specified
|
|
784
|
-
expect(parsed.executable !== false).toBe(true);
|
|
785
|
-
|
|
786
|
-
const scriptPath = join(SKILLS_DIR, "script-test", "scripts", "hello.sh");
|
|
787
|
-
expect(existsSync(scriptPath)).toBe(true);
|
|
788
|
-
|
|
789
|
-
const content = readFileSync(scriptPath, "utf-8");
|
|
790
|
-
expect(content).toBe(scriptContent);
|
|
791
|
-
});
|
|
792
|
-
|
|
793
|
-
it("should create scripts directory if needed", async () => {
|
|
794
|
-
await skills_create.execute({
|
|
795
|
-
name: "new-scripts",
|
|
796
|
-
description: "Use when new scripts",
|
|
797
|
-
body: "Body",
|
|
798
|
-
});
|
|
799
|
-
|
|
800
|
-
const scriptsDir = join(SKILLS_DIR, "new-scripts", "scripts");
|
|
801
|
-
expect(existsSync(scriptsDir)).toBe(false);
|
|
802
|
-
|
|
803
|
-
await skills_add_script.execute({
|
|
804
|
-
skill: "new-scripts",
|
|
805
|
-
script_name: "first.sh",
|
|
806
|
-
content: "#!/bin/bash\necho first",
|
|
807
|
-
});
|
|
808
|
-
|
|
809
|
-
expect(existsSync(scriptsDir)).toBe(true);
|
|
810
|
-
});
|
|
811
|
-
|
|
812
|
-
it("should add non-executable script when executable=false", async () => {
|
|
813
|
-
await skills_create.execute({
|
|
814
|
-
name: "data-script",
|
|
815
|
-
description: "Use when data",
|
|
816
|
-
body: "Body",
|
|
817
|
-
});
|
|
818
|
-
|
|
819
|
-
await skills_add_script.execute({
|
|
820
|
-
skill: "data-script",
|
|
821
|
-
script_name: "data.json",
|
|
822
|
-
content: '{"key": "value"}',
|
|
823
|
-
executable: false,
|
|
824
|
-
});
|
|
825
|
-
|
|
826
|
-
const parsed = await skills_add_script.execute({
|
|
827
|
-
skill: "data-script",
|
|
828
|
-
script_name: "config.yaml",
|
|
829
|
-
content: "key: value",
|
|
830
|
-
executable: false,
|
|
831
|
-
});
|
|
832
|
-
|
|
833
|
-
const result = JSON.parse(parsed);
|
|
834
|
-
expect(result.executable).toBe(false);
|
|
835
|
-
});
|
|
836
|
-
|
|
837
|
-
it("should prevent path traversal in script names", async () => {
|
|
838
|
-
await skills_create.execute({
|
|
839
|
-
name: "secure-scripts",
|
|
840
|
-
description: "Use when secure",
|
|
841
|
-
body: "Body",
|
|
842
|
-
});
|
|
843
|
-
|
|
844
|
-
const maliciousNames = [
|
|
845
|
-
"../../../etc/passwd.sh",
|
|
846
|
-
"../../bad.sh",
|
|
847
|
-
"/etc/script.sh",
|
|
848
|
-
"subdir/script.sh", // No subdirectories allowed
|
|
849
|
-
];
|
|
850
|
-
|
|
851
|
-
for (const name of maliciousNames) {
|
|
852
|
-
const result = await skills_add_script.execute({
|
|
853
|
-
skill: "secure-scripts",
|
|
854
|
-
script_name: name,
|
|
855
|
-
content: "echo bad",
|
|
856
|
-
});
|
|
857
|
-
|
|
858
|
-
expect(result).toContain("Invalid script name");
|
|
859
|
-
}
|
|
860
|
-
});
|
|
861
|
-
|
|
862
|
-
it("should return error for non-existent skill", async () => {
|
|
863
|
-
const result = await skills_add_script.execute({
|
|
864
|
-
skill: "non-existent",
|
|
865
|
-
script_name: "test.sh",
|
|
866
|
-
content: "echo test",
|
|
867
|
-
});
|
|
868
|
-
|
|
869
|
-
expect(result).toContain("not found");
|
|
870
|
-
});
|
|
871
|
-
|
|
872
|
-
it("should invalidate cache after adding script", async () => {
|
|
873
|
-
await skills_create.execute({
|
|
874
|
-
name: "cache-script-test",
|
|
875
|
-
description: "Use when cache",
|
|
876
|
-
body: "Body",
|
|
877
|
-
});
|
|
878
|
-
|
|
879
|
-
await skills_add_script.execute({
|
|
880
|
-
skill: "cache-script-test",
|
|
881
|
-
script_name: "test.sh",
|
|
882
|
-
content: "echo test",
|
|
883
|
-
});
|
|
884
|
-
|
|
885
|
-
// Should immediately show [has scripts]
|
|
886
|
-
const result = await skills_list.execute({});
|
|
887
|
-
expect(result).toContain("cache-script-test");
|
|
888
|
-
expect(result).toContain("[has scripts]");
|
|
889
|
-
});
|
|
890
|
-
});
|
|
891
|
-
|
|
892
|
-
// =============================================================================
|
|
893
|
-
// skills_execute Tool
|
|
894
|
-
// =============================================================================
|
|
895
|
-
|
|
896
|
-
describe("skills_execute tool", () => {
|
|
897
|
-
beforeEach(() => {
|
|
898
|
-
setupTestDir();
|
|
899
|
-
});
|
|
900
|
-
|
|
901
|
-
afterAll(() => {
|
|
902
|
-
cleanupTestDir();
|
|
903
|
-
});
|
|
904
|
-
|
|
905
|
-
it("should execute a script successfully", async () => {
|
|
906
|
-
await skills_create.execute({
|
|
907
|
-
name: "exec-test",
|
|
908
|
-
description: "Use when executing",
|
|
909
|
-
body: "Body",
|
|
910
|
-
});
|
|
911
|
-
|
|
912
|
-
await skills_add_script.execute({
|
|
913
|
-
skill: "exec-test",
|
|
914
|
-
script_name: "echo.sh",
|
|
915
|
-
content: '#!/bin/bash\necho "Hello from script"',
|
|
916
|
-
});
|
|
917
|
-
|
|
918
|
-
// Manually ensure executable (writeFileSync mode doesn't always work)
|
|
919
|
-
const scriptPath = join(SKILLS_DIR, "exec-test", "scripts", "echo.sh");
|
|
920
|
-
chmodSync(scriptPath, 0o755);
|
|
921
|
-
|
|
922
|
-
const result = await skills_execute.execute({
|
|
923
|
-
skill: "exec-test",
|
|
924
|
-
script: "echo.sh",
|
|
925
|
-
});
|
|
926
|
-
|
|
927
|
-
expect(result).toContain("Hello from script");
|
|
928
|
-
});
|
|
929
|
-
|
|
930
|
-
it("should pass project directory as first argument", async () => {
|
|
931
|
-
await skills_create.execute({
|
|
932
|
-
name: "args-test",
|
|
933
|
-
description: "Use when args",
|
|
934
|
-
body: "Body",
|
|
935
|
-
});
|
|
936
|
-
|
|
937
|
-
await skills_add_script.execute({
|
|
938
|
-
skill: "args-test",
|
|
939
|
-
script_name: "check-args.sh",
|
|
940
|
-
content: '#!/bin/bash\necho "Project dir: $1"',
|
|
941
|
-
});
|
|
942
|
-
|
|
943
|
-
const scriptPath = join(SKILLS_DIR, "args-test", "scripts", "check-args.sh");
|
|
944
|
-
chmodSync(scriptPath, 0o755);
|
|
945
|
-
|
|
946
|
-
const result = await skills_execute.execute({
|
|
947
|
-
skill: "args-test",
|
|
948
|
-
script: "check-args.sh",
|
|
949
|
-
});
|
|
950
|
-
|
|
951
|
-
expect(result).toContain("Project dir:");
|
|
952
|
-
expect(result).toContain(TEST_DIR);
|
|
953
|
-
});
|
|
954
|
-
|
|
955
|
-
it("should pass additional arguments to script", async () => {
|
|
956
|
-
await skills_create.execute({
|
|
957
|
-
name: "multi-args-test",
|
|
958
|
-
description: "Use when multi args",
|
|
959
|
-
body: "Body",
|
|
960
|
-
});
|
|
961
|
-
|
|
962
|
-
await skills_add_script.execute({
|
|
963
|
-
skill: "multi-args-test",
|
|
964
|
-
script_name: "args.sh",
|
|
965
|
-
content: '#!/bin/bash\necho "Args: $1 $2 $3"',
|
|
966
|
-
});
|
|
967
|
-
|
|
968
|
-
const scriptPath = join(SKILLS_DIR, "multi-args-test", "scripts", "args.sh");
|
|
969
|
-
chmodSync(scriptPath, 0o755);
|
|
970
|
-
|
|
971
|
-
const result = await skills_execute.execute({
|
|
972
|
-
skill: "multi-args-test",
|
|
973
|
-
script: "args.sh",
|
|
974
|
-
args: ["arg1", "arg2"],
|
|
975
|
-
});
|
|
976
|
-
|
|
977
|
-
expect(result).toContain("Args:");
|
|
978
|
-
expect(result).toContain("arg1");
|
|
979
|
-
expect(result).toContain("arg2");
|
|
980
|
-
});
|
|
981
|
-
|
|
982
|
-
it("should return error for non-existent skill", async () => {
|
|
983
|
-
const result = await skills_execute.execute({
|
|
984
|
-
skill: "non-existent",
|
|
985
|
-
script: "test.sh",
|
|
986
|
-
});
|
|
987
|
-
|
|
988
|
-
expect(result).toContain("not found");
|
|
989
|
-
});
|
|
990
|
-
|
|
991
|
-
it("should return error for non-existent script", async () => {
|
|
992
|
-
await skills_create.execute({
|
|
993
|
-
name: "no-script",
|
|
994
|
-
description: "Use when no script",
|
|
995
|
-
body: "Body",
|
|
996
|
-
});
|
|
997
|
-
|
|
998
|
-
const result = await skills_execute.execute({
|
|
999
|
-
skill: "no-script",
|
|
1000
|
-
script: "missing.sh",
|
|
1001
|
-
});
|
|
1002
|
-
|
|
1003
|
-
expect(result).toContain("not found");
|
|
1004
|
-
expect(result).toContain("Available:");
|
|
1005
|
-
});
|
|
1006
|
-
|
|
1007
|
-
it("should return non-zero exit code output", async () => {
|
|
1008
|
-
await skills_create.execute({
|
|
1009
|
-
name: "fail-test",
|
|
1010
|
-
description: "Use when failing",
|
|
1011
|
-
body: "Body",
|
|
1012
|
-
});
|
|
1013
|
-
|
|
1014
|
-
await skills_add_script.execute({
|
|
1015
|
-
skill: "fail-test",
|
|
1016
|
-
script_name: "fail.sh",
|
|
1017
|
-
content: '#!/bin/bash\necho "Failed"\nexit 1',
|
|
1018
|
-
});
|
|
1019
|
-
|
|
1020
|
-
const scriptPath = join(SKILLS_DIR, "fail-test", "scripts", "fail.sh");
|
|
1021
|
-
chmodSync(scriptPath, 0o755);
|
|
1022
|
-
|
|
1023
|
-
const result = await skills_execute.execute({
|
|
1024
|
-
skill: "fail-test",
|
|
1025
|
-
script: "fail.sh",
|
|
1026
|
-
});
|
|
1027
|
-
|
|
1028
|
-
expect(result).toContain("exited with code 1");
|
|
1029
|
-
expect(result).toContain("Failed");
|
|
1030
|
-
});
|
|
1031
|
-
|
|
1032
|
-
it("should timeout long-running scripts", async () => {
|
|
1033
|
-
await skills_create.execute({
|
|
1034
|
-
name: "timeout-test",
|
|
1035
|
-
description: "Use when timing out",
|
|
1036
|
-
body: "Body",
|
|
1037
|
-
});
|
|
1038
|
-
|
|
1039
|
-
await skills_add_script.execute({
|
|
1040
|
-
skill: "timeout-test",
|
|
1041
|
-
script_name: "slow.sh",
|
|
1042
|
-
content: '#!/bin/bash\nsleep 120', // 2 minutes (longer than 60s timeout)
|
|
1043
|
-
});
|
|
1044
|
-
|
|
1045
|
-
const scriptPath = join(SKILLS_DIR, "timeout-test", "scripts", "slow.sh");
|
|
1046
|
-
chmodSync(scriptPath, 0o755);
|
|
1047
|
-
|
|
1048
|
-
const result = await skills_execute.execute({
|
|
1049
|
-
skill: "timeout-test",
|
|
1050
|
-
script: "slow.sh",
|
|
1051
|
-
});
|
|
1052
|
-
|
|
1053
|
-
expect(result).toContain("timed out");
|
|
1054
|
-
expect(result).toContain("60 seconds");
|
|
1055
|
-
}, 65000); // Allow 65s for test itself
|
|
1056
|
-
});
|
|
1057
|
-
|
|
1058
|
-
// =============================================================================
|
|
1059
|
-
// Deprecation Warnings Tests
|
|
1060
|
-
// =============================================================================
|
|
1061
|
-
|
|
1062
|
-
describe("deprecation warnings", () => {
|
|
1063
|
-
beforeEach(() => {
|
|
1064
|
-
setupTestDir();
|
|
1065
|
-
});
|
|
1066
|
-
|
|
1067
|
-
afterAll(() => {
|
|
1068
|
-
cleanupTestDir();
|
|
1069
|
-
});
|
|
1070
|
-
|
|
1071
|
-
it("skills_list emits deprecation warning", async () => {
|
|
1072
|
-
const warnSpy = vi.spyOn(console, "warn");
|
|
1073
|
-
|
|
1074
|
-
await skills_list.execute({});
|
|
1075
|
-
|
|
1076
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
1077
|
-
expect.stringContaining("[DEPRECATED] skills_list")
|
|
1078
|
-
);
|
|
1079
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
1080
|
-
expect.stringContaining("OpenCode now provides native skills support")
|
|
1081
|
-
);
|
|
1082
|
-
warnSpy.mockRestore();
|
|
1083
|
-
});
|
|
1084
|
-
|
|
1085
|
-
it("skills_use emits deprecation warning", async () => {
|
|
1086
|
-
await skills_create.execute({
|
|
1087
|
-
name: "test-skill",
|
|
1088
|
-
description: "Use when testing",
|
|
1089
|
-
body: "Instructions",
|
|
1090
|
-
});
|
|
1091
|
-
|
|
1092
|
-
invalidateSkillsCache();
|
|
1093
|
-
|
|
1094
|
-
const warnSpy = vi.spyOn(console, "warn");
|
|
1095
|
-
|
|
1096
|
-
await skills_use.execute({ name: "test-skill" });
|
|
1097
|
-
|
|
1098
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
1099
|
-
expect.stringContaining("[DEPRECATED] skills_use")
|
|
1100
|
-
);
|
|
1101
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
1102
|
-
expect.stringContaining("OpenCode now provides native skills support")
|
|
1103
|
-
);
|
|
1104
|
-
warnSpy.mockRestore();
|
|
1105
|
-
});
|
|
1106
|
-
|
|
1107
|
-
it("skills_read emits deprecation warning", async () => {
|
|
1108
|
-
await skills_create.execute({
|
|
1109
|
-
name: "test-skill",
|
|
1110
|
-
description: "Use when testing",
|
|
1111
|
-
body: "Instructions",
|
|
1112
|
-
});
|
|
1113
|
-
|
|
1114
|
-
const skillDir = join(SKILLS_DIR, "test-skill");
|
|
1115
|
-
writeFileSync(join(skillDir, "example.md"), "# Example");
|
|
1116
|
-
|
|
1117
|
-
invalidateSkillsCache();
|
|
1118
|
-
|
|
1119
|
-
const warnSpy = vi.spyOn(console, "warn");
|
|
1120
|
-
|
|
1121
|
-
await skills_read.execute({
|
|
1122
|
-
skill: "test-skill",
|
|
1123
|
-
file: "example.md",
|
|
1124
|
-
});
|
|
1125
|
-
|
|
1126
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
1127
|
-
expect.stringContaining("[DEPRECATED] skills_read")
|
|
1128
|
-
);
|
|
1129
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
1130
|
-
expect.stringContaining("OpenCode now provides native skills support")
|
|
1131
|
-
);
|
|
1132
|
-
warnSpy.mockRestore();
|
|
1133
|
-
});
|
|
1134
|
-
|
|
1135
|
-
it("skills_execute emits deprecation warning", async () => {
|
|
1136
|
-
await skills_create.execute({
|
|
1137
|
-
name: "test-skill",
|
|
1138
|
-
description: "Use when testing",
|
|
1139
|
-
body: "Instructions",
|
|
1140
|
-
});
|
|
1141
|
-
|
|
1142
|
-
await skills_add_script.execute({
|
|
1143
|
-
skill: "test-skill",
|
|
1144
|
-
script_name: "test.sh",
|
|
1145
|
-
content: '#!/bin/bash\necho "test"',
|
|
1146
|
-
});
|
|
1147
|
-
|
|
1148
|
-
const scriptPath = join(SKILLS_DIR, "test-skill", "scripts", "test.sh");
|
|
1149
|
-
chmodSync(scriptPath, 0o755);
|
|
1150
|
-
|
|
1151
|
-
invalidateSkillsCache();
|
|
1152
|
-
|
|
1153
|
-
const warnSpy = vi.spyOn(console, "warn");
|
|
1154
|
-
|
|
1155
|
-
await skills_execute.execute({
|
|
1156
|
-
skill: "test-skill",
|
|
1157
|
-
script: "test.sh",
|
|
1158
|
-
});
|
|
1159
|
-
|
|
1160
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
1161
|
-
expect.stringContaining("[DEPRECATED] skills_execute")
|
|
1162
|
-
);
|
|
1163
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
1164
|
-
expect.stringContaining("OpenCode now provides native skills support")
|
|
1165
|
-
);
|
|
1166
|
-
warnSpy.mockRestore();
|
|
1167
|
-
});
|
|
1168
|
-
|
|
1169
|
-
it("deprecated tools still function correctly (soft deprecation)", async () => {
|
|
1170
|
-
// Create a skill
|
|
1171
|
-
await skills_create.execute({
|
|
1172
|
-
name: "functional-test",
|
|
1173
|
-
description: "Use when testing functionality",
|
|
1174
|
-
body: "# Test\n\nStill works!",
|
|
1175
|
-
});
|
|
1176
|
-
|
|
1177
|
-
invalidateSkillsCache();
|
|
1178
|
-
|
|
1179
|
-
// Suppress console.warn for this test
|
|
1180
|
-
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
1181
|
-
|
|
1182
|
-
// skills_list should still list skills
|
|
1183
|
-
const listResult = await skills_list.execute({});
|
|
1184
|
-
expect(listResult).toContain("functional-test");
|
|
1185
|
-
|
|
1186
|
-
// skills_use should still return content
|
|
1187
|
-
const useResult = await skills_use.execute({ name: "functional-test" });
|
|
1188
|
-
expect(useResult).toContain("Still works!");
|
|
1189
|
-
|
|
1190
|
-
warnSpy.mockRestore();
|
|
1191
|
-
});
|
|
1192
|
-
});
|