@mrclrchtr/supi-code-intelligence 11.2.0 → 11.4.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 (145) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +19 -9
  3. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  4. package/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +2 -1
  5. package/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +3 -1
  6. package/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
  7. package/node_modules/@mrclrchtr/supi-code-runtime/src/query-result.ts +9 -0
  8. package/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +13 -5
  9. package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  10. package/node_modules/@mrclrchtr/supi-core/src/child-web-tools.ts +110 -0
  11. package/node_modules/@mrclrchtr/supi-core/src/session.ts +11 -0
  12. package/node_modules/@mrclrchtr/supi-lsp/README.md +40 -3
  13. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  14. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +2 -1
  15. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +3 -1
  16. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
  17. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/query-result.ts +9 -0
  18. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +13 -5
  19. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  20. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/child-web-tools.ts +110 -0
  21. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/session.ts +11 -0
  22. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/range.js +2 -2
  23. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/constants.js +30 -0
  24. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/trim-comparator-whitespace.js +438 -0
  25. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/package.json +1 -1
  26. package/node_modules/@mrclrchtr/supi-lsp/package.json +3 -3
  27. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-collection.ts +11 -4
  28. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostics.ts +77 -6
  29. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-input-admission.ts +149 -0
  30. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-typescript-project.ts +40 -0
  31. package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +151 -44
  32. package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-scope.ts +10 -0
  33. package/node_modules/@mrclrchtr/supi-lsp/src/diagnostics/evidence.ts +2 -2
  34. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-typescript-coverage.ts +118 -0
  35. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-workspace-symbol.ts +157 -23
  36. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +318 -58
  37. package/node_modules/@mrclrchtr/supi-lsp/src/manager/typescript-file-local.ts +87 -0
  38. package/node_modules/@mrclrchtr/supi-lsp/src/provider/semantic-symbol-mapper.ts +22 -17
  39. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +68 -6
  40. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-rename.ts +1 -0
  41. package/node_modules/@mrclrchtr/supi-lsp/src/session/workspace-lsp-runtime.ts +5 -1
  42. package/node_modules/@mrclrchtr/supi-tree-sitter/README.md +2 -2
  43. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  44. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +2 -1
  45. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +3 -1
  46. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
  47. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/query-result.ts +9 -0
  48. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +13 -5
  49. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  50. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/child-web-tools.ts +110 -0
  51. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/session.ts +11 -0
  52. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +3 -3
  53. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm +0 -0
  54. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm.json +9 -1
  55. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm +0 -0
  56. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm.json +9 -1
  57. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-sites.ts +40 -25
  58. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/callees.ts +2 -0
  59. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/call-context.ts +44 -0
  60. package/package.json +6 -5
  61. package/src/analysis/health/server-status.ts +6 -2
  62. package/src/analysis/helpers.ts +0 -7
  63. package/src/analysis/relations/implementations.ts +5 -0
  64. package/src/analysis/relations/references.ts +5 -0
  65. package/src/analysis/search/exclusions.ts +47 -0
  66. package/src/analysis/search/paths.ts +32 -9
  67. package/src/analysis/target/anchored-structural.ts +3 -8
  68. package/src/analysis/target/anchored.ts +4 -20
  69. package/src/analysis/target/file-merge.ts +162 -0
  70. package/src/analysis/target/file-outline-omissions.ts +146 -0
  71. package/src/analysis/target/file-refinement.ts +7 -7
  72. package/src/analysis/target/file.ts +44 -156
  73. package/src/analysis/target/identity.ts +1 -1
  74. package/src/analysis/target/latex-label-container.ts +6 -6
  75. package/src/analysis/target/latex-section-anchor.ts +6 -6
  76. package/src/analysis/target/resolution.ts +18 -0
  77. package/src/analysis/target/symbol.ts +44 -12
  78. package/src/analysis/target/types.ts +38 -7
  79. package/src/api.ts +1 -1
  80. package/src/app/app.ts +9 -3
  81. package/src/extension.ts +17 -11
  82. package/src/session/graph/collect.ts +3 -10
  83. package/src/session/graph-types.ts +5 -1
  84. package/src/session/graph-workflow.ts +6 -4
  85. package/src/session/inspect/collect.ts +8 -2
  86. package/src/session/inspect/file-point.ts +2 -3
  87. package/src/session/inspect-workflow.ts +1 -1
  88. package/src/session/orientation/collect.ts +54 -16
  89. package/src/session/orientation/context-sections.ts +2 -3
  90. package/src/session/orientation/facts.ts +9 -1
  91. package/src/session/orientation/workspace-context.ts +3 -0
  92. package/src/session/orientation-types.ts +3 -0
  93. package/src/session/orientation-workflow.ts +24 -8
  94. package/src/session/refactor-identity.ts +76 -0
  95. package/src/session/refactor-workflow.ts +14 -16
  96. package/src/session/session.ts +87 -12
  97. package/src/session/target-store.ts +3 -18
  98. package/src/session/target-workflow.ts +56 -37
  99. package/src/substrate/lsp/recovery.ts +5 -5
  100. package/src/tool/code_find/render.ts +8 -4
  101. package/src/tool/code_find/result.ts +78 -6
  102. package/src/tool/code_find/spec.ts +4 -3
  103. package/src/tool/code_find/structured.ts +25 -9
  104. package/src/tool/code_graph/details.ts +1 -0
  105. package/src/tool/code_graph/display.ts +1 -1
  106. package/src/tool/code_graph/guidance.ts +1 -1
  107. package/src/tool/code_graph/markdown.ts +11 -6
  108. package/src/tool/code_graph/read-next.ts +38 -9
  109. package/src/tool/code_graph/reference-selection.ts +30 -0
  110. package/src/tool/code_graph/result.ts +25 -118
  111. package/src/tool/code_graph/section.ts +137 -0
  112. package/src/tool/code_graph/spec.ts +3 -3
  113. package/src/tool/code_graph/structured.ts +17 -6
  114. package/src/tool/code_health/display-paths.ts +92 -0
  115. package/src/tool/code_health/file-scope-markdown.ts +3 -2
  116. package/src/tool/code_health/result.ts +4 -2
  117. package/src/tool/code_health/spec.ts +3 -3
  118. package/src/tool/code_health/structured-schema.ts +44 -44
  119. package/src/tool/code_inspect/spec.ts +5 -1
  120. package/src/tool/code_inspect/structured.ts +1 -2
  121. package/src/tool/code_orientation/directory-navigation.ts +20 -31
  122. package/src/tool/code_orientation/execute.ts +1 -1
  123. package/src/tool/code_orientation/result.ts +22 -5
  124. package/src/tool/code_orientation/structured-schema.ts +46 -36
  125. package/src/tool/code_orientation/structured-workspace.ts +2 -1
  126. package/src/tool/code_orientation/structured.ts +6 -12
  127. package/src/tool/code_orientation/workspace-format.ts +2 -5
  128. package/src/tool/code_orientation/workspace-output.ts +40 -13
  129. package/src/tool/code_orientation/workspace-sections.ts +48 -4
  130. package/src/tool/code_refactor_apply/result.ts +1 -1
  131. package/src/tool/code_refactor_plan/result.ts +2 -1
  132. package/src/tool/code_refactor_plan/structured.ts +2 -3
  133. package/src/tool/code_resolve/guidance.ts +1 -1
  134. package/src/tool/code_resolve/markdown.ts +127 -64
  135. package/src/tool/code_resolve/result.ts +41 -25
  136. package/src/tool/code_resolve/structured.ts +49 -18
  137. package/src/tool/result/model-budget.ts +2 -2
  138. package/src/tool/result/refactor.ts +8 -5
  139. package/src/tool/result/structured.ts +8 -5
  140. package/src/tool/result/types.ts +31 -24
  141. package/src/tool/schemas.ts +5 -5
  142. package/src/ui/status-command.ts +37 -1
  143. package/src/ui/status-overlay.ts +70 -51
  144. package/src/ui/status-presentation.ts +108 -0
  145. package/src/ui/tui/common.ts +10 -10
@@ -34,8 +34,16 @@ export interface SymbolAnchor {
34
34
  character: number;
35
35
  }
36
36
 
37
- /** Provider-backed nesting evidence for a declaration reported within one document. */
38
- export type DeclarationNesting = "top-level" | "nested" | "unknown";
37
+ /**
38
+ * Where a declaration sits within its file, as reported by a provider.
39
+ *
40
+ * - `top-level`: directly in the file, not inside another declaration.
41
+ * - `member`: directly inside a class, interface, enum, struct, namespace,
42
+ * module, or object literal (methods, fields, properties, enum members).
43
+ * - `local`: inside the body of a function, method, or constructor.
44
+ * - `unknown`: the provider reported a flat symbol list without hierarchy.
45
+ */
46
+ export type DeclarationLevel = "top-level" | "member" | "local" | "unknown";
39
47
 
40
48
  /**
41
49
  * A discovered symbol / declaration.
@@ -54,7 +62,7 @@ export interface CodeSymbol {
54
62
  file: string;
55
63
  declarationAnchor: SymbolAnchor;
56
64
  nameAnchor?: SymbolAnchor;
57
- /** Named symbolic container when reported; absence does not prove top-level nesting. */
65
+ /** Named enclosing declaration when reported; absence does not prove a top-level declaration. */
58
66
  container?: string | null;
59
67
  }
60
68
 
@@ -63,10 +71,10 @@ export interface CodeSymbol {
63
71
  *
64
72
  * `unknown` means the provider returned a flat observation without an actual
65
73
  * hierarchy. A reported container name remains metadata and does not promote
66
- * a flat observation to known nesting.
74
+ * a flat observation to a known level.
67
75
  */
68
76
  export interface DocumentCodeSymbol extends CodeSymbol {
69
- nesting: DeclarationNesting;
77
+ level: DeclarationLevel;
70
78
  }
71
79
 
72
80
  // ── Result types ───────────────────────────────────────────────────────
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrclrchtr/supi-core",
3
- "version": "11.2.0",
3
+ "version": "11.4.0",
4
4
  "description": "Shared settings, configuration, reporting, and session infrastructure",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -0,0 +1,110 @@
1
+ // Session-provided Web tools for SuPi child sessions (Agent Runs and Reviewer Sessions).
2
+ //
3
+ // The loaded supi-web extension answers a synchronous request on the parent event bus.
4
+ // Consumers never depend on supi-web; when it is absent or provides no tools, the
5
+ // request returns undefined and the child simply lacks Web tools.
6
+
7
+ import type { ExtensionAPI, ExtensionFactory } from "@earendil-works/pi-coding-agent";
8
+
9
+ /** Web tools that child sessions may receive when the containing session provides them. */
10
+ export const CHILD_WEB_TOOL_NAMES = [
11
+ "web_fetch_md",
12
+ "web_search",
13
+ "web_docs_search",
14
+ "web_docs_fetch",
15
+ ] as const;
16
+
17
+ /** One session-provided Web tool name. */
18
+ export type ChildWebToolName = (typeof CHILD_WEB_TOOL_NAMES)[number];
19
+
20
+ /**
21
+ * Web tools currently callable in the containing session plus a child-only extension
22
+ * factory that registers them. The factory must not capture the parent session; it may
23
+ * capture plain data such as the containing session's configuration directory.
24
+ */
25
+ export interface ChildWebToolProvision {
26
+ readonly toolNames: readonly ChildWebToolName[];
27
+ /** Register the requested subset of `toolNames` in a child session. */
28
+ readonly createFactory: (toolNames: readonly ChildWebToolName[]) => ExtensionFactory;
29
+ }
30
+
31
+ /** Plain containing-session data supplied with a child Web tool request. */
32
+ export interface ChildWebToolsRequestContext {
33
+ /**
34
+ * Working directory whose SuPi configuration governs Web settings such as Firecrawl.
35
+ * Children with a different cwd (for example a frozen Review Workspace) keep this policy.
36
+ */
37
+ readonly configCwd: string;
38
+ }
39
+
40
+ type EventBusLike = Pick<ExtensionAPI["events"], "on" | "emit">;
41
+
42
+ const REQUEST_CHANNEL = "supi:child-web-tools:request";
43
+ const RESPONSE_CHANNEL = "supi:child-web-tools:response";
44
+
45
+ interface ChildWebToolsRequest extends ChildWebToolsRequestContext {
46
+ readonly requestId: string;
47
+ }
48
+
49
+ interface ChildWebToolsResponse {
50
+ readonly requestId: string;
51
+ readonly provision: ChildWebToolProvision;
52
+ }
53
+
54
+ let nextRequestId = 0;
55
+
56
+ /**
57
+ * Answer child Web tool requests on the parent event bus. The callback must be synchronous
58
+ * because Pi's event bus does not await listeners. Returns an unsubscribe function.
59
+ */
60
+ export function provideChildWebTools(
61
+ events: EventBusLike,
62
+ resolve: (context: ChildWebToolsRequestContext) => ChildWebToolProvision | undefined,
63
+ ): () => void {
64
+ return events.on(REQUEST_CHANNEL, (data) => {
65
+ const request = data as Partial<ChildWebToolsRequest> | undefined;
66
+ if (typeof request?.requestId !== "string" || typeof request.configCwd !== "string") return;
67
+ const { requestId, configCwd } = request;
68
+ const provision = resolve({ configCwd });
69
+ if (!provision || provision.toolNames.length === 0) return;
70
+ events.emit(RESPONSE_CHANNEL, { requestId, provision } satisfies ChildWebToolsResponse);
71
+ });
72
+ }
73
+
74
+ /** Capture the Web tools the containing session currently provides, if any. */
75
+ export function requestChildWebTools(
76
+ events: EventBusLike,
77
+ context: ChildWebToolsRequestContext,
78
+ ): ChildWebToolProvision | undefined {
79
+ const requestId = `child-web-${process.pid}-${++nextRequestId}`;
80
+ let provision: ChildWebToolProvision | undefined;
81
+ const unsubscribe = events.on(RESPONSE_CHANNEL, (data) => {
82
+ const response = data as Partial<ChildWebToolsResponse> | undefined;
83
+ if (response?.requestId === requestId && response.provision) provision = response.provision;
84
+ });
85
+ try {
86
+ events.emit(REQUEST_CHANNEL, { requestId, ...context } satisfies ChildWebToolsRequest);
87
+ } finally {
88
+ unsubscribe();
89
+ }
90
+ return provision;
91
+ }
92
+
93
+ /**
94
+ * Return the Web tools callable in a session under Pi's exposure rules: active `direct`
95
+ * tools, plus registered `codemode` and `deferred` tools. `model-only` and `hidden`
96
+ * tools are not callable.
97
+ */
98
+ export function callableChildWebToolNames(
99
+ pi: Pick<ExtensionAPI, "getAllTools" | "getActiveTools">,
100
+ ): ChildWebToolName[] {
101
+ const active = new Set(pi.getActiveTools());
102
+ const exposures = new Map(
103
+ pi.getAllTools().map((tool) => [tool.name, tool.exposure ?? "direct"] as const),
104
+ );
105
+ return CHILD_WEB_TOOL_NAMES.filter((name) => {
106
+ const exposure = exposures.get(name);
107
+ if (exposure === "direct") return active.has(name);
108
+ return exposure === "codemode" || exposure === "deferred";
109
+ });
110
+ }
@@ -1,5 +1,16 @@
1
1
  // supi-core session domain — session utilities and registries.
2
2
 
3
+ export type {
4
+ ChildWebToolName,
5
+ ChildWebToolProvision,
6
+ ChildWebToolsRequestContext,
7
+ } from "./child-web-tools.ts";
8
+ export {
9
+ CHILD_WEB_TOOL_NAMES,
10
+ callableChildWebToolNames,
11
+ provideChildWebTools,
12
+ requestChildWebTools,
13
+ } from "./child-web-tools.ts";
3
14
  export { createRegistry, createSessionStateRegistry } from "./registry-utils.ts";
4
15
  export type {
5
16
  SessionCapabilitySkill,
@@ -119,7 +119,7 @@ class Range {
119
119
  debug('hyphen replace', range)
120
120
 
121
121
  // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
122
- range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace)
122
+ range = trimComparatorWhitespace(range)
123
123
  debug('comparator trim', range)
124
124
 
125
125
  // `~ 1.2.3` => `~1.2.3`
@@ -224,11 +224,11 @@ const parseOptions = require('../internal/parse-options')
224
224
  const Comparator = require('./comparator')
225
225
  const debug = require('../internal/debug')
226
226
  const SemVer = require('./semver')
227
+ const trimComparatorWhitespace = require('../internal/trim-comparator-whitespace')
227
228
  const {
228
229
  safeRe: re,
229
230
  src,
230
231
  t,
231
- comparatorTrimReplace,
232
232
  tildeTrimReplace,
233
233
  caretTrimReplace,
234
234
  } = require('../internal/re')
@@ -15,6 +15,35 @@ const MAX_SAFE_COMPONENT_LENGTH = 16
15
15
  // the shortest version with a build 0.0.0+BUILD.
16
16
  const MAX_SAFE_BUILD_LENGTH = MAX_LENGTH - 6
17
17
 
18
+ // ECMAScript whitespace and line terminators matched by \s.
19
+ const WHITESPACE_CHARACTERS = [
20
+ '\t',
21
+ '\n',
22
+ '\v',
23
+ '\f',
24
+ '\r',
25
+ ' ',
26
+ '\u00a0',
27
+ '\u1680',
28
+ '\u2000',
29
+ '\u2001',
30
+ '\u2002',
31
+ '\u2003',
32
+ '\u2004',
33
+ '\u2005',
34
+ '\u2006',
35
+ '\u2007',
36
+ '\u2008',
37
+ '\u2009',
38
+ '\u200a',
39
+ '\u2028',
40
+ '\u2029',
41
+ '\u202f',
42
+ '\u205f',
43
+ '\u3000',
44
+ '\ufeff',
45
+ ]
46
+
18
47
  const RELEASE_TYPES = [
19
48
  'major',
20
49
  'premajor',
@@ -30,6 +59,7 @@ module.exports = {
30
59
  MAX_SAFE_COMPONENT_LENGTH,
31
60
  MAX_SAFE_BUILD_LENGTH,
32
61
  MAX_SAFE_INTEGER,
62
+ WHITESPACE_CHARACTERS,
33
63
  RELEASE_TYPES,
34
64
  SEMVER_SPEC_VERSION,
35
65
  FLAG_INCLUDE_PRERELEASE: 0b001,
@@ -0,0 +1,438 @@
1
+ // @ts-check
2
+ 'use strict'
3
+
4
+ // Reproduce safeRe[COMPARATORTRIM] replacement boundaries, not version
5
+ // validation. Each end-index finder returns an exclusive end, or its start
6
+ // on no match.
7
+ // Positions count from zero. An end of 3 means characters 0, 1, and 2 were read;
8
+ // range.slice(start, end) gives the matched text, not a converted number.
9
+ const {
10
+ MAX_LENGTH,
11
+ MAX_SAFE_BUILD_LENGTH,
12
+ WHITESPACE_CHARACTERS,
13
+ } = require('./constants')
14
+
15
+ /**
16
+ * Remembers the last two rows of digits so their characters need not be reread.
17
+ * Positions start at -1 until a row has been found.
18
+ *
19
+ * @typedef {object} DigitRunCache
20
+ * @property {number} start The first character of the most recently found row.
21
+ * @property {number} end The position after that row's last character.
22
+ * @property {number} previousStart The first character of the previous row.
23
+ * @property {number} previousEnd The position after the previous row.
24
+ */
25
+
26
+ // One entry per UTF-16 code unit keeps membership checks constant-time.
27
+ const whitespace = new Uint8Array(0x10000)
28
+ for (const char of WHITESPACE_CHARACTERS) {
29
+ whitespace[char.charCodeAt(0)] = 1
30
+ }
31
+
32
+ /**
33
+ * Checks whether a character is whitespace, like a space, tab, or newline.
34
+ * Looking past the end of the string returns false.
35
+ *
36
+ * @param {string|undefined} char One character, or undefined past the string's end.
37
+ * @returns {boolean} Whether the character is whitespace.
38
+ * @example isWhitespace(' ') // true
39
+ * @example isWhitespace('1') // false
40
+ */
41
+ const isWhitespace = char =>
42
+ char !== undefined && whitespace[char.charCodeAt(0)] === 1
43
+
44
+ /**
45
+ * Checks for v, =, or whitespace before the version number.
46
+ * These are historical version prefixes, not range operators:
47
+ * < and > are handled separately, as are tilde and caret ranges.
48
+ *
49
+ * @param {string|undefined} char One character to check.
50
+ * @returns {boolean} Whether the character can belong to a version prefix.
51
+ * @example isVersionPrefix('=') // true
52
+ * @example isVersionPrefix('>') // false
53
+ */
54
+ const isVersionPrefix = char =>
55
+ char === 'v' ||
56
+ char === '=' ||
57
+ isWhitespace(char)
58
+
59
+ /**
60
+ * Checks whether a character is one of the digits 0 through 9.
61
+ *
62
+ * @param {string|undefined} char One character to check.
63
+ * @returns {boolean} Whether the character is an ASCII digit.
64
+ * @example isDigit('7') // true
65
+ * @example isDigit('.') // false
66
+ */
67
+ const isDigit = char => char !== undefined && char >= '0' && char <= '9'
68
+
69
+ /**
70
+ * Checks whether a character is an English letter, uppercase or lowercase.
71
+ *
72
+ * @param {string|undefined} char One character to check.
73
+ * @returns {boolean} Whether the character is an ASCII letter.
74
+ * @example isLetter('b') // true
75
+ * @example isLetter('7') // false
76
+ */
77
+ const isLetter = char =>
78
+ char !== undefined && (
79
+ (char >= 'a' && char <= 'z') ||
80
+ (char >= 'A' && char <= 'Z')
81
+ )
82
+
83
+ /**
84
+ * Checks for a letter, digit, or hyphen: the characters allowed inside
85
+ * prerelease and build names such as beta-1.
86
+ *
87
+ * @param {string|undefined} char One character to check.
88
+ * @returns {boolean} Whether the character can be part of an identifier.
89
+ * @example isIdentifierCharacter('-') // true
90
+ * @example isIdentifierCharacter('.') // false; dots separate identifiers
91
+ */
92
+ const isIdentifierCharacter = char => isDigit(char) || isLetter(char) || char === '-'
93
+
94
+ /**
95
+ * Checks whether a version component can begin here: with a digit or
96
+ * a wildcard such as x, X, or *.
97
+ *
98
+ * @param {string|undefined} char One character to check.
99
+ * @returns {boolean} Whether a number or wildcard can start with this character.
100
+ * @example isVersionStart('x') // true
101
+ * @example isVersionStart('v') // false; v belongs to the prefix
102
+ */
103
+ const isVersionStart = char =>
104
+ isDigit(char) ||
105
+ char === 'x' ||
106
+ char === 'X' ||
107
+ char === '*'
108
+
109
+ /**
110
+ * Finds the end of a row of digits, but returns no more than limit digits.
111
+ * Remembers the last two rows so looking at them again does not reread them.
112
+ *
113
+ * @param {string} range The text to read; it is not changed.
114
+ * @param {number} start The position of the first character to check.
115
+ * @param {number} limit The most digit characters the returned match can include.
116
+ * @param {DigitRunCache} digitRuns Shared cache of digit-run positions, updated in place.
117
+ * @returns {number} The position after the matched digits, or start if none match.
118
+ * @example findDigitsEndIndex('123abc', 0, 10, digitRuns) // 3, pointing at a
119
+ * @example findDigitsEndIndex('123abc', 0, 2, digitRuns) // 2, pointing at the unread 3
120
+ */
121
+ const findDigitsEndIndex = (range, start, limit, digitRuns) => {
122
+ if (!isDigit(range[start])) {
123
+ return start
124
+ }
125
+ if (start >= digitRuns.start && start < digitRuns.end) {
126
+ return Math.min(start + limit, digitRuns.end)
127
+ }
128
+ if (start >= digitRuns.previousStart && start < digitRuns.previousEnd) {
129
+ return Math.min(start + limit, digitRuns.previousEnd)
130
+ }
131
+ let end = start + 1
132
+ while (isDigit(range[end])) {
133
+ end++
134
+ }
135
+ // A failed full version can rewind from its second run to its first.
136
+ digitRuns.previousStart = digitRuns.start
137
+ digitRuns.previousEnd = digitRuns.end
138
+ digitRuns.start = start
139
+ digitRuns.end = end
140
+ return Math.min(start + limit, end)
141
+ }
142
+
143
+ /**
144
+ * Reads a number using the old regex's length and leading-zero rules.
145
+ * Strict mode reads just the first zero in 012; loose mode can read all three.
146
+ *
147
+ * @param {string} range The text to read; it is not changed.
148
+ * @param {number} start The position where the number should begin.
149
+ * @param {boolean} loose Whether to allow leading zeros.
150
+ * @param {DigitRunCache} digitRuns Shared digit-run cache, updated as needed.
151
+ * @returns {number} The position after the matched digits, not their numeric value.
152
+ * @example findVersionNumberEndIndex('012', 0, false, digitRuns) // 1
153
+ * @example findVersionNumberEndIndex('012', 0, true, digitRuns) // 3
154
+ */
155
+ const findVersionNumberEndIndex = (range, start, loose, digitRuns) => {
156
+ if (!loose && range[start] === '0') {
157
+ return start + 1
158
+ }
159
+ // Strict syntax allows an initial nonzero digit plus MAX_LENGTH digits.
160
+ return findDigitsEndIndex(range, start, loose ? MAX_LENGTH : MAX_LENGTH + 1, digitRuns)
161
+ }
162
+
163
+ /**
164
+ * Reads one piece of a prerelease name, such as beta or 1 in beta.1.
165
+ * Tries the letter-or-hyphen form first, then the number-only form.
166
+ *
167
+ * @param {string} range The text to read; it is not changed.
168
+ * @param {number} start The position where the identifier should begin.
169
+ * @param {boolean} loose Whether numeric identifiers may have leading zeros.
170
+ * @param {DigitRunCache} digitRuns Shared digit-run cache, updated as needed.
171
+ * @returns {number} The position after the identifier, or start if none matches.
172
+ * @example findPrereleaseIdentifierEndIndex('beta.1', 0, false, digitRuns) // 4, at the dot
173
+ * @example findPrereleaseIdentifierEndIndex('001beta', 0, false, digitRuns) // 7
174
+ */
175
+ const findPrereleaseIdentifierEndIndex = (range, start, loose, digitRuns) => {
176
+ const digitsEnd = findDigitsEndIndex(range, start, MAX_LENGTH, digitRuns)
177
+ // The legacy regex tries a nonnumeric identifier before a numeric one.
178
+ if (isLetter(range[digitsEnd]) || range[digitsEnd] === '-') {
179
+ let end = digitsEnd + 1
180
+ const limit = end + MAX_SAFE_BUILD_LENGTH
181
+ while (end < limit && isIdentifierCharacter(range[end])) {
182
+ end++
183
+ }
184
+ return end
185
+ }
186
+ return findVersionNumberEndIndex(range, start, loose, digitRuns)
187
+ }
188
+
189
+ /**
190
+ * Reads a prerelease suffix such as -beta.1, one dot-separated piece at a time.
191
+ * Loose mode also allows the name without its opening hyphen.
192
+ *
193
+ * @param {string} range The text to read; it is not changed.
194
+ * @param {number} start The position where the suffix should begin, including -.
195
+ * @param {boolean} loose Whether the opening hyphen is optional and zeros allowed.
196
+ * @param {DigitRunCache} digitRuns Shared digit-run cache, updated as needed.
197
+ * @returns {number} The position after the matched suffix, or start if absent.
198
+ * @example findPrereleaseEndIndex('-beta.1+sha', 0, false, digitRuns) // 7, at the plus
199
+ * @example findPrereleaseEndIndex('beta', 0, false, digitRuns) // 0; no opening hyphen
200
+ */
201
+ const findPrereleaseEndIndex = (range, start, loose, digitRuns) => {
202
+ const hyphen = range[start] === '-'
203
+ if (!loose && !hyphen) {
204
+ return start
205
+ }
206
+ const identifierStart = start + (hyphen ? 1 : 0)
207
+ let end = findPrereleaseIdentifierEndIndex(range, identifierStart, loose, digitRuns)
208
+ if (end === identifierStart) {
209
+ if (!loose || !hyphen) {
210
+ return start
211
+ }
212
+ // In loose syntax, a lone hyphen can itself be the identifier.
213
+ end = findPrereleaseIdentifierEndIndex(range, start, loose, digitRuns)
214
+ }
215
+ while (range[end] === '.') {
216
+ const next = findPrereleaseIdentifierEndIndex(range, end + 1, loose, digitRuns)
217
+ if (next === end + 1) {
218
+ break
219
+ }
220
+ end = next
221
+ }
222
+ return end
223
+ }
224
+
225
+ /**
226
+ * Reads one build-name piece, such as sha or 123 in +sha.123.
227
+ * Stops at a disallowed character or the old regex's length limit.
228
+ *
229
+ * @param {string} range The text to read; it is not changed.
230
+ * @param {number} start The position where the identifier should begin.
231
+ * @returns {number} The position after the identifier, or start if none matches.
232
+ * @example findBuildIdentifierEndIndex('sha.123', 0) // 3, at the dot
233
+ * @example findBuildIdentifierEndIndex('001', 0) // 3; leading zeros are allowed
234
+ */
235
+ const findBuildIdentifierEndIndex = (range, start) => {
236
+ let end = start
237
+ while (end - start < MAX_SAFE_BUILD_LENGTH && isIdentifierCharacter(range[end])) {
238
+ end++
239
+ }
240
+ return end
241
+ }
242
+
243
+ /**
244
+ * Reads optional build metadata such as +sha.123.
245
+ * Leaves the position unchanged if there is no plus sign followed by a name.
246
+ *
247
+ * @param {string} range The text to read; it is not changed.
248
+ * @param {number} start The position where the opening + should be.
249
+ * @returns {number} The position after the matched metadata, or start if absent.
250
+ * @example findBuildEndIndex('+sha.123 <2', 0) // 8, at the space
251
+ * @example findBuildEndIndex('+', 0) // 0; a plus sign alone is not a match
252
+ */
253
+ const findBuildEndIndex = (range, start) => {
254
+ if (range[start] !== '+') {
255
+ return start
256
+ }
257
+ let end = findBuildIdentifierEndIndex(range, start + 1)
258
+ if (end === start + 1) {
259
+ return start
260
+ }
261
+ while (range[end] === '.') {
262
+ const next = findBuildIdentifierEndIndex(range, end + 1)
263
+ if (next === end + 1) {
264
+ break
265
+ }
266
+ end = next
267
+ }
268
+ return end
269
+ }
270
+
271
+ /**
272
+ * Reads three numbers separated by dots, then any prerelease and build suffixes.
273
+ * Uses loose rules, so forms such as 01.02.03beta can match here.
274
+ *
275
+ * @param {string} range The text to read; it is not changed.
276
+ * @param {number} start The position of the first number, after any prefix.
277
+ * @param {DigitRunCache} digitRuns Shared digit-run cache, updated as needed.
278
+ * @returns {number} The position after the version match, or start if none matches.
279
+ * @example findLooseFullVersionEndIndex('1.2.3-beta+sha <2', 0, digitRuns) // 14
280
+ * @example findLooseFullVersionEndIndex('1.2', 0, digitRuns) // 0; needs three numbers
281
+ */
282
+ const findLooseFullVersionEndIndex = (range, start, digitRuns) => {
283
+ let end = start
284
+ for (let component = 0; component < 3; component++) {
285
+ const next = findVersionNumberEndIndex(range, end, true, digitRuns)
286
+ if (next === end) {
287
+ return start
288
+ }
289
+ end = next
290
+ if (component < 2) {
291
+ if (range[end] !== '.') {
292
+ return start
293
+ }
294
+ end++
295
+ }
296
+ }
297
+ const prereleaseEnd = findPrereleaseEndIndex(range, end, true, digitRuns)
298
+ return findBuildEndIndex(range, prereleaseEnd)
299
+ }
300
+
301
+ /**
302
+ * Reads one component of a partial or wildcard version, such as 2 or x in 2.x.
303
+ * Numbers use strict leading-zero rules; wildcards take up one character.
304
+ *
305
+ * @param {string} range The text to read; it is not changed.
306
+ * @param {number} start The position where the component should begin.
307
+ * @param {DigitRunCache} digitRuns Shared digit-run cache, updated as needed.
308
+ * @returns {number} The position after the component, or start if none matches.
309
+ * @example findPartialVersionComponentEndIndex('2.x', 0, digitRuns) // 1, at the dot
310
+ * @example findPartialVersionComponentEndIndex('2.x', 2, digitRuns) // 3, after x
311
+ */
312
+ const findPartialVersionComponentEndIndex = (range, start, digitRuns) => {
313
+ if (isDigit(range[start])) {
314
+ return findVersionNumberEndIndex(range, start, false, digitRuns)
315
+ }
316
+ return isVersionStart(range[start]) ? start + 1 : start
317
+ }
318
+
319
+ /**
320
+ * Reads up to three components, allowing forms such as 1, 1.2, or 1.x.
321
+ * After the third component, also reads any strict prerelease and build suffixes.
322
+ *
323
+ * @param {string} range The text to read; it is not changed.
324
+ * @param {number} start The position of a number or wildcard, after any prefix.
325
+ * @param {DigitRunCache} digitRuns Shared digit-run cache, updated as needed.
326
+ * @returns {number} The position after the matched version text.
327
+ * @example findPartialVersionEndIndex('1.x <2', 0, digitRuns) // 3, at the space
328
+ * @example findPartialVersionEndIndex('1.', 0, digitRuns) // 1; the trailing dot is unread
329
+ */
330
+ const findPartialVersionEndIndex = (range, start, digitRuns) => {
331
+ let end = findPartialVersionComponentEndIndex(range, start, digitRuns)
332
+ for (let component = 0; component < 2; component++) {
333
+ if (range[end] !== '.') {
334
+ return end
335
+ }
336
+ const next = findPartialVersionComponentEndIndex(range, end + 1, digitRuns)
337
+ if (next === end + 1) {
338
+ return end
339
+ }
340
+ end = next
341
+ }
342
+ const prereleaseEnd = findPrereleaseEndIndex(range, end, false, digitRuns)
343
+ return findBuildEndIndex(range, prereleaseEnd)
344
+ }
345
+
346
+ /**
347
+ * Finds where a version match ends, without deciding whether the range is valid.
348
+ * Tries a loose full version first, then a partial or wildcard version, just
349
+ * like the old regex's LOOSEPLAIN and XRANGEPLAIN alternatives.
350
+ *
351
+ * @param {string} range The text to read; it is not changed.
352
+ * @param {number} start The position of a number or wildcard, after any prefix.
353
+ * @param {DigitRunCache} digitRuns Shared digit-run cache, updated as needed.
354
+ * @returns {number} The position where scanning the next candidate can resume.
355
+ * @example findVersionEndIndex('1.2.3 <2', 0, digitRuns) // 5, at the space
356
+ * @example findVersionEndIndex('1.x <2', 0, digitRuns) // 3, at the space
357
+ */
358
+ const findVersionEndIndex = (range, start, digitRuns) => {
359
+ const fullVersionEnd = findLooseFullVersionEndIndex(range, start, digitRuns)
360
+ return fullVersionEnd !== start
361
+ ? fullVersionEnd
362
+ : findPartialVersionEndIndex(range, start, digitRuns)
363
+ }
364
+
365
+ /**
366
+ * Finds the one whitespace character the old replacement would remove.
367
+ * Keeps leading whitespace, skips an optional operator, and checks immediately
368
+ * after it. Returns -1 if there is nothing to remove.
369
+ *
370
+ * @param {string} range The text containing a candidate already found by the caller.
371
+ * @param {number} matchStart The candidate's position, including leading whitespace.
372
+ * @returns {number} The position of the removable whitespace, or -1 if absent.
373
+ * @example findRemovableWhitespaceIndex(' > 1', 0) // 2; keep the space at position 0
374
+ * @example findRemovableWhitespaceIndex('>1', 0) // -1
375
+ */
376
+ const findRemovableWhitespaceIndex = (range, matchStart) => {
377
+ let position = matchStart
378
+ if (isWhitespace(range[position])) {
379
+ position++
380
+ }
381
+ if (range[position] === '<' || range[position] === '>') {
382
+ position++
383
+ }
384
+ if (range[position] === '=') {
385
+ position++
386
+ }
387
+ return isWhitespace(range[position]) ? position : -1
388
+ }
389
+
390
+ /**
391
+ * Joins an operator to its version, turning > 1.2.3 into >1.2.3.
392
+ * Copies everything else according to the old regex's matching rules.
393
+ * Moves forward through prefixes and whole versions to avoid repeatedly
394
+ * searching the same characters on long inputs.
395
+ *
396
+ * @param {string} range The range text to process; the original string is unchanged.
397
+ * @returns {string} The range with matched operator whitespace removed.
398
+ * @example trimComparatorWhitespace('> 1.2.3 < 2') // '>1.2.3 <2'
399
+ * @example trimComparatorWhitespace('> invalid') // '> invalid'
400
+ */
401
+ const trimComparatorWhitespace = range => {
402
+ let result = ''
403
+ let copyFrom = 0
404
+ let cursor = 0
405
+ const digitRuns = { start: -1, end: -1, previousStart: -1, previousEnd: -1 }
406
+
407
+ while (cursor < range.length) {
408
+ const matchStart = cursor
409
+ if (range[cursor] === '<' || range[cursor] === '>') {
410
+ cursor++
411
+ } else if (!isVersionPrefix(range[cursor]) && !isVersionStart(range[cursor])) {
412
+ cursor++
413
+ continue
414
+ }
415
+
416
+ // Consume a v/=/whitespace run once, even when no version follows it.
417
+ while (cursor < range.length && isVersionPrefix(range[cursor])) {
418
+ cursor++
419
+ }
420
+ if (!isVersionStart(range[cursor])) {
421
+ continue
422
+ }
423
+
424
+ const whitespacePosition = findRemovableWhitespaceIndex(range, matchStart)
425
+ if (whitespacePosition !== -1) {
426
+ result += range.slice(copyFrom, whitespacePosition)
427
+ copyFrom = whitespacePosition + 1
428
+ }
429
+
430
+ // Skip the entire match, so a prerelease's trailing v cannot be
431
+ // reconsidered as the prefix of another version.
432
+ cursor = findVersionEndIndex(range, cursor, digitRuns)
433
+ }
434
+
435
+ return result + range.slice(copyFrom)
436
+ }
437
+
438
+ module.exports = trimComparatorWhitespace
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semver",
3
- "version": "7.8.5",
3
+ "version": "7.8.6",
4
4
  "description": "The semantic version parser used by npm.",
5
5
  "main": "index.js",
6
6
  "scripts": {