botnote 0.2.16 → 0.2.18
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 +24 -504
- package/dist/bin.js +16 -9
- package/dist/bin.js.map +1 -1
- package/dist/config.d.ts +0 -4
- package/dist/config.js +0 -31
- package/dist/config.js.map +1 -1
- package/dist/mcp/server.js +1 -1
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/stdio.d.ts +8 -0
- package/dist/mcp/stdio.js +46 -0
- package/dist/mcp/stdio.js.map +1 -0
- package/package.json +8 -40
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -186
- package/dist/cli.js.map +0 -1
- package/dist/db/client.d.ts +0 -14
- package/dist/db/client.js +0 -16
- package/dist/db/client.js.map +0 -1
- package/dist/db/migrate.d.ts +0 -1
- package/dist/db/migrate.js +0 -57
- package/dist/db/migrate.js.map +0 -1
- package/dist/db/migrations/0001_init.sql +0 -89
- package/dist/db/migrations/0002_tasks_due_at.sql +0 -16
- package/dist/db/migrations/0003_task_priority_and_sequence.sql +0 -45
- package/dist/db/migrations/0004_pinned.sql +0 -8
- package/dist/db/migrations/0005_nullable_title_and_parent.sql +0 -5
- package/dist/db/migrations/0006_project_color_icon.sql +0 -3
- package/dist/db/migrations/0007_tokens.sql +0 -14
- package/dist/db/migrations/0008_simplify_kinds_drop_actors.sql +0 -21
- package/dist/db/migrations/0009_sessions.sql +0 -14
- package/dist/db/migrations/0010_completed_at.sql +0 -17
- package/dist/db/migrations/0011_completed_at_backfill_fix.sql +0 -14
- package/dist/db/migrations/0012_completed_at_backfill_due.sql +0 -16
- package/dist/db/migrations/0013_due_at_noon_utc.sql +0 -13
- package/dist/db/migrations/0014_recoverable_api_tokens.sql +0 -3
- package/dist/db/migrations/0015_collapse_delayed_archived_statuses.sql +0 -18
- package/dist/db/migrations/0016_embedding_settings.sql +0 -23
- package/dist/db/migrations/0017_recurrence_rules.sql +0 -55
- package/dist/db/migrations/0018_project_archived_at.sql +0 -8
- package/dist/db/migrations/0019_project_status.sql +0 -20
- package/dist/db/migrations/0020_project_archived_status.sql +0 -20
- package/dist/db/migrations/0021_workspace_settings.sql +0 -18
- package/dist/db/migrations/0022_recurrence_split.sql +0 -13
- package/dist/db/migrations/0023_comment_kind.sql +0 -24
- package/dist/db/migrations/0024_memory_access.sql +0 -12
- package/dist/db/migrations/0025_soft_delete.sql +0 -12
- package/dist/db/migrations/0026_sequence_counter.sql +0 -61
- package/dist/db/migrations/0027_self_parent_repair.sql +0 -10
- package/dist/db/migrations/0028_workspaces.sql +0 -65
- package/dist/db/migrations/0029_drop_global_uniques.sql +0 -38
- package/dist/db/migrations/0030_entity_actor_token.sql +0 -12
- package/dist/db/migrations/0031_entity_revisions.sql +0 -19
- package/dist/db/migrations/0032_touch_respects_explicit_updated_at.sql +0 -18
- package/dist/db/migrations/0033_worklog_kind.sql +0 -42
- package/dist/db/schema.d.ts +0 -2023
- package/dist/db/schema.js +0 -245
- package/dist/db/schema.js.map +0 -1
- package/dist/rest/attribution.d.ts +0 -22
- package/dist/rest/attribution.js +0 -62
- package/dist/rest/attribution.js.map +0 -1
- package/dist/rest/auth.d.ts +0 -47
- package/dist/rest/auth.js +0 -116
- package/dist/rest/auth.js.map +0 -1
- package/dist/rest/routes.d.ts +0 -3
- package/dist/rest/routes.js +0 -844
- package/dist/rest/routes.js.map +0 -1
- package/dist/rest/server.d.ts +0 -28
- package/dist/rest/server.js +0 -276
- package/dist/rest/server.js.map +0 -1
- package/dist/service/blockers.d.ts +0 -37
- package/dist/service/blockers.js +0 -46
- package/dist/service/blockers.js.map +0 -1
- package/dist/service/dates.d.ts +0 -19
- package/dist/service/dates.js +0 -52
- package/dist/service/dates.js.map +0 -1
- package/dist/service/embedding.d.ts +0 -75
- package/dist/service/embedding.js +0 -318
- package/dist/service/embedding.js.map +0 -1
- package/dist/service/embedding_settings.d.ts +0 -16
- package/dist/service/embedding_settings.js +0 -82
- package/dist/service/embedding_settings.js.map +0 -1
- package/dist/service/entities.d.ts +0 -96
- package/dist/service/entities.js +0 -628
- package/dist/service/entities.js.map +0 -1
- package/dist/service/feedback.d.ts +0 -13
- package/dist/service/feedback.js +0 -50
- package/dist/service/feedback.js.map +0 -1
- package/dist/service/hierarchy.d.ts +0 -31
- package/dist/service/hierarchy.js +0 -76
- package/dist/service/hierarchy.js.map +0 -1
- package/dist/service/index.d.ts +0 -10
- package/dist/service/index.js +0 -10
- package/dist/service/index.js.map +0 -1
- package/dist/service/locks.d.ts +0 -25
- package/dist/service/locks.js +0 -34
- package/dist/service/locks.js.map +0 -1
- package/dist/service/opening_brief.d.ts +0 -24
- package/dist/service/opening_brief.js +0 -210
- package/dist/service/opening_brief.js.map +0 -1
- package/dist/service/projects.d.ts +0 -9
- package/dist/service/projects.js +0 -59
- package/dist/service/projects.js.map +0 -1
- package/dist/service/recurrence.d.ts +0 -93
- package/dist/service/recurrence.js +0 -799
- package/dist/service/recurrence.js.map +0 -1
- package/dist/service/revisions.d.ts +0 -31
- package/dist/service/revisions.js +0 -53
- package/dist/service/revisions.js.map +0 -1
- package/dist/service/scope.d.ts +0 -14
- package/dist/service/scope.js +0 -19
- package/dist/service/scope.js.map +0 -1
- package/dist/service/search.d.ts +0 -34
- package/dist/service/search.js +0 -198
- package/dist/service/search.js.map +0 -1
- package/dist/service/sessions.d.ts +0 -24
- package/dist/service/sessions.js +0 -89
- package/dist/service/sessions.js.map +0 -1
- package/dist/service/tasks.d.ts +0 -48
- package/dist/service/tasks.js +0 -354
- package/dist/service/tasks.js.map +0 -1
- package/dist/service/tokens.d.ts +0 -21
- package/dist/service/tokens.js +0 -71
- package/dist/service/tokens.js.map +0 -1
- package/dist/service/transfer.d.ts +0 -64
- package/dist/service/transfer.js +0 -629
- package/dist/service/transfer.js.map +0 -1
- package/dist/service/types.d.ts +0 -772
- package/dist/service/types.js +0 -274
- package/dist/service/types.js.map +0 -1
- package/dist/service/workspace_settings.d.ts +0 -9
- package/dist/service/workspace_settings.js +0 -49
- package/dist/service/workspace_settings.js.map +0 -1
- package/web/dist/assets/index-C0u0ZrR4.css +0 -1
- package/web/dist/assets/index-sCiJNYQ3.js +0 -235
- package/web/dist/favicon.svg +0 -13
- package/web/dist/index.html +0 -22
package/dist/service/tasks.js
DELETED
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
import { and, asc, desc, eq, gte, inArray, isNotNull, isNull, lt, lte, ne, or, sql } from "drizzle-orm";
|
|
2
|
-
import { entities, recurrenceExceptions, recurrenceRules } from "../db/schema.js";
|
|
3
|
-
import { blockersFor } from "./blockers.js";
|
|
4
|
-
import { hierarchyFor } from "./hierarchy.js";
|
|
5
|
-
import { buildRRule, normalizeOccurrenceDueAt } from "./recurrence.js";
|
|
6
|
-
/**
|
|
7
|
-
* Tasks in a date range, split into scheduled / overdue / backlog buckets.
|
|
8
|
-
* Pure read: recurring occurrences are materialized by the daemon scheduler
|
|
9
|
-
* (startup pass + interval), never from this path, so concurrent polls from
|
|
10
|
-
* several UI tabs and agents cannot race on rule advancement.
|
|
11
|
-
*
|
|
12
|
-
* Each task has a "display date" that decides where it lands on the calendar:
|
|
13
|
-
* - status='done' → completedAt (when actually finished)
|
|
14
|
-
* - status='in_progress' → today (rolling — surfaces active work)
|
|
15
|
-
* - everything else → dueAt (when it's supposed to happen)
|
|
16
|
-
*
|
|
17
|
-
* `scheduled` returns any task whose display date falls inside [from, to).
|
|
18
|
-
* Done tasks without a completedAt (legacy / weird state) fall back to updatedAt.
|
|
19
|
-
* `overdue` is every unfinished task (open or in_progress) due before the
|
|
20
|
-
* requested range start, or before now when no range start is supplied.
|
|
21
|
-
*
|
|
22
|
-
* The buckets are disjoint: a task lands in exactly one of overdue, scheduled
|
|
23
|
-
* or backlog. Overdue wins over scheduled, and undated in_progress work sits
|
|
24
|
-
* in backlog when backlog is requested, otherwise on today.
|
|
25
|
-
*/
|
|
26
|
-
export async function tasksRange(scope, db, input) {
|
|
27
|
-
const now = new Date();
|
|
28
|
-
const inWorkspace = eq(entities.workspaceId, scope.workspaceId);
|
|
29
|
-
const projectFilter = input.projectIds?.length
|
|
30
|
-
? inArray(entities.projectId, input.projectIds)
|
|
31
|
-
: undefined;
|
|
32
|
-
const activeProjectFilter = projectFilter
|
|
33
|
-
? undefined
|
|
34
|
-
: sql `(${entities.projectId} IS NULL OR ${entities.projectId} IN (
|
|
35
|
-
SELECT id FROM projects
|
|
36
|
-
WHERE status <> 'archived' AND workspace_id = ${scope.workspaceId}::uuid
|
|
37
|
-
))`;
|
|
38
|
-
const notStatus = (status) => or(ne(entities.status, status), isNull(entities.status));
|
|
39
|
-
// Base filter applied to every bucket: only tasks, optional project filter,
|
|
40
|
-
// and the includeDone toggle. Rejected/archived work is excluded everywhere:
|
|
41
|
-
// includeDone means "show completion history", not "show abandoned work",
|
|
42
|
-
// and a cancelled task with a leftover dueAt is not scheduled for anything.
|
|
43
|
-
const baseConds = [
|
|
44
|
-
inWorkspace,
|
|
45
|
-
eq(entities.kind, "task"),
|
|
46
|
-
isNull(entities.deletedAt),
|
|
47
|
-
notStatus("rejected"),
|
|
48
|
-
notStatus("archived")
|
|
49
|
-
];
|
|
50
|
-
if (!input.includeDone) {
|
|
51
|
-
baseConds.push(notStatus("done"));
|
|
52
|
-
}
|
|
53
|
-
if (projectFilter)
|
|
54
|
-
baseConds.push(projectFilter);
|
|
55
|
-
if (activeProjectFilter)
|
|
56
|
-
baseConds.push(activeProjectFilter);
|
|
57
|
-
// Three independent passes, unioned in JS. Drizzle's `or` keeps the SQL
|
|
58
|
-
// clear and the partial completed_at index keeps the done-pass cheap.
|
|
59
|
-
const inRange = (col) => {
|
|
60
|
-
const conds = [];
|
|
61
|
-
if (input.from)
|
|
62
|
-
conds.push(gte(col, input.from));
|
|
63
|
-
if (input.to)
|
|
64
|
-
conds.push(lt(col, input.to));
|
|
65
|
-
return conds;
|
|
66
|
-
};
|
|
67
|
-
// Overdue claims anything due before this instant; the scheduled and
|
|
68
|
-
// in-progress passes below exclude it so the buckets stay disjoint.
|
|
69
|
-
const overdueCutoff = input.from ?? now;
|
|
70
|
-
// (a) Non-done, non-in_progress tasks scheduled by dueAt.
|
|
71
|
-
const dueByDueConds = [
|
|
72
|
-
...baseConds,
|
|
73
|
-
isNotNull(entities.dueAt),
|
|
74
|
-
notStatus("done"),
|
|
75
|
-
notStatus("in_progress"),
|
|
76
|
-
gte(entities.dueAt, overdueCutoff),
|
|
77
|
-
...inRange(entities.dueAt)
|
|
78
|
-
];
|
|
79
|
-
const dueByDue = await db
|
|
80
|
-
.select()
|
|
81
|
-
.from(entities)
|
|
82
|
-
.where(and(...dueByDueConds))
|
|
83
|
-
.orderBy(asc(entities.dueAt));
|
|
84
|
-
// (b) Done tasks rendered on completedAt, with updatedAt as the legacy
|
|
85
|
-
// fallback for rows completed before completed_at existed. Never place done
|
|
86
|
-
// work by dueAt: completion history should reflect when work actually ended.
|
|
87
|
-
let doneByCompleted = [];
|
|
88
|
-
if (input.includeDone) {
|
|
89
|
-
const doneByCompletedConds = [
|
|
90
|
-
inWorkspace,
|
|
91
|
-
eq(entities.kind, "task"),
|
|
92
|
-
isNull(entities.deletedAt),
|
|
93
|
-
eq(entities.status, "done"),
|
|
94
|
-
isNotNull(entities.completedAt),
|
|
95
|
-
...inRange(entities.completedAt)
|
|
96
|
-
];
|
|
97
|
-
if (projectFilter)
|
|
98
|
-
doneByCompletedConds.push(projectFilter);
|
|
99
|
-
if (activeProjectFilter)
|
|
100
|
-
doneByCompletedConds.push(activeProjectFilter);
|
|
101
|
-
const completedRows = await db
|
|
102
|
-
.select()
|
|
103
|
-
.from(entities)
|
|
104
|
-
.where(and(...doneByCompletedConds))
|
|
105
|
-
.orderBy(asc(entities.completedAt));
|
|
106
|
-
const legacyDoneConds = [
|
|
107
|
-
inWorkspace,
|
|
108
|
-
eq(entities.kind, "task"),
|
|
109
|
-
isNull(entities.deletedAt),
|
|
110
|
-
eq(entities.status, "done"),
|
|
111
|
-
isNull(entities.completedAt),
|
|
112
|
-
...inRange(entities.updatedAt)
|
|
113
|
-
];
|
|
114
|
-
if (projectFilter)
|
|
115
|
-
legacyDoneConds.push(projectFilter);
|
|
116
|
-
if (activeProjectFilter)
|
|
117
|
-
legacyDoneConds.push(activeProjectFilter);
|
|
118
|
-
const legacyRows = await db
|
|
119
|
-
.select()
|
|
120
|
-
.from(entities)
|
|
121
|
-
.where(and(...legacyDoneConds))
|
|
122
|
-
.orderBy(asc(entities.updatedAt));
|
|
123
|
-
doneByCompleted = [...completedRows, ...legacyRows];
|
|
124
|
-
}
|
|
125
|
-
// (c) in_progress tasks → today. Only relevant when "now" falls inside the
|
|
126
|
-
// requested window; otherwise the day cell would never render them anyway.
|
|
127
|
-
// Past-due in_progress work belongs to overdue, and undated in_progress
|
|
128
|
-
// work to backlog when the caller asked for it.
|
|
129
|
-
let inProgressToday = [];
|
|
130
|
-
const todayInRange = (!input.from || now >= new Date(input.from)) &&
|
|
131
|
-
(!input.to || now < new Date(input.to));
|
|
132
|
-
if (todayInRange) {
|
|
133
|
-
const ipConds = [
|
|
134
|
-
inWorkspace,
|
|
135
|
-
eq(entities.kind, "task"),
|
|
136
|
-
isNull(entities.deletedAt),
|
|
137
|
-
eq(entities.status, "in_progress"),
|
|
138
|
-
input.includeBacklog
|
|
139
|
-
? gte(entities.dueAt, overdueCutoff)
|
|
140
|
-
: or(isNull(entities.dueAt), gte(entities.dueAt, overdueCutoff))
|
|
141
|
-
];
|
|
142
|
-
if (projectFilter)
|
|
143
|
-
ipConds.push(projectFilter);
|
|
144
|
-
if (activeProjectFilter)
|
|
145
|
-
ipConds.push(activeProjectFilter);
|
|
146
|
-
inProgressToday = await db
|
|
147
|
-
.select()
|
|
148
|
-
.from(entities)
|
|
149
|
-
.where(and(...ipConds))
|
|
150
|
-
.orderBy(asc(entities.dueAt));
|
|
151
|
-
}
|
|
152
|
-
// Dedup by id — a status='done' task with a completedAt also matched (a) if
|
|
153
|
-
// its dueAt landed in range; (b) wins because it's the canonical display.
|
|
154
|
-
const scheduledMap = new Map();
|
|
155
|
-
for (const e of dueByDue)
|
|
156
|
-
scheduledMap.set(e.id, e);
|
|
157
|
-
for (const e of doneByCompleted)
|
|
158
|
-
scheduledMap.set(e.id, e);
|
|
159
|
-
for (const e of inProgressToday)
|
|
160
|
-
scheduledMap.set(e.id, e);
|
|
161
|
-
const scheduled = Array.from(scheduledMap.values());
|
|
162
|
-
// Overdue = past-due work that still needs attention, whether it has been
|
|
163
|
-
// started or not.
|
|
164
|
-
const overdueConds = [
|
|
165
|
-
inWorkspace,
|
|
166
|
-
eq(entities.kind, "task"),
|
|
167
|
-
isNull(entities.deletedAt),
|
|
168
|
-
isNotNull(entities.dueAt),
|
|
169
|
-
lt(entities.dueAt, overdueCutoff),
|
|
170
|
-
notStatus("done"),
|
|
171
|
-
notStatus("rejected"),
|
|
172
|
-
notStatus("archived")
|
|
173
|
-
];
|
|
174
|
-
if (projectFilter)
|
|
175
|
-
overdueConds.push(projectFilter);
|
|
176
|
-
if (activeProjectFilter)
|
|
177
|
-
overdueConds.push(activeProjectFilter);
|
|
178
|
-
const overdue = await db
|
|
179
|
-
.select()
|
|
180
|
-
.from(entities)
|
|
181
|
-
.where(and(...overdueConds))
|
|
182
|
-
.orderBy(asc(entities.dueAt));
|
|
183
|
-
let backlog = [];
|
|
184
|
-
if (input.includeBacklog) {
|
|
185
|
-
backlog = await db
|
|
186
|
-
.select()
|
|
187
|
-
.from(entities)
|
|
188
|
-
.where(and(...baseConds, isNull(entities.dueAt)))
|
|
189
|
-
.orderBy(desc(entities.createdAt))
|
|
190
|
-
.limit(200);
|
|
191
|
-
}
|
|
192
|
-
const virtualOccurrences = await expandVirtualOccurrences(scope, db, input, scheduled);
|
|
193
|
-
const taskIds = [...scheduled, ...overdue, ...backlog].map((t) => t.id);
|
|
194
|
-
const [blockers, hierarchy] = await Promise.all([
|
|
195
|
-
blockersFor(scope, db, taskIds),
|
|
196
|
-
hierarchyFor(scope, db, taskIds)
|
|
197
|
-
]);
|
|
198
|
-
const decorate = (rows) => rows.map((t) => ({
|
|
199
|
-
...t,
|
|
200
|
-
blockedBy: blockers.get(t.id) ?? [],
|
|
201
|
-
...(hierarchy.get(t.id) ?? { parent: null, subtasks: null })
|
|
202
|
-
}));
|
|
203
|
-
return {
|
|
204
|
-
scheduled: decorate(scheduled),
|
|
205
|
-
overdue: decorate(overdue),
|
|
206
|
-
backlog: decorate(backlog),
|
|
207
|
-
virtualOccurrences
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Compute "ghost" virtual occurrences for all active scheduled-anchor
|
|
212
|
-
* recurrence rules within the query window. These are NOT stored in the DB;
|
|
213
|
-
* they are ephemeral previews of future materialization.
|
|
214
|
-
*
|
|
215
|
-
* HARD BOUNDARY: only called when input.includeVirtualRecurrences is true.
|
|
216
|
-
* The window is clamped to [max(input.from, now), input.to) so only strictly
|
|
217
|
-
* future ghosts are returned.
|
|
218
|
-
*/
|
|
219
|
-
async function expandVirtualOccurrences(scope, db, input, realScheduled) {
|
|
220
|
-
// Guard: feature must be explicitly requested and a horizon must be present.
|
|
221
|
-
if (!input.includeVirtualRecurrences || !input.to)
|
|
222
|
-
return [];
|
|
223
|
-
const now = new Date();
|
|
224
|
-
const windowStart = new Date(Math.max((input.from ? new Date(input.from).getTime() : now.getTime()), now.getTime()));
|
|
225
|
-
const windowEnd = new Date(input.to);
|
|
226
|
-
if (windowStart.getTime() >= windowEnd.getTime())
|
|
227
|
-
return [];
|
|
228
|
-
// --- Query 1: candidate rules (enabled, scheduled, not ended before window) ---
|
|
229
|
-
const candidateRules = await db
|
|
230
|
-
.select()
|
|
231
|
-
.from(recurrenceRules)
|
|
232
|
-
.where(and(eq(recurrenceRules.workspaceId, scope.workspaceId), eq(recurrenceRules.enabled, true), eq(recurrenceRules.anchor, "scheduled"), lte(recurrenceRules.dtstart, windowEnd), or(isNull(recurrenceRules.endedAt),
|
|
233
|
-
// endedAt >= windowStart means rule may still have occurrences in window
|
|
234
|
-
gte(recurrenceRules.endedAt, windowStart))));
|
|
235
|
-
if (candidateRules.length === 0)
|
|
236
|
-
return [];
|
|
237
|
-
// --- Query 2: batch-fetch display-source entities ---
|
|
238
|
-
// For each rule: display source = currentOccurrenceId ?? seriesId
|
|
239
|
-
const displaySourceIds = candidateRules.map((r) => r.currentOccurrenceId ?? r.seriesId);
|
|
240
|
-
const uniqueDisplaySourceIds = [...new Set(displaySourceIds)];
|
|
241
|
-
const displaySourceRows = await db
|
|
242
|
-
.select()
|
|
243
|
-
.from(entities)
|
|
244
|
-
.where(and(eq(entities.workspaceId, scope.workspaceId), inArray(entities.id, uniqueDisplaySourceIds)));
|
|
245
|
-
const displaySourceById = new Map(displaySourceRows.map((e) => [e.id, e]));
|
|
246
|
-
// --- Query 3: batch-fetch this-only baselines for display sources ---
|
|
247
|
-
// These are 'modified' exceptions where the baseline records what the
|
|
248
|
-
// pre-edit value was; we apply them so a this-only edit on the current
|
|
249
|
-
// occurrence is NOT reflected in the ghost (the ghost should show what
|
|
250
|
-
// materialization will actually generate, which reverts this-only edits).
|
|
251
|
-
const modifiedExceptions = await db
|
|
252
|
-
.select()
|
|
253
|
-
.from(recurrenceExceptions)
|
|
254
|
-
.where(and(inArray(recurrenceExceptions.entityId, uniqueDisplaySourceIds), eq(recurrenceExceptions.action, "modified")));
|
|
255
|
-
// Map entityId → baseline (the pre-edit / series-default value)
|
|
256
|
-
const baselineByEntityId = new Map();
|
|
257
|
-
for (const exc of modifiedExceptions) {
|
|
258
|
-
if (!exc.entityId)
|
|
259
|
-
continue;
|
|
260
|
-
const meta = exc.metadata;
|
|
261
|
-
const baseline = meta?.baseline;
|
|
262
|
-
if (baseline && typeof baseline === "object" && !Array.isArray(baseline)) {
|
|
263
|
-
baselineByEntityId.set(exc.entityId, baseline);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
// --- Query 4: batch-fetch exceptions for subtraction ---
|
|
267
|
-
const ruleIds = candidateRules.map((r) => r.id);
|
|
268
|
-
const exceptionRows = await db
|
|
269
|
-
.select()
|
|
270
|
-
.from(recurrenceExceptions)
|
|
271
|
-
.where(and(inArray(recurrenceExceptions.ruleId, ruleIds), gte(recurrenceExceptions.occurrenceAt, windowStart), lt(recurrenceExceptions.occurrenceAt, windowEnd)));
|
|
272
|
-
// Group exceptions by ruleId; track the blocked occurrence timestamps on the
|
|
273
|
-
// SAME normalized timeline used for the ghosts below (occurrenceAt is already
|
|
274
|
-
// stored normalized, so re-normalizing is idempotent — but it keeps the
|
|
275
|
-
// exception and materialized subtractions on one consistent timeline even for
|
|
276
|
-
// extreme timezones where a raw RRule date and its normalized dueAt differ).
|
|
277
|
-
const ruleById = new Map(candidateRules.map((r) => [r.id, r]));
|
|
278
|
-
const blockedByRule = new Map();
|
|
279
|
-
for (const exc of exceptionRows) {
|
|
280
|
-
if (exc.action === "skipped" || exc.action === "cancelled" || exc.action === "modified") {
|
|
281
|
-
const rule = ruleById.get(exc.ruleId);
|
|
282
|
-
if (!rule)
|
|
283
|
-
continue;
|
|
284
|
-
if (!blockedByRule.has(exc.ruleId))
|
|
285
|
-
blockedByRule.set(exc.ruleId, new Set());
|
|
286
|
-
blockedByRule.get(exc.ruleId).add(normalizeOccurrenceDueAt(rule, exc.occurrenceAt).getTime());
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
// Build a set of (ruleId, normalizedDueAt ms) that are already materialized
|
|
290
|
-
// so we can subtract them from virtuals.
|
|
291
|
-
const realByRule = new Map();
|
|
292
|
-
for (const e of realScheduled) {
|
|
293
|
-
const meta = e.metadata;
|
|
294
|
-
const ruleId = meta?.recurrence?.ruleId;
|
|
295
|
-
if (!ruleId || !e.dueAt)
|
|
296
|
-
continue;
|
|
297
|
-
if (!realByRule.has(ruleId))
|
|
298
|
-
realByRule.set(ruleId, new Set());
|
|
299
|
-
realByRule.get(ruleId).add(e.dueAt.getTime());
|
|
300
|
-
}
|
|
301
|
-
// --- Expand per rule ---
|
|
302
|
-
const virtuals = [];
|
|
303
|
-
for (const rule of candidateRules) {
|
|
304
|
-
const displaySourceId = rule.currentOccurrenceId ?? rule.seriesId;
|
|
305
|
-
const displaySource = displaySourceById.get(displaySourceId);
|
|
306
|
-
if (!displaySource)
|
|
307
|
-
continue;
|
|
308
|
-
// Project filter
|
|
309
|
-
if (input.projectIds?.length) {
|
|
310
|
-
if (!displaySource.projectId || !input.projectIds.includes(displaySource.projectId))
|
|
311
|
-
continue;
|
|
312
|
-
}
|
|
313
|
-
// Resolve effective title and priority (apply baseline to revert this-only edits)
|
|
314
|
-
const baseline = baselineByEntityId.get(displaySourceId);
|
|
315
|
-
const effectiveTitle = baseline && "title" in baseline
|
|
316
|
-
? baseline.title
|
|
317
|
-
: displaySource.title;
|
|
318
|
-
const effectivePriority = baseline && "priority" in baseline
|
|
319
|
-
? (baseline.priority ?? "none")
|
|
320
|
-
: displaySource.priority;
|
|
321
|
-
// Expand RRule within window
|
|
322
|
-
const rruleInstance = buildRRule(rule, rule.dtstart);
|
|
323
|
-
const rawDates = rruleInstance.between(windowStart, windowEnd, true);
|
|
324
|
-
const blockedTimes = blockedByRule.get(rule.id);
|
|
325
|
-
const realTimes = realByRule.get(rule.id);
|
|
326
|
-
for (const rawDate of rawDates) {
|
|
327
|
-
const normalizedDate = normalizeOccurrenceDueAt(rule, rawDate);
|
|
328
|
-
const normalizedMs = normalizedDate.getTime();
|
|
329
|
-
// Subtract: blocked by a skip/cancel/modify exception (normalized timeline)
|
|
330
|
-
if (blockedTimes?.has(normalizedMs))
|
|
331
|
-
continue;
|
|
332
|
-
// Subtract: already materialized as a real entity (match by normalized dueAt)
|
|
333
|
-
if (realTimes?.has(normalizedMs))
|
|
334
|
-
continue;
|
|
335
|
-
const dueAtISO = normalizedDate.toISOString();
|
|
336
|
-
virtuals.push({
|
|
337
|
-
virtual: true,
|
|
338
|
-
id: `virtual:${rule.id}:${dueAtISO}`,
|
|
339
|
-
ruleId: rule.id,
|
|
340
|
-
seriesId: rule.seriesId,
|
|
341
|
-
occurrenceAt: rawDate.toISOString(),
|
|
342
|
-
dueAt: dueAtISO,
|
|
343
|
-
title: effectiveTitle,
|
|
344
|
-
projectId: displaySource.projectId,
|
|
345
|
-
priority: effectivePriority,
|
|
346
|
-
allDay: rule.allDay,
|
|
347
|
-
timezone: rule.timezone,
|
|
348
|
-
rrule: rule.rrule
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
return virtuals;
|
|
353
|
-
}
|
|
354
|
-
//# sourceMappingURL=tasks.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tasks.js","sourceRoot":"","sources":["../../src/service/tasks.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,GAAG,EACH,IAAI,EACJ,EAAE,EACF,GAAG,EACH,OAAO,EACP,SAAS,EACT,MAAM,EACN,EAAE,EACF,GAAG,EACH,EAAE,EACF,EAAE,EACF,GAAG,EAEJ,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,eAAe,EAAe,MAAM,iBAAiB,CAAC;AAC/F,OAAO,EAAE,WAAW,EAAqB,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAsB,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AA4BvE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,KAAY,EACZ,EAAkB,EAClB,KAAsB;IAEtB,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IAEvB,MAAM,WAAW,GAAG,EAAE,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAChE,MAAM,aAAa,GAAG,KAAK,CAAC,UAAU,EAAE,MAAM;QAC5C,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,UAAU,CAAC;QA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AAQ;gBACf,KAAK,EAAE,cAAc;gBACrB,SAAS,EAAE,aAAa,CAAC,SAAS;gBAClC,QAAQ,EAAE,iBAAiB;gBAC3B,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,KAAK,EAAE,IAAI,CAAC,KAAK;aAClB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/service/tokens.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Database } from "../db/client.js";
|
|
2
|
-
import { type Token } from "../db/schema.js";
|
|
3
|
-
import type { Scope } from "./scope.js";
|
|
4
|
-
export interface CreatedToken {
|
|
5
|
-
token: Token;
|
|
6
|
-
/** The recoverable plaintext token. NULL only for tokens created before 0014. */
|
|
7
|
-
plaintext: string;
|
|
8
|
-
}
|
|
9
|
-
export declare function createToken(scope: Scope, db: Database["db"], input: {
|
|
10
|
-
name: string;
|
|
11
|
-
}): Promise<CreatedToken>;
|
|
12
|
-
export declare function tokenLabels(scope: Scope, db: Database["db"]): Promise<Map<string, string>>;
|
|
13
|
-
export declare function resetTokenLabelCache(): void;
|
|
14
|
-
export declare function listTokens(scope: Scope, db: Database["db"]): Promise<Token[]>;
|
|
15
|
-
export declare function revokeToken(scope: Scope, db: Database["db"], id: string): Promise<boolean>;
|
|
16
|
-
/**
|
|
17
|
-
* Look up a token by its plaintext. Returns null if not found. Bumps
|
|
18
|
-
* last_used_at on success. Unscoped by design: the returned row's workspaceId
|
|
19
|
-
* is what the transport turns into the request Scope.
|
|
20
|
-
*/
|
|
21
|
-
export declare function consumeToken(db: Database["db"], plaintext: string): Promise<Token | null>;
|
package/dist/service/tokens.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { createHash, randomBytes } from "node:crypto";
|
|
2
|
-
import { and, desc, eq } from "drizzle-orm";
|
|
3
|
-
import { tokens } from "../db/schema.js";
|
|
4
|
-
const TOKEN_PREFIX = "bn_";
|
|
5
|
-
function sha256(input) {
|
|
6
|
-
return createHash("sha256").update(input).digest("hex");
|
|
7
|
-
}
|
|
8
|
-
export async function createToken(scope, db, input) {
|
|
9
|
-
const plaintext = `${TOKEN_PREFIX}${randomBytes(24).toString("hex")}`;
|
|
10
|
-
const tokenHash = sha256(plaintext);
|
|
11
|
-
const prefix = plaintext.slice(0, 11); // bn_ + first 8 hex
|
|
12
|
-
const [row] = await db
|
|
13
|
-
.insert(tokens)
|
|
14
|
-
.values({ workspaceId: scope.workspaceId, name: input.name, tokenHash, prefix, plaintext })
|
|
15
|
-
.returning();
|
|
16
|
-
if (!row)
|
|
17
|
-
throw new Error("token insert returned no row");
|
|
18
|
-
labelCache.delete(scope.workspaceId);
|
|
19
|
-
return { token: row, plaintext };
|
|
20
|
-
}
|
|
21
|
-
// Token id -> name, per workspace. Every entity response resolves its author
|
|
22
|
-
// through this map, so it is cached briefly instead of queried per request.
|
|
23
|
-
// Writes through createToken/revokeToken invalidate it; a rename path would
|
|
24
|
-
// have to do the same.
|
|
25
|
-
const LABEL_CACHE_TTL_MS = 30_000;
|
|
26
|
-
const labelCache = new Map();
|
|
27
|
-
export async function tokenLabels(scope, db) {
|
|
28
|
-
const cached = labelCache.get(scope.workspaceId);
|
|
29
|
-
if (cached && Date.now() - cached.at < LABEL_CACHE_TTL_MS)
|
|
30
|
-
return cached.labels;
|
|
31
|
-
const rows = await db
|
|
32
|
-
.select({ id: tokens.id, name: tokens.name })
|
|
33
|
-
.from(tokens)
|
|
34
|
-
.where(eq(tokens.workspaceId, scope.workspaceId));
|
|
35
|
-
const labels = new Map(rows.map((r) => [r.id, r.name]));
|
|
36
|
-
labelCache.set(scope.workspaceId, { at: Date.now(), labels });
|
|
37
|
-
return labels;
|
|
38
|
-
}
|
|
39
|
-
export function resetTokenLabelCache() {
|
|
40
|
-
labelCache.clear();
|
|
41
|
-
}
|
|
42
|
-
export async function listTokens(scope, db) {
|
|
43
|
-
return db
|
|
44
|
-
.select()
|
|
45
|
-
.from(tokens)
|
|
46
|
-
.where(eq(tokens.workspaceId, scope.workspaceId))
|
|
47
|
-
.orderBy(desc(tokens.createdAt));
|
|
48
|
-
}
|
|
49
|
-
export async function revokeToken(scope, db, id) {
|
|
50
|
-
const res = await db
|
|
51
|
-
.delete(tokens)
|
|
52
|
-
.where(and(eq(tokens.id, id), eq(tokens.workspaceId, scope.workspaceId)))
|
|
53
|
-
.returning({ id: tokens.id });
|
|
54
|
-
labelCache.delete(scope.workspaceId);
|
|
55
|
-
return res.length > 0;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Look up a token by its plaintext. Returns null if not found. Bumps
|
|
59
|
-
* last_used_at on success. Unscoped by design: the returned row's workspaceId
|
|
60
|
-
* is what the transport turns into the request Scope.
|
|
61
|
-
*/
|
|
62
|
-
export async function consumeToken(db, plaintext) {
|
|
63
|
-
const tokenHash = sha256(plaintext);
|
|
64
|
-
const rows = await db.select().from(tokens).where(eq(tokens.tokenHash, tokenHash)).limit(1);
|
|
65
|
-
const row = rows[0];
|
|
66
|
-
if (!row)
|
|
67
|
-
return null;
|
|
68
|
-
await db.update(tokens).set({ lastUsedAt: new Date() }).where(eq(tokens.id, row.id));
|
|
69
|
-
return row;
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=tokens.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../src/service/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,MAAM,EAAc,MAAM,iBAAiB,CAAC;AAGrD,MAAM,YAAY,GAAG,KAAK,CAAC;AAE3B,SAAS,MAAM,CAAC,KAAa;IAC3B,OAAO,UAAU,CAAC,QAAQ,C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MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;SACxE,SAAS,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;IAChC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IACrC,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;AACxB,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,EAAkB,EAClB,SAAiB;IAEjB,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC5F,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAC;IACtB,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,EAAE,UAAU,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IACrF,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { Database } from "../db/client.js";
|
|
2
|
-
import type { Scope } from "./scope.js";
|
|
3
|
-
/**
|
|
4
|
-
* JSON Lines workspace dump. Line 1 is the header; every later line is one
|
|
5
|
-
* record whose `type` names the table it came from. Records are written in
|
|
6
|
-
* dependency order (projects before entities before edges, ...) so the
|
|
7
|
-
* importer can stream them without buffering the whole file.
|
|
8
|
-
*
|
|
9
|
-
* Bump FORMAT_VERSION only for changes an older importer could not read.
|
|
10
|
-
* Adding optional fields is not such a change.
|
|
11
|
-
*/
|
|
12
|
-
export declare const FORMAT_VERSION = 1;
|
|
13
|
-
export declare const RECORD_TYPES: readonly ["project", "entity", "edge", "recurrence_rule", "recurrence_exception", "entity_revision", "settings"];
|
|
14
|
-
export type RecordType = (typeof RECORD_TYPES)[number];
|
|
15
|
-
export interface ExportHeader {
|
|
16
|
-
type: "header";
|
|
17
|
-
formatVersion: number;
|
|
18
|
-
botnoteVersion: string;
|
|
19
|
-
exportedAt: string;
|
|
20
|
-
workspace: {
|
|
21
|
-
id: string;
|
|
22
|
-
slug: string;
|
|
23
|
-
name: string;
|
|
24
|
-
};
|
|
25
|
-
includesVectors: boolean;
|
|
26
|
-
}
|
|
27
|
-
export interface ExportOptions {
|
|
28
|
-
/** Include `bodyVec` on entities. Off by default: vectors are large and the importer re-embeds. */
|
|
29
|
-
includeVectors?: boolean;
|
|
30
|
-
}
|
|
31
|
-
export declare function exportWorkspace(scope: Scope, db: Database["db"], opts?: ExportOptions): AsyncGenerator<string>;
|
|
32
|
-
export interface ImportCounts {
|
|
33
|
-
imported: number;
|
|
34
|
-
skipped: number;
|
|
35
|
-
conflicts: number;
|
|
36
|
-
}
|
|
37
|
-
export interface ImportConflict {
|
|
38
|
-
type: RecordType;
|
|
39
|
-
id: string;
|
|
40
|
-
reason: string;
|
|
41
|
-
}
|
|
42
|
-
export interface ImportReport {
|
|
43
|
-
formatVersion: number;
|
|
44
|
-
botnoteVersion: string;
|
|
45
|
-
exportedAt: string;
|
|
46
|
-
sourceWorkspace: {
|
|
47
|
-
id: string;
|
|
48
|
-
slug: string;
|
|
49
|
-
name: string;
|
|
50
|
-
};
|
|
51
|
-
counts: Record<RecordType, ImportCounts>;
|
|
52
|
-
/** First MAX_REPORTED_CONFLICTS conflicts; `conflictsTotal` has the full count. */
|
|
53
|
-
conflicts: ImportConflict[];
|
|
54
|
-
conflictsTotal: number;
|
|
55
|
-
/** Entities inserted without a vector; run the embedding backfill to search them. */
|
|
56
|
-
entitiesWithoutVector: number;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Import a dump produced by exportWorkspace into `scope`. Idempotent: rows
|
|
60
|
-
* whose id already exists here are skipped, so a partial import can simply be
|
|
61
|
-
* re-run. Rows owned by another workspace, or whose parent row is missing,
|
|
62
|
-
* are reported as conflicts and left out rather than aborting the import.
|
|
63
|
-
*/
|
|
64
|
-
export declare function importWorkspace(scope: Scope, db: Database["db"], lines: AsyncIterable<string> | Iterable<string>): Promise<ImportReport>;
|