npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@summonghost/compaction

v0.1.3

Published

Conversation-compaction policy, controller, and xAI-native adapter

Readme

@summonghost/compaction

Provider-neutral policy helpers and an xAI-native execution adapter for conversation compaction.

import { decideConversationCompaction } from "@summonghost/compaction";

const action = decideConversationCompaction({
  estimatedTokens: 72_000,
  policy: {
    proactiveTokens: 64_000,
    hardLimitTokens: 96_000,
    headroomTokens: 8_000,
  },
});

The package also exports stable compaction keys and stale-write guards. It has no runtime service and never owns provider credentials.

For stateful model loops, createConversationCompactionController owns effective-history reconciliation and proactive-versus-blocking coordination. Provider work stays behind injected callbacks:

const controller = createConversationCompactionController({
  policy,
  countInputTokens: ({ messages }) => tokenCounter(messages),
  createSnapshot: ({ messages, sequence }) =>
    summarizer({ messages, sequence }),
  applySnapshot: ({ snapshot }) => [renderSummary(snapshot)],
  scheduleCompaction: ({ run }) => backgroundQueue.enqueue(run),
});

hardLimitTokens is the threshold at which preparation must block; configure it low enough that the provider call creating the snapshot can still accept its source. After applying a blocking snapshot, the controller counts the replacement and throws ConversationCompactionLimitError instead of returning context that still reaches the hard limit.

The controller verifies that subsequent raw history extends the previously observed prefix before appending only its suffix. Replaced, truncated, or same-length-mutated history resets the effective view instead of reusing a stale summary. If no scheduler is supplied, proactive compaction is skipped and the controller waits for the blocking threshold.

Object messages should supply messagesEqual; the default Object.is comparison treats re-created objects as a changed branch.

Once proactive work is accepted, the controller keeps that source marked pending for the lifetime of the observed history branch. This prevents repeated background scheduling before the consumer applies its durable checkpoint. Background runs are invalidated when their observed history branch is replaced, and a failed run releases the pending marker so a later preparation may reschedule it. Preparation calls are serialized inside each controller. latestBlockingSnapshot() reports only the snapshot applied synchronously; background snapshots belong to the scheduler's durable lifecycle.

xAI native compaction

createXaiCompactionAdapter owns xAI's /tokenize-text and /responses/compact request bodies, opaque compaction-item validation, native usage parsing, conservative preflight counting, and timeout signals. The consumer injects an authenticated transport and therefore retains credentials, gateway selection, request metadata, and billing:

import { createXaiCompactionAdapter } from "@summonghost/compaction";

const xaiCompaction = createXaiCompactionAdapter({
  request: ({ body, conversationId, path, signal }) =>
    fetch(`${configuredXaiBaseUrl}${path}`, {
      method: "POST",
      headers: {
        authorization: configuredAuthorization,
        "content-type": "application/json",
        ...(conversationId && { "x-grok-conv-id": conversationId }),
      },
      body: JSON.stringify(body),
      signal,
    }),
});

const result = await xaiCompaction.compactInput({
  model: "grok-4.5",
  items: nativeResponsesInput,
  conversationId,
});

The transport contract never receives or discovers an application API key. It receives only the provider path, JSON body, optional conversation identifier, and an abort signal. Native checkpoint persistence and conversion from application messages remain consumer concerns.

Preflight tokenization measures serialized Responses input. Provider-side expansion of files or other structured items is not observable through /tokenize-text; consumers should carry forward known provider usage and reserve model-appropriate headroom for those inputs.

See Ghostkit for source and design notes.