neoagent 3.0.0 → 3.0.1-beta.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.
@@ -91,6 +91,8 @@ function runWithBusyRetry(action, { attempts = 5, delayMs = 50, label = 'SQLite
91
91
  let db = new Database(DB_PATH);
92
92
  db = initializeDatabase(db, DB_PATH);
93
93
 
94
+ const STALE_RUN_INTERRUPTED_ERROR = 'Server restarted while run was in progress.';
95
+
94
96
  db.exec(`
95
97
  CREATE TABLE IF NOT EXISTS users (
96
98
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -441,7 +443,8 @@ db.exec(`
441
443
 
442
444
  CREATE TABLE IF NOT EXISTS skills (
443
445
  id INTEGER PRIMARY KEY AUTOINCREMENT,
444
- name TEXT UNIQUE NOT NULL,
446
+ user_id INTEGER NOT NULL DEFAULT 0,
447
+ name TEXT NOT NULL,
445
448
  description TEXT,
446
449
  file_path TEXT NOT NULL,
447
450
  metadata TEXT DEFAULT '{}',
@@ -1078,6 +1081,57 @@ db.exec(`
1078
1081
 
1079
1082
  runSchemaMigrations(db);
1080
1083
 
1084
+ function interruptStaleAgentRuns(reason = STALE_RUN_INTERRUPTED_ERROR) {
1085
+ const normalizedReason = String(reason || STALE_RUN_INTERRUPTED_ERROR).trim()
1086
+ || STALE_RUN_INTERRUPTED_ERROR;
1087
+ const staleRunIds = db.prepare(
1088
+ `SELECT id
1089
+ FROM agent_runs
1090
+ WHERE status = 'running'`
1091
+ ).all().map((row) => row.id);
1092
+ const runsResult = db.prepare(
1093
+ `UPDATE agent_runs
1094
+ SET status = 'interrupted',
1095
+ error = COALESCE(NULLIF(error, ''), ?),
1096
+ updated_at = datetime('now'),
1097
+ completed_at = COALESCE(completed_at, datetime('now'))
1098
+ WHERE status = 'running'`
1099
+ ).run(normalizedReason);
1100
+
1101
+ db.prepare(
1102
+ `UPDATE agent_steps
1103
+ SET status = 'interrupted',
1104
+ error = COALESCE(NULLIF(error, ''), ?),
1105
+ completed_at = COALESCE(completed_at, datetime('now'))
1106
+ WHERE status = 'running'`
1107
+ ).run(normalizedReason);
1108
+
1109
+ db.prepare(
1110
+ `UPDATE agent_delegations
1111
+ SET status = 'interrupted',
1112
+ error = COALESCE(NULLIF(error, ''), ?),
1113
+ updated_at = datetime('now'),
1114
+ completed_at = COALESCE(completed_at, datetime('now'))
1115
+ WHERE status = 'running'`
1116
+ ).run(normalizedReason);
1117
+
1118
+ if (staleRunIds.length) {
1119
+ const placeholders = staleRunIds.map(() => '?').join(', ');
1120
+ db.prepare(
1121
+ `UPDATE pending_approvals
1122
+ SET status = 'expired',
1123
+ decided_at = COALESCE(decided_at, datetime('now')),
1124
+ updated_at = datetime('now')
1125
+ WHERE status = 'pending'
1126
+ AND run_id IN (${placeholders})`
1127
+ ).run(...staleRunIds);
1128
+ }
1129
+
1130
+ return runsResult.changes || 0;
1131
+ }
1132
+
1133
+ interruptStaleAgentRuns();
1134
+
1081
1135
  try {
1082
1136
  db.exec(`
1083
1137
  CREATE VIRTUAL TABLE IF NOT EXISTS screen_history_fts USING fts5(
@@ -2022,3 +2076,5 @@ try {
2022
2076
  }
2023
2077
 
2024
2078
  module.exports = db;
2079
+ module.exports.STALE_RUN_INTERRUPTED_ERROR = STALE_RUN_INTERRUPTED_ERROR;
2080
+ module.exports.interruptStaleAgentRuns = interruptStaleAgentRuns;
@@ -1 +1 @@
1
- 0aebc22637251b8ff07f20355c6f3771
1
+ 07f0fa2418c3bb652d9c285ad6a55b0f
@@ -37,6 +37,6 @@ _flutter.buildConfig = {"engineRevision":"77e2e94772b6eb43759e34ed1ad7da4674e19c
37
37
 
38
38
  _flutter.loader.load({
39
39
  serviceWorkerSettings: {
40
- serviceWorkerVersion: "4115106509" /* Flutter's service worker is deprecated and will be removed in a future Flutter release. */
40
+ serviceWorkerVersion: "1807031898" /* Flutter's service worker is deprecated and will be removed in a future Flutter release. */
41
41
  }
42
42
  });