@orbit-build/cli 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +98 -17
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -274895,6 +274895,8 @@ var WEB_UI_CLIENT_FOUNDATION_SCRIPT = String.raw` const byId = (id) => document
274895
274895
  pendingDelta: '',
274896
274896
  pendingThinking: '',
274897
274897
  animationFrame: 0,
274898
+ streamFlushTimer: 0,
274899
+ lastStreamRenderAt: 0,
274898
274900
  stickToBottom: true,
274899
274901
  eventSource: null,
274900
274902
  eventRetryTimer: 0,
@@ -275641,16 +275643,16 @@ var WEB_UI_CLIENT_MESSAGES_SCRIPT = String.raw` function appendInline(parent, t
275641
275643
  flushList();
275642
275644
  }
275643
275645
 
275644
- function createCodeBlock(languageName, codeText) {
275646
+ function createCodeBlock(languageName, codeText, streaming) {
275645
275647
  const info = String(languageName || '').trim().split(/\s+/).filter(Boolean);
275646
275648
  const language = info.shift() || 'text';
275647
275649
  const descriptor = info.join(' ');
275648
275650
  const source = String(codeText || '');
275649
275651
  const lines = source.split('\n');
275650
275652
  const isDiff = /^(diff|patch)$/i.test(language);
275651
- const isCollapsible = lines.length > 18;
275653
+ const isCollapsible = !streaming && lines.length > 18;
275652
275654
  const root = document.createElement('div');
275653
- root.className = 'code-block' + (isDiff ? ' is-diff' : '') + (isCollapsible ? ' is-collapsed' : '');
275655
+ root.className = 'code-block' + (isDiff ? ' is-diff' : '') + (isCollapsible ? ' is-collapsed' : '') + (streaming ? ' is-streaming' : '');
275654
275656
  root.dataset.language = language.toLowerCase();
275655
275657
  const header = document.createElement('div');
275656
275658
  header.className = 'code-header';
@@ -275893,19 +275895,52 @@ var WEB_UI_CLIENT_MESSAGES_SCRIPT = String.raw` function appendInline(parent, t
275893
275895
  }
275894
275896
  }
275895
275897
 
275896
- function renderRichText(container, value) {
275897
- container.replaceChildren();
275898
+ function repairStreamingInlineTail(text) {
275899
+ const lastBreak = Math.max(text.lastIndexOf('\n'), text.lastIndexOf('\r'));
275900
+ const prefix = text.slice(0, lastBreak + 1);
275901
+ const tail = text.slice(lastBreak + 1);
275902
+ const openMarkers = [];
275903
+ for (const marker of ['\u0060', '**', '~~']) {
275904
+ let cursor = 0;
275905
+ let count = 0;
275906
+ let lastMarker = -1;
275907
+ while (cursor < tail.length) {
275908
+ const markerIndex = tail.indexOf(marker, cursor);
275909
+ if (markerIndex === -1) break;
275910
+ count += 1;
275911
+ lastMarker = markerIndex;
275912
+ cursor = markerIndex + marker.length;
275913
+ }
275914
+ if (count % 2 === 1 && tail.slice(lastMarker + marker.length).trim()) {
275915
+ openMarkers.push({ marker, index: lastMarker });
275916
+ }
275917
+ }
275918
+ openMarkers.sort((left, right) => right.index - left.index);
275919
+ return prefix + tail + openMarkers.map((entry) => entry.marker).join('');
275920
+ }
275921
+
275922
+ function renderRichText(container, value, streaming) {
275898
275923
  const text = String(value || '');
275924
+ const output = document.createDocumentFragment();
275899
275925
  const fence = /\u0060\u0060\u0060([^\n\u0060]*)\n?([\s\S]*?)\u0060\u0060\u0060/g;
275900
275926
  let cursor = 0;
275901
275927
  let match;
275902
275928
  while ((match = fence.exec(text)) !== null) {
275903
- if (match.index > cursor) renderPlainBlocks(container, text.slice(cursor, match.index));
275904
- container.append(createCodeBlock(match[1].trim(), match[2].replace(/\n$/, '')));
275929
+ if (match.index > cursor) renderPlainBlocks(output, text.slice(cursor, match.index));
275930
+ output.append(createCodeBlock(match[1].trim(), match[2].replace(/\n$/, ''), streaming));
275905
275931
  cursor = match.index + match[0].length;
275906
275932
  }
275907
- if (cursor < text.length) renderPlainBlocks(container, text.slice(cursor));
275908
- if (!text) container.textContent = '';
275933
+ const tail = text.slice(cursor);
275934
+ const openFence = streaming
275935
+ ? tail.match(/\u0060\u0060\u0060([^\n\u0060]*)\n?([\s\S]*)$/)
275936
+ : null;
275937
+ if (openFence && openFence.index !== undefined) {
275938
+ if (openFence.index > 0) renderPlainBlocks(output, tail.slice(0, openFence.index));
275939
+ output.append(createCodeBlock(openFence[1].trim(), openFence[2], true));
275940
+ } else if (tail) {
275941
+ renderPlainBlocks(output, streaming ? repairStreamingInlineTail(tail) : tail);
275942
+ }
275943
+ container.replaceChildren(output);
275909
275944
  }
275910
275945
 
275911
275946
  function createThinkingBlock(text, open) {
@@ -276009,7 +276044,7 @@ var WEB_UI_CLIENT_MESSAGES_SCRIPT = String.raw` function appendInline(parent, t
276009
276044
 
276010
276045
  function appendStreamingDiff(payload) {
276011
276046
  if (!state.streaming || !payload || !payload.diff) return;
276012
- const block = createCodeBlock('diff ' + (payload.filePath || ''), payload.diff);
276047
+ const block = createCodeBlock('diff ' + (payload.filePath || ''), payload.diff, false);
276013
276048
  const textBody = state.streaming.textBody;
276014
276049
  if (textBody && textBody.parentNode === state.streaming.content) {
276015
276050
  state.streaming.content.insertBefore(block, textBody);
@@ -276083,8 +276118,7 @@ var WEB_UI_CLIENT_MESSAGES_SCRIPT = String.raw` function appendInline(parent, t
276083
276118
  if (block.type === 'text' && block.text) {
276084
276119
  const body = document.createElement('div');
276085
276120
  body.className = 'rich-text' + (streaming ? ' stream-caret' : '');
276086
- if (streaming) body.textContent = block.text;
276087
- else renderRichText(body, block.text);
276121
+ renderRichText(body, block.text, streaming);
276088
276122
  content.append(body);
276089
276123
  textBody = body;
276090
276124
  } else if (block.type === 'thinking') {
@@ -276182,6 +276216,7 @@ var WEB_UI_CLIENT_MESSAGES_SCRIPT = String.raw` function appendInline(parent, t
276182
276216
  }
276183
276217
 
276184
276218
  function createStreamingTurn(prompt, turnId) {
276219
+ cancelScheduledStreamFlush();
276185
276220
  if (prompt) {
276186
276221
  elements.messages.append(createMessage({
276187
276222
  id: 'optimistic-user-' + turnId,
@@ -276204,6 +276239,7 @@ var WEB_UI_CLIENT_MESSAGES_SCRIPT = String.raw` function appendInline(parent, t
276204
276239
  state.streamText = '';
276205
276240
  state.pendingDelta = '';
276206
276241
  state.pendingThinking = '';
276242
+ state.lastStreamRenderAt = 0;
276207
276243
  setEmptyState();
276208
276244
  state.stickToBottom = true;
276209
276245
  scrollToBottom(true);
@@ -276230,6 +276266,8 @@ var WEB_UI_CLIENT_MESSAGES_SCRIPT = String.raw` function appendInline(parent, t
276230
276266
  }
276231
276267
 
276232
276268
  function flushStream() {
276269
+ if (state.streamFlushTimer) clearTimeout(state.streamFlushTimer);
276270
+ state.streamFlushTimer = 0;
276233
276271
  state.animationFrame = 0;
276234
276272
  if (!state.streaming) return;
276235
276273
  if (state.pendingDelta) {
@@ -276237,7 +276275,8 @@ var WEB_UI_CLIENT_MESSAGES_SCRIPT = String.raw` function appendInline(parent, t
276237
276275
  state.pendingDelta = '';
276238
276276
  state.streaming.textBody.hidden = false;
276239
276277
  state.streaming.progress.hidden = true;
276240
- state.streaming.textBody.textContent = state.streamText;
276278
+ renderRichText(state.streaming.textBody, state.streamText, true);
276279
+ state.lastStreamRenderAt = performance.now();
276241
276280
  }
276242
276281
  if (state.pendingThinking) {
276243
276282
  if (!state.streaming.thinkingBody) {
@@ -276251,8 +276290,36 @@ var WEB_UI_CLIENT_MESSAGES_SCRIPT = String.raw` function appendInline(parent, t
276251
276290
  scrollToBottom(false);
276252
276291
  }
276253
276292
 
276293
+ function streamRenderInterval() {
276294
+ const length = state.streamText.length + state.pendingDelta.length;
276295
+ if (length > 80000) return 100;
276296
+ if (length > 24000) return 64;
276297
+ return 32;
276298
+ }
276299
+
276300
+ function cancelScheduledStreamFlush() {
276301
+ if (state.animationFrame) cancelAnimationFrame(state.animationFrame);
276302
+ if (state.streamFlushTimer) clearTimeout(state.streamFlushTimer);
276303
+ state.animationFrame = 0;
276304
+ state.streamFlushTimer = 0;
276305
+ }
276306
+
276254
276307
  function scheduleStreamFlush() {
276255
- if (!state.animationFrame) state.animationFrame = requestAnimationFrame(flushStream);
276308
+ if (state.pendingThinking && state.streamFlushTimer) {
276309
+ clearTimeout(state.streamFlushTimer);
276310
+ state.streamFlushTimer = 0;
276311
+ }
276312
+ if (state.animationFrame || state.streamFlushTimer) return;
276313
+ const elapsed = performance.now() - state.lastStreamRenderAt;
276314
+ const delay = state.lastStreamRenderAt ? Math.max(0, streamRenderInterval() - elapsed) : 0;
276315
+ if (delay && !state.pendingThinking) {
276316
+ state.streamFlushTimer = window.setTimeout(() => {
276317
+ state.streamFlushTimer = 0;
276318
+ state.animationFrame = requestAnimationFrame(flushStream);
276319
+ }, delay);
276320
+ return;
276321
+ }
276322
+ state.animationFrame = requestAnimationFrame(flushStream);
276256
276323
  }
276257
276324
 
276258
276325
  `;
@@ -277400,7 +277467,7 @@ var WEB_UI_CLIENT_SESSION_SCRIPT = String.raw` const controlCommands = ${WEB_UI
277400
277467
  setBusy(true, copy.working);
277401
277468
  ensureStreamingTurn(data.turn.id);
277402
277469
  } else if (state.busy && !state.submitting) {
277403
- if (state.animationFrame) cancelAnimationFrame(state.animationFrame);
277470
+ cancelScheduledStreamFlush();
277404
277471
  flushStream();
277405
277472
  state.activeTurnId = null;
277406
277473
  setBusy(false, '');
@@ -277867,7 +277934,7 @@ var WEB_UI_CLIENT_SESSION_SCRIPT = String.raw` const controlCommands = ${WEB_UI
277867
277934
 
277868
277935
  async function finishTurn(event) {
277869
277936
  if (event.turnId && state.activeTurnId && event.turnId !== state.activeTurnId) return;
277870
- if (state.animationFrame) cancelAnimationFrame(state.animationFrame);
277937
+ cancelScheduledStreamFlush();
277871
277938
  flushStream();
277872
277939
  const status = event.status || (event.ok === false ? 'failed' : 'completed');
277873
277940
  const failed = status === 'failed';
@@ -282398,7 +282465,21 @@ var WEB_UI_CONVERSATION_STYLES = String.raw`
282398
282465
  color: var(--danger);
282399
282466
  }
282400
282467
 
282401
- .stream-caret::after {
282468
+ .stream-caret > p:last-child::after,
282469
+ .stream-caret > h1:last-child::after,
282470
+ .stream-caret > h2:last-child::after,
282471
+ .stream-caret > h3:last-child::after,
282472
+ .stream-caret > h4:last-child::after,
282473
+ .stream-caret > h5:last-child::after,
282474
+ .stream-caret > h6:last-child::after,
282475
+ .stream-caret > blockquote:last-child::after,
282476
+ .stream-caret > ul:last-child > li:last-child::after,
282477
+ .stream-caret > ol:last-child > li:last-child::after,
282478
+ .stream-caret > .table-scroll:last-child tbody tr:last-child td:last-child::after,
282479
+ .stream-caret
282480
+ > .code-block:last-child
282481
+ .code-line:last-child
282482
+ .code-line-text::after {
282402
282483
  content: "";
282403
282484
  display: inline-block;
282404
282485
  width: 6px;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbit-build/cli",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Local-first AI coding agent CLI, TUI, Web UI, diagnostics, and LSP runtime",
5
5
  "keywords": [
6
6
  "ai",