elelem-skills 0.2.0 → 0.4.0
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.
- checksums.yaml +4 -4
- data/.agents/backlog/001-enforce-pinned-digests.md +71 -0
- data/.agents/backlog/002-refresh-skill-tool-description.md +64 -0
- data/.agents/backlog/003-redirect-status-handling.md +47 -0
- data/.agents/backlog/004-private-address-fetches.md +58 -0
- data/.agents/backlog/005-release-changelog-fixes.md +47 -0
- data/.agents/backlog/006-gem-metadata-links.md +65 -0
- data/.github/workflows/release.yml +63 -0
- data/.release-please-manifest.json +3 -0
- data/.rspec +1 -0
- data/.rubocop.yml +62 -0
- data/CHANGELOG.md +22 -0
- data/README.md +3 -0
- data/Rakefile +5 -1
- data/exe/elelem-skills +6 -0
- data/lib/elelem/skills/catalog.rb +74 -0
- data/lib/elelem/skills/cli.rb +55 -0
- data/lib/elelem/skills/fetcher.rb +164 -0
- data/lib/elelem/skills/lockfile.rb +56 -0
- data/lib/elelem/skills/setup.rb +88 -0
- data/lib/elelem/skills/skill.rb +6 -4
- data/lib/elelem/skills/skill_file.rb +42 -0
- data/lib/elelem/skills/version.rb +1 -1
- data/lib/elelem/skills.rb +13 -0
- data/release-please-config.json +12 -0
- data/spec/elelem/skills/catalog_spec.rb +122 -0
- data/spec/elelem/skills/cli_spec.rb +66 -0
- data/spec/elelem/skills/fetcher_spec.rb +282 -0
- data/spec/elelem/skills/lockfile_spec.rb +51 -0
- data/spec/elelem/skills/setup_spec.rb +124 -0
- data/spec/elelem/skills/skill_file_spec.rb +79 -0
- data/spec/elelem/skills/skill_spec.rb +11 -0
- data/spec/fixtures/skills/no-description/SKILL.md +5 -0
- data/spec/fixtures/skills/tdd/SKILL.md +8 -0
- data/spec/spec_helper.rb +13 -0
- metadata +92 -16
- data/lib/elelem/skills/prompts/build.erb +0 -39
- data/lib/elelem/skills/prompts/design.erb +0 -41
- data/lib/elelem/skills/prompts/plan.erb +0 -59
- data/lib/elelem/skills/prompts/review.erb +0 -44
- data/lib/elelem/skills/prompts/verify.erb +0 -39
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Elelem::Skills::Fetcher do
|
|
4
|
+
let(:install_dir) { Dir.mktmpdir }
|
|
5
|
+
let(:http) { class_double(Net::HTTP) }
|
|
6
|
+
let(:lockfile) { Elelem::Skills::Lockfile.new(File.join(install_dir, ".skill-lock.json")) }
|
|
7
|
+
let(:fetcher) { described_class.new(install_dir: install_dir, http: http) }
|
|
8
|
+
|
|
9
|
+
after { FileUtils.rm_rf(install_dir) }
|
|
10
|
+
|
|
11
|
+
def ok(body)
|
|
12
|
+
res = Net::HTTPOK.new("1.1", "200", "OK")
|
|
13
|
+
res.instance_variable_set(:@read, true)
|
|
14
|
+
res.body = body
|
|
15
|
+
res
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def moved(location)
|
|
19
|
+
res = Net::HTTPMovedPermanently.new("1.1", "301", "Moved Permanently")
|
|
20
|
+
res.instance_variable_set(:@read, true)
|
|
21
|
+
res["location"] = location
|
|
22
|
+
res
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def not_found
|
|
26
|
+
res = Net::HTTPNotFound.new("1.1", "404", "Not Found")
|
|
27
|
+
res.instance_variable_set(:@read, true)
|
|
28
|
+
res.body = ""
|
|
29
|
+
res
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
let(:skill_body) { "---\nname: example\ndescription: An example skill.\n---\nBody.\n" }
|
|
33
|
+
let(:digest) { "sha256:#{Digest::SHA256.hexdigest(skill_body)}" }
|
|
34
|
+
|
|
35
|
+
let(:index) do
|
|
36
|
+
{
|
|
37
|
+
"$schema" => Elelem::Skills::Fetcher::SCHEMA,
|
|
38
|
+
"skills" => [
|
|
39
|
+
{ "name" => "example", "type" => "skill-md", "description" => "An example skill.",
|
|
40
|
+
"url" => "/.well-known/agent-skills/example/SKILL.md", "digest" => digest }
|
|
41
|
+
]
|
|
42
|
+
}.to_json
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe "#fetch, trust" do
|
|
46
|
+
def two_skill_index(second_digest)
|
|
47
|
+
second = { "name" => "second", "type" => "skill-md", "description" => "Second.",
|
|
48
|
+
"url" => "/.well-known/agent-skills/second/SKILL.md", "digest" => second_digest }
|
|
49
|
+
JSON.parse(index).tap { |i| i["skills"] << second }.to_json
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def serve(index_body, second_body: skill_body)
|
|
53
|
+
allow(http).to receive(:get_response)
|
|
54
|
+
.with(URI("https://example.com/.well-known/agent-skills/index.json")).and_return(ok(index_body))
|
|
55
|
+
allow(http).to receive(:get_response)
|
|
56
|
+
.with(URI("https://example.com/.well-known/agent-skills/example/SKILL.md")).and_return(ok(skill_body))
|
|
57
|
+
allow(http).to receive(:get_response)
|
|
58
|
+
.with(URI("https://example.com/.well-known/agent-skills/second/SKILL.md")).and_return(ok(second_body))
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "refuses a plain http origin" do
|
|
62
|
+
expect { fetcher.fetch("http://example.com") }.to raise_error(described_class::FetchError, /use https/)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "does not let a remote index redirect to this machine, however it is spelled" do
|
|
66
|
+
%w[http://127.0.0.1:8080/x https://[0:0::1]:8443/x https://127.0.0.2/x https://LOCALHOST./x
|
|
67
|
+
https://[::ffff:127.0.0.1]/x https://0.0.0.0/x https://127.1/x https://0x7f000001/x
|
|
68
|
+
https://2130706433/x].each do |target|
|
|
69
|
+
allow(http).to receive(:get_response).and_return(moved(target))
|
|
70
|
+
|
|
71
|
+
expect { fetcher.fetch("example.com") }.to raise_error(described_class::FetchError, /use https/), target
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "allows plain http on this machine, for testing" do
|
|
76
|
+
allow(http).to receive(:get_response).and_return(not_found)
|
|
77
|
+
|
|
78
|
+
expect { fetcher.fetch("http://localhost:8080") }.to raise_error(described_class::FetchError, /404/)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "installs nothing when one skill fails its digest" do
|
|
82
|
+
serve(two_skill_index("sha256:#{"0" * 64}"))
|
|
83
|
+
|
|
84
|
+
expect { fetcher.fetch("example.com") }.to raise_error(described_class::FetchError, /digest mismatch/)
|
|
85
|
+
expect(File).not_to exist(File.join(install_dir, "example.com", "example", "SKILL.md"))
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "refuses a skill with no digest" do
|
|
89
|
+
serve(index.sub(/"digest":"[^"]*"/, '"digest":null'))
|
|
90
|
+
|
|
91
|
+
expect { fetcher.fetch("example.com") }.to raise_error(described_class::FetchError, /no digest/)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "warns when a pinned digest changes, then installs the new skill" do
|
|
95
|
+
serve(index)
|
|
96
|
+
fetcher.fetch("example.com")
|
|
97
|
+
changed = "---\nname: example\ndescription: Changed.\n---\nNew.\n"
|
|
98
|
+
changed_index = index.sub(digest, "sha256:#{Digest::SHA256.hexdigest(changed)}")
|
|
99
|
+
allow(http).to receive(:get_response)
|
|
100
|
+
.with(URI("https://example.com/.well-known/agent-skills/index.json")).and_return(ok(changed_index))
|
|
101
|
+
allow(http).to receive(:get_response)
|
|
102
|
+
.with(URI("https://example.com/.well-known/agent-skills/example/SKILL.md")).and_return(ok(changed))
|
|
103
|
+
allow(Elelem.logger).to receive(:warn)
|
|
104
|
+
|
|
105
|
+
fetcher.fetch("example.com")
|
|
106
|
+
|
|
107
|
+
expect(Elelem.logger).to have_received(:warn).with(%r{example.com/example changed: was #{digest}})
|
|
108
|
+
expect(fetcher.changed).to eq(["example.com/example"])
|
|
109
|
+
expect(File.read(File.join(install_dir, "example.com", "example", "SKILL.md"))).to eq(changed)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
describe "#fetch with redirects" do
|
|
114
|
+
it "follows them, and resolves skill URLs against the final index URL" do
|
|
115
|
+
allow(http).to receive(:get_response)
|
|
116
|
+
.with(URI("https://example.com/.well-known/agent-skills/index.json"))
|
|
117
|
+
.and_return(moved("https://www.example.com/.well-known/agent-skills/index.json"))
|
|
118
|
+
allow(http).to receive(:get_response)
|
|
119
|
+
.with(URI("https://www.example.com/.well-known/agent-skills/index.json")).and_return(ok(index))
|
|
120
|
+
allow(http).to receive(:get_response)
|
|
121
|
+
.with(URI("https://www.example.com/.well-known/agent-skills/example/SKILL.md")).and_return(ok(skill_body))
|
|
122
|
+
|
|
123
|
+
expect(fetcher.fetch("example.com")).to eq(["example"])
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it "refuses a redirect from https to http" do
|
|
127
|
+
allow(http).to receive(:get_response).and_return(moved("http://example.com/index.json"))
|
|
128
|
+
|
|
129
|
+
expect { fetcher.fetch("example.com") }.to raise_error(described_class::FetchError, /use https/)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it "stops after too many redirects" do
|
|
133
|
+
allow(http).to receive(:get_response).and_return(moved("/again"))
|
|
134
|
+
|
|
135
|
+
expect { fetcher.fetch("example.com") }.to raise_error(described_class::FetchError, /too many redirects/)
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
describe "#fetch" do
|
|
140
|
+
it "installs a skill-md entry whose digest matches" do
|
|
141
|
+
expect(http).to receive(:get_response)
|
|
142
|
+
.with(URI("https://example.com/.well-known/agent-skills/index.json"))
|
|
143
|
+
.and_return(ok(index))
|
|
144
|
+
expect(http).to receive(:get_response)
|
|
145
|
+
.with(URI("https://example.com/.well-known/agent-skills/example/SKILL.md"))
|
|
146
|
+
.and_return(ok(skill_body))
|
|
147
|
+
|
|
148
|
+
names = fetcher.fetch("example.com")
|
|
149
|
+
|
|
150
|
+
expect(names).to eq(["example"])
|
|
151
|
+
expect(File.read(File.join(install_dir, "example.com", "example", "SKILL.md"))).to eq(skill_body)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it "records the install in the lockfile, keyed by host/name" do
|
|
155
|
+
allow(http).to receive(:get_response)
|
|
156
|
+
.with(URI("https://example.com/.well-known/agent-skills/index.json"))
|
|
157
|
+
.and_return(ok(index))
|
|
158
|
+
allow(http).to receive(:get_response)
|
|
159
|
+
.with(URI("https://example.com/.well-known/agent-skills/example/SKILL.md"))
|
|
160
|
+
.and_return(ok(skill_body))
|
|
161
|
+
|
|
162
|
+
fetcher.fetch("example.com")
|
|
163
|
+
entry = lockfile.read.dig("skills", "example.com/example")
|
|
164
|
+
|
|
165
|
+
expect(entry["host"]).to eq("example.com")
|
|
166
|
+
expect(entry["name"]).to eq("example")
|
|
167
|
+
expect(entry["url"]).to eq("https://example.com/.well-known/agent-skills/example/SKILL.md")
|
|
168
|
+
expect(entry["digest"]).to eq(digest)
|
|
169
|
+
expect(entry["installedAt"]).not_to be_nil
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
it "adds https:// when the origin has no scheme" do
|
|
173
|
+
expect(http).to receive(:get_response)
|
|
174
|
+
.with(URI("https://example.com/.well-known/agent-skills/index.json"))
|
|
175
|
+
.and_return(ok(index))
|
|
176
|
+
allow(http).to receive(:get_response).with(URI("https://example.com/.well-known/agent-skills/example/SKILL.md")).and_return(ok(skill_body))
|
|
177
|
+
|
|
178
|
+
fetcher.fetch("example.com")
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it "raises when the digest does not match" do
|
|
182
|
+
tampered = index.sub(digest, "sha256:#{"0" * 64}")
|
|
183
|
+
allow(http).to receive(:get_response)
|
|
184
|
+
.with(URI("https://example.com/.well-known/agent-skills/index.json"))
|
|
185
|
+
.and_return(ok(tampered))
|
|
186
|
+
allow(http).to receive(:get_response)
|
|
187
|
+
.with(URI("https://example.com/.well-known/agent-skills/example/SKILL.md"))
|
|
188
|
+
.and_return(ok(skill_body))
|
|
189
|
+
|
|
190
|
+
expect { fetcher.fetch("example.com") }.to raise_error(Elelem::Skills::Fetcher::FetchError, /digest mismatch/)
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
it "raises on an unrecognized schema" do
|
|
194
|
+
bad = index.sub(Elelem::Skills::Fetcher::SCHEMA, "https://schemas.agentskills.io/discovery/9.9.9/schema.json")
|
|
195
|
+
allow(http).to receive(:get_response)
|
|
196
|
+
.with(URI("https://example.com/.well-known/agent-skills/index.json"))
|
|
197
|
+
.and_return(ok(bad))
|
|
198
|
+
|
|
199
|
+
expect do
|
|
200
|
+
fetcher.fetch("example.com")
|
|
201
|
+
end.to raise_error(Elelem::Skills::Fetcher::FetchError, /unrecognized index schema/)
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
it "raises when the schema field is absent (treated as incompatible v0.1.0)" do
|
|
205
|
+
no_schema = JSON.parse(index).tap { |h| h.delete("$schema") }.to_json
|
|
206
|
+
allow(http).to receive(:get_response)
|
|
207
|
+
.with(URI("https://example.com/.well-known/agent-skills/index.json"))
|
|
208
|
+
.and_return(ok(no_schema))
|
|
209
|
+
|
|
210
|
+
expect do
|
|
211
|
+
fetcher.fetch("example.com")
|
|
212
|
+
end.to raise_error(Elelem::Skills::Fetcher::FetchError, /unrecognized index schema/)
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
it "skips archive entries and warns, without raising" do
|
|
216
|
+
archive_index = {
|
|
217
|
+
"$schema" => Elelem::Skills::Fetcher::SCHEMA,
|
|
218
|
+
"skills" => [
|
|
219
|
+
{ "name" => "bundled", "type" => "archive", "description" => "Has resources.",
|
|
220
|
+
"url" => "/.well-known/agent-skills/bundled.tar.gz", "digest" => "sha256:#{"0" * 64}" }
|
|
221
|
+
]
|
|
222
|
+
}.to_json
|
|
223
|
+
allow(http).to receive(:get_response)
|
|
224
|
+
.with(URI("https://example.com/.well-known/agent-skills/index.json"))
|
|
225
|
+
.and_return(ok(archive_index))
|
|
226
|
+
expect(Elelem.logger).to receive(:warn).with(/unsupported type "archive"/)
|
|
227
|
+
|
|
228
|
+
expect(fetcher.fetch("example.com")).to eq([])
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
it "raises when the index request fails" do
|
|
232
|
+
allow(http).to receive(:get_response)
|
|
233
|
+
.with(URI("https://example.com/.well-known/agent-skills/index.json"))
|
|
234
|
+
.and_return(not_found)
|
|
235
|
+
|
|
236
|
+
expect { fetcher.fetch("example.com") }.to raise_error(Elelem::Skills::Fetcher::FetchError, /404/)
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
it "partitions by host so two origins publishing the same skill name don't clobber each other" do
|
|
240
|
+
other_body = "---\nname: example\ndescription: A different example skill, from another host.\n---\nOther body.\n"
|
|
241
|
+
other_digest = "sha256:#{Digest::SHA256.hexdigest(other_body)}"
|
|
242
|
+
other_index = {
|
|
243
|
+
"$schema" => Elelem::Skills::Fetcher::SCHEMA,
|
|
244
|
+
"skills" => [
|
|
245
|
+
{ "name" => "example", "type" => "skill-md", "description" => "A different example skill.",
|
|
246
|
+
"url" => "/.well-known/agent-skills/example/SKILL.md", "digest" => other_digest }
|
|
247
|
+
]
|
|
248
|
+
}.to_json
|
|
249
|
+
|
|
250
|
+
allow(http).to receive(:get_response)
|
|
251
|
+
.with(URI("https://example.com/.well-known/agent-skills/index.json"))
|
|
252
|
+
.and_return(ok(index))
|
|
253
|
+
allow(http).to receive(:get_response)
|
|
254
|
+
.with(URI("https://example.com/.well-known/agent-skills/example/SKILL.md"))
|
|
255
|
+
.and_return(ok(skill_body))
|
|
256
|
+
allow(http).to receive(:get_response)
|
|
257
|
+
.with(URI("https://other.example/.well-known/agent-skills/index.json"))
|
|
258
|
+
.and_return(ok(other_index))
|
|
259
|
+
allow(http).to receive(:get_response)
|
|
260
|
+
.with(URI("https://other.example/.well-known/agent-skills/example/SKILL.md"))
|
|
261
|
+
.and_return(ok(other_body))
|
|
262
|
+
|
|
263
|
+
fetcher.fetch("example.com")
|
|
264
|
+
fetcher.fetch("other.example")
|
|
265
|
+
|
|
266
|
+
expect(File.read(File.join(install_dir, "example.com", "example", "SKILL.md"))).to eq(skill_body)
|
|
267
|
+
expect(File.read(File.join(install_dir, "other.example", "example", "SKILL.md"))).to eq(other_body)
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
it "lowercases the host when using it as a directory name" do
|
|
271
|
+
index_url = URI("https://Example.COM/.well-known/agent-skills/index.json")
|
|
272
|
+
allow(http).to receive(:get_response).with(index_url).and_return(ok(index))
|
|
273
|
+
allow(http).to receive(:get_response)
|
|
274
|
+
.with(URI("https://Example.COM/.well-known/agent-skills/example/SKILL.md"))
|
|
275
|
+
.and_return(ok(skill_body))
|
|
276
|
+
|
|
277
|
+
fetcher.fetch("Example.COM")
|
|
278
|
+
|
|
279
|
+
expect(File.directory?(File.join(install_dir, "example.com"))).to be(true)
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Elelem::Skills::Lockfile do
|
|
4
|
+
let(:dir) { Dir.mktmpdir }
|
|
5
|
+
let(:path) { File.join(dir, ".skill-lock.json") }
|
|
6
|
+
let(:lockfile) { described_class.new(path) }
|
|
7
|
+
|
|
8
|
+
after { FileUtils.rm_rf(dir) }
|
|
9
|
+
|
|
10
|
+
describe "#read" do
|
|
11
|
+
it "returns an empty skills map when the file does not exist" do
|
|
12
|
+
expect(lockfile.read).to eq({ "version" => 1, "skills" => {} })
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "#record" do
|
|
17
|
+
it "writes a new entry keyed by host/name" do
|
|
18
|
+
lockfile.record(host: "example.com", name: "example", url: "https://example.com/example/SKILL.md",
|
|
19
|
+
digest: "sha256:abc")
|
|
20
|
+
|
|
21
|
+
entry = lockfile.read.dig("skills", "example.com/example")
|
|
22
|
+
expect(entry["host"]).to eq("example.com")
|
|
23
|
+
expect(entry["name"]).to eq("example")
|
|
24
|
+
expect(entry["url"]).to eq("https://example.com/example/SKILL.md")
|
|
25
|
+
expect(entry["digest"]).to eq("sha256:abc")
|
|
26
|
+
expect(entry["installedAt"]).to eq(entry["updatedAt"])
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "keeps the original installedAt but bumps updatedAt on re-install" do
|
|
30
|
+
lockfile.record(host: "example.com", name: "example", url: "https://example.com/example/SKILL.md",
|
|
31
|
+
digest: "sha256:abc")
|
|
32
|
+
first_installed_at = lockfile.read.dig("skills", "example.com/example", "installedAt")
|
|
33
|
+
|
|
34
|
+
lockfile.record(host: "example.com", name: "example", url: "https://example.com/example/SKILL.md",
|
|
35
|
+
digest: "sha256:def")
|
|
36
|
+
entry = lockfile.read.dig("skills", "example.com/example")
|
|
37
|
+
|
|
38
|
+
expect(entry["installedAt"]).to eq(first_installed_at)
|
|
39
|
+
expect(entry["digest"]).to eq("sha256:def")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "does not clobber an entry for the same skill name from a different host" do
|
|
43
|
+
lockfile.record(host: "example.com", name: "example", url: "https://example.com/example/SKILL.md",
|
|
44
|
+
digest: "sha256:abc")
|
|
45
|
+
lockfile.record(host: "other.example", name: "example", url: "https://other.example/example/SKILL.md",
|
|
46
|
+
digest: "sha256:def")
|
|
47
|
+
|
|
48
|
+
expect(lockfile.read["skills"].keys).to contain_exactly("example.com/example", "other.example/example")
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe "elelem-skills setup" do
|
|
4
|
+
let(:fixtures) { File.expand_path("../../fixtures/skills", __dir__) }
|
|
5
|
+
let(:agent) { Elelem::Session.new(Elelem::Agent.new(Object.new)) }
|
|
6
|
+
|
|
7
|
+
around do |example|
|
|
8
|
+
original = Elelem::Skills::Catalog::LOAD_PATHS
|
|
9
|
+
Elelem::Skills::Catalog.send(:remove_const, :LOAD_PATHS)
|
|
10
|
+
Elelem::Skills::Catalog.const_set(:LOAD_PATHS, [fixtures].freeze)
|
|
11
|
+
example.run
|
|
12
|
+
ensure
|
|
13
|
+
Elelem::Skills::Catalog.send(:remove_const, :LOAD_PATHS)
|
|
14
|
+
Elelem::Skills::Catalog.const_set(:LOAD_PATHS, original)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
before do
|
|
18
|
+
Elelem::Skills::Setup.call(agent)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe "skill tool" do
|
|
22
|
+
it "advertises the catalog in its description" do
|
|
23
|
+
tool = agent.toolbox.tool_for("skill")
|
|
24
|
+
|
|
25
|
+
expect(tool.description).to include("tdd: Test-driven development")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "returns the skill body and dir for a known skill" do
|
|
29
|
+
result = agent.toolbox.run("skill", { "name" => "tdd" })
|
|
30
|
+
|
|
31
|
+
expect(result).to be_ok
|
|
32
|
+
expect(result[:name]).to eq("tdd")
|
|
33
|
+
expect(result[:dir]).to eq(File.join(fixtures, "tdd"))
|
|
34
|
+
expect(result[:content]).to eq("# TDD\n\nRed, green, refactor.")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "fails for an unknown skill" do
|
|
38
|
+
result = agent.toolbox.run("skill", { "name" => "nope" })
|
|
39
|
+
|
|
40
|
+
expect(result).not_to be_ok
|
|
41
|
+
expect(result[:error]).to eq("unknown skill: nope")
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe "/skills command" do
|
|
46
|
+
it "lists the catalog" do
|
|
47
|
+
output = instance_double(Elelem::Output)
|
|
48
|
+
agent = Elelem::Session.new(Elelem::Agent.new(Object.new, output: output))
|
|
49
|
+
Elelem::Skills::Setup.call(agent)
|
|
50
|
+
|
|
51
|
+
expect(output).to receive(:say).with(
|
|
52
|
+
"- **tdd**: Test-driven development. Use when the user wants tests written first.", as: :markdown
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
agent.commands.run("skills", nil)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "shows a single skill's body" do
|
|
59
|
+
output = instance_double(Elelem::Output)
|
|
60
|
+
agent = Elelem::Session.new(Elelem::Agent.new(Object.new, output: output))
|
|
61
|
+
Elelem::Skills::Setup.call(agent)
|
|
62
|
+
|
|
63
|
+
expect(output).to receive(:say).with("# TDD\n\nRed, green, refactor.")
|
|
64
|
+
|
|
65
|
+
agent.commands.run("skills", "tdd")
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe "with an empty catalog" do
|
|
70
|
+
around do |example|
|
|
71
|
+
original = Elelem::Skills::Catalog::LOAD_PATHS
|
|
72
|
+
Elelem::Skills::Catalog.send(:remove_const, :LOAD_PATHS)
|
|
73
|
+
Elelem::Skills::Catalog.const_set(:LOAD_PATHS, [].freeze)
|
|
74
|
+
example.run
|
|
75
|
+
ensure
|
|
76
|
+
Elelem::Skills::Catalog.send(:remove_const, :LOAD_PATHS)
|
|
77
|
+
Elelem::Skills::Catalog.const_set(:LOAD_PATHS, original)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "still registers the skill tool and /skills command so remote skills can be fetched" do
|
|
81
|
+
agent = Elelem::Session.new(Elelem::Agent.new(Object.new))
|
|
82
|
+
Elelem::Config.apply(agent)
|
|
83
|
+
|
|
84
|
+
expect(agent.toolbox.tool_for("skill")).not_to be_nil
|
|
85
|
+
expect(agent.commands.names).to include("/skills")
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "sees a skill fetched via /skills fetch without re-running setup" do
|
|
89
|
+
remote_root = Dir.mktmpdir
|
|
90
|
+
begin
|
|
91
|
+
original_remote = Elelem::Skills::Catalog::REMOTE_SKILLS
|
|
92
|
+
Elelem::Skills::Catalog.send(:remove_const, :REMOTE_SKILLS)
|
|
93
|
+
Elelem::Skills::Catalog.const_set(:REMOTE_SKILLS, remote_root)
|
|
94
|
+
|
|
95
|
+
output = instance_double(Elelem::Output)
|
|
96
|
+
allow(output).to receive(:say)
|
|
97
|
+
agent = Elelem::Session.new(Elelem::Agent.new(Object.new, output: output))
|
|
98
|
+
Elelem::Skills::Setup.call(agent)
|
|
99
|
+
|
|
100
|
+
fetcher = instance_double(Elelem::Skills::Fetcher, fetch: ["wrangler"], changed: [])
|
|
101
|
+
allow(Elelem::Skills::Fetcher).to receive(:new).and_return(fetcher)
|
|
102
|
+
skill_dir = File.join(remote_root, "example.com", "wrangler")
|
|
103
|
+
FileUtils.mkdir_p(skill_dir)
|
|
104
|
+
File.write(File.join(skill_dir, "SKILL.md"), <<~SKILL)
|
|
105
|
+
---
|
|
106
|
+
name: wrangler
|
|
107
|
+
description: fetched from example.com
|
|
108
|
+
---
|
|
109
|
+
body
|
|
110
|
+
SKILL
|
|
111
|
+
|
|
112
|
+
agent.commands.run("skills", "fetch example.com")
|
|
113
|
+
|
|
114
|
+
expect(output).to have_received(:say).with(/Installed: wrangler/)
|
|
115
|
+
result = agent.toolbox.run("skill", { "name" => "wrangler" })
|
|
116
|
+
expect(result).to be_ok
|
|
117
|
+
ensure
|
|
118
|
+
FileUtils.rm_rf(remote_root)
|
|
119
|
+
Elelem::Skills::Catalog.send(:remove_const, :REMOTE_SKILLS)
|
|
120
|
+
Elelem::Skills::Catalog.const_set(:REMOTE_SKILLS, original_remote)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Elelem::Skills::SkillFile do
|
|
4
|
+
describe ".parse" do
|
|
5
|
+
it "parses frontmatter and body into a Skill" do
|
|
6
|
+
text = <<~SKILL
|
|
7
|
+
---
|
|
8
|
+
name: tdd
|
|
9
|
+
description: Test-driven development.
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# TDD
|
|
13
|
+
|
|
14
|
+
Red, green, refactor.
|
|
15
|
+
SKILL
|
|
16
|
+
|
|
17
|
+
skill = described_class.parse(text, path: "/skills/tdd/SKILL.md")
|
|
18
|
+
|
|
19
|
+
expect(skill.name).to eq("tdd")
|
|
20
|
+
expect(skill.description).to eq("Test-driven development.")
|
|
21
|
+
expect(skill.dir).to eq("/skills/tdd")
|
|
22
|
+
expect(skill.body).to eq("# TDD\n\nRed, green, refactor.")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "returns nil when description is missing" do
|
|
26
|
+
text = <<~SKILL
|
|
27
|
+
---
|
|
28
|
+
name: tdd
|
|
29
|
+
---
|
|
30
|
+
body
|
|
31
|
+
SKILL
|
|
32
|
+
|
|
33
|
+
expect(described_class.parse(text, path: "SKILL.md")).to be_nil
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "returns nil when there is no frontmatter" do
|
|
37
|
+
expect(described_class.parse("just a body, no frontmatter\n", path: "SKILL.md")).to be_nil
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe ".load" do
|
|
42
|
+
it "reads the file and parses it" do
|
|
43
|
+
fixtures = File.expand_path("../../fixtures/skills", __dir__)
|
|
44
|
+
|
|
45
|
+
skill = described_class.load(File.join(fixtures, "tdd", "SKILL.md"))
|
|
46
|
+
|
|
47
|
+
expect(skill.name).to eq("tdd")
|
|
48
|
+
expect(skill.dir).to eq(File.join(fixtures, "tdd"))
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "returns nil for a skill with no description" do
|
|
52
|
+
fixtures = File.expand_path("../../fixtures/skills", __dir__)
|
|
53
|
+
|
|
54
|
+
skill = described_class.load(File.join(fixtures, "no-description", "SKILL.md"))
|
|
55
|
+
|
|
56
|
+
expect(skill).to be_nil
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "reads a file with Windows line endings and a byte order mark" do
|
|
61
|
+
text = "\uFEFF---\r\nname: win\r\ndescription: Saved on Windows.\r\n---\r\nBody.\r\n"
|
|
62
|
+
skill = described_class.parse(text, path: "/skills/win/SKILL.md")
|
|
63
|
+
|
|
64
|
+
expect([skill.name, skill.description, skill.body]).to eq(["win", "Saved on Windows.", "Body."])
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "loads a UTF-8 file with a byte order mark under a non-UTF-8 locale" do
|
|
68
|
+
Dir.mktmpdir do |dir|
|
|
69
|
+
path = File.join(dir, "SKILL.md")
|
|
70
|
+
File.binwrite(path, "\xEF\xBB\xBF---\r\nname: caf\u00e9\r\ndescription: Accents.\r\n---\r\nBody.\r\n")
|
|
71
|
+
original = Encoding.default_external
|
|
72
|
+
Encoding.default_external = Encoding::US_ASCII
|
|
73
|
+
|
|
74
|
+
expect(described_class.load(path).name).to eq("caf\u00e9")
|
|
75
|
+
ensure
|
|
76
|
+
Encoding.default_external = original
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
data/spec/spec_helper.rb
ADDED