realontext 0.19.0 → 0.20.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "realontext",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "description": "Code search for coding agents, over the directory you are in. Needs `npm install -g realontext`.",
5
5
  "author": {
6
6
  "name": "FlowerRealm",
@@ -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; add `query`, an English description of the code - 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 ask, with line numbers. `pattern` is the regex you would grep for; add `query`, an English description of the code, when you are describing behavior, and leave it out for a name you know. 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.
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; add `query`, an English description of the code, unless you already know the exact name - 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 and, with `flat`, that the answer is not wrapped in
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,20 @@
1
- // `realontext hook <agent>`: the first time an agent's session
2
- // fires the hook `setup` wrote, the model is reminded that codebase-retrieval
3
- // searches source code. Once a session, and only context: the agent goes on
4
- // as it would, and any failure here is silent. Which event it answers, and in
5
- // what shape, is the agent's `hook` in `agents.js`.
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`.
6
7
  "use strict";
7
8
 
8
9
  const fs = require("fs");
9
10
  const os = require("os");
10
11
  const path = require("path");
11
12
 
12
- // True the first time it is asked for a session, false after: a marker file
13
- // per session, made atomically, since every hook call is its own process.
14
- function firstTime(session) {
15
- const id = String(session || process.ppid).replace(/[^\w-]/g, "");
13
+ // True the first time it is asked for one session and event, false after: a
14
+ // marker file per session, made atomically, since every hook call is its own
15
+ // process.
16
+ function firstTime(marker) {
17
+ const id = marker.replace(/[^\w-]/g, "");
16
18
  try {
17
19
  fs.closeSync(fs.openSync(path.join(os.tmpdir(), `realontext-hint-${id}`), "wx"));
18
20
  return true;
@@ -26,11 +28,17 @@ module.exports = function hook(key) {
26
28
  process.stdin.on("data", (d) => (raw += d));
27
29
  process.stdin.on("end", () => {
28
30
  try {
29
- const { event, flat } = require("./agents.js")[key].hook;
31
+ const events = [].concat(require("./agents.js")[key].hook);
30
32
  const input = JSON.parse(raw);
31
- if (!firstTime(input.session_id ?? input.sessionId ?? input.conversation_id)) return;
32
- const hint = fs.readFileSync(path.join(__dirname, "..", "hooks", "hint.md"), "utf8").trimEnd();
33
- const out = flat ? { additionalContext: hint } : { hookSpecificOutput: { hookEventName: event, additionalContext: hint } };
33
+ // The event that fired, as the agent names it; the first entry answers
34
+ // when the payload does not name one.
35
+ const fired = typeof input.hook_event_name === "string" ? input.hook_event_name : "";
36
+ const { event, flat, hint } = events.find((e) => e.event === fired) ?? events[0];
37
+ const session = String((input.session_id ?? input.sessionId ?? input.conversation_id) || process.ppid);
38
+ if (!firstTime(`${key}-${event}-${session}`)) return;
39
+ const file = hint ? `hint-${hint}.md` : "hint.md";
40
+ const text = fs.readFileSync(path.join(__dirname, "..", "hooks", file), "utf8").trimEnd();
41
+ const out = flat ? { additionalContext: text } : { hookSpecificOutput: { hookEventName: event, additionalContext: text } };
34
42
  process.stdout.write(JSON.stringify(out));
35
43
  } catch {
36
44
  // A reminder that cannot be given is not worth stopping the agent for.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "realontext",
3
- "version": "0.19.0",
3
+ "version": "0.20.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.19.0",
38
- "@realontext/linux-x64": "0.19.0",
39
- "@realontext/win32-x64": "0.19.0"
37
+ "@realontext/darwin-arm64": "0.20.0",
38
+ "@realontext/linux-x64": "0.20.0",
39
+ "@realontext/win32-x64": "0.20.0"
40
40
  }
41
41
  }