@volter/supercode-frontend-vscode 0.1.15 → 0.1.16

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/extension.js +115 -34
  2. package/package.json +1 -1
package/dist/extension.js CHANGED
@@ -8,7 +8,7 @@ import { readCredentialFile } from './credential.js';
8
8
  import { grantedProposals, PROPOSAL_EFFECTS, REQUESTED_PROPOSALS } from './proposals.js';
9
9
  import { observeActiveResponse, sessionStatus } from './native-session.js';
10
10
  import { RequestNotPendingError, VscodeFrontendSession } from './session.js';
11
- import { fence, acceptedDecisions, opaqueText, projectEvent, projectPendingRequests, projectHistory, projectReplayTurns, resolveParts, resolutionSentence, typedAnswer, } from './view.js';
11
+ import { acceptedDecisions, opaqueText, projectEvent, projectPendingRequests, projectHistory, projectReplayTurns, resolveParts, resolutionSentence, typedAnswer, } from './view.js';
12
12
  const SESSION_SCHEME = 'supercode';
13
13
  const PARTICIPANT_ID = 'supercode.chat';
14
14
  const DEFAULT_PARTICIPANT_ID = 'supercode.chat.default';
@@ -324,9 +324,17 @@ export async function activate(context) {
324
324
  const boundId = (resource) => resolveSessionBinding(resource, controls?.state.sessions ?? [], resourceBindings);
325
325
  let applying = Promise.resolve();
326
326
  const frontends = new SupercodeFrontends();
327
+ // Runtimes attached by address ("Set Runtime Token", "Attach to Runtime")
328
+ // beside a host's managed conversation. The host's catalogue does not know
329
+ // them, so they open as what they are: attachments, shown as their runtime
330
+ // reports them, and never taken for the conversation the host manages.
331
+ const attachedIds = new Set();
332
+ const managed = () => frontends.all.find((connection) => !attachedIds.has(connection.id));
333
+ // The attached runtime the person is looking at: the Chat names its harness, not the host's.
334
+ let focusedAttached;
327
335
  let approvalAvailable = false;
328
336
  context.subscriptions.push(frontends.onDidChange(() => {
329
- const active = frontends.get(undefined);
337
+ const active = managed();
330
338
  const available = Boolean(active?.session.descriptor?.actions.respond && active.session.permissions.has('approve'));
331
339
  if (available !== approvalAvailable) {
332
340
  approvalAvailable = available;
@@ -334,7 +342,9 @@ export async function activate(context) {
334
342
  }
335
343
  }));
336
344
  const identity = () => {
337
- const descriptor = frontends.get(undefined)?.session.descriptor;
345
+ if (focusedAttached)
346
+ return runtimeIdentity(focusedAttached.session.descriptor?.source_harness, focusedAttached.session.descriptor?.model);
347
+ const descriptor = managed()?.session.descriptor;
338
348
  return runtimeIdentity(controls?.state.selection.harness ?? descriptor?.source_harness, controls?.state.selection.model || controls?.state.actualModel || descriptor?.model);
339
349
  };
340
350
  const icon = () => {
@@ -384,7 +394,8 @@ export async function activate(context) {
384
394
  const existing = frontends.get(id);
385
395
  if (existing && existing.baseUrl === env.SUPERCODE_FRONTEND_URL)
386
396
  return existing;
387
- await frontends.disconnect();
397
+ for (const connection of frontends.all.filter((entry) => !attachedIds.has(entry.id)))
398
+ await frontends.disconnect(connection.id);
388
399
  const connection = await frontends.connect({ connectionId: id, baseUrl: env.SUPERCODE_FRONTEND_URL,
389
400
  token: await readCredentialFile(env.SUPERCODE_FRONTEND_CREDENTIAL_FILE), clientId: env.SUPERCODE_FRONTEND_CLIENT_ID,
390
401
  permissions: normalizePermissions(env.SUPERCODE_FRONTEND_PERMISSIONS, ['observe']), label: identity().name }, log);
@@ -405,10 +416,17 @@ export async function activate(context) {
405
416
  throw new Error('This conversation is no longer connected.');
406
417
  return connection;
407
418
  }
419
+ const attached = attachedIds.has(resource.authority) ? frontends.get(resource.authority) : undefined;
420
+ if (focusedAttached !== attached) {
421
+ focusedAttached = attached;
422
+ controlsChanged.fire();
423
+ }
424
+ if (attached)
425
+ return attached;
408
426
  const id = boundId(resource);
409
427
  if (!id)
410
428
  throw new Error('This chat has no backend session binding. Start a new chat; no message was sent.');
411
- const active = frontends.get(undefined);
429
+ const active = managed();
412
430
  if (active && active.id !== id && (active.session.descriptor?.turn_state === 'busy' || active.session.pendingRequests.size))
413
431
  throw new Error('Finish or cancel the active turn before opening another conversation.');
414
432
  try {
@@ -432,7 +450,7 @@ export async function activate(context) {
432
450
  async function applySelection(selection, openChat = true) {
433
451
  if (!controls)
434
452
  throw new Error('This host does not expose harness or model configuration.');
435
- const active = frontends.get(undefined);
453
+ const active = managed();
436
454
  if (active?.session.descriptor?.turn_state === 'busy' || active?.session.pendingRequests.size)
437
455
  throw new Error('Finish or cancel the current turn before starting a new chat.');
438
456
  await controls.select(selection);
@@ -454,7 +472,7 @@ export async function activate(context) {
454
472
  currentOptions,
455
473
  options: (resource) => {
456
474
  const id = resource ? boundId(resource) : undefined;
457
- const active = resource ? (id ? frontends.get(id) : undefined) : frontends.get(undefined);
475
+ const active = resource ? (id ? frontends.get(id) : undefined) : managed();
458
476
  const canApprove = active?.session.descriptor?.actions.respond && active.session.permissions.has('approve');
459
477
  const permissionItems = [{ id: 'ask', name: canApprove ? 'Ask for approval' : 'Harness permissions', description: canApprove ? 'Show each approval requested by the harness.' : 'Approval controls are unavailable for this harness.' },
460
478
  ...((canApprove || (!active && resource && currentOptions(resource).permissions === 'autoApprove')) ? [{ id: 'autoApprove', name: 'Auto approve', description: 'Allow tool approval requests for this chat. Harness sandbox rules still apply.' }] : [])];
@@ -479,6 +497,7 @@ export async function activate(context) {
479
497
  return connection;
480
498
  },
481
499
  resolve: connectionFor,
500
+ attached: (connection) => attachedIds.has(connection.id),
482
501
  catalogue: () => controls?.state.sessions ?? [],
483
502
  bindings: boundId,
484
503
  };
@@ -578,7 +597,7 @@ export async function activate(context) {
578
597
  }
579
598
  finally {
580
599
  cancellation.dispose();
581
- if (controls) {
600
+ if (controls && !attachedIds.has(connection.id)) {
582
601
  if (connection.session.descriptor?.session_id)
583
602
  await controls.remember(connection.id, connection.session.descriptor.session_id).catch(error => log.warn(`Could not save conversation identity: ${String(error)}`));
584
603
  await controls.refresh().catch(error => log.warn(`Could not refresh chat identity: ${String(error)}`));
@@ -591,8 +610,8 @@ export async function activate(context) {
591
610
  const requestedResource = chatContext.chatSessionContext?.chatSessionItem?.resource;
592
611
  const connection = requestedResource
593
612
  ? await connectionFor(requestedResource)
594
- : controls ? undefined : frontends.get(undefined);
595
- if (controls && connection && request.model?.vendor === 'supercode-runtime') {
613
+ : controls ? undefined : managed();
614
+ if (controls && connection && !attachedIds.has(connection.id) && request.model?.vendor === 'supercode-runtime') {
596
615
  const selection = controls.state.sessions.find(s => s.id === connection.id).selection;
597
616
  const expected = `${selection.harness}/${encodeURIComponent(selection.model || '__default__')}`;
598
617
  if (request.model.id !== expected || (typeof request.modelConfiguration?.reasoningEffort === 'string' && request.modelConfiguration.reasoningEffort !== selection.effort)) {
@@ -652,7 +671,7 @@ export async function activate(context) {
652
671
  // canDelegate is disabled to avoid a generic workbench-owned registration.
653
672
  // A participant names the harness; the native model picker names the model.
654
673
  // Keep the author stable when a model changes during request dispatch.
655
- const participantName = () => harnessDisplayName(controls?.state.selection.harness ?? frontends.get(undefined)?.session.descriptor?.source_harness);
674
+ const participantName = () => harnessDisplayName(focusedAttached?.session.descriptor?.source_harness ?? controls?.state.selection.harness ?? managed()?.session.descriptor?.source_harness);
656
675
  const participantKey = () => `${participantName()}/${identity().provider ?? ''}`;
657
676
  const makeParticipant = () => {
658
677
  const current = { name: participantName() };
@@ -792,11 +811,16 @@ export async function activate(context) {
792
811
  log.info('Volter Harness: a base URL is configured but no token is stored; run Volter Harness: Set Runtime Token.');
793
812
  return;
794
813
  }
795
- await frontends
814
+ const connection = await frontends
796
815
  .connect({ baseUrl, token, permissions: normalizePermissions(settings.get('permissions'), ['observe']) }, log)
797
816
  .catch((error) => {
798
817
  log.error(`Volter Harness could not attach to ${baseUrl}: ${String(error?.message ?? error)}`);
818
+ return undefined;
799
819
  });
820
+ if (controls && connection) {
821
+ attachedIds.add(connection.id);
822
+ controlsChanged.fire();
823
+ }
800
824
  }
801
825
  /**
802
826
  * The handover path: a runtime (or a product that launched this editor's
@@ -903,10 +927,79 @@ export function deactivate() {
903
927
  // Every disposable is owned by the extension context.
904
928
  }
905
929
  /**
906
- * One rendered part as the markdown a HISTORY turn carries. A replayed turn is
907
- * built from `ChatResponseMarkdownPart`s only — the live part types belong to a
908
- * running stream — so a tool row becomes its own one-line summary rather than
909
- * the JSON of the object that would have drawn it.
930
+ * A tool call reaches a turn as two parts, its start and its completion, which
931
+ * a live stream draws as one row because the editor merges them by
932
+ * `toolCallId`. A HISTORY turn is markdown and merges nothing, so each call
933
+ * showed twice ("Tool call: exec" and again with its output). The start keeps
934
+ * its place and its description (the command it ran); the completion gives it
935
+ * its output and outcome.
936
+ */
937
+ function oneRowPerToolCall(parts) {
938
+ const rows = [];
939
+ const started = new Map();
940
+ for (const part of parts) {
941
+ if (part.part === 'tool' && part.toolCallId) {
942
+ const at = started.get(part.toolCallId);
943
+ const first = at === undefined ? undefined : rows[at];
944
+ if (first && first.part === 'tool' && part.isComplete) {
945
+ rows[at] = {
946
+ ...first,
947
+ ...part,
948
+ pastTenseMessage: first.invocationMessage ?? part.pastTenseMessage,
949
+ invocationMessage: first.invocationMessage ?? part.invocationMessage,
950
+ };
951
+ continue;
952
+ }
953
+ if (!part.isComplete)
954
+ started.set(part.toolCallId, rows.length);
955
+ }
956
+ rows.push(part);
957
+ }
958
+ return rows;
959
+ }
960
+ /**
961
+ * A saved turn's parts, drawn as the live stream draws them. The editor
962
+ * converts a history turn's response with the same converter as a live
963
+ * response (`convertResponseTurn` maps every part through it), so a tool call
964
+ * is the same `ChatToolInvocationPart` row it was while it ran; only the text
965
+ * between tools is markdown, consecutive text joined into one part. A turn
966
+ * looks the same however late the Chat was opened.
967
+ */
968
+ function historyParts(parts) {
969
+ const out = [];
970
+ let text = [];
971
+ const flush = () => {
972
+ if (text.length)
973
+ out.push(new vscode.ChatResponseMarkdownPart(text.join('\n\n')));
974
+ text = [];
975
+ };
976
+ for (const part of parts) {
977
+ if (part.part === 'tool') {
978
+ flush();
979
+ const toolName = part.toolName || 'tool';
980
+ const invocation = new vscode.ChatToolInvocationPart(toolName, part.toolCallId);
981
+ invocation.invocationMessage = part.invocationMessage || toolName;
982
+ invocation.pastTenseMessage = part.pastTenseMessage || part.invocationMessage || toolName;
983
+ invocation.isConfirmed = true;
984
+ invocation.isComplete = part.isComplete;
985
+ if (part.isError !== undefined)
986
+ invocation.isError = part.isError;
987
+ if (part.isComplete) {
988
+ invocation.toolSpecificData = { input: part.inputText ?? '', output: part.resultText ?? '' };
989
+ }
990
+ out.push(invocation);
991
+ continue;
992
+ }
993
+ const value = historyText(part);
994
+ if (value)
995
+ text.push(value);
996
+ }
997
+ flush();
998
+ return out.length ? out : [new vscode.ChatResponseMarkdownPart('')];
999
+ }
1000
+ /**
1001
+ * One text part as the markdown a HISTORY turn carries (tool calls are drawn
1002
+ * as tool rows by `historyParts`).
910
1003
  */
911
1004
  function historyText(part) {
912
1005
  switch (part.part) {
@@ -921,17 +1014,9 @@ function historyText(part) {
921
1014
  return part.value;
922
1015
  case 'reference':
923
1016
  return `\`${part.path}\``;
924
- case 'tool': {
925
- // No `<details>` here: a HISTORY turn's markdown is rendered without raw
926
- // HTML, so the tags show up as text — observed. A replayed tool is one
927
- // line plus its output, fenced.
928
- const summary = part.pastTenseMessage ?? part.invocationMessage ?? part.toolName;
929
- if (!summary)
930
- return '';
931
- const verb = part.isError ? 'Tool failed:' : 'Tool call:';
932
- const result = part.resultText ? `\n\n${fence(part.resultText)}` : '';
933
- return `${verb} \`${summary}\`${result}`;
934
- }
1017
+ case 'tool':
1018
+ // Drawn as a tool row by `historyParts`.
1019
+ return '';
935
1020
  case 'answers':
936
1021
  return `**${part.title}**\n\n${part.message}`;
937
1022
  }
@@ -1051,7 +1136,7 @@ function registerSessions(context, frontends, participant, granted, handler, con
1051
1136
  if (!connection) {
1052
1137
  return { history: [], requestHandler: boundHandler };
1053
1138
  }
1054
- if (controls) {
1139
+ if (controls && !controls.attached(connection)) {
1055
1140
  controls.setPermission(resource, inputState.groups.find(group => group.id === 'permissions')?.selected?.id);
1056
1141
  inputState.groups = controls.options(resource);
1057
1142
  }
@@ -1097,16 +1182,12 @@ function registerSessions(context, frontends, participant, granted, handler, con
1097
1182
  history.push(new turns.ChatRequestTurn(turn.prompt ?? '', undefined, [], participant.id, []));
1098
1183
  continue;
1099
1184
  }
1100
- const markdown = (turn.parts ?? [])
1101
- .map(historyText)
1102
- .filter(Boolean)
1103
- .join('\n\n');
1104
- history.push(new turns.ChatResponseTurn([new vscode.ChatResponseMarkdownPart(markdown)], {}, participant.id));
1185
+ history.push(new turns.ChatResponseTurn(historyParts(oneRowPerToolCall(turn.parts ?? [])), {}, participant.id));
1105
1186
  }
1106
1187
  const busy = connection.session.descriptor?.turn_state === 'busy';
1107
1188
  return {
1108
1189
  title: connection.label,
1109
- options: controls?.currentOptions(resource),
1190
+ options: controls?.attached(connection) ? undefined : controls?.currentOptions(resource),
1110
1191
  history,
1111
1192
  requestHandler: boundHandler,
1112
1193
  activeResponseCallback: busy
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@volter/supercode-frontend-vscode",
3
3
  "displayName": "Volter Harness",
4
- "version": "0.1.15",
4
+ "version": "0.1.16",
5
5
  "type": "module",
6
6
  "description": "VS Code chat-view frontend for an existing Volter Harness SDK runtime",
7
7
  "publisher": "volter-ai-dev",