PPhraseNacre
AI coding workspace

LZ78 phrase tokens

PhraseNacre is a Windows coding workspace for examining dictionary-based byte encoders. Share the relevant project files, discuss LZ78 phrase growth and inspect how the suggested code marks a trailing known phrase.

● ● ●PhraseNacre●
A concrete starting point · LZ78 phrase tokens ×
def lz78_tokens(data):
    if type(data) is not bytes or len(data) > 4096:
        raise ValueError("lz78.input")
    dictionary, phrase, output = {b"": 0}, b"", []
    for byte in data:
        extended = phrase + bytes([byte])
        if extended in dictionary:
            phrase = extended
        else:
            output.append((dictionary[phrase], byte))
            dictionary[extended] = len(dictionary)
            phrase = b""
    if phrase:
        output.append((dictionary[phrase], None))
    return output
✳Encode at most 4096 bytes into LZ78 dictionary-index and next-byte pairs.
✓ ChangesReview before applying ↗
Illustrative workspace
01

Review before applying

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

02

Connection

Base URL, credentials and a reachable server.

03

Project

Test empty and repeated input, using a final null byte marker only for a phrase already in the dictionary.

Workflows

LZ78 phrase tokens

Workflows ↗
A concrete starting point
def lz78_tokens(data):
    if type(data) is not bytes or len(data) > 4096:
        raise ValueError("lz78.input")
    dictionary, phrase, output = {b"": 0}, b"", []
    for byte in data:
        extended = phrase + bytes([byte])
        if extended in dictionary:
            phrase = extended
        else:
            output.append((dictionary[phrase], byte))
            dictionary[extended] = len(dictionary)
            phrase = b""
    if phrase:
        output.append((dictionary[phrase], None))
    return output
AI coding workspace

Treat encoded output as an interface other code must read

PhraseNacre provides a Windows project workspace for developing code that transforms bytes into a representation consumed elsewhere. Begin with the source folder and the agreement between producer and reader. Ask the model to inspect that interface before proposing an encoder change, because an output that looks more compact may no longer mean the same thing to its consumer.

For a concrete task, use lz78.py to discuss how a trailing known phrase is represented. Supply short byte fixtures with repeated content and the token sequence the reader expects. The conversation can then focus on whether a proposed edit preserves the termination convention, rather than assuming every pair of encoder and decoder implementations shares one format.

Inspect the reader alongside the changed producer and run your own project checks. Include empty input, a repeated phrase and distinct bytes, with independent expected outputs where practical. A round trip is useful evidence, but also compare existing fixtures so two changed components do not agree on an incompatible new format without the review noticing.

You choose the assisting model through a supported OpenAI-compatible or Anthropic endpoint, including credentials when required. Abliterated AI models are available only where the endpoint offers them; provider restrictions still apply. Tool access and context limits depend on the chosen model and server, while format compatibility remains an explicit project requirement.

Questions for an encoder change

Why inspect the reader during an encoder patch?

The output is an interface, including any marker used for a trailing phrase. A producer can emit internally consistent tokens that the existing reader interprets differently. Review both sides and retain old fixtures so a small encoder change does not silently alter the format.

Is a successful round trip sufficient?

It is useful, but two components changed together can share the same mistake. Compare independently specified token examples and existing encoded fixtures as well. State which compatibility direction matters, such as whether the current reader must still accept previously produced data.

Should text be converted to bytes inside this routine?

Only under an explicit encoding contract. The example accepts bytes, so moving text conversion into it changes the interface. Inspect where the application currently chooses a character encoding and preserve that boundary unless the requested feature deliberately moves it.

Can I claim better compression after shortening the code?

No. Source length does not establish output size or workload performance. Keep the review focused on the requested behavior, and use an appropriate separate measurement if compression characteristics matter. Report only results from the actual fixtures and implementation you tested.

Get the Windows app ↗

PhraseNacre · Updated 2026-10-25