@thready-web/dsh-bot-plugin 0.1.0-beta.1 → 0.1.0-beta.11
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 +109 -1
- package/client.js +646 -621
- package/dist/approvals.js +160 -0
- package/dist/authorization.js +225 -0
- package/dist/canvas-http.js +248 -0
- package/dist/canvas-skills.js +56 -0
- package/dist/canvas-store.js +794 -0
- package/dist/canvas-tools.js +211 -0
- package/dist/cli.js +32 -12
- package/dist/context.js +60 -17
- package/dist/cron.js +1 -1
- package/dist/cua-access.js +79 -0
- package/dist/desk.js +314 -37
- package/dist/engine.js +178 -84
- package/dist/fs-safe.js +1 -1
- package/dist/host.js +1 -0
- package/dist/http-plugin.js +14 -4
- package/dist/http.js +402 -85
- package/dist/inbox.js +51 -40
- package/dist/index.js +201 -47
- package/dist/live-diff.js +3 -1
- package/dist/live-snapshot.js +2 -13
- package/dist/log/canonical.js +37 -0
- package/dist/log/plan.js +62 -0
- package/dist/log/routes.js +144 -0
- package/dist/log/snapshot-service.js +76 -0
- package/dist/log/source.js +173 -0
- package/dist/memory-catalog.js +798 -0
- package/dist/permissions.js +86 -0
- package/dist/provision.js +2 -0
- package/dist/questions.js +407 -0
- package/dist/runtime-registry.js +4 -4
- package/dist/session-files.js +2 -2
- package/dist/session-previews.js +5 -1
- package/dist/store.js +20 -5
- package/dist/tools.js +150 -32
- package/dist/triggers.js +83 -39
- package/dist/work-admit.js +222 -25
- package/dist/work-child.js +17 -9
- package/dist/work-http.js +52 -2
- package/dist/work-ledger.js +256 -16
- package/dist/work-mock-host.js +9 -6
- package/dist/work-mock.js +29 -19
- package/dist/work-tickets.js +423 -96
- package/dist/work-tools.js +43 -6
- package/dist/work-worker.js +1033 -207
- package/dist/workspace-files.js +319 -0
- package/dist/workspace-image.js +91 -0
- package/fixtures/mock-llm.mjs +17 -2
- package/package.json +16 -5
- package/public/assets/SourceEditor-CJwK846Z.css +1 -0
- package/public/assets/SourceEditor-uu0G7jsM.js +669 -0
- package/public/assets/abap-CRCWOmpq.js +1 -0
- package/public/assets/apex-DnsZk_dE.js +1 -0
- package/public/assets/azcli-1IWB1ccx.js +1 -0
- package/public/assets/bat-DPkNLes8.js +1 -0
- package/public/assets/bicep-Corcdgou.js +2 -0
- package/public/assets/cameligo-CGrWLZr3.js +1 -0
- package/public/assets/clojure-D9WOWImG.js +1 -0
- package/public/assets/codicon-DCmgc-ay.ttf +0 -0
- package/public/assets/coffee-B7EJu28W.js +1 -0
- package/public/assets/cpp-SEyurbux.js +1 -0
- package/public/assets/csharp-BoL64M5l.js +1 -0
- package/public/assets/csp-C46ZqvIl.js +1 -0
- package/public/assets/css-DQU6DXDx.js +3 -0
- package/public/assets/css.worker-DYpkewsP.js +79 -0
- package/public/assets/cssMode-C5DAFF5H.js +4 -0
- package/public/assets/cypher-D84EuPTj.js +1 -0
- package/public/assets/dart-D8lhlL1r.js +1 -0
- package/public/assets/dockerfile-DLk6rpji.js +1 -0
- package/public/assets/ecl-BO6FnfXk.js +1 -0
- package/public/assets/editor.worker-B4pQIWZD.js +12 -0
- package/public/assets/elixir-BRjLKONM.js +1 -0
- package/public/assets/flow9-Cac8vKd7.js +1 -0
- package/public/assets/freemarker2-DExNwSiZ.js +3 -0
- package/public/assets/fsharp-fd1GTHhf.js +1 -0
- package/public/assets/go-O9LJTZXk.js +1 -0
- package/public/assets/graphql-LQdxqEYJ.js +1 -0
- package/public/assets/handlebars-BK7YAvpQ.js +1 -0
- package/public/assets/hcl-DxDQ3s82.js +1 -0
- package/public/assets/html-CdDm_zae.js +1 -0
- package/public/assets/html.worker-tnXziJOq.js +456 -0
- package/public/assets/htmlMode-CLdn9oa1.js +4 -0
- package/public/assets/index-BB-QDSf2.css +1 -0
- package/public/assets/index-CsX-_qbo.js +62 -0
- package/public/assets/ini-BvajGCUy.js +1 -0
- package/public/assets/java-SYsfObOQ.js +1 -0
- package/public/assets/javascript-mLl83_3W.js +1 -0
- package/public/assets/json.worker-aFakAbRR.js +44 -0
- package/public/assets/jsonMode-B1-bihFd.js +10 -0
- package/public/assets/julia-DQXNmw_w.js +1 -0
- package/public/assets/kotlin-qQ0MG-9I.js +1 -0
- package/public/assets/less-GGFNNJHn.js +2 -0
- package/public/assets/lexon-Canl7DCW.js +1 -0
- package/public/assets/liquid-Cv8m0HUb.js +1 -0
- package/public/assets/lua-D28Ae8-K.js +1 -0
- package/public/assets/m3-DPitgjJI.js +1 -0
- package/public/assets/markdown-B811l8j2.js +1 -0
- package/public/assets/mdx-Q12b91rL.js +1 -0
- package/public/assets/mips-CdjsipkG.js +1 -0
- package/public/assets/msdax-CYqgjx_P.js +1 -0
- package/public/assets/mysql-BHd6q0vd.js +1 -0
- package/public/assets/objective-c-B1aVtJYH.js +1 -0
- package/public/assets/pascal-BhNW15KB.js +1 -0
- package/public/assets/pascaligo-5jv8CcQD.js +1 -0
- package/public/assets/perl-DlYyT36c.js +1 -0
- package/public/assets/pgsql-Dy0bjov7.js +1 -0
- package/public/assets/php-120yhfDK.js +1 -0
- package/public/assets/pla-CjnFlu4u.js +1 -0
- package/public/assets/postiats-CQpG440k.js +1 -0
- package/public/assets/powerquery-DdJtto1Z.js +1 -0
- package/public/assets/powershell-Bu_VLpJB.js +1 -0
- package/public/assets/protobuf-IBS6jZEB.js +2 -0
- package/public/assets/pug-kFxLfcjb.js +1 -0
- package/public/assets/python-Kda811W0.js +1 -0
- package/public/assets/qsharp-q7JyzKFN.js +1 -0
- package/public/assets/r-BIFz-_sK.js +1 -0
- package/public/assets/razor-CRuCpdOW.js +1 -0
- package/public/assets/redis-CHOsPHWR.js +1 -0
- package/public/assets/redshift-CBifECDb.js +1 -0
- package/public/assets/restructuredtext-CghPJEOS.js +1 -0
- package/public/assets/ruby-CYWGW-b1.js +1 -0
- package/public/assets/rust-DMDD0SHb.js +1 -0
- package/public/assets/sb-BYAiYHFx.js +1 -0
- package/public/assets/scala-Bqvq8jcR.js +1 -0
- package/public/assets/scheme-Dhb-2j9p.js +1 -0
- package/public/assets/scss-CTwUZ5N7.js +3 -0
- package/public/assets/shell-CsDZo4DB.js +1 -0
- package/public/assets/solidity-CME5AdoB.js +1 -0
- package/public/assets/sophia-RYC1BQQz.js +1 -0
- package/public/assets/sparql-KEyrF7De.js +1 -0
- package/public/assets/sql-BdTr02Mf.js +1 -0
- package/public/assets/st-C7iG7M4S.js +1 -0
- package/public/assets/swift-D7IUmUK8.js +1 -0
- package/public/assets/systemverilog-DgMryOEJ.js +1 -0
- package/public/assets/tcl-PloMZuKG.js +1 -0
- package/public/assets/ts.worker-Bij5J2kb.js +51316 -0
- package/public/assets/tsMode-BGHcz-M3.js +11 -0
- package/public/assets/twig-BfRIq3la.js +1 -0
- package/public/assets/typescript-Db1e0DCT.js +1 -0
- package/public/assets/typespec-CzxlYoT_.js +1 -0
- package/public/assets/vb-BwAE3J76.js +1 -0
- package/public/assets/wgsl-B_1kOXbF.js +298 -0
- package/public/assets/xml-H3zzFmnd.js +1 -0
- package/public/assets/yaml-BQrKvmTF.js +1 -0
- package/public/index.html +2 -2
- package/skills/ui/baseline-ui/SKILL.md +85 -0
- package/skills/ui/bencium-innovative-ux-designer/SKILL.md +227 -0
- package/skills/ui/better-ui/SKILL.md +133 -0
- package/skills/ui/design-lab/SKILL.md +920 -0
- package/skills/ui/frontend-design/SKILL.md +71 -0
- package/skills/ui/impeccable/SKILL.md +93 -0
- package/skills/ui/interface-design/SKILL.md +320 -0
- package/skills/ui/sources.json +66 -0
- package/skills/ui/ui-design/SKILL.md +35 -0
- package/skills/ui/ui-skills-root/SKILL.md +59 -0
- package/skills/ui/visual-design-foundations/SKILL.md +318 -0
- package/skills/ui/web-design-guidelines/SKILL.md +39 -0
- package/public/assets/index-Be82iGwe.css +0 -1
- package/public/assets/index-ByU9a3Lh.js +0 -61
package/dist/engine.js
CHANGED
|
@@ -37,12 +37,14 @@ export class Engine {
|
|
|
37
37
|
if (existing)
|
|
38
38
|
return existing;
|
|
39
39
|
const created = now();
|
|
40
|
-
this.store.db
|
|
40
|
+
this.store.db
|
|
41
|
+
.prepare(`
|
|
41
42
|
INSERT INTO session_bindings (
|
|
42
43
|
session_id, kind, status, schema_version, persona_version_id, fork_parent_session_id,
|
|
43
44
|
fork_seeded, last_view_revision, compaction_epoch, error_code, created_at, updated_at
|
|
44
45
|
) VALUES (?, 'session', 'active', 1, NULL, ?, ?, 0, 0, NULL, ?, ?)
|
|
45
|
-
`)
|
|
46
|
+
`)
|
|
47
|
+
.run(sessionId, fork.parentSessionId ?? null, fork.seeded ? 1 : 0, created, created);
|
|
46
48
|
return this.binding(sessionId);
|
|
47
49
|
}
|
|
48
50
|
/**
|
|
@@ -69,22 +71,29 @@ export class Engine {
|
|
|
69
71
|
const stamped = now();
|
|
70
72
|
if (existing) {
|
|
71
73
|
if (existing.kind !== 'bot') {
|
|
72
|
-
this.store.db
|
|
74
|
+
this.store.db
|
|
75
|
+
.prepare(`UPDATE session_bindings SET kind = 'bot', updated_at = ? WHERE session_id = ?`)
|
|
76
|
+
.run(stamped, sessionId);
|
|
73
77
|
}
|
|
74
78
|
return this.binding(sessionId);
|
|
75
79
|
}
|
|
76
|
-
this.store.db
|
|
80
|
+
this.store.db
|
|
81
|
+
.prepare(`
|
|
77
82
|
INSERT INTO session_bindings (
|
|
78
83
|
session_id, kind, status, schema_version, persona_version_id, fork_parent_session_id,
|
|
79
84
|
fork_seeded, last_view_revision, compaction_epoch, error_code, created_at, updated_at
|
|
80
85
|
) VALUES (?, 'bot', 'active', 1, NULL, NULL, 0, 0, 0, NULL, ?, ?)
|
|
81
|
-
`)
|
|
86
|
+
`)
|
|
87
|
+
.run(sessionId, stamped, stamped);
|
|
82
88
|
return this.binding(sessionId);
|
|
83
89
|
}
|
|
84
90
|
listBots() {
|
|
85
|
-
return this.store.db
|
|
91
|
+
return this.store.db
|
|
92
|
+
.prepare(`
|
|
86
93
|
SELECT session_id, persona_version_id FROM session_bindings WHERE kind = 'bot' ORDER BY created_at
|
|
87
|
-
`)
|
|
94
|
+
`)
|
|
95
|
+
.all()
|
|
96
|
+
.map(row => {
|
|
88
97
|
const persona = row.persona_version_id == null ? null : this.persona(row.persona_version_id);
|
|
89
98
|
const bytes = persona ? this.store.readBlob('persona', persona.content_hash) : null;
|
|
90
99
|
const name = bytes ? splitPersona(bytes.toString('utf8')).name : '';
|
|
@@ -120,10 +129,12 @@ export class Engine {
|
|
|
120
129
|
if (existing)
|
|
121
130
|
return existing;
|
|
122
131
|
const created = now();
|
|
123
|
-
this.store.db
|
|
132
|
+
this.store.db
|
|
133
|
+
.prepare(`
|
|
124
134
|
INSERT INTO persona_versions (content_hash, byte_length, note, created_by, created_at)
|
|
125
135
|
VALUES (?, ?, ?, 'user', ?)
|
|
126
|
-
`)
|
|
136
|
+
`)
|
|
137
|
+
.run(hash, bytes.length, note ?? null, created);
|
|
127
138
|
return this.store.db.prepare('SELECT * FROM persona_versions WHERE content_hash = ?').get(hash);
|
|
128
139
|
}
|
|
129
140
|
/**
|
|
@@ -136,11 +147,13 @@ export class Engine {
|
|
|
136
147
|
else
|
|
137
148
|
this.ensureSession(sessionId);
|
|
138
149
|
if (personaId == null) {
|
|
139
|
-
this.store.db
|
|
150
|
+
this.store.db
|
|
151
|
+
.prepare(`
|
|
140
152
|
UPDATE session_bindings
|
|
141
153
|
SET persona_version_id = NULL, status = 'active', error_code = NULL, updated_at = ?
|
|
142
154
|
WHERE session_id = ?
|
|
143
|
-
`)
|
|
155
|
+
`)
|
|
156
|
+
.run(now(), sessionId);
|
|
144
157
|
return this.binding(sessionId);
|
|
145
158
|
}
|
|
146
159
|
const persona = this.persona(personaId);
|
|
@@ -150,11 +163,13 @@ export class Engine {
|
|
|
150
163
|
this.markError(sessionId, 'HASH_MISMATCH');
|
|
151
164
|
throw Object.assign(new Error('persona blob does not match its hash'), { code: 'HASH_MISMATCH' });
|
|
152
165
|
}
|
|
153
|
-
this.store.db
|
|
166
|
+
this.store.db
|
|
167
|
+
.prepare(`
|
|
154
168
|
UPDATE session_bindings
|
|
155
169
|
SET persona_version_id = ?, status = 'active', error_code = NULL, updated_at = ?
|
|
156
170
|
WHERE session_id = ?
|
|
157
|
-
`)
|
|
171
|
+
`)
|
|
172
|
+
.run(personaId, now(), sessionId);
|
|
158
173
|
return this.binding(sessionId);
|
|
159
174
|
}
|
|
160
175
|
/**
|
|
@@ -162,9 +177,11 @@ export class Engine {
|
|
|
162
177
|
* @param {string} code
|
|
163
178
|
*/
|
|
164
179
|
markError(sessionId, code) {
|
|
165
|
-
this.store.db
|
|
180
|
+
this.store.db
|
|
181
|
+
.prepare(`
|
|
166
182
|
UPDATE session_bindings SET status = 'error', error_code = ?, updated_at = ? WHERE session_id = ?
|
|
167
|
-
`)
|
|
183
|
+
`)
|
|
184
|
+
.run(code, now(), sessionId);
|
|
168
185
|
}
|
|
169
186
|
/**
|
|
170
187
|
* @param {string} sessionId
|
|
@@ -176,9 +193,11 @@ export class Engine {
|
|
|
176
193
|
const current = this.binding(sessionId).last_event_watermark;
|
|
177
194
|
if (current != null && BigInt(current) >= BigInt(watermark))
|
|
178
195
|
return;
|
|
179
|
-
this.store.db
|
|
196
|
+
this.store.db
|
|
197
|
+
.prepare(`
|
|
180
198
|
UPDATE session_bindings SET last_event_watermark = ?, updated_at = ? WHERE session_id = ?
|
|
181
|
-
`)
|
|
199
|
+
`)
|
|
200
|
+
.run(watermark, now(), sessionId);
|
|
182
201
|
}
|
|
183
202
|
/**
|
|
184
203
|
* @param {string} sessionId
|
|
@@ -187,10 +206,11 @@ export class Engine {
|
|
|
187
206
|
checkSource(sessionId, sourceEventId) {
|
|
188
207
|
if (sourceEventId == null || sourceEventId === '')
|
|
189
208
|
return null;
|
|
190
|
-
|
|
209
|
+
const sourceText = typeof sourceEventId === 'string' ? sourceEventId : String(sourceEventId);
|
|
210
|
+
if (!/^\d+$/.test(sourceText))
|
|
191
211
|
return toolError('VALIDATION', 'sourceEventId must be an event sequence number in this session.');
|
|
192
212
|
const watermark = this.binding(sessionId)?.last_event_watermark;
|
|
193
|
-
if (watermark == null || BigInt(
|
|
213
|
+
if (watermark == null || BigInt(sourceText) > BigInt(watermark)) {
|
|
194
214
|
return toolError('VALIDATION', 'sourceEventId is outside the events this session has observed.');
|
|
195
215
|
}
|
|
196
216
|
return null;
|
|
@@ -199,35 +219,55 @@ export class Engine {
|
|
|
199
219
|
* @param {string} sessionId
|
|
200
220
|
* @param {number} turn
|
|
201
221
|
*/
|
|
202
|
-
|
|
222
|
+
/**
|
|
223
|
+
* Active facts, persona, state, and skills as freeze would select them.
|
|
224
|
+
* Does not insert a view revision.
|
|
225
|
+
* @param {string} sessionId
|
|
226
|
+
*/
|
|
227
|
+
liveSelection(sessionId) {
|
|
203
228
|
const binding = this.ensureSession(sessionId);
|
|
204
229
|
const state = this.stateRow(sessionId);
|
|
205
|
-
const facts = this.store.db
|
|
230
|
+
const facts = this.store.db
|
|
231
|
+
.prepare(`
|
|
206
232
|
SELECT id FROM facts WHERE session_id = ? AND status = 'active'
|
|
207
233
|
ORDER BY priority DESC, updated_at DESC, id DESC
|
|
208
|
-
`)
|
|
209
|
-
|
|
234
|
+
`)
|
|
235
|
+
.all(sessionId)
|
|
236
|
+
.map(row => row.id);
|
|
237
|
+
const skills = this.store.db
|
|
238
|
+
.prepare(`
|
|
210
239
|
SELECT skill_id, version, summary, enabled, revoked, scope
|
|
211
240
|
FROM skill_bindings WHERE session_id = ? ORDER BY skill_id
|
|
212
|
-
`)
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
241
|
+
`)
|
|
242
|
+
.all(sessionId);
|
|
243
|
+
return {
|
|
244
|
+
binding,
|
|
245
|
+
selected: {
|
|
246
|
+
factIds: facts,
|
|
247
|
+
memoryIds: [],
|
|
248
|
+
personaVersionId: binding.persona_version_id,
|
|
249
|
+
workingStateRev: state?.revision ?? 0,
|
|
250
|
+
skills,
|
|
251
|
+
},
|
|
219
252
|
};
|
|
253
|
+
}
|
|
254
|
+
freeze(sessionId, turn) {
|
|
255
|
+
const { binding, selected } = this.liveSelection(sessionId);
|
|
220
256
|
const revision = binding.last_view_revision + 1;
|
|
221
257
|
const frozenAt = now();
|
|
222
|
-
this.store.db
|
|
258
|
+
this.store.db
|
|
259
|
+
.prepare(`
|
|
223
260
|
INSERT INTO view_revisions (
|
|
224
261
|
session_id, revision, frozen_at, event_watermark, persona_version_id, working_state_rev,
|
|
225
262
|
snapshot_hash, compaction_epoch, presence, selected_json
|
|
226
263
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'unknown', ?)
|
|
227
|
-
`)
|
|
228
|
-
|
|
264
|
+
`)
|
|
265
|
+
.run(sessionId, revision, frozenAt, binding.last_event_watermark, binding.persona_version_id, selected.workingStateRev, 'pending', binding.compaction_epoch, JSON.stringify(selected));
|
|
266
|
+
this.store.db
|
|
267
|
+
.prepare(`
|
|
229
268
|
UPDATE session_bindings SET last_view_revision = ?, updated_at = ? WHERE session_id = ?
|
|
230
|
-
`)
|
|
269
|
+
`)
|
|
270
|
+
.run(revision, frozenAt, sessionId);
|
|
231
271
|
this.openViews.set(sessionId, { revision, turn });
|
|
232
272
|
return this.view(sessionId, revision);
|
|
233
273
|
}
|
|
@@ -246,9 +286,11 @@ export class Engine {
|
|
|
246
286
|
* @param {number} revision
|
|
247
287
|
*/
|
|
248
288
|
view(sessionId, revision) {
|
|
249
|
-
const row = this.store.db
|
|
289
|
+
const row = this.store.db
|
|
290
|
+
.prepare(`
|
|
250
291
|
SELECT * FROM view_revisions WHERE session_id = ? AND revision = ?
|
|
251
|
-
`)
|
|
292
|
+
`)
|
|
293
|
+
.get(sessionId, revision);
|
|
252
294
|
if (!row)
|
|
253
295
|
return null;
|
|
254
296
|
return { ...row, selected: JSON.parse(row.selected_json) };
|
|
@@ -272,9 +314,11 @@ export class Engine {
|
|
|
272
314
|
* @param {'present' | 'unknown' | 'needs_reinject'} presence
|
|
273
315
|
*/
|
|
274
316
|
recordSnapshot(sessionId, revision, hash, presence) {
|
|
275
|
-
this.store.db
|
|
317
|
+
this.store.db
|
|
318
|
+
.prepare(`
|
|
276
319
|
UPDATE view_revisions SET snapshot_hash = ?, presence = ? WHERE session_id = ? AND revision = ?
|
|
277
|
-
`)
|
|
320
|
+
`)
|
|
321
|
+
.run(hash, presence, sessionId, revision);
|
|
278
322
|
}
|
|
279
323
|
/**
|
|
280
324
|
* Adapter-internal counter. Not a DSH field.
|
|
@@ -286,14 +330,18 @@ export class Engine {
|
|
|
286
330
|
if (!binding)
|
|
287
331
|
return;
|
|
288
332
|
const epoch = binding.compaction_epoch + 1;
|
|
289
|
-
this.store.db
|
|
333
|
+
this.store.db
|
|
334
|
+
.prepare(`
|
|
290
335
|
UPDATE session_bindings SET compaction_epoch = ?, updated_at = ? WHERE session_id = ?
|
|
291
|
-
`)
|
|
292
|
-
|
|
336
|
+
`)
|
|
337
|
+
.run(epoch, now(), sessionId);
|
|
338
|
+
this.store.db
|
|
339
|
+
.prepare(`
|
|
293
340
|
UPDATE view_revisions
|
|
294
341
|
SET compaction_epoch = ?, presence = ?
|
|
295
342
|
WHERE session_id = ? AND revision = ?
|
|
296
|
-
`)
|
|
343
|
+
`)
|
|
344
|
+
.run(epoch, presence, sessionId, binding.last_view_revision);
|
|
297
345
|
}
|
|
298
346
|
/**
|
|
299
347
|
* @param {string} sessionId
|
|
@@ -304,10 +352,12 @@ export class Engine {
|
|
|
304
352
|
const binding = this.binding(sessionId);
|
|
305
353
|
if (!binding)
|
|
306
354
|
return;
|
|
307
|
-
this.store.db
|
|
355
|
+
this.store.db
|
|
356
|
+
.prepare(`
|
|
308
357
|
UPDATE view_revisions SET presence = 'present'
|
|
309
358
|
WHERE session_id = ? AND revision = ? AND snapshot_hash != 'pending'
|
|
310
|
-
`)
|
|
359
|
+
`)
|
|
360
|
+
.run(sessionId, binding.last_view_revision);
|
|
311
361
|
}
|
|
312
362
|
/**
|
|
313
363
|
* @param {string} sessionId
|
|
@@ -341,10 +391,12 @@ export class Engine {
|
|
|
341
391
|
* @param {string} sessionId
|
|
342
392
|
*/
|
|
343
393
|
revokedSkills(sessionId) {
|
|
344
|
-
return this.store.db
|
|
394
|
+
return this.store.db
|
|
395
|
+
.prepare(`
|
|
345
396
|
SELECT skill_id, version FROM skill_bindings
|
|
346
397
|
WHERE session_id = ? AND revoked = 1 ORDER BY skill_id
|
|
347
|
-
`)
|
|
398
|
+
`)
|
|
399
|
+
.all(sessionId);
|
|
348
400
|
}
|
|
349
401
|
/**
|
|
350
402
|
* @param {number[]} ids
|
|
@@ -366,9 +418,11 @@ export class Engine {
|
|
|
366
418
|
* @param {number} viewRevision
|
|
367
419
|
*/
|
|
368
420
|
mutate(sessionId, idempotencyKey, payloadHash, toolName, request, apply, viewRevision) {
|
|
369
|
-
const prior = this.store.db
|
|
421
|
+
const prior = this.store.db
|
|
422
|
+
.prepare(`
|
|
370
423
|
SELECT * FROM mutations WHERE scope = ? AND idempotency_key = ?
|
|
371
|
-
`)
|
|
424
|
+
`)
|
|
425
|
+
.get(sessionId, idempotencyKey);
|
|
372
426
|
if (prior) {
|
|
373
427
|
if (prior.payload_hash !== payloadHash)
|
|
374
428
|
return toolError('IDEMPOTENCY_KEY_REUSE', 'The same idempotency key was reused for different content.');
|
|
@@ -386,24 +440,30 @@ export class Engine {
|
|
|
386
440
|
data: data.data,
|
|
387
441
|
export: 'pending',
|
|
388
442
|
};
|
|
389
|
-
const info = this.store.db
|
|
443
|
+
const info = this.store.db
|
|
444
|
+
.prepare(`
|
|
390
445
|
INSERT INTO mutations (
|
|
391
446
|
scope, idempotency_key, payload_hash, tool_name, request_json, result_json, outcome, created_at
|
|
392
447
|
) VALUES (?, ?, ?, ?, ?, ?, 'applied', ?)
|
|
393
|
-
`)
|
|
394
|
-
|
|
448
|
+
`)
|
|
449
|
+
.run(sessionId, idempotencyKey, payloadHash, toolName, JSON.stringify(request), JSON.stringify(result), now());
|
|
450
|
+
this.store.db
|
|
451
|
+
.prepare(`
|
|
395
452
|
INSERT INTO export_outbox (session_id, mutation_id, status, attempts, updated_at)
|
|
396
453
|
VALUES (?, ?, 'pending', 0, ?)
|
|
397
|
-
`)
|
|
454
|
+
`)
|
|
455
|
+
.run(sessionId, Number(info.lastInsertRowid), now());
|
|
398
456
|
return { ...result, mutationId: Number(info.lastInsertRowid) };
|
|
399
457
|
}
|
|
400
458
|
/**
|
|
401
459
|
* @param {string} sessionId
|
|
402
460
|
*/
|
|
403
461
|
async flushExport(sessionId) {
|
|
404
|
-
const rows = this.store.db
|
|
462
|
+
const rows = this.store.db
|
|
463
|
+
.prepare(`
|
|
405
464
|
SELECT * FROM export_outbox WHERE session_id = ? AND status IN ('pending','failed') ORDER BY id
|
|
406
|
-
`)
|
|
465
|
+
`)
|
|
466
|
+
.all(sessionId);
|
|
407
467
|
for (const row of rows)
|
|
408
468
|
await this.exportOne(row);
|
|
409
469
|
}
|
|
@@ -416,16 +476,20 @@ export class Engine {
|
|
|
416
476
|
const dir = join(this.store.root, 'export', row.session_id);
|
|
417
477
|
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
418
478
|
writeFileSync(join(dir, 'memory.md'), text, { mode: 0o600 });
|
|
419
|
-
this.store.db
|
|
479
|
+
this.store.db
|
|
480
|
+
.prepare(`
|
|
420
481
|
UPDATE export_outbox SET status = 'done', attempts = ?, last_error = NULL, updated_at = ? WHERE id = ?
|
|
421
|
-
`)
|
|
482
|
+
`)
|
|
483
|
+
.run(row.attempts + 1, now(), row.id);
|
|
422
484
|
return { ok: true };
|
|
423
485
|
}
|
|
424
486
|
catch (error) {
|
|
425
487
|
const message = error instanceof Error ? error.message : String(error);
|
|
426
|
-
this.store.db
|
|
488
|
+
this.store.db
|
|
489
|
+
.prepare(`
|
|
427
490
|
UPDATE export_outbox SET status = 'failed', attempts = ?, last_error = ?, updated_at = ? WHERE id = ?
|
|
428
|
-
`)
|
|
491
|
+
`)
|
|
492
|
+
.run(row.attempts + 1, message, now(), row.id);
|
|
429
493
|
return { ok: false, error: message };
|
|
430
494
|
}
|
|
431
495
|
}
|
|
@@ -433,16 +497,22 @@ export class Engine {
|
|
|
433
497
|
* @param {string} sessionId
|
|
434
498
|
*/
|
|
435
499
|
exportMarkdown(sessionId) {
|
|
436
|
-
const facts = this.store.db
|
|
500
|
+
const facts = this.store.db
|
|
501
|
+
.prepare(`
|
|
437
502
|
SELECT id, revision, content, status FROM facts WHERE session_id = ? ORDER BY id
|
|
438
|
-
`)
|
|
439
|
-
|
|
503
|
+
`)
|
|
504
|
+
.all(sessionId);
|
|
505
|
+
const memories = this.store.db
|
|
506
|
+
.prepare(`
|
|
440
507
|
SELECT id, revision, title, content, status FROM memories WHERE session_id = ? ORDER BY id
|
|
441
|
-
`)
|
|
508
|
+
`)
|
|
509
|
+
.all(sessionId);
|
|
442
510
|
const state = this.statePayload(sessionId);
|
|
443
511
|
const lines = [`# session ${sessionId}`, '', '## facts'];
|
|
444
512
|
for (const fact of facts) {
|
|
445
|
-
lines.push(fact.status === 'forgotten'
|
|
513
|
+
lines.push(fact.status === 'forgotten'
|
|
514
|
+
? `- forgotten:${fact.id}`
|
|
515
|
+
: `- ${fact.id} rev ${fact.revision} (${fact.status}): ${fact.content}`);
|
|
446
516
|
}
|
|
447
517
|
lines.push('', '## memories');
|
|
448
518
|
for (const memory of memories) {
|
|
@@ -467,16 +537,20 @@ export class Engine {
|
|
|
467
537
|
if (facts.length === 0 && memories.length === 0 && query.length <= 32) {
|
|
468
538
|
strategy = 'substring';
|
|
469
539
|
const like = `%${query.replace(/[\\%_]/g, char => `\\${char}`)}%`;
|
|
470
|
-
facts = this.store.db
|
|
540
|
+
facts = this.store.db
|
|
541
|
+
.prepare(`
|
|
471
542
|
SELECT id, content, revision, priority FROM facts
|
|
472
543
|
WHERE session_id = ? AND status = 'active' AND content LIKE ? ESCAPE '\\'
|
|
473
544
|
ORDER BY priority DESC, updated_at DESC LIMIT ?
|
|
474
|
-
`)
|
|
475
|
-
|
|
545
|
+
`)
|
|
546
|
+
.all(sessionId, like, limit);
|
|
547
|
+
memories = this.store.db
|
|
548
|
+
.prepare(`
|
|
476
549
|
SELECT id, title, content, revision FROM memories
|
|
477
550
|
WHERE session_id = ? AND status = 'active' AND (content LIKE ? ESCAPE '\\' OR ifnull(title,'') LIKE ? ESCAPE '\\')
|
|
478
551
|
ORDER BY updated_at DESC LIMIT ?
|
|
479
|
-
`)
|
|
552
|
+
`)
|
|
553
|
+
.all(sessionId, like, like, limit);
|
|
480
554
|
}
|
|
481
555
|
return { strategy, facts, memories };
|
|
482
556
|
}
|
|
@@ -504,7 +578,8 @@ export class Engine {
|
|
|
504
578
|
throw Object.assign(new Error('skill blob mismatch'), { code: 'HASH_MISMATCH' });
|
|
505
579
|
}
|
|
506
580
|
const boundAt = now();
|
|
507
|
-
this.store.db
|
|
581
|
+
this.store.db
|
|
582
|
+
.prepare(`
|
|
508
583
|
INSERT INTO skill_bindings (
|
|
509
584
|
session_id, skill_id, scope, version, content_hash, summary, enabled, revoked, bound_at
|
|
510
585
|
) VALUES (?, ?, ?, ?, ?, ?, 1, 0, ?)
|
|
@@ -516,7 +591,8 @@ export class Engine {
|
|
|
516
591
|
enabled = 1,
|
|
517
592
|
revoked = 0,
|
|
518
593
|
bound_at = excluded.bound_at
|
|
519
|
-
`)
|
|
594
|
+
`)
|
|
595
|
+
.run(sessionId, skillId, scope, version, hash, summary, boundAt);
|
|
520
596
|
return this.skillRow(sessionId, skillId);
|
|
521
597
|
}
|
|
522
598
|
/**
|
|
@@ -524,9 +600,11 @@ export class Engine {
|
|
|
524
600
|
* @param {string} skillId
|
|
525
601
|
*/
|
|
526
602
|
skillRow(sessionId, skillId) {
|
|
527
|
-
return this.store.db
|
|
603
|
+
return (this.store.db
|
|
604
|
+
.prepare(`
|
|
528
605
|
SELECT * FROM skill_bindings WHERE session_id = ? AND skill_id = ?
|
|
529
|
-
`)
|
|
606
|
+
`)
|
|
607
|
+
.get(sessionId, skillId) ?? null);
|
|
530
608
|
}
|
|
531
609
|
/**
|
|
532
610
|
* @param {string} sessionId
|
|
@@ -537,11 +615,13 @@ export class Engine {
|
|
|
537
615
|
const row = this.skillRow(sessionId, skillId);
|
|
538
616
|
if (!row)
|
|
539
617
|
throw Object.assign(new Error('skill not bound'), { code: 'NOT_FOUND' });
|
|
540
|
-
const enabled = patch.enabled == null ? row.enabled :
|
|
541
|
-
const revoked = patch.revoked == null ? row.revoked :
|
|
542
|
-
this.store.db
|
|
618
|
+
const enabled = patch.enabled == null ? row.enabled : patch.enabled ? 1 : 0;
|
|
619
|
+
const revoked = patch.revoked == null ? row.revoked : patch.revoked ? 1 : 0;
|
|
620
|
+
this.store.db
|
|
621
|
+
.prepare(`
|
|
543
622
|
UPDATE skill_bindings SET enabled = ?, revoked = ?, bound_at = ? WHERE session_id = ? AND skill_id = ?
|
|
544
|
-
`)
|
|
623
|
+
`)
|
|
624
|
+
.run(enabled, revoked, now(), sessionId, skillId);
|
|
545
625
|
return this.skillRow(sessionId, skillId);
|
|
546
626
|
}
|
|
547
627
|
/**
|
|
@@ -602,7 +682,13 @@ export class Engine {
|
|
|
602
682
|
return this.registerSkill(sessionId, scope, skillId, version, summary.slice(0, 240), bytes);
|
|
603
683
|
}
|
|
604
684
|
recover() {
|
|
605
|
-
const report = {
|
|
685
|
+
const report = {
|
|
686
|
+
bindings: 0,
|
|
687
|
+
errors: [],
|
|
688
|
+
promoted: [],
|
|
689
|
+
ftsRebuilt: false,
|
|
690
|
+
exports: [],
|
|
691
|
+
};
|
|
606
692
|
const personas = this.store.db.prepare('SELECT * FROM persona_versions').all();
|
|
607
693
|
for (const persona of personas) {
|
|
608
694
|
if (!this.personaBlobOk(persona))
|
|
@@ -620,9 +706,11 @@ export class Engine {
|
|
|
620
706
|
report.promoted.push(binding.session_id);
|
|
621
707
|
}
|
|
622
708
|
}
|
|
623
|
-
const skills = this.store.db
|
|
709
|
+
const skills = this.store.db
|
|
710
|
+
.prepare(`
|
|
624
711
|
SELECT * FROM skill_bindings WHERE session_id = ? AND enabled = 1 AND revoked = 0
|
|
625
|
-
`)
|
|
712
|
+
`)
|
|
713
|
+
.all(binding.session_id);
|
|
626
714
|
for (const skill of skills) {
|
|
627
715
|
const bytes = this.store.readBlob('skill', skill.content_hash);
|
|
628
716
|
if (bytes == null || sha256(bytes) !== skill.content_hash) {
|
|
@@ -631,10 +719,12 @@ export class Engine {
|
|
|
631
719
|
}
|
|
632
720
|
}
|
|
633
721
|
if (binding.last_view_revision > 0) {
|
|
634
|
-
this.store.db
|
|
722
|
+
this.store.db
|
|
723
|
+
.prepare(`
|
|
635
724
|
UPDATE view_revisions SET presence = 'unknown'
|
|
636
725
|
WHERE session_id = ? AND revision = ? AND presence = 'present'
|
|
637
|
-
`)
|
|
726
|
+
`)
|
|
727
|
+
.run(binding.session_id, binding.last_view_revision);
|
|
638
728
|
}
|
|
639
729
|
}
|
|
640
730
|
report.ftsRebuilt = rebuildFtsIfNeeded(this.store.db);
|
|
@@ -662,21 +752,25 @@ function searchFts(db, fts, columns, sessionId, table, query, limit) {
|
|
|
662
752
|
const match = `"${query.replaceAll('"', ' ')}"`;
|
|
663
753
|
try {
|
|
664
754
|
if (table === 'facts') {
|
|
665
|
-
return db
|
|
755
|
+
return db
|
|
756
|
+
.prepare(`
|
|
666
757
|
SELECT f.id, f.content, f.revision, f.priority
|
|
667
758
|
FROM facts_fts
|
|
668
759
|
JOIN facts f ON f.id = facts_fts.rowid
|
|
669
760
|
WHERE facts_fts MATCH ? AND f.session_id = ? AND f.status = 'active'
|
|
670
761
|
LIMIT ?
|
|
671
|
-
`)
|
|
762
|
+
`)
|
|
763
|
+
.all(match, sessionId, limit);
|
|
672
764
|
}
|
|
673
|
-
return db
|
|
765
|
+
return db
|
|
766
|
+
.prepare(`
|
|
674
767
|
SELECT m.id, m.title, m.content, m.revision
|
|
675
768
|
FROM memories_fts
|
|
676
769
|
JOIN memories m ON m.id = memories_fts.rowid
|
|
677
770
|
WHERE memories_fts MATCH ? AND m.session_id = ? AND m.status = 'active'
|
|
678
771
|
LIMIT ?
|
|
679
|
-
`)
|
|
772
|
+
`)
|
|
773
|
+
.all(match, sessionId, limit);
|
|
680
774
|
}
|
|
681
775
|
catch {
|
|
682
776
|
return [];
|
package/dist/fs-safe.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { closeSync, constants, fsyncSync, lstatSync, mkdirSync, openSync, readSync, realpathSync, renameSync, writeSync } from 'node:fs';
|
|
1
|
+
import { closeSync, constants, fsyncSync, lstatSync, mkdirSync, openSync, readSync, realpathSync, renameSync, writeSync, } from 'node:fs';
|
|
2
2
|
import { basename, dirname, join, relative, sep } from 'node:path';
|
|
3
3
|
import { createHash, randomBytes } from 'node:crypto';
|
|
4
4
|
const OPEN_FLAGS = constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0);
|
package/dist/host.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/http-plugin.js
CHANGED
|
@@ -3,9 +3,12 @@ import { join } from 'node:path';
|
|
|
3
3
|
import { openStore } from "./store.js";
|
|
4
4
|
import { createEngine } from "./engine.js";
|
|
5
5
|
import { registerHttp } from "./http.js";
|
|
6
|
+
import { questionAnswererFor } from "./questions.js";
|
|
7
|
+
import { approvalAnswererFor } from "./approvals.js";
|
|
8
|
+
import { authorizationFor } from "./authorization.js";
|
|
6
9
|
import { runtimeFor, workRuntimeFor } from "./runtime-registry.js";
|
|
7
10
|
export const name = 'session-foundations-http';
|
|
8
|
-
export const inject = ['webServer', 'agents', 'sessionPersistence'];
|
|
11
|
+
export const inject = ['webServer', 'agents', 'sessionPersistence', 'sessionQuery', 'sessions'];
|
|
9
12
|
/**
|
|
10
13
|
* Local management routes for the same SQLite the main plugin uses.
|
|
11
14
|
* Loaded only on profiles that have a web server, so headless does not need it.
|
|
@@ -22,12 +25,19 @@ export function apply(ctx, config = {}) {
|
|
|
22
25
|
try {
|
|
23
26
|
store.close();
|
|
24
27
|
}
|
|
25
|
-
catch {
|
|
28
|
+
catch {
|
|
29
|
+
/* closed */
|
|
30
|
+
}
|
|
26
31
|
});
|
|
27
32
|
let key = dataDir;
|
|
28
33
|
try {
|
|
29
34
|
key = realpathSync(dataDir);
|
|
30
35
|
}
|
|
31
|
-
catch {
|
|
32
|
-
|
|
36
|
+
catch {
|
|
37
|
+
/* not created yet */
|
|
38
|
+
}
|
|
39
|
+
registerHttp(ctx, engine, () => runtimeFor(key) ?? runtimeFor(dataDir), () => workRuntimeFor(key) ?? workRuntimeFor(dataDir), dataDir, () => questionAnswererFor(key) ?? questionAnswererFor(dataDir), {
|
|
40
|
+
getApprovals: () => approvalAnswererFor(key) ?? approvalAnswererFor(dataDir),
|
|
41
|
+
getAuthorization: () => authorizationFor(key) ?? authorizationFor(dataDir),
|
|
42
|
+
});
|
|
33
43
|
}
|