neuralbrain 0.0.1 → 0.1.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/.env.example +2 -2
- package/README.md +19 -4
- package/dist/ai/chat.d.ts +1 -2
- package/dist/ai/chat.d.ts.map +1 -1
- package/dist/ai/chat.js +1 -2
- package/dist/ai/chat.js.map +1 -1
- package/dist/ai/config.d.ts +1 -1
- package/dist/ai/config.js +2 -2
- package/dist/ai/config.js.map +1 -1
- package/dist/app.d.ts +1 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +417 -50
- package/dist/app.js.map +1 -1
- package/dist/cli.d.ts +53 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +437 -37
- package/dist/cli.js.map +1 -1
- package/dist/consolidation/candidates.d.ts.map +1 -1
- package/dist/consolidation/candidates.js +19 -4
- package/dist/consolidation/candidates.js.map +1 -1
- package/dist/consolidation/fixtures.js +1 -1
- package/dist/consolidation/fixtures.js.map +1 -1
- package/dist/consolidation/gate.d.ts.map +1 -1
- package/dist/consolidation/gate.js +145 -109
- package/dist/consolidation/gate.js.map +1 -1
- package/dist/consolidation/runner.d.ts +6 -0
- package/dist/consolidation/runner.d.ts.map +1 -1
- package/dist/consolidation/runner.js +22 -2
- package/dist/consolidation/runner.js.map +1 -1
- package/dist/dashboard/clientScript.d.ts +1 -1
- package/dist/dashboard/clientScript.d.ts.map +1 -1
- package/dist/dashboard/clientScript.js +3774 -905
- package/dist/dashboard/clientScript.js.map +1 -1
- package/dist/dashboard/html.d.ts.map +1 -1
- package/dist/dashboard/html.js +605 -101
- package/dist/dashboard/html.js.map +1 -1
- package/dist/dashboard/styles.d.ts +1 -1
- package/dist/dashboard/styles.d.ts.map +1 -1
- package/dist/dashboard/styles.js +1591 -359
- package/dist/dashboard/styles.js.map +1 -1
- package/dist/learning/embedWorker.d.ts +13 -0
- package/dist/learning/embedWorker.d.ts.map +1 -1
- package/dist/learning/embedWorker.js +329 -59
- package/dist/learning/embedWorker.js.map +1 -1
- package/dist/learning/embedding.d.ts +1 -0
- package/dist/learning/embedding.d.ts.map +1 -1
- package/dist/learning/embedding.js +101 -26
- package/dist/learning/embedding.js.map +1 -1
- package/dist/learning/engine.js +1 -1
- package/dist/learning/engine.js.map +1 -1
- package/dist/learning/search.d.ts +17 -1
- package/dist/learning/search.d.ts.map +1 -1
- package/dist/learning/search.js +2094 -354
- package/dist/learning/search.js.map +1 -1
- package/dist/learning/storeMeta.d.ts +9 -0
- package/dist/learning/storeMeta.d.ts.map +1 -1
- package/dist/learning/storeMeta.js +30 -24
- package/dist/learning/storeMeta.js.map +1 -1
- package/dist/learning/types.d.ts +57 -8
- package/dist/learning/types.d.ts.map +1 -1
- package/dist/lib/condenser.d.ts +112 -0
- package/dist/lib/condenser.d.ts.map +1 -0
- package/dist/lib/condenser.js +1337 -0
- package/dist/lib/condenser.js.map +1 -0
- package/dist/lib/db.d.ts +10 -0
- package/dist/lib/db.d.ts.map +1 -1
- package/dist/lib/db.js +654 -167
- package/dist/lib/db.js.map +1 -1
- package/dist/lib/logger.d.ts.map +1 -1
- package/dist/lib/logger.js +3 -2
- package/dist/lib/logger.js.map +1 -1
- package/dist/lib/projectSlug.d.ts +12 -5
- package/dist/lib/projectSlug.d.ts.map +1 -1
- package/dist/lib/projectSlug.js +62 -23
- package/dist/lib/projectSlug.js.map +1 -1
- package/dist/lib/recurrence.d.ts +16 -0
- package/dist/lib/recurrence.d.ts.map +1 -0
- package/dist/lib/recurrence.js +293 -0
- package/dist/lib/recurrence.js.map +1 -0
- package/dist/lib/scope.d.ts +36 -1
- package/dist/lib/scope.d.ts.map +1 -1
- package/dist/lib/scope.js +183 -19
- package/dist/lib/scope.js.map +1 -1
- package/dist/lib/signalTags.d.ts +39 -0
- package/dist/lib/signalTags.d.ts.map +1 -0
- package/dist/lib/signalTags.js +203 -0
- package/dist/lib/signalTags.js.map +1 -0
- package/dist/lib/spool.d.ts +2 -0
- package/dist/lib/spool.d.ts.map +1 -1
- package/dist/lib/spool.js +176 -65
- package/dist/lib/spool.js.map +1 -1
- package/dist/lib/storeDiagnostics.d.ts +41 -0
- package/dist/lib/storeDiagnostics.d.ts.map +1 -0
- package/dist/lib/storeDiagnostics.js +148 -0
- package/dist/lib/storeDiagnostics.js.map +1 -0
- package/dist/lib/temporal.d.ts +44 -0
- package/dist/lib/temporal.d.ts.map +1 -0
- package/dist/lib/temporal.js +1063 -0
- package/dist/lib/temporal.js.map +1 -0
- package/dist/mcp/server.d.ts +93 -3
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +499 -68
- package/dist/mcp/server.js.map +1 -1
- package/dist/memory/actionStore.d.ts +94 -3
- package/dist/memory/actionStore.d.ts.map +1 -1
- package/dist/memory/actionStore.js +412 -124
- package/dist/memory/actionStore.js.map +1 -1
- package/dist/memory/deadLetterStore.d.ts.map +1 -1
- package/dist/memory/deadLetterStore.js +4 -2
- package/dist/memory/deadLetterStore.js.map +1 -1
- package/dist/memory/embedQueueStore.d.ts +19 -8
- package/dist/memory/embedQueueStore.d.ts.map +1 -1
- package/dist/memory/embedQueueStore.js +55 -25
- package/dist/memory/embedQueueStore.js.map +1 -1
- package/dist/memory/failurePatternStore.d.ts +17 -1
- package/dist/memory/failurePatternStore.d.ts.map +1 -1
- package/dist/memory/failurePatternStore.js +54 -31
- package/dist/memory/failurePatternStore.js.map +1 -1
- package/dist/memory/graphStore.d.ts +133 -3
- package/dist/memory/graphStore.d.ts.map +1 -1
- package/dist/memory/graphStore.js +980 -155
- package/dist/memory/graphStore.js.map +1 -1
- package/dist/memory/noteStore.d.ts +27 -2
- package/dist/memory/noteStore.d.ts.map +1 -1
- package/dist/memory/noteStore.js +89 -26
- package/dist/memory/noteStore.js.map +1 -1
- package/dist/memory/observationStore.d.ts +11 -1
- package/dist/memory/observationStore.d.ts.map +1 -1
- package/dist/memory/observationStore.js +90 -15
- package/dist/memory/observationStore.js.map +1 -1
- package/dist/memory/projectRename.d.ts.map +1 -1
- package/dist/memory/projectRename.js +5 -1
- package/dist/memory/projectRename.js.map +1 -1
- package/dist/memory/rollupSweeper.d.ts.map +1 -1
- package/dist/memory/rollupSweeper.js +43 -23
- package/dist/memory/rollupSweeper.js.map +1 -1
- package/dist/memory/sessionStore.d.ts +25 -7
- package/dist/memory/sessionStore.d.ts.map +1 -1
- package/dist/memory/sessionStore.js +145 -33
- package/dist/memory/sessionStore.js.map +1 -1
- package/dist/memory/trajectoryStore.d.ts +8 -0
- package/dist/memory/trajectoryStore.d.ts.map +1 -1
- package/dist/memory/trajectoryStore.js +196 -130
- package/dist/memory/trajectoryStore.js.map +1 -1
- package/dist/middleware/rateLimiter.d.ts.map +1 -1
- package/dist/middleware/rateLimiter.js +24 -1
- package/dist/middleware/rateLimiter.js.map +1 -1
- package/dist/routes/dashboard.d.ts.map +1 -1
- package/dist/routes/dashboard.js +181 -8
- package/dist/routes/dashboard.js.map +1 -1
- package/dist/routes/mcp.d.ts.map +1 -1
- package/dist/routes/mcp.js +173 -21
- package/dist/routes/mcp.js.map +1 -1
- package/dist/routes/memories.js +9 -1
- package/dist/routes/memories.js.map +1 -1
- package/dist/scripts/doctor.d.ts +26 -2
- package/dist/scripts/doctor.d.ts.map +1 -1
- package/dist/scripts/doctor.js +371 -259
- package/dist/scripts/doctor.js.map +1 -1
- package/dist/scripts/installAgent.d.ts.map +1 -1
- package/dist/scripts/installAgent.js +101 -19
- package/dist/scripts/installAgent.js.map +1 -1
- package/dist/scripts/migrateAgentMemory.js +2 -2
- package/dist/scripts/smokeTest.js +1 -1
- package/dist/scripts/smokeTest.js.map +1 -1
- package/docker-compose.yml +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +3 -2
- package/plugin/hooks/postToolUse.js +155 -50
- package/plugin/hooks/sessionStart.js +179 -27
- package/plugin/hooks/sessionStop.js +152 -37
- package/plugin/plugin.json +1 -1
- package/plugin/rules/AGENTS.md +10 -8
- package/plugin/skills/brain-memory/REFERENCE.md +15 -14
- package/plugin/skills/brain-memory/SKILL.md +2 -2
- package/plugin/skills/digest/SKILL.md +1 -1
- package/plugin/skills/handoff/SKILL.md +1 -1
- package/plugin/skills/save/SKILL.md +2 -2
- package/plugin/skills/search/SKILL.md +2 -2
- package/src/ai/chat.ts +1 -2
- package/src/ai/config.ts +2 -2
- package/src/app.ts +475 -54
- package/src/cli.ts +500 -38
- package/src/consolidation/candidates.ts +22 -4
- package/src/consolidation/fixtures.ts +1 -1
- package/src/consolidation/gate.ts +177 -140
- package/src/consolidation/runner.ts +26 -2
- package/src/dashboard/clientScript.ts +3774 -905
- package/src/dashboard/html.ts +605 -101
- package/src/dashboard/styles.ts +1591 -359
- package/src/learning/embedWorker.ts +350 -70
- package/src/learning/embedding.ts +141 -28
- package/src/learning/engine.ts +1 -1
- package/src/learning/search.ts +2533 -397
- package/src/learning/storeMeta.ts +36 -29
- package/src/learning/types.ts +66 -8
- package/src/lib/condenser.ts +1515 -0
- package/src/lib/db.ts +690 -171
- package/src/lib/logger.ts +4 -2
- package/src/lib/projectSlug.ts +77 -23
- package/src/lib/recurrence.ts +382 -0
- package/src/lib/scope.ts +220 -22
- package/src/lib/signalTags.ts +257 -0
- package/src/lib/spool.ts +181 -71
- package/src/lib/storeDiagnostics.ts +181 -0
- package/src/lib/temporal.ts +1250 -0
- package/src/mcp/server.ts +559 -88
- package/src/memory/actionStore.ts +642 -171
- package/src/memory/deadLetterStore.ts +4 -2
- package/src/memory/embedQueueStore.ts +63 -27
- package/src/memory/failurePatternStore.ts +84 -31
- package/src/memory/graphStore.ts +1396 -215
- package/src/memory/noteStore.ts +151 -30
- package/src/memory/observationStore.ts +117 -17
- package/src/memory/projectRename.ts +6 -2
- package/src/memory/rollupSweeper.ts +46 -23
- package/src/memory/sessionStore.ts +197 -38
- package/src/memory/trajectoryStore.ts +260 -140
- package/src/middleware/rateLimiter.ts +24 -1
- package/src/routes/dashboard.ts +194 -9
- package/src/routes/mcp.ts +185 -26
- package/src/routes/memories.ts +8 -1
- package/src/scripts/doctor.ts +461 -262
- package/src/scripts/installAgent.ts +106 -19
- package/src/scripts/migrateAgentMemory.ts +2 -2
- package/src/scripts/smokeTest.ts +1 -1
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ACTION_COLUMNS = void 0;
|
|
3
4
|
exports.createAction = createAction;
|
|
4
5
|
exports.getAction = getAction;
|
|
5
6
|
exports.listActions = listActions;
|
|
7
|
+
exports.getDueActions = getDueActions;
|
|
6
8
|
exports.getReadyActions = getReadyActions;
|
|
7
9
|
exports.updateAction = updateAction;
|
|
10
|
+
exports.checkReminders = checkReminders;
|
|
11
|
+
exports.ackReminders = ackReminders;
|
|
8
12
|
const crypto_1 = require("crypto");
|
|
9
13
|
const db_1 = require("../lib/db");
|
|
14
|
+
const redactSecrets_1 = require("../lib/redactSecrets");
|
|
15
|
+
const recurrence_1 = require("../lib/recurrence");
|
|
10
16
|
const scope_1 = require("../lib/scope");
|
|
17
|
+
const sqlite_1 = require("../lib/sqlite");
|
|
18
|
+
const embedQueueStore_1 = require("./embedQueueStore");
|
|
19
|
+
exports.ACTION_COLUMNS = 'id, session_id, scope, project_id, user_id, agent_id, title, description, status, priority, blocked_reason, files_json, due_at, remind_at, recurrence, last_reminded_at, snooze_until, parent_action_id, created_at, updated_at, resolved_at, resolved_by_session_id';
|
|
11
20
|
const VALID_STATUSES = new Set([
|
|
12
21
|
'ready',
|
|
13
22
|
'blocked',
|
|
@@ -34,11 +43,67 @@ function optionalString(value, field) {
|
|
|
34
43
|
}
|
|
35
44
|
return value.trim() || null;
|
|
36
45
|
}
|
|
46
|
+
function pickField(camel, snake) {
|
|
47
|
+
return camel !== undefined ? camel : snake;
|
|
48
|
+
}
|
|
49
|
+
function normalizeRecurrenceInput(raw) {
|
|
50
|
+
if (raw === undefined || raw === null)
|
|
51
|
+
return null;
|
|
52
|
+
if (typeof raw !== 'string') {
|
|
53
|
+
throw makeSchemaError('recurrence must be a string');
|
|
54
|
+
}
|
|
55
|
+
if (raw.trim() === '')
|
|
56
|
+
return null;
|
|
57
|
+
const validated = (0, recurrence_1.validateRecurrence)(raw);
|
|
58
|
+
if (!validated.ok) {
|
|
59
|
+
throw makeSchemaError(validated.error);
|
|
60
|
+
}
|
|
61
|
+
return validated.normalized;
|
|
62
|
+
}
|
|
63
|
+
function parseValidDate(raw) {
|
|
64
|
+
if (!raw)
|
|
65
|
+
return null;
|
|
66
|
+
const d = new Date(raw);
|
|
67
|
+
return Number.isNaN(d.getTime()) ? null : d;
|
|
68
|
+
}
|
|
69
|
+
const PRIORITY_ORDER_SQL = `
|
|
70
|
+
CASE priority
|
|
71
|
+
WHEN 'urgent' THEN 0
|
|
72
|
+
WHEN 'high' THEN 1
|
|
73
|
+
WHEN 'normal' THEN 2
|
|
74
|
+
WHEN 'low' THEN 3
|
|
75
|
+
ELSE 4
|
|
76
|
+
END ASC
|
|
77
|
+
`;
|
|
78
|
+
function appendScopeAndUserFilters(conditions, params, filters) {
|
|
79
|
+
const projectId = typeof filters?.projectId === 'string' ? filters.projectId.trim() || null : null;
|
|
80
|
+
const includeGlobal = filters?.includeGlobal !== false;
|
|
81
|
+
if (projectId) {
|
|
82
|
+
const scopeSql = (0, scope_1.buildHierarchicalScopeSql)({
|
|
83
|
+
projectId,
|
|
84
|
+
includeAncestors: filters?.includeAncestors ?? true,
|
|
85
|
+
includeChildren: filters?.includeChildren ?? false,
|
|
86
|
+
includeGlobal,
|
|
87
|
+
userId: filters?.userId,
|
|
88
|
+
});
|
|
89
|
+
conditions.push(scopeSql.clause);
|
|
90
|
+
params.push(...scopeSql.params);
|
|
91
|
+
return scopeSql.normalizedProjectId;
|
|
92
|
+
}
|
|
93
|
+
if (filters?.includeGlobal === false) {
|
|
94
|
+
conditions.push("scope != 'global'");
|
|
95
|
+
}
|
|
96
|
+
if (typeof filters?.userId === 'string' && filters.userId.trim() !== '') {
|
|
97
|
+
conditions.push('user_id = ?');
|
|
98
|
+
params.push(filters.userId.trim());
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
37
102
|
/**
|
|
38
103
|
* Create a new next-action record with explicit 3-state scope validation.
|
|
39
104
|
*/
|
|
40
105
|
function createAction(input) {
|
|
41
|
-
const rawProject = input.projectId
|
|
106
|
+
const rawProject = pickField(input.projectId, input.project_id);
|
|
42
107
|
const scoped = (0, scope_1.resolveScope)(input.scope, rawProject);
|
|
43
108
|
if (!scoped.ok) {
|
|
44
109
|
throw makeSchemaError(scoped.error);
|
|
@@ -54,49 +119,52 @@ function createAction(input) {
|
|
|
54
119
|
if (!VALID_PRIORITIES.has(priority)) {
|
|
55
120
|
throw makeSchemaError(`Invalid action priority '${String(priority)}'. Must be one of: low, normal, high, urgent`);
|
|
56
121
|
}
|
|
57
|
-
const db = (0, db_1.getDb)();
|
|
58
122
|
const customId = optionalString(input.id, 'id');
|
|
59
123
|
const id = customId || `act_${(0, crypto_1.randomUUID)().replace(/-/g, '').slice(0, 16)}`;
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const
|
|
124
|
+
const sessionId = optionalString(pickField(input.sessionId, input.session_id), 'session_id');
|
|
125
|
+
const userId = optionalString(pickField(input.userId, input.user_id), 'user_id');
|
|
126
|
+
const agentId = optionalString(pickField(input.agentId, input.agent_id), 'agent_id');
|
|
127
|
+
const title = (0, redactSecrets_1.redactSecrets)(input.title.trim());
|
|
128
|
+
const description = (0, redactSecrets_1.redactOptional)(optionalString(input.description, 'description'));
|
|
129
|
+
const blockedReason = (0, redactSecrets_1.redactOptional)(optionalString(pickField(input.blockedReason, input.blocked_reason), 'blocked_reason'));
|
|
65
130
|
const filesJson = Array.isArray(input.files)
|
|
66
131
|
? JSON.stringify(input.files)
|
|
67
132
|
: input.files_json ?? null;
|
|
133
|
+
const dueAt = (0, recurrence_1.normalizeUtcIso)(pickField(input.dueAt, input.due_at), 'due_at');
|
|
134
|
+
const remindAt = (0, recurrence_1.normalizeUtcIso)(pickField(input.remindAt, input.remind_at), 'remind_at');
|
|
135
|
+
const recurrence = normalizeRecurrenceInput(input.recurrence);
|
|
136
|
+
const lastRemindedAt = (0, recurrence_1.normalizeUtcIso)(pickField(input.lastRemindedAt, input.last_reminded_at), 'last_reminded_at');
|
|
137
|
+
const snoozeUntil = (0, recurrence_1.normalizeUtcIso)(pickField(input.snoozeUntil, input.snooze_until), 'snooze_until');
|
|
138
|
+
const parentActionId = optionalString(pickField(input.parentActionId, input.parent_action_id), 'parent_action_id');
|
|
68
139
|
const isResolved = status === 'done' || status === 'dismissed';
|
|
69
|
-
db.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
140
|
+
const db = (0, db_1.getDb)();
|
|
141
|
+
return (0, sqlite_1.transaction)(db, () => {
|
|
142
|
+
db.prepare(`
|
|
143
|
+
INSERT INTO actions (
|
|
144
|
+
id, session_id, scope, project_id, user_id, agent_id, title, description,
|
|
145
|
+
status, priority, blocked_reason, files_json,
|
|
146
|
+
due_at, remind_at, recurrence, last_reminded_at, snooze_until, parent_action_id,
|
|
147
|
+
resolved_at
|
|
148
|
+
) VALUES (
|
|
149
|
+
?, ?, ?, ?, ?, ?, ?, ?,
|
|
150
|
+
?, ?, ?, ?,
|
|
151
|
+
?, ?, ?, ?, ?, ?,
|
|
152
|
+
CASE WHEN ? = 1 THEN datetime('now') ELSE NULL END
|
|
153
|
+
)
|
|
154
|
+
`).run(id, sessionId, scoped.scope, scoped.projectId, userId, agentId, title, description, status, priority, blockedReason, filesJson, dueAt, remindAt, recurrence, lastRemindedAt, snoozeUntil, parentActionId, isResolved ? 1 : 0);
|
|
155
|
+
(0, embedQueueStore_1.enqueueForEmbedding)(id, 'action');
|
|
156
|
+
return getAction(id);
|
|
157
|
+
})();
|
|
76
158
|
}
|
|
77
159
|
function getAction(id) {
|
|
78
160
|
const db = (0, db_1.getDb)();
|
|
79
|
-
return db.prepare(
|
|
161
|
+
return db.prepare(`SELECT ${exports.ACTION_COLUMNS} FROM actions WHERE id = ?`).get(id);
|
|
80
162
|
}
|
|
81
163
|
function listActions(filters) {
|
|
82
164
|
const db = (0, db_1.getDb)();
|
|
83
165
|
const conditions = [];
|
|
84
166
|
const params = [];
|
|
85
|
-
const
|
|
86
|
-
const includeGlobal = filters?.includeGlobal !== false;
|
|
87
|
-
if (projectId) {
|
|
88
|
-
if (includeGlobal) {
|
|
89
|
-
conditions.push("((project_id = ? AND scope = 'project') OR scope = 'global')");
|
|
90
|
-
params.push(projectId);
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
conditions.push("(project_id = ? AND scope = 'project')");
|
|
94
|
-
params.push(projectId);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
else if (filters?.includeGlobal === false) {
|
|
98
|
-
conditions.push("scope != 'global'");
|
|
99
|
-
}
|
|
167
|
+
const queryProjectId = appendScopeAndUserFilters(conditions, params, filters);
|
|
100
168
|
if (filters?.status) {
|
|
101
169
|
const statuses = Array.isArray(filters.status)
|
|
102
170
|
? filters.status
|
|
@@ -111,129 +179,349 @@ function listActions(filters) {
|
|
|
111
179
|
conditions.push('session_id = ?');
|
|
112
180
|
params.push(filters.sessionId.trim());
|
|
113
181
|
}
|
|
182
|
+
const beforeIso = filters?.before !== undefined ? (0, recurrence_1.normalizeUtcIso)(filters.before, 'before') : null;
|
|
183
|
+
if (filters?.dueOnly === true) {
|
|
184
|
+
const cutoffIso = beforeIso ?? new Date().toISOString();
|
|
185
|
+
conditions.push("status IN ('ready', 'in_progress')");
|
|
186
|
+
conditions.push('((remind_at IS NOT NULL AND remind_at <= ?) OR (due_at IS NOT NULL AND due_at <= ?))');
|
|
187
|
+
params.push(cutoffIso, cutoffIso);
|
|
188
|
+
conditions.push('(snooze_until IS NULL OR snooze_until <= ?)');
|
|
189
|
+
params.push(cutoffIso);
|
|
190
|
+
}
|
|
191
|
+
else if (beforeIso !== null) {
|
|
192
|
+
conditions.push('((due_at IS NOT NULL AND due_at <= ?) OR (remind_at IS NOT NULL AND remind_at <= ?))');
|
|
193
|
+
params.push(beforeIso, beforeIso);
|
|
194
|
+
}
|
|
114
195
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
115
196
|
const limit = filters?.limit ?? 50;
|
|
116
197
|
params.push(limit);
|
|
117
|
-
|
|
198
|
+
const rows = db
|
|
118
199
|
.prepare(`
|
|
119
|
-
SELECT
|
|
200
|
+
SELECT ${exports.ACTION_COLUMNS} FROM actions
|
|
120
201
|
${whereClause}
|
|
121
202
|
ORDER BY
|
|
122
|
-
|
|
123
|
-
WHEN 'urgent' THEN 0
|
|
124
|
-
WHEN 'high' THEN 1
|
|
125
|
-
WHEN 'normal' THEN 2
|
|
126
|
-
WHEN 'low' THEN 3
|
|
127
|
-
ELSE 4
|
|
128
|
-
END ASC,
|
|
203
|
+
${PRIORITY_ORDER_SQL},
|
|
129
204
|
created_at DESC,
|
|
130
205
|
rowid DESC
|
|
131
206
|
LIMIT ?
|
|
132
207
|
`)
|
|
133
208
|
.all(...params);
|
|
209
|
+
return rows.map((row) => ({
|
|
210
|
+
...row,
|
|
211
|
+
match_tier: (0, scope_1.classifyMatchTier)(row.scope, row.project_id, queryProjectId).match_tier,
|
|
212
|
+
}));
|
|
134
213
|
}
|
|
135
214
|
/**
|
|
136
|
-
* Return open ('ready' or 'in_progress')
|
|
215
|
+
* Return due or reminded open actions ('ready' or 'in_progress') not snoozed past cutoff.
|
|
216
|
+
*/
|
|
217
|
+
function getDueActions(filters) {
|
|
218
|
+
const db = (0, db_1.getDb)();
|
|
219
|
+
const conditions = [];
|
|
220
|
+
const params = [];
|
|
221
|
+
const queryProjectId = appendScopeAndUserFilters(conditions, params, filters);
|
|
222
|
+
const nowIso = new Date().toISOString();
|
|
223
|
+
const beforeIso = filters?.before !== undefined ? (0, recurrence_1.normalizeUtcIso)(filters.before, 'before') : null;
|
|
224
|
+
const cutoffIso = beforeIso ?? nowIso;
|
|
225
|
+
conditions.push("status IN ('ready', 'in_progress')");
|
|
226
|
+
conditions.push('((remind_at IS NOT NULL AND remind_at <= ?) OR (due_at IS NOT NULL AND due_at <= ?))');
|
|
227
|
+
params.push(cutoffIso, cutoffIso);
|
|
228
|
+
conditions.push('(snooze_until IS NULL OR snooze_until <= ?)');
|
|
229
|
+
params.push(cutoffIso);
|
|
230
|
+
if (filters?.unremindedOnly === true) {
|
|
231
|
+
if (filters.cooldownMs !== undefined && filters.cooldownMs !== null) {
|
|
232
|
+
if (typeof filters.cooldownMs !== 'number' ||
|
|
233
|
+
!Number.isFinite(filters.cooldownMs) ||
|
|
234
|
+
filters.cooldownMs < 0) {
|
|
235
|
+
throw makeSchemaError('cooldownMs must be a non-negative finite number');
|
|
236
|
+
}
|
|
237
|
+
const cooldownCutoffIso = new Date(Date.now() - filters.cooldownMs).toISOString();
|
|
238
|
+
conditions.push('(last_reminded_at IS NULL OR last_reminded_at <= ?)');
|
|
239
|
+
params.push(cooldownCutoffIso);
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
conditions.push('last_reminded_at IS NULL');
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const whereClause = `WHERE ${conditions.join(' AND ')}`;
|
|
246
|
+
const limit = filters?.limit ?? 50;
|
|
247
|
+
params.push(limit);
|
|
248
|
+
const rows = db
|
|
249
|
+
.prepare(`
|
|
250
|
+
SELECT ${exports.ACTION_COLUMNS} FROM actions
|
|
251
|
+
${whereClause}
|
|
252
|
+
ORDER BY
|
|
253
|
+
COALESCE(remind_at, due_at) ASC,
|
|
254
|
+
${PRIORITY_ORDER_SQL},
|
|
255
|
+
created_at DESC,
|
|
256
|
+
rowid DESC
|
|
257
|
+
LIMIT ?
|
|
258
|
+
`)
|
|
259
|
+
.all(...params);
|
|
260
|
+
return rows.map((row) => ({
|
|
261
|
+
...row,
|
|
262
|
+
match_tier: (0, scope_1.classifyMatchTier)(row.scope, row.project_id, queryProjectId).match_tier,
|
|
263
|
+
overdue: Boolean(row.due_at && row.due_at <= nowIso),
|
|
264
|
+
}));
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Return open ('ready' or 'in_progress') actions for a project (plus ancestors and global by default).
|
|
137
268
|
*/
|
|
138
269
|
function getReadyActions(params) {
|
|
139
270
|
return listActions({
|
|
140
271
|
projectId: params?.projectId,
|
|
141
|
-
|
|
272
|
+
includeAncestors: params?.includeAncestors ?? true,
|
|
273
|
+
includeChildren: params?.includeChildren ?? false,
|
|
274
|
+
includeGlobal: params?.includeGlobal ?? true,
|
|
275
|
+
userId: params?.userId,
|
|
142
276
|
status: ['ready', 'in_progress'],
|
|
143
277
|
limit: params?.limit ?? 10,
|
|
144
278
|
});
|
|
145
279
|
}
|
|
146
280
|
/**
|
|
147
281
|
* Update an action record. Automatically sets resolved_at when status becomes
|
|
148
|
-
* 'done' or 'dismissed',
|
|
282
|
+
* 'done' or 'dismissed', spawns the next occurrence when completing a recurring
|
|
283
|
+
* action, and always updates updated_at inside a single transaction.
|
|
149
284
|
*/
|
|
150
285
|
function updateAction(id, patch) {
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
patch.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
? patch.
|
|
162
|
-
|
|
163
|
-
? patch.
|
|
164
|
-
:
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
286
|
+
const db = (0, db_1.getDb)();
|
|
287
|
+
return (0, sqlite_1.transaction)(db, () => {
|
|
288
|
+
const existing = getAction(id);
|
|
289
|
+
if (!existing)
|
|
290
|
+
return undefined;
|
|
291
|
+
let nextScope = existing.scope;
|
|
292
|
+
let nextProjectId = existing.project_id;
|
|
293
|
+
if (patch.scope !== undefined ||
|
|
294
|
+
patch.projectId !== undefined ||
|
|
295
|
+
patch.project_id !== undefined) {
|
|
296
|
+
const rawScope = patch.scope !== undefined ? patch.scope : existing.scope;
|
|
297
|
+
const rawProject = patch.projectId !== undefined
|
|
298
|
+
? patch.projectId
|
|
299
|
+
: patch.project_id !== undefined
|
|
300
|
+
? patch.project_id
|
|
301
|
+
: existing.project_id;
|
|
302
|
+
const scoped = (0, scope_1.resolveScope)(rawScope, rawProject);
|
|
303
|
+
if (!scoped.ok) {
|
|
304
|
+
throw makeSchemaError(scoped.error);
|
|
305
|
+
}
|
|
306
|
+
nextScope = scoped.scope;
|
|
307
|
+
nextProjectId = scoped.projectId;
|
|
168
308
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (
|
|
175
|
-
|
|
309
|
+
const rawUser = pickField(patch.userId, patch.user_id);
|
|
310
|
+
const nextUserId = rawUser !== undefined ? optionalString(rawUser, 'user_id') : existing.user_id;
|
|
311
|
+
const rawAgent = pickField(patch.agentId, patch.agent_id);
|
|
312
|
+
const nextAgentId = rawAgent !== undefined ? optionalString(rawAgent, 'agent_id') : existing.agent_id;
|
|
313
|
+
let nextTitle = existing.title;
|
|
314
|
+
if (patch.title !== undefined) {
|
|
315
|
+
if (typeof patch.title !== 'string' || patch.title.trim() === '') {
|
|
316
|
+
throw makeSchemaError('title cannot be empty');
|
|
317
|
+
}
|
|
318
|
+
nextTitle = (0, redactSecrets_1.redactSecrets)(patch.title.trim());
|
|
176
319
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
320
|
+
let nextStatus = existing.status;
|
|
321
|
+
if (patch.status !== undefined) {
|
|
322
|
+
if (!VALID_STATUSES.has(patch.status)) {
|
|
323
|
+
throw makeSchemaError(`Invalid action status '${String(patch.status)}'. Must be one of: ready, blocked, in_progress, done, dismissed`);
|
|
324
|
+
}
|
|
325
|
+
nextStatus = patch.status;
|
|
183
326
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
327
|
+
let nextPriority = existing.priority;
|
|
328
|
+
if (patch.priority !== undefined) {
|
|
329
|
+
if (!VALID_PRIORITIES.has(patch.priority)) {
|
|
330
|
+
throw makeSchemaError(`Invalid action priority '${String(patch.priority)}'. Must be one of: low, normal, high, urgent`);
|
|
331
|
+
}
|
|
332
|
+
nextPriority = patch.priority;
|
|
333
|
+
}
|
|
334
|
+
const nextDescription = patch.description !== undefined
|
|
335
|
+
? (0, redactSecrets_1.redactOptional)(optionalString(patch.description, 'description'))
|
|
336
|
+
: existing.description;
|
|
337
|
+
const rawBlockedReason = pickField(patch.blockedReason, patch.blocked_reason);
|
|
338
|
+
const nextBlockedReason = rawBlockedReason !== undefined
|
|
339
|
+
? (0, redactSecrets_1.redactOptional)(optionalString(rawBlockedReason, 'blocked_reason'))
|
|
340
|
+
: existing.blocked_reason;
|
|
341
|
+
const nextFilesJson = Array.isArray(patch.files)
|
|
342
|
+
? JSON.stringify(patch.files)
|
|
343
|
+
: patch.files_json !== undefined
|
|
344
|
+
? optionalString(patch.files_json, 'files_json')
|
|
345
|
+
: existing.files_json;
|
|
346
|
+
const rawDueAt = pickField(patch.dueAt, patch.due_at);
|
|
347
|
+
const nextDueAt = rawDueAt !== undefined ? (0, recurrence_1.normalizeUtcIso)(rawDueAt, 'due_at') : existing.due_at;
|
|
348
|
+
const rawRemindAt = pickField(patch.remindAt, patch.remind_at);
|
|
349
|
+
const nextRemindAt = rawRemindAt !== undefined ? (0, recurrence_1.normalizeUtcIso)(rawRemindAt, 'remind_at') : existing.remind_at;
|
|
350
|
+
const nextRecurrence = patch.recurrence !== undefined
|
|
351
|
+
? normalizeRecurrenceInput(patch.recurrence)
|
|
352
|
+
: existing.recurrence;
|
|
353
|
+
const rawLastRemindedAt = pickField(patch.lastRemindedAt, patch.last_reminded_at);
|
|
354
|
+
const nextLastRemindedAt = rawLastRemindedAt !== undefined
|
|
355
|
+
? (0, recurrence_1.normalizeUtcIso)(rawLastRemindedAt, 'last_reminded_at')
|
|
356
|
+
: existing.last_reminded_at;
|
|
357
|
+
const rawSnoozeUntil = pickField(patch.snoozeUntil, patch.snooze_until);
|
|
358
|
+
const nextSnoozeUntil = rawSnoozeUntil !== undefined
|
|
359
|
+
? (0, recurrence_1.normalizeUtcIso)(rawSnoozeUntil, 'snooze_until')
|
|
360
|
+
: existing.snooze_until;
|
|
361
|
+
const rawParentActionId = pickField(patch.parentActionId, patch.parent_action_id);
|
|
362
|
+
const nextParentActionId = rawParentActionId !== undefined
|
|
363
|
+
? optionalString(rawParentActionId, 'parent_action_id')
|
|
364
|
+
: existing.parent_action_id;
|
|
365
|
+
const rawResolvedBy = pickField(patch.resolvedBySessionId, patch.resolved_by_session_id);
|
|
366
|
+
const nextResolvedBy = rawResolvedBy !== undefined
|
|
367
|
+
? optionalString(rawResolvedBy, 'resolved_by_session_id')
|
|
368
|
+
: existing.resolved_by_session_id;
|
|
369
|
+
const shouldSetResolvedAt = (nextStatus === 'done' || nextStatus === 'dismissed') &&
|
|
370
|
+
existing.status !== 'done' &&
|
|
371
|
+
existing.status !== 'dismissed';
|
|
372
|
+
const shouldClearResolvedAt = nextStatus !== 'done' &&
|
|
373
|
+
nextStatus !== 'dismissed' &&
|
|
374
|
+
(existing.status === 'done' || existing.status === 'dismissed');
|
|
375
|
+
db.prepare(`
|
|
376
|
+
UPDATE actions
|
|
377
|
+
SET scope = ?,
|
|
378
|
+
project_id = ?,
|
|
379
|
+
user_id = ?,
|
|
380
|
+
agent_id = ?,
|
|
381
|
+
title = ?,
|
|
382
|
+
description = ?,
|
|
383
|
+
status = ?,
|
|
384
|
+
priority = ?,
|
|
385
|
+
blocked_reason = ?,
|
|
386
|
+
files_json = ?,
|
|
387
|
+
due_at = ?,
|
|
388
|
+
remind_at = ?,
|
|
389
|
+
recurrence = ?,
|
|
390
|
+
last_reminded_at = ?,
|
|
391
|
+
snooze_until = ?,
|
|
392
|
+
parent_action_id = ?,
|
|
393
|
+
resolved_by_session_id = ?,
|
|
394
|
+
resolved_at = CASE
|
|
395
|
+
WHEN ? = 1 THEN datetime('now')
|
|
396
|
+
WHEN ? = 1 THEN NULL
|
|
397
|
+
ELSE resolved_at
|
|
398
|
+
END,
|
|
399
|
+
updated_at = datetime('now')
|
|
400
|
+
WHERE id = ?
|
|
401
|
+
`).run(nextScope, nextProjectId, nextUserId, nextAgentId, nextTitle, nextDescription, nextStatus, nextPriority, nextBlockedReason, nextFilesJson, nextDueAt, nextRemindAt, nextRecurrence, nextLastRemindedAt, nextSnoozeUntil, nextParentActionId, nextResolvedBy, shouldSetResolvedAt ? 1 : 0, shouldClearResolvedAt ? 1 : 0, id);
|
|
402
|
+
const textOrRankChanged = nextTitle !== existing.title ||
|
|
403
|
+
nextDescription !== existing.description ||
|
|
404
|
+
nextBlockedReason !== existing.blocked_reason ||
|
|
405
|
+
nextStatus !== existing.status ||
|
|
406
|
+
nextPriority !== existing.priority;
|
|
407
|
+
if (textOrRankChanged) {
|
|
408
|
+
(0, embedQueueStore_1.enqueueForEmbedding)(id, 'action');
|
|
409
|
+
}
|
|
410
|
+
let nextOccurrence;
|
|
411
|
+
if (nextStatus === 'done' && existing.status !== 'done' && nextRecurrence) {
|
|
412
|
+
const now = new Date();
|
|
413
|
+
const dueDate = parseValidDate(nextDueAt);
|
|
414
|
+
const remindDate = parseValidDate(nextRemindAt);
|
|
415
|
+
let spawnedDueAt = null;
|
|
416
|
+
let spawnedRemindAt = null;
|
|
417
|
+
if (dueDate && remindDate) {
|
|
418
|
+
const leadMs = dueDate.getTime() - remindDate.getTime();
|
|
419
|
+
const nextDue = (0, recurrence_1.computeNextOccurrence)(nextRecurrence, dueDate);
|
|
420
|
+
spawnedDueAt = nextDue.toISOString();
|
|
421
|
+
spawnedRemindAt = new Date(nextDue.getTime() - leadMs).toISOString();
|
|
422
|
+
}
|
|
423
|
+
else if (dueDate) {
|
|
424
|
+
spawnedDueAt = (0, recurrence_1.computeNextOccurrence)(nextRecurrence, dueDate).toISOString();
|
|
425
|
+
}
|
|
426
|
+
else if (remindDate) {
|
|
427
|
+
spawnedRemindAt = (0, recurrence_1.computeNextOccurrence)(nextRecurrence, remindDate).toISOString();
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
spawnedDueAt = (0, recurrence_1.computeNextOccurrence)(nextRecurrence, now).toISOString();
|
|
431
|
+
}
|
|
432
|
+
const spawnedId = `act_${(0, crypto_1.randomUUID)().replace(/-/g, '').slice(0, 16)}`;
|
|
433
|
+
db.prepare(`
|
|
434
|
+
INSERT INTO actions (
|
|
435
|
+
id, session_id, scope, project_id, user_id, agent_id, title, description,
|
|
436
|
+
status, priority, blocked_reason, files_json,
|
|
437
|
+
due_at, remind_at, recurrence, last_reminded_at, snooze_until, parent_action_id
|
|
438
|
+
) VALUES (
|
|
439
|
+
?, ?, ?, ?, ?, ?, ?, ?,
|
|
440
|
+
'ready', ?, NULL, ?,
|
|
441
|
+
?, ?, ?, NULL, NULL, ?
|
|
442
|
+
)
|
|
443
|
+
`).run(spawnedId, existing.session_id, nextScope, nextProjectId, nextUserId, nextAgentId, nextTitle, nextDescription, nextPriority, nextFilesJson, spawnedDueAt, spawnedRemindAt, nextRecurrence, existing.id);
|
|
444
|
+
(0, embedQueueStore_1.enqueueForEmbedding)(spawnedId, 'action');
|
|
445
|
+
nextOccurrence = getAction(spawnedId);
|
|
446
|
+
}
|
|
447
|
+
const updated = getAction(id);
|
|
448
|
+
return nextOccurrence ? { ...updated, next_occurrence: nextOccurrence } : updated;
|
|
449
|
+
})();
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Evaluate due unreminded actions and, unless dryRun is true, stamp last_reminded_at.
|
|
453
|
+
*/
|
|
454
|
+
function checkReminders(options) {
|
|
455
|
+
const db = (0, db_1.getDb)();
|
|
456
|
+
return (0, sqlite_1.transaction)(db, () => {
|
|
457
|
+
const nowIso = new Date().toISOString();
|
|
458
|
+
const reminders = getDueActions({
|
|
459
|
+
projectId: options?.projectId,
|
|
460
|
+
includeAncestors: options?.includeAncestors,
|
|
461
|
+
includeChildren: options?.includeChildren,
|
|
462
|
+
includeGlobal: options?.includeGlobal,
|
|
463
|
+
userId: options?.userId,
|
|
464
|
+
before: options?.before,
|
|
465
|
+
unremindedOnly: true,
|
|
466
|
+
cooldownMs: options?.cooldownMs,
|
|
467
|
+
limit: options?.limit,
|
|
468
|
+
});
|
|
469
|
+
if (options?.dryRun || reminders.length === 0) {
|
|
470
|
+
return {
|
|
471
|
+
checked_at: nowIso,
|
|
472
|
+
reminders,
|
|
473
|
+
marked_count: 0,
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
const CHUNK_SIZE = 500;
|
|
477
|
+
const ids = reminders.map((r) => r.id);
|
|
478
|
+
let markedCount = 0;
|
|
479
|
+
for (let i = 0; i < ids.length; i += CHUNK_SIZE) {
|
|
480
|
+
const chunk = ids.slice(i, i + CHUNK_SIZE);
|
|
481
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
482
|
+
const res = db
|
|
483
|
+
.prepare(`UPDATE actions SET last_reminded_at = ?, updated_at = datetime('now') WHERE id IN (${placeholders})`)
|
|
484
|
+
.run(nowIso, ...chunk);
|
|
485
|
+
markedCount += res.changes;
|
|
190
486
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
nextStatus !== 'dismissed' &&
|
|
216
|
-
(existing.status === 'done' || existing.status === 'dismissed');
|
|
487
|
+
const stamped = reminders.map((r) => ({
|
|
488
|
+
...r,
|
|
489
|
+
last_reminded_at: nowIso,
|
|
490
|
+
}));
|
|
491
|
+
return {
|
|
492
|
+
checked_at: nowIso,
|
|
493
|
+
reminders: stamped,
|
|
494
|
+
marked_count: markedCount,
|
|
495
|
+
};
|
|
496
|
+
})();
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Acknowledge delivered reminders by stamping last_reminded_at on the specified action IDs.
|
|
500
|
+
*/
|
|
501
|
+
function ackReminders(ids, remindedAt) {
|
|
502
|
+
if (!Array.isArray(ids)) {
|
|
503
|
+
throw makeSchemaError('ids must be an array of action IDs');
|
|
504
|
+
}
|
|
505
|
+
const cleanIds = Array.from(new Set(ids.map((id) => (typeof id === 'string' ? id.trim() : '')).filter(Boolean)));
|
|
506
|
+
const remindedAtIso = (remindedAt !== undefined ? (0, recurrence_1.normalizeUtcIso)(remindedAt, 'reminded_at') : null) ??
|
|
507
|
+
new Date().toISOString();
|
|
508
|
+
if (cleanIds.length === 0) {
|
|
509
|
+
return { updated: 0, reminded_at: remindedAtIso };
|
|
510
|
+
}
|
|
217
511
|
const db = (0, db_1.getDb)();
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
ELSE resolved_at
|
|
233
|
-
END,
|
|
234
|
-
updated_at = datetime('now')
|
|
235
|
-
WHERE id = ?
|
|
236
|
-
`).run(nextScope, nextProjectId, nextTitle, nextDescription, nextStatus, nextPriority, nextBlockedReason, nextFilesJson, nextResolvedBy, shouldSetResolvedAt ? 1 : 0, shouldClearResolvedAt ? 1 : 0, id);
|
|
237
|
-
return getAction(id);
|
|
512
|
+
const updated = (0, sqlite_1.transaction)(db, () => {
|
|
513
|
+
const CHUNK_SIZE = 500;
|
|
514
|
+
let total = 0;
|
|
515
|
+
for (let i = 0; i < cleanIds.length; i += CHUNK_SIZE) {
|
|
516
|
+
const chunk = cleanIds.slice(i, i + CHUNK_SIZE);
|
|
517
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
518
|
+
const res = db
|
|
519
|
+
.prepare(`UPDATE actions SET last_reminded_at = ?, updated_at = datetime('now') WHERE id IN (${placeholders})`)
|
|
520
|
+
.run(remindedAtIso, ...chunk);
|
|
521
|
+
total += res.changes;
|
|
522
|
+
}
|
|
523
|
+
return total;
|
|
524
|
+
})();
|
|
525
|
+
return { updated, reminded_at: remindedAtIso };
|
|
238
526
|
}
|
|
239
527
|
//# sourceMappingURL=actionStore.js.map
|