doppelcode 0.7.0b5.post1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. doppelcode-0.7.0b5.post1/LICENSE +77 -0
  2. doppelcode-0.7.0b5.post1/PKG-INFO +418 -0
  3. doppelcode-0.7.0b5.post1/README.md +393 -0
  4. doppelcode-0.7.0b5.post1/doppelcode/__init__.py +3 -0
  5. doppelcode-0.7.0b5.post1/doppelcode/__main__.py +5 -0
  6. doppelcode-0.7.0b5.post1/doppelcode/aliascheck.py +316 -0
  7. doppelcode-0.7.0b5.post1/doppelcode/analyze.py +103 -0
  8. doppelcode-0.7.0b5.post1/doppelcode/cli.py +462 -0
  9. doppelcode-0.7.0b5.post1/doppelcode/cmake_words.py +621 -0
  10. doppelcode-0.7.0b5.post1/doppelcode/commentkeep.py +79 -0
  11. doppelcode-0.7.0b5.post1/doppelcode/config.py +156 -0
  12. doppelcode-0.7.0b5.post1/doppelcode/declare.py +364 -0
  13. doppelcode-0.7.0b5.post1/doppelcode/encodingfix.py +124 -0
  14. doppelcode-0.7.0b5.post1/doppelcode/headers.py +115 -0
  15. doppelcode-0.7.0b5.post1/doppelcode/keepset.py +84 -0
  16. doppelcode-0.7.0b5.post1/doppelcode/languages.py +168 -0
  17. doppelcode-0.7.0b5.post1/doppelcode/ledger.py +233 -0
  18. doppelcode-0.7.0b5.post1/doppelcode/lexer.py +294 -0
  19. doppelcode-0.7.0b5.post1/doppelcode/merge.py +86 -0
  20. doppelcode-0.7.0b5.post1/doppelcode/project.py +2343 -0
  21. doppelcode-0.7.0b5.post1/doppelcode/pyharvest.py +121 -0
  22. doppelcode-0.7.0b5.post1/doppelcode/pyparse.py +14 -0
  23. doppelcode-0.7.0b5.post1/doppelcode/secretconst.py +899 -0
  24. doppelcode-0.7.0b5.post1/doppelcode/strhide.py +188 -0
  25. doppelcode-0.7.0b5.post1/doppelcode/toolchains.py +192 -0
  26. doppelcode-0.7.0b5.post1/doppelcode/translate.py +599 -0
  27. doppelcode-0.7.0b5.post1/doppelcode/vault.py +85 -0
  28. doppelcode-0.7.0b5.post1/doppelcode/withhold.py +151 -0
  29. doppelcode-0.7.0b5.post1/doppelcode.egg-info/PKG-INFO +418 -0
  30. doppelcode-0.7.0b5.post1/doppelcode.egg-info/SOURCES.txt +49 -0
  31. doppelcode-0.7.0b5.post1/doppelcode.egg-info/dependency_links.txt +1 -0
  32. doppelcode-0.7.0b5.post1/doppelcode.egg-info/entry_points.txt +2 -0
  33. doppelcode-0.7.0b5.post1/doppelcode.egg-info/top_level.txt +1 -0
  34. doppelcode-0.7.0b5.post1/pyproject.toml +41 -0
  35. doppelcode-0.7.0b5.post1/setup.cfg +4 -0
  36. doppelcode-0.7.0b5.post1/tests/test_alias_import.py +232 -0
  37. doppelcode-0.7.0b5.post1/tests/test_beta_b2.py +151 -0
  38. doppelcode-0.7.0b5.post1/tests/test_build_064.py +222 -0
  39. doppelcode-0.7.0b5.post1/tests/test_doppelcode.py +326 -0
  40. doppelcode-0.7.0b5.post1/tests/test_encoding.py +172 -0
  41. doppelcode-0.7.0b5.post1/tests/test_import_preview.py +174 -0
  42. doppelcode-0.7.0b5.post1/tests/test_languages.py +375 -0
  43. doppelcode-0.7.0b5.post1/tests/test_large_063.py +309 -0
  44. doppelcode-0.7.0b5.post1/tests/test_ledger.py +127 -0
  45. doppelcode-0.7.0b5.post1/tests/test_line_endings.py +94 -0
  46. doppelcode-0.7.0b5.post1/tests/test_pilot_round2.py +268 -0
  47. doppelcode-0.7.0b5.post1/tests/test_rename_b3.py +100 -0
  48. doppelcode-0.7.0b5.post1/tests/test_review_062.py +175 -0
  49. doppelcode-0.7.0b5.post1/tests/test_secrets.py +621 -0
  50. doppelcode-0.7.0b5.post1/tests/test_security.py +171 -0
  51. doppelcode-0.7.0b5.post1/tests/test_withhold.py +306 -0
@@ -0,0 +1,77 @@
1
+ Required Notice: Copyright (c) 2026 Eliad Yehezkel
2
+
3
+ This software is free for personal use and other noncommercial purposes under the PolyForm Noncommercial License 1.0.0 below. Any commercial use, including use by or for a company, requires a separate commercial license from the licensor: see COMMERCIAL.md.
4
+
5
+ # PolyForm Noncommercial License 1.0.0
6
+
7
+ <https://polyformproject.org/licenses/noncommercial/1.0.0>
8
+
9
+ ## Acceptance
10
+
11
+ In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
12
+
13
+ ## Copyright License
14
+
15
+ The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
16
+
17
+ ## Distribution License
18
+
19
+ The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
20
+
21
+ ## Notices
22
+
23
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
24
+
25
+ > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
26
+
27
+ ## Changes and New Works License
28
+
29
+ The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
30
+
31
+ ## Patent License
32
+
33
+ The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
34
+
35
+ ## Noncommercial Purposes
36
+
37
+ Any noncommercial purpose is a permitted purpose.
38
+
39
+ ## Personal Uses
40
+
41
+ Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, is use for a permitted purpose.
42
+
43
+ ## Noncommercial Organizations
44
+
45
+ Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution is use for a permitted purpose regardless of the source of funding or obligations resulting from the funding.
46
+
47
+ ## Fair Use
48
+
49
+ You may have "fair use" rights for the software under the law. These terms do not limit them.
50
+
51
+ ## No Other Rights
52
+
53
+ These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
54
+
55
+ ## Patent Defense
56
+
57
+ If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
58
+
59
+ ## Violations
60
+
61
+ The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
62
+
63
+ ## No Liability
64
+
65
+ ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
66
+
67
+ ## Definitions
68
+
69
+ The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
70
+
71
+ **You** refers to the individual or entity agreeing to these terms.
72
+
73
+ **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
74
+
75
+ **Your licenses** are all the licenses granted to you for the software under these terms.
76
+
77
+ **Use** means anything you do with the software requiring one of your licenses.
@@ -0,0 +1,418 @@
1
+ Metadata-Version: 2.4
2
+ Name: doppelcode
3
+ Version: 0.7.0b5.post1
4
+ Summary: A private twin of your code for AI agents: the AI works on the twin, its edits merge back into the original
5
+ Author-email: DoppelCode <doppelcode.license@gmail.com>
6
+ License-Expression: PolyForm-Noncommercial-1.0.0
7
+ Project-URL: Homepage, https://github.com/doppelcode/doppelcode
8
+ Project-URL: Source, https://github.com/doppelcode/doppelcode
9
+ Project-URL: Issues, https://github.com/doppelcode/doppelcode/issues
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: Microsoft :: Windows
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Topic :: Software Development
21
+ Requires-Python: >=3.11
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Dynamic: license-file
25
+
26
+ # DoppelCode - a private twin of your code for AI agents
27
+
28
+ **Version:** 0.7.0b5.post1 (public beta)
29
+ **Date:** 2026-11-30
30
+
31
+ DoppelCode lets you use AI coding agents on proprietary code while reducing what an AI sees of your code. It
32
+ writes a **twin** of your project: the same code with your names, file names, comments and strings replaced
33
+ by placeholders, optionally with your tuned constants hidden and your core function bodies left out. The AI
34
+ works only on the twin. `doppel import` merges its edits back into your original with the real names, and
35
+ DoppelCode records what was sent to the AI, so you can show later which parts of your code an AI was given.
36
+
37
+ Python 3.11+, no third-party packages. Optional: gcc/g++ or clang (header harvesting, compile check), git
38
+ (3-way merge).
39
+
40
+ ## Quick Start (5 minutes)
41
+
42
+ ```
43
+ pip install doppelcode # installs the doppel command (or: python -m doppelcode ...)
44
+ pip install . # or: install from source, in a clone of this repo
45
+ doppel init path/to/project # optional: writes .doppel/config.json with the defaults
46
+ doppel export path/to/project --out path/to/twin # writes the twin
47
+ ```
48
+
49
+ 1. Open **the twin folder, not the original**, in your agent (Claude Code, GitHub Copilot agent, Cursor,
50
+ or paste it into a chat). The twin has an `AGENTS.md` / `CLAUDE.md` that tells the agent the rules.
51
+ 2. Let the agent work in the twin as usual.
52
+ 3. `doppel import path/to/project` merges the agent's changes into your original, with your names.
53
+ 4. `doppel check path/to/project` verifies the round trip, scans the twin for leaks and compiles both
54
+ versions (C / C++ machine code is compared; Python syntax trees are compared).
55
+ 5. `doppel report path/to/project` shows which function bodies were made available to an AI, and when.
56
+
57
+ ## Protection Levels
58
+
59
+ | Level | What the AI sees | Config |
60
+ |---|---|---|
61
+ | Names only | your code with names, file names, comments and strings replaced | default (`comments` / `strings`: `scrub` or `hide`) |
62
+ | + secret constants | tuned values and tables replaced by `K_` aliases with dummy values | `secret_symbols`, `secret_values`, `secret_files` |
63
+ | + withheld functions | the signature only; the body stays on your PC | `core_functions`, `core_modules` |
64
+
65
+ Pilot results (DeepSeek, DeepThink on; two small projects, one in C and one in Python; one chat per project
66
+ and condition). The attack question asked for every value and whether the core functions could be rebuilt:
67
+
68
+ | Round | Protection | Values recovered | "Can rebuild the core functions" | Tasks done automatically |
69
+ |---|---|---|---|---|
70
+ | 2 | Names only | all, in both projects | yes | 6 of 6 |
71
+ | 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) |
72
+ | 4 | + secrets + withheld (after the round 2 fixes) | none | no | 3 of 6, 1 partly right, 2 change requests in plain words |
73
+
74
+ These are small pilots with one model; they show the direction, not a guarantee.
75
+
76
+ ## Languages
77
+
78
+ | Language | Files | What is renamed | Library names kept by | Verified by `check` |
79
+ |---|---|---|---|---|
80
+ | C | `.c .h` | every identifier | system headers the code includes | compile + machine code |
81
+ | C++ | `.cpp .cc .cxx .hpp .hh ...` | every identifier | system / STL headers (via g++) | compile + machine code |
82
+ | Python | `.py .pyw .pyi` | names the project declares | public names of imported modules (read, never run), builtins | syntax trees |
83
+ | C# | `.cs` | names the project declares | keyword / BCL lists, member rule | compile (csc) |
84
+ | Java | `.java` | names the project declares | keyword / JDK lists, member rule | compile (javac) |
85
+ | JavaScript / TypeScript | `.js .mjs .jsx .ts .tsx` | names the project declares | keyword / runtime lists, member rule | compile, syntax only (Node) |
86
+
87
+ For the "declared" languages, a name is kept when it is used as a member of something the project
88
+ does not declare (`os.path`, `sb.Append`, `crypto.createHash`), when it is imported from an outside
89
+ module, when it is a keyword argument to a library call (`json.dumps(indent=2)`), or when it is a
90
+ method of a class derived from a library class (unittest `setUp`, `Thread.run`). Python packages
91
+ (folders with `__init__.py`) are renamed together with their imports; Java files take their public
92
+ class's new name. Code inside `f"{x}"`, `$"{x}"` and `` `${x}` `` is always translated, strings that
93
+ name code (`getattr(o, "x")`, `__all__`, `obj["x"]`, reflection) are renamed with it, and module
94
+ names (`require("crypto")`, `import ... from "lib"`) are never hidden.
95
+
96
+ Machine code is compared against a names-only version of the twin (strings and comments untouched),
97
+ so the comparison proves that renaming changed no code whatever the string policy. With strings set
98
+ to `keep`, a Python twin prints exactly what the original prints.
99
+
100
+ `check` also builds Java, C# and JS / TS. The original is built first; if it does not build with the
101
+ tool found, its files are listed as NOT CHECKED with the reason, so only errors the twin alone has
102
+ count. The twin's code is never run (javac without annotation processors, csc without analyzers,
103
+ JS / TS only compiled). Tools are found automatically and can be set in `.doppel/config.json`:
104
+
105
+ | Key | Default search |
106
+ |---|---|
107
+ | `javac` | PATH, `JAVA_HOME`, `~/.jdks`, Program Files JDKs, Android Studio's `jbr` |
108
+ | `csc` | Visual Studio Roslyn, .NET SDK, then the .NET Framework `csc` (C# 5 only: install the .NET SDK for newer C#) |
109
+ | `node` | PATH, Program Files, then VS Code's built-in Node (TypeScript types are stripped by Node) |
110
+
111
+ With strings set to `keep`, file and folder names inside path strings (`require("./falconRadio")`,
112
+ `fopen("rec_01.dat")`) are still renamed, so the twin finds its renamed modules and data files.
113
+
114
+ ## Desktop app
115
+
116
+ A desktop app is planned for a later release. This beta is the `doppel` command line; everything below
117
+ works with it.
118
+
119
+ ## Workflow
120
+
121
+ ```
122
+ python -m doppelcode init <project> # optional: write .doppel/config.json to tune policies
123
+ python -m doppelcode export <project> [--out DIR] # create/refresh the twin (default <parent>/obf_<hash>)
124
+ ... point the AI agent at the twin folder, let it edit ...
125
+ python -m doppelcode import <project> # merge the AI's changes into the original
126
+ python -m doppelcode check <project> --objects # round trip, leak scan, compile + machine-code compare
127
+ python -m doppelcode lookup <project> fn_0005 # translate a name either way
128
+ ```
129
+
130
+ `import` performs a 3-way merge per file: the AI's changes are applied even if you edited the
131
+ original in the meantime. Only overlapping edits produce `<file>.doppel-merge` (with conflict
132
+ markers; the original is left untouched). `export` refuses to run until those are resolved.
133
+
134
+ ### Review before applying (`--preview`)
135
+
136
+ ```
137
+ python -m doppelcode import <project> --preview DIR # see what import would write
138
+ python -m doppelcode import <project> --from-preview DIR # apply all of it
139
+ python -m doppelcode import <project> --from-preview DIR --only src/a.c # or one file
140
+ ```
141
+
142
+ `--preview DIR` runs the whole import, 3-way merge included, but writes the result to `DIR` at the same
143
+ relative paths (a conflict as `<file>.doppel-merge`) and prints the list of files. Nothing in the project,
144
+ the twin, the vault or `.doppel/config.json` changes. `DIR` must be outside the project and the twin, and
145
+ empty or an earlier preview (which is replaced). `DIR/.doppel-preview.json` records, per file, the twin
146
+ file and the original as they were.
147
+
148
+ `--from-preview DIR` applies exactly what was previewed, with the preview's `--rename` / `--accept`. It
149
+ refuses, and writes nothing, when a twin file or an original changed since the preview: preview again.
150
+ Applied files leave the manifest, so the rest can be applied later. The VS Code extension uses this for
151
+ its review view.
152
+
153
+ ### Files that are not UTF-8, and line ends
154
+
155
+ DoppelCode keeps every file's bytes: a Windows-1255 or Windows-1252 file goes into the twin in its own
156
+ encoding (with `comments: hide` its comments do not go at all) and comes back the same, except the lines the
157
+ AI changed. An AI agent's editor often saves such a twin file as UTF-8 (replacement characters, or the code
158
+ page decoded). Import gives every line whose only change is that re-encoding its original bytes back, and
159
+ writes the lines the AI did change in the file's code page when it can tell which one it is (`encoding:` in
160
+ the output). Line ends do not take part in the merge: the AI adding LF lines to a CRLF file, or your editor
161
+ saving the file again with one style, is not a change; changed lines take the original's style.
162
+
163
+ ### Names the AI coins in DoppelCode's style
164
+
165
+ AI models often name new things like the placeholders they see (`v_0048`, `fn_0017`, `"str_0013"`).
166
+ Mapped back blindly, a new parameter `v_0048` would become an unrelated existing name
167
+ (`fips_expected`), and a new string `"str_0013"` would become an existing text (`"ALL PASS"`).
168
+ On the lines the AI added or changed, `import` therefore flags:
169
+
170
+ - a known alias in a declaration position (function, parameter, local, field, type, macro) that
171
+ the old version of the file did not declare;
172
+ - an alias-shaped name that is not in the vault (`fn_0017`);
173
+ - a string literal that is exactly `"str_NNNN"` and was not in the old version of the file.
174
+
175
+ Plain uses of existing names map silently. Flagged files are **not merged**; the findings go to
176
+ the console and to `.doppel/import_review.txt`. Resolve them and import again:
177
+
178
+ ```
179
+ python -m doppelcode import <project> --rename v_0048=nonce --rename fn_0017=falcon_ctr_crypt
180
+ python -m doppelcode import <project> --rename "str_0013=Decrypt failed"
181
+ python -m doppelcode import <project> --accept v_0017 # keep as written (known alias: its vault meaning)
182
+ python -m doppelcode import <project> --accept # accept every finding
183
+ ```
184
+
185
+ A renamed name gets its own alias in the vault and the twin file is rewritten with it, so twin,
186
+ vault and original agree from then on.
187
+
188
+ `export` also writes `AGENTS.md` and `CLAUDE.md` into the twin root (unless the project has its
189
+ own) asking the agent to give new things plain names; `import` ignores both files.
190
+
191
+ ## Example (samples/aes_project)
192
+
193
+ ```c
194
+ /* original */ /* twin */
195
+ void falcon_encrypt_block( void fn_0002(
196
+ const FalconAesContext *ctx, const T_0001 *v_0006,
197
+ uint8_t block[FALCON_BLOCK_SIZE]); uint8_t v_0008[M_0002]);
198
+ #include "falcon_aes.h" #include "mod_0001.h"
199
+ ```
200
+
201
+ ## Secret constants
202
+
203
+ Renaming hides names, but in DSP or classifier code the numbers are often the real know-how:
204
+ thresholds, coefficients, tuning tables. Marked numbers are replaced in the twin by aliases
205
+ `K_0001`, `K_0002`, ...; the vault keeps the real values and `import` puts them back.
206
+
207
+ | Way to mark | Example | Hides |
208
+ |---|---|---|
209
+ | Line tag | `x = 145 # doppel:secret` | every number on that line, or a table starting there as a whole |
210
+ | `secret_symbols` | `["male_threshold", "lpc_order"]` | every number assigned to that name: assignments, `self.x = ...`, default values, keyword arguments (original names) |
211
+ | `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 |
212
+ | `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) |
213
+
214
+ ```
215
+ python -m doppelcode secrets suggest <project> [--all] [--top N] # ranked: tables, algorithm constants,
216
+ # thresholds, the rest (top 50 by default)
217
+ python -m doppelcode secrets list <project> [--show-values]
218
+ ```
219
+
220
+ - **A marked value is hidden everywhere** in the code (each place gets its own alias), and in
221
+ comments and strings too when they are `scrub`bed. `check` fails if the value is still visible
222
+ anywhere in the twin, also written as `0x91`, `1.45e2` or inside a string.
223
+ - `0`, `1`, `-1`, `2` and `0.5` are never hidden by value list (only at a tagged or named place),
224
+ and never count as leaks.
225
+ - **The twin still runs.** A twin-only file gives every alias a neutral dummy value, and each file
226
+ that uses one gets a marked line that `import` removes again:
227
+
228
+ | Language | Dummy file (twin root) | Line added to each file |
229
+ |---|---|---|
230
+ | Python | `doppel_secrets.py`: `K_0001 = 1.0`, tables `[0] * n` | `from doppel_secrets import K_... # DoppelCode` after the imports |
231
+ | C / C++ | `doppel_secrets.h`: `#define K_0001 (1.0f)`, tables `{0, 0, ...}` (same length) | `#include "../doppel_secrets.h" /* DoppelCode */` after the first include |
232
+
233
+ In C a table initializer is replaced as a whole (`static const uint8_t k_rcon[10] = K_0001;`,
234
+ the size kept), and `#define NAME 0x1b` works with `secret_symbols` too. The dummy file is
235
+ never imported; if the AI edits it, the import reports "secret value change requested" and
236
+ keeps the real value.
237
+ - `check` compiles / parses the dummy twin, and compares the original with the twin **with the
238
+ real values put back** (C: machine code, Python: syntax trees).
239
+ - If the AI replaces an alias by a literal (`K_0003` -> `3.5`), the file is not merged until you
240
+ decide: `--accept K_0003` takes 3.5, `--rename K_0003=@keep` keeps the secret,
241
+ `--rename K_0003=@secret` takes 3.5 and adds it to `secret_values`.
242
+ - The elements of a secret table are hidden wherever else they are written in the same form (a test
243
+ generator that hard-codes `400.0` from the tone table), and in comments and strings in any form
244
+ (`400Hz`). Small integers (-15..15) and powers of two stay visible: they are indexes, loop bounds,
245
+ sizes and bit masks. `doppel secrets suggest` lists the functions that write such values - consider
246
+ withholding them.
247
+ - Values computed from secrets (`145 * 2` written as `290`) are out of scope.
248
+
249
+ Supported for Python, C and C++.
250
+
251
+ With withheld functions or secret constants set, `strings` defaults to `hide` (banners and help
252
+ texts would still tell the purpose); set `"strings"` in `.doppel/config.json` to choose otherwise.
253
+ One-word mode strings passed straight to a library call (`filterwarnings("ignore")`,
254
+ `btype="band"`, `encode("utf-8")`) stay, so the twin still runs. Python dict keys are one class: in
255
+ `scrub` and `hide` every identifier-shaped key (`'pitch'`, `'f1'`, `'spectral_centroid'`) gets an
256
+ alias, so the keys do not list what a withheld function computes. Only keys of a library's dict stay
257
+ (`os.environ["PATH"]`, a dict literal handed to a library call); a key that merely matches a
258
+ library name (`'f2'`) is still aliased. A library dict is also followed through names
259
+ (`devs = sd.query_devices()`, `for d in devs`: `d['max_input_channels']` stays, in `hide` too).
260
+ In the text of a function that uses a secret table (its name, one of its values, or a table linked
261
+ by indexing such as `frequencies[target_sequence[i]]`), the table's small integers are hidden too
262
+ ("Symbol 10" -> "Symbol K_0012"); elsewhere small numbers stay. With protected code and
263
+ `"strings": "scrub"`, `check` prints a warning with an example string.
264
+
265
+ ## Withheld functions (optional)
266
+
267
+ Choose functions the AI may call but not read. In the twin their body becomes a stub; everything
268
+ else is obfuscated as before:
269
+
270
+ ```python
271
+ def fn_0004(self, v_0005):
272
+ raise NotImplementedError("doppel: body withheld (B_0001)")
273
+ ```
274
+ ```c
275
+ static void fn_0009(uint8_t v_0021[16])
276
+ { /* doppel: body withheld (B_0002) */ }
277
+
278
+ float fn_0002(const float* v_0014, int v_0015, double v_0016, double v_0017)
279
+ { /* doppel: body withheld (B_0003) */ return (float){0}; }
280
+ ```
281
+
282
+ A non-void C function returns a zero value (`return (T){0};`, C++ `return {};`), so the twin builds
283
+ with `-Werror=return-type`; a Python stub raises, so a twin-side test fails where the function is
284
+ called, not later with a `None`.
285
+
286
+ - **Choosing:** in `.doppel/config.json`:
287
+ `"core_functions": ["detector.py::Detector.classify", "src/filter.c::design_lowpass", "detector.py::Detector"]`
288
+ (a class withholds all its methods), `"core_modules": ["dsp/", "secret_algo.py"]` (whole files).
289
+ - **Import** puts the real bodies back byte for byte; edits elsewhere merge as usual. If the AI
290
+ changes or removes a withheld body, the file is not merged until you take its version with
291
+ `--accept B_0001`.
292
+ - **A change inside a withheld function:** the AI is told to describe it in plain words instead of
293
+ editing the stub, so you apply it yourself. Or release the body for one session:
294
+ `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
295
+ export after it withholds the function again. The release and the send are both in the exposure
296
+ ledger. `doppel withhold list PROJECT` shows the ids.
297
+ - **Purpose line (optional):** `doppel withhold purpose PROJECT B_0002 "returns (gender, confidence) for
298
+ one chunk"` (or right-click it in the outline) lists that line in the twin's `AGENTS.md`, so the AI
299
+ calls the right withheld function. Off unless you write one; it tells the AI the function's role,
300
+ not its body (names and secret values in it are translated). In pilot round 4 the AI called the
301
+ feature extractor where the gender decision was meant; both were withheld.
302
+ - **check:** the dummy twin still parses / compiles to objects; the machine-code comparison uses
303
+ the full-body copy, so it stays exact; Python syntax trees are compared without the withheld bodies.
304
+ - **Exposure:** withheld functions are logged as `declaration`, not `body`, so `doppel report` and the
305
+ budgets show the real share (e.g. 15 of 17 bodies, 88%).
306
+ - Python, C and C++ (Java and C# need typed stubs; later). The twin's `AGENTS.md` / `CLAUDE.md` tell
307
+ the agent not to implement or change withheld functions.
308
+
309
+ ## Exposure ledger
310
+
311
+ Every `export` records which function bodies it made available to an AI in
312
+ `.doppel/ledger.jsonl` (append-only, kept as an audit trail). A body is logged when it is new or
313
+ changed, or when it is sent again to a new twin folder (`"repeat": true`); a plain refresh adds
314
+ nothing.
315
+
316
+ ```
317
+ python -m doppelcode report <project> # per folder
318
+ python -m doppelcode report <project> --by function # first / last sent, how often
319
+ python -m doppelcode report <project> --since 2026-11-01
320
+
321
+ Exposure report - what was made available to an AI (not what it read)
322
+ folder functions bodies sent share secrets withheld
323
+ src/ 17 17 100% 6
324
+ ```
325
+
326
+ **Budgets:** `"exposure_budget": {"dsp/": 0.3}` stops an export that would make more than that share
327
+ of a folder's function bodies available; `export --allow-over-budget` exports anyway and records
328
+ the override in the ledger. With today's full twin every exported folder is at 100%, so a budget
329
+ acts as a guard ("never export dsp/") until declarations-only export (core modules) exists.
330
+
331
+ ## Key config options (`.doppel/config.json`)
332
+
333
+ | Key | Default | Meaning |
334
+ |---|---|---|
335
+ | `keep`, `keep_prefixes`, `keep_regex` | `[]` | names never renamed (e.g. vendor `HAL_`) |
336
+ | `exclude` | `[]` | third-party folders: copied verbatim, their names kept |
337
+ | `comments` | `scrub` | `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` |
338
+ | `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` |
339
+ | `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` |
340
+ | `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 |
341
+ | `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 |
342
+ | `rename_words` | `[]` | extra words to rename everywhere |
343
+ | `build_names` | `keep` | `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. With `keep`, `check` reports them as leaks. Set it with `export --build-names rename` |
344
+ | `sensitive_terms` | `[]` | substrings that `check` reports if still present in the twin |
345
+ | `naming` | `kind` | `kind` (fn_/v_/T_/M_) or `opaque` (id_ for all) |
346
+
347
+ Files that are not source, build or known text files are **not copied** to the twin (they may leak); add
348
+ them to `copy_verbatim` if the AI needs them. Build templates, packaging files, scripts (`.sh`, `.pl`,
349
+ `#!` files without an extension) and text files a build file names are copied; scripts are never
350
+ imported as new files, and changes to existing ones are listed for review.
351
+
352
+ ## Security
353
+
354
+ The twin is written by an AI agent, so DoppelCode treats it as untrusted:
355
+
356
+ - **Import** accepts new files only if they are C sources or known text files outside hidden folders.
357
+ Scripts (`.bat`, `.ps1`, `.sh`), binaries, Windows device names and anything under `.github`,
358
+ `.vscode`, `.git` and similar are reported as `BLOCKED` and never written. Changed build and
359
+ config files (Makefile, `*.mk`, `*.json`, ...) are listed under *Review before building*.
360
+ - **Links**: symlinks and junctions inside the twin are never followed (reported as `IGNORED (link)`),
361
+ and `export` refuses to write or delete through them. `export` also refuses to take over a
362
+ non-empty folder it did not create (`--force` to override).
363
+ - **Compile check**: if a twin file includes something outside the twin (absolute, `..` or UNC
364
+ `\\host\share` paths, which would make Windows connect to that host), the compiler is not run.
365
+ - **Leak scan** also reports absolute paths, the project folder name and the Windows user name (as
366
+ a path segment, an e-mail or a handle only, so a user `root` does not flag "rooted"). Absolute
367
+ paths in build and text files (toolchain folders, the source checkout) become `$(DOPPEL_PATH_0001)` in
368
+ the twin and come back on import. Prose that spells a renamed name out ("read audio file" for
369
+ `read_audio_file`) is listed under `hints:`; it does not fail the check (`hide` removes it).
370
+ - **Large projects:** `check` prints a leak summary (counts by kind, the top files, 30 examples, secret
371
+ values and absolute paths first) and writes the full list to `.doppel/leaks.txt` (`--leaks-all` prints
372
+ it). `"leak_allow": ["opus"]` accepts words such as a public project name; secret values and
373
+ absolute paths are always reported. Build and CLI words (cmake, version, option, enable, ...) are not
374
+ name parts. Headers and modules export could not find are counted and listed in `.doppel/missing.txt`.
375
+ - **Includes:** the compile check refuses a twin whose `#include` is absolute, a drive or UNC path, or
376
+ goes above the twin root; `#include "../x.h"` that stays inside the twin is compiled.
377
+ - **Import** warns when a new function reuses an existing alias for its own variable (it would come
378
+ back as the old meaning); keywords and builtins are not listed as new names. With `comments: hide`,
379
+ placeholder comments (`// cmt_0040`) the AI left out when it returned whole functions are put back
380
+ next to the code they belong to; a comment that went together with deleted code stays deleted.
381
+ - IDE and tool state (`.vs`, `.settings`, `*.user`, workspace and `c_cpp_properties.json` files) is
382
+ never copied, because it holds absolute paths and user names.
383
+ - `.doppel/vault.json` holds the real names and the hidden comments and strings in plain text, like the
384
+ project's own sources next to it, so it needs the same care. Keep the project folder private.
385
+ - The compile check uses the compiler's default C dialect (`compile_flags: []`); set the flags of
386
+ your real build if needed. Files it cannot verify are listed as `NOT CHECKED` with the reason.
387
+
388
+ ## Limitations
389
+
390
+ - **A twin builds and compiles like the original, but it does not always behave the same.** With
391
+ `strings: scrub`, names inside data strings (command-line option tables, registry keys) may be replaced;
392
+ with `strings: hide`, the program's text output changes. On librosa (pilot, 0.6.4) the original passed
393
+ 1,957 tests; the twin passed 1,835 (74 failed, 48 errors) with `scrub` and 1,351 (558 failed, 48 errors)
394
+ with `hide`. Run your tests on the original after `doppel import`; do not trust failing tests in the twin.
395
+ - DoppelCode reduces what an AI sees; it does not make code unreadable. Function signatures, call structure, control
396
+ flow and well-known algorithms stay visible in the twin, and a capable model can often tell what a program
397
+ does.
398
+ - Values are hidden only if you mark them (`secret_*`); `doppel secrets suggest` proposes candidates.
399
+ - A withheld function cannot be edited by the AI: it describes the change in plain words and you apply it, or
400
+ you release the body for one session (`doppel withhold release`), which is recorded.
401
+ - A CMake regex that finds several macros by a shared prefix (curl: `"#define LIBCURL_VERSION( |_NUM )"`)
402
+ cannot find them once they are renamed: add those macros to `keep`.
403
+ - With a CMake build (or build files that compute file paths), DoppelCode keeps file and folder names unless the
404
+ config sets `"rename_files": true`, so the twin builds with the project's own build; file names are then
405
+ visible.
406
+ - In a pytest project, test names (`test_*`, `Test*`), `pytest_*` hooks and pytest's fixture names are kept so
407
+ the twin's tests run; they are visible to the AI. `"keep_test_names": false` hides them.
408
+ - Leak scans and pilot results reduce risk; they are not a proof that nothing leaks. Review `check` output.
409
+
410
+ ## Tests
411
+
412
+ ```
413
+ python -m unittest discover -s tests
414
+ ```
415
+
416
+ ## License
417
+
418
+ 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).