@unblocklabs/unblock-memory 0.12.3 → 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.
Files changed (119) hide show
  1. package/README.md +19 -18
  2. package/dist/src/analysis.js +1 -1
  3. package/dist/src/cluster-review.d.ts +2 -0
  4. package/dist/src/cluster-review.js +3 -3
  5. package/dist/src/config.d.ts +9 -6
  6. package/dist/src/config.js +31 -20
  7. package/dist/src/curation.d.ts +1 -1
  8. package/dist/src/decision-client.d.ts +39 -0
  9. package/dist/src/decision-client.js +74 -0
  10. package/dist/src/{typesafe.d.ts → decision-ranking.d.ts} +15 -18
  11. package/dist/src/decision-ranking.js +154 -0
  12. package/dist/src/{typesafe-review.d.ts → decision-review.d.ts} +13 -9
  13. package/dist/src/decision-review.js +192 -0
  14. package/dist/src/diagnostics.d.ts +5 -5
  15. package/dist/src/emotion-baselines.d.ts +28 -3
  16. package/dist/src/emotion-baselines.js +309 -113
  17. package/dist/src/evidence-review.d.ts +22 -8
  18. package/dist/src/evidence-review.js +4 -4
  19. package/dist/src/extraction-chunk.d.ts +3 -0
  20. package/dist/src/extraction-chunk.js +23 -5
  21. package/dist/src/extraction-model.d.ts +2 -0
  22. package/dist/src/extraction-model.js +73 -48
  23. package/dist/src/extraction-runtime.d.ts +3 -1
  24. package/dist/src/extraction-runtime.js +43 -16
  25. package/dist/src/extraction-source.d.ts +1 -1
  26. package/dist/src/extraction-source.js +19 -11
  27. package/dist/src/extraction-store.d.ts +28 -3
  28. package/dist/src/extraction-store.js +145 -23
  29. package/dist/src/extraction-worker.d.ts +1 -0
  30. package/dist/src/extraction-worker.js +246 -93
  31. package/dist/src/inside-out-runtime.js +41 -29
  32. package/dist/src/inside-out-store.d.ts +2 -2
  33. package/dist/src/inside-out-store.js +110 -69
  34. package/dist/src/inside-out.d.ts +10 -9
  35. package/dist/src/inside-out.js +190 -105
  36. package/dist/src/manager.d.ts +22 -9
  37. package/dist/src/manager.js +275 -169
  38. package/dist/src/memory-search.d.ts +4 -2
  39. package/dist/src/memory-search.js +5 -5
  40. package/dist/src/memory-whisperer.d.ts +1 -1
  41. package/dist/src/memory-whisperer.js +183 -125
  42. package/dist/src/my-turn.d.ts +1 -1
  43. package/dist/src/my-turn.js +87 -68
  44. package/dist/src/people-background.d.ts +4 -0
  45. package/dist/src/people-background.js +29 -6
  46. package/dist/src/people-dossier-review.d.ts +20 -8
  47. package/dist/src/people-dossier-review.js +11 -8
  48. package/dist/src/people-hooks.js +127 -22
  49. package/dist/src/people-learning-cron.d.ts +1 -1
  50. package/dist/src/people-learning-cron.js +106 -57
  51. package/dist/src/people-learning-inventory.d.ts +1 -0
  52. package/dist/src/people-learning-inventory.js +281 -171
  53. package/dist/src/people-learning-prompt.js +1 -1
  54. package/dist/src/people-learning-runtime.d.ts +1 -1
  55. package/dist/src/people-learning-runtime.js +360 -203
  56. package/dist/src/people-learning-store.d.ts +27 -4
  57. package/dist/src/people-learning-store.js +312 -96
  58. package/dist/src/people-primer-tool.js +8 -6
  59. package/dist/src/people-primer.d.ts +3 -1
  60. package/dist/src/people-primer.js +61 -44
  61. package/dist/src/people-store.d.ts +18 -21
  62. package/dist/src/people-store.js +186 -63
  63. package/dist/src/people-tools.js +136 -92
  64. package/dist/src/plugin.js +16 -16
  65. package/dist/src/quality-audit.d.ts +2 -0
  66. package/dist/src/quality-audit.js +8 -7
  67. package/dist/src/response-audit.d.ts +1 -1
  68. package/dist/src/response-audit.js +76 -43
  69. package/dist/src/response-episodes.d.ts +1 -1
  70. package/dist/src/response-episodes.js +12 -17
  71. package/dist/src/response-judge.d.ts +151 -145
  72. package/dist/src/response-judge.js +535 -204
  73. package/dist/src/response-reviews.d.ts +29 -1
  74. package/dist/src/response-reviews.js +110 -13
  75. package/dist/src/response-runtime.js +8 -8
  76. package/dist/src/response-stages.d.ts +50 -53
  77. package/dist/src/response-stages.js +10 -4
  78. package/dist/src/response-store.d.ts +7 -6
  79. package/dist/src/response-store.js +332 -210
  80. package/dist/src/review-tools.d.ts +8 -2
  81. package/dist/src/review-tools.js +18 -18
  82. package/dist/src/runtime.d.ts +7 -4
  83. package/dist/src/runtime.js +624 -98
  84. package/dist/src/safety-whisperer.d.ts +2 -2
  85. package/dist/src/safety-whisperer.js +88 -71
  86. package/dist/src/session-sync.d.ts +3 -1
  87. package/dist/src/session-sync.js +200 -95
  88. package/dist/src/skill-whisperer.d.ts +1 -1
  89. package/dist/src/skill-whisperer.js +52 -30
  90. package/dist/src/training-gate.d.ts +8 -21
  91. package/dist/src/training-gate.js +32 -35
  92. package/dist/src/training-judge.d.ts +9 -16
  93. package/dist/src/training-judge.js +5 -5
  94. package/dist/src/training-queries.d.ts +13 -8
  95. package/dist/src/training-queries.js +370 -228
  96. package/dist/src/training-retrieval.d.ts +14 -24
  97. package/dist/src/training-retrieval.js +182 -136
  98. package/dist/src/training-runtime.d.ts +3 -0
  99. package/dist/src/training-runtime.js +76 -18
  100. package/dist/src/training-store.d.ts +18 -3
  101. package/dist/src/training-store.js +138 -50
  102. package/dist/src/training.js +8 -11
  103. package/dist/src/whisperer-context.d.ts +14 -0
  104. package/dist/src/whisperer-context.js +22 -1
  105. package/docs/configuration.md +76 -63
  106. package/docs/extraction.md +9 -7
  107. package/docs/memory-training.md +7 -6
  108. package/docs/people-learning.md +2 -2
  109. package/docs/peoplesql.md +6 -6
  110. package/docs/response-audit.md +10 -8
  111. package/docs/retrieval.md +40 -37
  112. package/openclaw.plugin.json +40 -26
  113. package/package.json +3 -2
  114. package/skills/memory-curator/SKILL.md +1 -1
  115. package/skills/people-whisperer/SKILL.md +1 -1
  116. package/dist/src/typesafe-client.d.ts +0 -30
  117. package/dist/src/typesafe-client.js +0 -92
  118. package/dist/src/typesafe-review.js +0 -154
  119. package/dist/src/typesafe.js +0 -147
@@ -2,8 +2,13 @@ import type { DatabaseSync } from "node:sqlite";
2
2
  import type { ResponseResult } from "./response-store.js";
3
3
  export declare const RESPONSE_REVIEW_POLICY = "response-review-v2";
4
4
  export type ResponseReviewStatus = "pending" | "resolved" | "dismissed" | "deferred";
5
+ export type ResponseReviewDecisionOptions = {
6
+ expectedInputHash?: string;
7
+ expectedEvidenceHash?: string;
8
+ };
5
9
  /** Operator-only tasks, intentionally not exposed as memory-curation agent tools. */
6
10
  export declare class ResponseReviews {
11
+ #private;
7
12
  private readonly db;
8
13
  constructor(db: DatabaseSync);
9
14
  sync(cohort: string, episodeId: string, inputHash: string, result: ResponseResult, now: number): void;
@@ -14,6 +19,9 @@ export declare class ResponseReviews {
14
19
  episodeId: string;
15
20
  family: string;
16
21
  status: string;
22
+ cohort: string;
23
+ inputHash: string;
24
+ evidenceHash: string;
17
25
  evidenceStatus: string;
18
26
  reviewerKind: import("node:sqlite").SQLOutputValue;
19
27
  resolutionNote: import("node:sqlite").SQLOutputValue;
@@ -21,7 +29,27 @@ export declare class ResponseReviews {
21
29
  updatedAt: import("node:sqlite").SQLOutputValue;
22
30
  evidence: unknown;
23
31
  }[];
24
- decide(cohort: string, id: string, status: ResponseReviewStatus, reviewer: "human" | "agent", note: string, now?: number): void;
32
+ decisions(taskId?: string, cohort?: string): {
33
+ id: number;
34
+ taskId: string;
35
+ status: ResponseReviewStatus;
36
+ reviewerKind: "human" | "agent";
37
+ note: string;
38
+ decidedAt: number;
39
+ cohort: string | null;
40
+ inputHash: string | null;
41
+ evidenceHash: string | null;
42
+ }[];
43
+ decide(cohort: string, id: string, status: ResponseReviewStatus, reviewer: "human" | "agent", note: string, now?: number, options?: ResponseReviewDecisionOptions): {
44
+ taskId: string;
45
+ status: ResponseReviewStatus;
46
+ reviewerKind: "agent" | "human";
47
+ note: string;
48
+ decidedAt: number;
49
+ cohort: string;
50
+ inputHash: string;
51
+ evidenceHash: string;
52
+ };
25
53
  annotate(occurredAt: number, kind: string, note: string): `${string}-${string}-${string}-${string}-${string}`;
26
54
  annotations(since: number, until: number): Record<string, import("node:sqlite").SQLOutputValue>[];
27
55
  }
@@ -3,9 +3,14 @@ import { responseOutcome } from "./response-outcome.js";
3
3
  import { immediateTransaction } from "./memory-database.js";
4
4
  import { jsonHash } from "./json-hash.js";
5
5
  export const RESPONSE_REVIEW_POLICY = "response-review-v2";
6
+ const DECISION_PROVENANCE_COLUMNS = ["cohort", "input_hash", "evidence_hash"];
7
+ function evidenceRevision(cohort, inputHash, detail) {
8
+ return jsonHash([cohort, inputHash, detail]);
9
+ }
6
10
  /** Operator-only tasks, intentionally not exposed as memory-curation agent tools. */
7
11
  export class ResponseReviews {
8
12
  db;
13
+ #provenanceColumnsReady = false;
9
14
  constructor(db) {
10
15
  this.db = db;
11
16
  db.exec(`CREATE TABLE IF NOT EXISTS response_review_tasks (
@@ -24,6 +29,20 @@ export class ResponseReviews {
24
29
  CREATE TABLE IF NOT EXISTS response_annotations (
25
30
  id TEXT PRIMARY KEY, occurred_at INTEGER NOT NULL, kind TEXT NOT NULL, note TEXT NOT NULL);`);
26
31
  }
32
+ #decisionColumns() {
33
+ const rows = this.db.prepare("PRAGMA table_info(response_review_decisions)").all();
34
+ return new Set(rows.map(row => String(row.name)));
35
+ }
36
+ #ensureDecisionProvenanceColumns() {
37
+ if (this.#provenanceColumnsReady)
38
+ return;
39
+ const existing = this.#decisionColumns();
40
+ for (const column of DECISION_PROVENANCE_COLUMNS) {
41
+ if (!existing.has(column)) {
42
+ this.db.exec(`ALTER TABLE response_review_decisions ADD COLUMN ${column} TEXT`);
43
+ }
44
+ }
45
+ }
27
46
  sync(cohort, episodeId, inputHash, result, now) {
28
47
  this.db.prepare(`UPDATE response_review_evidence SET active=-1 WHERE cohort=? AND task_id IN
29
48
  (SELECT id FROM response_review_tasks WHERE episode_id=?)`).run(cohort, episodeId);
@@ -75,25 +94,103 @@ export class ResponseReviews {
75
94
  list(cohort, id) {
76
95
  return this.db.prepare(`SELECT t.*,e.input_hash,e.active,e.detail FROM response_review_tasks t
77
96
  JOIN response_review_evidence e ON e.task_id=t.id WHERE e.cohort=? ${id ? "AND t.id=?" : ""}
78
- ORDER BY t.updated_at DESC,t.id LIMIT 1001`).all(cohort, ...(id ? [id] : [])).map(row => ({
79
- id: String(row.id), episodeId: String(row.episode_id), family: String(row.family), status: String(row.status),
80
- evidenceStatus: row.active === 1 ? "current" : row.active === -1 ? "superseded" : "stale", reviewerKind: row.reviewer_kind,
81
- resolutionNote: row.resolution_note, createdAt: row.created_at, updatedAt: row.updated_at,
82
- evidence: JSON.parse(String(row.detail)),
97
+ ORDER BY t.updated_at DESC,t.id LIMIT 1001`).all(cohort, ...(id ? [id] : [])).map(row => {
98
+ const inputHash = String(row.input_hash);
99
+ const detail = String(row.detail);
100
+ return {
101
+ id: String(row.id), episodeId: String(row.episode_id), family: String(row.family), status: String(row.status),
102
+ cohort, inputHash, evidenceHash: evidenceRevision(cohort, inputHash, detail),
103
+ evidenceStatus: row.active === 1 ? "current" : row.active === -1 ? "superseded" : "stale", reviewerKind: row.reviewer_kind,
104
+ resolutionNote: row.resolution_note, createdAt: row.created_at, updatedAt: row.updated_at,
105
+ evidence: JSON.parse(detail),
106
+ };
107
+ });
108
+ }
109
+ decisions(taskId, cohort) {
110
+ const columns = this.#decisionColumns();
111
+ const hasCohort = columns.has("cohort");
112
+ const hasInputHash = columns.has("input_hash");
113
+ const hasEvidenceHash = columns.has("evidence_hash");
114
+ if (cohort !== undefined && !hasCohort)
115
+ return [];
116
+ const clauses = [];
117
+ const params = [];
118
+ if (taskId !== undefined) {
119
+ clauses.push("task_id=?");
120
+ params.push(taskId);
121
+ }
122
+ if (cohort !== undefined) {
123
+ clauses.push("cohort=?");
124
+ params.push(cohort);
125
+ }
126
+ const where = clauses.length ? `WHERE ${clauses.join(" AND ")}` : "";
127
+ const select = [
128
+ "id", "task_id", "status", "reviewer_kind", "note", "decided_at",
129
+ hasCohort ? "cohort" : "NULL AS cohort",
130
+ hasInputHash ? "input_hash" : "NULL AS input_hash",
131
+ hasEvidenceHash ? "evidence_hash" : "NULL AS evidence_hash",
132
+ ].join(",");
133
+ return this.db.prepare(`SELECT ${select} FROM response_review_decisions ${where} ORDER BY decided_at,id`)
134
+ .all(...params)
135
+ .map(row => ({
136
+ id: Number(row.id),
137
+ taskId: String(row.task_id),
138
+ status: String(row.status),
139
+ reviewerKind: String(row.reviewer_kind),
140
+ note: String(row.note),
141
+ decidedAt: Number(row.decided_at),
142
+ cohort: row.cohort === null ? null : String(row.cohort),
143
+ inputHash: row.input_hash === null ? null : String(row.input_hash),
144
+ evidenceHash: row.evidence_hash === null ? null : String(row.evidence_hash),
83
145
  }));
84
146
  }
85
- decide(cohort, id, status, reviewer, note, now = Date.now()) {
147
+ decide(cohort, id, status, reviewer, note, now = Date.now(), options) {
148
+ const trimmedNote = note.trim();
86
149
  if (!["pending", "resolved", "dismissed", "deferred"].includes(status) || !["human", "agent"].includes(reviewer) ||
87
- !note.trim() || note.length > 4000)
150
+ !trimmedNote || note.length > 4000)
88
151
  throw new Error("Invalid response review decision");
89
- if (!this.list(cohort, id).length)
90
- throw new Error("Unknown response review task in current cohort");
91
- immediateTransaction(this.db, () => {
152
+ if (options?.expectedInputHash !== undefined && !options.expectedInputHash.trim()) {
153
+ throw new Error("Invalid expected response review input hash");
154
+ }
155
+ if (options?.expectedEvidenceHash !== undefined && !options.expectedEvidenceHash.trim()) {
156
+ throw new Error("Invalid expected response review evidence hash");
157
+ }
158
+ const recorded = immediateTransaction(this.db, () => {
159
+ const row = this.db.prepare(`SELECT t.episode_id,e.input_hash,e.active,e.detail
160
+ FROM response_review_tasks t
161
+ JOIN response_review_evidence e ON e.task_id=t.id
162
+ WHERE e.cohort=? AND t.id=?`).get(cohort, id);
163
+ if (!row)
164
+ throw new Error("Unknown response review task in current cohort");
165
+ const active = Number(row.active);
166
+ if (active !== 1) {
167
+ const state = active === -1 ? "superseded" : "stale";
168
+ throw new Error(`Cannot decide response review task with ${state} evidence`);
169
+ }
170
+ const inputHash = String(row.input_hash);
171
+ const currentResult = this.db.prepare(`SELECT 1 FROM response_results
172
+ WHERE cohort=? AND id=? AND input_hash=? AND active=1 AND status='ok'`)
173
+ .get(cohort, String(row.episode_id), inputHash);
174
+ if (!currentResult) {
175
+ throw new Error("Cannot decide response review task with stale evidence");
176
+ }
177
+ const evidenceHash = evidenceRevision(cohort, inputHash, String(row.detail));
178
+ if (options?.expectedInputHash !== undefined && options.expectedInputHash !== inputHash) {
179
+ throw new Error("Response review evidence input hash mismatch");
180
+ }
181
+ if (options?.expectedEvidenceHash !== undefined && options.expectedEvidenceHash !== evidenceHash) {
182
+ throw new Error("Response review evidence revision mismatch");
183
+ }
184
+ this.#ensureDecisionProvenanceColumns();
92
185
  this.db.prepare("UPDATE response_review_tasks SET status=?,reviewer_kind=?,resolution_note=?,updated_at=? WHERE id=?")
93
- .run(status, reviewer, note.trim(), now, id);
94
- this.db.prepare("INSERT INTO response_review_decisions(task_id,status,reviewer_kind,note,decided_at) VALUES(?,?,?,?,?)")
95
- .run(id, status, reviewer, note.trim(), now);
186
+ .run(status, reviewer, trimmedNote, now, id);
187
+ this.db.prepare(`INSERT INTO response_review_decisions(task_id,status,reviewer_kind,note,decided_at,cohort,input_hash,evidence_hash)
188
+ VALUES(?,?,?,?,?,?,?,?)`)
189
+ .run(id, status, reviewer, trimmedNote, now, cohort, inputHash, evidenceHash);
190
+ return { taskId: id, status, reviewerKind: reviewer, note: trimmedNote, decidedAt: now, cohort, inputHash, evidenceHash };
96
191
  });
192
+ this.#provenanceColumnsReady = true;
193
+ return recorded;
97
194
  }
98
195
  annotate(occurredAt, kind, note) {
99
196
  if (!Number.isFinite(occurredAt) || !["model", "prompt", "deployment", "other"].includes(kind) || !note.trim() || note.length > 4000)
@@ -22,6 +22,7 @@ export function registerResponseAudit(api, config) {
22
22
  .filter(c => config.responseAudit.memoryCorpora.includes(c.name))) };
23
23
  };
24
24
  api.registerCli(({ program, config: cfg }) => {
25
+ const cohort = () => responseCohort(config.responseAudit, config.decisionModel.model, config.decisionModel.endpoint);
25
26
  const root = program.command("memory-responses").description("Operator-only response quality audits and evidence-linked trend reports");
26
27
  root.command("audit").option("--agent <id>", "Agent id", "main").option("--dry-run", "Preview bounded coverage without inference or audit writes")
27
28
  .action(async (opts) => {
@@ -36,6 +37,8 @@ export function registerResponseAudit(api, config) {
36
37
  .option("--account <scope>", "Provider account scope; requires --sender").option("--person <id>", "Linked people-store person ID")
37
38
  .option("--task-type <type>", "Task classification").option("--model <id>", "Agent model")
38
39
  .action((opts) => {
40
+ if (opts.bucket !== "day" && opts.bucket !== "week")
41
+ throw new Error("Bucket must be day or week");
39
42
  if (!config.responseAudit.enabled) {
40
43
  console.log(JSON.stringify({ status: "disabled" }));
41
44
  return;
@@ -46,12 +49,8 @@ export function registerResponseAudit(api, config) {
46
49
  return;
47
50
  }
48
51
  const store = new ResponseAuditStore(storePath);
49
- if (opts.bucket !== "day" && opts.bucket !== "week") {
50
- store.close();
51
- throw new Error("Bucket must be day or week");
52
- }
53
52
  try {
54
- console.log(JSON.stringify(store.report(responseCohort(config.responseAudit), dateOption(opts.since, Date.now() - config.responseAudit.lookbackDays * 86400_000), opts.episode, { until: dateOption(opts.until, Number.MAX_SAFE_INTEGER), bucket: opts.bucket, senderId: opts.sender,
53
+ console.log(JSON.stringify(store.report(cohort(), dateOption(opts.since, Date.now() - config.responseAudit.lookbackDays * 86400_000), opts.episode, { until: dateOption(opts.until, Number.MAX_SAFE_INTEGER), bucket: opts.bucket, senderId: opts.sender,
55
54
  accountScope: opts.account, personId: opts.person, taskType: opts.taskType, agentModel: opts.model }), null, 2));
56
55
  }
57
56
  finally {
@@ -66,7 +65,7 @@ export function registerResponseAudit(api, config) {
66
65
  throw new Error("Response audit has not run");
67
66
  const store = new ResponseAuditStore(storePath);
68
67
  try {
69
- console.log(JSON.stringify(fn(store, responseCohort(config.responseAudit)), null, 2));
68
+ console.log(JSON.stringify(fn(store, cohort()), null, 2));
70
69
  }
71
70
  finally {
72
71
  store.close();
@@ -81,9 +80,10 @@ export function registerResponseAudit(api, config) {
81
80
  root.command("review").requiredOption("--id <id>", "Task ID").requiredOption("--status <status>", "pending, resolved, dismissed or deferred")
82
81
  .requiredOption("--reviewer <kind>", "human or agent: provenance, not an authorization grant")
83
82
  .requiredOption("--note <text>", "Evidence-based decision; no automatic whisperer write")
83
+ .requiredOption("--evidence-hash <hash>", "Evidence hash returned by memory-responses tasks")
84
84
  .option("--agent <id>", "Agent id", "main")
85
85
  .action((opts) => withStore(opts.agent, (store, cohort) => {
86
- store.reviews.decide(cohort, opts.id, opts.status, opts.reviewer, opts.note);
86
+ store.reviews.decide(cohort, opts.id, opts.status, opts.reviewer, opts.note, undefined, { expectedEvidenceHash: opts.evidenceHash });
87
87
  return store.reviews.list(cohort, opts.id);
88
88
  }));
89
89
  root.command("annotate").option("--agent <id>", "Agent id", "main").requiredOption("--date <date>", "UTC date YYYY-MM-DD")
@@ -93,7 +93,7 @@ export function registerResponseAudit(api, config) {
93
93
  .option("--agent <id>", "Agent id", "main")
94
94
  .action((opts) => withStore(opts.agent, (store, cohort) => store.retryFailed(cohort)));
95
95
  }, { descriptors: [{ name: "memory-responses", description: "Audit human-agent exchanges and report quality signals", hasSubcommands: true }] });
96
- if (api.registrationMode === "cli-metadata" || !config.responseAudit.enabled || !config.typesafe.enabled || !config.responseAudit.intervalMinutes)
96
+ if (api.registrationMode === "cli-metadata" || !config.responseAudit.enabled || !config.decisionModel.enabled || !config.responseAudit.intervalMinutes)
97
97
  return;
98
98
  let timer, running, lifetime = new AbortController();
99
99
  const tick = () => {
@@ -1,79 +1,76 @@
1
1
  import type { ResponseEpisode } from "./response-episodes.js";
2
+ import { type ResponseJudgeParams } from "./response-judge.js";
2
3
  import type { ResponseAuditStore } from "./response-store.js";
3
- export declare function assessResponseStages(store: ResponseAuditStore, cohort: string, e: ResponseEpisode, params: {
4
- apiKey: string;
5
- timeoutMs: number;
6
- signal: AbortSignal;
7
- }, sentimentEnabled: boolean, usage: {
4
+ export declare function assessResponseStages(store: ResponseAuditStore, cohort: string, e: ResponseEpisode, params: ResponseJudgeParams, sentimentEnabled: boolean, usage: {
8
5
  stageAttempts: number;
9
6
  stageCacheHits: number;
10
7
  }): Promise<{
11
8
  retrospective: {
12
9
  status: ResponseEpisode["followup"]["status"];
13
- judgment: import("typebox").Static<import("typebox").TObject<{
14
- answers: import("typebox").TObject<{
15
- correction: import("typebox").TObject<{
16
- type: import("typebox").TLiteral<"noul">;
17
- noul: import("typebox").TNumber;
18
- }>;
19
- deliveryAdmission: import("typebox").TObject<{
20
- type: import("typebox").TLiteral<"noul">;
21
- noul: import("typebox").TNumber;
22
- }>;
23
- regression: import("typebox").TObject<{
24
- type: import("typebox").TLiteral<"noul">;
25
- noul: import("typebox").TNumber;
26
- }>;
27
- scopeClarification: import("typebox").TObject<{
28
- type: import("typebox").TLiteral<"noul">;
29
- noul: import("typebox").TNumber;
30
- }>;
31
- outcome: import("typebox").TObject<{
32
- type: import("typebox").TLiteral<"choice">;
33
- choice: import("typebox").TEnum<("unknown" | "reported_shortfall" | "acknowledged_success")[]>;
34
- confidence: import("typebox").TNumber;
35
- probabilities: import("typebox").TObject<{
36
- [k: string]: import("typebox").TNumber;
37
- }>;
38
- }>;
39
- reason: import("typebox").TObject<{
40
- type: import("typebox").TLiteral<"choice">;
41
- choice: import("typebox").TEnum<("none_or_unclear" | "missing_requested_work" | "unnecessary_deferral" | "regression" | "incorrect_claim" | "wrong_scope" | "failed_delivery")[]>;
42
- confidence: import("typebox").TNumber;
43
- probabilities: import("typebox").TObject<{
44
- [k: string]: import("typebox").TNumber;
45
- }>;
46
- }>;
47
- }>;
48
- }>>["answers"] | null;
10
+ judgment: {
11
+ reason: {
12
+ type: "choice";
13
+ choice: "none_or_unclear" | "missing_requested_work" | "unnecessary_deferral" | "regression" | "incorrect_claim" | "wrong_scope" | "failed_delivery";
14
+ probabilities: {
15
+ [x: string]: number;
16
+ [x: number]: number;
17
+ };
18
+ confidence: number;
19
+ };
20
+ outcome: {
21
+ type: "choice";
22
+ choice: "unknown" | "reported_shortfall" | "acknowledged_success";
23
+ probabilities: {
24
+ [x: string]: number;
25
+ [x: number]: number;
26
+ };
27
+ confidence: number;
28
+ };
29
+ correction: {
30
+ type: "noul";
31
+ noul: number;
32
+ };
33
+ deliveryAdmission: {
34
+ type: "noul";
35
+ noul: number;
36
+ };
37
+ regression: {
38
+ type: "noul";
39
+ noul: number;
40
+ };
41
+ scopeClarification: {
42
+ type: "noul";
43
+ noul: number;
44
+ };
45
+ } | null;
49
46
  };
50
47
  quality: {
51
48
  taskType: {
52
49
  type: "choice";
53
- confidence: number;
54
- choice: "action" | "question" | "other" | "artifact" | "discussion";
50
+ choice: "question" | "action" | "other" | "artifact" | "discussion";
55
51
  probabilities: {
56
52
  [x: string]: number;
57
53
  [x: number]: number;
58
54
  };
55
+ confidence: number;
59
56
  };
60
57
  assessability: {
61
58
  type: "choice";
62
- confidence: number;
63
59
  choice: "assessable" | "not_assessable";
64
60
  probabilities: {
65
61
  [x: string]: number;
66
62
  [x: number]: number;
67
63
  };
64
+ confidence: number;
68
65
  };
69
66
  fitAssessability: {
70
67
  type: "choice";
71
- confidence: number;
72
68
  choice: "assessable" | "not_assessable";
73
69
  probabilities: {
74
70
  [x: string]: number;
75
71
  [x: number]: number;
76
72
  };
73
+ confidence: number;
77
74
  };
78
75
  underdelivery: {
79
76
  type: "noul";
@@ -81,63 +78,63 @@ export declare function assessResponseStages(store: ResponseAuditStore, cohort:
81
78
  };
82
79
  failureReason: {
83
80
  type: "choice";
84
- confidence: number;
85
81
  choice: "none_or_unclear" | "missing_requested_work" | "wrong_deliverable" | "missed_constraint" | "insufficient_answer_depth" | "unnecessary_deferral";
86
82
  probabilities: {
87
83
  [x: string]: number;
88
84
  [x: number]: number;
89
85
  };
86
+ confidence: number;
90
87
  };
91
88
  fulfillment: {
92
89
  type: "score";
93
- confidence: number;
94
90
  probabilities: {
95
91
  "0": number;
96
92
  "1": number;
97
93
  "2": number;
98
94
  "3": number;
99
95
  };
96
+ confidence: number;
100
97
  score: number;
101
98
  };
102
99
  deliverableFit: {
103
100
  type: "score";
104
- confidence: number;
105
101
  probabilities: {
106
102
  "0": number;
107
103
  "1": number;
108
104
  "2": number;
109
105
  "3": number;
110
106
  };
107
+ confidence: number;
111
108
  score: number;
112
109
  };
113
110
  consistency: {
114
111
  type: "choice";
115
- confidence: number;
116
112
  choice: "contradicted" | "not_assessable" | "consistent";
117
113
  probabilities: {
118
114
  [x: string]: number;
119
115
  [x: number]: number;
120
116
  };
117
+ confidence: number;
121
118
  };
122
119
  };
123
120
  feedback: {
124
121
  target: {
125
122
  type: "choice";
126
- confidence: number;
127
123
  choice: "delivery" | "mixed" | "unclear" | "current_answer" | "earlier_behavior" | "proactive_action" | "external" | "new_work";
128
124
  probabilities: {
129
125
  [x: string]: number;
130
126
  [x: number]: number;
131
127
  };
128
+ confidence: number;
132
129
  };
133
130
  feedbackType: {
134
131
  type: "choice";
135
- confidence: number;
136
132
  choice: "mixed" | "unrelated" | "unclear" | "acceptance" | "correction" | "continuation";
137
133
  probabilities: {
138
134
  [x: string]: number;
139
135
  [x: number]: number;
140
136
  };
137
+ confidence: number;
141
138
  };
142
139
  avoidableRework: {
143
140
  type: "noul";
@@ -154,12 +151,12 @@ export declare function assessResponseStages(store: ResponseAuditStore, cohort:
154
151
  } & Partial<{
155
152
  sentiment: {
156
153
  type: "choice";
157
- confidence: number;
158
154
  choice: "satisfied" | "dissatisfied" | "mixed" | "neutral" | "unrelated" | "unclear";
159
155
  probabilities: {
160
156
  [x: string]: number;
161
157
  [x: number]: number;
162
158
  };
159
+ confidence: number;
163
160
  };
164
161
  annoyance: {
165
162
  type: "noul";
@@ -171,13 +168,13 @@ export declare function assessResponseStages(store: ResponseAuditStore, cohort:
171
168
  };
172
169
  dissatisfactionIntensity: {
173
170
  type: "score";
174
- confidence: number;
175
171
  probabilities: {
176
172
  "0": number;
177
173
  "1": number;
178
174
  "2": number;
179
175
  "3": number;
180
176
  };
177
+ confidence: number;
181
178
  score: number;
182
179
  };
183
180
  }>;
@@ -1,13 +1,19 @@
1
1
  import { RESPONSE_EXTRACTOR_VERSION } from "./response-episodes.js";
2
- import { judgeResponse, judgeResponseFollowup, RESPONSE_STAGE_VERSIONS } from "./response-judge.js";
3
- import { TYPESAFE_MODEL } from "./typesafe-client.js";
2
+ import { judgeResponse, judgeResponseFollowup, RESPONSE_STAGE_VERSIONS, } from "./response-judge.js";
3
+ import { decisionModelScope, DEFAULT_DECISION_MODEL } from "./decision-client.js";
4
4
  import { jsonHash } from "./json-hash.js";
5
5
  export async function assessResponseStages(store, cohort, e, params, sentimentEnabled, usage) {
6
+ const scope = decisionModelScope(params.model ?? DEFAULT_DECISION_MODEL, params.endpoint);
6
7
  const original = { before: e.before, request: e.request, answer: e.answer, contextLimited: e.contextLimited };
7
8
  const feedback = { ...original, feedback: e.feedback };
8
- const evidence = { quality: original, feedback, sentiment: feedback, retrospective: { ...feedback, followup: e.followup } };
9
+ const evidence = {
10
+ quality: original,
11
+ feedback,
12
+ sentiment: feedback,
13
+ retrospective: { ...feedback, followup: e.followup },
14
+ };
9
15
  const keys = Object.fromEntries(Object.keys(evidence).map(stage => [stage,
10
- jsonHash([RESPONSE_EXTRACTOR_VERSION, TYPESAFE_MODEL, RESPONSE_STAGE_VERSIONS[stage],
16
+ jsonHash([RESPONSE_EXTRACTOR_VERSION, scope, RESPONSE_STAGE_VERSIONS[stage],
11
17
  e.id, e.session, e.senderId, e.thread, evidence[stage]]),
12
18
  ]));
13
19
  const cache = {
@@ -1,5 +1,5 @@
1
1
  import type { ResponseEpisode } from "./response-episodes.js";
2
- import type { ResponseJudgment, ResponseStages, judgeMemoryOpportunity, judgeResponseFollowup } from "./response-judge.js";
2
+ import { type ResponseJudgment, type ResponseStageContracts, type ResponseStages, type judgeMemoryOpportunity, type judgeResponseFollowup } from "./response-judge.js";
3
3
  import { responseOutcome } from "./response-outcome.js";
4
4
  import type { ResponseHuman } from "./response-identity.js";
5
5
  import { ResponseReviews } from "./response-reviews.js";
@@ -43,6 +43,7 @@ export declare class ResponseAuditStore {
43
43
  activeSessions(cohort: string, since: number): string[];
44
44
  observe(cohort: string, sessionId: string, episodes: readonly ResponseEpisode[]): void;
45
45
  needsJudgment(cohort: string, e: ResponseEpisode, now: number): boolean;
46
+ memoryRetryResult(cohort: string, e: ResponseEpisode): ResponseResult | undefined;
46
47
  attempted(cohort: string, e: ResponseEpisode, now: number): void;
47
48
  stale(cohort: string, e: ResponseEpisode): void;
48
49
  save(cohort: string, e: ResponseEpisode, result: ResponseResult, now: number): void;
@@ -61,12 +62,12 @@ export declare class ResponseAuditStore {
61
62
  pendingWork(cohort: string, since: number, now: number): number;
62
63
  /** Retry eligibility is not completion: include backoff and exhausted work. */
63
64
  unresolvedWork(cohort: string, since: number, until: number): number;
64
- stage<K extends keyof ResponseStages>(cohort: string, e: ResponseEpisode, stage: K, key: string): ResponseStages[K] | undefined;
65
+ stage<K extends keyof ResponseStages>(cohort: string, e: ResponseEpisode, stage: K, key: string, contract?: ResponseStageContracts[K]): ResponseStages[K] | undefined;
65
66
  stageBegin(keys: string[], now: number): void;
66
67
  stageSave<K extends keyof ResponseStages>(key: string, result: ResponseStages[K], now: number): void;
67
68
  retryFailed(cohort: string): {
68
- stages: number | bigint;
69
- episodes: number | bigint;
69
+ stages: number;
70
+ episodes: number;
70
71
  };
71
72
  scan(cohort: string, coverage: object, now: number): void;
72
73
  report(cohort: string, since: number, id?: string, options?: ResponseReportOptions): {
@@ -166,8 +167,8 @@ export declare class ResponseAuditStore {
166
167
  beforeCoverage: number;
167
168
  afterCoverage: number;
168
169
  coverageChanged: boolean;
169
- denominator: string;
170
- scale: string;
170
+ denominator: "confident_assessable_exchanges" | "all_evaluated_exchanges" | "sentiment_assessed_exchanges" | "emotion_assessed_exchanges" | "confident_intensity_exchanges";
171
+ scale: "0_to_3_visible_quality" | "0_to_1_observed_rate" | "0_to_3_expressed_dissatisfaction";
171
172
  delta: number | null;
172
173
  }[];
173
174
  examples: {