@north-light/cli 0.3.704 → 0.3.706
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/render/chat-view.d.ts +7 -60
- package/dist/clients/attach/render/chat-view.js +2 -4
- package/dist/clients/attach/viewer.js +537 -539
- package/dist/core/canvas/schema-pg/024-conversation-cycle-offset.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/config.js +1 -1
- package/dist/core/conversation-store/client.js +2 -2
- package/dist/core/conversation-store/index.d.ts +3 -3
- package/dist/core/conversation-store/patch.js +1 -1
- package/dist/core/conversation-store/row-store.js +13 -13
- package/dist/core/import/load/prepare.js +4 -4
- package/dist/core/runs/operations.js +6 -6
- package/dist/core/runtime/broker/tool-groups.js +1 -1
- package/dist/core/runtime/broker.js +1 -1
- package/dist/core/runtime/node-read.js +3 -3
- package/dist/core/runtime/session-cycles.d.ts +5 -22
- package/dist/core/runtime/session-cycles.js +1 -1
- package/dist/core/user-settings.d.ts +0 -30
- package/dist/core/user-settings.js +1 -1
- package/dist/daemon/api/handlers/conversations.js +3 -3
- package/dist/daemon/machine-link/forward.d.ts +1 -1
- package/dist/daemon/machine-link/forward.js +1 -1
- package/dist/types.d.ts +0 -23
- package/dist/types.js +1 -1
- package/package.json +3 -3
- package/packages/crouter-api/dist/clients/attach/render/chat-view.js +22 -261
- package/packages/crouter-api/dist/clients/attach/viewer.js +6 -5
- package/packages/crouter-api/dist/core/canvas/schema-version.js +1 -1
- package/packages/crouter-api/dist/core/config.js +2 -6
- package/packages/crouter-api/dist/core/conversation-store/client.js +1 -1
- package/packages/crouter-api/dist/core/conversation-store/patch.js +8 -3
- package/packages/crouter-api/dist/core/conversation-store/row-store.js +46 -19
- package/packages/crouter-api/dist/core/import/load/prepare.js +1 -1
- package/packages/crouter-api/dist/core/runs/operations.js +2 -2
- package/packages/crouter-api/dist/core/runtime/session-cycles.js +27 -75
- package/packages/crouter-api/dist/core/user-settings.js +1 -43
- package/packages/crouter-api/dist/daemon/machine-link/forward.js +12 -8
- package/packages/crouter-api/dist/types.js +0 -7
- 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/dist/clients/attach/render/condensed-history.d.ts +0 -21
- package/dist/clients/attach/render/condensed-history.js +0 -1
- package/packages/crouter-api/dist/clients/attach/render/condensed-history.js +0 -60
|
@@ -89,6 +89,21 @@ async function bytesOf(snap, start, end) {
|
|
|
89
89
|
}
|
|
90
90
|
return Buffer.concat(out);
|
|
91
91
|
}
|
|
92
|
+
/** The complete lines of one snapshot, read ahead in chunks. */
|
|
93
|
+
async function* linesOf(snap) {
|
|
94
|
+
const size = snap.parts.reduce((n, p) => n + p.bytes, 0) + snap.tail.reduce((n, p) => n + p.bytes, 0);
|
|
95
|
+
let carry = '';
|
|
96
|
+
for await (const bytes of readAhead(Math.ceil(size / CHUNK), (i) => bytesOf(snap, i * CHUNK, Math.min(size, (i + 1) * CHUNK)), READ_AHEAD)) {
|
|
97
|
+
const text = carry + bytes.toString('latin1');
|
|
98
|
+
const cut = text.lastIndexOf('\n');
|
|
99
|
+
carry = text.slice(cut + 1);
|
|
100
|
+
for (const line of text.slice(0, cut + 1).split('\n'))
|
|
101
|
+
if (line)
|
|
102
|
+
yield Buffer.from(line, 'latin1').toString('utf8');
|
|
103
|
+
}
|
|
104
|
+
if (carry)
|
|
105
|
+
yield Buffer.from(carry, 'latin1').toString('utf8');
|
|
106
|
+
}
|
|
92
107
|
/** Files registered by `recover` (tests, first-boot repair): imported as part 0 on first use. */
|
|
93
108
|
const legacy = new Map();
|
|
94
109
|
async function importOne(id, node, path) {
|
|
@@ -190,8 +205,16 @@ export function createRowStore() {
|
|
|
190
205
|
for (const entry of entries) {
|
|
191
206
|
const body = JSON.stringify(entry);
|
|
192
207
|
const row = await db.prepare('INSERT INTO conversation_entries (conversation_id, entry_id, body, bytes, execution_id, created) VALUES (?, ?, ?, ?, NULL, ?) ON CONFLICT (conversation_id, entry_id) DO NOTHING RETURNING entry_id').get(id, entry.id, body, Buffer.byteLength(body) + 1, at());
|
|
193
|
-
if (row)
|
|
194
|
-
|
|
208
|
+
if (!row)
|
|
209
|
+
continue;
|
|
210
|
+
inserted.push(entry);
|
|
211
|
+
// A broker start reads from the last cycle start (`read(id, 'cycle')`).
|
|
212
|
+
if (entry.type === 'custom' && entry.customType === 'crtr-cycle') {
|
|
213
|
+
// Part 0 is locked first, so a header relocation cannot change its length between this sum and the update.
|
|
214
|
+
await db.prepare('SELECT 1 FROM conversation_parts WHERE conversation_id = ? AND seq = 0 FOR UPDATE').get(id);
|
|
215
|
+
const size = [...await parts(db, id), ...await tail(db, id)].reduce((n, p) => n + Number(p.bytes), 0) - Buffer.byteLength(body) - 1;
|
|
216
|
+
await db.prepare('UPDATE conversation_parts SET cycle_offset = ? WHERE conversation_id = ? AND seq = 0').run(size, id);
|
|
217
|
+
}
|
|
195
218
|
}
|
|
196
219
|
if (owner.run_id && inserted.length) {
|
|
197
220
|
const pending = await appendConversationEvents(db, owner.run_id, owner.node_id, inserted, JSON.parse(owner.input_ids_json ?? '[]'), reprompt);
|
|
@@ -202,22 +225,7 @@ export function createRowStore() {
|
|
|
202
225
|
async readLines(id) {
|
|
203
226
|
const db = await openDb();
|
|
204
227
|
const { path } = await initial(id, db);
|
|
205
|
-
|
|
206
|
-
const size = snap.parts.reduce((n, p) => n + p.bytes, 0) + snap.tail.reduce((n, p) => n + p.bytes, 0);
|
|
207
|
-
async function* lines() {
|
|
208
|
-
let carry = '';
|
|
209
|
-
for await (const bytes of readAhead(Math.ceil(size / CHUNK), (i) => bytesOf(snap, i * CHUNK, Math.min(size, (i + 1) * CHUNK)), READ_AHEAD)) {
|
|
210
|
-
const text = carry + bytes.toString('latin1');
|
|
211
|
-
const cut = text.lastIndexOf('\n');
|
|
212
|
-
carry = text.slice(cut + 1);
|
|
213
|
-
for (const line of text.slice(0, cut + 1).split('\n'))
|
|
214
|
-
if (line)
|
|
215
|
-
yield Buffer.from(line, 'latin1').toString('utf8');
|
|
216
|
-
}
|
|
217
|
-
if (carry)
|
|
218
|
-
yield Buffer.from(carry, 'latin1').toString('utf8');
|
|
219
|
-
}
|
|
220
|
-
return { path, lines: lines() };
|
|
228
|
+
return { path, lines: linesOf(await snapshot(db, id)) };
|
|
221
229
|
},
|
|
222
230
|
async read(id, window) {
|
|
223
231
|
const db = await openDb();
|
|
@@ -225,6 +233,25 @@ export function createRowStore() {
|
|
|
225
233
|
const snap = await snapshot(db, id);
|
|
226
234
|
const size = snap.parts.reduce((n, p) => n + p.bytes, 0) + snap.tail.reduce((n, p) => n + p.bytes, 0);
|
|
227
235
|
const entriesOf = (text) => decode(text).filter((entry) => entry.type !== 'session');
|
|
236
|
+
if (window === 'cycle') {
|
|
237
|
+
const stored = await db.prepare('SELECT cycle_offset FROM conversation_parts WHERE conversation_id = ? AND seq = 0').get(id);
|
|
238
|
+
let offset = stored?.cycle_offset == null ? null : Number(stored.cycle_offset);
|
|
239
|
+
if (offset === null) {
|
|
240
|
+
// A conversation from before the offset was recorded: find its last cycle start once, here on the server.
|
|
241
|
+
offset = 0;
|
|
242
|
+
let position = 0;
|
|
243
|
+
for await (const line of linesOf(snap)) {
|
|
244
|
+
if (line.includes('"crtr-cycle"')) {
|
|
245
|
+
const entry = JSON.parse(line);
|
|
246
|
+
if (entry.type === 'custom' && entry.customType === 'crtr-cycle')
|
|
247
|
+
offset = position;
|
|
248
|
+
}
|
|
249
|
+
position += Buffer.byteLength(line) + 1;
|
|
250
|
+
}
|
|
251
|
+
await withCanvasWrite(async (tx) => { await tx.prepare('UPDATE conversation_parts SET cycle_offset = ? WHERE conversation_id = ? AND seq = 0 AND cycle_offset IS NULL').run(offset, id); });
|
|
252
|
+
}
|
|
253
|
+
return { header, entries: entriesOf((await bytesOf(snap, offset, size)).toString('utf8')), path };
|
|
254
|
+
}
|
|
228
255
|
if (!window || size <= window.head + window.tail)
|
|
229
256
|
return { header, entries: entriesOf((await bytesOf(snap, 0, size)).toString('utf8')), path };
|
|
230
257
|
const front = (await bytesOf(snap, 0, Math.max(0, window.head))).toString('utf8').split('\n');
|
|
@@ -365,7 +392,7 @@ export async function relocateConversationHeader(id, oldCwd, newCwd) {
|
|
|
365
392
|
// Blob I/O stays outside the write transaction; the swap only commits if part 0 is still the object we read.
|
|
366
393
|
await (await blobStore()).put(key, body);
|
|
367
394
|
const swapped = await withCanvasWrite(async (tx) => {
|
|
368
|
-
const done = await tx.prepare('UPDATE conversation_parts SET blob_key = ?, bytes = ? WHERE conversation_id = ? AND seq = 0 AND blob_key = ? RETURNING seq').get(key, body.length, id, first.blob_key);
|
|
395
|
+
const done = await tx.prepare('UPDATE conversation_parts SET blob_key = ?, bytes = ?, cycle_offset = CASE WHEN cycle_offset > 0 THEN cycle_offset + ? - bytes ELSE cycle_offset END WHERE conversation_id = ? AND seq = 0 AND blob_key = ? RETURNING seq').get(key, body.length, body.length, id, first.blob_key);
|
|
369
396
|
return done !== undefined;
|
|
370
397
|
});
|
|
371
398
|
await (await blobStore()).delete(swapped ? first.blob_key : key).catch(() => undefined);
|
|
@@ -53,7 +53,7 @@ export async function rewriteConversationHeaders(db, schema, map, blobs, runId)
|
|
|
53
53
|
rewritten += 1;
|
|
54
54
|
}
|
|
55
55
|
// Always the uploaded object's real length: a retried run restages the original `bytes` over a blob an earlier attempt already rewrote.
|
|
56
|
-
await db.prepareUncached(`UPDATE ${S('conversation_parts')} SET bytes =
|
|
56
|
+
await db.prepareUncached(`UPDATE ${S('conversation_parts')} SET bytes = ?, cycle_offset = NULL WHERE conversation_id = ? AND seq = 0`).run((next ?? data).length, conversation_id);
|
|
57
57
|
}
|
|
58
58
|
return rewritten;
|
|
59
59
|
}
|
|
@@ -39,7 +39,7 @@ import { ZERO_RUN_USAGE } from '../../api/dto/run-events.js';
|
|
|
39
39
|
import { isolatedBrokerLauncherAvailable } from '../runtime/host.js';
|
|
40
40
|
import { blaxelEnvironmentOf } from '../runtime/blaxel-environment.js';
|
|
41
41
|
import { resolveRunKind, resolveRunModel } from '../runtime/launch-target.js';
|
|
42
|
-
import {
|
|
42
|
+
import { transcriptMessages } from '../runtime/session-cycles.js';
|
|
43
43
|
import { originFor } from '../runtime/stamp/protocol.js';
|
|
44
44
|
import { readOutputRequest, readOutputResult } from '../runtime/output-result.js';
|
|
45
45
|
import { admitLegacyStructuredOutput } from '../../daemon/structured-requests/sidecar.js';
|
|
@@ -713,7 +713,7 @@ export async function traceRun(id, grantee, format) {
|
|
|
713
713
|
if (format === 'entries')
|
|
714
714
|
return { conversation_id: session_id, header, entries };
|
|
715
715
|
const manager = SessionManager.inMemory(header.cwd, undefined, [header, ...entries]);
|
|
716
|
-
const visible =
|
|
716
|
+
const visible = transcriptMessages(manager.getEntries(), manager.getLeafId());
|
|
717
717
|
const positions = new Map(entries.map((entry, index) => [entry.id, index]));
|
|
718
718
|
const prompts = entries.filter((entry) => entry.type === 'custom' && entry.customType === 'crtr-system-prompt').map((entry) => ({ id: entry.id, message: { role: 'custom', customType: 'crtr-system-prompt', data: 'data' in entry ? entry.data : undefined, timestamp: entry.timestamp } }));
|
|
719
719
|
const appMessages = entries.filter((entry) => entry.type === 'custom_message' && entry.customType === 'app_message').map((entry) => ({ id: entry.id, message: { role: 'custom', customType: 'app_message', content: 'content' in entry ? entry.content : '', timestamp: entry.timestamp } }));
|
|
@@ -1,37 +1,17 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Session cycles — one node, one conversation, many cycles.
|
|
2
2
|
//
|
|
3
|
-
// A refresh-yield
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// `cycleAwareMessages()` is the display-side counterpart: it rebuilds the FULL
|
|
12
|
-
// node history — each prior cycle's messages (via pi's own `buildSessionContext`,
|
|
13
|
-
// so a compacted prior cycle renders correctly), a synthetic divider message per
|
|
14
|
-
// boundary, then the live cycle's context — so the broker welcome snapshot
|
|
15
|
-
// (broker.ts) and the dormant snapshot (node-snapshot.ts) both render one
|
|
16
|
-
// continuous conversation.
|
|
3
|
+
// A refresh-yield reuses the node's conversation: the broker resets the
|
|
4
|
+
// session-tree leaf and appends a `crtr-cycle` custom entry as the new cycle's
|
|
5
|
+
// ROOT (parentId null). A broker start reads only the current cycle (the store's
|
|
6
|
+
// `from=cycle` read), so pi's `getEntries()` holds one cycle. Server-side
|
|
7
|
+
// readers of the whole conversation use `transcriptMessages`: earlier cycles as
|
|
8
|
+
// user and assistant text only, one line per cycle start, then the current
|
|
9
|
+
// cycle in full.
|
|
17
10
|
import { buildContextEntries, sessionEntryToContextMessages, } from '@earendil-works/pi-coding-agent';
|
|
18
11
|
/** customType of the persisted tree entry that ROOTS each post-yield cycle.
|
|
19
12
|
* Data payload: `{ cycle, fromLeaf }` — `cycle` is the node's cycle counter at
|
|
20
13
|
* relaunch, `fromLeaf` the previous cycle's leaf entry id. */
|
|
21
14
|
export const CRTR_CYCLE_CUSTOM_TYPE = 'crtr-cycle';
|
|
22
|
-
/** customType of the SYNTHETIC divider message spliced between cycles in
|
|
23
|
-
* snapshot rendering. Never persisted to the session file. */
|
|
24
|
-
export const CRTR_CYCLE_DIVIDER_CUSTOM_TYPE = 'crtr-cycle-divider';
|
|
25
|
-
function cycleDivider(cycle, timestamp) {
|
|
26
|
-
const label = cycle !== undefined ? `cycle ${cycle}` : 'new cycle';
|
|
27
|
-
return {
|
|
28
|
-
role: 'custom',
|
|
29
|
-
customType: CRTR_CYCLE_DIVIDER_CUSTOM_TYPE,
|
|
30
|
-
content: `yielded — ${label} begins with a fresh context window`,
|
|
31
|
-
display: true,
|
|
32
|
-
timestamp: new Date(timestamp).getTime(),
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
15
|
/** Text a provider attaches when the request's own AbortSignal fired. Pi's
|
|
36
16
|
* providers stamp `stopReason: 'aborted'` when they observe the signal
|
|
37
17
|
* themselves, but an abort that lands while the next request is starting
|
|
@@ -55,56 +35,28 @@ export function withoutYieldAbort(message) {
|
|
|
55
35
|
const { stopReason: _stopReason, errorMessage: _errorMessage, ...visible } = message;
|
|
56
36
|
return visible;
|
|
57
37
|
}
|
|
58
|
-
|
|
38
|
+
/** The context messages on the branch ending at `leafId`, each with its entry id. */
|
|
39
|
+
export function identifiedMessages(entries, leafId) {
|
|
40
|
+
const byId = new Map(entries.map((e) => [e.id, e]));
|
|
59
41
|
return buildContextEntries(entries, leafId, byId).flatMap((entry) => sessionEntryToContextMessages(entry).map((message) => ({ id: entry.id, message: message })));
|
|
60
42
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
? messages
|
|
65
|
-
: [...messages.slice(0, -1), { ...last, message: withoutYieldAbort(last.message) }];
|
|
66
|
-
}
|
|
67
|
-
/** The full multi-cycle message history for display: prior cycles (oldest
|
|
68
|
-
* first, each closed by a divider), then the live cycle's context. Falls back
|
|
69
|
-
* to plain `buildSessionContext()` when the session has no cycle markers, when
|
|
70
|
-
* the manager lacks tree accessors (fake engine), or when the current leaf was
|
|
71
|
-
* tree-navigated back into a pre-yield branch (pi's active-branch semantics
|
|
72
|
-
* then apply unchanged). */
|
|
73
|
-
export function cycleAwareMessages(sm) {
|
|
74
|
-
if (typeof sm.getEntries !== 'function' || typeof sm.getBranch !== 'function')
|
|
75
|
-
return undefined;
|
|
76
|
-
// File order = append order = chronological cycle order.
|
|
77
|
-
const entries = sm.getEntries();
|
|
78
|
-
const byId = new Map(entries.map((e) => [e.id, e]));
|
|
79
|
-
const currentBranch = sm.getBranch();
|
|
80
|
-
const current = identifiedContextMessages(entries, currentBranch.at(-1)?.id ?? null, byId);
|
|
81
|
-
const markers = entries.filter((e) => e.type === 'custom' && e.customType === CRTR_CYCLE_CUSTOM_TYPE);
|
|
82
|
-
if (markers.length === 0)
|
|
83
|
-
return current;
|
|
84
|
-
// The current cycle's root: first entry on the leaf→root path. When it is
|
|
85
|
-
// not a cycle marker, the leaf sits in the ORIGINAL (pre-yield) branch —
|
|
86
|
-
// render just that branch. Otherwise replay every cycle up to and including
|
|
87
|
-
// the one the marker closes.
|
|
88
|
-
const currentRootId = currentBranch[0]?.id;
|
|
89
|
-
const rootMarkerIndex = markers.findIndex((m) => m.id === currentRootId);
|
|
90
|
-
if (rootMarkerIndex === -1)
|
|
91
|
-
return current;
|
|
43
|
+
/** A whole conversation for display: each earlier cycle as user and assistant
|
|
44
|
+
* text only, one line where each cycle starts, then the current cycle in full. */
|
|
45
|
+
export function transcriptMessages(entries, leafId) {
|
|
92
46
|
const out = [];
|
|
93
|
-
for (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
47
|
+
for (const marker of entries) {
|
|
48
|
+
if (marker.type !== 'custom' || marker.customType !== CRTR_CYCLE_CUSTOM_TYPE)
|
|
49
|
+
continue;
|
|
50
|
+
const data = marker.data;
|
|
51
|
+
for (const item of data?.fromLeaf ? identifiedMessages(entries, data.fromLeaf) : []) {
|
|
52
|
+
const m = item.message;
|
|
53
|
+
if (m.role !== 'user' && m.role !== 'assistant')
|
|
54
|
+
continue;
|
|
55
|
+
const content = typeof m.content === 'string' ? m.content : m.content.filter((part) => part.type === 'text');
|
|
56
|
+
if (content.length > 0)
|
|
57
|
+
out.push({ ...item, message: { ...withoutYieldAbort(m), content } });
|
|
102
58
|
}
|
|
103
|
-
out.push({
|
|
104
|
-
id: `${marker.id}~divider`,
|
|
105
|
-
message: cycleDivider(marker.data?.cycle, marker.timestamp),
|
|
106
|
-
});
|
|
59
|
+
out.push({ id: marker.id, message: { role: 'custom', customType: CRTR_CYCLE_CUSTOM_TYPE, content: `cycle ${data?.cycle ?? ''} begins with a fresh context window`, display: true, timestamp: new Date(marker.timestamp).getTime() } });
|
|
107
60
|
}
|
|
108
|
-
out
|
|
109
|
-
return out;
|
|
61
|
+
return [...out, ...identifiedMessages(entries, leafId)];
|
|
110
62
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MOUSE_MODE_DEFAULTS, VERBOSITY_LEVELS, WHIP_MESSAGE_MODES } from '../types.js';
|
|
2
2
|
/** Display names for each verbosity level, least detail first. */
|
|
3
3
|
export const VERBOSITY_LABELS = {
|
|
4
4
|
replies: 'Replies only',
|
|
@@ -64,7 +64,6 @@ function providerOptionsFor(config, providerId) {
|
|
|
64
64
|
config.providerOptions[providerId] = created;
|
|
65
65
|
return created;
|
|
66
66
|
}
|
|
67
|
-
const LIVE_CYCLES = [1, 2, 3, 4, 5, 6];
|
|
68
67
|
/**
|
|
69
68
|
* Exhaustive settings-surface coverage for ScopeConfig. Primitive preferences
|
|
70
69
|
* are required by the type to define a Settings row; structured registries must
|
|
@@ -283,47 +282,6 @@ export const CONFIG_SETTINGS_COVERAGE = {
|
|
|
283
282
|
},
|
|
284
283
|
},
|
|
285
284
|
},
|
|
286
|
-
live_cycles: {
|
|
287
|
-
surface: 'settings',
|
|
288
|
-
setting: {
|
|
289
|
-
key: 'live_cycles',
|
|
290
|
-
label: 'Live cycles',
|
|
291
|
-
description: 'Trailing refresh cycles rendered at full fidelity; older cycles condense to text.',
|
|
292
|
-
valueConstraint: 'integer >= 1',
|
|
293
|
-
applies: 'Applies on the next attach.',
|
|
294
|
-
group: 'display',
|
|
295
|
-
order: 50,
|
|
296
|
-
format: (config) => String(config.live_cycles),
|
|
297
|
-
cycle: (config, delta) => { config.live_cycles = cycleNumber(LIVE_CYCLES, config.live_cycles, delta); },
|
|
298
|
-
setFromString: (config, raw) => {
|
|
299
|
-
const value = positiveIntegerFromString(raw, 'live_cycles');
|
|
300
|
-
if (typeof value === 'string')
|
|
301
|
-
return value;
|
|
302
|
-
config.live_cycles = value;
|
|
303
|
-
return null;
|
|
304
|
-
},
|
|
305
|
-
},
|
|
306
|
-
},
|
|
307
|
-
condensed_history: {
|
|
308
|
-
surface: 'settings',
|
|
309
|
-
setting: {
|
|
310
|
-
key: 'condensed_history',
|
|
311
|
-
label: 'Condensed history',
|
|
312
|
-
description: 'Messages retained from condensed cycles. Tool calls are never kept.',
|
|
313
|
-
valueConstraint: CONDENSED_HISTORY_MODES.join('|'),
|
|
314
|
-
applies: 'Applies on the next attach.',
|
|
315
|
-
group: 'display',
|
|
316
|
-
order: 60,
|
|
317
|
-
format: (config) => config.condensed_history,
|
|
318
|
-
cycle: (config, delta) => { config.condensed_history = cycleChoice(CONDENSED_HISTORY_MODES, config.condensed_history, delta); },
|
|
319
|
-
setFromString: (config, raw) => {
|
|
320
|
-
if (!CONDENSED_HISTORY_MODES.includes(raw))
|
|
321
|
-
return `condensed_history must be one of: ${CONDENSED_HISTORY_MODES.join('|')}`;
|
|
322
|
-
config.condensed_history = raw;
|
|
323
|
-
return null;
|
|
324
|
-
},
|
|
325
|
-
},
|
|
326
|
-
},
|
|
327
285
|
bash_tool_purpose: {
|
|
328
286
|
surface: 'settings',
|
|
329
287
|
setting: {
|
|
@@ -115,22 +115,26 @@ class ForwardedViewLink extends EventEmitter {
|
|
|
115
115
|
this.emit('close', this.failed);
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
/** One readiness check: the Mac connected the node's view.sock
|
|
119
|
-
function openReadyMachineView(environmentId, nodeId,
|
|
118
|
+
/** One readiness check: the Mac connected the node's view.sock before `deadline`. A channel still pending is kept until it connects, closes, the deadline passes or the launch exits; the channel that connected is returned open, for the caller to use or destroy, and null when it closed, the deadline passed or the launch exited (a pending channel is destroyed then). */
|
|
119
|
+
function openReadyMachineView(environmentId, nodeId, deadline, exited) {
|
|
120
120
|
return new Promise((resolve) => {
|
|
121
121
|
const view = openMachineView(environmentId, nodeId);
|
|
122
|
+
const timeoutMs = Math.max(1, deadline - Date.now());
|
|
123
|
+
let settled = false;
|
|
124
|
+
const giveUp = () => { if (settled)
|
|
125
|
+
return; settled = true; clearTimeout(timer); resolve(null); view.destroy(); };
|
|
122
126
|
const timer = setTimeout(() => {
|
|
123
127
|
emitEvent({ level: 'info', event: 'daemon.timing.view_ready_timeout', node_id: nodeId, fields: { channel: view.channel ?? '', timeout_ms: timeoutMs } });
|
|
124
|
-
|
|
125
|
-
view.destroy();
|
|
128
|
+
giveUp();
|
|
126
129
|
}, timeoutMs);
|
|
130
|
+
void exited?.then(giveUp);
|
|
127
131
|
// The no-op error listener stays on the returned channel until its user attaches its own: an error before then must not throw.
|
|
128
132
|
view.on('error', () => { });
|
|
129
|
-
view.on('connect', () => { clearTimeout(timer); resolve(view); });
|
|
130
|
-
view.on('close', () => { clearTimeout(timer); resolve(null); });
|
|
133
|
+
view.on('connect', () => { settled = true; clearTimeout(timer); resolve(view); });
|
|
134
|
+
view.on('close', () => { settled = true; clearTimeout(timer); resolve(null); });
|
|
131
135
|
});
|
|
132
136
|
}
|
|
133
|
-
/** Wait for the node's broker on the Mac to accept a viewer, retrying
|
|
137
|
+
/** Wait for the node's broker on the Mac to accept a viewer, retrying a channel that closes (its view.sock refused) after 250 ms; a pending channel is waited on, not replaced. The accepted channel, open, or null on the deadline or when the launch exits. A caller that does not use the channel destroys it. */
|
|
134
138
|
export async function waitForMachineView(environmentId, nodeId, exited, waitMs) {
|
|
135
139
|
const deadline = Date.now() + waitMs;
|
|
136
140
|
let exitSeen = false;
|
|
@@ -138,7 +142,7 @@ export async function waitForMachineView(environmentId, nodeId, exited, waitMs)
|
|
|
138
142
|
// Each attempt's length and outcome land in the calling request's step timings (`probe_<n>_ready_ms` / `probe_<n>_failed_ms`), and `ready_received_at` marks the first ready.
|
|
139
143
|
for (let attempt = 1; Date.now() <= deadline && !exitSeen; attempt++) {
|
|
140
144
|
const started = performance.now();
|
|
141
|
-
const ready = await openReadyMachineView(environmentId, nodeId,
|
|
145
|
+
const ready = await openReadyMachineView(environmentId, nodeId, deadline, exited);
|
|
142
146
|
addStepTiming(`probe_${attempt}_${ready !== null ? 'ready' : 'failed'}_ms`, performance.now() - started);
|
|
143
147
|
if (ready !== null) {
|
|
144
148
|
markAt('ready_received');
|
|
@@ -22,7 +22,6 @@ export const AGENTS_DIR = 'agents';
|
|
|
22
22
|
// (never a project/builtin scope — profiles are a user-root-only concept).
|
|
23
23
|
export const PROFILE_DIR = 'profiles';
|
|
24
24
|
export const DEFAULT_MAX_PANES_PER_WINDOW = 3;
|
|
25
|
-
/** Trailing cycles the attach viewer keeps at full fidelity (see `live_cycles`). */
|
|
26
25
|
export const DEFAULT_WHIP_MESSAGES = [
|
|
27
26
|
'Faster, clanker!',
|
|
28
27
|
"Get movin', bitch",
|
|
@@ -64,11 +63,7 @@ export const DEFAULT_WHIP_MESSAGES = [
|
|
|
64
63
|
/** What the whip action sends (see `whip_message_mode`). */
|
|
65
64
|
export const WHIP_MESSAGE_MODES = ['random', 'go-faster'];
|
|
66
65
|
export const DEFAULT_WHIP_MESSAGE_MODE = 'random';
|
|
67
|
-
export const DEFAULT_LIVE_CYCLES = 2;
|
|
68
66
|
export const MOUSE_MODE_DEFAULTS = ['tmux', 'on', 'off'];
|
|
69
|
-
/** Messages kept from a condensed cycle (see `condensed_history`). */
|
|
70
|
-
export const CONDENSED_HISTORY_MODES = ['none', 'user', 'agent', 'both'];
|
|
71
|
-
export const DEFAULT_CONDENSED_HISTORY = 'none';
|
|
72
67
|
/** Attach-viewer verbosity, least detail first. `replies`: one rewritten reply
|
|
73
68
|
* per message the person typed. `summaries`: every agent message, each tool
|
|
74
69
|
* group as its one-line summary. `tools`: each finished tool call on its call
|
|
@@ -101,8 +96,6 @@ export function defaultScopeConfig() {
|
|
|
101
96
|
whip_messages: [...DEFAULT_WHIP_MESSAGES],
|
|
102
97
|
whip_message_mode: DEFAULT_WHIP_MESSAGE_MODE,
|
|
103
98
|
mouse_mode_default: 'tmux',
|
|
104
|
-
live_cycles: DEFAULT_LIVE_CYCLES,
|
|
105
|
-
condensed_history: DEFAULT_CONDENSED_HISTORY,
|
|
106
99
|
bash_tool_purpose: true,
|
|
107
100
|
verbosity: DEFAULT_VERBOSITY,
|
|
108
101
|
detailed_tool_recaps: true,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/api",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.706",
|
|
4
4
|
"description": "Typed crtrd /v1 API contract — DTOs, route builders, the error contract, the CrtrClient, and the command-plugin manifest format. Zero runtime dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/api/index.js",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/plugin",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.706",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"postpack": "node ../../scripts/pack-minify.mjs postpack packages/crouter-plugin"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@north-light/api": "0.3.
|
|
31
|
-
"@north-light/identity": "0.3.
|
|
30
|
+
"@north-light/api": "0.3.706",
|
|
31
|
+
"@north-light/identity": "0.3.706"
|
|
32
32
|
},
|
|
33
33
|
"license": "UNLICENSED",
|
|
34
34
|
"publishConfig": {
|
package/runtime.lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.706",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@north-light/cli",
|
|
9
|
-
"version": "0.3.
|
|
9
|
+
"version": "0.3.706",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "UNLICENSED",
|
|
12
12
|
"workspaces": [
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"@milkdown/preset-gfm": "^7.22.3",
|
|
29
29
|
"@milkdown/prose": "^7.22.3",
|
|
30
30
|
"@milkdown/utils": "^7.22.3",
|
|
31
|
-
"@north-light/identity": "0.3.
|
|
32
|
-
"@north-light/plugin": "0.3.
|
|
31
|
+
"@north-light/identity": "0.3.706",
|
|
32
|
+
"@north-light/plugin": "0.3.706",
|
|
33
33
|
"cron-parser": "^5.6.0",
|
|
34
34
|
"esbuild": "0.28.2",
|
|
35
35
|
"jose": "^6.2.12",
|
|
@@ -10667,17 +10667,17 @@
|
|
|
10667
10667
|
},
|
|
10668
10668
|
"packages/crouter-api": {
|
|
10669
10669
|
"name": "@north-light/api",
|
|
10670
|
-
"version": "0.3.
|
|
10670
|
+
"version": "0.3.706",
|
|
10671
10671
|
"license": "UNLICENSED"
|
|
10672
10672
|
},
|
|
10673
10673
|
"packages/crouter-env-docker": {
|
|
10674
10674
|
"name": "@north-light/env-docker",
|
|
10675
|
-
"version": "0.3.
|
|
10675
|
+
"version": "0.3.706",
|
|
10676
10676
|
"license": "UNLICENSED"
|
|
10677
10677
|
},
|
|
10678
10678
|
"packages/crouter-identity": {
|
|
10679
10679
|
"name": "@north-light/identity",
|
|
10680
|
-
"version": "0.3.
|
|
10680
|
+
"version": "0.3.706",
|
|
10681
10681
|
"license": "UNLICENSED",
|
|
10682
10682
|
"dependencies": {
|
|
10683
10683
|
"jose": "^6.2.1"
|
|
@@ -10685,21 +10685,21 @@
|
|
|
10685
10685
|
},
|
|
10686
10686
|
"packages/crouter-plugin": {
|
|
10687
10687
|
"name": "@north-light/plugin",
|
|
10688
|
-
"version": "0.3.
|
|
10688
|
+
"version": "0.3.706",
|
|
10689
10689
|
"license": "UNLICENSED",
|
|
10690
10690
|
"dependencies": {
|
|
10691
|
-
"@north-light/api": "0.3.
|
|
10692
|
-
"@north-light/identity": "0.3.
|
|
10691
|
+
"@north-light/api": "0.3.706",
|
|
10692
|
+
"@north-light/identity": "0.3.706"
|
|
10693
10693
|
}
|
|
10694
10694
|
},
|
|
10695
10695
|
"packages/crouter-sdk": {
|
|
10696
10696
|
"name": "@north-light/sdk",
|
|
10697
|
-
"version": "0.3.
|
|
10697
|
+
"version": "0.3.706",
|
|
10698
10698
|
"license": "UNLICENSED",
|
|
10699
10699
|
"dependencies": {
|
|
10700
|
-
"@north-light/api": "0.3.
|
|
10701
|
-
"@north-light/identity": "0.3.
|
|
10702
|
-
"@north-light/plugin": "0.3.
|
|
10700
|
+
"@north-light/api": "0.3.706",
|
|
10701
|
+
"@north-light/identity": "0.3.706",
|
|
10702
|
+
"@north-light/plugin": "0.3.706",
|
|
10703
10703
|
"jose": "^6.2.1"
|
|
10704
10704
|
},
|
|
10705
10705
|
"bin": {
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { CondensedHistoryMode } from '../../../types.js';
|
|
2
|
-
/** A message from the broker snapshot, structurally. */
|
|
3
|
-
type Message = {
|
|
4
|
-
role?: string;
|
|
5
|
-
customType?: string;
|
|
6
|
-
};
|
|
7
|
-
export declare function isCycleDivider(message: Message): boolean;
|
|
8
|
-
/** Does this message survive into the condensed region? */
|
|
9
|
-
export declare function keepWhenCondensed(message: Message, mode: CondensedHistoryMode): boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Index into `messages` at which the LIVE (fully rendered) region begins.
|
|
12
|
-
*
|
|
13
|
-
* The snapshot is `[cycle 0][divider][cycle 1][divider]…[current cycle]`, so a
|
|
14
|
-
* transcript with D dividers holds D+1 cycles. Keeping the trailing
|
|
15
|
-
* `liveCycles` of them means everything up to and including divider
|
|
16
|
-
* `D - liveCycles` is condensed. Returns 0 — condense nothing — when the node
|
|
17
|
-
* has not yielded often enough to have older cycles, so a fresh or
|
|
18
|
-
* single-yield node renders exactly as it always did.
|
|
19
|
-
*/
|
|
20
|
-
export declare function liveRegionStart(messages: readonly Message[], liveCycles: number): number;
|
|
21
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var s=Object.defineProperty;var r=(t,e)=>s(t,"name",{value:e,configurable:!0});import{CRTR_CYCLE_DIVIDER_CUSTOM_TYPE as m}from"../../../core/runtime/session-cycles.js";const c={none:new Set,user:new Set(["user"]),agent:new Set(["assistant","compactionSummary","branchSummary"]),both:new Set(["user","assistant","compactionSummary","branchSummary"])};function a(t){return t.role==="custom"&&t.customType===m}r(a,"isCycleDivider");function p(t,e){return a(t)?!0:(c[e]??c.none).has(t.role??"")}r(p,"keepWhenCondensed");function f(t,e){const i=Math.max(1,Math.floor(e)),o=[];for(let n=0;n<t.length;n++)a(t[n])&&o.push(n);const u=o.length+1;return u<=i?0:o[u-i-1]+1}r(f,"liveRegionStart");export{a as isCycleDivider,p as keepWhenCondensed,f as liveRegionStart};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// condensed-history.ts — lightweight rendering of a node's OLD cycles.
|
|
2
|
-
//
|
|
3
|
-
// A node that has yielded several times carries every prior cycle in its welcome
|
|
4
|
-
// snapshot (cycleAwareMessages, session-cycles.ts). Cycles older than the trailing
|
|
5
|
-
// `live_cycles` (config, default 2) are condensed to cycle dividers plus whichever
|
|
6
|
-
// messages `condensed_history` (config, default `none`) admits. Tool calls and
|
|
7
|
-
// results are excluded; across six measured sessions they accounted for 62.9% of
|
|
8
|
-
// rendered lines and 69% of transcript build time.
|
|
9
|
-
//
|
|
10
|
-
// Retained messages stay as components inside one nested container. Settled lines
|
|
11
|
-
// are cached at a stable pane width, while a width change rerenders the nested
|
|
12
|
-
// content so old prose wraps with the rest of the transcript.
|
|
13
|
-
//
|
|
14
|
-
// The full detail of a condensed cycle remains in the node's session file, and
|
|
15
|
-
// `/tree` navigates the real branches.
|
|
16
|
-
import { CRTR_CYCLE_DIVIDER_CUSTOM_TYPE } from '../../../core/runtime/session-cycles.js';
|
|
17
|
-
/** Roles admitted by each `condensed_history` mode. `toolResult`,
|
|
18
|
-
* `bashExecution`, and every non-divider `custom` message (crtr output,
|
|
19
|
-
* injected context blocks) are never kept, nor are the tool-call components an
|
|
20
|
-
* assistant message would otherwise spawn — only its prose. The cycle dividers
|
|
21
|
-
* survive every mode, so `none` leaves the seams and nothing else. */
|
|
22
|
-
const ROLES_BY_MODE = {
|
|
23
|
-
none: new Set(),
|
|
24
|
-
user: new Set(['user']),
|
|
25
|
-
agent: new Set(['assistant', 'compactionSummary', 'branchSummary']),
|
|
26
|
-
both: new Set(['user', 'assistant', 'compactionSummary', 'branchSummary']),
|
|
27
|
-
};
|
|
28
|
-
export function isCycleDivider(message) {
|
|
29
|
-
return message.role === 'custom' && message.customType === CRTR_CYCLE_DIVIDER_CUSTOM_TYPE;
|
|
30
|
-
}
|
|
31
|
-
/** Does this message survive into the condensed region? */
|
|
32
|
-
export function keepWhenCondensed(message, mode) {
|
|
33
|
-
if (isCycleDivider(message))
|
|
34
|
-
return true;
|
|
35
|
-
return (ROLES_BY_MODE[mode] ?? ROLES_BY_MODE.none).has(message.role ?? '');
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Index into `messages` at which the LIVE (fully rendered) region begins.
|
|
39
|
-
*
|
|
40
|
-
* The snapshot is `[cycle 0][divider][cycle 1][divider]…[current cycle]`, so a
|
|
41
|
-
* transcript with D dividers holds D+1 cycles. Keeping the trailing
|
|
42
|
-
* `liveCycles` of them means everything up to and including divider
|
|
43
|
-
* `D - liveCycles` is condensed. Returns 0 — condense nothing — when the node
|
|
44
|
-
* has not yielded often enough to have older cycles, so a fresh or
|
|
45
|
-
* single-yield node renders exactly as it always did.
|
|
46
|
-
*/
|
|
47
|
-
export function liveRegionStart(messages, liveCycles) {
|
|
48
|
-
const keep = Math.max(1, Math.floor(liveCycles));
|
|
49
|
-
const dividers = [];
|
|
50
|
-
for (let i = 0; i < messages.length; i++) {
|
|
51
|
-
if (isCycleDivider(messages[i]))
|
|
52
|
-
dividers.push(i);
|
|
53
|
-
}
|
|
54
|
-
const cycles = dividers.length + 1;
|
|
55
|
-
if (cycles <= keep)
|
|
56
|
-
return 0;
|
|
57
|
-
// The last divider that closes a condensed cycle; the live region opens just
|
|
58
|
-
// after it (the divider itself stays in the condensed region as the seam).
|
|
59
|
-
return dividers[cycles - keep - 1] + 1;
|
|
60
|
-
}
|