@hasna/loops 0.1.0 → 0.3.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/README.md +88 -3
- package/dist/cli/index.js +1479 -75
- package/dist/daemon/daemon.d.ts +1 -0
- package/dist/daemon/index.js +1156 -52
- package/dist/daemon/install.d.ts +8 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +1335 -57
- package/dist/lib/accounts.d.ts +4 -0
- package/dist/lib/doctor.d.ts +13 -0
- package/dist/lib/executor.d.ts +20 -1
- package/dist/lib/format.d.ts +5 -1
- package/dist/lib/scheduler.d.ts +12 -0
- package/dist/lib/store.d.ts +47 -2
- package/dist/lib/store.js +627 -6
- package/dist/lib/workflow-runner.d.ts +14 -0
- package/dist/lib/workflow-spec.d.ts +5 -0
- package/dist/sdk/index.js +1126 -57
- package/dist/types.d.ts +88 -2
- package/docs/USAGE.md +89 -4
- package/package.json +2 -2
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AccountRef, AgentProvider } from "../types.js";
|
|
2
|
+
export declare function accountToolForProvider(provider: AgentProvider): string;
|
|
3
|
+
export declare function parseAccountExportLines(output: string): Record<string, string>;
|
|
4
|
+
export declare function resolveAccountEnv(account: AccountRef | undefined, toolHint?: string, env?: NodeJS.ProcessEnv): Record<string, string>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Store } from "./store.js";
|
|
2
|
+
export type DoctorSeverity = "ok" | "warn" | "fail";
|
|
3
|
+
export interface DoctorCheck {
|
|
4
|
+
id: string;
|
|
5
|
+
status: DoctorSeverity;
|
|
6
|
+
message: string;
|
|
7
|
+
detail?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface DoctorReport {
|
|
10
|
+
ok: boolean;
|
|
11
|
+
checks: DoctorCheck[];
|
|
12
|
+
}
|
|
13
|
+
export declare function runDoctor(store: Store): DoctorReport;
|
package/dist/lib/executor.d.ts
CHANGED
|
@@ -1,7 +1,26 @@
|
|
|
1
|
-
import type { ExecutorResult, Loop, LoopRun } from "../types.js";
|
|
1
|
+
import type { ExecutableTarget, ExecutorResult, Loop, LoopRun } from "../types.js";
|
|
2
2
|
export interface ExecuteOptions {
|
|
3
3
|
maxOutputBytes?: number;
|
|
4
4
|
env?: NodeJS.ProcessEnv;
|
|
5
5
|
log?: (message: string) => void;
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
onSpawn?: (pid: number) => void;
|
|
6
8
|
}
|
|
9
|
+
export interface ExecutionMetadata {
|
|
10
|
+
loopId?: string;
|
|
11
|
+
loopName?: string;
|
|
12
|
+
runId?: string;
|
|
13
|
+
scheduledFor?: string;
|
|
14
|
+
workflowId?: string;
|
|
15
|
+
workflowName?: string;
|
|
16
|
+
workflowRunId?: string;
|
|
17
|
+
workflowStepId?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface PreflightResult {
|
|
20
|
+
command: string;
|
|
21
|
+
accountProfile?: string;
|
|
22
|
+
accountTool?: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function preflightTarget(target: ExecutableTarget, metadata?: ExecutionMetadata, opts?: ExecuteOptions): PreflightResult;
|
|
25
|
+
export declare function executeTarget(target: ExecutableTarget, metadata?: ExecutionMetadata, opts?: ExecuteOptions): Promise<ExecutorResult>;
|
|
7
26
|
export declare function executeLoop(loop: Loop, run: LoopRun, opts?: ExecuteOptions): Promise<ExecutorResult>;
|
package/dist/lib/format.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import type { Loop, LoopRun } from "../types.js";
|
|
1
|
+
import type { 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 publicLoop(loop: Loop): Record<string, unknown>;
|
|
4
4
|
export declare function publicRun(run: LoopRun, showOutput?: boolean): Record<string, unknown>;
|
|
5
|
+
export declare function publicWorkflow(workflow: WorkflowSpec): Record<string, unknown>;
|
|
6
|
+
export declare function publicWorkflowRun(run: WorkflowRun): Record<string, unknown>;
|
|
7
|
+
export declare function publicWorkflowStepRun(run: WorkflowStepRun, showOutput?: boolean): Record<string, unknown>;
|
|
8
|
+
export declare function publicWorkflowEvent(event: WorkflowEvent): Record<string, unknown>;
|
package/dist/lib/scheduler.d.ts
CHANGED
|
@@ -15,4 +15,16 @@ export interface TickResult {
|
|
|
15
15
|
recovered: LoopRun[];
|
|
16
16
|
expired: Loop[];
|
|
17
17
|
}
|
|
18
|
+
export declare function manualRunScheduledFor(loop: Loop, now?: Date): string;
|
|
19
|
+
export declare function shouldAdvanceManualRun(loop: Loop, scheduledFor: string, now?: Date): boolean;
|
|
20
|
+
export declare function advanceLoop(store: Store, loop: Loop, run: LoopRun, finishedAt: Date, succeeded: boolean): void;
|
|
21
|
+
export declare function executeClaimedRun(deps: {
|
|
22
|
+
store: Store;
|
|
23
|
+
runnerId: string;
|
|
24
|
+
loop: Loop;
|
|
25
|
+
run: LoopRun;
|
|
26
|
+
now?: () => Date;
|
|
27
|
+
execute?: (loop: Loop, run: LoopRun) => Promise<ExecutorResult>;
|
|
28
|
+
onError?: (loop: Loop, error: unknown) => void;
|
|
29
|
+
}): Promise<LoopRun>;
|
|
18
30
|
export declare function tick(deps: SchedulerDeps): Promise<TickResult>;
|
package/dist/lib/store.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CreateLoopInput, Loop, LoopRun, LoopStatus, RunStatus } from "../types.js";
|
|
1
|
+
import type { CreateLoopInput, CreateWorkflowInput, Loop, LoopRun, LoopStatus, RunStatus, WorkflowEvent, WorkflowRun, WorkflowRunStatus, WorkflowSpec, WorkflowStepRun } from "../types.js";
|
|
2
2
|
export interface DaemonLease {
|
|
3
3
|
id: string;
|
|
4
4
|
pid: number;
|
|
@@ -12,6 +12,13 @@ export interface ClaimRunResult {
|
|
|
12
12
|
run: LoopRun;
|
|
13
13
|
loop: Loop;
|
|
14
14
|
}
|
|
15
|
+
export interface CreateWorkflowRunInput {
|
|
16
|
+
workflow: WorkflowSpec;
|
|
17
|
+
loop?: Loop;
|
|
18
|
+
loopRun?: LoopRun;
|
|
19
|
+
scheduledFor?: string;
|
|
20
|
+
idempotencyKey?: string;
|
|
21
|
+
}
|
|
15
22
|
export declare class Store {
|
|
16
23
|
private db;
|
|
17
24
|
constructor(path?: string);
|
|
@@ -27,12 +34,50 @@ export declare class Store {
|
|
|
27
34
|
dueLoops(now: Date): Loop[];
|
|
28
35
|
updateLoop(id: string, patch: Partial<Pick<Loop, "status" | "nextRunAt" | "retryScheduledFor" | "expiresAt">>): Loop;
|
|
29
36
|
deleteLoop(idOrName: string): boolean;
|
|
37
|
+
createWorkflow(input: CreateWorkflowInput): WorkflowSpec;
|
|
38
|
+
getWorkflow(id: string): WorkflowSpec | undefined;
|
|
39
|
+
findWorkflowByName(name: string): WorkflowSpec | undefined;
|
|
40
|
+
requireWorkflow(idOrName: string): WorkflowSpec;
|
|
41
|
+
listWorkflows(opts?: {
|
|
42
|
+
status?: WorkflowSpec["status"];
|
|
43
|
+
limit?: number;
|
|
44
|
+
}): WorkflowSpec[];
|
|
45
|
+
archiveWorkflow(idOrName: string): WorkflowSpec;
|
|
46
|
+
createWorkflowRun(input: CreateWorkflowRunInput): WorkflowRun;
|
|
47
|
+
getWorkflowRun(id: string): WorkflowRun | undefined;
|
|
48
|
+
requireWorkflowRun(id: string): WorkflowRun;
|
|
49
|
+
listWorkflowRuns(opts?: {
|
|
50
|
+
workflowId?: string;
|
|
51
|
+
loopRunId?: string;
|
|
52
|
+
limit?: number;
|
|
53
|
+
}): WorkflowRun[];
|
|
54
|
+
listWorkflowStepRuns(workflowRunId: string): WorkflowStepRun[];
|
|
55
|
+
getWorkflowStepRun(workflowRunId: string, stepId: string): WorkflowStepRun | undefined;
|
|
56
|
+
isWorkflowRunTerminal(workflowRunId: string): boolean;
|
|
57
|
+
startWorkflowStepRun(workflowRunId: string, stepId: string): WorkflowStepRun;
|
|
58
|
+
markWorkflowStepPid(workflowRunId: string, stepId: string, pid: number): WorkflowStepRun;
|
|
59
|
+
recoverWorkflowRun(workflowRunId: string, reason?: string): {
|
|
60
|
+
run: WorkflowRun;
|
|
61
|
+
recoveredSteps: WorkflowStepRun[];
|
|
62
|
+
};
|
|
63
|
+
finalizeWorkflowStepRun(workflowRunId: string, stepId: string, patch: Pick<WorkflowStepRun, "status" | "finishedAt" | "durationMs" | "stdout" | "stderr"> & Partial<Pick<WorkflowStepRun, "exitCode" | "error">>): WorkflowStepRun;
|
|
64
|
+
skipWorkflowStepRun(workflowRunId: string, stepId: string, reason: string): WorkflowStepRun;
|
|
65
|
+
finalizeWorkflowRun(workflowRunId: string, status: WorkflowRunStatus, patch?: Partial<Pick<WorkflowRun, "finishedAt" | "durationMs" | "error">>): WorkflowRun;
|
|
66
|
+
cancelWorkflowRun(workflowRunId: string, reason?: string): WorkflowRun;
|
|
67
|
+
appendWorkflowEvent(workflowRunId: string, eventType: string, stepId?: string, payload?: Record<string, unknown>): WorkflowEvent;
|
|
68
|
+
listWorkflowEvents(workflowRunId: string, limit?: number): WorkflowEvent[];
|
|
30
69
|
hasRunningRun(loopId: string): boolean;
|
|
70
|
+
markRunPid(id: string, pid: number, claimedBy?: string): LoopRun | undefined;
|
|
71
|
+
private hasLiveWorkflowStepProcesses;
|
|
31
72
|
createSkippedRun(loop: Loop, scheduledFor: string, reason: string): LoopRun;
|
|
32
73
|
getRun(id: string): LoopRun | undefined;
|
|
33
74
|
getRunBySlot(loopId: string, scheduledFor: string): LoopRun | undefined;
|
|
34
75
|
claimRun(loop: Loop, scheduledFor: string, runnerId: string, now?: Date): ClaimRunResult | undefined;
|
|
35
|
-
finalizeRun(id: string, patch: Pick<LoopRun, "status" | "finishedAt" | "durationMs" | "stdout" | "stderr"> & Partial<Pick<LoopRun, "exitCode" | "error" | "pid"
|
|
76
|
+
finalizeRun(id: string, patch: Pick<LoopRun, "status" | "finishedAt" | "durationMs" | "stdout" | "stderr"> & Partial<Pick<LoopRun, "exitCode" | "error" | "pid">>, opts?: {
|
|
77
|
+
claimedBy?: string;
|
|
78
|
+
now?: Date;
|
|
79
|
+
}): LoopRun;
|
|
80
|
+
heartbeatRunLease(id: string, claimedBy: string, leaseMs: number, now?: Date): LoopRun | undefined;
|
|
36
81
|
listRuns(opts?: {
|
|
37
82
|
loopId?: string;
|
|
38
83
|
status?: RunStatus;
|