@unblocklabs/unblock-memory 0.12.3 → 0.14.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 (138) hide show
  1. package/README.md +19 -18
  2. package/defaults.json +162 -0
  3. package/dist/src/analysis.js +1 -1
  4. package/dist/src/cluster-review.d.ts +2 -0
  5. package/dist/src/cluster-review.js +9 -8
  6. package/dist/src/config.d.ts +9 -6
  7. package/dist/src/config.js +59 -45
  8. package/dist/src/curation.d.ts +1 -1
  9. package/dist/src/decision-client.d.ts +45 -0
  10. package/dist/src/decision-client.js +87 -0
  11. package/dist/src/{typesafe.d.ts → decision-ranking.d.ts} +15 -18
  12. package/dist/src/decision-ranking.js +155 -0
  13. package/dist/src/{typesafe-review.d.ts → decision-review.d.ts} +13 -9
  14. package/dist/src/decision-review.js +193 -0
  15. package/dist/src/defaults.d.ts +8 -0
  16. package/dist/src/defaults.js +128 -0
  17. package/dist/src/diagnostics.d.ts +5 -5
  18. package/dist/src/emotion-baselines.d.ts +28 -3
  19. package/dist/src/emotion-baselines.js +312 -115
  20. package/dist/src/evidence-review.d.ts +22 -8
  21. package/dist/src/evidence-review.js +11 -8
  22. package/dist/src/extraction-chunk.d.ts +3 -0
  23. package/dist/src/extraction-chunk.js +25 -6
  24. package/dist/src/extraction-config.js +4 -2
  25. package/dist/src/extraction-model.d.ts +25 -17
  26. package/dist/src/extraction-model.js +232 -104
  27. package/dist/src/extraction-runtime.d.ts +3 -1
  28. package/dist/src/extraction-runtime.js +48 -20
  29. package/dist/src/extraction-source.d.ts +1 -1
  30. package/dist/src/extraction-source.js +21 -12
  31. package/dist/src/extraction-store.d.ts +29 -3
  32. package/dist/src/extraction-store.js +149 -25
  33. package/dist/src/extraction-worker.d.ts +3 -3
  34. package/dist/src/extraction-worker.js +250 -95
  35. package/dist/src/inside-out-runtime.js +43 -30
  36. package/dist/src/inside-out-sources.js +2 -1
  37. package/dist/src/inside-out-store.d.ts +2 -2
  38. package/dist/src/inside-out-store.js +111 -69
  39. package/dist/src/inside-out.d.ts +10 -9
  40. package/dist/src/inside-out.js +194 -106
  41. package/dist/src/manager.d.ts +22 -9
  42. package/dist/src/manager.js +279 -172
  43. package/dist/src/memory-database.js +3 -2
  44. package/dist/src/memory-passage.d.ts +2 -2
  45. package/dist/src/memory-passage.js +3 -2
  46. package/dist/src/memory-search.d.ts +4 -2
  47. package/dist/src/memory-search.js +5 -5
  48. package/dist/src/memory-whisperer.d.ts +1 -1
  49. package/dist/src/memory-whisperer.js +195 -129
  50. package/dist/src/my-turn.d.ts +1 -1
  51. package/dist/src/my-turn.js +90 -70
  52. package/dist/src/people-background.d.ts +5 -1
  53. package/dist/src/people-background.js +31 -7
  54. package/dist/src/people-dossier-review.d.ts +20 -8
  55. package/dist/src/people-dossier-review.js +15 -11
  56. package/dist/src/people-hooks.js +127 -22
  57. package/dist/src/people-learning-cron.d.ts +1 -1
  58. package/dist/src/people-learning-cron.js +107 -57
  59. package/dist/src/people-learning-inventory.d.ts +1 -0
  60. package/dist/src/people-learning-inventory.js +283 -172
  61. package/dist/src/people-learning-prompt.js +1 -1
  62. package/dist/src/people-learning-runtime.d.ts +1 -1
  63. package/dist/src/people-learning-runtime.js +360 -203
  64. package/dist/src/people-learning-store.d.ts +27 -4
  65. package/dist/src/people-learning-store.js +312 -96
  66. package/dist/src/people-primer-tool.js +13 -10
  67. package/dist/src/people-primer.d.ts +3 -1
  68. package/dist/src/people-primer.js +66 -48
  69. package/dist/src/people-store.d.ts +18 -21
  70. package/dist/src/people-store.js +188 -64
  71. package/dist/src/people-tools.js +138 -93
  72. package/dist/src/plugin.js +19 -18
  73. package/dist/src/quality-audit.d.ts +2 -0
  74. package/dist/src/quality-audit.js +11 -9
  75. package/dist/src/quality-triage.js +4 -3
  76. package/dist/src/query-generator.js +5 -2
  77. package/dist/src/response-audit.d.ts +1 -1
  78. package/dist/src/response-audit.js +78 -44
  79. package/dist/src/response-config.js +3 -1
  80. package/dist/src/response-episodes.d.ts +1 -1
  81. package/dist/src/response-episodes.js +15 -19
  82. package/dist/src/response-identity.js +2 -1
  83. package/dist/src/response-judge.d.ts +151 -145
  84. package/dist/src/response-judge.js +535 -204
  85. package/dist/src/response-memory.js +2 -1
  86. package/dist/src/response-outcome.js +9 -8
  87. package/dist/src/response-reviews.d.ts +29 -1
  88. package/dist/src/response-reviews.js +113 -15
  89. package/dist/src/response-runtime.js +10 -9
  90. package/dist/src/response-stages.d.ts +50 -53
  91. package/dist/src/response-stages.js +10 -4
  92. package/dist/src/response-store.d.ts +7 -6
  93. package/dist/src/response-store.js +335 -212
  94. package/dist/src/review-tools.d.ts +8 -2
  95. package/dist/src/review-tools.js +22 -21
  96. package/dist/src/runtime.d.ts +7 -4
  97. package/dist/src/runtime.js +625 -98
  98. package/dist/src/safety-config.js +3 -2
  99. package/dist/src/safety-whisperer.d.ts +2 -2
  100. package/dist/src/safety-whisperer.js +90 -73
  101. package/dist/src/session-sync.d.ts +3 -1
  102. package/dist/src/session-sync.js +202 -96
  103. package/dist/src/skill-whisperer.d.ts +2 -2
  104. package/dist/src/skill-whisperer.js +55 -32
  105. package/dist/src/slack-directory.js +3 -2
  106. package/dist/src/training-gate.d.ts +9 -22
  107. package/dist/src/training-gate.js +34 -36
  108. package/dist/src/training-input.js +4 -3
  109. package/dist/src/training-judge.d.ts +9 -16
  110. package/dist/src/training-judge.js +6 -5
  111. package/dist/src/training-models.d.ts +1 -1
  112. package/dist/src/training-models.js +9 -7
  113. package/dist/src/training-queries.d.ts +14 -9
  114. package/dist/src/training-queries.js +374 -231
  115. package/dist/src/training-retrieval.d.ts +17 -27
  116. package/dist/src/training-retrieval.js +186 -139
  117. package/dist/src/training-runtime.d.ts +3 -0
  118. package/dist/src/training-runtime.js +76 -18
  119. package/dist/src/training-store.d.ts +18 -3
  120. package/dist/src/training-store.js +141 -52
  121. package/dist/src/training.js +9 -11
  122. package/dist/src/whisperer-context.d.ts +13 -0
  123. package/dist/src/whisperer-context.js +22 -1
  124. package/docs/configuration.md +83 -64
  125. package/docs/extraction.md +26 -35
  126. package/docs/memory-training.md +7 -6
  127. package/docs/people-learning.md +2 -2
  128. package/docs/peoplesql.md +6 -6
  129. package/docs/response-audit.md +10 -8
  130. package/docs/retrieval.md +43 -47
  131. package/openclaw.plugin.json +76 -75
  132. package/package.json +5 -2
  133. package/skills/memory-curator/SKILL.md +1 -1
  134. package/skills/people-whisperer/SKILL.md +1 -1
  135. package/dist/src/typesafe-client.d.ts +0 -30
  136. package/dist/src/typesafe-client.js +0 -92
  137. package/dist/src/typesafe-review.js +0 -154
  138. package/dist/src/typesafe.js +0 -147
package/README.md CHANGED
@@ -10,8 +10,9 @@ keyword or vector similarity.
10
10
 
11
11
  **Requirements:** Node.js 22+ and OpenClaw 2026.8.1-beta.3 or later.
12
12
  Use the Node version required by your OpenClaw release.
13
- A [TypeSafe](https://docs.typesafe.ai) API key enables usefulness ranking; without
14
- it, explicit search returns labeled local search leads.
13
+ A decision-model API key enables usefulness ranking. The default endpoint is
14
+ `https://codex.unblocklabs.ai/v1/decisions` (Codex LB → OpenRouter `liquid/d1.2-ultra`).
15
+ Without a key, search returns labeled local leads.
15
16
 
16
17
  1. Install once per OpenClaw host, not once per agent:
17
18
 
@@ -19,11 +20,11 @@ it, explicit search returns labeled local search leads.
19
20
  openclaw plugins install npm:@unblocklabs/unblock-memory
20
21
  ```
21
22
 
22
- 2. For usefulness ranking, save your TypeSafe key in a private file (`chmod 600`), for example
23
- `~/.openclaw/secrets/unblock-memory-typesafe.env`:
23
+ 2. For usefulness ranking, save your `codex-lb` key in a private file (`chmod 600`), for example
24
+ `~/.openclaw/secrets/unblock-memory-decisions.env`:
24
25
 
25
26
  ```dotenv
26
- TYPESAFE_API_KEY="your-key"
27
+ CODEX_LB_API_KEY="your-key"
27
28
  ```
28
29
 
29
30
  3. Merge this into `~/.openclaw/openclaw.json`, keeping your other settings.
@@ -37,7 +38,7 @@ it, explicit search returns labeled local search leads.
37
38
  "unblock-memory": {
38
39
  "enabled": true,
39
40
  "config": {
40
- "typesafe": { "apiKeyFile": "/home/you/.openclaw/secrets/unblock-memory-typesafe.env" }
41
+ "decisionModel": { "apiKeyFile": "/home/you/.openclaw/secrets/unblock-memory-decisions.env" }
41
42
  }
42
43
  }
43
44
  }
@@ -52,7 +53,7 @@ it, explicit search returns labeled local search leads.
52
53
  ```
53
54
 
54
55
  `"credential": "available"` means the key was found. It does not check that
55
- TypeSafe accepts the key; a test search does.
56
+ the endpoint accepts the key; a test search does.
56
57
 
57
58
  By default each agent indexes `MEMORY.md`, `USER.md` and `memory/**/*.md` in its
58
59
  workspace. The index is built on first use and refreshes in the background when
@@ -65,7 +66,7 @@ To install from source instead:
65
66
  ## How it works
66
67
 
67
68
  The agent writes two queries: keywords for BM25 search and a plain-language
68
- question for vector search. Each returns up to ten candidate passages. TypeSafe
69
+ question for vector search. Each returns up to ten candidate passages. The decision model
69
70
  scores how useful each complete passage is for the question, and the best ones
70
71
  come back with their source location.
71
72
 
@@ -90,16 +91,16 @@ come back with their source location.
90
91
 
91
92
  The agent then calls `memory_get` with that `path` to read the surrounding
92
93
  context, attribution and dates. Search defaults to 5 results with a usefulness
93
- score of at least 0.7 when TypeSafe is available. If ranking is unavailable,
94
+ score of at least 0.7 when judging is available. If ranking is unavailable,
94
95
  search returns unjudged local leads with a warning; the usefulness threshold
95
- is not applied. Automatic Memory Whisperer hints still require TypeSafe.
96
+ is not applied. Automatic Memory Whisperer hints still require a decision model.
96
97
  See [search and read](docs/retrieval.md#search-and-read) for every parameter.
97
98
 
98
99
  **What leaves your machine:** indexing, embeddings, storage and `memory_get` run
99
100
  locally. `memory_search` sends the search question and candidate passages, with
100
- their paths and dates, to TypeSafe for scoring when available. Optional TypeSafe
101
+ their paths and dates, to the configured decision endpoint for scoring. Optional decision-model
101
102
  features send only what their own settings approve; see
102
- [TypeSafe data scope](docs/configuration.md#typesafe-data-scope).
103
+ [decision model data scope](docs/configuration.md#decision-model-data-scope).
103
104
 
104
105
  **On by default:** search and read over the `memory` corpus, and a
105
106
  [compaction memory flush](docs/configuration.md#compaction-memory-writes): before
@@ -114,10 +115,10 @@ Everything below is off until you configure it.
114
115
  | Feature | What it does |
115
116
  | --- | --- |
116
117
  | [Session indexing](docs/retrieval.md#sessions) | Makes past conversations searchable. Group and channel chats by default; DMs only if you add them. |
117
- | [Skill Whisperer](docs/retrieval.md#skill-whisperer) | Suggests one relevant skill for a user message. Never runs it. Turns on when you add a `skills` corpus; works without TypeSafe. |
118
- | [Memory Whisperer](docs/retrieval.md#memory-whisperer) | Adds up to three relevant past excerpts before the agent replies. Needs TypeSafe; optionally uses a self-hosted query-generation API with local fallback. |
119
- | [Safety Whisperer](docs/configuration.md#safety-whisperer) | Reminds the agent not to share sensitive topics, such as one person's salary, with requestors you haven't approved. A prompt-level guardrail, not access control; fails open if TypeSafe is unavailable. |
120
- | [My Turn](docs/configuration.md#my-turn) | Asks Jev whether a group/channel conversation needs this agent's response. Advises `NO_REPLY` only when silence is clearly favored; the agent keeps the final say. Opt-in; failures leave the turn unchanged. |
118
+ | [Skill Whisperer](docs/retrieval.md#skill-whisperer) | Suggests one relevant skill for a user message. Never runs it. Turns on when you add a `skills` corpus; works without a remote decision model. |
119
+ | [Memory Whisperer](docs/retrieval.md#memory-whisperer) | Adds up to three relevant past excerpts before the agent replies. Needs a configured decision endpoint (`decisionModel`); optionally uses a self-hosted query-generation API with local fallback. |
120
+ | [Safety Whisperer](docs/configuration.md#safety-whisperer) | Reminds the agent not to share sensitive topics, such as one person's salary, with requestors you haven't approved. A prompt-level guardrail, not access control; fails open if the decision endpoint is unavailable. |
121
+ | [My Turn](docs/configuration.md#my-turn) | Asks the configured decision model (default `liquid/d1.2-ultra` via Codex LB) whether a group/channel conversation needs this agent's response. Advises `NO_REPLY` only when silence is clearly favored; the agent keeps the final say. Opt-in; failures leave the turn unchanged. |
121
122
  | [People dossiers](docs/peoplesql.md) | Lets the agent keep a short, evidence-backed note about each person it works with. |
122
123
  | [People Whisperer](docs/peoplesql.md#injection-and-person-state) | Supplies identity, scoped preferences and unexpired lessons on each Slack user turn. Includes [private nightly learning and weekly validation](docs/people-learning.md) by default. |
123
124
  | [People Primer](docs/peoplesql.md#optional-people-dossier-primer) | Gathers evidence for a person's note and reviews proposed notes before they are saved. |
@@ -205,8 +206,8 @@ npm run preflight # full pre-release check
205
206
 
206
207
  Releases publish to npm from GitHub Releases; see
207
208
  [RELEASE.md](https://github.com/unblocklabs-ai/unblock-memory/blob/main/docs/RELEASE.md).
208
- Fleet TypeSafe key tooling for source checkouts is described in
209
- [TYPESAFE-FLEET.md](https://github.com/unblocklabs-ai/unblock-memory/blob/main/scripts/TYPESAFE-FLEET.md);
209
+ Fleet decision model key tooling for source checkouts is described in
210
+ [DECISION-FLEET.md](https://github.com/unblocklabs-ai/unblock-memory/blob/main/scripts/DECISION-FLEET.md);
210
211
  keep populated key files private.
211
212
 
212
213
  ## License
package/defaults.json ADDED
@@ -0,0 +1,162 @@
1
+ {
2
+ "decisionModel": {
3
+ "endpoint": "https://codex.unblocklabs.ai/v1/decisions",
4
+ "model": "liquid/d1.2-ultra",
5
+ "timeoutMs": 1500,
6
+ "unboundedTimeoutMs": 60000
7
+ },
8
+ "extraction": {
9
+ "version": "lasting-facts-v12-d1",
10
+ "proposalTimeoutMs": 30000,
11
+ "validationTimeoutMs": 10000,
12
+ "minProposalConfidence": 0.5,
13
+ "inputTargetTokens": 24000,
14
+ "inputLimitTokens": 28000,
15
+ "historyTokenBudget": 8000,
16
+ "promptReserveTokens": 512,
17
+ "perMessageTokenOverhead": 8,
18
+ "maxProposals": 20,
19
+ "maxFactChars": 600,
20
+ "maxQuoteChars": 512,
21
+ "maxEvidencePerProposal": 4,
22
+ "maxExistingFacts": 100,
23
+ "maxExistingChars": 40000,
24
+ "validatorBatchSize": 4,
25
+ "runTimeoutMs": 600000,
26
+ "leaseMs": 180000,
27
+ "heartbeatMs": 30000,
28
+ "pollIntervalMs": 60000,
29
+ "intervalMinutes": 60,
30
+ "historyMessages": 6,
31
+ "maxBatches": 5,
32
+ "minSupport": 0.9,
33
+ "minRetention": 0.9,
34
+ "minReplacement": 0.9
35
+ },
36
+ "training": {
37
+ "teacherModel": "openai/gpt-6-luna",
38
+ "teacherReasoning": "xhigh",
39
+ "teacherMaxTokens": 12000,
40
+ "teacherTimeoutMs": 300000,
41
+ "candidatesPerRound": 5,
42
+ "decisionTimeoutMs": 30000,
43
+ "gateThreshold": 0.7,
44
+ "leaseMs": 120000,
45
+ "heartbeatMs": 10000,
46
+ "retrievalDepth": 10,
47
+ "topScoreCount": 3,
48
+ "maxInputEvents": 50000,
49
+ "maxInputBytes": 32000000
50
+ },
51
+ "memoryWhisperer": {
52
+ "defaultApiEndpoint": "",
53
+ "maxJudgeCandidates": 6,
54
+ "maxFinalists": 4,
55
+ "maxQueryGenMs": 1500,
56
+ "queryClientTimeoutMs": 10000,
57
+ "queryResponseMaxBytes": 16384,
58
+ "maxInjectedChars": 5000,
59
+ "judgmentExcerptChars": 1200,
60
+ "memoryGetMaxChars": 12000,
61
+ "memoryGetMaxLines": 1000,
62
+ "maxTrackedSessions": 1000,
63
+ "maxRunsPerSession": 64,
64
+ "defaultMinUsefulness": 0.5,
65
+ "defaultMaxHints": 3,
66
+ "defaultCooldownTurns": 10,
67
+ "defaultTimeoutMs": 3000
68
+ },
69
+ "skillWhisperer": {
70
+ "maxCandidates": 10,
71
+ "maxParallelJudges": 3,
72
+ "minDecisionUsefulness": 0.7,
73
+ "timeoutMs": 3000,
74
+ "contextMaxChars": 12000,
75
+ "defaultHistoryMessages": 5,
76
+ "defaultMinScore": 0.5,
77
+ "defaultCooldownTurns": 10
78
+ },
79
+ "myTurn": {
80
+ "timeoutMs": 1500,
81
+ "nudgeMaxProbability": 0.2,
82
+ "stateMaxTokens": 24000,
83
+ "defaultHistoryMessages": 10
84
+ },
85
+ "safetyWhisperer": {
86
+ "stateMaxTokens": 24000,
87
+ "maxTrackedSessions": 1000,
88
+ "maxRunsPerSession": 4,
89
+ "defaultHistoryMessages": 6,
90
+ "defaultTimeoutMs": 3000,
91
+ "defaultMinProbability": 0.4
92
+ },
93
+ "review": {
94
+ "minClaimSupport": 0.9,
95
+ "minRedundancy": 0.9,
96
+ "maxRedundancyCandidates": 4,
97
+ "clusterCenterSamples": 3,
98
+ "clusterEdgeSamples": 3,
99
+ "minClusterConfidence": 0.9,
100
+ "minClusterAgreeingExamples": 2,
101
+ "toolTimeoutMs": 30000,
102
+ "maxClaimChars": 2000,
103
+ "maxCombinedCitationChars": 6000,
104
+ "maxCitationLines": 120
105
+ },
106
+ "quality": {
107
+ "defaultMinNoise": 0.8,
108
+ "triageNoiseThreshold": 0.8,
109
+ "triageEvidenceHigh": 0.8,
110
+ "triageEvidenceLow": 0.2,
111
+ "gradeMaxChars": 6000,
112
+ "previewChars": 400
113
+ },
114
+ "people": {
115
+ "defaultWhispererMaxChars": 1200,
116
+ "defaultTodosMaxOpen": 1000,
117
+ "backgroundMaxWords": 70,
118
+ "primerExcerptChars": 6000,
119
+ "primerWorkers": 4,
120
+ "primerUncertainFloor": 0.5,
121
+ "primerTimeoutMs": 120000,
122
+ "dossierMaxBytes": 65536,
123
+ "slackApiUrl": "https://slack.com/api/users.list",
124
+ "slackTimeoutMs": 30000,
125
+ "learningNightlyTimeoutSec": 2700,
126
+ "learningWeeklyTimeoutSec": 3600
127
+ },
128
+ "responseAudit": {
129
+ "deadlineMs": 120000,
130
+ "leaseMs": 180000,
131
+ "maxRetries": 3,
132
+ "retryBackoffMs": 600000,
133
+ "pollIntervalMs": 60000,
134
+ "maxEpisodeChars": 24000,
135
+ "maxSessionEvents": 2000,
136
+ "maxSessionBytes": 2000000,
137
+ "scoreHigh": 0.8,
138
+ "scoreLow": 0.2,
139
+ "defaultHistoryMessages": 6,
140
+ "defaultLookbackDays": 30,
141
+ "defaultMaxEpisodes": 20,
142
+ "defaultIntervalMinutes": 60
143
+ },
144
+ "insideOut": {
145
+ "retryFloorMs": 3600000,
146
+ "baselineRefreshMs": 86400000,
147
+ "batchSize": 500,
148
+ "readPageSize": 2000,
149
+ "defaultIntervalMinutes": 1440,
150
+ "defaultMaxInteractions": 100,
151
+ "defaultMaxContextTokens": 30000,
152
+ "defaultBaselineMinInteractions": 20
153
+ },
154
+ "sqlite": {
155
+ "mainBusyTimeoutMs": 5000,
156
+ "peopleInventoryBusyTimeoutMs": 2000,
157
+ "readerBusyTimeoutMs": 1000,
158
+ "watchDebounceMs": 250,
159
+ "watchRetryMs": 1000,
160
+ "flushReserveTokensFloor": 20000
161
+ }
162
+ }
@@ -517,7 +517,7 @@ export function readCluster(db, clusterReferenceId, requestedLimit = DEFAULT_MEM
517
517
  }
518
518
  const limit = Math.max(1, Math.min(MAX_MEMBER_LIMIT, Math.floor(requestedLimit)));
519
519
  const offset = Math.max(0, Math.floor(requestedOffset));
520
- const total = availableSize(db, run.id, clusterId);
520
+ const total = clusterId === -1 ? row.available_size : availableSize(db, run.id, clusterId);
521
521
  const pageMembers = members(db, run.id, clusterId, limit, offset, sort, temporal);
522
522
  const nextOffset = offset + pageMembers.length;
523
523
  const hasMore = nextOffset < total;
@@ -6,6 +6,8 @@ export declare function reviewClusterIngestion(params: {
6
6
  sources: readonly ResolvedSource[];
7
7
  clusterId: string;
8
8
  apiKey: string;
9
+ endpoint?: string;
10
+ model?: string;
9
11
  timeoutMs: number;
10
12
  signal: AbortSignal;
11
13
  read?: <T>(run: () => T) => Promise<T>;
@@ -1,7 +1,8 @@
1
+ import { DEFAULTS } from "./defaults.js";
1
2
  import { readAnalysisSummary, readCluster } from "./analysis.js";
2
3
  import { parseSafeVirtualPath } from "./sources.js";
3
- import { TYPESAFE_MODEL } from "./typesafe-client.js";
4
- import { reviewClusterDefects } from "./typesafe-review.js";
4
+ import { decisionModelScope, DEFAULT_DECISION_MODEL } from "./decision-client.js";
5
+ import { reviewClusterDefects } from "./decision-review.js";
5
6
  import { chunkFingerprint } from "./curation.js";
6
7
  function indexedChunk(db, safe, member) {
7
8
  return db.prepare(`SELECT c.doc, v.pos, v.chunk_len FROM documents d JOIN content c ON c.hash = d.hash
@@ -14,10 +15,10 @@ export async function reviewClusterIngestion(params) {
14
15
  const sources = new Map(params.sources.filter(source => source.kind !== "skills").map(source => [source.collection, source]));
15
16
  const read = params.read ?? (async (run) => run());
16
17
  const snapshot = await read(() => {
17
- const center = readCluster(params.db, params.clusterId, 3, 0, "representative");
18
+ const center = readCluster(params.db, params.clusterId, DEFAULTS.review.clusterCenterSamples, 0, "representative");
18
19
  if (center.status !== "ok" || center.stale)
19
20
  return { status: "unavailable", reason: "Cluster missing or stale; refresh analysis first" };
20
- const edge = readCluster(params.db, params.clusterId, 3, 0, "score_asc");
21
+ const edge = readCluster(params.db, params.clusterId, DEFAULTS.review.clusterEdgeSamples, 0, "score_asc");
21
22
  const candidates = [...new Map([...(center.members ?? []), ...(edge.members ?? [])].map(member => [`${member.hash}:${member.seq}`, member])).values()];
22
23
  const sample = candidates.flatMap(member => {
23
24
  const path = member.sourcePaths.find(path => parseSafeVirtualPath(path, sources));
@@ -26,7 +27,7 @@ export async function reviewClusterIngestion(params) {
26
27
  const safe = parseSafeVirtualPath(path, sources);
27
28
  // Reload the full chunk; analysis previews may be truncated. Never judge a silently cut prefix.
28
29
  const row = indexedChunk(params.db, safe, member);
29
- if (!row || row.pos < 0 || row.chunk_len < 1 || row.pos + row.chunk_len > row.doc.length || row.chunk_len > 2000)
30
+ if (!row || row.pos < 0 || row.chunk_len < 1 || row.pos + row.chunk_len > row.doc.length || row.chunk_len > DEFAULTS.review.maxClaimChars)
30
31
  return [];
31
32
  const text = row.doc.slice(row.pos, row.pos + row.chunk_len);
32
33
  return [{ path, hash: member.hash, seq: member.seq, from: row.doc.slice(0, row.pos).split("\n").length,
@@ -54,13 +55,13 @@ export async function reviewClusterIngestion(params) {
54
55
  return { status: "unavailable", reason: "Sample changed during review; retry" };
55
56
  }
56
57
  const members = sample.map(({ text: _text, ...member }, index) => ({ ...member, ...judgments[index],
57
- flagged: judgments[index].defect !== "none_or_uncertain" && judgments[index].confidence >= 0.9 }));
58
+ flagged: judgments[index].defect !== "none_or_uncertain" && judgments[index].confidence >= DEFAULTS.review.minClusterConfidence }));
58
59
  const recurring = ["wrapper", "encoding", "boilerplate"].flatMap(defect => {
59
60
  const examples = members.filter(member => member.flagged && member.defect === defect);
60
- return examples.length >= 2 ? [{ defect, examples: examples.map(member => ({ path: member.path, from: member.from, fingerprint: member.fingerprint })) }] : [];
61
+ return examples.length >= DEFAULTS.review.minClusterAgreeingExamples ? [{ defect, examples: examples.map(member => ({ path: member.path, from: member.from, fingerprint: member.fingerprint })) }] : [];
61
62
  });
62
63
  return { status: "ok", runId: snapshot.runId, clusterId: params.clusterId, members, recurring,
63
64
  sampled: sample.length, considered: snapshot.considered, clusterSize: snapshot.clusterSize,
64
- policy: `${TYPESAFE_MODEL}:cluster-defects-v2-isolated`, scope: "Center/edge sample of approved complete chunks only. Recurring labels are hypotheses, not proof of a shared cause or permission to change any member. Unreviewed members remain unknown." };
65
+ policy: `${decisionModelScope(params.model ?? DEFAULT_DECISION_MODEL, params.endpoint)}:cluster-defects-v2-isolated`, scope: "Center/edge sample of approved complete chunks only. Recurring labels are hypotheses, not proof of a shared cause or permission to change any member. Unreviewed members remain unknown." };
65
66
  });
66
67
  }
@@ -26,6 +26,14 @@ type SessionCorpusConfig = {
26
26
  };
27
27
  export type CorpusConfig = FileCorpusConfig | SkillCorpusConfig | SessionCorpusConfig;
28
28
  export declare const DEFAULT_CORPORA: readonly FileCorpusConfig[];
29
+ export type DecisionModelPluginConfig = {
30
+ enabled: boolean;
31
+ endpoint: string;
32
+ model: string;
33
+ apiKey?: string;
34
+ apiKeyFile?: string;
35
+ timeoutMs: number;
36
+ };
29
37
  export type UnblockMemoryConfig = {
30
38
  myTurn: MyTurnConfig;
31
39
  extraction: ExtractionConfig;
@@ -34,12 +42,7 @@ export type UnblockMemoryConfig = {
34
42
  analysis: {
35
43
  executable?: string;
36
44
  };
37
- typesafe: {
38
- enabled: boolean;
39
- apiKey?: string;
40
- apiKeyFile?: string;
41
- timeoutMs: number;
42
- };
45
+ decisionModel: DecisionModelPluginConfig;
43
46
  qualityAudit: {
44
47
  enabled: boolean;
45
48
  corpora: readonly string[];
@@ -1,4 +1,6 @@
1
+ import { DEFAULTS } from "./defaults.js";
1
2
  import { isAbsolute } from "node:path";
3
+ import { resolveDecisionConfig, } from "@unblocklabs/decisions";
2
4
  import { resolveExtraction } from "./extraction-config.js";
3
5
  import { resolveResponseAudit } from "./response-config.js";
4
6
  import { resolvePeoplePrimer } from "./people-primer-config.js";
@@ -19,16 +21,18 @@ export const DEFAULT_CORPORA = [
19
21
  ];
20
22
  export const DEFAULT_PEOPLE_CONFIG = {
21
23
  enabled: false,
22
- whisperer: { enabled: false, maxChars: 1200 },
23
- todos: { maxOpen: 1000 },
24
+ whisperer: { enabled: false, maxChars: DEFAULTS.people.defaultWhispererMaxChars },
25
+ todos: { maxOpen: DEFAULTS.people.defaultTodosMaxOpen },
24
26
  learning: DEFAULT_LEARNING,
25
27
  };
26
- const DEFAULT_TYPESAFE_CONFIG = {
28
+ const DEFAULT_DECISION_MODEL_CONFIG = {
27
29
  enabled: true,
28
- timeoutMs: 1500,
30
+ endpoint: DEFAULTS.decisionModel.endpoint,
31
+ model: DEFAULTS.decisionModel.model,
32
+ timeoutMs: DEFAULTS.decisionModel.timeoutMs,
29
33
  };
30
34
  const DEFAULT_QUALITY_AUDIT = {
31
- enabled: false, corpora: [], minNoise: 0.8,
35
+ enabled: false, corpora: [], minNoise: DEFAULTS.quality.defaultMinNoise,
32
36
  };
33
37
  function resolveQualityAudit(value, corpora) {
34
38
  if (value === undefined)
@@ -52,68 +56,77 @@ function resolveQualityAudit(value, corpora) {
52
56
  }
53
57
  return { enabled, corpora: [...new Set(selected)], minNoise };
54
58
  }
55
- function resolveTypeSafe(value) {
59
+ function resolveDecisionModel(value) {
60
+ const label = "decisionModel";
56
61
  if (value === undefined)
57
- return { ...DEFAULT_TYPESAFE_CONFIG };
62
+ return { ...DEFAULT_DECISION_MODEL_CONFIG };
58
63
  if (!value || typeof value !== "object" || Array.isArray(value)) {
59
- throw new Error("unblock-memory typesafe must be an object");
64
+ throw new Error(`unblock-memory ${label} must be an object`);
60
65
  }
61
66
  const config = value;
62
- assertOnlyKeys(config, ["enabled", "apiKey", "apiKeyFile", "timeoutMs"], "typesafe");
67
+ assertOnlyKeys(config, ["enabled", "endpoint", "model", "apiKey", "apiKeyFile", "timeoutMs"], label);
63
68
  const enabled = config.enabled ?? true;
64
69
  if (typeof enabled !== "boolean")
65
- throw new Error("unblock-memory typesafe.enabled must be a boolean");
66
- for (const key of ["apiKey", "apiKeyFile"]) {
67
- if (config[key] !== undefined && (typeof config[key] !== "string" || !config[key].trim())) {
68
- throw new Error(`unblock-memory typesafe.${key} must be a non-empty string`);
69
- }
70
+ throw new Error(`unblock-memory ${label}.enabled must be a boolean`);
71
+ const timeoutMs = positiveInteger(config.timeoutMs, DEFAULT_DECISION_MODEL_CONFIG.timeoutMs, `${label}.timeoutMs`, 10_000);
72
+ let resolved;
73
+ try {
74
+ resolved = resolveDecisionConfig({
75
+ endpoint: config.endpoint === undefined ? DEFAULTS.decisionModel.endpoint : config.endpoint,
76
+ model: config.model === undefined ? DEFAULTS.decisionModel.model : config.model,
77
+ apiKey: config.apiKey,
78
+ apiKeyFile: config.apiKeyFile,
79
+ timeoutMs,
80
+ });
70
81
  }
71
- const apiKey = typeof config.apiKey === "string" ? config.apiKey.trim() : undefined;
72
- const apiKeyFile = typeof config.apiKeyFile === "string" ? config.apiKeyFile.trim() : undefined;
73
- if (apiKey && apiKeyFile)
74
- throw new Error("unblock-memory typesafe accepts apiKey or apiKeyFile, not both");
75
- if (apiKeyFile && !isAbsolute(apiKeyFile)) {
76
- throw new Error("unblock-memory typesafe.apiKeyFile must be an absolute path");
82
+ catch (error) {
83
+ throw new Error(`unblock-memory ${label}: ${error instanceof Error ? error.message : String(error)}`);
77
84
  }
78
85
  return {
79
- enabled, ...(apiKey ? { apiKey } : {}), ...(apiKeyFile ? { apiKeyFile } : {}),
80
- timeoutMs: positiveInteger(config.timeoutMs, DEFAULT_TYPESAFE_CONFIG.timeoutMs, "typesafe.timeoutMs", 10_000),
86
+ enabled,
87
+ endpoint: resolved.endpoint,
88
+ model: resolved.model,
89
+ ...(resolved.apiKey ? { apiKey: resolved.apiKey } : {}),
90
+ ...(resolved.apiKeyFile ? { apiKeyFile: resolved.apiKeyFile } : {}),
91
+ timeoutMs: resolved.timeoutMs,
81
92
  };
82
93
  }
83
94
  const DEFAULT_SKILL_WHISPERER = {
84
95
  enabled: true,
85
- historyMessages: 5,
86
- minScore: 0.5,
87
- cooldownTurns: 10,
96
+ historyMessages: DEFAULTS.skillWhisperer.defaultHistoryMessages,
97
+ minScore: DEFAULTS.skillWhisperer.defaultMinScore,
98
+ cooldownTurns: DEFAULTS.skillWhisperer.defaultCooldownTurns,
88
99
  };
89
100
  const DEFAULT_MEMORY_WHISPERER = {
90
- enabled: false, complementaryHints: false, corpora: [], minUsefulness: 0.5,
91
- maxHints: 3, cooldownTurns: 10, timeoutMs: 3000,
92
- api: { endpoint: "http://192.168.1.191:18087" },
101
+ enabled: false, complementaryHints: false, corpora: [], minUsefulness: DEFAULTS.memoryWhisperer.defaultMinUsefulness,
102
+ maxHints: DEFAULTS.memoryWhisperer.defaultMaxHints, cooldownTurns: DEFAULTS.memoryWhisperer.defaultCooldownTurns,
103
+ timeoutMs: DEFAULTS.memoryWhisperer.defaultTimeoutMs, api: { endpoint: DEFAULTS.memoryWhisperer.defaultApiEndpoint },
93
104
  };
94
105
  function resolveQueryApi(value) {
95
106
  if (value === undefined)
96
- return { ...DEFAULT_MEMORY_WHISPERER.api };
107
+ value = {};
97
108
  if (!value || typeof value !== "object" || Array.isArray(value))
98
109
  throw new Error("memoryWhisperer.api must be an object");
99
110
  const config = value;
100
111
  assertOnlyKeys(config, ["endpoint", "apiKeyFile"], "memoryWhisperer.api");
101
112
  const endpoint = config.endpoint ?? DEFAULT_MEMORY_WHISPERER.api.endpoint;
102
113
  let url;
103
- try {
104
- url = new URL(typeof endpoint === "string" ? endpoint : "");
105
- }
106
- catch {
107
- throw new Error("memoryWhisperer.api.endpoint must be an HTTP(S) URL");
108
- }
109
- if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash) {
110
- throw new Error("memoryWhisperer.api.endpoint must be an HTTP(S) URL without credentials, query or fragment");
114
+ if (endpoint !== "") {
115
+ try {
116
+ url = new URL(typeof endpoint === "string" ? endpoint : "");
117
+ }
118
+ catch {
119
+ throw new Error("memoryWhisperer.api.endpoint must be an HTTP(S) URL or empty");
120
+ }
121
+ if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash) {
122
+ throw new Error("memoryWhisperer.api.endpoint must be an HTTP(S) URL without credentials, query or fragment");
123
+ }
111
124
  }
112
125
  const apiKeyFile = config.apiKeyFile;
113
126
  if (apiKeyFile !== undefined && (typeof apiKeyFile !== "string" || !isAbsolute(apiKeyFile))) {
114
127
  throw new Error("memoryWhisperer.api.apiKeyFile must be an absolute path");
115
128
  }
116
- return { endpoint: url.href.replace(/\/$/u, ""), ...(apiKeyFile ? { apiKeyFile } : {}) };
129
+ return { endpoint: url?.href.replace(/\/$/u, "") ?? "", ...(apiKeyFile ? { apiKeyFile } : {}) };
117
130
  }
118
131
  function resolveMemoryWhisperer(value, corpora) {
119
132
  if (value === undefined)
@@ -146,7 +159,7 @@ function resolveMemoryWhisperer(value, corpora) {
146
159
  }
147
160
  if (enabled && !selected.length)
148
161
  throw new Error("unblock-memory enabled memoryWhisperer requires explicit corpora");
149
- const cooldownTurns = config.cooldownTurns ?? 10;
162
+ const cooldownTurns = config.cooldownTurns ?? DEFAULT_MEMORY_WHISPERER.cooldownTurns;
150
163
  if (typeof cooldownTurns !== "number" || !Number.isInteger(cooldownTurns) || cooldownTurns < 0 || cooldownTurns > 1000) {
151
164
  throw new Error("unblock-memory memoryWhisperer.cooldownTurns must be an integer between 0 and 1000");
152
165
  }
@@ -157,7 +170,7 @@ function resolveMemoryWhisperer(value, corpora) {
157
170
  return {
158
171
  enabled, complementaryHints, corpora: [...new Set(selected)], cooldownTurns, minUsefulness,
159
172
  maxHints: positiveInteger(config.maxHints, DEFAULT_MEMORY_WHISPERER.maxHints, "memoryWhisperer.maxHints", 3),
160
- timeoutMs: positiveInteger(config.timeoutMs, 3000, "memoryWhisperer.timeoutMs", 10_000),
173
+ timeoutMs: positiveInteger(config.timeoutMs, DEFAULT_MEMORY_WHISPERER.timeoutMs, "memoryWhisperer.timeoutMs", 10_000),
161
174
  api: resolveQueryApi(config.api),
162
175
  };
163
176
  }
@@ -302,7 +315,7 @@ export function resolveConfig(value) {
302
315
  throw new Error("unblock-memory config must be an object");
303
316
  }
304
317
  const config = value;
305
- assertOnlyKeys(config, ["corpora", "keepEmbeddingModelWarm", "analysis", "people", "peoplePrimer", "skillWhisperer", "memoryWhisperer", "safetyWhisperer", "myTurn", "typesafe", "qualityAudit", "evidenceReview", "responseAudit", "insideOut", "extraction"], "config");
318
+ assertOnlyKeys(config, ["corpora", "keepEmbeddingModelWarm", "analysis", "people", "peoplePrimer", "skillWhisperer", "memoryWhisperer", "safetyWhisperer", "myTurn", "decisionModel", "qualityAudit", "evidenceReview", "responseAudit", "insideOut", "extraction"], "config");
306
319
  const corpora = resolveCorpora(config.corpora);
307
320
  const people = resolvePeople(config.people);
308
321
  const peoplePrimer = resolvePeoplePrimer(config.peoplePrimer, corpora, people.enabled);
@@ -350,9 +363,9 @@ export function resolveConfig(value) {
350
363
  const value = config.skillWhisperer;
351
364
  assertOnlyKeys(value, ["enabled", "historyMessages", "minScore", "cooldownTurns"], "skillWhisperer");
352
365
  const enabled = value.enabled ?? DEFAULT_SKILL_WHISPERER.enabled;
353
- const historyMessages = value.historyMessages ?? 5;
354
- const minScore = value.minScore ?? 0.5;
355
- const cooldownTurns = value.cooldownTurns ?? 10;
366
+ const historyMessages = value.historyMessages ?? DEFAULT_SKILL_WHISPERER.historyMessages;
367
+ const minScore = value.minScore ?? DEFAULT_SKILL_WHISPERER.minScore;
368
+ const cooldownTurns = value.cooldownTurns ?? DEFAULT_SKILL_WHISPERER.cooldownTurns;
356
369
  if (typeof enabled !== "boolean")
357
370
  throw new Error("unblock-memory skillWhisperer.enabled must be a boolean");
358
371
  if (typeof historyMessages !== "number" ||
@@ -387,5 +400,6 @@ export function resolveConfig(value) {
387
400
  responseAudit: resolveResponseAudit(config.responseAudit, corpora),
388
401
  insideOut: resolveInsideOut(config.insideOut),
389
402
  memoryWhisperer: resolveMemoryWhisperer(config.memoryWhisperer, corpora),
390
- safetyWhisperer: resolveSafetyWhisperer(config.safetyWhisperer), typesafe: resolveTypeSafe(config.typesafe) };
403
+ safetyWhisperer: resolveSafetyWhisperer(config.safetyWhisperer),
404
+ decisionModel: resolveDecisionModel(config.decisionModel) };
391
405
  }
@@ -1,4 +1,4 @@
1
- import type { QualityJudgment } from "./typesafe.js";
1
+ import type { QualityJudgment } from "./decision-ranking.js";
2
2
  declare const TEMPORAL_BASES: readonly ["path", "frontmatter", "session", "agent_verified"];
3
3
  export type TemporalBasis = typeof TEMPORAL_BASES[number];
4
4
  declare const MAINTENANCE_TASK_TYPES: readonly ["ambiguous_event_time", "exact_duplicate", "quality_review"];
@@ -0,0 +1,45 @@
1
+ import { classifyDecisionFailure, DecisionError, matchesDecisionModel, type DecisionResult, type ExtractionResult, type FieldMap, type QuestionMap } from "@unblocklabs/decisions";
2
+ import { Type } from "typebox";
3
+ import type { UnblockMemoryConfig } from "./config.js";
4
+ export { classifyDecisionFailure, matchesDecisionModel, DecisionError as DecisionRequestError, };
5
+ export declare const NOUL_SCHEMA: Type.TObject<{
6
+ type: Type.TLiteral<"noul">;
7
+ noul: Type.TNumber;
8
+ }>;
9
+ export declare const NOUL_ANSWERS_SCHEMA: Type.TObject<{
10
+ answers: Type.TRecord<"^.*$", Type.TObject<{
11
+ type: Type.TLiteral<"noul">;
12
+ noul: Type.TNumber;
13
+ }>>;
14
+ }>;
15
+ type DecisionRequestOptions = {
16
+ apiKey: string;
17
+ endpoint?: string;
18
+ model?: string;
19
+ timeoutMs?: number;
20
+ signal?: AbortSignal;
21
+ };
22
+ export declare const DEFAULT_DECISION_MODEL: string;
23
+ export declare function decisionModelScope(model?: string, endpoint?: string): string;
24
+ /** A conservative estimate of serialized size, not a model-specific tokenizer. Non-ASCII is budgeted separately. */
25
+ export declare function estimateDecisionTokens(value: unknown): number;
26
+ /** A decision-model deadline: the request's own timeout, or the caller's timed-out signal. */
27
+ export declare function isDecisionTimeout(error: unknown, signal: AbortSignal): boolean;
28
+ /** Explicit credentials take precedence; a missing explicit file never selects another key. */
29
+ export declare function resolveDecisionCredential(config: Pick<UnblockMemoryConfig["decisionModel"], "enabled" | "apiKey" | "apiKeyFile"> & {
30
+ endpoint?: string;
31
+ }): Promise<string | undefined>;
32
+ /** Typed extraction call backed directly by @unblocklabs/decisions. */
33
+ export declare function extractWithModel<const F extends FieldMap>(params: DecisionRequestOptions, state: string, fields: F, options?: {
34
+ validateModel?: boolean;
35
+ }): Promise<ExtractionResult<F>>;
36
+ /** Typed decision call backed directly by @unblocklabs/decisions. */
37
+ export declare function decideWithModel<const Q extends QuestionMap>(params: DecisionRequestOptions, state: unknown, questions: Q, options?: {
38
+ validateModel?: boolean;
39
+ allowExtraAnswerKeys?: boolean;
40
+ }): Promise<DecisionResult<Q>>;
41
+ /**
42
+ * Low-level raw JSON decision request backed by @unblocklabs/decisions `decideRaw()`,
43
+ * for callers that intentionally tolerate partial multi-question responses (e.g. Safety Whisperer).
44
+ */
45
+ export declare function requestDecision(params: DecisionRequestOptions, state: unknown, questions: unknown): Promise<unknown>;