agentlaw 0.1.1__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 (106) hide show
  1. agentlaw-0.1.1/LICENSE +21 -0
  2. agentlaw-0.1.1/PKG-INFO +206 -0
  3. agentlaw-0.1.1/README.md +172 -0
  4. agentlaw-0.1.1/pyproject.toml +74 -0
  5. agentlaw-0.1.1/setup.cfg +4 -0
  6. agentlaw-0.1.1/src/agentlaw/__init__.py +3 -0
  7. agentlaw-0.1.1/src/agentlaw/__main__.py +4 -0
  8. agentlaw-0.1.1/src/agentlaw/agent_setup/__init__.py +5 -0
  9. agentlaw-0.1.1/src/agentlaw/agent_setup/claude.py +193 -0
  10. agentlaw-0.1.1/src/agentlaw/agent_setup/codex.py +221 -0
  11. agentlaw-0.1.1/src/agentlaw/agent_setup/gemini.py +236 -0
  12. agentlaw-0.1.1/src/agentlaw/agent_setup/models.py +40 -0
  13. agentlaw-0.1.1/src/agentlaw/agent_setup/prompt.py +264 -0
  14. agentlaw-0.1.1/src/agentlaw/agent_setup/runner.py +344 -0
  15. agentlaw-0.1.1/src/agentlaw/cli.py +526 -0
  16. agentlaw-0.1.1/src/agentlaw/db.py +134 -0
  17. agentlaw-0.1.1/src/agentlaw/embeddings.py +208 -0
  18. agentlaw-0.1.1/src/agentlaw/init_cmd.py +190 -0
  19. agentlaw-0.1.1/src/agentlaw/memory_cmd.py +67 -0
  20. agentlaw-0.1.1/src/agentlaw/now_cmd.py +27 -0
  21. agentlaw-0.1.1/src/agentlaw/recovery_cmd.py +184 -0
  22. agentlaw-0.1.1/src/agentlaw/scaffold/AGENTLAW_CONSTITUTION.md +189 -0
  23. agentlaw-0.1.1/src/agentlaw/scaffold/AGENTLAW_FIX_TOOL.md +224 -0
  24. agentlaw-0.1.1/src/agentlaw/scaffold/AGENTLAW_INIT_TOOL.md +211 -0
  25. agentlaw-0.1.1/src/agentlaw/scaffold/AGENTLAW_UPDATE_TOOL.md +190 -0
  26. agentlaw-0.1.1/src/agentlaw/scaffold/AGENTS.md +87 -0
  27. agentlaw-0.1.1/src/agentlaw/scaffold/LICENSE +21 -0
  28. agentlaw-0.1.1/src/agentlaw/scaffold/README.md +153 -0
  29. agentlaw-0.1.1/src/agentlaw/scaffold/SECURITY.md +6 -0
  30. agentlaw-0.1.1/src/agentlaw/scaffold/docs/contracts/agentlaw-mcp-tools.md +545 -0
  31. agentlaw-0.1.1/src/agentlaw/scaffold/docs/contracts/agentlaw-update-workflow.md +113 -0
  32. agentlaw-0.1.1/src/agentlaw/scaffold/docs/contracts/shared-agentlaw-baseline.md +27 -0
  33. agentlaw-0.1.1/src/agentlaw/scaffold/docs/law/CODE_AUTHORSHIP_AND_STEWARDSHIP_RULES.md +281 -0
  34. agentlaw-0.1.1/src/agentlaw/scaffold/docs/law/FAILURE_TAXONOMY.md +189 -0
  35. agentlaw-0.1.1/src/agentlaw/scaffold/docs/law/INPUT_OUTPUT_CONTRACT.md +233 -0
  36. agentlaw-0.1.1/src/agentlaw/scaffold/docs/law/MECHANICAL_ENFORCEMENT_POLICY.md +68 -0
  37. agentlaw-0.1.1/src/agentlaw/scaffold/docs/law/MEMORY_AND_CONTINUITY_RULES.md +816 -0
  38. agentlaw-0.1.1/src/agentlaw/scaffold/docs/law/ORACLE_AND_JUDGMENT.md +286 -0
  39. agentlaw-0.1.1/src/agentlaw/scaffold/docs/law/REPOSITORY_ARTIFACT_RULES.md +440 -0
  40. agentlaw-0.1.1/src/agentlaw/scaffold/docs/law/SCOPE.md +85 -0
  41. agentlaw-0.1.1/src/agentlaw/scaffold/docs/law/STARTER_SPECIALIZATION_RULES.md +144 -0
  42. agentlaw-0.1.1/src/agentlaw/scaffold/docs/references/README.md +18 -0
  43. agentlaw-0.1.1/src/agentlaw/scaffold/docs/references/project-overview.md +50 -0
  44. agentlaw-0.1.1/src/agentlaw/scaffold/memory/LOOKUP_RULES.md +41 -0
  45. agentlaw-0.1.1/src/agentlaw/scaffold/memory/known-facts/README.md +5 -0
  46. agentlaw-0.1.1/src/agentlaw/scaffold/memory/logs/README.md +5 -0
  47. agentlaw-0.1.1/src/agentlaw/scaffold/memory/preferences.md +17 -0
  48. agentlaw-0.1.1/src/agentlaw/scaffold/memory/rules/README.md +5 -0
  49. agentlaw-0.1.1/src/agentlaw/scaffold/memory/working-set.md +30 -0
  50. agentlaw-0.1.1/src/agentlaw/scaffold/plans/active/README.md +5 -0
  51. agentlaw-0.1.1/src/agentlaw/scaffold/plans/completed/README.md +5 -0
  52. agentlaw-0.1.1/src/agentlaw/scaffold/plans/tech-debt-tracker.md +42 -0
  53. agentlaw-0.1.1/src/agentlaw/schema/v001_initial.sql +248 -0
  54. agentlaw-0.1.1/src/agentlaw/schema/v002_embedding_metadata.sql +42 -0
  55. agentlaw-0.1.1/src/agentlaw/schema/v003_runtime_repair_jobs.sql +23 -0
  56. agentlaw-0.1.1/src/agentlaw/schema/v004_runtime_repair_job_operation.sql +47 -0
  57. agentlaw-0.1.1/src/agentlaw/schema/v005_runtime_repair_jobs_table.sql +43 -0
  58. agentlaw-0.1.1/src/agentlaw/schema/v006_rule_memory_type.sql +76 -0
  59. agentlaw-0.1.1/src/agentlaw/server/__init__.py +1 -0
  60. agentlaw-0.1.1/src/agentlaw/server/app.py +159 -0
  61. agentlaw-0.1.1/src/agentlaw/server/tools/__init__.py +1 -0
  62. agentlaw-0.1.1/src/agentlaw/server/tools/authority.py +760 -0
  63. agentlaw-0.1.1/src/agentlaw/server/tools/governance.py +183 -0
  64. agentlaw-0.1.1/src/agentlaw/server/tools/ops.py +303 -0
  65. agentlaw-0.1.1/src/agentlaw/server/tools/read.py +622 -0
  66. agentlaw-0.1.1/src/agentlaw/server/tools/runtime_index.py +275 -0
  67. agentlaw-0.1.1/src/agentlaw/server/tools/runtime_jobs.py +269 -0
  68. agentlaw-0.1.1/src/agentlaw/server/tools/runtime_repair_service.py +129 -0
  69. agentlaw-0.1.1/src/agentlaw/server/tools/runtime_sources.py +298 -0
  70. agentlaw-0.1.1/src/agentlaw/server/tools/search.py +557 -0
  71. agentlaw-0.1.1/src/agentlaw/server/tools/session.py +1163 -0
  72. agentlaw-0.1.1/src/agentlaw/server/tools/source_reader.py +345 -0
  73. agentlaw-0.1.1/src/agentlaw/server/tools/write.py +1514 -0
  74. agentlaw-0.1.1/src/agentlaw/session_cmd.py +50 -0
  75. agentlaw-0.1.1/src/agentlaw/target_verify_cmd.py +189 -0
  76. agentlaw-0.1.1/src/agentlaw/verify_cmd.py +1127 -0
  77. agentlaw-0.1.1/src/agentlaw.egg-info/PKG-INFO +206 -0
  78. agentlaw-0.1.1/src/agentlaw.egg-info/SOURCES.txt +104 -0
  79. agentlaw-0.1.1/src/agentlaw.egg-info/dependency_links.txt +1 -0
  80. agentlaw-0.1.1/src/agentlaw.egg-info/entry_points.txt +2 -0
  81. agentlaw-0.1.1/src/agentlaw.egg-info/requires.txt +10 -0
  82. agentlaw-0.1.1/src/agentlaw.egg-info/top_level.txt +1 -0
  83. agentlaw-0.1.1/tests/test_agent_setup.py +443 -0
  84. agentlaw-0.1.1/tests/test_agent_setup_claude.py +83 -0
  85. agentlaw-0.1.1/tests/test_agent_setup_gemini.py +92 -0
  86. agentlaw-0.1.1/tests/test_cli_stdio.py +153 -0
  87. agentlaw-0.1.1/tests/test_db.py +225 -0
  88. agentlaw-0.1.1/tests/test_embeddings.py +190 -0
  89. agentlaw-0.1.1/tests/test_init_cmd.py +162 -0
  90. agentlaw-0.1.1/tests/test_mcp_transport.py +196 -0
  91. agentlaw-0.1.1/tests/test_memory_cmd.py +118 -0
  92. agentlaw-0.1.1/tests/test_memory_source_reader.py +268 -0
  93. agentlaw-0.1.1/tests/test_now_cmd.py +56 -0
  94. agentlaw-0.1.1/tests/test_package_smoke.py +94 -0
  95. agentlaw-0.1.1/tests/test_phase8_tools.py +692 -0
  96. agentlaw-0.1.1/tests/test_read_tools.py +403 -0
  97. agentlaw-0.1.1/tests/test_recovery_cmd.py +91 -0
  98. agentlaw-0.1.1/tests/test_search_tool.py +210 -0
  99. agentlaw-0.1.1/tests/test_server_warmup.py +169 -0
  100. agentlaw-0.1.1/tests/test_session_cmd.py +187 -0
  101. agentlaw-0.1.1/tests/test_session_tools.py +587 -0
  102. agentlaw-0.1.1/tests/test_target_verify_cmd.py +135 -0
  103. agentlaw-0.1.1/tests/test_tool_schemas.py +203 -0
  104. agentlaw-0.1.1/tests/test_topic_mining.py +189 -0
  105. agentlaw-0.1.1/tests/test_verify_cmd.py +846 -0
  106. agentlaw-0.1.1/tests/test_write_tools.py +782 -0
agentlaw-0.1.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 paranmir
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,206 @@
1
+ Metadata-Version: 2.4
2
+ Name: agentlaw
3
+ Version: 0.1.1
4
+ Summary: Law-first governance kit for AI coding agents: installable scaffold + memory MCP server that lets agents read project rules before they write code.
5
+ Author-email: paranmir <yhntgb444@gmail.com>
6
+ Maintainer-email: paranmir <yhntgb444@gmail.com>
7
+ License: MIT
8
+ Project-URL: Homepage, https://github.com/paranmir/agentlaw
9
+ Project-URL: Repository, https://github.com/paranmir/agentlaw
10
+ Project-URL: Issues, https://github.com/paranmir/agentlaw/issues
11
+ Keywords: llm,agents,memory,mcp,harness,governance
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development
20
+ Classifier: Topic :: Software Development :: Libraries
21
+ Requires-Python: >=3.11
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: typer<1,>=0.12
25
+ Requires-Dist: mcp<2,>=1.0
26
+ Requires-Dist: sqlite-vec<0.2,>=0.1.6
27
+ Requires-Dist: sentence-transformers<6,>=5.4
28
+ Requires-Dist: huggingface_hub<2,>=1.11
29
+ Requires-Dist: PyYAML<7,>=6.0
30
+ Provides-Extra: dev
31
+ Requires-Dist: build>=1.2; extra == "dev"
32
+ Requires-Dist: pytest>=8; extra == "dev"
33
+ Dynamic: license-file
34
+
35
+ # agentlaw
36
+
37
+ A law-first governance kit for AI coding agents — install governance structure before writing code.
38
+
39
+ `agentlaw` gives any repository a governed starting structure that AI coding agents can read, follow, and maintain. It works for brand-new repositories and already-existing codebases alike. Drop it in, run the bootstrap, and the agent knows what the rules are before it writes a single line.
40
+
41
+ > This repository is the **authoring workspace** for agentlaw. The public distribution lives at [`paranmir/agentlaw`](https://github.com/paranmir/agentlaw), and the installable Python package will publish to PyPI as `agentlaw`. Most users want the public repo or the PyPI package; this workspace develops the kit using the kit (recursive improvement).
42
+
43
+ ---
44
+
45
+ ## For Humans
46
+
47
+ ### Install
48
+
49
+ Once published to PyPI:
50
+
51
+ ```bash
52
+ pipx install agentlaw
53
+ ```
54
+
55
+ While the workspace is still pre-publish, install from this source tree:
56
+
57
+ ```bash
58
+ git clone https://github.com/paranmir/agentlaw-workspace
59
+ cd agentlaw-workspace
60
+ pip install -e .
61
+ ```
62
+
63
+ ### Quick Start
64
+
65
+ ```bash
66
+ # 1. Place agentlaw governance into your project
67
+ agentlaw init <your-project-dir>
68
+
69
+ # 2. Register the agentlaw-memory MCP server with your AI agent host.
70
+ # The default `--setup-agents prompt` mode emits LLM-actionable
71
+ # instructions — copy them into your agent and let it edit its host
72
+ # config. Restart the host after the edit lands.
73
+
74
+ # 3. Open a fresh chat with your AI agent on the project and say:
75
+ # Restore the session
76
+ # The agent loads the harness context and you can start work.
77
+ ```
78
+
79
+ ### Using agentlaw in Your AI Coding Session
80
+
81
+ Once agentlaw is initialized in a project and the `agentlaw-memory` MCP server is registered with your AI agent host, you drive the harness through natural-language triggers in your conversation. The agent maps each trigger to one of the harness's MCP tools and follows the procedure that the kit ships.
82
+
83
+ **Triggering session restore** — at the start of any new conversation on the project, say one of:
84
+
85
+ - "Restore the session" / "세션 복원해봐"
86
+ - "Pick up where we left off"
87
+ - "지금 어디까지 했어?"
88
+
89
+ The agent calls `agentlaw_session_restore`, the response packet carries the project's working set, every active plan body, the most recent session_save log entry, framework reminders (memory intent rule, write discipline, consult-before-answer rule), and a step-by-step reminder of the §Canonical Restore Route Mandatory Tier the agent must follow before answering. The first turn of every session is a context-loading turn; substantive work starts on turn two.
90
+
91
+ **Triggering session save** — when ending a session, before context compaction, or at any milestone, say one of:
92
+
93
+ - "Save the session" / "세션 저장해줘"
94
+ - "Wrap up and save state"
95
+ - "Snapshot what we did"
96
+
97
+ The agent calls `agentlaw_session_save` with the working frame, and the save tool surfaces a post-save verification obligation that you run after.
98
+
99
+ **When something feels off** — if the agent appears to be answering with stale context or missing rules, ask it to call `agentlaw_session_restore` again, or run `agentlaw mcp-recover --target . --client auto --json` to diagnose MCP connectivity from the shell side.
100
+
101
+ ### What This Project Is
102
+
103
+ **The problem.** AI coding agents arrive at a repository without governance. They make plausible-looking changes that violate invariants the team has not written down. The team adds a CLAUDE.md or AGENTS.md to capture rules; the file grows; the agent reads less of it; the rules silently stop applying. The agent and the team need shared structure they can both rely on.
104
+
105
+ **The kit.** agentlaw installs that structure as governance scaffolding: a constitution, a law layer (memory, artifact, oracle, failure rules), root control tools (init / update / fix), contract documents, a memory subsystem (working set, logs, rules, preferences), and a runtime MCP server that surfaces the rules every session. The agent reads the law before it writes; the kit's verifier mechanically catches drift between the rules and the code.
106
+
107
+ **Recursive improvement.** This authoring workspace develops agentlaw by using agentlaw on itself. Every plan that lands here goes through `AGENTLAW_INIT_TOOL.md` / `AGENTLAW_UPDATE_TOOL.md` / `AGENTLAW_FIX_TOOL.md` rules; every law change is mirrored to the publish-repo seed and to the bundled package scaffold; the same `agentlaw verify` that ships to target projects also runs against this repo. The kit's failures and improvements both surface here first.
108
+
109
+ ### Requirements
110
+
111
+ - **Python** 3.11 or newer (the kit uses `typing.Literal` unpacking and other 3.11-era stdlib features).
112
+ - **Operating systems**: developed on Windows; Ubuntu and macOS are exercised through the publish-readiness CI matrix.
113
+ - **Disk**: the embedding model occupies roughly 500 MB once downloaded (cached under `<your-project>/.harness/models/`).
114
+ - **Runtime dependencies** are declared in `pyproject.toml` under `[project] dependencies` (currently `typer`, `mcp`, `sqlite-vec`, `sentence-transformers`, `huggingface_hub`, `PyYAML`).
115
+ - **Dev dependencies** (`pip install -e ".[dev]"`): `build`, `pytest`.
116
+
117
+ ### Repository Layout (this authoring workspace)
118
+
119
+ ```
120
+ agentlaw-workspace/
121
+ ├── AGENTLAW_CONSTITUTION.md # highest authority
122
+ ├── AGENTLAW_INIT_TOOL.md # bootstrap entry
123
+ ├── AGENTLAW_UPDATE_TOOL.md # update flow
124
+ ├── AGENTLAW_FIX_TOOL.md # gap-fix flow
125
+ ├── AGENTS.md # routing-only entry map
126
+ ├── README.md # this file
127
+ ├── docs/
128
+ │ ├── harness/ # law layer
129
+ │ ├── contracts/ # contract documents (mirrored to publish-repo)
130
+ │ ├── references/ # local references (binaries gitignored)
131
+ │ └── plans/ # active and completed plans
132
+ ├── memory/ # derived continuity (logs, rules, working-set)
133
+ ├── publish-repo/ # PUBLIC distribution seed (separate git repo)
134
+ ├── src/agentlaw/ # Python package (CLI, MCP server, init, verify)
135
+ ├── tests/ # pytest suite
136
+ ├── sync_package_data.py # publish-repo → src/agentlaw/scaffold sync
137
+ └── verify_agentlaw.py # workspace integrity verifier
138
+ ```
139
+
140
+ ### Links
141
+
142
+ - **Public seed** (the kit users install): https://github.com/paranmir/agentlaw
143
+ - **PyPI** (once published): https://pypi.org/project/agentlaw/
144
+ - **This authoring workspace**: https://github.com/paranmir/agentlaw-workspace
145
+ - **Issues**: https://github.com/paranmir/agentlaw/issues
146
+
147
+ ---
148
+
149
+ ## For AI Agents
150
+
151
+ This section is the agent-facing reading order for first-time entry into the kit. If you are reading this README as a new session on a project that has agentlaw installed, follow the §Canonical Restore Route Mandatory Tier in `docs/law/MEMORY_AND_CONTINUITY_RULES.md` instead — that procedure is the binding one. This README is the on-ramp; the law file is the substance.
152
+
153
+ ### Agent Bootstrap (first install)
154
+
155
+ When the user asks you to set up agentlaw in a project:
156
+
157
+ 1. Install agentlaw from the approved source. Published path (post-release): `pipx install agentlaw`. Pre-publish source path: `pip install -e .` from this workspace.
158
+ 2. Run `agentlaw init <target-project> --setup-agents prompt` in the target. The `prompt` default emits LLM-actionable instructions for registering the `agentlaw-memory` MCP server in your host config; read those instructions and edit your host config rather than letting init auto-write to user-level config (that requires `--setup-agents auto --yes`).
159
+ 3. Restart your host after the config edit so the new MCP registration is picked up.
160
+ 4. On the next agent session, call `agentlaw_session_restore` (MCP) or `agentlaw session-restore --target . --json` (CLI fallback) and follow the §Canonical Restore Route Mandatory Tier in the response.
161
+ 5. If the MCP server is not visible in a new session despite restart, run `agentlaw mcp-recover --target . --client auto --json` to diagnose runtime + registration state.
162
+
163
+ ### Layer-by-layer map (what each artifact class is for)
164
+
165
+ - **`AGENTLAW_CONSTITUTION.md`** — highest authority; structural invariants. Rare changes; never violate.
166
+ - **Root control tools** (`AGENTLAW_INIT_TOOL.md`, `AGENTLAW_UPDATE_TOOL.md`, `AGENTLAW_FIX_TOOL.md`) — agent-facing procedure documents. Init bootstraps a fresh project, Update incorporates kit upgrades into an existing target, Fix runs the gap-resolution protocol.
167
+ - **`docs/law/*` (law layer)** — rules every session reads: memory and continuity, artifact rules, oracle and judgment, code authorship and stewardship, failure taxonomy, mechanical enforcement policy, starter specialization rules, scope, input/output contract.
168
+ - **`docs/contracts/*`** — boundary surfaces shared with target projects (MCP tool surface, shared baseline, update workflow). Mirrored to publish-repo.
169
+ - **`docs/references/*`** — research-and-context references; not authoritative.
170
+ - **`memory/*`** — derived continuity (working-set, logs, rules, preferences, lookup rules). Below law in authority.
171
+ - **`docs/plans/active/*` and `docs/plans/completed/*`** — work-in-flight and historical work. Active plans are read-on-restore.
172
+
173
+ ### Governing hierarchy
174
+
175
+ Authority flows top-down:
176
+
177
+ 1. `AGENTLAW_CONSTITUTION.md`
178
+ 2. Root control tools
179
+ 3. `docs/law/*` (law)
180
+ 4. `docs/contracts/*`
181
+ 5. `docs/references/*` (non-authoritative)
182
+ 6. `memory/*`
183
+ 7. `AGENTS.md` (routing only — never a rule store)
184
+
185
+ When two artifacts seem to conflict, the higher one wins. Memory never overrides law; references never override contracts; AGENTS.md is the entry map, not a source of rules.
186
+
187
+ ### Restore procedure on every session start
188
+
189
+ §Canonical Restore Route Mandatory Tier (full body in `docs/law/MEMORY_AND_CONTINUITY_RULES.md`) requires 14 steps before composing a substantive response. Summary: confirm runtime integrity, read the working set, read every law file, read every active plan body, read the most recent session_save log entry, scan recent_logs titles, read every active rule's body, read `memory/preferences.md`, read `memory/LOOKUP_RULES.md`, scan the known-facts manifest, run a working-frame `memory_search` over `current_goal + next_actions + open_questions`, inspect governance drift, assemble the packet, surface gaps to the user. The runtime pre-fetches body fields into the restore packet so the substance is in your context without extra `Read` calls; the procedure is binding regardless.
190
+
191
+ ### Critical rules — quick reference
192
+
193
+ One-line restatements; the binding text lives at the anchors.
194
+
195
+ - **Memory Intent Rule** — when the user expresses intent to remember, persist, or carry forward, resolve to one of `memory_write` / `promotion_proposal` / `associative_marker` / `explicit_non_save` before final response. Anchor: `docs/law/MEMORY_AND_CONTINUITY_RULES.md` §Memory Intent Rule.
196
+ - **Write Discipline** — silence is a valid answer; a write must clear the §Log Write Criterion three-question gate (and the §Item Write Criterion applicability gate for items). Volume is not the target; selectivity is. Anchor: §Write Discipline.
197
+ - **Read Routing Criterion** — classify the question (prior judgment / cross-session / current source) before reaching for `memory_search` vs `Grep`/`Read`. Anchor: §Read Routing Criterion.
198
+ - **Consult-Before-Answer Rule** — for memory-routed questions, consult memory **before** composing the answer, not after. Anchor: §Consult-Before-Answer Rule.
199
+ - **Self-Narration Prohibition** — governed artifact bodies and code comments describe current state only; revision history lives in plans, tracker entries, memory logs, and git, not in the body. Anchor: `docs/law/REPOSITORY_ARTIFACT_RULES.md` §Self-Narration Prohibition (paired with §Reasoning-Critical Inline Comments in `CODE_AUTHORSHIP_AND_STEWARDSHIP_RULES.md`).
200
+ - **Promotion Proposal Protocol** — runtime never selects promotion candidates; the agent judges whether durability + future operational relevance + authority gap all hold, then calls `memory_propose_promotion`. Anchor: §Promotion Proposal Protocol.
201
+
202
+ ---
203
+
204
+ ## License
205
+
206
+ MIT. See `LICENSE`.
@@ -0,0 +1,172 @@
1
+ # agentlaw
2
+
3
+ A law-first governance kit for AI coding agents — install governance structure before writing code.
4
+
5
+ `agentlaw` gives any repository a governed starting structure that AI coding agents can read, follow, and maintain. It works for brand-new repositories and already-existing codebases alike. Drop it in, run the bootstrap, and the agent knows what the rules are before it writes a single line.
6
+
7
+ > This repository is the **authoring workspace** for agentlaw. The public distribution lives at [`paranmir/agentlaw`](https://github.com/paranmir/agentlaw), and the installable Python package will publish to PyPI as `agentlaw`. Most users want the public repo or the PyPI package; this workspace develops the kit using the kit (recursive improvement).
8
+
9
+ ---
10
+
11
+ ## For Humans
12
+
13
+ ### Install
14
+
15
+ Once published to PyPI:
16
+
17
+ ```bash
18
+ pipx install agentlaw
19
+ ```
20
+
21
+ While the workspace is still pre-publish, install from this source tree:
22
+
23
+ ```bash
24
+ git clone https://github.com/paranmir/agentlaw-workspace
25
+ cd agentlaw-workspace
26
+ pip install -e .
27
+ ```
28
+
29
+ ### Quick Start
30
+
31
+ ```bash
32
+ # 1. Place agentlaw governance into your project
33
+ agentlaw init <your-project-dir>
34
+
35
+ # 2. Register the agentlaw-memory MCP server with your AI agent host.
36
+ # The default `--setup-agents prompt` mode emits LLM-actionable
37
+ # instructions — copy them into your agent and let it edit its host
38
+ # config. Restart the host after the edit lands.
39
+
40
+ # 3. Open a fresh chat with your AI agent on the project and say:
41
+ # Restore the session
42
+ # The agent loads the harness context and you can start work.
43
+ ```
44
+
45
+ ### Using agentlaw in Your AI Coding Session
46
+
47
+ Once agentlaw is initialized in a project and the `agentlaw-memory` MCP server is registered with your AI agent host, you drive the harness through natural-language triggers in your conversation. The agent maps each trigger to one of the harness's MCP tools and follows the procedure that the kit ships.
48
+
49
+ **Triggering session restore** — at the start of any new conversation on the project, say one of:
50
+
51
+ - "Restore the session" / "세션 복원해봐"
52
+ - "Pick up where we left off"
53
+ - "지금 어디까지 했어?"
54
+
55
+ The agent calls `agentlaw_session_restore`, the response packet carries the project's working set, every active plan body, the most recent session_save log entry, framework reminders (memory intent rule, write discipline, consult-before-answer rule), and a step-by-step reminder of the §Canonical Restore Route Mandatory Tier the agent must follow before answering. The first turn of every session is a context-loading turn; substantive work starts on turn two.
56
+
57
+ **Triggering session save** — when ending a session, before context compaction, or at any milestone, say one of:
58
+
59
+ - "Save the session" / "세션 저장해줘"
60
+ - "Wrap up and save state"
61
+ - "Snapshot what we did"
62
+
63
+ The agent calls `agentlaw_session_save` with the working frame, and the save tool surfaces a post-save verification obligation that you run after.
64
+
65
+ **When something feels off** — if the agent appears to be answering with stale context or missing rules, ask it to call `agentlaw_session_restore` again, or run `agentlaw mcp-recover --target . --client auto --json` to diagnose MCP connectivity from the shell side.
66
+
67
+ ### What This Project Is
68
+
69
+ **The problem.** AI coding agents arrive at a repository without governance. They make plausible-looking changes that violate invariants the team has not written down. The team adds a CLAUDE.md or AGENTS.md to capture rules; the file grows; the agent reads less of it; the rules silently stop applying. The agent and the team need shared structure they can both rely on.
70
+
71
+ **The kit.** agentlaw installs that structure as governance scaffolding: a constitution, a law layer (memory, artifact, oracle, failure rules), root control tools (init / update / fix), contract documents, a memory subsystem (working set, logs, rules, preferences), and a runtime MCP server that surfaces the rules every session. The agent reads the law before it writes; the kit's verifier mechanically catches drift between the rules and the code.
72
+
73
+ **Recursive improvement.** This authoring workspace develops agentlaw by using agentlaw on itself. Every plan that lands here goes through `AGENTLAW_INIT_TOOL.md` / `AGENTLAW_UPDATE_TOOL.md` / `AGENTLAW_FIX_TOOL.md` rules; every law change is mirrored to the publish-repo seed and to the bundled package scaffold; the same `agentlaw verify` that ships to target projects also runs against this repo. The kit's failures and improvements both surface here first.
74
+
75
+ ### Requirements
76
+
77
+ - **Python** 3.11 or newer (the kit uses `typing.Literal` unpacking and other 3.11-era stdlib features).
78
+ - **Operating systems**: developed on Windows; Ubuntu and macOS are exercised through the publish-readiness CI matrix.
79
+ - **Disk**: the embedding model occupies roughly 500 MB once downloaded (cached under `<your-project>/.harness/models/`).
80
+ - **Runtime dependencies** are declared in `pyproject.toml` under `[project] dependencies` (currently `typer`, `mcp`, `sqlite-vec`, `sentence-transformers`, `huggingface_hub`, `PyYAML`).
81
+ - **Dev dependencies** (`pip install -e ".[dev]"`): `build`, `pytest`.
82
+
83
+ ### Repository Layout (this authoring workspace)
84
+
85
+ ```
86
+ agentlaw-workspace/
87
+ ├── AGENTLAW_CONSTITUTION.md # highest authority
88
+ ├── AGENTLAW_INIT_TOOL.md # bootstrap entry
89
+ ├── AGENTLAW_UPDATE_TOOL.md # update flow
90
+ ├── AGENTLAW_FIX_TOOL.md # gap-fix flow
91
+ ├── AGENTS.md # routing-only entry map
92
+ ├── README.md # this file
93
+ ├── docs/
94
+ │ ├── harness/ # law layer
95
+ │ ├── contracts/ # contract documents (mirrored to publish-repo)
96
+ │ ├── references/ # local references (binaries gitignored)
97
+ │ └── plans/ # active and completed plans
98
+ ├── memory/ # derived continuity (logs, rules, working-set)
99
+ ├── publish-repo/ # PUBLIC distribution seed (separate git repo)
100
+ ├── src/agentlaw/ # Python package (CLI, MCP server, init, verify)
101
+ ├── tests/ # pytest suite
102
+ ├── sync_package_data.py # publish-repo → src/agentlaw/scaffold sync
103
+ └── verify_agentlaw.py # workspace integrity verifier
104
+ ```
105
+
106
+ ### Links
107
+
108
+ - **Public seed** (the kit users install): https://github.com/paranmir/agentlaw
109
+ - **PyPI** (once published): https://pypi.org/project/agentlaw/
110
+ - **This authoring workspace**: https://github.com/paranmir/agentlaw-workspace
111
+ - **Issues**: https://github.com/paranmir/agentlaw/issues
112
+
113
+ ---
114
+
115
+ ## For AI Agents
116
+
117
+ This section is the agent-facing reading order for first-time entry into the kit. If you are reading this README as a new session on a project that has agentlaw installed, follow the §Canonical Restore Route Mandatory Tier in `docs/law/MEMORY_AND_CONTINUITY_RULES.md` instead — that procedure is the binding one. This README is the on-ramp; the law file is the substance.
118
+
119
+ ### Agent Bootstrap (first install)
120
+
121
+ When the user asks you to set up agentlaw in a project:
122
+
123
+ 1. Install agentlaw from the approved source. Published path (post-release): `pipx install agentlaw`. Pre-publish source path: `pip install -e .` from this workspace.
124
+ 2. Run `agentlaw init <target-project> --setup-agents prompt` in the target. The `prompt` default emits LLM-actionable instructions for registering the `agentlaw-memory` MCP server in your host config; read those instructions and edit your host config rather than letting init auto-write to user-level config (that requires `--setup-agents auto --yes`).
125
+ 3. Restart your host after the config edit so the new MCP registration is picked up.
126
+ 4. On the next agent session, call `agentlaw_session_restore` (MCP) or `agentlaw session-restore --target . --json` (CLI fallback) and follow the §Canonical Restore Route Mandatory Tier in the response.
127
+ 5. If the MCP server is not visible in a new session despite restart, run `agentlaw mcp-recover --target . --client auto --json` to diagnose runtime + registration state.
128
+
129
+ ### Layer-by-layer map (what each artifact class is for)
130
+
131
+ - **`AGENTLAW_CONSTITUTION.md`** — highest authority; structural invariants. Rare changes; never violate.
132
+ - **Root control tools** (`AGENTLAW_INIT_TOOL.md`, `AGENTLAW_UPDATE_TOOL.md`, `AGENTLAW_FIX_TOOL.md`) — agent-facing procedure documents. Init bootstraps a fresh project, Update incorporates kit upgrades into an existing target, Fix runs the gap-resolution protocol.
133
+ - **`docs/law/*` (law layer)** — rules every session reads: memory and continuity, artifact rules, oracle and judgment, code authorship and stewardship, failure taxonomy, mechanical enforcement policy, starter specialization rules, scope, input/output contract.
134
+ - **`docs/contracts/*`** — boundary surfaces shared with target projects (MCP tool surface, shared baseline, update workflow). Mirrored to publish-repo.
135
+ - **`docs/references/*`** — research-and-context references; not authoritative.
136
+ - **`memory/*`** — derived continuity (working-set, logs, rules, preferences, lookup rules). Below law in authority.
137
+ - **`docs/plans/active/*` and `docs/plans/completed/*`** — work-in-flight and historical work. Active plans are read-on-restore.
138
+
139
+ ### Governing hierarchy
140
+
141
+ Authority flows top-down:
142
+
143
+ 1. `AGENTLAW_CONSTITUTION.md`
144
+ 2. Root control tools
145
+ 3. `docs/law/*` (law)
146
+ 4. `docs/contracts/*`
147
+ 5. `docs/references/*` (non-authoritative)
148
+ 6. `memory/*`
149
+ 7. `AGENTS.md` (routing only — never a rule store)
150
+
151
+ When two artifacts seem to conflict, the higher one wins. Memory never overrides law; references never override contracts; AGENTS.md is the entry map, not a source of rules.
152
+
153
+ ### Restore procedure on every session start
154
+
155
+ §Canonical Restore Route Mandatory Tier (full body in `docs/law/MEMORY_AND_CONTINUITY_RULES.md`) requires 14 steps before composing a substantive response. Summary: confirm runtime integrity, read the working set, read every law file, read every active plan body, read the most recent session_save log entry, scan recent_logs titles, read every active rule's body, read `memory/preferences.md`, read `memory/LOOKUP_RULES.md`, scan the known-facts manifest, run a working-frame `memory_search` over `current_goal + next_actions + open_questions`, inspect governance drift, assemble the packet, surface gaps to the user. The runtime pre-fetches body fields into the restore packet so the substance is in your context without extra `Read` calls; the procedure is binding regardless.
156
+
157
+ ### Critical rules — quick reference
158
+
159
+ One-line restatements; the binding text lives at the anchors.
160
+
161
+ - **Memory Intent Rule** — when the user expresses intent to remember, persist, or carry forward, resolve to one of `memory_write` / `promotion_proposal` / `associative_marker` / `explicit_non_save` before final response. Anchor: `docs/law/MEMORY_AND_CONTINUITY_RULES.md` §Memory Intent Rule.
162
+ - **Write Discipline** — silence is a valid answer; a write must clear the §Log Write Criterion three-question gate (and the §Item Write Criterion applicability gate for items). Volume is not the target; selectivity is. Anchor: §Write Discipline.
163
+ - **Read Routing Criterion** — classify the question (prior judgment / cross-session / current source) before reaching for `memory_search` vs `Grep`/`Read`. Anchor: §Read Routing Criterion.
164
+ - **Consult-Before-Answer Rule** — for memory-routed questions, consult memory **before** composing the answer, not after. Anchor: §Consult-Before-Answer Rule.
165
+ - **Self-Narration Prohibition** — governed artifact bodies and code comments describe current state only; revision history lives in plans, tracker entries, memory logs, and git, not in the body. Anchor: `docs/law/REPOSITORY_ARTIFACT_RULES.md` §Self-Narration Prohibition (paired with §Reasoning-Critical Inline Comments in `CODE_AUTHORSHIP_AND_STEWARDSHIP_RULES.md`).
166
+ - **Promotion Proposal Protocol** — runtime never selects promotion candidates; the agent judges whether durability + future operational relevance + authority gap all hold, then calls `memory_propose_promotion`. Anchor: §Promotion Proposal Protocol.
167
+
168
+ ---
169
+
170
+ ## License
171
+
172
+ MIT. See `LICENSE`.
@@ -0,0 +1,74 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "agentlaw"
7
+ version = "0.1.1"
8
+ description = "Law-first governance kit for AI coding agents: installable scaffold + memory MCP server that lets agents read project rules before they write code."
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = { text = "MIT" }
12
+ authors = [{ name = "paranmir", email = "yhntgb444@gmail.com" }]
13
+ maintainers = [{ name = "paranmir", email = "yhntgb444@gmail.com" }]
14
+ keywords = ["llm", "agents", "memory", "mcp", "harness", "governance"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Developers",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Topic :: Software Development",
24
+ "Topic :: Software Development :: Libraries",
25
+ ]
26
+
27
+ # Upper bounds reflect the security review's stability-hardening
28
+ # recommendation: pin to the next major to prevent silent breakage on a
29
+ # transitive upgrade. Tested floors (`>=`) come from observed compatible
30
+ # behavior; bumps are intentional, not incidental.
31
+ dependencies = [
32
+ "typer>=0.12,<1",
33
+ "mcp>=1.0,<2",
34
+ "sqlite-vec>=0.1.6,<0.2",
35
+ # Narrow ranges on the embedding stack: offline semantics
36
+ # (HF_HUB_OFFLINE, local_files_only=True) have changed silently across
37
+ # minor releases of both libraries. Freezing the tested range prevents
38
+ # a transitive upgrade from silently re-enabling Hub contact and
39
+ # resurrecting the 2026-04-24 first-call hang.
40
+ "sentence-transformers>=5.4,<6",
41
+ "huggingface_hub>=1.11,<2",
42
+ "PyYAML>=6.0,<7",
43
+ ]
44
+
45
+ [project.optional-dependencies]
46
+ dev = [
47
+ "build>=1.2",
48
+ "pytest>=8",
49
+ ]
50
+
51
+ [project.scripts]
52
+ agentlaw = "agentlaw.cli:app"
53
+
54
+ [tool.pytest.ini_options]
55
+ testpaths = ["tests"]
56
+ markers = [
57
+ "package: package build/install smoke tests; skipped unless HARNESS_RUN_PACKAGE_SMOKE=1.",
58
+ "slow: tests that download the embedding model or do heavy IO; excluded from default runs. Run with `pytest -m slow` to include.",
59
+ ]
60
+ addopts = "-m 'not slow' -ra"
61
+
62
+ [project.urls]
63
+ Homepage = "https://github.com/paranmir/agentlaw"
64
+ Repository = "https://github.com/paranmir/agentlaw"
65
+ Issues = "https://github.com/paranmir/agentlaw/issues"
66
+
67
+ [tool.setuptools.packages.find]
68
+ where = ["src"]
69
+
70
+ [tool.setuptools.package-data]
71
+ agentlaw = [
72
+ "schema/*.sql",
73
+ "scaffold/**/*",
74
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ """Agent Law — installable governance scaffold and memory MCP server."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,4 @@
1
+ from agentlaw.cli import app
2
+
3
+ if __name__ == "__main__":
4
+ app()
@@ -0,0 +1,5 @@
1
+ """Agent host setup orchestration."""
2
+
3
+ from agentlaw.agent_setup.runner import run_agent_setup
4
+
5
+ __all__ = ["run_agent_setup"]