vika-cli 0.0.0-stage → 0.1.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 (243) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +37 -2
  3. package/dist/cli.js +32 -0
  4. package/dist/cli.js.map +1 -0
  5. package/dist/commands/approve-and-create-tickets.js +51 -0
  6. package/dist/commands/approve-and-create-tickets.js.map +1 -0
  7. package/dist/commands/create-tickets-command.js +30 -0
  8. package/dist/commands/create-tickets-command.js.map +1 -0
  9. package/dist/commands/doctor-command.js +59 -0
  10. package/dist/commands/doctor-command.js.map +1 -0
  11. package/dist/commands/init-command.js +21 -0
  12. package/dist/commands/init-command.js.map +1 -0
  13. package/dist/commands/mark-deploy-command.js +59 -0
  14. package/dist/commands/mark-deploy-command.js.map +1 -0
  15. package/dist/commands/report-command.js +40 -0
  16. package/dist/commands/report-command.js.map +1 -0
  17. package/dist/commands/run-cli.js +197 -0
  18. package/dist/commands/run-cli.js.map +1 -0
  19. package/dist/commands/run-exit-code.js +11 -0
  20. package/dist/commands/run-exit-code.js.map +1 -0
  21. package/dist/commands/serve-command.js +49 -0
  22. package/dist/commands/serve-command.js.map +1 -0
  23. package/dist/configuration/configuration-errors.js +43 -0
  24. package/dist/configuration/configuration-errors.js.map +1 -0
  25. package/dist/configuration/configuration-schema.js +69 -0
  26. package/dist/configuration/configuration-schema.js.map +1 -0
  27. package/dist/configuration/database-url-checks.js +43 -0
  28. package/dist/configuration/database-url-checks.js.map +1 -0
  29. package/dist/configuration/describe-configuration-safely.js +20 -0
  30. package/dist/configuration/describe-configuration-safely.js.map +1 -0
  31. package/dist/configuration/hide-secrets.js +44 -0
  32. package/dist/configuration/hide-secrets.js.map +1 -0
  33. package/dist/configuration/load-configuration.js +97 -0
  34. package/dist/configuration/load-configuration.js.map +1 -0
  35. package/dist/configuration/read-environment-file.js +77 -0
  36. package/dist/configuration/read-environment-file.js.map +1 -0
  37. package/dist/dashboard/dashboard-page.js +267 -0
  38. package/dist/dashboard/dashboard-page.js.map +1 -0
  39. package/dist/dashboard/dashboard-server.js +144 -0
  40. package/dist/dashboard/dashboard-server.js.map +1 -0
  41. package/dist/dashboard/github-issue-link.js +23 -0
  42. package/dist/dashboard/github-issue-link.js.map +1 -0
  43. package/dist/dashboard/request-guard.js +34 -0
  44. package/dist/dashboard/request-guard.js.map +1 -0
  45. package/dist/database/database-store.js +425 -0
  46. package/dist/database/database-store.js.map +1 -0
  47. package/dist/database/store-types.js +2 -0
  48. package/dist/database/store-types.js.map +1 -0
  49. package/dist/deploys/check-sha-on-branch.js +21 -0
  50. package/dist/deploys/check-sha-on-branch.js.map +1 -0
  51. package/dist/deploys/commits-in-range.js +31 -0
  52. package/dist/deploys/commits-in-range.js.map +1 -0
  53. package/dist/deploys/marker-deploys.js +18 -0
  54. package/dist/deploys/marker-deploys.js.map +1 -0
  55. package/dist/deploys/merge-log.js +33 -0
  56. package/dist/deploys/merge-log.js.map +1 -0
  57. package/dist/deploys/pull-request-number.js +5 -0
  58. package/dist/deploys/pull-request-number.js.map +1 -0
  59. package/dist/deploys/read-merge-deploys.js +46 -0
  60. package/dist/deploys/read-merge-deploys.js.map +1 -0
  61. package/dist/deploys/record-deploys.js +12 -0
  62. package/dist/deploys/record-deploys.js.map +1 -0
  63. package/dist/deploys/run-git.js +49 -0
  64. package/dist/deploys/run-git.js.map +1 -0
  65. package/dist/deploys/starting-point.js +5 -0
  66. package/dist/deploys/starting-point.js.map +1 -0
  67. package/dist/deploys/utc-timestamp.js +6 -0
  68. package/dist/deploys/utc-timestamp.js.map +1 -0
  69. package/dist/doctor/check-configuration.js +46 -0
  70. package/dist/doctor/check-configuration.js.map +1 -0
  71. package/dist/doctor/check-database.js +30 -0
  72. package/dist/doctor/check-database.js.map +1 -0
  73. package/dist/doctor/check-deploys.js +22 -0
  74. package/dist/doctor/check-deploys.js.map +1 -0
  75. package/dist/doctor/check-service-logs.js +107 -0
  76. package/dist/doctor/check-service-logs.js.map +1 -0
  77. package/dist/doctor/check-service-repository.js +43 -0
  78. package/dist/doctor/check-service-repository.js.map +1 -0
  79. package/dist/doctor/check-tracker.js +20 -0
  80. package/dist/doctor/check-tracker.js.map +1 -0
  81. package/dist/doctor/check-webhook.js +13 -0
  82. package/dist/doctor/check-webhook.js.map +1 -0
  83. package/dist/doctor/doctor-check-types.js +4 -0
  84. package/dist/doctor/doctor-check-types.js.map +1 -0
  85. package/dist/doctor/format-doctor-report.js +15 -0
  86. package/dist/doctor/format-doctor-report.js.map +1 -0
  87. package/dist/doctor/suggest-path-map.js +35 -0
  88. package/dist/doctor/suggest-path-map.js.map +1 -0
  89. package/dist/error-grouping/build-clusters.js +77 -0
  90. package/dist/error-grouping/build-clusters.js.map +1 -0
  91. package/dist/error-grouping/cluster-types.js +3 -0
  92. package/dist/error-grouping/cluster-types.js.map +1 -0
  93. package/dist/error-grouping/exception-type.js +6 -0
  94. package/dist/error-grouping/exception-type.js.map +1 -0
  95. package/dist/error-grouping/fingerprints.js +18 -0
  96. package/dist/error-grouping/fingerprints.js.map +1 -0
  97. package/dist/error-grouping/normalize-message.js +29 -0
  98. package/dist/error-grouping/normalize-message.js.map +1 -0
  99. package/dist/error-grouping/template-miner.js +75 -0
  100. package/dist/error-grouping/template-miner.js.map +1 -0
  101. package/dist/log-parsing/assemble-log-entries.js +49 -0
  102. package/dist/log-parsing/assemble-log-entries.js.map +1 -0
  103. package/dist/log-parsing/build-log-entry.js +33 -0
  104. package/dist/log-parsing/build-log-entry.js.map +1 -0
  105. package/dist/log-parsing/detect-log-format.js +44 -0
  106. package/dist/log-parsing/detect-log-format.js.map +1 -0
  107. package/dist/log-parsing/json-log-format.js +56 -0
  108. package/dist/log-parsing/json-log-format.js.map +1 -0
  109. package/dist/log-parsing/line-readers.js +14 -0
  110. package/dist/log-parsing/line-readers.js.map +1 -0
  111. package/dist/log-parsing/log-entry-types.js +3 -0
  112. package/dist/log-parsing/log-entry-types.js.map +1 -0
  113. package/dist/log-parsing/log-levels.js +21 -0
  114. package/dist/log-parsing/log-levels.js.map +1 -0
  115. package/dist/log-parsing/nginx-log-format.js +56 -0
  116. package/dist/log-parsing/nginx-log-format.js.map +1 -0
  117. package/dist/log-parsing/parse-log-lines.js +11 -0
  118. package/dist/log-parsing/parse-log-lines.js.map +1 -0
  119. package/dist/log-parsing/read-line-timestamp.js +21 -0
  120. package/dist/log-parsing/read-line-timestamp.js.map +1 -0
  121. package/dist/log-parsing/read-log-command.js +68 -0
  122. package/dist/log-parsing/read-log-command.js.map +1 -0
  123. package/dist/log-parsing/read-log-file.js +32 -0
  124. package/dist/log-parsing/read-log-file.js.map +1 -0
  125. package/dist/log-parsing/stack-frames.js +10 -0
  126. package/dist/log-parsing/stack-frames.js.map +1 -0
  127. package/dist/log-parsing/text-log-format.js +24 -0
  128. package/dist/log-parsing/text-log-format.js.map +1 -0
  129. package/dist/log-parsing/timestamps.js +22 -0
  130. package/dist/log-parsing/timestamps.js.map +1 -0
  131. package/dist/pipeline/analyze-service.js +45 -0
  132. package/dist/pipeline/analyze-service.js.map +1 -0
  133. package/dist/pipeline/build-stored-report.js +24 -0
  134. package/dist/pipeline/build-stored-report.js.map +1 -0
  135. package/dist/pipeline/ingest-service-logs.js +39 -0
  136. package/dist/pipeline/ingest-service-logs.js.map +1 -0
  137. package/dist/pipeline/load-deploys-for-service.js +16 -0
  138. package/dist/pipeline/load-deploys-for-service.js.map +1 -0
  139. package/dist/pipeline/prepare-ticket-drafts.js +33 -0
  140. package/dist/pipeline/prepare-ticket-drafts.js.map +1 -0
  141. package/dist/pipeline/read-new-log-lines.js +39 -0
  142. package/dist/pipeline/read-new-log-lines.js.map +1 -0
  143. package/dist/pipeline/run-all-services.js +73 -0
  144. package/dist/pipeline/run-all-services.js.map +1 -0
  145. package/dist/pipeline/timestamp-range.js +20 -0
  146. package/dist/pipeline/timestamp-range.js.map +1 -0
  147. package/dist/project-setup/detect-project.js +76 -0
  148. package/dist/project-setup/detect-project.js.map +1 -0
  149. package/dist/project-setup/write-starter-files.js +68 -0
  150. package/dist/project-setup/write-starter-files.js.map +1 -0
  151. package/dist/redaction/redact-ip-addresses.js +26 -0
  152. package/dist/redaction/redact-ip-addresses.js.map +1 -0
  153. package/dist/redaction/redact-sensitive-text.js +40 -0
  154. package/dist/redaction/redact-sensitive-text.js.map +1 -0
  155. package/dist/redaction/redaction-kinds.js +5 -0
  156. package/dist/redaction/redaction-kinds.js.map +1 -0
  157. package/dist/regression-detection/count-series.js +38 -0
  158. package/dist/regression-detection/count-series.js.map +1 -0
  159. package/dist/regression-detection/detect-regressions.js +162 -0
  160. package/dist/regression-detection/detect-regressions.js.map +1 -0
  161. package/dist/regression-detection/detection-types.js +9 -0
  162. package/dist/regression-detection/detection-types.js.map +1 -0
  163. package/dist/regression-detection/noise-check.js +7 -0
  164. package/dist/regression-detection/noise-check.js.map +1 -0
  165. package/dist/regression-detection/restore-time.js +19 -0
  166. package/dist/regression-detection/restore-time.js.map +1 -0
  167. package/dist/regression-detection/severity.js +12 -0
  168. package/dist/regression-detection/severity.js.map +1 -0
  169. package/dist/regression-detection/time-units.js +12 -0
  170. package/dist/regression-detection/time-units.js.map +1 -0
  171. package/dist/reporting/build-report.js +77 -0
  172. package/dist/reporting/build-report.js.map +1 -0
  173. package/dist/reporting/compute-metrics.js +42 -0
  174. package/dist/reporting/compute-metrics.js.map +1 -0
  175. package/dist/reporting/format-terminal-report.js +104 -0
  176. package/dist/reporting/format-terminal-report.js.map +1 -0
  177. package/dist/reporting/report-schema.js +96 -0
  178. package/dist/reporting/report-schema.js.map +1 -0
  179. package/dist/reporting/report-types.js +2 -0
  180. package/dist/reporting/report-types.js.map +1 -0
  181. package/dist/suspect-attribution/apply-path-map.js +31 -0
  182. package/dist/suspect-attribution/apply-path-map.js.map +1 -0
  183. package/dist/suspect-attribution/attribute-regression.js +176 -0
  184. package/dist/suspect-attribution/attribute-regression.js.map +1 -0
  185. package/dist/suspect-attribution/bot-authors.js +8 -0
  186. package/dist/suspect-attribution/bot-authors.js.map +1 -0
  187. package/dist/suspect-attribution/callee-files.js +53 -0
  188. package/dist/suspect-attribution/callee-files.js.map +1 -0
  189. package/dist/suspect-attribution/changed-file-categories.js +39 -0
  190. package/dist/suspect-attribution/changed-file-categories.js.map +1 -0
  191. package/dist/suspect-attribution/crash-line-inputs.js +81 -0
  192. package/dist/suspect-attribution/crash-line-inputs.js.map +1 -0
  193. package/dist/suspect-attribution/function-names.js +42 -0
  194. package/dist/suspect-attribution/function-names.js.map +1 -0
  195. package/dist/suspect-attribution/git-blame-reader.js +160 -0
  196. package/dist/suspect-attribution/git-blame-reader.js.map +1 -0
  197. package/dist/suspect-attribution/score-suspects.js +100 -0
  198. package/dist/suspect-attribution/score-suspects.js.map +1 -0
  199. package/dist/suspect-attribution/suspect-types.js +2 -0
  200. package/dist/suspect-attribution/suspect-types.js.map +1 -0
  201. package/dist/ticket-trackers/create-tracker.js +21 -0
  202. package/dist/ticket-trackers/create-tracker.js.map +1 -0
  203. package/dist/ticket-trackers/jira-document.js +34 -0
  204. package/dist/ticket-trackers/jira-document.js.map +1 -0
  205. package/dist/ticket-trackers/jira-tracker.js +65 -0
  206. package/dist/ticket-trackers/jira-tracker.js.map +1 -0
  207. package/dist/ticket-trackers/linear-tracker.js +109 -0
  208. package/dist/ticket-trackers/linear-tracker.js.map +1 -0
  209. package/dist/ticket-trackers/send-tracker-request.js +84 -0
  210. package/dist/ticket-trackers/send-tracker-request.js.map +1 -0
  211. package/dist/ticket-trackers/tracker-types.js +3 -0
  212. package/dist/ticket-trackers/tracker-types.js.map +1 -0
  213. package/dist/ticketing/build-ticket-comment.js +14 -0
  214. package/dist/ticketing/build-ticket-comment.js.map +1 -0
  215. package/dist/ticketing/build-ticket-draft.js +172 -0
  216. package/dist/ticketing/build-ticket-draft.js.map +1 -0
  217. package/dist/ticketing/choose-assignee.js +30 -0
  218. package/dist/ticketing/choose-assignee.js.map +1 -0
  219. package/dist/ticketing/create-ticket.js +92 -0
  220. package/dist/ticketing/create-ticket.js.map +1 -0
  221. package/dist/ticketing/describe-ticket-outcome.js +24 -0
  222. package/dist/ticketing/describe-ticket-outcome.js.map +1 -0
  223. package/dist/ticketing/read-code-owners.js +82 -0
  224. package/dist/ticketing/read-code-owners.js.map +1 -0
  225. package/dist/ticketing/render-ticket-text.js +22 -0
  226. package/dist/ticketing/render-ticket-text.js.map +1 -0
  227. package/dist/ticketing/ticket-types.js +2 -0
  228. package/dist/ticketing/ticket-types.js.map +1 -0
  229. package/dist/webhook/build-webhook-payload.js +29 -0
  230. package/dist/webhook/build-webhook-payload.js.map +1 -0
  231. package/dist/webhook/send-regression-webhooks.js +57 -0
  232. package/dist/webhook/send-regression-webhooks.js.map +1 -0
  233. package/dist/webhook/sign-webhook-body.js +16 -0
  234. package/dist/webhook/sign-webhook-body.js.map +1 -0
  235. package/dist/webhook/webhook-payload-schema.js +32 -0
  236. package/dist/webhook/webhook-payload-schema.js.map +1 -0
  237. package/migrations/001_init.sql +66 -0
  238. package/migrations/002_bookmark_history_start.sql +9 -0
  239. package/migrations/003_tickets.sql +20 -0
  240. package/migrations/004_ticket_comment_count.sql +10 -0
  241. package/migrations/005_webhook_events.sql +18 -0
  242. package/migrations/README.md +1 -0
  243. package/package.json +37 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-merge-deploys.js","sourceRoot":"","sources":["../../src/deploys/read-merge-deploys.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,aAAa,EAAoB,MAAM,gBAAgB,CAAC;AACpG,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEhF,gFAAgF;AAChF,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAEjC,KAAK,UAAU,aAAa,CAAC,QAAgB,EAAE,MAAc;IAC3D,kBAAkB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACrC,IAAI,CAAC,MAAM,aAAa,CAAC,QA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AAE,CAAC;YACtC,gBAAgB,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,WAAW,CAAE,CAAC,CAAC,CAAC,IAAI,CACxF,CAAC,QAAQ,EAAE,EAAE,CAAC,eAAe,KAAK,GAAG,IAAI,QAAQ,CAAC,UAAU,CAAC,eAAe,CAAC,CAC9E,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;IACF,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,sBAAsB,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1E,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC;AACjF,CAAC;AAED,wEAAwE;AACxE,wEAAwE;AACxE,uEAAuE;AACvE,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,QAAgB,EAAE,MAAc,EAAE,OAAe,EAAE,UAAmB;IAC3G,MAAM,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACtC,8EAA8E;IAC9E,MAAM,SAAS,GAAG,MAAM,aAAa,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,gBAAgB,EAAE,YAAY,gBAAgB,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IACzH,IAAI,EAAE,OAAO,EAAE,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;IAC3C,IAAI,UAAU,KAAK,SAAS;QAAE,OAAO,GAAG,MAAM,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;IAC7F,OAAO,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,12 @@
1
+ // Saves deploys through the store. Duplicates are ignored by the store, so
2
+ // saving the same deploys again is safe. Takes the store as a parameter and
3
+ // never touches the database directly.
4
+ export async function recordDeploys(store, deploys) {
5
+ let added = 0;
6
+ for (const deploy of deploys) {
7
+ if (await store.saveDeploy(deploy))
8
+ added++;
9
+ }
10
+ return { added, alreadyKnown: deploys.length - added };
11
+ }
12
+ //# sourceMappingURL=record-deploys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record-deploys.js","sourceRoot":"","sources":["../../src/deploys/record-deploys.ts"],"names":[],"mappings":"AAEA,2EAA2E;AAC3E,4EAA4E;AAC5E,uCAAuC;AACvC,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,KAAgC,EAAE,OAAiB;IACrF,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,MAAM,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC;YAAE,KAAK,EAAE,CAAC;IAC9C,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,CAAC,MAAM,GAAG,KAAK,EAAE,CAAC;AACzD,CAAC"}
@@ -0,0 +1,49 @@
1
+ // Runs READ-ONLY git commands in the customer's repo (cwd = the repo path
2
+ // from the config). Arguments are always passed as an array, never as a
3
+ // shell string, and nothing from a log ever ends up in a command.
4
+ import { spawn } from "node:child_process";
5
+ // git's environment: the caller's, minus any GIT_* variables (inside a git
6
+ // hook GIT_DIR would point at a different repo), plus:
7
+ // no password prompts, no optional lock files, stable English messages.
8
+ function gitEnvironment() {
9
+ const environment = {};
10
+ for (const [key, value] of Object.entries(process.env))
11
+ if (!key.startsWith("GIT_"))
12
+ environment[key] = value;
13
+ return { ...environment, GIT_TERMINAL_PROMPT: "0", GIT_OPTIONAL_LOCKS: "0", LC_ALL: "C" };
14
+ }
15
+ // Runs one git command in the repo. Never through a shell.
16
+ export function runGit(repoPath, gitArguments) {
17
+ return new Promise((resolve, reject) => {
18
+ const child = spawn("git", ["-c", "core.quotePath=false", ...gitArguments], {
19
+ cwd: repoPath,
20
+ env: gitEnvironment(),
21
+ stdio: ["ignore", "pipe", "pipe"],
22
+ });
23
+ let stdout = "";
24
+ let stderr = "";
25
+ child.stdout.setEncoding("utf8").on("data", (chunk) => (stdout += chunk));
26
+ child.stderr.setEncoding("utf8").on("data", (chunk) => (stderr += chunk));
27
+ child.on("error", (error) => reject(new Error(`cannot run git in ${repoPath}: ${error.message}`)));
28
+ child.on("close", (exitCode) => resolve({ exitCode: exitCode ?? -1, stdout, stderr }));
29
+ });
30
+ }
31
+ // Runs git and returns stdout, or throws with git's own error message.
32
+ export async function runGitOrThrow(repoPath, gitArguments) {
33
+ const result = await runGit(repoPath, gitArguments);
34
+ if (result.exitCode !== 0)
35
+ throw new Error(`git ${gitArguments[0]} failed in ${repoPath}: ${result.stderr.trim()}`);
36
+ return result.stdout;
37
+ }
38
+ // Branch names and shas come from config or the database, but a value that
39
+ // starts with "-" would be read by git as an option, so refuse it.
40
+ export function assertSafeRevision(revision, description) {
41
+ if (revision === "" || revision.startsWith("-") || /\s/.test(revision))
42
+ throw new Error(`invalid ${description}: "${revision}"`);
43
+ }
44
+ // The full sha a branch/sha points at, or undefined if it doesn't exist.
45
+ export async function resolveCommit(repoPath, revision) {
46
+ const result = await runGit(repoPath, ["rev-parse", "--verify", "--quiet", `${revision}^{commit}`]);
47
+ return result.exitCode === 0 ? result.stdout.trim() : undefined;
48
+ }
49
+ //# sourceMappingURL=run-git.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-git.js","sourceRoot":"","sources":["../../src/deploys/run-git.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,wEAAwE;AACxE,kEAAkE;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,2EAA2E;AAC3E,uDAAuD;AACvD,0EAA0E;AAC1E,SAAS,cAAc;IACrB,MAAM,WAAW,GAAsB,EAAE,CAAC;IAC1C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC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ing to blame.
2
+ export function isStartingPoint(deploy) {
3
+ return deploy.previousSha === null;
4
+ }
5
+ //# sourceMappingURL=starting-point.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"starting-point.js","sourceRoot":"","sources":["../../src/deploys/starting-point.ts"],"names":[],"mappings":"AAEA,2EAA2E;AAC3E,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,OAAO,MAAM,CAAC,WAAW,KAAK,IAAI,CAAC;AACrC,CAAC"}
@@ -0,0 +1,6 @@
1
+ // Any ISO time -> UTC ISO ("...Z"), or undefined if it isn't a time.
2
+ export function toUtcIso(text) {
3
+ const timestampMs = Date.parse(text);
4
+ return Number.isNaN(timestampMs) ? undefined : new Date(timestampMs).toISOString();
5
+ }
6
+ //# sourceMappingURL=utc-timestamp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utc-timestamp.js","sourceRoot":"","sources":["../../src/deploys/utc-timestamp.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACrC,OAAO,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC,WAAW,EAAE,CAAC;AACrF,CAAC"}
@@ -0,0 +1,46 @@
1
+ // Doctor: is vika.yaml there and valid, and is the environment complete?
2
+ // Each configuration problem becomes its own FAIL line, under the area it
3
+ // belongs to (a missing JIRA_API_TOKEN is a tracker problem).
4
+ import { ConfigurationError } from "../configuration/configuration-errors.js";
5
+ import { loadConfiguration } from "../configuration/load-configuration.js";
6
+ import { failCheck, passCheck } from "./doctor-check-types.js";
7
+ function areaOfProblem(problem) {
8
+ if (/^(JIRA_|LINEAR_)/.test(problem))
9
+ return "tracker";
10
+ if (problem.startsWith("DATABASE_URL"))
11
+ return "database";
12
+ if (problem.startsWith("webhook"))
13
+ return "webhook";
14
+ return "configuration";
15
+ }
16
+ function fixForProblem(problem) {
17
+ if (problem.startsWith("looked for "))
18
+ return "run `vika init` in your project folder, or pass --config with the path to vika.yaml";
19
+ if (/ is not set /.test(problem))
20
+ return "add it to .env next to vika.yaml (see .env.example), or set it in the environment";
21
+ if (problem.startsWith("DATABASE_URL"))
22
+ return "use the form postgres://user:password@host:5432/database";
23
+ if (problem.startsWith("webhook"))
24
+ return "set webhook.url to a full https URL (http only for localhost); the secret goes in .env as VIKA_WEBHOOK_SECRET";
25
+ return "edit vika.yaml (vika.example.yaml shows every setting)";
26
+ }
27
+ export function checkConfiguration(options) {
28
+ try {
29
+ const configuration = loadConfiguration(options);
30
+ const serviceCount = Object.keys(configuration.services).length;
31
+ return {
32
+ checks: [passCheck("configuration", `${configuration.configurationFilePath} is valid (${serviceCount} ${serviceCount === 1 ? "service" : "services"})`)],
33
+ configuration,
34
+ };
35
+ }
36
+ catch (error) {
37
+ if (!(error instanceof ConfigurationError))
38
+ throw error;
39
+ const heading = error.message.split("\n")[0].replace(/:$/, "");
40
+ return {
41
+ checks: error.problems.map((problem) => failCheck(areaOfProblem(problem), `${heading}: ${problem}`, fixForProblem(problem))),
42
+ configuration: null,
43
+ };
44
+ }
45
+ }
46
+ //# sourceMappingURL=check-configuration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-configuration.js","sourceRoot":"","sources":["../../src/doctor/check-configuration.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,0EAA0E;AAC1E,8DAA8D;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAA2D,MAAM,wCAAwC,CAAC;AACpI,OAAO,EAAE,SAAS,EAAE,SAAS,EAAoB,MAAM,yBAAyB,CAAC;AAEjF,SAAS,aAAa,CAAC,OAAe;IACpC,IAAI,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,S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AChE,OAAO;YACL,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,OAAO,KAAK,OAAO,EAAE,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5H,aAAa,EAAE,IAAI;SACpB,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { failCheck, passCheck, warnCheck } from "./doctor-check-types.js";
2
+ const AREA = "database";
3
+ export function checkDatabase(inspection, urlWarnings, databaseName) {
4
+ const checks = [];
5
+ switch (inspection.status) {
6
+ case "unreachable":
7
+ checks.push(failCheck(AREA, "cannot reach the database host (nothing answered at the host and port in DATABASE_URL)", "start Postgres (docker compose up -d --wait db) or fix the host and port in DATABASE_URL"));
8
+ break;
9
+ case "wrong-password":
10
+ checks.push(failCheck(AREA, "the database refused the login (wrong user or password)", "check the user and password in DATABASE_URL (in .env)"));
11
+ break;
12
+ case "missing-database":
13
+ checks.push(failCheck(AREA, `the server answered, but database "${databaseName}" does not exist`, `create it (createdb ${databaseName}) or fix the database name at the end of DATABASE_URL`));
14
+ break;
15
+ case "failed":
16
+ checks.push(failCheck(AREA, "could not use the database", "check DATABASE_URL and that the user may read and write the database"));
17
+ break;
18
+ case "connected": {
19
+ checks.push(passCheck(AREA, "connected"));
20
+ const pendingMigrations = inspection.availableMigrations.filter((migration) => !inspection.appliedMigrations.includes(migration));
21
+ checks.push(pendingMigrations.length === 0
22
+ ? passCheck(AREA, `all ${inspection.availableMigrations.length} migrations applied`)
23
+ : warnCheck(AREA, `${pendingMigrations.length} migrations not applied yet: ${pendingMigrations.join(", ")}`, "nothing to do: they are applied automatically when `vika report` or `vika run` starts"));
24
+ }
25
+ }
26
+ for (const urlWarning of urlWarnings)
27
+ checks.push(warnCheck(AREA, urlWarning, "change DATABASE_URL in .env as described"));
28
+ return checks;
29
+ }
30
+ //# sourceMappingURL=check-database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-database.js","sourceRoot":"","sources":["../../src/doctor/check-database.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAoB,MAAM,yBAAyB,CAAC;AAE5F,MAAM,IAAI,GAAG,UAAU,CAAC;AAExB,MAAM,UAAU,aAAa,CAAC,UAA8B,EAAE,WAAqB,EAAE,YAAoB;IACvG,MAAM,MAAM,GAAkB,EAAE,CAAC;IACjC,QAAQ,UAAU,CAAC,MAAM,EAAE,CAAC;QAC1B,KAAK,aAAa;YAChB,MAAM,CAAC,IAAI,CACT,SAAS,CAAC,IAAI,EAAE,wFAAwF,EAAE,0FAA0F,CAAC,CACtM,CAAC;YACF,MAAM;QACR,KAAK,gBAAgB;YACnB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,yDAAyD,EAAE,uDAAuD,CAAC,CAAC,CAAC;YACjJ,MAAM;QACR,KAAK,kBAAkB;YACrB,MAAM,CAAC,IAAI,CACT,SAAS,CAAC,IAAI,EAAE,sCAAsC,YAAY,kBAAkB,EAAE,uBAAuB,YAAY,uDAAuD,CAAC,CAClL,CAAC;YACF,MAAM;QACR,KAAK,QAAQ;YACX,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,4BAA4B,EAAE,sEAAsE,CAAC,CAAC,CAAC;YACnI,MAAM;QACR,KAAK,WAAW,EAAE,CAAC;YACjB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;YAC1C,MAAM,iBAAiB,GAAG,UAAU,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,iBAAiB,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;YAClI,MAAM,CAAC,IAAI,CACT,iBAAiB,CAAC,MAAM,KAAK,CAAC;gBAC5B,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,UAAU,CAAC,mBAAmB,CAAC,MAAM,qBAAqB,CAAC;gBACpF,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,GAAG,iBAAiB,CAAC,MAAM,gCAAgC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,uFAAuF,CAAC,CACxM,CAAC;QACJ,CAAC;IACH,CAAC;IACD,KAAK,MAAM,UAAU,IAAI,WAAW;QAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,UAAU,EAAE,0CAA0C,CAAC,CAAC,CAAC;IAC3H,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { passCheck, warnCheck } from "./doctor-check-types.js";
2
+ export function checkDeploys(input) {
3
+ const area = `service ${input.serviceName}: deploys`;
4
+ switch (input.source) {
5
+ case "marker":
6
+ if (input.storedDeployCount === null)
7
+ return [warnCheck(area, "could not count the stored deploys (the database is not reachable)", "fix the database first")];
8
+ if (input.storedDeployCount === 0) {
9
+ return [
10
+ warnCheck(area, "deploys.source is marker, but no deploy has been recorded yet, so nothing can be judged", `add this to the end of your deploy script: vika mark-deploy --service ${input.serviceName} --sha "$(git rev-parse HEAD)" --time "$(date -u +%Y-%m-%dT%H:%M:%SZ)"`),
11
+ ];
12
+ }
13
+ return [passCheck(area, `${input.storedDeployCount} ${input.storedDeployCount === 1 ? "deploy" : "deploys"} recorded with mark-deploy`)];
14
+ case "merges":
15
+ return [
16
+ warnCheck(area, `deploys.source is merges: every commit on "${input.branch}" counts as a deploy at its commit time. That is rough: real deploy times are often later`, "for accurate results, use deploys: { source: marker } and run vika mark-deploy from your deploy script"),
17
+ ];
18
+ default:
19
+ return [warnCheck(area, `deploys.source "${input.source}" is not supported yet`, "use marker (recommended) or merges")];
20
+ }
21
+ }
22
+ //# sourceMappingURL=check-deploys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-deploys.js","sourceRoot":"","sources":["../../src/doctor/check-deploys.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAoB,MAAM,yBAAyB,CAAC;AASjF,MAAM,UAAU,YAAY,CAAC,KAAwB;IACnD,MAAM,IAAI,GAAG,WAAW,KAAK,CAAC,WAAW,WAAW,CAAC;IACrD,QAAQ,KAAK,CAAC,MAAM,EAAE,CAAC;QACrB,KAAK,QAAQ;YACX,IAAI,KAAK,CAAC,iBAAiB,KAAK,IAAI;gBAAE,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,oEAAoE,EAAE,wBAAwB,CAAC,CAAC,CAAC;YAC/J,IAAI,KAAK,CAAC,iBAAiB,KAAK,CAAC,EAAE,CAAC;gBAClC,OAAO;oBACL,SAAS,CACP,IAAI,EACJ,yFAAyF,EACzF,yEAAyE,KAAK,CAAC,WAAW,wEAAwE,CACnK;iBACF,CAAC;YACJ,CAAC;YACD,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,iBAAiB,IAAI,KAAK,CAAC,iBAAiB,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,4BAA4B,CAAC,CAAC,CAAC;QAC3I,KAAK,QAAQ;YACX,OAAO;gBACL,SAAS,CACP,IAAI,EACJ,8CAA8C,KAAK,CAAC,MAAM,2FAA2F,EACrJ,wGAAwG,CACzG;aACF,CAAC;QACJ;YACE,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,mBAAmB,KAAK,CAAC,MAAM,wBAAwB,EAAE,oCAAoC,CAAC,CAAC,CAAC;IAC5H,CAAC;AACH,CAAC"}
@@ -0,0 +1,107 @@
1
+ // Doctor, per service: can vika read the logs, are they in a format it
2
+ // knows, and do stack-trace paths point at files in the repo?
3
+ //
4
+ // A log file is opened and its first lines read; a log command is run ONCE,
5
+ // with a short timeout (it is the command the customer wrote in vika.yaml).
6
+ import { open } from "node:fs/promises";
7
+ import { isAbsolute, resolve } from "node:path";
8
+ import { recognizeFormat } from "../log-parsing/detect-log-format.js";
9
+ import { parseLines } from "../log-parsing/parse-log-lines.js";
10
+ import { readCommand } from "../log-parsing/read-log-command.js";
11
+ import { failCheck, passCheck, warnCheck } from "./doctor-check-types.js";
12
+ import { adviseOnPathMap } from "./suggest-path-map.js";
13
+ export const DOCTOR_COMMAND_TIMEOUT_MS = 10_000;
14
+ export const SAMPLE_LINE_COUNT = 200;
15
+ const SAMPLE_BYTES = 256 * 1024;
16
+ const GLOB_CHARACTERS = /[*?[\]{}]/;
17
+ // The start and the end of a file, without reading all of a big log: the
18
+ // start to check the format, the end for recent stack traces.
19
+ async function readFileSample(filePath) {
20
+ const handle = await open(filePath, "r");
21
+ try {
22
+ const { size } = await handle.stat();
23
+ const readBytes = async (position) => {
24
+ const buffer = Buffer.alloc(Math.min(SAMPLE_BYTES, size));
25
+ const { bytesRead } = await handle.read(buffer, 0, buffer.length, position);
26
+ return buffer.subarray(0, bytesRead).toString("utf8").split("\n");
27
+ };
28
+ const firstLines = (await readBytes(0)).slice(0, SAMPLE_LINE_COUNT);
29
+ // The first line of the end sample is usually cut in half: drop it.
30
+ const lastLines = size > SAMPLE_BYTES ? (await readBytes(size - SAMPLE_BYTES)).slice(1) : [];
31
+ return { firstLines, lastLines };
32
+ }
33
+ finally {
34
+ await handle.close();
35
+ }
36
+ }
37
+ export async function checkServiceLogs(input) {
38
+ const area = `service ${input.serviceName}: logs`;
39
+ const settingName = `services.${input.serviceName}.logs`;
40
+ const checks = [];
41
+ let sampleLines;
42
+ let stackTraceLines; // where to look for stack-trace paths
43
+ if (typeof input.logs === "string") {
44
+ if (GLOB_CHARACTERS.test(input.logs)) {
45
+ return [warnCheck(area, `${settingName} is a glob pattern; globs are not supported yet, so no logs will be read`, `set ${settingName} to one log file`)];
46
+ }
47
+ const filePath = isAbsolute(input.logs) ? input.logs : resolve(input.configurationDirectory, input.logs);
48
+ try {
49
+ const fileSample = await readFileSample(filePath);
50
+ sampleLines = fileSample.firstLines;
51
+ stackTraceLines = [...fileSample.firstLines, ...fileSample.lastLines];
52
+ }
53
+ catch (error) {
54
+ const reason = error.code === "ENOENT" ? "does not exist" : "cannot be read (check its permissions)";
55
+ return [failCheck(area, `${filePath} ${reason}`, `set ${settingName} to the service's log file, readable by the user that runs vika`)];
56
+ }
57
+ checks.push(passCheck(area, `${filePath} is readable`));
58
+ }
59
+ else {
60
+ const timeoutMs = input.commandTimeoutMs ?? DOCTOR_COMMAND_TIMEOUT_MS;
61
+ let commandRead;
62
+ try {
63
+ commandRead = await readCommand(input.logs.command, undefined, timeoutMs);
64
+ }
65
+ catch {
66
+ return [failCheck(area, "the log command could not be started", `check ${settingName}.command`)];
67
+ }
68
+ sampleLines = commandRead.lines.slice(0, SAMPLE_LINE_COUNT);
69
+ stackTraceLines = commandRead.lines;
70
+ if (commandRead.exitCode !== 0 && !commandRead.timedOut) {
71
+ return [failCheck(area, `the log command exited with code ${commandRead.exitCode}`, `run it yourself to see why: ${input.logs.command}`)];
72
+ }
73
+ if (commandRead.lines.length === 0) {
74
+ return [failCheck(area, `the log command printed nothing${commandRead.timedOut ? ` in ${timeoutMs / 1000} seconds` : ""}`, `run it yourself and check it prints log lines: ${input.logs.command}`)];
75
+ }
76
+ checks.push(commandRead.timedOut
77
+ ? warnCheck(area, `the log command was still running after ${timeoutMs / 1000} seconds (it printed ${commandRead.lines.length} lines)`, "commands that follow the log forever (like tail -f or --follow) never finish; drop that flag")
78
+ : passCheck(area, `the log command ran and printed ${commandRead.lines.length} lines`));
79
+ }
80
+ const nonEmptyLines = sampleLines.filter((line) => line.trim() !== "");
81
+ if (nonEmptyLines.length === 0) {
82
+ checks.push(warnCheck(area, "the log is empty, so its format can't be checked yet", "run doctor again once the service has written some logs"));
83
+ return checks;
84
+ }
85
+ const { format, recognizedCount } = recognizeFormat(nonEmptyLines);
86
+ if (recognizedCount === 0) {
87
+ checks.push(failCheck(area, `none of the first ${nonEmptyLines.length} lines is in a format vika knows (text, json, nginx)`, "see the README for the supported formats; most loggers can write one of them"));
88
+ return checks;
89
+ }
90
+ checks.push(passCheck(area, `format: ${format} (${recognizedCount} of the first ${nonEmptyLines.length} lines recognized)`));
91
+ if (input.doesRepoFileExist !== undefined) {
92
+ const framePaths = parseLines(stackTraceLines, format).entries.flatMap((entry) => entry.frames.map((frame) => frame.file));
93
+ const advice = await adviseOnPathMap(framePaths, input.pathMap, input.doesRepoFileExist);
94
+ if (advice.kind === "no stack traces")
95
+ checks.push(passCheck(area, "no stack traces in the sampled lines, so there are no file paths to check yet"));
96
+ if (advice.kind === "paths found")
97
+ checks.push(passCheck(area, `stack-trace paths match files in the repo (${advice.checkedCount} checked)`));
98
+ if (advice.kind === "suggestion") {
99
+ checks.push(warnCheck(area, `stack-trace paths like ${advice.examplePath} are not in the repo`, `add to services.${input.serviceName} in vika.yaml: pathMap: { "${advice.serverPrefix}": "${advice.repoPrefix}" }`));
100
+ }
101
+ if (advice.kind === "not found") {
102
+ checks.push(warnCheck(area, `stack-trace paths like ${advice.examplePath} are not in the repo`, `add a pathMap to services.${input.serviceName} that turns them into repo paths`));
103
+ }
104
+ }
105
+ return checks;
106
+ }
107
+ //# sourceMappingURL=check-service-logs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-service-logs.js","sourceRoot":"","sources":["../../src/doctor/check-service-logs.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,8DAA8D;AAC9D,EAAE;AACF,4EAA4E;AAC5E,4EAA4E;AAC5E,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAEjE,OAAO,EAAE,SAAS,EAAE,SAAS,E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,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3H,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;QACzF,IAAI,MAAM,CAAC,IAAI,KAAK,iBAAiB;YAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,+EAA+E,CAAC,CAAC,CAAC;QACrJ,IAAI,MAAM,CAAC,IAAI,KAAK,aAAa;YAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,8CAA8C,MAAM,CAAC,YAAY,WAAW,CAAC,CAAC,CAAC;QAC9I,IAAI,MAAM,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YACjC,MAAM,CAAC,IAAI,CACT,SAAS,CACP,IAAI,EACJ,0BAA0B,MAAM,CAAC,WAAW,sBAAsB,EAClE,mBAAmB,KAAK,CAAC,WAAW,+BAA+B,MAAM,CAAC,YAAY,OAAO,MAAM,CAAC,UAAU,KAAK,CACpH,CACF,CAAC;QACJ,CAAC;QACD,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YAChC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,0BAA0B,MAAM,CAAC,WAAW,sBAAsB,EAAE,6BAA6B,KAAK,CAAC,WAAW,kCAAkC,CAAC,CAAC,CAAC;QACrL,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,43 @@
1
+ // Doctor, per service: is `repo` a git repo, does the branch exist, is the
2
+ // checkout on it, and are the stored deploys really on it? Read-only git.
3
+ //
4
+ // vika reads the branch itself, never the checkout's HEAD, so a checkout on
5
+ // another branch is only a WARN. A missing branch, or a stored deploy that
6
+ // isn't on the branch, is a FAIL: vika can't attribute anything then.
7
+ import { existsSync, statSync } from "node:fs";
8
+ import { checkShaOnBranch } from "../deploys/check-sha-on-branch.js";
9
+ import { resolveCommit, runGit } from "../deploys/run-git.js";
10
+ import { failCheck, passCheck, warnCheck } from "./doctor-check-types.js";
11
+ // The checks, and whether the branch can be read (later checks need it).
12
+ export async function checkServiceRepository(input) {
13
+ const area = `service ${input.serviceName}: repo`;
14
+ const settingName = `services.${input.serviceName}.repo`;
15
+ if (!existsSync(input.repoPath) || !statSync(input.repoPath).isDirectory()) {
16
+ return { checks: [failCheck(area, `${input.repoPath} does not exist or is not a folder`, `set ${settingName} to the path of the service's git checkout`)], isBranchReadable: false };
17
+ }
18
+ const gitDirectory = await runGit(input.repoPath, ["rev-parse", "--git-dir"]);
19
+ if (gitDirectory.exitCode !== 0) {
20
+ return { checks: [failCheck(area, `${input.repoPath} is not a git repository`, `set ${settingName} to a git checkout (git clone your repo there)`)], isBranchReadable: false };
21
+ }
22
+ const checks = [passCheck(area, `${input.repoPath} is a git repository`)];
23
+ if ((await resolveCommit(input.repoPath, input.branch)) === undefined) {
24
+ checks.push(failCheck(area, `branch "${input.branch}" does not exist in ${input.repoPath}`, `set services.${input.serviceName}.branch to your production branch, or run git fetch in the checkout`));
25
+ return { checks, isBranchReadable: false };
26
+ }
27
+ checks.push(passCheck(area, `branch "${input.branch}" exists`));
28
+ const headSha = await resolveCommit(input.repoPath, "HEAD");
29
+ if (headSha !== undefined) {
30
+ const headCheck = await checkShaOnBranch(input.repoPath, headSha, input.branch);
31
+ checks.push(headCheck.onBranch
32
+ ? passCheck(area, `the checkout (HEAD ${headSha.slice(0, 7)}) is on "${input.branch}"`)
33
+ : warnCheck(area, `the checkout (HEAD ${headSha.slice(0, 7)}) is not on "${input.branch}"`, `nothing breaks: vika always reads "${input.branch}", not the checkout. To silence this, check out "${input.branch}"`));
34
+ }
35
+ if (input.latestStoredDeploy !== null) {
36
+ const deployCheck = await checkShaOnBranch(input.repoPath, input.latestStoredDeploy.sha, input.branch);
37
+ checks.push(deployCheck.onBranch
38
+ ? passCheck(area, `the latest stored deploy (${input.latestStoredDeploy.sha.slice(0, 7)}) is on "${input.branch}"`)
39
+ : failCheck(area, `the latest stored deploy: ${deployCheck.reason}`, `run git fetch in ${input.repoPath}, or check that mark-deploy gets the sha from "${input.branch}"`));
40
+ }
41
+ return { checks, isBranchReadable: true };
42
+ }
43
+ //# sourceMappingURL=check-service-repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-service-repository.js","sourceRoot":"","sources":["../../src/doctor/check-service-repository.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,0EAA0E;AAC1E,EAAE;AACF,4EAA4E;AAC5E,2EAA2E;AAC3E,sEAAsE;AACtE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAoB,MAAM,yBAAyB,CAAC;AAS5F,yEAAyE;AACzE,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,KAA2B;IACtE,MAAM,IAAI,GAAG,WAAW,KAAK,CAAC,WAAW,QAAQ,CAAC;IAClD,MAAM,WAAW,GAAG,YAAY,KAAK,CAAC,WAAW,OAAO,CAAC;IACzD,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;QAC3E,OAAO,EAAE,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,QAAQ,oCAAoC,EAAE,OAAO,WAAW,4CAA4C,CAAC,CAAC,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC;IACvL,CAAC;IACD,MAAM,YAAY,GAAG,MAAM,MA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AAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,YAAY,KAAK,CAAC,MAAM,GAAG,CAAC;YACvF,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,sBAAsB,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,gBAAgB,KAAK,CAAC,MAAM,GAAG,EAAE,sCAAsC,KAAK,CAAC,MAAM,oDAAoD,KAAK,CAAC,MAAM,GAAG,CAAC,CACrN,CAAC;IACJ,CAAC;IAED,IAAI,KAAK,CAAC,kBAAkB,KAAK,IAAI,EAAE,CAAC;QACtC,MAAM,WAAW,GAAG,MAAM,gBAAgB,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,kBAAkB,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QACvG,MAAM,CAAC,IAAI,CACT,WAAW,CAAC,QAAQ;YAClB,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,6BAA6B,KAAK,CAAC,kBAAkB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,YAAY,KAAK,CAAC,MAAM,GAAG,CAAC;YACnH,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,6BAA6B,WAAW,CAAC,MAAM,EAAE,EAAE,oBAAoB,KAAK,CAAC,QAAQ,kDAAkD,KAAK,CAAC,MAAM,GAAG,CAAC,CAC5K,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,20 @@
1
+ // Doctor: do the tracker credentials work? One cheap authenticated call
2
+ // (Jira /myself, Linear viewer). Errors are already plain English and
3
+ // token-free (send-tracker-request), and are masked again here.
4
+ import { hideSecrets } from "../configuration/hide-secrets.js";
5
+ import { failCheck, passCheck } from "./doctor-check-types.js";
6
+ const AREA = "tracker";
7
+ export async function checkTracker(tracker, secrets) {
8
+ if (tracker === null)
9
+ return [passCheck(AREA, 'tracker.type is "none": no tickets will be filed (that is fine)')];
10
+ const trackerName = tracker.trackerType === "jira" ? "Jira" : "Linear";
11
+ const credentialNames = tracker.trackerType === "jira" ? "JIRA_BASE_URL, JIRA_EMAIL and JIRA_API_TOKEN" : "LINEAR_API_KEY";
12
+ try {
13
+ const user = await tracker.checkCredentials();
14
+ return [passCheck(AREA, `${trackerName} accepts the credentials (logged in as ${user.name})`)];
15
+ }
16
+ catch (error) {
17
+ return [failCheck(AREA, hideSecrets(error instanceof Error ? error.message : String(error), secrets), `check ${credentialNames} in .env`)];
18
+ }
19
+ }
20
+ //# sourceMappingURL=check-tracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-tracker.js","sourceRoot":"","sources":["../../src/doctor/check-tracker.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,sEAAsE;AACtE,gEAAgE;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAoB,MAAM,yBAAyB,CAAC;AAEjF,MAAM,IAAI,GAAG,SAAS,CAAC;AAEvB,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAA6B,EAAE,OAAiB;IACjF,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,iEAAiE,CAAC,CAAC,CAAC;IAClH,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;IACvE,MAAM,eAAe,GAAG,OAAO,CAAC,WAAW,KAAK,MAAM,CAAC,CAAC,CAAC,8CAA8C,CAAC,CAAC,CAAC,gBAAgB,CAAC;IAC3H,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,gBAAgB,EAAE,CAAC;QAC9C,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,GAAG,WAAW,0CAA0C,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;IACjG,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,WAAW,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE,SAAS,eAAe,UAAU,CAAC,CAAC,CAAC;IAC7I,CAAC;AACH,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { passCheck, warnCheck } from "./doctor-check-types.js";
2
+ const AREA = "webhook";
3
+ export function checkWebhook(webhook) {
4
+ if (webhook === null)
5
+ return [];
6
+ const host = new URL(webhook.url).host;
7
+ const checks = [passCheck(AREA, `webhook URL on ${host} is valid; \`vika run\` posts each new regression there once`)];
8
+ if (webhook.secret === null) {
9
+ checks.push(warnCheck(AREA, "no VIKA_WEBHOOK_SECRET is set, so webhook bodies are not signed", "set VIKA_WEBHOOK_SECRET in .env so the receiver can check X-Vika-Signature"));
10
+ }
11
+ return checks;
12
+ }
13
+ //# sourceMappingURL=check-webhook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-webhook.js","sourceRoot":"","sources":["../../src/doctor/check-webhook.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAoB,MAAM,yBAAyB,CAAC;AAEjF,MAAM,IAAI,GAAG,SAAS,CAAC;AAEvB,MAAM,UAAU,YAAY,CAAC,OAAuC;IAClE,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC;IAChC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;IACvC,MAAM,MAAM,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,kBAAkB,IAAI,8DAA8D,CAAC,CAAC,CAAC;IACvH,IAAI,OAAO,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;QAC5B,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,iEAAiE,EAAE,4EAA4E,CAAC,CAAC,CAAC;IAChL,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export const passCheck = (area, message) => ({ area, level: "OK", message, fix: null });
2
+ export const warnCheck = (area, message, fix) => ({ area, level: "WARN", message, fix });
3
+ export const failCheck = (area, message, fix) => ({ area, level: "FAIL", message, fix });
4
+ //# sourceMappingURL=doctor-check-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doctor-check-types.js","sourceRoot":"","sources":["../../src/doctor/doctor-check-types.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,OAAe,EAAe,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;AACrH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,OAAe,EAAE,GAAW,EAAe,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;AAC9H,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,OAAe,EAAE,GAAW,EAAe,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ export function formatDoctorReport(checks) {
2
+ const lines = [];
3
+ for (const check of checks) {
4
+ lines.push(`${check.level.padEnd(4)} ${check.area}: ${check.message}`);
5
+ if (check.fix !== null)
6
+ lines.push(` fix: ${check.fix}`);
7
+ }
8
+ const failCount = checks.filter((check) => check.level === "FAIL").length;
9
+ const warnCount = checks.filter((check) => check.level === "WARN").length;
10
+ lines.push("", failCount === 0
11
+ ? `All set${warnCount > 0 ? `, with ${warnCount} ${warnCount === 1 ? "warning" : "warnings"}` : ""}.`
12
+ : `${failCount} ${failCount === 1 ? "problem" : "problems"} to fix (and ${warnCount} ${warnCount === 1 ? "warning" : "warnings"}).`);
13
+ return `${lines.join("\n").replace(/[^\x20-\x7e\n]/g, "?")}\n`;
14
+ }
15
+ //# sourceMappingURL=format-doctor-report.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-doctor-report.js","sourceRoot":"","sources":["../../src/doctor/format-doctor-report.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,kBAAkB,CAAC,MAAqB;IACtD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACvE,IAAI,KAAK,CAAC,GAAG,KAAK,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,aAAa,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;IAC/D,CAAC;IACD,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,MAAM,CAAC;IAC1E,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,MAAM,CAAC;IAC1E,KAAK,CAAC,IAAI,CACR,EAAE,EACF,SAAS,KAAK,CAAC;QACb,CAAC,CAAC,UAAU,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,SAAS,IAAI,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG;QACrG,CAAC,CAAC,GAAG,SAAS,IAAI,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,gBAAgB,SAAS,IAAI,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,IAAI,CACtI,CAAC;IACF,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,IAAI,CAAC;AACjE,CAAC"}
@@ -0,0 +1,35 @@
1
+ // When stack-trace paths (e.g. /app/src/orders/service.ts) don't exist in the
2
+ // repo, find the server prefix to map away: drop leading folders until the
3
+ // rest exists in the repo (src/orders/service.ts), and suggest that mapping.
4
+ // Pure, apart from the injected "does this file exist in the repo" check.
5
+ import { applyPathMap, isRepoRelativePath } from "../suspect-attribution/apply-path-map.js";
6
+ export async function adviseOnPathMap(framePaths, pathMap, doesRepoFileExist) {
7
+ // Library frames (node_modules, node:internal) are never in the repo.
8
+ const appFramePaths = [...new Set(framePaths)].filter((framePath) => !framePath.includes("node_modules/") && !/^[A-Za-z]+:/.test(framePath));
9
+ if (appFramePaths.length === 0)
10
+ return { kind: "no stack traces" };
11
+ let checkedCount = 0;
12
+ for (const framePath of appFramePaths) {
13
+ const mappedPath = applyPathMap(framePath, pathMap);
14
+ if (isRepoRelativePath(mappedPath) && (await doesRepoFileExist(mappedPath)))
15
+ checkedCount++;
16
+ }
17
+ if (checkedCount > 0)
18
+ return { kind: "paths found", checkedCount };
19
+ for (const framePath of appFramePaths) {
20
+ const pathParts = framePath.split("/");
21
+ for (let droppedCount = 1; droppedCount < pathParts.length; droppedCount++) {
22
+ const repoPath = pathParts.slice(droppedCount).join("/");
23
+ if (repoPath === "" || !isRepoRelativePath(repoPath) || !(await doesRepoFileExist(repoPath)))
24
+ continue;
25
+ // Keep the repo path's first folder in the mapping when it has one:
26
+ // "/app/src: src" reads better than "/app: ''" and means the same.
27
+ const hasFolder = droppedCount < pathParts.length - 1;
28
+ const keptCount = hasFolder ? droppedCount + 1 : droppedCount;
29
+ const serverPrefix = pathParts.slice(0, keptCount).join("/");
30
+ return { kind: "suggestion", serverPrefix: serverPrefix === "" ? "/" : serverPrefix, repoPrefix: hasFolder ? pathParts[droppedCount] : "", examplePath: framePath };
31
+ }
32
+ }
33
+ return { kind: "not found", examplePath: appFramePaths[0] };
34
+ }
35
+ //# sourceMappingURL=suggest-path-map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suggest-path-map.js","sourceRoot":"","sources":["../../src/doctor/suggest-path-map.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,2EAA2E;AAC3E,6EAA6E;AAC7E,0EAA0E;AAC1E,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAS5F,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,UAAoB,EACpB,OAA4B,EAC5B,iBAAyD;IAEzD,sEAAsE;IACtE,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAC7I,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;IAEnE,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,KAAK,MAAM,SAAS,IAAI,aAAa,EAAE,CAAC;QACtC,MAAM,UAAU,GAAG,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QACpD,IAAI,kBAAkB,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,iBAAiB,CAAC,UAAU,CAAC,CAAC;YAAE,YAAY,EAAE,CAAC;IAC9F,CAAC;IACD,IAAI,YA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@@
1
+ import { redact } from "../redaction/redact-sensitive-text.js";
2
+ import { ALL_REDACTION_KINDS } from "../redaction/redaction-kinds.js";
3
+ import { MAX_EXAMPLES, MAX_SOURCE_REFS } from "./cluster-types.js";
4
+ import { readExceptionType } from "./exception-type.js";
5
+ import { FINGERPRINT_FRAME_COUNT, stackFingerprint } from "./fingerprints.js";
6
+ import { normalize } from "./normalize-message.js";
7
+ import { addMessage, emptyState, exportState, importState, tokenize } from "./template-miner.js";
8
+ // Plain string order (not locale-aware), so output never depends on the machine.
9
+ const compareStrings = (left, right) => (left < right ? -1 : left > right ? 1 : 0);
10
+ // The start of the entry's minute, as ISO.
11
+ function minuteStartOf(timestamp) {
12
+ const minuteStart = new Date(Date.parse(timestamp));
13
+ minuteStart.setUTCSeconds(0, 0);
14
+ return minuteStart.toISOString();
15
+ }
16
+ // Frames as grouping sees them: every kind redacted.
17
+ const redactFramesFully = (frames) => frames.map((frame) => (frame.fn === undefined ? { file: redact(frame.file), line: frame.line } : { file: redact(frame.file), line: frame.line, fn: redact(frame.fn) }));
18
+ export function buildClusters(entries, service, minerState, redactionKinds = ALL_REDACTION_KINDS) {
19
+ const miner = importState(minerState ?? emptyState());
20
+ const clustersInProgress = new Map();
21
+ for (const entry of entries) {
22
+ const normalizedMessage = normalize(redact(entry.message));
23
+ const exceptionName = readExceptionType(entry.message);
24
+ const hasStackTrace = entry.frames.length > 0;
25
+ const fingerprint = hasStackTrace
26
+ ? stackFingerprint(service, exceptionName, redactFramesFully(entry.frames))
27
+ : addMessage(miner, service, normalizedMessage).fingerprint;
28
+ let inProgress = clustersInProgress.get(fingerprint);
29
+ if (!inProgress) {
30
+ const newCluster = {
31
+ fingerprint,
32
+ service,
33
+ template: tokenize(normalizedMessage).join(" "),
34
+ countsPerMinute: {},
35
+ firstSeen: entry.timestamp,
36
+ lastSeen: entry.timestamp,
37
+ examples: [],
38
+ sourceRefs: [],
39
+ topFrames: entry.frames.slice(0, FINGERPRINT_FRAME_COUNT).map((frame) => ({ ...frame })),
40
+ };
41
+ if (exceptionName !== undefined)
42
+ newCluster.exceptionType = exceptionName;
43
+ inProgress = { cluster: newCluster, countsPerMinute: new Map(), isTemplateFromMiner: !hasStackTrace };
44
+ clustersInProgress.set(fingerprint, inProgress);
45
+ }
46
+ const cluster = inProgress.cluster;
47
+ const minute = minuteStartOf(entry.timestamp);
48
+ inProgress.countsPerMinute.set(minute, (inProgress.countsPerMinute.get(minute) ?? 0) + 1);
49
+ if (Date.parse(entry.timestamp) < Date.parse(cluster.firstSeen))
50
+ cluster.firstSeen = entry.timestamp;
51
+ if (Date.parse(entry.timestamp) > Date.parse(cluster.lastSeen))
52
+ cluster.lastSeen = entry.timestamp;
53
+ // Messages are already redacted by the parser; redact again (with the
54
+ // same kinds) to be safe.
55
+ const example = redact(entry.message, redactionKinds);
56
+ if (cluster.examples.length < MAX_EXAMPLES && !cluster.examples.includes(example))
57
+ cluster.examples.push(example);
58
+ if (entry.file !== undefined && entry.lineNumber !== undefined) {
59
+ const sourceReference = `${entry.file}:${entry.lineNumber}`;
60
+ if (cluster.sourceRefs.length < MAX_SOURCE_REFS && !cluster.sourceRefs.includes(sourceReference)) {
61
+ cluster.sourceRefs.push(sourceReference);
62
+ }
63
+ }
64
+ }
65
+ const clusters = [];
66
+ for (const { cluster, countsPerMinute, isTemplateFromMiner } of clustersInProgress.values()) {
67
+ // Miner groups show their current (possibly generalized) template.
68
+ if (isTemplateFromMiner)
69
+ cluster.template = miner.byFingerprint.get(cluster.fingerprint).tokens.join(" ");
70
+ cluster.countsPerMinute = Object.fromEntries([...countsPerMinute.entries()].sort(([leftMinute], [rightMinute]) => compareStrings(leftMinute, rightMinute)));
71
+ clusters.push(cluster);
72
+ }
73
+ // Stable order: oldest group first, fingerprint breaks ties.
74
+ clusters.sort((left, right) => Date.parse(left.firstSeen) - Date.parse(right.firstSeen) || compareStrings(left.fingerprint, right.fingerprint));
75
+ return { clusters, state: exportState(miner) };
76
+ }
77
+ //# sourceMappingURL=build-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