realontext 0.19.0 → 0.21.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.
- package/.claude-plugin/plugin.json +1 -1
- package/bin/realontext.js +4 -2
- package/hooks/hint-grep.md +3 -0
- package/hooks/hint.md +1 -1
- package/lib/agents.js +13 -6
- package/lib/hook.js +29 -13
- package/lib/rules.md +1 -1
- package/package.json +4 -4
package/bin/realontext.js
CHANGED
|
@@ -16,8 +16,10 @@ const terminal = process.stdin.isTTY && process.stdout.isTTY;
|
|
|
16
16
|
if (command !== "mcp" && command !== "hook") require("../lib/update.js").start();
|
|
17
17
|
|
|
18
18
|
function exit(status) {
|
|
19
|
-
if (typeof status
|
|
20
|
-
process.
|
|
19
|
+
if (typeof status !== "string") process.exit(status);
|
|
20
|
+
process.kill(process.pid, status);
|
|
21
|
+
// Still here: a signal Node ignores, SIGPIPE. The status a shell gives it.
|
|
22
|
+
process.exit(128 + require("os").constants.signals[status]);
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
if (terminal && (command === undefined || (command === "setup" && rest.length === 0))) {
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<realontext>
|
|
2
|
+
That was grep. Code search goes through codebase-retrieval, not grep: call it now for the code you were looking for - it returns whole functions, ranked by what you asked, with line numbers. If it is not loaded yet, load it once with `search_tools` (query "codebase-retrieval") and call it. `pattern` is the regex you would grep for; give `query`, an English description of the code, on every call - leave it out only when the pattern is one exact name you know; with it, a model on the realontext Relay ranks the results. Text outside code (docs, configs, logs, a command's output) is `realontext query --pattern RE [--path PATH]...` in the shell.
|
|
3
|
+
</realontext>
|
package/hooks/hint.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
<realontext>
|
|
2
|
-
To search source code, call codebase-retrieval instead of grep or rg: it returns whole functions ranked by what you
|
|
2
|
+
To search source code, call codebase-retrieval yourself instead of grep or rg: it returns whole functions ranked by what you asked, with line numbers. Search yourself, at every step of the task: do not hand a code search to a subagent, which may not have this tool and greps instead. If your client defers tools and lists it by name only, load it once with your tool search before the first call. `pattern` is the regex you would grep for; give `query`, an English description of the code, on every call - leave it out only when the pattern is one exact name you know; with it, a model on the realontext Relay ranks the results. For docs, configs, logs and a command's output, use `realontext query --pattern RE [--path PATH]...` in the shell, or pipe into it: `git log | realontext query --pattern fix`. Do not run grep or rg at all.
|
|
3
3
|
</realontext>
|
package/lib/agents.js
CHANGED
|
@@ -15,9 +15,10 @@
|
|
|
15
15
|
// the once-a-session reminder, where the agent has a hook that adds
|
|
16
16
|
// context the model sees; the usage rules, where the agent is known not to
|
|
17
17
|
// pass the server's instructions to the model, or its model was seen not to
|
|
18
|
-
// use the tool without them. `hook` names the event the
|
|
19
|
-
// reminder answers
|
|
20
|
-
// `hookSpecificOutput
|
|
18
|
+
// use the tool without them. `hook` names the event or events the
|
|
19
|
+
// reminder answers, with `flat` that the answer is not wrapped in
|
|
20
|
+
// `hookSpecificOutput`, and with `hint` that another file in `hooks/` carries
|
|
21
|
+
// the text. An entry on a tool call answers the first time that tool runs.
|
|
21
22
|
"use strict";
|
|
22
23
|
|
|
23
24
|
const fs = require("fs");
|
|
@@ -250,11 +251,17 @@ const agents = {
|
|
|
250
251
|
// Global, like Codex's: nothing of ours lands in the repository. An
|
|
251
252
|
// earlier entry at another scope would win over this one, so clear first.
|
|
252
253
|
{ clear: "cmd mcp remove realontext", run: "cmd mcp add --scope user realontext -- realontext mcp" },
|
|
253
|
-
// Its hooks cover shell, read, write and edit, never the Grep tool: only
|
|
254
|
-
// SessionStart can carry the reminder.
|
|
255
254
|
{ list: "~/.commandcode/settings.json", at: ["hooks", "SessionStart"], value: nested("commandcode") },
|
|
255
|
+
// Its hooks match the tool's display name, and the Grep tool's is SEARCH:
|
|
256
|
+
// the reminder rides the first grep result itself, where the model reads
|
|
257
|
+
// it, not the session's first turn. Anchored: SEARCH also sits inside
|
|
258
|
+
// SEARCH_TOOLS and WEB_SEARCH.
|
|
259
|
+
{ list: "~/.commandcode/settings.json", at: ["hooks", "PreToolUse"], value: nested("commandcode", "^SEARCH$") },
|
|
260
|
+
],
|
|
261
|
+
hook: [
|
|
262
|
+
{ event: "SessionStart" },
|
|
263
|
+
{ event: "PreToolUse", hint: "grep" },
|
|
256
264
|
],
|
|
257
|
-
hook: { event: "SessionStart" },
|
|
258
265
|
},
|
|
259
266
|
};
|
|
260
267
|
|
package/lib/hook.js
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
// `realontext hook <agent>`: the first time
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
1
|
+
// `realontext hook <agent>`: the first time a session fires each hook
|
|
2
|
+
// `setup` wrote, the model is reminded that codebase-retrieval searches source
|
|
3
|
+
// code. Once a session per event, and only context: the agent goes on as it
|
|
4
|
+
// would, and any failure here is silent. Which events it answers, and in what
|
|
5
|
+
// shape, is the agent's `hook` in `agents.js` - one event or a list of them; an
|
|
6
|
+
// entry naming a `hint` reads `hooks/hint-<hint>.md` in place of `hooks/hint.md`.
|
|
7
|
+
// An entry with no `hint` whose event fired for a grep tool reads `hint-grep.md`
|
|
8
|
+
// instead: the reminder rides the grep itself, which is where the model reaches
|
|
9
|
+
// for it, not the session's first turn.
|
|
6
10
|
"use strict";
|
|
7
11
|
|
|
8
12
|
const fs = require("fs");
|
|
9
13
|
const os = require("os");
|
|
10
14
|
const path = require("path");
|
|
11
15
|
|
|
12
|
-
// True the first time it is asked for
|
|
13
|
-
// per session, made atomically, since every hook call is its own
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
// True the first time it is asked for one session, event and text, false after:
|
|
17
|
+
// a marker file per session, made atomically, since every hook call is its own
|
|
18
|
+
// process.
|
|
19
|
+
function firstTime(marker) {
|
|
20
|
+
const id = marker.replace(/[^\w-]/g, "");
|
|
16
21
|
try {
|
|
17
22
|
fs.closeSync(fs.openSync(path.join(os.tmpdir(), `realontext-hint-${id}`), "wx"));
|
|
18
23
|
return true;
|
|
@@ -26,11 +31,22 @@ module.exports = function hook(key) {
|
|
|
26
31
|
process.stdin.on("data", (d) => (raw += d));
|
|
27
32
|
process.stdin.on("end", () => {
|
|
28
33
|
try {
|
|
29
|
-
const
|
|
34
|
+
const events = [].concat(require("./agents.js")[key].hook);
|
|
30
35
|
const input = JSON.parse(raw);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
36
|
+
// The event that fired, as the agent names it; the first entry answers
|
|
37
|
+
// when the payload does not name one.
|
|
38
|
+
const fired = typeof input.hook_event_name === "string" ? input.hook_event_name : "";
|
|
39
|
+
const { event, flat, hint } = events.find((e) => e.event === fired) ?? events[0];
|
|
40
|
+
const session = String((input.session_id ?? input.sessionId ?? input.conversation_id) || process.ppid);
|
|
41
|
+
// The tool the event is about, as the agent names it: a grep tool gets the
|
|
42
|
+
// sharp reminder, anything else the plain one. Command Code's grep is
|
|
43
|
+
// SEARCH, which no `/grep/i` catches: its own entry says `hint: "grep"`.
|
|
44
|
+
const tool = String(input.tool_name ?? input.toolName ?? input.tool ?? "");
|
|
45
|
+
const which = hint ?? (/grep/i.test(tool) ? "grep" : "");
|
|
46
|
+
if (!firstTime(`${key}-${event}-${which || "hint"}-${session}`)) return;
|
|
47
|
+
const file = which ? `hint-${which}.md` : "hint.md";
|
|
48
|
+
const text = fs.readFileSync(path.join(__dirname, "..", "hooks", file), "utf8").trimEnd();
|
|
49
|
+
const out = flat ? { additionalContext: text } : { hookSpecificOutput: { hookEventName: event, additionalContext: text } };
|
|
34
50
|
process.stdout.write(JSON.stringify(out));
|
|
35
51
|
} catch {
|
|
36
52
|
// A reminder that cannot be given is not worth stopping the agent for.
|
package/lib/rules.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
## Code search
|
|
2
2
|
|
|
3
|
-
This repository is searched with realontext, which replaces grep. Its MCP tool `codebase-retrieval` searches the code: every time you need to know where something is in the source (where or how something is done, where a name you know is defined, what calls it, where it is used, which line of a file it is on), call `codebase-retrieval` yourself, at every step of the task (if your tools are deferred, load it first). For text in docs, configs and logs, and for a command's output, run `realontext query --pattern RE [--path PATH]...` in the shell, or pipe into it: `git log | realontext query --pattern fix`. Do not run grep, rg, git grep or any other text search, as a tool or in the shell, alone or inside a longer command. Listing files by name stays with your own tools. Every call needs a `pattern`: the grep you would have run, in ripgrep's syntax: a name exactly (`truncate_name\(` for every call of it), or for a description the keywords the code must contain, broad and case-insensitive (`(?i)retry|backoff`); only code with a matching line is searched.
|
|
3
|
+
This repository is searched with realontext, which replaces grep. Its MCP tool `codebase-retrieval` searches the code: every time you need to know where something is in the source (where or how something is done, where a name you know is defined, what calls it, where it is used, which line of a file it is on), call `codebase-retrieval` yourself, at every step of the task (if your tools are deferred, load it first). For text in docs, configs and logs, and for a command's output, run `realontext query --pattern RE [--path PATH]...` in the shell, or pipe into it: `git log | realontext query --pattern fix`. Do not run grep, rg, git grep or any other text search, as a tool or in the shell, alone or inside a longer command. Listing files by name stays with your own tools. Every call needs a `pattern`: the grep you would have run, in ripgrep's syntax: a name exactly (`truncate_name\(` for every call of it), or for a description the keywords the code must contain, broad and case-insensitive (`(?i)retry|backoff`); only code with a matching line is searched. Give a `query` on every call, an English description of the behavior with words likely to appear in the code: the Relay then orders the results. Leave it out only when the pattern is one exact name you already know and you want just its own line: the pattern's words answer at once. If nothing comes back, loosen the pattern; if 20 results are not enough, narrow it.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "realontext",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Code search for coding agents, over the directory you are in. CLI and MCP server.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"repository": {
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"react": "^18.3.1"
|
|
35
35
|
},
|
|
36
36
|
"optionalDependencies": {
|
|
37
|
-
"@realontext/darwin-arm64": "0.
|
|
38
|
-
"@realontext/linux-x64": "0.
|
|
39
|
-
"@realontext/win32-x64": "0.
|
|
37
|
+
"@realontext/darwin-arm64": "0.21.0",
|
|
38
|
+
"@realontext/linux-x64": "0.21.0",
|
|
39
|
+
"@realontext/win32-x64": "0.21.0"
|
|
40
40
|
}
|
|
41
41
|
}
|