@danypops/pi-lector 0.12.8 → 0.12.9

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.
@@ -13,6 +13,16 @@ import { lectorClient, type ResolvedWorkspace, withWorkspace, workspaceForCodeIn
13
13
  * the whole declared monorepo once (workspace_cache pointed at the repo root) and still rename a
14
14
  * file inside one of its member packages, without collapsing genuinely unrelated sibling projects
15
15
  * that were never declared together into one workspace identity.
16
+ *
17
+ * autoPopulate (Lector's own opt-in recovery from a "not-cached" graph) is applied carefully, not
18
+ * blanket-enabled: only once the correct FINAL scope is already known, never on a speculative
19
+ * first attempt that might still need widening. If a declared monorepo ancestor exists, the
20
+ * narrow project's own first attempt runs WITHOUT autoPopulate (so a genuinely never-populated
21
+ * narrow project still throws and triggers the widen-to-declared-root fallback below, exactly as
22
+ * before -- auto-populating the too-narrow scope here could make a rename "succeed" while
23
+ * silently missing a real cross-package reference the wider scope would have caught). Once widened
24
+ * to the declared root (or when no wider ancestor exists at all, meaning the narrow project IS the
25
+ * correct final scope), autoPopulate is safe and turned on -- one call converges instead of two.
16
26
  */
17
27
  export interface ReferenceBasedRenameOperations {
18
28
  rename(fromPath: string, toPath: string, maxFiles: number, maxSymbolsPerFile: number): Promise<OperationOutputs["workspace.referenceBasedRename"]>;
@@ -21,19 +31,32 @@ export interface ReferenceBasedRenameOperations {
21
31
  export function createReferenceBasedRenameOperations(): ReferenceBasedRenameOperations {
22
32
  return {
23
33
  async rename(fromPath, toPath, maxFiles, maxSymbolsPerFile) {
24
- const performRename = async ({ workspaceId }: ResolvedWorkspace) => {
34
+ const performRename = async ({ workspaceId }: ResolvedWorkspace, autoPopulate: boolean) => {
25
35
  const client = await lectorClient();
26
- return client.callOnce("workspace.referenceBasedRename", { workspaceId, fromPath, toPath, maxFiles, maxSymbolsPerFile });
36
+ return client.callOnce("workspace.referenceBasedRename", { workspaceId, fromPath, toPath, maxFiles, maxSymbolsPerFile, autoPopulate });
27
37
  };
28
38
 
39
+ const narrow = await workspaceForCodeIntelligencePath(fromPath);
40
+ const declared = await workspaceForDeclaredMonorepoRoot(narrow.root);
41
+ if (!declared) {
42
+ // No wider declared ancestor -- the narrow project IS the correct, final scope, so
43
+ // auto-populating it directly is exactly as safe as the already-widened case below.
44
+ return withWorkspace(
45
+ () => Promise.resolve(narrow),
46
+ (resolved) => performRename(resolved, true),
47
+ );
48
+ }
29
49
  try {
30
- return await withWorkspace(() => workspaceForCodeIntelligencePath(fromPath), performRename);
50
+ return await withWorkspace(
51
+ () => Promise.resolve(narrow),
52
+ (resolved) => performRename(resolved, false),
53
+ );
31
54
  } catch (error) {
32
55
  if (!remoteErrorIs(error, "ReferenceBasedRenameRequiresFreshGraph")) throw error;
33
- const narrow = await workspaceForCodeIntelligencePath(fromPath);
34
- const declared = await workspaceForDeclaredMonorepoRoot(narrow.root);
35
- if (!declared) throw error;
36
- return withWorkspace(() => Promise.resolve(declared), performRename);
56
+ return withWorkspace(
57
+ () => Promise.resolve(declared),
58
+ (resolved) => performRename(resolved, true),
59
+ );
37
60
  }
38
61
  },
39
62
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danypops/pi-lector",
3
- "version": "0.12.8",
3
+ "version": "0.12.9",
4
4
  "description": "Pi host adapter for Lector: overrides read/write/edit with a daemon-backed, hash-guarded filesystem",
5
5
  "license": "MIT",
6
6
  "type": "module",