@hasna/loops 0.4.1 → 0.4.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 +1 -1
- package/dist/api/index.d.ts +8 -2
- package/dist/api/index.js +961 -4
- package/dist/cli/index.js +458 -96
- package/dist/daemon/index.js +48 -14
- package/dist/index.d.ts +2 -0
- package/dist/index.js +740 -52
- package/dist/lib/format.d.ts +3 -1
- package/dist/lib/mode.js +18 -2
- package/dist/lib/route/todos-cli.d.ts +1 -0
- package/dist/lib/route/types.d.ts +10 -0
- package/dist/lib/storage/contract.d.ts +133 -0
- package/dist/lib/storage/contract.js +1 -0
- package/dist/lib/storage/index.d.ts +6 -0
- package/dist/lib/storage/index.js +4612 -0
- package/dist/lib/storage/postgres-schema.d.ts +4 -0
- package/dist/lib/storage/postgres-schema.js +328 -0
- package/dist/lib/storage/postgres.d.ts +22 -0
- package/dist/lib/storage/postgres.js +423 -0
- package/dist/lib/storage/sqlite.d.ts +84 -0
- package/dist/lib/storage/sqlite.js +4187 -0
- package/dist/lib/store.d.ts +3 -0
- package/dist/lib/store.js +27 -10
- package/dist/lib/template-kit.d.ts +10 -8
- package/dist/lib/templates.d.ts +1 -0
- package/dist/mcp/index.js +48 -14
- package/dist/runner/index.d.ts +23 -0
- package/dist/runner/index.js +1746 -4
- package/dist/sdk/index.js +30 -12
- package/docs/DEPLOYMENT_MODES.md +15 -7
- package/package.json +18 -2
package/dist/lib/format.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ export declare function textOutputBlocks(value: Pick<LoopRun | WorkflowStepRun,
|
|
|
4
4
|
indent?: string;
|
|
5
5
|
}): string[];
|
|
6
6
|
export declare function publicLoop(loop: Loop): Record<string, unknown>;
|
|
7
|
-
export declare function publicRun(run: LoopRun, showOutput?: boolean
|
|
7
|
+
export declare function publicRun(run: LoopRun, showOutput?: boolean, opts?: {
|
|
8
|
+
redactError?: boolean;
|
|
9
|
+
}): Record<string, unknown>;
|
|
8
10
|
export declare function publicExecutorResult(result: ExecutorResult, showOutput?: boolean): Record<string, unknown>;
|
|
9
11
|
export declare function publicWorkflow(workflow: WorkflowSpec): Record<string, unknown>;
|
|
10
12
|
export declare function publicWorkflowRun(run: WorkflowRun): Record<string, unknown>;
|
package/dist/lib/mode.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// package.json
|
|
3
3
|
var package_default = {
|
|
4
4
|
name: "@hasna/loops",
|
|
5
|
-
version: "0.4.
|
|
5
|
+
version: "0.4.2",
|
|
6
6
|
description: "Persistent local loop and workflow runner for deterministic commands and headless AI coding agents",
|
|
7
7
|
type: "module",
|
|
8
8
|
main: "dist/index.js",
|
|
@@ -42,6 +42,22 @@ var package_default = {
|
|
|
42
42
|
"./storage": {
|
|
43
43
|
types: "./dist/lib/store.d.ts",
|
|
44
44
|
import: "./dist/lib/store.js"
|
|
45
|
+
},
|
|
46
|
+
"./storage/contract": {
|
|
47
|
+
types: "./dist/lib/storage/contract.d.ts",
|
|
48
|
+
import: "./dist/lib/storage/contract.js"
|
|
49
|
+
},
|
|
50
|
+
"./storage/sqlite": {
|
|
51
|
+
types: "./dist/lib/storage/sqlite.d.ts",
|
|
52
|
+
import: "./dist/lib/storage/sqlite.js"
|
|
53
|
+
},
|
|
54
|
+
"./storage/postgres": {
|
|
55
|
+
types: "./dist/lib/storage/postgres.d.ts",
|
|
56
|
+
import: "./dist/lib/storage/postgres.js"
|
|
57
|
+
},
|
|
58
|
+
"./storage/postgres-schema": {
|
|
59
|
+
types: "./dist/lib/storage/postgres-schema.d.ts",
|
|
60
|
+
import: "./dist/lib/storage/postgres-schema.js"
|
|
45
61
|
}
|
|
46
62
|
},
|
|
47
63
|
files: [
|
|
@@ -52,7 +68,7 @@ var package_default = {
|
|
|
52
68
|
"LICENSE"
|
|
53
69
|
],
|
|
54
70
|
scripts: {
|
|
55
|
-
build: "rm -rf dist && bun build src/cli/index.ts src/daemon/index.ts src/api/index.ts src/runner/index.ts src/mcp/index.ts src/index.ts src/sdk/index.ts src/lib/store.ts src/lib/mode.ts --root src --outdir dist --target bun --packages external && chmod +x dist/cli/index.js dist/daemon/index.js dist/api/index.js dist/runner/index.js dist/mcp/index.js && tsc -p tsconfig.build.json --emitDeclarationOnly --outDir dist",
|
|
71
|
+
build: "rm -rf dist && bun build src/cli/index.ts src/daemon/index.ts src/api/index.ts src/runner/index.ts src/mcp/index.ts src/index.ts src/sdk/index.ts src/lib/store.ts src/lib/mode.ts src/lib/storage/index.ts src/lib/storage/contract.ts src/lib/storage/sqlite.ts src/lib/storage/postgres.ts src/lib/storage/postgres-schema.ts --root src --outdir dist --target bun --packages external && chmod +x dist/cli/index.js dist/daemon/index.js dist/api/index.js dist/runner/index.js dist/mcp/index.js && tsc -p tsconfig.build.json --emitDeclarationOnly --outDir dist",
|
|
56
72
|
"build:bin": "bun build src/cli/index.ts --compile --outfile dist/loops",
|
|
57
73
|
typecheck: "tsc --noEmit",
|
|
58
74
|
test: "bun test",
|
|
@@ -11,6 +11,7 @@ export declare function runLocalCommand(command: string, args: string[], opts?:
|
|
|
11
11
|
input?: string;
|
|
12
12
|
timeoutMs?: number;
|
|
13
13
|
maxBuffer?: number;
|
|
14
|
+
env?: Record<string, string | undefined>;
|
|
14
15
|
}): LocalCommandResult;
|
|
15
16
|
export declare function runLocalCommandWithStdoutFile(command: string, args: string[], opts?: {
|
|
16
17
|
input?: string;
|
|
@@ -47,6 +47,11 @@ export interface TodosReadyTask {
|
|
|
47
47
|
id?: string;
|
|
48
48
|
task_id?: string;
|
|
49
49
|
taskId?: string;
|
|
50
|
+
source_store_id?: string;
|
|
51
|
+
source_repo_path?: string;
|
|
52
|
+
source_db_path?: string;
|
|
53
|
+
source_task_key?: string;
|
|
54
|
+
source_selected_by_input?: boolean;
|
|
50
55
|
title?: string;
|
|
51
56
|
description?: string;
|
|
52
57
|
body?: string;
|
|
@@ -65,11 +70,16 @@ export interface TodosReadyTask {
|
|
|
65
70
|
task_list?: {
|
|
66
71
|
id?: string;
|
|
67
72
|
slug?: string;
|
|
73
|
+
name?: string;
|
|
68
74
|
};
|
|
69
75
|
[key: string]: unknown;
|
|
70
76
|
}
|
|
71
77
|
export interface TodosDrainOptions extends TodosTaskRouteOptions {
|
|
72
78
|
todosProject?: string;
|
|
79
|
+
todosSourceRoot?: string[];
|
|
80
|
+
todosSourceStore?: string[];
|
|
81
|
+
todosSourceInclude?: string[];
|
|
82
|
+
todosSourceExclude?: string[];
|
|
73
83
|
todosProjectId?: string;
|
|
74
84
|
taskList?: string;
|
|
75
85
|
tags?: string;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { Store } from "../store.js";
|
|
2
|
+
export type LoopStorageBackend = "sqlite" | "postgres";
|
|
3
|
+
export type LoopStorageMethodName = "createLoop" | "getLoop" | "findLoopByName" | "requireLoop" | "listLoops" | "dueLoops" | "updateLoop" | "renameLoop" | "archiveLoop" | "unarchiveLoop" | "deleteLoop" | "createWorkflow" | "getWorkflow" | "listWorkflows" | "countWorkflows" | "archiveWorkflow" | "createWorkflowInvocation" | "getWorkflowInvocation" | "listWorkflowInvocations" | "upsertWorkflowWorkItem" | "getWorkflowWorkItem" | "listWorkflowWorkItems" | "countActiveWorkflowWorkItems" | "admitWorkflowWorkItem" | "createGoal" | "getGoal" | "listGoals" | "createGoalPlanNodes" | "listGoalPlanNodes" | "updateGoalStatus" | "updateGoalPlanNode" | "recordGoalEvent" | "listGoalRuns" | "createWorkflowRun" | "getWorkflowRun" | "listWorkflowRuns" | "listWorkflowStepRuns" | "getWorkflowStepRun" | "startWorkflowStepRun" | "recoverWorkflowRun" | "finalizeWorkflowStepRun" | "finalizeWorkflowRun" | "appendWorkflowEvent" | "listWorkflowEvents" | "recordRunProcess" | "createSkippedRun" | "getRun" | "getRunBySlot" | "claimRun" | "finalizeRun" | "heartbeatRunLease" | "listRuns" | "recoverExpiredRunLeases" | "recoverExpiredRunLeasesDetailed" | "countLoops" | "countRuns" | "pruneHistory" | "acquireDaemonLease" | "heartbeatDaemonLease" | "releaseDaemonLease" | "getDaemonLease";
|
|
4
|
+
type AsyncStoreMethod<K extends LoopStorageMethodName> = Store[K] extends (...args: infer Args) => infer Result ? (...args: Args) => Promise<Result> : never;
|
|
5
|
+
export interface LoopStorageContract extends Record<LoopStorageMethodName, (...args: never[]) => Promise<unknown>> {
|
|
6
|
+
readonly backend: LoopStorageBackend;
|
|
7
|
+
readonly supportsRemoteRunners: boolean;
|
|
8
|
+
close(): Promise<void>;
|
|
9
|
+
createLoop: AsyncStoreMethod<"createLoop">;
|
|
10
|
+
getLoop: AsyncStoreMethod<"getLoop">;
|
|
11
|
+
findLoopByName: AsyncStoreMethod<"findLoopByName">;
|
|
12
|
+
requireLoop: AsyncStoreMethod<"requireLoop">;
|
|
13
|
+
listLoops: AsyncStoreMethod<"listLoops">;
|
|
14
|
+
dueLoops: AsyncStoreMethod<"dueLoops">;
|
|
15
|
+
updateLoop: AsyncStoreMethod<"updateLoop">;
|
|
16
|
+
renameLoop: AsyncStoreMethod<"renameLoop">;
|
|
17
|
+
archiveLoop: AsyncStoreMethod<"archiveLoop">;
|
|
18
|
+
unarchiveLoop: AsyncStoreMethod<"unarchiveLoop">;
|
|
19
|
+
deleteLoop: AsyncStoreMethod<"deleteLoop">;
|
|
20
|
+
createWorkflow: AsyncStoreMethod<"createWorkflow">;
|
|
21
|
+
getWorkflow: AsyncStoreMethod<"getWorkflow">;
|
|
22
|
+
listWorkflows: AsyncStoreMethod<"listWorkflows">;
|
|
23
|
+
countWorkflows: AsyncStoreMethod<"countWorkflows">;
|
|
24
|
+
archiveWorkflow: AsyncStoreMethod<"archiveWorkflow">;
|
|
25
|
+
createWorkflowInvocation: AsyncStoreMethod<"createWorkflowInvocation">;
|
|
26
|
+
getWorkflowInvocation: AsyncStoreMethod<"getWorkflowInvocation">;
|
|
27
|
+
listWorkflowInvocations: AsyncStoreMethod<"listWorkflowInvocations">;
|
|
28
|
+
upsertWorkflowWorkItem: AsyncStoreMethod<"upsertWorkflowWorkItem">;
|
|
29
|
+
getWorkflowWorkItem: AsyncStoreMethod<"getWorkflowWorkItem">;
|
|
30
|
+
listWorkflowWorkItems: AsyncStoreMethod<"listWorkflowWorkItems">;
|
|
31
|
+
countActiveWorkflowWorkItems: AsyncStoreMethod<"countActiveWorkflowWorkItems">;
|
|
32
|
+
admitWorkflowWorkItem: AsyncStoreMethod<"admitWorkflowWorkItem">;
|
|
33
|
+
createGoal: AsyncStoreMethod<"createGoal">;
|
|
34
|
+
getGoal: AsyncStoreMethod<"getGoal">;
|
|
35
|
+
listGoals: AsyncStoreMethod<"listGoals">;
|
|
36
|
+
createGoalPlanNodes: AsyncStoreMethod<"createGoalPlanNodes">;
|
|
37
|
+
listGoalPlanNodes: AsyncStoreMethod<"listGoalPlanNodes">;
|
|
38
|
+
updateGoalStatus: AsyncStoreMethod<"updateGoalStatus">;
|
|
39
|
+
updateGoalPlanNode: AsyncStoreMethod<"updateGoalPlanNode">;
|
|
40
|
+
recordGoalEvent: AsyncStoreMethod<"recordGoalEvent">;
|
|
41
|
+
listGoalRuns: AsyncStoreMethod<"listGoalRuns">;
|
|
42
|
+
createWorkflowRun: AsyncStoreMethod<"createWorkflowRun">;
|
|
43
|
+
getWorkflowRun: AsyncStoreMethod<"getWorkflowRun">;
|
|
44
|
+
listWorkflowRuns: AsyncStoreMethod<"listWorkflowRuns">;
|
|
45
|
+
listWorkflowStepRuns: AsyncStoreMethod<"listWorkflowStepRuns">;
|
|
46
|
+
getWorkflowStepRun: AsyncStoreMethod<"getWorkflowStepRun">;
|
|
47
|
+
startWorkflowStepRun: AsyncStoreMethod<"startWorkflowStepRun">;
|
|
48
|
+
recoverWorkflowRun: AsyncStoreMethod<"recoverWorkflowRun">;
|
|
49
|
+
finalizeWorkflowStepRun: AsyncStoreMethod<"finalizeWorkflowStepRun">;
|
|
50
|
+
finalizeWorkflowRun: AsyncStoreMethod<"finalizeWorkflowRun">;
|
|
51
|
+
appendWorkflowEvent: AsyncStoreMethod<"appendWorkflowEvent">;
|
|
52
|
+
listWorkflowEvents: AsyncStoreMethod<"listWorkflowEvents">;
|
|
53
|
+
recordRunProcess: AsyncStoreMethod<"recordRunProcess">;
|
|
54
|
+
createSkippedRun: AsyncStoreMethod<"createSkippedRun">;
|
|
55
|
+
getRun: AsyncStoreMethod<"getRun">;
|
|
56
|
+
getRunBySlot: AsyncStoreMethod<"getRunBySlot">;
|
|
57
|
+
claimRun: AsyncStoreMethod<"claimRun">;
|
|
58
|
+
finalizeRun: AsyncStoreMethod<"finalizeRun">;
|
|
59
|
+
heartbeatRunLease: AsyncStoreMethod<"heartbeatRunLease">;
|
|
60
|
+
listRuns: AsyncStoreMethod<"listRuns">;
|
|
61
|
+
recoverExpiredRunLeases: AsyncStoreMethod<"recoverExpiredRunLeases">;
|
|
62
|
+
recoverExpiredRunLeasesDetailed: AsyncStoreMethod<"recoverExpiredRunLeasesDetailed">;
|
|
63
|
+
countLoops: AsyncStoreMethod<"countLoops">;
|
|
64
|
+
countRuns: AsyncStoreMethod<"countRuns">;
|
|
65
|
+
pruneHistory: AsyncStoreMethod<"pruneHistory">;
|
|
66
|
+
acquireDaemonLease: AsyncStoreMethod<"acquireDaemonLease">;
|
|
67
|
+
heartbeatDaemonLease: AsyncStoreMethod<"heartbeatDaemonLease">;
|
|
68
|
+
releaseDaemonLease: AsyncStoreMethod<"releaseDaemonLease">;
|
|
69
|
+
getDaemonLease: AsyncStoreMethod<"getDaemonLease">;
|
|
70
|
+
}
|
|
71
|
+
export interface StorageMigration {
|
|
72
|
+
readonly id: string;
|
|
73
|
+
readonly checksum: string;
|
|
74
|
+
readonly sql: string;
|
|
75
|
+
}
|
|
76
|
+
export interface AppliedStorageMigration {
|
|
77
|
+
readonly id: string;
|
|
78
|
+
readonly checksum: string;
|
|
79
|
+
readonly appliedAt: string;
|
|
80
|
+
}
|
|
81
|
+
export interface StorageMigrationPlanItem {
|
|
82
|
+
readonly migration: StorageMigration;
|
|
83
|
+
readonly state: "already_applied" | "pending";
|
|
84
|
+
}
|
|
85
|
+
export interface StorageMigrationResult {
|
|
86
|
+
readonly backend: LoopStorageBackend;
|
|
87
|
+
readonly dryRun: boolean;
|
|
88
|
+
readonly applied: AppliedStorageMigration[];
|
|
89
|
+
readonly plan: StorageMigrationPlanItem[];
|
|
90
|
+
}
|
|
91
|
+
export interface SchemaMigrationStorage {
|
|
92
|
+
readonly backend: LoopStorageBackend;
|
|
93
|
+
readonly migrations: readonly StorageMigration[];
|
|
94
|
+
listAppliedMigrations(): Promise<AppliedStorageMigration[]>;
|
|
95
|
+
migrate(opts?: {
|
|
96
|
+
dryRun?: boolean;
|
|
97
|
+
}): Promise<StorageMigrationResult>;
|
|
98
|
+
close(): Promise<void>;
|
|
99
|
+
}
|
|
100
|
+
export type RunnerMachineStatus = "active" | "draining" | "offline";
|
|
101
|
+
export type RunnerLeaseStatus = "active" | "released" | "expired" | "stolen";
|
|
102
|
+
export interface RunnerMachineRecord {
|
|
103
|
+
id: string;
|
|
104
|
+
hostname: string;
|
|
105
|
+
labels: Record<string, string>;
|
|
106
|
+
capabilities: Record<string, unknown>;
|
|
107
|
+
status: RunnerMachineStatus;
|
|
108
|
+
lastSeenAt: string;
|
|
109
|
+
createdAt: string;
|
|
110
|
+
updatedAt: string;
|
|
111
|
+
}
|
|
112
|
+
export interface RunnerLeaseRecord {
|
|
113
|
+
id: string;
|
|
114
|
+
runnerId: string;
|
|
115
|
+
loopRunId?: string;
|
|
116
|
+
workflowRunId?: string;
|
|
117
|
+
claimToken: string;
|
|
118
|
+
status: RunnerLeaseStatus;
|
|
119
|
+
heartbeatAt: string;
|
|
120
|
+
expiresAt: string;
|
|
121
|
+
createdAt: string;
|
|
122
|
+
updatedAt: string;
|
|
123
|
+
}
|
|
124
|
+
export interface AuditEventRecord {
|
|
125
|
+
id: string;
|
|
126
|
+
actor: string;
|
|
127
|
+
action: string;
|
|
128
|
+
subjectType: string;
|
|
129
|
+
subjectId: string;
|
|
130
|
+
metadata?: Record<string, unknown>;
|
|
131
|
+
createdAt: string;
|
|
132
|
+
}
|
|
133
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// @bun
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { AppliedStorageMigration, AuditEventRecord, LoopStorageBackend, LoopStorageContract, LoopStorageMethodName, RunnerLeaseRecord, RunnerLeaseStatus, RunnerMachineRecord, RunnerMachineStatus, SchemaMigrationStorage, StorageMigration, StorageMigrationPlanItem, StorageMigrationResult, } from "./contract.js";
|
|
2
|
+
export { SqliteLoopStorage, createSqliteLoopStorage } from "./sqlite.js";
|
|
3
|
+
export { PostgresStorage, createPostgresStorage } from "./postgres.js";
|
|
4
|
+
export type { PostgresQueryExecutor } from "./postgres.js";
|
|
5
|
+
export { POSTGRES_MIGRATION_LEDGER_TABLE, POSTGRES_STORAGE_MIGRATIONS, checksumStorageSql, } from "./postgres-schema.js";
|
|
6
|
+
export { Store } from "../store.js";
|