cognitive-core 0.0.2 → 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/README.md +302 -116
- package/SKILL.md +193 -0
- package/dist/agents/index.d.ts +3 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +5 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/mock-provider.d.ts +23 -0
- package/dist/agents/mock-provider.d.ts.map +1 -0
- package/dist/agents/mock-provider.js +71 -0
- package/dist/agents/mock-provider.js.map +1 -0
- package/dist/agents/types.d.ts +98 -0
- package/dist/agents/types.d.ts.map +1 -0
- package/dist/agents/types.js +44 -0
- package/dist/agents/types.js.map +1 -0
- package/dist/atlas.d.ts +196 -0
- package/dist/atlas.d.ts.map +1 -0
- package/dist/atlas.js +373 -0
- package/dist/atlas.js.map +1 -0
- package/dist/bin/cognitive-core.d.ts +18 -0
- package/dist/bin/cognitive-core.d.ts.map +1 -0
- package/dist/bin/cognitive-core.js +419 -0
- package/dist/bin/cognitive-core.js.map +1 -0
- package/dist/embeddings/bm25.d.ts +104 -0
- package/dist/embeddings/bm25.d.ts.map +1 -0
- package/dist/embeddings/bm25.js +264 -0
- package/dist/embeddings/bm25.js.map +1 -0
- package/dist/embeddings/index.d.ts +12 -0
- package/dist/embeddings/index.d.ts.map +1 -0
- package/dist/embeddings/index.js +16 -0
- package/dist/embeddings/index.js.map +1 -0
- package/dist/embeddings/manager.d.ts +112 -0
- package/dist/embeddings/manager.d.ts.map +1 -0
- package/dist/embeddings/manager.js +215 -0
- package/dist/embeddings/manager.js.map +1 -0
- package/dist/embeddings/provider.d.ts +101 -0
- package/dist/embeddings/provider.d.ts.map +1 -0
- package/dist/embeddings/provider.js +232 -0
- package/dist/embeddings/provider.js.map +1 -0
- package/dist/embeddings/vector-store.d.ts +101 -0
- package/dist/embeddings/vector-store.d.ts.map +1 -0
- package/dist/embeddings/vector-store.js +256 -0
- package/dist/embeddings/vector-store.js.map +1 -0
- package/dist/factory.d.ts +193 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +109 -0
- package/dist/factory.js.map +1 -0
- package/dist/index.d.ts +30 -453
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -509
- package/dist/index.js.map +1 -0
- package/dist/learning/analyzer.d.ts +110 -0
- package/dist/learning/analyzer.d.ts.map +1 -0
- package/dist/learning/analyzer.js +213 -0
- package/dist/learning/analyzer.js.map +1 -0
- package/dist/learning/effectiveness.d.ts +158 -0
- package/dist/learning/effectiveness.d.ts.map +1 -0
- package/dist/learning/effectiveness.js +251 -0
- package/dist/learning/effectiveness.js.map +1 -0
- package/dist/learning/index.d.ts +8 -0
- package/dist/learning/index.d.ts.map +1 -0
- package/dist/learning/index.js +11 -0
- package/dist/learning/index.js.map +1 -0
- package/dist/learning/llm-extractor.d.ts +88 -0
- package/dist/learning/llm-extractor.d.ts.map +1 -0
- package/dist/learning/llm-extractor.js +372 -0
- package/dist/learning/llm-extractor.js.map +1 -0
- package/dist/learning/meta-learner.d.ts +80 -0
- package/dist/learning/meta-learner.d.ts.map +1 -0
- package/dist/learning/meta-learner.js +355 -0
- package/dist/learning/meta-learner.js.map +1 -0
- package/dist/learning/pipeline.d.ts +65 -0
- package/dist/learning/pipeline.d.ts.map +1 -0
- package/dist/learning/pipeline.js +170 -0
- package/dist/learning/pipeline.js.map +1 -0
- package/dist/learning/playbook-extractor.d.ts +113 -0
- package/dist/learning/playbook-extractor.d.ts.map +1 -0
- package/dist/learning/playbook-extractor.js +523 -0
- package/dist/learning/playbook-extractor.js.map +1 -0
- package/dist/learning/usage-inference.d.ts +82 -0
- package/dist/learning/usage-inference.d.ts.map +1 -0
- package/dist/learning/usage-inference.js +261 -0
- package/dist/learning/usage-inference.js.map +1 -0
- package/dist/mcp/index.d.ts +6 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +6 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/playbook-server.d.ts +120 -0
- package/dist/mcp/playbook-server.d.ts.map +1 -0
- package/dist/mcp/playbook-server.js +427 -0
- package/dist/mcp/playbook-server.js.map +1 -0
- package/dist/memory/curated-loader.d.ts +62 -0
- package/dist/memory/curated-loader.d.ts.map +1 -0
- package/dist/memory/curated-loader.js +106 -0
- package/dist/memory/curated-loader.js.map +1 -0
- package/dist/memory/experience.d.ts +122 -0
- package/dist/memory/experience.d.ts.map +1 -0
- package/dist/memory/experience.js +392 -0
- package/dist/memory/experience.js.map +1 -0
- package/dist/memory/index.d.ts +6 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +9 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/meta.d.ts +90 -0
- package/dist/memory/meta.d.ts.map +1 -0
- package/dist/memory/meta.js +362 -0
- package/dist/memory/meta.js.map +1 -0
- package/dist/memory/playbook.d.ts +133 -0
- package/dist/memory/playbook.d.ts.map +1 -0
- package/dist/memory/playbook.js +357 -0
- package/dist/memory/playbook.js.map +1 -0
- package/dist/memory/system.d.ts +167 -0
- package/dist/memory/system.d.ts.map +1 -0
- package/dist/memory/system.js +383 -0
- package/dist/memory/system.js.map +1 -0
- package/dist/runtime/backends/acp.d.ts +67 -0
- package/dist/runtime/backends/acp.d.ts.map +1 -0
- package/dist/runtime/backends/acp.js +290 -0
- package/dist/runtime/backends/acp.js.map +1 -0
- package/dist/runtime/backends/index.d.ts +5 -0
- package/dist/runtime/backends/index.d.ts.map +1 -0
- package/dist/runtime/backends/index.js +6 -0
- package/dist/runtime/backends/index.js.map +1 -0
- package/dist/runtime/backends/mock.d.ts +67 -0
- package/dist/runtime/backends/mock.d.ts.map +1 -0
- package/dist/runtime/backends/mock.js +153 -0
- package/dist/runtime/backends/mock.js.map +1 -0
- package/dist/runtime/backends/subprocess.d.ts +56 -0
- package/dist/runtime/backends/subprocess.d.ts.map +1 -0
- package/dist/runtime/backends/subprocess.js +260 -0
- package/dist/runtime/backends/subprocess.js.map +1 -0
- package/dist/runtime/flows/learning.d.ts +73 -0
- package/dist/runtime/flows/learning.d.ts.map +1 -0
- package/dist/runtime/flows/learning.js +116 -0
- package/dist/runtime/flows/learning.js.map +1 -0
- package/dist/runtime/flows/validation.d.ts +122 -0
- package/dist/runtime/flows/validation.d.ts.map +1 -0
- package/dist/runtime/flows/validation.js +223 -0
- package/dist/runtime/flows/validation.js.map +1 -0
- package/dist/runtime/index.d.ts +6 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +8 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/manager.d.ts +116 -0
- package/dist/runtime/manager.d.ts.map +1 -0
- package/dist/runtime/manager.js +416 -0
- package/dist/runtime/manager.js.map +1 -0
- package/dist/runtime/types.d.ts +138 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +2 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/search/evaluator.d.ts +102 -0
- package/dist/search/evaluator.d.ts.map +1 -0
- package/dist/search/evaluator.js +352 -0
- package/dist/search/evaluator.js.map +1 -0
- package/dist/search/index.d.ts +7 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +11 -0
- package/dist/search/index.js.map +1 -0
- package/dist/search/refinement-loop.d.ts +73 -0
- package/dist/search/refinement-loop.d.ts.map +1 -0
- package/dist/search/refinement-loop.js +245 -0
- package/dist/search/refinement-loop.js.map +1 -0
- package/dist/search/refinement-types.d.ts +154 -0
- package/dist/search/refinement-types.d.ts.map +1 -0
- package/dist/search/refinement-types.js +99 -0
- package/dist/search/refinement-types.js.map +1 -0
- package/dist/search/router.d.ts +61 -0
- package/dist/search/router.d.ts.map +1 -0
- package/dist/search/router.js +197 -0
- package/dist/search/router.js.map +1 -0
- package/dist/search/solver.d.ts +75 -0
- package/dist/search/solver.d.ts.map +1 -0
- package/dist/search/solver.js +216 -0
- package/dist/search/solver.js.map +1 -0
- package/dist/search/verification-runner.d.ts +125 -0
- package/dist/search/verification-runner.d.ts.map +1 -0
- package/dist/search/verification-runner.js +440 -0
- package/dist/search/verification-runner.js.map +1 -0
- package/dist/surfacing/index.d.ts +2 -0
- package/dist/surfacing/index.d.ts.map +1 -0
- package/dist/surfacing/index.js +2 -0
- package/dist/surfacing/index.js.map +1 -0
- package/dist/surfacing/skill-library.d.ts +158 -0
- package/dist/surfacing/skill-library.d.ts.map +1 -0
- package/dist/surfacing/skill-library.js +429 -0
- package/dist/surfacing/skill-library.js.map +1 -0
- package/dist/types/config.d.ts +1113 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +274 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +14 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/memory.d.ts +339 -0
- package/dist/types/memory.d.ts.map +1 -0
- package/dist/types/memory.js +207 -0
- package/dist/types/memory.js.map +1 -0
- package/dist/types/meta.d.ts +146 -0
- package/dist/types/meta.d.ts.map +1 -0
- package/dist/types/meta.js +51 -0
- package/dist/types/meta.js.map +1 -0
- package/dist/types/outcome.d.ts +42 -0
- package/dist/types/outcome.d.ts.map +1 -0
- package/dist/types/outcome.js +50 -0
- package/dist/types/outcome.js.map +1 -0
- package/dist/types/playbook.d.ts +119 -0
- package/dist/types/playbook.d.ts.map +1 -0
- package/dist/types/playbook.js +71 -0
- package/dist/types/playbook.js.map +1 -0
- package/dist/types/step.d.ts +44 -0
- package/dist/types/step.d.ts.map +1 -0
- package/dist/types/step.js +32 -0
- package/dist/types/step.js.map +1 -0
- package/dist/types/task.d.ts +91 -0
- package/dist/types/task.d.ts.map +1 -0
- package/dist/types/task.js +39 -0
- package/dist/types/task.js.map +1 -0
- package/dist/types/trajectory.d.ts +221 -0
- package/dist/types/trajectory.d.ts.map +1 -0
- package/dist/types/trajectory.js +60 -0
- package/dist/types/trajectory.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/similarity.d.ts +31 -0
- package/dist/utils/similarity.d.ts.map +1 -0
- package/dist/utils/similarity.js +107 -0
- package/dist/utils/similarity.js.map +1 -0
- package/dist/utils/storage.d.ts +106 -0
- package/dist/utils/storage.d.ts.map +1 -0
- package/dist/utils/storage.js +203 -0
- package/dist/utils/storage.js.map +1 -0
- package/dist/utils/validation.d.ts +129 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +171 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +50 -34
- package/scripts/migrate-to-playbooks.ts +307 -0
- package/src/agents/index.ts +14 -0
- package/src/agents/mock-provider.ts +93 -0
- package/src/agents/types.ts +137 -0
- package/src/atlas.ts +560 -0
- package/src/bin/cognitive-core.ts +470 -0
- package/src/embeddings/bm25.ts +337 -0
- package/src/embeddings/index.ts +39 -0
- package/src/embeddings/manager.ts +288 -0
- package/src/embeddings/provider.ts +311 -0
- package/src/embeddings/vector-store.ts +353 -0
- package/src/factory.ts +263 -0
- package/src/index.ts +246 -0
- package/src/learning/analyzer.ts +335 -0
- package/src/learning/effectiveness.ts +428 -0
- package/src/learning/index.ts +58 -0
- package/src/learning/llm-extractor.ts +542 -0
- package/src/learning/meta-learner.ts +516 -0
- package/src/learning/pipeline.ts +244 -0
- package/src/learning/playbook-extractor.ts +702 -0
- package/src/learning/usage-inference.ts +372 -0
- package/src/mcp/index.ts +12 -0
- package/src/mcp/playbook-server.ts +565 -0
- package/src/memory/curated-loader.ts +160 -0
- package/src/memory/experience.ts +515 -0
- package/src/memory/index.ts +27 -0
- package/src/memory/meta.ts +506 -0
- package/src/memory/playbook.ts +493 -0
- package/src/memory/system.ts +551 -0
- package/src/runtime/backends/acp.ts +378 -0
- package/src/runtime/backends/index.ts +24 -0
- package/src/runtime/backends/mock.ts +218 -0
- package/src/runtime/backends/subprocess.ts +356 -0
- package/src/runtime/flows/learning.ts +183 -0
- package/src/runtime/flows/validation.ts +381 -0
- package/src/runtime/index.ts +53 -0
- package/src/runtime/manager.ts +541 -0
- package/src/runtime/types.ts +157 -0
- package/src/search/evaluator.ts +474 -0
- package/src/search/index.ts +59 -0
- package/src/search/refinement-loop.ts +363 -0
- package/src/search/refinement-types.ts +159 -0
- package/src/search/router.ts +261 -0
- package/src/search/solver.ts +303 -0
- package/src/search/verification-runner.ts +570 -0
- package/src/surfacing/index.ts +6 -0
- package/src/surfacing/skill-library.ts +594 -0
- package/src/types/config.ts +333 -0
- package/src/types/index.ts +130 -0
- package/src/types/memory.ts +270 -0
- package/src/types/meta.ts +218 -0
- package/src/types/outcome.ts +66 -0
- package/src/types/playbook.ts +196 -0
- package/src/types/step.ts +40 -0
- package/src/types/task.ts +52 -0
- package/src/types/trajectory.ts +80 -0
- package/src/utils/index.ts +38 -0
- package/src/utils/similarity.ts +139 -0
- package/src/utils/storage.ts +249 -0
- package/src/utils/validation.ts +286 -0
- package/tests/embeddings/bm25.test.ts +130 -0
- package/tests/embeddings/manager.test.ts +205 -0
- package/tests/integration/atlas.test.ts +266 -0
- package/tests/integration/e2e.test.ts +929 -0
- package/tests/learning/analyzer.test.ts +426 -0
- package/tests/learning/effectiveness.test.ts +542 -0
- package/tests/learning/pipeline.test.ts +176 -0
- package/tests/learning/playbook-extractor-provenance.test.ts +114 -0
- package/tests/learning/usage-inference.test.ts +254 -0
- package/tests/mcp/playbook-server.test.ts +252 -0
- package/tests/memory/experience.test.ts +198 -0
- package/tests/memory/playbook.test.ts +338 -0
- package/tests/memory/provenance.test.ts +639 -0
- package/tests/memory/system.test.ts +325 -0
- package/tests/runtime/agent-manager.test.ts +512 -0
- package/tests/runtime/mock-backend.test.ts +248 -0
- package/tests/search/refinement-loop.test.ts +468 -0
- package/tests/search/refinement.test.ts +267 -0
- package/tests/search/router.test.ts +427 -0
- package/tests/surfacing/skill-library.test.ts +292 -0
- package/tests/types/outcome.test.ts +147 -0
- package/tests/types/step.test.ts +133 -0
- package/tests/types/task.test.ts +158 -0
- package/tests/types/trajectory.test.ts +253 -0
- package/tests/utils/similarity.test.ts +188 -0
- package/tests/utils/validation.test.ts +252 -0
- package/tsconfig.json +25 -0
- package/vitest.config.ts +22 -0
- package/dist/index.d.mts +0 -466
- package/dist/index.mjs +0 -478
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Playbook Types
|
|
3
|
+
*
|
|
4
|
+
* Playbook - Adaptive guidance that evolves with experience
|
|
5
|
+
* Merges ArcMemo strategies with Claudeception skills + Voyager evolution
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Playbook - The core learning unit that replaces Strategy + Skill
|
|
10
|
+
* Provides adaptive guidance that evolves based on usage outcomes
|
|
11
|
+
*/
|
|
12
|
+
export interface Playbook {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string; // kebab-case identifier
|
|
15
|
+
|
|
16
|
+
// === APPLICABILITY (when to use) ===
|
|
17
|
+
applicability: PlaybookApplicability;
|
|
18
|
+
|
|
19
|
+
// === GUIDANCE (what to do) ===
|
|
20
|
+
guidance: PlaybookGuidance;
|
|
21
|
+
|
|
22
|
+
// === VERIFICATION (how to know it worked) ===
|
|
23
|
+
verification: PlaybookVerification;
|
|
24
|
+
|
|
25
|
+
// === EVOLUTION (Voyager-style learning) ===
|
|
26
|
+
evolution: PlaybookEvolution;
|
|
27
|
+
|
|
28
|
+
// === PROVENANCE ===
|
|
29
|
+
provenance?: PlaybookProvenance;
|
|
30
|
+
|
|
31
|
+
// === METADATA ===
|
|
32
|
+
confidence: number; // 0-1, grows with successful use
|
|
33
|
+
complexity: PlaybookComplexity;
|
|
34
|
+
estimatedEffort: number; // Rough LLM calls needed
|
|
35
|
+
embedding?: number[]; // For semantic search
|
|
36
|
+
createdAt: Date;
|
|
37
|
+
updatedAt: Date;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* When to apply this playbook
|
|
42
|
+
*/
|
|
43
|
+
export interface PlaybookApplicability {
|
|
44
|
+
situations: string[]; // High-level: "debugging async code"
|
|
45
|
+
triggers: string[]; // Concrete: "Promise rejection", "TS2307"
|
|
46
|
+
antiPatterns: string[]; // When NOT to use (avoids false positives)
|
|
47
|
+
domains: string[]; // "typescript", "react", "api", "testing"
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* What to do when the playbook applies
|
|
52
|
+
*/
|
|
53
|
+
export interface PlaybookGuidance {
|
|
54
|
+
strategy: string; // High-level approach
|
|
55
|
+
tactics: string[]; // Mid-level steps
|
|
56
|
+
steps?: string[]; // Optional concrete commands
|
|
57
|
+
codeExample?: string; // Optional illustrative code
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* How to verify the playbook worked
|
|
62
|
+
*/
|
|
63
|
+
export interface PlaybookVerification {
|
|
64
|
+
successIndicators: string[]; // "Build passes", "Tests green"
|
|
65
|
+
failureIndicators: string[]; // "Same error", "New errors introduced"
|
|
66
|
+
rollbackStrategy?: string; // How to undo if it fails
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Provenance tracking - where a playbook came from
|
|
71
|
+
*/
|
|
72
|
+
export type PlaybookOrigin = 'extracted' | 'curated' | 'imported' | 'manual';
|
|
73
|
+
|
|
74
|
+
export interface PlaybookProvenance {
|
|
75
|
+
/** How the playbook was created */
|
|
76
|
+
origin: PlaybookOrigin;
|
|
77
|
+
/** For curated: relative path to source file (e.g. "playbooks/typescript-debugging.json") */
|
|
78
|
+
sourceFile?: string;
|
|
79
|
+
/** For imported: identifier of the source (e.g. "dash-agent", "community-pack") */
|
|
80
|
+
importedFrom?: string;
|
|
81
|
+
/** For curated: who authored it */
|
|
82
|
+
curatedBy?: string;
|
|
83
|
+
/** When this provenance was recorded */
|
|
84
|
+
recordedAt: Date;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Evolution tracking for Voyager-style learning
|
|
89
|
+
*/
|
|
90
|
+
export interface PlaybookEvolution {
|
|
91
|
+
version: string; // Semantic versioning
|
|
92
|
+
createdFrom: string[]; // Source trajectory IDs
|
|
93
|
+
failures: FailureRecord[]; // What went wrong
|
|
94
|
+
refinements: Refinement[]; // Context-specific adaptations
|
|
95
|
+
successCount: number;
|
|
96
|
+
failureCount: number;
|
|
97
|
+
lastUsed?: Date;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Record of a failure when applying the playbook
|
|
102
|
+
*/
|
|
103
|
+
export interface FailureRecord {
|
|
104
|
+
trajectoryId: string;
|
|
105
|
+
context: string; // What was different
|
|
106
|
+
failureMode: string; // How it failed
|
|
107
|
+
timestamp: Date;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Context-specific refinement to the playbook
|
|
112
|
+
*/
|
|
113
|
+
export interface Refinement {
|
|
114
|
+
context: string; // "monorepo", "esm", "legacy codebase"
|
|
115
|
+
addition: string; // "Also check workspace symlinks"
|
|
116
|
+
source: 'failure' | 'success' | 'manual';
|
|
117
|
+
addedAt: Date;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export type PlaybookComplexity = 'simple' | 'moderate' | 'complex';
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Create a new playbook with defaults
|
|
124
|
+
*/
|
|
125
|
+
export function createPlaybook(
|
|
126
|
+
input: Partial<Playbook> & {
|
|
127
|
+
name: string;
|
|
128
|
+
applicability: PlaybookApplicability;
|
|
129
|
+
guidance: PlaybookGuidance;
|
|
130
|
+
}
|
|
131
|
+
): Playbook {
|
|
132
|
+
const now = new Date();
|
|
133
|
+
return {
|
|
134
|
+
id: input.id ?? `playbook-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
135
|
+
name: input.name,
|
|
136
|
+
applicability: input.applicability,
|
|
137
|
+
guidance: input.guidance,
|
|
138
|
+
verification: input.verification ?? {
|
|
139
|
+
successIndicators: [],
|
|
140
|
+
failureIndicators: [],
|
|
141
|
+
},
|
|
142
|
+
evolution: input.evolution ?? {
|
|
143
|
+
version: '1.0.0',
|
|
144
|
+
createdFrom: [],
|
|
145
|
+
failures: [],
|
|
146
|
+
refinements: [],
|
|
147
|
+
successCount: 0,
|
|
148
|
+
failureCount: 0,
|
|
149
|
+
},
|
|
150
|
+
provenance: input.provenance ?? {
|
|
151
|
+
origin: 'extracted',
|
|
152
|
+
recordedAt: now,
|
|
153
|
+
},
|
|
154
|
+
confidence: input.confidence ?? 0.3, // Start with low confidence
|
|
155
|
+
complexity: input.complexity ?? 'moderate',
|
|
156
|
+
estimatedEffort: input.estimatedEffort ?? 3,
|
|
157
|
+
embedding: input.embedding,
|
|
158
|
+
createdAt: input.createdAt ?? now,
|
|
159
|
+
updatedAt: input.updatedAt ?? now,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Bump playbook version
|
|
165
|
+
*/
|
|
166
|
+
export function bumpPlaybookVersion(
|
|
167
|
+
playbook: Playbook,
|
|
168
|
+
type: 'major' | 'minor' | 'patch' = 'patch'
|
|
169
|
+
): string {
|
|
170
|
+
const [major, minor, patch] = playbook.evolution.version.split('.').map(Number);
|
|
171
|
+
switch (type) {
|
|
172
|
+
case 'major':
|
|
173
|
+
return `${major + 1}.0.0`;
|
|
174
|
+
case 'minor':
|
|
175
|
+
return `${major}.${minor + 1}.0`;
|
|
176
|
+
case 'patch':
|
|
177
|
+
default:
|
|
178
|
+
return `${major}.${minor}.${patch + 1}`;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Calculate playbook success rate
|
|
184
|
+
*/
|
|
185
|
+
export function getPlaybookSuccessRate(playbook: Playbook): number {
|
|
186
|
+
const total = playbook.evolution.successCount + playbook.evolution.failureCount;
|
|
187
|
+
if (total === 0) return 0;
|
|
188
|
+
return playbook.evolution.successCount / total;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Check if playbook has been used enough for reliable statistics
|
|
193
|
+
*/
|
|
194
|
+
export function hasReliableStats(playbook: Playbook, minUses: number = 3): boolean {
|
|
195
|
+
return playbook.evolution.successCount + playbook.evolution.failureCount >= minUses;
|
|
196
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Step - A single action in a trajectory
|
|
5
|
+
* Follows ReAct-style (Reasoning + Acting) pattern
|
|
6
|
+
*/
|
|
7
|
+
export const StepSchema = z.object({
|
|
8
|
+
/** Optional reasoning/thought before action */
|
|
9
|
+
thought: z.string().optional(),
|
|
10
|
+
/** The action taken */
|
|
11
|
+
action: z.string(),
|
|
12
|
+
/** Result/observation from the action */
|
|
13
|
+
observation: z.string(),
|
|
14
|
+
/** Timestamp when step was executed */
|
|
15
|
+
timestamp: z.date().default(() => new Date()),
|
|
16
|
+
/** Additional metadata */
|
|
17
|
+
metadata: z.record(z.unknown()).default({}),
|
|
18
|
+
/** Credit attribution score (0-1), assigned during analysis */
|
|
19
|
+
attributionScore: z.number().min(0).max(1).optional(),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export type Step = z.infer<typeof StepSchema>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Create a new step
|
|
26
|
+
*/
|
|
27
|
+
export function createStep(params: {
|
|
28
|
+
thought?: string;
|
|
29
|
+
action: string;
|
|
30
|
+
observation: string;
|
|
31
|
+
metadata?: Record<string, unknown>;
|
|
32
|
+
}): Step {
|
|
33
|
+
return StepSchema.parse({
|
|
34
|
+
thought: params.thought,
|
|
35
|
+
action: params.action,
|
|
36
|
+
observation: params.observation,
|
|
37
|
+
timestamp: new Date(),
|
|
38
|
+
metadata: params.metadata ?? {},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Verification specification for validating task outcomes
|
|
5
|
+
*/
|
|
6
|
+
export const VerificationSpecSchema = z.object({
|
|
7
|
+
type: z.enum(['exact_match', 'fuzzy_match', 'function', 'llm']),
|
|
8
|
+
expected: z.unknown().optional(),
|
|
9
|
+
tolerance: z.number().optional(),
|
|
10
|
+
verifier_id: z.string().optional(),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export type VerificationSpec = z.infer<typeof VerificationSpecSchema>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Task - The fundamental unit of work
|
|
17
|
+
* Represents what an agent needs to accomplish
|
|
18
|
+
*/
|
|
19
|
+
export const TaskSchema = z.object({
|
|
20
|
+
id: z.string(),
|
|
21
|
+
domain: z.string(), // e.g., 'arc', 'swe', 'code', 'reasoning'
|
|
22
|
+
description: z.string(),
|
|
23
|
+
context: z.record(z.unknown()).default({}),
|
|
24
|
+
verification: VerificationSpecSchema.optional(),
|
|
25
|
+
embedding: z.array(z.number()).optional(),
|
|
26
|
+
metadata: z.record(z.unknown()).default({}),
|
|
27
|
+
createdAt: z.date().default(() => new Date()),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export type Task = z.infer<typeof TaskSchema>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Create a new task with defaults
|
|
34
|
+
*/
|
|
35
|
+
export function createTask(params: {
|
|
36
|
+
id?: string;
|
|
37
|
+
domain: string;
|
|
38
|
+
description: string;
|
|
39
|
+
context?: Record<string, unknown>;
|
|
40
|
+
verification?: VerificationSpec;
|
|
41
|
+
metadata?: Record<string, unknown>;
|
|
42
|
+
}): Task {
|
|
43
|
+
return TaskSchema.parse({
|
|
44
|
+
id: params.id ?? crypto.randomUUID(),
|
|
45
|
+
domain: params.domain,
|
|
46
|
+
description: params.description,
|
|
47
|
+
context: params.context ?? {},
|
|
48
|
+
verification: params.verification,
|
|
49
|
+
metadata: params.metadata ?? {},
|
|
50
|
+
createdAt: new Date(),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { TaskSchema, type Task } from './task.js';
|
|
3
|
+
import { StepSchema, type Step } from './step.js';
|
|
4
|
+
import { OutcomeSchema, type Outcome } from './outcome.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Trajectory - A complete record of an agent's task-solving attempt
|
|
8
|
+
* The atomic unit of learning in Atlas
|
|
9
|
+
*/
|
|
10
|
+
export const TrajectorySchema = z.object({
|
|
11
|
+
/** Unique trajectory identifier */
|
|
12
|
+
id: z.string(),
|
|
13
|
+
/** The task being solved */
|
|
14
|
+
task: TaskSchema,
|
|
15
|
+
/** Sequence of steps taken */
|
|
16
|
+
steps: z.array(StepSchema),
|
|
17
|
+
/** Final outcome */
|
|
18
|
+
outcome: OutcomeSchema,
|
|
19
|
+
/** Identifier of the agent that produced this trajectory */
|
|
20
|
+
agentId: z.string(),
|
|
21
|
+
/** When the trajectory was created */
|
|
22
|
+
timestamp: z.date().default(() => new Date()),
|
|
23
|
+
/** Number of LLM API calls made */
|
|
24
|
+
llmCalls: z.number().default(0),
|
|
25
|
+
/** Total tokens used */
|
|
26
|
+
totalTokens: z.number().default(0),
|
|
27
|
+
/** Wall clock time in seconds */
|
|
28
|
+
wallTimeSeconds: z.number().default(0),
|
|
29
|
+
/** Additional metadata */
|
|
30
|
+
metadata: z.record(z.unknown()).default({}),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export type Trajectory = z.infer<typeof TrajectorySchema>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Create a new trajectory
|
|
37
|
+
*/
|
|
38
|
+
export function createTrajectory(params: {
|
|
39
|
+
id?: string;
|
|
40
|
+
task: Task;
|
|
41
|
+
steps: Step[];
|
|
42
|
+
outcome: Outcome;
|
|
43
|
+
agentId: string;
|
|
44
|
+
llmCalls?: number;
|
|
45
|
+
totalTokens?: number;
|
|
46
|
+
wallTimeSeconds?: number;
|
|
47
|
+
metadata?: Record<string, unknown>;
|
|
48
|
+
}): Trajectory {
|
|
49
|
+
return TrajectorySchema.parse({
|
|
50
|
+
id: params.id ?? crypto.randomUUID(),
|
|
51
|
+
task: params.task,
|
|
52
|
+
steps: params.steps,
|
|
53
|
+
outcome: params.outcome,
|
|
54
|
+
agentId: params.agentId,
|
|
55
|
+
timestamp: new Date(),
|
|
56
|
+
llmCalls: params.llmCalls ?? 0,
|
|
57
|
+
totalTokens: params.totalTokens ?? 0,
|
|
58
|
+
wallTimeSeconds: params.wallTimeSeconds ?? 0,
|
|
59
|
+
metadata: params.metadata ?? {},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Check if trajectory was successful
|
|
65
|
+
*/
|
|
66
|
+
export function isSuccessful(trajectory: Trajectory): boolean {
|
|
67
|
+
return trajectory.outcome.success;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Get key steps (those with high attribution scores)
|
|
72
|
+
*/
|
|
73
|
+
export function getKeySteps(
|
|
74
|
+
trajectory: Trajectory,
|
|
75
|
+
threshold = 0.15
|
|
76
|
+
): Step[] {
|
|
77
|
+
return trajectory.steps.filter(
|
|
78
|
+
(step) => (step.attributionScore ?? 0) >= threshold
|
|
79
|
+
);
|
|
80
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export {
|
|
2
|
+
cosineSimilarity,
|
|
3
|
+
jaccardSimilarity,
|
|
4
|
+
textSimilarity,
|
|
5
|
+
ngramSimilarity,
|
|
6
|
+
tokenize,
|
|
7
|
+
findTopK,
|
|
8
|
+
} from './similarity.js';
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
ensureDir,
|
|
12
|
+
saveJson,
|
|
13
|
+
loadJson,
|
|
14
|
+
listFiles,
|
|
15
|
+
exists,
|
|
16
|
+
JsonStore,
|
|
17
|
+
saveIndex,
|
|
18
|
+
loadIndex,
|
|
19
|
+
type StorageOptions,
|
|
20
|
+
} from './storage.js';
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
ValidationError,
|
|
24
|
+
validateString,
|
|
25
|
+
validateOptionalString,
|
|
26
|
+
validateNumber,
|
|
27
|
+
validateOptionalNumber,
|
|
28
|
+
validateArray,
|
|
29
|
+
validateVector,
|
|
30
|
+
validateTaskInput,
|
|
31
|
+
validateTrajectoryStepCount,
|
|
32
|
+
validateMCPArgs,
|
|
33
|
+
TaskInputSchema,
|
|
34
|
+
MCPSearchPlaybooksSchema,
|
|
35
|
+
MCPGetPlaybookDetailsSchema,
|
|
36
|
+
MCPGetPlaybooksByDomainSchema,
|
|
37
|
+
type TaskInput,
|
|
38
|
+
} from './validation.js';
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Similarity utilities for comparing embeddings and text
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Compute cosine similarity between two vectors
|
|
7
|
+
*/
|
|
8
|
+
export function cosineSimilarity(a: number[], b: number[]): number {
|
|
9
|
+
if (a.length !== b.length) {
|
|
10
|
+
throw new Error('Vectors must have the same length');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let dotProduct = 0;
|
|
14
|
+
let normA = 0;
|
|
15
|
+
let normB = 0;
|
|
16
|
+
|
|
17
|
+
for (let i = 0; i < a.length; i++) {
|
|
18
|
+
dotProduct += a[i] * b[i];
|
|
19
|
+
normA += a[i] * a[i];
|
|
20
|
+
normB += b[i] * b[i];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
normA = Math.sqrt(normA);
|
|
24
|
+
normB = Math.sqrt(normB);
|
|
25
|
+
|
|
26
|
+
if (normA === 0 || normB === 0) {
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return dotProduct / (normA * normB);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Compute Jaccard similarity between two sets of words
|
|
35
|
+
*/
|
|
36
|
+
export function jaccardSimilarity(a: string, b: string): number {
|
|
37
|
+
const setA = new Set(tokenize(a));
|
|
38
|
+
const setB = new Set(tokenize(b));
|
|
39
|
+
|
|
40
|
+
const intersection = new Set([...setA].filter((x) => setB.has(x)));
|
|
41
|
+
const union = new Set([...setA, ...setB]);
|
|
42
|
+
|
|
43
|
+
if (union.size === 0) {
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return intersection.size / union.size;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Simple tokenization for text similarity
|
|
52
|
+
*/
|
|
53
|
+
export function tokenize(text: string): string[] {
|
|
54
|
+
return text
|
|
55
|
+
.toLowerCase()
|
|
56
|
+
.replace(/[^\w\s]/g, ' ')
|
|
57
|
+
.split(/\s+/)
|
|
58
|
+
.filter((token) => token.length > 0);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Compute n-gram overlap similarity
|
|
63
|
+
*/
|
|
64
|
+
export function ngramSimilarity(
|
|
65
|
+
a: string,
|
|
66
|
+
b: string,
|
|
67
|
+
n = 3
|
|
68
|
+
): number {
|
|
69
|
+
const ngramsA = getNgrams(a, n);
|
|
70
|
+
const ngramsB = getNgrams(b, n);
|
|
71
|
+
|
|
72
|
+
const intersection = new Set(
|
|
73
|
+
[...ngramsA].filter((x) => ngramsB.has(x))
|
|
74
|
+
);
|
|
75
|
+
const union = new Set([...ngramsA, ...ngramsB]);
|
|
76
|
+
|
|
77
|
+
if (union.size === 0) {
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return intersection.size / union.size;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Get character n-grams from text
|
|
86
|
+
*/
|
|
87
|
+
function getNgrams(text: string, n: number): Set<string> {
|
|
88
|
+
const ngrams = new Set<string>();
|
|
89
|
+
const normalized = text.toLowerCase();
|
|
90
|
+
|
|
91
|
+
for (let i = 0; i <= normalized.length - n; i++) {
|
|
92
|
+
ngrams.add(normalized.slice(i, i + n));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return ngrams;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Combined text similarity using multiple methods
|
|
100
|
+
*/
|
|
101
|
+
export function textSimilarity(a: string, b: string): number {
|
|
102
|
+
const jaccard = jaccardSimilarity(a, b);
|
|
103
|
+
const ngram = ngramSimilarity(a, b);
|
|
104
|
+
|
|
105
|
+
// Weighted average
|
|
106
|
+
return jaccard * 0.6 + ngram * 0.4;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Find top-k most similar items
|
|
111
|
+
*/
|
|
112
|
+
export function findTopK<T>(
|
|
113
|
+
query: number[] | string,
|
|
114
|
+
items: T[],
|
|
115
|
+
getVector: (item: T) => number[] | string | undefined,
|
|
116
|
+
k: number
|
|
117
|
+
): Array<{ item: T; score: number }> {
|
|
118
|
+
const scored = items
|
|
119
|
+
.map((item) => {
|
|
120
|
+
const vector = getVector(item);
|
|
121
|
+
if (!vector) {
|
|
122
|
+
return { item, score: 0 };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
let score: number;
|
|
126
|
+
if (typeof query === 'string' && typeof vector === 'string') {
|
|
127
|
+
score = textSimilarity(query, vector);
|
|
128
|
+
} else if (Array.isArray(query) && Array.isArray(vector)) {
|
|
129
|
+
score = cosineSimilarity(query, vector);
|
|
130
|
+
} else {
|
|
131
|
+
score = 0;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return { item, score };
|
|
135
|
+
})
|
|
136
|
+
.sort((a, b) => b.score - a.score);
|
|
137
|
+
|
|
138
|
+
return scored.slice(0, k);
|
|
139
|
+
}
|