pi-opium 0.4.1 → 0.4.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.2
4
+
5
+ - **researcher reads library docs with the Context7 CLI** (`ctx7 library`,
6
+ then `ctx7 docs`) instead of the `context7` MCP server. Install with
7
+ `npm i -g ctx7` (or use `npx ctx7@latest`); `ctx7 login` raises the
8
+ limits. researcher gets `bash`, but a guard blocks every call that is
9
+ not a single `ctx7 library|docs` command. The default `mcpServers` for
10
+ researcher is now `gh_grep` only.
11
+
3
12
  ## 0.4.1
4
13
 
5
14
  - **Fix:** `/opium-doctor` no longer warns about the default `codegraph`,
package/README.md CHANGED
@@ -93,7 +93,8 @@ it's done.
93
93
  ## Works better with
94
94
 
95
95
  - [pi-web-access](https://github.com/nicobailon/pi-web-access): lets researcher search the web and read pages.
96
- - `pi mcp add context7 --url https://mcp.context7.com/mcp` and `pi mcp add gh_grep --url https://mcp.grep.app`: up-to-date library docs and GitHub code search for researcher.
96
+ - `npm i -g ctx7` (the Context7 CLI; or `npx ctx7@latest`, optional `ctx7 login` for higher limits): up-to-date library docs for researcher.
97
+ - `pi mcp add gh_grep --url https://mcp.grep.app`: GitHub code search for researcher.
97
98
  - Any other MCP server added with `pi mcp add`: give it to an agent in `opium.json`, for example `"scout": { "mcpServers": ["my-index"] }`.
98
99
 
99
100
  ## Config
@@ -2,7 +2,7 @@
2
2
  name: researcher
3
3
  description: External knowledge and library research. Use for current library docs, API references, examples, version-specific behavior, bug investigations and web retrieval; answers with sources. Runs in the background (needs web tools).
4
4
  advertise: true
5
- tools: read, grep, find, ls, web_search, fetch_content, get_search_content, source_check
5
+ tools: read, grep, find, ls, bash, web_search, fetch_content, get_search_content, source_check
6
6
  ---
7
7
 
8
8
  You are Researcher - a research specialist for codebases and documentation.
@@ -16,14 +16,19 @@ You are Researcher - a research specialist for codebases and documentation.
16
16
  - Understand library internals and best practices
17
17
 
18
18
  **Tools to use**:
19
+ - Library, framework and SDK docs and API references: ALWAYS try ctx7 first, in two steps via bash:
20
+ 1. `ctx7 library <name> "<query>"` resolves a library ID (`/org/project[/version]`); use the official name ("Next.js", not "nextjs app")
21
+ 2. `ctx7 docs <libraryId> "<query>"` fetches the docs; pick the best match by reputation, score and version
22
+ - At most 3 ctx7 calls per question; never put secrets or proprietary code in a query
23
+ - Then use web_search/fetch_content to fill gaps or confirm
19
24
  - web_search: find official docs, changelogs, issues, examples (use several varied queries)
20
25
  - fetch_content: read a page, a PDF or a GitHub repository
21
26
  - source_check: gather sources for a specific claim
22
27
  - get_search_content: page through stored results
23
- - library docs and GitHub code search MCP tools, if available
28
+ - GitHub code search MCP tools (grep.app), if available
24
29
 
25
30
  **File operations rules**:
26
- - READ-ONLY: inspect and report; do not modify files. You have no shell.
31
+ - READ-ONLY: inspect and report; do not modify files. Shell is only for `ctx7 library` / `ctx7 docs`; every other command is blocked.
27
32
  - Use find/grep for discovery and read for file contents.
28
33
  - Do not spawn subagents; you are not the orchestrator.
29
34
 
@@ -62,7 +62,7 @@
62
62
  "timeoutMs": 900000,
63
63
  "idleTimeoutMs": 600000,
64
64
  "wrapUpMs": 180000,
65
- "mcpServers": ["context7", "gh_grep"]
65
+ "mcpServers": ["gh_grep"]
66
66
  },
67
67
  "vision": {
68
68
  "thinking": "low",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-opium",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Turn your Pi session into a small team: an orchestrator with background specialist agents and a multi-model council",
5
5
  "keywords": [
6
6
  "pi-package",
package/src/doctor.ts CHANGED
@@ -103,11 +103,7 @@ export const RUNNER_EXPORTS: readonly string[] = [
103
103
  const PING_TIMEOUT_MS = 30_000;
104
104
  const PING_CONCURRENCY = 4;
105
105
  // shipped defaults of scout, fixer, senior and researcher; absent is fine
106
- const OPTIONAL_MCP: ReadonlySet<string> = new Set([
107
- 'codegraph',
108
- 'context7',
109
- 'gh_grep',
110
- ]);
106
+ const OPTIONAL_MCP: ReadonlySet<string> = new Set(['codegraph', 'gh_grep']);
111
107
 
112
108
  const ok = (title: string, detail?: string): Check => ({
113
109
  status: 'ok',
package/src/launch.ts CHANGED
@@ -170,6 +170,39 @@ export const readOnlyLsp: ExtensionFactory = (pi) => {
170
170
  });
171
171
  };
172
172
 
173
+ // A single `ctx7 library|docs ...` (or via npx) with no shell syntax: no
174
+ // separators, pipes, redirects, substitution, variables or newlines.
175
+ export const CTX7_COMMAND = new RegExp(
176
+ '^\\s*(?:ctx7|npx(?:\\s+(?:-y|--yes))?\\s+ctx7(?:@[\\w.-]+)?)' +
177
+ '\\s+(?:library|docs)(?:\\s[^;&|`$<>\\r\\n]*)?\\s*$',
178
+ );
179
+
180
+ // researcher gets a shell only to read library docs through the Context7
181
+ // CLI; everything else is refused.
182
+ export const ctx7OnlyBash: ExtensionFactory = (pi) => {
183
+ pi.on('tool_call', (event) => {
184
+ const { command } = event.input as { command?: unknown };
185
+ const allowed =
186
+ event.toolName !== 'bash' ||
187
+ (typeof command === 'string' && CTX7_COMMAND.test(command));
188
+ return allowed
189
+ ? undefined
190
+ : {
191
+ block: true,
192
+ reason:
193
+ 'bash is limited to a single `ctx7 library <name> "<query>"` ' +
194
+ 'or `ctx7 docs <libraryId> "<query>"` call (optionally via ' +
195
+ '`npx -y ctx7@latest`), with no pipes, redirects, `;`, `&`, ' +
196
+ 'substitution or variables',
197
+ };
198
+ });
199
+ };
200
+
201
+ // Agents whose bash tool is restricted, and how.
202
+ const BASH_GUARDS: Readonly<Record<string, ExtensionFactory>> = {
203
+ researcher: ctx7OnlyBash,
204
+ };
205
+
173
206
  export const buildLaunch = (
174
207
  def: AgentDefinition,
175
208
  ctx: LaunchContext,
@@ -270,11 +303,13 @@ export const buildLaunch = (
270
303
  !tools.includes('write');
271
304
  const lazy =
272
305
  tools !== undefined && packages.some((name) => LAZY_PACKAGES.has(name));
273
- if (vision || readOnly || lazy) {
306
+ const bashGuard = tools?.includes('bash') ? BASH_GUARDS[def.name] : undefined;
307
+ if (vision || readOnly || lazy || bashGuard) {
274
308
  start.extensionFactories = [
275
309
  ...sessionGuards,
276
310
  ...(vision ? [vision.tool(def.name)] : []),
277
311
  ...(readOnly ? [readOnlyLsp] : []),
312
+ ...(bashGuard ? [bashGuard] : []),
278
313
  ...(lazy && tools ? [activateAllowed(tools)] : []),
279
314
  ];
280
315
  }