Skip to content

Commit 3c70f41

Browse files
refactoring
1 parent 59b8242 commit 3c70f41

File tree

5 files changed

+3560
-3453
lines changed

5 files changed

+3560
-3453
lines changed

code2logic/cli.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,10 +652,22 @@ def _maybe_print_pretty_help() -> bool:
652652
help='Write all output to stdout instead of files (including schema and function-logic). Useful for piping.'
653653
)
654654
parser.add_argument(
655-
'--no-repeat-name',
655+
'--no-repeat-module',
656656
action='store_true',
657+
dest='no_repeat_module',
657658
help='Reduce repeated directory prefixes in TOON outputs by using ./file for consecutive entries in the same folder (applies to function-logic TOON and TOON module lists).'
658659
)
660+
parser.add_argument(
661+
'--no-repeat-name',
662+
action='store_true',
663+
dest='no_repeat_module',
664+
help=argparse.SUPPRESS
665+
)
666+
parser.add_argument(
667+
'--no-repeat-details',
668+
action='store_true',
669+
help='Reduce repeated directory prefixes in function-logic TOON section function_details by using ./file for consecutive entries in the same folder.'
670+
)
659671
parser.add_argument(
660672
'--no-install',
661673
action='store_true',
@@ -969,7 +981,7 @@ def _maybe_print_pretty_help() -> bool:
969981
output = generator.generate(
970982
project,
971983
detail=detail_map.get(args.detail, 'standard'),
972-
no_repeat_name=args.no_repeat_name,
984+
no_repeat_name=args.no_repeat_module,
973985
)
974986

975987
# Generate schema if requested
@@ -1021,7 +1033,12 @@ def _maybe_print_pretty_help() -> bool:
10211033
elif lower.endswith(('.yaml', '.yml')):
10221034
logic_out = logic_gen.generate_yaml(project, detail=args.detail)
10231035
elif lower.endswith('.toon'):
1024-
logic_out = logic_gen.generate_toon(project, detail=args.detail, no_repeat_name=args.no_repeat_name)
1036+
logic_out = logic_gen.generate_toon(
1037+
project,
1038+
detail=args.detail,
1039+
no_repeat_name=args.no_repeat_module,
1040+
no_repeat_details=args.no_repeat_details,
1041+
)
10251042
else:
10261043
logic_out = logic_gen.generate(project, detail=args.detail)
10271044

code2logic/function_logic.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ def generate_yaml(self, project: ProjectInfo, detail: str = 'full') -> str:
5959
return self.generate(project, detail)
6060
return yaml.dump(data, default_flow_style=False, allow_unicode=True, sort_keys=False, width=120)
6161

62-
def generate_toon(self, project: ProjectInfo, detail: str = 'full', no_repeat_name: bool = False) -> str:
62+
def generate_toon(
63+
self,
64+
project: ProjectInfo,
65+
detail: str = 'full',
66+
no_repeat_name: bool = False,
67+
no_repeat_details: bool = False,
68+
) -> str:
6369
if detail == 'detailed':
6470
detail = 'full'
6571
toon = TOONGenerator()
@@ -92,14 +98,14 @@ def generate_toon(self, project: ProjectInfo, detail: str = 'full', no_repeat_na
9298
if not items:
9399
continue
94100

95-
if no_repeat_name:
101+
if no_repeat_details:
96102
compressed_path, prev_dir = toon._compress_module_path(m.path, prev_dir)
97103
details_key = compressed_path
98104
else:
99105
details_key = m.path
100106
lines.append(f" {toon._quote(details_key)}:")
101107

102-
header = f"name{dm}kind{dm}sig{dm}loc{dm}async{dm}lines{dm}cc"
108+
header = f"line{dm}name{dm}kind{dm}sig{dm}async{dm}cc"
103109
if detail in ('standard', 'full'):
104110
header += f"{dm}does"
105111
if detail == 'full':
@@ -109,15 +115,14 @@ def generate_toon(self, project: ProjectInfo, detail: str = 'full', no_repeat_na
109115

110116
for kind, qname, func in items:
111117
sig = self._build_sig(func, include_async_prefix=False, language=m.language)
112-
loc = self._build_loc(func)
113118
is_async = 'true' if getattr(func, 'is_async', False) else 'false'
119+
start_line = str(getattr(func, 'start_line', 0) or 0)
114120
row = [
121+
start_line,
115122
toon._quote(qname),
116123
toon._quote(kind),
117124
toon._quote(sig),
118-
toon._quote(loc),
119125
is_async,
120-
str(getattr(func, 'lines', 0) or 0),
121126
str(getattr(func, 'complexity', 1) or 1),
122127
]
123128

docs/03-cli-reference.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ If `CODE2LOGIC_DEFAULT_PROVIDER=auto`, Code2Logic tries providers in priority or
4444
| `--compact` | | Use compact YAML format (14% smaller, meta.legend transparency) |
4545
| `--hybrid` | | Use hybrid YAML output (or use `-f hybrid`) |
4646
| `--ultra-compact` | | Use ultra-compact TOON format (71% smaller) |
47+
| `--no-repeat-module` | | Reduce repeated directory prefixes in TOON `modules[...]` tables by using `./file` for consecutive entries in the same folder |
48+
| `--no-repeat-details` | | Reduce repeated directory prefixes in function-logic TOON `function_details` section by using `./file` for consecutive entries in the same folder |
4749
| `--with-schema` | | Generate JSON schema alongside output |
4850
| `--verbose` | `-v` | Verbose output with timing |
4951
| `--debug` | | Debug output (very verbose) |
@@ -120,8 +122,14 @@ code2logic /path/to/project -f toon -o analysis.toon
120122
# Ultra-compact TOON (71% smaller, single-letter keys)
121123
code2logic /path/to/project -f toon --ultra-compact -o analysis-ultra.toon
122124

125+
# Reduce repeated directory prefixes in modules[] (uses ./file when staying in the same folder)
126+
code2logic /path/to/project -f toon --no-repeat-module -o analysis.toon
127+
123128
# Generate schema alongside output
124129
code2logic /path/to/project -f toon --ultra-compact --with-schema
130+
131+
# Generate function-logic as TOON + compress function_details module keys
132+
code2logic /path/to/project -f toon --function-logic --name project -o ./ --no-repeat-details
125133
```
126134

127135
Token-oriented object notation - most efficient format for LLM consumption.

docs/07-toon.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,85 @@ code2logic /path/to/project -f toon -o analysis.toon
120120

121121
# With full detail
122122
code2logic /path/to/project -f toon -d full
123+
124+
# Reduce repeated directory prefixes in the modules table
125+
# (when consecutive entries are in the same folder, emits ./file)
126+
code2logic /path/to/project -f toon --no-repeat-module -o analysis.toon
127+
128+
# Generate function-logic as TOON + reduce repeats in function_details
129+
code2logic /path/to/project -f toon --function-logic --name project -o ./ --no-repeat-details
130+
131+
# Enable both (modules table + function_details)
132+
code2logic /path/to/project -f toon --function-logic --name project -o ./ --no-repeat-module --no-repeat-details
133+
```
134+
135+
### Reducing Path Repetition (Filesystem Tree Hint)
136+
137+
For large repositories, repeating directory prefixes in every `modules[...]` row or every `function_details` key can waste a lot of tokens.
138+
139+
Code2Logic supports a compact, LLM-friendly convention:
140+
141+
- The first entry in a directory is emitted as a full relative path, e.g. `scripts/build-docs.js`
142+
- Subsequent consecutive entries in the same directory are emitted as `./<basename>`, e.g. `./seed_auth_users.py`
143+
144+
This signals "same directory as the previous entry" and is typically understood well by LLMs as a filesystem listing.
145+
146+
**Example (modules table):**
147+
148+
Without `--no-repeat-module`:
149+
150+
```toon
151+
modules[4]{path,lang,lines,kb}:
152+
scripts/build-docs.js,js,9,1.2
153+
scripts/seed_auth_users.py,py,4,0.4
154+
scripts/stats-collector.py,py,14,0.8
155+
shared/dsl-runtime.ts,ts,13,1.1
123156
```
124157

158+
With `--no-repeat-module`:
159+
160+
```toon
161+
modules[4]{path,lang,lines,kb}:
162+
scripts/build-docs.js,js,9,1.2
163+
./seed_auth_users.py,py,4,0.4
164+
./stats-collector.py,py,14,0.8
165+
shared/dsl-runtime.ts,ts,13,1.1
166+
```
167+
168+
**Example (function-logic TOON, function_details):**
169+
170+
```bash
171+
code2logic /path/to/project -f toon --function-logic --name project -o ./ --no-repeat-details
172+
```
173+
174+
Output fragment:
175+
176+
```toon
177+
function_details:
178+
firmware/main.py:
179+
functions[2]{line,name,kind,sig,async,cc,does}:
180+
77,index_page,function,(),true,2,Serve the firmware UI
181+
85,health_check,function,(),true,1,Health check endpoint
182+
./test_main.py:
183+
functions[1]{line,name,kind,sig,async,cc,does}:
184+
14,TestFirmwareSimulator.test_health_check,method,(),false,1,Test basic health endpoint
185+
```
186+
187+
Notes:
188+
189+
- `--no-repeat-module` affects TOON `modules[...]` tables (main TOON output and function-logic TOON modules table).
190+
- `--no-repeat-details` affects the module keys under `function_details` in function-logic TOON output.
191+
192+
### Language Codes
193+
194+
For lower token usage, TOON uses short language codes in `lang` columns and in `languages[...]` summary, e.g.:
195+
196+
- `py` = Python
197+
- `js` = JavaScript
198+
- `ts` = TypeScript
199+
200+
If a language is unknown or not mapped, the full language name is emitted.
201+
125202
## Format Syntax
126203

127204
### Basic Key-Value

0 commit comments

Comments
 (0)