@mossbear/protocol 0.1.0-alpha.114 → 0.1.0-alpha.116

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 (73) hide show
  1. package/dist/bundles.d.ts +662 -0
  2. package/dist/bundles.d.ts.map +1 -0
  3. package/dist/bundles.js +454 -0
  4. package/dist/bundles.js.map +1 -0
  5. package/dist/bundles.test.d.ts +2 -0
  6. package/dist/bundles.test.d.ts.map +1 -0
  7. package/dist/bundles.test.js +61 -0
  8. package/dist/bundles.test.js.map +1 -0
  9. package/dist/comments.d.ts +1405 -0
  10. package/dist/comments.d.ts.map +1 -0
  11. package/dist/comments.js +683 -0
  12. package/dist/comments.js.map +1 -0
  13. package/dist/comments.test.d.ts +2 -0
  14. package/dist/comments.test.d.ts.map +1 -0
  15. package/dist/comments.test.js +64 -0
  16. package/dist/comments.test.js.map +1 -0
  17. package/dist/guideHistory.d.ts +643 -0
  18. package/dist/guideHistory.d.ts.map +1 -0
  19. package/dist/guideHistory.js +343 -0
  20. package/dist/guideHistory.js.map +1 -0
  21. package/dist/guideHistory.test.d.ts +2 -0
  22. package/dist/guideHistory.test.d.ts.map +1 -0
  23. package/dist/guideHistory.test.js +35 -0
  24. package/dist/guideHistory.test.js.map +1 -0
  25. package/dist/guideImport.d.ts +398 -0
  26. package/dist/guideImport.d.ts.map +1 -0
  27. package/dist/guideImport.js +350 -0
  28. package/dist/guideImport.js.map +1 -0
  29. package/dist/guideImport.test.d.ts +2 -0
  30. package/dist/guideImport.test.d.ts.map +1 -0
  31. package/dist/guideImport.test.js +62 -0
  32. package/dist/guideImport.test.js.map +1 -0
  33. package/dist/guideSnapshot.d.ts +105 -0
  34. package/dist/guideSnapshot.d.ts.map +1 -0
  35. package/dist/guideSnapshot.js +101 -0
  36. package/dist/guideSnapshot.js.map +1 -0
  37. package/dist/guideSnapshot.test.d.ts +2 -0
  38. package/dist/guideSnapshot.test.d.ts.map +1 -0
  39. package/dist/guideSnapshot.test.js +49 -0
  40. package/dist/guideSnapshot.test.js.map +1 -0
  41. package/dist/schemas.d.ts +5122 -11710
  42. package/dist/schemas.d.ts.map +1 -1
  43. package/dist/schemas.js +61 -2816
  44. package/dist/schemas.js.map +1 -1
  45. package/dist/search.d.ts +1222 -0
  46. package/dist/search.d.ts.map +1 -0
  47. package/dist/search.js +474 -0
  48. package/dist/search.js.map +1 -0
  49. package/dist/search.test.d.ts +2 -0
  50. package/dist/search.test.d.ts.map +1 -0
  51. package/dist/search.test.js +64 -0
  52. package/dist/search.test.js.map +1 -0
  53. package/dist/sessionContracts.test.d.ts +2 -0
  54. package/dist/sessionContracts.test.d.ts.map +1 -0
  55. package/dist/sessionContracts.test.js +75 -0
  56. package/dist/sessionContracts.test.js.map +1 -0
  57. package/dist/sessionDigest.d.ts +149 -0
  58. package/dist/sessionDigest.d.ts.map +1 -0
  59. package/dist/sessionDigest.js +57 -0
  60. package/dist/sessionDigest.js.map +1 -0
  61. package/dist/sessionGrade.d.ts +184 -0
  62. package/dist/sessionGrade.d.ts.map +1 -0
  63. package/dist/sessionGrade.js +130 -0
  64. package/dist/sessionGrade.js.map +1 -0
  65. package/dist/types.d.ts +4 -27
  66. package/dist/types.d.ts.map +1 -1
  67. package/dist/types.js.map +1 -1
  68. package/dist/usageOnly.d.ts +5 -5
  69. package/dist/wirePrimitives.d.ts +173 -0
  70. package/dist/wirePrimitives.d.ts.map +1 -0
  71. package/dist/wirePrimitives.js +210 -0
  72. package/dist/wirePrimitives.js.map +1 -0
  73. package/package.json +1 -1
@@ -0,0 +1,683 @@
1
+ /** Comment reads, findings, evidence and agent writes. Depends only on shared wire primitives. */
2
+ import * as v from 'valibot';
3
+ import { NonEmptyStringSchema, CommentAuthorKindSchema, GuideHistoryUntrustedSchema, HarnessIdSchema, RepositoryNameSchema, ProjectIdSchema, MAX_ARTIFACT_FEEDBACK_BATCH, } from './wirePrimitives.js';
4
+ /**
5
+ * How many open comments one item carries on the wire, newest first.
6
+ *
7
+ * A wire bound, not a product limit: the write side refuses the comment that
8
+ * would exceed it *by name* (see the dashboard's note mutator), so this cap is
9
+ * never the thing that silently drops a comment a person left.
10
+ */
11
+ export const MAX_ITEM_COMMENTS_ON_WIRE = 20;
12
+ /**
13
+ * How many replies one delivered thread carries, the newest kept. A thread past
14
+ * it says how many it held back (`repliesWithheld`), so a cut is never silent.
15
+ */
16
+ export const MAX_REPLIES_PER_THREAD_ON_WIRE = 10;
17
+ /**
18
+ * The most entries one item's `comments` can hold once threads ride it: a
19
+ * person's allowance of roots plus an agent's own, each followed by its replies.
20
+ * A client that does not render threads is sent roots alone, which stay within
21
+ * `MAX_ITEM_COMMENTS_ON_WIRE`.
22
+ */
23
+ export const MAX_ITEM_THREAD_ENTRIES_ON_WIRE = 2 * MAX_ITEM_COMMENTS_ON_WIRE * (1 + MAX_REPLIES_PER_THREAD_ON_WIRE);
24
+ /** What a finding rests on: graded sessions, how loads read a skill, or the rubric alone. */
25
+ export const FindingTierSchema = v.picklist(['observed', 'usage', 'practice']);
26
+ /**
27
+ * What a Mossbear finding carries on the comment read, besides its claim.
28
+ *
29
+ * `tierLine` and `blindSpot` are written by the server from data it holds —
30
+ * the cited sessions, the load counts, the rubric check — never by a model, so
31
+ * they sit outside the response's untrusted markers. `prediction` is
32
+ * model-authored and arrives inside them. A finding never carries replacement
33
+ * text: the reader's agent has the repository and writes the fix.
34
+ */
35
+ export const CommentFindingSchema = v.object({
36
+ tier: FindingTierSchema,
37
+ /** How the finding is known, in one line: "Seen in 3 sessions (2026-09-15 – 2026-10-03)". */
38
+ tierLine: v.pipe(v.string(), v.maxLength(300)),
39
+ /** What the drafter did not read, fixed per tier. */
40
+ blindSpot: v.pipe(v.string(), v.maxLength(300)),
41
+ /** What should change in later sessions if the finding is fixed, wrapped in the untrusted markers. */
42
+ prediction: v.nullable(v.string()),
43
+ });
44
+ /** Whether an open Mossbear finding is the agent's to act on (`ArtifactComment.findingState`). */
45
+ export const CommentFindingStateSchema = v.picklist(['ready', 'waiting']);
46
+ /** Where a commented artifact is published from (`ArtifactComment.publishedFrom`). */
47
+ export const CommentPublishedFromSchema = v.object({
48
+ repository: v.optional(RepositoryNameSchema),
49
+ projectId: NonEmptyStringSchema,
50
+ branch: v.nullable(v.pipe(v.string(), v.maxLength(255))),
51
+ thisRepo: v.optional(v.boolean()),
52
+ });
53
+ /**
54
+ * One comment a **person** left about a context item, riding the item it is about.
55
+ *
56
+ * A comment is not an item: it is not a member, not projected, not versioned and
57
+ * not capturable. It travels on the item so that it inherits every delivery
58
+ * decision the item already went through — workspace scope, the archived drop,
59
+ * the response limit, the subscriber's mute — rather than restating them.
60
+ *
61
+ * **Every `body` here is already wrapped in the response's untrusted markers**
62
+ * (`ContextItemsResponseSchema.untrusted`). A reader emits the bytes as it
63
+ * received them and never re-wraps them: the markers are derived against the
64
+ * bodies the server sent, so a second wrapping cannot claim the same guarantee.
65
+ */
66
+ export const ArtifactCommentSchema = v.object({
67
+ id: NonEmptyStringSchema,
68
+ state: v.optional(v.picklist(['open', 'resolved'])),
69
+ /** Current source location of an anchored passage, or its lost quote. */
70
+ passage: v.optional(v.object({
71
+ quote: v.string(),
72
+ status: v.picklist(['located', 'changed', 'orphaned']),
73
+ lines: v.nullable(v.object({ start: v.number(), end: v.number() })),
74
+ /**
75
+ * Where the passage sits in an `html` page as the reader saw it: a CSS
76
+ * selector, the tag, and the nearest `aria-label` or heading. Sent when
77
+ * the passage has no source lines, so an agent can find a block the
78
+ * page's script built.
79
+ */
80
+ element: v.optional(v.object({
81
+ selector: v.string(),
82
+ tag: v.string(),
83
+ label: v.optional(v.string()),
84
+ })),
85
+ })),
86
+ /** The comment's text, already wrapped in the response's untrusted markers. */
87
+ body: v.string(),
88
+ /**
89
+ * What a comment Mossbear wrote is: a finding about the item, never an edit.
90
+ * Present only on a Mossbear comment. The comment's `body` begins with the
91
+ * claim (what goes wrong); this carries what the claim rests on.
92
+ */
93
+ finding: v.optional(CommentFindingSchema),
94
+ /**
95
+ * Whether the person handed a comment Mossbear drafted to their agent. Nothing
96
+ * hands one over any more, so a current server sends `false` on every Mossbear
97
+ * comment and omits it on a person's or an agent's; the field stays for
98
+ * readers that predate `findingState`. It does not say whether the agent may
99
+ * act: read `findingState` for that, and fall back to `approved: false`
100
+ * meaning "not yet accepted" only when `findingState` is absent, from a server
101
+ * that predates it. Only a client that reports a version able to mark drafts
102
+ * is listed a finding at all, so an older reader that strips this field never
103
+ * receives one it would misread.
104
+ */
105
+ approved: v.optional(v.boolean()),
106
+ /**
107
+ * Whether an open Mossbear finding is the agent's to act on. A current server
108
+ * sends `ready` on every open finding: it is the agent's unless the person
109
+ * dismisses it, and a dismissed finding is resolved. `waiting`, sent only by
110
+ * an older server, means it waits on the person: show it to the user and
111
+ * change nothing unless they say so. Present only on an open Mossbear
112
+ * comment. A server that predates the field omits it, and a reader then
113
+ * falls back to `approved`. This is a new name rather than a new meaning for
114
+ * `state`, which already says open or resolved.
115
+ */
116
+ findingState: v.optional(CommentFindingStateSchema),
117
+ /**
118
+ * Where the artifact is published from, when Mossbear records one: the
119
+ * committed `project.id` of the repository whose commits own it, and the
120
+ * branch it was published from (null when none was recorded). `thisRepo` is
121
+ * true when that is the repo the read declared, false when it is another repo,
122
+ * and absent when the read declared no repo. The field is absent when Mossbear
123
+ * records no publishing repo, which is not a claim that the artifact is
124
+ * Mossbear-owned.
125
+ */
126
+ publishedFrom: v.optional(CommentPublishedFromSchema),
127
+ /** The author's display name as the workspace shows it, or null. Never an email. */
128
+ authorName: v.nullable(v.string()),
129
+ /**
130
+ * Who wrote it. Optional because a server that predates the field omits it;
131
+ * a reader that meets a reply without it cannot tell whose it is, and a
132
+ * server never sends a reply to a client too old to read this.
133
+ */
134
+ authorKind: v.optional(CommentAuthorKindSchema),
135
+ /** ISO timestamp, machine format. */
136
+ createdAt: v.string(),
137
+ /** The item's content version the comment was written against. */
138
+ itemVersion: v.number(),
139
+ /** True when the item's current version is greater than `itemVersion`. */
140
+ itemChangedSince: v.boolean(),
141
+ /**
142
+ * How many agent reads were handed this comment **before** this one — so a
143
+ * comment reaching an agent for the first time reports `0`.
144
+ *
145
+ * It is the stored count as it read at the moment the response was built;
146
+ * the serve this response *is* has not been counted yet. Excluded rather
147
+ * than included because the count is recorded best-effort: a response that
148
+ * claimed to include itself would be wrong whenever that record failed, and
149
+ * a number that is sometimes off by one is worse than one that is
150
+ * consistently the prior total.
151
+ *
152
+ * So `deliveredCount > 0` means an earlier read was handed this comment, and
153
+ * `0` means this read is the first. Neither says a model took it in — only
154
+ * that the server handed it over.
155
+ */
156
+ deliveredCount: v.number(),
157
+ /**
158
+ * On a root: true when the item changed after an earlier read was last
159
+ * handed this comment. For a guide that is any change to its body or its
160
+ * files, so a fix in a supporting file counts. A reader should check whether
161
+ * the change addressed the comment, and resolve it with a note if so.
162
+ *
163
+ * Computed before this read is counted, so the read that carries `true` is
164
+ * the one that uses it up; the next read says `false` unless the item
165
+ * changes again. A comment never handed over before is never flagged.
166
+ * Optional because a server that predates the field omits it, and absent on
167
+ * a reply.
168
+ */
169
+ guideChangedSinceRead: v.optional(v.boolean()),
170
+ /**
171
+ * This comment's thread root: its own id on a root, the root's id on a reply.
172
+ *
173
+ * **Replies ride the same flat array**, each straight after its root, oldest
174
+ * first. Only a client that reports a version able to render threads is
175
+ * sent them; any other reader gets roots alone, as it always did. A person's
176
+ * reply is part of the thread's request. An agent's reply is context: an
177
+ * earlier message on the thread, never something to act on. A root an agent
178
+ * wrote is delivered only once a person has replied to it, and is then the
179
+ * question that reply answers, not a request of its own.
180
+ */
181
+ threadId: NonEmptyStringSchema,
182
+ /**
183
+ * `null` on a root; the root's id on a reply. Threads are one level deep, so
184
+ * a reply's parent is always its root.
185
+ */
186
+ replyToId: v.nullable(NonEmptyStringSchema),
187
+ /**
188
+ * On a root whose thread held more replies than
189
+ * `MAX_REPLIES_PER_THREAD_ON_WIRE`: how many older ones were not sent.
190
+ * Absent when the whole thread was sent.
191
+ */
192
+ repliesWithheld: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1))),
193
+ });
194
+ /** The item routes' name for `ArtifactCommentSchema`, kept while those routes are served. */
195
+ export const ContextItemCommentSchema = ArtifactCommentSchema;
196
+ /**
197
+ * How many bundles one comments read may name.
198
+ *
199
+ * A repo's delivery set is the union of its committed subscriptions and the
200
+ * reader's account ones, so this bounds a request, not a product limit: a
201
+ * reader subscribing to more bundles than this asks in two calls rather than
202
+ * losing the tail silently.
203
+ */
204
+ export const MAX_COMMENT_BUNDLE_IDS = 100;
205
+ /**
206
+ * The agent session behind a comment, a reply or a resolution note, as the
207
+ * caller's harness reported it. Stored on the row so the reply is named after
208
+ * that session; it is the caller's claim, read only among its own comments.
209
+ */
210
+ export const AgentIdentitySchema = v.object({
211
+ sessionId: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(128)),
212
+ harness: HarnessIdSchema,
213
+ /** The agent's own statement of its model, when it knows it. */
214
+ model: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(100))),
215
+ cliVersion: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(64))),
216
+ });
217
+ /**
218
+ * `POST /api/v1/context/comments/resolve`: close one open comment and leave the
219
+ * agent's note as a reply in its thread.
220
+ *
221
+ * **Two ways to find the comment, never both at once.** Without `artifactId`,
222
+ * the id is looked up among the comments the named bundles deliver, which is
223
+ * what `list_comments` listed. With it, the id is looked up among that one
224
+ * artifact's open comments, which is what its feedback read listed, after the
225
+ * same read check that read makes. A request with `artifactId` does not fall
226
+ * back to the bundles when the id is not on that artifact.
227
+ */
228
+ export const ResolveItemCommentRequestSchema = v.object({
229
+ /** The comment's id, or a unique prefix of it as a read printed it. */
230
+ id: v.pipe(v.string(), v.minLength(1), v.maxLength(128)),
231
+ /** One line, kept in the thread as the agent's reply. */
232
+ note: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(500), v.regex(/^[^\r\n]+$/)),
233
+ /** The bundles this repo receives. Ignored when `artifactId` is sent. */
234
+ bundleIds: v.optional(v.pipe(v.array(NonEmptyStringSchema), v.maxLength(MAX_COMMENT_BUNDLE_IDS)), []),
235
+ /** The artifact the comment is on, as its feedback read was asked for it. */
236
+ artifactId: v.optional(v.pipe(v.string(), v.minLength(1), v.maxLength(128))),
237
+ /**
238
+ * The reader's repo, as its committed `project.id`. A comment drafted from
239
+ * one repo's corrections is listed only to a read that declares that repo,
240
+ * so it is resolvable only by one that declares it too.
241
+ */
242
+ projectId: v.optional(ProjectIdSchema),
243
+ /** The CLI's version, so a draft resolves only for a client that marks drafts. */
244
+ cliVersion: v.optional(v.pipe(v.string(), v.maxLength(64))),
245
+ /**
246
+ * The agent session resolving it, stored on the note so the thread names
247
+ * who closed it. Optional: releases before it was sent resolve without one,
248
+ * and their notes read as an unnamed agent.
249
+ */
250
+ agent: v.optional(AgentIdentitySchema),
251
+ });
252
+ /** A resolve the server carried out. Every refusal is an error response instead. */
253
+ export const ResolveItemCommentResponseSchema = v.object({
254
+ resolved: v.literal(true),
255
+ });
256
+ /**
257
+ * How many times one subscriber is told, in one repo, that a given comment is
258
+ * waiting before the hook falls silent about it.
259
+ *
260
+ * **A cap on the interruption, never on the comment.** After it is reached the
261
+ * comment is still open, still on the item page, and still returned in full by
262
+ * the on-demand read — it simply stops being announced in front of the first
263
+ * turn of every session. So silence here means "nothing new to interrupt you
264
+ * about", never "nobody left anything".
265
+ *
266
+ * Three rather than one, for the reason the announcement exists: the first
267
+ * session in a repo is often doing unrelated work, so a one-shot announcement
268
+ * would routinely spend itself on the session least likely to act. Three is a
269
+ * judgement, named so replacing it is one edit — the same discipline the live
270
+ * session window is held to.
271
+ */
272
+ export const MAX_COMMENT_ANNOUNCEMENTS_PER_REPO = 3;
273
+ /**
274
+ * Ask which comments are waiting for this reader in this repo, and be counted as
275
+ * told.
276
+ *
277
+ * **A write, because being told is a fact the server has to keep.** The count
278
+ * cannot be `item_comments.delivered_count` — that is one global number across
279
+ * every subscriber and every repo, so one reader's fill of a comment would
280
+ * silence it for everyone — and it cannot live in the checkout, because the
281
+ * disposable environments this exists for rebuild the clone every session and
282
+ * a counter there resets with it, announcing every unresolved comment as new
283
+ * forever.
284
+ */
285
+ export const AnnounceItemCommentsRequestSchema = v.object({
286
+ /**
287
+ * The repo, as its committed config declares it. Required: it is the scope
288
+ * the count is kept under, and a request with nothing to key on could only
289
+ * be answered by an uncapped announcement — which is the repeating broadcast
290
+ * this route exists to end.
291
+ */
292
+ projectId: ProjectIdSchema,
293
+ /**
294
+ * The bundles this repo receives — the union the caller already resolved.
295
+ *
296
+ * Sent rather than derived, because only half of it is the server's to know:
297
+ * a repo-scoped subscription lives in the committed config and travels by
298
+ * `git clone`. Declaring a bundle grants nothing: every one of them is still
299
+ * filtered by the caller's own workspace membership.
300
+ */
301
+ bundleIds: v.pipe(v.array(NonEmptyStringSchema), v.maxLength(MAX_COMMENT_BUNDLE_IDS)),
302
+ /**
303
+ * The release asking. A person's reply on a thread counts as waiting only
304
+ * for a release that renders threads; without it the answer is the roots-only
305
+ * count every older release was given.
306
+ */
307
+ cliVersion: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(64))),
308
+ });
309
+ /**
310
+ * What an announcement answers: how many comments are waiting, and how many of
311
+ * them this call was counted as announcing.
312
+ *
313
+ * **Two numbers because they answer two questions and a reader needs both.**
314
+ * `open` is the true state of this repo's comments and is what a caller shows a
315
+ * person — a number that is sometimes a subset of the truth would be worse
316
+ * than the silence it replaced. `announced` is how many of those were still
317
+ * under the cap, and it is the one that decides whether to speak at all: zero
318
+ * means this reader has already been told about every one of them as often as
319
+ * the cap allows.
320
+ */
321
+ export const AnnounceItemCommentsResponseSchema = v.object({
322
+ /** Open, unmuted comments about the items these bundles deliver to this reader. */
323
+ open: v.pipe(v.number(), v.integer(), v.minValue(0)),
324
+ /** How many of those were under the cap and have now been counted as announced. */
325
+ announced: v.pipe(v.number(), v.integer(), v.minValue(0)),
326
+ });
327
+ /**
328
+ * How many comments one agent session may leave on one subject, not counting its
329
+ * whole-subject comment. Anchored comments and replies share it.
330
+ */
331
+ export const MAX_AGENT_COMMENTS_PER_SUBJECT = 50;
332
+ /** The longest an agent comment's text may be, in characters. */
333
+ export const MAX_AGENT_COMMENT_BODY_CHARS = 4000;
334
+ /**
335
+ * Why an agent comment was refused, as the `code` on the error body. A caller
336
+ * branches on these; the message beside one is for a person.
337
+ */
338
+ export const AGENT_COMMENT_ERROR_CODES = [
339
+ /** The request named no agent session. The CLI never makes one up. */
340
+ 'agent_session_required',
341
+ /** This agent session has used its comments on the subject. */
342
+ 'agent_comment_limit_reached',
343
+ /** An agent comment is text only: it may not carry replacement text. */
344
+ 'agent_comment_text_only',
345
+ /** The subject or comment is not one this account can comment on. */
346
+ 'agent_comment_target_missing',
347
+ /** A comment names a passage that is not whole lines of the item as it is now. */
348
+ 'agent_comment_passage_not_found',
349
+ /** The passage appears more than once, so which one is meant is unknown. */
350
+ 'agent_comment_passage_ambiguous',
351
+ /** The item already carries as many open comments as it may. */
352
+ 'item_comment_limit_reached',
353
+ ];
354
+ export const AgentCommentErrorCodeSchema = v.picklist(AGENT_COMMENT_ERROR_CODES);
355
+ const AgentCommentTargetIdSchema = v.pipe(v.string(), v.minLength(1), v.maxLength(128));
356
+ /**
357
+ * Leave a comment, or reply to one, as an agent (`POST /api/v1/context/comments`).
358
+ *
359
+ * **`target` names what the comment is about, one way.** `artifact` is the id
360
+ * a bundle read gave for a guide or document, and `item` is its older name for
361
+ * the same thing, accepted until every client sends `artifact`. `session` is an
362
+ * agent session id of the caller's own (the key a search hit and the session digest hand out), and
363
+ * `reply` is the id of a comment to answer. A reply joins that comment's thread
364
+ * and the subject it is about.
365
+ *
366
+ * **Who the agent is comes from `agent`, and `sessionId` is the harness's own
367
+ * id as the CLI read it.** A request without one is refused with
368
+ * `agent_session_required`, and the CLI and tool offer no way to type one. The
369
+ * server cannot check it against the harness, so it is a claim by the holder of
370
+ * the token: the comment is always written under that token's account, and the
371
+ * handle shown for it names a session only as far as the claim is true.
372
+ *
373
+ * **Text only.** There is no replacement-text field, and a request that carries
374
+ * one is refused with `agent_comment_text_only` rather than having it dropped.
375
+ */
376
+ export const AgentCommentRequestSchema = v.object({
377
+ target: v.variant('kind', [
378
+ v.object({ kind: v.literal('artifact'), id: AgentCommentTargetIdSchema }),
379
+ v.object({ kind: v.literal('session'), id: AgentCommentTargetIdSchema }),
380
+ v.object({ kind: v.literal('reply'), id: AgentCommentTargetIdSchema }),
381
+ ]),
382
+ body: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(MAX_AGENT_COMMENT_BODY_CHARS)),
383
+ /**
384
+ * The passage an item comment is about, as the exact text of one or more whole
385
+ * lines of the item (a paragraph, a heading, a list). None means the item as a
386
+ * whole. The server finds the lines; a passage that is not in the item as it is
387
+ * now is refused with `agent_comment_passage_not_found`.
388
+ */
389
+ passage: v.optional(v.pipe(v.string(), v.minLength(1), v.maxLength(8000))),
390
+ agent: AgentIdentitySchema,
391
+ /**
392
+ * The reader's repo, as its committed `project.id`. A reply may name a
393
+ * comment by the unique id prefix `list_comments` printed, and a comment
394
+ * drafted from one repo's corrections is listed only to a read that declares
395
+ * that repo, so it is matched only by a reply that declares it too.
396
+ */
397
+ projectId: v.optional(ProjectIdSchema),
398
+ /**
399
+ * The bundles the reader's `list_comments` was scoped to, so an id prefix
400
+ * printed there is matched among exactly those bundles. Without it the prefix
401
+ * is matched among every bundle the caller can reach.
402
+ */
403
+ bundleIds: v.optional(v.pipe(v.array(NonEmptyStringSchema), v.maxLength(MAX_COMMENT_BUNDLE_IDS))),
404
+ });
405
+ /** A batch may cover findings across several guides without one write per finding. */
406
+ export const MAX_FINDING_DISMISSALS_PER_REQUEST = 100;
407
+ export const FindingDismissalInputSchema = v.object({
408
+ id: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(128)),
409
+ reason: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(1000), v.check((reason) => !/[\r\n]/.test(reason), 'Use one line for the reason.')),
410
+ });
411
+ export const FindingDismissalInputsSchema = v.pipe(v.array(FindingDismissalInputSchema), v.minLength(1), v.maxLength(MAX_FINDING_DISMISSALS_PER_REQUEST), v.check((rows) => new Set(rows.map((row) => row.id)).size === rows.length, 'Name each finding only once.'));
412
+ export const SuggestFindingDismissalsRequestSchema = v.object({
413
+ suggestions: FindingDismissalInputsSchema,
414
+ agent: AgentCommentRequestSchema.entries.agent,
415
+ });
416
+ /** Recommendations are separate from the finding's open/resolved state. */
417
+ export const FindingDismissalSuggestionSchema = v.object({
418
+ id: NonEmptyStringSchema,
419
+ commentId: NonEmptyStringSchema,
420
+ reason: NonEmptyStringSchema,
421
+ agent: AgentCommentRequestSchema.entries.agent,
422
+ guideVersion: v.number(),
423
+ createdAt: v.string(),
424
+ });
425
+ export const SuggestFindingDismissalsResponseSchema = v.object({
426
+ results: v.array(v.object({
427
+ suggestion: FindingDismissalSuggestionSchema,
428
+ created: v.boolean(),
429
+ valid: v.boolean(),
430
+ })),
431
+ });
432
+ export const FindingDismissalSuggestionsCursorSchema = v.object({
433
+ id: v.pipe(v.string(), v.minLength(1), v.maxLength(128)),
434
+ createdAt: v.pipe(v.string(), v.isoTimestamp()),
435
+ });
436
+ export const FindingDismissalSuggestionsResponseSchema = v.object({
437
+ suggestions: v.array(FindingDismissalSuggestionSchema),
438
+ nextCursor: v.nullable(FindingDismissalSuggestionsCursorSchema),
439
+ });
440
+ /**
441
+ * The comment a create settled on. `created` is false when this agent session
442
+ * already had a whole-subject comment on the subject: that comment comes back
443
+ * unchanged and nothing was written.
444
+ */
445
+ export const AgentCommentResponseSchema = v.object({
446
+ created: v.boolean(),
447
+ comment: v.object({
448
+ id: v.string(),
449
+ threadId: v.string(),
450
+ subject: v.object({
451
+ kind: v.picklist(['artifact', 'session']),
452
+ id: v.string(),
453
+ }),
454
+ body: v.string(),
455
+ createdAt: v.string(),
456
+ }),
457
+ });
458
+ /**
459
+ * One comment on the on-demand read, with the item it is about named on the comment.
460
+ *
461
+ * The item is named here rather than the comments riding an item, because this
462
+ * read answers "what has been left for me" rather than "what is in this
463
+ * bundle": there is no item payload to hang them off, and an agent that has to
464
+ * ask for every item to find out whether one carries a comment is the round trip
465
+ * the announcement exists to avoid.
466
+ */
467
+ export const ItemCommentWithSubjectSchema = v.object({
468
+ ...ContextItemCommentSchema.entries,
469
+ /** The item the comment is about, as the wire names it. */
470
+ itemName: v.string(),
471
+ /** The item's declared repo-relative path, or null when it has none. */
472
+ itemPath: v.nullable(v.string()),
473
+ });
474
+ /**
475
+ * Every open comment waiting for this reader across the bundles they named.
476
+ *
477
+ * **This read is a delivery and is counted as one**, exactly as comments riding
478
+ * an item are: a body reached an agent. What it is *not* is an announcement —
479
+ * nothing here touches the per-repo announcement count, so asking to read your
480
+ * comments never spends the interruptions the hook is allowed.
481
+ *
482
+ * **Never capped.** The announcement cap governs whether a hook speaks; a
483
+ * reader who asked is owed every open comment, and hiding one here would retire a
484
+ * person's request without anybody deciding to.
485
+ */
486
+ export const ItemCommentsResponseSchema = v.object({
487
+ comments: v.array(ItemCommentWithSubjectSchema),
488
+ cursor: v.optional(v.string()),
489
+ /**
490
+ * The markers every `body` above is wrapped in, plus a statement of what
491
+ * they mean. Present exactly when at least one comment came back.
492
+ */
493
+ untrusted: v.optional(v.nullable(GuideHistoryUntrustedSchema)),
494
+ });
495
+ /**
496
+ * The evidence behind one Mossbear finding an agent was handed
497
+ * (`GET /api/v1/context/comments/evidence`).
498
+ *
499
+ * `list_comments` carries the claim and a one-line tier; this is the finding
500
+ * in full: the claim, the change it predicts in future sessions, what the
501
+ * drafter did not read, and the evidence for its tier. Readable only through a
502
+ * comment the comment read itself would deliver to this reader, so another
503
+ * person's finding, one drafted from another repo, or a draft listed only to a
504
+ * newer client has no evidence here either. A draft the reader was listed
505
+ * does: an agent can say why it was raised before the person approves it.
506
+ *
507
+ * Citations (observed and usage findings) are reduced to what the reader may
508
+ * see: their own sessions, with a date and a short excerpt of the grader's
509
+ * reasoning or of their own redacted correction turn. A `navigation` citation
510
+ * has an empty excerpt: it is dated evidence that a session loaded the skill,
511
+ * and nothing more. `citationsWithheld` counts any that were dropped, so a
512
+ * short list is never mistaken for the whole of it.
513
+ */
514
+ export const CommentEvidenceCitationSchema = v.object({
515
+ /**
516
+ * `navigation` is a skill load counted when a finding was drafted from how
517
+ * the skill's files were read: evidence of how a skill was used, not of a
518
+ * failure. `action` is a recorded step of a workflow repeated across
519
+ * sessions. `discrepancy` is a grader's note that a session's closing report
520
+ * contradicted its recorded actions; its excerpt is the agent's quoted claim
521
+ * and the record. `artifact_comment` is a person's comment on an artifact the
522
+ * cited session wrote; its excerpt is the comment. A server sends `action`,
523
+ * `discrepancy` and `artifact_comment` only to a client that names a version
524
+ * new enough to parse them.
525
+ */
526
+ kind: v.picklist([
527
+ 'verdict',
528
+ 'turn',
529
+ 'navigation',
530
+ 'action',
531
+ 'discrepancy',
532
+ 'artifact_comment',
533
+ ]),
534
+ sessionId: NonEmptyStringSchema,
535
+ /** ISO, when the verdict was graded, the turn was said, the skill loaded, or the action was recorded. */
536
+ at: v.string(),
537
+ /** Wrapped in the response's untrusted markers. */
538
+ excerpt: v.string(),
539
+ });
540
+ /** What a usage finding adds to its citations: the counts for one reference file. */
541
+ export const CommentEvidenceUsageSchema = v.object({
542
+ /** The reference's skill-relative path, wrapped in the response's untrusted markers. */
543
+ path: v.string(),
544
+ /** Eligible loads of the skill. */
545
+ loads: v.pipe(v.number(), v.integer()),
546
+ /** Distinct sessions those loads span. */
547
+ sessions: v.pipe(v.number(), v.integer()),
548
+ /** Loads followed by a successful read of the reference. */
549
+ loadsWithRead: v.pipe(v.number(), v.integer()),
550
+ });
551
+ /**
552
+ * What a practice finding adds: the rubric check it answers and the rubric's
553
+ * version, the practice lines it weighs with their sources, the facts measured
554
+ * from the file, and the answer to each item of evidence the check asks for.
555
+ * `answers[].answer` is model-written, so it travels wrapped in the response's
556
+ * untrusted markers.
557
+ */
558
+ export const CommentEvidencePracticeSchema = v.object({
559
+ check: v.object({ id: v.string(), name: v.string() }),
560
+ rubricVersion: v.pipe(v.number(), v.integer()),
561
+ // Optional, so a CLI reads a dashboard that has not shipped these fields yet:
562
+ // the two release independently.
563
+ practices: v.optional(v.array(v.object({
564
+ text: v.string(),
565
+ source: v.object({ title: v.string(), url: v.string() }),
566
+ })), []),
567
+ facts: v.optional(v.array(v.string()), []),
568
+ answers: v.optional(v.array(v.object({ item: v.string(), answer: v.string() })), []),
569
+ });
570
+ /**
571
+ * A comment the person (or Mossbear) left on one of the sessions a finding
572
+ * cites — the person's own account of what the agent should have known, set
573
+ * beside the grader's excerpt (`guide-findings-plan.md` → Your note on a
574
+ * session).
575
+ *
576
+ * **Reachable only here.** A comment about a session is never listed by
577
+ * `list_comments` or announced at session start: it is context for a finding,
578
+ * found by following the finding's citation, not a request.
579
+ */
580
+ export const CommentEvidenceSessionCommentSchema = v.object({
581
+ sessionId: NonEmptyStringSchema,
582
+ /** Only the person's own notes are sent today; `mossbear` is reserved. */
583
+ authorKind: v.picklist(['person', 'mossbear']),
584
+ /** ISO, when the comment was written. */
585
+ at: v.string(),
586
+ /** Wrapped in the response's untrusted markers. */
587
+ body: v.string(),
588
+ });
589
+ export const CommentEvidenceResponseSchema = v.object({
590
+ /** The comment's full id, even when the request named a prefix. */
591
+ commentId: NonEmptyStringSchema,
592
+ itemName: v.string(),
593
+ itemPath: v.nullable(v.string()),
594
+ tier: FindingTierSchema,
595
+ /** One line saying how the finding is known; server-written, outside the markers. */
596
+ tierLine: v.string(),
597
+ /** What the drafter did not read; server-written, outside the markers. */
598
+ blindSpot: v.string(),
599
+ /** What goes wrong, wrapped in the response's untrusted markers. */
600
+ claim: v.string(),
601
+ /** What future sessions should show if the finding is fixed, wrapped; null if none. */
602
+ prediction: v.nullable(v.string()),
603
+ /** A usage finding's counts; null on every other tier. */
604
+ usage: v.nullable(CommentEvidenceUsageSchema),
605
+ /** A practice finding's rubric check; null on every other tier. */
606
+ practice: v.nullable(CommentEvidencePracticeSchema),
607
+ citations: v.array(CommentEvidenceCitationSchema),
608
+ citationsWithheld: v.pipe(v.number(), v.integer()),
609
+ /**
610
+ * Comments on the cited sessions, newest first, wrapped in the untrusted
611
+ * markers. Defaulted so a response from a server that predates the field
612
+ * still parses.
613
+ */
614
+ sessionComments: v.optional(v.array(CommentEvidenceSessionCommentSchema), []),
615
+ /**
616
+ * Comments on the cited sessions that were left out to keep the response
617
+ * bounded (the newest few per session are sent), so a short list is never
618
+ * mistaken for the whole of it. Zero when none were.
619
+ */
620
+ sessionCommentsWithheld: v.optional(v.pipe(v.number(), v.integer()), 0),
621
+ untrusted: GuideHistoryUntrustedSchema,
622
+ });
623
+ /**
624
+ * How many artifacts one prompt-time announcement names. The rest are counted
625
+ * in one line and named on a later prompt, so a session that wrote many
626
+ * artifacts prints a few lines in front of a turn rather than a list.
627
+ */
628
+ export const MAX_SESSION_COMMENT_ANNOUNCEMENT_ARTIFACTS = 5;
629
+ /**
630
+ * Ask which artifacts this agent session wrote carry open comments, and which
631
+ * (`agent-hears-new-artifact-comments` slice 3).
632
+ *
633
+ * **A read, not a write.** Which of those comments the session has already been
634
+ * told about is kept beside the session, by comment id. Not by creation time:
635
+ * a comment can become readable long after it was created (a finding its owner
636
+ * approves, an artifact restored from the Trash), and a time cursor would have
637
+ * passed it by. The session-start announcement's per-repo count is a different
638
+ * question and is not touched.
639
+ */
640
+ export const AnnounceSessionCommentsRequestSchema = v.object({
641
+ /**
642
+ * The harness's own id for the session, as artifact writes record it in a
643
+ * version's metadata. Matched only against versions the caller's account
644
+ * wrote, so naming another account's session finds nothing.
645
+ */
646
+ agentSessionId: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(256)),
647
+ /** The repo asking, as its committed config declares it, for repo-scoped findings. */
648
+ projectId: v.optional(ProjectIdSchema),
649
+ });
650
+ export const AnnounceSessionCommentsResponseSchema = v.object({
651
+ /**
652
+ * The session's artifacts that carry open comments, most recently commented
653
+ * first; at most as many as one batch feedback read takes.
654
+ */
655
+ artifacts: v.pipe(v.array(v.object({
656
+ id: NonEmptyStringSchema,
657
+ name: v.string(),
658
+ /** Its open comments, newest first, at most one wire allowance of them. */
659
+ commentIds: v.pipe(v.array(NonEmptyStringSchema), v.minLength(1), v.maxLength(MAX_ITEM_COMMENTS_ON_WIRE)),
660
+ })), v.maxLength(MAX_ARTIFACT_FEEDBACK_BATCH)),
661
+ });
662
+ export function parseAnnounceItemCommentsRequest(data) {
663
+ return v.parse(AnnounceItemCommentsRequestSchema, data);
664
+ }
665
+ export function parseResolveItemCommentResponse(data) {
666
+ return v.parse(ResolveItemCommentResponseSchema, data);
667
+ }
668
+ export function parseAnnounceItemCommentsResponse(data) {
669
+ return v.parse(AnnounceItemCommentsResponseSchema, data);
670
+ }
671
+ export function parseAnnounceSessionCommentsResponse(data) {
672
+ return v.parse(AnnounceSessionCommentsResponseSchema, data);
673
+ }
674
+ export function parseAgentCommentResponse(data) {
675
+ return v.parse(AgentCommentResponseSchema, data);
676
+ }
677
+ export function parseItemCommentsResponse(data) {
678
+ return v.parse(ItemCommentsResponseSchema, data);
679
+ }
680
+ export function parseCommentEvidenceResponse(data) {
681
+ return v.parse(CommentEvidenceResponseSchema, data);
682
+ }
683
+ //# sourceMappingURL=comments.js.map