@bryti/agent 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/Dockerfile +27 -0
- package/README.md +77 -50
- package/config.example.yml +265 -0
- package/dist/active-hours.d.ts +23 -0
- package/dist/active-hours.d.ts.map +1 -0
- package/dist/active-hours.js +68 -0
- package/dist/active-hours.js.map +1 -0
- package/dist/agent.d.ts +84 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +383 -0
- package/dist/agent.js.map +1 -0
- package/dist/channels/markdown/ir.d.ts +79 -0
- package/dist/channels/markdown/ir.d.ts.map +1 -0
- package/dist/channels/markdown/ir.js +824 -0
- package/dist/channels/markdown/ir.js.map +1 -0
- package/dist/channels/markdown/render.d.ts +35 -0
- package/dist/channels/markdown/render.d.ts.map +1 -0
- package/dist/channels/markdown/render.js +178 -0
- package/dist/channels/markdown/render.js.map +1 -0
- package/dist/channels/telegram-network-errors.d.ts +27 -0
- package/dist/channels/telegram-network-errors.d.ts.map +1 -0
- package/dist/channels/telegram-network-errors.js +156 -0
- package/dist/channels/telegram-network-errors.js.map +1 -0
- package/dist/channels/telegram.d.ts +76 -0
- package/dist/channels/telegram.d.ts.map +1 -0
- package/dist/channels/telegram.js +814 -0
- package/dist/channels/telegram.js.map +1 -0
- package/dist/channels/types.d.ts +59 -0
- package/dist/channels/types.d.ts.map +1 -0
- package/dist/channels/types.js +9 -0
- package/dist/channels/types.js.map +1 -0
- package/dist/channels/whatsapp.d.ts +45 -0
- package/dist/channels/whatsapp.d.ts.map +1 -0
- package/dist/channels/whatsapp.js +310 -0
- package/dist/channels/whatsapp.js.map +1 -0
- package/dist/cli.d.ts +13 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +635 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands.d.ts +35 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +113 -0
- package/dist/commands.js.map +1 -0
- package/dist/compaction/history.d.ts +17 -0
- package/dist/compaction/history.d.ts.map +1 -0
- package/dist/compaction/history.js +35 -0
- package/dist/compaction/history.js.map +1 -0
- package/dist/compaction/index.d.ts +3 -0
- package/dist/compaction/index.d.ts.map +1 -0
- package/dist/compaction/index.js +3 -0
- package/dist/compaction/index.js.map +1 -0
- package/dist/compaction/proactive.d.ts +25 -0
- package/dist/compaction/proactive.d.ts.map +1 -0
- package/dist/compaction/proactive.js +87 -0
- package/dist/compaction/proactive.js.map +1 -0
- package/dist/compaction/transcript-repair.d.ts +55 -0
- package/dist/compaction/transcript-repair.d.ts.map +1 -0
- package/dist/compaction/transcript-repair.js +215 -0
- package/dist/compaction/transcript-repair.js.map +1 -0
- package/dist/config.d.ts +128 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +317 -0
- package/dist/config.js.map +1 -0
- package/dist/crash-recovery.d.ts +23 -0
- package/dist/crash-recovery.d.ts.map +1 -0
- package/dist/crash-recovery.js +96 -0
- package/dist/crash-recovery.js.map +1 -0
- package/dist/defaults/extensions/EXTENSIONS.md +158 -0
- package/dist/defaults/extensions/documents-hedgedoc.ts +153 -0
- package/dist/history.d.ts +31 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +49 -0
- package/dist/history.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +673 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +39 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +143 -0
- package/dist/logger.js.map +1 -0
- package/dist/memory/conversation-search.d.ts +15 -0
- package/dist/memory/conversation-search.d.ts.map +1 -0
- package/dist/memory/conversation-search.js +60 -0
- package/dist/memory/conversation-search.js.map +1 -0
- package/dist/memory/core-memory.d.ts +28 -0
- package/dist/memory/core-memory.d.ts.map +1 -0
- package/dist/memory/core-memory.js +102 -0
- package/dist/memory/core-memory.js.map +1 -0
- package/dist/memory/embeddings.d.ts +44 -0
- package/dist/memory/embeddings.d.ts.map +1 -0
- package/dist/memory/embeddings.js +139 -0
- package/dist/memory/embeddings.js.map +1 -0
- package/dist/memory/search.d.ts +49 -0
- package/dist/memory/search.d.ts.map +1 -0
- package/dist/memory/search.js +97 -0
- package/dist/memory/search.js.map +1 -0
- package/dist/memory/store.d.ts +32 -0
- package/dist/memory/store.d.ts.map +1 -0
- package/dist/memory/store.js +205 -0
- package/dist/memory/store.js.map +1 -0
- package/dist/message-queue.d.ts +73 -0
- package/dist/message-queue.d.ts.map +1 -0
- package/dist/message-queue.js +188 -0
- package/dist/message-queue.js.map +1 -0
- package/dist/model-infra.d.ts +64 -0
- package/dist/model-infra.d.ts.map +1 -0
- package/dist/model-infra.js +202 -0
- package/dist/model-infra.js.map +1 -0
- package/dist/projection/format.d.ts +10 -0
- package/dist/projection/format.d.ts.map +1 -0
- package/dist/projection/format.js +30 -0
- package/dist/projection/format.js.map +1 -0
- package/dist/projection/index.d.ts +11 -0
- package/dist/projection/index.d.ts.map +1 -0
- package/dist/projection/index.js +9 -0
- package/dist/projection/index.js.map +1 -0
- package/dist/projection/reflection.d.ts +94 -0
- package/dist/projection/reflection.d.ts.map +1 -0
- package/dist/projection/reflection.js +334 -0
- package/dist/projection/reflection.js.map +1 -0
- package/dist/projection/store.d.ts +144 -0
- package/dist/projection/store.d.ts.map +1 -0
- package/dist/projection/store.js +519 -0
- package/dist/projection/store.js.map +1 -0
- package/dist/projection/tools.d.ts +11 -0
- package/dist/projection/tools.d.ts.map +1 -0
- package/dist/projection/tools.js +237 -0
- package/dist/projection/tools.js.map +1 -0
- package/dist/scheduler.d.ts +36 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +286 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/system-prompt.d.ts +41 -0
- package/dist/system-prompt.d.ts.map +1 -0
- package/dist/system-prompt.js +162 -0
- package/dist/system-prompt.js.map +1 -0
- package/dist/time.d.ts +52 -0
- package/dist/time.d.ts.map +1 -0
- package/dist/time.js +138 -0
- package/dist/time.js.map +1 -0
- package/dist/tools/archival-memory-tool.d.ts +8 -0
- package/dist/tools/archival-memory-tool.d.ts.map +1 -0
- package/dist/tools/archival-memory-tool.js +68 -0
- package/dist/tools/archival-memory-tool.js.map +1 -0
- package/dist/tools/conversation-search-tool.d.ts +6 -0
- package/dist/tools/conversation-search-tool.d.ts.map +1 -0
- package/dist/tools/conversation-search-tool.js +28 -0
- package/dist/tools/conversation-search-tool.js.map +1 -0
- package/dist/tools/core-memory-tool.d.ts +7 -0
- package/dist/tools/core-memory-tool.d.ts.map +1 -0
- package/dist/tools/core-memory-tool.js +59 -0
- package/dist/tools/core-memory-tool.js.map +1 -0
- package/dist/tools/fetch-url.d.ts +15 -0
- package/dist/tools/fetch-url.d.ts.map +1 -0
- package/dist/tools/fetch-url.js +76 -0
- package/dist/tools/fetch-url.js.map +1 -0
- package/dist/tools/files.d.ts +10 -0
- package/dist/tools/files.d.ts.map +1 -0
- package/dist/tools/files.js +127 -0
- package/dist/tools/files.js.map +1 -0
- package/dist/tools/index.d.ts +17 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +118 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/result.d.ts +21 -0
- package/dist/tools/result.d.ts.map +1 -0
- package/dist/tools/result.js +36 -0
- package/dist/tools/result.js.map +1 -0
- package/dist/tools/skill-install.d.ts +17 -0
- package/dist/tools/skill-install.d.ts.map +1 -0
- package/dist/tools/skill-install.js +148 -0
- package/dist/tools/skill-install.js.map +1 -0
- package/dist/tools/web-search.d.ts +42 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +237 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/trust/guardrail.d.ts +60 -0
- package/dist/trust/guardrail.d.ts.map +1 -0
- package/dist/trust/guardrail.js +171 -0
- package/dist/trust/guardrail.js.map +1 -0
- package/dist/trust/index.d.ts +12 -0
- package/dist/trust/index.d.ts.map +1 -0
- package/dist/trust/index.js +12 -0
- package/dist/trust/index.js.map +1 -0
- package/dist/trust/store.d.ts +118 -0
- package/dist/trust/store.d.ts.map +1 -0
- package/dist/trust/store.js +209 -0
- package/dist/trust/store.js.map +1 -0
- package/dist/trust/wrapper.d.ts +36 -0
- package/dist/trust/wrapper.d.ts.map +1 -0
- package/dist/trust/wrapper.js +142 -0
- package/dist/trust/wrapper.js.map +1 -0
- package/dist/usage.d.ts +53 -0
- package/dist/usage.d.ts.map +1 -0
- package/dist/usage.js +124 -0
- package/dist/usage.js.map +1 -0
- package/dist/util/math.d.ts +9 -0
- package/dist/util/math.d.ts.map +1 -0
- package/dist/util/math.js +22 -0
- package/dist/util/math.js.map +1 -0
- package/dist/util/ssrf.d.ts +21 -0
- package/dist/util/ssrf.d.ts.map +1 -0
- package/dist/util/ssrf.js +77 -0
- package/dist/util/ssrf.js.map +1 -0
- package/dist/workers/index.d.ts +8 -0
- package/dist/workers/index.d.ts.map +1 -0
- package/dist/workers/index.js +7 -0
- package/dist/workers/index.js.map +1 -0
- package/dist/workers/registry.d.ts +53 -0
- package/dist/workers/registry.d.ts.map +1 -0
- package/dist/workers/registry.js +38 -0
- package/dist/workers/registry.js.map +1 -0
- package/dist/workers/scoped-tools.d.ts +21 -0
- package/dist/workers/scoped-tools.d.ts.map +1 -0
- package/dist/workers/scoped-tools.js +111 -0
- package/dist/workers/scoped-tools.js.map +1 -0
- package/dist/workers/spawn.d.ts +62 -0
- package/dist/workers/spawn.d.ts.map +1 -0
- package/dist/workers/spawn.js +314 -0
- package/dist/workers/spawn.js.map +1 -0
- package/dist/workers/tools.d.ts +26 -0
- package/dist/workers/tools.d.ts.map +1 -0
- package/dist/workers/tools.js +380 -0
- package/dist/workers/tools.js.map +1 -0
- package/docker-compose.yml +72 -0
- package/package.json +16 -1
- package/run.sh +27 -0
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Projection store: SQLite-backed storage for forward-looking agent memory.
|
|
3
|
+
*
|
|
4
|
+
* Stores future events, plans, and commitments with a resolution
|
|
5
|
+
* (exact/day/week/month/someday) and lifecycle (pending -> done/cancelled/passed).
|
|
6
|
+
*
|
|
7
|
+
* Lives in the same per-user memory.db as archival memory, its own table.
|
|
8
|
+
*
|
|
9
|
+
* Key columns: summary, raw_when (what the user said), resolved_when (ISO
|
|
10
|
+
* datetime), resolution, recurrence (cron), trigger_on_fact (keyword trigger),
|
|
11
|
+
* status, and dependencies (separate table for DAG relationships).
|
|
12
|
+
*/
|
|
13
|
+
import Database from "better-sqlite3";
|
|
14
|
+
import fs from "node:fs";
|
|
15
|
+
import path from "node:path";
|
|
16
|
+
import crypto from "node:crypto";
|
|
17
|
+
import { cosineSimilarity } from "../util/math.js";
|
|
18
|
+
function rowToProjection(row) {
|
|
19
|
+
let linked_ids = [];
|
|
20
|
+
if (row.linked_ids) {
|
|
21
|
+
try {
|
|
22
|
+
linked_ids = JSON.parse(row.linked_ids);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
linked_ids = [];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
id: row.id,
|
|
30
|
+
summary: row.summary,
|
|
31
|
+
raw_when: row.raw_when,
|
|
32
|
+
resolved_when: row.resolved_when,
|
|
33
|
+
resolution: row.resolution,
|
|
34
|
+
recurrence: row.recurrence,
|
|
35
|
+
trigger_on_fact: row.trigger_on_fact,
|
|
36
|
+
context: row.context,
|
|
37
|
+
linked_ids,
|
|
38
|
+
status: row.status,
|
|
39
|
+
created_at: row.created_at,
|
|
40
|
+
resolved_at: row.resolved_at,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function rowToDependency(row) {
|
|
44
|
+
return {
|
|
45
|
+
id: row.id,
|
|
46
|
+
observer_id: row.observer_id,
|
|
47
|
+
subject_id: row.subject_id,
|
|
48
|
+
condition: row.condition,
|
|
49
|
+
condition_type: row.condition_type,
|
|
50
|
+
created_at: row.created_at,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// Factory
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
/**
|
|
57
|
+
* Open (or create) the per-user projection store. Shares memory.db with
|
|
58
|
+
* archival memory.
|
|
59
|
+
*
|
|
60
|
+
* Schema overview
|
|
61
|
+
* ---------------
|
|
62
|
+
* projections
|
|
63
|
+
* Primary record. Holds the summary, timing fields (raw_when, resolved_when,
|
|
64
|
+
* resolution), recurrence cron, trigger_on_fact keyword, and status.
|
|
65
|
+
*
|
|
66
|
+
* projection_links
|
|
67
|
+
* Many-to-many cross-reference between projections (e.g., "this task belongs
|
|
68
|
+
* to that project"). Links are stored as a JSON array on the projections row
|
|
69
|
+
* (linked_ids) and optionally in this table for reverse lookups.
|
|
70
|
+
*
|
|
71
|
+
* projection_dependencies
|
|
72
|
+
* DAG edges. An observer projection waits for its subject projection(s) to
|
|
73
|
+
* reach a condition before it becomes active. Conditions are either a status
|
|
74
|
+
* keyword ("done", "cancelled", "passed") or an LLM-evaluated expression.
|
|
75
|
+
*
|
|
76
|
+
* Lifecycle state machine
|
|
77
|
+
* -----------------------
|
|
78
|
+
* pending → done (agent or user explicitly resolves it)
|
|
79
|
+
* pending → cancelled (agent or user cancels it)
|
|
80
|
+
* pending → passed (autoExpire: the time window elapsed without action)
|
|
81
|
+
*
|
|
82
|
+
* Recurring projections return to pending after each firing (see rearm()).
|
|
83
|
+
* Trigger-based projections become active (resolution='exact') when a matching
|
|
84
|
+
* fact arrives via checkTriggers(), then fire on the next scheduler tick.
|
|
85
|
+
*/
|
|
86
|
+
export function createProjectionStore(userId, dataDir) {
|
|
87
|
+
const userDir = path.join(dataDir, "users", userId);
|
|
88
|
+
fs.mkdirSync(userDir, { recursive: true });
|
|
89
|
+
const dbPath = path.join(userDir, "memory.db");
|
|
90
|
+
const db = new Database(dbPath);
|
|
91
|
+
db.pragma("journal_mode = WAL");
|
|
92
|
+
db.exec(`
|
|
93
|
+
CREATE TABLE IF NOT EXISTS projections (
|
|
94
|
+
id TEXT PRIMARY KEY,
|
|
95
|
+
summary TEXT NOT NULL,
|
|
96
|
+
raw_when TEXT,
|
|
97
|
+
resolved_when TEXT,
|
|
98
|
+
resolution TEXT NOT NULL DEFAULT 'day',
|
|
99
|
+
recurrence TEXT,
|
|
100
|
+
trigger_on_fact TEXT,
|
|
101
|
+
context TEXT,
|
|
102
|
+
linked_ids TEXT,
|
|
103
|
+
status TEXT NOT NULL DEFAULT 'pending',
|
|
104
|
+
created_at TEXT NOT NULL,
|
|
105
|
+
resolved_at TEXT
|
|
106
|
+
);
|
|
107
|
+
`);
|
|
108
|
+
db.exec(`
|
|
109
|
+
CREATE TABLE IF NOT EXISTS projection_dependencies (
|
|
110
|
+
id TEXT PRIMARY KEY,
|
|
111
|
+
observer_id TEXT NOT NULL,
|
|
112
|
+
subject_id TEXT NOT NULL,
|
|
113
|
+
condition TEXT NOT NULL,
|
|
114
|
+
condition_type TEXT NOT NULL DEFAULT 'status_change',
|
|
115
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
116
|
+
);
|
|
117
|
+
`);
|
|
118
|
+
// Migrate: add columns to existing databases that predate these features.
|
|
119
|
+
for (const ddl of [
|
|
120
|
+
`ALTER TABLE projections ADD COLUMN recurrence TEXT;`,
|
|
121
|
+
`ALTER TABLE projections ADD COLUMN trigger_on_fact TEXT;`,
|
|
122
|
+
]) {
|
|
123
|
+
try {
|
|
124
|
+
db.exec(ddl);
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// Column already exists — ignore
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const stmtInsert = db.prepare(`
|
|
131
|
+
INSERT INTO projections
|
|
132
|
+
(id, summary, raw_when, resolved_when, resolution, recurrence, trigger_on_fact, context, linked_ids, status, created_at)
|
|
133
|
+
VALUES
|
|
134
|
+
(?, ?, ?, ?, ?, ?, ?, ?, ?, 'pending', ?)
|
|
135
|
+
`);
|
|
136
|
+
const stmtInsertDependency = db.prepare(`
|
|
137
|
+
INSERT INTO projection_dependencies
|
|
138
|
+
(id, observer_id, subject_id, condition, condition_type, created_at)
|
|
139
|
+
VALUES
|
|
140
|
+
(?, ?, ?, ?, ?, ?)
|
|
141
|
+
`);
|
|
142
|
+
const stmtProjectionExists = db.prepare(`
|
|
143
|
+
SELECT id FROM projections WHERE id = ?
|
|
144
|
+
`);
|
|
145
|
+
const stmtDependencyEdges = db.prepare(`
|
|
146
|
+
SELECT subject_id, observer_id FROM projection_dependencies
|
|
147
|
+
`);
|
|
148
|
+
const stmtDependenciesForEvaluation = db.prepare(`
|
|
149
|
+
SELECT
|
|
150
|
+
d.id,
|
|
151
|
+
d.observer_id,
|
|
152
|
+
d.subject_id,
|
|
153
|
+
d.condition,
|
|
154
|
+
d.condition_type,
|
|
155
|
+
d.created_at,
|
|
156
|
+
s.status AS subject_status
|
|
157
|
+
FROM projection_dependencies d
|
|
158
|
+
JOIN projections o ON o.id = d.observer_id
|
|
159
|
+
JOIN projections s ON s.id = d.subject_id
|
|
160
|
+
WHERE o.status = 'pending'
|
|
161
|
+
`);
|
|
162
|
+
const stmtActivateObserver = db.prepare(`
|
|
163
|
+
UPDATE projections
|
|
164
|
+
SET resolved_when = datetime('now'), resolution = 'exact'
|
|
165
|
+
WHERE id = ? AND status = 'pending'
|
|
166
|
+
`);
|
|
167
|
+
const stmtDeleteDependenciesByObserver = db.prepare(`
|
|
168
|
+
DELETE FROM projection_dependencies WHERE observer_id = ?
|
|
169
|
+
`);
|
|
170
|
+
const stmtDependenciesList = db.prepare(`
|
|
171
|
+
SELECT * FROM projection_dependencies ORDER BY created_at ASC
|
|
172
|
+
`);
|
|
173
|
+
const stmtDependenciesListByObserver = db.prepare(`
|
|
174
|
+
SELECT * FROM projection_dependencies WHERE observer_id = ? ORDER BY created_at ASC
|
|
175
|
+
`);
|
|
176
|
+
const stmtUpcoming = db.prepare(`
|
|
177
|
+
SELECT * FROM projections
|
|
178
|
+
WHERE status = 'pending'
|
|
179
|
+
AND (
|
|
180
|
+
resolution = 'someday'
|
|
181
|
+
OR resolved_when IS NULL
|
|
182
|
+
OR resolved_when <= datetime('now', ? || ' days')
|
|
183
|
+
)
|
|
184
|
+
ORDER BY
|
|
185
|
+
CASE WHEN resolved_when IS NULL THEN 1 ELSE 0 END,
|
|
186
|
+
resolved_when ASC
|
|
187
|
+
`);
|
|
188
|
+
const stmtExactDue = db.prepare(`
|
|
189
|
+
SELECT * FROM projections
|
|
190
|
+
WHERE status = 'pending'
|
|
191
|
+
AND resolution = 'exact'
|
|
192
|
+
AND resolved_when IS NOT NULL
|
|
193
|
+
AND resolved_when <= datetime('now', ? || ' minutes')
|
|
194
|
+
AND resolved_when > datetime('now', '-10 minutes')
|
|
195
|
+
ORDER BY resolved_when ASC
|
|
196
|
+
`);
|
|
197
|
+
const stmtResolve = db.prepare(`
|
|
198
|
+
UPDATE projections
|
|
199
|
+
SET status = ?, resolved_at = datetime('now')
|
|
200
|
+
WHERE id = ? AND status = 'pending'
|
|
201
|
+
`);
|
|
202
|
+
const stmtRearm = db.prepare(`
|
|
203
|
+
UPDATE projections
|
|
204
|
+
SET status = 'pending', resolved_when = ?, resolved_at = NULL
|
|
205
|
+
WHERE id = ?
|
|
206
|
+
`);
|
|
207
|
+
// Fetch all pending projections that have a trigger_on_fact set.
|
|
208
|
+
const stmtPendingWithTriggers = db.prepare(`
|
|
209
|
+
SELECT * FROM projections
|
|
210
|
+
WHERE status = 'pending'
|
|
211
|
+
AND trigger_on_fact IS NOT NULL
|
|
212
|
+
AND trigger_on_fact != ''
|
|
213
|
+
`);
|
|
214
|
+
// Activate a trigger-matched projection: set resolved_when to now, resolution
|
|
215
|
+
// to 'exact', and clear trigger_on_fact so it won't re-match on future inserts.
|
|
216
|
+
const stmtActivateTrigger = db.prepare(`
|
|
217
|
+
UPDATE projections
|
|
218
|
+
SET resolved_when = datetime('now'), resolution = 'exact', trigger_on_fact = NULL
|
|
219
|
+
WHERE id = ? AND status = 'pending'
|
|
220
|
+
`);
|
|
221
|
+
const stmtExpire = db.prepare(`
|
|
222
|
+
UPDATE projections
|
|
223
|
+
SET status = 'passed', resolved_at = datetime('now')
|
|
224
|
+
WHERE status = 'pending'
|
|
225
|
+
AND resolution != 'someday'
|
|
226
|
+
AND resolved_when IS NOT NULL
|
|
227
|
+
AND (
|
|
228
|
+
-- Exact-time items expire after 1 hour (they either fired or were missed)
|
|
229
|
+
(resolution = 'exact' AND resolved_when < datetime('now', '-1 hours'))
|
|
230
|
+
OR
|
|
231
|
+
-- Day/week/month items expire after the configured threshold
|
|
232
|
+
(resolution != 'exact' AND resolved_when < datetime('now', ? || ' hours'))
|
|
233
|
+
)
|
|
234
|
+
`);
|
|
235
|
+
function inferConditionType(condition, explicit) {
|
|
236
|
+
if (explicit)
|
|
237
|
+
return explicit;
|
|
238
|
+
return ["done", "cancelled", "passed"].includes(condition) ? "status_change" : "llm";
|
|
239
|
+
}
|
|
240
|
+
function validateAndInsertDependency(observerId, subjectId, condition, conditionType) {
|
|
241
|
+
if (!condition.trim()) {
|
|
242
|
+
throw new Error("Dependency condition must not be empty");
|
|
243
|
+
}
|
|
244
|
+
const observerExists = stmtProjectionExists.get(observerId);
|
|
245
|
+
if (!observerExists) {
|
|
246
|
+
throw new Error(`Observer projection not found: ${observerId}`);
|
|
247
|
+
}
|
|
248
|
+
const subjectExists = stmtProjectionExists.get(subjectId);
|
|
249
|
+
if (!subjectExists) {
|
|
250
|
+
throw new Error(`Subject projection not found: ${subjectId}`);
|
|
251
|
+
}
|
|
252
|
+
if (observerId === subjectId) {
|
|
253
|
+
throw new Error("Projection cannot depend on itself");
|
|
254
|
+
}
|
|
255
|
+
const existingEdges = stmtDependencyEdges.all();
|
|
256
|
+
const edges = existingEdges.map((e) => ({ subject: e.subject_id, observer: e.observer_id }));
|
|
257
|
+
edges.push({ subject: subjectId, observer: observerId });
|
|
258
|
+
const adjacency = new Map();
|
|
259
|
+
for (const edge of edges) {
|
|
260
|
+
const list = adjacency.get(edge.subject) ?? [];
|
|
261
|
+
list.push(edge.observer);
|
|
262
|
+
adjacency.set(edge.subject, list);
|
|
263
|
+
}
|
|
264
|
+
// Cycle check: if observer can already reach subject, adding subject->observer closes a cycle.
|
|
265
|
+
const stack = [observerId];
|
|
266
|
+
const visited = new Set();
|
|
267
|
+
while (stack.length > 0) {
|
|
268
|
+
const current = stack.pop();
|
|
269
|
+
if (current === subjectId) {
|
|
270
|
+
throw new Error("Dependency cycle detected");
|
|
271
|
+
}
|
|
272
|
+
if (visited.has(current))
|
|
273
|
+
continue;
|
|
274
|
+
visited.add(current);
|
|
275
|
+
const next = adjacency.get(current) ?? [];
|
|
276
|
+
for (const n of next)
|
|
277
|
+
stack.push(n);
|
|
278
|
+
}
|
|
279
|
+
// Depth check across the full DAG after the new edge is considered.
|
|
280
|
+
const depthMemo = new Map();
|
|
281
|
+
const visiting = new Set();
|
|
282
|
+
const longestFrom = (node) => {
|
|
283
|
+
const cached = depthMemo.get(node);
|
|
284
|
+
if (cached !== undefined)
|
|
285
|
+
return cached;
|
|
286
|
+
if (visiting.has(node)) {
|
|
287
|
+
// Defensive guard; cycle should be caught above.
|
|
288
|
+
throw new Error("Dependency cycle detected");
|
|
289
|
+
}
|
|
290
|
+
visiting.add(node);
|
|
291
|
+
const children = adjacency.get(node) ?? [];
|
|
292
|
+
let best = 1;
|
|
293
|
+
for (const child of children) {
|
|
294
|
+
best = Math.max(best, 1 + longestFrom(child));
|
|
295
|
+
}
|
|
296
|
+
visiting.delete(node);
|
|
297
|
+
depthMemo.set(node, best);
|
|
298
|
+
return best;
|
|
299
|
+
};
|
|
300
|
+
const nodes = new Set([observerId, subjectId]);
|
|
301
|
+
for (const edge of edges) {
|
|
302
|
+
nodes.add(edge.subject);
|
|
303
|
+
nodes.add(edge.observer);
|
|
304
|
+
}
|
|
305
|
+
let maxDepth = 0;
|
|
306
|
+
for (const n of nodes) {
|
|
307
|
+
maxDepth = Math.max(maxDepth, longestFrom(n));
|
|
308
|
+
}
|
|
309
|
+
if (maxDepth > 5) {
|
|
310
|
+
throw new Error("Dependency chain too deep (max 5)");
|
|
311
|
+
}
|
|
312
|
+
const id = crypto.randomUUID();
|
|
313
|
+
const now = new Date().toISOString();
|
|
314
|
+
stmtInsertDependency.run(id, observerId, subjectId, condition.trim(), inferConditionType(condition.trim(), conditionType), now);
|
|
315
|
+
return id;
|
|
316
|
+
}
|
|
317
|
+
const addWithDependencies = db.transaction((params) => {
|
|
318
|
+
const id = crypto.randomUUID();
|
|
319
|
+
const now = new Date().toISOString();
|
|
320
|
+
// resolved_when is the normalised ISO datetime derived from raw_when (the
|
|
321
|
+
// caller is responsible for resolving natural-language expressions like
|
|
322
|
+
// "next Monday" before calling add()). For trigger_on_fact projections no
|
|
323
|
+
// resolved_when is needed upfront — checkTriggers() sets it at fire time.
|
|
324
|
+
stmtInsert.run(id, params.summary, params.raw_when ?? null, params.resolved_when ?? null, params.resolution ?? "day", params.recurrence ?? null, params.trigger_on_fact ?? null, params.context ?? null, params.linked_ids ? JSON.stringify(params.linked_ids) : null, now);
|
|
325
|
+
// Each entry in depends_on creates a DAG edge: this new projection (observer)
|
|
326
|
+
// will not activate until the referenced subject projection reaches its condition.
|
|
327
|
+
for (const dep of params.depends_on ?? []) {
|
|
328
|
+
validateAndInsertDependency(id, dep.subject_id, dep.condition, dep.condition_type);
|
|
329
|
+
}
|
|
330
|
+
return id;
|
|
331
|
+
});
|
|
332
|
+
return {
|
|
333
|
+
add({ summary, raw_when, resolved_when, resolution, recurrence, trigger_on_fact, context, linked_ids, depends_on }) {
|
|
334
|
+
return addWithDependencies({
|
|
335
|
+
summary,
|
|
336
|
+
raw_when,
|
|
337
|
+
resolved_when,
|
|
338
|
+
resolution,
|
|
339
|
+
recurrence,
|
|
340
|
+
trigger_on_fact,
|
|
341
|
+
context,
|
|
342
|
+
linked_ids,
|
|
343
|
+
depends_on,
|
|
344
|
+
});
|
|
345
|
+
},
|
|
346
|
+
getUpcoming(horizon_days) {
|
|
347
|
+
// SQL note: the ORDER BY uses a CASE expression to push rows with no
|
|
348
|
+
// resolved_when (someday / trigger-only items) to the end; time-bound
|
|
349
|
+
// projections are sorted ascending by resolved_when. Trigger-based
|
|
350
|
+
// projections also land here when they have no resolved_when yet; the
|
|
351
|
+
// caller can identify them by the non-null trigger_on_fact column.
|
|
352
|
+
const rows = stmtUpcoming.all(String(horizon_days));
|
|
353
|
+
return rows.map(rowToProjection);
|
|
354
|
+
},
|
|
355
|
+
getExactDue(window_minutes) {
|
|
356
|
+
// Filters to resolution='exact' only: day/week/month projections are surfaced
|
|
357
|
+
// through getUpcoming, not here. window_minutes must be larger than the
|
|
358
|
+
// scheduler tick (5 min) so that projections due between ticks are never
|
|
359
|
+
// skipped. The lower bound ('-10 minutes') prevents re-firing events that
|
|
360
|
+
// already fired but whose resolved_at hasn't been written yet.
|
|
361
|
+
const rows = stmtExactDue.all(String(window_minutes));
|
|
362
|
+
return rows.map(rowToProjection);
|
|
363
|
+
},
|
|
364
|
+
resolve(id, status) {
|
|
365
|
+
const result = stmtResolve.run(status, id);
|
|
366
|
+
return result.changes > 0;
|
|
367
|
+
},
|
|
368
|
+
rearm(id, nextResolvedWhen) {
|
|
369
|
+
// Only called for recurring projections after they fire. Resets status to
|
|
370
|
+
// 'pending' and advances resolved_when to the next occurrence so the
|
|
371
|
+
// scheduler will pick it up again. resolved_at is cleared so the projection
|
|
372
|
+
// looks fresh for the next cycle.
|
|
373
|
+
const result = stmtRearm.run(nextResolvedWhen, id);
|
|
374
|
+
return result.changes > 0;
|
|
375
|
+
},
|
|
376
|
+
async checkTriggers(factContent, embed, similarityThreshold = 0.55) {
|
|
377
|
+
const candidates = stmtPendingWithTriggers.all();
|
|
378
|
+
if (candidates.length === 0)
|
|
379
|
+
return [];
|
|
380
|
+
// Normalise the incoming fact to lowercase words for matching.
|
|
381
|
+
const factLower = factContent.toLowerCase();
|
|
382
|
+
const activated = [];
|
|
383
|
+
const embeddingFallback = [];
|
|
384
|
+
for (const row of candidates) {
|
|
385
|
+
const trigger = row.trigger_on_fact.toLowerCase().trim();
|
|
386
|
+
if (!trigger)
|
|
387
|
+
continue;
|
|
388
|
+
// Fast path (keyword matching): split trigger into tokens and require
|
|
389
|
+
// every token to appear in the fact text. This is O(n*m) but fast for
|
|
390
|
+
// short triggers. If all keywords are present the projection fires
|
|
391
|
+
// immediately, without involving the embedding model.
|
|
392
|
+
const keywords = trigger.split(/\W+/).filter(Boolean);
|
|
393
|
+
const allPresent = keywords.every((kw) => factLower.includes(kw));
|
|
394
|
+
if (allPresent) {
|
|
395
|
+
// Activate immediately: set resolved_when to now and resolution to
|
|
396
|
+
// 'exact' so the scheduler will fire this projection on the next tick.
|
|
397
|
+
// trigger_on_fact is cleared so it won't re-match future facts.
|
|
398
|
+
const result = stmtActivateTrigger.run(row.id);
|
|
399
|
+
if (result.changes > 0) {
|
|
400
|
+
const updated = { ...row, resolved_when: new Date().toISOString().slice(0, 16).replace("T", " "), resolution: "exact", trigger_on_fact: null };
|
|
401
|
+
activated.push(rowToProjection(updated));
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
else if (embed) {
|
|
405
|
+
// Skip embedding fallback for triggers that contain specific identifiers
|
|
406
|
+
// (worker IDs, UUIDs, etc.). These should only match on exact keywords,
|
|
407
|
+
// not semantic similarity. "worker w-abc123 complete" is semantically
|
|
408
|
+
// similar to "worker w-xyz789 complete" but they're about different workers.
|
|
409
|
+
const hasSpecificId = /w-[0-9a-f]{6,}|[0-9a-f]{8}-[0-9a-f]{4}-/.test(trigger);
|
|
410
|
+
if (!hasSpecificId) {
|
|
411
|
+
embeddingFallback.push(row);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
// Slow path (semantic matching): embed both the fact and the trigger phrase,
|
|
416
|
+
// then compute cosine similarity. Projections that score above
|
|
417
|
+
// similarityThreshold are activated the same way as keyword matches.
|
|
418
|
+
// The projection is resolved immediately on trigger (rather than queued)
|
|
419
|
+
// because by the time checkTriggers() runs the activating fact already
|
|
420
|
+
// exists — there is no point delaying the notification.
|
|
421
|
+
if (embeddingFallback.length > 0 && embed) {
|
|
422
|
+
const factVec = await embed(factContent);
|
|
423
|
+
for (const row of embeddingFallback) {
|
|
424
|
+
const triggerVec = await embed(row.trigger_on_fact);
|
|
425
|
+
const sim = cosineSimilarity(factVec, triggerVec);
|
|
426
|
+
if (sim >= similarityThreshold) {
|
|
427
|
+
const result = stmtActivateTrigger.run(row.id);
|
|
428
|
+
if (result.changes > 0) {
|
|
429
|
+
const updated = { ...row, resolved_when: new Date().toISOString().slice(0, 16).replace("T", " "), resolution: "exact", trigger_on_fact: null };
|
|
430
|
+
activated.push(rowToProjection(updated));
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return activated;
|
|
436
|
+
},
|
|
437
|
+
/**
|
|
438
|
+
* Marks pending projections as 'passed' when their resolved_when timestamp
|
|
439
|
+
* is more than threshold_hours hours in the past and they are still pending.
|
|
440
|
+
* Exact-resolution projections use a fixed 1-hour window (they either fired
|
|
441
|
+
* via the scheduler or were missed); all other resolutions use the caller-
|
|
442
|
+
* supplied threshold. Someday projections are never expired by time.
|
|
443
|
+
*
|
|
444
|
+
* Returns the number of rows updated.
|
|
445
|
+
*/
|
|
446
|
+
autoExpire(threshold_hours = 24) {
|
|
447
|
+
const result = stmtExpire.run(String(-threshold_hours));
|
|
448
|
+
return result.changes;
|
|
449
|
+
},
|
|
450
|
+
linkDependency(observerId, subjectId, condition, conditionType) {
|
|
451
|
+
return validateAndInsertDependency(observerId, subjectId, condition, conditionType);
|
|
452
|
+
},
|
|
453
|
+
/**
|
|
454
|
+
* Evaluates the dependency DAG and activates any observer projections whose
|
|
455
|
+
* conditions are all satisfied.
|
|
456
|
+
*
|
|
457
|
+
* Evaluation is performed in a fixed-point loop (up to 10 iterations):
|
|
458
|
+
* activating an observer may satisfy a condition for another observer further
|
|
459
|
+
* up the chain, so the loop re-runs until no new activations occur.
|
|
460
|
+
*
|
|
461
|
+
* Condition types:
|
|
462
|
+
* 'status_change' — satisfied when subject.status equals the condition
|
|
463
|
+
* string (e.g., "done"). Evaluated entirely in SQL-land via a JOIN.
|
|
464
|
+
* 'llm' — not yet implemented; always returns false here. Future
|
|
465
|
+
* implementation would call completeSimple() to evaluate the condition
|
|
466
|
+
* expression against the current state of both projections and the
|
|
467
|
+
* agent's archival memory.
|
|
468
|
+
*
|
|
469
|
+
* Returns the total number of observer projections activated.
|
|
470
|
+
*/
|
|
471
|
+
evaluateDependencies() {
|
|
472
|
+
let activatedTotal = 0;
|
|
473
|
+
// Iterate until stable so multiple newly-satisfied observers can activate in one pass.
|
|
474
|
+
for (let iteration = 0; iteration < 10; iteration++) {
|
|
475
|
+
const rows = stmtDependenciesForEvaluation.all();
|
|
476
|
+
const byObserver = new Map();
|
|
477
|
+
for (const row of rows) {
|
|
478
|
+
const group = byObserver.get(row.observer_id) ?? [];
|
|
479
|
+
group.push(row);
|
|
480
|
+
byObserver.set(row.observer_id, group);
|
|
481
|
+
}
|
|
482
|
+
let activatedThisIteration = 0;
|
|
483
|
+
for (const [observerId, deps] of byObserver) {
|
|
484
|
+
const allMet = deps.every((dep) => {
|
|
485
|
+
if (dep.condition_type === "status_change") {
|
|
486
|
+
return dep.subject_status === dep.condition;
|
|
487
|
+
}
|
|
488
|
+
// TODO: 'llm' condition type is not yet implemented. A future
|
|
489
|
+
// implementation would call completeSimple() with the condition
|
|
490
|
+
// string and the subject projection's current state to produce a
|
|
491
|
+
// boolean verdict, rather than relying on a fixed status keyword.
|
|
492
|
+
return false;
|
|
493
|
+
});
|
|
494
|
+
if (!allMet)
|
|
495
|
+
continue;
|
|
496
|
+
const result = stmtActivateObserver.run(observerId);
|
|
497
|
+
if (result.changes > 0) {
|
|
498
|
+
stmtDeleteDependenciesByObserver.run(observerId);
|
|
499
|
+
activatedThisIteration++;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
activatedTotal += activatedThisIteration;
|
|
503
|
+
if (activatedThisIteration === 0)
|
|
504
|
+
break;
|
|
505
|
+
}
|
|
506
|
+
return activatedTotal;
|
|
507
|
+
},
|
|
508
|
+
getDependencies(observerId) {
|
|
509
|
+
const rows = observerId
|
|
510
|
+
? stmtDependenciesListByObserver.all(observerId)
|
|
511
|
+
: stmtDependenciesList.all();
|
|
512
|
+
return rows.map(rowToDependency);
|
|
513
|
+
},
|
|
514
|
+
close() {
|
|
515
|
+
db.close();
|
|
516
|
+
},
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/projection/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AA8JnD,SAAS,eAAe,CAAC,GAAkB;IACzC,IAAI,UAAU,GAAa,EAAE,CAAC;IAC9B,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC;QACnB,IAAI,CAAC;YACH,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAa,CAAC;QACtD,CAAC;QAAC,MAAM,CAAC;YACP,UAAU,GAAG,EAAE,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,aAAa,EAAE,GAAG,CAAC,aAAa;QAChC,UAAU,EAAE,GAAG,CAAC,UAAkC;QAClD,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B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4
|
+
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
5
|
+
import type { ProjectionStore } from "./store.js";
|
|
6
|
+
/**
|
|
7
|
+
* Create projection tools. When timezone is set, naive datetimes from the
|
|
8
|
+
* agent are converted to UTC before storage.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createProjectionTools(store: ProjectionStore, timezone?: string): AgentTool<any>[];
|
|
11
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/projection/tools.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAmB,MAAM,6BAA6B,CAAC;AAG9E,OAAO,KAAK,EAAiD,eAAe,EAAE,MAAM,YAAY,CAAC;AA8HjG;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,eAAe,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,EAAE,CAiJjG"}
|