@north-light/cli 0.3.707 → 0.3.709
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.
- package/dist/api/client.d.ts +1 -2
- package/dist/api/client.js +3 -3
- package/dist/api/contract.d.ts +1 -1
- package/dist/api/contract.js +1 -1
- package/dist/api/dto/crons.d.ts +3 -0
- package/dist/api/dto/human.d.ts +9 -6
- package/dist/api/dto/inbox.d.ts +2 -0
- package/dist/api/dto/review-comments.d.ts +12 -35
- package/dist/api/dto/reviews.d.ts +3 -10
- package/dist/api/routes.d.ts +0 -1
- package/dist/api/routes.js +1 -1
- package/dist/builtin-memory/05-kinds/review/companion/00-base.md +2 -2
- package/dist/builtin-memory/crouter-sdk/release-notes.md +6 -0
- package/dist/clients/attach/chrome/canvas-panels.d.ts +1 -1
- package/dist/clients/attach/chrome/canvas-panels.js +1 -1
- package/dist/clients/attach/chrome/inbox-strip.js +1 -1
- package/dist/clients/attach/chrome/roster.js +6 -6
- package/dist/clients/attach/chrome/status-line.d.ts +1 -1
- package/dist/clients/attach/chrome/status-line.js +1 -1
- package/dist/clients/attach/chrome/ticket-panel.js +1 -1
- package/dist/clients/attach/input/capabilities.js +1 -1
- package/dist/clients/attach/input/controller.d.ts +4 -1
- package/dist/clients/attach/input/controller.js +3 -3
- package/dist/clients/attach/input/overlay-owner.d.ts +0 -1
- package/dist/clients/attach/input/overlay-owner.js +1 -1
- package/dist/clients/attach/overlays/graph.d.ts +3 -2
- package/dist/clients/attach/overlays/graph.js +1 -1
- package/dist/clients/attach/render/chat-view.d.ts +2 -0
- package/dist/clients/attach/render/chat-view.js +1 -1
- package/dist/clients/attach/render/doc-links.d.ts +1 -1
- package/dist/clients/attach/session/chrome-refresh.js +1 -1
- package/dist/clients/attach/session/connection.d.ts +10 -9
- package/dist/clients/attach/session/connection.js +1 -1
- package/dist/clients/attach/session/context.d.ts +1 -1
- package/dist/clients/attach/session/document-links.d.ts +1 -1
- package/dist/clients/attach/session/document-links.js +1 -1
- package/dist/clients/attach/session/identity.d.ts +2 -0
- package/dist/clients/attach/session/identity.js +1 -1
- package/dist/clients/attach/session/input-wiring.d.ts +2 -0
- package/dist/clients/attach/session/input-wiring.js +1 -1
- package/dist/clients/attach/session/keys.d.ts +2 -2
- package/dist/clients/attach/session/keys.js +1 -1
- package/dist/clients/attach/session/pane-tag.d.ts +3 -1
- package/dist/clients/attach/session/pane-tag.js +1 -1
- package/dist/clients/attach/session/reconnect.js +1 -1
- package/dist/clients/attach/session/surface-host.d.ts +0 -5
- package/dist/clients/attach/session/surface-host.js +1 -1
- package/dist/clients/attach/session/teardown.d.ts +2 -2
- package/dist/clients/attach/session/teardown.js +9 -7
- package/dist/clients/attach/viewer.d.ts +7 -5
- package/dist/clients/attach/viewer.js +571 -584
- package/dist/clients/editor-roundtrip.js +3 -0
- package/dist/clients/inbox/controller.d.ts +1 -6
- package/dist/clients/inbox/controller.js +1 -1
- package/dist/clients/inbox/dto-adapt.js +1 -1
- package/dist/clients/inbox/tui/page-body.js +1 -1
- package/dist/clients/inbox/tui/render.js +2 -2
- package/dist/clients/open-browser.d.ts +2 -0
- package/dist/clients/open-browser.js +1 -0
- package/dist/clients/surfaces/host.d.ts +0 -6
- package/dist/commands/human/review.js +1 -1
- package/dist/commands/node/wait.js +2 -6
- package/dist/commands/sys/context/admin/shell.js +1 -1
- package/dist/core/broker-client/client.d.ts +6 -3
- package/dist/core/broker-client/client.js +1 -1
- package/dist/core/canvas/crons.d.ts +11 -1
- package/dist/core/canvas/crons.js +14 -14
- package/dist/core/canvas/executions.js +1 -1
- package/dist/core/canvas/schema-pg/025-review-anchors.sql +19 -0
- package/dist/core/canvas/schema-pg/026-cron-deadline-body.sql +9 -0
- package/dist/core/canvas/schema-pg/027-cron-fires.sql +4 -0
- package/dist/core/canvas/schema-version.d.ts +1 -1
- package/dist/core/canvas/schema-version.js +1 -1
- package/dist/core/command.js +5 -5
- package/dist/core/feed/messages.d.ts +5 -0
- package/dist/core/feed/messages.js +5 -5
- package/dist/core/human/page-markdown.js +10 -12
- package/dist/core/human/tickets.js +1 -1
- package/dist/core/human/types.d.ts +4 -6
- package/dist/core/keybindings/attach-control.d.ts +0 -3
- package/dist/core/keybindings/attach-control.js +1 -1
- package/dist/core/keybindings/catalog.d.ts +1 -1
- package/dist/core/keybindings/catalog.js +1 -1
- package/dist/core/review/anchors.d.ts +28 -0
- package/dist/core/review/anchors.js +6 -0
- package/dist/core/review/comments.d.ts +2 -2
- package/dist/core/review/comments.js +7 -8
- package/dist/core/review/companion.d.ts +2 -1
- package/dist/core/review/companion.js +1 -1
- package/dist/core/review/document.d.ts +4 -17
- package/dist/core/review/document.js +1 -2
- package/dist/core/review/fork.js +2 -4
- package/dist/core/review/project.d.ts +1 -1
- package/dist/core/review/project.js +2 -2
- package/dist/core/review/realize.js +1 -1
- package/dist/core/review/stage.d.ts +2 -9
- package/dist/core/review/stage.js +1 -1
- package/dist/core/review/types.d.ts +16 -12
- package/dist/core/review/types.js +1 -1
- package/dist/core/runtime/bearings.js +4 -4
- package/dist/core/runtime/boot-root.js +4 -4
- package/dist/core/runtime/broker-cli.js +3 -3
- package/dist/core/runtime/broker-extension-render.js +1 -1
- package/dist/core/runtime/lifecycle.js +2 -2
- package/dist/core/runtime/revive.js +2 -2
- package/dist/core/runtime/runner/blaxel/client.d.ts +4 -0
- package/dist/core/runtime/runner/blaxel/client.js +1 -1
- package/dist/core/runtime/runner/blaxel/runner.d.ts +2 -3
- package/dist/core/runtime/runner/blaxel/runner.js +3 -3
- package/dist/core/runtime/runner/delete-sandboxes.d.ts +5 -0
- package/dist/core/runtime/runner/delete-sandboxes.js +6 -1
- package/dist/core/runtime/runner/types.d.ts +19 -3
- package/dist/core/runtime/tmux-bindings.js +3 -3
- package/dist/daemon/api/bridge.d.ts +5 -0
- package/dist/daemon/api/bridge.js +3 -3
- package/dist/daemon/api/canvas-host.js +1 -1
- package/dist/daemon/api/document-page.d.ts +12 -1
- package/dist/daemon/api/document-page.js +6 -6
- package/dist/daemon/api/handlers/crons.d.ts +2 -0
- package/dist/daemon/api/handlers/crons.js +1 -1
- package/dist/daemon/api/handlers/inbox.js +1 -1
- package/dist/daemon/api/handlers/nodes.js +1 -1
- package/dist/daemon/api/handlers/review-comments.js +1 -1
- package/dist/daemon/api/handlers/reviews.js +1 -1
- package/dist/daemon/api/map.js +2 -2
- package/dist/daemon/api/operations.js +1 -1
- package/dist/daemon/api/review-page.d.ts +3 -0
- package/dist/daemon/api/review-page.js +13 -0
- package/dist/daemon/broker-memory-cap.d.ts +9 -0
- package/dist/daemon/broker-memory-cap.js +2 -0
- package/dist/daemon/broker-signals/bus.d.ts +1 -1
- package/dist/daemon/broker-signals/bus.js +1 -1
- package/dist/daemon/cron/ended.d.ts +3 -0
- package/dist/daemon/cron/ended.js +2 -2
- package/dist/daemon/cron/lease-recovery.js +1 -1
- package/dist/daemon/cron/machine-fire.d.ts +9 -2
- package/dist/daemon/cron/machine-fire.js +1 -1
- package/dist/daemon/cron/passes.js +1 -1
- package/dist/daemon/cron-run.js +2 -2
- package/dist/daemon/crtrd.js +14 -14
- package/dist/daemon/machine-daemon.js +1 -1
- package/dist/daemon/machine-link/client.js +1 -1
- package/dist/daemon/reconcilers/fault-retry-backstop.js +1 -1
- package/dist/daemon/reconcilers/idle-sandbox.d.ts +1 -1
- package/dist/daemon/reconcilers/idle-sandbox.js +2 -2
- package/dist/daemon/reconcilers/node-lifecycle/remote-wake.js +2 -2
- package/dist/daemon/review/comment-notify.js +2 -2
- package/dist/daemon/review/deliver.d.ts +2 -2
- package/dist/daemon/review/deliver.js +6 -2
- package/dist/daemon/review/finish.js +1 -1
- package/dist/doc-editor/Geist-Variable.woff2 +0 -0
- package/dist/doc-editor/GeistMono-Variable.woff2 +0 -0
- package/dist/doc-editor/editor.css +1 -1
- package/dist/doc-editor/review.css +2 -0
- package/dist/doc-editor/review.js +149 -0
- package/dist/pi-extensions/canvas-review-boundary.js +3 -3
- package/docs/sdk/release-notes.md +6 -0
- package/package.json +13 -4
- package/packages/crouter-api/dist/api/client.js +0 -3
- package/packages/crouter-api/dist/api/contract.js +1 -1
- package/packages/crouter-api/dist/api/routes.js +0 -1
- package/packages/crouter-api/dist/clients/attach/chrome/canvas-panels.js +3 -3
- package/packages/crouter-api/dist/clients/attach/chrome/inbox-strip.js +5 -5
- package/packages/crouter-api/dist/clients/attach/chrome/roster.js +17 -28
- package/packages/crouter-api/dist/clients/attach/chrome/status-line.js +2 -7
- package/packages/crouter-api/dist/clients/attach/chrome/ticket-panel.js +1 -1
- package/packages/crouter-api/dist/clients/attach/input/capabilities.js +2 -1
- package/packages/crouter-api/dist/clients/attach/input/controller.js +17 -3
- package/packages/crouter-api/dist/clients/attach/input/overlay-owner.js +0 -7
- package/packages/crouter-api/dist/clients/attach/overlays/graph.js +4 -3
- package/packages/crouter-api/dist/clients/attach/render/chat-view.js +9 -0
- package/packages/crouter-api/dist/clients/attach/session/chrome-refresh.js +6 -3
- package/packages/crouter-api/dist/clients/attach/session/connection.js +53 -53
- package/packages/crouter-api/dist/clients/attach/session/document-links.js +1 -1
- package/packages/crouter-api/dist/clients/attach/session/identity.js +1 -0
- package/packages/crouter-api/dist/clients/attach/session/input-wiring.js +4 -3
- package/packages/crouter-api/dist/clients/attach/session/keys.js +11 -5
- package/packages/crouter-api/dist/clients/attach/session/pane-tag.js +7 -1
- package/packages/crouter-api/dist/clients/attach/session/reconnect.js +3 -3
- package/packages/crouter-api/dist/clients/attach/session/surface-host.js +0 -17
- package/packages/crouter-api/dist/clients/attach/session/teardown.js +7 -4
- package/packages/crouter-api/dist/clients/attach/viewer.js +77 -67
- package/packages/crouter-api/dist/clients/{inbox/review/roundtrip.js → editor-roundtrip.js} +1 -1
- package/packages/crouter-api/dist/clients/inbox/controller.js +12 -31
- package/packages/crouter-api/dist/clients/inbox/dto-adapt.js +1 -0
- package/packages/crouter-api/dist/clients/inbox/tui/page-body.js +0 -7
- package/packages/crouter-api/dist/clients/inbox/tui/render.js +0 -7
- package/packages/crouter-api/dist/clients/open-browser.js +6 -0
- package/packages/crouter-api/dist/commands/human/review.js +17 -18
- package/packages/crouter-api/dist/commands/node/wait.js +2 -10
- package/packages/crouter-api/dist/commands/sys/context/admin/shell.js +1 -1
- package/packages/crouter-api/dist/core/broker-client/client.js +20 -10
- package/packages/crouter-api/dist/core/canvas/crons.js +26 -10
- package/packages/crouter-api/dist/core/canvas/executions.js +7 -2
- package/packages/crouter-api/dist/core/canvas/schema-version.js +1 -1
- package/packages/crouter-api/dist/core/command.js +3 -0
- package/packages/crouter-api/dist/core/feed/messages.js +15 -0
- package/packages/crouter-api/dist/core/human/page-markdown.js +2 -6
- package/packages/crouter-api/dist/core/human/tickets.js +2 -11
- package/packages/crouter-api/dist/core/keybindings/attach-control.js +0 -1
- package/packages/crouter-api/dist/core/keybindings/catalog.js +1 -3
- package/packages/crouter-api/dist/core/review/anchors.js +91 -0
- package/packages/crouter-api/dist/core/review/comments.js +27 -46
- package/packages/crouter-api/dist/core/review/companion.js +5 -9
- package/packages/crouter-api/dist/core/review/document.js +17 -89
- package/packages/crouter-api/dist/core/review/project.js +2 -1
- package/packages/crouter-api/dist/core/review/types.js +2 -2
- package/packages/crouter-api/dist/core/runtime/bearings.js +2 -2
- package/packages/crouter-api/dist/core/runtime/lifecycle.js +3 -0
- package/packages/crouter-api/dist/core/runtime/revive.js +5 -25
- package/packages/crouter-api/dist/core/runtime/runner/blaxel/client.js +15 -8
- package/packages/crouter-api/dist/core/runtime/runner/blaxel/runner.js +60 -19
- package/packages/crouter-api/dist/core/runtime/runner/delete-sandboxes.js +18 -2
- package/packages/crouter-api/dist/core/runtime/tmux-bindings.js +0 -5
- package/packages/crouter-api/dist/daemon/api/map.js +2 -6
- package/packages/crouter-api/dist/daemon/api/operations.js +2 -2
- package/packages/crouter-api/dist/daemon/broker-signals/bus.js +1 -1
- package/packages/crouter-api/dist/daemon/cron/ended.js +22 -11
- package/packages/crouter-api/dist/daemon/cron/machine-fire.js +69 -6
- package/packages/crouter-api/dist/daemon/reconcilers/node-lifecycle/remote-wake.js +2 -2
- package/packages/crouter-api/dist/daemon/review/deliver.js +4 -3
- package/packages/crouter-api/dist/daemon/review/finish.js +26 -47
- package/packages/crouter-api/package.json +1 -1
- package/packages/crouter-identity/package.json +1 -1
- package/packages/crouter-plugin/package.json +3 -3
- package/runtime.lock.json +1740 -505
- package/dist/clients/attach/overlays/file-review.d.ts +0 -10
- package/dist/clients/attach/overlays/file-review.js +0 -2
- package/dist/clients/inbox/review/anchors.d.ts +0 -41
- package/dist/clients/inbox/review/anchors.js +0 -1
- package/dist/clients/inbox/review/comments-client.d.ts +0 -74
- package/dist/clients/inbox/review/comments-client.js +0 -1
- package/dist/clients/inbox/review/companion-pane.d.ts +0 -47
- package/dist/clients/inbox/review/companion-pane.js +0 -1
- package/dist/clients/inbox/review/document-surface.d.ts +0 -212
- package/dist/clients/inbox/review/document-surface.js +0 -2
- package/dist/clients/inbox/review/frame.d.ts +0 -57
- package/dist/clients/inbox/review/frame.js +0 -1
- package/dist/clients/inbox/review/keys.d.ts +0 -69
- package/dist/clients/inbox/review/keys.js +0 -1
- package/dist/clients/inbox/review/launch.d.ts +0 -16
- package/dist/clients/inbox/review/launch.js +0 -1
- package/dist/clients/inbox/review/live-source.d.ts +0 -24
- package/dist/clients/inbox/review/live-source.js +0 -1
- package/dist/clients/inbox/review/nvim.d.ts +0 -15
- package/dist/clients/inbox/review/nvim.js +0 -1
- package/dist/clients/inbox/review/remap.d.ts +0 -51
- package/dist/clients/inbox/review/remap.js +0 -1
- package/dist/clients/inbox/review/review-client.d.ts +0 -43
- package/dist/clients/inbox/review/review-client.js +0 -1
- package/dist/clients/inbox/review/roundtrip.js +0 -3
- package/dist/clients/inbox/review/state.d.ts +0 -153
- package/dist/clients/inbox/review/state.js +0 -4
- package/dist/clients/inbox/review-adapter.d.ts +0 -17
- package/dist/clients/inbox/review-adapter.js +0 -1
- package/dist/core/review/remap.d.ts +0 -24
- package/dist/core/review/remap.js +0 -19
- package/dist/core/review/signal.d.ts +0 -5
- package/dist/core/review/signal.js +0 -1
- package/dist/core/runtime/starting-screen.d.ts +0 -12
- package/dist/core/runtime/starting-screen.js +0 -9
- package/packages/crouter-api/dist/clients/attach/overlays/file-review.js +0 -146
- package/packages/crouter-api/dist/clients/inbox/review/anchors.js +0 -89
- package/packages/crouter-api/dist/clients/inbox/review/comments-client.js +0 -103
- package/packages/crouter-api/dist/clients/inbox/review/companion-pane.js +0 -109
- package/packages/crouter-api/dist/clients/inbox/review/document-surface.js +0 -1268
- package/packages/crouter-api/dist/clients/inbox/review/frame.js +0 -309
- package/packages/crouter-api/dist/clients/inbox/review/keys.js +0 -133
- package/packages/crouter-api/dist/clients/inbox/review/launch.js +0 -170
- package/packages/crouter-api/dist/clients/inbox/review/live-source.js +0 -160
- package/packages/crouter-api/dist/clients/inbox/review/nvim.js +0 -43
- package/packages/crouter-api/dist/clients/inbox/review/remap.js +0 -157
- package/packages/crouter-api/dist/clients/inbox/review/review-client.js +0 -125
- package/packages/crouter-api/dist/clients/inbox/review/state.js +0 -315
- package/packages/crouter-api/dist/clients/inbox/review-adapter.js +0 -43
- package/packages/crouter-api/dist/core/review/signal.js +0 -12
- package/packages/crouter-api/dist/core/termrender/code-doc.js +0 -92
- /package/dist/clients/{inbox/review/roundtrip.d.ts → editor-roundtrip.d.ts} +0 -0
|
@@ -44,7 +44,6 @@ export function reconnectShouldGiveUp(row) {
|
|
|
44
44
|
return row === null || (row.status === 'done' && row.final_report != null);
|
|
45
45
|
}
|
|
46
46
|
export class BrokerClient extends EventEmitter {
|
|
47
|
-
nodeId;
|
|
48
47
|
transport;
|
|
49
48
|
closeEmitted = false;
|
|
50
49
|
/** Tracks live connect↔close state so {@link request} can fail fast on a
|
|
@@ -61,22 +60,31 @@ export class BrokerClient extends EventEmitter {
|
|
|
61
60
|
* Resolved by the matching `data` frame / rejected by the matching `error`
|
|
62
61
|
* frame in {@link onFrame}, the request's timeout, or transport teardown. */
|
|
63
62
|
pending = new Map();
|
|
63
|
+
/** `nodeId` is undefined only for a viewer whose node is still being created: it holds no transport until {@link bindTransport}, so
|
|
64
|
+
* every send is a no-op and every request rejects until then. */
|
|
64
65
|
constructor(nodeId, options = {}) {
|
|
65
66
|
super();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
const transport = options.transport ?? (nodeId === undefined ? undefined : new SocketTransport(nodeId));
|
|
68
|
+
if (transport !== undefined)
|
|
69
|
+
this.bindTransport(transport);
|
|
70
|
+
}
|
|
71
|
+
/** Wire the transport once the node it reaches is known. */
|
|
72
|
+
bindTransport(transport) {
|
|
73
|
+
if (this.transport !== undefined)
|
|
74
|
+
throw new Error('BrokerClient already has a transport');
|
|
75
|
+
this.transport = transport;
|
|
76
|
+
transport.on('connect', () => {
|
|
69
77
|
this.closeEmitted = false;
|
|
70
78
|
this.connected = true;
|
|
71
79
|
this.lastTransportError = undefined;
|
|
72
80
|
this.emit('connect');
|
|
73
81
|
});
|
|
74
|
-
|
|
75
|
-
|
|
82
|
+
transport.on('frame', (frame) => this.onFrame(frame));
|
|
83
|
+
transport.on('error', (err) => {
|
|
76
84
|
this.lastTransportError = err.message;
|
|
77
85
|
this.emitError(err);
|
|
78
86
|
});
|
|
79
|
-
|
|
87
|
+
transport.on('close', () => this.onClose());
|
|
80
88
|
}
|
|
81
89
|
/** Issue a correlated read-op and resolve with the broker's `data` reply (or
|
|
82
90
|
* reject on the correlated `error`, a timeout, or transport teardown). Mints
|
|
@@ -112,22 +120,24 @@ export class BrokerClient extends EventEmitter {
|
|
|
112
120
|
* {@link BrokerUnavailableError} when the target has no reachable broker)
|
|
113
121
|
* on failure. Idempotent guard is the caller's job — call once. */
|
|
114
122
|
connect() {
|
|
115
|
-
this.transport
|
|
123
|
+
this.transport?.connect();
|
|
116
124
|
}
|
|
117
125
|
/** Re-establish the connection after a broker exit (a yield→revive cycle),
|
|
118
126
|
* to the SAME target. Resolves on `connect` (caller re-sends `hello`);
|
|
119
127
|
* rejects on a retryable dial failure. */
|
|
120
128
|
redial(options) {
|
|
129
|
+
if (this.transport === undefined)
|
|
130
|
+
return Promise.reject(new Error('no node to redial yet'));
|
|
121
131
|
return this.transport.redial(options);
|
|
122
132
|
}
|
|
123
133
|
/** Encode + send one client→broker frame. No-op on a dead/absent
|
|
124
134
|
* connection; never throws. */
|
|
125
135
|
send(frame) {
|
|
126
|
-
this.transport
|
|
136
|
+
this.transport?.send(frame);
|
|
127
137
|
}
|
|
128
138
|
/** Detach: tear down the transport. `close` fires → the caller tears down. */
|
|
129
139
|
close() {
|
|
130
|
-
this.transport
|
|
140
|
+
this.transport?.destroy();
|
|
131
141
|
}
|
|
132
142
|
onFrame(frame) {
|
|
133
143
|
// Correlated replies (read-ops + dequeue) are consumed by the pending-by-id
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
// serve the daemon-owned run executor in src/daemon/cron-run.ts.
|
|
22
22
|
import { withCanvasWrite, openDb } from './db.js';
|
|
23
23
|
import { capturePidIdentities, identitiesMatch, killProcessGroup } from './pid.js';
|
|
24
|
-
import { isProfilePaused } from '../profiles/manifest.js';
|
|
25
24
|
import { stopAppProcess } from '../spaces/process.js';
|
|
26
25
|
import { emitEvent } from '../events/emit.js';
|
|
27
26
|
import { personId } from './person.js';
|
|
27
|
+
import { deleteSandboxOfEndedNode } from '../runtime/runner/delete-sandboxes.js';
|
|
28
28
|
/** Ring bound for `cron_runs`: recordCronRun prunes each cron's history to
|
|
29
29
|
* its most recent this-many rows. */
|
|
30
30
|
export const CRON_RUN_RING = 20;
|
|
@@ -59,6 +59,8 @@ function cronFrom(r) {
|
|
|
59
59
|
expires_at: r['expires_at'] ?? null,
|
|
60
60
|
anchor_node: r['anchor_node'] ?? null,
|
|
61
61
|
cancel_on_wake: Number(r['cancel_on_wake']) !== 0,
|
|
62
|
+
deadline_body: r['deadline_body'] ?? null,
|
|
63
|
+
fires: Number(r['fires'] ?? 0),
|
|
62
64
|
cwd: r['cwd'],
|
|
63
65
|
env_json: r['env_json'] ?? null,
|
|
64
66
|
profile: r['profile'] ?? null,
|
|
@@ -198,9 +200,9 @@ async function insertCron(db, spec) {
|
|
|
198
200
|
await db.prepare(`INSERT INTO crons (
|
|
199
201
|
cron_id, name, created_by, grantee, sub, grant_id, scopes_json, origin_run_id, isolated, command, fire_at, recur, tz, expires_at,
|
|
200
202
|
anchor_node, cancel_on_wake, cwd, env_json, profile, scope,
|
|
201
|
-
run_timeout_s, overlap, on_output, sink, tier, created, updated, armed_from_exec
|
|
202
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
203
|
-
.run(spec.cron_id, spec.name, spec.created_by, spec.grantee ?? 'app:terminal', spec.sub ?? personId(), spec.grant_id ?? null, spec.scopes == null ? null : JSON.stringify(spec.scopes), spec.origin_run_id ?? null, spec.isolated ? 1 : 0, spec.command, spec.fire_at, spec.recur, spec.tz, spec.expires_at, spec.anchor_node, spec.cancel_on_wake ? 1 : 0, spec.cwd, spec.env_json, spec.profile, spec.scope, spec.run_timeout_s, spec.overlap, spec.on_output, spec.sink, spec.tier, now, now, spec.armed_from_exec ? 1 : 0);
|
|
203
|
+
run_timeout_s, overlap, on_output, sink, tier, created, updated, armed_from_exec, deadline_body
|
|
204
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
205
|
+
.run(spec.cron_id, spec.name, spec.created_by, spec.grantee ?? 'app:terminal', spec.sub ?? personId(), spec.grant_id ?? null, spec.scopes == null ? null : JSON.stringify(spec.scopes), spec.origin_run_id ?? null, spec.isolated ? 1 : 0, spec.command, spec.fire_at, spec.recur, spec.tz, spec.expires_at, spec.anchor_node, spec.cancel_on_wake ? 1 : 0, spec.cwd, spec.env_json, spec.profile, spec.scope, spec.run_timeout_s, spec.overlap, spec.on_output, spec.sink, spec.tier, now, now, spec.armed_from_exec ? 1 : 0, spec.deadline_body ?? null);
|
|
204
206
|
}
|
|
205
207
|
/** SELECT one cron by id. */
|
|
206
208
|
export async function getCron(cron_id) {
|
|
@@ -242,6 +244,8 @@ export async function cancelCron(cron_id, options) {
|
|
|
242
244
|
if (cron.run_state === 'running' && options?.preserveRunningProcess !== true)
|
|
243
245
|
killLeasedCronRun(cron);
|
|
244
246
|
await db.prepare('DELETE FROM crons WHERE cron_id = ?').run(cron_id);
|
|
247
|
+
if (cron.anchor_node !== null)
|
|
248
|
+
deleteSandboxOfEndedNode(cron.anchor_node);
|
|
245
249
|
return true;
|
|
246
250
|
});
|
|
247
251
|
}
|
|
@@ -294,11 +298,21 @@ export async function globalizeCronsForProfile(profileId) {
|
|
|
294
298
|
return ids;
|
|
295
299
|
});
|
|
296
300
|
}
|
|
301
|
+
/** A hosted cron ends after this many fires; no flag raises it (NL-1110). */
|
|
302
|
+
export const HOSTED_CRON_MAX_FIRES = 64;
|
|
303
|
+
/** Idle crons that have used all `max` fires; the due pass ends them whether paused or not (NL-1110). */
|
|
304
|
+
export async function cappedIdleCrons(max) {
|
|
305
|
+
return (await (await openDb()).prepare(`SELECT * FROM crons WHERE fires >= ? AND run_state = 'idle' ORDER BY cron_id`)
|
|
306
|
+
.all(max)).map(cronFrom);
|
|
307
|
+
}
|
|
297
308
|
/** DELETE one cron by id — one-shot consumption after its run settles.
|
|
298
309
|
* Returns whether a live row was removed, so a consumer racing an explicit
|
|
299
310
|
* cancel can no-op instead of double-settling. */
|
|
300
311
|
export async function consumeCron(cron_id) {
|
|
301
|
-
|
|
312
|
+
const gone = await (await openDb()).prepare('DELETE FROM crons WHERE cron_id = ? RETURNING anchor_node').get(cron_id);
|
|
313
|
+
if (gone !== undefined && gone.anchor_node !== null)
|
|
314
|
+
deleteSandboxOfEndedNode(gone.anchor_node);
|
|
315
|
+
return gone !== undefined;
|
|
302
316
|
}
|
|
303
317
|
/** UPDATE `state` (active|paused). Returns whether a row changed — pausing an
|
|
304
318
|
* already-paused cron (or a gone one) reports `false`. Pausing does NOT kill
|
|
@@ -376,7 +390,7 @@ export async function dueClockCrons(nowIso) {
|
|
|
376
390
|
return (await (await openDb()).prepare(`SELECT * FROM crons
|
|
377
391
|
WHERE state = 'active' AND run_state = 'idle' AND fire_at <= ?
|
|
378
392
|
ORDER BY fire_at, created, cron_id`)
|
|
379
|
-
.all(nowIso)).map(cronFrom)
|
|
393
|
+
.all(nowIso)).map(cronFrom);
|
|
380
394
|
}
|
|
381
395
|
/** Atomically acquire the idle run lease: flips `run_state` to 'running' and
|
|
382
396
|
* records lease/pid metadata, but ONLY if the row is still idle (the
|
|
@@ -390,12 +404,14 @@ export async function dueClockCrons(nowIso) {
|
|
|
390
404
|
*
|
|
391
405
|
* `outOfBand` stamps the lease as a `cron run` (manual verification) so the
|
|
392
406
|
* overlap pass leaves it alone — see `dueOverlapCrons`. */
|
|
393
|
-
export async function acquireCronRunLease(cron_id, leaseOwner, startedAtIso, outOfBand, executionId = null) {
|
|
407
|
+
export async function acquireCronRunLease(cron_id, leaseOwner, startedAtIso, outOfBand, executionId = null, maxFires = null) {
|
|
408
|
+
// With `maxFires`, the claim also counts the fire and is refused once the cron has used them all, in the same UPDATE.
|
|
409
|
+
const counted = maxFires !== null;
|
|
394
410
|
const res = await (await openDb()).prepare(`UPDATE crons
|
|
395
411
|
SET run_state = 'running', run_started_at = ?, run_pid = NULL, run_pid_identity = NULL,
|
|
396
|
-
run_lease_owner = ?, run_out_of_band = ?, run_execution_id = ?, updated = ?
|
|
397
|
-
WHERE cron_id = ? AND run_state = 'idle'`)
|
|
398
|
-
.run(startedAtIso, leaseOwner, outOfBand ? 1 : 0, executionId, new Date().toISOString(), cron_id);
|
|
412
|
+
run_lease_owner = ?, run_out_of_band = ?, run_execution_id = ?, updated = ?${counted ? ', fires = fires + 1' : ''}
|
|
413
|
+
WHERE cron_id = ? AND run_state = 'idle'${counted ? ' AND fires < ?' : ''}`)
|
|
414
|
+
.run(startedAtIso, leaseOwner, outOfBand ? 1 : 0, executionId, new Date().toISOString(), cron_id, ...(counted ? [maxFires] : []));
|
|
399
415
|
return Number(res.changes) > 0;
|
|
400
416
|
}
|
|
401
417
|
/** Attach the launcher's pid only to the run that claimed this lease. */
|
|
@@ -5,6 +5,7 @@ import { existsSync, readFileSync } from 'node:fs';
|
|
|
5
5
|
import { LAUNCHER_SOCKET } from '../../launcher/spec.js';
|
|
6
6
|
import { revokeNodeTokens } from './node-tokens.js';
|
|
7
7
|
import { clearPendingParkIn } from '../../daemon/park-pending.js';
|
|
8
|
+
import { deleteSandboxOfEndedNode } from '../runtime/runner/delete-sandboxes.js';
|
|
8
9
|
function now() {
|
|
9
10
|
return new Date().toISOString();
|
|
10
11
|
}
|
|
@@ -150,8 +151,10 @@ export async function endExecution(executionId, input) {
|
|
|
150
151
|
const at = now();
|
|
151
152
|
const ended = await db.prepare("UPDATE executions SET state = 'exited', ended_at = ?, exited_at = ?, exit_reason = COALESCE(exit_reason, ?) WHERE execution_id = ? AND state != 'exited' RETURNING node_id").get(at, at, input.reason, executionId);
|
|
152
153
|
await revokeNodeTokens(db, 'broker_process_id', executionId, at);
|
|
153
|
-
if (ended !== undefined)
|
|
154
|
+
if (ended !== undefined) {
|
|
154
155
|
await clearPendingParkIn(db, ended.node_id);
|
|
156
|
+
deleteSandboxOfEndedNode(ended.node_id);
|
|
157
|
+
}
|
|
155
158
|
return ended !== undefined;
|
|
156
159
|
});
|
|
157
160
|
}
|
|
@@ -176,8 +179,10 @@ export async function endLiveExecution(nodeId, input) {
|
|
|
176
179
|
const at = now();
|
|
177
180
|
const ended = await db.prepare("UPDATE executions SET state = 'exited', ended_at = ?, exited_at = ?, exit_reason = COALESCE(exit_reason, ?) WHERE node_id = ? AND state != 'exited'").run(at, at, input.reason, nodeId);
|
|
178
181
|
await revokeNodeTokens(db, 'node_id', nodeId, at);
|
|
179
|
-
if (Number(ended.changes) > 0)
|
|
182
|
+
if (Number(ended.changes) > 0) {
|
|
180
183
|
await clearPendingParkIn(db, nodeId);
|
|
184
|
+
deleteSandboxOfEndedNode(nodeId);
|
|
185
|
+
}
|
|
181
186
|
return Number(ended.changes) === 1;
|
|
182
187
|
});
|
|
183
188
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
/** The canvas schema version this build supports: the number of the highest delta in `schema-pg/` (the baseline
|
|
7
7
|
* `schema-pg.sql` is version 1). `scripts/install-runtime.mjs` reads this module from a candidate generation to refuse
|
|
8
8
|
* one below the live database's `schema_min_reader`. */
|
|
9
|
-
export const CANVAS_SCHEMA_VERSION =
|
|
9
|
+
export const CANVAS_SCHEMA_VERSION = 27;
|
|
10
10
|
/** The Postgres schema holding the canvas tables: `CRTR_DATABASE_SCHEMA` (`crtr` in the cloud deploy). Unset or empty
|
|
11
11
|
* means the role's own search_path (`public` on a Mac and on a VM). A name that is not a plain identifier is an error:
|
|
12
12
|
* it is put in a `search_path` connection option. */
|
|
@@ -456,6 +456,9 @@ export async function parseArgv(params, tokens, options) {
|
|
|
456
456
|
throw parseArgvError('unknown_flag', `unknown flag: --${flagName}`, `--${flagName}`, undefined, 'Use --<flag-name> for declared flags only. Run -h for the schema.');
|
|
457
457
|
}
|
|
458
458
|
const key = flagNameToKey(flagName);
|
|
459
|
+
if (provided.has(key) && flagDef.type !== 'bool' && flagDef.repeatable !== true) {
|
|
460
|
+
throw parseArgvError('bad_invocation', `--${flagName} given twice; it takes one value`, `--${flagName}`, flagName, `Pass --${flagName} once.`);
|
|
461
|
+
}
|
|
459
462
|
provided.add(key);
|
|
460
463
|
if (flagDef.type === 'bool') {
|
|
461
464
|
if (inlineValue !== undefined) {
|
|
@@ -165,6 +165,21 @@ export async function consumeDeadlineOnWake(nodeId) {
|
|
|
165
165
|
}
|
|
166
166
|
});
|
|
167
167
|
}
|
|
168
|
+
/** A node deadline fell due: in one write, delete its row and queue its body to the anchor as urgent wake mail, which the
|
|
169
|
+
* lifecycle tick delivers by waking the node wherever it runs. No process runs. A row already gone (a wake consumed it, or
|
|
170
|
+
* a re-arm replaced it) delivers nothing. */
|
|
171
|
+
export async function deliverDueDeadline(cron) {
|
|
172
|
+
if (cron.anchor_node === null || cron.deadline_body === null)
|
|
173
|
+
throw new Error(`cron ${cron.cron_id} is not a node deadline`);
|
|
174
|
+
const anchor = cron.anchor_node;
|
|
175
|
+
const body = cron.deadline_body;
|
|
176
|
+
await withCanvasWrite(async (db) => {
|
|
177
|
+
const deleted = await db.prepare("DELETE FROM crons WHERE cron_id = ? AND state = 'active' AND run_state = 'idle'").run(cron.cron_id);
|
|
178
|
+
if (Number(deleted.changes) === 0)
|
|
179
|
+
return;
|
|
180
|
+
await insertNodeNotice(db, anchor, { body, label: 'deadline reached', tier: 'urgent', wake: 1 });
|
|
181
|
+
});
|
|
182
|
+
}
|
|
168
183
|
/** Queue one runtime notice to a node's inbox inside the caller's write transaction (no sender). */
|
|
169
184
|
export async function queueNodeNotice(db, nodeId, notice) {
|
|
170
185
|
const queued = await insertNodeNotice(db, nodeId, notice);
|
|
@@ -191,12 +191,8 @@ function block(node, context) {
|
|
|
191
191
|
const contents = () => flow(node.children, context);
|
|
192
192
|
switch (node.tag) {
|
|
193
193
|
case 'Page': return contents();
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
const body = contents();
|
|
197
|
-
const heading = typeof title === 'string' && title.trim() !== '' ? `## ${markdownText(title.trim())}` : '';
|
|
198
|
-
return [heading, body].filter((part) => part !== '').join('\n\n');
|
|
199
|
-
}
|
|
194
|
+
// A step's title is the question's own heading again, so only its body projects.
|
|
195
|
+
case 'Step': return contents();
|
|
200
196
|
case 'p': return cleanInline(inline(node.children, context));
|
|
201
197
|
case 'h1':
|
|
202
198
|
case 'h2':
|
|
@@ -7,18 +7,9 @@ import { isBlobRequestPath, readRequestText } from './request-files.js';
|
|
|
7
7
|
import { validatePageResponses, validatePartialPageResponses } from './page-schema.js';
|
|
8
8
|
import { signalInboxActivity } from './root.js';
|
|
9
9
|
import { createPageRequest, getRequestByDirectory, presentationDir, publishPageRevisionTo, revisePageRequest, writeProgress as writeRequestProgress } from './requests.js';
|
|
10
|
-
const feedbackCommentSchema = z.object({ id: z.string().min(1),
|
|
10
|
+
const feedbackCommentSchema = z.object({ id: z.string().min(1), quote: z.string().default(''), comment: z.string().min(1), createdAt: z.string().min(1), resolved: z.boolean().default(false), detached: z.boolean().optional() }).passthrough();
|
|
11
11
|
const iso = z.string().datetime({ offset: true });
|
|
12
|
-
const feedbackSchema = z.object({ file: z.string().min(1).refine(isAbsolute, 'file must be absolute').refine((file) => resolve(file) === file, 'file must be canonical'), submitted: z.literal(true), approved: z.boolean(), comments: z.array(feedbackCommentSchema), submittedAt: iso, savedAt: iso, reviewId: z.string().optional(), changed: z.boolean().optional(), baselineSha256: z.string().optional(), approvedSha256: z.string().optional(), companionNodeId: z.string().optional(), commentsTotal: z.number().int().nonnegative().optional(), commentsUnresolved: z.number().int().nonnegative().optional() }).strict()
|
|
13
|
-
result.comments.forEach((comment, index) => {
|
|
14
|
-
if (comment.endLine < comment.line)
|
|
15
|
-
ctx.addIssue({ code: 'custom', message: 'endLine must be >= line', path: ['comments', index, 'endLine'] });
|
|
16
|
-
if ((comment.colStart === undefined) !== (comment.colEnd === undefined))
|
|
17
|
-
ctx.addIssue({ code: 'custom', message: 'columns must be supplied together', path: ['comments', index] });
|
|
18
|
-
if (comment.line === comment.endLine && comment.colStart !== undefined && comment.colEnd !== undefined && comment.colEnd <= comment.colStart)
|
|
19
|
-
ctx.addIssue({ code: 'custom', message: 'colEnd must exceed colStart', path: ['comments', index, 'colEnd'] });
|
|
20
|
-
});
|
|
21
|
-
});
|
|
12
|
+
const feedbackSchema = z.object({ file: z.string().min(1).refine(isAbsolute, 'file must be absolute').refine((file) => resolve(file) === file, 'file must be canonical'), submitted: z.literal(true), approved: z.boolean(), comments: z.array(feedbackCommentSchema), submittedAt: iso, savedAt: iso, document: z.object({ id: z.string(), name: z.string(), base_revision: z.string().nullable(), approved_revision: z.string().nullable() }).nullable().optional(), reviewId: z.string().optional(), changed: z.boolean().optional(), baselineSha256: z.string().optional(), approvedSha256: z.string().optional(), companionNodeId: z.string().optional(), commentsTotal: z.number().int().nonnegative().optional(), commentsUnresolved: z.number().int().nonnegative().optional() }).strict();
|
|
22
13
|
const slotResponseSchema = z.record(z.string(), z.unknown());
|
|
23
14
|
const pageResultSchema = z.object({ schema: z.literal('crtr.page-response/v1'), kind: z.literal('page'), responses: z.record(z.string(), slotResponseSchema), summary: z.string(), completedAt: iso, actor: z.string().optional() }).strict();
|
|
24
15
|
const pageProgressSchema = z.object({ kind: z.literal('page'), responses: z.record(z.string(), slotResponseSchema), savedAt: iso }).strict();
|
|
@@ -8,7 +8,6 @@ export const ATTACH_CONTROL_BINDINGS = [
|
|
|
8
8
|
{ menuId: 'crtr.tmux.menu.attach.model-ladder.next', actionId: 'crtr.attach.model-ladder.next' },
|
|
9
9
|
{ menuId: 'crtr.tmux.menu.attach.model-ladder.previous', actionId: 'crtr.attach.model-ladder.previous' },
|
|
10
10
|
{ menuId: 'crtr.tmux.menu.attach.command.inspect', actionId: 'crtr.attach.command.inspect' },
|
|
11
|
-
{ menuId: 'crtr.tmux.menu.attach.file-review', actionId: 'crtr.attach.file-review' },
|
|
12
11
|
{ menuId: 'crtr.tmux.menu.attach.profile-files', actionId: 'crtr.attach.profile-files' },
|
|
13
12
|
{ menuId: 'crtr.tmux.menu.attach.search', actionId: 'crtr.attach.search' },
|
|
14
13
|
{ menuId: 'crtr.tmux.menu.attach.whip', actionId: 'crtr.attach.whip' },
|
|
@@ -22,7 +22,7 @@ function menuEntry(action, name, description, defaults, contexts, globalDefaults
|
|
|
22
22
|
}
|
|
23
23
|
function attachEntry(menuId, actionId, name, description,
|
|
24
24
|
// Empty hides the row from the attach submenu while the action stays bindable
|
|
25
|
-
// and reachable by its direct gesture
|
|
25
|
+
// and reachable by its direct gesture.
|
|
26
26
|
menuDefaults, directDefaults) {
|
|
27
27
|
return [
|
|
28
28
|
b(menuId, 'Attach', name, description, menuDefaults, 'tmux-menu-selector', ['tmux.menu.attach'], undefined, { field: 'menu', pairedId: actionId }),
|
|
@@ -48,7 +48,6 @@ export const BINDING_CATALOG = Object.freeze([
|
|
|
48
48
|
...menuEntry('detach', 'Demote and close viewer', 'Demote the focused node and close its viewer; its broker keeps running off-screen.', ['shift+d'], ['tmux.menu']),
|
|
49
49
|
...menuEntry('close-subtree', 'Close subtree', 'Close the focused node and its subtree.', ['x'], ['tmux.menu']),
|
|
50
50
|
...menuEntry('background-bash', 'Background running bash', 'Hand the focused node’s running bash command to its background job system.', ['b'], ['tmux.menu']),
|
|
51
|
-
...menuEntry('file-review', 'Review a file', 'Open a line-anchored review of a file named in the transcript.', ['v'], ['tmux.menu']),
|
|
52
51
|
...menuEntry('pin', 'Pin conversation', 'Pin or unpin this conversation in the canvas navigator.', ['p'], ['tmux.menu']),
|
|
53
52
|
...menuEntry('show', 'Inspect node', 'Open the focused node’s inspection menu.', ['i'], ['tmux.menu']),
|
|
54
53
|
...menuEntry('view-settings', 'Display settings', 'Open the viewer display-settings menu.', ['z'], ['tmux.menu']),
|
|
@@ -86,7 +85,6 @@ export const BINDING_CATALOG = Object.freeze([
|
|
|
86
85
|
...attachEntry('crtr.tmux.menu.attach.model-ladder.next', 'crtr.attach.model-ladder.next', 'Next model', 'Move to the next model ladder rung.', [']'], ['alt+m']),
|
|
87
86
|
...attachEntry('crtr.tmux.menu.attach.model-ladder.previous', 'crtr.attach.model-ladder.previous', 'Previous model', 'Move to the previous model ladder rung.', ['['], ['alt+shift+m']),
|
|
88
87
|
...attachEntry('crtr.tmux.menu.attach.command.inspect', 'crtr.attach.command.inspect', 'Inspect loaded command', 'Open the loaded slash command’s expanded prompt.', ['h'], ['alt+shift+h']),
|
|
89
|
-
...attachEntry('crtr.tmux.menu.attach.file-review', 'crtr.attach.file-review', 'Review a file', 'Open a line-anchored review of a file named in the transcript.', [], ['alt+shift+r']),
|
|
90
88
|
...attachEntry('crtr.tmux.menu.attach.profile-files', 'crtr.attach.profile-files', 'Search profile files', 'Fuzzy-match path segments across the node family’s working directories, their context directories (files), profile projects and the profile’s own directory; Ctrl+Y copies a selected path.', ['f'], ['ctrl+f']),
|
|
91
89
|
...attachEntry('crtr.tmux.menu.attach.search', 'crtr.attach.search', 'Search transcript', 'Search the transcript as it is currently displayed — folded tool output is not searched until it is unfolded.', ['/'], ['alt+/']),
|
|
92
90
|
...attachEntry('crtr.tmux.menu.attach.reload-viewer', 'crtr.attach.reload-viewer', 'Reload viewer', 'Restart this viewer in place on the installed release.', [], []),
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { unified } from 'unified';
|
|
2
|
+
import remarkParse from 'remark-parse';
|
|
3
|
+
import remarkGfm from 'remark-gfm';
|
|
4
|
+
import { ANCHOR_CONTEXT_MAX, COMMENT_QUOTE_MAX, ReviewOperationError } from './types.js';
|
|
5
|
+
const parser = unified().use(remarkParse).use(remarkGfm);
|
|
6
|
+
const BLOCK_JOIN = new Set(['root', 'blockquote', 'footnoteDefinition']);
|
|
7
|
+
const LINE_JOIN = new Set(['list', 'table', 'tableRow']);
|
|
8
|
+
function collapse(text) {
|
|
9
|
+
return text.replace(/\s+/g, ' ').trim();
|
|
10
|
+
}
|
|
11
|
+
function render(node) {
|
|
12
|
+
if (node.type === 'text' || node.type === 'inlineCode' || node.type === 'code')
|
|
13
|
+
return node.value ?? '';
|
|
14
|
+
if (node.type === 'break')
|
|
15
|
+
return '\n';
|
|
16
|
+
const kids = node.children ?? [];
|
|
17
|
+
const sep = BLOCK_JOIN.has(node.type) ? '\n\n' : LINE_JOIN.has(node.type) ? '\n' : '';
|
|
18
|
+
const parts = kids.map(render);
|
|
19
|
+
if (sep === '' && kids.some((kid) => kid.type === 'paragraph' || kid.type === 'list' || kid.type === 'listItem'))
|
|
20
|
+
return parts.join('\n');
|
|
21
|
+
return parts.join(sep);
|
|
22
|
+
}
|
|
23
|
+
/** The text a reader sees: markdown syntax removed, blocks separated, whitespace collapsed. */
|
|
24
|
+
export function renderedText(markdown) {
|
|
25
|
+
return collapse(render(parser.parse(markdown)));
|
|
26
|
+
}
|
|
27
|
+
export function normalizeAnchor(anchor) {
|
|
28
|
+
const quote = collapse(anchor.quote);
|
|
29
|
+
const violations = [];
|
|
30
|
+
if (quote === '')
|
|
31
|
+
violations.push('quote must not be empty');
|
|
32
|
+
if (quote.length > COMMENT_QUOTE_MAX)
|
|
33
|
+
violations.push(`quote exceeds ${COMMENT_QUOTE_MAX} characters`);
|
|
34
|
+
const offset = anchor.offset ?? 0;
|
|
35
|
+
if (!Number.isSafeInteger(offset) || offset < 0)
|
|
36
|
+
violations.push('offset must be a non-negative integer');
|
|
37
|
+
if (violations.length > 0)
|
|
38
|
+
throw new ReviewOperationError('invalid_anchor', 'comment anchor is invalid', { violations });
|
|
39
|
+
return {
|
|
40
|
+
quote,
|
|
41
|
+
prefix: collapse(anchor.prefix ?? '').slice(-ANCHOR_CONTEXT_MAX),
|
|
42
|
+
suffix: collapse(anchor.suffix ?? '').slice(0, ANCHOR_CONTEXT_MAX),
|
|
43
|
+
offset,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function commonSuffix(a, b) {
|
|
47
|
+
let n = 0;
|
|
48
|
+
while (n < a.length && n < b.length && a[a.length - 1 - n] === b[b.length - 1 - n])
|
|
49
|
+
n += 1;
|
|
50
|
+
return n;
|
|
51
|
+
}
|
|
52
|
+
function commonPrefix(a, b) {
|
|
53
|
+
let n = 0;
|
|
54
|
+
while (n < a.length && n < b.length && a[n] === b[n])
|
|
55
|
+
n += 1;
|
|
56
|
+
return n;
|
|
57
|
+
}
|
|
58
|
+
/** Find an anchor in the current rendered text: every exact quote match, best prefix+suffix agreement, then nearest offset. Null = detached. */
|
|
59
|
+
export function resolveAnchor(text, anchor) {
|
|
60
|
+
let best = null;
|
|
61
|
+
for (let at = text.indexOf(anchor.quote); at !== -1; at = text.indexOf(anchor.quote, at + 1)) {
|
|
62
|
+
const score = commonSuffix(text.slice(Math.max(0, at - anchor.prefix.length), at), anchor.prefix)
|
|
63
|
+
+ commonPrefix(text.slice(at + anchor.quote.length, at + anchor.quote.length + anchor.suffix.length), anchor.suffix);
|
|
64
|
+
const distance = Math.abs(at - anchor.offset);
|
|
65
|
+
if (best === null || score > best.score || (score === best.score && distance < best.distance))
|
|
66
|
+
best = { start: at, score, distance };
|
|
67
|
+
}
|
|
68
|
+
return best === null ? null : { start: best.start, end: best.start + anchor.quote.length };
|
|
69
|
+
}
|
|
70
|
+
/** Occurrences of a quote with 32 characters of context each, for a caller that must disambiguate. */
|
|
71
|
+
export function quoteOccurrences(text, quote) {
|
|
72
|
+
const out = [];
|
|
73
|
+
for (let at = text.indexOf(quote); at !== -1; at = text.indexOf(quote, at + 1)) {
|
|
74
|
+
out.push({ offset: at, prefix: text.slice(Math.max(0, at - ANCHOR_CONTEXT_MAX), at), suffix: text.slice(at + quote.length, at + quote.length + ANCHOR_CONTEXT_MAX) });
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
/** Validate a new anchor against the current document and fill context the caller left out. */
|
|
79
|
+
export function anchorInDocument(markdown, input) {
|
|
80
|
+
const anchor = normalizeAnchor(input);
|
|
81
|
+
const text = renderedText(markdown);
|
|
82
|
+
const found = quoteOccurrences(text, anchor.quote);
|
|
83
|
+
if (found.length === 0)
|
|
84
|
+
throw new ReviewOperationError('quote_not_found', 'the quoted text does not occur in the current document', { quote: anchor.quote });
|
|
85
|
+
if (found.length > 1 && input.prefix === undefined && input.suffix === undefined && input.offset === undefined) {
|
|
86
|
+
throw new ReviewOperationError('invalid_anchor', 'the quoted text occurs more than once; pass prefix or suffix', { occurrences: found });
|
|
87
|
+
}
|
|
88
|
+
if (input.prefix === undefined && input.suffix === undefined)
|
|
89
|
+
return { ...anchor, prefix: found[0].prefix, suffix: found[0].suffix, offset: found[0].offset };
|
|
90
|
+
return anchor;
|
|
91
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto';
|
|
2
|
-
import { withCanvasWrite, openDb } from '../canvas/db.js';
|
|
2
|
+
import { afterCommit, withCanvasWrite, openDb } from '../canvas/db.js';
|
|
3
3
|
import { nowIso } from '../fs-utils.js';
|
|
4
|
-
import {
|
|
5
|
-
import { COMMENT_EVENTS_PAGE_DEFAULT, COMMENT_EVENTS_PAGE_MAX,
|
|
4
|
+
import { brokerSignalBus } from '../../daemon/broker-signals/bus.js';
|
|
5
|
+
import { COMMENT_EVENTS_PAGE_DEFAULT, COMMENT_EVENTS_PAGE_MAX, COMMENT_TEXT_MAX, LIVE_COMMENTS_MAX, ReviewOperationError, } from './types.js';
|
|
6
6
|
function commentFromRow(row) {
|
|
7
7
|
return {
|
|
8
8
|
comment_id: row.comment_id,
|
|
@@ -11,15 +11,11 @@ function commentFromRow(row) {
|
|
|
11
11
|
revision: row.revision,
|
|
12
12
|
text: row.text,
|
|
13
13
|
anchor: {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
...(row.anchor_quote === null ? {} : { quote: row.anchor_quote }),
|
|
14
|
+
quote: row.anchor_quote,
|
|
15
|
+
prefix: row.anchor_prefix,
|
|
16
|
+
suffix: row.anchor_suffix,
|
|
17
|
+
offset: Number(row.anchor_offset),
|
|
19
18
|
},
|
|
20
|
-
anchor_state: row.anchor_state,
|
|
21
|
-
anchor_line_text: row.anchor_line_text,
|
|
22
|
-
anchor_doc_hash: row.anchor_doc_hash,
|
|
23
19
|
author: { kind: row.author_kind, node_id: row.author_node_id },
|
|
24
20
|
updated_by: { kind: row.updated_by_kind, node_id: row.updated_by_node_id },
|
|
25
21
|
created_at: row.created_at,
|
|
@@ -66,17 +62,6 @@ function trimText(text) {
|
|
|
66
62
|
}
|
|
67
63
|
return trimmed;
|
|
68
64
|
}
|
|
69
|
-
function truncateUtf8(text, maxBytes) {
|
|
70
|
-
if (Buffer.byteLength(text, 'utf8') <= maxBytes)
|
|
71
|
-
return text;
|
|
72
|
-
const marker = '… [truncated]';
|
|
73
|
-
const markerBytes = Buffer.byteLength(marker, 'utf8');
|
|
74
|
-
const bytes = Buffer.from(text, 'utf8');
|
|
75
|
-
let end = Math.max(0, maxBytes - markerBytes);
|
|
76
|
-
while (end > 0 && (bytes[end] & 0xc0) === 0x80)
|
|
77
|
-
end -= 1;
|
|
78
|
-
return `${bytes.subarray(0, end).toString('utf8')}${marker}`;
|
|
79
|
-
}
|
|
80
65
|
async function getStoredComment(db, commentIdValue) {
|
|
81
66
|
return await db.prepare('SELECT * FROM review_comments WHERE comment_id = ?').get(commentIdValue) ?? null;
|
|
82
67
|
}
|
|
@@ -120,10 +105,10 @@ async function updateComment(db, row, fields, actor, at) {
|
|
|
120
105
|
`).run(fields.status ?? row.status, revision, fields.text ?? row.text, actor.kind, actor.node_id, at, fields.resolved_at === undefined ? row.resolved_at : fields.resolved_at, fields.deleted_at === undefined ? row.deleted_at : fields.deleted_at, row.comment_id);
|
|
121
106
|
return { ...row, ...fields, revision, updated_by_kind: actor.kind, updated_by_node_id: actor.node_id, updated_at: at };
|
|
122
107
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
108
|
+
/** Tell every process listening on `crtr_signal` (and this one, at commit) that a review changed. Call inside the mutating transaction: a rollback sends nothing. */
|
|
109
|
+
export async function signalReviewChange(db, reviewId) {
|
|
110
|
+
await db.prepare('SELECT pg_notify(?, ?)').get('crtr_signal', `review:${reviewId}`);
|
|
111
|
+
afterCommit(() => brokerSignalBus.markSignal('review', reviewId));
|
|
127
112
|
}
|
|
128
113
|
export async function createComment(args) {
|
|
129
114
|
const result = await withCanvasWrite(async (db) => {
|
|
@@ -136,19 +121,17 @@ export async function createComment(args) {
|
|
|
136
121
|
});
|
|
137
122
|
}
|
|
138
123
|
const text = trimText(args.text);
|
|
139
|
-
const lineText = truncateUtf8(args.line_text, COMMENT_LINE_TEXT_MAX);
|
|
140
124
|
const at = nowIso();
|
|
141
125
|
let id = commentId();
|
|
142
126
|
while (await getStoredComment(db, id) !== null)
|
|
143
127
|
id = commentId();
|
|
144
128
|
const inserted = await db.prepare(`
|
|
145
129
|
INSERT INTO review_comments
|
|
146
|
-
(comment_id, review_id, status, revision, text,
|
|
147
|
-
anchor_col_start, anchor_col_end, anchor_quote, anchor_line_text, anchor_doc_hash, anchor_state,
|
|
130
|
+
(comment_id, review_id, status, revision, text, anchor_quote, anchor_prefix, anchor_suffix, anchor_offset,
|
|
148
131
|
author_kind, author_node_id, updated_by_kind, updated_by_node_id, created_at,
|
|
149
132
|
updated_at, resolved_at, deleted_at, created_seq)
|
|
150
|
-
VALUES (?, ?, 'open', 1, ?, ?, ?, ?, ?, ?, ?, ?,
|
|
151
|
-
`).run(id, args.review_id, text, args.anchor.
|
|
133
|
+
VALUES (?, ?, 'open', 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, NULL, 0)
|
|
134
|
+
`).run(id, args.review_id, text, args.anchor.quote, args.anchor.prefix, args.anchor.suffix, args.anchor.offset, args.actor.kind, args.actor.node_id, args.actor.kind, args.actor.node_id, at, at);
|
|
152
135
|
if (inserted.changes !== 1)
|
|
153
136
|
throw new Error('failed to insert review comment');
|
|
154
137
|
const row = (await getStoredComment(db, id));
|
|
@@ -158,12 +141,12 @@ export async function createComment(args) {
|
|
|
158
141
|
actor: args.actor,
|
|
159
142
|
operation_id: args.operation_id,
|
|
160
143
|
at,
|
|
161
|
-
payload: { text, anchor: args.anchor
|
|
144
|
+
payload: { text, anchor: args.anchor },
|
|
162
145
|
});
|
|
163
146
|
await db.prepare('UPDATE review_comments SET created_seq = ? WHERE comment_id = ?').run(seq, id);
|
|
147
|
+
await signalReviewChange(db, args.review_id);
|
|
164
148
|
return { comment: commentFromRow({ ...row, created_seq: seq }), changed: true };
|
|
165
149
|
});
|
|
166
|
-
signalReviewActivity();
|
|
167
150
|
return result;
|
|
168
151
|
}
|
|
169
152
|
export async function editComment(commentIdValue, args) {
|
|
@@ -191,9 +174,10 @@ export async function editComment(commentIdValue, args) {
|
|
|
191
174
|
anchor: commentFromRow(updated).anchor,
|
|
192
175
|
},
|
|
193
176
|
});
|
|
177
|
+
await signalReviewChange(db, updated.review_id);
|
|
194
178
|
return { comment: commentFromRow(updated), changed: true };
|
|
195
179
|
});
|
|
196
|
-
return
|
|
180
|
+
return result;
|
|
197
181
|
}
|
|
198
182
|
async function transitionComment(commentIdValue, args, target, kind) {
|
|
199
183
|
const result = await withCanvasWrite(async (db) => {
|
|
@@ -227,9 +211,10 @@ async function transitionComment(commentIdValue, args, target, kind) {
|
|
|
227
211
|
anchor: commentFromRow(updated).anchor,
|
|
228
212
|
},
|
|
229
213
|
});
|
|
214
|
+
await signalReviewChange(db, updated.review_id);
|
|
230
215
|
return { comment: commentFromRow(updated), changed: true };
|
|
231
216
|
});
|
|
232
|
-
return
|
|
217
|
+
return result;
|
|
233
218
|
}
|
|
234
219
|
export async function resolveComment(commentIdValue, args) {
|
|
235
220
|
return await transitionComment(commentIdValue, args, 'resolved', 'resolved');
|
|
@@ -244,10 +229,10 @@ export async function listComments(reviewId, opts) {
|
|
|
244
229
|
const db = await openDb();
|
|
245
230
|
const status = opts?.status;
|
|
246
231
|
const rows = status === undefined
|
|
247
|
-
? await db.prepare("SELECT * FROM review_comments WHERE review_id = ? AND status != 'deleted' ORDER BY
|
|
232
|
+
? await db.prepare("SELECT * FROM review_comments WHERE review_id = ? AND status != 'deleted' ORDER BY created_seq").all(reviewId)
|
|
248
233
|
: status === 'all'
|
|
249
|
-
? await db.prepare('SELECT * FROM review_comments WHERE review_id = ? ORDER BY
|
|
250
|
-
: await db.prepare('SELECT * FROM review_comments WHERE review_id = ? AND status = ? ORDER BY
|
|
234
|
+
? await db.prepare('SELECT * FROM review_comments WHERE review_id = ? ORDER BY created_seq').all(reviewId)
|
|
235
|
+
: await db.prepare('SELECT * FROM review_comments WHERE review_id = ? AND status = ? ORDER BY created_seq').all(reviewId, status);
|
|
251
236
|
return rows.map(commentFromRow);
|
|
252
237
|
}
|
|
253
238
|
export async function getComment(commentIdValue) {
|
|
@@ -266,17 +251,13 @@ export async function listReviewEvents(reviewId, opts) {
|
|
|
266
251
|
return { events, next_since_seq: events.length === 0 ? since : events[events.length - 1].seq };
|
|
267
252
|
}
|
|
268
253
|
export async function snapshotCommentsLocked(db, reviewId) {
|
|
269
|
-
const rows = await db.prepare("SELECT * FROM review_comments WHERE review_id = ? AND status != 'deleted' ORDER BY
|
|
254
|
+
const rows = await db.prepare("SELECT * FROM review_comments WHERE review_id = ? AND status != 'deleted' ORDER BY created_seq").all(reviewId);
|
|
270
255
|
const comments = rows.map((row) => ({
|
|
271
256
|
id: row.comment_id,
|
|
272
|
-
|
|
273
|
-
endLine: row.anchor_end_line,
|
|
274
|
-
...(row.anchor_quote === null ? {} : { quote: row.anchor_quote }),
|
|
275
|
-
...(row.anchor_col_start === null ? {} : { colStart: row.anchor_col_start }),
|
|
276
|
-
...(row.anchor_col_end === null ? {} : { colEnd: row.anchor_col_end }),
|
|
277
|
-
lineText: row.anchor_line_text,
|
|
257
|
+
quote: row.anchor_quote,
|
|
278
258
|
comment: row.text,
|
|
279
259
|
createdAt: row.created_at,
|
|
260
|
+
resolved: row.status === 'resolved',
|
|
280
261
|
}));
|
|
281
262
|
return { comments, total: rows.length, unresolved: rows.filter((row) => row.status === 'open').length };
|
|
282
263
|
}
|
|
@@ -291,6 +272,6 @@ export async function appendDeliveryEvent(args) {
|
|
|
291
272
|
(review_id, comment_id, kind, state_change, revision_after, actor_kind, actor_node_id, at, operation_id, payload)
|
|
292
273
|
VALUES (?, ?, ?, 0, NULL, 'system', NULL, ?, ?, ?)
|
|
293
274
|
`).run(args.review_id, args.comment_id, args.kind, nowIso(), args.operation_id, json(args.payload));
|
|
275
|
+
await signalReviewChange(db, args.review_id);
|
|
294
276
|
});
|
|
295
|
-
signalReviewActivity();
|
|
296
277
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { conversationIdFromPath, conversationStore, ConversationNotFoundError } from '../conversation-store/index.js';
|
|
3
|
-
import {
|
|
3
|
+
import { isAbsolute } from 'node:path';
|
|
4
4
|
import { BrokerClient } from '../broker-client/index.js';
|
|
5
5
|
import { deleteNode, getNode } from '../canvas/index.js';
|
|
6
6
|
import { expandModelCandidates } from '../model-routes.js';
|
|
@@ -12,7 +12,6 @@ import { spawnNode } from '../runtime/nodes.js';
|
|
|
12
12
|
import { SessionManager } from '../runtime/broker-sdk.js';
|
|
13
13
|
import { isReviewBoundary } from '../runtime/session-visibility.js';
|
|
14
14
|
import { forkNodeLedger } from '../runtime/ledger.js';
|
|
15
|
-
import { isBlobRequestPath } from '../human/request-files.js';
|
|
16
15
|
import { ReviewOperationError } from './types.js';
|
|
17
16
|
const EXACT_MODEL_SPEC = /^[^/\s:]+\/[^/\s:]+:(?:off|minimal|low|medium|high|xhigh|max)$/;
|
|
18
17
|
const BIND_POLL_MS = 100;
|
|
@@ -134,11 +133,8 @@ export async function captureOrigin(originNodeId, deps = {}) {
|
|
|
134
133
|
}
|
|
135
134
|
/** Create the ordinary, promptless companion node. Realization owns its launch. */
|
|
136
135
|
export async function spawnReviewCompanion(spec) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (!isAbsolute(spec.branchFile) || !(isAbsolute(spec.targetFile) || isBlobRequestPath(spec.targetFile))) {
|
|
140
|
-
throw new Error('review companion requires an absolute branch path and an absolute or request-blob target');
|
|
141
|
-
}
|
|
136
|
+
if (!isAbsolute(spec.branchFile))
|
|
137
|
+
throw new Error('review companion requires an absolute branch path');
|
|
142
138
|
if (!EXACT_MODEL_SPEC.test(spec.modelSpec)) {
|
|
143
139
|
throw new Error('review companion requires an exact model spec');
|
|
144
140
|
}
|
|
@@ -167,9 +163,9 @@ export async function spawnReviewCompanion(spec) {
|
|
|
167
163
|
review_id: spec.reviewId,
|
|
168
164
|
origin_node_id: spec.originNodeId,
|
|
169
165
|
branch_file: spec.branchFile,
|
|
170
|
-
target_file: spec.
|
|
166
|
+
target_file: spec.documentName,
|
|
171
167
|
},
|
|
172
|
-
name: `review ${
|
|
168
|
+
name: `review ${spec.documentName}`,
|
|
173
169
|
launch,
|
|
174
170
|
});
|
|
175
171
|
try {
|