codemem 0.46.0 → 0.46.1
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 +94 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { ContextOnlyReplayError, DEDUP_KEY_BACKFILL_JOB, DEFAULT_COORDINATOR_DB_PATH, DedupKeyBackfillRunner, DeviceIdentityError, EXTRACTION_BENCHMARK_QUALITY_WEIGHTS, MUTATING_TOOL_NAMES, MemoryStore, ObserverClient, ObserverOutputError, ObserverOutputTransportError, PROMPT_TRANSPORT_PROTOCOL_RANGE, REF_BACKFILL_JOB, RawEventIngestValidationError, RawEventSweeper, RefBackfillRunner, SCOPE_BACKFILL_JOB, SESSION_CONTEXT_BACKFILL_JOB, SUMMARY_DEDUP_BACKFILL_JOB, ScopeBackfillRunner, SessionContextBackfillRunner, SummaryDedupBackfillRunner, SyncRetentionRunner, TRUSTED_HOOK_MAPPER_OPTIONS, VERSION, VectorModelMigrationRunner, aiBackfillStructuredContent, applyBootstrapSnapshot, applyDistillRule, arePromptTransportProtocolRangesCompatible, atomicReplaceConfigFile, backfillMemoryDedupKeys, backfillNarrativeFromBody, backfillTagsText, backfillVectors, buildBaseUrl, buildDirectPeerAuthHeaders, buildDistillReport, buildPiFlushSignalFromEvent, buildRawEventEnvelopeFromHook, buildRawEventEnvelopeFromPiEvent, buildViewerIdentityTarget, classifyPromptTransportFailure, clonePromptPackAttempt, collectOperationalStatus, compareMemoryRoleReports, connect, connectReadOnly, coordinatorCreateGroupAction, coordinatorCreateInviteAction, coordinatorCreateScopeAction, coordinatorDisableDeviceAction, coordinatorEnrollDeviceAction, coordinatorGrantScopeMembershipAction, coordinatorImportInviteAction, coordinatorListBootstrapGrantsAction, coordinatorListDevicesAction, coordinatorListGroupsAction, coordinatorListJoinRequestsAction, coordinatorListScopeMembershipsAction, coordinatorListScopesAction, coordinatorRemoveDeviceAction, coordinatorRenameDeviceAction, coordinatorReviewJoinRequestAction, coordinatorRevokeBootstrapGrantAction, coordinatorRevokeScopeMembershipAction, coordinatorUpdateScopeAction, createBetterSqliteCoordinatorApp, deactivateLowSignalMemories, deactivateLowSignalObservations, dedupNearDuplicateMemories, describePiObserverStatus, detectInstallKind, draftDistillRule, ensureDeviceIdentity, ensureSchemaBootstrapped, estimateExtractionModelCost, exportMemories, extractApplyPatchPaths, extractionReplayObserverIdentity, fetchAllSnapshotPages, fingerprintPublicKey, flushRawEvents, formatHostPort, getAttributionDiagnostics, getCodememConfigPath, getExtractionBenchmarkProfile, getExtractionModelPricing, getInjectionEvalScenarioPack, getInjectionEvalScenarioPrompts, getMaintenanceJob, getMemoryArtifactReport, getMemoryRoleReport, getRawEventRelinkPlan, getRawEventRelinkReport, getRawEventStatus, getSemanticIndexDiagnostics, getSessionExtractionEval, getSessionExtractionEvalScenario, getUpdateStatus, getWorkspaceCodememConfigPath, hasPendingDedupKeyBackfill, hasPendingRefBackfill, hasPendingScopeBackfill, hasPendingSessionContextBackfill, hasPendingSummaryDedupBackfill, hasUnsyncedSharedMemoryChanges, importMemories, ingestRawEvents, initDatabase, isAutomaticRecallMeasurement, isEmbeddingDisabled, isExplicitUpdateInstallEligible, isReleaseVersionForChannel, judgeDistillReport, listMaintenanceJobs, listPerPeerScopeSyncState, listRetentionScopeIds, loadObserverConfig, loadPublicKey, loadSqliteVec, mdnsEnabled, mutateCodememConfigFile, normalizePromptTransportProtocolRange, observerBaseUrlForProviderOverride, planReplicationOpsAgePrune, probeCodememViewerLiveness, probeCodememViewerLiveness as probeCodememViewerLiveness$1, probeRequiredNativeRuntime, projectMatchesFilter, promptPackArtifactFingerprint, pruneReplicationOpsUntilCaughtUp, rawEventsGate, readCodememConfigFile, readCodememConfigFileAtPath, readCoordinatorSyncConfig, readImportPayload, recordAutomaticRecall, recordPromptPackArtifacts, recordPromptPackTerminal, recordRetrievalSurface, renderUnifiedDiff, replayBatchExtraction, replayBatchExtractionWithTierRouting, requestJson, resolveCodememConfigPath, resolveComparablePath, resolveDbPath, resolveHookProject, resolvePiAgentDir, resolvePiObserverConfig, resolveProject, resolveProjectRoot, resolveRetrievalSession, retryRawEventFailures, runSyncDaemon, runSyncPass, scanSecretsRetroactive, schema, scoreExtractionBenchmarkOutput, setPeerProjectFilter, syncPassPreflight, tryUpdateRetrievalDelivery, updatePeerAddresses, vacuumDatabase, viewerUrl, writeCodememConfigFile } from "@codemem/core";
|
|
2
|
+
import { ContextOnlyReplayError, DEDUP_KEY_BACKFILL_JOB, DEFAULT_COORDINATOR_DB_PATH, DedupKeyBackfillRunner, DeviceIdentityError, EXTRACTION_BENCHMARK_QUALITY_WEIGHTS, MUTATING_TOOL_NAMES, MemoryStore, ObserverClient, ObserverOutputError, ObserverOutputTransportError, PROMPT_TRANSPORT_PROTOCOL_RANGE, REF_BACKFILL_JOB, RawEventIngestValidationError, RawEventSweeper, RefBackfillRunner, SCOPE_BACKFILL_JOB, SESSION_CONTEXT_BACKFILL_JOB, SUMMARY_DEDUP_BACKFILL_JOB, ScopeBackfillRunner, SessionContextBackfillRunner, SummaryDedupBackfillRunner, SyncRetentionRunner, TRUSTED_HOOK_MAPPER_OPTIONS, VERSION, VectorModelMigrationRunner, aiBackfillStructuredContent, applyBootstrapSnapshot, applyDistillRule, arePromptTransportProtocolRangesCompatible, atomicReplaceConfigFile, backfillMemoryDedupKeys, backfillNarrativeFromBody, backfillTagsText, backfillVectors, buildBaseUrl, buildDirectPeerAuthHeaders, buildDistillReport, buildPiFlushSignalFromEvent, buildRawEventEnvelopeFromHook, buildRawEventEnvelopeFromPiEvent, buildTieredObserverSelection, buildViewerIdentityTarget, classifyPromptTransportFailure, clonePromptPackAttempt, collectOperationalStatus, compareMemoryRoleReports, connect, connectReadOnly, coordinatorCreateGroupAction, coordinatorCreateInviteAction, coordinatorCreateScopeAction, coordinatorDisableDeviceAction, coordinatorEnrollDeviceAction, coordinatorGrantScopeMembershipAction, coordinatorImportInviteAction, coordinatorListBootstrapGrantsAction, coordinatorListDevicesAction, coordinatorListGroupsAction, coordinatorListJoinRequestsAction, coordinatorListScopeMembershipsAction, coordinatorListScopesAction, coordinatorRemoveDeviceAction, coordinatorRenameDeviceAction, coordinatorReviewJoinRequestAction, coordinatorRevokeBootstrapGrantAction, coordinatorRevokeScopeMembershipAction, coordinatorUpdateScopeAction, createBetterSqliteCoordinatorApp, deactivateLowSignalMemories, deactivateLowSignalObservations, dedupNearDuplicateMemories, describePiObserverStatus, detectInstallKind, draftDistillRule, ensureDeviceIdentity, ensureSchemaBootstrapped, estimateExtractionModelCost, exportMemories, extractApplyPatchPaths, extractionReplayObserverIdentity, fetchAllSnapshotPages, fingerprintPublicKey, flushRawEvents, formatHostPort, getAttributionDiagnostics, getCodememConfigPath, getExtractionBenchmarkProfile, getExtractionModelPricing, getInjectionEvalScenarioPack, getInjectionEvalScenarioPrompts, getMaintenanceJob, getMemoryArtifactReport, getMemoryRoleReport, getRawEventRelinkPlan, getRawEventRelinkReport, getRawEventStatus, getSemanticIndexDiagnostics, getSessionExtractionEval, getSessionExtractionEvalScenario, getUpdateStatus, getWorkspaceCodememConfigPath, hasPendingDedupKeyBackfill, hasPendingRefBackfill, hasPendingScopeBackfill, hasPendingSessionContextBackfill, hasPendingSummaryDedupBackfill, hasUnsyncedSharedMemoryChanges, importMemories, ingestRawEvents, initDatabase, isAutomaticRecallMeasurement, isEmbeddingDisabled, isExplicitUpdateInstallEligible, isReleaseVersionForChannel, judgeDistillReport, listMaintenanceJobs, listPerPeerScopeSyncState, listRetentionScopeIds, loadObserverConfig, loadPublicKey, loadSqliteVec, mdnsEnabled, mutateCodememConfigFile, normalizePromptTransportProtocolRange, observerBaseUrlForProviderOverride, planReplicationOpsAgePrune, probeCodememViewerLiveness, probeCodememViewerLiveness as probeCodememViewerLiveness$1, probeRequiredNativeRuntime, projectMatchesFilter, promptPackArtifactFingerprint, pruneReplicationOpsUntilCaughtUp, rawEventsGate, readCodememConfigFile, readCodememConfigFileAtPath, readCoordinatorSyncConfig, readImportPayload, recordAutomaticRecall, recordPromptPackArtifacts, recordPromptPackTerminal, recordRetrievalSurface, renderUnifiedDiff, replayBatchExtraction, replayBatchExtractionWithTierRouting, requestJson, resolveCodememConfigPath, resolveComparablePath, resolveDbPath, resolveHookProject, resolvePiAgentDir, resolvePiObserverConfig, resolveProject, resolveProjectRoot, resolveRetrievalSession, retryRawEventFailures, runSyncDaemon, runSyncPass, scanSecretsRetroactive, schema, scoreExtractionBenchmarkOutput, setPeerProjectFilter, syncPassPreflight, tryUpdateRetrievalDelivery, updatePeerAddresses, vacuumDatabase, viewerUrl, writeCodememConfigFile } from "@codemem/core";
|
|
3
3
|
import { Command, Option } from "commander";
|
|
4
4
|
import omelette from "omelette";
|
|
5
5
|
import { randomInt, randomUUID } from "node:crypto";
|
|
@@ -7259,6 +7259,94 @@ function timeSince(isoDate) {
|
|
|
7259
7259
|
return `${Math.floor(days / 30)}mo ago`;
|
|
7260
7260
|
}
|
|
7261
7261
|
//#endregion
|
|
7262
|
+
//#region src/observer-runtime-controller.ts
|
|
7263
|
+
/** Keep the live observer and saved config separate until in-flight work has drained. */
|
|
7264
|
+
var ObserverRuntimeController = class {
|
|
7265
|
+
sweeper;
|
|
7266
|
+
createObserver;
|
|
7267
|
+
activeObserver;
|
|
7268
|
+
revision = 0;
|
|
7269
|
+
work = null;
|
|
7270
|
+
stopped = false;
|
|
7271
|
+
state = "active";
|
|
7272
|
+
message;
|
|
7273
|
+
constructor(observer, sweeper, createObserver) {
|
|
7274
|
+
this.sweeper = sweeper;
|
|
7275
|
+
this.createObserver = createObserver;
|
|
7276
|
+
this.activeObserver = observer;
|
|
7277
|
+
}
|
|
7278
|
+
getObserver() {
|
|
7279
|
+
return this.activeObserver;
|
|
7280
|
+
}
|
|
7281
|
+
getStatus() {
|
|
7282
|
+
const active = this.activeObserver.getStatus();
|
|
7283
|
+
const config = this.activeObserver.toConfig();
|
|
7284
|
+
const previewTier = (tier) => {
|
|
7285
|
+
const selected = config.observerTierRoutingEnabled ? buildTieredObserverSelection(config, {
|
|
7286
|
+
tier,
|
|
7287
|
+
observer: {},
|
|
7288
|
+
reasons: []
|
|
7289
|
+
}).observer : config;
|
|
7290
|
+
return {
|
|
7291
|
+
provider: selected.observerProvider ?? active.provider,
|
|
7292
|
+
model: selected.observerModel ?? active.model,
|
|
7293
|
+
runtime: selected.observerRuntime ?? active.runtime,
|
|
7294
|
+
reasoningEffort: selected.observerReasoningEffort ?? null
|
|
7295
|
+
};
|
|
7296
|
+
};
|
|
7297
|
+
return {
|
|
7298
|
+
state: this.state,
|
|
7299
|
+
...this.message ? { message: this.message } : {},
|
|
7300
|
+
active: {
|
|
7301
|
+
provider: active.provider,
|
|
7302
|
+
model: active.model,
|
|
7303
|
+
runtime: active.runtime,
|
|
7304
|
+
authType: active.auth.type,
|
|
7305
|
+
tierRoutingEnabled: config.observerTierRoutingEnabled === true,
|
|
7306
|
+
simple: previewTier("simple"),
|
|
7307
|
+
rich: previewTier("rich")
|
|
7308
|
+
}
|
|
7309
|
+
};
|
|
7310
|
+
}
|
|
7311
|
+
requestApply() {
|
|
7312
|
+
if (this.stopped) return false;
|
|
7313
|
+
this.revision += 1;
|
|
7314
|
+
this.state = "applying";
|
|
7315
|
+
this.message = void 0;
|
|
7316
|
+
this.startWork();
|
|
7317
|
+
return true;
|
|
7318
|
+
}
|
|
7319
|
+
startWork() {
|
|
7320
|
+
if (this.work) return;
|
|
7321
|
+
this.work = this.applyLatest().finally(() => {
|
|
7322
|
+
this.work = null;
|
|
7323
|
+
if (!this.stopped && this.state === "applying") this.startWork();
|
|
7324
|
+
});
|
|
7325
|
+
}
|
|
7326
|
+
async applyLatest() {
|
|
7327
|
+
while (!this.stopped) {
|
|
7328
|
+
const revision = this.revision;
|
|
7329
|
+
try {
|
|
7330
|
+
const next = await this.sweeper.reconfigureObserver(this.createObserver, { shouldResume: () => !this.stopped && this.revision === revision });
|
|
7331
|
+
if (!next) continue;
|
|
7332
|
+
this.activeObserver = next;
|
|
7333
|
+
this.state = "active";
|
|
7334
|
+
return;
|
|
7335
|
+
} catch {
|
|
7336
|
+
if (revision !== this.revision) continue;
|
|
7337
|
+
this.state = "failed";
|
|
7338
|
+
this.message = "Observer settings were saved but could not be applied. Retry applying settings.";
|
|
7339
|
+
return;
|
|
7340
|
+
}
|
|
7341
|
+
}
|
|
7342
|
+
}
|
|
7343
|
+
async stop() {
|
|
7344
|
+
this.stopped = true;
|
|
7345
|
+
this.revision += 1;
|
|
7346
|
+
await this.work;
|
|
7347
|
+
}
|
|
7348
|
+
};
|
|
7349
|
+
//#endregion
|
|
7262
7350
|
//#region src/viewer-runtime.ts
|
|
7263
7351
|
function isValidPid(value) {
|
|
7264
7352
|
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
@@ -7864,6 +7952,7 @@ async function startBackgroundViewer(invocation) {
|
|
|
7864
7952
|
}
|
|
7865
7953
|
function startRawEventProcessing(dbPath, store, observer, createInbox) {
|
|
7866
7954
|
const sweeper = new RawEventSweeper(store, { observer });
|
|
7955
|
+
const observerRuntime = new ObserverRuntimeController(observer, sweeper, () => new ObserverClient());
|
|
7867
7956
|
sweeper.start();
|
|
7868
7957
|
const queue = createInbox({
|
|
7869
7958
|
dbPath,
|
|
@@ -7891,10 +7980,13 @@ function startRawEventProcessing(dbPath, store, observer, createInbox) {
|
|
|
7891
7980
|
rawEventInbox: queue.inbox,
|
|
7892
7981
|
rawEventTarget,
|
|
7893
7982
|
sweeper,
|
|
7894
|
-
|
|
7983
|
+
getObserver: () => observerRuntime.getObserver(),
|
|
7984
|
+
scheduleObserverApply: () => observerRuntime.requestApply(),
|
|
7985
|
+
getObserverApplyStatus: () => observerRuntime.getStatus()
|
|
7895
7986
|
},
|
|
7896
7987
|
stop: async () => {
|
|
7897
7988
|
rawEventTarget.stop();
|
|
7989
|
+
await observerRuntime.stop();
|
|
7898
7990
|
await queue.stop();
|
|
7899
7991
|
await sweeper.stop();
|
|
7900
7992
|
}
|