@mrclrchtr/supi-code-intelligence 1.4.0 → 1.6.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.
Files changed (57) hide show
  1. package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  2. package/node_modules/@mrclrchtr/supi-core/src/api.ts +2 -0
  3. package/node_modules/@mrclrchtr/supi-core/src/index.ts +2 -0
  4. package/node_modules/@mrclrchtr/supi-core/src/path-utils.ts +40 -0
  5. package/node_modules/@mrclrchtr/supi-core/src/registry-utils.ts +42 -10
  6. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  7. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/api.ts +2 -0
  8. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/index.ts +2 -0
  9. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/path-utils.ts +40 -0
  10. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/registry-utils.ts +42 -10
  11. package/node_modules/@mrclrchtr/supi-lsp/package.json +3 -2
  12. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-project-info.ts +2 -16
  13. package/node_modules/@mrclrchtr/supi-lsp/src/pattern-matcher.ts +11 -184
  14. package/node_modules/@mrclrchtr/supi-lsp/src/session/service-registry.ts +5 -21
  15. package/node_modules/@mrclrchtr/supi-lsp/src/tool/guidance.ts +15 -75
  16. package/node_modules/@mrclrchtr/supi-lsp/src/tool/register-tools.ts +13 -166
  17. package/node_modules/@mrclrchtr/supi-lsp/src/tool/tool-specs.ts +248 -0
  18. package/node_modules/@mrclrchtr/supi-lsp/src/utils.ts +5 -34
  19. package/node_modules/@mrclrchtr/supi-tree-sitter/README.md +18 -6
  20. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/README.md +107 -0
  21. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +44 -0
  22. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/api.ts +85 -0
  23. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/config/config-settings.ts +76 -0
  24. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/config/config.ts +186 -0
  25. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/context/context-messages.ts +119 -0
  26. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/context/context-provider-registry.ts +36 -0
  27. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/context/context-tag.ts +31 -0
  28. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +255 -0
  29. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/extension.ts +1 -0
  30. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/index.ts +85 -0
  31. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/path-utils.ts +40 -0
  32. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/project-roots.ts +170 -0
  33. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/registry-utils.ts +86 -0
  34. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/session-utils.ts +29 -0
  35. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/settings/settings-command.ts +15 -0
  36. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +41 -0
  37. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/settings/settings-ui.ts +226 -0
  38. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/terminal.ts +60 -0
  39. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +8 -3
  40. package/node_modules/@mrclrchtr/supi-tree-sitter/src/api.ts +5 -1
  41. package/node_modules/@mrclrchtr/supi-tree-sitter/src/index.ts +5 -1
  42. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/runtime.ts +3 -2
  43. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/service-registry.ts +30 -0
  44. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/session.ts +16 -8
  45. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/action-specs.ts +92 -0
  46. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/guidance.ts +12 -3
  47. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tree-sitter.ts +111 -61
  48. package/node_modules/@mrclrchtr/supi-tree-sitter/src/types.ts +13 -2
  49. package/package.json +4 -4
  50. package/src/actions/brief-action.ts +5 -5
  51. package/src/code-intelligence.ts +3 -10
  52. package/src/pattern-structured.ts +1 -1
  53. package/src/providers/structural-provider.ts +15 -3
  54. package/src/search-helpers.ts +4 -15
  55. package/src/tool/action-specs.ts +66 -0
  56. package/src/tool/guidance.ts +4 -7
  57. package/src/tool-actions.ts +23 -40
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrclrchtr/supi-core",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "SuPi core — shared infrastructure for SuPi extensions (XML context tags, config system)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -49,6 +49,7 @@ export {
49
49
  redactDebugData,
50
50
  resetDebugRegistry,
51
51
  } from "./debug-registry.ts";
52
+ export { fileToUri, resolveToolPath, stripToolPathPrefix, uriToFile } from "./path-utils.ts";
52
53
  export type { KnownRootEntry } from "./project-roots.ts";
53
54
  export {
54
55
  buildKnownRootsMap,
@@ -63,6 +64,7 @@ export {
63
64
  sortRootsBySpecificity,
64
65
  walkProject,
65
66
  } from "./project-roots.ts";
67
+ export { createRegistry, createSessionStateRegistry } from "./registry-utils.ts";
66
68
  export { getActiveBranchEntries } from "./session-utils.ts";
67
69
  export { registerSettingsCommand } from "./settings/settings-command.ts";
68
70
  export type { SettingsScope, SettingsSection } from "./settings/settings-registry.ts";
@@ -49,6 +49,7 @@ export {
49
49
  redactDebugData,
50
50
  resetDebugRegistry,
51
51
  } from "./debug-registry.ts";
52
+ export { fileToUri, resolveToolPath, stripToolPathPrefix, uriToFile } from "./path-utils.ts";
52
53
  export type { KnownRootEntry } from "./project-roots.ts";
53
54
  export {
54
55
  buildKnownRootsMap,
@@ -63,6 +64,7 @@ export {
63
64
  sortRootsBySpecificity,
64
65
  walkProject,
65
66
  } from "./project-roots.ts";
67
+ export { createRegistry, createSessionStateRegistry } from "./registry-utils.ts";
66
68
  export { getActiveBranchEntries } from "./session-utils.ts";
67
69
  export { registerSettingsCommand } from "./settings/settings-command.ts";
68
70
  export type { SettingsScope, SettingsSection } from "./settings/settings-registry.ts";
@@ -0,0 +1,40 @@
1
+ import * as path from "node:path";
2
+
3
+ /** Strip pi's optional leading `@` file-path prefix from a tool input. */
4
+ export function stripToolPathPrefix(target: string): string {
5
+ return target.startsWith("@") ? target.slice(1) : target;
6
+ }
7
+
8
+ /**
9
+ * Resolve a tool-style file path from a session cwd.
10
+ *
11
+ * Built-in pi file tools accept a leading `@` prefix in path arguments, so
12
+ * shared SuPi path helpers normalize that prefix before resolving relative
13
+ * paths.
14
+ */
15
+ export function resolveToolPath(cwd: string, target: string): string {
16
+ return path.resolve(cwd, stripToolPathPrefix(target));
17
+ }
18
+
19
+ /** Convert a file path to a file:// URI. */
20
+ export function fileToUri(filePath: string): string {
21
+ const resolved = path.resolve(filePath);
22
+ if (process.platform === "win32") {
23
+ return `file:///${resolved.replace(/\\/g, "/")}`;
24
+ }
25
+ return `file://${resolved}`;
26
+ }
27
+
28
+ /** Convert a file:// URI to a file path. */
29
+ export function uriToFile(uri: string): string {
30
+ if (!uri.startsWith("file://")) return uri;
31
+ let filePath = decodeURIComponent(uri.slice(7));
32
+ if (
33
+ process.platform === "win32" &&
34
+ filePath.startsWith("/") &&
35
+ /^[A-Za-z]:/.test(filePath.slice(1))
36
+ ) {
37
+ filePath = filePath.slice(1);
38
+ }
39
+ return filePath;
40
+ }
@@ -5,8 +5,20 @@
5
5
  // Without this, each symlink path gets its own module copy and its own Map,
6
6
  // so registrations from one instance are invisible to consumers in another.
7
7
 
8
+ import * as path from "node:path";
9
+
8
10
  const SYMBOL_PREFIX = "@mrclrchtr/supi-core/";
9
11
 
12
+ function getGlobalRegistryMap<T>(name: string): Map<string, T> {
13
+ const key = Symbol.for(SYMBOL_PREFIX + name);
14
+ let map = (globalThis as Record<symbol, unknown>)[key] as Map<string, T> | undefined;
15
+ if (!map) {
16
+ map = new Map<string, T>();
17
+ (globalThis as Record<symbol, unknown>)[key] = map;
18
+ }
19
+ return map;
20
+ }
21
+
10
22
  /**
11
23
  * Create a named registry backed by `globalThis` + `Symbol.for`.
12
24
  *
@@ -18,16 +30,7 @@ const SYMBOL_PREFIX = "@mrclrchtr/supi-core/";
18
30
  * @returns An object with `register`, `getAll`, and `clear` functions.
19
31
  */
20
32
  export function createRegistry<T>(name: string) {
21
- const key = Symbol.for(SYMBOL_PREFIX + name);
22
-
23
- const getMap = (): Map<string, T> => {
24
- let map = (globalThis as Record<symbol, unknown>)[key] as Map<string, T> | undefined;
25
- if (!map) {
26
- map = new Map<string, T>();
27
- (globalThis as Record<symbol, unknown>)[key] = map;
28
- }
29
- return map;
30
- };
33
+ const getMap = (): Map<string, T> => getGlobalRegistryMap<T>(name);
31
34
 
32
35
  return {
33
36
  /**
@@ -52,3 +55,32 @@ export function createRegistry<T>(name: string) {
52
55
  },
53
56
  };
54
57
  }
58
+
59
+ /**
60
+ * Create a named session-state registry keyed by normalized cwd.
61
+ *
62
+ * This helper is intended for session-scoped runtime services that should be
63
+ * shared across duplicate jiti module instances while keeping package-specific
64
+ * state unions and convenience wrappers local to the calling package.
65
+ */
66
+ export function createSessionStateRegistry<TState>(name: string) {
67
+ const getMap = (): Map<string, TState> => getGlobalRegistryMap<TState>(name);
68
+ const normalizeCwd = (cwd: string): string => path.resolve(cwd);
69
+
70
+ return {
71
+ /** Get the current state for one session cwd. */
72
+ get: (cwd: string): TState | undefined => {
73
+ return getMap().get(normalizeCwd(cwd));
74
+ },
75
+
76
+ /** Store the current state for one session cwd. */
77
+ set: (cwd: string, state: TState): void => {
78
+ getMap().set(normalizeCwd(cwd), state);
79
+ },
80
+
81
+ /** Clear the current state for one session cwd. */
82
+ clear: (cwd: string): void => {
83
+ getMap().delete(normalizeCwd(cwd));
84
+ },
85
+ };
86
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrclrchtr/supi-core",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "SuPi core — shared infrastructure for SuPi extensions (XML context tags, config system)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -49,6 +49,7 @@ export {
49
49
  redactDebugData,
50
50
  resetDebugRegistry,
51
51
  } from "./debug-registry.ts";
52
+ export { fileToUri, resolveToolPath, stripToolPathPrefix, uriToFile } from "./path-utils.ts";
52
53
  export type { KnownRootEntry } from "./project-roots.ts";
53
54
  export {
54
55
  buildKnownRootsMap,
@@ -63,6 +64,7 @@ export {
63
64
  sortRootsBySpecificity,
64
65
  walkProject,
65
66
  } from "./project-roots.ts";
67
+ export { createRegistry, createSessionStateRegistry } from "./registry-utils.ts";
66
68
  export { getActiveBranchEntries } from "./session-utils.ts";
67
69
  export { registerSettingsCommand } from "./settings/settings-command.ts";
68
70
  export type { SettingsScope, SettingsSection } from "./settings/settings-registry.ts";
@@ -49,6 +49,7 @@ export {
49
49
  redactDebugData,
50
50
  resetDebugRegistry,
51
51
  } from "./debug-registry.ts";
52
+ export { fileToUri, resolveToolPath, stripToolPathPrefix, uriToFile } from "./path-utils.ts";
52
53
  export type { KnownRootEntry } from "./project-roots.ts";
53
54
  export {
54
55
  buildKnownRootsMap,
@@ -63,6 +64,7 @@ export {
63
64
  sortRootsBySpecificity,
64
65
  walkProject,
65
66
  } from "./project-roots.ts";
67
+ export { createRegistry, createSessionStateRegistry } from "./registry-utils.ts";
66
68
  export { getActiveBranchEntries } from "./session-utils.ts";
67
69
  export { registerSettingsCommand } from "./settings/settings-command.ts";
68
70
  export type { SettingsScope, SettingsSection } from "./settings/settings-registry.ts";
@@ -0,0 +1,40 @@
1
+ import * as path from "node:path";
2
+
3
+ /** Strip pi's optional leading `@` file-path prefix from a tool input. */
4
+ export function stripToolPathPrefix(target: string): string {
5
+ return target.startsWith("@") ? target.slice(1) : target;
6
+ }
7
+
8
+ /**
9
+ * Resolve a tool-style file path from a session cwd.
10
+ *
11
+ * Built-in pi file tools accept a leading `@` prefix in path arguments, so
12
+ * shared SuPi path helpers normalize that prefix before resolving relative
13
+ * paths.
14
+ */
15
+ export function resolveToolPath(cwd: string, target: string): string {
16
+ return path.resolve(cwd, stripToolPathPrefix(target));
17
+ }
18
+
19
+ /** Convert a file path to a file:// URI. */
20
+ export function fileToUri(filePath: string): string {
21
+ const resolved = path.resolve(filePath);
22
+ if (process.platform === "win32") {
23
+ return `file:///${resolved.replace(/\\/g, "/")}`;
24
+ }
25
+ return `file://${resolved}`;
26
+ }
27
+
28
+ /** Convert a file:// URI to a file path. */
29
+ export function uriToFile(uri: string): string {
30
+ if (!uri.startsWith("file://")) return uri;
31
+ let filePath = decodeURIComponent(uri.slice(7));
32
+ if (
33
+ process.platform === "win32" &&
34
+ filePath.startsWith("/") &&
35
+ /^[A-Za-z]:/.test(filePath.slice(1))
36
+ ) {
37
+ filePath = filePath.slice(1);
38
+ }
39
+ return filePath;
40
+ }
@@ -5,8 +5,20 @@
5
5
  // Without this, each symlink path gets its own module copy and its own Map,
6
6
  // so registrations from one instance are invisible to consumers in another.
7
7
 
8
+ import * as path from "node:path";
9
+
8
10
  const SYMBOL_PREFIX = "@mrclrchtr/supi-core/";
9
11
 
12
+ function getGlobalRegistryMap<T>(name: string): Map<string, T> {
13
+ const key = Symbol.for(SYMBOL_PREFIX + name);
14
+ let map = (globalThis as Record<symbol, unknown>)[key] as Map<string, T> | undefined;
15
+ if (!map) {
16
+ map = new Map<string, T>();
17
+ (globalThis as Record<symbol, unknown>)[key] = map;
18
+ }
19
+ return map;
20
+ }
21
+
10
22
  /**
11
23
  * Create a named registry backed by `globalThis` + `Symbol.for`.
12
24
  *
@@ -18,16 +30,7 @@ const SYMBOL_PREFIX = "@mrclrchtr/supi-core/";
18
30
  * @returns An object with `register`, `getAll`, and `clear` functions.
19
31
  */
20
32
  export function createRegistry<T>(name: string) {
21
- const key = Symbol.for(SYMBOL_PREFIX + name);
22
-
23
- const getMap = (): Map<string, T> => {
24
- let map = (globalThis as Record<symbol, unknown>)[key] as Map<string, T> | undefined;
25
- if (!map) {
26
- map = new Map<string, T>();
27
- (globalThis as Record<symbol, unknown>)[key] = map;
28
- }
29
- return map;
30
- };
33
+ const getMap = (): Map<string, T> => getGlobalRegistryMap<T>(name);
31
34
 
32
35
  return {
33
36
  /**
@@ -52,3 +55,32 @@ export function createRegistry<T>(name: string) {
52
55
  },
53
56
  };
54
57
  }
58
+
59
+ /**
60
+ * Create a named session-state registry keyed by normalized cwd.
61
+ *
62
+ * This helper is intended for session-scoped runtime services that should be
63
+ * shared across duplicate jiti module instances while keeping package-specific
64
+ * state unions and convenience wrappers local to the calling package.
65
+ */
66
+ export function createSessionStateRegistry<TState>(name: string) {
67
+ const getMap = (): Map<string, TState> => getGlobalRegistryMap<TState>(name);
68
+ const normalizeCwd = (cwd: string): string => path.resolve(cwd);
69
+
70
+ return {
71
+ /** Get the current state for one session cwd. */
72
+ get: (cwd: string): TState | undefined => {
73
+ return getMap().get(normalizeCwd(cwd));
74
+ },
75
+
76
+ /** Store the current state for one session cwd. */
77
+ set: (cwd: string, state: TState): void => {
78
+ getMap().set(normalizeCwd(cwd), state);
79
+ },
80
+
81
+ /** Clear the current state for one session cwd. */
82
+ clear: (cwd: string): void => {
83
+ getMap().delete(normalizeCwd(cwd));
84
+ },
85
+ };
86
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrclrchtr/supi-lsp",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "SuPi LSP extension — Language Server Protocol integration for pi",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -21,8 +21,9 @@
21
21
  "!__tests__"
22
22
  ],
23
23
  "dependencies": {
24
+ "ignore": "^7.0.5",
24
25
  "typescript": "6.0.3",
25
- "@mrclrchtr/supi-core": "1.4.0"
26
+ "@mrclrchtr/supi-core": "1.6.0"
26
27
  },
27
28
  "bundledDependencies": [
28
29
  "@mrclrchtr/supi-core"
@@ -1,6 +1,7 @@
1
1
  import type { LspClient } from "../client/client.ts";
2
2
  import type { ProjectServerInfo } from "../config/types.ts";
3
3
  import { displayRelativeFilePath } from "../summary.ts";
4
+ import { getSupportedLspServerActions } from "../tool/tool-specs.ts";
4
5
 
5
6
  interface ProjectServerInfoInput {
6
7
  serverName: string;
@@ -28,22 +29,7 @@ export function buildProjectServerInfo(
28
29
  root: input.root,
29
30
  fileTypes: input.fileTypes,
30
31
  status,
31
- supportedActions: getSupportedActions(input.client?.serverCapabilities),
32
+ supportedActions: getSupportedLspServerActions(input.client?.serverCapabilities),
32
33
  openFiles: input.client?.openFiles.map((file) => displayRelativeFilePath(file, cwd)) ?? [],
33
34
  };
34
35
  }
35
-
36
- function getSupportedActions(capabilities: LspClient["serverCapabilities"] | undefined): string[] {
37
- if (!capabilities) return [];
38
-
39
- const actions: string[] = ["diagnostics [optional file]"];
40
- if (capabilities.hoverProvider) actions.push("hover(file,line,char)");
41
- if (capabilities.definitionProvider) actions.push("definition(file,line,char)");
42
- if (capabilities.referencesProvider) actions.push("references(file,line,char)");
43
- if (capabilities.implementationProvider) actions.push("implementation(file,line,char)");
44
- if (capabilities.documentSymbolProvider) actions.push("symbols(file)");
45
- if (capabilities.workspaceSymbolProvider) actions.push("workspace_symbols(query)");
46
- if (capabilities.renameProvider) actions.push("rename(file,line,char,newName)");
47
- if (capabilities.codeActionProvider) actions.push("code_actions(file,line,char)");
48
- return actions;
49
- }
@@ -1,20 +1,15 @@
1
+ import ignore from "ignore";
2
+
1
3
  /** Gitignore-style glob pattern matching for path exclusion.
2
4
  *
3
- * Supports:
4
- * - Literal names at any depth: __tests__, build
5
- * - Trailing slash directory-only: __tests__ + "/"
6
- * - Leading slash root-anchored: "/" + build
7
- * - Stars-star-slash recursive: e.g. `**` + "/" + fixtures
8
- * - Asterisk single-segment wildcard: *.generated.ts
9
- * - Literal paths: packages + "/" + legacy
10
- */
11
-
12
- /**
13
- * Normalize path separators to forward slashes and trim.
5
+ * Delegates to the {@link https://github.com/kaelzhang/node-ignore | ignore} package,
6
+ * which provides battle-tested .gitignore semantics used by ESLint, Prettier, and others.
7
+ *
8
+ * Supports full gitignore syntax: literal names, `*` / `?` wildcards, `**` recursive globs,
9
+ * leading `/` anchored patterns, trailing `/` directory-only patterns, and `!` negation.
10
+ *
11
+ * **Note:** Patterns that start with `#` are treated as comments unless escaped with `\#`.
14
12
  */
15
- function normalize(p: string): string {
16
- return p.replaceAll("\\", "/").trim();
17
- }
18
13
 
19
14
  /**
20
15
  * Check whether a project-relative file path matches a gitignore-style glob pattern.
@@ -24,174 +19,6 @@ function normalize(p: string): string {
24
19
  * @returns `true` if the file path matches the pattern
25
20
  */
26
21
  export function isGlobMatch(filePath: string, pattern: string): boolean {
27
- const fp = normalize(filePath);
28
- const pat = normalize(pattern);
29
- if (!fp || !pat) return false;
30
-
31
- // Leading / → anchored to root
32
- const anchored = pat.startsWith("/");
33
- const noLeadingSlash = anchored ? pat.slice(1) : pat;
34
-
35
- // Trailing / → directory-only
36
- const dirOnly = noLeadingSlash.endsWith("/");
37
- const cleanPat = dirOnly ? noLeadingSlash.slice(0, -1) : noLeadingSlash;
38
-
39
- if (!cleanPat) return false;
40
-
41
- return matchGlob(fp, cleanPat, { anchored, dirOnly });
42
- }
43
-
44
- interface MatchOptions {
45
- anchored: boolean;
46
- dirOnly: boolean;
47
- }
48
-
49
- /**
50
- * Core recursive pattern matching against a multi-segment path.
51
- */
52
- function matchGlob(filePath: string, pattern: string, opts: MatchOptions): boolean {
53
- // Direct match
54
- if (!opts.anchored && !opts.dirOnly && filePath === pattern) return true;
55
-
56
- // Split into segments
57
- const pathSegments = filePath.split("/");
58
- const patternSegments = pattern.split("/");
59
-
60
- // ** recursive glob
61
- if (pattern.startsWith("**/")) {
62
- const suffix = pattern.slice(3);
63
- return (
64
- matchGlob(filePath, suffix, { ...opts, anchored: false }) ||
65
- starStarMatch(pathSegments, suffix)
66
- );
67
- }
68
-
69
- // prefix/**/suffix bounded recursive glob
70
- const dstarIdx = pattern.indexOf("/**/");
71
- if (dstarIdx !== -1) {
72
- const prefix = pattern.slice(0, dstarIdx);
73
- const suffix = pattern.slice(dstarIdx + 4);
74
- return matchBoundedStar(pathSegments, prefix, suffix);
75
- }
76
-
77
- // Single-segment patterns
78
- if (patternSegments.length === 1 && !opts.anchored) {
79
- return matchSingleSegment(pathSegments, patternSegments[0], opts.dirOnly);
80
- }
81
-
82
- // Multi-segment: anchored or unanchored
83
- if (opts.anchored) {
84
- return matchSegments(pathSegments, patternSegments, opts.dirOnly);
85
- }
86
-
87
- // Unanchored multi-segment: try at each starting position
88
- return matchUnanchoredSegments(pathSegments, patternSegments, opts.dirOnly);
89
- }
90
-
91
- /**
92
- * Match a ** recursive suffix across directory levels.
93
- */
94
- function starStarMatch(segments: string[], suffix: string): boolean {
95
- for (let i = 0; i < segments.length; i++) {
96
- const remaining = segments.slice(i).join("/");
97
- if (matchGlob(remaining, suffix, { anchored: false, dirOnly: false })) return true;
98
- }
99
- return false;
100
- }
101
-
102
- /** Match prefix plus star-star-slash plus suffix bounded recursive pattern. */
103
- function matchBoundedStar(segments: string[], prefix: string, suffix: string): boolean {
104
- // Try to find a split point where left matches prefix and right matches suffix
105
- for (let i = 1; i < segments.length; i++) {
106
- const left = segments.slice(0, i).join("/");
107
- const right = segments.slice(i).join("/");
108
- if (
109
- matchGlob(left, prefix, { anchored: false, dirOnly: false }) &&
110
- matchGlob(right, suffix, { anchored: false, dirOnly: false })
111
- ) {
112
- return true;
113
- }
114
- }
115
- return false;
116
- }
117
-
118
- /**
119
- * Match a single-segment pattern against path segments.
120
- */
121
- function matchSingleSegment(segments: string[], patternSeg: string, dirOnly: boolean): boolean {
122
- const hasGlob = patternSeg.includes("*") || patternSeg.includes("?");
123
-
124
- if (hasGlob) {
125
- // Glob pattern matches any segment
126
- return segments.some((seg) => simpleMatch(seg, patternSeg));
127
- }
128
-
129
- // Literal segment name
130
- if (dirOnly) {
131
- // Match as directory: any segment except the last (file) one
132
- return segments.slice(0, -1).some((seg) => seg === patternSeg);
133
- }
134
-
135
- // Match any segment (file or directory)
136
- return segments.some((seg) => seg === patternSeg);
137
- }
138
-
139
- /**
140
- * Try to match multi-segment pattern at each start position.
141
- */
142
- function matchUnanchoredSegments(segments: string[], pattern: string[], dirOnly: boolean): boolean {
143
- for (let i = 0; i < segments.length; i++) {
144
- if (matchSegments(segments.slice(i), pattern, dirOnly)) return true;
145
- }
146
- return false;
147
- }
148
-
149
- /** Match segments from start. Returns true if all pattern segments match contiguously. */
150
- function matchSegments(segments: string[], pattern: string[], dirOnly: boolean): boolean {
151
- if (pattern.length > segments.length) return false;
152
-
153
- for (let i = 0; i < pattern.length; i++) {
154
- if (!matchSegmentAtIndex(segments, pattern, i)) return false;
155
- }
156
-
157
- // dirOnly: last matched segment must not be the last path segment
158
- if (dirOnly && pattern.length === segments.length) return false;
159
-
160
- return true;
161
- }
162
-
163
- /** Match a single pattern segment against the corresponding path segment. */
164
- function matchSegmentAtIndex(segments: string[], pattern: string[], index: number): boolean {
165
- const patSeg = pattern[index];
166
- const pathSeg = segments[index];
167
-
168
- if (patSeg === "**") {
169
- // ** at end matches all remaining segments
170
- if (index === pattern.length - 1) return true;
171
- // Try rest of pattern from various positions
172
- for (let j = index; j < segments.length; j++) {
173
- if (matchSegments(segments.slice(j), pattern.slice(index + 1), false)) return true;
174
- }
175
- return false;
176
- }
177
-
178
- return simpleMatch(pathSeg, patSeg);
179
- }
180
-
181
- /**
182
- * Match a single path segment against a single pattern segment.
183
- * Supports `*` (any chars except `/`) and `?` (single char).
184
- */
185
- function simpleMatch(segment: string, pattern: string): boolean {
186
- if (pattern === "*") return true;
187
- if (pattern === segment) return true;
188
- if (!pattern.includes("*") && !pattern.includes("?")) return false;
189
-
190
- // Convert pattern to simple regex
191
- const regexStr = pattern
192
- .replace(/[.+^${}()|[\]\\]/g, "\\$&")
193
- .replace(/\*/g, "[^/]*")
194
- .replace(/\?/g, "[^/]");
195
-
196
- return new RegExp(`^${regexStr}$`).test(segment);
22
+ if (!filePath || !pattern) return false;
23
+ return ignore().add(pattern).ignores(filePath);
197
24
  }
@@ -2,7 +2,7 @@
2
2
  // Peer extensions can import `getSessionLspService` from the package root
3
3
  // to reuse the active LSP runtime without starting duplicate servers.
4
4
 
5
- import * as path from "node:path";
5
+ import { createSessionStateRegistry } from "@mrclrchtr/supi-core/api";
6
6
  import type {
7
7
  CodeAction,
8
8
  Diagnostic,
@@ -189,34 +189,18 @@ export class SessionLspService {
189
189
 
190
190
  // ── Registry ──────────────────────────────────────────────────────────
191
191
 
192
- const REGISTRY_KEY = Symbol.for("@mrclrchtr/supi-lsp/session-registry");
193
192
  const WAIT_INTERVAL_MS = 25;
194
-
195
- function getRegistry(): Map<string, SessionLspServiceState> {
196
- const globalScope = globalThis as typeof globalThis & Record<symbol, unknown>;
197
- const existing = globalScope[REGISTRY_KEY];
198
- if (existing instanceof Map) return existing as Map<string, SessionLspServiceState>;
199
-
200
- const registry = new Map<string, SessionLspServiceState>();
201
- globalScope[REGISTRY_KEY] = registry;
202
- return registry;
203
- }
204
-
205
- function normalizeCwd(cwd: string): string {
206
- return path.resolve(cwd);
207
- }
208
-
209
- const registry = getRegistry();
193
+ const registry = createSessionStateRegistry<SessionLspServiceState>("supi-lsp/session-registry");
210
194
 
211
195
  /** Publish the LSP service state for a session cwd. */
212
196
  export function setSessionLspServiceState(cwd: string, state: SessionLspServiceState): void {
213
- registry.set(normalizeCwd(cwd), state);
197
+ registry.set(cwd, state);
214
198
  }
215
199
 
216
200
  /** Acquire the LSP service state for a session cwd. */
217
201
  export function getSessionLspService(cwd: string): SessionLspServiceState {
218
202
  return (
219
- registry.get(normalizeCwd(cwd)) ?? {
203
+ registry.get(cwd) ?? {
220
204
  kind: "unavailable",
221
205
  reason: "No LSP session initialized for this workspace",
222
206
  }
@@ -241,5 +225,5 @@ export async function waitForSessionLspService(
241
225
 
242
226
  /** Remove the LSP service state for a session cwd. */
243
227
  export function clearSessionLspService(cwd: string): void {
244
- registry.delete(normalizeCwd(cwd));
228
+ registry.clear(cwd);
245
229
  }