<script lang="ts">
// How big each worktree's logs may grow: the workshop's one limit.
//
// Every operation started from the workbench is written to a file in its
// worktree's logs, so this is the setting that decides how much of the past
// a page can still show. What one worktree's logs hold is that worktree's
// Settings.
import SettingsSection from "./SettingsSection.svelte";
import { workshopSettings } from "../../stores/workshop-settings.svelte.js";
import SizeSlider from "./SizeSlider.svelte";
const GB = 1024 * 1024 * 1024;
/**
* The largest cap worth offering.
*
* Not a limit the daemon enforces — it accepts anything at or above its
* minimum — but the top of the slider's travel. Past this the setting stops
* being a cap and becomes "never sweep", which is what turning the sweep off
* is for.
*/
const MAX_BYTES = 256 * GB;
let localMax: number = $state(workshopSettings.logs.max_bytes);
$effect(() => {
localMax = workshopSettings.logs.max_bytes;
});
const dirty = $derived(localMax !== workshopSettings.logs.max_bytes);
/** Lowering the limit sweeps every open worktree's logs down to it at once. */
const lowering = $derived(dirty && localMax < workshopSettings.logs.max_bytes);
async function save() {
await workshopSettings.save({ logs: { max_bytes: localMax } });
}
</script>
<SettingsSection
title="Logs"
description="Every operation run from the workbench is written to a file in its worktree's logs, so its output survives closing the tab, restarting the daemon, and however much the run says. What one worktree's logs hold is in that worktree's Settings."
>
<div class="setting-row">
<span class="setting-label">Maximum size of each worktree's logs</span>
<SizeSlider
value={localMax}
min={workshopSettings.logs.min_bytes}
max={MAX_BYTES}
onchange={(bytes) => (localMax = bytes)}
/>
</div>
<p class="setting-note">
As the limit is reached, whole logs are removed oldest first — a whole
operation, a whole test session — and never one that is being written.
</p>
{#if lowering}
<p class="setting-warn">
Saving a lower limit removes the oldest logs of every open worktree
holding more, at once.
</p>
{/if}
{#if dirty}
<div class="save-row">
<button class="save-btn" disabled={workshopSettings.saving} onclick={save}>
{workshopSettings.saving ? "Saving..." : "Save"}
</button>
</div>
{/if}
</SettingsSection>
<style>
.setting-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: var(--wb-spacing-12);
padding: var(--wb-spacing-8) 0;
}
.setting-label {
font-size: var(--wb-font-size-12);
color: var(--vscode-foreground);
}
.setting-note {
margin: var(--wb-spacing-4) 0 0;
font-size: var(--wb-font-size-11);
color: var(--vscode-descriptionForeground, #999);
}
.setting-warn {
margin: var(--wb-spacing-4) 0 0;
font-size: var(--wb-font-size-11);
color: var(--vscode-editorWarning-foreground, #cca700);
}
.save-row {
display: flex;
justify-content: flex-end;
}
.save-btn {
height: var(--wb-control-size-28);
padding: 0 var(--wb-spacing-16);
border-radius: var(--wsb-radius-sm);
font-size: var(--wb-font-size-12);
font-weight: 500;
color: white;
background: var(--vscode-focusBorder);
border: none;
cursor: pointer;
}
.save-btn:disabled {
opacity: 0.6;
cursor: default;
}
</style>