@poe-platform/safe-bash 0.1.825 → 0.1.827

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 (155) hide show
  1. package/dist/image-ast/index.js +39 -18
  2. package/dist/pdf-ast/image.js +1 -1
  3. package/dist/pdf-ast/index.js +1 -1
  4. package/dist/pdf-ast/vendor/pdfjs-fonts.mjs +9 -3
  5. package/dist/safe-bash/chunks/{chunk-AGHV53VF.js → chunk-M6XFU6LQ.js} +3 -1
  6. package/dist/safe-bash/chunks/{chunk-363QOIDR.js → chunk-T6FHWSHM.js} +3 -1
  7. package/dist/safe-bash/command-chunks/{chunk-ZPBL7TYJ.js → chunk-2JRHCVMQ.js} +1 -1
  8. package/dist/safe-bash/command-chunks/{chunk-FMGNXOMV.js → chunk-2L3NMRLG.js} +7 -3
  9. package/dist/safe-bash/command-chunks/{chunk-DAQO64WC.js → chunk-2YKOJPIW.js} +1 -1
  10. package/dist/safe-bash/command-chunks/{chunk-EPYJSPOY.js → chunk-3QCW4VQF.js} +12 -8
  11. package/dist/safe-bash/command-chunks/{chunk-YRBFNT5B.js → chunk-3YL2TMLA.js} +10 -1
  12. package/dist/safe-bash/command-chunks/{chunk-5H7ZHP7F.js → chunk-43NDRBKY.js} +1 -1
  13. package/dist/safe-bash/command-chunks/{chunk-BBOYR6LV.js → chunk-46GA576V.js} +3 -3
  14. package/dist/safe-bash/command-chunks/{chunk-WPT2FCHH.js → chunk-4SLPM2WM.js} +1 -1
  15. package/dist/safe-bash/command-chunks/{chunk-7ZQVMPSB.js → chunk-5CAXR62E.js} +1 -1
  16. package/dist/safe-bash/command-chunks/{chunk-3DTHX5UU.js → chunk-66653AEZ.js} +40 -14
  17. package/dist/safe-bash/command-chunks/{chunk-ETFJ4L7F.js → chunk-6OLE6CLV.js} +1 -1
  18. package/dist/safe-bash/command-chunks/{chunk-ZIDESNHW.js → chunk-7M3M6FKC.js} +1 -1
  19. package/dist/safe-bash/command-chunks/{chunk-2KMNVJB7.js → chunk-A7PKUIJT.js} +1 -1
  20. package/dist/safe-bash/command-chunks/{chunk-AVSINNZ6.js → chunk-DEQ47SBQ.js} +5 -5
  21. package/dist/safe-bash/command-chunks/{chunk-EV7A5FNN.js → chunk-FFFRLPXU.js} +2 -2
  22. package/dist/safe-bash/command-chunks/{chunk-4MVQE6CT.js → chunk-FYTBEGSY.js} +1 -1
  23. package/dist/safe-bash/command-chunks/{chunk-LFTGMUAV.js → chunk-HQIZR6EU.js} +192 -489
  24. package/dist/safe-bash/command-chunks/chunk-HS2L7I4N.js +219 -0
  25. package/dist/safe-bash/command-chunks/{chunk-WKS2PAZL.js → chunk-HUGKO4ZE.js} +10 -1
  26. package/dist/safe-bash/command-chunks/chunk-IGXH5W5Z.js +111 -0
  27. package/dist/safe-bash/command-chunks/{chunk-CMJBRGU2.js → chunk-IHQZKUBS.js} +1 -1
  28. package/dist/safe-bash/command-chunks/chunk-JADJ4BMN.js +1519 -0
  29. package/dist/safe-bash/command-chunks/{chunk-5AQAWIYK.js → chunk-JEZC5V3B.js} +4 -0
  30. package/dist/safe-bash/command-chunks/{chunk-YB5TNDY6.js → chunk-K5VJ4NNL.js} +39 -5
  31. package/dist/safe-bash/command-chunks/{chunk-7RQGRFHJ.js → chunk-KHWDEAE4.js} +2 -2
  32. package/dist/safe-bash/command-chunks/chunk-L54KVUSY.js +604 -0
  33. package/dist/safe-bash/command-chunks/{chunk-3NJETNC2.js → chunk-MBXNG6C3.js} +2 -2
  34. package/dist/safe-bash/command-chunks/{chunk-HCPEYQKT.js → chunk-N4SH6QY5.js} +285 -302
  35. package/dist/safe-bash/command-chunks/{chunk-3DID6MQY.js → chunk-OWTQYLID.js} +2 -2
  36. package/dist/safe-bash/command-chunks/{chunk-4EA7WI3L.js → chunk-QOOQD6BD.js} +42 -33
  37. package/dist/safe-bash/command-chunks/{chunk-RQTFK7AV.js → chunk-QZYEI4N6.js} +1 -1
  38. package/dist/safe-bash/command-chunks/{chunk-R3SLT3ZX.js → chunk-R6GON4H3.js} +11 -1
  39. package/dist/safe-bash/command-chunks/{chunk-2GILUQJY.js → chunk-R7ZGDHME.js} +3 -3
  40. package/dist/safe-bash/command-chunks/{chunk-HNEWGADJ.js → chunk-RUXOFW5G.js} +7 -6
  41. package/dist/safe-bash/command-chunks/{chunk-LKAFLJ5L.js → chunk-RWQKX44L.js} +1 -1
  42. package/dist/safe-bash/command-chunks/{chunk-PKH57OIC.js → chunk-SG2KOOD4.js} +2 -2
  43. package/dist/safe-bash/command-chunks/chunk-T4TGJYFV.js +60 -0
  44. package/dist/safe-bash/command-chunks/chunk-TGSNVLFZ.js +105 -0
  45. package/dist/safe-bash/command-chunks/{chunk-NXCJNPL3.js → chunk-UCE77LYV.js} +2 -1
  46. package/dist/safe-bash/command-chunks/{chunk-EWECMOQ5.js → chunk-UIHPHIKI.js} +1 -1
  47. package/dist/safe-bash/command-chunks/{chunk-XSZNL3GV.js → chunk-UJPWPRVB.js} +191 -146
  48. package/dist/safe-bash/command-chunks/{chunk-E5CDHXFA.js → chunk-VOR6YDZC.js} +26 -1
  49. package/dist/safe-bash/command-chunks/chunk-VSNVYOK2.js +30 -0
  50. package/dist/safe-bash/command-chunks/{chunk-4XYGJB24.js → chunk-VTH4AORO.js} +3 -3
  51. package/dist/safe-bash/command-chunks/{chunk-W5LH7D23.js → chunk-WKKJJBJQ.js} +8 -8
  52. package/dist/safe-bash/command-chunks/{chunk-OLXMWQJ5.js → chunk-WRO3PB2M.js} +1 -1
  53. package/dist/safe-bash/command-chunks/{chunk-RUAGHZNF.js → chunk-X5ODTF3E.js} +7 -5
  54. package/dist/safe-bash/command-chunks/{chunk-LH4VBNF6.js → chunk-XGTSP2CP.js} +84 -16
  55. package/dist/safe-bash/command-chunks/{chunk-K576GZED.js → chunk-XTHKXCF2.js} +2 -2
  56. package/dist/safe-bash/command-chunks/{chunk-J3VS55K4.js → chunk-YHRESVJ7.js} +9 -3
  57. package/dist/safe-bash/command-chunks/{chunk-UWIDPTOB.js → chunk-YSCKOUQP.js} +1 -1
  58. package/dist/safe-bash/command-chunks/{chunk-UYNJF5QN.js → chunk-ZALAWNOE.js} +76 -122
  59. package/dist/safe-bash/command-chunks/{chunk-OT75C5YS.js → chunk-ZYXKW2K7.js} +1 -1
  60. package/dist/safe-bash/command-chunks/{pdf-renderer-346WYKSZ.js → pdf-renderer-5QWOVFA4.js} +1 -1
  61. package/dist/safe-bash/command-chunks/{prompt-tool-debug-3POFNRYP.js → prompt-tool-debug-G7ATE7D5.js} +6 -4
  62. package/dist/safe-bash/commands/llm/index.browser.js +5 -1
  63. package/dist/safe-bash/commands/llm/index.js +1 -1
  64. package/dist/safe-bash/commands/python/executor.browser.js +3 -1
  65. package/dist/safe-bash/commands/python/executor.js +1 -1
  66. package/dist/safe-bash/commands/python/index.browser.js +5 -1
  67. package/dist/safe-bash/commands/python/index.js +1 -1
  68. package/dist/safe-bash/core.browser.js +2 -2
  69. package/dist/safe-bash/full-core.browser.js +10 -2
  70. package/dist/safe-bash-command-awk/awk-runtime.js +2 -2
  71. package/dist/safe-bash-command-awk/awk-syntax.js +1 -1
  72. package/dist/safe-bash-command-awk/awk.js +3 -3
  73. package/dist/safe-bash-command-awk/index.js +3 -3
  74. package/dist/safe-bash-command-gpg/index.js +11 -3
  75. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  76. package/dist/safe-bash-command-llm/collections.js +6 -4
  77. package/dist/safe-bash-command-llm/command.js +4 -4
  78. package/dist/safe-bash-command-llm/import-json-document.d.ts +9 -2
  79. package/dist/safe-bash-command-llm/index.d.ts +2 -1
  80. package/dist/safe-bash-command-llm/index.js +10 -4
  81. package/dist/safe-bash-command-llm/loader-provider.d.ts +5 -0
  82. package/dist/safe-bash-command-mcp/index.js +10 -13
  83. package/dist/safe-bash-command-pdftoppm/index.js +2 -2
  84. package/dist/safe-bash-command-playwright-cli/index.js +2 -2
  85. package/dist/safe-bash-command-playwright-cli/playwright/ability-execution.d.ts +1 -0
  86. package/dist/safe-bash-command-playwright-cli/playwright/ability-execution.js +1 -1
  87. package/dist/safe-bash-command-playwright-cli/playwright/controller.d.ts +2 -0
  88. package/dist/safe-bash-command-playwright-cli/playwright/controller.js +2 -2
  89. package/dist/safe-bash-command-playwright-cli/playwright/index.js +2 -2
  90. package/dist/safe-bash-command-python/build-backend.d.ts +2 -0
  91. package/dist/safe-bash-command-python/cache.d.ts +1 -1
  92. package/dist/safe-bash-command-python/executor.d.ts +5 -2
  93. package/dist/safe-bash-command-python/executor.js +11 -6
  94. package/dist/safe-bash-command-python/host-capabilities.js +1 -1
  95. package/dist/safe-bash-command-python/index.js +11 -6
  96. package/dist/safe-bash-command-python/jspi.js +5 -3
  97. package/dist/safe-bash-command-python/manifest-file.d.ts +44 -0
  98. package/dist/safe-bash-command-python/manifest.d.ts +45 -0
  99. package/dist/safe-bash-command-python/provisioning.d.ts +20 -1
  100. package/dist/safe-bash-command-python/provisioning.js +3 -2
  101. package/dist/safe-bash-command-python/reply.js +7 -11
  102. package/dist/safe-bash-command-python/source-archive.js +2 -2
  103. package/dist/safe-bash-command-python/source-zip.js +2 -2
  104. package/dist/safe-bash-command-python/worker.js +34 -21
  105. package/dist/safe-bash-command-sqlite3/engine.d.ts +4 -0
  106. package/dist/safe-bash-command-sqlite3/index.js +174 -18
  107. package/dist/safe-bash-command-svgo/index.js +1 -1
  108. package/dist/safe-bash-command-tar/create.js +3 -3
  109. package/dist/safe-bash-command-tar/extract.js +3 -3
  110. package/dist/safe-bash-command-tar/index.js +5 -5
  111. package/dist/safe-bash-command-tar/modes.js +5 -5
  112. package/dist/safe-bash-command-tar/options.d.ts +1 -1
  113. package/dist/safe-bash-command-tar/options.js +1 -1
  114. package/dist/safe-bash-command-tar/stream.js +1 -1
  115. package/dist/safe-bash-command-wkhtmltopdf/index.js +1 -1
  116. package/dist/safe-bash-command-xan/argv.js +1 -1
  117. package/dist/safe-bash-command-xan/commands.js +3 -3
  118. package/dist/safe-bash-command-xan/index.js +3 -3
  119. package/dist/safe-bash-command-xan/io.js +2 -2
  120. package/dist/safe-bash-compression-engine/bounded-codec.js +3 -3
  121. package/dist/safe-bash-compression-engine/codec-loader.js +2 -2
  122. package/dist/safe-bash-compression-engine/files.js +6 -6
  123. package/dist/safe-bash-compression-engine/index.js +5 -5
  124. package/dist/safe-bash-compression-engine/operand.js +6 -6
  125. package/dist/safe-bash-compression-engine/options.js +1 -1
  126. package/dist/safe-bash-compression-engine/stream.js +5 -5
  127. package/dist/safe-bash-compression-engine/zstd-decode.js +4 -4
  128. package/dist/safe-bash-contracts/filesystem-descriptor.js +1 -1
  129. package/dist/safe-bash-contracts/filesystem-output.js +1 -1
  130. package/dist/safe-bash-csv-engine/index.js +6 -6
  131. package/dist/safe-bash-csv-engine/python-codec-aliases.js +1 -1
  132. package/dist/safe-bash-csv-engine/python-codepages.js +3 -3
  133. package/dist/safe-bash-csv-engine/python-file-codepages.js +2 -2
  134. package/dist/safe-bash-csv-engine/python-utf16.js +4 -4
  135. package/dist/safe-bash-csv-engine/text-decoder.js +6 -6
  136. package/dist/safe-bash-graphviz-engine/index.js +1 -1
  137. package/dist/safe-bash-pager-engine/index.js +2 -2
  138. package/dist/safe-bash-query-engine/capture.js +3 -3
  139. package/dist/safe-bash-query-engine/delpaths.js +3 -3
  140. package/dist/safe-bash-query-engine/formats.js +2 -2
  141. package/dist/safe-bash-query-engine/index.js +10 -10
  142. package/dist/safe-bash-query-engine/indices.js +3 -3
  143. package/dist/safe-bash-query-engine/input.d.ts +3 -3
  144. package/dist/safe-bash-query-engine/input.js +1 -1
  145. package/dist/safe-bash-query-engine/interpreter.js +9 -9
  146. package/dist/safe-bash-query-engine/query-core.js +10 -10
  147. package/dist/safe-bash-query-engine/regex.js +4 -4
  148. package/dist/safe-bash-query-engine/splits.js +5 -5
  149. package/dist/safe-bash-query-engine/values.js +2 -2
  150. package/package.json +2 -2
  151. package/dist/safe-bash/command-chunks/chunk-OOYVZAWL.js +0 -90
  152. package/dist/safe-bash/command-chunks/chunk-RZOHZGEZ.js +0 -772
  153. package/dist/safe-bash/command-chunks/chunk-WIUEM7HP.js +0 -58
  154. package/dist/safe-bash/command-chunks/chunk-WY6THI6J.js +0 -673
  155. package/dist/safe-bash/command-chunks/chunk-ZERCTWUI.js +0 -467
@@ -1,7 +1,16 @@
1
1
  // packages/safe-bash-command-wkhtmltopdf/src/pdf-renderer.ts
2
2
  import { Parser } from "parse5";
3
3
  import { drainCooperativeSteps } from "../../safe-bash-contracts/yield.js";
4
- import { PdfDocument, decodePng } from "../../pdf-ast/index.js";
4
+ import {
5
+ PdfDocument,
6
+ cosArray,
7
+ cosDict,
8
+ cosName,
9
+ cosNumber,
10
+ cosString,
11
+ decodePng,
12
+ dictSet
13
+ } from "../../pdf-ast/index.js";
5
14
 
6
15
  // packages/safe-bash-command-wkhtmltopdf/src/command.ts
7
16
  import { commandRuntimeIdentity, getCommandArguments } from "../../safe-bash-contracts/command.js";
@@ -1229,7 +1238,7 @@ async function runWkhtmltopdf(context, options = {}) {
1229
1238
  await writeBytes(stdout.output, encoder.encode(text), signal);
1230
1239
  result = { kind: "information", exitCode: 0 };
1231
1240
  } else {
1232
- const renderer = options.renderer ?? (await import("./pdf-renderer-346WYKSZ.js")).pdfAstRenderer;
1241
+ const renderer = options.renderer ?? (await import("./pdf-renderer-5QWOVFA4.js")).pdfAstRenderer;
1233
1242
  requireRendererFeatures(renderer.profile, []);
1234
1243
  let outputBytes = 0;
1235
1244
  let outputChunks = 0;
@@ -1741,6 +1750,7 @@ function* layoutObjectPagesSteps(blocks, box, settings, signal) {
1741
1750
  let cooperativeWork = 0;
1742
1751
  const pages = [];
1743
1752
  let currentActions = [];
1753
+ let currentHeadings = [];
1744
1754
  const headerReserve = settings.header.left || settings.header.center || settings.header.right ? 24 : 0;
1745
1755
  const footerReserve = settings.footer.left || settings.footer.center || settings.footer.right ? 24 : 0;
1746
1756
  const topY = box.height - box.marginTop - headerReserve;
@@ -1748,8 +1758,9 @@ function* layoutObjectPagesSteps(blocks, box, settings, signal) {
1748
1758
  const contentWidth = Math.max(72, box.width - box.marginLeft - box.marginRight);
1749
1759
  let cursorY = topY;
1750
1760
  const flushPage = () => {
1751
- pages.push({ actions: currentActions });
1761
+ pages.push({ actions: currentActions, headings: currentHeadings });
1752
1762
  currentActions = [];
1763
+ currentHeadings = [];
1753
1764
  cursorY = topY;
1754
1765
  };
1755
1766
  const ensureHeight = (needed) => {
@@ -1775,6 +1786,9 @@ function* layoutObjectPagesSteps(blocks, box, settings, signal) {
1775
1786
  const maxChars = Math.max(15, Math.floor(contentWidth / (fontSize * 0.55)));
1776
1787
  const lines = wrapTextLines(block.text ?? "", maxChars);
1777
1788
  ensureHeight(lines.length * lineHeight + 10);
1789
+ if (block.text) {
1790
+ currentHeadings.push({ title: block.text, level });
1791
+ }
1778
1792
  cursorY -= 4;
1779
1793
  const blockTopY = cursorY;
1780
1794
  for (const line of lines) {
@@ -2080,9 +2094,13 @@ function* layoutObjectPagesSteps(blocks, box, settings, signal) {
2080
2094
  }
2081
2095
  return pages;
2082
2096
  }
2083
- function substituteFurnitureTokens(template, tokens) {
2097
+ function substituteFurnitureTokens(template, tokens, replacements = []) {
2084
2098
  const isoDate = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
2085
- return template.replace(/\[page\]/g, String(tokens.page)).replace(/\[topage\]/g, String(tokens.topage)).replace(/\[webpage\]/g, tokens.webpage).replace(/\[title\]/g, tokens.title).replace(/\[section\]/g, tokens.section ?? tokens.title).replace(/\[subsection\]/g, tokens.subsection ?? "").replace(/\[isodate\]/g, isoDate).replace(/\[date\]/g, isoDate);
2099
+ let out = template.replace(/\[page\]/g, String(tokens.page)).replace(/\[topage\]/g, String(tokens.topage)).replace(/\[toPage\]/g, String(tokens.topage)).replace(/\[webpage\]/g, tokens.webpage).replace(/\[title\]/g, tokens.title).replace(/\[section\]/g, tokens.section ?? tokens.title).replace(/\[subsection\]/g, tokens.subsection ?? "").replace(/\[isodate\]/g, isoDate).replace(/\[date\]/g, isoDate);
2100
+ for (const [rk, rv] of replacements) {
2101
+ if (rk) out = out.split(`[${rk}]`).join(rv);
2102
+ }
2103
+ return out;
2086
2104
  }
2087
2105
  function* renderPdfAstSteps(request) {
2088
2106
  let cooperativeWork = 0;
@@ -2108,7 +2126,7 @@ function* renderPdfAstSteps(request) {
2108
2126
  const pages = yield* layoutObjectPagesSteps(parsed.blocks, box, obj.settings, signal);
2109
2127
  laidOutPerObject.push(pages);
2110
2128
  objectMeta.push({
2111
- title: parsed.title || inferredDocumentTitle || "Document",
2129
+ title: job.global.documentTitle || parsed.title || inferredDocumentTitle || "Document",
2112
2130
  webpage: obj.input ?? "-",
2113
2131
  settings: obj.settings
2114
2132
  });
@@ -2133,16 +2151,19 @@ function* renderPdfAstSteps(request) {
2133
2151
  creator: "wkhtmltopdf (pdf-ast-static)",
2134
2152
  producer: "@poe-code/pdf-ast"
2135
2153
  });
2154
+ const outlineEntries = [];
2136
2155
  for (const outPage of sequence.pages) {
2137
2156
  yield;
2138
2157
  signal.throwIfAborted();
2139
2158
  const spec = laidOutPerObject[outPage.objectIndex][outPage.pageIndex];
2140
2159
  const meta = objectMeta[outPage.objectIndex];
2141
2160
  const page = doc.addPage({ width: box.width, height: box.height });
2142
- for (const action of spec.actions) {
2143
- if (++cooperativeWork % 64 === 0)
2144
- yield;
2145
- action(page, doc, grayscale);
2161
+ if (job.global.outline && job.global.outlineDepth > 0 && outPage.copyIndex === 0 && meta.settings.includeInOutline) {
2162
+ for (const h of spec.headings ?? []) {
2163
+ if (h.level <= job.global.outlineDepth) {
2164
+ outlineEntries.push({ title: h.title, level: h.level, pageRef: page.ref });
2165
+ }
2166
+ }
2146
2167
  }
2147
2168
  const tokens = {
2148
2169
  page: outPage.logicalPage,
@@ -2150,11 +2171,12 @@ function* renderPdfAstSteps(request) {
2150
2171
  webpage: meta.webpage,
2151
2172
  title: meta.title
2152
2173
  };
2174
+ const repl = meta.settings.replacements;
2153
2175
  const header = meta.settings.header;
2154
2176
  const footer = meta.settings.footer;
2155
2177
  const headerY = box.height - Math.max(18, box.marginTop * 0.6);
2156
2178
  if (header.left) {
2157
- page.drawText(substituteFurnitureTokens(header.left, tokens), {
2179
+ page.drawText(substituteFurnitureTokens(header.left, tokens, repl), {
2158
2180
  x: box.marginLeft,
2159
2181
  y: headerY,
2160
2182
  size: Math.min(10, header.fontSize || 9),
@@ -2163,7 +2185,7 @@ function* renderPdfAstSteps(request) {
2163
2185
  });
2164
2186
  }
2165
2187
  if (header.center) {
2166
- const text = substituteFurnitureTokens(header.center, tokens);
2188
+ const text = substituteFurnitureTokens(header.center, tokens, repl);
2167
2189
  page.drawText(text, {
2168
2190
  x: Math.max(box.marginLeft, (box.width - text.length * 4.5) / 2),
2169
2191
  y: headerY,
@@ -2173,7 +2195,7 @@ function* renderPdfAstSteps(request) {
2173
2195
  });
2174
2196
  }
2175
2197
  if (header.right) {
2176
- const text = substituteFurnitureTokens(header.right, tokens);
2198
+ const text = substituteFurnitureTokens(header.right, tokens, repl);
2177
2199
  page.drawText(text, {
2178
2200
  x: Math.max(box.marginLeft, box.width - box.marginRight - text.length * 4.8),
2179
2201
  y: headerY,
@@ -2192,9 +2214,14 @@ function* renderPdfAstSteps(request) {
2192
2214
  strokeWidth: 0.5
2193
2215
  });
2194
2216
  }
2217
+ for (const action of spec.actions) {
2218
+ if (++cooperativeWork % 64 === 0)
2219
+ yield;
2220
+ action(page, doc, grayscale);
2221
+ }
2195
2222
  const footerY = Math.max(12, box.marginBottom * 0.5);
2196
2223
  if (footer.left) {
2197
- page.drawText(substituteFurnitureTokens(footer.left, tokens), {
2224
+ page.drawText(substituteFurnitureTokens(footer.left, tokens, repl), {
2198
2225
  x: box.marginLeft,
2199
2226
  y: footerY,
2200
2227
  size: Math.min(10, footer.fontSize || 9),
@@ -2203,7 +2230,7 @@ function* renderPdfAstSteps(request) {
2203
2230
  });
2204
2231
  }
2205
2232
  if (footer.center) {
2206
- const text = substituteFurnitureTokens(footer.center, tokens);
2233
+ const text = substituteFurnitureTokens(footer.center, tokens, repl);
2207
2234
  page.drawText(text, {
2208
2235
  x: Math.max(box.marginLeft, (box.width - text.length * 4.5) / 2),
2209
2236
  y: footerY,
@@ -2213,7 +2240,7 @@ function* renderPdfAstSteps(request) {
2213
2240
  });
2214
2241
  }
2215
2242
  if (footer.right) {
2216
- const text = substituteFurnitureTokens(footer.right, tokens);
2243
+ const text = substituteFurnitureTokens(footer.right, tokens, repl);
2217
2244
  page.drawText(text, {
2218
2245
  x: Math.max(box.marginLeft, box.width - box.marginRight - text.length * 4.8),
2219
2246
  y: footerY,
@@ -2233,6 +2260,47 @@ function* renderPdfAstSteps(request) {
2233
2260
  });
2234
2261
  }
2235
2262
  }
2263
+ if (outlineEntries.length > 0 && doc.cos.rootRef) {
2264
+ const catalog = doc.cos.resolveDict(doc.cos.rootRef);
2265
+ if (catalog) {
2266
+ const outlinesDict = cosDict({ Type: cosName("Outlines") });
2267
+ const outlinesRef = doc.cos.allocateObject(outlinesDict);
2268
+ dictSet(catalog, "Outlines", outlinesRef);
2269
+ const stack = [{ ref: outlinesRef, dict: outlinesDict, children: [] }];
2270
+ for (const bm of outlineEntries) {
2271
+ const targetLevel = Math.max(1, bm.level);
2272
+ while (stack.length > targetLevel) {
2273
+ stack.pop();
2274
+ }
2275
+ while (stack.length < targetLevel) {
2276
+ const top = stack[stack.length - 1];
2277
+ const lastChild = top.children[top.children.length - 1];
2278
+ if (lastChild) {
2279
+ stack.push({ ref: lastChild.ref, dict: lastChild.dict, children: [] });
2280
+ } else {
2281
+ break;
2282
+ }
2283
+ }
2284
+ const parentState = stack[stack.length - 1];
2285
+ const itemDict = cosDict({
2286
+ Title: cosString(bm.title),
2287
+ Parent: parentState.ref,
2288
+ Dest: cosArray([bm.pageRef, cosName("XYZ"), { kind: "null" }, { kind: "null" }, { kind: "null" }])
2289
+ });
2290
+ const itemRef = doc.cos.allocateObject(itemDict);
2291
+ const prevSibling = parentState.children[parentState.children.length - 1];
2292
+ if (prevSibling) {
2293
+ dictSet(prevSibling.dict, "Next", itemRef);
2294
+ dictSet(itemDict, "Prev", prevSibling.ref);
2295
+ } else {
2296
+ dictSet(parentState.dict, "First", itemRef);
2297
+ }
2298
+ dictSet(parentState.dict, "Last", itemRef);
2299
+ parentState.children.push({ ref: itemRef, dict: itemDict });
2300
+ dictSet(parentState.dict, "Count", cosNumber(parentState.children.length));
2301
+ }
2302
+ }
2303
+ }
2236
2304
  return doc.save();
2237
2305
  }
2238
2306
  function createPdfAstRenderer() {
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  extendedPattern
3
- } from "./chunk-UWIDPTOB.js";
3
+ } from "./chunk-YSCKOUQP.js";
4
4
  import {
5
5
  describe
6
- } from "./chunk-ZIDESNHW.js";
6
+ } from "./chunk-7M3M6FKC.js";
7
7
  import {
8
8
  JqError,
9
9
  JqLimitError,
@@ -11183,11 +11183,13 @@ var Commands = class {
11183
11183
  this.onAllocation = onAllocation;
11184
11184
  }
11185
11185
  cmds = [];
11186
+ hasPoints = false;
11186
11187
  transformStack = [];
11187
11188
  currentTransform = [1, 0, 0, 1, 0, 0];
11188
11189
  add(cmd, args) {
11189
11190
  this.onAllocation?.(64 + (args?.length ?? 0) * 16);
11190
11191
  if (args) {
11192
+ this.hasPoints = true;
11191
11193
  const { currentTransform } = this;
11192
11194
  for (let i = 0, ii = args.length; i < ii; i += 2) {
11193
11195
  Util.applyTransform(args, currentTransform, i);
@@ -11272,7 +11274,9 @@ var CompiledFont = class _CompiledFont {
11272
11274
  const cmds = new Commands(onAllocation);
11273
11275
  cmds.transform(fontMatrix.slice());
11274
11276
  this.compileGlyphImpl(code, cmds, glyphId);
11275
- cmds.add(DrawOPS.closePath);
11277
+ if (cmds.hasPoints) {
11278
+ cmds.add(DrawOPS.closePath);
11279
+ }
11276
11280
  return cmds.getPath();
11277
11281
  }
11278
11282
  compileGlyphImpl() {
@@ -11312,8 +11316,10 @@ var Type2Compiled = class extends CompiledFont {
11312
11316
  cmds.onFrameAllocation = onAllocation;
11313
11317
  cmds.transform(matrix2.slice());
11314
11318
  yield* compileCharString(code, cmds, this, glyphId);
11315
- cmds.add(DrawOPS.closePath);
11316
- yield cmds.getPath();
11319
+ if (cmds.hasPoints) {
11320
+ cmds.add(DrawOPS.closePath);
11321
+ yield cmds.getPath();
11322
+ }
11317
11323
  }
11318
11324
  compileGlyphImpl(code, cmds, glyphId) {
11319
11325
  for (const ignored of compileCharString(code, cmds, this, glyphId)) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  describe
3
- } from "./chunk-ZIDESNHW.js";
3
+ } from "./chunk-7M3M6FKC.js";
4
4
  import {
5
5
  JqError,
6
6
  JqLimitError,
@@ -1,7 +1,3 @@
1
- import {
2
- isPythonWhitespace
3
- } from "./chunk-E5CDHXFA.js";
4
-
5
1
  // packages/safe-bash-command-llm/src/import-json-document.ts
6
2
  import { jsonValues } from "../../safe-bash-query-engine/input.js";
7
3
  import { Budget, resolveJqLimits } from "../../safe-bash-query-engine/limits.js";
@@ -27,122 +23,122 @@ var JsonStorage = class extends PagedStorage {
27
23
  }
28
24
  };
29
25
  var JsonDocumentStore = class {
30
- storage;
31
- payload;
32
- keys;
33
- steps = 0;
26
+ #storage;
27
+ #payload;
28
+ #keys;
29
+ #steps = 0;
34
30
  constructor(options) {
35
31
  if (!Number.isSafeInteger(options.maxFileBytes) || options.maxFileBytes < 1 || !Number.isSafeInteger(options.maxOpenFiles) || options.maxOpenFiles < 1) throw new RangeError("Invalid JSON staging limits");
36
- this.signal = options.signal;
32
+ this.#signal = options.signal;
37
33
  const cache = new PagedStorageCache(4);
38
- this.storage = new JsonStorage(options.fs, options.directory, options.signal, options.maxFileBytes, cache);
39
- this.payload = new PagedStorage({ fs: options.fs, cwd: options.directory, env: {}, signal: options.signal }, 4, cache);
40
- this.keys = new IntegerTable(this.storage, 64);
34
+ this.#storage = new JsonStorage(options.fs, options.directory, options.signal, options.maxFileBytes, cache);
35
+ this.#payload = new PagedStorage({ fs: options.fs, cwd: options.directory, env: {}, signal: options.signal }, 4, cache);
36
+ this.#keys = new IntegerTable(this.#storage, 64);
41
37
  }
42
- signal;
43
- async step() {
44
- this.signal.throwIfAborted();
45
- if (++this.steps % 256 === 0) await yieldTurn(this.signal);
38
+ #signal;
39
+ async #step() {
40
+ this.#signal.throwIfAborted();
41
+ if (++this.#steps % 256 === 0) await yieldTurn(this.#signal);
46
42
  }
47
- async number(position) {
48
- const bytes = await this.storage.read(position, 8);
43
+ async #number(position) {
44
+ const bytes = await this.#storage.read(position, 8);
49
45
  return new DataView(bytes.buffer, bytes.byteOffset, 8).getFloat64(0, true);
50
46
  }
51
- async put(position, value) {
47
+ async #put(position, value) {
52
48
  const bytes = new Uint8Array(8);
53
49
  new DataView(bytes.buffer).setFloat64(0, value, true);
54
- await this.storage.write(position, bytes);
50
+ await this.#storage.write(position, bytes);
55
51
  }
56
- async record(values) {
52
+ async #record(values) {
57
53
  const bytes = new Uint8Array(recordBytes), view = new DataView(bytes.buffer);
58
54
  for (let index = 0; index < values.length; index++) view.setFloat64(index * 8, values[index], true);
59
- return this.storage.append(bytes);
55
+ return this.#storage.append(bytes);
60
56
  }
61
- async appendPoints(points, storage = this.payload) {
57
+ async appendPoints(points, storage = this.#payload) {
62
58
  for (let offset = 0; offset < points.length; offset += pageBytes / 4) {
63
- await this.step();
59
+ await this.#step();
64
60
  const count = Math.min(pageBytes / 4, points.length - offset);
65
61
  const bytes = new Uint8Array(count * 4), view = new DataView(bytes.buffer);
66
62
  for (let index = 0; index < count; index++) view.setUint32(index * 4, points[offset + index], true);
67
63
  await storage.append(bytes);
68
64
  }
69
65
  }
70
- async equalKey(entry, points) {
71
- const start = await this.number(entry + 16), end = await this.number(entry + 24);
66
+ async #equalKey(entry, points) {
67
+ const start = await this.#number(entry + 16), end = await this.#number(entry + 24);
72
68
  if (end - start !== points.length * 4) return false;
73
69
  for (let offset = 0; offset < points.length; offset += pageBytes / 4) {
74
- await this.step();
70
+ await this.#step();
75
71
  const count = Math.min(pageBytes / 4, points.length - offset);
76
- const bytes = await this.storage.read(start + offset * 4, count * 4);
72
+ const bytes = await this.#storage.read(start + offset * 4, count * 4);
77
73
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.length);
78
74
  for (let index = 0; index < count; index++) if (view.getUint32(index * 4, true) !== points[offset + index]) return false;
79
75
  }
80
76
  return true;
81
77
  }
82
78
  async insert(type, parent, key, keyPoints, token = "") {
83
- await this.step();
84
- const id = await this.record([nodeTypes.indexOf(type), parent, 0, 0, 0, 0, 0]);
79
+ await this.#step();
80
+ const id = await this.#record([nodeTypes.indexOf(type), parent, 0, 0, 0, 0, 0]);
85
81
  if (token) {
86
82
  const bytes = new TextEncoder().encode(token);
87
- const start = await this.storage.append(bytes);
88
- await this.put(id + 16, start);
89
- await this.put(id + 24, start + bytes.length);
83
+ const start = await this.#storage.append(bytes);
84
+ await this.#put(id + 16, start);
85
+ await this.#put(id + 24, start + bytes.length);
90
86
  }
91
87
  if (parent) {
92
88
  let hash = 0;
93
89
  if (keyPoints) for (const point of keyPoints) hash = Math.imul(hash ^ point, 16777619) >>> 0;
94
90
  hash = (hash ^ parent ^ Math.floor(parent / 4294967296)) >>> 0;
95
- const collision = keyPoints ? Number(await this.keys.get(BigInt(hash)) ?? 0n) : 0;
91
+ const collision = keyPoints ? Number(await this.#keys.get(BigInt(hash)) ?? 0n) : 0;
96
92
  let existing = 0;
97
- for (let entry = collision; entry; entry = await this.number(entry + 8)) {
98
- await this.step();
99
- if (await this.number(entry) === parent && await this.equalKey(entry, keyPoints)) {
93
+ for (let entry = collision; entry; entry = await this.#number(entry + 8)) {
94
+ await this.#step();
95
+ if (await this.#number(entry) === parent && await this.#equalKey(entry, keyPoints)) {
100
96
  existing = entry;
101
97
  break;
102
98
  }
103
99
  }
104
- if (existing) await this.put(existing + 32, id);
100
+ if (existing) await this.#put(existing + 32, id);
105
101
  else {
106
- const start = this.storage.allocate(0);
107
- if (keyPoints) await this.appendPoints(keyPoints, this.storage);
108
- const end = this.storage.allocate(0);
109
- const entry = await this.record([parent, collision, start, end, id, 0, keyPoints ? -1 : key]);
110
- const tail = await this.number(parent + 40);
111
- if (tail) await this.put(tail + 40, entry);
112
- else await this.put(parent + 32, entry);
113
- await this.put(parent + 40, entry);
114
- await this.put(parent + 48, await this.number(parent + 48) + 1);
115
- if (keyPoints) await this.keys.set(BigInt(hash), BigInt(entry));
102
+ const start = this.#storage.allocate(0);
103
+ if (keyPoints) await this.appendPoints(keyPoints, this.#storage);
104
+ const end = this.#storage.allocate(0);
105
+ const entry = await this.#record([parent, collision, start, end, id, 0, keyPoints ? -1 : key]);
106
+ const tail = await this.#number(parent + 40);
107
+ if (tail) await this.#put(tail + 40, entry);
108
+ else await this.#put(parent + 32, entry);
109
+ await this.#put(parent + 40, entry);
110
+ await this.#put(parent + 48, await this.#number(parent + 48) + 1);
111
+ if (keyPoints) await this.#keys.set(BigInt(hash), BigInt(entry));
116
112
  }
117
113
  }
118
- if (type === "string") await this.put(id + 16, this.payload.allocate(0));
114
+ if (type === "string") await this.#put(id + 16, this.#payload.allocate(0));
119
115
  return id;
120
116
  }
121
117
  async endString(id) {
122
- await this.put(id + 24, this.payload.allocate(0));
118
+ await this.#put(id + 24, this.#payload.allocate(0));
123
119
  }
124
120
  async parent(id) {
125
- return this.number(id + 8);
121
+ return this.#number(id + 8);
126
122
  }
127
123
  async node(id) {
128
- await this.step();
129
- const type = nodeTypes[await this.number(id)];
130
- const start = await this.number(id + 16), end = await this.number(id + 24);
124
+ await this.#step();
125
+ const type = nodeTypes[await this.#number(id)];
126
+ const start = await this.#number(id + 16), end = await this.#number(id + 24);
131
127
  let token = "";
132
128
  if (type === "number" || type === "boolean") {
133
129
  const decoder = new TextDecoder();
134
130
  for (let offset = start; offset < end; offset += pageBytes) {
135
- await this.step();
136
- token += decoder.decode(await this.storage.read(offset, Math.min(pageBytes, end - offset)), { stream: true });
131
+ await this.#step();
132
+ token += decoder.decode(await this.#storage.read(offset, Math.min(pageBytes, end - offset)), { stream: true });
137
133
  }
138
134
  token += decoder.decode();
139
135
  }
140
136
  return { id, type, start, end, token };
141
137
  }
142
- async *points(node, storage = this.payload) {
138
+ async *points(node, storage = this.#payload) {
143
139
  if (node.type !== "string") throw new TypeError("JSON node is not a string");
144
140
  for (let offset = node.start; offset < node.end; offset += pageBytes) {
145
- await this.step();
141
+ await this.#step();
146
142
  const bytes = await storage.read(offset, Math.min(pageBytes, node.end - offset));
147
143
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.length), points = [];
148
144
  for (let index = 0; index < bytes.length; index += 4) points.push(view.getUint32(index, true));
@@ -150,21 +146,21 @@ var JsonDocumentStore = class {
150
146
  }
151
147
  }
152
148
  async child(parent, after = -1) {
153
- await this.step();
154
- const entry = after < 0 ? await this.number(parent + 32) : await this.number(after + 40);
149
+ await this.#step();
150
+ const entry = after < 0 ? await this.#number(parent + 32) : await this.#number(after + 40);
155
151
  if (!entry) return void 0;
156
- const node = await this.node(await this.number(entry + 32)), key = await this.number(entry + 48);
152
+ const node = await this.node(await this.#number(entry + 32)), key = await this.#number(entry + 48);
157
153
  if (key >= 0) return { node, position: entry, key };
158
154
  const keyPoints = [];
159
155
  let text = "";
160
- for await (const points of this.points({ id: entry, type: "string", start: await this.number(entry + 16), end: await this.number(entry + 24), token: "" }, this.storage)) {
156
+ for await (const points of this.points({ id: entry, type: "string", start: await this.#number(entry + 16), end: await this.#number(entry + 24), token: "" }, this.#storage)) {
161
157
  keyPoints.push(...points);
162
158
  text += String.fromCodePoint(...points);
163
159
  }
164
160
  return { node, position: entry, key: text, keyPoints };
165
161
  }
166
162
  async close() {
167
- const results = await Promise.allSettled([this.storage.close(), this.payload.close()]);
163
+ const results = await Promise.allSettled([this.#storage.close(), this.#payload.close()]);
168
164
  for (const result of results) if (result.status === "rejected") throw result.reason;
169
165
  }
170
166
  };
@@ -175,15 +171,17 @@ var EmptyJsonDocumentError = class extends Error {
175
171
  super("JSON document is empty");
176
172
  }
177
173
  };
178
- async function withEmbeddingJsonDocument(options, input, operation) {
179
- const { signal } = options, store = new JsonDocumentStore(options);
174
+ async function openJsonDocument(options, input) {
175
+ const { signal } = options, store = new JsonDocumentStore(options), profile = options.profile ?? "python39";
180
176
  try {
181
177
  let root = 0, parent = 0, stringNode = 0;
182
178
  const budget = new Budget(resolveJqLimits({ maxInputBytes: Infinity, maxValueBytes: Infinity, maxCollectionSize: Infinity, maxSteps: Infinity }), signal);
183
- for await (const event of jsonValues(input, budget, { stream: true, stringChunks: { maxControlBytes: 65536, containers: true, codePoints: true }, profile: "python39" })) {
179
+ for await (const event of jsonValues(input, budget, { stream: true, stringChunks: { maxControlBytes: options.maxControlBytes ?? 65536, containers: true, codePoints: profile === "python39" }, profile })) {
184
180
  signal.throwIfAborted();
185
181
  if (!Array.isArray(event) || !Array.isArray(event[0])) throw new Error("Invalid JSON parser event");
186
- const path = event[0], value = event[1], kind = event[2], metadata = event[3];
182
+ const path = event[0], value = event[1], kind = event[2];
183
+ const points = (text) => Array.from(text, (char) => char.codePointAt(0));
184
+ const metadata = profile === "python39" ? event[3] : { key: typeof path.at(-1) === "string" ? points(path.at(-1)) : null, points: typeof value === "string" ? points(value) : null };
187
185
  const insert = async (type, token = "") => {
188
186
  const node = await store.insert(type, parent, Number(path.at(-1)), metadata.key, token);
189
187
  if (!parent) root = node;
@@ -200,7 +198,7 @@ async function withEmbeddingJsonDocument(options, input, operation) {
200
198
  await store.endString(stringNode);
201
199
  stringNode = 0;
202
200
  }
203
- } else if (kind === null) {
201
+ } else if (kind === null || kind === void 0 && event.length > 1) {
204
202
  if (value instanceof Decimal) await insert("number", value.text);
205
203
  else if (typeof value === "number") await insert("number", String(value));
206
204
  else if (value === null) await insert("null");
@@ -208,69 +206,25 @@ async function withEmbeddingJsonDocument(options, input, operation) {
208
206
  }
209
207
  }
210
208
  if (!root) throw new EmptyJsonDocumentError();
211
- return await operation({ root: await store.node(root), child: store.child.bind(store), points: store.points.bind(store), async *text(node) {
209
+ return { close: store.close.bind(store), root: await store.node(root), child: store.child.bind(store), points: store.points.bind(store), async *text(node) {
212
210
  for await (const points of store.points(node)) yield String.fromCodePoint(...points);
213
- } });
214
- } finally {
211
+ } };
212
+ } catch (error) {
215
213
  await store.close();
214
+ throw error;
216
215
  }
217
216
  }
218
-
219
- // packages/safe-bash-command-llm/src/indent-text.ts
220
- import { yieldTurn as yieldTurn2 } from "../../safe-bash-contracts/yield.js";
221
- async function* decodeLlmText(source, signal) {
222
- const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
223
- let steps = 0;
224
- for await (const bytes of source) {
225
- if (++steps % 256 === 0) await yieldTurn2(signal);
226
- signal.throwIfAborted();
227
- for (let offset = 0; offset < bytes.length; offset += 2048) {
228
- if (++steps % 256 === 0) await yieldTurn2(signal);
229
- signal.throwIfAborted();
230
- yield decoder.decode(bytes.subarray(offset, offset + 2048), { stream: true });
231
- }
232
- }
233
- yield decoder.decode();
234
- }
235
- async function* indentLlmText(source, signal) {
236
- const replay = decodeLlmText(source, signal)[Symbol.asyncIterator]();
237
- let pending = "", offset = 0;
238
- async function* line(length2, nonblank2) {
239
- if (nonblank2) yield " ";
240
- while (length2) {
241
- if (offset === pending.length) {
242
- const next = await replay.next();
243
- if (next.done) throw new Error("Stored content changed");
244
- pending = next.value;
245
- offset = 0;
246
- if (!pending.length) continue;
247
- }
248
- const count = Math.min(length2, pending.length - offset);
249
- yield pending.slice(offset, offset + count);
250
- offset += count;
251
- length2 -= count;
252
- }
253
- }
254
- let length = 0, nonblank = false;
217
+ async function withEmbeddingJsonDocument(options, input, operation) {
218
+ const document = await openJsonDocument(options, input);
255
219
  try {
256
- for await (const chunk of decodeLlmText(source, signal)) for (const char of chunk) {
257
- length += char.length;
258
- if (!isPythonWhitespace(char)) nonblank = true;
259
- if (["\n", "\r", "\v", "\f", "", "", "", "\x85", "\u2028", "\u2029"].includes(char)) {
260
- yield* line(length, nonblank);
261
- length = 0;
262
- nonblank = false;
263
- }
264
- }
265
- if (length) yield* line(length, nonblank);
220
+ return await operation(document);
266
221
  } finally {
267
- await replay.return?.();
222
+ await document.close();
268
223
  }
269
224
  }
270
225
 
271
226
  export {
272
227
  EmptyJsonDocumentError,
273
- withEmbeddingJsonDocument,
274
- decodeLlmText,
275
- indentLlmText
228
+ openJsonDocument,
229
+ withEmbeddingJsonDocument
276
230
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  indexValue,
3
3
  type
4
- } from "./chunk-ZIDESNHW.js";
4
+ } from "./chunk-7M3M6FKC.js";
5
5
  import {
6
6
  JqError,
7
7
  JqLimitError,
@@ -6,7 +6,7 @@ import {
6
6
  pdfAstWkhtmltopdfCommand,
7
7
  pdfAstWkhtmltopdfCommands,
8
8
  renderPdfAstSync
9
- } from "./chunk-LH4VBNF6.js";
9
+ } from "./chunk-XGTSP2CP.js";
10
10
  import "./chunk-65DS4IOB.js";
11
11
  export {
12
12
  createPdfAstRenderer,
@@ -1,15 +1,17 @@
1
+ import {
2
+ indentLlmText
3
+ } from "./chunk-T4TGJYFV.js";
1
4
  import {
2
5
  EmptyJsonDocumentError,
3
- indentLlmText,
4
6
  withEmbeddingJsonDocument
5
- } from "./chunk-UYNJF5QN.js";
7
+ } from "./chunk-ZALAWNOE.js";
6
8
  import {
7
9
  pythonRepr
8
- } from "./chunk-EWECMOQ5.js";
10
+ } from "./chunk-UIHPHIKI.js";
9
11
  import {
10
12
  createLlmSpool,
11
13
  floatText
12
- } from "./chunk-E5CDHXFA.js";
14
+ } from "./chunk-VOR6YDZC.js";
13
15
  import "./chunk-3PO534WJ.js";
14
16
  import {
15
17
  attachmentDigestHex,