gcf-python 0.1.2__py3-none-any.whl → 0.2.0__py3-none-any.whl
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.
- gcf/__init__.py +1 -1
- gcf/decode.py +7 -0
- gcf/encode.py +13 -7
- gcf/generic.py +8 -7
- gcf/session.py +13 -7
- {gcf_python-0.1.2.dist-info → gcf_python-0.2.0.dist-info}/METADATA +17 -10
- gcf_python-0.2.0.dist-info/RECORD +14 -0
- gcf_python-0.1.2.dist-info/RECORD +0 -14
- {gcf_python-0.1.2.dist-info → gcf_python-0.2.0.dist-info}/WHEEL +0 -0
- {gcf_python-0.1.2.dist-info → gcf_python-0.2.0.dist-info}/entry_points.txt +0 -0
- {gcf_python-0.1.2.dist-info → gcf_python-0.2.0.dist-info}/licenses/LICENSE +0 -0
gcf/__init__.py
CHANGED
gcf/decode.py
CHANGED
|
@@ -34,6 +34,9 @@ def decode(input_text: str) -> Payload:
|
|
|
34
34
|
raise DecodeError(f"invalid header, expected 'GCF ...' got {header!r}")
|
|
35
35
|
_parse_header(header[4:], p)
|
|
36
36
|
|
|
37
|
+
if not p.tool:
|
|
38
|
+
raise DecodeError("header missing required 'tool' field")
|
|
39
|
+
|
|
37
40
|
# Parse body: symbols and edges.
|
|
38
41
|
symbols: list[Symbol] = []
|
|
39
42
|
sym_by_id: dict[int, Symbol] = {}
|
|
@@ -48,6 +51,10 @@ def decode(input_text: str) -> Payload:
|
|
|
48
51
|
# Group header.
|
|
49
52
|
if line.startswith("## "):
|
|
50
53
|
group = line[3:]
|
|
54
|
+
# Strip bracket suffix: "edges [200]" -> "edges"
|
|
55
|
+
bracket_idx = group.find(" [")
|
|
56
|
+
if bracket_idx >= 0:
|
|
57
|
+
group = group[:bracket_idx]
|
|
51
58
|
in_edges = group == "edges"
|
|
52
59
|
if not in_edges:
|
|
53
60
|
if group == "targets":
|
gcf/encode.py
CHANGED
|
@@ -17,17 +17,23 @@ def encode(p: Payload) -> str:
|
|
|
17
17
|
"""
|
|
18
18
|
parts: list[str] = []
|
|
19
19
|
|
|
20
|
-
# Header line.
|
|
21
|
-
header = f"GCF tool={p.tool} budget={p.token_budget} tokens={p.tokens_used} symbols={len(p.symbols)}"
|
|
22
|
-
if p.pack_root:
|
|
23
|
-
header += f" pack_root={p.pack_root}"
|
|
24
|
-
parts.append(header)
|
|
25
|
-
|
|
26
20
|
# Build symbol index for edge references.
|
|
27
21
|
sym_index: dict[str, int] = {}
|
|
28
22
|
for i, s in enumerate(p.symbols):
|
|
29
23
|
sym_index[s.qualified_name] = i
|
|
30
24
|
|
|
25
|
+
# Count valid edges (both endpoints in symbol index).
|
|
26
|
+
valid_edges = sum(
|
|
27
|
+
1 for e in p.edges
|
|
28
|
+
if e.source in sym_index and e.target in sym_index
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
# Header line.
|
|
32
|
+
header = f"GCF tool={p.tool} budget={p.token_budget} tokens={p.tokens_used} symbols={len(p.symbols)} edges={valid_edges}"
|
|
33
|
+
if p.pack_root:
|
|
34
|
+
header += f" pack_root={p.pack_root}"
|
|
35
|
+
parts.append(header)
|
|
36
|
+
|
|
31
37
|
# Group symbols by distance.
|
|
32
38
|
groups = _group_by_distance(p.symbols)
|
|
33
39
|
group_names = ["targets", "related", "extended"]
|
|
@@ -58,7 +64,7 @@ def encode(p: Payload) -> str:
|
|
|
58
64
|
if e.status and e.status != "unchanged":
|
|
59
65
|
line += f" {e.status}"
|
|
60
66
|
edge_lines.append(line)
|
|
61
|
-
parts.append("## edges")
|
|
67
|
+
parts.append(f"## edges [{len(edge_lines)}]")
|
|
62
68
|
parts.extend(edge_lines)
|
|
63
69
|
|
|
64
70
|
return "\n".join(parts) + "\n"
|
gcf/generic.py
CHANGED
|
@@ -18,6 +18,8 @@ def encode_generic(data: Any) -> str:
|
|
|
18
18
|
Returns:
|
|
19
19
|
GCF-formatted text string.
|
|
20
20
|
"""
|
|
21
|
+
if data is None or not isinstance(data, (dict, list)):
|
|
22
|
+
return str(data) if data is not None else "-"
|
|
21
23
|
lines: list[str] = []
|
|
22
24
|
_encode_value(data, lines, depth=0)
|
|
23
25
|
return "\n".join(lines) + "\n" if lines else "\n"
|
|
@@ -33,15 +35,16 @@ def _encode_value(value: Any, lines: list[str], depth: int) -> None:
|
|
|
33
35
|
lines.append(_indent(depth) + _format_value(value))
|
|
34
36
|
|
|
35
37
|
|
|
36
|
-
def _encode_dict(d: dict, lines: list[str], depth: int) -> None:
|
|
38
|
+
def _encode_dict(d: dict, lines: list[str], depth: int, name: str | None = None) -> None:
|
|
37
39
|
"""Encode a dict into key=value pairs with section headers for nested values."""
|
|
38
40
|
prefix = _indent(depth)
|
|
41
|
+
if name is not None:
|
|
42
|
+
lines.append(f"{prefix}## {name}")
|
|
39
43
|
for key, value in d.items():
|
|
40
44
|
if isinstance(value, list):
|
|
41
45
|
_encode_array(value, key, lines, depth)
|
|
42
46
|
elif isinstance(value, dict):
|
|
43
|
-
|
|
44
|
-
_encode_dict(value, lines, depth + 1)
|
|
47
|
+
_encode_dict(value, lines, depth + 1, name=key)
|
|
45
48
|
else:
|
|
46
49
|
lines.append(f"{prefix}{key}={_format_value(value)}")
|
|
47
50
|
|
|
@@ -85,14 +88,12 @@ def _encode_tabular(items: list[dict], name: str, lines: list[str], depth: int)
|
|
|
85
88
|
|
|
86
89
|
if nested_fields:
|
|
87
90
|
lines.append(f"{prefix}@{i} {row_str}")
|
|
88
|
-
inner_prefix = _indent(depth + 1)
|
|
89
91
|
for nk in nested_fields:
|
|
90
92
|
nv = item.get(nk)
|
|
91
93
|
if isinstance(nv, list):
|
|
92
94
|
_encode_array(nv, nk, lines, depth + 1)
|
|
93
95
|
elif isinstance(nv, dict):
|
|
94
|
-
|
|
95
|
-
_encode_dict(nv, lines, depth + 2)
|
|
96
|
+
_encode_dict(nv, lines, depth + 1, name=nk)
|
|
96
97
|
else:
|
|
97
98
|
lines.append(f"{prefix}{row_str}")
|
|
98
99
|
|
|
@@ -141,7 +142,7 @@ def _format_value(value: Any) -> str:
|
|
|
141
142
|
return str(value)
|
|
142
143
|
s = str(value)
|
|
143
144
|
if "|" in s or "\n" in s or s == "":
|
|
144
|
-
escaped = s.replace("\\", "\\\\").replace('"', '\\"')
|
|
145
|
+
escaped = s.replace("\\", "\\\\").replace('"', '\\"').replace("\n", "\\n")
|
|
145
146
|
return f'"{escaped}"'
|
|
146
147
|
return s
|
|
147
148
|
|
gcf/session.py
CHANGED
|
@@ -77,20 +77,26 @@ def encode_with_session(p: Payload, sess: Session | None = None) -> str:
|
|
|
77
77
|
|
|
78
78
|
parts: list[str] = []
|
|
79
79
|
|
|
80
|
+
# Build local ID mapping for this response.
|
|
81
|
+
local_index: dict[str, int] = {}
|
|
82
|
+
for i, s in enumerate(p.symbols):
|
|
83
|
+
local_index[s.qualified_name] = i
|
|
84
|
+
|
|
85
|
+
# Count valid edges.
|
|
86
|
+
valid_edges = sum(
|
|
87
|
+
1 for e in p.edges
|
|
88
|
+
if e.source in local_index and e.target in local_index
|
|
89
|
+
)
|
|
90
|
+
|
|
80
91
|
# Header with session=true marker.
|
|
81
92
|
header = (
|
|
82
93
|
f"GCF tool={p.tool} budget={p.token_budget} tokens={p.tokens_used} "
|
|
83
|
-
f"symbols={len(p.symbols)} session=true"
|
|
94
|
+
f"symbols={len(p.symbols)} edges={valid_edges} session=true"
|
|
84
95
|
)
|
|
85
96
|
if p.pack_root:
|
|
86
97
|
header += f" pack_root={p.pack_root}"
|
|
87
98
|
parts.append(header)
|
|
88
99
|
|
|
89
|
-
# Build local ID mapping for this response.
|
|
90
|
-
local_index: dict[str, int] = {}
|
|
91
|
-
for i, s in enumerate(p.symbols):
|
|
92
|
-
local_index[s.qualified_name] = i
|
|
93
|
-
|
|
94
100
|
# Track which symbols are new (need full declaration).
|
|
95
101
|
new_symbols: list[Symbol] = []
|
|
96
102
|
|
|
@@ -122,7 +128,7 @@ def encode_with_session(p: Payload, sess: Session | None = None) -> str:
|
|
|
122
128
|
|
|
123
129
|
# Edges section.
|
|
124
130
|
if p.edges:
|
|
125
|
-
parts.append("## edges")
|
|
131
|
+
parts.append(f"## edges [{valid_edges}]")
|
|
126
132
|
for e in p.edges:
|
|
127
133
|
src_idx = local_index.get(e.source)
|
|
128
134
|
tgt_idx = local_index.get(e.target)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gcf-python
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Python implementation of GCF (Graph Compact Format): token-optimized wire format for LLM tool responses
|
|
5
5
|
Project-URL: Homepage, https://github.com/blackwell-systems/gcf-python
|
|
6
6
|
Project-URL: Documentation, https://blackwell-systems.github.io/gcf/
|
|
@@ -30,9 +30,11 @@ Description-Content-Type: text/markdown
|
|
|
30
30
|
|
|
31
31
|
# gcf-python
|
|
32
32
|
|
|
33
|
-
Python implementation of [GCF (Graph Compact Format)](https://
|
|
33
|
+
Python implementation of [GCF (Graph Compact Format)](https://gcformat.com/) — the most token-efficient wire format for LLMs. A drop-in alternative to JSON and TOON for any structured data.
|
|
34
34
|
|
|
35
|
-
**
|
|
35
|
+
**79% fewer input tokens than JSON. 75% fewer output tokens. 52% smaller than TOON. 100% LLM comprehension at 500 symbols, where JSON fails at 66.7%.**
|
|
36
|
+
|
|
37
|
+
Docs: [gcformat.com](https://gcformat.com/) · [Playground](https://gcformat.com/playground.html) · [GCF vs TOON](https://gcformat.com/guide/vs-toon.html)
|
|
36
38
|
|
|
37
39
|
## Install
|
|
38
40
|
|
|
@@ -40,7 +42,7 @@ Python implementation of [GCF (Graph Compact Format)](https://github.com/blackwe
|
|
|
40
42
|
pip install gcf-python
|
|
41
43
|
```
|
|
42
44
|
|
|
43
|
-
Zero dependencies. Pure Python. Python 3.9+. Includes CLI.
|
|
45
|
+
Zero dependencies. Pure Python. Python 3.9+. Includes CLI. Don't want to change code? Use the [MCP proxy](https://github.com/blackwell-systems/gcf-proxy) for zero-code adoption.
|
|
44
46
|
|
|
45
47
|
## CLI
|
|
46
48
|
|
|
@@ -84,12 +86,12 @@ output = encode(p)
|
|
|
84
86
|
|
|
85
87
|
Output:
|
|
86
88
|
```
|
|
87
|
-
GCF tool=context_for_task budget=5000 tokens=1847 symbols=2
|
|
89
|
+
GCF tool=context_for_task budget=5000 tokens=1847 symbols=2 edges=1
|
|
88
90
|
## targets
|
|
89
91
|
@0 fn pkg.AuthMiddleware 0.78 lsp_resolved
|
|
90
92
|
## related
|
|
91
93
|
@1 fn pkg.NewServer 0.54 lsp_resolved
|
|
92
|
-
## edges
|
|
94
|
+
## edges [1]
|
|
93
95
|
@0<@1 calls
|
|
94
96
|
```
|
|
95
97
|
|
|
@@ -211,11 +213,16 @@ GCF wins on every dataset except deeply nested config (75 tokens on a 618-token
|
|
|
211
213
|
|
|
212
214
|
Reproducible: [blackwell-systems/toon@gcf-comparison](https://github.com/blackwell-systems/toon/tree/gcf-comparison)
|
|
213
215
|
|
|
214
|
-
##
|
|
216
|
+
## Links
|
|
215
217
|
|
|
216
|
-
-
|
|
217
|
-
-
|
|
218
|
-
-
|
|
218
|
+
- [Documentation](https://gcformat.com/)
|
|
219
|
+
- [Playground](https://gcformat.com/playground.html)
|
|
220
|
+
- [Specification](https://github.com/blackwell-systems/gcf)
|
|
221
|
+
- [Go library](https://github.com/blackwell-systems/gcf-go)
|
|
222
|
+
- [TypeScript library](https://github.com/blackwell-systems/gcf-typescript)
|
|
223
|
+
- [MCP Proxy](https://github.com/blackwell-systems/gcf-proxy) (zero-code adoption)
|
|
224
|
+
- [GCF vs TOON](https://gcformat.com/guide/vs-toon.html)
|
|
225
|
+
- [TOON benchmark fork](https://github.com/blackwell-systems/toon/tree/gcf-comparison)
|
|
219
226
|
|
|
220
227
|
## License
|
|
221
228
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
gcf/__init__.py,sha256=epW-CoQh3RBrnF3-lWSiPS-DI4HUlRRe8q9JeLPRxwE,1541
|
|
2
|
+
gcf/cli.py,sha256=2hSTBqiYcn1_EgGXuO65MHiEGh0C4DRMvspTd2zUaso,4258
|
|
3
|
+
gcf/constants.py,sha256=cmZ8YJSOB0im_eyfN8v4UvrLpBC6Fuf4cfcKZGbutxY,638
|
|
4
|
+
gcf/decode.py,sha256=48G6XmBilGYl0-c_Xy7MX0iTwOxGW9bn3wC4UyNApc4,5465
|
|
5
|
+
gcf/delta.py,sha256=xU0ujtSq1iF7yU8yk_WNQKh8iove-WUV_nKSuvW1XVk,1656
|
|
6
|
+
gcf/encode.py,sha256=Oljb1r5b7SHmng1XYvcvuJMpaRfJVJ81VOyocPf_kAs,2915
|
|
7
|
+
gcf/generic.py,sha256=xSXCufl4uK3xaDDPsKb4g5Mf0B-HVePzzwnwKYXJ8OU,5200
|
|
8
|
+
gcf/session.py,sha256=4_ARRL06Tg2CI8D2eyi0V5nFphFAFMfOKBXYnAbI6Nk,4690
|
|
9
|
+
gcf/types.py,sha256=AWm-LQoSqLHAYtEjcAxWQZqJ4JXqNreLUKO2mJFgNMA,1465
|
|
10
|
+
gcf_python-0.2.0.dist-info/METADATA,sha256=2YETOadgxh76qeHmHYZKOcpAo-4HGLyBQBh3BC148cA,7929
|
|
11
|
+
gcf_python-0.2.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
12
|
+
gcf_python-0.2.0.dist-info/entry_points.txt,sha256=aFT6gqlkh8iGfM8cblE-LUMxHH08_v71IIoZtDdRIVA,37
|
|
13
|
+
gcf_python-0.2.0.dist-info/licenses/LICENSE,sha256=txSvg3E4LugiB7MOOTci6WKd6wMOrOJTvaITeFJ2SgU,1074
|
|
14
|
+
gcf_python-0.2.0.dist-info/RECORD,,
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
gcf/__init__.py,sha256=bhnoIK9Qk7tMgWX_3q6HFvE3w55yw5rw2jyFHx7Bqx8,1541
|
|
2
|
-
gcf/cli.py,sha256=2hSTBqiYcn1_EgGXuO65MHiEGh0C4DRMvspTd2zUaso,4258
|
|
3
|
-
gcf/constants.py,sha256=cmZ8YJSOB0im_eyfN8v4UvrLpBC6Fuf4cfcKZGbutxY,638
|
|
4
|
-
gcf/decode.py,sha256=gkBW9fmcurQ9bfcDXbaCOWemMmljo_MiZMj3-1rYvsw,5198
|
|
5
|
-
gcf/delta.py,sha256=xU0ujtSq1iF7yU8yk_WNQKh8iove-WUV_nKSuvW1XVk,1656
|
|
6
|
-
gcf/encode.py,sha256=WZCRv1Vj2PDTYvBgv__2P8GHh8FapxfAZmt5zo0k9Jc,2700
|
|
7
|
-
gcf/generic.py,sha256=N4rhf3JAdQHcWA9HEbTPxWnMfvdac6oZzQHQSnZdXdE,5105
|
|
8
|
-
gcf/session.py,sha256=F8OTJCMRMCY7Yzcvd7aU8wlbER0LZAMUcB4W9kHeSq4,4508
|
|
9
|
-
gcf/types.py,sha256=AWm-LQoSqLHAYtEjcAxWQZqJ4JXqNreLUKO2mJFgNMA,1465
|
|
10
|
-
gcf_python-0.1.2.dist-info/METADATA,sha256=FumNV9D2FUZfkUor89SPotIgLTo2QXmUhT9RHZc4DYk,7320
|
|
11
|
-
gcf_python-0.1.2.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
12
|
-
gcf_python-0.1.2.dist-info/entry_points.txt,sha256=aFT6gqlkh8iGfM8cblE-LUMxHH08_v71IIoZtDdRIVA,37
|
|
13
|
-
gcf_python-0.1.2.dist-info/licenses/LICENSE,sha256=txSvg3E4LugiB7MOOTci6WKd6wMOrOJTvaITeFJ2SgU,1074
|
|
14
|
-
gcf_python-0.1.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|