Metadata-Version: 2.4
Name: doppelcode
Version: 0.7.0b11
Summary: A private twin of your code for AI agents: the AI works on the twin, its edits merge back into the original
Author-email: DoppelCode <doppelcode.license@gmail.com>
License-Expression: PolyForm-Noncommercial-1.0.0
Project-URL: Homepage, https://github.com/doppelcode/doppelcode
Project-URL: Source, https://github.com/doppelcode/doppelcode
Project-URL: Issues, https://github.com/doppelcode/doppelcode/issues
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# DoppelCode - a private twin of your code for AI agents

![Original code vs the twin the AI sees](https://raw.githubusercontent.com/doppelcode/doppelcode/main/docs/before_after.png)

**Version:** 0.7.0b11 (public beta)

**Date:** 2026-12-03

DoppelCode lets you use AI coding agents on proprietary code while reducing what an AI sees of your code. It
writes a **twin** of your project: the same code with your names and file names replaced by placeholders.
By default, comments are hidden in source, build and script files (`comments: hide`) and names are replaced
inside strings (`strings: scrub`); `strings: hide` replaces whole strings too. Optionally your tuned constants are hidden and your
core function bodies left out. The AI works only on the twin. `doppel import` merges its edits back into
your original with the real names, and DoppelCode records what was sent to the AI, so you can show later
which parts of your code an AI was given.

Python 3.11+, no third-party packages. Optional: gcc/g++ or clang (header harvesting, compile check), git
(3-way merge).

## Quick Start (5 minutes)

```
pip install doppelcode                           # installs the doppel command (or: python -m doppelcode ...)
pip install .                                    # or: install from source, in a clone of this repo
doppel init   path/to/project                    # optional: writes .doppel/config.json with the defaults
doppel export path/to/project --out path/to/twin # writes the twin
```

On Windows, pip may say *The script doppel.exe is installed in '...\Scripts' which is not on PATH*. Then
`doppel` is not found: add that folder to your user `Path` (Settings > System > About > Advanced system
settings > Environment Variables; open a new terminal afterwards), or run every command as
`py -m doppelcode ...` instead of `doppel ...`. The VS Code extension uses `py -m doppelcode` by itself
when `doppel` is not found.

1. Open **the twin folder, not the original**, in your agent (Claude Code, GitHub Copilot agent, Cursor,
   or paste it into a chat). The twin has an `AGENTS.md` / `CLAUDE.md` that tells the agent the rules.
2. Let the agent work in the twin as usual.
3. `doppel import path/to/project` merges the agent's changes into your original, with your names.
4. `doppel check path/to/project` verifies the round trip, scans the twin for leaks and compiles both
   versions (C / C++ machine code is compared; Python syntax trees are compared).
5. `doppel report path/to/project` shows which function bodies were made available to an AI, and when.

## Protection Levels

| Level | What the AI sees | Config |
|---|---|---|
| Names only | your code with names and file names replaced; comments hidden in source, build and script files; names replaced inside strings (`scrub`); with `strings: hide`, whole strings replaced | default `comments: hide`, `strings: scrub`, `build_names: rename` |
| + secret constants | tuned values and tables replaced by `K_` aliases with dummy values | `secret_symbols`, `secret_values`, `secret_files` |
| + withheld functions | the signature only; the body stays on your PC | `core_functions`, `core_modules` |

Pilot results (DeepSeek, DeepThink on; two small projects, one in C and one in Python; one chat per project
and condition). The attack question asked for every value and whether the core functions could be rebuilt:

| Round | Protection | Values recovered | "Can rebuild the core functions" | Tasks done automatically |
|---|---|---|---|---|
| 2 | Names only | all, in both projects | yes | 6 of 6 |
| 2 | + secrets + withheld | 4 of 16 tones, 3 of 4 symbols (from test code); one unmarked pair | no | 4 of 6 (the 2 others were changes inside withheld bodies, done by the owner) |
| 4 | + secrets + withheld (after the round 2 fixes) | none | no | 3 of 6, 1 partly right, 2 change requests in plain words |

These are small pilots with one model; they show the direction, not a guarantee.

### The defaults and the trade-off (0.7.0b10)

| Setting | Default | Why | To change |
|---|---|---|---|
| `comments` | `hide` | comments often say what the code is for, who wrote it and for whom; hiding them (in source, build and script files) does not change how the twin builds or runs | `"comments": "scrub"` keeps comments with your names replaced (better AI answers, the comment text is visible to the AI) |
| `strings` | `scrub` | strings are data: hiding them changes what the twin does at runtime (curl's twin no longer recognises its own options; 603 of librosa's 1,957 tests fail). An agent that runs tests in the twin would then "fix" failures that exist only there, and import would bring those edits back | `"strings": "hide"` for projects whose messages or keys are sensitive; the twin may then behave differently at runtime |
| `build_names` | `rename` | Makefile and CMake targets and options made of your names (`falcon_selftest`) would tell the AI your names | `"build_names": "keep"`. With `rename`, the twin's build options are renamed too (`-DCURL_USE_LIBPSL=OFF` is `-Dw_0688=OFF` in the twin): `doppel translate --to-twin` translates a configure command |

Configs written before 0.7.0b10 keep their values; `doppel init` prints how to switch.

## Languages

| Language | Files | What is renamed | Library names kept by | Verified by `check` |
|---|---|---|---|---|
| C | `.c .h` | every identifier | system headers the code includes | compile + machine code |
| C++ | `.cpp .cc .cxx .hpp .hh ...` | every identifier | system / STL headers (via g++) | compile + machine code |
| Python | `.py .pyw .pyi` | names the project declares | public names of imported modules (read, never run), builtins | syntax trees |
| C# | `.cs` | names the project declares | keyword / BCL lists, member rule | compile (csc) |
| Java | `.java` | names the project declares | keyword / JDK lists, member rule | compile (javac) |
| JavaScript / TypeScript | `.js .mjs .jsx .ts .tsx` | names the project declares | keyword / runtime lists, member rule | compile, syntax only (Node) |

For the "declared" languages, a name is kept when it is used as a member of something the project
does not declare (`os.path`, `sb.Append`, `crypto.createHash`), when it is imported from an outside
module, when it is a keyword argument to a library call (`json.dumps(indent=2)`), or when it is a
method of a class derived from a library class (unittest `setUp`, `Thread.run`). Python packages
(folders with `__init__.py`) are renamed together with their imports; Java files take their public
class's new name. Code inside `f"{x}"`, `$"{x}"` and `` `${x}` `` is always translated, strings that
name code (`getattr(o, "x")`, `__all__`, `obj["x"]`, reflection) are renamed with it, and module
names (`require("crypto")`, `import ... from "lib"`) are never hidden.

Machine code is compared against a names-only version of the twin (strings and comments untouched),
so the comparison proves that renaming changed no code whatever the string policy. With strings set
to `keep`, a Python twin prints exactly what the original prints.

`check` also builds Java, C# and JS / TS. The original is built first; if it does not build with the
tool found, its files are listed as NOT CHECKED with the reason, so only errors the twin alone has
count. The twin's code is never run (javac without annotation processors, csc without analyzers,
JS / TS only compiled). Tools are found automatically and can be set in `.doppel/config.json`:

| Key | Default search |
|---|---|
| `javac` | PATH, `JAVA_HOME`, `~/.jdks`, Program Files JDKs, Android Studio's `jbr` |
| `csc` | Visual Studio Roslyn, .NET SDK, then the .NET Framework `csc` (C# 5 only: install the .NET SDK for newer C#) |
| `node` | PATH, Program Files, then VS Code's built-in Node (TypeScript types are stripped by Node) |

With strings set to `keep`, file and folder names inside path strings (`require("./falconRadio")`,
`fopen("rec_01.dat")`) are still renamed, so the twin finds its renamed modules and data files.

## Desktop app

A desktop app is planned for a later release. This beta is the `doppel` command line; everything below
works with it.

## Workflow

```
python -m doppelcode init   <project>            # optional: write .doppel/config.json to tune policies
python -m doppelcode export <project> [--out DIR] # create/refresh the twin (default <parent>/twin_<hash>)
   ... point the AI agent at the twin folder, let it edit ...
python -m doppelcode import <project>             # merge the AI's changes into the original
python -m doppelcode check  <project> --objects   # round trip, leak scan, compile + machine-code compare
python -m doppelcode lookup <project> fn_0005     # translate a name either way
python -m doppelcode translate <project> --to-twin      # a request to the AI, in real names (stdin)
python -m doppelcode translate <project> --to-original  # the AI's reply, back to the real names
```

`import` performs a 3-way merge per file: the AI's changes are applied even if you edited the
original in the meantime. Only overlapping edits produce `<file>.doppel-merge` (with conflict
markers; the original is left untouched). `export` refuses to run until those are resolved.

`init` writes the defaults, with your OS user name and git `user.name` (and its words) as
`sensitive_terms`, so `check` reports them anywhere in the twin. A term under 4 letters (a user name
`ted`) is matched as a whole word only, so it does not flag "tested"; `init` lists such terms. Longer
terms match inside words too. An existing config is not changed.

### Where the twin is, and copied or moved projects

The twin goes where `--out` says, or `twin_dir` in the config, or into `twin_root` as `twin_<hash>`, or else
next to the project as `twin_<hash>` (before 0.7.0b9 the default name was `obf_<hash>`; an existing project keeps
the twin it remembers, and an `obf_<hash>` folder from before is still used).

**A neutral twin folder** (0.7.0b11). The agent sees the twin's full path, and next to the project that path holds
the names of the folders above it, which in a company often name a customer, a product or a team. Set a folder that
says nothing, for all new twins of a project:

```
doppel init <project> --twin-root C:\doppel-twins        # or "twin_root" in .doppel/config.json
```

New twins then go to `C:\doppel-twins\twin_<hash>` (the hash says nothing about the project). A twin exported
before stays where it is until you run `export --out <folder>\twin_<hash>` once. `check` prints a hint when the
twin's path holds one of your `sensitive_terms` or a part of the project's folder name. `doppel init` prints the same
tip until a `twin_root` is set; the default stays next to the project.

The vault also records the project's own path:

- **Moved** (the old folder is gone): the twin stays; `export` notes the move.
- **Copied** with its `.doppel` folder (the old folder still has its own): the copy must not use the other
  project's twin. `import` and `check` refuse until `export` has run in the copy, and that `export` writes a new
  twin for it (`twin_<hash>` next to the copy, or `--out`) and leaves the other twin alone. A vault from before
  0.7.0b9 has no recorded path: if its twin's default name belongs to another path, `export` says so; give
  such a copy its own twin with `--out`.
- A project that has both `.doppel` and an old `.cobf` folder uses the one with the vault (`.doppel` when both
  have one) and every command warns until you keep only one.

### Review before applying (`--preview`)

```
python -m doppelcode import <project> --preview DIR                        # see what import would write
python -m doppelcode import <project> --from-preview DIR                   # apply all of it
python -m doppelcode import <project> --from-preview DIR --only src/a.c    # or one file
```

`--preview DIR` runs the whole import, 3-way merge included, but writes the result to `DIR` at the same
relative paths (a conflict as `<file>.doppel-merge`) and prints the list of files. Nothing in the project,
the twin, the vault or `.doppel/config.json` changes. `DIR` must be outside the project and the twin, and
empty or an earlier preview (which is replaced). `DIR/.doppel-preview.json` records, per file, the twin
file and the original as they were.

`--from-preview DIR` applies exactly what was previewed, with the preview's `--rename` / `--accept`. It
refuses, and writes nothing, when a twin file or an original changed since the preview: preview again.
Applied files leave the manifest, so the rest can be applied later. The VS Code extension uses this for
its review view.

### Files that are not UTF-8, and line ends

DoppelCode keeps every file's bytes: a Windows-1255 or Windows-1252 file goes into the twin in its own
encoding (with `comments: hide` its comments do not go at all) and comes back the same, except the lines the
AI changed. An AI agent's editor often saves such a twin file as UTF-8 (replacement characters, or the code
page decoded). Import gives every line whose only change is that re-encoding its original bytes back, and
writes the lines the AI did change in the file's code page when it can tell which one it is (`encoding:` in
the output). Line ends do not take part in the merge: the AI adding LF lines to a CRLF file, or your editor
saving the file again with one style, is not a change; changed lines take the original's style.

### Writing to the AI in real names (`translate`)

```
python -m doppelcode translate <project> --to-twin     [--text TEXT | --file FILE] [--json]
python -m doppelcode translate <project> --to-original [--text TEXT | --file FILE] [--json]
python -m doppelcode translate <project> --to-original --stream     # a filter: stdin -> stdout, line by line
```

`--to-twin` translates a request you write with the project's real names to the names the AI sees in the
twin; `--to-original` translates the AI's reply back. The text comes from stdin unless `--text` or `--file`
gives it. Both read only `.doppel` and write nothing.

`--to-original --stream` is a filter for an AI agent's live output (the VS Code extension's Agent panel uses
it): it reads stdin line by line, writes each line translated as soon as it is complete (UTF-8, flushed
after every line, line ends kept) and exits with 0 when stdin ends. It prints no warnings.

- Whole identifiers only, case-sensitive: `sample_rate_hz` is one name, never `sample_rate` plus `_hz`.
- A name that is a plain English word (`block`, `key`, `state`) is translated where the text is code (in
  backticks, in a code fence, or next to code punctuation such as `block[i]`, `ctx->key`, `key(...)`); in prose
  it stays a word, so "encrypt the first block" does not become "encrypt the v_0030 v_0008".
- File paths, with `/` or `\`, follow the twin (`Utils/Utils_ReadWriteFile.c` -> `Utils/mod_0001.c`).
- A withheld function becomes its `B_` id; its body and purpose line are never used.
- Back to the original: the same reverse translator as `import`, so names the AI coined from a placeholder
  (`fn_0005_checked`) come back as import restores them, `K_` names show the real value and `str_` / `cmt_`
  ids the real text. Placeholder-style names the vault does not know stay as they are, with a warning.

`--to-twin` warns, and never blocks, about: a sensitive term (`sensitive_terms`, the project folder name, the
OS user name, git `user.name`), a number or text equal to a secret constant's value, a word or phrase that is
part of a real name (`Falcon`, "sample rate"), an identifier-shaped word the vault does not know (it may be a
real name the twin does not cover), and a real file path (absolute, or a project file the twin does not have).
`leak_allow` silences a word. A single word of a real name that is also a common English word (`round`,
`first`, `chain`) is reported as information, not as a warning: almost every request has such words, so they
tell the AI little. A phrase that spells out a real name ("sample rate") stays a warning. Exit code 0 without
warnings (information alone included), 3 with warnings (on stderr as `warning:` and `info:` lines, or in the
JSON), 2 on an error. `--json` prints `text`, `replacements` (`from`, `to`, `count`) and `warnings` (`kind`,
`severity` (`warning` or `info`), `text`, `position`, `line`, `column`, `length`, `detail`) in ASCII.

### Names the AI coins in DoppelCode's style

AI models often name new things like the placeholders they see (`v_0048`, `fn_0017`, `"str_0013"`).
Mapped back blindly, a new parameter `v_0048` would become an unrelated existing name
(`fips_expected`), and a new string `"str_0013"` would become an existing text (`"ALL PASS"`).
On the lines the AI added or changed, `import` therefore flags:

- a known alias in a declaration position (function, parameter, local, field, type, macro) that
  the old version of the file did not declare;
- an alias-shaped name that is not in the vault (`fn_0017`);
- a string literal that is exactly `"str_NNNN"` and was not in the old version of the file.

Plain uses of existing names map silently. Flagged files are **not merged**; the findings go to
the console and to `.doppel/import_review.txt`. Resolve them and import again:

```
python -m doppelcode import <project> --rename v_0048=nonce --rename fn_0017=falcon_ctr_crypt
python -m doppelcode import <project> --rename "str_0013=Decrypt failed"
python -m doppelcode import <project> --accept v_0017      # keep as written (known alias: its vault meaning)
python -m doppelcode import <project> --accept             # accept every finding
```

A renamed name gets its own alias in the vault and the twin file is rewritten with it, so twin,
vault and original agree from then on.

`export` also writes `AGENTS.md` and `CLAUDE.md` into the twin root (unless the project has its
own) asking the agent to give new things plain names, and a `.doppel-twin` marker, a small JSON file
(`"doppelcode": "twin"`) that tools such as the VS Code extension use to know a twin folder. The marker names
nothing of the project. `import` ignores all three files.

## Example (samples/aes_project)

```c
/* original */                                   /* twin */
void falcon_encrypt_block(                       void fn_0002(
    const FalconAesContext *ctx,                     const T_0001 *v_0006,
    uint8_t block[FALCON_BLOCK_SIZE]);               uint8_t v_0008[M_0002]);
#include "falcon_aes.h"                          #include "mod_0001.h"
```

The names are gone, and with the default config the comments are hidden and the Makefile's `falcon_selftest`
target is renamed. The strings still say "Falcon", and `check` says so. Copy `samples/aes_project` somewhere first
(`export` writes `.doppel` into the project):

```
doppel export aes_project --out aes_twin
doppel check  aes_project
round trip:  OK
leaks:       3 line(s) - full list in ...\aes_project\.doppel\leaks.txt
  by kind:   name part 3
  src/main.c:8: name part 'falcon' in Falcon
  src/main.c:54: name part 'falcon' in FalconLinkKey01
  src/main.c:55: name part 'falcon' in FalconInitVec01
  3 line(s) of source files have parts of your names in strings ('scrub' keeps that text). Fix: "strings": "hide"
  in .doppel/config.json, then export again (with strings hidden, the twin may behave differently at runtime); or
  add words that may stay (a public product name) to "leak_allow".
  name parts by word: 3 line(s) from 1 word(s): falcon (3)
  Words that may stay (a public product name): add to .doppel/config.json:
    "leak_allow": ["falcon"]
hints:       name parts that are common or technical words, not counted as leaks: decrypt (2), encrypt (2), link (1)
compile:     2 C/C++ file(s), 0 twin-only error(s)
```

`check` exits with 1: the twin's strings still say `"Falcon telemetry frame #42: altitude=1200m"` and
`"FalconLinkKey01"`. The fix: hide the strings, then export and check again:

```
doppel export aes_project --strings hide
doppel check  aes_project
round trip:  OK
leaks:       none
compile:     2 C/C++ file(s), 0 twin-only error(s)
```

`check` exits with 0. The other way: list the words that may stay visible in `leak_allow`
(`"leak_allow": ["falcon"]`); the strings then stay as they are. Words such as `encrypt` or `link` are common
technical words: `check` lists them as hints, not as leaks.

## Secret constants

Renaming hides names, but in DSP or classifier code the numbers are often the real know-how:
thresholds, coefficients, tuning tables. Marked numbers are replaced in the twin by aliases
`K_0001`, `K_0002`, ...; the vault keeps the real values and `import` puts them back.

| Way to mark | Example | Hides |
|---|---|---|
| Line tag | `x = 145  # doppel:secret` | every number on that line, or a table starting there as a whole |
| `secret_symbols` | `["male_threshold", "lpc_order"]` | every number assigned to that name: assignments, `self.x = ...`, default values, keyword arguments (original names) |
| `secret_values` | `["0.97", "3.3"]` | every number with that value: an integer mark `"145"` hides every form (`145`, `145.0`, `0x91`, `1.45e2`); a float mark `"3.0"` hides `3.0`, `3.` and `3.0f` but not the integer `3`. Also inside strings and comments (even with `keep`) and in f-string code (`f"{0.97 * x:.2f}"`); format specifications such as `"%.2f"` and the `.2f` of `{x:.2f}` are never touched, JSON / dict text (`{"gain": 0.97}`) is not a format spec |
| `secret_files` / `secret_functions` | `["dsp/"]` / `["src/f.c::gate"]` | every `secrets suggest` candidate in these files / functions (values and table names; in a function only inside it) |

```
python -m doppelcode secrets suggest <project> [--all] [--top N]   # ranked: tables, algorithm constants,
                                                       # thresholds, the rest (top 50 by default)
python -m doppelcode secrets list <project> [--show-values]
```

- **A marked value is hidden everywhere** in the code (each place gets its own alias), and in
  comments and strings too when they are `scrub`bed. `check` fails if the value is still visible
  anywhere in the twin, also written as `0x91`, `1.45e2` or inside a string.
- `0`, `1`, `-1`, `2` and `0.5` are never hidden by value list (only at a tagged or named place),
  and never count as leaks.
- **The twin still runs.** A twin-only file gives every alias a neutral dummy value, and each file
  that uses one gets a marked line that `import` removes again:

  | Language | Dummy file (twin root) | Line added to each file |
  |---|---|---|
  | Python | `doppel_secrets.py`: `K_0001 = 1.0`, tables `[0] * n` | `from doppel_secrets import K_...  # DoppelCode` after the imports |
  | C / C++ | `doppel_secrets.h`: `#define K_0001 (1.0f)`, tables `{0, 0, ...}` (same length) | `#include "../doppel_secrets.h" /* DoppelCode */` after the first include |

  In C a table initializer is replaced as a whole (`static const uint8_t k_rcon[10] = K_0001;`,
  the size kept), and `#define NAME 0x1b` works with `secret_symbols` too. The dummy file is
  never imported; if the AI edits it, the import reports "secret value change requested" and
  keeps the real value.
- `check` compiles / parses the dummy twin, and compares the original with the twin **with the
  real values put back** (C: machine code, Python: syntax trees).
- If the AI replaces an alias by a literal (`K_0003` -> `3.5`), the file is not merged until you
  decide: `--accept K_0003` takes 3.5, `--rename K_0003=@keep` keeps the secret,
  `--rename K_0003=@secret` takes 3.5 and adds it to `secret_values`.
- The elements of a secret table are hidden wherever else they are written in the same form (a test
  generator that hard-codes `400.0` from the tone table), and in comments and strings in any form
  (`400Hz`). Small integers (-15..15) and powers of two stay visible: they are indexes, loop bounds,
  sizes and bit masks. `doppel secrets suggest` lists the functions that write such values - consider
  withholding them.
- Values computed from secrets (`145 * 2` written as `290`) are out of scope.

Supported for Python, C and C++.

With withheld functions or secret constants set, `strings` defaults to `hide` (banners and help
texts would still tell the purpose); set `"strings"` in `.doppel/config.json` to choose otherwise.
One-word mode strings passed straight to a library call (`filterwarnings("ignore")`,
`btype="band"`, `encode("utf-8")`) stay, so the twin still runs. Python dict keys are one class: in
`scrub` and `hide` every identifier-shaped key (`'pitch'`, `'f1'`, `'spectral_centroid'`) gets an
alias, so the keys do not list what a withheld function computes. Only keys of a library's dict stay
(`os.environ["PATH"]`, a dict literal handed to a library call); a key that merely matches a
library name (`'f2'`) is still aliased. A library dict is also followed through names
(`devs = sd.query_devices()`, `for d in devs`: `d['max_input_channels']` stays, in `hide` too).
In the text of a function that uses a secret table (its name, one of its values, or a table linked
by indexing such as `frequencies[target_sequence[i]]`), the table's small integers are hidden too
("Symbol 10" -> "Symbol K_0012"); elsewhere small numbers stay. With protected code and
`"strings": "scrub"`, `check` prints a warning with an example string.

## Withheld functions (optional)

Choose functions the AI may call but not read. In the twin their body becomes a stub; everything
else is renamed as before:

```python
def fn_0004(self, v_0005):
    raise NotImplementedError("doppel: body withheld (B_0001)")
```
```c
static void fn_0009(uint8_t v_0021[16])
{ /* doppel: body withheld (B_0002) */ }

float fn_0002(const float* v_0014, int v_0015, double v_0016, double v_0017)
{ /* doppel: body withheld (B_0003) */ return (float){0}; }
```

A non-void C function returns a zero value (`return (T){0};`, C++ `return {};`), so the twin builds
with `-Werror=return-type`; a Python stub raises, so a twin-side test fails where the function is
called, not later with a `None`.

- **Choosing:** in `.doppel/config.json`:
  `"core_functions": ["detector.py::Detector.classify", "src/filter.c::design_lowpass", "detector.py::Detector"]`
  (a class withholds all its methods), `"core_modules": ["dsp/", "secret_algo.py"]` (whole files).
- **Import** puts the real bodies back byte for byte; edits elsewhere merge as usual. If the AI
  changes or removes a withheld body, the file is not merged until you take its version with
  `--accept B_0001`.
- **A change inside a withheld function:** the AI is told to describe it in plain words instead of
  editing the stub, so you apply it yourself. Or release the body for one session:
  `doppel withhold release PROJECT B_0001 --reason "widen the pitch range"`. The next export sends the body, the AI's edit merges as usual, and the
  export after it withholds the function again. The release and the send are both in the exposure
  ledger. `doppel withhold list PROJECT` shows the ids.
- **Purpose line (optional):** `doppel withhold purpose PROJECT B_0002 "returns (gender, confidence) for
  one chunk"` (or right-click it in the outline) lists that line in the twin's `AGENTS.md`, so the AI
  calls the right withheld function. Off unless you write one; it tells the AI the function's role,
  not its body (names and secret values in it are translated). In pilot round 4 the AI called the
  feature extractor where the gender decision was meant; both were withheld.
- **check:** the dummy twin still parses / compiles to objects; the machine-code comparison uses
  the full-body copy, so it stays exact; Python syntax trees are compared without the withheld bodies.
- **Exposure:** withheld functions are logged as `declaration`, not `body`, so `doppel report` and the
  budgets show the real share (e.g. 15 of 17 bodies, 88%).
- Python, C and C++ (Java and C# need typed stubs; later). The twin's `AGENTS.md` / `CLAUDE.md` tell
  the agent not to implement or change withheld functions.

## Exposure ledger

Every `export` records which function bodies it made available to an AI in
`.doppel/ledger.jsonl` (append-only, kept as an audit trail). A body is logged when it is new or
changed, or when it is sent again to a new twin folder (`"repeat": true`); a plain refresh adds
nothing.

```
python -m doppelcode report <project>                 # per folder
python -m doppelcode report <project> --by function   # first / last sent, how often
python -m doppelcode report <project> --since 2026-11-01

Exposure report - what was made available to an AI (not what it read)
folder  functions  bodies sent  share   secrets withheld
src/           17           17   100%        6
```

**Budgets:** `"exposure_budget": {"dsp/": 0.3}` stops an export that would make more than that share
of a folder's function bodies available; `export --allow-over-budget` exports anyway and records
the override in the ledger. With today's full twin every exported folder is at 100%, so a budget
acts as a guard ("never export dsp/") until declarations-only export (core modules) exists.

## Key config options (`.doppel/config.json`)

| Key | Default | Meaning |
|---|---|---|
| `keep`, `keep_prefixes`, `keep_regex` | `[]` | names never renamed (e.g. vendor `HAL_`) |
| `exclude` | `[]` | third-party folders: copied verbatim, their names kept |
| `comments` | `hide` | `scrub` replaces mapped names inside comments, `keep` leaves them, `hide` replaces each whole comment by a placeholder in the file's own syntax (`/* cmt_0007 */`, `// cmt_0007`, `# cmt_0007` in Python, Makefiles and CMake files; same line count) that `import` restores. Set it with `export --comments hide` |
| `strings` | `scrub` | `scrub` replaces mapped names inside strings, `keep` leaves them, `hide` replaces each string literal by an id and keeps its format skeleton (`"Sample rate: %d Hz\n"` -> `"str_0002 %d\n"`), restored on `import` (also around the AI's edits). `check --objects` compares machine code against a names-only twin, so it works with every string setting. Set it with `export --strings hide` |
| `data_files` | `none` | `build`: text files that build files name (generated docs, symbol lists) are copied, so the project's own build works; with `none` they are listed in `.doppel/build_inputs.txt` and export prints a note. `copy`: also the data files the code reads, under their aliases. File and folder names in strings always get file-shaped aliases when strings are `scrub`/`hide` (`"InputFiles//"` -> `"dir_0001//"`, `"rec_01.dat"` -> `"file_0001.dat"`); with `copy`, every file in a folder the code names (or named itself) goes to the twin, so the twin program still finds its inputs. Import ignores these folders (no data or program output comes back). Set it with `export --data copy` |
| `rename_files` | `true` (not set: `false` with a CMake build or build files that compute paths) | rename file names; `false` keeps file and folder names (and CMake target names), so the project's own build finds them |
| `keep_test_names` | `true` | in a pytest project, keep `test_*` / `Test*` names, `pytest_*` hooks and pytest's fixture names so the twin's tests run (the names are visible); `false` hides them |
| `rename_words` | `[]` | extra words to rename everywhere |
| `build_names` | `rename` | `rename`: in Makefiles / CMake files, words made of the project's name parts (`TARGET := falcon_selftest`) get `w_` aliases, so the build produces a renamed binary, and the build's own options are renamed too (configure the twin with the twin's names). With `keep`, `check` reports them as leaks. Set it with `export --build-names keep` |
| `sensitive_terms` | `[]` (`init`: your OS user name and git `user.name`) | words that `check` reports if still present in the twin (and `translate --to-twin` warns about): inside other words from 4 letters, as whole words under 4 |
| `accept_file_names` | `false` | `true`: you accept that the twin keeps your file and folder names (CMake builds, `rename_files: false`); `check` then reports them in one hint line instead of failing |
| `twin_root` | (none) | a neutral folder for new twins (`<twin_root>/twin_<hash>`); see "Where the twin is". Set it with `init --twin-root` |
| `leak_allow` | `[]` | words and names `check` and `translate` accept (a public project name, a copyright holder); secret values and absolute paths are always reported |
| `naming` | `kind` | `kind` (fn_/v_/T_/M_) or `opaque` (id_ for all) |

Files that are not source, build or known text files are **not copied** to the twin (they may leak); add
them to `copy_verbatim` if the AI needs them. Build templates, packaging files, scripts (`.sh`, `.pl`,
`#!` files without an extension) and text files a build file names are copied; scripts are never
imported as new files, and changes to existing ones are listed for review.

## Security

The twin is written by an AI agent, so DoppelCode treats it as untrusted:

- **Import** accepts new files only if they are C sources or known text files outside hidden folders.
  Scripts (`.bat`, `.ps1`, `.sh`), binaries, Windows device names and anything under `.github`,
  `.vscode`, `.git` and similar are reported as `BLOCKED` and never written. Changed build and
  config files (Makefile, `*.mk`, `*.json`, ...) are listed under *Review before building*.
- **Links**: symlinks and junctions inside the twin are never followed (reported as `IGNORED (link)`),
  and `export` refuses to write or delete through them. `export` also refuses to take over a
  non-empty folder it did not create (`--force` to override).
- **Compile check**: if a twin file includes something outside the twin (absolute, `..` or UNC
  `\\host\share` paths, which would make Windows connect to that host), the compiler is not run.
- **Leak scan** also reports absolute paths, the project folder name and the Windows user name (as
  a path segment, an e-mail or a handle only, so a user `root` does not flag "rooted"). Absolute
  paths in build, script and text files (toolchain folders, the source checkout) become `$(DOPPEL_PATH_0001)` in
  the twin and come back on import, whatever user name they hold: since 0.7.0b11 also a quoted path with spaces
  (`"C:\Program Files\Vendor Tools\bin"`, whole) and a path right after a compiler or linker option
  (`-IC:/sdk/include`, `-LC:\lib`, `/LIBPATH:C:\lib`). `check` reports, as "absolute path", any that still
  reaches the twin, for example in a source file's string. Prose that spells a renamed name out ("read audio file" for
  `read_audio_file`) is listed under `hints:`; it does not fail the check (`hide` removes it).
- **Parts of your names in comments and strings** (0.7.0b9): `scrub` replaces whole names, so
  `/* Falcon link self-test */` or `"FalconLinkKey01"` stay. `check` reports such parts (4+ letters, used in
  at least two of your names, `falcon` from `falcon_encrypt_block` and `FalconAesContext`) in comments and
  strings of source files, as it does in build files. A part that is also a common English or technical word
  (`link`, `round`, `symbol`, `frequency`, `samples`) is listed under `hints:`, not as a leak (0.7.0b10), unless
  it is one of your `sensitive_terms`. The project's folder name counts the same way: a name made of such words
  (`AudioSequence`) gives hints, a codename (`Atlas_fw`, `Mercury`) is always reported. Name-part leaks are
  grouped by word, with a ready `leak_allow` line. Fix: `comments` / `strings: hide`, or `leak_allow`.
- **Author lines** (0.7.0b9): `Author:`, `@author`, `Created by`, `Written by`, `Copyright (c) <year> <name>`
  and `__author__ = ...` lines left in the twin are leaks. `check` groups them by name (500 identical
  copyright headers are one entry with a count) and prints a `"leak_allow": [...]` line to copy, or use
  `comments: hide`.
- **Import checks its snapshots** (0.7.0b9): `import` compares the AI's edits with the twin as DoppelCode wrote it
  (`.doppel/twin_base`) and merges them against the original as of the last sync (`.doppel/base`). Each snapshot
  has its hash in the vault. If one changed since (an agent with access to the project edited it), `import`
  refuses and names the files. Delete a changed `twin_base` file and `import` rebuilds it from the base copy;
  delete a changed `base` file and `import` writes the AI's version of that file next to the original
  (`<file>.doppel-incoming`) for you to merge. A vault from before 0.7.0b9 gets the base hashes at its next export.
- **Large projects:** `check` prints a leak summary (counts by kind, the top files, 30 examples, secret
  values and absolute paths first) and writes the full list to `.doppel/leaks.txt` (`--leaks-all` prints
  it). `"leak_allow": ["opus"]` accepts words such as a public project name; secret values and
  absolute paths are always reported. Build and CLI words (cmake, version, option, enable, ...) are not
  name parts. Headers and modules export could not find are counted and listed in `.doppel/missing.txt`.
- **Includes:** the compile check refuses a twin whose `#include` is absolute, a drive or UNC path, or
  goes above the twin root; `#include "../x.h"` that stays inside the twin is compiled.
- **Import** warns when a new function reuses an existing alias for its own variable (it would come
  back as the old meaning); keywords and builtins are not listed as new names. With `comments: hide`,
  placeholder comments (`// cmt_0040`) the AI left out when it returned whole functions are put back
  next to the code they belong to; a comment that went together with deleted code stays deleted.
- IDE and tool state (`.vs`, `.settings`, `*.user`, workspace and `c_cpp_properties.json` files) is
  never copied, because it holds absolute paths and user names.
- `.doppel/vault.json` holds the real names and the hidden comments and strings in plain text, like the
  project's own sources next to it, so it needs the same care. Keep the project folder private.
- The compile check uses the compiler's default C dialect (`compile_flags: []`); set the flags of
  your real build if needed. Files it cannot verify are listed as `NOT CHECKED` with the reason.

## Limitations

- **A twin builds and compiles like the original, but it does not always behave the same.** With
  `strings: scrub`, names inside data strings (command-line option tables, registry keys) may be replaced;
  with `strings: hide`, the program's text output changes. On librosa (pilot, 0.6.4) the original passed
  1,957 tests; the twin passed 1,835 (74 failed, 48 errors) with `scrub` and 1,351 (558 failed, 48 errors)
  with `hide`. Run your tests on the original after `doppel import`; do not trust failing tests in the twin.
- DoppelCode reduces what an AI sees; it does not make code unreadable. Function signatures, call structure, control
  flow and well-known algorithms stay visible in the twin, and a capable model can often tell what a program
  does.
- With the default `strings: scrub` (and with `comments: scrub`), the rest of the text in strings (and comments)
  stays visible, including words that are parts of your names (for example a product name inside a message or a
  key string). Use `strings: hide` for code whose messages or keys are sensitive.
- With `strings: hide`, every format specifier stays visible (`%d`, `%.1f`, `%1$d`, `%(rate)d`, `{0}`, `{x:.2f}`,
  `${x}`); only the words are hidden. One known case: in Python, `"%(rate)d Hz" % {"rate": rate}` hides the dict
  key `"rate"` on its own, so in the twin the key no longer matches `%(rate)d` and the line raises `KeyError` if
  the twin runs it. Import restores both; the original is not affected.
- Values are hidden only if you mark them (`secret_*`); `doppel secrets suggest` proposes candidates.
- A withheld function cannot be edited by the AI: it describes the change in plain words and you apply it, or
  you release the body for one session (`doppel withhold release`), which is recorded.
- A CMake regex that finds several macros by a shared prefix (curl: `"#define LIBCURL_VERSION( |_NUM )"`)
  cannot find them once they are renamed: add those macros to `keep`.
- In CMake projects (or with build files that compute file paths), file and folder names stay visible in the
  twin: DoppelCode keeps them unless the config sets `"rename_files": true`, so the twin builds with the project's
  own build. `check` reports this as one finding ("File names kept for the CMake build: N files and folders")
  and fails until you accept it once with `"accept_file_names": true`; after that it prints one hint line.
- In a pytest project, test names (`test_*`, `Test*`), `pytest_*` hooks and pytest's fixture names are kept so
  the twin's tests run; they are visible to the AI. `"keep_test_names": false` hides them.
- Comments in script files (0.7.0b11): with `comments: hide`, shell, Perl, PowerShell, batch and other `#!` scripts
  have their comments hidden too (`# cmt_0001`, `REM cmt_0001`, `:: cmt_0001`, `<# cmt_0001 #>`). The rules are
  careful not to break a script the build runs, so some comments stay: trailing comments in Perl (`#` can be a
  regex delimiter), comment-like lines inside heredocs and Perl's POD. `check` reports what stays. Other text
  files (`.md`, `.yml`, `.txt`) are not code: their text stays, with your names replaced.
- `translate` (0.7.0b11) maps only the names the last export used: a name that is only in a file you added to
  `ignore` later is no longer translated or shown as an example (the vault keeps it for older twins).
- Leak scans and pilot results reduce risk; they are not a proof that nothing leaks. Review `check` output.

## Tests

```
python -m unittest discover -s tests
```

## License

DoppelCode is free for personal use, education, research and other noncommercial purposes under the [PolyForm Noncommercial License 1.0.0](LICENSE). Any commercial use, including use by or for a company, requires a paid commercial license: see [COMMERCIAL.md](COMMERCIAL.md).
