@osmosis-ai/core 0.1.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.
- package/dist/api/index.d.ts +12 -0
- package/dist/api/index.js +87 -0
- package/dist/api/index.js.map +1 -0
- package/dist/capture/index.d.ts +10 -0
- package/dist/capture/index.js +52 -0
- package/dist/capture/index.js.map +1 -0
- package/dist/distill/index.d.ts +35 -0
- package/dist/distill/index.js +41 -0
- package/dist/distill/index.js.map +1 -0
- package/dist/fitness/index.d.ts +14 -0
- package/dist/fitness/index.js +39 -0
- package/dist/fitness/index.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/retrieval/index.d.ts +11 -0
- package/dist/retrieval/index.js +51 -0
- package/dist/retrieval/index.js.map +1 -0
- package/dist/seeds/index.d.ts +5 -0
- package/dist/seeds/index.js +131 -0
- package/dist/seeds/index.js.map +1 -0
- package/dist/store/index.d.ts +43 -0
- package/dist/store/index.js +230 -0
- package/dist/store/index.js.map +1 -0
- package/dist/types/index.d.ts +53 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/validation/index.d.ts +119 -0
- package/dist/validation/index.js +55 -0
- package/dist/validation/index.js.map +1 -0
- package/package.json +23 -0
- package/src/__tests__/api.test.ts +103 -0
- package/src/__tests__/capture.test.ts +113 -0
- package/src/__tests__/distill.test.ts +83 -0
- package/src/__tests__/fitness.test.ts +58 -0
- package/src/__tests__/retrieval.test.ts +83 -0
- package/src/__tests__/store.test.ts +262 -0
- package/src/__tests__/types.test.ts +92 -0
- package/src/api/index.ts +94 -0
- package/src/capture/index.ts +71 -0
- package/src/distill/index.ts +64 -0
- package/src/fitness/index.ts +56 -0
- package/src/index.ts +51 -0
- package/src/retrieval/index.ts +61 -0
- package/src/seeds/index.ts +146 -0
- package/src/store/index.ts +250 -0
- package/src/types/index.ts +76 -0
- package/src/validation/index.ts +63 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import Database from 'better-sqlite3';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { validateCreateAtom, validateCreateToolAtom, validateCreateNegativeAtom } from '../validation/index.js';
|
|
4
|
+
const SCHEMA_SQL = `
|
|
5
|
+
CREATE TABLE IF NOT EXISTS atoms (
|
|
6
|
+
id TEXT PRIMARY KEY,
|
|
7
|
+
type TEXT NOT NULL,
|
|
8
|
+
observation TEXT NOT NULL,
|
|
9
|
+
context TEXT NOT NULL,
|
|
10
|
+
confidence REAL NOT NULL,
|
|
11
|
+
fitness_score REAL NOT NULL,
|
|
12
|
+
trust_tier TEXT NOT NULL DEFAULT 'quarantine',
|
|
13
|
+
source_agent_hash TEXT NOT NULL,
|
|
14
|
+
created_at TEXT NOT NULL,
|
|
15
|
+
updated_at TEXT NOT NULL,
|
|
16
|
+
decay_rate REAL NOT NULL DEFAULT 0.99,
|
|
17
|
+
|
|
18
|
+
-- ToolAtom fields (nullable)
|
|
19
|
+
tool_name TEXT,
|
|
20
|
+
params_hash TEXT,
|
|
21
|
+
outcome TEXT,
|
|
22
|
+
error_signature TEXT,
|
|
23
|
+
latency_ms REAL,
|
|
24
|
+
reliability_score REAL,
|
|
25
|
+
|
|
26
|
+
-- NegativeAtom fields (nullable)
|
|
27
|
+
anti_pattern TEXT,
|
|
28
|
+
failure_cluster_size INTEGER,
|
|
29
|
+
error_type TEXT,
|
|
30
|
+
severity TEXT,
|
|
31
|
+
|
|
32
|
+
-- Dedup & fitness fields
|
|
33
|
+
evidence_count INTEGER NOT NULL DEFAULT 1,
|
|
34
|
+
use_count INTEGER NOT NULL DEFAULT 0,
|
|
35
|
+
success_after_use INTEGER NOT NULL DEFAULT 0,
|
|
36
|
+
failure_after_use INTEGER NOT NULL DEFAULT 0,
|
|
37
|
+
last_used TEXT
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
CREATE INDEX IF NOT EXISTS idx_atoms_type ON atoms(type);
|
|
41
|
+
CREATE INDEX IF NOT EXISTS idx_atoms_tool_name ON atoms(tool_name);
|
|
42
|
+
CREATE INDEX IF NOT EXISTS idx_atoms_confidence ON atoms(confidence);
|
|
43
|
+
CREATE INDEX IF NOT EXISTS idx_atoms_fitness ON atoms(fitness_score);
|
|
44
|
+
CREATE INDEX IF NOT EXISTS idx_atoms_updated_at ON atoms(updated_at);
|
|
45
|
+
`;
|
|
46
|
+
// Migration: add columns if they don't exist (for existing DBs)
|
|
47
|
+
const MIGRATIONS = [
|
|
48
|
+
`ALTER TABLE atoms ADD COLUMN evidence_count INTEGER NOT NULL DEFAULT 1`,
|
|
49
|
+
`ALTER TABLE atoms ADD COLUMN use_count INTEGER NOT NULL DEFAULT 0`,
|
|
50
|
+
`ALTER TABLE atoms ADD COLUMN success_after_use INTEGER NOT NULL DEFAULT 0`,
|
|
51
|
+
`ALTER TABLE atoms ADD COLUMN failure_after_use INTEGER NOT NULL DEFAULT 0`,
|
|
52
|
+
`ALTER TABLE atoms ADD COLUMN last_used TEXT`,
|
|
53
|
+
];
|
|
54
|
+
/**
|
|
55
|
+
* Jaccard similarity between two strings (based on word bigrams).
|
|
56
|
+
*/
|
|
57
|
+
export function jaccardSimilarity(a, b) {
|
|
58
|
+
const bigrams = (s) => {
|
|
59
|
+
const words = s.toLowerCase().split(/\s+/).filter(Boolean);
|
|
60
|
+
const set = new Set();
|
|
61
|
+
for (let i = 0; i < words.length - 1; i++) {
|
|
62
|
+
set.add(words[i] + ' ' + words[i + 1]);
|
|
63
|
+
}
|
|
64
|
+
// Also add unigrams for short texts
|
|
65
|
+
for (const w of words)
|
|
66
|
+
set.add(w);
|
|
67
|
+
return set;
|
|
68
|
+
};
|
|
69
|
+
const setA = bigrams(a);
|
|
70
|
+
const setB = bigrams(b);
|
|
71
|
+
if (setA.size === 0 && setB.size === 0)
|
|
72
|
+
return 1;
|
|
73
|
+
let intersection = 0;
|
|
74
|
+
for (const x of setA)
|
|
75
|
+
if (setB.has(x))
|
|
76
|
+
intersection++;
|
|
77
|
+
const union = setA.size + setB.size - intersection;
|
|
78
|
+
return union === 0 ? 1 : intersection / union;
|
|
79
|
+
}
|
|
80
|
+
export class AtomStore {
|
|
81
|
+
db;
|
|
82
|
+
constructor(dbPath = ':memory:') {
|
|
83
|
+
this.db = new Database(dbPath);
|
|
84
|
+
this.db.pragma('journal_mode = WAL');
|
|
85
|
+
this.migrate();
|
|
86
|
+
}
|
|
87
|
+
/** Run schema migrations */
|
|
88
|
+
migrate() {
|
|
89
|
+
this.db.exec(SCHEMA_SQL);
|
|
90
|
+
// Apply column migrations for existing DBs (ignore if already exists)
|
|
91
|
+
for (const sql of MIGRATIONS) {
|
|
92
|
+
try {
|
|
93
|
+
this.db.exec(sql);
|
|
94
|
+
}
|
|
95
|
+
catch { /* column already exists */ }
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** Find atoms with similar observation text */
|
|
99
|
+
findSimilar(observation, threshold = 0.7) {
|
|
100
|
+
const all = this.getAll();
|
|
101
|
+
return all.filter(a => jaccardSimilarity(a.observation, observation) >= threshold);
|
|
102
|
+
}
|
|
103
|
+
/** Insert a base/pattern/skill/context atom (with validation and dedup) */
|
|
104
|
+
createAtom(data) {
|
|
105
|
+
validateCreateAtom(data);
|
|
106
|
+
// Dedup check
|
|
107
|
+
const similar = this.findSimilar(data.observation, 0.9);
|
|
108
|
+
if (similar.length > 0) {
|
|
109
|
+
const best = similar[0];
|
|
110
|
+
this._mergeAtom(best.id, data.fitness_score, data.confidence);
|
|
111
|
+
return this.getById(best.id);
|
|
112
|
+
}
|
|
113
|
+
const now = new Date().toISOString();
|
|
114
|
+
const atom = { id: randomUUID(), ...data, created_at: now, updated_at: now };
|
|
115
|
+
this.db.prepare(`
|
|
116
|
+
INSERT INTO atoms (id, type, observation, context, confidence, fitness_score,
|
|
117
|
+
trust_tier, source_agent_hash, created_at, updated_at, decay_rate, evidence_count)
|
|
118
|
+
VALUES (@id, @type, @observation, @context, @confidence, @fitness_score,
|
|
119
|
+
@trust_tier, @source_agent_hash, @created_at, @updated_at, @decay_rate, 1)
|
|
120
|
+
`).run(atom);
|
|
121
|
+
return atom;
|
|
122
|
+
}
|
|
123
|
+
/** Insert a ToolAtom (with validation and dedup) */
|
|
124
|
+
createToolAtom(data) {
|
|
125
|
+
validateCreateToolAtom(data);
|
|
126
|
+
const similar = this.findSimilar(data.observation, 0.9);
|
|
127
|
+
if (similar.length > 0) {
|
|
128
|
+
const best = similar[0];
|
|
129
|
+
this._mergeAtom(best.id, data.fitness_score, data.confidence);
|
|
130
|
+
return this.getById(best.id);
|
|
131
|
+
}
|
|
132
|
+
const now = new Date().toISOString();
|
|
133
|
+
const atom = { id: randomUUID(), ...data, created_at: now, updated_at: now };
|
|
134
|
+
this.db.prepare(`
|
|
135
|
+
INSERT INTO atoms (id, type, observation, context, confidence, fitness_score,
|
|
136
|
+
trust_tier, source_agent_hash, created_at, updated_at, decay_rate,
|
|
137
|
+
tool_name, params_hash, outcome, error_signature, latency_ms, reliability_score, evidence_count)
|
|
138
|
+
VALUES (@id, @type, @observation, @context, @confidence, @fitness_score,
|
|
139
|
+
@trust_tier, @source_agent_hash, @created_at, @updated_at, @decay_rate,
|
|
140
|
+
@tool_name, @params_hash, @outcome, @error_signature, @latency_ms, @reliability_score, 1)
|
|
141
|
+
`).run(atom);
|
|
142
|
+
return atom;
|
|
143
|
+
}
|
|
144
|
+
/** Insert a NegativeAtom (with validation and dedup) */
|
|
145
|
+
createNegativeAtom(data) {
|
|
146
|
+
validateCreateNegativeAtom(data);
|
|
147
|
+
const similar = this.findSimilar(data.observation, 0.9);
|
|
148
|
+
if (similar.length > 0) {
|
|
149
|
+
const best = similar[0];
|
|
150
|
+
this._mergeAtom(best.id, data.fitness_score, data.confidence);
|
|
151
|
+
return this.getById(best.id);
|
|
152
|
+
}
|
|
153
|
+
const now = new Date().toISOString();
|
|
154
|
+
const atom = { id: randomUUID(), ...data, created_at: now, updated_at: now };
|
|
155
|
+
this.db.prepare(`
|
|
156
|
+
INSERT INTO atoms (id, type, observation, context, confidence, fitness_score,
|
|
157
|
+
trust_tier, source_agent_hash, created_at, updated_at, decay_rate,
|
|
158
|
+
anti_pattern, failure_cluster_size, error_type, severity, evidence_count)
|
|
159
|
+
VALUES (@id, @type, @observation, @context, @confidence, @fitness_score,
|
|
160
|
+
@trust_tier, @source_agent_hash, @created_at, @updated_at, @decay_rate,
|
|
161
|
+
@anti_pattern, @failure_cluster_size, @error_type, @severity, 1)
|
|
162
|
+
`).run(atom);
|
|
163
|
+
return atom;
|
|
164
|
+
}
|
|
165
|
+
/** Merge: keep higher fitness, increment evidence_count */
|
|
166
|
+
_mergeAtom(existingId, newFitness, newConfidence) {
|
|
167
|
+
this.db.prepare(`
|
|
168
|
+
UPDATE atoms SET
|
|
169
|
+
fitness_score = MAX(fitness_score, ?),
|
|
170
|
+
confidence = MAX(confidence, ?),
|
|
171
|
+
evidence_count = evidence_count + 1,
|
|
172
|
+
updated_at = ?
|
|
173
|
+
WHERE id = ?
|
|
174
|
+
`).run(newFitness, newConfidence, new Date().toISOString(), existingId);
|
|
175
|
+
}
|
|
176
|
+
/** Get atom by ID */
|
|
177
|
+
getById(id) {
|
|
178
|
+
const row = this.db.prepare('SELECT * FROM atoms WHERE id = ?').get(id);
|
|
179
|
+
return row ?? null;
|
|
180
|
+
}
|
|
181
|
+
/** Query atoms by type */
|
|
182
|
+
queryByType(type) {
|
|
183
|
+
return this.db.prepare('SELECT * FROM atoms WHERE type = ?').all(type);
|
|
184
|
+
}
|
|
185
|
+
/** Query tool atoms by tool_name */
|
|
186
|
+
queryByToolName(toolName) {
|
|
187
|
+
return this.db.prepare('SELECT * FROM atoms WHERE type = ? AND tool_name = ?').all('tool', toolName);
|
|
188
|
+
}
|
|
189
|
+
/** Query atoms with confidence >= threshold */
|
|
190
|
+
queryByConfidence(threshold) {
|
|
191
|
+
return this.db.prepare('SELECT * FROM atoms WHERE confidence >= ? ORDER BY confidence DESC').all(threshold);
|
|
192
|
+
}
|
|
193
|
+
/** Full-text search on observation */
|
|
194
|
+
search(query) {
|
|
195
|
+
return this.db.prepare('SELECT * FROM atoms WHERE observation LIKE ? ORDER BY fitness_score DESC')
|
|
196
|
+
.all(`%${query}%`);
|
|
197
|
+
}
|
|
198
|
+
/** Update fitness score for a specific atom */
|
|
199
|
+
updateFitnessScore(id, newScore) {
|
|
200
|
+
this.db.prepare('UPDATE atoms SET fitness_score = ?, updated_at = ? WHERE id = ?')
|
|
201
|
+
.run(newScore, new Date().toISOString(), id);
|
|
202
|
+
}
|
|
203
|
+
/** Record a usage event */
|
|
204
|
+
recordUsage(id, success) {
|
|
205
|
+
const col = success ? 'success_after_use' : 'failure_after_use';
|
|
206
|
+
this.db.prepare(`
|
|
207
|
+
UPDATE atoms SET use_count = use_count + 1, ${col} = ${col} + 1,
|
|
208
|
+
last_used = ?, updated_at = ? WHERE id = ?
|
|
209
|
+
`).run(new Date().toISOString(), new Date().toISOString(), id);
|
|
210
|
+
}
|
|
211
|
+
/** Apply decay: multiply fitness_score by decay_rate for all atoms */
|
|
212
|
+
applyDecay() {
|
|
213
|
+
const result = this.db.prepare('UPDATE atoms SET fitness_score = fitness_score * decay_rate, updated_at = ? WHERE fitness_score > 0').run(new Date().toISOString());
|
|
214
|
+
return result.changes;
|
|
215
|
+
}
|
|
216
|
+
/** Delete atom by ID */
|
|
217
|
+
deleteAtom(id) {
|
|
218
|
+
const result = this.db.prepare('DELETE FROM atoms WHERE id = ?').run(id);
|
|
219
|
+
return result.changes > 0;
|
|
220
|
+
}
|
|
221
|
+
/** Get all atoms */
|
|
222
|
+
getAll() {
|
|
223
|
+
return this.db.prepare('SELECT * FROM atoms').all();
|
|
224
|
+
}
|
|
225
|
+
/** Close the database */
|
|
226
|
+
close() {
|
|
227
|
+
this.db.close();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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,2BAA2B;IAC3B,WAAW,CAAC,EAAU,EAAE,OAAgB;QACtC,MAAM,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,mBAAmB,CAAC;QAChE,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC;oDACgC,GAAG,MAAM,GAAG;;KAE3D,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;IACjE,CAAC;IAED,sEAAsE;IACtE,UAAU;QACR,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,OAAO,CAC5B,qGAAqG,CACtG,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;QAChC,OAAO,MAAM,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,wBAAwB;IACxB,UAAU,CAAC,EAAU;QACnB,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,gCAAgC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACzE,OAAO,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED,oBAAoB;IACpB,MAAM;QACJ,OAAO,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,GAAG,EAAqB,CAAC;IACzE,CAAC;IAED,yBAAyB;IACzB,KAAK;QACH,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export type TrustTier = 'quarantine' | 'local' | 'verified' | 'canonical';
|
|
2
|
+
export type AtomType = 'tool' | 'negative' | 'pattern' | 'skill' | 'context';
|
|
3
|
+
export type Outcome = 'success' | 'failure' | 'partial';
|
|
4
|
+
export type Severity = 'low' | 'medium' | 'high' | 'critical';
|
|
5
|
+
export interface KnowledgeAtom {
|
|
6
|
+
id: string;
|
|
7
|
+
type: AtomType;
|
|
8
|
+
observation: string;
|
|
9
|
+
context: string;
|
|
10
|
+
confidence: number;
|
|
11
|
+
fitness_score: number;
|
|
12
|
+
trust_tier: TrustTier;
|
|
13
|
+
source_agent_hash: string;
|
|
14
|
+
created_at: string;
|
|
15
|
+
updated_at: string;
|
|
16
|
+
decay_rate: number;
|
|
17
|
+
}
|
|
18
|
+
export interface ToolAtom extends KnowledgeAtom {
|
|
19
|
+
type: 'tool';
|
|
20
|
+
tool_name: string;
|
|
21
|
+
params_hash: string;
|
|
22
|
+
outcome: Outcome;
|
|
23
|
+
error_signature: string | null;
|
|
24
|
+
latency_ms: number | null;
|
|
25
|
+
reliability_score: number;
|
|
26
|
+
}
|
|
27
|
+
export interface NegativeAtom extends KnowledgeAtom {
|
|
28
|
+
type: 'negative';
|
|
29
|
+
anti_pattern: string;
|
|
30
|
+
failure_cluster_size: number;
|
|
31
|
+
error_type: string;
|
|
32
|
+
severity: Severity;
|
|
33
|
+
}
|
|
34
|
+
export interface PatternAtom extends KnowledgeAtom {
|
|
35
|
+
type: 'pattern';
|
|
36
|
+
}
|
|
37
|
+
export interface SkillAtom extends KnowledgeAtom {
|
|
38
|
+
type: 'skill';
|
|
39
|
+
}
|
|
40
|
+
export interface ContextAtom extends KnowledgeAtom {
|
|
41
|
+
type: 'context';
|
|
42
|
+
}
|
|
43
|
+
export type AnyAtom = ToolAtom | NegativeAtom | PatternAtom | SkillAtom | ContextAtom;
|
|
44
|
+
export interface OutcomeSignals {
|
|
45
|
+
completed_without_error: boolean;
|
|
46
|
+
revisited_within_1hr: boolean;
|
|
47
|
+
human_accepted: boolean | null;
|
|
48
|
+
convergence_steps: number;
|
|
49
|
+
error_free: boolean;
|
|
50
|
+
}
|
|
51
|
+
export type CreateToolAtom = Omit<ToolAtom, 'id' | 'created_at' | 'updated_at'>;
|
|
52
|
+
export type CreateNegativeAtom = Omit<NegativeAtom, 'id' | 'created_at' | 'updated_at'>;
|
|
53
|
+
export type CreateAtom = Omit<KnowledgeAtom, 'id' | 'created_at' | 'updated_at'>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const CreateAtomSchema: z.ZodObject<{
|
|
3
|
+
type: z.ZodEnum<{
|
|
4
|
+
tool: "tool";
|
|
5
|
+
negative: "negative";
|
|
6
|
+
pattern: "pattern";
|
|
7
|
+
skill: "skill";
|
|
8
|
+
context: "context";
|
|
9
|
+
}>;
|
|
10
|
+
observation: z.ZodString;
|
|
11
|
+
context: z.ZodString;
|
|
12
|
+
confidence: z.ZodNumber;
|
|
13
|
+
fitness_score: z.ZodNumber;
|
|
14
|
+
trust_tier: z.ZodEnum<{
|
|
15
|
+
quarantine: "quarantine";
|
|
16
|
+
local: "local";
|
|
17
|
+
verified: "verified";
|
|
18
|
+
canonical: "canonical";
|
|
19
|
+
}>;
|
|
20
|
+
source_agent_hash: z.ZodString;
|
|
21
|
+
decay_rate: z.ZodNumber;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
export declare const CreateToolAtomSchema: z.ZodObject<{
|
|
24
|
+
observation: z.ZodString;
|
|
25
|
+
context: z.ZodString;
|
|
26
|
+
confidence: z.ZodNumber;
|
|
27
|
+
fitness_score: z.ZodNumber;
|
|
28
|
+
trust_tier: z.ZodEnum<{
|
|
29
|
+
quarantine: "quarantine";
|
|
30
|
+
local: "local";
|
|
31
|
+
verified: "verified";
|
|
32
|
+
canonical: "canonical";
|
|
33
|
+
}>;
|
|
34
|
+
source_agent_hash: z.ZodString;
|
|
35
|
+
decay_rate: z.ZodNumber;
|
|
36
|
+
type: z.ZodLiteral<"tool">;
|
|
37
|
+
tool_name: z.ZodString;
|
|
38
|
+
params_hash: z.ZodString;
|
|
39
|
+
outcome: z.ZodEnum<{
|
|
40
|
+
success: "success";
|
|
41
|
+
failure: "failure";
|
|
42
|
+
partial: "partial";
|
|
43
|
+
}>;
|
|
44
|
+
error_signature: z.ZodNullable<z.ZodString>;
|
|
45
|
+
latency_ms: z.ZodNullable<z.ZodNumber>;
|
|
46
|
+
reliability_score: z.ZodNumber;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
export declare const CreateNegativeAtomSchema: z.ZodObject<{
|
|
49
|
+
observation: z.ZodString;
|
|
50
|
+
context: z.ZodString;
|
|
51
|
+
confidence: z.ZodNumber;
|
|
52
|
+
fitness_score: z.ZodNumber;
|
|
53
|
+
trust_tier: z.ZodEnum<{
|
|
54
|
+
quarantine: "quarantine";
|
|
55
|
+
local: "local";
|
|
56
|
+
verified: "verified";
|
|
57
|
+
canonical: "canonical";
|
|
58
|
+
}>;
|
|
59
|
+
source_agent_hash: z.ZodString;
|
|
60
|
+
decay_rate: z.ZodNumber;
|
|
61
|
+
type: z.ZodLiteral<"negative">;
|
|
62
|
+
anti_pattern: z.ZodString;
|
|
63
|
+
failure_cluster_size: z.ZodNumber;
|
|
64
|
+
error_type: z.ZodString;
|
|
65
|
+
severity: z.ZodEnum<{
|
|
66
|
+
low: "low";
|
|
67
|
+
medium: "medium";
|
|
68
|
+
high: "high";
|
|
69
|
+
critical: "critical";
|
|
70
|
+
}>;
|
|
71
|
+
}, z.core.$strip>;
|
|
72
|
+
export declare const OutcomeSignalsSchema: z.ZodObject<{
|
|
73
|
+
completed_without_error: z.ZodBoolean;
|
|
74
|
+
revisited_within_1hr: z.ZodBoolean;
|
|
75
|
+
human_accepted: z.ZodNullable<z.ZodBoolean>;
|
|
76
|
+
convergence_steps: z.ZodNumber;
|
|
77
|
+
error_free: z.ZodBoolean;
|
|
78
|
+
}, z.core.$strip>;
|
|
79
|
+
/** Validate and return typed data, or throw ZodError */
|
|
80
|
+
export declare function validateCreateAtom(data: unknown): {
|
|
81
|
+
type: "tool" | "negative" | "pattern" | "skill" | "context";
|
|
82
|
+
observation: string;
|
|
83
|
+
context: string;
|
|
84
|
+
confidence: number;
|
|
85
|
+
fitness_score: number;
|
|
86
|
+
trust_tier: "quarantine" | "local" | "verified" | "canonical";
|
|
87
|
+
source_agent_hash: string;
|
|
88
|
+
decay_rate: number;
|
|
89
|
+
};
|
|
90
|
+
export declare function validateCreateToolAtom(data: unknown): {
|
|
91
|
+
observation: string;
|
|
92
|
+
context: string;
|
|
93
|
+
confidence: number;
|
|
94
|
+
fitness_score: number;
|
|
95
|
+
trust_tier: "quarantine" | "local" | "verified" | "canonical";
|
|
96
|
+
source_agent_hash: string;
|
|
97
|
+
decay_rate: number;
|
|
98
|
+
type: "tool";
|
|
99
|
+
tool_name: string;
|
|
100
|
+
params_hash: string;
|
|
101
|
+
outcome: "success" | "failure" | "partial";
|
|
102
|
+
error_signature: string | null;
|
|
103
|
+
latency_ms: number | null;
|
|
104
|
+
reliability_score: number;
|
|
105
|
+
};
|
|
106
|
+
export declare function validateCreateNegativeAtom(data: unknown): {
|
|
107
|
+
observation: string;
|
|
108
|
+
context: string;
|
|
109
|
+
confidence: number;
|
|
110
|
+
fitness_score: number;
|
|
111
|
+
trust_tier: "quarantine" | "local" | "verified" | "canonical";
|
|
112
|
+
source_agent_hash: string;
|
|
113
|
+
decay_rate: number;
|
|
114
|
+
type: "negative";
|
|
115
|
+
anti_pattern: string;
|
|
116
|
+
failure_cluster_size: number;
|
|
117
|
+
error_type: string;
|
|
118
|
+
severity: "low" | "medium" | "high" | "critical";
|
|
119
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// ── Shared enums ─────────────────────────────────────────────
|
|
3
|
+
const TrustTierSchema = z.enum(['quarantine', 'local', 'verified', 'canonical']);
|
|
4
|
+
const AtomTypeSchema = z.enum(['tool', 'negative', 'pattern', 'skill', 'context']);
|
|
5
|
+
const OutcomeSchema = z.enum(['success', 'failure', 'partial']);
|
|
6
|
+
const SeveritySchema = z.enum(['low', 'medium', 'high', 'critical']);
|
|
7
|
+
const unit = z.number().min(0).max(1);
|
|
8
|
+
// ── Base CreateAtom ──────────────────────────────────────────
|
|
9
|
+
export const CreateAtomSchema = z.object({
|
|
10
|
+
type: AtomTypeSchema,
|
|
11
|
+
observation: z.string().min(1),
|
|
12
|
+
context: z.string(),
|
|
13
|
+
confidence: unit,
|
|
14
|
+
fitness_score: unit,
|
|
15
|
+
trust_tier: TrustTierSchema,
|
|
16
|
+
source_agent_hash: z.string().min(1),
|
|
17
|
+
decay_rate: unit,
|
|
18
|
+
});
|
|
19
|
+
// ── CreateToolAtom ───────────────────────────────────────────
|
|
20
|
+
export const CreateToolAtomSchema = CreateAtomSchema.extend({
|
|
21
|
+
type: z.literal('tool'),
|
|
22
|
+
tool_name: z.string().min(1),
|
|
23
|
+
params_hash: z.string(),
|
|
24
|
+
outcome: OutcomeSchema,
|
|
25
|
+
error_signature: z.string().nullable(),
|
|
26
|
+
latency_ms: z.number().nullable(),
|
|
27
|
+
reliability_score: unit,
|
|
28
|
+
});
|
|
29
|
+
// ── CreateNegativeAtom ───────────────────────────────────────
|
|
30
|
+
export const CreateNegativeAtomSchema = CreateAtomSchema.extend({
|
|
31
|
+
type: z.literal('negative'),
|
|
32
|
+
anti_pattern: z.string().min(1),
|
|
33
|
+
failure_cluster_size: z.number().int().min(0),
|
|
34
|
+
error_type: z.string().min(1),
|
|
35
|
+
severity: SeveritySchema,
|
|
36
|
+
});
|
|
37
|
+
// ── OutcomeSignals ───────────────────────────────────────────
|
|
38
|
+
export const OutcomeSignalsSchema = z.object({
|
|
39
|
+
completed_without_error: z.boolean(),
|
|
40
|
+
revisited_within_1hr: z.boolean(),
|
|
41
|
+
human_accepted: z.boolean().nullable(),
|
|
42
|
+
convergence_steps: z.number().int().min(0),
|
|
43
|
+
error_free: z.boolean(),
|
|
44
|
+
});
|
|
45
|
+
/** Validate and return typed data, or throw ZodError */
|
|
46
|
+
export function validateCreateAtom(data) {
|
|
47
|
+
return CreateAtomSchema.parse(data);
|
|
48
|
+
}
|
|
49
|
+
export function validateCreateToolAtom(data) {
|
|
50
|
+
return CreateToolAtomSchema.parse(data);
|
|
51
|
+
}
|
|
52
|
+
export function validateCreateNegativeAtom(data) {
|
|
53
|
+
return CreateNegativeAtomSchema.parse(data);
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,gEAAgE;AAChE,MAAM,eAAe,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;AACjF,MAAM,cAAc,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;AACnF,MAAM,aAAa,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;AAChE,MAAM,cAAc,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;AAErE,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAEtC,gEAAgE;AAChE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,IAAI,EAAE,cAAc;IACpB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,UAAU,EAAE,IAAI;IAChB,aAAa,EAAE,IAAI;I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ACtC,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1C,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE;CACxB,CAAC,CAAC;AAEH,wDAAwD;AACxD,MAAM,UAAU,kBAAkB,CAAC,IAAa;IAC9C,OAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,IAAa;IAClD,OAAO,oBAAoB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,IAAa;IACtD,OAAO,wBAAwB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC9C,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@osmosis-ai/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Core knowledge atom types, local SQLite store, and instrumentation stubs for Osmosis",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"test:watch": "vitest"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"better-sqlite3": "^11.7.0",
|
|
15
|
+
"zod": "^4.3.6"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/better-sqlite3": "^7.6.12",
|
|
19
|
+
"typescript": "^5.7.0",
|
|
20
|
+
"vitest": "^3.0.0"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT"
|
|
23
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { createServer } from '../api/index.js';
|
|
3
|
+
import { AtomStore } from '../store/index.js';
|
|
4
|
+
import type { Server } from 'node:http';
|
|
5
|
+
|
|
6
|
+
const PORT = 19876;
|
|
7
|
+
|
|
8
|
+
function req(path: string, opts: RequestInit = {}): Promise<Response> {
|
|
9
|
+
return fetch(`http://localhost:${PORT}${path}`, opts);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe('REST API', () => {
|
|
13
|
+
let store: AtomStore;
|
|
14
|
+
let server: Server;
|
|
15
|
+
|
|
16
|
+
beforeEach(async () => {
|
|
17
|
+
store = new AtomStore(':memory:');
|
|
18
|
+
server = createServer(store, PORT);
|
|
19
|
+
await new Promise(r => server.once('listening', r));
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
afterEach(async () => {
|
|
23
|
+
await new Promise<void>(r => server.close(() => r()));
|
|
24
|
+
store.close();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('POST /atoms creates a context atom', async () => {
|
|
28
|
+
const res = await req('/atoms', {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
headers: { 'Content-Type': 'application/json' },
|
|
31
|
+
body: JSON.stringify({
|
|
32
|
+
type: 'context', observation: 'API test', context: '{}',
|
|
33
|
+
confidence: 0.5, fitness_score: 0.5, trust_tier: 'local',
|
|
34
|
+
source_agent_hash: 'test', decay_rate: 0.99,
|
|
35
|
+
}),
|
|
36
|
+
});
|
|
37
|
+
expect(res.status).toBe(201);
|
|
38
|
+
const body = await res.json();
|
|
39
|
+
expect(body.id).toBeTruthy();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('POST /atoms rejects invalid data', async () => {
|
|
43
|
+
const res = await req('/atoms', {
|
|
44
|
+
method: 'POST',
|
|
45
|
+
headers: { 'Content-Type': 'application/json' },
|
|
46
|
+
body: JSON.stringify({ type: 'context', observation: '' }),
|
|
47
|
+
});
|
|
48
|
+
expect(res.status).toBe(400);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('GET /atoms returns all', async () => {
|
|
52
|
+
store.createAtom({
|
|
53
|
+
type: 'context', observation: 'api get test', context: '{}',
|
|
54
|
+
confidence: 0.5, fitness_score: 0.5, trust_tier: 'local',
|
|
55
|
+
source_agent_hash: 'test', decay_rate: 0.99,
|
|
56
|
+
});
|
|
57
|
+
const res = await req('/atoms');
|
|
58
|
+
const body = await res.json();
|
|
59
|
+
expect(body).toHaveLength(1);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('GET /atoms/:id returns one atom', async () => {
|
|
63
|
+
const atom = store.createAtom({
|
|
64
|
+
type: 'context', observation: 'api id test', context: '{}',
|
|
65
|
+
confidence: 0.5, fitness_score: 0.5, trust_tier: 'local',
|
|
66
|
+
source_agent_hash: 'test', decay_rate: 0.99,
|
|
67
|
+
});
|
|
68
|
+
const res = await req(`/atoms/${atom.id}`);
|
|
69
|
+
expect(res.status).toBe(200);
|
|
70
|
+
const body = await res.json();
|
|
71
|
+
expect(body.id).toBe(atom.id);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('GET /atoms/:id returns 404 for missing', async () => {
|
|
75
|
+
const res = await req('/atoms/00000000-0000-0000-0000-000000000000');
|
|
76
|
+
expect(res.status).toBe(404);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('GET /atoms/search?q= searches', async () => {
|
|
80
|
+
store.createAtom({
|
|
81
|
+
type: 'context', observation: 'screenshot fails on lazy load', context: '{}',
|
|
82
|
+
confidence: 0.5, fitness_score: 0.5, trust_tier: 'local',
|
|
83
|
+
source_agent_hash: 'test', decay_rate: 0.99,
|
|
84
|
+
});
|
|
85
|
+
const res = await req('/atoms/search?q=screenshot');
|
|
86
|
+
const body = await res.json();
|
|
87
|
+
expect(body).toHaveLength(1);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('GET /atoms?type= filters by type', async () => {
|
|
91
|
+
store.createToolAtom({
|
|
92
|
+
type: 'tool', observation: 'tool filter test', context: '{}',
|
|
93
|
+
confidence: 0.5, fitness_score: 0.5, trust_tier: 'local',
|
|
94
|
+
source_agent_hash: 'test', decay_rate: 0.99,
|
|
95
|
+
tool_name: 'test.tool', params_hash: 'x',
|
|
96
|
+
outcome: 'success', error_signature: null,
|
|
97
|
+
latency_ms: null, reliability_score: 1,
|
|
98
|
+
});
|
|
99
|
+
const res = await req('/atoms?type=tool');
|
|
100
|
+
const body = await res.json();
|
|
101
|
+
expect(body).toHaveLength(1);
|
|
102
|
+
});
|
|
103
|
+
});
|