@srobroek/pi-agent-researcher 0.10.4 → 0.12.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/CHANGELOG.md +13 -0
- package/README.md +19 -0
- package/_kit/prereqs.json +26 -0
- package/_kit/prereqs.ts +374 -0
- package/agents/researcher.md +38 -7
- package/package.json +25 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
## agent-researcher [0.12.0](https://github.com/srobroek/harness-plugins/compare/agent-researcher--v0.11.0...agent-researcher--v0.12.0) (2026-11-24)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* **agent-coder:** grant pi subagents code-intelligence and helper tools ([89d8d54](https://github.com/srobroek/harness-plugins/commit/89d8d54af33d144801baf1ea2af5496b78887ced))
|
|
6
|
+
* **agent-researcher:** grant pi subagents code-intelligence and helper tools ([911efc5](https://github.com/srobroek/harness-plugins/commit/911efc59063d68104b81c8bc4af9da0d34fc6ef8))
|
|
7
|
+
|
|
8
|
+
## agent-researcher [0.11.0](https://github.com/srobroek/harness-plugins/compare/agent-researcher--v0.10.4...agent-researcher--v0.11.0) (2026-11-24)
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* **agent-researcher:** match pi-subagents' built-in researcher contract on pi ([e3fa574](https://github.com/srobroek/harness-plugins/commit/e3fa57424c3e58eea0860c0e7529d4ac09288448))
|
|
13
|
+
|
|
1
14
|
## agent-researcher [0.10.4](https://github.com/srobroek/harness-plugins/compare/agent-researcher--v0.10.3...agent-researcher--v0.10.4) (2026-11-24)
|
|
2
15
|
|
|
3
16
|
## agent-researcher [0.10.3](https://github.com/srobroek/harness-plugins/compare/agent-researcher--v0.10.2...agent-researcher--v0.10.3) (2026-11-24)
|
package/README.md
CHANGED
|
@@ -56,6 +56,14 @@ Patterns must name MCP server tools only (`<server>_<tool>`). The option refuses
|
|
|
56
56
|
|
|
57
57
|
This agent allows `execute`, so it reaches MCP tools through Code Mode; each nested call is checked against the same rules (`packages/core/src/tool.ts:337-339`, OpenCode v2.2.6).
|
|
58
58
|
|
|
59
|
+
## Pi tools
|
|
60
|
+
|
|
61
|
+
Pi `researcher` keeps `web_search`, `fetch_content`, `get_search_content`, and `source_check` from `pi-web-access`. It adds `symbol_search`, `module_report`, `project_report`, `read_symbol`, `read_enclosing`, `ast_grep_search`, `ast_grep_outline`, `lens_diagnostics`, and `pi_lens_activate_tools` from `pi-lens`. `repomix_pack` comes from `@srobroek/pi-repomix`.
|
|
62
|
+
|
|
63
|
+
Required companion packages: `pi-subagents`, `pi-web-access`, `pi-lens`, and `@srobroek/pi-repomix`. `context7` must be configured as a Pi MCP server in `~/.pi/agent/mcp.json`; it is selected by `mcp:context7`.
|
|
64
|
+
|
|
65
|
+
pi-lens keeps `ast_grep_*` tools inactive until `pi_lens_activate_tools` runs; they are available starting the next turn. The read-only allowlist omits `lsp_navigation` and `ast_grep_replace`.
|
|
66
|
+
|
|
59
67
|
## Install
|
|
60
68
|
Install the Pi package from npm:
|
|
61
69
|
|
|
@@ -73,3 +81,14 @@ omp plugin install /path/to/harness-plugins/plugins/agent-researcher/omp
|
|
|
73
81
|
```
|
|
74
82
|
|
|
75
83
|
This plugin ships no skills, so it is not in the Claude Code marketplace.
|
|
84
|
+
|
|
85
|
+
## Works with
|
|
86
|
+
|
|
87
|
+
This package works with these pi packages. Install them next to it.
|
|
88
|
+
|
|
89
|
+
| Package | Required | For | Install |
|
|
90
|
+
| --- | --- | --- | --- |
|
|
91
|
+
| `pi-subagents` | yes | the subagent tool | `pi install npm:pi-subagents` |
|
|
92
|
+
| `pi-lens` | yes | code-intelligence tools for the subagent | `pi install npm:pi-lens` |
|
|
93
|
+
| `@srobroek/pi-repomix` | yes | the repomix_pack tool | `pi install npm:@srobroek/pi-repomix` |
|
|
94
|
+
| `pi-web-access` | yes | web research tools | `pi install npm:pi-web-access` |
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"plugin": "agent-researcher",
|
|
3
|
+
"prerequisites": [],
|
|
4
|
+
"companions": [
|
|
5
|
+
{
|
|
6
|
+
"package": "pi-subagents",
|
|
7
|
+
"for": "the subagent tool",
|
|
8
|
+
"required": true
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"package": "pi-lens",
|
|
12
|
+
"for": "code-intelligence tools for the subagent",
|
|
13
|
+
"required": true
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"package": "@srobroek/pi-repomix",
|
|
17
|
+
"for": "the repomix_pack tool",
|
|
18
|
+
"required": true
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"package": "pi-web-access",
|
|
22
|
+
"for": "web research tools",
|
|
23
|
+
"required": true
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
package/_kit/prereqs.ts
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
// Generated by harness-kit build. Do not edit.
|
|
2
|
+
import { spawnSync } from "node:child_process"
|
|
3
|
+
import { accessSync, constants, readFileSync, statSync } from "node:fs"
|
|
4
|
+
import { homedir } from "node:os"
|
|
5
|
+
import { delimiter, dirname, isAbsolute, join, resolve } from "node:path"
|
|
6
|
+
import { fileURLToPath } from "node:url"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A pi and OMP extension that checks the external CLIs a plugin declares in its `prerequisites`. harness-kit writes the
|
|
10
|
+
* plugin's list to `_kit/prereqs.json` and vendors this file as `_kit/prereqs.ts`. Both harnesses load it from the
|
|
11
|
+
* package's extension list, because they share the `session_start` event and `ctx.ui.notify`.
|
|
12
|
+
*
|
|
13
|
+
* On `session_start` it looks each `bin` up without a shell: an executable file of that name in the `PATH` directories,
|
|
14
|
+
* after the `node_modules/.bin` directories of the package and its ancestors when the prerequisite names an npm package
|
|
15
|
+
* (`install.npm`). With a `version` range it runs `<bin> --version` (2 s timeout) and compares the first version-looking
|
|
16
|
+
* token of the output. The check runs once per process, and the result is cached.
|
|
17
|
+
*
|
|
18
|
+
* A pi tree's list may also name companions: pi packages the plugin works with, such as the skill packs its prompts
|
|
19
|
+
* refer to. A companion counts as installed when a `packages` entry of pi's settings names it: `npm:<name>[@version]`,
|
|
20
|
+
* or a local directory whose package.json has that name. Both the agent directory's `settings.json`
|
|
21
|
+
* (`$PI_CODING_AGENT_DIR`, default `~/.pi/agent`) and the project's `.pi/settings.json` count.
|
|
22
|
+
*
|
|
23
|
+
* Every tool that is missing, too old, or whose version cannot be read, and every companion that is not installed, goes
|
|
24
|
+
* into one notice. A session with a UI gets it as a warning through `ctx.ui.notify`. Without a UI, one line goes to
|
|
25
|
+
* stderr, at most once per process, and not after a UI notice: in OMP, subagent sessions have no UI and share the
|
|
26
|
+
* process. When nothing is missing, nothing is reported.
|
|
27
|
+
* A gate extension of the plugin fails closed with `missingRequired()` and `prereqMessage(name)`, imported from
|
|
28
|
+
* `../_kit/prereqs.ts`. Both cover required tools and required companions:
|
|
29
|
+
*
|
|
30
|
+
* const missing = missingRequired()
|
|
31
|
+
* if (missing.length > 0) return { block: true, reason: missing.map((bin) => prereqMessage(bin)).join("\n") }
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
export interface Install {
|
|
35
|
+
/** A mise tool, installed with `mise use -g <mise>`. */
|
|
36
|
+
mise?: string
|
|
37
|
+
url?: string
|
|
38
|
+
/** `<name>@<range>`: the npm package that provides the bin. Its `node_modules/.bin` is searched before PATH. */
|
|
39
|
+
npm?: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface Prerequisite {
|
|
43
|
+
bin: string
|
|
44
|
+
/** What the plugin uses the tool for, shown in the notice. */
|
|
45
|
+
for: string
|
|
46
|
+
/** The plugin's gates cannot work without it. */
|
|
47
|
+
required: boolean
|
|
48
|
+
install: Install
|
|
49
|
+
/** A semver range that the version in `<bin> --version` must satisfy. */
|
|
50
|
+
version?: string
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** A pi package the plugin works with, such as a skill pack its prompts refer to. */
|
|
54
|
+
export interface Companion {
|
|
55
|
+
/** The npm package name, scoped or not. */
|
|
56
|
+
package: string
|
|
57
|
+
/** What the plugin uses it for, shown in the notice. */
|
|
58
|
+
for: string
|
|
59
|
+
required: boolean
|
|
60
|
+
/** The range a published package gives it in `peerDependencies`; the check does not compare versions. */
|
|
61
|
+
range?: string
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The contents of `_kit/prereqs.json`. */
|
|
65
|
+
export interface Manifest {
|
|
66
|
+
plugin: string
|
|
67
|
+
prerequisites: Prerequisite[]
|
|
68
|
+
/** Only a pi tree's list has companions. */
|
|
69
|
+
companions?: Companion[]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** An unmet prerequisite: not found, or a version that does not satisfy the range (`found` is absent when unreadable). */
|
|
73
|
+
export interface Finding {
|
|
74
|
+
prerequisite: Prerequisite
|
|
75
|
+
problem: "missing" | "version"
|
|
76
|
+
found?: string
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type Env = Record<string, string | undefined>
|
|
80
|
+
|
|
81
|
+
export interface Deps {
|
|
82
|
+
/** The package tree holding `_kit/prereqs.json`; defaults to the parent of the `_kit` directory. */
|
|
83
|
+
root?: string
|
|
84
|
+
env?: Env
|
|
85
|
+
/** The project whose `.pi/settings.json` counts; defaults to the session's cwd, or the process's. */
|
|
86
|
+
cwd?: string
|
|
87
|
+
/** Writes the notice of a session without a UI; defaults to one line on stderr. */
|
|
88
|
+
stderr?: (line: string) => void
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface Context {
|
|
92
|
+
hasUI: boolean
|
|
93
|
+
cwd?: string
|
|
94
|
+
ui: { notify(message: string, type: "warning"): void }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The slice of the pi and OMP extension API this file uses. */
|
|
98
|
+
interface Api {
|
|
99
|
+
on(event: "session_start", handler: (event: unknown, ctx: Context) => void): void
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
type Version = readonly [number, number, number]
|
|
103
|
+
type Comparator = { op: "<" | "<=" | ">" | ">="; version: Version }
|
|
104
|
+
|
|
105
|
+
const VERSION_TIMEOUT_MS = 2000
|
|
106
|
+
const OPERATOR = /^(<=|>=|<|>|=|\^|~)?v?(.+)$/
|
|
107
|
+
const NUMBER = /^\d+$/
|
|
108
|
+
const WILDCARD = /^[xX*]$/
|
|
109
|
+
const VERSION_TOKEN = /(\d+)\.(\d+)(?:\.(\d+))?/
|
|
110
|
+
/** Matches nothing: no version is below 0.0.0. */
|
|
111
|
+
const NOTHING: Comparator = { op: "<", version: [0, 0, 0] }
|
|
112
|
+
|
|
113
|
+
function compare(a: Version, b: Version): number {
|
|
114
|
+
for (let index = 0; index < 3; index++) if (a[index] !== b[index]) return (a[index] as number) - (b[index] as number)
|
|
115
|
+
return 0
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** The numbers of a partial version (`1`, `1.2`, `1.2.3`, `1.x`, `*`): wildcards end it. Undefined when malformed. */
|
|
119
|
+
function partial(text: string): number[] | undefined {
|
|
120
|
+
const parts = text.split(".")
|
|
121
|
+
if (parts.length > 3 || !parts.every((part) => NUMBER.test(part) || WILDCARD.test(part))) return undefined
|
|
122
|
+
const wild = parts.findIndex((part) => WILDCARD.test(part))
|
|
123
|
+
if (wild === -1) return parts.map(Number)
|
|
124
|
+
return parts.slice(wild).every((part) => WILDCARD.test(part)) ? parts.slice(0, wild).map(Number) : undefined
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** One range item as comparators, with npm's meaning for partial versions, `^` and `~`. */
|
|
128
|
+
function comparators(op: string, numbers: number[]): Comparator[] {
|
|
129
|
+
if (numbers.length === 0) return op === "<" || op === ">" ? [NOTHING] : []
|
|
130
|
+
const [major = 0, minor = 0, patch = 0] = numbers
|
|
131
|
+
const at: Version = [major, minor, patch]
|
|
132
|
+
const exact = numbers.length === 3
|
|
133
|
+
// The first version past the given parts: 1 gives 2.0.0, 1.2 and 1.2.3 give 1.3.0.
|
|
134
|
+
const next: Version = numbers.length === 1 ? [major + 1, 0, 0] : [major, minor + 1, 0]
|
|
135
|
+
switch (op) {
|
|
136
|
+
case ">=":
|
|
137
|
+
return [{ op: ">=", version: at }]
|
|
138
|
+
case ">":
|
|
139
|
+
return [exact ? { op: ">", version: at } : { op: ">=", version: next }]
|
|
140
|
+
case "<":
|
|
141
|
+
return [{ op: "<", version: at }]
|
|
142
|
+
case "<=":
|
|
143
|
+
return [exact ? { op: "<=", version: at } : { op: "<", version: next }]
|
|
144
|
+
case "~":
|
|
145
|
+
return [{ op: ">=", version: at }, { op: "<", version: next }]
|
|
146
|
+
case "^": {
|
|
147
|
+
const upper: Version = major > 0 || numbers.length === 1 ? [major + 1, 0, 0] : minor > 0 || numbers.length === 2 ? [0, minor + 1, 0] : [0, 0, patch + 1]
|
|
148
|
+
return [{ op: ">=", version: at }, { op: "<", version: upper }]
|
|
149
|
+
}
|
|
150
|
+
default:
|
|
151
|
+
return exact ? [{ op: ">=", version: at }, { op: "<=", version: at }] : [{ op: ">=", version: at }, { op: "<", version: next }]
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* A semver range as alternatives (`||`) of comparators that must all hold. Supported: `<`, `<=`, `>`, `>=`, `=`, `^`, `~`,
|
|
157
|
+
* plain and partial versions, and `x`/`*` wildcards. Versions are numbers only. Throws on anything else.
|
|
158
|
+
*/
|
|
159
|
+
export function parseRange(range: string): Comparator[][] {
|
|
160
|
+
return range.split("||").map((alternative) => {
|
|
161
|
+
const items = alternative.trim().replace(/(<=|>=|<|>|=|\^|~)\s+/g, "$1")
|
|
162
|
+
if (!items) throw new Error(`${JSON.stringify(range)} has an empty alternative`)
|
|
163
|
+
return items.split(/\s+/).flatMap((item) => {
|
|
164
|
+
const match = OPERATOR.exec(item)
|
|
165
|
+
const numbers = match ? partial(match[2] as string) : undefined
|
|
166
|
+
if (!match || !numbers) throw new Error(`${JSON.stringify(range)} is not a supported semver range: cannot read "${item}" (use comparators such as >=1.3.0, ^2.1 or ~1.4.2)`)
|
|
167
|
+
return comparators(match[1] ?? "", numbers)
|
|
168
|
+
})
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** The first version-looking token (`1.2` or `1.2.3`) in a command's output, as `x.y.z`. A suffix such as `-rc.1` is ignored. */
|
|
173
|
+
export function versionIn(output: string): string | undefined {
|
|
174
|
+
const match = VERSION_TOKEN.exec(output)
|
|
175
|
+
return match ? `${Number(match[1])}.${Number(match[2])}.${Number(match[3] ?? 0)}` : undefined
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Whether an `x.y.z` version satisfies a range that `parseRange` accepts. */
|
|
179
|
+
export function satisfies(version: string, range: string): boolean {
|
|
180
|
+
const [major = 0, minor = 0, patch = 0] = version.split(".").map(Number)
|
|
181
|
+
const at: Version = [major, minor, patch]
|
|
182
|
+
return parseRange(range).some((alternative) =>
|
|
183
|
+
alternative.every(({ op, version: bound }) => {
|
|
184
|
+
const order = compare(at, bound)
|
|
185
|
+
return op === "<" ? order < 0 : op === "<=" ? order <= 0 : op === ">" ? order > 0 : order >= 0
|
|
186
|
+
}),
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Directories searched for a prerequisite, in order. Relative and empty PATH entries are skipped. */
|
|
191
|
+
export function searchPath(prerequisite: Prerequisite, root: string, env: Env): string[] {
|
|
192
|
+
const dirs: string[] = []
|
|
193
|
+
if (prerequisite.install.npm) {
|
|
194
|
+
for (let dir = root; ; dir = dirname(dir)) {
|
|
195
|
+
dirs.push(join(dir, "node_modules", ".bin"))
|
|
196
|
+
if (dirname(dir) === dir) break
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
dirs.push(...(env.PATH ?? "").split(delimiter).filter((dir) => isAbsolute(dir)))
|
|
200
|
+
return dirs
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** The first executable file named `bin` in `dirs`, like `which`. */
|
|
204
|
+
export function which(bin: string, dirs: readonly string[]): string | undefined {
|
|
205
|
+
for (const dir of dirs) {
|
|
206
|
+
const file = join(dir, bin)
|
|
207
|
+
try {
|
|
208
|
+
if (!statSync(file).isFile()) continue
|
|
209
|
+
accessSync(file, constants.X_OK)
|
|
210
|
+
return file
|
|
211
|
+
} catch {
|
|
212
|
+
// Not here, or not executable: keep looking.
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return undefined
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function readVersion(file: string): string | undefined {
|
|
219
|
+
const run = spawnSync(file, ["--version"], { encoding: "utf8", timeout: VERSION_TIMEOUT_MS, killSignal: "SIGKILL", stdio: ["ignore", "pipe", "pipe"] })
|
|
220
|
+
if (run.error) return undefined
|
|
221
|
+
return versionIn(`${run.stdout ?? ""}\n${run.stderr ?? ""}`)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** The unmet prerequisites of a manifest, in its order. Runs the lookups and version commands on every call. */
|
|
225
|
+
export function check(manifest: Manifest, root: string, env: Env): Finding[] {
|
|
226
|
+
return manifest.prerequisites.flatMap((prerequisite): Finding[] => {
|
|
227
|
+
const file = which(prerequisite.bin, searchPath(prerequisite, root, env))
|
|
228
|
+
if (!file) return [{ prerequisite, problem: "missing" }]
|
|
229
|
+
if (!prerequisite.version) return []
|
|
230
|
+
const found = readVersion(file)
|
|
231
|
+
if (found === undefined) return [{ prerequisite, problem: "version" }]
|
|
232
|
+
return satisfies(found, prerequisite.version) ? [] : [{ prerequisite, problem: "version", found }]
|
|
233
|
+
})
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** The ways to install a tool: `mise use -g` first when the plugin names a mise tool, then npm, then the URL. */
|
|
237
|
+
export function installHint(install: Install): string {
|
|
238
|
+
const ways = [...(install.mise ? [`mise use -g ${install.mise}`] : []), ...(install.npm ? [`npm install -g ${install.npm}`] : []), ...(install.url ? [`see ${install.url}`] : [])]
|
|
239
|
+
return ways.join(", or ")
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** One unmet prerequisite: what it is for, what is wrong, and how to install it. */
|
|
243
|
+
export function describeFinding({ prerequisite, problem, found }: Finding): string {
|
|
244
|
+
const where = prerequisite.install.npm ? "not in node_modules/.bin or on PATH" : "not on PATH"
|
|
245
|
+
const wrong = problem === "missing" ? where : found ? `version ${found} does not satisfy ${prerequisite.version}` : `cannot read its version from \`${prerequisite.bin} --version\` (needs ${prerequisite.version})`
|
|
246
|
+
return `${prerequisite.bin} (${prerequisite.required ? "required, " : ""}for ${prerequisite.for}): ${wrong}; install: ${installHint(prerequisite.install)}`
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const isObject = (value: unknown): value is Record<string, unknown> => typeof value === "object" && value !== null && !Array.isArray(value)
|
|
250
|
+
|
|
251
|
+
/** `npm:<name>` or `npm:<name>@<version>`, scoped or not. */
|
|
252
|
+
const NPM_SOURCE = /^npm:((?:@[^/@\s]+\/)?[^/@\s]+)(?:@.*)?$/
|
|
253
|
+
/** A source with a scheme, such as `git:` or `https:`, which names no package without fetching it. */
|
|
254
|
+
const SCHEME = /^[a-z][a-z0-9+.-]+:/i
|
|
255
|
+
|
|
256
|
+
/** pi's agent directory: `$PI_CODING_AGENT_DIR`, else `~/.pi/agent`. */
|
|
257
|
+
export function piAgentDir(env: Env): string {
|
|
258
|
+
const custom = env.PI_CODING_AGENT_DIR?.trim()
|
|
259
|
+
return custom ? custom : join(env.HOME ?? homedir(), ".pi", "agent")
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function packageNameAt(dir: string): string | undefined {
|
|
263
|
+
try {
|
|
264
|
+
const manifest: unknown = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"))
|
|
265
|
+
return isObject(manifest) && typeof manifest.name === "string" ? manifest.name : undefined
|
|
266
|
+
} catch {
|
|
267
|
+
return undefined
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* The package names a pi settings file installs: each `packages` entry (a string, or an object's `source`) that is
|
|
273
|
+
* `npm:<name>[@version]`, or a local path, relative to the file, whose package.json has a name. A missing or unreadable
|
|
274
|
+
* file installs nothing.
|
|
275
|
+
*/
|
|
276
|
+
export function installedPackages(file: string, env: Env): string[] {
|
|
277
|
+
let settings: unknown
|
|
278
|
+
try {
|
|
279
|
+
settings = JSON.parse(readFileSync(file, "utf8"))
|
|
280
|
+
} catch {
|
|
281
|
+
return []
|
|
282
|
+
}
|
|
283
|
+
const packages = isObject(settings) && Array.isArray(settings.packages) ? settings.packages : []
|
|
284
|
+
return packages.flatMap((entry) => {
|
|
285
|
+
const source = typeof entry === "string" ? entry : isObject(entry) && typeof entry.source === "string" ? entry.source : undefined
|
|
286
|
+
if (!source) return []
|
|
287
|
+
const npm = NPM_SOURCE.exec(source)
|
|
288
|
+
if (npm) return [npm[1] as string]
|
|
289
|
+
if (SCHEME.test(source)) return []
|
|
290
|
+
const local = source.startsWith("~/") ? join(env.HOME ?? homedir(), source.slice(2)) : resolve(dirname(file), source)
|
|
291
|
+
const name = packageNameAt(local)
|
|
292
|
+
return name ? [name] : []
|
|
293
|
+
})
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** The companions of a manifest that neither the agent directory's nor the project's pi settings install. */
|
|
297
|
+
export function missingCompanions(manifest: Manifest, cwd: string, env: Env): Companion[] {
|
|
298
|
+
const companions = manifest.companions ?? []
|
|
299
|
+
if (companions.length === 0) return []
|
|
300
|
+
const settings = [join(piAgentDir(env), "settings.json"), join(cwd, ".pi", "settings.json")]
|
|
301
|
+
const installed = new Set(settings.flatMap((file) => installedPackages(file, env)))
|
|
302
|
+
return companions.filter((companion) => !installed.has(companion.package))
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** One missing companion: what it is for and how to install it. */
|
|
306
|
+
export function describeCompanion(companion: Companion): string {
|
|
307
|
+
return `${companion.package} (${companion.required ? "required, " : ""}for ${companion.for}): not installed; install: pi install npm:${companion.package}`
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const defaultRoot = () => join(dirname(fileURLToPath(import.meta.url)), "..")
|
|
311
|
+
|
|
312
|
+
type Status = { manifest: Manifest; findings: Finding[]; companions: Companion[] }
|
|
313
|
+
|
|
314
|
+
const cache = new Map<string, Status>()
|
|
315
|
+
/** Packages whose notice this process has shown or written. */
|
|
316
|
+
const reported = new Set<string>()
|
|
317
|
+
|
|
318
|
+
/** The manifest, its unmet prerequisites and its missing companions, checked once per package root, PATH, project and agent directory in this process. */
|
|
319
|
+
function status(deps: Deps): Status {
|
|
320
|
+
const root = deps.root ?? defaultRoot()
|
|
321
|
+
const env = deps.env ?? process.env
|
|
322
|
+
const cwd = deps.cwd ?? process.cwd()
|
|
323
|
+
const key = [root, env.PATH ?? "", cwd, piAgentDir(env)].join("\0")
|
|
324
|
+
let entry = cache.get(key)
|
|
325
|
+
if (!entry) {
|
|
326
|
+
const manifest = JSON.parse(readFileSync(join(root, "_kit", "prereqs.json"), "utf8")) as Manifest
|
|
327
|
+
entry = { manifest, findings: check(manifest, root, env), companions: missingCompanions(manifest, cwd, env) }
|
|
328
|
+
cache.set(key, entry)
|
|
329
|
+
}
|
|
330
|
+
return entry
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* The bins of required prerequisites that are missing, too old, or of unreadable version, then the packages of required
|
|
335
|
+
* companions that are not installed. Gates block on a non-empty list.
|
|
336
|
+
*/
|
|
337
|
+
export function missingRequired(deps: Deps = {}): string[] {
|
|
338
|
+
const { findings, companions } = status(deps)
|
|
339
|
+
return [
|
|
340
|
+
...findings.filter((finding) => finding.prerequisite.required).map((finding) => finding.prerequisite.bin),
|
|
341
|
+
...companions.filter((companion) => companion.required).map((companion) => companion.package),
|
|
342
|
+
]
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** The message a gate gives for one declared prerequisite (by bin) or companion (by package): what is wrong and how to install it. */
|
|
346
|
+
export function prereqMessage(name: string, deps: Deps = {}): string {
|
|
347
|
+
const { manifest, findings, companions } = status(deps)
|
|
348
|
+
const finding = findings.find((item) => item.prerequisite.bin === name)
|
|
349
|
+
if (finding) return `${manifest.plugin} needs ${describeFinding(finding)}`
|
|
350
|
+
const companion = companions.find((item) => item.package === name)
|
|
351
|
+
if (companion) return `${manifest.plugin} needs ${describeCompanion(companion)}`
|
|
352
|
+
const declared = manifest.prerequisites.some((item) => item.bin === name) || (manifest.companions ?? []).some((item) => item.package === name)
|
|
353
|
+
if (!declared) throw new Error(`${manifest.plugin} declares no prerequisite or companion "${name}"`)
|
|
354
|
+
return `${manifest.plugin}: ${name} is available`
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export default function prereqsExtension(pi: Api, deps: Deps = {}): void {
|
|
358
|
+
const stderr = deps.stderr ?? ((line: string) => void process.stderr.write(`${line}\n`))
|
|
359
|
+
pi.on("session_start", (_event, ctx) => {
|
|
360
|
+
const { manifest, findings, companions } = status({ ...deps, cwd: deps.cwd ?? ctx.cwd })
|
|
361
|
+
const lines = [...findings.map(describeFinding), ...companions.map(describeCompanion)]
|
|
362
|
+
if (lines.length === 0) return
|
|
363
|
+
const heading = `${manifest.plugin}: prerequisites not met`
|
|
364
|
+
const key = deps.root ?? defaultRoot()
|
|
365
|
+
if (ctx.hasUI) {
|
|
366
|
+
reported.add(key)
|
|
367
|
+
ctx.ui.notify([`${heading}:`, ...lines.map((line) => `- ${line}`)].join("\n"), "warning")
|
|
368
|
+
return
|
|
369
|
+
}
|
|
370
|
+
if (reported.has(key)) return
|
|
371
|
+
reported.add(key)
|
|
372
|
+
stderr(`${heading}: ${lines.join("; ")}`)
|
|
373
|
+
})
|
|
374
|
+
}
|
package/agents/researcher.md
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: researcher
|
|
3
3
|
description: "Answers one scoped research question from code, docs and the web with cited observations and inferences; edits nothing."
|
|
4
|
-
tools: read, grep, find, ls, bash, subagent, web_search, fetch_content, get_search_content, source_check
|
|
4
|
+
tools: read, grep, find, ls, bash, subagent, web_search, fetch_content, get_search_content, source_check, symbol_search, module_report, project_report, read_symbol, read_enclosing, ast_grep_search, ast_grep_outline, lens_diagnostics, pi_lens_activate_tools, repomix_pack, mcp:context7
|
|
5
5
|
allowedAgents: scout
|
|
6
6
|
allowNestedSubagents: true
|
|
7
|
-
subagentOnlyExtensions: npm:pi-web-access
|
|
7
|
+
subagentOnlyExtensions: npm:pi-web-access, npm:pi-lens, npm:@srobroek/pi-repomix
|
|
8
8
|
skills: repomix, quality-code-design, quality-code-policy, quality-testing, quality-test-audit, quality-profiling, lang-go, lang-python, lang-rust, lang-typescript, toolchain-guide, aws-guidance, whats-new
|
|
9
|
+
thinking: medium
|
|
10
|
+
systemPromptMode: replace
|
|
9
11
|
inheritProjectContext: true
|
|
10
|
-
inheritSkills:
|
|
12
|
+
inheritSkills: false
|
|
13
|
+
output: research.md
|
|
11
14
|
---
|
|
12
15
|
|
|
13
16
|
You answer one scoped research question from code, docs, external documentation, or the web. Your brief supplies the question and may name one bead to record it on. You make no product-code edits and do not change the bead graph.
|
|
@@ -15,10 +18,14 @@ You answer one scoped research question from code, docs, external documentation,
|
|
|
15
18
|
## Procedure
|
|
16
19
|
|
|
17
20
|
1. Read the brief and the assigned bead, if any. Use repository evidence before external sources; prefer primary documentation and source.
|
|
18
|
-
2. Inspect the narrowest relevant files first. For a broad codebase lookup, use the `subagent` tool to ask the `scout` agent when the caller authorizes delegation; otherwise do the lookup yourself.
|
|
19
|
-
3. For web research, use `web_search`, `fetch_content`, `get_search_content`, and `source_check`. These tools require the `pi-web-access` package to be installed and loaded in the child. If unavailable, state the evidence limit; do not invent a result.
|
|
21
|
+
2. Inspect the narrowest relevant files first. For a broad codebase lookup, use the `subagent` tool to ask the `scout` agent when the caller authorizes delegation; otherwise do the lookup yourself. When useful, split broader questions into 2-4 bounded research angles and run targeted searches for each rather than one generic search.
|
|
22
|
+
3. For web research, use `web_search`, `fetch_content`, `get_search_content`, and `source_check`. These tools require the `pi-web-access` package to be installed and loaded in the child. If unavailable, state the evidence limit; do not invent a result. Treat search snippets as discovery aids and read the original source for every material claim.
|
|
20
23
|
4. For a broad external repository, use the `repomix` skill and its CLI procedure. If unavailable, state the evidence limit rather than assuming an MCP tool exists.
|
|
21
|
-
5. Separate observations from inferences. Cite every material claim with a path
|
|
24
|
+
5. Separate observations from interpretations and inferences. Cite every material claim with a repository `path:line` or source URL, and label its confidence as high, medium, or low. Report contradictions and missing evidence instead of silently resolving them. Include remaining clarification questions when the task asks for them.
|
|
25
|
+
|
|
26
|
+
Use `mcp:context7` for Context7 documentation; it must be configured as a server named `context7` in `~/.pi/agent/mcp.json`.
|
|
27
|
+
|
|
28
|
+
pi-lens keeps `ast_grep_*` tools inactive until `pi_lens_activate_tools` runs; they are available starting the next turn.
|
|
22
29
|
Pi supplies skills listed in agent frontmatter automatically; do not try to call a skill tool.
|
|
23
30
|
|
|
24
31
|
## Boundaries
|
|
@@ -30,4 +37,28 @@ Pi supplies skills listed in agent frontmatter automatically; do not try to call
|
|
|
30
37
|
|
|
31
38
|
## Output contract
|
|
32
39
|
|
|
33
|
-
Begin with `VERDICT: DONE|BLOCKED`.
|
|
40
|
+
Begin with `VERDICT: DONE|BLOCKED`. End with the existing JSON report fields (`verdict`, `answer`, optional `bead_id`, `uncertainty`, and `notes`). The `answer` string must contain a Markdown report in this structure:
|
|
41
|
+
|
|
42
|
+
```markdown
|
|
43
|
+
# Research: [topic]
|
|
44
|
+
|
|
45
|
+
## Summary
|
|
46
|
+
2-3 sentence direct answer.
|
|
47
|
+
|
|
48
|
+
## Findings
|
|
49
|
+
Numbered material findings. Each gives **Claim**, **Sources**, **Support** (`observation`, `interpretation`, or `inference`), and **Confidence** (`high`, `medium`, or `low`). Cite repository evidence as `path:line` and external evidence with a URL.
|
|
50
|
+
|
|
51
|
+
## Contradictions
|
|
52
|
+
Contradictory or disputed evidence and its sources, or "None found."
|
|
53
|
+
|
|
54
|
+
## Missing evidence
|
|
55
|
+
Unverified claims, unresolved questions, and remaining clarification questions when requested, or "None identified."
|
|
56
|
+
|
|
57
|
+
## Sources
|
|
58
|
+
Kept sources and why they matter; note sources rejected or deprioritized when useful.
|
|
59
|
+
|
|
60
|
+
## Next steps
|
|
61
|
+
Only useful follow-up research, or "None."
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Keep findings concise and record only the requested research. Use `notes` only for relevant information no other field carries, under 80 words.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@srobroek/pi-agent-researcher",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "The researcher subagent: answers one scoped question from code, docs and the web with cited observations and inferences, and records it on a bead when given one.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package"
|
|
@@ -15,14 +15,37 @@
|
|
|
15
15
|
"CHANGELOG.md",
|
|
16
16
|
"LICENSE",
|
|
17
17
|
"README.md",
|
|
18
|
+
"_kit",
|
|
18
19
|
"agents"
|
|
19
20
|
],
|
|
20
21
|
"publishConfig": {
|
|
21
22
|
"access": "public",
|
|
22
23
|
"provenance": true
|
|
23
24
|
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@srobroek/pi-repomix": "*",
|
|
27
|
+
"pi-lens": "*",
|
|
28
|
+
"pi-subagents": "*",
|
|
29
|
+
"pi-web-access": "*"
|
|
30
|
+
},
|
|
31
|
+
"peerDependenciesMeta": {
|
|
32
|
+
"@srobroek/pi-repomix": {
|
|
33
|
+
"optional": true
|
|
34
|
+
},
|
|
35
|
+
"pi-lens": {
|
|
36
|
+
"optional": true
|
|
37
|
+
},
|
|
38
|
+
"pi-subagents": {
|
|
39
|
+
"optional": true
|
|
40
|
+
},
|
|
41
|
+
"pi-web-access": {
|
|
42
|
+
"optional": true
|
|
43
|
+
}
|
|
44
|
+
},
|
|
24
45
|
"pi": {
|
|
25
|
-
"extensions": [
|
|
46
|
+
"extensions": [
|
|
47
|
+
"./_kit/prereqs.ts"
|
|
48
|
+
],
|
|
26
49
|
"subagents": {
|
|
27
50
|
"agents": [
|
|
28
51
|
"./agents"
|