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