causoryn 0.0.0-stage → 0.2.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 (197) hide show
  1. package/.claude-plugin/plugin.json +36 -0
  2. package/.codex-plugin/mcp.json +19 -0
  3. package/.codex-plugin/plugin.json +38 -0
  4. package/.zcode-plugin/plugin.json +42 -0
  5. package/LICENSE +21 -0
  6. package/README.md +171 -2
  7. package/THIRD-PARTY-NOTICES.md +443 -0
  8. package/dist/bundle-manifest.json +39 -0
  9. package/dist/cli.d.ts +3 -0
  10. package/dist/cli.js +253 -0
  11. package/dist/doctor.d.ts +13 -0
  12. package/dist/doctor.js +507 -0
  13. package/dist/index.d.ts +10 -0
  14. package/dist/index.js +10 -0
  15. package/dist/mcp-server.mjs +288477 -0
  16. package/dist/mcp-server.mjs.LEGAL.txt +17 -0
  17. package/dist/node_modules/better-sqlite3/LICENSE +21 -0
  18. package/dist/node_modules/better-sqlite3/lib/binding.js +62 -0
  19. package/dist/node_modules/better-sqlite3/lib/darwin-arm64.js +3 -0
  20. package/dist/node_modules/better-sqlite3/lib/darwin-x64.js +3 -0
  21. package/dist/node_modules/better-sqlite3/lib/database.js +109 -0
  22. package/dist/node_modules/better-sqlite3/lib/index.js +3 -0
  23. package/dist/node_modules/better-sqlite3/lib/linux-arm64.js +3 -0
  24. package/dist/node_modules/better-sqlite3/lib/linux-x64.js +3 -0
  25. package/dist/node_modules/better-sqlite3/lib/linuxmusl-arm64.js +4 -0
  26. package/dist/node_modules/better-sqlite3/lib/linuxmusl-x64.js +4 -0
  27. package/dist/node_modules/better-sqlite3/lib/methods/aggregate.js +43 -0
  28. package/dist/node_modules/better-sqlite3/lib/methods/backup.js +67 -0
  29. package/dist/node_modules/better-sqlite3/lib/methods/explain.js +9 -0
  30. package/dist/node_modules/better-sqlite3/lib/methods/function.js +31 -0
  31. package/dist/node_modules/better-sqlite3/lib/methods/inspect.js +7 -0
  32. package/dist/node_modules/better-sqlite3/lib/methods/pragma.js +12 -0
  33. package/dist/node_modules/better-sqlite3/lib/methods/serialize.js +16 -0
  34. package/dist/node_modules/better-sqlite3/lib/methods/table.js +195 -0
  35. package/dist/node_modules/better-sqlite3/lib/methods/transaction.js +78 -0
  36. package/dist/node_modules/better-sqlite3/lib/methods/wrappers.js +54 -0
  37. package/dist/node_modules/better-sqlite3/lib/sqlite-error.js +25 -0
  38. package/dist/node_modules/better-sqlite3/lib/util.js +12 -0
  39. package/dist/node_modules/better-sqlite3/lib/win32-arm64.js +3 -0
  40. package/dist/node_modules/better-sqlite3/lib/win32-x64.js +3 -0
  41. package/dist/node_modules/better-sqlite3/package.json +67 -0
  42. package/dist/node_modules/better-sqlite3/prebuilds/darwin-arm64.node +0 -0
  43. package/dist/node_modules/better-sqlite3/prebuilds/darwin-x64.node +0 -0
  44. package/dist/node_modules/better-sqlite3/prebuilds/linux-arm64.node +0 -0
  45. package/dist/node_modules/better-sqlite3/prebuilds/linux-x64.node +0 -0
  46. package/dist/node_modules/better-sqlite3/prebuilds/linuxmusl-arm64.node +0 -0
  47. package/dist/node_modules/better-sqlite3/prebuilds/linuxmusl-x64.node +0 -0
  48. package/dist/node_modules/better-sqlite3/prebuilds/win32-arm64.node +0 -0
  49. package/dist/node_modules/better-sqlite3/prebuilds/win32-x64.node +0 -0
  50. package/dist/runtime-stage.d.ts +8 -0
  51. package/dist/runtime-stage.js +159 -0
  52. package/dist/setup.d.ts +15 -0
  53. package/dist/setup.js +735 -0
  54. package/dist/toml-patch.d.ts +10 -0
  55. package/dist/toml-patch.js +587 -0
  56. package/dist/types.d.ts +144 -0
  57. package/dist/types.js +35 -0
  58. package/dist/typescript-lib/lib.d.ts +22 -0
  59. package/dist/typescript-lib/lib.decorators.d.ts +384 -0
  60. package/dist/typescript-lib/lib.decorators.legacy.d.ts +22 -0
  61. package/dist/typescript-lib/lib.dom.asynciterable.d.ts +41 -0
  62. package/dist/typescript-lib/lib.dom.d.ts +39429 -0
  63. package/dist/typescript-lib/lib.dom.iterable.d.ts +571 -0
  64. package/dist/typescript-lib/lib.es2015.collection.d.ts +147 -0
  65. package/dist/typescript-lib/lib.es2015.core.d.ts +597 -0
  66. package/dist/typescript-lib/lib.es2015.d.ts +28 -0
  67. package/dist/typescript-lib/lib.es2015.generator.d.ts +77 -0
  68. package/dist/typescript-lib/lib.es2015.iterable.d.ts +605 -0
  69. package/dist/typescript-lib/lib.es2015.promise.d.ts +81 -0
  70. package/dist/typescript-lib/lib.es2015.proxy.d.ts +128 -0
  71. package/dist/typescript-lib/lib.es2015.reflect.d.ts +144 -0
  72. package/dist/typescript-lib/lib.es2015.symbol.d.ts +46 -0
  73. package/dist/typescript-lib/lib.es2015.symbol.wellknown.d.ts +326 -0
  74. package/dist/typescript-lib/lib.es2016.array.include.d.ts +116 -0
  75. package/dist/typescript-lib/lib.es2016.d.ts +21 -0
  76. package/dist/typescript-lib/lib.es2016.full.d.ts +23 -0
  77. package/dist/typescript-lib/lib.es2016.intl.d.ts +31 -0
  78. package/dist/typescript-lib/lib.es2017.arraybuffer.d.ts +21 -0
  79. package/dist/typescript-lib/lib.es2017.d.ts +26 -0
  80. package/dist/typescript-lib/lib.es2017.date.d.ts +31 -0
  81. package/dist/typescript-lib/lib.es2017.full.d.ts +23 -0
  82. package/dist/typescript-lib/lib.es2017.intl.d.ts +44 -0
  83. package/dist/typescript-lib/lib.es2017.object.d.ts +49 -0
  84. package/dist/typescript-lib/lib.es2017.sharedmemory.d.ts +135 -0
  85. package/dist/typescript-lib/lib.es2017.string.d.ts +45 -0
  86. package/dist/typescript-lib/lib.es2017.typedarrays.d.ts +53 -0
  87. package/dist/typescript-lib/lib.es2018.asyncgenerator.d.ts +77 -0
  88. package/dist/typescript-lib/lib.es2018.asynciterable.d.ts +53 -0
  89. package/dist/typescript-lib/lib.es2018.d.ts +24 -0
  90. package/dist/typescript-lib/lib.es2018.full.d.ts +24 -0
  91. package/dist/typescript-lib/lib.es2018.intl.d.ts +83 -0
  92. package/dist/typescript-lib/lib.es2018.promise.d.ts +30 -0
  93. package/dist/typescript-lib/lib.es2018.regexp.d.ts +37 -0
  94. package/dist/typescript-lib/lib.es2019.array.d.ts +79 -0
  95. package/dist/typescript-lib/lib.es2019.d.ts +24 -0
  96. package/dist/typescript-lib/lib.es2019.full.d.ts +24 -0
  97. package/dist/typescript-lib/lib.es2019.intl.d.ts +23 -0
  98. package/dist/typescript-lib/lib.es2019.object.d.ts +33 -0
  99. package/dist/typescript-lib/lib.es2019.string.d.ts +37 -0
  100. package/dist/typescript-lib/lib.es2019.symbol.d.ts +24 -0
  101. package/dist/typescript-lib/lib.es2020.bigint.d.ts +765 -0
  102. package/dist/typescript-lib/lib.es2020.d.ts +27 -0
  103. package/dist/typescript-lib/lib.es2020.date.d.ts +42 -0
  104. package/dist/typescript-lib/lib.es2020.full.d.ts +24 -0
  105. package/dist/typescript-lib/lib.es2020.intl.d.ts +474 -0
  106. package/dist/typescript-lib/lib.es2020.number.d.ts +28 -0
  107. package/dist/typescript-lib/lib.es2020.promise.d.ts +47 -0
  108. package/dist/typescript-lib/lib.es2020.sharedmemory.d.ts +99 -0
  109. package/dist/typescript-lib/lib.es2020.string.d.ts +44 -0
  110. package/dist/typescript-lib/lib.es2020.symbol.wellknown.d.ts +41 -0
  111. package/dist/typescript-lib/lib.es2021.d.ts +23 -0
  112. package/dist/typescript-lib/lib.es2021.full.d.ts +24 -0
  113. package/dist/typescript-lib/lib.es2021.intl.d.ts +166 -0
  114. package/dist/typescript-lib/lib.es2021.promise.d.ts +48 -0
  115. package/dist/typescript-lib/lib.es2021.string.d.ts +33 -0
  116. package/dist/typescript-lib/lib.es2021.weakref.d.ts +78 -0
  117. package/dist/typescript-lib/lib.es2022.array.d.ts +121 -0
  118. package/dist/typescript-lib/lib.es2022.d.ts +25 -0
  119. package/dist/typescript-lib/lib.es2022.error.d.ts +75 -0
  120. package/dist/typescript-lib/lib.es2022.full.d.ts +24 -0
  121. package/dist/typescript-lib/lib.es2022.intl.d.ts +145 -0
  122. package/dist/typescript-lib/lib.es2022.object.d.ts +26 -0
  123. package/dist/typescript-lib/lib.es2022.regexp.d.ts +39 -0
  124. package/dist/typescript-lib/lib.es2022.string.d.ts +25 -0
  125. package/dist/typescript-lib/lib.es2023.array.d.ts +924 -0
  126. package/dist/typescript-lib/lib.es2023.collection.d.ts +21 -0
  127. package/dist/typescript-lib/lib.es2023.d.ts +22 -0
  128. package/dist/typescript-lib/lib.es2023.full.d.ts +24 -0
  129. package/dist/typescript-lib/lib.es2023.intl.d.ts +56 -0
  130. package/dist/typescript-lib/lib.es2024.arraybuffer.d.ts +65 -0
  131. package/dist/typescript-lib/lib.es2024.collection.d.ts +29 -0
  132. package/dist/typescript-lib/lib.es2024.d.ts +26 -0
  133. package/dist/typescript-lib/lib.es2024.full.d.ts +24 -0
  134. package/dist/typescript-lib/lib.es2024.object.d.ts +29 -0
  135. package/dist/typescript-lib/lib.es2024.promise.d.ts +35 -0
  136. package/dist/typescript-lib/lib.es2024.regexp.d.ts +25 -0
  137. package/dist/typescript-lib/lib.es2024.sharedmemory.d.ts +68 -0
  138. package/dist/typescript-lib/lib.es2024.string.d.ts +29 -0
  139. package/dist/typescript-lib/lib.es5.d.ts +4601 -0
  140. package/dist/typescript-lib/lib.es6.d.ts +23 -0
  141. package/dist/typescript-lib/lib.esnext.array.d.ts +35 -0
  142. package/dist/typescript-lib/lib.esnext.collection.d.ts +96 -0
  143. package/dist/typescript-lib/lib.esnext.d.ts +29 -0
  144. package/dist/typescript-lib/lib.esnext.decorators.d.ts +28 -0
  145. package/dist/typescript-lib/lib.esnext.disposable.d.ts +193 -0
  146. package/dist/typescript-lib/lib.esnext.error.d.ts +24 -0
  147. package/dist/typescript-lib/lib.esnext.float16.d.ts +445 -0
  148. package/dist/typescript-lib/lib.esnext.full.d.ts +24 -0
  149. package/dist/typescript-lib/lib.esnext.intl.d.ts +21 -0
  150. package/dist/typescript-lib/lib.esnext.iterator.d.ts +148 -0
  151. package/dist/typescript-lib/lib.esnext.promise.d.ts +34 -0
  152. package/dist/typescript-lib/lib.esnext.sharedmemory.d.ts +25 -0
  153. package/dist/typescript-lib/lib.scripthost.d.ts +322 -0
  154. package/dist/typescript-lib/lib.webworker.asynciterable.d.ts +41 -0
  155. package/dist/typescript-lib/lib.webworker.d.ts +13150 -0
  156. package/dist/typescript-lib/lib.webworker.importscripts.d.ts +23 -0
  157. package/dist/typescript-lib/lib.webworker.iterable.d.ts +340 -0
  158. package/licenses/Apache-2.0.txt +55 -0
  159. package/licenses/TypeScript-ThirdPartyNoticeText.txt +193 -0
  160. package/licenses/better-sqlite3-LICENSE.txt +21 -0
  161. package/mcp_config.json +16 -0
  162. package/native/go-worker/PROTOCOL.md +316 -0
  163. package/native/go-worker/cmd/worker/main.go +440 -0
  164. package/native/go-worker/go.mod +3 -0
  165. package/native/go-worker/internal/analyze/analyze.go +820 -0
  166. package/native/go-worker/internal/analyze/model.go +182 -0
  167. package/native/go-worker/internal/analyze/routes.go +181 -0
  168. package/native/python-worker/PROTOCOL.md +342 -0
  169. package/native/python-worker/worker.py +1190 -0
  170. package/native/roslyn-worker/Causoryn.RoslynWorker.csproj +40 -0
  171. package/native/roslyn-worker/Causoryn.RoslynWorker.deps.json +59 -0
  172. package/native/roslyn-worker/Causoryn.RoslynWorker.dll +0 -0
  173. package/native/roslyn-worker/Causoryn.RoslynWorker.runtimeconfig.json +13 -0
  174. package/native/roslyn-worker/Microsoft.CodeAnalysis.CSharp.dll +0 -0
  175. package/native/roslyn-worker/Microsoft.CodeAnalysis.dll +0 -0
  176. package/native/roslyn-worker/PROTOCOL.md +285 -0
  177. package/native/roslyn-worker/Program.cs +249 -0
  178. package/native/roslyn-worker/Protocol.cs +397 -0
  179. package/native/roslyn-worker/ReferenceResolver.cs +235 -0
  180. package/native/roslyn-worker/WorkerAnalyzer.cs +1669 -0
  181. package/native/roslyn-worker/packages.lock.json +30 -0
  182. package/native/rust-worker/Cargo.lock +107 -0
  183. package/native/rust-worker/Cargo.toml +23 -0
  184. package/native/rust-worker/PROTOCOL.md +294 -0
  185. package/native/rust-worker/src/analyzer.rs +1209 -0
  186. package/native/rust-worker/src/main.rs +127 -0
  187. package/native/rust-worker/src/protocol.rs +284 -0
  188. package/native/rust-worker/src/sha256.rs +136 -0
  189. package/package.json +71 -4
  190. package/plugin.json +17 -0
  191. package/scripts/causoryn.mjs +40 -0
  192. package/scripts/lib/node-version-guard.mjs +24 -0
  193. package/scripts/plugin-mcp-launcher.mjs +111 -0
  194. package/skills/causoryn/SKILL.md +53 -0
  195. package/skills/map-system/SKILL.md +69 -0
  196. package/skills/preflight-change/SKILL.md +38 -0
  197. package/skills/verify-change/SKILL.md +31 -0
@@ -0,0 +1,10 @@
1
+ import { type CodexMcpServerSpec, type ParsedCodexMcpServer } from "./types.js";
2
+ export declare function formatTomlBasicString(value: string): string;
3
+ export declare function validateTomlStructure(rawToml: string): void;
4
+ export declare function upsertCodexMcpServer(existingToml: string, spec: CodexMcpServerSpec): string;
5
+ export declare function removeCodexMcpServer(existingToml: string): {
6
+ readonly content: string;
7
+ readonly removed: boolean;
8
+ };
9
+ export declare function readCodexMcpServer(rawToml: string): ParsedCodexMcpServer | null;
10
+ //# sourceMappingURL=toml-patch.d.ts.map
@@ -0,0 +1,587 @@
1
+ import { CausorynCliError, } from "./types.js";
2
+ const DEFAULT_STARTUP_TIMEOUT_SEC = 30;
3
+ const CAUSORYN_TABLE = "mcp_servers.causoryn";
4
+ const CAUSORYN_ENV_TABLE = "mcp_servers.causoryn.env";
5
+ export function formatTomlBasicString(value) {
6
+ let out = '"';
7
+ for (let i = 0; i < value.length; i += 1) {
8
+ const ch = value[i] ?? "";
9
+ const code = value.charCodeAt(i);
10
+ if (ch === "\\") {
11
+ out += "\\\\";
12
+ }
13
+ else if (ch === '"') {
14
+ out += '\\"';
15
+ }
16
+ else if (ch === "\b") {
17
+ out += "\\b";
18
+ }
19
+ else if (ch === "\f") {
20
+ out += "\\f";
21
+ }
22
+ else if (ch === "\n") {
23
+ out += "\\n";
24
+ }
25
+ else if (ch === "\r") {
26
+ out += "\\r";
27
+ }
28
+ else if (ch === "\t") {
29
+ out += "\\t";
30
+ }
31
+ else if (code < 0x20 || code === 0x7f) {
32
+ out += `\\u${code.toString(16).padStart(4, "0")}`;
33
+ }
34
+ else {
35
+ out += ch;
36
+ }
37
+ }
38
+ out += '"';
39
+ return out;
40
+ }
41
+ function unescapeTomlString(raw) {
42
+ const trimmed = raw.trim();
43
+ if (trimmed.startsWith("'") && trimmed.endsWith("'") && trimmed.length >= 2) {
44
+ return trimmed.slice(1, -1);
45
+ }
46
+ if (!trimmed.startsWith('"') || !trimmed.endsWith('"') || trimmed.length < 2) {
47
+ throw new CausorynCliError("cli/malformed-toml", `Geçersiz TOML string değeri: ${raw}`);
48
+ }
49
+ const body = trimmed.slice(1, -1);
50
+ let result = "";
51
+ for (let i = 0; i < body.length; i += 1) {
52
+ const ch = body[i] ?? "";
53
+ if (ch !== "\\") {
54
+ result += ch;
55
+ continue;
56
+ }
57
+ i += 1;
58
+ if (i >= body.length) {
59
+ throw new CausorynCliError("cli/malformed-toml", "Kapanmamış TOML kaçış dizisi");
60
+ }
61
+ const esc = body[i] ?? "";
62
+ switch (esc) {
63
+ case "\\":
64
+ result += "\\";
65
+ break;
66
+ case '"':
67
+ result += '"';
68
+ break;
69
+ case "n":
70
+ result += "\n";
71
+ break;
72
+ case "r":
73
+ result += "\r";
74
+ break;
75
+ case "t":
76
+ result += "\t";
77
+ break;
78
+ case "b":
79
+ result += "\b";
80
+ break;
81
+ case "f":
82
+ result += "\f";
83
+ break;
84
+ case "u": {
85
+ const hex = body.slice(i + 1, i + 5);
86
+ if (!/^[0-9a-fA-F]{4}$/.test(hex)) {
87
+ throw new CausorynCliError("cli/malformed-toml", `Geçersiz \\u kaçışı: ${hex}`);
88
+ }
89
+ result += String.fromCharCode(Number.parseInt(hex, 16));
90
+ i += 4;
91
+ break;
92
+ }
93
+ default:
94
+ result += esc;
95
+ break;
96
+ }
97
+ }
98
+ return result;
99
+ }
100
+ /**
101
+ * Tek satırı tarayarak tırnak/parantez dengesini doğrular ve yorum öncesi
102
+ * aktif içeriği döndürür.
103
+ */
104
+ function scanTomlLine(line, lineNumber, state) {
105
+ let i = 0;
106
+ let inBasic = false;
107
+ let inLiteral = false;
108
+ let codeEnd = line.length;
109
+ while (i < line.length) {
110
+ if (state.inMultilineBasic) {
111
+ if (line.startsWith('"""', i)) {
112
+ state.inMultilineBasic = false;
113
+ i += 3;
114
+ continue;
115
+ }
116
+ if (line[i] === "\\") {
117
+ i += 2;
118
+ continue;
119
+ }
120
+ i += 1;
121
+ continue;
122
+ }
123
+ if (state.inMultilineLiteral) {
124
+ if (line.startsWith("'''", i)) {
125
+ state.inMultilineLiteral = false;
126
+ i += 3;
127
+ continue;
128
+ }
129
+ i += 1;
130
+ continue;
131
+ }
132
+ if (inBasic) {
133
+ if (line[i] === "\\") {
134
+ i += 2;
135
+ continue;
136
+ }
137
+ if (line[i] === '"') {
138
+ inBasic = false;
139
+ }
140
+ i += 1;
141
+ continue;
142
+ }
143
+ if (inLiteral) {
144
+ if (line[i] === "'") {
145
+ inLiteral = false;
146
+ }
147
+ i += 1;
148
+ continue;
149
+ }
150
+ if (line.startsWith('"""', i)) {
151
+ state.inMultilineBasic = true;
152
+ i += 3;
153
+ continue;
154
+ }
155
+ if (line.startsWith("'''", i)) {
156
+ state.inMultilineLiteral = true;
157
+ i += 3;
158
+ continue;
159
+ }
160
+ const ch = line[i] ?? "";
161
+ if (ch === '"') {
162
+ inBasic = true;
163
+ i += 1;
164
+ continue;
165
+ }
166
+ if (ch === "'") {
167
+ inLiteral = true;
168
+ i += 1;
169
+ continue;
170
+ }
171
+ if (ch === "#") {
172
+ codeEnd = i;
173
+ break;
174
+ }
175
+ if (ch === "[") {
176
+ state.bracketDepth += 1;
177
+ }
178
+ else if (ch === "]") {
179
+ state.bracketDepth -= 1;
180
+ if (state.bracketDepth < 0) {
181
+ throw new CausorynCliError("cli/malformed-toml", `Bozuk TOML (satır ${String(lineNumber)}): eşleşmeyen ']' karakteri`);
182
+ }
183
+ }
184
+ else if (ch === "{") {
185
+ state.braceDepth += 1;
186
+ }
187
+ else if (ch === "}") {
188
+ state.braceDepth -= 1;
189
+ if (state.braceDepth < 0) {
190
+ throw new CausorynCliError("cli/malformed-toml", `Bozuk TOML (satır ${String(lineNumber)}): eşleşmeyen '}' karakteri`);
191
+ }
192
+ }
193
+ i += 1;
194
+ }
195
+ if (inBasic || inLiteral) {
196
+ throw new CausorynCliError("cli/malformed-toml", `Bozuk TOML (satır ${String(lineNumber)}): kapanmamış string tırnağı`);
197
+ }
198
+ return { effectiveCode: line.slice(0, codeEnd).trim() };
199
+ }
200
+ function parseTableHeaderCode(effectiveCode, lineNumber) {
201
+ if (!effectiveCode.startsWith("[")) {
202
+ return null;
203
+ }
204
+ if (effectiveCode.startsWith("[[")) {
205
+ if (!effectiveCode.endsWith("]]")) {
206
+ throw new CausorynCliError("cli/malformed-toml", `Bozuk TOML (satır ${String(lineNumber)}): kapanmamış dizi-tablo başlığı`);
207
+ }
208
+ const inner = effectiveCode.slice(2, -2).trim();
209
+ if (inner.length === 0 || inner.includes("[") || inner.includes("]")) {
210
+ throw new CausorynCliError("cli/malformed-toml", `Bozuk TOML (satır ${String(lineNumber)}): geçersiz dizi-tablo başlığı`);
211
+ }
212
+ return `[${inner}]`;
213
+ }
214
+ if (!effectiveCode.endsWith("]")) {
215
+ throw new CausorynCliError("cli/malformed-toml", `Bozuk TOML (satır ${String(lineNumber)}): kapanmamış tablo başlığı`);
216
+ }
217
+ const inner = effectiveCode.slice(1, -1).trim();
218
+ if (inner.length === 0 || inner.includes("[") || inner.includes("]")) {
219
+ throw new CausorynCliError("cli/malformed-toml", `Bozuk TOML (satır ${String(lineNumber)}): geçersiz tablo başlığı`);
220
+ }
221
+ return inner;
222
+ }
223
+ function findTopLevelEquals(code) {
224
+ let inBasic = false;
225
+ let inLiteral = false;
226
+ for (let i = 0; i < code.length; i += 1) {
227
+ const ch = code[i] ?? "";
228
+ if (inBasic) {
229
+ if (ch === "\\") {
230
+ i += 1;
231
+ continue;
232
+ }
233
+ if (ch === '"')
234
+ inBasic = false;
235
+ continue;
236
+ }
237
+ if (inLiteral) {
238
+ if (ch === "'")
239
+ inLiteral = false;
240
+ continue;
241
+ }
242
+ if (ch === '"') {
243
+ inBasic = true;
244
+ continue;
245
+ }
246
+ if (ch === "'") {
247
+ inLiteral = true;
248
+ continue;
249
+ }
250
+ if (ch === "=")
251
+ return i;
252
+ }
253
+ return -1;
254
+ }
255
+ function parseTomlDocument(rawToml) {
256
+ const withoutBom = rawToml.startsWith("\uFEFF") ? rawToml.slice(1) : rawToml;
257
+ const eol = withoutBom.includes("\r\n") ? "\r\n" : "\n";
258
+ const rawLines = withoutBom.length === 0 ? [] : withoutBom.split(/\r?\n/);
259
+ const state = {
260
+ inMultilineBasic: false,
261
+ inMultilineLiteral: false,
262
+ bracketDepth: 0,
263
+ braceDepth: 0,
264
+ };
265
+ const builders = [{ header: null, lines: [] }];
266
+ const seenStandardTables = new Set();
267
+ for (let idx = 0; idx < rawLines.length; idx += 1) {
268
+ const line = rawLines[idx] ?? "";
269
+ const lineNumber = idx + 1;
270
+ const wasContinuation = state.inMultilineBasic ||
271
+ state.inMultilineLiteral ||
272
+ state.bracketDepth > 0 ||
273
+ state.braceDepth > 0;
274
+ const { effectiveCode } = scanTomlLine(line, lineNumber, state);
275
+ const currentBuilder = builders[builders.length - 1];
276
+ if (currentBuilder === undefined) {
277
+ throw new CausorynCliError("cli/malformed-toml", "İç TOML ayrıştırıcı hatası");
278
+ }
279
+ if (wasContinuation || effectiveCode.length === 0) {
280
+ currentBuilder.lines.push(line);
281
+ continue;
282
+ }
283
+ if (effectiveCode.startsWith("[")) {
284
+ // Tablo başlığında bracketDepth scan sırasında +1/-1 ile 0'a dönmüş olmalı
285
+ if (state.bracketDepth !== 0 || state.braceDepth !== 0) {
286
+ throw new CausorynCliError("cli/malformed-toml", `Bozuk TOML (satır ${String(lineNumber)}): dengesiz tablo başlığı`);
287
+ }
288
+ const header = parseTableHeaderCode(effectiveCode, lineNumber);
289
+ if (header !== null && !header.startsWith("[")) {
290
+ if (seenStandardTables.has(header)) {
291
+ throw new CausorynCliError("cli/malformed-toml", `Bozuk TOML (satır ${String(lineNumber)}): mükerrer tablo başlığı [${header}]`);
292
+ }
293
+ seenStandardTables.add(header);
294
+ }
295
+ builders.push({ header, lines: [line] });
296
+ continue;
297
+ }
298
+ const eqIdx = findTopLevelEquals(effectiveCode);
299
+ if (eqIdx <= 0) {
300
+ throw new CausorynCliError("cli/malformed-toml", `Bozuk TOML (satır ${String(lineNumber)}): anahtar = değer ataması bekleniyordu`);
301
+ }
302
+ const keyPart = effectiveCode.slice(0, eqIdx).trim();
303
+ const valuePart = effectiveCode.slice(eqIdx + 1).trim();
304
+ if (keyPart.length === 0 ||
305
+ (valuePart.length === 0 && !state.inMultilineBasic && !state.inMultilineLiteral)) {
306
+ throw new CausorynCliError("cli/malformed-toml", `Bozuk TOML (satır ${String(lineNumber)}): eksik anahtar veya değer`);
307
+ }
308
+ currentBuilder.lines.push(line);
309
+ }
310
+ if (state.inMultilineBasic ||
311
+ state.inMultilineLiteral ||
312
+ state.bracketDepth !== 0 ||
313
+ state.braceDepth !== 0) {
314
+ throw new CausorynCliError("cli/malformed-toml", "Bozuk TOML: dosya sonunda kapanmamış çok-satırlı değer veya dizi/tablo");
315
+ }
316
+ // Bir sonraki tablo başlığının hemen üstündeki yorum satırlarını o tabloya bağla
317
+ const sections = [];
318
+ let pendingLeadingComments = [];
319
+ for (let bIdx = 0; bIdx < builders.length; bIdx += 1) {
320
+ const builder = builders[bIdx];
321
+ if (builder === undefined)
322
+ continue;
323
+ const myLeading = pendingLeadingComments;
324
+ pendingLeadingComments = [];
325
+ const hasNextTable = bIdx + 1 < builders.length;
326
+ const bodyLines = [...builder.lines];
327
+ if (hasNextTable && bodyLines.length > 0) {
328
+ const minKeep = builder.header === null ? 0 : 1;
329
+ const detached = [];
330
+ while (bodyLines.length > minKeep) {
331
+ const tail = bodyLines[bodyLines.length - 1] ?? "";
332
+ if (tail.trim().startsWith("#")) {
333
+ detached.unshift(tail);
334
+ bodyLines.pop();
335
+ }
336
+ else {
337
+ break;
338
+ }
339
+ }
340
+ // Yalnızca öncesinde boş satır varsa veya preamble tamamen yorumsa sonraki tabloya bağla
341
+ if (detached.length > 0) {
342
+ const prev = bodyLines[bodyLines.length - 1];
343
+ if (prev === undefined || prev.trim().length === 0) {
344
+ pendingLeadingComments = detached;
345
+ }
346
+ else {
347
+ bodyLines.push(...detached);
348
+ }
349
+ }
350
+ }
351
+ sections.push({
352
+ header: builder.header,
353
+ leadingComments: myLeading,
354
+ lines: bodyLines,
355
+ });
356
+ }
357
+ return { eol, sections };
358
+ }
359
+ export function validateTomlStructure(rawToml) {
360
+ parseTomlDocument(rawToml);
361
+ }
362
+ function renderCausorynSections(spec) {
363
+ const timeoutSec = spec.startupTimeoutSec ?? DEFAULT_STARTUP_TIMEOUT_SEC;
364
+ const formattedArgs = spec.args.map((arg) => formatTomlBasicString(arg)).join(", ");
365
+ const mainLines = [
366
+ `[${CAUSORYN_TABLE}]`,
367
+ `command = ${formatTomlBasicString(spec.command)}`,
368
+ `args = [${formattedArgs}]`,
369
+ `startup_timeout_sec = ${String(timeoutSec)}`,
370
+ ];
371
+ const out = [
372
+ {
373
+ header: CAUSORYN_TABLE,
374
+ leadingComments: [],
375
+ lines: mainLines,
376
+ },
377
+ ];
378
+ const envEntries = spec.env !== undefined ? Object.entries(spec.env) : [];
379
+ if (envEntries.length > 0) {
380
+ envEntries.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
381
+ const envLines = [
382
+ `[${CAUSORYN_ENV_TABLE}]`,
383
+ ...envEntries.map(([k, v]) => `${formatTomlKey(k)} = ${formatTomlBasicString(v)}`),
384
+ ];
385
+ out.push({
386
+ header: CAUSORYN_ENV_TABLE,
387
+ leadingComments: [],
388
+ lines: envLines,
389
+ });
390
+ }
391
+ return out;
392
+ }
393
+ function formatTomlKey(key) {
394
+ return /^[A-Za-z0-9_-]+$/.test(key) ? key : formatTomlBasicString(key);
395
+ }
396
+ function trimTrailingBlankLines(lines) {
397
+ const copy = [...lines];
398
+ while (copy.length > 0 && (copy[copy.length - 1] ?? "").trim().length === 0) {
399
+ copy.pop();
400
+ }
401
+ return copy;
402
+ }
403
+ function serializeSections(sections, eol) {
404
+ const blocks = [];
405
+ for (const section of sections) {
406
+ const trimmedLines = trimTrailingBlankLines(section.lines);
407
+ const combined = [...section.leadingComments, ...trimmedLines];
408
+ if (section.header === null && combined.length === 0) {
409
+ continue;
410
+ }
411
+ blocks.push(combined.join(eol));
412
+ }
413
+ if (blocks.length === 0) {
414
+ return "";
415
+ }
416
+ return `${blocks.join(eol + eol)}${eol}`;
417
+ }
418
+ export function upsertCodexMcpServer(existingToml, spec) {
419
+ const parsed = parseTomlDocument(existingToml);
420
+ const replacement = renderCausorynSections(spec);
421
+ const outputSections = [];
422
+ let inserted = false;
423
+ const hasExistingMain = parsed.sections.some((s) => s.header === CAUSORYN_TABLE);
424
+ for (const section of parsed.sections) {
425
+ if (section.header === CAUSORYN_TABLE) {
426
+ if (!inserted) {
427
+ const firstReplacement = replacement[0];
428
+ if (firstReplacement !== undefined) {
429
+ outputSections.push({
430
+ header: firstReplacement.header,
431
+ leadingComments: section.leadingComments,
432
+ lines: firstReplacement.lines,
433
+ });
434
+ for (let i = 1; i < replacement.length; i += 1) {
435
+ const extra = replacement[i];
436
+ if (extra !== undefined)
437
+ outputSections.push(extra);
438
+ }
439
+ }
440
+ inserted = true;
441
+ }
442
+ continue;
443
+ }
444
+ if (section.header === CAUSORYN_ENV_TABLE) {
445
+ // Yeni env varsa yukarıda replacement ile eklendi; eski env düşürülür.
446
+ continue;
447
+ }
448
+ if (!hasExistingMain &&
449
+ !inserted &&
450
+ section.header !== null &&
451
+ section.header.startsWith(`${CAUSORYN_TABLE}.`)) {
452
+ outputSections.push(...replacement);
453
+ inserted = true;
454
+ }
455
+ outputSections.push(section);
456
+ }
457
+ if (!inserted) {
458
+ outputSections.push(...replacement);
459
+ }
460
+ return serializeSections(outputSections, parsed.eol);
461
+ }
462
+ export function removeCodexMcpServer(existingToml) {
463
+ const parsed = parseTomlDocument(existingToml);
464
+ let removed = false;
465
+ const kept = [];
466
+ for (const section of parsed.sections) {
467
+ if (section.header === CAUSORYN_TABLE ||
468
+ (section.header !== null && section.header.startsWith(`${CAUSORYN_TABLE}.`))) {
469
+ removed = true;
470
+ continue;
471
+ }
472
+ kept.push(section);
473
+ }
474
+ if (!removed) {
475
+ return { content: existingToml, removed: false };
476
+ }
477
+ return { content: serializeSections(kept, parsed.eol), removed: true };
478
+ }
479
+ function parseTomlStringArray(rawValue) {
480
+ const trimmed = rawValue.trim();
481
+ if (!trimmed.startsWith("[") || !trimmed.endsWith("]")) {
482
+ throw new CausorynCliError("cli/malformed-toml", `TOML dizi bekleniyordu: ${rawValue}`);
483
+ }
484
+ const inner = trimmed.slice(1, -1).trim();
485
+ if (inner.length === 0)
486
+ return [];
487
+ const items = [];
488
+ let current = "";
489
+ let inBasic = false;
490
+ let inLiteral = false;
491
+ for (let i = 0; i < inner.length; i += 1) {
492
+ const ch = inner[i] ?? "";
493
+ if (inBasic) {
494
+ current += ch;
495
+ if (ch === "\\" && i + 1 < inner.length) {
496
+ i += 1;
497
+ current += inner[i] ?? "";
498
+ continue;
499
+ }
500
+ if (ch === '"')
501
+ inBasic = false;
502
+ continue;
503
+ }
504
+ if (inLiteral) {
505
+ current += ch;
506
+ if (ch === "'")
507
+ inLiteral = false;
508
+ continue;
509
+ }
510
+ if (ch === '"') {
511
+ inBasic = true;
512
+ current += ch;
513
+ continue;
514
+ }
515
+ if (ch === "'") {
516
+ inLiteral = true;
517
+ current += ch;
518
+ continue;
519
+ }
520
+ if (ch === ",") {
521
+ const piece = current.trim();
522
+ if (piece.length > 0) {
523
+ items.push(unescapeTomlString(piece));
524
+ }
525
+ current = "";
526
+ continue;
527
+ }
528
+ current += ch;
529
+ }
530
+ const tail = current.trim();
531
+ if (tail.length > 0) {
532
+ items.push(unescapeTomlString(tail));
533
+ }
534
+ return items;
535
+ }
536
+ export function readCodexMcpServer(rawToml) {
537
+ const parsed = parseTomlDocument(rawToml);
538
+ const target = parsed.sections.find((s) => s.header === CAUSORYN_TABLE);
539
+ if (target === undefined) {
540
+ return null;
541
+ }
542
+ let command = null;
543
+ let args = [];
544
+ let startupTimeoutSec = null;
545
+ const state = {
546
+ inMultilineBasic: false,
547
+ inMultilineLiteral: false,
548
+ bracketDepth: 0,
549
+ braceDepth: 0,
550
+ };
551
+ let pendingAssignment = "";
552
+ for (let i = 1; i < target.lines.length; i += 1) {
553
+ const line = target.lines[i] ?? "";
554
+ const { effectiveCode } = scanTomlLine(line, i + 1, state);
555
+ if (effectiveCode.length === 0)
556
+ continue;
557
+ pendingAssignment =
558
+ pendingAssignment.length === 0 ? effectiveCode : `${pendingAssignment} ${effectiveCode}`;
559
+ if (state.bracketDepth > 0 || state.braceDepth > 0) {
560
+ continue;
561
+ }
562
+ const eqIdx = findTopLevelEquals(pendingAssignment);
563
+ const assignment = pendingAssignment;
564
+ pendingAssignment = "";
565
+ if (eqIdx <= 0)
566
+ continue;
567
+ const key = assignment.slice(0, eqIdx).trim();
568
+ const val = assignment.slice(eqIdx + 1).trim();
569
+ if (key === "command") {
570
+ command = unescapeTomlString(val);
571
+ }
572
+ else if (key === "args") {
573
+ args = parseTomlStringArray(val);
574
+ }
575
+ else if (key === "startup_timeout_sec") {
576
+ const parsedNum = Number.parseInt(val, 10);
577
+ if (Number.isFinite(parsedNum)) {
578
+ startupTimeoutSec = parsedNum;
579
+ }
580
+ }
581
+ }
582
+ if (command === null) {
583
+ return null;
584
+ }
585
+ return { command, args, startupTimeoutSec };
586
+ }
587
+ //# sourceMappingURL=toml-patch.js.map