@hasna/loops 0.4.3 → 0.4.5

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/dist/lib/store.js CHANGED
@@ -1523,7 +1523,7 @@ class Store {
1523
1523
  }
1524
1524
  const applied = new Set(this.db.query("SELECT id FROM schema_migrations").all().map((row) => row.id));
1525
1525
  for (const migration of this.migrations()) {
1526
- if (!migration.baseline && !migration.reapply && applied.has(migration.id))
1526
+ if (!migration.baseline && applied.has(migration.id))
1527
1527
  continue;
1528
1528
  migration.apply();
1529
1529
  if (!applied.has(migration.id)) {
@@ -1576,7 +1576,6 @@ class Store {
1576
1576
  },
1577
1577
  {
1578
1578
  id: "0007_run_claim_tokens",
1579
- reapply: true,
1580
1579
  apply: () => {
1581
1580
  this.addColumnIfMissing("loop_runs", "claim_token", "TEXT");
1582
1581
  this.db.exec("CREATE INDEX IF NOT EXISTS idx_runs_claim_token ON loop_runs(claim_token) WHERE claim_token IS NOT NULL");
@@ -3841,6 +3840,190 @@ class Store {
3841
3840
  const row = status ? this.db.query("SELECT COUNT(*) AS count FROM loop_runs WHERE status = ?").get(status) : this.db.query("SELECT COUNT(*) AS count FROM loop_runs").get();
3842
3841
  return row?.count ?? 0;
3843
3842
  }
3843
+ exportMigrationRows(opts = {}) {
3844
+ const includeRuns = opts.includeRuns ?? true;
3845
+ const workflows = this.db.query("SELECT * FROM workflow_specs ORDER BY created_at ASC, id ASC").all().map(rowToWorkflow);
3846
+ const loops = this.db.query("SELECT * FROM loops ORDER BY created_at ASC, id ASC").all().map(rowToLoop);
3847
+ const runs = includeRuns ? this.db.query("SELECT * FROM loop_runs ORDER BY created_at ASC, id ASC").all().map(rowToRun) : [];
3848
+ return { schemaVersion: SCHEMA_USER_VERSION, workflows, loops, runs, checks: this.migrationChecks() };
3849
+ }
3850
+ countTable(table) {
3851
+ const row = this.db.query(`SELECT COUNT(*) AS count FROM ${table}`).get();
3852
+ return row?.count ?? 0;
3853
+ }
3854
+ migrationChecks() {
3855
+ const now = nowIso();
3856
+ return {
3857
+ unsupportedCounts: {
3858
+ workflowInvocations: this.countTable("workflow_invocations"),
3859
+ workflowWorkItems: this.countTable("workflow_work_items"),
3860
+ workflowRuns: this.countTable("workflow_runs"),
3861
+ workflowStepRuns: this.countTable("workflow_step_runs"),
3862
+ workflowEvents: this.countTable("workflow_events"),
3863
+ goals: this.countTable("goals"),
3864
+ goalPlanNodes: this.countTable("goal_plan_nodes"),
3865
+ goalRuns: this.countTable("goal_runs")
3866
+ },
3867
+ volatileCounts: {
3868
+ daemonLeases: this.countTable("daemon_lease"),
3869
+ activeDaemonLeases: this.db.query("SELECT COUNT(*) AS count FROM daemon_lease WHERE expires_at > ?").get(now)?.count ?? 0,
3870
+ runningLoopRuns: this.db.query("SELECT COUNT(*) AS count FROM loop_runs WHERE status = 'running'").get()?.count ?? 0,
3871
+ runningWorkflowRuns: this.db.query("SELECT COUNT(*) AS count FROM workflow_runs WHERE status = 'running'").get()?.count ?? 0,
3872
+ runningWorkflowStepRuns: this.db.query("SELECT COUNT(*) AS count FROM workflow_step_runs WHERE status = 'running'").get()?.count ?? 0,
3873
+ leasedWorkflowWorkItems: this.db.query("SELECT COUNT(*) AS count FROM workflow_work_items WHERE lease_expires_at IS NOT NULL OR status IN ('admitted', 'running')").get()?.count ?? 0
3874
+ }
3875
+ };
3876
+ }
3877
+ upsertMigrationWorkflow(workflow, opts = {}) {
3878
+ const existing = this.getWorkflow(workflow.id);
3879
+ if (existing && !opts.replace)
3880
+ return existing;
3881
+ this.db.query(`INSERT INTO workflow_specs (id, name, description, version, status, goal_json, steps_json, created_at, updated_at)
3882
+ VALUES ($id, $name, $description, $version, $status, $goal, $steps, $created, $updated)
3883
+ ON CONFLICT(id) DO UPDATE SET
3884
+ name=$name,
3885
+ description=$description,
3886
+ version=$version,
3887
+ status=$status,
3888
+ goal_json=$goal,
3889
+ steps_json=$steps,
3890
+ created_at=$created,
3891
+ updated_at=$updated`).run({
3892
+ $id: workflow.id,
3893
+ $name: workflow.name,
3894
+ $description: workflow.description ?? null,
3895
+ $version: workflow.version,
3896
+ $status: workflow.status,
3897
+ $goal: workflow.goal ? JSON.stringify(workflow.goal) : null,
3898
+ $steps: JSON.stringify(workflow.steps),
3899
+ $created: workflow.createdAt,
3900
+ $updated: workflow.updatedAt
3901
+ });
3902
+ const imported = this.getWorkflow(workflow.id);
3903
+ if (!imported)
3904
+ throw new Error(`workflow not found after migration import: ${workflow.id}`);
3905
+ return imported;
3906
+ }
3907
+ upsertMigrationLoop(loop, opts = {}) {
3908
+ const existing = this.getLoop(loop.id);
3909
+ if (existing && !opts.replace)
3910
+ return existing;
3911
+ this.assertNoNestedWorkflowGoal(loop.target, loop.goal);
3912
+ this.db.query(`INSERT INTO loops (id, name, description, status, archived_at, archived_from_status, schedule_json, target_json,
3913
+ goal_json, machine_json, next_run_at, retry_scheduled_for, catch_up, catch_up_limit, overlap, max_attempts,
3914
+ retry_delay_ms, lease_ms, expires_at, created_at, updated_at)
3915
+ VALUES ($id, $name, $description, $status, $archivedAt, $archivedFromStatus, $schedule, $target,
3916
+ $goal, $machine, $nextRun, $retrySlot, $catchUp, $catchUpLimit, $overlap, $maxAttempts,
3917
+ $retryDelay, $leaseMs, $expiresAt, $created, $updated)
3918
+ ON CONFLICT(id) DO UPDATE SET
3919
+ name=$name,
3920
+ description=$description,
3921
+ status=$status,
3922
+ archived_at=$archivedAt,
3923
+ archived_from_status=$archivedFromStatus,
3924
+ schedule_json=$schedule,
3925
+ target_json=$target,
3926
+ goal_json=$goal,
3927
+ machine_json=$machine,
3928
+ next_run_at=$nextRun,
3929
+ retry_scheduled_for=$retrySlot,
3930
+ catch_up=$catchUp,
3931
+ catch_up_limit=$catchUpLimit,
3932
+ overlap=$overlap,
3933
+ max_attempts=$maxAttempts,
3934
+ retry_delay_ms=$retryDelay,
3935
+ lease_ms=$leaseMs,
3936
+ expires_at=$expiresAt,
3937
+ created_at=$created,
3938
+ updated_at=$updated`).run({
3939
+ $id: loop.id,
3940
+ $name: loop.name,
3941
+ $description: loop.description ?? null,
3942
+ $status: loop.status,
3943
+ $archivedAt: loop.archivedAt ?? null,
3944
+ $archivedFromStatus: loop.archivedFromStatus ?? null,
3945
+ $schedule: JSON.stringify(loop.schedule),
3946
+ $target: JSON.stringify(loop.target),
3947
+ $goal: loop.goal ? JSON.stringify(loop.goal) : null,
3948
+ $machine: loop.machine ? JSON.stringify(loop.machine) : null,
3949
+ $nextRun: loop.nextRunAt ?? null,
3950
+ $retrySlot: loop.retryScheduledFor ?? null,
3951
+ $catchUp: loop.catchUp,
3952
+ $catchUpLimit: loop.catchUpLimit,
3953
+ $overlap: loop.overlap,
3954
+ $maxAttempts: loop.maxAttempts,
3955
+ $retryDelay: loop.retryDelayMs,
3956
+ $leaseMs: loop.leaseMs,
3957
+ $expiresAt: loop.expiresAt ?? null,
3958
+ $created: loop.createdAt,
3959
+ $updated: loop.updatedAt
3960
+ });
3961
+ const imported = this.getLoop(loop.id);
3962
+ if (!imported)
3963
+ throw new Error(`loop not found after migration import: ${loop.id}`);
3964
+ return imported;
3965
+ }
3966
+ upsertMigrationRun(run, opts = {}) {
3967
+ if (run.status === "running")
3968
+ throw new ValidationError(`cannot import running run ${run.id}`);
3969
+ const existing = this.getRun(run.id);
3970
+ if (existing && !opts.replace)
3971
+ return existing;
3972
+ this.db.query(`INSERT INTO loop_runs (id, loop_id, loop_name, scheduled_for, attempt, status, started_at, finished_at,
3973
+ claimed_by, claim_token, lease_expires_at, pid, pgid, process_started_at, exit_code, duration_ms,
3974
+ stdout, stderr, error, goal_run_id, created_at, updated_at)
3975
+ VALUES ($id, $loopId, $loopName, $scheduledFor, $attempt, $status, $startedAt, $finishedAt,
3976
+ $claimedBy, NULL, $leaseExpiresAt, $pid, $pgid, $processStartedAt, $exitCode, $durationMs,
3977
+ $stdout, $stderr, $error, $goalRunId, $created, $updated)
3978
+ ON CONFLICT(id) DO UPDATE SET
3979
+ loop_id=$loopId,
3980
+ loop_name=$loopName,
3981
+ scheduled_for=$scheduledFor,
3982
+ attempt=$attempt,
3983
+ status=$status,
3984
+ started_at=$startedAt,
3985
+ finished_at=$finishedAt,
3986
+ claimed_by=$claimedBy,
3987
+ claim_token=NULL,
3988
+ lease_expires_at=$leaseExpiresAt,
3989
+ pid=$pid,
3990
+ pgid=$pgid,
3991
+ process_started_at=$processStartedAt,
3992
+ exit_code=$exitCode,
3993
+ duration_ms=$durationMs,
3994
+ stdout=$stdout,
3995
+ stderr=$stderr,
3996
+ error=$error,
3997
+ goal_run_id=$goalRunId,
3998
+ created_at=$created,
3999
+ updated_at=$updated`).run({
4000
+ $id: run.id,
4001
+ $loopId: run.loopId,
4002
+ $loopName: run.loopName,
4003
+ $scheduledFor: run.scheduledFor,
4004
+ $attempt: run.attempt,
4005
+ $status: run.status,
4006
+ $startedAt: run.startedAt ?? null,
4007
+ $finishedAt: run.finishedAt ?? null,
4008
+ $claimedBy: run.claimedBy ?? null,
4009
+ $leaseExpiresAt: run.leaseExpiresAt ?? null,
4010
+ $pid: run.pid ?? null,
4011
+ $pgid: run.pgid ?? null,
4012
+ $processStartedAt: run.processStartedAt ?? null,
4013
+ $exitCode: run.exitCode ?? null,
4014
+ $durationMs: run.durationMs ?? null,
4015
+ $stdout: scrubbedOrNull(run.stdout),
4016
+ $stderr: scrubbedOrNull(run.stderr),
4017
+ $error: scrubbedOrNull(run.error),
4018
+ $goalRunId: run.goalRunId ?? null,
4019
+ $created: run.createdAt,
4020
+ $updated: run.updatedAt
4021
+ });
4022
+ const imported = this.getRun(run.id);
4023
+ if (!imported)
4024
+ throw new Error(`run not found after migration import: ${run.id}`);
4025
+ return imported;
4026
+ }
3844
4027
  pruneHistory(opts) {
3845
4028
  const { maxAgeDays, keepPerLoop } = opts;
3846
4029
  if (maxAgeDays === undefined && keepPerLoop === undefined) {
@@ -45,26 +45,24 @@ export declare function verifierIdleTimeoutMs(input: {
45
45
  export declare function verifierRuntimeGuidance(input: {
46
46
  verifierIdleTimeoutMs?: number;
47
47
  }): string;
48
- export declare function todosInspectLine(todosProjectPath: string, taskId: string, todosDbPath?: string): string;
49
- export declare function todosStartLine(todosProjectPath: string, taskId: string, todosDbPath?: string): string;
50
- export declare function todosEvidenceLine(todosProjectPath: string, taskId: string, placeholder: string, todosDbPath?: string): string;
51
- export declare function todosVerificationLine(todosProjectPath: string, taskId: string, todosDbPath?: string): string;
52
- export declare function todosDoneLine(todosProjectPath: string, taskId: string, todosDbPath?: string): string;
48
+ export declare function todosInspectLine(todosProjectPath: string, taskId: string): string;
49
+ export declare function todosStartLine(todosProjectPath: string, taskId: string): string;
50
+ export declare function todosEvidenceLine(todosProjectPath: string, taskId: string, placeholder: string): string;
51
+ export declare function todosVerificationLine(todosProjectPath: string, taskId: string): string;
52
+ export declare function todosDoneLine(todosProjectPath: string, taskId: string): string;
53
53
  /** Exact-todos-commands stanza: project pin, cwd-inference warning, inspect, then role-specific command lines. */
54
- export declare function todosExactCommandsFragment(todosProjectPath: string, taskId: string, commandLines: string[], todosDbPath?: string): string[];
54
+ export declare function todosExactCommandsFragment(todosProjectPath: string, taskId: string, commandLines: string[]): string[];
55
55
  /** Worktree policy PROSE for agent guidance; enforcement is executor-native via target.worktree. */
56
56
  export declare function worktreePrompt(plan: AgentWorktreeSpec): string;
57
57
  export declare function worktreeContextFragment(plan: AgentWorktreeSpec): Record<string, unknown>;
58
58
  export declare function shellQuote(value: string): string;
59
- export declare function todosEnvPrefix(todosDbPath?: string): string;
60
- export declare function sourceTaskGateCommand(todosProjectPath: string, taskId: string, todosDbPath?: string): string;
59
+ export declare function sourceTaskGateCommand(todosProjectPath: string, taskId: string): string;
61
60
  export type LifecycleGateStage = "triage" | "planner";
62
- export declare function lifecycleGateCommand(todosProjectPath: string, taskId: string, stage: LifecycleGateStage, goMarker: string, blockedMarker: string, todosDbPath?: string): string;
61
+ export declare function lifecycleGateCommand(todosProjectPath: string, taskId: string, stage: LifecycleGateStage, goMarker: string, blockedMarker: string): string;
63
62
  export interface PrHandoffCommandOptions {
64
63
  artifactPath: string;
65
64
  taskId: string;
66
65
  todosProjectPath: string;
67
- todosDbPath?: string;
68
66
  worktreeCwd: string;
69
67
  worktreeRoot: string;
70
68
  expectedBranch: string;
@@ -38,7 +38,6 @@ export interface TodosTaskWorkflowTemplateInput extends AgentWorkflowTemplateBas
38
38
  taskTitle?: string;
39
39
  taskDescription?: string;
40
40
  todosProjectPath?: string;
41
- todosDbPath?: string;
42
41
  prHandoff?: boolean;
43
42
  eventId?: string;
44
43
  eventType?: string;
package/dist/mcp/index.js CHANGED
@@ -1525,7 +1525,7 @@ class Store {
1525
1525
  }
1526
1526
  const applied = new Set(this.db.query("SELECT id FROM schema_migrations").all().map((row) => row.id));
1527
1527
  for (const migration of this.migrations()) {
1528
- if (!migration.baseline && !migration.reapply && applied.has(migration.id))
1528
+ if (!migration.baseline && applied.has(migration.id))
1529
1529
  continue;
1530
1530
  migration.apply();
1531
1531
  if (!applied.has(migration.id)) {
@@ -1578,7 +1578,6 @@ class Store {
1578
1578
  },
1579
1579
  {
1580
1580
  id: "0007_run_claim_tokens",
1581
- reapply: true,
1582
1581
  apply: () => {
1583
1582
  this.addColumnIfMissing("loop_runs", "claim_token", "TEXT");
1584
1583
  this.db.exec("CREATE INDEX IF NOT EXISTS idx_runs_claim_token ON loop_runs(claim_token) WHERE claim_token IS NOT NULL");
@@ -3843,6 +3842,190 @@ class Store {
3843
3842
  const row = status ? this.db.query("SELECT COUNT(*) AS count FROM loop_runs WHERE status = ?").get(status) : this.db.query("SELECT COUNT(*) AS count FROM loop_runs").get();
3844
3843
  return row?.count ?? 0;
3845
3844
  }
3845
+ exportMigrationRows(opts = {}) {
3846
+ const includeRuns = opts.includeRuns ?? true;
3847
+ const workflows = this.db.query("SELECT * FROM workflow_specs ORDER BY created_at ASC, id ASC").all().map(rowToWorkflow);
3848
+ const loops = this.db.query("SELECT * FROM loops ORDER BY created_at ASC, id ASC").all().map(rowToLoop);
3849
+ const runs = includeRuns ? this.db.query("SELECT * FROM loop_runs ORDER BY created_at ASC, id ASC").all().map(rowToRun) : [];
3850
+ return { schemaVersion: SCHEMA_USER_VERSION, workflows, loops, runs, checks: this.migrationChecks() };
3851
+ }
3852
+ countTable(table) {
3853
+ const row = this.db.query(`SELECT COUNT(*) AS count FROM ${table}`).get();
3854
+ return row?.count ?? 0;
3855
+ }
3856
+ migrationChecks() {
3857
+ const now = nowIso();
3858
+ return {
3859
+ unsupportedCounts: {
3860
+ workflowInvocations: this.countTable("workflow_invocations"),
3861
+ workflowWorkItems: this.countTable("workflow_work_items"),
3862
+ workflowRuns: this.countTable("workflow_runs"),
3863
+ workflowStepRuns: this.countTable("workflow_step_runs"),
3864
+ workflowEvents: this.countTable("workflow_events"),
3865
+ goals: this.countTable("goals"),
3866
+ goalPlanNodes: this.countTable("goal_plan_nodes"),
3867
+ goalRuns: this.countTable("goal_runs")
3868
+ },
3869
+ volatileCounts: {
3870
+ daemonLeases: this.countTable("daemon_lease"),
3871
+ activeDaemonLeases: this.db.query("SELECT COUNT(*) AS count FROM daemon_lease WHERE expires_at > ?").get(now)?.count ?? 0,
3872
+ runningLoopRuns: this.db.query("SELECT COUNT(*) AS count FROM loop_runs WHERE status = 'running'").get()?.count ?? 0,
3873
+ runningWorkflowRuns: this.db.query("SELECT COUNT(*) AS count FROM workflow_runs WHERE status = 'running'").get()?.count ?? 0,
3874
+ runningWorkflowStepRuns: this.db.query("SELECT COUNT(*) AS count FROM workflow_step_runs WHERE status = 'running'").get()?.count ?? 0,
3875
+ leasedWorkflowWorkItems: this.db.query("SELECT COUNT(*) AS count FROM workflow_work_items WHERE lease_expires_at IS NOT NULL OR status IN ('admitted', 'running')").get()?.count ?? 0
3876
+ }
3877
+ };
3878
+ }
3879
+ upsertMigrationWorkflow(workflow, opts = {}) {
3880
+ const existing = this.getWorkflow(workflow.id);
3881
+ if (existing && !opts.replace)
3882
+ return existing;
3883
+ this.db.query(`INSERT INTO workflow_specs (id, name, description, version, status, goal_json, steps_json, created_at, updated_at)
3884
+ VALUES ($id, $name, $description, $version, $status, $goal, $steps, $created, $updated)
3885
+ ON CONFLICT(id) DO UPDATE SET
3886
+ name=$name,
3887
+ description=$description,
3888
+ version=$version,
3889
+ status=$status,
3890
+ goal_json=$goal,
3891
+ steps_json=$steps,
3892
+ created_at=$created,
3893
+ updated_at=$updated`).run({
3894
+ $id: workflow.id,
3895
+ $name: workflow.name,
3896
+ $description: workflow.description ?? null,
3897
+ $version: workflow.version,
3898
+ $status: workflow.status,
3899
+ $goal: workflow.goal ? JSON.stringify(workflow.goal) : null,
3900
+ $steps: JSON.stringify(workflow.steps),
3901
+ $created: workflow.createdAt,
3902
+ $updated: workflow.updatedAt
3903
+ });
3904
+ const imported = this.getWorkflow(workflow.id);
3905
+ if (!imported)
3906
+ throw new Error(`workflow not found after migration import: ${workflow.id}`);
3907
+ return imported;
3908
+ }
3909
+ upsertMigrationLoop(loop, opts = {}) {
3910
+ const existing = this.getLoop(loop.id);
3911
+ if (existing && !opts.replace)
3912
+ return existing;
3913
+ this.assertNoNestedWorkflowGoal(loop.target, loop.goal);
3914
+ this.db.query(`INSERT INTO loops (id, name, description, status, archived_at, archived_from_status, schedule_json, target_json,
3915
+ goal_json, machine_json, next_run_at, retry_scheduled_for, catch_up, catch_up_limit, overlap, max_attempts,
3916
+ retry_delay_ms, lease_ms, expires_at, created_at, updated_at)
3917
+ VALUES ($id, $name, $description, $status, $archivedAt, $archivedFromStatus, $schedule, $target,
3918
+ $goal, $machine, $nextRun, $retrySlot, $catchUp, $catchUpLimit, $overlap, $maxAttempts,
3919
+ $retryDelay, $leaseMs, $expiresAt, $created, $updated)
3920
+ ON CONFLICT(id) DO UPDATE SET
3921
+ name=$name,
3922
+ description=$description,
3923
+ status=$status,
3924
+ archived_at=$archivedAt,
3925
+ archived_from_status=$archivedFromStatus,
3926
+ schedule_json=$schedule,
3927
+ target_json=$target,
3928
+ goal_json=$goal,
3929
+ machine_json=$machine,
3930
+ next_run_at=$nextRun,
3931
+ retry_scheduled_for=$retrySlot,
3932
+ catch_up=$catchUp,
3933
+ catch_up_limit=$catchUpLimit,
3934
+ overlap=$overlap,
3935
+ max_attempts=$maxAttempts,
3936
+ retry_delay_ms=$retryDelay,
3937
+ lease_ms=$leaseMs,
3938
+ expires_at=$expiresAt,
3939
+ created_at=$created,
3940
+ updated_at=$updated`).run({
3941
+ $id: loop.id,
3942
+ $name: loop.name,
3943
+ $description: loop.description ?? null,
3944
+ $status: loop.status,
3945
+ $archivedAt: loop.archivedAt ?? null,
3946
+ $archivedFromStatus: loop.archivedFromStatus ?? null,
3947
+ $schedule: JSON.stringify(loop.schedule),
3948
+ $target: JSON.stringify(loop.target),
3949
+ $goal: loop.goal ? JSON.stringify(loop.goal) : null,
3950
+ $machine: loop.machine ? JSON.stringify(loop.machine) : null,
3951
+ $nextRun: loop.nextRunAt ?? null,
3952
+ $retrySlot: loop.retryScheduledFor ?? null,
3953
+ $catchUp: loop.catchUp,
3954
+ $catchUpLimit: loop.catchUpLimit,
3955
+ $overlap: loop.overlap,
3956
+ $maxAttempts: loop.maxAttempts,
3957
+ $retryDelay: loop.retryDelayMs,
3958
+ $leaseMs: loop.leaseMs,
3959
+ $expiresAt: loop.expiresAt ?? null,
3960
+ $created: loop.createdAt,
3961
+ $updated: loop.updatedAt
3962
+ });
3963
+ const imported = this.getLoop(loop.id);
3964
+ if (!imported)
3965
+ throw new Error(`loop not found after migration import: ${loop.id}`);
3966
+ return imported;
3967
+ }
3968
+ upsertMigrationRun(run, opts = {}) {
3969
+ if (run.status === "running")
3970
+ throw new ValidationError(`cannot import running run ${run.id}`);
3971
+ const existing = this.getRun(run.id);
3972
+ if (existing && !opts.replace)
3973
+ return existing;
3974
+ this.db.query(`INSERT INTO loop_runs (id, loop_id, loop_name, scheduled_for, attempt, status, started_at, finished_at,
3975
+ claimed_by, claim_token, lease_expires_at, pid, pgid, process_started_at, exit_code, duration_ms,
3976
+ stdout, stderr, error, goal_run_id, created_at, updated_at)
3977
+ VALUES ($id, $loopId, $loopName, $scheduledFor, $attempt, $status, $startedAt, $finishedAt,
3978
+ $claimedBy, NULL, $leaseExpiresAt, $pid, $pgid, $processStartedAt, $exitCode, $durationMs,
3979
+ $stdout, $stderr, $error, $goalRunId, $created, $updated)
3980
+ ON CONFLICT(id) DO UPDATE SET
3981
+ loop_id=$loopId,
3982
+ loop_name=$loopName,
3983
+ scheduled_for=$scheduledFor,
3984
+ attempt=$attempt,
3985
+ status=$status,
3986
+ started_at=$startedAt,
3987
+ finished_at=$finishedAt,
3988
+ claimed_by=$claimedBy,
3989
+ claim_token=NULL,
3990
+ lease_expires_at=$leaseExpiresAt,
3991
+ pid=$pid,
3992
+ pgid=$pgid,
3993
+ process_started_at=$processStartedAt,
3994
+ exit_code=$exitCode,
3995
+ duration_ms=$durationMs,
3996
+ stdout=$stdout,
3997
+ stderr=$stderr,
3998
+ error=$error,
3999
+ goal_run_id=$goalRunId,
4000
+ created_at=$created,
4001
+ updated_at=$updated`).run({
4002
+ $id: run.id,
4003
+ $loopId: run.loopId,
4004
+ $loopName: run.loopName,
4005
+ $scheduledFor: run.scheduledFor,
4006
+ $attempt: run.attempt,
4007
+ $status: run.status,
4008
+ $startedAt: run.startedAt ?? null,
4009
+ $finishedAt: run.finishedAt ?? null,
4010
+ $claimedBy: run.claimedBy ?? null,
4011
+ $leaseExpiresAt: run.leaseExpiresAt ?? null,
4012
+ $pid: run.pid ?? null,
4013
+ $pgid: run.pgid ?? null,
4014
+ $processStartedAt: run.processStartedAt ?? null,
4015
+ $exitCode: run.exitCode ?? null,
4016
+ $durationMs: run.durationMs ?? null,
4017
+ $stdout: scrubbedOrNull(run.stdout),
4018
+ $stderr: scrubbedOrNull(run.stderr),
4019
+ $error: scrubbedOrNull(run.error),
4020
+ $goalRunId: run.goalRunId ?? null,
4021
+ $created: run.createdAt,
4022
+ $updated: run.updatedAt
4023
+ });
4024
+ const imported = this.getRun(run.id);
4025
+ if (!imported)
4026
+ throw new Error(`run not found after migration import: ${run.id}`);
4027
+ return imported;
4028
+ }
3846
4029
  pruneHistory(opts) {
3847
4030
  const { maxAgeDays, keepPerLoop } = opts;
3848
4031
  if (maxAgeDays === undefined && keepPerLoop === undefined) {
@@ -7346,7 +7529,7 @@ async function tick(deps) {
7346
7529
  // package.json
7347
7530
  var package_default = {
7348
7531
  name: "@hasna/loops",
7349
- version: "0.4.3",
7532
+ version: "0.4.5",
7350
7533
  description: "Persistent local loop and workflow runner for deterministic commands and headless AI coding agents",
7351
7534
  type: "module",
7352
7535
  main: "dist/index.js",
@@ -7420,7 +7603,7 @@ var package_default = {
7420
7603
  prepare: "test -d dist || bun run build",
7421
7604
  "dev:cli": "bun run src/cli/index.ts",
7422
7605
  "dev:daemon": "bun run src/daemon/index.ts",
7423
- prepublishOnly: "bun run build && bun run test:boundary"
7606
+ prepublishOnly: "bun run build && bun run typecheck && bun test && bun run test:boundary"
7424
7607
  },
7425
7608
  keywords: [
7426
7609
  "loops",
@@ -3,7 +3,7 @@
3
3
  // package.json
4
4
  var package_default = {
5
5
  name: "@hasna/loops",
6
- version: "0.4.3",
6
+ version: "0.4.5",
7
7
  description: "Persistent local loop and workflow runner for deterministic commands and headless AI coding agents",
8
8
  type: "module",
9
9
  main: "dist/index.js",
@@ -77,7 +77,7 @@ var package_default = {
77
77
  prepare: "test -d dist || bun run build",
78
78
  "dev:cli": "bun run src/cli/index.ts",
79
79
  "dev:daemon": "bun run src/daemon/index.ts",
80
- prepublishOnly: "bun run build && bun run test:boundary"
80
+ prepublishOnly: "bun run build && bun run typecheck && bun test && bun run test:boundary"
81
81
  },
82
82
  keywords: [
83
83
  "loops",
@@ -1,9 +1,12 @@
1
1
  import type { CreateLoopInput, Goal, GoalRun, Loop, LoopRun, LoopStatus, OpenAutomationsRuntimeBinding, RunStatus } from "../types.js";
2
2
  import { type DoctorReport } from "../lib/doctor.js";
3
3
  import { type LoopsHealthReport } from "../lib/health.js";
4
+ import { type ApplyLoopsMigrationResult, type ExportLoopsMigrationOptions, type ImportLoopsMigrationOptions, type LoopsMigrationBundle, type LoopsMigrationPlan, type SelfHostedPlanOptions } from "../lib/migration.js";
4
5
  import { tick } from "../lib/scheduler.js";
5
6
  import { Store } from "../lib/store.js";
6
7
  export { runGoal } from "../lib/goal/runner.js";
8
+ export { LOOPS_MIGRATION_SCHEMA, applyImportMigrationBundle, buildImportMigrationPlan, buildSelfHostedMigrationPlan, exportLoopsMigrationBundle, migrationHash, registerSelfHostedRunner, validateLoopsMigrationBundle, } from "../lib/migration.js";
9
+ export type { ApplyLoopsMigrationResult, ExportLoopsMigrationOptions, ImportLoopsMigrationOptions, LoopsMigrationAction, LoopsMigrationBundle, LoopsMigrationPlan, LoopsMigrationPlanRow, LoopsMigrationPlanSummary, LoopsMigrationResource, RunnerRegistrationOptions, RunnerRegistrationResult, SelfHostedPlanOptions, } from "../lib/migration.js";
7
10
  export interface LoopsClientOptions {
8
11
  store?: Store;
9
12
  /**
@@ -53,6 +56,12 @@ export declare class LoopsClient {
53
56
  };
54
57
  tick(): Promise<Awaited<ReturnType<typeof tick>>>;
55
58
  runNow(idOrName: string): Promise<LoopRun>;
59
+ exportBundle(opts?: ExportLoopsMigrationOptions): LoopsMigrationBundle;
60
+ planImport(bundle: LoopsMigrationBundle, opts?: ImportLoopsMigrationOptions): LoopsMigrationPlan;
61
+ importBundle(bundle: LoopsMigrationBundle, opts?: ImportLoopsMigrationOptions): ApplyLoopsMigrationResult;
62
+ planSelfHostedMigration(opts?: Omit<SelfHostedPlanOptions, "operation"> & {
63
+ operation?: SelfHostedPlanOptions["operation"];
64
+ }): Promise<LoopsMigrationPlan>;
56
65
  close(): void;
57
66
  }
58
67
  export declare function loops(opts?: LoopsClientOptions): LoopsClient;