octomind 0.25.0

Session-based AI development assistant with conversational codebase interaction, multimodal vision support, built-in MCP tools, and multi-provider AI integration
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
// Copyright 2026 Muvon Un Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#[cfg(test)]
mod tests {
	use crate::mcp::core::skill::{
		build_resource_catalog, has_activate_script, has_validate_script, parse_skill_meta,
	};
	use std::fs;

	// ---------------------------------------------------------------------------
	// parse_skill_meta
	// ---------------------------------------------------------------------------

	#[test]
	fn test_parse_skill_meta_valid_minimal() {
		let content = "---\nname: my-skill\ndescription: Does something useful\n---\n\n# Body";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.name, "my-skill");
		assert_eq!(meta.description, "Does something useful");
		assert!(meta.compatibility.is_none());
		assert!(meta.license.is_none());
		assert!(meta.allowed_tools.is_empty());
		assert!(meta.capabilities.is_empty());
		assert!(meta.domains.is_empty());
	}

	#[test]
	fn test_parse_skill_meta_all_fields() {
		let content = "---\nname: full-skill\ndescription: A complete skill\ncompatibility: developer\nlicense: MIT\nallowed-tools: shell view text_editor\n---\n\n# Instructions\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.name, "full-skill");
		assert_eq!(meta.description, "A complete skill");
		assert_eq!(meta.compatibility.as_deref(), Some("developer"));
		assert_eq!(meta.license.as_deref(), Some("MIT"));
		assert_eq!(meta.allowed_tools, vec!["shell", "view", "text_editor"]);
	}

	#[test]
	fn test_parse_skill_meta_quoted_values() {
		let content = "---\nname: \"quoted-skill\"\ndescription: 'single quoted'\n---\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.name, "quoted-skill");
		assert_eq!(meta.description, "single quoted");
	}

	#[test]
	fn test_parse_skill_meta_no_frontmatter() {
		let content = "# Just a markdown file\n\nNo frontmatter here.";
		assert!(parse_skill_meta(content).is_none());
	}

	#[test]
	fn test_parse_skill_meta_missing_name() {
		let content = "---\ndescription: No name field\n---\n";
		assert!(parse_skill_meta(content).is_none());
	}

	#[test]
	fn test_parse_skill_meta_missing_description() {
		let content = "---\nname: no-desc\n---\n";
		assert!(parse_skill_meta(content).is_none());
	}

	#[test]
	fn test_parse_skill_meta_unclosed_frontmatter() {
		// No closing ---
		let content = "---\nname: broken\ndescription: no close\n";
		assert!(parse_skill_meta(content).is_none());
	}

	#[test]
	fn test_parse_skill_meta_allowed_tools_single() {
		let content = "---\nname: s\ndescription: d\nallowed-tools: shell\n---\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.allowed_tools, vec!["shell"]);
	}

	#[test]
	fn test_parse_skill_meta_allowed_tools_empty_value() {
		// allowed-tools present but empty — should produce empty vec
		let content = "---\nname: s\ndescription: d\nallowed-tools: \n---\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert!(meta.allowed_tools.is_empty());
	}

	#[test]
	fn test_parse_skill_meta_leading_whitespace() {
		// File may have leading whitespace/newlines before ---
		let content = "\n\n---\nname: ws-skill\ndescription: whitespace before\n---\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.name, "ws-skill");
	}

	#[test]
	fn test_parse_skill_meta_unknown_fields_ignored() {
		let content =
			"---\nname: s\ndescription: d\nunknown-field: ignored\nanother: also-ignored\n---\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.name, "s");
		assert_eq!(meta.description, "d");
	}

	// ---------------------------------------------------------------------------
	// capabilities and domains parsing
	// ---------------------------------------------------------------------------

	#[test]
	fn test_parse_skill_meta_capabilities_space_delimited() {
		let content = "---\nname: s\ndescription: d\ncapabilities: git memory codesearch\n---\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.capabilities, vec!["git", "memory", "codesearch"]);
	}

	#[test]
	fn test_parse_skill_meta_capabilities_array_syntax() {
		let content = "---\nname: s\ndescription: d\ncapabilities: [\"git\", \"memory\"]\n---\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.capabilities, vec!["git", "memory"]);
	}

	#[test]
	fn test_parse_skill_meta_capabilities_array_unquoted() {
		let content = "---\nname: s\ndescription: d\ncapabilities: [git, memory]\n---\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.capabilities, vec!["git", "memory"]);
	}

	#[test]
	fn test_parse_skill_meta_domains_space_delimited() {
		let content = "---\nname: s\ndescription: d\ndomains: developer devops\n---\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.domains, vec!["developer", "devops"]);
	}

	#[test]
	fn test_parse_skill_meta_domains_array_syntax() {
		let content = "---\nname: s\ndescription: d\ndomains: [\"developer\", \"devops\"]\n---\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.domains, vec!["developer", "devops"]);
	}

	#[test]
	fn test_parse_skill_meta_empty_capabilities() {
		let content = "---\nname: s\ndescription: d\ncapabilities: \n---\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert!(meta.capabilities.is_empty());
	}

	#[test]
	fn test_parse_skill_meta_all_new_fields() {
		let content = "---\nname: rust-dev\ndescription: Rust development\ncapabilities: git memory\ndomains: developer\nallowed-tools: shell text_editor\n---\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.name, "rust-dev");
		assert_eq!(meta.capabilities, vec!["git", "memory"]);
		assert_eq!(meta.domains, vec!["developer"]);
		assert_eq!(meta.allowed_tools, vec!["shell", "text_editor"]);
	}

	// ---------------------------------------------------------------------------
	// rules parsing
	// ---------------------------------------------------------------------------

	#[test]
	fn test_parse_rules_file() {
		let content = "---\nname: s\ndescription: d\nrules:\n  - file(Cargo.toml)\n---\nbody\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.rules.len(), 1);
		assert_eq!(meta.rules[0].len(), 1);
		assert!(
			matches!(&meta.rules[0][0], crate::mcp::core::skill::ActivateCheck::File(p) if p == "Cargo.toml")
		);
	}

	#[test]
	fn test_parse_rules_multiple_groups() {
		let content = "---\nname: s\ndescription: d\nrules:\n  - file(Cargo.toml)\n  - content(rust)\n---\nbody\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.rules.len(), 2);
		assert_eq!(meta.rules[0].len(), 1);
		assert_eq!(meta.rules[1].len(), 1);
		assert!(
			matches!(&meta.rules[0][0], crate::mcp::core::skill::ActivateCheck::File(p) if p == "Cargo.toml")
		);
		assert!(
			matches!(&meta.rules[1][0], crate::mcp::core::skill::ActivateCheck::Content(p) if p == "rust")
		);
	}

	#[test]
	fn test_parse_rules_multiple_checks_in_group() {
		let content =
			"---\nname: s\ndescription: d\nrules:\n  - content(rust) content(cargo)\n---\nbody\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.rules.len(), 1);
		assert_eq!(meta.rules[0].len(), 2);
		assert!(
			matches!(&meta.rules[0][0], crate::mcp::core::skill::ActivateCheck::Content(p) if p == "rust")
		);
		assert!(
			matches!(&meta.rules[0][1], crate::mcp::core::skill::ActivateCheck::Content(p) if p == "cargo")
		);
	}

	#[test]
	fn test_parse_rules_grep_with_path() {
		let content = "---\nname: s\ndescription: d\nrules:\n  - grep(fn main, *.rs)\n---\nbody\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.rules.len(), 1);
		assert_eq!(meta.rules[0].len(), 1);
		assert!(
			matches!(&meta.rules[0][0], crate::mcp::core::skill::ActivateCheck::Grep { pattern, path } if pattern == "fn main" && path.as_deref() == Some("*.rs"))
		);
	}

	#[test]
	fn test_parse_rules_env_and_match() {
		let content = "---\nname: s\ndescription: d\nrules:\n  - env(CI=true) match(\\bdeploy\\b)\n---\nbody\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.rules.len(), 1);
		assert_eq!(meta.rules[0].len(), 2);
		assert!(
			matches!(&meta.rules[0][0], crate::mcp::core::skill::ActivateCheck::Env { var, value } if var == "CI" && value.as_deref() == Some("true"))
		);
		assert!(
			matches!(&meta.rules[0][1], crate::mcp::core::skill::ActivateCheck::Match(p) if p == r"\bdeploy\b")
		);
	}

	#[test]
	fn test_parse_no_rules() {
		let content = "---\nname: s\ndescription: d\n---\nbody\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert!(meta.rules.is_empty());
	}

	#[test]
	fn test_parse_rules_with_other_fields() {
		let content = "---\nname: programming-rust\ndescription: Rust dev\ncapabilities: programming-rust\ndomains: developer\nrules:\n  - file(Cargo.toml)\n  - content(rust)\n---\nbody\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.name, "programming-rust");
		assert_eq!(meta.capabilities, vec!["programming-rust"]);
		assert_eq!(meta.domains, vec!["developer"]);
		assert_eq!(meta.rules.len(), 2);
	}

	#[test]
	fn test_parse_rules_bin() {
		let content = "---\nname: s\ndescription: d\nrules:\n  - bin(cargo)\n---\nbody\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.rules.len(), 1);
		assert!(
			matches!(&meta.rules[0][0], crate::mcp::core::skill::ActivateCheck::Bin(p) if p == "cargo")
		);
	}

	#[test]
	fn test_parse_rules_session() {
		let content = "---\nname: s\ndescription: d\nrules:\n  - session(developer)\n---\nbody\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.rules.len(), 1);
		assert!(
			matches!(&meta.rules[0][0], crate::mcp::core::skill::ActivateCheck::Session(p) if p == "developer")
		);
	}

	#[test]
	fn test_parse_rules_workdir() {
		let content = "---\nname: s\ndescription: d\nrules:\n  - workdir(rust)\n---\nbody\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.rules.len(), 1);
		assert!(
			matches!(&meta.rules[0][0], crate::mcp::core::skill::ActivateCheck::Workdir(p) if p == "rust")
		);
	}

	#[test]
	fn test_parse_rules_combined_new_checks() {
		let content = "---\nname: s\ndescription: d\nrules:\n  - bin(cargo) file(Cargo.toml)\n  - session(dev) workdir(rust)\n---\nbody\n";
		let meta = parse_skill_meta(content).expect("should parse");
		assert_eq!(meta.rules.len(), 2);
		assert_eq!(meta.rules[0].len(), 2);
		assert_eq!(meta.rules[1].len(), 2);
		assert!(
			matches!(&meta.rules[0][0], crate::mcp::core::skill::ActivateCheck::Bin(p) if p == "cargo")
		);
		assert!(
			matches!(&meta.rules[0][1], crate::mcp::core::skill::ActivateCheck::File(p) if p == "Cargo.toml")
		);
		assert!(
			matches!(&meta.rules[1][0], crate::mcp::core::skill::ActivateCheck::Session(p) if p == "dev")
		);
		assert!(
			matches!(&meta.rules[1][1], crate::mcp::core::skill::ActivateCheck::Workdir(p) if p == "rust")
		);
	}

	// ---------------------------------------------------------------------------
	// activate rule evaluation
	// ---------------------------------------------------------------------------

	#[test]
	fn test_activate_check_file_exists() {
		let dir = tempfile::tempdir().unwrap();
		fs::write(dir.path().join("Cargo.toml"), "").unwrap();
		let check = crate::mcp::core::skill::ActivateCheck::File("Cargo.toml".to_string());
		assert!(check.matches("", dir.path(), ""));
		assert!(
			!crate::mcp::core::skill::ActivateCheck::File("go.mod".to_string()).matches(
				"",
				dir.path(),
				""
			)
		);
	}

	#[test]
	fn test_activate_check_content_match() {
		let check = crate::mcp::core::skill::ActivateCheck::Content("rust".to_string());
		assert!(check.matches("lets code in rust", std::path::Path::new("."), ""));
		assert!(check.matches("RUST is great", std::path::Path::new("."), ""));
		assert!(!check.matches("lets code in python", std::path::Path::new("."), ""));
	}

	#[test]
	fn test_activate_check_content_word_boundary() {
		let check = crate::mcp::core::skill::ActivateCheck::Content("rust".to_string());
		assert!(check.matches("lets code in rust", std::path::Path::new("."), ""));
		assert!(check.matches("RUST is great", std::path::Path::new("."), ""));
		assert!(!check.matches("lets code in python", std::path::Path::new("."), ""));
		// Word boundary: "rust" should not match "thrust"
		assert!(!check.matches("thrust is powerful", std::path::Path::new("."), ""));
	}

	#[test]
	fn test_activate_check_bin_found() {
		// "ls" exists on all platforms
		let check = crate::mcp::core::skill::ActivateCheck::Bin("ls".to_string());
		assert!(check.matches("", std::path::Path::new("."), ""));
	}

	#[test]
	fn test_activate_check_bin_not_found() {
		let check =
			crate::mcp::core::skill::ActivateCheck::Bin("nonexistent_binary_xyz_12345".to_string());
		assert!(!check.matches("", std::path::Path::new("."), ""));
	}

	#[test]
	fn test_activate_check_session_match() {
		let check = crate::mcp::core::skill::ActivateCheck::Session("octomind".to_string());
		assert!(check.matches(
			"",
			std::path::Path::new("."),
			"260421-141708-octomind-a1b2c3"
		));
		// Case-insensitive
		assert!(check.matches("", std::path::Path::new("."), "Octomind-Session"));
	}

	#[test]
	fn test_activate_check_session_no_match() {
		let check = crate::mcp::core::skill::ActivateCheck::Session("python".to_string());
		assert!(!check.matches(
			"",
			std::path::Path::new("."),
			"260421-141708-octomind-a1b2c3"
		));
	}

	#[test]
	fn test_activate_check_workdir_match() {
		let check = crate::mcp::core::skill::ActivateCheck::Workdir("octomind".to_string());
		assert!(check.matches("", std::path::Path::new("/Users/dev/octomind"), ""));
		// Case-insensitive
		assert!(check.matches("", std::path::Path::new("/Users/dev/Octomind"), ""));
	}

	#[test]
	fn test_activate_check_workdir_no_match() {
		let check = crate::mcp::core::skill::ActivateCheck::Workdir("python".to_string());
		assert!(!check.matches("", std::path::Path::new("/Users/dev/octomind"), ""));
	}

	// ---------------------------------------------------------------------------
	// activate/validate script discovery
	// ---------------------------------------------------------------------------

	#[test]
	fn test_has_activate_script() {
		let dir = tempfile::tempdir().unwrap();
		assert!(!has_activate_script(dir.path()));
		fs::write(dir.path().join("activate"), "#!/bin/bash\nexit 0").unwrap();
		assert!(has_activate_script(dir.path()));
	}

	#[test]
	fn test_has_validate_script() {
		let dir = tempfile::tempdir().unwrap();
		assert!(!has_validate_script(dir.path()));
		fs::write(dir.path().join("validate"), "#!/bin/bash\nexit 0").unwrap();
		assert!(has_validate_script(dir.path()));
	}

	// ---------------------------------------------------------------------------
	// build_resource_catalog
	// ---------------------------------------------------------------------------

	#[test]
	fn test_build_resource_catalog_empty_dir() {
		let dir = tempfile::tempdir().unwrap();
		let result = build_resource_catalog(dir.path());
		assert!(result.is_empty(), "no subdirs → empty catalog");
	}

	#[test]
	fn test_build_resource_catalog_no_known_subdirs() {
		let dir = tempfile::tempdir().unwrap();
		fs::create_dir(dir.path().join("other")).unwrap();
		fs::write(dir.path().join("other/file.txt"), "content").unwrap();
		let result = build_resource_catalog(dir.path());
		assert!(result.is_empty(), "unknown subdir → not included");
	}

	#[test]
	fn test_build_resource_catalog_scripts_only() {
		let dir = tempfile::tempdir().unwrap();
		let scripts = dir.path().join("scripts");
		fs::create_dir(&scripts).unwrap();
		fs::write(scripts.join("deploy.sh"), "#!/bin/bash\necho hi").unwrap();

		let result = build_resource_catalog(dir.path());
		assert!(result.contains("**scripts/**"));
		assert!(result.contains("deploy.sh"));
		assert!(result.contains(&scripts.join("deploy.sh").display().to_string()));
		assert!(!result.contains("**references/**"));
		assert!(!result.contains("**assets/**"));
	}

	#[test]
	fn test_build_resource_catalog_all_subdirs() {
		let dir = tempfile::tempdir().unwrap();

		let scripts = dir.path().join("scripts");
		fs::create_dir(&scripts).unwrap();
		fs::write(scripts.join("run.sh"), "#!/bin/bash").unwrap();

		let refs = dir.path().join("references");
		fs::create_dir(&refs).unwrap();
		fs::write(refs.join("guide.md"), "# Guide").unwrap();

		let assets = dir.path().join("assets");
		fs::create_dir(&assets).unwrap();
		fs::write(assets.join("template.json"), "{}").unwrap();

		let result = build_resource_catalog(dir.path());
		assert!(result.contains("**scripts/**"));
		assert!(result.contains("run.sh"));
		assert!(result.contains("**references/**"));
		assert!(result.contains("guide.md"));
		assert!(result.contains("**assets/**"));
		assert!(result.contains("template.json"));
	}

	#[test]
	fn test_build_resource_catalog_empty_subdir_skipped() {
		let dir = tempfile::tempdir().unwrap();
		// scripts exists but is empty — should not appear in output
		fs::create_dir(dir.path().join("scripts")).unwrap();
		// references has a file
		let refs = dir.path().join("references");
		fs::create_dir(&refs).unwrap();
		fs::write(refs.join("note.md"), "note").unwrap();

		let result = build_resource_catalog(dir.path());
		assert!(
			!result.contains("**scripts/**"),
			"empty scripts/ should be skipped"
		);
		assert!(result.contains("**references/**"));
	}

	#[test]
	fn test_build_resource_catalog_sorted_entries() {
		let dir = tempfile::tempdir().unwrap();
		let scripts = dir.path().join("scripts");
		fs::create_dir(&scripts).unwrap();
		fs::write(scripts.join("z_last.sh"), "").unwrap();
		fs::write(scripts.join("a_first.sh"), "").unwrap();
		fs::write(scripts.join("m_middle.sh"), "").unwrap();

		let result = build_resource_catalog(dir.path());
		let pos_a = result.find("a_first.sh").unwrap();
		let pos_m = result.find("m_middle.sh").unwrap();
		let pos_z = result.find("z_last.sh").unwrap();
		assert!(
			pos_a < pos_m && pos_m < pos_z,
			"entries should be sorted alphabetically"
		);
	}

	#[test]
	fn test_build_resource_catalog_subdirs_not_listed_as_files() {
		let dir = tempfile::tempdir().unwrap();
		let scripts = dir.path().join("scripts");
		fs::create_dir(&scripts).unwrap();
		// A nested directory inside scripts — should be ignored (not a file)
		fs::create_dir(scripts.join("nested")).unwrap();
		fs::write(scripts.join("real.sh"), "").unwrap();

		let result = build_resource_catalog(dir.path());
		assert!(result.contains("real.sh"));
		assert!(
			!result.contains("nested"),
			"subdirectories should not appear as entries"
		);
	}

	#[test]
	fn test_build_resource_catalog_header_format() {
		let dir = tempfile::tempdir().unwrap();
		let refs = dir.path().join("references");
		fs::create_dir(&refs).unwrap();
		fs::write(refs.join("doc.md"), "content").unwrap();

		let result = build_resource_catalog(dir.path());
		assert!(result.starts_with("\n\n## Skill Resources\n\n"));
	}
}