@cortexkit/opencode-magic-context 0.41.2 → 0.41.4

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 (230) hide show
  1. package/README.md +9 -3
  2. package/dist/announcement-3c1vertn.js +14 -0
  3. package/dist/config/index.d.ts +9 -0
  4. package/dist/config/index.d.ts.map +1 -1
  5. package/dist/config/project-security.d.ts.map +1 -1
  6. package/dist/config/schema/magic-context.d.ts +756 -4
  7. package/dist/config/schema/magic-context.d.ts.map +1 -1
  8. package/dist/conflict-warning-hook-ejkc9sjn.js +16 -0
  9. package/dist/derive-budgets-bc366cz8.js +13 -0
  10. package/dist/features/magic-context/compartment-lease.d.ts +6 -0
  11. package/dist/features/magic-context/compartment-lease.d.ts.map +1 -1
  12. package/dist/features/magic-context/dreamer/classify.d.ts.map +1 -1
  13. package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts +13 -0
  14. package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts.map +1 -1
  15. package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
  16. package/dist/features/magic-context/dreamer/task-scheduler.d.ts +3 -0
  17. package/dist/features/magic-context/dreamer/task-scheduler.d.ts.map +1 -1
  18. package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
  19. package/dist/features/magic-context/migrations.d.ts.map +1 -1
  20. package/dist/features/magic-context/storage-db.d.ts +18 -1
  21. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  22. package/dist/features/magic-context/storage-meta-persisted.d.ts +13 -14
  23. package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
  24. package/dist/features/magic-context/storage-meta.d.ts +1 -1
  25. package/dist/features/magic-context/storage-meta.d.ts.map +1 -1
  26. package/dist/features/magic-context/storage-subagent-invocations.d.ts +3 -2
  27. package/dist/features/magic-context/storage-subagent-invocations.d.ts.map +1 -1
  28. package/dist/features/magic-context/storage-tags.d.ts +6 -0
  29. package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
  30. package/dist/features/magic-context/storage.d.ts +2 -2
  31. package/dist/features/magic-context/storage.d.ts.map +1 -1
  32. package/dist/features/magic-context/subagent-token-capture.d.ts +2 -1
  33. package/dist/features/magic-context/subagent-token-capture.d.ts.map +1 -1
  34. package/dist/hooks/magic-context/command-handler.d.ts +5 -1
  35. package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
  36. package/dist/hooks/magic-context/compaction-marker-manager.d.ts +6 -1
  37. package/dist/hooks/magic-context/compaction-marker-manager.d.ts.map +1 -1
  38. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
  39. package/dist/hooks/magic-context/compartment-runner-types.d.ts +4 -0
  40. package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
  41. package/dist/hooks/magic-context/compartment-runner.d.ts +2 -1
  42. package/dist/hooks/magic-context/compartment-runner.d.ts.map +1 -1
  43. package/dist/hooks/magic-context/derive-budgets.d.ts +1 -0
  44. package/dist/hooks/magic-context/derive-budgets.d.ts.map +1 -1
  45. package/dist/hooks/magic-context/emergency-drop.d.ts +3 -1
  46. package/dist/hooks/magic-context/emergency-drop.d.ts.map +1 -1
  47. package/dist/hooks/magic-context/execute-status.d.ts +7 -1
  48. package/dist/hooks/magic-context/execute-status.d.ts.map +1 -1
  49. package/dist/hooks/magic-context/heuristic-cleanup.d.ts +4 -3
  50. package/dist/hooks/magic-context/heuristic-cleanup.d.ts.map +1 -1
  51. package/dist/hooks/magic-context/hook-handlers.d.ts +2 -0
  52. package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
  53. package/dist/hooks/magic-context/hook.d.ts +9 -5
  54. package/dist/hooks/magic-context/hook.d.ts.map +1 -1
  55. package/dist/hooks/magic-context/inject-compartments.d.ts +6 -0
  56. package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
  57. package/dist/hooks/magic-context/issue-423-fixture.d.ts +37 -0
  58. package/dist/hooks/magic-context/issue-423-fixture.d.ts.map +1 -0
  59. package/dist/hooks/magic-context/issue-424-fixture.d.ts +11 -0
  60. package/dist/hooks/magic-context/issue-424-fixture.d.ts.map +1 -0
  61. package/dist/hooks/magic-context/module-state-sync.d.ts +2 -1
  62. package/dist/hooks/magic-context/module-state-sync.d.ts.map +1 -1
  63. package/dist/hooks/magic-context/module-transport.d.ts +11 -4
  64. package/dist/hooks/magic-context/module-transport.d.ts.map +1 -1
  65. package/dist/hooks/magic-context/module-wire.d.ts +6 -1
  66. package/dist/hooks/magic-context/module-wire.d.ts.map +1 -1
  67. package/dist/hooks/magic-context/producer-window-guard.d.ts +8 -0
  68. package/dist/hooks/magic-context/producer-window-guard.d.ts.map +1 -0
  69. package/dist/hooks/magic-context/protected-tail-boundary.d.ts +59 -0
  70. package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
  71. package/dist/hooks/magic-context/read-session-chunk.d.ts +2 -0
  72. package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
  73. package/dist/hooks/magic-context/read-session-db.d.ts +15 -0
  74. package/dist/hooks/magic-context/read-session-db.d.ts.map +1 -1
  75. package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts +4 -1
  76. package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts.map +1 -1
  77. package/dist/hooks/magic-context/recomp-orchestrator.d.ts +2 -0
  78. package/dist/hooks/magic-context/recomp-orchestrator.d.ts.map +1 -1
  79. package/dist/hooks/magic-context/rust-mode-transform.d.ts +15 -2
  80. package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
  81. package/dist/hooks/magic-context/send-session-notification.d.ts +6 -0
  82. package/dist/hooks/magic-context/send-session-notification.d.ts.map +1 -1
  83. package/dist/hooks/magic-context/sentinel.d.ts +8 -19
  84. package/dist/hooks/magic-context/sentinel.d.ts.map +1 -1
  85. package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
  86. package/dist/hooks/magic-context/tag-messages.d.ts +2 -0
  87. package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
  88. package/dist/hooks/magic-context/tail-hygiene-walk.d.ts +8 -3
  89. package/dist/hooks/magic-context/tail-hygiene-walk.d.ts.map +1 -1
  90. package/dist/hooks/magic-context/tool-drop-target.d.ts +1 -0
  91. package/dist/hooks/magic-context/tool-drop-target.d.ts.map +1 -1
  92. package/dist/hooks/magic-context/transform-compartment-phase.d.ts +2 -0
  93. package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
  94. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +32 -0
  95. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  96. package/dist/hooks/magic-context/transform.d.ts +4 -0
  97. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  98. package/dist/hooks/magic-context/wrapup-orchestrator.d.ts.map +1 -1
  99. package/dist/{index-j8r0ejb3.js → index-0y2mcg5y.js} +1971 -11203
  100. package/dist/{index-1yh8g550.js → index-22jkk6wg.js} +2 -15
  101. package/dist/{index-dmvy29z0.js → index-3wzdwt6p.js} +11 -15
  102. package/dist/{index-eq9wr75c.js → index-4avmwfp5.js} +57 -108
  103. package/dist/{index-d1mxrd3p.js → index-7k55qm8a.js} +17 -12
  104. package/dist/{index-2wchnyk6.js → index-avwt563y.js} +8 -1
  105. package/dist/{index-4x691bz5.js → index-dkv2dn46.js} +5 -2
  106. package/dist/{index-rgdqj8nj.js → index-e7vx3byk.js} +1 -1
  107. package/dist/{index-szf8w1p5.js → index-fmsr7v69.js} +2 -2
  108. package/dist/{index-y1yr57fw.js → index-fz104x1j.js} +18 -18
  109. package/dist/{index-d62ypazr.js → index-jdxxq8cz.js} +6 -11
  110. package/dist/{index-9j3tx8hy.js → index-may8skc8.js} +6 -25
  111. package/dist/{index-cvda5jb3.js → index-mjv9je4e.js} +23 -19
  112. package/dist/{index-zwjhba2r.js → index-q264erdp.js} +122 -41
  113. package/dist/{index-b9j85d29.js → index-raatkvw5.js} +49 -11
  114. package/dist/{index-9xexf8s7.js → index-rn7gafjr.js} +1 -9
  115. package/dist/index-sd3egckz.js +1583 -0
  116. package/dist/index-v6t0tg85.js +13 -0
  117. package/dist/index.d.ts.map +1 -1
  118. package/dist/index.js +2660 -3255
  119. package/dist/model-resolution-dxatzjde.js +12 -0
  120. package/dist/{index-dynqfgx1.js → module-asyncify-2EFITU5U-rkqjhjxd.js} +69 -8
  121. package/dist/plugin/boot-deadline.d.ts +47 -0
  122. package/dist/plugin/boot-deadline.d.ts.map +1 -0
  123. package/dist/plugin/conflict-warning-hook.d.ts +10 -0
  124. package/dist/plugin/conflict-warning-hook.d.ts.map +1 -1
  125. package/dist/plugin/hooks/create-session-hooks.d.ts +5 -0
  126. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  127. package/dist/plugin/messages-transform.d.ts.map +1 -1
  128. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  129. package/dist/prompt-context-5y5ms8f9.js +6 -0
  130. package/dist/recomp-orchestrator-q98r6rga.js +19 -0
  131. package/dist/rpc-notifications-4amf6mf4.js +14 -0
  132. package/dist/{index-vnz6jvdc.js → safe-notification-target-q9z81zt3.js} +4 -3
  133. package/dist/send-session-notification-hdh02wy9.js +16 -0
  134. package/dist/shared/cache-ttl-display.d.ts +23 -0
  135. package/dist/shared/cache-ttl-display.d.ts.map +1 -0
  136. package/dist/shared/cache-ttl-seed.d.ts +10 -0
  137. package/dist/shared/cache-ttl-seed.d.ts.map +1 -0
  138. package/dist/shared/config-diagnostics.d.ts +30 -0
  139. package/dist/shared/config-diagnostics.d.ts.map +1 -0
  140. package/dist/shared/config-warning-surface.d.ts +3 -0
  141. package/dist/shared/config-warning-surface.d.ts.map +1 -0
  142. package/dist/shared/conflict-detector.d.ts +3 -1
  143. package/dist/shared/conflict-detector.d.ts.map +1 -1
  144. package/dist/shared/data-path.d.ts +10 -9
  145. package/dist/shared/data-path.d.ts.map +1 -1
  146. package/dist/shared/harness-provider-map.d.ts +7 -0
  147. package/dist/shared/harness-provider-map.d.ts.map +1 -1
  148. package/dist/shared/harness.d.ts +3 -3
  149. package/dist/shared/harness.d.ts.map +1 -1
  150. package/dist/shared/jsonc-parser.d.ts +12 -0
  151. package/dist/shared/jsonc-parser.d.ts.map +1 -1
  152. package/dist/shared/model-resolution.d.ts +3 -3
  153. package/dist/shared/model-resolution.d.ts.map +1 -1
  154. package/dist/shared/model-suggestion-retry.d.ts +14 -10
  155. package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
  156. package/dist/shared/pi-executable.d.ts +6 -0
  157. package/dist/shared/pi-executable.d.ts.map +1 -0
  158. package/dist/shared/prompt-surface-runtime.d.ts +2 -2
  159. package/dist/shared/prompt-surface-runtime.d.ts.map +1 -1
  160. package/dist/shared/rpc-types.d.ts +6 -0
  161. package/dist/shared/rpc-types.d.ts.map +1 -1
  162. package/dist/shared/rpc-utils.d.ts.map +1 -1
  163. package/dist/shared/status-detail-text.d.ts.map +1 -1
  164. package/dist/shared/tag-transcript.d.ts.map +1 -1
  165. package/dist/shared/transcript.d.ts +2 -1
  166. package/dist/shared/transcript.d.ts.map +1 -1
  167. package/dist/storage-meta-session-dvwfw778.js +20 -0
  168. package/dist/task-config-hnv93r7p.js +9 -0
  169. package/dist/transformers-node-wasm.js +328 -328
  170. package/dist/transformers-web.js +72 -72
  171. package/dist/{transformers.node-b1wa0hgx.js → transformers.node-dpmf3wpx.js} +74 -74
  172. package/package.json +1 -1
  173. package/src/config/index.test.ts +72 -0
  174. package/src/config/index.ts +96 -15
  175. package/src/config/project-security.hostile-matrix.test.ts +78 -9
  176. package/src/config/project-security.ts +4 -3
  177. package/src/config/schema/magic-context.test.ts +64 -0
  178. package/src/config/schema/magic-context.ts +100 -6
  179. package/src/shared/cache-ttl-display.test.ts +84 -0
  180. package/src/shared/cache-ttl-display.ts +64 -0
  181. package/src/shared/cache-ttl-seed.ts +23 -0
  182. package/src/shared/config-diagnostics.test.ts +29 -0
  183. package/src/shared/config-diagnostics.ts +64 -0
  184. package/src/shared/config-warning-surface.ts +28 -0
  185. package/src/shared/conflict-detector.test.ts +24 -0
  186. package/src/shared/conflict-detector.ts +25 -7
  187. package/src/shared/data-path.ts +10 -9
  188. package/src/shared/harness-provider-map.test.ts +16 -0
  189. package/src/shared/harness-provider-map.ts +15 -0
  190. package/src/shared/harness.ts +3 -3
  191. package/src/shared/jsonc-parser.test.ts +14 -1
  192. package/src/shared/jsonc-parser.ts +93 -0
  193. package/src/shared/model-resolution.test.ts +61 -0
  194. package/src/shared/model-resolution.ts +14 -5
  195. package/src/shared/model-suggestion-retry.ts +143 -28
  196. package/src/shared/pi-executable.ts +20 -0
  197. package/src/shared/prompt-surface-runtime.ts +3 -3
  198. package/src/shared/rpc-types.ts +6 -0
  199. package/src/shared/rpc-utils.ts +2 -3
  200. package/src/shared/status-detail-text.test.ts +2 -1
  201. package/src/shared/status-detail-text.ts +5 -1
  202. package/src/shared/tag-transcript.ts +32 -2
  203. package/src/shared/transcript.ts +3 -1
  204. package/src/tui/index.tsx +15 -1
  205. package/src/tui-compiled/index.tsx +234 -222
  206. package/dist/announcement-3g9xg433.js +0 -18
  207. package/dist/conflict-warning-hook-rf17b6et.js +0 -17
  208. package/dist/derive-budgets-9q2d3r93.js +0 -14
  209. package/dist/emscripten-module-49k43zfy.js +0 -507
  210. package/dist/emscripten-module-ex4v0x4z.js +0 -606
  211. package/dist/emscripten-module-jfs3d1dq.js +0 -1536
  212. package/dist/emscripten-module-ss4g4spn.js +0 -4563
  213. package/dist/ffi-bbm9vkfa.js +0 -92
  214. package/dist/ffi-kb5r0x1j.js +0 -92
  215. package/dist/ffi-qnrt0y78.js +0 -80
  216. package/dist/ffi-yx2hpf4p.js +0 -80
  217. package/dist/index-8mtsfhyg.js +0 -146
  218. package/dist/index-8sseka65.js +0 -251
  219. package/dist/index-ss632za9.js +0 -77
  220. package/dist/model-resolution-6w6wzw18.js +0 -17
  221. package/dist/module-ES6BEMUI-1yjdz59c.js +0 -14
  222. package/dist/module-asyncify-2EFITU5U-fdkx4fhy.js +0 -9
  223. package/dist/prompt-context-29qkb28f.js +0 -7
  224. package/dist/recomp-orchestrator-m37p3fq6.js +0 -34
  225. package/dist/rpc-notifications-1ffm755w.js +0 -17
  226. package/dist/safe-notification-target-2a8py95v.js +0 -11
  227. package/dist/send-session-notification-bw7eex6w.js +0 -20
  228. package/dist/storage-meta-session-dse3qv6s.js +0 -23
  229. package/dist/task-config-gv6s04fp.js +0 -18
  230. /package/dist/{index-37yzyeca.js → index-3fe78beq.js} +0 -0
@@ -0,0 +1,1583 @@
1
+ // src/shared/jsonc-parser.ts
2
+ import { existsSync, readFileSync } from "node:fs";
3
+
4
+ // ../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
5
+ function createScanner2(text, ignoreTrivia = false) {
6
+ const len = text.length;
7
+ let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
8
+ function scanHexDigits(count, exact) {
9
+ let digits = 0;
10
+ let value = 0;
11
+ while (digits < count || !exact) {
12
+ let ch = text.charCodeAt(pos);
13
+ if (ch >= 48 && ch <= 57) {
14
+ value = value * 16 + ch - 48;
15
+ } else if (ch >= 65 && ch <= 70) {
16
+ value = value * 16 + ch - 65 + 10;
17
+ } else if (ch >= 97 && ch <= 102) {
18
+ value = value * 16 + ch - 97 + 10;
19
+ } else {
20
+ break;
21
+ }
22
+ pos++;
23
+ digits++;
24
+ }
25
+ if (digits < count) {
26
+ value = -1;
27
+ }
28
+ return value;
29
+ }
30
+ function setPosition(newPosition) {
31
+ pos = newPosition;
32
+ value = "";
33
+ tokenOffset = 0;
34
+ token = 16;
35
+ scanError = 0;
36
+ }
37
+ function scanNumber() {
38
+ let start = pos;
39
+ if (text.charCodeAt(pos) === 48) {
40
+ pos++;
41
+ } else {
42
+ pos++;
43
+ while (pos < text.length && isDigit(text.charCodeAt(pos))) {
44
+ pos++;
45
+ }
46
+ }
47
+ if (pos < text.length && text.charCodeAt(pos) === 46) {
48
+ pos++;
49
+ if (pos < text.length && isDigit(text.charCodeAt(pos))) {
50
+ pos++;
51
+ while (pos < text.length && isDigit(text.charCodeAt(pos))) {
52
+ pos++;
53
+ }
54
+ } else {
55
+ scanError = 3;
56
+ return text.substring(start, pos);
57
+ }
58
+ }
59
+ let end = pos;
60
+ if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
61
+ pos++;
62
+ if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) {
63
+ pos++;
64
+ }
65
+ if (pos < text.length && isDigit(text.charCodeAt(pos))) {
66
+ pos++;
67
+ while (pos < text.length && isDigit(text.charCodeAt(pos))) {
68
+ pos++;
69
+ }
70
+ end = pos;
71
+ } else {
72
+ scanError = 3;
73
+ }
74
+ }
75
+ return text.substring(start, end);
76
+ }
77
+ function scanString() {
78
+ let result = "", start = pos;
79
+ while (true) {
80
+ if (pos >= len) {
81
+ result += text.substring(start, pos);
82
+ scanError = 2;
83
+ break;
84
+ }
85
+ const ch = text.charCodeAt(pos);
86
+ if (ch === 34) {
87
+ result += text.substring(start, pos);
88
+ pos++;
89
+ break;
90
+ }
91
+ if (ch === 92) {
92
+ result += text.substring(start, pos);
93
+ pos++;
94
+ if (pos >= len) {
95
+ scanError = 2;
96
+ break;
97
+ }
98
+ const ch2 = text.charCodeAt(pos++);
99
+ switch (ch2) {
100
+ case 34:
101
+ result += '"';
102
+ break;
103
+ case 92:
104
+ result += "\\";
105
+ break;
106
+ case 47:
107
+ result += "/";
108
+ break;
109
+ case 98:
110
+ result += "\b";
111
+ break;
112
+ case 102:
113
+ result += "\f";
114
+ break;
115
+ case 110:
116
+ result += `
117
+ `;
118
+ break;
119
+ case 114:
120
+ result += "\r";
121
+ break;
122
+ case 116:
123
+ result += "\t";
124
+ break;
125
+ case 117:
126
+ const ch3 = scanHexDigits(4, true);
127
+ if (ch3 >= 0) {
128
+ result += String.fromCharCode(ch3);
129
+ } else {
130
+ scanError = 4;
131
+ }
132
+ break;
133
+ default:
134
+ scanError = 5;
135
+ }
136
+ start = pos;
137
+ continue;
138
+ }
139
+ if (ch >= 0 && ch <= 31) {
140
+ if (isLineBreak(ch)) {
141
+ result += text.substring(start, pos);
142
+ scanError = 2;
143
+ break;
144
+ } else {
145
+ scanError = 6;
146
+ }
147
+ }
148
+ pos++;
149
+ }
150
+ return result;
151
+ }
152
+ function scanNext() {
153
+ value = "";
154
+ scanError = 0;
155
+ tokenOffset = pos;
156
+ lineStartOffset = lineNumber;
157
+ prevTokenLineStartOffset = tokenLineStartOffset;
158
+ if (pos >= len) {
159
+ tokenOffset = len;
160
+ return token = 17;
161
+ }
162
+ let code = text.charCodeAt(pos);
163
+ if (isWhiteSpace(code)) {
164
+ do {
165
+ pos++;
166
+ value += String.fromCharCode(code);
167
+ code = text.charCodeAt(pos);
168
+ } while (isWhiteSpace(code));
169
+ return token = 15;
170
+ }
171
+ if (isLineBreak(code)) {
172
+ pos++;
173
+ value += String.fromCharCode(code);
174
+ if (code === 13 && text.charCodeAt(pos) === 10) {
175
+ pos++;
176
+ value += `
177
+ `;
178
+ }
179
+ lineNumber++;
180
+ tokenLineStartOffset = pos;
181
+ return token = 14;
182
+ }
183
+ switch (code) {
184
+ case 123:
185
+ pos++;
186
+ return token = 1;
187
+ case 125:
188
+ pos++;
189
+ return token = 2;
190
+ case 91:
191
+ pos++;
192
+ return token = 3;
193
+ case 93:
194
+ pos++;
195
+ return token = 4;
196
+ case 58:
197
+ pos++;
198
+ return token = 6;
199
+ case 44:
200
+ pos++;
201
+ return token = 5;
202
+ case 34:
203
+ pos++;
204
+ value = scanString();
205
+ return token = 10;
206
+ case 47:
207
+ const start = pos - 1;
208
+ if (text.charCodeAt(pos + 1) === 47) {
209
+ pos += 2;
210
+ while (pos < len) {
211
+ if (isLineBreak(text.charCodeAt(pos))) {
212
+ break;
213
+ }
214
+ pos++;
215
+ }
216
+ value = text.substring(start, pos);
217
+ return token = 12;
218
+ }
219
+ if (text.charCodeAt(pos + 1) === 42) {
220
+ pos += 2;
221
+ const safeLength = len - 1;
222
+ let commentClosed = false;
223
+ while (pos < safeLength) {
224
+ const ch = text.charCodeAt(pos);
225
+ if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
226
+ pos += 2;
227
+ commentClosed = true;
228
+ break;
229
+ }
230
+ pos++;
231
+ if (isLineBreak(ch)) {
232
+ if (ch === 13 && text.charCodeAt(pos) === 10) {
233
+ pos++;
234
+ }
235
+ lineNumber++;
236
+ tokenLineStartOffset = pos;
237
+ }
238
+ }
239
+ if (!commentClosed) {
240
+ pos++;
241
+ scanError = 1;
242
+ }
243
+ value = text.substring(start, pos);
244
+ return token = 13;
245
+ }
246
+ value += String.fromCharCode(code);
247
+ pos++;
248
+ return token = 16;
249
+ case 45:
250
+ value += String.fromCharCode(code);
251
+ pos++;
252
+ if (pos === len || !isDigit(text.charCodeAt(pos))) {
253
+ return token = 16;
254
+ }
255
+ case 48:
256
+ case 49:
257
+ case 50:
258
+ case 51:
259
+ case 52:
260
+ case 53:
261
+ case 54:
262
+ case 55:
263
+ case 56:
264
+ case 57:
265
+ value += scanNumber();
266
+ return token = 11;
267
+ default:
268
+ while (pos < len && isUnknownContentCharacter(code)) {
269
+ pos++;
270
+ code = text.charCodeAt(pos);
271
+ }
272
+ if (tokenOffset !== pos) {
273
+ value = text.substring(tokenOffset, pos);
274
+ switch (value) {
275
+ case "true":
276
+ return token = 8;
277
+ case "false":
278
+ return token = 9;
279
+ case "null":
280
+ return token = 7;
281
+ }
282
+ return token = 16;
283
+ }
284
+ value += String.fromCharCode(code);
285
+ pos++;
286
+ return token = 16;
287
+ }
288
+ }
289
+ function isUnknownContentCharacter(code) {
290
+ if (isWhiteSpace(code) || isLineBreak(code)) {
291
+ return false;
292
+ }
293
+ switch (code) {
294
+ case 125:
295
+ case 93:
296
+ case 123:
297
+ case 91:
298
+ case 34:
299
+ case 58:
300
+ case 44:
301
+ case 47:
302
+ return false;
303
+ }
304
+ return true;
305
+ }
306
+ function scanNextNonTrivia() {
307
+ let result;
308
+ do {
309
+ result = scanNext();
310
+ } while (result >= 12 && result <= 15);
311
+ return result;
312
+ }
313
+ return {
314
+ setPosition,
315
+ getPosition: () => pos,
316
+ scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
317
+ getToken: () => token,
318
+ getTokenValue: () => value,
319
+ getTokenOffset: () => tokenOffset,
320
+ getTokenLength: () => pos - tokenOffset,
321
+ getTokenStartLine: () => lineStartOffset,
322
+ getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
323
+ getTokenError: () => scanError
324
+ };
325
+ }
326
+ function isWhiteSpace(ch) {
327
+ return ch === 32 || ch === 9;
328
+ }
329
+ function isLineBreak(ch) {
330
+ return ch === 10 || ch === 13;
331
+ }
332
+ function isDigit(ch) {
333
+ return ch >= 48 && ch <= 57;
334
+ }
335
+ var CharacterCodes;
336
+ (function(CharacterCodes) {
337
+ CharacterCodes[CharacterCodes["lineFeed"] = 10] = "lineFeed";
338
+ CharacterCodes[CharacterCodes["carriageReturn"] = 13] = "carriageReturn";
339
+ CharacterCodes[CharacterCodes["space"] = 32] = "space";
340
+ CharacterCodes[CharacterCodes["_0"] = 48] = "_0";
341
+ CharacterCodes[CharacterCodes["_1"] = 49] = "_1";
342
+ CharacterCodes[CharacterCodes["_2"] = 50] = "_2";
343
+ CharacterCodes[CharacterCodes["_3"] = 51] = "_3";
344
+ CharacterCodes[CharacterCodes["_4"] = 52] = "_4";
345
+ CharacterCodes[CharacterCodes["_5"] = 53] = "_5";
346
+ CharacterCodes[CharacterCodes["_6"] = 54] = "_6";
347
+ CharacterCodes[CharacterCodes["_7"] = 55] = "_7";
348
+ CharacterCodes[CharacterCodes["_8"] = 56] = "_8";
349
+ CharacterCodes[CharacterCodes["_9"] = 57] = "_9";
350
+ CharacterCodes[CharacterCodes["a"] = 97] = "a";
351
+ CharacterCodes[CharacterCodes["b"] = 98] = "b";
352
+ CharacterCodes[CharacterCodes["c"] = 99] = "c";
353
+ CharacterCodes[CharacterCodes["d"] = 100] = "d";
354
+ CharacterCodes[CharacterCodes["e"] = 101] = "e";
355
+ CharacterCodes[CharacterCodes["f"] = 102] = "f";
356
+ CharacterCodes[CharacterCodes["g"] = 103] = "g";
357
+ CharacterCodes[CharacterCodes["h"] = 104] = "h";
358
+ CharacterCodes[CharacterCodes["i"] = 105] = "i";
359
+ CharacterCodes[CharacterCodes["j"] = 106] = "j";
360
+ CharacterCodes[CharacterCodes["k"] = 107] = "k";
361
+ CharacterCodes[CharacterCodes["l"] = 108] = "l";
362
+ CharacterCodes[CharacterCodes["m"] = 109] = "m";
363
+ CharacterCodes[CharacterCodes["n"] = 110] = "n";
364
+ CharacterCodes[CharacterCodes["o"] = 111] = "o";
365
+ CharacterCodes[CharacterCodes["p"] = 112] = "p";
366
+ CharacterCodes[CharacterCodes["q"] = 113] = "q";
367
+ CharacterCodes[CharacterCodes["r"] = 114] = "r";
368
+ CharacterCodes[CharacterCodes["s"] = 115] = "s";
369
+ CharacterCodes[CharacterCodes["t"] = 116] = "t";
370
+ CharacterCodes[CharacterCodes["u"] = 117] = "u";
371
+ CharacterCodes[CharacterCodes["v"] = 118] = "v";
372
+ CharacterCodes[CharacterCodes["w"] = 119] = "w";
373
+ CharacterCodes[CharacterCodes["x"] = 120] = "x";
374
+ CharacterCodes[CharacterCodes["y"] = 121] = "y";
375
+ CharacterCodes[CharacterCodes["z"] = 122] = "z";
376
+ CharacterCodes[CharacterCodes["A"] = 65] = "A";
377
+ CharacterCodes[CharacterCodes["B"] = 66] = "B";
378
+ CharacterCodes[CharacterCodes["C"] = 67] = "C";
379
+ CharacterCodes[CharacterCodes["D"] = 68] = "D";
380
+ CharacterCodes[CharacterCodes["E"] = 69] = "E";
381
+ CharacterCodes[CharacterCodes["F"] = 70] = "F";
382
+ CharacterCodes[CharacterCodes["G"] = 71] = "G";
383
+ CharacterCodes[CharacterCodes["H"] = 72] = "H";
384
+ CharacterCodes[CharacterCodes["I"] = 73] = "I";
385
+ CharacterCodes[CharacterCodes["J"] = 74] = "J";
386
+ CharacterCodes[CharacterCodes["K"] = 75] = "K";
387
+ CharacterCodes[CharacterCodes["L"] = 76] = "L";
388
+ CharacterCodes[CharacterCodes["M"] = 77] = "M";
389
+ CharacterCodes[CharacterCodes["N"] = 78] = "N";
390
+ CharacterCodes[CharacterCodes["O"] = 79] = "O";
391
+ CharacterCodes[CharacterCodes["P"] = 80] = "P";
392
+ CharacterCodes[CharacterCodes["Q"] = 81] = "Q";
393
+ CharacterCodes[CharacterCodes["R"] = 82] = "R";
394
+ CharacterCodes[CharacterCodes["S"] = 83] = "S";
395
+ CharacterCodes[CharacterCodes["T"] = 84] = "T";
396
+ CharacterCodes[CharacterCodes["U"] = 85] = "U";
397
+ CharacterCodes[CharacterCodes["V"] = 86] = "V";
398
+ CharacterCodes[CharacterCodes["W"] = 87] = "W";
399
+ CharacterCodes[CharacterCodes["X"] = 88] = "X";
400
+ CharacterCodes[CharacterCodes["Y"] = 89] = "Y";
401
+ CharacterCodes[CharacterCodes["Z"] = 90] = "Z";
402
+ CharacterCodes[CharacterCodes["asterisk"] = 42] = "asterisk";
403
+ CharacterCodes[CharacterCodes["backslash"] = 92] = "backslash";
404
+ CharacterCodes[CharacterCodes["closeBrace"] = 125] = "closeBrace";
405
+ CharacterCodes[CharacterCodes["closeBracket"] = 93] = "closeBracket";
406
+ CharacterCodes[CharacterCodes["colon"] = 58] = "colon";
407
+ CharacterCodes[CharacterCodes["comma"] = 44] = "comma";
408
+ CharacterCodes[CharacterCodes["dot"] = 46] = "dot";
409
+ CharacterCodes[CharacterCodes["doubleQuote"] = 34] = "doubleQuote";
410
+ CharacterCodes[CharacterCodes["minus"] = 45] = "minus";
411
+ CharacterCodes[CharacterCodes["openBrace"] = 123] = "openBrace";
412
+ CharacterCodes[CharacterCodes["openBracket"] = 91] = "openBracket";
413
+ CharacterCodes[CharacterCodes["plus"] = 43] = "plus";
414
+ CharacterCodes[CharacterCodes["slash"] = 47] = "slash";
415
+ CharacterCodes[CharacterCodes["formFeed"] = 12] = "formFeed";
416
+ CharacterCodes[CharacterCodes["tab"] = 9] = "tab";
417
+ })(CharacterCodes || (CharacterCodes = {}));
418
+
419
+ // ../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/string-intern.js
420
+ var cachedSpaces = new Array(20).fill(0).map((_, index) => {
421
+ return " ".repeat(index);
422
+ });
423
+ var maxCachedValues = 200;
424
+ var cachedBreakLinesWithSpaces = {
425
+ " ": {
426
+ "\n": new Array(maxCachedValues).fill(0).map((_, index) => {
427
+ return `
428
+ ` + " ".repeat(index);
429
+ }),
430
+ "\r": new Array(maxCachedValues).fill(0).map((_, index) => {
431
+ return "\r" + " ".repeat(index);
432
+ }),
433
+ "\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
434
+ return `\r
435
+ ` + " ".repeat(index);
436
+ })
437
+ },
438
+ "\t": {
439
+ "\n": new Array(maxCachedValues).fill(0).map((_, index) => {
440
+ return `
441
+ ` + "\t".repeat(index);
442
+ }),
443
+ "\r": new Array(maxCachedValues).fill(0).map((_, index) => {
444
+ return "\r" + "\t".repeat(index);
445
+ }),
446
+ "\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
447
+ return `\r
448
+ ` + "\t".repeat(index);
449
+ })
450
+ }
451
+ };
452
+ var supportedEols = [`
453
+ `, "\r", `\r
454
+ `];
455
+
456
+ // ../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/format.js
457
+ function format(documentText, range, options) {
458
+ let initialIndentLevel;
459
+ let formatText;
460
+ let formatTextStart;
461
+ let rangeStart;
462
+ let rangeEnd;
463
+ if (range) {
464
+ rangeStart = range.offset;
465
+ rangeEnd = rangeStart + range.length;
466
+ formatTextStart = rangeStart;
467
+ while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) {
468
+ formatTextStart--;
469
+ }
470
+ let endOffset = rangeEnd;
471
+ while (endOffset < documentText.length && !isEOL(documentText, endOffset)) {
472
+ endOffset++;
473
+ }
474
+ formatText = documentText.substring(formatTextStart, endOffset);
475
+ initialIndentLevel = computeIndentLevel(formatText, options);
476
+ } else {
477
+ formatText = documentText;
478
+ initialIndentLevel = 0;
479
+ formatTextStart = 0;
480
+ rangeStart = 0;
481
+ rangeEnd = documentText.length;
482
+ }
483
+ const eol = getEOL(options, documentText);
484
+ const eolFastPathSupported = supportedEols.includes(eol);
485
+ let numberLineBreaks = 0;
486
+ let indentLevel = 0;
487
+ let indentValue;
488
+ if (options.insertSpaces) {
489
+ indentValue = cachedSpaces[options.tabSize || 4] ?? repeat(cachedSpaces[1], options.tabSize || 4);
490
+ } else {
491
+ indentValue = "\t";
492
+ }
493
+ const indentType = indentValue === "\t" ? "\t" : " ";
494
+ let scanner = createScanner2(formatText, false);
495
+ let hasError = false;
496
+ function newLinesAndIndent() {
497
+ if (numberLineBreaks > 1) {
498
+ return repeat(eol, numberLineBreaks) + repeat(indentValue, initialIndentLevel + indentLevel);
499
+ }
500
+ const amountOfSpaces = indentValue.length * (initialIndentLevel + indentLevel);
501
+ if (!eolFastPathSupported || amountOfSpaces > cachedBreakLinesWithSpaces[indentType][eol].length) {
502
+ return eol + repeat(indentValue, initialIndentLevel + indentLevel);
503
+ }
504
+ if (amountOfSpaces <= 0) {
505
+ return eol;
506
+ }
507
+ return cachedBreakLinesWithSpaces[indentType][eol][amountOfSpaces];
508
+ }
509
+ function scanNext() {
510
+ let token = scanner.scan();
511
+ numberLineBreaks = 0;
512
+ while (token === 15 || token === 14) {
513
+ if (token === 14 && options.keepLines) {
514
+ numberLineBreaks += 1;
515
+ } else if (token === 14) {
516
+ numberLineBreaks = 1;
517
+ }
518
+ token = scanner.scan();
519
+ }
520
+ hasError = token === 16 || scanner.getTokenError() !== 0;
521
+ return token;
522
+ }
523
+ const editOperations = [];
524
+ function addEdit(text, startOffset, endOffset) {
525
+ if (!hasError && (!range || startOffset < rangeEnd && endOffset > rangeStart) && documentText.substring(startOffset, endOffset) !== text) {
526
+ editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text });
527
+ }
528
+ }
529
+ let firstToken = scanNext();
530
+ if (options.keepLines && numberLineBreaks > 0) {
531
+ addEdit(repeat(eol, numberLineBreaks), 0, 0);
532
+ }
533
+ if (firstToken !== 17) {
534
+ let firstTokenStart = scanner.getTokenOffset() + formatTextStart;
535
+ let initialIndent = indentValue.length * initialIndentLevel < 20 && options.insertSpaces ? cachedSpaces[indentValue.length * initialIndentLevel] : repeat(indentValue, initialIndentLevel);
536
+ addEdit(initialIndent, formatTextStart, firstTokenStart);
537
+ }
538
+ while (firstToken !== 17) {
539
+ let firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
540
+ let secondToken = scanNext();
541
+ let replaceContent = "";
542
+ let needsLineBreak = false;
543
+ while (numberLineBreaks === 0 && (secondToken === 12 || secondToken === 13)) {
544
+ let commentTokenStart = scanner.getTokenOffset() + formatTextStart;
545
+ addEdit(cachedSpaces[1], firstTokenEnd, commentTokenStart);
546
+ firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
547
+ needsLineBreak = secondToken === 12;
548
+ replaceContent = needsLineBreak ? newLinesAndIndent() : "";
549
+ secondToken = scanNext();
550
+ }
551
+ if (secondToken === 2) {
552
+ if (firstToken !== 1) {
553
+ indentLevel--;
554
+ }
555
+ if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 1) {
556
+ replaceContent = newLinesAndIndent();
557
+ } else if (options.keepLines) {
558
+ replaceContent = cachedSpaces[1];
559
+ }
560
+ } else if (secondToken === 4) {
561
+ if (firstToken !== 3) {
562
+ indentLevel--;
563
+ }
564
+ if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 3) {
565
+ replaceContent = newLinesAndIndent();
566
+ } else if (options.keepLines) {
567
+ replaceContent = cachedSpaces[1];
568
+ }
569
+ } else {
570
+ switch (firstToken) {
571
+ case 3:
572
+ case 1:
573
+ indentLevel++;
574
+ if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
575
+ replaceContent = newLinesAndIndent();
576
+ } else {
577
+ replaceContent = cachedSpaces[1];
578
+ }
579
+ break;
580
+ case 5:
581
+ if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
582
+ replaceContent = newLinesAndIndent();
583
+ } else {
584
+ replaceContent = cachedSpaces[1];
585
+ }
586
+ break;
587
+ case 12:
588
+ replaceContent = newLinesAndIndent();
589
+ break;
590
+ case 13:
591
+ if (numberLineBreaks > 0) {
592
+ replaceContent = newLinesAndIndent();
593
+ } else if (!needsLineBreak) {
594
+ replaceContent = cachedSpaces[1];
595
+ }
596
+ break;
597
+ case 6:
598
+ if (options.keepLines && numberLineBreaks > 0) {
599
+ replaceContent = newLinesAndIndent();
600
+ } else if (!needsLineBreak) {
601
+ replaceContent = cachedSpaces[1];
602
+ }
603
+ break;
604
+ case 10:
605
+ if (options.keepLines && numberLineBreaks > 0) {
606
+ replaceContent = newLinesAndIndent();
607
+ } else if (secondToken === 6 && !needsLineBreak) {
608
+ replaceContent = "";
609
+ }
610
+ break;
611
+ case 7:
612
+ case 8:
613
+ case 9:
614
+ case 11:
615
+ case 2:
616
+ case 4:
617
+ if (options.keepLines && numberLineBreaks > 0) {
618
+ replaceContent = newLinesAndIndent();
619
+ } else {
620
+ if ((secondToken === 12 || secondToken === 13) && !needsLineBreak) {
621
+ replaceContent = cachedSpaces[1];
622
+ } else if (secondToken !== 5 && secondToken !== 17) {
623
+ hasError = true;
624
+ }
625
+ }
626
+ break;
627
+ case 16:
628
+ hasError = true;
629
+ break;
630
+ }
631
+ if (numberLineBreaks > 0 && (secondToken === 12 || secondToken === 13)) {
632
+ replaceContent = newLinesAndIndent();
633
+ }
634
+ }
635
+ if (secondToken === 17) {
636
+ if (options.keepLines && numberLineBreaks > 0) {
637
+ replaceContent = newLinesAndIndent();
638
+ } else {
639
+ replaceContent = options.insertFinalNewline ? eol : "";
640
+ }
641
+ }
642
+ const secondTokenStart = scanner.getTokenOffset() + formatTextStart;
643
+ addEdit(replaceContent, firstTokenEnd, secondTokenStart);
644
+ firstToken = secondToken;
645
+ }
646
+ return editOperations;
647
+ }
648
+ function repeat(s, count) {
649
+ let result = "";
650
+ for (let i = 0;i < count; i++) {
651
+ result += s;
652
+ }
653
+ return result;
654
+ }
655
+ function computeIndentLevel(content, options) {
656
+ let i = 0;
657
+ let nChars = 0;
658
+ const tabSize = options.tabSize || 4;
659
+ while (i < content.length) {
660
+ let ch = content.charAt(i);
661
+ if (ch === cachedSpaces[1]) {
662
+ nChars++;
663
+ } else if (ch === "\t") {
664
+ nChars += tabSize;
665
+ } else {
666
+ break;
667
+ }
668
+ i++;
669
+ }
670
+ return Math.floor(nChars / tabSize);
671
+ }
672
+ function getEOL(options, text) {
673
+ for (let i = 0;i < text.length; i++) {
674
+ const ch = text.charAt(i);
675
+ if (ch === "\r") {
676
+ if (i + 1 < text.length && text.charAt(i + 1) === `
677
+ `) {
678
+ return `\r
679
+ `;
680
+ }
681
+ return "\r";
682
+ } else if (ch === `
683
+ `) {
684
+ return `
685
+ `;
686
+ }
687
+ }
688
+ return options && options.eol || `
689
+ `;
690
+ }
691
+ function isEOL(text, offset) {
692
+ return `\r
693
+ `.indexOf(text.charAt(offset)) !== -1;
694
+ }
695
+
696
+ // ../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/parser.js
697
+ var ParseOptions;
698
+ (function(ParseOptions) {
699
+ ParseOptions.DEFAULT = {
700
+ allowTrailingComma: false
701
+ };
702
+ })(ParseOptions || (ParseOptions = {}));
703
+ function parse(text, errors = [], options = ParseOptions.DEFAULT) {
704
+ let currentProperty = null;
705
+ let currentParent = [];
706
+ const previousParents = [];
707
+ function onValue(value) {
708
+ if (Array.isArray(currentParent)) {
709
+ currentParent.push(value);
710
+ } else if (currentProperty !== null) {
711
+ currentParent[currentProperty] = value;
712
+ }
713
+ }
714
+ const visitor = {
715
+ onObjectBegin: () => {
716
+ const object = {};
717
+ onValue(object);
718
+ previousParents.push(currentParent);
719
+ currentParent = object;
720
+ currentProperty = null;
721
+ },
722
+ onObjectProperty: (name) => {
723
+ currentProperty = name;
724
+ },
725
+ onObjectEnd: () => {
726
+ currentParent = previousParents.pop();
727
+ },
728
+ onArrayBegin: () => {
729
+ const array = [];
730
+ onValue(array);
731
+ previousParents.push(currentParent);
732
+ currentParent = array;
733
+ currentProperty = null;
734
+ },
735
+ onArrayEnd: () => {
736
+ currentParent = previousParents.pop();
737
+ },
738
+ onLiteralValue: onValue,
739
+ onError: (error, offset, length) => {
740
+ errors.push({ error, offset, length });
741
+ }
742
+ };
743
+ visit(text, visitor, options);
744
+ return currentParent[0];
745
+ }
746
+ function parseTree2(text, errors = [], options = ParseOptions.DEFAULT) {
747
+ let currentParent = { type: "array", offset: -1, length: -1, children: [], parent: undefined };
748
+ function ensurePropertyComplete(endOffset) {
749
+ if (currentParent.type === "property") {
750
+ currentParent.length = endOffset - currentParent.offset;
751
+ currentParent = currentParent.parent;
752
+ }
753
+ }
754
+ function onValue(valueNode) {
755
+ currentParent.children.push(valueNode);
756
+ return valueNode;
757
+ }
758
+ const visitor = {
759
+ onObjectBegin: (offset) => {
760
+ currentParent = onValue({ type: "object", offset, length: -1, parent: currentParent, children: [] });
761
+ },
762
+ onObjectProperty: (name, offset, length) => {
763
+ currentParent = onValue({ type: "property", offset, length: -1, parent: currentParent, children: [] });
764
+ currentParent.children.push({ type: "string", value: name, offset, length, parent: currentParent });
765
+ },
766
+ onObjectEnd: (offset, length) => {
767
+ ensurePropertyComplete(offset + length);
768
+ currentParent.length = offset + length - currentParent.offset;
769
+ currentParent = currentParent.parent;
770
+ ensurePropertyComplete(offset + length);
771
+ },
772
+ onArrayBegin: (offset, length) => {
773
+ currentParent = onValue({ type: "array", offset, length: -1, parent: currentParent, children: [] });
774
+ },
775
+ onArrayEnd: (offset, length) => {
776
+ currentParent.length = offset + length - currentParent.offset;
777
+ currentParent = currentParent.parent;
778
+ ensurePropertyComplete(offset + length);
779
+ },
780
+ onLiteralValue: (value, offset, length) => {
781
+ onValue({ type: getNodeType(value), offset, length, parent: currentParent, value });
782
+ ensurePropertyComplete(offset + length);
783
+ },
784
+ onSeparator: (sep, offset, length) => {
785
+ if (currentParent.type === "property") {
786
+ if (sep === ":") {
787
+ currentParent.colonOffset = offset;
788
+ } else if (sep === ",") {
789
+ ensurePropertyComplete(offset);
790
+ }
791
+ }
792
+ },
793
+ onError: (error, offset, length) => {
794
+ errors.push({ error, offset, length });
795
+ }
796
+ };
797
+ visit(text, visitor, options);
798
+ const result = currentParent.children[0];
799
+ if (result) {
800
+ delete result.parent;
801
+ }
802
+ return result;
803
+ }
804
+ function findNodeAtLocation2(root, path) {
805
+ if (!root) {
806
+ return;
807
+ }
808
+ let node = root;
809
+ for (let segment of path) {
810
+ if (typeof segment === "string") {
811
+ if (node.type !== "object" || !Array.isArray(node.children)) {
812
+ return;
813
+ }
814
+ let found = false;
815
+ for (const propertyNode of node.children) {
816
+ if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment && propertyNode.children.length === 2) {
817
+ node = propertyNode.children[1];
818
+ found = true;
819
+ break;
820
+ }
821
+ }
822
+ if (!found) {
823
+ return;
824
+ }
825
+ } else {
826
+ const index = segment;
827
+ if (node.type !== "array" || index < 0 || !Array.isArray(node.children) || index >= node.children.length) {
828
+ return;
829
+ }
830
+ node = node.children[index];
831
+ }
832
+ }
833
+ return node;
834
+ }
835
+ function getNodeValue2(node) {
836
+ switch (node.type) {
837
+ case "array":
838
+ return node.children.map(getNodeValue2);
839
+ case "object":
840
+ const obj = Object.create(null);
841
+ for (let prop of node.children) {
842
+ const valueNode = prop.children[1];
843
+ if (valueNode) {
844
+ obj[prop.children[0].value] = getNodeValue2(valueNode);
845
+ }
846
+ }
847
+ return obj;
848
+ case "null":
849
+ case "string":
850
+ case "number":
851
+ case "boolean":
852
+ return node.value;
853
+ default:
854
+ return;
855
+ }
856
+ }
857
+ function visit(text, visitor, options = ParseOptions.DEFAULT) {
858
+ const _scanner = createScanner2(text, false);
859
+ const _jsonPath = [];
860
+ let suppressedCallbacks = 0;
861
+ function toNoArgVisit(visitFunction) {
862
+ return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
863
+ }
864
+ function toOneArgVisit(visitFunction) {
865
+ return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
866
+ }
867
+ function toOneArgVisitWithPath(visitFunction) {
868
+ return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
869
+ }
870
+ function toBeginVisit(visitFunction) {
871
+ return visitFunction ? () => {
872
+ if (suppressedCallbacks > 0) {
873
+ suppressedCallbacks++;
874
+ } else {
875
+ let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
876
+ if (cbReturn === false) {
877
+ suppressedCallbacks = 1;
878
+ }
879
+ }
880
+ } : () => true;
881
+ }
882
+ function toEndVisit(visitFunction) {
883
+ return visitFunction ? () => {
884
+ if (suppressedCallbacks > 0) {
885
+ suppressedCallbacks--;
886
+ }
887
+ if (suppressedCallbacks === 0) {
888
+ visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
889
+ }
890
+ } : () => true;
891
+ }
892
+ const onObjectBegin = toBeginVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toEndVisit(visitor.onObjectEnd), onArrayBegin = toBeginVisit(visitor.onArrayBegin), onArrayEnd = toEndVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
893
+ const disallowComments = options && options.disallowComments;
894
+ const allowTrailingComma = options && options.allowTrailingComma;
895
+ function scanNext() {
896
+ while (true) {
897
+ const token = _scanner.scan();
898
+ switch (_scanner.getTokenError()) {
899
+ case 4:
900
+ handleError(14);
901
+ break;
902
+ case 5:
903
+ handleError(15);
904
+ break;
905
+ case 3:
906
+ handleError(13);
907
+ break;
908
+ case 1:
909
+ if (!disallowComments) {
910
+ handleError(11);
911
+ }
912
+ break;
913
+ case 2:
914
+ handleError(12);
915
+ break;
916
+ case 6:
917
+ handleError(16);
918
+ break;
919
+ }
920
+ switch (token) {
921
+ case 12:
922
+ case 13:
923
+ if (disallowComments) {
924
+ handleError(10);
925
+ } else {
926
+ onComment();
927
+ }
928
+ break;
929
+ case 16:
930
+ handleError(1);
931
+ break;
932
+ case 15:
933
+ case 14:
934
+ break;
935
+ default:
936
+ return token;
937
+ }
938
+ }
939
+ }
940
+ function handleError(error, skipUntilAfter = [], skipUntil = []) {
941
+ onError(error);
942
+ if (skipUntilAfter.length + skipUntil.length > 0) {
943
+ let token = _scanner.getToken();
944
+ while (token !== 17) {
945
+ if (skipUntilAfter.indexOf(token) !== -1) {
946
+ scanNext();
947
+ break;
948
+ } else if (skipUntil.indexOf(token) !== -1) {
949
+ break;
950
+ }
951
+ token = scanNext();
952
+ }
953
+ }
954
+ }
955
+ function parseString(isValue) {
956
+ const value = _scanner.getTokenValue();
957
+ if (isValue) {
958
+ onLiteralValue(value);
959
+ } else {
960
+ onObjectProperty(value);
961
+ _jsonPath.push(value);
962
+ }
963
+ scanNext();
964
+ return true;
965
+ }
966
+ function parseLiteral() {
967
+ switch (_scanner.getToken()) {
968
+ case 11:
969
+ const tokenValue = _scanner.getTokenValue();
970
+ let value = Number(tokenValue);
971
+ if (isNaN(value)) {
972
+ handleError(2);
973
+ value = 0;
974
+ }
975
+ onLiteralValue(value);
976
+ break;
977
+ case 7:
978
+ onLiteralValue(null);
979
+ break;
980
+ case 8:
981
+ onLiteralValue(true);
982
+ break;
983
+ case 9:
984
+ onLiteralValue(false);
985
+ break;
986
+ default:
987
+ return false;
988
+ }
989
+ scanNext();
990
+ return true;
991
+ }
992
+ function parseProperty() {
993
+ if (_scanner.getToken() !== 10) {
994
+ handleError(3, [], [2, 5]);
995
+ return false;
996
+ }
997
+ parseString(false);
998
+ if (_scanner.getToken() === 6) {
999
+ onSeparator(":");
1000
+ scanNext();
1001
+ if (!parseValue()) {
1002
+ handleError(4, [], [2, 5]);
1003
+ }
1004
+ } else {
1005
+ handleError(5, [], [2, 5]);
1006
+ }
1007
+ _jsonPath.pop();
1008
+ return true;
1009
+ }
1010
+ function parseObject() {
1011
+ onObjectBegin();
1012
+ scanNext();
1013
+ let needsComma = false;
1014
+ while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
1015
+ if (_scanner.getToken() === 5) {
1016
+ if (!needsComma) {
1017
+ handleError(4, [], []);
1018
+ }
1019
+ onSeparator(",");
1020
+ scanNext();
1021
+ if (_scanner.getToken() === 2 && allowTrailingComma) {
1022
+ break;
1023
+ }
1024
+ } else if (needsComma) {
1025
+ handleError(6, [], []);
1026
+ }
1027
+ if (!parseProperty()) {
1028
+ handleError(4, [], [2, 5]);
1029
+ }
1030
+ needsComma = true;
1031
+ }
1032
+ onObjectEnd();
1033
+ if (_scanner.getToken() !== 2) {
1034
+ handleError(7, [2], []);
1035
+ } else {
1036
+ scanNext();
1037
+ }
1038
+ return true;
1039
+ }
1040
+ function parseArray() {
1041
+ onArrayBegin();
1042
+ scanNext();
1043
+ let isFirstElement = true;
1044
+ let needsComma = false;
1045
+ while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
1046
+ if (_scanner.getToken() === 5) {
1047
+ if (!needsComma) {
1048
+ handleError(4, [], []);
1049
+ }
1050
+ onSeparator(",");
1051
+ scanNext();
1052
+ if (_scanner.getToken() === 4 && allowTrailingComma) {
1053
+ break;
1054
+ }
1055
+ } else if (needsComma) {
1056
+ handleError(6, [], []);
1057
+ }
1058
+ if (isFirstElement) {
1059
+ _jsonPath.push(0);
1060
+ isFirstElement = false;
1061
+ } else {
1062
+ _jsonPath[_jsonPath.length - 1]++;
1063
+ }
1064
+ if (!parseValue()) {
1065
+ handleError(4, [], [4, 5]);
1066
+ }
1067
+ needsComma = true;
1068
+ }
1069
+ onArrayEnd();
1070
+ if (!isFirstElement) {
1071
+ _jsonPath.pop();
1072
+ }
1073
+ if (_scanner.getToken() !== 4) {
1074
+ handleError(8, [4], []);
1075
+ } else {
1076
+ scanNext();
1077
+ }
1078
+ return true;
1079
+ }
1080
+ function parseValue() {
1081
+ switch (_scanner.getToken()) {
1082
+ case 3:
1083
+ return parseArray();
1084
+ case 1:
1085
+ return parseObject();
1086
+ case 10:
1087
+ return parseString(true);
1088
+ default:
1089
+ return parseLiteral();
1090
+ }
1091
+ }
1092
+ scanNext();
1093
+ if (_scanner.getToken() === 17) {
1094
+ if (options.allowEmptyContent) {
1095
+ return true;
1096
+ }
1097
+ handleError(4, [], []);
1098
+ return false;
1099
+ }
1100
+ if (!parseValue()) {
1101
+ handleError(4, [], []);
1102
+ return false;
1103
+ }
1104
+ if (_scanner.getToken() !== 17) {
1105
+ handleError(9, [], []);
1106
+ }
1107
+ return true;
1108
+ }
1109
+ function getNodeType(value) {
1110
+ switch (typeof value) {
1111
+ case "boolean":
1112
+ return "boolean";
1113
+ case "number":
1114
+ return "number";
1115
+ case "string":
1116
+ return "string";
1117
+ case "object": {
1118
+ if (!value) {
1119
+ return "null";
1120
+ } else if (Array.isArray(value)) {
1121
+ return "array";
1122
+ }
1123
+ return "object";
1124
+ }
1125
+ default:
1126
+ return "null";
1127
+ }
1128
+ }
1129
+
1130
+ // ../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/edit.js
1131
+ function setProperty(text, originalPath, value, options) {
1132
+ const path = originalPath.slice();
1133
+ const errors = [];
1134
+ const root = parseTree2(text, errors);
1135
+ let parent = undefined;
1136
+ let lastSegment = undefined;
1137
+ while (path.length > 0) {
1138
+ lastSegment = path.pop();
1139
+ parent = findNodeAtLocation2(root, path);
1140
+ if (parent === undefined && value !== undefined) {
1141
+ if (typeof lastSegment === "string") {
1142
+ value = { [lastSegment]: value };
1143
+ } else {
1144
+ value = [value];
1145
+ }
1146
+ } else {
1147
+ break;
1148
+ }
1149
+ }
1150
+ if (!parent) {
1151
+ if (value === undefined) {
1152
+ throw new Error("Can not delete in empty document");
1153
+ }
1154
+ return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, options);
1155
+ } else if (parent.type === "object" && typeof lastSegment === "string" && Array.isArray(parent.children)) {
1156
+ const existing = findNodeAtLocation2(parent, [lastSegment]);
1157
+ if (existing !== undefined) {
1158
+ if (value === undefined) {
1159
+ if (!existing.parent) {
1160
+ throw new Error("Malformed AST");
1161
+ }
1162
+ const propertyIndex = parent.children.indexOf(existing.parent);
1163
+ let removeBegin;
1164
+ let removeEnd = existing.parent.offset + existing.parent.length;
1165
+ if (propertyIndex > 0) {
1166
+ let previous = parent.children[propertyIndex - 1];
1167
+ removeBegin = previous.offset + previous.length;
1168
+ } else {
1169
+ removeBegin = parent.offset + 1;
1170
+ if (parent.children.length > 1) {
1171
+ let next = parent.children[1];
1172
+ removeEnd = next.offset;
1173
+ }
1174
+ }
1175
+ return withFormatting(text, { offset: removeBegin, length: removeEnd - removeBegin, content: "" }, options);
1176
+ } else {
1177
+ return withFormatting(text, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) }, options);
1178
+ }
1179
+ } else {
1180
+ if (value === undefined) {
1181
+ return [];
1182
+ }
1183
+ const newProperty = `${JSON.stringify(lastSegment)}: ${JSON.stringify(value)}`;
1184
+ const index = options.getInsertionIndex ? options.getInsertionIndex(parent.children.map((p) => p.children[0].value)) : parent.children.length;
1185
+ let edit;
1186
+ if (index > 0) {
1187
+ let previous = parent.children[index - 1];
1188
+ edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
1189
+ } else if (parent.children.length === 0) {
1190
+ edit = { offset: parent.offset + 1, length: 0, content: newProperty };
1191
+ } else {
1192
+ edit = { offset: parent.offset + 1, length: 0, content: newProperty + "," };
1193
+ }
1194
+ return withFormatting(text, edit, options);
1195
+ }
1196
+ } else if (parent.type === "array" && typeof lastSegment === "number" && Array.isArray(parent.children)) {
1197
+ const insertIndex = lastSegment;
1198
+ if (insertIndex === -1) {
1199
+ const newProperty = `${JSON.stringify(value)}`;
1200
+ let edit;
1201
+ if (parent.children.length === 0) {
1202
+ edit = { offset: parent.offset + 1, length: 0, content: newProperty };
1203
+ } else {
1204
+ const previous = parent.children[parent.children.length - 1];
1205
+ edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
1206
+ }
1207
+ return withFormatting(text, edit, options);
1208
+ } else if (value === undefined && parent.children.length >= 0) {
1209
+ const removalIndex = lastSegment;
1210
+ const toRemove = parent.children[removalIndex];
1211
+ let edit;
1212
+ if (parent.children.length === 1) {
1213
+ edit = { offset: parent.offset + 1, length: parent.length - 2, content: "" };
1214
+ } else if (parent.children.length - 1 === removalIndex) {
1215
+ let previous = parent.children[removalIndex - 1];
1216
+ let offset = previous.offset + previous.length;
1217
+ let parentEndOffset = parent.offset + parent.length;
1218
+ edit = { offset, length: parentEndOffset - 2 - offset, content: "" };
1219
+ } else {
1220
+ edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: "" };
1221
+ }
1222
+ return withFormatting(text, edit, options);
1223
+ } else if (value !== undefined) {
1224
+ let edit;
1225
+ const newProperty = `${JSON.stringify(value)}`;
1226
+ if (!options.isArrayInsertion && parent.children.length > lastSegment) {
1227
+ const toModify = parent.children[lastSegment];
1228
+ edit = { offset: toModify.offset, length: toModify.length, content: newProperty };
1229
+ } else if (parent.children.length === 0 || lastSegment === 0) {
1230
+ edit = { offset: parent.offset + 1, length: 0, content: parent.children.length === 0 ? newProperty : newProperty + "," };
1231
+ } else {
1232
+ const index = lastSegment > parent.children.length ? parent.children.length : lastSegment;
1233
+ const previous = parent.children[index - 1];
1234
+ edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
1235
+ }
1236
+ return withFormatting(text, edit, options);
1237
+ } else {
1238
+ throw new Error(`Can not ${value === undefined ? "remove" : options.isArrayInsertion ? "insert" : "modify"} Array index ${insertIndex} as length is not sufficient`);
1239
+ }
1240
+ } else {
1241
+ throw new Error(`Can not add ${typeof lastSegment !== "number" ? "index" : "property"} to parent of type ${parent.type}`);
1242
+ }
1243
+ }
1244
+ function withFormatting(text, edit, options) {
1245
+ if (!options.formattingOptions) {
1246
+ return [edit];
1247
+ }
1248
+ let newText = applyEdit(text, edit);
1249
+ let begin = edit.offset;
1250
+ let end = edit.offset + edit.content.length;
1251
+ if (edit.length === 0 || edit.content.length === 0) {
1252
+ while (begin > 0 && !isEOL(newText, begin - 1)) {
1253
+ begin--;
1254
+ }
1255
+ while (end < newText.length && !isEOL(newText, end)) {
1256
+ end++;
1257
+ }
1258
+ }
1259
+ const edits = format(newText, { offset: begin, length: end - begin }, { ...options.formattingOptions, keepLines: false });
1260
+ for (let i = edits.length - 1;i >= 0; i--) {
1261
+ const edit = edits[i];
1262
+ newText = applyEdit(newText, edit);
1263
+ begin = Math.min(begin, edit.offset);
1264
+ end = Math.max(end, edit.offset + edit.length);
1265
+ end += edit.content.length - edit.length;
1266
+ }
1267
+ const editLength = text.length - (newText.length - end) - begin;
1268
+ return [{ offset: begin, length: editLength, content: newText.substring(begin, end) }];
1269
+ }
1270
+ function applyEdit(text, edit) {
1271
+ return text.substring(0, edit.offset) + edit.content + text.substring(edit.offset + edit.length);
1272
+ }
1273
+
1274
+ // ../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/main.js
1275
+ var createScanner = createScanner2;
1276
+ var ScanError;
1277
+ (function(ScanError) {
1278
+ ScanError[ScanError["None"] = 0] = "None";
1279
+ ScanError[ScanError["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
1280
+ ScanError[ScanError["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
1281
+ ScanError[ScanError["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
1282
+ ScanError[ScanError["InvalidUnicode"] = 4] = "InvalidUnicode";
1283
+ ScanError[ScanError["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
1284
+ ScanError[ScanError["InvalidCharacter"] = 6] = "InvalidCharacter";
1285
+ })(ScanError || (ScanError = {}));
1286
+ var SyntaxKind;
1287
+ (function(SyntaxKind) {
1288
+ SyntaxKind[SyntaxKind["OpenBraceToken"] = 1] = "OpenBraceToken";
1289
+ SyntaxKind[SyntaxKind["CloseBraceToken"] = 2] = "CloseBraceToken";
1290
+ SyntaxKind[SyntaxKind["OpenBracketToken"] = 3] = "OpenBracketToken";
1291
+ SyntaxKind[SyntaxKind["CloseBracketToken"] = 4] = "CloseBracketToken";
1292
+ SyntaxKind[SyntaxKind["CommaToken"] = 5] = "CommaToken";
1293
+ SyntaxKind[SyntaxKind["ColonToken"] = 6] = "ColonToken";
1294
+ SyntaxKind[SyntaxKind["NullKeyword"] = 7] = "NullKeyword";
1295
+ SyntaxKind[SyntaxKind["TrueKeyword"] = 8] = "TrueKeyword";
1296
+ SyntaxKind[SyntaxKind["FalseKeyword"] = 9] = "FalseKeyword";
1297
+ SyntaxKind[SyntaxKind["StringLiteral"] = 10] = "StringLiteral";
1298
+ SyntaxKind[SyntaxKind["NumericLiteral"] = 11] = "NumericLiteral";
1299
+ SyntaxKind[SyntaxKind["LineCommentTrivia"] = 12] = "LineCommentTrivia";
1300
+ SyntaxKind[SyntaxKind["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
1301
+ SyntaxKind[SyntaxKind["LineBreakTrivia"] = 14] = "LineBreakTrivia";
1302
+ SyntaxKind[SyntaxKind["Trivia"] = 15] = "Trivia";
1303
+ SyntaxKind[SyntaxKind["Unknown"] = 16] = "Unknown";
1304
+ SyntaxKind[SyntaxKind["EOF"] = 17] = "EOF";
1305
+ })(SyntaxKind || (SyntaxKind = {}));
1306
+ var parse2 = parse;
1307
+ var parseTree = parseTree2;
1308
+ var findNodeAtLocation = findNodeAtLocation2;
1309
+ var getNodeValue = getNodeValue2;
1310
+ var ParseErrorCode;
1311
+ (function(ParseErrorCode) {
1312
+ ParseErrorCode[ParseErrorCode["InvalidSymbol"] = 1] = "InvalidSymbol";
1313
+ ParseErrorCode[ParseErrorCode["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
1314
+ ParseErrorCode[ParseErrorCode["PropertyNameExpected"] = 3] = "PropertyNameExpected";
1315
+ ParseErrorCode[ParseErrorCode["ValueExpected"] = 4] = "ValueExpected";
1316
+ ParseErrorCode[ParseErrorCode["ColonExpected"] = 5] = "ColonExpected";
1317
+ ParseErrorCode[ParseErrorCode["CommaExpected"] = 6] = "CommaExpected";
1318
+ ParseErrorCode[ParseErrorCode["CloseBraceExpected"] = 7] = "CloseBraceExpected";
1319
+ ParseErrorCode[ParseErrorCode["CloseBracketExpected"] = 8] = "CloseBracketExpected";
1320
+ ParseErrorCode[ParseErrorCode["EndOfFileExpected"] = 9] = "EndOfFileExpected";
1321
+ ParseErrorCode[ParseErrorCode["InvalidCommentToken"] = 10] = "InvalidCommentToken";
1322
+ ParseErrorCode[ParseErrorCode["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
1323
+ ParseErrorCode[ParseErrorCode["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
1324
+ ParseErrorCode[ParseErrorCode["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
1325
+ ParseErrorCode[ParseErrorCode["InvalidUnicode"] = 14] = "InvalidUnicode";
1326
+ ParseErrorCode[ParseErrorCode["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
1327
+ ParseErrorCode[ParseErrorCode["InvalidCharacter"] = 16] = "InvalidCharacter";
1328
+ })(ParseErrorCode || (ParseErrorCode = {}));
1329
+ function printParseErrorCode(code) {
1330
+ switch (code) {
1331
+ case 1:
1332
+ return "InvalidSymbol";
1333
+ case 2:
1334
+ return "InvalidNumberFormat";
1335
+ case 3:
1336
+ return "PropertyNameExpected";
1337
+ case 4:
1338
+ return "ValueExpected";
1339
+ case 5:
1340
+ return "ColonExpected";
1341
+ case 6:
1342
+ return "CommaExpected";
1343
+ case 7:
1344
+ return "CloseBraceExpected";
1345
+ case 8:
1346
+ return "CloseBracketExpected";
1347
+ case 9:
1348
+ return "EndOfFileExpected";
1349
+ case 10:
1350
+ return "InvalidCommentToken";
1351
+ case 11:
1352
+ return "UnexpectedEndOfComment";
1353
+ case 12:
1354
+ return "UnexpectedEndOfString";
1355
+ case 13:
1356
+ return "UnexpectedEndOfNumber";
1357
+ case 14:
1358
+ return "InvalidUnicode";
1359
+ case 15:
1360
+ return "InvalidEscapeCharacter";
1361
+ case 16:
1362
+ return "InvalidCharacter";
1363
+ }
1364
+ return "<unknown ParseErrorCode>";
1365
+ }
1366
+ function modify(text, path, value, options) {
1367
+ return setProperty(text, path, value, options);
1368
+ }
1369
+ function applyEdits(text, edits) {
1370
+ let sortedEdits = edits.slice(0).sort((a, b) => {
1371
+ const diff = a.offset - b.offset;
1372
+ if (diff === 0) {
1373
+ return a.length - b.length;
1374
+ }
1375
+ return diff;
1376
+ });
1377
+ let lastModifiedOffset = text.length;
1378
+ for (let i = sortedEdits.length - 1;i >= 0; i--) {
1379
+ let e = sortedEdits[i];
1380
+ if (e.offset + e.length <= lastModifiedOffset) {
1381
+ text = applyEdit(text, e);
1382
+ } else {
1383
+ throw new Error("Overlapping edit");
1384
+ }
1385
+ lastModifiedOffset = e.offset;
1386
+ }
1387
+ return text;
1388
+ }
1389
+
1390
+ // src/shared/jsonc-parser.ts
1391
+ function stripJsonComments(content) {
1392
+ let result = "";
1393
+ let inString = false;
1394
+ let escaped = false;
1395
+ let inLineComment = false;
1396
+ let inBlockComment = false;
1397
+ for (let index = 0;index < content.length; index += 1) {
1398
+ const char = content[index];
1399
+ const next = content[index + 1];
1400
+ if (inLineComment) {
1401
+ if (char === `
1402
+ `) {
1403
+ inLineComment = false;
1404
+ result += char;
1405
+ }
1406
+ continue;
1407
+ }
1408
+ if (inBlockComment) {
1409
+ if (char === "*" && next === "/") {
1410
+ inBlockComment = false;
1411
+ index += 1;
1412
+ }
1413
+ continue;
1414
+ }
1415
+ if (inString) {
1416
+ result += char;
1417
+ if (escaped) {
1418
+ escaped = false;
1419
+ } else if (char === "\\") {
1420
+ escaped = true;
1421
+ } else if (char === '"') {
1422
+ inString = false;
1423
+ }
1424
+ continue;
1425
+ }
1426
+ if (char === '"') {
1427
+ inString = true;
1428
+ result += char;
1429
+ continue;
1430
+ }
1431
+ if (char === "/" && next === "/") {
1432
+ inLineComment = true;
1433
+ index += 1;
1434
+ continue;
1435
+ }
1436
+ if (char === "/" && next === "*") {
1437
+ inBlockComment = true;
1438
+ index += 1;
1439
+ continue;
1440
+ }
1441
+ result += char;
1442
+ }
1443
+ return result;
1444
+ }
1445
+ function stripTrailingCommas(content) {
1446
+ let result = "";
1447
+ let inString = false;
1448
+ let escaped = false;
1449
+ for (let index = 0;index < content.length; index += 1) {
1450
+ const char = content[index];
1451
+ if (inString) {
1452
+ result += char;
1453
+ if (escaped) {
1454
+ escaped = false;
1455
+ } else if (char === "\\") {
1456
+ escaped = true;
1457
+ } else if (char === '"') {
1458
+ inString = false;
1459
+ }
1460
+ continue;
1461
+ }
1462
+ if (char === '"') {
1463
+ inString = true;
1464
+ result += char;
1465
+ continue;
1466
+ }
1467
+ if (char === ",") {
1468
+ let lookahead = index + 1;
1469
+ while (lookahead < content.length && /\s/.test(content[lookahead] ?? "")) {
1470
+ lookahead += 1;
1471
+ }
1472
+ const next = content[lookahead];
1473
+ if (next === "}" || next === "]") {
1474
+ continue;
1475
+ }
1476
+ }
1477
+ result += char;
1478
+ }
1479
+ return result;
1480
+ }
1481
+ var PROTOTYPE_POLLUTION_KEYS = new Set(["__proto__", "constructor", "prototype"]);
1482
+ function isPrototypePollutionKey(key) {
1483
+ return PROTOTYPE_POLLUTION_KEYS.has(key);
1484
+ }
1485
+ function sanitizeParsedJson(value, options = {}, path = []) {
1486
+ if (Array.isArray(value)) {
1487
+ return value.map((entry, index) => sanitizeParsedJson(entry, options, [...path, index]));
1488
+ }
1489
+ if (value === null || typeof value !== "object")
1490
+ return value;
1491
+ const source = value;
1492
+ const sourcePrototype = Object.getPrototypeOf(source);
1493
+ if (sourcePrototype !== null && sourcePrototype !== Object.prototype) {
1494
+ options.onRejectedKey?.([...path, "__proto__"]);
1495
+ }
1496
+ const sanitized = {};
1497
+ for (const key of Object.keys(source)) {
1498
+ if (isPrototypePollutionKey(key)) {
1499
+ options.onRejectedKey?.([...path, key]);
1500
+ continue;
1501
+ }
1502
+ Object.defineProperty(sanitized, key, {
1503
+ value: sanitizeParsedJson(source[key], options, [...path, key]),
1504
+ enumerable: true,
1505
+ configurable: true,
1506
+ writable: true
1507
+ });
1508
+ }
1509
+ return sanitized;
1510
+ }
1511
+ function lineAndColumnAt(content, offset) {
1512
+ const before = content.slice(0, Math.max(0, offset));
1513
+ const lines = before.split(/\r?\n/);
1514
+ return { line: lines.length, column: (lines.at(-1)?.length ?? 0) + 1 };
1515
+ }
1516
+ function parseIssue(content, error) {
1517
+ const location = lineAndColumnAt(content, error.offset);
1518
+ const code = printParseErrorCode(error.error);
1519
+ const message = code.replace(/([a-z])([A-Z])/g, "$1 $2").toLowerCase();
1520
+ return {
1521
+ ...location,
1522
+ offset: error.offset,
1523
+ length: error.length,
1524
+ message
1525
+ };
1526
+ }
1527
+ function normalizeJsoncParserObjects(value, options, path = []) {
1528
+ if (Array.isArray(value)) {
1529
+ return value.map((entry, index) => normalizeJsoncParserObjects(entry, options, [...path, String(index)]));
1530
+ }
1531
+ if (value === null || typeof value !== "object")
1532
+ return value;
1533
+ const prototype = Object.getPrototypeOf(value);
1534
+ if (prototype !== Object.prototype && prototype !== null) {
1535
+ options.onRejectedKey?.([...path, "__proto__"]);
1536
+ }
1537
+ const normalized = {};
1538
+ for (const [key, entry] of Object.entries(value)) {
1539
+ Object.defineProperty(normalized, key, {
1540
+ configurable: true,
1541
+ enumerable: true,
1542
+ writable: true,
1543
+ value: normalizeJsoncParserObjects(entry, options, [...path, key])
1544
+ });
1545
+ }
1546
+ return normalized;
1547
+ }
1548
+ function parseJsoncRecovering(content, options = {}) {
1549
+ const errors = [];
1550
+ const parsed = parse2(content, errors, {
1551
+ allowTrailingComma: true,
1552
+ disallowComments: false,
1553
+ allowEmptyContent: false
1554
+ });
1555
+ return {
1556
+ value: sanitizeParsedJson(normalizeJsoncParserObjects(parsed, options), options),
1557
+ issues: errors.map((error) => parseIssue(content, error))
1558
+ };
1559
+ }
1560
+ function parseJsonc(content, options = {}) {
1561
+ const normalized = stripTrailingCommas(stripJsonComments(content));
1562
+ return sanitizeParsedJson(JSON.parse(normalized), options);
1563
+ }
1564
+ function readJsoncFile(filePath) {
1565
+ try {
1566
+ return parseJsonc(readFileSync(filePath, "utf-8"));
1567
+ } catch (_error) {
1568
+ return null;
1569
+ }
1570
+ }
1571
+ function detectConfigFile(basePath) {
1572
+ const jsoncPath = `${basePath}.jsonc`;
1573
+ const jsonPath = `${basePath}.json`;
1574
+ if (existsSync(jsoncPath)) {
1575
+ return { format: "jsonc", path: jsoncPath };
1576
+ }
1577
+ if (existsSync(jsonPath)) {
1578
+ return { format: "json", path: jsonPath };
1579
+ }
1580
+ return { format: "none", path: jsoncPath };
1581
+ }
1582
+
1583
+ export { createScanner, parseTree, findNodeAtLocation, getNodeValue, modify, applyEdits, stripJsonComments, isPrototypePollutionKey, parseJsoncRecovering, parseJsonc, readJsoncFile, detectConfigFile };