MCPcopy Create free account
hub / github.com/cortexkit/magic-context / spawnPiHistorianRun

Function spawnPiHistorianRun

packages/pi-plugin/src/context-handler.ts:2828–2936  ·  view source on GitHub ↗
(args: {
	ctx: ExtensionContext;
	sessionId: string;
	db: ContextDatabase;
	historian: PiHistorianOptions;
	provider: { readMessages: () => ReturnType<typeof readPiSessionMessages> };
	unregister: () => void;
	boundarySnapshot: ProtectedTailBoundarySnapshot;
	refreshBoundarySnapshot?: () => ProtectedTailBoundarySnapshot;
	currentContextLimit: number;
})

Source from the content-addressed store, hash-verified

2826}
2827
2828function spawnPiHistorianRun(args: {
2829 ctx: ExtensionContext;
2830 sessionId: string;
2831 db: ContextDatabase;
2832 historian: PiHistorianOptions;
2833 provider: { readMessages: () => ReturnType<typeof readPiSessionMessages> };
2834 unregister: () => void;
2835 boundarySnapshot: ProtectedTailBoundarySnapshot;
2836 refreshBoundarySnapshot?: () => ProtectedTailBoundarySnapshot;
2837 currentContextLimit: number;
2838}): void {
2839 const {
2840 ctx,
2841 sessionId,
2842 db,
2843 historian,
2844 provider,
2845 unregister,
2846 boundarySnapshot,
2847 refreshBoundarySnapshot,
2848 currentContextLimit,
2849 } = args;
2850 const holderId = crypto.randomUUID();
2851 const runPromise = (async () => {
2852 const lease = acquireCompartmentLease(db, sessionId, holderId);
2853 if (!lease) {
2854 sessionLog(
2855 sessionId,
2856 "historian skipped: compartment lease held by another process",
2857 );
2858 return;
2859 }
2860 const renewal = startPiCompartmentLeaseRenewal(db, sessionId, holderId);
2861 try {
2862 await runPiHistorian({
2863 db,
2864 sessionId,
2865 directory: ctx.cwd,
2866 provider,
2867 appendCompaction: resolvePiAppendCompaction(ctx),
2868 readBranchEntries: resolvePiReadBranchEntries(ctx),
2869 runner: historian.runner,
2870 historianModel: historian.model,
2871 fallbackModels: historian.fallbackModels,
2872 historianChunkTokens: historian.historianChunkTokens,
2873 boundarySnapshot,
2874 refreshBoundarySnapshot,
2875 currentContextLimit,
2876 historianTimeoutMs: historian.timeoutMs,
2877 twoPass: historian.twoPass,
2878 thinkingLevel: historian.thinkingLevel,
2879 memoryEnabled: historian.memoryEnabled,
2880 autoPromote: historian.autoPromote,
2881 userMemoriesEnabled: historian.userMemoriesEnabled,
2882 language: historian.language,
2883 compartmentLeaseHolderId: holderId,
2884 onPublished: () => {
2885 const sessionStillActive = isContextHandlerSessionActive(sessionId);

Callers 1

maybeFireHistorianFunction · 0.85

Calls 13

acquireCompartmentLeaseFunction · 0.90
sessionLogFunction · 0.90
runPiHistorianFunction · 0.90
clearEmergencyRecoveryFunction · 0.90
releaseCompartmentLeaseFunction · 0.90
deleteMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected