@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,139 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const PlaybookEntrySchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
timestamp: z.ZodString;
|
|
5
|
+
source: z.ZodEnum<["generator", "reflector", "curator", "verifier", "solver"]>;
|
|
6
|
+
kind: z.ZodEnum<["trajectory", "lesson", "delta", "verification-failure", "remediation-attempt"]>;
|
|
7
|
+
content: z.ZodString;
|
|
8
|
+
utility: z.ZodNumber;
|
|
9
|
+
harmfulness: z.ZodNumber;
|
|
10
|
+
supersedes: z.ZodOptional<z.ZodString>;
|
|
11
|
+
metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
12
|
+
section: z.ZodOptional<z.ZodString>;
|
|
13
|
+
helpful: z.ZodDefault<z.ZodNumber>;
|
|
14
|
+
harmful: z.ZodDefault<z.ZodNumber>;
|
|
15
|
+
embedding: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
16
|
+
archived: z.ZodDefault<z.ZodBoolean>;
|
|
17
|
+
}, "strip", z.ZodTypeAny, {
|
|
18
|
+
id: string;
|
|
19
|
+
timestamp: string;
|
|
20
|
+
source: "generator" | "reflector" | "curator" | "verifier" | "solver";
|
|
21
|
+
kind: "trajectory" | "lesson" | "delta" | "verification-failure" | "remediation-attempt";
|
|
22
|
+
content: string;
|
|
23
|
+
utility: number;
|
|
24
|
+
harmfulness: number;
|
|
25
|
+
metadata: Record<string, unknown>;
|
|
26
|
+
helpful: number;
|
|
27
|
+
harmful: number;
|
|
28
|
+
archived: boolean;
|
|
29
|
+
supersedes?: string | undefined;
|
|
30
|
+
section?: string | undefined;
|
|
31
|
+
embedding?: number[] | undefined;
|
|
32
|
+
}, {
|
|
33
|
+
id: string;
|
|
34
|
+
timestamp: string;
|
|
35
|
+
source: "generator" | "reflector" | "curator" | "verifier" | "solver";
|
|
36
|
+
kind: "trajectory" | "lesson" | "delta" | "verification-failure" | "remediation-attempt";
|
|
37
|
+
content: string;
|
|
38
|
+
utility: number;
|
|
39
|
+
harmfulness: number;
|
|
40
|
+
metadata: Record<string, unknown>;
|
|
41
|
+
supersedes?: string | undefined;
|
|
42
|
+
section?: string | undefined;
|
|
43
|
+
helpful?: number | undefined;
|
|
44
|
+
harmful?: number | undefined;
|
|
45
|
+
embedding?: number[] | undefined;
|
|
46
|
+
archived?: boolean | undefined;
|
|
47
|
+
}>;
|
|
48
|
+
export type PlaybookEntry = z.infer<typeof PlaybookEntrySchema>;
|
|
49
|
+
export declare const DeltaUpdateSchema: z.ZodObject<{
|
|
50
|
+
additions: z.ZodArray<z.ZodObject<{
|
|
51
|
+
id: z.ZodString;
|
|
52
|
+
timestamp: z.ZodString;
|
|
53
|
+
source: z.ZodEnum<["generator", "reflector", "curator", "verifier", "solver"]>;
|
|
54
|
+
kind: z.ZodEnum<["trajectory", "lesson", "delta", "verification-failure", "remediation-attempt"]>;
|
|
55
|
+
content: z.ZodString;
|
|
56
|
+
utility: z.ZodNumber;
|
|
57
|
+
harmfulness: z.ZodNumber;
|
|
58
|
+
supersedes: z.ZodOptional<z.ZodString>;
|
|
59
|
+
metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
60
|
+
section: z.ZodOptional<z.ZodString>;
|
|
61
|
+
helpful: z.ZodDefault<z.ZodNumber>;
|
|
62
|
+
harmful: z.ZodDefault<z.ZodNumber>;
|
|
63
|
+
embedding: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
64
|
+
archived: z.ZodDefault<z.ZodBoolean>;
|
|
65
|
+
}, "strip", z.ZodTypeAny, {
|
|
66
|
+
id: string;
|
|
67
|
+
timestamp: string;
|
|
68
|
+
source: "generator" | "reflector" | "curator" | "verifier" | "solver";
|
|
69
|
+
kind: "trajectory" | "lesson" | "delta" | "verification-failure" | "remediation-attempt";
|
|
70
|
+
content: string;
|
|
71
|
+
utility: number;
|
|
72
|
+
harmfulness: number;
|
|
73
|
+
metadata: Record<string, unknown>;
|
|
74
|
+
helpful: number;
|
|
75
|
+
harmful: number;
|
|
76
|
+
archived: boolean;
|
|
77
|
+
supersedes?: string | undefined;
|
|
78
|
+
section?: string | undefined;
|
|
79
|
+
embedding?: number[] | undefined;
|
|
80
|
+
}, {
|
|
81
|
+
id: string;
|
|
82
|
+
timestamp: string;
|
|
83
|
+
source: "generator" | "reflector" | "curator" | "verifier" | "solver";
|
|
84
|
+
kind: "trajectory" | "lesson" | "delta" | "verification-failure" | "remediation-attempt";
|
|
85
|
+
content: string;
|
|
86
|
+
utility: number;
|
|
87
|
+
harmfulness: number;
|
|
88
|
+
metadata: Record<string, unknown>;
|
|
89
|
+
supersedes?: string | undefined;
|
|
90
|
+
section?: string | undefined;
|
|
91
|
+
helpful?: number | undefined;
|
|
92
|
+
harmful?: number | undefined;
|
|
93
|
+
embedding?: number[] | undefined;
|
|
94
|
+
archived?: boolean | undefined;
|
|
95
|
+
}>, "many">;
|
|
96
|
+
deprecations: z.ZodArray<z.ZodString, "many">;
|
|
97
|
+
}, "strip", z.ZodTypeAny, {
|
|
98
|
+
additions: {
|
|
99
|
+
id: string;
|
|
100
|
+
timestamp: string;
|
|
101
|
+
source: "generator" | "reflector" | "curator" | "verifier" | "solver";
|
|
102
|
+
kind: "trajectory" | "lesson" | "delta" | "verification-failure" | "remediation-attempt";
|
|
103
|
+
content: string;
|
|
104
|
+
utility: number;
|
|
105
|
+
harmfulness: number;
|
|
106
|
+
metadata: Record<string, unknown>;
|
|
107
|
+
helpful: number;
|
|
108
|
+
harmful: number;
|
|
109
|
+
archived: boolean;
|
|
110
|
+
supersedes?: string | undefined;
|
|
111
|
+
section?: string | undefined;
|
|
112
|
+
embedding?: number[] | undefined;
|
|
113
|
+
}[];
|
|
114
|
+
deprecations: string[];
|
|
115
|
+
}, {
|
|
116
|
+
additions: {
|
|
117
|
+
id: string;
|
|
118
|
+
timestamp: string;
|
|
119
|
+
source: "generator" | "reflector" | "curator" | "verifier" | "solver";
|
|
120
|
+
kind: "trajectory" | "lesson" | "delta" | "verification-failure" | "remediation-attempt";
|
|
121
|
+
content: string;
|
|
122
|
+
utility: number;
|
|
123
|
+
harmfulness: number;
|
|
124
|
+
metadata: Record<string, unknown>;
|
|
125
|
+
supersedes?: string | undefined;
|
|
126
|
+
section?: string | undefined;
|
|
127
|
+
helpful?: number | undefined;
|
|
128
|
+
harmful?: number | undefined;
|
|
129
|
+
embedding?: number[] | undefined;
|
|
130
|
+
archived?: boolean | undefined;
|
|
131
|
+
}[];
|
|
132
|
+
deprecations: string[];
|
|
133
|
+
}>;
|
|
134
|
+
export type DeltaUpdate = z.infer<typeof DeltaUpdateSchema>;
|
|
135
|
+
export interface PlaybookSnapshot {
|
|
136
|
+
entries: PlaybookEntry[];
|
|
137
|
+
takenAt: string;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/playbook/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgB9B,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAG5B,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const PlaybookEntrySchema = z.object({
|
|
3
|
+
id: z.string().min(1),
|
|
4
|
+
timestamp: z.string().datetime(),
|
|
5
|
+
source: z.enum(['generator', 'reflector', 'curator', 'verifier', 'solver']),
|
|
6
|
+
kind: z.enum(['trajectory', 'lesson', 'delta', 'verification-failure', 'remediation-attempt']),
|
|
7
|
+
content: z.string(),
|
|
8
|
+
utility: z.number().min(0).max(1),
|
|
9
|
+
harmfulness: z.number().min(0).max(1),
|
|
10
|
+
supersedes: z.string().optional(),
|
|
11
|
+
metadata: z.record(z.unknown()),
|
|
12
|
+
// New fields for grounded spec revision
|
|
13
|
+
section: z.string().optional(), // playbook section (e.g., "auth", "testing")
|
|
14
|
+
helpful: z.number().int().min(0).default(0), // positive reinforcement counter
|
|
15
|
+
harmful: z.number().int().min(0).default(0), // negative reinforcement counter
|
|
16
|
+
embedding: z.array(z.number()).optional(), // cached embedding vector
|
|
17
|
+
archived: z.boolean().default(false), // soft-delete flag
|
|
18
|
+
});
|
|
19
|
+
export const DeltaUpdateSchema = z.object({
|
|
20
|
+
additions: z.array(PlaybookEntrySchema),
|
|
21
|
+
deprecations: z.array(z.string()),
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/playbook/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACrB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;IAC3E,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,CAAC,CAAC;IAC9F,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACjC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACrC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACjC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IAC/B,wCAAwC;IACxC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAqB,6CAA6C;IAChG,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAQ,iCAAiC;IACpF,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAQ,iCAAiC;IACpF,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,EAAW,0BAA0B;IAC9E,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,EAAgB,mBAAmB;CACxE,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,mBAAmB,CAAC;IACvC,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;CAClC,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SandboxOptions, SandboxResult } from './types.js';
|
|
2
|
+
export declare class ExecutionSandbox {
|
|
3
|
+
exec(command: string, args: string[], options: SandboxOptions): Promise<SandboxResult>;
|
|
4
|
+
private execProcess;
|
|
5
|
+
private execContainer;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=execution-sandbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution-sandbox.d.ts","sourceRoot":"","sources":["../../src/primitives/execution-sandbox.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhE,qBAAa,gBAAgB;IACrB,IAAI,CACR,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,aAAa,CAAC;IAOzB,OAAO,CAAC,WAAW;YAoEL,aAAa;CAyB5B"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
export class ExecutionSandbox {
|
|
3
|
+
async exec(command, args, options) {
|
|
4
|
+
if (options.containerMode) {
|
|
5
|
+
return this.execContainer(command, args, options);
|
|
6
|
+
}
|
|
7
|
+
return this.execProcess(command, args, options);
|
|
8
|
+
}
|
|
9
|
+
execProcess(command, args, options) {
|
|
10
|
+
return new Promise((resolve) => {
|
|
11
|
+
const start = Date.now();
|
|
12
|
+
const controller = new AbortController();
|
|
13
|
+
const maxBuffer = options.maxBuffer ?? 10 * 1024 * 1024;
|
|
14
|
+
const child = spawn(command, args, {
|
|
15
|
+
cwd: options.workingDir,
|
|
16
|
+
env: options.env ? { ...process.env, ...options.env } : process.env,
|
|
17
|
+
signal: controller.signal,
|
|
18
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
19
|
+
});
|
|
20
|
+
let stdout = '';
|
|
21
|
+
let stderr = '';
|
|
22
|
+
let timedOut = false;
|
|
23
|
+
const timer = setTimeout(() => {
|
|
24
|
+
timedOut = true;
|
|
25
|
+
controller.abort();
|
|
26
|
+
}, options.timeoutMs);
|
|
27
|
+
child.stdout.on('data', (chunk) => {
|
|
28
|
+
if (stdout.length < maxBuffer) {
|
|
29
|
+
stdout += chunk.toString();
|
|
30
|
+
if (stdout.length > maxBuffer) {
|
|
31
|
+
stdout = stdout.slice(0, maxBuffer);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
child.stderr.on('data', (chunk) => {
|
|
36
|
+
if (stderr.length < maxBuffer) {
|
|
37
|
+
stderr += chunk.toString();
|
|
38
|
+
if (stderr.length > maxBuffer) {
|
|
39
|
+
stderr = stderr.slice(0, maxBuffer);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
child.on('close', (code) => {
|
|
44
|
+
clearTimeout(timer);
|
|
45
|
+
resolve({
|
|
46
|
+
stdout,
|
|
47
|
+
stderr,
|
|
48
|
+
exitCode: code ?? 1,
|
|
49
|
+
timedOut,
|
|
50
|
+
durationMs: Date.now() - start,
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
child.on('error', () => {
|
|
54
|
+
clearTimeout(timer);
|
|
55
|
+
resolve({
|
|
56
|
+
stdout,
|
|
57
|
+
stderr,
|
|
58
|
+
exitCode: 1,
|
|
59
|
+
timedOut,
|
|
60
|
+
durationMs: Date.now() - start,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async execContainer(command, args, options) {
|
|
66
|
+
if (!options.containerImage) {
|
|
67
|
+
throw new Error('containerImage is required when containerMode is enabled.');
|
|
68
|
+
}
|
|
69
|
+
const dockerArgs = [
|
|
70
|
+
'run', '--rm',
|
|
71
|
+
'-w', '/workspace',
|
|
72
|
+
'-v', `${options.workingDir}:/workspace`,
|
|
73
|
+
...(options.env
|
|
74
|
+
? Object.entries(options.env).flatMap(([k, v]) => ['-e', `${k}=${v}`])
|
|
75
|
+
: []),
|
|
76
|
+
options.containerImage,
|
|
77
|
+
command,
|
|
78
|
+
...args,
|
|
79
|
+
];
|
|
80
|
+
return this.execProcess('docker', dockerArgs, {
|
|
81
|
+
...options,
|
|
82
|
+
containerMode: false,
|
|
83
|
+
workingDir: options.workingDir,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=execution-sandbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution-sandbox.js","sourceRoot":"","sources":["../../src/primitives/execution-sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,MAAM,OAAO,gBAAgB;IAC3B,KAAK,CAAC,IAAI,CACR,OAAe,EACf,IAAc,EACd,OAAuB;QAEvB,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IAEO,WAAW,CACjB,OAAe,EACf,IAAc,EACd,OAAuB;QAEvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACzB,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;YACzC,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;YAExD,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE;gBACjC,GAAG,EAAE,OAAO,CAAC,UAAU;gBACvB,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG;gBACnE,MAAM,EAAE,UAAU,CAAC,MAAM;gBACzB,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;aAClC,CAAC,CAAC;YAEH,IAAI,MAAM,GAAG,EAAE,CAAC;YAChB,IAAI,MAAM,GAAG,EAAE,CAAC;YAChB,IAAI,QAAQ,GAAG,KAAK,CAAC;YAErB,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;gBAC5B,QAAQ,GAAG,IAAI,CAAC;gBAChB,UAAU,CAAC,KAAK,EAAE,CAAC;YACrB,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;YAEtB,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;gBACxC,IAAI,MAAM,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;oBAC9B,MAAM,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;oBAC3B,IAAI,MAAM,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;wBAC9B,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;oBACtC,CAAC;gBACH,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;gBACxC,IAAI,MAAM,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;oBAC9B,MAAM,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;oBAC3B,IAAI,MAAM,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;wBAC9B,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;oBACtC,CAAC;gBACH,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;gBACzB,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,OAAO,CAAC;oBACN,MAAM;oBACN,MAAM;oBACN,QAAQ,EAAE,IAAI,IAAI,CAAC;oBACnB,QAAQ;oBACR,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;iBAC/B,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;gBACrB,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,OAAO,CAAC;oBACN,MAAM;oBACN,MAAM;oBACN,QAAQ,EAAE,CAAC;oBACX,QAAQ;oBACR,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;iBAC/B,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,aAAa,CACzB,OAAe,EACf,IAAc,EACd,OAAuB;QAEvB,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;QAC/E,CAAC;QACD,MAAM,UAAU,GAAG;YACjB,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,YAAY;YAClB,IAAI,EAAE,GAAG,OAAO,CAAC,UAAU,aAAa;YACxC,GAAG,CAAC,OAAO,CAAC,GAAG;gBACb,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACtE,CAAC,CAAC,EAAE,CAAC;YACP,OAAO,CAAC,cAAc;YACtB,OAAO;YACP,GAAG,IAAI;SACR,CAAC;QACF,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,UAAU,EAAE;YAC5C,GAAG,OAAO;YACV,aAAa,EAAE,KAAK;YACpB,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class RatchetGuard {
|
|
2
|
+
private readonly workingDir;
|
|
3
|
+
private checkpointRef;
|
|
4
|
+
constructor(workingDir: string);
|
|
5
|
+
checkpoint(): Promise<string>;
|
|
6
|
+
keepOrRevert(predicate: () => Promise<boolean>): Promise<boolean>;
|
|
7
|
+
revert(ref: string): Promise<void>;
|
|
8
|
+
private git;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=ratchet-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ratchet-guard.d.ts","sourceRoot":"","sources":["../../src/primitives/ratchet-guard.ts"],"names":[],"mappings":"AAEA,qBAAa,YAAY;IAGX,OAAO,CAAC,QAAQ,CAAC,UAAU;IAFvC,OAAO,CAAC,aAAa,CAAuB;gBAEf,UAAU,EAAE,MAAM;IAEzC,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAM7B,YAAY,CAAC,SAAS,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAqBjE,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKxC,OAAO,CAAC,GAAG;CAMZ"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
export class RatchetGuard {
|
|
3
|
+
workingDir;
|
|
4
|
+
checkpointRef = null;
|
|
5
|
+
constructor(workingDir) {
|
|
6
|
+
this.workingDir = workingDir;
|
|
7
|
+
}
|
|
8
|
+
async checkpoint() {
|
|
9
|
+
const sha = this.git(['rev-parse', 'HEAD']);
|
|
10
|
+
this.checkpointRef = sha;
|
|
11
|
+
return sha;
|
|
12
|
+
}
|
|
13
|
+
async keepOrRevert(predicate) {
|
|
14
|
+
if (!this.checkpointRef) {
|
|
15
|
+
throw new Error('No checkpoint set. Call checkpoint() first.');
|
|
16
|
+
}
|
|
17
|
+
let keep;
|
|
18
|
+
try {
|
|
19
|
+
keep = await predicate();
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
keep = false;
|
|
23
|
+
}
|
|
24
|
+
if (keep) {
|
|
25
|
+
this.checkpointRef = this.git(['rev-parse', 'HEAD']);
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
await this.revert(this.checkpointRef);
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async revert(ref) {
|
|
34
|
+
this.git(['reset', '--hard', ref]);
|
|
35
|
+
this.checkpointRef = ref;
|
|
36
|
+
}
|
|
37
|
+
git(args) {
|
|
38
|
+
return execFileSync('git', args, {
|
|
39
|
+
cwd: this.workingDir,
|
|
40
|
+
encoding: 'utf-8',
|
|
41
|
+
}).trim();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=ratchet-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ratchet-guard.js","sourceRoot":"","sources":["../../src/primitives/ratchet-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,OAAO,YAAY;IAGM;IAFrB,aAAa,GAAkB,IAAI,CAAC;IAE5C,YAA6B,UAAkB;QAAlB,eAAU,GAAV,UAAU,CAAQ;IAAG,CAAC;IAEnD,KAAK,CAAC,UAAU;QACd,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;QAC5C,IAAI,CAAC,aAAa,GAAG,GAAG,CAAC;QACzB,OAAO,GAAG,CAAC;IACb,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,SAAiC;QAClD,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;QAED,IAAI,IAAa,CAAC;QAClB,IAAI,CAAC;YACH,IAAI,GAAG,MAAM,SAAS,EAAE,CAAC;QAC3B,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,GAAG,KAAK,CAAC;QACf,CAAC;QAED,IAAI,IAAI,EAAE,CAAC;YACT,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;YACrD,OAAO,IAAI,CAAC;QACd,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YACtC,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW;QACtB,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC;QACnC,IAAI,CAAC,aAAa,GAAG,GAAG,CAAC;IAC3B,CAAC;IAEO,GAAG,CAAC,IAAc;QACxB,OAAO,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE;YAC/B,GAAG,EAAE,IAAI,CAAC,UAAU;YACpB,QAAQ,EAAE,OAAO;SAClB,CAAC,CAAC,IAAI,EAAE,CAAC;IACZ,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-budget.d.ts","sourceRoot":"","sources":["../../src/primitives/token-budget.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAW;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,KAAK,CAAK;gBAEN,OAAO,EAAE,MAAM;IAO3B,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAY7B,SAAS,IAAI,MAAM;IAInB,SAAS,IAAI,OAAO;IAIpB,IAAI,IAAI,MAAM;CAGf"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export class TokenBudget {
|
|
2
|
+
ceiling;
|
|
3
|
+
_used = 0;
|
|
4
|
+
constructor(ceiling) {
|
|
5
|
+
if (!Number.isFinite(ceiling) || ceiling <= 0) {
|
|
6
|
+
throw new Error('Token budget ceiling must be a finite positive number.');
|
|
7
|
+
}
|
|
8
|
+
this.ceiling = ceiling;
|
|
9
|
+
}
|
|
10
|
+
consume(tokens) {
|
|
11
|
+
if (tokens < 0) {
|
|
12
|
+
throw new Error('Token consumption must be non-negative.');
|
|
13
|
+
}
|
|
14
|
+
if (this._used + tokens > this.ceiling) {
|
|
15
|
+
throw new Error(`Token budget exceeded: consuming ${tokens} would use ${this._used + tokens} of ${this.ceiling} ceiling.`);
|
|
16
|
+
}
|
|
17
|
+
this._used += tokens;
|
|
18
|
+
}
|
|
19
|
+
remaining() {
|
|
20
|
+
return this.ceiling - this._used;
|
|
21
|
+
}
|
|
22
|
+
exhausted() {
|
|
23
|
+
return this._used >= this.ceiling;
|
|
24
|
+
}
|
|
25
|
+
used() {
|
|
26
|
+
return this._used;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=token-budget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-budget.js","sourceRoot":"","sources":["../../src/primitives/token-budget.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,WAAW;IACb,OAAO,CAAS;IACjB,KAAK,GAAG,CAAC,CAAC;IAElB,YAAY,OAAe;QACzB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,IAAI,CAAC,EAAE,CAAC;YAC9C,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;QAC5E,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,OAAO,CAAC,MAAc;QACpB,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;QAC7D,CAAC;QACD,IAAI,IAAI,CAAC,KAAK,GAAG,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CACb,oCAAoC,MAAM,cAAc,IAAI,CAAC,KAAK,GAAG,MAAM,OAAO,IAAI,CAAC,OAAO,WAAW,CAC1G,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC;IACvB,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC;IACnC,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC;IACpC,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface SandboxOptions {
|
|
2
|
+
workingDir: string;
|
|
3
|
+
timeoutMs: number;
|
|
4
|
+
maxBuffer?: number;
|
|
5
|
+
env?: Record<string, string>;
|
|
6
|
+
containerMode?: boolean;
|
|
7
|
+
containerImage?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface SandboxResult {
|
|
10
|
+
stdout: string;
|
|
11
|
+
stderr: string;
|
|
12
|
+
exitCode: number;
|
|
13
|
+
timedOut: boolean;
|
|
14
|
+
durationMs: number;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/primitives/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/primitives/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { LLMProvider } from '../llm/types.js';
|
|
2
|
+
import type { GenerationResult } from '../generator/types.js';
|
|
3
|
+
import type { ReflectionResult, ReflectorConfig, GroundTruth } from './types.js';
|
|
4
|
+
interface ReflectorInput {
|
|
5
|
+
taskId: string;
|
|
6
|
+
generation: GenerationResult;
|
|
7
|
+
groundTruth?: GroundTruth;
|
|
8
|
+
}
|
|
9
|
+
export declare class Reflector {
|
|
10
|
+
private readonly llm;
|
|
11
|
+
private readonly config;
|
|
12
|
+
constructor(llm: LLMProvider, config?: ReflectorConfig);
|
|
13
|
+
run(input: ReflectorInput): Promise<ReflectionResult>;
|
|
14
|
+
private buildPrompt;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=reflector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reflector.d.ts","sourceRoot":"","sources":["../../src/reflector/reflector.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAYjF,UAAU,cAAc;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,gBAAgB,CAAC;IAC7B,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;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;CAgCpB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const ReflectionResponseSchema = z.object({
|
|
3
|
+
lessons: z.array(z.object({
|
|
4
|
+
insight: z.string(),
|
|
5
|
+
source: z.enum(['success', 'failure', 'heuristic']),
|
|
6
|
+
confidence: z.number().min(0).max(1),
|
|
7
|
+
})),
|
|
8
|
+
});
|
|
9
|
+
export class Reflector {
|
|
10
|
+
llm;
|
|
11
|
+
config;
|
|
12
|
+
constructor(llm, config = {}) {
|
|
13
|
+
this.llm = llm;
|
|
14
|
+
this.config = config;
|
|
15
|
+
}
|
|
16
|
+
async run(input) {
|
|
17
|
+
const prompt = this.buildPrompt(input);
|
|
18
|
+
const response = await this.llm.structured(prompt, ReflectionResponseSchema, {
|
|
19
|
+
model: this.config.model,
|
|
20
|
+
temperature: this.config.temperature,
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
taskId: input.taskId,
|
|
24
|
+
sourceGenerationTaskId: input.generation.taskId,
|
|
25
|
+
lessons: response.lessons,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
buildPrompt(input) {
|
|
29
|
+
const parts = [
|
|
30
|
+
'You are the Reflector in an ACE (Agentic Context Engineering) pipeline.',
|
|
31
|
+
'Your role is to analyze a generation result and extract factual and heuristic lessons.',
|
|
32
|
+
'',
|
|
33
|
+
'## Generation Trajectories',
|
|
34
|
+
...input.generation.trajectories.map((t) => `Step ${t.step}: ${t.reasoning} → ${t.action}`),
|
|
35
|
+
'',
|
|
36
|
+
'## Generated Artifacts',
|
|
37
|
+
...input.generation.artifacts.map((a) => `${a.path} (${a.language}):\n${a.content}`),
|
|
38
|
+
];
|
|
39
|
+
if (input.groundTruth) {
|
|
40
|
+
parts.push('', `## Ground Truth (${input.groundTruth.type})`, input.groundTruth.content);
|
|
41
|
+
}
|
|
42
|
+
parts.push('', 'Extract lessons: what worked (success), what failed (failure), and general heuristics.', 'Rate your confidence in each lesson from 0 to 1.');
|
|
43
|
+
return parts.join('\n');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=reflector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reflector.js","sourceRoot":"","sources":["../../src/reflector/reflector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,OAAO,EAAE,CAAC,CAAC,KAAK,CACd,CAAC,CAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;QACnB,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;QACnD,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;KACrC,CAAC,CACH;CACF,CAAC,CAAC;AAQH,MAAM,OAAO,SAAS;IAED;IACA;IAFnB,YACmB,GAAgB,EAChB,SAA0B,EAAE;QAD5B,QAAG,GAAH,GAAG,CAAa;QAChB,WAAM,GAAN,MAAM,CAAsB;IAC5C,CAAC;IAEJ,KAAK,CAAC,GAAG,CAAC,KAAqB;QAC7B,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QACvC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,EAAE,wBAAwB,EAAE;YAC3E,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK;YACxB,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW;SACrC,CAAC,CAAC;QAEH,OAAO;YACL,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,sBAAsB,EAAE,KAAK,CAAC,UAAU,CAAC,MAAM;YAC/C,OAAO,EAAE,QAAQ,CAAC,OAAO;SAC1B,CAAC;IACJ,CAAC;IAEO,WAAW,CAAC,KAAqB;QACvC,MAAM,KAAK,GAAG;YACZ,yEAAyE;YACzE,wFAAwF;YACxF,EAAE;YACF,4BAA4B;YAC5B,GAAG,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC,GAAG,CAClC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,CAAC,MAAM,EAAE,CACtD;YACD,EAAE;YACF,wBAAwB;YACxB,GAAG,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,GAAG,CAC/B,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,QAAQ,OAAO,CAAC,CAAC,OAAO,EAAE,CAClD;SACF,CAAC;QAEF,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;YACtB,KAAK,CAAC,IAAI,CACR,EAAE,EACF,oBAAoB,KAAK,CAAC,WAAW,CAAC,IAAI,GAAG,EAC7C,KAAK,CAAC,WAAW,CAAC,OAAO,CAC1B,CAAC;QACJ,CAAC;QAED,KAAK,CAAC,IAAI,CACR,EAAE,EACF,wFAAwF,EACxF,kDAAkD,CACnD,CAAC;QAEF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface Lesson {
|
|
2
|
+
insight: string;
|
|
3
|
+
source: 'success' | 'failure' | 'heuristic';
|
|
4
|
+
confidence: number;
|
|
5
|
+
}
|
|
6
|
+
export interface GroundTruth {
|
|
7
|
+
type: 'test-results' | 'error-log' | 'manual';
|
|
8
|
+
content: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ReflectorConfig {
|
|
11
|
+
model?: string;
|
|
12
|
+
temperature?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ReflectionResult {
|
|
15
|
+
taskId: string;
|
|
16
|
+
sourceGenerationTaskId: string;
|
|
17
|
+
lessons: Lesson[];
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/reflector/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,WAAW,CAAC;IAC5C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,cAAc,GAAG,WAAW,GAAG,QAAQ,CAAC;IAC9C,OAAO,EAAE,MAAM,CAAC;CACjB;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,sBAAsB,EAAE,MAAM,CAAC;IAC/B,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/reflector/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@galileodev/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": ["dist"],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"test": "vitest run"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@anthropic-ai/sdk": "^0.52.0",
|
|
23
|
+
"@huggingface/transformers": "^3.0.0",
|
|
24
|
+
"ulid": "^2.3.0",
|
|
25
|
+
"zod": "^3.24.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^25.5.0"
|
|
29
|
+
}
|
|
30
|
+
}
|