@hasna/workflows 0.1.0 → 0.1.2
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 +75 -18
- package/dist/agent-tools.js +1937 -1
- package/dist/cli/index.js +2762 -7
- package/dist/handlers.js +96 -1
- package/dist/index.js +2062 -9
- package/dist/mcp/index.js +1994 -16
- package/dist/serve/index.js +1992 -9
- package/dist/service.js +1911 -7
- package/hasna.contract.json +2 -2
- package/package.json +7 -5
- package/types/agent-tools.d.ts +2 -6
- package/types/daemon.d.ts +119 -0
- package/types/expr.d.ts +58 -0
- package/types/graph.d.ts +80 -0
- package/types/handlers.d.ts +1 -5
- package/types/lanes/claude.d.ts +16 -0
- package/types/lanes/codex.d.ts +12 -0
- package/types/lanes/cursor.d.ts +13 -0
- package/types/lanes/grok.d.ts +16 -0
- package/types/lanes/index.d.ts +14 -0
- package/types/lanes/types.d.ts +64 -0
- package/types/render.d.ts +12 -0
- package/types/secrets.d.ts +30 -0
- package/types/service.d.ts +18 -0
- package/types/session.d.ts +51 -0
- package/types/store.d.ts +86 -0
- package/types/wal.d.ts +85 -0
package/types/store.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export declare const RUN_STATUSES: readonly ["pending", "running", "completed", "failed", "cancelled", "interrupted"];
|
|
2
|
+
export type RunStatus = (typeof RUN_STATUSES)[number];
|
|
3
|
+
export declare const NODE_STATUSES: readonly ["pending", "running", "completed", "failed", "skipped"];
|
|
4
|
+
export type NodeStatus = (typeof NODE_STATUSES)[number];
|
|
5
|
+
export interface RunRow {
|
|
6
|
+
id: string;
|
|
7
|
+
graphName: string;
|
|
8
|
+
graphVersion: string;
|
|
9
|
+
status: RunStatus;
|
|
10
|
+
attempts: number;
|
|
11
|
+
contextJson: string;
|
|
12
|
+
resultJson: string | null;
|
|
13
|
+
error: string | null;
|
|
14
|
+
startedAt: string | null;
|
|
15
|
+
finishedAt: string | null;
|
|
16
|
+
createdAt: string;
|
|
17
|
+
updatedAt: string;
|
|
18
|
+
}
|
|
19
|
+
export interface RunNodeRow {
|
|
20
|
+
id: string;
|
|
21
|
+
runId: string;
|
|
22
|
+
nodeId: string;
|
|
23
|
+
status: NodeStatus;
|
|
24
|
+
attempts: number;
|
|
25
|
+
lane: string | null;
|
|
26
|
+
exitCode: number | null;
|
|
27
|
+
outputJson: string | null;
|
|
28
|
+
error: string | null;
|
|
29
|
+
startedAt: string | null;
|
|
30
|
+
finishedAt: string | null;
|
|
31
|
+
}
|
|
32
|
+
export interface MemoRow {
|
|
33
|
+
key: string;
|
|
34
|
+
graphName: string;
|
|
35
|
+
nodeId: string;
|
|
36
|
+
inputHash: string;
|
|
37
|
+
outputJson: string;
|
|
38
|
+
hitCount: number;
|
|
39
|
+
createdAt: string;
|
|
40
|
+
}
|
|
41
|
+
export interface CreateRunInput {
|
|
42
|
+
graphName: string;
|
|
43
|
+
graphVersion: string;
|
|
44
|
+
context?: unknown;
|
|
45
|
+
}
|
|
46
|
+
export interface CreateRunNodeInput {
|
|
47
|
+
runId: string;
|
|
48
|
+
nodeId: string;
|
|
49
|
+
lane?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface WorkflowsStore {
|
|
52
|
+
close(): void;
|
|
53
|
+
listTables(): string[];
|
|
54
|
+
createRun(input: CreateRunInput): RunRow;
|
|
55
|
+
getRun(id: string): RunRow | undefined;
|
|
56
|
+
listRuns(opts?: {
|
|
57
|
+
status?: RunStatus;
|
|
58
|
+
limit?: number;
|
|
59
|
+
}): RunRow[];
|
|
60
|
+
setRunStatus(id: string, status: RunStatus, patch?: {
|
|
61
|
+
result?: unknown;
|
|
62
|
+
error?: string | null;
|
|
63
|
+
startedAt?: string;
|
|
64
|
+
finishedAt?: string;
|
|
65
|
+
}): void;
|
|
66
|
+
/** Persist the run's durable execution state (the engine's cursor + steps). */
|
|
67
|
+
setRunContext(id: string, context: unknown): void;
|
|
68
|
+
bumpAttempts(id: string): void;
|
|
69
|
+
createRunNode(input: CreateRunNodeInput): RunNodeRow;
|
|
70
|
+
getRunNode(id: string): RunNodeRow | undefined;
|
|
71
|
+
listRunNodes(runId: string): RunNodeRow[];
|
|
72
|
+
setRunNodeStatus(id: string, status: NodeStatus, patch?: {
|
|
73
|
+
exitCode?: number | null;
|
|
74
|
+
output?: unknown;
|
|
75
|
+
error?: string | null;
|
|
76
|
+
startedAt?: string;
|
|
77
|
+
finishedAt?: string;
|
|
78
|
+
}): void;
|
|
79
|
+
bumpAttemptsNode(id: string): void;
|
|
80
|
+
memoPut(key: string, graphName: string, nodeId: string, inputHash: string, outputJson: string): void;
|
|
81
|
+
memoGet(key: string): MemoRow | undefined;
|
|
82
|
+
memoHit(key: string): void;
|
|
83
|
+
memoList(): MemoRow[];
|
|
84
|
+
memoClear(): void;
|
|
85
|
+
}
|
|
86
|
+
export declare function openStore(dataDir: string): WorkflowsStore;
|
package/types/wal.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { WorkflowGraph } from "./graph.js";
|
|
2
|
+
export interface ClaimOp {
|
|
3
|
+
op: "claim_acquired";
|
|
4
|
+
runId: string;
|
|
5
|
+
worker: string;
|
|
6
|
+
expiresAt: string;
|
|
7
|
+
fencing: number;
|
|
8
|
+
at: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ReleaseOp {
|
|
11
|
+
op: "claim_released";
|
|
12
|
+
runId: string;
|
|
13
|
+
fencing: number;
|
|
14
|
+
at: string;
|
|
15
|
+
}
|
|
16
|
+
export interface GraphRegisteredOp {
|
|
17
|
+
op: "graph_registered";
|
|
18
|
+
name: string;
|
|
19
|
+
version: string;
|
|
20
|
+
graph: WorkflowGraph;
|
|
21
|
+
at: string;
|
|
22
|
+
}
|
|
23
|
+
export type WalOp = {
|
|
24
|
+
op: "run_started";
|
|
25
|
+
runId: string;
|
|
26
|
+
at: string;
|
|
27
|
+
} | {
|
|
28
|
+
op: "run_finished";
|
|
29
|
+
runId: string;
|
|
30
|
+
status: string;
|
|
31
|
+
at: string;
|
|
32
|
+
} | {
|
|
33
|
+
op: "node_started";
|
|
34
|
+
runId: string;
|
|
35
|
+
nodeId: string;
|
|
36
|
+
at: string;
|
|
37
|
+
} | {
|
|
38
|
+
op: "node_finished";
|
|
39
|
+
runId: string;
|
|
40
|
+
nodeId: string;
|
|
41
|
+
status: string;
|
|
42
|
+
at: string;
|
|
43
|
+
} | {
|
|
44
|
+
op: "memo_set";
|
|
45
|
+
key: string;
|
|
46
|
+
at: string;
|
|
47
|
+
} | GraphRegisteredOp | ClaimOp | ReleaseOp;
|
|
48
|
+
export interface WalEntry {
|
|
49
|
+
seq: number;
|
|
50
|
+
at: string;
|
|
51
|
+
checksum: string;
|
|
52
|
+
op: WalOp;
|
|
53
|
+
}
|
|
54
|
+
export interface LiveClaim {
|
|
55
|
+
worker: string;
|
|
56
|
+
fencing: number;
|
|
57
|
+
expiresAtMs: number;
|
|
58
|
+
}
|
|
59
|
+
export interface WalReplay {
|
|
60
|
+
entries: WalEntry[];
|
|
61
|
+
/** True when the file contained a torn tail (partial or corrupt line). */
|
|
62
|
+
torn: boolean;
|
|
63
|
+
/** True when the torn tail was truncated away. */
|
|
64
|
+
repaired: boolean;
|
|
65
|
+
/** Reconstructed live claims from claim_acquired/claim_released pairs. */
|
|
66
|
+
liveClaims(nowMs?: number): Map<string, LiveClaim>;
|
|
67
|
+
}
|
|
68
|
+
export declare const WAL_FILE_NAME = "session.wal";
|
|
69
|
+
/** The data-dir layout is workflows/ + sessions/ + workflows.db (owner spec):
|
|
70
|
+
* session WALs live under sessions/, workflow graph files under workflows/. */
|
|
71
|
+
export declare const SESSIONS_DIR_NAME = "sessions";
|
|
72
|
+
export declare class SessionWAL {
|
|
73
|
+
readonly filePath: string;
|
|
74
|
+
private constructor();
|
|
75
|
+
static open(dataDir: string): SessionWAL;
|
|
76
|
+
static openAt(filePath: string): SessionWAL;
|
|
77
|
+
/** Append one op and return the persisted entry (seq is 1-based). */
|
|
78
|
+
append(op: WalOp): WalEntry;
|
|
79
|
+
private nextSeq;
|
|
80
|
+
/** Read and verify the whole WAL; truncate the first torn tail. */
|
|
81
|
+
replay(): WalReplay;
|
|
82
|
+
close(): void;
|
|
83
|
+
}
|
|
84
|
+
/** Write a fresh (empty) WAL — used by tests and by init. */
|
|
85
|
+
export declare function resetWal(filePath: string): void;
|