skill-tree 0.1.0 → 0.1.2
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/chunk-3SRB47JW.mjs +8344 -0
- package/dist/chunk-43YOKLZP.mjs +6081 -0
- package/dist/chunk-4AGZU52D.mjs +7918 -0
- package/dist/chunk-4OC5QFIF.mjs +11267 -0
- package/dist/chunk-55SMGVTP.mjs +7126 -0
- package/dist/chunk-6FX4IK4Z.mjs +5368 -0
- package/dist/chunk-7EGDKOHV.mjs +9439 -0
- package/dist/chunk-7LMOQW5H.mjs +4893 -0
- package/dist/chunk-7VB4ZRZO.mjs +7127 -0
- package/dist/chunk-BPVRW25O.mjs +6089 -0
- package/dist/chunk-CI4476KM.mjs +6607 -0
- package/dist/chunk-DDXYQ74I.mjs +13969 -0
- package/dist/chunk-DQOFJXBX.mjs +6595 -0
- package/dist/chunk-E2CVK23F.mjs +8751 -0
- package/dist/chunk-II7DECZQ.mjs +9111 -0
- package/dist/{chunk-5QGJJCVX.mjs → chunk-INKVOZXK.mjs} +506 -0
- package/dist/chunk-K6NRCSAZ.mjs +4355 -0
- package/dist/chunk-ZQVS7MQK.mjs +6081 -0
- package/dist/cli/index.mjs +1 -1
- package/dist/index.d.mts +326 -1
- package/dist/index.d.ts +326 -1
- package/dist/index.js +509 -0
- package/dist/index.mjs +7 -1
- package/package.json +7 -3
package/dist/index.js
CHANGED
|
@@ -42,6 +42,7 @@ __export(index_exports, {
|
|
|
42
42
|
BaseStorageAdapter: () => BaseStorageAdapter,
|
|
43
43
|
BatchProcessor: () => BatchProcessor,
|
|
44
44
|
ClaudeCodeAdapter: () => ClaudeCodeAdapter,
|
|
45
|
+
CognitiveCoreProvider: () => CognitiveCoreProvider,
|
|
45
46
|
ConflictStore: () => ConflictStore,
|
|
46
47
|
DEFAULT_ACTIVATION_CONFIG: () => DEFAULT_ACTIVATION_CONFIG,
|
|
47
48
|
DEFAULT_AGENTS_CONFIG: () => DEFAULT_AGENTS_CONFIG,
|
|
@@ -93,7 +94,9 @@ __export(index_exports, {
|
|
|
93
94
|
createAgentsParser: () => createAgentsParser,
|
|
94
95
|
createAgentsSync: () => createAgentsSync,
|
|
95
96
|
createBackupHook: () => createBackupHook,
|
|
97
|
+
createCognitiveCoreProvider: () => createCognitiveCoreProvider,
|
|
96
98
|
createConflictStore: () => createConflictStore,
|
|
99
|
+
createDefaultCognitiveCoreFactory: () => createDefaultCognitiveCoreFactory,
|
|
97
100
|
createDefaultSyncConfig: () => createDefaultSyncConfig,
|
|
98
101
|
createExtractionEnrichmentHook: () => createExtractionEnrichmentHook,
|
|
99
102
|
createExtractionValidationHook: () => createExtractionValidationHook,
|
|
@@ -13907,6 +13910,509 @@ function conditionalHook(filter, handler) {
|
|
|
13907
13910
|
};
|
|
13908
13911
|
}
|
|
13909
13912
|
|
|
13913
|
+
// src/learning/providers/cognitive-core.ts
|
|
13914
|
+
var CognitiveCoreProvider = class {
|
|
13915
|
+
constructor(options) {
|
|
13916
|
+
this.name = "cognitive-core";
|
|
13917
|
+
this.description = "Advanced learning using cognitive-core with batch extraction and feedback";
|
|
13918
|
+
this.capabilities = {
|
|
13919
|
+
accumulating: true,
|
|
13920
|
+
feedbackEnabled: true,
|
|
13921
|
+
persistent: true,
|
|
13922
|
+
minTrajectories: 5,
|
|
13923
|
+
supportedKinds: ["skill", "strategy", "pattern", "error-fix"]
|
|
13924
|
+
};
|
|
13925
|
+
this.initialized = false;
|
|
13926
|
+
// ID mapping: playbook.id <-> candidate.id
|
|
13927
|
+
// For cognitive-core, we use playbook.id as the candidate.id directly
|
|
13928
|
+
this.playbookIdCache = /* @__PURE__ */ new Map();
|
|
13929
|
+
this.factory = options.factory;
|
|
13930
|
+
this.config = {
|
|
13931
|
+
storagePath: options.storagePath ?? "./.cognitive-core",
|
|
13932
|
+
minTrajectories: options.minTrajectories ?? 5,
|
|
13933
|
+
deduplicationThreshold: options.deduplicationThreshold ?? 0.85,
|
|
13934
|
+
creditStrategy: options.creditStrategy ?? "simple",
|
|
13935
|
+
convertToReAct: options.convertToReAct ?? true
|
|
13936
|
+
};
|
|
13937
|
+
this.memory = this.factory.createMemorySystem(this.config.storagePath);
|
|
13938
|
+
this.pipeline = this.factory.createLearningPipeline(this.memory, {
|
|
13939
|
+
creditStrategy: this.config.creditStrategy,
|
|
13940
|
+
minTrajectories: this.config.minTrajectories,
|
|
13941
|
+
deduplicationThreshold: this.config.deduplicationThreshold
|
|
13942
|
+
});
|
|
13943
|
+
}
|
|
13944
|
+
/**
|
|
13945
|
+
* Initialize the provider (load persisted state)
|
|
13946
|
+
*/
|
|
13947
|
+
async initialize() {
|
|
13948
|
+
if (this.initialized) return;
|
|
13949
|
+
await this.memory.init();
|
|
13950
|
+
this.initialized = true;
|
|
13951
|
+
}
|
|
13952
|
+
/**
|
|
13953
|
+
* Shutdown cleanly (persist state, release resources)
|
|
13954
|
+
*/
|
|
13955
|
+
async shutdown() {
|
|
13956
|
+
await this.memory.close();
|
|
13957
|
+
this.initialized = false;
|
|
13958
|
+
}
|
|
13959
|
+
/**
|
|
13960
|
+
* Analyze a trajectory and accumulate for batch learning.
|
|
13961
|
+
* Returns empty candidates until flush() or batch threshold.
|
|
13962
|
+
*/
|
|
13963
|
+
async analyze(trajectory, options) {
|
|
13964
|
+
await this.initialize();
|
|
13965
|
+
const startTime = Date.now();
|
|
13966
|
+
const ccTrajectory = this.convertTrajectory(trajectory, options);
|
|
13967
|
+
await this.pipeline.processTrajectory(ccTrajectory);
|
|
13968
|
+
let candidates = [];
|
|
13969
|
+
let updates = [];
|
|
13970
|
+
let demotions = [];
|
|
13971
|
+
let antiPatterns = [];
|
|
13972
|
+
if (options?.forceImmediate || this.pipeline.shouldRunBatch()) {
|
|
13973
|
+
const batchResult = await this.runBatchExtraction(options);
|
|
13974
|
+
candidates = batchResult.candidates;
|
|
13975
|
+
updates = batchResult.updates ?? [];
|
|
13976
|
+
demotions = batchResult.demotions ?? [];
|
|
13977
|
+
antiPatterns = batchResult.antiPatterns ?? [];
|
|
13978
|
+
}
|
|
13979
|
+
return {
|
|
13980
|
+
candidates,
|
|
13981
|
+
updates: updates.length > 0 ? updates : void 0,
|
|
13982
|
+
demotions: demotions.length > 0 ? demotions : void 0,
|
|
13983
|
+
antiPatterns: antiPatterns.length > 0 ? antiPatterns : void 0,
|
|
13984
|
+
providerState: {
|
|
13985
|
+
pendingCount: this.pipeline.getAccumulatedCount(),
|
|
13986
|
+
readyForFlush: this.pipeline.shouldRunBatch()
|
|
13987
|
+
},
|
|
13988
|
+
metadata: {
|
|
13989
|
+
trajectoriesAnalyzed: 1,
|
|
13990
|
+
durationMs: Date.now() - startTime
|
|
13991
|
+
}
|
|
13992
|
+
};
|
|
13993
|
+
}
|
|
13994
|
+
/**
|
|
13995
|
+
* Analyze multiple trajectories together.
|
|
13996
|
+
* Enables better cross-trajectory pattern detection.
|
|
13997
|
+
*/
|
|
13998
|
+
async analyzeBatch(trajectories, options) {
|
|
13999
|
+
await this.initialize();
|
|
14000
|
+
const startTime = Date.now();
|
|
14001
|
+
for (const trajectory of trajectories) {
|
|
14002
|
+
const ccTrajectory = this.convertTrajectory(trajectory, options);
|
|
14003
|
+
await this.pipeline.processTrajectory(ccTrajectory);
|
|
14004
|
+
}
|
|
14005
|
+
const batchResult = await this.runBatchExtraction(options);
|
|
14006
|
+
return {
|
|
14007
|
+
candidates: batchResult.candidates,
|
|
14008
|
+
updates: batchResult.updates,
|
|
14009
|
+
demotions: batchResult.demotions,
|
|
14010
|
+
antiPatterns: batchResult.antiPatterns,
|
|
14011
|
+
providerState: {
|
|
14012
|
+
pendingCount: this.pipeline.getAccumulatedCount(),
|
|
14013
|
+
readyForFlush: this.pipeline.shouldRunBatch()
|
|
14014
|
+
},
|
|
14015
|
+
metadata: {
|
|
14016
|
+
trajectoriesAnalyzed: trajectories.length,
|
|
14017
|
+
durationMs: Date.now() - startTime
|
|
14018
|
+
}
|
|
14019
|
+
};
|
|
14020
|
+
}
|
|
14021
|
+
/**
|
|
14022
|
+
* Force extraction from accumulated trajectories.
|
|
14023
|
+
*/
|
|
14024
|
+
async flush(options) {
|
|
14025
|
+
await this.initialize();
|
|
14026
|
+
const startTime = Date.now();
|
|
14027
|
+
const pendingCount = this.pipeline.getAccumulatedCount();
|
|
14028
|
+
const batchResult = await this.runBatchExtraction(options);
|
|
14029
|
+
return {
|
|
14030
|
+
...batchResult,
|
|
14031
|
+
metadata: {
|
|
14032
|
+
trajectoriesAnalyzed: pendingCount,
|
|
14033
|
+
durationMs: Date.now() - startTime
|
|
14034
|
+
}
|
|
14035
|
+
};
|
|
14036
|
+
}
|
|
14037
|
+
/**
|
|
14038
|
+
* Record outcome when a candidate/playbook is applied.
|
|
14039
|
+
* Updates playbook confidence and may generate refinements.
|
|
14040
|
+
*/
|
|
14041
|
+
async recordOutcome(feedback) {
|
|
14042
|
+
await this.initialize();
|
|
14043
|
+
const playbookId = feedback.candidateId;
|
|
14044
|
+
const playbook = await this.memory.playbooks.get(playbookId);
|
|
14045
|
+
if (!playbook) {
|
|
14046
|
+
return { recorded: false };
|
|
14047
|
+
}
|
|
14048
|
+
await this.memory.recordPlaybookUsage(
|
|
14049
|
+
playbookId,
|
|
14050
|
+
feedback.trajectoryId,
|
|
14051
|
+
feedback.success,
|
|
14052
|
+
feedback.context,
|
|
14053
|
+
feedback.failureMode
|
|
14054
|
+
);
|
|
14055
|
+
const updates = [];
|
|
14056
|
+
const antiPatterns = [];
|
|
14057
|
+
if (feedback.success) {
|
|
14058
|
+
updates.push({
|
|
14059
|
+
candidateId: playbookId,
|
|
14060
|
+
incrementSuccess: true,
|
|
14061
|
+
confidenceAdjustment: 0.05
|
|
14062
|
+
// Slight boost on success
|
|
14063
|
+
});
|
|
14064
|
+
} else {
|
|
14065
|
+
updates.push({
|
|
14066
|
+
candidateId: playbookId,
|
|
14067
|
+
incrementFailure: true,
|
|
14068
|
+
confidenceAdjustment: -0.1
|
|
14069
|
+
// Decrease confidence on failure
|
|
14070
|
+
});
|
|
14071
|
+
if (feedback.context || feedback.failureMode) {
|
|
14072
|
+
antiPatterns.push({
|
|
14073
|
+
id: `anti-${playbookId}-${Date.now()}`,
|
|
14074
|
+
candidateId: playbookId,
|
|
14075
|
+
pattern: feedback.context ?? "Unknown context",
|
|
14076
|
+
reason: feedback.failureMode ?? "Unknown failure mode",
|
|
14077
|
+
discoveredFrom: feedback.trajectoryId,
|
|
14078
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
14079
|
+
});
|
|
14080
|
+
}
|
|
14081
|
+
}
|
|
14082
|
+
return {
|
|
14083
|
+
recorded: true,
|
|
14084
|
+
updates: updates.length > 0 ? updates : void 0,
|
|
14085
|
+
antiPatterns: antiPatterns.length > 0 ? antiPatterns : void 0
|
|
14086
|
+
};
|
|
14087
|
+
}
|
|
14088
|
+
/**
|
|
14089
|
+
* Check if a candidate is a duplicate based on playbook similarity
|
|
14090
|
+
*/
|
|
14091
|
+
isDuplicate(candidate, existing) {
|
|
14092
|
+
if (existing.some((e) => e.id === candidate.id)) {
|
|
14093
|
+
return true;
|
|
14094
|
+
}
|
|
14095
|
+
for (const e of existing) {
|
|
14096
|
+
const similarity = this.computeSimilarity(candidate, e);
|
|
14097
|
+
if (similarity > this.config.deduplicationThreshold) {
|
|
14098
|
+
return true;
|
|
14099
|
+
}
|
|
14100
|
+
}
|
|
14101
|
+
return false;
|
|
14102
|
+
}
|
|
14103
|
+
/**
|
|
14104
|
+
* Compute similarity between two candidates
|
|
14105
|
+
*/
|
|
14106
|
+
computeSimilarity(a, b) {
|
|
14107
|
+
if (a.kind !== b.kind) return 0.1;
|
|
14108
|
+
const nameA = this.tokenize(a.name);
|
|
14109
|
+
const nameB = this.tokenize(b.name);
|
|
14110
|
+
const nameSimilarity = this.jaccardSimilarity(nameA, nameB);
|
|
14111
|
+
let contentSimilarity = 0;
|
|
14112
|
+
if (a.content.kind === "skill" && b.content.kind === "skill") {
|
|
14113
|
+
const aWords = this.tokenize(a.content.problem + " " + a.content.solution);
|
|
14114
|
+
const bWords = this.tokenize(b.content.problem + " " + b.content.solution);
|
|
14115
|
+
contentSimilarity = this.jaccardSimilarity(aWords, bWords);
|
|
14116
|
+
}
|
|
14117
|
+
return nameSimilarity * 0.3 + contentSimilarity * 0.7;
|
|
14118
|
+
}
|
|
14119
|
+
// ==========================================================================
|
|
14120
|
+
// Private Methods
|
|
14121
|
+
// ==========================================================================
|
|
14122
|
+
/**
|
|
14123
|
+
* Run batch extraction and convert results to LearningCandidates
|
|
14124
|
+
*/
|
|
14125
|
+
async runBatchExtraction(options) {
|
|
14126
|
+
await this.pipeline.runBatchLearning();
|
|
14127
|
+
const allPlaybooks = await this.memory.playbooks.getAll();
|
|
14128
|
+
const candidates = [];
|
|
14129
|
+
const updates = [];
|
|
14130
|
+
const demotions = [];
|
|
14131
|
+
const antiPatterns = [];
|
|
14132
|
+
const minConfidence = options?.minConfidence ?? 0;
|
|
14133
|
+
const requestedKinds = options?.kinds;
|
|
14134
|
+
for (const playbook of allPlaybooks) {
|
|
14135
|
+
if (!this.playbookIdCache.has(playbook.id)) {
|
|
14136
|
+
const candidate = this.playbookToCandidate(playbook);
|
|
14137
|
+
if (candidate.confidence < minConfidence) {
|
|
14138
|
+
continue;
|
|
14139
|
+
}
|
|
14140
|
+
if (requestedKinds && !requestedKinds.includes(candidate.kind)) {
|
|
14141
|
+
continue;
|
|
14142
|
+
}
|
|
14143
|
+
candidates.push(candidate);
|
|
14144
|
+
this.playbookIdCache.set(playbook.id, true);
|
|
14145
|
+
}
|
|
14146
|
+
const successRate = playbook.evolution.successCount + playbook.evolution.failureCount > 0 ? playbook.evolution.successCount / (playbook.evolution.successCount + playbook.evolution.failureCount) : 1;
|
|
14147
|
+
if (successRate < 0.3 && playbook.evolution.successCount + playbook.evolution.failureCount >= 3) {
|
|
14148
|
+
demotions.push({
|
|
14149
|
+
candidateId: playbook.id,
|
|
14150
|
+
reason: `Low success rate: ${Math.round(successRate * 100)}%`,
|
|
14151
|
+
newConfidence: successRate,
|
|
14152
|
+
deprecate: successRate < 0.1
|
|
14153
|
+
});
|
|
14154
|
+
}
|
|
14155
|
+
for (const antiPattern of playbook.applicability.antiPatterns) {
|
|
14156
|
+
antiPatterns.push({
|
|
14157
|
+
id: `anti-${playbook.id}-${antiPattern.slice(0, 10)}`,
|
|
14158
|
+
candidateId: playbook.id,
|
|
14159
|
+
pattern: antiPattern,
|
|
14160
|
+
reason: "Learned from playbook applicability",
|
|
14161
|
+
discoveredFrom: playbook.evolution.createdFrom[0] ?? "unknown",
|
|
14162
|
+
createdAt: playbook.createdAt
|
|
14163
|
+
});
|
|
14164
|
+
}
|
|
14165
|
+
}
|
|
14166
|
+
return {
|
|
14167
|
+
candidates,
|
|
14168
|
+
updates: updates.length > 0 ? updates : void 0,
|
|
14169
|
+
demotions: demotions.length > 0 ? demotions : void 0,
|
|
14170
|
+
antiPatterns: antiPatterns.length > 0 ? antiPatterns : void 0,
|
|
14171
|
+
providerState: {
|
|
14172
|
+
pendingCount: this.pipeline.getAccumulatedCount(),
|
|
14173
|
+
readyForFlush: this.pipeline.shouldRunBatch()
|
|
14174
|
+
}
|
|
14175
|
+
};
|
|
14176
|
+
}
|
|
14177
|
+
/**
|
|
14178
|
+
* Convert a skill-tree Trajectory to cognitive-core Trajectory format
|
|
14179
|
+
*/
|
|
14180
|
+
convertTrajectory(trajectory, options) {
|
|
14181
|
+
const firstUserTurn = trajectory.turns.find((t) => t.role === "user");
|
|
14182
|
+
let taskDescription = firstUserTurn?.content ?? "Unknown task";
|
|
14183
|
+
if (options?.context) {
|
|
14184
|
+
taskDescription = `${taskDescription}
|
|
14185
|
+
|
|
14186
|
+
Context: ${options.context}`;
|
|
14187
|
+
}
|
|
14188
|
+
const task = this.factory.createTask({
|
|
14189
|
+
id: trajectory.sessionId,
|
|
14190
|
+
domain: trajectory.metadata.projectName ?? "general",
|
|
14191
|
+
description: taskDescription,
|
|
14192
|
+
context: trajectory.metadata.custom ?? {}
|
|
14193
|
+
});
|
|
14194
|
+
const [startTurn, endTurn] = options?.turnRange ?? [0, trajectory.turns.length - 1];
|
|
14195
|
+
const turnsToProcess = trajectory.turns.slice(startTurn, endTurn + 1);
|
|
14196
|
+
const steps = [];
|
|
14197
|
+
if (this.config.convertToReAct) {
|
|
14198
|
+
for (let i = 0; i < turnsToProcess.length; i++) {
|
|
14199
|
+
const turn = turnsToProcess[i];
|
|
14200
|
+
if (turn.role === "assistant") {
|
|
14201
|
+
const step = this.turnToStep(turn, turnsToProcess, i);
|
|
14202
|
+
if (step) {
|
|
14203
|
+
steps.push(step);
|
|
14204
|
+
}
|
|
14205
|
+
}
|
|
14206
|
+
}
|
|
14207
|
+
}
|
|
14208
|
+
const outcome = {
|
|
14209
|
+
success: trajectory.outcome?.success ?? false,
|
|
14210
|
+
partialScore: trajectory.outcome?.success ? 1 : 0,
|
|
14211
|
+
solution: trajectory.outcome?.summary ?? "",
|
|
14212
|
+
errorInfo: trajectory.outcome?.errors?.join("; ")
|
|
14213
|
+
};
|
|
14214
|
+
return this.factory.createTrajectory({
|
|
14215
|
+
id: trajectory.sessionId,
|
|
14216
|
+
task,
|
|
14217
|
+
steps,
|
|
14218
|
+
outcome,
|
|
14219
|
+
agentId: trajectory.metadata.agentType ?? "skill-tree",
|
|
14220
|
+
metadata: trajectory.metadata.custom ?? {}
|
|
14221
|
+
});
|
|
14222
|
+
}
|
|
14223
|
+
/**
|
|
14224
|
+
* Convert an assistant turn to a cognitive-core Step
|
|
14225
|
+
*/
|
|
14226
|
+
turnToStep(turn, allTurns, turnIndex) {
|
|
14227
|
+
let observation = "";
|
|
14228
|
+
const nextTurn = allTurns[turnIndex + 1];
|
|
14229
|
+
if (nextTurn?.role === "tool" && nextTurn.toolResults?.length) {
|
|
14230
|
+
observation = nextTurn.toolResults.map((r) => r.output).join("\n");
|
|
14231
|
+
} else if (nextTurn?.role === "user") {
|
|
14232
|
+
observation = nextTurn.content.slice(0, 500);
|
|
14233
|
+
}
|
|
14234
|
+
let action = "";
|
|
14235
|
+
if (turn.toolCalls?.length) {
|
|
14236
|
+
action = turn.toolCalls.map((tc) => `${tc.name}(${JSON.stringify(tc.input).slice(0, 200)})`).join("; ");
|
|
14237
|
+
} else {
|
|
14238
|
+
action = turn.content.slice(0, 300);
|
|
14239
|
+
}
|
|
14240
|
+
const thought = turn.toolCalls?.length ? turn.content.slice(0, 500) : void 0;
|
|
14241
|
+
return this.factory.createStep({
|
|
14242
|
+
thought,
|
|
14243
|
+
action,
|
|
14244
|
+
observation
|
|
14245
|
+
});
|
|
14246
|
+
}
|
|
14247
|
+
/**
|
|
14248
|
+
* Convert a cognitive-core Playbook to a LearningCandidate
|
|
14249
|
+
*/
|
|
14250
|
+
playbookToCandidate(playbook) {
|
|
14251
|
+
const kind = this.inferKind(playbook);
|
|
14252
|
+
const content = this.createContentForKind(kind, playbook);
|
|
14253
|
+
const attribution = playbook.evolution.createdFrom.map(
|
|
14254
|
+
(trajectoryId, i) => ({
|
|
14255
|
+
turnIndex: i,
|
|
14256
|
+
score: 1 / Math.max(1, playbook.evolution.createdFrom.length),
|
|
14257
|
+
reasoning: `Derived from trajectory ${trajectoryId}`
|
|
14258
|
+
})
|
|
14259
|
+
);
|
|
14260
|
+
return {
|
|
14261
|
+
kind,
|
|
14262
|
+
id: playbook.id,
|
|
14263
|
+
name: playbook.name,
|
|
14264
|
+
content,
|
|
14265
|
+
confidence: playbook.confidence,
|
|
14266
|
+
attribution,
|
|
14267
|
+
source: {
|
|
14268
|
+
provider: this.name,
|
|
14269
|
+
trajectoryId: playbook.evolution.createdFrom[0] ?? "unknown",
|
|
14270
|
+
turnRange: [0, 0],
|
|
14271
|
+
// Playbooks don't track specific turn ranges
|
|
14272
|
+
extractedAt: playbook.createdAt,
|
|
14273
|
+
metadata: {
|
|
14274
|
+
version: playbook.evolution.version,
|
|
14275
|
+
successCount: playbook.evolution.successCount,
|
|
14276
|
+
failureCount: playbook.evolution.failureCount,
|
|
14277
|
+
complexity: playbook.complexity
|
|
14278
|
+
}
|
|
14279
|
+
},
|
|
14280
|
+
embedding: playbook.embedding,
|
|
14281
|
+
// Pass through embedding if present
|
|
14282
|
+
tags: playbook.applicability.domains,
|
|
14283
|
+
reasoning: playbook.guidance.strategy
|
|
14284
|
+
};
|
|
14285
|
+
}
|
|
14286
|
+
/**
|
|
14287
|
+
* Create appropriate content type for the inferred kind
|
|
14288
|
+
*/
|
|
14289
|
+
createContentForKind(kind, playbook) {
|
|
14290
|
+
switch (kind) {
|
|
14291
|
+
case "strategy":
|
|
14292
|
+
return {
|
|
14293
|
+
kind: "strategy",
|
|
14294
|
+
situation: playbook.applicability.situations.join(". "),
|
|
14295
|
+
suggestion: playbook.guidance.strategy,
|
|
14296
|
+
parameters: playbook.guidance.codeExample ? { example: playbook.guidance.codeExample } : void 0
|
|
14297
|
+
};
|
|
14298
|
+
case "pattern":
|
|
14299
|
+
return {
|
|
14300
|
+
kind: "pattern",
|
|
14301
|
+
pattern: playbook.applicability.triggers[0] ?? playbook.name,
|
|
14302
|
+
description: playbook.guidance.strategy,
|
|
14303
|
+
examples: playbook.applicability.situations
|
|
14304
|
+
};
|
|
14305
|
+
case "error-fix":
|
|
14306
|
+
return {
|
|
14307
|
+
kind: "error-fix",
|
|
14308
|
+
errorPattern: playbook.applicability.triggers.join(" | "),
|
|
14309
|
+
fix: playbook.guidance.strategy + (playbook.guidance.steps?.length ? "\n\nSteps:\n" + playbook.guidance.steps.map((s, i) => `${i + 1}. ${s}`).join("\n") : ""),
|
|
14310
|
+
frequency: playbook.evolution.successCount + playbook.evolution.failureCount,
|
|
14311
|
+
errorExamples: playbook.applicability.triggers
|
|
14312
|
+
};
|
|
14313
|
+
case "skill":
|
|
14314
|
+
default:
|
|
14315
|
+
return {
|
|
14316
|
+
kind: "skill",
|
|
14317
|
+
problem: playbook.applicability.situations.join(". "),
|
|
14318
|
+
solution: playbook.guidance.strategy + (playbook.guidance.steps?.length ? "\n\nSteps:\n" + playbook.guidance.steps.map((s, i) => `${i + 1}. ${s}`).join("\n") : ""),
|
|
14319
|
+
verification: playbook.verification.successIndicators.join(". "),
|
|
14320
|
+
triggers: this.extractTriggers(playbook),
|
|
14321
|
+
examples: []
|
|
14322
|
+
// Playbooks don't have direct examples
|
|
14323
|
+
};
|
|
14324
|
+
}
|
|
14325
|
+
}
|
|
14326
|
+
/**
|
|
14327
|
+
* Infer the kind of learning from a playbook
|
|
14328
|
+
*/
|
|
14329
|
+
inferKind(playbook) {
|
|
14330
|
+
const hasErrorTriggers = playbook.applicability.triggers.some(
|
|
14331
|
+
(t) => t.toLowerCase().includes("error") || /^[A-Z]{2,}\d+/.test(t)
|
|
14332
|
+
);
|
|
14333
|
+
if (hasErrorTriggers) {
|
|
14334
|
+
return "error-fix";
|
|
14335
|
+
}
|
|
14336
|
+
const strategy = playbook.guidance.strategy.toLowerCase();
|
|
14337
|
+
if (strategy.includes("approach") || strategy.includes("strategy") || strategy.includes("when you see")) {
|
|
14338
|
+
return "strategy";
|
|
14339
|
+
}
|
|
14340
|
+
if (playbook.applicability.situations.some((s) => s.includes("pattern"))) {
|
|
14341
|
+
return "pattern";
|
|
14342
|
+
}
|
|
14343
|
+
return "skill";
|
|
14344
|
+
}
|
|
14345
|
+
/**
|
|
14346
|
+
* Extract triggers from playbook applicability
|
|
14347
|
+
*/
|
|
14348
|
+
extractTriggers(playbook) {
|
|
14349
|
+
const triggers = [];
|
|
14350
|
+
for (const situation of playbook.applicability.situations) {
|
|
14351
|
+
triggers.push({
|
|
14352
|
+
type: "context",
|
|
14353
|
+
value: situation,
|
|
14354
|
+
description: "Situation trigger"
|
|
14355
|
+
});
|
|
14356
|
+
}
|
|
14357
|
+
for (const trigger of playbook.applicability.triggers) {
|
|
14358
|
+
let type = "keyword";
|
|
14359
|
+
if (trigger.toLowerCase().includes("error") || /^[A-Z]{2,}\d+/.test(trigger)) {
|
|
14360
|
+
type = "error";
|
|
14361
|
+
} else if (trigger.startsWith("/") || trigger.includes("*")) {
|
|
14362
|
+
type = "pattern";
|
|
14363
|
+
}
|
|
14364
|
+
triggers.push({
|
|
14365
|
+
type,
|
|
14366
|
+
value: trigger,
|
|
14367
|
+
description: "Explicit trigger"
|
|
14368
|
+
});
|
|
14369
|
+
}
|
|
14370
|
+
return triggers;
|
|
14371
|
+
}
|
|
14372
|
+
/**
|
|
14373
|
+
* Tokenize text into words
|
|
14374
|
+
*/
|
|
14375
|
+
tokenize(text) {
|
|
14376
|
+
return text.toLowerCase().split(/\W+/).filter((w) => w.length > 2);
|
|
14377
|
+
}
|
|
14378
|
+
/**
|
|
14379
|
+
* Compute Jaccard similarity between two arrays
|
|
14380
|
+
*/
|
|
14381
|
+
jaccardSimilarity(a, b) {
|
|
14382
|
+
const setA = new Set(a);
|
|
14383
|
+
const setB = new Set(b);
|
|
14384
|
+
const intersection = new Set([...setA].filter((x) => setB.has(x)));
|
|
14385
|
+
const union = /* @__PURE__ */ new Set([...setA, ...setB]);
|
|
14386
|
+
return union.size === 0 ? 0 : intersection.size / union.size;
|
|
14387
|
+
}
|
|
14388
|
+
};
|
|
14389
|
+
function createCognitiveCoreProvider(options) {
|
|
14390
|
+
return new CognitiveCoreProvider(options);
|
|
14391
|
+
}
|
|
14392
|
+
async function createDefaultCognitiveCoreFactory() {
|
|
14393
|
+
const cc = await import("cognitive-core");
|
|
14394
|
+
return {
|
|
14395
|
+
createMemorySystem(storagePath) {
|
|
14396
|
+
return cc.createMemorySystem(storagePath);
|
|
14397
|
+
},
|
|
14398
|
+
createLearningPipeline(memory, config) {
|
|
14399
|
+
return cc.createLearningPipeline(
|
|
14400
|
+
memory,
|
|
14401
|
+
config
|
|
14402
|
+
);
|
|
14403
|
+
},
|
|
14404
|
+
createTrajectory(params) {
|
|
14405
|
+
return cc.createTrajectory(params);
|
|
14406
|
+
},
|
|
14407
|
+
createTask(params) {
|
|
14408
|
+
return cc.createTask(params);
|
|
14409
|
+
},
|
|
14410
|
+
createStep(params) {
|
|
14411
|
+
return cc.createStep(params);
|
|
14412
|
+
}
|
|
14413
|
+
};
|
|
14414
|
+
}
|
|
14415
|
+
|
|
13910
14416
|
// src/sync/git-sync-adapter.ts
|
|
13911
14417
|
var fs8 = __toESM(require("fs"));
|
|
13912
14418
|
var path8 = __toESM(require("path"));
|
|
@@ -15436,6 +15942,7 @@ var VERSION = "0.1.0";
|
|
|
15436
15942
|
BaseStorageAdapter,
|
|
15437
15943
|
BatchProcessor,
|
|
15438
15944
|
ClaudeCodeAdapter,
|
|
15945
|
+
CognitiveCoreProvider,
|
|
15439
15946
|
ConflictStore,
|
|
15440
15947
|
DEFAULT_ACTIVATION_CONFIG,
|
|
15441
15948
|
DEFAULT_AGENTS_CONFIG,
|
|
@@ -15487,7 +15994,9 @@ var VERSION = "0.1.0";
|
|
|
15487
15994
|
createAgentsParser,
|
|
15488
15995
|
createAgentsSync,
|
|
15489
15996
|
createBackupHook,
|
|
15997
|
+
createCognitiveCoreProvider,
|
|
15490
15998
|
createConflictStore,
|
|
15999
|
+
createDefaultCognitiveCoreFactory,
|
|
15491
16000
|
createDefaultSyncConfig,
|
|
15492
16001
|
createExtractionEnrichmentHook,
|
|
15493
16002
|
createExtractionValidationHook,
|
package/dist/index.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
BaseStorageAdapter,
|
|
12
12
|
BatchProcessor,
|
|
13
13
|
ClaudeCodeAdapter,
|
|
14
|
+
CognitiveCoreProvider,
|
|
14
15
|
ConflictStore,
|
|
15
16
|
DEFAULT_ACTIVATION_CONFIG,
|
|
16
17
|
DEFAULT_AGENTS_CONFIG,
|
|
@@ -62,7 +63,9 @@ import {
|
|
|
62
63
|
createAgentsParser,
|
|
63
64
|
createAgentsSync,
|
|
64
65
|
createBackupHook,
|
|
66
|
+
createCognitiveCoreProvider,
|
|
65
67
|
createConflictStore,
|
|
68
|
+
createDefaultCognitiveCoreFactory,
|
|
66
69
|
createDefaultSyncConfig,
|
|
67
70
|
createExtractionEnrichmentHook,
|
|
68
71
|
createExtractionValidationHook,
|
|
@@ -120,7 +123,7 @@ import {
|
|
|
120
123
|
sortVersions,
|
|
121
124
|
testingProfile,
|
|
122
125
|
writeAgentsMd
|
|
123
|
-
} from "./chunk-
|
|
126
|
+
} from "./chunk-INKVOZXK.mjs";
|
|
124
127
|
export {
|
|
125
128
|
ActivationManager,
|
|
126
129
|
AdapterRegistry,
|
|
@@ -134,6 +137,7 @@ export {
|
|
|
134
137
|
BaseStorageAdapter,
|
|
135
138
|
BatchProcessor,
|
|
136
139
|
ClaudeCodeAdapter,
|
|
140
|
+
CognitiveCoreProvider,
|
|
137
141
|
ConflictStore,
|
|
138
142
|
DEFAULT_ACTIVATION_CONFIG,
|
|
139
143
|
DEFAULT_AGENTS_CONFIG,
|
|
@@ -185,7 +189,9 @@ export {
|
|
|
185
189
|
createAgentsParser,
|
|
186
190
|
createAgentsSync,
|
|
187
191
|
createBackupHook,
|
|
192
|
+
createCognitiveCoreProvider,
|
|
188
193
|
createConflictStore,
|
|
194
|
+
createDefaultCognitiveCoreFactory,
|
|
189
195
|
createDefaultSyncConfig,
|
|
190
196
|
createExtractionEnrichmentHook,
|
|
191
197
|
createExtractionValidationHook,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "skill-tree",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Library for managing agent skill versions and evolution - extract, iterate, and adapt skills from agent trajectories",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -27,7 +27,10 @@
|
|
|
27
27
|
"test:ui": "vitest --ui",
|
|
28
28
|
"test:coverage": "vitest run --coverage",
|
|
29
29
|
"test:legacy": "tsx test/run-all.ts",
|
|
30
|
-
"prepublishOnly": "npm run build"
|
|
30
|
+
"prepublishOnly": "npm run build",
|
|
31
|
+
"version:patch": "npm version patch && git push && git push --tags",
|
|
32
|
+
"version:minor": "npm version minor && git push && git push --tags",
|
|
33
|
+
"version:major": "npm version major && git push && git push --tags"
|
|
31
34
|
},
|
|
32
35
|
"keywords": [
|
|
33
36
|
"ai",
|
|
@@ -58,6 +61,7 @@
|
|
|
58
61
|
"better-sqlite3": "^12.6.2",
|
|
59
62
|
"chalk": "^5.6.2",
|
|
60
63
|
"commander": "^14.0.2",
|
|
61
|
-
"simple-git": "^3.30.0"
|
|
64
|
+
"simple-git": "^3.30.0",
|
|
65
|
+
"cognitive-core": "^0.1.1"
|
|
62
66
|
}
|
|
63
67
|
}
|