@takara-ai/miru-code 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 (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +176 -0
  3. package/bin/miru.cjs +41 -0
  4. package/package.json +72 -0
  5. package/src/agents/claude.md +41 -0
  6. package/src/agents/copilot.md +41 -0
  7. package/src/agents/cursor.md +40 -0
  8. package/src/agents/gemini.md +43 -0
  9. package/src/agents/kiro.md +43 -0
  10. package/src/agents/opencode.md +44 -0
  11. package/src/agents.ts +30 -0
  12. package/src/cache.ts +141 -0
  13. package/src/chunking/chunking.ts +36 -0
  14. package/src/chunking/lines.ts +79 -0
  15. package/src/chunking/structural.ts +244 -0
  16. package/src/cli.ts +245 -0
  17. package/src/concurrency.ts +58 -0
  18. package/src/embeddings/openai.ts +442 -0
  19. package/src/env-files.ts +44 -0
  20. package/src/env.ts +50 -0
  21. package/src/git.ts +52 -0
  22. package/src/index/bm25-types.ts +18 -0
  23. package/src/index/bm25-worker.ts +48 -0
  24. package/src/index/bm25.ts +238 -0
  25. package/src/index/create.ts +195 -0
  26. package/src/index/dense.ts +105 -0
  27. package/src/index/file-walker.ts +113 -0
  28. package/src/index/files.ts +126 -0
  29. package/src/index/persistence.ts +100 -0
  30. package/src/index/quantize.ts +168 -0
  31. package/src/index/semantic-index.ts +11 -0
  32. package/src/index/sparse.ts +25 -0
  33. package/src/index/topk.ts +52 -0
  34. package/src/index/vector-storage.ts +27 -0
  35. package/src/index.ts +3 -0
  36. package/src/mcp/index-cache.ts +95 -0
  37. package/src/mcp/serve.ts +24 -0
  38. package/src/mcp/server.ts +100 -0
  39. package/src/miru-index.ts +269 -0
  40. package/src/ranking/boosting.ts +329 -0
  41. package/src/ranking/penalties.ts +110 -0
  42. package/src/ranking/weighting.ts +11 -0
  43. package/src/search.ts +180 -0
  44. package/src/tokens.ts +27 -0
  45. package/src/types.ts +47 -0
  46. package/src/utils.ts +64 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Takara
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.
package/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # Miru (見る)
2
+
3
+ Hybrid code search for AI agents — **TypeScript**, **Bun**, and **Takara embeddings**.
4
+
5
+ *Miru* means “to see” or “to look” in Japanese — semantic search that helps agents find code by meaning.
6
+
7
+ Indexes a local directory, combines semantic search with BM25, RRF fusion, and code-tuned reranking.
8
+
9
+ ## Install
10
+
11
+ Miru ships **Bun as a dependency** so `miru` uses a compatible runtime after install. You still need [Node.js](https://nodejs.org) on your PATH for the install step (Bun’s `postinstall`); do not use `--ignore-scripts`.
12
+
13
+ ```bash
14
+ # Run once without installing
15
+ bunx @takara-ai/miru-code search "auth middleware" ./src
16
+
17
+ # Global CLI (npm or bun)
18
+ bun add -g @takara-ai/miru-code
19
+ # or: npm install -g @takara-ai/miru-code
20
+ miru search "auth middleware" ./src
21
+
22
+ # Library
23
+ bun add @takara-ai/miru-code
24
+ ```
25
+
26
+ ```ts
27
+ import { MiruIndex } from "@takara-ai/miru-code";
28
+
29
+ const index = await MiruIndex.fromPath("./src");
30
+ ```
31
+
32
+ ## Setup
33
+
34
+ ```bash
35
+ bun install
36
+ ```
37
+
38
+ Add credentials to `.env.local` (loaded automatically when you run from this repo), or pass them in your MCP config `env` block (recommended for Cursor — MCP does not inherit IDE env vars reliably).
39
+
40
+ | Variable | Default |
41
+ |----------|---------|
42
+ | `TAKARA_API_KEY` / `OPENAI_API_KEY` / `MIRU_OPENAI_API_KEY` | (required) Bearer token for Takara |
43
+ | `MIRU_OPENAI_BASE_URL` | `https://infer.dev.takara.ai/v1` |
44
+ | `MIRU_OPENAI_EMBEDDING_MODEL` | `ds1-potion-code-16m` |
45
+ | `MIRU_EMBEDDING_DIMENSIONS` | `256` (auto for potion) |
46
+ | `MIRU_FLOAT_VECTORS` | unset (default **int8** quantized vectors); set `1` for float32 |
47
+ | `MIRU_EMBEDDING_BATCH_SIZE` | `32` (max for this model) |
48
+ | `MIRU_CONCURRENCY` | logical CPUs **minus 2** (min 1) |
49
+
50
+ `SEMBLE_*` env names are still accepted as aliases for migration.
51
+
52
+ Parallelism: file reads/chunking, embedding batches (up to concurrency in flight), query embed overlapping BM25, and **BM25 scoring in Bun workers** (shards by doc range when index has 256+ chunks). BM25 uses an inverted postings list for fast single-threaded search on small indexes. Override with `MIRU_CONCURRENCY`.
53
+
54
+ `OPENAI_*` env aliases are also accepted where noted in the CLI help.
55
+
56
+ ## CLI
57
+
58
+ ```bash
59
+ # Hybrid search (positional, Python-compatible)
60
+ bun run miru search "where are embeddings created" ./src -k 5
61
+
62
+ # Find semantically related chunks
63
+ bun run miru find-related src/embeddings/openai.ts 120 ./src
64
+
65
+ # Write a miru-code sub-agent for Cursor / Claude / etc.
66
+ bun run miru init --agent cursor
67
+
68
+ # Clear disk cache
69
+ bun run miru clear ./src
70
+ ```
71
+
72
+ Indexes are cached under `~/Library/Caches/miru` (macOS) or `~/.cache/miru` (Linux).
73
+
74
+ ## MCP server
75
+
76
+ Run with **no arguments** to start the stdio MCP server. It indexes the **current working directory** (Cursor sets this to your workspace). Optional path/ref flags pre-index a different repo.
77
+
78
+ ```bash
79
+ bun /path/to/miru/src/cli.ts
80
+ # or after bun add -g @takara-ai/miru-code: miru
81
+ # or without installing: bunx @takara-ai/miru-code
82
+ ```
83
+
84
+ **Tools:** `search`, `find_related` — pass `repo` only when querying a different path or git URL.
85
+
86
+ Cursor `~/.cursor/mcp.json` (or project `.cursor/mcp.json`):
87
+
88
+ ```json
89
+ {
90
+ "mcpServers": {
91
+ "miru": {
92
+ "command": "bunx",
93
+ "args": ["@takara-ai/miru-code"],
94
+ "env": {
95
+ "TAKARA_API_KEY": "your-takara-bearer-token",
96
+ "MIRU_OPENAI_BASE_URL": "https://infer.dev.takara.ai/v1",
97
+ "MIRU_OPENAI_EMBEDDING_MODEL": "ds1-potion-code-16m",
98
+ "MIRU_EMBEDDING_DIMENSIONS": "256"
99
+ }
100
+ }
101
+ }
102
+ }
103
+ ```
104
+
105
+ Alternatively, after `bun add -g @takara-ai/miru-code`:
106
+
107
+ ```json
108
+ {
109
+ "mcpServers": {
110
+ "miru": {
111
+ "command": "miru",
112
+ "env": {
113
+ "TAKARA_API_KEY": "your-takara-bearer-token"
114
+ }
115
+ }
116
+ }
117
+ }
118
+ ```
119
+
120
+ Local development (path to this repo):
121
+
122
+ ```json
123
+ {
124
+ "mcpServers": {
125
+ "miru": {
126
+ "command": "bun",
127
+ "args": ["/absolute/path/to/miru/src/cli.ts"],
128
+ "env": {
129
+ "TAKARA_API_KEY": "your-takara-bearer-token"
130
+ }
131
+ }
132
+ }
133
+ }
134
+ ```
135
+
136
+ No project path in `args` for `bunx` / global install — Cursor runs the server with `cwd` set to the open workspace, which becomes the default index. Put the bearer token in `env`; MCP will not read `.env.local` unless those vars are unset.
137
+
138
+ ## Library
139
+
140
+ ```ts
141
+ import { MiruIndex } from "@takara-ai/miru-code";
142
+
143
+ const index = await MiruIndex.fromPath("./src");
144
+ const results = await index.search({ query: "BM25 tokenize", topK: 10 });
145
+ ```
146
+
147
+ ## Tests
148
+
149
+ ```bash
150
+ bun test
151
+ bun run typecheck
152
+ ```
153
+
154
+ ## Publishing
155
+
156
+ Releases use **Bun** for install, test, and `bun pm pack`. The registry upload uses **`npm publish`** on that tarball because [Bun does not yet support npm OIDC trusted publishing](https://github.com/oven-sh/bun/issues/22423) — no long-lived npm tokens in GitHub secrets.
157
+
158
+ **Local first publish** (creates the package on npm):
159
+
160
+ ```bash
161
+ bun publish --access public
162
+ ```
163
+
164
+ **CI** (after Trusted Publisher is configured on npm):
165
+
166
+ ```bash
167
+ npm version patch
168
+ git push && git push --tags
169
+ gh release create v0.1.1 --generate-notes
170
+ ```
171
+
172
+ The `release.yml` workflow runs when the GitHub Release is published.
173
+
174
+ ## License
175
+
176
+ MIT
package/bin/miru.cjs ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const { spawnSync } = require("node:child_process");
5
+ const fs = require("node:fs");
6
+ const path = require("node:path");
7
+
8
+ const packageRoot = path.join(__dirname, "..");
9
+
10
+ function resolveBunExecutable() {
11
+ const binName = process.platform === "win32" ? "bun.cmd" : "bun";
12
+ const candidates = [
13
+ path.join(packageRoot, "node_modules", ".bin", binName),
14
+ path.join(packageRoot, "node_modules", "bun", "bin", process.platform === "win32" ? "bun.exe" : "bun"),
15
+ ];
16
+ for (const candidate of candidates) {
17
+ if (fs.existsSync(candidate)) {
18
+ return candidate;
19
+ }
20
+ }
21
+ return binName;
22
+ }
23
+
24
+ const cli = path.join(packageRoot, "src", "cli.ts");
25
+ const bun = resolveBunExecutable();
26
+ const result = spawnSync(bun, [cli, ...process.argv.slice(2)], {
27
+ stdio: "inherit",
28
+ cwd: process.cwd(),
29
+ env: process.env,
30
+ shell: process.platform === "win32",
31
+ });
32
+
33
+ if (result.error) {
34
+ console.error(
35
+ "miru: failed to run Bun. Reinstall with lifecycle scripts enabled (do not use --ignore-scripts).",
36
+ );
37
+ console.error(result.error.message);
38
+ process.exit(1);
39
+ }
40
+
41
+ process.exit(result.status ?? 1);
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@takara-ai/miru-code",
3
+ "version": "0.1.0",
4
+ "description": "Miru (見る) — hybrid code search for agents. Bun, TypeScript, Takara embeddings.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Takara",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/takara-ai/miru-code.git"
11
+ },
12
+ "homepage": "https://takara.ai",
13
+ "bugs": "https://github.com/takara-ai/miru-code/issues",
14
+ "keywords": [
15
+ "code-search",
16
+ "semantic-search",
17
+ "hybrid-search",
18
+ "mcp",
19
+ "embeddings",
20
+ "bm25",
21
+ "bun",
22
+ "agents",
23
+ "cursor",
24
+ "takara"
25
+ ],
26
+ "engines": {
27
+ "bun": ">=1.1.0"
28
+ },
29
+ "trustedDependencies": [
30
+ "bun"
31
+ ],
32
+ "bin": {
33
+ "miru": "bin/miru.cjs"
34
+ },
35
+ "main": "./src/index.ts",
36
+ "types": "./src/index.ts",
37
+ "exports": {
38
+ ".": "./src/index.ts"
39
+ },
40
+ "files": [
41
+ "bin",
42
+ "src",
43
+ "README.md",
44
+ "LICENSE"
45
+ ],
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "scripts": {
50
+ "miru": "bun run src/cli.ts",
51
+ "mcp": "bun run src/cli.ts",
52
+ "test": "bun test",
53
+ "typecheck": "tsc --noEmit",
54
+ "lint": "biome check .",
55
+ "lint:fix": "biome check --write .",
56
+ "prepublishOnly": "bun run typecheck && bun test",
57
+ "publish": "npm publish --access public",
58
+ "benchmark:quality": "bun run scripts/benchmark-quality.ts",
59
+ "benchmark:quantization": "bun run scripts/benchmark-quantization.ts"
60
+ },
61
+ "dependencies": {
62
+ "@modelcontextprotocol/sdk": "^1.29.0",
63
+ "bun": "^1.1.0",
64
+ "ignore": "^7.0.5",
65
+ "zod": "^4.4.3"
66
+ },
67
+ "devDependencies": {
68
+ "@biomejs/biome": "^2.4.16",
69
+ "@types/bun": "latest",
70
+ "typescript": "^5.9.3"
71
+ }
72
+ }
@@ -0,0 +1,41 @@
1
+ ---
2
+ name: miru-code
3
+ description: Code search agent for exploring any codebase. Use for finding code by intent, locating implementations, understanding how something works, or discovering related code. Prefer over Grep/Glob/Read for any semantic or exploratory question.
4
+ tools: Bash, Read
5
+ ---
6
+
7
+ Use `miru search` to find code by describing what it does or naming a symbol/identifier, instead of grep:
8
+
9
+ ```bash
10
+ miru search "authentication flow" ./my-project
11
+ miru search "save_pretrained" ./my-project
12
+ miru search "save model to disk" ./my-project --top-k 10
13
+ ```
14
+
15
+ Results are cached automatically on first run and invalidated when files change.
16
+
17
+ Use `--content docs` to search documentation and prose, `--content config` for config files (yaml, toml, etc.), or `--content all` to search code, docs, and config:
18
+
19
+ ```bash
20
+ miru search "deployment guide" ./my-project --content docs
21
+ miru search "database host port" ./my-project --content config
22
+ miru search "authentication" ./my-project --content all
23
+ ```
24
+
25
+ Use `miru find-related` to discover code similar to a known location (pass `file_path` and `line` from a prior search result):
26
+
27
+ ```bash
28
+ miru find-related src/auth.py 42 ./my-project
29
+ ```
30
+
31
+ `path` defaults to the current directory when omitted; git URLs are accepted.
32
+
33
+ If `miru` is not on `$PATH`, use `bunx miru` in its place.
34
+
35
+ ### Workflow
36
+
37
+ 1. Start with `miru search` to find relevant chunks. The index is built and cached automatically.
38
+ 2. Use `--content docs` for documentation, `--content config` for config files, or `--content all` for everything.
39
+ 3. Inspect full files only when the returned chunk does not give enough context.
40
+ 4. Optionally use `miru find-related` with a promising result's `file_path` and `line` to discover related implementations.
41
+ 5. Use grep only when you need exhaustive literal matches or quick confirmation of an exact string.
@@ -0,0 +1,41 @@
1
+ ---
2
+ name: miru-code
3
+ description: Code search agent for exploring any codebase. Use for finding code by intent, locating implementations, understanding how something works, or discovering related code. Prefer over Grep/Glob/Read for any semantic or exploratory question.
4
+ tools: Bash, Read
5
+ ---
6
+
7
+ Use `miru search` to find code by describing what it does or naming a symbol/identifier, instead of grep:
8
+
9
+ ```bash
10
+ miru search "authentication flow" ./my-project
11
+ miru search "save_pretrained" ./my-project
12
+ miru search "save model to disk" ./my-project --top-k 10
13
+ ```
14
+
15
+ Results are cached automatically on first run and invalidated when files change.
16
+
17
+ Use `--content docs` to search documentation and prose, `--content config` for config files (yaml, toml, etc.), or `--content all` to search code, docs, and config:
18
+
19
+ ```bash
20
+ miru search "deployment guide" ./my-project --content docs
21
+ miru search "database host port" ./my-project --content config
22
+ miru search "authentication" ./my-project --content all
23
+ ```
24
+
25
+ Use `miru find-related` to discover code similar to a known location (pass `file_path` and `line` from a prior search result):
26
+
27
+ ```bash
28
+ miru find-related src/auth.py 42 ./my-project
29
+ ```
30
+
31
+ `path` defaults to the current directory when omitted; git URLs are accepted.
32
+
33
+ If `miru` is not on `$PATH`, use `bunx miru` in its place.
34
+
35
+ ### Workflow
36
+
37
+ 1. Start with `miru search` to find relevant chunks. The index is built and cached automatically.
38
+ 2. Use `--content docs` for documentation, `--content config` for config files, or `--content all` for everything.
39
+ 3. Inspect full files only when the returned chunk does not give enough context.
40
+ 4. Optionally use `miru find-related` with a promising result's `file_path` and `line` to discover related implementations.
41
+ 5. Use grep only when you need exhaustive literal matches or quick confirmation of an exact string.
@@ -0,0 +1,40 @@
1
+ ---
2
+ name: miru-code
3
+ description: Code search agent for exploring any codebase. Use for finding code by intent, locating implementations, understanding how something works, or discovering related code. Prefer over Bash/Read for any semantic or exploratory question.
4
+ ---
5
+
6
+ Use `miru search` to find code by describing what it does or naming a symbol/identifier, instead of grep:
7
+
8
+ ```bash
9
+ miru search "authentication flow" ./my-project
10
+ miru search "save_pretrained" ./my-project
11
+ miru search "save model to disk" ./my-project --top-k 10
12
+ ```
13
+
14
+ Results are cached automatically on first run and invalidated when files change.
15
+
16
+ Use `--content docs` to search documentation and prose, `--content config` for config files (yaml, toml, etc.), or `--content all` to search code, docs, and config:
17
+
18
+ ```bash
19
+ miru search "deployment guide" ./my-project --content docs
20
+ miru search "database host port" ./my-project --content config
21
+ miru search "authentication" ./my-project --content all
22
+ ```
23
+
24
+ Use `miru find-related` to discover code similar to a known location (pass `file_path` and `line` from a prior search result):
25
+
26
+ ```bash
27
+ miru find-related src/auth.py 42 ./my-project
28
+ ```
29
+
30
+ `path` defaults to the current directory when omitted; git URLs are accepted.
31
+
32
+ If `miru` is not on `$PATH`, use `bunx miru` in its place.
33
+
34
+ ### Workflow
35
+
36
+ 1. Start with `miru search` to find relevant chunks. The index is built and cached automatically.
37
+ 2. Use `--content docs` for documentation, `--content config` for config files, or `--content all` for everything.
38
+ 3. Inspect full files only when the returned chunk does not give enough context.
39
+ 4. Optionally use `miru find-related` with a promising result's `file_path` and `line` to discover related implementations.
40
+ 5. Use grep only when you need exhaustive literal matches or quick confirmation of an exact string.
@@ -0,0 +1,43 @@
1
+ ---
2
+ name: miru-code
3
+ description: Code search agent for exploring any codebase. Use for finding code by intent, locating implementations, understanding how something works, or discovering related code. Prefer over run_shell_command/read_file for any semantic or exploratory question.
4
+ tools:
5
+ - run_shell_command
6
+ - read_file
7
+ ---
8
+
9
+ Use `miru search` to find code by describing what it does or naming a symbol/identifier, instead of grep:
10
+
11
+ ```bash
12
+ miru search "authentication flow" ./my-project
13
+ miru search "save_pretrained" ./my-project
14
+ miru search "save model to disk" ./my-project --top-k 10
15
+ ```
16
+
17
+ Results are cached automatically on first run and invalidated when files change.
18
+
19
+ Use `--content docs` to search documentation and prose, `--content config` for config files (yaml, toml, etc.), or `--content all` to search code, docs, and config:
20
+
21
+ ```bash
22
+ miru search "deployment guide" ./my-project --content docs
23
+ miru search "database host port" ./my-project --content config
24
+ miru search "authentication" ./my-project --content all
25
+ ```
26
+
27
+ Use `miru find-related` to discover code similar to a known location (pass `file_path` and `line` from a prior search result):
28
+
29
+ ```bash
30
+ miru find-related src/auth.py 42 ./my-project
31
+ ```
32
+
33
+ `path` defaults to the current directory when omitted; git URLs are accepted.
34
+
35
+ If `miru` is not on `$PATH`, use `bunx miru` in its place.
36
+
37
+ ### Workflow
38
+
39
+ 1. Start with `miru search` to find relevant chunks. The index is built and cached automatically.
40
+ 2. Use `--content docs` for documentation, `--content config` for config files, or `--content all` for everything.
41
+ 3. Inspect full files only when the returned chunk does not give enough context.
42
+ 4. Optionally use `miru find-related` with a promising result's `file_path` and `line` to discover related implementations.
43
+ 5. Use grep only when you need exhaustive literal matches or quick confirmation of an exact string.
@@ -0,0 +1,43 @@
1
+ ---
2
+ name: miru-code
3
+ description: Code search agent for exploring any codebase. Use for finding code by intent, locating implementations, understanding how something works, or discovering related code. Prefer over shell/read tools for any semantic or exploratory question.
4
+ tools:
5
+ - shell
6
+ - read
7
+ ---
8
+
9
+ Use `miru search` to find code by describing what it does or naming a symbol/identifier, instead of grep:
10
+
11
+ ```bash
12
+ miru search "authentication flow" ./my-project
13
+ miru search "save_pretrained" ./my-project
14
+ miru search "save model to disk" ./my-project --top-k 10
15
+ ```
16
+
17
+ Results are cached automatically on first run and invalidated when files change.
18
+
19
+ Use `--content docs` to search documentation and prose, `--content config` for config files (yaml, toml, etc.), or `--content all` to search code, docs, and config:
20
+
21
+ ```bash
22
+ miru search "deployment guide" ./my-project --content docs
23
+ miru search "database host port" ./my-project --content config
24
+ miru search "authentication" ./my-project --content all
25
+ ```
26
+
27
+ Use `miru find-related` to discover code similar to a known location (pass `file_path` and `line` from a prior search result):
28
+
29
+ ```bash
30
+ miru find-related src/auth.py 42 ./my-project
31
+ ```
32
+
33
+ `path` defaults to the current directory when omitted; git URLs are accepted.
34
+
35
+ If `miru` is not on `$PATH`, use `bunx miru` in its place.
36
+
37
+ ### Workflow
38
+
39
+ 1. Start with `miru search` to find relevant chunks. The index is built and cached automatically.
40
+ 2. Use `--content docs` for documentation, `--content config` for config files, or `--content all` for everything.
41
+ 3. Inspect full files only when the returned chunk does not give enough context.
42
+ 4. Optionally use `miru find-related` with a promising result's `file_path` and `line` to discover related implementations.
43
+ 5. Use grep only when you need exhaustive literal matches or quick confirmation of an exact string.
@@ -0,0 +1,44 @@
1
+ ---
2
+ name: miru-code
3
+ description: Code search agent for exploring any codebase. Use for finding code by intent, locating implementations, understanding how something works, or discovering related code. Prefer over Bash/Read for any semantic or exploratory question.
4
+ mode: subagent
5
+ permission:
6
+ bash: allow
7
+ read: allow
8
+ ---
9
+
10
+ Use `miru search` to find code by describing what it does or naming a symbol/identifier, instead of grep:
11
+
12
+ ```bash
13
+ miru search "authentication flow" ./my-project
14
+ miru search "save_pretrained" ./my-project
15
+ miru search "save model to disk" ./my-project --top-k 10
16
+ ```
17
+
18
+ Results are cached automatically on first run and invalidated when files change.
19
+
20
+ Use `--content docs` to search documentation and prose, `--content config` for config files (yaml, toml, etc.), or `--content all` to search code, docs, and config:
21
+
22
+ ```bash
23
+ miru search "deployment guide" ./my-project --content docs
24
+ miru search "database host port" ./my-project --content config
25
+ miru search "authentication" ./my-project --content all
26
+ ```
27
+
28
+ Use `miru find-related` to discover code similar to a known location (pass `file_path` and `line` from a prior search result):
29
+
30
+ ```bash
31
+ miru find-related src/auth.py 42 ./my-project
32
+ ```
33
+
34
+ `path` defaults to the current directory when omitted; git URLs are accepted.
35
+
36
+ If `miru` is not on `$PATH`, use `bunx miru` in its place.
37
+
38
+ ### Workflow
39
+
40
+ 1. Start with `miru search` to find relevant chunks. The index is built and cached automatically.
41
+ 2. Use `--content docs` for documentation, `--content config` for config files, or `--content all` for everything.
42
+ 3. Inspect full files only when the returned chunk does not give enough context.
43
+ 4. Optionally use `miru find-related` with a promising result's `file_path` and `line` to discover related implementations.
44
+ 5. Use grep only when you need exhaustive literal matches or quick confirmation of an exact string.
package/src/agents.ts ADDED
@@ -0,0 +1,30 @@
1
+ import { mkdir, readFile } from "node:fs/promises";
2
+ import { dirname, join } from "node:path";
3
+
4
+ export type AgentId = "claude" | "copilot" | "cursor" | "gemini" | "kiro" | "opencode";
5
+
6
+ const AGENTS_DIR = join(import.meta.dir, "agents");
7
+
8
+ export function agentDestination(agent: AgentId): string {
9
+ const baseDir = agent === "copilot" ? ".github" : `.${agent}`;
10
+ return join(baseDir, "agents", "miru-code.md");
11
+ }
12
+
13
+ export async function loadAgentTemplate(agent: AgentId): Promise<string> {
14
+ return readFile(join(AGENTS_DIR, `${agent}.md`), "utf-8");
15
+ }
16
+
17
+ export async function writeAgentFile(
18
+ agent: AgentId,
19
+ options: { force?: boolean } = {},
20
+ ): Promise<string> {
21
+ const dest = agentDestination(agent);
22
+ const existing = await Bun.file(dest).exists();
23
+ if (existing && !options.force) {
24
+ throw new Error(`${dest} already exists. Run with --force to overwrite.`);
25
+ }
26
+ await mkdir(dirname(dest), { recursive: true });
27
+ const content = await loadAgentTemplate(agent);
28
+ await Bun.write(dest, content);
29
+ return dest;
30
+ }