@phi-code-admin/phi-code 0.57.4 → 0.57.6
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/agents/code.md +24 -0
- package/agents/explore.md +25 -0
- package/agents/plan.md +26 -0
- package/agents/review.md +25 -0
- package/agents/test.md +24 -0
- package/extensions/phi/README.md +1 -1
- package/extensions/phi/init.ts +114 -15
- package/extensions/phi/smart-router.ts +22 -1
- package/package.json +2 -1
package/agents/code.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: code
|
|
3
|
+
description: Writes and modifies code. Full tool access for implementation.
|
|
4
|
+
tools: read, write, edit, bash, grep, find, ls
|
|
5
|
+
model: default
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
You are a coding specialist. You receive a task and implement it precisely.
|
|
9
|
+
|
|
10
|
+
## Guidelines
|
|
11
|
+
|
|
12
|
+
- Write clean, well-structured code following the project's conventions
|
|
13
|
+
- Handle edge cases and error conditions
|
|
14
|
+
- Add necessary imports and type annotations
|
|
15
|
+
- Follow existing patterns in the codebase
|
|
16
|
+
- If tests exist, ensure your changes don't break them
|
|
17
|
+
- Use meaningful variable and function names
|
|
18
|
+
|
|
19
|
+
## Output Format
|
|
20
|
+
|
|
21
|
+
When done, provide:
|
|
22
|
+
1. Files created or modified (with paths)
|
|
23
|
+
2. Brief description of changes
|
|
24
|
+
3. Any remaining TODOs or known limitations
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: explore
|
|
3
|
+
description: Fast codebase analysis. Returns structured context for other agents.
|
|
4
|
+
tools: read, grep, find, ls, bash
|
|
5
|
+
model: default
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
You are an exploration specialist. You analyze codebases quickly and return structured findings.
|
|
9
|
+
|
|
10
|
+
## Guidelines
|
|
11
|
+
|
|
12
|
+
- Read files systematically (directory structure first, then key files)
|
|
13
|
+
- Identify patterns, conventions, and architecture
|
|
14
|
+
- Note dependencies and integrations
|
|
15
|
+
- Highlight potential issues or inconsistencies
|
|
16
|
+
- Do NOT modify any files — read-only analysis
|
|
17
|
+
|
|
18
|
+
## Output Format
|
|
19
|
+
|
|
20
|
+
Provide a structured analysis:
|
|
21
|
+
1. **Architecture**: Project structure and organization
|
|
22
|
+
2. **Key Files**: Most important files and their purposes
|
|
23
|
+
3. **Dependencies**: External libraries and services
|
|
24
|
+
4. **Patterns**: Coding conventions and design patterns used
|
|
25
|
+
5. **Issues**: Potential problems or improvements
|
package/agents/plan.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: plan
|
|
3
|
+
description: Creates detailed implementation plans. Read-only — never modifies files.
|
|
4
|
+
tools: read, grep, find, ls
|
|
5
|
+
model: default
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
You are a planning specialist. You create detailed, actionable implementation plans.
|
|
9
|
+
|
|
10
|
+
## Guidelines
|
|
11
|
+
|
|
12
|
+
- Analyze requirements thoroughly before planning
|
|
13
|
+
- Break work into small, independent tasks
|
|
14
|
+
- Identify dependencies between tasks
|
|
15
|
+
- Suggest the right agent type for each task (code, test, review, explore)
|
|
16
|
+
- Consider edge cases, error handling, and testing
|
|
17
|
+
- Do NOT modify files — provide the plan only
|
|
18
|
+
|
|
19
|
+
## Output Format
|
|
20
|
+
|
|
21
|
+
1. **Overview**: High-level approach summary
|
|
22
|
+
2. **Architecture**: Technical decisions and trade-offs
|
|
23
|
+
3. **Tasks**: Ordered list with dependencies
|
|
24
|
+
- Each task: description, agent type, estimated complexity, dependencies
|
|
25
|
+
4. **Risks**: Potential issues and mitigations
|
|
26
|
+
5. **Success Criteria**: How to verify the plan is complete
|
package/agents/review.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: review
|
|
3
|
+
description: Senior code reviewer. Checks quality, security, maintainability.
|
|
4
|
+
tools: read, grep, find, ls, bash
|
|
5
|
+
model: default
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
You are a senior code reviewer. You assess code quality, security, and maintainability.
|
|
9
|
+
|
|
10
|
+
## Guidelines
|
|
11
|
+
|
|
12
|
+
- Check for security vulnerabilities (injection, auth, data exposure)
|
|
13
|
+
- Verify error handling and edge cases
|
|
14
|
+
- Assess code readability and maintainability
|
|
15
|
+
- Check for performance issues (N+1 queries, memory leaks, blocking calls)
|
|
16
|
+
- Verify adherence to project conventions
|
|
17
|
+
- Do NOT fix issues — report them with severity and suggestions
|
|
18
|
+
|
|
19
|
+
## Output Format
|
|
20
|
+
|
|
21
|
+
1. **Security**: Critical, High, Medium, Low findings
|
|
22
|
+
2. **Quality**: Code style, patterns, maintainability
|
|
23
|
+
3. **Performance**: Bottlenecks, inefficiencies
|
|
24
|
+
4. **Suggestions**: Specific improvements with examples
|
|
25
|
+
5. **Verdict**: Approve, Request Changes, or Block (with reasons)
|
package/agents/test.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: test
|
|
3
|
+
description: Runs tests, validates changes. Executes commands but only modifies test files.
|
|
4
|
+
tools: read, bash, grep, find, ls
|
|
5
|
+
model: default
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
You are a testing specialist. You validate code quality through testing.
|
|
9
|
+
|
|
10
|
+
## Guidelines
|
|
11
|
+
|
|
12
|
+
- Run existing tests first to establish baseline
|
|
13
|
+
- Write tests for new or modified functionality
|
|
14
|
+
- Test edge cases and error conditions
|
|
15
|
+
- Verify that changes don't break existing behavior
|
|
16
|
+
- Report test coverage if tools are available
|
|
17
|
+
|
|
18
|
+
## Output Format
|
|
19
|
+
|
|
20
|
+
1. **Baseline**: Results of running existing tests
|
|
21
|
+
2. **New Tests**: Tests written and their results
|
|
22
|
+
3. **Coverage**: What is tested and what isn't
|
|
23
|
+
4. **Issues Found**: Bugs, edge cases, or regressions
|
|
24
|
+
5. **Verdict**: Pass/fail with justification
|
package/extensions/phi/README.md
CHANGED
package/extensions/phi/init.ts
CHANGED
|
@@ -23,6 +23,7 @@ interface DetectedProvider {
|
|
|
23
23
|
baseUrl: string;
|
|
24
24
|
models: string[];
|
|
25
25
|
available: boolean;
|
|
26
|
+
local?: boolean; // True for Ollama/LM Studio (models discovered at runtime)
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
interface RoutingConfig {
|
|
@@ -82,15 +83,65 @@ function detectProviders(): DetectedProvider[] {
|
|
|
82
83
|
models: ["llama-3.3-70b-versatile", "mixtral-8x7b-32768"],
|
|
83
84
|
available: false,
|
|
84
85
|
},
|
|
86
|
+
{
|
|
87
|
+
name: "Ollama",
|
|
88
|
+
envVar: "OLLAMA",
|
|
89
|
+
baseUrl: "http://localhost:11434/v1",
|
|
90
|
+
models: [], // Discovered at runtime
|
|
91
|
+
available: false,
|
|
92
|
+
local: true,
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: "LM Studio",
|
|
96
|
+
envVar: "LM_STUDIO",
|
|
97
|
+
baseUrl: "http://localhost:1234/v1",
|
|
98
|
+
models: [], // Discovered at runtime
|
|
99
|
+
available: false,
|
|
100
|
+
local: true,
|
|
101
|
+
},
|
|
85
102
|
];
|
|
86
103
|
|
|
87
104
|
for (const p of providers) {
|
|
88
|
-
p.
|
|
105
|
+
if (p.local) {
|
|
106
|
+
// Local providers: check if server is running by probing the URL
|
|
107
|
+
p.available = false; // Will be checked async in detectLocalProviders()
|
|
108
|
+
} else {
|
|
109
|
+
p.available = !!process.env[p.envVar];
|
|
110
|
+
}
|
|
89
111
|
}
|
|
90
112
|
|
|
91
113
|
return providers;
|
|
92
114
|
}
|
|
93
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Detect local providers (Ollama, LM Studio) by probing their endpoints
|
|
118
|
+
* and fetching available models dynamically.
|
|
119
|
+
*/
|
|
120
|
+
async function detectLocalProviders(providers: DetectedProvider[]): Promise<void> {
|
|
121
|
+
for (const p of providers) {
|
|
122
|
+
if (!p.local) continue;
|
|
123
|
+
try {
|
|
124
|
+
const controller = new AbortController();
|
|
125
|
+
const timeout = setTimeout(() => controller.abort(), 3000);
|
|
126
|
+
const res = await fetch(`${p.baseUrl}/models`, {
|
|
127
|
+
signal: controller.signal,
|
|
128
|
+
headers: { Authorization: `Bearer ${p.envVar === "OLLAMA" ? "ollama" : "lm-studio"}` },
|
|
129
|
+
});
|
|
130
|
+
clearTimeout(timeout);
|
|
131
|
+
if (res.ok) {
|
|
132
|
+
const data = await res.json() as any;
|
|
133
|
+
const models = (data.data || []).map((m: any) => m.id).filter(Boolean);
|
|
134
|
+
if (models.length > 0) {
|
|
135
|
+
p.models = models;
|
|
136
|
+
p.available = true;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
} catch {
|
|
140
|
+
// Server not running — that's fine
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
94
145
|
function getAllAvailableModels(providers: DetectedProvider[]): string[] {
|
|
95
146
|
return providers.filter(p => p.available).flatMap(p => p.models);
|
|
96
147
|
}
|
|
@@ -210,18 +261,55 @@ _Edit this file to customize Phi Code's behavior for your project._
|
|
|
210
261
|
|
|
211
262
|
// ─── MODE: Auto ──────────────────────────────────────────────────
|
|
212
263
|
|
|
264
|
+
/**
|
|
265
|
+
* Auto-assign models based on specialization heuristics.
|
|
266
|
+
* Works with ANY provider — not just Alibaba.
|
|
267
|
+
*
|
|
268
|
+
* Strategy: match model names against known specialization patterns.
|
|
269
|
+
* - "coder" in name → code tasks
|
|
270
|
+
* - "mini"/"flash"/"fast"/"small" in name → explore/test (fast tasks)
|
|
271
|
+
* - Largest/best model → plan/debug/review (reasoning tasks)
|
|
272
|
+
* - If only 1 model available → everything uses that model (still works!)
|
|
273
|
+
*/
|
|
213
274
|
function autoMode(availableModels: string[]): Record<string, { preferred: string; fallback: string }> {
|
|
214
275
|
const assignments: Record<string, { preferred: string; fallback: string }> = {};
|
|
215
276
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
assignments[role.key] =
|
|
277
|
+
if (availableModels.length === 0) {
|
|
278
|
+
// Shouldn't happen, but safety fallback
|
|
279
|
+
const fb = { preferred: "qwen3.5-plus", fallback: "qwen3.5-plus" };
|
|
280
|
+
for (const role of TASK_ROLES) assignments[role.key] = fb;
|
|
281
|
+
assignments["default"] = fb;
|
|
282
|
+
return assignments;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (availableModels.length === 1) {
|
|
286
|
+
// Single model: everything uses it
|
|
287
|
+
const single = { preferred: availableModels[0], fallback: availableModels[0] };
|
|
288
|
+
for (const role of TASK_ROLES) assignments[role.key] = single;
|
|
289
|
+
assignments["default"] = single;
|
|
290
|
+
return assignments;
|
|
220
291
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
292
|
+
|
|
293
|
+
// Categorize models by name heuristics
|
|
294
|
+
const lower = availableModels.map(m => ({ id: m, l: m.toLowerCase() }));
|
|
295
|
+
const coderModels = lower.filter(m => /coder|code|codestral/.test(m.l)).map(m => m.id);
|
|
296
|
+
const fastModels = lower.filter(m => /mini|flash|fast|small|haiku|lite/.test(m.l)).map(m => m.id);
|
|
297
|
+
const reasoningModels = lower.filter(m => /max|pro|plus|opus|large|o1|o3/.test(m.l)).map(m => m.id);
|
|
298
|
+
|
|
299
|
+
// Pick best for each category, with fallback to first available
|
|
300
|
+
const bestCoder = coderModels[0] || reasoningModels[0] || availableModels[0];
|
|
301
|
+
const bestReasoning = reasoningModels[0] || availableModels[0];
|
|
302
|
+
const bestFast = fastModels[0] || availableModels[availableModels.length - 1] || availableModels[0];
|
|
303
|
+
const generalModel = reasoningModels[0] || availableModels[0];
|
|
304
|
+
const fallbackModel = availableModels.find(m => m !== generalModel) || generalModel;
|
|
305
|
+
|
|
306
|
+
assignments["code"] = { preferred: bestCoder, fallback: generalModel };
|
|
307
|
+
assignments["debug"] = { preferred: bestReasoning, fallback: fallbackModel };
|
|
308
|
+
assignments["plan"] = { preferred: bestReasoning, fallback: fallbackModel };
|
|
309
|
+
assignments["explore"] = { preferred: bestFast, fallback: generalModel };
|
|
310
|
+
assignments["test"] = { preferred: bestFast, fallback: generalModel };
|
|
311
|
+
assignments["review"] = { preferred: generalModel, fallback: fallbackModel };
|
|
312
|
+
assignments["default"] = { preferred: generalModel, fallback: fallbackModel };
|
|
225
313
|
|
|
226
314
|
return assignments;
|
|
227
315
|
}
|
|
@@ -376,21 +464,32 @@ _Edit this file to customize Phi Code's behavior for your project._
|
|
|
376
464
|
ctx.ui.notify("║ Φ Phi Code Setup Wizard ║", "info");
|
|
377
465
|
ctx.ui.notify("╚══════════════════════════════════════╝\n", "info");
|
|
378
466
|
|
|
379
|
-
// 1. Detect API keys
|
|
380
|
-
ctx.ui.notify("🔍 Detecting
|
|
467
|
+
// 1. Detect API keys and local providers
|
|
468
|
+
ctx.ui.notify("🔍 Detecting providers...", "info");
|
|
381
469
|
const providers = detectProviders();
|
|
470
|
+
|
|
471
|
+
// Probe local providers (Ollama, LM Studio)
|
|
472
|
+
ctx.ui.notify("🔍 Probing local model servers...", "info");
|
|
473
|
+
await detectLocalProviders(providers);
|
|
474
|
+
|
|
382
475
|
const available = providers.filter(p => p.available);
|
|
383
476
|
|
|
384
477
|
if (available.length === 0) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
"
|
|
478
|
+
const cloudProviders = providers.filter(p => !p.local);
|
|
479
|
+
ctx.ui.notify("❌ No providers found. Options:\n\n" +
|
|
480
|
+
"**Cloud providers** (set API key):\n" +
|
|
481
|
+
cloudProviders.map(p => ` export ${p.envVar}="your-key" # ${p.name}`).join("\n") +
|
|
482
|
+
"\n\n**Local providers** (start the server):\n" +
|
|
483
|
+
" • Ollama: `ollama serve` (default port 11434)\n" +
|
|
484
|
+
" • LM Studio: Start server in app (default port 1234)\n" +
|
|
485
|
+
"\n💡 Free options: Alibaba Coding Plan (cloud, $0) or Ollama (local, free)", "error");
|
|
388
486
|
return;
|
|
389
487
|
}
|
|
390
488
|
|
|
391
489
|
ctx.ui.notify(`✅ Found ${available.length} provider(s):`, "info");
|
|
392
490
|
for (const p of available) {
|
|
393
|
-
|
|
491
|
+
const tag = p.local ? " (local)" : "";
|
|
492
|
+
ctx.ui.notify(` • ${p.name}${tag} — ${p.models.length} model(s)${p.local ? ": " + p.models.join(", ") : ""}`, "info");
|
|
394
493
|
}
|
|
395
494
|
|
|
396
495
|
const allModels = getAllAvailableModels(providers);
|
|
@@ -170,6 +170,25 @@ export default function smartRouterExtension(pi: ExtensionAPI) {
|
|
|
170
170
|
|
|
171
171
|
// ─── Input Event ─────────────────────────────────────────────────
|
|
172
172
|
|
|
173
|
+
/**
|
|
174
|
+
* Resolve a model name to an available model.
|
|
175
|
+
* If the preferred model exists in the registry, use it.
|
|
176
|
+
* Otherwise, fall back to the current model.
|
|
177
|
+
*/
|
|
178
|
+
function resolveModel(preferredModel: string, ctx: any): string {
|
|
179
|
+
// Check if model exists in registry
|
|
180
|
+
try {
|
|
181
|
+
const available = ctx.modelRegistry?.getAvailable?.() || [];
|
|
182
|
+
if (available.some((m: any) => m.id === preferredModel)) {
|
|
183
|
+
return preferredModel;
|
|
184
|
+
}
|
|
185
|
+
// Model not available — use current model
|
|
186
|
+
return ctx.model?.id || preferredModel;
|
|
187
|
+
} catch {
|
|
188
|
+
return ctx.model?.id || preferredModel;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
173
192
|
pi.on("input", async (event, ctx) => {
|
|
174
193
|
if (!config.enabled || event.source === "extension") {
|
|
175
194
|
return { action: "continue" };
|
|
@@ -179,8 +198,10 @@ export default function smartRouterExtension(pi: ExtensionAPI) {
|
|
|
179
198
|
|
|
180
199
|
if (result.category && result.confidence >= 25 && result.route) {
|
|
181
200
|
if (config.notifyOnRecommendation) {
|
|
201
|
+
const resolved = resolveModel(result.route.preferredModel, ctx);
|
|
202
|
+
const suffix = resolved !== result.route.preferredModel ? ` (→ ${resolved})` : "";
|
|
182
203
|
ctx.ui.notify(
|
|
183
|
-
`🔀 ${result.route.description} → \`${result.route.preferredModel}
|
|
204
|
+
`🔀 ${result.route.description} → \`${result.route.preferredModel}\`${suffix} (${result.confidence}% | ${result.matches.join(", ")})`,
|
|
184
205
|
"info"
|
|
185
206
|
);
|
|
186
207
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phi-code-admin/phi-code",
|
|
3
|
-
"version": "0.57.
|
|
3
|
+
"version": "0.57.6",
|
|
4
4
|
"description": "Coding agent CLI with read, bash, edit, write tools and session management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"piConfig": {
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"files": [
|
|
26
26
|
"dist",
|
|
27
27
|
"skills",
|
|
28
|
+
"agents",
|
|
28
29
|
"extensions",
|
|
29
30
|
"README.md",
|
|
30
31
|
"LICENSE",
|