wavetermdev/waveterm · error

Cannot get last command data without shell integration

Error message

Cannot get last command data without shell integration

What it means

When a termgetscrollbacklines request asks for lastcommand metadata, the terminal must have shell integration active (prompt markers/command tracking). If the shell integration status atom is null, no such data can be derived, so the handler throws instead of returning wrong boundaries.

Source

Thrown at frontend/app/view/term/term-wsh.tsx:127

        rh: RpcResponseHelper,
        data: CommandTermGetScrollbackLinesData
    ): Promise<CommandTermGetScrollbackLinesRtnData> {
        const termWrap = this.model.termRef.current;
        if (!termWrap || !termWrap.terminal) {
            return {
                totallines: 0,
                linestart: data.linestart,
                lines: [],
                lastupdated: 0,
            };
        }

        const buffer = termWrap.terminal.buffer.active;
        const totalLines = buffer.length;

        if (data.lastcommand) {
            if (globalStore.get(termWrap.shellIntegrationStatusAtom) == null) {
                throw new Error("Cannot get last command data without shell integration");
            }

            let startBufferIndex = 0;
            let endBufferIndex = totalLines;
            if (termWrap.promptMarkers.length > 0) {
                // The last marker is the current prompt, so we want the second-to-last for the previous command
                // If there's only one marker, use it (edge case for first command)
                const markerIndex =
                    termWrap.promptMarkers.length > 1
                        ? termWrap.promptMarkers.length - 2
                        : termWrap.promptMarkers.length - 1;
                const commandStartMarker = termWrap.promptMarkers[markerIndex];
                startBufferIndex = commandStartMarker.line;

                // End at the last marker (current prompt) if there are multiple markers
                if (termWrap.promptMarkers.length > 1) {
                    const currentPromptMarker = termWrap.promptMarkers[termWrap.promptMarkers.length - 1];
                    endBufferIndex = currentPromptMarker.line;

View on GitHub (pinned to a4447c1563)

Solutions

  1. Enable/install shell integration for the running shell (source the provided integration script in the shell rc).
  2. Retry only after shellIntegrationStatusAtom is non-null; poll or subscribe instead of assuming.
  3. Set lastcommand:false (or omit it) if you only need raw scrollback lines.
  4. Verify the shell/term environment actually reports integration status (check termWrap.shellIntegrationStatusAtom).

Example fix

// before
const lines = await RpcApi.TermGetScrollbackLines(controller, { lastcommand: true });
// after
const hasIntegration = globalStore.get(termWrap.shellIntegrationStatusAtom) != null;
const lines = await RpcApi.TermGetScrollbackLines(controller, { lastcommand: hasIntegration });
Defensive patterns

Strategy: fallback

Validate before calling

const status = globalStore.get(termWrap.shellIntegrationStatusAtom);
if (data.lastcommand && status == null) {
  // degrade: request without lastcommand metadata
  data = { ...data, lastcommand: false };
}

Type guard

function hasShellIntegration(termWrap: TermWrap): boolean {
  return globalStore.get(termWrap.shellIntegrationStatusAtom) != null;
}

Try / catch

try {
  return await getScrollbackLines(data);
} catch (e) {
  if (String(e.message).includes("without shell integration")) {
    // fall back to plain scrollback without last-command boundaries
    return await getScrollbackLines({ ...data, lastcommand: false });
  }
  throw e;
}

Prevention

When it happens

Trigger: Requesting scrollback with lastcommand:true while the shell lacks integration (plain bash/sh without osc prompt hooks), the integration script failed to load, or the terminal just started and status was never set.

Common situations: Using minimal/ exotic shells without Wave's shell-integration hooks, connecting over ssh without the integration being injected, or users disabling shell integration in settings.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/d882d1c1a8ac302a. Report an issue: GitHub.