@mossbear/protocol 0.1.0-alpha.100

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 (143) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -0
  3. package/dist/agentGuidancePaths.d.ts +101 -0
  4. package/dist/agentGuidancePaths.d.ts.map +1 -0
  5. package/dist/agentGuidancePaths.js +185 -0
  6. package/dist/agentGuidancePaths.js.map +1 -0
  7. package/dist/agentGuidancePaths.test.d.ts +2 -0
  8. package/dist/agentGuidancePaths.test.d.ts.map +1 -0
  9. package/dist/agentGuidancePaths.test.js +91 -0
  10. package/dist/agentGuidancePaths.test.js.map +1 -0
  11. package/dist/aliasPaths.d.ts +100 -0
  12. package/dist/aliasPaths.d.ts.map +1 -0
  13. package/dist/aliasPaths.js +148 -0
  14. package/dist/aliasPaths.js.map +1 -0
  15. package/dist/aliasPaths.test.d.ts +2 -0
  16. package/dist/aliasPaths.test.d.ts.map +1 -0
  17. package/dist/aliasPaths.test.js +80 -0
  18. package/dist/aliasPaths.test.js.map +1 -0
  19. package/dist/artifact.test.d.ts +2 -0
  20. package/dist/artifact.test.d.ts.map +1 -0
  21. package/dist/artifact.test.js +374 -0
  22. package/dist/artifact.test.js.map +1 -0
  23. package/dist/bundleSlug.d.ts +177 -0
  24. package/dist/bundleSlug.d.ts.map +1 -0
  25. package/dist/bundleSlug.js +233 -0
  26. package/dist/bundleSlug.js.map +1 -0
  27. package/dist/bundleSlug.test.d.ts +2 -0
  28. package/dist/bundleSlug.test.d.ts.map +1 -0
  29. package/dist/bundleSlug.test.js +197 -0
  30. package/dist/bundleSlug.test.js.map +1 -0
  31. package/dist/commentAnchor.d.ts +34 -0
  32. package/dist/commentAnchor.d.ts.map +1 -0
  33. package/dist/commentAnchor.js +122 -0
  34. package/dist/commentAnchor.js.map +1 -0
  35. package/dist/commentAnchor.test.d.ts +2 -0
  36. package/dist/commentAnchor.test.d.ts.map +1 -0
  37. package/dist/commentAnchor.test.js +48 -0
  38. package/dist/commentAnchor.test.js.map +1 -0
  39. package/dist/contextKinds.d.ts +165 -0
  40. package/dist/contextKinds.d.ts.map +1 -0
  41. package/dist/contextKinds.js +148 -0
  42. package/dist/contextKinds.js.map +1 -0
  43. package/dist/contextKinds.test.d.ts +2 -0
  44. package/dist/contextKinds.test.d.ts.map +1 -0
  45. package/dist/contextKinds.test.js +137 -0
  46. package/dist/contextKinds.test.js.map +1 -0
  47. package/dist/frameDocument.d.ts +71 -0
  48. package/dist/frameDocument.d.ts.map +1 -0
  49. package/dist/frameDocument.js +140 -0
  50. package/dist/frameDocument.js.map +1 -0
  51. package/dist/frameDocument.test.d.ts +2 -0
  52. package/dist/frameDocument.test.d.ts.map +1 -0
  53. package/dist/frameDocument.test.js +84 -0
  54. package/dist/frameDocument.test.js.map +1 -0
  55. package/dist/frameProtocol.d.ts +11 -0
  56. package/dist/frameProtocol.d.ts.map +1 -0
  57. package/dist/frameProtocol.js +11 -0
  58. package/dist/frameProtocol.js.map +1 -0
  59. package/dist/index.d.ts +24 -0
  60. package/dist/index.d.ts.map +1 -0
  61. package/dist/index.js +24 -0
  62. package/dist/index.js.map +1 -0
  63. package/dist/limits.d.ts +19 -0
  64. package/dist/limits.d.ts.map +1 -0
  65. package/dist/limits.js +19 -0
  66. package/dist/limits.js.map +1 -0
  67. package/dist/markdownSections.d.ts +58 -0
  68. package/dist/markdownSections.d.ts.map +1 -0
  69. package/dist/markdownSections.js +102 -0
  70. package/dist/markdownSections.js.map +1 -0
  71. package/dist/markdownSections.test.d.ts +2 -0
  72. package/dist/markdownSections.test.d.ts.map +1 -0
  73. package/dist/markdownSections.test.js +95 -0
  74. package/dist/markdownSections.test.js.map +1 -0
  75. package/dist/pairing.d.ts +183 -0
  76. package/dist/pairing.d.ts.map +1 -0
  77. package/dist/pairing.js +175 -0
  78. package/dist/pairing.js.map +1 -0
  79. package/dist/pairing.test.d.ts +2 -0
  80. package/dist/pairing.test.d.ts.map +1 -0
  81. package/dist/pairing.test.js +105 -0
  82. package/dist/pairing.test.js.map +1 -0
  83. package/dist/photos.d.ts +146 -0
  84. package/dist/photos.d.ts.map +1 -0
  85. package/dist/photos.js +127 -0
  86. package/dist/photos.js.map +1 -0
  87. package/dist/publicModelCatalog.d.ts +19 -0
  88. package/dist/publicModelCatalog.d.ts.map +1 -0
  89. package/dist/publicModelCatalog.generated.d.ts +2 -0
  90. package/dist/publicModelCatalog.generated.d.ts.map +1 -0
  91. package/dist/publicModelCatalog.generated.js +489 -0
  92. package/dist/publicModelCatalog.generated.js.map +1 -0
  93. package/dist/publicModelCatalog.js +68 -0
  94. package/dist/publicModelCatalog.js.map +1 -0
  95. package/dist/publicModelCatalog.test.d.ts +2 -0
  96. package/dist/publicModelCatalog.test.d.ts.map +1 -0
  97. package/dist/publicModelCatalog.test.js +88 -0
  98. package/dist/publicModelCatalog.test.js.map +1 -0
  99. package/dist/publicModelNativeAliases.d.ts +5 -0
  100. package/dist/publicModelNativeAliases.d.ts.map +1 -0
  101. package/dist/publicModelNativeAliases.js +8 -0
  102. package/dist/publicModelNativeAliases.js.map +1 -0
  103. package/dist/schemas.d.ts +10745 -0
  104. package/dist/schemas.d.ts.map +1 -0
  105. package/dist/schemas.js +4572 -0
  106. package/dist/schemas.js.map +1 -0
  107. package/dist/schemas.test.d.ts +2 -0
  108. package/dist/schemas.test.d.ts.map +1 -0
  109. package/dist/schemas.test.js +1617 -0
  110. package/dist/schemas.test.js.map +1 -0
  111. package/dist/steeringOverTime.d.ts +30 -0
  112. package/dist/steeringOverTime.d.ts.map +1 -0
  113. package/dist/steeringOverTime.js +19 -0
  114. package/dist/steeringOverTime.js.map +1 -0
  115. package/dist/types.d.ts +109 -0
  116. package/dist/types.d.ts.map +1 -0
  117. package/dist/types.js +12 -0
  118. package/dist/types.js.map +1 -0
  119. package/dist/usageOnly.d.ts +190 -0
  120. package/dist/usageOnly.d.ts.map +1 -0
  121. package/dist/usageOnly.js +53 -0
  122. package/dist/usageOnly.js.map +1 -0
  123. package/dist/usageOnly.test.d.ts +2 -0
  124. package/dist/usageOnly.test.d.ts.map +1 -0
  125. package/dist/usageOnly.test.js +203 -0
  126. package/dist/usageOnly.test.js.map +1 -0
  127. package/dist/version.d.ts +47 -0
  128. package/dist/version.d.ts.map +1 -0
  129. package/dist/version.js +125 -0
  130. package/dist/version.js.map +1 -0
  131. package/dist/version.test.d.ts +2 -0
  132. package/dist/version.test.d.ts.map +1 -0
  133. package/dist/version.test.js +86 -0
  134. package/dist/version.test.js.map +1 -0
  135. package/dist/whatSyncs.d.ts +62 -0
  136. package/dist/whatSyncs.d.ts.map +1 -0
  137. package/dist/whatSyncs.js +228 -0
  138. package/dist/whatSyncs.js.map +1 -0
  139. package/dist/whatSyncs.test.d.ts +2 -0
  140. package/dist/whatSyncs.test.d.ts.map +1 -0
  141. package/dist/whatSyncs.test.js +113 -0
  142. package/dist/whatSyncs.test.js.map +1 -0
  143. package/package.json +52 -0
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The tags on every message between a Mossbear host page and an `html`
3
+ * artifact's frame. In a module of their own, with no imports, because the
4
+ * dashboard bundles its frame comment layer from source and anything this
5
+ * module pulled in would become part of that script.
6
+ */
7
+ /** Tag on every message the frame posts, so the host can tell ours by shape. */
8
+ export declare const FRAME_MESSAGE_SOURCE = "mossbear-frame";
9
+ /** Tag on every message the host posts into the frame. */
10
+ export declare const FRAME_HOST_MESSAGE_SOURCE = "mossbear-host";
11
+ //# sourceMappingURL=frameProtocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frameProtocol.d.ts","sourceRoot":"","sources":["../src/frameProtocol.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,gFAAgF;AAChF,eAAO,MAAM,oBAAoB,mBAAmB,CAAA;AAEpD,0DAA0D;AAC1D,eAAO,MAAM,yBAAyB,kBAAkB,CAAA"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The tags on every message between a Mossbear host page and an `html`
3
+ * artifact's frame. In a module of their own, with no imports, because the
4
+ * dashboard bundles its frame comment layer from source and anything this
5
+ * module pulled in would become part of that script.
6
+ */
7
+ /** Tag on every message the frame posts, so the host can tell ours by shape. */
8
+ export const FRAME_MESSAGE_SOURCE = 'mossbear-frame';
9
+ /** Tag on every message the host posts into the frame. */
10
+ export const FRAME_HOST_MESSAGE_SOURCE = 'mossbear-host';
11
+ //# sourceMappingURL=frameProtocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frameProtocol.js","sourceRoot":"","sources":["../src/frameProtocol.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,gFAAgF;AAChF,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAA;AAEpD,0DAA0D;AAC1D,MAAM,CAAC,MAAM,yBAAyB,GAAG,eAAe,CAAA"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @mossbear/protocol
3
+ *
4
+ * Runtime-validated shared schemas and transport contracts.
5
+ * This package must remain importable outside the CLI package.
6
+ */
7
+ export * from './agentGuidancePaths.js';
8
+ export * from './aliasPaths.js';
9
+ export * from './bundleSlug.js';
10
+ export * from './commentAnchor.js';
11
+ export * from './contextKinds.js';
12
+ export * from './frameDocument.js';
13
+ export * from './frameProtocol.js';
14
+ export * from './markdownSections.js';
15
+ export * from './pairing.js';
16
+ export * from './photos.js';
17
+ export * from './publicModelCatalog.js';
18
+ export * from './schemas.js';
19
+ export * from './steeringOverTime.js';
20
+ export * from './types.js';
21
+ export * from './usageOnly.js';
22
+ export * from './version.js';
23
+ export * from './whatSyncs.js';
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,yBAAyB,CAAA;AACvC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,yBAAyB,CAAA;AACvC,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @mossbear/protocol
3
+ *
4
+ * Runtime-validated shared schemas and transport contracts.
5
+ * This package must remain importable outside the CLI package.
6
+ */
7
+ export * from './agentGuidancePaths.js';
8
+ export * from './aliasPaths.js';
9
+ export * from './bundleSlug.js';
10
+ export * from './commentAnchor.js';
11
+ export * from './contextKinds.js';
12
+ export * from './frameDocument.js';
13
+ export * from './frameProtocol.js';
14
+ export * from './markdownSections.js';
15
+ export * from './pairing.js';
16
+ export * from './photos.js';
17
+ export * from './publicModelCatalog.js';
18
+ export * from './schemas.js';
19
+ export * from './steeringOverTime.js';
20
+ export * from './types.js';
21
+ export * from './usageOnly.js';
22
+ export * from './version.js';
23
+ export * from './whatSyncs.js';
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,yBAAyB,CAAA;AACvC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,yBAAyB,CAAA;AACvC,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Wire-level size limits, kept in a module with no imports.
3
+ *
4
+ * Lives apart from `schemas.ts` so a build-time script can read a limit
5
+ * without loading valibot or the package's compiled output. `schemas.ts`
6
+ * re-exports it, so `@mossbear/protocol` exposes the same name it always has.
7
+ */
8
+ /** Max serialized size (UTF-8 bytes) of a pushed or captured item's content. */
9
+ export declare const MAX_CONTEXT_CONTENT_BYTES: number;
10
+ /** Max serialized size (UTF-8 bytes) of an imported guide file's raw content. */
11
+ export declare const MAX_RAW_GUIDE_CONTENT_BYTES: number;
12
+ /** Max length, in characters, of an artifact's name. */
13
+ export declare const MAX_ARTIFACT_NAME_CHARS = 200;
14
+ /**
15
+ * Max length, in characters, of an artifact's description: one paragraph of
16
+ * plain text. Longer text belongs in a Markdown artifact.
17
+ */
18
+ export declare const MAX_ARTIFACT_DESCRIPTION_CHARS = 1000;
19
+ //# sourceMappingURL=limits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../src/limits.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,gFAAgF;AAChF,eAAO,MAAM,yBAAyB,QAAa,CAAA;AAEnD,iFAAiF;AACjF,eAAO,MAAM,2BAA2B,QAAa,CAAA;AAErD,wDAAwD;AACxD,eAAO,MAAM,uBAAuB,MAAM,CAAA;AAE1C;;;GAGG;AACH,eAAO,MAAM,8BAA8B,OAAO,CAAA"}
package/dist/limits.js ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Wire-level size limits, kept in a module with no imports.
3
+ *
4
+ * Lives apart from `schemas.ts` so a build-time script can read a limit
5
+ * without loading valibot or the package's compiled output. `schemas.ts`
6
+ * re-exports it, so `@mossbear/protocol` exposes the same name it always has.
7
+ */
8
+ /** Max serialized size (UTF-8 bytes) of a pushed or captured item's content. */
9
+ export const MAX_CONTEXT_CONTENT_BYTES = 256 * 1024;
10
+ /** Max serialized size (UTF-8 bytes) of an imported guide file's raw content. */
11
+ export const MAX_RAW_GUIDE_CONTENT_BYTES = 512 * 1024;
12
+ /** Max length, in characters, of an artifact's name. */
13
+ export const MAX_ARTIFACT_NAME_CHARS = 200;
14
+ /**
15
+ * Max length, in characters, of an artifact's description: one paragraph of
16
+ * plain text. Longer text belongs in a Markdown artifact.
17
+ */
18
+ export const MAX_ARTIFACT_DESCRIPTION_CHARS = 1000;
19
+ //# sourceMappingURL=limits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limits.js","sourceRoot":"","sources":["../src/limits.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,gFAAgF;AAChF,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,GAAG,IAAI,CAAA;AAEnD,iFAAiF;AACjF,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,GAAG,IAAI,CAAA;AAErD,wDAAwD;AACxD,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAA;AAE1C;;;GAGG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,IAAI,CAAA"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Markdown sections: the part of a document between one heading and the next.
3
+ *
4
+ * The server uses it to cut a search hit down to the section that holds the
5
+ * match. It lives in the protocol package so any client reading a guide's
6
+ * sections gets the same answer to "which lines are headings" — and the answer
7
+ * is not a regex over lines: a `#` line inside a fenced code block is a shell
8
+ * comment, and a `#` line in YAML frontmatter is a YAML comment.
9
+ *
10
+ * The functions take an **outline** rather than a whole body: the lines that can
11
+ * change the reading (headings, fences, frontmatter delimiters) with their line
12
+ * numbers. Every other line may be left out, which is what lets the server build
13
+ * the outline in the database and keep a large body there.
14
+ */
15
+ /** A line of a document, numbered from 1. */
16
+ export type OutlineLine = {
17
+ line: number;
18
+ text: string;
19
+ };
20
+ /** A real heading: not inside a code fence, not inside frontmatter. */
21
+ export type MarkdownHeading = {
22
+ line: number;
23
+ level: number;
24
+ text: string;
25
+ };
26
+ /**
27
+ * Where a line sits: the heading path down to its innermost section, that
28
+ * heading's line, and the line of the next heading of any level (exclusive).
29
+ * `startLine` is null above the first heading; `endLine` is null when nothing
30
+ * follows.
31
+ */
32
+ export type SectionPosition = {
33
+ path: string[];
34
+ startLine: number | null;
35
+ endLine: number | null;
36
+ };
37
+ /** The separator a heading path is written with. */
38
+ export declare const SECTION_PATH_SEPARATOR = " \u203A ";
39
+ /**
40
+ * Whether a line can change the outline. The server filters lines with the same
41
+ * rule in SQL (`OUTLINE_LINE_REGEX`), so a line left out there is one this
42
+ * module would have ignored anyway.
43
+ */
44
+ export declare function isOutlineLine(text: string): boolean;
45
+ /**
46
+ * {@link isOutlineLine} as a Postgres ARE, for filtering lines in the database.
47
+ * Kept beside the JavaScript rule so the two cannot drift apart unnoticed; the
48
+ * unit test pins them against the same lines.
49
+ */
50
+ export declare const OUTLINE_LINE_REGEX = "^ {0,3}(#{1,6}([ \\t\\r]|$)|`{3,}|~{3,})|^---[ \\t\\r]*$";
51
+ /**
52
+ * The real headings in an outline, in order. Lines must arrive in ascending
53
+ * order; any line that is not an outline line may be missing.
54
+ */
55
+ export declare function markdownHeadings(lines: Iterable<OutlineLine>): MarkdownHeading[];
56
+ /** The section a line belongs to — the innermost heading at or above it. */
57
+ export declare function sectionAt(headings: readonly MarkdownHeading[], line: number): SectionPosition;
58
+ //# sourceMappingURL=markdownSections.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdownSections.d.ts","sourceRoot":"","sources":["../src/markdownSections.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,6CAA6C;AAC7C,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAExD,uEAAuE;AACvE,MAAM,MAAM,eAAe,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAE3E;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CACvB,CAAA;AAED,oDAAoD;AACpD,eAAO,MAAM,sBAAsB,aAAQ,CAAA;AAM3C;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,6DAC6B,CAAA;AAO5D;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,eAAe,EAAE,CA4ChF;AAED,4EAA4E;AAC5E,wBAAgB,SAAS,CACvB,QAAQ,EAAE,SAAS,eAAe,EAAE,EACpC,IAAI,EAAE,MAAM,GACX,eAAe,CAkBjB"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Markdown sections: the part of a document between one heading and the next.
3
+ *
4
+ * The server uses it to cut a search hit down to the section that holds the
5
+ * match. It lives in the protocol package so any client reading a guide's
6
+ * sections gets the same answer to "which lines are headings" — and the answer
7
+ * is not a regex over lines: a `#` line inside a fenced code block is a shell
8
+ * comment, and a `#` line in YAML frontmatter is a YAML comment.
9
+ *
10
+ * The functions take an **outline** rather than a whole body: the lines that can
11
+ * change the reading (headings, fences, frontmatter delimiters) with their line
12
+ * numbers. Every other line may be left out, which is what lets the server build
13
+ * the outline in the database and keep a large body there.
14
+ */
15
+ /** The separator a heading path is written with. */
16
+ export const SECTION_PATH_SEPARATOR = ' › ';
17
+ const HEADING = /^ {0,3}(#{1,6})(?:[ \t]+(.*?))?[ \t\r]*$/;
18
+ const FENCE_OPEN = /^ {0,3}(`{3,}|~{3,})/;
19
+ const FRONTMATTER_DELIMITER = /^---[ \t\r]*$/;
20
+ /**
21
+ * Whether a line can change the outline. The server filters lines with the same
22
+ * rule in SQL (`OUTLINE_LINE_REGEX`), so a line left out there is one this
23
+ * module would have ignored anyway.
24
+ */
25
+ export function isOutlineLine(text) {
26
+ return HEADING.test(text) || FENCE_OPEN.test(text) || FRONTMATTER_DELIMITER.test(text);
27
+ }
28
+ /**
29
+ * {@link isOutlineLine} as a Postgres ARE, for filtering lines in the database.
30
+ * Kept beside the JavaScript rule so the two cannot drift apart unnoticed; the
31
+ * unit test pins them against the same lines.
32
+ */
33
+ export const OUTLINE_LINE_REGEX = '^ {0,3}(#{1,6}([ \\t\\r]|$)|`{3,}|~{3,})|^---[ \\t\\r]*$';
34
+ /** Heading text with its optional closing `#` run removed, as CommonMark reads it. */
35
+ function headingText(raw) {
36
+ return (raw ?? '').replace(/(?:^|[ \t]+)#+$/, '').trim();
37
+ }
38
+ /**
39
+ * The real headings in an outline, in order. Lines must arrive in ascending
40
+ * order; any line that is not an outline line may be missing.
41
+ */
42
+ export function markdownHeadings(lines) {
43
+ const headings = [];
44
+ let fence = null;
45
+ let inFrontmatter = false;
46
+ let first = true;
47
+ for (const { line, text } of lines) {
48
+ const isFirstLine = first && line === 1;
49
+ first = false;
50
+ if (inFrontmatter) {
51
+ if (FRONTMATTER_DELIMITER.test(text))
52
+ inFrontmatter = false;
53
+ continue;
54
+ }
55
+ if (isFirstLine && FRONTMATTER_DELIMITER.test(text)) {
56
+ inFrontmatter = true;
57
+ continue;
58
+ }
59
+ const fenceMatch = FENCE_OPEN.exec(text);
60
+ if (fence !== null) {
61
+ // A closing fence is the same character, at least as long, and nothing after it.
62
+ const run = fenceMatch?.[1];
63
+ if (run !== undefined &&
64
+ run[0] === fence.char &&
65
+ run.length >= fence.length &&
66
+ text.trim() === run) {
67
+ fence = null;
68
+ }
69
+ continue;
70
+ }
71
+ if (fenceMatch?.[1] !== undefined) {
72
+ fence = { char: fenceMatch[1][0], length: fenceMatch[1].length };
73
+ continue;
74
+ }
75
+ const heading = HEADING.exec(text);
76
+ if (heading?.[1] !== undefined) {
77
+ headings.push({ line, level: heading[1].length, text: headingText(heading[2]) });
78
+ }
79
+ }
80
+ return headings;
81
+ }
82
+ /** The section a line belongs to — the innermost heading at or above it. */
83
+ export function sectionAt(headings, line) {
84
+ const stack = [];
85
+ let endLine = null;
86
+ for (const heading of headings) {
87
+ if (heading.line > line) {
88
+ endLine = heading.line;
89
+ break;
90
+ }
91
+ while (stack.length > 0 && stack[stack.length - 1].level >= heading.level)
92
+ stack.pop();
93
+ stack.push(heading);
94
+ }
95
+ const innermost = stack[stack.length - 1];
96
+ return {
97
+ path: stack.map((heading) => heading.text),
98
+ startLine: innermost?.line ?? null,
99
+ endLine,
100
+ };
101
+ }
102
+ //# sourceMappingURL=markdownSections.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdownSections.js","sourceRoot":"","sources":["../src/markdownSections.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAoBH,oDAAoD;AACpD,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,CAAA;AAE3C,MAAM,OAAO,GAAG,0CAA0C,CAAA;AAC1D,MAAM,UAAU,GAAG,sBAAsB,CAAA;AACzC,MAAM,qBAAqB,GAAG,eAAe,CAAA;AAE7C;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACxF,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAC7B,0DAA0D,CAAA;AAE5D,sFAAsF;AACtF,SAAS,WAAW,CAAC,GAAuB;IAC1C,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,OA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C,SAAS,EAAE,SAAS,EAAE,IAAI,IAAI,IAAI;QAClC,OAAO;KACR,CAAA;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=markdownSections.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdownSections.test.d.ts","sourceRoot":"","sources":["../src/markdownSections.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,95 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { isOutlineLine, markdownHeadings, OUTLINE_LINE_REGEX, sectionAt, } from './markdownSections.js';
3
+ function outline(content) {
4
+ return content.split('\n').map((text, index) => ({ line: index + 1, text }));
5
+ }
6
+ const DOC = [
7
+ '---', // 1
8
+ 'name: deploy', // 2
9
+ '# not a heading', // 3
10
+ '---', // 4
11
+ '# Deploy', // 5
12
+ 'intro', // 6
13
+ '## Rollback', // 7
14
+ '```bash', // 8
15
+ '# revert the release', // 9
16
+ '```', // 10
17
+ 'run the revert', // 11
18
+ '### Database', // 12
19
+ 'restore the dump', // 13
20
+ '## Release ##', // 14
21
+ 'tag it', // 15
22
+ ].join('\n');
23
+ describe('markdownHeadings', () => {
24
+ it('skips frontmatter and fenced lines, and strips a closing # run', () => {
25
+ expect(markdownHeadings(outline(DOC))).toEqual([
26
+ { line: 5, level: 1, text: 'Deploy' },
27
+ { line: 7, level: 2, text: 'Rollback' },
28
+ { line: 12, level: 3, text: 'Database' },
29
+ { line: 14, level: 2, text: 'Release' },
30
+ ]);
31
+ });
32
+ it('reads the same headings from only the outline lines', () => {
33
+ const lines = outline(DOC).filter((entry) => isOutlineLine(entry.text));
34
+ expect(markdownHeadings(lines)).toEqual(markdownHeadings(outline(DOC)));
35
+ });
36
+ it('does not close a fence on a shorter or different run', () => {
37
+ const doc = ['````', '```', '# inside', '~~~~', '````', '# Outside'].join('\n');
38
+ expect(markdownHeadings(outline(doc)).map((h) => h.text)).toEqual(['Outside']);
39
+ });
40
+ it('does not read a hashtag or seven hashes as a heading', () => {
41
+ expect(markdownHeadings(outline('#tag\n####### seven\n#'))).toEqual([
42
+ { line: 3, level: 1, text: '' },
43
+ ]);
44
+ });
45
+ });
46
+ describe('OUTLINE_LINE_REGEX', () => {
47
+ it('agrees with isOutlineLine, so the database keeps every line that matters', () => {
48
+ const regex = new RegExp(OUTLINE_LINE_REGEX);
49
+ const samples = [
50
+ '# a',
51
+ ' ## b',
52
+ ' # indented code',
53
+ '#tag',
54
+ '#',
55
+ '```ts',
56
+ '~~~',
57
+ '``',
58
+ '---',
59
+ '--- x',
60
+ 'text',
61
+ '## c\r',
62
+ '---\r',
63
+ ];
64
+ for (const sample of samples)
65
+ expect(regex.test(sample)).toBe(isOutlineLine(sample));
66
+ });
67
+ });
68
+ describe('sectionAt', () => {
69
+ const headings = markdownHeadings(outline(DOC));
70
+ it('names the innermost section and its path, three deep', () => {
71
+ expect(sectionAt(headings, 13)).toEqual({
72
+ path: ['Deploy', 'Rollback', 'Database'],
73
+ startLine: 12,
74
+ endLine: 14,
75
+ });
76
+ });
77
+ it('puts a fenced # line in the section around it', () => {
78
+ expect(sectionAt(headings, 9)).toEqual({
79
+ path: ['Deploy', 'Rollback'],
80
+ startLine: 7,
81
+ endLine: 12,
82
+ });
83
+ });
84
+ it('pops back to the parent level for a sibling', () => {
85
+ expect(sectionAt(headings, 15)).toEqual({
86
+ path: ['Deploy', 'Release'],
87
+ startLine: 14,
88
+ endLine: null,
89
+ });
90
+ });
91
+ it('has no path above the first heading', () => {
92
+ expect(sectionAt(headings, 2)).toEqual({ path: [], startLine: null, endLine: 5 });
93
+ });
94
+ });
95
+ //# sourceMappingURL=markdownSections.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdownSections.test.js","sourceRoot":"","sources":["../src/markdownSections.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,kBA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B,SAAS,EAAE,EAAE;YACb,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC7C,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAA;IACnF,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Device-pairing transport contract — `mossbear login`.
3
+ *
4
+ * Shape is RFC 8628 (OAuth 2.0 Device Authorization Grant): the CLI asks for a
5
+ * pairing, gets back a long secret it keeps (`deviceCode`) and a short one the
6
+ * human retypes in a browser (`userCode`), then polls until a signed-in user
7
+ * approves or denies it.
8
+ *
9
+ * The two codes are deliberately asymmetric, and the asymmetry is the whole
10
+ * security argument:
11
+ *
12
+ * - `deviceCode` is the *credential*. It never leaves the machine that asked
13
+ * for the pairing, so it is sized like a credential (256 bits) and the
14
+ * server stores only its hash.
15
+ * - `userCode` is *typed by a human*, so it is sized for the smallest thing a
16
+ * human will retype without resenting it — {@link PAIRING_CODE_LENGTH}
17
+ * characters of {@link PAIRING_CODE_ALPHABET}, which is 38.4 bits. That is
18
+ * well above RFC 8628 §5.1's 20-bit floor, but it is still small enough that
19
+ * entropy alone is not the control: a per-pairing attempt budget enforced in
20
+ * the database is (`~/server/pairing/` in the dashboard).
21
+ *
22
+ * This file is the one home for the code's shape because three callers need
23
+ * it and must agree: the server generates it, the `/pair` page accepts it
24
+ * typed back in any casing or spacing, and the CLI prints it.
25
+ */
26
+ import * as v from 'valibot';
27
+ /**
28
+ * Symbols a pairing code may contain.
29
+ *
30
+ * Twenty consonants and eight digits. Every vowel is out, and so is `Y` — a
31
+ * code with no vowel in it cannot spell a word a user then reports as
32
+ * offensive. `0`, `1` and `I` are out on top of that, being the characters
33
+ * people mis-transcribe when reading a code off one screen and typing it into
34
+ * another. (`O` and `U` are already gone as vowels; `L` stays, since the two
35
+ * things it is confusable with are both excluded.)
36
+ */
37
+ export declare const PAIRING_CODE_ALPHABET = "BCDFGHJKLMNPQRSTVWXZ23456789";
38
+ /** Characters in a pairing code, excluding the display hyphen. */
39
+ export declare const PAIRING_CODE_LENGTH = 8;
40
+ /** Where the hyphen goes when a code is shown to a human: `XXXX-XXXX`. */
41
+ export declare const PAIRING_CODE_GROUP_SIZE = 4;
42
+ /**
43
+ * Strip a user's typing back to the canonical form the server stores.
44
+ *
45
+ * Accepts what people actually type when copying a code off another screen:
46
+ * lowercase, spaces, hyphens anywhere (not only where we put one). Returns the
47
+ * uppercase, separator-free string — **which may still not be a valid code**;
48
+ * callers pair this with {@link isWellFormedUserCode} rather than trusting it.
49
+ */
50
+ export declare function normalizeUserCode(input: string): string;
51
+ /**
52
+ * Insert the display hyphen: `7X2QBM4T` → `7X2Q-BM4T`.
53
+ *
54
+ * Input is normalized first, so this is safe to call on a code that has
55
+ * already been formatted (it will not accumulate hyphens).
56
+ */
57
+ export declare function formatUserCode(code: string): string;
58
+ /**
59
+ * Whether a normalized code could have been generated by this server.
60
+ *
61
+ * A cheap shape check, not an authorization one — it exists so a typo costs a
62
+ * validation message rather than a database round trip and an attempt off the
63
+ * pairing's budget.
64
+ */
65
+ export declare function isWellFormedUserCode(code: string): boolean;
66
+ /**
67
+ * A pairing code as it arrives from a client. Normalized then shape-checked,
68
+ * so every consumer downstream of a parse holds the canonical form.
69
+ */
70
+ export declare const UserCodeSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string>, v.CheckAction<string, "not a pairing code">]>;
71
+ export declare const PairInitiateRequestSchema: v.ObjectSchema<{
72
+ /**
73
+ * What the user will see on the approval page — a hostname, typically.
74
+ * Untrusted display text: the page renders it as text, never as markup.
75
+ */
76
+ readonly deviceName: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MaxLengthAction<string, 64, undefined>]>, undefined>;
77
+ readonly cliVersion: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MaxLengthAction<string, 32, undefined>]>, undefined>;
78
+ }, undefined>;
79
+ export type PairInitiateRequest = v.InferOutput<typeof PairInitiateRequestSchema>;
80
+ export declare const PairInitiateResponseSchema: v.ObjectSchema<{
81
+ /** The CLI's secret. Sent once, never returned by any other endpoint. */
82
+ readonly deviceCode: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
83
+ /** Hyphenated for display — the CLI prints this verbatim. */
84
+ readonly userCode: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
85
+ readonly verificationUri: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
86
+ /** `verificationUri` with the code prefilled, for a clickable terminal link. */
87
+ readonly verificationUriComplete: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
88
+ /** Seconds until the pairing expires. */
89
+ readonly expiresIn: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
90
+ /** Seconds the CLI must wait between polls (RFC 8628 §3.2 `interval`). */
91
+ readonly interval: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
92
+ }, undefined>;
93
+ export type PairInitiateResponse = v.InferOutput<typeof PairInitiateResponseSchema>;
94
+ export declare const PairPollRequestSchema: v.ObjectSchema<{
95
+ readonly deviceCode: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 256, undefined>]>;
96
+ }, undefined>;
97
+ export type PairPollRequest = v.InferOutput<typeof PairPollRequestSchema>;
98
+ /**
99
+ * Poll outcomes.
100
+ *
101
+ * A variant rather than an HTTP status code per outcome: `denied` and
102
+ * `expired` are *protocol answers*, not transport failures, and the CLI has to
103
+ * tell them apart to say something useful. Transport failures stay transport
104
+ * failures — an unparseable body is 400, an unknown device code is 404, and
105
+ * polling faster than `interval` is 429.
106
+ */
107
+ export declare const PairPollResponseSchema: v.VariantSchema<"status", [v.ObjectSchema<{
108
+ readonly status: v.LiteralSchema<"pending", undefined>;
109
+ readonly interval: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
110
+ }, undefined>, v.ObjectSchema<{
111
+ readonly status: v.LiteralSchema<"complete", undefined>;
112
+ /**
113
+ * The CLI token, delivered exactly once. A second poll of the same
114
+ * pairing gets `expired`, because the pairing is consumed by this one.
115
+ */
116
+ readonly token: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
117
+ /** Who approved it, so the CLI can say "Paired as …". */
118
+ readonly email: v.NullableSchema<v.StringSchema<undefined>, undefined>;
119
+ }, undefined>, v.ObjectSchema<{
120
+ readonly status: v.LiteralSchema<"denied", undefined>;
121
+ }, undefined>, v.ObjectSchema<{
122
+ readonly status: v.LiteralSchema<"expired", undefined>;
123
+ }, undefined>], undefined>;
124
+ export type PairPollResponse = v.InferOutput<typeof PairPollResponseSchema>;
125
+ /** What the `/pair` page shows before asking the user to decide. */
126
+ export declare const PairLookupResponseSchema: v.ObjectSchema<{
127
+ readonly userCode: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
128
+ readonly deviceName: v.NullableSchema<v.StringSchema<undefined>, undefined>;
129
+ readonly cliVersion: v.NullableSchema<v.StringSchema<undefined>, undefined>;
130
+ /** ISO 8601. The page counts down against it. */
131
+ readonly expiresAt: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
132
+ }, undefined>;
133
+ export type PairLookupResponse = v.InferOutput<typeof PairLookupResponseSchema>;
134
+ export declare const PairDecisionRequestSchema: v.ObjectSchema<{
135
+ readonly userCode: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string>, v.CheckAction<string, "not a pairing code">]>;
136
+ readonly decision: v.PicklistSchema<["approve", "deny"], undefined>;
137
+ }, undefined>;
138
+ export type PairDecisionRequest = v.InferOutput<typeof PairDecisionRequestSchema>;
139
+ export declare const PairDecisionResponseSchema: v.ObjectSchema<{
140
+ readonly status: v.PicklistSchema<["approved", "denied"], undefined>;
141
+ }, undefined>;
142
+ export type PairDecisionResponse = v.InferOutput<typeof PairDecisionResponseSchema>;
143
+ export declare function parsePairInitiateRequest(data: unknown): {
144
+ deviceName?: string | undefined;
145
+ cliVersion?: string | undefined;
146
+ };
147
+ export declare function parsePairInitiateResponse(data: unknown): {
148
+ deviceCode: string;
149
+ userCode: string;
150
+ verificationUri: string;
151
+ verificationUriComplete: string;
152
+ expiresIn: number;
153
+ interval: number;
154
+ };
155
+ export declare function parsePairPollRequest(data: unknown): {
156
+ deviceCode: string;
157
+ };
158
+ export declare function parsePairPollResponse(data: unknown): {
159
+ status: "pending";
160
+ interval: number;
161
+ } | {
162
+ status: "complete";
163
+ token: string;
164
+ email: string | null;
165
+ } | {
166
+ status: "denied";
167
+ } | {
168
+ status: "expired";
169
+ };
170
+ export declare function parsePairLookupResponse(data: unknown): {
171
+ userCode: string;
172
+ deviceName: string | null;
173
+ cliVersion: string | null;
174
+ expiresAt: string;
175
+ };
176
+ export declare function parsePairDecisionRequest(data: unknown): {
177
+ userCode: string;
178
+ decision: "approve" | "deny";
179
+ };
180
+ export declare function parsePairDecisionResponse(data: unknown): {
181
+ status: "approved" | "denied";
182
+ };
183
+ //# sourceMappingURL=pairing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pairing.d.ts","sourceRoot":"","sources":["../src/pairing.ts"],"names":[],"mappings":"AAAA;;;;;;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