codemem 0.28.1 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +90 -8
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { DEDUP_KEY_BACKFILL_JOB, DEFAULT_COORDINATOR_DB_PATH, DedupKeyBackfillRunner, MUTATING_TOOL_NAMES, MemoryStore, ObserverClient, REF_BACKFILL_JOB, RawEventSweeper, RefBackfillRunner, SESSION_CONTEXT_BACKFILL_JOB, SUMMARY_DEDUP_BACKFILL_JOB, SessionContextBackfillRunner, SummaryDedupBackfillRunner, SyncRetentionRunner, VERSION, VectorModelMigrationRunner, aiBackfillStructuredContent, applyBootstrapSnapshot, backfillMemoryDedupKeys, backfillNarrativeFromBody, backfillTagsText, backfillVectors, buildAuthHeaders, buildBaseUrl, buildRawEventEnvelopeFromHook, compareMemoryRoleReports, connect, coordinatorCreateGroupAction, coordinatorCreateInviteAction, coordinatorDisableDeviceAction, coordinatorEnrollDeviceAction, coordinatorImportInviteAction, coordinatorListBootstrapGrantsAction, coordinatorListDevicesAction, coordinatorListGroupsAction, coordinatorListJoinRequestsAction, coordinatorRemoveDeviceAction, coordinatorRenameDeviceAction, coordinatorReviewJoinRequestAction, coordinatorRevokeBootstrapGrantAction, createBetterSqliteCoordinatorApp, deactivateLowSignalMemories, deactivateLowSignalObservations, dedupNearDuplicateMemories, ensureDeviceIdentity, ensureSchemaBootstrapped, exportMemories, extractApplyPatchPaths, fetchAllSnapshotPages, fingerprintPublicKey, flushRawEvents, getExtractionBenchmarkProfile, getInjectionEvalScenarioPack, getInjectionEvalScenarioPrompts, getMaintenanceJob, getMemoryRoleReport, getRawEventRelinkPlan, getRawEventRelinkReport, getRawEventStatus, getSemanticIndexDiagnostics, getSessionExtractionEval, getSessionExtractionEvalScenario, getWorkspaceCodememConfigPath, hasPendingDedupKeyBackfill, hasPendingRefBackfill, hasPendingSessionContextBackfill, hasPendingSummaryDedupBackfill, hasUnsyncedSharedMemoryChanges, importMemories, initDatabase, isEmbeddingDisabled, loadObserverConfig, loadPublicKey, loadSqliteVec, planReplicationOpsAgePrune, pruneReplicationOpsUntilCaughtUp, rawEventsGate, readCodememConfigFile, readCodememConfigFileAtPath, readCoordinatorSyncConfig, readImportPayload, replayBatchExtraction, replayBatchExtractionWithTierRouting, requestJson, resolveCodememConfigPath, resolveDbPath, resolveHookProject, resolveProject, retryRawEventFailures, runSyncDaemon, runSyncPass, schema, setPeerProjectFilter, stripJsonComments, stripPrivateObj, stripTrailingCommas, syncPassPreflight, updatePeerAddresses, vacuumDatabase, writeCodememConfigFile } from "@codemem/core";
|
|
2
|
+
import { DEDUP_KEY_BACKFILL_JOB, DEFAULT_COORDINATOR_DB_PATH, DedupKeyBackfillRunner, MUTATING_TOOL_NAMES, MemoryStore, ObserverClient, REF_BACKFILL_JOB, RawEventSweeper, RefBackfillRunner, SESSION_CONTEXT_BACKFILL_JOB, SUMMARY_DEDUP_BACKFILL_JOB, SessionContextBackfillRunner, SummaryDedupBackfillRunner, SyncRetentionRunner, VERSION, VectorModelMigrationRunner, aiBackfillStructuredContent, applyBootstrapSnapshot, backfillMemoryDedupKeys, backfillNarrativeFromBody, backfillTagsText, backfillVectors, buildAuthHeaders, buildBaseUrl, buildRawEventEnvelopeFromHook, compareMemoryRoleReports, connect, coordinatorCreateGroupAction, coordinatorCreateInviteAction, coordinatorDisableDeviceAction, coordinatorEnrollDeviceAction, coordinatorImportInviteAction, coordinatorListBootstrapGrantsAction, coordinatorListDevicesAction, coordinatorListGroupsAction, coordinatorListJoinRequestsAction, coordinatorRemoveDeviceAction, coordinatorRenameDeviceAction, coordinatorReviewJoinRequestAction, coordinatorRevokeBootstrapGrantAction, createBetterSqliteCoordinatorApp, deactivateLowSignalMemories, deactivateLowSignalObservations, dedupNearDuplicateMemories, ensureDeviceIdentity, ensureSchemaBootstrapped, exportMemories, extractApplyPatchPaths, fetchAllSnapshotPages, fingerprintPublicKey, flushRawEvents, getExtractionBenchmarkProfile, getInjectionEvalScenarioPack, getInjectionEvalScenarioPrompts, getMaintenanceJob, getMemoryRoleReport, getRawEventRelinkPlan, getRawEventRelinkReport, getRawEventStatus, getSemanticIndexDiagnostics, getSessionExtractionEval, getSessionExtractionEvalScenario, getWorkspaceCodememConfigPath, hasPendingDedupKeyBackfill, hasPendingRefBackfill, hasPendingSessionContextBackfill, hasPendingSummaryDedupBackfill, hasUnsyncedSharedMemoryChanges, importMemories, initDatabase, isEmbeddingDisabled, listMaintenanceJobs, loadObserverConfig, loadPublicKey, loadSqliteVec, mdnsEnabled, planReplicationOpsAgePrune, pruneReplicationOpsUntilCaughtUp, rawEventsGate, readCodememConfigFile, readCodememConfigFileAtPath, readCoordinatorSyncConfig, readImportPayload, replayBatchExtraction, replayBatchExtractionWithTierRouting, requestJson, resolveCodememConfigPath, resolveDbPath, resolveHookProject, resolveProject, retryRawEventFailures, runSyncDaemon, runSyncPass, schema, setPeerProjectFilter, stripJsonComments, stripPrivateObj, stripTrailingCommas, syncPassPreflight, updatePeerAddresses, vacuumDatabase, writeCodememConfigFile } from "@codemem/core";
|
|
3
3
|
import { Command, Option } from "commander";
|
|
4
4
|
import omelette from "omelette";
|
|
5
5
|
import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, rmdirSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
@@ -2575,6 +2575,78 @@ cmd$1.action((inputFile, opts) => {
|
|
|
2575
2575
|
});
|
|
2576
2576
|
var importMemoriesCommand = cmd$1;
|
|
2577
2577
|
//#endregion
|
|
2578
|
+
//#region src/commands/maintenance.ts
|
|
2579
|
+
var maintenanceCmd = new Command("maintenance").configureHelp(helpStyle).description("Inspect background maintenance / backfill jobs");
|
|
2580
|
+
var statusCmd$1 = new Command("status").configureHelp(helpStyle).description("Print current status of all maintenance jobs");
|
|
2581
|
+
addDbOption(statusCmd$1);
|
|
2582
|
+
addJsonOption(statusCmd$1);
|
|
2583
|
+
statusCmd$1.action((opts) => {
|
|
2584
|
+
const store = new MemoryStore(resolveDbPath(resolveDbOpt(opts)));
|
|
2585
|
+
try {
|
|
2586
|
+
const jobs = listMaintenanceJobs(store.db);
|
|
2587
|
+
if (opts.json) {
|
|
2588
|
+
console.log(JSON.stringify({ jobs }, null, 2));
|
|
2589
|
+
return;
|
|
2590
|
+
}
|
|
2591
|
+
printJobsTable(jobs);
|
|
2592
|
+
} finally {
|
|
2593
|
+
store.close();
|
|
2594
|
+
}
|
|
2595
|
+
});
|
|
2596
|
+
maintenanceCmd.addCommand(statusCmd$1);
|
|
2597
|
+
var maintenanceCommand = maintenanceCmd;
|
|
2598
|
+
function printJobsTable(jobs) {
|
|
2599
|
+
p.intro("codemem maintenance");
|
|
2600
|
+
if (jobs.length === 0) {
|
|
2601
|
+
p.log.info("No maintenance jobs recorded in this database.");
|
|
2602
|
+
p.outro("done");
|
|
2603
|
+
return;
|
|
2604
|
+
}
|
|
2605
|
+
const statusRank = {
|
|
2606
|
+
running: 0,
|
|
2607
|
+
pending: 1,
|
|
2608
|
+
failed: 2,
|
|
2609
|
+
cancelled: 3,
|
|
2610
|
+
completed: 4
|
|
2611
|
+
};
|
|
2612
|
+
const sorted = [...jobs].sort((a, b) => {
|
|
2613
|
+
const rankDiff = (statusRank[a.status] ?? 9) - (statusRank[b.status] ?? 9);
|
|
2614
|
+
if (rankDiff !== 0) return rankDiff;
|
|
2615
|
+
return b.updated_at.localeCompare(a.updated_at);
|
|
2616
|
+
});
|
|
2617
|
+
for (const job of sorted) {
|
|
2618
|
+
const progress = formatProgress(job);
|
|
2619
|
+
const when = job.finished_at ? `finished ${shortAge(job.finished_at)} ago` : job.started_at ? `started ${shortAge(job.started_at)} ago` : `updated ${shortAge(job.updated_at)} ago`;
|
|
2620
|
+
const header = `${job.kind} · ${job.status}${progress ? ` · ${progress}` : ""} · ${when}`;
|
|
2621
|
+
const body = [
|
|
2622
|
+
job.title,
|
|
2623
|
+
job.message,
|
|
2624
|
+
job.error ? `error: ${job.error}` : null
|
|
2625
|
+
].filter(Boolean).join("\n");
|
|
2626
|
+
(job.status === "failed" ? p.log.error : job.status === "completed" ? p.log.success : p.log.step)(`${header}\n${body}`);
|
|
2627
|
+
}
|
|
2628
|
+
p.outro("done");
|
|
2629
|
+
}
|
|
2630
|
+
function formatProgress(job) {
|
|
2631
|
+
const { current, total, unit } = job.progress;
|
|
2632
|
+
if (!current && !total) return null;
|
|
2633
|
+
const unitLabel = unit || "items";
|
|
2634
|
+
if (total == null || total <= 0) return `${current.toLocaleString()} ${unitLabel}`;
|
|
2635
|
+
const pct = Math.round(100 * current / total);
|
|
2636
|
+
return `${current.toLocaleString()}/${total.toLocaleString()} ${unitLabel} (${pct}%)`;
|
|
2637
|
+
}
|
|
2638
|
+
function shortAge(iso) {
|
|
2639
|
+
const parsed = Date.parse(iso);
|
|
2640
|
+
if (!Number.isFinite(parsed)) return iso;
|
|
2641
|
+
const seconds = Math.max(0, Math.round((Date.now() - parsed) / 1e3));
|
|
2642
|
+
if (seconds < 60) return `${seconds}s`;
|
|
2643
|
+
const minutes = Math.round(seconds / 60);
|
|
2644
|
+
if (minutes < 60) return `${minutes}m`;
|
|
2645
|
+
const hours = Math.round(minutes / 60);
|
|
2646
|
+
if (hours < 48) return `${hours}h`;
|
|
2647
|
+
return `${Math.round(hours / 24)}d`;
|
|
2648
|
+
}
|
|
2649
|
+
//#endregion
|
|
2578
2650
|
//#region src/commands/mcp.ts
|
|
2579
2651
|
var mcpCmd = new Command("mcp").configureHelp(helpStyle).description("Start the MCP stdio server");
|
|
2580
2652
|
addDbOption(mcpCmd);
|
|
@@ -3881,7 +3953,10 @@ async function startForegroundViewer(invocation) {
|
|
|
3881
3953
|
dbPath,
|
|
3882
3954
|
signal: retentionAbort.signal
|
|
3883
3955
|
});
|
|
3884
|
-
const vectorMigrationRunner = new VectorModelMigrationRunner({
|
|
3956
|
+
const vectorMigrationRunner = new VectorModelMigrationRunner({
|
|
3957
|
+
dbPath,
|
|
3958
|
+
signal: backfillAbort.signal
|
|
3959
|
+
});
|
|
3885
3960
|
const backfillCoordinator = createSequentialBackfillCoordinator(store, [
|
|
3886
3961
|
{
|
|
3887
3962
|
name: "Dedup-key",
|
|
@@ -4123,10 +4198,12 @@ serveCmd.addOption(new Option("--stop", "stop background viewer").hideHelp());
|
|
|
4123
4198
|
serveCmd.addOption(new Option("--restart", "restart background viewer").hideHelp());
|
|
4124
4199
|
var serveCommand = serveCmd.action(async (action, opts) => {
|
|
4125
4200
|
try {
|
|
4126
|
-
if (
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4201
|
+
if (action === void 0) {
|
|
4202
|
+
if (opts.stop) emitDeprecationWarning("--stop", "codemem serve stop");
|
|
4203
|
+
if (opts.restart) emitDeprecationWarning("--restart", "codemem serve restart");
|
|
4204
|
+
if (opts.background) emitDeprecationWarning("--background", "codemem serve start");
|
|
4205
|
+
if (opts.foreground) emitDeprecationWarning("--foreground", "codemem serve start --foreground");
|
|
4206
|
+
}
|
|
4130
4207
|
const normalizedAction = action === void 0 ? void 0 : action === "start" || action === "stop" || action === "restart" ? action : null;
|
|
4131
4208
|
if (normalizedAction === null) {
|
|
4132
4209
|
p.log.error(`Unknown serve action: ${action}`);
|
|
@@ -4907,11 +4984,15 @@ doctorCmd.action(async (opts) => {
|
|
|
4907
4984
|
if (reach !== "ok") issues.push(`peer ${peer.peer_device_id} unreachable`);
|
|
4908
4985
|
if (!pinned || !hasKey) issues.push(`peer ${peer.peer_device_id} not pinned`);
|
|
4909
4986
|
}
|
|
4987
|
+
const mdnsActive = mdnsEnabled();
|
|
4988
|
+
const mdnsSource = process.env.CODEMEM_SYNC_MDNS ? "env" : config.sync_mdns ? "config" : null;
|
|
4989
|
+
const mdnsLabel = mdnsActive ? mdnsSource === "env" ? "enabled (env)" : "enabled (config)" : "disabled";
|
|
4910
4990
|
if (opts.json) {
|
|
4911
4991
|
console.log(JSON.stringify({
|
|
4912
4992
|
enabled: config.sync_enabled === true,
|
|
4913
4993
|
listen: `${syncHost}:${syncPort}`,
|
|
4914
|
-
mdns:
|
|
4994
|
+
mdns: mdnsLabel,
|
|
4995
|
+
mdns_source: mdnsSource,
|
|
4915
4996
|
daemon: reachable ? "running" : "not running",
|
|
4916
4997
|
identity: device?.device_id ?? null,
|
|
4917
4998
|
daemon_error: daemonState?.last_error ?? null,
|
|
@@ -4924,7 +5005,7 @@ doctorCmd.action(async (opts) => {
|
|
|
4924
5005
|
console.log("Sync doctor");
|
|
4925
5006
|
console.log(`- Enabled: ${config.sync_enabled === true}`);
|
|
4926
5007
|
console.log(`- Listen: ${syncHost}:${syncPort}`);
|
|
4927
|
-
console.log(`- mDNS: ${
|
|
5008
|
+
console.log(`- mDNS: ${mdnsLabel}`);
|
|
4928
5009
|
console.log(`- Daemon: ${reachable ? "running" : "not running"}`);
|
|
4929
5010
|
if (!device) console.log("- Identity: missing (run `codemem sync enable`)");
|
|
4930
5011
|
else console.log(`- Identity: ${device.device_id}`);
|
|
@@ -5417,6 +5498,7 @@ program.addCommand(dbCommand);
|
|
|
5417
5498
|
program.addCommand(exportMemoriesCommand);
|
|
5418
5499
|
program.addCommand(importMemoriesCommand);
|
|
5419
5500
|
program.addCommand(statsCommand);
|
|
5501
|
+
program.addCommand(maintenanceCommand);
|
|
5420
5502
|
program.addCommand(embedCommand);
|
|
5421
5503
|
program.addCommand(recentCommand);
|
|
5422
5504
|
program.addCommand(searchCommand);
|