@unblocklabs/unblock-memory 0.10.0 → 0.10.2
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/dist/src/abortable.d.ts +2 -0
- package/dist/src/abortable.js +4 -0
- package/dist/src/agent-paths.d.ts +5 -0
- package/dist/src/agent-paths.js +10 -0
- package/dist/src/analysis.js +13 -18
- package/dist/src/cluster-review.js +9 -7
- package/dist/src/config.js +2 -2
- package/dist/src/curation.js +3 -10
- package/dist/src/emotion-baselines.d.ts +12 -1
- package/dist/src/emotion-baselines.js +67 -47
- package/dist/src/evidence-review.js +2 -1
- package/dist/src/extraction-chunk.js +3 -4
- package/dist/src/extraction-index.d.ts +2 -0
- package/dist/src/extraction-index.js +4 -2
- package/dist/src/extraction-runtime.js +3 -3
- package/dist/src/extraction-store.js +7 -19
- package/dist/src/extraction-worker.js +3 -2
- package/dist/src/guards.d.ts +6 -0
- package/dist/src/guards.js +12 -0
- package/dist/src/inside-out-runtime.js +4 -3
- package/dist/src/inside-out-store.d.ts +28 -4
- package/dist/src/inside-out-store.js +50 -19
- package/dist/src/inside-out.js +6 -6
- package/dist/src/json-hash.d.ts +2 -0
- package/dist/src/json-hash.js +6 -0
- package/dist/src/manager.js +62 -91
- package/dist/src/memory-database.d.ts +3 -0
- package/dist/src/memory-database.js +18 -1
- package/dist/src/people-hooks.js +3 -6
- package/dist/src/people-primer-tool.js +0 -2
- package/dist/src/people-primer.js +3 -6
- package/dist/src/people-store.d.ts +2 -1
- package/dist/src/people-store.js +29 -82
- package/dist/src/people-tools.js +4 -5
- package/dist/src/plugin.js +20 -13
- package/dist/src/quality-audit.js +2 -2
- package/dist/src/query-generator.js +1 -1
- package/dist/src/response-audit.js +7 -8
- package/dist/src/response-episodes.js +5 -8
- package/dist/src/response-judge.js +2 -3
- package/dist/src/response-reviews.js +8 -18
- package/dist/src/response-runtime.js +4 -3
- package/dist/src/response-stages.js +4 -4
- package/dist/src/response-store.js +15 -44
- package/dist/src/response-text.d.ts +1 -0
- package/dist/src/response-text.js +6 -4
- package/dist/src/runtime.js +9 -8
- package/dist/src/safety-whisperer.js +4 -12
- package/dist/src/session-projector.js +7 -14
- package/dist/src/session-sync.d.ts +1 -0
- package/dist/src/session-sync.js +13 -17
- package/dist/src/skill-whisperer.js +3 -9
- package/dist/src/slack-directory.js +1 -5
- package/dist/src/sources.js +17 -37
- package/dist/src/tool-context.d.ts +2 -0
- package/dist/src/tool-context.js +5 -1
- package/dist/src/training-input.d.ts +0 -1
- package/dist/src/training-input.js +3 -6
- package/dist/src/training-queries.d.ts +1 -1
- package/dist/src/training-queries.js +9 -8
- package/dist/src/training-retrieval.js +2 -2
- package/dist/src/training-runtime.js +3 -3
- package/dist/src/training-store.js +14 -25
- package/dist/src/typesafe-client.d.ts +8 -0
- package/dist/src/typesafe-client.js +7 -1
- package/dist/src/typesafe-review.d.ts +1 -1
- package/dist/src/typesafe-review.js +1 -3
- package/dist/src/typesafe.js +4 -7
- package/docs/configuration.md +17 -7
- package/docs/retrieval.md +2 -1
- package/openclaw.plugin.json +2 -3
- package/package.json +1 -1
package/dist/src/people-store.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Buffer } from "node:buffer";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
-
import { MEMORY_DATABASE, openMemoryDatabase } from "./memory-database.js";
|
|
4
|
+
import { immediateTransaction, MEMORY_DATABASE, openMemoryDatabase } from "./memory-database.js";
|
|
5
5
|
import { resolveStateDir } from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
|
|
6
6
|
import { normalizeAgentIdStrict } from "openclaw/plugin-sdk/routing";
|
|
7
7
|
import { Type } from "typebox";
|
|
8
8
|
import { Value } from "typebox/value";
|
|
9
9
|
import { backgroundWordCount, PEOPLE_BACKGROUND_MAX_WORDS } from "./people-background.js";
|
|
10
|
+
import { agentStateDir } from "./agent-paths.js";
|
|
10
11
|
const BASELINE_DOSSIER_CATEGORIES = [
|
|
11
12
|
"role",
|
|
12
13
|
"priorities",
|
|
@@ -154,8 +155,11 @@ export class PeopleStore {
|
|
|
154
155
|
this.#maxBlurbChars = options.maxBlurbChars;
|
|
155
156
|
try {
|
|
156
157
|
this.#migrate();
|
|
158
|
+
// The second index serves cross-scope matches (inside-out-store PERSON_MATCH).
|
|
157
159
|
this.#db.exec(`CREATE INDEX IF NOT EXISTS person_identities_person
|
|
158
|
-
ON person_identities(person_id, provider, account_scope, external_id)
|
|
160
|
+
ON person_identities(person_id, provider, account_scope, external_id);
|
|
161
|
+
CREATE INDEX IF NOT EXISTS person_identities_provider_external
|
|
162
|
+
ON person_identities(provider, external_id)`);
|
|
159
163
|
}
|
|
160
164
|
catch (error) {
|
|
161
165
|
this.#db.close();
|
|
@@ -207,8 +211,7 @@ export class PeopleStore {
|
|
|
207
211
|
const externalId = required(input.externalId, "externalId");
|
|
208
212
|
const directorySync = input.syncedAt !== undefined;
|
|
209
213
|
const now = input.seenAt ?? input.syncedAt ?? new Date().toISOString();
|
|
210
|
-
this.#db
|
|
211
|
-
try {
|
|
214
|
+
return immediateTransaction(this.#db, () => {
|
|
212
215
|
const existing = this.#identityRow(provider, accountScope, externalId);
|
|
213
216
|
const personId = existing?.person_id ?? randomUUID();
|
|
214
217
|
if (existing) {
|
|
@@ -216,7 +219,6 @@ export class PeopleStore {
|
|
|
216
219
|
.prepare("SELECT * FROM people WHERE id = ?")
|
|
217
220
|
.get(personId);
|
|
218
221
|
if (existingPerson.status !== "active") {
|
|
219
|
-
this.#db.exec("COMMIT");
|
|
220
222
|
return { person: person(existingPerson), identity: identity(existing), created: false };
|
|
221
223
|
}
|
|
222
224
|
}
|
|
@@ -289,13 +291,8 @@ export class PeopleStore {
|
|
|
289
291
|
.prepare("SELECT * FROM people WHERE id = ?")
|
|
290
292
|
.get(personId);
|
|
291
293
|
const identityRow = this.#identityRow(provider, accountScope, externalId);
|
|
292
|
-
this.#db.exec("COMMIT");
|
|
293
294
|
return { person: person(personRow), identity: identity(identityRow), created: !existing };
|
|
294
|
-
}
|
|
295
|
-
catch (error) {
|
|
296
|
-
this.#db.exec("ROLLBACK");
|
|
297
|
-
throw error;
|
|
298
|
-
}
|
|
295
|
+
});
|
|
299
296
|
}
|
|
300
297
|
findPersonByIdentity(provider, accountScope, externalId) {
|
|
301
298
|
const row = this.#db
|
|
@@ -330,11 +327,9 @@ export class PeopleStore {
|
|
|
330
327
|
const name = required(input.name, "company name");
|
|
331
328
|
const primaryDomain = optional(input.primaryDomain);
|
|
332
329
|
const now = new Date().toISOString();
|
|
333
|
-
this.#db
|
|
334
|
-
try {
|
|
330
|
+
return immediateTransaction(this.#db, () => {
|
|
335
331
|
const target = this.#db.prepare("SELECT id FROM people WHERE id = ?").get(personId);
|
|
336
332
|
if (!target) {
|
|
337
|
-
this.#db.exec("COMMIT");
|
|
338
333
|
return undefined;
|
|
339
334
|
}
|
|
340
335
|
let row = this.#db
|
|
@@ -359,13 +354,8 @@ export class PeopleStore {
|
|
|
359
354
|
this.#db
|
|
360
355
|
.prepare("UPDATE people SET company_id = ?, updated_at = ? WHERE id = ?")
|
|
361
356
|
.run(row.id, now, personId);
|
|
362
|
-
this.#db.exec("COMMIT");
|
|
363
357
|
return company(row);
|
|
364
|
-
}
|
|
365
|
-
catch (error) {
|
|
366
|
-
this.#db.exec("ROLLBACK");
|
|
367
|
-
throw error;
|
|
368
|
-
}
|
|
358
|
+
});
|
|
369
359
|
}
|
|
370
360
|
listActivePeople(limit = 50, offset = 0) {
|
|
371
361
|
return this.#db
|
|
@@ -387,8 +377,7 @@ export class PeopleStore {
|
|
|
387
377
|
this.#db
|
|
388
378
|
.prepare("UPDATE people SET injection_enabled = ?, updated_at = ? WHERE id = ?")
|
|
389
379
|
.run(Number(enabled), now, personId);
|
|
390
|
-
|
|
391
|
-
return row ? person(row) : undefined;
|
|
380
|
+
return this.getPerson(personId);
|
|
392
381
|
}
|
|
393
382
|
validateDossier(input) {
|
|
394
383
|
const dossier = Value.Parse(PERSON_DOSSIER_WRITE_SCHEMA, input);
|
|
@@ -401,16 +390,16 @@ export class PeopleStore {
|
|
|
401
390
|
.get(personId);
|
|
402
391
|
return row?.id ?? null;
|
|
403
392
|
}
|
|
393
|
+
/** Returns undefined when the person does not exist. */
|
|
404
394
|
replaceDossier(personId, reasonInput, input, expectedRevision) {
|
|
405
395
|
const dossier = this.validateDossier(input);
|
|
406
396
|
const dossierJson = serializeDossier(dossier);
|
|
407
397
|
const reason = dossierReason(reasonInput);
|
|
408
398
|
const reviewedAt = new Date().toISOString();
|
|
409
|
-
this.#db
|
|
410
|
-
try {
|
|
399
|
+
return immediateTransaction(this.#db, () => {
|
|
411
400
|
const target = this.#db.prepare("SELECT id, status FROM people WHERE id = ?").get(personId);
|
|
412
401
|
if (!target)
|
|
413
|
-
|
|
402
|
+
return undefined;
|
|
414
403
|
if (expectedRevision !== undefined &&
|
|
415
404
|
(target.status !== "active" || this.getDossierRevision(personId) !== expectedRevision)) {
|
|
416
405
|
throw new DossierConflictError();
|
|
@@ -437,24 +426,17 @@ export class PeopleStore {
|
|
|
437
426
|
VALUES (?, ?, 'replace', ?, ?, ?, ?)
|
|
438
427
|
`)
|
|
439
428
|
.run(randomUUID(), personId, existing?.dossier_json ?? null, dossierJson, reason, reviewedAt);
|
|
440
|
-
this.#db.exec("COMMIT");
|
|
441
429
|
return dossier;
|
|
442
|
-
}
|
|
443
|
-
catch (error) {
|
|
444
|
-
this.#db.exec("ROLLBACK");
|
|
445
|
-
throw error;
|
|
446
|
-
}
|
|
430
|
+
});
|
|
447
431
|
}
|
|
448
432
|
deleteDossier(personId, reasonInput) {
|
|
449
433
|
const reason = dossierReason(reasonInput);
|
|
450
434
|
const changedAt = new Date().toISOString();
|
|
451
|
-
this.#db
|
|
452
|
-
try {
|
|
435
|
+
return immediateTransaction(this.#db, () => {
|
|
453
436
|
const existing = this.#db
|
|
454
437
|
.prepare("SELECT dossier_json FROM person_dossiers WHERE person_id = ?")
|
|
455
438
|
.get(personId);
|
|
456
439
|
if (!existing) {
|
|
457
|
-
this.#db.exec("COMMIT");
|
|
458
440
|
return false;
|
|
459
441
|
}
|
|
460
442
|
parseDossierJson(existing.dossier_json);
|
|
@@ -466,13 +448,8 @@ export class PeopleStore {
|
|
|
466
448
|
VALUES (?, ?, 'delete', ?, NULL, ?, ?)
|
|
467
449
|
`)
|
|
468
450
|
.run(randomUUID(), personId, existing.dossier_json, reason, changedAt);
|
|
469
|
-
this.#db.exec("COMMIT");
|
|
470
451
|
return true;
|
|
471
|
-
}
|
|
472
|
-
catch (error) {
|
|
473
|
-
this.#db.exec("ROLLBACK");
|
|
474
|
-
throw error;
|
|
475
|
-
}
|
|
452
|
+
});
|
|
476
453
|
}
|
|
477
454
|
getWhisperReceipt(threadKey, personId) {
|
|
478
455
|
const row = this.#db
|
|
@@ -571,8 +548,7 @@ export class PeopleStore {
|
|
|
571
548
|
}
|
|
572
549
|
softDeletePerson(personId) {
|
|
573
550
|
const now = new Date().toISOString();
|
|
574
|
-
this.#db
|
|
575
|
-
try {
|
|
551
|
+
return immediateTransaction(this.#db, () => {
|
|
576
552
|
const changed = this.#db
|
|
577
553
|
.prepare(`
|
|
578
554
|
UPDATE people SET status = 'unavailable', injection_enabled = 0,
|
|
@@ -580,7 +556,6 @@ export class PeopleStore {
|
|
|
580
556
|
`)
|
|
581
557
|
.run(now, personId);
|
|
582
558
|
if (changed.changes === 0) {
|
|
583
|
-
this.#db.exec("COMMIT");
|
|
584
559
|
return undefined;
|
|
585
560
|
}
|
|
586
561
|
this.#upsertTodoRow({
|
|
@@ -589,18 +564,12 @@ export class PeopleStore {
|
|
|
589
564
|
context: { personId },
|
|
590
565
|
}, now);
|
|
591
566
|
const updated = this.getPerson(personId);
|
|
592
|
-
this.#db.exec("COMMIT");
|
|
593
567
|
return updated;
|
|
594
|
-
}
|
|
595
|
-
catch (error) {
|
|
596
|
-
this.#db.exec("ROLLBACK");
|
|
597
|
-
throw error;
|
|
598
|
-
}
|
|
568
|
+
});
|
|
599
569
|
}
|
|
600
570
|
restorePerson(personId) {
|
|
601
571
|
const now = new Date().toISOString();
|
|
602
|
-
this.#db
|
|
603
|
-
try {
|
|
572
|
+
return immediateTransaction(this.#db, () => {
|
|
604
573
|
const changed = this.#db
|
|
605
574
|
.prepare(`
|
|
606
575
|
UPDATE people SET status = 'active', injection_enabled = 0, updated_at = ?
|
|
@@ -608,17 +577,11 @@ export class PeopleStore {
|
|
|
608
577
|
`)
|
|
609
578
|
.run(now, personId);
|
|
610
579
|
if (changed.changes === 0) {
|
|
611
|
-
this.#db.exec("COMMIT");
|
|
612
580
|
return undefined;
|
|
613
581
|
}
|
|
614
582
|
const restored = this.getPerson(personId);
|
|
615
|
-
this.#db.exec("COMMIT");
|
|
616
583
|
return restored;
|
|
617
|
-
}
|
|
618
|
-
catch (error) {
|
|
619
|
-
this.#db.exec("ROLLBACK");
|
|
620
|
-
throw error;
|
|
621
|
-
}
|
|
584
|
+
});
|
|
622
585
|
}
|
|
623
586
|
resolveTodoByKey(deduplicationKey, note) {
|
|
624
587
|
const now = new Date().toISOString();
|
|
@@ -633,16 +596,10 @@ export class PeopleStore {
|
|
|
633
596
|
const deduplicationKey = required(input.deduplicationKey, "deduplicationKey");
|
|
634
597
|
const kind = required(input.kind, "kind");
|
|
635
598
|
const now = new Date().toISOString();
|
|
636
|
-
this.#db
|
|
637
|
-
try {
|
|
599
|
+
return immediateTransaction(this.#db, () => {
|
|
638
600
|
const row = this.#upsertTodoRow({ deduplicationKey, kind, context: input.context }, now);
|
|
639
|
-
this.#db.exec("COMMIT");
|
|
640
601
|
return todo(row);
|
|
641
|
-
}
|
|
642
|
-
catch (error) {
|
|
643
|
-
this.#db.exec("ROLLBACK");
|
|
644
|
-
throw error;
|
|
645
|
-
}
|
|
602
|
+
});
|
|
646
603
|
}
|
|
647
604
|
listTodos(limit = 100) {
|
|
648
605
|
const bounded = Math.max(1, Math.min(100, Math.floor(limit)));
|
|
@@ -661,12 +618,14 @@ export class PeopleStore {
|
|
|
661
618
|
const row = this.#db
|
|
662
619
|
.prepare("SELECT * FROM people_todos WHERE deduplication_key = ?")
|
|
663
620
|
.get(input.deduplicationKey);
|
|
664
|
-
if (row
|
|
621
|
+
if (!row || row.status === "resolved") {
|
|
665
622
|
const count = this.#db
|
|
666
623
|
.prepare("SELECT COUNT(*) AS count FROM people_todos WHERE status = 'open'")
|
|
667
624
|
.get();
|
|
668
625
|
if (count.count >= this.#maxOpenTodos)
|
|
669
626
|
return this.#incrementOverflowTodo(now);
|
|
627
|
+
}
|
|
628
|
+
if (row?.status === "resolved") {
|
|
670
629
|
this.#db
|
|
671
630
|
.prepare(`
|
|
672
631
|
UPDATE people_todos
|
|
@@ -687,11 +646,6 @@ export class PeopleStore {
|
|
|
687
646
|
.run(contextJson, now, row.id);
|
|
688
647
|
return this.#db.prepare("SELECT * FROM people_todos WHERE id = ?").get(row.id);
|
|
689
648
|
}
|
|
690
|
-
const count = this.#db
|
|
691
|
-
.prepare("SELECT COUNT(*) AS count FROM people_todos WHERE status = 'open'")
|
|
692
|
-
.get();
|
|
693
|
-
if (count.count >= this.#maxOpenTodos)
|
|
694
|
-
return this.#incrementOverflowTodo(now);
|
|
695
649
|
const id = randomUUID();
|
|
696
650
|
this.#db
|
|
697
651
|
.prepare(`
|
|
@@ -758,8 +712,7 @@ export class PeopleStore {
|
|
|
758
712
|
}
|
|
759
713
|
}
|
|
760
714
|
#migrate() {
|
|
761
|
-
this.#db
|
|
762
|
-
try {
|
|
715
|
+
return immediateTransaction(this.#db, () => {
|
|
763
716
|
// Re-read under the write lock so concurrent first opens cannot both migrate.
|
|
764
717
|
const version = this.#db.prepare("SELECT version FROM memory_schema WHERE component='people'").get()?.version
|
|
765
718
|
?? this.#db.prepare("PRAGMA user_version").get()?.user_version ?? 0;
|
|
@@ -767,7 +720,6 @@ export class PeopleStore {
|
|
|
767
720
|
throw new Error(`unsupported PeopleSQL schema version: ${version}`);
|
|
768
721
|
if (version === 4) {
|
|
769
722
|
this.#db.prepare("INSERT OR IGNORE INTO memory_schema VALUES ('people',4)").run();
|
|
770
|
-
this.#db.exec("COMMIT");
|
|
771
723
|
return;
|
|
772
724
|
}
|
|
773
725
|
if (version === 2) {
|
|
@@ -881,12 +833,7 @@ export class PeopleStore {
|
|
|
881
833
|
INSERT INTO memory_schema VALUES ('people',4)
|
|
882
834
|
ON CONFLICT(component) DO UPDATE SET version=excluded.version;
|
|
883
835
|
`);
|
|
884
|
-
|
|
885
|
-
}
|
|
886
|
-
catch (error) {
|
|
887
|
-
this.#db.exec("ROLLBACK");
|
|
888
|
-
throw error;
|
|
889
|
-
}
|
|
836
|
+
});
|
|
890
837
|
}
|
|
891
838
|
}
|
|
892
839
|
export class PeopleStores {
|
|
@@ -904,7 +851,7 @@ export class PeopleStores {
|
|
|
904
851
|
const canonicalAgentId = normalized.value;
|
|
905
852
|
let store = this.#stores.get(canonicalAgentId);
|
|
906
853
|
if (!store) {
|
|
907
|
-
store = new PeopleStore(join(this.#stateRoot,
|
|
854
|
+
store = new PeopleStore(join(agentStateDir(canonicalAgentId, this.#stateRoot), MEMORY_DATABASE), this.#options);
|
|
908
855
|
this.#stores.set(canonicalAgentId, store);
|
|
909
856
|
}
|
|
910
857
|
return store;
|
package/dist/src/people-tools.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Type } from "typebox";
|
|
|
3
3
|
import { Value } from "typebox/value";
|
|
4
4
|
import { renderPeopleWhisper } from "./people-hooks.js";
|
|
5
5
|
import { DossierConflictError, PERSON_DOSSIER_WRITE_SCHEMA } from "./people-store.js";
|
|
6
|
-
import { getContext } from "./tool-context.js";
|
|
6
|
+
import { getContext, runtimeConfig } from "./tool-context.js";
|
|
7
7
|
import { reviewPersonDossier } from "./people-dossier-review.js";
|
|
8
8
|
import { createOpenClawSlackDirectory, syncSlackDirectory, } from "./slack-directory.js";
|
|
9
9
|
const nonEmpty = Type.String({ pattern: "\\S", maxLength: 1000 });
|
|
@@ -223,14 +223,13 @@ function createUpdateTool(stores, config, runtime, ctx) {
|
|
|
223
223
|
: "TypeSafe background review passed (person-background-v2)";
|
|
224
224
|
try {
|
|
225
225
|
const dossier = store.replaceDossier(input.personId, `${input.reason}\n${audit}`, proposed, revision);
|
|
226
|
+
if (!dossier)
|
|
227
|
+
return jsonResult({ status: "not_found" });
|
|
226
228
|
return jsonResult({ status: "ok", saved: true, verification: review.status === "manual" ? "manual" : "typesafe", dossier, review });
|
|
227
229
|
}
|
|
228
230
|
catch (error) {
|
|
229
231
|
if (error instanceof DossierConflictError)
|
|
230
232
|
return jsonResult({ status: "conflict", saved: false, reason: error.message });
|
|
231
|
-
if (error instanceof Error && error.message.startsWith("person not found:")) {
|
|
232
|
-
return jsonResult({ status: "not_found" });
|
|
233
|
-
}
|
|
234
233
|
throw error;
|
|
235
234
|
}
|
|
236
235
|
}
|
|
@@ -297,7 +296,7 @@ export function registerPeopleTools(api, stores, config, runtime, directoryReade
|
|
|
297
296
|
});
|
|
298
297
|
api.registerTool((ctx) => createSyncTool(stores, directoryReader ??
|
|
299
298
|
createOpenClawSlackDirectory({
|
|
300
|
-
getConfig: () => ctx
|
|
299
|
+
getConfig: () => runtimeConfig(ctx),
|
|
301
300
|
}), ctx), {
|
|
302
301
|
names: ["memory_people_sync"],
|
|
303
302
|
optional: true,
|
package/dist/src/plugin.js
CHANGED
|
@@ -21,7 +21,12 @@ import { resolveTimezone } from "./session-projector.js";
|
|
|
21
21
|
import { searchMemory } from "./memory-search.js";
|
|
22
22
|
import { prepareQueryConversation, QueryInputBudgetError } from "./query-contract.js";
|
|
23
23
|
import { resolveTypeSafeApiKey } from "./typesafe-client.js";
|
|
24
|
+
import { abortedByTimeout } from "./abortable.js";
|
|
24
25
|
import { registerExtraction } from "./extraction-runtime.js";
|
|
26
|
+
function managerUnavailable(error) {
|
|
27
|
+
return jsonResult({ status: "unavailable", error: error ?? "memory unavailable" });
|
|
28
|
+
}
|
|
29
|
+
const ISO_TIMESTAMP_PATTERN = "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{1,9})?(?:Z|[+-]\\d{2}:\\d{2})$";
|
|
25
30
|
const searchParameters = Type.Object({
|
|
26
31
|
bm25Query: Type.String({ pattern: "\\S", description: "Distinctive names, identifiers and keywords for BM25 retrieval." }),
|
|
27
32
|
vectorQuery: Type.String({ pattern: "\\S", description: "Natural-language question describing the information needed; also the intent used to judge usefulness." }),
|
|
@@ -31,11 +36,11 @@ const searchParameters = Type.Object({
|
|
|
31
36
|
sessionFilter: Type.Optional(Type.Object({
|
|
32
37
|
startedFrom: Type.Optional(Type.String({
|
|
33
38
|
description: "Inclusive lower bound on session start time, not message or claim dates (ISO 8601).",
|
|
34
|
-
pattern:
|
|
39
|
+
pattern: ISO_TIMESTAMP_PATTERN,
|
|
35
40
|
})),
|
|
36
41
|
startedTo: Type.Optional(Type.String({
|
|
37
42
|
description: "Inclusive upper bound on session start time, not message or claim dates (ISO 8601).",
|
|
38
|
-
pattern:
|
|
43
|
+
pattern: ISO_TIMESTAMP_PATTERN,
|
|
39
44
|
})),
|
|
40
45
|
provider: Type.Optional(Type.String({ pattern: "\\S" })),
|
|
41
46
|
chatType: Type.Optional(Type.Union([Type.Literal("channel"), Type.Literal("group"), Type.Literal("direct")])),
|
|
@@ -128,8 +133,7 @@ function createSearchTool(runtime, ctx, typesafe, diagnostics) {
|
|
|
128
133
|
measurement.otherMs = Math.max(0, measurement.elapsedMs - measurement.setupMs -
|
|
129
134
|
(measurement.retrievalMs ?? 0) - (measurement.candidatePrepMs ?? 0) - (measurement.judgeMs ?? 0));
|
|
130
135
|
if (signal?.aborted)
|
|
131
|
-
measurement.outcome = signal
|
|
132
|
-
? "timed_out" : "cancelled";
|
|
136
|
+
measurement.outcome = abortedByTimeout(signal) ? "timed_out" : "cancelled";
|
|
133
137
|
diagnostics.measureSearch(active.agentId, measurement);
|
|
134
138
|
}
|
|
135
139
|
},
|
|
@@ -149,7 +153,7 @@ function createGetTool(runtime, ctx) {
|
|
|
149
153
|
const path = untrimmedPath.trim();
|
|
150
154
|
const { manager, error } = await runtime.getMemorySearchManager(active);
|
|
151
155
|
if (!manager)
|
|
152
|
-
return
|
|
156
|
+
return managerUnavailable(error);
|
|
153
157
|
return jsonResult(await manager.readFile({
|
|
154
158
|
relPath: path,
|
|
155
159
|
from,
|
|
@@ -218,7 +222,7 @@ function createReclusterTool(runtime, ctx) {
|
|
|
218
222
|
const options = Value.Parse(reclusterParameters, params);
|
|
219
223
|
const { manager, error } = await runtime.getMemorySearchManager(active);
|
|
220
224
|
if (!manager)
|
|
221
|
-
return
|
|
225
|
+
return managerUnavailable(error);
|
|
222
226
|
try {
|
|
223
227
|
return jsonResult(await manager.recluster(options, signal));
|
|
224
228
|
}
|
|
@@ -247,7 +251,7 @@ function createListClustersTool(runtime, ctx) {
|
|
|
247
251
|
const { limit } = Value.Parse(listClustersParameters, params);
|
|
248
252
|
const { manager, error } = await runtime.getMemorySearchManager(active);
|
|
249
253
|
if (!manager)
|
|
250
|
-
return
|
|
254
|
+
return managerUnavailable(error);
|
|
251
255
|
return jsonResult(await manager.listClusters(limit));
|
|
252
256
|
},
|
|
253
257
|
};
|
|
@@ -277,7 +281,7 @@ function createFetchClusterTool(runtime, ctx) {
|
|
|
277
281
|
const { clusterId, topK, offset, sort } = Value.Parse(fetchClusterParameters, params);
|
|
278
282
|
const { manager, error } = await runtime.getMemorySearchManager(active);
|
|
279
283
|
if (!manager)
|
|
280
|
-
return
|
|
284
|
+
return managerUnavailable(error);
|
|
281
285
|
return jsonResult(await manager.fetchCluster({ clusterId, topK, offset, sort }));
|
|
282
286
|
},
|
|
283
287
|
};
|
|
@@ -338,14 +342,12 @@ function createListMaintenanceTool(runtime, ctx) {
|
|
|
338
342
|
const options = Value.Parse(listMaintenanceParameters, params);
|
|
339
343
|
const { manager, error } = await runtime.getMemorySearchManager(active);
|
|
340
344
|
if (!manager)
|
|
341
|
-
return
|
|
345
|
+
return managerUnavailable(error);
|
|
342
346
|
return jsonResult({ status: "ok", tasks: await manager.listMaintenanceTasks(options) });
|
|
343
347
|
},
|
|
344
348
|
};
|
|
345
349
|
}
|
|
346
|
-
const isoTimestamp = Type.String({
|
|
347
|
-
pattern: "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{1,9})?(?:Z|[+-]\\d{2}:\\d{2})$",
|
|
348
|
-
});
|
|
350
|
+
const isoTimestamp = Type.String({ pattern: ISO_TIMESTAMP_PATTERN });
|
|
349
351
|
const updateMaintenanceParameters = Type.Object({
|
|
350
352
|
taskId: Type.String({ pattern: "\\S" }),
|
|
351
353
|
action: Type.Union([
|
|
@@ -379,7 +381,7 @@ function createUpdateMaintenanceTool(runtime, ctx) {
|
|
|
379
381
|
const { taskId, action, note, annotation } = Value.Parse(updateMaintenanceParameters, params);
|
|
380
382
|
const { manager, error } = await runtime.getMemorySearchManager(active);
|
|
381
383
|
if (!manager)
|
|
382
|
-
return
|
|
384
|
+
return managerUnavailable(error);
|
|
383
385
|
const updated = manager.updateMaintenanceTask({
|
|
384
386
|
id: taskId,
|
|
385
387
|
status: action === "resolve" ? "resolved" : action === "defer" ? "deferred" : "irrelevant",
|
|
@@ -494,6 +496,11 @@ export function registerUnblockMemory(api) {
|
|
|
494
496
|
api.on("gateway_stop", () => peopleStores.closeAll());
|
|
495
497
|
}
|
|
496
498
|
const diagnostics = WhispererDiagnostics.shared();
|
|
499
|
+
// The manifest sets no default for `enabled`, so true here was written by the operator.
|
|
500
|
+
const skillSettings = api.pluginConfig?.skillWhisperer;
|
|
501
|
+
if (skillSettings?.enabled === true && !config.skillWhisperer.enabled) {
|
|
502
|
+
api.logger.warn('unblock-memory skillWhisperer.enabled is true but no corpus has kind "skills"; Skill Whisperer is inactive');
|
|
503
|
+
}
|
|
497
504
|
registerWhispererPrompt(api, {
|
|
498
505
|
memory: registerMemoryWhisperer(api, runtime, config.memoryWhisperer, config.typesafe, diagnostics),
|
|
499
506
|
skill: registerSkillWhisperer(api, runtime, config.skillWhisperer, config.typesafe, diagnostics),
|
|
@@ -132,6 +132,7 @@ export async function auditQualityPage(params) {
|
|
|
132
132
|
structure === "serialized_message" ? "possible_serialized_message" : "possible_ingestion_noise";
|
|
133
133
|
const startLine = row.doc.slice(0, row.pos).split("\n").length;
|
|
134
134
|
const endLine = startLine + text.split("\n").length - 1;
|
|
135
|
+
const triage = qualityTriage(judgment.noise, judgment.evidence, structure === "encoded_message");
|
|
135
136
|
const task = curation.addTask({
|
|
136
137
|
type: "quality_review", corpus: source.corpus, collection: source.collection,
|
|
137
138
|
path: row.path, reason, contentFingerprint: fingerprint,
|
|
@@ -141,7 +142,7 @@ export async function auditQualityPage(params) {
|
|
|
141
142
|
indicator: structure === "empty" ? "deterministic_empty" :
|
|
142
143
|
structure === "encoded_message" ? "deterministic_encoding" : "typesafe",
|
|
143
144
|
...judgment, policy: QUALITY_JUDGE_VERSION,
|
|
144
|
-
triage
|
|
145
|
+
triage,
|
|
145
146
|
instruction: "Inspect original source and ingestion before acting. Verify source/index after any authorized repair. Never manually edit generated session projections.",
|
|
146
147
|
}),
|
|
147
148
|
});
|
|
@@ -149,7 +150,6 @@ export async function auditQualityPage(params) {
|
|
|
149
150
|
advance();
|
|
150
151
|
if (task.status !== "pending")
|
|
151
152
|
continue;
|
|
152
|
-
const triage = qualityTriage(judgment.noise, judgment.evidence, structure === "encoded_message");
|
|
153
153
|
const key = JSON.stringify([source.collection, reason, triage]);
|
|
154
154
|
const group = groups.get(key) ?? {
|
|
155
155
|
corpus: source.corpus, source: source.configuredPath, reason, triage, pending: 0, examples: [],
|
|
@@ -4,7 +4,7 @@ import { abortable } from "./abortable.js";
|
|
|
4
4
|
import { messageText } from "./whisperer-context.js";
|
|
5
5
|
import { conversationUserText } from "./response-text.js";
|
|
6
6
|
import { parseQueryPair, prepareQueryConversation } from "./query-contract.js";
|
|
7
|
-
|
|
7
|
+
import { record } from "./guards.js";
|
|
8
8
|
/** Preserve whole visible messages and the complete current request, never tool/thinking text. */
|
|
9
9
|
export function queryConversation(prompt, messages) {
|
|
10
10
|
const currentRequest = conversationUserText(prompt)?.text ?? "";
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
1
|
import { abortable } from "./abortable.js";
|
|
3
|
-
import { resolveTypeSafeApiKey } from "./typesafe-client.js";
|
|
2
|
+
import { resolveTypeSafeApiKey, TYPESAFE_MODEL } from "./typesafe-client.js";
|
|
4
3
|
import { RESPONSE_EXTRACTOR_VERSION, ResponseTranscriptReader } from "./response-episodes.js";
|
|
5
4
|
import { RESPONSE_RUBRIC_VERSION, RESPONSE_STAGE_VERSIONS, judgeMemoryOpportunity } from "./response-judge.js";
|
|
6
5
|
import { ResponseAuditStore } from "./response-store.js";
|
|
7
6
|
import { responseMemoryCandidates } from "./response-memory.js";
|
|
8
7
|
import { assessResponseStages } from "./response-stages.js";
|
|
9
8
|
import { ResponsePeople } from "./response-identity.js";
|
|
10
|
-
import {
|
|
9
|
+
import { jsonHash } from "./json-hash.js";
|
|
11
10
|
export function responseCohort(config) {
|
|
12
|
-
return RESPONSE_RUBRIC_VERSION + ":" +
|
|
11
|
+
return RESPONSE_RUBRIC_VERSION + ":" + jsonHash({
|
|
13
12
|
extractor: RESPONSE_EXTRACTOR_VERSION, historyMessages: config.historyMessages,
|
|
14
13
|
stages: RESPONSE_STAGE_VERSIONS,
|
|
15
14
|
sentimentEnabled: config.sentimentEnabled,
|
|
16
15
|
senderIds: [...config.senderIds].sort(), chatTypes: [...config.chatTypes].sort(), memoryCorpora: [...config.memoryCorpora].sort(),
|
|
17
|
-
})
|
|
16
|
+
}).slice(0, 16);
|
|
18
17
|
}
|
|
19
18
|
/** All inference is outside memory's mutation queue and outside transcript DB transactions. */
|
|
20
19
|
export async function auditResponses(options) {
|
|
@@ -96,7 +95,7 @@ export async function auditResponses(options) {
|
|
|
96
95
|
coverage.reconciledSessions++;
|
|
97
96
|
for (const key of Object.keys(snapshot.coverage))
|
|
98
97
|
coverage[key] += snapshot.coverage[key];
|
|
99
|
-
const episodes = snapshot.episodes.filter(e => e.timestamp >=
|
|
98
|
+
const episodes = snapshot.episodes.filter(e => e.timestamp >= since);
|
|
100
99
|
coverage.outsideLookback += snapshot.episodes.length - episodes.length;
|
|
101
100
|
store?.observe(cohort, session, snapshot.episodes);
|
|
102
101
|
store?.checkpointSave(cohort, session, snapshot.revision, snapshot.coverage);
|
|
@@ -123,9 +122,9 @@ export async function auditResponses(options) {
|
|
|
123
122
|
try {
|
|
124
123
|
const approved = options.sources.filter(s => config.responseAudit.memoryCorpora.includes(s.corpus));
|
|
125
124
|
const candidates = responseMemoryCandidates(options.indexPath, approved, e);
|
|
126
|
-
const memoryKey =
|
|
125
|
+
const memoryKey = jsonHash([TYPESAFE_MODEL, RESPONSE_STAGE_VERSIONS.memory,
|
|
127
126
|
e.id, e.session, e.senderId, e.request, e.answer, e.feedback, candidates,
|
|
128
|
-
[...config.responseAudit.memoryCorpora].sort()])
|
|
127
|
+
[...config.responseAudit.memoryCorpora].sort()]);
|
|
129
128
|
let judged = store.stage(cohort, e, "memory", memoryKey);
|
|
130
129
|
if (judged)
|
|
131
130
|
coverage.stageCacheHits++;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
1
|
import { DatabaseSync } from "node:sqlite";
|
|
3
2
|
import { AgentTranscriptReader } from "./agent-transcript.js";
|
|
4
3
|
import { messageText } from "./whisperer-context.js";
|
|
5
4
|
import { responseUserText } from "./response-text.js";
|
|
5
|
+
import { jsonHash } from "./json-hash.js";
|
|
6
|
+
import { record } from "./guards.js";
|
|
6
7
|
export const RESPONSE_EXTRACTOR_VERSION = 6;
|
|
7
8
|
const MAX_EVENTS = 2000, MAX_SESSION_BYTES = 2_000_000, MAX_EPISODE_CHARS = 24_000;
|
|
8
|
-
function record(v) {
|
|
9
|
-
return v !== null && typeof v === "object" && !Array.isArray(v) ? v : undefined;
|
|
10
|
-
}
|
|
11
|
-
const hash = (value) => createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
12
9
|
/** Never deduce human identity from text or the user role alone. */
|
|
13
10
|
export function responseEpisodes(session, rows, config) {
|
|
14
11
|
const coverage = { completedResponses: 0, eligible: 0, noFeedback: 0,
|
|
@@ -44,7 +41,7 @@ export function responseEpisodes(session, rows, config) {
|
|
|
44
41
|
coverage.oversized++;
|
|
45
42
|
else {
|
|
46
43
|
const { final: _final, ...content } = current;
|
|
47
|
-
const id =
|
|
44
|
+
const id = jsonHash([session.sessionId, current.answer.at(-1).seq]);
|
|
48
45
|
const episode = { id, inputHash: "", session, ...content, followup: { status: "pending", messages: [] } };
|
|
49
46
|
episodes.push(episode);
|
|
50
47
|
followupTarget = episode;
|
|
@@ -172,7 +169,7 @@ export function responseEpisodes(session, rows, config) {
|
|
|
172
169
|
finish(false); // No next assistant turn: the feedback block may still grow.
|
|
173
170
|
for (const episode of episodes) {
|
|
174
171
|
const { inputHash: _hash, session: s, ...content } = episode;
|
|
175
|
-
episode.inputHash =
|
|
172
|
+
episode.inputHash = jsonHash([RESPONSE_EXTRACTOR_VERSION, s.sessionId, s.accountId, s.chatType, s.conversationId, content]);
|
|
176
173
|
}
|
|
177
174
|
return { episodes, coverage };
|
|
178
175
|
}
|
|
@@ -261,7 +258,7 @@ export class ResponseTranscriptReader {
|
|
|
261
258
|
const rows = snapshot.rows;
|
|
262
259
|
// Exact active content catches in-place edits and branch changes even when writer
|
|
263
260
|
// watermarks are absent. Raw text is never retained in the checkpoint database.
|
|
264
|
-
const revision =
|
|
261
|
+
const revision = jsonHash([RESPONSE_EXTRACTOR_VERSION, session, config.historyMessages, [...config.senderIds].sort(), rows]);
|
|
265
262
|
if (revision === previousRevision)
|
|
266
263
|
return { unchanged: true, revision };
|
|
267
264
|
return { ...responseEpisodes(session, rows, config), revision };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
import { Value } from "typebox/value";
|
|
3
|
-
import { requestTypeSafe, TYPESAFE_NOUL_SCHEMA as noul } from "./typesafe-client.js";
|
|
4
|
-
|
|
5
|
-
export const RESPONSE_RUBRIC_VERSION = `${TYPESAFE_REVIEW_MODEL}:response-v10`;
|
|
3
|
+
import { requestTypeSafe, TYPESAFE_MODEL, TYPESAFE_NOUL_SCHEMA as noul } from "./typesafe-client.js";
|
|
4
|
+
export const RESPONSE_RUBRIC_VERSION = `${TYPESAFE_MODEL}:response-v10`;
|
|
6
5
|
export const RESPONSE_STAGE_VERSIONS = { quality: "quality-v9", feedback: "feedback-v9", sentiment: "sentiment-v10", retrospective: "retrospective-v9", memory: "memory-v2-isolated" };
|
|
7
6
|
const probability = Type.Number({ minimum: 0, maximum: 1 });
|
|
8
7
|
const score = Type.Object({ type: Type.Literal("score"), score: Type.Number({ minimum: 0, maximum: 3 }),
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { responseOutcome } from "./response-outcome.js";
|
|
3
|
+
import { immediateTransaction } from "./memory-database.js";
|
|
4
|
+
import { jsonHash } from "./json-hash.js";
|
|
3
5
|
export const RESPONSE_REVIEW_POLICY = "response-review-v2";
|
|
4
6
|
/** Operator-only tasks, intentionally not exposed as memory-curation agent tools. */
|
|
5
7
|
export class ResponseReviews {
|
|
@@ -40,7 +42,7 @@ export class ResponseReviews {
|
|
|
40
42
|
];
|
|
41
43
|
for (const s of signals) {
|
|
42
44
|
const humanKey = result.human?.key ?? "unknown";
|
|
43
|
-
const id =
|
|
45
|
+
const id = jsonHash([episodeId, s.family, humanKey]);
|
|
44
46
|
this.db.prepare(`INSERT INTO response_review_tasks(id,episode_id,family,human_key,created_at,updated_at) VALUES(?,?,?,?,?,?)
|
|
45
47
|
ON CONFLICT(id) DO UPDATE SET updated_at=excluded.updated_at`).run(id, episodeId, s.family, humanKey, now, now);
|
|
46
48
|
this.db.prepare(`INSERT INTO response_review_evidence VALUES(?,?,?,1,?) ON CONFLICT(task_id,cohort)
|
|
@@ -51,8 +53,7 @@ export class ResponseReviews {
|
|
|
51
53
|
DO UPDATE SET input_hash=excluded.input_hash,policy=excluded.policy`).run(cohort, episodeId, inputHash, RESPONSE_REVIEW_POLICY);
|
|
52
54
|
}
|
|
53
55
|
refresh(cohort, since) {
|
|
54
|
-
this.db
|
|
55
|
-
try {
|
|
56
|
+
return immediateTransaction(this.db, () => {
|
|
56
57
|
const rows = this.db.prepare(`SELECT r.id,r.input_hash,r.result FROM response_results r
|
|
57
58
|
LEFT JOIN response_review_versions v ON v.cohort=r.cohort AND v.episode_id=r.id
|
|
58
59
|
WHERE r.cohort=? AND r.active=1 AND r.status='ok' AND r.episode_at>=?
|
|
@@ -60,13 +61,8 @@ export class ResponseReviews {
|
|
|
60
61
|
.all(cohort, since, RESPONSE_REVIEW_POLICY);
|
|
61
62
|
for (const row of rows)
|
|
62
63
|
this.sync(cohort, String(row.id), String(row.input_hash), JSON.parse(String(row.result)), Date.now());
|
|
63
|
-
this.db.exec("COMMIT");
|
|
64
64
|
return rows.length;
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
this.db.exec("ROLLBACK");
|
|
68
|
-
throw error;
|
|
69
|
-
}
|
|
65
|
+
});
|
|
70
66
|
}
|
|
71
67
|
reconcile(cohort, sessionId) {
|
|
72
68
|
this.db.prepare(`UPDATE response_review_evidence AS e SET active=CASE WHEN EXISTS (
|
|
@@ -92,18 +88,12 @@ export class ResponseReviews {
|
|
|
92
88
|
throw new Error("Invalid response review decision");
|
|
93
89
|
if (!this.list(cohort, id).length)
|
|
94
90
|
throw new Error("Unknown response review task in current cohort");
|
|
95
|
-
this.db
|
|
96
|
-
try {
|
|
91
|
+
immediateTransaction(this.db, () => {
|
|
97
92
|
this.db.prepare("UPDATE response_review_tasks SET status=?,reviewer_kind=?,resolution_note=?,updated_at=? WHERE id=?")
|
|
98
93
|
.run(status, reviewer, note.trim(), now, id);
|
|
99
94
|
this.db.prepare("INSERT INTO response_review_decisions(task_id,status,reviewer_kind,note,decided_at) VALUES(?,?,?,?,?)")
|
|
100
95
|
.run(id, status, reviewer, note.trim(), now);
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
this.db.exec("ROLLBACK");
|
|
105
|
-
throw error;
|
|
106
|
-
}
|
|
96
|
+
});
|
|
107
97
|
}
|
|
108
98
|
annotate(occurredAt, kind, note) {
|
|
109
99
|
if (!Number.isFinite(occurredAt) || !["model", "prompt", "deployment", "other"].includes(kind) || !note.trim() || note.length > 4000)
|