conare 0.1.4 → 0.1.6
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 +58 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -289,6 +289,7 @@ function cleanText(raw) {
|
|
|
289
289
|
let text = raw;
|
|
290
290
|
text = text.replace(/<system-reminder>[\s\S]*?<\/system-reminder>/g, "");
|
|
291
291
|
text = text.replace(/<attached-context[\s\S]*?<\/attached-context>/g, "");
|
|
292
|
+
text = text.replace(/<environment_context>[\s\S]*?<\/environment_context>/g, "");
|
|
292
293
|
return text.trim();
|
|
293
294
|
}
|
|
294
295
|
function createContentHash(content) {
|
|
@@ -450,6 +451,20 @@ import { existsSync as existsSync3, readFileSync as readFileSync3, readdirSync a
|
|
|
450
451
|
import { join as join4, basename as basename2 } from "node:path";
|
|
451
452
|
import { homedir as homedir4 } from "node:os";
|
|
452
453
|
var MAX_CONTENT2 = 48000;
|
|
454
|
+
function isCodexBoilerplate(text) {
|
|
455
|
+
return text.startsWith("# AGENTS.md instructions for") || text.startsWith("<INSTRUCTIONS>") || text.startsWith("<user_instructions>") || text.startsWith("<user_action>");
|
|
456
|
+
}
|
|
457
|
+
function stripEnvironmentContext(text) {
|
|
458
|
+
let cwd = null;
|
|
459
|
+
const cwdMatch = text.match(/<cwd>([^<]+)<\/cwd>/);
|
|
460
|
+
if (cwdMatch)
|
|
461
|
+
cwd = cwdMatch[1];
|
|
462
|
+
const cleaned = text.replace(/<environment_context>[\s\S]*?<\/environment_context>/g, "").trim();
|
|
463
|
+
return { text: cleaned, cwd };
|
|
464
|
+
}
|
|
465
|
+
function projectFromCwd(cwd) {
|
|
466
|
+
return cwd.replace(/^\/Users\/[^/]+\//, "");
|
|
467
|
+
}
|
|
453
468
|
function ingestCodex() {
|
|
454
469
|
const memories = [];
|
|
455
470
|
const sessionIds = [];
|
|
@@ -476,10 +491,21 @@ function ingestCodex() {
|
|
|
476
491
|
for (const [sessionId, entries] of sessions) {
|
|
477
492
|
entries.sort((a, b) => a.ts - b.ts);
|
|
478
493
|
const date = new Date(entries[0].ts * 1000).toISOString().slice(0, 10);
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
494
|
+
let project = null;
|
|
495
|
+
const cleanEntries = [];
|
|
496
|
+
for (const e of entries) {
|
|
497
|
+
let text = cleanText(e.text);
|
|
498
|
+
if (isCodexBoilerplate(text))
|
|
499
|
+
continue;
|
|
500
|
+
const env = stripEnvironmentContext(text);
|
|
501
|
+
text = env.text;
|
|
502
|
+
if (!project && env.cwd)
|
|
503
|
+
project = projectFromCwd(env.cwd);
|
|
504
|
+
if (text.length === 0)
|
|
505
|
+
continue;
|
|
506
|
+
cleanEntries.push(text.length > 300 ? text.slice(0, 300) + "..." : text);
|
|
507
|
+
}
|
|
508
|
+
const body = cleanEntries.filter(Boolean).join(`
|
|
483
509
|
|
|
484
510
|
---
|
|
485
511
|
|
|
@@ -505,7 +531,14 @@ ${body}`;
|
|
|
505
531
|
memories.push({
|
|
506
532
|
content,
|
|
507
533
|
containerTag: "codex-chats",
|
|
508
|
-
metadata: {
|
|
534
|
+
metadata: {
|
|
535
|
+
dedupKey,
|
|
536
|
+
contentHash,
|
|
537
|
+
source: "codex",
|
|
538
|
+
sessionId,
|
|
539
|
+
date,
|
|
540
|
+
...project ? { project } : {}
|
|
541
|
+
}
|
|
509
542
|
});
|
|
510
543
|
sessionIds.push(sessionId);
|
|
511
544
|
}
|
|
@@ -536,17 +569,23 @@ function walkCodexSessions(dir, memories, sessionIds, stats) {
|
|
|
536
569
|
`).filter(Boolean);
|
|
537
570
|
const turns = [];
|
|
538
571
|
let date = null;
|
|
572
|
+
let project = null;
|
|
539
573
|
for (const line of lines) {
|
|
540
574
|
try {
|
|
541
575
|
const obj = JSON.parse(line);
|
|
542
576
|
if (!date && obj.timestamp)
|
|
543
577
|
date = obj.timestamp.slice(0, 10);
|
|
578
|
+
if (obj.type === "session_meta" && obj.payload?.cwd) {
|
|
579
|
+
project = projectFromCwd(obj.payload.cwd);
|
|
580
|
+
}
|
|
544
581
|
if (obj.type === "response_item" && obj.payload?.role === "user") {
|
|
545
582
|
const content2 = obj.payload.content;
|
|
546
583
|
if (Array.isArray(content2)) {
|
|
547
584
|
for (const block of content2) {
|
|
548
585
|
if (block.type === "input_text" && block.text) {
|
|
549
586
|
const text = cleanText(block.text);
|
|
587
|
+
if (isCodexBoilerplate(text))
|
|
588
|
+
continue;
|
|
550
589
|
if (text.length > 50)
|
|
551
590
|
turns.push(text);
|
|
552
591
|
}
|
|
@@ -588,7 +627,8 @@ ${body}`;
|
|
|
588
627
|
contentHash,
|
|
589
628
|
source: "codex-session",
|
|
590
629
|
sessionId,
|
|
591
|
-
date: date || "unknown"
|
|
630
|
+
date: date || "unknown",
|
|
631
|
+
...project ? { project } : {}
|
|
592
632
|
}
|
|
593
633
|
});
|
|
594
634
|
sessionIds.push(sessionId);
|
|
@@ -1009,7 +1049,7 @@ function indexCodebase(rootPath) {
|
|
|
1009
1049
|
|
|
1010
1050
|
// src/api.ts
|
|
1011
1051
|
var API_URL = "https://mcp.conare.ai";
|
|
1012
|
-
function createUploadBatches(memories, maxItems =
|
|
1052
|
+
function createUploadBatches(memories, maxItems = 50, maxChars = 1500000) {
|
|
1013
1053
|
const batches = [];
|
|
1014
1054
|
let current = [];
|
|
1015
1055
|
let currentChars = 0;
|
|
@@ -1060,7 +1100,7 @@ async function getRemoteMemoryCount(apiKey) {
|
|
|
1060
1100
|
return null;
|
|
1061
1101
|
}
|
|
1062
1102
|
}
|
|
1063
|
-
async function uploadItems(apiKey, items) {
|
|
1103
|
+
async function uploadItems(apiKey, items, asyncEmbed = false) {
|
|
1064
1104
|
let retries = 4;
|
|
1065
1105
|
while (retries > 0) {
|
|
1066
1106
|
try {
|
|
@@ -1070,7 +1110,7 @@ async function uploadItems(apiKey, items) {
|
|
|
1070
1110
|
"Content-Type": "application/json",
|
|
1071
1111
|
Authorization: `Bearer ${apiKey}`
|
|
1072
1112
|
},
|
|
1073
|
-
body: JSON.stringify(items)
|
|
1113
|
+
body: JSON.stringify(asyncEmbed ? { items, async: true } : items)
|
|
1074
1114
|
});
|
|
1075
1115
|
if (res.status === 429) {
|
|
1076
1116
|
retries--;
|
|
@@ -1104,8 +1144,9 @@ async function uploadBulk(apiKey, memories, onProgress) {
|
|
|
1104
1144
|
let failed = 0;
|
|
1105
1145
|
const total = memories.length;
|
|
1106
1146
|
const results = [];
|
|
1107
|
-
|
|
1108
|
-
|
|
1147
|
+
const batches = createUploadBatches(memories);
|
|
1148
|
+
for (const batch of batches) {
|
|
1149
|
+
let batchResults = await uploadItems(apiKey, batch.items, true);
|
|
1109
1150
|
if (batch.items.length > 1 && batchResults.some((result) => !result.success)) {
|
|
1110
1151
|
const retriedResults = [];
|
|
1111
1152
|
for (let i = 0;i < batch.items.length; i++) {
|
|
@@ -1114,7 +1155,7 @@ async function uploadBulk(apiKey, memories, onProgress) {
|
|
|
1114
1155
|
retriedResults.push(result);
|
|
1115
1156
|
continue;
|
|
1116
1157
|
}
|
|
1117
|
-
const [singleResult] = await uploadItems(apiKey, [batch.items[i]]);
|
|
1158
|
+
const [singleResult] = await uploadItems(apiKey, [batch.items[i]], true);
|
|
1118
1159
|
retriedResults.push(singleResult);
|
|
1119
1160
|
}
|
|
1120
1161
|
batchResults = retriedResults;
|
|
@@ -2194,6 +2235,11 @@ Nothing new to index.`);
|
|
|
2194
2235
|
allMemories.push(...memories);
|
|
2195
2236
|
console.log(renderDiscoverySummary(memories.length, filtered, deduped));
|
|
2196
2237
|
}
|
|
2238
|
+
allMemories.sort((a, b3) => {
|
|
2239
|
+
const da = a.metadata?.date || "0000";
|
|
2240
|
+
const db = b3.metadata?.date || "0000";
|
|
2241
|
+
return db.localeCompare(da);
|
|
2242
|
+
});
|
|
2197
2243
|
console.log();
|
|
2198
2244
|
if (allMemories.length === 0) {
|
|
2199
2245
|
console.log("Nothing new to upload.");
|