@unblocklabs/unblock-memory 0.12.2 → 0.13.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/README.md +19 -18
- package/dist/src/analysis.js +1 -1
- package/dist/src/cluster-review.d.ts +2 -0
- package/dist/src/cluster-review.js +3 -3
- package/dist/src/config.d.ts +9 -6
- package/dist/src/config.js +31 -20
- package/dist/src/curation.d.ts +1 -1
- package/dist/src/decision-client.d.ts +39 -0
- package/dist/src/decision-client.js +74 -0
- package/dist/src/{typesafe.d.ts → decision-ranking.d.ts} +15 -18
- package/dist/src/decision-ranking.js +154 -0
- package/dist/src/{typesafe-review.d.ts → decision-review.d.ts} +13 -9
- package/dist/src/decision-review.js +192 -0
- package/dist/src/diagnostics.d.ts +5 -5
- package/dist/src/emotion-baselines.d.ts +28 -3
- package/dist/src/emotion-baselines.js +309 -113
- package/dist/src/evidence-review.d.ts +22 -8
- package/dist/src/evidence-review.js +4 -4
- package/dist/src/extraction-chunk.d.ts +3 -0
- package/dist/src/extraction-chunk.js +23 -5
- package/dist/src/extraction-model.d.ts +2 -0
- package/dist/src/extraction-model.js +73 -48
- package/dist/src/extraction-runtime.d.ts +3 -1
- package/dist/src/extraction-runtime.js +43 -16
- package/dist/src/extraction-source.d.ts +1 -1
- package/dist/src/extraction-source.js +19 -11
- package/dist/src/extraction-store.d.ts +28 -3
- package/dist/src/extraction-store.js +145 -23
- package/dist/src/extraction-worker.d.ts +1 -0
- package/dist/src/extraction-worker.js +246 -93
- package/dist/src/inside-out-runtime.js +41 -29
- package/dist/src/inside-out-store.d.ts +2 -2
- package/dist/src/inside-out-store.js +110 -69
- package/dist/src/inside-out.d.ts +10 -9
- package/dist/src/inside-out.js +190 -105
- package/dist/src/manager.d.ts +22 -9
- package/dist/src/manager.js +275 -169
- package/dist/src/memory-search.d.ts +4 -2
- package/dist/src/memory-search.js +5 -5
- package/dist/src/memory-whisperer.d.ts +1 -1
- package/dist/src/memory-whisperer.js +189 -127
- package/dist/src/my-turn.d.ts +1 -1
- package/dist/src/my-turn.js +87 -68
- package/dist/src/people-background.d.ts +4 -0
- package/dist/src/people-background.js +29 -6
- package/dist/src/people-dossier-review.d.ts +20 -8
- package/dist/src/people-dossier-review.js +11 -8
- package/dist/src/people-hooks.js +127 -22
- package/dist/src/people-learning-cron.d.ts +1 -1
- package/dist/src/people-learning-cron.js +106 -57
- package/dist/src/people-learning-inventory.d.ts +1 -0
- package/dist/src/people-learning-inventory.js +281 -171
- package/dist/src/people-learning-prompt.js +1 -1
- package/dist/src/people-learning-runtime.d.ts +1 -1
- package/dist/src/people-learning-runtime.js +423 -204
- package/dist/src/people-learning-store.d.ts +27 -4
- package/dist/src/people-learning-store.js +312 -96
- package/dist/src/people-primer-tool.js +8 -6
- package/dist/src/people-primer.d.ts +3 -1
- package/dist/src/people-primer.js +61 -44
- package/dist/src/people-store.d.ts +18 -21
- package/dist/src/people-store.js +186 -63
- package/dist/src/people-tools.js +136 -92
- package/dist/src/plugin.js +16 -16
- package/dist/src/quality-audit.d.ts +2 -0
- package/dist/src/quality-audit.js +8 -7
- package/dist/src/query-generator.d.ts +1 -1
- package/dist/src/query-generator.js +15 -8
- package/dist/src/response-audit.d.ts +1 -1
- package/dist/src/response-audit.js +76 -43
- package/dist/src/response-episodes.d.ts +1 -1
- package/dist/src/response-episodes.js +12 -17
- package/dist/src/response-judge.d.ts +151 -145
- package/dist/src/response-judge.js +535 -204
- package/dist/src/response-reviews.d.ts +29 -1
- package/dist/src/response-reviews.js +110 -13
- package/dist/src/response-runtime.js +8 -8
- package/dist/src/response-stages.d.ts +50 -53
- package/dist/src/response-stages.js +10 -4
- package/dist/src/response-store.d.ts +7 -6
- package/dist/src/response-store.js +332 -210
- package/dist/src/response-text.d.ts +2 -0
- package/dist/src/response-text.js +182 -36
- package/dist/src/review-tools.d.ts +8 -2
- package/dist/src/review-tools.js +18 -18
- package/dist/src/runtime.d.ts +7 -4
- package/dist/src/runtime.js +624 -98
- package/dist/src/safety-whisperer.d.ts +2 -2
- package/dist/src/safety-whisperer.js +88 -71
- package/dist/src/session-sync.d.ts +3 -1
- package/dist/src/session-sync.js +200 -95
- package/dist/src/skill-whisperer.d.ts +1 -1
- package/dist/src/skill-whisperer.js +52 -30
- package/dist/src/training-gate.d.ts +8 -21
- package/dist/src/training-gate.js +32 -35
- package/dist/src/training-judge.d.ts +9 -16
- package/dist/src/training-judge.js +5 -5
- package/dist/src/training-queries.d.ts +13 -8
- package/dist/src/training-queries.js +370 -228
- package/dist/src/training-retrieval.d.ts +14 -24
- package/dist/src/training-retrieval.js +182 -136
- package/dist/src/training-runtime.d.ts +3 -0
- package/dist/src/training-runtime.js +76 -18
- package/dist/src/training-store.d.ts +18 -3
- package/dist/src/training-store.js +138 -50
- package/dist/src/training.js +8 -11
- package/dist/src/whisperer-context.d.ts +14 -0
- package/dist/src/whisperer-context.js +22 -1
- package/docs/configuration.md +76 -63
- package/docs/extraction.md +9 -7
- package/docs/memory-training.md +7 -6
- package/docs/people-learning.md +2 -2
- package/docs/peoplesql.md +6 -6
- package/docs/response-audit.md +10 -8
- package/docs/retrieval.md +40 -37
- package/openclaw.plugin.json +40 -26
- package/package.json +3 -2
- package/skills/memory-curator/SKILL.md +1 -1
- package/skills/people-whisperer/SKILL.md +1 -1
- package/dist/src/typesafe-client.d.ts +0 -30
- package/dist/src/typesafe-client.js +0 -92
- package/dist/src/typesafe-review.js +0 -154
- package/dist/src/typesafe.js +0 -147
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { immediateTransaction, openMemoryDatabase } from "./memory-database.js";
|
|
3
|
+
import { validateCachedStage } from "./response-judge.js";
|
|
3
4
|
import { responseOutcome, RESPONSE_REPORT_VERSION } from "./response-outcome.js";
|
|
4
5
|
import { ResponsePeople } from "./response-identity.js";
|
|
5
6
|
import { ResponseReviews, RESPONSE_REVIEW_POLICY } from "./response-reviews.js";
|
|
7
|
+
const MAX_RETRY_ATTEMPTS = 3;
|
|
8
|
+
const RETRY_BACKOFF_MS = 600_000;
|
|
6
9
|
/** Operator-only tables: not a memory corpus and never injected into agent prompts. */
|
|
7
10
|
export class ResponseAuditStore {
|
|
8
11
|
#db;
|
|
@@ -10,34 +13,36 @@ export class ResponseAuditStore {
|
|
|
10
13
|
constructor(path) {
|
|
11
14
|
this.#db = openMemoryDatabase(path);
|
|
12
15
|
try {
|
|
13
|
-
this.#db
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
16
|
+
this.reviews = immediateTransaction(this.#db, () => {
|
|
17
|
+
const version = this.#db.prepare("SELECT version FROM memory_schema WHERE component='responses'").get()?.version;
|
|
18
|
+
if (version !== undefined && version !== 1)
|
|
19
|
+
throw new Error("Unsupported response audit schema version");
|
|
20
|
+
this.#db.exec(`
|
|
21
|
+
CREATE TABLE IF NOT EXISTS response_lease (id INTEGER PRIMARY KEY CHECK(id=1), token TEXT, expires INTEGER);
|
|
22
|
+
CREATE TABLE IF NOT EXISTS response_results (
|
|
23
|
+
cohort TEXT, id TEXT, session_id TEXT NOT NULL, input_hash TEXT NOT NULL,
|
|
24
|
+
episode_at INTEGER NOT NULL, active INTEGER NOT NULL, status TEXT NOT NULL,
|
|
25
|
+
attempts INTEGER NOT NULL DEFAULT 0, attempted_at INTEGER, assessed_at INTEGER, result TEXT,
|
|
26
|
+
PRIMARY KEY(cohort,id));
|
|
27
|
+
CREATE TABLE IF NOT EXISTS response_scans (cohort TEXT PRIMARY KEY, observed_at INTEGER, coverage TEXT);
|
|
28
|
+
CREATE INDEX IF NOT EXISTS response_results_time ON response_results(cohort,episode_at);
|
|
29
|
+
CREATE INDEX IF NOT EXISTS response_results_session ON response_results(cohort,session_id,episode_at);`);
|
|
30
|
+
this.#db.exec(`CREATE TABLE IF NOT EXISTS response_checkpoints (
|
|
31
|
+
cohort TEXT NOT NULL, session_id TEXT NOT NULL, revision TEXT NOT NULL, coverage TEXT NOT NULL,
|
|
32
|
+
PRIMARY KEY(cohort,session_id));
|
|
33
|
+
CREATE TABLE IF NOT EXISTS response_cursors (cohort TEXT PRIMARY KEY,cursor TEXT NOT NULL);
|
|
34
|
+
CREATE TABLE IF NOT EXISTS response_schedule (
|
|
35
|
+
id INTEGER PRIMARY KEY CHECK(id=1), interval_ms INTEGER NOT NULL, next_due INTEGER NOT NULL);
|
|
36
|
+
CREATE TABLE IF NOT EXISTS response_stages (
|
|
37
|
+
key TEXT PRIMARY KEY, stage TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'pending',
|
|
38
|
+
attempts INTEGER NOT NULL DEFAULT 0, attempted_at INTEGER, assessed_at INTEGER, result TEXT);
|
|
39
|
+
CREATE TABLE IF NOT EXISTS response_stage_links (
|
|
40
|
+
cohort TEXT NOT NULL, episode_id TEXT NOT NULL, input_hash TEXT NOT NULL, stage TEXT NOT NULL, key TEXT NOT NULL,
|
|
41
|
+
PRIMARY KEY(cohort,episode_id,stage));`);
|
|
42
|
+
const reviews = new ResponseReviews(this.#db);
|
|
43
|
+
this.#db.exec("INSERT OR IGNORE INTO memory_schema VALUES ('responses',1)");
|
|
44
|
+
return reviews;
|
|
45
|
+
});
|
|
41
46
|
}
|
|
42
47
|
catch (error) {
|
|
43
48
|
this.#db.close();
|
|
@@ -84,24 +89,47 @@ export class ResponseAuditStore {
|
|
|
84
89
|
});
|
|
85
90
|
}
|
|
86
91
|
needsJudgment(cohort, e, now) {
|
|
87
|
-
const row = this.#db.prepare(
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
const row = this.#db.prepare(`SELECT 1 FROM response_results
|
|
93
|
+
WHERE cohort=? AND id=? AND input_hash=? AND active=1
|
|
94
|
+
AND (status!='ok' OR json_extract(result,'$.memory.status')='unavailable')
|
|
95
|
+
AND attempts<? AND (attempted_at IS NULL OR attempted_at<=?)`)
|
|
96
|
+
.get(cohort, e.id, e.inputHash, MAX_RETRY_ATTEMPTS, now - RETRY_BACKOFF_MS);
|
|
97
|
+
return !!row;
|
|
98
|
+
}
|
|
99
|
+
memoryRetryResult(cohort, e) {
|
|
100
|
+
const row = this.#db.prepare(`SELECT result FROM response_results r
|
|
101
|
+
WHERE cohort=? AND id=? AND input_hash=? AND active=1 AND status='ok'
|
|
102
|
+
AND json_extract(result,'$.memory.status')='unavailable'
|
|
103
|
+
AND NOT EXISTS (
|
|
104
|
+
SELECT 1 FROM response_stage_links l LEFT JOIN response_stages s ON s.key=l.key
|
|
105
|
+
WHERE l.cohort=r.cohort AND l.episode_id=r.id AND l.input_hash=r.input_hash
|
|
106
|
+
AND l.stage!='memory' AND (s.status IS NULL OR s.status!='ok')
|
|
107
|
+
)`).get(cohort, e.id, e.inputHash);
|
|
108
|
+
return row && typeof row.result === "string" ? JSON.parse(row.result) : undefined;
|
|
90
109
|
}
|
|
91
110
|
attempted(cohort, e, now) {
|
|
92
|
-
this.#db.prepare(
|
|
111
|
+
this.#db.prepare(`UPDATE response_results SET attempts=attempts+1,attempted_at=?,
|
|
112
|
+
status=CASE WHEN status='ok' THEN 'ok' ELSE 'failed' END
|
|
113
|
+
WHERE cohort=? AND id=? AND input_hash=?`)
|
|
93
114
|
.run(now, cohort, e.id, e.inputHash);
|
|
94
115
|
}
|
|
95
116
|
stale(cohort, e) {
|
|
96
117
|
// Snapshot races are not provider failures and must not exhaust their retry budget.
|
|
97
|
-
this.#db.prepare(`UPDATE response_results SET attempts=MAX(0,attempts-1),attempted_at=NULL,
|
|
98
|
-
|
|
118
|
+
this.#db.prepare(`UPDATE response_results SET attempts=MAX(0,attempts-1),attempted_at=NULL,
|
|
119
|
+
status=CASE WHEN status='ok' THEN 'ok' ELSE 'pending' END
|
|
120
|
+
WHERE cohort=? AND id=? AND input_hash=? AND active=1
|
|
121
|
+
AND (status='failed' OR (status='ok' AND json_extract(result,'$.memory.status')='unavailable'))`)
|
|
122
|
+
.run(cohort, e.id, e.inputHash);
|
|
99
123
|
}
|
|
100
124
|
save(cohort, e, result, now) {
|
|
101
125
|
result = { ...result, human: result.human ?? new ResponsePeople().resolve(e) };
|
|
126
|
+
const memoryUnavailable = result.memory.status === "unavailable" ? 1 : 0;
|
|
102
127
|
immediateTransaction(this.#db, () => {
|
|
103
|
-
const changed = this.#db.prepare(
|
|
104
|
-
|
|
128
|
+
const changed = this.#db.prepare(`UPDATE response_results SET
|
|
129
|
+
attempts=CASE WHEN ?=1 AND (status!='ok' OR COALESCE(json_extract(result,'$.memory.status'),'')!='unavailable') THEN 1 ELSE attempts END,
|
|
130
|
+
attempted_at=CASE WHEN ?=1 THEN ? ELSE attempted_at END,
|
|
131
|
+
status='ok',assessed_at=?,result=? WHERE cohort=? AND id=? AND input_hash=? AND active=1`)
|
|
132
|
+
.run(memoryUnavailable, memoryUnavailable, now, now, JSON.stringify(result), cohort, e.id, e.inputHash).changes;
|
|
105
133
|
if (changed)
|
|
106
134
|
this.reviews.sync(cohort, e.id, e.inputHash, result, now);
|
|
107
135
|
});
|
|
@@ -122,14 +150,17 @@ export class ResponseAuditStore {
|
|
|
122
150
|
this.#db.prepare("DELETE FROM response_checkpoints WHERE cohort=? AND session_id=?").run(cohort, session);
|
|
123
151
|
}
|
|
124
152
|
sessionWork(cohort, session, since, now) {
|
|
125
|
-
const row = this.#db.prepare(`SELECT COUNT(*) total,SUM(CASE WHEN status!='ok'
|
|
126
|
-
(attempted_at IS NULL OR attempted_at<=?) THEN 1 ELSE 0 END) due FROM response_results
|
|
127
|
-
WHERE cohort=? AND session_id=? AND active=1 AND episode_at>=?`)
|
|
153
|
+
const row = this.#db.prepare(`SELECT COUNT(*) total,SUM(CASE WHEN (status!='ok' OR json_extract(result,'$.memory.status')='unavailable')
|
|
154
|
+
AND attempts<? AND (attempted_at IS NULL OR attempted_at<=?) THEN 1 ELSE 0 END) due FROM response_results
|
|
155
|
+
WHERE cohort=? AND session_id=? AND active=1 AND episode_at>=?`)
|
|
156
|
+
.get(MAX_RETRY_ATTEMPTS, now - RETRY_BACKOFF_MS, cohort, session, since);
|
|
128
157
|
return { total: Number(row.total), due: Number(row.due ?? 0) };
|
|
129
158
|
}
|
|
130
159
|
pendingWork(cohort, since, now) {
|
|
131
160
|
return Number(this.#db.prepare(`SELECT COUNT(*) n FROM response_results WHERE cohort=? AND active=1 AND episode_at>=?
|
|
132
|
-
AND status!='ok'
|
|
161
|
+
AND (status!='ok' OR json_extract(result,'$.memory.status')='unavailable')
|
|
162
|
+
AND attempts<? AND (attempted_at IS NULL OR attempted_at<=?)`)
|
|
163
|
+
.get(cohort, since, MAX_RETRY_ATTEMPTS, now - RETRY_BACKOFF_MS).n);
|
|
133
164
|
}
|
|
134
165
|
/** Retry eligibility is not completion: include backoff and exhausted work. */
|
|
135
166
|
unresolvedWork(cohort, since, until) {
|
|
@@ -139,18 +170,39 @@ export class ResponseAuditStore {
|
|
|
139
170
|
WHERE l.cohort=r.cohort AND l.episode_id=r.id AND l.input_hash=r.input_hash AND (s.status IS NULL OR s.status!='ok')))`)
|
|
140
171
|
.get(cohort, since, until).n);
|
|
141
172
|
}
|
|
142
|
-
stage(cohort, e, stage, key) {
|
|
143
|
-
this.#db
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
173
|
+
stage(cohort, e, stage, key, contract) {
|
|
174
|
+
return immediateTransaction(this.#db, () => {
|
|
175
|
+
this.#db.prepare("INSERT OR IGNORE INTO response_stages(key,stage) VALUES(?,?)").run(key, stage);
|
|
176
|
+
this.#db.prepare(`INSERT INTO response_stage_links VALUES(?,?,?,?,?) ON CONFLICT(cohort,episode_id,stage)
|
|
177
|
+
DO UPDATE SET input_hash=excluded.input_hash,key=excluded.key`).run(cohort, e.id, e.inputHash, stage, key);
|
|
178
|
+
const row = this.#db.prepare("SELECT result FROM response_stages WHERE key=? AND status='ok'").get(key);
|
|
179
|
+
if (!row)
|
|
180
|
+
return undefined;
|
|
181
|
+
try {
|
|
182
|
+
if (typeof row.result !== "string")
|
|
183
|
+
throw new Error("Missing cached response stage payload");
|
|
184
|
+
const effectiveContract = (contract !== undefined
|
|
185
|
+
? contract
|
|
186
|
+
: stage === "retrospective" && e.followup
|
|
187
|
+
? { status: e.followup.status }
|
|
188
|
+
: undefined);
|
|
189
|
+
return validateCachedStage(stage, JSON.parse(row.result), effectiveContract);
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
// Evict only this corrupted cached stage so valid siblings remain cached and this stage can recompute cleanly.
|
|
193
|
+
this.#db.prepare(`UPDATE response_stages
|
|
194
|
+
SET status='pending',attempts=0,attempted_at=NULL,assessed_at=NULL,result=NULL
|
|
195
|
+
WHERE key=? AND status='ok'`).run(key);
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
148
199
|
}
|
|
149
200
|
stageBegin(keys, now) {
|
|
150
201
|
immediateTransaction(this.#db, () => {
|
|
151
202
|
for (const key of keys) {
|
|
152
203
|
const changed = this.#db.prepare(`UPDATE response_stages SET attempts=attempts+1,attempted_at=?,status='failed'
|
|
153
|
-
WHERE key=? AND status!='ok' AND attempts
|
|
204
|
+
WHERE key=? AND status!='ok' AND attempts<? AND (attempted_at IS NULL OR attempted_at<=?)`)
|
|
205
|
+
.run(now, key, MAX_RETRY_ATTEMPTS, now - RETRY_BACKOFF_MS).changes;
|
|
154
206
|
if (!changed)
|
|
155
207
|
throw new Error("Response stage in backoff or retry exhausted");
|
|
156
208
|
}
|
|
@@ -161,15 +213,33 @@ export class ResponseAuditStore {
|
|
|
161
213
|
}
|
|
162
214
|
retryFailed(cohort) {
|
|
163
215
|
return immediateTransaction(this.#db, () => {
|
|
164
|
-
const
|
|
165
|
-
WHERE cohort=? AND active=1 AND
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
216
|
+
const memoryOnly = this.#db.prepare(`UPDATE response_results AS r SET attempts=0,attempted_at=NULL
|
|
217
|
+
WHERE cohort=? AND active=1 AND status='ok' AND json_extract(result,'$.memory.status')='unavailable'
|
|
218
|
+
AND NOT EXISTS (
|
|
219
|
+
SELECT 1 FROM response_stage_links l LEFT JOIN response_stages s ON s.key=l.key
|
|
220
|
+
WHERE l.cohort=r.cohort AND l.episode_id=r.id AND l.input_hash=r.input_hash
|
|
221
|
+
AND l.stage!='memory' AND (s.status IS NULL OR s.status!='ok')
|
|
222
|
+
)`).run(cohort).changes;
|
|
223
|
+
const reset = this.#db.prepare(`UPDATE response_results AS r
|
|
224
|
+
SET attempts=0,attempted_at=NULL,assessed_at=NULL,result=NULL,status='pending'
|
|
225
|
+
WHERE cohort=? AND active=1 AND (
|
|
226
|
+
status!='ok'
|
|
227
|
+
OR (NOT (status='ok' AND COALESCE(json_extract(result,'$.memory.status'),'')='unavailable') AND EXISTS (
|
|
228
|
+
SELECT 1 FROM response_stage_links l LEFT JOIN response_stages s ON s.key=l.key
|
|
229
|
+
WHERE l.cohort=r.cohort AND l.episode_id=r.id AND l.input_hash=r.input_hash
|
|
230
|
+
AND (s.status IS NULL OR s.status!='ok')
|
|
231
|
+
))
|
|
232
|
+
OR EXISTS (
|
|
233
|
+
SELECT 1 FROM response_stage_links l LEFT JOIN response_stages s ON s.key=l.key
|
|
234
|
+
WHERE l.cohort=r.cohort AND l.episode_id=r.id AND l.input_hash=r.input_hash
|
|
235
|
+
AND l.stage!='memory' AND (s.status IS NULL OR s.status!='ok')
|
|
236
|
+
)
|
|
237
|
+
)`).run(cohort).changes;
|
|
238
|
+
const stages = this.#db.prepare(`UPDATE response_stages SET attempts=0,attempted_at=NULL,assessed_at=NULL,result=NULL,status='pending'
|
|
169
239
|
WHERE status!='ok' AND key IN (SELECT l.key FROM response_stage_links l JOIN response_results r
|
|
170
240
|
ON r.cohort=l.cohort AND r.id=l.episode_id AND r.input_hash=l.input_hash WHERE r.cohort=? AND r.active=1)`)
|
|
171
241
|
.run(cohort).changes;
|
|
172
|
-
return { stages, episodes };
|
|
242
|
+
return { stages: Number(stages), episodes: Number(memoryOnly) + Number(reset) };
|
|
173
243
|
});
|
|
174
244
|
}
|
|
175
245
|
scan(cohort, coverage, now) {
|
|
@@ -204,170 +274,19 @@ export class ResponseAuditStore {
|
|
|
204
274
|
const taskType = r.quality.taskType.confidence >= 0.8 ? r.quality.taskType.choice : "uncertain";
|
|
205
275
|
const human = r.human ?? null;
|
|
206
276
|
const key = JSON.stringify([week, taskType, r.agentModel, human?.key ?? null]);
|
|
207
|
-
const g = groups.get(key) ??
|
|
208
|
-
|
|
209
|
-
fulfillmentSum: 0, deliverableSum: 0, feedbackCertain: 0, accepted: 0, reworkCertain: 0, rework: 0, memoryGap: 0, dissatisfied: 0,
|
|
210
|
-
sentimentAssessed: 0, sentimentCertain: 0, emotionAssessed: 0, annoyed: 0, frustrated: 0,
|
|
211
|
-
annoyanceUncertain: 0, frustrationUncertain: 0, dissatisfactionIntensityScored: 0, intensitySum: 0,
|
|
212
|
-
underdeliveryCertain: 0, underdelivery: 0, failureReasons: {},
|
|
213
|
-
feedbackTargets: {}, retrospectiveAssessed: 0, laterCorrections: 0, deliveryAdmissions: 0,
|
|
214
|
-
outcomeKnown: 0, acknowledgedSuccess: 0, reportedShortfall: 0, outcomeReasons: {} };
|
|
215
|
-
g.evaluated++;
|
|
216
|
-
const underdelivery = r.quality.underdelivery.noul >= 0.8;
|
|
217
|
-
if (r.quality.underdelivery.noul <= 0.2 || underdelivery)
|
|
218
|
-
g.underdeliveryCertain++;
|
|
219
|
-
if (underdelivery) {
|
|
220
|
-
g.underdelivery++;
|
|
221
|
-
const reason = r.quality.failureReason.confidence >= 0.8 ? r.quality.failureReason.choice : "uncertain";
|
|
222
|
-
g.failureReasons[reason] = (g.failureReasons[reason] ?? 0) + 1;
|
|
223
|
-
}
|
|
224
|
-
if (r.quality.assessability.choice === "assessable" && r.quality.assessability.confidence >= 0.8) {
|
|
225
|
-
g.assessable++;
|
|
226
|
-
if (r.quality.fulfillment.confidence >= 0.8) {
|
|
227
|
-
g.fulfillmentScored++;
|
|
228
|
-
g.fulfillmentSum += r.quality.fulfillment.score;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
if (r.quality.fitAssessability.choice === "assessable" && r.quality.fitAssessability.confidence >= 0.8) {
|
|
232
|
-
g.fitAssessable++;
|
|
233
|
-
if (r.quality.deliverableFit.confidence >= 0.8) {
|
|
234
|
-
g.deliverableFitScored++;
|
|
235
|
-
g.deliverableSum += r.quality.deliverableFit.score;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
const target = r.feedback.target.confidence >= 0.8 ? r.feedback.target.choice : "uncertain";
|
|
239
|
-
g.feedbackTargets[target] = (g.feedbackTargets[target] ?? 0) + 1;
|
|
240
|
-
const laterCorrection = (r.retrospective.judgment?.correction.noul ?? 0) >= 0.8;
|
|
241
|
-
const deliveryAdmission = (r.retrospective.judgment?.deliveryAdmission.noul ?? 0) >= 0.8;
|
|
242
|
-
const outcome = responseOutcome(r);
|
|
243
|
-
const reportedShortfall = outcome.status === "reported_shortfall";
|
|
244
|
-
if (reportedShortfall || outcome.status === "acknowledged_success") {
|
|
245
|
-
g.outcomeKnown++;
|
|
246
|
-
if (reportedShortfall) {
|
|
247
|
-
g.reportedShortfall++;
|
|
248
|
-
for (const label of outcome.reasons.length ? outcome.reasons : ["uncertain"]) {
|
|
249
|
-
g.outcomeReasons[label] = (g.outcomeReasons[label] ?? 0) + 1;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
else
|
|
253
|
-
g.acknowledgedSuccess++;
|
|
254
|
-
}
|
|
255
|
-
if (r.retrospective.judgment)
|
|
256
|
-
g.retrospectiveAssessed++;
|
|
257
|
-
if (laterCorrection)
|
|
258
|
-
g.laterCorrections++;
|
|
259
|
-
if (deliveryAdmission)
|
|
260
|
-
g.deliveryAdmissions++;
|
|
261
|
-
if (r.feedback.feedbackType.confidence >= 0.8) {
|
|
262
|
-
g.feedbackCertain++;
|
|
263
|
-
if (r.feedback.feedbackType.choice === "acceptance")
|
|
264
|
-
g.accepted++;
|
|
265
|
-
}
|
|
266
|
-
const burden = r.feedback.avoidableRework.noul;
|
|
267
|
-
if (burden <= 0.2 || burden >= 0.8) {
|
|
268
|
-
g.reworkCertain++;
|
|
269
|
-
if (burden >= 0.8)
|
|
270
|
-
g.rework++;
|
|
271
|
-
}
|
|
272
|
-
const memoryGap = r.feedback.memoryGap.noul >= 0.8;
|
|
273
|
-
const sentiment = r.feedback.sentiment;
|
|
274
|
-
const sentimentCertain = !!sentiment && sentiment.confidence >= 0.8 && sentiment.choice !== "unclear";
|
|
275
|
-
const dissatisfied = sentimentCertain && ["dissatisfied", "mixed"].includes(sentiment.choice);
|
|
276
|
-
if (sentiment)
|
|
277
|
-
g.sentimentAssessed++;
|
|
278
|
-
if (sentimentCertain)
|
|
279
|
-
g.sentimentCertain++;
|
|
280
|
-
const { annoyance, frustration, dissatisfactionIntensity: intensity } = r.feedback;
|
|
281
|
-
const annoyed = !!annoyance && annoyance.noul >= 0.8;
|
|
282
|
-
const frustrated = !!frustration && frustration.noul >= 0.8;
|
|
283
|
-
if (annoyance && frustration) {
|
|
284
|
-
g.emotionAssessed++;
|
|
285
|
-
if (annoyed)
|
|
286
|
-
g.annoyed++;
|
|
287
|
-
if (frustrated)
|
|
288
|
-
g.frustrated++;
|
|
289
|
-
if (annoyance.noul > 0.2 && annoyance.noul < 0.8)
|
|
290
|
-
g.annoyanceUncertain++;
|
|
291
|
-
if (frustration.noul > 0.2 && frustration.noul < 0.8)
|
|
292
|
-
g.frustrationUncertain++;
|
|
293
|
-
}
|
|
294
|
-
if (intensity && intensity.confidence >= 0.8) {
|
|
295
|
-
g.dissatisfactionIntensityScored++;
|
|
296
|
-
g.intensitySum += intensity.score;
|
|
297
|
-
}
|
|
298
|
-
if (memoryGap)
|
|
299
|
-
g.memoryGap++;
|
|
300
|
-
if (dissatisfied)
|
|
301
|
-
g.dissatisfied++;
|
|
277
|
+
const g = groups.get(key) ?? createReportGroup(week, human, taskType, r.agentModel);
|
|
278
|
+
const { signals, outcome } = recordEpisodeInGroup(g, r);
|
|
302
279
|
groups.set(key, g);
|
|
303
|
-
const signals = [underdelivery ? "clear_underdelivery" : "", burden >= 0.8 ? "avoidable_rework" : "", memoryGap ? "reported_memory_gap" : "", dissatisfied ? `dissatisfied:${target}` : "",
|
|
304
|
-
annoyed ? `annoyed:${target}` : "", frustrated ? `frustrated:${target}` : "",
|
|
305
|
-
laterCorrection ? "later_correction" : "", deliveryAdmission ? "delivery_admission" : "", reportedShortfall ? "reported_shortfall" : ""].filter(Boolean);
|
|
306
280
|
if (signals.length && examples.length < 20)
|
|
307
281
|
examples.push({ id: String(row.id), episodeAt: Number(row.episode_at), assessedAt: Number(row.assessed_at), signals, outcome });
|
|
308
282
|
}
|
|
309
|
-
const summaries = [...groups.values()].map(
|
|
310
|
-
|
|
311
|
-
fulfillmentMean: g.fulfillmentScored ? fulfillmentSum / g.fulfillmentScored : null,
|
|
312
|
-
deliverableFitMean: g.deliverableFitScored ? deliverableSum / g.deliverableFitScored : null,
|
|
313
|
-
sentimentNotAssessed: g.evaluated - g.sentimentAssessed,
|
|
314
|
-
sentimentUnknown: g.sentimentAssessed - g.sentimentCertain,
|
|
315
|
-
sentimentCoverage: g.sentimentAssessed / g.evaluated,
|
|
316
|
-
// Observed rates include uncertainty in their denominator, never silently label it neutral.
|
|
317
|
-
dissatisfactionRate: g.sentimentAssessed ? g.dissatisfied / g.sentimentAssessed : null,
|
|
318
|
-
sentimentUnknownRate: g.sentimentAssessed ? (g.sentimentAssessed - g.sentimentCertain) / g.sentimentAssessed : null,
|
|
319
|
-
annoyanceRate: g.emotionAssessed ? g.annoyed / g.emotionAssessed : null,
|
|
320
|
-
frustrationRate: g.emotionAssessed ? g.frustrated / g.emotionAssessed : null,
|
|
321
|
-
dissatisfactionIntensityMean: g.dissatisfactionIntensityScored ? intensitySum / g.dissatisfactionIntensityScored : null,
|
|
322
|
-
observedSuccessRate: g.outcomeKnown ? g.acknowledgedSuccess / g.outcomeKnown : null,
|
|
323
|
-
observedSuccessRate95Interval: wilson(g.acknowledgedSuccess, g.outcomeKnown),
|
|
324
|
-
outcomeUnknown: g.evaluated - g.outcomeKnown,
|
|
325
|
-
outcomeCoverage: g.outcomeKnown / g.evaluated,
|
|
326
|
-
acknowledgedRate: g.acknowledgedSuccess / g.evaluated,
|
|
327
|
-
reportedShortfallRate: g.reportedShortfall / g.evaluated,
|
|
328
|
-
unknownRate: (g.evaluated - g.outcomeKnown) / g.evaluated,
|
|
329
|
-
underdeliveryRate: g.underdeliveryCertain ? g.underdelivery / g.underdeliveryCertain : null,
|
|
330
|
-
underdeliveryRate95Interval: wilson(g.underdelivery, g.underdeliveryCertain),
|
|
331
|
-
reworkRate: g.reworkCertain ? g.rework / g.reworkCertain : null,
|
|
332
|
-
reworkRate95Interval: wilson(g.rework, g.reworkCertain), smallSample: g.evaluated < 20,
|
|
333
|
-
}));
|
|
334
|
-
const trends = summaries.flatMap(current => {
|
|
335
|
-
const previous = summaries.filter(g => g.taskType === current.taskType && g.agentModel === current.agentModel &&
|
|
336
|
-
g.human?.key === current.human?.key && g.week < current.week)
|
|
337
|
-
.sort((a, b) => b.week.localeCompare(a.week))[0];
|
|
338
|
-
if (!previous)
|
|
339
|
-
return [];
|
|
340
|
-
return ["fulfillment", "deliverableFit", "acknowledgedRate", "reportedShortfallRate", "unknownRate",
|
|
341
|
-
"dissatisfactionRate", "sentimentUnknownRate", "annoyanceRate", "frustrationRate", "dissatisfactionIntensity"].map(dimension => {
|
|
342
|
-
const scoreDimension = dimension === "fulfillment" || dimension === "deliverableFit" || dimension === "dissatisfactionIntensity" ? dimension : null;
|
|
343
|
-
const sentimentDimension = dimension === "dissatisfactionRate" || dimension === "sentimentUnknownRate";
|
|
344
|
-
const emotionDimension = dimension === "annoyanceRate" || dimension === "frustrationRate";
|
|
345
|
-
const assessedSubset = scoreDimension || sentimentDimension || emotionDimension;
|
|
346
|
-
const beforeN = scoreDimension ? previous[`${scoreDimension}Scored`] : sentimentDimension ? previous.sentimentAssessed : emotionDimension ? previous.emotionAssessed : previous.evaluated;
|
|
347
|
-
const afterN = scoreDimension ? current[`${scoreDimension}Scored`] : sentimentDimension ? current.sentimentAssessed : emotionDimension ? current.emotionAssessed : current.evaluated;
|
|
348
|
-
const before = dimension === "fulfillment" || dimension === "deliverableFit" || dimension === "dissatisfactionIntensity" ? previous[`${dimension}Mean`] : previous[dimension];
|
|
349
|
-
const after = dimension === "fulfillment" || dimension === "deliverableFit" || dimension === "dissatisfactionIntensity" ? current[`${dimension}Mean`] : current[dimension];
|
|
350
|
-
const beforeCoverage = assessedSubset ? beforeN / previous.evaluated : previous.outcomeCoverage;
|
|
351
|
-
const afterCoverage = assessedSubset ? afterN / current.evaluated : current.outcomeCoverage;
|
|
352
|
-
const coverageChanged = beforeCoverage !== afterCoverage;
|
|
353
|
-
const enough = beforeN >= 20 && afterN >= 20 && current.taskType !== "uncertain" && current.agentModel !== "unknown";
|
|
354
|
-
const status = !current.human || !current.human.accountScope || current.taskType === "uncertain" || current.agentModel === "unknown" ? "unknown_stratum" :
|
|
355
|
-
!enough ? "insufficient_samples" : assessedSubset && coverageChanged ? "coverage_changed" : "descriptive_comparison";
|
|
356
|
-
return { fromWeek: previous.week, toWeek: current.week, taskType: current.taskType, agentModel: current.agentModel,
|
|
357
|
-
fromPeriod: previous.week, toPeriod: current.week, human: current.human,
|
|
358
|
-
dimension, beforeN, afterN, status,
|
|
359
|
-
before, after, beforeEvaluated: previous.evaluated, afterEvaluated: current.evaluated,
|
|
360
|
-
beforeCoverage, afterCoverage, coverageChanged,
|
|
361
|
-
denominator: dimension === "dissatisfactionIntensity" ? "confident_intensity_exchanges" : scoreDimension ? "confident_assessable_exchanges" : sentimentDimension ? "sentiment_assessed_exchanges" : emotionDimension ? "emotion_assessed_exchanges" : "all_evaluated_exchanges",
|
|
362
|
-
scale: dimension === "dissatisfactionIntensity" ? "0_to_3_expressed_dissatisfaction" : scoreDimension ? "0_to_3_visible_quality" : "0_to_1_observed_rate",
|
|
363
|
-
delta: status === "descriptive_comparison" ? after - before : null };
|
|
364
|
-
});
|
|
365
|
-
});
|
|
283
|
+
const summaries = [...groups.values()].map(summarizeGroup);
|
|
284
|
+
const trends = computeTrends(summaries);
|
|
366
285
|
const stages = this.#db.prepare(`SELECT s.stage,s.status,COUNT(*) count,
|
|
367
|
-
SUM(CASE WHEN s.status!='ok' AND s.attempts
|
|
286
|
+
SUM(CASE WHEN s.status!='ok' AND s.attempts>=? THEN 1 ELSE 0 END) exhausted
|
|
368
287
|
FROM response_stage_links l JOIN response_stages s ON s.key=l.key JOIN response_results r
|
|
369
288
|
ON r.cohort=l.cohort AND r.id=l.episode_id AND r.input_hash=l.input_hash
|
|
370
|
-
WHERE r.cohort=? AND r.active=1 AND r.episode_at>=? AND r.episode_at<? GROUP BY s.stage,s.status`).all(cohort, since, until);
|
|
289
|
+
WHERE r.cohort=? AND r.active=1 AND r.episode_at>=? AND r.episode_at<? GROUP BY s.stage,s.status`).all(MAX_RETRY_ATTEMPTS, cohort, since, until);
|
|
371
290
|
return { cohort, reportVersion: RESPONSE_REPORT_VERSION, reviewPolicy: RESPONSE_REVIEW_POLICY, bucket, since, until,
|
|
372
291
|
annotations: this.reviews.annotations(since, until), stages, stageCountsScope: "cohort_and_date_range_before_person_filters",
|
|
373
292
|
rubricScope: "Responded-to exchanges only; observational, not factual verification or causal performance attribution.",
|
|
@@ -388,6 +307,209 @@ export class ResponseAuditStore {
|
|
|
388
307
|
}
|
|
389
308
|
close() { this.#db.close(); }
|
|
390
309
|
}
|
|
310
|
+
function createReportGroup(week, human, taskType, agentModel) {
|
|
311
|
+
return {
|
|
312
|
+
week, human, taskType, agentModel, evaluated: 0, assessable: 0, fitAssessable: 0,
|
|
313
|
+
fulfillmentScored: 0, deliverableFitScored: 0,
|
|
314
|
+
fulfillmentSum: 0, deliverableSum: 0, feedbackCertain: 0, accepted: 0, reworkCertain: 0, rework: 0, memoryGap: 0, dissatisfied: 0,
|
|
315
|
+
sentimentAssessed: 0, sentimentCertain: 0, emotionAssessed: 0, annoyed: 0, frustrated: 0,
|
|
316
|
+
annoyanceUncertain: 0, frustrationUncertain: 0, dissatisfactionIntensityScored: 0, intensitySum: 0,
|
|
317
|
+
underdeliveryCertain: 0, underdelivery: 0, failureReasons: {},
|
|
318
|
+
feedbackTargets: {}, retrospectiveAssessed: 0, laterCorrections: 0, deliveryAdmissions: 0,
|
|
319
|
+
outcomeKnown: 0, acknowledgedSuccess: 0, reportedShortfall: 0, outcomeReasons: {},
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
function recordEpisodeInGroup(g, r) {
|
|
323
|
+
g.evaluated++;
|
|
324
|
+
const underdelivery = r.quality.underdelivery.noul >= 0.8;
|
|
325
|
+
if (r.quality.underdelivery.noul <= 0.2 || underdelivery)
|
|
326
|
+
g.underdeliveryCertain++;
|
|
327
|
+
if (underdelivery) {
|
|
328
|
+
g.underdelivery++;
|
|
329
|
+
const reason = r.quality.failureReason.confidence >= 0.8 ? r.quality.failureReason.choice : "uncertain";
|
|
330
|
+
g.failureReasons[reason] = (g.failureReasons[reason] ?? 0) + 1;
|
|
331
|
+
}
|
|
332
|
+
if (r.quality.assessability.choice === "assessable" && r.quality.assessability.confidence >= 0.8) {
|
|
333
|
+
g.assessable++;
|
|
334
|
+
if (r.quality.fulfillment.confidence >= 0.8) {
|
|
335
|
+
g.fulfillmentScored++;
|
|
336
|
+
g.fulfillmentSum += r.quality.fulfillment.score;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (r.quality.fitAssessability.choice === "assessable" && r.quality.fitAssessability.confidence >= 0.8) {
|
|
340
|
+
g.fitAssessable++;
|
|
341
|
+
if (r.quality.deliverableFit.confidence >= 0.8) {
|
|
342
|
+
g.deliverableFitScored++;
|
|
343
|
+
g.deliverableSum += r.quality.deliverableFit.score;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
const target = r.feedback.target.confidence >= 0.8 ? r.feedback.target.choice : "uncertain";
|
|
347
|
+
g.feedbackTargets[target] = (g.feedbackTargets[target] ?? 0) + 1;
|
|
348
|
+
const laterCorrection = (r.retrospective.judgment?.correction.noul ?? 0) >= 0.8;
|
|
349
|
+
const deliveryAdmission = (r.retrospective.judgment?.deliveryAdmission.noul ?? 0) >= 0.8;
|
|
350
|
+
const outcome = responseOutcome(r);
|
|
351
|
+
const reportedShortfall = outcome.status === "reported_shortfall";
|
|
352
|
+
if (reportedShortfall || outcome.status === "acknowledged_success") {
|
|
353
|
+
g.outcomeKnown++;
|
|
354
|
+
if (reportedShortfall) {
|
|
355
|
+
g.reportedShortfall++;
|
|
356
|
+
for (const label of outcome.reasons.length ? outcome.reasons : ["uncertain"]) {
|
|
357
|
+
g.outcomeReasons[label] = (g.outcomeReasons[label] ?? 0) + 1;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
else
|
|
361
|
+
g.acknowledgedSuccess++;
|
|
362
|
+
}
|
|
363
|
+
if (r.retrospective.judgment)
|
|
364
|
+
g.retrospectiveAssessed++;
|
|
365
|
+
if (laterCorrection)
|
|
366
|
+
g.laterCorrections++;
|
|
367
|
+
if (deliveryAdmission)
|
|
368
|
+
g.deliveryAdmissions++;
|
|
369
|
+
if (r.feedback.feedbackType.confidence >= 0.8) {
|
|
370
|
+
g.feedbackCertain++;
|
|
371
|
+
if (r.feedback.feedbackType.choice === "acceptance")
|
|
372
|
+
g.accepted++;
|
|
373
|
+
}
|
|
374
|
+
const burden = r.feedback.avoidableRework.noul;
|
|
375
|
+
if (burden <= 0.2 || burden >= 0.8) {
|
|
376
|
+
g.reworkCertain++;
|
|
377
|
+
if (burden >= 0.8)
|
|
378
|
+
g.rework++;
|
|
379
|
+
}
|
|
380
|
+
const memoryGap = r.feedback.memoryGap.noul >= 0.8;
|
|
381
|
+
const sentiment = r.feedback.sentiment;
|
|
382
|
+
const sentimentCertain = !!sentiment && sentiment.confidence >= 0.8 && sentiment.choice !== "unclear";
|
|
383
|
+
const dissatisfied = sentimentCertain && ["dissatisfied", "mixed"].includes(sentiment.choice);
|
|
384
|
+
if (sentiment)
|
|
385
|
+
g.sentimentAssessed++;
|
|
386
|
+
if (sentimentCertain)
|
|
387
|
+
g.sentimentCertain++;
|
|
388
|
+
const { annoyance, frustration, dissatisfactionIntensity: intensity } = r.feedback;
|
|
389
|
+
const annoyed = !!annoyance && annoyance.noul >= 0.8;
|
|
390
|
+
const frustrated = !!frustration && frustration.noul >= 0.8;
|
|
391
|
+
if (annoyance && frustration) {
|
|
392
|
+
g.emotionAssessed++;
|
|
393
|
+
if (annoyed)
|
|
394
|
+
g.annoyed++;
|
|
395
|
+
if (frustrated)
|
|
396
|
+
g.frustrated++;
|
|
397
|
+
if (annoyance.noul > 0.2 && annoyance.noul < 0.8)
|
|
398
|
+
g.annoyanceUncertain++;
|
|
399
|
+
if (frustration.noul > 0.2 && frustration.noul < 0.8)
|
|
400
|
+
g.frustrationUncertain++;
|
|
401
|
+
}
|
|
402
|
+
if (intensity && intensity.confidence >= 0.8) {
|
|
403
|
+
g.dissatisfactionIntensityScored++;
|
|
404
|
+
g.intensitySum += intensity.score;
|
|
405
|
+
}
|
|
406
|
+
if (memoryGap)
|
|
407
|
+
g.memoryGap++;
|
|
408
|
+
if (dissatisfied)
|
|
409
|
+
g.dissatisfied++;
|
|
410
|
+
const signals = [underdelivery ? "clear_underdelivery" : "", burden >= 0.8 ? "avoidable_rework" : "", memoryGap ? "reported_memory_gap" : "", dissatisfied ? `dissatisfied:${target}` : "",
|
|
411
|
+
annoyed ? `annoyed:${target}` : "", frustrated ? `frustrated:${target}` : "",
|
|
412
|
+
laterCorrection ? "later_correction" : "", deliveryAdmission ? "delivery_admission" : "", reportedShortfall ? "reported_shortfall" : ""].filter(Boolean);
|
|
413
|
+
return { signals, outcome };
|
|
414
|
+
}
|
|
415
|
+
function summarizeGroup({ fulfillmentSum, deliverableSum, intensitySum, ...g }) {
|
|
416
|
+
return {
|
|
417
|
+
...g,
|
|
418
|
+
periodStart: g.week,
|
|
419
|
+
fulfillmentMean: g.fulfillmentScored ? fulfillmentSum / g.fulfillmentScored : null,
|
|
420
|
+
deliverableFitMean: g.deliverableFitScored ? deliverableSum / g.deliverableFitScored : null,
|
|
421
|
+
sentimentNotAssessed: g.evaluated - g.sentimentAssessed,
|
|
422
|
+
sentimentUnknown: g.sentimentAssessed - g.sentimentCertain,
|
|
423
|
+
sentimentCoverage: g.sentimentAssessed / g.evaluated,
|
|
424
|
+
// Observed rates include uncertainty in their denominator, never silently label it neutral.
|
|
425
|
+
dissatisfactionRate: g.sentimentAssessed ? g.dissatisfied / g.sentimentAssessed : null,
|
|
426
|
+
sentimentUnknownRate: g.sentimentAssessed ? (g.sentimentAssessed - g.sentimentCertain) / g.sentimentAssessed : null,
|
|
427
|
+
annoyanceRate: g.emotionAssessed ? g.annoyed / g.emotionAssessed : null,
|
|
428
|
+
frustrationRate: g.emotionAssessed ? g.frustrated / g.emotionAssessed : null,
|
|
429
|
+
dissatisfactionIntensityMean: g.dissatisfactionIntensityScored ? intensitySum / g.dissatisfactionIntensityScored : null,
|
|
430
|
+
observedSuccessRate: g.outcomeKnown ? g.acknowledgedSuccess / g.outcomeKnown : null,
|
|
431
|
+
observedSuccessRate95Interval: wilson(g.acknowledgedSuccess, g.outcomeKnown),
|
|
432
|
+
outcomeUnknown: g.evaluated - g.outcomeKnown,
|
|
433
|
+
outcomeCoverage: g.outcomeKnown / g.evaluated,
|
|
434
|
+
acknowledgedRate: g.acknowledgedSuccess / g.evaluated,
|
|
435
|
+
reportedShortfallRate: g.reportedShortfall / g.evaluated,
|
|
436
|
+
unknownRate: (g.evaluated - g.outcomeKnown) / g.evaluated,
|
|
437
|
+
underdeliveryRate: g.underdeliveryCertain ? g.underdelivery / g.underdeliveryCertain : null,
|
|
438
|
+
underdeliveryRate95Interval: wilson(g.underdelivery, g.underdeliveryCertain),
|
|
439
|
+
reworkRate: g.reworkCertain ? g.rework / g.reworkCertain : null,
|
|
440
|
+
reworkRate95Interval: wilson(g.rework, g.reworkCertain),
|
|
441
|
+
smallSample: g.evaluated < 20,
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
const TREND_DIMENSIONS = [
|
|
445
|
+
{ dimension: "fulfillment", sampleKey: "fulfillmentScored", valueKey: "fulfillmentMean", assessedSubset: true,
|
|
446
|
+
denominator: "confident_assessable_exchanges", scale: "0_to_3_visible_quality" },
|
|
447
|
+
{ dimension: "deliverableFit", sampleKey: "deliverableFitScored", valueKey: "deliverableFitMean", assessedSubset: true,
|
|
448
|
+
denominator: "confident_assessable_exchanges", scale: "0_to_3_visible_quality" },
|
|
449
|
+
{ dimension: "acknowledgedRate", sampleKey: "evaluated", valueKey: "acknowledgedRate", assessedSubset: false,
|
|
450
|
+
denominator: "all_evaluated_exchanges", scale: "0_to_1_observed_rate" },
|
|
451
|
+
{ dimension: "reportedShortfallRate", sampleKey: "evaluated", valueKey: "reportedShortfallRate", assessedSubset: false,
|
|
452
|
+
denominator: "all_evaluated_exchanges", scale: "0_to_1_observed_rate" },
|
|
453
|
+
{ dimension: "unknownRate", sampleKey: "evaluated", valueKey: "unknownRate", assessedSubset: false,
|
|
454
|
+
denominator: "all_evaluated_exchanges", scale: "0_to_1_observed_rate" },
|
|
455
|
+
{ dimension: "dissatisfactionRate", sampleKey: "sentimentAssessed", valueKey: "dissatisfactionRate", assessedSubset: true,
|
|
456
|
+
denominator: "sentiment_assessed_exchanges", scale: "0_to_1_observed_rate" },
|
|
457
|
+
{ dimension: "sentimentUnknownRate", sampleKey: "sentimentAssessed", valueKey: "sentimentUnknownRate", assessedSubset: true,
|
|
458
|
+
denominator: "sentiment_assessed_exchanges", scale: "0_to_1_observed_rate" },
|
|
459
|
+
{ dimension: "annoyanceRate", sampleKey: "emotionAssessed", valueKey: "annoyanceRate", assessedSubset: true,
|
|
460
|
+
denominator: "emotion_assessed_exchanges", scale: "0_to_1_observed_rate" },
|
|
461
|
+
{ dimension: "frustrationRate", sampleKey: "emotionAssessed", valueKey: "frustrationRate", assessedSubset: true,
|
|
462
|
+
denominator: "emotion_assessed_exchanges", scale: "0_to_1_observed_rate" },
|
|
463
|
+
{ dimension: "dissatisfactionIntensity", sampleKey: "dissatisfactionIntensityScored", valueKey: "dissatisfactionIntensityMean", assessedSubset: true,
|
|
464
|
+
denominator: "confident_intensity_exchanges", scale: "0_to_3_expressed_dissatisfaction" },
|
|
465
|
+
];
|
|
466
|
+
function computeTrends(summaries) {
|
|
467
|
+
const byStratum = new Map();
|
|
468
|
+
for (const summary of summaries) {
|
|
469
|
+
const stratumKey = JSON.stringify([summary.taskType, summary.agentModel, summary.human?.key ?? null]);
|
|
470
|
+
const list = byStratum.get(stratumKey);
|
|
471
|
+
if (list)
|
|
472
|
+
list.push(summary);
|
|
473
|
+
else
|
|
474
|
+
byStratum.set(stratumKey, [summary]);
|
|
475
|
+
}
|
|
476
|
+
const previousBySummary = new Map();
|
|
477
|
+
for (const periods of byStratum.values()) {
|
|
478
|
+
if (periods.length < 2)
|
|
479
|
+
continue;
|
|
480
|
+
periods.sort((a, b) => a.week.localeCompare(b.week));
|
|
481
|
+
for (let i = 1; i < periods.length; i++)
|
|
482
|
+
previousBySummary.set(periods[i], periods[i - 1]);
|
|
483
|
+
}
|
|
484
|
+
return summaries.flatMap(current => {
|
|
485
|
+
const previous = previousBySummary.get(current);
|
|
486
|
+
if (!previous)
|
|
487
|
+
return [];
|
|
488
|
+
const unknownStratum = !current.human || !current.human.accountScope || current.taskType === "uncertain" || current.agentModel === "unknown";
|
|
489
|
+
return TREND_DIMENSIONS.map(spec => {
|
|
490
|
+
const beforeN = previous[spec.sampleKey];
|
|
491
|
+
const afterN = current[spec.sampleKey];
|
|
492
|
+
const before = previous[spec.valueKey];
|
|
493
|
+
const after = current[spec.valueKey];
|
|
494
|
+
const beforeCoverage = spec.assessedSubset ? beforeN / previous.evaluated : previous.outcomeCoverage;
|
|
495
|
+
const afterCoverage = spec.assessedSubset ? afterN / current.evaluated : current.outcomeCoverage;
|
|
496
|
+
const coverageChanged = beforeCoverage !== afterCoverage;
|
|
497
|
+
const status = unknownStratum ? "unknown_stratum"
|
|
498
|
+
: beforeN < 20 || afterN < 20 ? "insufficient_samples"
|
|
499
|
+
: spec.assessedSubset && coverageChanged ? "coverage_changed"
|
|
500
|
+
: "descriptive_comparison";
|
|
501
|
+
return {
|
|
502
|
+
fromWeek: previous.week, toWeek: current.week, taskType: current.taskType, agentModel: current.agentModel,
|
|
503
|
+
fromPeriod: previous.week, toPeriod: current.week, human: current.human,
|
|
504
|
+
dimension: spec.dimension, beforeN, afterN, status,
|
|
505
|
+
before, after, beforeEvaluated: previous.evaluated, afterEvaluated: current.evaluated,
|
|
506
|
+
beforeCoverage, afterCoverage, coverageChanged,
|
|
507
|
+
denominator: spec.denominator, scale: spec.scale,
|
|
508
|
+
delta: status === "descriptive_comparison" ? after - before : null,
|
|
509
|
+
};
|
|
510
|
+
});
|
|
511
|
+
});
|
|
512
|
+
}
|
|
391
513
|
function wilson(successes, total) {
|
|
392
514
|
if (!total)
|
|
393
515
|
return null;
|
|
@@ -4,6 +4,8 @@ export declare function conversationUserText(raw: string, sender?: unknown): {
|
|
|
4
4
|
text: string;
|
|
5
5
|
contextLimited: boolean;
|
|
6
6
|
} | undefined;
|
|
7
|
+
/** Unwrap human text for recall query generation, including non-Slack OpenClaw inbound envelopes. */
|
|
8
|
+
export declare function queryUserText(raw: string, sender?: unknown): string | undefined;
|
|
7
9
|
/** Like conversationUserText, plus the untrusted inbound context (thread starter, reply target,
|
|
8
10
|
* chat history) that a recognized envelope carries before the current message. */
|
|
9
11
|
export declare function conversationEnvelope(raw: string, sender?: unknown): {
|