@oh-my-pi/pi-utils 17.2.8 → 17.2.10

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 (89) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/types/acp/connection.d.ts +118 -0
  3. package/dist/types/acp/protocol.d.ts +526 -0
  4. package/dist/types/acp/schema.d.ts +41 -0
  5. package/dist/types/acp/stream.d.ts +8 -0
  6. package/dist/types/acp/transport.d.ts +81 -0
  7. package/dist/types/acp.d.ts +6 -0
  8. package/dist/types/browsers.d.ts +68 -0
  9. package/dist/types/chalk.d.ts +125 -0
  10. package/dist/types/dates.d.ts +7 -0
  11. package/dist/types/docx/converter.d.ts +46 -0
  12. package/dist/types/docx/xml.d.ts +26 -0
  13. package/dist/types/docx/zip.d.ts +6 -0
  14. package/dist/types/docx.d.ts +11 -0
  15. package/dist/types/dom/core.d.ts +431 -0
  16. package/dist/types/dom/parser.d.ts +7 -0
  17. package/dist/types/dom/selector.d.ts +5 -0
  18. package/dist/types/dom.d.ts +5 -0
  19. package/dist/types/headers.d.ts +34 -0
  20. package/dist/types/index.d.ts +1 -0
  21. package/dist/types/logger/rotating-file.d.ts +18 -0
  22. package/dist/types/lru.d.ts +46 -0
  23. package/dist/types/marked/core.d.ts +445 -0
  24. package/dist/types/marked.d.ts +2 -0
  25. package/dist/types/postmortem.d.ts +14 -0
  26. package/dist/types/procmgr.d.ts +16 -0
  27. package/dist/types/prompt.d.ts +2 -2
  28. package/dist/types/readability/readability.d.ts +9 -0
  29. package/dist/types/readability/readerable.d.ts +10 -0
  30. package/dist/types/readability/types.d.ts +70 -0
  31. package/dist/types/readability.d.ts +4 -0
  32. package/dist/types/template.d.ts +62 -0
  33. package/dist/types/turndown/gfm.d.ts +11 -0
  34. package/dist/types/turndown/html.d.ts +5 -0
  35. package/dist/types/turndown/service.d.ts +21 -0
  36. package/dist/types/turndown/types.d.ts +70 -0
  37. package/dist/types/turndown.d.ts +4 -0
  38. package/dist/types/version.d.ts +18 -0
  39. package/dist/types/vterm/buffer.d.ts +99 -0
  40. package/dist/types/vterm/terminal.d.ts +44 -0
  41. package/dist/types/vterm.d.ts +8 -0
  42. package/dist/types/xml.d.ts +31 -0
  43. package/package.json +2 -5
  44. package/src/acp/connection.ts +344 -0
  45. package/src/acp/protocol.ts +466 -0
  46. package/src/acp/schema.ts +160 -0
  47. package/src/acp/stream.ts +82 -0
  48. package/src/acp/transport.ts +213 -0
  49. package/src/acp.ts +6 -0
  50. package/src/browsers.ts +501 -0
  51. package/src/chalk.ts +312 -0
  52. package/src/dates.ts +194 -0
  53. package/src/docx/converter.ts +681 -0
  54. package/src/docx/xml.ts +166 -0
  55. package/src/docx/zip.ts +87 -0
  56. package/src/docx.ts +20 -0
  57. package/src/dom/core.ts +1254 -0
  58. package/src/dom/parser.ts +370 -0
  59. package/src/dom/selector.ts +290 -0
  60. package/src/dom.ts +33 -0
  61. package/src/fetch-retry.ts +7 -1
  62. package/src/frontmatter.ts +1 -1
  63. package/src/headers.ts +167 -0
  64. package/src/index.ts +1 -0
  65. package/src/logger/rotating-file.ts +149 -0
  66. package/src/logger.ts +12 -28
  67. package/src/lru.ts +185 -0
  68. package/src/marked/core.ts +1576 -0
  69. package/src/marked.ts +2 -0
  70. package/src/postmortem.ts +44 -1
  71. package/src/procmgr.ts +21 -4
  72. package/src/prompt.ts +5 -22
  73. package/src/readability/readability.ts +533 -0
  74. package/src/readability/readerable.ts +51 -0
  75. package/src/readability/types.ts +72 -0
  76. package/src/readability.ts +11 -0
  77. package/src/template.ts +586 -0
  78. package/src/turndown/gfm.ts +106 -0
  79. package/src/turndown/html.ts +257 -0
  80. package/src/turndown/service.ts +334 -0
  81. package/src/turndown/types.ts +81 -0
  82. package/src/turndown.ts +5 -0
  83. package/src/version.ts +99 -0
  84. package/src/vterm/buffer.ts +218 -0
  85. package/src/vterm/terminal.ts +773 -0
  86. package/src/vterm.ts +8 -0
  87. package/src/which.ts +6 -4
  88. package/src/xml.ts +313 -0
  89. package/src/winston-daily-rotate-file.d.ts +0 -6
@@ -0,0 +1,51 @@
1
+ /** Behavior-compatible reimplementation of @mozilla/readability's used surface. */
2
+
3
+ import type { ReadabilityDocument, ReadabilityElement, ReadabilityNode } from "./types";
4
+
5
+ const UNLIKELY =
6
+ /-ad-|ai2html|banner|breadcrumbs|combx|comment|community|cover-wrap|disqus|extra|footer|gdpr|header|legends|menu|related|remark|replies|rss|shoutbox|sidebar|skyscraper|social|sponsor|supplemental|ad-break|agegate|pagination|pager|popup|yom-remote/i;
7
+ const POSSIBLE = /and|article|body|column|content|main|shadow/i;
8
+
9
+ /** Options for the inexpensive readerability estimate. */
10
+ export interface ReaderableOptions {
11
+ minContentLength?: number;
12
+ minScore?: number;
13
+ visibilityChecker?: (node: ReadabilityNode) => boolean;
14
+ }
15
+
16
+ /** Estimates whether a document contains enough prose for article extraction. */
17
+ export function isProbablyReaderable(
18
+ document: ReadabilityDocument,
19
+ options: ReaderableOptions | ((node: ReadabilityNode) => boolean) = {},
20
+ ): boolean {
21
+ const resolved = typeof options === "function" ? { visibilityChecker: options } : options;
22
+ const minLength = resolved.minContentLength ?? 140;
23
+ const minScore = resolved.minScore ?? 20;
24
+ const visible =
25
+ resolved.visibilityChecker ??
26
+ ((node: ReadabilityNode) => {
27
+ const element = node as ReadabilityElement;
28
+ const style = element.getAttribute("style")?.toLowerCase() ?? "";
29
+ return (
30
+ !element.hasAttribute("hidden") &&
31
+ element.getAttribute("aria-hidden") !== "true" &&
32
+ !/display\s*:\s*none/.test(style)
33
+ );
34
+ });
35
+ const candidates = new Set<ReadabilityElement>(Array.from(document.querySelectorAll("p, pre, article")));
36
+ for (const br of Array.from(document.querySelectorAll("div > br"))) {
37
+ if (br.parentNode) candidates.add(br.parentNode as ReadabilityElement);
38
+ }
39
+ let score = 0;
40
+ for (const node of candidates) {
41
+ if (!visible(node)) continue;
42
+ const label = `${node.className} ${node.id}`;
43
+ if (UNLIKELY.test(label) && !POSSIBLE.test(label)) continue;
44
+ if ((node.parentNode as ReadabilityElement | null)?.tagName === "LI" && node.tagName === "P") continue;
45
+ const length = (node.textContent ?? "").trim().length;
46
+ if (length < minLength) continue;
47
+ score += Math.sqrt(length - minLength);
48
+ if (score > minScore) return true;
49
+ }
50
+ return false;
51
+ }
@@ -0,0 +1,72 @@
1
+ /** Behavior-compatible reimplementation of @mozilla/readability's used surface. */
2
+
3
+ /** Minimal standards-shaped DOM node accepted by the readability extractor. */
4
+ export interface ReadabilityNode {
5
+ readonly nodeType: number;
6
+ readonly nodeName: string;
7
+ readonly tagName?: string;
8
+ readonly ownerDocument?: ReadabilityDocument | null;
9
+ parentNode: ReadabilityNode | null;
10
+ readonly children?: ArrayLike<ReadabilityElement>;
11
+ readonly childNodes: ArrayLike<ReadabilityNode>;
12
+ readonly firstChild: ReadabilityNode | null;
13
+ readonly textContent: string | null;
14
+ appendChild(node: ReadabilityNode): ReadabilityNode;
15
+ cloneNode(deep?: boolean): ReadabilityNode;
16
+ remove(): void;
17
+ }
18
+
19
+ /** Minimal standards-shaped DOM element accepted by the readability extractor. */
20
+ export interface ReadabilityElement extends ReadabilityNode {
21
+ readonly children: ArrayLike<ReadabilityElement>;
22
+ readonly tagName: string;
23
+ id: string;
24
+ className: string;
25
+ innerHTML: string;
26
+ readonly attributes: ArrayLike<{ readonly name: string; readonly value: string }>;
27
+ getAttribute(name: string): string | null;
28
+ hasAttribute(name: string): boolean;
29
+ setAttribute(name: string, value: string): void;
30
+ removeAttribute(name: string): void;
31
+ getElementsByTagName(name: string): ArrayLike<ReadabilityElement>;
32
+ querySelector(selector: string): ReadabilityElement | null;
33
+ querySelectorAll(selector: string): ArrayLike<ReadabilityElement>;
34
+ }
35
+
36
+ /** Minimal standards-shaped document accepted by the readability extractor. */
37
+ export interface ReadabilityDocument extends ReadabilityNode {
38
+ title: string;
39
+ readonly body: ReadabilityElement | null;
40
+ readonly documentElement: ReadabilityElement | null;
41
+ createElement(name: string): ReadabilityElement;
42
+ getElementsByTagName(name: string): ArrayLike<ReadabilityElement>;
43
+ querySelector(selector: string): ReadabilityElement | null;
44
+ querySelectorAll(selector: string): ArrayLike<ReadabilityElement>;
45
+ }
46
+
47
+ /** Configuration for article extraction. */
48
+ export interface ReadabilityOptions<T = string> {
49
+ debug?: boolean;
50
+ maxElemsToParse?: number;
51
+ nbTopCandidates?: number;
52
+ charThreshold?: number;
53
+ classesToPreserve?: string[];
54
+ keepClasses?: boolean;
55
+ serializer?: (node: ReadabilityNode) => T;
56
+ disableJSONLD?: boolean;
57
+ allowedVideoRegex?: RegExp;
58
+ }
59
+
60
+ /** Extracted article and metadata. */
61
+ export interface ReadabilityArticle<T = string> {
62
+ title: string | null | undefined;
63
+ content: T | null | undefined;
64
+ textContent: string | null | undefined;
65
+ length: number | null | undefined;
66
+ excerpt: string | null | undefined;
67
+ byline: string | null | undefined;
68
+ dir: string | null | undefined;
69
+ siteName: string | null | undefined;
70
+ lang: string | null | undefined;
71
+ publishedTime: string | null | undefined;
72
+ }
@@ -0,0 +1,11 @@
1
+ /** Behavior-compatible reimplementation of @mozilla/readability's used surface. */
2
+
3
+ export { Readability } from "./readability/readability";
4
+ export { isProbablyReaderable, type ReaderableOptions } from "./readability/readerable";
5
+ export type {
6
+ ReadabilityArticle,
7
+ ReadabilityDocument,
8
+ ReadabilityElement,
9
+ ReadabilityNode,
10
+ ReadabilityOptions,
11
+ } from "./readability/types";