codesesh 0.7.1 → 0.8.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.
@@ -79,7 +79,7 @@ import {
79
79
  syncSessionSearchIndexChanges,
80
80
  upsertBookmark,
81
81
  withEstimatedSessionCost
82
- } from "./chunk-7GQEIPVK.js";
82
+ } from "./chunk-XANARSZG.js";
83
83
  export {
84
84
  BaseAgent,
85
85
  BookmarkStorageUnavailableError,
@@ -161,4 +161,4 @@ export {
161
161
  upsertBookmark,
162
162
  withEstimatedSessionCost
163
163
  };
164
- //# sourceMappingURL=dist-L4XKQDGX.js.map
164
+ //# sourceMappingURL=dist-WJUBVCLN.js.map
package/dist/index.js CHANGED
@@ -29,7 +29,7 @@ import {
29
29
  searchFileActivitySessions,
30
30
  searchSessions,
31
31
  upsertBookmark
32
- } from "./chunk-7GQEIPVK.js";
32
+ } from "./chunk-XANARSZG.js";
33
33
 
34
34
  // src/index.ts
35
35
  import { defineCommand, runMain } from "citty";
@@ -1184,12 +1184,6 @@ function buildRefreshDiff(agentName, previousSessions, nextSessions, candidateCh
1184
1184
  function restoreAgentCacheMeta(agent, meta) {
1185
1185
  agent.setSessionMetaMap?.(new Map(Object.entries(meta)));
1186
1186
  }
1187
- function sourceFingerprintFromMeta(meta) {
1188
- return typeof meta?.sourceFingerprint === "string" ? meta.sourceFingerprint : null;
1189
- }
1190
- function sourcePathFromMeta(meta) {
1191
- return typeof meta?.sourcePath === "string" ? meta.sourcePath : null;
1192
- }
1193
1187
  function toAbsolutePath(path) {
1194
1188
  return isAbsolute(path) ? path : resolve2(path);
1195
1189
  }
@@ -1688,23 +1682,19 @@ var LiveScanStore = class {
1688
1682
  return workerUrl;
1689
1683
  }
1690
1684
  getScanRefreshWorkerUrl() {
1691
- const workerUrl = new URL("./scan-refresh-worker.js", import.meta.url);
1692
- if (workerUrl.protocol === "file:" && !existsSync3(fileURLToPath2(workerUrl))) {
1693
- return null;
1694
- }
1695
- return workerUrl;
1685
+ return new URL("./scan-refresh-worker.js", import.meta.url);
1696
1686
  }
1697
- scanAgentInWorker(agent, previousSessions, changedIds, scanOptions) {
1687
+ scanAgentInWorker(agent, previousSessions, changedIds, scanOptions, workerOptions = {}) {
1698
1688
  const workerUrl = this.getScanRefreshWorkerUrl();
1699
- if (!workerUrl) return null;
1700
1689
  return new Promise((resolve4, reject) => {
1701
1690
  const worker = new Worker(workerUrl, {
1702
1691
  workerData: {
1703
1692
  agentName: agent.name,
1704
1693
  previousSessions,
1705
1694
  changedIds,
1695
+ sourceSync: workerOptions.sourceSync,
1706
1696
  scanOptions,
1707
- meta: buildAgentCacheMeta(agent)
1697
+ meta: workerOptions.meta ?? buildAgentCacheMeta(agent)
1708
1698
  }
1709
1699
  });
1710
1700
  worker.unref();
@@ -1721,7 +1711,13 @@ var LiveScanStore = class {
1721
1711
  return;
1722
1712
  }
1723
1713
  if (message.type === "done") {
1724
- finish(() => resolve4({ sessions: message.sessions, meta: message.meta }));
1714
+ finish(
1715
+ () => resolve4({
1716
+ sessions: message.sessions,
1717
+ meta: message.meta,
1718
+ changedIds: message.changedIds
1719
+ })
1720
+ );
1725
1721
  return;
1726
1722
  }
1727
1723
  finish(() => reject(new Error(message.error)));
@@ -1738,7 +1734,7 @@ var LiveScanStore = class {
1738
1734
  }
1739
1735
  buildFullSearchIndexJobs(context) {
1740
1736
  return this.agents.map((agent) => {
1741
- const cached = loadCachedSessions(agent.name, { ignoreTtl: true });
1737
+ const cached = loadCachedSessions(agent.name);
1742
1738
  if (cached) {
1743
1739
  return {
1744
1740
  kind: "full",
@@ -1863,39 +1859,6 @@ var LiveScanStore = class {
1863
1859
  canSyncSources(agent) {
1864
1860
  return Boolean(agent.listSessionSources && agent.scanSessionSource);
1865
1861
  }
1866
- syncAgentSources(agent, cachedSessions, cachedMeta) {
1867
- const sessionMap = new Map(cachedSessions.map((session) => [session.id, session]));
1868
- const sourceRefs = agent.listSessionSources();
1869
- const currentIds = new Set(sourceRefs.map((source) => source.sessionId));
1870
- const changedIds = /* @__PURE__ */ new Set();
1871
- for (const source of sourceRefs) {
1872
- const cachedSession = sessionMap.get(source.sessionId);
1873
- const cached = cachedMeta[source.sessionId];
1874
- const sameSource = sourcePathFromMeta(cached) === source.sourcePath;
1875
- const sameFingerprint = sourceFingerprintFromMeta(cached) === source.fingerprint;
1876
- if (cachedSession && sameSource && sameFingerprint) continue;
1877
- const next = agent.scanSessionSource(source.sourcePath);
1878
- changedIds.add(source.sessionId);
1879
- if (next) {
1880
- sessionMap.set(next.id, next);
1881
- } else {
1882
- sessionMap.delete(source.sessionId);
1883
- }
1884
- }
1885
- for (const session of cachedSessions) {
1886
- if (!currentIds.has(session.id)) {
1887
- sessionMap.delete(session.id);
1888
- changedIds.add(session.id);
1889
- }
1890
- }
1891
- const sessions = attachMissingProjectIdentities([...sessionMap.values()]);
1892
- const persistenceDiff = buildRefreshDiff(agent.name, cachedSessions, sessions, [...changedIds]);
1893
- return {
1894
- sessions,
1895
- changedIds: [...changedIds],
1896
- persistenceDiff
1897
- };
1898
- }
1899
1862
  async refreshInitialIndex() {
1900
1863
  const startedAt = performance.now();
1901
1864
  const context = "scan.initial.background";
@@ -2145,7 +2108,7 @@ var LiveScanStore = class {
2145
2108
  return;
2146
2109
  }
2147
2110
  const previousSessions = this.byAgent[agentName] ?? [];
2148
- const cached = loadCachedSessions(agentName, { ignoreTtl: true });
2111
+ const cached = loadCachedSessions(agentName);
2149
2112
  const refreshBaseline = cached?.sessions ?? previousSessions;
2150
2113
  const cacheTimestamp = cached?.timestamp ?? this.refreshTimestamps.get(agentName) ?? 0;
2151
2114
  if (cached) {
@@ -2174,32 +2137,38 @@ var LiveScanStore = class {
2174
2137
  } else if (!isInitialized) {
2175
2138
  this.setScanPhase("initializing");
2176
2139
  const scanStartedAt = performance.now();
2177
- const workerResult = this.scanAgentInWorker(agent, previousSessions, null, {});
2178
- if (workerResult) {
2179
- const result = await workerResult;
2180
- nextSessions = result.sessions;
2181
- agent.setSessionMetaMap?.(new Map(Object.entries(result.meta)));
2182
- } else {
2183
- nextSessions = await Promise.resolve(
2184
- agent.scan({
2185
- onProgress: (progress) => this.updateAgentScanProgress(agentName, progress)
2186
- })
2187
- );
2188
- }
2140
+ const result = await this.scanAgentInWorker(agent, previousSessions, null, {});
2141
+ nextSessions = result.sessions;
2142
+ agent.setSessionMetaMap?.(new Map(Object.entries(result.meta)));
2189
2143
  fullScanSessions = attachMissingProjectIdentities(nextSessions);
2190
2144
  nextSessions = fullScanSessions;
2191
2145
  scanDuration = performance.now() - scanStartedAt;
2192
2146
  this.refreshTimestamps.set(agentName, Date.now());
2193
2147
  } else if (cached && this.canSyncSources(agent)) {
2194
2148
  const scanStartedAt = performance.now();
2195
- const result = this.syncAgentSources(agent, cached.sessions, cached.meta);
2149
+ const result = await this.scanAgentInWorker(
2150
+ agent,
2151
+ cached.sessions,
2152
+ null,
2153
+ {},
2154
+ {
2155
+ sourceSync: true,
2156
+ meta: cached.meta
2157
+ }
2158
+ );
2196
2159
  nextSessions = result.sessions;
2197
- preciseChangedIds = result.changedIds;
2160
+ agent.setSessionMetaMap?.(new Map(Object.entries(result.meta)));
2161
+ preciseChangedIds = result.changedIds ?? [];
2198
2162
  usedIncrementalScan = true;
2199
- persistenceDiff = result.persistenceDiff;
2163
+ persistenceDiff = buildRefreshDiff(
2164
+ agentName,
2165
+ cached.sessions,
2166
+ attachMissingProjectIdentities(nextSessions),
2167
+ preciseChangedIds
2168
+ );
2200
2169
  scanDuration = performance.now() - scanStartedAt;
2201
2170
  this.refreshTimestamps.set(agentName, Date.now());
2202
- if (result.changedIds.length === 0) {
2171
+ if (preciseChangedIds.length === 0) {
2203
2172
  appLogger.debug("scan.refresh.unchanged", {
2204
2173
  agent: agentName,
2205
2174
  duration_ms: Math.round(performance.now() - startedAt)
@@ -2236,18 +2205,9 @@ var LiveScanStore = class {
2236
2205
  scanDuration = performance.now() - scanStartedAt;
2237
2206
  } else {
2238
2207
  const scanStartedAt = performance.now();
2239
- const workerResult = this.scanAgentInWorker(agent, previousSessions, null, {});
2240
- if (workerResult) {
2241
- const result = await workerResult;
2242
- nextSessions = result.sessions;
2243
- agent.setSessionMetaMap?.(new Map(Object.entries(result.meta)));
2244
- } else {
2245
- nextSessions = await Promise.resolve(
2246
- agent.scan({
2247
- onProgress: (progress) => this.updateAgentScanProgress(agentName, progress)
2248
- })
2249
- );
2250
- }
2208
+ const result = await this.scanAgentInWorker(agent, previousSessions, null, {});
2209
+ nextSessions = result.sessions;
2210
+ agent.setSessionMetaMap?.(new Map(Object.entries(result.meta)));
2251
2211
  fullScanSessions = attachMissingProjectIdentities(nextSessions);
2252
2212
  nextSessions = fullScanSessions;
2253
2213
  scanDuration = performance.now() - scanStartedAt;
@@ -2480,7 +2440,7 @@ var main = defineCommand({
2480
2440
  log_path: appLogger.getLogPath()
2481
2441
  });
2482
2442
  if (clearCache) {
2483
- const { clearCache: clear } = await import("./dist-L4XKQDGX.js");
2443
+ const { clearCache: clear } = await import("./dist-WJUBVCLN.js");
2484
2444
  clear();
2485
2445
  appLogger.info("cache.clear");
2486
2446
  console.log("Cache cleared.");