gemcode 0.2.2__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.
Files changed (58) hide show
  1. gemcode/__init__.py +3 -0
  2. gemcode/__main__.py +3 -0
  3. gemcode/agent.py +146 -0
  4. gemcode/audit.py +16 -0
  5. gemcode/callbacks.py +473 -0
  6. gemcode/capability_routing.py +137 -0
  7. gemcode/cli.py +658 -0
  8. gemcode/compaction.py +35 -0
  9. gemcode/computer_use/__init__.py +0 -0
  10. gemcode/computer_use/browser_computer.py +275 -0
  11. gemcode/config.py +247 -0
  12. gemcode/interactions.py +15 -0
  13. gemcode/invoke.py +151 -0
  14. gemcode/kairos_daemon.py +221 -0
  15. gemcode/limits.py +83 -0
  16. gemcode/live_audio_engine.py +124 -0
  17. gemcode/mcp_loader.py +57 -0
  18. gemcode/memory/__init__.py +0 -0
  19. gemcode/memory/embedding_memory_service.py +292 -0
  20. gemcode/memory/file_memory_service.py +176 -0
  21. gemcode/modality_tools.py +216 -0
  22. gemcode/model_routing.py +179 -0
  23. gemcode/paths.py +29 -0
  24. gemcode/permissions.py +5 -0
  25. gemcode/plugins/__init__.py +0 -0
  26. gemcode/plugins/terminal_hooks_plugin.py +168 -0
  27. gemcode/plugins/tool_recovery_plugin.py +135 -0
  28. gemcode/prompt_suggestions.py +80 -0
  29. gemcode/query/__init__.py +36 -0
  30. gemcode/query/config.py +35 -0
  31. gemcode/query/deps.py +20 -0
  32. gemcode/query/engine.py +55 -0
  33. gemcode/query/stop_hooks.py +63 -0
  34. gemcode/query/token_budget.py +109 -0
  35. gemcode/query/transitions.py +41 -0
  36. gemcode/session_runtime.py +81 -0
  37. gemcode/thinking.py +136 -0
  38. gemcode/tool_prompt_manifest.py +118 -0
  39. gemcode/tool_registry.py +50 -0
  40. gemcode/tools/__init__.py +25 -0
  41. gemcode/tools/edit.py +53 -0
  42. gemcode/tools/filesystem.py +73 -0
  43. gemcode/tools/search.py +85 -0
  44. gemcode/tools/shell.py +73 -0
  45. gemcode/tools_inspector.py +132 -0
  46. gemcode/trust.py +54 -0
  47. gemcode/tui/app.py +697 -0
  48. gemcode/tui/scrollback.py +312 -0
  49. gemcode/vertex.py +22 -0
  50. gemcode/web/__init__.py +2 -0
  51. gemcode/web/claude_sse_adapter.py +282 -0
  52. gemcode/web/terminal_repl.py +147 -0
  53. gemcode-0.2.2.dist-info/METADATA +440 -0
  54. gemcode-0.2.2.dist-info/RECORD +58 -0
  55. gemcode-0.2.2.dist-info/WHEEL +5 -0
  56. gemcode-0.2.2.dist-info/entry_points.txt +2 -0
  57. gemcode-0.2.2.dist-info/licenses/LICENSE +151 -0
  58. gemcode-0.2.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,147 @@
1
+ from __future__ import annotations
2
+
3
+ import asyncio
4
+ import os
5
+ import sys
6
+ from pathlib import Path
7
+ from typing import Any
8
+
9
+ from gemcode.config import GemCodeConfig
10
+ from gemcode.session_runtime import create_runner
11
+ from gemcode.web.claude_sse_adapter import _extract_text_from_event
12
+
13
+
14
+ def _truthy_env(name: str, *, default: bool = False) -> bool:
15
+ v = os.environ.get(name)
16
+ if v is None:
17
+ return default
18
+ return v.lower() in ("1", "true", "yes", "on")
19
+
20
+
21
+ async def run_single_turn(
22
+ *,
23
+ runner: Any,
24
+ cfg: GemCodeConfig,
25
+ prompt: str,
26
+ user_id: str,
27
+ session_id: str,
28
+ ) -> None:
29
+ """
30
+ Run one user line through GemCode's ADK runner, streaming incremental
31
+ assistant-visible text to stdout (so the browser can render it as PTY
32
+ output bytes).
33
+ """
34
+ # Import here to avoid module import overhead / side effects at startup.
35
+ from google.adk.agents.run_config import RunConfig
36
+ from google.genai import types
37
+
38
+ emitted_text = ""
39
+
40
+ new_message = types.Content(role="user", parts=[types.Part(text=prompt)])
41
+ run_config = (
42
+ RunConfig(max_llm_calls=cfg.max_llm_calls)
43
+ if cfg.max_llm_calls is not None
44
+ else None
45
+ )
46
+
47
+ kwargs: dict[str, Any] = {
48
+ "user_id": user_id,
49
+ "session_id": session_id,
50
+ "new_message": new_message,
51
+ }
52
+ if run_config is not None:
53
+ kwargs["run_config"] = run_config
54
+
55
+ async for event in runner.run_async(**kwargs):
56
+ text = _extract_text_from_event(event)
57
+ if not text:
58
+ continue
59
+
60
+ # Match the delta logic from the Claude SSE adapter so the UI can
61
+ # render incremental output without repeating content.
62
+ if text.startswith(emitted_text):
63
+ delta = text[len(emitted_text) :]
64
+ else:
65
+ common = 0
66
+ max_common = min(len(text), len(emitted_text))
67
+ while common < max_common and text[common] == emitted_text[common]:
68
+ common += 1
69
+ delta = text[common:]
70
+
71
+ if delta:
72
+ emitted_text += delta
73
+ sys.stdout.write(delta)
74
+ sys.stdout.flush()
75
+
76
+
77
+ async def run_mock_turn(prompt: str) -> None:
78
+ mock_response = os.environ.get("GEMCODE_WEB_MOCK_RESPONSE")
79
+ if not isinstance(mock_response, str) or not mock_response.strip():
80
+ return
81
+
82
+ chunk_size = int(os.environ.get("GEMCODE_WEB_MOCK_CHUNK", "6"))
83
+ # Provide a tiny delay to make streaming observable in the terminal.
84
+ full = mock_response
85
+ for i in range(0, len(full), max(1, chunk_size)):
86
+ delta = full[i : i + chunk_size]
87
+ sys.stdout.write(delta)
88
+ sys.stdout.flush()
89
+ await asyncio.sleep(0.01)
90
+
91
+
92
+ async def repl() -> None:
93
+ project_root = os.environ.get("GEMCODE_WEB_PROJECT_ROOT") or os.getcwd()
94
+
95
+ cfg = GemCodeConfig(project_root=Path(project_root))
96
+ cfg.permission_mode = os.environ.get("GEMCODE_PERMISSION_MODE", cfg.permission_mode)
97
+ cfg.yes_to_all = _truthy_env("GEMCODE_WEB_YES_TO_ALL", default=False)
98
+ # Avoid interactive HITL prompts inside the terminal PTY.
99
+ cfg.interactive_permission_ask = False
100
+
101
+ session_id = os.environ.get("GEMCODE_TERMINAL_SESSION_ID") or "terminal"
102
+ user_id = os.environ.get("GEMCODE_TERMINAL_USER_ID") or "web-terminal"
103
+
104
+ runner = create_runner(cfg, extra_tools=None)
105
+
106
+ # Terminal.js expects the PTY output stream, so keep banners minimal.
107
+ sys.stdout.write("")
108
+ sys.stdout.flush()
109
+
110
+ try:
111
+ while True:
112
+ line = sys.stdin.readline()
113
+ if not line:
114
+ break
115
+
116
+ prompt = line.rstrip("\n").rstrip("\r").strip()
117
+ if not prompt:
118
+ continue
119
+
120
+ if prompt.lower() in {"exit", "quit", "/exit", "/quit"}:
121
+ break
122
+
123
+ await run_mock_turn(prompt)
124
+ if os.environ.get("GEMCODE_WEB_MOCK_RESPONSE"):
125
+ continue
126
+
127
+ await run_single_turn(
128
+ runner=runner,
129
+ cfg=cfg,
130
+ prompt=prompt,
131
+ user_id=user_id,
132
+ session_id=session_id,
133
+ )
134
+ finally:
135
+ try:
136
+ await runner.close()
137
+ except Exception:
138
+ pass
139
+
140
+
141
+ def main() -> None:
142
+ asyncio.run(repl())
143
+
144
+
145
+ if __name__ == "__main__":
146
+ main()
147
+
@@ -0,0 +1,440 @@
1
+ Metadata-Version: 2.4
2
+ Name: gemcode
3
+ Version: 0.2.2
4
+ Summary: Local-first coding agent on Google Gemini + ADK
5
+ Author: GemCode Contributors
6
+ License: Apache License
7
+ Version 2.0, January 2004
8
+ http://www.apache.org/licenses/
9
+
10
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
11
+
12
+ 1. Definitions.
13
+
14
+ "License" shall mean the terms and conditions for use, reproduction,
15
+ and distribution as defined by Sections 1 through 9 of this document.
16
+
17
+ "Licensor" shall mean the copyright owner or entity authorized by
18
+ the copyright owner that is granting the License.
19
+
20
+ "Legal Entity" shall mean the union of the acting entity and all
21
+ other entities that control, are controlled by, or are under common
22
+ control with that entity. For the purposes of this definition,
23
+ "control" means (i) the power, direct or indirect, to cause the
24
+ direction or management of such entity, whether by contract or
25
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
26
+ outstanding shares, or (iii) beneficial ownership of such entity.
27
+
28
+ "You" (or "Your") shall mean an individual or Legal Entity
29
+ exercising permissions granted by this License.
30
+
31
+ "Source" form shall mean the preferred form for making modifications,
32
+ including but not limited to software source code, documentation
33
+ source, and configuration files.
34
+
35
+ "Object" form shall mean any form resulting from mechanical
36
+ transformation or translation of a Source form, including but
37
+ not limited to compiled object code, generated documentation,
38
+ and conversions to other media types.
39
+
40
+ "Work" shall mean the work of authorship, whether in Source or
41
+ Object form, made available under the License, as indicated by a
42
+ copyright notice that is included in or attached to the work
43
+ (an example is provided in the Appendix below).
44
+
45
+ "Derivative Works" shall mean any work, whether in Source or Object
46
+ form, that is based on (or derived from) the Work and for which the
47
+ editorial revisions, annotations, elaborations, or other modifications
48
+ represent, as a whole, an original work of authorship. For the purposes
49
+ of this License, Derivative Works shall not include works that remain
50
+ separable from, or merely link (or bind by name) to the interfaces of,
51
+ the Work and Derivative Works thereof.
52
+
53
+ "Contribution" shall mean any work of authorship, including
54
+ the original version of the Work and any modifications or additions
55
+ to that Work or Derivative Works thereof, that is intentionally
56
+ submitted to Licensor for inclusion in the Work by the copyright owner
57
+ or by an individual or Legal Entity authorized to submit on behalf of
58
+ the copyright owner. For the purposes of this definition, "submitted"
59
+ means any form of electronic, verbal, or written communication sent
60
+ to the Licensor or its representatives, including but not limited to
61
+ communication on electronic mailing lists, source code control systems,
62
+ and issue tracking systems that are managed by, or on behalf of, the
63
+ Licensor for the purpose of discussing and improving the Work, but
64
+ excluding communication that is conspicuously marked or otherwise
65
+ designated in writing by the copyright owner as "Not a Contribution."
66
+
67
+ "Contributor" shall mean Licensor and any individual or Legal Entity
68
+ on behalf of whom a Contribution has been received by Licensor and
69
+ subsequently incorporated within the Work.
70
+
71
+ 2. Grant of Copyright License. Subject to the terms and conditions of
72
+ this License, each Contributor hereby grants to You a perpetual,
73
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
74
+ copyright license to reproduce, prepare Derivative Works of,
75
+ publicly display, publicly perform, sublicense, and distribute the
76
+ Work and such Derivative Works in Source or Object form.
77
+
78
+ 3. Grant of Patent License. Subject to the terms and conditions of
79
+ this License, each Contributor hereby grants to You a perpetual,
80
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
81
+ (except as stated in this section) patent license to make, have made,
82
+ use, offer to sell, sell, import, and otherwise transfer the Work,
83
+ where such license applies only to those patent claims licensable
84
+ by such Contributor that are necessarily infringed by their
85
+ Contribution(s) alone or by combination of their Contribution(s)
86
+ with the Work to which such Contribution(s) was submitted. If You
87
+ institute patent litigation against any entity (including a
88
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
89
+ or a Contribution incorporated within the Work constitutes direct
90
+ or contributory patent infringement, then any patent licenses
91
+ granted to You under this License for that Work shall terminate
92
+ as of the date such litigation is filed.
93
+
94
+ 4. Redistribution. You may reproduce and distribute copies of the
95
+ Work or Derivative Works thereof in any medium, with or without
96
+ modifications, and in Source or Object form, provided that You
97
+ meet the following conditions:
98
+
99
+ (a) You must give any other recipients of the Work or
100
+ Derivative Works a copy of this License; and
101
+
102
+ (b) You must cause any modified files to carry prominent notices
103
+ stating that You changed the files; and
104
+
105
+ (c) You must retain, in the Source form of any Derivative Works
106
+ that You distribute, all copyright, patent, trademark, and
107
+ attribution notices from the Source form of the Work,
108
+ excluding those notices that do not pertain to any part of
109
+ the Derivative Works; and
110
+
111
+ (d) If the Work includes a "NOTICE" text file as part of its
112
+ distribution, then any Derivative Works that You distribute must
113
+ include a readable copy of the attribution notices contained
114
+ within such NOTICE file, excluding those notices that do not
115
+ pertain to any part of the Derivative Works, in at least one
116
+ of the following places: within a NOTICE text file distributed
117
+ as part of the Derivative Works; within the Source form or
118
+ documentation, if provided along with the Derivative Works; or,
119
+ within a display generated by the Derivative Works, if and
120
+ wherever such third-party notices normally appear. The contents
121
+ of the NOTICE file are for informational purposes only and
122
+ do not modify the License. You may add Your own attribution
123
+ notices within Derivative Works that You distribute, alongside
124
+ or as an addendum to the NOTICE text from the Work, provided
125
+ that such additional attribution notices cannot be construed
126
+ as modifying the License.
127
+
128
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
129
+ any Contribution intentionally submitted for inclusion in the Work
130
+ by You to the Licensor shall be under the terms and conditions of
131
+ this License, without any additional terms or conditions.
132
+
133
+ 6. Trademarks. This License does not grant permission to use the trade
134
+ names, trademarks, service marks, or product names of the Licensor.
135
+
136
+ 7. Disclaimer of Warranty. Unless required by applicable law or
137
+ agreed to in writing, Licensor provides the Work (and each
138
+ Contributor provides its Contributions) on an "AS IS" BASIS,
139
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
140
+
141
+ 8. Limitation of Liability. In no event and under no legal theory,
142
+ whether in tort (including negligence), contract, or otherwise,
143
+ unless required by applicable law, shall any Contributor be liable
144
+ to You for damages, including any direct, indirect, special,
145
+ incidental, or consequential damages arising in any way out of the
146
+ use of the Work.
147
+
148
+ 9. Accepting Warranty or Additional Liability. While redistributing
149
+ the Work or Derivative Works thereof, You may choose to offer,
150
+ and charge a fee for, acceptance of support, warranty, indemnity,
151
+ or other liability obligations and/or rights consistent with this
152
+ License. However, in accepting such obligations, You may act only
153
+ on Your own behalf and on Your sole responsibility.
154
+
155
+ END OF TERMS AND CONDITIONS
156
+
157
+
158
+ Project-URL: Homepage, https://github.com/spiderdev27/GemCode
159
+ Project-URL: Repository, https://github.com/spiderdev27/GemCode
160
+ Project-URL: Issues, https://github.com/spiderdev27/GemCode/issues
161
+ Keywords: ai,agent,coding,gemini,adk,cli,tui
162
+ Classifier: Development Status :: 3 - Alpha
163
+ Classifier: Environment :: Console
164
+ Classifier: Intended Audience :: Developers
165
+ Classifier: License :: OSI Approved :: Apache Software License
166
+ Classifier: Operating System :: OS Independent
167
+ Classifier: Programming Language :: Python :: 3
168
+ Classifier: Programming Language :: Python :: 3 :: Only
169
+ Classifier: Programming Language :: Python :: 3.11
170
+ Classifier: Programming Language :: Python :: 3.12
171
+ Classifier: Programming Language :: Python :: 3.13
172
+ Classifier: Topic :: Software Development
173
+ Classifier: Topic :: Software Development :: Libraries
174
+ Classifier: Topic :: Terminals
175
+ Requires-Python: >=3.11
176
+ Description-Content-Type: text/markdown
177
+ License-File: LICENSE
178
+ Requires-Dist: google-adk>=1.0.0
179
+ Requires-Dist: google-genai>=1.0.0
180
+ Requires-Dist: python-dotenv>=1.0.0
181
+ Provides-Extra: dev
182
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
183
+ Requires-Dist: pytest-asyncio>=0.24.0; extra == "dev"
184
+ Provides-Extra: mcp
185
+ Requires-Dist: mcp>=1.0.0; extra == "mcp"
186
+ Provides-Extra: tui
187
+ Requires-Dist: prompt_toolkit>=3.0.0; extra == "tui"
188
+ Requires-Dist: rich>=13.0.0; extra == "tui"
189
+ Dynamic: license-file
190
+
191
+ # GemCode
192
+
193
+ Local-first coding agent: **Gemini** + **[Google ADK](https://google.github.io/adk-docs/)**, with repo tools, permissions, session persistence, and optional MCP. Implemented in clean-room fashion (reference only to third-party Claude Code trees).
194
+
195
+ ## Requirements
196
+
197
+ - Python 3.11+
198
+ - A [Google AI Studio API key](https://aistudio.google.com/app/apikey) (`GOOGLE_API_KEY`)
199
+
200
+ ## Install
201
+
202
+ ```bash
203
+ cd gemcode
204
+ python3 -m venv .venv
205
+ source .venv/bin/activate # Windows: .venv\Scripts\activate
206
+ pip install -e ".[dev]"
207
+ ```
208
+
209
+ Copy `.env.example` to `.env` and set `GOOGLE_API_KEY`.
210
+
211
+ ## Usage
212
+
213
+ From a git repository root (or pass `-C /path/to/repo`):
214
+
215
+ ```bash
216
+ gemcode "Explain the structure of src/"
217
+ gemcode --yes "Add a module docstring to src/foo.py"
218
+ gemcode --session mysess --yes "Continue: run tests and fix failures"
219
+ ```
220
+
221
+ - **`--yes`**: allow mutating tools (`write_file`, `search_replace`). Shell execution is still restricted by the `.env.example` allowlist.
222
+ - **`--session`**: Conversation history is stored under `.gemcode/sessions.sqlite` (ADK `SqliteSessionService`). Reuse the same `--session` id to continue.
223
+ - **`--max-llm-calls`**: cap model↔tool iterations for this message (maps to ADK `RunConfig.max_llm_calls`). You can also set `GEMCODE_MAX_LLM_CALLS`.
224
+ - **`--model-mode`**: choose model routing mode (`auto|fast|balanced|quality`, default `fast`). In `auto`, GemCode heuristically picks a model for the prompt.
225
+ - **Gemini family routing**: set `GEMCODE_MODEL_FAMILY_MODE=auto|primary|alt`.
226
+ - `primary` uses the `GEMCODE_MODEL*` ids (Gemini 3.x defaults)
227
+ - `alt` uses the `GEMCODE_MODEL_ALT*` ids (Gemini 2.5 family defaults)
228
+ - `auto` uses a cheap prompt heuristic to prefer Gemini 3.x for complex tasks and Gemini 2.5 for simpler ones.
229
+ - **Deep research**: set `--deep-research` (or `GEMCODE_ENABLE_DEEP_RESEARCH=1`) to enable research tools and route to `GEMCODE_MODEL_DEEP_RESEARCH` (default: `travel_explore`).
230
+ - Gemini 3.x tool context circulation (built-in tools + custom/function tools)
231
+ - Enabled by default for `--deep-research` runs, so Search/URL/Maps results can be combined with your custom tools in the same workflow.
232
+ - Controlled by `GEMCODE_TOOL_COMBINATION_MODE` / `--tool-combination-mode` (`deep_research|always|never|auto`, default: `deep_research`).
233
+ - **Embeddings**: set `--embeddings` (or `GEMCODE_ENABLE_EMBEDDINGS=1`) to enable embeddings-based semantic retrieval (and embedding-backed memory when `GEMCODE_ENABLE_MEMORY=1`).
234
+ - **Capability routing**: set `--capability-mode` (or `GEMCODE_CAPABILITY_MODE`) to `auto|research|embeddings|computer|audio|all` to enable the right toolsets (deep research / embeddings / computer-use) and route to role-appropriate models when applicable.
235
+ - **Tool inventory / validation**:
236
+ - `gemcode tools list` prints the exact tool inventory and whether each tool can build a Gemini tool declaration
237
+ - `gemcode tools smoke` fails non-zero if any tool’s declaration compilation fails
238
+ - Optional inspection flags: `--deep-research`, `--maps-grounding`, `--embeddings`, `--memory`
239
+ - **Optional compaction**: set `GEMCODE_ENABLE_COMPACT=1` to trim old `Content` entries before each model call (MVP sliding window; can break complex tool chains if too aggressive—tune `GEMCODE_MAX_CONTENT_ITEMS`).
240
+ - **Session token ceiling**: set `GEMCODE_MAX_SESSION_TOKENS` to stop the next LLM call when cumulative `usage_metadata.total_token_count` exceeds the limit.
241
+ - **Token budget tracking**: set `GEMCODE_TOKEN_BUDGET` to enforce continuation/stop decisions per user turn (token-budget audit in `.gemcode/audit.log`).
242
+ - **Stop-the-loop hooks**: set `GEMCODE_POST_TURN_HOOK=/path/to/hook.sh` (or place an executable at `.gemcode/hooks/post_turn`) to run after each user message.
243
+ - **Circuit breaker**: set `GEMCODE_MAX_CONSECUTIVE_TOOL_FAILURES` to block further tools after N consecutive tool errors.
244
+ - **Recovery-loop**: ADK `ReflectAndRetryToolPlugin`-based retries on tool failures.
245
+ - Set `GEMCODE_ENABLE_TOOL_RECOVERY_RETRY=0` to disable.
246
+ - Set `GEMCODE_TOOL_REFLECT_MAX_RETRIES=1` to control retries per tool.
247
+ - **Gemini thinking controls (Claude-like)**:
248
+ - By default GemCode lets Gemini use its dynamic/adaptive thinking behavior.
249
+ - Set `GEMCODE_DISABLE_THINKING=1` to force a best-effort “low thinking” mode:
250
+ - Gemini 3.x: uses `thinkingLevel=minimal` (can't fully disable)
251
+ - Gemini 2.5: uses `thinkingBudget=0` (disables thinking where supported)
252
+ - Enable thought summaries for debugging with `GEMCODE_INCLUDE_THOUGHT_SUMMARIES=1` (increases tokens/cost).
253
+ - Fine-tune explicitly:
254
+ - `GEMCODE_THINKING_LEVEL=minimal|low|medium|high` (Gemini 3.x only)
255
+ - `GEMCODE_THINKING_BUDGET=0|-1|1024` (Gemini 2.5 only)
256
+ - Additionally, when `model_mode` is set to `fast|balanced|quality` and you
257
+ haven't provided explicit `GEMCODE_THINKING_*` overrides:
258
+ - Gemini 3.x auto-maps `fast|balanced|quality` to `thinkingLevel`
259
+ - Gemini 2.5 auto-maps `fast|balanced|quality` to `thinkingBudget`
260
+ - If `model_mode=auto`, GemCode leaves thinking unmodified.
261
+ - **Persistent memory (optional)**: set `GEMCODE_ENABLE_MEMORY=1` to ingest conversation snippets and retrieve relevant memories on future turns.
262
+ - **Project context**: optional `GEMINI.md` in the project root is injected into the system instruction.
263
+
264
+ ### Permissions
265
+
266
+ - **`GEMCODE_PERMISSION_MODE=strict`**: writes and `run_command` are blocked unless the command name is in `GEMCODE_ALLOW_COMMANDS`.
267
+ - **`default`**: reads always allowed; writes require `--yes`; shell runs only allowlisted commands (see `.env.example`).
268
+ - **In-run HITL permission ask (optional)**:
269
+ - Enable with `--interactive-ask` or `GEMCODE_INTERACTIVE_PERMISSION_ASK=1`.
270
+ - When enabled and you did NOT pass `--yes`, GemCode prompts you in the terminal to approve mutating tools (`write_file`, `search_replace`) and computer-use actions (browser automation).
271
+ - If you don’t approve, the tool call is blocked (no silent re-execution).
272
+
273
+ When tools are blocked by policy, the consecutive-tool circuit breaker does not count those policy rejections as “tool failures”.
274
+
275
+ Optional debugging: set `GEMCODE_EMIT_TOOL_USE_SUMMARIES=1` to write a lightweight `tool_result` record per tool into `.gemcode/audit.log`.
276
+
277
+ ### Optional MCP
278
+
279
+ Install with `pip install -e ".[mcp]"` and create `.gemcode/mcp.json` (see [gemcode/mcp_loader.py](src/gemcode/mcp_loader.py)). Run with `--mcp` to attach configured servers.
280
+
281
+ ### Vertex AI / Interactions API
282
+
283
+ See [src/gemcode/vertex.py](src/gemcode/vertex.py) and [src/gemcode/interactions.py](src/gemcode/interactions.py) for environment variables and future wiring.
284
+
285
+ ## Tools and “Powers”
286
+
287
+ GemCode wires tools into Gemini via ADK in a Claude Code–style outer/inner
288
+ loop:
289
+
290
+ - **Outer loop** (your CLI / session) sets model + tools + safety gates and
291
+ then streams the resulting Events.
292
+ - **Inner loop** (inside ADK) repeatedly calls the model and executes tools
293
+ until completion or stop conditions.
294
+
295
+ ### Core function tools (custom, always available)
296
+
297
+ GemCode always exposes a set of function tools you can use to read and edit
298
+ the user’s project.
299
+
300
+ - Read-only tools (typically allowed without `--yes`):
301
+ - `read_file`
302
+ - `list_directory`
303
+ - `glob_files`
304
+ - `grep_content`
305
+ - Mutating tools (require `--yes` unless your policy blocks them):
306
+ - `write_file`
307
+ - `search_replace`
308
+ - Shell execution:
309
+ - `run_command` (guarded by `GEMCODE_ALLOW_COMMANDS` from `.env.example` and
310
+ `GEMCODE_PERMISSION_MODE`).
311
+
312
+ Tool execution is still controlled by permission gates and then governed by
313
+ GemCode’s circuit breaker + recovery behavior.
314
+
315
+ ### In-run interactive permission ask (HITL)
316
+
317
+ GemCode can switch from “fail closed unless you re-run with `--yes`” to an
318
+ in-run approval workflow:
319
+
320
+ - If enabled (`--interactive-ask` / `GEMCODE_INTERACTIVE_PERMISSION_ASK=1`) and you did not pass `--yes`,
321
+ any mutating tool call or computer-use action will trigger a terminal prompt.
322
+ - Approving continues the same run; rejecting blocks the tool call.
323
+
324
+ This applies to both the standard CLI (`gemcode "..."`) and the Kairos daemon (`gemcode kairos`).
325
+
326
+ ### Kairos proactive scheduler (daemon)
327
+
328
+ `gemcode kairos` runs a long-lived scheduler that turns prompts into queued
329
+ jobs:
330
+
331
+ - You type one prompt per line into stdin; each line becomes a job.
332
+ - Jobs are run with a priority queue; the daemon also exposes Kairos tools so
333
+ the model itself can `kairos_enqueue_prompt()` additional work.
334
+
335
+ Kairos tools available to the model (per job):
336
+
337
+ - `kairos_sleep_ms(duration_ms: int)`: pauses just that job for `duration_ms` without blocking other queued jobs.
338
+ - `kairos_enqueue_prompt(prompt: str, priority: int = 0, session_id: str | None = None)`:
339
+ enqueues a new job. If `session_id` is omitted, it defaults to the current job’s session.
340
+
341
+ Priority defaults for stdin-enqueued jobs are controlled by `--default-priority`.
342
+
343
+ ### Deep research (built-in Gemini tools + optional tool combination)
344
+
345
+ When deep research is enabled (CLI `--deep-research` or `GEMCODE_ENABLE_DEEP_RESEARCH=1`),
346
+ GemCode injects Gemini built-in tools:
347
+
348
+ - `google_search`
349
+ - `url_context`
350
+ - `google_maps_grounding` (optional; only injected when explicitly enabled via
351
+ `--maps-grounding` or `GEMCODE_ENABLE_MAPS_GROUNDING=1`)
352
+
353
+ On Gemini **3.x** models, GemCode can additionally enable Gemini’s built-in
354
+ tool context circulation so built-in results (Search/URL/Maps) can be
355
+ combined with your custom tools in the same workflow:
356
+
357
+ - Controlled by `GEMCODE_TOOL_COMBINATION_MODE` / `--tool-combination-mode`
358
+ (`deep_research|always|never|auto`, default: `deep_research`).
359
+
360
+ ### Embeddings (semantic retrieval + embedding-backed memory)
361
+
362
+ When embeddings are enabled (`--embeddings` or `GEMCODE_ENABLE_EMBEDDINGS=1`),
363
+ GemCode injects a semantic retrieval tool:
364
+
365
+ - `semantic_search_files` (embeds query + candidate file chunks, ranks via cosine similarity).
366
+
367
+ If you also enable persistent memory ingestion (`GEMCODE_ENABLE_MEMORY=1`),
368
+ GemCode uses embedding-backed memory storage:
369
+
370
+ - `EmbeddingFileMemoryService` stores both text and vectors in `.gemcode/memories.jsonl`.
371
+ - Retrieval uses cosine similarity and falls back to keyword search when needed.
372
+
373
+ ### Computer Use (optional, gated browser automation)
374
+
375
+ When computer use is enabled (`GEMCODE_ENABLE_COMPUTER_USE=1` or `--capability-mode computer`),
376
+ GemCode adds an ADK `ComputerUseToolset` backed by Playwright (`BrowserComputer`).
377
+
378
+ Notes:
379
+
380
+ - Requires optional deps: `playwright` (and you should run `playwright install`).
381
+ - Browser automation actions are **still permission-gated**:
382
+ - In `default` permission mode, computer-use tool calls require `--yes`.
383
+ - In `strict` mode, computer use is denied.
384
+ - Headless mode is controlled by `GEMCODE_COMPUTER_HEADLESS`.
385
+
386
+ ### Live audio (Gemini Live API via ADK)
387
+
388
+ GemCode also supports real-time audio sessions via `gemcode live-audio`.
389
+ It streams microphone audio to Gemini using ADK’s `Runner.run_live()` and
390
+ prints model text parts.
391
+
392
+ This MVP requires optional deps:
393
+
394
+ - `sounddevice`
395
+ - `numpy`
396
+
397
+ You can configure:
398
+
399
+ - record duration (`--seconds`)
400
+ - PCM sample rate (`--rate`)
401
+ - optional language (`--language`)
402
+ - optional model override (`--model`, must support AUDIO streaming)
403
+
404
+ ### Memory ingestion + prompt suggestions
405
+
406
+ After each run, `GemCodeTerminalHooksPlugin`:
407
+
408
+ - writes a structured terminal reason to `.gemcode/audit.log`
409
+ - optionally ingests the session into memory (via ADK memory integration)
410
+ - optionally generates “next-step” prompt suggestions:
411
+ - uses `gemcode/prompt_suggestions.py` heuristics
412
+ - if `GEMCODE_PROMPT_SUGGESTIONS_USE_INTERACTIONS=1`, it can also call Gemini
413
+ using the Interactions API to produce a better suggestion
414
+ - runs your stopHooks-like post-turn script from `GEMCODE_POST_TURN_HOOK` (or
415
+ `.gemcode/hooks/post_turn`)
416
+
417
+ ### Safety, circuit breaker, and recovery
418
+
419
+ GemCode enforces:
420
+
421
+ - **Permission gates** via ADK callbacks:
422
+ - `GEMCODE_PERMISSION_MODE=strict` blocks writes and shell (unless allowlisted)
423
+ - mutating + computer-use tool calls require `--yes` in default mode
424
+ - **Consecutive tool failure circuit breaker**:
425
+ - capped by `GEMCODE_MAX_CONSECUTIVE_TOOL_FAILURES`
426
+ - policy rejections don’t increment the streak
427
+ - **Recovery-loop**:
428
+ - ADK `ReflectAndRetryToolPlugin`-based retries on retryable tool errors
429
+ - recovery skips policy denials and circuit breaker blocks
430
+
431
+ ## Development
432
+
433
+ ```bash
434
+ pip install -e ".[dev]"
435
+ pytest
436
+ ```
437
+
438
+ ## References (local only)
439
+
440
+ Do not commit proprietary leaked trees into this package. Keep `claude-code-leaked/` and similar folders outside version control or in a private mirror.
@@ -0,0 +1,58 @@
1
+ gemcode/__init__.py,sha256=t4MRGiDnfwoooXSyGyGVwkyp23qZ_GhLbXPtPp5OwjA,65
2
+ gemcode/__main__.py,sha256=EX2s1hxq2Yvli_-tnBN3w5Qv4bOjsBBbjyISF0pDIQw,37
3
+ gemcode/agent.py,sha256=9Sr5frzycaPI6HshyZXD_Ppz0xrJ7BDidjd62NNFRYQ,4859
4
+ gemcode/audit.py,sha256=bh9uhXaeh8wqxqoZtz3ZAowd8Ndk1ss-mw9993Vlrgo,469
5
+ gemcode/callbacks.py,sha256=NWHfPKQzk7095hhFp5TveN61eyoltPvbNFMdDfB26Ag,16162
6
+ gemcode/capability_routing.py,sha256=D8tvawmf_MSL94GVXgG9QhDvNaQVGqzA8tUFQ8XlftY,2894
7
+ gemcode/cli.py,sha256=7F6Rg-fJxnDWURjsuzGPo0_H_UPUhf0UXxTBwI0pVNM,21330
8
+ gemcode/compaction.py,sha256=QcvpA_ylEp5JPKMxEBYIlE9OkCCQ0Sk_dKzQjGzZ8xk,976
9
+ gemcode/config.py,sha256=cEquoxTtSqrco9-ON7c_wQM1mcECnChaq5lDfVsA-lQ,8482
10
+ gemcode/interactions.py,sha256=B0b3QNE_I2i5_HtiebX4ehhjlc4Nbqjf_XbvcTLyJT0,641
11
+ gemcode/invoke.py,sha256=H5c7j5OpakoHJtcSbGg3rewFzJk4_Stm2Uj1VrBgam4,4550
12
+ gemcode/kairos_daemon.py,sha256=giINipslAIhBtdbqA0o4RYwt4fBsZjtkiKDjp4zSEvw,6980
13
+ gemcode/limits.py,sha256=-we1UWK-E3-gNbubh0J4fQ7F3enllSDHE4rs5YW1qdU,2530
14
+ gemcode/live_audio_engine.py,sha256=Re1zS-9lcaK2qfU7ydPVQlI6tXxv384O6Bs1dhZ8Puo,3423
15
+ gemcode/mcp_loader.py,sha256=0QRgYvI71YNAyehO0N9SgK-9jhiocXHVo0J5HQ8MZHo,1344
16
+ gemcode/modality_tools.py,sha256=196Plk1lUgegPu-VeVoONkt3Zlxk5kXQnM8vlRFapn0,6261
17
+ gemcode/model_routing.py,sha256=Q42HZtXQa6rao2O2vYMHxohrTgD-wq4t7qGxU4_38Jg,4881
18
+ gemcode/paths.py,sha256=U6cEH9jfIcSc4NO8Ke0jniZSiJTfCIJPvSMue3hR0ZU,768
19
+ gemcode/permissions.py,sha256=9FmwTP_LLflahxS9KXvY3VPSra4e-h3OariOqnWIKDI,177
20
+ gemcode/prompt_suggestions.py,sha256=S1djH6GFi7ONQTEvXr-irxYjfdco6CEeIGUp7zn0OcE,2397
21
+ gemcode/session_runtime.py,sha256=Evqr6YNqB_O0V3omGjqD1ve_6kdpgwe7KFev9-WE_nA,3308
22
+ gemcode/thinking.py,sha256=lnp_rN0K2GMPY7Bjb5DwIGSjACial27rJdbHoI_zAW4,4377
23
+ gemcode/tool_prompt_manifest.py,sha256=KkwRG9hhwTpMILJvkVNaeERmCysrGNpbeHZLf36GTf0,4466
24
+ gemcode/tool_registry.py,sha256=Y7Xg8FKBVbanewnN9YGKvGeOZcOETb0TUx0SewWIUhw,1395
25
+ gemcode/tools_inspector.py,sha256=okmu4PDYAQQ7nthDvuzSHmy2zArFTG4ftIPRadzLnxA,4100
26
+ gemcode/trust.py,sha256=fxe57Xg6aL_KU24bQDUtD-rXjsNpaq7g-eQTInZnudE,1336
27
+ gemcode/vertex.py,sha256=Fy8zxuU8jWkObt0WDRI0XmgnjNznILXVLVwKjImNz9Q,643
28
+ gemcode/computer_use/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
+ gemcode/computer_use/browser_computer.py,sha256=Rrlu954siA_9rg4E5TVqIongefz_WRhZ2pG5o2_QuZ8,8307
30
+ gemcode/memory/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
31
+ gemcode/memory/embedding_memory_service.py,sha256=45mp4dDXMxdtafIq6LBPbFs5iij6lRnp4M9Zinvw9eY,8544
32
+ gemcode/memory/file_memory_service.py,sha256=LLe-aRnEzyZ9FYPb4z_czwkR8D16ACwhCspbUc_BSM4,4909
33
+ gemcode/plugins/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
+ gemcode/plugins/terminal_hooks_plugin.py,sha256=WVUxjPLqaOVXd0sRWvXMkEgPJTa-ZoBW0FjvFBzAd5w,5218
35
+ gemcode/plugins/tool_recovery_plugin.py,sha256=N3nMDMuthwGJNqpV3tjXLdCYjUl9Dlwf-xtzZ5QkqZA,3876
36
+ gemcode/query/__init__.py,sha256=b9uZ1g3vQ-EHzLizRWq_d-UQyZ4zZfgi5MLEapDIr24,1259
37
+ gemcode/query/config.py,sha256=a_vRwqSB3qWshvdHZ4Fh_-APCSm3hXk3KYGMjpaC5Y4,943
38
+ gemcode/query/deps.py,sha256=56WJJYc-DZqojRaQISiFfEULCPEhyfBzy7D5ODkpPP0,405
39
+ gemcode/query/engine.py,sha256=GPuvUgTRpWmyA39I_3ayVEADlHVFhPrC2FGW_yKs2yw,1420
40
+ gemcode/query/stop_hooks.py,sha256=jaXMN2OptwHeGXF8o630zIVr62T8jVg-eIyREG0GyxA,1847
41
+ gemcode/query/token_budget.py,sha256=JTq2TrGkFY5t5KOs-P9XQPqahyjcdTzN3wctZ1JxFV0,2973
42
+ gemcode/query/transitions.py,sha256=vJ77cv4cFwdvsxyGr7MxXz6uGVB5IDqOClqR1MkWvqw,933
43
+ gemcode/tools/__init__.py,sha256=vtaVEGPhfMmMxOlQWHcJOi3xmlQyXOtoq93OUa-r33A,715
44
+ gemcode/tools/edit.py,sha256=Q6ALUCHQV37n0j6XQd2luCaDm0fIavho3faDisOqtuU,1716
45
+ gemcode/tools/filesystem.py,sha256=z-OzP4HJQ0_KHBWgzXUbvHz91G-QoUjwJYgmoQdA0gk,2452
46
+ gemcode/tools/search.py,sha256=0SBmPJtjOiFbYB0T7mwKaVtAv_sVRSX8lAJ7ZNqiF8U,2328
47
+ gemcode/tools/shell.py,sha256=_ish9ndXMxcXQ5A1lTpTi3fwpk4dcdge2fZDJr-o400,2055
48
+ gemcode/tui/app.py,sha256=FZLcVcZtnbBstrlJRqYcS3worVSGdgiGtKoouLk8xJY,22084
49
+ gemcode/tui/scrollback.py,sha256=c8R898foH8Bq4IysxTMVSIFU6_u9vTSjLd3GwSh_aWA,8863
50
+ gemcode/web/__init__.py,sha256=EysmUAWs6g-lmMk4VFljKfaHVrEgb_FiIzwQmBdORJc,40
51
+ gemcode/web/claude_sse_adapter.py,sha256=HcNp0Lh4DdBZBLOpstsqa-VzfqAUrRngZ6FSuJ-mIMg,8609
52
+ gemcode/web/terminal_repl.py,sha256=k2irvFGbCY8gDm_pbirR7b_cakaeafcctoTIvnJkVXk,3902
53
+ gemcode-0.2.2.dist-info/licenses/LICENSE,sha256=TD4524qn-W8Z07GTDnag-9jJPFutFZNB0a1WbMHPC54,8388
54
+ gemcode-0.2.2.dist-info/METADATA,sha256=vb5_CJlSi9hdHs15eX-DvWXpgQiQA1jCemhnvTEvZ38,23746
55
+ gemcode-0.2.2.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
56
+ gemcode-0.2.2.dist-info/entry_points.txt,sha256=cZdLTLDiHbks7OSUCuxCh66dCWeQdpLR8BozoqfEjV4,45
57
+ gemcode-0.2.2.dist-info/top_level.txt,sha256=UYrjULLBY2bcgK6KI6flomJWmsbDXu7n0rvW2SWFrbo,8
58
+ gemcode-0.2.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ gemcode = gemcode.cli:main