@gopersonal/advisor 1.0.1 → 1.0.3
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 +5 -0
- package/build/index.js +35 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,6 +65,11 @@ claude mcp add advisor -- npx -y @gopersonal/advisor
|
|
|
65
65
|
| `ADVISOR_MODEL` | Model name | `gpt-4o`, `claude-sonnet-4-5` |
|
|
66
66
|
| `ADVISOR_API_KEY` | API key for the provider | `sk-...` |
|
|
67
67
|
| `ADVISOR_BASE_URL` | Custom base URL (optional) | `https://proxy.example.com` |
|
|
68
|
+
| `ADVISOR_DIRECTORY` | Project directory for opencode context (optional) | `/Users/me/myproject` |
|
|
69
|
+
| `ADVISOR_INSTRUCTIONS` | Path to instructions/AGENTS.md file (optional) | `/Users/me/myproject/AGENTS.md` |
|
|
70
|
+
|
|
71
|
+
`ADVISOR_DIRECTORY` gives the advisor context about your project (file structure, code, etc.).
|
|
72
|
+
`ADVISOR_INSTRUCTIONS` loads a custom instructions file (like AGENTS.md) so the advisor knows your project conventions.
|
|
68
73
|
|
|
69
74
|
If no env vars are set, the advisor connects to a running opencode instance or starts one using your default opencode config.
|
|
70
75
|
|
package/build/index.js
CHANGED
|
@@ -7,35 +7,46 @@ import { createOpencode, createOpencodeClient } from "@opencode-ai/sdk/v2";
|
|
|
7
7
|
//
|
|
8
8
|
// Pass these via the "env" field in the MCP config JSON.
|
|
9
9
|
//
|
|
10
|
-
// Option A: OpenAI-compatible endpoint
|
|
10
|
+
// Option A: OpenAI-compatible endpoint (most providers, proxies, etc.)
|
|
11
11
|
// ADVISOR_PROVIDER = "openai"
|
|
12
|
-
// ADVISOR_MODEL = "gpt-4o"
|
|
12
|
+
// ADVISOR_MODEL = "gpt-4o"
|
|
13
13
|
// ADVISOR_API_KEY = "sk-..."
|
|
14
|
-
// ADVISOR_BASE_URL = "https://api.openai.com/v1"
|
|
14
|
+
// ADVISOR_BASE_URL = "https://api.openai.com/v1"
|
|
15
15
|
//
|
|
16
16
|
// Option B: Anthropic-compatible endpoint
|
|
17
17
|
// ADVISOR_PROVIDER = "anthropic"
|
|
18
|
-
// ADVISOR_MODEL = "claude-sonnet-4-5"
|
|
18
|
+
// ADVISOR_MODEL = "claude-sonnet-4-5"
|
|
19
19
|
// ADVISOR_API_KEY = "sk-ant-..."
|
|
20
|
-
// ADVISOR_BASE_URL = "https://api.anthropic.com"
|
|
20
|
+
// ADVISOR_BASE_URL = "https://api.anthropic.com"
|
|
21
21
|
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
22
|
+
// Optional:
|
|
23
|
+
// ADVISOR_DIRECTORY = project directory for opencode context (e.g. "/Users/me/myproject")
|
|
24
|
+
// ADVISOR_INSTRUCTIONS = path to instructions file (e.g. "/Users/me/myproject/AGENTS.md")
|
|
24
25
|
//
|
|
25
26
|
function resolveProviderAndModel() {
|
|
26
27
|
const explicitProvider = process.env.ADVISOR_PROVIDER?.toLowerCase();
|
|
27
28
|
const rawModel = process.env.ADVISOR_MODEL;
|
|
28
29
|
if (!rawModel)
|
|
29
30
|
return undefined;
|
|
30
|
-
// Option 1: explicit ADVISOR_PROVIDER + ADVISOR_MODEL (recommended)
|
|
31
31
|
if (explicitProvider) {
|
|
32
|
+
// "openai" provider in opencode uses OpenAI's Responses API which most
|
|
33
|
+
// compatible endpoints don't support. Use @ai-sdk/openai-compatible instead,
|
|
34
|
+
// which calls the standard /v1/chat/completions endpoint.
|
|
35
|
+
if (explicitProvider === "openai") {
|
|
36
|
+
return {
|
|
37
|
+
provider: "openai-compat",
|
|
38
|
+
model: rawModel,
|
|
39
|
+
fullModel: `openai-compat/${rawModel}`,
|
|
40
|
+
npm: "@ai-sdk/openai-compatible",
|
|
41
|
+
};
|
|
42
|
+
}
|
|
32
43
|
return {
|
|
33
44
|
provider: explicitProvider,
|
|
34
45
|
model: rawModel,
|
|
35
46
|
fullModel: `${explicitProvider}/${rawModel}`,
|
|
36
47
|
};
|
|
37
48
|
}
|
|
38
|
-
//
|
|
49
|
+
// Legacy "provider/model" format in ADVISOR_MODEL
|
|
39
50
|
if (rawModel.includes("/")) {
|
|
40
51
|
const [provider, ...rest] = rawModel.split("/");
|
|
41
52
|
return {
|
|
@@ -44,22 +55,28 @@ function resolveProviderAndModel() {
|
|
|
44
55
|
fullModel: rawModel,
|
|
45
56
|
};
|
|
46
57
|
}
|
|
47
|
-
// Just a model name with no provider —
|
|
58
|
+
// Just a model name with no provider — use openai-compatible
|
|
48
59
|
return {
|
|
49
|
-
provider: "openai",
|
|
60
|
+
provider: "openai-compat",
|
|
50
61
|
model: rawModel,
|
|
51
|
-
fullModel: `openai/${rawModel}`,
|
|
62
|
+
fullModel: `openai-compat/${rawModel}`,
|
|
63
|
+
npm: "@ai-sdk/openai-compatible",
|
|
52
64
|
};
|
|
53
65
|
}
|
|
54
66
|
function buildOpencodeConfig() {
|
|
55
67
|
const resolved = resolveProviderAndModel();
|
|
56
68
|
const apiKey = process.env.ADVISOR_API_KEY;
|
|
57
69
|
const baseURL = process.env.ADVISOR_BASE_URL;
|
|
58
|
-
const npm = process.env.ADVISOR_NPM;
|
|
70
|
+
const npm = process.env.ADVISOR_NPM || resolved?.npm;
|
|
71
|
+
const instructions = process.env.ADVISOR_INSTRUCTIONS;
|
|
59
72
|
const config = {
|
|
60
73
|
// Disable title generation (it uses small_model which may not work with custom providers)
|
|
61
74
|
small_model: resolved?.fullModel || undefined,
|
|
75
|
+
// Additional instruction files (e.g. AGENTS.md)
|
|
76
|
+
...(instructions ? { instructions: [instructions] } : {}),
|
|
62
77
|
};
|
|
78
|
+
if (instructions)
|
|
79
|
+
console.error(`[advisor] Instructions: ${instructions}`);
|
|
63
80
|
if (resolved) {
|
|
64
81
|
config.model = resolved.fullModel;
|
|
65
82
|
console.error(`[advisor] Provider: ${resolved.provider}, Model: ${resolved.model}`);
|
|
@@ -151,8 +168,10 @@ function sleep(ms) {
|
|
|
151
168
|
}
|
|
152
169
|
async function askOpencode(prompt, systemPrompt) {
|
|
153
170
|
const client = await getOpencodeClient();
|
|
171
|
+
const directory = process.env.ADVISOR_DIRECTORY;
|
|
154
172
|
const sessionResult = await client.session.create({
|
|
155
173
|
title: "Advisor Query",
|
|
174
|
+
...(directory ? { directory } : {}),
|
|
156
175
|
});
|
|
157
176
|
if (!sessionResult.data) {
|
|
158
177
|
throw new Error("Failed to create opencode session");
|
|
@@ -166,6 +185,7 @@ async function askOpencode(prompt, systemPrompt) {
|
|
|
166
185
|
sessionID: sessionId,
|
|
167
186
|
system: systemPrompt,
|
|
168
187
|
...(modelOverride ? { model: modelOverride } : {}),
|
|
188
|
+
...(directory ? { directory } : {}),
|
|
169
189
|
parts: [{ type: "text", text: prompt }],
|
|
170
190
|
});
|
|
171
191
|
console.error(`[advisor] Prompt submitted async`);
|
|
@@ -381,7 +401,8 @@ server.registerTool("get_second_opinion", {
|
|
|
381
401
|
async function main() {
|
|
382
402
|
const transport = new StdioServerTransport();
|
|
383
403
|
await server.connect(transport);
|
|
384
|
-
|
|
404
|
+
const dir = process.env.ADVISOR_DIRECTORY;
|
|
405
|
+
console.error(`[advisor] MCP Advisor server running on stdio${dir ? ` (directory: ${dir})` : ""}`);
|
|
385
406
|
}
|
|
386
407
|
main().catch((error) => {
|
|
387
408
|
console.error("[advisor] Fatal error:", error);
|