@galileodev/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/curator/curator.d.ts +18 -0
- package/dist/curator/curator.d.ts.map +1 -0
- package/dist/curator/curator.js +55 -0
- package/dist/curator/curator.js.map +1 -0
- package/dist/curator/deduplicator.d.ts +7 -0
- package/dist/curator/deduplicator.d.ts.map +1 -0
- package/dist/curator/deduplicator.js +32 -0
- package/dist/curator/deduplicator.js.map +1 -0
- package/dist/curator/merge-engine.d.ts +20 -0
- package/dist/curator/merge-engine.d.ts.map +1 -0
- package/dist/curator/merge-engine.js +84 -0
- package/dist/curator/merge-engine.js.map +1 -0
- package/dist/curator/scoring.d.ts +14 -0
- package/dist/curator/scoring.d.ts.map +1 -0
- package/dist/curator/scoring.js +26 -0
- package/dist/curator/scoring.js.map +1 -0
- package/dist/curator/types.d.ts +5 -0
- package/dist/curator/types.d.ts.map +1 -0
- package/dist/curator/types.js +2 -0
- package/dist/curator/types.js.map +1 -0
- package/dist/embeddings/cosine.d.ts +2 -0
- package/dist/embeddings/cosine.d.ts.map +1 -0
- package/dist/embeddings/cosine.js +20 -0
- package/dist/embeddings/cosine.js.map +1 -0
- package/dist/embeddings/onnx-provider.d.ts +6 -0
- package/dist/embeddings/onnx-provider.d.ts.map +1 -0
- package/dist/embeddings/onnx-provider.js +19 -0
- package/dist/embeddings/onnx-provider.js.map +1 -0
- package/dist/embeddings/types.d.ts +5 -0
- package/dist/embeddings/types.d.ts.map +1 -0
- package/dist/embeddings/types.js +2 -0
- package/dist/embeddings/types.js.map +1 -0
- package/dist/events/bus.d.ts +9 -0
- package/dist/events/bus.d.ts.map +1 -0
- package/dist/events/bus.js +15 -0
- package/dist/events/bus.js.map +1 -0
- package/dist/events/types.d.ts +6 -0
- package/dist/events/types.d.ts.map +1 -0
- package/dist/events/types.js +2 -0
- package/dist/events/types.js.map +1 -0
- package/dist/generator/generator.d.ts +17 -0
- package/dist/generator/generator.d.ts.map +1 -0
- package/dist/generator/generator.js +59 -0
- package/dist/generator/generator.js.map +1 -0
- package/dist/generator/types.d.ts +20 -0
- package/dist/generator/types.d.ts.map +1 -0
- package/dist/generator/types.js +2 -0
- package/dist/generator/types.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/llm/anthropic.d.ts +14 -0
- package/dist/llm/anthropic.d.ts.map +1 -0
- package/dist/llm/anthropic.js +41 -0
- package/dist/llm/anthropic.js.map +1 -0
- package/dist/llm/mock.d.ts +15 -0
- package/dist/llm/mock.d.ts.map +1 -0
- package/dist/llm/mock.js +24 -0
- package/dist/llm/mock.js.map +1 -0
- package/dist/llm/types.d.ts +15 -0
- package/dist/llm/types.d.ts.map +1 -0
- package/dist/llm/types.js +2 -0
- package/dist/llm/types.js.map +1 -0
- package/dist/pipeline/pipeline.d.ts +7 -0
- package/dist/pipeline/pipeline.d.ts.map +1 -0
- package/dist/pipeline/pipeline.js +57 -0
- package/dist/pipeline/pipeline.js.map +1 -0
- package/dist/pipeline/types.d.ts +28 -0
- package/dist/pipeline/types.d.ts.map +1 -0
- package/dist/pipeline/types.js +2 -0
- package/dist/pipeline/types.js.map +1 -0
- package/dist/playbook/filesystem.d.ts +20 -0
- package/dist/playbook/filesystem.d.ts.map +1 -0
- package/dist/playbook/filesystem.js +80 -0
- package/dist/playbook/filesystem.js.map +1 -0
- package/dist/playbook/markdown-compiler.d.ts +8 -0
- package/dist/playbook/markdown-compiler.d.ts.map +1 -0
- package/dist/playbook/markdown-compiler.js +49 -0
- package/dist/playbook/markdown-compiler.js.map +1 -0
- package/dist/playbook/reconciler.d.ts +10 -0
- package/dist/playbook/reconciler.d.ts.map +1 -0
- package/dist/playbook/reconciler.js +43 -0
- package/dist/playbook/reconciler.js.map +1 -0
- package/dist/playbook/store.d.ts +12 -0
- package/dist/playbook/store.d.ts.map +1 -0
- package/dist/playbook/store.js +2 -0
- package/dist/playbook/store.js.map +1 -0
- package/dist/playbook/types.d.ts +139 -0
- package/dist/playbook/types.d.ts.map +1 -0
- package/dist/playbook/types.js +23 -0
- package/dist/playbook/types.js.map +1 -0
- package/dist/primitives/execution-sandbox.d.ts +7 -0
- package/dist/primitives/execution-sandbox.d.ts.map +1 -0
- package/dist/primitives/execution-sandbox.js +87 -0
- package/dist/primitives/execution-sandbox.js.map +1 -0
- package/dist/primitives/ratchet-guard.d.ts +10 -0
- package/dist/primitives/ratchet-guard.d.ts.map +1 -0
- package/dist/primitives/ratchet-guard.js +44 -0
- package/dist/primitives/ratchet-guard.js.map +1 -0
- package/dist/primitives/token-budget.d.ts +10 -0
- package/dist/primitives/token-budget.d.ts.map +1 -0
- package/dist/primitives/token-budget.js +29 -0
- package/dist/primitives/token-budget.js.map +1 -0
- package/dist/primitives/types.d.ts +16 -0
- package/dist/primitives/types.d.ts.map +1 -0
- package/dist/primitives/types.js +2 -0
- package/dist/primitives/types.js.map +1 -0
- package/dist/reflector/reflector.d.ts +17 -0
- package/dist/reflector/reflector.d.ts.map +1 -0
- package/dist/reflector/reflector.js +46 -0
- package/dist/reflector/reflector.js.map +1 -0
- package/dist/reflector/types.d.ts +19 -0
- package/dist/reflector/types.d.ts.map +1 -0
- package/dist/reflector/types.js +2 -0
- package/dist/reflector/types.js.map +1 -0
- package/package.json +30 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { LLMProvider } from '../llm/types.js';
|
|
2
|
+
import type { PlaybookEntry, DeltaUpdate } from '../playbook/types.js';
|
|
3
|
+
import type { ReflectionResult } from '../reflector/types.js';
|
|
4
|
+
import type { CuratorConfig } from './types.js';
|
|
5
|
+
interface CuratorInput {
|
|
6
|
+
taskId: string;
|
|
7
|
+
reflection: ReflectionResult;
|
|
8
|
+
currentEntries: PlaybookEntry[];
|
|
9
|
+
}
|
|
10
|
+
export declare class Curator {
|
|
11
|
+
private readonly llm;
|
|
12
|
+
private readonly config;
|
|
13
|
+
constructor(llm: LLMProvider, config?: CuratorConfig);
|
|
14
|
+
run(input: CuratorInput): Promise<DeltaUpdate>;
|
|
15
|
+
private buildPrompt;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=curator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"curator.d.ts","sourceRoot":"","sources":["../../src/curator/curator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAahD,UAAU,YAAY;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,gBAAgB,CAAC;IAC7B,cAAc,EAAE,aAAa,EAAE,CAAC;CACjC;AAED,qBAAa,OAAO;IAEhB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,GAAG,EAAE,WAAW,EAChB,MAAM,GAAE,aAAkB;IAGvC,GAAG,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;IA0BpD,OAAO,CAAC,WAAW;CA6BpB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ulid } from 'ulid';
|
|
3
|
+
import { deduplicate } from './deduplicator.js';
|
|
4
|
+
const CurationResponseSchema = z.object({
|
|
5
|
+
scoredEntries: z.array(z.object({
|
|
6
|
+
content: z.string(),
|
|
7
|
+
utility: z.number().min(0).max(1),
|
|
8
|
+
harmfulness: z.number().min(0).max(1),
|
|
9
|
+
})),
|
|
10
|
+
});
|
|
11
|
+
export class Curator {
|
|
12
|
+
llm;
|
|
13
|
+
config;
|
|
14
|
+
constructor(llm, config = {}) {
|
|
15
|
+
this.llm = llm;
|
|
16
|
+
this.config = config;
|
|
17
|
+
}
|
|
18
|
+
async run(input) {
|
|
19
|
+
const prompt = this.buildPrompt(input);
|
|
20
|
+
const response = await this.llm.structured(prompt, CurationResponseSchema, {
|
|
21
|
+
model: this.config.model,
|
|
22
|
+
temperature: this.config.temperature,
|
|
23
|
+
});
|
|
24
|
+
const newEntries = response.scoredEntries.map((scored) => ({
|
|
25
|
+
id: ulid(),
|
|
26
|
+
timestamp: new Date().toISOString(),
|
|
27
|
+
source: 'curator',
|
|
28
|
+
kind: 'delta',
|
|
29
|
+
content: scored.content,
|
|
30
|
+
utility: scored.utility,
|
|
31
|
+
harmfulness: scored.harmfulness,
|
|
32
|
+
metadata: { taskId: input.taskId },
|
|
33
|
+
helpful: 0,
|
|
34
|
+
harmful: 0,
|
|
35
|
+
archived: false,
|
|
36
|
+
}));
|
|
37
|
+
const { kept, deprecations } = deduplicate(input.currentEntries, newEntries);
|
|
38
|
+
return { additions: kept, deprecations };
|
|
39
|
+
}
|
|
40
|
+
buildPrompt(input) {
|
|
41
|
+
const parts = [
|
|
42
|
+
'You are the Curator in an ACE (Agentic Context Engineering) pipeline.',
|
|
43
|
+
'Your role is to score lessons for utility and harmfulness, then produce compact delta updates.',
|
|
44
|
+
'',
|
|
45
|
+
'## Lessons from Reflector',
|
|
46
|
+
...input.reflection.lessons.map((l) => `- [${l.source}, confidence: ${l.confidence}] ${l.insight}`),
|
|
47
|
+
];
|
|
48
|
+
if (input.currentEntries.length > 0) {
|
|
49
|
+
parts.push('', '## Current Playbook Entries', ...input.currentEntries.map((e) => `- [${e.kind}] (utility: ${e.utility}) ${e.content}`));
|
|
50
|
+
}
|
|
51
|
+
parts.push('', 'For each lesson, produce a concise delta entry with utility score [0,1] and harmfulness score [0,1].', 'Merge similar insights. Drop low-value or harmful ones.');
|
|
52
|
+
return parts.join('\n');
|
|
53
|
+
}
|
|
54
|
+
}
|
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tG,yDAAyD,CAC1D,CAAC;QAEF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PlaybookEntry } from '../playbook/types.js';
|
|
2
|
+
export interface DeduplicationResult {
|
|
3
|
+
kept: PlaybookEntry[];
|
|
4
|
+
deprecations: string[];
|
|
5
|
+
}
|
|
6
|
+
export declare function deduplicate(existing: PlaybookEntry[], incoming: PlaybookEntry[]): DeduplicationResult;
|
|
7
|
+
//# sourceMappingURL=deduplicator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deduplicator.d.ts","sourceRoot":"","sources":["../../src/curator/deduplicator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,aAAa,EAAE,CAAC;IACtB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAMD,wBAAgB,WAAW,CACzB,QAAQ,EAAE,aAAa,EAAE,EACzB,QAAQ,EAAE,aAAa,EAAE,GACxB,mBAAmB,CA+BrB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
function normalize(content) {
|
|
2
|
+
return content.toLowerCase().trim().replace(/\s+/g, ' ');
|
|
3
|
+
}
|
|
4
|
+
export function deduplicate(existing, incoming) {
|
|
5
|
+
if (incoming.length === 0) {
|
|
6
|
+
return { kept: [], deprecations: [] };
|
|
7
|
+
}
|
|
8
|
+
const existingByContent = new Map();
|
|
9
|
+
for (const entry of existing) {
|
|
10
|
+
const key = normalize(entry.content);
|
|
11
|
+
const group = existingByContent.get(key) ?? [];
|
|
12
|
+
group.push(entry);
|
|
13
|
+
existingByContent.set(key, group);
|
|
14
|
+
}
|
|
15
|
+
const kept = [];
|
|
16
|
+
const deprecations = [];
|
|
17
|
+
for (const entry of incoming) {
|
|
18
|
+
const normalized = normalize(entry.content);
|
|
19
|
+
const matches = existingByContent.get(normalized);
|
|
20
|
+
if (matches && matches.length > 0) {
|
|
21
|
+
for (const match of matches) {
|
|
22
|
+
deprecations.push(match.id);
|
|
23
|
+
}
|
|
24
|
+
kept.push({ ...entry, supersedes: matches[matches.length - 1].id });
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
kept.push(entry);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return { kept, deprecations };
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=deduplicator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deduplicator.js","sourceRoot":"","sources":["../../src/curator/deduplicator.ts"],"names":[],"mappings":"AAOA,SAAS,SAAS,CAAC,OAAe;IAChC,OAAO,OAAO,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,WAAW,CACzB,QAAyB,EACzB,QAAyB;IAEzB,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC;IACxC,CAAC;IAED,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAA2B,CAAC;IAC7D,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;QAC7B,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrC,MAAM,KAAK,GAAG,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAC/C,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClB,iBAAiB,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,IAAI,GAAoB,EAAE,CAAC;IACjC,MAAM,YAAY,GAAa,EAAE,CAAC;IAElC,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;QAC7B,MAAM,UAAU,GAAG,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC5C,MAAM,OAAO,GAAG,iBAAiB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAElD,IAAI,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAClC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;gBAC5B,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC9B,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACtE,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PlaybookEntry } from '../playbook/types.js';
|
|
2
|
+
import type { EmbeddingProvider } from '../embeddings/types.js';
|
|
3
|
+
export interface MergeEngineConfig {
|
|
4
|
+
similarityThreshold: number;
|
|
5
|
+
maxEntriesPerSection: number;
|
|
6
|
+
lambda?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface MergeResult {
|
|
9
|
+
entries: PlaybookEntry[];
|
|
10
|
+
pruned: PlaybookEntry[];
|
|
11
|
+
merged: number;
|
|
12
|
+
added: number;
|
|
13
|
+
}
|
|
14
|
+
export declare class MergeEngine {
|
|
15
|
+
private readonly embeddings;
|
|
16
|
+
private readonly config;
|
|
17
|
+
constructor(embeddings: EmbeddingProvider, config: MergeEngineConfig);
|
|
18
|
+
merge(existing: PlaybookEntry[], deltas: PlaybookEntry[], outcome: 'success' | 'failure' | 'partial'): Promise<MergeResult>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=merge-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-engine.d.ts","sourceRoot":"","sources":["../../src/curator/merge-engine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAIhE,MAAM,WAAW,iBAAiB;IAChC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,WAAW;IAEpB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,UAAU,EAAE,iBAAiB,EAC7B,MAAM,EAAE,iBAAiB;IAGtC,KAAK,CACT,QAAQ,EAAE,aAAa,EAAE,EACzB,MAAM,EAAE,aAAa,EAAE,EACvB,OAAO,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,GACzC,OAAO,CAAC,WAAW,CAAC;CAmFxB"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { cosineSimilarity } from '../embeddings/cosine.js';
|
|
2
|
+
import { curationScore } from './scoring.js';
|
|
3
|
+
export class MergeEngine {
|
|
4
|
+
embeddings;
|
|
5
|
+
config;
|
|
6
|
+
constructor(embeddings, config) {
|
|
7
|
+
this.embeddings = embeddings;
|
|
8
|
+
this.config = config;
|
|
9
|
+
}
|
|
10
|
+
async merge(existing, deltas, outcome) {
|
|
11
|
+
const entries = existing.map((e) => ({ ...e }));
|
|
12
|
+
let merged = 0;
|
|
13
|
+
let added = 0;
|
|
14
|
+
// 1. Dedup: for each delta, find best match in existing entries
|
|
15
|
+
for (const delta of deltas) {
|
|
16
|
+
const deltaEmbedding = await this.embeddings.embed(delta.content);
|
|
17
|
+
let bestMatch = null;
|
|
18
|
+
for (let i = 0; i < entries.length; i++) {
|
|
19
|
+
const entry = entries[i];
|
|
20
|
+
if (entry.archived)
|
|
21
|
+
continue;
|
|
22
|
+
let entryEmbedding = entry.embedding;
|
|
23
|
+
if (!entryEmbedding) {
|
|
24
|
+
entryEmbedding = await this.embeddings.embed(entry.content);
|
|
25
|
+
entries[i] = { ...entries[i], embedding: entryEmbedding };
|
|
26
|
+
}
|
|
27
|
+
const sim = cosineSimilarity(deltaEmbedding, entryEmbedding);
|
|
28
|
+
if (sim >= this.config.similarityThreshold) {
|
|
29
|
+
if (!bestMatch || sim > bestMatch.similarity) {
|
|
30
|
+
bestMatch = { index: i, similarity: sim };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (bestMatch) {
|
|
35
|
+
const entry = entries[bestMatch.index];
|
|
36
|
+
// Consistent outcome handling: success → helpful++, failure → harmful++, partial → neither
|
|
37
|
+
if (outcome === 'success') {
|
|
38
|
+
entries[bestMatch.index] = { ...entry, helpful: entry.helpful + 1 };
|
|
39
|
+
}
|
|
40
|
+
else if (outcome === 'failure') {
|
|
41
|
+
entries[bestMatch.index] = { ...entry, harmful: entry.harmful + 1 };
|
|
42
|
+
}
|
|
43
|
+
// partial: no counter change — the lesson is noted but outcome is ambiguous
|
|
44
|
+
merged++;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const newEntry = {
|
|
48
|
+
...delta,
|
|
49
|
+
embedding: deltaEmbedding,
|
|
50
|
+
helpful: delta.helpful + (outcome === 'success' ? 1 : 0),
|
|
51
|
+
harmful: delta.harmful + (outcome === 'failure' ? 1 : 0),
|
|
52
|
+
archived: false,
|
|
53
|
+
};
|
|
54
|
+
entries.push(newEntry);
|
|
55
|
+
added++;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// 2. Recompute scores on all active entries
|
|
59
|
+
const now = Date.now();
|
|
60
|
+
for (let i = 0; i < entries.length; i++) {
|
|
61
|
+
if (entries[i].archived)
|
|
62
|
+
continue;
|
|
63
|
+
const ageMs = now - new Date(entries[i].timestamp).getTime();
|
|
64
|
+
const score = curationScore(entries[i].helpful, entries[i].harmful, ageMs, { lambda: this.config.lambda });
|
|
65
|
+
entries[i] = { ...entries[i], utility: score };
|
|
66
|
+
}
|
|
67
|
+
// 3. Prune: keep top-K by score, archive the rest
|
|
68
|
+
const active = entries.filter((e) => !e.archived);
|
|
69
|
+
const archived = entries.filter((e) => e.archived);
|
|
70
|
+
let pruned = [];
|
|
71
|
+
if (active.length > this.config.maxEntriesPerSection) {
|
|
72
|
+
active.sort((a, b) => b.utility - a.utility);
|
|
73
|
+
pruned = active.splice(this.config.maxEntriesPerSection)
|
|
74
|
+
.map((e) => ({ ...e, archived: true }));
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
entries: [...active, ...archived, ...pruned],
|
|
78
|
+
pruned,
|
|
79
|
+
merged,
|
|
80
|
+
added,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=merge-engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-engine.js","sourceRoot":"","sources":["../../src/curator/merge-engine.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAe7C,MAAM,OAAO,WAAW;IAEH;IACA;IAFnB,YACmB,UAA6B,EAC7B,MAAyB;QADzB,eAAU,GAAV,UAAU,CAAmB;QAC7B,WAAM,GAAN,MAAM,CAAmB;IACzC,CAAC;IAEJ,KAAK,CAAC,KAAK,CACT,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AAG,QAAQ,EAAE,GAAG,MAAM,CAAC;YAC5C,MAAM;YACN,MAAM;YACN,KAAK;SACN,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface CurationWeights {
|
|
2
|
+
effectivenessWeight?: number;
|
|
3
|
+
recencyWeight?: number;
|
|
4
|
+
lambda?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface SelectionWeights {
|
|
7
|
+
effectivenessWeight?: number;
|
|
8
|
+
recencyWeight?: number;
|
|
9
|
+
taskSimilarityWeight?: number;
|
|
10
|
+
lambda?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function curationScore(helpful: number, harmful: number, ageMs: number, weights?: CurationWeights): number;
|
|
13
|
+
export declare function selectionScore(helpful: number, harmful: number, ageMs: number, taskSimilarity: number, weights?: SelectionWeights): number;
|
|
14
|
+
//# sourceMappingURL=scoring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scoring.d.ts","sourceRoot":"","sources":["../../src/curator/scoring.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC9B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAaD,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,eAAe,GACxB,MAAM,CAMR;AAED,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,cAAc,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,gBAAgB,GACzB,MAAM,CAWR"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// packages/core/src/curator/scoring.ts
|
|
2
|
+
function effectiveness(helpful, harmful) {
|
|
3
|
+
return helpful / (helpful + harmful + 1);
|
|
4
|
+
}
|
|
5
|
+
function recency(ageMs, lambda) {
|
|
6
|
+
// Convert milliseconds to days so default lambda=0.01 gives sensible decay
|
|
7
|
+
// (entry at 100 days → recency ≈ 0.37, at 0 days → 1.0)
|
|
8
|
+
const ageDays = ageMs / (1000 * 60 * 60 * 24);
|
|
9
|
+
return Math.exp(-lambda * ageDays);
|
|
10
|
+
}
|
|
11
|
+
export function curationScore(helpful, harmful, ageMs, weights) {
|
|
12
|
+
const ew = weights?.effectivenessWeight ?? 0.6;
|
|
13
|
+
const rw = weights?.recencyWeight ?? 0.4;
|
|
14
|
+
const lambda = weights?.lambda ?? 0.01;
|
|
15
|
+
return ew * effectiveness(helpful, harmful) + rw * recency(ageMs, lambda);
|
|
16
|
+
}
|
|
17
|
+
export function selectionScore(helpful, harmful, ageMs, taskSimilarity, weights) {
|
|
18
|
+
const ew = weights?.effectivenessWeight ?? 0.4;
|
|
19
|
+
const rw = weights?.recencyWeight ?? 0.2;
|
|
20
|
+
const tw = weights?.taskSimilarityWeight ?? 0.4;
|
|
21
|
+
const lambda = weights?.lambda ?? 0.01;
|
|
22
|
+
return (ew * effectiveness(helpful, harmful) +
|
|
23
|
+
rw * recency(ageMs, lambda) +
|
|
24
|
+
tw * taskSimilarity);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=scoring.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scoring.js","sourceRoot":"","sources":["../../src/curator/scoring.ts"],"names":[],"mappings":"AAAA,uCAAuC;AAevC,SAAS,aAAa,CAAC,OAAe,EAAE,OAAe;IACrD,OAAO,OAAO,GAAG,CAAC,OAAO,GAAG,OAAO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"types.d.ts","sourceRoot":"","sources":["../../src/curator/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/curator/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cosine.d.ts","sourceRoot":"","sources":["../../src/embeddings/cosine.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAqBjE"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function cosineSimilarity(a, b) {
|
|
2
|
+
if (a.length !== b.length) {
|
|
3
|
+
throw new Error(`Vector length mismatch: ${a.length} vs ${b.length}`);
|
|
4
|
+
}
|
|
5
|
+
let dotProduct = 0;
|
|
6
|
+
let magnitudeA = 0;
|
|
7
|
+
let magnitudeB = 0;
|
|
8
|
+
for (let i = 0; i < a.length; i++) {
|
|
9
|
+
dotProduct += a[i] * b[i];
|
|
10
|
+
magnitudeA += a[i] * a[i];
|
|
11
|
+
magnitudeB += b[i] * b[i];
|
|
12
|
+
}
|
|
13
|
+
const magnitude = Math.sqrt(magnitudeA) * Math.sqrt(magnitudeB);
|
|
14
|
+
if (magnitude === 0)
|
|
15
|
+
return 0.0;
|
|
16
|
+
// Clamp to [-1, 1] to guard against floating-point rounding errors with
|
|
17
|
+
// subnormal or very small magnitude vectors.
|
|
18
|
+
return Math.max(-1.0, Math.min(1.0, dotProduct / magnitude));
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=cosine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cosine.js","sourceRoot":"","sources":["../../src/embeddings/cosine.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,gBAAgB,CAAC,CAAW,EAAE,CAAW;IACvD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC,MAAM,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IACxE,CAAC;IAED,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,UAAU,GAAG,CAAC,CAAC;IAEnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,UAAU,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1B,UAAU,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1B,UAAU,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAChE,IAAI,SAAS,KAAK,CAAC;QAAE,OAAO,GAAG,CAAC;IAEhC,wEAAwE;IACxE,6CAA6C;IAC7C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { EmbeddingProvider } from './types.js';
|
|
2
|
+
export declare class OnnxEmbeddingProvider implements EmbeddingProvider {
|
|
3
|
+
embed(text: string): Promise<number[]>;
|
|
4
|
+
embedBatch(texts: string[]): Promise<number[][]>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=onnx-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onnx-provider.d.ts","sourceRoot":"","sources":["../../src/embeddings/onnx-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAYpD,qBAAa,qBAAsB,YAAW,iBAAiB;IACvD,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAMtC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;CAGvD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
let pipelineInstance = null;
|
|
2
|
+
async function getExtractor() {
|
|
3
|
+
if (!pipelineInstance) {
|
|
4
|
+
const { pipeline } = await import('@huggingface/transformers');
|
|
5
|
+
pipelineInstance = await pipeline('feature-extraction', 'Xenova/all-MiniLM-L6-v2');
|
|
6
|
+
}
|
|
7
|
+
return pipelineInstance;
|
|
8
|
+
}
|
|
9
|
+
export class OnnxEmbeddingProvider {
|
|
10
|
+
async embed(text) {
|
|
11
|
+
const extractor = await getExtractor();
|
|
12
|
+
const output = await extractor(text, { pooling: 'mean', normalize: true });
|
|
13
|
+
return Array.from(output.data);
|
|
14
|
+
}
|
|
15
|
+
async embedBatch(texts) {
|
|
16
|
+
return Promise.all(texts.map((t) => this.embed(t)));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=onnx-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onnx-provider.js","sourceRoot":"","sources":["../../src/embeddings/onnx-provider.ts"],"names":[],"mappings":"AAEA,IAAI,gBAAgB,GAAQ,IAAI,CAAC;AAEjC,KAAK,UAAU,YAAY;IACzB,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,2BAA2B,CAAC,CAAC;QAC/D,gBAAgB,GAAG,MAAM,QAAQ,CAAC,oBAAoB,EAAE,yBAAyB,CAAC,CAAC;IACrF,CAAC;IACD,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,MAAM,OAAO,qBAAqB;IAChC,KAAK,CAAC,KAAK,CAAC,IAAY;QACtB,MAAM,SAAS,GAAG,MAAM,YAAY,EAAE,CAAC;QACvC,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3E,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAoB,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,KAAe;QAC9B,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACtD,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/embeddings/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACvC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;CAClD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/embeddings/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PipelineEvent } from './types.js';
|
|
2
|
+
type EventHandler = (event: PipelineEvent) => void;
|
|
3
|
+
export declare class EventBus {
|
|
4
|
+
private handlers;
|
|
5
|
+
on(type: PipelineEvent['type'], handler: EventHandler): void;
|
|
6
|
+
emit(event: PipelineEvent): void;
|
|
7
|
+
}
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=bus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bus.d.ts","sourceRoot":"","sources":["../../src/events/bus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,KAAK,YAAY,GAAG,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;AAEnD,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAqC;IAErD,EAAE,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAM5D,IAAI,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI;CAMjC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class EventBus {
|
|
2
|
+
handlers = new Map();
|
|
3
|
+
on(type, handler) {
|
|
4
|
+
const existing = this.handlers.get(type) ?? [];
|
|
5
|
+
existing.push(handler);
|
|
6
|
+
this.handlers.set(type, existing);
|
|
7
|
+
}
|
|
8
|
+
emit(event) {
|
|
9
|
+
const handlers = this.handlers.get(event.type) ?? [];
|
|
10
|
+
for (const handler of handlers) {
|
|
11
|
+
handler(event);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=bus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bus.js","sourceRoot":"","sources":["../../src/events/bus.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,QAAQ;IACX,QAAQ,GAAG,IAAI,GAAG,EAA0B,CAAC;IAErD,EAAE,CAAC,IAA2B,EAAE,OAAqB;QACnD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QAC/C,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED,IAAI,CAAC,KAAoB;QACvB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACrD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,OAAO,CAAC,KAAK,CAAC,CAAC;QACjB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/events/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,YAAY,GAAG,YAAY,GAAG,UAAU,GAAG,cAAc,GAAG,aAAa,CAAC;IAChF,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/events/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { LLMProvider } from '../llm/types.js';
|
|
2
|
+
import type { PlaybookSnapshot } from '../playbook/types.js';
|
|
3
|
+
import type { GenerationResult, GeneratorConfig } from './types.js';
|
|
4
|
+
interface GeneratorInput {
|
|
5
|
+
taskId: string;
|
|
6
|
+
instruction: string;
|
|
7
|
+
snapshot: PlaybookSnapshot;
|
|
8
|
+
}
|
|
9
|
+
export declare class Generator {
|
|
10
|
+
private readonly llm;
|
|
11
|
+
private readonly config;
|
|
12
|
+
constructor(llm: LLMProvider, config?: GeneratorConfig);
|
|
13
|
+
run(input: GeneratorInput): Promise<GenerationResult>;
|
|
14
|
+
private buildPrompt;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/generator/generator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAuBpE,UAAU,cAAc;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,gBAAgB,CAAC;CAC5B;AAED,qBAAa,SAAS;IAElB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,GAAG,EAAE,WAAW,EAChB,MAAM,GAAE,eAAoB;IAGzC,GAAG,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAc3D,OAAO,CAAC,WAAW;CAwBpB"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
function escapeXmlDelimiters(text) {
|
|
3
|
+
return text.replace(/</g, '<').replace(/>/g, '>');
|
|
4
|
+
}
|
|
5
|
+
const GenerationResponseSchema = z.object({
|
|
6
|
+
trajectories: z.array(z.object({
|
|
7
|
+
step: z.number(),
|
|
8
|
+
reasoning: z.string(),
|
|
9
|
+
action: z.string(),
|
|
10
|
+
})),
|
|
11
|
+
artifacts: z.array(z.object({
|
|
12
|
+
path: z.string(),
|
|
13
|
+
content: z.string(),
|
|
14
|
+
language: z.string(),
|
|
15
|
+
})),
|
|
16
|
+
});
|
|
17
|
+
export class Generator {
|
|
18
|
+
llm;
|
|
19
|
+
config;
|
|
20
|
+
constructor(llm, config = {}) {
|
|
21
|
+
this.llm = llm;
|
|
22
|
+
this.config = config;
|
|
23
|
+
}
|
|
24
|
+
async run(input) {
|
|
25
|
+
const prompt = this.buildPrompt(input);
|
|
26
|
+
const response = await this.llm.structured(prompt, GenerationResponseSchema, {
|
|
27
|
+
model: this.config.model,
|
|
28
|
+
temperature: this.config.temperature,
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
taskId: input.taskId,
|
|
32
|
+
trajectories: response.trajectories,
|
|
33
|
+
artifacts: response.artifacts,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
buildPrompt(input) {
|
|
37
|
+
const playbookContext = input.snapshot.entries.length > 0
|
|
38
|
+
? input.snapshot.entries
|
|
39
|
+
.map((e) => `- [${e.kind}] (utility: ${e.utility}) ${escapeXmlDelimiters(e.content)}`)
|
|
40
|
+
.join('\n')
|
|
41
|
+
: 'No prior context.';
|
|
42
|
+
return [
|
|
43
|
+
'<system_instructions>',
|
|
44
|
+
'You are the Generator in an ACE (Agentic Context Engineering) pipeline.',
|
|
45
|
+
'Your role is to produce explicit reasoning trajectories and code artifacts.',
|
|
46
|
+
'Respond with trajectories (step-by-step reasoning) and artifacts (code/config files).',
|
|
47
|
+
'</system_instructions>',
|
|
48
|
+
'',
|
|
49
|
+
'<playbook_context>',
|
|
50
|
+
playbookContext,
|
|
51
|
+
'</playbook_context>',
|
|
52
|
+
'',
|
|
53
|
+
'<current_task>',
|
|
54
|
+
escapeXmlDelimiters(input.instruction),
|
|
55
|
+
'</current_task>',
|
|
56
|
+
].join('\n');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../src/generator/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,SAAS,mBAAmB,CAAC,IAAY;IACvC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,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Q,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;YAC/B,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO;iBACnB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,eAAe,CAAC,CAAC,OAAO,KAAK,mBAAmB,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;iBACrF,IAAI,CAAC,IAAI,CAAC;YACf,CAAC,CAAC,mBAAmB,CAAC;QAE1B,OAAO;YACL,uBAAuB;YACvB,yEAAyE;YACzE,6EAA6E;YAC7E,uFAAuF;YACvF,wBAAwB;YACxB,EAAE;YACF,oBAAoB;YACpB,eAAe;YACf,qBAAqB;YACrB,EAAE;YACF,gBAAgB;YAChB,mBAAmB,CAAC,KAAK,CAAC,WAAW,CAAC;YACtC,iBAAiB;SAClB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface Trajectory {
|
|
2
|
+
step: number;
|
|
3
|
+
reasoning: string;
|
|
4
|
+
action: string;
|
|
5
|
+
}
|
|
6
|
+
export interface Artifact {
|
|
7
|
+
path: string;
|
|
8
|
+
content: string;
|
|
9
|
+
language: string;
|
|
10
|
+
}
|
|
11
|
+
export interface GeneratorConfig {
|
|
12
|
+
model?: string;
|
|
13
|
+
temperature?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface GenerationResult {
|
|
16
|
+
taskId: string;
|
|
17
|
+
trajectories: Trajectory[];
|
|
18
|
+
artifacts: Artifact[];
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/generator/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,UAAU,EAAE,CAAC;IAC3B,SAAS,EAAE,QAAQ,EAAE,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/generator/types.ts"],"names":[],"mappings":""}
|