zenofcontext 0.1.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.
@@ -0,0 +1,32 @@
1
+ """The Zen of Context. Like ``import this``, importing prints the principles.
2
+
3
+ Set the environment variable ZENOFCONTEXT_QUIET=1 to import without printing,
4
+ e.g. when using ``zenofcontext.PRINCIPLES`` as data.
5
+ """
6
+
7
+ import os
8
+ import sys
9
+
10
+ from .principles import PRINCIPLES, THEMES, Principle, by_theme, get
11
+ from .render import concise as _concise
12
+
13
+ __version__ = "0.1.0"
14
+ __author__ = "Anuj Sadani"
15
+ __all__ = ["PRINCIPLES", "THEMES", "Principle", "by_theme", "get", "ZEN_CONCISE"]
16
+
17
+ ZEN_CONCISE = _concise()
18
+
19
+
20
+ def _running_cli() -> bool:
21
+ # `zenofcontext ...` console script, or `python -m zenofcontext ...`: the CLI prints instead.
22
+ if os.path.basename(sys.argv[0] or "").split(".")[0] == "zenofcontext":
23
+ return True
24
+ orig = sys.orig_argv
25
+ if "-m" in orig:
26
+ i = orig.index("-m")
27
+ return i + 1 < len(orig) and orig[i + 1] == "zenofcontext"
28
+ return False
29
+
30
+
31
+ if not os.environ.get("ZENOFCONTEXT_QUIET") and not _running_cli():
32
+ print(ZEN_CONCISE)
@@ -0,0 +1,48 @@
1
+ """Command line: ``zenofcontext`` or ``python -m zenofcontext``."""
2
+
3
+ import argparse
4
+ import random
5
+ import sys
6
+
7
+ from . import __version__
8
+ from . import render
9
+ from .principles import PRINCIPLES, get
10
+
11
+
12
+ def main(argv=None) -> int:
13
+ parser = argparse.ArgumentParser(prog="zenofcontext", description="The Zen of Context.")
14
+ mode = parser.add_mutually_exclusive_group()
15
+ mode.add_argument("-v", "--verbose", action="store_true", help="principles with explanations")
16
+ mode.add_argument("-e", "--examples", action="store_true", help="verbose, plus a do/don't example for each")
17
+ mode.add_argument("-t", "--themes", action="store_true", help="grouped by theme: select, shape, trust, maintain")
18
+ mode.add_argument("-n", "--number", type=int, metavar="N", help="show one principle in full (1-%d)" % len(PRINCIPLES))
19
+ mode.add_argument("-r", "--random", action="store_true", help="one random principle, e.g. for a daily reminder")
20
+ mode.add_argument("--checklist", action="store_true", help="Markdown checklist for PR templates or AGENTS.md")
21
+ mode.add_argument("--json", action="store_true", help="machine-readable output")
22
+ parser.add_argument("--version", action="version", version="zenofcontext " + __version__)
23
+ args = parser.parse_args(argv)
24
+
25
+ if args.verbose:
26
+ out = render.verbose()
27
+ elif args.examples:
28
+ out = render.verbose(examples=True)
29
+ elif args.themes:
30
+ out = render.themed()
31
+ elif args.checklist:
32
+ out = render.checklist()
33
+ elif args.json:
34
+ out = render.as_json()
35
+ elif args.number is not None or args.random:
36
+ try:
37
+ p = random.choice(PRINCIPLES) if args.random else get(args.number)
38
+ except KeyError:
39
+ parser.error("principle number must be 1-%d" % len(PRINCIPLES))
40
+ out = "%d. %s\n %s\n Do: %s\n Don't: %s" % (p.number, p.text, p.explanation, p.do, p.dont)
41
+ else:
42
+ out = render.concise()
43
+ print(out)
44
+ return 0
45
+
46
+
47
+ if __name__ == "__main__":
48
+ sys.exit(main())
@@ -0,0 +1,124 @@
1
+ """The principles as structured data."""
2
+
3
+ from dataclasses import dataclass
4
+ from typing import Dict, List, Tuple
5
+
6
+ THEMES: Dict[str, str] = {
7
+ 'select': 'Select',
8
+ 'shape': 'Shape',
9
+ 'trust': 'Trust',
10
+ 'maintain': 'Maintain',
11
+ }
12
+
13
+
14
+ @dataclass(frozen=True)
15
+ class Principle:
16
+ number: int
17
+ text: str
18
+ explanation: str
19
+ theme: str
20
+ do: str
21
+ dont: str
22
+
23
+
24
+ PRINCIPLES: Tuple[Principle, ...] = (
25
+ Principle(
26
+ 1, 'Context is a budget, not a dumping ground.',
27
+ "Every token you add competes for the model's attention and costs time and money. Decide what each piece of context is for before you include it.",
28
+ 'select',
29
+ do='Include the two files the change touches and the failing test.',
30
+ dont='Paste the whole repository "just in case".',
31
+ ),
32
+ Principle(
33
+ 2, 'Relevant is better than complete.',
34
+ "More context doesn't mean better answers; irrelevant material dilutes the signal and can mislead. Rank by relevance to the task and stop when the rest adds little.",
35
+ 'select',
36
+ do='Send the three most relevant policy sections.',
37
+ dont='Send the full 200-page handbook for a question about leave.',
38
+ ),
39
+ Principle(
40
+ 3, 'Just in time is better than just in case.',
41
+ 'Load details when the task needs them, not up front. Give the model a way to fetch more—search, file reads, references—instead of front-loading everything.',
42
+ 'select',
43
+ do='Provide an index of documents and a tool to open one.',
44
+ dont='Preload every document the model might possibly need.',
45
+ ),
46
+ Principle(
47
+ 4, 'Tool results are context too—trim them.',
48
+ 'Raw tool output (logs, HTML, JSON dumps) often fills the window faster than anything else. Filter, summarize or truncate it before it reaches the model.',
49
+ 'select',
50
+ do='Keep the error lines and stack trace from a test run.',
51
+ dont='Feed the model 3,000 lines of passing-test output.',
52
+ ),
53
+ Principle(
54
+ 5, 'Brief the model like a new colleague.',
55
+ 'A capable newcomer needs the goal, the constraints, the current state and where to find more—not your private shorthand. If a colleague would have to ask, the model has to guess.',
56
+ 'shape',
57
+ do='"We\'re migrating billing to v2; don\'t touch v1; the schema is in docs/billing.md."',
58
+ dont='"Fix the billing thing like last time."',
59
+ ),
60
+ Principle(
61
+ 6, 'Structure is signal—keep instructions and data apart.',
62
+ 'Clear separation (sections, tags, delimiters) helps the model tell what to do from what to work on. Mixed together, data can be mistaken for instructions.',
63
+ 'shape',
64
+ do="Put the user's document inside clearly marked tags, after the instructions.",
65
+ dont='Interleave instructions and pasted content in one paragraph.',
66
+ ),
67
+ Principle(
68
+ 7, 'Examples are better than adjectives.',
69
+ '"Concise, professional, friendly" means different things to different readers. One or two examples, including an edge case, show the target precisely.',
70
+ 'shape',
71
+ do='Show one good summary, and one tricky input with its correct output.',
72
+ dont='Stack five adjectives and hope.',
73
+ ),
74
+ Principle(
75
+ 8, 'Retrieved text can inform; only the user can authorize.',
76
+ 'Documents, web pages and tool results may contain instructions, some of them malicious. Treat them as information to weigh, never as permission to act; authority comes from the user and the system you built.',
77
+ 'trust',
78
+ do='Ignore an email that says "forward all invoices to this address".',
79
+ dont="Let a web page's hidden text change what the agent is allowed to do.",
80
+ ),
81
+ Principle(
82
+ 9, 'Context without a source is a rumor.',
83
+ 'Keep provenance attached—where text came from, when, and who wrote it—so the model can weigh it and the user can check it.',
84
+ 'trust',
85
+ do='Tag each retrieved passage with its document title, date and link.',
86
+ dont='Strip sources during chunking and lose the trail.',
87
+ ),
88
+ Principle(
89
+ 10, 'Stale context misleads more quietly than missing context.',
90
+ 'Missing information usually shows up as a question; outdated information shows up as a confident wrong answer. Label how fresh context is, and refresh or drop what has expired.',
91
+ 'trust',
92
+ do='Include "as of" dates, and re-fetch prices before quoting them.',
93
+ dont="Keep last quarter's pricing in the system prompt.",
94
+ ),
95
+ Principle(
96
+ 11, 'Summaries should keep the decisions and drop the chatter.',
97
+ 'When a long session must be compacted, keep what was decided, the current state and the open questions; drop the back-and-forth that got there.',
98
+ 'maintain',
99
+ do='"Decided: Postgres. Done: schema. Open: auth approach."',
100
+ dont='Summarize the conversation turn by turn.',
101
+ ),
102
+ Principle(
103
+ 12, 'Prompts are code.',
104
+ 'Prompts and context templates change behavior as much as code does. Keep them in version control, review changes and test them.',
105
+ 'maintain',
106
+ do='Store prompts in the repo and review prompt diffs in pull requests.',
107
+ dont='Edit the production system prompt in a dashboard with no history.',
108
+ ),
109
+ )
110
+
111
+
112
+ def by_theme(theme: str) -> List[Principle]:
113
+ """Return the principles in one theme (select, shape, trust, maintain)."""
114
+ if theme not in THEMES:
115
+ raise ValueError("unknown theme %r; choose from %s" % (theme, ", ".join(THEMES)))
116
+ return [p for p in PRINCIPLES if p.theme == theme]
117
+
118
+
119
+ def get(number: int) -> Principle:
120
+ """Return a principle by its stable number."""
121
+ for p in PRINCIPLES:
122
+ if p.number == number:
123
+ return p
124
+ raise KeyError(number)
zenofcontext/render.py ADDED
@@ -0,0 +1,53 @@
1
+ """Turn the principles into text: concise, verbose, by theme, checklist, JSON."""
2
+
3
+ import json
4
+ from dataclasses import asdict
5
+
6
+ from .principles import PRINCIPLES, THEMES, by_theme
7
+
8
+ TITLE = "The Zen of Context, by Anuj Sadani"
9
+
10
+
11
+ def concise() -> str:
12
+ lines = [TITLE, ""]
13
+ lines += ["%d. %s" % (p.number, p.text) for p in PRINCIPLES]
14
+ return "\n".join(lines) + "\n"
15
+
16
+
17
+ def verbose(examples: bool = False) -> str:
18
+ lines = ["The Zen of Context (Verbose Edition)", "by Anuj Sadani", ""]
19
+ for p in PRINCIPLES:
20
+ pad = " " * (len(str(p.number)) + 2)
21
+ lines.append("%d. %s" % (p.number, p.text))
22
+ lines.append("%s— %s" % (pad, p.explanation))
23
+ if examples:
24
+ lines.append("%sDo: %s" % (pad, p.do))
25
+ lines.append("%sDon't: %s" % (pad, p.dont))
26
+ lines.append("")
27
+ return "\n".join(lines)
28
+
29
+
30
+ def themed() -> str:
31
+ lines = [TITLE + " — by theme", ""]
32
+ for key, name in THEMES.items():
33
+ lines.append(name)
34
+ lines += [" %d. %s" % (p.number, p.text) for p in by_theme(key)]
35
+ lines.append("")
36
+ return "\n".join(lines)
37
+
38
+
39
+ def checklist() -> str:
40
+ """Markdown checklist for PR templates, AGENTS.md or CLAUDE.md."""
41
+ lines = ["## Context review checklist (Zen of Context)", ""]
42
+ for key, name in THEMES.items():
43
+ lines.append("### " + name)
44
+ lines += ["- [ ] %s _(#%d)_" % (p.do, p.number) for p in by_theme(key)]
45
+ lines.append("")
46
+ return "\n".join(lines)
47
+
48
+
49
+ def as_json() -> str:
50
+ return json.dumps(
51
+ {"themes": THEMES, "principles": [asdict(p) for p in PRINCIPLES]},
52
+ ensure_ascii=False, indent=2,
53
+ )
@@ -0,0 +1,10 @@
1
+ """``from zenofcontext import verbose`` prints the verbose edition."""
2
+
3
+ import os
4
+
5
+ from .render import verbose as _verbose
6
+
7
+ VERBOSE_ZEN = _verbose()
8
+
9
+ if not os.environ.get("ZENOFCONTEXT_QUIET"):
10
+ print(VERBOSE_ZEN)
@@ -0,0 +1,139 @@
1
+ Metadata-Version: 2.4
2
+ Name: zenofcontext
3
+ Version: 0.1.0
4
+ Summary: The Zen of Context: principles for deciding what goes into a model's context window. Printed on import.
5
+ Author-email: Anuj Sadani <anuj.sadani3@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/asadani/zenofcontext
8
+ Project-URL: Issues, https://github.com/asadani/zenofcontext/issues
9
+ Project-URL: Changelog, https://github.com/asadani/zenofcontext/blob/main/CHANGELOG.md
10
+ Keywords: context engineering,prompt engineering,LLM,RAG,AI,Zen
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Topic :: Software Development
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Dynamic: license-file
20
+
21
+ # zenofcontext
22
+
23
+ [![CI](https://github.com/asadani/zenofcontext/actions/workflows/ci.yml/badge.svg)](https://github.com/asadani/zenofcontext/actions/workflows/ci.yml)
24
+ [![PyPI](https://img.shields.io/pypi/v/zenofcontext)](https://pypi.org/project/zenofcontext/)
25
+
26
+ ### The Zen of Context: principles for deciding what goes into a model's context window.
27
+
28
+ What a model sees decides what it does. These principles cover how to select, shape, trust and maintain the context you give a model.
29
+
30
+ `import this` gave Python a shared mindset. `import zenofcontext` does the same for this corner of AI engineering: 12 short principles you can remember, cite by number and argue about.
31
+
32
+ ```bash
33
+ pip install zenofcontext # or: uv pip install zenofcontext / uv add zenofcontext
34
+ uvx zenofcontext --random # run the CLI without installing (uv)
35
+ ```
36
+
37
+ ```python
38
+ >>> import zenofcontext
39
+ The Zen of Context, by Anuj Sadani
40
+
41
+ 1. Context is a budget, not a dumping ground.
42
+ 2. Relevant is better than complete.
43
+ ...
44
+ ```
45
+
46
+ ---
47
+
48
+ ## The principles
49
+
50
+ Numbers are stable across releases, so "see principle 3" in a review always means the same thing.
51
+
52
+ ### Select
53
+ 1. Context is a budget, not a dumping ground.
54
+ 2. Relevant is better than complete.
55
+ 3. Just in time is better than just in case.
56
+ 4. Tool results are context too—trim them.
57
+
58
+ ### Shape
59
+ 5. Brief the model like a new colleague.
60
+ 6. Structure is signal—keep instructions and data apart.
61
+ 7. Examples are better than adjectives.
62
+
63
+ ### Trust
64
+ 8. Retrieved text can inform; only the user can authorize.
65
+ 9. Context without a source is a rumor.
66
+ 10. Stale context misleads more quietly than missing context.
67
+
68
+ ### Maintain
69
+ 11. Summaries should keep the decisions and drop the chatter.
70
+ 12. Prompts are code.
71
+
72
+ Every principle comes with an explanation and a concrete do/don't example: `zenofcontext --examples`.
73
+
74
+ ---
75
+
76
+ ## Usage
77
+
78
+ ### On import
79
+
80
+ ```python
81
+ import zenofcontext # prints the principles
82
+ from zenofcontext import verbose # prints them with explanations
83
+ ```
84
+
85
+ Set `ZENOFCONTEXT_QUIET=1` to import without printing.
86
+
87
+ ### Command line
88
+
89
+ ```bash
90
+ zenofcontext # the principles
91
+ zenofcontext --verbose # with explanations
92
+ zenofcontext --examples # with a do/don't example for each
93
+ zenofcontext --themes # grouped by theme
94
+ zenofcontext -n 3 # one principle in full
95
+ zenofcontext --random # one at random: a daily reminder for your shell profile
96
+ zenofcontext --checklist # Markdown checklist for PRs and agent instructions
97
+ zenofcontext --json # machine-readable
98
+ ```
99
+
100
+ `python -m zenofcontext` works the same way.
101
+
102
+ ### As data
103
+
104
+ ```python
105
+ import os; os.environ["ZENOFCONTEXT_QUIET"] = "1"
106
+ import zenofcontext
107
+
108
+ zenofcontext.get(3).text # "Just in time is better than just in case."
109
+ zenofcontext.by_theme("select") # list of Principle objects
110
+ [p.text for p in zenofcontext.PRINCIPLES]
111
+ ```
112
+
113
+ ---
114
+
115
+ ## Putting it into your workflow
116
+
117
+ A slogan is not a process. The principles help most where decisions are made:
118
+
119
+ - **Pull requests.** Paste `zenofcontext --checklist` into `.github/pull_request_template.md`. Reviewers can then point to a principle by number.
120
+ - **Coding agents.** Add the checklist (or `zenofcontext --themes`) to `AGENTS.md`, `CLAUDE.md` or your editor's rules file, so your agent works by the same standard you review by.
121
+ - **Onboarding.** `zenofcontext --examples` is a short read for anyone new to the team's approach.
122
+
123
+ ---
124
+
125
+ ## What this is, and isn't
126
+
127
+ - It **is** a compact, opinionated philosophy and a shared vocabulary for teams.
128
+ - It **isn't** a linter, a framework or a replacement for engineering judgment.
129
+ - It's **vendor-neutral**: no principle depends on a particular model, framework or vendor.
130
+
131
+ ---
132
+
133
+ ## Contributing
134
+
135
+ The principles should evolve through discussion, not by decree. Propose a new principle, a rewording or a better example by opening an issue. See [CONTRIBUTING.md](CONTRIBUTING.md).
136
+
137
+ ## License
138
+
139
+ [MIT](LICENSE)
@@ -0,0 +1,11 @@
1
+ zenofcontext/__init__.py,sha256=LLZTItkybSfgqn6p1u1m6QI-8sNc18akAGvAJVA0kCA,980
2
+ zenofcontext/__main__.py,sha256=xMzWuz3b7okSh9eJp7uTwq_-6cPY45IZ4-11PS-P9Bw,2020
3
+ zenofcontext/principles.py,sha256=sAhXIWcZ-cK8AQUeUXZkJuvCZKmZf2UQ-tGep6hlpRs,5845
4
+ zenofcontext/render.py,sha256=I6-_cL3EKzz-ViLXEM74YHSk-GVqrhoxo6xl6hFDtWs,1647
5
+ zenofcontext/verbose.py,sha256=fV_RBr-L2BjbQJYaSJbnmmy1Wg9_eEpugNrAAPrFnUg,218
6
+ zenofcontext-0.1.0.dist-info/licenses/LICENSE,sha256=ZLTwi-H42dk58Vbp1Ih8Grg_JqoJ1PkddBD5MpPf8gY,1068
7
+ zenofcontext-0.1.0.dist-info/METADATA,sha256=fp3tM-vH5p5ZBPzvzBzbEpVAuyCniqa_QHWJPfa-1_Q,4809
8
+ zenofcontext-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
9
+ zenofcontext-0.1.0.dist-info/entry_points.txt,sha256=_pIsaKnQ-yucLVL1qTruL81m18n2IMbeQgERjwvCKRM,60
10
+ zenofcontext-0.1.0.dist-info/top_level.txt,sha256=MZNHKzIagb89EzdGSfAjvCU0wdsUYSkuhEH6NOj3Uuw,13
11
+ zenofcontext-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ zenofcontext = zenofcontext.__main__:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Anuj Sadani
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ zenofcontext