@flanksource/clicky-ui 0.3.86 → 0.3.88

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 (147) hide show
  1. package/dist/components.cjs +0 -1
  2. package/dist/components.d.ts +1 -1
  3. package/dist/components.d.ts.map +1 -1
  4. package/dist/components.js +2 -2
  5. package/dist/data/ProgressBars.cjs +157 -101
  6. package/dist/data/ProgressBars.cjs.map +1 -1
  7. package/dist/data/ProgressBars.d.ts +1 -1
  8. package/dist/data/ProgressBars.d.ts.map +1 -1
  9. package/dist/data/ProgressBars.js +157 -101
  10. package/dist/data/ProgressBars.js.map +1 -1
  11. package/dist/data/ai/PromptCatalog/PromptCatalogTable.cjs +1 -0
  12. package/dist/data/ai/PromptCatalog/PromptCatalogTable.cjs.map +1 -1
  13. package/dist/data/ai/PromptCatalog/PromptCatalogTable.d.ts.map +1 -1
  14. package/dist/data/ai/PromptCatalog/PromptCatalogTable.js +1 -0
  15. package/dist/data/ai/PromptCatalog/PromptCatalogTable.js.map +1 -1
  16. package/dist/data/traces/ProcessResourceMetrics.cjs +99 -0
  17. package/dist/data/traces/ProcessResourceMetrics.cjs.map +1 -0
  18. package/dist/data/traces/ProcessResourceMetrics.d.ts +10 -0
  19. package/dist/data/traces/ProcessResourceMetrics.d.ts.map +1 -0
  20. package/dist/data/traces/ProcessResourceMetrics.js +99 -0
  21. package/dist/data/traces/ProcessResourceMetrics.js.map +1 -0
  22. package/dist/data/traces/ProcessTraceDetail.cjs +85 -108
  23. package/dist/data/traces/ProcessTraceDetail.cjs.map +1 -1
  24. package/dist/data/traces/ProcessTraceDetail.d.ts +7 -1
  25. package/dist/data/traces/ProcessTraceDetail.d.ts.map +1 -1
  26. package/dist/data/traces/ProcessTraceDetail.js +88 -111
  27. package/dist/data/traces/ProcessTraceDetail.js.map +1 -1
  28. package/dist/data/traces/ProcessUsageBars.cjs +37 -41
  29. package/dist/data/traces/ProcessUsageBars.cjs.map +1 -1
  30. package/dist/data/traces/ProcessUsageBars.d.ts.map +1 -1
  31. package/dist/data/traces/ProcessUsageBars.js +37 -41
  32. package/dist/data/traces/ProcessUsageBars.js.map +1 -1
  33. package/dist/data/traces/process-tree.cjs +35 -0
  34. package/dist/data/traces/process-tree.cjs.map +1 -1
  35. package/dist/data/traces/process-tree.d.ts +15 -0
  36. package/dist/data/traces/process-tree.d.ts.map +1 -1
  37. package/dist/data/traces/process-tree.js +35 -1
  38. package/dist/data/traces/process-tree.js.map +1 -1
  39. package/dist/data/version-info.cjs +3 -3
  40. package/dist/data/version-info.js +3 -3
  41. package/dist/expressions/lang/attributes.cjs.map +1 -1
  42. package/dist/expressions/lang/attributes.d.ts.map +1 -1
  43. package/dist/expressions/lang/attributes.js.map +1 -1
  44. package/dist/expressions/lang/completion.cjs.map +1 -1
  45. package/dist/expressions/lang/completion.d.ts.map +1 -1
  46. package/dist/expressions/lang/completion.js.map +1 -1
  47. package/dist/expressions/lang/generated/conformance.json.d.ts +280 -0
  48. package/dist/expressions/lang/generated/index.cjs.map +1 -1
  49. package/dist/expressions/lang/generated/index.d.ts.map +1 -1
  50. package/dist/expressions/lang/generated/index.js.map +1 -1
  51. package/dist/expressions/lang/generated/languages.cjs +2 -0
  52. package/dist/expressions/lang/generated/languages.cjs.map +1 -1
  53. package/dist/expressions/lang/generated/languages.js +2 -0
  54. package/dist/expressions/lang/generated/languages.js.map +1 -1
  55. package/dist/expressions/lang/generated/languages.json.d.ts +2 -0
  56. package/dist/expressions/lang/generated/spec.cjs +2 -2
  57. package/dist/expressions/lang/generated/spec.cjs.map +1 -1
  58. package/dist/expressions/lang/generated/spec.js +2 -2
  59. package/dist/expressions/lang/generated/spec.js.map +1 -1
  60. package/dist/expressions/lang/generated/spec.json.d.ts +81 -26
  61. package/dist/expressions/lang/hover.cjs +3 -1
  62. package/dist/expressions/lang/hover.cjs.map +1 -1
  63. package/dist/expressions/lang/hover.d.ts.map +1 -1
  64. package/dist/expressions/lang/hover.js +3 -1
  65. package/dist/expressions/lang/hover.js.map +1 -1
  66. package/dist/expressions/lang/index.cjs.map +1 -1
  67. package/dist/expressions/lang/index.d.ts.map +1 -1
  68. package/dist/expressions/lang/index.js.map +1 -1
  69. package/dist/expressions/lang/merge.cjs +5 -0
  70. package/dist/expressions/lang/merge.cjs.map +1 -1
  71. package/dist/expressions/lang/merge.d.ts +4 -0
  72. package/dist/expressions/lang/merge.d.ts.map +1 -1
  73. package/dist/expressions/lang/merge.js +5 -0
  74. package/dist/expressions/lang/merge.js.map +1 -1
  75. package/dist/expressions/lang/prefix.cjs.map +1 -1
  76. package/dist/expressions/lang/prefix.d.ts.map +1 -1
  77. package/dist/expressions/lang/prefix.js.map +1 -1
  78. package/dist/expressions/lang/spec.d.ts.map +1 -1
  79. package/dist/expressions/lang/theme.cjs.map +1 -1
  80. package/dist/expressions/lang/theme.d.ts.map +1 -1
  81. package/dist/expressions/lang/theme.js.map +1 -1
  82. package/dist/expressions/lang/types.d.ts +12 -0
  83. package/dist/expressions/lang/types.d.ts.map +1 -1
  84. package/dist/expressions/playground/EmbeddedPlayground.cjs +6 -5
  85. package/dist/expressions/playground/EmbeddedPlayground.cjs.map +1 -1
  86. package/dist/expressions/playground/EmbeddedPlayground.d.ts +12 -4
  87. package/dist/expressions/playground/EmbeddedPlayground.d.ts.map +1 -1
  88. package/dist/expressions/playground/EmbeddedPlayground.js +6 -5
  89. package/dist/expressions/playground/EmbeddedPlayground.js.map +1 -1
  90. package/dist/expressions/playground/ExpressionPlayground.cjs +217 -156
  91. package/dist/expressions/playground/ExpressionPlayground.cjs.map +1 -1
  92. package/dist/expressions/playground/ExpressionPlayground.d.ts +7 -6
  93. package/dist/expressions/playground/ExpressionPlayground.d.ts.map +1 -1
  94. package/dist/expressions/playground/ExpressionPlayground.js +217 -156
  95. package/dist/expressions/playground/ExpressionPlayground.js.map +1 -1
  96. package/dist/expressions/playground/panels/ReferencePanel.cjs +34 -0
  97. package/dist/expressions/playground/panels/ReferencePanel.cjs.map +1 -0
  98. package/dist/expressions/playground/panels/ReferencePanel.d.ts +22 -0
  99. package/dist/expressions/playground/panels/ReferencePanel.d.ts.map +1 -0
  100. package/dist/expressions/playground/panels/ReferencePanel.js +33 -0
  101. package/dist/expressions/playground/panels/ReferencePanel.js.map +1 -0
  102. package/dist/expressions/playground/panels/SpecPanel.cjs +10 -2
  103. package/dist/expressions/playground/panels/SpecPanel.cjs.map +1 -1
  104. package/dist/expressions/playground/panels/SpecPanel.d.ts.map +1 -1
  105. package/dist/expressions/playground/panels/SpecPanel.js +10 -2
  106. package/dist/expressions/playground/panels/SpecPanel.js.map +1 -1
  107. package/dist/expressions/playground/useEvaluator.cjs +56 -42
  108. package/dist/expressions/playground/useEvaluator.cjs.map +1 -1
  109. package/dist/expressions/playground/useEvaluator.d.ts +0 -2
  110. package/dist/expressions/playground/useEvaluator.d.ts.map +1 -1
  111. package/dist/expressions/playground/useEvaluator.js +56 -42
  112. package/dist/expressions/playground/useEvaluator.js.map +1 -1
  113. package/dist/expressions/playground/useSampleRuns.cjs +22 -18
  114. package/dist/expressions/playground/useSampleRuns.cjs.map +1 -1
  115. package/dist/expressions/playground/useSampleRuns.d.ts +2 -3
  116. package/dist/expressions/playground/useSampleRuns.d.ts.map +1 -1
  117. package/dist/expressions/playground/useSampleRuns.js +22 -18
  118. package/dist/expressions/playground/useSampleRuns.js.map +1 -1
  119. package/dist/hooks/use-latest.cjs +14 -0
  120. package/dist/hooks/use-latest.cjs.map +1 -0
  121. package/dist/hooks/use-latest.d.ts +3 -0
  122. package/dist/hooks/use-latest.d.ts.map +1 -0
  123. package/dist/hooks/use-latest.js +14 -0
  124. package/dist/hooks/use-latest.js.map +1 -0
  125. package/dist/index.cjs +0 -1
  126. package/dist/index.js +2 -2
  127. package/dist/overlay/ConfirmDialog.cjs +12 -37
  128. package/dist/overlay/ConfirmDialog.cjs.map +1 -1
  129. package/dist/overlay/ConfirmDialog.d.ts +3 -17
  130. package/dist/overlay/ConfirmDialog.d.ts.map +1 -1
  131. package/dist/overlay/ConfirmDialog.js +12 -37
  132. package/dist/overlay/ConfirmDialog.js.map +1 -1
  133. package/dist/overlay/useConfirm.cjs +1 -16
  134. package/dist/overlay/useConfirm.cjs.map +1 -1
  135. package/dist/overlay/useConfirm.d.ts +1 -9
  136. package/dist/overlay/useConfirm.d.ts.map +1 -1
  137. package/dist/overlay/useConfirm.js +3 -17
  138. package/dist/overlay/useConfirm.js.map +1 -1
  139. package/dist/runtime/barrels.json +1574 -1576
  140. package/dist/runtime/importmap.json +2185 -2183
  141. package/package.json +1 -1
  142. package/dist/overlay/confirmMemory.cjs +0 -58
  143. package/dist/overlay/confirmMemory.cjs.map +0 -1
  144. package/dist/overlay/confirmMemory.d.ts +0 -8
  145. package/dist/overlay/confirmMemory.d.ts.map +0 -1
  146. package/dist/overlay/confirmMemory.js +0 -54
  147. package/dist/overlay/confirmMemory.js.map +0 -1
@@ -1,50 +1,46 @@
1
+ const require_UiChip = require("../../icons/components/UiChip.cjs");
2
+ const require_UiMemoryStick = require("../../icons/components/UiMemoryStick.cjs");
1
3
  const require_format = require("../../lib/format.cjs");
2
- const require_ProgressBar = require("../ProgressBar.cjs");
4
+ const require_ProgressBars = require("../ProgressBars.cjs");
3
5
  const require_process_tree = require("./process-tree.cjs");
4
6
  let react_jsx_runtime = require("react/jsx-runtime");
5
7
  // src/data/traces/ProcessUsageBars.tsx
6
- function Usage({ resource, pid, value, percent, title }) {
7
- const label = `${resource} for pid ${pid}`;
8
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
9
- className: "w-28 shrink-0 text-xs tabular-nums",
10
- title,
11
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
12
- className: "mb-0.5 flex justify-between gap-1 text-muted-foreground",
13
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: resource }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: value })]
14
- }), percent == null ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
15
- role: "progressbar",
16
- "aria-label": label,
17
- "aria-valuetext": "Waiting for sample",
18
- "aria-valuemin": 0,
19
- "aria-valuemax": 100,
20
- className: "h-1 rounded-full bg-muted"
21
- }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ProgressBar.ProgressBar, {
22
- label,
23
- total: 100,
24
- height: "h-1",
25
- segments: [{
26
- count: Math.max(0, Math.min(100, percent)),
27
- color: "bg-primary",
28
- label: value
29
- }]
30
- })]
31
- });
32
- }
8
+ var GiB = 1024 ** 3;
9
+ /** One bar per core (100% CPU), captioned as a CPU %. */
10
+ var CPU_UNIT = {
11
+ perBar: 100,
12
+ label: "",
13
+ barLabel: "core",
14
+ format: (cores) => require_process_tree.formatCpuPercent(cores * 100)
15
+ };
16
+ /** One bar per GB of RSS, captioned in the readable byte size. */
17
+ var RSS_UNIT = {
18
+ perBar: GiB,
19
+ label: "",
20
+ barLabel: "GB",
21
+ format: (gb) => require_format.formatBytes(gb * GiB)
22
+ };
33
23
  function ProcessUsageBars({ row, memoryPercent }) {
34
24
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
35
- className: "flex shrink-0 gap-3",
36
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Usage, {
37
- resource: "CPU",
38
- pid: row.pid,
39
- value: require_process_tree.formatCpuPercent(row.cpuPercent),
40
- percent: row.cpuPercent,
41
- title: `Peak ${require_process_tree.formatCpuPercent(row.peakCpuPercent)} · CPU per core`
42
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Usage, {
43
- resource: "RAM",
44
- pid: row.pid,
45
- value: require_format.formatBytes(row.rssBytes),
46
- percent: memoryPercent,
47
- title: `Peak ${require_format.formatBytes(row.peakRssBytes)}${memoryPercent === void 0 ? "" : ` · ${memoryPercent.toFixed(1)}% of host RAM`}`
25
+ className: "flex shrink-0 items-center gap-3",
26
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ProgressBars.ProgressBars, {
27
+ variant: "cell",
28
+ orientation: "vertical",
29
+ showLabel: false,
30
+ icon: require_UiChip.UiChip,
31
+ unit: CPU_UNIT,
32
+ title: `CPU for pid ${row.pid}`,
33
+ usage: row.cpuPercent ?? void 0,
34
+ hoverFooter: `Peak ${require_process_tree.formatCpuPercent(row.peakCpuPercent)} · one bar per core`
35
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ProgressBars.ProgressBars, {
36
+ variant: "cell",
37
+ orientation: "vertical",
38
+ showLabel: false,
39
+ icon: require_UiMemoryStick.UiMemoryStick,
40
+ unit: RSS_UNIT,
41
+ title: `RAM for pid ${row.pid}`,
42
+ usage: row.rssBytes,
43
+ hoverFooter: `Peak ${require_format.formatBytes(row.peakRssBytes)}${memoryPercent === void 0 ? "" : ` · ${memoryPercent.toFixed(1)}% of host RAM`} · one bar per GB`
48
44
  })]
49
45
  });
50
46
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ProcessUsageBars.cjs","names":["ProgressBar","formatCpuPercent","formatBytes"],"sources":["../../../src/data/traces/ProcessUsageBars.tsx"],"sourcesContent":["import { formatBytes } from \"../../lib/format\";\nimport { ProgressBar } from \"../ProgressBar\";\nimport { formatCpuPercent } from \"./process-tree\";\nimport type { ProcessNodeRow } from \"./types\";\n\nfunction Usage({ resource, pid, value, percent, title }: { resource: \"CPU\" | \"RAM\"; pid: number; value: string; percent: number | null | undefined; title: string }) {\n const label = `${resource} for pid ${pid}`;\n return <div className=\"w-28 shrink-0 text-xs tabular-nums\" title={title}>\n <div className=\"mb-0.5 flex justify-between gap-1 text-muted-foreground\"><span>{resource}</span><span>{value}</span></div>\n {percent == null\n ? <div role=\"progressbar\" aria-label={label} aria-valuetext=\"Waiting for sample\" aria-valuemin={0} aria-valuemax={100} className=\"h-1 rounded-full bg-muted\" />\n : <ProgressBar label={label} total={100} height=\"h-1\" segments={[{ count: Math.max(0, Math.min(100, percent)), color: \"bg-primary\", label: value }]} />}\n </div>;\n}\n\nexport function ProcessUsageBars({ row, memoryPercent }: { row: ProcessNodeRow; memoryPercent: number | undefined }) {\n return <div className=\"flex shrink-0 gap-3\">\n <Usage resource=\"CPU\" pid={row.pid} value={formatCpuPercent(row.cpuPercent)} percent={row.cpuPercent} title={`Peak ${formatCpuPercent(row.peakCpuPercent)} · CPU per core`} />\n <Usage resource=\"RAM\" pid={row.pid} value={formatBytes(row.rssBytes)} percent={memoryPercent} title={`Peak ${formatBytes(row.peakRssBytes)}${memoryPercent === undefined ? \"\" : ` · ${memoryPercent.toFixed(1)}% of host RAM`}`} />\n </div>;\n}\n"],"mappings":";;;;;AAKA,SAAS,MAAM,EAAE,UAAU,KAAK,OAAO,SAAS,SAAqH;CACnK,MAAM,QAAQ,GAAG,SAAS,WAAW;CACrC,OAAO,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;EAAK,WAAU;EAA4C;EAA3D,UAAA,CACL,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CAAyE,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD,EAAA,UAAO,SAAe,CAAA,GAAC,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD,EAAA,UAAO,MAAY,CAAA,CAAM;EACxH,CAAA,GAAA,WAAW,OACR,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;GAAK,MAAK;GAAc,cAAY;GAAO,kBAAe;GAAqB,iBAAe;GAAG,iBAAe;GAAK,WAAU;EAA6B,CAAA,IAC5J,iBAAA,GAAA,kBAAA,IAAA,CAACA,oBAAAA,aAAD;GAAoB;GAAO,OAAO;GAAK,QAAO;GAAM,UAAU,CAAC;IAAE,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,KAAK,OAAO,CAAC;IAAG,OAAO;IAAc,OAAO;GAAM,CAAC;EAAI,CAAA,CACrJ;;AACP;AAEA,SAAgB,iBAAiB,EAAE,KAAK,iBAA6E;CACnH,OAAO,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACL,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;GAAO,UAAS;GAAM,KAAK,IAAI;GAAK,OAAOC,qBAAAA,iBAAiB,IAAI,UAAU;GAAG,SAAS,IAAI;GAAY,OAAO,QAAQA,qBAAAA,iBAAiB,IAAI,cAAc,EAAE;EAAmB,CAAA,GAC7K,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;GAAO,UAAS;GAAM,KAAK,IAAI;GAAK,OAAOC,eAAAA,YAAY,IAAI,QAAQ;GAAG,SAAS;GAAe,OAAO,QAAQA,eAAAA,YAAY,IAAI,YAAY,IAAI,kBAAkB,KAAA,IAAY,KAAK,MAAM,cAAc,QAAQ,CAAC,EAAE;EAAmB,CAAA,CAC/N;;AACP"}
1
+ {"version":3,"file":"ProcessUsageBars.cjs","names":["formatCpuPercent","formatBytes","ProgressBars","UiChip","UiMemoryStick"],"sources":["../../../src/data/traces/ProcessUsageBars.tsx"],"sourcesContent":["import { UiChip, UiMemoryStick } from \"../../icons\";\nimport { formatBytes } from \"../../lib/format\";\nimport { ProgressBars, type ProgressBarsUnit } from \"../ProgressBars\";\nimport { formatCpuPercent } from \"./process-tree\";\nimport type { ProcessNodeRow } from \"./types\";\n\nconst GiB = 1024 ** 3;\n\n/** One bar per core (100% CPU), captioned as a CPU %. */\nconst CPU_UNIT: ProgressBarsUnit = { perBar: 100, label: \"\", barLabel: \"core\", format: (cores) => formatCpuPercent(cores * 100) };\n\n/** One bar per GB of RSS, captioned in the readable byte size. */\nconst RSS_UNIT: ProgressBarsUnit = { perBar: GiB, label: \"\", barLabel: \"GB\", format: (gb) => formatBytes(gb * GiB) };\n\nexport function ProcessUsageBars({ row, memoryPercent }: { row: ProcessNodeRow; memoryPercent: number | undefined }) {\n return <div className=\"flex shrink-0 items-center gap-3\">\n <ProgressBars variant=\"cell\" orientation=\"vertical\" showLabel={false} icon={UiChip} unit={CPU_UNIT}\n title={`CPU for pid ${row.pid}`} usage={row.cpuPercent ?? undefined}\n hoverFooter={`Peak ${formatCpuPercent(row.peakCpuPercent)} · one bar per core`} />\n <ProgressBars variant=\"cell\" orientation=\"vertical\" showLabel={false} icon={UiMemoryStick} unit={RSS_UNIT}\n title={`RAM for pid ${row.pid}`} usage={row.rssBytes}\n hoverFooter={`Peak ${formatBytes(row.peakRssBytes)}${memoryPercent === undefined ? \"\" : ` · ${memoryPercent.toFixed(1)}% of host RAM`} · one bar per GB`} />\n </div>;\n}\n"],"mappings":";;;;;;;AAMA,IAAM,MAAM,QAAQ;;AAGpB,IAAM,WAA6B;CAAE,QAAQ;CAAK,OAAO;CAAI,UAAU;CAAQ,SAAS,UAAUA,qBAAAA,iBAAiB,QAAQ,GAAG;AAAE;;AAGhI,IAAM,WAA6B;CAAE,QAAQ;CAAK,OAAO;CAAI,UAAU;CAAM,SAAS,OAAOC,eAAAA,YAAY,KAAK,GAAG;AAAE;AAEnH,SAAgB,iBAAiB,EAAE,KAAK,iBAA6E;CACnH,OAAO,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACL,iBAAA,GAAA,kBAAA,IAAA,CAACC,qBAAAA,cAAD;GAAc,SAAQ;GAAO,aAAY;GAAW,WAAW;GAAO,MAAMC,eAAAA;GAAQ,MAAM;GACxF,OAAO,eAAe,IAAI;GAAO,OAAO,IAAI,cAAc,KAAA;GAC1D,aAAa,QAAQH,qBAAAA,iBAAiB,IAAI,cAAc,EAAE;EAAuB,CAAA,GACnF,iBAAA,GAAA,kBAAA,IAAA,CAACE,qBAAAA,cAAD;GAAc,SAAQ;GAAO,aAAY;GAAW,WAAW;GAAO,MAAME,sBAAAA;GAAe,MAAM;GAC/F,OAAO,eAAe,IAAI;GAAO,OAAO,IAAI;GAC5C,aAAa,QAAQH,eAAAA,YAAY,IAAI,YAAY,IAAI,kBAAkB,KAAA,IAAY,KAAK,MAAM,cAAc,QAAQ,CAAC,EAAE,eAAe;EAAqB,CAAA,CAC1J;;AACP"}
@@ -1 +1 @@
1
- {"version":3,"file":"ProcessUsageBars.d.ts","sourceRoot":"","sources":["../../../src/data/traces/ProcessUsageBars.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAY9C,wBAAgB,gBAAgB,CAAC,EAAE,GAAG,EAAE,aAAa,EAAE,EAAE;IAAE,GAAG,EAAE,cAAc,CAAC;IAAC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,+BAKlH"}
1
+ {"version":3,"file":"ProcessUsageBars.d.ts","sourceRoot":"","sources":["../../../src/data/traces/ProcessUsageBars.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAU9C,wBAAgB,gBAAgB,CAAC,EAAE,GAAG,EAAE,aAAa,EAAE,EAAE;IAAE,GAAG,EAAE,cAAc,CAAC;IAAC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,+BASlH"}
@@ -1,50 +1,46 @@
1
+ import { UiChip } from "../../icons/components/UiChip.js";
2
+ import { UiMemoryStick } from "../../icons/components/UiMemoryStick.js";
1
3
  import { formatBytes } from "../../lib/format.js";
2
- import { ProgressBar } from "../ProgressBar.js";
4
+ import { ProgressBars } from "../ProgressBars.js";
3
5
  import { formatCpuPercent } from "./process-tree.js";
4
6
  import { jsx, jsxs } from "react/jsx-runtime";
5
7
  // src/data/traces/ProcessUsageBars.tsx
6
- function Usage({ resource, pid, value, percent, title }) {
7
- const label = `${resource} for pid ${pid}`;
8
- return /* @__PURE__ */ jsxs("div", {
9
- className: "w-28 shrink-0 text-xs tabular-nums",
10
- title,
11
- children: [/* @__PURE__ */ jsxs("div", {
12
- className: "mb-0.5 flex justify-between gap-1 text-muted-foreground",
13
- children: [/* @__PURE__ */ jsx("span", { children: resource }), /* @__PURE__ */ jsx("span", { children: value })]
14
- }), percent == null ? /* @__PURE__ */ jsx("div", {
15
- role: "progressbar",
16
- "aria-label": label,
17
- "aria-valuetext": "Waiting for sample",
18
- "aria-valuemin": 0,
19
- "aria-valuemax": 100,
20
- className: "h-1 rounded-full bg-muted"
21
- }) : /* @__PURE__ */ jsx(ProgressBar, {
22
- label,
23
- total: 100,
24
- height: "h-1",
25
- segments: [{
26
- count: Math.max(0, Math.min(100, percent)),
27
- color: "bg-primary",
28
- label: value
29
- }]
30
- })]
31
- });
32
- }
8
+ var GiB = 1024 ** 3;
9
+ /** One bar per core (100% CPU), captioned as a CPU %. */
10
+ var CPU_UNIT = {
11
+ perBar: 100,
12
+ label: "",
13
+ barLabel: "core",
14
+ format: (cores) => formatCpuPercent(cores * 100)
15
+ };
16
+ /** One bar per GB of RSS, captioned in the readable byte size. */
17
+ var RSS_UNIT = {
18
+ perBar: GiB,
19
+ label: "",
20
+ barLabel: "GB",
21
+ format: (gb) => formatBytes(gb * GiB)
22
+ };
33
23
  function ProcessUsageBars({ row, memoryPercent }) {
34
24
  return /* @__PURE__ */ jsxs("div", {
35
- className: "flex shrink-0 gap-3",
36
- children: [/* @__PURE__ */ jsx(Usage, {
37
- resource: "CPU",
38
- pid: row.pid,
39
- value: formatCpuPercent(row.cpuPercent),
40
- percent: row.cpuPercent,
41
- title: `Peak ${formatCpuPercent(row.peakCpuPercent)} · CPU per core`
42
- }), /* @__PURE__ */ jsx(Usage, {
43
- resource: "RAM",
44
- pid: row.pid,
45
- value: formatBytes(row.rssBytes),
46
- percent: memoryPercent,
47
- title: `Peak ${formatBytes(row.peakRssBytes)}${memoryPercent === void 0 ? "" : ` · ${memoryPercent.toFixed(1)}% of host RAM`}`
25
+ className: "flex shrink-0 items-center gap-3",
26
+ children: [/* @__PURE__ */ jsx(ProgressBars, {
27
+ variant: "cell",
28
+ orientation: "vertical",
29
+ showLabel: false,
30
+ icon: UiChip,
31
+ unit: CPU_UNIT,
32
+ title: `CPU for pid ${row.pid}`,
33
+ usage: row.cpuPercent ?? void 0,
34
+ hoverFooter: `Peak ${formatCpuPercent(row.peakCpuPercent)} · one bar per core`
35
+ }), /* @__PURE__ */ jsx(ProgressBars, {
36
+ variant: "cell",
37
+ orientation: "vertical",
38
+ showLabel: false,
39
+ icon: UiMemoryStick,
40
+ unit: RSS_UNIT,
41
+ title: `RAM for pid ${row.pid}`,
42
+ usage: row.rssBytes,
43
+ hoverFooter: `Peak ${formatBytes(row.peakRssBytes)}${memoryPercent === void 0 ? "" : ` · ${memoryPercent.toFixed(1)}% of host RAM`} · one bar per GB`
48
44
  })]
49
45
  });
50
46
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ProcessUsageBars.js","names":[],"sources":["../../../src/data/traces/ProcessUsageBars.tsx"],"sourcesContent":["import { formatBytes } from \"../../lib/format\";\nimport { ProgressBar } from \"../ProgressBar\";\nimport { formatCpuPercent } from \"./process-tree\";\nimport type { ProcessNodeRow } from \"./types\";\n\nfunction Usage({ resource, pid, value, percent, title }: { resource: \"CPU\" | \"RAM\"; pid: number; value: string; percent: number | null | undefined; title: string }) {\n const label = `${resource} for pid ${pid}`;\n return <div className=\"w-28 shrink-0 text-xs tabular-nums\" title={title}>\n <div className=\"mb-0.5 flex justify-between gap-1 text-muted-foreground\"><span>{resource}</span><span>{value}</span></div>\n {percent == null\n ? <div role=\"progressbar\" aria-label={label} aria-valuetext=\"Waiting for sample\" aria-valuemin={0} aria-valuemax={100} className=\"h-1 rounded-full bg-muted\" />\n : <ProgressBar label={label} total={100} height=\"h-1\" segments={[{ count: Math.max(0, Math.min(100, percent)), color: \"bg-primary\", label: value }]} />}\n </div>;\n}\n\nexport function ProcessUsageBars({ row, memoryPercent }: { row: ProcessNodeRow; memoryPercent: number | undefined }) {\n return <div className=\"flex shrink-0 gap-3\">\n <Usage resource=\"CPU\" pid={row.pid} value={formatCpuPercent(row.cpuPercent)} percent={row.cpuPercent} title={`Peak ${formatCpuPercent(row.peakCpuPercent)} · CPU per core`} />\n <Usage resource=\"RAM\" pid={row.pid} value={formatBytes(row.rssBytes)} percent={memoryPerc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","names":[],"sources":["../../../src/data/traces/ProcessUsageBars.tsx"],"sourcesContent":["import { UiChip, UiMemoryStick } from \"../../icons\";\nimport { formatBytes } from \"../../lib/format\";\nimport { ProgressBars, type ProgressBarsUnit } from \"../ProgressBars\";\nimport { formatCpuPercent } from \"./process-tree\";\nimport type { ProcessNodeRow } from \"./types\";\n\nconst GiB = 1024 ** 3;\n\n/** One bar per core (100% CPU), captioned as a CPU %. */\nconst CPU_UNIT: ProgressBarsUnit = { perBar: 100, label: \"\", barLabel: \"core\", format: (cores) => formatCpuPercent(cores * 100) };\n\n/** One bar per GB of RSS, captioned in the readable byte size. */\nconst RSS_UNIT: ProgressBarsUnit = { perBar: GiB, label: \"\", barLabel: \"GB\", format: (gb) => formatBytes(gb * GiB) };\n\nexport function ProcessUsageBars({ row, memoryPercent }: { row: ProcessNodeRow; memoryPercent: number | undefined }) {\n return <div className=\"flex shrink-0 items-center gap-3\">\n <ProgressBars variant=\"cell\" orientation=\"vertical\" showLabel={false} icon={UiChip} unit={CPU_UNIT}\n title={`CPU for pid ${row.pid}`} usage={row.cpuPercent ?? undefined}\n hoverFooter={`Peak ${formatCpuPercent(row.peakCpuPercent)} · one bar per core`} />\n <ProgressBars variant=\"cell\" orientation=\"vertical\" showLabel={false} icon={UiMemoryStick} unit={RSS_UNIT}\n title={`RAM for pid ${row.pid}`} usage={row.rssBytes}\n hoverFooter={`Peak ${formatBytes(row.peakRssBytes)}${memoryPercent === undefined ? \"\" : ` · ${memoryPercent.toFixed(1)}% of host RAM`} · one bar per GB`} />\n </div>;\n}\n"],"mappings":";;;;;;;AAMA,IAAM,MAAM,QAAQ;;AAGpB,IAAM,WAA6B;CAAE,QAAQ;CAAK,OAAO;CAAI,UAAU;CAAQ,SAAS,UAAU,iBAAiB,QAAQ,GAAG;AAAE;;AAGhI,IAAM,WAA6B;CAAE,QAAQ;CAAK,OAAO;CAAI,UAAU;CAAM,SAAS,OAAO,YAAY,KAAK,GAAG;AAAE;AAEnH,SAAgB,iBAAiB,EAAE,KAAK,iBAA6E;CACnH,OAAO,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACL,oBAAC,cAAD;GAAc,SAAQ;GAAO,aAAY;GAAW,WAAW;GAAO,MAAM;GAAQ,MAAM;GACxF,OAAO,eAAe,IAAI;GAAO,OAAO,IAAI,cAAc,KAAA;GAC1D,aAAa,QAAQ,iBAAiB,IAAI,cAAc,EAAE;EAAuB,CAAA,GACnF,oBAAC,cAAD;GAAc,SAAQ;GAAO,aAAY;GAAW,WAAW;GAAO,MAAM;GAAe,MAAM;GAC/F,OAAO,eAAe,IAAI;GAAO,OAAO,IAAI;GAC5C,aAAa,QAAQ,YAAY,IAAI,YAAY,IAAI,kBAAkB,KAAA,IAAY,KAAK,MAAM,cAAc,QAAQ,CAAC,EAAE,eAAe;EAAqB,CAAA,CAC1J;;AACP"}
@@ -90,6 +90,40 @@ function processSeries(samples, key) {
90
90
  rss: own.map((sample) => sample.rssBytes)
91
91
  };
92
92
  }
93
+ /**
94
+ * The combined CPU % and RSS bytes of a process and all its descendants at
95
+ * each sampling tick (one tick is one sampling round across every process), in
96
+ * tick order, so the peak of a series is the most the subtree used at once. A
97
+ * tick's CPU sums the known readings and is left out when none is known.
98
+ * The latest tick retains its CPU and RSS totals even when CPU is unknown.
99
+ */
100
+ function subtreeSeries(rows, samples, key) {
101
+ const keys = /* @__PURE__ */ new Set([key]);
102
+ for (let grew = true; grew;) {
103
+ grew = false;
104
+ for (const row of rows) if (row.parentKey && keys.has(row.parentKey) && !keys.has(row.key)) {
105
+ keys.add(row.key);
106
+ grew = true;
107
+ }
108
+ }
109
+ const ticks = /* @__PURE__ */ new Map();
110
+ for (const sample of samples) {
111
+ if (!keys.has(sample.key)) continue;
112
+ const total = ticks.get(sample.tick) ?? {
113
+ cpu: null,
114
+ rss: 0
115
+ };
116
+ total.rss += sample.rssBytes;
117
+ if (sample.cpuPercent != null) total.cpu = (total.cpu ?? 0) + sample.cpuPercent;
118
+ ticks.set(sample.tick, total);
119
+ }
120
+ const ordered = [...ticks].sort(([a], [b]) => a - b).map(([, total]) => total);
121
+ return {
122
+ cpu: ordered.flatMap((total) => total.cpu === null ? [] : [total.cpu]),
123
+ rss: ordered.map((total) => total.rss),
124
+ latest: ordered.at(-1)
125
+ };
126
+ }
93
127
  /** SVG polyline points for `values` in a `width` x `height` box, zero at the bottom and the maximum at the top. */
94
128
  function sparklinePoints(values, width, height) {
95
129
  if (values.length < 2) return void 0;
@@ -110,5 +144,6 @@ exports.processLifetimeMs = processLifetimeMs;
110
144
  exports.processSeries = processSeries;
111
145
  exports.pruneExitedProcesses = pruneExitedProcesses;
112
146
  exports.sparklinePoints = sparklinePoints;
147
+ exports.subtreeSeries = subtreeSeries;
113
148
 
114
149
  //# sourceMappingURL=process-tree.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"process-tree.cjs","names":[],"sources":["../../../src/data/traces/process-tree.ts"],"sourcesContent":["import type { ProcessNodeRow, ProcessSampleRow } from \"./types\";\n\nexport type ProcessTreeNode = {\n row: ProcessNodeRow;\n children: ProcessTreeNode[];\n /** The process has exited: by its status, or because an exit time was recorded. */\n exited: boolean;\n};\n\nconst byStart = (a: ProcessTreeNode, b: ProcessTreeNode) =>\n Date.parse(a.row.startedAt) - Date.parse(b.row.startedAt) || a.row.pid - b.row.pid;\n\n/**\n * Builds the forest a `process_tree` stream describes: each row under its\n * `parentKey`. A row whose parent was never recorded (the capture began below\n * it) becomes a root. The stream holds each process once, so a repeated key or a\n * parent cycle is a corrupt capture and throws.\n */\nexport function buildProcessForest(rows: ProcessNodeRow[]): ProcessTreeNode[] {\n const nodes = new Map<string, ProcessTreeNode>();\n for (const row of rows) {\n if (nodes.has(row.key)) throw new Error(`process tree key \"${row.key}\" appears twice`);\n nodes.set(row.key, { row, children: [], exited: isProcessExited(row) });\n }\n\n const roots: ProcessTreeNode[] = [];\n for (const node of nodes.values()) {\n const parent = node.row.parentKey ? nodes.get(node.row.parentKey) : undefined;\n (parent ? parent.children : roots).push(node);\n }\n\n roots.sort((a, b) => Number(Boolean(b.row.isRoot)) - Number(Boolean(a.row.isRoot)) || byStart(a, b));\n const reached = flattenForest(roots);\n if (reached.length !== nodes.size) {\n const lost = [...nodes.keys()].filter((key) => !reached.some((node) => node.row.key === key));\n throw new Error(`process tree has a parent cycle among keys ${lost.map((key) => `\"${key}\"`).join(\", \")}`);\n }\n for (const node of nodes.values()) node.children.sort(byStart);\n return roots;\n}\n\n/**\n * Drops exited processes from a forest, keeping an exited process only while it\n * still has a live descendant to hang off. Returns new nodes; the input is not\n * modified.\n */\nexport function pruneExitedProcesses(roots: ProcessTreeNode[]): ProcessTreeNode[] {\n return roots.flatMap((node) => {\n const children = pruneExitedProcesses(node.children);\n return node.exited && children.length === 0 ? [] : [{ ...node, children }];\n });\n}\n\n/** How long the process lived: to its exit, else to the last time it was seen. */\nexport function processLifetimeMs(row: ProcessNodeRow): number {\n return Date.parse(row.exitedAt ?? row.lastSeenAt) - Date.parse(row.startedAt);\n}\n\n/** A trace timestamp as local `YYYY-MM-DD HH:MM:SS`; text that is not a date is returned unchanged. */\nexport function formatProcessTimestamp(iso: string): string {\n const date = new Date(iso);\n if (Number.isNaN(date.getTime())) return iso;\n const pad = (n: number) => String(n).padStart(2, \"0\");\n return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;\n}\n\n/** The process has exited: by its status, or because an exit time was recorded. */\nexport function isProcessExited(row: ProcessNodeRow): boolean {\n return row.status === \"exited\" || Boolean(row.exitedAt);\n}\n\n/** The forest depth-first, parents before children. */\nexport function flattenForest(roots: ProcessTreeNode[]): ProcessTreeNode[] {\n const flat: ProcessTreeNode[] = [];\n const visit = (node: ProcessTreeNode) => {\n flat.push(node);\n node.children.forEach(visit);\n };\n roots.forEach(visit);\n return flat;\n}\n\n/** A CPU % for display, \"—\" while it is still unknown. */\nexport function formatCpuPercent(value: number | null | undefined): string {\n return value == null ? \"—\" : `${value.toFixed(1)}%`;\n}\n\nfunction knownCpu(samples: ProcessSampleRow[]): number[] {\n return samples.flatMap((sample) => (sample.cpuPercent == null ? [] : [sample.cpuPercent]));\n}\n\n/** Each process's known CPU % over its samples, in tick order. */\nexport function cpuSeriesByKey(samples: ProcessSampleRow[]): Map<string, number[]> {\n const byKey = new Map<string, ProcessSampleRow[]>();\n for (const sample of samples) byKey.set(sample.key, [...(byKey.get(sample.key) ?? []), sample]);\n return new Map([...byKey].map(([key, list]) => [key, knownCpu(list.sort((a, b) => a.tick - b.tick))]));\n}\n\n/** One process's known CPU % and RSS bytes over its samples, in tick order. */\nexport function processSeries(samples: ProcessSampleRow[], key: string): { cpu: number[]; rss: number[] } {\n const own = samples.filter((sample) => sample.key === key).sort((a, b) => a.tick - b.tick);\n return { cpu: knownCpu(own), rss: own.map((sample) => sample.rssBytes) };\n}\n\n/** SVG polyline points for `values` in a `width` x `height` box, zero at the bottom and the maximum at the top. */\nexport function sparklinePoints(values: number[], width: number, height: number): string | undefined {\n if (values.length < 2) return undefined;\n const max = Math.max(...values);\n return values\n .map((value, index) => {\n const x = (index / (values.length - 1)) * width;\n const y = max === 0 ? height : height - (value / max) * height;\n return `${x.toFixed(1)},${y.toFixed(1)}`;\n })\n .join(\" \");\n}\n"],"mappings":";AASA,IAAM,WAAW,GAAoB,MACnC,KAAK,MAAM,EAAE,IAAI,SAAS,IAAI,KAAK,MAAM,EAAE,IAAI,SAAS,KAAK,EAAE,IAAI,MAAM,EAAE,IAAI;;;;;;;AAQjF,SAAgB,mBAAmB,MAA2C;CAC5E,MAAM,wBAAQ,IAAI,IAA6B;CAC/C,KAAK,MAAM,OAAO,MAAM;EACtB,IAAI,MAAM,IAAI,IAAI,GAAG,GAAG,MAAM,IAAI,MAAM,qBAAqB,IAAI,IAAI,gBAAgB;EACrF,MAAM,IAAI,IAAI,KAAK;GAAE;GAAK,UAAU,CAAC;GAAG,QAAQ,gBAAgB,GAAG;EAAE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AAE,OAAO,EAAE,IAAI;CACzF,OAAO;EAAE,KAAK,SAAS,GAAG;EAAG,KAAK,IAAI,KAAK,WAAW,OAAO,QAAQ;CAAE;AACzE;;AAGA,SAAgB,gBAAgB,QAAkB,OAAe,QAAoC;CACnG,IAAI,OAAO,SAAS,GAAG,OAAO,KAAA;CAC9B,MAAM,MAAM,KAAK,IAAI,GAAG,MAAM;CAC9B,OAAO,OACJ,KAAK,OAAO,UAAU;EACrB,MAAM,IAAK,SAAS,OAAO,SAAS,KAAM;EAC1C,MAAM,IAAI,QAAQ,IAAI,SAAS,SAAU,QAAQ,MAAO;EACxD,OAAO,GAAG,EAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC;CACvC,CAAC,CAAC,CACD,KAAK,GAAG;AACb"}
1
+ {"version":3,"file":"process-tree.cjs","names":[],"sources":["../../../src/data/traces/process-tree.ts"],"sourcesContent":["import type { ProcessNodeRow, ProcessSampleRow } from \"./types\";\n\nexport type ProcessTreeNode = {\n row: ProcessNodeRow;\n children: ProcessTreeNode[];\n /** The process has exited: by its status, or because an exit time was recorded. */\n exited: boolean;\n};\n\nconst byStart = (a: ProcessTreeNode, b: ProcessTreeNode) =>\n Date.parse(a.row.startedAt) - Date.parse(b.row.startedAt) || a.row.pid - b.row.pid;\n\n/**\n * Builds the forest a `process_tree` stream describes: each row under its\n * `parentKey`. A row whose parent was never recorded (the capture began below\n * it) becomes a root. The stream holds each process once, so a repeated key or a\n * parent cycle is a corrupt capture and throws.\n */\nexport function buildProcessForest(rows: ProcessNodeRow[]): ProcessTreeNode[] {\n const nodes = new Map<string, ProcessTreeNode>();\n for (const row of rows) {\n if (nodes.has(row.key)) throw new Error(`process tree key \"${row.key}\" appears twice`);\n nodes.set(row.key, { row, children: [], exited: isProcessExited(row) });\n }\n\n const roots: ProcessTreeNode[] = [];\n for (const node of nodes.values()) {\n const parent = node.row.parentKey ? nodes.get(node.row.parentKey) : undefined;\n (parent ? parent.children : roots).push(node);\n }\n\n roots.sort((a, b) => Number(Boolean(b.row.isRoot)) - Number(Boolean(a.row.isRoot)) || byStart(a, b));\n const reached = flattenForest(roots);\n if (reached.length !== nodes.size) {\n const lost = [...nodes.keys()].filter((key) => !reached.some((node) => node.row.key === key));\n throw new Error(`process tree has a parent cycle among keys ${lost.map((key) => `\"${key}\"`).join(\", \")}`);\n }\n for (const node of nodes.values()) node.children.sort(byStart);\n return roots;\n}\n\n/**\n * Drops exited processes from a forest, keeping an exited process only while it\n * still has a live descendant to hang off. Returns new nodes; the input is not\n * modified.\n */\nexport function pruneExitedProcesses(roots: ProcessTreeNode[]): ProcessTreeNode[] {\n return roots.flatMap((node) => {\n const children = pruneExitedProcesses(node.children);\n return node.exited && children.length === 0 ? [] : [{ ...node, children }];\n });\n}\n\n/** How long the process lived: to its exit, else to the last time it was seen. */\nexport function processLifetimeMs(row: ProcessNodeRow): number {\n return Date.parse(row.exitedAt ?? row.lastSeenAt) - Date.parse(row.startedAt);\n}\n\n/** A trace timestamp as local `YYYY-MM-DD HH:MM:SS`; text that is not a date is returned unchanged. */\nexport function formatProcessTimestamp(iso: string): string {\n const date = new Date(iso);\n if (Number.isNaN(date.getTime())) return iso;\n const pad = (n: number) => String(n).padStart(2, \"0\");\n return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;\n}\n\n/** The process has exited: by its status, or because an exit time was recorded. */\nexport function isProcessExited(row: ProcessNodeRow): boolean {\n return row.status === \"exited\" || Boolean(row.exitedAt);\n}\n\n/** The forest depth-first, parents before children. */\nexport function flattenForest(roots: ProcessTreeNode[]): ProcessTreeNode[] {\n const flat: ProcessTreeNode[] = [];\n const visit = (node: ProcessTreeNode) => {\n flat.push(node);\n node.children.forEach(visit);\n };\n roots.forEach(visit);\n return flat;\n}\n\n/** A CPU % for display, \"—\" while it is still unknown. */\nexport function formatCpuPercent(value: number | null | undefined): string {\n return value == null ? \"—\" : `${value.toFixed(1)}%`;\n}\n\nfunction knownCpu(samples: ProcessSampleRow[]): number[] {\n return samples.flatMap((sample) => (sample.cpuPercent == null ? [] : [sample.cpuPercent]));\n}\n\n/** Each process's known CPU % over its samples, in tick order. */\nexport function cpuSeriesByKey(samples: ProcessSampleRow[]): Map<string, number[]> {\n const byKey = new Map<string, ProcessSampleRow[]>();\n for (const sample of samples) byKey.set(sample.key, [...(byKey.get(sample.key) ?? []), sample]);\n return new Map([...byKey].map(([key, list]) => [key, knownCpu(list.sort((a, b) => a.tick - b.tick))]));\n}\n\n/** One process's known CPU % and RSS bytes over its samples, in tick order. */\nexport function processSeries(samples: ProcessSampleRow[], key: string): { cpu: number[]; rss: number[] } {\n const own = samples.filter((sample) => sample.key === key).sort((a, b) => a.tick - b.tick);\n return { cpu: knownCpu(own), rss: own.map((sample) => sample.rssBytes) };\n}\n\n/**\n * The combined CPU % and RSS bytes of a process and all its descendants at\n * each sampling tick (one tick is one sampling round across every process), in\n * tick order, so the peak of a series is the most the subtree used at once. A\n * tick's CPU sums the known readings and is left out when none is known.\n * The latest tick retains its CPU and RSS totals even when CPU is unknown.\n */\nexport function subtreeSeries(rows: ProcessNodeRow[], samples: ProcessSampleRow[], key: string): {\n cpu: number[];\n rss: number[];\n latest: { cpu: number | null; rss: number } | undefined;\n} {\n const keys = new Set([key]);\n for (let grew = true; grew; ) {\n grew = false;\n for (const row of rows) {\n if (row.parentKey && keys.has(row.parentKey) && !keys.has(row.key)) {\n keys.add(row.key);\n grew = true;\n }\n }\n }\n const ticks = new Map<number, { cpu: number | null; rss: number }>();\n for (const sample of samples) {\n if (!keys.has(sample.key)) continue;\n const total = ticks.get(sample.tick) ?? { cpu: null, rss: 0 };\n total.rss += sample.rssBytes;\n if (sample.cpuPercent != null) total.cpu = (total.cpu ?? 0) + sample.cpuPercent;\n ticks.set(sample.tick, total);\n }\n const ordered = [...ticks].sort(([a], [b]) => a - b).map(([, total]) => total);\n return {\n cpu: ordered.flatMap((total) => (total.cpu === null ? [] : [total.cpu])),\n rss: ordered.map((total) => total.rss),\n latest: ordered.at(-1),\n };\n}\n\n/** SVG polyline points for `values` in a `width` x `height` box, zero at the bottom and the maximum at the top. */\nexport function sparklinePoints(values: number[], width: number, height: number): string | undefined {\n if (values.length < 2) return undefined;\n const max = Math.max(...values);\n return values\n .map((value, index) => {\n const x = (index / (values.length - 1)) * width;\n const y = max === 0 ? height : height - (value / max) * height;\n return `${x.toFixed(1)},${y.toFixed(1)}`;\n })\n .join(\" \");\n}\n"],"mappings":";AASA,IAAM,WAAW,GAAoB,MACnC,KAAK,MAAM,EAAE,IAAI,SAAS,IAAI,KAAK,MAAM,EAAE,IAAI,SAAS,KAAK,EAAE,IAAI,MAAM,EAAE,IAAI;;;;;;;AAQjF,SAAgB,mBAAmB,MAA2C;CAC5E,MAAM,wBAAQ,IAAI,IAA6B;CAC/C,KAAK,MAAM,OAAO,MAAM;EACtB,IAAI,MAAM,IAAI,IAAI,GAAG,GAAG,MAAM,IAAI,MAAM,qBAAqB,IAAI,IAAI,gBAAgB;EACrF,MAAM,IAAI,IAAI,KAAK;GAAE;GAAK,UAAU,CAAC;GAAG,QAAQ,gBAAgB,GAAG;EAAE,CAAC;CACxE;CAEA,MAAM,QAA2B,CAAC;CAClC,KAAK,MAAM,QAAQ,MAAM,OAAO,GAAG;EACjC,MAAM,SAAS,KAAK,IAAI,YAAY,MAAM,IAAI,KAAK,IAAI,SAAS,IAAI,KAAA;EACpE,CAAC,SAAS,OAAO,WAAW,MAAA,CAAO,KAAK,IAAI;CAC9C;CAEA,MAAM,MAAM,GAAG,MAAM,OAAO,QAAQ,EAAE,IAAI,MAAM,CAAC,IAAI,OAAO,QAAQ,EAAE,IAAI,MAAM,CAAC,KAAK,QAAQ,GAAG,CAAC,CAAC;CACnG,MAAM,UAAU,cAAc,KAAK;CACnC,IAAI,QAAQ,WAAW,MAAM,MAAM;EACjC,MAAM,OAAO,CAAC,GAAG,MAAM,KAAK,CAAC,CAAC,C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SAAS;EAC5B,IAAI,CAAC,KAAK,IAAI,OAAO,GAAG,GAAG;EAC3B,MAAM,QAAQ,MAAM,IAAI,OAAO,IAAI,KAAK;GAAE,KAAK;GAAM,KAAK;EAAE;EAC5D,MAAM,OAAO,OAAO;EACpB,IAAI,OAAO,cAAc,MAAM,MAAM,OAAO,MAAM,OAAO,KAAK,OAAO;EACrE,MAAM,IAAI,OAAO,MAAM,KAAK;CAC9B;CACA,MAAM,UAAU,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,WAAW,KAAK;CAC7E,OAAO;EACL,KAAK,QAAQ,SAAS,UAAW,MAAM,QAAQ,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAE;EACvE,KAAK,QAAQ,KAAK,UAAU,MAAM,GAAG;EACrC,QAAQ,QAAQ,GAAG,EAAE;CACvB;AACF;;AAGA,SAAgB,gBAAgB,QAAkB,OAAe,QAAoC;CACnG,IAAI,OAAO,SAAS,GAAG,OAAO,KAAA;CAC9B,MAAM,MAAM,KAAK,IAAI,GAAG,MAAM;CAC9B,OAAO,OACJ,KAAK,OAAO,UAAU;EACrB,MAAM,IAAK,SAAS,OAAO,SAAS,KAAM;EAC1C,MAAM,IAAI,QAAQ,IAAI,SAAS,SAAU,QAAQ,MAAO;EACxD,OAAO,GAAG,EAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC;CACvC,CAAC,CAAC,CACD,KAAK,GAAG;AACb"}
@@ -35,6 +35,21 @@ export declare function processSeries(samples: ProcessSampleRow[], key: string):
35
35
  cpu: number[];
36
36
  rss: number[];
37
37
  };
38
+ /**
39
+ * The combined CPU % and RSS bytes of a process and all its descendants at
40
+ * each sampling tick (one tick is one sampling round across every process), in
41
+ * tick order, so the peak of a series is the most the subtree used at once. A
42
+ * tick's CPU sums the known readings and is left out when none is known.
43
+ * The latest tick retains its CPU and RSS totals even when CPU is unknown.
44
+ */
45
+ export declare function subtreeSeries(rows: ProcessNodeRow[], samples: ProcessSampleRow[], key: string): {
46
+ cpu: number[];
47
+ rss: number[];
48
+ latest: {
49
+ cpu: number | null;
50
+ rss: number;
51
+ } | undefined;
52
+ };
38
53
  /** SVG polyline points for `values` in a `width` x `height` box, zero at the bottom and the maximum at the top. */
39
54
  export declare function sparklinePoints(values: number[], width: number, height: number): string | undefined;
40
55
  //# sourceMappingURL=process-tree.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"process-tree.d.ts","sourceRoot":"","sources":["../../../src/data/traces/process-tree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhE,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,EAAE,cAAc,CAAC;IACpB,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,mFAAmF;IACnF,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAKF;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,cAAc,EAAE,GAAG,eAAe,EAAE,CAqB5E;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,eAAe,EAAE,CAKhF;AAED,kFAAkF;AAClF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,cAAc,GAAG,MAAM,CAE7D;AAED,uGAAuG;AACvG,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK1D;AAED,mFAAmF;AACnF,wBAAgB,eAAe,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAE5D;AAED,uDAAuD;AACvD,wBAAgB,aAAa,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,eAAe,EAAE,CAQzE;AAED,0DAA0D;AAC1D,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAEzE;AAMD,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EAAE,GAAG,eAAe,EAAE,CAQzE;AAED,0DAA0D;AAC1D,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAEzE;AAMD,kEAAkE;AAClE,wBAAgB,cAAc,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAIjF;AAED,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,EAAE,CAAC;IAAC,GAAG,EAAE,MAAM,EAAE,CAAA;CAAE,CAGxG;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,cAAc,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG;IAC/F,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;CACzD,CAyBA;AAED,mHAAmH;AACnH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAUnG"}
@@ -90,6 +90,40 @@ function processSeries(samples, key) {
90
90
  rss: own.map((sample) => sample.rssBytes)
91
91
  };
92
92
  }
93
+ /**
94
+ * The combined CPU % and RSS bytes of a process and all its descendants at
95
+ * each sampling tick (one tick is one sampling round across every process), in
96
+ * tick order, so the peak of a series is the most the subtree used at once. A
97
+ * tick's CPU sums the known readings and is left out when none is known.
98
+ * The latest tick retains its CPU and RSS totals even when CPU is unknown.
99
+ */
100
+ function subtreeSeries(rows, samples, key) {
101
+ const keys = /* @__PURE__ */ new Set([key]);
102
+ for (let grew = true; grew;) {
103
+ grew = false;
104
+ for (const row of rows) if (row.parentKey && keys.has(row.parentKey) && !keys.has(row.key)) {
105
+ keys.add(row.key);
106
+ grew = true;
107
+ }
108
+ }
109
+ const ticks = /* @__PURE__ */ new Map();
110
+ for (const sample of samples) {
111
+ if (!keys.has(sample.key)) continue;
112
+ const total = ticks.get(sample.tick) ?? {
113
+ cpu: null,
114
+ rss: 0
115
+ };
116
+ total.rss += sample.rssBytes;
117
+ if (sample.cpuPercent != null) total.cpu = (total.cpu ?? 0) + sample.cpuPercent;
118
+ ticks.set(sample.tick, total);
119
+ }
120
+ const ordered = [...ticks].sort(([a], [b]) => a - b).map(([, total]) => total);
121
+ return {
122
+ cpu: ordered.flatMap((total) => total.cpu === null ? [] : [total.cpu]),
123
+ rss: ordered.map((total) => total.rss),
124
+ latest: ordered.at(-1)
125
+ };
126
+ }
93
127
  /** SVG polyline points for `values` in a `width` x `height` box, zero at the bottom and the maximum at the top. */
94
128
  function sparklinePoints(values, width, height) {
95
129
  if (values.length < 2) return void 0;
@@ -100,6 +134,6 @@ function sparklinePoints(values, width, height) {
100
134
  return `${x.toFixed(1)},${y.toFixed(1)}`;
101
135
  }).join(" ");
102
136
  }
103
- export { buildProcessForest, cpuSeriesByKey, flattenForest, formatCpuPercent, formatProcessTimestamp, isProcessExited, processLifetimeMs, processSeries, pruneExitedProcesses, sparklinePoints };
137
+ export { buildProcessForest, cpuSeriesByKey, flattenForest, formatCpuPercent, formatProcessTimestamp, isProcessExited, processLifetimeMs, processSeries, pruneExitedProcesses, sparklinePoints, subtreeSeries };
104
138
 
105
139
  //# sourceMappingURL=process-tree.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"process-tree.js","names":[],"sources":["../../../src/data/traces/process-tree.ts"],"sourcesContent":["import type { ProcessNodeRow, ProcessSampleRow } from \"./types\";\n\nexport type ProcessTreeNode = {\n row: ProcessNodeRow;\n children: ProcessTreeNode[];\n /** The process has exited: by its status, or because an exit time was recorded. */\n exited: boolean;\n};\n\nconst byStart = (a: ProcessTreeNode, b: ProcessTreeNode) =>\n Date.parse(a.row.startedAt) - Date.parse(b.row.startedAt) || a.row.pid - b.row.pid;\n\n/**\n * Builds the forest a `process_tree` stream describes: each row under its\n * `parentKey`. A row whose parent was never recorded (the capture began below\n * it) becomes a root. The stream holds each process once, so a repeated key or a\n * parent cycle is a corrupt capture and throws.\n */\nexport function buildProcessForest(rows: ProcessNodeRow[]): ProcessTreeNode[] {\n const nodes = new Map<string, ProcessTreeNode>();\n for (const row of rows) {\n if (nodes.has(row.key)) throw new Error(`process tree key \"${row.key}\" appears twice`);\n nodes.set(row.key, { row, children: [], exited: isProcessExited(row) });\n }\n\n const roots: ProcessTreeNode[] = [];\n for (const node of nodes.values()) {\n const parent = node.row.parentKey ? nodes.get(node.row.parentKey) : undefined;\n (parent ? parent.children : roots).push(node);\n }\n\n roots.sort((a, b) => Number(Boolean(b.row.isRoot)) - Number(Boolean(a.row.isRoot)) || byStart(a, b));\n const reached = flattenForest(roots);\n if (reached.length !== nodes.size) {\n const lost = [...nodes.keys()].filter((key) => !reached.some((node) => node.row.key === key));\n throw new Error(`process tree has a parent cycle among keys ${lost.map((key) => `\"${key}\"`).join(\", \")}`);\n }\n for (const node of nodes.values()) node.children.sort(byStart);\n return roots;\n}\n\n/**\n * Drops exited processes from a forest, keeping an exited process only while it\n * still has a live descendant to hang off. Returns new nodes; the input is not\n * modified.\n */\nexport function pruneExitedProcesses(roots: ProcessTreeNode[]): ProcessTreeNode[] {\n return roots.flatMap((node) => {\n const children = pruneExitedProcesses(node.children);\n return node.exited && children.length === 0 ? [] : [{ ...node, children }];\n });\n}\n\n/** How long the process lived: to its exit, else to the last time it was seen. */\nexport function processLifetimeMs(row: ProcessNodeRow): number {\n return Date.parse(row.exitedAt ?? row.lastSeenAt) - Date.parse(row.startedAt);\n}\n\n/** A trace timestamp as local `YYYY-MM-DD HH:MM:SS`; text that is not a date is returned unchanged. */\nexport function formatProcessTimestamp(iso: string): string {\n const date = new Date(iso);\n if (Number.isNaN(date.getTime())) return iso;\n const pad = (n: number) => String(n).padStart(2, \"0\");\n return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;\n}\n\n/** The process has exited: by its status, or because an exit time was recorded. */\nexport function isProcessExited(row: ProcessNodeRow): boolean {\n return row.status === \"exited\" || Boolean(row.exitedAt);\n}\n\n/** The forest depth-first, parents before children. */\nexport function flattenForest(roots: ProcessTreeNode[]): ProcessTreeNode[] {\n const flat: ProcessTreeNode[] = [];\n const visit = (node: ProcessTreeNode) => {\n flat.push(node);\n node.children.forEach(visit);\n };\n roots.forEach(visit);\n return flat;\n}\n\n/** A CPU % for display, \"—\" while it is still unknown. */\nexport function formatCpuPercent(value: number | null | undefined): string {\n return value == null ? \"—\" : `${value.toFixed(1)}%`;\n}\n\nfunction knownCpu(samples: ProcessSampleRow[]): number[] {\n return samples.flatMap((sample) => (sample.cpuPercent == null ? [] : [sample.cpuPercent]));\n}\n\n/** Each process's known CPU % over its samples, in tick order. */\nexport function cpuSeriesByKey(samples: ProcessSampleRow[]): Map<string, number[]> {\n const byKey = new Map<string, ProcessSampleRow[]>();\n for (const sample of samples) byKey.set(sample.key, [...(byKey.get(sample.key) ?? []), sample]);\n return new Map([...byKey].map(([key, list]) => [key, knownCpu(list.sort((a, b) => a.tick - b.tick))]));\n}\n\n/** One process's known CPU % and RSS bytes over its samples, in tick order. */\nexport function processSeries(samples: ProcessSampleRow[], key: string): { cpu: number[]; rss: number[] } {\n const own = samples.filter((sample) => sample.key === key).sort((a, b) => a.tick - b.tick);\n return { cpu: knownCpu(own), rss: own.map((sample) => sample.rssBytes) };\n}\n\n/** SVG polyline points for `values` in a `width` x `height` box, zero at the bottom and the maximum at the top. */\nexport function sparklinePoints(values: number[], width: number, height: number): string | undefined {\n if (values.length < 2) return undefined;\n const max = Math.max(...values);\n return values\n .map((value, index) => {\n const x = (index / (values.length - 1)) * width;\n const y = max === 0 ? height : height - (value / max) * height;\n return `${x.toFixed(1)},${y.toFixed(1)}`;\n })\n .join(\" \");\n}\n"],"mappings":";AASA,IAAM,WAAW,GAAoB,MACnC,KAAK,MAAM,EAAE,IAAI,SAAS,IAAI,KAAK,MAAM,EAAE,IAAI,SAAS,KAAK,EAAE,IAAI,MAAM,EAAE,IAAI;;;;;;;AAQjF,SAAgB,mBAAmB,MAA2C;CAC5E,MAAM,wBAAQ,IAAI,IAA6B;CAC/C,KAAK,MAAM,OAAO,MAAM;EACtB,IAAI,MAAM,IAAI,IAAI,GAAG,GAAG,MAAM,IAAI,MAAM,qBAAqB,IAAI,IAAI,gBAAgB;EACrF,MAAM,IAAI,IAAI,KAAK;GAAE;GAAK,UAAU,CAAC;GAAG,QAAQ,gBAAgB,GAAG;EAAE,CAAC;CACxE;CAEA,MAAM,QAA2B,CAAC;CAClC,KAAK,MAAM,QAAQ,MAAM,OAAO,GAAG;EACjC,MAAM,SAAS,KAAK,IAAI,YAAY,MAAM,IAAI,KAAK,IAAI,SAAS,IAAI,KAAA;EACpE,CAAC,SAAS,OAAO,WAAW,MAAA,CAAO,KAAK,IAAI;CAC9C;CAEA,MAAM,MAAM,GAAG,MAAM,OAAO,QAAQ,EAAE,IAAI,MAAM,CAAC,IAAI,OAAO,QAAQ,EAAE,IAAI,MAAM,CAAC,KAAK,QAAQ,GAAG,CAAC,CAAC;CACnG,MAAM,UAAU,cAAc,KAAK;CACnC,IAAI,QAAQ,WAAW,MAAM,MAAM;EACjC,MAAM,OAAO,CAAC,GAAG,MAAM,KAAK,CAAC,CAAC,CAAC,QAAQ,QAAQ,CAAC,QAAQ,MAAM,SAAS,KAAK,IAAI,QAAQ,GAAG,CAAC;EAC5F,MAAM,IAAI,MAAM,8CAA8C,KAAK,KAAK,QAAQ,IAAI,IAAI,EAAE,CAAC,CAAC,KAAK,IAAI,GAAG;CAC1G;CACA,KAAK,MAAM,Q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,OAAO,cAAc,OAAO,CAAC,IAAI,CAAC,OAAO,UAAU,CAAE;AAC3F;;AAGA,SAAgB,eAAe,SAAoD;CACjF,MAAM,wBAAQ,IAAI,IAAgC;CAClD,KAAK,MAAM,UAAU,SAAS,MAAM,IAAI,OAAO,KAAK,CAAC,GAAI,MAAM,IAAI,OAAO,GAAG,KAAK,CAAC,GAAI,MAAM,CAAC;CAC9F,OAAO,IAAI,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,UAAU,CAAC,KAAK,SAAS,KAAK,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACvG;;AAGA,SAAgB,cAAc,SAA6B,KAA+C;CACxG,MAAM,MAAM,QAAQ,QAAQ,WAAW,OAAO,QAAQ,GAAG,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,IAAI;CACzF,OAAO;EAAE,KAAK,SAAS,GAAG;EAAG,KAAK,IAAI,KAAK,WAAW,OAAO,QAAQ;CAAE;AACzE;;AAGA,SAAgB,gBAAgB,QAAkB,OAAe,QAAoC;CACnG,IAAI,OAAO,SAAS,GAAG,OAAO,KAAA;CAC9B,MAAM,MAAM,KAAK,IAAI,GAAG,MAAM;CAC9B,OAAO,OACJ,KAAK,OAAO,UAAU;EACrB,MAAM,IAAK,SAAS,OAAO,SAAS,KAAM;EAC1C,MAAM,IAAI,QAAQ,IAAI,SAAS,SAAU,QAAQ,MAAO;EACxD,OAAO,GAAG,EAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC;CACvC,CAAC,CAAC,CACD,KAAK,GAAG;AACb"}
1
+ {"version":3,"file":"process-tree.js","names":[],"sources":["../../../src/data/traces/process-tree.ts"],"sourcesContent":["import type { ProcessNodeRow, ProcessSampleRow } from \"./types\";\n\nexport type ProcessTreeNode = {\n row: ProcessNodeRow;\n children: ProcessTreeNode[];\n /** The process has exited: by its status, or because an exit time was recorded. */\n exited: boolean;\n};\n\nconst byStart = (a: ProcessTreeNode, b: ProcessTreeNode) =>\n Date.parse(a.row.startedAt) - Date.parse(b.row.startedAt) || a.row.pid - b.row.pid;\n\n/**\n * Builds the forest a `process_tree` stream describes: each row under its\n * `parentKey`. A row whose parent was never recorded (the capture began below\n * it) becomes a root. The stream holds each process once, so a repeated key or a\n * parent cycle is a corrupt capture and throws.\n */\nexport function buildProcessForest(rows: ProcessNodeRow[]): ProcessTreeNode[] {\n const nodes = new Map<string, ProcessTreeNode>();\n for (const row of rows) {\n if (nodes.has(row.key)) throw new Error(`process tree key \"${row.key}\" appears twice`);\n nodes.set(row.key, { row, children: [], exited: isProcessExited(row) });\n }\n\n const roots: ProcessTreeNode[] = [];\n for (const node of nodes.values()) {\n const parent = node.row.parentKey ? nodes.get(node.row.parentKey) : undefined;\n (parent ? parent.children : roots).push(node);\n }\n\n roots.sort((a, b) => Number(Boolean(b.row.isRoot)) - Number(Boolean(a.row.isRoot)) || byStart(a, b));\n const reached = flattenForest(roots);\n if (reached.length !== nodes.size) {\n const lost = [...nodes.keys()].filter((key) => !reached.some((node) => node.row.key === key));\n throw new Error(`process tree has a parent cycle among keys ${lost.map((key) => `\"${key}\"`).join(\", \")}`);\n }\n for (const node of nodes.values()) node.children.sort(byStart);\n return roots;\n}\n\n/**\n * Drops exited processes from a forest, keeping an exited process only while it\n * still has a live descendant to hang off. Returns new nodes; the input is not\n * modified.\n */\nexport function pruneExitedProcesses(roots: ProcessTreeNode[]): ProcessTreeNode[] {\n return roots.flatMap((node) => {\n const children = pruneExitedProcesses(node.children);\n return node.exited && children.length === 0 ? [] : [{ ...node, children }];\n });\n}\n\n/** How long the process lived: to its exit, else to the last time it was seen. */\nexport function processLifetimeMs(row: ProcessNodeRow): number {\n return Date.parse(row.exitedAt ?? row.lastSeenAt) - Date.parse(row.startedAt);\n}\n\n/** A trace timestamp as local `YYYY-MM-DD HH:MM:SS`; text that is not a date is returned unchanged. */\nexport function formatProcessTimestamp(iso: string): string {\n const date = new Date(iso);\n if (Number.isNaN(date.getTime())) return iso;\n const pad = (n: number) => String(n).padStart(2, \"0\");\n return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;\n}\n\n/** The process has exited: by its status, or because an exit time was recorded. */\nexport function isProcessExited(row: ProcessNodeRow): boolean {\n return row.status === \"exited\" || Boolean(row.exitedAt);\n}\n\n/** The forest depth-first, parents before children. */\nexport function flattenForest(roots: ProcessTreeNode[]): ProcessTreeNode[] {\n const flat: ProcessTreeNode[] = [];\n const visit = (node: ProcessTreeNode) => {\n flat.push(node);\n node.children.forEach(visit);\n };\n roots.forEach(visit);\n return flat;\n}\n\n/** A CPU % for display, \"—\" while it is still unknown. */\nexport function formatCpuPercent(value: number | null | undefined): string {\n return value == null ? \"—\" : `${value.toFixed(1)}%`;\n}\n\nfunction knownCpu(samples: ProcessSampleRow[]): number[] {\n return samples.flatMap((sample) => (sample.cpuPercent == null ? [] : [sample.cpuPercent]));\n}\n\n/** Each process's known CPU % over its samples, in tick order. */\nexport function cpuSeriesByKey(samples: ProcessSampleRow[]): Map<string, number[]> {\n const byKey = new Map<string, ProcessSampleRow[]>();\n for (const sample of samples) byKey.set(sample.key, [...(byKey.get(sample.key) ?? []), sample]);\n return new Map([...byKey].map(([key, list]) => [key, knownCpu(list.sort((a, b) => a.tick - b.tick))]));\n}\n\n/** One process's known CPU % and RSS bytes over its samples, in tick order. */\nexport function processSeries(samples: ProcessSampleRow[], key: string): { cpu: number[]; rss: number[] } {\n const own = samples.filter((sample) => sample.key === key).sort((a, b) => a.tick - b.tick);\n return { cpu: knownCpu(own), rss: own.map((sample) => sample.rssBytes) };\n}\n\n/**\n * The combined CPU % and RSS bytes of a process and all its descendants at\n * each sampling tick (one tick is one sampling round across every process), in\n * tick order, so the peak of a series is the most the subtree used at once. A\n * tick's CPU sums the known readings and is left out when none is known.\n * The latest tick retains its CPU and RSS totals even when CPU is unknown.\n */\nexport function subtreeSeries(rows: ProcessNodeRow[], samples: ProcessSampleRow[], key: string): {\n cpu: number[];\n rss: number[];\n latest: { cpu: number | null; rss: number } | undefined;\n} {\n const keys = new Set([key]);\n for (let grew = true; grew; ) {\n grew = false;\n for (const row of rows) {\n if (row.parentKey && keys.has(row.parentKey) && !keys.has(row.key)) {\n keys.add(row.key);\n grew = true;\n }\n }\n }\n const ticks = new Map<number, { cpu: number | null; rss: number }>();\n for (const sample of samples) {\n if (!keys.has(sample.key)) continue;\n const total = ticks.get(sample.tick) ?? { cpu: null, rss: 0 };\n total.rss += sample.rssBytes;\n if (sample.cpuPercent != null) total.cpu = (total.cpu ?? 0) + sample.cpuPercent;\n ticks.set(sample.tick, total);\n }\n const ordered = [...ticks].sort(([a], [b]) => a - b).map(([, total]) => total);\n return {\n cpu: ordered.flatMap((total) => (total.cpu === null ? [] : [total.cpu])),\n rss: ordered.map((total) => total.rss),\n latest: ordered.at(-1),\n };\n}\n\n/** SVG polyline points for `values` in a `width` x `height` box, zero at the bottom and the maximum at the top. */\nexport function sparklinePoints(values: number[], width: number, height: number): string | undefined {\n if (values.length < 2) return undefined;\n const max = Math.max(...values);\n return values\n .map((value, index) => {\n const x = (index / (values.length - 1)) * width;\n const y = max === 0 ? height : height - (value / max) * height;\n return `${x.toFixed(1)},${y.toFixed(1)}`;\n })\n .join(\" \");\n}\n"],"mappings":";AASA,IAAM,WAAW,GAAoB,MACnC,KAAK,MAAM,EAAE,IAAI,SAAS,IAAI,KAAK,MAAM,EAAE,IAAI,SAAS,KAAK,EAAE,IAAI,MAAM,EAAE,IAAI;;;;;;;AAQjF,SAAgB,mBAAmB,MAA2C;CAC5E,MAAM,wBAAQ,IAAI,IAA6B;CAC/C,KAAK,MAAM,OAAO,MAAM;EACtB,IAAI,MAAM,IAAI,IAAI,GAAG,GAAG,MAAM,IAAI,MAAM,qBAAqB,IAAI,IAAI,gBAAgB;EACrF,MAAM,IAAI,IAAI,KAAK;G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,IAAI,GAAG,MAAM;CAC9B,OAAO,OACJ,KAAK,OAAO,UAAU;EACrB,MAAM,IAAK,SAAS,OAAO,SAAS,KAAM;EAC1C,MAAM,IAAI,QAAQ,IAAI,SAAS,SAAU,QAAQ,MAAO;EACxD,OAAO,GAAG,EAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC;CACvC,CAAC,CAAC,CACD,KAAK,GAAG;AACb"}
@@ -14,9 +14,9 @@ function detectMode() {
14
14
  /** Resolve build + runtime version metadata. */
15
15
  function getVersionInfo() {
16
16
  return {
17
- commit: read(() => "78e346a1b", ""),
18
- tag: read(() => "page-runtime-build@0.1.2", ""),
19
- date: read(() => "2026-12-02T04:34:47.563Z", ""),
17
+ commit: read(() => "e5b4fae76", ""),
18
+ tag: read(() => "page-runtime-build@0.1.4", ""),
19
+ date: read(() => "2026-12-03T10:47:59.891Z", ""),
20
20
  dirty: read(() => true, false),
21
21
  mode: detectMode()
22
22
  };
@@ -14,9 +14,9 @@ function detectMode() {
14
14
  /** Resolve build + runtime version metadata. */
15
15
  function getVersionInfo() {
16
16
  return {
17
- commit: read(() => "78e346a1b", ""),
18
- tag: read(() => "page-runtime-build@0.1.2", ""),
19
- date: read(() => "2026-12-02T04:34:14.657Z", ""),
17
+ commit: read(() => "e5b4fae76", ""),
18
+ tag: read(() => "page-runtime-build@0.1.4", ""),
19
+ date: read(() => "2026-12-03T10:47:25.757Z", ""),
20
20
  dirty: read(() => true, false),
21
21
  mode: detectMode()
22
22
  };
@@ -1 +1 @@
1
- {"version":3,"file":"attributes.cjs","names":["pathFlavour"],"sources":["../../../src/expressions/lang/attributes.ts"],"sourcesContent":["import type { CelSpec, GoTemplateSpec, GomplateSpec } from \"./types\";\nimport { pathFlavour } from \"./environment\";\n\n/**\n * The Monarch word lists a tokenizer rule refers to as `@name`.\n *\n * The tokenizers themselves are fixed: their rules match any dotted call and\n * then dispatch on these lists (`$1@namespaces`, `$1@globalFunctions`, …). So a\n * host's own `catalog.query` needs no new grammar — only `catalog` in\n * `namespaces` and `query` in `globalFunctions`.\n *\n * This mirrors the derivation in `genmonarch/lang_cel.go` and\n * `lang_gotemplate.go`. `attributes.test.ts` recomputes the generated bundle\n * from the generated spec and asserts the two agree, so the mirror cannot drift\n * silently.\n */\nexport type Attributes = Record<string, string[]>;\n\n/** CEL's word lists, minus `operators`, which comes from the grammar. */\nexport function celAttributes(spec: CelSpec): Attributes {\n const global: string[] = [];\n const member: string[] = [];\n for (const fn of spec.functions) {\n if (fn.memberOnly) member.push(fn.name);\n else global.push(leafOf(fn.name));\n }\n\n return {\n // `true`/`false`/`null` are constants, and colouring them as keywords too\n // would let whichever rule ran first decide.\n keywords: spec.keywords.filter((word) => !CONSTANTS.includes(word)),\n constants: [...CONSTANTS],\n typeKeywords: spec.types,\n macros: spec.macros.map((macro) => macro.name),\n namespaces: spec.namespaces,\n globalFunctions: global,\n memberFunctions: member,\n };\n}\n\n/** The go-template word lists, shared by the bare and embedded languages. */\nexport function goTemplateAttributes(spec: GoTemplateSpec): Attributes {\n return {\n keywords: spec.keywords,\n builtins: spec.builtins,\n namespaces: spec.namespaces,\n functions: spec.functions.filter((fn) => !fn.namespace).map((fn) => fn.name),\n };\n}\n\n/** The word lists for one language id, or null where a spec does not drive it. */\nexport function attributesFor(languageId: string, spec: GomplateSpec): Attributes | null {\n switch (pathFlavour(languageId)) {\n case \"cel\":\n return normalize(celAttributes(spec.cel));\n case \"gotemplate\":\n return normalize(goTemplateAttributes(spec.gotemplate));\n default:\n // JSONPath's vocabulary is the grammar's own, with nothing to extend.\n return null;\n }\n}\n\nconst CONSTANTS = [\"true\", \"false\", \"null\"];\n\n/**\n * Sorted and deduplicated, matching `Language.MarshalJSON` on the Go side, so a\n * recomputed list compares equal to a generated one.\n */\nfunction normalize(attributes: Attributes): Attributes {\n const out: Attributes = {};\n for (const [name, words] of Object.entries(attributes)) {\n out[name] = [...new Set(words)].sort();\n }\n return out;\n}\n\nfunction leafOf(name: string) {\n const dot =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AM,IAAI,OAAO,KAAK,MAAM,MAAM,CAAC;AAC5C"}
1
+ {"version":3,"file":"attributes.cjs","names":["pathFlavour"],"sources":["../../../src/expressions/lang/attributes.ts"],"sourcesContent":["import type { CelSpec, GoTemplateSpec, GomplateSpec } from \"./types.js\";\nimport { pathFlavour } from \"./environment.js\";\n\n/**\n * The Monarch word lists a tokenizer rule refers to as `@name`.\n *\n * The tokenizers themselves are fixed: their rules match any dotted call and\n * then dispatch on these lists (`$1@namespaces`, `$1@globalFunctions`, …). So a\n * host's own `catalog.query` needs no new grammar — only `catalog` in\n * `namespaces` and `query` in `globalFunctions`.\n *\n * This mirrors the derivation in `genmonarch/lang_cel.go` and\n * `lang_gotemplate.go`. `attributes.test.ts` recomputes the generated bundle\n * from the generated spec and asserts the two agree, so the mirror cannot drift\n * silently.\n */\nexport type Attributes = Record<string, string[]>;\n\n/** CEL's word lists, minus `operators`, which comes from the grammar. */\nexport function celAttributes(spec: CelSpec): Attributes {\n const global: string[] = [];\n const member: string[] = [];\n for (const fn of spec.functions) {\n if (fn.memberOnly) member.push(fn.name);\n else global.push(leafOf(fn.name));\n }\n\n return {\n // `true`/`false`/`null` are constants, and colouring them as keywords too\n // would let whichever rule ran first decide.\n keywords: spec.keywords.filter((word) => !CONSTANTS.includes(word)),\n constants: [...CONSTANTS],\n typeKeywords: spec.types,\n macros: spec.macros.map((macro) => macro.name),\n namespaces: spec.namespaces,\n globalFunctions: global,\n memberFunctions: member,\n };\n}\n\n/** The go-template word lists, shared by the bare and embedded languages. */\nexport function goTemplateAttributes(spec: GoTemplateSpec): Attributes {\n return {\n keywords: spec.keywords,\n builtins: spec.builtins,\n namespaces: spec.namespaces,\n functions: spec.functions.filter((fn) => !fn.namespace).map((fn) => fn.name),\n };\n}\n\n/** The word lists for one language id, or null where a spec does not drive it. */\nexport function attributesFor(languageId: string, spec: GomplateSpec): Attributes | null {\n switch (pathFlavour(languageId)) {\n case \"cel\":\n return normalize(celAttributes(spec.cel));\n case \"gotemplate\":\n return normalize(goTemplateAttributes(spec.gotemplate));\n default:\n // JSONPath's vocabulary is the grammar's own, with nothing to extend.\n return null;\n }\n}\n\nconst CONSTANTS = [\"true\", \"false\", \"null\"];\n\n/**\n * Sorted and deduplicated, matching `Language.MarshalJSON` on the Go side, so a\n * recomputed list compares equal to a generated one.\n */\nfunction normalize(attributes: Attributes): Attributes {\n const out: Attributes = {};\n for (const [name, words] of Object.entries(attributes)) {\n out[name] = [...new Set(words)].sort();\n }\n return out;\n}\n\nfunction leafOf(name: string) {\n const dot = name.lastIndexOf(\".\");\n return dot < 0 ? name : name.slice(dot + 1);\n}\n"],"mappings":";;;AAmBA,SAAgB,cAAc,MAA2B;CACvD,MAAM,SAAmB,CAAC;CAC1B,MAAM,SAAmB,CAAC;CAC1B,KAAK,MAAM,MAAM,KAAK,WACpB,IAAI,GAAG,YAAY,OAAO,KAAK,GAAG,IAAI;MACjC,OAAO,KAAK,OAAO,GAAG,IAAI,CAAC;CAGlC,OAAO;EAGL,UAAU,KAAK,SAAS,QAAQ,SAAS,CAAC,UAAU,SAAS,IAAI,CAAC;EAClE,WAAW,CAAC,GAAG,SAAS;EACxB,cAAc,KAAK;EACnB,QAAQ,KAAK,OAAO,KAAK,UAAU,MAAM,IAAI;EAC7C,YAAY,KAAK;EACjB,iBAAiB;EACjB,iBAAiB;CACnB;AACF;;AAGA,SAAgB,qBAAqB,MAAkC;CACrE,OAAO;EACL,UAAU,KAAK;EACf,UAAU,KAAK;EACf,YAAY,KAAK;EACjB,WAAW,KAAK,UAAU,QAAQ,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC,KAAK,OAAO,GAAG,IAAI;CAC7E;AACF;;AAGA,SAAgB,cAAc,YAAoB,MAAuC;CACvF,QAAQA,oBAAAA,YAAY,UAAU,GAA9B;EACE,KAAK,OACH,OAAO,UAAU,cAAc,KAAK,GAAG,CAAC;EAC1C,KAAK,cACH,OAAO,UAAU,qBAAqB,KAAK,UAAU,CAAC;EACxD,SAEE,OAAO;CACX;AACF;AAEA,IAAM,YAAY;CAAC;CAAQ;CAAS;AAAM;;;;;AAM1C,SAAS,UAAU,YAAoC;CACrD,MAAM,MAAkB,CAAC;CACzB,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,UAAU,GACnD,IAAI,QAAQ,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK;CAEvC,OAAO;AACT;AAEA,SAAS,OAAO,MAAc;CAC5B,MAAM,MAAM,KAAK,YAAY,GAAG;CAChC,OAAO,MAAM,IAAI,OAAO,KAAK,MAAM,MAAM,CAAC;AAC5C"}
@@ -1 +1 @@
1
- {"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../../src/expressions/lang/attributes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGrE;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;AAElD,yEAAyE;AACzE,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,UAAU,CAmBvD;AAED,6EAA6E;AAC7E,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,cAAc,GAAG,UAAU,CAOrE;AAED,kFAAkF;AAClF,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,UAAU,GAAG,IAAI,CAUvF"}
1
+ {"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../../src/expressions/lang/attributes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGxE;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;AAElD,yEAAyE;AACzE,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,UAAU,CAmBvD;AAED,6EAA6E;AAC7E,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,cAAc,GAAG,UAAU,CAOrE;AAED,kFAAkF;AAClF,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,UAAU,GAAG,IAAI,CAUvF"}
@@ -1 +1 @@
1
- {"version":3,"file":"attributes.js","names":[],"sources":["../../../src/expressions/lang/attributes.ts"],"sourcesContent":["import type { CelSpec, GoTemplateSpec, GomplateSpec } from \"./types\";\nimport { pathFlavour } from \"./environment\";\n\n/**\n * The Monarch word lists a tokenizer rule refers to as `@name`.\n *\n * The tokenizers themselves are fixed: their rules match any dotted call and\n * then dispatch on these lists (`$1@namespaces`, `$1@globalFunctions`, …). So a\n * host's own `catalog.query` needs no new grammar — only `catalog` in\n * `namespaces` and `query` in `globalFunctions`.\n *\n * This mirrors the derivation in `genmonarch/lang_cel.go` and\n * `lang_gotemplate.go`. `attributes.test.ts` recomputes the generated bundle\n * from the generated spec and asserts the two agree, so the mirror cannot drift\n * silently.\n */\nexport type Attributes = Record<string, string[]>;\n\n/** CEL's word lists, minus `operators`, which comes from the grammar. */\nexport function celAttributes(spec: CelSpec): Attributes {\n const global: string[] = [];\n const member: string[] = [];\n for (const fn of spec.functions) {\n if (fn.memberOnly) member.push(fn.name);\n else global.push(leafOf(fn.name));\n }\n\n return {\n // `true`/`false`/`null` are constants, and colouring them as keywords too\n // would let whichever rule ran first decide.\n keywords: spec.keywords.filter((word) => !CONSTANTS.includes(word)),\n constants: [...CONSTANTS],\n typeKeywords: spec.types,\n macros: spec.macros.map((macro) => macro.name),\n namespaces: spec.namespaces,\n globalFunctions: global,\n memberFunctions: member,\n };\n}\n\n/** The go-template word lists, shared by the bare and embedded languages. */\nexport function goTemplateAttributes(spec: GoTemplateSpec): Attributes {\n return {\n keywords: spec.keywords,\n builtins: spec.builtins,\n namespaces: spec.namespaces,\n functions: spec.functions.filter((fn) => !fn.namespace).map((fn) => fn.name),\n };\n}\n\n/** The word lists for one language id, or null where a spec does not drive it. */\nexport function attributesFor(languageId: string, spec: GomplateSpec): Attributes | null {\n switch (pathFlavour(languageId)) {\n case \"cel\":\n return normalize(celAttributes(spec.cel));\n case \"gotemplate\":\n return normalize(goTemplateAttributes(spec.gotemplate));\n default:\n // JSONPath's vocabulary is the grammar's own, with nothing to extend.\n return null;\n }\n}\n\nconst CONSTANTS = [\"true\", \"false\", \"null\"];\n\n/**\n * Sorted and deduplicated, matching `Language.MarshalJSON` on the Go side, so a\n * recomputed list compares equal to a generated one.\n */\nfunction normalize(attributes: Attributes): Attributes {\n const out: Attributes = {};\n for (const [name, words] of Object.entries(attributes)) {\n out[name] = [...new Set(words)].sort();\n }\n return out;\n}\n\nfunction leafOf(name: string) {\n const dot = name.lastIndexOf(\".\");\n return dot < 0 ? name : name.slice(dot + 1);\n}\n"],"mappings":";;;AAmBA,SAAgB,cAAc,MAA2B;CACvD,MAAM,SAAmB,CAAC;CAC1B,MAAM,SAAmB,CAAC;CAC1B,KAAK,MAAM,MAAM,KAAK,WACpB,IAAI,GAAG,YAAY,OAAO,KAAK,GAAG,IAAI;MACjC,OAAO,KAAK,OAAO,GAAG,IAAI,CAAC;CAGlC,OAAO;EAGL,UAAU,KAAK,SAAS,QAAQ,SAAS,CAAC,UAAU,SAAS,IAAI,CAAC;EAClE,WAAW,CAAC,GAAG,SAAS;EACxB,cAAc,KAAK;EACnB,QAAQ,KAAK,OAAO,KAAK,UAAU,MAAM,IAAI;EAC7C,YAAY,KAAK;EACjB,iBAAiB;EACjB,iBAAiB;CACnB;AACF;;AAGA,SAAgB,qBAAqB,MAAkC;CACrE,OAAO;EACL,UAAU,KAAK;EACf,UAAU,KAAK;EACf,YAAY,KAAK;EACjB,WAAW,KAAK,UAAU,QAAQ,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC,KAAK,OAAO,GAAG,IAAI;CAC7E;AACF;;AAGA,SAAgB,cAAc,YAAoB,MAAuC;CACvF,QAAQ,YAAY,UAAU,GAA9B;EACE,KAAK,OACH,OAAO,UAAU,cAAc,KAAK,GAAG,CAAC;EAC1C,KAAK,cACH,OAAO,UAAU,qBAAqB,KAAK,UAAU,CAAC;EACxD,SAEE,OAAO;CACX;AACF;AAEA,IAAM,YAAY;CAAC;CAAQ;CAAS;AAAM;;;;;AAM1C,SAAS,UAAU,YAAoC;CACrD,MAAM,MAAkB,CAAC;CACzB,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,UAAU,GACnD,IAAI,QAAQ,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK;CAEvC,OAAO;AACT;AAEA,SAAS,OAAO,MAAc;CAC5B,MAAM,MAAM,KAAK,YAAY,GAAG;CAChC,OAAO,MAAM,IAAI,OAAO,KAAK,MAAM,MAAM,CAAC;AAC5C"}
1
+ {"version":3,"file":"attributes.js","names":[],"sources":["../../../src/expressions/lang/attributes.ts"],"sourcesContent":["import type { CelSpec, GoTemplateSpec, GomplateSpec } from \"./types.js\";\nimport { pathFlavour } from \"./environment.js\";\n\n/**\n * The Monarch word lists a tokenizer rule refers to as `@name`.\n *\n * The tokenizers themselves are fixed: their rules match any dotted call and\n * then dispatch on these lists (`$1@namespaces`, `$1@globalFunctions`, …). So a\n * host's own `catalog.query` needs no new grammar — only `catalog` in\n * `namespaces` and `query` in `globalFunctions`.\n *\n * This mirrors the derivation in `genmonarch/lang_cel.go` and\n * `lang_gotemplate.go`. `attributes.test.ts` recomputes the generated bundle\n * from the generated spec and asserts the two agree, so the mirror cannot drift\n * silently.\n */\nexport type Attributes = Record<string, string[]>;\n\n/** CEL's word lists, minus `operators`, which comes from the grammar. */\nexport function celAttributes(spec: CelSpec): Attributes {\n const global: string[] = [];\n const member: string[] = [];\n for (const fn of spec.functions) {\n if (fn.memberOnly) member.push(fn.name);\n else global.push(leafOf(fn.name));\n }\n\n return {\n // `true`/`false`/`null` are constants, and colouring them as keywords too\n // would let whichever rule ran first decide.\n keywords: spec.keywords.filter((word) => !CONSTANTS.includes(word)),\n constants: [...CONSTANTS],\n typeKeywords: spec.types,\n macros: spec.macros.map((macro) => macro.name),\n namespaces: spec.namespaces,\n globalFunctions: global,\n memberFunctions: member,\n };\n}\n\n/** The go-template word lists, shared by the bare and embedded languages. */\nexport function goTemplateAttributes(spec: GoTemplateSpec): Attributes {\n return {\n keywords: spec.keywords,\n builtins: spec.builtins,\n namespaces: spec.namespaces,\n functions: spec.functions.filter((fn) => !fn.namespace).map((fn) => fn.name),\n };\n}\n\n/** The word lists for one language id, or null where a spec does not drive it. */\nexport function attributesFor(languageId: string, spec: GomplateSpec): Attributes | null {\n switch (pathFlavour(languageId)) {\n case \"cel\":\n return normalize(celAttributes(spec.cel));\n case \"gotemplate\":\n return normalize(goTemplateAttributes(spec.gotemplate));\n default:\n // JSONPath's vocabulary is the grammar's own, with nothing to extend.\n return null;\n }\n}\n\nconst CONSTANTS = [\"true\", \"false\", \"null\"];\n\n/**\n * Sorted and deduplicated, matching `Language.MarshalJSON` on the Go side, so a\n * recomputed list compares equal to a generated one.\n */\nfunction normalize(attributes: Attributes): Attributes {\n const out: Attributes = {};\n for (const [name, words] of Object.entries(attributes)) {\n out[name] = [...new Set(words)].sort();\n }\n return out;\n}\n\nfunction leafOf(name: string) {\n const dot = name.lastIndexOf(\".\");\n return dot < 0 ? name : name.slice(dot + 1);\n}\n"],"mappings":";;;AAmBA,SAAgB,cAAc,MAA2B;CACvD,MAAM,SAAmB,CAAC;CAC1B,MAAM,SAAmB,CAAC;CAC1B,KAAK,MAAM,MAAM,KAAK,WACpB,IAAI,GAAG,YAAY,OAAO,KAAK,GAAG,IAAI;MACjC,OAAO,KAAK,OAAO,GAAG,IAAI,CAAC;CAGlC,OAAO;EAGL,UAAU,KAAK,SAAS,QAAQ,SAAS,CAAC,UAAU,SAAS,IAAI,CAAC;EAClE,WAAW,CAAC,GAAG,SAAS;EACxB,cAAc,KAAK;EACnB,QAAQ,KAAK,OAAO,KAAK,UAAU,MAAM,IAAI;EAC7C,YAAY,KAAK;EACjB,iBAAiB;EACjB,iBAAiB;CACnB;AACF;;AAGA,SAAgB,qBAAqB,MAAkC;CACrE,OAAO;EACL,UAAU,KAAK;EACf,UAAU,KAAK;EACf,YAAY,KAAK;EACjB,WAAW,KAAK,UAAU,QAAQ,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC,KAAK,OAAO,GAAG,IAAI;CAC7E;AACF;;AAGA,SAAgB,cAAc,YAAoB,MAAuC;CACvF,QAAQ,YAAY,UAAU,GAA9B;EACE,KAAK,OACH,OAAO,UAAU,cAAc,KAAK,GAAG,CAAC;EAC1C,KAAK,cACH,OAAO,UAAU,qBAAqB,KAAK,UAAU,CAAC;EACxD,SAEE,OAAO;CACX;AACF;AAEA,IAAM,YAAY;CAAC;CAAQ;CAAS;AAAM;;;;;AAM1C,SAAS,UAAU,YAAoC;CACrD,MAAM,MAAkB,CAAC;CACzB,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,UAAU,GACnD,IAAI,QAAQ,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK;CAEvC,OAAO;AACT;AAEA,SAAS,OAAO,MAAc;CAC5B,MAAM,MAAM,KAAK,YAAY,GAAG;CAChC,OAAO,MAAM,IAAI,OAAO,KAAK,MAAM,MAAM,CAAC;AAC5C"}
@@ -1 +1 @@
1
- {"version":3,"file":"completion.cjs","names":["pathFlavour","environmentPrefixAt","resolvePath","childEntries","pathExpression","functionDocumentation","macroDocumentation"],"sources":["../../../src/expressions/lang/completion.ts"],"sourcesContent":["import type * as monaco from \"monaco-editor\";\nimport type { GomplateSpec, Monaco, SpecFunction, SpecMacro } from \"./types\";\nimport { functionDocumentation, macroDocumentation } from \"./hover\";\nimport { childEntries, pathExpression, pathFlavour, resolvePath } from \"./environment\";\nimport { environmentPrefixAt } from \"./prefix\";\n\n/** Supplies the document expressions are evaluated against, on every request. */\nexport type EnvironmentSource = () => unknown;\n\nexport interface CompletionOptions {\n /** The catalogue to complete from — gomplate's, or a host's merged over it. */\n spec: GomplateSpec;\n environment?: EnvironmentSource | undefined;\n}\n\n/**\n * Registers completion for one language.\n *\n * The catalogue half is built once per registration, so a host that supplies\n * its own spec re-registers rather than mutating in place. The document half is\n * rebuilt per request, because the document is being edited alongside the\n * expression.\n */\nexport function registerCompletion(\n monaco: Monaco,\n languageId: string,\n options: CompletionOptions,\n) {\n return monaco.languages.registerCompletionItemProvider(\n languageId,\n completionProvider(monaco, languageId, options),\n );\n}\n\n/**\n * The provider `registerCompletion` installs, exposed so it can be driven\n * directly by a test over a real model rather than through Monaco's registry.\n */\nexport function completionProvider(\n monaco: Monaco,\n languageId: string,\n { spec, environment }: CompletionOptions,\n) {\n const items = catalogueItems(monaco, languageId, spec);\n return {\n // A dot must retrigger, or `k8s.` offers nothing until another key is hit.\n triggerCharacters: [\".\"],\n provideCompletionItems(model: monaco.editor.ITextModel, position: monaco.Position) {\n const suggestions: monaco.languages.CompletionItem[] = environmentItems(\n monaco,\n model,\n position,\n languageId,\n environment,\n );\n const range = wordRange(model, position);\n for (const item of items) suggestions.push({ ...item, range });\n return { suggestions };\n },\n };\n}\n\n/**\n * A completion item without its range. The range depends on the cursor, so it\n * is attached per request while the rest of the item is built once.\n */\ntype Item = Omit<monaco.languages.CompletionItem, \"range\">;\n\nfunction catalogueItems(monaco: Monaco, languageId: string, spec: GomplateSpec): Item[] {\n switch (pathFlavour(languageId)) {\n case \"cel\":\n return celCompletionItems(monaco, spec);\n case \"gotemplate\":\n return goTemplateCompletionItems(monaco, spec);\n default:\n // JSONPath's dialect has no catalogue to generate from; its completions\n // come entirely from the document.\n return [];\n }\n}\n\n/**\n * The keys reachable from the cursor's position in the document.\n *\n * Each item replaces the whole path typed so far with a freshly rendered one,\n * rather than appending to it, so what lands in the editor is always valid in\n * that language — quoting an awkward key, or dropping the suggestion entirely\n * where the language cannot express the path.\n */\nfunction environmentItems(\n monaco: Monaco,\n model: monaco.editor.ITextModel,\n position: monaco.Position,\n languageId: string,\n environment: EnvironmentSource | undefined,\n): monaco.languages.CompletionItem[] {\n if (!environment) return [];\n const document = environment();\n if (document === undefined || document === null) return [];\n\n const prefix = environmentPrefixAt(model, position, languageId);\n if (!prefix) return [];\n\n const parent = resolvePath(document, prefix.segments);\n if (parent === undefined) return [];\n\n const kinds = monaco.languages.CompletionItemKind;\n const range = {\n startLineNumber: position.lineNumber,\n endLineNumber: position.lineNumber,\n startColumn: prefix.startColumn,\n endColumn: prefix.endColumn,\n };\n\n // Monaco filters a candidate against the model text from the range start to\n // the cursor, so `filterText` has to continue what was typed rather than\n // repeat the rendered path: `pod.items[0]` does not match `pod.items.`, and\n // the subscripted keys would be filtered straight back out.\n const typedHead = prefix.typed.slice(0, prefix.typed.length - prefix.leaf.length);\n\n const items: monaco.languages.CompletionItem[] = [];\n for (const entry of childEntries(parent)) {\n const insertText = pathExpression(languageId, [...prefix.segments, entry.segment]);\n if (insertText === null) continue;\n items.push({\n label: entry.key,\n kind: entry.container ? kinds.Folder : kinds.Field,\n insertText,\n filterText: `${typedHead}${entry.key}`,\n detail: `${entry.kind} · ${entry.summary}`,\n // A key of the document being evaluated beats any catalogue entry: it is\n // what the author came to the editor to write.\n sortText: `0${entry.key}`,\n range,\n });\n }\n return items;\n}\n\nfunction celCompletionItems(monaco: Monaco, spec: GomplateSpec) {\n const kinds = monaco.languages.CompletionItemKind;\n const items: Item[] = [];\n\n for (const fn of spec.cel.functions) {\n items.push(buildFunctionItem(monaco, fn, celInsertText(fn), kinds.Function));\n }\n for (const macro of spec.cel.macros) {\n items.push(buildMacroItem(monaco, macro));\n }\n for (const keyword of spec.cel.keywords) {\n items.push({\n label: keyword,\n kind: kinds.Keyword,\n insertText: keyword,\n detail: \"CEL keyword\",\n });\n }\n for (const type of spec.cel.types) {\n items.push({ label: type, kind: kinds.TypeParameter, insertText: type, detail: \"CEL type\" });\n }\n return items;\n}\n\nfunction goTemplateCompletionItems(monaco: Monaco, spec: GomplateSpec) {\n const kinds = monaco.languages.CompletionItemKind;\n const items: Item[] = [];\n\n for (const fn of spec.gotemplate.functions) {\n items.push(buildFunctionItem(monaco, fn, fn.name, kinds.Function));\n }\n for (const builtin of spec.gotemplate.builtins) {\n items.push({\n label: builtin,\n kind: kinds.Function,\n insertText: builtin,\n detail: \"text/template builtin\",\n });\n }\n for (const keyword of spec.gotemplate.keywords) {\n items.push({\n label: keyword,\n kind: kinds.Keyword,\n insertText: keyword,\n detail: \"template keyword\",\n });\n }\n return items;\n}\n\nfunction buildFunctionItem(\n monaco: Monaco,\n fn: SpecFunction,\n insertText: string,\n kind: monaco.languages.CompletionItemKind,\n): Item {\n // A function with neither a Go signature nor an overload has no detail to\n // show; the key has to be absent rather than explicitly undefined.\n const detail = fn.signature ?? fn.overloads?.[0]?.result;\n return {\n label: fn.name,\n kind: fn.memberOnly ? monaco.languages.CompletionItemKind.Method : kind,\n insertText,\n ...(detail === undefined ? {} : { detail }),\n documentation: { value: functionDocumentation(fn) },\n filterText: fn.name,\n // Un-namespaced names first: they are the short, common ones, and a\n // namespace is easy to reach by typing its prefix.\n sortText: fn.namespace ? `2${fn.name}` : `1${fn.name}`,\n };\n}\n\nfunction buildMacroItem(monaco: Monaco, macro: SpecMacro): Item {\n return {\n label: macro.name,\n kind: monaco.languages.CompletionItemKind.Keyword,\n insertText: macro.name,\n detail: `macro (${macro.argCount === 0 ? \"variadic\" : `${macro.argCount} args`})`,\n documentation: { value: macroDocumentation(macro) },\n filterText: macro.name,\n sortText: `1${macro.name}`,\n };\n}\n\n/**\n * CEL functions take parentheses; a member-only function is offered without a\n * leading dot because the dot is already typed when completion fires.\n */\nfunction celInsertText(fn: SpecFunction) {\n const arity = fn.overloads?.[0]?.args.length ?? 0;\n const receiver = fn.overloads?.[0]?.member ? 1 : 0;\n return arity - receiver === 0 ? `${fn.name}()` : `${fn.name}(`;\n}\n\nfunction wordRange(\n model: {\n getWordUntilPosition(p: { lineNumber: number; column: number }): {\n startColumn: number;\n endColumn: number;\n };\n },\n position: { lineNumber: number; column: number },\n) {\n const word = model.getWordUntilPosition(position);\n return {\n startLineNumber: position.lineNumber,\n endLineNumber: position.lineNumber,\n startColumn: word.startColumn,\n endColumn: word.endColumn,\n };\n}\n"],"mappings":";;;;;;;;;;;;AAuBA,SAAgB,mBACd,QACA,YACA,SACA;CACA,OAAO,OAAO,UAAU,+BACtB,YACA,mBAAmB,QAAQ,YAAY,OAAO,CAChD;AACF;;;;;AAMA,SAAgB,mBACd,QACA,YACA,EAAE,MAAM,eACR;CACA,MAAM,QAAQ,eAAe,QAAQ,YAAY,IAAI;CACrD,OAAO;EAEL,mBAAmB,CAAC,GAAG;EACvB,uBAAuB,OAAiC,UAA2B;GACjF,MAAM,cAAiD,iBACrD,QACA,OACA,UACA,YACA,WACF;GACA,MAAM,QAAQ,UAAU,OAAO,QAAQ;GACvC,KAAK,MAAM,QAAQ,OAAO,YAAY,KAAK;IAAE,GAAG;IAAM;GAAM,CAAC;GAC7D,OAAO,EAAE,YAAY;EACvB;CACF;AACF;AAQA,SAAS,eAAe,QAAgB,YAAoB,MAA4B;CACtF,QAAQA,oBAAAA,YAAY,UAAU,GAA9B;EACE,KAAK,OACH,OAAO,mBAAmB,QAAQ,IAAI;EACxC,KAAK,cACH,OAAO,0BAA0B,QAAQ,IAAI;EAC/C,SAGE,OAAO,CAAC;CACZ;AACF;;;;;;;;;AAUA,SAAS,iBACP,QACA,OACA,UACA,YACA,aACmC;CACnC,IAAI,CAAC,aAAa,OAAO,CAAC;CAC1B,MAAM,WAAW,YAAY;CAC7B,IAAI,aAAa,KAAA,KAAa,aAAa,MAAM,OAAO,CAAC;CAEzD,MAAM,SAASC,eAAAA,oBAAoB,OAAO,UAAU,UAAU;CAC9D,IAAI,CAAC,QAAQ,OAAO,CAAC;CAErB,MAAM,SAASC,oBAAAA,YAAY,UAAU,OAAO,QAAQ;CACpD,IAAI,WAAW,KAAA,GAA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AAC9D;AAEA,SAAS,UACP,OAMA,UACA;CACA,MAAM,OAAO,MAAM,qBAAqB,QAAQ;CAChD,OAAO;EACL,iBAAiB,SAAS;EAC1B,eAAe,SAAS;EACxB,aAAa,KAAK;EAClB,WAAW,KAAK;CAClB;AACF"}
1
+ {"version":3,"file":"completion.cjs","names":["pathFlavour","environmentPrefixAt","resolvePath","childEntries","pathExpression","functionDocumentation","macroDocumentation"],"sources":["../../../src/expressions/lang/completion.ts"],"sourcesContent":["import type * as monaco from \"monaco-editor\";\nimport type { GomplateSpec, Monaco, SpecFunction, SpecMacro } from \"./types.js\";\nimport { functionDocumentation, macroDocumentation } from \"./hover.js\";\nimport { childEntries, pathExpression, pathFlavour, resolvePath } from \"./environment.js\";\nimport { environmentPrefixAt } from \"./prefix.js\";\n\n/** Supplies the document expressions are evaluated against, on every request. */\nexport type EnvironmentSource = () => unknown;\n\nexport interface CompletionOptions {\n /** The catalogue to complete from — gomplate's, or a host's merged over it. */\n spec: GomplateSpec;\n environment?: EnvironmentSource | undefined;\n}\n\n/**\n * Registers completion for one language.\n *\n * The catalogue half is built once per registration, so a host that supplies\n * its own spec re-registers rather than mutating in place. The document half is\n * rebuilt per request, because the document is being edited alongside the\n * expression.\n */\nexport function registerCompletion(\n monaco: Monaco,\n languageId: string,\n options: CompletionOptions,\n) {\n return monaco.languages.registerCompletionItemProvider(\n languageId,\n completionProvider(monaco, languageId, options),\n );\n}\n\n/**\n * The provider `registerCompletion` installs, exposed so it can be driven\n * directly by a test over a real model rather than through Monaco's registry.\n */\nexport function completionProvider(\n monaco: Monaco,\n languageId: string,\n { spec, environment }: CompletionOptions,\n) {\n const items = catalogueItems(monaco, languageId, spec);\n return {\n // A dot must retrigger, or `k8s.` offers nothing until another key is hit.\n triggerCharacters: [\".\"],\n provideCompletionItems(model: monaco.editor.ITextModel, position: monaco.Position) {\n const suggestions: monaco.languages.CompletionItem[] = environmentItems(\n monaco,\n model,\n position,\n languageId,\n environment,\n );\n const range = wordRange(model, position);\n for (const item of items) suggestions.push({ ...item, range });\n return { suggestions };\n },\n };\n}\n\n/**\n * A completion item without its range. The range depends on the cursor, so it\n * is attached per request while the rest of the item is built once.\n */\ntype Item = Omit<monaco.languages.CompletionItem, \"range\">;\n\nfunction catalogueItems(monaco: Monaco, languageId: string, spec: GomplateSpec): Item[] {\n switch (pathFlavour(languageId)) {\n case \"cel\":\n return celCompletionItems(monaco, spec);\n case \"gotemplate\":\n return goTemplateCompletionItems(monaco, spec);\n default:\n // JSONPath's dialect has no catalogue to generate from; its completions\n // come entirely from the document.\n return [];\n }\n}\n\n/**\n * The keys reachable from the cursor's position in the document.\n *\n * Each item replaces the whole path typed so far with a freshly rendered one,\n * rather than appending to it, so what lands in the editor is always valid in\n * that language — quoting an awkward key, or dropping the suggestion entirely\n * where the language cannot express the path.\n */\nfunction environmentItems(\n monaco: Monaco,\n model: monaco.editor.ITextModel,\n position: monaco.Position,\n languageId: string,\n environment: EnvironmentSource | undefined,\n): monaco.languages.CompletionItem[] {\n if (!environment) return [];\n const document = environment();\n if (document === undefined || document === null) return [];\n\n const prefix = environmentPrefixAt(model, position, languageId);\n if (!prefix) return [];\n\n const parent = resolvePath(document, prefix.segments);\n if (parent === undefined) return [];\n\n const kinds = monaco.languages.CompletionItemKind;\n const range = {\n startLineNumber: position.lineNumber,\n endLineNumber: position.lineNumber,\n startColumn: prefix.startColumn,\n endColumn: prefix.endColumn,\n };\n\n // Monaco filters a candidate against the model text from the range start to\n // the cursor, so `filterText` has to continue what was typed rather than\n // repeat the rendered path: `pod.items[0]` does not match `pod.items.`, and\n // the subscripted keys would be filtered straight back out.\n const typedHead = prefix.typed.slice(0, prefix.typed.length - prefix.leaf.length);\n\n const items: monaco.languages.CompletionItem[] = [];\n for (const entry of childEntries(parent)) {\n const insertText = pathExpression(languageId, [...prefix.segments, entry.segment]);\n if (insertText === null) continue;\n items.push({\n label: entry.key,\n kind: entry.container ? kinds.Folder : kinds.Field,\n insertText,\n filterText: `${typedHead}${entry.key}`,\n detail: `${entry.kind} · ${entry.summary}`,\n // A key of the document being evaluated beats any catalogue entry: it is\n // what the author came to the editor to write.\n sortText: `0${entry.key}`,\n range,\n });\n }\n return items;\n}\n\nfunction celCompletionItems(monaco: Monaco, spec: GomplateSpec) {\n const kinds = monaco.languages.CompletionItemKind;\n const items: Item[] = [];\n\n for (const fn of spec.cel.functions) {\n items.push(buildFunctionItem(monaco, fn, celInsertText(fn), kinds.Function));\n }\n for (const macro of spec.cel.macros) {\n items.push(buildMacroItem(monaco, macro));\n }\n for (const keyword of spec.cel.keywords) {\n items.push({\n label: keyword,\n kind: kinds.Keyword,\n insertText: keyword,\n detail: \"CEL keyword\",\n });\n }\n for (const type of spec.cel.types) {\n items.push({ label: type, kind: kinds.TypeParameter, insertText: type, detail: \"CEL type\" });\n }\n return items;\n}\n\nfunction goTemplateCompletionItems(monaco: Monaco, spec: GomplateSpec) {\n const kinds = monaco.languages.CompletionItemKind;\n const items: Item[] = [];\n\n for (const fn of spec.gotemplate.functions) {\n items.push(buildFunctionItem(monaco, fn, fn.name, kinds.Function));\n }\n for (const builtin of spec.gotemplate.builtins) {\n items.push({\n label: builtin,\n kind: kinds.Function,\n insertText: builtin,\n detail: \"text/template builtin\",\n });\n }\n for (const keyword of spec.gotemplate.keywords) {\n items.push({\n label: keyword,\n kind: kinds.Keyword,\n insertText: keyword,\n detail: \"template keyword\",\n });\n }\n return items;\n}\n\nfunction buildFunctionItem(\n monaco: Monaco,\n fn: SpecFunction,\n insertText: string,\n kind: monaco.languages.CompletionItemKind,\n): Item {\n // A function with neither a Go signature nor an overload has no detail to\n // show; the key has to be absent rather than explicitly undefined.\n const detail = fn.signature ?? fn.overloads?.[0]?.result;\n return {\n label: fn.name,\n kind: fn.memberOnly ? monaco.languages.CompletionItemKind.Method : kind,\n insertText,\n ...(detail === undefined ? {} : { detail }),\n documentation: { value: functionDocumentation(fn) },\n filterText: fn.name,\n // Un-namespaced names first: they are the short, common ones, and a\n // namespace is easy to reach by typing its prefix.\n sortText: fn.namespace ? `2${fn.name}` : `1${fn.name}`,\n };\n}\n\nfunction buildMacroItem(monaco: Monaco, macro: SpecMacro): Item {\n return {\n label: macro.name,\n kind: monaco.languages.CompletionItemKind.Keyword,\n insertText: macro.name,\n detail: `macro (${macro.argCount === 0 ? \"variadic\" : `${macro.argCount} args`})`,\n documentation: { value: macroDocumentation(macro) },\n filterText: macro.name,\n sortText: `1${macro.name}`,\n };\n}\n\n/**\n * CEL functions take parentheses; a member-only function is offered without a\n * leading dot because the dot is already typed when completion fires.\n */\nfunction celInsertText(fn: SpecFunction) {\n const arity = fn.overloads?.[0]?.args.length ?? 0;\n const receiver = fn.overloads?.[0]?.member ? 1 : 0;\n return arity - receiver === 0 ? `${fn.name}()` : `${fn.name}(`;\n}\n\nfunction wordRange(\n model: {\n getWordUntilPosition(p: { lineNumber: number; column: number }): {\n startColumn: number;\n endColumn: number;\n };\n },\n position: { lineNumber: number; column: number },\n) {\n const word = model.getWordUntilPosition(position);\n return {\n startLineNumber: position.lineNumber,\n endLineNumber: position.lineNumber,\n startColumn: word.startColumn,\n endColumn: word.endColumn,\n };\n}\n"],"mappings":";;;;;;;;;;;;AAuBA,SAAgB,mBACd,QACA,YACA,SACA;CACA,OAAO,OAAO,UAAU,+BACtB,YACA,mBAAmB,QAAQ,YAAY,OAAO,CAChD;AACF;;;;;AAMA,SAAgB,mBACd,QACA,YACA,EAAE,MAAM,eACR;CACA,MAAM,QAAQ,eAAe,QAAQ,YAAY,IAAI;CACrD,OAAO;EAEL,mBAAmB,CAAC,GAAG;EACvB,uBAAuB,OAAiC,UAA2B;GACjF,MAAM,cAAiD,iBACrD,QACA,OACA,UACA,YACA,WACF;GACA,MAAM,QAAQ,UAAU,OAAO,QAAQ;GACvC,KAAK,MAAM,QAAQ,OAAO,YAAY,KAAK;IAAE,GAAG;IAAM;GAAM,CAAC;GAC7D,OAAO,EAAE,YAAY;EACvB;CACF;AACF;AAQA,SAAS,eAAe,QAAgB,YAAo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