Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ Nightly builds of `master` are on
second period, so the readable 500 opencode answers handler defects with reads
"… Check server logs for details." instead of ending in "..".

### πŸ“š Documentation

- HQ's redesigned board and session screens show named asks, edit previews, rendered Markdown and
coloured diffs, with Changes and Terminal tabs and an SDK calls dock remembered across reloads.
Permission asks offer Deny, Allow always and Allow once; questions can be submitted or dismissed,
and a running turn can be stopped. Session titles follow later renames, and untitled rows stay
clickable. A session's asks are listed again when its page opens and when one of its turns ends,
so an ask a stopped turn dropped no longer stays on the board.

## [2.0.1] - 2026-11-22

**`2.0.1` pins opencode `2.3.2`.** It is a patch that moves the protocol pin, so generated types
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project>
<ItemGroup>
<!-- third-party analyzers -->
<PackageVersion Include="Markdig" Version="1.6.0" />
<PackageVersion Include="Meziantou.Analyzer" Version="3.0.340" />
<PackageVersion Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="5.6.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.12.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<base href="/" />
<link rel="stylesheet" href="app.css" />
<HeadOutlet @rendermode="new InteractiveServerRenderMode(prerender: false)" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
@inherits LayoutComponentBase
@inject SessionBoard Board
@inject PanelState Panel
@inject Microsoft.JSInterop.IJSRuntime JS
@inject ILogger<MainLayout> Logger

<div class="shell @(Panel.Open ? "sdk-open" : null)">
<header class="top">
<div class="title">OpenCode HQ</div>
<div class="status mono">@(Board.Connected ? "connected" : "not connected")</div>
<a class="button primary" href="/sessions/new">New session</a>
<a class="brand" href="/">OpenCode HQ</a>
<span class="conn" role="status"><span class="mark @(Board.Connected ? "connected" : "lost")"></span><span class="conn-text">@(Board.Connected ? "Connected" : "Not connected")</span></span>
<button type="button" aria-expanded="@(Panel.Open ? "true" : "false")" aria-controls="sdk-dock" @onclick="Panel.Toggle"><span><span class="wide">@(Panel.Open ? "Hide " : "Show ")</span>SDK calls</span></button>
<a class="button" href="/sessions/new">New session</a>
</header>
@Body
</div>
Original file line number Diff line number Diff line change
@@ -1,13 +1,62 @@
using Microsoft.JSInterop;

namespace OpenCode.Playground.Hq.Components;

/// <summary>Every screen's header: the connection and a way to start a session.</summary>
public sealed partial class MainLayout : IDisposable
{
/// <inheritdoc />
public void Dispose() => Board.Changed -= OnChanged;
public void Dispose()
{
Board.Changed -= OnChanged;
Panel.Changed -= OnPanelChanged;
}

/// <inheritdoc />
protected override void OnInitialized()
{
Board.Changed += OnChanged;
Panel.Changed += OnPanelChanged;
}

/// <inheritdoc />
protected override void OnInitialized() => Board.Changed += OnChanged;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender)
{
return;
}

try
{
var stored = await JS.InvokeAsync<string?>("localStorage.getItem", "hq.sdk-calls.open");
if (stored == "true" && !Panel.Open)
{
Panel.Toggle();
}
}
catch (JSException exception)
{
Logger.LogWarning(exception, "Could not read the SDK calls dock preference.");
}
}

private void OnPanelChanged(object? sender, EventArgs args)
{
// The renderer owns this work and reports render faults; storage failures are logged here.
_ = InvokeAsync(async () =>
{
StateHasChanged();
try
{
await JS.InvokeVoidAsync("localStorage.setItem", "hq.sdk-calls.open", Panel.Open ? "true" : "false");
}
catch (JSException exception)
{
Logger.LogWarning(exception, "Could not remember the SDK calls dock preference.");
}
});
}

private void OnChanged(object? sender, EventArgs args)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ internal sealed class SessionConversation(OpenCodeClient client, ILogger<Session
public int EndedTurns { get; private set; }
public string? LastError { get; private set; }

public async Task StopAsync(CancellationToken cancellationToken)
{
#region panel: stop
try
{
_ = await client.Sessions.GetSessionClient(SessionId).InterruptAsync(
new SessionInterruptRequest { Resume = true }, cancellationToken: cancellationToken);
}
catch (OpenCodeException exception)
{
logger.LogWarning(exception, "Could not stop session {SessionId}.", SessionId);
}
#endregion
}

/// <summary>Subscribes before loading history, then follows the session until cancelled.</summary>
public async Task FollowAsync(string sessionId, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,103 @@
@inject SessionBoard Board
@inject ILogger<SessionScreen> Logger

<PageTitle>Session</PageTitle>
<div class="screen">
<main>
<p><a href="/">Back to HQ</a></p>

@if (Conversation.LastError is { } error)
{
<p role="alert">@error</p>
}
@if (Board.LastError is { } boardError)
{
<p role="alert">@boardError</p>
}
@if (_followLost)
{
<p role="alert">Lost the connection to HQ's server. Reload the page to follow this session again.</p>
}

@foreach (var line in Conversation.Lines)
{
<div class="line @line.Author"><span class="who">@line.Author</span>@line.Text</div>
}
@if (Conversation.Running)
{
<p>Working...</p>
}

@foreach (var item in Board.NeedsYou.Where(item => item.SessionId == SessionId))
{
@if (item.Form is not null)
<PageTitle>@Title</PageTitle>
<main class="session">
<header class="session-head">
<h1>@Title</h1>
<p class="meta">
@if (Board.Find(SessionId)?.Location.Directory is { } directory)
{
<span title="@directory">@SessionsScreen.FolderName(directory)</span>
}
@switch (Board.StatusOf(SessionId))
{
case "waiting for you":
<span class="status waiting"><span class="mark decide"></span>Waiting for you</span>
break;
case "running":
<span class="status running"><span class="mark running"></span>Running</span>
break;
default:
<span class="status idle"><span class="mark idle"></span>Idle</span>
break;
}
</p>
</header>
<div class="talk">
@if (Conversation.LastError is { } error)
{
<FormCard @key="item.Id" Form="item.Form" />
<p role="alert">@error</p>
}
else
@if (Board.LastError is { } boardError)
{
<div class="ask">
<div class="ask-text"><div class="ask-kind">Permission</div><div class="mono">@item.Title</div></div>
<button class="primary" @onclick="() => AnswerAsync(item, PermissionReply.Once)">Allow once</button>
<button @onclick="() => AnswerAsync(item, PermissionReply.Reject)">Reject</button>
</div>
<p role="alert">@boardError</p>
}
}

<form class="prompt" @onsubmit="SendAsync" @onsubmit:preventDefault>
<textarea @bind="_prompt" @bind:event="oninput" disabled="@Conversation.Running"></textarea>
<button class="primary" type="submit" disabled="@(!Conversation.Ready || Conversation.Running || string.IsNullOrWhiteSpace(_prompt))">Send</button>
</form>

@if (_followLost)
{
<p role="alert">Lost the connection to HQ's server. Reload the page to follow this session again.</p>
}
<div class="transcript">
@foreach (var line in Conversation.Lines)
{
@if (line.Author == "you")
{
<div class="turn you @(line.Pending ? "pending" : null)"><span class="sr">You: </span>@line.Text</div>
}
else
{
<div class="turn"><span class="sr">Agent: </span><div class="md">@Rendered(line.Text)</div></div>
}
}
</div>
@if (Conversation.Running)
{
<p class="status running"><span class="mark running"></span>Working</p>
}
@if (Board.NeedsYou.Any(item => item.SessionId == SessionId))
{
<section class="queue" aria-labelledby="needs-you-here">
<h2 class="signal" id="needs-you-here"><span class="mark decide"></span>Needs you</h2>
@foreach (var item in Board.NeedsYou.Where(item => item.SessionId == SessionId))
{
@if (item.Form is not null)
{
<FormCard @key="item.Id" Form="item.Form" ShowSession="false" />
}
else
{
<PermissionAsk @key="item.Id" Item="item" ShowSession="false" />
}
}
</section>
}
<form class="composer" @onsubmit="SendAsync" @onsubmit:preventDefault>
<label class="sr" for="prompt">Prompt</label>
<textarea id="prompt" rows="2" placeholder="Send a prompt to this session" @bind="_prompt" @bind:event="oninput" disabled="@Conversation.Running"></textarea>
@if (Conversation.Running)
{
<button type="button" @onclick="StopAsync">Stop</button>
}
else
{
<button type="submit" disabled="@(!Conversation.Ready || string.IsNullOrWhiteSpace(_prompt))">Send</button>
}
</form>
</div>
<aside class="rail" aria-label="Changed files and terminal">
<div class="tabs" role="tablist" aria-label="Session tools">
<button type="button" role="tab" id="tab-changes" aria-selected="@(_terminalTab ? "false" : "true")" aria-controls="panel-changes" @onclick="() => _terminalTab = false">Changes<span class="count">@_changeCount</span></button>
<button type="button" role="tab" id="tab-terminal" aria-selected="@(_terminalTab ? "true" : "false")" aria-controls="panel-terminal" @onclick="() => _terminalTab = true">Terminal</button>
</div>
<div class="tabpanel" role="tabpanel" id="panel-changes" aria-labelledby="tab-changes" hidden="@_terminalTab">
@if (Conversation.Ready)
{
<ChangedFiles SessionId="@SessionId" Running="@Conversation.Running" Refresh="@Conversation.EndedTurns" CountChanged="count => _changeCount = count" />
}
</div>
<div class="tabpanel" role="tabpanel" id="panel-terminal" aria-labelledby="tab-terminal" hidden="@(!_terminalTab)">
<TerminalPanel SessionId="@SessionId" />
</div>
</aside>
</main>
<section class="side" aria-label="Changed files and terminal">
@if (Conversation.Ready)
{
<ChangedFiles SessionId="@SessionId" Running="@Conversation.Running" Refresh="@Conversation.EndedTurns" />
}
<TerminalPanel SessionId="@SessionId" />
</section>
<SdkPanel Entries="PanelEntry.SessionScreen" Guide="https://github.com/opencode-dotnet/opencode-sdk-dotnet/blob/master/docs/guide/streaming.md#-streaming-an-answer-as-it-arrives" />
</div>
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
using Markdig;
using Microsoft.AspNetCore.Components;
using OpenCode.Playground.Hq.Features.Sessions;
using OpenCode.Sdk.Models;

namespace OpenCode.Playground.Hq.Features.Conversation;

/// <summary>One session's conversation, asks, prompt box and changed files.</summary>
public sealed partial class SessionScreen : IDisposable
{
private static readonly MarkdownPipeline Pipeline = new MarkdownPipelineBuilder().DisableHtml().Build();
internal static MarkupString Rendered(string text) => new(Markdown.ToHtml(text, Pipeline));
private readonly CancellationTokenSource _lifetime = new();
private string _prompt = "";
private bool _followLost;
private bool _terminalTab;
private int _changeCount;
private string Title => Board.Find(SessionId)?.Title is { Length: > 0 } title ? title : "Untitled session";

/// <summary>Gets or sets the session shown.</summary>
[Parameter]
Expand All @@ -32,8 +36,14 @@ protected override void OnInitialized()
// The screen owns this follow: it ends with _lifetime, and its faults reach FollowFaulted.
_ = Conversation.FollowAsync(SessionId, _lifetime.Token).ContinueWith(
FollowFaulted, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.Default);
// As upstream's session page does when it opens, the asks shown are the ones the server still lists.
_ = Board.ResyncAsync(SessionId, _lifetime.Token).ContinueWith(
ResyncFaulted, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.Default);
}

private void ResyncFaulted(Task resync) =>
Logger.LogWarning(resync.Exception, "Could not list the asks of session {SessionId}.", SessionId);

private void OnChanged(object? sender, EventArgs args)
{
// The renderer owns this work: a render failure reaches its own error handling, which logs it.
Expand All @@ -58,5 +68,5 @@ private async Task SendAsync()
}
}

private Task AnswerAsync(NeedsYouItem item, PermissionReply decision) => Board.AnswerAsync(item, decision, _lifetime.Token);
private Task StopAsync() => Conversation.StopAsync(_lifetime.Token);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
{
<p role="alert">Changed files are unavailable: @error</p>
}
else if (_loaded)
else if (_diffs.Count == 0)
{
<p class="meta">Nothing changed in the last turn.</p>
}
else
{
<section>
<h3>Changed in the last turn (@_diffs.Count)</h3>
<p class="meta">Changed in the last turn</p>
@foreach (var diff in _diffs)
{
<details>
<summary>@diff.File +@diff.Additions -@diff.Deletions</summary>
<pre>@diff.Patch</pre>
<details class="file">
<summary>@diff.File<span class="plus">+@diff.Additions</span><span class="minus">&minus;@diff.Deletions</span></summary>
<DiffView Patch="@diff.Patch" Label="@($"Patch for {diff.File}")" />
</details>
}
</section>
Expand All @@ -38,6 +42,10 @@ else if (_loaded)
[Parameter]
public bool Running { get; set; }

/// <summary>Gets or sets the callback for the Changes tab's count.</summary>
[Parameter]
public EventCallback<int> CountChanged { get; set; }

/// <inheritdoc />
protected override async Task OnParametersSetAsync()
{
Expand All @@ -55,6 +63,7 @@ else if (_loaded)
_diffs = (await Client.Sessions.GetSessionClient(SessionId).GetDiffAsync()).Diffs;
#endregion
_error = null;
await CountChanged.InvokeAsync(_diffs.Count);
}
catch (OpenCodeException exception)
{
Expand Down
Loading
Loading