@fradser/pi-context 0.5.0 → 0.5.1
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/README.md +42 -138
- package/agents/context-researcher.md +3 -3
- package/extensions/context-command.ts +121 -0
- package/extensions/context-tools.ts +3 -1
- package/index.ts +8 -0
- package/package.json +5 -7
- package/references/workflow.md +108 -0
- package/skills/code-context/SKILL.md +0 -127
- package/skills/get-context/SKILL.md +0 -38
package/README.md
CHANGED
|
@@ -1,16 +1,32 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Context Pi Package
|
|
2
2
|
|
|
3
|
-
**Version:** 0.
|
|
3
|
+
**Version:** 0.5.0
|
|
4
4
|
|
|
5
5
|
Retrieve code context for any repo, library, or natural-language query via 5 methods: DeepWiki, Context7, Exa, git clone, and web search+fetch.
|
|
6
6
|
|
|
7
|
+
The package does **not** ship a skill. Native tool guidance is injected into the system prompt, and the `/context` command loads the full workflow into the current turn.
|
|
8
|
+
|
|
7
9
|
## Installation
|
|
8
10
|
|
|
9
11
|
```bash
|
|
10
|
-
pi install /
|
|
12
|
+
pi install npm:@fradser/pi-context
|
|
13
|
+
# or from this repository:
|
|
14
|
+
pi install /path/to/pi-packages/packages/context
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Run `/context` followed by a natural-language question, repository slug, library name, or several targets. For example:
|
|
20
|
+
|
|
21
|
+
```text
|
|
22
|
+
/context React 19 server actions error handling
|
|
23
|
+
/context facebook/react
|
|
24
|
+
/context facebook/react zustand --method=deepwiki,context7
|
|
11
25
|
```
|
|
12
26
|
|
|
13
|
-
|
|
27
|
+
`--method=` accepts `deepwiki,context7,exa,clone,web,all` (comma-separated). With no target, the command reads dependency manifests in the current directory (`package.json`, `pyproject.toml`, `go.mod`, `Cargo.toml`) and uses detected dependencies as targets.
|
|
28
|
+
|
|
29
|
+
The full workflow (target classification, per-method process, fallbacks, selection guide) lives in `references/workflow.md` and is injected into the turn when `/context` runs. Lightweight tool-selection guidance is always present in the system prompt.
|
|
14
30
|
|
|
15
31
|
## Runtime requirements
|
|
16
32
|
|
|
@@ -22,161 +38,49 @@ Run `/skill:get-context <query…>` for the executable Pi workflow.
|
|
|
22
38
|
| Git clone | Always | Pi `bash` + `read` |
|
|
23
39
|
| Web fetch | Always | `curl`/HTTP via `bash` |
|
|
24
40
|
|
|
25
|
-
All three retrieval tools are registered by this package's extension (`
|
|
26
|
-
|
|
27
|
-
## Overview
|
|
28
|
-
|
|
29
|
-
Code Context accepts **arbitrary input** — a natural-language question, a repo slug, a library name, or several of these at once — and routes each target to the right method(s). It prefers intermediate summaries so the main conversation stays clean, returning only synthesized summaries.
|
|
30
|
-
|
|
31
|
-
## Methods
|
|
32
|
-
|
|
33
|
-
### 1. DeepWiki (AI-powered repo documentation)
|
|
34
|
-
|
|
35
|
-
Best for: Public GitHub repositories requiring architecture overview, component explanations, or high-level understanding.
|
|
36
|
-
|
|
37
|
-
**Tool:** `context_deepwiki` — `owner`/`repo` + `mode: structure | contents | ask`
|
|
38
|
-
|
|
39
|
-
**Process:**
|
|
40
|
-
1. `context_deepwiki` with `mode: "structure"` (e.g. owner=`facebook`, repo=`react`)
|
|
41
|
-
2. `context_deepwiki` with `mode: "contents"` for full wiki text, or `mode: "ask"` + `question` for targeted Q&A
|
|
42
|
-
|
|
43
|
-
**Strengths:** Zero setup, instant AI-summarized documentation.
|
|
44
|
-
|
|
45
|
-
**Limitations:** Only works for public GitHub repos; coverage varies by popularity.
|
|
46
|
-
|
|
47
|
-
---
|
|
48
|
-
|
|
49
|
-
### 2. Context7 (library documentation)
|
|
50
|
-
|
|
51
|
-
Best for: Getting up-to-date API docs, usage examples, and version-specific documentation for npm/pip packages.
|
|
52
|
-
|
|
53
|
-
**Tool:** `context_context7` — `query` + optional `topic`
|
|
54
|
-
|
|
55
|
-
**Process:**
|
|
56
|
-
1. `context_context7` with the library name (e.g. `"react"`, `"fastapi"`)
|
|
57
|
-
2. Pass a `topic` (e.g. `"auth"`, `"ssr"`) for focused snippets; include the version in the query when given (`react@18`)
|
|
58
|
-
|
|
59
|
-
**Strengths:** Always current docs, supports version pinning, covers thousands of libraries.
|
|
60
|
-
|
|
61
|
-
**Limitations:** Requires the library to be indexed; less useful for internal packages.
|
|
62
|
-
|
|
63
|
-
---
|
|
64
|
-
|
|
65
|
-
### 3. Exa Code Search (web-wide code examples)
|
|
66
|
-
|
|
67
|
-
Best for: Finding real-world usage patterns, StackOverflow answers, GitHub Gist examples.
|
|
68
|
-
|
|
69
|
-
**Tool:** `context_exa` — `query` + optional `numResults` (requires `EXA_API_KEY`)
|
|
70
|
-
|
|
71
|
-
**Query tips:**
|
|
72
|
-
- Include language: `"TypeScript React"`
|
|
73
|
-
- Include version: `"Next.js 14 app router"`
|
|
74
|
-
- Use exact identifiers: `"useServerAction"`
|
|
75
|
-
- Add pattern type: `"example"`, `"error handling"`
|
|
76
|
-
|
|
77
|
-
**Strengths:** Finds diverse real-world examples beyond official docs.
|
|
78
|
-
|
|
79
|
-
**Limitations:** Results may be outdated; verify publication dates.
|
|
80
|
-
|
|
81
|
-
---
|
|
82
|
-
|
|
83
|
-
### 4. Git Clone (direct code inspection)
|
|
84
|
-
|
|
85
|
-
Best for: Private repositories, detailed implementation review, or when other methods lack depth.
|
|
86
|
-
|
|
87
|
-
**Process:**
|
|
88
|
-
1. `git clone <repo-url> /tmp/<repo-name> --depth=1`
|
|
89
|
-
2. Read key files: entry points, configuration, core modules
|
|
90
|
-
3. Use bash find/grep and Pi `read` to analyze structure and patterns
|
|
91
|
-
4. Clean up: `rm -rf /tmp/<repo-name>`
|
|
92
|
-
|
|
93
|
-
**Strengths:** Full code access, works with private repos.
|
|
94
|
-
|
|
95
|
-
**Limitations:** Requires network/disk space; slow for large repos.
|
|
96
|
-
|
|
97
|
-
---
|
|
98
|
-
|
|
99
|
-
### 5. Web Search + Fetch (post-clone enrichment)
|
|
100
|
-
|
|
101
|
-
Best for: Enriching clone findings with changelogs, issue discussions, migration guides.
|
|
102
|
-
|
|
103
|
-
**Tools:** web search via `curl`/HTTP, HTTP fetch via `curl`
|
|
104
|
-
|
|
105
|
-
**When to use:** After completing Method 4. Gives you the *why* and *what changed*.
|
|
106
|
-
|
|
107
|
-
**Query patterns:**
|
|
108
|
-
- Changelogs: `"<repo> CHANGELOG v<version>"`
|
|
109
|
-
- Design rationale: `"<repo> <concept> why OR rationale site:github.com"`
|
|
110
|
-
- Migration: `"<repo> migrate from <old> to <new>"`
|
|
111
|
-
|
|
112
|
-
**Strengths:** Surfaces context never in source code.
|
|
113
|
-
|
|
114
|
-
**Limitations:** Results may be stale; always validate against actual code.
|
|
115
|
-
|
|
116
|
-
---
|
|
117
|
-
|
|
118
|
-
## Usage
|
|
119
|
-
|
|
120
|
-
### Pi skill: get-context
|
|
121
|
-
|
|
122
|
-
Run `/skill:get-context` followed by a natural-language question, repository slug, library name, or several targets. For example:
|
|
123
|
-
|
|
124
|
-
```text
|
|
125
|
-
/skill:get-context React 19 server actions error handling
|
|
126
|
-
/skill:get-context facebook/react
|
|
127
|
-
/skill:get-context facebook/react zustand --method=deepwiki,context7
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
`--method=` accepts `deepwiki,context7,exa,clone,web,all` (comma-separated). With no target, the skill reads dependency manifests in the current directory. It classifies each target and routes it through the allowed methods, noting gaps when a permitted method cannot cover it.
|
|
41
|
+
All three retrieval tools are registered by this package's root extension entry (`index.ts`) and call the public REST APIs directly — no MCP servers needed.
|
|
131
42
|
|
|
132
|
-
|
|
43
|
+
## Methods (summary)
|
|
133
44
|
|
|
134
|
-
|
|
45
|
+
1. **DeepWiki** — AI-generated repo docs via `context_deepwiki` (`mode: structure | contents | ask`).
|
|
46
|
+
2. **Context7** — up-to-date library docs via `context_context7` (`query` + optional `topic`).
|
|
47
|
+
3. **Exa** — web/code search via `context_exa` (`query` + optional `numResults`, requires `EXA_API_KEY`).
|
|
48
|
+
4. **Git clone** — `git clone --depth=1` to `/tmp`, `read` key files, clean up.
|
|
49
|
+
5. **Web search+fetch** — `bash` + `curl` against official docs, GitHub issues, changelogs.
|
|
135
50
|
|
|
136
|
-
|
|
51
|
+
If a native tool is unavailable or errors, fall back to clone/web. The `/context` workflow reference contains the full selection matrix and per-method process.
|
|
137
52
|
|
|
138
|
-
##
|
|
53
|
+
## Optional manual brief
|
|
139
54
|
|
|
140
|
-
|
|
141
|
-
|----------|---------|----------|
|
|
142
|
-
| "How does X library work?" | Context7 | DeepWiki |
|
|
143
|
-
| "Understand Y repo architecture" | DeepWiki | Git Clone |
|
|
144
|
-
| "Find examples of Z pattern" | Exa | Context7 |
|
|
145
|
-
| "Inspect private/internal repo" | Git Clone | - |
|
|
146
|
-
| "What changed in v3?" | Context7 | Exa |
|
|
147
|
-
| "How are modules connected?" | DeepWiki | Git Clone |
|
|
148
|
-
| "Why was this design decision?" | Git Clone → Web Search | DeepWiki |
|
|
149
|
-
| "Compare X vs Y" (natural-language) | Exa + Context7 | Web Search |
|
|
150
|
-
| "Best practice for Z" (natural-language) | Web Search | Exa |
|
|
55
|
+
`agents/context-researcher.md` is an optional manual prompt brief for an isolated research pass. Pi does not load it as an invocable agent; use the `/context` command for the executable workflow.
|
|
151
56
|
|
|
152
57
|
## Structure
|
|
153
58
|
|
|
154
59
|
```
|
|
155
|
-
|
|
60
|
+
context/
|
|
61
|
+
├── index.ts # Package-root extension entry point
|
|
156
62
|
├── extensions/
|
|
157
|
-
│
|
|
63
|
+
│ ├── context-tools.ts # Native pi tools: context_deepwiki / context_context7 / context_exa
|
|
64
|
+
│ └── context-command.ts # /context command + system-prompt guidance
|
|
65
|
+
├── references/
|
|
66
|
+
│ └── workflow.md # Full workflow injected by /context
|
|
158
67
|
├── agents/
|
|
159
|
-
│ └── context-researcher.md # Isolated research
|
|
160
|
-
├── skills/
|
|
161
|
-
│ ├── code-context/ # Knowledge skill (internal)
|
|
162
|
-
│ │ └── SKILL.md # Method selection guide
|
|
163
|
-
│ └── get-context/ # User-invocable command
|
|
164
|
-
│ └── SKILL.md # Command workflow
|
|
68
|
+
│ └── context-researcher.md # Isolated research brief (manual)
|
|
165
69
|
└── README.md
|
|
166
70
|
```
|
|
167
71
|
|
|
168
72
|
## Prerequisites
|
|
169
73
|
|
|
170
|
-
- Pi
|
|
74
|
+
- Pi with extensions + custom tools
|
|
171
75
|
- Network access for external lookups
|
|
172
76
|
- `EXA_API_KEY` for the Exa method (optional for the other four)
|
|
173
77
|
|
|
174
78
|
## Best Practices
|
|
175
79
|
|
|
176
|
-
- **Local first**:
|
|
177
|
-
- **
|
|
178
|
-
- **
|
|
179
|
-
- **
|
|
80
|
+
- **Local first**: check local context (package.json, imports) before external lookups.
|
|
81
|
+
- **Combine methods**: DeepWiki / clone for architecture, Context7 for API surface, Exa / web for community patterns.
|
|
82
|
+
- **Verify sources**: cross-reference fetched content against actual code.
|
|
83
|
+
- **Clean up**: remove `/tmp` clones when finished.
|
|
180
84
|
|
|
181
85
|
## License
|
|
182
86
|
|
|
@@ -5,7 +5,7 @@ description: Research a library, repository, or code pattern without polluting t
|
|
|
5
5
|
|
|
6
6
|
# Context researcher (optional agent brief)
|
|
7
7
|
|
|
8
|
-
Pi does not load Claude Code agent files automatically. Treat this file as a **prompt brief** when you want an isolated research pass. Prefer `/
|
|
8
|
+
Pi does not load Claude Code agent files automatically. Treat this file as a **prompt brief** when you want an isolated research pass. Prefer the `/context` command for the executable workflow.
|
|
9
9
|
|
|
10
10
|
## Runtime requirements
|
|
11
11
|
|
|
@@ -21,9 +21,9 @@ If a native context tool is unavailable or fails, skip that method, use clone +
|
|
|
21
21
|
|
|
22
22
|
## Process
|
|
23
23
|
|
|
24
|
-
1. **Parse the request** — targets and optional `--method=` list (see `/
|
|
24
|
+
1. **Parse the request** — targets and optional `--method=` list (see `/context`).
|
|
25
25
|
2. **Classify** each target (repo / library / natural-language).
|
|
26
|
-
3. **Select methods** per `/
|
|
26
|
+
3. **Select methods** per the `/context` workflow's selection guide.
|
|
27
27
|
4. **Execute with Pi tools** — use the applicable native context tools (`context_deepwiki`, `context_context7`, `context_exa`) plus `bash` and `read`. Summarize intermediates; do not dump raw payloads.
|
|
28
28
|
5. **Return** a concise architecture/API/examples summary only.
|
|
29
29
|
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
|
|
6
|
+
const PKG_DIR =
|
|
7
|
+
typeof __dirname === "string"
|
|
8
|
+
? __dirname
|
|
9
|
+
: dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
|
|
11
|
+
const WORKFLOW_PATH = join(PKG_DIR, "..", "references", "workflow.md");
|
|
12
|
+
|
|
13
|
+
const METHOD_FLAG = "--method=";
|
|
14
|
+
const ALL_METHODS = ["deepwiki", "context7", "exa", "clone", "web", "all"] as const;
|
|
15
|
+
const MANIFEST_FILES = ["package.json", "pyproject.toml", "go.mod", "Cargo.toml"];
|
|
16
|
+
|
|
17
|
+
const CONTEXT_GUIDANCE = `
|
|
18
|
+
## Context retrieval
|
|
19
|
+
|
|
20
|
+
- Use \`context_deepwiki\` for public GitHub repo architecture and DeepWiki Q&A.
|
|
21
|
+
- Use \`context_context7\` for up-to-date library/API docs (optionally focused by topic).
|
|
22
|
+
- Use \`context_exa\` for web/code search when EXA_API_KEY is set; otherwise fall back to \`bash\` + \`curl\`.
|
|
23
|
+
- Use \`git clone --depth=1\` to /tmp plus \`read\`/\`bash\` for private repos or deep inspection; always clean up.
|
|
24
|
+
- Prefer small intermediate summaries over dumping raw API payloads into the conversation.
|
|
25
|
+
- The \`/context <targets...> [--method=...]\` command loads the full workflow when the user asks to research or understand code.
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
interface ParsedArgs {
|
|
29
|
+
targets: string[];
|
|
30
|
+
methods: string[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function parseArgs(raw: string): ParsedArgs {
|
|
34
|
+
const targets: string[] = [];
|
|
35
|
+
let methods: string[] = ["all"];
|
|
36
|
+
const tokens = raw.match(/(?:[^\s"]+|"[^"]*")+/g) ?? [];
|
|
37
|
+
for (const token of tokens) {
|
|
38
|
+
if (token.startsWith(METHOD_FLAG)) {
|
|
39
|
+
methods = token
|
|
40
|
+
.slice(METHOD_FLAG.length)
|
|
41
|
+
.split(",")
|
|
42
|
+
.map((m) => m.trim().toLowerCase())
|
|
43
|
+
.filter((m) => (ALL_METHODS as readonly string[]).includes(m));
|
|
44
|
+
if (methods.length === 0) methods = ["all"];
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
targets.push(token.replace(/^"|"$/g, ""));
|
|
48
|
+
}
|
|
49
|
+
return { targets, methods };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function detectDependencies(cwd: string): string[] {
|
|
53
|
+
const deps = new Set<string>();
|
|
54
|
+
for (const file of MANIFEST_FILES) {
|
|
55
|
+
try {
|
|
56
|
+
const text = readFileSync(join(cwd, file), "utf8");
|
|
57
|
+
if (file === "package.json") {
|
|
58
|
+
const json = JSON.parse(text) as {
|
|
59
|
+
dependencies?: Record<string, string>;
|
|
60
|
+
devDependencies?: Record<string, string>;
|
|
61
|
+
};
|
|
62
|
+
for (const name of Object.keys(json.dependencies ?? {})) deps.add(name);
|
|
63
|
+
for (const name of Object.keys(json.devDependencies ?? {})) deps.add(name);
|
|
64
|
+
} else if (file === "pyproject.toml") {
|
|
65
|
+
for (const match of text.matchAll(/^\s*"([A-Za-z0-9_.-]+)"\s*[>=<~!]/gm)) {
|
|
66
|
+
deps.add(match[1]);
|
|
67
|
+
}
|
|
68
|
+
} else if (file === "go.mod") {
|
|
69
|
+
for (const match of text.matchAll(/^\s*([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+)\s+v/gm)) {
|
|
70
|
+
deps.add(match[1]);
|
|
71
|
+
}
|
|
72
|
+
} else if (file === "Cargo.toml") {
|
|
73
|
+
for (const match of text.matchAll(/^([A-Za-z0-9_-]+)\s*=\s*"[^"]+"/gm)) {
|
|
74
|
+
deps.add(match[1]);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
} catch {
|
|
78
|
+
// Missing or unreadable manifest — skip.
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return [...deps];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function loadWorkflow(): string {
|
|
85
|
+
return readFileSync(WORKFLOW_PATH, "utf8");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function buildUserPrompt(args: ParsedArgs, cwd: string): string {
|
|
89
|
+
const workflow = loadWorkflow();
|
|
90
|
+
const targets = args.targets.length > 0 ? args.targets : detectDependencies(cwd);
|
|
91
|
+
const header = [
|
|
92
|
+
"Run the /context workflow.",
|
|
93
|
+
"",
|
|
94
|
+
`Targets: ${targets.length > 0 ? targets.join(", ") : "(none provided and no dependencies detected in cwd)"}`,
|
|
95
|
+
`Allowed methods: ${args.methods.join(",")}`,
|
|
96
|
+
"",
|
|
97
|
+
"---",
|
|
98
|
+
"",
|
|
99
|
+
].join("\n");
|
|
100
|
+
return header + workflow;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function registerContextCommand(pi: ExtensionAPI): void {
|
|
104
|
+
pi.on("before_agent_start", async (event) => ({
|
|
105
|
+
systemPrompt: event.systemPrompt + CONTEXT_GUIDANCE,
|
|
106
|
+
}));
|
|
107
|
+
|
|
108
|
+
pi.registerCommand("context", {
|
|
109
|
+
description:
|
|
110
|
+
"Retrieve code context for repos, libraries, or a natural-language question via DeepWiki, Context7, Exa, clone, or web.",
|
|
111
|
+
handler: async (rawArgs, ctx) => {
|
|
112
|
+
const args = parseArgs(rawArgs.trim());
|
|
113
|
+
const prompt = buildUserPrompt(args, ctx.cwd);
|
|
114
|
+
pi.sendUserMessage(prompt, { deliverAs: "followUp" });
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export default function register(pi: ExtensionAPI): void {
|
|
120
|
+
registerContextCommand(pi);
|
|
121
|
+
}
|
|
@@ -122,7 +122,7 @@ const ExaParams = Type.Object({
|
|
|
122
122
|
),
|
|
123
123
|
});
|
|
124
124
|
|
|
125
|
-
export
|
|
125
|
+
export function registerContextTools(pi: ExtensionAPI): void {
|
|
126
126
|
pi.registerTool({
|
|
127
127
|
name: "context_deepwiki",
|
|
128
128
|
label: "DeepWiki repo docs",
|
|
@@ -273,3 +273,5 @@ export default function (pi: ExtensionAPI) {
|
|
|
273
273
|
},
|
|
274
274
|
});
|
|
275
275
|
}
|
|
276
|
+
|
|
277
|
+
export default registerContextTools;
|
package/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import registerContextCommand from "./extensions/context-command.ts";
|
|
3
|
+
import registerContextTools from "./extensions/context-tools.ts";
|
|
4
|
+
|
|
5
|
+
export default function contextExtension(pi: ExtensionAPI): void {
|
|
6
|
+
registerContextTools(pi);
|
|
7
|
+
registerContextCommand(pi);
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fradser/pi-context",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Retrieve code context for any repo, library, or natural-language query via DeepWiki, Context7, Exa, git clone, and web search+fetch. Native pi tools (context_deepwiki/context_context7/context_exa) call the public REST APIs directly — no MCP servers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -19,17 +19,15 @@
|
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
|
-
"
|
|
22
|
+
"index.ts",
|
|
23
23
|
"extensions",
|
|
24
|
+
"references",
|
|
24
25
|
"agents",
|
|
25
26
|
"README.md"
|
|
26
27
|
],
|
|
27
28
|
"pi": {
|
|
28
|
-
"skills": [
|
|
29
|
-
"./skills"
|
|
30
|
-
],
|
|
31
29
|
"extensions": [
|
|
32
|
-
"./
|
|
30
|
+
"./index.ts"
|
|
33
31
|
]
|
|
34
32
|
},
|
|
35
33
|
"peerDependencies": {
|
|
@@ -37,4 +35,4 @@
|
|
|
37
35
|
"@earendil-works/pi-ai": "*",
|
|
38
36
|
"typebox": "*"
|
|
39
37
|
}
|
|
40
|
-
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# context workflow
|
|
2
|
+
|
|
3
|
+
Retrieve code context for any repo, library, or natural-language code/technology question. Five methods are available; pick them per target. Prefer small intermediate summaries over dumping raw API payloads into the long-lived conversation.
|
|
4
|
+
|
|
5
|
+
## Native tools
|
|
6
|
+
|
|
7
|
+
| Method | Tool | Availability |
|
|
8
|
+
|--------|------|--------------|
|
|
9
|
+
| DeepWiki | `context_deepwiki` | always, no key |
|
|
10
|
+
| Context7 | `context_context7` | always, optional `CONTEXT7_API_KEY` for higher quota |
|
|
11
|
+
| Exa | `context_exa` | requires `EXA_API_KEY` |
|
|
12
|
+
| Git clone | `bash` + `read` | always |
|
|
13
|
+
| Web search+fetch | `bash` + `curl` | always |
|
|
14
|
+
|
|
15
|
+
If a native tool is unavailable or errors (e.g. `EXA_API_KEY` unset), skip it and use the documented clone/web fallback. Report which methods ran. There are no Pi built-ins named `WebSearch`/`WebFetch`/`Task` — do not invent them.
|
|
16
|
+
|
|
17
|
+
## Invocation
|
|
18
|
+
|
|
19
|
+
`/context [targets...] [--method=a,b,...]`
|
|
20
|
+
|
|
21
|
+
- `--method=` accepts a comma-separated list from `deepwiki,context7,exa,clone,web,all`. Default: `all`.
|
|
22
|
+
- Quoted strings are one target. Multiple positional tokens are multiple targets.
|
|
23
|
+
- No targets: read dependency manifests in cwd (`package.json`, `go.mod`, `pyproject.toml`, `Cargo.toml`) and use detected dependencies as targets.
|
|
24
|
+
|
|
25
|
+
Classify each target:
|
|
26
|
+
|
|
27
|
+
- GitHub slug (`owner/repo`) or git URL → repo — DeepWiki (`context_deepwiki`), else clone.
|
|
28
|
+
- Bare package name or `name@version` → library — Context7 (`context_context7`), else web + clone of docs repo when known.
|
|
29
|
+
- Anything else → natural-language — Exa (`context_exa`) when `EXA_API_KEY` is set, else web search via `curl`.
|
|
30
|
+
|
|
31
|
+
When `--method=` is passed, use the intersection of allowed and applicable methods. Empty intersection → skip and report.
|
|
32
|
+
|
|
33
|
+
## Method 1: DeepWiki
|
|
34
|
+
|
|
35
|
+
Best for: public GitHub repos needing an architecture overview quickly.
|
|
36
|
+
|
|
37
|
+
1. `context_deepwiki` with `owner`/`repo` and `mode: "structure"` (e.g. `facebook` / `react`).
|
|
38
|
+
2. `mode: "contents"` for the full wiki text, or `mode: "ask"` with `question` for targeted Q&A.
|
|
39
|
+
3. Extract architecture summary and key relationships.
|
|
40
|
+
|
|
41
|
+
Token isolation: structure → relevant pages → short architecture summary.
|
|
42
|
+
Fallback on error: Method 4 (clone) + Method 5 (web) on GitHub docs/README.
|
|
43
|
+
|
|
44
|
+
## Method 2: Context7
|
|
45
|
+
|
|
46
|
+
Best for: up-to-date API docs and version-specific examples for packages/frameworks.
|
|
47
|
+
|
|
48
|
+
1. `context_context7` with the library name as `query` (e.g. `fastapi`, `react`).
|
|
49
|
+
2. Pass a `topic` (e.g. `auth`, `ssr`) for focused snippets; include the version in the query when given (`react@18`).
|
|
50
|
+
3. Extract the minimum viable API surface + examples.
|
|
51
|
+
|
|
52
|
+
Token isolation: resolve id → query → minimum viable API surface + examples.
|
|
53
|
+
Fallback on error: official docs URLs via `curl`, or clone of the library repo docs.
|
|
54
|
+
|
|
55
|
+
## Method 3: Exa
|
|
56
|
+
|
|
57
|
+
Best for: real-world usage patterns and cross-web code examples.
|
|
58
|
+
|
|
59
|
+
1. Call with a precise query (language/framework/version/identifiers).
|
|
60
|
+
2. Prefer recent sources; dedupe near-identical snippets and mirrors.
|
|
61
|
+
3. Return a short explanation with sources.
|
|
62
|
+
|
|
63
|
+
Fallback when key missing / error: GitHub code search URLs / known docs via `curl`, or clone representative examples.
|
|
64
|
+
|
|
65
|
+
## Method 4: Git clone
|
|
66
|
+
|
|
67
|
+
Best for: private repos, deep implementation review, when other methods lack depth.
|
|
68
|
+
|
|
69
|
+
1. `git clone <repo-url> /tmp/<repo-name> --depth=1`
|
|
70
|
+
2. `read` key files: entry points, config, core modules.
|
|
71
|
+
3. Map structure with `bash` find/ls; search with `bash` grep.
|
|
72
|
+
4. Cleanup: `rm -rf /tmp/<repo-name>`.
|
|
73
|
+
|
|
74
|
+
## Method 5: Web search + fetch
|
|
75
|
+
|
|
76
|
+
Best for: rationale, changelogs, issues, migration guides.
|
|
77
|
+
|
|
78
|
+
1. Derive version-anchored queries from the question or clone findings.
|
|
79
|
+
2. Fetch high-signal URLs (official docs, GitHub issues/PRs, changelogs).
|
|
80
|
+
3. Extract only relevant sections; cross-check against cloned code when available.
|
|
81
|
+
4. Discard results older than ~2 years unless foundational.
|
|
82
|
+
|
|
83
|
+
Query patterns:
|
|
84
|
+
- Changelogs: `"<repo> CHANGELOG v<version>"`
|
|
85
|
+
- Rationale: `"<repo> <concept> why OR rationale site:github.com"`
|
|
86
|
+
- Known issues: `"<repo> <symbol> issue OR bug site:github.com"`
|
|
87
|
+
- Migration: `"<repo> migrate from <old> to <new>"`
|
|
88
|
+
|
|
89
|
+
## Method selection guide
|
|
90
|
+
|
|
91
|
+
| Scenario | Primary | Fallback |
|
|
92
|
+
|----------|---------|----------|
|
|
93
|
+
| "How does X library work?" | Context7 | Web / clone |
|
|
94
|
+
| "Architecture of Y repo" | DeepWiki | Git clone |
|
|
95
|
+
| "Examples of Z pattern" | Exa | Context7 / web |
|
|
96
|
+
| "Private/internal repo" | Git clone | — |
|
|
97
|
+
| "What changed in v3?" | Context7 | Web |
|
|
98
|
+
| "Why this design?" | Git clone → web | DeepWiki |
|
|
99
|
+
| "Compare X vs Y" | Exa + Context7 | Web |
|
|
100
|
+
| "Best practice for Z" | Web | Exa |
|
|
101
|
+
|
|
102
|
+
## Combining methods
|
|
103
|
+
|
|
104
|
+
1. DeepWiki / clone for architecture.
|
|
105
|
+
2. Context7 for API surface.
|
|
106
|
+
3. Exa / web for community patterns.
|
|
107
|
+
4. Always prefer read-only operations; clean up `/tmp` clones.
|
|
108
|
+
5. Return a synthesized summary only — drop raw bulk payloads.
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: code-context
|
|
3
|
-
description: This skill should be used when the user asks to "understand a codebase", "get code context", "research a library", "explore a repository", "find code examples", "look up documentation", asks a natural-language code/technology question (e.g. "how does X work", "X vs Y", "best practice for Z"), or wants to understand how a specific project, library, or concept works before making changes.
|
|
4
|
-
disable-model-invocation: true
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Code Context Retrieval
|
|
8
|
-
|
|
9
|
-
This skill provides 5 methods for retrieving code context. Select methods based on the target: public GitHub repos, library docs, code search, direct inspection, or post-clone web enrichment.
|
|
10
|
-
|
|
11
|
-
## Pi tools and runtime
|
|
12
|
-
|
|
13
|
-
Use Pi built-ins: `bash`, `read`, `edit` (rarely), `write` (rarely), plus this package's native tools from `extensions/context-tools.ts`.
|
|
14
|
-
|
|
15
|
-
| Method | Runtime |
|
|
16
|
-
|--------|---------|
|
|
17
|
-
| DeepWiki | `context_deepwiki` tool (always available; no key) |
|
|
18
|
-
| Context7 | `context_context7` tool (always available; optional `CONTEXT7_API_KEY` for higher quota) |
|
|
19
|
-
| Exa | `context_exa` tool (requires `EXA_API_KEY` env) |
|
|
20
|
-
| Git clone | `bash` + `read` (always available) |
|
|
21
|
-
| Web search+fetch | `bash` + `curl` (or host HTTP) |
|
|
22
|
-
|
|
23
|
-
If a tool reports an error (e.g. `EXA_API_KEY` unset), skip it and use clone/web fallbacks. Report which methods ran.
|
|
24
|
-
|
|
25
|
-
## Token Isolation (Critical)
|
|
26
|
-
|
|
27
|
-
Prefer small intermediate summaries over dumping entire API payloads into the long-lived conversation:
|
|
28
|
-
|
|
29
|
-
- **DeepWiki**: structure → relevant pages → short architecture summary
|
|
30
|
-
- **Context7**: resolve id → query → minimum viable API surface + examples
|
|
31
|
-
- **Exa**: query → dedupe near-identical snippets → short explanation
|
|
32
|
-
- **Git clone**: clone to `/tmp/`, read entry points, cleanup, return structure + patterns
|
|
33
|
-
- **Web**: targeted queries, fetch high-signal URLs only, validate against code when possible
|
|
34
|
-
|
|
35
|
-
## Method 1: DeepWiki (AI-powered repo documentation)
|
|
36
|
-
|
|
37
|
-
Best for: public GitHub repos needing architecture overview quickly.
|
|
38
|
-
|
|
39
|
-
**Tool**: `context_deepwiki` (native, always available)
|
|
40
|
-
|
|
41
|
-
**Process**:
|
|
42
|
-
1. `context_deepwiki` with `owner`/`repo` and `mode: "structure"` (e.g. `facebook` / `react`)
|
|
43
|
-
2. `context_deepwiki` `mode: "contents"` for the full wiki text, or `mode: "ask"` with a `question` for targeted Q&A
|
|
44
|
-
3. Extract architecture summary and key relationships
|
|
45
|
-
|
|
46
|
-
**Fallback on error**: Method 4 (clone) + Method 5 (web) on GitHub docs/README.
|
|
47
|
-
|
|
48
|
-
## Method 2: Context7 (library documentation)
|
|
49
|
-
|
|
50
|
-
Best for: up-to-date API docs and version-specific examples for packages/frameworks.
|
|
51
|
-
|
|
52
|
-
**Tool**: `context_context7` (native, always available)
|
|
53
|
-
|
|
54
|
-
**Process**:
|
|
55
|
-
1. `context_context7` with the library name as `query` (e.g. `fastapi`, `react`)
|
|
56
|
-
2. Pass a `topic` (e.g. `auth`, `ssr`) for focused snippets; include the version in the query when given (`react@18`)
|
|
57
|
-
3. Extract the minimum viable API surface + examples
|
|
58
|
-
|
|
59
|
-
**Fallback on error**: official docs URLs via `curl`, or clone of the library repo docs.
|
|
60
|
-
|
|
61
|
-
## Method 3: Exa Code Search
|
|
62
|
-
|
|
63
|
-
Best for: real-world usage patterns and cross-web code examples.
|
|
64
|
-
|
|
65
|
-
**Tool**: `context_exa` (native; requires `EXA_API_KEY`)
|
|
66
|
-
|
|
67
|
-
**Process**:
|
|
68
|
-
1. Call with a precise query (language/framework/version/identifiers)
|
|
69
|
-
2. Prefer recent sources; dedupe mirrors
|
|
70
|
-
|
|
71
|
-
**Fallback when key missing / error**: GitHub code search URLs / known docs via `curl`, or clone representative examples.
|
|
72
|
-
|
|
73
|
-
## Method 4: Git Clone (direct code inspection)
|
|
74
|
-
|
|
75
|
-
Best for: private repos, deep implementation review, when other methods lack depth.
|
|
76
|
-
|
|
77
|
-
**Process**:
|
|
78
|
-
1. `git clone <repo-url> /tmp/<repo-name> --depth=1`
|
|
79
|
-
2. `read` key files: entry points, config, core modules
|
|
80
|
-
3. Map structure with `bash` find/ls; search with `bash` grep or Pi search tools if available
|
|
81
|
-
4. Cleanup: `rm -rf /tmp/<repo-name>`
|
|
82
|
-
|
|
83
|
-
## Method 5: Web Search + Fetch
|
|
84
|
-
|
|
85
|
-
Best for: rationale, changelogs, issues, migration guides.
|
|
86
|
-
|
|
87
|
-
**Tools**: `bash` + `curl` (or host HTTP client). There are no Pi built-ins named web search via `curl`/HTTP / HTTP fetch via `curl`.
|
|
88
|
-
|
|
89
|
-
**Process**:
|
|
90
|
-
1. Derive version-anchored queries from the question or clone findings
|
|
91
|
-
2. Fetch high-signal URLs (official docs, GitHub issues/PRs, changelogs)
|
|
92
|
-
3. Extract only relevant sections; cross-check against cloned code when available
|
|
93
|
-
4. Discard results older than ~2 years unless foundational
|
|
94
|
-
|
|
95
|
-
**Query patterns**:
|
|
96
|
-
- Changelogs: `"<repo> CHANGELOG v<version>"`
|
|
97
|
-
- Rationale: `"<repo> <concept> why OR rationale site:github.com"`
|
|
98
|
-
- Known issues: `"<repo> <symbol> issue OR bug site:github.com"`
|
|
99
|
-
- Migration: `"<repo> migrate from <old> to <new>"`
|
|
100
|
-
|
|
101
|
-
## Target Classification
|
|
102
|
-
|
|
103
|
-
- **Repo target** — `owner/repo` or git URL → DeepWiki (`context_deepwiki`) or Git Clone
|
|
104
|
-
- **Library target** — package name / `name@version` → Context7 (`context_context7`) else web/docs clone
|
|
105
|
-
- **Natural-language target** — question/comparison → Exa (`context_exa`) and/or Web; Context7 if a library is named
|
|
106
|
-
|
|
107
|
-
When caller passes `--method=`, use the intersection of allowed and applicable methods. Empty intersection → skip and report.
|
|
108
|
-
|
|
109
|
-
## Method Selection Guide
|
|
110
|
-
|
|
111
|
-
| Scenario | Primary | Fallback |
|
|
112
|
-
|----------|---------|----------|
|
|
113
|
-
| "How does X library work?" | Context7 | Web / clone |
|
|
114
|
-
| "Architecture of Y repo" | DeepWiki | Git Clone |
|
|
115
|
-
| "Examples of Z pattern" | Exa | Context7 / web |
|
|
116
|
-
| "Private/internal repo" | Git Clone | — |
|
|
117
|
-
| "What changed in v3?" | Context7 | Web |
|
|
118
|
-
| "Why this design?" | Git Clone → Web | DeepWiki |
|
|
119
|
-
| "Compare X vs Y" | Exa + Context7 | Web |
|
|
120
|
-
| "Best practice for Z" | Web | Exa |
|
|
121
|
-
|
|
122
|
-
## Combining Methods
|
|
123
|
-
|
|
124
|
-
1. DeepWiki / clone for architecture
|
|
125
|
-
2. Context7 for API surface
|
|
126
|
-
3. Exa / web for community patterns
|
|
127
|
-
4. Always prefer read-only operations; clean up `/tmp` clones
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: get-context
|
|
3
|
-
description: Execute this when the user requests code context for a repository, library, or any natural-language code/technology question using DeepWiki, Context7, Exa, git clone, and/or web search+fetch.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# get-context
|
|
7
|
-
|
|
8
|
-
Run the full code-context workflow using Pi tools. Prefer keeping heavy lookups out of a single giant turn when possible — summarize intermediate results.
|
|
9
|
-
|
|
10
|
-
## Pi tools and runtime
|
|
11
|
-
|
|
12
|
-
| Capability | How |
|
|
13
|
-
|------------|-----|
|
|
14
|
-
| Clone / local files | `bash` (`git clone`), `read`, `bash` (find/grep) |
|
|
15
|
-
| Web fetch | `bash` with `curl -fsSL` (or available HTTP client) |
|
|
16
|
-
| DeepWiki / Context7 / Exa | Native tools from this package's `extensions/context-tools.ts`: `context_deepwiki`, `context_context7`, `context_exa` (Exa needs `EXA_API_KEY`) |
|
|
17
|
-
|
|
18
|
-
If a native tool is unavailable (e.g. `EXA_API_KEY` unset), fall back to clone + web fetch methods from `/skill:code-context`.
|
|
19
|
-
|
|
20
|
-
## Invocation args
|
|
21
|
-
|
|
22
|
-
When invoked as `/skill:get-context <args>`, the text after the skill block is the user-provided arguments. Pi does not expand `$ARGUMENTS` placeholders inside skill bodies; use the trailing invocation text.
|
|
23
|
-
|
|
24
|
-
1. Split into positional targets and optional `--method=` flag.
|
|
25
|
-
- `--method=` accepts a comma-separated list from `deepwiki,context7,exa,clone,web,all`. Default: `all`.
|
|
26
|
-
- Quoted strings are one target.
|
|
27
|
-
- Multiple positional tokens are multiple targets.
|
|
28
|
-
2. Classify each target:
|
|
29
|
-
- GitHub slug (`owner/repo`) or git URL → repo (DeepWiki via `context_deepwiki`, else clone).
|
|
30
|
-
- Bare package name or `name@version` → library (Context7 via `context_context7`, else web + clone of docs repo when known).
|
|
31
|
-
- Anything else → natural-language (Exa via `context_exa` when `EXA_API_KEY` is set, else web search via `curl` to searchable sources / known docs URLs).
|
|
32
|
-
3. Empty input: read dependency manifests in cwd (`package.json`, `go.mod`, `pyproject.toml`, `Cargo.toml`) and use detected dependencies as targets.
|
|
33
|
-
|
|
34
|
-
## Execute
|
|
35
|
-
|
|
36
|
-
1. Load and follow `/skill:code-context` (or `read` that skill file) for method selection and process detail.
|
|
37
|
-
2. Run methods with Pi tools as above; do not invent Claude-only tools (`Task`, `WebSearch`, `WebFetch`).
|
|
38
|
-
3. Return a synthesized summary only — drop raw bulk payloads.
|