omnius 1.0.853 → 1.0.855
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/dist/index.js +2 -2
- package/dist/library.js +548 -394
- package/docs/DISCOVERY.json +74 -1
- package/docs/DISCOVERY.md +3 -1
- package/docs/work-orders/WO-completion-review-recovery-20261013.md +61 -3
- package/docs/work-orders/WO-telegram-retained-source-handoff-20261013.md +111 -0
- package/docs/work-orders/evidence/telegram-completion-review-live-20261013.json +1692 -3
- package/docs/work-orders/evidence/telegram-retained-source-handoff-live-20261013.json +335 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/dist/library.js
CHANGED
|
@@ -1325,7 +1325,7 @@ var init_trace = __esm({
|
|
|
1325
1325
|
this.id = id5;
|
|
1326
1326
|
artifactKey(id5);
|
|
1327
1327
|
}
|
|
1328
|
-
begin(state, actions,
|
|
1328
|
+
begin(state, actions, metadata2 = {}) {
|
|
1329
1329
|
if (this.pending || this.events.length >= MAX_UI_TRACE_EVENTS)
|
|
1330
1330
|
throw new Error("Trace admission is full.");
|
|
1331
1331
|
parseUiDecision({ answers: { action: { choice: actions[0]?.id } } }, actions, "host-trace", 0);
|
|
@@ -1333,7 +1333,7 @@ var init_trace = __esm({
|
|
|
1333
1333
|
throw new Error("Trace candidates do not belong to the observed state.");
|
|
1334
1334
|
parseState(redactedState(state));
|
|
1335
1335
|
const ticket = randomUUID5();
|
|
1336
|
-
this.pending = { ticket, state: structuredClone(state), actions: structuredClone([...actions]), provenance: provenance({ ...
|
|
1336
|
+
this.pending = { ticket, state: structuredClone(state), actions: structuredClone([...actions]), provenance: provenance({ ...metadata2, source: "host_ui_outcome" }) };
|
|
1337
1337
|
return ticket;
|
|
1338
1338
|
}
|
|
1339
1339
|
complete(ticket, outcome, measurements = {}) {
|
|
@@ -65202,12 +65202,12 @@ var init_contextMemoryLedger = __esm({
|
|
|
65202
65202
|
return row2 ? mapRecord(row2) : null;
|
|
65203
65203
|
}
|
|
65204
65204
|
listRecords(epoch2, opts = {}) {
|
|
65205
|
-
const
|
|
65205
|
+
const rows2 = this.db.prepare(`
|
|
65206
65206
|
SELECT * FROM context_memory_record
|
|
65207
65207
|
WHERE epoch = ? ${opts.includeSuperseded ? "" : "AND valid_until IS NULL"}
|
|
65208
65208
|
ORDER BY valid_from ASC, id ASC
|
|
65209
65209
|
`).all(epoch2);
|
|
65210
|
-
return
|
|
65210
|
+
return rows2.map(mapRecord);
|
|
65211
65211
|
}
|
|
65212
65212
|
beginTransaction(input) {
|
|
65213
65213
|
const id5 = input.id ?? randomUUID12();
|
|
@@ -65333,9 +65333,9 @@ var init_contextMemoryLedger = __esm({
|
|
|
65333
65333
|
const ids2 = [...selected];
|
|
65334
65334
|
if (ids2.length === 0)
|
|
65335
65335
|
continue;
|
|
65336
|
-
const
|
|
65336
|
+
const rows2 = this.db.prepare(`SELECT DISTINCT transaction_id FROM context_memory_transaction_record
|
|
65337
65337
|
WHERE record_id IN (${ids2.map(() => "?").join(",")})`).all(...ids2);
|
|
65338
|
-
for (const row2 of
|
|
65338
|
+
for (const row2 of rows2) {
|
|
65339
65339
|
transactionIds.add(row2.transaction_id);
|
|
65340
65340
|
const transaction = this.getTransaction(row2.transaction_id);
|
|
65341
65341
|
for (const recordId of transaction?.recordIds ?? []) {
|
|
@@ -65370,14 +65370,14 @@ var init_contextMemoryLedger = __esm({
|
|
|
65370
65370
|
* the revision that was current at a historical instant.
|
|
65371
65371
|
*/
|
|
65372
65372
|
listRecordsAt(epoch2, asOf) {
|
|
65373
|
-
const
|
|
65373
|
+
const rows2 = this.db.prepare(`
|
|
65374
65374
|
SELECT * FROM context_memory_record
|
|
65375
65375
|
WHERE epoch = ?
|
|
65376
65376
|
AND valid_from <= ?
|
|
65377
65377
|
AND (valid_until IS NULL OR valid_until > ?)
|
|
65378
65378
|
ORDER BY valid_from ASC, id ASC
|
|
65379
65379
|
`).all(epoch2, asOf, asOf);
|
|
65380
|
-
return
|
|
65380
|
+
return rows2.map(mapRecord);
|
|
65381
65381
|
}
|
|
65382
65382
|
/**
|
|
65383
65383
|
* Retrieval can walk both directions: dependencies are recorded from an
|
|
@@ -65796,8 +65796,8 @@ var init_immutableEvidenceStore = __esm({
|
|
|
65796
65796
|
const missingScopes = this.db.prepare("SELECT id, metadata_json FROM vm_evidence_documents WHERE scope_id IS NULL").all();
|
|
65797
65797
|
const updateScope = this.db.prepare("UPDATE vm_evidence_documents SET scope_id = ? WHERE id = ?");
|
|
65798
65798
|
for (const row2 of missingScopes) {
|
|
65799
|
-
const
|
|
65800
|
-
const scopeId = typeof
|
|
65799
|
+
const metadata2 = parseObject2(row2["metadata_json"]);
|
|
65800
|
+
const scopeId = typeof metadata2["scopeId"] === "string" ? metadata2["scopeId"].trim() : "";
|
|
65801
65801
|
if (scopeId)
|
|
65802
65802
|
updateScope.run(scopeId, String(row2["id"]));
|
|
65803
65803
|
}
|
|
@@ -65839,8 +65839,8 @@ var init_immutableEvidenceStore = __esm({
|
|
|
65839
65839
|
if (!Number.isFinite(Date.parse(timestamp5)))
|
|
65840
65840
|
throw new Error("evidence timestamp must be ISO-8601 compatible");
|
|
65841
65841
|
const contentHash2 = sha256(input.originalText);
|
|
65842
|
-
const
|
|
65843
|
-
const scopeId = typeof
|
|
65842
|
+
const metadata2 = input.metadata ?? {};
|
|
65843
|
+
const scopeId = typeof metadata2["scopeId"] === "string" && metadata2["scopeId"].trim() ? metadata2["scopeId"].trim() : null;
|
|
65844
65844
|
const id5 = input.id ?? `evidence-document-${sha256(`${scopeId ?? ""}\0${input.source}\0${input.sourceUri ?? ""}\0${input.messageId ?? ""}\0${input.version}\0${contentHash2}`).slice(0, 32)}`;
|
|
65845
65845
|
const existing = this.getDocument(id5);
|
|
65846
65846
|
if (existing) {
|
|
@@ -65859,7 +65859,7 @@ var init_immutableEvidenceStore = __esm({
|
|
|
65859
65859
|
INSERT INTO vm_evidence_documents
|
|
65860
65860
|
(id, source, source_uri, message_id, source_timestamp, version, content_hash, original_text, scope_id, metadata_json, created_at)
|
|
65861
65861
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
65862
|
-
`).run(id5, input.source, input.sourceUri ?? null, input.messageId ?? null, timestamp5, input.version, contentHash2, input.originalText, scopeId, stableStringify2(
|
|
65862
|
+
`).run(id5, input.source, input.sourceUri ?? null, input.messageId ?? null, timestamp5, input.version, contentHash2, input.originalText, scopeId, stableStringify2(metadata2), createdAt);
|
|
65863
65863
|
const insertChunk = this.db.prepare(`
|
|
65864
65864
|
INSERT INTO vm_evidence_chunks
|
|
65865
65865
|
(id, document_id, ordinal, kind, token_start, token_end, char_start, char_end,
|
|
@@ -66022,7 +66022,7 @@ var init_immutableEvidenceStore = __esm({
|
|
|
66022
66022
|
const ftsQuery = terms3.map((term) => `"${term.replaceAll('"', '""')}"`).join(" OR ");
|
|
66023
66023
|
const bounded3 = Math.max(1, Math.min(500, Math.floor(limit2)));
|
|
66024
66024
|
const scope = scopePredicate(filters);
|
|
66025
|
-
const
|
|
66025
|
+
const rows2 = this.db.prepare(`
|
|
66026
66026
|
SELECT c.*, d.source, d.source_uri, d.message_id, d.version, d.source_timestamp,
|
|
66027
66027
|
d.metadata_json AS document_metadata_json,
|
|
66028
66028
|
bm25(vm_evidence_fts) AS lexical_rank
|
|
@@ -66033,7 +66033,7 @@ var init_immutableEvidenceStore = __esm({
|
|
|
66033
66033
|
ORDER BY lexical_rank ASC
|
|
66034
66034
|
LIMIT ?
|
|
66035
66035
|
`).all(ftsQuery, ...scope.params, bounded3);
|
|
66036
|
-
return this.filterRows(
|
|
66036
|
+
return this.filterRows(rows2, filters).slice(0, bounded3).map((row2) => ({
|
|
66037
66037
|
chunk: mapChunk(row2),
|
|
66038
66038
|
score: 1 / (1 + Math.abs(Number(row2["lexical_rank"] ?? 0))),
|
|
66039
66039
|
channel: "bm25"
|
|
@@ -66044,7 +66044,7 @@ var init_immutableEvidenceStore = __esm({
|
|
|
66044
66044
|
return [];
|
|
66045
66045
|
const bounded3 = Math.max(1, Math.min(500, Math.floor(limit2)));
|
|
66046
66046
|
const scope = scopePredicate(filters);
|
|
66047
|
-
const
|
|
66047
|
+
const rows2 = this.db.prepare(`
|
|
66048
66048
|
SELECT c.*, d.source, d.source_uri, d.message_id, d.version, d.source_timestamp,
|
|
66049
66049
|
d.metadata_json AS document_metadata_json
|
|
66050
66050
|
FROM vm_evidence_chunks c
|
|
@@ -66053,7 +66053,7 @@ var init_immutableEvidenceStore = __esm({
|
|
|
66053
66053
|
ORDER BY d.source_timestamp DESC, c.ordinal ASC
|
|
66054
66054
|
LIMIT ?
|
|
66055
66055
|
`).all(value, ...scope.params, bounded3);
|
|
66056
|
-
return this.filterRows(
|
|
66056
|
+
return this.filterRows(rows2, filters).slice(0, bounded3).map((row2) => ({
|
|
66057
66057
|
chunk: mapChunk(row2),
|
|
66058
66058
|
score: 1,
|
|
66059
66059
|
channel: "exact",
|
|
@@ -66066,7 +66066,7 @@ var init_immutableEvidenceStore = __esm({
|
|
|
66066
66066
|
return [];
|
|
66067
66067
|
const bounded3 = Math.max(1, Math.min(500, Math.floor(limit2)));
|
|
66068
66068
|
const scope = scopePredicate(filters);
|
|
66069
|
-
const
|
|
66069
|
+
const rows2 = this.db.prepare(`
|
|
66070
66070
|
SELECT c.*, d.source, d.source_uri, d.message_id, d.version, d.source_timestamp,
|
|
66071
66071
|
d.metadata_json AS document_metadata_json, s.symbol AS matched_symbol
|
|
66072
66072
|
FROM vm_evidence_symbols s
|
|
@@ -66076,7 +66076,7 @@ var init_immutableEvidenceStore = __esm({
|
|
|
66076
66076
|
ORDER BY d.source_timestamp DESC, c.ordinal ASC
|
|
66077
66077
|
LIMIT ?
|
|
66078
66078
|
`).all(normalized4, ...scope.params, bounded3);
|
|
66079
|
-
return this.filterRows(
|
|
66079
|
+
return this.filterRows(rows2, filters).slice(0, bounded3).map((row2) => ({
|
|
66080
66080
|
chunk: mapChunk(row2),
|
|
66081
66081
|
score: 1,
|
|
66082
66082
|
channel: "symbol",
|
|
@@ -66093,9 +66093,9 @@ var init_immutableEvidenceStore = __esm({
|
|
|
66093
66093
|
return [];
|
|
66094
66094
|
const bounded3 = Math.max(1, Math.min(500, Math.floor(limit2)));
|
|
66095
66095
|
const scope = scopePredicate(filters);
|
|
66096
|
-
const
|
|
66096
|
+
const rows2 = [];
|
|
66097
66097
|
for (const entityId of entityIds) {
|
|
66098
|
-
|
|
66098
|
+
rows2.push(...this.db.prepare(`
|
|
66099
66099
|
SELECT c.*, d.source, d.source_uri, d.message_id, d.version, d.source_timestamp,
|
|
66100
66100
|
d.metadata_json AS document_metadata_json
|
|
66101
66101
|
FROM vm_evidence_entity_mentions m
|
|
@@ -66106,7 +66106,7 @@ var init_immutableEvidenceStore = __esm({
|
|
|
66106
66106
|
LIMIT ?
|
|
66107
66107
|
`).all(entityId, ...scope.params, bounded3));
|
|
66108
66108
|
}
|
|
66109
|
-
return this.filterRows(
|
|
66109
|
+
return this.filterRows(rows2, filters).slice(0, bounded3).map((row2) => ({
|
|
66110
66110
|
chunk: mapChunk(row2),
|
|
66111
66111
|
score: 1,
|
|
66112
66112
|
channel: "entity",
|
|
@@ -66116,7 +66116,7 @@ var init_immutableEvidenceStore = __esm({
|
|
|
66116
66116
|
searchRecency(limit2 = 50, filters = {}) {
|
|
66117
66117
|
const bounded3 = Math.max(1, Math.min(500, Math.floor(limit2)));
|
|
66118
66118
|
const scope = scopePredicate(filters);
|
|
66119
|
-
const
|
|
66119
|
+
const rows2 = this.db.prepare(`
|
|
66120
66120
|
SELECT c.*, d.source, d.source_uri, d.message_id, d.version, d.source_timestamp,
|
|
66121
66121
|
d.metadata_json AS document_metadata_json
|
|
66122
66122
|
FROM vm_evidence_chunks c
|
|
@@ -66125,7 +66125,7 @@ var init_immutableEvidenceStore = __esm({
|
|
|
66125
66125
|
ORDER BY d.source_timestamp DESC, c.ordinal DESC
|
|
66126
66126
|
LIMIT ?
|
|
66127
66127
|
`).all(...scope.params, bounded3);
|
|
66128
|
-
const filtered = this.filterRows(
|
|
66128
|
+
const filtered = this.filterRows(rows2, filters).slice(0, bounded3);
|
|
66129
66129
|
return filtered.map((row2, index) => ({
|
|
66130
66130
|
chunk: mapChunk(row2),
|
|
66131
66131
|
score: 1 / (1 + index),
|
|
@@ -66135,7 +66135,7 @@ var init_immutableEvidenceStore = __esm({
|
|
|
66135
66135
|
searchDense(model, queryVector, limit2 = 50, filters = {}) {
|
|
66136
66136
|
const query = normalizedVector(queryVector);
|
|
66137
66137
|
const scope = scopePredicate(filters);
|
|
66138
|
-
const
|
|
66138
|
+
const rows2 = this.db.prepare(`
|
|
66139
66139
|
SELECT c.*, d.source, d.source_uri, d.message_id, d.version, d.source_timestamp,
|
|
66140
66140
|
d.metadata_json AS document_metadata_json,
|
|
66141
66141
|
e.vector_json, e.dimensions
|
|
@@ -66144,7 +66144,7 @@ var init_immutableEvidenceStore = __esm({
|
|
|
66144
66144
|
JOIN vm_evidence_documents d ON d.id = c.document_id
|
|
66145
66145
|
WHERE e.model = ? AND e.dimensions = ?${scope.sql}
|
|
66146
66146
|
`).all(model, query.length, ...scope.params);
|
|
66147
|
-
return this.filterRows(
|
|
66147
|
+
return this.filterRows(rows2, filters).map((row2) => {
|
|
66148
66148
|
const vector = JSON.parse(String(row2["vector_json"]));
|
|
66149
66149
|
return { chunk: mapChunk(row2), score: cosine(query, vector), channel: "dense" };
|
|
66150
66150
|
}).sort((left, right) => right.score - left.score).slice(0, Math.max(1, Math.min(500, Math.floor(limit2))));
|
|
@@ -66242,13 +66242,13 @@ var init_immutableEvidenceStore = __esm({
|
|
|
66242
66242
|
characters: Number(row2["characters"] ?? 0)
|
|
66243
66243
|
};
|
|
66244
66244
|
}
|
|
66245
|
-
filterRows(
|
|
66245
|
+
filterRows(rows2, filters) {
|
|
66246
66246
|
const documentIds = filters.documentIds ? new Set(filters.documentIds) : null;
|
|
66247
66247
|
const kinds3 = filters.kinds ? new Set(filters.kinds) : null;
|
|
66248
66248
|
const after = filters.after ? Date.parse(filters.after) : null;
|
|
66249
66249
|
const before = filters.before ? Date.parse(filters.before) : null;
|
|
66250
66250
|
const scopeIds = filters.scopeIds ? new Set(filters.scopeIds) : null;
|
|
66251
|
-
return
|
|
66251
|
+
return rows2.filter((row2) => {
|
|
66252
66252
|
if (documentIds && !documentIds.has(String(row2["document_id"])))
|
|
66253
66253
|
return false;
|
|
66254
66254
|
if (kinds3 && !kinds3.has(row2["kind"]))
|
|
@@ -66262,10 +66262,10 @@ var init_immutableEvidenceStore = __esm({
|
|
|
66262
66262
|
if (filters.version && String(row2["version"] ?? "") !== filters.version)
|
|
66263
66263
|
return false;
|
|
66264
66264
|
if (scopeIds) {
|
|
66265
|
-
const
|
|
66265
|
+
const metadata2 = parseObject2(row2["document_metadata_json"]);
|
|
66266
66266
|
const declaredScopes = [
|
|
66267
|
-
...typeof
|
|
66268
|
-
...Array.isArray(
|
|
66267
|
+
...typeof metadata2["scopeId"] === "string" ? [metadata2["scopeId"]] : [],
|
|
66268
|
+
...Array.isArray(metadata2["scopeIds"]) ? metadata2["scopeIds"].filter((value) => typeof value === "string") : []
|
|
66269
66269
|
];
|
|
66270
66270
|
if (!declaredScopes.some((scopeId) => scopeIds.has(scopeId)))
|
|
66271
66271
|
return false;
|
|
@@ -66368,9 +66368,9 @@ var init_artifactReviewSourceIndex = __esm({
|
|
|
66368
66368
|
}
|
|
66369
66369
|
observedChannels(owner) {
|
|
66370
66370
|
this.owner(owner);
|
|
66371
|
-
const
|
|
66371
|
+
const rows2 = this.db.prepare(`SELECT channel,payload_json,payload_sha256 FROM vm_corpus_observed_channels
|
|
66372
66372
|
WHERE scope_id=? AND run_id=? AND task_epoch=? ORDER BY channel`).all(owner.scopeId, owner.runId, owner.taskEpoch);
|
|
66373
|
-
return
|
|
66373
|
+
return rows2.map((row2) => {
|
|
66374
66374
|
const payload2 = text3(row2["payload_json"], "channel payload"), input = JSON.parse(payload2);
|
|
66375
66375
|
if (hash3(payload2) !== row2["payload_sha256"] || stable(input) !== payload2 || stable(input.owner) !== stable(owner) || row2["channel"] !== "ocr_text" || input.channel !== row2["channel"])
|
|
66376
66376
|
throw new Error("Observed corpus channel owner or payload changed");
|
|
@@ -66498,11 +66498,11 @@ var init_artifactReviewSourceIndex = __esm({
|
|
|
66498
66498
|
parameters.push(stable(values));
|
|
66499
66499
|
}
|
|
66500
66500
|
}
|
|
66501
|
-
const
|
|
66502
|
-
const more =
|
|
66501
|
+
const rows2 = this.db.prepare(`SELECT * FROM vm_artifact_review_sources WHERE ${where} ORDER BY seq LIMIT ?`).all(...parameters, size + 1);
|
|
66502
|
+
const more = rows2.length > size;
|
|
66503
66503
|
if (more)
|
|
66504
|
-
|
|
66505
|
-
const items =
|
|
66504
|
+
rows2.pop();
|
|
66505
|
+
const items = rows2.map((row2) => this.entry(row2, input.owner));
|
|
66506
66506
|
const last = items.at(-1);
|
|
66507
66507
|
const nextCursor = more && last ? Buffer.from(stable({
|
|
66508
66508
|
schema: "omnius.artifact-review-source-cursor.v1",
|
|
@@ -66752,17 +66752,17 @@ var init_sourceCorpusStore = __esm({
|
|
|
66752
66752
|
];
|
|
66753
66753
|
if (typeof input.orderKey !== "string")
|
|
66754
66754
|
throw new Error("orderKey must be a string");
|
|
66755
|
-
const
|
|
66755
|
+
const metadata2 = metadataJson(input.metadata);
|
|
66756
66756
|
const prior = row(this.db.prepare(`SELECT * FROM vm_corpus_sources
|
|
66757
66757
|
WHERE scope_id=? AND corpus_id=? AND source_id=? AND version_id=?`).get(input.scopeId, input.corpusId, input.sourceId, input.sourceSha256));
|
|
66758
66758
|
if (prior) {
|
|
66759
|
-
if (prior["source_uri"] !== input.sourceUri || prior["media_kind"] !== input.mediaKind || prior["order_key"] !== input.orderKey || prior["metadata_json"] !==
|
|
66759
|
+
if (prior["source_uri"] !== input.sourceUri || prior["media_kind"] !== input.mediaKind || prior["order_key"] !== input.orderKey || prior["metadata_json"] !== metadata2)
|
|
66760
66760
|
throw new Error("Immutable source declaration conflicts with existing version");
|
|
66761
66761
|
return this.source(prior);
|
|
66762
66762
|
}
|
|
66763
66763
|
this.db.prepare(`INSERT INTO vm_corpus_sources
|
|
66764
66764
|
(scope_id,corpus_id,source_id,version_id,source_sha256,source_uri,media_kind,order_key,metadata_json,created_at)
|
|
66765
|
-
VALUES (?,?,?,?,?,?,?,?,?,?)`).run(input.scopeId, input.corpusId, values[0], values[1], values[1], values[2], values[3], input.orderKey,
|
|
66765
|
+
VALUES (?,?,?,?,?,?,?,?,?,?)`).run(input.scopeId, input.corpusId, values[0], values[1], values[1], values[2], values[3], input.orderKey, metadata2, now());
|
|
66766
66766
|
return this.source(row(this.db.prepare(`SELECT * FROM vm_corpus_sources
|
|
66767
66767
|
WHERE scope_id=? AND corpus_id=? AND source_id=? AND version_id=?`).get(input.scopeId, input.corpusId, input.sourceId, input.sourceSha256)));
|
|
66768
66768
|
}
|
|
@@ -66780,15 +66780,15 @@ var init_sourceCorpusStore = __esm({
|
|
|
66780
66780
|
const countConflict = this.db.prepare(`SELECT seq FROM vm_corpus_observations WHERE source_seq=? AND page_count<>? LIMIT 1`).get(source.sequence, input.pageCount);
|
|
66781
66781
|
if (countConflict)
|
|
66782
66782
|
throw new Error("The same source bytes cannot change page count");
|
|
66783
|
-
const
|
|
66783
|
+
const metadata2 = metadataJson(input.metadata);
|
|
66784
66784
|
const old = row(this.db.prepare(`SELECT * FROM vm_corpus_observations WHERE source_seq=? AND document_id=?`).get(source.sequence, document.id));
|
|
66785
|
-
if (old && (old["body_sha256"] !== document.contentHash || old["page_count"] !== input.pageCount || old["complete"] !== Number(input.complete) || old["metadata_json"] !==
|
|
66785
|
+
if (old && (old["body_sha256"] !== document.contentHash || old["page_count"] !== input.pageCount || old["complete"] !== Number(input.complete) || old["metadata_json"] !== metadata2))
|
|
66786
66786
|
throw new Error("Immutable source observation conflicts with existing identity");
|
|
66787
66787
|
this.db.exec("BEGIN IMMEDIATE");
|
|
66788
66788
|
try {
|
|
66789
66789
|
if (!old)
|
|
66790
66790
|
this.db.prepare(`INSERT INTO vm_corpus_observations
|
|
66791
|
-
(source_seq,document_id,body_sha256,page_count,complete,metadata_json,created_at) VALUES (?,?,?,?,?,?,?)`).run(source.sequence, document.id, document.contentHash, input.pageCount, Number(input.complete),
|
|
66791
|
+
(source_seq,document_id,body_sha256,page_count,complete,metadata_json,created_at) VALUES (?,?,?,?,?,?,?)`).run(source.sequence, document.id, document.contentHash, input.pageCount, Number(input.complete), metadata2, now());
|
|
66792
66792
|
const observation = old ?? row(this.db.prepare(`SELECT * FROM vm_corpus_observations WHERE source_seq=? AND document_id=?`).get(source.sequence, document.id));
|
|
66793
66793
|
const observationSequence = Number(observation["seq"]);
|
|
66794
66794
|
let pages = 0;
|
|
@@ -67011,11 +67011,11 @@ var init_sourceCorpusStore = __esm({
|
|
|
67011
67011
|
if ((operation.coverageKind === "summarized" || operation.coverageKind === "manipulated") && !input.derivedDocumentId)
|
|
67012
67012
|
throw new Error("Derived work requires a separately persisted output document");
|
|
67013
67013
|
const derived = input.derivedDocumentId ? this.verifiedDocument(input.derivedDocumentId, input.scopeId) : null;
|
|
67014
|
-
const
|
|
67014
|
+
const metadata2 = metadataJson(input.metadata);
|
|
67015
67015
|
const previous = row(this.db.prepare(`SELECT * FROM vm_corpus_coverage
|
|
67016
67016
|
WHERE scope_id=? AND corpus_id=? AND operation_id=? AND unit=? AND unit_seq=?`).get(input.scopeId, input.corpusId, input.operationId, operation.unit, unitSequence));
|
|
67017
67017
|
if (previous) {
|
|
67018
|
-
if (previous["kind"] !== operation.coverageKind || previous["derived_document_id"] !== (derived?.id ?? null) || previous["derived_sha256"] !== (derived?.contentHash ?? null) || previous["metadata_json"] !==
|
|
67018
|
+
if (previous["kind"] !== operation.coverageKind || previous["derived_document_id"] !== (derived?.id ?? null) || previous["derived_sha256"] !== (derived?.contentHash ?? null) || previous["metadata_json"] !== metadata2)
|
|
67019
67019
|
throw new Error("Immutable coverage conflicts with the prior derived output");
|
|
67020
67020
|
return;
|
|
67021
67021
|
}
|
|
@@ -67023,7 +67023,7 @@ var init_sourceCorpusStore = __esm({
|
|
|
67023
67023
|
throw new Error("Cannot add coverage to a completed operation");
|
|
67024
67024
|
this.db.prepare(`INSERT INTO vm_corpus_coverage
|
|
67025
67025
|
(scope_id,corpus_id,operation_id,unit,unit_seq,kind,derived_document_id,derived_sha256,metadata_json,created_at)
|
|
67026
|
-
VALUES (?,?,?,?,?,?,?,?,?,?)`).run(input.scopeId, input.corpusId, input.operationId, operation.unit, unitSequence, operation.coverageKind, derived?.id ?? null, derived?.contentHash ?? null,
|
|
67026
|
+
VALUES (?,?,?,?,?,?,?,?,?,?)`).run(input.scopeId, input.corpusId, input.operationId, operation.unit, unitSequence, operation.coverageKind, derived?.id ?? null, derived?.contentHash ?? null, metadata2, now());
|
|
67027
67027
|
}
|
|
67028
67028
|
completeOperation(input) {
|
|
67029
67029
|
return this.transaction(() => this.completeOperationInside(input));
|
|
@@ -67360,11 +67360,11 @@ var init_sourceCorpusStore = __esm({
|
|
|
67360
67360
|
}
|
|
67361
67361
|
const select2 = unit === "source" ? "SELECT s.* FROM vm_corpus_sources s" : this.pageSelect();
|
|
67362
67362
|
const fields2 = unit === "source" ? `s.order_key ${direction},s.seq ${direction}` : `s.order_key ${direction},s.seq ${direction},p.page_number ${direction},p.channel ${direction},p.segment_ordinal ${direction},p.seq ${direction}`;
|
|
67363
|
-
const
|
|
67364
|
-
const more =
|
|
67363
|
+
const rows2 = this.db.prepare(`${select2} WHERE ${where.sql} ORDER BY ${fields2} LIMIT ?`).all(...where.params, size + 1);
|
|
67364
|
+
const more = rows2.length > size;
|
|
67365
67365
|
if (more)
|
|
67366
|
-
|
|
67367
|
-
const last =
|
|
67366
|
+
rows2.pop();
|
|
67367
|
+
const last = rows2.at(-1);
|
|
67368
67368
|
const nextCursor = more && last ? Buffer.from(stable2({
|
|
67369
67369
|
schema: "omnius.source-corpus-cursor.v1",
|
|
67370
67370
|
queryHash,
|
|
@@ -67380,7 +67380,7 @@ var init_sourceCorpusStore = __esm({
|
|
|
67380
67380
|
} : {}
|
|
67381
67381
|
}
|
|
67382
67382
|
})).toString("base64url") : null;
|
|
67383
|
-
return { items:
|
|
67383
|
+
return { items: rows2.map(map), nextCursor, snapshot };
|
|
67384
67384
|
}
|
|
67385
67385
|
where(input, snapshot, unit) {
|
|
67386
67386
|
const selection = this.selection(input);
|
|
@@ -67921,7 +67921,7 @@ var init_evidenceIngestion = __esm({
|
|
|
67921
67921
|
return state;
|
|
67922
67922
|
}
|
|
67923
67923
|
appendRecord(record9, options, state) {
|
|
67924
|
-
const
|
|
67924
|
+
const metadata2 = {
|
|
67925
67925
|
...record9.metadata ?? {},
|
|
67926
67926
|
...options.scopeId ? { scopeId: options.scopeId } : {}
|
|
67927
67927
|
};
|
|
@@ -67933,7 +67933,7 @@ var init_evidenceIngestion = __esm({
|
|
|
67933
67933
|
...record9.timestamp ? { timestamp: record9.timestamp } : {},
|
|
67934
67934
|
version: record9.version,
|
|
67935
67935
|
originalText: record9.text,
|
|
67936
|
-
metadata
|
|
67936
|
+
metadata: metadata2
|
|
67937
67937
|
};
|
|
67938
67938
|
const stored = this.store.appendDocument(documentInput, chunkStructuredEvidence(record9.text, {
|
|
67939
67939
|
kind: record9.kind ?? "auto",
|
|
@@ -68089,8 +68089,8 @@ var init_structuredMemoryStore = __esm({
|
|
|
68089
68089
|
const missingScopes = this.db.prepare("SELECT id, metadata_json FROM vm_structured_memory WHERE scope_id IS NULL").all();
|
|
68090
68090
|
const updateScope = this.db.prepare("UPDATE vm_structured_memory SET scope_id = ? WHERE id = ?");
|
|
68091
68091
|
for (const row2 of missingScopes) {
|
|
68092
|
-
const
|
|
68093
|
-
const scopeId = typeof
|
|
68092
|
+
const metadata2 = parseObject3(row2["metadata_json"]);
|
|
68093
|
+
const scopeId = typeof metadata2["scopeId"] === "string" ? metadata2["scopeId"].trim() : "";
|
|
68094
68094
|
if (scopeId)
|
|
68095
68095
|
updateScope.run(scopeId, String(row2["id"]));
|
|
68096
68096
|
}
|
|
@@ -68315,13 +68315,13 @@ var init_structuredMemoryStore = __esm({
|
|
|
68315
68315
|
clauses.push("compression_generation <= ?");
|
|
68316
68316
|
params.push(Math.max(0, Math.floor(maximumGeneration)));
|
|
68317
68317
|
}
|
|
68318
|
-
const
|
|
68318
|
+
const rows2 = this.db.prepare(`
|
|
68319
68319
|
SELECT * FROM vm_structured_memory
|
|
68320
68320
|
WHERE ${clauses.join(" AND ")}
|
|
68321
68321
|
ORDER BY importance DESC, valid_from DESC
|
|
68322
68322
|
LIMIT ?
|
|
68323
68323
|
`).all(...params, limit2);
|
|
68324
|
-
return
|
|
68324
|
+
return rows2.map(mapRecord2);
|
|
68325
68325
|
}
|
|
68326
68326
|
/**
|
|
68327
68327
|
* Lexically locate derived memory, then let the caller expand immutable
|
|
@@ -68367,7 +68367,7 @@ var init_structuredMemoryStore = __esm({
|
|
|
68367
68367
|
clauses.push("m.compression_generation <= ?");
|
|
68368
68368
|
params.push(Math.max(0, Math.floor(maximumGeneration)));
|
|
68369
68369
|
}
|
|
68370
|
-
const
|
|
68370
|
+
const rows2 = this.db.prepare(`
|
|
68371
68371
|
SELECT m.*, bm25(vm_structured_memory_fts) AS lexical_rank
|
|
68372
68372
|
FROM vm_structured_memory_fts f
|
|
68373
68373
|
JOIN vm_structured_memory m ON m.id = f.memory_id
|
|
@@ -68375,7 +68375,7 @@ var init_structuredMemoryStore = __esm({
|
|
|
68375
68375
|
ORDER BY lexical_rank ASC, m.importance DESC, m.valid_from DESC
|
|
68376
68376
|
LIMIT ?
|
|
68377
68377
|
`).all(...params, limit2);
|
|
68378
|
-
return
|
|
68378
|
+
return rows2.map((row2) => {
|
|
68379
68379
|
const record9 = mapRecord2(row2);
|
|
68380
68380
|
const lexical = 1 / (1 + Math.abs(Number(row2["lexical_rank"] ?? 0)));
|
|
68381
68381
|
const generationPenalty = 1 + record9.compressionGeneration * 0.05;
|
|
@@ -68725,7 +68725,7 @@ var init_virtualMemory = __esm({
|
|
|
68725
68725
|
throw new Error(`virtual memory item not found: ${id5}`);
|
|
68726
68726
|
return item;
|
|
68727
68727
|
}
|
|
68728
|
-
record(operation, itemIds, fromLevel, toLevel, tokenDelta, reason,
|
|
68728
|
+
record(operation, itemIds, fromLevel, toLevel, tokenDelta, reason, metadata2 = {}) {
|
|
68729
68729
|
const event = {
|
|
68730
68730
|
id: `vm-event-${randomUUID16()}`,
|
|
68731
68731
|
operation,
|
|
@@ -68735,7 +68735,7 @@ var init_virtualMemory = __esm({
|
|
|
68735
68735
|
tokenDelta,
|
|
68736
68736
|
reason,
|
|
68737
68737
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
68738
|
-
metadata
|
|
68738
|
+
metadata: metadata2
|
|
68739
68739
|
};
|
|
68740
68740
|
this.events.push(event);
|
|
68741
68741
|
this.options.onTelemetry?.(event);
|
|
@@ -68968,7 +68968,7 @@ var init_virtualMemoryReceiptStore = __esm({
|
|
|
68968
68968
|
const itemIds = [...new Set(input.itemIds ?? [])];
|
|
68969
68969
|
const tokenDelta = Number.isFinite(input.tokenDelta) ? Math.trunc(input.tokenDelta ?? 0) : 0;
|
|
68970
68970
|
const tokenBudget = Number.isFinite(input.tokenBudget) && (input.tokenBudget ?? -1) >= 0 ? Math.trunc(input.tokenBudget) : void 0;
|
|
68971
|
-
const
|
|
68971
|
+
const metadata2 = input.metadata ?? {};
|
|
68972
68972
|
const payload2 = {
|
|
68973
68973
|
scopeId,
|
|
68974
68974
|
runId: input.runId,
|
|
@@ -68981,7 +68981,7 @@ var init_virtualMemoryReceiptStore = __esm({
|
|
|
68981
68981
|
tokenDelta,
|
|
68982
68982
|
tokenBudget,
|
|
68983
68983
|
reason,
|
|
68984
|
-
metadata,
|
|
68984
|
+
metadata: metadata2,
|
|
68985
68985
|
timestamp: timestamp5
|
|
68986
68986
|
};
|
|
68987
68987
|
const payloadHash = createHash19("sha256").update(stableStringify4(payload2)).digest("hex");
|
|
@@ -68998,7 +68998,7 @@ var init_virtualMemoryReceiptStore = __esm({
|
|
|
68998
68998
|
item_ids_json, token_delta, token_budget, reason, metadata_json,
|
|
68999
68999
|
event_timestamp, payload_hash, created_at)
|
|
69000
69000
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
69001
|
-
`).run(id5, scopeId, input.runId ?? null, input.requestId ?? null, input.stage, input.operation ?? null, input.fromLevel ?? null, input.toLevel ?? null, stableStringify4(itemIds), tokenDelta, tokenBudget ?? null, reason, stableStringify4(
|
|
69001
|
+
`).run(id5, scopeId, input.runId ?? null, input.requestId ?? null, input.stage, input.operation ?? null, input.fromLevel ?? null, input.toLevel ?? null, stableStringify4(itemIds), tokenDelta, tokenBudget ?? null, reason, stableStringify4(metadata2), timestamp5, payloadHash, (/* @__PURE__ */ new Date()).toISOString());
|
|
69002
69002
|
return this.get(id5);
|
|
69003
69003
|
}
|
|
69004
69004
|
get(id5) {
|
|
@@ -69966,10 +69966,10 @@ var init_unifiedMemoryStore = __esm({
|
|
|
69966
69966
|
return toNumber(row2?.count, 0);
|
|
69967
69967
|
}
|
|
69968
69968
|
getChunks(itemId2) {
|
|
69969
|
-
const
|
|
69969
|
+
const rows2 = this.db.prepare(`
|
|
69970
69970
|
SELECT * FROM memory_chunk WHERE item_id = ? ORDER BY sequence ASC
|
|
69971
69971
|
`).all(itemId2);
|
|
69972
|
-
return
|
|
69972
|
+
return rows2.map(mapChunkRow);
|
|
69973
69973
|
}
|
|
69974
69974
|
getChunk(id5) {
|
|
69975
69975
|
const row2 = this.db.prepare("SELECT * FROM memory_chunk WHERE id = ?").get(id5);
|
|
@@ -70052,10 +70052,10 @@ var init_unifiedMemoryStore = __esm({
|
|
|
70052
70052
|
return mapProvenanceRow(row2);
|
|
70053
70053
|
}
|
|
70054
70054
|
getProvenance(itemId2) {
|
|
70055
|
-
const
|
|
70055
|
+
const rows2 = this.db.prepare(`
|
|
70056
70056
|
SELECT * FROM memory_provenance WHERE item_id = ? ORDER BY created_at ASC
|
|
70057
70057
|
`).all(itemId2);
|
|
70058
|
-
return
|
|
70058
|
+
return rows2.map(mapProvenanceRow);
|
|
70059
70059
|
}
|
|
70060
70060
|
createLink(input) {
|
|
70061
70061
|
const id5 = input.id ?? randomUUID18();
|
|
@@ -70102,8 +70102,8 @@ var init_unifiedMemoryStore = __esm({
|
|
|
70102
70102
|
ORDER BY i.importance DESC, i.confidence DESC, i.updated_at DESC, c.sequence ASC
|
|
70103
70103
|
LIMIT ?
|
|
70104
70104
|
`;
|
|
70105
|
-
const
|
|
70106
|
-
return
|
|
70105
|
+
const rows2 = this.db.prepare(sql).all(...termParams, ...filters.params, limit2);
|
|
70106
|
+
return rows2.map((row2, index) => {
|
|
70107
70107
|
const rowText = `${row2.item_title ?? ""} ${row2.chunk_text ?? ""}`;
|
|
70108
70108
|
const hitScore = lexicalHitScore(rowText, terms3);
|
|
70109
70109
|
const rankScore = Math.max(hitScore, 1 / (index + 1));
|
|
@@ -70140,8 +70140,8 @@ var init_unifiedMemoryStore = __esm({
|
|
|
70140
70140
|
${filters.sql}
|
|
70141
70141
|
LIMIT ?
|
|
70142
70142
|
`;
|
|
70143
|
-
const
|
|
70144
|
-
const matches =
|
|
70143
|
+
const rows2 = this.db.prepare(sql).all(query.length, ...embeddingFilter.params, ...filters.params, scanLimit);
|
|
70144
|
+
const matches = rows2.map((row2) => {
|
|
70145
70145
|
const rowData = row2;
|
|
70146
70146
|
const embedding = decodeMemoryVector(rowData.embedding_vector);
|
|
70147
70147
|
const similarity2 = cosineMemorySimilarity(query, embedding);
|
|
@@ -70210,13 +70210,13 @@ var init_unifiedMemoryStore = __esm({
|
|
|
70210
70210
|
const scopeSql = scope ? `AND EXISTS (SELECT 1 FROM memory_item i WHERE i.id=q.item_id AND i.scope_id=?
|
|
70211
70211
|
AND i.deleted_at IS NULL AND (i.expires_at IS NULL OR i.expires_at>?)
|
|
70212
70212
|
AND json_extract(q.payload_json,'$.scopeId')=? AND json_extract(q.payload_json,'$.profileSha256')=?)` : "";
|
|
70213
|
-
const
|
|
70213
|
+
const rows2 = this.db.prepare(`SELECT q.* FROM memory_job_queue q
|
|
70214
70214
|
WHERE ((q.status='pending' AND q.scheduled_at<=?) OR (q.status='running' AND q.started_at<=?))
|
|
70215
70215
|
AND q.job_type IN (${placeholders(jobTypes.length)}) ${scopeSql}
|
|
70216
70216
|
${jobIds ? `AND q.id IN (${placeholders(jobIds.length)})` : ""}
|
|
70217
70217
|
ORDER BY q.scheduled_at ASC,q.created_at ASC,q.id ASC LIMIT ?`).all(now2, expired, ...jobTypes, ...scope ? [scope.scopeId, now2, scope.scopeId, scope.profileSha256] : [], ...jobIds ?? [], max);
|
|
70218
70218
|
const owned = [];
|
|
70219
|
-
for (const row2 of
|
|
70219
|
+
for (const row2 of rows2) {
|
|
70220
70220
|
const job = mapJobRow(row2);
|
|
70221
70221
|
const changed = this.db.prepare(`UPDATE memory_job_queue SET status='running',attempts=attempts+1,started_at=?,updated_at=?
|
|
70222
70222
|
WHERE id=? AND attempts=? AND ((status='pending' AND scheduled_at<=?) OR (status='running' AND started_at<=?))`).run(now2, now2, job.id, job.attempts, now2, expired).changes;
|
|
@@ -70263,18 +70263,18 @@ var init_unifiedMemoryStore = __esm({
|
|
|
70263
70263
|
}
|
|
70264
70264
|
listJobs(status2, limit2 = 50) {
|
|
70265
70265
|
const max = normalizeLimit(limit2, 50, 1e3);
|
|
70266
|
-
const
|
|
70266
|
+
const rows2 = status2 ? this.db.prepare(`
|
|
70267
70267
|
SELECT * FROM memory_job_queue WHERE status = ? ORDER BY scheduled_at ASC LIMIT ?
|
|
70268
70268
|
`).all(status2, max) : this.db.prepare(`
|
|
70269
70269
|
SELECT * FROM memory_job_queue ORDER BY scheduled_at ASC LIMIT ?
|
|
70270
70270
|
`).all(max);
|
|
70271
|
-
return
|
|
70271
|
+
return rows2.map(mapJobRow);
|
|
70272
70272
|
}
|
|
70273
70273
|
chunksMissingEmbedding(embeddingSetSlug, limit2 = 100) {
|
|
70274
70274
|
const embeddingSet = embeddingSetSlug ? this.getEmbeddingSetBySlug(embeddingSetSlug) : this.getDefaultEmbeddingSet();
|
|
70275
70275
|
if (!embeddingSet)
|
|
70276
70276
|
return [];
|
|
70277
|
-
const
|
|
70277
|
+
const rows2 = this.db.prepare(`
|
|
70278
70278
|
SELECT c.*
|
|
70279
70279
|
FROM memory_chunk c
|
|
70280
70280
|
JOIN memory_item i ON i.id = c.item_id
|
|
@@ -70286,7 +70286,7 @@ var init_unifiedMemoryStore = __esm({
|
|
|
70286
70286
|
ORDER BY i.importance DESC, i.updated_at DESC, c.sequence ASC
|
|
70287
70287
|
LIMIT ?
|
|
70288
70288
|
`).all(embeddingSet.id, this.nowIso(), normalizeLimit(limit2, 100, 5e3));
|
|
70289
|
-
return
|
|
70289
|
+
return rows2.map(mapChunkRow);
|
|
70290
70290
|
}
|
|
70291
70291
|
upsertGraphNode(input) {
|
|
70292
70292
|
const id5 = input.id ?? randomUUID18();
|
|
@@ -70366,7 +70366,7 @@ var init_unifiedMemoryStore = __esm({
|
|
|
70366
70366
|
const filters = this.buildSearchFilters(options);
|
|
70367
70367
|
const nodeClauses = terms3.map(() => "(n.normalized_text LIKE ? OR n.text LIKE ?)").join(" OR ");
|
|
70368
70368
|
const nodeParams = terms3.flatMap((term) => [`%${term}%`, `%${term}%`]);
|
|
70369
|
-
const
|
|
70369
|
+
const rows2 = this.db.prepare(`
|
|
70370
70370
|
SELECT
|
|
70371
70371
|
${CANDIDATE_SELECT},
|
|
70372
70372
|
n.weight AS graph_node_weight,
|
|
@@ -70382,7 +70382,7 @@ var init_unifiedMemoryStore = __esm({
|
|
|
70382
70382
|
ORDER BY n.mention_count DESC, n.weight DESC, i.importance DESC, c.sequence ASC
|
|
70383
70383
|
LIMIT ?
|
|
70384
70384
|
`).all(...nodeParams, ...filters.params, limit2);
|
|
70385
|
-
return
|
|
70385
|
+
return rows2.map((row2, index) => {
|
|
70386
70386
|
const r = row2;
|
|
70387
70387
|
const hitScore = Math.min(1, toNumber(r.graph_mention_count, 1) / 10 * 0.4 + toNumber(r.graph_node_weight, 0.5) * 0.4 + toNumber(r.graph_item_weight, 0.5) * 0.2);
|
|
70388
70388
|
const rankScore = Math.max(hitScore, 1 / (index + 1));
|
|
@@ -70444,7 +70444,7 @@ var init_unifiedMemoryStore = __esm({
|
|
|
70444
70444
|
const amount = Math.abs(options.amount ?? 0.02);
|
|
70445
70445
|
const maxItems = normalizeLimit(options.maxItems, 100, 5e3);
|
|
70446
70446
|
const cutoff = new Date(this.now().getTime() - olderThanDays * 24 * 60 * 60 * 1e3).toISOString();
|
|
70447
|
-
const
|
|
70447
|
+
const rows2 = this.db.prepare(`
|
|
70448
70448
|
SELECT id
|
|
70449
70449
|
FROM memory_item
|
|
70450
70450
|
WHERE deleted_at IS NULL
|
|
@@ -70453,7 +70453,7 @@ var init_unifiedMemoryStore = __esm({
|
|
|
70453
70453
|
ORDER BY updated_at ASC
|
|
70454
70454
|
LIMIT ?
|
|
70455
70455
|
`).all(cutoff, maxItems);
|
|
70456
|
-
const itemIds =
|
|
70456
|
+
const itemIds = rows2.map((row2) => String(row2.id ?? "")).filter(Boolean);
|
|
70457
70457
|
if (itemIds.length === 0)
|
|
70458
70458
|
return { decayed: 0, itemIds: [] };
|
|
70459
70459
|
const txn = this.db.transaction(() => {
|
|
@@ -70533,7 +70533,7 @@ var init_unifiedMemoryStore = __esm({
|
|
|
70533
70533
|
const pattern = `%${term}%`;
|
|
70534
70534
|
return [pattern, pattern, pattern];
|
|
70535
70535
|
});
|
|
70536
|
-
const
|
|
70536
|
+
const rows2 = this.db.prepare(`
|
|
70537
70537
|
SELECT ${CANDIDATE_SELECT}
|
|
70538
70538
|
FROM memory_chunk c
|
|
70539
70539
|
JOIN memory_item i ON i.id = c.item_id
|
|
@@ -70543,7 +70543,7 @@ var init_unifiedMemoryStore = __esm({
|
|
|
70543
70543
|
ORDER BY i.importance DESC, i.updated_at DESC, c.sequence ASC
|
|
70544
70544
|
LIMIT ?
|
|
70545
70545
|
`).all(...params, ...filters.params, limit2);
|
|
70546
|
-
return
|
|
70546
|
+
return rows2.map((row2, index) => {
|
|
70547
70547
|
const score = 1 / (index + 1);
|
|
70548
70548
|
const match2 = mapCandidateRow(row2, "lexical", score);
|
|
70549
70549
|
match2.rank = index + 1;
|
|
@@ -71709,8 +71709,8 @@ var init_repoProfileStore = __esm({
|
|
|
71709
71709
|
}
|
|
71710
71710
|
/** List all stored repository profiles. */
|
|
71711
71711
|
list() {
|
|
71712
|
-
const
|
|
71713
|
-
return
|
|
71712
|
+
const rows2 = this.db.prepare("SELECT * FROM repo_profiles ORDER BY repo_root").all();
|
|
71713
|
+
return rows2.map(rowToProfile);
|
|
71714
71714
|
}
|
|
71715
71715
|
/** Remove a profile by repository root path. No-ops if not found. */
|
|
71716
71716
|
delete(repoRoot) {
|
|
@@ -71771,18 +71771,18 @@ var init_fileSummaryStore = __esm({
|
|
|
71771
71771
|
}
|
|
71772
71772
|
/** List all file summaries for a repository. */
|
|
71773
71773
|
listByRepo(repoRoot) {
|
|
71774
|
-
const
|
|
71775
|
-
return
|
|
71774
|
+
const rows2 = this.db.prepare("SELECT * FROM file_summaries WHERE repo_root = ? ORDER BY file_path").all(repoRoot);
|
|
71775
|
+
return rows2.map(rowToSummary);
|
|
71776
71776
|
}
|
|
71777
71777
|
/** List all file summaries belonging to a domain label. */
|
|
71778
71778
|
listByDomain(domain) {
|
|
71779
|
-
const
|
|
71780
|
-
return
|
|
71779
|
+
const rows2 = this.db.prepare("SELECT * FROM file_summaries WHERE domain = ? ORDER BY file_path").all(domain);
|
|
71780
|
+
return rows2.map(rowToSummary);
|
|
71781
71781
|
}
|
|
71782
71782
|
/** List all file summaries with the given risk level. */
|
|
71783
71783
|
listByRiskLevel(riskLevel) {
|
|
71784
|
-
const
|
|
71785
|
-
return
|
|
71784
|
+
const rows2 = this.db.prepare("SELECT * FROM file_summaries WHERE risk_level = ? ORDER BY file_path").all(riskLevel);
|
|
71785
|
+
return rows2.map(rowToSummary);
|
|
71786
71786
|
}
|
|
71787
71787
|
/** Remove a file summary by path. No-ops if not found. */
|
|
71788
71788
|
delete(filePath) {
|
|
@@ -71837,26 +71837,26 @@ var init_taskMemoryStore = __esm({
|
|
|
71837
71837
|
}
|
|
71838
71838
|
/** List all tasks associated with a session. */
|
|
71839
71839
|
listBySession(sessionId) {
|
|
71840
|
-
const
|
|
71841
|
-
return
|
|
71840
|
+
const rows2 = this.db.prepare("SELECT * FROM task_memory WHERE session_id = ? ORDER BY created_at DESC").all(sessionId);
|
|
71841
|
+
return rows2.map(rowToTask);
|
|
71842
71842
|
}
|
|
71843
71843
|
/** List all tasks for a repository root. */
|
|
71844
71844
|
listByRepo(repoRoot) {
|
|
71845
|
-
const
|
|
71846
|
-
return
|
|
71845
|
+
const rows2 = this.db.prepare("SELECT * FROM task_memory WHERE repo_root = ? ORDER BY created_at DESC").all(repoRoot);
|
|
71846
|
+
return rows2.map(rowToTask);
|
|
71847
71847
|
}
|
|
71848
71848
|
/** List tasks filtered by outcome. */
|
|
71849
71849
|
listByOutcome(outcome) {
|
|
71850
|
-
const
|
|
71851
|
-
return
|
|
71850
|
+
const rows2 = this.db.prepare("SELECT * FROM task_memory WHERE outcome = ? ORDER BY created_at DESC").all(outcome);
|
|
71851
|
+
return rows2.map(rowToTask);
|
|
71852
71852
|
}
|
|
71853
71853
|
/**
|
|
71854
71854
|
* Return the N most recently created tasks across all sessions and repos.
|
|
71855
71855
|
* Useful for building a rolling context window.
|
|
71856
71856
|
*/
|
|
71857
71857
|
recent(limit2) {
|
|
71858
|
-
const
|
|
71859
|
-
return
|
|
71858
|
+
const rows2 = this.db.prepare("SELECT * FROM task_memory ORDER BY created_at DESC LIMIT ?").all(limit2);
|
|
71859
|
+
return rows2.map(rowToTask);
|
|
71860
71860
|
}
|
|
71861
71861
|
};
|
|
71862
71862
|
}
|
|
@@ -71907,18 +71907,18 @@ var init_patchHistoryStore = __esm({
|
|
|
71907
71907
|
}
|
|
71908
71908
|
/** List all patches associated with a task. */
|
|
71909
71909
|
listByTask(taskId) {
|
|
71910
|
-
const
|
|
71911
|
-
return
|
|
71910
|
+
const rows2 = this.db.prepare("SELECT * FROM patch_history WHERE task_id = ? ORDER BY created_at ASC").all(taskId);
|
|
71911
|
+
return rows2.map(rowToPatch);
|
|
71912
71912
|
}
|
|
71913
71913
|
/** List all patches for a given file path (across all tasks). */
|
|
71914
71914
|
listByFile(filePath) {
|
|
71915
|
-
const
|
|
71916
|
-
return
|
|
71915
|
+
const rows2 = this.db.prepare("SELECT * FROM patch_history WHERE file_path = ? ORDER BY created_at DESC").all(filePath);
|
|
71916
|
+
return rows2.map(rowToPatch);
|
|
71917
71917
|
}
|
|
71918
71918
|
/** List patches filtered by status. */
|
|
71919
71919
|
listByStatus(status2) {
|
|
71920
|
-
const
|
|
71921
|
-
return
|
|
71920
|
+
const rows2 = this.db.prepare("SELECT * FROM patch_history WHERE status = ? ORDER BY created_at DESC").all(status2);
|
|
71921
|
+
return rows2.map(rowToPatch);
|
|
71922
71922
|
}
|
|
71923
71923
|
/**
|
|
71924
71924
|
* Update the lifecycle status of a patch and optionally set a timestamp.
|
|
@@ -71985,18 +71985,18 @@ var init_failureStore = __esm({
|
|
|
71985
71985
|
}
|
|
71986
71986
|
/** List failures filtered by type. */
|
|
71987
71987
|
listByType(failureType) {
|
|
71988
|
-
const
|
|
71989
|
-
return
|
|
71988
|
+
const rows2 = this.db.prepare("SELECT * FROM failures WHERE failure_type = ? ORDER BY created_at DESC").all(failureType);
|
|
71989
|
+
return rows2.map(rowToFailure);
|
|
71990
71990
|
}
|
|
71991
71991
|
/** List all failures sharing the same content fingerprint. */
|
|
71992
71992
|
listByFingerprint(fingerprint2) {
|
|
71993
|
-
const
|
|
71994
|
-
return
|
|
71993
|
+
const rows2 = this.db.prepare("SELECT * FROM failures WHERE fingerprint = ? ORDER BY created_at DESC").all(fingerprint2);
|
|
71994
|
+
return rows2.map(rowToFailure);
|
|
71995
71995
|
}
|
|
71996
71996
|
/** List all failures that have not yet been marked as resolved. */
|
|
71997
71997
|
listUnresolved() {
|
|
71998
|
-
const
|
|
71999
|
-
return
|
|
71998
|
+
const rows2 = this.db.prepare("SELECT * FROM failures WHERE resolved = 0 ORDER BY created_at DESC").all();
|
|
71999
|
+
return rows2.map(rowToFailure);
|
|
72000
72000
|
}
|
|
72001
72001
|
/**
|
|
72002
72002
|
* Mark a failure as resolved.
|
|
@@ -72061,18 +72061,18 @@ var init_validationStore = __esm({
|
|
|
72061
72061
|
}
|
|
72062
72062
|
/** List all validation runs for a given task. */
|
|
72063
72063
|
listByTask(taskId) {
|
|
72064
|
-
const
|
|
72065
|
-
return
|
|
72064
|
+
const rows2 = this.db.prepare("SELECT * FROM validation_runs WHERE task_id = ? ORDER BY created_at ASC").all(taskId);
|
|
72065
|
+
return rows2.map(rowToRun);
|
|
72066
72066
|
}
|
|
72067
72067
|
/** List validation runs filtered by run type. */
|
|
72068
72068
|
listByRunType(runType) {
|
|
72069
|
-
const
|
|
72070
|
-
return
|
|
72069
|
+
const rows2 = this.db.prepare("SELECT * FROM validation_runs WHERE run_type = ? ORDER BY created_at DESC").all(runType);
|
|
72070
|
+
return rows2.map(rowToRun);
|
|
72071
72071
|
}
|
|
72072
72072
|
/** List all failed validation runs. */
|
|
72073
72073
|
listFailed() {
|
|
72074
|
-
const
|
|
72075
|
-
return
|
|
72074
|
+
const rows2 = this.db.prepare("SELECT * FROM validation_runs WHERE passed = 0 ORDER BY created_at DESC").all();
|
|
72075
|
+
return rows2.map(rowToRun);
|
|
72076
72076
|
}
|
|
72077
72077
|
/**
|
|
72078
72078
|
* Return the most recent validation run for a task, or `null` if no runs
|
|
@@ -72145,17 +72145,17 @@ var init_toolPatternStore = __esm({
|
|
|
72145
72145
|
}
|
|
72146
72146
|
/** Get all sequences for a given repo */
|
|
72147
72147
|
listByRepo(repoRoot) {
|
|
72148
|
-
const
|
|
72148
|
+
const rows2 = this.db.prepare(`
|
|
72149
72149
|
SELECT * FROM tool_sequences WHERE repo_root = ? ORDER BY created_at DESC
|
|
72150
72150
|
`).all(repoRoot);
|
|
72151
|
-
return
|
|
72151
|
+
return rows2.map(this.hydrate);
|
|
72152
72152
|
}
|
|
72153
72153
|
/** Get recent sequences globally */
|
|
72154
72154
|
recent(limit2 = 20) {
|
|
72155
|
-
const
|
|
72155
|
+
const rows2 = this.db.prepare(`
|
|
72156
72156
|
SELECT * FROM tool_sequences ORDER BY created_at DESC LIMIT ?
|
|
72157
72157
|
`).all(limit2);
|
|
72158
|
-
return
|
|
72158
|
+
return rows2.map(this.hydrate);
|
|
72159
72159
|
}
|
|
72160
72160
|
/**
|
|
72161
72161
|
* Detect repeated patterns across recorded sequences.
|
|
@@ -72253,8 +72253,8 @@ var init_toolPatternStore = __esm({
|
|
|
72253
72253
|
params.push(scope);
|
|
72254
72254
|
}
|
|
72255
72255
|
query += " ORDER BY created_at DESC";
|
|
72256
|
-
const
|
|
72257
|
-
return
|
|
72256
|
+
const rows2 = this.db.prepare(query).all(...params);
|
|
72257
|
+
return rows2.map((r) => ({
|
|
72258
72258
|
name: r["name"],
|
|
72259
72259
|
scope: r["scope"],
|
|
72260
72260
|
createdAt: r["created_at"]
|
|
@@ -72638,13 +72638,13 @@ function buildTrace(input) {
|
|
|
72638
72638
|
consecutiveActions: Math.max(0, Math.floor(i.consecutiveActions ?? 0))
|
|
72639
72639
|
};
|
|
72640
72640
|
}
|
|
72641
|
-
function attachTrace(
|
|
72642
|
-
return { ...
|
|
72641
|
+
function attachTrace(metadata2, trace) {
|
|
72642
|
+
return { ...metadata2 ?? {}, [EMBODIED_KEY]: trace };
|
|
72643
72643
|
}
|
|
72644
|
-
function extractTrace(
|
|
72645
|
-
if (!
|
|
72644
|
+
function extractTrace(metadata2) {
|
|
72645
|
+
if (!metadata2 || typeof metadata2 !== "object")
|
|
72646
72646
|
return null;
|
|
72647
|
-
const raw =
|
|
72647
|
+
const raw = metadata2[EMBODIED_KEY];
|
|
72648
72648
|
if (!raw || typeof raw !== "object")
|
|
72649
72649
|
return null;
|
|
72650
72650
|
return buildTrace(raw);
|
|
@@ -72681,10 +72681,10 @@ var init_embodiedTrace = __esm({
|
|
|
72681
72681
|
});
|
|
72682
72682
|
|
|
72683
72683
|
// packages/memory/dist/pprRetrieval.js
|
|
72684
|
-
function readEpisodeAffect(
|
|
72685
|
-
if (!
|
|
72684
|
+
function readEpisodeAffect(metadata2) {
|
|
72685
|
+
if (!metadata2 || typeof metadata2 !== "object")
|
|
72686
72686
|
return null;
|
|
72687
|
-
const trace =
|
|
72687
|
+
const trace = metadata2["embodiedTrace"];
|
|
72688
72688
|
if (!trace || typeof trace !== "object")
|
|
72689
72689
|
return null;
|
|
72690
72690
|
const affect = trace["affect"];
|
|
@@ -72939,10 +72939,10 @@ import { join as join13 } from "node:path";
|
|
|
72939
72939
|
import { mkdirSync as mkdirSync7, existsSync as existsSync11 } from "node:fs";
|
|
72940
72940
|
import { randomUUID as randomUUID24 } from "node:crypto";
|
|
72941
72941
|
import { createHash as createHash23 } from "node:crypto";
|
|
72942
|
-
function readEpisodeAffect2(
|
|
72943
|
-
if (!
|
|
72942
|
+
function readEpisodeAffect2(metadata2) {
|
|
72943
|
+
if (!metadata2 || typeof metadata2 !== "object")
|
|
72944
72944
|
return null;
|
|
72945
|
-
const trace =
|
|
72945
|
+
const trace = metadata2["embodiedTrace"];
|
|
72946
72946
|
if (!trace || typeof trace !== "object")
|
|
72947
72947
|
return null;
|
|
72948
72948
|
const affect = trace["affect"];
|
|
@@ -72950,10 +72950,10 @@ function readEpisodeAffect2(metadata) {
|
|
|
72950
72950
|
return null;
|
|
72951
72951
|
return sanitizeEmotionalState(affect);
|
|
72952
72952
|
}
|
|
72953
|
-
function readEpisodeEngagement(
|
|
72954
|
-
if (!
|
|
72953
|
+
function readEpisodeEngagement(metadata2) {
|
|
72954
|
+
if (!metadata2 || typeof metadata2 !== "object")
|
|
72955
72955
|
return null;
|
|
72956
|
-
const trace =
|
|
72956
|
+
const trace = metadata2["embodiedTrace"];
|
|
72957
72957
|
if (!trace || typeof trace !== "object")
|
|
72958
72958
|
return null;
|
|
72959
72959
|
const t = trace;
|
|
@@ -73240,9 +73240,9 @@ var init_episodeStore = __esm({
|
|
|
73240
73240
|
}
|
|
73241
73241
|
sql += " ORDER BY timestamp DESC LIMIT ?";
|
|
73242
73242
|
params.push(Math.min(limit2 * 5, 500));
|
|
73243
|
-
let
|
|
73243
|
+
let rows2 = this.db.prepare(sql).all(...params);
|
|
73244
73244
|
if (query.metadataFilter || query.soundClass || query.rmsRange) {
|
|
73245
|
-
|
|
73245
|
+
rows2 = rows2.filter((row2) => {
|
|
73246
73246
|
let meta = null;
|
|
73247
73247
|
try {
|
|
73248
73248
|
meta = row2.metadata ? typeof row2.metadata === "string" ? JSON.parse(row2.metadata) : row2.metadata : null;
|
|
@@ -73271,7 +73271,7 @@ var init_episodeStore = __esm({
|
|
|
73271
73271
|
return true;
|
|
73272
73272
|
});
|
|
73273
73273
|
}
|
|
73274
|
-
const scored =
|
|
73274
|
+
const scored = rows2.map((row2) => {
|
|
73275
73275
|
const ep = this.rowToEpisode(row2);
|
|
73276
73276
|
const tau = DECAY_TAU[ep.decayClass] ?? DECAY_TAU.daily;
|
|
73277
73277
|
const recency = tau === Infinity ? 1 : Math.exp(-(now2 - ep.timestamp) / tau);
|
|
@@ -73400,19 +73400,19 @@ var init_episodeStore = __esm({
|
|
|
73400
73400
|
return false;
|
|
73401
73401
|
if (query.minImportance !== void 0 && episode.importance < query.minImportance)
|
|
73402
73402
|
return false;
|
|
73403
|
-
const
|
|
73403
|
+
const metadata2 = episode.metadata;
|
|
73404
73404
|
if (query.metadataFilter) {
|
|
73405
|
-
if (!
|
|
73405
|
+
if (!metadata2)
|
|
73406
73406
|
return false;
|
|
73407
73407
|
for (const [key, value] of Object.entries(query.metadataFilter)) {
|
|
73408
|
-
if (
|
|
73408
|
+
if (metadata2[key] !== value)
|
|
73409
73409
|
return false;
|
|
73410
73410
|
}
|
|
73411
73411
|
}
|
|
73412
|
-
if (query.soundClass &&
|
|
73412
|
+
if (query.soundClass && metadata2?.["sound_class"] !== query.soundClass)
|
|
73413
73413
|
return false;
|
|
73414
73414
|
if (query.rmsRange) {
|
|
73415
|
-
const rms =
|
|
73415
|
+
const rms = metadata2?.["rms_db"] ?? metadata2?.["rmsDb"];
|
|
73416
73416
|
if (typeof rms !== "number")
|
|
73417
73417
|
return false;
|
|
73418
73418
|
if (query.rmsRange.min !== void 0 && rms < query.rmsRange.min)
|
|
@@ -73724,10 +73724,10 @@ var init_audioObservationStore = __esm({
|
|
|
73724
73724
|
return embeddingFromRow(row2);
|
|
73725
73725
|
}
|
|
73726
73726
|
listEmbeddings(observationId) {
|
|
73727
|
-
const
|
|
73727
|
+
const rows2 = this.db.prepare(`
|
|
73728
73728
|
SELECT * FROM audio_observation_embedding WHERE observation_id = ? ORDER BY created_at ASC
|
|
73729
73729
|
`).all(observationId);
|
|
73730
|
-
return
|
|
73730
|
+
return rows2.map(embeddingFromRow);
|
|
73731
73731
|
}
|
|
73732
73732
|
/**
|
|
73733
73733
|
* List one exact, declared audio vector space without calculating similarity.
|
|
@@ -73742,7 +73742,7 @@ var init_audioObservationStore = __esm({
|
|
|
73742
73742
|
if (!Number.isInteger(maximum) || maximum < 1 || maximum > 5e3) {
|
|
73743
73743
|
throw new Error("limit must be a positive integer no greater than 5000");
|
|
73744
73744
|
}
|
|
73745
|
-
const
|
|
73745
|
+
const rows2 = this.db.prepare(`
|
|
73746
73746
|
SELECT
|
|
73747
73747
|
o.id AS observation_id, o.episode_id, o.asset_digest, o.source_uri, o.start_ms, o.end_ms,
|
|
73748
73748
|
o.channel, o.sample_rate_hz, o.diarization_cluster_id, o.observed_at,
|
|
@@ -73759,7 +73759,7 @@ var init_audioObservationStore = __esm({
|
|
|
73759
73759
|
ORDER BY e.created_at ASC, e.id ASC
|
|
73760
73760
|
LIMIT ?
|
|
73761
73761
|
`).all(options.role, embeddingSetSlug, text5(options.model, "model", true), text5(options.modelRevision, "modelRevision", true), text5(options.modelDigest, "modelDigest", true), maximum);
|
|
73762
|
-
return
|
|
73762
|
+
return rows2.map((row2) => ({
|
|
73763
73763
|
observation: observationFromRow({
|
|
73764
73764
|
id: row2.observation_id,
|
|
73765
73765
|
episode_id: row2.episode_id,
|
|
@@ -73801,7 +73801,7 @@ var init_audioObservationStore = __esm({
|
|
|
73801
73801
|
clauses.push("o.asset_digest = ?");
|
|
73802
73802
|
params.push(text5(options.assetDigest, "assetDigest", true));
|
|
73803
73803
|
}
|
|
73804
|
-
const
|
|
73804
|
+
const rows2 = this.db.prepare(`
|
|
73805
73805
|
SELECT
|
|
73806
73806
|
o.id AS observation_id, o.episode_id, o.asset_digest, o.source_uri, o.start_ms, o.end_ms,
|
|
73807
73807
|
o.channel, o.sample_rate_hz, o.diarization_cluster_id, o.observed_at,
|
|
@@ -73819,7 +73819,7 @@ var init_audioObservationStore = __esm({
|
|
|
73819
73819
|
if (!Number.isFinite(minScore) || minScore < 0 || minScore > 1) {
|
|
73820
73820
|
throw new Error("minScore must be between 0 and 1");
|
|
73821
73821
|
}
|
|
73822
|
-
return
|
|
73822
|
+
return rows2.map((row2) => {
|
|
73823
73823
|
const observation = observationFromRow({
|
|
73824
73824
|
id: row2.observation_id,
|
|
73825
73825
|
episode_id: row2.episode_id,
|
|
@@ -74388,12 +74388,12 @@ var init_speakerIdentityStore = __esm({
|
|
|
74388
74388
|
throw new Error("speaker identity query vector dimensions do not match the exact space contract");
|
|
74389
74389
|
}
|
|
74390
74390
|
const configured = thresholds(input.thresholds);
|
|
74391
|
-
const
|
|
74391
|
+
const rows2 = this.db.prepare(`
|
|
74392
74392
|
SELECT * FROM speaker_identity_profile
|
|
74393
74393
|
WHERE scope_id = ? AND embedding_set_slug = ? AND model = ? AND model_revision = ?
|
|
74394
74394
|
AND model_digest = ? AND dimensions = ? AND normalization = ?
|
|
74395
74395
|
`).all(scopeId, space.embeddingSetSlug, space.model, space.modelRevision, space.modelDigest, space.dimensions, space.normalization);
|
|
74396
|
-
const candidates =
|
|
74396
|
+
const candidates = rows2.map((row2) => {
|
|
74397
74397
|
const profile3 = this.profileFromRow(row2);
|
|
74398
74398
|
return {
|
|
74399
74399
|
profileId: profile3.id,
|
|
@@ -74829,7 +74829,7 @@ var init_multimodalIdentity = __esm({
|
|
|
74829
74829
|
const message = input.message;
|
|
74830
74830
|
const sender = input.sender;
|
|
74831
74831
|
const content = buildEpisodeContent(input);
|
|
74832
|
-
const
|
|
74832
|
+
const metadata2 = {
|
|
74833
74833
|
...input.metadata || {},
|
|
74834
74834
|
mmidVersion: 1,
|
|
74835
74835
|
sourceSurface,
|
|
@@ -74848,7 +74848,7 @@ var init_multimodalIdentity = __esm({
|
|
|
74848
74848
|
sessionId: input.sessionId,
|
|
74849
74849
|
modality,
|
|
74850
74850
|
content,
|
|
74851
|
-
metadata,
|
|
74851
|
+
metadata: metadata2,
|
|
74852
74852
|
toolName: "multimodal_identity_ingest",
|
|
74853
74853
|
decayClass: modality === "social" ? "permanent" : void 0
|
|
74854
74854
|
});
|
|
@@ -74918,7 +74918,7 @@ var init_multimodalIdentity = __esm({
|
|
|
74918
74918
|
});
|
|
74919
74919
|
}
|
|
74920
74920
|
if (input.transcript && input.transcript.trim()) {
|
|
74921
|
-
const transcriptMeta = { ...
|
|
74921
|
+
const transcriptMeta = { ...metadata2, sourceEpisodeId: episodeId, transcriptOf: episodeId };
|
|
74922
74922
|
const transcriptEpisodeId = this.episodeStore.insert({
|
|
74923
74923
|
sessionId: input.sessionId,
|
|
74924
74924
|
modality: "text",
|
|
@@ -75380,13 +75380,13 @@ var init_proceduralMemoryStore = __esm({
|
|
|
75380
75380
|
}
|
|
75381
75381
|
/** List all active memories, ordered by utility*confidence descending. */
|
|
75382
75382
|
list(limit2 = 100, offset = 0) {
|
|
75383
|
-
const
|
|
75383
|
+
const rows2 = this.db.prepare(`
|
|
75384
75384
|
SELECT * FROM procedural_memory
|
|
75385
75385
|
WHERE deleted_at IS NULL
|
|
75386
75386
|
ORDER BY (utility * confidence) DESC
|
|
75387
75387
|
LIMIT ? OFFSET ?
|
|
75388
75388
|
`).all(limit2, offset);
|
|
75389
|
-
return
|
|
75389
|
+
return rows2.map((r) => this._mapRow(r));
|
|
75390
75390
|
}
|
|
75391
75391
|
/** Update a memory. Creates a revision. */
|
|
75392
75392
|
update(id5, changes, model) {
|
|
@@ -75446,14 +75446,14 @@ var init_proceduralMemoryStore = __esm({
|
|
|
75446
75446
|
/** Full-text search across content, trigger, and steps. */
|
|
75447
75447
|
searchText(query, limit2 = 10) {
|
|
75448
75448
|
const pattern = `%${query}%`;
|
|
75449
|
-
const
|
|
75449
|
+
const rows2 = this.db.prepare(`
|
|
75450
75450
|
SELECT *, 1.0 as score FROM procedural_memory
|
|
75451
75451
|
WHERE deleted_at IS NULL
|
|
75452
75452
|
AND (content LIKE ? OR trigger_pattern LIKE ? OR steps LIKE ?)
|
|
75453
75453
|
ORDER BY (utility * confidence) DESC
|
|
75454
75454
|
LIMIT ?
|
|
75455
75455
|
`).all(pattern, pattern, pattern, limit2);
|
|
75456
|
-
return
|
|
75456
|
+
return rows2.map((r) => ({
|
|
75457
75457
|
memory: this._mapRow(r),
|
|
75458
75458
|
score: r.score,
|
|
75459
75459
|
matchType: "text"
|
|
@@ -75461,13 +75461,13 @@ var init_proceduralMemoryStore = __esm({
|
|
|
75461
75461
|
}
|
|
75462
75462
|
/** Semantic search using stored embeddings. */
|
|
75463
75463
|
searchSemantic(queryVector, limit2 = 5, minSimilarity = 0.3) {
|
|
75464
|
-
const
|
|
75464
|
+
const rows2 = this.db.prepare(`
|
|
75465
75465
|
SELECT pm.*, me.vector FROM procedural_memory pm
|
|
75466
75466
|
JOIN memory_embedding me ON me.memory_id = pm.id
|
|
75467
75467
|
WHERE pm.deleted_at IS NULL
|
|
75468
75468
|
`).all();
|
|
75469
75469
|
const results = [];
|
|
75470
|
-
for (const row2 of
|
|
75470
|
+
for (const row2 of rows2) {
|
|
75471
75471
|
const stored = new Float32Array(row2.vector.buffer, row2.vector.byteOffset, row2.vector.byteLength / 4);
|
|
75472
75472
|
const sim = cosineSimilarity2(queryVector, stored);
|
|
75473
75473
|
if (sim >= minSimilarity) {
|
|
@@ -75513,7 +75513,7 @@ var init_proceduralMemoryStore = __esm({
|
|
|
75513
75513
|
}
|
|
75514
75514
|
/** Find memories linked to the given memory ID. */
|
|
75515
75515
|
findLinked(memoryId, limit2 = 5) {
|
|
75516
|
-
const
|
|
75516
|
+
const rows2 = this.db.prepare(`
|
|
75517
75517
|
SELECT pm.*, ml.confidence as link_confidence FROM procedural_memory pm
|
|
75518
75518
|
JOIN memory_link ml ON (ml.target_id = pm.id AND ml.source_id = ?)
|
|
75519
75519
|
OR (ml.source_id = pm.id AND ml.target_id = ?)
|
|
@@ -75521,7 +75521,7 @@ var init_proceduralMemoryStore = __esm({
|
|
|
75521
75521
|
ORDER BY ml.confidence DESC
|
|
75522
75522
|
LIMIT ?
|
|
75523
75523
|
`).all(memoryId, memoryId, limit2);
|
|
75524
|
-
return
|
|
75524
|
+
return rows2.map((r) => ({
|
|
75525
75525
|
memory: this._mapRow(r),
|
|
75526
75526
|
confidence: r.link_confidence
|
|
75527
75527
|
}));
|
|
@@ -75529,10 +75529,10 @@ var init_proceduralMemoryStore = __esm({
|
|
|
75529
75529
|
// ── Revisions ───────────────────────────────────────────────────────
|
|
75530
75530
|
/** Get revision history for a memory. */
|
|
75531
75531
|
getRevisions(memoryId) {
|
|
75532
|
-
const
|
|
75532
|
+
const rows2 = this.db.prepare(`
|
|
75533
75533
|
SELECT * FROM memory_revision WHERE memory_id = ? ORDER BY created_at DESC
|
|
75534
75534
|
`).all(memoryId);
|
|
75535
|
-
return
|
|
75535
|
+
return rows2.map((r) => ({
|
|
75536
75536
|
id: r.id,
|
|
75537
75537
|
memoryId: r.memory_id,
|
|
75538
75538
|
content: r.content,
|
|
@@ -76268,7 +76268,7 @@ var init_memory2 = __esm({
|
|
|
76268
76268
|
const originalTokens = params.content.split(/\s+/).length;
|
|
76269
76269
|
const crlTokens = crlExpression.split(/\s+/).length;
|
|
76270
76270
|
const tokenSavings = 1 - crlTokens / originalTokens;
|
|
76271
|
-
const
|
|
76271
|
+
const metadata2 = {
|
|
76272
76272
|
originalText: params.content,
|
|
76273
76273
|
crlExpression,
|
|
76274
76274
|
concepts: concepts.map((c) => c.name),
|
|
@@ -76283,7 +76283,7 @@ var init_memory2 = __esm({
|
|
|
76283
76283
|
turnNumber: params.turnNumber ?? void 0,
|
|
76284
76284
|
toolName: params.toolName ?? "crl_encode",
|
|
76285
76285
|
importance: params.importance ?? 7,
|
|
76286
|
-
metadata
|
|
76286
|
+
metadata: metadata2
|
|
76287
76287
|
};
|
|
76288
76288
|
return this.episodeStore.insert(episode);
|
|
76289
76289
|
}
|
|
@@ -76295,7 +76295,7 @@ var init_memory2 = __esm({
|
|
|
76295
76295
|
const crlExpression = this.encoder.encode(resolved);
|
|
76296
76296
|
const concepts = this.encoder.extractConcepts(resolved);
|
|
76297
76297
|
const relations = this.encoder.extractRelations(resolved, concepts);
|
|
76298
|
-
const
|
|
76298
|
+
const metadata2 = {
|
|
76299
76299
|
originalText: params.template,
|
|
76300
76300
|
crlExpression,
|
|
76301
76301
|
concepts: concepts.map((c) => c.name),
|
|
@@ -76309,7 +76309,7 @@ var init_memory2 = __esm({
|
|
|
76309
76309
|
turnNumber: params.turnNumber ?? void 0,
|
|
76310
76310
|
toolName: "crl_template",
|
|
76311
76311
|
importance: params.importance ?? 7,
|
|
76312
|
-
metadata
|
|
76312
|
+
metadata: metadata2
|
|
76313
76313
|
};
|
|
76314
76314
|
return this.episodeStore.insert(episode);
|
|
76315
76315
|
}
|
|
@@ -76319,12 +76319,12 @@ var init_memory2 = __esm({
|
|
|
76319
76319
|
retrieveCRL(query, expand2 = true) {
|
|
76320
76320
|
const episodes = this.episodeStore.search(query);
|
|
76321
76321
|
return episodes.map((episode) => {
|
|
76322
|
-
const
|
|
76322
|
+
const metadata2 = episode.metadata;
|
|
76323
76323
|
const decoded = expand2 ? this.decoder.decode(episode.content) : episode.content;
|
|
76324
76324
|
return {
|
|
76325
76325
|
episode,
|
|
76326
76326
|
decoded,
|
|
76327
|
-
metadata
|
|
76327
|
+
metadata: metadata2
|
|
76328
76328
|
};
|
|
76329
76329
|
});
|
|
76330
76330
|
}
|
|
@@ -76339,14 +76339,14 @@ var init_memory2 = __esm({
|
|
|
76339
76339
|
const episodes = this.episodeStore.search(fullQuery);
|
|
76340
76340
|
const results = [];
|
|
76341
76341
|
for (const episode of episodes) {
|
|
76342
|
-
const
|
|
76343
|
-
if (!
|
|
76342
|
+
const metadata2 = episode.metadata;
|
|
76343
|
+
if (!metadata2?.concepts)
|
|
76344
76344
|
continue;
|
|
76345
76345
|
const conceptLower = concept.toLowerCase();
|
|
76346
|
-
const matches =
|
|
76346
|
+
const matches = metadata2.concepts.some((c) => c.toLowerCase().includes(conceptLower));
|
|
76347
76347
|
if (matches) {
|
|
76348
|
-
const conceptCount =
|
|
76349
|
-
const relevance = conceptCount /
|
|
76348
|
+
const conceptCount = metadata2.concepts.filter((c) => c.toLowerCase().includes(conceptLower)).length;
|
|
76349
|
+
const relevance = conceptCount / metadata2.concepts.length;
|
|
76350
76350
|
results.push({ episode, relevance });
|
|
76351
76351
|
}
|
|
76352
76352
|
}
|
|
@@ -76362,10 +76362,10 @@ var init_memory2 = __esm({
|
|
|
76362
76362
|
};
|
|
76363
76363
|
const episodes = this.episodeStore.search(fullQuery);
|
|
76364
76364
|
return episodes.filter((episode) => {
|
|
76365
|
-
const
|
|
76366
|
-
if (!
|
|
76365
|
+
const metadata2 = episode.metadata;
|
|
76366
|
+
if (!metadata2?.relations)
|
|
76367
76367
|
return false;
|
|
76368
|
-
return
|
|
76368
|
+
return metadata2.relations.some((r) => r.includes(operator));
|
|
76369
76369
|
});
|
|
76370
76370
|
}
|
|
76371
76371
|
/**
|
|
@@ -76383,14 +76383,14 @@ var init_memory2 = __esm({
|
|
|
76383
76383
|
let minSavings = 1;
|
|
76384
76384
|
let count2 = 0;
|
|
76385
76385
|
for (const episode of episodes) {
|
|
76386
|
-
const
|
|
76387
|
-
if (!
|
|
76386
|
+
const metadata2 = episode.metadata;
|
|
76387
|
+
if (!metadata2?.tokenSavings)
|
|
76388
76388
|
continue;
|
|
76389
76389
|
count2++;
|
|
76390
|
-
totalOriginal +=
|
|
76391
|
-
totalCRL +=
|
|
76392
|
-
maxSavings = Math.max(maxSavings,
|
|
76393
|
-
minSavings = Math.min(minSavings,
|
|
76390
|
+
totalOriginal += metadata2.originalText?.split(/\s+/).length ?? 0;
|
|
76391
|
+
totalCRL += metadata2.crlExpression.split(/\s+/).length;
|
|
76392
|
+
maxSavings = Math.max(maxSavings, metadata2.tokenSavings);
|
|
76393
|
+
minSavings = Math.min(minSavings, metadata2.tokenSavings);
|
|
76394
76394
|
}
|
|
76395
76395
|
return {
|
|
76396
76396
|
totalEpisodes: count2,
|
|
@@ -76422,7 +76422,7 @@ var init_memory2 = __esm({
|
|
|
76422
76422
|
const crlTokens = crlExpression.split(/\s+/).length;
|
|
76423
76423
|
const tokenSavings = 1 - crlTokens / originalTokens;
|
|
76424
76424
|
if (tokenSavings > 0.1) {
|
|
76425
|
-
const
|
|
76425
|
+
const metadata2 = {
|
|
76426
76426
|
originalText: episode.content,
|
|
76427
76427
|
crlExpression,
|
|
76428
76428
|
concepts: concepts.map((c) => c.name),
|
|
@@ -76436,7 +76436,7 @@ var init_memory2 = __esm({
|
|
|
76436
76436
|
turnNumber: episode.turnNumber ?? void 0,
|
|
76437
76437
|
toolName: "crl_compress",
|
|
76438
76438
|
importance: episode.importance,
|
|
76439
|
-
metadata
|
|
76439
|
+
metadata: metadata2
|
|
76440
76440
|
});
|
|
76441
76441
|
compressed++;
|
|
76442
76442
|
}
|
|
@@ -76641,8 +76641,8 @@ var init_converter = __esm({
|
|
|
76641
76641
|
let totalCRLTokens = 0;
|
|
76642
76642
|
for (const episode of episodes) {
|
|
76643
76643
|
result.processed++;
|
|
76644
|
-
const
|
|
76645
|
-
if (
|
|
76644
|
+
const metadata2 = episode.metadata;
|
|
76645
|
+
if (metadata2?.crlExpression || episode.toolName?.startsWith("crl_")) {
|
|
76646
76646
|
result.skipped++;
|
|
76647
76647
|
continue;
|
|
76648
76648
|
}
|
|
@@ -76719,7 +76719,7 @@ var init_converter = __esm({
|
|
|
76719
76719
|
}
|
|
76720
76720
|
for (const episode of crlEpisodes) {
|
|
76721
76721
|
try {
|
|
76722
|
-
const
|
|
76722
|
+
const metadata2 = episode.metadata;
|
|
76723
76723
|
const backup = this.backupManager.restoreEpisode(episode.id);
|
|
76724
76724
|
if (backup) {
|
|
76725
76725
|
const insert = {
|
|
@@ -76733,10 +76733,10 @@ var init_converter = __esm({
|
|
|
76733
76733
|
};
|
|
76734
76734
|
this.episodeStore.insert(insert);
|
|
76735
76735
|
result.restored++;
|
|
76736
|
-
} else if (
|
|
76736
|
+
} else if (metadata2?.originalText) {
|
|
76737
76737
|
const decoded = this.decoder.decode(episode.content);
|
|
76738
76738
|
const insert = {
|
|
76739
|
-
content:
|
|
76739
|
+
content: metadata2.originalText || decoded,
|
|
76740
76740
|
sessionId: episode.sessionId ?? void 0,
|
|
76741
76741
|
taskId: episode.taskId ?? void 0,
|
|
76742
76742
|
turnNumber: episode.turnNumber ?? void 0,
|
|
@@ -78029,8 +78029,8 @@ var init_selfModel = __esm({
|
|
|
78029
78029
|
for (const k of keys4)
|
|
78030
78030
|
out[k] = 0;
|
|
78031
78031
|
try {
|
|
78032
|
-
const
|
|
78033
|
-
for (const r of
|
|
78032
|
+
const rows2 = this.db.prepare(`SELECT ${column} AS k, COUNT(*) AS c FROM episodes GROUP BY ${column}`).all();
|
|
78033
|
+
for (const r of rows2)
|
|
78034
78034
|
out[r.k] = r.c;
|
|
78035
78035
|
} catch {
|
|
78036
78036
|
}
|
|
@@ -78060,20 +78060,20 @@ var init_selfModel = __esm({
|
|
|
78060
78060
|
}
|
|
78061
78061
|
idsByDecay(klass, cutoff) {
|
|
78062
78062
|
try {
|
|
78063
|
-
const
|
|
78064
|
-
return
|
|
78063
|
+
const rows2 = this.db.prepare(`SELECT id FROM episodes WHERE decay_class = ? AND timestamp <= ? ORDER BY timestamp ASC LIMIT 200`).all(klass, cutoff);
|
|
78064
|
+
return rows2.map((r) => r.id);
|
|
78065
78065
|
} catch {
|
|
78066
78066
|
return [];
|
|
78067
78067
|
}
|
|
78068
78068
|
}
|
|
78069
78069
|
weakProcedural(threshold) {
|
|
78070
78070
|
try {
|
|
78071
|
-
const
|
|
78071
|
+
const rows2 = this.db.prepare(`SELECT id FROM procedural_memory
|
|
78072
78072
|
WHERE deleted_at IS NULL
|
|
78073
78073
|
AND COALESCE(utility, 0.5) < ?
|
|
78074
78074
|
ORDER BY utility ASC
|
|
78075
78075
|
LIMIT 200`).all(threshold);
|
|
78076
|
-
return
|
|
78076
|
+
return rows2.map((r) => r.id);
|
|
78077
78077
|
} catch {
|
|
78078
78078
|
return [];
|
|
78079
78079
|
}
|
|
@@ -78082,8 +78082,8 @@ var init_selfModel = __esm({
|
|
|
78082
78082
|
* and convert to MetaKnowledgeTopic[]. Tolerates missing tables. */
|
|
78083
78083
|
queryEpisodeTopics(sql, k, prefixArgs = []) {
|
|
78084
78084
|
try {
|
|
78085
|
-
const
|
|
78086
|
-
return
|
|
78085
|
+
const rows2 = this.db.prepare(sql).all(...prefixArgs, k);
|
|
78086
|
+
return rows2.map((r) => ({
|
|
78087
78087
|
id: r.id,
|
|
78088
78088
|
label: (r.content ?? "").slice(0, 80),
|
|
78089
78089
|
score: typeof r.score === "number" ? r.score : 0
|
|
@@ -78096,12 +78096,12 @@ var init_selfModel = __esm({
|
|
|
78096
78096
|
* filtered to active (non-soft-deleted) rows. */
|
|
78097
78097
|
queryProceduralTopics(k) {
|
|
78098
78098
|
try {
|
|
78099
|
-
const
|
|
78099
|
+
const rows2 = this.db.prepare(`SELECT id, content, (COALESCE(utility, 0.5) * COALESCE(confidence, 0.5)) AS score
|
|
78100
78100
|
FROM procedural_memory
|
|
78101
78101
|
WHERE deleted_at IS NULL
|
|
78102
78102
|
ORDER BY score DESC
|
|
78103
78103
|
LIMIT ?`).all(k);
|
|
78104
|
-
return
|
|
78104
|
+
return rows2.map((r) => ({
|
|
78105
78105
|
id: r.id,
|
|
78106
78106
|
label: (r.content ?? "").slice(0, 80),
|
|
78107
78107
|
score: typeof r.score === "number" ? r.score : 0
|
|
@@ -78406,22 +78406,22 @@ function slowWaveReplay(db, options = {}) {
|
|
|
78406
78406
|
const delta = options.strengthDelta ?? 1;
|
|
78407
78407
|
const start = Date.now();
|
|
78408
78408
|
const cutoff = start - lookback;
|
|
78409
|
-
let
|
|
78409
|
+
let rows2 = [];
|
|
78410
78410
|
try {
|
|
78411
|
-
|
|
78411
|
+
rows2 = db.prepare(`SELECT id FROM episodes
|
|
78412
78412
|
WHERE importance >= ?
|
|
78413
78413
|
AND timestamp >= ?
|
|
78414
78414
|
ORDER BY importance DESC, timestamp DESC
|
|
78415
78415
|
LIMIT ?`).all(minImp, cutoff, topK);
|
|
78416
78416
|
} catch {
|
|
78417
|
-
|
|
78417
|
+
rows2 = [];
|
|
78418
78418
|
}
|
|
78419
|
-
if (
|
|
78419
|
+
if (rows2.length === 0) {
|
|
78420
78420
|
return {
|
|
78421
78421
|
cycle: emptyCycle("slow_wave", start)
|
|
78422
78422
|
};
|
|
78423
78423
|
}
|
|
78424
|
-
const ids =
|
|
78424
|
+
const ids = rows2.map((r) => r.id);
|
|
78425
78425
|
const placeholders2 = ids.map(() => "?").join(",");
|
|
78426
78426
|
const safeDelta = Number.isFinite(delta) ? delta : 1;
|
|
78427
78427
|
try {
|
|
@@ -78618,18 +78618,18 @@ function lightSleep(db, options = {}) {
|
|
|
78618
78618
|
const remaining = maxPrune - (pruned.length + compressed.length);
|
|
78619
78619
|
if (remaining <= 0)
|
|
78620
78620
|
break;
|
|
78621
|
-
let
|
|
78621
|
+
let rows2 = [];
|
|
78622
78622
|
try {
|
|
78623
|
-
|
|
78623
|
+
rows2 = db.prepare(`SELECT id, content FROM episodes
|
|
78624
78624
|
WHERE decay_class = ?
|
|
78625
78625
|
AND importance < ?
|
|
78626
78626
|
AND timestamp < ?
|
|
78627
78627
|
ORDER BY timestamp ASC
|
|
78628
78628
|
LIMIT ?`).all(klass, pruneImportance, cutoff, remaining);
|
|
78629
78629
|
} catch {
|
|
78630
|
-
|
|
78630
|
+
rows2 = [];
|
|
78631
78631
|
}
|
|
78632
|
-
if (
|
|
78632
|
+
if (rows2.length === 0)
|
|
78633
78633
|
continue;
|
|
78634
78634
|
if (compressMode) {
|
|
78635
78635
|
try {
|
|
@@ -78637,7 +78637,7 @@ function lightSleep(db, options = {}) {
|
|
|
78637
78637
|
SET content = ?,
|
|
78638
78638
|
metadata = json_patch(COALESCE(metadata, '{}'), json_object('compressedAt', ?))
|
|
78639
78639
|
WHERE id = ?`);
|
|
78640
|
-
for (const row2 of
|
|
78640
|
+
for (const row2 of rows2) {
|
|
78641
78641
|
const truncated = (row2.content ?? "").slice(0, gistMaxChars);
|
|
78642
78642
|
const gist = (row2.content ?? "").length > gistMaxChars ? truncated + "…" : truncated;
|
|
78643
78643
|
try {
|
|
@@ -78654,7 +78654,7 @@ function lightSleep(db, options = {}) {
|
|
|
78654
78654
|
} catch {
|
|
78655
78655
|
}
|
|
78656
78656
|
} else {
|
|
78657
|
-
const ids =
|
|
78657
|
+
const ids = rows2.map((r) => r.id);
|
|
78658
78658
|
try {
|
|
78659
78659
|
const placeholders2 = ids.map(() => "?").join(",");
|
|
78660
78660
|
db.prepare(`DELETE FROM episodes WHERE id IN (${placeholders2})`).run(...ids);
|
|
@@ -78668,7 +78668,7 @@ function lightSleep(db, options = {}) {
|
|
|
78668
78668
|
const hubThreshold = Math.max(1, options.hubThreshold ?? 50);
|
|
78669
78669
|
const flaggedHubs = [];
|
|
78670
78670
|
try {
|
|
78671
|
-
const
|
|
78671
|
+
const rows2 = db.prepare(`SELECT node_id, edge_count FROM (
|
|
78672
78672
|
SELECT src_id AS node_id, COUNT(*) AS edge_count FROM kg_edges GROUP BY src_id
|
|
78673
78673
|
UNION ALL
|
|
78674
78674
|
SELECT dst_id AS node_id, COUNT(*) AS edge_count FROM kg_edges GROUP BY dst_id
|
|
@@ -78677,7 +78677,7 @@ function lightSleep(db, options = {}) {
|
|
|
78677
78677
|
HAVING SUM(edge_count) >= ?
|
|
78678
78678
|
ORDER BY SUM(edge_count) DESC
|
|
78679
78679
|
LIMIT 50`).all(hubThreshold);
|
|
78680
|
-
for (const r of
|
|
78680
|
+
for (const r of rows2)
|
|
78681
78681
|
flaggedHubs.push(r.node_id);
|
|
78682
78682
|
} catch {
|
|
78683
78683
|
}
|
|
@@ -78925,16 +78925,16 @@ var init_socialMemory = __esm({
|
|
|
78925
78925
|
};
|
|
78926
78926
|
for (const k of Object.keys(trustByDomain))
|
|
78927
78927
|
trustByDomain[k] = clamp0110(trustByDomain[k]);
|
|
78928
|
-
const
|
|
78928
|
+
const metadata2 = input.metadata ?? existing?.metadata ?? null;
|
|
78929
78929
|
if (existing) {
|
|
78930
78930
|
this.db.prepare(`UPDATE social_agents
|
|
78931
78931
|
SET name = ?, type = ?, last_interaction = ?,
|
|
78932
78932
|
personality = ?, trust = ?, metadata = ?
|
|
78933
|
-
WHERE id = ?`).run(input.name, input.type ?? existing.type, now2, JSON.stringify(personality), JSON.stringify({ overall: trustOverall, byDomain: trustByDomain }),
|
|
78933
|
+
WHERE id = ?`).run(input.name, input.type ?? existing.type, now2, JSON.stringify(personality), JSON.stringify({ overall: trustOverall, byDomain: trustByDomain }), metadata2 ? JSON.stringify(metadata2) : null, id5);
|
|
78934
78934
|
} else {
|
|
78935
78935
|
this.db.prepare(`INSERT INTO social_agents
|
|
78936
78936
|
(id, name, type, first_met, last_interaction, interaction_count, personality, trust, metadata)
|
|
78937
|
-
VALUES (?, ?, ?, ?, ?, 0, ?, ?, ?)`).run(id5, input.name, input.type ?? "agent", now2, now2, JSON.stringify(personality), JSON.stringify({ overall: trustOverall, byDomain: trustByDomain }),
|
|
78937
|
+
VALUES (?, ?, ?, ?, ?, 0, ?, ?, ?)`).run(id5, input.name, input.type ?? "agent", now2, now2, JSON.stringify(personality), JSON.stringify({ overall: trustOverall, byDomain: trustByDomain }), metadata2 ? JSON.stringify(metadata2) : null);
|
|
78938
78938
|
}
|
|
78939
78939
|
return this.getAgent(id5);
|
|
78940
78940
|
}
|
|
@@ -78945,8 +78945,8 @@ var init_socialMemory = __esm({
|
|
|
78945
78945
|
return rowToAgent(row2);
|
|
78946
78946
|
}
|
|
78947
78947
|
listAgents() {
|
|
78948
|
-
const
|
|
78949
|
-
return
|
|
78948
|
+
const rows2 = this.db.prepare(`SELECT * FROM social_agents ORDER BY last_interaction DESC`).all();
|
|
78949
|
+
return rows2.map(rowToAgent);
|
|
78950
78950
|
}
|
|
78951
78951
|
updateAgent(id5, update) {
|
|
78952
78952
|
if (!this.getAgent(id5))
|
|
@@ -79023,8 +79023,8 @@ var init_socialMemory = __esm({
|
|
|
79023
79023
|
return rowToRelationship(row2);
|
|
79024
79024
|
}
|
|
79025
79025
|
listRelationshipsFor(agent) {
|
|
79026
|
-
const
|
|
79027
|
-
return
|
|
79026
|
+
const rows2 = this.db.prepare(`SELECT * FROM social_relationships WHERE agent_a = ? OR agent_b = ?`).all(agent, agent);
|
|
79027
|
+
return rows2.map(rowToRelationship);
|
|
79028
79028
|
}
|
|
79029
79029
|
// ── Social lessons ────────────────────────────────────────────────────────
|
|
79030
79030
|
recordLesson(input) {
|
|
@@ -79041,8 +79041,8 @@ var init_socialMemory = __esm({
|
|
|
79041
79041
|
return (r.changes ?? 0) > 0;
|
|
79042
79042
|
}
|
|
79043
79043
|
listLessons(sourceAgent) {
|
|
79044
|
-
const
|
|
79045
|
-
return
|
|
79044
|
+
const rows2 = sourceAgent ? this.db.prepare(`SELECT * FROM social_lessons WHERE source_agent = ? ORDER BY timestamp DESC`).all(sourceAgent) : this.db.prepare(`SELECT * FROM social_lessons ORDER BY timestamp DESC`).all();
|
|
79045
|
+
return rows2.map(rowToLesson);
|
|
79046
79046
|
}
|
|
79047
79047
|
// ── MEM_GAP B6: collective memory ────────────────────────────────────────
|
|
79048
79048
|
recordOpinion(input) {
|
|
@@ -79061,8 +79061,8 @@ var init_socialMemory = __esm({
|
|
|
79061
79061
|
* - divergence: 1 - agreementScore.
|
|
79062
79062
|
*/
|
|
79063
79063
|
getConsensus(topic) {
|
|
79064
|
-
const
|
|
79065
|
-
const opinions =
|
|
79064
|
+
const rows2 = this.db.prepare(`SELECT * FROM social_shared_knowledge WHERE topic = ? ORDER BY timestamp DESC`).all(topic);
|
|
79065
|
+
const opinions = rows2.map(rowToOpinion);
|
|
79066
79066
|
if (opinions.length === 0) {
|
|
79067
79067
|
return { contributors: 0, agreementScore: 1, divergence: 0, opinions };
|
|
79068
79068
|
}
|
|
@@ -79082,8 +79082,8 @@ var init_socialMemory = __esm({
|
|
|
79082
79082
|
};
|
|
79083
79083
|
}
|
|
79084
79084
|
listOpinions(topic) {
|
|
79085
|
-
const
|
|
79086
|
-
return
|
|
79085
|
+
const rows2 = topic ? this.db.prepare(`SELECT * FROM social_shared_knowledge WHERE topic = ? ORDER BY timestamp DESC`).all(topic) : this.db.prepare(`SELECT * FROM social_shared_knowledge ORDER BY timestamp DESC`).all();
|
|
79086
|
+
return rows2.map(rowToOpinion);
|
|
79087
79087
|
}
|
|
79088
79088
|
};
|
|
79089
79089
|
}
|
|
@@ -79256,10 +79256,10 @@ function buildGist(input) {
|
|
|
79256
79256
|
function goalHashOf(goal) {
|
|
79257
79257
|
return computeGoalHash(goal);
|
|
79258
79258
|
}
|
|
79259
|
-
function isSessionGist(
|
|
79260
|
-
if (!
|
|
79259
|
+
function isSessionGist(metadata2) {
|
|
79260
|
+
if (!metadata2 || typeof metadata2 !== "object")
|
|
79261
79261
|
return false;
|
|
79262
|
-
const m =
|
|
79262
|
+
const m = metadata2;
|
|
79263
79263
|
return m["kind"] === "session_gist" && typeof m["goalHash"] === "string";
|
|
79264
79264
|
}
|
|
79265
79265
|
var DOMAIN_KEYWORDS;
|
|
@@ -79454,12 +79454,12 @@ function lookupBySignature(store, signature, limit2 = 3) {
|
|
|
79454
79454
|
const lim = Math.max(1, Math.min(20, limit2));
|
|
79455
79455
|
try {
|
|
79456
79456
|
const db = store.getDb();
|
|
79457
|
-
const
|
|
79457
|
+
const rows2 = db.prepare(`SELECT id, content, metadata, timestamp FROM episodes
|
|
79458
79458
|
WHERE tool_name = 'stagnation_recipe'
|
|
79459
79459
|
ORDER BY timestamp DESC
|
|
79460
79460
|
LIMIT 200`).all();
|
|
79461
79461
|
const out = [];
|
|
79462
|
-
for (const r of
|
|
79462
|
+
for (const r of rows2) {
|
|
79463
79463
|
try {
|
|
79464
79464
|
const m = r.metadata ? JSON.parse(r.metadata) : null;
|
|
79465
79465
|
if (m && m.signature === signature) {
|
|
@@ -79534,9 +79534,9 @@ var init_codebaseMap = __esm({
|
|
|
79534
79534
|
let nodes = 0;
|
|
79535
79535
|
let edges = 0;
|
|
79536
79536
|
try {
|
|
79537
|
-
const
|
|
79538
|
-
nodes =
|
|
79539
|
-
for (const r of
|
|
79537
|
+
const rows2 = this.db.prepare(`SELECT path FROM codebase_map_node WHERE repo_fp = ?`).all(this.repoFp);
|
|
79538
|
+
nodes = rows2.length;
|
|
79539
|
+
for (const r of rows2) {
|
|
79540
79540
|
this.touchCount.set(r.path, 1);
|
|
79541
79541
|
}
|
|
79542
79542
|
const erows = this.db.prepare(`SELECT COUNT(*) AS c FROM codebase_map_edge WHERE repo_fp = ?`).get(this.repoFp);
|
|
@@ -79590,12 +79590,12 @@ var init_codebaseMap = __esm({
|
|
|
79590
79590
|
topFiles(limit2 = 15) {
|
|
79591
79591
|
const lim = Math.max(1, Math.min(100, limit2));
|
|
79592
79592
|
try {
|
|
79593
|
-
const
|
|
79593
|
+
const rows2 = this.db.prepare(`SELECT path, last_touched_ts, last_result, metadata FROM codebase_map_node
|
|
79594
79594
|
WHERE repo_fp = ? AND kind = 'file'
|
|
79595
79595
|
ORDER BY last_touched_ts DESC
|
|
79596
79596
|
LIMIT ?`).all(this.repoFp, lim);
|
|
79597
79597
|
const out = [];
|
|
79598
|
-
for (const r of
|
|
79598
|
+
for (const r of rows2) {
|
|
79599
79599
|
let count2 = 1;
|
|
79600
79600
|
try {
|
|
79601
79601
|
const m = r.metadata ? JSON.parse(r.metadata) : null;
|
|
@@ -79613,11 +79613,11 @@ var init_codebaseMap = __esm({
|
|
|
79613
79613
|
topTests(limit2 = 15) {
|
|
79614
79614
|
const lim = Math.max(1, Math.min(100, limit2));
|
|
79615
79615
|
try {
|
|
79616
|
-
const
|
|
79616
|
+
const rows2 = this.db.prepare(`SELECT path AS name, last_result AS result, last_touched_ts AS ts FROM codebase_map_node
|
|
79617
79617
|
WHERE repo_fp = ? AND kind = 'test'
|
|
79618
79618
|
ORDER BY last_touched_ts DESC
|
|
79619
79619
|
LIMIT ?`).all(this.repoFp, lim);
|
|
79620
|
-
return
|
|
79620
|
+
return rows2.map((r) => ({ name: r.name, result: r.result || "?", ts: r.ts }));
|
|
79621
79621
|
} catch {
|
|
79622
79622
|
return [];
|
|
79623
79623
|
}
|
|
@@ -79738,18 +79738,18 @@ async function reembedAll(db, embedFn, opts = {}) {
|
|
|
79738
79738
|
let skipped = 0;
|
|
79739
79739
|
let offset = 0;
|
|
79740
79740
|
while (offset < total) {
|
|
79741
|
-
let
|
|
79741
|
+
let rows2 = [];
|
|
79742
79742
|
try {
|
|
79743
|
-
|
|
79743
|
+
rows2 = db.prepare(`SELECT id, content FROM episodes
|
|
79744
79744
|
WHERE content IS NOT NULL AND length(content) > 0
|
|
79745
79745
|
ORDER BY rowid ASC LIMIT ? OFFSET ?`).all(batch, offset);
|
|
79746
79746
|
} catch {
|
|
79747
79747
|
break;
|
|
79748
79748
|
}
|
|
79749
|
-
if (
|
|
79749
|
+
if (rows2.length === 0)
|
|
79750
79750
|
break;
|
|
79751
79751
|
const updates = [];
|
|
79752
|
-
for (const r of
|
|
79752
|
+
for (const r of rows2) {
|
|
79753
79753
|
try {
|
|
79754
79754
|
const vec = await embedFn(r.content);
|
|
79755
79755
|
if (vec && vec.length > 0) {
|
|
@@ -79774,14 +79774,14 @@ async function reembedAll(db, embedFn, opts = {}) {
|
|
|
79774
79774
|
} catch {
|
|
79775
79775
|
}
|
|
79776
79776
|
}
|
|
79777
|
-
done +=
|
|
79777
|
+
done += rows2.length;
|
|
79778
79778
|
if (opts.onProgress) {
|
|
79779
79779
|
try {
|
|
79780
79780
|
opts.onProgress(done, total);
|
|
79781
79781
|
} catch {
|
|
79782
79782
|
}
|
|
79783
79783
|
}
|
|
79784
|
-
offset +=
|
|
79784
|
+
offset += rows2.length;
|
|
79785
79785
|
}
|
|
79786
79786
|
return { reembedded, skipped, total };
|
|
79787
79787
|
}
|
|
@@ -80476,8 +80476,8 @@ function deleteEpisodes(db, ids, dryRun) {
|
|
|
80476
80476
|
return unique4.length;
|
|
80477
80477
|
let deleted = 0;
|
|
80478
80478
|
const stmt = db.prepare(`DELETE FROM episodes WHERE id = ?`);
|
|
80479
|
-
const tx = db.transaction((
|
|
80480
|
-
for (const id5 of
|
|
80479
|
+
const tx = db.transaction((rows2) => {
|
|
80480
|
+
for (const id5 of rows2) {
|
|
80481
80481
|
const result = stmt.run(id5);
|
|
80482
80482
|
deleted += Number(result.changes ?? 0);
|
|
80483
80483
|
}
|
|
@@ -80557,10 +80557,10 @@ function loadGraphNodeCandidates(db, limit2) {
|
|
|
80557
80557
|
return [];
|
|
80558
80558
|
}
|
|
80559
80559
|
}
|
|
80560
|
-
function vectorDuplicateNodePairs(
|
|
80560
|
+
function vectorDuplicateNodePairs(rows2, threshold) {
|
|
80561
80561
|
const pairs = [];
|
|
80562
80562
|
const buckets = /* @__PURE__ */ new Map();
|
|
80563
|
-
for (const row2 of
|
|
80563
|
+
for (const row2 of rows2) {
|
|
80564
80564
|
const bucketKey = row2.nodeType || "entity";
|
|
80565
80565
|
const bucket = buckets.get(bucketKey) ?? [];
|
|
80566
80566
|
const vector = vectorFor(row2.embedding, row2.text);
|
|
@@ -80597,7 +80597,7 @@ function mergeGraphNodes(db, pairs, dryRun) {
|
|
|
80597
80597
|
if (dryRun || unique4.length === 0)
|
|
80598
80598
|
return unique4.length;
|
|
80599
80599
|
let merged = 0;
|
|
80600
|
-
const tx = db.transaction((
|
|
80600
|
+
const tx = db.transaction((rows2) => {
|
|
80601
80601
|
const src = db.prepare(`UPDATE kg_edges SET src_id = ? WHERE src_id = ?`);
|
|
80602
80602
|
const dst = db.prepare(`UPDATE kg_edges SET dst_id = ? WHERE dst_id = ?`);
|
|
80603
80603
|
const del = db.prepare(`DELETE FROM kg_nodes WHERE id = ?`);
|
|
@@ -80605,7 +80605,7 @@ function mergeGraphNodes(db, pairs, dryRun) {
|
|
|
80605
80605
|
SET mention_count = mention_count + COALESCE((SELECT mention_count FROM kg_nodes WHERE id = ?), 0),
|
|
80606
80606
|
last_seen = MAX(last_seen, COALESCE((SELECT last_seen FROM kg_nodes WHERE id = ?), last_seen))
|
|
80607
80607
|
WHERE id = ?`);
|
|
80608
|
-
for (const pair of
|
|
80608
|
+
for (const pair of rows2) {
|
|
80609
80609
|
bump.run(pair.dropId, pair.dropId, pair.keepId);
|
|
80610
80610
|
src.run(pair.keepId, pair.dropId);
|
|
80611
80611
|
dst.run(pair.keepId, pair.dropId);
|
|
@@ -80773,8 +80773,8 @@ function reinforceGraphNodes(dbPath, ids) {
|
|
|
80773
80773
|
const now2 = Date.now();
|
|
80774
80774
|
const stmt = db.prepare("UPDATE kg_nodes SET last_seen = ?, mention_count = COALESCE(mention_count, 1) + 1 WHERE id = ?");
|
|
80775
80775
|
let updated = 0;
|
|
80776
|
-
const tx = db.transaction((
|
|
80777
|
-
for (const id5 of
|
|
80776
|
+
const tx = db.transaction((rows2) => {
|
|
80777
|
+
for (const id5 of rows2)
|
|
80778
80778
|
updated += Number(stmt.run(now2, id5).changes ?? 0);
|
|
80779
80779
|
});
|
|
80780
80780
|
tx(ids);
|
|
@@ -80839,8 +80839,8 @@ function archiveAndDeleteNodes(db, dbPath, ids, archive) {
|
|
|
80839
80839
|
function deleteById(db, table, ids) {
|
|
80840
80840
|
let deleted = 0;
|
|
80841
80841
|
const stmt = db.prepare(`DELETE FROM ${table} WHERE id = ?`);
|
|
80842
|
-
const tx = db.transaction((
|
|
80843
|
-
for (const id5 of
|
|
80842
|
+
const tx = db.transaction((rows2) => {
|
|
80843
|
+
for (const id5 of rows2) {
|
|
80844
80844
|
const result = stmt.run(id5);
|
|
80845
80845
|
deleted += Number(result.changes ?? 0);
|
|
80846
80846
|
}
|
|
@@ -80848,10 +80848,10 @@ function deleteById(db, table, ids) {
|
|
|
80848
80848
|
tx(ids);
|
|
80849
80849
|
return deleted;
|
|
80850
80850
|
}
|
|
80851
|
-
function vectorDuplicateIds(
|
|
80851
|
+
function vectorDuplicateIds(rows2, threshold) {
|
|
80852
80852
|
const duplicateIds = [];
|
|
80853
80853
|
const buckets = /* @__PURE__ */ new Map();
|
|
80854
|
-
for (const row2 of
|
|
80854
|
+
for (const row2 of rows2) {
|
|
80855
80855
|
const key = `${row2.toolName}\0${row2.modality}`;
|
|
80856
80856
|
const bucket = buckets.get(key) ?? [];
|
|
80857
80857
|
const vector = vectorFor(row2.embedding, row2.content);
|
|
@@ -197486,12 +197486,12 @@ ${lanes.join("\n")}
|
|
|
197486
197486
|
return members;
|
|
197487
197487
|
}
|
|
197488
197488
|
function injectClassTypeMetadata(modifiers, node) {
|
|
197489
|
-
const
|
|
197490
|
-
if (some(
|
|
197489
|
+
const metadata2 = getTypeMetadata(node, node);
|
|
197490
|
+
if (some(metadata2)) {
|
|
197491
197491
|
const modifiersArray = [];
|
|
197492
197492
|
addRange(modifiersArray, takeWhile(modifiers, isExportOrDefaultModifier));
|
|
197493
197493
|
addRange(modifiersArray, filter2(modifiers, isDecorator));
|
|
197494
|
-
addRange(modifiersArray,
|
|
197494
|
+
addRange(modifiersArray, metadata2);
|
|
197495
197495
|
addRange(modifiersArray, filter2(skipWhile(modifiers, isExportOrDefaultModifier), isModifier));
|
|
197496
197496
|
modifiers = setTextRange(factory2.createNodeArray(modifiersArray), modifiers);
|
|
197497
197497
|
}
|
|
@@ -197499,11 +197499,11 @@ ${lanes.join("\n")}
|
|
|
197499
197499
|
}
|
|
197500
197500
|
function injectClassElementTypeMetadata(modifiers, node, container) {
|
|
197501
197501
|
if (isClassLike(container) && classElementOrClassElementParameterIsDecorated(legacyDecorators, node, container)) {
|
|
197502
|
-
const
|
|
197503
|
-
if (some(
|
|
197502
|
+
const metadata2 = getTypeMetadata(node, container);
|
|
197503
|
+
if (some(metadata2)) {
|
|
197504
197504
|
const modifiersArray = [];
|
|
197505
197505
|
addRange(modifiersArray, filter2(modifiers, isDecorator));
|
|
197506
|
-
addRange(modifiersArray,
|
|
197506
|
+
addRange(modifiersArray, metadata2);
|
|
197507
197507
|
addRange(modifiersArray, filter2(modifiers, isModifier));
|
|
197508
197508
|
modifiers = setTextRange(factory2.createNodeArray(modifiersArray), modifiers);
|
|
197509
197509
|
}
|
|
@@ -201883,11 +201883,11 @@ ${lanes.join("\n")}
|
|
|
201883
201883
|
if (!allDecorators) {
|
|
201884
201884
|
return void 0;
|
|
201885
201885
|
}
|
|
201886
|
-
const { false: decorators, true:
|
|
201886
|
+
const { false: decorators, true: metadata2 } = groupBy2(allDecorators.decorators, isSyntheticMetadataDecorator);
|
|
201887
201887
|
const decoratorExpressions = [];
|
|
201888
201888
|
addRange(decoratorExpressions, map(decorators, transformDecorator));
|
|
201889
201889
|
addRange(decoratorExpressions, flatMap(allDecorators.parameters, transformDecoratorsOfParameter));
|
|
201890
|
-
addRange(decoratorExpressions, map(
|
|
201890
|
+
addRange(decoratorExpressions, map(metadata2, transformDecorator));
|
|
201891
201891
|
return decoratorExpressions;
|
|
201892
201892
|
}
|
|
201893
201893
|
function addClassElementDecorationStatements(statements, node, isStatic2) {
|
|
@@ -299161,23 +299161,23 @@ Project '${project.projectName}' (${ProjectKind[project.projectKind]}) ${counter
|
|
|
299161
299161
|
performanceData: performanceData && toProtocolPerformanceData(performanceData)
|
|
299162
299162
|
};
|
|
299163
299163
|
if (success) {
|
|
299164
|
-
let
|
|
299164
|
+
let metadata2;
|
|
299165
299165
|
if (isArray(info)) {
|
|
299166
299166
|
res.body = info;
|
|
299167
|
-
|
|
299167
|
+
metadata2 = info.metadata;
|
|
299168
299168
|
delete info.metadata;
|
|
299169
299169
|
} else if (typeof info === "object") {
|
|
299170
299170
|
if (info.metadata) {
|
|
299171
299171
|
const { metadata: infoMetadata, ...body } = info;
|
|
299172
299172
|
res.body = body;
|
|
299173
|
-
|
|
299173
|
+
metadata2 = infoMetadata;
|
|
299174
299174
|
} else {
|
|
299175
299175
|
res.body = info;
|
|
299176
299176
|
}
|
|
299177
299177
|
} else {
|
|
299178
299178
|
res.body = info;
|
|
299179
299179
|
}
|
|
299180
|
-
if (
|
|
299180
|
+
if (metadata2) res.metadata = metadata2;
|
|
299181
299181
|
} else {
|
|
299182
299182
|
Debug.assert(info === void 0);
|
|
299183
299183
|
}
|
|
@@ -333104,9 +333104,9 @@ var init_code_graph_db = __esm({
|
|
|
333104
333104
|
if (visited.size >= limit2)
|
|
333105
333105
|
break;
|
|
333106
333106
|
if (chaseKinds.length > 0) {
|
|
333107
|
-
const
|
|
333107
|
+
const rows2 = this.db.prepare(`SELECT target_file as dst, edge_type as kind FROM edges
|
|
333108
333108
|
WHERE source_file = ? AND edge_type IN (${chaseKinds.map(() => "?").join(",")})`).all(node, ...chaseKinds);
|
|
333109
|
-
for (const r of
|
|
333109
|
+
for (const r of rows2) {
|
|
333110
333110
|
edges.push({ src: node, dst: r.dst, kind: r.kind });
|
|
333111
333111
|
if (!visited.has(r.dst)) {
|
|
333112
333112
|
visited.set(r.dst, d);
|
|
@@ -333115,10 +333115,10 @@ var init_code_graph_db = __esm({
|
|
|
333115
333115
|
}
|
|
333116
333116
|
}
|
|
333117
333117
|
if (annotateKinds.length > 0) {
|
|
333118
|
-
const
|
|
333118
|
+
const rows2 = this.db.prepare(`SELECT target_symbol as dst, edge_type as kind FROM edges
|
|
333119
333119
|
WHERE source_file = ? AND edge_type IN (${annotateKinds.map(() => "?").join(",")})
|
|
333120
333120
|
LIMIT 200`).all(node, ...annotateKinds);
|
|
333121
|
-
for (const r of
|
|
333121
|
+
for (const r of rows2) {
|
|
333122
333122
|
if (r.dst)
|
|
333123
333123
|
edges.push({ src: node, dst: r.dst, kind: r.kind });
|
|
333124
333124
|
}
|
|
@@ -340806,19 +340806,19 @@ function resolveProviderTransport(options) {
|
|
|
340806
340806
|
};
|
|
340807
340807
|
}
|
|
340808
340808
|
function buildProviderHeaders(provider, options = {}) {
|
|
340809
|
-
const
|
|
340809
|
+
const metadata2 = "descriptor" in provider ? provider.descriptor : provider;
|
|
340810
340810
|
const headers = {};
|
|
340811
340811
|
if (options.includeJsonContentType !== false) {
|
|
340812
340812
|
headers["Content-Type"] = "application/json";
|
|
340813
340813
|
}
|
|
340814
|
-
for (const [name, template] of Object.entries(
|
|
340814
|
+
for (const [name, template] of Object.entries(metadata2.auth.staticHeaders ?? {})) {
|
|
340815
340815
|
headers[name] = template.replace("{version}", options.clientVersion?.trim() || "unknown");
|
|
340816
340816
|
}
|
|
340817
340817
|
const key = options.apiKey?.trim();
|
|
340818
340818
|
if (key) {
|
|
340819
|
-
if (
|
|
340819
|
+
if (metadata2.auth.strategy === "anthropic-api-key") {
|
|
340820
340820
|
headers["x-api-key"] = key;
|
|
340821
|
-
} else if (
|
|
340821
|
+
} else if (metadata2.auth.strategy === "bearer") {
|
|
340822
340822
|
headers["Authorization"] = `Bearer ${key}`;
|
|
340823
340823
|
}
|
|
340824
340824
|
}
|
|
@@ -341315,19 +341315,19 @@ function progressProofValid(unit, input, runId, frontier) {
|
|
|
341315
341315
|
const stateOwnerRunId = runId ?? input.effectState?.runId;
|
|
341316
341316
|
if (!evidence || proof.taskEpoch !== plan.taskEpoch || proof.contractRevision !== plan.contractRevision || proof.requirementSetSha256 !== plan.requirementSetSha256 || proof.policySha256 !== taskWorkPolicySha256V1(contract) || proof.unitDefinitionSha256 !== taskWorkUnitDefinitionSha256V1(unit) || proof.proposal.selectedUnitId !== unit.id || proof.proposal.planRevision >= plan.revision || canonical2(proof.outcomes.map((e) => e.evidenceId)) !== canonical2(proof.proposal.outcomeEvidenceIds))
|
|
341317
341317
|
return false;
|
|
341318
|
-
const
|
|
341319
|
-
if (
|
|
341318
|
+
const rows2 = proof.outcomes.map((binding) => evidence.find((entry) => entry.id === binding.evidenceId && evidenceDigest(entry) === binding.evidenceSha256 && entry.workOperation?.operationRef === binding.operationRef && ownedOutcome(entry, unit, plan, contract, proof.runId)));
|
|
341319
|
+
if (rows2.some((entry) => !entry))
|
|
341320
341320
|
return false;
|
|
341321
|
-
if (runId !== void 0 && proof.runId !== runId && !
|
|
341321
|
+
if (runId !== void 0 && proof.runId !== runId && !rows2.every((entry) => input.isCurrentInheritedOutcome?.(entry) === true))
|
|
341322
341322
|
return false;
|
|
341323
|
-
if (input.effectState &&
|
|
341323
|
+
if (input.effectState && rows2.some((entry) => entry.metrics?.documentPersistence && !documentPersistenceWitness(entry, input.effectState)))
|
|
341324
341324
|
return false;
|
|
341325
341325
|
const servedWork = contract.criteria.filter((criterion) => unit.criterionIds.includes(criterion.id) && criterion.mode === "work");
|
|
341326
341326
|
const includesServedWork = !unit.checkpoint || servedWork.length > 0 && servedWork.every((criterion) => proof.workCriteria.some((witness) => witness.criterionId === criterion.id));
|
|
341327
341327
|
const work = checkpointWorkCriteria(unit, contract, includesServedWork);
|
|
341328
|
-
if (!work.length && !unit.checkpoint || work.length !== proof.workCriteria.length || work.some((c) => !proof.workCriteria.some((w) => w.criterionId === c.id)) || proof.workCriteria.some((w) => w.evidenceIds.some((id5) => !
|
|
341328
|
+
if (!work.length && !unit.checkpoint || work.length !== proof.workCriteria.length || work.some((c) => !proof.workCriteria.some((w) => w.criterionId === c.id)) || proof.workCriteria.some((w) => w.evidenceIds.some((id5) => !rows2.some((e) => e.id === id5))) || frontier && work.some((c) => !frontier.satisfiedCriterionIds.includes(c.id)) || (unit.checkpoint && unit.readiness ? !proof.readinessObservations : proof.readinessObservations !== void 0) || !readinessSatisfied(unit, evidence, frontier, proof.readinessObservations))
|
|
341329
341329
|
return false;
|
|
341330
|
-
const reconstructed = proceduralWitnesses(unit, plan, contract,
|
|
341330
|
+
const reconstructed = proceduralWitnesses(unit, plan, contract, rows2, proof.runId, input.effectState, input.effectState === void 0 ? proof : void 0, false, includesServedWork, frontier, stateOwnerRunId ?? proof.runId);
|
|
341331
341331
|
return !!reconstructed && canonical2(reconstructed) === canonical2({
|
|
341332
341332
|
workCriteria: proof.workCriteria,
|
|
341333
341333
|
...proof.localOutcomes ? { localOutcomes: proof.localOutcomes } : {},
|
|
@@ -341378,7 +341378,7 @@ function backgroundProcessWitness(entry, state, archived) {
|
|
|
341378
341378
|
return null;
|
|
341379
341379
|
return externalEffectWitness(entry, state, state ? void 0 : archived);
|
|
341380
341380
|
}
|
|
341381
|
-
function assignedSourceObservations(unit, plan, contract,
|
|
341381
|
+
function assignedSourceObservations(unit, plan, contract, rows2, runId, frontier) {
|
|
341382
341382
|
if (!unit.checkpoint)
|
|
341383
341383
|
return [];
|
|
341384
341384
|
const observations = [];
|
|
@@ -341386,7 +341386,7 @@ function assignedSourceObservations(unit, plan, contract, rows, runId, frontier)
|
|
|
341386
341386
|
const current = frontier?.criteria.find((criterion) => criterion.id === criterionId);
|
|
341387
341387
|
if (frontier && (current?.status !== "satisfied" || !frontier.satisfiedCriterionIds.includes(criterionId)))
|
|
341388
341388
|
return null;
|
|
341389
|
-
const entry =
|
|
341389
|
+
const entry = rows2.find((entry2) => ownedOutcome(entry2, unit, plan, contract, runId) && observationEntry(entry2, criterionId) && (!current || current.evidenceIds.includes(entry2.id)));
|
|
341390
341390
|
if (!entry)
|
|
341391
341391
|
return null;
|
|
341392
341392
|
if (!observations.some((observation) => observation.id === entry.id))
|
|
@@ -341394,10 +341394,10 @@ function assignedSourceObservations(unit, plan, contract, rows, runId, frontier)
|
|
|
341394
341394
|
}
|
|
341395
341395
|
return observations;
|
|
341396
341396
|
}
|
|
341397
|
-
function proceduralWitnesses(unit, plan, contract,
|
|
341397
|
+
function proceduralWitnesses(unit, plan, contract, rows2, runId, state, archived, selectCurrent = false, includesServedWork = !unit.checkpoint, frontier, stateOwnerRunId = runId) {
|
|
341398
341398
|
if (state && (state.runId !== stateOwnerRunId || state.taskEpoch !== plan.taskEpoch))
|
|
341399
341399
|
return null;
|
|
341400
|
-
const sources = assignedSourceObservations(unit, plan, contract,
|
|
341400
|
+
const sources = assignedSourceObservations(unit, plan, contract, rows2, runId, frontier);
|
|
341401
341401
|
if (!sources)
|
|
341402
341402
|
return null;
|
|
341403
341403
|
const work = checkpointWorkCriteria(unit, contract, includesServedWork);
|
|
@@ -341407,7 +341407,7 @@ function proceduralWitnesses(unit, plan, contract, rows, runId, state, archived,
|
|
|
341407
341407
|
for (const criterion of work) {
|
|
341408
341408
|
const ids = /* @__PURE__ */ new Set();
|
|
341409
341409
|
for (const kind of criterion.requiredEvidenceKinds) {
|
|
341410
|
-
const entry =
|
|
341410
|
+
const entry = rows2.find((entry2) => {
|
|
341411
341411
|
if (!ownedOutcome(entry2, unit, plan, contract, runId) || !criterion.effectProvenance && !entry2.criterionIds?.includes(criterion.id))
|
|
341412
341412
|
return false;
|
|
341413
341413
|
if (kind === "observation")
|
|
@@ -341440,7 +341440,7 @@ function proceduralWitnesses(unit, plan, contract, rows, runId, state, archived,
|
|
|
341440
341440
|
}
|
|
341441
341441
|
const localOutcomes = [];
|
|
341442
341442
|
for (const kind of unit.checkpoint?.requiredKinds ?? []) {
|
|
341443
|
-
const entry = (kind === "observation" && !includesServedWork ? sources[0] : void 0) ??
|
|
341443
|
+
const entry = (kind === "observation" && !includesServedWork ? sources[0] : void 0) ?? rows2.find((entry2) => ownedOutcome(entry2, unit, plan, contract, runId) && (kind === "observation" ? entry2.kind === "tool_result" && entry2.role === "observation" : documentPersistenceWitness(entry2, state, archived) !== null || backgroundProcessWitness(entry2, state, archived) !== null || entry2.kind === "file_change" && entry2.role === "mutation" && entry2.workOperation.effect === "external_effect" && !!entry2.targetPaths?.length && (!selectCurrent || mutationArtifacts(entry2, state, archived) !== null)));
|
|
341444
341444
|
if (!entry)
|
|
341445
341445
|
return null;
|
|
341446
341446
|
if (kind === "mutation") {
|
|
@@ -341475,28 +341475,28 @@ function taskWorkProgressHandoff(input, nextUnitId, outcomeEvidenceIds) {
|
|
|
341475
341475
|
const successor = plan.units.find((candidate) => (nextUnitId === void 0 || candidate.id === nextUnitId) && candidate.id !== unit.id && candidate.attemptState === "proposed" && candidate.dependsOn.every((id5) => id5 === unit.id || plan.units.some((u) => u.id === id5 && ["checkpointed", "settled"].includes(u.attemptState))));
|
|
341476
341476
|
if (!successor)
|
|
341477
341477
|
return null;
|
|
341478
|
-
let
|
|
341479
|
-
if (!
|
|
341478
|
+
let rows2 = outcomeEvidenceIds ? outcomeEvidenceIds.map((id5) => input.evidence.find((e) => e.id === id5 && ownedOutcome(e, unit, plan, contract, input.runId))) : input.evidence.filter((e) => ownedOutcome(e, unit, plan, contract, input.runId));
|
|
341479
|
+
if (!rows2.length || rows2.some((e) => !e))
|
|
341480
341480
|
return null;
|
|
341481
341481
|
const work = checkpointWorkCriteria(unit, contract, !unit.checkpoint);
|
|
341482
341482
|
if (!work.length && !unit.checkpoint || work.some((c) => !frontier.satisfiedCriterionIds.includes(c.id)) || !readinessSatisfied(unit, input.evidence, frontier))
|
|
341483
341483
|
return null;
|
|
341484
341484
|
if (outcomeEvidenceIds === void 0) {
|
|
341485
|
-
const current = proceduralWitnesses(unit, plan, contract,
|
|
341485
|
+
const current = proceduralWitnesses(unit, plan, contract, rows2, input.runId, input.effectState, void 0, true, void 0, frontier);
|
|
341486
341486
|
if (!current)
|
|
341487
341487
|
return null;
|
|
341488
|
-
const sources = assignedSourceObservations(unit, plan, contract,
|
|
341488
|
+
const sources = assignedSourceObservations(unit, plan, contract, rows2, input.runId, frontier);
|
|
341489
341489
|
const selectedIds = /* @__PURE__ */ new Set([
|
|
341490
341490
|
...current.workCriteria.flatMap((w) => w.evidenceIds),
|
|
341491
341491
|
...(current.localOutcomes ?? []).flatMap((w) => w.evidenceIds),
|
|
341492
341492
|
...sources.map((source) => source.id)
|
|
341493
341493
|
]);
|
|
341494
|
-
|
|
341494
|
+
rows2 = rows2.filter((e) => selectedIds.has(e.id));
|
|
341495
341495
|
}
|
|
341496
|
-
const witnesses = proceduralWitnesses(unit, plan, contract,
|
|
341496
|
+
const witnesses = proceduralWitnesses(unit, plan, contract, rows2, input.runId, input.effectState, void 0, false, void 0, frontier);
|
|
341497
341497
|
if (!witnesses)
|
|
341498
341498
|
return null;
|
|
341499
|
-
return { unit, successor, rows, witnesses };
|
|
341499
|
+
return { unit, successor, rows: rows2, witnesses };
|
|
341500
341500
|
}
|
|
341501
341501
|
function taskWorkProgressHandoffEligibleV1(input) {
|
|
341502
341502
|
return taskWorkProgressHandoff(input) !== null;
|
|
@@ -341508,7 +341508,7 @@ function applyTaskWorkProgressProposalV1(input) {
|
|
|
341508
341508
|
const handoff = taskWorkProgressHandoff(input, proposal.nextUnitId, proposal.outcomeEvidenceIds);
|
|
341509
341509
|
if (!handoff)
|
|
341510
341510
|
return null;
|
|
341511
|
-
const { unit, successor, rows, witnesses } = handoff;
|
|
341511
|
+
const { unit, successor, rows: rows2, witnesses } = handoff;
|
|
341512
341512
|
const next = structuredClone(plan), target2 = next.units.find((u) => u.id === unit.id);
|
|
341513
341513
|
target2.progressProof = {
|
|
341514
341514
|
schema: "omnius.task-work-progress-proof.v1",
|
|
@@ -341519,7 +341519,7 @@ function applyTaskWorkProgressProposalV1(input) {
|
|
|
341519
341519
|
policySha256: taskWorkPolicySha256V1(contract),
|
|
341520
341520
|
unitDefinitionSha256: taskWorkUnitDefinitionSha256V1(unit),
|
|
341521
341521
|
proposal,
|
|
341522
|
-
outcomes:
|
|
341522
|
+
outcomes: rows2.map((e) => ({ evidenceId: e.id, evidenceSha256: evidenceDigest(e), operationRef: e.workOperation.operationRef })),
|
|
341523
341523
|
...witnesses,
|
|
341524
341524
|
...unit.checkpoint && unit.readiness ? { readinessObservations: unit.readiness.criterionIds.map((criterionId) => {
|
|
341525
341525
|
const state = frontier.criteria.find((c) => c.id === criterionId);
|
|
@@ -341541,7 +341541,7 @@ function applyTaskWorkOwnedSourceCheckpointV1(input) {
|
|
|
341541
341541
|
const sources = input.contract.criteria.filter((criterion) => unit.criterionIds.includes(criterion.id) && criterion.mode === "work" && !criterion.effectProvenance && criterion.requiredEvidenceKinds.length === 1 && criterion.requiredEvidenceKinds[0] === "observation");
|
|
341542
341542
|
if (!sources.length)
|
|
341543
341543
|
return null;
|
|
341544
|
-
const
|
|
341544
|
+
const rows2 = [];
|
|
341545
341545
|
for (const source of sources) {
|
|
341546
341546
|
const state = input.frontier.criteria.find((value) => value.id === source.id);
|
|
341547
341547
|
const observation = input.evidence?.find((entry) => ownedOutcome(entry, unit, input.plan, input.contract, input.runId) && observationEntry(entry, source.id) && state?.evidenceIds.includes(entry.id));
|
|
@@ -341549,10 +341549,10 @@ function applyTaskWorkOwnedSourceCheckpointV1(input) {
|
|
|
341549
341549
|
if (state?.status !== "satisfied" || !input.frontier.satisfiedCriterionIds.includes(source.id) || !observation || unit.checkpoint.requiredKinds.includes("mutation") && (!persistence || observation.workOperation.operationRef !== persistence.workOperation.operationRef))
|
|
341550
341550
|
return null;
|
|
341551
341551
|
for (const entry of [observation, ...persistence ? [persistence] : []])
|
|
341552
|
-
if (!
|
|
341553
|
-
|
|
341552
|
+
if (!rows2.some((row2) => row2.id === entry.id))
|
|
341553
|
+
rows2.push(entry);
|
|
341554
341554
|
}
|
|
341555
|
-
const outcomeEvidenceIds =
|
|
341555
|
+
const outcomeEvidenceIds = rows2.map((entry) => entry.id);
|
|
341556
341556
|
const handoff = taskWorkProgressHandoff(input, void 0, outcomeEvidenceIds);
|
|
341557
341557
|
if (!handoff)
|
|
341558
341558
|
return null;
|
|
@@ -342758,18 +342758,21 @@ function zeroCost(cost2) {
|
|
|
342758
342758
|
return Array.isArray(cost2.tiers) && cost2.tiers.length <= 32 && cost2.tiers.every((tier) => object2(tier) && tier.tiers === void 0 && zeroCost(tier));
|
|
342759
342759
|
}
|
|
342760
342760
|
function parseOpenCodeFreeModelCatalog(json5) {
|
|
342761
|
+
return tryParseOpenCodeFreeModelCatalog(json5) ?? [];
|
|
342762
|
+
}
|
|
342763
|
+
function tryParseOpenCodeFreeModelCatalog(json5) {
|
|
342761
342764
|
if (typeof json5 !== "string" || Buffer.byteLength(json5) > MAX_CATALOG_BYTES)
|
|
342762
|
-
return
|
|
342765
|
+
return void 0;
|
|
342763
342766
|
try {
|
|
342764
342767
|
const catalog = JSON.parse(json5);
|
|
342765
342768
|
if (!object2(catalog) || !object2(catalog.opencode))
|
|
342766
|
-
return
|
|
342769
|
+
return void 0;
|
|
342767
342770
|
const provider = catalog.opencode;
|
|
342768
342771
|
if (provider.id !== "opencode" || provider.api !== OPENCODE_INFERENCE_BASE_URL || !["@ai-sdk/openai-compatible", "@ai-sdk/openai"].includes(String(provider.npm)) || !object2(provider.models))
|
|
342769
|
-
return
|
|
342772
|
+
return void 0;
|
|
342770
342773
|
const entries = Object.entries(provider.models);
|
|
342771
342774
|
if (entries.length > MAX_OPENCODE_CATALOG_MODELS)
|
|
342772
|
-
return
|
|
342775
|
+
return void 0;
|
|
342773
342776
|
const models = [];
|
|
342774
342777
|
for (const [id5, model] of entries) {
|
|
342775
342778
|
if (!/^[a-z0-9][a-z0-9._-]{0,127}$/.test(id5) || !object2(model) || model.id !== id5 || model.status === "deprecated" || !zeroCost(model.cost) || !object2(model.modalities) || !Array.isArray(model.modalities.input) || !model.modalities.input.includes("text") || !Array.isArray(model.modalities.output) || !model.modalities.output.includes("text") || !object2(model.limit) || !positiveInteger2(model.limit.context) || !positiveInteger2(model.limit.output))
|
|
@@ -342802,7 +342805,7 @@ function parseOpenCodeFreeModelCatalog(json5) {
|
|
|
342802
342805
|
}
|
|
342803
342806
|
return models.sort((a, b) => a.model < b.model ? -1 : a.model > b.model ? 1 : 0);
|
|
342804
342807
|
} catch {
|
|
342805
|
-
return
|
|
342808
|
+
return void 0;
|
|
342806
342809
|
}
|
|
342807
342810
|
}
|
|
342808
342811
|
function parseOpenCodeAvailableModelIds(json5) {
|
|
@@ -342819,22 +342822,7 @@ function parseOpenCodeAvailableModelIds(json5) {
|
|
|
342819
342822
|
return void 0;
|
|
342820
342823
|
}
|
|
342821
342824
|
}
|
|
342822
|
-
function
|
|
342823
|
-
const available = parseOpenCodeAvailableModelIds(availabilityJson);
|
|
342824
|
-
if (available === void 0)
|
|
342825
|
-
return [...models];
|
|
342826
|
-
const ids = new Set(available);
|
|
342827
|
-
const seen = /* @__PURE__ */ new Set();
|
|
342828
|
-
return models.filter((model) => {
|
|
342829
|
-
if (!ids.has(model.model) || seen.has(model.model))
|
|
342830
|
-
return false;
|
|
342831
|
-
seen.add(model.model);
|
|
342832
|
-
return true;
|
|
342833
|
-
});
|
|
342834
|
-
}
|
|
342835
|
-
function normalizeOpenCodeFreeModelCatalog(json5, availabilityJson) {
|
|
342836
|
-
const metadata = parseOpenCodeFreeModelCatalog(json5);
|
|
342837
|
-
const models = availabilityJson === void 0 ? metadata : intersectOpenCodeAvailableModels(metadata, availabilityJson);
|
|
342825
|
+
function normalizeOpenCodeFreeModels(models) {
|
|
342838
342826
|
return { data: models.map((model) => {
|
|
342839
342827
|
const structuredOutput = model.nativeStructuredOutput ?? model.structuredOutput;
|
|
342840
342828
|
return {
|
|
@@ -343030,6 +343018,36 @@ function parseKeylessInferenceRegistry(html) {
|
|
|
343030
343018
|
return [];
|
|
343031
343019
|
}
|
|
343032
343020
|
|
|
343021
|
+
// packages/orchestrator/dist/builtin-free-snapshot.js
|
|
343022
|
+
var rows = [
|
|
343023
|
+
["muse-spark-1.3-contributor-free", "Muse Spark 1.3 Free", 1048576, 131072, void 0, true, true],
|
|
343024
|
+
["step-5-preview-free", "Step 5 Preview Free", 1e6, 65536, 1e6, true],
|
|
343025
|
+
["ling-3.1-flash-free", "Ling 3.1 Flash Free", 262144, 32768, void 0, false],
|
|
343026
|
+
["mimo-v2.6-flash-free", "MiMo-V2.6-Flash Free", 2e5, 32e3, void 0, void 0],
|
|
343027
|
+
["nemotron-3.5-lightning-free", "Nemotron 3.5 Lightning Free", 262144, 262144, void 0, true],
|
|
343028
|
+
["big-pickle", "Big Pickle", 2e5, 32e3, 16e4, true],
|
|
343029
|
+
["cat-jam-free", "Cat Jam Free", 262144, 131072, void 0, true],
|
|
343030
|
+
["longcat-2.5-preview-free", "LongCat 2.5 Preview Free", 1e6, 131072, void 0, void 0],
|
|
343031
|
+
["space-bunny-free", "Space Bunny Free", 1048576, 524288, 524288, void 0]
|
|
343032
|
+
];
|
|
343033
|
+
var metadata = Object.fromEntries(rows.map(([id5, name, context, output, input, structured_output, responses]) => [id5, {
|
|
343034
|
+
id: id5,
|
|
343035
|
+
name,
|
|
343036
|
+
cost: { input: 0, output: 0 },
|
|
343037
|
+
tool_call: true,
|
|
343038
|
+
modalities: { input: ["text"], output: ["text"] },
|
|
343039
|
+
limit: { context, output, ...input === void 0 ? {} : { input } },
|
|
343040
|
+
...structured_output === void 0 ? {} : { structured_output },
|
|
343041
|
+
...responses ? { provider: { npm: "@ai-sdk/openai", shape: "responses" } } : {}
|
|
343042
|
+
}]));
|
|
343043
|
+
var BUILTIN_FREE_MODEL_SNAPSHOT = Object.freeze(parseOpenCodeFreeModelCatalog(JSON.stringify({ opencode: {
|
|
343044
|
+
id: "opencode",
|
|
343045
|
+
api: OPENCODE_INFERENCE_BASE_URL,
|
|
343046
|
+
npm: "@ai-sdk/openai-compatible",
|
|
343047
|
+
models: metadata
|
|
343048
|
+
} })).map((model) => Object.freeze(model)));
|
|
343049
|
+
var BUILTIN_FREE_MODEL_IDS = new Set(BUILTIN_FREE_MODEL_SNAPSHOT.map((model) => model.model));
|
|
343050
|
+
|
|
343033
343051
|
// packages/orchestrator/dist/inference-provider-error.js
|
|
343034
343052
|
var object4 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
343035
343053
|
var reasons = /* @__PURE__ */ new Set(["unsupported_schema", "request", "rate", "auth", "upstream"]);
|
|
@@ -344949,6 +344967,8 @@ var InvalidInferenceResponse = class extends Error {
|
|
|
344949
344967
|
this.name = "InvalidInferenceResponse";
|
|
344950
344968
|
}
|
|
344951
344969
|
};
|
|
344970
|
+
var InvalidDiscoveryMetadata = class extends Error {
|
|
344971
|
+
};
|
|
344952
344972
|
var cooldowns = /* @__PURE__ */ new Map();
|
|
344953
344973
|
var localCooldowns = /* @__PURE__ */ new Map();
|
|
344954
344974
|
var registryCaches = /* @__PURE__ */ new WeakMap();
|
|
@@ -345567,6 +345587,30 @@ var RemoteInferenceFallback = class _RemoteInferenceFallback {
|
|
|
345567
345587
|
this.fence(request);
|
|
345568
345588
|
}
|
|
345569
345589
|
}
|
|
345590
|
+
/** Discovery receipts never imply that a model was selected or generated. */
|
|
345591
|
+
discovery(request, route, discovery, error) {
|
|
345592
|
+
this.fence(request);
|
|
345593
|
+
if (!request.onInferenceRouteLifecycle)
|
|
345594
|
+
return;
|
|
345595
|
+
const failure = error === void 0 ? void 0 : safeFailure(error, request, route);
|
|
345596
|
+
const receipt = {
|
|
345597
|
+
location: "remote",
|
|
345598
|
+
phase: "discovery",
|
|
345599
|
+
backendType: "vllm",
|
|
345600
|
+
providerId: route.keyless?.id ?? route.providerId ?? "remote",
|
|
345601
|
+
model: route.model,
|
|
345602
|
+
...request.logicalRequestId ? { logicalRequestId: request.logicalRequestId } : {},
|
|
345603
|
+
discovery: { ...discovery, ...failure ? {
|
|
345604
|
+
category: error instanceof InvalidDiscoveryMetadata ? "invalid_metadata" : failure.category === "timeout" ? "timeout" : "transport",
|
|
345605
|
+
...failure.status === void 0 ? {} : { status: failure.status }
|
|
345606
|
+
} : {} }
|
|
345607
|
+
};
|
|
345608
|
+
try {
|
|
345609
|
+
request.onInferenceRouteLifecycle(this.scrubber(route)(receipt));
|
|
345610
|
+
} catch {
|
|
345611
|
+
this.fence(request);
|
|
345612
|
+
}
|
|
345613
|
+
}
|
|
345570
345614
|
async prepare(route) {
|
|
345571
345615
|
await this.validate(route.baseUrl);
|
|
345572
345616
|
if (route.profile) {
|
|
@@ -345811,6 +345855,7 @@ ${line}`).join("");
|
|
|
345811
345855
|
if (!priority.has(key))
|
|
345812
345856
|
priority.set(key, priority.size);
|
|
345813
345857
|
if ((routeCooldown(candidate)?.until ?? 0) > this.now()) {
|
|
345858
|
+
this.discovery(request, candidate, { stage: "cooldown", outcome: "cooling", modelCount: 1 });
|
|
345814
345859
|
if (routeCooldown(candidate)?.rateLimited)
|
|
345815
345860
|
waiting.set(key, candidate);
|
|
345816
345861
|
continue;
|
|
@@ -345921,8 +345966,6 @@ ${line}`).join("");
|
|
|
345921
345966
|
return;
|
|
345922
345967
|
if (this.builtInPrimaryRequest && (!this.policy.enabled || !this.policy.keyless) && provider.id !== "opencode")
|
|
345923
345968
|
continue;
|
|
345924
|
-
if (request.tools.length && !provider.nativeToolsHint || hasImages(request) || (request.responseFormat ?? request.response_format) && provider.structuredOutputHint === false)
|
|
345925
|
-
continue;
|
|
345926
345969
|
const route = {
|
|
345927
345970
|
baseUrl: provider.chatUrl.slice(0, -"/chat/completions".length),
|
|
345928
345971
|
model: provider.model,
|
|
@@ -345933,8 +345976,10 @@ ${line}`).join("");
|
|
|
345933
345976
|
keyless: provider,
|
|
345934
345977
|
...provider.anonymousAuthorization === "Bearer unused" ? { apiKey: "unused" } : provider.anonymousAuthorization === "Bearer public" && provider.clientIdentity === "opencode" && provider.chatUrl === `${OPENCODE_INFERENCE_BASE_URL}/chat/completions` ? { apiKey: "public" } : {}
|
|
345935
345978
|
};
|
|
345936
|
-
if (!this.compatible(request, route, includeCooling))
|
|
345979
|
+
if (request.tools.length && !provider.nativeToolsHint || hasImages(request) || (request.responseFormat ?? request.response_format) && provider.structuredOutputHint === false || !this.compatible(request, route, includeCooling)) {
|
|
345980
|
+
this.discovery(request, route, { stage: "eligibility", outcome: "no_eligible_models", modelCount: 0 });
|
|
345937
345981
|
continue;
|
|
345982
|
+
}
|
|
345938
345983
|
if (provider.providerDefaultModel) {
|
|
345939
345984
|
const key = routeKey(route);
|
|
345940
345985
|
if (!seen.has(key))
|
|
@@ -345942,8 +345987,10 @@ ${line}`).join("");
|
|
|
345942
345987
|
continue;
|
|
345943
345988
|
}
|
|
345944
345989
|
const modelsUrl = provider.modelsUrl;
|
|
345945
|
-
if (!modelsUrl)
|
|
345990
|
+
if (!modelsUrl) {
|
|
345991
|
+
this.discovery(request, route, { stage: "catalog", outcome: "unavailable" });
|
|
345946
345992
|
continue;
|
|
345993
|
+
}
|
|
345947
345994
|
try {
|
|
345948
345995
|
let cache3 = catalogCaches.get(fetcher);
|
|
345949
345996
|
if (!cache3) {
|
|
@@ -345953,24 +346000,81 @@ ${line}`).join("");
|
|
|
345953
346000
|
const cached = cache3.get(modelsUrl);
|
|
345954
346001
|
const openCodeCatalog = provider.catalogKind === "opencode" && provider.clientIdentity === "opencode" && route.baseUrl === OPENCODE_INFERENCE_BASE_URL && modelsUrl === OPENCODE_MODEL_CATALOG_URL;
|
|
345955
346002
|
const kiloCatalog = provider.catalogKind === "kilo" && provider.id === "kilo" && route.baseUrl === "https://api.kilo.ai/api/gateway" && modelsUrl === "https://api.kilo.ai/api/gateway/models";
|
|
345956
|
-
|
|
345957
|
-
if (
|
|
346003
|
+
let raw;
|
|
346004
|
+
if (cached && cached.until > this.now()) {
|
|
346005
|
+
raw = cached.value;
|
|
346006
|
+
this.discovery(request, route, { stage: "catalog", outcome: cached.source === "bundled" || cached.source === "last_known_good" ? cached.source : "cached", ...object12(raw) && Array.isArray(raw.data) ? { modelCount: raw.data.length } : {} });
|
|
346007
|
+
} else {
|
|
346008
|
+
try {
|
|
346009
|
+
const text12 = await this.read(modelsUrl, request, deadline, openCodeCatalog ? MAX_OPENCODE_CATALOG_BYTES : kiloCatalog ? MAX_KILO_CATALOG_BYTES : MAX_CATALOG_BYTES2);
|
|
346010
|
+
if (openCodeCatalog) {
|
|
346011
|
+
const models2 = tryParseOpenCodeFreeModelCatalog(text12);
|
|
346012
|
+
if (models2 === void 0)
|
|
346013
|
+
throw new InvalidDiscoveryMetadata();
|
|
346014
|
+
raw = normalizeOpenCodeFreeModels(models2);
|
|
346015
|
+
} else {
|
|
346016
|
+
try {
|
|
346017
|
+
raw = JSON.parse(text12);
|
|
346018
|
+
} catch {
|
|
346019
|
+
throw new InvalidDiscoveryMetadata();
|
|
346020
|
+
}
|
|
346021
|
+
}
|
|
346022
|
+
if (!object12(raw) || !Array.isArray(raw.data) || raw.data.length > 512)
|
|
346023
|
+
throw new InvalidDiscoveryMetadata();
|
|
346024
|
+
if (cache3.size >= 64 && !cache3.has(modelsUrl))
|
|
346025
|
+
cache3.delete(cache3.keys().next().value);
|
|
346026
|
+
cache3.set(modelsUrl, { until: this.now() + 3e5, value: raw, source: "live" });
|
|
346027
|
+
this.discovery(request, route, { stage: "catalog", outcome: "live", modelCount: raw.data.length });
|
|
346028
|
+
} catch (error) {
|
|
346029
|
+
this.fence(request);
|
|
346030
|
+
if (!openCodeCatalog) {
|
|
346031
|
+
this.discovery(request, route, { stage: "catalog", outcome: "unavailable" }, error);
|
|
346032
|
+
continue;
|
|
346033
|
+
}
|
|
346034
|
+
raw = cached?.value ?? normalizeOpenCodeFreeModels(BUILTIN_FREE_MODEL_SNAPSHOT);
|
|
346035
|
+
const source = !cached || cached.source === "bundled" ? "bundled" : "last_known_good";
|
|
346036
|
+
if (cache3.size >= 64 && !cache3.has(modelsUrl))
|
|
346037
|
+
cache3.delete(cache3.keys().next().value);
|
|
346038
|
+
cache3.set(modelsUrl, { until: this.now() + 15e3, value: raw, source });
|
|
346039
|
+
this.discovery(request, route, {
|
|
346040
|
+
stage: "catalog",
|
|
346041
|
+
outcome: source,
|
|
346042
|
+
...object12(raw) && Array.isArray(raw.data) ? { modelCount: raw.data.length } : {}
|
|
346043
|
+
}, error);
|
|
346044
|
+
}
|
|
346045
|
+
}
|
|
346046
|
+
if (!object12(raw) || !Array.isArray(raw.data) || raw.data.length > 512) {
|
|
346047
|
+
this.discovery(request, route, { stage: "catalog", outcome: "unavailable" }, new InvalidDiscoveryMetadata());
|
|
345958
346048
|
continue;
|
|
345959
|
-
|
|
345960
|
-
cache3.delete(cache3.keys().next().value);
|
|
345961
|
-
cache3.set(modelsUrl, { until: this.now() + 3e5, value: raw });
|
|
346049
|
+
}
|
|
345962
346050
|
let available;
|
|
345963
346051
|
if (openCodeCatalog && raw.data.length && provider.availabilityModelsUrl === OPENCODE_AVAILABLE_MODELS_URL) {
|
|
345964
346052
|
const cachedAvailability = availabilityCaches.get(fetcher);
|
|
345965
|
-
if (cachedAvailability && cachedAvailability.until > this.now())
|
|
346053
|
+
if (cachedAvailability && cachedAvailability.until > this.now()) {
|
|
345966
346054
|
available = cachedAvailability.ids;
|
|
345967
|
-
|
|
346055
|
+
this.discovery(request, route, {
|
|
346056
|
+
stage: "availability",
|
|
346057
|
+
outcome: available === void 0 ? "unavailable" : "cached",
|
|
346058
|
+
...available === void 0 ? {} : { modelCount: available.length }
|
|
346059
|
+
});
|
|
346060
|
+
} else {
|
|
346061
|
+
let refreshed = false;
|
|
345968
346062
|
try {
|
|
345969
346063
|
available = parseOpenCodeAvailableModelIds(await this.read(OPENCODE_AVAILABLE_MODELS_URL, request, deadline, MAX_CATALOG_BYTES2));
|
|
345970
|
-
|
|
346064
|
+
if (available === void 0)
|
|
346065
|
+
throw new InvalidDiscoveryMetadata();
|
|
346066
|
+
refreshed = true;
|
|
346067
|
+
this.discovery(request, route, { stage: "availability", outcome: "live", modelCount: available.length });
|
|
346068
|
+
} catch (error) {
|
|
345971
346069
|
this.fence(request);
|
|
346070
|
+
available = cachedAvailability?.ids;
|
|
346071
|
+
this.discovery(request, route, {
|
|
346072
|
+
stage: "availability",
|
|
346073
|
+
outcome: available === void 0 ? "unavailable" : "last_known_good",
|
|
346074
|
+
...available === void 0 ? {} : { modelCount: available.length }
|
|
346075
|
+
}, error);
|
|
345972
346076
|
}
|
|
345973
|
-
availabilityCaches.set(fetcher, { until: this.now() + (
|
|
346077
|
+
availabilityCaches.set(fetcher, { until: this.now() + (refreshed ? 3e5 : 15e3), ids: available });
|
|
345974
346078
|
}
|
|
345975
346079
|
}
|
|
345976
346080
|
const availableIds = available === void 0 ? void 0 : new Set(available);
|
|
@@ -346020,8 +346124,10 @@ ${line}`).join("");
|
|
|
346020
346124
|
if (compatible.length > modelLimit)
|
|
346021
346125
|
compatible.pop();
|
|
346022
346126
|
}
|
|
346023
|
-
if (!compatible.length)
|
|
346127
|
+
if (!compatible.length) {
|
|
346128
|
+
this.discovery(request, route, { stage: "eligibility", outcome: "no_eligible_models", modelCount: 0 });
|
|
346024
346129
|
continue;
|
|
346130
|
+
}
|
|
346025
346131
|
if (keylessInferenceStage(provider) < 2) {
|
|
346026
346132
|
for (const candidate of compatible) {
|
|
346027
346133
|
this.fence(request);
|
|
@@ -346034,9 +346140,9 @@ ${line}`).join("");
|
|
|
346034
346140
|
}
|
|
346035
346141
|
} else
|
|
346036
346142
|
alternatives.push(compatible);
|
|
346037
|
-
} catch {
|
|
346143
|
+
} catch (error) {
|
|
346038
346144
|
this.fence(request);
|
|
346039
|
-
this.
|
|
346145
|
+
this.discovery(request, route, { stage: "eligibility", outcome: "unavailable" }, error);
|
|
346040
346146
|
}
|
|
346041
346147
|
}
|
|
346042
346148
|
const best = (routes) => {
|
|
@@ -346078,7 +346184,7 @@ ${line}`).join("");
|
|
|
346078
346184
|
});
|
|
346079
346185
|
if (!response.ok || Number(response.headers.get("content-length")) > limit2) {
|
|
346080
346186
|
await response.body?.cancel();
|
|
346081
|
-
throw new Error("Remote discovery unavailable.");
|
|
346187
|
+
throw Object.assign(new Error("Remote discovery unavailable."), { status: response.status });
|
|
346082
346188
|
}
|
|
346083
346189
|
if (!response.body)
|
|
346084
346190
|
return "";
|
|
@@ -352009,10 +352115,10 @@ var DurableDocumentWorkerCoordinator = class {
|
|
|
352009
352115
|
for (const source of options.grant.definition.sources.filter((source2) => ids.includes(source2.sourceId))) {
|
|
352010
352116
|
current();
|
|
352011
352117
|
const saved = [...options.corpus.streamSources(this.scope)].find((value) => value.sourceId === source.sourceId);
|
|
352012
|
-
const
|
|
352013
|
-
if (!
|
|
352118
|
+
const metadata2 = options.corpus.getOperationWorkCoverage({ ...this.scope, sourceSequence: saved.sequence });
|
|
352119
|
+
if (!metadata2)
|
|
352014
352120
|
continue;
|
|
352015
|
-
const receipt =
|
|
352121
|
+
const receipt = metadata2.receipt, output = metadata2.output;
|
|
352016
352122
|
if (!receipt || typeof output !== "string" || receipt.delegationId !== options.grant.id || receipt.definitionSha256 !== options.grant.id.slice("delegation:".length) || taskExecutionDigest(output) !== receipt.outputSha256 || taskExecutionDigest(taskDocumentSourceIdentityV1(receipt.source)) !== taskExecutionDigest(taskDocumentSourceIdentityV1(source)))
|
|
352017
352123
|
throw new Error("Durable document worker result changed");
|
|
352018
352124
|
await reopenSource(options.workspaceRoot, source, controller.signal, current);
|
|
@@ -353128,7 +353234,7 @@ function literalNativeTableView(receipt, pageBodies) {
|
|
|
353128
353234
|
return null;
|
|
353129
353235
|
}
|
|
353130
353236
|
candidates.push({ id: table.id, text: literalLine(table.columns.flatMap((column) => column.anchors)) });
|
|
353131
|
-
const
|
|
353237
|
+
const rows2 = [];
|
|
353132
353238
|
const frequencies = table.columns.map(() => /* @__PURE__ */ new Map());
|
|
353133
353239
|
const unassigned = [];
|
|
353134
353240
|
for (const row2 of table.rows) {
|
|
@@ -353141,7 +353247,7 @@ function literalNativeTableView(receipt, pageBodies) {
|
|
|
353141
353247
|
if (!row2.unassigned.every(validWord))
|
|
353142
353248
|
return null;
|
|
353143
353249
|
const rowId = nativeId(row2.id, `${table.id}:r`);
|
|
353144
|
-
|
|
353250
|
+
rows2.push(rowId);
|
|
353145
353251
|
row2.cells.forEach((cell, index) => {
|
|
353146
353252
|
const groups = frequencies[index];
|
|
353147
353253
|
let members = groups.get(cell.text);
|
|
@@ -353163,7 +353269,7 @@ function literalNativeTableView(receipt, pageBodies) {
|
|
|
353163
353269
|
wordIds(column.anchors),
|
|
353164
353270
|
[...frequencies[index]].map(([text12, members]) => [text12, members.length, members])
|
|
353165
353271
|
]),
|
|
353166
|
-
rows,
|
|
353272
|
+
rows: rows2,
|
|
353167
353273
|
...unassigned.length ? { unassigned } : {}
|
|
353168
353274
|
});
|
|
353169
353275
|
}
|
|
@@ -358296,8 +358402,8 @@ function integrationClosureCompletionBlockers(closure) {
|
|
|
358296
358402
|
}
|
|
358297
358403
|
const blockers = [];
|
|
358298
358404
|
for (const claim of claimNodes) {
|
|
358299
|
-
const
|
|
358300
|
-
const material =
|
|
358405
|
+
const metadata2 = claim.label.match(/^\[(.+?)\]\s/);
|
|
358406
|
+
const material = metadata2?.[1] ?? "low";
|
|
358301
358407
|
const edges = claimEdges.get(claim.id) ?? [];
|
|
358302
358408
|
const needsIndependent = edges.some((edge) => edge.relation === "verified_by" && edge.state === "open");
|
|
358303
358409
|
const isHardwareClaim = edges.some((edge) => edge.reason === "hardware-attained claim requires delivery evidence");
|
|
@@ -363785,11 +363891,11 @@ function encodeRequirementLedger(ledger) {
|
|
|
363785
363891
|
if (prefix.length >= 8)
|
|
363786
363892
|
prefixes[key] = prefix;
|
|
363787
363893
|
}
|
|
363788
|
-
const { requirements: _requirements, ...
|
|
363894
|
+
const { requirements: _requirements, ...metadata2 } = ledger;
|
|
363789
363895
|
const encoded2 = {
|
|
363790
363896
|
schema: "omnius.bounded-artifact-requirement-ledger.v2",
|
|
363791
363897
|
encoding: "columns_defaults_prefixes_missing_text_equals_sourceText",
|
|
363792
|
-
ledger:
|
|
363898
|
+
ledger: metadata2,
|
|
363793
363899
|
fields: fields2,
|
|
363794
363900
|
defaults: defaults2,
|
|
363795
363901
|
prefixes,
|
|
@@ -369237,7 +369343,7 @@ var SignalExtractor = class {
|
|
|
369237
369343
|
* retained as unclassified context; the extractor must not infer semantic
|
|
369238
369344
|
* intent from words inside the message body.
|
|
369239
369345
|
*/
|
|
369240
|
-
classify(content,
|
|
369346
|
+
classify(content, metadata2) {
|
|
369241
369347
|
if (!content)
|
|
369242
369348
|
return { type: "noise", label: "empty" };
|
|
369243
369349
|
if (content.includes("[REFERENCE CONTRACT v1]")) {
|
|
@@ -369247,14 +369353,14 @@ var SignalExtractor = class {
|
|
|
369247
369353
|
preserve: true
|
|
369248
369354
|
};
|
|
369249
369355
|
}
|
|
369250
|
-
const type = normalizeSignalClass(
|
|
369251
|
-
const priority = typeof
|
|
369356
|
+
const type = normalizeSignalClass(metadata2?.type) ?? "context";
|
|
369357
|
+
const priority = typeof metadata2?.priority === "number" && Number.isFinite(metadata2.priority) ? metadata2.priority : void 0;
|
|
369252
369358
|
return {
|
|
369253
369359
|
type,
|
|
369254
|
-
label: cleanSignalLabel(
|
|
369360
|
+
label: cleanSignalLabel(metadata2?.label) ?? "unclassified",
|
|
369255
369361
|
...priority !== void 0 ? { priority } : {},
|
|
369256
|
-
...typeof
|
|
369257
|
-
...
|
|
369362
|
+
...typeof metadata2?.dedupeKey === "string" && metadata2.dedupeKey.trim() ? { dedupeKey: metadata2.dedupeKey.trim().slice(0, 160) } : {},
|
|
369363
|
+
...metadata2?.preserve === true ? { preserve: true } : {}
|
|
369258
369364
|
};
|
|
369259
369365
|
}
|
|
369260
369366
|
/**
|
|
@@ -372419,8 +372525,8 @@ function collectMetadataReports(signals) {
|
|
|
372419
372525
|
const pressureReports = [];
|
|
372420
372526
|
const forgettingReports = [];
|
|
372421
372527
|
for (const signal of signals) {
|
|
372422
|
-
const
|
|
372423
|
-
for (const [key, value] of Object.entries(
|
|
372528
|
+
const metadata2 = signal.metadata ?? {};
|
|
372529
|
+
for (const [key, value] of Object.entries(metadata2)) {
|
|
372424
372530
|
if (value == null)
|
|
372425
372531
|
continue;
|
|
372426
372532
|
if (/pressure/i.test(key))
|
|
@@ -373845,14 +373951,14 @@ function loadRuntimeRolloutIntegrityKey(stateDir) {
|
|
|
373845
373951
|
}
|
|
373846
373952
|
fsyncDirectory2(root);
|
|
373847
373953
|
}
|
|
373848
|
-
const
|
|
373849
|
-
if (
|
|
373954
|
+
const metadata2 = lstatSync4(path7);
|
|
373955
|
+
if (metadata2.isSymbolicLink() || !metadata2.isFile()) {
|
|
373850
373956
|
throw new Error("runtime_rollout_integrity_key_unsafe_type");
|
|
373851
373957
|
}
|
|
373852
|
-
if (typeof process.getuid === "function" &&
|
|
373958
|
+
if (typeof process.getuid === "function" && metadata2.uid !== process.getuid()) {
|
|
373853
373959
|
throw new Error("runtime_rollout_integrity_key_foreign_owner");
|
|
373854
373960
|
}
|
|
373855
|
-
if (process.platform !== "win32" && (
|
|
373961
|
+
if (process.platform !== "win32" && (metadata2.mode & 63) !== 0) {
|
|
373856
373962
|
throw new Error("runtime_rollout_integrity_key_permissive_mode");
|
|
373857
373963
|
}
|
|
373858
373964
|
const key = readFileSync53(path7);
|
|
@@ -382466,7 +382572,7 @@ async function projectCorpusPageReviewSourceBound(input, proofOwner) {
|
|
|
382466
382572
|
const terms3 = [...new Set(input.goal.toLocaleLowerCase().match(/[\p{L}\p{N}_]+/gu) ?? [])];
|
|
382467
382573
|
while (ordinal < segments.segmentCount) {
|
|
382468
382574
|
input.signal?.throwIfAborted();
|
|
382469
|
-
const
|
|
382575
|
+
const rows2 = database.prepare(`SELECT p.page_id,p.segment_ordinal FROM vm_corpus_pages p
|
|
382470
382576
|
JOIN vm_corpus_observations o ON o.seq=p.observation_seq JOIN vm_evidence_documents d ON d.id=o.document_id
|
|
382471
382577
|
WHERE p.source_seq=? AND p.page_number=? AND p.channel='native_text' AND p.full_page_sha256=? AND p.complete=1
|
|
382472
382578
|
AND p.segment_ordinal>? AND d.version=? AND NOT EXISTS (
|
|
@@ -382475,9 +382581,9 @@ async function projectCorpusPageReviewSourceBound(input, proofOwner) {
|
|
|
382475
382581
|
AND newer.page_number=p.page_number AND newer.channel=p.channel AND newer.full_page_sha256=p.full_page_sha256
|
|
382476
382582
|
AND newer.segment_ordinal=p.segment_ordinal AND newer.complete=1 AND nd.version=d.version AND newer.seq>p.seq)
|
|
382477
382583
|
ORDER BY p.segment_ordinal LIMIT 16`).all(source.sequence, page.page, page.nativeText.sha256, after, extractionVersion);
|
|
382478
|
-
if (!
|
|
382584
|
+
if (!rows2.length)
|
|
382479
382585
|
throw new Error("Corpus complete segment chain is missing");
|
|
382480
|
-
for (const row2 of
|
|
382586
|
+
for (const row2 of rows2) {
|
|
382481
382587
|
input.signal?.throwIfAborted();
|
|
382482
382588
|
const read = corpus.readPage({ scopeId: owner.scopeId, corpusId: segments.corpusId, pageId: row2.page_id });
|
|
382483
382589
|
const part = read.page;
|
|
@@ -384883,14 +384989,14 @@ function formatTodoReminderItems(todos, maxRows) {
|
|
|
384883
384989
|
roots.push(todo);
|
|
384884
384990
|
}
|
|
384885
384991
|
}
|
|
384886
|
-
const
|
|
384992
|
+
const rows2 = [];
|
|
384887
384993
|
const seen = /* @__PURE__ */ new Set();
|
|
384888
384994
|
const visit = (todo, depth) => {
|
|
384889
|
-
if (
|
|
384995
|
+
if (rows2.length >= maxRows || seen.has(todo))
|
|
384890
384996
|
return;
|
|
384891
384997
|
seen.add(todo);
|
|
384892
384998
|
const indent2 = " ".repeat(Math.min(depth, 4));
|
|
384893
|
-
|
|
384999
|
+
rows2.push(`${indent2}- [${todo.status}] ${todo.content}`);
|
|
384894
385000
|
if (!todo.id)
|
|
384895
385001
|
return;
|
|
384896
385002
|
for (const child of byParent.get(todo.id) ?? [])
|
|
@@ -384900,9 +385006,9 @@ function formatTodoReminderItems(todos, maxRows) {
|
|
|
384900
385006
|
visit(root, 0);
|
|
384901
385007
|
for (const todo of todos)
|
|
384902
385008
|
visit(todo, 0);
|
|
384903
|
-
if (todos.length >
|
|
384904
|
-
|
|
384905
|
-
return
|
|
385009
|
+
if (todos.length > rows2.length)
|
|
385010
|
+
rows2.push(`... +${todos.length - rows2.length} more`);
|
|
385011
|
+
return rows2.join("\n");
|
|
384906
385012
|
}
|
|
384907
385013
|
function selectHeadTailLines(lines, headCount, tailCount) {
|
|
384908
385014
|
if (lines.length <= headCount + tailCount)
|
|
@@ -396553,7 +396659,7 @@ ${context ?? ""}`;
|
|
|
396553
396659
|
const surface = String(obj["surface"] ?? this._inferEvidenceSurface(toolName));
|
|
396554
396660
|
const id5 = typeof obj["id"] === "string" && obj["id"].trim() ? obj["id"].trim() : `ev_${this.quickHash(`${toolName}:${action}:${turn}:${toolCallIndex}:${JSON.stringify(args).slice(0, 500)}`)}`;
|
|
396555
396661
|
const createdAtIso = typeof obj["createdAtIso"] === "string" && obj["createdAtIso"].trim() ? obj["createdAtIso"].trim() : (/* @__PURE__ */ new Date()).toISOString();
|
|
396556
|
-
const
|
|
396662
|
+
const metadata2 = {
|
|
396557
396663
|
...obj["metadata"] && typeof obj["metadata"] === "object" ? obj["metadata"] : {},
|
|
396558
396664
|
runnerTurn: turn,
|
|
396559
396665
|
runnerToolCallIndex: toolCallIndex,
|
|
@@ -396566,7 +396672,7 @@ ${context ?? ""}`;
|
|
|
396566
396672
|
tool: String(obj["tool"] ?? toolName),
|
|
396567
396673
|
action,
|
|
396568
396674
|
surface,
|
|
396569
|
-
metadata
|
|
396675
|
+
metadata: metadata2
|
|
396570
396676
|
};
|
|
396571
396677
|
}
|
|
396572
396678
|
_extractRuntimeEvidenceEvents(result, toolName, args, turn, toolCallIndex) {
|
|
@@ -398979,11 +399085,11 @@ ${sections.join("\n")}` : sections.join("\n");
|
|
|
398979
399085
|
});
|
|
398980
399086
|
}
|
|
398981
399087
|
}
|
|
398982
|
-
_activeContextItem(kind, id5, source, label, content, priority = 0,
|
|
399088
|
+
_activeContextItem(kind, id5, source, label, content, priority = 0, metadata2) {
|
|
398983
399089
|
const normalized4 = normalizeContextSnippet(content ?? "", 1200);
|
|
398984
399090
|
if (!normalized4)
|
|
398985
399091
|
return null;
|
|
398986
|
-
return { id: id5, kind, source, label, content: normalized4, priority, metadata };
|
|
399092
|
+
return { id: id5, kind, source, label, content: normalized4, priority, metadata: metadata2 };
|
|
398987
399093
|
}
|
|
398988
399094
|
_normalizeExternalContextItems(raw) {
|
|
398989
399095
|
const arr = Array.isArray(raw) ? raw : [];
|
|
@@ -400738,12 +400844,12 @@ Rewrite it now for ${ctx.model}.`;
|
|
|
400738
400844
|
});
|
|
400739
400845
|
}
|
|
400740
400846
|
_restoreCheckpointToolPromotions(checkpoint, messages) {
|
|
400741
|
-
const
|
|
400847
|
+
const metadata2 = checkpoint.toolPromotions;
|
|
400742
400848
|
const restored = [];
|
|
400743
400849
|
const rejected = [];
|
|
400744
400850
|
const config = this.options.progressiveToolPolicy;
|
|
400745
400851
|
const descriptors2 = new Map(config.descriptors.map((descriptor2) => [descriptor2.name, descriptor2]));
|
|
400746
|
-
for (const entry of
|
|
400852
|
+
for (const entry of metadata2?.entries ?? []) {
|
|
400747
400853
|
const tool = this.tools.get(entry.toolName);
|
|
400748
400854
|
const descriptor2 = descriptors2.get(entry.toolName);
|
|
400749
400855
|
const reason = entry.remainingTurns === 0 ? "expired" : !tool ? "unregistered" : entry.definitionSha256 !== this._toolPromotionDefinitionSha256(tool) ? "definition-changed" : descriptor2 && (descriptor2.role !== "specialized" || (descriptor2.requiresCapabilities ?? []).some((capability) => !config.profile.capabilities.includes(capability))) ? "current-profile-denied" : null;
|
|
@@ -400767,7 +400873,7 @@ Rewrite it now for ${ctx.model}.`;
|
|
|
400767
400873
|
restored.push(`${entry.toolName}:${remainingTurns}t`);
|
|
400768
400874
|
}
|
|
400769
400875
|
this._toolExposureRevision++;
|
|
400770
|
-
const summary = `Update tool discovery: restored=${restored.join(",").slice(0, 800) || "none"}; not restored=${rejected.join(",").slice(0, 800) || (
|
|
400876
|
+
const summary = `Update tool discovery: restored=${restored.join(",").slice(0, 800) || "none"}; not restored=${rejected.join(",").slice(0, 800) || (metadata2 ? "none" : "legacy checkpoint has no discovery leases")}. Tool schemas are revalidated against the current registry and execution profile. Prior discovery messages do not grant current callability. Use tool_search for fresh discovery when a needed schema is absent; ordinary execution and authorization checks still apply. No task progress is granted by restoration.`;
|
|
400771
400877
|
messages.push({ role: "system", policyScope: "runtime", content: summary });
|
|
400772
400878
|
this.emit({ type: "status", content: summary, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
|
|
400773
400879
|
}
|
|
@@ -408079,6 +408185,7 @@ ${dynamicProjectContext}`
|
|
|
408079
408185
|
let completed = false;
|
|
408080
408186
|
let summary = "";
|
|
408081
408187
|
let acceptedCompletionReply;
|
|
408188
|
+
let retainedWorkCompletionReply;
|
|
408082
408189
|
const completionReplyOwners = /* @__PURE__ */ new Map();
|
|
408083
408190
|
const sameResponseTelegramCompletionReplies = /* @__PURE__ */ new Map();
|
|
408084
408191
|
const telegramOnlyCompletionCallIds = /* @__PURE__ */ new Set();
|
|
@@ -408087,6 +408194,13 @@ ${dynamicProjectContext}`
|
|
|
408087
408194
|
const currentTelegramCompletionObjectiveScope = () => {
|
|
408088
408195
|
return this._telegramCompletionObjectiveScope();
|
|
408089
408196
|
};
|
|
408197
|
+
const currentTelegramCompletionNativePolicy = () => taskExecutionDigest({
|
|
408198
|
+
nativeScope: this.options.taskNativeScope ?? null,
|
|
408199
|
+
objective: this._taskObjectiveContract ? {
|
|
408200
|
+
...this._taskObjectiveContract,
|
|
408201
|
+
criteria: this._taskObjectiveContract.criteria.map(({ status: _status, ...criterion }) => criterion)
|
|
408202
|
+
} : null
|
|
408203
|
+
});
|
|
408090
408204
|
const acceptedTaskCompleteArgs = (tc, result, completionTurn) => {
|
|
408091
408205
|
const restored = result.completionRestoredPayload;
|
|
408092
408206
|
const owner = completionReplyOwners.get(tc.id);
|
|
@@ -408101,12 +408215,10 @@ ${dynamicProjectContext}`
|
|
|
408101
408215
|
...restored.missingCriterionIds !== void 0 ? { missing_criterion_ids: [...restored.missingCriterionIds] } : {}
|
|
408102
408216
|
};
|
|
408103
408217
|
};
|
|
408104
|
-
const
|
|
408218
|
+
const currentCompletionReplyCandidate = (toolCallId, args, completionTurn) => {
|
|
408105
408219
|
const owner = completionReplyOwners.get(toolCallId);
|
|
408106
|
-
if (this._isTelegramSurface() && (!owner || owner.runId !== this.currentArtifactRunId() || owner.taskEpoch !== this._taskEpoch || owner.turn !== completionTurn || owner.objectiveScope !== currentTelegramCompletionObjectiveScope())) {
|
|
408107
|
-
|
|
408108
|
-
acceptedVisibleConversationResponse = false;
|
|
408109
|
-
return;
|
|
408220
|
+
if (this._isTelegramSurface() && (!owner || owner.runId !== this.currentArtifactRunId() || owner.taskEpoch !== this._taskEpoch || owner.turn !== completionTurn || owner.objectiveScope !== currentTelegramCompletionObjectiveScope() || owner.nativePolicy !== currentTelegramCompletionNativePolicy())) {
|
|
408221
|
+
return void 0;
|
|
408110
408222
|
}
|
|
408111
408223
|
const rawUserReply = typeof args["user_reply"] === "string" ? args["user_reply"].trim() : "";
|
|
408112
408224
|
const sameResponseBinding = sameResponseTelegramCompletionReplies.get(toolCallId);
|
|
@@ -408114,7 +408226,8 @@ ${dynamicProjectContext}`
|
|
|
408114
408226
|
const explicitText = sameResponseBinding && rawUserReply === sameResponseBinding.text ? "" : rawUserReply;
|
|
408115
408227
|
const modelText = this._isTelegramSurface() ? void 0 : this._latestModelVisibleAssistantText;
|
|
408116
408228
|
const text12 = explicitText || sameResponseText || (modelText?.runId === this.currentArtifactRunId() && modelText.taskEpoch === this._taskEpoch ? modelText.text : "");
|
|
408117
|
-
|
|
408229
|
+
return text12 ? {
|
|
408230
|
+
nativePolicy: currentTelegramCompletionNativePolicy(),
|
|
408118
408231
|
text: text12,
|
|
408119
408232
|
toolCallId,
|
|
408120
408233
|
runId: this.currentArtifactRunId(),
|
|
@@ -408123,7 +408236,10 @@ ${dynamicProjectContext}`
|
|
|
408123
408236
|
...owner?.objectiveFingerprint ? { objectiveFingerprint: owner.objectiveFingerprint } : {},
|
|
408124
408237
|
source: explicitText ? "task_complete_user_reply" : sameResponseText ? sameResponseBinding.source : "model_visible_text"
|
|
408125
408238
|
} : void 0;
|
|
408126
|
-
|
|
408239
|
+
};
|
|
408240
|
+
const captureAcceptedCompletionReply = (toolCallId, args, completionTurn) => {
|
|
408241
|
+
acceptedCompletionReply = currentCompletionReplyCandidate(toolCallId, args, completionTurn);
|
|
408242
|
+
acceptedVisibleConversationResponse = Boolean(acceptedCompletionReply);
|
|
408127
408243
|
};
|
|
408128
408244
|
let acceptedTaskCompleteStatus;
|
|
408129
408245
|
let acceptedTaskCompleteOverride;
|
|
@@ -408784,7 +408900,7 @@ ${lastCompletionGateFeedback.trim().slice(0, 4e3)}` : ""
|
|
|
408784
408900
|
}
|
|
408785
408901
|
return true;
|
|
408786
408902
|
};
|
|
408787
|
-
const holdTaskCompleteGates = (args, turn) => {
|
|
408903
|
+
const holdTaskCompleteGates = (args, turn, acceptedToolCallId) => {
|
|
408788
408904
|
acceptedTaskCompleteStatus = completionStatusFromTaskCompleteArgs(args);
|
|
408789
408905
|
const overrideReason = typeof args["override_reason"] === "string" ? args["override_reason"].trim() : "";
|
|
408790
408906
|
acceptedTaskCompleteOverride = {
|
|
@@ -408816,8 +408932,30 @@ ${lastCompletionGateFeedback.trim().slice(0, 4e3)}` : ""
|
|
|
408816
408932
|
this._completionLedger = reconcileClaimsWithEvidence(this._completionLedger);
|
|
408817
408933
|
this._refreshIntegrationClosure();
|
|
408818
408934
|
}
|
|
408819
|
-
if (this.options.expectedOutcomeContract)
|
|
408935
|
+
if (this.options.expectedOutcomeContract) {
|
|
408936
|
+
if (!["blocked", "incomplete", "needs_input"].includes(acceptedTaskCompleteStatus ?? "")) {
|
|
408937
|
+
const assessment = this._currentExpectedOutcomeAssessment();
|
|
408938
|
+
const missingWork = assessment?.missingEffects.filter((effect) => effect !== "visible_response" && effect !== "delivery") ?? [];
|
|
408939
|
+
if (missingWork.length > 0) {
|
|
408940
|
+
if (acceptedToolCallId)
|
|
408941
|
+
retainedWorkCompletionReply = currentCompletionReplyCandidate(acceptedToolCallId, args, turn);
|
|
408942
|
+
const open4 = this._objectiveFrontier?.criteria.filter((criterion) => criterion.status !== "satisfied").map((criterion) => criterion.id) ?? [];
|
|
408943
|
+
return holdAuthoritativeCompletionDeficit({
|
|
408944
|
+
code: "expected_outcome_work",
|
|
408945
|
+
reason: `Missing required work evidence: ${missingWork.join(", ")}`,
|
|
408946
|
+
feedback: [
|
|
408947
|
+
"[COMPLETION BLOCKED — required work evidence]",
|
|
408948
|
+
`Missing required work effects: ${missingWork.join(", ")}.`,
|
|
408949
|
+
...open4.length ? [`Current unresolved criteria: ${open4.join(", ")}.`] : [],
|
|
408950
|
+
"The adapter accepted the exact answer draft, not proof that the missing work occurred or that Telegram received it.",
|
|
408951
|
+
"Keep this same task, runner, workspace and exact user_reply. Use the admitted tools to gather only the missing evidence, then retry task_complete with the same answer unless the actual findings require a correction.",
|
|
408952
|
+
"Do not redraft merely to satisfy this gate, repeat successful source acquisition, restart planning, or fabricate an observation or provider acknowledgement. If genuinely blocked, report an honest incomplete status or one concrete needs_input question."
|
|
408953
|
+
].join("\n")
|
|
408954
|
+
}, args, turn);
|
|
408955
|
+
}
|
|
408956
|
+
}
|
|
408820
408957
|
return false;
|
|
408958
|
+
}
|
|
408821
408959
|
const authoritativeDeficit = authoritativeCompletionDeficit(turn);
|
|
408822
408960
|
if (authoritativeDeficit) {
|
|
408823
408961
|
return holdAuthoritativeCompletionDeficit(authoritativeDeficit, args, turn);
|
|
@@ -408943,6 +409081,7 @@ ${lastCompletionGateFeedback.trim().slice(0, 4e3)}` : ""
|
|
|
408943
409081
|
const evidenceCallId = `${tc.id}:${crypto.randomUUID()}`;
|
|
408944
409082
|
if (tc.name === "task_complete") {
|
|
408945
409083
|
completionReplyOwners.set(tc.id, {
|
|
409084
|
+
nativePolicy: currentTelegramCompletionNativePolicy(),
|
|
408946
409085
|
runId: evidenceScope.runId,
|
|
408947
409086
|
taskEpoch: evidenceScope.taskEpoch,
|
|
408948
409087
|
turn,
|
|
@@ -414557,7 +414696,7 @@ ${transportFailure2}` : transportFailure2;
|
|
|
414557
414696
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
414558
414697
|
});
|
|
414559
414698
|
} else {
|
|
414560
|
-
if (holdTaskCompleteGates(taskCompleteArgs, turn)) {
|
|
414699
|
+
if (holdTaskCompleteGates(taskCompleteArgs, turn, sr.result.completionAdmission === "accepted" ? matchTc.id : void 0)) {
|
|
414561
414700
|
if (this._completionIncompleteVerification)
|
|
414562
414701
|
break;
|
|
414563
414702
|
continue;
|
|
@@ -414631,7 +414770,7 @@ ${transportFailure2}` : transportFailure2;
|
|
|
414631
414770
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
414632
414771
|
});
|
|
414633
414772
|
} else {
|
|
414634
|
-
if (holdTaskCompleteGates(taskCompleteArgs, turn)) {
|
|
414773
|
+
if (holdTaskCompleteGates(taskCompleteArgs, turn, r.completionAdmission === "accepted" ? r.tc.id : void 0)) {
|
|
414635
414774
|
if (this._completionIncompleteVerification)
|
|
414636
414775
|
break;
|
|
414637
414776
|
continue;
|
|
@@ -414750,7 +414889,7 @@ ${transportFailure2}` : transportFailure2;
|
|
|
414750
414889
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
414751
414890
|
});
|
|
414752
414891
|
} else {
|
|
414753
|
-
if (holdTaskCompleteGates(taskCompleteArgs, turn)) {
|
|
414892
|
+
if (holdTaskCompleteGates(taskCompleteArgs, turn, r.completionAdmission === "accepted" ? r.tc.id : void 0)) {
|
|
414754
414893
|
if (this._completionIncompleteVerification)
|
|
414755
414894
|
break;
|
|
414756
414895
|
continue;
|
|
@@ -415695,7 +415834,7 @@ ${diagnosis}` : diagnosis;
|
|
|
415695
415834
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
415696
415835
|
});
|
|
415697
415836
|
} else {
|
|
415698
|
-
if (holdTaskCompleteGates(taskCompleteArgs, turn)) {
|
|
415837
|
+
if (holdTaskCompleteGates(taskCompleteArgs, turn, r.completionAdmission === "accepted" ? r.tc.id : void 0)) {
|
|
415699
415838
|
if (this._completionIncompleteVerification)
|
|
415700
415839
|
break;
|
|
415701
415840
|
continue;
|
|
@@ -417121,6 +417260,8 @@ Result: ${summary.slice(0, 330)}`,
|
|
|
417121
417260
|
await this._deferredMemoryQueue;
|
|
417122
417261
|
} catch {
|
|
417123
417262
|
}
|
|
417263
|
+
const missingRetainedWorkEffects = expectedOutcomeAssessment?.missingEffects.filter((effect) => effect !== "visible_response" && effect !== "delivery") ?? [];
|
|
417264
|
+
const retainedWorkReplyIsCurrent = Boolean(this._isTelegramSurface() && retainedWorkCompletionReply && terminalReceipt && !completed && !this.aborted && !this._pendingSteeringPreemption && !terminalReceipt.runtimeFailure && !this.taskRequirementInterpretationPending && !this._hasUnresolvedCurrentSteeringInputs() && !declaredDegradedCompletion && missingRetainedWorkEffects.length > 0 && retainedWorkCompletionReply.runId === this.currentArtifactRunId() && retainedWorkCompletionReply.taskEpoch === this._taskEpoch && retainedWorkCompletionReply.taskEpoch === terminalReceipt.taskEpoch && retainedWorkCompletionReply.objectiveScope === currentTelegramCompletionObjectiveScope() && retainedWorkCompletionReply.nativePolicy === currentTelegramCompletionNativePolicy());
|
|
417124
417265
|
const declaredIncompleteReplyIsCurrent = Boolean(acceptedTaskCompleteStatus === "incomplete" && runStatus === "incomplete" && !this.aborted && !terminalReceipt?.runtimeFailure && terminalReceipt?.status === "incomplete" && acceptedCompletionReply?.source === "task_complete_user_reply" && acceptedCompletionReply.runId === this.currentArtifactRunId() && acceptedCompletionReply.taskEpoch === this._taskEpoch && acceptedCompletionReply.objectiveScope === currentTelegramCompletionObjectiveScope());
|
|
417125
417266
|
return {
|
|
417126
417267
|
status: runStatus,
|
|
@@ -417148,6 +417289,19 @@ Result: ${summary.slice(0, 330)}`,
|
|
|
417148
417289
|
terminalReceiptId: terminalReceipt.id,
|
|
417149
417290
|
authority: declaredIncompleteReplyIsCurrent ? "declared_incomplete" : providerDeliveryIsOnlyRemainingEffect || providerDeliveryEffectsArePending ? "provider_delivery_pending" : "router_expected_effect_mismatch"
|
|
417150
417291
|
} : void 0,
|
|
417292
|
+
...retainedWorkReplyIsCurrent && retainedWorkCompletionReply && terminalReceipt ? {
|
|
417293
|
+
retainedCompletionReply: {
|
|
417294
|
+
schema: "omnius.retained-completion-reply.v1",
|
|
417295
|
+
authority: "pending_work_evidence",
|
|
417296
|
+
text: retainedWorkCompletionReply.text,
|
|
417297
|
+
toolCallId: retainedWorkCompletionReply.toolCallId,
|
|
417298
|
+
runId: terminalReceipt.runId,
|
|
417299
|
+
taskEpoch: retainedWorkCompletionReply.taskEpoch,
|
|
417300
|
+
terminalReceiptId: terminalReceipt.id,
|
|
417301
|
+
objectiveScope: retainedWorkCompletionReply.objectiveScope,
|
|
417302
|
+
missingEffects: missingRetainedWorkEffects
|
|
417303
|
+
}
|
|
417304
|
+
} : {},
|
|
417151
417305
|
durationMs,
|
|
417152
417306
|
filesEdited,
|
|
417153
417307
|
testsRun,
|