@north-light/cli 0.3.706 → 0.3.708

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 (187) hide show
  1. package/dist/api/client.d.ts +1 -2
  2. package/dist/api/client.js +3 -3
  3. package/dist/api/contract.d.ts +1 -1
  4. package/dist/api/contract.js +1 -1
  5. package/dist/api/dto/human.d.ts +9 -6
  6. package/dist/api/dto/inbox.d.ts +2 -0
  7. package/dist/api/dto/review-comments.d.ts +12 -35
  8. package/dist/api/dto/reviews.d.ts +3 -10
  9. package/dist/api/routes.d.ts +0 -1
  10. package/dist/api/routes.js +1 -1
  11. package/dist/builtin-memory/05-kinds/review/companion/00-base.md +2 -2
  12. package/dist/builtin-memory/crouter-sdk/release-notes.md +6 -0
  13. package/dist/clients/attach/chrome/canvas-panels.d.ts +1 -1
  14. package/dist/clients/attach/chrome/canvas-panels.js +1 -1
  15. package/dist/clients/attach/chrome/roster.js +6 -6
  16. package/dist/clients/attach/chrome/status-line.js +1 -1
  17. package/dist/clients/attach/chrome/ticket-panel.js +1 -1
  18. package/dist/clients/attach/input/controller.d.ts +0 -1
  19. package/dist/clients/attach/input/controller.js +3 -3
  20. package/dist/clients/attach/input/overlay-owner.d.ts +0 -1
  21. package/dist/clients/attach/input/overlay-owner.js +1 -1
  22. package/dist/clients/attach/session/keys.d.ts +0 -2
  23. package/dist/clients/attach/session/keys.js +1 -1
  24. package/dist/clients/attach/session/surface-host.d.ts +0 -5
  25. package/dist/clients/attach/session/surface-host.js +1 -1
  26. package/dist/clients/attach/viewer.js +545 -560
  27. package/dist/clients/editor-roundtrip.js +3 -0
  28. package/dist/clients/inbox/controller.d.ts +1 -6
  29. package/dist/clients/inbox/controller.js +1 -1
  30. package/dist/clients/inbox/dto-adapt.js +1 -1
  31. package/dist/clients/inbox/tui/page-body.js +1 -1
  32. package/dist/clients/inbox/tui/render.js +2 -2
  33. package/dist/clients/open-browser.d.ts +2 -0
  34. package/dist/clients/open-browser.js +1 -0
  35. package/dist/clients/surfaces/host.d.ts +0 -6
  36. package/dist/commands/human/review.js +1 -1
  37. package/dist/commands/sys/context/admin/shell.js +1 -1
  38. package/dist/core/canvas/schema-pg/025-review-anchors.sql +19 -0
  39. package/dist/core/canvas/schema-version.d.ts +1 -1
  40. package/dist/core/canvas/schema-version.js +1 -1
  41. package/dist/core/human/page-markdown.js +10 -12
  42. package/dist/core/human/tickets.js +1 -1
  43. package/dist/core/human/types.d.ts +4 -6
  44. package/dist/core/keybindings/attach-control.d.ts +0 -3
  45. package/dist/core/keybindings/attach-control.js +1 -1
  46. package/dist/core/keybindings/catalog.d.ts +1 -1
  47. package/dist/core/keybindings/catalog.js +1 -1
  48. package/dist/core/review/anchors.d.ts +28 -0
  49. package/dist/core/review/anchors.js +6 -0
  50. package/dist/core/review/comments.d.ts +2 -2
  51. package/dist/core/review/comments.js +7 -8
  52. package/dist/core/review/companion.d.ts +2 -1
  53. package/dist/core/review/companion.js +1 -1
  54. package/dist/core/review/document.d.ts +4 -17
  55. package/dist/core/review/document.js +1 -2
  56. package/dist/core/review/fork.js +2 -4
  57. package/dist/core/review/project.d.ts +1 -1
  58. package/dist/core/review/project.js +2 -2
  59. package/dist/core/review/realize.js +1 -1
  60. package/dist/core/review/stage.d.ts +2 -9
  61. package/dist/core/review/stage.js +1 -1
  62. package/dist/core/review/types.d.ts +16 -12
  63. package/dist/core/review/types.js +1 -1
  64. package/dist/core/runtime/broker/turn-replies.d.ts +1 -3
  65. package/dist/core/runtime/broker-cli.js +3 -3
  66. package/dist/core/runtime/broker-extension-render.js +1 -1
  67. package/dist/core/runtime/tmux-bindings.js +3 -3
  68. package/dist/daemon/api/canvas-host.js +1 -1
  69. package/dist/daemon/api/document-page.d.ts +12 -1
  70. package/dist/daemon/api/document-page.js +6 -6
  71. package/dist/daemon/api/handlers/inbox.js +1 -1
  72. package/dist/daemon/api/handlers/review-comments.js +1 -1
  73. package/dist/daemon/api/handlers/reviews.js +1 -1
  74. package/dist/daemon/api/map.js +2 -2
  75. package/dist/daemon/api/review-page.d.ts +3 -0
  76. package/dist/daemon/api/review-page.js +13 -0
  77. package/dist/daemon/broker-memory-cap.d.ts +9 -0
  78. package/dist/daemon/broker-memory-cap.js +2 -0
  79. package/dist/daemon/broker-signals/bus.d.ts +1 -1
  80. package/dist/daemon/broker-signals/bus.js +1 -1
  81. package/dist/daemon/crtrd.js +14 -14
  82. package/dist/daemon/machine-daemon.js +1 -1
  83. package/dist/daemon/review/comment-notify.js +2 -2
  84. package/dist/daemon/review/deliver.d.ts +2 -2
  85. package/dist/daemon/review/deliver.js +6 -2
  86. package/dist/daemon/review/finish.js +1 -1
  87. package/dist/doc-editor/Geist-Variable.woff2 +0 -0
  88. package/dist/doc-editor/GeistMono-Variable.woff2 +0 -0
  89. package/dist/doc-editor/editor.css +1 -1
  90. package/dist/doc-editor/review.css +2 -0
  91. package/dist/doc-editor/review.js +149 -0
  92. package/dist/pi-extensions/canvas-review-boundary.js +3 -3
  93. package/dist/shared/turn-replies.d.ts +3 -3
  94. package/dist/shared/turn-replies.js +3 -3
  95. package/docs/sdk/release-notes.md +6 -0
  96. package/package.json +13 -4
  97. package/packages/crouter-api/dist/api/client.js +0 -3
  98. package/packages/crouter-api/dist/api/contract.js +1 -1
  99. package/packages/crouter-api/dist/api/routes.js +0 -1
  100. package/packages/crouter-api/dist/clients/attach/chrome/canvas-panels.js +3 -3
  101. package/packages/crouter-api/dist/clients/attach/chrome/roster.js +9 -20
  102. package/packages/crouter-api/dist/clients/attach/chrome/status-line.js +1 -6
  103. package/packages/crouter-api/dist/clients/attach/chrome/ticket-panel.js +1 -1
  104. package/packages/crouter-api/dist/clients/attach/input/controller.js +0 -3
  105. package/packages/crouter-api/dist/clients/attach/input/overlay-owner.js +0 -7
  106. package/packages/crouter-api/dist/clients/attach/session/keys.js +0 -1
  107. package/packages/crouter-api/dist/clients/attach/session/surface-host.js +0 -17
  108. package/packages/crouter-api/dist/clients/attach/viewer.js +0 -37
  109. package/packages/crouter-api/dist/clients/{inbox/review/roundtrip.js → editor-roundtrip.js} +1 -1
  110. package/packages/crouter-api/dist/clients/inbox/controller.js +12 -31
  111. package/packages/crouter-api/dist/clients/inbox/dto-adapt.js +1 -0
  112. package/packages/crouter-api/dist/clients/inbox/tui/page-body.js +0 -7
  113. package/packages/crouter-api/dist/clients/inbox/tui/render.js +0 -7
  114. package/packages/crouter-api/dist/clients/open-browser.js +6 -0
  115. package/packages/crouter-api/dist/commands/human/review.js +17 -18
  116. package/packages/crouter-api/dist/commands/sys/context/admin/shell.js +1 -1
  117. package/packages/crouter-api/dist/core/canvas/schema-version.js +1 -1
  118. package/packages/crouter-api/dist/core/human/page-markdown.js +2 -6
  119. package/packages/crouter-api/dist/core/human/tickets.js +2 -11
  120. package/packages/crouter-api/dist/core/keybindings/attach-control.js +0 -1
  121. package/packages/crouter-api/dist/core/keybindings/catalog.js +1 -3
  122. package/packages/crouter-api/dist/core/review/anchors.js +91 -0
  123. package/packages/crouter-api/dist/core/review/comments.js +27 -46
  124. package/packages/crouter-api/dist/core/review/companion.js +5 -9
  125. package/packages/crouter-api/dist/core/review/document.js +17 -89
  126. package/packages/crouter-api/dist/core/review/project.js +2 -1
  127. package/packages/crouter-api/dist/core/review/types.js +2 -2
  128. package/packages/crouter-api/dist/core/runtime/tmux-bindings.js +0 -5
  129. package/packages/crouter-api/dist/daemon/api/map.js +2 -6
  130. package/packages/crouter-api/dist/daemon/broker-signals/bus.js +1 -1
  131. package/packages/crouter-api/dist/daemon/review/deliver.js +4 -3
  132. package/packages/crouter-api/dist/daemon/review/finish.js +26 -47
  133. package/packages/crouter-api/dist/shared/turn-replies.js +9 -14
  134. package/packages/crouter-api/package.json +1 -1
  135. package/packages/crouter-identity/package.json +1 -1
  136. package/packages/crouter-plugin/package.json +3 -3
  137. package/runtime.lock.json +1740 -505
  138. package/dist/clients/attach/overlays/file-review.d.ts +0 -10
  139. package/dist/clients/attach/overlays/file-review.js +0 -2
  140. package/dist/clients/inbox/review/anchors.d.ts +0 -41
  141. package/dist/clients/inbox/review/anchors.js +0 -1
  142. package/dist/clients/inbox/review/comments-client.d.ts +0 -74
  143. package/dist/clients/inbox/review/comments-client.js +0 -1
  144. package/dist/clients/inbox/review/companion-pane.d.ts +0 -47
  145. package/dist/clients/inbox/review/companion-pane.js +0 -1
  146. package/dist/clients/inbox/review/document-surface.d.ts +0 -212
  147. package/dist/clients/inbox/review/document-surface.js +0 -2
  148. package/dist/clients/inbox/review/frame.d.ts +0 -57
  149. package/dist/clients/inbox/review/frame.js +0 -1
  150. package/dist/clients/inbox/review/keys.d.ts +0 -69
  151. package/dist/clients/inbox/review/keys.js +0 -1
  152. package/dist/clients/inbox/review/launch.d.ts +0 -16
  153. package/dist/clients/inbox/review/launch.js +0 -1
  154. package/dist/clients/inbox/review/live-source.d.ts +0 -24
  155. package/dist/clients/inbox/review/live-source.js +0 -1
  156. package/dist/clients/inbox/review/nvim.d.ts +0 -15
  157. package/dist/clients/inbox/review/nvim.js +0 -1
  158. package/dist/clients/inbox/review/remap.d.ts +0 -51
  159. package/dist/clients/inbox/review/remap.js +0 -1
  160. package/dist/clients/inbox/review/review-client.d.ts +0 -43
  161. package/dist/clients/inbox/review/review-client.js +0 -1
  162. package/dist/clients/inbox/review/roundtrip.js +0 -3
  163. package/dist/clients/inbox/review/state.d.ts +0 -153
  164. package/dist/clients/inbox/review/state.js +0 -4
  165. package/dist/clients/inbox/review-adapter.d.ts +0 -17
  166. package/dist/clients/inbox/review-adapter.js +0 -1
  167. package/dist/core/review/remap.d.ts +0 -24
  168. package/dist/core/review/remap.js +0 -19
  169. package/dist/core/review/signal.d.ts +0 -5
  170. package/dist/core/review/signal.js +0 -1
  171. package/packages/crouter-api/dist/clients/attach/overlays/file-review.js +0 -146
  172. package/packages/crouter-api/dist/clients/inbox/review/anchors.js +0 -89
  173. package/packages/crouter-api/dist/clients/inbox/review/comments-client.js +0 -103
  174. package/packages/crouter-api/dist/clients/inbox/review/companion-pane.js +0 -109
  175. package/packages/crouter-api/dist/clients/inbox/review/document-surface.js +0 -1268
  176. package/packages/crouter-api/dist/clients/inbox/review/frame.js +0 -309
  177. package/packages/crouter-api/dist/clients/inbox/review/keys.js +0 -133
  178. package/packages/crouter-api/dist/clients/inbox/review/launch.js +0 -170
  179. package/packages/crouter-api/dist/clients/inbox/review/live-source.js +0 -160
  180. package/packages/crouter-api/dist/clients/inbox/review/nvim.js +0 -43
  181. package/packages/crouter-api/dist/clients/inbox/review/remap.js +0 -157
  182. package/packages/crouter-api/dist/clients/inbox/review/review-client.js +0 -125
  183. package/packages/crouter-api/dist/clients/inbox/review/state.js +0 -315
  184. package/packages/crouter-api/dist/clients/inbox/review-adapter.js +0 -43
  185. package/packages/crouter-api/dist/core/review/signal.js +0 -12
  186. package/packages/crouter-api/dist/core/termrender/code-doc.js +0 -92
  187. /package/dist/clients/{inbox/review/roundtrip.d.ts → editor-roundtrip.d.ts} +0 -0
@@ -2,10 +2,11 @@ import { atomicWriteJson } from '../human/convention.js';
2
2
  import { isCloudRole } from '../canvas/person.js';
3
3
  import { writeRequestFile } from '../human/request-files.js';
4
4
  /** Build the immutable approval result from the review row and one comment snapshot. */
5
- export function buildReviewResult(review, snapshot, approvedSha256, at) {
5
+ export function buildReviewResult(review, snapshot, approvedSha256, at, document) {
6
6
  return {
7
7
  schema: 'humanloop.review-response/v1',
8
8
  review_id: review.review_id,
9
+ document,
9
10
  file: review.file,
10
11
  submitted: true,
11
12
  approved: true,
@@ -5,8 +5,8 @@
5
5
  */
6
6
  /** Limits */
7
7
  export const COMMENT_TEXT_MAX = 8_000;
8
- export const COMMENT_QUOTE_MAX = 4_000;
9
- export const COMMENT_LINE_TEXT_MAX = 8_000;
8
+ export const COMMENT_QUOTE_MAX = 2_000;
9
+ export const ANCHOR_CONTEXT_MAX = 32;
10
10
  export const LIVE_COMMENTS_MAX = 500;
11
11
  export const COMMENT_EVENTS_PAGE_DEFAULT = 200;
12
12
  export const COMMENT_EVENTS_PAGE_MAX = 1_000;
@@ -26,10 +26,6 @@ const LEAF_MENU_ACTIONS = {
26
26
  'crtr.tmux.menu.detach': { description: 'demote + close viewer', action: { kind: 'direct', run: 'node lifecycle demote --pane {pane} --detach' } },
27
27
  'crtr.tmux.menu.close-subtree': { description: 'close agent + subtree', action: { kind: 'direct', run: 'node lifecycle close --pane {pane}' } },
28
28
  'crtr.tmux.menu.background-bash': { description: 'background running bash', action: { kind: 'direct', run: 'node bash background --pane {pane}' } },
29
- // M-S-r, not M-R: with extended-keys csi-u tmux encodes M-R as alt+uppercase-R
30
- // WITHOUT the shift modifier bit, which pi-tui's `alt+shift+r` matcher rejects;
31
- // M-S-r carries shift+alt and lands as the same chord the keyboard produces.
32
- 'crtr.tmux.menu.file-review': { description: 'review a file', action: { kind: 'raw-keys', keys: 'M-S-r' } },
33
29
  'crtr.tmux.menu.metadata': { description: 'metadata', action: { kind: 'keys', keys: '/node-metadata' } },
34
30
  'crtr.tmux.menu.more-detail': { description: 'more detail', action: { kind: 'keys', keys: '/more-detail' } },
35
31
  'crtr.tmux.menu.less-detail': { description: 'less detail', action: { kind: 'keys', keys: '/less-detail' } },
@@ -300,7 +296,6 @@ function menuItems(bindings, entries) {
300
296
  addGroup('Current node', boundItems([
301
297
  'crtr.tmux.menu.attach',
302
298
  'crtr.tmux.menu.background-bash',
303
- 'crtr.tmux.menu.file-review',
304
299
  'crtr.tmux.menu.pin',
305
300
  'crtr.tmux.menu.copy-id',
306
301
  'crtr.tmux.menu.reload-viewer',
@@ -497,9 +497,6 @@ export function toReviewCommentDTO(comment) {
497
497
  revision: comment.revision,
498
498
  text: comment.text,
499
499
  anchor: { ...comment.anchor },
500
- anchor_state: comment.anchor_state,
501
- anchor_line_text: comment.anchor_line_text,
502
- anchor_doc_hash: comment.anchor_doc_hash,
503
500
  author: {
504
501
  kind: comment.author.kind,
505
502
  ...(comment.author.node_id === null ? {} : { node_id: comment.author.node_id }),
@@ -556,6 +553,7 @@ export function toReviewCommentEventDTO(event) {
556
553
  /** Project the immutable snake_case review result to the existing camelCase feedback wire shape. */
557
554
  export function toFeedbackResultDTO(result) {
558
555
  const dto = {
556
+ document: result.document,
559
557
  file: result.file,
560
558
  submitted: result.submitted,
561
559
  approved: result.approved,
@@ -596,12 +594,10 @@ export const REVIEW_ERROR_MAP = Object.freeze({
596
594
  unknown_comment: { status: 404, code: 'unknown_comment' },
597
595
  comment_deleted: { status: 409, code: 'comment_deleted' },
598
596
  invalid_anchor: { status: 400, code: 'invalid_anchor' },
599
- anchor_out_of_range: { status: 400, code: 'anchor_out_of_range' },
597
+ quote_not_found: { status: 409, code: 'quote_not_found' },
600
598
  text_too_long: { status: 400, code: 'text_too_long' },
601
599
  comment_limit_reached: { status: 409, code: 'comment_limit_reached' },
602
600
  stale_comment: { status: 409, code: 'stale_comment' },
603
- range_batch_incomplete: { status: 409, code: 'range_batch_incomplete' },
604
- range_batch_stale: { status: 409, code: 'range_batch_stale' },
605
601
  });
606
602
  /** The single error-mapping function (spec §8). Projects any thrown value into
607
603
  * `{ status, code }`:
@@ -27,7 +27,7 @@ export function cachedBrokerNodeFields(node) {
27
27
  * exited (the lane processes run that node's lifecycle pass). `document` carries a document object id: it was edited or
28
28
  * deleted, and a browser document stream re-reads it. The writers fire them (the
29
29
  * schema's triggers, or the unit that owns the writer); the bus only delivers. */
30
- export const BROKER_SIGNAL_KINDS = ['mail', 'node', 'grant', 'run_event', 'report', 'structured_request', 'queue', 'spend_limits', 'environment_image', 'fault_retry', 'settings', 'machine', 'machine_call', 'document', 'execution_exit'];
30
+ export const BROKER_SIGNAL_KINDS = ['mail', 'node', 'grant', 'run_event', 'report', 'structured_request', 'queue', 'spend_limits', 'environment_image', 'fault_retry', 'settings', 'machine', 'machine_call', 'document', 'review', 'execution_exit'];
31
31
  const KNOWN_KINDS = new Set(BROKER_SIGNAL_KINDS);
32
32
  /** Hints, not delivery state: a rolled-back write may mark an id. The consumer always re-reads durable state. Pending
33
33
  * marks are bounded by distinct (kind, id) pairs and delivered once per flush. */
@@ -1,13 +1,14 @@
1
1
  /** Render the immutable approval fact as plain prose. It is delivered as an
2
2
  * inbox entry, so the inbox card is its envelope — a nested `<runtime>` card
3
3
  * here would reach the model escaped and the attached view as raw markup. */
4
- export function renderApprovalMessage(review, resultPath) {
4
+ export function renderApprovalMessage(review, resultPath, comments = []) {
5
5
  const summary = review.document_name !== null
6
6
  ? review.changed
7
- ? `The user reviewed and approved \`${review.document_name}\`. Their edits are saved as a new revision; re-read it with \`crtr canvas read ${review.document_name}\` before continuing. Review conversation: node \`${review.companion_node_id}\`.`
7
+ ? `The user reviewed and approved \`${review.document_name}\`. Their edits are saved in the document; re-read it with \`crtr canvas read ${review.document_name}\` before continuing. Review conversation: node \`${review.companion_node_id}\`.`
8
8
  : `The user reviewed and approved \`${review.document_name}\`. The document was not modified.`
9
9
  : review.changed
10
10
  ? `The user reviewed and approved \`${review.file}\`. The document changed during review; re-read it before continuing. Review conversation: node \`${review.companion_node_id}\`.`
11
11
  : `The user reviewed and approved \`${review.file}\`. The document was not modified.`;
12
- return `${summary}\n\nDurable review result: ${resultPath}`;
12
+ const notes = comments.length === 0 ? '' : `\n\nComments:\n${comments.map((c) => `- ${c.resolved ? '[resolved] ' : ''}"${c.quote}"${c.detached === true ? ' (text no longer in the document)' : ''}: ${c.comment}`).join('\n')}`;
13
+ return `${summary}${notes}\n\nDurable review result: ${resultPath}`;
13
14
  }
@@ -1,13 +1,11 @@
1
1
  import { withCanvasWrite } from '../../core/canvas/db.js';
2
- import { get as getBody } from '../../core/graph/bodies.js';
3
- import { documentById, editDocument, heads } from '../../core/graph/documents.js';
4
- import { readerFor } from '../../core/graph/reader.js';
2
+ import { createHash } from 'node:crypto';
3
+ import { documentById, heads } from '../../core/graph/documents.js';
5
4
  import { warmDocumentWatchers } from '../api/reader.js';
6
- import { checkoutsForCwd } from '../../core/graph/repo-sync/repos.js';
7
- import { snapshotCommentsLocked } from '../../core/review/comments.js';
8
- import { readReviewSource } from '../../core/review/document.js';
5
+ import { signalReviewChange, snapshotCommentsLocked } from '../../core/review/comments.js';
6
+ import { currentReviewText } from '../../core/review/document.js';
7
+ import { renderedText, resolveAnchor } from '../../core/review/anchors.js';
9
8
  import { projectReviewCancellation, projectReviewResult, buildReviewResult } from '../../core/review/project.js';
10
- import { signalReviewActivity } from '../../core/review/signal.js';
11
9
  import { clearReviewSubmit, getReview, getReviewByCompanion, requestReviewSubmit, requireVisibleReview } from '../../core/review/store.js';
12
10
  import { ReviewOperationError } from '../../core/review/types.js';
13
11
  import { settleHumanRequest } from '../human/settle.js';
@@ -32,11 +30,11 @@ function effects(result) {
32
30
  }
33
31
  /** A runtime notice, not the person's words: `human-answer` would make attached
34
32
  * views render this body as a message the person typed. */
35
- function approvalNotification(review) {
33
+ function approvalNotification(review, result) {
36
34
  return {
37
35
  label: 'review approved by the user',
38
36
  disposition: null,
39
- body_json: { review_id: review.review_id, result_path: resultPath(review), body: renderApprovalMessage(review, resultPath(review)) },
37
+ body_json: { review_id: review.review_id, result_path: resultPath(review), body: renderApprovalMessage(review, resultPath(review), result.comments) },
40
38
  };
41
39
  }
42
40
  function cancellationNotification(review, reason, disposition) {
@@ -47,39 +45,11 @@ function cancellationNotification(review, reason, disposition) {
47
45
  body_json: { review_id: review.review_id, disposition, body: dismissed ? `The review of \`${review.document_name ?? review.file}\` was dismissed without approval.` : `The review of \`${review.document_name ?? review.file}\` was canceled${reason === '' ? '' : ` — ${reason}`}.` },
48
46
  };
49
47
  }
50
- /**
51
- * A document review's edits become a new revision, authored by the person, made from the heads
52
- * the review was snapshotted from. The document moving meanwhile refuses the save as
53
- * `stale_revision`; the same text already at the single head (a concurrent submit of this
54
- * review won) counts as saved.
55
- */
56
- async function saveReviewedDocument(db, review, text) {
57
- if (review.document_id === null || review.document_base === null)
58
- return;
59
- const reposFn = async (cwd, person) => await checkoutsForCwd(db, cwd, person);
60
- const doc = await documentById(db, review.document_id);
61
- const reader = await readerFor(db, { class: 'person' }, reposFn);
62
- const saved = await editDocument(db, reader, doc, { body: text }, `edited in review ${review.review_id}`, review.document_base, {}, reposFn);
63
- if (!('stale' in saved))
64
- return;
65
- const current = await heads(db, doc);
66
- if (current.length === 1 && await getBody(db, current[0].body_hash) === text)
67
- return;
68
- throw new ReviewOperationError('stale_revision', `${review.document_name ?? doc.name} changed since the review began; the reviewed text was not saved`, {
69
- review_id: review.review_id,
70
- document: review.document_name ?? doc.name,
71
- base: review.document_base,
72
- heads_key: saved.stale.heads_key,
73
- revision: saved.stale.revision,
74
- next: `Read the current revision with \`crtr canvas read ${doc.id}\`, then start a new review of it.`,
75
- });
76
- }
77
48
  async function approveReview(initial) {
78
49
  if (initial.state === 'canceled')
79
50
  return terminalConflict(initial, 'submit');
80
51
  if (initial.state === 'approved')
81
52
  return { outcome: 'already_settled', record: initial, result: approvedResult(initial) };
82
- const source = await readReviewSource(initial.file, 'submit');
83
53
  if (initial.document_id !== null)
84
54
  await warmDocumentWatchers(initial.document_id); // git lookups before the write opens
85
55
  const { result, resultJson } = await withCanvasWrite(async (db) => {
@@ -88,33 +58,43 @@ async function approveReview(initial) {
88
58
  return terminalConflict(review, 'submit');
89
59
  if (review.state === 'approved')
90
60
  return { result: approvedResult(review), resultJson: review.result_json };
61
+ const text = await currentReviewText(db, review);
62
+ const approvedSha256 = createHash('sha256').update(text).digest('hex');
91
63
  const snapshot = await snapshotCommentsLocked(db, review.review_id);
92
- const result = buildReviewResult(review, snapshot, source.sha256, now());
93
- if (result.changed)
94
- await saveReviewedDocument(db, review, new TextDecoder('utf-8').decode(source.bytes));
64
+ const quotes = renderedText(text);
65
+ for (const comment of snapshot.comments)
66
+ comment.detached = resolveAnchor(quotes, { quote: comment.quote, prefix: '', suffix: '', offset: 0 }) === null;
67
+ let document = null;
68
+ if (review.document_id !== null) {
69
+ const doc = await documentById(db, review.document_id);
70
+ document = { id: doc.id, name: review.document_name ?? doc.name, base_revision: review.document_base, approved_revision: (await heads(db, doc)).map((h) => h.rev_id).sort().join(',') };
71
+ }
72
+ const result = buildReviewResult(review, snapshot, approvedSha256, now(), document);
95
73
  return { result, resultJson: JSON.stringify(result) };
96
74
  });
97
75
  const settled = await settleHumanRequest({
98
76
  request_id: initial.review_id,
99
77
  outcome: 'approved',
100
78
  result_json: resultJson,
101
- notification: approvalNotification({ ...initial, changed: result.changed }),
79
+ notification: approvalNotification({ ...initial, changed: result.changed }, result),
102
80
  post_commit: effects(result),
103
81
  });
104
82
  if (settled.outcome === 'settled')
105
- signalReviewActivity();
83
+ await signalReview(initial.review_id);
106
84
  const record = await requireVisibleReview(initial.review_id);
107
85
  if (settled.outcome === 'already_settled' && record.state !== 'approved')
108
86
  return terminalConflict(record, 'submit');
109
87
  return { outcome: settled.outcome, record, result: settled.outcome === 'settled' ? result : approvedResult(record) };
110
88
  }
89
+ /** Announce a review change committed by the settle or store step just before. */
90
+ const signalReview = (reviewId) => withCanvasWrite((db) => signalReviewChange(db, reviewId));
111
91
  export async function submitReviewApproval(reviewId) {
112
92
  const review = await requireVisibleReview(reviewId);
113
93
  if (review.state === 'canceled')
114
94
  return terminalConflict(review, 'submit');
115
95
  if (review.state === 'open' && await companionStillWorking(review.companion_node_id)) {
116
96
  if (await requestReviewSubmit(reviewId, now()))
117
- signalReviewActivity();
97
+ await signalReview(reviewId);
118
98
  return { outcome: 'awaiting_companion', record: await requireVisibleReview(reviewId) };
119
99
  }
120
100
  return approveReview(review);
@@ -131,10 +111,9 @@ export async function completeRequestedSubmit(reviewId, opts) {
131
111
  return await approveReview(review);
132
112
  }
133
113
  catch (error) {
134
- // A refused save leaves the review open with no submit pending, rather than retried every tick.
135
- if (error instanceof ReviewOperationError && error.code === 'stale_revision') {
114
+ if (error instanceof ReviewOperationError && error.code === 'source_unreadable') {
136
115
  await clearReviewSubmit(reviewId);
137
- signalReviewActivity();
116
+ await signalReview(reviewId);
138
117
  }
139
118
  throw error;
140
119
  }
@@ -162,7 +141,7 @@ export async function cancelReview(reviewId, args = {}) {
162
141
  },
163
142
  });
164
143
  if (settled.outcome === 'settled')
165
- signalReviewActivity();
144
+ await signalReview(reviewId);
166
145
  const record = await requireVisibleReview(reviewId);
167
146
  if (settled.outcome === 'already_settled' && record.state === 'approved')
168
147
  return terminalConflict(record, 'cancel');
@@ -48,24 +48,19 @@ export function isSettledAssistant(message) {
48
48
  return message.role === 'assistant' && message.stopReason !== 'aborted' && message.stopReason !== 'error';
49
49
  }
50
50
  /** The text a viewer shows as a turn's reply. One prose message is the reply
51
- * verbatim. Otherwise the latest rewrite whose sources are all still in the turn,
52
- * followed by any later prose it does not cover, verbatim. A missing or stale
53
- * rewrite degrades to concatenation, never to a lost answer. */
51
+ * verbatim. Otherwise the latest rewrite, when it covers any prose the viewer
52
+ * holds, followed by the later prose verbatim; earlier sources may be outside the
53
+ * viewer's last messages. Without such a rewrite, the prose is concatenated. */
54
54
  export function turnReplyText(prose, reply) {
55
55
  if (prose.length === 0)
56
56
  return '';
57
57
  if (prose.length === 1)
58
58
  return prose[0].text;
59
- const keys = new Set(prose.map((item) => item.key));
60
- if (reply !== undefined && reply.sources.every((source) => keys.has(source))) {
61
- const covered = new Set(reply.sources);
62
- // Prose up to the last covered message is subsumed by the rewrite; only
63
- // messages after it are appended.
64
- let lastCovered = -1;
65
- prose.forEach((item, index) => { if (covered.has(item.key))
66
- lastCovered = index; });
67
- const tail = prose.slice(lastCovered + 1).map((item) => item.text);
68
- return [reply.text, ...tail].join('\n\n');
69
- }
59
+ const covered = new Set(reply?.sources);
60
+ let lastCovered = -1;
61
+ prose.forEach((item, index) => { if (covered.has(item.key))
62
+ lastCovered = index; });
63
+ if (lastCovered >= 0)
64
+ return [reply.text, ...prose.slice(lastCovered + 1).map((item) => item.text)].join('\n\n');
70
65
  return prose.map((item) => item.text).join('\n\n');
71
66
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/api",
3
- "version": "0.3.706",
3
+ "version": "0.3.708",
4
4
  "description": "Typed crtrd /v1 API contract — DTOs, route builders, the error contract, the CrtrClient, and the command-plugin manifest format. Zero runtime dependencies.",
5
5
  "type": "module",
6
6
  "main": "./dist/api/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/identity",
3
- "version": "0.3.706",
3
+ "version": "0.3.708",
4
4
  "description": "Northlight access-token verification and scope rules",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/plugin",
3
- "version": "0.3.706",
3
+ "version": "0.3.708",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -27,8 +27,8 @@
27
27
  "postpack": "node ../../scripts/pack-minify.mjs postpack packages/crouter-plugin"
28
28
  },
29
29
  "dependencies": {
30
- "@north-light/api": "0.3.706",
31
- "@north-light/identity": "0.3.706"
30
+ "@north-light/api": "0.3.708",
31
+ "@north-light/identity": "0.3.708"
32
32
  },
33
33
  "license": "UNLICENSED",
34
34
  "publishConfig": {