omnius 1.0.537 → 1.0.538
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
CHANGED
|
@@ -1209,8 +1209,8 @@ var init_model_broker = __esm({
|
|
|
1209
1209
|
}
|
|
1210
1210
|
/** Restore a set of previously evicted Ollama models, oldest first. */
|
|
1211
1211
|
async restoreOllamaModels(models, options2 = {}) {
|
|
1212
|
-
const
|
|
1213
|
-
for (const model of
|
|
1212
|
+
const unique3 = dedupeLoadedModels(models.filter((m2) => m2.host === "ollama")).sort((a2, b) => a2.lastUsedAt - b.lastUsedAt);
|
|
1213
|
+
for (const model of unique3) {
|
|
1214
1214
|
await this.warmOllamaModel(model.name, options2.keepAlive ?? "30m").catch(() => false);
|
|
1215
1215
|
}
|
|
1216
1216
|
}
|
|
@@ -16121,8 +16121,8 @@ function mapItemKind(value2) {
|
|
|
16121
16121
|
}
|
|
16122
16122
|
return "custom";
|
|
16123
16123
|
}
|
|
16124
|
-
function mapScopeRow(
|
|
16125
|
-
const r2 =
|
|
16124
|
+
function mapScopeRow(row2) {
|
|
16125
|
+
const r2 = row2;
|
|
16126
16126
|
return {
|
|
16127
16127
|
id: String(r2.id ?? ""),
|
|
16128
16128
|
name: String(r2.name ?? ""),
|
|
@@ -16136,8 +16136,8 @@ function mapScopeRow(row) {
|
|
|
16136
16136
|
updatedAt: String(r2.updated_at ?? "")
|
|
16137
16137
|
};
|
|
16138
16138
|
}
|
|
16139
|
-
function mapItemRow(
|
|
16140
|
-
const r2 =
|
|
16139
|
+
function mapItemRow(row2) {
|
|
16140
|
+
const r2 = row2;
|
|
16141
16141
|
return {
|
|
16142
16142
|
id: String(r2.id ?? ""),
|
|
16143
16143
|
scopeId: String(r2.scope_id ?? ""),
|
|
@@ -16158,8 +16158,8 @@ function mapItemRow(row) {
|
|
|
16158
16158
|
updatedAt: String(r2.updated_at ?? "")
|
|
16159
16159
|
};
|
|
16160
16160
|
}
|
|
16161
|
-
function mapChunkRow(
|
|
16162
|
-
const r2 =
|
|
16161
|
+
function mapChunkRow(row2) {
|
|
16162
|
+
const r2 = row2;
|
|
16163
16163
|
return {
|
|
16164
16164
|
id: String(r2.id ?? ""),
|
|
16165
16165
|
itemId: String(r2.item_id ?? ""),
|
|
@@ -16172,8 +16172,8 @@ function mapChunkRow(row) {
|
|
|
16172
16172
|
createdAt: String(r2.created_at ?? "")
|
|
16173
16173
|
};
|
|
16174
16174
|
}
|
|
16175
|
-
function mapEmbeddingSetRow(
|
|
16176
|
-
const r2 =
|
|
16175
|
+
function mapEmbeddingSetRow(row2) {
|
|
16176
|
+
const r2 = row2;
|
|
16177
16177
|
const setType = r2.set_type === "filter" ? "filter" : "full";
|
|
16178
16178
|
return {
|
|
16179
16179
|
id: String(r2.id ?? ""),
|
|
@@ -16187,8 +16187,8 @@ function mapEmbeddingSetRow(row) {
|
|
|
16187
16187
|
updatedAt: String(r2.updated_at ?? "")
|
|
16188
16188
|
};
|
|
16189
16189
|
}
|
|
16190
|
-
function mapEmbeddingRow(
|
|
16191
|
-
const r2 =
|
|
16190
|
+
function mapEmbeddingRow(row2) {
|
|
16191
|
+
const r2 = row2;
|
|
16192
16192
|
return {
|
|
16193
16193
|
id: String(r2.id ?? ""),
|
|
16194
16194
|
chunkId: String(r2.chunk_id ?? ""),
|
|
@@ -16200,8 +16200,8 @@ function mapEmbeddingRow(row) {
|
|
|
16200
16200
|
createdAt: String(r2.created_at ?? "")
|
|
16201
16201
|
};
|
|
16202
16202
|
}
|
|
16203
|
-
function mapProvenanceRow(
|
|
16204
|
-
const r2 =
|
|
16203
|
+
function mapProvenanceRow(row2) {
|
|
16204
|
+
const r2 = row2;
|
|
16205
16205
|
return {
|
|
16206
16206
|
id: String(r2.id ?? ""),
|
|
16207
16207
|
itemId: String(r2.item_id ?? ""),
|
|
@@ -16214,8 +16214,8 @@ function mapProvenanceRow(row) {
|
|
|
16214
16214
|
createdAt: String(r2.created_at ?? "")
|
|
16215
16215
|
};
|
|
16216
16216
|
}
|
|
16217
|
-
function mapLinkRow(
|
|
16218
|
-
const r2 =
|
|
16217
|
+
function mapLinkRow(row2) {
|
|
16218
|
+
const r2 = row2;
|
|
16219
16219
|
return {
|
|
16220
16220
|
id: String(r2.id ?? ""),
|
|
16221
16221
|
sourceItemId: String(r2.source_item_id ?? ""),
|
|
@@ -16234,8 +16234,8 @@ function mapJobStatus(value2) {
|
|
|
16234
16234
|
}
|
|
16235
16235
|
return "pending";
|
|
16236
16236
|
}
|
|
16237
|
-
function mapJobRow(
|
|
16238
|
-
const r2 =
|
|
16237
|
+
function mapJobRow(row2) {
|
|
16238
|
+
const r2 = row2;
|
|
16239
16239
|
return {
|
|
16240
16240
|
id: String(r2.id ?? ""),
|
|
16241
16241
|
jobType: String(r2.job_type ?? ""),
|
|
@@ -16259,8 +16259,8 @@ function mapGraphNodeType(value2) {
|
|
|
16259
16259
|
}
|
|
16260
16260
|
return "concept";
|
|
16261
16261
|
}
|
|
16262
|
-
function mapGraphNodeRow(
|
|
16263
|
-
const r2 =
|
|
16262
|
+
function mapGraphNodeRow(row2) {
|
|
16263
|
+
const r2 = row2;
|
|
16264
16264
|
return {
|
|
16265
16265
|
id: String(r2.id ?? ""),
|
|
16266
16266
|
scopeId: String(r2.scope_id ?? ""),
|
|
@@ -16274,8 +16274,8 @@ function mapGraphNodeRow(row) {
|
|
|
16274
16274
|
lastSeenAt: String(r2.last_seen_at ?? "")
|
|
16275
16275
|
};
|
|
16276
16276
|
}
|
|
16277
|
-
function mapGraphEdgeRow(
|
|
16278
|
-
const r2 =
|
|
16277
|
+
function mapGraphEdgeRow(row2) {
|
|
16278
|
+
const r2 = row2;
|
|
16279
16279
|
return {
|
|
16280
16280
|
id: String(r2.id ?? ""),
|
|
16281
16281
|
scopeId: String(r2.scope_id ?? ""),
|
|
@@ -16291,8 +16291,8 @@ function mapGraphEdgeRow(row) {
|
|
|
16291
16291
|
createdAt: String(r2.created_at ?? "")
|
|
16292
16292
|
};
|
|
16293
16293
|
}
|
|
16294
|
-
function mapItemNodeRow(
|
|
16295
|
-
const r2 =
|
|
16294
|
+
function mapItemNodeRow(row2) {
|
|
16295
|
+
const r2 = row2;
|
|
16296
16296
|
return {
|
|
16297
16297
|
itemId: String(r2.item_id ?? ""),
|
|
16298
16298
|
nodeId: String(r2.node_id ?? ""),
|
|
@@ -16303,8 +16303,8 @@ function mapItemNodeRow(row) {
|
|
|
16303
16303
|
updatedAt: String(r2.updated_at ?? "")
|
|
16304
16304
|
};
|
|
16305
16305
|
}
|
|
16306
|
-
function mapCandidateRow(
|
|
16307
|
-
const r2 =
|
|
16306
|
+
function mapCandidateRow(row2, source, score) {
|
|
16307
|
+
const r2 = row2;
|
|
16308
16308
|
const scope = {
|
|
16309
16309
|
id: String(r2.scope_id ?? ""),
|
|
16310
16310
|
name: String(r2.scope_name ?? ""),
|
|
@@ -16396,12 +16396,12 @@ var init_unifiedMemoryStore = __esm({
|
|
|
16396
16396
|
return scope;
|
|
16397
16397
|
}
|
|
16398
16398
|
getScopeByName(name10) {
|
|
16399
|
-
const
|
|
16400
|
-
return
|
|
16399
|
+
const row2 = this.db.prepare("SELECT * FROM memory_scope WHERE name = ?").get(name10);
|
|
16400
|
+
return row2 ? mapScopeRow(row2) : null;
|
|
16401
16401
|
}
|
|
16402
16402
|
getScopeById(id2) {
|
|
16403
|
-
const
|
|
16404
|
-
return
|
|
16403
|
+
const row2 = this.db.prepare("SELECT * FROM memory_scope WHERE id = ?").get(id2);
|
|
16404
|
+
return row2 ? mapScopeRow(row2) : null;
|
|
16405
16405
|
}
|
|
16406
16406
|
ensureEmbeddingSet(input) {
|
|
16407
16407
|
const existing = this.getEmbeddingSetBySlug(input.slug);
|
|
@@ -16423,12 +16423,12 @@ var init_unifiedMemoryStore = __esm({
|
|
|
16423
16423
|
return this.ensureEmbeddingSet({ slug: this.defaultEmbeddingSetSlug, setType: "full" });
|
|
16424
16424
|
}
|
|
16425
16425
|
getEmbeddingSetBySlug(slug) {
|
|
16426
|
-
const
|
|
16427
|
-
return
|
|
16426
|
+
const row2 = this.db.prepare("SELECT * FROM memory_embedding_set WHERE slug = ?").get(slug);
|
|
16427
|
+
return row2 ? mapEmbeddingSetRow(row2) : null;
|
|
16428
16428
|
}
|
|
16429
16429
|
getEmbeddingSetById(id2) {
|
|
16430
|
-
const
|
|
16431
|
-
return
|
|
16430
|
+
const row2 = this.db.prepare("SELECT * FROM memory_embedding_set WHERE id = ?").get(id2);
|
|
16431
|
+
return row2 ? mapEmbeddingSetRow(row2) : null;
|
|
16432
16432
|
}
|
|
16433
16433
|
upsertItem(input) {
|
|
16434
16434
|
const txn = this.db.transaction(() => {
|
|
@@ -16506,50 +16506,50 @@ var init_unifiedMemoryStore = __esm({
|
|
|
16506
16506
|
return txn();
|
|
16507
16507
|
}
|
|
16508
16508
|
getItem(id2) {
|
|
16509
|
-
const
|
|
16510
|
-
return
|
|
16509
|
+
const row2 = this.db.prepare("SELECT * FROM memory_item WHERE id = ?").get(id2);
|
|
16510
|
+
return row2 ? mapItemRow(row2) : null;
|
|
16511
16511
|
}
|
|
16512
16512
|
countItems() {
|
|
16513
|
-
const
|
|
16513
|
+
const row2 = this.db.prepare(`
|
|
16514
16514
|
SELECT COUNT(*) AS count
|
|
16515
16515
|
FROM memory_item
|
|
16516
16516
|
WHERE deleted_at IS NULL
|
|
16517
16517
|
AND (expires_at IS NULL OR expires_at > ?)
|
|
16518
16518
|
`).get(this.nowIso());
|
|
16519
|
-
return toNumber(
|
|
16519
|
+
return toNumber(row2?.count, 0);
|
|
16520
16520
|
}
|
|
16521
16521
|
countChunks() {
|
|
16522
|
-
const
|
|
16522
|
+
const row2 = this.db.prepare(`
|
|
16523
16523
|
SELECT COUNT(*) AS count
|
|
16524
16524
|
FROM memory_chunk c
|
|
16525
16525
|
JOIN memory_item i ON i.id = c.item_id
|
|
16526
16526
|
WHERE i.deleted_at IS NULL
|
|
16527
16527
|
AND (i.expires_at IS NULL OR i.expires_at > ?)
|
|
16528
16528
|
`).get(this.nowIso());
|
|
16529
|
-
return toNumber(
|
|
16529
|
+
return toNumber(row2?.count, 0);
|
|
16530
16530
|
}
|
|
16531
16531
|
countEmbeddings(embeddingSetSlug) {
|
|
16532
16532
|
if (embeddingSetSlug) {
|
|
16533
16533
|
const set = this.getEmbeddingSetBySlug(embeddingSetSlug);
|
|
16534
16534
|
if (!set)
|
|
16535
16535
|
return 0;
|
|
16536
|
-
const
|
|
16536
|
+
const row3 = this.db.prepare(`
|
|
16537
16537
|
SELECT COUNT(*) AS count
|
|
16538
16538
|
FROM memory_embedding_v2
|
|
16539
16539
|
WHERE embedding_set_id = ?
|
|
16540
16540
|
`).get(set.id);
|
|
16541
|
-
return toNumber(
|
|
16541
|
+
return toNumber(row3?.count, 0);
|
|
16542
16542
|
}
|
|
16543
|
-
const
|
|
16544
|
-
return toNumber(
|
|
16543
|
+
const row2 = this.db.prepare("SELECT COUNT(*) AS count FROM memory_embedding_v2").get();
|
|
16544
|
+
return toNumber(row2?.count, 0);
|
|
16545
16545
|
}
|
|
16546
16546
|
countGraphNodes() {
|
|
16547
|
-
const
|
|
16548
|
-
return toNumber(
|
|
16547
|
+
const row2 = this.db.prepare("SELECT COUNT(*) AS count FROM memory_graph_node").get();
|
|
16548
|
+
return toNumber(row2?.count, 0);
|
|
16549
16549
|
}
|
|
16550
16550
|
countGraphEdges(activeOnly = true) {
|
|
16551
|
-
const
|
|
16552
|
-
return toNumber(
|
|
16551
|
+
const row2 = activeOnly ? this.db.prepare("SELECT COUNT(*) AS count FROM memory_graph_edge WHERE valid_until IS NULL").get() : this.db.prepare("SELECT COUNT(*) AS count FROM memory_graph_edge").get();
|
|
16552
|
+
return toNumber(row2?.count, 0);
|
|
16553
16553
|
}
|
|
16554
16554
|
getChunks(itemId2) {
|
|
16555
16555
|
const rows = this.db.prepare(`
|
|
@@ -16558,8 +16558,8 @@ var init_unifiedMemoryStore = __esm({
|
|
|
16558
16558
|
return rows.map(mapChunkRow);
|
|
16559
16559
|
}
|
|
16560
16560
|
getChunk(id2) {
|
|
16561
|
-
const
|
|
16562
|
-
return
|
|
16561
|
+
const row2 = this.db.prepare("SELECT * FROM memory_chunk WHERE id = ?").get(id2);
|
|
16562
|
+
return row2 ? mapChunkRow(row2) : null;
|
|
16563
16563
|
}
|
|
16564
16564
|
storeChunkEmbedding(chunkId, vector, options2 = {}) {
|
|
16565
16565
|
const chunk = this.getChunk(chunkId);
|
|
@@ -16582,12 +16582,12 @@ var init_unifiedMemoryStore = __esm({
|
|
|
16582
16582
|
input_hash = excluded.input_hash,
|
|
16583
16583
|
created_at = excluded.created_at
|
|
16584
16584
|
`).run(id2, chunkId, embeddingSet.id, encodeMemoryVector(normalized), options2.model ?? embeddingSet.model, normalized.length, inputHash, now2);
|
|
16585
|
-
const
|
|
16585
|
+
const row2 = this.db.prepare(`
|
|
16586
16586
|
SELECT * FROM memory_embedding_v2 WHERE chunk_id = ? AND embedding_set_id = ?
|
|
16587
16587
|
`).get(chunkId, embeddingSet.id);
|
|
16588
|
-
if (!
|
|
16588
|
+
if (!row2)
|
|
16589
16589
|
throw new Error(`Failed to store embedding for memory chunk ${chunkId}`);
|
|
16590
|
-
return mapEmbeddingRow(
|
|
16590
|
+
return mapEmbeddingRow(row2);
|
|
16591
16591
|
}
|
|
16592
16592
|
recordProvenance(itemId2, input) {
|
|
16593
16593
|
const id2 = randomUUID4();
|
|
@@ -16597,10 +16597,10 @@ var init_unifiedMemoryStore = __esm({
|
|
|
16597
16597
|
(id, item_id, source_type, source_id, source_uri, observed_at, actor, metadata_json, created_at)
|
|
16598
16598
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
16599
16599
|
`).run(id2, itemId2, input.sourceType, input.sourceId ?? "", input.sourceUri ?? "", input.observedAt ?? null, input.actor ?? "", stringifyJson(input.metadata), now2);
|
|
16600
|
-
const
|
|
16601
|
-
if (!
|
|
16600
|
+
const row2 = this.db.prepare("SELECT * FROM memory_provenance WHERE id = ?").get(id2);
|
|
16601
|
+
if (!row2)
|
|
16602
16602
|
throw new Error(`Failed to record provenance for memory item ${itemId2}`);
|
|
16603
|
-
return mapProvenanceRow(
|
|
16603
|
+
return mapProvenanceRow(row2);
|
|
16604
16604
|
}
|
|
16605
16605
|
getProvenance(itemId2) {
|
|
16606
16606
|
const rows = this.db.prepare(`
|
|
@@ -16620,13 +16620,13 @@ var init_unifiedMemoryStore = __esm({
|
|
|
16620
16620
|
evidence = excluded.evidence,
|
|
16621
16621
|
metadata_json = excluded.metadata_json
|
|
16622
16622
|
`).run(id2, input.sourceItemId, input.targetItemId, input.linkType ?? "related", clamp012(input.weight ?? 0.5), input.evidence ?? "", stringifyJson(input.metadata), now2);
|
|
16623
|
-
const
|
|
16623
|
+
const row2 = this.db.prepare(`
|
|
16624
16624
|
SELECT * FROM memory_link_v2
|
|
16625
16625
|
WHERE source_item_id = ? AND target_item_id = ? AND link_type = ?
|
|
16626
16626
|
`).get(input.sourceItemId, input.targetItemId, input.linkType ?? "related");
|
|
16627
|
-
if (!
|
|
16627
|
+
if (!row2)
|
|
16628
16628
|
throw new Error("Failed to create memory link");
|
|
16629
|
-
return mapLinkRow(
|
|
16629
|
+
return mapLinkRow(row2);
|
|
16630
16630
|
}
|
|
16631
16631
|
searchLexical(query, options2 = {}) {
|
|
16632
16632
|
const terms2 = extractSearchTerms(query);
|
|
@@ -16654,11 +16654,11 @@ var init_unifiedMemoryStore = __esm({
|
|
|
16654
16654
|
LIMIT ?
|
|
16655
16655
|
`;
|
|
16656
16656
|
const rows = this.db.prepare(sql).all(...termParams, ...filters.params, limit);
|
|
16657
|
-
return rows.map((
|
|
16658
|
-
const rowText = `${
|
|
16657
|
+
return rows.map((row2, index) => {
|
|
16658
|
+
const rowText = `${row2.item_title ?? ""} ${row2.chunk_text ?? ""}`;
|
|
16659
16659
|
const hitScore = lexicalHitScore(rowText, terms2);
|
|
16660
16660
|
const rankScore = Math.max(hitScore, 1 / (index + 1));
|
|
16661
|
-
const match = mapCandidateRow(
|
|
16661
|
+
const match = mapCandidateRow(row2, "lexical", rankScore);
|
|
16662
16662
|
match.rank = index + 1;
|
|
16663
16663
|
match.rawScore = hitScore;
|
|
16664
16664
|
match.scoreBreakdown.lexical = rankScore;
|
|
@@ -16692,12 +16692,12 @@ var init_unifiedMemoryStore = __esm({
|
|
|
16692
16692
|
LIMIT ?
|
|
16693
16693
|
`;
|
|
16694
16694
|
const rows = this.db.prepare(sql).all(query.length, ...embeddingFilter.params, ...filters.params, scanLimit);
|
|
16695
|
-
const matches = rows.map((
|
|
16696
|
-
const rowData =
|
|
16695
|
+
const matches = rows.map((row2) => {
|
|
16696
|
+
const rowData = row2;
|
|
16697
16697
|
const embedding = decodeMemoryVector(rowData.embedding_vector);
|
|
16698
16698
|
const similarity3 = cosineMemorySimilarity(query, embedding);
|
|
16699
16699
|
const score = clamp012((similarity3 + 1) / 2);
|
|
16700
|
-
const match = mapCandidateRow(
|
|
16700
|
+
const match = mapCandidateRow(row2, "vector", score);
|
|
16701
16701
|
match.embedding = embedding;
|
|
16702
16702
|
match.vectorSimilarity = similarity3;
|
|
16703
16703
|
match.rawScore = similarity3;
|
|
@@ -16708,8 +16708,8 @@ var init_unifiedMemoryStore = __esm({
|
|
|
16708
16708
|
return matches.filter((match) => match.score >= (options2.minScore ?? 0)).sort((a2, b) => b.score - a2.score).slice(0, limit).map((match, index) => ({ ...match, rank: index + 1 }));
|
|
16709
16709
|
}
|
|
16710
16710
|
recordAccess(itemIds) {
|
|
16711
|
-
const
|
|
16712
|
-
if (
|
|
16711
|
+
const unique3 = [...new Set(itemIds)].filter(Boolean);
|
|
16712
|
+
if (unique3.length === 0)
|
|
16713
16713
|
return;
|
|
16714
16714
|
const update2 = this.db.prepare(`
|
|
16715
16715
|
UPDATE memory_item
|
|
@@ -16719,7 +16719,7 @@ var init_unifiedMemoryStore = __esm({
|
|
|
16719
16719
|
`);
|
|
16720
16720
|
const now2 = this.nowIso();
|
|
16721
16721
|
const txn = this.db.transaction(() => {
|
|
16722
|
-
for (const id2 of
|
|
16722
|
+
for (const id2 of unique3)
|
|
16723
16723
|
update2.run(now2, id2);
|
|
16724
16724
|
});
|
|
16725
16725
|
txn();
|
|
@@ -16738,8 +16738,8 @@ var init_unifiedMemoryStore = __esm({
|
|
|
16738
16738
|
return job;
|
|
16739
16739
|
}
|
|
16740
16740
|
getJob(id2) {
|
|
16741
|
-
const
|
|
16742
|
-
return
|
|
16741
|
+
const row2 = this.db.prepare("SELECT * FROM memory_job_queue WHERE id = ?").get(id2);
|
|
16742
|
+
return row2 ? mapJobRow(row2) : null;
|
|
16743
16743
|
}
|
|
16744
16744
|
claimJobs(jobTypes, limit = 10) {
|
|
16745
16745
|
if (jobTypes.length === 0)
|
|
@@ -16839,13 +16839,13 @@ var init_unifiedMemoryStore = __esm({
|
|
|
16839
16839
|
metadata_json = excluded.metadata_json,
|
|
16840
16840
|
last_seen_at = excluded.last_seen_at
|
|
16841
16841
|
`).run(id2, input.scopeId, normalized, input.text.trim(), nodeType, clamp012(input.weight ?? 0.5), stringifyJson(input.metadata), now2, now2);
|
|
16842
|
-
const
|
|
16842
|
+
const row2 = this.db.prepare(`
|
|
16843
16843
|
SELECT * FROM memory_graph_node
|
|
16844
16844
|
WHERE scope_id = ? AND normalized_text = ? AND node_type = ?
|
|
16845
16845
|
`).get(input.scopeId, normalized, nodeType);
|
|
16846
|
-
if (!
|
|
16846
|
+
if (!row2)
|
|
16847
16847
|
throw new Error(`Failed to upsert graph node ${input.text}`);
|
|
16848
|
-
return mapGraphNodeRow(
|
|
16848
|
+
return mapGraphNodeRow(row2);
|
|
16849
16849
|
}
|
|
16850
16850
|
linkItemToGraphNode(input) {
|
|
16851
16851
|
const now2 = this.nowIso();
|
|
@@ -16859,12 +16859,12 @@ var init_unifiedMemoryStore = __esm({
|
|
|
16859
16859
|
evidence = excluded.evidence,
|
|
16860
16860
|
updated_at = excluded.updated_at
|
|
16861
16861
|
`).run(input.itemId, input.nodeId, relation, clamp012(input.weight ?? 0.5), input.evidence ?? "", now2, now2);
|
|
16862
|
-
const
|
|
16862
|
+
const row2 = this.db.prepare(`
|
|
16863
16863
|
SELECT * FROM memory_item_node WHERE item_id = ? AND node_id = ? AND relation = ?
|
|
16864
16864
|
`).get(input.itemId, input.nodeId, relation);
|
|
16865
|
-
if (!
|
|
16865
|
+
if (!row2)
|
|
16866
16866
|
throw new Error("Failed to link memory item to graph node");
|
|
16867
|
-
return mapItemNodeRow(
|
|
16867
|
+
return mapItemNodeRow(row2);
|
|
16868
16868
|
}
|
|
16869
16869
|
createGraphEdge(input) {
|
|
16870
16870
|
const id2 = input.id ?? randomUUID4();
|
|
@@ -16880,14 +16880,14 @@ var init_unifiedMemoryStore = __esm({
|
|
|
16880
16880
|
metadata_json = excluded.metadata_json,
|
|
16881
16881
|
valid_until = NULL
|
|
16882
16882
|
`).run(id2, input.scopeId, input.sourceNodeId, input.targetNodeId, relation, clamp012(input.weight ?? 0.5), input.sourceItemId ?? null, input.evidence ?? "", stringifyJson(input.metadata), now2, now2);
|
|
16883
|
-
const
|
|
16883
|
+
const row2 = this.db.prepare(`
|
|
16884
16884
|
SELECT * FROM memory_graph_edge
|
|
16885
16885
|
WHERE scope_id = ? AND source_node_id = ? AND target_node_id = ? AND relation = ?
|
|
16886
16886
|
AND (source_item_id = ? OR (source_item_id IS NULL AND ? IS NULL))
|
|
16887
16887
|
`).get(input.scopeId, input.sourceNodeId, input.targetNodeId, relation, input.sourceItemId ?? null, input.sourceItemId ?? null);
|
|
16888
|
-
if (!
|
|
16888
|
+
if (!row2)
|
|
16889
16889
|
throw new Error("Failed to create graph edge");
|
|
16890
|
-
return mapGraphEdgeRow(
|
|
16890
|
+
return mapGraphEdgeRow(row2);
|
|
16891
16891
|
}
|
|
16892
16892
|
clearItemGraph(itemId2) {
|
|
16893
16893
|
this.db.prepare("DELETE FROM memory_item_node WHERE item_id = ?").run(itemId2);
|
|
@@ -16917,11 +16917,11 @@ var init_unifiedMemoryStore = __esm({
|
|
|
16917
16917
|
ORDER BY n.mention_count DESC, n.weight DESC, i.importance DESC, c.sequence ASC
|
|
16918
16918
|
LIMIT ?
|
|
16919
16919
|
`).all(...nodeParams, ...filters.params, limit);
|
|
16920
|
-
return rows.map((
|
|
16921
|
-
const r2 =
|
|
16920
|
+
return rows.map((row2, index) => {
|
|
16921
|
+
const r2 = row2;
|
|
16922
16922
|
const hitScore = Math.min(1, toNumber(r2.graph_mention_count, 1) / 10 * 0.4 + toNumber(r2.graph_node_weight, 0.5) * 0.4 + toNumber(r2.graph_item_weight, 0.5) * 0.2);
|
|
16923
16923
|
const rankScore = Math.max(hitScore, 1 / (index + 1));
|
|
16924
|
-
const match = mapCandidateRow(
|
|
16924
|
+
const match = mapCandidateRow(row2, "graph", rankScore);
|
|
16925
16925
|
match.rank = index + 1;
|
|
16926
16926
|
match.rawScore = hitScore;
|
|
16927
16927
|
match.scoreBreakdown.graph = rankScore;
|
|
@@ -16988,7 +16988,7 @@ var init_unifiedMemoryStore = __esm({
|
|
|
16988
16988
|
ORDER BY updated_at ASC
|
|
16989
16989
|
LIMIT ?
|
|
16990
16990
|
`).all(cutoff, maxItems);
|
|
16991
|
-
const itemIds = rows.map((
|
|
16991
|
+
const itemIds = rows.map((row2) => String(row2.id ?? "")).filter(Boolean);
|
|
16992
16992
|
if (itemIds.length === 0)
|
|
16993
16993
|
return { decayed: 0, itemIds: [] };
|
|
16994
16994
|
const txn = this.db.transaction(() => {
|
|
@@ -17078,9 +17078,9 @@ var init_unifiedMemoryStore = __esm({
|
|
|
17078
17078
|
ORDER BY i.importance DESC, i.updated_at DESC, c.sequence ASC
|
|
17079
17079
|
LIMIT ?
|
|
17080
17080
|
`).all(...params, ...filters.params, limit);
|
|
17081
|
-
return rows.map((
|
|
17081
|
+
return rows.map((row2, index) => {
|
|
17082
17082
|
const score = 1 / (index + 1);
|
|
17083
|
-
const match = mapCandidateRow(
|
|
17083
|
+
const match = mapCandidateRow(row2, "lexical", score);
|
|
17084
17084
|
match.rank = index + 1;
|
|
17085
17085
|
match.scoreBreakdown.lexical = score;
|
|
17086
17086
|
match.scoreBreakdown.itemQuality = itemQuality(match.item);
|
|
@@ -17977,18 +17977,18 @@ var init_memoryPrefill = __esm({
|
|
|
17977
17977
|
});
|
|
17978
17978
|
|
|
17979
17979
|
// packages/memory/dist/repoProfileStore.js
|
|
17980
|
-
function rowToProfile(
|
|
17980
|
+
function rowToProfile(row2) {
|
|
17981
17981
|
return {
|
|
17982
|
-
repoRoot:
|
|
17983
|
-
languages: JSON.parse(
|
|
17984
|
-
frameworks: JSON.parse(
|
|
17985
|
-
buildSystem:
|
|
17986
|
-
testCommands: JSON.parse(
|
|
17987
|
-
lintCommands: JSON.parse(
|
|
17988
|
-
packageManager:
|
|
17989
|
-
notes:
|
|
17990
|
-
createdAt:
|
|
17991
|
-
updatedAt:
|
|
17982
|
+
repoRoot: row2.repo_root,
|
|
17983
|
+
languages: JSON.parse(row2.languages),
|
|
17984
|
+
frameworks: JSON.parse(row2.frameworks),
|
|
17985
|
+
buildSystem: row2.build_system,
|
|
17986
|
+
testCommands: JSON.parse(row2.test_commands),
|
|
17987
|
+
lintCommands: JSON.parse(row2.lint_commands),
|
|
17988
|
+
packageManager: row2.package_manager,
|
|
17989
|
+
notes: row2.notes ?? null,
|
|
17990
|
+
createdAt: row2.created_at,
|
|
17991
|
+
updatedAt: row2.updated_at
|
|
17992
17992
|
};
|
|
17993
17993
|
}
|
|
17994
17994
|
var RepoProfileStore;
|
|
@@ -18020,8 +18020,8 @@ var init_repoProfileStore = __esm({
|
|
|
18020
18020
|
}
|
|
18021
18021
|
/** Retrieve a profile by repository root path, or `null` if not found. */
|
|
18022
18022
|
get(repoRoot) {
|
|
18023
|
-
const
|
|
18024
|
-
return
|
|
18023
|
+
const row2 = this.db.prepare("SELECT * FROM repo_profiles WHERE repo_root = ?").get(repoRoot);
|
|
18024
|
+
return row2 ? rowToProfile(row2) : null;
|
|
18025
18025
|
}
|
|
18026
18026
|
/** List all stored repository profiles. */
|
|
18027
18027
|
list() {
|
|
@@ -18037,19 +18037,19 @@ var init_repoProfileStore = __esm({
|
|
|
18037
18037
|
});
|
|
18038
18038
|
|
|
18039
18039
|
// packages/memory/dist/fileSummaryStore.js
|
|
18040
|
-
function rowToSummary(
|
|
18040
|
+
function rowToSummary(row2) {
|
|
18041
18041
|
return {
|
|
18042
|
-
filePath:
|
|
18043
|
-
repoRoot:
|
|
18044
|
-
purpose:
|
|
18045
|
-
exports: JSON.parse(
|
|
18046
|
-
imports: JSON.parse(
|
|
18047
|
-
domain:
|
|
18048
|
-
riskLevel:
|
|
18049
|
-
relatedTests: JSON.parse(
|
|
18050
|
-
notes:
|
|
18051
|
-
createdAt:
|
|
18052
|
-
updatedAt:
|
|
18042
|
+
filePath: row2.file_path,
|
|
18043
|
+
repoRoot: row2.repo_root,
|
|
18044
|
+
purpose: row2.purpose,
|
|
18045
|
+
exports: JSON.parse(row2.exports),
|
|
18046
|
+
imports: JSON.parse(row2.imports),
|
|
18047
|
+
domain: row2.domain,
|
|
18048
|
+
riskLevel: row2.risk_level,
|
|
18049
|
+
relatedTests: JSON.parse(row2.related_tests),
|
|
18050
|
+
notes: row2.notes ?? null,
|
|
18051
|
+
createdAt: row2.created_at,
|
|
18052
|
+
updatedAt: row2.updated_at
|
|
18053
18053
|
};
|
|
18054
18054
|
}
|
|
18055
18055
|
var FileSummaryStore;
|
|
@@ -18082,8 +18082,8 @@ var init_fileSummaryStore = __esm({
|
|
|
18082
18082
|
}
|
|
18083
18083
|
/** Retrieve a file summary by path, or `null` if not found. */
|
|
18084
18084
|
get(filePath) {
|
|
18085
|
-
const
|
|
18086
|
-
return
|
|
18085
|
+
const row2 = this.db.prepare("SELECT * FROM file_summaries WHERE file_path = ?").get(filePath);
|
|
18086
|
+
return row2 ? rowToSummary(row2) : null;
|
|
18087
18087
|
}
|
|
18088
18088
|
/** List all file summaries for a repository. */
|
|
18089
18089
|
listByRepo(repoRoot) {
|
|
@@ -18110,19 +18110,19 @@ var init_fileSummaryStore = __esm({
|
|
|
18110
18110
|
|
|
18111
18111
|
// packages/memory/dist/taskMemoryStore.js
|
|
18112
18112
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
18113
|
-
function rowToTask(
|
|
18113
|
+
function rowToTask(row2) {
|
|
18114
18114
|
return {
|
|
18115
|
-
id:
|
|
18116
|
-
sessionId:
|
|
18117
|
-
repoRoot:
|
|
18118
|
-
goal:
|
|
18119
|
-
constraints: JSON.parse(
|
|
18120
|
-
filesTouched: JSON.parse(
|
|
18121
|
-
patches: JSON.parse(
|
|
18122
|
-
outcome:
|
|
18123
|
-
qualityScore:
|
|
18124
|
-
notes:
|
|
18125
|
-
createdAt:
|
|
18115
|
+
id: row2.id,
|
|
18116
|
+
sessionId: row2.session_id,
|
|
18117
|
+
repoRoot: row2.repo_root,
|
|
18118
|
+
goal: row2.goal,
|
|
18119
|
+
constraints: JSON.parse(row2.constraints),
|
|
18120
|
+
filesTouched: JSON.parse(row2.files_touched),
|
|
18121
|
+
patches: JSON.parse(row2.patches),
|
|
18122
|
+
outcome: row2.outcome,
|
|
18123
|
+
qualityScore: row2.quality_score ?? null,
|
|
18124
|
+
notes: row2.notes ?? null,
|
|
18125
|
+
createdAt: row2.created_at
|
|
18126
18126
|
};
|
|
18127
18127
|
}
|
|
18128
18128
|
var TaskMemoryStore;
|
|
@@ -18148,8 +18148,8 @@ var init_taskMemoryStore = __esm({
|
|
|
18148
18148
|
}
|
|
18149
18149
|
/** Retrieve a task record by id, or `null` if not found. */
|
|
18150
18150
|
getById(id2) {
|
|
18151
|
-
const
|
|
18152
|
-
return
|
|
18151
|
+
const row2 = this.db.prepare("SELECT * FROM task_memory WHERE id = ?").get(id2);
|
|
18152
|
+
return row2 ? rowToTask(row2) : null;
|
|
18153
18153
|
}
|
|
18154
18154
|
/** List all tasks associated with a session. */
|
|
18155
18155
|
listBySession(sessionId) {
|
|
@@ -18180,19 +18180,19 @@ var init_taskMemoryStore = __esm({
|
|
|
18180
18180
|
|
|
18181
18181
|
// packages/memory/dist/patchHistoryStore.js
|
|
18182
18182
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
18183
|
-
function rowToPatch(
|
|
18183
|
+
function rowToPatch(row2) {
|
|
18184
18184
|
return {
|
|
18185
|
-
id:
|
|
18186
|
-
taskId:
|
|
18187
|
-
sessionId:
|
|
18188
|
-
repoRoot:
|
|
18189
|
-
filePath:
|
|
18190
|
-
diff:
|
|
18191
|
-
status:
|
|
18192
|
-
appliedAt:
|
|
18193
|
-
revertedAt:
|
|
18194
|
-
notes:
|
|
18195
|
-
createdAt:
|
|
18185
|
+
id: row2.id,
|
|
18186
|
+
taskId: row2.task_id,
|
|
18187
|
+
sessionId: row2.session_id,
|
|
18188
|
+
repoRoot: row2.repo_root,
|
|
18189
|
+
filePath: row2.file_path,
|
|
18190
|
+
diff: row2.diff,
|
|
18191
|
+
status: row2.status,
|
|
18192
|
+
appliedAt: row2.applied_at ?? null,
|
|
18193
|
+
revertedAt: row2.reverted_at ?? null,
|
|
18194
|
+
notes: row2.notes ?? null,
|
|
18195
|
+
createdAt: row2.created_at
|
|
18196
18196
|
};
|
|
18197
18197
|
}
|
|
18198
18198
|
var PatchHistoryStore;
|
|
@@ -18218,8 +18218,8 @@ var init_patchHistoryStore = __esm({
|
|
|
18218
18218
|
}
|
|
18219
18219
|
/** Retrieve a patch by id, or `null` if not found. */
|
|
18220
18220
|
getById(id2) {
|
|
18221
|
-
const
|
|
18222
|
-
return
|
|
18221
|
+
const row2 = this.db.prepare("SELECT * FROM patch_history WHERE id = ?").get(id2);
|
|
18222
|
+
return row2 ? rowToPatch(row2) : null;
|
|
18223
18223
|
}
|
|
18224
18224
|
/** List all patches associated with a task. */
|
|
18225
18225
|
listByTask(taskId) {
|
|
@@ -18255,21 +18255,21 @@ var init_patchHistoryStore = __esm({
|
|
|
18255
18255
|
|
|
18256
18256
|
// packages/memory/dist/failureStore.js
|
|
18257
18257
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
18258
|
-
function rowToFailure(
|
|
18258
|
+
function rowToFailure(row2) {
|
|
18259
18259
|
return {
|
|
18260
|
-
id:
|
|
18261
|
-
taskId:
|
|
18262
|
-
sessionId:
|
|
18263
|
-
repoRoot:
|
|
18264
|
-
failureType:
|
|
18265
|
-
fingerprint:
|
|
18266
|
-
filePath:
|
|
18267
|
-
errorMessage:
|
|
18268
|
-
context:
|
|
18269
|
-
resolved:
|
|
18270
|
-
resolvedAt:
|
|
18271
|
-
notes:
|
|
18272
|
-
createdAt:
|
|
18260
|
+
id: row2.id,
|
|
18261
|
+
taskId: row2.task_id,
|
|
18262
|
+
sessionId: row2.session_id,
|
|
18263
|
+
repoRoot: row2.repo_root,
|
|
18264
|
+
failureType: row2.failure_type,
|
|
18265
|
+
fingerprint: row2.fingerprint,
|
|
18266
|
+
filePath: row2.file_path ?? null,
|
|
18267
|
+
errorMessage: row2.error_message,
|
|
18268
|
+
context: row2.context !== null ? JSON.parse(row2.context) : null,
|
|
18269
|
+
resolved: row2.resolved === 1,
|
|
18270
|
+
resolvedAt: row2.resolved_at ?? null,
|
|
18271
|
+
notes: row2.notes ?? null,
|
|
18272
|
+
createdAt: row2.created_at
|
|
18273
18273
|
};
|
|
18274
18274
|
}
|
|
18275
18275
|
var FailureStore;
|
|
@@ -18296,8 +18296,8 @@ var init_failureStore = __esm({
|
|
|
18296
18296
|
}
|
|
18297
18297
|
/** Retrieve a failure by id, or `null` if not found. */
|
|
18298
18298
|
getById(id2) {
|
|
18299
|
-
const
|
|
18300
|
-
return
|
|
18299
|
+
const row2 = this.db.prepare("SELECT * FROM failures WHERE id = ?").get(id2);
|
|
18300
|
+
return row2 ? rowToFailure(row2) : null;
|
|
18301
18301
|
}
|
|
18302
18302
|
/** List failures filtered by type. */
|
|
18303
18303
|
listByType(failureType) {
|
|
@@ -18331,21 +18331,21 @@ var init_failureStore = __esm({
|
|
|
18331
18331
|
|
|
18332
18332
|
// packages/memory/dist/validationStore.js
|
|
18333
18333
|
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
18334
|
-
function rowToRun(
|
|
18334
|
+
function rowToRun(row2) {
|
|
18335
18335
|
return {
|
|
18336
|
-
id:
|
|
18337
|
-
taskId:
|
|
18338
|
-
sessionId:
|
|
18339
|
-
repoRoot:
|
|
18340
|
-
runType:
|
|
18341
|
-
command:
|
|
18342
|
-
passed:
|
|
18343
|
-
durationMs:
|
|
18344
|
-
output:
|
|
18345
|
-
errorOutput:
|
|
18346
|
-
coveragePercent:
|
|
18347
|
-
notes:
|
|
18348
|
-
createdAt:
|
|
18336
|
+
id: row2.id,
|
|
18337
|
+
taskId: row2.task_id,
|
|
18338
|
+
sessionId: row2.session_id,
|
|
18339
|
+
repoRoot: row2.repo_root,
|
|
18340
|
+
runType: row2.run_type,
|
|
18341
|
+
command: row2.command,
|
|
18342
|
+
passed: row2.passed === 1,
|
|
18343
|
+
durationMs: row2.duration_ms ?? null,
|
|
18344
|
+
output: row2.output ?? null,
|
|
18345
|
+
errorOutput: row2.error_output ?? null,
|
|
18346
|
+
coveragePercent: row2.coverage_percent ?? null,
|
|
18347
|
+
notes: row2.notes ?? null,
|
|
18348
|
+
createdAt: row2.created_at
|
|
18349
18349
|
};
|
|
18350
18350
|
}
|
|
18351
18351
|
var ValidationStore;
|
|
@@ -18372,8 +18372,8 @@ var init_validationStore = __esm({
|
|
|
18372
18372
|
}
|
|
18373
18373
|
/** Retrieve a validation run by id, or `null` if not found. */
|
|
18374
18374
|
getById(id2) {
|
|
18375
|
-
const
|
|
18376
|
-
return
|
|
18375
|
+
const row2 = this.db.prepare("SELECT * FROM validation_runs WHERE id = ?").get(id2);
|
|
18376
|
+
return row2 ? rowToRun(row2) : null;
|
|
18377
18377
|
}
|
|
18378
18378
|
/** List all validation runs for a given task. */
|
|
18379
18379
|
listByTask(taskId) {
|
|
@@ -18398,11 +18398,11 @@ var init_validationStore = __esm({
|
|
|
18398
18398
|
* (common in tests) are ordered deterministically by insertion order.
|
|
18399
18399
|
*/
|
|
18400
18400
|
latestByTask(taskId) {
|
|
18401
|
-
const
|
|
18401
|
+
const row2 = this.db.prepare(`SELECT * FROM validation_runs
|
|
18402
18402
|
WHERE task_id = ?
|
|
18403
18403
|
ORDER BY created_at DESC, rowid DESC
|
|
18404
18404
|
LIMIT 1`).get(taskId);
|
|
18405
|
-
return
|
|
18405
|
+
return row2 ? rowToRun(row2) : null;
|
|
18406
18406
|
}
|
|
18407
18407
|
};
|
|
18408
18408
|
}
|
|
@@ -18577,14 +18577,14 @@ var init_toolPatternStore = __esm({
|
|
|
18577
18577
|
}));
|
|
18578
18578
|
}
|
|
18579
18579
|
// -- Helpers -------------------------------------------------------------
|
|
18580
|
-
hydrate(
|
|
18580
|
+
hydrate(row2) {
|
|
18581
18581
|
return {
|
|
18582
|
-
id:
|
|
18583
|
-
taskId:
|
|
18584
|
-
sessionId:
|
|
18585
|
-
repoRoot:
|
|
18586
|
-
sequence: JSON.parse(
|
|
18587
|
-
createdAt:
|
|
18582
|
+
id: row2["id"],
|
|
18583
|
+
taskId: row2["task_id"],
|
|
18584
|
+
sessionId: row2["session_id"],
|
|
18585
|
+
repoRoot: row2["repo_root"],
|
|
18586
|
+
sequence: JSON.parse(row2["sequence"] || "[]"),
|
|
18587
|
+
createdAt: row2["created_at"]
|
|
18588
18588
|
};
|
|
18589
18589
|
}
|
|
18590
18590
|
};
|
|
@@ -19418,8 +19418,8 @@ var init_episodeStore = __esm({
|
|
|
19418
19418
|
const result = this.db.prepare(`UPDATE episodes SET reuse_count = COALESCE(reuse_count, 0) + ? WHERE id = ?`).run(safeDelta, id2);
|
|
19419
19419
|
if (result.changes === 0)
|
|
19420
19420
|
return null;
|
|
19421
|
-
const
|
|
19422
|
-
return
|
|
19421
|
+
const row2 = this.db.prepare(`SELECT reuse_count FROM episodes WHERE id = ?`).get(id2);
|
|
19422
|
+
return row2?.reuse_count ?? null;
|
|
19423
19423
|
} catch {
|
|
19424
19424
|
return null;
|
|
19425
19425
|
}
|
|
@@ -19558,10 +19558,10 @@ var init_episodeStore = __esm({
|
|
|
19558
19558
|
params.push(Math.min(limit * 5, 500));
|
|
19559
19559
|
let rows = this.db.prepare(sql).all(...params);
|
|
19560
19560
|
if (query.metadataFilter || query.soundClass || query.rmsRange) {
|
|
19561
|
-
rows = rows.filter((
|
|
19561
|
+
rows = rows.filter((row2) => {
|
|
19562
19562
|
let meta = null;
|
|
19563
19563
|
try {
|
|
19564
|
-
meta =
|
|
19564
|
+
meta = row2.metadata ? typeof row2.metadata === "string" ? JSON.parse(row2.metadata) : row2.metadata : null;
|
|
19565
19565
|
} catch {
|
|
19566
19566
|
return false;
|
|
19567
19567
|
}
|
|
@@ -19587,8 +19587,8 @@ var init_episodeStore = __esm({
|
|
|
19587
19587
|
return true;
|
|
19588
19588
|
});
|
|
19589
19589
|
}
|
|
19590
|
-
const scored = rows.map((
|
|
19591
|
-
const ep = this.rowToEpisode(
|
|
19590
|
+
const scored = rows.map((row2) => {
|
|
19591
|
+
const ep = this.rowToEpisode(row2);
|
|
19592
19592
|
const tau = DECAY_TAU[ep.decayClass] ?? DECAY_TAU.daily;
|
|
19593
19593
|
const recency = tau === Infinity ? 1 : Math.exp(-(now2 - ep.timestamp) / tau);
|
|
19594
19594
|
const importance = ep.importance / 10;
|
|
@@ -19676,8 +19676,8 @@ var init_episodeStore = __esm({
|
|
|
19676
19676
|
}
|
|
19677
19677
|
/** Get a single episode by ID. */
|
|
19678
19678
|
get(id2) {
|
|
19679
|
-
const
|
|
19680
|
-
return
|
|
19679
|
+
const row2 = this.db.prepare("SELECT * FROM episodes WHERE id = ?").get(id2);
|
|
19680
|
+
return row2 ? this.rowToEpisode(row2) : null;
|
|
19681
19681
|
}
|
|
19682
19682
|
/** Get recent episodes (for context assembly). */
|
|
19683
19683
|
recent(limit = 10, sessionId) {
|
|
@@ -19726,30 +19726,30 @@ var init_episodeStore = __esm({
|
|
|
19726
19726
|
}
|
|
19727
19727
|
}
|
|
19728
19728
|
// ─── Internal ────────────────────────────────────────────────────────────
|
|
19729
|
-
rowToEpisode(
|
|
19729
|
+
rowToEpisode(row2) {
|
|
19730
19730
|
return {
|
|
19731
|
-
id:
|
|
19732
|
-
timestamp:
|
|
19733
|
-
sessionId:
|
|
19734
|
-
taskId:
|
|
19735
|
-
turnNumber:
|
|
19736
|
-
modality:
|
|
19737
|
-
toolName:
|
|
19738
|
-
content:
|
|
19739
|
-
contentHash:
|
|
19740
|
-
metadata:
|
|
19741
|
-
embedding:
|
|
19731
|
+
id: row2.id,
|
|
19732
|
+
timestamp: row2.timestamp,
|
|
19733
|
+
sessionId: row2.session_id,
|
|
19734
|
+
taskId: row2.task_id,
|
|
19735
|
+
turnNumber: row2.turn_number,
|
|
19736
|
+
modality: row2.modality,
|
|
19737
|
+
toolName: row2.tool_name,
|
|
19738
|
+
content: row2.content,
|
|
19739
|
+
contentHash: row2.content_hash,
|
|
19740
|
+
metadata: row2.metadata ? JSON.parse(row2.metadata) : null,
|
|
19741
|
+
embedding: row2.embedding ? new Float32Array(new Uint8Array(row2.embedding).buffer) : null,
|
|
19742
19742
|
// Belt-and-braces: rows from pre-fix DBs may have null importance
|
|
19743
19743
|
// (from legacy inserts with NaN that SQLite coerced to NULL).
|
|
19744
19744
|
// Re-sanitize on read so downstream code always sees a valid number.
|
|
19745
|
-
importance: sanitizeImportance(
|
|
19746
|
-
decayClass:
|
|
19747
|
-
strength: typeof
|
|
19748
|
-
lastRetrieved:
|
|
19749
|
-
clipEmbedding:
|
|
19750
|
-
gist:
|
|
19751
|
-
sourceEpisodeId:
|
|
19752
|
-
reuseCount: typeof
|
|
19745
|
+
importance: sanitizeImportance(row2.importance),
|
|
19746
|
+
decayClass: row2.decay_class,
|
|
19747
|
+
strength: typeof row2.strength === "number" && Number.isFinite(row2.strength) ? row2.strength : 1,
|
|
19748
|
+
lastRetrieved: row2.last_retrieved,
|
|
19749
|
+
clipEmbedding: row2.clip_embedding ? new Float32Array(new Uint8Array(row2.clip_embedding).buffer) : null,
|
|
19750
|
+
gist: row2.gist,
|
|
19751
|
+
sourceEpisodeId: row2.source_episode_id,
|
|
19752
|
+
reuseCount: typeof row2.reuse_count === "number" ? row2.reuse_count : 0
|
|
19753
19753
|
};
|
|
19754
19754
|
}
|
|
19755
19755
|
};
|
|
@@ -19848,13 +19848,13 @@ var init_temporalGraph = __esm({
|
|
|
19848
19848
|
/** Find a node by text (case-insensitive). */
|
|
19849
19849
|
findNode(text2, nodeType) {
|
|
19850
19850
|
const sql = nodeType ? "SELECT * FROM kg_nodes WHERE text = ? AND node_type = ? LIMIT 1" : "SELECT * FROM kg_nodes WHERE text = ? LIMIT 1";
|
|
19851
|
-
const
|
|
19852
|
-
return
|
|
19851
|
+
const row2 = nodeType ? this.db.prepare(sql).get(text2, nodeType) : this.db.prepare(sql).get(text2);
|
|
19852
|
+
return row2 ? this.rowToNode(row2) : null;
|
|
19853
19853
|
}
|
|
19854
19854
|
/** Get a node by ID. */
|
|
19855
19855
|
getNode(id2) {
|
|
19856
|
-
const
|
|
19857
|
-
return
|
|
19856
|
+
const row2 = this.db.prepare("SELECT * FROM kg_nodes WHERE id = ?").get(id2);
|
|
19857
|
+
return row2 ? this.rowToNode(row2) : null;
|
|
19858
19858
|
}
|
|
19859
19859
|
/** List all nodes of a given type. */
|
|
19860
19860
|
nodesByType(nodeType, limit = 100) {
|
|
@@ -19993,30 +19993,30 @@ var init_temporalGraph = __esm({
|
|
|
19993
19993
|
}
|
|
19994
19994
|
}
|
|
19995
19995
|
// ─── Internal ────────────────────────────────────────────────────────────
|
|
19996
|
-
rowToNode(
|
|
19996
|
+
rowToNode(row2) {
|
|
19997
19997
|
return {
|
|
19998
|
-
id:
|
|
19999
|
-
text:
|
|
20000
|
-
nodeType:
|
|
20001
|
-
embedding:
|
|
20002
|
-
firstSeen:
|
|
20003
|
-
lastSeen:
|
|
20004
|
-
mentionCount:
|
|
19998
|
+
id: row2.id,
|
|
19999
|
+
text: row2.text,
|
|
20000
|
+
nodeType: row2.node_type,
|
|
20001
|
+
embedding: row2.embedding ? new Float32Array(new Uint8Array(row2.embedding).buffer) : null,
|
|
20002
|
+
firstSeen: row2.first_seen,
|
|
20003
|
+
lastSeen: row2.last_seen,
|
|
20004
|
+
mentionCount: row2.mention_count
|
|
20005
20005
|
};
|
|
20006
20006
|
}
|
|
20007
|
-
rowToEdge(
|
|
20007
|
+
rowToEdge(row2) {
|
|
20008
20008
|
return {
|
|
20009
|
-
id:
|
|
20010
|
-
srcId:
|
|
20011
|
-
dstId:
|
|
20012
|
-
relation:
|
|
20013
|
-
fact:
|
|
20014
|
-
edgeType:
|
|
20015
|
-
validFrom:
|
|
20016
|
-
validUntil:
|
|
20017
|
-
confidence:
|
|
20018
|
-
sourceEpisodeId:
|
|
20019
|
-
modality:
|
|
20009
|
+
id: row2.id,
|
|
20010
|
+
srcId: row2.src_id,
|
|
20011
|
+
dstId: row2.dst_id,
|
|
20012
|
+
relation: row2.relation,
|
|
20013
|
+
fact: row2.fact,
|
|
20014
|
+
edgeType: row2.edge_type,
|
|
20015
|
+
validFrom: row2.valid_from,
|
|
20016
|
+
validUntil: row2.valid_until,
|
|
20017
|
+
confidence: row2.confidence,
|
|
20018
|
+
sourceEpisodeId: row2.source_episode_id,
|
|
20019
|
+
modality: row2.modality
|
|
20020
20020
|
};
|
|
20021
20021
|
}
|
|
20022
20022
|
};
|
|
@@ -20610,10 +20610,10 @@ var init_proceduralMemoryStore = __esm({
|
|
|
20610
20610
|
}
|
|
20611
20611
|
/** Get a memory by ID. Returns null if not found or soft-deleted. */
|
|
20612
20612
|
get(id2) {
|
|
20613
|
-
const
|
|
20613
|
+
const row2 = this.db.prepare(`
|
|
20614
20614
|
SELECT * FROM procedural_memory WHERE id = ? AND deleted_at IS NULL
|
|
20615
20615
|
`).get(id2);
|
|
20616
|
-
return
|
|
20616
|
+
return row2 ? this._mapRow(row2) : null;
|
|
20617
20617
|
}
|
|
20618
20618
|
/** List all active memories, ordered by utility*confidence descending. */
|
|
20619
20619
|
list(limit = 100, offset = 0) {
|
|
@@ -20704,12 +20704,12 @@ var init_proceduralMemoryStore = __esm({
|
|
|
20704
20704
|
WHERE pm.deleted_at IS NULL
|
|
20705
20705
|
`).all();
|
|
20706
20706
|
const results = [];
|
|
20707
|
-
for (const
|
|
20708
|
-
const stored = new Float32Array(
|
|
20707
|
+
for (const row2 of rows) {
|
|
20708
|
+
const stored = new Float32Array(row2.vector.buffer, row2.vector.byteOffset, row2.vector.byteLength / 4);
|
|
20709
20709
|
const sim = cosineSimilarity2(queryVector, stored);
|
|
20710
20710
|
if (sim >= minSimilarity) {
|
|
20711
20711
|
results.push({
|
|
20712
|
-
memory: this._mapRow(
|
|
20712
|
+
memory: this._mapRow(row2),
|
|
20713
20713
|
score: sim,
|
|
20714
20714
|
matchType: "semantic"
|
|
20715
20715
|
});
|
|
@@ -20732,10 +20732,10 @@ var init_proceduralMemoryStore = __esm({
|
|
|
20732
20732
|
}
|
|
20733
20733
|
/** Check if a memory has an embedding. */
|
|
20734
20734
|
hasEmbedding(memoryId) {
|
|
20735
|
-
const
|
|
20735
|
+
const row2 = this.db.prepare(`
|
|
20736
20736
|
SELECT COUNT(*) as cnt FROM memory_embedding WHERE memory_id = ?
|
|
20737
20737
|
`).get(memoryId);
|
|
20738
|
-
return
|
|
20738
|
+
return row2?.cnt > 0;
|
|
20739
20739
|
}
|
|
20740
20740
|
// ── Links ───────────────────────────────────────────────────────────
|
|
20741
20741
|
/** Create a link between two memories. */
|
|
@@ -20804,10 +20804,10 @@ var init_proceduralMemoryStore = __esm({
|
|
|
20804
20804
|
// ── Stats ───────────────────────────────────────────────────────────
|
|
20805
20805
|
/** Count active memories. */
|
|
20806
20806
|
count() {
|
|
20807
|
-
const
|
|
20807
|
+
const row2 = this.db.prepare(`
|
|
20808
20808
|
SELECT COUNT(*) as cnt FROM procedural_memory WHERE deleted_at IS NULL
|
|
20809
20809
|
`).get();
|
|
20810
|
-
return
|
|
20810
|
+
return row2?.cnt ?? 0;
|
|
20811
20811
|
}
|
|
20812
20812
|
/** Migration helper: import from flat JSON metabolism store. */
|
|
20813
20813
|
importFromJson(entries) {
|
|
@@ -20834,21 +20834,21 @@ var init_proceduralMemoryStore = __esm({
|
|
|
20834
20834
|
return imported;
|
|
20835
20835
|
}
|
|
20836
20836
|
// ── Internal ────────────────────────────────────────────────────────
|
|
20837
|
-
_mapRow(
|
|
20837
|
+
_mapRow(row2) {
|
|
20838
20838
|
return {
|
|
20839
|
-
id:
|
|
20840
|
-
type:
|
|
20841
|
-
category:
|
|
20842
|
-
content:
|
|
20843
|
-
triggerPattern:
|
|
20844
|
-
steps:
|
|
20845
|
-
sourceTrace:
|
|
20846
|
-
utility:
|
|
20847
|
-
confidence:
|
|
20848
|
-
accessCount:
|
|
20849
|
-
deletedAt:
|
|
20850
|
-
createdAt:
|
|
20851
|
-
updatedAt:
|
|
20839
|
+
id: row2.id,
|
|
20840
|
+
type: row2.type,
|
|
20841
|
+
category: row2.category,
|
|
20842
|
+
content: row2.content,
|
|
20843
|
+
triggerPattern: row2.trigger_pattern,
|
|
20844
|
+
steps: row2.steps,
|
|
20845
|
+
sourceTrace: row2.source_trace,
|
|
20846
|
+
utility: row2.utility,
|
|
20847
|
+
confidence: row2.confidence,
|
|
20848
|
+
accessCount: row2.access_count,
|
|
20849
|
+
deletedAt: row2.deleted_at,
|
|
20850
|
+
createdAt: row2.created_at,
|
|
20851
|
+
updatedAt: row2.updated_at
|
|
20852
20852
|
};
|
|
20853
20853
|
}
|
|
20854
20854
|
};
|
|
@@ -23247,16 +23247,16 @@ var init_selfModel = __esm({
|
|
|
23247
23247
|
// ── private helpers ────────────────────────────────────────────────────────
|
|
23248
23248
|
scalarCount(sql) {
|
|
23249
23249
|
try {
|
|
23250
|
-
const
|
|
23251
|
-
return
|
|
23250
|
+
const row2 = this.db.prepare(sql).get();
|
|
23251
|
+
return row2?.c ?? 0;
|
|
23252
23252
|
} catch {
|
|
23253
23253
|
return 0;
|
|
23254
23254
|
}
|
|
23255
23255
|
}
|
|
23256
23256
|
tableCount(name10) {
|
|
23257
23257
|
try {
|
|
23258
|
-
const
|
|
23259
|
-
return
|
|
23258
|
+
const row2 = this.db.prepare(`SELECT COUNT(*) AS c FROM ${name10}`).get();
|
|
23259
|
+
return row2?.c ?? 0;
|
|
23260
23260
|
} catch {
|
|
23261
23261
|
return 0;
|
|
23262
23262
|
}
|
|
@@ -23282,8 +23282,8 @@ var init_selfModel = __esm({
|
|
|
23282
23282
|
const critEnd = safe(b.critical, 10) + 1;
|
|
23283
23283
|
const q = (lo, hi) => {
|
|
23284
23284
|
try {
|
|
23285
|
-
const
|
|
23286
|
-
return
|
|
23285
|
+
const row2 = this.db.prepare(`SELECT COUNT(*) AS c FROM episodes WHERE importance >= ? AND importance < ?`).get(lo, hi);
|
|
23286
|
+
return row2?.c ?? 0;
|
|
23287
23287
|
} catch {
|
|
23288
23288
|
return 0;
|
|
23289
23289
|
}
|
|
@@ -23874,16 +23874,16 @@ function lightSleep(db, options2 = {}) {
|
|
|
23874
23874
|
SET content = ?,
|
|
23875
23875
|
metadata = json_patch(COALESCE(metadata, '{}'), json_object('compressedAt', ?))
|
|
23876
23876
|
WHERE id = ?`);
|
|
23877
|
-
for (const
|
|
23878
|
-
const truncated = (
|
|
23879
|
-
const gist = (
|
|
23877
|
+
for (const row2 of rows) {
|
|
23878
|
+
const truncated = (row2.content ?? "").slice(0, gistMaxChars);
|
|
23879
|
+
const gist = (row2.content ?? "").length > gistMaxChars ? truncated + "…" : truncated;
|
|
23880
23880
|
try {
|
|
23881
|
-
updateStmt.run(gist, start2,
|
|
23882
|
-
compressed.push(
|
|
23881
|
+
updateStmt.run(gist, start2, row2.id);
|
|
23882
|
+
compressed.push(row2.id);
|
|
23883
23883
|
} catch {
|
|
23884
23884
|
try {
|
|
23885
|
-
db.prepare(`UPDATE episodes SET content = ? WHERE id = ?`).run(gist,
|
|
23886
|
-
compressed.push(
|
|
23885
|
+
db.prepare(`UPDATE episodes SET content = ? WHERE id = ?`).run(gist, row2.id);
|
|
23886
|
+
compressed.push(row2.id);
|
|
23887
23887
|
} catch {
|
|
23888
23888
|
}
|
|
23889
23889
|
}
|
|
@@ -24000,8 +24000,8 @@ function cosineSim(a2, b) {
|
|
|
24000
24000
|
}
|
|
24001
24001
|
function episodeCount(db) {
|
|
24002
24002
|
try {
|
|
24003
|
-
const
|
|
24004
|
-
return
|
|
24003
|
+
const row2 = db.prepare(`SELECT COUNT(*) AS c FROM episodes`).get();
|
|
24004
|
+
return row2?.c ?? 0;
|
|
24005
24005
|
} catch {
|
|
24006
24006
|
return 0;
|
|
24007
24007
|
}
|
|
@@ -24042,48 +24042,48 @@ function sanitizeBig5(p2) {
|
|
|
24042
24042
|
function pairKey(a2, b) {
|
|
24043
24043
|
return a2 <= b ? { lo: a2, hi: b } : { lo: b, hi: a2 };
|
|
24044
24044
|
}
|
|
24045
|
-
function rowToOpinion(
|
|
24045
|
+
function rowToOpinion(row2) {
|
|
24046
24046
|
return {
|
|
24047
|
-
id:
|
|
24048
|
-
topic:
|
|
24049
|
-
agentId:
|
|
24050
|
-
opinion:
|
|
24051
|
-
confidence:
|
|
24052
|
-
timestamp:
|
|
24047
|
+
id: row2.id,
|
|
24048
|
+
topic: row2.topic,
|
|
24049
|
+
agentId: row2.agent_id,
|
|
24050
|
+
opinion: row2.opinion,
|
|
24051
|
+
confidence: row2.confidence,
|
|
24052
|
+
timestamp: row2.timestamp
|
|
24053
24053
|
};
|
|
24054
24054
|
}
|
|
24055
|
-
function rowToAgent(
|
|
24055
|
+
function rowToAgent(row2) {
|
|
24056
24056
|
return {
|
|
24057
|
-
id:
|
|
24058
|
-
name:
|
|
24059
|
-
type:
|
|
24060
|
-
firstMet:
|
|
24061
|
-
lastInteraction:
|
|
24062
|
-
interactionCount:
|
|
24063
|
-
personality: sanitizeBig5(JSON.parse(
|
|
24064
|
-
trust: JSON.parse(
|
|
24065
|
-
metadata:
|
|
24057
|
+
id: row2.id,
|
|
24058
|
+
name: row2.name,
|
|
24059
|
+
type: row2.type,
|
|
24060
|
+
firstMet: row2.first_met,
|
|
24061
|
+
lastInteraction: row2.last_interaction,
|
|
24062
|
+
interactionCount: row2.interaction_count,
|
|
24063
|
+
personality: sanitizeBig5(JSON.parse(row2.personality)),
|
|
24064
|
+
trust: JSON.parse(row2.trust),
|
|
24065
|
+
metadata: row2.metadata ? JSON.parse(row2.metadata) : null
|
|
24066
24066
|
};
|
|
24067
24067
|
}
|
|
24068
|
-
function rowToRelationship(
|
|
24068
|
+
function rowToRelationship(row2) {
|
|
24069
24069
|
return {
|
|
24070
|
-
agentA:
|
|
24071
|
-
agentB:
|
|
24072
|
-
strength:
|
|
24073
|
-
valence:
|
|
24074
|
-
reciprocity:
|
|
24075
|
-
lastUpdated:
|
|
24076
|
-
history: JSON.parse(
|
|
24070
|
+
agentA: row2.agent_a,
|
|
24071
|
+
agentB: row2.agent_b,
|
|
24072
|
+
strength: row2.strength,
|
|
24073
|
+
valence: row2.valence,
|
|
24074
|
+
reciprocity: row2.reciprocity,
|
|
24075
|
+
lastUpdated: row2.last_updated,
|
|
24076
|
+
history: JSON.parse(row2.history ?? "[]")
|
|
24077
24077
|
};
|
|
24078
24078
|
}
|
|
24079
|
-
function rowToLesson(
|
|
24079
|
+
function rowToLesson(row2) {
|
|
24080
24080
|
return {
|
|
24081
|
-
id:
|
|
24082
|
-
sourceAgent:
|
|
24083
|
-
lesson:
|
|
24084
|
-
confidence:
|
|
24085
|
-
adopted:
|
|
24086
|
-
timestamp:
|
|
24081
|
+
id: row2.id,
|
|
24082
|
+
sourceAgent: row2.source_agent,
|
|
24083
|
+
lesson: row2.lesson,
|
|
24084
|
+
confidence: row2.confidence,
|
|
24085
|
+
adopted: row2.adopted === 1,
|
|
24086
|
+
timestamp: row2.timestamp
|
|
24087
24087
|
};
|
|
24088
24088
|
}
|
|
24089
24089
|
var NEUTRAL_BIG5, SocialMemoryStore;
|
|
@@ -24176,10 +24176,10 @@ var init_socialMemory = __esm({
|
|
|
24176
24176
|
return this.getAgent(id2);
|
|
24177
24177
|
}
|
|
24178
24178
|
getAgent(id2) {
|
|
24179
|
-
const
|
|
24180
|
-
if (!
|
|
24179
|
+
const row2 = this.db.prepare(`SELECT * FROM social_agents WHERE id = ?`).get(id2);
|
|
24180
|
+
if (!row2)
|
|
24181
24181
|
return null;
|
|
24182
|
-
return rowToAgent(
|
|
24182
|
+
return rowToAgent(row2);
|
|
24183
24183
|
}
|
|
24184
24184
|
listAgents() {
|
|
24185
24185
|
const rows = this.db.prepare(`SELECT * FROM social_agents ORDER BY last_interaction DESC`).all();
|
|
@@ -24254,10 +24254,10 @@ var init_socialMemory = __esm({
|
|
|
24254
24254
|
}
|
|
24255
24255
|
getRelationship(agentA, agentB) {
|
|
24256
24256
|
const { lo, hi } = pairKey(agentA, agentB);
|
|
24257
|
-
const
|
|
24258
|
-
if (!
|
|
24257
|
+
const row2 = this.db.prepare(`SELECT * FROM social_relationships WHERE agent_a = ? AND agent_b = ?`).get(lo, hi);
|
|
24258
|
+
if (!row2)
|
|
24259
24259
|
return null;
|
|
24260
|
-
return rowToRelationship(
|
|
24260
|
+
return rowToRelationship(row2);
|
|
24261
24261
|
}
|
|
24262
24262
|
listRelationshipsFor(agent) {
|
|
24263
24263
|
const rows = this.db.prepare(`SELECT * FROM social_relationships WHERE agent_a = ? OR agent_b = ?`).all(agent, agent);
|
|
@@ -24937,10 +24937,10 @@ function ensureSchema(db) {
|
|
|
24937
24937
|
function checkEmbeddingDrift(db, current) {
|
|
24938
24938
|
ensureSchema(db);
|
|
24939
24939
|
try {
|
|
24940
|
-
const
|
|
24941
|
-
if (!
|
|
24940
|
+
const row2 = db.prepare(`SELECT model_name, dim, set_at_ts FROM embedding_meta WHERE id = 1`).get();
|
|
24941
|
+
if (!row2)
|
|
24942
24942
|
return { driftDetected: false };
|
|
24943
|
-
const prev = { model:
|
|
24943
|
+
const prev = { model: row2.model_name, dim: row2.dim, ts: row2.set_at_ts };
|
|
24944
24944
|
const drift = prev.model !== current.model || prev.dim !== current.dim;
|
|
24945
24945
|
return { driftDetected: drift, previous: prev };
|
|
24946
24946
|
} catch {
|
|
@@ -25503,10 +25503,10 @@ function maintainEpisodes(dbPath, options2, shouldStop) {
|
|
|
25503
25503
|
stats.duplicateDeleted = deleteEpisodes(db, duplicateIds.slice(0, options2.maxEpisodeDeletes ?? 1e3), !!options2.dryRun);
|
|
25504
25504
|
const remainingDeleteBudget = Math.max(0, (options2.maxEpisodeDeletes ?? 1e3) - stats.duplicateDeleted);
|
|
25505
25505
|
if (remainingDeleteBudget > 0) {
|
|
25506
|
-
const lowSignalIds = candidates.filter((
|
|
25507
|
-
id:
|
|
25508
|
-
score: memoryUtilityScore(
|
|
25509
|
-
})).filter((
|
|
25506
|
+
const lowSignalIds = candidates.filter((row2) => !duplicateIds.includes(row2.id)).map((row2) => ({
|
|
25507
|
+
id: row2.id,
|
|
25508
|
+
score: memoryUtilityScore(row2, Date.now())
|
|
25509
|
+
})).filter((row2) => row2.score < (options2.minUtilityScore ?? 0.18)).sort((a2, b) => a2.score - b.score).slice(0, remainingDeleteBudget).map((row2) => row2.id);
|
|
25510
25510
|
stats.lowSignalDeleted = deleteEpisodes(db, lowSignalIds, !!options2.dryRun);
|
|
25511
25511
|
}
|
|
25512
25512
|
}
|
|
@@ -25545,9 +25545,9 @@ function loadEpisodeCandidates(db, limit) {
|
|
|
25545
25545
|
}
|
|
25546
25546
|
}
|
|
25547
25547
|
function deleteEpisodes(db, ids, dryRun) {
|
|
25548
|
-
const
|
|
25549
|
-
if (dryRun ||
|
|
25550
|
-
return
|
|
25548
|
+
const unique3 = [...new Set(ids)].filter(Boolean);
|
|
25549
|
+
if (dryRun || unique3.length === 0)
|
|
25550
|
+
return unique3.length;
|
|
25551
25551
|
let deleted = 0;
|
|
25552
25552
|
const stmt = db.prepare(`DELETE FROM episodes WHERE id = ?`);
|
|
25553
25553
|
const tx = db.transaction((rows) => {
|
|
@@ -25556,7 +25556,7 @@ function deleteEpisodes(db, ids, dryRun) {
|
|
|
25556
25556
|
deleted += Number(result.changes ?? 0);
|
|
25557
25557
|
}
|
|
25558
25558
|
});
|
|
25559
|
-
tx(
|
|
25559
|
+
tx(unique3);
|
|
25560
25560
|
return deleted;
|
|
25561
25561
|
}
|
|
25562
25562
|
function maintainGraph(dbPath, options2, shouldStop) {
|
|
@@ -25631,33 +25631,33 @@ function loadGraphNodeCandidates(db, limit) {
|
|
|
25631
25631
|
function vectorDuplicateNodePairs(rows, threshold) {
|
|
25632
25632
|
const pairs = [];
|
|
25633
25633
|
const buckets = /* @__PURE__ */ new Map();
|
|
25634
|
-
for (const
|
|
25635
|
-
const bucketKey =
|
|
25634
|
+
for (const row2 of rows) {
|
|
25635
|
+
const bucketKey = row2.nodeType || "entity";
|
|
25636
25636
|
const bucket = buckets.get(bucketKey) ?? [];
|
|
25637
|
-
const vector = vectorFor(
|
|
25637
|
+
const vector = vectorFor(row2.embedding, row2.text);
|
|
25638
25638
|
let merged = false;
|
|
25639
25639
|
for (let i2 = 0; i2 < bucket.length; i2++) {
|
|
25640
25640
|
const other = bucket[i2];
|
|
25641
25641
|
const otherVector = vectorFor(other.embedding, other.text);
|
|
25642
25642
|
if (cosine2(vector, otherVector) < threshold)
|
|
25643
25643
|
continue;
|
|
25644
|
-
const keep = graphNodeScore(
|
|
25645
|
-
const drop = keep.id ===
|
|
25644
|
+
const keep = graphNodeScore(row2) > graphNodeScore(other) ? row2 : other;
|
|
25645
|
+
const drop = keep.id === row2.id ? other : row2;
|
|
25646
25646
|
pairs.push({ keepId: keep.id, dropId: drop.id });
|
|
25647
|
-
if (keep.id ===
|
|
25648
|
-
bucket[i2] =
|
|
25647
|
+
if (keep.id === row2.id)
|
|
25648
|
+
bucket[i2] = row2;
|
|
25649
25649
|
merged = true;
|
|
25650
25650
|
break;
|
|
25651
25651
|
}
|
|
25652
25652
|
if (!merged)
|
|
25653
|
-
bucket.push(
|
|
25653
|
+
bucket.push(row2);
|
|
25654
25654
|
buckets.set(bucketKey, bucket);
|
|
25655
25655
|
}
|
|
25656
25656
|
return pairs;
|
|
25657
25657
|
}
|
|
25658
25658
|
function mergeGraphNodes(db, pairs, dryRun) {
|
|
25659
25659
|
const seen = /* @__PURE__ */ new Set();
|
|
25660
|
-
const
|
|
25660
|
+
const unique3 = pairs.filter((pair) => {
|
|
25661
25661
|
if (!pair.keepId || !pair.dropId || pair.keepId === pair.dropId)
|
|
25662
25662
|
return false;
|
|
25663
25663
|
if (seen.has(pair.dropId))
|
|
@@ -25665,8 +25665,8 @@ function mergeGraphNodes(db, pairs, dryRun) {
|
|
|
25665
25665
|
seen.add(pair.dropId);
|
|
25666
25666
|
return true;
|
|
25667
25667
|
});
|
|
25668
|
-
if (dryRun ||
|
|
25669
|
-
return
|
|
25668
|
+
if (dryRun || unique3.length === 0)
|
|
25669
|
+
return unique3.length;
|
|
25670
25670
|
let merged = 0;
|
|
25671
25671
|
const tx = db.transaction((rows) => {
|
|
25672
25672
|
const src2 = db.prepare(`UPDATE kg_edges SET src_id = ? WHERE src_id = ?`);
|
|
@@ -25684,7 +25684,7 @@ function mergeGraphNodes(db, pairs, dryRun) {
|
|
|
25684
25684
|
merged += Number(deleted.changes ?? 0);
|
|
25685
25685
|
}
|
|
25686
25686
|
});
|
|
25687
|
-
tx(
|
|
25687
|
+
tx(unique3);
|
|
25688
25688
|
return merged;
|
|
25689
25689
|
}
|
|
25690
25690
|
function dedupeGraphEdges(db, limit, dryRun) {
|
|
@@ -25699,7 +25699,7 @@ function dedupeGraphEdges(db, limit, dryRun) {
|
|
|
25699
25699
|
FROM kg_edges
|
|
25700
25700
|
)
|
|
25701
25701
|
WHERE rn > 1
|
|
25702
|
-
LIMIT ?`).all(Math.max(1, limit)).map((
|
|
25702
|
+
LIMIT ?`).all(Math.max(1, limit)).map((row2) => row2.id);
|
|
25703
25703
|
} catch {
|
|
25704
25704
|
return 0;
|
|
25705
25705
|
}
|
|
@@ -25717,7 +25717,7 @@ function pruneInactiveEdges(db, limit, dryRun) {
|
|
|
25717
25717
|
AND valid_until < ?
|
|
25718
25718
|
AND COALESCE(confidence, 1) < 0.55
|
|
25719
25719
|
ORDER BY valid_until ASC
|
|
25720
|
-
LIMIT ?`).all(cutoff, Math.max(1, limit)).map((
|
|
25720
|
+
LIMIT ?`).all(cutoff, Math.max(1, limit)).map((row2) => row2.id);
|
|
25721
25721
|
} catch {
|
|
25722
25722
|
return 0;
|
|
25723
25723
|
}
|
|
@@ -25735,7 +25735,7 @@ function pruneOrphanNodes(db, limit, dryRun) {
|
|
|
25735
25735
|
AND COALESCE(n.last_seen, 0) < ?
|
|
25736
25736
|
AND NOT EXISTS (SELECT 1 FROM kg_edges e WHERE e.src_id = n.id OR e.dst_id = n.id)
|
|
25737
25737
|
ORDER BY n.last_seen ASC
|
|
25738
|
-
LIMIT ?`).all(cutoff, Math.max(1, limit)).map((
|
|
25738
|
+
LIMIT ?`).all(cutoff, Math.max(1, limit)).map((row2) => row2.id);
|
|
25739
25739
|
} catch {
|
|
25740
25740
|
return 0;
|
|
25741
25741
|
}
|
|
@@ -25745,8 +25745,8 @@ function pruneOrphanNodes(db, limit, dryRun) {
|
|
|
25745
25745
|
}
|
|
25746
25746
|
function countNodes(db) {
|
|
25747
25747
|
try {
|
|
25748
|
-
const
|
|
25749
|
-
return Number(
|
|
25748
|
+
const row2 = db.prepare("SELECT COUNT(*) AS n FROM kg_nodes").get();
|
|
25749
|
+
return Number(row2?.n ?? 0);
|
|
25750
25750
|
} catch {
|
|
25751
25751
|
return 0;
|
|
25752
25752
|
}
|
|
@@ -25779,27 +25779,27 @@ function selectCapEvictionCandidates(db, options2, withText) {
|
|
|
25779
25779
|
LIMIT ?`).all(protectCut, shortlistLimit);
|
|
25780
25780
|
const degStmt = db.prepare("SELECT COUNT(*) AS d FROM kg_edges WHERE src_id = ? OR dst_id = ?");
|
|
25781
25781
|
const scored = [];
|
|
25782
|
-
for (const
|
|
25783
|
-
if (protect.has(
|
|
25782
|
+
for (const row2 of shortlist) {
|
|
25783
|
+
if (protect.has(row2.id))
|
|
25784
25784
|
continue;
|
|
25785
25785
|
let deg = 0;
|
|
25786
25786
|
try {
|
|
25787
|
-
deg = Number(degStmt.get(
|
|
25787
|
+
deg = Number(degStmt.get(row2.id, row2.id)?.d ?? 0);
|
|
25788
25788
|
} catch {
|
|
25789
25789
|
deg = 0;
|
|
25790
25790
|
}
|
|
25791
25791
|
if (deg >= hubDegreeGuard)
|
|
25792
25792
|
continue;
|
|
25793
|
-
const ageMs = Math.max(0, now2 -
|
|
25793
|
+
const ageMs = Math.max(0, now2 - row2.ls);
|
|
25794
25794
|
const recency = Math.exp(-ageMs / (30 * DAY));
|
|
25795
|
-
const utility = Math.log1p(
|
|
25795
|
+
const utility = Math.log1p(row2.mc) * 0.5 + Math.min(deg, 8) / 8 * 0.3 + recency * 0.2;
|
|
25796
25796
|
scored.push({
|
|
25797
|
-
id:
|
|
25798
|
-
text:
|
|
25799
|
-
nodeType:
|
|
25800
|
-
mentionCount:
|
|
25797
|
+
id: row2.id,
|
|
25798
|
+
text: row2.text,
|
|
25799
|
+
nodeType: row2.nodeType,
|
|
25800
|
+
mentionCount: row2.mc,
|
|
25801
25801
|
degree: deg,
|
|
25802
|
-
lastSeen:
|
|
25802
|
+
lastSeen: row2.ls,
|
|
25803
25803
|
score: utility
|
|
25804
25804
|
});
|
|
25805
25805
|
}
|
|
@@ -25920,43 +25920,43 @@ function deleteById(db, table, ids) {
|
|
|
25920
25920
|
function vectorDuplicateIds(rows, threshold) {
|
|
25921
25921
|
const duplicateIds = [];
|
|
25922
25922
|
const buckets = /* @__PURE__ */ new Map();
|
|
25923
|
-
for (const
|
|
25924
|
-
const key = `${
|
|
25923
|
+
for (const row2 of rows) {
|
|
25924
|
+
const key = `${row2.toolName}\0${row2.modality}`;
|
|
25925
25925
|
const bucket = buckets.get(key) ?? [];
|
|
25926
|
-
const vector = vectorFor(
|
|
25926
|
+
const vector = vectorFor(row2.embedding, row2.content);
|
|
25927
25927
|
let absorbed = false;
|
|
25928
25928
|
for (let i2 = 0; i2 < bucket.length; i2++) {
|
|
25929
25929
|
const other = bucket[i2];
|
|
25930
25930
|
const otherVector = vectorFor(other.embedding, other.content);
|
|
25931
25931
|
if (cosine2(vector, otherVector) < threshold)
|
|
25932
25932
|
continue;
|
|
25933
|
-
const keep = memoryUtilityScore(
|
|
25934
|
-
const drop = keep.id ===
|
|
25933
|
+
const keep = memoryUtilityScore(row2, Date.now()) > memoryUtilityScore(other, Date.now()) ? row2 : other;
|
|
25934
|
+
const drop = keep.id === row2.id ? other : row2;
|
|
25935
25935
|
duplicateIds.push(drop.id);
|
|
25936
|
-
if (keep.id ===
|
|
25937
|
-
bucket[i2] =
|
|
25936
|
+
if (keep.id === row2.id)
|
|
25937
|
+
bucket[i2] = row2;
|
|
25938
25938
|
absorbed = true;
|
|
25939
25939
|
break;
|
|
25940
25940
|
}
|
|
25941
25941
|
if (!absorbed)
|
|
25942
|
-
bucket.push(
|
|
25942
|
+
bucket.push(row2);
|
|
25943
25943
|
buckets.set(key, bucket);
|
|
25944
25944
|
}
|
|
25945
25945
|
return [...new Set(duplicateIds)];
|
|
25946
25946
|
}
|
|
25947
|
-
function memoryUtilityScore(
|
|
25948
|
-
const tau = DECAY_TAU2[
|
|
25949
|
-
const retention = tau === Number.POSITIVE_INFINITY ? 1 : Math.exp(-Math.max(0, now2 -
|
|
25950
|
-
const importance = clamp018(
|
|
25951
|
-
const strength = clamp018(Math.log2(Math.max(1,
|
|
25952
|
-
const reuse = clamp018(Math.log1p(Math.max(0,
|
|
25953
|
-
const recentUse = now2 -
|
|
25947
|
+
function memoryUtilityScore(row2, now2) {
|
|
25948
|
+
const tau = DECAY_TAU2[row2.decayClass] ?? DECAY_TAU2.daily;
|
|
25949
|
+
const retention = tau === Number.POSITIVE_INFINITY ? 1 : Math.exp(-Math.max(0, now2 - row2.lastAccessed) / tau);
|
|
25950
|
+
const importance = clamp018(row2.importance / 10);
|
|
25951
|
+
const strength = clamp018(Math.log2(Math.max(1, row2.strength)) / 4);
|
|
25952
|
+
const reuse = clamp018(Math.log1p(Math.max(0, row2.reuseCount)) / Math.log(9));
|
|
25953
|
+
const recentUse = now2 - row2.lastAccessed <= 6 * HOUR ? 1 : 0;
|
|
25954
25954
|
return importance * 0.42 + retention * 0.22 + strength * 0.16 + reuse * 0.16 + recentUse * 0.04;
|
|
25955
25955
|
}
|
|
25956
|
-
function graphNodeScore(
|
|
25957
|
-
const age = Math.max(0, Date.now() -
|
|
25956
|
+
function graphNodeScore(row2) {
|
|
25957
|
+
const age = Math.max(0, Date.now() - row2.lastSeen);
|
|
25958
25958
|
const recency = Math.exp(-age / (30 * DAY));
|
|
25959
|
-
return Math.log1p(Math.max(0,
|
|
25959
|
+
return Math.log1p(Math.max(0, row2.mentionCount)) * 0.7 + recency * 0.3;
|
|
25960
25960
|
}
|
|
25961
25961
|
function vectorFor(rawEmbedding, text2) {
|
|
25962
25962
|
const decoded = decodeEmbedding(rawEmbedding);
|
|
@@ -44758,8 +44758,8 @@ function jsonToCSV(data, separator = ",") {
|
|
|
44758
44758
|
};
|
|
44759
44759
|
const lines = [
|
|
44760
44760
|
headers.map((h) => esc(h)).join(separator),
|
|
44761
|
-
...data.map((
|
|
44762
|
-
const obj =
|
|
44761
|
+
...data.map((row2) => {
|
|
44762
|
+
const obj = row2;
|
|
44763
44763
|
return headers.map((h) => esc(obj[h])).join(separator);
|
|
44764
44764
|
})
|
|
44765
44765
|
];
|
|
@@ -44771,8 +44771,8 @@ function jsonToMarkdownTable(data) {
|
|
|
44771
44771
|
const headers = Object.keys(data[0]);
|
|
44772
44772
|
const headerRow = `| ${headers.join(" | ")} |`;
|
|
44773
44773
|
const sepRow = `| ${headers.map(() => "---").join(" | ")} |`;
|
|
44774
|
-
const dataRows = data.map((
|
|
44775
|
-
const obj =
|
|
44774
|
+
const dataRows = data.map((row2) => {
|
|
44775
|
+
const obj = row2;
|
|
44776
44776
|
return `| ${headers.map((h) => String(obj[h] ?? "")).join(" | ")} |`;
|
|
44777
44777
|
});
|
|
44778
44778
|
return [headerRow, sepRow, ...dataRows].join("\n") + "\n";
|
|
@@ -47485,12 +47485,12 @@ var init_identity2 = __esm({
|
|
|
47485
47485
|
function from2({ name: name10, code: code8, encode: encode15, minDigestLength, maxDigestLength }) {
|
|
47486
47486
|
return new Hasher(name10, code8, encode15, minDigestLength, maxDigestLength);
|
|
47487
47487
|
}
|
|
47488
|
-
function createDigest(digest3, code8,
|
|
47489
|
-
if (
|
|
47490
|
-
if (
|
|
47488
|
+
function createDigest(digest3, code8, truncate5) {
|
|
47489
|
+
if (truncate5 != null && truncate5 !== digest3.byteLength) {
|
|
47490
|
+
if (truncate5 > digest3.byteLength) {
|
|
47491
47491
|
throw new Error(`Invalid truncate option, must be less than or equal to ${digest3.byteLength}`);
|
|
47492
47492
|
}
|
|
47493
|
-
digest3 = digest3.subarray(0,
|
|
47493
|
+
digest3 = digest3.subarray(0, truncate5);
|
|
47494
47494
|
}
|
|
47495
47495
|
return create(code8, digest3);
|
|
47496
47496
|
}
|
|
@@ -80435,7 +80435,7 @@ var require_truncate = __commonJS({
|
|
|
80435
80435
|
function isLowSurrogate(codePoint) {
|
|
80436
80436
|
return codePoint >= 56320 && codePoint <= 57343;
|
|
80437
80437
|
}
|
|
80438
|
-
module.exports = function
|
|
80438
|
+
module.exports = function truncate5(getLength, string2, byteLength) {
|
|
80439
80439
|
if (typeof string2 !== "string") {
|
|
80440
80440
|
throw new Error("Input must be string");
|
|
80441
80441
|
}
|
|
@@ -80466,9 +80466,9 @@ var require_truncate = __commonJS({
|
|
|
80466
80466
|
var require_truncate_utf8_bytes = __commonJS({
|
|
80467
80467
|
"../node_modules/truncate-utf8-bytes/index.js"(exports, module) {
|
|
80468
80468
|
"use strict";
|
|
80469
|
-
var
|
|
80469
|
+
var truncate5 = require_truncate();
|
|
80470
80470
|
var getLength = Buffer.byteLength.bind(Buffer);
|
|
80471
|
-
module.exports =
|
|
80471
|
+
module.exports = truncate5.bind(null, getLength);
|
|
80472
80472
|
}
|
|
80473
80473
|
});
|
|
80474
80474
|
|
|
@@ -80476,7 +80476,7 @@ var require_truncate_utf8_bytes = __commonJS({
|
|
|
80476
80476
|
var require_sanitize_filename = __commonJS({
|
|
80477
80477
|
"../node_modules/sanitize-filename/index.js"(exports, module) {
|
|
80478
80478
|
"use strict";
|
|
80479
|
-
var
|
|
80479
|
+
var truncate5 = require_truncate_utf8_bytes();
|
|
80480
80480
|
var illegalRe = /[\/\?<>\\:\*\|"]/g;
|
|
80481
80481
|
var controlRe = /[\x00-\x1f\x80-\x9f]/g;
|
|
80482
80482
|
var reservedRe = /^\.+$/;
|
|
@@ -80492,7 +80492,7 @@ var require_sanitize_filename = __commonJS({
|
|
|
80492
80492
|
}
|
|
80493
80493
|
var sanitized = input.replace(illegalRe, replacement).replace(controlRe, replacement).replace(reservedRe, replacement).replace(windowsReservedRe, replacement);
|
|
80494
80494
|
sanitized = replaceTrailingDotsAndSpaces(sanitized, replacement);
|
|
80495
|
-
return
|
|
80495
|
+
return truncate5(sanitized, 255);
|
|
80496
80496
|
}
|
|
80497
80497
|
module.exports = function(input, options2) {
|
|
80498
80498
|
var replacement = options2 && options2.replacement || "";
|
|
@@ -100071,15 +100071,15 @@ var require_x509_cjs = __commonJS({
|
|
|
100071
100071
|
const view = pvtsutils.BufferSourceConverter.toUint8Array(buffer2);
|
|
100072
100072
|
const res = [];
|
|
100073
100073
|
for (let i2 = 0; i2 < view.length; ) {
|
|
100074
|
-
const
|
|
100074
|
+
const row2 = [];
|
|
100075
100075
|
for (let j = 0; j < 16 && i2 < view.length; j++) {
|
|
100076
100076
|
if (j === 8) {
|
|
100077
|
-
|
|
100077
|
+
row2.push("");
|
|
100078
100078
|
}
|
|
100079
100079
|
const hex = view[i2++].toString(16).padStart(2, "0");
|
|
100080
|
-
|
|
100080
|
+
row2.push(hex);
|
|
100081
100081
|
}
|
|
100082
|
-
res.push(`${pad}${
|
|
100082
|
+
res.push(`${pad}${row2.join(" ")}`);
|
|
100083
100083
|
}
|
|
100084
100084
|
return res;
|
|
100085
100085
|
}
|
|
@@ -289969,11 +289969,11 @@ function parseCSV(text2, separator = ",") {
|
|
|
289969
289969
|
const rows = [];
|
|
289970
289970
|
for (let i2 = 1; i2 < lines.length; i2++) {
|
|
289971
289971
|
const values = parseLine(lines[i2]);
|
|
289972
|
-
const
|
|
289972
|
+
const row2 = {};
|
|
289973
289973
|
for (let j = 0; j < headers.length; j++) {
|
|
289974
|
-
|
|
289974
|
+
row2[headers[j]] = (values[j] ?? "").trim();
|
|
289975
289975
|
}
|
|
289976
|
-
rows.push(
|
|
289976
|
+
rows.push(row2);
|
|
289977
289977
|
}
|
|
289978
289978
|
return rows;
|
|
289979
289979
|
}
|
|
@@ -290004,11 +290004,11 @@ function parseMarkdownTables(text2) {
|
|
|
290004
290004
|
if (!dataLine.startsWith("|") || !dataLine.endsWith("|"))
|
|
290005
290005
|
break;
|
|
290006
290006
|
const values = dataLine.split("|").filter((c9) => c9.trim() !== "").map((c9) => c9.trim());
|
|
290007
|
-
const
|
|
290007
|
+
const row2 = {};
|
|
290008
290008
|
for (let j = 0; j < headers.length; j++) {
|
|
290009
|
-
|
|
290009
|
+
row2[headers[j]] = values[j] ?? "";
|
|
290010
290010
|
}
|
|
290011
|
-
rows.push(
|
|
290011
|
+
rows.push(row2);
|
|
290012
290012
|
i2++;
|
|
290013
290013
|
}
|
|
290014
290014
|
if (rows.length > 0) {
|
|
@@ -293696,9 +293696,9 @@ Run autoresearch(action="setup") to begin.`,
|
|
|
293696
293696
|
} catch {
|
|
293697
293697
|
}
|
|
293698
293698
|
}
|
|
293699
|
-
const
|
|
293699
|
+
const row2 = `${commitHash} ${valBpb.toFixed(6)} ${memGb.toFixed(1)} keep ${desc}
|
|
293700
293700
|
`;
|
|
293701
|
-
appendFileSync3(tsvPath,
|
|
293701
|
+
appendFileSync3(tsvPath, row2, "utf-8");
|
|
293702
293702
|
return {
|
|
293703
293703
|
success: true,
|
|
293704
293704
|
output: `Kept: ${commitHash} | val_bpb=${valBpb.toFixed(6)} | ${memGb.toFixed(1)}GB | ${desc}
|
|
@@ -293729,9 +293729,9 @@ Branch advanced. Ready for next experiment.`,
|
|
|
293729
293729
|
commitHash = execSync21("git rev-parse --short HEAD", { cwd: workspace, encoding: "utf-8", timeout: 5e3 }).trim();
|
|
293730
293730
|
} catch {
|
|
293731
293731
|
}
|
|
293732
|
-
const
|
|
293732
|
+
const row2 = `${commitHash} ${valBpb.toFixed(6)} ${memGb.toFixed(1)} discard ${desc}
|
|
293733
293733
|
`;
|
|
293734
|
-
appendFileSync3(tsvPath,
|
|
293734
|
+
appendFileSync3(tsvPath, row2, "utf-8");
|
|
293735
293735
|
try {
|
|
293736
293736
|
execSync21("git checkout -- train.py", { cwd: workspace, encoding: "utf-8", timeout: 5e3 });
|
|
293737
293737
|
} catch {
|
|
@@ -446532,8 +446532,8 @@ ${lanes.join("\n")}
|
|
|
446532
446532
|
const headerPadding = Math.max(numberLength(maxErrors) - leftColumnHeadingLength, 0);
|
|
446533
446533
|
let tabularData = "";
|
|
446534
446534
|
tabularData += " ".repeat(headerPadding) + headerRow + "\n";
|
|
446535
|
-
fileToErrorCount.forEach((
|
|
446536
|
-
const [file, errorCount] =
|
|
446535
|
+
fileToErrorCount.forEach((row2) => {
|
|
446536
|
+
const [file, errorCount] = row2;
|
|
446537
446537
|
const errorCountDigitsLength = Math.log(errorCount) * Math.LOG10E + 1 | 0;
|
|
446538
446538
|
const leftPadding = errorCountDigitsLength < leftPaddingGoal ? " ".repeat(leftPaddingGoal - errorCountDigitsLength) : "";
|
|
446539
446539
|
const fileRef = prettyPathForFileError(file, host.getCurrentDirectory());
|
|
@@ -497694,9 +497694,9 @@ ${options2.prefix}` : "\n" : options2.prefix
|
|
|
497694
497694
|
}
|
|
497695
497695
|
return map22;
|
|
497696
497696
|
}
|
|
497697
|
-
function getRuleBucketIndex(
|
|
497698
|
-
Debug.assert(
|
|
497699
|
-
return
|
|
497697
|
+
function getRuleBucketIndex(row2, column) {
|
|
497698
|
+
Debug.assert(row2 <= 166 && column <= 166, "Must compute formatting context from tokens");
|
|
497699
|
+
return row2 * mapRowLength + column;
|
|
497700
497700
|
}
|
|
497701
497701
|
var maskBitSize = 5;
|
|
497702
497702
|
var mask = 31;
|
|
@@ -503283,11 +503283,11 @@ ${options2.prefix}` : "\n" : options2.prefix
|
|
|
503283
503283
|
return true;
|
|
503284
503284
|
}
|
|
503285
503285
|
const set = /* @__PURE__ */ new Map();
|
|
503286
|
-
let
|
|
503286
|
+
let unique3 = 0;
|
|
503287
503287
|
for (const v of arr1) {
|
|
503288
503288
|
if (set.get(v) !== true) {
|
|
503289
503289
|
set.set(v, true);
|
|
503290
|
-
|
|
503290
|
+
unique3++;
|
|
503291
503291
|
}
|
|
503292
503292
|
}
|
|
503293
503293
|
for (const v of arr2) {
|
|
@@ -503297,10 +503297,10 @@ ${options2.prefix}` : "\n" : options2.prefix
|
|
|
503297
503297
|
}
|
|
503298
503298
|
if (isSet === true) {
|
|
503299
503299
|
set.set(v, false);
|
|
503300
|
-
|
|
503300
|
+
unique3--;
|
|
503301
503301
|
}
|
|
503302
503302
|
}
|
|
503303
|
-
return
|
|
503303
|
+
return unique3 === 0;
|
|
503304
503304
|
}
|
|
503305
503305
|
function typeAcquisitionChanged(opt1, opt2) {
|
|
503306
503306
|
return opt1.enable !== opt2.enable || !setIsEqualTo(opt1.include, opt2.include) || !setIsEqualTo(opt1.exclude, opt2.exclude);
|
|
@@ -545424,17 +545424,17 @@ var init_code_graph_db = __esm({
|
|
|
545424
545424
|
* single source of truth for column→field translation; if the schema
|
|
545425
545425
|
* gains/renames a column, only this method needs updating.
|
|
545426
545426
|
*/
|
|
545427
|
-
rowToSymbol(
|
|
545427
|
+
rowToSymbol(row2) {
|
|
545428
545428
|
return {
|
|
545429
|
-
id:
|
|
545430
|
-
filePath:
|
|
545431
|
-
name:
|
|
545432
|
-
kind:
|
|
545433
|
-
startLine:
|
|
545434
|
-
endLine:
|
|
545435
|
-
signature:
|
|
545436
|
-
docstring:
|
|
545437
|
-
exported: !!
|
|
545429
|
+
id: row2.id,
|
|
545430
|
+
filePath: row2.file_path,
|
|
545431
|
+
name: row2.name,
|
|
545432
|
+
kind: row2.kind,
|
|
545433
|
+
startLine: row2.start_line ?? 0,
|
|
545434
|
+
endLine: row2.end_line ?? 0,
|
|
545435
|
+
signature: row2.signature ?? "",
|
|
545436
|
+
docstring: row2.docstring ?? "",
|
|
545437
|
+
exported: !!row2.exported
|
|
545438
545438
|
};
|
|
545439
545439
|
}
|
|
545440
545440
|
/** Get all symbols for a file. */
|
|
@@ -545559,16 +545559,16 @@ var init_code_graph_db = __esm({
|
|
|
545559
545559
|
}
|
|
545560
545560
|
/** Get graph statistics. */
|
|
545561
545561
|
getStats() {
|
|
545562
|
-
const
|
|
545562
|
+
const row2 = this.stmts.getStats.get();
|
|
545563
545563
|
return {
|
|
545564
|
-
...
|
|
545564
|
+
...row2,
|
|
545565
545565
|
lastFullIndex: this.db.prepare(`SELECT MAX(last_indexed) as t FROM files`).get()?.t ?? null
|
|
545566
545566
|
};
|
|
545567
545567
|
}
|
|
545568
545568
|
/** Get the stored hash for a file (for change detection). */
|
|
545569
545569
|
getFileHash(relPath) {
|
|
545570
|
-
const
|
|
545571
|
-
return
|
|
545570
|
+
const row2 = this.stmts.getFile.get(relPath);
|
|
545571
|
+
return row2?.hash ?? null;
|
|
545572
545572
|
}
|
|
545573
545573
|
/** Compact query: top-N files by import count (pseudo-PageRank). */
|
|
545574
545574
|
getTopFiles(limit = 20) {
|
|
@@ -567353,32 +567353,32 @@ async function scanOllamaProcesses(options2 = {}) {
|
|
|
567353
567353
|
readGpuMemoryByPid(system)
|
|
567354
567354
|
]);
|
|
567355
567355
|
const snapshots = [];
|
|
567356
|
-
for (const
|
|
567357
|
-
const serve = isOllamaServeCommand(
|
|
567358
|
-
const runner = !serve && isOllamaRunnerCommand(
|
|
567356
|
+
for (const row2 of psRows) {
|
|
567357
|
+
const serve = isOllamaServeCommand(row2.command);
|
|
567358
|
+
const runner = !serve && isOllamaRunnerCommand(row2.command);
|
|
567359
567359
|
if (!serve && !runner)
|
|
567360
567360
|
continue;
|
|
567361
|
-
const env2 = serve ? await readProcEnv(system,
|
|
567361
|
+
const env2 = serve ? await readProcEnv(system, row2.pid) : { readable: false, values: {} };
|
|
567362
567362
|
const ports = uniqueNumbers([
|
|
567363
|
-
...portMap.get(
|
|
567363
|
+
...portMap.get(row2.pid) ?? [],
|
|
567364
567364
|
...serve ? portsFromEnv(env2.values) : []
|
|
567365
567365
|
]);
|
|
567366
567366
|
const ollamaApiPorts = serve ? await probeOllamaPorts(system, ports) : [];
|
|
567367
567367
|
snapshots.push({
|
|
567368
|
-
pid:
|
|
567369
|
-
ppid:
|
|
567370
|
-
command:
|
|
567371
|
-
cpuPct:
|
|
567372
|
-
memPct:
|
|
567373
|
-
elapsedMs:
|
|
567368
|
+
pid: row2.pid,
|
|
567369
|
+
ppid: row2.ppid,
|
|
567370
|
+
command: row2.command,
|
|
567371
|
+
cpuPct: row2.cpuPct,
|
|
567372
|
+
memPct: row2.memPct,
|
|
567373
|
+
elapsedMs: row2.elapsedMs,
|
|
567374
567374
|
ports,
|
|
567375
567375
|
ollamaApiPorts,
|
|
567376
567376
|
envReadable: env2.readable,
|
|
567377
567377
|
env: env2.values,
|
|
567378
|
-
gpuMemoryMb: gpuMemoryByPid.get(
|
|
567378
|
+
gpuMemoryMb: gpuMemoryByPid.get(row2.pid) ?? null,
|
|
567379
567379
|
isOllamaServe: serve,
|
|
567380
567380
|
isOllamaRunner: runner,
|
|
567381
|
-
runnerModelBlob: runner ? parseRunnerModelBlob(
|
|
567381
|
+
runnerModelBlob: runner ? parseRunnerModelBlob(row2.command) : null
|
|
567382
567382
|
});
|
|
567383
567383
|
}
|
|
567384
567384
|
const decisions = classifyOllamaProcesses(snapshots, {
|
|
@@ -573255,6 +573255,285 @@ var init_reflectionBuffer = __esm({
|
|
|
573255
573255
|
}
|
|
573256
573256
|
});
|
|
573257
573257
|
|
|
573258
|
+
// packages/orchestrator/dist/trajectory-checkpoint.js
|
|
573259
|
+
function sanitizeTrajectoryText(value2, max = 260) {
|
|
573260
|
+
const text2 = String(value2 ?? "").replace(/\x1B\[[0-?]*[ -/]*[@-~]/g, "").replace(CONTROL_RE, " ").replace(/\s+/g, " ").trim();
|
|
573261
|
+
return text2.length > max ? `${text2.slice(0, Math.max(0, max - 1))}…` : text2;
|
|
573262
|
+
}
|
|
573263
|
+
function trajectoryCheckpointFingerprint(checkpoint) {
|
|
573264
|
+
return [
|
|
573265
|
+
checkpoint.assessment,
|
|
573266
|
+
checkpoint.goal,
|
|
573267
|
+
checkpoint.phase ?? "",
|
|
573268
|
+
checkpoint.currentStep ?? "",
|
|
573269
|
+
checkpoint.completedWork.join(""),
|
|
573270
|
+
checkpoint.groundedFacts.map((fact) => `${fact.statement}\0${fact.evidence}\0${fact.freshness}`).join(""),
|
|
573271
|
+
checkpoint.openQuestions.join(""),
|
|
573272
|
+
checkpoint.nextAction,
|
|
573273
|
+
checkpoint.successEvidence,
|
|
573274
|
+
checkpoint.doNotRepeat.join("")
|
|
573275
|
+
].join("");
|
|
573276
|
+
}
|
|
573277
|
+
function buildTrajectoryCheckpoint(input) {
|
|
573278
|
+
const state = input.taskState;
|
|
573279
|
+
const goal = sanitizeTrajectoryText(state.originalGoal || state.goal, 600) || "Recover the concrete user goal before mutating project files.";
|
|
573280
|
+
const observations = input.observations.slice(-16);
|
|
573281
|
+
const outcome = [...observations].reverse().find((item) => item.type === "tool_result" || item.type === "error");
|
|
573282
|
+
const outcomeText = sanitizeTrajectoryText(outcome?.content, 240);
|
|
573283
|
+
const latestFailure = [...observations].reverse().find((item) => item.type === "tool_result" && item.success === false || item.type === "error");
|
|
573284
|
+
const failureText = sanitizeTrajectoryText(latestFailure?.content, 300);
|
|
573285
|
+
const fallbackFailure = input.recentFailures?.at(-1);
|
|
573286
|
+
const combinedFailure = [
|
|
573287
|
+
failureText,
|
|
573288
|
+
sanitizeTrajectoryText(fallbackFailure?.error || fallbackFailure?.output, 300)
|
|
573289
|
+
].filter(Boolean).join(" ");
|
|
573290
|
+
const focus = sanitizeTrajectoryText(input.focusDirective, 300);
|
|
573291
|
+
const targetPath = inferTargetPath(combinedFailure || outcomeText || focus) ?? latestFailure?.targetPath ?? mostRecentTargetForTool(observations, latestFailure?.toolName);
|
|
573292
|
+
const targetFreshness = targetPath ? input.evidenceFreshness?.(targetPath) ?? "unknown" : "unknown";
|
|
573293
|
+
const fullWriteIssue = (latestFailure?.toolName === "file_write" || fallbackFailure?.tool === "file_write" || /file_write/i.test(combinedFailure)) && /FULL FILE (?:WRITE LOOP BLOCKED|REWRITE CONTRACT)|overwrite(?:=true)?|expected_hash|Refusing to overwrite existing file/i.test(combinedFailure);
|
|
573294
|
+
const explicitBlock = /(?:permission denied|needs user input|ask_user|cannot proceed|external dependency|\[.*BLOCKED\])/i.test(combinedFailure);
|
|
573295
|
+
const hasRecentFailure = Boolean(combinedFailure);
|
|
573296
|
+
const modifiedFiles = Array.from(state.modifiedFiles).slice(-3);
|
|
573297
|
+
const verifierDue = modifiedFiles.length > 0 && (input.lastVerifier?.turn === void 0 || input.lastMutationTurn !== void 0 && (input.lastVerifier.turn ?? -1) < input.lastMutationTurn);
|
|
573298
|
+
let assessment = "on_trajectory";
|
|
573299
|
+
let nextAction = sanitizeTrajectoryText(state.nextAction, 260) || "Take one narrow, evidence-backed action that advances the active task.";
|
|
573300
|
+
let successEvidence = "A tool result directly confirms the next action advanced the stated goal.";
|
|
573301
|
+
const openQuestions = [];
|
|
573302
|
+
const doNotRepeat = [];
|
|
573303
|
+
if (fullWriteIssue) {
|
|
573304
|
+
assessment = "recovery_required";
|
|
573305
|
+
const target = targetPath || "the existing target file";
|
|
573306
|
+
nextAction = targetFreshness === "fresh" ? `Use file_edit/file_patch for the local change in ${target}; do not resume full-file writes.` : `file_read ${target}, then prefer file_edit/file_patch for the local change.`;
|
|
573307
|
+
successEvidence = targetFreshness === "fresh" ? "A targeted mutation based on the freshly read file, or an explicit evidence-backed blocker." : "Fresh current file evidence followed by a targeted mutation, or an explicit evidence-backed blocker.";
|
|
573308
|
+
doNotRepeat.push(`file_write ${target} with another changed full-file payload before fresh read evidence.`);
|
|
573309
|
+
if (targetFreshness !== "fresh") {
|
|
573310
|
+
openQuestions.push(`Current bytes/hash for ${target} are not freshly evidenced.`);
|
|
573311
|
+
}
|
|
573312
|
+
} else if (explicitBlock) {
|
|
573313
|
+
assessment = "blocked";
|
|
573314
|
+
nextAction = "Resolve or report the explicit blocker with the evidence that established it.";
|
|
573315
|
+
successEvidence = "A new observation removes the blocker or documents why it cannot be removed.";
|
|
573316
|
+
doNotRepeat.push("Retrying the blocked action unchanged without new evidence.");
|
|
573317
|
+
} else if (focus) {
|
|
573318
|
+
assessment = "recovery_required";
|
|
573319
|
+
nextAction = extractFocusNextAction(focus) || nextAction;
|
|
573320
|
+
successEvidence = "The focus recovery requirement is satisfied by a fresh tool observation.";
|
|
573321
|
+
doNotRepeat.push("Ignoring the active focus recovery directive.");
|
|
573322
|
+
} else if (hasRecentFailure) {
|
|
573323
|
+
assessment = "recovery_required";
|
|
573324
|
+
nextAction = "Use the newest failure evidence to make one different, narrow diagnostic or repair action.";
|
|
573325
|
+
successEvidence = "The next tool result changes, resolves, or explicitly narrows the observed failure.";
|
|
573326
|
+
doNotRepeat.push("Retrying the same failed action with unchanged prerequisites.");
|
|
573327
|
+
} else if (verifierDue) {
|
|
573328
|
+
assessment = "verification_due";
|
|
573329
|
+
nextAction = "Run the declared verifier or the narrowest relevant validation for the recent mutation.";
|
|
573330
|
+
successEvidence = "A post-mutation verifier result is recorded.";
|
|
573331
|
+
}
|
|
573332
|
+
const groundedFacts = [];
|
|
573333
|
+
if (state.currentStep.trim()) {
|
|
573334
|
+
groundedFacts.push({
|
|
573335
|
+
statement: `Current work: ${sanitizeTrajectoryText(state.currentStep, 180)}`,
|
|
573336
|
+
evidence: `task_state@tool_call_${state.toolCallCount}`,
|
|
573337
|
+
freshness: "unknown"
|
|
573338
|
+
});
|
|
573339
|
+
}
|
|
573340
|
+
if (outcomeText) {
|
|
573341
|
+
const status = outcome?.success === false ? "failed" : "observed";
|
|
573342
|
+
groundedFacts.push({
|
|
573343
|
+
statement: `${outcome?.toolName ?? "runner"} ${status}: ${outcomeText}`,
|
|
573344
|
+
evidence: `turn:${outcome?.turn ?? input.turn}:${outcome?.type ?? "event"}`,
|
|
573345
|
+
freshness: "fresh"
|
|
573346
|
+
});
|
|
573347
|
+
}
|
|
573348
|
+
if (modifiedFiles.length > 0) {
|
|
573349
|
+
groundedFacts.push({
|
|
573350
|
+
statement: `Recent project mutations: ${modifiedFiles.map(([path16, action]) => `${path16} (${action})`).join(", ")}`,
|
|
573351
|
+
evidence: `task_state@tool_call_${state.toolCallCount}`,
|
|
573352
|
+
freshness: "unknown"
|
|
573353
|
+
});
|
|
573354
|
+
}
|
|
573355
|
+
if (input.lastVerifier?.summary) {
|
|
573356
|
+
groundedFacts.push({
|
|
573357
|
+
statement: `Latest verifier ${input.lastVerifier.passed === true ? "passed" : input.lastVerifier.passed === false ? "failed" : "reported"}: ${sanitizeTrajectoryText(input.lastVerifier.summary, 180)}`,
|
|
573358
|
+
evidence: `verifier@turn_${input.lastVerifier.turn ?? "unknown"}`,
|
|
573359
|
+
freshness: "fresh"
|
|
573360
|
+
});
|
|
573361
|
+
}
|
|
573362
|
+
if (targetPath) {
|
|
573363
|
+
groundedFacts.push({
|
|
573364
|
+
statement: `Evidence for ${targetPath}: ${targetFreshness}`,
|
|
573365
|
+
evidence: `evidence_ledger:${targetPath}`,
|
|
573366
|
+
freshness: targetFreshness
|
|
573367
|
+
});
|
|
573368
|
+
}
|
|
573369
|
+
if (focus) {
|
|
573370
|
+
groundedFacts.push({
|
|
573371
|
+
statement: `Active recovery directive: ${focus}`,
|
|
573372
|
+
evidence: "focus_supervisor",
|
|
573373
|
+
freshness: "fresh"
|
|
573374
|
+
});
|
|
573375
|
+
}
|
|
573376
|
+
const completedWork = state.completedSteps.slice(-MAX_COMPLETED).map((value2) => sanitizeTrajectoryText(value2, 180)).filter(Boolean);
|
|
573377
|
+
if (state.pendingSteps.length > 0 && !state.nextAction.trim()) {
|
|
573378
|
+
openQuestions.push(`Choose the next pending task: ${sanitizeTrajectoryText(state.pendingSteps[0], 180)}`);
|
|
573379
|
+
}
|
|
573380
|
+
const checkpointWithoutIdentity = {
|
|
573381
|
+
schemaVersion: 1,
|
|
573382
|
+
trigger: sanitizeTrajectoryText(input.trigger || inferTrigger(outcome), 80),
|
|
573383
|
+
assessment,
|
|
573384
|
+
goal,
|
|
573385
|
+
phase: sanitizeTrajectoryText(state.phase, 60) || void 0,
|
|
573386
|
+
currentStep: sanitizeTrajectoryText(state.currentStep, 180) || void 0,
|
|
573387
|
+
completedWork,
|
|
573388
|
+
groundedFacts: groundedFacts.slice(0, MAX_FACTS),
|
|
573389
|
+
openQuestions: unique2(openQuestions, 2),
|
|
573390
|
+
nextAction: sanitizeTrajectoryText(nextAction, 320),
|
|
573391
|
+
successEvidence: sanitizeTrajectoryText(successEvidence, 280),
|
|
573392
|
+
doNotRepeat: unique2(doNotRepeat, MAX_CONSTRAINTS)
|
|
573393
|
+
};
|
|
573394
|
+
const fingerprint = trajectoryCheckpointFingerprint(checkpointWithoutIdentity);
|
|
573395
|
+
return {
|
|
573396
|
+
...checkpointWithoutIdentity,
|
|
573397
|
+
id: `trajectory-${input.turn}-${shortHash2(fingerprint)}`,
|
|
573398
|
+
revision: input.revision,
|
|
573399
|
+
turn: input.turn
|
|
573400
|
+
};
|
|
573401
|
+
}
|
|
573402
|
+
function renderTrajectoryCheckpoint(checkpoint, maxChars = 1100) {
|
|
573403
|
+
const lines = [
|
|
573404
|
+
"[TRAJECTORY CHECKPOINT]",
|
|
573405
|
+
`revision=${checkpoint.revision} turn=${checkpoint.turn} trigger=${checkpoint.trigger}`,
|
|
573406
|
+
`Goal: ${checkpoint.goal}`,
|
|
573407
|
+
`Assessment: ${checkpoint.assessment}`,
|
|
573408
|
+
checkpoint.phase ? `Phase: ${checkpoint.phase}` : null,
|
|
573409
|
+
checkpoint.currentStep ? `Current step: ${checkpoint.currentStep}` : null,
|
|
573410
|
+
checkpoint.completedWork.length > 0 ? `Completed evidence-backed work: ${checkpoint.completedWork.join("; ")}` : null,
|
|
573411
|
+
checkpoint.groundedFacts.length > 0 ? "Grounded facts:" : null,
|
|
573412
|
+
...checkpoint.groundedFacts.map((fact) => `- [${fact.evidence}; ${fact.freshness}] ${fact.statement}`),
|
|
573413
|
+
checkpoint.openQuestions.length > 0 ? "Open questions:" : null,
|
|
573414
|
+
...checkpoint.openQuestions.map((question) => `- ${question}`),
|
|
573415
|
+
`Required next action: ${checkpoint.nextAction}`,
|
|
573416
|
+
`Success evidence: ${checkpoint.successEvidence}`,
|
|
573417
|
+
checkpoint.doNotRepeat.length > 0 ? "Do not repeat:" : null,
|
|
573418
|
+
...checkpoint.doNotRepeat.map((constraint) => `- ${constraint}`),
|
|
573419
|
+
"Attention rule: reconcile the next tool call with this checkpoint. Treat stale or unknown evidence as a reason to read or verify. Do not quote this checkpoint or produce a reasoning transcript."
|
|
573420
|
+
].filter((line) => Boolean(line));
|
|
573421
|
+
return truncate(lines.join("\n"), maxChars);
|
|
573422
|
+
}
|
|
573423
|
+
function scopeTrajectoryCheckpoint(checkpoint, delegatedScope, exitEvidence) {
|
|
573424
|
+
if (!checkpoint)
|
|
573425
|
+
return null;
|
|
573426
|
+
return {
|
|
573427
|
+
parentGoal: checkpoint.goal,
|
|
573428
|
+
delegatedScope: sanitizeTrajectoryText(delegatedScope, 320),
|
|
573429
|
+
assessment: checkpoint.assessment,
|
|
573430
|
+
relevantConstraint: checkpoint.doNotRepeat[0],
|
|
573431
|
+
exitEvidence: sanitizeTrajectoryText(exitEvidence, 260)
|
|
573432
|
+
};
|
|
573433
|
+
}
|
|
573434
|
+
function renderScopedTrajectoryCheckpoint(slice2) {
|
|
573435
|
+
if (!slice2)
|
|
573436
|
+
return "";
|
|
573437
|
+
return [
|
|
573438
|
+
"[PARENT TRAJECTORY SCOPE]",
|
|
573439
|
+
`Parent goal: ${slice2.parentGoal}`,
|
|
573440
|
+
`Delegated scope: ${slice2.delegatedScope}`,
|
|
573441
|
+
`Parent assessment: ${slice2.assessment}`,
|
|
573442
|
+
slice2.relevantConstraint ? `Relevant constraint: ${slice2.relevantConstraint}` : null,
|
|
573443
|
+
`Exit evidence required: ${slice2.exitEvidence}`,
|
|
573444
|
+
"Use this as scoped orientation. Verify your own file and tool facts before acting."
|
|
573445
|
+
].filter((line) => Boolean(line)).join("\n");
|
|
573446
|
+
}
|
|
573447
|
+
function inferTrigger(outcome) {
|
|
573448
|
+
if (!outcome)
|
|
573449
|
+
return "task_start";
|
|
573450
|
+
if (outcome.type === "compaction")
|
|
573451
|
+
return "compaction";
|
|
573452
|
+
if (outcome.type === "error")
|
|
573453
|
+
return "error";
|
|
573454
|
+
if (outcome.type === "tool_result") {
|
|
573455
|
+
return outcome.success === false ? "tool_failure" : "tool_result";
|
|
573456
|
+
}
|
|
573457
|
+
return outcome.type;
|
|
573458
|
+
}
|
|
573459
|
+
function inferTargetPath(value2) {
|
|
573460
|
+
const text2 = String(value2 ?? "");
|
|
573461
|
+
const patterns = [
|
|
573462
|
+
/\]\s+([^\s,;]+\.[a-zA-Z0-9_-]+)\s+has already/i,
|
|
573463
|
+
/existing file\s+([^\s,;]+)/i,
|
|
573464
|
+
/(?:file_read|file_write|file_edit|file_patch)\s+([^\s,;]+)/i,
|
|
573465
|
+
/(?:path|file)\s*[=:]\s*["']([^"']+)["']/i
|
|
573466
|
+
];
|
|
573467
|
+
for (const pattern of patterns) {
|
|
573468
|
+
const candidate = pattern.exec(text2)?.[1]?.trim();
|
|
573469
|
+
if (candidate)
|
|
573470
|
+
return candidate.replace(/[.)\]}]+$/, "");
|
|
573471
|
+
}
|
|
573472
|
+
return null;
|
|
573473
|
+
}
|
|
573474
|
+
function mostRecentTargetForTool(observations, toolName) {
|
|
573475
|
+
for (const observation of [...observations].reverse()) {
|
|
573476
|
+
if (observation.type === "tool_call" && observation.targetPath && (!toolName || observation.toolName === toolName)) {
|
|
573477
|
+
return observation.targetPath;
|
|
573478
|
+
}
|
|
573479
|
+
}
|
|
573480
|
+
return null;
|
|
573481
|
+
}
|
|
573482
|
+
function extractFocusNextAction(value2) {
|
|
573483
|
+
const match = /(?:Required next action|Next action)\s*:\s*(.+?)(?=\s+(?:Success evidence|Do not repeat|Attention rule)|$)/i.exec(value2);
|
|
573484
|
+
if (match?.[1])
|
|
573485
|
+
return sanitizeTrajectoryText(match[1], 300);
|
|
573486
|
+
const required = /required_next_action=([a-z_]+)/i.exec(value2)?.[1];
|
|
573487
|
+
switch (required) {
|
|
573488
|
+
case "read_authoritative_target":
|
|
573489
|
+
return "Read the authoritative target before attempting another mutation.";
|
|
573490
|
+
case "disambiguate_edit_match":
|
|
573491
|
+
return "Read the current target and disambiguate the intended edit match.";
|
|
573492
|
+
case "edit_different_target":
|
|
573493
|
+
return "Choose a different evidence-backed target for the next edit.";
|
|
573494
|
+
case "run_verification":
|
|
573495
|
+
return "Run the required verification before additional exploration or completion.";
|
|
573496
|
+
case "use_cached_evidence":
|
|
573497
|
+
return "Use the already-rendered evidence before requesting another identical read.";
|
|
573498
|
+
case "update_todos":
|
|
573499
|
+
return "Update the task plan to reflect the current evidence before continuing.";
|
|
573500
|
+
case "delegate_isolated_fix":
|
|
573501
|
+
return "Delegate the isolated repair with a concrete exit-evidence contract.";
|
|
573502
|
+
case "creative_pivot_or_research":
|
|
573503
|
+
return "Take a different diagnostic or research action grounded in the latest failure.";
|
|
573504
|
+
case "report_blocked":
|
|
573505
|
+
case "report_incomplete":
|
|
573506
|
+
return "Report the current blocker or incomplete state with the evidence that established it.";
|
|
573507
|
+
default:
|
|
573508
|
+
return null;
|
|
573509
|
+
}
|
|
573510
|
+
}
|
|
573511
|
+
function unique2(values, limit) {
|
|
573512
|
+
return [...new Set(values.map((value2) => sanitizeTrajectoryText(value2)).filter(Boolean))].slice(0, limit);
|
|
573513
|
+
}
|
|
573514
|
+
function truncate(value2, max) {
|
|
573515
|
+
const clean5 = String(value2 ?? "").trim();
|
|
573516
|
+
return clean5.length > max ? `${clean5.slice(0, Math.max(0, max - 1))}…` : clean5;
|
|
573517
|
+
}
|
|
573518
|
+
function shortHash2(value2) {
|
|
573519
|
+
let hash = 2166136261;
|
|
573520
|
+
for (let i2 = 0; i2 < value2.length; i2++) {
|
|
573521
|
+
hash ^= value2.charCodeAt(i2);
|
|
573522
|
+
hash = Math.imul(hash, 16777619);
|
|
573523
|
+
}
|
|
573524
|
+
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
573525
|
+
}
|
|
573526
|
+
var CONTROL_RE, MAX_FACTS, MAX_COMPLETED, MAX_CONSTRAINTS;
|
|
573527
|
+
var init_trajectory_checkpoint = __esm({
|
|
573528
|
+
"packages/orchestrator/dist/trajectory-checkpoint.js"() {
|
|
573529
|
+
"use strict";
|
|
573530
|
+
CONTROL_RE = /[\x00-\x1F\x7F]/g;
|
|
573531
|
+
MAX_FACTS = 5;
|
|
573532
|
+
MAX_COMPLETED = 3;
|
|
573533
|
+
MAX_CONSTRAINTS = 3;
|
|
573534
|
+
}
|
|
573535
|
+
});
|
|
573536
|
+
|
|
573258
573537
|
// packages/orchestrator/dist/taskHandoff.js
|
|
573259
573538
|
import * as fs4 from "node:fs";
|
|
573260
573539
|
import * as path5 from "node:path";
|
|
@@ -573290,6 +573569,12 @@ function buildTaskHandoff(params) {
|
|
|
573290
573569
|
toolsUsed,
|
|
573291
573570
|
turns: params.turns
|
|
573292
573571
|
});
|
|
573572
|
+
const trajectory = params.trajectory ? {
|
|
573573
|
+
assessment: params.trajectory.assessment,
|
|
573574
|
+
nextAction: sanitizeTrajectoryText(params.trajectory.nextAction, 360),
|
|
573575
|
+
successEvidence: sanitizeTrajectoryText(params.trajectory.successEvidence, 360),
|
|
573576
|
+
doNotRepeat: params.trajectory.doNotRepeat.slice(0, 3).map((item) => sanitizeTrajectoryText(item, 220)).filter(Boolean)
|
|
573577
|
+
} : void 0;
|
|
573293
573578
|
return {
|
|
573294
573579
|
v: 2,
|
|
573295
573580
|
sessionId: params.sessionId,
|
|
@@ -573303,6 +573588,7 @@ function buildTaskHandoff(params) {
|
|
|
573303
573588
|
endedAt: Date.now(),
|
|
573304
573589
|
artifactMode,
|
|
573305
573590
|
quality,
|
|
573591
|
+
...trajectory ? { trajectory } : {},
|
|
573306
573592
|
...params.transcriptPath ? { transcriptPath: params.transcriptPath } : {}
|
|
573307
573593
|
};
|
|
573308
573594
|
}
|
|
@@ -573374,6 +573660,14 @@ function buildHandoffMessagePair(h) {
|
|
|
573374
573660
|
const toolsBlock = h.toolsUsed.length ? h.toolsUsed.map((t2) => ` - ${t2}`).join("\n") : " (none)";
|
|
573375
573661
|
const actionsBlock = h.lastActions.length ? h.lastActions.map((a2) => ` - ${a2}`).join("\n") : " (none recorded)";
|
|
573376
573662
|
const summaryBlock = h.priorSummary || "(no summary captured)";
|
|
573663
|
+
const trajectoryBlock = h.trajectory ? [
|
|
573664
|
+
"Prior trajectory (STALE orientation — verify before acting):",
|
|
573665
|
+
` Assessment: ${h.trajectory.assessment}`,
|
|
573666
|
+
` Next: ${h.trajectory.nextAction || "(not captured)"}`,
|
|
573667
|
+
` Proof: ${h.trajectory.successEvidence || "(not captured)"}`,
|
|
573668
|
+
...h.trajectory.doNotRepeat.length ? [` Guard: ${h.trajectory.doNotRepeat.join("; ")}`] : [],
|
|
573669
|
+
""
|
|
573670
|
+
] : [];
|
|
573377
573671
|
const transcriptHint = h.transcriptPath ? `
|
|
573378
573672
|
|
|
573379
573673
|
If you need verbatim details from the prior task (specific code, exact error messages, or content beyond this summary), file_read the transcript at: ${h.transcriptPath}` : "";
|
|
@@ -573395,6 +573689,7 @@ If you need verbatim details from the prior task (specific code, exact error mes
|
|
|
573395
573689
|
"Summary:",
|
|
573396
573690
|
summaryBlock,
|
|
573397
573691
|
"",
|
|
573692
|
+
...trajectoryBlock,
|
|
573398
573693
|
"Last actions:",
|
|
573399
573694
|
actionsBlock,
|
|
573400
573695
|
transcriptHint,
|
|
@@ -573414,6 +573709,7 @@ var init_taskHandoff = __esm({
|
|
|
573414
573709
|
"packages/orchestrator/dist/taskHandoff.js"() {
|
|
573415
573710
|
"use strict";
|
|
573416
573711
|
init_artifactQuality();
|
|
573712
|
+
init_trajectory_checkpoint();
|
|
573417
573713
|
DEFAULT_TTL_MS2 = 24 * 60 * 60 * 1e3;
|
|
573418
573714
|
MAX_SUMMARY_CHARS = 8e3;
|
|
573419
573715
|
MAX_FILES = 30;
|
|
@@ -574060,7 +574356,7 @@ var init_codeGraphLink = __esm({
|
|
|
574060
574356
|
|
|
574061
574357
|
// packages/orchestrator/dist/artifactContract.js
|
|
574062
574358
|
import { createHash as createHash29 } from "node:crypto";
|
|
574063
|
-
function
|
|
574359
|
+
function shortHash3(content) {
|
|
574064
574360
|
if (!content)
|
|
574065
574361
|
return "empty";
|
|
574066
574362
|
try {
|
|
@@ -574101,7 +574397,7 @@ var init_artifactContract = __esm({
|
|
|
574101
574397
|
}
|
|
574102
574398
|
update(path16, mutation, content, fileSize2) {
|
|
574103
574399
|
const existing = this._contracts.get(path16);
|
|
574104
|
-
const hash = content !== void 0 ?
|
|
574400
|
+
const hash = content !== void 0 ? shortHash3(content) : existing?.hash ?? "unknown";
|
|
574105
574401
|
const size = fileSize2 ?? existing?.size ?? 0;
|
|
574106
574402
|
const mutationCount = (existing?.mutationCount ?? 0) + (mutation ? 1 : 0);
|
|
574107
574403
|
const role = mutation ? existing?.role === "read" || existing?.role === "read-write" ? "read-write" : "write" : existing?.role === "write" || existing?.role === "read-write" ? "read-write" : "read";
|
|
@@ -574377,7 +574673,7 @@ var init_artifactContract = __esm({
|
|
|
574377
574673
|
dedupeKey(content, cls) {
|
|
574378
574674
|
if (cls.dedupeKey)
|
|
574379
574675
|
return cls.dedupeKey;
|
|
574380
|
-
return `exact:${
|
|
574676
|
+
return `exact:${shortHash3(content)}`;
|
|
574381
574677
|
}
|
|
574382
574678
|
dropPriority(cls) {
|
|
574383
574679
|
if (cls.preserve)
|
|
@@ -577146,7 +577442,7 @@ function isControlSignal(signal) {
|
|
|
577146
577442
|
return signal.kind === "runtime_guidance" || signal.kind === "action_contract" || signal.kind === "recent_failure";
|
|
577147
577443
|
}
|
|
577148
577444
|
function isEvidenceSignal(signal) {
|
|
577149
|
-
return signal.kind === "goal" || signal.kind === "user_steering" || signal.kind === "task_state" || signal.kind === "known_files" || signal.kind === "tool_cache" || signal.kind === "git_state" || signal.kind === "memory" || signal.kind === "semantic_chunk" || signal.kind === "session_history" || signal.kind === "anchor" || signal.kind === "handoff" || signal.kind === "environment" || signal.kind === "compaction_summary";
|
|
577445
|
+
return signal.kind === "goal" || signal.kind === "user_steering" || signal.kind === "trajectory_checkpoint" || signal.kind === "task_state" || signal.kind === "known_files" || signal.kind === "tool_cache" || signal.kind === "git_state" || signal.kind === "memory" || signal.kind === "semantic_chunk" || signal.kind === "session_history" || signal.kind === "anchor" || signal.kind === "handoff" || signal.kind === "environment" || signal.kind === "compaction_summary";
|
|
577150
577446
|
}
|
|
577151
577447
|
function signalFromBlock(kind, source, content, options2 = {}) {
|
|
577152
577448
|
const normalized = normalizeSignalContent(content ?? "");
|
|
@@ -577176,6 +577472,7 @@ var init_context_fabric = __esm({
|
|
|
577176
577472
|
PRIORITY = {
|
|
577177
577473
|
GOAL: 100,
|
|
577178
577474
|
ACTION_CONTRACT: 98,
|
|
577475
|
+
TRAJECTORY: 97,
|
|
577179
577476
|
USER_STEERING: 95,
|
|
577180
577477
|
RUNTIME_GUIDANCE: 94,
|
|
577181
577478
|
GIT_STATE: 86,
|
|
@@ -577195,6 +577492,7 @@ var init_context_fabric = __esm({
|
|
|
577195
577492
|
KIND_ORDER = [
|
|
577196
577493
|
"goal",
|
|
577197
577494
|
"user_steering",
|
|
577495
|
+
"trajectory_checkpoint",
|
|
577198
577496
|
"runtime_guidance",
|
|
577199
577497
|
"action_contract",
|
|
577200
577498
|
"git_state",
|
|
@@ -577214,6 +577512,7 @@ var init_context_fabric = __esm({
|
|
|
577214
577512
|
KIND_LABELS = {
|
|
577215
577513
|
goal: "Goal",
|
|
577216
577514
|
user_steering: "User Steering",
|
|
577515
|
+
trajectory_checkpoint: "Trajectory Checkpoint",
|
|
577217
577516
|
runtime_guidance: "Runtime Guidance",
|
|
577218
577517
|
action_contract: "Next Action Contract",
|
|
577219
577518
|
git_state: "Git State",
|
|
@@ -577233,6 +577532,7 @@ var init_context_fabric = __esm({
|
|
|
577233
577532
|
DEFAULT_KIND_CHAR_BUDGET = {
|
|
577234
577533
|
goal: 900,
|
|
577235
577534
|
user_steering: 1400,
|
|
577535
|
+
trajectory_checkpoint: 1200,
|
|
577236
577536
|
runtime_guidance: 900,
|
|
577237
577537
|
action_contract: 1400,
|
|
577238
577538
|
git_state: 1400,
|
|
@@ -577556,6 +577856,8 @@ function runtimeControlSemanticKey(content) {
|
|
|
577556
577856
|
return null;
|
|
577557
577857
|
if (content.includes("[ACTIVE CONTEXT FRAME]"))
|
|
577558
577858
|
return "context.active-frame";
|
|
577859
|
+
if (content.includes("[TRAJECTORY CHECKPOINT]"))
|
|
577860
|
+
return "context.trajectory-checkpoint";
|
|
577559
577861
|
if (content.includes("[NEXT ACTION CONTRACT]"))
|
|
577560
577862
|
return "context.next-action";
|
|
577561
577863
|
if (content.includes("[RUNTIME DIRECTIVE]")) {
|
|
@@ -578002,7 +578304,7 @@ function recordContextWindowDump(input) {
|
|
|
578002
578304
|
String(input.turn ?? ""),
|
|
578003
578305
|
String(input.attempt ?? "")
|
|
578004
578306
|
].join("|");
|
|
578005
|
-
const id2 = `${timestamp.replace(/[:.]/g, "-")}-${input.agentType}-${
|
|
578307
|
+
const id2 = `${timestamp.replace(/[:.]/g, "-")}-${input.agentType}-${shortHash4(stable)}`;
|
|
578006
578308
|
const metrics2 = analyzeContextWindowDumpRequest(input.request);
|
|
578007
578309
|
const record = {
|
|
578008
578310
|
schemaVersion: 1,
|
|
@@ -578323,7 +578625,7 @@ function trimString(value2, max) {
|
|
|
578323
578625
|
function safeId(value2) {
|
|
578324
578626
|
return String(value2 || "unknown").replace(/[^a-zA-Z0-9_.:-]/g, "_").slice(0, 160);
|
|
578325
578627
|
}
|
|
578326
|
-
function
|
|
578628
|
+
function shortHash4(value2) {
|
|
578327
578629
|
return createHash30("sha256").update(value2).digest("hex").slice(0, 10);
|
|
578328
578630
|
}
|
|
578329
578631
|
function pruneOldDumpFiles(dir) {
|
|
@@ -578768,7 +579070,7 @@ function recordDebugToolEvent(input) {
|
|
|
578768
579070
|
if (!shouldRecordToolEvent(input, diagnoses))
|
|
578769
579071
|
return null;
|
|
578770
579072
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
578771
|
-
const argsHash =
|
|
579073
|
+
const argsHash = shortHash5(argsPreview);
|
|
578772
579074
|
const eventId = [
|
|
578773
579075
|
timestamp.replace(/[:.]/g, "-"),
|
|
578774
579076
|
safeId2(input.toolName),
|
|
@@ -578839,7 +579141,7 @@ function recordDebugContextWindowDump(input) {
|
|
|
578839
579141
|
const eventId = [
|
|
578840
579142
|
timestamp.replace(/[:.]/g, "-"),
|
|
578841
579143
|
"context",
|
|
578842
|
-
|
|
579144
|
+
shortHash5(input.record.id)
|
|
578843
579145
|
].join("-");
|
|
578844
579146
|
const eventDir = join112(paths.runDir, "events", turnDir(input.record.turn));
|
|
578845
579147
|
const eventPath = join112(eventDir, `${eventId}.json`);
|
|
@@ -578881,6 +579183,56 @@ function recordDebugContextWindowDump(input) {
|
|
|
578881
579183
|
writeEventAndIndexes(paths, event, eventPath);
|
|
578882
579184
|
return event;
|
|
578883
579185
|
}
|
|
579186
|
+
function recordDebugTrajectoryCheckpoint(input) {
|
|
579187
|
+
if (debugArtifactDisabled())
|
|
579188
|
+
return null;
|
|
579189
|
+
const checkpoint = input.checkpoint;
|
|
579190
|
+
const cwd4 = resolve55(input.cwd || process.cwd());
|
|
579191
|
+
const runId = safeId2(input.runId || input.sessionId || "unknown-run");
|
|
579192
|
+
const sessionId = safeId2(input.sessionId || runId);
|
|
579193
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
579194
|
+
const paths = debugRunPaths(cwd4, runId, input.stateDir);
|
|
579195
|
+
const eventId = [
|
|
579196
|
+
timestamp.replace(/[:.]/g, "-"),
|
|
579197
|
+
"trajectory",
|
|
579198
|
+
shortHash5(checkpoint.id)
|
|
579199
|
+
].join("-");
|
|
579200
|
+
const eventDir = join112(paths.runDir, "events", turnDir(checkpoint.turn));
|
|
579201
|
+
const eventPath = join112(eventDir, `${eventId}.json`);
|
|
579202
|
+
const diagnoses = [
|
|
579203
|
+
"trajectory-checkpoint",
|
|
579204
|
+
`trajectory-${checkpoint.assessment.replace(/_/g, "-")}`
|
|
579205
|
+
];
|
|
579206
|
+
const event = {
|
|
579207
|
+
schemaVersion: 1,
|
|
579208
|
+
id: eventId,
|
|
579209
|
+
kind: "trajectory_checkpoint",
|
|
579210
|
+
timestamp,
|
|
579211
|
+
runId,
|
|
579212
|
+
sessionId,
|
|
579213
|
+
cwd: cwd4,
|
|
579214
|
+
turn: checkpoint.turn,
|
|
579215
|
+
trajectory: {
|
|
579216
|
+
revision: checkpoint.revision,
|
|
579217
|
+
assessment: checkpoint.assessment,
|
|
579218
|
+
nextAction: trim(checkpoint.nextAction, 500),
|
|
579219
|
+
successEvidence: trim(checkpoint.successEvidence, 500),
|
|
579220
|
+
doNotRepeat: checkpoint.doNotRepeat.slice(0, 3).map((value2) => trim(value2, 300))
|
|
579221
|
+
},
|
|
579222
|
+
diagnoses,
|
|
579223
|
+
summary: `Trajectory ${checkpoint.assessment}: ${trim(checkpoint.nextAction, 220)}`,
|
|
579224
|
+
anchors: buildAnchors(cwd4, runId, paths, [
|
|
579225
|
+
{
|
|
579226
|
+
label: "event_json",
|
|
579227
|
+
kind: "event",
|
|
579228
|
+
path: eventPath,
|
|
579229
|
+
note: "Evidence-bound trajectory checkpoint."
|
|
579230
|
+
}
|
|
579231
|
+
])
|
|
579232
|
+
};
|
|
579233
|
+
writeEventAndIndexes(paths, event, eventPath);
|
|
579234
|
+
return event;
|
|
579235
|
+
}
|
|
578884
579236
|
function debugRunPaths(cwd4, runId, stateDir) {
|
|
578885
579237
|
const root = debugArtifactRoot(cwd4, stateDir);
|
|
578886
579238
|
const runDir = join112(root, "runs", safeId2(runId));
|
|
@@ -578931,6 +579283,7 @@ function updateRunIndex(paths, event, eventPath) {
|
|
|
578931
579283
|
eventCount: 0,
|
|
578932
579284
|
toolEventCount: 0,
|
|
578933
579285
|
contextDumpCount: 0,
|
|
579286
|
+
trajectoryCheckpointCount: 0,
|
|
578934
579287
|
successCount: 0,
|
|
578935
579288
|
failureCount: 0,
|
|
578936
579289
|
mutationCount: 0,
|
|
@@ -578948,6 +579301,9 @@ function updateRunIndex(paths, event, eventPath) {
|
|
|
578948
579301
|
index.summary.toolEventCount++;
|
|
578949
579302
|
if (event.kind === "context_window_dump")
|
|
578950
579303
|
index.summary.contextDumpCount++;
|
|
579304
|
+
if (event.kind === "trajectory_checkpoint") {
|
|
579305
|
+
index.summary.trajectoryCheckpointCount = (index.summary.trajectoryCheckpointCount ?? 0) + 1;
|
|
579306
|
+
}
|
|
578951
579307
|
if (event.success === true)
|
|
578952
579308
|
index.summary.successCount++;
|
|
578953
579309
|
if (event.success === false)
|
|
@@ -579505,7 +579861,7 @@ function trim(value2, max) {
|
|
|
579505
579861
|
function safeId2(value2) {
|
|
579506
579862
|
return String(value2 || "unknown").replace(/[^a-zA-Z0-9_.:-]/g, "_").slice(0, 160);
|
|
579507
579863
|
}
|
|
579508
|
-
function
|
|
579864
|
+
function shortHash5(value2) {
|
|
579509
579865
|
return createHash31("sha256").update(value2).digest("hex").slice(0, 10);
|
|
579510
579866
|
}
|
|
579511
579867
|
var DEBUG_LIBRARY_DIR, RUN_EVENTS_LIMIT, PREVIEW_LIMIT;
|
|
@@ -581737,10 +582093,10 @@ function compileFixCardToWorkboardInput(card) {
|
|
|
581737
582093
|
};
|
|
581738
582094
|
}
|
|
581739
582095
|
function compileFixCardId(fingerprint) {
|
|
581740
|
-
return `compile-${
|
|
582096
|
+
return `compile-${shortHash6(fingerprint)}`;
|
|
581741
582097
|
}
|
|
581742
582098
|
function compileFixVerifierFingerprint(command) {
|
|
581743
|
-
return
|
|
582099
|
+
return shortHash6(command.trim().replace(/\s+/g, " "));
|
|
581744
582100
|
}
|
|
581745
582101
|
function formatDiagnosticLocation(diag) {
|
|
581746
582102
|
const parts = [diag.file || "<compiler-output>"];
|
|
@@ -581773,7 +582129,7 @@ function normalizeDiagnostic(diag, index, source) {
|
|
|
581773
582129
|
message: message2
|
|
581774
582130
|
});
|
|
581775
582131
|
return {
|
|
581776
|
-
id: `diag-${
|
|
582132
|
+
id: `diag-${shortHash6(fingerprint || String(index))}`,
|
|
581777
582133
|
rank: index + 1,
|
|
581778
582134
|
file,
|
|
581779
582135
|
line: diag.line,
|
|
@@ -581851,7 +582207,7 @@ function uniqueNormalizedPaths(values) {
|
|
|
581851
582207
|
function isCompileFixDiagnostic(value2) {
|
|
581852
582208
|
return Boolean(value2 && typeof value2.fingerprint === "string" && typeof value2.rank === "number");
|
|
581853
582209
|
}
|
|
581854
|
-
function
|
|
582210
|
+
function shortHash6(value2) {
|
|
581855
582211
|
return createHash32("sha256").update(value2).digest("hex").slice(0, 10);
|
|
581856
582212
|
}
|
|
581857
582213
|
function fence(value2) {
|
|
@@ -584530,10 +584886,10 @@ function classifyShellIntent(cmd) {
|
|
|
584530
584886
|
return { klass: "verify", verb: "test", tool: first2 };
|
|
584531
584887
|
}
|
|
584532
584888
|
}
|
|
584533
|
-
const
|
|
584534
|
-
if (!
|
|
584889
|
+
const row2 = VERB_TABLE[verbToken];
|
|
584890
|
+
if (!row2)
|
|
584535
584891
|
return { klass: "other", verb: verbToken, tool: first2 };
|
|
584536
|
-
return { klass:
|
|
584892
|
+
return { klass: row2.klass, verb: row2.canonical, tool: first2 };
|
|
584537
584893
|
}
|
|
584538
584894
|
function verifyShellOutcome(command, ctx3, result) {
|
|
584539
584895
|
const cmd = (command ?? "").trim();
|
|
@@ -585417,6 +585773,20 @@ function resolvePersistentMemoryMode(options2) {
|
|
|
585417
585773
|
}
|
|
585418
585774
|
return "full";
|
|
585419
585775
|
}
|
|
585776
|
+
function resolveTrajectoryCheckpointMode(explicit) {
|
|
585777
|
+
if (explicit === "off" || explicit === "shadow" || explicit === "adaptive" || explicit === "always") {
|
|
585778
|
+
return explicit;
|
|
585779
|
+
}
|
|
585780
|
+
const env2 = String(process.env["OMNIUS_TRAJECTORY_CHECKPOINT"] ?? "").trim().toLowerCase();
|
|
585781
|
+
if (env2 === "off" || env2 === "shadow" || env2 === "adaptive" || env2 === "always") {
|
|
585782
|
+
return env2;
|
|
585783
|
+
}
|
|
585784
|
+
return "adaptive";
|
|
585785
|
+
}
|
|
585786
|
+
function resolveTrajectoryCheckpointCadence(explicit) {
|
|
585787
|
+
const candidate = typeof explicit === "number" ? explicit : Number(process.env["OMNIUS_TRAJECTORY_CHECKPOINT_EVERY_TURNS"] ?? 4);
|
|
585788
|
+
return Number.isFinite(candidate) ? Math.max(1, Math.min(32, Math.floor(candidate))) : 4;
|
|
585789
|
+
}
|
|
585420
585790
|
function upsertContextFrame(messages2, frame, marker = "[ACTIVE CONTEXT FRAME]") {
|
|
585421
585791
|
for (let i2 = messages2.length - 1; i2 >= 0; i2--) {
|
|
585422
585792
|
const m2 = messages2[i2];
|
|
@@ -586153,6 +586523,7 @@ var init_agenticRunner = __esm({
|
|
|
586153
586523
|
init_context_fabric();
|
|
586154
586524
|
init_context_compiler();
|
|
586155
586525
|
init_evidenceLedger();
|
|
586526
|
+
init_trajectory_checkpoint();
|
|
586156
586527
|
init_adversaryStream();
|
|
586157
586528
|
init_contextWindowDump();
|
|
586158
586529
|
init_debugArtifactLibrary();
|
|
@@ -586272,6 +586643,15 @@ var init_agenticRunner = __esm({
|
|
|
586272
586643
|
modifiedFiles: /* @__PURE__ */ new Map(),
|
|
586273
586644
|
toolCallCount: 0
|
|
586274
586645
|
};
|
|
586646
|
+
// -- Trajectory Grounding --
|
|
586647
|
+
// A small, sanitized observation tail covers synthetic/preflight blocks that
|
|
586648
|
+
// intentionally do not enter the ordinary tool-failure accumulator.
|
|
586649
|
+
_trajectoryObservations = [];
|
|
586650
|
+
_trajectoryCheckpoint = null;
|
|
586651
|
+
_trajectoryFingerprint = "";
|
|
586652
|
+
_trajectoryRevision = 0;
|
|
586653
|
+
_trajectoryDirtyCauses = /* @__PURE__ */ new Set();
|
|
586654
|
+
_trajectoryLastEmittedToolCall = -1;
|
|
586275
586655
|
// -- File State Registry (SWE-agent inspired) --
|
|
586276
586656
|
_fileRegistry = /* @__PURE__ */ new Map();
|
|
586277
586657
|
// -- Memex Experience Archive (arXiv:2603.04257 inspired) --
|
|
@@ -587712,6 +588092,8 @@ ${parts.join("\n")}
|
|
|
587712
588092
|
backwardPassReview: options2?.backwardPassReview,
|
|
587713
588093
|
completionVerifyCommand: options2?.completionVerifyCommand,
|
|
587714
588094
|
focusSupervisor: resolveFocusSupervisorMode(options2?.focusSupervisor),
|
|
588095
|
+
trajectoryCheckpoint: resolveTrajectoryCheckpointMode(options2?.trajectoryCheckpoint),
|
|
588096
|
+
trajectoryCheckpointEveryTurns: resolveTrajectoryCheckpointCadence(options2?.trajectoryCheckpointEveryTurns),
|
|
587715
588097
|
supervisorModel: options2?.supervisorModel ?? process.env["OMNIUS_SUPERVISOR_MODEL"] ?? "",
|
|
587716
588098
|
supervisorTimeoutMs: options2?.supervisorTimeoutMs ?? Number(process.env["OMNIUS_SUPERVISOR_TIMEOUT_MS"] ?? 2e4),
|
|
587717
588099
|
supervisorMaxTokens: options2?.supervisorMaxTokens ?? 900,
|
|
@@ -592886,21 +593268,21 @@ ${sections.join("\n")}` : sections.join("\n");
|
|
|
592886
593268
|
sections.push(`Compacted historical entries: ${compactedCount}. They show what was observed earlier, not what is currently on disk. Re-run the narrow read or verifier when freshness matters.`);
|
|
592887
593269
|
}
|
|
592888
593270
|
if (filesRead.length > 0) {
|
|
592889
|
-
const
|
|
592890
|
-
sections.push(`Files already read (${
|
|
593271
|
+
const unique3 = [...new Set(filesRead)].slice(0, 30);
|
|
593272
|
+
sections.push(`Files already read (${unique3.length}): ${unique3.join(", ")}`);
|
|
592891
593273
|
}
|
|
592892
593274
|
if (dirsListed.length > 0) {
|
|
592893
|
-
const
|
|
592894
|
-
sections.push(`Directories already listed (${
|
|
593275
|
+
const unique3 = [...new Set(dirsListed)].slice(0, 15);
|
|
593276
|
+
sections.push(`Directories already listed (${unique3.length}): ${unique3.join(", ")}`);
|
|
592895
593277
|
sections.push(`Do not call list_directory again on these exact directories unless you changed their contents. Use the listed child paths directly with file_read/edit/delegation.`);
|
|
592896
593278
|
}
|
|
592897
593279
|
if (searches.length > 0) {
|
|
592898
|
-
const
|
|
592899
|
-
sections.push(`Searches already run (${
|
|
593280
|
+
const unique3 = [...new Set(searches)].slice(0, 15);
|
|
593281
|
+
sections.push(`Searches already run (${unique3.length}): ${unique3.join(", ")}`);
|
|
592900
593282
|
}
|
|
592901
593283
|
if (shells.length > 0) {
|
|
592902
|
-
const
|
|
592903
|
-
sections.push(`Shell commands already executed (${
|
|
593284
|
+
const unique3 = [...new Set(shells)].slice(0, 15);
|
|
593285
|
+
sections.push(`Shell commands already executed (${unique3.length}): ${unique3.join(", ")}`);
|
|
592904
593286
|
}
|
|
592905
593287
|
if (sections.length <= 1)
|
|
592906
593288
|
return null;
|
|
@@ -593242,6 +593624,8 @@ ${String(concreteGoal).replace(/\s+/g, " ").trim().slice(0, 1200)}` : null
|
|
|
593242
593624
|
const churnBlock = this._renderWriteChurnBlock(turn);
|
|
593243
593625
|
const focusBlock = this._focusSupervisor?.renderFrame() ?? null;
|
|
593244
593626
|
const actionContractBlock = this._renderNextActionContract(turn);
|
|
593627
|
+
const trajectoryCheckpoint = this._refreshTrajectoryCheckpoint(turn, focusBlock);
|
|
593628
|
+
const trajectoryBlock = this.options.trajectoryCheckpoint === "shadow" ? null : trajectoryCheckpoint ? renderTrajectoryCheckpoint(trajectoryCheckpoint) : null;
|
|
593245
593629
|
const toolCacheBlock = recentToolResults ? this._renderKnowledgeBlock(recentToolResults) : null;
|
|
593246
593630
|
const anchorsBlock = this.surfaceAnchors(messages2);
|
|
593247
593631
|
const pprMemoryBlock = this._lastPprMemoryLines.length > 0 ? `[Associative Memory - related prior experience]
|
|
@@ -593275,6 +593659,20 @@ ${this._lastPprMemoryLines.slice(0, 5).join("\n")}` : null;
|
|
|
593275
593659
|
priority: 100,
|
|
593276
593660
|
createdTurn: turn
|
|
593277
593661
|
}),
|
|
593662
|
+
signalFromBlock("trajectory_checkpoint", "turn.trajectory-checkpoint", trajectoryBlock, {
|
|
593663
|
+
id: "trajectory-checkpoint",
|
|
593664
|
+
dedupeKey: "turn.trajectory-checkpoint",
|
|
593665
|
+
semanticKey: "context.trajectory-checkpoint",
|
|
593666
|
+
conflictGroup: "context.trajectory-checkpoint",
|
|
593667
|
+
priority: PRIORITY.TRAJECTORY,
|
|
593668
|
+
createdTurn: turn,
|
|
593669
|
+
ttlTurns: 1,
|
|
593670
|
+
metadata: trajectoryCheckpoint ? {
|
|
593671
|
+
revision: trajectoryCheckpoint.revision,
|
|
593672
|
+
assessment: trajectoryCheckpoint.assessment,
|
|
593673
|
+
trigger: trajectoryCheckpoint.trigger
|
|
593674
|
+
} : void 0
|
|
593675
|
+
}),
|
|
593278
593676
|
signalFromBlock("known_files", "turn.files", filesystemBlock, {
|
|
593279
593677
|
id: "filesystem-state",
|
|
593280
593678
|
dedupeKey: "turn.files",
|
|
@@ -593394,6 +593792,7 @@ ${this._lastPprMemoryLines.slice(0, 5).join("\n")}` : null;
|
|
|
593394
593792
|
maxChars: 13e3,
|
|
593395
593793
|
kindCharBudget: {
|
|
593396
593794
|
known_files: 8500,
|
|
593795
|
+
trajectory_checkpoint: 1200,
|
|
593397
593796
|
runtime_guidance: 900,
|
|
593398
593797
|
recent_failure: 1400,
|
|
593399
593798
|
action_contract: 1400
|
|
@@ -594524,6 +594923,7 @@ ${notice}`;
|
|
|
594524
594923
|
/** Inject a user message into the running conversation (mid-task steering) */
|
|
594525
594924
|
injectUserMessage(content) {
|
|
594526
594925
|
this.pendingUserMessages.push(this.scrubUserInput(content, "injected-user-message"));
|
|
594926
|
+
this._trajectoryDirtyCauses.add("user_steering");
|
|
594527
594927
|
}
|
|
594528
594928
|
/** Inject bounded runtime guidance without treating it as user steering. */
|
|
594529
594929
|
injectRuntimeGuidance(content) {
|
|
@@ -594531,8 +594931,14 @@ ${notice}`;
|
|
|
594531
594931
|
}
|
|
594532
594932
|
enqueueRuntimeGuidance(content) {
|
|
594533
594933
|
const cleaned = this.scrubUserInput(content, "runtime-guidance").trim();
|
|
594534
|
-
if (cleaned)
|
|
594934
|
+
if (cleaned) {
|
|
594535
594935
|
this.pendingRuntimeGuidanceMessages.push(cleaned);
|
|
594936
|
+
this._trajectoryDirtyCauses.add("runtime_guidance");
|
|
594937
|
+
}
|
|
594938
|
+
}
|
|
594939
|
+
/** Current evidence-bound checkpoint for a UI or child-agent projection. */
|
|
594940
|
+
getTrajectoryCheckpoint() {
|
|
594941
|
+
return this._trajectoryCheckpoint;
|
|
594536
594942
|
}
|
|
594537
594943
|
/** Retract the last pending user message (Esc cancel).
|
|
594538
594944
|
* Returns the retracted text, or null if queue is empty or already consumed. */
|
|
@@ -594639,7 +595045,124 @@ ${notice}`;
|
|
|
594639
595045
|
});
|
|
594640
595046
|
return !this.aborted;
|
|
594641
595047
|
}
|
|
595048
|
+
/** Record only bounded, model-safe event summaries for the next checkpoint. */
|
|
595049
|
+
_observeTrajectoryEvent(event) {
|
|
595050
|
+
if (event.type === "trajectory_checkpoint")
|
|
595051
|
+
return;
|
|
595052
|
+
if (event.type !== "tool_call" && event.type !== "tool_result" && event.type !== "status" && event.type !== "compaction" && event.type !== "error" && event.type !== "complete" && event.type !== "user_interrupt") {
|
|
595053
|
+
return;
|
|
595054
|
+
}
|
|
595055
|
+
const content = sanitizeTrajectoryText(sanitizeModelVisibleContextText(String(event.content ?? "")), 360);
|
|
595056
|
+
const targetPath = event.toolArgs ? sanitizeTrajectoryText(this.extractPrimaryToolPath(event.toolArgs), 320) || void 0 : void 0;
|
|
595057
|
+
this._trajectoryObservations.push({
|
|
595058
|
+
type: event.type,
|
|
595059
|
+
turn: event.turn,
|
|
595060
|
+
toolName: event.toolName,
|
|
595061
|
+
targetPath,
|
|
595062
|
+
success: event.success,
|
|
595063
|
+
content,
|
|
595064
|
+
timestamp: event.timestamp
|
|
595065
|
+
});
|
|
595066
|
+
if (this._trajectoryObservations.length > 32) {
|
|
595067
|
+
this._trajectoryObservations.splice(0, this._trajectoryObservations.length - 32);
|
|
595068
|
+
}
|
|
595069
|
+
if (event.type === "tool_result") {
|
|
595070
|
+
this._trajectoryDirtyCauses.add(event.success === false ? "tool_failure" : "tool_result");
|
|
595071
|
+
} else if (event.type === "compaction") {
|
|
595072
|
+
this._trajectoryDirtyCauses.add("compaction");
|
|
595073
|
+
} else if (event.type === "error" || event.type === "user_interrupt") {
|
|
595074
|
+
this._trajectoryDirtyCauses.add(event.type);
|
|
595075
|
+
} else if (event.type === "status" && content) {
|
|
595076
|
+
if (/focus|loop|blocked|verif|mutation|sub-agent|subagent/i.test(content)) {
|
|
595077
|
+
this._trajectoryDirtyCauses.add("status_change");
|
|
595078
|
+
}
|
|
595079
|
+
}
|
|
595080
|
+
}
|
|
595081
|
+
_trajectoryEvidenceFreshness(path16) {
|
|
595082
|
+
const normalized = this._normalizeEvidencePath(path16);
|
|
595083
|
+
const entry = this._evidenceLedger.get(normalized) ?? this._evidenceLedger.get(path16);
|
|
595084
|
+
if (!entry)
|
|
595085
|
+
return "unknown";
|
|
595086
|
+
return entry.stale ? "stale" : "fresh";
|
|
595087
|
+
}
|
|
595088
|
+
/**
|
|
595089
|
+
* Rebuild the one current checkpoint at the context boundary. This shared
|
|
595090
|
+
* method is deliberately used by normal and brute-force loops via
|
|
595091
|
+
* _buildTurnContextFrame(), preventing separate prompt injections from
|
|
595092
|
+
* drifting apart or accumulating in history.
|
|
595093
|
+
*/
|
|
595094
|
+
_refreshTrajectoryCheckpoint(turn, focusDirective) {
|
|
595095
|
+
if (this.options.trajectoryCheckpoint === "off")
|
|
595096
|
+
return null;
|
|
595097
|
+
const trigger = [...this._trajectoryDirtyCauses].join(",") || (this._trajectoryCheckpoint ? "cadence" : "task_start");
|
|
595098
|
+
const provisional = buildTrajectoryCheckpoint({
|
|
595099
|
+
turn,
|
|
595100
|
+
revision: Math.max(1, this._trajectoryRevision || 1),
|
|
595101
|
+
trigger,
|
|
595102
|
+
taskState: this._taskState,
|
|
595103
|
+
observations: this._trajectoryObservations,
|
|
595104
|
+
recentFailures: this._recentFailures,
|
|
595105
|
+
focusDirective,
|
|
595106
|
+
lastVerifier: this._worldFacts.lastTest,
|
|
595107
|
+
lastMutationTurn: this._lastFileWriteTurn,
|
|
595108
|
+
evidenceFreshness: (path16) => this._trajectoryEvidenceFreshness(path16)
|
|
595109
|
+
});
|
|
595110
|
+
const { id: _id2, revision: _revision, turn: _turn, ...fingerprintInput } = provisional;
|
|
595111
|
+
const fingerprint = trajectoryCheckpointFingerprint(fingerprintInput);
|
|
595112
|
+
const changed = fingerprint !== this._trajectoryFingerprint;
|
|
595113
|
+
if (changed) {
|
|
595114
|
+
this._trajectoryRevision++;
|
|
595115
|
+
this._trajectoryFingerprint = fingerprint;
|
|
595116
|
+
}
|
|
595117
|
+
const checkpoint = buildTrajectoryCheckpoint({
|
|
595118
|
+
turn,
|
|
595119
|
+
revision: Math.max(1, this._trajectoryRevision),
|
|
595120
|
+
trigger,
|
|
595121
|
+
taskState: this._taskState,
|
|
595122
|
+
observations: this._trajectoryObservations,
|
|
595123
|
+
recentFailures: this._recentFailures,
|
|
595124
|
+
focusDirective,
|
|
595125
|
+
lastVerifier: this._worldFacts.lastTest,
|
|
595126
|
+
lastMutationTurn: this._lastFileWriteTurn,
|
|
595127
|
+
evidenceFreshness: (path16) => this._trajectoryEvidenceFreshness(path16)
|
|
595128
|
+
});
|
|
595129
|
+
this._trajectoryCheckpoint = checkpoint;
|
|
595130
|
+
const cadenceReached = this._taskState.toolCallCount - this._trajectoryLastEmittedToolCall >= this.options.trajectoryCheckpointEveryTurns;
|
|
595131
|
+
const shouldEmit = changed || this.options.trajectoryCheckpoint === "always" || this.options.trajectoryCheckpoint === "adaptive" && cadenceReached;
|
|
595132
|
+
this._trajectoryDirtyCauses.clear();
|
|
595133
|
+
if (shouldEmit) {
|
|
595134
|
+
this._trajectoryLastEmittedToolCall = this._taskState.toolCallCount;
|
|
595135
|
+
this.emit({
|
|
595136
|
+
type: "trajectory_checkpoint",
|
|
595137
|
+
content: renderTrajectoryCheckpoint(checkpoint),
|
|
595138
|
+
trajectory: checkpoint,
|
|
595139
|
+
turn,
|
|
595140
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
595141
|
+
});
|
|
595142
|
+
this._onTypedEvent?.({
|
|
595143
|
+
type: "trajectory_checkpoint",
|
|
595144
|
+
runId: this._sessionId,
|
|
595145
|
+
revision: checkpoint.revision,
|
|
595146
|
+
assessment: checkpoint.assessment,
|
|
595147
|
+
nextAction: checkpoint.nextAction,
|
|
595148
|
+
summary: `Trajectory ${checkpoint.assessment}: ${checkpoint.nextAction}`,
|
|
595149
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
595150
|
+
});
|
|
595151
|
+
try {
|
|
595152
|
+
recordDebugTrajectoryCheckpoint({
|
|
595153
|
+
cwd: this.authoritativeWorkingDirectory(),
|
|
595154
|
+
stateDir: this.omniusStateDir(),
|
|
595155
|
+
runId: this._sessionId,
|
|
595156
|
+
sessionId: this._sessionId,
|
|
595157
|
+
checkpoint
|
|
595158
|
+
});
|
|
595159
|
+
} catch {
|
|
595160
|
+
}
|
|
595161
|
+
}
|
|
595162
|
+
return checkpoint;
|
|
595163
|
+
}
|
|
594642
595164
|
emit(event) {
|
|
595165
|
+
this._observeTrajectoryEvent(event);
|
|
594643
595166
|
for (const handler of this.handlers) {
|
|
594644
595167
|
try {
|
|
594645
595168
|
handler(event);
|
|
@@ -594931,6 +595454,12 @@ Respond with your assessment, then take action.`;
|
|
|
594931
595454
|
modifiedFiles: /* @__PURE__ */ new Map(),
|
|
594932
595455
|
toolCallCount: 0
|
|
594933
595456
|
};
|
|
595457
|
+
this._trajectoryObservations = [];
|
|
595458
|
+
this._trajectoryCheckpoint = null;
|
|
595459
|
+
this._trajectoryFingerprint = "";
|
|
595460
|
+
this._trajectoryRevision = 0;
|
|
595461
|
+
this._trajectoryDirtyCauses = /* @__PURE__ */ new Set(["task_start"]);
|
|
595462
|
+
this._trajectoryLastEmittedToolCall = -1;
|
|
594934
595463
|
this._runStartTime = Date.now();
|
|
594935
595464
|
this._runErrorCount = 0;
|
|
594936
595465
|
this._runErrorPatterns = [];
|
|
@@ -602133,7 +602662,8 @@ ${caveat}` : caveat;
|
|
|
602133
602662
|
toolCallLog,
|
|
602134
602663
|
turns: consolidation.turns,
|
|
602135
602664
|
transcriptPath,
|
|
602136
|
-
artifactMode: this.options.artifactMode
|
|
602665
|
+
artifactMode: this.options.artifactMode,
|
|
602666
|
+
trajectory: this._trajectoryCheckpoint
|
|
602137
602667
|
});
|
|
602138
602668
|
if (!shouldPersistTaskHandoff(handoff))
|
|
602139
602669
|
throw "skip-low-quality-handoff";
|
|
@@ -609578,6 +610108,18 @@ function legacyAgenticEventToRunEvent(runId, event) {
|
|
|
609578
610108
|
timestamp
|
|
609579
610109
|
};
|
|
609580
610110
|
}
|
|
610111
|
+
if (event.type === "trajectory_checkpoint") {
|
|
610112
|
+
const trajectory = event["trajectory"] && typeof event["trajectory"] === "object" ? event["trajectory"] : void 0;
|
|
610113
|
+
return {
|
|
610114
|
+
type: "trajectory_checkpoint",
|
|
610115
|
+
runId,
|
|
610116
|
+
...typeof trajectory?.["revision"] === "number" ? { revision: trajectory["revision"] } : {},
|
|
610117
|
+
...typeof trajectory?.["assessment"] === "string" ? { assessment: text(trajectory["assessment"], 80) } : {},
|
|
610118
|
+
...typeof trajectory?.["nextAction"] === "string" ? { nextAction: text(trajectory["nextAction"], 500) } : {},
|
|
610119
|
+
summary: text(event.content, 900),
|
|
610120
|
+
timestamp
|
|
610121
|
+
};
|
|
610122
|
+
}
|
|
609581
610123
|
if (event.type === "complete") {
|
|
609582
610124
|
const success = event.success === true;
|
|
609583
610125
|
return {
|
|
@@ -611716,10 +612258,10 @@ function buildAgentNotification(task) {
|
|
|
611716
612258
|
` <status>${task.status}</status>`
|
|
611717
612259
|
];
|
|
611718
612260
|
if (task.result) {
|
|
611719
|
-
lines.push(` <summary>${escapeXml(
|
|
612261
|
+
lines.push(` <summary>${escapeXml(truncate2(task.result, 500))}</summary>`);
|
|
611720
612262
|
}
|
|
611721
612263
|
if (task.error) {
|
|
611722
|
-
lines.push(` <error>${escapeXml(
|
|
612264
|
+
lines.push(` <error>${escapeXml(truncate2(task.error, 300))}</error>`);
|
|
611723
612265
|
}
|
|
611724
612266
|
lines.push(` <tool-uses>${task.progress.toolUseCount}</tool-uses>`);
|
|
611725
612267
|
lines.push(` <turns>${task.progress.turnsCompleted}</turns>`);
|
|
@@ -611736,7 +612278,7 @@ function buildAgentNotification(task) {
|
|
|
611736
612278
|
function escapeXml(s2) {
|
|
611737
612279
|
return s2.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
611738
612280
|
}
|
|
611739
|
-
function
|
|
612281
|
+
function truncate2(s2, maxLen) {
|
|
611740
612282
|
if (s2.length <= maxLen)
|
|
611741
612283
|
return s2;
|
|
611742
612284
|
return s2.slice(0, maxLen - 3) + "...";
|
|
@@ -615092,6 +615634,9 @@ function buildSubAgentSystemPrompt(type, scenario) {
|
|
|
615092
615634
|
if (focus.length) {
|
|
615093
615635
|
out.push(`## Focus`, ...focus, "");
|
|
615094
615636
|
}
|
|
615637
|
+
const trajectory = renderScopedTrajectoryCheckpoint(scenario.trajectory);
|
|
615638
|
+
if (trajectory)
|
|
615639
|
+
out.push(trajectory, "");
|
|
615095
615640
|
const exit = scenario.exitCriterion ?? (p2.mutates ? "Your change is verified by a passing build/test observation." : "You have produced the requested read-only result with evidence.");
|
|
615096
615641
|
out.push(`## Done When`, exit, "");
|
|
615097
615642
|
out.push(`## Constraints`);
|
|
@@ -615104,6 +615649,7 @@ var WORKER_PREAMBLE, PURPOSES;
|
|
|
615104
615649
|
var init_subagent_prompt = __esm({
|
|
615105
615650
|
"packages/orchestrator/dist/subagent-prompt.js"() {
|
|
615106
615651
|
"use strict";
|
|
615652
|
+
init_trajectory_checkpoint();
|
|
615107
615653
|
WORKER_PREAMBLE = [
|
|
615108
615654
|
"You are an isolated sub-agent with a deliberately small context and a single,",
|
|
615109
615655
|
"bounded purpose. You were spawned by an orchestrator that holds the overall",
|
|
@@ -615288,6 +615834,7 @@ __export(dist_exports3, {
|
|
|
615288
615834
|
buildSkillDescription: () => buildSkillDescription,
|
|
615289
615835
|
buildSteeringPacket: () => buildSteeringPacket,
|
|
615290
615836
|
buildSubAgentSystemPrompt: () => buildSubAgentSystemPrompt,
|
|
615837
|
+
buildTrajectoryCheckpoint: () => buildTrajectoryCheckpoint,
|
|
615291
615838
|
buildUnitTodos: () => buildUnitTodos,
|
|
615292
615839
|
checkMilestoneComplete: () => checkMilestoneComplete,
|
|
615293
615840
|
chooseCheapModelRoute: () => chooseCheapModelRoute,
|
|
@@ -615463,6 +616010,7 @@ __export(dist_exports3, {
|
|
|
615463
616010
|
recordContextWindowDump: () => recordContextWindowDump,
|
|
615464
616011
|
recordDebugContextWindowDump: () => recordDebugContextWindowDump,
|
|
615465
616012
|
recordDebugToolEvent: () => recordDebugToolEvent,
|
|
616013
|
+
recordDebugTrajectoryCheckpoint: () => recordDebugTrajectoryCheckpoint,
|
|
615466
616014
|
recordHookExecution: () => recordHookExecution,
|
|
615467
616015
|
recordTokenUsage: () => recordTokenUsage,
|
|
615468
616016
|
recordToolDecision: () => recordToolDecision,
|
|
@@ -615477,6 +616025,8 @@ __export(dist_exports3, {
|
|
|
615477
616025
|
reinforcementScore: () => reinforcementScore,
|
|
615478
616026
|
renderGitProgressActionContract: () => renderGitProgressActionContract,
|
|
615479
616027
|
renderGitProgressContextBlock: () => renderGitProgressContextBlock,
|
|
616028
|
+
renderScopedTrajectoryCheckpoint: () => renderScopedTrajectoryCheckpoint,
|
|
616029
|
+
renderTrajectoryCheckpoint: () => renderTrajectoryCheckpoint,
|
|
615480
616030
|
renderValidationContract: () => renderValidationContract,
|
|
615481
616031
|
renderWorkerSkill: () => renderWorkerSkill,
|
|
615482
616032
|
requestApproval: () => requestApproval,
|
|
@@ -615489,12 +616039,14 @@ __export(dist_exports3, {
|
|
|
615489
616039
|
retentionStrength: () => retentionStrength,
|
|
615490
616040
|
runFeatureNode: () => runFeatureNode,
|
|
615491
616041
|
sanitizeInvisibleUnicode: () => sanitizeInvisibleUnicode,
|
|
616042
|
+
sanitizeTrajectoryText: () => sanitizeTrajectoryText,
|
|
615492
616043
|
saveCompletionLedger: () => saveCompletionLedger,
|
|
615493
616044
|
saveFeatureTree: () => saveFeatureTree,
|
|
615494
616045
|
saveStabilityIndex: () => saveStabilityIndex,
|
|
615495
616046
|
scanContextContent: () => scanContextContent,
|
|
615496
616047
|
scanDuplicateDefinitions: () => scanDuplicateDefinitions,
|
|
615497
616048
|
scanOllamaProcesses: () => scanOllamaProcesses,
|
|
616049
|
+
scopeTrajectoryCheckpoint: () => scopeTrajectoryCheckpoint,
|
|
615498
616050
|
scoreHandoff: () => scoreHandoff,
|
|
615499
616051
|
scoreMemoryItem: () => scoreMemoryItem,
|
|
615500
616052
|
scoreMemoryItems: () => scoreMemoryItems,
|
|
@@ -615516,6 +616068,7 @@ __export(dist_exports3, {
|
|
|
615516
616068
|
summarizeGitProgressForTrajectory: () => summarizeGitProgressForTrajectory,
|
|
615517
616069
|
tierForWeight: () => tierForWeight,
|
|
615518
616070
|
toSnrDb: () => toSnrDb,
|
|
616071
|
+
trajectoryCheckpointFingerprint: () => trajectoryCheckpointFingerprint,
|
|
615519
616072
|
truncateContent: () => truncateContent,
|
|
615520
616073
|
updateAssertionResult: () => updateAssertionResult,
|
|
615521
616074
|
updateMemoryStability: () => updateMemoryStability,
|
|
@@ -615617,6 +616170,7 @@ var init_dist8 = __esm({
|
|
|
615617
616170
|
init_domainDetector();
|
|
615618
616171
|
init_decomposition_orchestrator();
|
|
615619
616172
|
init_subagent_prompt();
|
|
616173
|
+
init_trajectory_checkpoint();
|
|
615620
616174
|
init_contextBudget();
|
|
615621
616175
|
}
|
|
615622
616176
|
});
|
|
@@ -616365,10 +616919,10 @@ function stringifyImageAsciiMatrix(matrix) {
|
|
|
616365
616919
|
const displayLines = [];
|
|
616366
616920
|
const plainLines = [];
|
|
616367
616921
|
for (const rowUnknown of rows) {
|
|
616368
|
-
const
|
|
616922
|
+
const row2 = Array.isArray(rowUnknown) ? rowUnknown : [];
|
|
616369
616923
|
let displayLine = "";
|
|
616370
616924
|
let plainLine = "";
|
|
616371
|
-
for (const cell of
|
|
616925
|
+
for (const cell of row2) {
|
|
616372
616926
|
const pixel = matrixPixel(cell);
|
|
616373
616927
|
displayLine += `\x1B[38;2;${pixel.r};${pixel.g};${pixel.b}m${IMAGE_ASCII_BLOCK}\x1B[0m`;
|
|
616374
616928
|
const idx = Math.round(pixel.value / 255 * (DEFAULT_PIXELS.length - 1));
|
|
@@ -616403,8 +616957,8 @@ function isLowInformationAsciiPreview(ascii2) {
|
|
|
616403
616957
|
if (!plain) return true;
|
|
616404
616958
|
const visible = plain.replace(/\s/g, "");
|
|
616405
616959
|
if (visible.length < 12) return true;
|
|
616406
|
-
const
|
|
616407
|
-
if (
|
|
616960
|
+
const unique3 = new Set(Array.from(visible));
|
|
616961
|
+
if (unique3.size <= 2 && /[█▓▒░#@]/u.test(visible)) return true;
|
|
616408
616962
|
return false;
|
|
616409
616963
|
}
|
|
616410
616964
|
function previewFailure(message2, width) {
|
|
@@ -620392,8 +620946,8 @@ function formatLiveDashboardFromSnapshot(snapshot, opts = {}) {
|
|
|
620392
620946
|
const paneContentWidth = Math.max(10, paneWidth - 2);
|
|
620393
620947
|
const sourceLines = dashboardPreviewLines(maximized);
|
|
620394
620948
|
const paneHeight = cameraPaneTargetHeight(maximized, sourceLines, paneContentWidth, { maxHeight: 60 });
|
|
620395
|
-
for (const
|
|
620396
|
-
lines.push(`│${truncateAnsiCell(
|
|
620949
|
+
for (const row2 of formatCameraPane(maximized, paneWidth, paneHeight, now2)) {
|
|
620950
|
+
lines.push(`│${truncateAnsiCell(row2, innerWidth)}│`);
|
|
620397
620951
|
}
|
|
620398
620952
|
} else {
|
|
620399
620953
|
const { innerWidth, paneCount, paneWidth } = liveDashboardPaneLayout(width, cameras.length);
|
|
@@ -620405,8 +620959,8 @@ function formatLiveDashboardFromSnapshot(snapshot, opts = {}) {
|
|
|
620405
620959
|
return formatCameraPane(camera, paneWidth, paneHeight, now2);
|
|
620406
620960
|
});
|
|
620407
620961
|
const rowCount = Math.max(...panes.map((pane) => pane.length));
|
|
620408
|
-
for (let
|
|
620409
|
-
const body = panes.map((pane) => pane[
|
|
620962
|
+
for (let row2 = 0; row2 < rowCount; row2++) {
|
|
620963
|
+
const body = panes.map((pane) => pane[row2] ?? " ".repeat(paneWidth)).join(" ");
|
|
620410
620964
|
lines.push(`│${truncateAnsiCell(body, innerWidth)}│`);
|
|
620411
620965
|
}
|
|
620412
620966
|
}
|
|
@@ -620465,8 +621019,8 @@ function formatLiveDashboardFromSnapshot(snapshot, opts = {}) {
|
|
|
620465
621019
|
for (const item of audioBits.slice(0, 11)) pushDashboardWrapped(lines, item, width);
|
|
620466
621020
|
if (asr.waterfall.length > 0) {
|
|
620467
621021
|
lines.push(`│${truncateAnsiCell(` ├─ speech waterfall ${dashboardDim("blue quiet → red loud")}`, width - 2)}│`);
|
|
620468
|
-
for (const
|
|
620469
|
-
lines.push(`│${truncateAnsiCell(` │ ${
|
|
621022
|
+
for (const row2 of asr.waterfall.slice(-8)) {
|
|
621023
|
+
lines.push(`│${truncateAnsiCell(` │ ${row2}`, width - 2)}│`);
|
|
620470
621024
|
}
|
|
620471
621025
|
}
|
|
620472
621026
|
if (coloredSoundSummary) {
|
|
@@ -628812,12 +629366,12 @@ function setUpdateBadgeRegion(active, startCol, length4) {
|
|
|
628812
629366
|
_updateBadgeCol = startCol;
|
|
628813
629367
|
_updateBadgeLen = length4;
|
|
628814
629368
|
}
|
|
628815
|
-
function hitTestHeaderButton(
|
|
628816
|
-
if (_updateBadgeActive &&
|
|
629369
|
+
function hitTestHeaderButton(row2, col, termWidth) {
|
|
629370
|
+
if (_updateBadgeActive && row2 === 1 && col >= _updateBadgeCol && col < _updateBadgeCol + _updateBadgeLen) {
|
|
628817
629371
|
return "/update";
|
|
628818
629372
|
}
|
|
628819
629373
|
const hdrRow = layout().headerContent;
|
|
628820
|
-
if (
|
|
629374
|
+
if (row2 === hdrRow) {
|
|
628821
629375
|
if (col <= 3) return "header-prev";
|
|
628822
629376
|
if (col >= termWidth - 3) return "header-next";
|
|
628823
629377
|
const btnDefs = [
|
|
@@ -628881,12 +629435,12 @@ var init_text_selection = __esm({
|
|
|
628881
629435
|
* Handle mouse press (button 0, M suffix in SGR).
|
|
628882
629436
|
* Starts a new selection from the click position.
|
|
628883
629437
|
*/
|
|
628884
|
-
onMousePress(
|
|
629438
|
+
onMousePress(row2, col) {
|
|
628885
629439
|
const mode = this._blockModeArmed ? "block" : "line";
|
|
628886
629440
|
this._blockModeArmed = false;
|
|
628887
629441
|
this._selection = {
|
|
628888
|
-
anchor: { row, col },
|
|
628889
|
-
current: { row, col },
|
|
629442
|
+
anchor: { row: row2, col },
|
|
629443
|
+
current: { row: row2, col },
|
|
628890
629444
|
mode
|
|
628891
629445
|
};
|
|
628892
629446
|
this._active = true;
|
|
@@ -628895,17 +629449,17 @@ var init_text_selection = __esm({
|
|
|
628895
629449
|
* Handle mouse drag (button 32, M suffix in SGR).
|
|
628896
629450
|
* Extends the selection to the current cursor position.
|
|
628897
629451
|
*/
|
|
628898
|
-
onMouseDrag(
|
|
629452
|
+
onMouseDrag(row2, col) {
|
|
628899
629453
|
if (!this._active || !this._selection) return;
|
|
628900
|
-
this._selection.current = { row, col };
|
|
629454
|
+
this._selection.current = { row: row2, col };
|
|
628901
629455
|
}
|
|
628902
629456
|
/**
|
|
628903
629457
|
* Handle mouse release (button 0, m suffix in SGR).
|
|
628904
629458
|
* Finalizes the selection.
|
|
628905
629459
|
*/
|
|
628906
|
-
onMouseRelease(
|
|
629460
|
+
onMouseRelease(row2, col) {
|
|
628907
629461
|
if (!this._active || !this._selection) return;
|
|
628908
|
-
this._selection.current = { row, col };
|
|
629462
|
+
this._selection.current = { row: row2, col };
|
|
628909
629463
|
this._active = false;
|
|
628910
629464
|
if (this._selection.anchor.row === this._selection.current.row && this._selection.anchor.col === this._selection.current.col) {
|
|
628911
629465
|
this._selection = null;
|
|
@@ -631390,7 +631944,7 @@ function renderToolDynamicBlock(kind, render2, opts, collapse, persistedSpec) {
|
|
|
631390
631944
|
function breakTelegramCoalesce() {
|
|
631391
631945
|
_telegramCoalesce = null;
|
|
631392
631946
|
}
|
|
631393
|
-
function renderTelegramCoalescedRow(
|
|
631947
|
+
function renderTelegramCoalescedRow(row2, opts) {
|
|
631394
631948
|
const colorCode = opts?.colorCode ?? 45;
|
|
631395
631949
|
const title = opts?.title ?? "✈ Telegram";
|
|
631396
631950
|
const redir = _contentWriteHook?.redirect?.();
|
|
@@ -631403,7 +631957,7 @@ function renderTelegramCoalescedRow(row, opts) {
|
|
|
631403
631957
|
{
|
|
631404
631958
|
title,
|
|
631405
631959
|
metrics: "",
|
|
631406
|
-
body: [{ text:
|
|
631960
|
+
body: [{ text: row2, mode: "wrap", kind: "plain" }],
|
|
631407
631961
|
colorCode
|
|
631408
631962
|
},
|
|
631409
631963
|
width
|
|
@@ -631413,12 +631967,12 @@ function renderTelegramCoalescedRow(row, opts) {
|
|
|
631413
631967
|
return;
|
|
631414
631968
|
}
|
|
631415
631969
|
if (_telegramCoalesce) {
|
|
631416
|
-
_telegramCoalesce.lines.push(
|
|
631970
|
+
_telegramCoalesce.lines.push(row2);
|
|
631417
631971
|
host.refreshDynamicBlocks();
|
|
631418
631972
|
return;
|
|
631419
631973
|
}
|
|
631420
631974
|
const id2 = `tg-coalesce-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
631421
|
-
const state = { id: id2, lines: [
|
|
631975
|
+
const state = { id: id2, lines: [row2], colorCode };
|
|
631422
631976
|
_telegramCoalesce = state;
|
|
631423
631977
|
host.registerDynamicBlock(
|
|
631424
631978
|
id2,
|
|
@@ -631441,14 +631995,14 @@ function renderTelegramCoalescedRow(row, opts) {
|
|
|
631441
631995
|
function breakVoiceChatCoalesce() {
|
|
631442
631996
|
_voiceChatCoalesce = null;
|
|
631443
631997
|
}
|
|
631444
|
-
function renderVoiceChatCoalescedRow(
|
|
631998
|
+
function renderVoiceChatCoalescedRow(row2, opts) {
|
|
631445
631999
|
const colorCode = opts?.colorCode ?? 45;
|
|
631446
632000
|
const title = opts?.title ?? "☏ VoiceChat";
|
|
631447
632001
|
const redir = _contentWriteHook?.redirect?.();
|
|
631448
632002
|
const host = _contentWriteHook?.dynamicBlockHost?.() ?? null;
|
|
631449
632003
|
if (redir || !host || typeof host.refreshDynamicBlocks !== "function") {
|
|
631450
632004
|
_voiceChatCoalesce = null;
|
|
631451
|
-
const text2 = `${
|
|
632005
|
+
const text2 = `${row2}
|
|
631452
632006
|
`;
|
|
631453
632007
|
if (redir) redir(text2);
|
|
631454
632008
|
else process.stdout.write(text2);
|
|
@@ -631458,15 +632012,15 @@ function renderVoiceChatCoalescedRow(row, opts) {
|
|
|
631458
632012
|
const replacePrefix = opts?.replaceLastPrefix;
|
|
631459
632013
|
const lastIndex = _voiceChatCoalesce.rows.length - 1;
|
|
631460
632014
|
if (replacePrefix && lastIndex >= 0 && _voiceChatCoalesce.rows[lastIndex]?.startsWith(replacePrefix)) {
|
|
631461
|
-
_voiceChatCoalesce.rows[lastIndex] =
|
|
632015
|
+
_voiceChatCoalesce.rows[lastIndex] = row2;
|
|
631462
632016
|
} else {
|
|
631463
|
-
_voiceChatCoalesce.rows.push(
|
|
632017
|
+
_voiceChatCoalesce.rows.push(row2);
|
|
631464
632018
|
}
|
|
631465
632019
|
host.refreshDynamicBlocks();
|
|
631466
632020
|
return;
|
|
631467
632021
|
}
|
|
631468
632022
|
const id2 = `voicechat-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
631469
|
-
const state = { id: id2, rows: [
|
|
632023
|
+
const state = { id: id2, rows: [row2], expanded: false, colorCode };
|
|
631470
632024
|
_voiceChatCoalesce = state;
|
|
631471
632025
|
host.registerDynamicBlock(id2, (width) => {
|
|
631472
632026
|
const visible = state.expanded ? state.rows : state.rows.slice(-VOICECHAT_VISIBLE_ROWS);
|
|
@@ -638972,6 +639526,17 @@ function buildHandoffPrompt(repoRoot) {
|
|
|
638972
639526
|
}
|
|
638973
639527
|
lines.push("");
|
|
638974
639528
|
}
|
|
639529
|
+
if (handoff.trajectory) {
|
|
639530
|
+
const trajectory = handoff.trajectory;
|
|
639531
|
+
lines.push("### Prior Trajectory (stale orientation — verify before acting):");
|
|
639532
|
+
lines.push(`- Assessment: ${trajectory.assessment}`);
|
|
639533
|
+
lines.push(`- Next: ${trajectory.nextAction}`);
|
|
639534
|
+
lines.push(`- Success evidence: ${trajectory.successEvidence}`);
|
|
639535
|
+
if (trajectory.doNotRepeat.length > 0) {
|
|
639536
|
+
lines.push(`- Guard: ${trajectory.doNotRepeat.slice(0, 3).join("; ")}`);
|
|
639537
|
+
}
|
|
639538
|
+
lines.push("");
|
|
639539
|
+
}
|
|
638975
639540
|
if (handoff.memories.length > 0) {
|
|
638976
639541
|
lines.push("### Memories Used:");
|
|
638977
639542
|
for (const m2 of handoff.memories.slice(0, 3)) {
|
|
@@ -639312,6 +639877,17 @@ function renderSessionDiary(entries) {
|
|
|
639312
639877
|
const summary = e2.summary.replace(/\s+/g, " ").trim().slice(0, 280);
|
|
639313
639878
|
lines.push(`- **Summary:** ${summary}`);
|
|
639314
639879
|
}
|
|
639880
|
+
if (e2.trajectory) {
|
|
639881
|
+
const trajectory = e2.trajectory;
|
|
639882
|
+
lines.push(
|
|
639883
|
+
`- **Trajectory:** ${trajectory.assessment} — next: ${trajectory.nextAction.replace(/\s+/g, " ").trim().slice(0, 220)}`
|
|
639884
|
+
);
|
|
639885
|
+
if (trajectory.doNotRepeat.length > 0) {
|
|
639886
|
+
lines.push(
|
|
639887
|
+
`- **Trajectory guard:** ${trajectory.doNotRepeat[0].replace(/\s+/g, " ").trim().slice(0, 220)}`
|
|
639888
|
+
);
|
|
639889
|
+
}
|
|
639890
|
+
}
|
|
639315
639891
|
lines.push("");
|
|
639316
639892
|
}
|
|
639317
639893
|
while (lines.length > 1 && lines[lines.length - 1] === "") lines.pop();
|
|
@@ -640989,6 +641565,17 @@ function stageForAgentEvent(event) {
|
|
|
640989
641565
|
return { stage: "compacting" };
|
|
640990
641566
|
case "debug_adversary":
|
|
640991
641567
|
return { stage: "adversary_audit" };
|
|
641568
|
+
case "trajectory_checkpoint":
|
|
641569
|
+
if (/verification_due/i.test(event.content ?? "")) {
|
|
641570
|
+
return { stage: "verifying", detail: "trajectory" };
|
|
641571
|
+
}
|
|
641572
|
+
if (/\bblocked\b/i.test(event.content ?? "")) {
|
|
641573
|
+
return { stage: "failed", detail: "trajectory" };
|
|
641574
|
+
}
|
|
641575
|
+
if (/recovery_required/i.test(event.content ?? "")) {
|
|
641576
|
+
return { stage: "blocked", detail: "trajectory" };
|
|
641577
|
+
}
|
|
641578
|
+
return { stage: "planning", detail: "trajectory" };
|
|
640992
641579
|
case "complete":
|
|
640993
641580
|
return { stage: "completed", detail: "done" };
|
|
640994
641581
|
case "error":
|
|
@@ -641297,6 +641884,116 @@ var init_sub_agent_live_block = __esm({
|
|
|
641297
641884
|
}
|
|
641298
641885
|
});
|
|
641299
641886
|
|
|
641887
|
+
// packages/cli/src/tui/trajectory-live-block.ts
|
|
641888
|
+
function trajectoryStage(checkpoint) {
|
|
641889
|
+
switch (checkpoint.assessment) {
|
|
641890
|
+
case "recovery_required":
|
|
641891
|
+
return "blocked";
|
|
641892
|
+
case "verification_due":
|
|
641893
|
+
return "verifying";
|
|
641894
|
+
case "blocked":
|
|
641895
|
+
return "failed";
|
|
641896
|
+
default:
|
|
641897
|
+
return "planning";
|
|
641898
|
+
}
|
|
641899
|
+
}
|
|
641900
|
+
function buildTrajectoryLiveBlockLines(checkpoint, width, phase, truecolor = supportsTruecolor()) {
|
|
641901
|
+
if (!checkpoint) return [];
|
|
641902
|
+
const w = Math.max(48, Math.floor(width));
|
|
641903
|
+
const inner = Math.max(1, w - 4);
|
|
641904
|
+
const stage2 = trajectoryStage(checkpoint);
|
|
641905
|
+
const title = ` Trajectory · ${checkpoint.assessment.replace(/_/g, " ")} `;
|
|
641906
|
+
const top = `╭─┤${title}├${"─".repeat(Math.max(0, w - 5 - title.length))}╮`;
|
|
641907
|
+
const bottom = `╰${"─".repeat(Math.max(0, w - 2))}╯`;
|
|
641908
|
+
const lines = [paint2(top, stage2, phase, 0, truecolor)];
|
|
641909
|
+
lines.push(row(`Goal: ${checkpoint.goal}`, inner, stage2, phase, truecolor));
|
|
641910
|
+
lines.push(
|
|
641911
|
+
row(
|
|
641912
|
+
`Next: ${checkpoint.nextAction}`,
|
|
641913
|
+
inner,
|
|
641914
|
+
stage2,
|
|
641915
|
+
phase,
|
|
641916
|
+
truecolor
|
|
641917
|
+
)
|
|
641918
|
+
);
|
|
641919
|
+
lines.push(
|
|
641920
|
+
row(
|
|
641921
|
+
`Proof: ${checkpoint.successEvidence}`,
|
|
641922
|
+
inner,
|
|
641923
|
+
stage2,
|
|
641924
|
+
phase,
|
|
641925
|
+
truecolor
|
|
641926
|
+
)
|
|
641927
|
+
);
|
|
641928
|
+
const guard = checkpoint.doNotRepeat[0] ?? checkpoint.openQuestions[0];
|
|
641929
|
+
if (guard) {
|
|
641930
|
+
lines.push(
|
|
641931
|
+
row(
|
|
641932
|
+
`Guard: ${guard}`,
|
|
641933
|
+
inner,
|
|
641934
|
+
stage2,
|
|
641935
|
+
phase,
|
|
641936
|
+
truecolor
|
|
641937
|
+
)
|
|
641938
|
+
);
|
|
641939
|
+
}
|
|
641940
|
+
const fact = checkpoint.groundedFacts[0];
|
|
641941
|
+
if (fact) {
|
|
641942
|
+
lines.push(
|
|
641943
|
+
row(
|
|
641944
|
+
`Evidence: ${fact.statement}`,
|
|
641945
|
+
inner,
|
|
641946
|
+
stage2,
|
|
641947
|
+
phase,
|
|
641948
|
+
truecolor
|
|
641949
|
+
)
|
|
641950
|
+
);
|
|
641951
|
+
}
|
|
641952
|
+
lines.push(paint2(bottom, stage2, phase, 0, truecolor));
|
|
641953
|
+
return lines;
|
|
641954
|
+
}
|
|
641955
|
+
function buildTrajectoryLiveBlockCollapsedLine(checkpoint, width, phase, truecolor = supportsTruecolor()) {
|
|
641956
|
+
if (!checkpoint) return [];
|
|
641957
|
+
const stage2 = trajectoryStage(checkpoint);
|
|
641958
|
+
const w = Math.max(24, Math.floor(width));
|
|
641959
|
+
const text2 = fit3(
|
|
641960
|
+
`▸ Trajectory · ${checkpoint.assessment.replace(/_/g, " ")} · ${checkpoint.nextAction}`,
|
|
641961
|
+
w
|
|
641962
|
+
);
|
|
641963
|
+
return [paint2(text2, stage2, phase, 0, truecolor)];
|
|
641964
|
+
}
|
|
641965
|
+
function row(value2, width, stage2, phase, truecolor) {
|
|
641966
|
+
return `│ ${paint2(fit3(value2, width), stage2, phase, 1, truecolor)} │`;
|
|
641967
|
+
}
|
|
641968
|
+
function paint2(value2, stage2, phase, offset, truecolor) {
|
|
641969
|
+
let out = "";
|
|
641970
|
+
for (const [index, char] of Array.from(value2).entries()) {
|
|
641971
|
+
if (truecolor) {
|
|
641972
|
+
const [r2, g, b] = stageGradientRgb(stage2, index + offset, phase);
|
|
641973
|
+
out += `\x1B[38;2;${r2};${g};${b}m${char}`;
|
|
641974
|
+
} else {
|
|
641975
|
+
out += `\x1B[38;5;${stageFallbackColor(stage2)}m${char}`;
|
|
641976
|
+
}
|
|
641977
|
+
}
|
|
641978
|
+
return `${out}\x1B[0m`;
|
|
641979
|
+
}
|
|
641980
|
+
function fit3(value2, width) {
|
|
641981
|
+
const clean5 = value2.replace(ANSI_RE3, "").replace(/\s+/g, " ").trim();
|
|
641982
|
+
const chars = Array.from(clean5);
|
|
641983
|
+
if (chars.length > width) {
|
|
641984
|
+
return `${chars.slice(0, Math.max(0, width - 1)).join("")}…`;
|
|
641985
|
+
}
|
|
641986
|
+
return clean5 + " ".repeat(Math.max(0, width - chars.length));
|
|
641987
|
+
}
|
|
641988
|
+
var ANSI_RE3;
|
|
641989
|
+
var init_trajectory_live_block = __esm({
|
|
641990
|
+
"packages/cli/src/tui/trajectory-live-block.ts"() {
|
|
641991
|
+
init_stageIndicator();
|
|
641992
|
+
init_sub_agent_live_block();
|
|
641993
|
+
ANSI_RE3 = /\x1B\[[0-?]*[ -/]*[@-~]|\x1B\].*?(?:\x07|\x1B\\)/g;
|
|
641994
|
+
}
|
|
641995
|
+
});
|
|
641996
|
+
|
|
641300
641997
|
// packages/cli/src/tui/tui-tasks-renderer.ts
|
|
641301
641998
|
var tui_tasks_renderer_exports = {};
|
|
641302
641999
|
__export(tui_tasks_renderer_exports, {
|
|
@@ -641525,7 +642222,7 @@ function statusToAnsi(status) {
|
|
|
641525
642222
|
return { mark: "○", color: PENDING };
|
|
641526
642223
|
}
|
|
641527
642224
|
}
|
|
641528
|
-
function
|
|
642225
|
+
function truncate3(s2, max) {
|
|
641529
642226
|
if (s2.length <= max) return s2.padEnd(max, " ");
|
|
641530
642227
|
return s2.slice(0, Math.max(0, max - 1)) + "…";
|
|
641531
642228
|
}
|
|
@@ -641795,7 +642492,7 @@ function render(options2 = {}) {
|
|
|
641795
642492
|
const { mark, color } = statusToAnsi(t2.displayStatus);
|
|
641796
642493
|
const contentWidth = Math.max(4, cols - 8);
|
|
641797
642494
|
const contentText = formatTodoContent(t2, activeId);
|
|
641798
|
-
const truncated =
|
|
642495
|
+
const truncated = truncate3(contentText, contentWidth);
|
|
641799
642496
|
if (activeId && t2.id === activeId) {
|
|
641800
642497
|
const grad = paintActiveRowGradient(truncated);
|
|
641801
642498
|
if (grad) {
|
|
@@ -641819,16 +642516,16 @@ function render(options2 = {}) {
|
|
|
641819
642516
|
const safeClearTop = L.headerBottom + 1;
|
|
641820
642517
|
const safeClearBottom = L.contentBottom;
|
|
641821
642518
|
if (_lastPaintedTop >= 0 && _lastPaintedBottom >= _lastPaintedTop) {
|
|
641822
|
-
for (let
|
|
641823
|
-
if (
|
|
641824
|
-
if (
|
|
641825
|
-
out += `\x1B[${
|
|
642519
|
+
for (let row2 = _lastPaintedTop; row2 <= _lastPaintedBottom; row2++) {
|
|
642520
|
+
if (row2 >= newTop && row2 <= newBottom) continue;
|
|
642521
|
+
if (row2 < safeClearTop || row2 > safeClearBottom) continue;
|
|
642522
|
+
out += `\x1B[${row2};1H${CLEAR_LINE}`;
|
|
641826
642523
|
}
|
|
641827
642524
|
}
|
|
641828
642525
|
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
641829
|
-
const
|
|
641830
|
-
if (
|
|
641831
|
-
out += `\x1B[${
|
|
642526
|
+
const row2 = L.tasksTop + i2;
|
|
642527
|
+
if (row2 > L.tasksBottom) break;
|
|
642528
|
+
out += `\x1B[${row2};1H${CLEAR_LINE}${BG}${" ".repeat(cols)}\x1B[${row2};2H${lines[i2]}${RESET3}`;
|
|
641832
642529
|
}
|
|
641833
642530
|
out += RESTORE + SHOW;
|
|
641834
642531
|
try {
|
|
@@ -641839,9 +642536,9 @@ function render(options2 = {}) {
|
|
|
641839
642536
|
_lastPaintedBottom = newBottom;
|
|
641840
642537
|
_toggleRowAbs = toggleLineIdx >= 0 && L.tasksTop + toggleLineIdx <= L.tasksBottom ? L.tasksTop + toggleLineIdx : -1;
|
|
641841
642538
|
}
|
|
641842
|
-
function handleTuiTasksClick(
|
|
642539
|
+
function handleTuiTasksClick(row2) {
|
|
641843
642540
|
if (!panelEffectivelyVisible()) return false;
|
|
641844
|
-
if (_toggleRowAbs < 0 ||
|
|
642541
|
+
if (_toggleRowAbs < 0 || row2 !== _toggleRowAbs) return false;
|
|
641845
642542
|
_expanded = !_expanded;
|
|
641846
642543
|
loadTodos();
|
|
641847
642544
|
render();
|
|
@@ -641856,9 +642553,9 @@ function clearLastPaintedRows() {
|
|
|
641856
642553
|
const safeTop = L.headerBottom + 1;
|
|
641857
642554
|
const safeBottom = Math.max(L.contentBottom, safeTop - 1);
|
|
641858
642555
|
let out = HIDE + SAVE;
|
|
641859
|
-
for (let
|
|
641860
|
-
if (
|
|
641861
|
-
out += `\x1B[${
|
|
642556
|
+
for (let row2 = _lastPaintedTop; row2 <= _lastPaintedBottom; row2++) {
|
|
642557
|
+
if (row2 < safeTop || row2 > safeBottom) continue;
|
|
642558
|
+
out += `\x1B[${row2};1H${CLEAR_LINE}`;
|
|
641862
642559
|
}
|
|
641863
642560
|
out += RESTORE + SHOW;
|
|
641864
642561
|
try {
|
|
@@ -642963,14 +643660,14 @@ function loadFailurePatterns(store2) {
|
|
|
642963
643660
|
const unresolved = store2.listUnresolved();
|
|
642964
643661
|
if (unresolved.length === 0) return "";
|
|
642965
643662
|
const seen = /* @__PURE__ */ new Set();
|
|
642966
|
-
const
|
|
643663
|
+
const unique3 = unresolved.filter((f2) => {
|
|
642967
643664
|
if (seen.has(f2.fingerprint)) return false;
|
|
642968
643665
|
seen.add(f2.fingerprint);
|
|
642969
643666
|
return true;
|
|
642970
643667
|
});
|
|
642971
|
-
if (
|
|
643668
|
+
if (unique3.length === 0) return "";
|
|
642972
643669
|
const lines = ["Known failure patterns (avoid repeating these):"];
|
|
642973
|
-
for (const f2 of
|
|
643670
|
+
for (const f2 of unique3.slice(0, 8)) {
|
|
642974
643671
|
const file = f2.filePath ? ` in ${f2.filePath}` : "";
|
|
642975
643672
|
lines.push(`- [${f2.failureType}]${file}: ${f2.errorMessage.slice(0, 150)}`);
|
|
642976
643673
|
}
|
|
@@ -644059,6 +644756,7 @@ var init_status_bar = __esm({
|
|
|
644059
644756
|
init_render();
|
|
644060
644757
|
init_stageIndicator();
|
|
644061
644758
|
init_sub_agent_live_block();
|
|
644759
|
+
init_trajectory_live_block();
|
|
644062
644760
|
init_tui_tasks_renderer();
|
|
644063
644761
|
init_braille_spinner();
|
|
644064
644762
|
init_project_context();
|
|
@@ -644301,6 +644999,9 @@ var init_status_bar = __esm({
|
|
|
644301
644999
|
// toggles sub-agent / scroll info below header
|
|
644302
645000
|
_subAgentLiveBlockId = "sub-agent-live-preview";
|
|
644303
645001
|
_subAgentLiveBlockAppended = false;
|
|
645002
|
+
_trajectoryLiveBlockId = "trajectory-grounding-preview";
|
|
645003
|
+
_trajectoryLiveBlockAppended = false;
|
|
645004
|
+
_trajectoryCheckpoint = null;
|
|
644304
645005
|
// Virtual scrollback buffer — stores content lines for Page Up/Down scrolling.
|
|
644305
645006
|
// Since we're in alternate screen buffer, there's no native scrollback.
|
|
644306
645007
|
// NOTE: _contentLines is now a reference to the ACTIVE view's buffer.
|
|
@@ -645172,9 +645873,9 @@ var init_status_bar = __esm({
|
|
|
645172
645873
|
innerWidth: Math.max(1, termWidth - contentStartCol - rightChrome)
|
|
645173
645874
|
};
|
|
645174
645875
|
}
|
|
645175
|
-
hitTestCurrentHeaderAction(
|
|
645876
|
+
hitTestCurrentHeaderAction(row2, col, termWidth) {
|
|
645176
645877
|
const hdrRow = layout().headerContent;
|
|
645177
|
-
if (
|
|
645878
|
+
if (row2 !== hdrRow) return null;
|
|
645178
645879
|
const chrome = this.getHeaderChromeLayout(termWidth);
|
|
645179
645880
|
if (chrome.showPrev && col === 2) return "header-prev";
|
|
645180
645881
|
if (chrome.showNext && col === termWidth - 1) return "header-next";
|
|
@@ -646046,6 +646747,7 @@ var init_status_bar = __esm({
|
|
|
646046
646747
|
updatedAt: Date.now()
|
|
646047
646748
|
});
|
|
646048
646749
|
}
|
|
646750
|
+
this.ensureTrajectoryLiveBlock();
|
|
646049
646751
|
if (this._agentViews.size > 1) this.ensureSubAgentLiveBlock();
|
|
646050
646752
|
setTermSize(process.stdout.rows ?? 24, process.stdout.columns ?? 80);
|
|
646051
646753
|
setFooterMetricsVisible(this._footerMetricsVisible);
|
|
@@ -646259,11 +646961,11 @@ var init_status_bar = __esm({
|
|
|
646259
646961
|
return false;
|
|
646260
646962
|
}
|
|
646261
646963
|
/** Handle mouse click on a suggestion row */
|
|
646262
|
-
suggestClickAt(
|
|
646964
|
+
suggestClickAt(row2) {
|
|
646263
646965
|
const pos = this.rowPositions(termRows());
|
|
646264
646966
|
if (pos.suggestStartRow <= 0 || this._suggestions.length === 0)
|
|
646265
646967
|
return false;
|
|
646266
|
-
const idx =
|
|
646968
|
+
const idx = row2 - pos.suggestStartRow;
|
|
646267
646969
|
if (idx >= 0 && idx < this._suggestions.length) {
|
|
646268
646970
|
this._suggestIndex = idx;
|
|
646269
646971
|
return this.suggestAccept();
|
|
@@ -646509,18 +647211,18 @@ var init_status_bar = __esm({
|
|
|
646509
647211
|
* Routes to header/footer/tab clicks and scroll affordances. Content-area
|
|
646510
647212
|
* drag selection is deliberately left to the terminal.
|
|
646511
647213
|
*/
|
|
646512
|
-
handlePointerEvent(type, col,
|
|
647214
|
+
handlePointerEvent(type, col, row2) {
|
|
646513
647215
|
if (!this.active) return;
|
|
646514
647216
|
const w = termCols();
|
|
646515
|
-
if (type === "press" &&
|
|
646516
|
-
if (this.handleContentBlockClick(
|
|
647217
|
+
if (type === "press" && row2 >= this.scrollRegionTop) {
|
|
647218
|
+
if (this.handleContentBlockClick(row2, col)) return;
|
|
646517
647219
|
}
|
|
646518
647220
|
if (type === "press" && this._suggestions.length > 0) {
|
|
646519
|
-
if (this.suggestClickAt(
|
|
647221
|
+
if (this.suggestClickAt(row2)) return;
|
|
646520
647222
|
}
|
|
646521
|
-
if (
|
|
647223
|
+
if (row2 < this.scrollRegionTop) {
|
|
646522
647224
|
const hdrRow = layout().headerContent;
|
|
646523
|
-
if (type === "press" &&
|
|
647225
|
+
if (type === "press" && row2 === hdrRow && String(this.currentHeaderPanel).startsWith("sys-")) {
|
|
646524
647226
|
const zones = this._sysClickZones ?? [];
|
|
646525
647227
|
const hit = zones.find((z18) => col >= z18.start && col <= z18.end);
|
|
646526
647228
|
if (hit) {
|
|
@@ -646531,12 +647233,12 @@ var init_status_bar = __esm({
|
|
|
646531
647233
|
if (type === "press" && this._updateLatest) {
|
|
646532
647234
|
const hdrRow2 = layout().headerContent;
|
|
646533
647235
|
const verZone = this._verClickZone;
|
|
646534
|
-
if (
|
|
647236
|
+
if (row2 === hdrRow2 && verZone && col >= verZone.start && col <= verZone.end) {
|
|
646535
647237
|
if (this._headerButtonHandler) this._headerButtonHandler("/update");
|
|
646536
647238
|
return;
|
|
646537
647239
|
}
|
|
646538
647240
|
}
|
|
646539
|
-
const cmd = this.hitTestCurrentHeaderAction(
|
|
647241
|
+
const cmd = this.hitTestCurrentHeaderAction(row2, col, w);
|
|
646540
647242
|
if (type === "press" && cmd) {
|
|
646541
647243
|
if (cmd === "header-prev") {
|
|
646542
647244
|
this.prevHeaderPanel();
|
|
@@ -646577,44 +647279,44 @@ var init_status_bar = __esm({
|
|
|
646577
647279
|
}
|
|
646578
647280
|
if (type === "press" && this._footerMetricsVisible) {
|
|
646579
647281
|
const metricsRow = layout().footerMetrics;
|
|
646580
|
-
if (
|
|
647282
|
+
if (row2 === metricsRow && col >= termCols() - 5) {
|
|
646581
647283
|
this.cycleDebugPanelPage();
|
|
646582
647284
|
this.renderFooterAndPositionInput();
|
|
646583
647285
|
return;
|
|
646584
647286
|
}
|
|
646585
647287
|
}
|
|
646586
|
-
if (type === "press" && this._scrollBtnRegion &&
|
|
647288
|
+
if (type === "press" && this._scrollBtnRegion && row2 === this._scrollBtnRegion.row) {
|
|
646587
647289
|
if (col >= this._scrollBtnRegion.start && col <= this._scrollBtnRegion.end) {
|
|
646588
647290
|
this.jumpToLive();
|
|
646589
647291
|
return;
|
|
646590
647292
|
}
|
|
646591
647293
|
}
|
|
646592
|
-
if (type === "press" && this._copyBtnRegion &&
|
|
647294
|
+
if (type === "press" && this._copyBtnRegion && row2 === this._copyBtnRegion.row) {
|
|
646593
647295
|
if (col >= this._copyBtnRegion.start && col <= this._copyBtnRegion.end) {
|
|
646594
647296
|
void this.copySessionToClipboard();
|
|
646595
647297
|
return;
|
|
646596
647298
|
}
|
|
646597
647299
|
}
|
|
646598
647300
|
const pos = this.rowPositions(termRows());
|
|
646599
|
-
if (type === "press" && pos.tabBarRow > 0 &&
|
|
647301
|
+
if (type === "press" && pos.tabBarRow > 0 && row2 === pos.tabBarRow) {
|
|
646600
647302
|
const viewId = this.hitTestTabBar(col);
|
|
646601
647303
|
if (viewId) this.switchToView(viewId);
|
|
646602
647304
|
return;
|
|
646603
647305
|
}
|
|
646604
647306
|
if (type === "press") {
|
|
646605
647307
|
const Lt = layout();
|
|
646606
|
-
if (Lt.tasksTop > 0 &&
|
|
647308
|
+
if (Lt.tasksTop > 0 && row2 >= Lt.tasksTop && row2 <= Lt.tasksBottom) {
|
|
646607
647309
|
let consumed = false;
|
|
646608
647310
|
try {
|
|
646609
|
-
consumed = handleTuiTasksClick(
|
|
647311
|
+
consumed = handleTuiTasksClick(row2);
|
|
646610
647312
|
} catch {
|
|
646611
647313
|
}
|
|
646612
647314
|
if (consumed) return;
|
|
646613
647315
|
}
|
|
646614
647316
|
}
|
|
646615
|
-
if (type === "press" && this.handleFooterInputClick(
|
|
647317
|
+
if (type === "press" && this.handleFooterInputClick(row2, col)) return;
|
|
646616
647318
|
const L = layout();
|
|
646617
|
-
const inContent =
|
|
647319
|
+
const inContent = row2 >= this.scrollRegionTop && row2 <= L.contentBottom;
|
|
646618
647320
|
if (inContent) {
|
|
646619
647321
|
return;
|
|
646620
647322
|
}
|
|
@@ -646660,6 +647362,34 @@ var init_status_bar = __esm({
|
|
|
646660
647362
|
}, 1500);
|
|
646661
647363
|
}
|
|
646662
647364
|
// ── Agent View Management (WO-NA1) ────────────────────────────
|
|
647365
|
+
/** Store and render the runner's single evidence-bound trajectory checkpoint. */
|
|
647366
|
+
updateTrajectoryCheckpoint(checkpoint) {
|
|
647367
|
+
this._trajectoryCheckpoint = checkpoint;
|
|
647368
|
+
this.ensureTrajectoryLiveBlock();
|
|
647369
|
+
if (this.active) {
|
|
647370
|
+
this.refreshDynamicBlocks();
|
|
647371
|
+
this.renderFooterPreserveCursor();
|
|
647372
|
+
}
|
|
647373
|
+
}
|
|
647374
|
+
getTrajectoryCheckpoint() {
|
|
647375
|
+
return this._trajectoryCheckpoint;
|
|
647376
|
+
}
|
|
647377
|
+
ensureTrajectoryLiveBlock() {
|
|
647378
|
+
if (!this.active || !this._agentViews.has("main") || !this._trajectoryCheckpoint)
|
|
647379
|
+
return;
|
|
647380
|
+
if (this._trajectoryLiveBlockAppended) return;
|
|
647381
|
+
ensureCollapsible(this._trajectoryLiveBlockId);
|
|
647382
|
+
this.registerDynamicBlock(this._trajectoryLiveBlockId, (width) => {
|
|
647383
|
+
const checkpoint = this._trajectoryCheckpoint;
|
|
647384
|
+
return getCollapseState(this._trajectoryLiveBlockId) === "collapsed" ? buildTrajectoryLiveBlockCollapsedLine(
|
|
647385
|
+
checkpoint,
|
|
647386
|
+
width,
|
|
647387
|
+
this._stagePhase
|
|
647388
|
+
) : buildTrajectoryLiveBlockLines(checkpoint, width, this._stagePhase);
|
|
647389
|
+
});
|
|
647390
|
+
this.appendDynamicBlockToAgentView("main", this._trajectoryLiveBlockId);
|
|
647391
|
+
this._trajectoryLiveBlockAppended = true;
|
|
647392
|
+
}
|
|
646663
647393
|
/** Keep one compact, live child-agent preview in the MAIN view. */
|
|
646664
647394
|
ensureSubAgentLiveBlock() {
|
|
646665
647395
|
if (!this.active || !this._agentViews.has("main") || this._agentViews.size <= 1)
|
|
@@ -647005,17 +647735,17 @@ var init_status_bar = __esm({
|
|
|
647005
647735
|
if (this.writeDepth > 0) {
|
|
647006
647736
|
const inputWrap = this.wrapInput(w);
|
|
647007
647737
|
let buf = `\x1B[${this.scrollRegionTop};${pos.scrollEnd}r\x1B[?25l\x1B[?7l`;
|
|
647008
|
-
for (let
|
|
647009
|
-
buf += `\x1B[${
|
|
647738
|
+
for (let row2 = clearStart; row2 <= rows; row2++) {
|
|
647739
|
+
buf += `\x1B[${row2};1H\x1B[2K`;
|
|
647010
647740
|
}
|
|
647011
647741
|
buf += `\x1B[${pos.inputStartRow};1H${PANEL_BG_SEQ}\x1B[2K${this.buildInputBoxTop(w)}${PANEL_BG_SEQ}`;
|
|
647012
647742
|
for (let i2 = 0; i2 < inputWrap.lines.length; i2++) {
|
|
647013
|
-
const
|
|
647743
|
+
const row2 = pos.inputStartRow + 1 + i2;
|
|
647014
647744
|
const prefix = i2 === 0 ? this.promptText : " ".repeat(this.promptWidth);
|
|
647015
647745
|
const lineContent = `${prefix}${inputWrap.lines[i2]}`;
|
|
647016
|
-
buf += `\x1B[${
|
|
647746
|
+
buf += `\x1B[${row2};1H${PANEL_BG_SEQ}\x1B[2K`;
|
|
647017
647747
|
buf += `${this.borderVSeq(1)}${BOX_V3}${RESET4}${PANEL_BG_SEQ}${lineContent}`;
|
|
647018
|
-
buf += `${PANEL_BG_SEQ}\x1B[K\x1B[${
|
|
647748
|
+
buf += `${PANEL_BG_SEQ}\x1B[K\x1B[${row2};${w}H${this.borderVSeq(w)}${BOX_V3}${RESET4}${PANEL_BG_SEQ}`;
|
|
647019
647749
|
}
|
|
647020
647750
|
buf += this.buildEnhanceSegment(
|
|
647021
647751
|
w,
|
|
@@ -647035,8 +647765,8 @@ var init_status_bar = __esm({
|
|
|
647035
647765
|
this.fillContentArea();
|
|
647036
647766
|
this.repaintContent();
|
|
647037
647767
|
let clearBuf = "\x1B[?7l";
|
|
647038
|
-
for (let
|
|
647039
|
-
clearBuf += `\x1B[${
|
|
647768
|
+
for (let row2 = pos.scrollEnd + 1; row2 <= rows; row2++) {
|
|
647769
|
+
clearBuf += `\x1B[${row2};1H\x1B[2K`;
|
|
647040
647770
|
}
|
|
647041
647771
|
clearBuf += "\x1B[?7h";
|
|
647042
647772
|
this.termWrite(clearBuf);
|
|
@@ -647542,14 +648272,14 @@ ${CONTENT_BG_SEQ}`);
|
|
|
647542
648272
|
};
|
|
647543
648273
|
return this._rowCountCache;
|
|
647544
648274
|
}
|
|
647545
|
-
firstSourceLineForRow(prefix,
|
|
648275
|
+
firstSourceLineForRow(prefix, row2) {
|
|
647546
648276
|
if (prefix.length <= 1) return 0;
|
|
647547
648277
|
let lo = 0;
|
|
647548
648278
|
let hi = Math.max(0, prefix.length - 2);
|
|
647549
648279
|
let answer = hi;
|
|
647550
648280
|
while (lo <= hi) {
|
|
647551
648281
|
const mid = lo + hi >> 1;
|
|
647552
|
-
if ((prefix[mid + 1] ?? 0) >
|
|
648282
|
+
if ((prefix[mid + 1] ?? 0) > row2) {
|
|
647553
648283
|
answer = mid;
|
|
647554
648284
|
hi = mid - 1;
|
|
647555
648285
|
} else {
|
|
@@ -647908,11 +648638,11 @@ ${CONTENT_BG_SEQ}`);
|
|
|
647908
648638
|
buf += "\x1B7";
|
|
647909
648639
|
buf += "\x1B[?25l";
|
|
647910
648640
|
const selRanges = this._textSelection.getSelectedRanges();
|
|
647911
|
-
for (let
|
|
647912
|
-
const lineIdx = startIdx +
|
|
648641
|
+
for (let row2 = 0; row2 < h; row2++) {
|
|
648642
|
+
const lineIdx = startIdx + row2;
|
|
647913
648643
|
const reflowed = reflowedLines[lineIdx];
|
|
647914
648644
|
let line = reflowed?.line ?? "";
|
|
647915
|
-
const screenRow = this.scrollRegionTop +
|
|
648645
|
+
const screenRow = this.scrollRegionTop + row2;
|
|
647916
648646
|
if (screenRow < headerSafeFloor) continue;
|
|
647917
648647
|
line = line.replace(/\x1B\[0m/g, `\x1B[0m${CONTENT_BG_SEQ}`);
|
|
647918
648648
|
const sel = selRanges.find((r2) => r2.bufferIdx === reflowed?.bufferIdx);
|
|
@@ -648191,8 +648921,8 @@ ${CONTENT_BG_SEQ}`);
|
|
|
648191
648921
|
const end = termRows();
|
|
648192
648922
|
if (start2 > end) return;
|
|
648193
648923
|
let buf = "\x1B7\x1B[?25l";
|
|
648194
|
-
for (let
|
|
648195
|
-
buf += `\x1B[${
|
|
648924
|
+
for (let row2 = start2; row2 <= end; row2++) {
|
|
648925
|
+
buf += `\x1B[${row2};1H${CONTENT_BG_SEQ}\x1B[2K`;
|
|
648196
648926
|
}
|
|
648197
648927
|
buf += "\x1B8";
|
|
648198
648928
|
if (this.writeDepth === 0) buf += "\x1B[?25h";
|
|
@@ -648312,10 +649042,10 @@ ${CONTENT_BG_SEQ}`);
|
|
|
648312
649042
|
const cellEnd = w - 1;
|
|
648313
649043
|
let buf = "";
|
|
648314
649044
|
for (let i2 = 0; i2 < rowCount; i2++) {
|
|
648315
|
-
const
|
|
648316
|
-
buf += `\x1B[${
|
|
649045
|
+
const row2 = firstInputRow + i2;
|
|
649046
|
+
buf += `\x1B[${row2};${dividerCol}H${this.borderVSeq(dividerCol)}${BOX_V3}${RESET4}${PANEL_BG_SEQ}`;
|
|
648317
649047
|
if (i2 > 0) {
|
|
648318
|
-
buf += `\x1B[${
|
|
649048
|
+
buf += `\x1B[${row2};${cellStart}H${PANEL_BG_SEQ}${" ".repeat(ENHANCE_SEG_INNER)}`;
|
|
648319
649049
|
}
|
|
648320
649050
|
}
|
|
648321
649051
|
buf += this.buildEnhanceButtonCell(firstInputRow, cellStart);
|
|
@@ -648323,8 +649053,8 @@ ${CONTENT_BG_SEQ}`);
|
|
|
648323
649053
|
return buf;
|
|
648324
649054
|
}
|
|
648325
649055
|
/** Render the button-cell content for the current enhance state (width = ENHANCE_SEG_INNER). */
|
|
648326
|
-
buildEnhanceButtonCell(
|
|
648327
|
-
const cup = `\x1B[${
|
|
649056
|
+
buildEnhanceButtonCell(row2, cellStart) {
|
|
649057
|
+
const cup = `\x1B[${row2};${cellStart}H`;
|
|
648328
649058
|
if (this._enhanceState === "busy") {
|
|
648329
649059
|
this._enhanceConfirmZones = null;
|
|
648330
649060
|
const frame = ENHANCE_SPIN_FRAMES[this._enhanceSpinFrame % ENHANCE_SPIN_FRAMES.length] ?? "⠋";
|
|
@@ -648486,14 +649216,14 @@ ${CONTENT_BG_SEQ}`);
|
|
|
648486
649216
|
* or a click in the text area to reposition the cursor. Returns true when the
|
|
648487
649217
|
* click was consumed.
|
|
648488
649218
|
*/
|
|
648489
|
-
handleFooterInputClick(
|
|
649219
|
+
handleFooterInputClick(row2, col) {
|
|
648490
649220
|
if (!this.inputStateProvider) return false;
|
|
648491
649221
|
const w = getTermWidth();
|
|
648492
649222
|
const pos = this.rowPositions(termRows());
|
|
648493
649223
|
const inputLines = this.computeInputLineCount(w);
|
|
648494
649224
|
const firstInputRow = pos.inputStartRow + 1;
|
|
648495
649225
|
const lastInputRow = firstInputRow + inputLines - 1;
|
|
648496
|
-
if (
|
|
649226
|
+
if (row2 < firstInputRow || row2 > lastInputRow) return false;
|
|
648497
649227
|
if (this.enhanceSegEnabled(w)) {
|
|
648498
649228
|
const dividerCol = this.enhanceDividerCol(w);
|
|
648499
649229
|
const cellStart = dividerCol + 1;
|
|
@@ -648526,7 +649256,7 @@ ${CONTENT_BG_SEQ}`);
|
|
|
648526
649256
|
availWidth
|
|
648527
649257
|
);
|
|
648528
649258
|
const lineIdx = Math.min(
|
|
648529
|
-
Math.max(0,
|
|
649259
|
+
Math.max(0, row2 - firstInputRow),
|
|
648530
649260
|
rawLines.length - 1
|
|
648531
649261
|
);
|
|
648532
649262
|
const rawLine = rawLines[lineIdx] ?? "";
|
|
@@ -648778,13 +649508,13 @@ ${CONTENT_BG_SEQ}`);
|
|
|
648778
649508
|
buf += `\x1B[${spacerRow};1H${PANEL_BG_SEQ}\x1B[2K${RESET4}`;
|
|
648779
649509
|
}
|
|
648780
649510
|
for (let i2 = 0; i2 < inputWrap.lines.length; i2++) {
|
|
648781
|
-
const
|
|
649511
|
+
const row2 = pos.inputStartRow + 1 + i2;
|
|
648782
649512
|
const prefix = i2 === 0 ? this.promptText : " ".repeat(this.promptWidth);
|
|
648783
649513
|
const lineContent = `${prefix}${inputWrap.lines[i2]}`;
|
|
648784
|
-
buf += `\x1B[${
|
|
649514
|
+
buf += `\x1B[${row2};1H${PANEL_BG_SEQ}\x1B[2K`;
|
|
648785
649515
|
buf += `${this.borderVSeq(1)}${BOX_V3}${RESET4}${PANEL_BG_SEQ}${lineContent}`;
|
|
648786
649516
|
buf += `${PANEL_BG_SEQ}\x1B[K`;
|
|
648787
|
-
buf += `\x1B[${
|
|
649517
|
+
buf += `\x1B[${row2};${w}H${this.borderVSeq(w)}${BOX_V3}${RESET4}${PANEL_BG_SEQ}`;
|
|
648788
649518
|
}
|
|
648789
649519
|
buf += this.buildEnhanceSegment(
|
|
648790
649520
|
w,
|
|
@@ -648794,17 +649524,17 @@ ${CONTENT_BG_SEQ}`);
|
|
|
648794
649524
|
const cursorTermRow = pos.inputStartRow + 1 + inputWrap.cursorRow;
|
|
648795
649525
|
if (this._suggestions.length > 0 && pos.suggestStartRow > 0) {
|
|
648796
649526
|
for (let si = 0; si < this._suggestions.length; si++) {
|
|
648797
|
-
const
|
|
649527
|
+
const row2 = pos.suggestStartRow + si;
|
|
648798
649528
|
const cmd = this._suggestions[si];
|
|
648799
649529
|
const isHighlighted = si === this._suggestIndex;
|
|
648800
649530
|
const bg = isHighlighted ? `\x1B[48;5;235m` : PANEL_BG_SEQ;
|
|
648801
649531
|
const fg2 = isHighlighted ? `\x1B[1;38;5;${TEXT_PRIMARY}m` : `\x1B[38;5;${TEXT_PRIMARY}m`;
|
|
648802
649532
|
const slash = isHighlighted ? `\x1B[38;5;245m` : `\x1B[38;5;${TEXT_DIM}m`;
|
|
648803
649533
|
const marker = isHighlighted ? `\x1B[38;5;${TEXT_PRIMARY}m› ` : " ";
|
|
648804
|
-
buf += `\x1B[${
|
|
649534
|
+
buf += `\x1B[${row2};1H${PANEL_BG_SEQ}\x1B[2K${this.borderVSeq(1)}${BOX_V3}${RESET4}${PANEL_BG_SEQ}`;
|
|
648805
649535
|
buf += `${bg} ${marker}${slash}/${fg2}${cmd}`;
|
|
648806
649536
|
buf += `${PANEL_BG_SEQ}\x1B[K`;
|
|
648807
|
-
buf += `\x1B[${
|
|
649537
|
+
buf += `\x1B[${row2};${w}H${this.borderVSeq(w)}${BOX_V3}${RESET4}${PANEL_BG_SEQ}`;
|
|
648808
649538
|
}
|
|
648809
649539
|
const suggestBottomRow = pos.suggestStartRow + this._suggestions.length;
|
|
648810
649540
|
buf += `\x1B[${suggestBottomRow};1H${PANEL_BG_SEQ}\x1B[2K${this.buildInputBoxBottom(w)}${PANEL_BG_SEQ}`;
|
|
@@ -648852,13 +649582,13 @@ ${CONTENT_BG_SEQ}`);
|
|
|
648852
649582
|
}
|
|
648853
649583
|
buf += `\x1B[${pos.inputStartRow};1H${PANEL_BG_SEQ}\x1B[2K${this.buildInputBoxTop(w)}${PANEL_BG_SEQ}`;
|
|
648854
649584
|
for (let i2 = 0; i2 < inputWrap.lines.length; i2++) {
|
|
648855
|
-
const
|
|
649585
|
+
const row2 = pos.inputStartRow + 1 + i2;
|
|
648856
649586
|
const prefix = i2 === 0 ? this.promptText : " ".repeat(this.promptWidth);
|
|
648857
649587
|
const lineContent = `${prefix}${inputWrap.lines[i2]}`;
|
|
648858
|
-
buf += `\x1B[${
|
|
649588
|
+
buf += `\x1B[${row2};1H${PANEL_BG_SEQ}\x1B[2K`;
|
|
648859
649589
|
buf += `${this.borderVSeq(1)}${BOX_V3}${RESET4}${PANEL_BG_SEQ}${lineContent}`;
|
|
648860
649590
|
buf += `${PANEL_BG_SEQ}\x1B[K`;
|
|
648861
|
-
buf += `\x1B[${
|
|
649591
|
+
buf += `\x1B[${row2};${w}H${this.borderVSeq(w)}${BOX_V3}${RESET4}${PANEL_BG_SEQ}`;
|
|
648862
649592
|
}
|
|
648863
649593
|
buf += this.buildEnhanceSegment(
|
|
648864
649594
|
w,
|
|
@@ -648867,13 +649597,13 @@ ${CONTENT_BG_SEQ}`);
|
|
|
648867
649597
|
);
|
|
648868
649598
|
if (this._suggestions.length > 0 && pos.suggestStartRow > 0) {
|
|
648869
649599
|
for (let si = 0; si < this._suggestions.length; si++) {
|
|
648870
|
-
const
|
|
649600
|
+
const row2 = pos.suggestStartRow + si;
|
|
648871
649601
|
const cmd = this._suggestions[si];
|
|
648872
649602
|
const isHl = si === this._suggestIndex;
|
|
648873
649603
|
const fg2 = isHl ? `\x1B[1;38;5;${TEXT_PRIMARY}m` : `\x1B[38;5;${TEXT_PRIMARY}m`;
|
|
648874
649604
|
const marker = isHl ? `\x1B[38;5;${TEXT_PRIMARY}m› ` : " ";
|
|
648875
|
-
buf += `\x1B[${
|
|
648876
|
-
buf += `${PANEL_BG_SEQ}\x1B[K\x1B[${
|
|
649605
|
+
buf += `\x1B[${row2};1H${PANEL_BG_SEQ}\x1B[2K${this.borderVSeq(1)}${BOX_V3}${RESET4}${PANEL_BG_SEQ} ${marker}\x1B[38;5;${TEXT_DIM}m/${fg2}${cmd}`;
|
|
649606
|
+
buf += `${PANEL_BG_SEQ}\x1B[K\x1B[${row2};${w}H${this.borderVSeq(w)}${BOX_V3}${RESET4}`;
|
|
648877
649607
|
}
|
|
648878
649608
|
buf += `\x1B[${pos.bufferRow};1H${PANEL_BG_SEQ}\x1B[2K${this.buildInputBoxBottom(w)}`;
|
|
648879
649609
|
} else {
|
|
@@ -648926,17 +649656,17 @@ ${CONTENT_BG_SEQ}`);
|
|
|
648926
649656
|
}
|
|
648927
649657
|
const releasedEnd = pos.inputStartRow - 1;
|
|
648928
649658
|
if (oldFooterTop <= releasedEnd) {
|
|
648929
|
-
for (let
|
|
648930
|
-
buf += `\x1B[${
|
|
649659
|
+
for (let row2 = oldFooterTop; row2 <= releasedEnd; row2++) {
|
|
649660
|
+
buf += `\x1B[${row2};1H${CONTENT_BG_SEQ}\x1B[2K`;
|
|
648931
649661
|
}
|
|
648932
649662
|
}
|
|
648933
649663
|
buf += "\x1B[?7l";
|
|
648934
649664
|
buf += `\x1B[${pos.inputStartRow};1H${PANEL_BG_SEQ}\x1B[2K${this.buildInputBoxTop(w)}`;
|
|
648935
649665
|
for (let i2 = 0; i2 < inputWrap.lines.length; i2++) {
|
|
648936
|
-
const
|
|
649666
|
+
const row2 = pos.inputStartRow + 1 + i2;
|
|
648937
649667
|
const prefix = i2 === 0 ? this.promptText : " ".repeat(this.promptWidth);
|
|
648938
649668
|
const lineContent = `${prefix}${inputWrap.lines[i2]}`;
|
|
648939
|
-
buf += `\x1B[${
|
|
649669
|
+
buf += `\x1B[${row2};1H${PANEL_BG_SEQ}\x1B[2K${this.borderVSeq(1)}${BOX_V3}${RESET4}${PANEL_BG_SEQ}${lineContent}${PANEL_BG_SEQ}\x1B[K\x1B[${row2};${w}H${this.borderVSeq(w)}${BOX_V3}${RESET4}`;
|
|
648940
649670
|
}
|
|
648941
649671
|
buf += this.buildEnhanceSegment(
|
|
648942
649672
|
w,
|
|
@@ -648945,15 +649675,15 @@ ${CONTENT_BG_SEQ}`);
|
|
|
648945
649675
|
);
|
|
648946
649676
|
if (this._suggestions.length > 0 && pos.suggestStartRow > 0) {
|
|
648947
649677
|
for (let si = 0; si < this._suggestions.length; si++) {
|
|
648948
|
-
const
|
|
649678
|
+
const row2 = pos.suggestStartRow + si;
|
|
648949
649679
|
const cmd = this._suggestions[si];
|
|
648950
649680
|
const isHl = si === this._suggestIndex;
|
|
648951
649681
|
const bg = isHl ? `\x1B[48;5;235m` : PANEL_BG_SEQ;
|
|
648952
649682
|
const fg2 = isHl ? `\x1B[1;38;5;${TEXT_PRIMARY}m` : `\x1B[38;5;${TEXT_PRIMARY}m`;
|
|
648953
649683
|
const marker = isHl ? `\x1B[38;5;${TEXT_PRIMARY}m› ` : " ";
|
|
648954
|
-
buf += `\x1B[${
|
|
649684
|
+
buf += `\x1B[${row2};1H${PANEL_BG_SEQ}\x1B[2K${this.borderVSeq(1)}${BOX_V3}${RESET4}${PANEL_BG_SEQ}`;
|
|
648955
649685
|
buf += `${bg} ${marker}\x1B[38;5;${TEXT_DIM}m/${fg2}${cmd}`;
|
|
648956
|
-
buf += `${PANEL_BG_SEQ}\x1B[K\x1B[${
|
|
649686
|
+
buf += `${PANEL_BG_SEQ}\x1B[K\x1B[${row2};${w}H${this.borderVSeq(w)}${BOX_V3}${RESET4}`;
|
|
648957
649687
|
}
|
|
648958
649688
|
}
|
|
648959
649689
|
buf += `\x1B[${pos.bufferRow};1H${PANEL_BG_SEQ}\x1B[2K${this.buildInputBoxBottom(w)}`;
|
|
@@ -648975,13 +649705,13 @@ ${CONTENT_BG_SEQ}`);
|
|
|
648975
649705
|
let buf = "\x1B7\x1B[?25l\x1B[?7l";
|
|
648976
649706
|
buf += `\x1B[${pos.inputStartRow};1H${PANEL_BG_SEQ}\x1B[2K${this.buildInputBoxTop(w)}${PANEL_BG_SEQ}`;
|
|
648977
649707
|
for (let i2 = 0; i2 < inputWrap.lines.length; i2++) {
|
|
648978
|
-
const
|
|
649708
|
+
const row2 = pos.inputStartRow + 1 + i2;
|
|
648979
649709
|
const prefix = i2 === 0 ? this.promptText : " ".repeat(this.promptWidth);
|
|
648980
649710
|
const lineContent = `${prefix}${inputWrap.lines[i2]}`;
|
|
648981
|
-
buf += `\x1B[${
|
|
649711
|
+
buf += `\x1B[${row2};1H${PANEL_BG_SEQ}\x1B[2K`;
|
|
648982
649712
|
buf += `${this.borderVSeq(1)}${BOX_V3}${RESET4}${PANEL_BG_SEQ}${lineContent}`;
|
|
648983
649713
|
buf += `${PANEL_BG_SEQ}\x1B[K`;
|
|
648984
|
-
buf += `\x1B[${
|
|
649714
|
+
buf += `\x1B[${row2};${w}H${this.borderVSeq(w)}${BOX_V3}${RESET4}${PANEL_BG_SEQ}`;
|
|
648985
649715
|
}
|
|
648986
649716
|
buf += this.buildEnhanceSegment(
|
|
648987
649717
|
w,
|
|
@@ -648990,15 +649720,15 @@ ${CONTENT_BG_SEQ}`);
|
|
|
648990
649720
|
);
|
|
648991
649721
|
if (this._suggestions.length > 0 && pos.suggestStartRow > 0) {
|
|
648992
649722
|
for (let si = 0; si < this._suggestions.length; si++) {
|
|
648993
|
-
const
|
|
649723
|
+
const row2 = pos.suggestStartRow + si;
|
|
648994
649724
|
const cmd = this._suggestions[si];
|
|
648995
649725
|
const isHl = si === this._suggestIndex;
|
|
648996
649726
|
const bg = isHl ? `\x1B[48;5;235m` : PANEL_BG_SEQ;
|
|
648997
649727
|
const fg2 = isHl ? `\x1B[1;38;5;${TEXT_PRIMARY}m` : `\x1B[38;5;${TEXT_PRIMARY}m`;
|
|
648998
649728
|
const marker = isHl ? `\x1B[38;5;${TEXT_PRIMARY}m› ` : " ";
|
|
648999
|
-
buf += `\x1B[${
|
|
649729
|
+
buf += `\x1B[${row2};1H${PANEL_BG_SEQ}\x1B[2K${this.borderVSeq(1)}${BOX_V3}${RESET4}${PANEL_BG_SEQ}`;
|
|
649000
649730
|
buf += `${bg} ${marker}\x1B[38;5;${TEXT_DIM}m/${fg2}${cmd}`;
|
|
649001
|
-
buf += `${PANEL_BG_SEQ}\x1B[K\x1B[${
|
|
649731
|
+
buf += `${PANEL_BG_SEQ}\x1B[K\x1B[${row2};${w}H${this.borderVSeq(w)}${BOX_V3}${RESET4}${PANEL_BG_SEQ}`;
|
|
649002
649732
|
}
|
|
649003
649733
|
}
|
|
649004
649734
|
buf += `\x1B[${pos.bufferRow};1H${PANEL_BG_SEQ}\x1B[2K${this.buildInputBoxBottom(w)}${PANEL_BG_SEQ}`;
|
|
@@ -653761,9 +654491,9 @@ function formatExpandedContextDiagnostic(specs, math) {
|
|
|
653761
654491
|
memBits.push(`RAM ${fmtGB(specs.availableRamGB)}/${fmtGB(specs.totalRamGB)}${specs.unifiedMemory ? " unified" : ""}`);
|
|
653762
654492
|
const mem = memBits.join(", ");
|
|
653763
654493
|
const kv = `KV ${fmtKB(math.kvBytesPerToken)}/tok (${math.kvSource})`;
|
|
653764
|
-
const
|
|
654494
|
+
const fit5 = `fit ${fmtK(math.memoryFit)}, arch ${math.archCtx !== null ? fmtK(math.archCtx) : "n/a"}, floor ${fmtK(math.floor)}`;
|
|
653765
654495
|
const limit = `→ ${fmtK(math.numCtx)} (${math.limitedBy === "floor" ? "min floor" : math.limitedBy === "arch" ? "arch-capped" : "memory-fit"})`;
|
|
653766
|
-
return `[${mem} | model ${fmtGB(math.modelSizeGB)} | ${kv} | ${
|
|
654496
|
+
return `[${mem} | model ${fmtGB(math.modelSizeGB)} | ${kv} | ${fit5} ${limit}]`;
|
|
653767
654497
|
}
|
|
653768
654498
|
async function ensureExpandedContext(modelName, backendUrl2) {
|
|
653769
654499
|
if (modelName.includes("cloud") || modelName.includes(":cloud")) {
|
|
@@ -654042,7 +654772,7 @@ export PATH="${binDir}:$PATH" # Added by omnius for nvim
|
|
|
654042
654772
|
} catch {
|
|
654043
654773
|
}
|
|
654044
654774
|
}
|
|
654045
|
-
var execAsync2, OMNIUS_FIRST_RUN_BANNER,
|
|
654775
|
+
var execAsync2, OMNIUS_FIRST_RUN_BANNER, ANSI_RE4, visibleLen2, SETUP_MODEL_VARIANTS, _toolSupportCache, EXPANDED_VARIANT_MIN_NUM_CTX, _cloudflaredInstallPromise;
|
|
654046
654776
|
var init_setup = __esm({
|
|
654047
654777
|
"packages/cli/src/tui/setup.ts"() {
|
|
654048
654778
|
init_model_picker();
|
|
@@ -654061,8 +654791,8 @@ var init_setup = __esm({
|
|
|
654061
654791
|
"░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ",
|
|
654062
654792
|
" ░▒▓██████▓▒░░▒▓█▓▒░░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓██████▓▒░░▒▓███████▓▒░ "
|
|
654063
654793
|
].join("\n");
|
|
654064
|
-
|
|
654065
|
-
visibleLen2 = (value2) => Array.from(value2.replace(
|
|
654794
|
+
ANSI_RE4 = /\x1B\[[0-?]*[ -/]*[@-~]/g;
|
|
654795
|
+
visibleLen2 = (value2) => Array.from(value2.replace(ANSI_RE4, "")).length;
|
|
654066
654796
|
SETUP_MODEL_VARIANTS = [
|
|
654067
654797
|
{ tag: "robit/ornith:9b", sizeGB: 6.6, label: "9B params (6.6 GB) - recommended minimum", cloud: false },
|
|
654068
654798
|
{ tag: "robit/ornith:35b", sizeGB: 24, label: "35B params (24 GB) - recommended on 32GB+ unified memory/VRAM", cloud: false }
|
|
@@ -658198,13 +658928,13 @@ async function startNeovimMode(opts) {
|
|
|
658198
658928
|
if (topOffset > 0) {
|
|
658199
658929
|
filtered = filtered.replace(
|
|
658200
658930
|
/\x1B\[(\d+);(\d+)H/g,
|
|
658201
|
-
(_m,
|
|
658931
|
+
(_m, row2, col) => `\x1B[${parseInt(row2) + topOffset};${col}H`
|
|
658202
658932
|
).replace(
|
|
658203
658933
|
/\x1B\[(\d+)H/g,
|
|
658204
|
-
(_m,
|
|
658934
|
+
(_m, row2) => `\x1B[${parseInt(row2) + topOffset}H`
|
|
658205
658935
|
).replace(/\x1B\[H/g, `\x1B[${topOffset + 1}H`).replace(
|
|
658206
658936
|
/\x1B\[(\d+)d/g,
|
|
658207
|
-
(_m,
|
|
658937
|
+
(_m, row2) => `\x1B[${parseInt(row2) + topOffset}d`
|
|
658208
658938
|
);
|
|
658209
658939
|
}
|
|
658210
658940
|
if (!state.focused) {
|
|
@@ -658279,11 +659009,11 @@ async function startNeovimMode(opts) {
|
|
|
658279
659009
|
let normalized = seq.replace(/\x1BO([ABCD])/g, "\x1B[$1");
|
|
658280
659010
|
normalized = normalized.replace(
|
|
658281
659011
|
/\x1B\[<(\d+);(\d+);(\d+)([Mm])/g,
|
|
658282
|
-
(_m, btn, col,
|
|
659012
|
+
(_m, btn, col, row2, suffix) => {
|
|
658283
659013
|
const b = parseInt(btn);
|
|
658284
659014
|
if (suffix !== "M" || b !== 0) return "";
|
|
658285
659015
|
const L = layout();
|
|
658286
|
-
const hostRow = parseInt(
|
|
659016
|
+
const hostRow = parseInt(row2);
|
|
658287
659017
|
if (hostRow > L.contentBottom) {
|
|
658288
659018
|
toggleFocus(state);
|
|
658289
659019
|
return "";
|
|
@@ -659126,7 +659856,7 @@ var init_mem_metabolize = __esm({
|
|
|
659126
659856
|
});
|
|
659127
659857
|
|
|
659128
659858
|
// packages/cli/src/tui/commands/kg-prune-inference.ts
|
|
659129
|
-
function
|
|
659859
|
+
function truncate4(text2, max) {
|
|
659130
659860
|
const clean5 = text2.replace(/\s+/g, " ").trim();
|
|
659131
659861
|
return clean5.length > max ? clean5.slice(0, max - 1) + "…" : clean5;
|
|
659132
659862
|
}
|
|
@@ -659138,7 +659868,7 @@ async function classifySignalNodes(candidates, cfg) {
|
|
|
659138
659868
|
return { reviewed: 0, keepIds: [], ok: false, error: "no model/endpoint" };
|
|
659139
659869
|
}
|
|
659140
659870
|
const list = sample.map(
|
|
659141
|
-
(n2, i2) => `${i2 + 1}. id=${n2.id} type=${n2.nodeType} mentions=${n2.mentionCount} edges=${n2.degree} :: ${
|
|
659871
|
+
(n2, i2) => `${i2 + 1}. id=${n2.id} type=${n2.nodeType} mentions=${n2.mentionCount} edges=${n2.degree} :: ${truncate4(n2.text, 160)}`
|
|
659142
659872
|
).join("\n");
|
|
659143
659873
|
const system = 'You are the memory-consolidation process of an AI agent, running during idle time (like sleep). You are shown low-activity knowledge-graph nodes that are scheduled to be FORGOTTEN to keep memory bounded. Your job: rescue only the ones that are durable SIGNAL — stable facts, real entities, decisions, identities, or reusable knowledge the agent will likely need again. Let transient, redundant, trivial, or noisy nodes be forgotten. Reply with ONLY a JSON array of the id strings to KEEP, e.g. ["a1","b2"]. Keep the array short and selective. If none are worth keeping, reply []';
|
|
659144
659874
|
const user = `Nodes scheduled for forgetting:
|
|
@@ -674733,12 +675463,12 @@ function cad3dFitIcon(score) {
|
|
|
674733
675463
|
if (score >= 40) return c3.yellow("△");
|
|
674734
675464
|
return c3.red("✖");
|
|
674735
675465
|
}
|
|
674736
|
-
function cad3dModelDetail(spec,
|
|
675466
|
+
function cad3dModelDetail(spec, fit5) {
|
|
674737
675467
|
const download = spec.resources.approxDownloadGB ? `~${spec.resources.approxDownloadGB}GB` : "size unknown";
|
|
674738
675468
|
const vram = spec.resources.recommendedVramGB ? `${spec.resources.recommendedVramGB}GB VRAM rec` : "VRAM varies";
|
|
674739
675469
|
const license = spec.hf.license ? `license ${spec.hf.license}` : "license unknown";
|
|
674740
675470
|
const token = spec.deployment.requiresToken ? "requires HF token" : "no token gate";
|
|
674741
|
-
return `${
|
|
675471
|
+
return `${fit5.label} · ${spec.backend} · ${download} · ${vram} · ${license} · ${token}`;
|
|
674742
675472
|
}
|
|
674743
675473
|
async function startCad3dViewerFromCommand(rawPath) {
|
|
674744
675474
|
const viewer = await startCadModelViewer(
|
|
@@ -674754,11 +675484,11 @@ async function showCad3dModelsMenu(ctx3, hasLocal, mode) {
|
|
|
674754
675484
|
const active = mode === "cad" ? settings.cadModel : settings.model3dModel;
|
|
674755
675485
|
const currentViewer2 = getCurrentCadModelViewer();
|
|
674756
675486
|
const buildItem = (entry) => {
|
|
674757
|
-
const
|
|
675487
|
+
const fit5 = rateCad3dModelForHardware(entry.spec, specs);
|
|
674758
675488
|
return {
|
|
674759
675489
|
key: `model:${entry.spec.id}`,
|
|
674760
|
-
label: `${cad3dFitIcon(
|
|
674761
|
-
detail: cad3dModelDetail(entry.spec,
|
|
675490
|
+
label: `${cad3dFitIcon(fit5.score)} ${String(fit5.score).padStart(3)}/100 ${entry.spec.label}`,
|
|
675491
|
+
detail: cad3dModelDetail(entry.spec, fit5)
|
|
674762
675492
|
};
|
|
674763
675493
|
};
|
|
674764
675494
|
const items = [
|
|
@@ -674793,11 +675523,11 @@ async function showCad3dModelsMenu(ctx3, hasLocal, mode) {
|
|
|
674793
675523
|
const patch = mode === "cad" ? { cadModel: id2, cadBackend: entry.spec.backend } : { model3dModel: id2, model3dBackend: entry.spec.backend };
|
|
674794
675524
|
const save3 = hasLocal ? ctx3.saveLocalSettings : ctx3.saveSettings;
|
|
674795
675525
|
save3(patch);
|
|
674796
|
-
const
|
|
675526
|
+
const fit5 = rateCad3dModelForHardware(entry.spec, specs);
|
|
674797
675527
|
renderInfo(
|
|
674798
675528
|
`${mode === "cad" ? "CAD" : "3D"} model: ${id2} (${entry.spec.backend})${hasLocal ? " (project-local)" : ""}`
|
|
674799
675529
|
);
|
|
674800
|
-
renderInfo(`Hardware fit: ${
|
|
675530
|
+
renderInfo(`Hardware fit: ${fit5.score}/100 ${fit5.label} - ${fit5.note}`);
|
|
674801
675531
|
if (entry.spec.resources.approxDownloadGB) {
|
|
674802
675532
|
renderInfo(
|
|
674803
675533
|
`Download estimate: ~${entry.spec.resources.approxDownloadGB}GB in ${unifiedModelStoreDir()}`
|
|
@@ -674948,19 +675678,19 @@ async function renderImageModelList(ctx3) {
|
|
|
674948
675678
|
renderInfo("");
|
|
674949
675679
|
renderInfo(c3.bold(category));
|
|
674950
675680
|
for (const preset of presets) {
|
|
674951
|
-
const
|
|
675681
|
+
const fit5 = rateImagePresetForHardware(preset, specs);
|
|
674952
675682
|
const primary = category === "Primary hyper-realistic baseline" ? c3.cyan(" ★") : "";
|
|
674953
675683
|
const disk = ctx3 ? imageModelDiskStats(ctx3, preset, ollamaSizes) : { downloaded: false, bytes: 0, paths: [] };
|
|
674954
675684
|
const diskInfo = disk.downloaded ? ` ${c3.green("✓")} ${formatFileSize(disk.bytes)}` : "";
|
|
674955
675685
|
renderInfo(
|
|
674956
|
-
`${imageFitIcon(
|
|
675686
|
+
`${imageFitIcon(fit5.score)} ${String(fit5.score).padStart(3)}/100 ${c3.bold(preset.label)}${primary}${diskInfo}`
|
|
674957
675687
|
);
|
|
674958
675688
|
renderInfo(` id: ${preset.id}`);
|
|
674959
675689
|
renderInfo(
|
|
674960
|
-
` type: ${preset.backend} · ${preset.sizeClass ?? "unknown size"} · ${
|
|
675690
|
+
` type: ${preset.backend} · ${preset.sizeClass ?? "unknown size"} · ${fit5.label}`
|
|
674961
675691
|
);
|
|
674962
675692
|
renderImagePresetDetail(" quality: ", preset.quality ?? preset.note);
|
|
674963
|
-
renderImagePresetDetail(" fit: ",
|
|
675693
|
+
renderImagePresetDetail(" fit: ", fit5.note);
|
|
674964
675694
|
if (preset.deployment)
|
|
674965
675695
|
renderImagePresetDetail(" deploy: ", preset.deployment);
|
|
674966
675696
|
}
|
|
@@ -675103,13 +675833,13 @@ async function showImageModelsMenu(ctx3, hasLocal) {
|
|
|
675103
675833
|
() => /* @__PURE__ */ new Map()
|
|
675104
675834
|
);
|
|
675105
675835
|
const buildModelItem = (preset) => {
|
|
675106
|
-
const
|
|
675836
|
+
const fit5 = rateImagePresetForHardware(preset, specs);
|
|
675107
675837
|
const disk = imageModelDiskStats(ctx3, preset, ollamaSizes);
|
|
675108
675838
|
const downloaded = disk.downloaded ? `${c3.green("✓")} ` : "";
|
|
675109
675839
|
return {
|
|
675110
675840
|
key: `model:${preset.id}`,
|
|
675111
|
-
label: `${downloaded}${imageFitIcon(
|
|
675112
|
-
detail: `${
|
|
675841
|
+
label: `${downloaded}${imageFitIcon(fit5.score)} ${String(fit5.score).padStart(3)}/100 ${preset.label}`,
|
|
675842
|
+
detail: `${fit5.score}/100 ${fit5.label} · ${preset.category ?? preset.backend} · ${preset.sizeClass ?? preset.id}${downloadedModelSuffix(disk)}`
|
|
675113
675843
|
};
|
|
675114
675844
|
};
|
|
675115
675845
|
const items = [
|
|
@@ -675194,9 +675924,9 @@ async function showImageModelsMenu(ctx3, hasLocal) {
|
|
|
675194
675924
|
renderInfo(
|
|
675195
675925
|
`Image model: ${model} (${backend})${hasLocal ? " (project-local)" : ""}`
|
|
675196
675926
|
);
|
|
675197
|
-
const
|
|
675198
|
-
if (
|
|
675199
|
-
renderInfo(`Hardware fit: ${
|
|
675927
|
+
const fit5 = preset ? rateImagePresetForHardware(preset, specs) : void 0;
|
|
675928
|
+
if (fit5)
|
|
675929
|
+
renderInfo(`Hardware fit: ${fit5.score}/100 ${fit5.label} — ${fit5.note}`);
|
|
675200
675930
|
if (preset?.install) renderInfo(`Prewarm command: ${preset.install}`);
|
|
675201
675931
|
await prewarmImageModel(ctx3, model, backend);
|
|
675202
675932
|
}
|
|
@@ -675512,19 +676242,19 @@ async function renderVideoModelList(ctx3) {
|
|
|
675512
676242
|
renderInfo("");
|
|
675513
676243
|
renderInfo(c3.bold(category));
|
|
675514
676244
|
for (const preset of presets) {
|
|
675515
|
-
const
|
|
676245
|
+
const fit5 = rateVideoPresetForHardware(preset, specs);
|
|
675516
676246
|
const disk = videoModelDiskStats(ctx3, preset);
|
|
675517
676247
|
const diskInfo = disk.downloaded ? ` ${c3.green("✓")} ${formatFileSize(disk.bytes)}` : "";
|
|
675518
676248
|
renderInfo(
|
|
675519
|
-
`${imageFitIcon(
|
|
676249
|
+
`${imageFitIcon(fit5.score)} ${String(fit5.score).padStart(3)}/100 ${c3.bold(preset.label)}${diskInfo}`
|
|
675520
676250
|
);
|
|
675521
676251
|
renderInfo(` id: ${preset.id}`);
|
|
675522
676252
|
renderInfo(
|
|
675523
|
-
` type: ${preset.backend} · ${preset.sizeClass} · ${preset.kinds.join("/")} · ${
|
|
676253
|
+
` type: ${preset.backend} · ${preset.sizeClass} · ${preset.kinds.join("/")} · ${fit5.label}`
|
|
675524
676254
|
);
|
|
675525
676255
|
renderImagePresetDetail(" quality: ", preset.quality);
|
|
675526
676256
|
renderImagePresetDetail(" output: ", preset.output);
|
|
675527
|
-
renderImagePresetDetail(" fit: ",
|
|
676257
|
+
renderImagePresetDetail(" fit: ", fit5.note);
|
|
675528
676258
|
renderImagePresetDetail(" deploy: ", preset.deployment);
|
|
675529
676259
|
if (preset.licenseNote)
|
|
675530
676260
|
renderImagePresetDetail(" license: ", preset.licenseNote);
|
|
@@ -675535,13 +676265,13 @@ async function showVideoModelsMenu(ctx3, hasLocal) {
|
|
|
675535
676265
|
const settings = resolveSettings(ctx3.repoRoot);
|
|
675536
676266
|
const specs = await detectSystemSpecsAsync();
|
|
675537
676267
|
const buildModelItem = (preset) => {
|
|
675538
|
-
const
|
|
676268
|
+
const fit5 = rateVideoPresetForHardware(preset, specs);
|
|
675539
676269
|
const disk = videoModelDiskStats(ctx3, preset);
|
|
675540
676270
|
const downloaded = disk.downloaded ? `${c3.green("✓")} ` : "";
|
|
675541
676271
|
return {
|
|
675542
676272
|
key: `model:${preset.id}`,
|
|
675543
|
-
label: `${downloaded}${imageFitIcon(
|
|
675544
|
-
detail: `${
|
|
676273
|
+
label: `${downloaded}${imageFitIcon(fit5.score)} ${String(fit5.score).padStart(3)}/100 ${preset.label}`,
|
|
676274
|
+
detail: `${fit5.label} · ${preset.category} · ${preset.kinds.join("/")}${downloadedModelSuffix(disk)}`
|
|
675545
676275
|
};
|
|
675546
676276
|
};
|
|
675547
676277
|
const items = [
|
|
@@ -675620,8 +676350,8 @@ async function showVideoModelsMenu(ctx3, hasLocal) {
|
|
|
675620
676350
|
`Video model: ${model} (${backend})${hasLocal ? " (project-local)" : ""}`
|
|
675621
676351
|
);
|
|
675622
676352
|
if (preset) {
|
|
675623
|
-
const
|
|
675624
|
-
renderInfo(`Hardware fit: ${
|
|
676353
|
+
const fit5 = rateVideoPresetForHardware(preset, specs);
|
|
676354
|
+
renderInfo(`Hardware fit: ${fit5.score}/100 ${fit5.label} — ${fit5.note}`);
|
|
675625
676355
|
if (preset.licenseNote) renderInfo(`License: ${preset.licenseNote}`);
|
|
675626
676356
|
if (preset.install) renderInfo(`Prewarm command: ${preset.install}`);
|
|
675627
676357
|
}
|
|
@@ -675883,19 +676613,19 @@ async function renderAudioModelList(ctx3, kind) {
|
|
|
675883
676613
|
renderInfo("");
|
|
675884
676614
|
renderInfo(c3.bold(category));
|
|
675885
676615
|
for (const preset of presets) {
|
|
675886
|
-
const
|
|
676616
|
+
const fit5 = rateAudioPresetForHardware(preset, specs);
|
|
675887
676617
|
const disk = audioModelDiskStats(ctx3, preset);
|
|
675888
676618
|
const diskInfo = disk.downloaded ? ` ${c3.green("✓")} ${formatFileSize(disk.bytes)}` : "";
|
|
675889
676619
|
renderInfo(
|
|
675890
|
-
`${audioFitIcon(
|
|
676620
|
+
`${audioFitIcon(fit5.score)} ${String(fit5.score).padStart(3)}/100 ${c3.bold(preset.label)}${diskInfo}`
|
|
675891
676621
|
);
|
|
675892
676622
|
renderInfo(` id: ${preset.id}`);
|
|
675893
676623
|
renderInfo(
|
|
675894
|
-
` type: ${preset.backend} · ${preset.sizeClass} · ${
|
|
676624
|
+
` type: ${preset.backend} · ${preset.sizeClass} · ${fit5.label}`
|
|
675895
676625
|
);
|
|
675896
676626
|
renderImagePresetDetail(" quality: ", preset.quality);
|
|
675897
676627
|
renderImagePresetDetail(" output: ", preset.output);
|
|
675898
|
-
renderImagePresetDetail(" fit: ",
|
|
676628
|
+
renderImagePresetDetail(" fit: ", fit5.note);
|
|
675899
676629
|
renderImagePresetDetail(" deploy: ", preset.deployment);
|
|
675900
676630
|
}
|
|
675901
676631
|
}
|
|
@@ -675920,13 +676650,13 @@ async function showAudioGenerationMenu(ctx3, hasLocal, kind) {
|
|
|
675920
676650
|
const activeModel = activeAudioModel(settings, kind);
|
|
675921
676651
|
const title = kind === "music" ? "Music Generation" : "Sound Generation";
|
|
675922
676652
|
const buildModelItem = (preset) => {
|
|
675923
|
-
const
|
|
676653
|
+
const fit5 = rateAudioPresetForHardware(preset, specs);
|
|
675924
676654
|
const disk = audioModelDiskStats(ctx3, preset);
|
|
675925
676655
|
const downloaded = disk.downloaded ? `${c3.green("✓")} ` : "";
|
|
675926
676656
|
return {
|
|
675927
676657
|
key: `model:${preset.id}`,
|
|
675928
|
-
label: `${downloaded}${audioFitIcon(
|
|
675929
|
-
detail: `${
|
|
676658
|
+
label: `${downloaded}${audioFitIcon(fit5.score)} ${String(fit5.score).padStart(3)}/100 ${preset.label}`,
|
|
676659
|
+
detail: `${fit5.label} · ${preset.category} · ${preset.sizeClass}${downloadedModelSuffix(disk)}`
|
|
675930
676660
|
};
|
|
675931
676661
|
};
|
|
675932
676662
|
const setupItems = kind === "music" ? [
|
|
@@ -676047,8 +676777,8 @@ async function showAudioGenerationMenu(ctx3, hasLocal, kind) {
|
|
|
676047
676777
|
`${kind === "music" ? "Music" : "Sound"} model: ${model} (${backend})${hasLocal ? " (project-local)" : ""}`
|
|
676048
676778
|
);
|
|
676049
676779
|
if (preset) {
|
|
676050
|
-
const
|
|
676051
|
-
renderInfo(`Hardware fit: ${
|
|
676780
|
+
const fit5 = rateAudioPresetForHardware(preset, specs);
|
|
676781
|
+
renderInfo(`Hardware fit: ${fit5.score}/100 ${fit5.label} - ${fit5.note}`);
|
|
676052
676782
|
renderInfo(`Prewarm command: ${preset.install}`);
|
|
676053
676783
|
}
|
|
676054
676784
|
await prewarmAudioModel(ctx3, kind, model, backend);
|
|
@@ -685261,8 +685991,8 @@ var init_carousel = __esm({
|
|
|
685261
685991
|
this.rebuildRibbons();
|
|
685262
685992
|
}
|
|
685263
685993
|
rebuildRibbons() {
|
|
685264
|
-
for (const
|
|
685265
|
-
|
|
685994
|
+
for (const row2 of this.rows) {
|
|
685995
|
+
row2.renderedPlain = buildPlainRibbon(row2.phrases, this.width);
|
|
685266
685996
|
}
|
|
685267
685997
|
}
|
|
685268
685998
|
/**
|
|
@@ -685288,10 +686018,10 @@ var init_carousel = __esm({
|
|
|
685288
686018
|
process.stdout.on("resize", this.resizeHandler);
|
|
685289
686019
|
this.renderFrame();
|
|
685290
686020
|
this.timer = setInterval(() => {
|
|
685291
|
-
for (const
|
|
685292
|
-
|
|
685293
|
-
if (Math.abs(
|
|
685294
|
-
|
|
686021
|
+
for (const row2 of this.rows) {
|
|
686022
|
+
row2.offset += row2.speed * row2.direction;
|
|
686023
|
+
if (Math.abs(row2.offset) > row2.renderedPlain.length / 2) {
|
|
686024
|
+
row2.offset = 0;
|
|
685295
686025
|
}
|
|
685296
686026
|
}
|
|
685297
686027
|
this.renderFrame();
|
|
@@ -685320,18 +686050,18 @@ var init_carousel = __esm({
|
|
|
685320
686050
|
* Extract a terminal-width colored window from a scrolling ribbon.
|
|
685321
686051
|
* Uses column-aware width to prevent CJK/fullwidth character overflow.
|
|
685322
686052
|
*/
|
|
685323
|
-
extractWindow(
|
|
686053
|
+
extractWindow(row2) {
|
|
685324
686054
|
const maxCols = this.width;
|
|
685325
|
-
const plain =
|
|
686055
|
+
const plain = row2.renderedPlain;
|
|
685326
686056
|
if (!plain) return "";
|
|
685327
|
-
let start2 = Math.floor(Math.abs(
|
|
686057
|
+
let start2 = Math.floor(Math.abs(row2.offset)) % plain.length;
|
|
685328
686058
|
if (start2 < 0) start2 += plain.length;
|
|
685329
686059
|
const separator = " : ";
|
|
685330
686060
|
let coloredLine = "";
|
|
685331
686061
|
let colCount = 0;
|
|
685332
686062
|
let charInPhrase = 0;
|
|
685333
686063
|
let skipChars = start2;
|
|
685334
|
-
const phrases =
|
|
686064
|
+
const phrases = row2.phrases;
|
|
685335
686065
|
let fullIdx = 0;
|
|
685336
686066
|
while (skipChars > 0) {
|
|
685337
686067
|
const p2 = phrases[fullIdx % phrases.length];
|
|
@@ -685491,15 +686221,15 @@ function createCohereBanner() {
|
|
|
685491
686221
|
const fgColor = 226;
|
|
685492
686222
|
const halftone = ["█", "▓", "▒", "░", " "];
|
|
685493
686223
|
for (let r2 = 0; r2 < rows; r2++) {
|
|
685494
|
-
const
|
|
686224
|
+
const row2 = [];
|
|
685495
686225
|
for (let c9 = 0; c9 < width; c9++) {
|
|
685496
686226
|
const distFromCenter = Math.abs(c9 - width / 2) / (width / 2);
|
|
685497
686227
|
const htIdx = Math.min(halftone.length - 1, Math.floor(distFromCenter * halftone.length));
|
|
685498
686228
|
const char = r2 === 0 || r2 === 2 ? halftone[htIdx] : " ";
|
|
685499
686229
|
const charFg = r2 === 1 ? fgColor : 238;
|
|
685500
|
-
|
|
686230
|
+
row2.push({ char, fg: charFg, bg: bgColor, bold: false });
|
|
685501
686231
|
}
|
|
685502
|
-
grid.push(
|
|
686232
|
+
grid.push(row2);
|
|
685503
686233
|
}
|
|
685504
686234
|
const text2 = "COHERE — Distributed Cognitive Commons";
|
|
685505
686235
|
const startCol = Math.max(0, Math.floor((width - text2.length) / 2));
|
|
@@ -685522,11 +686252,11 @@ function createSponsorBanner(sponsorName, tagline, primaryColor = 214, bgColor =
|
|
|
685522
686252
|
const rows = headerHeight();
|
|
685523
686253
|
const grid = [];
|
|
685524
686254
|
for (let r2 = 0; r2 < rows; r2++) {
|
|
685525
|
-
const
|
|
686255
|
+
const row2 = [];
|
|
685526
686256
|
for (let c9 = 0; c9 < width; c9++) {
|
|
685527
|
-
|
|
686257
|
+
row2.push({ char: " ", fg: primaryColor, bg: bgColor, bold: false });
|
|
685528
686258
|
}
|
|
685529
|
-
grid.push(
|
|
686259
|
+
grid.push(row2);
|
|
685530
686260
|
}
|
|
685531
686261
|
const nameText = ` ${sponsorName}`;
|
|
685532
686262
|
for (let i2 = 0; i2 < nameText.length && i2 < width; i2++) {
|
|
@@ -685577,19 +686307,19 @@ function listBannerDesigns(workDir) {
|
|
|
685577
686307
|
function createEmptyGrid(width, rows = 3) {
|
|
685578
686308
|
const grid = [];
|
|
685579
686309
|
for (let r2 = 0; r2 < rows; r2++) {
|
|
685580
|
-
const
|
|
686310
|
+
const row2 = [];
|
|
685581
686311
|
for (let c9 = 0; c9 < width; c9++) {
|
|
685582
|
-
|
|
686312
|
+
row2.push({ char: " ", fg: -1, bg: -1, bold: false });
|
|
685583
686313
|
}
|
|
685584
|
-
grid.push(
|
|
686314
|
+
grid.push(row2);
|
|
685585
686315
|
}
|
|
685586
686316
|
return grid;
|
|
685587
686317
|
}
|
|
685588
|
-
function setGridText(grid,
|
|
685589
|
-
if (!grid[
|
|
686318
|
+
function setGridText(grid, row2, col, text2, fg2 = -1, bg = -1, bold = false) {
|
|
686319
|
+
if (!grid[row2]) return;
|
|
685590
686320
|
for (let i2 = 0; i2 < text2.length; i2++) {
|
|
685591
|
-
if (col + i2 < grid[
|
|
685592
|
-
grid[
|
|
686321
|
+
if (col + i2 < grid[row2].length) {
|
|
686322
|
+
grid[row2][col + i2] = { char: text2[i2], fg: fg2, bg, bold };
|
|
685593
686323
|
}
|
|
685594
686324
|
}
|
|
685595
686325
|
}
|
|
@@ -685833,11 +686563,11 @@ var init_banner = __esm({
|
|
|
685833
686563
|
const L = layout();
|
|
685834
686564
|
for (let r2 = 0; r2 < this.rows; r2++) {
|
|
685835
686565
|
buf += `\x1B[${L.headerTop + r2};1H${tuiBg() >= 0 ? `\x1B[48;5;${tuiBg()}m` : "\x1B[49m"}\x1B[2K`;
|
|
685836
|
-
const
|
|
685837
|
-
if (!
|
|
686566
|
+
const row2 = frame.grid[r2];
|
|
686567
|
+
if (!row2) continue;
|
|
685838
686568
|
let prevFg = -1, prevBg = -1, prevBold = false;
|
|
685839
|
-
for (let c9 = 0; c9 < Math.min(this.width,
|
|
685840
|
-
const cell =
|
|
686569
|
+
for (let c9 = 0; c9 < Math.min(this.width, row2.length); c9++) {
|
|
686570
|
+
const cell = row2[c9];
|
|
685841
686571
|
let char = cell.char;
|
|
685842
686572
|
if (defaultBoxSeparators?.has(c9 + 1)) {
|
|
685843
686573
|
if (r2 === 0) char = "┬";
|
|
@@ -685989,8 +686719,8 @@ function generateDescriptors(repoRoot) {
|
|
|
685989
686719
|
if (repoName2 && !tags.includes(repoName2)) {
|
|
685990
686720
|
tags.push(repoName2);
|
|
685991
686721
|
}
|
|
685992
|
-
const
|
|
685993
|
-
const phrases =
|
|
686722
|
+
const unique3 = [...new Set(tags.map((t2) => t2.toLowerCase().trim()).filter((t2) => t2.length > 1 && t2.length < 60))];
|
|
686723
|
+
const phrases = unique3.map((text2) => ({
|
|
685994
686724
|
text: text2,
|
|
685995
686725
|
color: weightedColor(profile)
|
|
685996
686726
|
}));
|
|
@@ -686011,7 +686741,7 @@ function generateDescriptors(repoRoot) {
|
|
|
686011
686741
|
];
|
|
686012
686742
|
for (const fb of fallbacks) {
|
|
686013
686743
|
if (phrases.length >= 20) break;
|
|
686014
|
-
if (!
|
|
686744
|
+
if (!unique3.includes(fb)) {
|
|
686015
686745
|
phrases.push({ text: fb, color: weightedColor(profile) });
|
|
686016
686746
|
}
|
|
686017
686747
|
}
|
|
@@ -691938,13 +692668,13 @@ function buildScopedToolList(scope) {
|
|
|
691938
692668
|
const commandSigs = commands.flatMap((cmd) => cmd.signatures);
|
|
691939
692669
|
const allSigs = [...syntheticSigs, ...commandSigs];
|
|
691940
692670
|
const seen = /* @__PURE__ */ new Set();
|
|
691941
|
-
const
|
|
692671
|
+
const unique3 = allSigs.filter((sig) => {
|
|
691942
692672
|
if (seen.has(sig.signature)) return false;
|
|
691943
692673
|
seen.add(sig.signature);
|
|
691944
692674
|
return true;
|
|
691945
692675
|
});
|
|
691946
692676
|
const entries = [];
|
|
691947
|
-
for (const sig of
|
|
692677
|
+
for (const sig of unique3) {
|
|
691948
692678
|
const matchingCmd = commands.find(
|
|
691949
692679
|
(cmd) => cmd.signatures.some((s2) => s2.signature === sig.signature)
|
|
691950
692680
|
);
|
|
@@ -697045,14 +697775,14 @@ function parseTelegramReplyPreferenceUpdate(parsed) {
|
|
|
697045
697775
|
}
|
|
697046
697776
|
function uniqueTelegramJsonCandidates(candidates) {
|
|
697047
697777
|
const seen = /* @__PURE__ */ new Set();
|
|
697048
|
-
const
|
|
697778
|
+
const unique3 = [];
|
|
697049
697779
|
for (const candidate of candidates) {
|
|
697050
697780
|
const clean5 = candidate.trim();
|
|
697051
697781
|
if (!clean5 || seen.has(clean5)) continue;
|
|
697052
697782
|
seen.add(clean5);
|
|
697053
|
-
|
|
697783
|
+
unique3.push(clean5);
|
|
697054
697784
|
}
|
|
697055
|
-
return
|
|
697785
|
+
return unique3;
|
|
697056
697786
|
}
|
|
697057
697787
|
function extractBalancedTelegramJsonObjects(text2) {
|
|
697058
697788
|
const objects = [];
|
|
@@ -698051,10 +698781,10 @@ function telegramHistoryTime(entry) {
|
|
|
698051
698781
|
});
|
|
698052
698782
|
}
|
|
698053
698783
|
function formatTelegramIdentitySignals(signals) {
|
|
698054
|
-
const
|
|
698784
|
+
const unique3 = [
|
|
698055
698785
|
...new Set(signals.map((signal) => signal.trim()).filter(Boolean))
|
|
698056
698786
|
];
|
|
698057
|
-
return
|
|
698787
|
+
return unique3.length > 0 ? unique3.join(", ") : "none";
|
|
698058
698788
|
}
|
|
698059
698789
|
function summarizeTelegramMessageAttachments(msg) {
|
|
698060
698790
|
const parts = [];
|
|
@@ -698540,12 +699270,12 @@ function buildTelegramHelpHTML(scope, maxPublicCommands = 24) {
|
|
|
698540
699270
|
...commands.flatMap((cmd) => cmd.signatures)
|
|
698541
699271
|
];
|
|
698542
699272
|
const seen = /* @__PURE__ */ new Set();
|
|
698543
|
-
const
|
|
699273
|
+
const unique3 = signatures.filter((sig) => {
|
|
698544
699274
|
if (seen.has(sig.signature)) return false;
|
|
698545
699275
|
seen.add(sig.signature);
|
|
698546
699276
|
return true;
|
|
698547
699277
|
});
|
|
698548
|
-
const visible = scope === "public" ?
|
|
699278
|
+
const visible = scope === "public" ? unique3.slice(0, maxPublicCommands) : unique3;
|
|
698549
699279
|
const lines = [
|
|
698550
699280
|
`<b>Commands (${scope === "admin" ? "admin full scope" : "public secure scope"})</b>`,
|
|
698551
699281
|
"",
|
|
@@ -698553,7 +699283,7 @@ function buildTelegramHelpHTML(scope, maxPublicCommands = 24) {
|
|
|
698553
699283
|
(sig) => `<code>${escapeTelegramHTML(sig.signature)}</code> - ${escapeTelegramHTML(sig.description)}`
|
|
698554
699284
|
)
|
|
698555
699285
|
];
|
|
698556
|
-
if (scope === "public" &&
|
|
699286
|
+
if (scope === "public" && unique3.length > visible.length) {
|
|
698557
699287
|
lines.push("");
|
|
698558
699288
|
lines.push(
|
|
698559
699289
|
`Public scope truncated to ${visible.length} safe commands. Authenticate as admin for full command help.`
|
|
@@ -701384,10 +702114,10 @@ ${message2}`)
|
|
|
701384
702114
|
telegramModelMenuItems(generation) {
|
|
701385
702115
|
return this.telegramGenerationModelDescriptors(generation).map((model) => {
|
|
701386
702116
|
const cached = model.cachedBytes > 0 ? `cached ${formatModelBytes(model.cachedBytes)}` : "not downloaded";
|
|
701387
|
-
const
|
|
702117
|
+
const fit5 = model.recommendedVramGB ? `${model.recommendedVramGB}GB VRAM rec` : model.minVramGB ? `${model.minVramGB}GB VRAM min` : "VRAM n/a";
|
|
701388
702118
|
return {
|
|
701389
702119
|
label: model.label,
|
|
701390
|
-
description: `${model.backend} - ${model.category} - ${
|
|
702120
|
+
description: `${model.backend} - ${model.category} - ${fit5} - ${cached}`,
|
|
701391
702121
|
action: {
|
|
701392
702122
|
type: "model_detail",
|
|
701393
702123
|
generation,
|
|
@@ -703233,13 +703963,13 @@ ${mediaContext}` : ""
|
|
|
703233
703963
|
const store2 = new EpisodeStore(paths.episodes, graph);
|
|
703234
703964
|
let existingTelegramEpisodes = 0;
|
|
703235
703965
|
try {
|
|
703236
|
-
const
|
|
703966
|
+
const row2 = store2.getDb().prepare(
|
|
703237
703967
|
`
|
|
703238
703968
|
SELECT COUNT(*) AS n FROM episodes
|
|
703239
703969
|
WHERE session_id = ? AND metadata LIKE '%"sourceSurface":"telegram"%'
|
|
703240
703970
|
`
|
|
703241
703971
|
).get(sessionKey);
|
|
703242
|
-
existingTelegramEpisodes =
|
|
703972
|
+
existingTelegramEpisodes = row2?.n ?? 0;
|
|
703243
703973
|
} finally {
|
|
703244
703974
|
store2.close();
|
|
703245
703975
|
graph.close();
|
|
@@ -704754,9 +705484,9 @@ ${lines.join("\n")}`;
|
|
|
704754
705484
|
if (!db) return "";
|
|
704755
705485
|
const rows = /* @__PURE__ */ new Map();
|
|
704756
705486
|
const addRows = (items) => {
|
|
704757
|
-
for (const
|
|
704758
|
-
const key = Number(
|
|
704759
|
-
if (Number.isFinite(key)) rows.set(key,
|
|
705487
|
+
for (const row2 of items) {
|
|
705488
|
+
const key = Number(row2.rowid);
|
|
705489
|
+
if (Number.isFinite(key)) rows.set(key, row2);
|
|
704760
705490
|
}
|
|
704761
705491
|
};
|
|
704762
705492
|
try {
|
|
@@ -704803,11 +705533,11 @@ ${lines.join("\n")}`;
|
|
|
704803
705533
|
}
|
|
704804
705534
|
const selected = [...rows.values()].sort((a2, b) => Number(b.received_at ?? 0) - Number(a2.received_at ?? 0)).slice(0, limit);
|
|
704805
705535
|
if (selected.length === 0) return "";
|
|
704806
|
-
const lines = selected.map((
|
|
704807
|
-
const when =
|
|
704808
|
-
const speaker =
|
|
704809
|
-
const reply =
|
|
704810
|
-
return `- ${when} ${speaker}/${
|
|
705536
|
+
const lines = selected.map((row2) => {
|
|
705537
|
+
const when = row2.received_at ? new Date(Number(row2.received_at)).toISOString() : "";
|
|
705538
|
+
const speaker = row2.role === "assistant" ? `@${this.state.botUsername || "omnius"}` : row2.username ? `@${row2.username}` : row2.from_user_id ? `user:${row2.from_user_id}` : "unknown";
|
|
705539
|
+
const reply = row2.reply_to_message_id ? ` reply_to:${row2.reply_to_message_id}` : "";
|
|
705540
|
+
return `- ${when} ${speaker}/${row2.role || "user"} msg:${row2.message_id}${reply}: ${telegramContextJsonString(String(row2.text || ""), 260)}`;
|
|
704811
705541
|
});
|
|
704812
705542
|
return [
|
|
704813
705543
|
"### SQLite Telegram Raw Mirror Recall",
|
|
@@ -704886,16 +705616,16 @@ ${lines.join("\n")}`;
|
|
|
704886
705616
|
LIMIT ?
|
|
704887
705617
|
`
|
|
704888
705618
|
).all(sessionKey, limit);
|
|
704889
|
-
return rows.reverse().map((
|
|
705619
|
+
return rows.reverse().map((row2) => this.telegramSqliteRowToHistoryEntry(row2));
|
|
704890
705620
|
} catch {
|
|
704891
705621
|
return [];
|
|
704892
705622
|
}
|
|
704893
705623
|
}
|
|
704894
|
-
telegramSqliteRowIsBot(
|
|
704895
|
-
if (
|
|
704896
|
-
if (
|
|
705624
|
+
telegramSqliteRowIsBot(row2) {
|
|
705625
|
+
if (row2.role === "assistant") return true;
|
|
705626
|
+
if (row2.from_is_bot === 1 || row2.from_is_bot === true) return true;
|
|
704897
705627
|
for (const key of ["normalized_json", "raw_json"]) {
|
|
704898
|
-
const raw =
|
|
705628
|
+
const raw = row2?.[key];
|
|
704899
705629
|
if (typeof raw !== "string" || !raw.trim()) continue;
|
|
704900
705630
|
try {
|
|
704901
705631
|
const parsed = JSON.parse(raw);
|
|
@@ -704906,31 +705636,31 @@ ${lines.join("\n")}`;
|
|
|
704906
705636
|
}
|
|
704907
705637
|
return false;
|
|
704908
705638
|
}
|
|
704909
|
-
telegramSqliteRowToHistoryEntry(
|
|
705639
|
+
telegramSqliteRowToHistoryEntry(row2) {
|
|
704910
705640
|
const num3 = (value2) => {
|
|
704911
705641
|
const n2 = Number(value2);
|
|
704912
705642
|
return Number.isFinite(n2) ? n2 : void 0;
|
|
704913
705643
|
};
|
|
704914
|
-
const role =
|
|
704915
|
-
const username =
|
|
704916
|
-
const fromUserId = num3(
|
|
704917
|
-
const isBot = this.telegramSqliteRowIsBot(
|
|
705644
|
+
const role = row2.role === "assistant" ? "assistant" : "user";
|
|
705645
|
+
const username = row2.username ? String(row2.username) : void 0;
|
|
705646
|
+
const fromUserId = num3(row2.from_user_id);
|
|
705647
|
+
const isBot = this.telegramSqliteRowIsBot(row2);
|
|
704918
705648
|
return {
|
|
704919
705649
|
role,
|
|
704920
|
-
text: String(
|
|
704921
|
-
ts: num3(
|
|
704922
|
-
chatId:
|
|
705650
|
+
text: String(row2.text || ""),
|
|
705651
|
+
ts: num3(row2.received_at),
|
|
705652
|
+
chatId: row2.chat_id,
|
|
704923
705653
|
speaker: role === "assistant" ? `@${this.state.botUsername || username || "omnius"}` : username ? `@${username}` : fromUserId !== void 0 ? isBot ? `bot:${fromUserId}` : `user:${fromUserId}` : "unknown",
|
|
704924
705654
|
username,
|
|
704925
|
-
firstName:
|
|
705655
|
+
firstName: row2.first_name ? String(row2.first_name) : void 0,
|
|
704926
705656
|
fromUserId,
|
|
704927
705657
|
isBot,
|
|
704928
|
-
messageId: num3(
|
|
704929
|
-
messageThreadId: num3(
|
|
704930
|
-
replyToMessageId: num3(
|
|
704931
|
-
chatType:
|
|
704932
|
-
chatTitle:
|
|
704933
|
-
mediaSummary:
|
|
705658
|
+
messageId: num3(row2.message_id),
|
|
705659
|
+
messageThreadId: num3(row2.message_thread_id),
|
|
705660
|
+
replyToMessageId: num3(row2.reply_to_message_id),
|
|
705661
|
+
chatType: row2.chat_type,
|
|
705662
|
+
chatTitle: row2.chat_title || void 0,
|
|
705663
|
+
mediaSummary: row2.media_json ? "media attached in raw Telegram SQLite mirror" : void 0
|
|
704934
705664
|
};
|
|
704935
705665
|
}
|
|
704936
705666
|
telegramMergedHistoryForSession(sessionKey, limit = TELEGRAM_CHAT_HISTORY_LIMIT) {
|
|
@@ -704977,7 +705707,7 @@ ${lines.join("\n")}`;
|
|
|
704977
705707
|
if (earliestRows.length > 0 || latestRow) {
|
|
704978
705708
|
return {
|
|
704979
705709
|
earliest: earliestRows.map(
|
|
704980
|
-
(
|
|
705710
|
+
(row2) => this.telegramSqliteRowToHistoryEntry(row2)
|
|
704981
705711
|
),
|
|
704982
705712
|
latest: latestRow ? this.telegramSqliteRowToHistoryEntry(latestRow) : void 0
|
|
704983
705713
|
};
|
|
@@ -705044,17 +705774,17 @@ ${lines.join("\n")}`;
|
|
|
705044
705774
|
LIMIT ?
|
|
705045
705775
|
`
|
|
705046
705776
|
).all(...params, limit);
|
|
705047
|
-
return rows.map((
|
|
705048
|
-
const role =
|
|
705049
|
-
const fromUserId = Number(
|
|
705050
|
-
const isBot = role === "assistant" ||
|
|
705051
|
-
const speaker = role === "assistant" ? `@${this.state.botUsername ||
|
|
705052
|
-
const firstTs = Number(
|
|
705053
|
-
const lastTs = Number(
|
|
705777
|
+
return rows.map((row2) => {
|
|
705778
|
+
const role = row2.role === "assistant" ? "assistant" : "user";
|
|
705779
|
+
const fromUserId = Number(row2.from_user_id);
|
|
705780
|
+
const isBot = role === "assistant" || row2.from_is_bot === 1 || row2.from_is_bot === true;
|
|
705781
|
+
const speaker = role === "assistant" ? `@${this.state.botUsername || row2.username || "omnius"}` : row2.username ? `@${row2.username}` : Number.isFinite(fromUserId) ? isBot ? `bot:${fromUserId}` : `user:${fromUserId}` : row2.first_name || "unknown";
|
|
705782
|
+
const firstTs = Number(row2.first_ts);
|
|
705783
|
+
const lastTs = Number(row2.last_ts);
|
|
705054
705784
|
return {
|
|
705055
705785
|
speaker,
|
|
705056
705786
|
isBot,
|
|
705057
|
-
count: Number(
|
|
705787
|
+
count: Number(row2.n) || 0,
|
|
705058
705788
|
firstTs: Number.isFinite(firstTs) ? firstTs : void 0,
|
|
705059
705789
|
lastTs: Number.isFinite(lastTs) ? lastTs : void 0
|
|
705060
705790
|
};
|
|
@@ -705110,9 +705840,9 @@ ${lines.join("\n")}`;
|
|
|
705110
705840
|
);
|
|
705111
705841
|
const rows = /* @__PURE__ */ new Map();
|
|
705112
705842
|
const addRows = (items) => {
|
|
705113
|
-
for (const
|
|
705114
|
-
const key = Number(
|
|
705115
|
-
if (Number.isFinite(key)) rows.set(key,
|
|
705843
|
+
for (const row2 of items) {
|
|
705844
|
+
const key = Number(row2.rowid);
|
|
705845
|
+
if (Number.isFinite(key)) rows.set(key, row2);
|
|
705116
705846
|
}
|
|
705117
705847
|
};
|
|
705118
705848
|
const baseWhere = (extraClauses = [], extraParams = []) => {
|
|
@@ -705191,13 +705921,13 @@ ${lines.join("\n")}`;
|
|
|
705191
705921
|
}).slice(0, limit);
|
|
705192
705922
|
}
|
|
705193
705923
|
formatTelegramSqliteMirrorRows(rows, maxText = 260) {
|
|
705194
|
-
return rows.map((
|
|
705195
|
-
const when =
|
|
705196
|
-
const speaker =
|
|
705197
|
-
const kind =
|
|
705198
|
-
const reply =
|
|
705199
|
-
const media =
|
|
705200
|
-
return `- ${when} ${speaker}/${
|
|
705924
|
+
return rows.map((row2) => {
|
|
705925
|
+
const when = row2.received_at ? new Date(Number(row2.received_at)).toISOString() : "";
|
|
705926
|
+
const speaker = row2.role === "assistant" ? `@${this.state.botUsername || "omnius"}` : row2.username ? `@${row2.username}` : row2.from_user_id ? this.telegramSqliteRowIsBot(row2) ? `bot:${row2.from_user_id}` : `user:${row2.from_user_id}` : "unknown";
|
|
705927
|
+
const kind = row2.role === "assistant" || this.telegramSqliteRowIsBot(row2) ? "bot" : "human";
|
|
705928
|
+
const reply = row2.reply_to_message_id ? ` reply_to:${row2.reply_to_message_id}` : "";
|
|
705929
|
+
const media = row2.media_json ? " media:attached" : "";
|
|
705930
|
+
return `- ${when} ${speaker}/${row2.role || "user"} [${kind}] msg:${row2.message_id}${reply}${media}: ${telegramContextJsonString(String(row2.text || ""), maxText)}`;
|
|
705201
705931
|
}).join("\n");
|
|
705202
705932
|
}
|
|
705203
705933
|
searchTelegramEpisodeMemory(sessionKey, query, limit = 8) {
|
|
@@ -712613,20 +713343,20 @@ Scoped workspace: ${scopedRoot}`,
|
|
|
712613
713343
|
};
|
|
712614
713344
|
}
|
|
712615
713345
|
async deleteTelegramMessages(chatId, messageIds, currentMsg) {
|
|
712616
|
-
const
|
|
712617
|
-
if (
|
|
713346
|
+
const unique3 = [...new Set(messageIds)].filter((id2) => Number.isFinite(id2));
|
|
713347
|
+
if (unique3.length === 0)
|
|
712618
713348
|
throw new Error(
|
|
712619
713349
|
"deleteTelegramMessages requires at least one message id."
|
|
712620
713350
|
);
|
|
712621
713351
|
await this.assertTelegramBotRightsForAction(
|
|
712622
713352
|
"delete_messages",
|
|
712623
713353
|
chatId,
|
|
712624
|
-
|
|
713354
|
+
unique3,
|
|
712625
713355
|
currentMsg
|
|
712626
713356
|
);
|
|
712627
713357
|
const chunks = [];
|
|
712628
|
-
for (let idx = 0; idx <
|
|
712629
|
-
chunks.push(
|
|
713358
|
+
for (let idx = 0; idx < unique3.length; idx += 100)
|
|
713359
|
+
chunks.push(unique3.slice(idx, idx + 100));
|
|
712630
713360
|
const results = [];
|
|
712631
713361
|
for (const chunk of chunks) {
|
|
712632
713362
|
const result = await this.apiCall("deleteMessages", {
|
|
@@ -712644,9 +713374,9 @@ Scoped workspace: ${scopedRoot}`,
|
|
|
712644
713374
|
telegram_method: "deleteMessages",
|
|
712645
713375
|
ok: true,
|
|
712646
713376
|
chat_id: chatId,
|
|
712647
|
-
message_ids:
|
|
713377
|
+
message_ids: unique3,
|
|
712648
713378
|
batches: results,
|
|
712649
|
-
bot_rights_checked: !this.telegramTargetLooksPrivate(chatId, currentMsg) && !
|
|
713379
|
+
bot_rights_checked: !this.telegramTargetLooksPrivate(chatId, currentMsg) && !unique3.every((id2) => this.isKnownAssistantTelegramMessage(chatId, id2)),
|
|
712650
713380
|
policy_scope: this.telegramToolPolicy.chatOverrides?.[String(chatId)] ? "chat" : "global/default"
|
|
712651
713381
|
};
|
|
712652
713382
|
}
|
|
@@ -715520,9 +716250,9 @@ function pushShellLiveLine(state, line) {
|
|
|
715520
716250
|
}
|
|
715521
716251
|
}
|
|
715522
716252
|
function contentRow2(value2, inner) {
|
|
715523
|
-
return `│ ${
|
|
716253
|
+
return `│ ${fit4(value2, inner)} │`;
|
|
715524
716254
|
}
|
|
715525
|
-
function
|
|
716255
|
+
function fit4(value2, width) {
|
|
715526
716256
|
const plain = value2.replace(ANSI_OR_OSC_RE, "").replace(/\s+$/g, "");
|
|
715527
716257
|
const chars = Array.from(plain);
|
|
715528
716258
|
if (chars.length > width) {
|
|
@@ -715595,8 +716325,8 @@ function gibberishTokenPenalty(s2) {
|
|
|
715595
716325
|
const tokens = s2.trim().split(/\s+/).filter(Boolean);
|
|
715596
716326
|
if (tokens.length < 2) return 0;
|
|
715597
716327
|
let penalty = 0;
|
|
715598
|
-
const
|
|
715599
|
-
const uniqueRatio =
|
|
716328
|
+
const unique3 = new Set(tokens.map((t2) => t2.toLowerCase()));
|
|
716329
|
+
const uniqueRatio = unique3.size / tokens.length;
|
|
715600
716330
|
if (tokens.length >= 4 && uniqueRatio <= 0.5) {
|
|
715601
716331
|
penalty += Math.min(1, (0.5 - uniqueRatio) * 2 + 0.5);
|
|
715602
716332
|
}
|
|
@@ -717291,15 +718021,15 @@ var init_mouse_filter = __esm({
|
|
|
717291
718021
|
const hasMarker = Boolean(match[1]);
|
|
717292
718022
|
const btn = parseInt(match[2], 10);
|
|
717293
718023
|
const col = parseInt(match[3], 10);
|
|
717294
|
-
const
|
|
718024
|
+
const row2 = parseInt(match[4], 10);
|
|
717295
718025
|
const suffix = match[5];
|
|
717296
|
-
if (!Number.isFinite(btn) || !Number.isFinite(col) || !Number.isFinite(
|
|
718026
|
+
if (!Number.isFinite(btn) || !Number.isFinite(col) || !Number.isFinite(row2))
|
|
717297
718027
|
return null;
|
|
717298
|
-
if (col <= 0 ||
|
|
718028
|
+
if (col <= 0 || row2 <= 0) return null;
|
|
717299
718029
|
if (!hasMarker && Date.now() > this.expectPrefixlessMouseUntil && !this.isKnownMouseButton(btn))
|
|
717300
718030
|
return null;
|
|
717301
718031
|
if (btn < 0 || btn > 255) return null;
|
|
717302
|
-
return { raw: match[0], btn, col, row, suffix };
|
|
718032
|
+
return { raw: match[0], btn, col, row: row2, suffix };
|
|
717303
718033
|
}
|
|
717304
718034
|
looksLikePartialPrefixlessSgrMouse(input) {
|
|
717305
718035
|
if (input.length < 2) return false;
|
|
@@ -717317,21 +718047,21 @@ var init_mouse_filter = __esm({
|
|
|
717317
718047
|
return false;
|
|
717318
718048
|
}
|
|
717319
718049
|
handleSgrMouse(mouse) {
|
|
717320
|
-
const { btn, col, row, suffix } = mouse;
|
|
718050
|
+
const { btn, col, row: row2, suffix } = mouse;
|
|
717321
718051
|
if ((btn === 64 || btn === 96) && this.onScroll)
|
|
717322
|
-
this.onScroll("up", 3,
|
|
718052
|
+
this.onScroll("up", 3, row2);
|
|
717323
718053
|
else if ((btn === 65 || btn === 97) && this.onScroll)
|
|
717324
|
-
this.onScroll("down", 3,
|
|
718054
|
+
this.onScroll("down", 3, row2);
|
|
717325
718055
|
else if (this.onPointer) {
|
|
717326
718056
|
const hasShift = (btn & 4) !== 0 && btn < 32;
|
|
717327
718057
|
if (btn === 2) {
|
|
717328
718058
|
} else if (hasShift) {
|
|
717329
718059
|
} else if ((btn === 0 || btn === 1) && suffix === "M") {
|
|
717330
|
-
this.onPointer("press", col,
|
|
718060
|
+
this.onPointer("press", col, row2);
|
|
717331
718061
|
} else if (btn >= 32 && btn <= 35 && suffix === "M") {
|
|
717332
|
-
this.onPointer("drag", col,
|
|
718062
|
+
this.onPointer("drag", col, row2);
|
|
717333
718063
|
} else if (suffix === "m") {
|
|
717334
|
-
this.onPointer("release", col,
|
|
718064
|
+
this.onPointer("release", col, row2);
|
|
717335
718065
|
}
|
|
717336
718066
|
}
|
|
717337
718067
|
if (this.onActivity) this.onActivity();
|
|
@@ -717687,10 +718417,10 @@ var init_direct_input = __esm({
|
|
|
717687
718417
|
const hasMarker = Boolean(match[1]);
|
|
717688
718418
|
const btn = parseInt(match[2], 10);
|
|
717689
718419
|
const col = parseInt(match[3], 10);
|
|
717690
|
-
const
|
|
717691
|
-
if (!Number.isFinite(btn) || !Number.isFinite(col) || !Number.isFinite(
|
|
718420
|
+
const row2 = parseInt(match[4], 10);
|
|
718421
|
+
if (!Number.isFinite(btn) || !Number.isFinite(col) || !Number.isFinite(row2))
|
|
717692
718422
|
return null;
|
|
717693
|
-
if (btn < 0 || btn > 255 || col <= 0 ||
|
|
718423
|
+
if (btn < 0 || btn > 255 || col <= 0 || row2 <= 0) return null;
|
|
717694
718424
|
if (!hasMarker && Date.now() > this._expectPrefixlessMouseUntil && !this._isKnownMouseButton(btn))
|
|
717695
718425
|
return null;
|
|
717696
718426
|
return { length: match[0].length };
|
|
@@ -748773,7 +749503,12 @@ function wireAgentToolMinimal(tool, config, repoRoot) {
|
|
|
748773
749503
|
const workerSystem = opts.agentType ? buildSubAgentSystemPrompt(opts.agentType, {
|
|
748774
749504
|
task: opts.task,
|
|
748775
749505
|
focusFiles: opts.focusFiles,
|
|
748776
|
-
exitCriterion: opts.exitCriterion
|
|
749506
|
+
exitCriterion: opts.exitCriterion,
|
|
749507
|
+
trajectory: scopeTrajectoryCheckpoint(
|
|
749508
|
+
_activeRunnerRef?.getTrajectoryCheckpoint?.() ?? null,
|
|
749509
|
+
opts.task,
|
|
749510
|
+
opts.exitCriterion ?? "Return a compact result with a tool observation that verifies it."
|
|
749511
|
+
)
|
|
748777
749512
|
}) : opts.systemPromptAddition;
|
|
748778
749513
|
const systemCtx = workerSystem ? `Working directory: ${repoRoot}
|
|
748779
749514
|
|
|
@@ -749467,6 +750202,11 @@ function formatSubAgentEventForView(event) {
|
|
|
749467
750202
|
const t2 = (event.content ?? "").trim();
|
|
749468
750203
|
return t2 ? `· ${truncateSubAgentViewText(t2, 300)}` : null;
|
|
749469
750204
|
}
|
|
750205
|
+
case "trajectory_checkpoint": {
|
|
750206
|
+
const assessment = event.trajectory?.assessment ?? "updated";
|
|
750207
|
+
const next = event.trajectory?.nextAction ?? "";
|
|
750208
|
+
return `↗ trajectory ${assessment}: ${truncateSubAgentViewText(next, 300)}`;
|
|
750209
|
+
}
|
|
749470
750210
|
case "error": {
|
|
749471
750211
|
const t2 = (event.content ?? "").trim();
|
|
749472
750212
|
return t2 ? `✗ ${truncateSubAgentViewText(t2, 400)}` : null;
|
|
@@ -751977,6 +752717,9 @@ ${entry.fullContent}`
|
|
|
751977
752717
|
}
|
|
751978
752718
|
case "user_interrupt":
|
|
751979
752719
|
break;
|
|
752720
|
+
case "trajectory_checkpoint":
|
|
752721
|
+
statusBar?.updateTrajectoryCheckpoint(event.trajectory ?? null);
|
|
752722
|
+
break;
|
|
751980
752723
|
case "compaction":
|
|
751981
752724
|
if (isNeovimActive()) {
|
|
751982
752725
|
writeToNeovimOutput("\x1B[33m⚠ Context compacted\x1B[0m\r\n");
|
|
@@ -752204,6 +752947,7 @@ When done, either call task_complete with your answer, or use FINAL_VAR(variable
|
|
|
752204
752947
|
}
|
|
752205
752948
|
}
|
|
752206
752949
|
resetSessionLock();
|
|
752950
|
+
statusBar?.updateTrajectoryCheckpoint(null);
|
|
752207
752951
|
const promise = Promise.resolve(
|
|
752208
752952
|
runWithOmniusContext(
|
|
752209
752953
|
{
|
|
@@ -752481,6 +753225,14 @@ When done, either call task_complete with your answer, or use FINAL_VAR(variable
|
|
|
752481
753225
|
cleanForStorage(result.summary)
|
|
752482
753226
|
);
|
|
752483
753227
|
}
|
|
753228
|
+
const finalTrajectory = runner.getTrajectoryCheckpoint();
|
|
753229
|
+
const trajectoryOrientation = finalTrajectory ? {
|
|
753230
|
+
revision: finalTrajectory.revision,
|
|
753231
|
+
assessment: finalTrajectory.assessment,
|
|
753232
|
+
nextAction: cleanForStorage(finalTrajectory.nextAction).slice(0, 360),
|
|
753233
|
+
successEvidence: cleanForStorage(finalTrajectory.successEvidence).slice(0, 360),
|
|
753234
|
+
doNotRepeat: finalTrajectory.doNotRepeat.slice(0, 3).map((item) => cleanForStorage(item).slice(0, 220)).filter(Boolean)
|
|
753235
|
+
} : void 0;
|
|
752484
753236
|
try {
|
|
752485
753237
|
saveSession(repoRoot, {
|
|
752486
753238
|
id: sessionId,
|
|
@@ -752508,7 +753260,8 @@ When done, either call task_complete with your answer, or use FINAL_VAR(variable
|
|
|
752508
753260
|
completed: result.completed,
|
|
752509
753261
|
model: config.model,
|
|
752510
753262
|
source: "task_complete",
|
|
752511
|
-
sessionId
|
|
753263
|
+
sessionId,
|
|
753264
|
+
...trajectoryOrientation ? { trajectory: trajectoryOrientation } : {}
|
|
752512
753265
|
});
|
|
752513
753266
|
} catch {
|
|
752514
753267
|
}
|
|
@@ -752563,7 +753316,8 @@ When done, either call task_complete with your answer, or use FINAL_VAR(variable
|
|
|
752563
753316
|
buildSucceeded: validationStatus.buildSucceeded
|
|
752564
753317
|
},
|
|
752565
753318
|
eligible: result.completed,
|
|
752566
|
-
handoffAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
753319
|
+
handoffAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
753320
|
+
...trajectoryOrientation ? { trajectory: trajectoryOrientation } : {}
|
|
752567
753321
|
};
|
|
752568
753322
|
writeTaskHandoff2(repoRoot, handoff);
|
|
752569
753323
|
} catch {
|
|
@@ -753264,7 +754018,12 @@ async function startInteractive(config, repoPath2) {
|
|
|
753264
754018
|
const workerSystem = opts.agentType ? buildSubAgentSystemPrompt(opts.agentType, {
|
|
753265
754019
|
task: opts.task,
|
|
753266
754020
|
focusFiles: opts.focusFiles,
|
|
753267
|
-
exitCriterion: opts.exitCriterion
|
|
754021
|
+
exitCriterion: opts.exitCriterion,
|
|
754022
|
+
trajectory: scopeTrajectoryCheckpoint(
|
|
754023
|
+
_activeRunnerRef?.getTrajectoryCheckpoint?.() ?? null,
|
|
754024
|
+
opts.task,
|
|
754025
|
+
opts.exitCriterion ?? "Return a compact result with a tool observation that verifies it."
|
|
754026
|
+
)
|
|
753268
754027
|
}) : opts.systemPromptAddition;
|
|
753269
754028
|
const systemCtx = workerSystem ? `Working directory: ${repoRoot}
|
|
753270
754029
|
|
|
@@ -754147,10 +754906,10 @@ This is an independent background session started from /background.`
|
|
|
754147
754906
|
const { MouseFilterStream: MouseFilterStream2 } = await Promise.resolve().then(() => (init_mouse_filter(), mouse_filter_exports));
|
|
754148
754907
|
let origTtyWriteRef = null;
|
|
754149
754908
|
const mouseFilter = new MouseFilterStream2(
|
|
754150
|
-
(direction, lines,
|
|
754909
|
+
(direction, lines, row2) => {
|
|
754151
754910
|
const fh = statusBar._currentFooterHeight ?? 3;
|
|
754152
754911
|
const footerStart = termRows() - fh + 1;
|
|
754153
|
-
if (
|
|
754912
|
+
if (row2 >= footerStart) {
|
|
754154
754913
|
const arrowKey = direction === "up" ? { name: "up" } : { name: "down" };
|
|
754155
754914
|
const arrowSeq = direction === "up" ? "\x1B[A" : "\x1B[B";
|
|
754156
754915
|
origTtyWriteRef?.(arrowSeq, arrowKey);
|
|
@@ -754163,8 +754922,8 @@ This is an independent background session started from /background.`
|
|
|
754163
754922
|
statusBar.cancelMouseIdle();
|
|
754164
754923
|
statusBar.enableMouseTracking();
|
|
754165
754924
|
},
|
|
754166
|
-
(type, col,
|
|
754167
|
-
statusBar.handlePointerEvent(type, col,
|
|
754925
|
+
(type, col, row2) => {
|
|
754926
|
+
statusBar.handlePointerEvent(type, col, row2);
|
|
754168
754927
|
},
|
|
754169
754928
|
() => {
|
|
754170
754929
|
}
|