Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

3.7 KB
Raw Blame
---
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';

// The demo VM and its guide are defined in docs/demos/demoshell/. `snapshot`
// is the VM's Demoshell reference; it changes if the VM moves to another
// Demoshell org or is renamed.
const server = 'https://build.demoshell.com';
const snapshot = 'm/tui:worktrunk';
const launchUrl = `${server}/launch?snapshot=${encodeURIComponent(snapshot)}`;
---

<StarlightPage
  frontmatter={{
    title: 'Try Worktrunk in a demo shell',
    description: 'Try Worktrunk in a demo shell',
    editUrl: false,
    tableOfContents: false,
    pagefind: false,
    head: [{ tag: 'meta', attrs: { name: 'robots', content: 'noindex' } }],
  }}
>
  <div class="wt-try-it" data-server={server} data-snapshot={snapshot}>
    <noscript>
      <p><a href={launchUrl}>Open the demo</a></p>
    </noscript>
  </div>
  <p class="wt-try-it-link">
    <a href={launchUrl}>Open the full-page demo in Demoshell</a>
  </p>
</StarlightPage>

<style>
  .wt-try-it-link {
    margin-block: 0.75rem 0;
  }

  /* The workspace uses the main pane's width while the title stays in the docs rail. */
  .wt-try-it {
    height: var(--wt-workspace-height, max(420px, calc(100svh - 16rem)));
    /* Keep Demoshell's attribution badge clear of the guide controls. */
    padding-block-end: 2rem;
  }

  :global(html:has(.wt-try-it) main) {
    padding-block-end: 0;
  }

  :global(html:has(.wt-try-it) main footer) {
    display: none;
  }
</style>

<script is:inline type="module">
  const target = document.querySelector('.wt-try-it');
  const fullPageLink = document.querySelector('.wt-try-it-link');
  const currentTheme = () => (document.documentElement.dataset.theme === 'dark' ? 'dark' : 'light');

  const fitWorkspace = () => {
    const { top, bottom } = target.getBoundingClientRect();
    const spaceBelowWorkspace = fullPageLink.getBoundingClientRect().bottom - bottom;
    const panel = target.closest('.content-panel');
    const panelStyle = getComputedStyle(panel);
    const left = target.closest('.main-pane').getBoundingClientRect().left
      + parseFloat(panelStyle.paddingInlineStart);
    const rightPadding = parseFloat(panelStyle.paddingInlineEnd);
    const bottomPadding = parseFloat(panelStyle.paddingBlockEnd);
    target.style.marginInlineStart = `${left - target.parentElement.getBoundingClientRect().left}px`;
    target.style.width = `${document.documentElement.clientWidth - left - rightPadding}px`;
    const documentTop = top + window.scrollY;
    target.style.setProperty('--wt-workspace-height', `${Math.max(420, window.innerHeight - documentTop - spaceBelowWorkspace - bottomPadding)}px`);
  };
  fitWorkspace();
  window.addEventListener('resize', fitWorkspace);
  // Refit when the heading or link reflows, including late font loads.
  const layoutObserver = new ResizeObserver(fitWorkspace);
  layoutObserver.observe(document.querySelector('h1'));
  layoutObserver.observe(fullPageLink);

  try {
    const { default: Demoshell } = await import(`${target.dataset.server}/embed/demoshell-embed.js`);
    const demo = await Demoshell.mount(target, {
      snapshot: target.dataset.snapshot,
      server: target.dataset.server,
      theme: currentTheme(),
    });
    // Follow the site's theme toggle, as the page around the demo does.
    new MutationObserver(() => demo.setTheme?.(currentTheme())).observe(document.documentElement, {
      attributes: true,
      attributeFilter: ['data-theme'],
    });
  } catch (error) {
    const link = document.createElement('a');
    link.href = `${target.dataset.server}/launch?snapshot=${encodeURIComponent(target.dataset.snapshot)}`;
    link.textContent = 'Open the demo on Demoshell';
    target.replaceChildren(link);
    console.error('[try-it] demo failed to load', error);
  }
</script>