@north-light/cli 0.3.711 → 0.3.713
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/clients/attach/input/controller.d.ts +6 -0
- package/dist/clients/attach/input/controller.js +3 -3
- package/dist/clients/attach/input/local-files.d.ts +16 -0
- package/dist/clients/attach/input/local-files.js +6 -0
- package/dist/clients/attach/session/editor-frame.d.ts +2 -2
- package/dist/clients/attach/session/editor-frame.js +1 -1
- package/dist/clients/attach/viewer.js +406 -402
- package/dist/commands/node/bash.js +1 -1
- package/dist/core/bash-guard.d.ts +10 -0
- package/dist/core/bash-guard.js +4 -4
- package/dist/core/broker-client/client.d.ts +2 -2
- package/dist/core/conversation-store/row-store.js +1 -1
- package/dist/core/graph/documents.d.ts +5 -5
- package/dist/core/graph/documents.js +9 -9
- package/dist/core/graph/kinds/custom.js +2 -2
- package/dist/core/graph/kinds/document.js +4 -4
- package/dist/core/graph/kinds/environment.js +2 -2
- package/dist/core/graph/kinds/job.js +2 -2
- package/dist/core/graph/kinds/kind.d.ts +9 -1
- package/dist/core/graph/kinds/live-read.d.ts +4 -2
- package/dist/core/graph/kinds/live-read.js +1 -1
- package/dist/core/graph/kinds/node.js +5 -5
- package/dist/core/graph/kinds/owner.js +2 -2
- package/dist/core/graph/reader.js +3 -3
- package/dist/core/import/load/run.js +2 -2
- package/dist/core/permissions/evaluator.js +2 -2
- package/dist/core/runtime/bearings-render.d.ts +3 -0
- package/dist/core/runtime/bearings-render.js +7 -7
- package/dist/core/runtime/bearings.js +5 -5
- package/dist/core/runtime/broker/frame-dispatch.js +1 -1
- package/dist/core/runtime/broker/frame-read.d.ts +5 -1
- package/dist/core/runtime/broker/frame-read.js +1 -1
- package/dist/core/runtime/broker-protocol.d.ts +37 -2
- package/dist/daemon/api/handlers/broker-ops.js +1 -1
- package/dist/daemon/api/handlers/llm.js +3 -3
- package/dist/daemon/api/handlers/objects.js +3 -3
- package/dist/daemon/api/handlers/reviews.js +1 -1
- package/dist/daemon/api/map.d.ts +6 -0
- package/dist/daemon/api/map.js +1 -1
- package/dist/daemon/machine-daemon.js +1 -1
- package/dist/daemon/reconcilers/node-lifecycle/tick.js +1 -1
- package/dist/pi-extensions/canvas-inbox-watcher.js +2 -2
- package/docs/ci-runner.md +4 -4
- package/package.json +3 -3
- package/packages/crouter-api/dist/clients/attach/input/controller.js +43 -12
- package/packages/crouter-api/dist/clients/attach/input/local-files.js +97 -0
- package/packages/crouter-api/dist/clients/attach/session/editor-frame.js +27 -8
- package/packages/crouter-api/dist/commands/node/bash.js +2 -2
- package/packages/crouter-api/dist/core/bash-guard.js +1 -1
- package/packages/crouter-api/dist/core/conversation-store/row-store.js +1 -1
- package/packages/crouter-api/dist/core/graph/documents.js +12 -24
- package/packages/crouter-api/dist/core/graph/kinds/custom.js +1 -3
- package/packages/crouter-api/dist/core/graph/kinds/document.js +8 -25
- package/packages/crouter-api/dist/core/graph/kinds/environment.js +1 -3
- package/packages/crouter-api/dist/core/graph/kinds/job.js +1 -3
- package/packages/crouter-api/dist/core/graph/kinds/node.js +1 -3
- package/packages/crouter-api/dist/core/graph/kinds/owner.js +1 -3
- package/packages/crouter-api/dist/core/graph/reader.js +7 -1
- package/packages/crouter-api/dist/core/permissions/evaluator.js +12 -6
- package/packages/crouter-api/dist/core/runtime/bearings-render.js +11 -0
- package/packages/crouter-api/dist/core/runtime/bearings.js +6 -2
- package/packages/crouter-api/dist/daemon/api/handlers/broker-ops.js +5 -5
- package/packages/crouter-api/dist/daemon/api/map.js +1 -1
- package/packages/crouter-api/dist/{clients/attach/chrome/git-info.js → shared/git-status.js} +5 -5
- 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 +14 -14
- package/packages/crouter-api/dist/core/graph/kinds/live-read.js +0 -11
- /package/dist/{clients/attach/chrome/git-info.d.ts → shared/git-status.d.ts} +0 -0
- /package/dist/{clients/attach/chrome/git-info.js → shared/git-status.js} +0 -0
|
@@ -12,6 +12,7 @@ import { dispatchSlashCommand, isSlashCommand } from '../slash/dispatch.js';
|
|
|
12
12
|
import { viewerOperationForFrame } from './capabilities.js';
|
|
13
13
|
import { readClipboardImage, writeClipboardImageToFile } from './clipboard-image.js';
|
|
14
14
|
import { InputOverlayOwner } from './overlay-owner.js';
|
|
15
|
+
import { attachLocalFiles, hasLocalPaths } from './local-files.js';
|
|
15
16
|
import { announceFallbackEditor, NO_EDITOR_MESSAGE, resolveEditor } from '../../../core/editor-resolver.js';
|
|
16
17
|
const DOUBLE_ESCAPE_MS = 500;
|
|
17
18
|
const MAX_FRAME_BYTES = BROKER_READ_CAPS.maxLineBytes - 4 * 1024 * 1024;
|
|
@@ -257,26 +258,56 @@ export class InputController {
|
|
|
257
258
|
if (delivery !== 'steer' && delivery !== 'prompt')
|
|
258
259
|
return;
|
|
259
260
|
const expanded = this.expandImagePlaceholders(classification.kind === 'slash' ? text : classification.text);
|
|
260
|
-
|
|
261
|
+
const sent = () => {
|
|
262
|
+
this.recordCompletionUse(text);
|
|
263
|
+
this.editor.addToHistory(classification.trimmed);
|
|
264
|
+
this.clearPastedImages();
|
|
265
|
+
};
|
|
266
|
+
const deliver = (final) => {
|
|
267
|
+
if (!this.emitDrive(delivery === 'steer' ? { type: 'steer', text: final } : { type: 'prompt', text: final }))
|
|
268
|
+
return false;
|
|
269
|
+
if (delivery === 'prompt')
|
|
270
|
+
this.hooks.onMessageSent?.(final, true);
|
|
271
|
+
this.hooks.onPromptSent?.();
|
|
272
|
+
return true;
|
|
273
|
+
};
|
|
274
|
+
this.sendMessage(expanded, text, classification.kind !== 'slash', sent, deliver);
|
|
275
|
+
}
|
|
276
|
+
/** Send one message through `deliver`, with `sent` run and the editor cleared
|
|
277
|
+
* exactly once it is accepted. A message naming files on this machine (when
|
|
278
|
+
* `files` allows it and a broker can take them) clears the editor first, sends
|
|
279
|
+
* each file to the node, then delivers the rewritten text; a refused delivery
|
|
280
|
+
* puts the typed text back. */
|
|
281
|
+
sendMessage(expanded, typed, files, sent, deliver) {
|
|
282
|
+
const request = this.hooks.onRequest;
|
|
283
|
+
if (!files || request === undefined || !hasLocalPaths(expanded)) {
|
|
284
|
+
if (!deliver(expanded))
|
|
285
|
+
return;
|
|
286
|
+
sent();
|
|
287
|
+
this.editor.setText('');
|
|
261
288
|
return;
|
|
262
|
-
|
|
263
|
-
|
|
289
|
+
}
|
|
290
|
+
sent();
|
|
264
291
|
this.editor.setText('');
|
|
265
|
-
this.
|
|
266
|
-
|
|
267
|
-
this.
|
|
268
|
-
|
|
292
|
+
this.tui.requestRender();
|
|
293
|
+
void attachLocalFiles(expanded, request).then((final) => {
|
|
294
|
+
if (!deliver(final) && this.editor.getText().trim() === '') {
|
|
295
|
+
this.editor.setText(typed);
|
|
296
|
+
this.tui.requestRender();
|
|
297
|
+
}
|
|
298
|
+
});
|
|
269
299
|
}
|
|
270
300
|
handleFollowUp() {
|
|
271
301
|
const text = this.editor.getText();
|
|
272
302
|
const trimmed = text.trim();
|
|
273
303
|
if (!trimmed)
|
|
274
304
|
return;
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
305
|
+
const expanded = this.expandImagePlaceholders(text);
|
|
306
|
+
const sent = () => {
|
|
307
|
+
this.editor.addToHistory(trimmed);
|
|
308
|
+
this.clearPastedImages();
|
|
309
|
+
};
|
|
310
|
+
this.sendMessage(expanded, text, true, sent, (final) => this.emitDrive({ type: 'follow_up', text: final }));
|
|
280
311
|
}
|
|
281
312
|
async handleDequeue() {
|
|
282
313
|
if (this.refuseStarting())
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// input/local-files.ts — file paths in a message the person sends. A path they
|
|
2
|
+
// typed or pasted (or a pasted image's temp file) names a file on the viewer's
|
|
3
|
+
// machine, which the node may not share. Before the message leaves, each such
|
|
4
|
+
// file is sent to the node's broker (`upload_file`) and its path in the text is
|
|
5
|
+
// replaced with the path the node can read. Nothing here blocks the send: a file
|
|
6
|
+
// that is missing, too large or fails to upload stays as typed and the message
|
|
7
|
+
// gains a `<runtime>` note saying why.
|
|
8
|
+
import { closeSync, constants, fstatSync, openSync, readFileSync } from 'node:fs';
|
|
9
|
+
import { homedir } from 'node:os';
|
|
10
|
+
/** Base64 grows the bytes by a third and the frame must fit the broker's read cap, so a file above this stays on the viewer. */
|
|
11
|
+
export const LOCAL_FILE_MAX_BYTES = 16 * 1024 * 1024;
|
|
12
|
+
/** An absolute or `~/` path, with shell-escaped spaces (`a\ b`) as a terminal drag-and-drop writes them. */
|
|
13
|
+
const PATH_TOKEN = /(?<![\w/~.:-])(~?\/(?:\\ |[^\s'"`<>()[\]{}])+)/g;
|
|
14
|
+
/** Every path token in `text`, with sentence punctuation trimmed and escapes undone. Exported for tests. */
|
|
15
|
+
export function findLocalPaths(text) {
|
|
16
|
+
const out = [];
|
|
17
|
+
for (const m of text.matchAll(PATH_TOKEN)) {
|
|
18
|
+
const raw = m[1].replace(/[.,;:!?]+$/, '');
|
|
19
|
+
if (raw === '/' || raw === '~/' || raw.startsWith('//'))
|
|
20
|
+
continue;
|
|
21
|
+
const unescaped = raw.replace(/\\ /g, ' ');
|
|
22
|
+
const path = unescaped.startsWith('~/') ? `${homedir()}${unescaped.slice(1)}` : unescaped;
|
|
23
|
+
out.push({ start: m.index, end: m.index + raw.length, raw, path });
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
function readLocal(path) {
|
|
28
|
+
let fd;
|
|
29
|
+
try {
|
|
30
|
+
fd = openSync(path, constants.O_RDONLY);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return { kind: 'missing' };
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const stat = fstatSync(fd);
|
|
37
|
+
if (!stat.isFile())
|
|
38
|
+
return { kind: 'not-file' };
|
|
39
|
+
if (stat.size > LOCAL_FILE_MAX_BYTES)
|
|
40
|
+
return { kind: 'too-large', size: stat.size };
|
|
41
|
+
return { kind: 'file', bytes: readFileSync(fd) };
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
closeSync(fd);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function mib(bytes) {
|
|
48
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MiB`;
|
|
49
|
+
}
|
|
50
|
+
/** True when `text` names any path, so the caller can keep the plain synchronous send otherwise. */
|
|
51
|
+
export function hasLocalPaths(text) {
|
|
52
|
+
return findLocalPaths(text).length > 0;
|
|
53
|
+
}
|
|
54
|
+
/** Send each local file `text` names to the node and rewrite its path; append a `<runtime>` note for every file that could not go. */
|
|
55
|
+
export async function attachLocalFiles(text, request) {
|
|
56
|
+
const matches = findLocalPaths(text);
|
|
57
|
+
if (matches.length === 0)
|
|
58
|
+
return text;
|
|
59
|
+
const notes = [];
|
|
60
|
+
const sent = new Map();
|
|
61
|
+
const replaced = [];
|
|
62
|
+
for (const match of matches) {
|
|
63
|
+
const done = sent.get(match.path);
|
|
64
|
+
if (done !== undefined) {
|
|
65
|
+
replaced.push({ match, to: done });
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const read = readLocal(match.path);
|
|
69
|
+
if (read.kind === 'not-file')
|
|
70
|
+
continue;
|
|
71
|
+
if (read.kind === 'missing') {
|
|
72
|
+
notes.push(`${match.raw} does not exist on the person's machine, so it was not sent to you.`);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (read.kind === 'too-large') {
|
|
76
|
+
notes.push(`file ${match.raw} is too large (${mib(read.size)}; the limit is ${mib(LOCAL_FILE_MAX_BYTES)}), not uploaded.`);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
const reply = await request({ type: 'upload_file', source_path: match.path, data: read.bytes.toString('base64') });
|
|
81
|
+
if (reply.kind !== 'upload_file')
|
|
82
|
+
throw new Error('unexpected reply');
|
|
83
|
+
sent.set(match.path, reply.path);
|
|
84
|
+
replaced.push({ match, to: reply.path });
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
notes.push(`file ${match.raw} could not be uploaded (${error instanceof Error ? error.message : String(error)}).`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
let out = text;
|
|
91
|
+
for (const { match, to } of replaced.reverse()) {
|
|
92
|
+
if (to === match.path && match.raw === to)
|
|
93
|
+
continue;
|
|
94
|
+
out = `${out.slice(0, match.start)}${to}${out.slice(match.end)}`;
|
|
95
|
+
}
|
|
96
|
+
return notes.length === 0 ? out : `${out}\n\n<runtime>\n${notes.join('\n')}\n</runtime>`;
|
|
97
|
+
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { basename } from 'node:path';
|
|
9
9
|
import { modeIcon, personaLabel } from '../../../core/canvas/labels.js';
|
|
10
10
|
import { colorChipStyle, defaultTitleStyle, thinkingBorderColor, thinkingTitleStyle } from '../input/titled-editor.js';
|
|
11
|
-
import {
|
|
11
|
+
import { loadProfileManifest } from '../../../core/profiles/manifest.js';
|
|
12
12
|
/** Nerd Font terminal glyph marks a one-shot node; resident nodes need no
|
|
13
13
|
* lifecycle glyph because they persist by default. */
|
|
14
14
|
const TERMINAL_NODE_ICON = '\uf489';
|
|
@@ -62,7 +62,7 @@ export function displayEditorTitle(sessionName, identity) {
|
|
|
62
62
|
* and paints every frame-attached adornment — border hue, title chip, context
|
|
63
63
|
* badge, and git context. */
|
|
64
64
|
export function createEditorChrome(ctx, hooks) {
|
|
65
|
-
const { meta, tui, pal, editor } = ctx;
|
|
65
|
+
const { meta, tui, pal, editor, socket } = ctx;
|
|
66
66
|
// Shell/bash mode: the editor text leads with `!`. Tracks pi's interactive
|
|
67
67
|
// `isBashMode`, which recolors the editor border green as a visual cue (#7).
|
|
68
68
|
// Three levels: 0 = off, 1 = `!` (output goes to the agent's context), 2 = `!!`
|
|
@@ -72,11 +72,24 @@ export function createEditorChrome(ctx, hooks) {
|
|
|
72
72
|
// `/color` override for the name chip — null means the default (thinking-
|
|
73
73
|
// tracking) chip. Bash mode still wins: the green frame is a live safety cue.
|
|
74
74
|
let chipColor = null;
|
|
75
|
-
|
|
75
|
+
// The badge names the node's profile; a node without one (or whose manifest
|
|
76
|
+
// will not load here) falls back to the folder it runs in.
|
|
77
|
+
const profileLabel = (() => {
|
|
78
|
+
const id = meta.profile_id;
|
|
79
|
+
if (!id)
|
|
80
|
+
return basename(meta.cwd) || meta.cwd;
|
|
81
|
+
try {
|
|
82
|
+
return loadProfileManifest(id).manifest.name;
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return id;
|
|
86
|
+
}
|
|
87
|
+
})();
|
|
88
|
+
const syncContextBadge = () => {
|
|
76
89
|
const identity = hooks.nodeIdentity();
|
|
77
90
|
const lifecycle = identity?.lifecycle === 'terminal' ? `${TERMINAL_NODE_ICON} ` : '';
|
|
78
91
|
const persona = identity ? ` · ${personaLabel(identity)}` : '';
|
|
79
|
-
editor.contextBadge = `${lifecycle}${
|
|
92
|
+
editor.contextBadge = `${lifecycle}${profileLabel}${persona}`;
|
|
80
93
|
};
|
|
81
94
|
// Paint the editor border + title chip. Shell/bash mode (leading `!`) wins and
|
|
82
95
|
// forces the whole frame green (#7); otherwise the hue tracks the thinking
|
|
@@ -105,8 +118,9 @@ export function createEditorChrome(ctx, hooks) {
|
|
|
105
118
|
tui.requestRender();
|
|
106
119
|
};
|
|
107
120
|
// Git context painted into the RIGHT of the editor's top border: branch and
|
|
108
|
-
// status symbols (● dirty, ⇡ ahead, ⇣ behind)
|
|
109
|
-
//
|
|
121
|
+
// status symbols (● dirty, ⇡ ahead, ⇣ behind) of the node's own working
|
|
122
|
+
// directory, read by its broker (the viewer may run on another machine).
|
|
123
|
+
// Refreshed by the poll.
|
|
110
124
|
const renderGitInfo = (info) => {
|
|
111
125
|
const parts = [];
|
|
112
126
|
if (info.branch)
|
|
@@ -122,9 +136,14 @@ export function createEditorChrome(ctx, hooks) {
|
|
|
122
136
|
parts.push(sym.join(''));
|
|
123
137
|
// A trailing space keeps the symbols off the very last border cell.
|
|
124
138
|
editor.info = parts.length > 0 ? ` ${parts.join(pal.muted(' · '))} ` : '';
|
|
125
|
-
syncContextBadge(info.dir);
|
|
126
139
|
tui.requestRender();
|
|
127
140
|
};
|
|
141
|
+
const pollGit = () => {
|
|
142
|
+
socket.request({ type: 'get_git_status' }).then((reply) => {
|
|
143
|
+
if (reply.kind === 'git_status')
|
|
144
|
+
renderGitInfo(reply);
|
|
145
|
+
}, () => { });
|
|
146
|
+
};
|
|
128
147
|
return {
|
|
129
148
|
bashMode: () => bashMode,
|
|
130
149
|
setChipColor: (color) => {
|
|
@@ -137,6 +156,6 @@ export function createEditorChrome(ctx, hooks) {
|
|
|
137
156
|
editor.title = displayEditorTitle(sessionName, hooks.nodeIdentity());
|
|
138
157
|
},
|
|
139
158
|
syncContextBadge: () => syncContextBadge(),
|
|
140
|
-
pollGit
|
|
159
|
+
pollGit,
|
|
141
160
|
};
|
|
142
161
|
}
|
|
@@ -69,8 +69,8 @@ const nodeBashRun = defineLeaf({
|
|
|
69
69
|
throw new InputError({ error: 'no_node', message: '`node bash run` starts a job for the calling node and works only inside a node’s bash tool', next: 'Run it from a node’s bash tool call.' });
|
|
70
70
|
}
|
|
71
71
|
const cwd = process.cwd();
|
|
72
|
-
const {
|
|
73
|
-
const refusal =
|
|
72
|
+
const { destructiveCommandRefusal } = await import('../../core/bash-guard.js');
|
|
73
|
+
const refusal = destructiveCommandRefusal(command, cwd);
|
|
74
74
|
if (refusal !== null) {
|
|
75
75
|
throw new InputError({ error: 'refused', message: refusal, next: 'Run a different command.' });
|
|
76
76
|
}
|
|
@@ -436,7 +436,7 @@ function broadSearchRefusalMessage(segment, target, reason) {
|
|
|
436
436
|
* `rm -rf "$HOME"` is a scratch directory and runs. A `HOME=/tmp/x cmd`
|
|
437
437
|
* PREFIX applies to that one command only, so a later `rm -rf "$HOME"` is the
|
|
438
438
|
* real home — which is precisely the mistake that destroyed one. */
|
|
439
|
-
function destructiveCommandRefusal(command, cwd, home) {
|
|
439
|
+
export function destructiveCommandRefusal(command, cwd, home = homedir()) {
|
|
440
440
|
const vars = initialVariables(home, cwd);
|
|
441
441
|
// Every directory a relative operand might be resolved from. A `cd` ADDS its
|
|
442
442
|
// destination rather than replacing the previous one, because the guard
|
|
@@ -332,9 +332,9 @@ export function createRowStore() {
|
|
|
332
332
|
const db = await openDb();
|
|
333
333
|
const old = await parts(db, id);
|
|
334
334
|
await withCanvasWrite(async (tx) => {
|
|
335
|
+
await tx.prepare('DELETE FROM sessions WHERE session_id = ?').run(id);
|
|
335
336
|
await tx.prepare('DELETE FROM conversation_entries WHERE conversation_id = ?').run(id);
|
|
336
337
|
await tx.prepare('DELETE FROM conversation_parts WHERE conversation_id = ?').run(id);
|
|
337
|
-
await tx.prepare('DELETE FROM sessions WHERE session_id = ?').run(id);
|
|
338
338
|
});
|
|
339
339
|
for (const part of old)
|
|
340
340
|
await (await blobStore()).delete(part.blob_key);
|
|
@@ -99,7 +99,7 @@ export async function heads(db, doc) {
|
|
|
99
99
|
AND NOT EXISTS (SELECT 1 FROM revision_parents p WHERE p.parent = r.rev_id) ORDER BY r.number DESC, r.rev_id`).all(doc.id);
|
|
100
100
|
return (await mapAsync(raws, async (r) => await toRevision(db, r)));
|
|
101
101
|
}
|
|
102
|
-
function headsKeyOf(revs) {
|
|
102
|
+
export function headsKeyOf(revs) {
|
|
103
103
|
return revs.map((r) => r.rev_id).sort().join(',');
|
|
104
104
|
}
|
|
105
105
|
export async function documentRecord(db, doc) {
|
|
@@ -447,32 +447,20 @@ export async function setDocumentRecord(db, reader, doc, fields, rationale) {
|
|
|
447
447
|
}, { savepoint: true });
|
|
448
448
|
}
|
|
449
449
|
// ── read and history ───────────────────────────────────────────────────────
|
|
450
|
-
/** Record that the reader holds the document's current heads: a `read` watch with that read
|
|
451
|
-
* base, and a `read` push. Delivery's content load calls this without reading the body. */
|
|
452
|
-
export async function recordRead(db, reader, doc, reposFn) {
|
|
453
|
-
const actor = actorOf(reader);
|
|
454
|
-
const { heads_key } = await documentRecord(db, doc);
|
|
455
|
-
await recordWatch(db, actor, doc, 'read', { readHeadsKey: heads_key });
|
|
456
|
-
await publish(db, { event: 'read', object: doc, actor, attrs: {} }, reposFn);
|
|
457
|
-
}
|
|
458
450
|
/** The document's record, each head with its body (several = needs merge) and its links under
|
|
459
|
-
* their current names
|
|
460
|
-
export async function readDocument(db, reader, doc
|
|
451
|
+
* their current names. Records nothing. */
|
|
452
|
+
export async function readDocument(db, reader, doc) {
|
|
461
453
|
assertDocument(doc);
|
|
462
454
|
await readable(db, reader, doc);
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
if (!doc.deleted_at)
|
|
473
|
-
await recordRead(db, reader, doc, reposFn);
|
|
474
|
-
return { object: doc, record, heads: current, needsMerge: current.length > 1, links };
|
|
475
|
-
}, { savepoint: true });
|
|
455
|
+
const record = await documentRecord(db, doc);
|
|
456
|
+
const headRows = await heads(db, doc);
|
|
457
|
+
const texts = await getBodies(db, headRows.map((h) => h.body_hash));
|
|
458
|
+
const current = await mapAsync(headRows, async (h) => ({ ...h, body: await withCurrentNames(db, doc, texts.get(h.body_hash)) }));
|
|
459
|
+
const read = await readableOrDeleted(db, await resolveReader(db, reader), 'o');
|
|
460
|
+
const linked = await db.prepareUncached(`SELECT e.written_as AS _written_as, o.* FROM edges e JOIN objects o ON o.id = e.dst
|
|
461
|
+
WHERE e.type = 'links-to' AND e.src = ? AND (${read.sql}) ORDER BY e.written_as`).all(doc.id, ...read.params);
|
|
462
|
+
const links = linked.map(({ _written_as, ...object }) => ({ written_as: _written_as ?? '', object: object, deleted: object.deleted_at !== null }));
|
|
463
|
+
return { object: doc, record, heads: current, needsMerge: current.length > 1, links };
|
|
476
464
|
}
|
|
477
465
|
/** Every revision, newest first, with authors, rationales and parents. Records nothing. */
|
|
478
466
|
export async function history(db, reader, doc) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { recordLiveRead } from './live-read.js';
|
|
2
1
|
import { header } from './render.js';
|
|
3
2
|
import { objectDTO } from './dto.js';
|
|
4
3
|
import { receiverForObject } from '../receivers.js';
|
|
@@ -10,8 +9,7 @@ export function customKind(name, declared) {
|
|
|
10
9
|
created: { level: 4 }, read: { level: 1 }, watched: { level: 1 },
|
|
11
10
|
deleted: { level: 5 }, configured: { level: 1 }, ...events,
|
|
12
11
|
}, addressable: 'name', receiverFor: receiverForObject,
|
|
13
|
-
async read(db,
|
|
14
|
-
await recordLiveRead(db, reader, object, opts.reposFn);
|
|
12
|
+
async read(db, _reader, object) {
|
|
15
13
|
const row = await db.prepare('SELECT description, summary, state_json, published_at, receiver_json, dropped FROM custom_objects WHERE object = ?')
|
|
16
14
|
.get(object.id);
|
|
17
15
|
const receiver = row?.receiver_json == null ? null : JSON.parse(row.receiver_json);
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { deliveryDocOf, nodeSubject, ownerHandle } from '../../substrate/delivery/corpus.js';
|
|
3
|
-
import { recordContentDelivery } from '../../substrate/delivery/deliver.js';
|
|
1
|
+
import { deliveryDocOf, nodeSubject } from '../../substrate/delivery/corpus.js';
|
|
4
2
|
import { renderExplicitRead } from '../../substrate/delivery/render-event.js';
|
|
5
3
|
import { permits, resolveReader } from '../../permissions/evaluator.js';
|
|
6
|
-
import { documentRecord, readDocument } from '../documents.js';
|
|
7
|
-
import { loadLedger
|
|
8
|
-
import { getById } from '../objects.js';
|
|
4
|
+
import { documentRecord, headsKeyOf, readDocument } from '../documents.js';
|
|
5
|
+
import { loadLedger } from '../exposures.js';
|
|
9
6
|
import { rulesOf } from '../rules.js';
|
|
10
7
|
import { objectDTO, objectDTOs } from './dto.js';
|
|
11
8
|
import { withBase } from './kind.js';
|
|
@@ -28,21 +25,7 @@ async function explicitReadAttachments(db, reader, doc) {
|
|
|
28
25
|
const ledger = isNode ? await loadLedger(db, reader.node.id) : { node: '', preferenceSnapshot: null, objects: new Map(), listed: new Map() };
|
|
29
26
|
const ctx = { db, reader, subject: isNode ? await nodeSubject(db, reader) : null, ledger, channel: 'transcript' };
|
|
30
27
|
const read = await renderExplicitRead(ctx, await deliveryDocOf(db, reader, doc));
|
|
31
|
-
|
|
32
|
-
await recordContentDelivery(db, reader, read.delivered);
|
|
33
|
-
await saveLedger(db, ledger);
|
|
34
|
-
}
|
|
35
|
-
return { attachments: read.attachments, linked: read.linked.map((d) => d.object) };
|
|
36
|
-
}
|
|
37
|
-
/** A node's explicit read of a knowledge or preference document is the analytics memory log's
|
|
38
|
-
* `read` event; its companions are `loaded` rows, written by `recordContentDelivery`. */
|
|
39
|
-
async function recordExplicitMemoryRead(db, reader, doc) {
|
|
40
|
-
if (reader.class !== 'node' || (doc.kind !== 'knowledge' && doc.kind !== 'preference') || doc.owner === null)
|
|
41
|
-
return;
|
|
42
|
-
const owner = await getById(db, doc.owner);
|
|
43
|
-
if (owner === null)
|
|
44
|
-
return;
|
|
45
|
-
await recordMemoryReadsIn(db, reader.node.id, [{ name: doc.name, scope: ownerHandle(owner), at: new Date().toISOString(), type: 'read' }]);
|
|
28
|
+
return { attachments: read.attachments, linked: read.linked.map((d) => d.object), ...(isNode ? { ledger } : {}), delivered: read.delivered };
|
|
46
29
|
}
|
|
47
30
|
function render(o, d) {
|
|
48
31
|
const lines = [];
|
|
@@ -104,11 +87,10 @@ export const documentKind = {
|
|
|
104
87
|
return { summary: (await documentRecord(db, doc)).summary ?? null, rules: (await rulesOf(db, doc)).length };
|
|
105
88
|
},
|
|
106
89
|
async read(db, reader, doc, opts) {
|
|
107
|
-
const read = await readDocument(db, reader, doc
|
|
108
|
-
await recordExplicitMemoryRead(db, reader, doc);
|
|
90
|
+
const read = await readDocument(db, reader, doc);
|
|
109
91
|
const rec = read.record;
|
|
110
92
|
const under = await listingOf(db, await resolveReader(db, reader), doc);
|
|
111
|
-
const { attachments, linked } = await explicitReadAttachments(db, reader, doc);
|
|
93
|
+
const { attachments, linked, ledger, delivered } = await explicitReadAttachments(db, reader, doc);
|
|
112
94
|
const listed = new Set(under.map((o) => o.id));
|
|
113
95
|
const listing = [...under, ...await objectDTOs(db, linked.filter((o) => !listed.has(o.id)))];
|
|
114
96
|
const data = {
|
|
@@ -127,6 +109,7 @@ export const documentKind = {
|
|
|
127
109
|
})),
|
|
128
110
|
};
|
|
129
111
|
}
|
|
130
|
-
return { data: data, text: render(await objectDTO(db, doc), data)
|
|
112
|
+
return { data: data, text: render(await objectDTO(db, doc), data),
|
|
113
|
+
record: { headsKey: headsKeyOf(read.heads), ...(ledger === undefined ? {} : { ledger }), delivered } };
|
|
131
114
|
},
|
|
132
115
|
};
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
/** The environment kind: a place objects run. Today only the machine an install runs on. */
|
|
2
2
|
import { objectDTO } from './dto.js';
|
|
3
3
|
import { withBase } from './kind.js';
|
|
4
|
-
import { recordLiveRead } from './live-read.js';
|
|
5
4
|
import { attr, header } from './render.js';
|
|
6
5
|
export const environmentKind = {
|
|
7
6
|
name: 'environment',
|
|
8
7
|
addressable: 'id',
|
|
9
8
|
events: withBase(),
|
|
10
|
-
async read(db,
|
|
9
|
+
async read(db, _reader, environment) {
|
|
11
10
|
const row = await db.prepare('SELECT kind, machine_id, last_seen_at FROM environments WHERE object = ?').get(environment.id);
|
|
12
11
|
if (!row)
|
|
13
12
|
throw new Error(`environment object ${environment.id} has no environments row`);
|
|
14
|
-
await recordLiveRead(db, reader, environment, opts.reposFn);
|
|
15
13
|
const o = await objectDTO(db, environment);
|
|
16
14
|
const data = { kind: row.kind, machine_id: row.machine_id, last_seen_at: row.last_seen_at };
|
|
17
15
|
const text = [header('object', o, attr('machine_id', data.machine_id) + attr('last_seen_at', data.last_seen_at)),
|
|
@@ -2,17 +2,15 @@
|
|
|
2
2
|
import { jobRow } from '../jobs.js';
|
|
3
3
|
import { objectDTO } from './dto.js';
|
|
4
4
|
import { withBase } from './kind.js';
|
|
5
|
-
import { recordLiveRead } from './live-read.js';
|
|
6
5
|
import { attr, header } from './render.js';
|
|
7
6
|
export const jobKind = {
|
|
8
7
|
name: 'job',
|
|
9
8
|
addressable: 'id',
|
|
10
9
|
events: withBase({ exited: { level: 7 }, killed: { level: 7 }, silent: { level: 7 } }),
|
|
11
|
-
async read(db,
|
|
10
|
+
async read(db, _reader, job) {
|
|
12
11
|
const row = await jobRow(db, job);
|
|
13
12
|
if (!row)
|
|
14
13
|
throw new Error(`job object ${job.id} has no jobs row`);
|
|
15
|
-
await recordLiveRead(db, reader, job, opts.reposFn);
|
|
16
14
|
const o = await objectDTO(db, job);
|
|
17
15
|
const data = { command: row.command, status: row.status, exit_code: row.exit_code, output_key: row.output_key };
|
|
18
16
|
const text = [
|
|
@@ -6,7 +6,6 @@ import { readGoal } from '../../runtime/kickoff.js';
|
|
|
6
6
|
import { permits, resolveReader } from '../../permissions/evaluator.js';
|
|
7
7
|
import { objectDTO } from './dto.js';
|
|
8
8
|
import { withBase } from './kind.js';
|
|
9
|
-
import { recordLiveRead } from './live-read.js';
|
|
10
9
|
import { attr, header, section } from './render.js';
|
|
11
10
|
import { mapAsync } from '../../async-array.js';
|
|
12
11
|
const TIERED = [3, 5, 7];
|
|
@@ -65,14 +64,13 @@ export const nodeKind = {
|
|
|
65
64
|
'notice.deadline': { level: 5, levels: TIERED, durable: true, carriesBody: true, elevatesTier: true },
|
|
66
65
|
'notice.close': { level: 5, levels: TIERED, durable: true, carriesBody: true, elevatesTier: true },
|
|
67
66
|
}),
|
|
68
|
-
async read(db, reader, node
|
|
67
|
+
async read(db, reader, node) {
|
|
69
68
|
const row = await db.prepare('SELECT status FROM nodes WHERE node_id = ?').get(node.id);
|
|
70
69
|
const read = await permits(db, await resolveReader(db, reader), 'read', 'o');
|
|
71
70
|
const visible = async (rows) => await mapAsync(rows, async (o) => await objectDTO(db, o));
|
|
72
71
|
const children = await db.prepareUncached(`SELECT o.* FROM nodes n JOIN objects o ON o.id = n.node_id
|
|
73
72
|
WHERE n.parent = ? AND o.deleted_at IS NULL AND ${read.sql} ORDER BY o.seq`).all(node.id, ...read.params);
|
|
74
73
|
const owned = await db.prepareUncached(`SELECT o.* FROM objects o WHERE o.owner = ? AND o.deleted_at IS NULL AND ${read.sql} ORDER BY o.seq`).all(node.id, ...read.params);
|
|
75
|
-
await recordLiveRead(db, reader, node, opts.reposFn);
|
|
76
74
|
const data = {
|
|
77
75
|
status: row?.status ?? 'deleted', mandate_first_line: firstLine(await readGoal(node.id)), children: await visible(children),
|
|
78
76
|
owned: await visible(owned.filter((o) => o.type !== 'job')), jobs: await visible(owned.filter((o) => o.type === 'job')),
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
/** The owner kinds — person, app, repo, profile, group: identities that own objects. Base events only. */
|
|
2
2
|
import { objectDTO } from './dto.js';
|
|
3
3
|
import { withBase } from './kind.js';
|
|
4
|
-
import { recordLiveRead } from './live-read.js';
|
|
5
4
|
import { header } from './render.js';
|
|
6
5
|
function ownerKind(name) {
|
|
7
6
|
return {
|
|
8
7
|
name,
|
|
9
8
|
addressable: 'handle',
|
|
10
9
|
events: withBase(),
|
|
11
|
-
async read(db,
|
|
10
|
+
async read(db, _reader, owner) {
|
|
12
11
|
const id = await db.prepare('SELECT scheme, external_id FROM identities WHERE object = ?').get(owner.id);
|
|
13
|
-
await recordLiveRead(db, reader, owner, opts.reposFn);
|
|
14
12
|
const data = {
|
|
15
13
|
handle: owner.name, display_name: owner.preview || owner.name,
|
|
16
14
|
identity: { scheme: id?.scheme ?? '', external_id: id?.external_id ?? '' },
|
|
@@ -210,8 +210,14 @@ export async function readerForObject(db, watcher, reposFn = async () => [], loo
|
|
|
210
210
|
: grants.length === 1
|
|
211
211
|
? always(grants[0])
|
|
212
212
|
: kept?.resolved ?? null;
|
|
213
|
+
// The person the object reads for: its one grant's person, the person it is kept for, or the person that owns it. Delivery resolves the reader's
|
|
214
|
+
// user from this, so a reader built outside a request (package publishing, on a cloud role) never asks the process for a person.
|
|
215
|
+
const personSub = owner.type === 'person'
|
|
216
|
+
? (await db.prepare("SELECT external_id FROM identities WHERE object = ? AND scheme = 'user'").get(owner.id))?.external_id
|
|
217
|
+
: undefined;
|
|
218
|
+
const readsFor = personSub ?? (grants.length === 1 ? grants[0].sub : kept?.sub);
|
|
213
219
|
return { class: 'object', object: watcher, node: watcher, owner, app: owningApp, scopes,
|
|
214
|
-
...(
|
|
220
|
+
...(readsFor === undefined ? {} : { sub: readsFor }), repos: owner.type === 'repo' ? [owner] : [] };
|
|
215
221
|
}
|
|
216
222
|
/** The scopes `app` (an app object) holds now: its one active grant's always-scopes, or a local plugin's `crtr_app_` token scopes when it has no
|
|
217
223
|
* grant; null for several grants or none that applies. Unlike an app-owned object's reader (`readerForObject`), it has no person to pick one grant by. */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isCloudRole, personIdAsync } from '../canvas/person.js';
|
|
2
|
+
import { requestPersonId } from '../canvas/person-state.js';
|
|
2
3
|
import { OBJECT_TYPE, GROUP_TYPE } from './builtin.js';
|
|
3
4
|
import { ceilingFrag, resolveCeiling } from './ceiling.js';
|
|
4
5
|
import { compilePermission } from './compile.js';
|
|
@@ -11,17 +12,21 @@ const ACCESS = { read: 'read', use: 'read', edit: 'write', share: 'write', messa
|
|
|
11
12
|
const bareUser = (principal) => principal.replace(/^user:/, '');
|
|
12
13
|
/** The user a reader acts for: a person's own identity; an app call's `sub`; a node's `sub`; otherwise the install's person. */
|
|
13
14
|
export async function userOf(db, reader) {
|
|
15
|
+
return await namedUserOf(db, reader) ?? bareUser(await personIdAsync());
|
|
16
|
+
}
|
|
17
|
+
/** The user a reader names itself, without falling back to the process's person; null when it names none. */
|
|
18
|
+
async function namedUserOf(db, reader) {
|
|
14
19
|
if (reader.class === 'person') {
|
|
15
20
|
const row = await db.prepare("SELECT external_id FROM identities WHERE object = ? AND scheme = 'user'").get(reader.person.id);
|
|
16
|
-
return
|
|
21
|
+
return row === undefined ? null : bareUser(row.external_id);
|
|
17
22
|
}
|
|
18
23
|
if (reader.class === 'app')
|
|
19
|
-
return
|
|
24
|
+
return reader.sub === undefined ? null : bareUser(reader.sub);
|
|
20
25
|
if (reader.class === 'object' && reader.sub !== undefined)
|
|
21
26
|
return bareUser(reader.sub);
|
|
22
27
|
const nodeId = reader.class === 'node' ? reader.node.id : reader.object.id;
|
|
23
28
|
const row = await db.prepare('SELECT sub FROM nodes WHERE node_id = ?').get(nodeId);
|
|
24
|
-
return
|
|
29
|
+
return row?.sub == null ? null : bareUser(row.sub);
|
|
25
30
|
}
|
|
26
31
|
/** The user ids a subject stands for (the user and `*`) and every group it reaches, directly or through nested groups. */
|
|
27
32
|
export async function subjectSet(db, userId) {
|
|
@@ -35,8 +40,9 @@ export async function subjectSet(db, userId) {
|
|
|
35
40
|
return { userIds, groupIds: rows.map((r) => r.id) };
|
|
36
41
|
}
|
|
37
42
|
/** A reader `shareReads` marked is built for one request: its user, subjects and definitions are resolved once; any other reader may outlive a
|
|
38
|
-
* membership change and resolves them per call. The user a reader reads as is `userOf`, except that on a cloud role
|
|
39
|
-
*
|
|
43
|
+
* membership change and resolves them per call. The user a reader reads as is `userOf`, except that on a cloud role outside a request a reader that
|
|
44
|
+
* names no user itself (an app reader with no `sub`, such as package link derivation at boot; a watcher's reader built while a package publishes) acts
|
|
45
|
+
* for no person: null. `userOf` itself keeps throwing there. */
|
|
40
46
|
const oneRequest = new WeakMap();
|
|
41
47
|
export const shareReads = (reader) => { if (!oneRequest.has(reader))
|
|
42
48
|
oneRequest.set(reader, null); return reader; };
|
|
@@ -45,7 +51,7 @@ export function resolveReader(db, reader) {
|
|
|
45
51
|
if (shared)
|
|
46
52
|
return shared;
|
|
47
53
|
const ev = (async () => {
|
|
48
|
-
const userId =
|
|
54
|
+
const userId = isCloudRole() && requestPersonId() === undefined ? await namedUserOf(db, reader) : await userOf(db, reader);
|
|
49
55
|
return { reader, userId, subjects: userId === null ? { userIds: ['*'], groupIds: [] } : await subjectSet(db, userId), defs: await loadDefinitions(db) };
|
|
50
56
|
})();
|
|
51
57
|
if (shared === null) {
|
|
@@ -172,6 +172,17 @@ export function contextDirNote(nodeId, grantee) {
|
|
|
172
172
|
'scripts, data, logs and page modules. Your working dir is the project, NOT this directory, so a ' +
|
|
173
173
|
'bare relative `context/...` lands in the repo, not here.');
|
|
174
174
|
}
|
|
175
|
+
/** Where the node's engine and shell run, by the runner of its latest execution. A cloud sandbox is not the person's
|
|
176
|
+
* computer, so a path from their Mac (a pasted screenshot's temp file, a `/Users/...` path) does not exist there. */
|
|
177
|
+
export function whereYouRunNote(runner) {
|
|
178
|
+
if (runner === 'blaxel') {
|
|
179
|
+
return 'You run in a cloud sandbox, not on the person\'s computer. A file path from their Mac (such as `/Users/...` or `/var/folders/...`) does not exist here; their Mac\'s files and shell are reached through `crtr device`.';
|
|
180
|
+
}
|
|
181
|
+
if (runner === 'process' || runner === 'machine') {
|
|
182
|
+
return 'You run on the person\'s own computer: file paths they give you exist here.';
|
|
183
|
+
}
|
|
184
|
+
return '';
|
|
185
|
+
}
|
|
175
186
|
/** The profile-purview note — rendered ONLY when the profile resolves to a
|
|
176
187
|
* manifest that names at least one project dir. Phrased as PURVIEW, not a cwd
|
|
177
188
|
* replacement: the node's cwd is still its one working dir (bash/edits run
|
|
@@ -15,7 +15,7 @@ import { cadenceDisplay } from '../wake.js';
|
|
|
15
15
|
import { renderKnowledge, renderWorkspaceOpen } from '../substrate/delivery/render-boot.js';
|
|
16
16
|
import { situationalContextEnvelope } from './situational-context.js';
|
|
17
17
|
import { statusRank } from '../canvas/node-order.js';
|
|
18
|
-
import { buildProjectContextBlock, contextDirNote, orchestratorContextNote, profileNote as profileNoteShared, renderGraphMap, buildIdentityAssertion as buildIdentityAssertionShared, worktreeNote, } from './bearings-render.js';
|
|
18
|
+
import { buildProjectContextBlock, contextDirNote, orchestratorContextNote, whereYouRunNote, profileNote as profileNoteShared, renderGraphMap, buildIdentityAssertion as buildIdentityAssertionShared, worktreeNote, } from './bearings-render.js';
|
|
19
19
|
import { mapAsync } from '../async-array.js';
|
|
20
20
|
/** The bearings custom type is shared with every attached renderer. */
|
|
21
21
|
export { CONTEXT_INTRO_CUSTOM_TYPE } from '../../shared/generated-context.js';
|
|
@@ -162,7 +162,11 @@ function managedWorktreeNote(node) {
|
|
|
162
162
|
* documents owned by the directory's repo (its `<repo>/index` is the workspace front door). */
|
|
163
163
|
async function bearingsShell(nodeId, knowledge, workspaceContext) {
|
|
164
164
|
const node = await getNode(nodeId);
|
|
165
|
+
const execution = await latestExecutionForNode(nodeId);
|
|
165
166
|
const bearings = ['<crtr-bearings>', await buildIdentityAssertion(nodeId, node)];
|
|
167
|
+
const whereYouRun = whereYouRunNote(execution?.runner);
|
|
168
|
+
if (whereYouRun !== '')
|
|
169
|
+
bearings.push('', '## Where you run', whereYouRun);
|
|
166
170
|
const map = await buildGraphMap(nodeId, node);
|
|
167
171
|
if (map !== '')
|
|
168
172
|
bearings.push('', '## Your place in the canvas', map);
|
|
@@ -183,7 +187,7 @@ async function bearingsShell(nodeId, knowledge, workspaceContext) {
|
|
|
183
187
|
// nested card inside the outer envelope. Never routed through the visible
|
|
184
188
|
// chat/digest path. '' when nothing was ever set.
|
|
185
189
|
const situational = await situationalContextEnvelope(nodeId) ?? '';
|
|
186
|
-
const projectCtx = node?.cwd !== undefined &&
|
|
190
|
+
const projectCtx = node?.cwd !== undefined && execution?.runner === 'process' ? buildProjectContextBlock(node.cwd) : ''; // reads this host
|
|
187
191
|
return [bearings.join('\n'), knowledge, workspaceContext, situational, projectCtx]
|
|
188
192
|
.filter((s) => s !== '')
|
|
189
193
|
.join('\n');
|