pi-harness-runtime 1.1.411 → 1.1.413

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 (157) 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 +229 -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/cache-strategy/package.json +1 -1
  16. package/packages/capability-registry/package.json +1 -1
  17. package/packages/checkpoint/package.json +1 -1
  18. package/packages/cli-plugin-sdk/package.json +1 -1
  19. package/packages/clipboard/package.json +1 -1
  20. package/packages/clipboard-plugin/package.json +1 -1
  21. package/packages/code-generation/package.json +1 -1
  22. package/packages/code-review/package.json +1 -1
  23. package/packages/codex-adapter/package.json +1 -1
  24. package/packages/codex-watcher/package.json +1 -1
  25. package/packages/config-capture/package.json +1 -1
  26. package/packages/connection-runtime/package.json +1 -1
  27. package/packages/context-compiler/package.json +1 -1
  28. package/packages/context-discovery/package.json +1 -1
  29. package/packages/context-manager/package.json +1 -1
  30. package/packages/contracts/package.json +1 -1
  31. package/packages/cookie-sanitizer/package.json +1 -1
  32. package/packages/cost-optimizer/package.json +1 -1
  33. package/packages/dependency-analyzer/package.json +1 -1
  34. package/packages/django-plugin/package.json +1 -1
  35. package/packages/doc-generator/package.json +1 -1
  36. package/packages/durable-review/package.json +1 -1
  37. package/packages/e2e-tester/package.json +1 -1
  38. package/packages/evaluation-engine/package.json +1 -1
  39. package/packages/evaluation-runner/package.json +1 -1
  40. package/packages/event-bus/package.json +1 -1
  41. package/packages/event-sink/package.json +1 -1
  42. package/packages/event-store/package.json +1 -1
  43. package/packages/experience-replay/package.json +1 -1
  44. package/packages/feedback-collector/package.json +1 -1
  45. package/packages/file-copy-helper/package.json +1 -1
  46. package/packages/framework-detector/package.json +1 -1
  47. package/packages/framework-plugin-sdk/package.json +1 -1
  48. package/packages/frappe-plugin/package.json +1 -1
  49. package/packages/generic-web-plugin/package.json +1 -1
  50. package/packages/health-monitor/package.json +1 -1
  51. package/packages/intent-analyzer/package.json +1 -1
  52. package/packages/jev-judge/package.json +1 -1
  53. package/packages/knowledge-graph/package.json +1 -1
  54. package/packages/knowledge-retrieval/package.json +1 -1
  55. package/packages/laravel-plugin/package.json +1 -1
  56. package/packages/learning-engine/package.json +1 -1
  57. package/packages/logging/package.json +1 -1
  58. package/packages/mcp-adapter/package.json +1 -1
  59. package/packages/memory-engine/package.json +1 -1
  60. package/packages/milestone-manager/package.json +1 -1
  61. package/packages/model-registry/package.json +1 -1
  62. package/packages/nextjs-plugin/package.json +1 -1
  63. package/packages/notification/package.json +1 -1
  64. package/packages/observability/package.json +1 -1
  65. package/packages/okf-indexer/package.json +1 -1
  66. package/packages/paperclip-integration/package.json +1 -1
  67. package/packages/performance-optimizer/package.json +1 -1
  68. package/packages/permission-mode/package.json +1 -1
  69. package/packages/privilege-broker/package.json +1 -1
  70. package/packages/project-analyzer/package.json +1 -1
  71. package/packages/project-bootstrap/package.json +1 -1
  72. package/packages/projection-engine/package.json +1 -1
  73. package/packages/prompt-compiler/package.json +1 -1
  74. package/packages/prompt-versioning/package.json +1 -1
  75. package/packages/provider-adapter-sdk/package.json +1 -1
  76. package/packages/provider-router/package.json +1 -1
  77. package/packages/provider-selector/package.json +1 -1
  78. package/packages/providers/package.json +1 -1
  79. package/packages/qdrant-skills/dist/client.d.ts +10 -0
  80. package/packages/qdrant-skills/dist/client.d.ts.map +1 -1
  81. package/packages/qdrant-skills/dist/client.js +41 -9
  82. package/packages/qdrant-skills/dist/client.js.map +1 -1
  83. package/packages/qdrant-skills/dist/embedder.d.ts +10 -0
  84. package/packages/qdrant-skills/dist/embedder.d.ts.map +1 -1
  85. package/packages/qdrant-skills/dist/embedder.js +12 -2
  86. package/packages/qdrant-skills/dist/embedder.js.map +1 -1
  87. package/packages/qdrant-skills/dist/index.d.ts +2 -2
  88. package/packages/qdrant-skills/dist/index.d.ts.map +1 -1
  89. package/packages/qdrant-skills/dist/index.js +2 -2
  90. package/packages/qdrant-skills/dist/index.js.map +1 -1
  91. package/packages/qdrant-skills/package.json +1 -1
  92. package/packages/qdrant-skills/src/client.ts +38 -9
  93. package/packages/qdrant-skills/src/embedder.ts +14 -2
  94. package/packages/qdrant-skills/src/index.ts +3 -0
  95. package/packages/qdrant-skills/test/collection-info.test.ts +165 -0
  96. package/packages/quota-manager/package.json +1 -1
  97. package/packages/rate-limiter/package.json +1 -1
  98. package/packages/react-vite-plugin/package.json +1 -1
  99. package/packages/relay/package.json +1 -1
  100. package/packages/release-manager/package.json +1 -1
  101. package/packages/requirement-compiler/package.json +1 -1
  102. package/packages/runtime/package.json +1 -1
  103. package/packages/scheduler/package.json +1 -1
  104. package/packages/scheduler-adapter/package.json +1 -1
  105. package/packages/session/package.json +1 -1
  106. package/packages/session-api/package.json +1 -1
  107. package/packages/session-export/package.json +1 -1
  108. package/packages/shared-context/package.json +1 -1
  109. package/packages/skill-mcp-client/package.json +1 -1
  110. package/packages/skill-registry/package.json +1 -1
  111. package/packages/skills/dist/index.d.ts +14 -1
  112. package/packages/skills/dist/index.d.ts.map +1 -1
  113. package/packages/skills/dist/index.js +3 -1
  114. package/packages/skills/dist/index.js.map +1 -1
  115. package/packages/skills/dist/loader.d.ts +209 -0
  116. package/packages/skills/dist/loader.d.ts.map +1 -1
  117. package/packages/skills/dist/loader.js +386 -15
  118. package/packages/skills/dist/loader.js.map +1 -1
  119. package/packages/skills/dist/remote-source.d.ts +107 -0
  120. package/packages/skills/dist/remote-source.d.ts.map +1 -0
  121. package/packages/skills/dist/remote-source.js +79 -0
  122. package/packages/skills/dist/remote-source.js.map +1 -0
  123. package/packages/skills/dist/vector-schema.d.ts +58 -0
  124. package/packages/skills/dist/vector-schema.d.ts.map +1 -0
  125. package/packages/skills/dist/vector-schema.js +55 -0
  126. package/packages/skills/dist/vector-schema.js.map +1 -0
  127. package/packages/skills/package.json +1 -1
  128. package/packages/skills/src/index.ts +16 -2
  129. package/packages/skills/src/loader.ts +532 -39
  130. package/packages/skills/src/remote-source.ts +148 -0
  131. package/packages/skills/src/vector-schema.ts +72 -0
  132. package/packages/skills/test/remote-skills.test.ts +292 -0
  133. package/packages/skills/test/remote-source.test.ts +248 -0
  134. package/packages/sprint-planner/package.json +1 -1
  135. package/packages/subscription-engine/package.json +1 -1
  136. package/packages/task-compiler/package.json +1 -1
  137. package/packages/telegram/package.json +1 -1
  138. package/packages/tencentdb-memory/package.json +1 -1
  139. package/packages/tencentdb-sync/package.json +1 -1
  140. package/packages/test-data-generator/package.json +1 -1
  141. package/packages/test-generator/package.json +1 -1
  142. package/packages/todo-bd-sync/package.json +1 -1
  143. package/packages/token-estimation/package.json +1 -1
  144. package/packages/token-optimizer/package.json +1 -1
  145. package/packages/tooling-preference/package.json +1 -1
  146. package/packages/trajectory/package.json +1 -1
  147. package/packages/tui/package.json +1 -1
  148. package/packages/two-phase-review/package.json +1 -1
  149. package/packages/types/package.json +1 -1
  150. package/packages/voice-api/package.json +1 -1
  151. package/packages/webmcp-tester/package.json +1 -1
  152. package/packages/wiki/package.json +1 -1
  153. package/packages/workflow-events/package.json +1 -1
  154. package/packages/workspace-scanner/package.json +1 -1
  155. package/packages/worktree/package.json +1 -1
  156. package/packages/write-review/package.json +1 -1
  157. package/scripts/sync-to-qdrant.ts +79 -14
@@ -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
+ }
@@ -0,0 +1,292 @@
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
+
243
+ it("names the skills of the legacy collection", async () => {
244
+ // The runtime collection does not exist yet, but the collection of
245
+ // the previous version still holds the skills. They are not lost -
246
+ // the reader has to know where they are.
247
+ const client = {
248
+ async upsert(): Promise<void> {},
249
+ async query(): Promise<unknown> {
250
+ return { points: [] };
251
+ },
252
+ async getCollection(name: string): Promise<unknown> {
253
+ if (name === "pi-harness-skills") {
254
+ return {
255
+ points_count: 79,
256
+ config: { params: { vectors: { size: 384, distance: "Cosine" } } },
257
+ };
258
+ }
259
+ throw new Error("Not Found");
260
+ },
261
+ };
262
+ const registry = createSkillRegistry({
263
+ qdrantClient: client as never,
264
+ embedder: fakeEmbedder,
265
+ collection: "pi-harness-skills-openai-v1",
266
+ });
267
+
268
+ const stats = await registry.getQdrantStats();
269
+
270
+ expect(stats.state).toBe("missing");
271
+ expect(stats.legacy?.collection).toBe("pi-harness-skills");
272
+ expect(stats.legacy?.count).toBe(79);
273
+ expect(stats.legacy?.dimensions).toBe(384);
274
+ expect(stats.legacy?.model).toBe("sentence-transformers/all-MiniLM-L6-v2");
275
+ });
276
+
277
+ it("does not look for a second collection when the legacy one is the runtime one", async () => {
278
+ const client = fakeClient([], {
279
+ points_count: 0,
280
+ config: { params: { vectors: { size: 1536, distance: "Cosine" } } },
281
+ });
282
+ const registry = createSkillRegistry({
283
+ qdrantClient: client,
284
+ embedder: fakeEmbedder,
285
+ collection: "pi-harness-skills",
286
+ });
287
+
288
+ const stats = await registry.getQdrantStats();
289
+
290
+ expect(stats.legacy).toBeUndefined();
291
+ });
292
+ });