@astratra/conscience 0.0.0-stage → 1.1.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 (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.fr.md +954 -0
  3. package/README.md +915 -2
  4. package/package.json +50 -4
  5. package/src/autoconscience/experiments/common.js +76 -0
  6. package/src/autoconscience/experiments/execution.js +33 -0
  7. package/src/autoconscience/experiments/holdout.js +88 -0
  8. package/src/autoconscience/experiments/laboratory.js +99 -0
  9. package/src/autoconscience/experiments/replay.js +113 -0
  10. package/src/autoconscience/experiments/runner.js +54 -0
  11. package/src/autoconscience/experiments/sandbox.js +58 -0
  12. package/src/autoconscience/index.d.ts +203 -0
  13. package/src/autoconscience/index.js +116 -0
  14. package/src/autoconscience/lessons.js +32 -0
  15. package/src/autoconscience/shadow/candidate.js +69 -0
  16. package/src/autoconscience/shadow/index.d.ts +169 -0
  17. package/src/autoconscience/shadow/index.js +11 -0
  18. package/src/autoconscience/shadow/report.js +125 -0
  19. package/src/autoconscience/shadow/runner.js +384 -0
  20. package/src/autoconscience/shadow/store.js +98 -0
  21. package/src/autoconscience/signals.js +88 -0
  22. package/src/autoconscience/statistics.js +84 -0
  23. package/src/autoconscience/vigilance/abstention.js +123 -0
  24. package/src/autoconscience/vigilance/adversary.js +145 -0
  25. package/src/autoconscience/vigilance/common.js +56 -0
  26. package/src/autoconscience/vigilance/drift.js +306 -0
  27. package/src/autoconscience/vigilance/followups.js +100 -0
  28. package/src/autoconscience/vigilance/index.d.ts +190 -0
  29. package/src/autoconscience/vigilance/index.js +23 -0
  30. package/src/autoconscience/vigilance/lessonTests.js +40 -0
  31. package/src/autoconscience/vigilance/library.js +162 -0
  32. package/src/autoconscience/vigilance/roles.js +122 -0
  33. package/src/autoconscience/vigilance/store.js +166 -0
  34. package/src/conscience.js +559 -0
  35. package/src/diff.js +27 -0
  36. package/src/errors.js +11 -0
  37. package/src/governor/approvals.js +132 -0
  38. package/src/governor/changes.js +269 -0
  39. package/src/governor/governor.js +286 -0
  40. package/src/governor/index.d.ts +385 -0
  41. package/src/governor/index.js +22 -0
  42. package/src/governor/policy.js +136 -0
  43. package/src/governor/postgres.js +243 -0
  44. package/src/governor/remote.js +305 -0
  45. package/src/governor/review.js +191 -0
  46. package/src/governor/rollout.js +66 -0
  47. package/src/governor/stores.js +136 -0
  48. package/src/governor/util.js +53 -0
  49. package/src/guard.js +21 -0
  50. package/src/index.d.ts +244 -0
  51. package/src/index.js +23 -0
  52. package/src/memoryStore.js +65 -0
  53. package/src/postgres.js +93 -0
  54. package/src/records.js +220 -0
@@ -0,0 +1,306 @@
1
+ 'use strict';
2
+ /*
3
+ * Drift watch (proposition 17). Compares a baseline window with a current
4
+ * window on three families of signals:
5
+ * - inputs: distribution of domains and of languages, length of requests;
6
+ * - outcomes: rate of succeeded / failed (and the share of unknown);
7
+ * - performance: calibration (Brier score, confidence gap) and tool reliability.
8
+ *
9
+ * Tests, all simple and documented:
10
+ * - Population Stability Index (PSI) for distributions. Each category gets a
11
+ * 0.5 pseudo-count so an empty category never gives an infinite value.
12
+ * Conventional reading: PSI < 0.10 stable, 0.10 to 0.25 moderate shift,
13
+ * >= 0.25 significant shift. Lengths are cut into bins at the baseline
14
+ * quintiles.
15
+ * - Difference of two proportions with Newcombe's hybrid score interval,
16
+ * built from the two Wilson intervals (the same Wilson as P2). A shift is
17
+ * "significant" when the interval excludes zero and the gap is at least
18
+ * `minimumEffect` (default 5 points); statistically visible but tiny gaps
19
+ * stay "moderate".
20
+ * - Brier score and confidence gap: plain difference against a threshold
21
+ * (they come from P2 summaries, there is no raw sample to test).
22
+ *
23
+ * A window with fewer known observations than `minimumSample` never concludes.
24
+ * A business calendar (P2) is consulted BEFORE blaming the agent: a calendar
25
+ * period that overlaps the current window but not the baseline explains the
26
+ * shift. The result is a coded recommendation (monitor / freeze / investigate /
27
+ * propose_rollback). Nothing is applied here: a rollback is only ever a
28
+ * proposal handed to the governor.
29
+ */
30
+ const { wilsonInterval, minimum, number } = require('../statistics');
31
+ const { ready, invalid, actorOf, isoOf } = require('./common');
32
+
33
+ const RECOMMENDATIONS = Object.freeze(['monitor', 'freeze', 'investigate', 'propose_rollback']);
34
+ const PSI_MODERATE = 0.1;
35
+ const PSI_SIGNIFICANT = 0.25;
36
+
37
+ const round = (value) => Math.round(value * 1e6) / 1e6;
38
+ const total = (counts) => Object.values(counts).reduce((sum, value) => sum + value, 0);
39
+
40
+ function counts(value, name) {
41
+ if (value == null) return null;
42
+ if (typeof value !== 'object' || Array.isArray(value)) invalid(`${name} must map a category to a count.`);
43
+ for (const [key, count] of Object.entries(value)) {
44
+ if (typeof count !== 'number' || !Number.isFinite(count) || count < 0) invalid(`${name}.${key} must be a finite count >= 0.`);
45
+ }
46
+ return value;
47
+ }
48
+
49
+ /** Population Stability Index of two count tables, with its biggest contributors. */
50
+ function populationStabilityIndex(baseline, current) {
51
+ const keys = [...new Set([...Object.keys(baseline), ...Object.keys(current)])].sort();
52
+ const bt = total(baseline), ct = total(current), k = keys.length;
53
+ if (!k || bt <= 0 || ct <= 0) return null;
54
+ const parts = keys.map((key) => {
55
+ const pb = ((baseline[key] ?? 0) + 0.5) / (bt + 0.5 * k);
56
+ const pc = ((current[key] ?? 0) + 0.5) / (ct + 0.5 * k);
57
+ return { category: key, baseline: round(pb), current: round(pc), contribution: (pc - pb) * Math.log(pc / pb) };
58
+ });
59
+ const value = parts.reduce((sum, part) => sum + part.contribution, 0);
60
+ const top = [...parts].sort((a, b) => b.contribution - a.contribution || (a.category < b.category ? -1 : 1)).slice(0, 3)
61
+ .map((part) => ({ ...part, contribution: round(part.contribution) }));
62
+ return { psi: value, categories: k, top };
63
+ }
64
+
65
+ /** Newcombe hybrid score interval for p2 - p1 (Wilson intervals of each proportion). */
66
+ function differenceInterval(s1, n1, s2, n2, level = 0.95) {
67
+ const a = wilsonInterval(s1, n1, level), b = wilsonInterval(s2, n2, level);
68
+ const p1 = s1 / n1, p2 = s2 / n2, d = p2 - p1;
69
+ return { difference: d, low: d - Math.sqrt((p2 - b.low) ** 2 + (a.high - p1) ** 2), high: d + Math.sqrt((b.high - p2) ** 2 + (p1 - a.low) ** 2), level };
70
+ }
71
+
72
+ const levelOfPsi = (psi) => (psi >= PSI_SIGNIFICANT ? 'significant' : psi >= PSI_MODERATE ? 'moderate' : 'none');
73
+
74
+ function signal(fields) {
75
+ return { drifted: fields.level === 'none' ? false : fields.level == null ? null : true, ...fields };
76
+ }
77
+ const insufficient = (id, dimension, metric, test, baselineSample, currentSample, threshold) => signal({
78
+ id, dimension, metric, test, status: 'insufficient_data', level: null, statistic: null, direction: null, baselineSample, currentSample, threshold, details: null
79
+ });
80
+
81
+ function distributionSignal(id, dimension, metric, base, cur, minimumSample) {
82
+ const bt = total(base), ct = total(cur);
83
+ if (bt < minimumSample || ct < minimumSample) return insufficient(id, dimension, metric, 'psi', bt, ct, PSI_SIGNIFICANT);
84
+ const result = populationStabilityIndex(base, cur);
85
+ return signal({ id, dimension, metric, test: 'psi', status: 'observed', statistic: round(result.psi), level: levelOfPsi(result.psi),
86
+ direction: 'shift', baselineSample: bt, currentSample: ct, threshold: PSI_SIGNIFICANT, details: { moderateFrom: PSI_MODERATE, top: result.top } });
87
+ }
88
+
89
+ function lengthBins(baseline, current) {
90
+ const sorted = [...baseline].sort((a, b) => a - b);
91
+ const edges = [...new Set([0.2, 0.4, 0.6, 0.8].map((q) => sorted[Math.min(sorted.length - 1, Math.floor(q * sorted.length))]))];
92
+ const label = (value) => { const index = edges.findIndex((edge) => value <= edge); return `bin_${index === -1 ? edges.length : index}`; };
93
+ const table = (values) => { const out = {}; for (const v of values) out[label(v)] = (out[label(v)] ?? 0) + 1; return out; };
94
+ return { base: table(baseline), cur: table(current), edges };
95
+ }
96
+
97
+ function lengthsOf(value, name) {
98
+ if (value == null) return null;
99
+ if (!Array.isArray(value) || !value.every((v) => typeof v === 'number' && Number.isFinite(v) && v >= 0)) invalid(`${name} must be an array of finite lengths >= 0.`);
100
+ return value;
101
+ }
102
+
103
+ function proportionSignal(id, dimension, metric, base, cur, options, { minimumEffect, goodDirection }) {
104
+ const [bs, bn] = base, [cs, cn] = cur;
105
+ if (bn < options.minimumSample || cn < options.minimumSample) return insufficient(id, dimension, metric, 'newcombe_difference', bn, cn, minimumEffect);
106
+ const interval = differenceInterval(bs, bn, cs, cn, options.level);
107
+ const excludesZero = interval.low > 0 || interval.high < 0;
108
+ const gap = Math.abs(interval.difference);
109
+ const level = excludesZero ? (gap >= minimumEffect ? 'significant' : 'moderate') : 'none';
110
+ const direction = interval.difference === 0 ? 'unchanged' : interval.difference * goodDirection > 0 ? 'improvement' : 'degradation';
111
+ return signal({ id, dimension, metric, test: 'newcombe_difference', status: 'observed', statistic: round(interval.difference), level,
112
+ direction, baselineSample: bn, currentSample: cn, threshold: minimumEffect,
113
+ details: { baselineRate: round(bs / bn), currentRate: round(cs / cn), interval: { low: round(interval.low), high: round(interval.high), level: interval.level } } });
114
+ }
115
+
116
+ function outcomeCounts(value, name) {
117
+ if (value == null) return null;
118
+ counts(value, name);
119
+ for (const key of ['succeeded', 'failed']) if (typeof value[key] !== 'number') invalid(`${name}.${key} is required.`);
120
+ return { succeeded: value.succeeded, failed: value.failed, unknown: value.unknown ?? 0 };
121
+ }
122
+
123
+ function toolKey(t) { return JSON.stringify([t.tool, t.provider ?? null]); }
124
+
125
+ function windowOf(win, name) {
126
+ if (win == null) return null;
127
+ const from = Date.parse(win.from), to = Date.parse(win.to);
128
+ if (!Number.isFinite(from) || !Number.isFinite(to) || from >= to) invalid(`${name}.window must be { from, to } with from before to.`);
129
+ return { from, to, iso: { from: new Date(from).toISOString(), to: new Date(to).toISOString() } };
130
+ }
131
+
132
+ /** Calendar periods of this domain that overlap the current window and not the baseline one. */
133
+ function explainingPeriods(governor, organisationId, domain, calendars, baseWindow, curWindow) {
134
+ const overlaps = (period, win) => Date.parse(period.from) < win.to && win.from < Date.parse(period.to);
135
+ const out = [];
136
+ for (const calendar of calendars) {
137
+ governor.assertSingleOrganisation(organisationId, calendar.organisationId);
138
+ if (calendar.domain !== domain) continue;
139
+ for (const period of calendar.periods) {
140
+ const from = Date.parse(period.from), to = Date.parse(period.to);
141
+ if (!Number.isFinite(from) || !Number.isFinite(to) || from >= to) invalid('Invalid calendar period.');
142
+ if (overlaps(period, curWindow) && !overlaps(period, baseWindow)) out.push({ calendar: calendar.name, label: period.label, from: period.from, to: period.to, kind: period.kind ?? null });
143
+ }
144
+ }
145
+ return out;
146
+ }
147
+
148
+ /**
149
+ * Build a window summary from P2 material. `decisions` are the decisions of the
150
+ * window, `findings` the P2 findings computed on that same window. `languageOf`
151
+ * is injected (the core detects no language).
152
+ */
153
+ function snapshotWindow({ decisions = [], findings = [], agentId, domain, languageOf, window } = {}) {
154
+ const domains = {}, languages = {}, lengths = [];
155
+ for (const d of decisions) {
156
+ if (agentId && d.agentId !== agentId) continue;
157
+ const name = d.domain ?? 'general';
158
+ domains[name] = (domains[name] ?? 0) + 1;
159
+ lengths.push(String(d.objective ?? '').length);
160
+ if (typeof languageOf === 'function') { const lang = languageOf(d); if (lang) languages[lang] = (languages[lang] ?? 0) + 1; }
161
+ }
162
+ const outcomes = { succeeded: 0, failed: 0, unknown: 0 };
163
+ for (const f of findings) if (f.kind === 'outcome' && Object.hasOwn(outcomes, f.details?.outcomeStatus)) outcomes[f.details.outcomeStatus] += 1;
164
+ const calibration = findings.find((f) => f.kind === 'calibration' && (!agentId || f.agentId === agentId) && (!domain || f.domain === domain))?.details ?? null;
165
+ const tools = findings.filter((f) => f.kind === 'tool_reliability').map((f) => ({ tool: f.details.tool, provider: f.details.provider, knownCalls: f.details.knownCalls, failures: f.details.failures }));
166
+ return {
167
+ window: window ?? null, inputs: { domains, languages: typeof languageOf === 'function' ? languages : undefined, lengths }, outcomes,
168
+ performance: { calibration: calibration && { sampleSize: calibration.sampleSize, brierScore: calibration.brierScore, confidenceGap: calibration.confidenceGap }, tools }
169
+ };
170
+ }
171
+
172
+ /**
173
+ * Detect drift. Needs a genuine, running governor. Returns data only:
174
+ * `applied` is always false. With `propose` and a `recentChange`, a rollback
175
+ * recommendation becomes a pending proposal at the governor; nothing else.
176
+ */
177
+ async function detectDrift(options = {}) {
178
+ const { governor, organisationId, agentId, domain, baseline, current } = options;
179
+ await ready(governor, organisationId);
180
+ if (typeof agentId !== 'string' || !agentId) invalid('agentId is required.');
181
+ if (typeof domain !== 'string' || !domain) invalid('domain is required.');
182
+ if (!baseline || !current || typeof baseline !== 'object' || typeof current !== 'object') invalid('baseline and current summaries are required.');
183
+ const minimumSample = minimum(options.minimumSample);
184
+ const level = options.level ?? 0.95;
185
+ wilsonInterval(0, 1, level);
186
+ const minimumEffect = number(options.minimumEffect ?? 0.05, 'minimumEffect', 0, 1);
187
+ const brierDelta = number(options.brierDelta ?? 0.05, 'brierDelta', 0, 1);
188
+ const gapDelta = number(options.confidenceGapDelta ?? 0.1, 'confidenceGapDelta', 0, 1);
189
+ const freezeDrop = number(options.freezeDrop ?? 0.15, 'freezeDrop', 0, 1);
190
+ const settings = { minimumSample, level };
191
+ const calendars = options.calendars ?? [];
192
+ if (!Array.isArray(calendars)) invalid('calendars must be an array.');
193
+
194
+ const signals = [];
195
+ /* ---- inputs ---- */
196
+ for (const [key, metric] of [['domains', 'domain_mix'], ['languages', 'language_mix']]) {
197
+ const b = counts(baseline.inputs?.[key], `baseline.inputs.${key}`), c = counts(current.inputs?.[key], `current.inputs.${key}`);
198
+ if (b && c) signals.push(distributionSignal(`inputs.${metric}`, 'inputs', metric, b, c, minimumSample));
199
+ }
200
+ const bl = lengthsOf(baseline.inputs?.lengths, 'baseline.inputs.lengths'), cl = lengthsOf(current.inputs?.lengths, 'current.inputs.lengths');
201
+ if (bl && cl) {
202
+ if (bl.length < minimumSample || cl.length < minimumSample) signals.push(insufficient('inputs.length', 'inputs', 'length', 'psi', bl.length, cl.length, PSI_SIGNIFICANT));
203
+ else { const bins = lengthBins(bl, cl); const s = distributionSignal('inputs.length', 'inputs', 'length', bins.base, bins.cur, 1); s.details.binEdges = bins.edges; signals.push(s); }
204
+ }
205
+ /* ---- outcomes ---- */
206
+ const bo = outcomeCounts(baseline.outcomes, 'baseline.outcomes'), co = outcomeCounts(current.outcomes, 'current.outcomes');
207
+ if (bo && co) {
208
+ signals.push(proportionSignal('outcomes.success_rate', 'outcomes', 'success_rate', [bo.succeeded, bo.succeeded + bo.failed], [co.succeeded, co.succeeded + co.failed], settings, { minimumEffect, goodDirection: 1 }));
209
+ const bAll = bo.succeeded + bo.failed + bo.unknown, cAll = co.succeeded + co.failed + co.unknown;
210
+ signals.push(proportionSignal('outcomes.unknown_rate', 'outcomes', 'unknown_rate', [bo.unknown, bAll], [co.unknown, cAll], settings, { minimumEffect, goodDirection: -1 }));
211
+ }
212
+ /* ---- performance ---- */
213
+ const bc = baseline.performance?.calibration, cc = current.performance?.calibration;
214
+ if (bc && cc) {
215
+ const enough = (bc.sampleSize ?? 0) >= minimumSample && (cc.sampleSize ?? 0) >= minimumSample;
216
+ const delta = (id, metric, base, cur, threshold, signed) => {
217
+ if (!enough || base == null || cur == null) return insufficient(id, 'performance', metric, 'threshold_difference', bc.sampleSize ?? 0, cc.sampleSize ?? 0, threshold);
218
+ const diff = signed(cur) - signed(base);
219
+ const lvl = diff >= threshold ? 'significant' : diff >= threshold / 2 ? 'moderate' : 'none';
220
+ return signal({ id, dimension: 'performance', metric, test: 'threshold_difference', status: 'observed', statistic: round(cur - base), level: lvl,
221
+ direction: diff > 0 ? 'degradation' : diff < 0 ? 'improvement' : 'unchanged', baselineSample: bc.sampleSize, currentSample: cc.sampleSize, threshold,
222
+ details: { baseline: base, current: cur } });
223
+ };
224
+ signals.push(delta('performance.brier_score', 'brier_score', bc.brierScore, cc.brierScore, brierDelta, (v) => v));
225
+ signals.push(delta('performance.overconfidence', 'overconfidence', bc.confidenceGap, cc.confidenceGap, gapDelta, (v) => v));
226
+ }
227
+ const bt = new Map((baseline.performance?.tools ?? []).map((t) => [toolKey(t), t]));
228
+ for (const t of current.performance?.tools ?? []) {
229
+ const before = bt.get(toolKey(t));
230
+ if (!before) continue;
231
+ signals.push(proportionSignal(`performance.tool_errors[${t.tool}|${t.provider ?? ''}]`, 'performance', 'tool_error_rate', [before.failures, before.knownCalls], [t.failures, t.knownCalls], settings,
232
+ { minimumEffect, goodDirection: -1 }));
233
+ }
234
+ signals.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
235
+
236
+ /* ---- reading of the signals ---- */
237
+ const significant = (dimension, test = () => true) => signals.some((s) => s.dimension === dimension && s.level === 'significant' && test(s));
238
+ const worse = (s) => s.direction === 'degradation';
239
+ const inputsDrift = significant('inputs');
240
+ const outcomeDegraded = signals.some((s) => s.id === 'outcomes.success_rate' && s.level === 'significant' && worse(s));
241
+ const calibrationDegraded = significant('performance', (s) => s.test === 'threshold_difference' && worse(s));
242
+ const toolDegraded = significant('performance', (s) => s.metric === 'tool_error_rate' && worse(s));
243
+ const anySignificant = signals.some((s) => s.level === 'significant');
244
+ const anyModerate = signals.some((s) => s.level === 'moderate');
245
+ const evaluated = signals.some((s) => s.status === 'observed');
246
+ const status = !evaluated ? 'insufficient_data' : anySignificant ? 'drift' : anyModerate ? 'watch' : 'stable';
247
+
248
+ /* ---- calendar first ---- */
249
+ const baseWindow = windowOf(baseline.window, 'baseline'), curWindow = windowOf(current.window, 'current');
250
+ let calendar = { status: 'not_checked', periods: [] };
251
+ if (calendars.length) {
252
+ if (!baseWindow || !curWindow) invalid('A calendar check needs baseline.window and current.window.');
253
+ const periods = explainingPeriods(governor, organisationId, domain, calendars, baseWindow, curWindow);
254
+ calendar = { status: periods.length ? 'explains' : 'does_not_explain', periods };
255
+ }
256
+ const drifting = status === 'drift' || status === 'watch';
257
+ const explained = drifting && calendar.status === 'explains';
258
+
259
+ /* ---- recommendation ---- */
260
+ const degraded = outcomeDegraded || calibrationDegraded || toolDegraded;
261
+ const reasons = [];
262
+ let recommendation = 'monitor';
263
+ let change = options.recentChange ?? null;
264
+ if (change) {
265
+ if (typeof change !== 'object' || !['kind', 'id', 'version', 'previousVersion'].every((k) => typeof change[k] === 'string' && change[k])) invalid('recentChange needs kind, id, version and previousVersion.');
266
+ change = { kind: change.kind, id: change.id, version: change.version, previousVersion: change.previousVersion, deployedAt: isoOf(change.deployedAt, 'recentChange.deployedAt') };
267
+ }
268
+ const afterChange = Boolean(change && curWindow && curWindow.from >= Date.parse(change.deployedAt));
269
+ const drop = signals.find((s) => s.id === 'outcomes.success_rate' && s.level === 'significant' && worse(s));
270
+ if (status === 'insufficient_data') reasons.push('insufficient_data');
271
+ else if (!drifting) reasons.push('no_drift');
272
+ else if (explained) reasons.push('calendar_explained');
273
+ else if (!degraded) reasons.push(inputsDrift ? 'inputs_shift_only' : 'watch_only');
274
+ else if (inputsDrift || toolDegraded) { recommendation = 'investigate'; reasons.push(...[inputsDrift && 'inputs_shift', toolDegraded && 'tool_degradation', outcomeDegraded && 'outcome_decline', calibrationDegraded && 'calibration_decline'].filter(Boolean)); }
275
+ else if (afterChange) { recommendation = 'propose_rollback'; reasons.push('degradation_after_change'); }
276
+ else if (drop && Math.abs(drop.statistic) >= freezeDrop) { recommendation = 'freeze'; reasons.push('severe_outcome_decline'); }
277
+ else { recommendation = 'investigate'; reasons.push(...[outcomeDegraded && 'outcome_decline', calibrationDegraded && 'calibration_decline'].filter(Boolean)); }
278
+
279
+ const result = {
280
+ organisationId, agentId, domain, status, signals, calendar,
281
+ attribution: explained ? 'calendar' : status === 'drift' || status === 'watch' ? 'agent_or_environment' : 'none',
282
+ reexamineAfter: explained ? calendar.periods.map((p) => p.to).sort().at(-1) : null,
283
+ recommendation, reasons, recentChange: change, applied: false, proposal: null, finding: null
284
+ };
285
+
286
+ if (options.propose && recommendation === 'propose_rollback') {
287
+ const proposedBy = actorOf(options.propose.proposedBy, { kind: 'engine', id: 'drift-watch' });
288
+ result.proposal = await governor.evaluatePolicy({
289
+ organisationId, target: { kind: change.kind, id: change.id, version: change.version },
290
+ change: { revertTo: change.previousVersion, from: change.version },
291
+ justification: { code: 'drift_detected', agentId, domain, signals: signals.filter((s) => s.level === 'significant').map((s) => ({ id: s.id, statistic: s.statistic, direction: s.direction })) },
292
+ rollback: { revertTo: change.previousVersion }, risk: options.propose.risk ?? 'high', proposedBy, owner: options.propose.owner ?? null
293
+ });
294
+ }
295
+ if (options.recordedBy && drifting) {
296
+ result.finding = await governor.recordFinding({
297
+ organisationId, runId: options.runId ?? null, code: explained ? 'drift_calendar_explained' : 'drift_detected',
298
+ severity: recommendation === 'monitor' ? 'info' : recommendation === 'investigate' ? 'medium' : 'high',
299
+ subject: { kind: 'agent_domain', id: `${agentId}:${domain}` }, evidenceRefs: signals.filter((s) => s.level && s.level !== 'none').map((s) => s.id),
300
+ metrics: { recommendation, attribution: result.attribution }, recordedBy: actorOf(options.recordedBy)
301
+ });
302
+ }
303
+ return result;
304
+ }
305
+
306
+ module.exports = { detectDrift, snapshotWindow, populationStabilityIndex, differenceInterval, DRIFT_RECOMMENDATIONS: RECOMMENDATIONS };
@@ -0,0 +1,100 @@
1
+ 'use strict';
2
+ /*
3
+ * Prospective memory (proposition 18). A follow-up is a commitment to look at a
4
+ * decision again when its result becomes observable. It is created once (same
5
+ * decision, same date, same question: same follow-up), isolated by
6
+ * organisation, and erased with the person it concerns.
7
+ */
8
+ const { ConscienceError } = require('../../errors');
9
+ const { fingerprintOf } = require('../../governor/util');
10
+ const { ready, invalid, isoOf, maskerOf, maskText, isNonEmptyString } = require('./common');
11
+ const { VIGILANCE_STORE_METHODS } = require('./store');
12
+
13
+ const STATUSES = Object.freeze(['scheduled', 'done']);
14
+
15
+ /**
16
+ * Eraser for createConscience({ erasers: [...] }): removes the follow-ups of a
17
+ * person in the same call as the rest of their data.
18
+ */
19
+ function followUpEraser(store) {
20
+ if (!store || typeof store.removeFollowUps !== 'function') throw new ConscienceError('store_invalid', 'A vigilance store is required.');
21
+ return async ({ organisationId, userId }) => ({ name: 'follow_ups', count: await store.removeFollowUps({ organisationId, userId }) });
22
+ }
23
+
24
+ function createFollowUps(options = {}) {
25
+ const { governor, conscience, store } = options;
26
+ if (!conscience || conscience.governor !== governor) invalid('conscience must use the supplied governor.');
27
+ for (const method of VIGILANCE_STORE_METHODS) {
28
+ if (!store || typeof store[method] !== 'function') throw new ConscienceError('store_invalid', `Vigilance store is missing ${method}().`);
29
+ }
30
+ const mask = maskerOf(options.masker);
31
+ const now = options.now ?? Date.now;
32
+ const iso = () => new Date(now()).toISOString();
33
+
34
+ async function scheduleFollowUp(input = {}) {
35
+ const organisationId = await ready(governor, input.organisationId);
36
+ if (!isNonEmptyString(input.decisionId)) invalid('decisionId is required.');
37
+ const observableAt = isoOf(input.observableAt, 'observableAt');
38
+ if (!isNonEmptyString(input.question) || input.question.length > 5000) invalid('question must be a non-empty string of at most 5000 characters.');
39
+ const scope = { organisationId, userId: input.userId ?? null };
40
+ const decision = await conscience.getDecision(scope, input.decisionId);
41
+ if (!decision) throw new ConscienceError('not_found', 'Decision not found.');
42
+ const question = await maskText(mask, input.question);
43
+ const fingerprint = fingerprintOf({ kind: 'follow_up', organisationId, decisionId: decision.id, observableAt, question });
44
+ const id = input.id == null ? `fu_${fingerprint.slice(0, 32)}` : input.id;
45
+ if (!isNonEmptyString(id) || id.length > 500) invalid('id must be a non-empty string of at most 500 characters.');
46
+ const record = {
47
+ id, organisationId, userId: decision.userId ?? null, agentId: decision.agentId, decisionId: decision.id,
48
+ observableAt, question, status: 'scheduled', fingerprint, createdAt: iso(), completedAt: null, outcomeRef: null
49
+ };
50
+ const { record: stored, created } = await store.putFollowUp(record);
51
+ if (!created && stored.fingerprint !== fingerprint) throw new ConscienceError('conflict', 'A different follow-up already uses this id.');
52
+ return { followUp: stored, created };
53
+ }
54
+
55
+ /** Follow-ups whose date has come, oldest first, with the decision to look at again. Content is data, never an instruction. */
56
+ async function dueFollowUps(input = {}) {
57
+ const organisationId = await ready(governor, input.organisationId);
58
+ const at = input.now == null ? iso() : isoOf(input.now, 'now');
59
+ const filter = { organisationId, status: 'scheduled', observableTo: at, limit: input.limit };
60
+ if (input.userId != null) filter.userId = input.userId;
61
+ const due = [];
62
+ for (const followUp of await store.listFollowUps(filter)) {
63
+ const decision = await conscience.getDecision({ organisationId }, followUp.decisionId);
64
+ if (!decision) continue; // The decision was erased: nothing left to look at.
65
+ due.push({
66
+ followUp,
67
+ decision: { id: decision.id, agentId: decision.agentId, domain: decision.domain, objective: decision.objective, expectedOutcome: decision.expectedOutcome, horizon: decision.horizon }
68
+ });
69
+ }
70
+ return due;
71
+ }
72
+
73
+ async function completeFollowUp(input = {}) {
74
+ const organisationId = await ready(governor, input.organisationId);
75
+ if (!isNonEmptyString(input.id)) invalid('id is required.');
76
+ const found = await store.getFollowUp(organisationId, input.id);
77
+ if (!found) throw new ConscienceError('not_found', 'Follow-up not found.');
78
+ if (found.status === 'done') return { followUp: found, completed: false };
79
+ const updated = await store.updateFollowUp(organisationId, input.id, 'scheduled', { status: 'done', completedAt: iso(), outcomeRef: input.outcomeRef ?? null });
80
+ return { followUp: updated ?? await store.getFollowUp(organisationId, input.id), completed: Boolean(updated) };
81
+ }
82
+
83
+ async function listFollowUps(input = {}) {
84
+ const organisationId = await ready(governor, input.organisationId);
85
+ const filter = { organisationId, limit: input.limit };
86
+ for (const field of ['userId', 'decisionId', 'status']) if (input[field] !== undefined) filter[field] = input[field];
87
+ if (filter.status !== undefined && !STATUSES.includes(filter.status)) invalid(`status must be one of ${STATUSES.join(', ')}.`);
88
+ return store.listFollowUps(filter);
89
+ }
90
+
91
+ async function eraseSubject({ organisationId, userId } = {}) {
92
+ governor.assertSingleOrganisation(organisationId);
93
+ if (!isNonEmptyString(userId)) invalid('eraseSubject needs organisationId and userId.');
94
+ return { removed: await store.removeFollowUps({ organisationId, userId }) };
95
+ }
96
+
97
+ return Object.freeze({ scheduleFollowUp, dueFollowUps, completeFollowUp, listFollowUps, eraseSubject, eraser: followUpEraser(store) });
98
+ }
99
+
100
+ module.exports = { createFollowUps, followUpEraser, FOLLOW_UP_STATUSES: STATUSES };
@@ -0,0 +1,190 @@
1
+ /** P3, second half: vigilance. Deterministic: no language model, nothing is ever applied by itself. */
2
+ import type { Governor, ChangeProposal } from '../../governor';
3
+ import type { Conscience, DecisionRecord } from '../../index';
4
+ import type { CalibrationResult, DomainCalendar, ErrorCostPolicy, Interval, ReflectionFinding, StatisticsOptions } from '../index';
5
+
6
+ /** Structurally the scenario of evaluateAgent in @astratra/testkit (this package does not depend on it). */
7
+ export interface EvaluateAgentScenario {
8
+ id: string; question: string;
9
+ tools?: Array<{ name: string; run(args: Record<string, unknown>, context?: any): unknown | Promise<unknown> }>;
10
+ expect?: { tools?: string[]; content?: Array<string | RegExp> };
11
+ score?(input: { text: string; calls: Array<{ name: string; args: Record<string, unknown> }>; output: unknown; checks: Array<{ name: string; passed: boolean }> }): number | Promise<number>;
12
+ }
13
+
14
+ export type Masker = ((text: string) => string | Promise<string>) | { redactString(text: string): string } | { mask(text: string): string };
15
+ export interface Actor { kind: 'engine' | 'model' | 'human' | 'system'; id: string }
16
+
17
+ /* ---------- 17 · drift ---------- */
18
+ export type DriftRecommendation = 'monitor' | 'freeze' | 'investigate' | 'propose_rollback';
19
+ export interface WindowSummary {
20
+ window?: { from: string | Date; to: string | Date };
21
+ inputs?: { domains?: Record<string, number>; languages?: Record<string, number>; lengths?: number[] };
22
+ outcomes?: { succeeded: number; failed: number; unknown?: number };
23
+ performance?: {
24
+ calibration?: { sampleSize: number; brierScore: number | null; confidenceGap: number | null };
25
+ tools?: Array<{ tool: string; provider?: string | null; knownCalls: number; failures: number }>;
26
+ };
27
+ }
28
+ export interface DriftSignal {
29
+ id: string; dimension: 'inputs' | 'outcomes' | 'performance'; metric: string;
30
+ test: 'psi' | 'newcombe_difference' | 'threshold_difference';
31
+ status: 'observed' | 'insufficient_data'; level: 'none' | 'moderate' | 'significant' | null; drifted: boolean | null;
32
+ statistic: number | null; direction: 'shift' | 'degradation' | 'improvement' | 'unchanged' | null;
33
+ baselineSample: number; currentSample: number; threshold: number; details: Record<string, unknown> | null;
34
+ }
35
+ export interface RecentChange { kind: string; id: string; version: string; previousVersion: string; deployedAt: string | Date }
36
+ export interface DetectDriftOptions extends StatisticsOptions {
37
+ governor: Governor; organisationId: string; agentId: string; domain: string;
38
+ baseline: WindowSummary; current: WindowSummary;
39
+ /** P2 calendars of the same organisation: a period that overlaps the current window and not the baseline explains a shift. */
40
+ calendars?: DomainCalendar[];
41
+ recentChange?: RecentChange;
42
+ minimumEffect?: number; brierDelta?: number; confidenceGapDelta?: number; freezeDrop?: number;
43
+ /** Turns a rollback recommendation into a PENDING proposal at the governor. Never applies it. */
44
+ propose?: { proposedBy?: Actor; owner?: string; risk?: 'low' | 'medium' | 'high' | 'critical' };
45
+ recordedBy?: Actor; runId?: string;
46
+ }
47
+ export interface DriftReport {
48
+ organisationId: string; agentId: string; domain: string;
49
+ status: 'stable' | 'watch' | 'drift' | 'insufficient_data'; signals: DriftSignal[];
50
+ calendar: { status: 'not_checked' | 'explains' | 'does_not_explain'; periods: Array<{ calendar: string; label: string; from: string; to: string; kind: string | null }> };
51
+ attribution: 'none' | 'calendar' | 'agent_or_environment'; reexamineAfter: string | null;
52
+ recommendation: DriftRecommendation; reasons: string[];
53
+ recentChange: (Omit<RecentChange, 'deployedAt'> & { deployedAt: string }) | null;
54
+ /** Always false: detection never applies anything. */
55
+ applied: false; proposal: ChangeProposal | null; finding: unknown | null;
56
+ }
57
+ export function detectDrift(options: DetectDriftOptions): Promise<DriftReport>;
58
+ export function snapshotWindow(input: { decisions?: DecisionRecord[]; findings?: ReflectionFinding[]; agentId?: string; domain?: string; languageOf?: (decision: DecisionRecord) => string | null | undefined; window?: { from: string; to: string } }): WindowSummary;
59
+ export function populationStabilityIndex(baseline: Record<string, number>, current: Record<string, number>): { psi: number; categories: number; top: Array<{ category: string; baseline: number; current: number; contribution: number }> } | null;
60
+ export function differenceInterval(s1: number, n1: number, s2: number, n2: number, level?: 0.9 | 0.95 | 0.99): { difference: number; low: number; high: number; level: number };
61
+ export const DRIFT_RECOMMENDATIONS: readonly DriftRecommendation[];
62
+
63
+ /* ---------- 18 · prospective memory ---------- */
64
+ export interface VigilanceStore {
65
+ putFollowUp(record: FollowUp): Promise<{ record: FollowUp; created: boolean }>;
66
+ getFollowUp(organisationId: string, id: string): Promise<FollowUp | null>;
67
+ listFollowUps(filter: { organisationId: string; userId?: string | null; decisionId?: string; status?: string; observableTo?: string; limit?: number }): Promise<FollowUp[]>;
68
+ updateFollowUp(organisationId: string, id: string, expectedStatus: string, patch: Partial<FollowUp>): Promise<FollowUp | null>;
69
+ removeFollowUps(filter: { organisationId: string; userId: string }): Promise<number>;
70
+ putCandidate(record: ScenarioCandidate): Promise<{ record: ScenarioCandidate; created: boolean }>;
71
+ getCandidate(organisationId: string, id: string): Promise<ScenarioCandidate | null>;
72
+ listCandidates(filter: { organisationId: string; agentId?: string | null; limit?: number }): Promise<ScenarioCandidate[]>;
73
+ }
74
+ export interface FollowUp {
75
+ id: string; organisationId: string; userId: string | null; agentId: string; decisionId: string;
76
+ observableAt: string; question: string; status: 'scheduled' | 'done'; fingerprint: string;
77
+ createdAt: string; completedAt: string | null; outcomeRef: string | null;
78
+ }
79
+ export interface DueFollowUp {
80
+ followUp: FollowUp;
81
+ decision: { id: string; agentId: string; domain?: string; objective: string; expectedOutcome: DecisionRecord['expectedOutcome']; horizon: string };
82
+ }
83
+ export interface FollowUps {
84
+ /** Same decision, date and question: same follow-up (created: false). Another organisation's decision: not_found. */
85
+ scheduleFollowUp(input: { organisationId: string; userId?: string; decisionId: string; observableAt: string | Date; question: string; id?: string }): Promise<{ followUp: FollowUp; created: boolean }>;
86
+ /** Scheduled follow-ups whose date has come (`now` defaults to the clock), oldest first. */
87
+ dueFollowUps(input: { organisationId: string; userId?: string; now?: string | Date; limit?: number }): Promise<DueFollowUp[]>;
88
+ completeFollowUp(input: { organisationId: string; id: string; outcomeRef?: string }): Promise<{ followUp: FollowUp; completed: boolean }>;
89
+ listFollowUps(input: { organisationId: string; userId?: string; decisionId?: string; status?: 'scheduled' | 'done'; limit?: number }): Promise<FollowUp[]>;
90
+ eraseSubject(input: { organisationId: string; userId: string }): Promise<{ removed: number }>;
91
+ /** Pass it in createConscience({ erasers: [followUps.eraser] }) (or use followUpEraser(store) before the follow-ups exist). */
92
+ readonly eraser: (subject: { organisationId: string; userId: string }) => Promise<{ name: string; count: number }>;
93
+ }
94
+ export function createFollowUps(options: { governor: Governor; conscience: Conscience; store: VigilanceStore; masker: Masker; now?: () => number }): FollowUps;
95
+ export function followUpEraser(store: Pick<VigilanceStore, 'removeFollowUps'>): FollowUps['eraser'];
96
+ export const FOLLOW_UP_STATUSES: readonly ['scheduled', 'done'];
97
+
98
+ /* ---------- 26 · abstention ---------- */
99
+ export interface AbstentionOptions extends StatisticsOptions {
100
+ governor: Governor; organisationId: string; agentId: string; domain: string;
101
+ calibration?: CalibrationResult; findings?: ReflectionFinding[];
102
+ errorCosts?: Pick<ErrorCostPolicy, 'falsePositive' | 'falseNegative'>; errorCostPolicy?: Pick<ErrorCostPolicy, 'falsePositive' | 'falseNegative'>;
103
+ /** Threshold in force today (default: the prudent default). */
104
+ currentThreshold?: number; defaultThreshold?: number;
105
+ propose?: { proposedBy?: Actor; owner?: string; risk?: 'low' | 'medium' | 'high' | 'critical' };
106
+ }
107
+ export interface AbstentionPolicy {
108
+ organisationId: string; agentId: string; domain: string;
109
+ /** Computed threshold. Not in force until a human approves the proposal. */
110
+ threshold: number; effectiveThreshold: number;
111
+ basis: 'calibration_and_costs' | 'insufficient_data' | 'no_reliable_region'; status: 'computed' | 'prudent_default';
112
+ costRatio: number | null; sampleSize: number; minimumSample: number;
113
+ region: { from: number; sampleSize: number; rate: number; interval: Interval | null } | null;
114
+ reasons: string[]; belowThreshold: { recommendation: 'ask_clarification'; alternative: 'propose_verification' };
115
+ changeRequired: boolean; applied: false; proposal: ChangeProposal | null;
116
+ }
117
+ export function abstentionPolicy(options: AbstentionOptions): Promise<AbstentionPolicy>;
118
+ export function shouldAbstain(policy: Pick<AbstentionPolicy, 'effectiveThreshold'>, input: { confidence: number; actionKind?: string }): { abstain: boolean; threshold: number; recommendation: 'proceed' | 'ask_clarification' | 'propose_verification' };
119
+ export const ABSTENTION_DEFAULT_THRESHOLD: 0.8;
120
+
121
+ /* ---------- 27 and 03 · scenarios to review ---------- */
122
+ export type ScenarioCategory = 'injection' | 'ambiguity' | 'edge_case' | 'cross_organisation' | 'regression';
123
+ export type CandidateStatus = 'to_review' | 'approved' | 'declined' | 'rejected' | 'expired';
124
+ export interface ScenarioSpec {
125
+ question: string;
126
+ /** Simulated tools: fixed results, no effect on anything. */
127
+ tools: Array<{ name: string; returns: unknown }>;
128
+ expect: { tools: string[]; content: Array<string | { regex: string; flags: string }> };
129
+ forbiddenTools: string[]; forbiddenContent: string[];
130
+ }
131
+ export interface ScenarioCandidate {
132
+ id: string; organisationId: string; agentId: string | null; category: ScenarioCategory;
133
+ origin: Record<string, unknown>; source: 'template' | 'generator' | 'template_fallback' | 'lesson';
134
+ /** Starts as "to_review"; "approved" only when humans approved exactly this content at the governor. */
135
+ status: CandidateStatus; addedToTests: boolean; scenario: ScenarioSpec; fingerprint: string; proposalId: string | null; createdAt: string;
136
+ }
137
+ export interface ScenarioLibrary {
138
+ submit(candidates: ScenarioCandidate[], input: { organisationId: string; proposedBy?: Actor }): Promise<Array<{ candidate: ScenarioCandidate; created: boolean; proposal: ChangeProposal }>>;
139
+ list(input: { organisationId: string; agentId?: string | null; status?: CandidateStatus; limit?: number }): Promise<ScenarioCandidate[]>;
140
+ /** The only way into the test suite. */
141
+ approved(input: { organisationId: string; agentId?: string | null }): Promise<Array<{ candidate: ScenarioCandidate; scenario: EvaluateAgentScenario }>>;
142
+ toScenario(candidate: ScenarioCandidate): EvaluateAgentScenario;
143
+ }
144
+ export function createScenarioLibrary(options: { governor: Governor; store: VigilanceStore; masker: Masker; now?: () => number; targetKind?: 'instructions' | 'threshold' | 'tool_description' | 'routing' }): ScenarioLibrary;
145
+ export function scenarioToTestkit(candidate: ScenarioCandidate): EvaluateAgentScenario;
146
+
147
+ export interface FailureInput { id: string; agentId: string; domain?: string; question: string; organisationId?: string }
148
+ /** Injected generator: returns data only (a partial description), never code. */
149
+ export type AdversarialGenerator = (input: { category: ScenarioCategory; failure: Required<Omit<FailureInput, 'organisationId'>>; template: Partial<ScenarioSpec>; signal?: AbortSignal }) => Partial<Pick<ScenarioSpec, 'question' | 'tools' | 'forbiddenTools' | 'forbiddenContent'>> & { expect?: { tools?: string[]; content?: string[] } } | Promise<unknown>;
150
+ export function generateAdversarialCases(options: {
151
+ governor: Governor; organisationId: string; failures: FailureInput[]; masker: Masker; generator?: AdversarialGenerator;
152
+ categories?: Array<Exclude<ScenarioCategory, 'regression'>>; limit?: number; locale?: 'en' | 'fr'; library?: ScenarioLibrary; proposedBy?: Actor; now?: () => number; signal?: AbortSignal;
153
+ }): Promise<{ candidates: ScenarioCandidate[]; rejected: Array<{ failureId: string; category: string; reason: 'generator_invalid' | 'generator_error' }>; submitted: boolean }>;
154
+ export const ADVERSARIAL_CATEGORIES: readonly Exclude<ScenarioCategory, 'regression'>[];
155
+
156
+ export function lessonToScenario(lesson: { id: string; organisationId: string; status: string; agentId?: string | null; domain?: string | null; revisionId?: string; evidence: Array<{ kind: string; ref: string }> }, options: {
157
+ governor: Governor; masker: Masker; question: string; tools?: Array<{ name: string; returns?: unknown }>;
158
+ expect?: { tools?: string[]; content?: Array<string | RegExp> }; forbiddenTools?: string[]; forbiddenContent?: string[];
159
+ organisationId?: string; agentId?: string; library?: ScenarioLibrary; proposedBy?: Actor; now?: () => number;
160
+ }): Promise<ScenarioCandidate>;
161
+ export const SCENARIO_CATEGORIES: readonly ScenarioCategory[];
162
+ export const CANDIDATE_STATUSES: readonly CandidateStatus[];
163
+
164
+ /* ---------- 14 · multi-role review ---------- */
165
+ export type ReviewScope = 'observation' | 'agent' | 'domain' | 'organisation';
166
+ export interface ReviewedFinding { id: string; organisationId?: string; confidence: number; requestedScope?: ReviewScope; decisionIds?: string[]; evidence?: Array<{ kind: string; ref: string }>; [key: string]: unknown }
167
+ export interface RoleContext { organisationId: string; role: 'verifier' | 'contradictor' | 'riskController'; signal?: AbortSignal }
168
+ export interface ReviewRoles {
169
+ verifier(finding: Readonly<ReviewedFinding>, context: RoleContext): { evidence: Array<{ kind: 'decision' | 'prediction' | 'outcome' | 'correction' | 'external'; ref: string; organisationId?: string }> } | Promise<unknown>;
170
+ contradictor(finding: Readonly<ReviewedFinding>, context: RoleContext): { competing: Array<{ statement: string; strength: number }> } | Promise<unknown>;
171
+ riskController(finding: Readonly<ReviewedFinding>, context: RoleContext): { approved: boolean; maxScope: ReviewScope; reasons?: string[] } | Promise<unknown>;
172
+ }
173
+ export interface RoleReview { role: string; passed: boolean; blockers: string[]; error?: string; [key: string]: unknown }
174
+ export interface RoleReviewResult {
175
+ findingId: string; organisationId: string; advances: boolean; status: 'supported' | 'hypothesis'; blockers: string[];
176
+ reviews: { verifier: RoleReview; contradictor: RoleReview; riskController: RoleReview };
177
+ finding: ReviewedFinding & { status: 'supported' | 'hypothesis' }; recorded: unknown | null;
178
+ }
179
+ export function reviewByRoles(options: {
180
+ governor: Governor; organisationId: string; finding: ReviewedFinding; roles: ReviewRoles;
181
+ minimumIndependent?: number; evidenceExists?: (item: { kind: string; ref: string; organisationId: string }) => boolean | Promise<boolean>;
182
+ recordedBy?: Actor; runId?: string; signal?: AbortSignal;
183
+ }): Promise<RoleReviewResult>;
184
+ export const REVIEW_ROLES: readonly ['verifier', 'contradictor', 'riskController'];
185
+ export const REVIEW_SCOPES: readonly ReviewScope[];
186
+
187
+ /* ---------- stores ---------- */
188
+ export function createMemoryVigilanceStore(): VigilanceStore;
189
+ export function createPostgresVigilanceStore(db: { query(sql: string, params?: unknown[]): Promise<{ rows: any[]; rowCount?: number | null }> }, options?: { prefix?: string }): VigilanceStore;
190
+ export function postgresVigilanceSchema(options?: { prefix?: string }): string;
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+ /* P3, second half: vigilance (17 drift, 18 follow-ups, 26 abstention, 27 night adversary, 14 multi-role review, 03 lesson turned into a test). */
3
+ const drift = require('./drift');
4
+ const followups = require('./followups');
5
+ const abstention = require('./abstention');
6
+ const adversary = require('./adversary');
7
+ const roles = require('./roles');
8
+ const lessonTests = require('./lessonTests');
9
+ const library = require('./library');
10
+ const store = require('./store');
11
+
12
+ module.exports = {
13
+ detectDrift: drift.detectDrift, snapshotWindow: drift.snapshotWindow, populationStabilityIndex: drift.populationStabilityIndex,
14
+ differenceInterval: drift.differenceInterval, DRIFT_RECOMMENDATIONS: drift.DRIFT_RECOMMENDATIONS,
15
+ createFollowUps: followups.createFollowUps, followUpEraser: followups.followUpEraser, FOLLOW_UP_STATUSES: followups.FOLLOW_UP_STATUSES,
16
+ abstentionPolicy: abstention.abstentionPolicy, shouldAbstain: abstention.shouldAbstain, ABSTENTION_DEFAULT_THRESHOLD: abstention.ABSTENTION_DEFAULT_THRESHOLD,
17
+ generateAdversarialCases: adversary.generateAdversarialCases, ADVERSARIAL_CATEGORIES: adversary.ADVERSARIAL_CATEGORIES,
18
+ reviewByRoles: roles.reviewByRoles, REVIEW_ROLES: roles.REVIEW_ROLES, REVIEW_SCOPES: roles.REVIEW_SCOPES,
19
+ lessonToScenario: lessonTests.lessonToScenario,
20
+ createScenarioLibrary: library.createScenarioLibrary, scenarioToTestkit: library.toScenario,
21
+ SCENARIO_CATEGORIES: library.SCENARIO_CATEGORIES, CANDIDATE_STATUSES: library.CANDIDATE_STATUSES,
22
+ createMemoryVigilanceStore: store.createMemoryVigilanceStore, createPostgresVigilanceStore: store.createPostgresVigilanceStore, postgresVigilanceSchema: store.postgresVigilanceSchema
23
+ };