pi-harness-runtime 1.1.410 → 1.1.412

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.
Files changed (171) hide show
  1. package/harness/notification-settings.ts +130 -0
  2. package/harness/skill-remote-source.ts +157 -0
  3. package/harness/skill-sync.ts +74 -22
  4. package/harness/skills-startup.ts +202 -0
  5. package/harness/startup-report.ts +98 -56
  6. package/harness-startup-status.ts +31 -2
  7. package/index.ts +125 -31
  8. package/package.json +1 -1
  9. package/packages/a2a-adapter/package.json +1 -1
  10. package/packages/agent-policy/package.json +1 -1
  11. package/packages/architecture-generator/package.json +1 -1
  12. package/packages/auth/package.json +1 -1
  13. package/packages/autonomous-refactor/package.json +1 -1
  14. package/packages/autonomous-runtime/package.json +1 -1
  15. package/packages/autonomous-runtime/test/types.test.ts +59 -32
  16. package/packages/cache-strategy/package.json +1 -1
  17. package/packages/capability-registry/package.json +1 -1
  18. package/packages/checkpoint/package.json +1 -1
  19. package/packages/cli-plugin-sdk/package.json +1 -1
  20. package/packages/clipboard/package.json +1 -1
  21. package/packages/clipboard-plugin/package.json +1 -1
  22. package/packages/code-generation/package.json +1 -1
  23. package/packages/code-review/package.json +1 -1
  24. package/packages/codex-adapter/package.json +1 -1
  25. package/packages/codex-watcher/package.json +1 -1
  26. package/packages/config-capture/package.json +1 -1
  27. package/packages/connection-runtime/package.json +1 -1
  28. package/packages/context-compiler/package.json +1 -1
  29. package/packages/context-discovery/package.json +1 -1
  30. package/packages/context-manager/package.json +1 -1
  31. package/packages/contracts/package.json +1 -1
  32. package/packages/cookie-sanitizer/package.json +1 -1
  33. package/packages/cookie-sanitizer/test/sync.test.ts +7 -1
  34. package/packages/cost-optimizer/package.json +1 -1
  35. package/packages/dependency-analyzer/dist/src/imports.js +3 -3
  36. package/packages/dependency-analyzer/dist/src/imports.js.map +1 -1
  37. package/packages/dependency-analyzer/package.json +1 -1
  38. package/packages/dependency-analyzer/src/imports.ts +3 -3
  39. package/packages/dependency-analyzer/test/analyzer.test.ts +1 -0
  40. package/packages/django-plugin/package.json +1 -1
  41. package/packages/doc-generator/package.json +1 -1
  42. package/packages/durable-review/package.json +1 -1
  43. package/packages/durable-review/test/acceptance.test.ts +24 -2
  44. package/packages/durable-review/test/smoke.test.ts +85 -47
  45. package/packages/e2e-tester/package.json +1 -1
  46. package/packages/evaluation-engine/package.json +1 -1
  47. package/packages/evaluation-runner/package.json +1 -1
  48. package/packages/event-bus/package.json +1 -1
  49. package/packages/event-bus/test/bus.test.ts +16 -4
  50. package/packages/event-sink/package.json +1 -1
  51. package/packages/event-store/package.json +1 -1
  52. package/packages/experience-replay/package.json +1 -1
  53. package/packages/feedback-collector/package.json +1 -1
  54. package/packages/file-copy-helper/package.json +1 -1
  55. package/packages/framework-detector/package.json +1 -1
  56. package/packages/framework-plugin-sdk/package.json +1 -1
  57. package/packages/frappe-plugin/package.json +1 -1
  58. package/packages/generic-web-plugin/package.json +1 -1
  59. package/packages/health-monitor/package.json +1 -1
  60. package/packages/intent-analyzer/package.json +1 -1
  61. package/packages/jev-judge/package.json +1 -1
  62. package/packages/knowledge-graph/package.json +1 -1
  63. package/packages/knowledge-retrieval/package.json +1 -1
  64. package/packages/laravel-plugin/package.json +1 -1
  65. package/packages/learning-engine/package.json +1 -1
  66. package/packages/logging/package.json +1 -1
  67. package/packages/mcp-adapter/package.json +1 -1
  68. package/packages/memory-engine/package.json +1 -1
  69. package/packages/milestone-manager/package.json +1 -1
  70. package/packages/model-registry/package.json +1 -1
  71. package/packages/nextjs-plugin/package.json +1 -1
  72. package/packages/notification/package.json +1 -1
  73. package/packages/observability/package.json +1 -1
  74. package/packages/okf-indexer/package.json +1 -1
  75. package/packages/paperclip-integration/package.json +1 -1
  76. package/packages/performance-optimizer/package.json +1 -1
  77. package/packages/permission-mode/package.json +1 -1
  78. package/packages/privilege-broker/package.json +1 -1
  79. package/packages/project-analyzer/package.json +1 -1
  80. package/packages/project-bootstrap/package.json +1 -1
  81. package/packages/projection-engine/package.json +1 -1
  82. package/packages/prompt-compiler/package.json +1 -1
  83. package/packages/prompt-versioning/package.json +1 -1
  84. package/packages/provider-adapter-sdk/package.json +1 -1
  85. package/packages/provider-router/package.json +1 -1
  86. package/packages/provider-selector/package.json +1 -1
  87. package/packages/providers/package.json +1 -1
  88. package/packages/qdrant-skills/dist/client.d.ts.map +1 -1
  89. package/packages/qdrant-skills/dist/client.js +21 -8
  90. package/packages/qdrant-skills/dist/client.js.map +1 -1
  91. package/packages/qdrant-skills/dist/embedder.d.ts +37 -0
  92. package/packages/qdrant-skills/dist/embedder.d.ts.map +1 -1
  93. package/packages/qdrant-skills/dist/embedder.js +65 -1
  94. package/packages/qdrant-skills/dist/embedder.js.map +1 -1
  95. package/packages/qdrant-skills/dist/index.d.ts +1 -1
  96. package/packages/qdrant-skills/dist/index.d.ts.map +1 -1
  97. package/packages/qdrant-skills/dist/index.js +1 -1
  98. package/packages/qdrant-skills/dist/index.js.map +1 -1
  99. package/packages/qdrant-skills/package.json +1 -1
  100. package/packages/qdrant-skills/src/client.ts +19 -8
  101. package/packages/qdrant-skills/src/embedder.ts +103 -1
  102. package/packages/qdrant-skills/src/index.ts +5 -0
  103. package/packages/qdrant-skills/test/collection-info.test.ts +129 -0
  104. package/packages/qdrant-skills/test/embedder-batch.test.ts +184 -0
  105. package/packages/quota-manager/package.json +1 -1
  106. package/packages/rate-limiter/package.json +1 -1
  107. package/packages/react-vite-plugin/package.json +1 -1
  108. package/packages/relay/package.json +1 -1
  109. package/packages/release-manager/package.json +1 -1
  110. package/packages/requirement-compiler/package.json +1 -1
  111. package/packages/runtime/package.json +1 -1
  112. package/packages/scheduler/package.json +1 -1
  113. package/packages/scheduler-adapter/package.json +1 -1
  114. package/packages/session/package.json +1 -1
  115. package/packages/session-api/package.json +1 -1
  116. package/packages/session-export/package.json +1 -1
  117. package/packages/shared-context/package.json +1 -1
  118. package/packages/skill-mcp-client/package.json +1 -1
  119. package/packages/skill-registry/package.json +1 -1
  120. package/packages/skills/dist/index.d.ts +19 -1
  121. package/packages/skills/dist/index.d.ts.map +1 -1
  122. package/packages/skills/dist/index.js +7 -2
  123. package/packages/skills/dist/index.js.map +1 -1
  124. package/packages/skills/dist/loader.d.ts +273 -3
  125. package/packages/skills/dist/loader.d.ts.map +1 -1
  126. package/packages/skills/dist/loader.js +525 -36
  127. package/packages/skills/dist/loader.js.map +1 -1
  128. package/packages/skills/dist/remote-source.d.ts +107 -0
  129. package/packages/skills/dist/remote-source.d.ts.map +1 -0
  130. package/packages/skills/dist/remote-source.js +79 -0
  131. package/packages/skills/dist/remote-source.js.map +1 -0
  132. package/packages/skills/dist/vector-schema.d.ts +58 -0
  133. package/packages/skills/dist/vector-schema.d.ts.map +1 -0
  134. package/packages/skills/dist/vector-schema.js +55 -0
  135. package/packages/skills/dist/vector-schema.js.map +1 -0
  136. package/packages/skills/package.json +1 -1
  137. package/packages/skills/src/index.ts +28 -5
  138. package/packages/skills/src/loader.ts +688 -53
  139. package/packages/skills/src/remote-source.ts +148 -0
  140. package/packages/skills/src/vector-schema.ts +72 -0
  141. package/packages/skills/test/init-skills.test.ts +107 -111
  142. package/packages/skills/test/remote-skills.test.ts +242 -0
  143. package/packages/skills/test/remote-source.test.ts +248 -0
  144. package/packages/skills/test/vector-indexing.test.ts +205 -0
  145. package/packages/sprint-planner/package.json +1 -1
  146. package/packages/subscription-engine/package.json +1 -1
  147. package/packages/task-compiler/package.json +1 -1
  148. package/packages/telegram/package.json +1 -1
  149. package/packages/tencentdb-memory/package.json +1 -1
  150. package/packages/tencentdb-sync/package.json +1 -1
  151. package/packages/test-data-generator/package.json +1 -1
  152. package/packages/test-generator/package.json +1 -1
  153. package/packages/todo-bd-sync/package.json +1 -1
  154. package/packages/token-estimation/package.json +1 -1
  155. package/packages/token-optimizer/package.json +1 -1
  156. package/packages/tooling-preference/package.json +1 -1
  157. package/packages/trajectory/package.json +1 -1
  158. package/packages/tui/package.json +1 -1
  159. package/packages/two-phase-review/package.json +1 -1
  160. package/packages/types/package.json +1 -1
  161. package/packages/voice-api/package.json +1 -1
  162. package/packages/webmcp-tester/package.json +1 -1
  163. package/packages/wiki/package.json +1 -1
  164. package/packages/workflow-events/package.json +1 -1
  165. package/packages/workspace-scanner/package.json +1 -1
  166. package/packages/workspace-scanner/test/scanner.test.ts +4 -3
  167. package/packages/worktree/package.json +1 -1
  168. package/packages/write-review/package.json +1 -1
  169. package/scripts/sync-to-qdrant.ts +79 -14
  170. package/packages/autonomous-runtime/test/autonomous-runtime.test.ts +0 -194
  171. package/packages/autonomous-runtime/test/inbox.test.ts +0 -80
@@ -0,0 +1,148 @@
1
+ /**
2
+ * The server-held skills.
3
+ *
4
+ * The vector store holds an INDEX: the name, the description and a
5
+ * truncated body. That is enough to FIND a skill, but not to use it - a
6
+ * complete SKILL.md (with its references and examples) is larger than a
7
+ * vector store payload should be.
8
+ *
9
+ * The remote source is therefore the authoritative store of the complete
10
+ * skill content. It is reached through an authenticated service, so the
11
+ * SERVER decides which skills this user may see. A client never decides
12
+ * that on its own.
13
+ */
14
+
15
+ import type { Skill } from "./types.js";
16
+
17
+ /** A skill the server holds. */
18
+ export interface RemoteSkill {
19
+ /** The id the server knows the skill by. */
20
+ id: string;
21
+ /** The name of the skill. */
22
+ name: string;
23
+ /** What the skill does. */
24
+ description: string;
25
+ /** The version of the content. */
26
+ version?: string;
27
+ /** When the content changed the last time. */
28
+ updatedAt?: string;
29
+ /** The content of the skill (the body of SKILL.md). */
30
+ content?: string;
31
+ /**
32
+ * Whether the content is the COMPLETE skill.
33
+ *
34
+ * A vector store payload carries a truncated body - that is not a
35
+ * complete skill. The service returns the whole thing, so it sets
36
+ * this flag.
37
+ */
38
+ contentComplete?: boolean;
39
+ }
40
+
41
+ /** Where the server-held skills come from. */
42
+ export interface RemoteSkillSource {
43
+ /**
44
+ * The skills the server holds for this user and workspace.
45
+ *
46
+ * @param options The search term and the number of skills to return.
47
+ */
48
+ list(options?: { search?: string; limit?: number }): Promise<RemoteSkill[]>;
49
+ /** The complete content of one skill. */
50
+ get(id: string): Promise<RemoteSkill | null>;
51
+ }
52
+
53
+ /** The reasons a call to the remote source can fail. */
54
+ export type RemoteSkillFailure =
55
+ /** The service refused the call - the token is missing or wrong. */
56
+ | "denied"
57
+ /** The service could not be reached. */
58
+ | "unavailable";
59
+
60
+ /** The state of the server-held skills. */
61
+ export type RemoteSkillState =
62
+ /** No service is configured. */
63
+ | "not-configured"
64
+ /** The service refused the call. */
65
+ | "denied"
66
+ /** The service could not be reached. */
67
+ | "unavailable"
68
+ /** The service holds no skill for this user. */
69
+ | "empty"
70
+ /** The service holds skills. */
71
+ | "populated";
72
+
73
+ /** What the remote source knows. */
74
+ export interface RemoteSkillStats {
75
+ /** The state of the source. */
76
+ state: RemoteSkillState;
77
+ /** The number of skills the source holds. */
78
+ count: number;
79
+ /** The reason of a failed call. */
80
+ error?: string;
81
+ }
82
+
83
+ /**
84
+ * A skill from a remote record.
85
+ *
86
+ * The record carries the content, so the skill is usable without a local
87
+ * copy. The path stays empty: a server skill has no directory on this
88
+ * machine.
89
+ */
90
+ export function skillFromRemote(record: RemoteSkill): Skill {
91
+ const version = record.version;
92
+ return {
93
+ id: record.id,
94
+ path: "",
95
+ frontmatter: {
96
+ name: record.name,
97
+ description: record.description,
98
+ ...(version ? { version } : {}),
99
+ },
100
+ body: record.content ?? "",
101
+ references: [],
102
+ examples: [],
103
+ metadata: {
104
+ name: record.name,
105
+ description: record.description,
106
+ ...(version ? { version } : {}),
107
+ ...(record.updatedAt ? { updated_at: record.updatedAt } : {}),
108
+ },
109
+ loaded: true,
110
+ };
111
+ }
112
+
113
+ /**
114
+ * The version of a cached remote skill.
115
+ *
116
+ * A skill without a version cannot be compared - the cache keeps it.
117
+ */
118
+ export function remoteVersion(skill: Skill | undefined): string | undefined {
119
+ return skill?.frontmatter.version ?? skill?.metadata.version;
120
+ }
121
+
122
+ /**
123
+ * The safe reason of a failed call.
124
+ *
125
+ * The message never carries a credential: a token that a service echoed
126
+ * back is removed before the message leaves the process.
127
+ */
128
+ export function describeRemoteFailure(error: unknown): string {
129
+ const raw = error instanceof Error ? error.message : String(error ?? "");
130
+ const safe = raw
131
+ .replace(/bearer\s+\S+/gi, "bearer <redacted>")
132
+ .replace(/\b[A-Za-z0-9_-]{32,}\b/g, "<redacted>")
133
+ .replace(/\s+/g, " ")
134
+ .trim();
135
+ return safe.slice(0, 200) || "the service could not be reached";
136
+ }
137
+
138
+ /**
139
+ * Whether the cached skill is older than the record.
140
+ *
141
+ * A record without a version never replaces a cached skill: an unknown
142
+ * version is not evidence of a change.
143
+ */
144
+ export function isStale(cached: Skill | undefined, record: RemoteSkill): boolean {
145
+ if (!cached) return true;
146
+ if (!record.version) return false;
147
+ return remoteVersion(cached) !== record.version;
148
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * The vector schema of the skill collection.
3
+ *
4
+ * A Qdrant collection holds vectors of exactly ONE size. Two different
5
+ * embedding models produce two different vector sizes, so they must never
6
+ * write into the same collection: the second writer is rejected by the
7
+ * server with a dimension error, and the data of the first writer becomes
8
+ * unsearchable by the second.
9
+ *
10
+ * The collection name carries the model and a version, so a change of the
11
+ * model leads to a NEW collection instead of a silent mix of two vector
12
+ * spaces.
13
+ *
14
+ * The model itself lives in the Qdrant package (the embedder owns it). This
15
+ * module owns the collection - that is a decision of the skills domain, not
16
+ * of the vector store.
17
+ */
18
+
19
+ /**
20
+ * The collection the runtime indexes into and searches.
21
+ *
22
+ * `QDRANT_COLLECTION` overrides it, so a cluster that already holds a
23
+ * collection under another name keeps working.
24
+ */
25
+ export const SKILL_COLLECTION = "pi-harness-skills-openai-v1";
26
+
27
+ /**
28
+ * The collection that was used before the schema was versioned.
29
+ *
30
+ * It holds 384-dimensional vectors - the model that
31
+ * `scripts/sync-to-qdrant.ts` used - and is NOT compatible with the
32
+ * runtime. It is named here so a mismatch can name the real cause instead
33
+ * of only the numbers.
34
+ */
35
+ export const LEGACY_SKILL_COLLECTION = "pi-harness-skills";
36
+
37
+ /** The model of the legacy collection. */
38
+ export const LEGACY_SKILL_COLLECTION_MODEL = "sentence-transformers/all-MiniLM-L6-v2";
39
+
40
+ /** The vector size of the legacy collection. */
41
+ export const LEGACY_SKILL_COLLECTION_DIMENSIONS = 384;
42
+
43
+ /** The schema a skill collection is expected to have. */
44
+ export interface SkillVectorSchema {
45
+ /** The vector size. */
46
+ dimensions: number;
47
+ /** The distance metric. */
48
+ distance: string;
49
+ /** The embedding model, when it is known. */
50
+ model?: string;
51
+ }
52
+
53
+ /**
54
+ * Why the collection does not match the expected schema - or null when it
55
+ * does.
56
+ *
57
+ * The message names the numbers, so the reader can tell WHICH schema the
58
+ * collection was built with.
59
+ */
60
+ export function describeSkillSchemaMismatch(
61
+ actual: { dimensions?: number; distance?: string },
62
+ expected: SkillVectorSchema,
63
+ ): string | null {
64
+ if (actual.dimensions !== undefined && actual.dimensions !== expected.dimensions) {
65
+ const model = expected.model ? ` (${expected.model})` : "";
66
+ return `the collection holds ${actual.dimensions}-dimensional vectors, the runtime embeds with ${expected.dimensions}${model}`;
67
+ }
68
+ if (actual.distance !== undefined && actual.distance !== expected.distance) {
69
+ return `the collection uses the ${actual.distance} distance, the runtime expects ${expected.distance}`;
70
+ }
71
+ return null;
72
+ }
@@ -1,118 +1,114 @@
1
1
  /**
2
- * Skills Initialization E2E Test
3
- *
4
- * Tests the initSkills function to ensure:
5
- * 1. initSkills() with no args uses default directories
6
- * 2. initSkills({ locations }) with explicit locations works
7
- * 3. initSkills({ locations: undefined }) falls back to defaults (the bug case)
8
- *
9
- * Bug: Previously, passing undefined for locations would override defaults
10
- * with undefined, causing "directories is not iterable" error.
11
- *
12
- * Usage:
13
- * bun packages/skills/test/init-skills.test.ts
2
+ * The initialization of the skills system.
3
+ *
4
+ * The test used to be a script that ran `initSkills()` while the module was
5
+ * imported. That scanned the real skill directories of the machine and
6
+ * started the vector indexing of every skill it found, which opened a
7
+ * connection per skill and starved every other test of the process.
8
+ *
9
+ * The test now uses a temporary directory and a registry without a vector
10
+ * index, so it neither reads the machine nor reaches the network.
14
11
  */
15
12
 
13
+ import { describe, it, expect, beforeEach, afterEach } from "bun:test";
14
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
15
+ import { tmpdir } from "node:os";
16
+ import { join } from "node:path";
17
+
16
18
  import { initSkills } from "../src/index.js";
19
+ import { createSkillRegistry } from "../src/loader.js";
20
+
21
+ let tempDir: string;
17
22
 
18
- async function runTests() {
19
- console.log("=== initSkills E2E Test ===\n");
20
-
21
- let passed = 0;
22
- let failed = 0;
23
-
24
- // Test 1: no args
25
- console.log("[Test 1] initSkills() with no arguments...");
26
- try {
27
- const result = initSkills();
28
- if (!result || !Array.isArray(result.skills) || !Array.isArray(result.errors)) {
29
- throw new Error("Invalid result structure");
30
- }
31
- console.log(` PASS: Returned ${result.skills.length} skills, ${result.errors.length} errors\n`);
32
- passed++;
33
- } catch (error) {
34
- console.error(` FAIL: ${error}\n`);
35
- failed++;
36
- }
37
-
38
- // Test 2: explicit locations
39
- console.log("[Test 2] initSkills({ locations: [...] })...");
40
- try {
41
- const result = initSkills({ locations: ["/tmp/test"] });
42
- if (!result) {
43
- throw new Error("No result returned");
44
- }
45
- console.log(` PASS: Returned ${result.skills.length} skills\n`);
46
- passed++;
47
- } catch (error) {
48
- console.error(` FAIL: ${error}\n`);
49
- failed++;
50
- }
51
-
52
- // Test 3: undefined locations (the bug case)
53
- console.log("[Test 3] initSkills({ locations: undefined }) - THE BUG CASE...");
54
- try {
55
- const result = initSkills({ locations: undefined });
56
- if (!result || !Array.isArray(result.skills)) {
57
- throw new Error("Invalid result structure");
58
- }
59
- console.log(` PASS: Returned ${result.skills.length} skills\n`);
60
- passed++;
61
- } catch (error) {
62
- console.error(` FAIL: ${error}\n`);
63
- failed++;
64
- }
65
-
66
- // Test 4: partial config with only maxDepth
67
- console.log("[Test 4] initSkills({ maxDepth: 5 })...");
68
- try {
69
- const result = initSkills({ maxDepth: 5 });
70
- if (!result || !Array.isArray(result.skills)) {
71
- throw new Error("Invalid result structure");
72
- }
73
- console.log(` PASS: Returned ${result.skills.length} skills\n`);
74
- passed++;
75
- } catch (error) {
76
- console.error(` FAIL: ${error}\n`);
77
- failed++;
78
- }
79
-
80
- // Test 5: partial config with only includeHidden
81
- console.log("[Test 5] initSkills({ includeHidden: true })...");
82
- try {
83
- const result = initSkills({ includeHidden: true });
84
- if (!result || !Array.isArray(result.skills)) {
85
- throw new Error("Invalid result structure");
86
- }
87
- console.log(` PASS: Returned ${result.skills.length} skills\n`);
88
- passed++;
89
- } catch (error) {
90
- console.error(` FAIL: ${error}\n`);
91
- failed++;
92
- }
93
-
94
- // Test 6: empty locations array
95
- console.log("[Test 6] initSkills({ locations: [] })...");
96
- try {
97
- const result = initSkills({ locations: [] });
98
- if (!result) {
99
- throw new Error("No result returned");
100
- }
101
- console.log(` PASS: Returned ${result.skills.length} skills\n`);
102
- passed++;
103
- } catch (error) {
104
- console.error(` FAIL: ${error}\n`);
105
- failed++;
106
- }
107
-
108
- // Summary
109
- console.log("=== Summary ===");
110
- console.log(`Passed: ${passed}`);
111
- console.log(`Failed: ${failed}`);
112
-
113
- if (failed > 0) {
114
- process.exit(1);
115
- }
23
+ /** Write a skill into a directory of the temporary home. */
24
+ function writeSkill(directory: string, name: string): void {
25
+ const skillDir = join(tempDir, directory, name);
26
+ mkdirSync(skillDir, { recursive: true });
27
+ writeFileSync(
28
+ join(skillDir, "SKILL.md"),
29
+ [
30
+ "---",
31
+ `name: ${name}`,
32
+ `description: The ${name} skill.`,
33
+ "version: 1.0.0",
34
+ "---",
35
+ "",
36
+ `The body of the ${name} skill.`,
37
+ "",
38
+ ].join("\n"),
39
+ "utf8",
40
+ );
116
41
  }
117
42
 
118
- runTests();
43
+ beforeEach(() => {
44
+ tempDir = mkdtempSync(join(tmpdir(), "test-init-skills-"));
45
+ mkdirSync(join(tempDir, "skills"), { recursive: true });
46
+ writeSkill("skills", "alpha");
47
+ writeSkill("skills", "beta");
48
+ });
49
+
50
+ afterEach(() => {
51
+ rmSync(tempDir, { recursive: true, force: true });
52
+ });
53
+
54
+ describe("the initialization of the skills system", () => {
55
+ it("scans the given locations", () => {
56
+ const result = initSkills({
57
+ locations: [join(tempDir, "skills")],
58
+ registry: createSkillRegistry({ indexer: null }),
59
+ });
60
+
61
+ expect(result.skills.length).toBe(2);
62
+ expect(result.skills.map((skill) => skill.id).sort()).toEqual(["alpha", "beta"]);
63
+ expect(result.errors).toEqual([]);
64
+ });
65
+
66
+ it("falls back to the default locations when none are given", () => {
67
+ // The default locations point at the machine of the test, so the
68
+ // result is only checked for its shape.
69
+ const result = initSkills({
70
+ registry: createSkillRegistry({ indexer: null }),
71
+ });
72
+
73
+ expect(Array.isArray(result.skills)).toBe(true);
74
+ expect(Array.isArray(result.errors)).toBe(true);
75
+ });
76
+
77
+ it("falls back to the default locations when they are undefined", () => {
78
+ // The bug case: an undefined value must not override the defaults.
79
+ const result = initSkills({
80
+ locations: undefined,
81
+ registry: createSkillRegistry({ indexer: null }),
82
+ });
83
+
84
+ expect(Array.isArray(result.skills)).toBe(true);
85
+ expect(Array.isArray(result.errors)).toBe(true);
86
+ });
87
+
88
+ it("accepts a partial configuration", () => {
89
+ const result = initSkills({
90
+ maxDepth: 5,
91
+ includeHidden: true,
92
+ registry: createSkillRegistry({ indexer: null }),
93
+ });
94
+
95
+ expect(Array.isArray(result.skills)).toBe(true);
96
+ });
97
+
98
+ it("accepts an empty list of locations", () => {
99
+ const result = initSkills({
100
+ locations: [],
101
+ registry: createSkillRegistry({ indexer: null }),
102
+ });
103
+
104
+ expect(result.skills).toEqual([]);
105
+ });
106
+
107
+ it("registers the scanned skills in the registry", () => {
108
+ const registry = createSkillRegistry({ indexer: null });
109
+
110
+ initSkills({ locations: [join(tempDir, "skills")], registry });
111
+
112
+ expect(registry.list().length).toBe(2);
113
+ });
114
+ });
@@ -0,0 +1,242 @@
1
+ /**
2
+ * The skills that only exist in the vector store.
3
+ *
4
+ * The vector store holds the skills of a team. A client that has no local
5
+ * copy of a skill must still be able to find it - and to use it: the
6
+ * payload carries the name, the description and the body.
7
+ *
8
+ * The registry used to DROP every hit whose skill was not registered
9
+ * locally, so a shared skill was invisible on every machine that had no
10
+ * local copy of it - which is exactly the case the vector store exists for.
11
+ *
12
+ * The client and the embedder are injected, so the test neither reaches the
13
+ * network nor replaces a process-global module.
14
+ */
15
+
16
+ import { describe, expect, it } from "bun:test";
17
+
18
+ import {
19
+ createSkillRegistry,
20
+ type QdrantClientLike,
21
+ type QdrantEmbedderLike,
22
+ } from "../src/loader.js";
23
+ import type { Skill } from "../src/types.js";
24
+
25
+ /** A point of the vector store. */
26
+ interface VectorPoint {
27
+ id: number;
28
+ score: number;
29
+ payload?: Record<string, unknown>;
30
+ }
31
+
32
+ /** A client that answers a query with the given points. */
33
+ function fakeClient(
34
+ points: VectorPoint[],
35
+ description?: Record<string, unknown>,
36
+ ): QdrantClientLike & { queries: number } {
37
+ const client = {
38
+ queries: 0,
39
+ async upsert(): Promise<void> {},
40
+ async query(): Promise<unknown> {
41
+ client.queries += 1;
42
+ return { points };
43
+ },
44
+ async getCollection(): Promise<unknown> {
45
+ if (!description) throw new Error("Not found: Collection not found");
46
+ return description;
47
+ },
48
+ };
49
+ return client;
50
+ }
51
+
52
+ /** An embedder that returns a fixed vector. */
53
+ const fakeEmbedder: QdrantEmbedderLike = {
54
+ async createEmbedding() {
55
+ return { embedding: [0.1, 0.2, 0.3], tokens: 3 };
56
+ },
57
+ };
58
+
59
+ /** A local skill, as the scanner would register it. */
60
+ function localSkill(id: string): Skill {
61
+ return {
62
+ id,
63
+ path: `/tmp/skills/${id}`,
64
+ frontmatter: { name: id, description: `the local ${id}` },
65
+ body: `the local body of ${id}`,
66
+ references: [],
67
+ examples: [],
68
+ metadata: { name: id, description: `the local ${id}` },
69
+ loaded: false,
70
+ };
71
+ }
72
+
73
+ describe("a skill that only exists in the vector store", () => {
74
+ it("is found instead of being dropped", async () => {
75
+ const client = fakeClient([
76
+ {
77
+ id: 19,
78
+ score: 0.91,
79
+ payload: {
80
+ name: "frappe-doctype-field-order",
81
+ description: "the shared skill",
82
+ body: "the shared body",
83
+ },
84
+ },
85
+ ]);
86
+ const registry = createSkillRegistry({
87
+ qdrantClient: client,
88
+ embedder: fakeEmbedder,
89
+ collection: "pi-harness-skills-test",
90
+ });
91
+
92
+ const results = await registry.findVector("field order");
93
+
94
+ expect(results).toHaveLength(1);
95
+ expect(results[0].source).toBe("remote");
96
+ expect(results[0].skill.id).toBe("frappe-doctype-field-order");
97
+ // The payload is the skill - the body travels with it.
98
+ expect(results[0].skill.body).toBe("the shared body");
99
+ expect(results[0].skill.frontmatter.description).toBe("the shared skill");
100
+ });
101
+
102
+ it("does not count as a local skill", async () => {
103
+ const client = fakeClient([
104
+ { id: 19, score: 0.9, payload: { name: "shared", description: "d", body: "b" } },
105
+ ]);
106
+ const registry = createSkillRegistry({
107
+ qdrantClient: client,
108
+ embedder: fakeEmbedder,
109
+ collection: "pi-harness-skills-test",
110
+ });
111
+ registry.register(localSkill("local-one"));
112
+
113
+ await registry.findVector("shared");
114
+
115
+ // The local count stays local - that is what the startup line shows.
116
+ expect(registry.list()).toHaveLength(1);
117
+ expect(registry.list().map((skill) => skill.id)).toEqual(["local-one"]);
118
+ expect(registry.listRemote().map((skill) => skill.id)).toEqual(["shared"]);
119
+ });
120
+
121
+ it("can be loaded without a local directory", async () => {
122
+ const client = fakeClient([
123
+ { id: 19, score: 0.9, payload: { name: "shared", description: "d", body: "the body" } },
124
+ ]);
125
+ const registry = createSkillRegistry({
126
+ qdrantClient: client,
127
+ embedder: fakeEmbedder,
128
+ collection: "pi-harness-skills-test",
129
+ });
130
+
131
+ await registry.findVector("shared");
132
+ const loaded = await registry.load("shared");
133
+
134
+ expect(loaded).not.toBeNull();
135
+ expect(loaded?.body).toBe("the body");
136
+ expect(loaded?.path).toBe("");
137
+ });
138
+
139
+ it("marks a local hit as local", async () => {
140
+ const client = fakeClient([
141
+ { id: 1, score: 0.9, payload: { name: "local-one", description: "d", body: "b" } },
142
+ ]);
143
+ const registry = createSkillRegistry({
144
+ qdrantClient: client,
145
+ embedder: fakeEmbedder,
146
+ collection: "pi-harness-skills-test",
147
+ });
148
+ registry.register(localSkill("local-one"));
149
+
150
+ const results = await registry.findVector("local");
151
+
152
+ expect(results).toHaveLength(1);
153
+ expect(results[0].source).toBe("local");
154
+ expect(results[0].skill.path).toBe("/tmp/skills/local-one");
155
+ });
156
+
157
+ it("skips a hit without a name", async () => {
158
+ const client = fakeClient([
159
+ { id: 1, score: 0.9, payload: { description: "no name" } },
160
+ { id: 2, score: 0.8, payload: { name: "", description: "empty name" } },
161
+ ]);
162
+ const registry = createSkillRegistry({
163
+ qdrantClient: client,
164
+ embedder: fakeEmbedder,
165
+ collection: "pi-harness-skills-test",
166
+ });
167
+
168
+ expect(await registry.findVector("anything")).toHaveLength(0);
169
+ });
170
+ });
171
+
172
+ describe("the state of the vector store", () => {
173
+ it("reports the number of skills", async () => {
174
+ const client = fakeClient([], {
175
+ points_count: 79,
176
+ config: { params: { vectors: { size: 1536, distance: "Cosine" } } },
177
+ });
178
+ const registry = createSkillRegistry({
179
+ qdrantClient: client,
180
+ embedder: fakeEmbedder,
181
+ collection: "pi-harness-skills-openai-v1",
182
+ });
183
+
184
+ const stats = await registry.getQdrantStats();
185
+
186
+ expect(stats.state).toBe("populated");
187
+ expect(stats.count).toBe(79);
188
+ expect(stats.dimensions).toBe(1536);
189
+ expect(stats.schemaMismatch).toBeUndefined();
190
+ });
191
+
192
+ it("names the real cause of an incompatible collection", async () => {
193
+ const client = fakeClient([], {
194
+ points_count: 79,
195
+ config: { params: { vectors: { size: 384, distance: "Cosine" } } },
196
+ });
197
+ const registry = createSkillRegistry({
198
+ qdrantClient: client,
199
+ embedder: fakeEmbedder,
200
+ collection: "pi-harness-skills",
201
+ });
202
+
203
+ const stats = await registry.getQdrantStats();
204
+
205
+ // The mismatch names the numbers, so the reader knows WHICH schema
206
+ // the collection was built with.
207
+ expect(stats.schemaMismatch).toContain("384");
208
+ expect(stats.schemaMismatch).toContain("1536");
209
+ expect(stats.schemaMismatch).toContain("sync-to-qdrant.ts");
210
+ });
211
+
212
+ it("reports an empty collection", async () => {
213
+ const client = fakeClient([], {
214
+ points_count: 0,
215
+ config: { params: { vectors: { size: 1536, distance: "Cosine" } } },
216
+ });
217
+ const registry = createSkillRegistry({
218
+ qdrantClient: client,
219
+ embedder: fakeEmbedder,
220
+ collection: "pi-harness-skills-openai-v1",
221
+ });
222
+
223
+ const stats = await registry.getQdrantStats();
224
+
225
+ expect(stats.state).toBe("empty");
226
+ expect(stats.count).toBe(0);
227
+ });
228
+
229
+ it("reports a collection that does not exist", async () => {
230
+ const client = fakeClient([]);
231
+ const registry = createSkillRegistry({
232
+ qdrantClient: client,
233
+ embedder: fakeEmbedder,
234
+ collection: "pi-harness-skills-openai-v1",
235
+ });
236
+
237
+ const stats = await registry.getQdrantStats();
238
+
239
+ expect(stats.state).toBe("missing");
240
+ expect(stats.count).toBe(0);
241
+ });
242
+ });