@hasna/loops 0.3.5 → 0.3.7
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/README.md +60 -0
- package/dist/cli/index.js +1054 -22
- package/dist/daemon/index.js +974 -19
- package/dist/index.d.ts +3 -0
- package/dist/index.js +985 -18
- package/dist/lib/executor.d.ts +3 -0
- package/dist/lib/format.d.ts +3 -1
- package/dist/lib/goal/model-factory.d.ts +9 -0
- package/dist/lib/goal/prompts.d.ts +4 -0
- package/dist/lib/goal/runner.d.ts +3 -0
- package/dist/lib/goal/status.d.ts +9 -0
- package/dist/lib/goal/types.d.ts +120 -0
- package/dist/lib/store.d.ts +58 -1
- package/dist/lib/store.js +544 -5
- package/dist/lib/workflow-spec.d.ts +2 -1
- package/dist/sdk/index.d.ts +6 -1
- package/dist/sdk/index.js +981 -18
- package/dist/types.d.ts +10 -0
- package/docs/TRANSCRIPT_LOOP_PATTERNS.md +95 -0
- package/docs/USAGE.md +17 -0
- package/docs/workflows/transcript-feedback-to-loops.json +80 -0
- package/package.json +5 -2
package/dist/lib/executor.d.ts
CHANGED
package/dist/lib/format.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExecutorResult, Loop, LoopRun, WorkflowEvent, WorkflowRun, WorkflowSpec, WorkflowStepRun } from "../types.js";
|
|
1
|
+
import type { ExecutorResult, Goal, GoalRun, Loop, LoopRun, WorkflowEvent, WorkflowRun, WorkflowSpec, WorkflowStepRun } from "../types.js";
|
|
2
2
|
export declare function redact(value: string | undefined, visible?: number): string | undefined;
|
|
3
3
|
export declare function textOutputBlocks(value: Pick<LoopRun | WorkflowStepRun, "stdout" | "stderr">, opts?: {
|
|
4
4
|
indent?: string;
|
|
@@ -10,3 +10,5 @@ export declare function publicWorkflow(workflow: WorkflowSpec): Record<string, u
|
|
|
10
10
|
export declare function publicWorkflowRun(run: WorkflowRun): Record<string, unknown>;
|
|
11
11
|
export declare function publicWorkflowStepRun(run: WorkflowStepRun, showOutput?: boolean): Record<string, unknown>;
|
|
12
12
|
export declare function publicWorkflowEvent(event: WorkflowEvent): Record<string, unknown>;
|
|
13
|
+
export declare function publicGoal(goal: Goal): Record<string, unknown>;
|
|
14
|
+
export declare function publicGoalRun(run: GoalRun): Record<string, unknown>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LanguageModel } from "ai";
|
|
2
|
+
export interface ResolveGoalModelOptions {
|
|
3
|
+
model?: string;
|
|
4
|
+
baseURL?: string;
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
env?: NodeJS.ProcessEnv;
|
|
7
|
+
}
|
|
8
|
+
export declare const DEFAULT_GOAL_MODEL = "openai/gpt-4o-mini";
|
|
9
|
+
export declare function resolveGoalModel(opts?: ResolveGoalModelOptions): LanguageModel;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Goal, GoalPlanNode, GoalSpec } from "./types.js";
|
|
2
|
+
export declare function planPrompt(spec: GoalSpec): string;
|
|
3
|
+
export declare function iterationPrompt(goal: Goal, readyNodes: GoalPlanNode[]): string;
|
|
4
|
+
export declare function achievementPrompt(goal: Goal, nodes: GoalPlanNode[], evidence: string[]): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { GoalPlan, GoalPlanNode, GoalPlanNodeStatus, GoalRollup, GoalStatus } from "./types.js";
|
|
2
|
+
export declare function isTerminal(status: GoalStatus): boolean;
|
|
3
|
+
export declare function nodeBudgetExhausted(node: GoalPlanNode): boolean;
|
|
4
|
+
export declare function readyNodeKeys(plan: Pick<GoalPlan, "status" | "nodes">): string[];
|
|
5
|
+
export declare function rollupSummary(nodes: Pick<GoalPlanNode, "status">[]): GoalRollup;
|
|
6
|
+
export declare function assertGoalTransition(from: GoalStatus, to: GoalStatus): void;
|
|
7
|
+
export declare function assertAcyclicNodes(nodes: Pick<GoalPlanNode, "key" | "dependsOn">[]): void;
|
|
8
|
+
export declare function updateReadyFlags(nodes: GoalPlanNode[], planStatus: GoalPlan["status"]): GoalPlanNode[];
|
|
9
|
+
export declare function normalizeNodeStatus(status: string): GoalPlanNodeStatus;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { LanguageModel } from "ai";
|
|
2
|
+
import type { ExecutableTarget, ExecutorResult } from "../../types.js";
|
|
3
|
+
import type { Store } from "../store.js";
|
|
4
|
+
export type GoalStatus = "active" | "paused" | "blocked" | "usageLimited" | "budgetLimited" | "complete" | "cancelled";
|
|
5
|
+
export type GoalPlanNodeStatus = "pending" | GoalStatus;
|
|
6
|
+
export type GoalPlanStatus = "active" | "paused" | "blocked" | "budgetLimited" | "complete" | "cancelled";
|
|
7
|
+
export type GoalAutoExecute = "off" | "readyOnly" | "aiDirected";
|
|
8
|
+
export declare const GOAL_TERMINAL: readonly ["budgetLimited", "complete", "cancelled"];
|
|
9
|
+
export declare const GOAL_OBJECTIVE_MAX_CHARS = 4000;
|
|
10
|
+
export interface GoalSpec {
|
|
11
|
+
objective: string;
|
|
12
|
+
tokenBudget?: number;
|
|
13
|
+
model?: string;
|
|
14
|
+
maxTurns?: number;
|
|
15
|
+
maxTokens?: number;
|
|
16
|
+
autoExecute?: GoalAutoExecute;
|
|
17
|
+
}
|
|
18
|
+
export interface Goal {
|
|
19
|
+
goalId: string;
|
|
20
|
+
planId: string;
|
|
21
|
+
objective: string;
|
|
22
|
+
status: GoalStatus;
|
|
23
|
+
tokenBudget?: number;
|
|
24
|
+
tokensUsed: number;
|
|
25
|
+
timeUsedSeconds: number;
|
|
26
|
+
createdAt: string;
|
|
27
|
+
updatedAt: string;
|
|
28
|
+
autoExecute: GoalAutoExecute;
|
|
29
|
+
maxTokens?: number;
|
|
30
|
+
sourceType?: string;
|
|
31
|
+
sourceId?: string;
|
|
32
|
+
loopId?: string;
|
|
33
|
+
loopRunId?: string;
|
|
34
|
+
workflowId?: string;
|
|
35
|
+
workflowRunId?: string;
|
|
36
|
+
workflowStepId?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface GoalRollup {
|
|
39
|
+
total: number;
|
|
40
|
+
pending: number;
|
|
41
|
+
active: number;
|
|
42
|
+
paused: number;
|
|
43
|
+
blocked: number;
|
|
44
|
+
usageLimited: number;
|
|
45
|
+
budgetLimited: number;
|
|
46
|
+
complete: number;
|
|
47
|
+
cancelled: number;
|
|
48
|
+
}
|
|
49
|
+
export interface GoalPlanNode {
|
|
50
|
+
nodeId: string;
|
|
51
|
+
planId: string;
|
|
52
|
+
key: string;
|
|
53
|
+
sequence: number;
|
|
54
|
+
priority: number;
|
|
55
|
+
objective: string;
|
|
56
|
+
status: GoalPlanNodeStatus;
|
|
57
|
+
ready: boolean;
|
|
58
|
+
tokenBudget?: number;
|
|
59
|
+
tokensUsed: number;
|
|
60
|
+
timeUsedSeconds: number;
|
|
61
|
+
dependsOn: string[];
|
|
62
|
+
createdAt: string;
|
|
63
|
+
updatedAt: string;
|
|
64
|
+
}
|
|
65
|
+
export interface GoalPlan {
|
|
66
|
+
planId: string;
|
|
67
|
+
goalId: string;
|
|
68
|
+
status: GoalPlanStatus;
|
|
69
|
+
autoExecute: GoalAutoExecute;
|
|
70
|
+
maxTokens?: number;
|
|
71
|
+
rollup: GoalRollup;
|
|
72
|
+
nodes: GoalPlanNode[];
|
|
73
|
+
createdAt: string;
|
|
74
|
+
updatedAt: string;
|
|
75
|
+
}
|
|
76
|
+
export interface GoalRun {
|
|
77
|
+
runId: string;
|
|
78
|
+
goalId: string;
|
|
79
|
+
planId: string;
|
|
80
|
+
loopId?: string;
|
|
81
|
+
loopRunId?: string;
|
|
82
|
+
workflowId?: string;
|
|
83
|
+
workflowRunId?: string;
|
|
84
|
+
workflowStepId?: string;
|
|
85
|
+
turn: number;
|
|
86
|
+
phase: "plan" | "execute" | "validate" | "status";
|
|
87
|
+
status: GoalStatus | GoalPlanNodeStatus;
|
|
88
|
+
nodeKey?: string;
|
|
89
|
+
tokensUsed: number;
|
|
90
|
+
evidence?: Record<string, unknown>;
|
|
91
|
+
rawResponse?: unknown;
|
|
92
|
+
createdAt: string;
|
|
93
|
+
updatedAt: string;
|
|
94
|
+
}
|
|
95
|
+
export interface GoalExecutionContext {
|
|
96
|
+
loopId?: string;
|
|
97
|
+
loopName?: string;
|
|
98
|
+
loopRunId?: string;
|
|
99
|
+
scheduledFor?: string;
|
|
100
|
+
workflowId?: string;
|
|
101
|
+
workflowName?: string;
|
|
102
|
+
workflowRunId?: string;
|
|
103
|
+
workflowStepId?: string;
|
|
104
|
+
}
|
|
105
|
+
export interface RunGoalOptions {
|
|
106
|
+
store?: Store;
|
|
107
|
+
model?: LanguageModel;
|
|
108
|
+
target?: ExecutableTarget;
|
|
109
|
+
executeNode?: (node: GoalPlanNode, metadata: Record<string, string | undefined>) => Promise<ExecutorResult>;
|
|
110
|
+
env?: NodeJS.ProcessEnv;
|
|
111
|
+
daemonLeaseId?: string;
|
|
112
|
+
beforePersist?: () => void;
|
|
113
|
+
signal?: AbortSignal;
|
|
114
|
+
cancelPollMs?: number;
|
|
115
|
+
context?: GoalExecutionContext;
|
|
116
|
+
}
|
|
117
|
+
export interface GoalExecutorResult extends ExecutorResult {
|
|
118
|
+
goalId?: string;
|
|
119
|
+
goalRunId?: string;
|
|
120
|
+
}
|
package/dist/lib/store.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CreateLoopInput, CreateWorkflowInput, Loop, LoopRun, LoopStatus, RunStatus, WorkflowEvent, WorkflowRun, WorkflowRunStatus, WorkflowSpec, WorkflowStepRun } from "../types.js";
|
|
1
|
+
import type { CreateLoopInput, CreateWorkflowInput, Goal, GoalAutoExecute, GoalPlanNode, GoalRun, GoalStatus, Loop, LoopRun, LoopStatus, RunStatus, WorkflowEvent, WorkflowRun, WorkflowRunStatus, WorkflowSpec, WorkflowStepRun } from "../types.js";
|
|
2
2
|
interface DaemonLeaseFence {
|
|
3
3
|
daemonLeaseId?: string;
|
|
4
4
|
now?: Date;
|
|
@@ -24,6 +24,36 @@ export interface CreateWorkflowRunInput {
|
|
|
24
24
|
idempotencyKey?: string;
|
|
25
25
|
daemonLeaseId?: string;
|
|
26
26
|
}
|
|
27
|
+
export interface CreateGoalInput {
|
|
28
|
+
objective: string;
|
|
29
|
+
tokenBudget?: number;
|
|
30
|
+
autoExecute?: GoalAutoExecute;
|
|
31
|
+
maxTokens?: number;
|
|
32
|
+
sourceType?: string;
|
|
33
|
+
sourceId?: string;
|
|
34
|
+
loopId?: string;
|
|
35
|
+
loopRunId?: string;
|
|
36
|
+
workflowId?: string;
|
|
37
|
+
workflowRunId?: string;
|
|
38
|
+
workflowStepId?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface CreateGoalPlanNodeInput {
|
|
41
|
+
key: string;
|
|
42
|
+
objective: string;
|
|
43
|
+
dependsOn?: string[];
|
|
44
|
+
priority?: number;
|
|
45
|
+
tokenBudget?: number;
|
|
46
|
+
}
|
|
47
|
+
export interface RecordGoalEventInput {
|
|
48
|
+
goalId: string;
|
|
49
|
+
turn?: number;
|
|
50
|
+
phase: GoalRun["phase"];
|
|
51
|
+
status: GoalRun["status"];
|
|
52
|
+
nodeKey?: string;
|
|
53
|
+
tokensUsed?: number;
|
|
54
|
+
evidence?: Record<string, unknown>;
|
|
55
|
+
rawResponse?: unknown;
|
|
56
|
+
}
|
|
27
57
|
export declare class Store {
|
|
28
58
|
private db;
|
|
29
59
|
constructor(path?: string);
|
|
@@ -49,6 +79,33 @@ export declare class Store {
|
|
|
49
79
|
limit?: number;
|
|
50
80
|
}): WorkflowSpec[];
|
|
51
81
|
archiveWorkflow(idOrName: string): WorkflowSpec;
|
|
82
|
+
createGoal(input: CreateGoalInput, opts?: DaemonLeaseFence): Goal;
|
|
83
|
+
getGoal(id: string): Goal | undefined;
|
|
84
|
+
requireGoal(id: string): Goal;
|
|
85
|
+
findGoalByLoop(idOrName: string): Goal | undefined;
|
|
86
|
+
findGoalByRunId(id: string): Goal | undefined;
|
|
87
|
+
findGoalByContext(context: {
|
|
88
|
+
loopRunId?: string;
|
|
89
|
+
workflowRunId?: string;
|
|
90
|
+
workflowStepId?: string;
|
|
91
|
+
sourceType?: string;
|
|
92
|
+
sourceId?: string;
|
|
93
|
+
}): Goal | undefined;
|
|
94
|
+
listGoals(opts?: {
|
|
95
|
+
status?: GoalStatus;
|
|
96
|
+
limit?: number;
|
|
97
|
+
}): Goal[];
|
|
98
|
+
createGoalPlanNodes(goalId: string, nodes: CreateGoalPlanNodeInput[], opts?: DaemonLeaseFence): GoalPlanNode[];
|
|
99
|
+
listGoalPlanNodes(goalIdOrPlanId: string): GoalPlanNode[];
|
|
100
|
+
updateGoalStatus(goalId: string, status: GoalStatus, opts?: DaemonLeaseFence): Goal;
|
|
101
|
+
addGoalUsage(goalId: string, tokens: number, timeUsedSeconds?: number, opts?: DaemonLeaseFence): Goal;
|
|
102
|
+
updateGoalPlanNode(goalId: string, key: string, patch: Partial<Pick<GoalPlanNode, "status" | "tokensUsed" | "timeUsedSeconds" | "ready">>, opts?: DaemonLeaseFence): GoalPlanNode;
|
|
103
|
+
recordGoalEvent(input: RecordGoalEventInput, opts?: DaemonLeaseFence): GoalRun;
|
|
104
|
+
listGoalRuns(opts?: {
|
|
105
|
+
goalId?: string;
|
|
106
|
+
runId?: string;
|
|
107
|
+
limit?: number;
|
|
108
|
+
}): GoalRun[];
|
|
52
109
|
createWorkflowRun(input: CreateWorkflowRunInput): WorkflowRun;
|
|
53
110
|
getWorkflowRun(id: string): WorkflowRun | undefined;
|
|
54
111
|
requireWorkflowRun(id: string): WorkflowRun;
|