@getmateo/protocol 0.0.0-stage → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/LICENSE +211 -0
  2. package/README.md +11 -2
  3. package/dist/addresses.d.ts +6 -0
  4. package/dist/addresses.js +2 -0
  5. package/dist/agent-attention-notification.d.ts +57 -0
  6. package/dist/agent-attention-notification.js +177 -0
  7. package/dist/agent-deep-link.d.ts +8 -0
  8. package/dist/agent-deep-link.js +49 -0
  9. package/dist/agent-labels.d.ts +14 -0
  10. package/dist/agent-labels.js +38 -0
  11. package/dist/agent-lifecycle.d.ts +3 -0
  12. package/dist/agent-lifecycle.js +8 -0
  13. package/dist/agent-message.d.ts +20 -0
  14. package/dist/agent-message.js +12 -0
  15. package/dist/agent-profile.d.ts +31 -0
  16. package/dist/agent-profile.js +32 -0
  17. package/dist/agent-runtime-config.d.ts +4 -0
  18. package/dist/agent-runtime-config.js +5 -0
  19. package/dist/agent-shells.d.ts +25 -0
  20. package/dist/agent-shells.js +17 -0
  21. package/dist/agent-state-bucket.d.ts +15 -0
  22. package/dist/agent-state-bucket.js +41 -0
  23. package/dist/agent-title-limits.d.ts +2 -0
  24. package/dist/agent-title-limits.js +2 -0
  25. package/dist/agent-types.d.ts +484 -0
  26. package/dist/agent-types.js +33 -0
  27. package/dist/binary-frames/demux.d.ts +15 -0
  28. package/dist/binary-frames/demux.js +28 -0
  29. package/dist/binary-frames/file-transfer.d.ts +51 -0
  30. package/dist/binary-frames/file-transfer.js +108 -0
  31. package/dist/binary-frames/host-route.d.ts +13 -0
  32. package/dist/binary-frames/host-route.js +39 -0
  33. package/dist/binary-frames/index.d.ts +5 -0
  34. package/dist/binary-frames/index.js +5 -0
  35. package/dist/binary-frames/terminal.d.ts +35 -0
  36. package/dist/binary-frames/terminal.js +100 -0
  37. package/dist/branch-slug.d.ts +14 -0
  38. package/dist/branch-slug.js +49 -0
  39. package/dist/browser-automation/capabilities.d.ts +7 -0
  40. package/dist/browser-automation/capabilities.js +31 -0
  41. package/dist/browser-automation/rpc-schemas.d.ts +1224 -0
  42. package/dist/browser-automation/rpc-schemas.js +497 -0
  43. package/dist/browser-download-rules.d.ts +21 -0
  44. package/dist/browser-download-rules.js +54 -0
  45. package/dist/build-metadata.d.ts +17 -0
  46. package/dist/build-metadata.js +61 -0
  47. package/dist/chat/rpc-schemas.d.ts +158 -0
  48. package/dist/chat/rpc-schemas.js +104 -0
  49. package/dist/chat/types.d.ts +30 -0
  50. package/dist/chat/types.js +23 -0
  51. package/dist/check-traits.d.ts +11 -0
  52. package/dist/check-traits.js +10 -0
  53. package/dist/chunked-transport.d.ts +42 -0
  54. package/dist/chunked-transport.js +277 -0
  55. package/dist/client-capabilities.d.ts +24 -0
  56. package/dist/client-capabilities.js +52 -0
  57. package/dist/connection-offer.d.ts +36 -0
  58. package/dist/connection-offer.js +53 -0
  59. package/dist/daemon-auth.d.ts +548 -0
  60. package/dist/daemon-auth.js +152 -0
  61. package/dist/daemon-endpoints.d.ts +54 -0
  62. package/dist/daemon-endpoints.js +243 -0
  63. package/dist/error-utils.d.ts +11 -0
  64. package/dist/error-utils.js +27 -0
  65. package/dist/fleet.d.ts +381 -0
  66. package/dist/fleet.js +134 -0
  67. package/dist/forge-manifest.d.ts +66 -0
  68. package/dist/forge-manifest.js +92 -0
  69. package/dist/generated/validation/ws-outbound-schema-metadata.d.ts +14187 -0
  70. package/dist/generated/validation/ws-outbound-schema-metadata.js +262 -0
  71. package/dist/generated/validation/ws-outbound.aot.d.ts +520 -0
  72. package/dist/generated/validation/ws-outbound.aot.js +106677 -0
  73. package/dist/git-remote.d.ts +33 -0
  74. package/dist/git-remote.js +94 -0
  75. package/dist/gitea-status.d.ts +10 -0
  76. package/dist/gitea-status.js +23 -0
  77. package/dist/gitlab-pipeline.d.ts +10 -0
  78. package/dist/gitlab-pipeline.js +17 -0
  79. package/dist/global-terminal.d.ts +3 -0
  80. package/dist/global-terminal.js +8 -0
  81. package/dist/host-connection-schema.d.ts +11 -0
  82. package/dist/host-connection-schema.js +9 -0
  83. package/dist/host-target.d.ts +20 -0
  84. package/dist/host-target.js +137 -0
  85. package/dist/hosts.d.ts +133 -0
  86. package/dist/hosts.js +82 -0
  87. package/dist/literal-union.d.ts +2 -0
  88. package/dist/literal-union.js +2 -0
  89. package/dist/loop/rpc-schemas.d.ts +636 -0
  90. package/dist/loop/rpc-schemas.js +164 -0
  91. package/dist/mateo-config-schema.d.ts +138 -0
  92. package/dist/mateo-config-schema.js +98 -0
  93. package/dist/mateo-tool-call-detail.d.ts +2 -0
  94. package/dist/mateo-tool-call-detail.js +3 -0
  95. package/dist/mateo-tool-presentation/agent-message.d.ts +10 -0
  96. package/dist/mateo-tool-presentation/agent-message.js +23 -0
  97. package/dist/mateo-tool-presentation/catalog.d.ts +321 -0
  98. package/dist/mateo-tool-presentation/catalog.js +319 -0
  99. package/dist/mateo-tool-presentation/detail-sections.d.ts +15 -0
  100. package/dist/mateo-tool-presentation/detail-sections.js +161 -0
  101. package/dist/mateo-tool-presentation/index.d.ts +22 -0
  102. package/dist/mateo-tool-presentation/index.js +62 -0
  103. package/dist/mateo-tool-presentation/summary-text.d.ts +7 -0
  104. package/dist/mateo-tool-presentation/summary-text.js +22 -0
  105. package/dist/messages.d.ts +70260 -0
  106. package/dist/messages.js +6740 -0
  107. package/dist/path-utils.d.ts +2 -0
  108. package/dist/path-utils.js +16 -0
  109. package/dist/plugin-browser-consent-copy.d.ts +193 -0
  110. package/dist/plugin-browser-consent-copy.js +109 -0
  111. package/dist/plugin-browser-grants.d.ts +48 -0
  112. package/dist/plugin-browser-grants.js +56 -0
  113. package/dist/plugin-browser.d.ts +321 -0
  114. package/dist/plugin-browser.js +109 -0
  115. package/dist/plugin-config.d.ts +18 -0
  116. package/dist/plugin-config.js +13 -0
  117. package/dist/plugin-overview.d.ts +12 -0
  118. package/dist/plugin-overview.js +50 -0
  119. package/dist/plugin-registry.d.ts +153 -0
  120. package/dist/plugin-registry.js +83 -0
  121. package/dist/plugin-requirements.d.ts +11 -0
  122. package/dist/plugin-requirements.js +26 -0
  123. package/dist/plugin-source-reference.d.ts +11 -0
  124. package/dist/plugin-source-reference.js +68 -0
  125. package/dist/provider-config.d.ts +141 -0
  126. package/dist/provider-config.js +113 -0
  127. package/dist/provider-icon-names.d.ts +5 -0
  128. package/dist/provider-icon-names.js +54 -0
  129. package/dist/provider-manifest.d.ts +30 -0
  130. package/dist/provider-manifest.js +247 -0
  131. package/dist/provider-snapshot-codec.d.ts +18 -0
  132. package/dist/provider-snapshot-codec.js +71 -0
  133. package/dist/schedule/cadence.d.ts +6 -0
  134. package/dist/schedule/cadence.js +28 -0
  135. package/dist/schedule/cron-expression.d.ts +14 -0
  136. package/dist/schedule/cron-expression.js +107 -0
  137. package/dist/schedule/rpc-schemas.d.ts +570 -0
  138. package/dist/schedule/rpc-schemas.js +158 -0
  139. package/dist/schedule/types.d.ts +201 -0
  140. package/dist/schedule/types.js +68 -0
  141. package/dist/search/text-match.d.ts +78 -0
  142. package/dist/search/text-match.js +330 -0
  143. package/dist/service-defaults.d.ts +3 -0
  144. package/dist/service-defaults.js +5 -0
  145. package/dist/ssh-transport.d.ts +11 -0
  146. package/dist/ssh-transport.js +72 -0
  147. package/dist/terminal-activity.d.ts +21 -0
  148. package/dist/terminal-activity.js +25 -0
  149. package/dist/terminal-input-mode.d.ts +30 -0
  150. package/dist/terminal-input-mode.js +180 -0
  151. package/dist/terminal-key-input.d.ts +13 -0
  152. package/dist/terminal-key-input.js +210 -0
  153. package/dist/terminal-profile.d.ts +10 -0
  154. package/dist/terminal-profile.js +11 -0
  155. package/dist/terminal-profiles.d.ts +41 -0
  156. package/dist/terminal-profiles.js +276 -0
  157. package/dist/terminal-snapshot.d.ts +4 -0
  158. package/dist/terminal-snapshot.js +220 -0
  159. package/dist/terminal-stream-protocol.d.ts +2 -0
  160. package/dist/terminal-stream-protocol.js +2 -0
  161. package/dist/terminal-subscription-key.d.ts +2 -0
  162. package/dist/terminal-subscription-key.js +9 -0
  163. package/dist/timeline-identity.d.ts +3 -0
  164. package/dist/timeline-identity.js +8 -0
  165. package/dist/tool-call-display.d.ts +13 -0
  166. package/dist/tool-call-display.js +144 -0
  167. package/dist/tool-name-normalization.d.ts +9 -0
  168. package/dist/tool-name-normalization.js +82 -0
  169. package/dist/user-agent.d.ts +26 -0
  170. package/dist/user-agent.js +101 -0
  171. package/dist/validation/ws-outbound-envelope.d.ts +13413 -0
  172. package/dist/validation/ws-outbound-envelope.js +17 -0
  173. package/dist/validation/ws-outbound.d.ts +12 -0
  174. package/dist/validation/ws-outbound.js +38 -0
  175. package/dist/websocket-message-limit.d.ts +5 -0
  176. package/dist/websocket-message-limit.js +5 -0
  177. package/dist/workspace-labels.d.ts +9 -0
  178. package/dist/workspace-labels.js +19 -0
  179. package/package.json +48 -4
@@ -0,0 +1,330 @@
1
+ /**
2
+ * Ranked text matching shared by the app's pickers and the daemon's history
3
+ * search. A match is a tier plus the offset it was found at; lower is better on
4
+ * both, so callers sort ascending and never have to invent a scale.
5
+ *
6
+ * Typo tolerance is opt-in via `fuzzy`. The pickers leave it off — a combobox
7
+ * over a known list wants exact narrowing — while history search turns it on
8
+ * because the user is recalling a title from memory.
9
+ */
10
+ /** Exact tiers, best to worst. The fuzzy tier always sorts after all of them. */
11
+ const TIER_EXACT = 0;
12
+ const TIER_WHOLE_WORD = 1;
13
+ const TIER_PREFIX = 2;
14
+ const TIER_WORD_START = 3;
15
+ const TIER_SUBSTRING = 4;
16
+ const TIER_SUBSEQUENCE = 5;
17
+ const TIER_FUZZY = 6;
18
+ function isWordBoundaryChar(ch) {
19
+ if (ch === undefined)
20
+ return true;
21
+ return !/[a-z0-9]/.test(ch);
22
+ }
23
+ function scoreSubstringMatch(query, text) {
24
+ let best = null;
25
+ let pos = 0;
26
+ while (pos <= text.length - query.length) {
27
+ const found = text.indexOf(query, pos);
28
+ if (found === -1)
29
+ break;
30
+ const before = found > 0 ? text[found - 1] : undefined;
31
+ const after = text[found + query.length];
32
+ const startsAtBoundary = found === 0 || isWordBoundaryChar(before);
33
+ const endsAtBoundary = after === undefined || isWordBoundaryChar(after);
34
+ let tier;
35
+ if (startsAtBoundary && endsAtBoundary) {
36
+ tier = TIER_WHOLE_WORD;
37
+ }
38
+ else if (found === 0) {
39
+ tier = TIER_PREFIX;
40
+ }
41
+ else if (startsAtBoundary) {
42
+ tier = TIER_WORD_START;
43
+ }
44
+ else {
45
+ tier = TIER_SUBSTRING;
46
+ }
47
+ if (!best || tier < best.tier || (tier === best.tier && found < best.offset)) {
48
+ best = { tier, offset: found };
49
+ }
50
+ pos = found + 1;
51
+ }
52
+ return best;
53
+ }
54
+ function scoreSubsequenceMatch(query, text) {
55
+ let queryIndex = 0;
56
+ let firstIndex = -1;
57
+ let lastIndex = -1;
58
+ for (let textIndex = 0; textIndex < text.length && queryIndex < query.length; textIndex += 1) {
59
+ if (/\s/u.test(text[textIndex])) {
60
+ queryIndex = 0;
61
+ firstIndex = -1;
62
+ lastIndex = -1;
63
+ continue;
64
+ }
65
+ if (text[textIndex] !== query[queryIndex])
66
+ continue;
67
+ if (firstIndex === -1)
68
+ firstIndex = textIndex;
69
+ lastIndex = textIndex;
70
+ queryIndex += 1;
71
+ }
72
+ if (queryIndex !== query.length || firstIndex === -1)
73
+ return null;
74
+ return { tier: TIER_SUBSEQUENCE, offset: firstIndex, spread: lastIndex - firstIndex + 1 };
75
+ }
76
+ /**
77
+ * Damerau-Levenshtein distance, abandoned as soon as every cell in a row is
78
+ * over budget. Bounding it is what keeps the fuzzy tier affordable to run
79
+ * against every word of every candidate.
80
+ */
81
+ function boundedEditDistance(query, word, budget) {
82
+ if (Math.abs(query.length - word.length) > budget)
83
+ return null;
84
+ let twoRowsBack = [];
85
+ let previousRow = Array.from({ length: word.length + 1 }, (_, index) => index);
86
+ for (let queryIndex = 1; queryIndex <= query.length; queryIndex += 1) {
87
+ const currentRow = [queryIndex];
88
+ let rowBest = queryIndex;
89
+ for (let wordIndex = 1; wordIndex <= word.length; wordIndex += 1) {
90
+ const substitutionCost = query[queryIndex - 1] === word[wordIndex - 1] ? 0 : 1;
91
+ let cost = Math.min(currentRow[wordIndex - 1] + 1, previousRow[wordIndex] + 1, previousRow[wordIndex - 1] + substitutionCost);
92
+ const isTransposition = queryIndex > 1 &&
93
+ wordIndex > 1 &&
94
+ query[queryIndex - 1] === word[wordIndex - 2] &&
95
+ query[queryIndex - 2] === word[wordIndex - 1];
96
+ if (isTransposition) {
97
+ cost = Math.min(cost, twoRowsBack[wordIndex - 2] + 1);
98
+ }
99
+ currentRow.push(cost);
100
+ rowBest = Math.min(rowBest, cost);
101
+ }
102
+ if (rowBest > budget)
103
+ return null;
104
+ twoRowsBack = previousRow;
105
+ previousRow = currentRow;
106
+ }
107
+ const distance = previousRow[word.length];
108
+ return distance <= budget ? distance : null;
109
+ }
110
+ function transpositionDistance(query, word) {
111
+ return isAdjacentTransposition(query, word) ? 1 : null;
112
+ }
113
+ /** True when the two differ only by one swap of neighbouring characters. */
114
+ function isAdjacentTransposition(query, word) {
115
+ if (query.length !== word.length)
116
+ return false;
117
+ let index = 0;
118
+ while (index < query.length && query[index] === word[index])
119
+ index += 1;
120
+ if (index >= query.length - 1)
121
+ return false;
122
+ if (query[index] !== word[index + 1] || query[index + 1] !== word[index])
123
+ return false;
124
+ return query.slice(index + 2) === word.slice(index + 2);
125
+ }
126
+ export function fuzzyPolicyForToken(token) {
127
+ if (token.length <= 3)
128
+ return null;
129
+ if (token.length === 4)
130
+ return { maxEdits: 1, transpositionsOnly: true };
131
+ if (token.length <= 7)
132
+ return { maxEdits: 1, transpositionsOnly: false };
133
+ return { maxEdits: 2, transpositionsOnly: false };
134
+ }
135
+ /**
136
+ * Words are what people mistype, so the fuzzy tier compares the query against
137
+ * each word rather than against the whole string — otherwise a long title's
138
+ * length difference alone would blow the budget.
139
+ */
140
+ function scoreFuzzyMatch(query, text, policy) {
141
+ if (policy.maxEdits <= 0 || query.length <= policy.maxEdits)
142
+ return null;
143
+ let best = null;
144
+ const wordPattern = /[a-z0-9]+/g;
145
+ let word = wordPattern.exec(text);
146
+ while (word !== null) {
147
+ // Compare against the whole word and against its leading slices, so a typo
148
+ // in a prefix ("confug" for "configuration") still lands — the length gap
149
+ // to the full word would otherwise blow the budget on its own.
150
+ const candidates = new Set([
151
+ word[0],
152
+ word[0].slice(0, query.length),
153
+ word[0].slice(0, query.length + policy.maxEdits),
154
+ ]);
155
+ for (const candidate of candidates) {
156
+ const distance = policy.transpositionsOnly
157
+ ? transpositionDistance(query, candidate)
158
+ : boundedEditDistance(query, candidate, policy.maxEdits);
159
+ if (distance === null)
160
+ continue;
161
+ const score = { tier: TIER_FUZZY, offset: word.index, spread: distance };
162
+ if (!best || compareMatchScores(score, best) < 0) {
163
+ best = score;
164
+ }
165
+ }
166
+ word = wordPattern.exec(text);
167
+ }
168
+ return best;
169
+ }
170
+ export function scoreMatch(query, text, options = {}) {
171
+ if (!query)
172
+ return { tier: TIER_EXACT, offset: 0 };
173
+ const q = query.toLowerCase();
174
+ const t = text.toLowerCase();
175
+ if (t === q)
176
+ return { tier: TIER_EXACT, offset: 0 };
177
+ const substring = scoreSubstringMatch(q, t);
178
+ const exact = substring ?? (options.subsequence === false ? null : scoreSubsequenceMatch(q, t));
179
+ if (exact)
180
+ return exact;
181
+ const fuzzy = options.fuzzy;
182
+ return fuzzy ? scoreFuzzyMatch(q, t, fuzzy) : null;
183
+ }
184
+ function compactText(value) {
185
+ let compact = "";
186
+ const offsets = [];
187
+ for (let index = 0; index < value.length; index += 1) {
188
+ if (!/[a-z0-9]/i.test(value[index]))
189
+ continue;
190
+ compact += value[index].toLowerCase();
191
+ offsets.push(index);
192
+ }
193
+ return { value: compact, offsets };
194
+ }
195
+ /** Match a query against a complete displayed path, including its separators. */
196
+ export function scorePathMatch(query, path) {
197
+ const direct = scoreMatch(query, path);
198
+ if (direct)
199
+ return direct;
200
+ const compactQuery = compactText(query);
201
+ const compactPath = compactText(path);
202
+ if (!compactQuery.value || !compactPath.value)
203
+ return null;
204
+ const compactScore = scoreMatch(compactQuery.value, compactPath.value);
205
+ if (!compactScore)
206
+ return null;
207
+ return {
208
+ ...compactScore,
209
+ offset: compactPath.offsets[compactScore.offset] ?? compactScore.offset,
210
+ };
211
+ }
212
+ function mergeAdjacentRanges(indices) {
213
+ const ranges = [];
214
+ for (const index of indices) {
215
+ const last = ranges.at(-1);
216
+ if (last && last.start + last.length === index) {
217
+ last.length += 1;
218
+ continue;
219
+ }
220
+ ranges.push({ start: index, length: 1 });
221
+ }
222
+ return ranges;
223
+ }
224
+ function wordRangeAt(text, offset) {
225
+ let end = offset;
226
+ while (end < text.length && /[a-z0-9]/.test(text[end]))
227
+ end += 1;
228
+ return { start: offset, length: Math.max(end - offset, 1) };
229
+ }
230
+ /**
231
+ * Where a score's match actually landed, so a caller can mark it. Derived from
232
+ * a score rather than produced alongside one: ranking touches every candidate
233
+ * and needs no ranges, while only the handful of rows that get rendered do.
234
+ *
235
+ * The tier decides the shape. A substring hit is one span; a subsequence hit is
236
+ * the scattered characters it walked; a typo hit marks the whole word, because
237
+ * the characters the user got wrong are not in the text to point at.
238
+ */
239
+ export function matchRanges(query, text, score) {
240
+ if (!query)
241
+ return [];
242
+ const q = query.toLowerCase();
243
+ const t = text.toLowerCase();
244
+ if (score.tier === TIER_EXACT)
245
+ return [{ start: 0, length: text.length }];
246
+ if (score.tier === TIER_FUZZY)
247
+ return [wordRangeAt(t, score.offset)];
248
+ if (score.tier === TIER_SUBSEQUENCE) {
249
+ const indices = [];
250
+ let queryIndex = 0;
251
+ for (let textIndex = score.offset; textIndex < t.length && queryIndex < q.length; textIndex += 1) {
252
+ if (t[textIndex] !== q[queryIndex])
253
+ continue;
254
+ indices.push(textIndex);
255
+ queryIndex += 1;
256
+ }
257
+ return mergeAdjacentRanges(indices);
258
+ }
259
+ return [{ start: score.offset, length: q.length }];
260
+ }
261
+ export function compareMatchScores(a, b) {
262
+ if (a.tier !== b.tier)
263
+ return a.tier - b.tier;
264
+ if (a.offset !== b.offset)
265
+ return a.offset - b.offset;
266
+ return (a.spread ?? 0) - (b.spread ?? 0);
267
+ }
268
+ export function tokenizeQuery(query) {
269
+ return query
270
+ .trim()
271
+ .toLowerCase()
272
+ .split(/\s+/)
273
+ .filter((token) => token.length > 0);
274
+ }
275
+ /** Each token's best score across the fields, or null when some token matches none. */
276
+ function scoreTokens(query, fields, options) {
277
+ const scores = [];
278
+ for (const token of tokenizeQuery(query)) {
279
+ const fuzzy = options.typoTolerant ? fuzzyPolicyForToken(token) : null;
280
+ let best = null;
281
+ for (const field of fields) {
282
+ const score = scoreMatch(token, field, { fuzzy, subsequence: options.subsequence });
283
+ if (score && (!best || compareMatchScores(score, best) < 0)) {
284
+ best = score;
285
+ }
286
+ }
287
+ if (!best)
288
+ return null;
289
+ scores.push({ token, score: best });
290
+ }
291
+ return scores;
292
+ }
293
+ export function scoreTextFields(query, fields, options = {}) {
294
+ const scores = scoreTokens(query, fields, options);
295
+ if (!scores)
296
+ return null;
297
+ const aggregate = { tier: TIER_EXACT, offset: 0, spread: 0 };
298
+ for (const { token, score } of scores) {
299
+ aggregate.tier += score.tier;
300
+ aggregate.offset += score.offset;
301
+ aggregate.spread = (aggregate.spread ?? 0) + (score.spread ?? token.length);
302
+ }
303
+ return aggregate;
304
+ }
305
+ const MATCH_CLASS_ORDER = ["word", "inside-word", "scattered"];
306
+ function matchClassOfTier(tier) {
307
+ if (tier <= TIER_WORD_START)
308
+ return "word";
309
+ if (tier === TIER_SUBSTRING)
310
+ return "inside-word";
311
+ return "scattered";
312
+ }
313
+ /** Closer classes first. */
314
+ export function compareMatchClasses(a, b) {
315
+ return MATCH_CLASS_ORDER.indexOf(a) - MATCH_CLASS_ORDER.indexOf(b);
316
+ }
317
+ /** The class of the query's loosest token, or null when some token matches no field. */
318
+ export function textFieldsMatchClass(query, fields, options = {}) {
319
+ const scores = scoreTokens(query, fields, options);
320
+ if (!scores)
321
+ return null;
322
+ let loosest = "word";
323
+ for (const { score } of scores) {
324
+ const tokenClass = matchClassOfTier(score.tier);
325
+ if (compareMatchClasses(tokenClass, loosest) > 0)
326
+ loosest = tokenClass;
327
+ }
328
+ return loosest;
329
+ }
330
+ //# sourceMappingURL=text-match.js.map
@@ -0,0 +1,3 @@
1
+ export declare const DEFAULT_RELAY_ENDPOINT = "relay.ssh3.com:443";
2
+ export declare const DEFAULT_APP_BASE_URL = "https://mateo.ssh3.com";
3
+ //# sourceMappingURL=service-defaults.d.ts.map
@@ -0,0 +1,5 @@
1
+ // Mateo-owned service defaults, shared by packaged daemon, pairing and CLI guidance.
2
+ // Per-host config.json and launch environment overrides remain authoritative.
3
+ export const DEFAULT_RELAY_ENDPOINT = "relay.ssh3.com:443";
4
+ export const DEFAULT_APP_BASE_URL = "https://mateo.ssh3.com";
5
+ //# sourceMappingURL=service-defaults.js.map
@@ -0,0 +1,11 @@
1
+ export declare const DEFAULT_SSH_DAEMON_PORT = 8686;
2
+ export interface SshTransportTarget {
3
+ host: string;
4
+ sshPort?: number;
5
+ daemonPort: number;
6
+ }
7
+ export declare function validatePort(value: string | number, label: string): number;
8
+ export declare function validateSshHost(host: string): string;
9
+ export declare function parseSshTransportUri(value: string): SshTransportTarget;
10
+ export declare function buildSshTunnelArgs(target: SshTransportTarget): string[];
11
+ //# sourceMappingURL=ssh-transport.d.ts.map
@@ -0,0 +1,72 @@
1
+ export const DEFAULT_SSH_DAEMON_PORT = 8686;
2
+ export function validatePort(value, label) {
3
+ const port = Number(value);
4
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
5
+ throw new Error(`${label} must be between 1 and 65535`);
6
+ }
7
+ return port;
8
+ }
9
+ export function validateSshHost(host) {
10
+ const normalized = host.trim();
11
+ if (!normalized)
12
+ throw new Error("SSH host is required");
13
+ if (/\s/u.test(normalized) || normalized.startsWith("-")) {
14
+ throw new Error("SSH host is invalid");
15
+ }
16
+ return normalized;
17
+ }
18
+ export function parseSshTransportUri(value) {
19
+ let url;
20
+ try {
21
+ url = new URL(value);
22
+ }
23
+ catch (error) {
24
+ throw new Error("Invalid SSH host URI", { cause: error });
25
+ }
26
+ if (url.protocol !== "ssh:" || url.password || (url.pathname !== "" && url.pathname !== "/")) {
27
+ throw new Error("Invalid SSH host URI");
28
+ }
29
+ if (url.hash)
30
+ throw new Error("SSH host URI does not support fragments");
31
+ for (const key of url.searchParams.keys()) {
32
+ if (key !== "daemonPort")
33
+ throw new Error(`Unsupported SSH host option: ${key}`);
34
+ }
35
+ const daemonPorts = url.searchParams.getAll("daemonPort");
36
+ if (daemonPorts.length > 1)
37
+ throw new Error("daemonPort may only be specified once");
38
+ const urlHostname = url.hostname;
39
+ const hostname = validateSshHost(urlHostname.startsWith("[") && urlHostname.endsWith("]")
40
+ ? urlHostname.slice(1, -1)
41
+ : urlHostname);
42
+ const username = decodeURIComponent(url.username);
43
+ const host = validateSshHost(username ? `${username}@${hostname}` : hostname);
44
+ return {
45
+ host,
46
+ ...(url.port ? { sshPort: validatePort(url.port, "SSH port") } : {}),
47
+ daemonPort: daemonPorts[0] === undefined
48
+ ? DEFAULT_SSH_DAEMON_PORT
49
+ : validatePort(daemonPorts[0], "Daemon port"),
50
+ };
51
+ }
52
+ export function buildSshTunnelArgs(target) {
53
+ const host = validateSshHost(target.host);
54
+ const daemonPort = validatePort(target.daemonPort, "Daemon port");
55
+ const args = [
56
+ "-T",
57
+ "-o",
58
+ "BatchMode=yes",
59
+ "-o",
60
+ "ConnectTimeout=10",
61
+ "-o",
62
+ "ClearAllForwardings=yes",
63
+ "-o",
64
+ "ExitOnForwardFailure=yes",
65
+ ];
66
+ if (target.sshPort !== undefined) {
67
+ args.push("-p", String(validatePort(target.sshPort, "SSH port")));
68
+ }
69
+ args.push("-W", `127.0.0.1:${daemonPort}`, host);
70
+ return args;
71
+ }
72
+ //# sourceMappingURL=ssh-transport.js.map
@@ -0,0 +1,21 @@
1
+ import { z } from "zod";
2
+ export declare const TERMINAL_ACTIVITY_STATES: readonly ["idle", "working", "attention"];
3
+ export declare const TERMINAL_ACTIVITY_ATTENTION_REASONS: readonly ["finished", "needs_input"];
4
+ export type TerminalActivityState = (typeof TERMINAL_ACTIVITY_STATES)[number];
5
+ export type TerminalActivityAttentionReason = (typeof TERMINAL_ACTIVITY_ATTENTION_REASONS)[number];
6
+ export declare const TerminalActivitySchema: z.ZodObject<{
7
+ state: z.ZodCatch<z.ZodEnum<{
8
+ idle: "idle";
9
+ working: "working";
10
+ attention: "attention";
11
+ }>>;
12
+ attentionReason: z.ZodCatch<z.ZodOptional<z.ZodNullable<z.ZodEnum<{
13
+ finished: "finished";
14
+ needs_input: "needs_input";
15
+ }>>>>;
16
+ changedAt: z.ZodNumber;
17
+ }, z.core.$strip>;
18
+ export type TerminalActivity = z.infer<typeof TerminalActivitySchema>;
19
+ export type TerminalActivityStatusBucket = "running" | "needs_input" | "attention";
20
+ export declare function deriveTerminalActivityStatusBucket(activity: TerminalActivity | null | undefined): TerminalActivityStatusBucket | null;
21
+ //# sourceMappingURL=terminal-activity.d.ts.map
@@ -0,0 +1,25 @@
1
+ import { z } from "zod";
2
+ export const TERMINAL_ACTIVITY_STATES = ["idle", "working", "attention"];
3
+ export const TERMINAL_ACTIVITY_ATTENTION_REASONS = ["finished", "needs_input"];
4
+ export const TerminalActivitySchema = z.object({
5
+ // Forward-compat: a newer daemon may send a state this client doesn't know.
6
+ // Degrade unknown states to "idle" (no indicator, no notification) so the
7
+ // message still parses, instead of a strict enum rejecting the whole payload.
8
+ state: z.enum(TERMINAL_ACTIVITY_STATES).catch("idle"),
9
+ attentionReason: z.enum(TERMINAL_ACTIVITY_ATTENTION_REASONS).nullable().optional().catch(null),
10
+ changedAt: z.number(),
11
+ });
12
+ export function deriveTerminalActivityStatusBucket(activity) {
13
+ if (!activity)
14
+ return null;
15
+ if (activity.attentionReason === "needs_input")
16
+ return "needs_input";
17
+ if (activity.attentionReason === "finished")
18
+ return "attention";
19
+ if (activity.state === "working")
20
+ return "running";
21
+ if (activity.state === "attention")
22
+ return "needs_input";
23
+ return null;
24
+ }
25
+ //# sourceMappingURL=terminal-activity.js.map
@@ -0,0 +1,30 @@
1
+ export interface TerminalInputModeFeedResult {
2
+ changed: boolean;
3
+ responses: string[];
4
+ }
5
+ export interface TerminalInputModeState {
6
+ kittyKeyboardFlags: number;
7
+ win32InputMode: boolean;
8
+ applicationCursorKeys?: boolean;
9
+ bracketedPaste?: boolean;
10
+ }
11
+ export declare const DEFAULT_TERMINAL_INPUT_MODE_STATE: TerminalInputModeState;
12
+ export declare function terminalInputModeSupportsModifiedEnter(state: TerminalInputModeState): boolean;
13
+ export declare function terminalInputModeStatesEqual(left: TerminalInputModeState, right: TerminalInputModeState): boolean;
14
+ export declare class TerminalInputModeTracker {
15
+ private kittyKeyboardFlags;
16
+ private win32InputMode;
17
+ private applicationCursorKeys;
18
+ private bracketedPaste;
19
+ private readonly kittyKeyboardStack;
20
+ private pending;
21
+ feed(data: string): TerminalInputModeFeedResult;
22
+ reset(): void;
23
+ getState(): TerminalInputModeState;
24
+ getKittyKeyboardFlags(): number;
25
+ supportsModifiedEnter(): boolean;
26
+ getPreamble(): string;
27
+ private applyKittyKeyboardSequence;
28
+ private applyPrivateModeSequence;
29
+ }
30
+ //# sourceMappingURL=terminal-input-mode.d.ts.map
@@ -0,0 +1,180 @@
1
+ export const DEFAULT_TERMINAL_INPUT_MODE_STATE = {
2
+ kittyKeyboardFlags: 0,
3
+ win32InputMode: false,
4
+ applicationCursorKeys: false,
5
+ bracketedPaste: false,
6
+ };
7
+ const ESC = String.fromCharCode(0x1b);
8
+ const APPLICATION_CURSOR_KEYS_MODE = 1;
9
+ const WIN32_INPUT_MODE = 9001;
10
+ const BRACKETED_PASTE_MODE = 2004;
11
+ const CSI_INPUT_MODE_SEQUENCE = new RegExp(`${ESC}\\[(?:([<>=?]?)([0-9;]*)u|\\?([0-9;]*)([hl]))`, "g");
12
+ const INCOMPLETE_CSI_INPUT_MODE_SEQUENCE = new RegExp(`${ESC}\\[[<>=?]?[0-9;]*$`);
13
+ function parseFirstParam(params) {
14
+ const first = params.split(";")[0];
15
+ if (!first || !/^\d+$/.test(first)) {
16
+ return null;
17
+ }
18
+ return Number(first);
19
+ }
20
+ function parseSecondParam(params) {
21
+ const second = params.split(";")[1];
22
+ if (!second || !/^\d+$/.test(second)) {
23
+ return null;
24
+ }
25
+ return Number(second);
26
+ }
27
+ function parsePrivateModeParams(params) {
28
+ const modes = new Set();
29
+ for (const param of params.split(";")) {
30
+ if (/^\d+$/.test(param)) {
31
+ modes.add(Number(param));
32
+ }
33
+ }
34
+ return modes;
35
+ }
36
+ export function terminalInputModeSupportsModifiedEnter(state) {
37
+ return state.kittyKeyboardFlags > 0 || state.win32InputMode;
38
+ }
39
+ export function terminalInputModeStatesEqual(left, right) {
40
+ return (left.kittyKeyboardFlags === right.kittyKeyboardFlags &&
41
+ left.win32InputMode === right.win32InputMode &&
42
+ Boolean(left.applicationCursorKeys) === Boolean(right.applicationCursorKeys) &&
43
+ Boolean(left.bracketedPaste) === Boolean(right.bracketedPaste));
44
+ }
45
+ export class TerminalInputModeTracker {
46
+ constructor() {
47
+ this.kittyKeyboardFlags = 0;
48
+ this.win32InputMode = false;
49
+ this.applicationCursorKeys = false;
50
+ this.bracketedPaste = false;
51
+ this.kittyKeyboardStack = [];
52
+ this.pending = "";
53
+ }
54
+ feed(data) {
55
+ if (data.length === 0) {
56
+ return { changed: false, responses: [] };
57
+ }
58
+ const text = `${this.pending}${data}`;
59
+ this.pending = "";
60
+ let changed = false;
61
+ const responses = [];
62
+ let consumedUntil = 0;
63
+ CSI_INPUT_MODE_SEQUENCE.lastIndex = 0;
64
+ for (;;) {
65
+ const match = CSI_INPUT_MODE_SEQUENCE.exec(text);
66
+ if (!match) {
67
+ break;
68
+ }
69
+ consumedUntil = CSI_INPUT_MODE_SEQUENCE.lastIndex;
70
+ if (match[4]) {
71
+ changed = this.applyPrivateModeSequence(match[3] ?? "", match[4]) || changed;
72
+ continue;
73
+ }
74
+ const result = this.applyKittyKeyboardSequence(match[1] ?? "", match[2] ?? "");
75
+ changed = changed || result.changed;
76
+ responses.push(...result.responses);
77
+ }
78
+ const tail = text.slice(consumedUntil);
79
+ const pendingStart = tail.lastIndexOf(`${ESC}[`);
80
+ if (pendingStart >= 0) {
81
+ const pending = tail.slice(pendingStart);
82
+ if (INCOMPLETE_CSI_INPUT_MODE_SEQUENCE.test(pending)) {
83
+ this.pending = pending;
84
+ }
85
+ }
86
+ return { changed, responses };
87
+ }
88
+ reset() {
89
+ this.kittyKeyboardFlags = 0;
90
+ this.win32InputMode = false;
91
+ this.applicationCursorKeys = false;
92
+ this.bracketedPaste = false;
93
+ this.kittyKeyboardStack.length = 0;
94
+ this.pending = "";
95
+ }
96
+ getState() {
97
+ return {
98
+ kittyKeyboardFlags: this.kittyKeyboardFlags,
99
+ win32InputMode: this.win32InputMode,
100
+ applicationCursorKeys: this.applicationCursorKeys,
101
+ bracketedPaste: this.bracketedPaste,
102
+ };
103
+ }
104
+ getKittyKeyboardFlags() {
105
+ return this.kittyKeyboardFlags;
106
+ }
107
+ supportsModifiedEnter() {
108
+ return terminalInputModeSupportsModifiedEnter(this.getState());
109
+ }
110
+ getPreamble() {
111
+ const parts = [];
112
+ if (this.kittyKeyboardFlags > 0) {
113
+ parts.push(`\x1b[=${this.kittyKeyboardFlags};1u`);
114
+ }
115
+ if (this.win32InputMode) {
116
+ parts.push("\x1b[?9001h");
117
+ }
118
+ if (this.applicationCursorKeys) {
119
+ parts.push("\x1b[?1h");
120
+ }
121
+ if (this.bracketedPaste) {
122
+ parts.push("\x1b[?2004h");
123
+ }
124
+ return parts.join("");
125
+ }
126
+ applyKittyKeyboardSequence(prefix, params) {
127
+ const previousFlags = this.kittyKeyboardFlags;
128
+ switch (prefix) {
129
+ case ">": {
130
+ this.kittyKeyboardStack.push(this.kittyKeyboardFlags);
131
+ this.kittyKeyboardFlags = parseFirstParam(params) ?? 1;
132
+ break;
133
+ }
134
+ case "=": {
135
+ const mode = parseSecondParam(params) ?? 1;
136
+ this.kittyKeyboardFlags = mode === 0 ? 0 : (parseFirstParam(params) ?? 0);
137
+ break;
138
+ }
139
+ case "<": {
140
+ const count = Math.max(1, parseFirstParam(params) ?? 1);
141
+ for (let index = 0; index < count; index += 1) {
142
+ this.kittyKeyboardFlags = this.kittyKeyboardStack.pop() ?? 0;
143
+ }
144
+ break;
145
+ }
146
+ case "?":
147
+ return {
148
+ changed: false,
149
+ responses: [`\x1b[?${this.kittyKeyboardFlags}u`],
150
+ };
151
+ default:
152
+ return { changed: false, responses: [] };
153
+ }
154
+ return {
155
+ changed: this.kittyKeyboardFlags !== previousFlags,
156
+ responses: [],
157
+ };
158
+ }
159
+ applyPrivateModeSequence(params, final) {
160
+ const modes = parsePrivateModeParams(params);
161
+ let changed = false;
162
+ if (modes.has(WIN32_INPUT_MODE)) {
163
+ const previous = this.win32InputMode;
164
+ this.win32InputMode = final === "h";
165
+ changed = this.win32InputMode !== previous || changed;
166
+ }
167
+ if (modes.has(APPLICATION_CURSOR_KEYS_MODE)) {
168
+ const previous = this.applicationCursorKeys;
169
+ this.applicationCursorKeys = final === "h";
170
+ changed = this.applicationCursorKeys !== previous || changed;
171
+ }
172
+ if (modes.has(BRACKETED_PASTE_MODE)) {
173
+ const previous = this.bracketedPaste;
174
+ this.bracketedPaste = final === "h";
175
+ changed = this.bracketedPaste !== previous || changed;
176
+ }
177
+ return changed;
178
+ }
179
+ }
180
+ //# sourceMappingURL=terminal-input-mode.js.map