@keel_flow/goals 0.2.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/LICENSE +21 -0
- package/dist/dlq.d.ts +11 -0
- package/dist/dlq.d.ts.map +1 -0
- package/dist/dlq.js +29 -0
- package/dist/dlq.js.map +1 -0
- package/dist/evaluator.d.ts +54 -0
- package/dist/evaluator.d.ts.map +1 -0
- package/dist/evaluator.js +146 -0
- package/dist/evaluator.js.map +1 -0
- package/dist/executor.d.ts +18 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/executor.js +68 -0
- package/dist/executor.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/registry.d.ts +9 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +119 -0
- package/dist/registry.js.map +1 -0
- package/dist/risk.d.ts +9 -0
- package/dist/risk.d.ts.map +1 -0
- package/dist/risk.js +36 -0
- package/dist/risk.js.map +1 -0
- package/dist/server.d.ts +5 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +3 -0
- package/dist/server.js.map +1 -0
- package/dist/triggers.d.ts +12 -0
- package/dist/triggers.d.ts.map +1 -0
- package/dist/triggers.js +161 -0
- package/dist/triggers.js.map +1 -0
- package/dist/types.d.ts +57 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 jglasskatz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/dlq.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DlqStore } from "./types.js";
|
|
2
|
+
export interface DlqOptions {
|
|
3
|
+
store: DlqStore;
|
|
4
|
+
maxConsecutiveFailures?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare const DEFAULT_MAX_CONSECUTIVE_FAILURES = 3;
|
|
7
|
+
export declare function recordFailure(opts: DlqOptions, goalId: string, reason: string): Promise<number>;
|
|
8
|
+
export declare function recordSuccess(opts: DlqOptions, goalId: string): Promise<void>;
|
|
9
|
+
export declare function shouldPause(opts: DlqOptions, goalId: string): Promise<boolean>;
|
|
10
|
+
export declare function createInMemoryDlqStore(): DlqStore;
|
|
11
|
+
//# sourceMappingURL=dlq.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dlq.d.ts","sourceRoot":"","sources":["../src/dlq.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,QAAQ,CAAC;IAChB,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,eAAO,MAAM,gCAAgC,IAAI,CAAC;AAElD,wBAAsB,aAAa,CACjC,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAEjB;AAED,wBAAsB,aAAa,CACjC,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAEf;AAED,wBAAsB,WAAW,CAC/B,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC,CAIlB;AAED,wBAAgB,sBAAsB,IAAI,QAAQ,CAejD"}
|
package/dist/dlq.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const DEFAULT_MAX_CONSECUTIVE_FAILURES = 3;
|
|
2
|
+
export async function recordFailure(opts, goalId, reason) {
|
|
3
|
+
return opts.store.recordFailure(goalId, reason);
|
|
4
|
+
}
|
|
5
|
+
export async function recordSuccess(opts, goalId) {
|
|
6
|
+
return opts.store.recordSuccess(goalId);
|
|
7
|
+
}
|
|
8
|
+
export async function shouldPause(opts, goalId) {
|
|
9
|
+
const limit = opts.maxConsecutiveFailures ?? DEFAULT_MAX_CONSECUTIVE_FAILURES;
|
|
10
|
+
const count = await opts.store.getConsecutiveFailures(goalId);
|
|
11
|
+
return count >= limit;
|
|
12
|
+
}
|
|
13
|
+
export function createInMemoryDlqStore() {
|
|
14
|
+
const counts = new Map();
|
|
15
|
+
return {
|
|
16
|
+
async recordFailure(goalId) {
|
|
17
|
+
const next = (counts.get(goalId) ?? 0) + 1;
|
|
18
|
+
counts.set(goalId, next);
|
|
19
|
+
return next;
|
|
20
|
+
},
|
|
21
|
+
async recordSuccess(goalId) {
|
|
22
|
+
counts.set(goalId, 0);
|
|
23
|
+
},
|
|
24
|
+
async getConsecutiveFailures(goalId) {
|
|
25
|
+
return counts.get(goalId) ?? 0;
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=dlq.js.map
|
package/dist/dlq.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dlq.js","sourceRoot":"","sources":["../src/dlq.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAC,CAAC;AAElD,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAAgB,EAChB,MAAc,EACd,MAAc;IAEd,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAAgB,EAChB,MAAc;IAEd,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,IAAgB,EAChB,MAAc;IAEd,MAAM,KAAK,GAAG,IAAI,CAAC,sBAAsB,IAAI,gCAAgC,CAAC;IAC9E,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC;IAC9D,OAAO,KAAK,IAAI,KAAK,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACzC,OAAO;QACL,KAAK,CAAC,aAAa,CAAC,MAAM;YACxB,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;YAC3C,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACzB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,KAAK,CAAC,aAAa,CAAC,MAAM;YACxB,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACxB,CAAC;QACD,KAAK,CAAC,sBAAsB,CAAC,MAAM;YACjC,OAAO,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Goal, GoalAction, GoalContextLoader, TelemetryEmitterLike } from "./types.js";
|
|
2
|
+
import { type ClassifyContext } from "./risk.js";
|
|
3
|
+
export interface EvaluatorModelProvider {
|
|
4
|
+
defaultModel: string;
|
|
5
|
+
generate(req: {
|
|
6
|
+
system: string;
|
|
7
|
+
messages: Array<{
|
|
8
|
+
role: "user" | "assistant";
|
|
9
|
+
content: Array<{
|
|
10
|
+
type: "text";
|
|
11
|
+
text: string;
|
|
12
|
+
}>;
|
|
13
|
+
}>;
|
|
14
|
+
model: string;
|
|
15
|
+
maxTokens?: number;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
content: Array<{
|
|
18
|
+
type: "text";
|
|
19
|
+
text: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: "tool_use";
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
input: unknown;
|
|
25
|
+
} | {
|
|
26
|
+
type: "tool_result";
|
|
27
|
+
toolUseId: string;
|
|
28
|
+
content: string;
|
|
29
|
+
}>;
|
|
30
|
+
stopReason: string;
|
|
31
|
+
usage: {
|
|
32
|
+
inputTokens: number;
|
|
33
|
+
outputTokens: number;
|
|
34
|
+
};
|
|
35
|
+
}>;
|
|
36
|
+
}
|
|
37
|
+
export interface EvaluateGoalOpts {
|
|
38
|
+
goal: Goal;
|
|
39
|
+
provider: EvaluatorModelProvider;
|
|
40
|
+
model?: string;
|
|
41
|
+
telemetry?: TelemetryEmitterLike;
|
|
42
|
+
contextLoader: GoalContextLoader;
|
|
43
|
+
sessionId?: string;
|
|
44
|
+
workspaceId?: string;
|
|
45
|
+
contextWindowMs?: number;
|
|
46
|
+
maxActions?: number;
|
|
47
|
+
classifyCtx?: ClassifyContext;
|
|
48
|
+
}
|
|
49
|
+
export interface EvaluateGoalResult {
|
|
50
|
+
actions: GoalAction[];
|
|
51
|
+
rawResponse?: string;
|
|
52
|
+
}
|
|
53
|
+
export declare function evaluateGoal(opts: EvaluateGoalOpts): Promise<EvaluateGoalResult>;
|
|
54
|
+
//# sourceMappingURL=evaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../src/evaluator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,IAAI,EACJ,UAAU,EACV,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAkB,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjE,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE;QACZ,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;YAAC,OAAO,EAAE,KAAK,CAAC;gBAAE,IAAI,EAAE,MAAM,CAAC;gBAAC,IAAI,EAAE,MAAM,CAAA;aAAE,CAAC,CAAA;SAAE,CAAC,CAAC;QAChG,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC;QACV,OAAO,EAAE,KAAK,CACV;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,GAC9B;YAAE,IAAI,EAAE,UAAU,CAAC;YAAC,EAAE,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,OAAO,CAAA;SAAE,GAC9D;YAAE,IAAI,EAAE,aAAa,CAAC;YAAC,SAAS,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAC9D,CAAC;QACF,UAAU,EAAE,MAAM,CAAC;QACnB,KAAK,EAAE;YAAE,WAAW,EAAE,MAAM,CAAC;YAAC,YAAY,EAAE,MAAM,CAAA;SAAE,CAAC;KACtD,CAAC,CAAC;CACJ;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,sBAAsB,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,oBAAoB,CAAC;IACjC,aAAa,EAAE,iBAAiB,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,eAAe,CAAC;CAC/B;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AA4DD,wBAAsB,YAAY,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAqGtF"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { GoalActionSchema } from "@keel_flow/schema";
|
|
3
|
+
import { classifyAction } from "./risk.js";
|
|
4
|
+
const SYSTEM_PROMPT = `You are the Keel goal evaluator. Given a goal, recent telemetry, and the current repo state, choose 1-3 next actions from this typed set:
|
|
5
|
+
|
|
6
|
+
- verify: run \`keel verify\` (no payload required)
|
|
7
|
+
- kb-retrieve: retrieve from the KB. payload: {query: string, k?: number}
|
|
8
|
+
- surface-question: notify the human with a question. payload: {question: string}
|
|
9
|
+
- add-memory-entry: append to project memory. payload: {fact: string}
|
|
10
|
+
- dispatch-subagent: dispatch a sub-agent to do work (writes code). payload: {task: string, context?: string}
|
|
11
|
+
- open-build: open a structured planning build. payload: {topic: string, codify?: boolean}
|
|
12
|
+
- mark-achieved: declare the goal achieved. payload: {evidence: string}
|
|
13
|
+
- wait: explicitly wait until the next trigger. payload: {until?: string}
|
|
14
|
+
|
|
15
|
+
Output a JSON array of {actionKind, rationale, payload} objects. Each rationale must explain why this action right now, given the goal's success criteria and the current state. Be concise. Do not propose actions whose rationale you cannot defend in one sentence.`;
|
|
16
|
+
function buildEvalUserMessage(opts, state) {
|
|
17
|
+
const lines = [];
|
|
18
|
+
lines.push(`Goal: ${opts.goal.title}`);
|
|
19
|
+
lines.push(`Description: ${opts.goal.description}`);
|
|
20
|
+
lines.push(`Status: ${opts.goal.status}`);
|
|
21
|
+
if (opts.goal.deadline)
|
|
22
|
+
lines.push(`Deadline: ${opts.goal.deadline}`);
|
|
23
|
+
lines.push("");
|
|
24
|
+
lines.push("Success criteria:");
|
|
25
|
+
for (const c of opts.goal.successCriteria) {
|
|
26
|
+
lines.push(` [${c.achieved ? "x" : " "}] ${c.text}${c.evidence ? ` (evidence: ${c.evidence})` : ""}`);
|
|
27
|
+
}
|
|
28
|
+
lines.push("");
|
|
29
|
+
lines.push("Current state:");
|
|
30
|
+
lines.push(` Branch: ${state.snapshot.branch}`);
|
|
31
|
+
lines.push(` Uncommitted files: ${state.snapshot.uncommittedFiles}`);
|
|
32
|
+
lines.push(` Last verify exit code: ${state.snapshot.lastVerifyExitCode ?? "unknown"}`);
|
|
33
|
+
lines.push(` Architecture nodes: ${state.arch.nodeCount}`);
|
|
34
|
+
lines.push(` Principles registered: ${state.principles.count}`);
|
|
35
|
+
lines.push(` Recent telemetry events (window): ${state.events}`);
|
|
36
|
+
lines.push("");
|
|
37
|
+
lines.push(`Propose 1-${opts.maxActions ?? 3} actions. Reply with ONLY a JSON array. No prose, no markdown fences.`);
|
|
38
|
+
return lines.join("\n");
|
|
39
|
+
}
|
|
40
|
+
function extractJsonArray(raw) {
|
|
41
|
+
const trimmed = raw.trim();
|
|
42
|
+
const start = trimmed.indexOf("[");
|
|
43
|
+
const end = trimmed.lastIndexOf("]");
|
|
44
|
+
if (start < 0 || end < 0 || end <= start)
|
|
45
|
+
return null;
|
|
46
|
+
const slice = trimmed.slice(start, end + 1);
|
|
47
|
+
try {
|
|
48
|
+
const parsed = JSON.parse(slice);
|
|
49
|
+
return Array.isArray(parsed) ? parsed : null;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export async function evaluateGoal(opts) {
|
|
56
|
+
const sessionId = opts.sessionId ?? randomUUID();
|
|
57
|
+
const goalId = opts.goal.id;
|
|
58
|
+
const workspaceId = opts.workspaceId ?? opts.goal.workspaceId;
|
|
59
|
+
opts.telemetry?.emit({
|
|
60
|
+
sessionId,
|
|
61
|
+
parentEventId: null,
|
|
62
|
+
workspaceId,
|
|
63
|
+
triggeredBy: { kind: "schedule", goalId },
|
|
64
|
+
kind: "goal.evaluate-start",
|
|
65
|
+
payload: { goalId, title: opts.goal.title },
|
|
66
|
+
});
|
|
67
|
+
const sinceMs = Date.now() - (opts.contextWindowMs ?? 24 * 60 * 60 * 1000);
|
|
68
|
+
const [arch, principles, events, snapshot] = await Promise.all([
|
|
69
|
+
opts.contextLoader.readArchitecture(),
|
|
70
|
+
opts.contextLoader.readPrinciples(),
|
|
71
|
+
opts.contextLoader.listRecentEvents({ sinceMs }),
|
|
72
|
+
opts.contextLoader.getCurrentStateSnapshot(),
|
|
73
|
+
]);
|
|
74
|
+
const state = {
|
|
75
|
+
arch: { nodeCount: arch.nodes.length },
|
|
76
|
+
principles: { count: principles.all().length },
|
|
77
|
+
events: events.length,
|
|
78
|
+
snapshot,
|
|
79
|
+
};
|
|
80
|
+
const userMessage = buildEvalUserMessage(opts, state);
|
|
81
|
+
const res = await opts.provider.generate({
|
|
82
|
+
system: SYSTEM_PROMPT,
|
|
83
|
+
model: opts.model ?? opts.provider.defaultModel,
|
|
84
|
+
messages: [{ role: "user", content: [{ type: "text", text: userMessage }] }],
|
|
85
|
+
maxTokens: 1024,
|
|
86
|
+
});
|
|
87
|
+
const textBlocks = res.content.filter((b) => b.type === "text");
|
|
88
|
+
const raw = textBlocks.map((b) => b.text).join("\n");
|
|
89
|
+
const parsed = extractJsonArray(raw);
|
|
90
|
+
const actions = [];
|
|
91
|
+
if (parsed) {
|
|
92
|
+
for (const rawAction of parsed.slice(0, opts.maxActions ?? 3)) {
|
|
93
|
+
if (typeof rawAction !== "object" || rawAction === null)
|
|
94
|
+
continue;
|
|
95
|
+
const record = rawAction;
|
|
96
|
+
const candidate = {
|
|
97
|
+
id: randomUUID(),
|
|
98
|
+
goalId,
|
|
99
|
+
proposedAt: new Date().toISOString(),
|
|
100
|
+
actionKind: record["actionKind"],
|
|
101
|
+
rationale: typeof record["rationale"] === "string" ? record["rationale"] : "",
|
|
102
|
+
payload: typeof record["payload"] === "object" && record["payload"] !== null
|
|
103
|
+
? record["payload"]
|
|
104
|
+
: {},
|
|
105
|
+
status: "pending-approval",
|
|
106
|
+
approvedAt: null,
|
|
107
|
+
};
|
|
108
|
+
const result = GoalActionSchema.safeParse(candidate);
|
|
109
|
+
if (!result.success)
|
|
110
|
+
continue;
|
|
111
|
+
const action = result.data;
|
|
112
|
+
const risk = classifyAction(action, opts.classifyCtx);
|
|
113
|
+
const finalAction = risk === "auto"
|
|
114
|
+
? { ...action, status: "approved", approvedAt: new Date().toISOString() }
|
|
115
|
+
: action;
|
|
116
|
+
actions.push(finalAction);
|
|
117
|
+
opts.telemetry?.emit({
|
|
118
|
+
sessionId,
|
|
119
|
+
parentEventId: null,
|
|
120
|
+
workspaceId,
|
|
121
|
+
triggeredBy: { kind: "schedule", goalId },
|
|
122
|
+
kind: "goal.action-proposed",
|
|
123
|
+
payload: {
|
|
124
|
+
actionId: finalAction.id,
|
|
125
|
+
actionKind: finalAction.actionKind,
|
|
126
|
+
status: finalAction.status,
|
|
127
|
+
rationale: finalAction.rationale,
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
opts.telemetry?.emit({
|
|
133
|
+
sessionId,
|
|
134
|
+
parentEventId: null,
|
|
135
|
+
workspaceId,
|
|
136
|
+
triggeredBy: { kind: "schedule", goalId },
|
|
137
|
+
kind: "goal.evaluate-end",
|
|
138
|
+
payload: {
|
|
139
|
+
goalId,
|
|
140
|
+
proposed: actions.length,
|
|
141
|
+
autoApproved: actions.filter((a) => a.status === "approved").length,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
return { actions, rawResponse: raw };
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=evaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluator.js","sourceRoot":"","sources":["../src/evaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAOrD,OAAO,EAAE,cAAc,EAAwB,MAAM,WAAW,CAAC;AAsCjE,MAAM,aAAa,GAAG;;;;;;;;;;;uQAWiP,CAAC;AAExQ,SAAS,oBAAoB,CAAC,IAAsB,EAAE,KAKrD;IACC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IACvC,KAAK,CAAC,IAAI,CAAC,gBAAgB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IACpD,KAAK,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1C,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ;QAAE,KAAK,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;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TelemetryEmitterLike } from "./types.js";
|
|
2
|
+
export interface ExecuteActionOpts {
|
|
3
|
+
goal: Goal;
|
|
4
|
+
action: GoalAction;
|
|
5
|
+
executors: ActionExecutors;
|
|
6
|
+
telemetry?: TelemetryEmitterLike;
|
|
7
|
+
sessionId?: string;
|
|
8
|
+
workspaceId?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class UnsupportedActionError extends Error {
|
|
11
|
+
constructor(kind: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class ActionNotApprovedError extends Error {
|
|
14
|
+
constructor(status: string);
|
|
15
|
+
}
|
|
16
|
+
export declare function executeAction(opts: ExecuteActionOpts): Promise<ActionExecutionResult>;
|
|
17
|
+
export declare function createNoopExecutors(): ActionExecutors;
|
|
18
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EACf,IAAI,EACJ,UAAU,EACV,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,EAAE,UAAU,CAAC;IACnB,SAAS,EAAE,eAAe,CAAC;IAC3B,SAAS,CAAC,EAAE,oBAAoB,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,IAAI,EAAE,MAAM;CAIzB;AAED,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,MAAM,EAAE,MAAM;CAI3B;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CA2C3F;AAID,wBAAgB,mBAAmB,IAAI,eAAe,CAOrD"}
|
package/dist/executor.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
export class UnsupportedActionError extends Error {
|
|
3
|
+
constructor(kind) {
|
|
4
|
+
super(`No executor registered for action kind: ${kind}`);
|
|
5
|
+
this.name = "UnsupportedActionError";
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export class ActionNotApprovedError extends Error {
|
|
9
|
+
constructor(status) {
|
|
10
|
+
super(`Action is not approved (status=${status}); refusing to execute`);
|
|
11
|
+
this.name = "ActionNotApprovedError";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export async function executeAction(opts) {
|
|
15
|
+
if (opts.action.status !== "approved") {
|
|
16
|
+
throw new ActionNotApprovedError(opts.action.status);
|
|
17
|
+
}
|
|
18
|
+
const executor = opts.executors[opts.action.actionKind];
|
|
19
|
+
if (!executor) {
|
|
20
|
+
throw new UnsupportedActionError(opts.action.actionKind);
|
|
21
|
+
}
|
|
22
|
+
const sessionId = opts.sessionId ?? randomUUID();
|
|
23
|
+
const workspaceId = opts.workspaceId ?? opts.goal.workspaceId;
|
|
24
|
+
try {
|
|
25
|
+
const result = await executor({ goal: opts.goal, action: opts.action });
|
|
26
|
+
opts.telemetry?.emit({
|
|
27
|
+
sessionId,
|
|
28
|
+
parentEventId: null,
|
|
29
|
+
workspaceId,
|
|
30
|
+
triggeredBy: { kind: "schedule", goalId: opts.goal.id },
|
|
31
|
+
kind: "goal.action-executed",
|
|
32
|
+
payload: {
|
|
33
|
+
actionId: opts.action.id,
|
|
34
|
+
actionKind: opts.action.actionKind,
|
|
35
|
+
outcome: result.outcome,
|
|
36
|
+
status: result.status ?? "completed",
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
43
|
+
opts.telemetry?.emit({
|
|
44
|
+
sessionId,
|
|
45
|
+
parentEventId: null,
|
|
46
|
+
workspaceId,
|
|
47
|
+
triggeredBy: { kind: "schedule", goalId: opts.goal.id },
|
|
48
|
+
kind: "goal.failed",
|
|
49
|
+
payload: {
|
|
50
|
+
actionId: opts.action.id,
|
|
51
|
+
actionKind: opts.action.actionKind,
|
|
52
|
+
error: detail,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
throw err;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Helpers that build a minimal default executor map. Real CLI/API supply
|
|
59
|
+
// real executors; this is for the in-memory thin-slice and tests.
|
|
60
|
+
export function createNoopExecutors() {
|
|
61
|
+
return {
|
|
62
|
+
wait: async () => ({ outcome: "waited" }),
|
|
63
|
+
"surface-question": async ({ action }) => ({
|
|
64
|
+
outcome: `surfaced: ${action.payload["question"] ?? "(no question)"}`,
|
|
65
|
+
}),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAkBzC,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/C,YAAY,IAAY;QACtB,KAAK,CAAC,2CAA2C,IAAI,EAAE,CAAC,CAAC;QACzD,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/C,YAAY,MAAc;QACxB,KAAK,CAAC,kCAAkC,MAAM,wBAAwB,CAAC,CAAC;QACxE,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAuB;IACzD,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;QACtC,MAAM,IAAI,sBAAsB,CAAC,IAAI,CAAC,MAAM,CAAC,MA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Aa,EAAE,IAAI;YACnB,WAAW;YACX,WAAW,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE;YACvD,IAAI,EAAE,aAAa;YACnB,OAAO,EAAE;gBACP,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE;gBACxB,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU;gBAClC,KAAK,EAAE,MAAM;aACd;SACF,CAAC,CAAC;QACH,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC;AAED,yEAAyE;AACzE,kEAAkE;AAClE,MAAM,UAAU,mBAAmB;IACjC,OAAO;QACL,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;QACzC,kBAAkB,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;YACzC,OAAO,EAAE,aAAc,MAAM,CAAC,OAAO,CAAC,UAAU,CAAY,IAAI,eAAe,EAAE;SAClF,CAAC;KACH,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { GOAL_REGISTRY, findGoalSpec, defaultTriggersFor, } from "./registry.js";
|
|
2
|
+
export type { GoalSpec } from "./registry.js";
|
|
3
|
+
export { parseCron, nextFireFor, matchesEvent, hasEventTrigger, eventKindsFor, } from "./triggers.js";
|
|
4
|
+
export type { CronParseResult } from "./triggers.js";
|
|
5
|
+
export type { EvaluatorModelProvider, EvaluateGoalOpts, EvaluateGoalResult, } from "./evaluator.js";
|
|
6
|
+
export type { ExecuteActionOpts } from "./executor.js";
|
|
7
|
+
export { classifyAction } from "./risk.js";
|
|
8
|
+
export type { RiskDecision, ClassifyContext, ClassifyTrustTier } from "./risk.js";
|
|
9
|
+
export { recordFailure, recordSuccess, shouldPause, createInMemoryDlqStore, DEFAULT_MAX_CONSECUTIVE_FAILURES, } from "./dlq.js";
|
|
10
|
+
export type { DlqOptions } from "./dlq.js";
|
|
11
|
+
export type { Goal, GoalAction, GoalActionKind, GoalTrigger, ArchitectureMapLike, PrincipleRegistryLike, AgentEventLike, CurrentStateSnapshot, GoalContextLoader, ActionExecutionContext, ActionExecutionResult, ActionExecutor, ActionExecutors, DlqStore, TelemetryEmitterLike, } from "./types.js";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,YAAY,EACZ,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EACL,SAAS,EACT,WAAW,EACX,YAAY,EACZ,eAAe,EACf,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,YAAY,EACV,sBAAsB,EACtB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAElF,OAAO,EACL,aAAa,EACb,aAAa,EACb,WAAW,EACX,sBAAsB,EACtB,gCAAgC,GACjC,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,YAAY,EACV,IAAI,EACJ,UAAU,EACV,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,EACd,oBAAoB,EACpB,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,QAAQ,EACR,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { GOAL_REGISTRY, findGoalSpec, defaultTriggersFor, } from "./registry.js";
|
|
2
|
+
export { parseCron, nextFireFor, matchesEvent, hasEventTrigger, eventKindsFor, } from "./triggers.js";
|
|
3
|
+
export { classifyAction } from "./risk.js";
|
|
4
|
+
export { recordFailure, recordSuccess, shouldPause, createInMemoryDlqStore, DEFAULT_MAX_CONSECUTIVE_FAILURES, } from "./dlq.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,YAAY,EACZ,kBAAkB,GACnB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,SAAS,EACT,WAAW,EACX,YAAY,EACZ,eAAe,EACf,aAAa,GACd,MAAM,eAAe,CAAC;AAUvB,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C,OAAO,EACL,aAAa,EACb,aAAa,EACb,WAAW,EACX,sBAAsB,EACtB,gCAAgC,GACjC,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Goal, GoalTrigger } from "@keel_flow/schema";
|
|
2
|
+
export interface GoalSpec extends Omit<Goal, "id" | "workspaceId" | "lastEvaluatedAt" | "createdAt" | "updatedAt"> {
|
|
3
|
+
id: string;
|
|
4
|
+
builtIn: true;
|
|
5
|
+
}
|
|
6
|
+
export declare const GOAL_REGISTRY: GoalSpec[];
|
|
7
|
+
export declare function findGoalSpec(id: string): GoalSpec | undefined;
|
|
8
|
+
export declare function defaultTriggersFor(id: string): GoalTrigger[];
|
|
9
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE3D,MAAM,WAAW,QACf,SAAQ,IAAI,CACV,IAAI,EACJ,IAAI,GAAG,aAAa,GAAG,iBAAiB,GAAG,WAAW,GAAG,WAAW,CACrE;IACD,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,IAAI,CAAC;CACf;AAsHD,eAAO,MAAM,aAAa,EAAE,QAAQ,EAQnC,CAAC;AAEF,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAE7D;AAED,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,EAAE,CAG5D"}
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
const KEEP_MAIN_GREEN = {
|
|
2
|
+
id: "keep-main-green",
|
|
3
|
+
builtIn: true,
|
|
4
|
+
title: "Keep main green",
|
|
5
|
+
description: "Run verify on main; surface failures fast. Triggers nightly and on every PR opened.",
|
|
6
|
+
status: "active",
|
|
7
|
+
successCriteria: [
|
|
8
|
+
{ text: "Most recent verify on main exits 0", achieved: false },
|
|
9
|
+
{ text: "No critical verify violations in the last 7 days", achieved: false },
|
|
10
|
+
],
|
|
11
|
+
triggers: [
|
|
12
|
+
{ kind: "cron", expression: "0 2 * * *" },
|
|
13
|
+
{ kind: "event", eventKind: "pull-request.opened" },
|
|
14
|
+
],
|
|
15
|
+
linkedBuildSlug: null,
|
|
16
|
+
deadline: null,
|
|
17
|
+
parentGoalId: null,
|
|
18
|
+
};
|
|
19
|
+
const SESSION_RETROSPECTIVE = {
|
|
20
|
+
id: "session-retrospective",
|
|
21
|
+
builtIn: true,
|
|
22
|
+
title: "Session retrospective",
|
|
23
|
+
description: "Auto-generate a reflection after every session ends; surfaces learnings for the next session.",
|
|
24
|
+
status: "active",
|
|
25
|
+
successCriteria: [
|
|
26
|
+
{ text: "Every session.end has a corresponding reflection within 30s", achieved: false },
|
|
27
|
+
],
|
|
28
|
+
triggers: [{ kind: "event", eventKind: "session.end" }],
|
|
29
|
+
linkedBuildSlug: null,
|
|
30
|
+
deadline: null,
|
|
31
|
+
parentGoalId: null,
|
|
32
|
+
};
|
|
33
|
+
const WEEKLY_LEARN_ROLLUP = {
|
|
34
|
+
id: "weekly-learn-rollup",
|
|
35
|
+
builtIn: true,
|
|
36
|
+
title: "Weekly learn rollup",
|
|
37
|
+
description: "Batch reflections from the past week and propose learnings via `keel learn`.",
|
|
38
|
+
status: "active",
|
|
39
|
+
successCriteria: [
|
|
40
|
+
{ text: "At least one rollup ran in the last 7 days", achieved: false },
|
|
41
|
+
],
|
|
42
|
+
triggers: [{ kind: "cron", expression: "0 9 * * MON" }],
|
|
43
|
+
linkedBuildSlug: null,
|
|
44
|
+
deadline: null,
|
|
45
|
+
parentGoalId: null,
|
|
46
|
+
};
|
|
47
|
+
const KB_STAY_FRESH = {
|
|
48
|
+
id: "kb-stay-fresh",
|
|
49
|
+
builtIn: true,
|
|
50
|
+
title: "KB stay fresh",
|
|
51
|
+
description: "Reindex affected chunks whenever a KB document changes upstream.",
|
|
52
|
+
status: "active",
|
|
53
|
+
successCriteria: [
|
|
54
|
+
{ text: "No KB document is stale (sha mismatch with source) for > 1h", achieved: false },
|
|
55
|
+
],
|
|
56
|
+
triggers: [{ kind: "event", eventKind: "kb.doc.changed" }],
|
|
57
|
+
linkedBuildSlug: null,
|
|
58
|
+
deadline: null,
|
|
59
|
+
parentGoalId: null,
|
|
60
|
+
};
|
|
61
|
+
const BUILD_STAY_DISTILLED = {
|
|
62
|
+
id: "build-stay-distilled",
|
|
63
|
+
builtIn: true,
|
|
64
|
+
title: "Build stay distilled",
|
|
65
|
+
description: "Auto-update `summary.md` for builds in `drafting` state every 5 minutes so the summary tracks the conversation.",
|
|
66
|
+
status: "active",
|
|
67
|
+
successCriteria: [
|
|
68
|
+
{ text: "Every drafting build has a summary updated within 10 minutes of last turn", achieved: false },
|
|
69
|
+
],
|
|
70
|
+
triggers: [{ kind: "interval", minutes: 5 }],
|
|
71
|
+
linkedBuildSlug: null,
|
|
72
|
+
deadline: null,
|
|
73
|
+
parentGoalId: null,
|
|
74
|
+
};
|
|
75
|
+
const AWAITING_APPROVAL_NUDGE = {
|
|
76
|
+
id: "awaiting-approval-nudge",
|
|
77
|
+
builtIn: true,
|
|
78
|
+
title: "Awaiting approval nudge",
|
|
79
|
+
description: "Surface stalled approval gates (builds in awaiting-approval, goal actions in pending-approval) every 15 minutes.",
|
|
80
|
+
status: "active",
|
|
81
|
+
successCriteria: [
|
|
82
|
+
{ text: "No approval has been pending for > 24 hours without a nudge surface", achieved: false },
|
|
83
|
+
],
|
|
84
|
+
triggers: [{ kind: "interval", minutes: 15 }],
|
|
85
|
+
linkedBuildSlug: null,
|
|
86
|
+
deadline: null,
|
|
87
|
+
parentGoalId: null,
|
|
88
|
+
};
|
|
89
|
+
const PRINCIPLES_AUDIT = {
|
|
90
|
+
id: "principles-audit",
|
|
91
|
+
builtIn: true,
|
|
92
|
+
title: "Principles audit",
|
|
93
|
+
description: "Weekly principle check across the repo: run every principle's `check()` against the current tree state.",
|
|
94
|
+
status: "active",
|
|
95
|
+
successCriteria: [
|
|
96
|
+
{ text: "Audit completed in the last 7 days with all critical principles passing", achieved: false },
|
|
97
|
+
],
|
|
98
|
+
triggers: [{ kind: "cron", expression: "0 3 * * SUN" }],
|
|
99
|
+
linkedBuildSlug: null,
|
|
100
|
+
deadline: null,
|
|
101
|
+
parentGoalId: null,
|
|
102
|
+
};
|
|
103
|
+
export const GOAL_REGISTRY = [
|
|
104
|
+
KEEP_MAIN_GREEN,
|
|
105
|
+
SESSION_RETROSPECTIVE,
|
|
106
|
+
WEEKLY_LEARN_ROLLUP,
|
|
107
|
+
KB_STAY_FRESH,
|
|
108
|
+
BUILD_STAY_DISTILLED,
|
|
109
|
+
AWAITING_APPROVAL_NUDGE,
|
|
110
|
+
PRINCIPLES_AUDIT,
|
|
111
|
+
];
|
|
112
|
+
export function findGoalSpec(id) {
|
|
113
|
+
return GOAL_REGISTRY.find((g) => g.id === id);
|
|
114
|
+
}
|
|
115
|
+
export function defaultTriggersFor(id) {
|
|
116
|
+
const spec = findGoalSpec(id);
|
|
117
|
+
return spec ? spec.triggers : [];
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAWA,MAAM,eAAe,GAAa;IAChC,EAAE,EAAE,iBAAiB;IACrB,OAAO,EAAE,IAAI;IACb,KAAK,EAAE,iBAAiB;IACxB,WAAW,EACT,qFAAqF;IACvF,MAAM,EAAE,QAAQ;IAChB,eAAe,EAAE;QACf,EAAE,IAAI,EAAE,oCAAoC,EAAE,QAAQ,EAAE,KAAK,EAAE;QAC/D,EAAE,IAAI,EAAE,kDAAkD,EAAE,QAAQ,EAAE,KAAK,EAAE;KAC9E;IACD,QAAQ,EAAE;QACR,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE;QACzC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE;KACpD;IACD,eAAe,EAAE,IAAI;IACrB,QAAQ,EAAE,IAAI;IACd,YAAY,EAAE,IAAI;CACnB,CAAC;AAEF,MAAM,qBAAqB,GAAa;IACtC,EAAE,EAAE,uBAAuB;IAC3B,OAAO,EAAE,IAAI;IACb,KAAK,EAAE,uBAAuB;IAC9B,WAAW,EACT,+FAA+F;IACjG,MAAM,EAAE,QAAQ;IAChB,eAAe,EAAE;QACf,EAAE,IAAI,EAAE,6DAA6D,EAAE,QAAQ,EAAE,KAAK,EAAE;KACzF;IACD,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC;IACvD,eAAe,EAAE,IAAI;IACrB,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Y,CAAC,EAAE,CAAC,CAAC;IAC9B,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;AACnC,CAAC"}
|
package/dist/risk.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { GoalAction } from "@keel_flow/schema";
|
|
2
|
+
export type RiskDecision = "auto" | "queue";
|
|
3
|
+
export type ClassifyTrustTier = "locked" | "guarded" | "open";
|
|
4
|
+
export interface ClassifyContext {
|
|
5
|
+
trustTier: ClassifyTrustTier;
|
|
6
|
+
hasUntrustedWrites: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function classifyAction(action: GoalAction, ctx?: ClassifyContext): RiskDecision;
|
|
9
|
+
//# sourceMappingURL=risk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"risk.d.ts","sourceRoot":"","sources":["../src/risk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,mBAAmB,CAAC;AAEpE,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,OAAO,CAAC;AAE5C,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC;AAE9D,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,iBAAiB,CAAC;IAC7B,kBAAkB,EAAE,OAAO,CAAC;CAC7B;AASD,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,eAAe,GAAG,YAAY,CA+BtF"}
|
package/dist/risk.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const SAFE_WITHOUT_VERIFY = [
|
|
2
|
+
"kb-retrieve",
|
|
3
|
+
"surface-question",
|
|
4
|
+
"add-memory-entry",
|
|
5
|
+
"wait",
|
|
6
|
+
];
|
|
7
|
+
export function classifyAction(action, ctx) {
|
|
8
|
+
// Fail closed when no trust context is supplied: an absent context must not
|
|
9
|
+
// grant the most permissive posture. Production callers (the scheduler) always
|
|
10
|
+
// pass a real context, so this default only governs the no-context path —
|
|
11
|
+
// there it should queue rather than silently auto-approve side-effecting work.
|
|
12
|
+
const tier = ctx?.trustTier ?? "locked";
|
|
13
|
+
const untrusted = ctx?.hasUntrustedWrites ?? true;
|
|
14
|
+
if (action.actionKind === "verify") {
|
|
15
|
+
// vitest executes every *.test.ts in the repo; gate on tier and untrusted
|
|
16
|
+
// writes so a sub-agent-planted test file cannot run without human approval.
|
|
17
|
+
if (tier === "open" && !untrusted)
|
|
18
|
+
return "auto";
|
|
19
|
+
return "queue";
|
|
20
|
+
}
|
|
21
|
+
if (SAFE_WITHOUT_VERIFY.includes(action.actionKind))
|
|
22
|
+
return "auto";
|
|
23
|
+
if (action.actionKind === "open-build") {
|
|
24
|
+
const isCodify = Boolean(action.payload["codify"] ??
|
|
25
|
+
action.payload["transitionTo"] === "codified");
|
|
26
|
+
return isCodify ? "queue" : "auto";
|
|
27
|
+
}
|
|
28
|
+
if (action.actionKind === "mark-achieved") {
|
|
29
|
+
return "queue";
|
|
30
|
+
}
|
|
31
|
+
if (action.actionKind === "dispatch-subagent") {
|
|
32
|
+
return "queue";
|
|
33
|
+
}
|
|
34
|
+
return "queue";
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=risk.js.map
|
package/dist/risk.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"risk.js","sourceRoot":"","sources":["../src/risk.ts"],"names":[],"mappings":"AAWA,MAAM,mBAAmB,GAAqB;IAC5C,aAAa;IACb,kBAAkB;IAClB,kBAAkB;IAClB,MAAM;CACP,CAAC;AAEF,MAAM,UAAU,cAAc,CAAC,MAAkB,EAAE,GAAqB;IACtE,4EAA4E;IAC5E,+EAA+E;IAC/E,0EAA0E;IAC1E,+EAA+E;IAC/E,MAAM,IAAI,GAAG,GAAG,EAAE,SAAS,IAAI,QAAQ,CAAC;IACxC,MAAM,SAAS,GAAG,GAAG,EAAE,kBAAkB,IAAI,IAAI,CAAC;IAElD,IAAI,MAAM,CAAC,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,0EAA0E;QAC1E,6EAA6E;QAC7E,IAAI,IAAI,KAAK,MAAM,IAAI,CAAC,SAAS;YAAE,OAAO,MAAM,CAAC;QACjD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,IAAI,mBAAmB,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC;QAAE,OAAO,MAAM,CAAC;IAEnE,IAAI,MAAM,CAAC,UAAU,KAAK,YAAY,EAAE,CAAC;QACvC,MAAM,QAAQ,GAAG,OAAO,CACrB,MAAM,CAAC,OAAmC,CAAC,QAAQ,CAAC;YAClD,MAAM,CAAC,OAAmC,CAAC,cAAc,CAAC,KAAK,UAAU,CAC7E,CAAC;QACF,OAAO,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;IACrC,CAAC;IACD,IAAI,MAAM,CAAC,UAAU,KAAK,eAAe,EAAE,CAAC;QAC1C,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,MAAM,CAAC,UAAU,KAAK,mBAAmB,EAAE,CAAC;QAC9C,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { evaluateGoal } from "./evaluator.js";
|
|
2
|
+
export type { EvaluatorModelProvider, EvaluateGoalOpts, EvaluateGoalResult, } from "./evaluator.js";
|
|
3
|
+
export { executeAction, createNoopExecutors, UnsupportedActionError, ActionNotApprovedError, } from "./executor.js";
|
|
4
|
+
export type { ExecuteActionOpts } from "./executor.js";
|
|
5
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,YAAY,EACV,sBAAsB,EACtB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAO9C,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { GoalTrigger, AgentEventLike } from "./types.js";
|
|
2
|
+
export interface CronParseResult {
|
|
3
|
+
isValid: boolean;
|
|
4
|
+
nextFireAt?: Date;
|
|
5
|
+
error?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function parseCron(expression: string, now?: Date): CronParseResult;
|
|
8
|
+
export declare function nextFireFor(triggers: GoalTrigger[], nowMs: number, lastFiredAtMs?: number): number | null;
|
|
9
|
+
export declare function matchesEvent(trigger: GoalTrigger, event: AgentEventLike): boolean;
|
|
10
|
+
export declare function hasEventTrigger(triggers: GoalTrigger[]): boolean;
|
|
11
|
+
export declare function eventKindsFor(triggers: GoalTrigger[]): string[];
|
|
12
|
+
//# sourceMappingURL=triggers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"triggers.d.ts","sourceRoot":"","sources":["../src/triggers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE9D,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,IAAI,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAmID,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,GAAE,IAAiB,GAAG,eAAe,CAQrF;AAED,wBAAgB,WAAW,CACzB,QAAQ,EAAE,WAAW,EAAE,EACvB,KAAK,EAAE,MAAM,EACb,aAAa,CAAC,EAAE,MAAM,GACrB,MAAM,GAAG,IAAI,CAkBf;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO,CAGjF;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,OAAO,CAEhE;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,EAAE,CAI/D"}
|
package/dist/triggers.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
const DOW_NAMES = {
|
|
2
|
+
SUN: 0, MON: 1, TUE: 2, WED: 3, THU: 4, FRI: 5, SAT: 6,
|
|
3
|
+
};
|
|
4
|
+
const MONTH_NAMES = {
|
|
5
|
+
JAN: 1, FEB: 2, MAR: 3, APR: 4, MAY: 5, JUN: 6,
|
|
6
|
+
JUL: 7, AUG: 8, SEP: 9, OCT: 10, NOV: 11, DEC: 12,
|
|
7
|
+
};
|
|
8
|
+
function expandField(raw, min, max, names) {
|
|
9
|
+
const out = new Set();
|
|
10
|
+
for (const part of raw.split(",")) {
|
|
11
|
+
let step = 1;
|
|
12
|
+
let body = part;
|
|
13
|
+
const slashIdx = body.indexOf("/");
|
|
14
|
+
if (slashIdx >= 0) {
|
|
15
|
+
step = parseInt(body.slice(slashIdx + 1), 10);
|
|
16
|
+
if (!Number.isFinite(step) || step <= 0)
|
|
17
|
+
throw new Error(`Invalid step in ${raw}`);
|
|
18
|
+
body = body.slice(0, slashIdx);
|
|
19
|
+
}
|
|
20
|
+
let lo = min;
|
|
21
|
+
let hi = max;
|
|
22
|
+
if (body === "*" || body === "") {
|
|
23
|
+
// keep full range
|
|
24
|
+
}
|
|
25
|
+
else if (body.includes("-")) {
|
|
26
|
+
const [aRaw, bRaw] = body.split("-");
|
|
27
|
+
lo = resolveAtom(aRaw ?? "", names);
|
|
28
|
+
hi = resolveAtom(bRaw ?? "", names);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
const v = resolveAtom(body, names);
|
|
32
|
+
lo = v;
|
|
33
|
+
hi = v;
|
|
34
|
+
}
|
|
35
|
+
if (!Number.isFinite(lo) || !Number.isFinite(hi)) {
|
|
36
|
+
throw new Error(`Invalid atom in ${raw}`);
|
|
37
|
+
}
|
|
38
|
+
if (lo < min || hi > max || lo > hi) {
|
|
39
|
+
throw new Error(`Out-of-range value in ${raw} (${lo}-${hi}, allowed ${min}-${max})`);
|
|
40
|
+
}
|
|
41
|
+
for (let v = lo; v <= hi; v += step)
|
|
42
|
+
out.add(v);
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
function resolveAtom(s, names) {
|
|
47
|
+
const t = s.trim().toUpperCase();
|
|
48
|
+
if (names && t in names)
|
|
49
|
+
return names[t];
|
|
50
|
+
const n = parseInt(t, 10);
|
|
51
|
+
if (!Number.isFinite(n))
|
|
52
|
+
throw new Error(`Cannot parse atom '${s}'`);
|
|
53
|
+
return n;
|
|
54
|
+
}
|
|
55
|
+
function parseCronFields(expression) {
|
|
56
|
+
const parts = expression.trim().split(/\s+/);
|
|
57
|
+
if (parts.length !== 5) {
|
|
58
|
+
throw new Error(`Expected 5 fields, got ${parts.length}`);
|
|
59
|
+
}
|
|
60
|
+
const [m, h, dom, mo, dow] = parts;
|
|
61
|
+
return {
|
|
62
|
+
minute: expandField(m, 0, 59),
|
|
63
|
+
hour: expandField(h, 0, 23),
|
|
64
|
+
dayOfMonth: expandField(dom, 1, 31),
|
|
65
|
+
month: expandField(mo, 1, 12, MONTH_NAMES),
|
|
66
|
+
dayOfWeek: expandField(dow, 0, 6, DOW_NAMES),
|
|
67
|
+
dayOfMonthAny: dom === "*",
|
|
68
|
+
dayOfWeekAny: dow === "*",
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function nextCronFire(fields, from) {
|
|
72
|
+
const candidate = new Date(from.getTime());
|
|
73
|
+
candidate.setSeconds(0, 0);
|
|
74
|
+
candidate.setMinutes(candidate.getMinutes() + 1);
|
|
75
|
+
for (let i = 0; i < 366 * 24 * 60; i++) {
|
|
76
|
+
const yr = candidate.getFullYear();
|
|
77
|
+
const mo = candidate.getMonth() + 1;
|
|
78
|
+
const day = candidate.getDate();
|
|
79
|
+
const dow = candidate.getDay();
|
|
80
|
+
const hr = candidate.getHours();
|
|
81
|
+
const min = candidate.getMinutes();
|
|
82
|
+
if (!fields.month.has(mo)) {
|
|
83
|
+
candidate.setMonth(candidate.getMonth() + 1, 1);
|
|
84
|
+
candidate.setHours(0, 0, 0, 0);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const domOk = fields.dayOfMonth.has(day);
|
|
88
|
+
const dowOk = fields.dayOfWeek.has(dow);
|
|
89
|
+
const dayOk = fields.dayOfMonthAny && fields.dayOfWeekAny
|
|
90
|
+
? true
|
|
91
|
+
: fields.dayOfMonthAny
|
|
92
|
+
? dowOk
|
|
93
|
+
: fields.dayOfWeekAny
|
|
94
|
+
? domOk
|
|
95
|
+
: domOk || dowOk;
|
|
96
|
+
if (!dayOk) {
|
|
97
|
+
candidate.setDate(candidate.getDate() + 1);
|
|
98
|
+
candidate.setHours(0, 0, 0, 0);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (!fields.hour.has(hr)) {
|
|
102
|
+
candidate.setHours(candidate.getHours() + 1, 0, 0, 0);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (!fields.minute.has(min)) {
|
|
106
|
+
candidate.setMinutes(candidate.getMinutes() + 1, 0, 0);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
return candidate;
|
|
110
|
+
void yr;
|
|
111
|
+
}
|
|
112
|
+
throw new Error("No matching cron time within 1 year");
|
|
113
|
+
}
|
|
114
|
+
export function parseCron(expression, now = new Date()) {
|
|
115
|
+
try {
|
|
116
|
+
const fields = parseCronFields(expression);
|
|
117
|
+
const nextFireAt = nextCronFire(fields, now);
|
|
118
|
+
return { isValid: true, nextFireAt };
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
return { isValid: false, error: err instanceof Error ? err.message : String(err) };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export function nextFireFor(triggers, nowMs, lastFiredAtMs) {
|
|
125
|
+
let soonest = null;
|
|
126
|
+
const now = new Date(nowMs);
|
|
127
|
+
for (const t of triggers) {
|
|
128
|
+
if (t.kind === "cron") {
|
|
129
|
+
const r = parseCron(t.expression, now);
|
|
130
|
+
if (r.isValid && r.nextFireAt) {
|
|
131
|
+
const ms = r.nextFireAt.getTime();
|
|
132
|
+
if (soonest === null || ms < soonest)
|
|
133
|
+
soonest = ms;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else if (t.kind === "interval") {
|
|
137
|
+
const base = lastFiredAtMs ?? nowMs;
|
|
138
|
+
const next = base + t.minutes * 60 * 1000;
|
|
139
|
+
const adjusted = next <= nowMs ? nowMs + t.minutes * 60 * 1000 : next;
|
|
140
|
+
if (soonest === null || adjusted < soonest)
|
|
141
|
+
soonest = adjusted;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return soonest;
|
|
145
|
+
}
|
|
146
|
+
export function matchesEvent(trigger, event) {
|
|
147
|
+
if (trigger.kind !== "event")
|
|
148
|
+
return false;
|
|
149
|
+
return trigger.eventKind === event.kind;
|
|
150
|
+
}
|
|
151
|
+
export function hasEventTrigger(triggers) {
|
|
152
|
+
return triggers.some((t) => t.kind === "event");
|
|
153
|
+
}
|
|
154
|
+
export function eventKindsFor(triggers) {
|
|
155
|
+
const out = [];
|
|
156
|
+
for (const t of triggers)
|
|
157
|
+
if (t.kind === "event")
|
|
158
|
+
out.push(t.eventKind);
|
|
159
|
+
return out;
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=triggers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"triggers.js","sourceRoot":"","sources":["../src/triggers.ts"],"names":[],"mappings":"AAQA,MAAM,SAAS,GAA2B;IACxC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;CACvD,CAAC;AAEF,MAAM,WAAW,GAA2B;IAC1C,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;IAC9C,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE;CAClD,CAAC;AAYF,SAAS,WAAW,CAClB,GAAW,EACX,GAAW,EACX,GAAW,EACX,KAA8B;IAE9B,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9B,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QAClC,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,IAAI,IAAI,GAAG,IAAI,CAAC;QAChB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACnC,IAAI,QAAQ,IAAI,CAAC,EAAE,CAAC;YAClB,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,CA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GAAG,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;YACtE,IAAI,OAAO,KAAK,IAAI,IAAI,QAAQ,GAAG,OAAO;gBAAE,OAAO,GAAG,QAAQ,CAAC;QACjE,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAoB,EAAE,KAAqB;IACtE,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IAC3C,OAAO,OAAO,CAAC,SAAS,KAAK,KAAK,CAAC,IAAI,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,QAAuB;IACrD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,QAAuB;IACnD,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,KAAK,MAAM,CAAC,IAAI,QAAQ;QAAE,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO;YAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACxE,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { AgentEvent, Goal, GoalAction, GoalActionKind, GoalTrigger } from "@keel_flow/schema";
|
|
2
|
+
export type { Goal, GoalAction, GoalActionKind, GoalTrigger };
|
|
3
|
+
export interface ArchitectureMapLike {
|
|
4
|
+
nodes: Array<{
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
}>;
|
|
8
|
+
connections: unknown[];
|
|
9
|
+
}
|
|
10
|
+
export interface PrincipleRegistryLike {
|
|
11
|
+
all(): Array<{
|
|
12
|
+
id: string;
|
|
13
|
+
severity: string;
|
|
14
|
+
description: string;
|
|
15
|
+
}>;
|
|
16
|
+
}
|
|
17
|
+
export interface AgentEventLike {
|
|
18
|
+
id: string;
|
|
19
|
+
ts: string | Date;
|
|
20
|
+
kind: string;
|
|
21
|
+
sessionId: string;
|
|
22
|
+
payload: Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
export interface CurrentStateSnapshot {
|
|
25
|
+
branch: string;
|
|
26
|
+
uncommittedFiles: number;
|
|
27
|
+
lastVerifyExitCode: number | null;
|
|
28
|
+
}
|
|
29
|
+
export interface GoalContextLoader {
|
|
30
|
+
readArchitecture(): Promise<ArchitectureMapLike>;
|
|
31
|
+
readPrinciples(): Promise<PrincipleRegistryLike>;
|
|
32
|
+
listRecentEvents(opts: {
|
|
33
|
+
sinceMs: number;
|
|
34
|
+
kinds?: string[];
|
|
35
|
+
}): Promise<AgentEventLike[]>;
|
|
36
|
+
getCurrentStateSnapshot(): Promise<CurrentStateSnapshot>;
|
|
37
|
+
}
|
|
38
|
+
export interface ActionExecutionContext {
|
|
39
|
+
goal: Goal;
|
|
40
|
+
action: GoalAction;
|
|
41
|
+
}
|
|
42
|
+
export interface ActionExecutionResult {
|
|
43
|
+
outcome: string;
|
|
44
|
+
status?: "completed" | "failed" | "parked" | "verified";
|
|
45
|
+
meta?: Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
export type ActionExecutor = (ctx: ActionExecutionContext) => Promise<ActionExecutionResult>;
|
|
48
|
+
export type ActionExecutors = Partial<Record<GoalActionKind, ActionExecutor>>;
|
|
49
|
+
export interface DlqStore {
|
|
50
|
+
recordFailure(goalId: string, reason: string): Promise<number>;
|
|
51
|
+
recordSuccess(goalId: string): Promise<void>;
|
|
52
|
+
getConsecutiveFailures(goalId: string): Promise<number>;
|
|
53
|
+
}
|
|
54
|
+
export interface TelemetryEmitterLike {
|
|
55
|
+
emit(event: Omit<AgentEvent, "id" | "ts">): void;
|
|
56
|
+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MAAM,EAAE,CAAC;KAClB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAC9B,uBAAuB,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAAC;CAC1D;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,CAAC;IACxD,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,MAAM,cAAc,GAAG,CAC3B,GAAG,EAAE,sBAAsB,KACxB,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAEpC,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC;AAE9E,MAAM,WAAW,QAAQ;IACvB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/D,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACzD;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;CAClD"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@keel_flow/goals",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"require": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts"
|
|
19
|
+
},
|
|
20
|
+
"./server": {
|
|
21
|
+
"import": "./dist/server.js",
|
|
22
|
+
"require": "./dist/server.js",
|
|
23
|
+
"types": "./dist/server.d.ts"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"zod": "^3.23.0",
|
|
28
|
+
"@keel_flow/schema": "0.2.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^25.9.1",
|
|
32
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
33
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
34
|
+
"eslint": "^9.0.0",
|
|
35
|
+
"typescript": "^5.5.0",
|
|
36
|
+
"vitest": "^2.0.0"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc",
|
|
40
|
+
"typecheck": "tsc --noEmit",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"lint": "eslint src"
|
|
43
|
+
}
|
|
44
|
+
}
|