@unblocklabs/unblock-memory 0.13.0 → 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.
- package/defaults.json +162 -0
- package/dist/src/cluster-review.js +6 -5
- package/dist/src/config.js +33 -30
- package/dist/src/decision-client.d.ts +8 -2
- package/dist/src/decision-client.js +22 -9
- package/dist/src/decision-ranking.js +2 -1
- package/dist/src/decision-review.js +8 -7
- package/dist/src/defaults.d.ts +8 -0
- package/dist/src/defaults.js +128 -0
- package/dist/src/emotion-baselines.js +3 -2
- package/dist/src/evidence-review.js +7 -4
- package/dist/src/extraction-chunk.js +2 -1
- package/dist/src/extraction-config.js +4 -2
- package/dist/src/extraction-model.d.ts +23 -17
- package/dist/src/extraction-model.js +164 -61
- package/dist/src/extraction-runtime.js +5 -4
- package/dist/src/extraction-source.js +2 -1
- package/dist/src/extraction-store.d.ts +1 -0
- package/dist/src/extraction-store.js +4 -2
- package/dist/src/extraction-worker.d.ts +2 -3
- package/dist/src/extraction-worker.js +12 -10
- package/dist/src/inside-out-runtime.js +2 -1
- package/dist/src/inside-out-sources.js +2 -1
- package/dist/src/inside-out-store.js +3 -2
- package/dist/src/inside-out.js +5 -2
- package/dist/src/manager.js +5 -4
- package/dist/src/memory-database.js +3 -2
- package/dist/src/memory-passage.d.ts +2 -2
- package/dist/src/memory-passage.js +3 -2
- package/dist/src/memory-whisperer.js +16 -8
- package/dist/src/my-turn.js +5 -4
- package/dist/src/people-background.d.ts +1 -1
- package/dist/src/people-background.js +2 -1
- package/dist/src/people-dossier-review.js +4 -3
- package/dist/src/people-learning-cron.js +2 -1
- package/dist/src/people-learning-inventory.js +2 -1
- package/dist/src/people-primer-tool.js +5 -4
- package/dist/src/people-primer.js +5 -4
- package/dist/src/people-store.js +2 -1
- package/dist/src/people-tools.js +2 -1
- package/dist/src/plugin.js +3 -2
- package/dist/src/quality-audit.js +3 -2
- package/dist/src/quality-triage.js +4 -3
- package/dist/src/query-generator.js +5 -2
- package/dist/src/response-audit.js +3 -2
- package/dist/src/response-config.js +3 -1
- package/dist/src/response-episodes.js +3 -2
- package/dist/src/response-identity.js +2 -1
- package/dist/src/response-memory.js +2 -1
- package/dist/src/response-outcome.js +9 -8
- package/dist/src/response-reviews.js +3 -2
- package/dist/src/response-runtime.js +2 -1
- package/dist/src/response-store.js +26 -25
- package/dist/src/review-tools.js +4 -3
- package/dist/src/runtime.js +2 -1
- package/dist/src/safety-config.js +3 -2
- package/dist/src/safety-whisperer.js +3 -3
- package/dist/src/session-sync.js +2 -1
- package/dist/src/skill-whisperer.d.ts +1 -1
- package/dist/src/skill-whisperer.js +4 -3
- package/dist/src/slack-directory.js +3 -2
- package/dist/src/training-gate.d.ts +2 -2
- package/dist/src/training-gate.js +3 -2
- package/dist/src/training-input.js +4 -3
- package/dist/src/training-judge.js +2 -1
- package/dist/src/training-models.d.ts +1 -1
- package/dist/src/training-models.js +9 -7
- package/dist/src/training-queries.d.ts +1 -1
- package/dist/src/training-queries.js +4 -3
- package/dist/src/training-retrieval.d.ts +3 -3
- package/dist/src/training-retrieval.js +4 -3
- package/dist/src/training-store.js +3 -2
- package/dist/src/training.js +2 -1
- package/dist/src/whisperer-context.d.ts +1 -2
- package/dist/src/whisperer-context.js +2 -2
- package/docs/configuration.md +7 -1
- package/docs/extraction.md +25 -36
- package/docs/retrieval.md +3 -10
- package/openclaw.plugin.json +42 -55
- package/package.json +5 -3
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULTS } from "./defaults.js";
|
|
1
2
|
// Reporting/composition changes do not require paid re-inference of the same rubric.
|
|
2
3
|
export const RESPONSE_REPORT_VERSION = "response-report-v4";
|
|
3
4
|
/** Compose observed evidence, not a factual-verification or causal agent grade.
|
|
@@ -11,16 +12,16 @@ export function responseOutcome(result) {
|
|
|
11
12
|
reasons.push(reason);
|
|
12
13
|
reasonDetails.push({ reason, strength, measure, source });
|
|
13
14
|
};
|
|
14
|
-
if (result.quality.underdelivery.noul >=
|
|
15
|
+
if (result.quality.underdelivery.noul >= DEFAULTS.responseAudit.scoreHigh) {
|
|
15
16
|
basis.push("visible_underdelivery");
|
|
16
17
|
const reason = result.quality.failureReason;
|
|
17
|
-
if (reason.confidence >=
|
|
18
|
+
if (reason.confidence >= DEFAULTS.responseAudit.scoreHigh && reason.choice !== "none_or_unclear")
|
|
18
19
|
addReason(reason.choice, reason.confidence, "visible_quality");
|
|
19
20
|
}
|
|
20
21
|
if (later) {
|
|
21
|
-
const correction = later.correction.noul >=
|
|
22
|
-
const delivery = later.deliveryAdmission.noul >=
|
|
23
|
-
const regression = later.regression.noul >=
|
|
22
|
+
const correction = later.correction.noul >= DEFAULTS.responseAudit.scoreHigh;
|
|
23
|
+
const delivery = later.deliveryAdmission.noul >= DEFAULTS.responseAudit.scoreHigh;
|
|
24
|
+
const regression = later.regression.noul >= DEFAULTS.responseAudit.scoreHigh;
|
|
24
25
|
if (correction)
|
|
25
26
|
basis.push("later_correction");
|
|
26
27
|
if (delivery) {
|
|
@@ -31,20 +32,20 @@ export function responseOutcome(result) {
|
|
|
31
32
|
basis.push("regression_admission");
|
|
32
33
|
addReason("regression", later.regression.noul, "regression_admission", "yes_probability");
|
|
33
34
|
}
|
|
34
|
-
const reported = later.outcome.confidence >=
|
|
35
|
+
const reported = later.outcome.confidence >= DEFAULTS.responseAudit.scoreHigh && later.outcome.choice === "reported_shortfall" && later.scopeClarification.noul <= DEFAULTS.responseAudit.scoreLow;
|
|
35
36
|
if (reported)
|
|
36
37
|
basis.push("reported_shortfall");
|
|
37
38
|
// A narrow admission can establish the shortfall even when the broad outcome
|
|
38
39
|
// abstains. Its independently confident reason is still useful, not overridden
|
|
39
40
|
// by a hard-coded assumption that every correction means incorrect_claim.
|
|
40
|
-
if ((correction || delivery || regression || reported) && later.reason.confidence >=
|
|
41
|
+
if ((correction || delivery || regression || reported) && later.reason.confidence >= DEFAULTS.responseAudit.scoreHigh && later.reason.choice !== "none_or_unclear") {
|
|
41
42
|
addReason(later.reason.choice, later.reason.confidence, "retrospective_reason");
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
if (basis.length)
|
|
45
46
|
return { status: "reported_shortfall", basis, reasons: [...new Set(reasons)], reasonDetails,
|
|
46
47
|
reasonStatus: reasonDetails.length ? "classified" : "uncertain" };
|
|
47
|
-
if (later?.outcome.choice === "acknowledged_success" && later.outcome.confidence >=
|
|
48
|
+
if (later?.outcome.choice === "acknowledged_success" && later.outcome.confidence >= DEFAULTS.responseAudit.scoreHigh) {
|
|
48
49
|
return { status: "acknowledged_success", basis: ["human_acknowledgment"], reasons: [], reasonDetails: [], reasonStatus: "not_applicable" };
|
|
49
50
|
}
|
|
50
51
|
return { status: "unknown", basis: [], reasons: [], reasonDetails: [], reasonStatus: "not_applicable" };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULTS } from "./defaults.js";
|
|
1
2
|
import { randomUUID } from "node:crypto";
|
|
2
3
|
import { responseOutcome } from "./response-outcome.js";
|
|
3
4
|
import { immediateTransaction } from "./memory-database.js";
|
|
@@ -54,8 +55,8 @@ export class ResponseReviews {
|
|
|
54
55
|
const agentProbability = agentDirected.reduce((sum, key) => sum + f.target.probabilities[key], 0);
|
|
55
56
|
const signals = [
|
|
56
57
|
...(outcome.status === "reported_shortfall" ? [{ family: "delivery_quality", detail: outcome }] : []),
|
|
57
|
-
...(intensity && intensity.probabilities["2"] + intensity.probabilities["3"] >=
|
|
58
|
-
((f.annoyance?.noul ?? 0) >=
|
|
58
|
+
...(intensity && intensity.probabilities["2"] + intensity.probabilities["3"] >= DEFAULTS.responseAudit.scoreHigh && agentProbability >= DEFAULTS.responseAudit.scoreHigh &&
|
|
59
|
+
((f.annoyance?.noul ?? 0) >= DEFAULTS.responseAudit.scoreHigh || (f.frustration?.noul ?? 0) >= DEFAULTS.responseAudit.scoreHigh) ?
|
|
59
60
|
[{ family: "human_experience", detail: { target: f.target, sentiment: f.sentiment, annoyance: f.annoyance,
|
|
60
61
|
frustration: f.frustration, intensity } }] : []),
|
|
61
62
|
];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULTS } from "./defaults.js";
|
|
1
2
|
import { hasMemoryTable, MEMORY_DATABASE } from "./memory-database.js";
|
|
2
3
|
import { join } from "node:path";
|
|
3
4
|
import { resolveAgentWorkspaceDir } from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
|
|
@@ -130,7 +131,7 @@ export function registerResponseAudit(api, config) {
|
|
|
130
131
|
clearInterval(timer);
|
|
131
132
|
lifetime = new AbortController();
|
|
132
133
|
// A minute poll honors durable due times without relying on process uptime.
|
|
133
|
-
timer = setInterval(tick,
|
|
134
|
+
timer = setInterval(tick, DEFAULTS.responseAudit.pollIntervalMs);
|
|
134
135
|
timer.unref();
|
|
135
136
|
tick(); // New schedules wait one interval; overdue schedules get one bounded attempt.
|
|
136
137
|
});
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { DEFAULTS } from "./defaults.js";
|
|
1
2
|
import { randomUUID } from "node:crypto";
|
|
2
3
|
import { immediateTransaction, openMemoryDatabase } from "./memory-database.js";
|
|
3
4
|
import { validateCachedStage } from "./response-judge.js";
|
|
4
5
|
import { responseOutcome, RESPONSE_REPORT_VERSION } from "./response-outcome.js";
|
|
5
6
|
import { ResponsePeople } from "./response-identity.js";
|
|
6
7
|
import { ResponseReviews, RESPONSE_REVIEW_POLICY } from "./response-reviews.js";
|
|
7
|
-
const MAX_RETRY_ATTEMPTS =
|
|
8
|
-
const RETRY_BACKOFF_MS =
|
|
8
|
+
const MAX_RETRY_ATTEMPTS = DEFAULTS.responseAudit.maxRetries;
|
|
9
|
+
const RETRY_BACKOFF_MS = DEFAULTS.responseAudit.retryBackoffMs;
|
|
9
10
|
/** Operator-only tables: not a memory corpus and never injected into agent prompts. */
|
|
10
11
|
export class ResponseAuditStore {
|
|
11
12
|
#db;
|
|
@@ -64,7 +65,7 @@ export class ResponseAuditStore {
|
|
|
64
65
|
const token = randomUUID();
|
|
65
66
|
const result = this.#db.prepare(`INSERT INTO response_lease VALUES(1,?,?)
|
|
66
67
|
ON CONFLICT(id) DO UPDATE SET token=excluded.token,expires=excluded.expires WHERE response_lease.expires < ?`)
|
|
67
|
-
.run(token, now +
|
|
68
|
+
.run(token, now + DEFAULTS.responseAudit.leaseMs, now);
|
|
68
69
|
return result.changes ? token : undefined;
|
|
69
70
|
}
|
|
70
71
|
release(token) { this.#db.prepare("DELETE FROM response_lease WHERE token=?").run(token); }
|
|
@@ -271,7 +272,7 @@ export class ResponseAuditStore {
|
|
|
271
272
|
if (bucket === "week")
|
|
272
273
|
date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 6) % 7);
|
|
273
274
|
const week = date.toISOString().slice(0, 10);
|
|
274
|
-
const taskType = r.quality.taskType.confidence >=
|
|
275
|
+
const taskType = r.quality.taskType.confidence >= DEFAULTS.responseAudit.scoreHigh ? r.quality.taskType.choice : "uncertain";
|
|
275
276
|
const human = r.human ?? null;
|
|
276
277
|
const key = JSON.stringify([week, taskType, r.agentModel, human?.key ?? null]);
|
|
277
278
|
const g = groups.get(key) ?? createReportGroup(week, human, taskType, r.agentModel);
|
|
@@ -321,32 +322,32 @@ function createReportGroup(week, human, taskType, agentModel) {
|
|
|
321
322
|
}
|
|
322
323
|
function recordEpisodeInGroup(g, r) {
|
|
323
324
|
g.evaluated++;
|
|
324
|
-
const underdelivery = r.quality.underdelivery.noul >=
|
|
325
|
-
if (r.quality.underdelivery.noul <=
|
|
325
|
+
const underdelivery = r.quality.underdelivery.noul >= DEFAULTS.responseAudit.scoreHigh;
|
|
326
|
+
if (r.quality.underdelivery.noul <= DEFAULTS.responseAudit.scoreLow || underdelivery)
|
|
326
327
|
g.underdeliveryCertain++;
|
|
327
328
|
if (underdelivery) {
|
|
328
329
|
g.underdelivery++;
|
|
329
|
-
const reason = r.quality.failureReason.confidence >=
|
|
330
|
+
const reason = r.quality.failureReason.confidence >= DEFAULTS.responseAudit.scoreHigh ? r.quality.failureReason.choice : "uncertain";
|
|
330
331
|
g.failureReasons[reason] = (g.failureReasons[reason] ?? 0) + 1;
|
|
331
332
|
}
|
|
332
|
-
if (r.quality.assessability.choice === "assessable" && r.quality.assessability.confidence >=
|
|
333
|
+
if (r.quality.assessability.choice === "assessable" && r.quality.assessability.confidence >= DEFAULTS.responseAudit.scoreHigh) {
|
|
333
334
|
g.assessable++;
|
|
334
|
-
if (r.quality.fulfillment.confidence >=
|
|
335
|
+
if (r.quality.fulfillment.confidence >= DEFAULTS.responseAudit.scoreHigh) {
|
|
335
336
|
g.fulfillmentScored++;
|
|
336
337
|
g.fulfillmentSum += r.quality.fulfillment.score;
|
|
337
338
|
}
|
|
338
339
|
}
|
|
339
|
-
if (r.quality.fitAssessability.choice === "assessable" && r.quality.fitAssessability.confidence >=
|
|
340
|
+
if (r.quality.fitAssessability.choice === "assessable" && r.quality.fitAssessability.confidence >= DEFAULTS.responseAudit.scoreHigh) {
|
|
340
341
|
g.fitAssessable++;
|
|
341
|
-
if (r.quality.deliverableFit.confidence >=
|
|
342
|
+
if (r.quality.deliverableFit.confidence >= DEFAULTS.responseAudit.scoreHigh) {
|
|
342
343
|
g.deliverableFitScored++;
|
|
343
344
|
g.deliverableSum += r.quality.deliverableFit.score;
|
|
344
345
|
}
|
|
345
346
|
}
|
|
346
|
-
const target = r.feedback.target.confidence >=
|
|
347
|
+
const target = r.feedback.target.confidence >= DEFAULTS.responseAudit.scoreHigh ? r.feedback.target.choice : "uncertain";
|
|
347
348
|
g.feedbackTargets[target] = (g.feedbackTargets[target] ?? 0) + 1;
|
|
348
|
-
const laterCorrection = (r.retrospective.judgment?.correction.noul ?? 0) >=
|
|
349
|
-
const deliveryAdmission = (r.retrospective.judgment?.deliveryAdmission.noul ?? 0) >=
|
|
349
|
+
const laterCorrection = (r.retrospective.judgment?.correction.noul ?? 0) >= DEFAULTS.responseAudit.scoreHigh;
|
|
350
|
+
const deliveryAdmission = (r.retrospective.judgment?.deliveryAdmission.noul ?? 0) >= DEFAULTS.responseAudit.scoreHigh;
|
|
350
351
|
const outcome = responseOutcome(r);
|
|
351
352
|
const reportedShortfall = outcome.status === "reported_shortfall";
|
|
352
353
|
if (reportedShortfall || outcome.status === "acknowledged_success") {
|
|
@@ -366,40 +367,40 @@ function recordEpisodeInGroup(g, r) {
|
|
|
366
367
|
g.laterCorrections++;
|
|
367
368
|
if (deliveryAdmission)
|
|
368
369
|
g.deliveryAdmissions++;
|
|
369
|
-
if (r.feedback.feedbackType.confidence >=
|
|
370
|
+
if (r.feedback.feedbackType.confidence >= DEFAULTS.responseAudit.scoreHigh) {
|
|
370
371
|
g.feedbackCertain++;
|
|
371
372
|
if (r.feedback.feedbackType.choice === "acceptance")
|
|
372
373
|
g.accepted++;
|
|
373
374
|
}
|
|
374
375
|
const burden = r.feedback.avoidableRework.noul;
|
|
375
|
-
if (burden <=
|
|
376
|
+
if (burden <= DEFAULTS.responseAudit.scoreLow || burden >= DEFAULTS.responseAudit.scoreHigh) {
|
|
376
377
|
g.reworkCertain++;
|
|
377
|
-
if (burden >=
|
|
378
|
+
if (burden >= DEFAULTS.responseAudit.scoreHigh)
|
|
378
379
|
g.rework++;
|
|
379
380
|
}
|
|
380
|
-
const memoryGap = r.feedback.memoryGap.noul >=
|
|
381
|
+
const memoryGap = r.feedback.memoryGap.noul >= DEFAULTS.responseAudit.scoreHigh;
|
|
381
382
|
const sentiment = r.feedback.sentiment;
|
|
382
|
-
const sentimentCertain = !!sentiment && sentiment.confidence >=
|
|
383
|
+
const sentimentCertain = !!sentiment && sentiment.confidence >= DEFAULTS.responseAudit.scoreHigh && sentiment.choice !== "unclear";
|
|
383
384
|
const dissatisfied = sentimentCertain && ["dissatisfied", "mixed"].includes(sentiment.choice);
|
|
384
385
|
if (sentiment)
|
|
385
386
|
g.sentimentAssessed++;
|
|
386
387
|
if (sentimentCertain)
|
|
387
388
|
g.sentimentCertain++;
|
|
388
389
|
const { annoyance, frustration, dissatisfactionIntensity: intensity } = r.feedback;
|
|
389
|
-
const annoyed = !!annoyance && annoyance.noul >=
|
|
390
|
-
const frustrated = !!frustration && frustration.noul >=
|
|
390
|
+
const annoyed = !!annoyance && annoyance.noul >= DEFAULTS.responseAudit.scoreHigh;
|
|
391
|
+
const frustrated = !!frustration && frustration.noul >= DEFAULTS.responseAudit.scoreHigh;
|
|
391
392
|
if (annoyance && frustration) {
|
|
392
393
|
g.emotionAssessed++;
|
|
393
394
|
if (annoyed)
|
|
394
395
|
g.annoyed++;
|
|
395
396
|
if (frustrated)
|
|
396
397
|
g.frustrated++;
|
|
397
|
-
if (annoyance.noul >
|
|
398
|
+
if (annoyance.noul > DEFAULTS.responseAudit.scoreLow && annoyance.noul < DEFAULTS.responseAudit.scoreHigh)
|
|
398
399
|
g.annoyanceUncertain++;
|
|
399
|
-
if (frustration.noul >
|
|
400
|
+
if (frustration.noul > DEFAULTS.responseAudit.scoreLow && frustration.noul < DEFAULTS.responseAudit.scoreHigh)
|
|
400
401
|
g.frustrationUncertain++;
|
|
401
402
|
}
|
|
402
|
-
if (intensity && intensity.confidence >=
|
|
403
|
+
if (intensity && intensity.confidence >= DEFAULTS.responseAudit.scoreHigh) {
|
|
403
404
|
g.dissatisfactionIntensityScored++;
|
|
404
405
|
g.intensitySum += intensity.score;
|
|
405
406
|
}
|
|
@@ -407,7 +408,7 @@ function recordEpisodeInGroup(g, r) {
|
|
|
407
408
|
g.memoryGap++;
|
|
408
409
|
if (dissatisfied)
|
|
409
410
|
g.dissatisfied++;
|
|
410
|
-
const signals = [underdelivery ? "clear_underdelivery" : "", burden >=
|
|
411
|
+
const signals = [underdelivery ? "clear_underdelivery" : "", burden >= DEFAULTS.responseAudit.scoreHigh ? "avoidable_rework" : "", memoryGap ? "reported_memory_gap" : "", dissatisfied ? `dissatisfied:${target}` : "",
|
|
411
412
|
annoyed ? `annoyed:${target}` : "", frustrated ? `frustrated:${target}` : "",
|
|
412
413
|
laterCorrection ? "later_correction" : "", deliveryAdmission ? "delivery_admission" : "", reportedShortfall ? "reported_shortfall" : ""].filter(Boolean);
|
|
413
414
|
return { signals, outcome };
|
package/dist/src/review-tools.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULTS } from "./defaults.js";
|
|
1
2
|
import { Type } from "typebox";
|
|
2
3
|
import { Value } from "typebox/value";
|
|
3
4
|
import { jsonResult } from "openclaw/plugin-sdk/agent-runtime";
|
|
@@ -6,17 +7,17 @@ import { resolveDecisionCredential } from "./decision-client.js";
|
|
|
6
7
|
import { safetyStatus } from "./safety-whisperer.js";
|
|
7
8
|
import { abortable } from "./abortable.js";
|
|
8
9
|
const claimParameters = Type.Object({
|
|
9
|
-
claim: Type.String({ pattern: "\\S", maxLength:
|
|
10
|
+
claim: Type.String({ pattern: "\\S", maxLength: DEFAULTS.review.maxClaimChars }),
|
|
10
11
|
citations: Type.Array(Type.Object({
|
|
11
12
|
path: Type.String({ pattern: "^qmd://", maxLength: 2000 }),
|
|
12
|
-
from: Type.Integer({ minimum: 1 }), lines: Type.Integer({ minimum: 1, maximum:
|
|
13
|
+
from: Type.Integer({ minimum: 1 }), lines: Type.Integer({ minimum: 1, maximum: DEFAULTS.review.maxCitationLines }),
|
|
13
14
|
}, { additionalProperties: false }), { minItems: 1, maxItems: 3 }),
|
|
14
15
|
}, { additionalProperties: false });
|
|
15
16
|
const clusterParameters = Type.Object({ clusterId: Type.String({ pattern: "^[0-9a-f]{10}$" }) }, { additionalProperties: false });
|
|
16
17
|
const noParameters = Type.Object({}, { additionalProperties: false });
|
|
17
18
|
/** Bound initialization as well as inference, without cancelling shared managers. */
|
|
18
19
|
export async function reviewRequestContext(runtime, active, decisionModel, signal) {
|
|
19
|
-
const deadline = AbortSignal.timeout(
|
|
20
|
+
const deadline = AbortSignal.timeout(DEFAULTS.review.toolTimeoutMs);
|
|
20
21
|
const combined = signal ? AbortSignal.any([signal, deadline]) : deadline;
|
|
21
22
|
const apiKey = await abortable(resolveDecisionCredential(decisionModel), combined);
|
|
22
23
|
if (!apiKey)
|
package/dist/src/runtime.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULTS } from "./defaults.js";
|
|
1
2
|
import { randomUUID } from "node:crypto";
|
|
2
3
|
import { closeSync, constants, fchmodSync, lstatSync, openSync, readFileSync } from "node:fs";
|
|
3
4
|
import fs from "node:fs/promises";
|
|
@@ -15,7 +16,7 @@ import { agentStateDir, agentTranscriptDatabase } from "./agent-paths.js";
|
|
|
15
16
|
const SESSION_SYNC_LOCK_FILE = "session-sync.lock.sqlite";
|
|
16
17
|
const LEGACY_SESSION_SYNC_LOCK_FILE = "session-sync.lock";
|
|
17
18
|
const SESSION_SYNC_STATUS_FILE = "session-sync-status.json";
|
|
18
|
-
const LEASE_BUSY_TIMEOUT_MS =
|
|
19
|
+
const LEASE_BUSY_TIMEOUT_MS = DEFAULTS.sqlite.mainBusyTimeoutMs;
|
|
19
20
|
const MAX_LEASE_BUSY_RETRIES = 6;
|
|
20
21
|
const heldSessionSyncLeaseTokens = new Set();
|
|
21
22
|
const LEASE_SCHEMA_SQL = `
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { DEFAULTS } from "./defaults.js";
|
|
1
2
|
import { normalizeAgentIdStrict } from "openclaw/plugin-sdk/routing";
|
|
2
|
-
const DEFAULT_SAFETY_MIN_PROBABILITY =
|
|
3
|
+
const DEFAULT_SAFETY_MIN_PROBABILITY = DEFAULTS.safetyWhisperer.defaultMinProbability;
|
|
3
4
|
const MAX_SCENARIOS = 20;
|
|
4
5
|
const MAX_TEXT_CHARS = 2000;
|
|
5
6
|
const MAX_ENTRIES = 500;
|
|
@@ -86,7 +87,7 @@ function scenario(value, index) {
|
|
|
86
87
|
};
|
|
87
88
|
}
|
|
88
89
|
export function resolveSafetyWhisperer(value) {
|
|
89
|
-
const defaults = { enabled: false, historyMessages:
|
|
90
|
+
const defaults = { enabled: false, historyMessages: DEFAULTS.safetyWhisperer.defaultHistoryMessages, timeoutMs: DEFAULTS.safetyWhisperer.defaultTimeoutMs, excludedChannels: [], scenarios: [] };
|
|
90
91
|
if (value === undefined)
|
|
91
92
|
return defaults;
|
|
92
93
|
const config = record(value, "safetyWhisperer");
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { DEFAULTS } from "./defaults.js";
|
|
1
2
|
import { Value } from "typebox/value";
|
|
2
3
|
import { estimateDecisionTokens, isDecisionTimeout, requestDecision, resolveDecisionCredential, NOUL_SCHEMA, DecisionRequestError } from "./decision-client.js";
|
|
3
|
-
import {
|
|
4
|
+
import { messageText, takeRecentWithinTokens } from "./whisperer-context.js";
|
|
4
5
|
import { CONVERSATION_INFO, conversationEnvelope, conversationUserText } from "./response-text.js";
|
|
5
6
|
import { SKILL_WHISPERER_TIMEOUT_MS } from "./skill-whisperer.js";
|
|
6
7
|
import { abortable } from "./abortable.js";
|
|
7
8
|
import { nonBlank, record } from "./guards.js";
|
|
8
|
-
const MAX_SESSIONS =
|
|
9
|
-
const RUNS_PER_SESSION = 4;
|
|
9
|
+
const { stateMaxTokens: MAX_STATE_TOKENS, maxTrackedSessions: MAX_SESSIONS, maxRunsPerSession: RUNS_PER_SESSION } = DEFAULTS.safetyWhisperer;
|
|
10
10
|
class SafetyInputError extends Error {
|
|
11
11
|
}
|
|
12
12
|
/** Thread replies and forum topics belong to their parent conversation (`C1:thread:1712.01`, `-100:topic:5`). */
|
package/dist/src/session-sync.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULTS } from "./defaults.js";
|
|
1
2
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
3
|
import { existsSync, lstatSync, readFileSync, statSync } from "node:fs";
|
|
3
4
|
import { chmod, mkdir, readFile, rename, unlink, utimes, writeFile } from "node:fs/promises";
|
|
@@ -99,7 +100,7 @@ function assertSchema(db, expectedAgentId) {
|
|
|
99
100
|
function readSnapshot(params) {
|
|
100
101
|
const db = new DatabaseSync(params.databasePath, { readOnly: true });
|
|
101
102
|
try {
|
|
102
|
-
db.exec(
|
|
103
|
+
db.exec(`PRAGMA query_only = ON; PRAGMA busy_timeout = ${DEFAULTS.sqlite.mainBusyTimeoutMs}; BEGIN`);
|
|
103
104
|
assertSchema(db, params.agentId);
|
|
104
105
|
const transcripts = new AgentTranscriptReader(db, params.agentId);
|
|
105
106
|
const placeholders = params.chatTypes.map(() => "?").join(", ");
|
|
@@ -2,7 +2,7 @@ import type { OpenClawConfig, OpenClawPluginApi } from "openclaw/plugin-sdk/plug
|
|
|
2
2
|
import type { UnblockMemoryConfig } from "./config.js";
|
|
3
3
|
import type { SkillSearchCandidate } from "./manager.js";
|
|
4
4
|
import type { WhispererDiagnostics } from "./diagnostics.js";
|
|
5
|
-
export declare const SKILL_WHISPERER_TIMEOUT_MS
|
|
5
|
+
export declare const SKILL_WHISPERER_TIMEOUT_MS: number;
|
|
6
6
|
type SkillWhispererRuntime = {
|
|
7
7
|
searchSkills(params: {
|
|
8
8
|
cfg: OpenClawConfig;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { DEFAULTS } from "./defaults.js";
|
|
1
2
|
import { basename } from "node:path";
|
|
2
3
|
import { selectSkill } from "./decision-ranking.js";
|
|
3
4
|
import { isDecisionTimeout, resolveDecisionCredential, DecisionRequestError } from "./decision-client.js";
|
|
4
5
|
import { buildSkillWhispererQuery, MAX_SKILL_QUERY_CHARS, recentSkillMessages } from "./whisperer-context.js";
|
|
5
6
|
import { abortable } from "./abortable.js";
|
|
6
7
|
import { isRecord } from "./guards.js";
|
|
7
|
-
const CANDIDATE_LIMIT =
|
|
8
|
-
const JUDGE_CANDIDATE_LIMIT =
|
|
8
|
+
const CANDIDATE_LIMIT = DEFAULTS.skillWhisperer.maxCandidates;
|
|
9
|
+
const JUDGE_CANDIDATE_LIMIT = DEFAULTS.skillWhisperer.maxParallelJudges;
|
|
9
10
|
const MAX_SESSIONS = 1_000;
|
|
10
11
|
const MAX_SEEN_RUNS = 64;
|
|
11
|
-
export const SKILL_WHISPERER_TIMEOUT_MS =
|
|
12
|
+
export const SKILL_WHISPERER_TIMEOUT_MS = DEFAULTS.skillWhisperer.timeoutMs;
|
|
12
13
|
function decisionConversation(prompt, messages) {
|
|
13
14
|
const currentRequest = prompt.trim().slice(-MAX_SKILL_QUERY_CHARS);
|
|
14
15
|
let remaining = MAX_SKILL_QUERY_CHARS - currentRequest.length;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULTS } from "./defaults.js";
|
|
1
2
|
import { inspectReadOnlyChannelAccount } from "openclaw/plugin-sdk/directory-runtime";
|
|
2
3
|
import { record } from "./guards.js";
|
|
3
4
|
function text(value, maxLength) {
|
|
@@ -43,13 +44,13 @@ export function createOpenClawSlackDirectory(params) {
|
|
|
43
44
|
const cursors = new Set();
|
|
44
45
|
let cursor;
|
|
45
46
|
while (entries.length < limit) {
|
|
46
|
-
const url = new URL(
|
|
47
|
+
const url = new URL(DEFAULTS.people.slackApiUrl);
|
|
47
48
|
url.searchParams.set("limit", String(Math.min(limit, 200)));
|
|
48
49
|
if (cursor)
|
|
49
50
|
url.searchParams.set("cursor", cursor);
|
|
50
51
|
const response = await request(url, {
|
|
51
52
|
headers: { authorization: `Bearer ${token}` },
|
|
52
|
-
signal: AbortSignal.timeout(
|
|
53
|
+
signal: AbortSignal.timeout(DEFAULTS.people.slackTimeoutMs),
|
|
53
54
|
});
|
|
54
55
|
const payload = record(await response.json());
|
|
55
56
|
if (!response.ok || payload?.ok !== true) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TrainingInput } from "./training-input.js";
|
|
2
2
|
export declare const TRAINING_GATE_VERSION = "historical-recall-v2";
|
|
3
|
-
export declare const TRAINING_GATE_MODEL
|
|
4
|
-
export declare const TRAINING_GATE_THRESHOLD
|
|
3
|
+
export declare const TRAINING_GATE_MODEL: string;
|
|
4
|
+
export declare const TRAINING_GATE_THRESHOLD: number;
|
|
5
5
|
export declare const TRAINING_GATE_QUESTIONS: {
|
|
6
6
|
readonly recall_needed: import("@unblocklabs/decisions").NoulQuestion;
|
|
7
7
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { DEFAULTS } from "./defaults.js";
|
|
1
2
|
import { DecisionError, noul } from "@unblocklabs/decisions";
|
|
2
3
|
import { decideWithModel, DEFAULT_DECISION_MODEL } from "./decision-client.js";
|
|
3
4
|
export const TRAINING_GATE_VERSION = "historical-recall-v2";
|
|
4
5
|
export const TRAINING_GATE_MODEL = DEFAULT_DECISION_MODEL;
|
|
5
|
-
export const TRAINING_GATE_THRESHOLD =
|
|
6
|
+
export const TRAINING_GATE_THRESHOLD = DEFAULTS.training.gateThreshold;
|
|
6
7
|
export const TRAINING_GATE_QUESTIONS = {
|
|
7
8
|
recall_needed: noul({
|
|
8
9
|
question: "Would additional historical memory, beyond the supplied conversation, materially help answer `currentRequest`?",
|
|
@@ -24,7 +25,7 @@ export const TRAINING_GATE_QUESTIONS = {
|
|
|
24
25
|
};
|
|
25
26
|
export async function judgeTrainingInput(input, apiKey, signal, options) {
|
|
26
27
|
const expectedModel = options?.model ?? DEFAULT_DECISION_MODEL;
|
|
27
|
-
const result = await decideWithModel({ apiKey, endpoint: options?.endpoint, model: expectedModel, signal }, input, TRAINING_GATE_QUESTIONS, { validateModel: true });
|
|
28
|
+
const result = await decideWithModel({ apiKey, endpoint: options?.endpoint, model: expectedModel, timeoutMs: DEFAULTS.training.decisionTimeoutMs, signal }, input, TRAINING_GATE_QUESTIONS, { validateModel: true });
|
|
28
29
|
if (!result.usage) {
|
|
29
30
|
throw new DecisionError("Invalid training gate response", "invalid_response");
|
|
30
31
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULTS } from "./defaults.js";
|
|
1
2
|
import { DatabaseSync } from "node:sqlite";
|
|
2
3
|
import { AgentTranscriptReader } from "./agent-transcript.js";
|
|
3
4
|
import { messageText } from "./whisperer-context.js";
|
|
@@ -28,7 +29,7 @@ export function trainingExamples(rows, renew) {
|
|
|
28
29
|
history.push({ role, content });
|
|
29
30
|
};
|
|
30
31
|
for (const row of rows) {
|
|
31
|
-
if (renew && Date.now() - renewedAt >=
|
|
32
|
+
if (renew && Date.now() - renewedAt >= DEFAULTS.training.heartbeatMs) {
|
|
32
33
|
renew();
|
|
33
34
|
renewedAt = Date.now();
|
|
34
35
|
}
|
|
@@ -135,7 +136,7 @@ export class TrainingTranscriptReader {
|
|
|
135
136
|
constructor(path, agentId) {
|
|
136
137
|
this.#db = new DatabaseSync(path, { readOnly: true });
|
|
137
138
|
try {
|
|
138
|
-
this.#db.exec(
|
|
139
|
+
this.#db.exec(`PRAGMA query_only=ON; PRAGMA busy_timeout=${DEFAULTS.sqlite.readerBusyTimeoutMs}`);
|
|
139
140
|
this.#transcripts = new AgentTranscriptReader(this.#db, agentId, "Unsupported training transcript schema or agent");
|
|
140
141
|
const columns = this.#db.prepare("PRAGMA table_info(session_windows)").all().map(c => c.name);
|
|
141
142
|
this.#lineage = ["parent_session_key", "spawned_by", "plugin_owner_id", "hook_external_content_source"].every(c => columns.includes(c));
|
|
@@ -159,7 +160,7 @@ export class TrainingTranscriptReader {
|
|
|
159
160
|
/:(?:cron|subagent|heartbeat|hook)(?::|$)/i.test(String(session.session_key)) ||
|
|
160
161
|
session.parent_session_key || session.spawned_by || session.plugin_owner_id || session.hook_external_content_source)
|
|
161
162
|
return null;
|
|
162
|
-
const snapshot = this.#transcripts.read(sessionId, { maxEvents:
|
|
163
|
+
const snapshot = this.#transcripts.read(sessionId, { maxEvents: DEFAULTS.training.maxInputEvents, maxBytes: DEFAULTS.training.maxInputBytes });
|
|
163
164
|
if (snapshot.kind === "oversized")
|
|
164
165
|
return { oversized: true };
|
|
165
166
|
if (snapshot.kind !== "ready")
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULTS } from "./defaults.js";
|
|
1
2
|
import { MEMORY_JUDGE_VERSION, memoryUsefulnessRequest, judgeMemoryPassage } from "./decision-ranking.js";
|
|
2
3
|
export const CONTEXT_JUDGE_VERSION = MEMORY_JUDGE_VERSION;
|
|
3
4
|
export function contextJudgeRequest(input, asOf, hit, model) {
|
|
@@ -6,5 +7,5 @@ export function contextJudgeRequest(input, asOf, hit, model) {
|
|
|
6
7
|
}, asOf, model);
|
|
7
8
|
}
|
|
8
9
|
export async function judgeTrainingPassage(request, apiKey, options) {
|
|
9
|
-
return judgeMemoryPassage(request, { apiKey, endpoint: options?.endpoint, model: options?.model, timeoutMs:
|
|
10
|
+
return judgeMemoryPassage(request, { apiKey, endpoint: options?.endpoint, model: options?.model, timeoutMs: DEFAULTS.training.decisionTimeoutMs });
|
|
10
11
|
}
|
|
@@ -2,7 +2,7 @@ import { Type, type Static } from "typebox";
|
|
|
2
2
|
import type { TrainingInput } from "./training-input.js";
|
|
3
3
|
import type { QueryLane } from "./query-contract.js";
|
|
4
4
|
export declare const TRAINING_RECIPE_VERSION = "lex-vec-v2";
|
|
5
|
-
export declare const TRAINING_TEACHER_MODEL
|
|
5
|
+
export declare const TRAINING_TEACHER_MODEL: string;
|
|
6
6
|
export declare const TRAINING_TEACHER_VERSION = "lex-vec-teacher-v2-xhigh";
|
|
7
7
|
export type TrainingRound = 1 | 2;
|
|
8
8
|
export type QueryFeedback = {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { DEFAULTS } from "./defaults.js";
|
|
1
2
|
import { Type } from "typebox";
|
|
2
3
|
import { Value } from "typebox/value";
|
|
3
4
|
export const TRAINING_RECIPE_VERSION = "lex-vec-v2";
|
|
4
|
-
export const TRAINING_TEACHER_MODEL =
|
|
5
|
+
export const TRAINING_TEACHER_MODEL = DEFAULTS.training.teacherModel;
|
|
5
6
|
export const TRAINING_TEACHER_VERSION = "lex-vec-teacher-v2-xhigh";
|
|
6
7
|
const TRAINING_TEACHER_PROMPT_VERSION = "lex-vec-teacher-prompt-v2";
|
|
7
|
-
const TRAINING_CANDIDATES_PER_ROUND =
|
|
8
|
+
const TRAINING_CANDIDATES_PER_ROUND = DEFAULTS.training.candidatesPerRound;
|
|
8
9
|
const queriesSchema = Type.Object({ queries: Type.Array(Type.String({ minLength: 1, maxLength: 500 }), { minItems: TRAINING_CANDIDATES_PER_ROUND, maxItems: TRAINING_CANDIDATES_PER_ROUND }) }, { additionalProperties: false });
|
|
9
10
|
export function trainingTeacherPrompt(lane) {
|
|
10
11
|
return `You generate memory-search queries for a training dataset. You are not a participant in the supplied conversation.
|
|
@@ -22,7 +23,7 @@ Target evidence needed for currentRequest, not the conversation's broad topic:
|
|
|
22
23
|
- Seek useful historical details not already supplied. Treat earlier assistant explanations as claims to investigate, not established causes. Do not invent names, aliases, premises, screenshot contents or predicted answers.
|
|
23
24
|
- Vary relevant evidence angles and wording. When context is sparse, use grounded paraphrases rather than inventing topics to fill the set.
|
|
24
25
|
|
|
25
|
-
If a lane_feedback block is present, it contains only this lane's earlier queries and their raw top
|
|
26
|
+
If a lane_feedback block is present, it contains only this lane's earlier queries and their raw top-${DEFAULTS.training.topScoreCount} passage-usefulness averages. Use that feedback to propose improved candidates. It is not evidence about the answer. You may retain a strong candidate.
|
|
26
27
|
Never answer or continue the conversation, ask clarification questions, execute tools, include credentials, or use knowledge of events beyond the supplied conversation. Code supplies the historical cutoff. Return JSON only.`;
|
|
27
28
|
}
|
|
28
29
|
export function trainingTeacherMessage(input, lane, feedback) {
|
|
@@ -41,17 +42,18 @@ export function trainingTeacher(runtime, agentId) {
|
|
|
41
42
|
throw new Error("Training requires host runtime.llm.complete");
|
|
42
43
|
}
|
|
43
44
|
const complete = llm.complete.bind(llm);
|
|
45
|
+
const expectedModel = TRAINING_TEACHER_MODEL.slice(TRAINING_TEACHER_MODEL.indexOf("/") + 1);
|
|
44
46
|
return async (input, lane, feedback) => {
|
|
45
|
-
const result = await complete({ agentId, model: TRAINING_TEACHER_MODEL, reasoning:
|
|
47
|
+
const result = await complete({ agentId, model: TRAINING_TEACHER_MODEL, reasoning: DEFAULTS.training.teacherReasoning, maxTokens: DEFAULTS.training.teacherMaxTokens,
|
|
46
48
|
purpose: "unblock-memory.training-queries", systemPrompt: trainingTeacherPrompt(lane),
|
|
47
|
-
signal: AbortSignal.timeout(
|
|
49
|
+
signal: AbortSignal.timeout(DEFAULTS.training.teacherTimeoutMs), execution: { mode: "isolated-agent-runtime", timeoutMs: DEFAULTS.training.teacherTimeoutMs },
|
|
48
50
|
messages: [{ role: "user", content: trainingTeacherMessage(input, lane, feedback) }] });
|
|
49
|
-
const schema = Type.Object({ text: Type.String(), model: Type.Literal(
|
|
51
|
+
const schema = Type.Object({ text: Type.String(), model: Type.Literal(expectedModel),
|
|
50
52
|
execution: Type.Object({ mode: Type.Literal("isolated-agent-runtime") }),
|
|
51
53
|
usage: Type.Optional(Type.Object({ inputTokens: Type.Optional(Type.Integer({ minimum: 0 })), outputTokens: Type.Optional(Type.Integer({ minimum: 0 })) })),
|
|
52
54
|
});
|
|
53
55
|
if (!Value.Check(schema, result))
|
|
54
|
-
throw new Error(
|
|
56
|
+
throw new Error(`Training requires isolated ${expectedModel} output`);
|
|
55
57
|
let parsed;
|
|
56
58
|
try {
|
|
57
59
|
parsed = JSON.parse(result.text);
|
|
@@ -51,7 +51,7 @@ export declare function generateTrainingQueries(source: Source, store: TrainingS
|
|
|
51
51
|
}[];
|
|
52
52
|
};
|
|
53
53
|
}>;
|
|
54
|
-
/** Raw top-
|
|
54
|
+
/** Raw top-score average, including values below runtime's injection threshold. */
|
|
55
55
|
export declare function trainingQueryScore(probabilities: readonly number[]): number;
|
|
56
56
|
export declare function selectTrainingQueries(queries: readonly QueryEvaluation[]): QueryPair;
|
|
57
57
|
export declare function evaluateTrainingQueries(source: Source, store: TrainingStore, config: UnblockMemoryConfig, runtime: unknown, options: Options & {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULTS } from "./defaults.js";
|
|
1
2
|
import { collectTraining } from "./training.js";
|
|
2
3
|
import { TRAINING_GATE_THRESHOLD } from "./training-gate.js";
|
|
3
4
|
import { classifyDecisionFailure, resolveDecisionCredential } from "./decision-client.js";
|
|
@@ -7,7 +8,7 @@ import { contextJudgeRequest, judgeTrainingPassage, CONTEXT_JUDGE_VERSION } from
|
|
|
7
8
|
import { memoryJudgeVersion } from "./decision-ranking.js";
|
|
8
9
|
import { jsonHash } from "./json-hash.js";
|
|
9
10
|
const LANES = ["lex", "vec"];
|
|
10
|
-
const SELECTION_VERSION =
|
|
11
|
+
const SELECTION_VERSION = `independent-lanes-top${DEFAULTS.training.topScoreCount}-mean-v2`;
|
|
11
12
|
const TARGET_POLICY = "best-per-lane-no-minimum-v1";
|
|
12
13
|
export const TRAINING_EVALUATION_CONCURRENCY = 4;
|
|
13
14
|
function bounds(options) {
|
|
@@ -143,9 +144,9 @@ export async function generateTrainingQueries(source, store, runtime, options) {
|
|
|
143
144
|
}));
|
|
144
145
|
return { refreshed, ...result, threshold: options.threshold ?? TRAINING_GATE_THRESHOLD, model: TRAINING_TEACHER_MODEL };
|
|
145
146
|
}
|
|
146
|
-
/** Raw top-
|
|
147
|
+
/** Raw top-score average, including values below runtime's injection threshold. */
|
|
147
148
|
export function trainingQueryScore(probabilities) {
|
|
148
|
-
const top = probabilities.toSorted((a, b) => b - a).slice(0,
|
|
149
|
+
const top = probabilities.toSorted((a, b) => b - a).slice(0, DEFAULTS.training.topScoreCount);
|
|
149
150
|
return top.length ? top.reduce((sum, value) => sum + value, 0) / top.length : 0;
|
|
150
151
|
}
|
|
151
152
|
export function selectTrainingQueries(queries) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { ChatType } from "./config.js";
|
|
2
2
|
import type { SessionMessageSpan } from "./session-projector.js";
|
|
3
3
|
import type { QueryLane } from "./query-contract.js";
|
|
4
|
-
export declare const TRAINING_RETRIEVAL_VERSION
|
|
4
|
+
export declare const TRAINING_RETRIEVAL_VERSION: string;
|
|
5
5
|
export declare const TRAINING_SEARCH_OPTIONS: {
|
|
6
|
-
readonly vector:
|
|
7
|
-
readonly bm25:
|
|
6
|
+
readonly vector: number;
|
|
7
|
+
readonly bm25: number;
|
|
8
8
|
readonly mergedLimit: null;
|
|
9
9
|
readonly rerank: false;
|
|
10
10
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULTS } from "./defaults.js";
|
|
1
2
|
import { createHash } from "node:crypto";
|
|
2
3
|
import { statSync } from "node:fs";
|
|
3
4
|
import { join } from "node:path";
|
|
@@ -7,8 +8,8 @@ import { projectionHash, readSessionManifest } from "./session-sync.js";
|
|
|
7
8
|
import { resolveSessionSource } from "./sources.js";
|
|
8
9
|
import { trainingCandidates } from "./training-candidates.js";
|
|
9
10
|
import { MEMORY_PASSAGE_VERSION, renderMemoryPassage, duplicateMemoryPassage } from "./memory-passage.js";
|
|
10
|
-
export const TRAINING_RETRIEVAL_VERSION = `qmd-2.10.2-historical-lanes-
|
|
11
|
-
export const TRAINING_SEARCH_OPTIONS = { vector:
|
|
11
|
+
export const TRAINING_RETRIEVAL_VERSION = `qmd-2.10.2-historical-lanes-depth${DEFAULTS.training.retrievalDepth}-v3:${MEMORY_PASSAGE_VERSION}`;
|
|
12
|
+
export const TRAINING_SEARCH_OPTIONS = { vector: DEFAULTS.training.retrievalDepth, bm25: DEFAULTS.training.retrievalDepth, mergedLimit: null, rerank: false };
|
|
12
13
|
/** Missing historical evidence is reviewable; unexpected SQLite/I/O failures remain fatal. */
|
|
13
14
|
export class HistoricalCorpusUnavailableError extends Error {
|
|
14
15
|
}
|
|
@@ -107,7 +108,7 @@ async function captureSourceSessions(stateDir, chatTypes) {
|
|
|
107
108
|
if (typeof extensionPath !== "string")
|
|
108
109
|
throw new Error("QMD sqlite-vec path unavailable");
|
|
109
110
|
sourceDb.loadExtension(extensionPath);
|
|
110
|
-
sourceDb.exec(
|
|
111
|
+
sourceDb.exec(`PRAGMA query_only=ON; PRAGMA busy_timeout=${DEFAULTS.sqlite.mainBusyTimeoutMs}; BEGIN`);
|
|
111
112
|
settings = sourceDb.prepare("SELECT key,value FROM store_config WHERE key='embedding_chunk_strategy'").all();
|
|
112
113
|
const manifestSessions = Object.values(manifest.sessions).sort((a, b) => a.documentPath.localeCompare(b.documentPath));
|
|
113
114
|
if (!manifestSessions.length) {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { DEFAULTS } from "./defaults.js";
|
|
1
2
|
import { randomUUID } from "node:crypto";
|
|
2
3
|
import { immediateTransaction, openMemoryDatabase } from "./memory-database.js";
|
|
3
4
|
import { TRAINING_PREPARATION } from "./training-input.js";
|
|
4
5
|
import { TRAINING_GATE_MODEL, TRAINING_GATE_THRESHOLD, TRAINING_GATE_VERSION } from "./training-gate.js";
|
|
5
6
|
import { TRAINING_RECIPE_VERSION } from "./training-models.js";
|
|
6
7
|
import { jsonHash } from "./json-hash.js";
|
|
7
|
-
const LEASE_MS =
|
|
8
|
+
const LEASE_MS = DEFAULTS.training.leaseMs;
|
|
8
9
|
export class TrainingStore {
|
|
9
10
|
#db;
|
|
10
11
|
#owner = randomUUID();
|
|
@@ -118,7 +119,7 @@ export class TrainingStore {
|
|
|
118
119
|
}
|
|
119
120
|
catch (error) {
|
|
120
121
|
leaseError = error;
|
|
121
|
-
} },
|
|
122
|
+
} }, DEFAULTS.training.heartbeatMs);
|
|
122
123
|
heartbeat.unref();
|
|
123
124
|
try {
|
|
124
125
|
const value = await fn();
|
package/dist/src/training.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULTS } from "./defaults.js";
|
|
1
2
|
import { classifyDecisionFailure, resolveDecisionCredential } from "./decision-client.js";
|
|
2
3
|
import { TrainingTranscriptReader } from "./training-input.js";
|
|
3
4
|
import { judgeTrainingInput, TRAINING_GATE_QUESTIONS } from "./training-gate.js";
|
|
@@ -81,7 +82,7 @@ export async function runTraining(source, store, config, options) {
|
|
|
81
82
|
let judgment;
|
|
82
83
|
try {
|
|
83
84
|
// Offline labeling has its own deadline, not Whisperer's latency-sensitive timeout.
|
|
84
|
-
judgment = await judgeTrainingInput(input, key, AbortSignal.timeout(
|
|
85
|
+
judgment = await judgeTrainingInput(input, key, AbortSignal.timeout(DEFAULTS.training.decisionTimeoutMs), { endpoint: config.decisionModel.endpoint, model: config.decisionModel.model });
|
|
85
86
|
}
|
|
86
87
|
catch (error) {
|
|
87
88
|
const classified = classifyDecisionFailure(error);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export declare const MAX_SKILL_QUERY_CHARS
|
|
2
|
-
export declare const MAX_STATE_TOKENS = 24000;
|
|
1
|
+
export declare const MAX_SKILL_QUERY_CHARS: number;
|
|
3
2
|
/** Only visible user/assistant text; never system, tool, image, or thinking blocks. */
|
|
4
3
|
export declare function messageText(message: unknown): {
|
|
5
4
|
role: "user" | "assistant";
|