@alexwkleung/reika 0.0.0-stage → 0.1.0

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 (140) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +4 -0
  3. package/README.md +150 -2
  4. package/README.zh-CN.md +150 -0
  5. package/dist/agent/attachments.js +63 -0
  6. package/dist/agent/compaction.js +862 -0
  7. package/dist/agent/compactionreport.js +64 -0
  8. package/dist/agent/continuation.js +153 -0
  9. package/dist/agent/decoderate.js +132 -0
  10. package/dist/agent/entropytrace.js +169 -0
  11. package/dist/agent/genreserve.js +75 -0
  12. package/dist/agent/groundcheck.js +195 -0
  13. package/dist/agent/logitrecovery.js +171 -0
  14. package/dist/agent/loop.js +3460 -0
  15. package/dist/agent/mentions.js +118 -0
  16. package/dist/agent/pastedurls.js +203 -0
  17. package/dist/agent/planpressure.js +87 -0
  18. package/dist/agent/plantrack.js +503 -0
  19. package/dist/agent/prefillcost.js +79 -0
  20. package/dist/agent/prefixtrace.js +90 -0
  21. package/dist/agent/prompt.js +346 -0
  22. package/dist/agent/readfirst.js +190 -0
  23. package/dist/agent/readtrace.js +181 -0
  24. package/dist/agent/reasoningtrace.js +242 -0
  25. package/dist/agent/subagentpressure.js +70 -0
  26. package/dist/agent/subagentreport.js +117 -0
  27. package/dist/agent/warm.js +163 -0
  28. package/dist/approval.js +53 -0
  29. package/dist/check/typecheck.js +208 -0
  30. package/dist/cli.js +64 -0
  31. package/dist/config.js +446 -0
  32. package/dist/context/bootstrap.js +120 -0
  33. package/dist/context/bundlesize.js +74 -0
  34. package/dist/context/files.js +67 -0
  35. package/dist/context/gitignore.js +102 -0
  36. package/dist/context/repomap.js +304 -0
  37. package/dist/debug.js +63 -0
  38. package/dist/headless.js +276 -0
  39. package/dist/headlessargs.js +86 -0
  40. package/dist/laststate.js +71 -0
  41. package/dist/limit.js +27 -0
  42. package/dist/mcp/client.js +538 -0
  43. package/dist/mcp/config.js +187 -0
  44. package/dist/mcp/manager.js +145 -0
  45. package/dist/mcp/tools.js +323 -0
  46. package/dist/ocr/select.js +29 -0
  47. package/dist/ocr/system.js +162 -0
  48. package/dist/ocr/types.js +1 -0
  49. package/dist/ocr/vision.js +139 -0
  50. package/dist/provider/budget.js +56 -0
  51. package/dist/provider/cachehints.js +30 -0
  52. package/dist/provider/client.js +545 -0
  53. package/dist/provider/contextwindow.js +78 -0
  54. package/dist/provider/dispatcher.js +126 -0
  55. package/dist/provider/latches.js +28 -0
  56. package/dist/provider/modellimits.js +155 -0
  57. package/dist/provider/tokens.js +32 -0
  58. package/dist/provider/toolcall.js +1067 -0
  59. package/dist/provider/transport.js +249 -0
  60. package/dist/search/_chrome.js +349 -0
  61. package/dist/search/cdp.js +218 -0
  62. package/dist/search/searxng.js +86 -0
  63. package/dist/search/types.js +17 -0
  64. package/dist/session.js +372 -0
  65. package/dist/skillmatch.js +143 -0
  66. package/dist/skills.js +269 -0
  67. package/dist/store/payloads.js +21 -0
  68. package/dist/store/sessions.js +142 -0
  69. package/dist/store/transcript.js +353 -0
  70. package/dist/tools/_danger.js +1053 -0
  71. package/dist/tools/_deps.js +203 -0
  72. package/dist/tools/_diff.js +64 -0
  73. package/dist/tools/_exfil.js +168 -0
  74. package/dist/tools/_hosts.js +224 -0
  75. package/dist/tools/_markdown.js +380 -0
  76. package/dist/tools/_net.js +65 -0
  77. package/dist/tools/_paths.js +68 -0
  78. package/dist/tools/_readonly.js +402 -0
  79. package/dist/tools/_sandbox.js +551 -0
  80. package/dist/tools/_spill.js +216 -0
  81. package/dist/tools/_spillstats.js +45 -0
  82. package/dist/tools/_treediff.js +305 -0
  83. package/dist/tools/_urls.js +335 -0
  84. package/dist/tools/_walk.js +24 -0
  85. package/dist/tools/_writetargets.js +144 -0
  86. package/dist/tools/ask.js +194 -0
  87. package/dist/tools/bash.js +634 -0
  88. package/dist/tools/edit.js +426 -0
  89. package/dist/tools/fetch.js +415 -0
  90. package/dist/tools/glob.js +142 -0
  91. package/dist/tools/grep.js +263 -0
  92. package/dist/tools/index.js +171 -0
  93. package/dist/tools/list.js +96 -0
  94. package/dist/tools/read.js +74 -0
  95. package/dist/tools/search.js +134 -0
  96. package/dist/tools/subagent.js +23 -0
  97. package/dist/tools/write.js +92 -0
  98. package/dist/types.js +1 -0
  99. package/dist/ui/App.js +2518 -0
  100. package/dist/ui/Approval.js +91 -0
  101. package/dist/ui/Confirm.js +77 -0
  102. package/dist/ui/DiffView.js +391 -0
  103. package/dist/ui/Input.js +461 -0
  104. package/dist/ui/ModelSelect.js +32 -0
  105. package/dist/ui/PlanProgress.js +50 -0
  106. package/dist/ui/Question.js +105 -0
  107. package/dist/ui/QueuedList.js +17 -0
  108. package/dist/ui/ResumeSelect.js +54 -0
  109. package/dist/ui/Scrollback.js +688 -0
  110. package/dist/ui/Splash.js +42 -0
  111. package/dist/ui/Status.js +182 -0
  112. package/dist/ui/Suggestions.js +50 -0
  113. package/dist/ui/Working.js +242 -0
  114. package/dist/ui/clipboard.js +77 -0
  115. package/dist/ui/commands.js +159 -0
  116. package/dist/ui/focus.js +56 -0
  117. package/dist/ui/format.js +180 -0
  118. package/dist/ui/glyphs.js +48 -0
  119. package/dist/ui/highlight.js +191 -0
  120. package/dist/ui/identity.js +211 -0
  121. package/dist/ui/layout.js +81 -0
  122. package/dist/ui/markdown.js +356 -0
  123. package/dist/ui/models.js +32 -0
  124. package/dist/ui/pastes.js +59 -0
  125. package/dist/ui/paths.js +19 -0
  126. package/dist/ui/pr.js +72 -0
  127. package/dist/ui/queue.js +25 -0
  128. package/dist/ui/reasoningfold.js +56 -0
  129. package/dist/ui/redact.js +51 -0
  130. package/dist/ui/scrub.js +49 -0
  131. package/dist/ui/suggest.js +92 -0
  132. package/dist/ui/summary.js +59 -0
  133. package/dist/ui/syncframe.js +92 -0
  134. package/dist/ui/termtext.js +113 -0
  135. package/dist/ui/theme.js +95 -0
  136. package/dist/ui/warmtrigger.js +37 -0
  137. package/dist/version.js +27 -0
  138. package/package.json +104 -3
  139. package/skills/issue.md +41 -0
  140. package/skills/review.md +122 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ Reika
2
+ Copyright 2026 Alex Leung
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (see LICENSE).
package/README.md CHANGED
@@ -1,3 +1,151 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="docs/assets/reika-dark.svg">
4
+ <img alt="Reika" src="docs/assets/reika-light.svg" width="262">
5
+ </picture>
6
+ </p>
2
7
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
8
+ <p align="center">
9
+ A coding agent CLI for local and hosted models,<br>
10
+ designed around small local models first.
11
+ </p>
12
+
13
+ <p align="center">
14
+ <a href="https://reikacode.com">Website</a> ·
15
+ <a href="#quick-start">Quick start</a> ·
16
+ <a href="#documentation">Docs</a> ·
17
+ <a href="docs/models.md">Tested models</a> ·
18
+ <a href="README.zh-CN.md">简体中文</a>
19
+ </p>
20
+
21
+ ![Reika fixing a retry helper and its test with a local model](docs/demo.gif)
22
+
23
+ <sup>A real local run of Qwen3.6 35B A3B (Unsloth UD-IQ2_M) via llama.cpp, sped up 3×. The model's first test fails and it fixes it from the error.</sup>
24
+
25
+ Reika is a coding agent CLI for local and hosted models. It was designed around small local models first (8B–35B, often at Q2–Q4, on a 16–32k context window), so it is careful with context, fails more gracefully, and says when it's stuck. It doesn't make a small model smarter. It makes working with one less frustrating: less of the window wasted, fewer loops on the same read, and less chance of the task quietly getting lost.
26
+
27
+ Day to day it runs on large hosted models, and small local ones are where it gets tested. At the small end, expect a better experience rather than frontier results. In testing, 14–35B models handled multi-file tasks most reliably, 8–9B models managed simple, well-scoped ones, and below 7B rarely got far.
28
+
29
+ Reika is pre-1.0, so commands, settings and behavior can still change between releases.
30
+
31
+ ## What the measurements say
32
+
33
+ The harness's design choices were measured rather than assumed, and the record is published. It measures what a harness can and can't do about the problems small models run into, not how good the models become. The short version, with the runs and the numbers behind it in [docs/findings.md](docs/findings.md):
34
+
35
+ - **The harness's own context management cost more than the model did.** One mid-context rewrite re-processed 8,453 tokens of prompt — 7.9 minutes of prefill — where an append in the same session cost 25 tokens and 3.5 seconds.
36
+ - **Ask the model for its findings before a fold drops them.** In the A/B behind this, the arm whose findings were dropped folded five times, re-read files it had already read, and never answered; the arm that was asked answered from the digest.
37
+ - **A small model takes tool output literally.** A grep that said "0 matches" for a call it couldn't serve sent a model rewording a correct pattern for five rounds; a loop blamed on a 35B at Q2 was reika feeding the model its own tool-call markup back.
38
+ - **Prompt wording is the weakest lever.** On a vague task at Q2 a model converges or spirals about 50/50, and the harness cannot move that rate — only what the failing half costs.
39
+ - **The loop detectors separate cleanly.** Healthy reasoning rounds measure 0.2–0.3 on cross-round similarity; locked loops sit at 1.00, and a 38-round productive turn never fired the detector.
40
+
41
+ ## Highlights
42
+
43
+ - **Context discipline.** Old tool output collapses to one-line summaries, requests stay append-only between shrink events so the engine's prompt cache survives, and when the window fills the model writes its own findings note before older turns fold into a recap.
44
+ - **Loop and spiral breaking.** Repeated reads, re-derived reasoning, and runaway thinking blocks are detected and answered with an escalating ladder (nudge, pinned ledger, tool withdrawal, honest stop) rather than a 30-minute spiral.
45
+ - **Checks on what the model does.** Blind edits are bounced to a read first, TypeScript edits are typechecked against a pre-edit baseline, and a written plan is tracked step by step from what the harness observes, not what the model claims.
46
+ - **Plan → implement.** A read-only plan mode that ends in a numbered, file-specific plan — refine it over as many turns as you like before executing — and a vibe mode that chains plan and implementation on every prompt.
47
+ - **Safe by default.** Ordinary edits run, dangerous commands still prompt, and on macOS model-chosen shell commands run under a kernel sandbox (writes confined to the project, network denied).
48
+ - **Extensible.** Stdio MCP servers add tools, and each tool also becomes a slash command. Markdown skills become slash commands too; `/issue` and `/review` ship with Reika and appear wherever `gh` and a GitHub remote are.
49
+ - **No telemetry.** Your code goes to the model server you configure and nowhere else: with a local server it never leaves your machine, and with a cloud API it goes to that provider. The only other requests are the web tools, when a web tool is used or you paste a link, a download of the public models.dev catalog to look up context limits (only for hosted endpoints, and never with your data), and whatever the MCP servers you configure do on their own.
50
+ - **Built for slow local engines.** Tolerates long prefills, handles tool-call dialects from models without a native template, and shows decode speed, context fill, and cache hit rate in the status bar.
51
+
52
+ ## Requirements
53
+
54
+ - Node.js 22 or newer (macOS 11+ or glibc 2.28+ Linux — see [Platforms](docs/platforms.md)).
55
+ - An OpenAI-compatible model server: llama.cpp, MLX, vLLM, or a cloud API.
56
+ - macOS is the primary platform. Linux works, but without the shell sandbox or image-paste OCR (set `REIKA_VISION_MODEL` to read pasted images with a vision model instead). Windows may work under WSL2.
57
+ - A modern terminal (iTerm2, Ghostty, Kitty, etc). Recommended for proper TUI rendering.
58
+
59
+ ## Quick start
60
+
61
+ Install it with any of these (npm and pnpm need Node ≥ 22; Homebrew pulls Node in):
62
+
63
+ ```sh
64
+ npm i -g @alexwkleung/reika
65
+ pnpm add -g @alexwkleung/reika
66
+ brew install alexwkleung/tap/reika
67
+ ```
68
+
69
+ Serve a model. Example below with llama.cpp:
70
+
71
+ ```sh
72
+ llama-server -m <model.gguf> -c 24576 --jinja <other-launch-args>
73
+ ```
74
+
75
+ Then point Reika at it:
76
+
77
+ ```sh
78
+ export REIKA_MODEL=model # or put it in ~/.config/reika/.env
79
+ cd your-project && reika
80
+ ```
81
+
82
+ Using a hosted API instead? Skip the server and set `REIKA_BASE_URL`, `REIKA_API_KEY` and `REIKA_MODEL` to the provider's endpoint, your key and its model id; [Install and first run](docs/getting-started.md#hosted) has the details.
83
+
84
+ `REIKA_BASE_URL` defaults to `http://localhost:8080/v1`, llama-server's default. The context window is read from the server when it reports one, and for hosted endpoints from the models.dev catalog; set `REIKA_CONTEXT_WINDOW` when neither has it. Reika sends no sampling parameters of its own, so your server's flags are what apply.
85
+
86
+ To run from a checkout instead — `git clone https://github.com/alexwkleung/reika.git && cd reika`, then `pnpm install` (npm users: `npm i -g pnpm`) and `pnpm run install:global` to build and install the `reika` binary, or `cp .env.example .env` and `pnpm run dev` to run without installing. `pnpm run uninstall:global` removes the global binary.
87
+
88
+ ## Common configuration
89
+
90
+ Set these in your shell, a project `.env`, or `~/.config/reika/.env` (in that order of precedence). The full list, experimental flags, and multi-model profiles are in [docs/configuration.md](docs/configuration.md).
91
+
92
+ | Key | Default | What |
93
+ | ---------------------- | -------------------------- | ------------------------------------------------------------------------------------- |
94
+ | `REIKA_MODEL` | _required_ | Model name, or a comma-separated list served by the same endpoint |
95
+ | `REIKA_BASE_URL` | `http://localhost:8080/v1` | OpenAI-compatible endpoint |
96
+ | `REIKA_API_KEY` | `no-key` | API key (any non-empty value for local servers) |
97
+ | `REIKA_CONTEXT_WINDOW` | _probed from the server_ | Context window in tokens; drives compaction, the context gauge, and the repo map size |
98
+ | `REIKA_MIN_GEN_TOKENS` | _learned_ (from `2048`) | Room reserved for the reply; learned from the model's rounds, set it to pin |
99
+ | `REIKA_AUTO_APPROVE` | `safe` | `off` confirms every edit and command; `bypass` confirms nothing |
100
+
101
+ ## Modes
102
+
103
+ `Shift+Tab` cycles modes, or switch with a slash command. The mode and model you end a session in are the ones the next session opens in.
104
+
105
+ | Mode | What it does |
106
+ | --------- | ---------------------------------------------------------------------------- |
107
+ | `agent` | The default: the model reads, edits, and runs commands |
108
+ | `plan` | Read-only exploration that ends in a written plan; `/implement` runs it |
109
+ | `vibe` | Plans first, then implements the plan, on every prompt |
110
+ | `minimal` | Shell only, with no repo map or project context loaded upfront |
111
+ | `grind` | Agent turns run a fixed, careful procedure: define done, test, review |
112
+ | `chat` | Plain conversation with a separate history; web tools only |
113
+ | `shell` | Your input runs as a shell command, and the output joins the agent's context |
114
+
115
+ `reika -p "<prompt>"` runs a single turn headless and prints the reply, for scripts and other harnesses. See [docs/usage.md](docs/usage.md) for modes in detail, headless flags, and every slash command.
116
+
117
+ ## Safety
118
+
119
+ - **Approvals** default to `safe`: ordinary edits and commands run on their own, but anything matching a dangerous pattern (`rm -rf`, force pushes, package installs, `curl`, …) and any write outside the project still asks you first. `bypass` can only be set at launch, never mid-session.
120
+ - **Sandbox** (macOS, on by default): model-chosen shell commands can write only inside the project, temp, and cache directories, and have no network apart from loopback and read-only `git`/`gh`. A command you explicitly approve runs unsandboxed. `REIKA_SANDBOX=0` turns it off.
121
+
122
+ Found a way around one of these? Report it privately; see [SECURITY.md](SECURITY.md).
123
+
124
+ ## Documentation
125
+
126
+ The same pages are on the website, [reikacode.com](https://reikacode.com).
127
+
128
+ | Doc | Covers |
129
+ | ------------------------------------------------ | ----------------------------------------------------------------------------------------- |
130
+ | [Install and first run](docs/getting-started.md) | Requirements, installing, serving a model, and the first run |
131
+ | [Configuration](docs/configuration.md) | Every `.env` key, experimental flags, named profiles, last-session state |
132
+ | [Modes, headless, commands](docs/usage.md) | Each mode in depth, `reika -p`, slash commands, `/save` transcripts |
133
+ | [Tools](docs/tools.md) | The model's tools, approval prompts, web search setup, MCP servers, `.gitignore` |
134
+ | [Instructions and skills](docs/skills.md) | `AGENTS.md`, skills as slash commands, plain-English routing, pasted URLs |
135
+ | [Tested models](docs/models.md) | Local quants and APIs Reika has been run against |
136
+ | [Findings](docs/findings.md) | The measured record: what broke, what held, and how each number was obtained |
137
+ | [Platforms](docs/platforms.md) | Requirements, running on a weak machine, what differs on Linux and Windows |
138
+ | [Architecture and caveats](docs/architecture.md) | How the harness works, and known limitations |
139
+ | [Contributing](CONTRIBUTING.md) | Scripts, design philosophy, a pointer to `AGENTS.md`, and external contributor guidelines |
140
+
141
+ ## Inspired by
142
+
143
+ Claude Code, Codex, Crush, OpenCode, Pi, Aider, DeepSeek Harness, Qwen Code, Kimi Code CLI, Gemini CLI, Junie, and DS4.
144
+
145
+ ## License
146
+
147
+ Apache License 2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
148
+
149
+ ## Supporting our work
150
+
151
+ If Reika is useful to you, consider supporting it via [GitHub Sponsors](https://github.com/sponsors/alexwkleung), [Ko-fi](https://ko-fi.com/alexwkleung), or [Buy Me a Coffee](https://buymeacoffee.com/alexwkleung). See [Support](docs/support.md) for what it funds and other ways to help.
@@ -0,0 +1,150 @@
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="docs/assets/reika-dark.svg">
4
+ <img alt="Reika" src="docs/assets/reika-light.svg" width="262">
5
+ </picture>
6
+ </p>
7
+
8
+ <p align="center">
9
+ 适用于本地与托管模型的编码代理 CLI,<br>
10
+ 首先围绕小型本地模型设计。
11
+ </p>
12
+
13
+ <p align="center">
14
+ <a href="https://reikacode.com">网站</a> ·
15
+ <a href="#快速开始">快速开始</a> ·
16
+ <a href="#文档">文档</a> ·
17
+ <a href="docs/models.md">测试过的模型</a> ·
18
+ <a href="README.md">English</a>
19
+ </p>
20
+
21
+ ![Reika 用本地模型修复一个重试辅助函数及其测试](docs/demo.gif)
22
+
23
+ <sup>一次真实的本地运行:Qwen3.6 35B A3B(Unsloth UD-IQ2_M)经 llama.cpp,加速 3×。模型的第一次测试失败,它根据报错修好了。</sup>
24
+
25
+ Reika 是一个适用于本地与托管模型的编码代理 CLI。它首先围绕小型本地模型设计(8B–35B,通常处于 Q2–Q4,16–32k 上下文窗口),因此对上下文很节制,失败时更体面,卡住时会直说。它不会让小模型变得更聪明,只是让使用小模型的体验少一些挫败:浪费的窗口更少,在同一个读取上打转更少,任务也更不容易被悄悄弄丢。
26
+
27
+ 日常使用跑在大型托管模型上,小型本地模型是测试它的地方。在小模型这一端,能期待的是更好的体验,而不是前沿模型的效果。测试中,14–35B 模型处理多文件任务最可靠,8–9B 模型能完成简单、范围明确的任务,7B 以下很少能走远。
28
+
29
+ Reika 还处于 1.0 之前,命令、设置和行为在不同版本之间仍可能变化。
30
+
31
+ ## 测量结果
32
+
33
+ 框架的设计取舍是测量出来的,而不是假设的,记录也都公开。测量的是框架对小模型遇到的问题能做什么、不能做什么,而不是模型会变得多好。简短版本如下,完整的运行记录与数字见 [docs/findings.md](docs/findings.md):
34
+
35
+ - **框架自己的上下文管理,代价比模型本身更大。** 一次发生在上下文中段的改写重新预填充了 8,453 个 token —— 7.9 分钟;而同一会话里的一次追加只花 25 个 token、3.5 秒。
36
+ - **折叠之前先向模型要它的发现。** 支撑这一点的 A/B 中,发现被丢弃的那一臂折叠了五次,反复重读已经读过的文件,始终没有作答;被问过的那一臂直接从笔记里给出了答案。
37
+ - **小模型会照字面理解工具输出。** grep 对一个它根本无法执行的调用也回答"0 matches",结果模型花了五轮去改写一个本来正确的模式;一个被归咎于 Q2 下 35B 模型的循环,其实是 Reika 把模型自己的工具调用标记又喂了回去。
38
+ - **提示词措辞是最弱的杠杆。** 在 Q2 下面对含糊任务,模型收敛与打转大约各占一半,框架改变不了这个比例 —— 只能改变失败那一半的代价。
39
+ - **循环检测器的区分度很干净。** 健康的推理轮次在跨轮相似度上测得 0.2–0.3;锁死的循环停在 1.00,而一个跑了 38 轮的有效轮次从未触发检测。
40
+
41
+ ## 亮点
42
+
43
+ - **上下文纪律。** 旧的工具输出折叠成一行摘要;在两次压缩事件之间请求保持只追加,让引擎的 prompt 缓存得以存活;窗口填满时,模型先写下自己的发现笔记,之后较早的轮次才折叠成回顾。
44
+ - **循环与打转中断。** 重复读取、反复重推的推理、以及失控的思考块都会被检测到,并用一套逐级升级的手段回应(轻推、固定台账、收回工具、坦诚终止),而不是让它打转半小时。
45
+ - **对模型行为的检查。** 盲改会被退回,要求先读;TypeScript 编辑会对照编辑前的基线做类型检查;写下的计划按框架观察到的事实逐步追踪,而不是按模型自己声称的进度。
46
+ - **计划 → 实现。** 只读的计划模式最终产出一份带编号、落到具体文件的计划 —— 你可以在执行之前用任意多轮来打磨它 —— 而 vibe 模式会在每次提示时把计划和实现串起来。
47
+ - **默认安全。** 普通编辑直接执行,危险命令仍会询问;在 macOS 上,由模型选择的 shell 命令运行在内核沙箱里(写入限制在项目内,网络被禁止)。
48
+ - **可扩展。** Stdio MCP 服务器可以添加工具,每个工具同时也会变成一个斜杠命令。Markdown 技能同样会变成斜杠命令;`/issue` 和 `/review` 随 Reika 一起发布,只要有 `gh` 和 GitHub 远程仓库就会出现。
49
+ - **无遥测。** 你的代码只会发往你自己配置的模型服务器,别处不去:用本地服务器时它从不离开你的机器,用云端 API 时它只发给该提供商。除此之外的请求只有:使用网络工具或粘贴链接时发起的请求;为查询上下文上限而下载公开的 models.dev 目录(仅针对托管端点,且从不携带你的数据);以及你配置的 MCP 服务器各自的行为。
50
+ - **为慢速本地引擎而做。** 容忍长预填充,能处理没有原生模板的模型发出的工具调用方言,并在状态栏显示解码速度、上下文占用和缓存命中率。
51
+
52
+ ## 要求
53
+
54
+ - Node.js 22 或更新版本(macOS 11+,或 glibc 2.28+ 的 Linux —— 见[平台](docs/platforms.md))。
55
+ - 一个 OpenAI 兼容的模型服务器:llama.cpp、MLX、vLLM 或云端 API。
56
+ - macOS 是主要平台。Linux 可用,但没有 shell 沙箱和图片粘贴 OCR(可以设置 `REIKA_VISION_MODEL`,改用视觉模型读取粘贴的图片)。Windows 或许能在 WSL2 下运行。
57
+ - 现代终端(iTerm2、Ghostty、Kitty 等)。想要正确的 TUI 渲染,建议使用它们。
58
+
59
+ ## 快速开始
60
+
61
+ 用以下任一方式安装(npm 和 pnpm 需要 Node ≥ 22;Homebrew 会自动装好 Node):
62
+
63
+ ```sh
64
+ npm i -g @alexwkleung/reika
65
+ pnpm add -g @alexwkleung/reika
66
+ brew install alexwkleung/tap/reika
67
+ ```
68
+
69
+ 启动一个模型。下面以 llama.cpp 为例:
70
+
71
+ ```sh
72
+ llama-server -m <model.gguf> -c 24576 --jinja <other-launch-args>
73
+ ```
74
+
75
+ 然后把 Reika 指向它:
76
+
77
+ ```sh
78
+ export REIKA_MODEL=model # 或写进 ~/.config/reika/.env
79
+ cd your-project && reika
80
+ ```
81
+
82
+ 改用托管 API?跳过启动服务器这一步,把 `REIKA_BASE_URL`、`REIKA_API_KEY` 和 `REIKA_MODEL` 设为服务商的端点、你的密钥和它的模型 ID;详见 [安装与首次运行](docs/getting-started.md#hosted)。
83
+
84
+ `REIKA_BASE_URL` 默认是 `http://localhost:8080/v1`,即 llama-server 的默认地址。上下文窗口在服务器上报时从中读取,托管端点则从 models.dev 目录中读取;两者都没有时,请设置 `REIKA_CONTEXT_WINDOW`。Reika 不发送任何自己的采样参数,所以生效的就是你服务器的启动参数。
85
+
86
+ 想改从检出目录运行:`git clone https://github.com/alexwkleung/reika.git && cd reika`,然后 `pnpm install`(npm 用户先 `npm i -g pnpm`)并用 `pnpm run install:global` 构建安装 `reika` 可执行文件;或者 `cp .env.example .env`、编辑它,再 `pnpm run dev` 直接运行而不安装。`pnpm run uninstall:global` 会移除全局可执行文件。
87
+
88
+ ## 常用配置
89
+
90
+ 这些可以设在你的 shell、项目 `.env` 或 `~/.config/reika/.env` 中(优先级即此顺序)。完整列表、实验性开关和多模型 profile 见[配置文档](docs/configuration.md)。
91
+
92
+ | 键 | 默认值 | 说明 |
93
+ | ---------------------- | --------------------------- | ------------------------------------------------------ |
94
+ | `REIKA_MODEL` | _必填_ | 模型名称,或同一端点提供的逗号分隔列表 |
95
+ | `REIKA_BASE_URL` | `http://localhost:8080/v1` | OpenAI 兼容端点 |
96
+ | `REIKA_API_KEY` | `no-key` | API 密钥(本地服务器填任意非空值) |
97
+ | `REIKA_CONTEXT_WINDOW` | _从服务器探测_ | 上下文窗口 token 数;驱动压缩和上下文占用条 |
98
+ | `REIKA_MIN_GEN_TOKENS` | _学习得到_(起始为 `2048`) | 为回复预留的空间;从模型的轮次中学习,设置它即固定该值 |
99
+ | `REIKA_AUTO_APPROVE` | `safe` | `off` 让每次编辑和命令都需确认;`bypass` 什么都不确认 |
100
+
101
+ ## 模式
102
+
103
+ `Shift+Tab` 循环切换模式,也可以用斜杠命令切换。你结束会话时所处的模式和模型,就是下次会话打开时的模式和模型。
104
+
105
+ | 模式 | 作用 |
106
+ | --------- | -------------------------------------------------------- |
107
+ | `agent` | 默认模式:模型读取、编辑并运行命令 |
108
+ | `plan` | 只读探索,最终产出一份写好的计划;`/implement` 执行它 |
109
+ | `vibe` | 每次提示都先规划,再实现该计划 |
110
+ | `minimal` | 仅 shell,不预先加载仓库地图和项目上下文 |
111
+ | `grind` | 代理轮次按固定而谨慎的流程运行:定义完成标准、测试、复查 |
112
+ | `chat` | 与主历史分开的纯对话;只有网络工具 |
113
+ | `shell` | 你的输入作为 shell 命令运行,输出并入代理的上下文 |
114
+
115
+ `reika -p "<prompt>"` 无头运行单个轮次并打印回复,用于脚本和其他框架。模式细节、无头参数以及全部斜杠命令见[用法文档](docs/usage.md)。
116
+
117
+ ## 安全
118
+
119
+ - **审批**默认是 `safe`:普通编辑和命令自行执行,但任何匹配危险模式的命令(`rm -rf`、强制推送、安装软件包、`curl`……)以及项目之外的任何写入,仍会先问你。`bypass` 只能在启动时设置,会话中无法切换。
120
+ - **沙箱**(macOS,默认开启):由模型选择的 shell 命令只能写入项目、临时和缓存目录内,且除回环地址和只读的 `git`/`gh` 之外没有网络。你明确批准的命令不做沙箱隔离运行。`REIKA_SANDBOX=0` 可将其关闭。
121
+
122
+ 发现了绕过其中某一道的方式?请私下报告,见 [SECURITY.md](SECURITY.md)。
123
+
124
+ ## 文档
125
+
126
+ 这些页面也在网站 [reikacode.com](https://reikacode.com) 上(英文)。
127
+
128
+ | 文档 | 内容 |
129
+ | -------------------------------------- | ---------------------------------------------------------------- |
130
+ | [配置](docs/configuration.md) | 每一个 `.env` 键、实验性开关、具名 profile、上次会话状态 |
131
+ | [模式、无头与命令](docs/usage.md) | 各模式详解、`reika -p`、斜杠命令、`/save` 会话记录 |
132
+ | [工具](docs/tools.md) | 模型可用的工具、审批提示、网络搜索设置、MCP 服务器、`.gitignore` |
133
+ | [指令与技能](docs/skills.md) | `AGENTS.md`、作为斜杠命令的技能、自然语言路由、粘贴的链接 |
134
+ | [测试过的模型](docs/models.md) | Reika 实际跑过的本地量化版本和 API |
135
+ | [测量结果](docs/findings.md) | 实测记录:什么坏了、什么撑住了,以及每个数字是怎么得到的 |
136
+ | [平台](docs/platforms.md) | 运行要求、在弱机器上运行、Linux 和 Windows 上的差异 |
137
+ | [架构与注意事项](docs/architecture.md) | 框架如何工作,以及已知限制 |
138
+ | [贡献](CONTRIBUTING.md) | 脚本、设计理念、`AGENTS.md` 指引,以及外部贡献者指南 |
139
+
140
+ ## 灵感来自
141
+
142
+ Claude Code、Codex、Crush、OpenCode、Pi、Aider、DeepSeek Harness、Qwen Code、Kimi Code CLI、Gemini CLI、Junie 和 DS4。
143
+
144
+ ## 许可
145
+
146
+ Apache License 2.0。见 [LICENSE](LICENSE) 和 [NOTICE](NOTICE)。
147
+
148
+ ## 支持我们的工作
149
+
150
+ 如果 Reika 对你有用,可以考虑通过 [GitHub Sponsors](https://github.com/sponsors/alexwkleung)、[Ko-fi](https://ko-fi.com/alexwkleung) 或 [Buy Me a Coffee](https://buymeacoffee.com/alexwkleung) 支持这个项目。
@@ -0,0 +1,63 @@
1
+ // Pasted-image attachments. A clipboard image is OCR'd the moment it's pasted and parked here
2
+ // keyed by a short marker (`[Image 1]`) that goes into the input buffer in its place — the user
3
+ // sees a token they can move or delete, not a wall of extracted text, and the marker survives
4
+ // into the scrollback bubble as a readable record of what was attached.
5
+ // Extracted text is capped well below the mention cap (50k): a dense screenshot can OCR into
6
+ // thousands of characters, and this tool's whole premise is that context is scarce.
7
+ export const MAX_IMAGE_TEXT = 20_000;
8
+ // Under a native-vision profile (`VisionRoute`) the bytes are never read: they go to the model as
9
+ // an image part for the turn that attached them, and this note takes the description's place in
10
+ // history. Written to be true *after* the fact — by the time the model reads it again the image is
11
+ // long gone, and the honest thing to say is that it can no longer look.
12
+ export const NATIVE_IMAGE_NOTE = '(not transcribed — you were shown this image directly, once. ' +
13
+ 'Ask for a re-paste if you need to look at it again.)';
14
+ const MARKER_RE = /\[Image (\d+)\]/g;
15
+ export function nextImageMarker(existing) {
16
+ const used = existing.map(a => Number(/\d+/.exec(a.marker)?.[0] ?? 0));
17
+ return `[Image ${Math.max(0, ...used) + 1}]`;
18
+ }
19
+ // The model-facing form of extracted text. Mirrors the <file> block expandMentions emits, so
20
+ // an image reads as one more attached artifact rather than a new concept to learn.
21
+ export function imageBlock(attrs, text) {
22
+ const rendered = Object.entries(attrs)
23
+ .map(([k, v]) => ` ${k}="${v.replace(/"/g, '&quot;')}"`)
24
+ .join('');
25
+ return `<image${rendered}>\n${truncateImageText(text)}\n</image>`;
26
+ }
27
+ export function truncateImageText(text) {
28
+ if (text.length <= MAX_IMAGE_TEXT)
29
+ return text;
30
+ return (text.slice(0, MAX_IMAGE_TEXT) + `\n…(truncated, ${text.length - MAX_IMAGE_TEXT} more chars)`);
31
+ }
32
+ // Prepend a block for every attachment still referenced in the text. An attachment whose marker
33
+ // the user deleted while editing is dropped: the marker is the user's handle on the attachment,
34
+ // so removing it has to mean "don't send this".
35
+ export function attachImageBlocks(input, attachments) {
36
+ const live = attachments.filter(a => input.includes(a.marker));
37
+ if (live.length === 0)
38
+ return input;
39
+ const blocks = live.map(a => imageBlock({ id: /\d+/.exec(a.marker)?.[0] ?? '1', source: a.source }, a.text));
40
+ return `${blocks.join('\n\n')}\n\n${input}`;
41
+ }
42
+ // A native attachment's route is chosen at paste time, but the turn that sends it can run on a
43
+ // profile that cannot see — a /model switch in between, or a queued message replayed after one.
44
+ // Its bytes would then reach a text-only model, and history would hold only NATIVE_IMAGE_NOTE. So
45
+ // the sending turn reads them first, the way the describe route would have at paste time.
46
+ export async function readNativeAttachments(attachments, ocr) {
47
+ const failed = [];
48
+ const read = await Promise.all(attachments.map(async (a) => {
49
+ if (!a.native)
50
+ return a;
51
+ const result = await ocr(a.native.bytes);
52
+ if (result.ok)
53
+ return { marker: a.marker, text: result.text, source: a.source };
54
+ failed.push(a.marker);
55
+ return { marker: a.marker, text: '(image could not be read)', source: a.source };
56
+ }));
57
+ return { attachments: read, failed };
58
+ }
59
+ // Whether any marker at all is present — lets the caller skip the work when nothing was pasted.
60
+ export function hasImageMarker(input) {
61
+ MARKER_RE.lastIndex = 0;
62
+ return MARKER_RE.test(input);
63
+ }